|
|
|
|
Reply From: |
IHate |
I don’t know anything about your project but you are using a lot of arrays for what seem like simple tasks to me. You don’t need to save every piece of data, you can get it at runtime as you need with functions or signals.
The only reason I can think of for a simple turret to store 5 different enemies is if it is able to shoot 5 enemies at the same time. Otherwise you can just create a function on the turret that targets the closest enemy or the enemy with the most health,etc, making a behaviour that store the current target in case you want to keep the first target under fire even if it is not the closest enemy or the healthiest that way you save some memory.
If you can shoot 5 targets with a single turret this function would add them to the array as they get in range and then another would erase them as they leave. You can use signals to tell the function what enemy is in range with area entered or something like that.
You don’t need to store the enemies until they are in range unless you want to track for a very specific reason.
Make your turrets a scene so they can pick their targets on their own store their targets and ignore anything they don’t care about.
Is hard to tell without knowing more about what you exactly need but either way arrays must be huge to feel a significant slowdown. I’ve read some people storing the entirety of their game’s dialogue in a single array (I would parse it as I need it tho). Rendering things can take a bigger toll on your game’s performance than an array.
thanks for the feedback , my project is a top down tank RTS effort, and is coming along pretty good. my turrets are scenes of their own and their targeting array only stores the information of opposing units in their detection radius, I don’t see that there is another way to make that work, all turrets do target for themselves , I can select a tank and change its target focus to another unit but only within its detection radius. when I mention targeting array I am considering down the road when I add in other units particularly foot soldiers, it is not the size of one targeting array I was talking about , it is the impact of having a battle with a lot of forces involved.
I don’t think I indicated I am trying to store superfluous data but to get enemies doing something more than running around on predetermined paths storing data is required and there is no two ways about that.
I am really just curious about types of arrays for different types of data or if the arrays I am using are fine for the types of data, I doubt I am in danger of much memory impact at this point but figure I should have scaling in mind.
ArthurER | 2020-10-09 02:34
If you are storing all the units in range but you can shoot them all at the same time the information is irrelevant.
How are you updating the targets array? if its an RTS you are doing it every frame I imagine.
So why store all these enemies you don’t care about right now.
If you want to target another unit in range make a function that enables a “targeting mode” during this mode the turret displays its range and the units inside so you can swap targets once a target is selected end the “targeting mode” and stick to 1 target so it only needs to track that. If the target dies or runs away you can do an auto targeting and picks the closest enemy.
I’m not a very experienced programmer but I just don’t see the point storing all this data if you store it means you need it every time on every function, and I don’t think your turret is using all that info at all times. It will escalate quickly and it will be redundant most of the frames.
a bunch of arrays but small shouldn’t be a problem if you are using arrays that contain only 1 type of information use a poolarray there’s 7 types of pools in godot: Array — Godot Engine (stable) documentation in English
Optimized for memory usage, does not fragment the memory.
the target array is updated @ on_body_entered and @ on_body_exited because that is when the reference to the body is passed to the area and that does not happen every frame that a body is in the area it happens one time when the body enters or exits the area , if it is not accepted then then the turret would have to do a more frame by frame check for overlapping bodies, and that would break more than it would fix the turrets _process(delta) begins with “if target” that script does nothing until the detection radius pushes a target into the array @on_body_entered when targets have exited the array is empty and the turret returns home the script becomes inactive , with empty arrays.
some of what you are saying here just does not make sense for the action of autonomous units , if five units of an opposing force are in the detection radius of a unit, the purpose for that information is not limited to targeting , it also at the same time means that five units are targeting it , I don’t see how that information is irrelevant if I stand any chance to make some AI for units it is not going to be by discarding information like that.
perhaps you are imagining a player script driven by W, S, A, D keys and an enemy script , but that is not what I have I have a vehicle script and a turret script, that all units share , the player can move units to locations and change target focus , the enemy AI can so far scout and I just got it to select a scouted target and launch its first attack, it would not be able to do that discarding the information you are saying is not relevant.
ArthurER | 2020-10-09 15:24