Storing large number of objects in a map (Gaming)

D.V.D

Make a wish
Reaction score
73
So I was reading a PDF of the Cuda program for Nvidia Graphics Cards and when I was thinking about how to create my own graphics engine, I came across this problem. So in this case, let's say that im ray casting to find objects on a map that is 10km by 10km. If the smallest point on my map is 1 millimeter, that would result in the map being 10 000 00 00 0ml by 10 000 00 00 0ml. This would result in a ridiculously large 2d array of 1 000 000 000 000 000 000 mm square. So using a 2d array to store all objects on the map would result in terabytes of information which is largely impossible. So then came the problem, how would I find objects on my map? I could loop through every object on the map every time a ray moves to see if the object is hit by the ray but lets say you have a very detailed scene. For example, in Warcraft 3 you would have sometimes 10 000 to 100 000 doodads on a detailed map followed by a number of units that can also be from hundreds to thousands depending on the map. This however is warcraft 3, if your making a detailed map like this so for example skyrim, you can have millions of objects on the map and looping through each one of them for every ray would be far too slow. So my question is, are there any efficient ways of storing large amounts of objects on a large map while not going overboard in the number of operations done to find the objects using ray casting methods.
 

s3rius

Linux is only free if your time is worthless.
Reaction score
130
Usually you don't store what object is in each square millimeter (that's nearly impossible, as you said), but you store each object's X/Y coordinate.

Also, for such large maps you only store a small portion of all objects for ray-casting (or anything else). Say 100m².

Now, I know how games like Dead Rising handle their hundreds of zombies etc:

They take two lists. They put all objects in this 100m² radius into the two lists. The first list keeps them sorted by X-position, the other one by Y-position.
Now it's very easy to determine the position of nearby objects relative to any object.
Just search the object in both lists and check all following (or preceeding) objects whether they intersect the ray.
 

D.V.D

Make a wish
Reaction score
73
Storing the map in a array is only helpful for small maps that would be for example, rooms or inside of houses.

Oh i see, but wouldn't you have to loop through all objects/models on the map to figure out what objects are near you? And for larger maps, that turns out to be thousands+ amount of models in the game.
 

s3rius

Linux is only free if your time is worthless.
Reaction score
130
You'd have to sort them once into the two lists, then regulary update them so the lists are up-to-date.

After that you have a list that looks like this:

[Unit 2] <-> [Unit 6] <-> [Unit 1] <-> [Unit 3] <-> [Unit 5] <-> [Unit 4]

All units are sorted by X-position, so U2 has lowest X position and U4 has highest.
If you now want all units nearby U1 you have to find U1 in the list. Then you can take the previous and following units in the list and see if they're close enough. Once a unit is too far away you know that all following units are too far away too (since they're sorted by x pos).

This would already be enough to make a decently fast search if you have tons and tons of items.
The second list (the only sorted by Y) can help you in finding it even faster, but isn't actually needed so much.
 

D.V.D

Make a wish
Reaction score
73
Oh i see how it works. Before I was thinking of dividing the map into 10 000 squares, if the map is as labeled as 10 by 10km. Each square would then be 10m by 10m and if a object moves or is created, its position is rounded to the nearest square. Each square would then have a list of objects in it and you could rather than loop through all units on the map to find their position, you would just loop through all units in the square that the ray is in.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top