Search Unity

Efficiently simulating 3d world without visuals

Discussion in 'Scripting' started by Sendatsu_Yoshimitsu, Oct 21, 2016.

  1. Sendatsu_Yoshimitsu

    Sendatsu_Yoshimitsu

    Joined:
    May 19, 2014
    Posts:
    691
    I'm working on a military grand strategy game that takes place in a 3d world, but doesn't have any 3d graphics; all of the UI uses icons on flat maps and charts.

    The most direct way to accomplish this seems like it would be treating it like a rogue-like: make a 3d grid of some tile data struct which has stuff like terrain height, terrain type, and collision properties, and maintain separate lists of each entity type (infantry, tanks, planes, etc), where each entity keeps track of its own coordinates.

    This is the sort of thing that works great on a small scale, but in order to accurately simulate an entire world I would need to do it on the scale of millions of tiles, at which point it becomes way less performant. I could cut the tile data down to a single integer representing elevation, and maybe divide the world into tons of, say, 100k X 100k X 100k chunks, which in turn would require a reasonably involved amount of work to ensure stuff was getting pooled and streamed in/out in an efficient way.

    I think I'm barking up the right tree, but before I toss a nontrivial amount of work into getting the streaming chunk thing working, I wanted to see if my general approach makes sense to anyone else- I can't see how you could simplify it more than I have, but I'm hoping there's something incredibly obvious I missed by going for the direct approach.
     
  2. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,698
    For the entities, instead of a grid or a single list, you need a quadtree. The 3D equivalent is an octree, but I think it would be overkill in this scenario.

    For the terrain data, if you can generate it from a function, then you don't need to store hard-coded data for each coordinate and stream chunks.
     
  3. Sendatsu_Yoshimitsu

    Sendatsu_Yoshimitsu

    Joined:
    May 19, 2014
    Posts:
    691
    The reason I'm still kinda clinging to the hard-coding is because I was originally planning on expanding the world generator to work like dwarf fortress does, where you do several passes of heightmaps/cellular automata for wind, rain, temperature and so forth, layer them together, then determine the terrain type based on the aggregate results, but the more I look at the nightmare hard streaming would be, the more I think you're absolutely right and a simpler deterministic alogrithmn would be smarter.

    On the topic of entities, I understand quadtrees in theory, but I'm mainly used to thinking of them as vehicles for lots and lots of LOD, so I'm not sure I'm quite seeing how they would work for the entity list- is the idea that they're inherently a more performant container to iterate through than a simple list/array every time I need to see if there's anything at a given coordinate?
     
  4. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,698
    What about a hybrid with regions that use a library of predefined layers -- essentially a tilemap where each tile covers a larger area than a single grid point.

    Yes, exactly.
     
  5. Sendatsu_Yoshimitsu

    Sendatsu_Yoshimitsu

    Joined:
    May 19, 2014
    Posts:
    691
    Hmm, that's a really neat idea- let me mess around and post back if I end up with something cool; I've never put any thought into doing it deterministically, but I'm betting there are at least a couple of very well-tested solutions once I dive into the literature.
     
    TonyLi likes this.