A Gravity & Pressure revamp is needed

  • motaywo
    March 2017 Member 5 Permalink

    VVV - 1st Paragraph optional - VVV


    (Read the ramble below if you want to - it explains what I'm asking)  (Example Save - id:2116090)

    I realized the other day that pressure and gravity are operating on an older framework than particles in TPT. The pressure/gravity engine operates using the same 4x4 grid that WALL uses, which means powders and liquid don't actually react on a pixel by pixel basis. Any pressure or air velocity created is constant within 4x4 chunks, which is why one pixel thick TTAN can't block pressure, even though it's programmed to.

    Newtonian Gravity works the same way, which is why it's nearly impossible to orbit something something around BHOL, but not too hard to do with radial gravity on. Save gravity operates pixel by pixel, but newtonian gravity does not.


    (DO read this - this IS what I'm asking)

    If you read all of that above, I salute you. If not, no worries. 

    Basically, what I'm saying is that the air/gravity engine should be updated to calculate pressure, gravity, and velocity, for each pixel.


    The change would be a toggleable setting in some future update, similar to the way "newtonian gravity" or "water equalization" can be switched off or on. There might be a performance dip, but by having it switchable the impact would be no different than the "water eq. settings" : slightly laggy when on, not laggy when off.

    By maintaining part of the old system, older saves would be unaffected, but newer saves could choose to use the higher resolution.


    Benefits would include more reliable contruction methods, more detailed and intricate mechanisms or sensors, and the possibility of creating pneumatics or hydraulics-based machines! (... bicycle pump anyone?...)


    I don't expect this to be implented any time soon (although sooner would be nice!) - I'm not a programmer, but I can assume it won't be as simple as just changing a number in the code. I realize it will take time, I'm just putting it out there for anyone looking for a challenge.

    Edited once by motaywo. Last: March 2017
  • space_powder
    March 2017 Member 1 Permalink

    Honestly, this is so relatable.


  • Atari
    March 2017 Member 1 Permalink
    This is actually a fairly good idea.
  • jacob1
    March 2017 Developer 0 Permalink
    The main issue is this: "The change would be a toggleable setting"

    It would take some rewrites to allow it to be toggleable. The arrays for air / gravity are a fixed size. It would definitely be possible with some rewrites, I guess.

    Another issue I know of is that the air simulation doesn't work properly on a 1x1 grid. Basically that is like making the distance between everything 4x bigger. Everything, such as explosions, would travel 4x slower. So it's not just as simple as changing CELL to 1, you also have to make a lot of adjustments to the simulation itself. I didn't create the air sim so I don't know the best way to do this and make it still act the same as it does now.

    Part of the reason we are 4x4 currently is because it is a lot slower to do 1x1 grids. Newtonian Gravity is already multithreaded. If you don't use GRAVFFT is it very slow to use a 4x4 grid, and a 1x1 grid would be worse. This means the android port wouldn't be able to use 1x1 Newtonian Gravity. And I don't know what the performance of Newtonian Gravity would be on the PC version since I've never tested a 1x1 grid. I do know air would be a lot laggier, it would probably have to be multithreaded to make this possible too.
  • Lord_Bowserinator
    March 2017 Member 0 Permalink

    @jacob1 (View Post) A while ago I tested a 1x1 grid, averaged around 16-20 FPS on a save with some AIR blowing around.


  • motaywo
    March 2017 Member 0 Permalink

    @jacob1 (View Post)

    I admit I understand very little of what you were talking about, and I know almost nothing about how TPT was programmed. However, I do have a fair bit of experience with music software (i.e. Logic, from Apple), and something you said gave me an idea.


    (Feel free to correct me if I'm wrong) - One of the significant problems implementing this, as I understand it, is that by reducing the grid size to 1x1, the simulation would be calculating 4x more data, which would make it 4x slower, and then we'd have additional lag on top.


    In music software like Logic, the more realistic synthesized instruments are super data-heavy, and I've had times where my computer just can't manage the system load when playing in real-time.

    However, Logic has an option where it preprocesses the audio track beforehand, then uses the high-resolution audio only during playback. (In Logic, they call the setting "Freeze")    The catch is that you can't make changes during the high-res playback, without 'unfreezing' the track.


    Would something like this be possible in TPT?:


    1. We would be using the simulation normally (with the 4x4 grid)

    2. If we wanted to test with the higher resolution, we would pause the sim, open the simulation options panel, and select the 1x1 grid.

    3. When we close the panel and un-pause, the game would take 10-15 seconds to buffer/process and then display the playback at a comfortable FPS.

    4. Each time we pause to make a change and resume, there would be a few second delay for the system to buffer, but because it would be toggleable, we would only have to wait if we really wanted to test with the smaller grid.


    I could talking complete nonsense in terms of what's possible, but if it could work, it would probably be an acceptable compromise between resolution and simulation speed.

  • zaccybot2
    March 2017 Member 0 Permalink

    That would be very difficult to implement, and just a side note real quick, it is calculating 16x the data

  • Emperor_Bowserinator
    March 2017 Member 0 Permalink

    @motaywo (View Post) TPT isn't exactly meant to be an accurate aerodynamics simulation, more of a game. How many people would actually use TPT for that purpose (Especially when there are tons of more accurate air sims out there). 


  • motaywo
    March 2017 Member 0 Permalink

    @Emperor_Bowserinator (View Post)

    I see what you mean, and totally agree... I can just get really, really carried away...


    As you say, this isn't supposed to be a NASA/JPL level simulation - who knows, maybe 30-40 years from now, when a future generation is playing this game on quantum computers, they'll be able to do it... (and there I go again...)

  • jacob1
    March 2017 Developer 0 Permalink
    @motaywo (View Post)
    Actually a 1x1 grid is 16x slower than 4x4. That is 16 times the space.

    A "buffer" sounds like an awful idea to me. TPT doesn't buffer stuff, it just runs it at whatever FPS it can put out. It's entirely normal to not be at 60fps, we've never done any buffering to try to keep 60fps because that would make the game terrible to play. You can't buffer air simulation changes without also updating the entire simulation.

    I don't know how much the slowdown would be, but putting it in another thread would definitely help since air can be an expensive calculation. Buffering isn't the answer.

    Another easier solution is just to keep it 4x4, but do some averaging to calculate the "local" pressure / gravity.
    Edited once by jacob1. Last: March 2017