started pulling in lua stuff, fixed an issue with camera range

This commit is contained in:
2021-12-12 17:17:09 -05:00
parent d5fd89e228
commit 8213dd8cb3
9 changed files with 55 additions and 12 deletions

View File

@@ -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)

View File

@@ -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<K, T> resource_map;

View File

@@ -2,4 +2,5 @@
// Created by m on 12/12/21.
//
#include "dungeonalgorithm.hpp"
#include "luacontextmanager.hpp"

View File

@@ -0,0 +1,16 @@
//
// Created by m on 12/12/21.
//
#ifndef RLA_IIPP_LUACONTEXTMANAGER_HPP
#define RLA_IIPP_LUACONTEXTMANAGER_HPP
#include <sol/sol.hpp>
class LuaContextManager {
public:
};
#endif //RLA_IIPP_LUACONTEXTMANAGER_HPP

View File

@@ -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<Point> 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;

View File

@@ -28,7 +28,7 @@ public:
T get(int x, int y) {
return grid[y][x];
}
auto get_range() {
ranges::any_view<Point> get_range() {
int height = get_height();
int width = get_width();
return ranges::views::iota(0, height) | ranges::views::transform([height, width](int y) {

View File

@@ -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);
}
};

View File

@@ -5,10 +5,13 @@
#ifndef RLA_IIPP_DUNGEONALGORITHM_HPP
#define RLA_IIPP_DUNGEONALGORITHM_HPP
#include <string>
#include <optional>
#include <sol/sol.hpp>
class DungeonAlgorithm {
struct DungeonAlgorithm {
std::string path;
std::optional<sol::table> algorithm_data;
};
#endif //RLA_IIPP_DUNGEONALGORITHM_HPP

View File

@@ -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 <vector>
#include <range/v3/range.hpp>
#include <range/v3/view.hpp>
#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<char> tile_map = Grid2D<char>(0, 0);
Camera camera = Camera();
LuaContextManager lua_context_manager = LuaContextManager();
int x = 0;
int y=0;