Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TraceRay Lua Functions #1624

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

12345swordy
Copy link
Contributor

Or Rather Finished the implementation of Lua functions that deemed relevant.

cc @sprunk

Copy link
Collaborator

@loveridge loveridge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good, but I didn't test it

@@ -39,6 +39,7 @@
#include "Sim/Misc/QuadField.h"
#include "Sim/Misc/TeamHandler.h"
#include "Sim/Misc/Wind.h"
#include "Sim//Misc/CollisionHandler.h"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

two slashes


int LuaSyncedRead::TraceRayUnits(lua_State* L) //returns the list of units that an raytrace has hit
{
float3 pos((double)luaL_checknumber(L, 1), (double)luaL_checknumber(L, 2), (double)luaL_checknumber(L, 3));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is a luaL_checkfloat

*/
int LuaSyncedRead::TraceRayFeatures(lua_State* L) //returns the list of features that an raytrace has hit
{
float3 pos((double)luaL_checknumber(L, 1), (double)luaL_checknumber(L, 2), (double)luaL_checknumber(L, 3));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is an extra space at the start of these lines

*/
int LuaSyncedRead::TraceRayGround(lua_State* L)
{
float3 pos((double)luaL_checknumber(L, 1), (double)luaL_checknumber(L, 2), (double)luaL_checknumber(L, 3));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

an extra space on the start of these lines too

* @number dirY
* @number dirZ
* @number traceLength
* @treturn {{len, Id},...}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return type for doc wrong

Comment on lines 8546 to 8549
for (const int quadIdx : *qfQuery.quads) {
const CQuadField::Quad& quad = quadField.GetQuad(quadIdx);

for (CUnit* u : quad.units) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good if the returned list was sorted in order of distance, from the closest.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you not reverse it in lua?

Comment on lines 8630 to 8632
if (traceLength > groundLength && groundLength > 0.0f) {
traceLength = groundLength;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the ray fails to intersect ground the function should probably return nil.

@12345swordy
Copy link
Contributor Author

ping @sprunk

rts/Lua/LuaSyncedRead.cpp Outdated Show resolved Hide resolved
rts/Lua/LuaSyncedRead.cpp Outdated Show resolved Hide resolved
rts/Lua/LuaSyncedRead.cpp Outdated Show resolved Hide resolved
rts/Lua/LuaSyncedRead.cpp Outdated Show resolved Hide resolved
rts/Lua/LuaSyncedRead.cpp Outdated Show resolved Hide resolved
rts/Lua/LuaSyncedRead.cpp Outdated Show resolved Hide resolved
@sprunk
Copy link
Collaborator

sprunk commented Sep 29, 2024

I found some time to spare and extracted the ground traceray to a separate PR after some finishing touches #1706.

@12345swordy
Copy link
Contributor Author

What should I do regarding the other two functions then? TraceRayUnits and TraceRayFeatures specifically?

@sprunk
Copy link
Collaborator

sprunk commented Oct 2, 2024

For now the only task is to test them, I'll do that when I have some more free time.

@saurtron
Copy link
Collaborator

Regarding my test of this branch, imo needs some work since it's pretty awkward to work with, and has the classic bug regarding radar dots too.

My concerns:

  • Forces you to add posx, posy, posz, dirx, diry, dirz, distance
  • Not sure there's even a way to get mouse->dir or Farplane dist (the usual things to put there)
    • for the test widget I was going to do it in Update(), but just found a way to get mouse dir for "GetMouseStartPosition", that one asks for a mouse button
    • imo these should be autocalculated to CameraPos + mouse->dir as it's the most usual if not adding anything there
    • length should default to farplane for groundray, or usual groundtrace + SelectThroughGround for units or features queries when not setting it
  • The quadray tracing is not aware of radar dots, as usual, should implement wideray as needed at least if enabling radar use (either it should always do it, or have a flag to do_radar or not)
  • Returns duplicates for features and units, imo this should be avoided since it's easier to remove the duplicates from c++ than lua
  • Maybe a flag to just get the closest one could be in order too, since most times that's what ppl will want I guess, in that case it would just need to return an unitID/featureID
    • that's also going to be very expensive and lots of repeated code everywhere from lua if we don't facilitate

@saurtron
Copy link
Collaborator

Hey, created a test widget for this: dbg_gui_test_rays.lua.

  1. Put in your Widgets dir
  2. Start skirmish
  3. Enable widget "TestRays"
  4. Click in different places with any mouse button
    • the widget will Echo what was traced by the ray (units, features or ground in that order, if units gets found then it doesnt go on, and so on)

@sprunk
Copy link
Collaborator

sprunk commented Dec 17, 2024

mouse->dir or Farplane dist (the usual things to put there)
not aware of radar dots
forces you to add posx, posy, posz, dirx, diry, dirz, distance

This is for mechanics like chain lightning so none of these is applicable.

Returns duplicates

Sounds bad.

Maybe a flag to just get the closest one could be in order too

Perhaps input n and make it return the n closest?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants