Windows support

This commit is contained in:
Gabrieal Jimmy
2026-10-02 16:04:30 -05:00
parent 34fa21139f
commit d31689cf86
14 changed files with 242 additions and 57 deletions

View File

@@ -135,7 +135,7 @@ bool App::init() {
if (capture_) ImGui::GetIO().ConfigFlags |= ImGuiConfigFlags_NoMouse;
if (!world_.init()) {
HD2D_ERR("failed to load game assets from %s", BS_ASSET_DIR);
HD2D_ERR("failed to load game assets from %s", gameAssetDir().c_str());
return false;
}
world_.buildZone("meadow", 1); // title backdrop; rebuilt with the server's seed on join

View File

@@ -2,10 +2,21 @@
#include <algorithm>
#include <cmath>
#include <filesystem>
#include <vector>
namespace bs {
const std::string& engineAssetDir() {
static const std::string dir = [] {
std::filesystem::path packaged = executableDir() / "engine";
std::error_code ec;
if (std::filesystem::exists(packaged / "shaders" / "common.glsl", ec)) return packaged.string();
return std::string(HD2D_ENGINE_ASSET_DIR);
}();
return dir;
}
void UiTexture::upload(const hd2d::Image& img) {
if (id_ && size_ != glm::ivec2(img.width, img.height)) reset();
if (!id_) {

View File

@@ -2,6 +2,8 @@
// Small client-wide helpers: asset paths, UI textures, color conversion.
#include "hd2d/GL.h"
#include "Paths.h"
#include "hd2d/Texture.h"
#include <imgui.h>
@@ -11,17 +13,18 @@
#include <cstdint>
#include <string>
#ifndef BS_ASSET_DIR
#define BS_ASSET_DIR "assets"
#endif
#ifndef HD2D_ENGINE_ASSET_DIR
#define HD2D_ENGINE_ASSET_DIR "../Vibe-HD-2D/assets"
#endif
namespace bs {
inline std::string gameAsset(const std::string& rel) { return std::string(BS_ASSET_DIR) + "/" + rel; }
inline std::string engineAsset(const std::string& rel) { return std::string(HD2D_ENGINE_ASSET_DIR) + "/" + rel; }
// Game assets: `<exe dir>/assets` in a release package, else the source checkout (see Paths.h).
inline std::string gameAsset(const std::string& rel) { return gameAssetDir() + "/" + rel; }
// Engine shaders, fonts, textures, models: `<exe dir>/engine` in a release package, else the
// engine checkout baked in by CMake.
const std::string& engineAssetDir();
inline std::string engineAsset(const std::string& rel) { return engineAssetDir() + "/" + rel; }
constexpr float kPixelsPerUnit = 32.0f; // world texel density shared by all pixel art
constexpr float kCreaturePixelsPerUnit = 40.0f; // creatures render a bit smaller than trainers

View File

@@ -28,34 +28,6 @@ namespace bs {
namespace fs = std::filesystem;
fs::path userDataDir() {
fs::path base;
#if defined(_WIN32)
if (const char* a = std::getenv("APPDATA"); a && *a) base = a;
#else
if (const char* x = std::getenv("XDG_DATA_HOME"); x && *x) base = x;
else if (const char* h = std::getenv("HOME"); h && *h) base = fs::path(h) / ".local/share";
#endif
if (base.empty()) base = ".";
fs::path d = base / "brandling-safari";
std::error_code ec;
fs::create_directories(d, ec);
return d;
}
fs::path executableDir() {
#if defined(_WIN32)
std::wstring buf(32768, L'\0');
DWORD n = GetModuleFileNameW(nullptr, buf.data(), DWORD(buf.size()));
buf.resize(n);
return fs::path(buf).parent_path();
#else
std::error_code ec;
fs::path exe = fs::read_symlink("/proc/self/exe", ec);
return ec ? fs::current_path() : exe.parent_path();
#endif
}
#if defined(_WIN32)
namespace {

View File

@@ -4,18 +4,13 @@
// server saves and exits cleanly on every platform (Windows has no SIGTERM),
// and only kills it if it does not exit in time. Its output goes to a log file.
#include "Paths.h"
#include <cstdint>
#include <filesystem>
#include <string>
namespace bs {
// Per-user data folder: %APPDATA%\brandling-safari on Windows,
// $XDG_DATA_HOME/brandling-safari or ~/.local/share/brandling-safari elsewhere
// (the server uses the same folder for world.db). Created if missing.
std::filesystem::path userDataDir();
std::filesystem::path executableDir();
class LocalServer {
public:
LocalServer() = default;