Plombo
I'd like to get your opinion on a pretty drastic internal change I'm thinking about.
I've been working on cleaning up the collision logic, and more and more I'm thinking the collision types need unifying. I don't mean as in make one super box, but instead to add a layer of abstraction.
Current Method
There's also a third collision set at the moment, but we won't get into that. The thing you'll notice is that coords all use the same structure across the board, but because coords are a property of attack and body respectively, they are part of separate parent pointers on an entity and have to be handled as such. In turn, this means the collision logic starts to get redundant real quick.
Here's how we find collisions now:
[list type=decimal]
[*]Loop through each entity as a possible target.
[*]Loop through all of SELF attack boxes at current animation frame.
[*]
[list type=decimal]
[*]Loop through all body boxes for current TARGET, calculate absolute coordinates for body/attack, and compare for a collision.
[*]If SELF attack has counter property (or upcoming clash property), we loop through all attack boxes for current TARGET'S's animation frame, calculate absolute coordinates for body/attack, and compare for a collision.
[/list]
[/list]
Possibly two nested loops, and a LOT of redundant code.
Proposed Change
Now the collision logic looks like this:
[list type=decimal]
[*]Loop through each entity as a possible target.
[*]Loop through all of SELF collision boxes at current animation frame.
[*]
[list type=decimal]
[*]If SELF collision box is an attack, loop through all collision boxes for current TARGET, calculate absolute coordinates for body/attack, and compare for a collision.
[*]If the opposing box is an attack, then verify SELF attack can clash or counter. Otherwise ignore it.
[/list]
[/list]
I think this logic will be slightly faster overall, and it will certainly eliminate a lot of redundant code. It should also be easier to deal with when using script access, and IMO much more extensible.
Other than the code work (which is on me), do you see any major pratfalls to this approach?
I'd like to get your opinion on a pretty drastic internal change I'm thinking about.
I've been working on cleaning up the collision logic, and more and more I'm thinking the collision types need unifying. I don't mean as in make one super box, but instead to add a layer of abstraction.
Current Method
Code:
s_collision_attack_list (one) -- (many) s_collision_attack
- s_coords * coords
- int index
- int tag
- ...
s_collision_body_list (one) -- (many) s_collision_body
- s_coords * coords
- int index
- int tag
- ...
s_coords * attack_coords = {entity}->animation->collision_attack[{frame}]->instance[{instance}]->coords;
s_coords * body_coords = {entity}->animation->collision_body[{frame}]->instance[{instance}]->coords;
There's also a third collision set at the moment, but we won't get into that. The thing you'll notice is that coords all use the same structure across the board, but because coords are a property of attack and body respectively, they are part of separate parent pointers on an entity and have to be handled as such. In turn, this means the collision logic starts to get redundant real quick.
Here's how we find collisions now:
[list type=decimal]
[*]Loop through each entity as a possible target.
[*]Loop through all of SELF attack boxes at current animation frame.
[*]
[list type=decimal]
[*]Loop through all body boxes for current TARGET, calculate absolute coordinates for body/attack, and compare for a collision.
[*]If SELF attack has counter property (or upcoming clash property), we loop through all attack boxes for current TARGET'S's animation frame, calculate absolute coordinates for body/attack, and compare for a collision.
[/list]
[/list]
Possibly two nested loops, and a LOT of redundant code.
Proposed Change
Code:
s_collision_list (one) -- (many) s_collision
- e_collision_type type (bitwise flags)
- s_coords * coords
- int index
- int tag
- s_attack * attack (old attack properties)
- s_body * body (old body properties)
s_coords * <any type>_coords = {entity}->animation->collision[{frame}]->instance[{instance}]->coords;
- We'll avoid wasting memory by simply not allocating properties that aren't needed (i.e. if it's just a body box, don't allocate memory for attack properties). Obviously several properties between the collision types could be consolidate, so there actually should be a net memory savings.
- Entity has a single array pointer for all collisions replacing the current array pointers for attack, body, and space.
- The type property will tell us if this is a space box, a body box, attack box, or whatever else. We'll use bitwise logic so its possible to be more than one type.
Now the collision logic looks like this:
[list type=decimal]
[*]Loop through each entity as a possible target.
[*]Loop through all of SELF collision boxes at current animation frame.
[*]
[list type=decimal]
[*]If SELF collision box is an attack, loop through all collision boxes for current TARGET, calculate absolute coordinates for body/attack, and compare for a collision.
[*]If the opposing box is an attack, then verify SELF attack can clash or counter. Otherwise ignore it.
[/list]
[/list]
I think this logic will be slightly faster overall, and it will certainly eliminate a lot of redundant code. It should also be easier to deal with when using script access, and IMO much more extensible.
Other than the code work (which is on me), do you see any major pratfalls to this approach?