#Pretty cool, could be better optimised though

1 messages · Page 1 of 1 (latest)

polar turret
#

Looks like a very cool addon, went to check how you'd make an addon like this optimised and it looks like there's alot of good stuff in there but a couple things that could be improved.

  1. (as far as I can tell) ScanEntities is called alot. ThinkingProcess seems to call it every second (ish as there's a random offset?), however EnemyReaction is also called which can call ScanEntities up to another 4 times! This means that every second, ScanEntities could be called up to 5 times.

Each of these scans calls FindInSphere twice, meaning up to 10 FindInSphere calls per second for no real reason. As far as I can tell most of these results could be cached and reused for the same tick/second.

  1. sapdata.lua:L17, confirmSaveData does not work (probably just put == where you meant !=), but if it did work then each new prop found would TableToJSON the entire (large) _Sapbot_PropStructureDataset table and write it to a file. You should certainly be using SQL for this, but if you really didn't want to, at least make it so the file is only saved at the end of the ScanEntities check, otherwise it could be many (as many new local props there are) writes per second.

  2. The HUDPaint in sap_bot:L840 seems to create alot of Colors. For example, Color(0, 0, 0) is called quite alot, (or saphealthbossvo which is created always but only used in certain circumstances). (Also applies for sap_bot.lua:L2158, and literally all over sapbotcreator.lua). These could be cached outside of the hook/function and reused for better preformance. See note https://wiki.facepunch.com/gmod/Global.Color.

  3. In sap_bot.lua, alot of static Vectors are created in loops / functions that could be cached. Mainly alot of Vector(0, 0, 0) calls across most pathing functions. See note https://wiki.facepunch.com/gmod/Global.Vector.

  4. Vector:Distance is used quite alot where Vector:DistToSqr would be better. https://wiki.facepunch.com/gmod/Vector:DistToSqr

#

I wanna reiterate that this is a very cool addon, It's very hard to make something this complex without having some efficiency losses along the way. Great stuff otherwise

grim meteor
#

yeah also rn ScanEntities is kinda placeholder, as it does multiple sphere checks 'n such, in an ideal world i would only do it once, but it was a last minute update change.
with stuff like creating new instances of variables, i try to avoid it as even just the act of creating a local variable is accessing ram in excess, so when doing loops and such i reuse values a lot, but its causing there to be a lot of variables on the entity, so its a 50/50 with my optimization on that regard, no ideal solution for that, but yeah the color value is useless, i was lazy there.
i use DistToSqr a lot, but in some situations exact distance values are needed, its a nightmare when done in the rendering..
square root / division is a nightmare.

#

also ignore my phoneme related code, its a hell script that idk if i'll ever be able to improve on,
i wrote it up in some sort of daze, with no memory of what i was thinking and very little notes,
as with most of my code

#

for stuff like this i've essentially made multiple mini markdown programming languages,
that i then use all over the place, to make formatting easier,
but in situations like this, its on par with shit like Brainfuck, incomprehensible to humans without a lot of research and debugging

#

its useful in their dialog datasets though, stuff like this means accessing other sap bot names and knowing where the text generation can end, is more manageable than other methods

#

though there's cursed shit also that i am very aware of, like this where it manually goes over a bunch of transformations of the tts in the most scuffed lazy way ever

#

its cause i couldn't be fucked with making something better that would handle the logic of turning numbers into text that the tts engine could process, same with stuff like shortenings of words

dapper patio
#

Kill them while you still can...