diff --git a/.gitattributes b/.gitattributes index 1fe8bae..e69de29 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +0,0 @@ -*.bmp filter=lfs diff=lfs merge=lfs -text diff --git a/.gitignore b/.gitignore index 4e2a22e..7744b04 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,11 @@ [Dd]ebug [Rr]elease +# CLion idea +.idea +cmake-build-debug +cmake-build-release + # CMake CMakeCache.txt CMakeFiles diff --git a/CMakeLists.txt b/CMakeLists.txt index c9d0491..13a323c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,14 +1,17 @@ cmake_minimum_required(VERSION 2.8.9) set(CMAKE_DISABLE_SOURCE_CHANGES ON) set(CMAKE_DISABLE_IN_SOURCE_BUILD ON) +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/") + +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libgcc -static-libstdc++") project(dungeon) -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${dungeon_SOURCE_DIR}/cmake") - +find_package(OpenGL REQUIRED) find_package(SDL2 REQUIRED) -include_directories(${SDL2_INCLUDE_DIR} "libs/glm") -link_libraries(${SDL2_LIBRARY}) +include_directories(${OPENGL_INCLUDE_DIR} ${SDL2_INCLUDE_DIR} "libs/glm") +link_libraries(${OPENGL_LIBRARIES} ${SDL2_LIBRARY}) file(GLOB SOURCES "src/*.cpp" "src/*.c" "src/*.h") add_executable(dungeon ${SOURCES}) diff --git a/src/AttackEnemyNode.cpp b/src/AttackEnemyNode.cpp index 382e91a..622a8e8 100644 --- a/src/AttackEnemyNode.cpp +++ b/src/AttackEnemyNode.cpp @@ -14,7 +14,7 @@ BehaviourTreeStatus AttackEnemyNode::tick(BTTick * tick) { auto actors = tick->target->map->GetActorList(); std::vector visibleEnemies; - for each (auto actor in *actors) { + for (auto actor : *actors) { if (actor == tick->target) continue; if (actor->isTypeOf(ACT_HERO) != ishero) { @@ -31,7 +31,7 @@ BehaviourTreeStatus AttackEnemyNode::tick(BTTick * tick) { Actor* closestActor = nullptr; float closestDist; - for each (Actor* actor in visibleEnemies) { + for (Actor* actor : visibleEnemies) { float dist = Pathfinder::distance(tick->target->getPosition(), actor->getPosition()); if (closestActor == nullptr || dist < closestDist) { diff --git a/src/BehaviourTreeNode.cpp b/src/BehaviourTreeNode.cpp index 6dbc348..bab319e 100644 --- a/src/BehaviourTreeNode.cpp +++ b/src/BehaviourTreeNode.cpp @@ -10,7 +10,7 @@ BehaviourTreeNode::BehaviourTreeNode(BehaviourTreeNode* parent) { } BehaviourTreeNode::~BehaviourTreeNode() { - for each (BehaviourTreeNode* child in children) { + for (BehaviourTreeNode* child : children) { delete child; } } diff --git a/src/Config.cpp b/src/Config.cpp index e08f07e..08506b4 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -44,7 +44,7 @@ static inline void trim(string &s) { -Config::Config(char* path) { +Config::Config(string path) { this->path = path; } @@ -99,13 +99,13 @@ void Config::save() { ofstream conf(path, ios::trunc); if (conf.is_open()) { vector vec; - for each (auto it in ints) { + for (auto it : ints) { vec.push_back(it.first + " = " + to_string(it.second)); } - for each (auto it in floats) { + for (auto it : floats) { vec.push_back(it.first + " = " + to_string(it.second)); } - for each (auto it in bools) { + for (auto it : bools) { string b; if (it.second) { b = "true"; @@ -115,11 +115,11 @@ void Config::save() { } vec.push_back(it.first + " = " + b); } - for each (auto it in strings) { + for (auto it : strings) { vec.push_back(it.first + " = " + it.second); } sort(vec.begin(), vec.end()); - for each (auto it in vec) { + for (auto it : vec) { conf << it << "\n"; } conf.close(); diff --git a/src/Config.h b/src/Config.h index 0b94b9f..a69739d 100644 --- a/src/Config.h +++ b/src/Config.h @@ -3,13 +3,13 @@ #include class Config { - char* path; + std::string path; std::map strings; std::map floats; std::map ints; std::map bools; public: - Config(char* path); + Config(std::string path); void load(); void save(); void deleteValue(std::string key); diff --git a/src/ExploreNode.cpp b/src/ExploreNode.cpp index 78c2066..a4e56a7 100644 --- a/src/ExploreNode.cpp +++ b/src/ExploreNode.cpp @@ -1,3 +1,4 @@ +#include #include "ExploreNode.h" #include "Pathfinder.h" #include "BehaviourTree.h" @@ -26,7 +27,7 @@ BehaviourTreeStatus ExploreNode::tick(BTTick * tick) { std::vector neigh = map->getNeighbours(pos.x, pos.y); std::vector options; float lowestval = 999999; - for each (vec2i npos in neigh) { + for (vec2i npos : neigh) { float val = dijkstra.getValue(npos.x, npos.y); if (val < lowestval) { lowestval = val; @@ -41,7 +42,7 @@ BehaviourTreeStatus ExploreNode::tick(BTTick * tick) { return BT_FAILED; } while (options.size() > 0) { - int i = rand() % options.size(); + int i = std::rand() % options.size(); vec2i next = options[i]; vec2i dp = next - pos; if (tick->target->Move(dp.x, dp.y)) { diff --git a/src/FieldOfVision.cpp b/src/FieldOfVision.cpp index 220be29..bf86916 100644 --- a/src/FieldOfVision.cpp +++ b/src/FieldOfVision.cpp @@ -1,3 +1,4 @@ +#include #include "FieldOfVision.h" #include "Tilemap.h" @@ -18,7 +19,7 @@ namespace FOV { void CastLight(Tilemap* map, Tilemap* vision, int visioncounter, int row, float start, float end, int xx, int xy, int yx, int yy, int startX, int startY, float radius) { float newStart = 0.0f; - if (start < end) { + if (start < end) { return; } bool blocked = false; diff --git a/src/FleeNode.cpp b/src/FleeNode.cpp index 645f4a4..fc347eb 100644 --- a/src/FleeNode.cpp +++ b/src/FleeNode.cpp @@ -1,3 +1,4 @@ +#include #include "FleeNode.h" #include "Pathfinder.h" #include "BehaviourTree.h" @@ -16,7 +17,7 @@ BehaviourTreeStatus FleeNode::tick(BTTick * tick) { std::vector enemyPos; bool ishero = tick->target->isTypeOf(ACT_HERO); auto actors = tick->target->map->GetActorList(); - for each (Actor* actor in *actors) { + for (Actor* actor : *actors) { if (actor->isTypeOf(ACT_HERO) != ishero) { vec2i pos = actor->getPosition(); if (tick->target->CanSee(pos.x, pos.y)) { @@ -48,7 +49,7 @@ BehaviourTreeStatus FleeNode::tick(BTTick * tick) { std::vector neigh = map->getNeighbours(pos.x, pos.y); std::vector options; float lowestval = 999999; - for each (vec2i npos in neigh) { + for (vec2i npos : neigh) { float val = dijkstra.getValue(npos.x, npos.y); if (val < lowestval) { lowestval = val; diff --git a/src/Game.cpp b/src/Game.cpp index 7836637..e58104c 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -140,7 +140,7 @@ void update(double dt) { timer = 0; auto actors = tilemap->GetActorList(); - for each (Actor* var in *actors) { + for (Actor* var : *actors) { var->Update(); } for (int i = (int)actors->size() - 1; i >= 0; i--) { @@ -200,7 +200,7 @@ void draw(double alpha) { } } auto actors = tilemap->GetActorList(); - for each (Actor* var in *actors) { + for (Actor* var : *actors) { vec2i pos = var->getPosition(); if (hero == nullptr || hero->CanSee(pos.x, pos.y)) { renderer->SetColor(0, 0, 0, 255); diff --git a/src/HealFriendNode.cpp b/src/HealFriendNode.cpp index a6d93e0..7b55791 100644 --- a/src/HealFriendNode.cpp +++ b/src/HealFriendNode.cpp @@ -13,7 +13,7 @@ BehaviourTreeStatus HealFriendNode::tick(BTTick * tick) { auto actors = tick->target->map->GetActorList(); std::vector friends; - for each (auto actor in *actors) { + for (auto actor : *actors) { if (actor == tick->target) continue; if (actor->isTypeOf(ACT_HERO) == ishero && actor->health < actor->maxhealth-1) { @@ -30,7 +30,7 @@ BehaviourTreeStatus HealFriendNode::tick(BTTick * tick) { Actor* lowestHpActor = nullptr; int lowestHp; - for each (Actor* actor in friends) { + for (Actor* actor : friends) { if (lowestHpActor == nullptr || actor->health < lowestHp) { lowestHpActor = actor; lowestHp = actor->health; diff --git a/src/IfNotSeeEnemyNode.cpp b/src/IfNotSeeEnemyNode.cpp index 48fb223..9665d9f 100644 --- a/src/IfNotSeeEnemyNode.cpp +++ b/src/IfNotSeeEnemyNode.cpp @@ -15,7 +15,7 @@ BehaviourTreeStatus IfNotSeeEnemyNode::tick(BTTick * tick) { bool ishero = tick->target->isTypeOf(ACT_HERO); auto actors = tick->target->map->GetActorList(); - for each (auto actor in *actors) { + for (auto actor : *actors) { if (actor == tick->target) continue; if (actor->isTypeOf(ACT_HERO) != ishero) { diff --git a/src/IfSeeEnemyNode.cpp b/src/IfSeeEnemyNode.cpp index 81f5914..1f23971 100644 --- a/src/IfSeeEnemyNode.cpp +++ b/src/IfSeeEnemyNode.cpp @@ -15,7 +15,7 @@ BehaviourTreeStatus IfSeeEnemyNode::tick(BTTick * tick) { bool ishero = tick->target->isTypeOf(ACT_HERO); auto actors = tick->target->map->GetActorList(); - for each (auto actor in *actors) { + for (auto actor : *actors) { if (actor == tick->target) continue; if (actor->isTypeOf(ACT_HERO) != ishero) { diff --git a/src/IfSeeFriendNode.cpp b/src/IfSeeFriendNode.cpp index 4fb6c25..7cdb7f0 100644 --- a/src/IfSeeFriendNode.cpp +++ b/src/IfSeeFriendNode.cpp @@ -16,7 +16,7 @@ BehaviourTreeStatus IfSeeFriendNode::tick(BTTick * tick) { bool ishero = tick->target->isTypeOf(ACT_HERO); auto actors = tick->target->map->GetActorList(); - for each (auto actor in *actors) { + for (auto actor : *actors) { if (actor == tick->target) continue; if (actor->isTypeOf(ACT_HERO) == ishero) { diff --git a/src/Main.cpp b/src/Main.cpp index 4213ef3..8fe75a8 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -1,7 +1,6 @@ //#define _ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH //#define _ITERATOR_DEBUG_LEVEL 0 -#include "Renderer.h" #include #include @@ -9,6 +8,7 @@ #include #include +#include "Renderer.h" #include "Input.h" #include "Config.h" #include "Game.h" @@ -19,6 +19,7 @@ Uint64 perfFreq; double currTime(); +#undef main int main(int argc, char* argv[]) { Renderer* renderer; Input* input; diff --git a/src/Pathfinder.cpp b/src/Pathfinder.cpp index 4e620e0..8dd0070 100644 --- a/src/Pathfinder.cpp +++ b/src/Pathfinder.cpp @@ -1,3 +1,4 @@ +#include #include "Pathfinder.h" #include "Tilemap.h" @@ -38,7 +39,7 @@ namespace Pathfinder //map->SetTile(current->pos.x, current->pos.y, TILE_CLOSED); auto neighbours = map->getNeighbours(current->pos.x, current->pos.y); - for each (auto pos in neighbours) + for (auto pos : neighbours) { if (map->GetTile(pos.x, pos.y) == '#') { @@ -64,11 +65,11 @@ namespace Pathfinder path.push_back(current->pos); current = current->from; } - for each (AStarNode* var in open) + for (AStarNode* var : open) { delete var; } - for each (AStarNode* var in closed) + for (AStarNode* var : closed) { delete var; } @@ -137,11 +138,11 @@ namespace Pathfinder } } } - for each (AStarNode* var in open) + for (AStarNode* var : open) { delete var; } - for each (AStarNode* var in closed) + for (AStarNode* var : closed) { delete var; } @@ -158,15 +159,15 @@ namespace Pathfinder } out->height = map->GetHeight(); out->width = map->GetWidth(); - for each (vec2i pos in *goals) { + for (vec2i pos : *goals) { out->setValue(pos.x, pos.y, 0); } std::vector queue; - for each (vec2i pos in *goals) { + for (vec2i pos : *goals) { auto neigh = map->getNeighbours(pos.x, pos.y); - for each (vec2i npos in neigh) { + for (vec2i npos : neigh) { int val = out->getValue(npos.x, npos.y); if (map->GetTile(npos.x, npos.y) != '#' && val > 1) { if (npos.x != 0 && npos.y != 0) { diff --git a/src/RangedAttackNode.cpp b/src/RangedAttackNode.cpp index d7e7e6f..bfe0b95 100644 --- a/src/RangedAttackNode.cpp +++ b/src/RangedAttackNode.cpp @@ -17,7 +17,7 @@ BehaviourTreeStatus RangedAttackNode::tick(BTTick * tick) { auto actors = tick->target->map->GetActorList(); std::vector enemies; - for each (auto actor in *actors) { + for (auto actor : *actors) { if (actor == tick->target) continue; if (actor->isTypeOf(ACT_HERO) != ishero) { @@ -34,7 +34,7 @@ BehaviourTreeStatus RangedAttackNode::tick(BTTick * tick) { Actor* lowestHpActor = nullptr; int lowestHp; - for each (Actor* actor in enemies) { + for (Actor* actor : enemies) { if (lowestHpActor == nullptr || actor->health < lowestHp) { lowestHpActor = actor; lowestHp = actor->health; diff --git a/src/Renderer.cpp b/src/Renderer.cpp index 8cfa6a5..0899f18 100644 --- a/src/Renderer.cpp +++ b/src/Renderer.cpp @@ -106,13 +106,13 @@ GLuint spriteVertArrayId; GLuint colorUniform; GLuint mvpUniform; -bool Renderer::Init(char* title, int width, int height) { +bool Renderer::Init(std::string title, int width, int height) { SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); - window = SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, SDL_WINDOW_OPENGL); + window = SDL_CreateWindow(title.data(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, SDL_WINDOW_OPENGL); if (window == NULL) { return false; } @@ -268,24 +268,26 @@ Texture * Renderer::LoadTexture(std::string path) { // Texture already loaded, no need to load it again return &it->second; } - return nullptr; } Sprite Renderer::CreateSprite(std::string path, int x, int y, int w, int h) { Sprite sprite; - sprite.region = {x, y, w, h}; + sprite.region.x = x; + sprite.region.y = y; + sprite.region.w = w; + sprite.region.h = h; sprite.texture = LoadTexture(path); if (sprite.texture != nullptr) { - float tw = sprite.texture->w; - float th = sprite.texture->h; + float tw = (float)sprite.texture->w; + float th = (float)sprite.texture->h; const float uvs[] = { x / tw, y / th, (x + w) / tw, y / th, x / tw, (y + h) / th, (x + w) / tw, (y + h) / th, }; - + glCreateBuffers(1, &sprite.uvBuf); glBindBuffer(GL_ARRAY_BUFFER, sprite.uvBuf); diff --git a/src/Renderer.h b/src/Renderer.h index b5a054a..16d3bd5 100644 --- a/src/Renderer.h +++ b/src/Renderer.h @@ -45,7 +45,7 @@ class Renderer public: Renderer(); ~Renderer(); - bool Init(char* title, int width, int height); + bool Init(std::string title, int width, int height); void SetColor(float r, float g, float b, float a); void SetColor(Color col); void SetTitle(const char* title); diff --git a/src/Tilemap.cpp b/src/Tilemap.cpp index de4dc0a..31e17c0 100644 --- a/src/Tilemap.cpp +++ b/src/Tilemap.cpp @@ -17,7 +17,7 @@ Tilemap::Tilemap(int width, int height) Tilemap::~Tilemap() { delete tilemap; - for each (auto var in actors) { + for (auto var : actors) { delete var; } } @@ -82,7 +82,7 @@ bool Tilemap::IsBlocked(int x, int y) if (tilemap[GetIndex(x,y)] == '#') { // TODO: Replace hardcoded tiles return true; } - for each (Actor* var in actors) { + for (Actor* var : actors) { vec2i pos = var->getPosition(); if (var->IsAlive() && pos.x == x && pos.y == y) { return true; @@ -94,7 +94,7 @@ bool Tilemap::IsBlocked(int x, int y) } void Tilemap::AddActor(Actor * actor) { - for each (Actor* var in actors) { + for (Actor* var : actors) { if (var == actor) { return; } @@ -113,7 +113,7 @@ void Tilemap::RemoveActor(Actor * actor) { Actor * Tilemap::GetActor(int x, int y, Actors type) { vec2i pos = { x,y }; - for each (Actor* act in actors) { + for (Actor* act : actors) { if (act->isTypeOf(type)) { vec2i apos = act->getPosition(); if (apos == pos) { @@ -127,8 +127,8 @@ Actor * Tilemap::GetActor(int x, int y, Actors type) { std::vector Tilemap::GetActors(int x, int y, int range, Actors type) { std::vector found; std::vector neigh = getNeighbours(x, y, range); - for each (Actor* act in actors) { - for each (vec2i pos in neigh) { + for (Actor* act : actors) { + for (vec2i pos : neigh) { if (act->isTypeOf(type)) { vec2i apos = act->getPosition(); if (apos == pos) { diff --git a/src/Tilemap.h b/src/Tilemap.h index 4cec06c..8ad18e8 100644 --- a/src/Tilemap.h +++ b/src/Tilemap.h @@ -1,11 +1,9 @@ #pragma once #include +#include "Actor.h" struct vec2i; -class Actor; -enum Actors; - class Tilemap { unsigned int* tilemap; std::vector actors; diff --git a/src/Tileset.cpp b/src/Tileset.cpp index 2a68a6f..3005489 100644 --- a/src/Tileset.cpp +++ b/src/Tileset.cpp @@ -1,7 +1,7 @@ #include "Tileset.h" #include "Renderer.h" -Tileset::Tileset(Renderer* renderer, char * imgPath, int imgWidth, int imgHeight, int tileWidth, int tileHeight) { +Tileset::Tileset(Renderer* renderer, std::string imgPath, int imgWidth, int imgHeight, int tileWidth, int tileHeight) { int tilesX = imgWidth / tileWidth; int tilesY = imgHeight / tileHeight; amount = tilesX*tilesY; diff --git a/src/Tileset.h b/src/Tileset.h index 6c52647..33e510a 100644 --- a/src/Tileset.h +++ b/src/Tileset.h @@ -1,4 +1,5 @@ #pragma once +#include class Renderer; struct Sprite; @@ -8,7 +9,7 @@ class Tileset { Sprite* sprites; int amount; public: - Tileset(Renderer* renderer, char* imgPath, int imgWidth, int imgHeight, int tileWidth, int tileHeight); + Tileset(Renderer* renderer, std::string imgPath, int imgWidth, int imgHeight, int tileWidth, int tileHeight); ~Tileset(); int GetAmount(); Sprite* GetSprite(int tileId); diff --git a/src/WanderNode.cpp b/src/WanderNode.cpp index d401415..8536fa1 100644 --- a/src/WanderNode.cpp +++ b/src/WanderNode.cpp @@ -1,3 +1,4 @@ +#include #include "WanderNode.h" #include "BehaviourTree.h" #include "Actor.h" @@ -19,7 +20,7 @@ BehaviourTreeStatus WanderNode::tick(BTTick * tick) { int i = rand() % neighbours.size(); vec2i dp = neighbours[i] - pos; bool valid = true; - for each (vec2i var in previous) { + for (vec2i var : previous) { if (var == neighbours[i]) { valid = false; break; diff --git a/src/World.cpp b/src/World.cpp index 4e59f4f..09f877e 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -1,5 +1,6 @@ #include "World.h" #include +#include World::World() { World(0); @@ -38,7 +39,7 @@ Tilemap* World::GetMap(unsigned int level) { World::~World() { seeds.clear(); - for each (Tilemap* map in maps) { + for (Tilemap* map : maps) { if (map != nullptr) { delete map; } diff --git a/src/eglew.h b/src/eglew.h index 4f8f550..44e8391 100644 --- a/src/eglew.h +++ b/src/eglew.h @@ -106,6 +106,7 @@ #include #include +#define GLEW_STATIC #include "glew.h" #ifdef __cplusplus diff --git a/src/glew.c b/src/glew.c index ebb17fe..ae29f30 100644 --- a/src/glew.c +++ b/src/glew.c @@ -31,6 +31,7 @@ */ #ifndef GLEW_INCLUDE +#define GLEW_STATIC #include "glew.h" #else #include GLEW_INCLUDE