RTS advice
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.
Adamhttp://www.allgamedevelopment.com
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.
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.
Create-ivity - a game development blog Mouseover for more information.
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.
//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.
Adamhttp://www.allgamedevelopment.com
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.
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.
Create-ivity - a game development blog Mouseover for more information.
Quote: Original post by Captain PThis removes the ability to multithread pathfinding.
[...]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[...]
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.
"Walk not the trodden path, for it has borne it's burden." -John, Flying Monk
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 :)
Adamhttp://www.allgamedevelopment.com
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement