find all particles IDs stored in x, y

  • wisecase2
    11th Oct 2018 Member 0 Permalink

    I'm building a mod that makes it more realistic. is it possible to find all particle IDs stored in a location x, y? so I know I can get only one with pmap [x] [y] or photon [x] [y] (if it is energy), but it is possible that it has more than one particle in the same position in the game, since several parts[i] can have the same location x, y. example: I find all particle IDs belonging to the NEUT element in the x, y coordinate. (sorry bad english)

  • jacob1
    11th Oct 2018 Developer 1 Permalink
    No, this isn't possible in constant time. You can only see the top particle in pmap and the top particle in photons. pmap is regenerated once a frame by looping through every particle in parts[] and adding it to pmap.

    This is why stacking is "unsupported" and generally not used in official reactions. Only energy particles can stack during normal movement. There isn't any element that can see elements "underneath" nearby particles, they all only react with the top particle.

    You can loop through the entirety of parts[] if you want to find everything in a specific spot, that is the only way. There's potentially some other highly specific custom code you could write, but there is no generic way.
  • wisecase2
    12th Oct 2018 Member 0 Permalink

    I have an idea, I can create another 3-dimensional vector and use the radix storage mode to store the remains of the particles, I'm going to test how much it will weigh (probably little compared to the rest of the processing (updates, graphics, etc...)).

  • LBPHacker
    12th Oct 2018 Developer 1 Permalink

    You could maybe add a next pointer (would be a particle ID, not an actual pointer) to particles and then the pmap update loop would just append all particles in the same position to a linked list whose first item would be the first particle there. This would increase the particle structure size from the usual 56 bytes to 64, but hey, it would be pretty easy to implement, backwards compatible, would not require tricky data structures, and the pmap update loop would still be O(n).

  • QuanTech
    12th Oct 2018 Member 1 Permalink

    programmer brains are impressive

  • wisecase2
    12th Oct 2018 Member 0 Permalink

    @LBPHacker (View Post)

     the method of the next id pointer at x, y coordinates worked very well! except that I did not define a new property for particles, because it is not necessary since it needs updating every tick (I used currentTick to check if x, y was updated or not), it was simply to create another pmap2[yres] [xres] [3] (currentTick (if it was updated or not), first particle and last of the x,y), and idpoint [npart] [2] (with currentTick first and id of next particle). (sorry bad english)