git repos / blockattack-game

commit 52be78a6

Poul Sander · 2026-09-18 18:10
52be78a63c2b7107db2ff2c49e3e4f1d511f4d98 patch · browse files
parent 84ff93b4b5e909cf65f6796ab5cc554700fd7d85

Started to replace some uses of boost that are no longer relevant

Changed files

M source/code/HelpModInfoState.cpp before
M source/code/ModInfo.cpp before
M source/code/common.cpp before
M source/code/common.h before
M source/code/main.cpp before
M source/code/themes.cpp before
diff --git a/source/code/HelpModInfoState.cpp b/source/code/HelpModInfoState.cpp index e4cf0a8..4008e01 100644 --- a/source/code/HelpModInfoState.cpp +++ b/source/code/HelpModInfoState.cpp
@@ -27,7 +27,6 @@ https://blockattack.net
#include "common.h"
#include "sago/SagoMisc.hpp"
#include "os.hpp"
-#include <boost/algorithm/string/predicate.hpp>
#include <sstream>
struct Mod {
@@ -71,7 +70,7 @@ static void initMods(std::vector<Mod>& mod_list) {
static void appendMods(const std::vector<std::string>& mod_files, const std::string& dir, std::vector<Mod>& mods_available) {
for (const std::string& mod : mod_files) {
- if (!boost::ends_with(mod, ".data")) {
+ if (!mod.ends_with(".data")) {
continue;
}
Mod m;
diff --git a/source/code/ModInfo.cpp b/source/code/ModInfo.cpp index 92686e9..d3737c1 100644 --- a/source/code/ModInfo.cpp +++ b/source/code/ModInfo.cpp
@@ -26,7 +26,7 @@ http://blockattack.net
#include "rapidjson/document.h"
#include <iostream>
#include <sstream>
-#include <boost/algorithm/string.hpp>
+#include "common.h"
void ModInfo::InitModList(const std::vector<std::string>& modlist) {
this->mod_list = modlist;
@@ -44,8 +44,7 @@ void ModInfo::InitModList(const std::vector<std::string>& modlist) {
const auto& t = document.GetObject().FindMember("sprites");
if (t != document.MemberEnd() && t->value.IsString()) {
std::string sprites = t->value.GetString();
- std::vector<std::string> sprites_vector;
- boost::split(sprites_vector, sprites, boost::is_any_of(","));
+ std::vector<std::string> sprites_vector = split_string(sprites, ",");
sprite_filename_list.insert(sprite_filename_list.end(), sprites_vector.begin(), sprites_vector.end());
}
}
@@ -56,8 +55,7 @@ void ModInfo::ParseModFile(const std::string& content) {
std::istringstream ss(content);
std::string line;
while (std::getline(ss, line)) {
- std::vector<std::string> line_vector;
- boost::split(line_vector, line, boost::is_any_of(","));
+ std::vector<std::string> line_vector = split_string(line, ",");
if (line_vector.size() < 2) {
std::cerr << "skipping " << line << "\n";
continue;
diff --git a/source/code/common.cpp b/source/code/common.cpp index 2b59fcc..8dedc20 100644 --- a/source/code/common.cpp +++ b/source/code/common.cpp
@@ -59,6 +59,24 @@ int str2int(const std::string& str2parse) {
}
}
+std::vector<std::string> split_string(const std::string& input, const std::string& sep)
+{
+ std::vector<std::string> out;
+ if (sep.empty())
+ {
+ out.push_back(input);
+ return out;
+ }
+ std::size_t start = 0;
+ std::size_t pos = 0;
+ while ((pos = input.find(sep, start)) != std::string::npos) {
+ out.emplace_back(input, start, pos - start);
+ start = pos + sep.size();
+ }
+ out.emplace_back(input, start);
+ return out;
+}
+
/**
* Takes a number of milliseconds and returns the value in commonTime format.
*/
diff --git a/source/code/common.h b/source/code/common.h index 8915991..e02d30e 100644 --- a/source/code/common.h +++ b/source/code/common.h
@@ -33,6 +33,7 @@ https://blockattack.net
#include <string>
#include <iostream>
#include <map>
+#include <vector>
#include <stdlib.h>
#include <libintl.h>
#include <ctime>
@@ -66,6 +67,14 @@ void dieOnNullptr(bool, const char* msg);
*/
double str2double(const std::string &str2parse) __attribute__((const));
+/**
+ * Split a string into multiple strings using the given separator
+ * @param input The string to split
+ * @param sep The separator
+ * @return A vector of strings
+ */
+std::vector<std::string> split_string(const std::string& input, const std::string& sep);
+
class TimeHandler
{
public:
diff --git a/source/code/main.cpp b/source/code/main.cpp index 51615ca..ec2183a 100644 --- a/source/code/main.cpp +++ b/source/code/main.cpp
@@ -61,7 +61,6 @@ https://blockattack.net
#include "common.h"
#include "gamecontroller.h"
-#include <boost/algorithm/string.hpp>
#include <boost/program_options.hpp>
#include <fstream>
#include "levelselect.hpp"
@@ -1085,10 +1084,6 @@ int main(int argc, char* argv[]) {
OsCreateSaveFolder();
writeStateFile(argv[0], PHYSFS_getBaseDir());
PhysFsSetSearchPath(config.search_paths, config.savepath);
- /*if (globalData.modList.empty() && sago::FileExists(MODLIST_TXT)) {
- std::string modString = sago::GetFileContent(MODLIST_TXT);
- boost::split(globalData.modList, modString, boost::is_any_of(","));
- }*/
globalData.modinfo.InitModList(globalData.modList);
if (sago::FileExists(MODLIST_TXT)) {
globalData.modinfo.ParseModFile(sago::GetFileContent(MODLIST_TXT));
diff --git a/source/code/themes.cpp b/source/code/themes.cpp index 0d23292..e8cce00 100644 --- a/source/code/themes.cpp +++ b/source/code/themes.cpp
@@ -31,7 +31,6 @@ https://www.blockattack.net
#include "nlohmann/json.hpp"
#include <iostream>
#include "global.hpp"
-#include <boost/algorithm/string/predicate.hpp>
#include <fmt/format.h>
using json = nlohmann::json;
@@ -329,7 +328,7 @@ void ThemesInit() {
ThemesFillMissingFields(themes[0]);
const std::vector<std::string>& theme_files = sago::GetFileList("themes");
for (const std::string& filename : theme_files) {
- if (boost::algorithm::ends_with(filename,".json")) {
+ if (filename.ends_with(".json")) {
ThemesReadDataFromFile("themes/"+filename);
}
}
@@ -442,7 +441,7 @@ void ThemesInitCustomBackgrounds() {
bool first = true;
for (const std::string& filename : custom_backgrounds) {
std::cout << "Found custom background " << filename << "\n";
- if (boost::algorithm::ends_with(filename, ".png") || boost::algorithm::ends_with(filename, ".jpg")) {
+ if (filename.ends_with(".png") || filename.ends_with(".jpg")) {
BackGroundData bg;
bg.name = filename;
std::string texture_name = fmt::format("custom_background_{}",filename);;
@@ -501,7 +500,7 @@ void ThemesSaveBackgroundData(const std::string& name, const BackGroundData& dat
void ThemesLoadCustomBorders() {
const std::vector<std::string>& border_files = sago::GetFileList("borders");
for (const std::string& filename : border_files) {
- if (boost::algorithm::ends_with(filename, ".json")) {
+ if (filename.ends_with(".json")) {
std::string filepath = fmt::format("borders/{}", filename);
std::string s = sago::GetFileContent(filepath);
if (s.empty()) {
@@ -525,7 +524,7 @@ void ThemesLoadCustomBorders() {
void ThemesLoadCustomBackgrounds() {
const std::vector<std::string>& background_files = sago::GetFileList("backgrounds");
for (const std::string& filename : background_files) {
- if (boost::algorithm::ends_with(filename, ".json")) {
+ if (filename.ends_with(".json")) {
std::string filepath = fmt::format("backgrounds/{}", filename);
std::string s = sago::GetFileContent(filepath);
if (s.empty()) {