Now compiles with CLion+MinGW

This commit is contained in:
Adrian Hedqvist 2017-09-17 20:07:38 +02:00
parent 6a31952257
commit c4997823ed
28 changed files with 77 additions and 60 deletions

1
.gitattributes vendored
View file

@ -1 +0,0 @@
*.bmp filter=lfs diff=lfs merge=lfs -text

5
.gitignore vendored
View file

@ -10,6 +10,11 @@
[Dd]ebug
[Rr]elease
# CLion idea
.idea
cmake-build-debug
cmake-build-release
# CMake
CMakeCache.txt
CMakeFiles

View file

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

View file

@ -14,7 +14,7 @@ BehaviourTreeStatus AttackEnemyNode::tick(BTTick * tick) {
auto actors = tick->target->map->GetActorList();
std::vector<Actor*> 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) {

View file

@ -10,7 +10,7 @@ BehaviourTreeNode::BehaviourTreeNode(BehaviourTreeNode* parent) {
}
BehaviourTreeNode::~BehaviourTreeNode() {
for each (BehaviourTreeNode* child in children) {
for (BehaviourTreeNode* child : children) {
delete child;
}
}

View file

@ -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<string> 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();

View file

@ -3,13 +3,13 @@
#include <map>
class Config {
char* path;
std::string path;
std::map<std::string, std::string> strings;
std::map<std::string, float> floats;
std::map<std::string, int> ints;
std::map<std::string, bool> bools;
public:
Config(char* path);
Config(std::string path);
void load();
void save();
void deleteValue(std::string key);

View file

@ -1,3 +1,4 @@
#include <cstdlib>
#include "ExploreNode.h"
#include "Pathfinder.h"
#include "BehaviourTree.h"
@ -26,7 +27,7 @@ BehaviourTreeStatus ExploreNode::tick(BTTick * tick) {
std::vector<vec2i> neigh = map->getNeighbours(pos.x, pos.y);
std::vector<vec2i> 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)) {

View file

@ -1,3 +1,4 @@
#include <cmath>
#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;

View file

@ -1,3 +1,4 @@
#include <cstdlib>
#include "FleeNode.h"
#include "Pathfinder.h"
#include "BehaviourTree.h"
@ -16,7 +17,7 @@ BehaviourTreeStatus FleeNode::tick(BTTick * tick) {
std::vector<vec2i> 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<vec2i> neigh = map->getNeighbours(pos.x, pos.y);
std::vector<vec2i> 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;

View file

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

View file

@ -13,7 +13,7 @@ BehaviourTreeStatus HealFriendNode::tick(BTTick * tick) {
auto actors = tick->target->map->GetActorList();
std::vector<Actor*> 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;

View file

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

View file

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

View file

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

View file

@ -1,7 +1,6 @@
//#define _ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH
//#define _ITERATOR_DEBUG_LEVEL 0
#include "Renderer.h"
#include <SDL.h>
#include <stdio.h>
@ -9,6 +8,7 @@
#include <string>
#include <time.h>
#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;

View file

@ -1,3 +1,4 @@
#include <math.h>
#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<vec2i> 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) {

View file

@ -17,7 +17,7 @@ BehaviourTreeStatus RangedAttackNode::tick(BTTick * tick) {
auto actors = tick->target->map->GetActorList();
std::vector<Actor*> 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;

View file

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

View file

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

View file

@ -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<Actor*> Tilemap::GetActors(int x, int y, int range, Actors type) {
std::vector<Actor*> found;
std::vector<vec2i> 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) {

View file

@ -1,11 +1,9 @@
#pragma once
#include <vector>
#include "Actor.h"
struct vec2i;
class Actor;
enum Actors;
class Tilemap {
unsigned int* tilemap;
std::vector<Actor*> actors;

View file

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

View file

@ -1,4 +1,5 @@
#pragma once
#include <string>
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);

View file

@ -1,3 +1,4 @@
#include <cstdlib>
#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;

View file

@ -1,5 +1,6 @@
#include "World.h"
#include <time.h>
#include <cstdlib>
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;
}

View file

@ -106,6 +106,7 @@
#include <KHR/khrplatform.h>
#include <EGL/eglplatform.h>
#define GLEW_STATIC
#include "glew.h"
#ifdef __cplusplus

View file

@ -31,6 +31,7 @@
*/
#ifndef GLEW_INCLUDE
#define GLEW_STATIC
#include "glew.h"
#else
#include GLEW_INCLUDE