started pulling in lua stuff, fixed an issue with camera range
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -2,4 +2,5 @@
|
||||
// Created by m on 12/12/21.
|
||||
//
|
||||
|
||||
#include "dungeonalgorithm.hpp"
|
||||
#include "luacontextmanager.hpp"
|
||||
|
||||
16
src/engine/scripting/luacontextmanager.hpp
Normal file
16
src/engine/scripting/luacontextmanager.hpp
Normal 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
|
||||
@@ -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;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user