Creating a map editor like Warcraft 3

Started by
5 comments, last by FantasyVII 11 years, 2 months ago

Hello everyone,

I have created a 2D tile based map editor. It's perfect for me. I love it and it gets the job done. However I was watching this video and I didn't understand one thing. When the user place multiple tiles of the same type, how does the editor merge them into one? I just can't understand how to program this feature.

BTW I know that the map editor is in 3D.

">

Can someone please explain how this works?

Thank you smile.png

Advertisement
Every time a tile is placed, you scan the tiles around it, and if they meet certain criteria, you replace them with the appropriate tiles.

eg: If you drag road tiles into another road tile going the other direction, you replace it with a T junction tile. If the user drags a road into the other end of the T junction, it becomes an intersection.

The T Junction and Intersection tiles already exist in memory, but they are not user place-able. The user can only place the road, and the program will insert the T junctions and intersections as required.

Every time a tile is placed, you scan the tiles around it, and if they meet certain criteria, you replace them with the appropriate tiles.

eg: If you drag road tiles into another road tile going the other direction, you replace it with a T junction tile. If the user drags a road into the other end of the T junction, it becomes an intersection.

The T Junction and Intersection tiles already exist in memory, but they are not user place-able. The user can only place the road, and the program will insert the T junctions and intersections as required.

Thanks. That make sense :D

One last question. I have a small problem. If I try to draw more than 500 - 1000 2D tiles/ 3D objects my FPS drops. Now I know that you shouldn't draw more than 350 - 500 2D tiles/ 3D objects because the CPU can't send all those data fast enough to the GPU to process them.

So I put in a if statement and said if the camera can see these objects, draw them. if not, then don't draw them. and that helped a lot. However if I try to zoom out, you can see almost the whole map. and the map has more than 4000 tiles. so my FPS drops a lot. Is there a solution to my problem? The CPU just can't keep up.

How do all of these game render more than 1.3 million triangles and I can get 4000 tiles to be sent to my GPU fast enough? The only solution I can see is not to let the player zoom out that much.


To get the most out of your rendering speed you have to optimize everything.

Models are uploaded to the GPU's memory and drawn directly from there. There is nothing to send except the draw command.

Polygons are sorted by state to reduce the amount of times that drawing has to stop so states can be changed (rendering modes, material settings, textures, etc...)

Textures and tiles are atlased into one big image to reduce texture state changes.

Many other things, but I can't rewrite the whole book in a post, etc..etc... smile.png

So you could load up all your tiles onto 1 big texture, then create a static model of your map and upload it to the card. Then you just need to make 1 draw call to render the map. If needed, you can split the mesh up into smaller meshes. Like you said, you have 4000 tiles. Maybe split it up by 5 or 10 to get smaller renderable chunks.

I'm guessing you are drawing your tiles one by one?

To get the most out of your rendering speed you have to optimize everything.

Models are uploaded to the GPU's memory and drawn directly from there. There is nothing to send except the draw command.

Polygons are sorted by state to reduce the amount of times that drawing has to stop so states can be changed (rendering modes, material settings, textures, etc...)

Textures and tiles are atlased into one big image to reduce texture state changes.

Many other things, but I can't rewrite the whole book in a post, etc..etc... smile.png

So you could load up all your tiles onto 1 big texture, then create a static model of your map and upload it to the card. Then you just need to make 1 draw call to render the map. If needed, you can split the mesh up into smaller meshes. Like you said, you have 4000 tiles. Maybe split it up by 5 or 10 to get smaller renderable chunks.

I'm guessing you are drawing your tiles one by one?

yes I'm drawing my tiles one by one?

How can I send all my tiles directly to the GPU so I don't have to draw them one by one? I'm using XNA.

1) Put all your tiles on a bigger sheet, and remember where they are, so you can figure out what their coordinates are. Bascially you should have a list that has every material, and what coords it was assigned on the sheet.

2) Make a data structure that consists of 4000 quads (or however many you need for you map, I'm using 4000 because you said 4000). GO find a tutorial somewhere that will tell you how to make one, or use a modeling application. Remember that each quad will need it's own set of uv coords. They can't be shared.
struct quad
{
   vector3 [4] vertex;
   vector2 [4] uv;
}
3) Go through the quads and assign them the uv coords from your texture atlas. Refer to the list from step one.

4) Use XNA to create a vertex object out of your data from your struct.

5) When drawing, load the tiles texture atlas, and then just draw your map out in 1 call, as one model.

Drawing your map til by tile means you are sending over 4000 draw calls per frame. That's about ~3500 too many!

1) Put all your tiles on a bigger sheet, and remember where they are, so you can figure out what their coordinates are. Bascially you should have a list that has every material, and what coords it was assigned on the sheet.

2) Make a data structure that consists of 4000 quads (or however many you need for you map, I'm using 4000 because you said 4000). GO find a tutorial somewhere that will tell you how to make one, or use a modeling application. Remember that each quad will need it's own set of uv coords. They can't be shared.


struct quad
{
   vector3 [4] vertex;
   vector2 [4] uv;
}
3) Go through the quads and assign them the uv coords from your texture atlas. Refer to the list from step one.

4) Use XNA to create a vertex object out of your data from your struct.

5) When drawing, load the tiles texture atlas, and then just draw your map out in 1 call, as one model.

Drawing your map til by tile means you are sending over 4000 draw calls per frame. That's about ~3500 too many!

yah I know :D

thanks. I will try that.

This topic is closed to new replies.

Advertisement