Jump to content
  • Advertisement
Sign in to follow this  
adam23

RTS advice

This topic is 4406 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am starting work on a 2D RTS game. This will be the hardest game I have worked on to date. I know pathfinding and state machines fairly well. The problem I have is in structuring my game. I am planning 8 - 10 different character types. Say there are 100 enemies in the game so each one has to have a copy of the map that is 64 x 64 nodes. This doesn't seem to big at first but right now I have the map loaded from a file so each enemy would need to load an individual map. This would cause a huge loss in performance if I am reading from a file everytime a character is created. What is the ideal way to handle a problem like this? I thought about loading one global map and then just copying data to new maps as it is needed, but I still feel that copying 4096 nodes everytime a character is created can get costly. Anyway you can look at what I have right now here: http://adamwlarson.com/RTS/RTS.zip The selection box can be drawn but it doesn't do anything right now. You just right click to guide the soldier along the map. The map can be scrolled by getting the mouse close to the edge of the window.

Share this post


Link to post
Share on other sites
Advertisement
Why would every unit need it's own copy of the map? Can't you just give them a pointer or reference to the map data they need?

You could also consider building a pathfinding module, so units can ask it to create a suitable route for them. Whatever you do however, I see no reason why every unit should have it's own copy of the nodegraph.

Share this post


Link to post
Share on other sites
Maybe I am doing something wrong in my A* implementation. I have a node map of 64 x 64 nodes that stores information such has heuristics cost, total cost, and path cost. Each unit would have a different value stored in the map than another one. Here is my node structure.
//Define the node
struct Node{
bool blocked;
bool visited;
int weight;
Node *parent;
int x, y;
int m_f,m_h,m_g;
}
weight is just the value I use to reset the values of the map when searching for a new path. So if weight is 4 I would set m_g to 4, then m_h woul be the heuristics cost and m_f would be the total m_g + m_h which is how the node is sorted in my ordered linked list. parent is used to back track through the found path.

Share this post


Link to post
Share on other sites
Just build a pathfinding system that contains the nodegraph, and give it a function that returns a path, then have units call this function when they need a path to move on. This system should maintain the nodegraph so it's always ready to generate a path for whoever asks for it. This way, you've elminated the node copying as well as the memory overhead.
As for unit types using different heuristic values, you could incorporate that by providing a function that sets the heuristic cost of the various tiles.

So, for example, when a soldier needs to get moving, it calls the pathfinder:
pathfinder.SetHeuristics(5, 3, 4, 1, 2, 4);
path = pathfinder.GeneratePath(start, end);
If there's a lot of different tiles, an array, or struct, would be better. Alternately you can put this into the pathfinder itself, by adding a 'value profile' and using a function to select a given profile, one for each unit type. You could make it load such profiles from a script for easy tweaking, too...

// Your demo doesn't run on my system bytheway, I get an error saying it's missing the d3dx9d_30.dll.

Share this post


Link to post
Share on other sites
Quote:
Original post by Captain P
[...]Just build a pathfinding system that contains the nodegraph, and give it a function that returns a path, then have units call this function when they need a path to move on. This system should maintain the nodegraph so it's always ready to generate a path for whoever asks for it. This way, you've elminated the node copying as well as the memory overhead.
As for unit types using different heuristic values, you could[...]
This removes the ability to multithread pathfinding.
I say you should store a node graph that has global data (location, connectivity, weights, etc). Then, for each path you want to find, you create a 'path graph' that stores per-instance costs (heuristic and actual) and other info (in closed list or not). The latter structure allows for pausing and resuming pathfinding at any time without another path search corrupting the data. When you're done with the 'path graph'(you've found a path), instead of deleting it, just put it in a list of available 'path graphs' that you use for the next searches.

You might need more than one global table (for different movement modes, such as flying, walking, submarine, etc), but you only need one per movement type and you can load it at the start of the game.

Share this post


Link to post
Share on other sites
That is an excellent idea, I am going to try and implement it this way. One of the problems with doing it the way mentioned before for my program is that I don't want to tie up the entire game loop until a path is found. If 100 characters need a path at the same time, I would have to sort them and only do one or two per loop. Thanks for the tips everyone, I really appreciate it :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!