diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/game.cpp | 9 | ||||
-rw-r--r-- | src/game.h | 3 | ||||
-rw-r--r-- | src/main.cpp | 1 | ||||
-rw-r--r-- | src/muxer.cpp | 5 | ||||
-rw-r--r-- | src/renderer.cpp | 23 | ||||
-rw-r--r-- | src/runtime.h | 13 | ||||
-rw-r--r-- | src/runtime_macos.mm | 16 | ||||
-rw-r--r-- | src/runtime_test.cpp | 5 |
8 files changed, 56 insertions, 19 deletions
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 @@ | |||
1 | #include "game.h" | 1 | #include "game.h" |
2 | #include <vector> | 2 | #include <vector> |
3 | #include <fov.h> | 3 | #include "fov.h" |
4 | #include <iostream> | 4 | #include <iostream> |
5 | #include <fstream> | 5 | #include <fstream> |
6 | #include <set> | 6 | #include <set> |
@@ -8,6 +8,7 @@ | |||
8 | #include "util.h" | 8 | #include "util.h" |
9 | #include "renderer.h" | 9 | #include "renderer.h" |
10 | #include "consts.h" | 10 | #include "consts.h" |
11 | #include "runtime.h" | ||
11 | 12 | ||
12 | Game::Game(std::mt19937& rng, Muxer& muxer, Renderer& renderer) : | 13 | Game::Game(std::mt19937& rng, Muxer& muxer, Renderer& renderer) : |
13 | rng(rng), | 14 | rng(rng), |
@@ -35,7 +36,7 @@ Game::Game(std::mt19937& rng, Muxer& muxer, Renderer& renderer) : | |||
35 | tick(); | 36 | tick(); |
36 | } while (!isInitialCaveBigEnough()); | 37 | } while (!isInitialCaveBigEnough()); |
37 | 38 | ||
38 | std::ifstream textFile("../res/childoflight.txt"); | 39 | std::ifstream textFile(Runtime::getResourcePath("childoflight.txt")); |
39 | std::string line; | 40 | std::string line; |
40 | while (std::getline(textFile, line)) { | 41 | while (std::getline(textFile, line)) { |
41 | signTexts.push_back(line); | 42 | signTexts.push_back(line); |
@@ -284,7 +285,7 @@ void Game::recalculateLighting() | |||
284 | if (game.map.inBounds(x, y)) | 285 | if (game.map.inBounds(x, y)) |
285 | { | 286 | { |
286 | MapData& sourceData = *static_cast<MapData*>(source); | 287 | MapData& sourceData = *static_cast<MapData*>(source); |
287 | double lightRadius = static_cast<double>(sourceData.lightRadius); | 288 | //double lightRadius = static_cast<double>(sourceData.lightRadius); |
288 | 289 | ||
289 | if (!game.map.at(x,y).lit) | 290 | if (!game.map.at(x,y).lit) |
290 | { | 291 | { |
@@ -302,7 +303,7 @@ void Game::recalculateLighting() | |||
302 | for (int x = map.getLeft(); x < map.getRight(); x++) | 303 | for (int x = map.getLeft(); x < map.getRight(); x++) |
303 | { | 304 | { |
304 | Source ls = Source::None; | 305 | Source ls = Source::None; |
305 | int lightRadius; | 306 | int lightRadius = 0; |
306 | 307 | ||
307 | if (renderPlayer && player_x == x && player_y == y) | 308 | if (renderPlayer && player_x == x && player_y == y) |
308 | { | 309 | { |
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 @@ | |||
13 | #include "consts.h" | 13 | #include "consts.h" |
14 | #include "sign.h" | 14 | #include "sign.h" |
15 | #include "menu.h" | 15 | #include "menu.h" |
16 | #include "runtime.h" | ||
16 | 17 | ||
17 | class Renderer; | 18 | class Renderer; |
18 | 19 | ||
@@ -88,7 +89,7 @@ public: | |||
88 | int player_oldx = 0; | 89 | int player_oldx = 0; |
89 | int player_oldy = 0; | 90 | int player_oldy = 0; |
90 | bool renderPlayer = true; | 91 | bool renderPlayer = true; |
91 | Animation playerAnim {"../res/player_anim.txt"}; | 92 | Animation playerAnim {Runtime::getResourcePath("player_anim.txt")}; |
92 | 93 | ||
93 | int maxZoom = INIT_ZOOM; | 94 | int maxZoom = INIT_ZOOM; |
94 | int curZoom = INIT_ZOOM; | 95 | 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 @@ | |||
1 | #include <vector> | 1 | #include <vector> |
2 | #include <fov.h> | ||
3 | #include <iostream> | 2 | #include <iostream> |
4 | #include <memory> | 3 | #include <memory> |
5 | #include "util.h" | 4 | #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 @@ | |||
1 | #include "muxer.h" | 1 | #include "muxer.h" |
2 | #include <iostream> | 2 | #include <iostream> |
3 | #include <fmod_errors.h> | 3 | #include <fmod_errors.h> |
4 | #include "runtime.h" | ||
4 | 5 | ||
5 | void ERRCHECK_fn(FMOD_RESULT result, const char* file, int line) { | 6 | void ERRCHECK_fn(FMOD_RESULT result, const char* file, int line) { |
6 | if (result != FMOD_OK) { | 7 | if (result != FMOD_OK) { |
@@ -22,10 +23,10 @@ Muxer::Muxer() { | |||
22 | ERRCHECK(system_->initialize(1024, FMOD_STUDIO_INIT_NORMAL, FMOD_INIT_NORMAL, nullptr)); | 23 | ERRCHECK(system_->initialize(1024, FMOD_STUDIO_INIT_NORMAL, FMOD_INIT_NORMAL, nullptr)); |
23 | 24 | ||
24 | FMOD::Studio::Bank* masterBank = nullptr; | 25 | FMOD::Studio::Bank* masterBank = nullptr; |
25 | ERRCHECK(system_->loadBankFile("../res/fmod/Build/Desktop/Master Bank.bank", FMOD_STUDIO_LOAD_BANK_NORMAL, &masterBank)); | 26 | ERRCHECK(system_->loadBankFile(Runtime::getResourcePath("Master.bank").c_str(), FMOD_STUDIO_LOAD_BANK_NORMAL, &masterBank)); |
26 | 27 | ||
27 | FMOD::Studio::Bank* stringsBank = nullptr; | 28 | FMOD::Studio::Bank* stringsBank = nullptr; |
28 | ERRCHECK(system_->loadBankFile("../res/fmod/Build/Desktop/Master Bank.strings.bank", FMOD_STUDIO_LOAD_BANK_NORMAL, &stringsBank)); | 29 | ERRCHECK(system_->loadBankFile(Runtime::getResourcePath("Master.strings.bank").c_str(), FMOD_STUDIO_LOAD_BANK_NORMAL, &stringsBank)); |
29 | } | 30 | } |
30 | 31 | ||
31 | void Muxer::setPlayerLoc(int x, int y) { | 32 | 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 @@ | |||
1 | #include "renderer.h" | 1 | #include "renderer.h" |
2 | #include <iostream> | 2 | #include <iostream> |
3 | #include "game.h" | 3 | #include "game.h" |
4 | #include "runtime.h" | ||
4 | 5 | ||
5 | Renderer::Renderer() | 6 | Renderer::Renderer() |
6 | { | 7 | { |
@@ -33,7 +34,7 @@ Renderer::Renderer() | |||
33 | } | 34 | } |
34 | 35 | ||
35 | texture_ptr origFade; | 36 | texture_ptr origFade; |
36 | loadTextureFromFile("../res/lighting.png", origFade); | 37 | loadTextureFromFile("lighting.png", origFade); |
37 | 38 | ||
38 | playerFade_ = texture_ptr( | 39 | playerFade_ = texture_ptr( |
39 | SDL_CreateTexture( | 40 | SDL_CreateTexture( |
@@ -105,22 +106,22 @@ Renderer::Renderer() | |||
105 | SDL_SetRenderDrawColor(ren_.get(), 100, 100, 100, 255); | 106 | SDL_SetRenderDrawColor(ren_.get(), 100, 100, 100, 255); |
106 | SDL_RenderFillRect(ren_.get(), nullptr); | 107 | SDL_RenderFillRect(ren_.get(), nullptr); |
107 | 108 | ||
108 | loadTextureFromFile("../res/player.png", playerSheet_); | 109 | loadTextureFromFile("player.png", playerSheet_); |
109 | loadTextureFromFile("../res/runninbloods.png", tileset_); | 110 | loadTextureFromFile("runninbloods.png", tileset_); |
110 | loadTextureFromFile("../res/lamp.png", lamp_); | 111 | loadTextureFromFile("lamp.png", lamp_); |
111 | loadTextureFromFile("../res/read_instruction.png", readInstruction_); | 112 | loadTextureFromFile("read_instruction.png", readInstruction_); |
112 | loadTextureFromFile("../res/menu.png", menuBg_); | 113 | loadTextureFromFile("menu.png", menuBg_); |
113 | 114 | ||
114 | loadTextureFromFile("../res/title0.png", titles_[0]); | 115 | loadTextureFromFile("title0.png", titles_[0]); |
115 | SDL_QueryTexture(titles_[0].get(), nullptr, nullptr, &titleWidths_[0], &titleHeights_[0]); | 116 | SDL_QueryTexture(titles_[0].get(), nullptr, nullptr, &titleWidths_[0], &titleHeights_[0]); |
116 | 117 | ||
117 | loadTextureFromFile("../res/title1.png", titles_[1]); | 118 | loadTextureFromFile("title1.png", titles_[1]); |
118 | SDL_QueryTexture(titles_[1].get(), nullptr, nullptr, &titleWidths_[1], &titleHeights_[1]); | 119 | SDL_QueryTexture(titles_[1].get(), nullptr, nullptr, &titleWidths_[1], &titleHeights_[1]); |
119 | 120 | ||
120 | loadTextureFromFile("../res/title3.png", titles_[2]); | 121 | loadTextureFromFile("title3.png", titles_[2]); |
121 | SDL_QueryTexture(titles_[2].get(), nullptr, nullptr, &titleWidths_[2], &titleHeights_[2]); | 122 | SDL_QueryTexture(titles_[2].get(), nullptr, nullptr, &titleWidths_[2], &titleHeights_[2]); |
122 | 123 | ||
123 | font_ = font_ptr(TTF_OpenFont("../res/softsquare.ttf", 45)); | 124 | font_ = font_ptr(TTF_OpenFont(Runtime::getResourcePath("softsquare.ttf").c_str(), 45)); |
124 | if (!font_) { | 125 | if (!font_) { |
125 | throw ttf_error(); | 126 | throw ttf_error(); |
126 | } | 127 | } |
@@ -553,7 +554,7 @@ void Renderer::renderTitle(int num, double fade) { | |||
553 | } | 554 | } |
554 | 555 | ||
555 | void Renderer::loadTextureFromFile(std::string_view path, texture_ptr& texture) { | 556 | void Renderer::loadTextureFromFile(std::string_view path, texture_ptr& texture) { |
556 | surface_ptr pfs(IMG_Load(path.data())); | 557 | surface_ptr pfs(IMG_Load(Runtime::getResourcePath(path).c_str())); |
557 | if (!pfs) | 558 | if (!pfs) |
558 | { | 559 | { |
559 | throw img_error(); | 560 | 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 @@ | |||
1 | #ifndef RUNTIME_H_A8DA6E1E | ||
2 | #define RUNTIME_H_A8DA6E1E | ||
3 | |||
4 | #include <string> | ||
5 | #include <string_view> | ||
6 | |||
7 | class Runtime { | ||
8 | public: | ||
9 | |||
10 | static std::string getResourcePath(std::string_view filename); | ||
11 | }; | ||
12 | |||
13 | #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 @@ | |||
1 | #include "runtime.h" | ||
2 | #import <Foundation/Foundation.h> | ||
3 | |||
4 | std::string Runtime::getResourcePath(std::string_view filename) { | ||
5 | CFStringRef fileNameRef = CFStringCreateWithCString(kCFAllocatorDefault, filename.data(), kCFStringEncodingUTF8); | ||
6 | CFURLRef appUrlRef = CFBundleCopyResourceURL(CFBundleGetMainBundle(), fileNameRef, NULL, NULL); | ||
7 | CFStringRef filePathRef = CFURLCopyPath(appUrlRef); | ||
8 | const char* filePath = CFStringGetCStringPtr(filePathRef, kCFStringEncodingUTF8); | ||
9 | std::string result(filePath); | ||
10 | |||
11 | CFRelease(filePathRef); | ||
12 | CFRelease(appUrlRef); | ||
13 | CFRelease(fileNameRef); | ||
14 | |||
15 | return result; | ||
16 | } | ||
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 @@ | |||
1 | #include "runtime.h" | ||
2 | |||
3 | std::string Runtime::getResourcePath(std::string_view name) { | ||
4 | return std::string("../res/") + std::string(name); | ||
5 | } | ||