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

Improve the controlability of the CAP traces #108

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

Conversation

dvdvideo1234
Copy link

No description provided.

@AlexALX
Copy link
Collaborator

AlexALX commented Oct 10, 2021

For what exact purposes this can be used? since its nowhere used in cap

@dvdvideo1234
Copy link
Author

I an contently coding the extended version of laser tool and I want to support the stargate portals. However CAP runs the quick trace, that does not give options for fine tuning when running it. This PR aims to add fine tuning for the StarGate.Trace:New function as it currently does not support mask, collision group and ignore world. In all the paces the function is called currently will use the old set of parameters (start,dir,ignore) and the default values of the trace data where the argument is not passed. My aim is not to call for trace two times when CAP is installed and my beam refraction will still work as otherwise the traced ray origin goes inside the world and calculation fails.

@TheMerkyShadow
Copy link
Contributor

TheMerkyShadow commented Oct 11, 2021

This feature you wish to add is "frivolous" and only useful for yourself. And while it is appreciated...this mod doesn't really need it. You could easily override functionality in your addon and didn't even need to make a pull request.

I don't speak for any of the main developers here. I'm just giving my opinion.

@dvdvideo1234
Copy link
Author

Yeah. Maybe, but you can tune your traces now instead of relying on the one general option. Maybe it is a bit slower, but it gives more control on the result. I will let the CAP devs decide. It will be good for me and anyone that uses CAP traces :P

@AlexALX
Copy link
Collaborator

AlexALX commented Oct 11, 2021

Can we see source of util.QuickTrace somewhere? just curious if its really faster or not than util.TraceLine..

Also as possible way - we can use both ways, lets say if arguments are not provided - use quicktrace still, otherwise use advanced one.

Just thoughts...

@dvdvideo1234
Copy link
Author

dvdvideo1234 commented Oct 11, 2021

It seems to be the same thing. Creates trace data internally and calls util.TraceLine

https://github.com/Facepunch/garrysmod/blob/master/garrysmod/lua/includes/extensions/util.lua#L56

My idea is generally to stop executing two traces for every beam trace with the CAP one being the priority and taken over by the regular trace when the traced entity is not a CAP-able entity ( like event horizon for example ). This will improve the speed for the Laser STool and the CAP traces base functionality will not get affected. I meant faster in a way assuming the other parameters are not used ;). If we want to talk about faster. It will be better to provide util.TraceLine with result stor ouput table so it will not get created every time. util.QuickTrace is more of a Lua wrapper than an actual core function.

@AlexALX
Copy link
Collaborator

AlexALX commented Oct 11, 2021

oh ok, so i guess its fine to replace this, will check later (near weekend)

@dvdvideo1234
Copy link
Author

dvdvideo1234 commented Oct 13, 2021

Numeric for is better than pairs according to the given data set ( array of trace tables )

https://www.lua.org/pil/4.3.4.html
https://www.lua.org/gems/sample.pdf
https://medium.com/@sleitnick/battle-of-the-loops-c001bcb4961c

@dvdvideo1234
Copy link
Author

dvdvideo1234 commented Oct 22, 2021

It will be nice to also have non-zero width traces. This will also not affect the current tracing of CAP ( which uses: (start,dir,ignore) ). Also The StartPos key is obviously wrong according to the wiki. Localized the trace start position for speed. The algorithm will always pick the first entry as the first most near position.

Optimized: Localize trace.start for speed
@dvdvideo1234
Copy link
Author

@AlexALX Hi, so any progress on this? Tell me if I can help somehow.

Optimized: Speed of trace pick-up routine
Added: Zero width results in running the old trace method
Updated: Closest trace measured according to true start origin
@dvdvideo1234
Copy link
Author

Finally it seems it is in a good place.

Added: `QuickIgnore` as class method
Added: Ray-sphere intersection in vector-N form `HitSphere`
Removed: Unused variable `old` in `HitWall`
@dvdvideo1234
Copy link
Author

dvdvideo1234 commented Dec 18, 2021

Hello, @AlexALX @TheMerkyShadow

I've provided you with linear algebra solution of detecting shield intersection here StarGate.Trace:HitSphere, which will potentially solve the problem requested here elseif (class == "shield") then and here if (not hit and class=="shield" and not in_box. You can use it to detect ( calculate ) hits and use it in your code like follows:

local mpos, ppos = self:HitSphere(....)
if(mpos or ppos) then -- There is a ray-sphere intersection ( for spherical shields )
   -- Do something with the closest or furthest intersection points
end

@AlexALX
Copy link
Collaborator

AlexALX commented Feb 11, 2022

Hi, is this final version?

@dvdvideo1234
Copy link
Author

Hello,

Yes, it is. It stays here for quite a while now ;)

@dvdvideo1234
Copy link
Author

dvdvideo1234 commented Mar 5, 2022

@AlexALX

Hi, any progress on this. Tell me if I need to help!

@AlexALX
Copy link
Collaborator

AlexALX commented Mar 5, 2022

In my country war started, so can't say anything right now.

…rcle

Fixed: Return a proper value just like `StarGate.Trace:HitWall`
@dvdvideo1234
Copy link
Author

@AlexALX

Just preserved the coding convention and fixed some mistakes ;)

@AlexALX
Copy link
Collaborator

AlexALX commented Sep 7, 2022

damn, can't merge this without checking, since looks way much changes. will see bit later.

@AlexALX
Copy link
Collaborator

AlexALX commented Mar 28, 2024

[cap] addons/cap/lua/stargate/shared/tracelines.lua:247: attempt to index global 'data' (a nil value)

  1. New - addons/cap/lua/stargate/shared/tracelines.lua:247
  2. v - addons/cap/lua/stargate/shared/cap.lua:289
    3. unknown - lua/includes/modules/hook.lua:96 (x4)

@dvdvideo1234
Copy link
Author

Fixed, @AlexALX ;)

Fixed: Some comment typos and if-statement brackets to match convention
Updated: Use squared distance instead of meridian distance when comparing
@dvdvideo1234
Copy link
Author

Hello, @AlexALX I think we are ready. Made some optimizations

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

Successfully merging this pull request may close these issues.

3 participants