Tiny 5 Bit Computer (mapS)

  • ichee007
    5th Jan 2013 Member 0 Permalink

    @drakide (View Post)

     Hi,

    Im from germany and i want to make a Video about your Computer because its AWESOME !
    I make TPT tutorials in german but i want to show your creation, because I want to show my viewers what is possible.

     

    You can watch my videos here: https://www.youtube.com/user/MegaTheoretisch?feature=mhee

     

    If you agree or want to talk write me an mail with your skype-name or ICQ or watever you have to: robin@gtl.de

     

    Yours sincerely,

     

    Robin

  • Cheesepuff2
    5th Jan 2013 Member 0 Permalink

    How do I even click the buttons!? I don't get how you do it!!

  • dom2mom
    8th Jan 2013 Member 0 Permalink

    @drakide, oh, whoopsie, I thought you were talking about somethign different XD

  • Bekas
    9th Jan 2013 Member 0 Permalink

    @drakide

    Store particles in a matrix. (I think powder toy stores all particles in an array/list which seems awfully inefficient to me. A matrix would allow saving a **huge** amount of computations at the cost of RAM.)

     

    The difference in performance from 1d vs 2d arrays is negligible.

     

     

  • belugawhale
    11th Jan 2013 Member 0 Permalink

    Just as a troll, i chose 3.14 as my number, and it said I was lying!

  • Box-Poorsoft
    11th Jan 2013 Banned 0 Permalink
    This post is hidden because the user is banned
  • drakide
    13th Jan 2013 Member 0 Permalink

    @Bekas (View Post)

     The difference in performance from 1d vs 2d arrays is negligible.

    That depends on how you use them. TPT seems to simply append all nbew particles to a huge list. Whenever a particle needs to check whether it can move somewhere it has to traverse the complete list in order to check whether it is obstructed. The same happens whenever a spark needs to check whether it can spark any particle in the environment. I assume that the list is traversed several thousand times per frame in a decent simulation. When the particles would be stored in a matrix though the random access time to all particles is constant (and very low). This would of course use huge amounts of memory. (On a 604*376 simulation about 2*604*376*8 Bytes, which is about 3.5 MiB.) However those 3.5 MiB can easily be managed by every decent PC but would result in a huge speedup. I wouldn't call that "negligible".

    Note however that I never took a look at TPT's sourcecode. 

  • jacksonmj
    14th Jan 2013 Developer 0 Permalink

    @drakide (View Post)

    Particles are stored in a huge list, but there is also a particle map - a matrix which contains information about which particle (if any) is in each position. This matrix stores the particle's type and list index.To check which particle is in a particular position, one element of this matrix is accessed.

     

    Here is a fictional example of the complete source code for a neighbour interaction (excluding variable declarations). It accesses 8 elements in the particle map (pmap), corresponding to the 8 neighbouring positions around position (x,y). At no point does it traverse the entire list of particles (parts).

     

        for (ry=-1; ry<2; ry++)
            for (rx=-1; rx<2; rx++)
                if (x+rx>=0 && y+ry>=0 && x+rx<XRES && y+ry<YRES && (rx || ry))
                {
                    r = pmap[y+ry][x+rx]; // Access one element of the particle map, which contains information about the particle at position (x+rx, y+ry), if any
                    if (!r) // If zero, there is no particle in this position
                        continue;
                    if ((r&0xFF)==PT_BRAY) // Check the type of the neighbouring particle
                    {

                        // Do stuff with this particle, using the list index from the particle map

                        // For example, set the life of the neighbouring particle to 4
                        parts[r>>8].life = 4;
                    }
                }

     

    TPT can't store all the particle data in a matrix, because TPT allows multiple particles to be in the same place (e.g. photons). With a matrix, there is only room for one particle in each position.

  • drakide
    15th Jan 2013 Member 0 Permalink

    @jacksonmj (View Post)

     Thank you for the clarification.

    TPT can't store all the particle data in a matrix, because TPT allows multiple particles to be in the same place (e.g. photons). With a matrix, there is only room for one particle in each position.

    Using a matrix wouldn't be much of a limitation to that. PIPE too does not seem to actually move particles but instead absorb them and release them afterwards. A similar approach could be used for Photons in GLASS, FILT, ... . This would of course increase the amount of code and i personally wouldn't do it like that.

    However if TPT uses a "particle map" its fine with me. (Whats the difference anyway?) One question remains though: How does the particle map handle multiple particles in the same location? Is it a map of lists?

  • jacksonmj
    15th Jan 2013 Developer 0 Permalink

    All particles have 56 bytes in which to store particle properties. PIPE squeezes most of the properties of the absorbed particle into properties that it doesn't use, but this is imperfect - only one particle can be absorbed, and some of the properties are lost. So yeah, doing it that way wouldn't really be practical.

     

    At the moment, the particle map doesn't handle multiple particles in the same location (or at least, it doesn't handle them well). It can only store information about one particle in each position.

     

    This does cause a few problems. Some of these problems can be mitigated with various tricks, but this isn't entirely satisfactory and a map of lists is something that I'd like to test out at some point. There are actually two particle maps - one for particles that can block movement of other particles and don't usually overlap, and one for energy particles like photons and neutrons that overlap frequently and don't affect movement. Both maps are recalculated each frame, just before all the physics and particle interactions happen. Access to the first particle map is prioritised so that, for example, INVS does not overwrite an entry for another particle in the same position, meaning that collisions work correctly inside INVS. 

     

    The difference between a particle map and storing all the data in a matrix: The particle map stores 4 bytes of data for each location. 1 byte is for the particle type (DUST/WATR/etc), and the other 3 for the index in the parts array. The 56 bytes of particle properties (particle type, position, velocity, etc) are stored in the parts array, instead of directly in the particle map.