From a07d588c94f68cdc559ceb016c031c9199f0b868 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Sun, 20 Mar 2022 11:52:09 -0400 Subject: we can now build a mac bundle! --- src/game.cpp | 9 +++++---- src/game.h | 3 ++- src/main.cpp | 1 - src/muxer.cpp | 5 +++-- src/renderer.cpp | 23 ++++++++++++----------- src/runtime.h | 13 +++++++++++++ src/runtime_macos.mm | 16 ++++++++++++++++ src/runtime_test.cpp | 5 +++++ 8 files changed, 56 insertions(+), 19 deletions(-) create mode 100644 src/runtime.h create mode 100644 src/runtime_macos.mm create mode 100644 src/runtime_test.cpp (limited to 'src') diff --git a/src/game.cpp b/src/game.cpp index a3aa7be..39828f4 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -1,6 +1,6 @@ #include "game.h" #include -#include +#include "fov.h" #include #include #include @@ -8,6 +8,7 @@ #include "util.h" #include "renderer.h" #include "consts.h" +#include "runtime.h" Game::Game(std::mt19937& rng, Muxer& muxer, Renderer& renderer) : rng(rng), @@ -35,7 +36,7 @@ Game::Game(std::mt19937& rng, Muxer& muxer, Renderer& renderer) : tick(); } while (!isInitialCaveBigEnough()); - std::ifstream textFile("../res/childoflight.txt"); + std::ifstream textFile(Runtime::getResourcePath("childoflight.txt")); std::string line; while (std::getline(textFile, line)) { signTexts.push_back(line); @@ -284,7 +285,7 @@ void Game::recalculateLighting() if (game.map.inBounds(x, y)) { MapData& sourceData = *static_cast(source); - double lightRadius = static_cast(sourceData.lightRadius); + //double lightRadius = static_cast(sourceData.lightRadius); if (!game.map.at(x,y).lit) { @@ -302,7 +303,7 @@ void Game::recalculateLighting() for (int x = map.getLeft(); x < map.getRight(); x++) { Source ls = Source::None; - int lightRadius; + int lightRadius = 0; if (renderPlayer && player_x == x && player_y == y) { diff --git a/src/game.h b/src/game.h index 3b092dd..914df53 100644 --- a/src/game.h +++ b/src/game.h @@ -13,6 +13,7 @@ #include "consts.h" #include "sign.h" #include "menu.h" +#include "runtime.h" class Renderer; @@ -88,7 +89,7 @@ public: int player_oldx = 0; int player_oldy = 0; bool renderPlayer = true; - Animation playerAnim {"../res/player_anim.txt"}; + Animation playerAnim {Runtime::getResourcePath("player_anim.txt")}; int maxZoom = INIT_ZOOM; int curZoom = INIT_ZOOM; diff --git a/src/main.cpp b/src/main.cpp index ae64079..0b9195f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,5 +1,4 @@ #include -#include #include #include #include "util.h" diff --git a/src/muxer.cpp b/src/muxer.cpp index 6ae6936..c276c0f 100644 --- a/src/muxer.cpp +++ b/src/muxer.cpp @@ -1,6 +1,7 @@ #include "muxer.h" #include #include +#include "runtime.h" void ERRCHECK_fn(FMOD_RESULT result, const char* file, int line) { if (result != FMOD_OK) { @@ -22,10 +23,10 @@ Muxer::Muxer() { ERRCHECK(system_->initialize(1024, FMOD_STUDIO_INIT_NORMAL, FMOD_INIT_NORMAL, nullptr)); FMOD::Studio::Bank* masterBank = nullptr; - ERRCHECK(system_->loadBankFile("../res/fmod/Build/Desktop/Master Bank.bank", FMOD_STUDIO_LOAD_BANK_NORMAL, &masterBank)); + ERRCHECK(system_->loadBankFile(Runtime::getResourcePath("Master.bank").c_str(), FMOD_STUDIO_LOAD_BANK_NORMAL, &masterBank)); FMOD::Studio::Bank* stringsBank = nullptr; - ERRCHECK(system_->loadBankFile("../res/fmod/Build/Desktop/Master Bank.strings.bank", FMOD_STUDIO_LOAD_BANK_NORMAL, &stringsBank)); + ERRCHECK(system_->loadBankFile(Runtime::getResourcePath("Master.strings.bank").c_str(), FMOD_STUDIO_LOAD_BANK_NORMAL, &stringsBank)); } void Muxer::setPlayerLoc(int x, int y) { diff --git a/src/renderer.cpp b/src/renderer.cpp index 724e297..09bddc9 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -1,6 +1,7 @@ #include "renderer.h" #include #include "game.h" +#include "runtime.h" Renderer::Renderer() { @@ -33,7 +34,7 @@ Renderer::Renderer() } texture_ptr origFade; - loadTextureFromFile("../res/lighting.png", origFade); + loadTextureFromFile("lighting.png", origFade); playerFade_ = texture_ptr( SDL_CreateTexture( @@ -105,22 +106,22 @@ Renderer::Renderer() SDL_SetRenderDrawColor(ren_.get(), 100, 100, 100, 255); SDL_RenderFillRect(ren_.get(), nullptr); - loadTextureFromFile("../res/player.png", playerSheet_); - loadTextureFromFile("../res/runninbloods.png", tileset_); - loadTextureFromFile("../res/lamp.png", lamp_); - loadTextureFromFile("../res/read_instruction.png", readInstruction_); - loadTextureFromFile("../res/menu.png", menuBg_); + loadTextureFromFile("player.png", playerSheet_); + loadTextureFromFile("runninbloods.png", tileset_); + loadTextureFromFile("lamp.png", lamp_); + loadTextureFromFile("read_instruction.png", readInstruction_); + loadTextureFromFile("menu.png", menuBg_); - loadTextureFromFile("../res/title0.png", titles_[0]); + loadTextureFromFile("title0.png", titles_[0]); SDL_QueryTexture(titles_[0].get(), nullptr, nullptr, &titleWidths_[0], &titleHeights_[0]); - loadTextureFromFile("../res/title1.png", titles_[1]); + loadTextureFromFile("title1.png", titles_[1]); SDL_QueryTexture(titles_[1].get(), nullptr, nullptr, &titleWidths_[1], &titleHeights_[1]); - loadTextureFromFile("../res/title3.png", titles_[2]); + loadTextureFromFile("title3.png", titles_[2]); SDL_QueryTexture(titles_[2].get(), nullptr, nullptr, &titleWidths_[2], &titleHeights_[2]); - font_ = font_ptr(TTF_OpenFont("../res/softsquare.ttf", 45)); + font_ = font_ptr(TTF_OpenFont(Runtime::getResourcePath("softsquare.ttf").c_str(), 45)); if (!font_) { throw ttf_error(); } @@ -553,7 +554,7 @@ void Renderer::renderTitle(int num, double fade) { } void Renderer::loadTextureFromFile(std::string_view path, texture_ptr& texture) { - surface_ptr pfs(IMG_Load(path.data())); + surface_ptr pfs(IMG_Load(Runtime::getResourcePath(path).c_str())); if (!pfs) { throw img_error(); diff --git a/src/runtime.h b/src/runtime.h new file mode 100644 index 0000000..a0e3a2c --- /dev/null +++ b/src/runtime.h @@ -0,0 +1,13 @@ +#ifndef RUNTIME_H_A8DA6E1E +#define RUNTIME_H_A8DA6E1E + +#include +#include + +class Runtime { +public: + + static std::string getResourcePath(std::string_view filename); +}; + +#endif /* end of include guard: RUNTIME_H_A8DA6E1E */ diff --git a/src/runtime_macos.mm b/src/runtime_macos.mm new file mode 100644 index 0000000..b46e6f8 --- /dev/null +++ b/src/runtime_macos.mm @@ -0,0 +1,16 @@ +#include "runtime.h" +#import + +std::string Runtime::getResourcePath(std::string_view filename) { + CFStringRef fileNameRef = CFStringCreateWithCString(kCFAllocatorDefault, filename.data(), kCFStringEncodingUTF8); + CFURLRef appUrlRef = CFBundleCopyResourceURL(CFBundleGetMainBundle(), fileNameRef, NULL, NULL); + CFStringRef filePathRef = CFURLCopyPath(appUrlRef); + const char* filePath = CFStringGetCStringPtr(filePathRef, kCFStringEncodingUTF8); + std::string result(filePath); + + CFRelease(filePathRef); + CFRelease(appUrlRef); + CFRelease(fileNameRef); + + return result; +} diff --git a/src/runtime_test.cpp b/src/runtime_test.cpp new file mode 100644 index 0000000..b4a6d34 --- /dev/null +++ b/src/runtime_test.cpp @@ -0,0 +1,5 @@ +#include "runtime.h" + +std::string Runtime::getResourcePath(std::string_view name) { + return std::string("../res/") + std::string(name); +} -- cgit 1.4.1