Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


marc40000

Member Since 28 Feb 2010
Offline Last Active Jan 30 2013 02:29 PM

Posts I've Made

In Topic: Fast dyanamic_cast

28 January 2013 - 05:22 PM

I always wondered about something related. Assuming at some Point you Need to know what class an object actually is of. Then, as far as I understand, I could try dynamic_cast<> to all possible classes. And that's O(n), if n is the number of possible classes. So having a map or hashtable to just look it up should theoretically be faster for large enough n. Is this correct or am I missing a possible way to use dynamic_cast<> efficiently for this?


In Topic: Handling many objects

03 September 2012 - 06:07 AM

When I wrote my prvious post, I did a quick google of hashtable and java anf also found HashTable and HashMap. While HashMap looked more appealing than HashTable to me, I'ld prefer a generic version.

Spatial Data structures may look complicated at first sight. (Hashtables as well.) But if you don't have to implement them yourself and can use an existing working implementation, it's actually quite simple, as they do what you otherwise have to solve with loops over all objects and check for their positions. It's actually simplyfing your code while being faster. If you don't have many objects in your scene, the speed point might be neglectable though. From a theoretical point of view, assuming you have n objects in your scene and each does a spatial query that has to cycle through all objects, one gamelogic update will be O(n^2). That's really bad for large n. f you use a spatial datastructure, a spatial query goes down to O(log n) and for n objects, that gives us O(n log n) which is way better for large n. Assume n==1000, first scenario, that's about 1000000 "steps" while it's only about 10000 for the spatial data structure version. That's an acceleration of factor 100!

In Topic: Handling many objects

02 September 2012 - 12:14 PM

Yes, for example in php the associative array is implemented as a hashtable or map. In java, there is probably a hashtable implementation in the framework - but I haven't used java for years so I don't know what it's called. In .net for example it's called a Dictionary so it might not be called hashtable in java.

If each frame Update() has to be called on every gameobject, there is no way around actually calling it. I'm not sure what you mean with "recursively controlling itself". Instead of a hashtable or additional to it, you can have a logical tree structure where you put your objects in if you want. I think Unity does this. However, you probably want a hashtable next to it as well so you can get an object given its unique-id.

In Topic: World scale RTS

02 September 2012 - 10:57 AM

I tried something similar like you describe, even though it was less realistic and more fantasy style and less politics and more rts: http://www.confrontation-unlimited.net/cuweb/
The world is split into generated islands that connect through portals. That way, as the amount of players rise, the world can dynamically be resized everywhere, not just at the borders. It's browser based and from 2000, but it still works. There are screenshots on the page.

I'm also working on a newer version of it with a dedicated client and nicer graphics etc: http://www.confrontation-unlimited.net This is still in development, so there are some quirks here an there but basically you can build buildings and units and fight.

@Orymus3: Funny that you mentioned the fps mode as I had the same idea and tried that. Since everything is 3d and physically simulated, you can select a unit, press f3 and controll it directly. You can still command your other units around in this mode since you can still select them and give them a target. I'm not sure if this will stay a gimmick though. I can hardly imagine this to be of much use when two armies fight each other.

In Topic: Handling many objects

02 September 2012 - 10:40 AM

I think you need something like this. While an array might not be the best choice, you need a place where all you game objects are put in so you can do things with all of them like your move() or a general gamelogicupdate() or a render() etc.

I prefer to have a hashtable to store my game objects in. This comes with some handy features:
- you can still iterate over all your objects
- every object you create can get a unique id and you can store it in the hastable by that unique id. With an array you could use the index for that, but as the game continues, you get higher and higher ids while old objects get removed and you get holes in your array. OR you could put new objects at the places of removed objects, but then, your index-ids aren't unique anymore.
- each object having a unique id allows objects to reference each other without tricky sideeffects. For eaxmple imagine a unit A chase another unit B. You could add a reference of B in A and that way A can check B's location in the gamelogicupdate() and knows where to move. However, what if B gets destroyed? It get removed from the scene, but it keeps existing because A has a reference to it. If A only knew B's id, it can do the same as above by checking the hashtable of B and get B's position. When B gets destroyed, A will notice because the hashtable lookup will fail. Also note that references/pointers are only valid locally. When you add network play, you absolutely need some kind of unique ids.

Instead of a hashtable one could use a map. Besides that, you probably want a spatial datastructure as well to put your game objects in so you can do queries like "give me alle objects within a radius of 5m of point p.". One might be able to combine these datastructures somehow, I don't know thought. I always used those two next to each other.

PARTNERS