Here's the most recent build.I'm about to start working on ship-to-ship combat, and as a prerequisite for that, I made a thing called an 'entity map.' I store ships in a big list/vector called shipList. But going through the whole list so many times per second just to see if there's a ship on the tile you are pointing at would be so slow, so I created a grid the size of the world map. Each turn, a token that has the ID of a ship is dropped into the cell (on the grid) that corresponds to where the ship is on the world map. If there's an old token in the cell, it's emptied. Then when I want to see if a ship is on a certain map tile I check the grid for a token. If the token is old, I ignore it. This lets the entityMap be both efficient and useful. The timestamp is incremented each time the world is updated, and the whole map is cleared every 2147483647 turns. The player probably won't even reach that many turns, but just in case
The tooltip shows the name of a ship.
Right-clicking on the ship pops up its status screen. You're like an omnipotent god, peering into the ship's intimate secrets O_O
Another thing that was done is optimizing the pathfinding algorithm. Before optimization, it lagged a lot and paused the game often to calculate a path. After, it's nearly perfectly silky and runs smooth.
Originally, it looked at a huuuuge list of potential places to poke and prod to see if it makes you go closer to your destination(the f-value list). It examined every single element in the list and gave you one with the lowest f-value, calculated by DistanceFromStart +
what I think is, but might not be theDistanceToDestination. But the list sometimes reached a couple hundred elements in size. Going through the list is horridly slow.
I tried making it use a
heap. Basically, each time you add a new potential place(
node) you could poke later, it puts all the potential places in a certain order, with the one with the lowest f-value on top all the tip. I just pick up the top value, and the whole heap shifts so the next-lowest one is on top again. Quite efficient.
Even after these optimizations it was slow. This time, I changed how the nodes were stored. The nodes are places the algorithm has looked at. Ones that are basically dead endssay, they lead away from the destination, or there are better ways to get thereare put on the closed set. The ones that I want to look at next are put on the open set. Originally I had to do a
binary search to retrieve a node every time. Added up by a couple hundred times a second it's a big performance hit. Instead of a map/dictionary, I used a hashmap. If a map has all the nodes sorted in order, and you would basically trial-and-error your way to the element you want, in a hashmap you know (almost) exactly where this element would be, and where that one would be, using magic made into technology via a hashing function.
To sum up? Optimizations! OPTIMIZATIONSZZZZ
Next up is the combat system. After that is better merchant AI, and maybe even pirate ships to attack you!
(well, I suppose I'll need to make GUI for installing and removing ship parts including cannons sometime, but GUI is scary and more importantly boring T_T)