Compare commits
7 Commits
5cd3a68e6d
...
win_build
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aa52ff9f8e | ||
|
|
3180fc026d | ||
|
|
f57d52c670 | ||
|
|
7ef37e180a | ||
|
|
8008f55cb9 | ||
|
|
118c6260b4 | ||
|
|
1240d21ef8 |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,4 +1,4 @@
|
|||||||
tags
|
tags
|
||||||
python/.ipynb_checkpoints
|
python/.ipynb_checkpoints
|
||||||
cpp/build
|
cpp/test
|
||||||
cpp/pathfinding
|
cpp/pathfinding
|
||||||
|
|||||||
9
.gitmodules
vendored
Normal file
9
.gitmodules
vendored
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
[submodule "vs/SDL"]
|
||||||
|
path = vs/SDL
|
||||||
|
url = https://github.com/libsdl-org/SDL.git
|
||||||
|
[submodule "vs/glew"]
|
||||||
|
path = vs/glew
|
||||||
|
url = gitea@gitea.veleslabs.org:jan.mrna/glew.git
|
||||||
|
[submodule "vs/SDL_image"]
|
||||||
|
path = vs/SDL_image
|
||||||
|
url = https://github.com/libsdl-org/SDL_image.git
|
||||||
@@ -48,6 +48,6 @@ Alternatively (or if you want to edit the file), you can use the [Jupyeter Lab o
|
|||||||
- [x] drawing tiles
|
- [x] drawing tiles
|
||||||
- [x] add "terrain tiles" with different costs
|
- [x] add "terrain tiles" with different costs
|
||||||
- [x] add mouse-click action
|
- [x] add mouse-click action
|
||||||
- [x] add direct movement (through mouse click action, no pathfinding)
|
- [ ] add direct movement (through mouse click action, no pathfinding)
|
||||||
- [ ] implement pathfinding
|
- [ ] implement pathfinding
|
||||||
- [ ] windows build?
|
- [ ] windows build?
|
||||||
|
|||||||
39
cpp/Makefile
39
cpp/Makefile
@@ -1,34 +1,9 @@
|
|||||||
# ---------------------------------
|
all: test pathfinding
|
||||||
# Generated by Kimi K2
|
# TODO add extra warnings
|
||||||
#---------- configurable ----------
|
# TODO linter?
|
||||||
CXX := g++
|
|
||||||
CXXFLAGS := -std=c++23 -Wall -Wextra -Wpedantic -ggdb3
|
|
||||||
LDFLAGS :=
|
|
||||||
LDLIBS := -lSDL3 -lSDL3_image -lGLEW -lGL
|
|
||||||
|
|
||||||
SRC_DIR := src
|
pathfinding: src/main.cpp src/array.hpp
|
||||||
BUILD_DIR:= build
|
g++ -Wall -ggdb3 -lSDL3 -lSDL3_image -std=c++23 -lGLEW -lGL -o pathfinding src/main.cpp
|
||||||
TARGET := pathfinding
|
|
||||||
|
|
||||||
#----------------------------------
|
test: src/test.cpp src/array.hpp
|
||||||
SOURCES := $(wildcard $(SRC_DIR)/*.cpp)
|
g++ -Wall -Wextra -Wpedantic -ggdb3 -std=c++23 -lgtest -o test src/test.cpp
|
||||||
OBJECTS := $(SOURCES:$(SRC_DIR)/%.cpp=$(BUILD_DIR)/%.o)
|
|
||||||
|
|
||||||
#----------------------------------
|
|
||||||
.PHONY: all clean
|
|
||||||
|
|
||||||
all: $(TARGET)
|
|
||||||
|
|
||||||
# link step
|
|
||||||
$(TARGET): $(OBJECTS)
|
|
||||||
$(CXX) $(LDFLAGS) -o $@ $^ $(LDLIBS)
|
|
||||||
|
|
||||||
# compile step
|
|
||||||
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.cpp | $(BUILD_DIR)
|
|
||||||
$(CXX) $(CXXFLAGS) -c -o $@ $<
|
|
||||||
|
|
||||||
$(BUILD_DIR):
|
|
||||||
mkdir -p $@
|
|
||||||
|
|
||||||
clean:
|
|
||||||
rm -rf $(BUILD_DIR) $(TARGET)
|
|
||||||
|
|||||||
@@ -1,66 +0,0 @@
|
|||||||
#include <memory>
|
|
||||||
|
|
||||||
#include "entities.hpp"
|
|
||||||
|
|
||||||
#include "log.hpp"
|
|
||||||
#include "math.hpp"
|
|
||||||
#include "sprite.hpp"
|
|
||||||
|
|
||||||
Entity::Entity(WorldPos position) : m_Position(position) {
|
|
||||||
LOG_DEBUG("spawning entity at position ", position);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::ostream &operator<<(std::ostream &os, const Entity &obj) {
|
|
||||||
static constexpr std::array<std::string_view,
|
|
||||||
static_cast<size_t>(Entity::Type::COUNT)>
|
|
||||||
type_name{"NONE", "PLAYER", "TILE"};
|
|
||||||
size_t idx = static_cast<size_t>(obj.GetType());
|
|
||||||
assert(idx < type_name.size());
|
|
||||||
os << type_name[idx];
|
|
||||||
return os;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Entity::ZeroActualVelocityInDirection(WorldPos direction) {
|
|
||||||
// Vectors e1, e2 form the basis for a local coord system,
|
|
||||||
// where e1 is formed by the direction where we want to zero-out
|
|
||||||
// the velocity, and e2 is the orthogonal vector.
|
|
||||||
// Scalars q1, q2 are coordinates for e1, e2 basis.
|
|
||||||
WorldPos e1 = direction.normalized();
|
|
||||||
WorldPos e2 = e1.orthogonal();
|
|
||||||
|
|
||||||
// q1 * e1 + q2 * e2 = v, from this follows:
|
|
||||||
auto &v = GetActualVelocity();
|
|
||||||
float q2 = (v.y * e1.x - v.x * e1.y) / (e2.y * e1.x - e2.x * e1.y);
|
|
||||||
float q1 = (v.x - q2 * e2.x) / e1.x;
|
|
||||||
|
|
||||||
// We then zero-out the q1, but only if it's positive - meaning
|
|
||||||
// it is aiming in the direction of "direction", not out.
|
|
||||||
// (otherwise we're not able to move out from collision with
|
|
||||||
// another object)
|
|
||||||
if (q1 > 0.0f) {
|
|
||||||
SetActualVelocity(q2 * e2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Entity::Update(float time_delta) {
|
|
||||||
m_Position += m_ActualVelocity * time_delta;
|
|
||||||
}
|
|
||||||
|
|
||||||
Player::Player() {
|
|
||||||
LOG_DEBUG(".");
|
|
||||||
if (m_Sprite == nullptr) {
|
|
||||||
LoadResources();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Sprite &Player::GetSprite() {
|
|
||||||
assert(m_Sprite != nullptr);
|
|
||||||
return *m_Sprite;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Player::LoadResources() {
|
|
||||||
m_Sprite =
|
|
||||||
std::make_unique<Sprite>("resources/player.png", WorldPos{38.0f, 46.0f});
|
|
||||||
}
|
|
||||||
|
|
||||||
std::unique_ptr<Sprite> Player::m_Sprite;
|
|
||||||
@@ -1,85 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <array>
|
|
||||||
#include <cstdint>
|
|
||||||
#include <iostream>
|
|
||||||
#include <memory>
|
|
||||||
#include <string_view>
|
|
||||||
|
|
||||||
#include "log.hpp"
|
|
||||||
#include "math.hpp"
|
|
||||||
#include "sprite.hpp"
|
|
||||||
|
|
||||||
class Entity {
|
|
||||||
public:
|
|
||||||
enum class Type : std::uint8_t {
|
|
||||||
NONE,
|
|
||||||
PLAYER,
|
|
||||||
TILE,
|
|
||||||
COUNT // must be last
|
|
||||||
};
|
|
||||||
|
|
||||||
Entity(WorldPos position = {0.0f, 0.0f});
|
|
||||||
Entity(const Entity &) = delete;
|
|
||||||
Entity &operator=(const Entity &) = delete;
|
|
||||||
Entity(Entity &&) = delete;
|
|
||||||
Entity &operator=(Entity &&) = delete;
|
|
||||||
|
|
||||||
friend std::ostream &operator<<(std::ostream &os, const Entity &obj);
|
|
||||||
|
|
||||||
virtual Sprite &GetSprite() = 0;
|
|
||||||
virtual constexpr float GetCollisionRadius() const = 0;
|
|
||||||
virtual constexpr Type GetType() const = 0;
|
|
||||||
virtual bool IsMovable() const = 0;
|
|
||||||
virtual bool IsCollidable() const = 0;
|
|
||||||
|
|
||||||
virtual void Update(float time_delta);
|
|
||||||
|
|
||||||
virtual constexpr float GetCollisionRadiusSquared() const {
|
|
||||||
return GetCollisionRadius() * GetCollisionRadius();
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetFlagExpired() { m_FlagExpired = true; }
|
|
||||||
bool IsFlaggedExpired() const { return m_FlagExpired; }
|
|
||||||
|
|
||||||
const WorldPos &GetPosition() const { return m_Position; }
|
|
||||||
void SetPosition(WorldPos new_pos) { m_Position = new_pos; }
|
|
||||||
|
|
||||||
const WorldPos &GetActualVelocity() const { return m_ActualVelocity; }
|
|
||||||
const WorldPos &GetRequestedVelocity() const { return m_RequestedVelocity; }
|
|
||||||
void SetActualVelocity(const WorldPos &new_velocity) {
|
|
||||||
m_ActualVelocity = new_velocity;
|
|
||||||
}
|
|
||||||
void SetRequestedVelocity(const WorldPos &new_velocity) {
|
|
||||||
m_RequestedVelocity = new_velocity;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ZeroActualVelocityInDirection(WorldPos direction);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
WorldPos m_Position;
|
|
||||||
WorldPos m_ActualVelocity;
|
|
||||||
WorldPos m_RequestedVelocity;
|
|
||||||
|
|
||||||
private:
|
|
||||||
bool m_FlagExpired = false;
|
|
||||||
static constexpr float m_CollisionRadiusSq = 1000.0f;
|
|
||||||
};
|
|
||||||
|
|
||||||
class Player final : public Entity {
|
|
||||||
public:
|
|
||||||
Player();
|
|
||||||
|
|
||||||
Sprite &GetSprite() override;
|
|
||||||
|
|
||||||
constexpr Entity::Type GetType() const override {
|
|
||||||
return Entity::Type::PLAYER;
|
|
||||||
}
|
|
||||||
constexpr float GetCollisionRadius() const override { return 50.0f; }
|
|
||||||
bool IsMovable() const override { return true; }
|
|
||||||
bool IsCollidable() const override { return true; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
void LoadResources();
|
|
||||||
static std::unique_ptr<Sprite> m_Sprite;
|
|
||||||
};
|
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
#include <thread>
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
#include "gameloop.hpp"
|
|
||||||
|
|
||||||
#include "pathfindingdemo.hpp"
|
|
||||||
#include "window.hpp"
|
|
||||||
#include "user_input.hpp"
|
|
||||||
#include "log.hpp"
|
|
||||||
#include "pathfinder.hpp"
|
|
||||||
#include "math.hpp"
|
|
||||||
|
|
||||||
void GameLoop::Run() {
|
|
||||||
LOG_INFO("Running the game");
|
|
||||||
while (!m_Game->IsExitRequested()) {
|
|
||||||
m_Game->HandleActions(m_UserInput->GetActions());
|
|
||||||
m_Game->UpdatePlayerVelocity();
|
|
||||||
|
|
||||||
m_Window->ClearWindow();
|
|
||||||
|
|
||||||
// TODO wrap all of the drawing in some function
|
|
||||||
// TODO rethink coupling and dependencies here
|
|
||||||
|
|
||||||
// draw the map (terrain tiles)
|
|
||||||
const Map &map = m_Game->GetMap();
|
|
||||||
const auto &tiles = map.GetMapTiles();
|
|
||||||
for (size_t row = 0; row < tiles.size(); row++) {
|
|
||||||
for (size_t col = 0; col < tiles[row].size(); col++) {
|
|
||||||
// LOG_DEBUG("Drawing rect (", row, ", ", col, ")");
|
|
||||||
m_Window->DrawRect(
|
|
||||||
map.TileEdgeToWorld(TilePos{row, col}),
|
|
||||||
map.GetTileSize(), tiles[row][col]->R, tiles[row][col]->G,
|
|
||||||
tiles[row][col]->B, tiles[row][col]->A);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// draw the path, if it exists
|
|
||||||
WorldPos start_pos = m_Game->GetPlayer()->GetPosition();
|
|
||||||
for (const auto& next_pos: m_Game->GetPath()) {
|
|
||||||
m_Window->DrawLine(start_pos, next_pos);
|
|
||||||
start_pos = next_pos;
|
|
||||||
}
|
|
||||||
|
|
||||||
// draw all the entities (player etc)
|
|
||||||
for (auto &entity : m_Game->GetEntities()) {
|
|
||||||
m_Window->DrawSprite(entity->GetPosition(), entity->GetSprite());
|
|
||||||
}
|
|
||||||
|
|
||||||
m_Window->Flush();
|
|
||||||
// TODO measure fps
|
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(30));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
#include "pathfindingdemo.hpp"
|
|
||||||
#include "window.hpp"
|
|
||||||
#include "user_input.hpp"
|
|
||||||
|
|
||||||
class GameLoop {
|
|
||||||
public:
|
|
||||||
GameLoop() = default;
|
|
||||||
~GameLoop() = default;
|
|
||||||
|
|
||||||
GameLoop(const GameLoop&) = delete;
|
|
||||||
GameLoop(GameLoop&&) = delete;
|
|
||||||
GameLoop& operator=(const GameLoop&) = delete;
|
|
||||||
GameLoop& operator=(GameLoop&&) = delete;
|
|
||||||
|
|
||||||
void Run();
|
|
||||||
|
|
||||||
void SetGame(std::unique_ptr<PathFindingDemo> x) {
|
|
||||||
m_Game = std::move(x);
|
|
||||||
}
|
|
||||||
void SetWindow(std::unique_ptr<Window> x) { m_Window = std::move(x); }
|
|
||||||
void SetUserInput(std::unique_ptr<UserInput> x) {
|
|
||||||
m_UserInput = std::move(x);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::unique_ptr<PathFindingDemo> m_Game;
|
|
||||||
std::unique_ptr<Window> m_Window;
|
|
||||||
std::unique_ptr<UserInput> m_UserInput;
|
|
||||||
};
|
|
||||||
@@ -2,13 +2,21 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#define LOG_CRITICAL(...) Log::critical(__PRETTY_FUNCTION__, ": ", __VA_ARGS__)
|
#if defined(__GNUC__) || defined(__clang__)
|
||||||
#define LOG_ERROR(...) Log::error(__PRETTY_FUNCTION__, ": ", __VA_ARGS__)
|
# define PRETTY_FUNC __PRETTY_FUNCTION__
|
||||||
#define LOG_WARNING(...) Log::warning(__PRETTY_FUNCTION__, ": ", __VA_ARGS__)
|
#elif defined(_MSC_VER)
|
||||||
#define LOG_INFO(...) Log::info(__PRETTY_FUNCTION__, ": ", __VA_ARGS__)
|
# define PRETTY_FUNC __FUNCTION__
|
||||||
#define LOG_DEBUG(...) Log::debug(__PRETTY_FUNCTION__, ": ", __VA_ARGS__)
|
#else
|
||||||
|
# define PRETTY_FUNC __func__
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define LOG_CRITICAL(...) Log::critical(PRETTY_FUNC, ": ", __VA_ARGS__)
|
||||||
|
#define LOG_ERROR(...) Log::error(PRETTY_FUNC, ": ", __VA_ARGS__)
|
||||||
|
#define LOG_WARNING(...) Log::warning(PRETTY_FUNC, ": ", __VA_ARGS__)
|
||||||
|
#define LOG_INFO(...) Log::info(PRETTY_FUNC, ": ", __VA_ARGS__)
|
||||||
|
#define LOG_DEBUG(...) Log::debug(PRETTY_FUNC, ": ", __VA_ARGS__)
|
||||||
#define LOG_PROFILING_DEBUG(...) \
|
#define LOG_PROFILING_DEBUG(...) \
|
||||||
Log::profiling_debug(__PRETTY_FUNCTION__, ": ", __VA_ARGS__)
|
Log::profiling_debug(PRETTY_FUNC, ": ", __VA_ARGS__)
|
||||||
|
|
||||||
namespace Log {
|
namespace Log {
|
||||||
enum class LevelTypes {
|
enum class LevelTypes {
|
||||||
|
|||||||
789
cpp/src/main.cpp
789
cpp/src/main.cpp
@@ -1,18 +1,785 @@
|
|||||||
#include "gameloop.hpp"
|
#include <cassert>
|
||||||
#include "log.hpp"
|
#include <chrono>
|
||||||
#include "pathfindingdemo.hpp"
|
#include <cmath>
|
||||||
#include "user_input.hpp"
|
#include <cstdlib>
|
||||||
#include "window.hpp"
|
#include <expected>
|
||||||
|
#include <iostream>
|
||||||
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <thread>
|
||||||
|
#include <unordered_set>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
int main() {
|
#include "array.hpp"
|
||||||
|
#include "log.hpp"
|
||||||
|
#include "math.hpp"
|
||||||
|
|
||||||
|
//
|
||||||
|
// Utils
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// Math stuff
|
||||||
|
//
|
||||||
|
|
||||||
|
// Forward declarations
|
||||||
|
class Sprite;
|
||||||
|
class Sound;
|
||||||
|
class UserAction;
|
||||||
|
|
||||||
|
//
|
||||||
|
// UI stuff. This is the part directly dependent on the SDL
|
||||||
|
//
|
||||||
|
|
||||||
|
// containers
|
||||||
|
|
||||||
|
#include <GL/glew.h>
|
||||||
|
#include <SDL3/SDL.h>
|
||||||
|
#include <SDL3_image/SDL_image.h>
|
||||||
|
|
||||||
|
class Sound {
|
||||||
|
public:
|
||||||
|
Sound() { LOG_DEBUG("."); }
|
||||||
|
Sound(const Sound &x) { LOG_DEBUG("."); }
|
||||||
|
Sound(Sound &&x) noexcept { LOG_DEBUG("."); }
|
||||||
|
~Sound() { LOG_DEBUG("."); }
|
||||||
|
};
|
||||||
|
|
||||||
|
class AudioOutput {
|
||||||
|
public:
|
||||||
|
AudioOutput() { LOG_DEBUG("."); }
|
||||||
|
AudioOutput(const AudioOutput &x) = delete;
|
||||||
|
AudioOutput(AudioOutput &&x) = delete;
|
||||||
|
~AudioOutput() { LOG_DEBUG("."); }
|
||||||
|
|
||||||
|
std::expected<void, std::string> Init() {
|
||||||
|
LOG_INFO("Initialing audio output");
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
void PlaySound(Sound &s);
|
||||||
|
};
|
||||||
|
|
||||||
|
class Sprite {
|
||||||
|
public:
|
||||||
|
Sprite() : m_Texture(nullptr, SDL_DestroyTexture) {}
|
||||||
|
Sprite(std::string path, Vec2D<float> center) : Sprite() {
|
||||||
|
LoadImage(path, center);
|
||||||
|
}
|
||||||
|
int m_R = 0;
|
||||||
|
int m_G = 0;
|
||||||
|
int m_B = 0;
|
||||||
|
int m_A = 0;
|
||||||
|
Sprite(const Sprite &x) = delete;
|
||||||
|
Sprite(Sprite &&x) = delete;
|
||||||
|
~Sprite() { LOG_DEBUG("."); }
|
||||||
|
void LoadImage(std::string path, Vec2D<float> image_center = {0.0, 0.0}) {
|
||||||
|
LOG_INFO("Loading image ", path);
|
||||||
|
assert(m_Renderer != nullptr);
|
||||||
|
|
||||||
|
auto surface = std::unique_ptr<SDL_Surface, decltype(&SDL_DestroySurface)>(
|
||||||
|
IMG_Load(path.c_str()), SDL_DestroySurface);
|
||||||
|
|
||||||
|
if (surface == nullptr) {
|
||||||
|
LOG_ERROR("IMG_Load failed to load ", path);
|
||||||
|
throw std::runtime_error("Failed to load resources");
|
||||||
|
}
|
||||||
|
|
||||||
|
m_Texture = std::unique_ptr<SDL_Texture, decltype(&SDL_DestroyTexture)>(
|
||||||
|
SDL_CreateTextureFromSurface(m_Renderer.get(), surface.get()),
|
||||||
|
SDL_DestroyTexture);
|
||||||
|
if (m_Texture == nullptr) {
|
||||||
|
LOG_ERROR("SDL_CreateTextureFromSurface failed");
|
||||||
|
throw std::runtime_error("Failed to load resources");
|
||||||
|
}
|
||||||
|
float w, h;
|
||||||
|
SDL_GetTextureSize(m_Texture.get(), &w, &h);
|
||||||
|
m_Size = {w, h};
|
||||||
|
m_ImageCenter = image_center;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Renderer is shared for all class instances - we need it in order
|
||||||
|
// to create textures from images
|
||||||
|
static void SetRenderer(std::shared_ptr<SDL_Renderer> renderer) {
|
||||||
|
m_Renderer = renderer;
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetTexture cannot return pointer to const, as SDL_RenderTexture modifies it
|
||||||
|
SDL_Texture *GetTexture() { return m_Texture.get(); }
|
||||||
|
|
||||||
|
Vec2D<float> GetSize() const { return m_Size; }
|
||||||
|
Vec2D<float> GetCenter() const { return m_ImageCenter; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
static std::shared_ptr<SDL_Renderer> m_Renderer;
|
||||||
|
std::unique_ptr<SDL_Texture, decltype(&SDL_DestroyTexture)> m_Texture;
|
||||||
|
Vec2D<float> m_Size;
|
||||||
|
Vec2D<float> m_ImageCenter;
|
||||||
|
float m_TextureWidth = 0;
|
||||||
|
float m_TextureHeight = 0;
|
||||||
|
};
|
||||||
|
std::shared_ptr<SDL_Renderer> Sprite::m_Renderer = nullptr;
|
||||||
|
|
||||||
|
// User interface classes
|
||||||
|
|
||||||
|
class Window {
|
||||||
|
public:
|
||||||
|
Window(const Window &x) = delete;
|
||||||
|
Window(Window &&x) = delete;
|
||||||
|
Window(int width, int height) : m_Width(width), m_Height(height) {
|
||||||
|
LOG_DEBUG(".");
|
||||||
|
}
|
||||||
|
|
||||||
|
std::expected<void, std::string> Init() {
|
||||||
|
LOG_DEBUG(".");
|
||||||
|
|
||||||
|
if (SDL_Init(SDL_INIT_VIDEO) == false) {
|
||||||
|
return std::unexpected(std::string("SDL could not initialize! Error: ") +
|
||||||
|
SDL_GetError());
|
||||||
|
}
|
||||||
|
m_Window = SDL_CreateWindow("SDL2 Window", m_Width, m_Height,
|
||||||
|
SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
|
||||||
|
if (m_Window == nullptr) {
|
||||||
|
std::atexit(SDL_Quit);
|
||||||
|
return std::unexpected(
|
||||||
|
std::string("Window could not be created! Error: ") + SDL_GetError());
|
||||||
|
}
|
||||||
|
|
||||||
|
m_Context = SDL_GL_CreateContext(m_Window);
|
||||||
|
if (m_Context == nullptr) {
|
||||||
|
SDL_DestroyWindow(m_Window);
|
||||||
|
std::atexit(SDL_Quit);
|
||||||
|
return std::unexpected(
|
||||||
|
std::string("GL context could not be created! Error: ") +
|
||||||
|
SDL_GetError());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (glewInit() != GLEW_OK) {
|
||||||
|
SDL_GL_DestroyContext(m_Context);
|
||||||
|
SDL_DestroyWindow(m_Window);
|
||||||
|
std::atexit(SDL_Quit);
|
||||||
|
return std::unexpected("GLEW init failed!");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Resize();
|
||||||
|
|
||||||
|
m_Renderer = std::shared_ptr<SDL_Renderer>(
|
||||||
|
SDL_CreateRenderer(m_Window, NULL), SDL_DestroyRenderer);
|
||||||
|
if (m_Renderer == nullptr) {
|
||||||
|
SDL_DestroyWindow(m_Window);
|
||||||
|
std::atexit(SDL_Quit);
|
||||||
|
return std::unexpected(
|
||||||
|
std::string("Renderer could not be created! Error: ") +
|
||||||
|
SDL_GetError());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set renderer to the Sprite class
|
||||||
|
Sprite::SetRenderer(m_Renderer);
|
||||||
|
|
||||||
|
// TODO this needs to be tied to map size
|
||||||
|
SDL_SetRenderScale(m_Renderer.get(), 1.0f, 1.0f);
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
~Window() {
|
||||||
|
// SDL_DestroyRenderer(m_Renderer); // handled by shared_ptr
|
||||||
|
SDL_GL_DestroyContext(m_Context);
|
||||||
|
SDL_DestroyWindow(m_Window);
|
||||||
|
std::atexit(SDL_Quit);
|
||||||
|
LOG_DEBUG(".");
|
||||||
|
}
|
||||||
|
|
||||||
|
void DrawSprite(const Vec2D<float> &position, Sprite &s) {
|
||||||
|
Vec2D<float> size = s.GetSize();
|
||||||
|
Vec2D<float> img_center = s.GetCenter();
|
||||||
|
SDL_FRect rect = {position.x - img_center.x, position.y - img_center.y,
|
||||||
|
size.x, size.y};
|
||||||
|
SDL_RenderTexture(m_Renderer.get(), s.GetTexture(), nullptr, &rect);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DrawRect(const Vec2D<float> &position, const Vec2D<float> size,
|
||||||
|
uint8_t R, uint8_t G, uint8_t B, uint8_t A) {
|
||||||
|
SDL_FRect rect = {position.x, position.y,
|
||||||
|
size.x, size.y};
|
||||||
|
SDL_SetRenderDrawColor(m_Renderer.get(), R, G, B, A);
|
||||||
|
SDL_RenderFillRect(m_Renderer.get(), &rect);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ClearWindow() {
|
||||||
|
SDL_SetRenderDrawColor(m_Renderer.get(), 50, 50, 50, 255);
|
||||||
|
SDL_RenderClear(m_Renderer.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
void Flush() { SDL_RenderPresent(m_Renderer.get()); }
|
||||||
|
|
||||||
|
void DrawCircle(const Vec2D<float> &position, float radius) {
|
||||||
|
int cx = static_cast<int>(position.x);
|
||||||
|
int cy = static_cast<int>(position.y);
|
||||||
|
SDL_SetRenderDrawColor(m_Renderer.get(), 255, 0, 0, 255);
|
||||||
|
for (int i = 0; i < 360; ++i) {
|
||||||
|
double a = i * M_PI / 180.0;
|
||||||
|
SDL_RenderPoint(m_Renderer.get(),
|
||||||
|
cx + static_cast<int>(std::round(radius * std::cos(a))),
|
||||||
|
cy + static_cast<int>(std::round(radius * std::sin(a))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<SDL_Renderer> m_Renderer = nullptr;
|
||||||
|
SDL_Window *m_Window;
|
||||||
|
SDL_GLContext m_Context;
|
||||||
|
|
||||||
|
private:
|
||||||
|
uint32_t m_Width;
|
||||||
|
uint32_t m_Height;
|
||||||
|
};
|
||||||
|
|
||||||
|
class UserAction {
|
||||||
|
public:
|
||||||
|
enum class Type { NONE, EXIT, MOVE, CROUCH, STAND, FIRE, MOVE_TARGET};
|
||||||
|
|
||||||
|
UserAction() = default;
|
||||||
|
|
||||||
|
UserAction(Type t) : type(t) {}
|
||||||
|
|
||||||
|
UserAction(Type t, char key) : type(t), Argument{.key = key} {}
|
||||||
|
|
||||||
|
UserAction(Type t, Vec2D<float> v) : type(t), Argument{.position = v} {}
|
||||||
|
|
||||||
|
~UserAction() = default;
|
||||||
|
|
||||||
|
Type type;
|
||||||
|
|
||||||
|
union {
|
||||||
|
Vec2D<float> position;
|
||||||
|
char key;
|
||||||
|
} Argument;
|
||||||
|
};
|
||||||
|
|
||||||
|
class UserInput {
|
||||||
|
public:
|
||||||
|
UserInput()
|
||||||
|
: // pre-alloc some space
|
||||||
|
m_Actions(10) {
|
||||||
|
LOG_DEBUG(".");
|
||||||
|
};
|
||||||
|
|
||||||
|
UserInput(const UserInput &x) = delete;
|
||||||
|
UserInput(UserInput &&x) = delete;
|
||||||
|
~UserInput() { LOG_DEBUG("."); };
|
||||||
|
|
||||||
|
std::expected<void, std::string> Init() { return {}; }
|
||||||
|
|
||||||
|
const std::vector<UserAction> &GetActions() {
|
||||||
|
m_Actions.clear();
|
||||||
|
static Vec2D<float> move_direction = {0.0f, 0.0f};
|
||||||
|
static bool send_move_action = false;
|
||||||
|
SDL_Event event;
|
||||||
|
|
||||||
|
while (SDL_PollEvent(&event)) {
|
||||||
|
if (event.type == SDL_EVENT_KEY_DOWN || event.type == SDL_EVENT_KEY_UP) {
|
||||||
|
bool key_down = event.type == SDL_EVENT_KEY_DOWN ? true : false;
|
||||||
|
SDL_KeyboardEvent kbd_event = event.key;
|
||||||
|
if (kbd_event.repeat) {
|
||||||
|
// SDL repeats KEY_DOWN if key is held down, we ignore that
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
LOG_DEBUG("Key '", static_cast<char>(kbd_event.key),
|
||||||
|
key_down ? "' down" : "' up");
|
||||||
|
|
||||||
|
switch (kbd_event.key) {
|
||||||
|
case 'q':
|
||||||
|
m_Actions.emplace_back(UserAction::Type::EXIT);
|
||||||
|
// further processing of inputs is not needed
|
||||||
|
return m_Actions;
|
||||||
|
case 'w':
|
||||||
|
case 's':
|
||||||
|
case 'a':
|
||||||
|
case 'd':
|
||||||
|
case SDLK_UP:
|
||||||
|
case SDLK_DOWN:
|
||||||
|
case SDLK_LEFT:
|
||||||
|
case SDLK_RIGHT: {
|
||||||
|
static std::map<char, Vec2D<float>> move_base{
|
||||||
|
{'w', {0.0, 1.0}},
|
||||||
|
{'s', {0.0, -1.0}},
|
||||||
|
{'a', {1.0, 0.0}},
|
||||||
|
{'d', {-1.0, 0.0}},
|
||||||
|
{static_cast<char>(SDLK_UP), {0.0, 1.0}},
|
||||||
|
{static_cast<char>(SDLK_DOWN), {0.0, -1.0}},
|
||||||
|
{static_cast<char>(SDLK_LEFT), {1.0, 0.0}},
|
||||||
|
{static_cast<char>(SDLK_RIGHT), {-1.0, 0.0}},
|
||||||
|
};
|
||||||
|
|
||||||
|
float direction = key_down ? -1.0f : 1.0f;
|
||||||
|
send_move_action = true;
|
||||||
|
move_direction += move_base[kbd_event.key] * direction;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SDLK_SPACE:
|
||||||
|
if (key_down)
|
||||||
|
m_Actions.emplace_back(UserAction::Type::FIRE);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
LOG_INFO("Key '", static_cast<char>(kbd_event.key), "' not mapped");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else if (event.type == SDL_EVENT_MOUSE_BUTTON_DOWN) {
|
||||||
|
SDL_MouseButtonEvent mouse_event = event.button;
|
||||||
|
LOG_DEBUG("Mouse down: ", mouse_event.x, ", ", mouse_event.y);
|
||||||
|
m_Actions.emplace_back(UserAction::Type::MOVE_TARGET,
|
||||||
|
Vec2D<float>{mouse_event.x, mouse_event.y});
|
||||||
|
} else {
|
||||||
|
// TODO uncomment, for now too much noise
|
||||||
|
// LOG_WARNING("Action not processed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (send_move_action) {
|
||||||
|
m_Actions.emplace_back(UserAction::Type::MOVE,
|
||||||
|
move_direction.normalized());
|
||||||
|
send_move_action = false;
|
||||||
|
}
|
||||||
|
return m_Actions;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<UserAction> m_Actions;
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// Game classes
|
||||||
|
//
|
||||||
|
|
||||||
|
class Entity {
|
||||||
|
public:
|
||||||
|
enum class Type : std::uint8_t {
|
||||||
|
NONE,
|
||||||
|
PLAYER,
|
||||||
|
WALL,
|
||||||
|
TILE,
|
||||||
|
COUNT // must be last
|
||||||
|
};
|
||||||
|
|
||||||
|
Entity(Vec2D<float> position = {0.0f, 0.0f}) : m_Position(position) {
|
||||||
|
LOG_DEBUG("spawning entity at position ", position);
|
||||||
|
}
|
||||||
|
|
||||||
|
friend std::ostream &operator<<(std::ostream &os, const Entity &obj) {
|
||||||
|
static constexpr std::array<std::string_view,
|
||||||
|
static_cast<size_t>(Entity::Type::COUNT)>
|
||||||
|
type_name{"NONE", "PLAYER", "WALL", "TILE"};
|
||||||
|
size_t idx = static_cast<size_t>(obj.GetType());
|
||||||
|
assert(idx < type_name.size());
|
||||||
|
os << type_name[idx];
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual Sprite &GetSprite() = 0;
|
||||||
|
virtual constexpr float GetCollisionRadius() const = 0;
|
||||||
|
virtual constexpr float GetCollisionRadiusSquared() {
|
||||||
|
return GetCollisionRadius() * GetCollisionRadius();
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual constexpr Type GetType() const = 0;
|
||||||
|
void SetFlagExpired() { m_FlagExpired = true; }
|
||||||
|
bool IsFlaggedExpired() { return m_FlagExpired; }
|
||||||
|
|
||||||
|
const Vec2D<float> &GetPosition() const { return m_Position; }
|
||||||
|
void SetPosition(Vec2D<float> new_pos) { m_Position = new_pos; }
|
||||||
|
|
||||||
|
const Vec2D<float> &GetActualVelocity() const { return m_ActualVelocity; }
|
||||||
|
const Vec2D<float> &GetRequestedVelocity() const {
|
||||||
|
return m_RequestedVelocity;
|
||||||
|
}
|
||||||
|
void SetActualVelocity(const Vec2D<float> &new_velocity) {
|
||||||
|
m_ActualVelocity = new_velocity;
|
||||||
|
}
|
||||||
|
void SetRequestedVelocity(const Vec2D<float> &new_velocity) {
|
||||||
|
m_RequestedVelocity = new_velocity;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZeroActualVelocityInDirection(Vec2D<float> direction) {
|
||||||
|
// Vectors e1, e2 form the basis for a local coord system,
|
||||||
|
// where e1 is formed by the direction where we want to zero-out
|
||||||
|
// the velocity, and e2 is the orthogonal vector.
|
||||||
|
// Scalars q1, q2 are coordinates for e1, e2 basis.
|
||||||
|
Vec2D<float> e1 = direction.normalized();
|
||||||
|
Vec2D<float> e2 = e1.orthogonal();
|
||||||
|
|
||||||
|
// q1 * e1 + q2 * e2 = v, from this follows:
|
||||||
|
auto &v = GetActualVelocity();
|
||||||
|
float q2 = (v.y * e1.x - v.x * e1.y) / (e2.y * e1.x - e2.x * e1.y);
|
||||||
|
float q1 = (v.x - q2 * e2.x) / e1.x;
|
||||||
|
|
||||||
|
// We then zero-out the q1, but only if it's positive - meaning
|
||||||
|
// it is aiming in the direction of "direction", not out.
|
||||||
|
// (otherwise we're not able to move out from collision with
|
||||||
|
// another object)
|
||||||
|
if (q1 > 0.0f) {
|
||||||
|
SetActualVelocity(q2 * e2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void Update(float time_delta) {
|
||||||
|
m_Position += m_ActualVelocity * time_delta;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual bool IsMovable() const = 0;
|
||||||
|
virtual bool IsCollidable() const = 0;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
Vec2D<float> m_Position;
|
||||||
|
Vec2D<float> m_ActualVelocity;
|
||||||
|
Vec2D<float> m_RequestedVelocity;
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool m_FlagExpired = false;
|
||||||
|
static constexpr float m_CollisionRadiusSq = 1000.0f;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Wall final : public Entity {
|
||||||
|
public:
|
||||||
|
Wall(Vec2D<float> pos = {0.0f, 0.0f}) : Entity(pos) {
|
||||||
|
LOG_DEBUG(".");
|
||||||
|
if (m_Sprite == nullptr) {
|
||||||
|
LoadResources();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Wall(const Wall &x) = delete;
|
||||||
|
Wall(Wall &&x) = delete;
|
||||||
|
|
||||||
|
Sprite &GetSprite() override {
|
||||||
|
assert(m_Sprite != nullptr);
|
||||||
|
return *m_Sprite;
|
||||||
|
}
|
||||||
|
constexpr Entity::Type GetType() const override { return Entity::Type::WALL; }
|
||||||
|
constexpr float GetCollisionRadius() const override { return 50.0f; }
|
||||||
|
bool IsMovable() const override { return false; }
|
||||||
|
bool IsCollidable() const override { return true; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
void LoadResources() {
|
||||||
|
m_Sprite = std::make_unique<Sprite>("resources/wall.png",
|
||||||
|
Vec2D<float>{50.0f, 50.0f});
|
||||||
|
}
|
||||||
|
static std::unique_ptr<Sprite> m_Sprite;
|
||||||
|
};
|
||||||
|
std::unique_ptr<Sprite> Wall::m_Sprite;
|
||||||
|
|
||||||
|
class Player final : public Entity {
|
||||||
|
public:
|
||||||
|
Player() {
|
||||||
|
LOG_DEBUG(".");
|
||||||
|
if (m_Sprite == nullptr) {
|
||||||
|
LoadResources();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Player(const Player &x) = delete;
|
||||||
|
Player(Player &&x) = delete;
|
||||||
|
|
||||||
|
Sprite &GetSprite() override {
|
||||||
|
assert(m_Sprite != nullptr);
|
||||||
|
return *m_Sprite;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr Entity::Type GetType() const override {
|
||||||
|
return Entity::Type::PLAYER;
|
||||||
|
}
|
||||||
|
constexpr float GetCollisionRadius() const override { return 50.0f; }
|
||||||
|
bool IsMovable() const override { return true; }
|
||||||
|
bool IsCollidable() const override { return true; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
void LoadResources() {
|
||||||
|
m_Sprite = std::make_unique<Sprite>("resources/player.png",
|
||||||
|
Vec2D<float>{38.0f, 46.0f});
|
||||||
|
}
|
||||||
|
static std::unique_ptr<Sprite> m_Sprite;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::unique_ptr<Sprite> Player::m_Sprite;
|
||||||
|
|
||||||
|
using Collision = std::pair<std::shared_ptr<Entity>, std::shared_ptr<Entity>>;
|
||||||
|
|
||||||
|
struct Tile {
|
||||||
|
float cost;
|
||||||
|
uint8_t R, G, B, A;
|
||||||
|
};
|
||||||
|
|
||||||
|
static const std::map<std::string_view, Tile> tile_types = {
|
||||||
|
{"Grass", {1.0, 0, 200, 0, 255}},
|
||||||
|
{"Mud", {2.0, 100, 100, 100, 255}},
|
||||||
|
{"Road", {0.5, 200, 200, 200, 255}},
|
||||||
|
{"Water", {10.0, 0, 50, 200, 255}},
|
||||||
|
};
|
||||||
|
|
||||||
|
using TilePos = Vec2D<int>;
|
||||||
|
using WorldPos = Vec2D<float>;
|
||||||
|
|
||||||
|
class Map {
|
||||||
|
|
||||||
|
// TODO using = ... for tile vector
|
||||||
|
|
||||||
|
public:
|
||||||
|
static constexpr float TILE_SIZE = 100.0f; // tile size in world
|
||||||
|
|
||||||
|
Map(int width, int height) : m_Width(width), m_Height(height) {
|
||||||
|
bool sw = true;
|
||||||
|
LOG_DEBUG("width = ", width, " height = ", height);
|
||||||
|
m_Tiles = std::vector<std::vector<const Tile *>>{};
|
||||||
|
for (int i = 0; i < m_Width; i++) {
|
||||||
|
m_Tiles.push_back(std::vector<const Tile *>{});
|
||||||
|
for (int j = 0; j < m_Height; j++) {
|
||||||
|
if (sw)
|
||||||
|
m_Tiles[i].push_back(&tile_types.at("Grass"));
|
||||||
|
else
|
||||||
|
m_Tiles[i].push_back(&tile_types.at("Water"));
|
||||||
|
sw = !sw;
|
||||||
|
}
|
||||||
|
sw = !sw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Map() : Map(0, 0) {}
|
||||||
|
|
||||||
|
const std::vector<std::vector<const Tile *>> &GetMapTiles() const {
|
||||||
|
return m_Tiles;
|
||||||
|
}
|
||||||
|
|
||||||
|
WorldPos TileToWorld(TilePos p) const {
|
||||||
|
return WorldPos{p.x * TILE_SIZE, p.y * TILE_SIZE};
|
||||||
|
}
|
||||||
|
|
||||||
|
TilePos WorldToTile(WorldPos p) const {
|
||||||
|
return TilePos{p.x / TILE_SIZE, p.y / TILE_SIZE};
|
||||||
|
}
|
||||||
|
|
||||||
|
Vec2D<float> GetTileSize() const {
|
||||||
|
return Vec2D<float>{TILE_SIZE, TILE_SIZE};
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
// std::vector<std::vector<const Tile*>> m_Tiles;
|
||||||
|
std::vector<std::vector<const Tile *>> m_Tiles;
|
||||||
|
int m_Width = 0;
|
||||||
|
int m_Height = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
class PathFindingDemo {
|
||||||
|
public:
|
||||||
|
PathFindingDemo(int width, int height)
|
||||||
|
: m_Width(width), m_Height(height), // TODO delete width, height
|
||||||
|
m_Map(width, height) {
|
||||||
|
LOG_DEBUG(".");
|
||||||
|
}
|
||||||
|
|
||||||
|
~PathFindingDemo() { LOG_DEBUG("."); }
|
||||||
|
|
||||||
|
PathFindingDemo(const PathFindingDemo &m) = delete;
|
||||||
|
PathFindingDemo(PathFindingDemo &&m) = delete;
|
||||||
|
|
||||||
|
void AddEntity(std::shared_ptr<Entity> e) {
|
||||||
|
// TODO emplace_back
|
||||||
|
m_Entities.push_back(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CreateMap() {
|
||||||
|
m_Entities.clear();
|
||||||
|
m_Player = std::make_shared<Player>();
|
||||||
|
m_Player->SetPosition(Vec2D<float>{200.0f, 200.0f});
|
||||||
|
m_Entities.push_back(m_Player);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<Player> GetPlayer() { return m_Player; }
|
||||||
|
|
||||||
|
Vec2D<float> GetRandomPosition() const { return Vec2D<float>{0.0, 0.0}; }
|
||||||
|
|
||||||
|
std::vector<std::shared_ptr<Entity>> &GetEntities() { return m_Entities; }
|
||||||
|
|
||||||
|
void UpdateEntities() {
|
||||||
|
float time_delta = 1.0f;
|
||||||
|
|
||||||
|
// Remove entities marked as expired and handle expiry logic (e.g. bomb
|
||||||
|
// exploding); for all other entities, reset the actual velocity to the
|
||||||
|
// requested; actual velocity will be updated later with collisions
|
||||||
|
for (auto &entity : m_Entities) {
|
||||||
|
if (entity->IsFlaggedExpired()) {
|
||||||
|
ExpiryGameLogic(*entity);
|
||||||
|
auto it = std::find(m_Entities.begin(), m_Entities.end(), entity);
|
||||||
|
if (it != m_Entities.end()) {
|
||||||
|
std::swap(*it, m_Entities.back());
|
||||||
|
m_Entities.pop_back();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Actual velocity might be changed later by collisions
|
||||||
|
entity->SetActualVelocity(entity->GetRequestedVelocity());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle collisions:
|
||||||
|
// - update actual velocity for colliding objects
|
||||||
|
// - handle collision logic
|
||||||
|
auto &collisions = GetEntityCollisions();
|
||||||
|
// LOG_DEBUG("number of collisions: ", collisions.size());
|
||||||
|
for (auto &collision : collisions) {
|
||||||
|
Entity &A = *std::get<0>(collision);
|
||||||
|
Entity &B = *std::get<1>(collision);
|
||||||
|
if (!A.IsMovable())
|
||||||
|
continue;
|
||||||
|
// modify actual speed
|
||||||
|
// LOG_DEBUG("Collision: A is ", A, ", B is ", B);
|
||||||
|
Vec2D<float> AB = B.GetPosition() - A.GetPosition();
|
||||||
|
A.ZeroActualVelocityInDirection(AB);
|
||||||
|
// handle logic
|
||||||
|
CollisionGameLogic(A, B);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update entities: this advances animations,
|
||||||
|
// internal timers, and updates positions (with velocity
|
||||||
|
// modified by the collision handling)
|
||||||
|
for (auto &entity : m_Entities) {
|
||||||
|
entity->Update(time_delta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CollisionGameLogic(Entity &A, Entity &B) {
|
||||||
|
// not used for path finding demo
|
||||||
|
}
|
||||||
|
|
||||||
|
void ExpiryGameLogic(Entity &entity) {
|
||||||
|
// not used for path finding demo
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::vector<Collision> &GetEntityCollisions() {
|
||||||
|
static std::vector<Collision> m_Collisions;
|
||||||
|
|
||||||
|
m_Collisions.clear();
|
||||||
|
for (const auto &entity_A : m_Entities) {
|
||||||
|
for (const auto &entity_B : m_Entities) {
|
||||||
|
if (entity_A == entity_B)
|
||||||
|
continue;
|
||||||
|
if (!entity_A->IsCollidable() || !entity_B->IsCollidable())
|
||||||
|
continue;
|
||||||
|
// check distance of player to given entity
|
||||||
|
auto position_A = entity_A->GetPosition();
|
||||||
|
auto position_B = entity_B->GetPosition();
|
||||||
|
auto distance_sq = position_A.distance_squared(position_B);
|
||||||
|
auto collision_distance_sq =
|
||||||
|
entity_A->GetCollisionRadiusSquared() +
|
||||||
|
entity_B->GetCollisionRadiusSquared() +
|
||||||
|
2 * entity_A->GetCollisionRadius() * entity_B->GetCollisionRadius();
|
||||||
|
// TODO use vector instructions
|
||||||
|
if (distance_sq < collision_distance_sq) {
|
||||||
|
m_Collisions.emplace_back(Collision(entity_A, entity_B));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return m_Collisions;
|
||||||
|
}
|
||||||
|
|
||||||
|
void HandleActions(const std::vector<UserAction> &actions) {
|
||||||
|
for (const auto &action : actions) {
|
||||||
|
if (action.type == UserAction::Type::EXIT) {
|
||||||
|
LOG_INFO("Exit requested");
|
||||||
|
m_ExitRequested = true;
|
||||||
|
} else if (action.type == UserAction::Type::FIRE) {
|
||||||
|
LOG_INFO("Fire");
|
||||||
|
// AddEntity(m_Player->CreateBomb());
|
||||||
|
} else if (action.type == UserAction::Type::MOVE) {
|
||||||
|
LOG_INFO("Move direction ", action.Argument.position);
|
||||||
|
m_Player->SetRequestedVelocity(action.Argument.position * 4.0f);
|
||||||
|
} else if (action.type == UserAction::Type::MOVE_TARGET) {
|
||||||
|
TilePos p = m_Map.WorldToTile(action.Argument.position);
|
||||||
|
LOG_INFO("Move target: ", action.Argument.position, ", tile pos: ", p);
|
||||||
|
// TODO move
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const Map &GetMap() const { return m_Map; }
|
||||||
|
|
||||||
|
bool IsCollisionBoxVisible() const { return m_DrawCollisionBox; }
|
||||||
|
bool IsExitRequested() const { return m_ExitRequested; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
int m_Width;
|
||||||
|
int m_Height;
|
||||||
|
bool m_ExitRequested = false;
|
||||||
|
bool m_DrawCollisionBox = true;
|
||||||
|
std::vector<std::shared_ptr<Entity>> m_Entities;
|
||||||
|
std::shared_ptr<Player> m_Player;
|
||||||
|
Map m_Map;
|
||||||
|
};
|
||||||
|
|
||||||
|
// GameLoop class handles user input and audio/video output,
|
||||||
|
// client side only. No game logic should be handled here.
|
||||||
|
|
||||||
|
class GameLoop {
|
||||||
|
public:
|
||||||
|
GameLoop() = default;
|
||||||
|
|
||||||
|
void Run() {
|
||||||
|
LOG_INFO("Running the game");
|
||||||
|
while (!m_Game->IsExitRequested()) {
|
||||||
|
m_Game->HandleActions(m_UserInput->GetActions());
|
||||||
|
m_Game->UpdateEntities();
|
||||||
|
|
||||||
|
m_Window->ClearWindow();
|
||||||
|
|
||||||
|
// draw the map (terrain tiles)
|
||||||
|
const Map &map = m_Game->GetMap();
|
||||||
|
const auto &tiles = map.GetMapTiles();
|
||||||
|
for (int row = 0; row < tiles.size(); row++) {
|
||||||
|
for (int col = 0; col < tiles[row].size(); col++) {
|
||||||
|
// LOG_DEBUG("Drawing rect (", row, ", ", col, ")");
|
||||||
|
m_Window->DrawRect(
|
||||||
|
map.TileToWorld(TilePos{row, col}),
|
||||||
|
map.GetTileSize(), tiles[row][col]->R, tiles[row][col]->G,
|
||||||
|
tiles[row][col]->B, tiles[row][col]->A);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// draw all the entities (player etc)
|
||||||
|
for (auto &entity : m_Game->GetEntities()) {
|
||||||
|
m_Window->DrawSprite(entity->GetPosition(), entity->GetSprite());
|
||||||
|
if (m_Game->IsCollisionBoxVisible()) {
|
||||||
|
m_Window->DrawCircle(entity->GetPosition(),
|
||||||
|
entity->GetCollisionRadius());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m_Window->Flush();
|
||||||
|
// TODO measure fps
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(30));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void SetGame(std::unique_ptr<PathFindingDemo> x) {
|
||||||
|
m_Game = std::move(x);
|
||||||
|
}
|
||||||
|
inline void SetWindow(std::unique_ptr<Window> x) { m_Window = std::move(x); }
|
||||||
|
inline void SetUserInput(std::unique_ptr<UserInput> x) {
|
||||||
|
m_UserInput = std::move(x);
|
||||||
|
}
|
||||||
|
inline void SetAudioOutput(std::unique_ptr<AudioOutput> x) {
|
||||||
|
m_AudioOutput = std::move(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::unique_ptr<PathFindingDemo> m_Game;
|
||||||
|
std::unique_ptr<Window> m_Window;
|
||||||
|
std::unique_ptr<UserInput> m_UserInput;
|
||||||
|
std::unique_ptr<AudioOutput> m_AudioOutput;
|
||||||
|
};
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
constexpr int error = -1;
|
constexpr int error = -1;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initialize the input/output system
|
* Initialize the input/output system
|
||||||
*/
|
*/
|
||||||
|
|
||||||
auto window = std::make_unique<Window>(640, 480);
|
auto window = std::make_unique<Window>(640, 480); // the holy resolution
|
||||||
|
// auto window_init = window->Init();
|
||||||
if (auto initialized = window->Init(); !initialized) {
|
if (auto initialized = window->Init(); !initialized) {
|
||||||
LOG_ERROR(initialized.error());
|
LOG_ERROR(initialized.error());
|
||||||
return error;
|
return error;
|
||||||
@@ -24,6 +791,12 @@ int main() {
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto audio_output = std::make_unique<AudioOutput>();
|
||||||
|
if (auto initialized = audio_output->Init(); !initialized) {
|
||||||
|
LOG_ERROR(initialized.error());
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initialize the map and run the pathfinding demo
|
* Initialize the map and run the pathfinding demo
|
||||||
*/
|
*/
|
||||||
@@ -34,7 +807,7 @@ int main() {
|
|||||||
auto game_loop = GameLoop{};
|
auto game_loop = GameLoop{};
|
||||||
game_loop.SetWindow(std::move(window));
|
game_loop.SetWindow(std::move(window));
|
||||||
game_loop.SetUserInput(std::move(user_input));
|
game_loop.SetUserInput(std::move(user_input));
|
||||||
|
game_loop.SetAudioOutput(std::move(audio_output));
|
||||||
game_loop.SetGame(std::move(demo));
|
game_loop.SetGame(std::move(demo));
|
||||||
game_loop.Run();
|
game_loop.Run();
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,86 +0,0 @@
|
|||||||
#include <cassert>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "log.hpp"
|
|
||||||
#include "map.hpp"
|
|
||||||
#include "tile.hpp"
|
|
||||||
|
|
||||||
Map::Map(int rows, int cols) : m_Cols(cols), m_Rows(rows) {
|
|
||||||
bool sw = true;
|
|
||||||
LOG_DEBUG("cols = ", cols, " rows = ", rows);
|
|
||||||
m_Tiles = std::vector<std::vector<const Tile *>>{};
|
|
||||||
for (size_t row = 0; row < m_Rows; row++) {
|
|
||||||
m_Tiles.push_back(std::vector<const Tile *>{});
|
|
||||||
for (size_t col = 0; col < m_Cols; col++) {
|
|
||||||
if (sw)
|
|
||||||
m_Tiles[row].push_back(&tile_types.at("Grass"));
|
|
||||||
else
|
|
||||||
m_Tiles[row].push_back(&tile_types.at("Road"));
|
|
||||||
sw = !sw;
|
|
||||||
}
|
|
||||||
sw = !sw;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
WorldPos Map::TileToWorld(TilePos p) const {
|
|
||||||
return WorldPos{(p.x + 0.5) * TILE_SIZE, (p.y + 0.5) * TILE_SIZE};
|
|
||||||
}
|
|
||||||
|
|
||||||
WorldPos Map::TileEdgeToWorld(TilePos p) const {
|
|
||||||
return WorldPos{p.x * TILE_SIZE, p.y * TILE_SIZE};
|
|
||||||
}
|
|
||||||
|
|
||||||
TilePos Map::WorldToTile(WorldPos p) const {
|
|
||||||
return TilePos{p.x / TILE_SIZE, p.y / TILE_SIZE};
|
|
||||||
}
|
|
||||||
|
|
||||||
WorldPos Map::GetTileSize() const { return WorldPos{TILE_SIZE, TILE_SIZE}; }
|
|
||||||
|
|
||||||
const Tile *Map::GetTileAt(TilePos p) const {
|
|
||||||
assert(IsTilePosValid(p));
|
|
||||||
size_t row = p.x;
|
|
||||||
size_t col = p.y;
|
|
||||||
|
|
||||||
return m_Tiles[row][col];
|
|
||||||
}
|
|
||||||
|
|
||||||
const Tile *Map::GetTileAt(WorldPos p) const {
|
|
||||||
return GetTileAt(WorldToTile(p));
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Map::IsTilePosValid(TilePos p) const {
|
|
||||||
size_t row = p.x;
|
|
||||||
size_t col = p.y;
|
|
||||||
|
|
||||||
return row < m_Tiles.size() && col < m_Tiles[0].size();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
std::vector<TilePos> Map::GetNeighbors(TilePos center) const
|
|
||||||
{
|
|
||||||
std::vector<TilePos> neighbours;
|
|
||||||
neighbours.reserve(4);
|
|
||||||
|
|
||||||
std::array<TilePos, 4> candidates = {
|
|
||||||
center + TilePos{1,0},
|
|
||||||
center + TilePos{-1,0},
|
|
||||||
center + TilePos{0, 1},
|
|
||||||
center + TilePos{0, -1},
|
|
||||||
};
|
|
||||||
|
|
||||||
for (const auto& c : candidates) {
|
|
||||||
if (IsTilePosValid(c))
|
|
||||||
neighbours.push_back(c);
|
|
||||||
}
|
|
||||||
return neighbours;
|
|
||||||
}
|
|
||||||
// std::vector<TilePos> neighbours;
|
|
||||||
// neighbours.reserve(8);
|
|
||||||
// for (int dx = -1; dx <= 1; ++dx) {
|
|
||||||
// for (int dy = -1; dy <= 1; ++dy) {
|
|
||||||
// if (dx == 0 && dy == 0) continue;
|
|
||||||
// TilePos p{center.x + dx, center.y + dy};
|
|
||||||
// if (IsTilePosValid(p)) neighbours.push_back(std::move(p));
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return neighbours;
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "math.hpp"
|
|
||||||
#include "tile.hpp"
|
|
||||||
|
|
||||||
using TileGrid = std::vector<std::vector<const Tile *>>;
|
|
||||||
|
|
||||||
class Map {
|
|
||||||
public:
|
|
||||||
static constexpr float TILE_SIZE = 100.0f; // tile size in world
|
|
||||||
|
|
||||||
Map(int rows, int cols);
|
|
||||||
Map() : Map(0, 0) {}
|
|
||||||
|
|
||||||
Map(const Map&) = delete;
|
|
||||||
Map(Map&&) = delete;
|
|
||||||
Map& operator=(const Map&) = delete;
|
|
||||||
Map& operator=(Map&&) = delete;
|
|
||||||
|
|
||||||
const TileGrid &GetMapTiles() const { return m_Tiles; }
|
|
||||||
|
|
||||||
// coordinate conversion functions
|
|
||||||
WorldPos TileToWorld(TilePos p) const;
|
|
||||||
WorldPos TileEdgeToWorld(TilePos p) const;
|
|
||||||
TilePos WorldToTile(WorldPos p) const;
|
|
||||||
|
|
||||||
WorldPos GetTileSize() const;
|
|
||||||
const Tile *GetTileAt(TilePos p) const;
|
|
||||||
const Tile *GetTileAt(WorldPos p) const;
|
|
||||||
|
|
||||||
bool IsTilePosValid(TilePos p) const;
|
|
||||||
|
|
||||||
|
|
||||||
std::vector<TilePos> GetNeighbors(TilePos center) const;
|
|
||||||
|
|
||||||
template <typename T> double GetTileVelocityCoeff(T p) const {
|
|
||||||
return 1.0 / GetTileAt(p)->cost;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
TileGrid m_Tiles;
|
|
||||||
size_t m_Cols = 0;
|
|
||||||
size_t m_Rows = 0;
|
|
||||||
};
|
|
||||||
@@ -3,11 +3,12 @@
|
|||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <concepts>
|
#include <concepts>
|
||||||
#include <initializer_list>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
constexpr double EQUALITY_LIMIT = 1e-6;
|
#ifdef _WIN32
|
||||||
|
#include <numbers>
|
||||||
|
#define M_PI std::numbers::pi
|
||||||
|
#endif
|
||||||
|
|
||||||
template <typename T> struct Vec2D {
|
template <typename T> struct Vec2D {
|
||||||
public:
|
public:
|
||||||
@@ -32,16 +33,6 @@ public:
|
|||||||
return Vec2D{k * v.x, k * v.y};
|
return Vec2D{k * v.x, k * v.y};
|
||||||
}
|
}
|
||||||
|
|
||||||
friend bool operator==(const Vec2D &a, const Vec2D &b) {
|
|
||||||
if constexpr (std::is_integral_v<T>) {
|
|
||||||
return a.x == b.x && a.y == b.y;
|
|
||||||
} else if constexpr (std::is_floating_point_v<T>) {
|
|
||||||
return a.distance(b) < EQUALITY_LIMIT;
|
|
||||||
} else {
|
|
||||||
static_assert("Unhandled comparison");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Vec2D operator*(float b) const { return Vec2D{b * x, b * y}; }
|
Vec2D operator*(float b) const { return Vec2D{b * x, b * y}; }
|
||||||
|
|
||||||
T distance_squared(const Vec2D &other) const {
|
T distance_squared(const Vec2D &other) const {
|
||||||
@@ -60,7 +51,7 @@ public:
|
|||||||
requires std::floating_point<T>
|
requires std::floating_point<T>
|
||||||
{
|
{
|
||||||
auto length = sqrt(x * x + y * y);
|
auto length = sqrt(x * x + y * y);
|
||||||
if (length < EQUALITY_LIMIT) {
|
if (length < 1e-6) {
|
||||||
x = y = 0;
|
x = y = 0;
|
||||||
} else {
|
} else {
|
||||||
x /= length;
|
x /= length;
|
||||||
@@ -100,15 +91,3 @@ public:
|
|||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
using TilePos = Vec2D<int>;
|
|
||||||
using WorldPos = Vec2D<float>;
|
|
||||||
|
|
||||||
struct TilePosHash {
|
|
||||||
std::size_t operator()(const TilePos& p) const noexcept {
|
|
||||||
std::size_t h1 = std::hash<int>{}(p.x);
|
|
||||||
std::size_t h2 = std::hash<int>{}(p.y);
|
|
||||||
return h1 ^ (h2 + 0x9e3779b9 + (h1<<6) + (h1>>2));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,89 +0,0 @@
|
|||||||
#include <memory>
|
|
||||||
#include <cassert>
|
|
||||||
#include <queue>
|
|
||||||
|
|
||||||
#include "pathfinder.hpp"
|
|
||||||
#include "log.hpp"
|
|
||||||
|
|
||||||
namespace pathfinder {
|
|
||||||
|
|
||||||
|
|
||||||
PathFinderBase::PathFinderBase(const Map* map) : m_Map(map) {}
|
|
||||||
|
|
||||||
|
|
||||||
Path LinearPathFinder::CalculatePath(WorldPos start, WorldPos end)
|
|
||||||
{
|
|
||||||
auto path = Path{end};
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Path BFS::CalculatePath(WorldPos start_world, WorldPos end_world) {
|
|
||||||
if (m_Map == nullptr) return {};
|
|
||||||
|
|
||||||
const TilePos start = m_Map->WorldToTile(start_world);
|
|
||||||
const TilePos end = m_Map->WorldToTile(end_world);
|
|
||||||
|
|
||||||
if (!m_Map->IsTilePosValid(start) || !m_Map->IsTilePosValid(end))
|
|
||||||
return {};
|
|
||||||
if (start == end) {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
// clear previous run
|
|
||||||
m_CameFrom.clear();
|
|
||||||
m_Distance.clear();
|
|
||||||
|
|
||||||
std::queue<TilePos> frontier;
|
|
||||||
frontier.push(start);
|
|
||||||
m_CameFrom[start] = start;
|
|
||||||
m_Distance[start] = 0.0f;
|
|
||||||
|
|
||||||
// ---------------- build flow-field ----------------
|
|
||||||
bool early_exit = false;
|
|
||||||
while (!frontier.empty() && !early_exit) {
|
|
||||||
TilePos current = frontier.front();
|
|
||||||
frontier.pop();
|
|
||||||
|
|
||||||
for (TilePos next : m_Map->GetNeighbors(current)) {
|
|
||||||
if (m_CameFrom.find(next) == m_CameFrom.end()) { // not visited
|
|
||||||
frontier.push(next);
|
|
||||||
m_Distance[next] = m_Distance[current] + 1.0f;
|
|
||||||
m_CameFrom[next] = current;
|
|
||||||
|
|
||||||
if (next == end) { // early exit
|
|
||||||
early_exit = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// --------------- reconstruct path -----------------
|
|
||||||
if (m_CameFrom.find(end) == m_CameFrom.end())
|
|
||||||
return {}; // end not reached
|
|
||||||
|
|
||||||
Path path;
|
|
||||||
TilePos cur = end;
|
|
||||||
path.push_back(m_Map->TileToWorld(cur));
|
|
||||||
while (cur != start) {
|
|
||||||
cur = m_CameFrom[cur];
|
|
||||||
path.push_back(m_Map->TileToWorld(cur));
|
|
||||||
}
|
|
||||||
std::reverse(path.begin(), path.end());
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::unique_ptr<PathFinderBase> create(PathFinderType type, const Map* map) {
|
|
||||||
switch (type) {
|
|
||||||
case PathFinderType::LINEAR:
|
|
||||||
return std::move(std::make_unique<LinearPathFinder>(map));
|
|
||||||
case PathFinderType::BFS:
|
|
||||||
return std::move(std::make_unique<BFS>(map));
|
|
||||||
case PathFinderType::COUNT:
|
|
||||||
LOG_WARNING("Incorrect pathfinder type");
|
|
||||||
return nullptr;
|
|
||||||
};
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // pathfinder namespace
|
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
#include <memory>
|
|
||||||
#include <unordered_map>
|
|
||||||
|
|
||||||
#include "math.hpp"
|
|
||||||
#include "map.hpp"
|
|
||||||
|
|
||||||
namespace pathfinder {
|
|
||||||
|
|
||||||
using Path = std::vector<WorldPos>;
|
|
||||||
|
|
||||||
enum class PathFinderType {
|
|
||||||
LINEAR = 1,
|
|
||||||
BFS,
|
|
||||||
COUNT,
|
|
||||||
};
|
|
||||||
|
|
||||||
class PathFinderBase {
|
|
||||||
public:
|
|
||||||
PathFinderBase(const Map* m);
|
|
||||||
~PathFinderBase() = default;
|
|
||||||
|
|
||||||
PathFinderBase(const PathFinderBase&) = delete;
|
|
||||||
PathFinderBase(PathFinderBase&&) = delete;
|
|
||||||
PathFinderBase& operator=(const PathFinderBase&) = delete;
|
|
||||||
PathFinderBase& operator=(PathFinderBase&&) = delete;
|
|
||||||
|
|
||||||
virtual const std::string_view& GetName() const = 0;
|
|
||||||
virtual Path CalculatePath(WorldPos start, WorldPos end) = 0;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
const Map* m_Map;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class LinearPathFinder : public PathFinderBase {
|
|
||||||
|
|
||||||
public:
|
|
||||||
LinearPathFinder(const Map* m): PathFinderBase(m) {}
|
|
||||||
Path CalculatePath(WorldPos start, WorldPos end) override;
|
|
||||||
const std::string_view& GetName() const override { return m_Name; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
const std::string_view m_Name = "Linear Path";
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class BFS: public PathFinderBase {
|
|
||||||
|
|
||||||
public:
|
|
||||||
BFS(const Map* m): PathFinderBase(m) {}
|
|
||||||
Path CalculatePath(WorldPos start, WorldPos end) override;
|
|
||||||
const std::string_view& GetName() const override { return m_Name; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
const std::string_view m_Name = "Breadth First Search";
|
|
||||||
std::unordered_map<TilePos, double, TilePosHash> m_Distance;
|
|
||||||
std::unordered_map<TilePos, TilePos, TilePosHash> m_CameFrom;
|
|
||||||
};
|
|
||||||
|
|
||||||
std::unique_ptr<PathFinderBase> create(PathFinderType type, const Map* map);
|
|
||||||
|
|
||||||
} // pathfinder namespace
|
|
||||||
|
|
||||||
@@ -1,95 +0,0 @@
|
|||||||
#include <memory>
|
|
||||||
#include <optional>
|
|
||||||
#include <queue>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "pathfindingdemo.hpp"
|
|
||||||
|
|
||||||
#include "entities.hpp"
|
|
||||||
#include "log.hpp"
|
|
||||||
#include "map.hpp"
|
|
||||||
#include "user_input.hpp"
|
|
||||||
#include "pathfinder.hpp"
|
|
||||||
|
|
||||||
PathFindingDemo::PathFindingDemo(int width, int height) :
|
|
||||||
m_Map(width, height)
|
|
||||||
{
|
|
||||||
LOG_DEBUG(".");
|
|
||||||
// set default pathfinder method
|
|
||||||
m_PathFinder = pathfinder::create(pathfinder::PathFinderType::LINEAR, (const Map*)&m_Map);
|
|
||||||
}
|
|
||||||
|
|
||||||
PathFindingDemo::~PathFindingDemo() { LOG_DEBUG("."); }
|
|
||||||
|
|
||||||
void PathFindingDemo::AddEntity(std::shared_ptr<Entity> e) {
|
|
||||||
// TODO emplace_back
|
|
||||||
m_Entities.push_back(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
void PathFindingDemo::CreateMap() {
|
|
||||||
m_Entities.clear();
|
|
||||||
m_Player = std::make_shared<Player>();
|
|
||||||
m_Player->SetPosition(WorldPos{200.0f, 200.0f});
|
|
||||||
m_Entities.push_back(m_Player);
|
|
||||||
}
|
|
||||||
|
|
||||||
WorldPos PathFindingDemo::GetRandomPosition() const {
|
|
||||||
return WorldPos{0.0, 0.0};
|
|
||||||
}
|
|
||||||
|
|
||||||
std::optional<WorldPos> PathFindingDemo::GetMoveTarget() {
|
|
||||||
WorldPos current_player_pos = GetPlayer()->GetPosition();
|
|
||||||
|
|
||||||
if (m_Path.empty()) {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
WorldPos next_player_pos = m_Path.front();
|
|
||||||
|
|
||||||
if (current_player_pos.distance(next_player_pos) > 10.0) {
|
|
||||||
// target not reached yet
|
|
||||||
return next_player_pos;
|
|
||||||
}
|
|
||||||
// target reached, pop it
|
|
||||||
//m_MoveQueue.pop();
|
|
||||||
m_Path.erase(m_Path.begin());
|
|
||||||
// return nothing - if there's next point in the queue,
|
|
||||||
// we'll get it in the next iteration
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
void PathFindingDemo::UpdatePlayerVelocity() {
|
|
||||||
auto player = GetPlayer();
|
|
||||||
auto current_pos = player->GetPosition();
|
|
||||||
double tile_velocity_coeff = m_Map.GetTileVelocityCoeff(current_pos);
|
|
||||||
auto next_pos = GetMoveTarget();
|
|
||||||
WorldPos velocity = WorldPos{};
|
|
||||||
if (next_pos) {
|
|
||||||
velocity = next_pos.value() - current_pos;
|
|
||||||
velocity.normalize();
|
|
||||||
LOG_DEBUG("I want to move to: ", next_pos.value(),
|
|
||||||
", velocity: ", velocity);
|
|
||||||
}
|
|
||||||
player->SetActualVelocity(velocity * tile_velocity_coeff);
|
|
||||||
float time_delta = 1.0f;
|
|
||||||
player->Update(time_delta);
|
|
||||||
}
|
|
||||||
|
|
||||||
void PathFindingDemo::HandleActions(const std::vector<UserAction> &actions) {
|
|
||||||
for (const auto &action : actions) {
|
|
||||||
if (action.type == UserAction::Type::EXIT) {
|
|
||||||
LOG_INFO("Exit requested");
|
|
||||||
m_ExitRequested = true;
|
|
||||||
} else if (action.type == UserAction::Type::SET_MOVE_TARGET) {
|
|
||||||
WorldPos wp = action.Argument.position;
|
|
||||||
LOG_INFO("Calculating path to target: ", wp);
|
|
||||||
m_Path = m_PathFinder->CalculatePath(m_Player->GetPosition(), wp);
|
|
||||||
LOG_INFO("Done, path node count: ", m_Path.size());
|
|
||||||
} else if (action.type == UserAction::Type::SELECT_PATHFINDER) {
|
|
||||||
using namespace pathfinder;
|
|
||||||
PathFinderType type = static_cast<PathFinderType>(action.Argument.number);
|
|
||||||
m_PathFinder = pathfinder::create(type, (const Map*)&m_Map);
|
|
||||||
LOG_INFO("Switched to path finding method: ", m_PathFinder->GetName());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
#include <optional>
|
|
||||||
#include <queue>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "entities.hpp"
|
|
||||||
#include "log.hpp"
|
|
||||||
#include "map.hpp"
|
|
||||||
#include "user_input.hpp"
|
|
||||||
#include "pathfinder.hpp"
|
|
||||||
|
|
||||||
class PathFindingDemo {
|
|
||||||
public:
|
|
||||||
PathFindingDemo(int width, int height);
|
|
||||||
~PathFindingDemo();
|
|
||||||
|
|
||||||
PathFindingDemo(const PathFindingDemo &m) = delete;
|
|
||||||
PathFindingDemo(PathFindingDemo &&m) = delete;
|
|
||||||
PathFindingDemo &operator=(const PathFindingDemo &) = delete;
|
|
||||||
PathFindingDemo &operator=(PathFindingDemo &&) = delete;
|
|
||||||
|
|
||||||
std::shared_ptr<Player> GetPlayer() { return m_Player; }
|
|
||||||
std::vector<std::shared_ptr<Entity>>& GetEntities() { return m_Entities; }
|
|
||||||
const Map& GetMap() const { return m_Map; }
|
|
||||||
const pathfinder::Path& GetPath() const { return m_Path; }
|
|
||||||
bool IsExitRequested() const { return m_ExitRequested; }
|
|
||||||
|
|
||||||
void AddEntity(std::shared_ptr<Entity> e);
|
|
||||||
void CreateMap();
|
|
||||||
std::optional<WorldPos> GetMoveTarget();
|
|
||||||
void UpdatePlayerVelocity();
|
|
||||||
void HandleActions(const std::vector<UserAction> &actions);
|
|
||||||
WorldPos GetRandomPosition() const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
bool m_ExitRequested = false;
|
|
||||||
Map m_Map;
|
|
||||||
std::vector<std::shared_ptr<Entity>> m_Entities;
|
|
||||||
std::shared_ptr<Player> m_Player;
|
|
||||||
pathfinder::Path m_Path;
|
|
||||||
std::unique_ptr<pathfinder::PathFinderBase> m_PathFinder;
|
|
||||||
};
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
#include "sprite.hpp"
|
|
||||||
|
|
||||||
#include <SDL3/SDL.h>
|
|
||||||
#include <SDL3_image/SDL_image.h>
|
|
||||||
#include <cassert>
|
|
||||||
#include <memory>
|
|
||||||
#include <stdexcept>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include "log.hpp"
|
|
||||||
#include "math.hpp"
|
|
||||||
|
|
||||||
Sprite::Sprite() : m_Texture(nullptr, SDL_DestroyTexture) {}
|
|
||||||
|
|
||||||
Sprite::Sprite(std::string path, Vec2D<float> center) : Sprite() {
|
|
||||||
LoadImage(path, center);
|
|
||||||
}
|
|
||||||
|
|
||||||
Sprite::~Sprite() { LOG_DEBUG("."); }
|
|
||||||
|
|
||||||
void Sprite::LoadImage(std::string path, Vec2D<float> image_center) {
|
|
||||||
LOG_INFO("Loading image ", path);
|
|
||||||
assert(m_Renderer != nullptr);
|
|
||||||
|
|
||||||
auto surface = std::unique_ptr<SDL_Surface, decltype(&SDL_DestroySurface)>(
|
|
||||||
IMG_Load(path.c_str()), SDL_DestroySurface);
|
|
||||||
|
|
||||||
if (surface == nullptr) {
|
|
||||||
LOG_ERROR("IMG_Load failed to load ", path);
|
|
||||||
throw std::runtime_error("Failed to load resources");
|
|
||||||
}
|
|
||||||
|
|
||||||
m_Texture = std::unique_ptr<SDL_Texture, decltype(&SDL_DestroyTexture)>(
|
|
||||||
SDL_CreateTextureFromSurface(m_Renderer.get(), surface.get()),
|
|
||||||
SDL_DestroyTexture);
|
|
||||||
if (m_Texture == nullptr) {
|
|
||||||
LOG_ERROR("SDL_CreateTextureFromSurface failed");
|
|
||||||
throw std::runtime_error("Failed to load resources");
|
|
||||||
}
|
|
||||||
float w, h;
|
|
||||||
SDL_GetTextureSize(m_Texture.get(), &w, &h);
|
|
||||||
m_Size = {w, h};
|
|
||||||
m_ImageCenter = image_center;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Renderer is shared for all class instances - we need it in order
|
|
||||||
// to create textures from images
|
|
||||||
void Sprite::SetRenderer(std::shared_ptr<SDL_Renderer> renderer) {
|
|
||||||
m_Renderer = renderer;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<SDL_Renderer> Sprite::m_Renderer = nullptr;
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <SDL3/SDL.h>
|
|
||||||
#include <SDL3_image/SDL_image.h>
|
|
||||||
#include <cassert>
|
|
||||||
#include <memory>
|
|
||||||
#include <stdexcept>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include "log.hpp"
|
|
||||||
#include "math.hpp"
|
|
||||||
|
|
||||||
class Sprite {
|
|
||||||
public:
|
|
||||||
Sprite();
|
|
||||||
~Sprite();
|
|
||||||
explicit Sprite(std::string path, WorldPos center = {0, 0});
|
|
||||||
|
|
||||||
Sprite(const Sprite &) = delete;
|
|
||||||
Sprite &operator=(const Sprite &) = delete;
|
|
||||||
Sprite(Sprite &&) = delete;
|
|
||||||
Sprite &operator=(Sprite &&) = delete;
|
|
||||||
|
|
||||||
static void SetRenderer(std::shared_ptr<SDL_Renderer> renderer);
|
|
||||||
|
|
||||||
// GetTexture cannot return pointer to const, as SDL_RenderTexture modifies it
|
|
||||||
SDL_Texture *GetTexture() { return m_Texture.get(); }
|
|
||||||
WorldPos GetSize() const { return m_Size; }
|
|
||||||
WorldPos GetCenter() const { return m_ImageCenter; }
|
|
||||||
|
|
||||||
void LoadImage(std::string path, WorldPos image_center = {0.0, 0.0});
|
|
||||||
|
|
||||||
private:
|
|
||||||
static std::shared_ptr<SDL_Renderer> m_Renderer;
|
|
||||||
std::unique_ptr<SDL_Texture, decltype(&SDL_DestroyTexture)> m_Texture;
|
|
||||||
WorldPos m_Size;
|
|
||||||
WorldPos m_ImageCenter;
|
|
||||||
float m_TextureWidth = 0;
|
|
||||||
float m_TextureHeight = 0;
|
|
||||||
};
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
#include "tile.hpp"
|
|
||||||
|
|
||||||
const std::map<std::string_view, Tile> tile_types = {
|
|
||||||
{"Grass", {1.0, 0, 200, 0, 255}},
|
|
||||||
{"Mud", {2.0, 100, 100, 100, 255}},
|
|
||||||
{"Road", {0.5, 200, 200, 200, 255}},
|
|
||||||
{"Water", {10.0, 0, 50, 200, 255}},
|
|
||||||
};
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <cstdint>
|
|
||||||
#include <map>
|
|
||||||
#include <string_view>
|
|
||||||
|
|
||||||
struct Tile {
|
|
||||||
float cost;
|
|
||||||
uint8_t R, G, B, A;
|
|
||||||
};
|
|
||||||
|
|
||||||
extern const std::map<std::string_view, Tile> tile_types;
|
|
||||||
@@ -1,68 +0,0 @@
|
|||||||
#include <SDL3/SDL.h>
|
|
||||||
#include <expected>
|
|
||||||
#include <map>
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "user_input.hpp"
|
|
||||||
|
|
||||||
#include "log.hpp"
|
|
||||||
#include "math.hpp"
|
|
||||||
|
|
||||||
UserInput::UserInput()
|
|
||||||
: // pre-alloc some space
|
|
||||||
m_Actions(10) {
|
|
||||||
LOG_DEBUG(".");
|
|
||||||
};
|
|
||||||
|
|
||||||
UserInput::~UserInput() { LOG_DEBUG("."); };
|
|
||||||
|
|
||||||
std::expected<void, std::string> UserInput::Init() { return {}; }
|
|
||||||
|
|
||||||
const std::vector<UserAction> &UserInput::GetActions() {
|
|
||||||
m_Actions.clear();
|
|
||||||
static WorldPos move_direction = {0.0f, 0.0f};
|
|
||||||
SDL_Event event;
|
|
||||||
|
|
||||||
while (SDL_PollEvent(&event)) {
|
|
||||||
if (event.type == SDL_EVENT_KEY_DOWN || event.type == SDL_EVENT_KEY_UP) {
|
|
||||||
bool key_down = event.type == SDL_EVENT_KEY_DOWN ? true : false;
|
|
||||||
SDL_KeyboardEvent kbd_event = event.key;
|
|
||||||
if (kbd_event.repeat) {
|
|
||||||
// SDL repeats KEY_DOWN if key is held down, we ignore that
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
LOG_DEBUG("Key '", static_cast<char>(kbd_event.key),
|
|
||||||
key_down ? "' down" : "' up");
|
|
||||||
|
|
||||||
switch (kbd_event.key) {
|
|
||||||
case 'q':
|
|
||||||
m_Actions.emplace_back(UserAction::Type::EXIT);
|
|
||||||
// further processing of inputs is not needed
|
|
||||||
return m_Actions;
|
|
||||||
case '1':
|
|
||||||
case '2':
|
|
||||||
case '3':
|
|
||||||
case '4':
|
|
||||||
if (key_down) {
|
|
||||||
int selection = kbd_event.key - '0';
|
|
||||||
m_Actions.emplace_back(UserAction::Type::SELECT_PATHFINDER, selection);
|
|
||||||
LOG_INFO("Pathfinder selected: ", selection);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
LOG_INFO("Key '", static_cast<char>(kbd_event.key), "' not mapped");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else if (event.type == SDL_EVENT_MOUSE_BUTTON_DOWN) {
|
|
||||||
SDL_MouseButtonEvent mouse_event = event.button;
|
|
||||||
LOG_DEBUG("Mouse down: ", mouse_event.x, ", ", mouse_event.y);
|
|
||||||
m_Actions.emplace_back(UserAction::Type::SET_MOVE_TARGET,
|
|
||||||
WorldPos{mouse_event.x, mouse_event.y});
|
|
||||||
} else {
|
|
||||||
// TODO uncomment, for now too much noise
|
|
||||||
// LOG_WARNING("Action not processed");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return m_Actions;
|
|
||||||
}
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <expected>
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "log.hpp"
|
|
||||||
#include "math.hpp"
|
|
||||||
|
|
||||||
class UserAction {
|
|
||||||
public:
|
|
||||||
enum class Type { NONE, EXIT, SET_MOVE_TARGET, SELECT_PATHFINDER };
|
|
||||||
|
|
||||||
UserAction() = default;
|
|
||||||
UserAction(Type t) : type(t) {}
|
|
||||||
UserAction(Type t, char key) : type(t), Argument{.key = key} {}
|
|
||||||
UserAction(Type t, WorldPos v) : type(t), Argument{.position = v} {}
|
|
||||||
UserAction(Type t, int arg) : type(t), Argument{.number = arg} {}
|
|
||||||
~UserAction() = default;
|
|
||||||
|
|
||||||
Type type;
|
|
||||||
|
|
||||||
union {
|
|
||||||
WorldPos position;
|
|
||||||
char key;
|
|
||||||
int number;
|
|
||||||
} Argument;
|
|
||||||
};
|
|
||||||
|
|
||||||
class UserInput {
|
|
||||||
public:
|
|
||||||
UserInput();
|
|
||||||
~UserInput();
|
|
||||||
|
|
||||||
UserInput(const UserInput &x) = delete;
|
|
||||||
UserInput(UserInput &&x) = delete;
|
|
||||||
UserInput &operator=(const UserInput &) = delete;
|
|
||||||
UserInput &operator=(UserInput &&) = delete;
|
|
||||||
|
|
||||||
std::expected<void, std::string> Init();
|
|
||||||
|
|
||||||
const std::vector<UserAction> &GetActions();
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::vector<UserAction> m_Actions;
|
|
||||||
};
|
|
||||||
@@ -1,118 +0,0 @@
|
|||||||
#include <GL/glew.h>
|
|
||||||
#include <SDL3/SDL.h>
|
|
||||||
#include <SDL3/SDL_opengl.h>
|
|
||||||
#include <cmath>
|
|
||||||
#include <cstdlib>
|
|
||||||
#include <expected>
|
|
||||||
#include <memory>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include "window.hpp"
|
|
||||||
|
|
||||||
#include "log.hpp"
|
|
||||||
#include "math.hpp"
|
|
||||||
#include "sprite.hpp"
|
|
||||||
|
|
||||||
Window::Window(int width, int height) : m_Width(width), m_Height(height) {
|
|
||||||
LOG_DEBUG(".");
|
|
||||||
}
|
|
||||||
|
|
||||||
std::expected<void, std::string> Window::Init() {
|
|
||||||
LOG_DEBUG(".");
|
|
||||||
|
|
||||||
if (SDL_Init(SDL_INIT_VIDEO) == false) {
|
|
||||||
return std::unexpected(std::string("SDL could not initialize! Error: ") +
|
|
||||||
SDL_GetError());
|
|
||||||
}
|
|
||||||
m_Window = SDL_CreateWindow("SDL2 Window", m_Width, m_Height,
|
|
||||||
SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
|
|
||||||
if (m_Window == nullptr) {
|
|
||||||
std::atexit(SDL_Quit);
|
|
||||||
return std::unexpected(std::string("Window could not be created! Error: ") +
|
|
||||||
SDL_GetError());
|
|
||||||
}
|
|
||||||
|
|
||||||
m_Context = SDL_GL_CreateContext(m_Window);
|
|
||||||
if (m_Context == nullptr) {
|
|
||||||
SDL_DestroyWindow(m_Window);
|
|
||||||
std::atexit(SDL_Quit);
|
|
||||||
return std::unexpected(
|
|
||||||
std::string("GL context could not be created! Error: ") +
|
|
||||||
SDL_GetError());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (glewInit() != GLEW_OK) {
|
|
||||||
SDL_GL_DestroyContext(m_Context);
|
|
||||||
SDL_DestroyWindow(m_Window);
|
|
||||||
std::atexit(SDL_Quit);
|
|
||||||
return std::unexpected("GLEW init failed!");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Resize();
|
|
||||||
|
|
||||||
m_Renderer = std::shared_ptr<SDL_Renderer>(SDL_CreateRenderer(m_Window, NULL),
|
|
||||||
SDL_DestroyRenderer);
|
|
||||||
if (m_Renderer == nullptr) {
|
|
||||||
SDL_DestroyWindow(m_Window);
|
|
||||||
std::atexit(SDL_Quit);
|
|
||||||
return std::unexpected(
|
|
||||||
std::string("Renderer could not be created! Error: ") + SDL_GetError());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set renderer to the Sprite class
|
|
||||||
Sprite::SetRenderer(m_Renderer);
|
|
||||||
|
|
||||||
// TODO this needs to be tied to map size
|
|
||||||
SDL_SetRenderScale(m_Renderer.get(), 1.0f, 1.0f);
|
|
||||||
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
Window::~Window() {
|
|
||||||
// SDL_DestroyRenderer(m_Renderer); // handled by shared_ptr
|
|
||||||
SDL_GL_DestroyContext(m_Context);
|
|
||||||
SDL_DestroyWindow(m_Window);
|
|
||||||
std::atexit(SDL_Quit);
|
|
||||||
LOG_DEBUG(".");
|
|
||||||
}
|
|
||||||
|
|
||||||
void Window::DrawSprite(const WorldPos &position, Sprite &s) {
|
|
||||||
WorldPos size = s.GetSize();
|
|
||||||
WorldPos img_center = s.GetCenter();
|
|
||||||
SDL_FRect rect = {position.x - img_center.x, position.y - img_center.y,
|
|
||||||
size.x, size.y};
|
|
||||||
SDL_RenderTexture(m_Renderer.get(), s.GetTexture(), nullptr, &rect);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Window::DrawRect(const WorldPos &position, const WorldPos size, uint8_t R,
|
|
||||||
uint8_t G, uint8_t B, uint8_t A) {
|
|
||||||
SDL_FRect rect = {position.x, position.y, size.x, size.y};
|
|
||||||
SDL_SetRenderDrawColor(m_Renderer.get(), R, G, B, A);
|
|
||||||
SDL_RenderFillRect(m_Renderer.get(), &rect);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Window::ClearWindow() {
|
|
||||||
SDL_SetRenderDrawColor(m_Renderer.get(), 50, 50, 50, 255);
|
|
||||||
SDL_RenderClear(m_Renderer.get());
|
|
||||||
}
|
|
||||||
|
|
||||||
void Window::Flush() { SDL_RenderPresent(m_Renderer.get()); }
|
|
||||||
|
|
||||||
void Window::DrawCircle(const WorldPos &position, float radius) {
|
|
||||||
int cx = static_cast<int>(position.x);
|
|
||||||
int cy = static_cast<int>(position.y);
|
|
||||||
SDL_SetRenderDrawColor(m_Renderer.get(), 255, 0, 0, 255);
|
|
||||||
for (int i = 0; i < 360; ++i) {
|
|
||||||
double a = i * M_PI / 180.0;
|
|
||||||
SDL_RenderPoint(m_Renderer.get(),
|
|
||||||
cx + static_cast<int>(std::round(radius * std::cos(a))),
|
|
||||||
cy + static_cast<int>(std::round(radius * std::sin(a))));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Window::DrawLine(const WorldPos &A, const WorldPos &B)
|
|
||||||
{
|
|
||||||
SDL_SetRenderDrawColor(m_Renderer.get(), 255, 0, 0, 255);
|
|
||||||
SDL_RenderLine(m_Renderer.get(), A.x, A.y, B.x, B.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <GL/glew.h>
|
|
||||||
#include <SDL3/SDL.h>
|
|
||||||
#include <SDL3/SDL_opengl.h>
|
|
||||||
#include <cmath>
|
|
||||||
#include <expected>
|
|
||||||
#include <memory>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include "math.hpp"
|
|
||||||
#include "sprite.hpp"
|
|
||||||
|
|
||||||
class Window {
|
|
||||||
public:
|
|
||||||
Window(int width, int height);
|
|
||||||
~Window();
|
|
||||||
|
|
||||||
Window(const Window &x) = delete;
|
|
||||||
Window(Window &&x) = delete;
|
|
||||||
Window &operator=(const Window &) = delete;
|
|
||||||
Window &operator=(Window &&) = delete;
|
|
||||||
|
|
||||||
std::expected<void, std::string> Init();
|
|
||||||
void DrawSprite(const WorldPos &position, Sprite &s);
|
|
||||||
void DrawRect(const WorldPos &position, const WorldPos size, uint8_t R,
|
|
||||||
uint8_t G, uint8_t B, uint8_t A);
|
|
||||||
void ClearWindow();
|
|
||||||
void Flush();
|
|
||||||
void DrawCircle(const WorldPos &position, float radius);
|
|
||||||
void DrawLine(const WorldPos &A, const WorldPos &B);
|
|
||||||
|
|
||||||
std::shared_ptr<SDL_Renderer> m_Renderer = nullptr;
|
|
||||||
SDL_Window *m_Window;
|
|
||||||
SDL_GLContext m_Context;
|
|
||||||
|
|
||||||
private:
|
|
||||||
uint32_t m_Width;
|
|
||||||
uint32_t m_Height;
|
|
||||||
};
|
|
||||||
1
vs/SDL
Submodule
1
vs/SDL
Submodule
Submodule vs/SDL added at 3e9e22f17d
1
vs/SDL_image
Submodule
1
vs/SDL_image
Submodule
Submodule vs/SDL_image added at eeae8a64df
1
vs/glew
Submodule
1
vs/glew
Submodule
Submodule vs/glew added at 02505d6cc1
61
vs/pathfinding_demo/pathfinding_demo.sln
Normal file
61
vs/pathfinding_demo/pathfinding_demo.sln
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 17
|
||||||
|
VisualStudioVersion = 17.9.34622.214
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pathfinding_demo", "pathfinding_demo.vcxproj", "{E14D159C-08E1-46E4-BD63-6157EDBC70DC}"
|
||||||
|
EndProject
|
||||||
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SDL3", "..\SDL\VisualC\SDL\SDL.vcxproj", "{81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}"
|
||||||
|
EndProject
|
||||||
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "glew_static", "..\glew\build\vc15\glew_static.vcxproj", "{664E6F0D-6784-4760-9565-D54F8EB1EDF4}"
|
||||||
|
EndProject
|
||||||
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SDL3_image", "..\SDL_image\VisualC\SDL_image.vcxproj", "{2BD5534E-00E2-4BEA-AC96-D9A92EA24696}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|x64 = Debug|x64
|
||||||
|
Debug|x86 = Debug|x86
|
||||||
|
Release|x64 = Release|x64
|
||||||
|
Release|x86 = Release|x86
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{E14D159C-08E1-46E4-BD63-6157EDBC70DC}.Debug|x64.ActiveCfg = Debug|x64
|
||||||
|
{E14D159C-08E1-46E4-BD63-6157EDBC70DC}.Debug|x64.Build.0 = Debug|x64
|
||||||
|
{E14D159C-08E1-46E4-BD63-6157EDBC70DC}.Debug|x86.ActiveCfg = Debug|Win32
|
||||||
|
{E14D159C-08E1-46E4-BD63-6157EDBC70DC}.Debug|x86.Build.0 = Debug|Win32
|
||||||
|
{E14D159C-08E1-46E4-BD63-6157EDBC70DC}.Release|x64.ActiveCfg = Release|x64
|
||||||
|
{E14D159C-08E1-46E4-BD63-6157EDBC70DC}.Release|x64.Build.0 = Release|x64
|
||||||
|
{E14D159C-08E1-46E4-BD63-6157EDBC70DC}.Release|x86.ActiveCfg = Release|Win32
|
||||||
|
{E14D159C-08E1-46E4-BD63-6157EDBC70DC}.Release|x86.Build.0 = Release|Win32
|
||||||
|
{81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}.Debug|x64.ActiveCfg = Debug|x64
|
||||||
|
{81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}.Debug|x64.Build.0 = Debug|x64
|
||||||
|
{81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}.Debug|x86.ActiveCfg = Debug|Win32
|
||||||
|
{81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}.Debug|x86.Build.0 = Debug|Win32
|
||||||
|
{81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}.Release|x64.ActiveCfg = Release|x64
|
||||||
|
{81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}.Release|x64.Build.0 = Release|x64
|
||||||
|
{81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}.Release|x86.ActiveCfg = Release|Win32
|
||||||
|
{81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}.Release|x86.Build.0 = Release|Win32
|
||||||
|
{664E6F0D-6784-4760-9565-D54F8EB1EDF4}.Debug|x64.ActiveCfg = Debug|x64
|
||||||
|
{664E6F0D-6784-4760-9565-D54F8EB1EDF4}.Debug|x64.Build.0 = Debug|x64
|
||||||
|
{664E6F0D-6784-4760-9565-D54F8EB1EDF4}.Debug|x86.ActiveCfg = Debug|Win32
|
||||||
|
{664E6F0D-6784-4760-9565-D54F8EB1EDF4}.Debug|x86.Build.0 = Debug|Win32
|
||||||
|
{664E6F0D-6784-4760-9565-D54F8EB1EDF4}.Release|x64.ActiveCfg = Release|x64
|
||||||
|
{664E6F0D-6784-4760-9565-D54F8EB1EDF4}.Release|x64.Build.0 = Release|x64
|
||||||
|
{664E6F0D-6784-4760-9565-D54F8EB1EDF4}.Release|x86.ActiveCfg = Release|Win32
|
||||||
|
{664E6F0D-6784-4760-9565-D54F8EB1EDF4}.Release|x86.Build.0 = Release|Win32
|
||||||
|
{2BD5534E-00E2-4BEA-AC96-D9A92EA24696}.Debug|x64.ActiveCfg = Debug|x64
|
||||||
|
{2BD5534E-00E2-4BEA-AC96-D9A92EA24696}.Debug|x64.Build.0 = Debug|x64
|
||||||
|
{2BD5534E-00E2-4BEA-AC96-D9A92EA24696}.Debug|x86.ActiveCfg = Debug|Win32
|
||||||
|
{2BD5534E-00E2-4BEA-AC96-D9A92EA24696}.Debug|x86.Build.0 = Debug|Win32
|
||||||
|
{2BD5534E-00E2-4BEA-AC96-D9A92EA24696}.Release|x64.ActiveCfg = Release|x64
|
||||||
|
{2BD5534E-00E2-4BEA-AC96-D9A92EA24696}.Release|x64.Build.0 = Release|x64
|
||||||
|
{2BD5534E-00E2-4BEA-AC96-D9A92EA24696}.Release|x86.ActiveCfg = Release|Win32
|
||||||
|
{2BD5534E-00E2-4BEA-AC96-D9A92EA24696}.Release|x86.Build.0 = Release|Win32
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {7CCA451E-D4BA-48B4-AAD0-8AC02333FD9D}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
167
vs/pathfinding_demo/pathfinding_demo.vcxproj
Normal file
167
vs/pathfinding_demo/pathfinding_demo.vcxproj
Normal file
@@ -0,0 +1,167 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<ItemGroup Label="ProjectConfigurations">
|
||||||
|
<ProjectConfiguration Include="Debug|Win32">
|
||||||
|
<Configuration>Debug</Configuration>
|
||||||
|
<Platform>Win32</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Release|Win32">
|
||||||
|
<Configuration>Release</Configuration>
|
||||||
|
<Platform>Win32</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Debug|x64">
|
||||||
|
<Configuration>Debug</Configuration>
|
||||||
|
<Platform>x64</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Release|x64">
|
||||||
|
<Configuration>Release</Configuration>
|
||||||
|
<Platform>x64</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClCompile Include="..\..\cpp\src\main.cpp" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClInclude Include="..\..\cpp\src\array.hpp" />
|
||||||
|
<ClInclude Include="..\..\cpp\src\log.hpp" />
|
||||||
|
<ClInclude Include="..\..\cpp\src\math.hpp" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\glew\build\vc15\glew_static.vcxproj">
|
||||||
|
<Project>{664e6f0d-6784-4760-9565-d54f8eb1edf4}</Project>
|
||||||
|
</ProjectReference>
|
||||||
|
<ProjectReference Include="..\SDL\VisualC\SDL\SDL.vcxproj">
|
||||||
|
<Project>{81ce8daf-ebb2-4761-8e45-b71abcca8c68}</Project>
|
||||||
|
</ProjectReference>
|
||||||
|
<ProjectReference Include="..\SDL_image\VisualC\SDL_image.vcxproj">
|
||||||
|
<Project>{2bd5534e-00e2-4bea-ac96-d9a92ea24696}</Project>
|
||||||
|
</ProjectReference>
|
||||||
|
</ItemGroup>
|
||||||
|
<PropertyGroup Label="Globals">
|
||||||
|
<VCProjectVersion>17.0</VCProjectVersion>
|
||||||
|
<Keyword>Win32Proj</Keyword>
|
||||||
|
<ProjectGuid>{e14d159c-08e1-46e4-bd63-6157edbc70dc}</ProjectGuid>
|
||||||
|
<RootNamespace>pathfindingdemo</RootNamespace>
|
||||||
|
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||||
|
<ImportGroup Label="ExtensionSettings">
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="Shared">
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<PropertyGroup Label="UserMacros" />
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<PreprocessorDefinitions>GLEW_STATIC</PreprocessorDefinitions>
|
||||||
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
<LanguageStandard>stdcpplatest</LanguageStandard>
|
||||||
|
<AdditionalIncludeDirectories>..\glew\include;..\SDL\include;..\SDL_image\include;..\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
<AdditionalLibraryDirectories>..\glew\lib\Debug\x64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||||
|
<AdditionalDependencies>opengl32.lib;glu32.lib;glew32sd.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<PreprocessorDefinitions>GLEW_STATIC</PreprocessorDefinitions>
|
||||||
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
<LanguageStandard>stdcpplatest</LanguageStandard>
|
||||||
|
<AdditionalIncludeDirectories>..\glew\include;..\SDL\include;..\SDL_image\include;..\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
<AdditionalLibraryDirectories>..\glew\lib\Debug\x64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||||
|
<AdditionalDependencies>opengl32.lib;glu32.lib;glew32sd.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<PreprocessorDefinitions>GLEW_STATIC</PreprocessorDefinitions>
|
||||||
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
<LanguageStandard>stdcpplatest</LanguageStandard>
|
||||||
|
<AdditionalIncludeDirectories>..\glew\include;..\SDL\include;..\SDL_image\include;..\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
<AdditionalLibraryDirectories>..\glew\lib\Debug\x64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||||
|
<AdditionalDependencies>opengl32.lib;glu32.lib;glew32sd.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<PreprocessorDefinitions>GLEW_STATIC</PreprocessorDefinitions>
|
||||||
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
<LanguageStandard>stdcpplatest</LanguageStandard>
|
||||||
|
<AdditionalIncludeDirectories>..\glew\include;..\SDL\include;..\SDL_image\include;..\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
<AdditionalLibraryDirectories>..\glew\lib\Debug\x64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||||
|
<AdditionalDependencies>opengl32.lib;glu32.lib;glew32sd.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
|
<ImportGroup Label="ExtensionTargets">
|
||||||
|
</ImportGroup>
|
||||||
|
</Project>
|
||||||
33
vs/pathfinding_demo/pathfinding_demo.vcxproj.filters
Normal file
33
vs/pathfinding_demo/pathfinding_demo.vcxproj.filters
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<ItemGroup>
|
||||||
|
<Filter Include="Source Files">
|
||||||
|
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||||
|
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||||
|
</Filter>
|
||||||
|
<Filter Include="Header Files">
|
||||||
|
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||||
|
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
|
||||||
|
</Filter>
|
||||||
|
<Filter Include="Resource Files">
|
||||||
|
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||||
|
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||||
|
</Filter>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClCompile Include="..\..\cpp\src\main.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClInclude Include="..\..\cpp\src\array.hpp">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\cpp\src\log.hpp">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\cpp\src\math.hpp">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
||||||
19
vs/pathfinding_demo/pathfinding_demo.vcxproj.user
Normal file
19
vs/pathfinding_demo/pathfinding_demo.vcxproj.user
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<LocalDebuggerWorkingDirectory>$(ProjectDir)\..\..\cpp</LocalDebuggerWorkingDirectory>
|
||||||
|
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<LocalDebuggerWorkingDirectory>$(ProjectDir)\..\..\cpp</LocalDebuggerWorkingDirectory>
|
||||||
|
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<LocalDebuggerWorkingDirectory>$(ProjectDir)\..\..\cpp</LocalDebuggerWorkingDirectory>
|
||||||
|
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<LocalDebuggerWorkingDirectory>$(ProjectDir)\..\..\cpp</LocalDebuggerWorkingDirectory>
|
||||||
|
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
||||||
|
</PropertyGroup>
|
||||||
|
</Project>
|
||||||
Reference in New Issue
Block a user