It has been a couple of weeks, which means it's time for another dev blog. I guess we'll be going into depth a lot more from now on, so these will probably get quite a bit longer, but I'm sure some of you people out there will enjoy the detail.
Great News, everyone! MB22 joined our team and will create awesome music and soundeffects for Cytopia henceforth!
He already made two amazing pieces of music for our soundtrack. It sounds not just professional, but also very soothing and fits Cytopias style perfectly.
Enough talk, here are two links for you to listen to:
Cytopia OST 2 by MB22
Cytopia OST 1 by MB22
Save / Load Game
Cytopia now supports loading and saving your map! Meaning, you can finally keep the great city you’ve built and even share it with friends or present it in our forum.
Utilizing the opensource library nlohmann::json (GitHub - nlohmann/json: JSON for Modern C++) for Cytopia, we’ve added a feature to save and load your game. Until the User Interface gets the new features we need to display a save / load game dialog and enter a filename, it will only use one save file though. (resources/save.cts), so be careful, not to overwrite your existing file. Btw, the file extension cts stands for CyTopia Savegame.
To serialize a map to json, we used the functions to_json and from_json that allow direct (de-)serialization of arbitrary data types in C++.
Right now, the most important parameters that define a map are, of course, it’s size, the height level of each map node and the used tile type, that corresponds directly to the ids from the TileData.json file.
This data gets saved in json format in the save file and can be read back to a json object directly.
Now that savegames are finally implemented, we noticed, that a very basic savegame for a 128x128 yet takes up close to 2MB. So we had to add compression. Zlib is a widely used library for compression, so that‘s what we chose.
Writing functions to compress and decompress strings was pretty straight forward. See compression.cxx if you‘re interested in the code.
Zlib can‘t handle file streams by default though and using boost is recommended, but we wanted to avoid the overhead of thirdparty libraries.
Nevertheless, it‘s no problem to dump the ifstream to a sstream and convert that back to a string. But remember to open the streams as binary.
std::ifstream file(fileName, std::ios_base::in | std::ios_base::binary);
buffer << file.rdbuf();
jsonAsString = decompressString(buffer.str());
json saveGameJSON = json::parse(jsonAsString, nullptr, false);
To prevent problems with future changes to the savegame format, we’ve also a version number property to the savegame, so we can provide functions to upgrade savegames later.
For implementation details see:
JSON Serialization (Load and Save Game) by JimmySnails · Pull Request #82 · JimmySnails/Cytopia · GitHub
Add zlib compression for save games by JimmySnails · Pull Request #96 · JimmySnails/Cytopia · GitHub
Support for another Platform has been added to Cytopia! So by now, we also support macOS!
We‘ve created a dmg file for you, so all you‘ll have to do is open it and move the Cytopia app to your Applications folder and start building the city of your dreams!
Building cytopia yourself is pretty easy and can be done via the following steps:
Install brew (The missing package manager for macOS (or Linux) — The missing package manager for macOS (or Linux))
Install SDL Libraries
brew install sdl2 sdl2_image sdl2_mixer sdl2_ttf
cmake –build .
Now a few words regarding the technical implementation.
Bringing Cytopia to macOS was quite the endeavor. After cloning the repo and calling cmake, it instantly worked from the shell. But trying to start the binary from Finder didn’t work, because the resources directory couldn’t be found.
After further analyzing, we found out that macOS is setting the Apps working directory to the home dir. One solution is, to create a App Bundle (.app file) and integrate all files needed by the app in the Resource Folder. Luckily, CMake provides functions for that.
All there was left, was to create a DMG package. We already use CPack for Windows and Linux, so we added the “DragNDrop” CPack Generator and we were done.
In Travis, there’s now an automated build for macOS too, so we can catch platform specific build problems.
If you’re interested in the implementation details, have a look at the Pull Request:
add macOS build by JimmySnails · Pull Request #95 · JimmySnails/Cytopia · GitHub
New Graphics Artist
Rock Fort has joined our graphics team. He is a popular TheoTown plug-in creator, known for his awesome texturing skills, so we're happy to have him working with us.
This past few weeks, we've been working hard on many things. Just recently, I have finished the new road frames, including diagonal corners and proper slopes (to go with the new terrain). The rest of the team has been hard at work creating new RCI buildings as well. On top of that, we now have a new tree type, palm trees (by Folesnaid)!
Speaking of Folesnaid, he has also been working on creating a "desert pack," which will include a small collection of desert themed buildings.
Besides those roads, I have been working on other things, like highway walls (like mdk's SHW plug-in), which you'll be able to use to decorate your cities (eventually). Soon I'll begin to work on some powerlines, pipes, and trains.