summaryrefslogtreecommitdiffstats
path: root/game/shared/splash.cc
diff options
context:
space:
mode:
authoruntodesu <kirill@untode.su>2025-03-15 16:22:09 +0500
committeruntodesu <kirill@untode.su>2025-03-15 16:22:09 +0500
commit3bf42c6ff3805a0d42bbc661794a95ff31bedc26 (patch)
tree05049955847504808d6bed2bb7b155f8b03807bb /game/shared/splash.cc
parent02294547dcde0d4ad76e229106702261e9f10a51 (diff)
downloadvoxelius-3bf42c6ff3805a0d42bbc661794a95ff31bedc26.tar.bz2
voxelius-3bf42c6ff3805a0d42bbc661794a95ff31bedc26.zip
Add whatever I was working on for the last month
Diffstat (limited to 'game/shared/splash.cc')
-rw-r--r--game/shared/splash.cc34
1 files changed, 34 insertions, 0 deletions
diff --git a/game/shared/splash.cc b/game/shared/splash.cc
new file mode 100644
index 0000000..ec7b3c8
--- /dev/null
+++ b/game/shared/splash.cc
@@ -0,0 +1,34 @@
+#include "shared/pch.hh"
+#include "shared/splash.hh"
+
+constexpr static const char *SPLASHES_FILENAME = "misc/splashes.txt";
+
+static std::mt19937_64 splash_random;
+static std::vector<std::string> splash_lines;
+
+void splash::init(void)
+{
+ if(auto file = PHYSFS_openRead(SPLASHES_FILENAME)) {
+ auto source = std::string(PHYSFS_fileLength(file), char(0x00));
+ PHYSFS_readBytes(file, source.data(), source.size());
+ PHYSFS_close(file);
+
+ std::string line;
+ std::istringstream stream(source);
+
+ while(std::getline(stream, line)) {
+ splash_lines.push_back(line);
+ }
+
+ splash_random.seed(std::random_device()());
+ }
+ else {
+ splash_lines.push_back(fmt::format("{}: {}", SPLASHES_FILENAME, PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())));
+ }
+}
+
+const char* splash::get(void)
+{
+ std::uniform_int_distribution<std::size_t> dist(0, splash_lines.size() - 1);
+ return splash_lines.at(dist(splash_random)).c_str();
+}