Question about S3k's collision bug

Discussion in 'Engineering & Reverse Engineering' started by FireRat, Apr 18, 2018.

  1. Cooljerk

    Cooljerk

    NotEqual Tech, Inc - VR & Game Dev Oldbie
    4,332
    70
    28
    Take note, oldbie, the trial member above is showing you up on your behavior. There is nothing wrong with asking for further clarification and if you don't have anything else to contribute beyond snark, don't post.

    Much appreciate this response.
     
  2. flamewing

    flamewing

    Emerald Hunter Tech Member
    1,138
    0
    16
    France
    Sonic Classic Heroes; Sonic 2 Special Stage Editor; Sonic 3&K Heroes (on hold)
    Note that those are for different kinds of collision (solidity vs touch). The checks probably would not be imported by having Tails and Sonic do the touch loop together because of 2 things:
    1. The loop figures out Sonic's/Tails' hitbox and position once and caches it in registers, then uses these values for touch checks with all objects. Doing Sonic and Tails together would require figuring out hitbox and position for Sonic, checking touch with one object, then figuring hitbox and position for Tails, and checking touch again.
    2. The loop stops after the first touch. With the combined loop, you cannot do this or Tails will not touch any objects on a frame in which Sonic also touches.
    Also, you can just convert touch to a subscription-based model like in S3/S&K/S3&K, which only check touch with touchable objects.
     
  3. Cooljerk

    Cooljerk

    NotEqual Tech, Inc - VR & Game Dev Oldbie
    4,332
    70
    28
    Would you mind going into a bit more detail about this? Doesn't have to be as dense of a post as you made before or anything, but that sounds interesting.
     
  4. flamewing

    flamewing

    Emerald Hunter Tech Member
    1,138
    0
    16
    France
    Sonic Classic Heroes; Sonic 2 Special Stage Editor; Sonic 3&K Heroes (on hold)
    Objects have a field called collision flags. This field controls both the size of an object's hitbox as well as how the collision is processed. If the collision flags are zero, there is no collision. Most objects have zero in their collision flags.

    In S1/SCD/S2, this means a lot of time is spent going through the object slots checking collision flags, and skipping all those with zero collision flags (which includes those empty object slots). This is done twice in S2, for Sonic and for Tails, and consumes a few thousands of cycles per character per frame when all objects are skipped.

    S3/S&K/S3&K have a buffer in RAM with the addresses of all objects that are touchable, with a count at the beginning of the buffer. Each object is responsible for adding itself to the list, and the list is "cleared" after the code for Sonic and Tails code has finished executing and before all other objects execute their own coffee; this is done by setting the number of objects in the list to zero. The collision code only checks objects on that list, which avoids uselessly processing a lot of objects.

    The amount of cycles saved this way is spent by having shields also check projectile deflections against all objects in this list. Hyper Sonic's hyper dash, Hyper Knuckles' for into wall, and Super Tails' flickies also use the list for checking targets.
     
  5. Cooljerk

    Cooljerk

    NotEqual Tech, Inc - VR & Game Dev Oldbie
    4,332
    70
    28
    Ah! THIS is the type of "speed up" I was talking about in pervious posts when I mentioned a "buckets" approach. This is precisely the type of thing I've been poking for in this topic, thanks so much!