Friday, April 19, 2019

RTS_9 "Building inside of cities & Map Culling"

Optimization has been one of the biggest priorities for me when making this game. Freeing up GPU & CPU allows for more advanced AI, more units, more cities, more complex maps, just more and better stuff in general. That's why it took me reprogramming the map render/generate system 5 times to get it to where it is now.

As it already stands the game is well optimized with my GTX 970 running at 95FPS on a 128x128 map. But that's still not good enough so I decided to implement more optimization: Map Culling.

Something you may not realize is that by default your graphics card wants to render everything in a scene, which is obviously bad since there's no reason to render something going on a mile away. This is why modern games use occlusion culling to inform the camera what the player can see so that they only have to render that and not the objects behind them. This is great for games with pre-built levels, but I wrote my own system for generating & rendering the world which means I don't get the luxuries that pre-built systems have.

So I wrote my own version of occlusion culling for the world that tells the camera to only render chunks it's looking at, here it is in action:



I'm absolutely thrilled with how this turned out, it's got a few bugs but overall it definitely helps improve the performance of the game. By how much is debatable since it depends on the map size you're playing on as well as where on the map you're looking, but multiple tests on it have determined that it reduces the number of vertices the camera is drawing by 6~40%. That's a big range I know but given how many different map sizes and ways maps can look it's understandable that it can't just be a simple answer.

Now a 6~40% reduction in the number of vertices the camera has to draw is significant but that doesn't necessarily mean 6~40% more frames. As for how much it actually helps your overall FPS, I've been unable to accurately determine, but it's definitely lightening the load of the GPU and that's what matters.

Now with all of that optimization mumbo-jumbo out of the way, let's talk about gameplay.

In the last update, I introduced a ton of information all at once such as stability and different happiness factors like crime or housing. Allow me to expand on these concepts a bit here and to explain a couple things I hadn't before.

Building Slots
Land is limited and hexes can only support so many buildings. You can only build so many buildings on a single hex which means that you have to use your space wisely. Right now the rule is 3 buildings per hex but this may change in the future.

Expanding a city
The spot you found your city is only the main grid of the city, everything you build is built on the hexes around that city. However you can expand your city by building more city blocks on hexes, but those hexes can't already have a building on them whatsoever. This means that in order to expand your city outward you'll have to set some land aside with expansion in mind.

Food Consumption VS Food Stockpiling
I had forgotten to mention the little slider below the main city UI. This slider determines how much of the food a city produces should go to consumption or stockpiling. Consumption means that the produced food instantly is consumed and goes toward increasing the population of the city, while food stockpiling is food that is stored to feed the currently existing population.

In my formula about stability, you'll notice that food happiness means that you need to have food stockpiled for your citizens to eat instead of having it all go toward more population. But having food stockpiled isn't just good for happiness, but if you have too low of food your population can actually start to starve and you can lose population.

More importantly, you can be cut off from your production of food. If for example your city is under siege by enemies your city could end up being cut off from its farms, so having a large stockpile is smart otherwise an enemy army could end up starving your city out resulting in its surrender.

This means that food is not only important for city micromanagement but as a war tactic as well. Your city can only hold so much food though, which means you'll also have to build stockpiles which take up precious building slots, so it's definitely a balancing act.


Wow, that is a lot of information to drop on you suddenly but it was necessary for you to understand in order for future updates to make sense. A lot of this is planned and not implemented (For example that slider doesn't yet actually effect stockpiling or anything) but it's just important to note.

And so now finally, all concepts and everything aside here is the main gameplay feature of this update: You can now build buildings on the hexes around a city:



Currently, there's only one test building that's being used for this, but with this feature, it means I can now start getting to main feature buildings like resource production (farms) or unit spawners. Right now you can only build 2 buildings at a time, which I don't know if I'll keep or not.

This is a big step forward for future updates. I hope it wasn't too much to take in!

Sincerely,
Blake Gillman

Not so fun fact:
I have to actually edit a cursor on to the image when showing the user hovering over something because pressing "PRT SC" (Print Screen) doesn't capture your cursor.

No comments:

Post a Comment