diff --git a/CMakeLists.txt b/CMakeLists.txt index 64c4ef0..df7932b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,7 @@ include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) # Includes the contents of th conan_basic_setup() # Prepares the CMakeList.txt for Conan. # $source_files is a space-delimited list of filenames. -add_executable(rla_iipp src/main.cpp src/engine/engine.hpp src/engine/game/game.hpp src/engine/rendering/renderer.hpp src/game/visualizer.hpp src/game/visualizer.cpp src/engine/rendering/sdl/sdlrenderer.cpp src/engine/rendering/sdl/sdlrenderer.hpp src/engine/rendering/sdl/sdlrenderer.cpp src/engine/rendering/sdl/sdlrenderer.hpp src/engine/engine.cpp src/engine/engine.hpp src/engine/rendering/sdl/sdltexturemanager.cpp src/engine/rendering/sdl/sdltexturemanager.hpp src/engine/resources/resourcemanager.hpp src/engine/rendering/sdl/sdlfontmanager.cpp src/engine/rendering/sdl/sdlfontmanager.hpp src/engine/input/inputprocessor.hpp src/engine/input/sdlinputprocessor.cpp src/engine/input/sdlinputprocessor.hpp src/engine/utility/camera.cpp src/engine/utility/camera.hpp src/engine/utility/point.hpp src/engine/utility/rectangle.hpp src/engine/utility/grid2d.hpp src/game/dungeonalgorithm.cpp src/game/dungeonalgorithm.hpp) # Specifies the executable to build. +add_executable(rla_iipp src/main.cpp src/engine/engine.hpp src/engine/game/game.hpp src/engine/rendering/renderer.hpp src/game/visualizer.hpp src/game/visualizer.cpp src/engine/rendering/sdl/sdlrenderer.cpp src/engine/rendering/sdl/sdlrenderer.hpp src/engine/rendering/sdl/sdlrenderer.cpp src/engine/rendering/sdl/sdlrenderer.hpp src/engine/engine.cpp src/engine/engine.hpp src/engine/rendering/sdl/sdltexturemanager.cpp src/engine/rendering/sdl/sdltexturemanager.hpp src/engine/resources/resourcemanager.hpp src/engine/rendering/sdl/sdlfontmanager.cpp src/engine/rendering/sdl/sdlfontmanager.hpp src/engine/input/inputprocessor.hpp src/engine/input/sdlinputprocessor.cpp src/engine/input/sdlinputprocessor.hpp src/engine/utility/camera.cpp src/engine/utility/camera.hpp src/engine/utility/point.hpp src/engine/utility/rectangle.hpp src/engine/utility/grid2d.hpp src/engine/scripting/luacontextmanager.cpp src/engine/scripting/luacontextmanager.hpp src/game/dungeonalgorithm.hpp) # Specifies the executable to build. target_link_libraries(rla_iipp ${CONAN_LIBS}) # Specifies what libraries to link, using Conan. file(COPY assets DESTINATION ${CMAKE_BINARY_DIR}/bin) file(COPY config DESTINATION ${CMAKE_BINARY_DIR}/bin) \ No newline at end of file diff --git a/src/engine/resources/resourcemanager.hpp b/src/engine/resources/resourcemanager.hpp index ad8928f..78e4221 100644 --- a/src/engine/resources/resourcemanager.hpp +++ b/src/engine/resources/resourcemanager.hpp @@ -12,12 +12,18 @@ class ResourceManager { public: virtual T fetch_resource(A args) { K key = get_key(args); - if(this->resource_map.find(key) == this->resource_map.end()) { + if(!this->resource_map.contains(key)) { T resource = this->load_resource(args); this->resource_map[key] = resource; } return this->resource_map[key]; } + virtual void clear_resource(A args) { + K key = get_key(args); + if(this->resource_map.contains(key)) { + this->resource_map.erase(key); + } + } protected: std::unordered_map resource_map; diff --git a/src/game/dungeonalgorithm.cpp b/src/engine/scripting/luacontextmanager.cpp similarity index 51% rename from src/game/dungeonalgorithm.cpp rename to src/engine/scripting/luacontextmanager.cpp index 6bf1713..fedb0af 100644 --- a/src/game/dungeonalgorithm.cpp +++ b/src/engine/scripting/luacontextmanager.cpp @@ -2,4 +2,5 @@ // Created by m on 12/12/21. // -#include "dungeonalgorithm.hpp" +#include "luacontextmanager.hpp" + diff --git a/src/engine/scripting/luacontextmanager.hpp b/src/engine/scripting/luacontextmanager.hpp new file mode 100644 index 0000000..669467e --- /dev/null +++ b/src/engine/scripting/luacontextmanager.hpp @@ -0,0 +1,16 @@ +// +// Created by m on 12/12/21. +// + +#ifndef RLA_IIPP_LUACONTEXTMANAGER_HPP +#define RLA_IIPP_LUACONTEXTMANAGER_HPP +#include + + +class LuaContextManager { +public: + +}; + + +#endif //RLA_IIPP_LUACONTEXTMANAGER_HPP diff --git a/src/engine/utility/camera.cpp b/src/engine/utility/camera.cpp index 7ae526b..5824bcf 100644 --- a/src/engine/utility/camera.cpp +++ b/src/engine/utility/camera.cpp @@ -1,6 +1,7 @@ // // Created by m on 12/11/21. // + #include "camera.hpp" Rectangle Camera::get_bounds() { @@ -8,8 +9,14 @@ Rectangle Camera::get_bounds() { } void Camera::move_camera(Point new_center) { + bool recalculate_bounds = false; + if(new_center != this->center) { + recalculate_bounds = true; + } this->center = new_center; - this->cached_bounds = calculate_bounds(); + if(recalculate_bounds) { + this->cached_bounds = calculate_bounds(); + } } void Camera::set_bounds(int max_x, int max_y) { @@ -37,8 +44,8 @@ ranges::any_view Camera::get_range() { int width = bounds.width; int miny = bounds.y; int minx = bounds.x; - return ranges::views::iota(miny, height) | ranges::views::transform([width, minx](int y) { - return ranges::views::iota(minx, width) | ranges::views::transform([y](int x) { + return ranges::views::iota(miny, miny+height) | ranges::views::transform([width, minx](int y) { + return ranges::views::iota(minx, minx+width) | ranges::views::transform([y](int x) { return Point{x,y}; }); }) | ranges::views::join; diff --git a/src/engine/utility/grid2d.hpp b/src/engine/utility/grid2d.hpp index 1f6a82d..e7b96e9 100644 --- a/src/engine/utility/grid2d.hpp +++ b/src/engine/utility/grid2d.hpp @@ -28,7 +28,7 @@ public: T get(int x, int y) { return grid[y][x]; } - auto get_range() { + ranges::any_view get_range() { int height = get_height(); int width = get_width(); return ranges::views::iota(0, height) | ranges::views::transform([height, width](int y) { diff --git a/src/engine/utility/point.hpp b/src/engine/utility/point.hpp index dc00d01..37e0267 100644 --- a/src/engine/utility/point.hpp +++ b/src/engine/utility/point.hpp @@ -10,6 +10,14 @@ struct Point { int x; int y; + bool operator==(const Point &rhs) const { + return x == rhs.x && + y == rhs.y; + } + + bool operator!=(const Point &rhs) const { + return !(rhs == *this); + } }; diff --git a/src/game/dungeonalgorithm.hpp b/src/game/dungeonalgorithm.hpp index 68e4578..d2e60d4 100644 --- a/src/game/dungeonalgorithm.hpp +++ b/src/game/dungeonalgorithm.hpp @@ -5,10 +5,13 @@ #ifndef RLA_IIPP_DUNGEONALGORITHM_HPP #define RLA_IIPP_DUNGEONALGORITHM_HPP +#include +#include +#include -class DungeonAlgorithm { - +struct DungeonAlgorithm { + std::string path; + std::optional algorithm_data; }; - #endif //RLA_IIPP_DUNGEONALGORITHM_HPP diff --git a/src/game/visualizer.hpp b/src/game/visualizer.hpp index 411faec..b6633ab 100644 --- a/src/game/visualizer.hpp +++ b/src/game/visualizer.hpp @@ -5,13 +5,14 @@ #include "../engine/rendering/renderer.hpp" #include "../engine/utility/camera.hpp" #include "../engine/utility/grid2d.hpp" +#include "../engine/scripting/luacontextmanager.hpp" #include #include #include #ifndef RLA_IIPP_VISUALIZER_HPP #define RLA_IIPP_VISUALIZER_HPP -#define MAP_SIZE_W 10 -#define MAP_SIZE_H 10 +#define MAP_SIZE_W 20 +#define MAP_SIZE_H 20 #define TILE_WIDTH 48 #define TILE_HEIGHT 48 #define WALL_CHAR '#' @@ -34,6 +35,7 @@ private: int window_height = 0; Grid2D tile_map = Grid2D(0, 0); Camera camera = Camera(); + LuaContextManager lua_context_manager = LuaContextManager(); int x = 0; int y=0;