Added some helpers to camera and range lib to replace the standard ranges library due to some issues clangd has with the gcc implementation
This commit is contained in:
@@ -1,13 +1,12 @@
|
|||||||
|
set(CMAKE_CXX_STANDARD 20) # c++ 20
|
||||||
cmake_minimum_required(VERSION 3.22) # Specifies the required CMake version.
|
cmake_minimum_required(VERSION 3.22) # Specifies the required CMake version.
|
||||||
project(rla_iipp) # Defines the project name.
|
project(rla_iipp) # Defines the project name.
|
||||||
|
|
||||||
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) # Includes the contents of the conanbuildinfo.cmake file.
|
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) # Includes the contents of the conanbuildinfo.cmake file.
|
||||||
conan_basic_setup() # Prepares the CMakeList.txt for Conan.
|
conan_basic_setup() # Prepares the CMakeList.txt for Conan.
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 20) # c++ 20
|
|
||||||
|
|
||||||
# $source_files is a space-delimited list of filenames.
|
# $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/game/camera.cpp src/game/camera.hpp src/engine/utility/point.hpp src/engine/utility/rectangle.hpp src/engine/utility/grid2d.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/game/dungeonalgorithm.cpp src/game/dungeonalgorithm.hpp) # Specifies the executable to build.
|
||||||
target_link_libraries(rla_iipp ${CONAN_LIBS}) # Specifies what libraries to link, using Conan.
|
target_link_libraries(rla_iipp ${CONAN_LIBS}) # Specifies what libraries to link, using Conan.
|
||||||
file(COPY assets DESTINATION ${CMAKE_BINARY_DIR}/bin)
|
file(COPY assets DESTINATION ${CMAKE_BINARY_DIR}/bin)
|
||||||
file(COPY config DESTINATION ${CMAKE_BINARY_DIR}/bin)
|
file(COPY config DESTINATION ${CMAKE_BINARY_DIR}/bin)
|
||||||
@@ -5,5 +5,6 @@ sdl_image/2.0.5
|
|||||||
fmt/8.0.1
|
fmt/8.0.1
|
||||||
tomlplusplus/2.5.0
|
tomlplusplus/2.5.0
|
||||||
sol2/3.2.3
|
sol2/3.2.3
|
||||||
|
range-v3/0.11.0
|
||||||
[generators]
|
[generators]
|
||||||
cmake
|
cmake
|
||||||
@@ -5,6 +5,21 @@
|
|||||||
#include "camera.hpp"
|
#include "camera.hpp"
|
||||||
|
|
||||||
Rectangle Camera::get_bounds() {
|
Rectangle Camera::get_bounds() {
|
||||||
|
return cached_bounds;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Camera::move_camera(Point new_center) {
|
||||||
|
this->center = new_center;
|
||||||
|
this->cached_bounds = calculate_bounds();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Camera::set_bounds(int max_x, int max_y) {
|
||||||
|
this->max_x = max_x;
|
||||||
|
this->max_y = max_y;
|
||||||
|
this->cached_bounds = calculate_bounds();
|
||||||
|
}
|
||||||
|
|
||||||
|
Rectangle Camera::calculate_bounds() {
|
||||||
int minx = std::clamp(center.x-(tiles_rendered_x/2), 0, std::max(0,max_x - tiles_rendered_x));
|
int minx = std::clamp(center.x-(tiles_rendered_x/2), 0, std::max(0,max_x - tiles_rendered_x));
|
||||||
int miny = std::clamp(center.y-(tiles_rendered_y/2), 0, std::max(0,max_y - tiles_rendered_y));
|
int miny = std::clamp(center.y-(tiles_rendered_y/2), 0, std::max(0,max_y - tiles_rendered_y));
|
||||||
int width = std::min(tiles_rendered_x, max_x-minx);
|
int width = std::min(tiles_rendered_x, max_x-minx);
|
||||||
@@ -12,11 +27,7 @@ Rectangle Camera::get_bounds() {
|
|||||||
return Rectangle{minx, miny, width, height};
|
return Rectangle{minx, miny, width, height};
|
||||||
}
|
}
|
||||||
|
|
||||||
void Camera::move_camera(Point new_center) {
|
Point Camera::camera_coords_to_screen_coords(Point camera_coord) {
|
||||||
this->center = new_center;
|
auto bounds = get_bounds();
|
||||||
}
|
return Point{camera_coord.x-bounds.x, camera_coord.y-bounds.y};
|
||||||
|
|
||||||
void Camera::set_bounds(int max_x, int max_y) {
|
|
||||||
this->max_x = max_x;
|
|
||||||
this->max_y = max_y;
|
|
||||||
}
|
}
|
||||||
@@ -6,8 +6,8 @@
|
|||||||
#define RLA_IIPP_CAMERA_HPP
|
#define RLA_IIPP_CAMERA_HPP
|
||||||
|
|
||||||
|
|
||||||
#include "../engine/utility/point.hpp"
|
#include "point.hpp"
|
||||||
#include "../engine/utility/rectangle.hpp"
|
#include "rectangle.hpp"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
class Camera {
|
class Camera {
|
||||||
@@ -18,10 +18,13 @@ private:
|
|||||||
int tiles_rendered_y=0;
|
int tiles_rendered_y=0;
|
||||||
int max_x=0;
|
int max_x=0;
|
||||||
int max_y=0;
|
int max_y=0;
|
||||||
|
Rectangle cached_bounds=Rectangle();
|
||||||
|
Rectangle calculate_bounds();
|
||||||
public:
|
public:
|
||||||
Rectangle get_bounds();
|
Rectangle get_bounds();
|
||||||
void move_camera(Point new_center);
|
void move_camera(Point new_center);
|
||||||
void set_bounds(int max_x, int max_y);
|
void set_bounds(int max_x, int max_y);
|
||||||
|
Point camera_coords_to_screen_coords(Point camera_coord);
|
||||||
Camera()=default;
|
Camera()=default;
|
||||||
|
|
||||||
Camera(const Point ¢er, int tilesRenderedX, int tilesRenderedY, int maxX, int maxY) : center(center),
|
Camera(const Point ¢er, int tilesRenderedX, int tilesRenderedY, int maxX, int maxY) : center(center),
|
||||||
@@ -30,7 +33,10 @@ public:
|
|||||||
tiles_rendered_y(
|
tiles_rendered_y(
|
||||||
tilesRenderedY),
|
tilesRenderedY),
|
||||||
max_x(maxX),
|
max_x(maxX),
|
||||||
max_y(maxY) {}
|
max_y(maxY)
|
||||||
|
{
|
||||||
|
cached_bounds = calculate_bounds();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
5
src/game/dungeonalgorithm.cpp
Normal file
5
src/game/dungeonalgorithm.cpp
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
//
|
||||||
|
// Created by m on 12/12/21.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "dungeonalgorithm.hpp"
|
||||||
14
src/game/dungeonalgorithm.hpp
Normal file
14
src/game/dungeonalgorithm.hpp
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
//
|
||||||
|
// Created by m on 12/12/21.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef RLA_IIPP_DUNGEONALGORITHM_HPP
|
||||||
|
#define RLA_IIPP_DUNGEONALGORITHM_HPP
|
||||||
|
|
||||||
|
|
||||||
|
class DungeonAlgorithm {
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif //RLA_IIPP_DUNGEONALGORITHM_HPP
|
||||||
@@ -30,16 +30,19 @@ void Visualizer::render(Renderer *renderer) {
|
|||||||
auto wall = Sprite{&tiles, 497};
|
auto wall = Sprite{&tiles, 497};
|
||||||
auto character = Sprite{&characters, this->sprite_index};
|
auto character = Sprite{&characters, this->sprite_index};
|
||||||
auto bounds = this->camera.get_bounds();
|
auto bounds = this->camera.get_bounds();
|
||||||
for(int ty=bounds.y;ty<bounds.y+bounds.height;ty++) {
|
|
||||||
for(int tx=bounds.x;tx<bounds.x+bounds.width;tx++) {
|
for(int ty : ranges::views::iota(bounds.y, bounds.y+bounds.height)) {
|
||||||
|
for(int tx : ranges::views::iota(bounds.x, bounds.x+bounds.width)) {
|
||||||
|
auto wp = camera.camera_coords_to_screen_coords(Point{tx, ty});
|
||||||
|
int wx = wp.x, wy = wp.y;
|
||||||
if(this->tile_map.get(tx, ty) == FLOOR_CHAR) {
|
if(this->tile_map.get(tx, ty) == FLOOR_CHAR) {
|
||||||
renderer->draw_sprite(grass, (tx-bounds.x)*TILE_WIDTH, (ty-bounds.y)*TILE_HEIGHT);
|
renderer->draw_sprite(grass, wx*TILE_WIDTH, wy*TILE_HEIGHT);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
renderer->draw_sprite(wall, (tx-bounds.x)*TILE_WIDTH, (ty-bounds.y)*TILE_HEIGHT);
|
renderer->draw_sprite(wall, wx*TILE_WIDTH, wy*TILE_HEIGHT);
|
||||||
}
|
}
|
||||||
if(tx == x && ty == y) {
|
if(tx == x && ty == y) {
|
||||||
renderer->draw_sprite(character, (tx-bounds.x)*TILE_WIDTH, (ty-bounds.y)*TILE_HEIGHT);
|
renderer->draw_sprite(character, wx*TILE_WIDTH, wy*TILE_HEIGHT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -59,12 +62,7 @@ void Visualizer::initialize_map(int width, int height) {
|
|||||||
this->tile_map = Grid2D<char>(width, height);
|
this->tile_map = Grid2D<char>(width, height);
|
||||||
for(int ty=0;ty<this->tile_map.get_height();ty++) {
|
for(int ty=0;ty<this->tile_map.get_height();ty++) {
|
||||||
for (int tx = 0; tx < tile_map.get_width(); tx++) {
|
for (int tx = 0; tx < tile_map.get_width(); tx++) {
|
||||||
if (tx == 0 || ty == 0 || ty == this->tile_map.get_height() - 1 || tx == this->tile_map.get_width() - 1) {
|
this->tile_map.insert(tx, ty, FLOOR_CHAR);
|
||||||
this->tile_map.insert(tx, ty, WALL_CHAR);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
this->tile_map.insert(tx, ty, FLOOR_CHAR);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,13 +3,15 @@
|
|||||||
//
|
//
|
||||||
#include "../engine/game/game.hpp"
|
#include "../engine/game/game.hpp"
|
||||||
#include "../engine/rendering/renderer.hpp"
|
#include "../engine/rendering/renderer.hpp"
|
||||||
#include "camera.hpp"
|
#include "../engine/utility/camera.hpp"
|
||||||
#include "../engine/utility/grid2d.hpp"
|
#include "../engine/utility/grid2d.hpp"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <range/v3/range.hpp>
|
||||||
|
#include <range/v3/view.hpp>
|
||||||
#ifndef RLA_IIPP_VISUALIZER_HPP
|
#ifndef RLA_IIPP_VISUALIZER_HPP
|
||||||
#define RLA_IIPP_VISUALIZER_HPP
|
#define RLA_IIPP_VISUALIZER_HPP
|
||||||
#define MAP_SIZE_W 10
|
#define MAP_SIZE_W 20
|
||||||
#define MAP_SIZE_H 10
|
#define MAP_SIZE_H 20
|
||||||
#define TILE_WIDTH 48
|
#define TILE_WIDTH 48
|
||||||
#define TILE_HEIGHT 48
|
#define TILE_HEIGHT 48
|
||||||
#define WALL_CHAR '#'
|
#define WALL_CHAR '#'
|
||||||
|
|||||||
Reference in New Issue
Block a user