Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix makefile to include new project source files #39

Merged
merged 5 commits into from Nov 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions WyvernsNest.vcxproj
Expand Up @@ -138,6 +138,7 @@
<ClCompile Include="src\engine\renderer.cpp" />
<ClCompile Include="src\engine\sprite.cpp" />
<ClCompile Include="src\engine\state.cpp" />
<ClCompile Include="src\engine\textureManager.cpp" />
<ClCompile Include="src\engine\text\font.cpp" />
<ClCompile Include="src\engine\text\textRenderer.cpp" />
<ClCompile Include="src\game\combat.cpp" />
Expand Down Expand Up @@ -166,6 +167,7 @@
<ClInclude Include="src\engine\renderer.hpp" />
<ClInclude Include="src\engine\sprite.hpp" />
<ClInclude Include="src\engine\state.hpp" />
<ClInclude Include="src\engine\textureManager.hpp" />
<ClInclude Include="src\engine\text\font.hpp" />
<ClInclude Include="src\engine\text\textRenderer.hpp" />
<ClInclude Include="src\game\combat.hpp" />
Expand Down
6 changes: 6 additions & 0 deletions WyvernsNest.vcxproj.filters
Expand Up @@ -84,6 +84,9 @@
<ClCompile Include="src\game\menu.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\engine\textureManager.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\engine\engine.hpp">
Expand Down Expand Up @@ -173,5 +176,8 @@
<ClInclude Include="src\game\menu.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\engine\textureManager.hpp">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
10 changes: 8 additions & 2 deletions makefile
Expand Up @@ -4,10 +4,10 @@ LIBS = -lGLEW -lSDL2 -lfreetype -L/usr/local/Cellar/sdl2/2.0.8/lib/ -L/usr/local
INCLUDE = -I/usr/local/Cellar/sdl2/2.0.8/include/SDL2/ -I/usr/local/Cellar/glew/2.1.0/include/ -Ilibs/stb_image/ -I/usr/local/Cellar/freetype/2.9.1/include/freetype2/
LFLAGS = -std=c++11 -framework OpenGL -w $(LIBS) $(INCLUDE)
CFLAGS = $(LFLAGS) -o bin/objs/$@
OBJS = engine.o entity.o indexBuffer.o shader.o texture.o vertexArray.o vertexBuffer.o renderer.o sprite.o state.o combat.o customization.o cutscene.o vec.o
OBJS = engine.o entity.o indexBuffer.o shader.o texture.o vertexArray.o vertexBuffer.o renderer.o sprite.o state.o combat.o customization.o cutscene.o vec.o textRenderer.o font.o player.o grid.o enemy.o menu.o unit.o attack.o
BIN_OBJS = $(addprefix bin/objs/, $(OBJS))

VPATH = src src/engine src/engine/opengl src/engine/text src/game src/math bin bin/objs
VPATH = src src/engine src/engine/opengl src/engine/text src/game src/game/combat src/math bin bin/objs
TARGET = bin/game

all: $(TARGET)
Expand Down Expand Up @@ -38,6 +38,12 @@ combat.o: combat.cpp core.hpp
customization.o: customization.cpp core.hpp unitData.hpp
cutscene.o: cutscene.cpp core.hpp
vec.o: vec.cpp
player.o: player.cpp core.hpp vec.hpp attack.hpp
grid.o: grid.cpp core.hpp vec.hpp player.hpp enemy.hpp
enemy.o: enemy.cpp core.hpp vec.hpp
menu.o: menu.cpp core.hpp
unit.o: unit.cpp core.hpp attack.hpp unitData.hpp
attack.o: attack.cpp core.hpp vec.hpp

.cpp.o:
$(CXX) $(CFLAGS) -c $<
Expand Down
5 changes: 5 additions & 0 deletions src/engine/core.hpp
Expand Up @@ -4,6 +4,7 @@
#include "engine.hpp"
#include "renderer.hpp"
#include "text/textRenderer.hpp"
#include "textureManager.hpp"
#include "entity.hpp"
#include "state.hpp"
#include "sprite.hpp"
Expand Down Expand Up @@ -47,6 +48,10 @@ namespace Core {
return Engine::get_instance().getDebugMode();
}

inline Texture * getTexture(const std::string& fileName) {
return Engine::get_instance().getTextureManager()->getTexture(fileName);
}

// Wrappers around renderer functionalities
namespace Renderer {

Expand Down
12 changes: 12 additions & 0 deletions src/engine/engine.cpp
Expand Up @@ -10,6 +10,7 @@
// Other project includes
#include "renderer.hpp"
#include "text/textRenderer.hpp"
#include "textureManager.hpp"
#include "state.hpp"

bool Engine::init(const char * name, int window_width, int window_height) {
Expand Down Expand Up @@ -64,6 +65,9 @@ bool Engine::init(const char * name, int window_width, int window_height) {
// Initialize the text renderer after the OpenGL context is created
m_textRenderer = new TextRenderer("res/test_font.ttf", 32, Vec2<int>(m_windowWidth, m_windowHeight));

// Initialize the texture manager
m_textureManager = new TextureManager();

// reset m_lastTick for a more accurate first tick
m_lastTick = SDL_GetTicks();

Expand Down Expand Up @@ -135,6 +139,10 @@ TextRenderer * Engine::getTextRenderer() {
return m_textRenderer;
}

TextureManager * Engine::getTextureManager() {
return m_textureManager;
}

void Engine::setState(State * state) {
if (m_state) delete m_state;
m_state = state;
Expand All @@ -161,6 +169,10 @@ Engine::Engine() :
Engine::~Engine() {
delete m_state;

delete m_renderer;
delete m_textRenderer;
delete m_textureManager;

SDL_GL_DeleteContext(m_context);
SDL_DestroyWindow(m_window);
SDL_Quit();
Expand Down
4 changes: 4 additions & 0 deletions src/engine/engine.hpp
Expand Up @@ -6,6 +6,8 @@

class Renderer;
class TextRenderer;
class TextureManager;

class State;

class Engine {
Expand All @@ -32,6 +34,7 @@ class Engine {
int getWindowHeight() const;
Renderer * getRenderer();
TextRenderer * getTextRenderer();
TextureManager * getTextureManager();

// State changing functions
void setState(State * state);
Expand All @@ -49,6 +52,7 @@ class Engine {
// System objects
Renderer * m_renderer;
TextRenderer * m_textRenderer;
TextureManager * m_textureManager;

// SDL/OpenGL specific objects
SDL_Window * m_window;
Expand Down
8 changes: 6 additions & 2 deletions src/engine/sprite.cpp
Expand Up @@ -11,8 +11,8 @@ Sprite::Sprite(const std::string & path) :
original_w(0),
original_h(0)
{
src_w = original_w = w = texture.getWidth();
src_h = original_h = h = texture.getHeight();
src_w = original_w = w = Core::getTexture(path)->getWidth();
src_h = original_h = h = Core::getTexture(path)->getHeight();
}

Sprite::~Sprite() {
Expand All @@ -24,6 +24,10 @@ void Sprite::render() {
Core::Renderer::drawSprite(*this);
}

const Texture & Sprite::getTexture() const {
return *Core::getTexture(texture);
}

void Sprite::setPos(int x, int y) {
this->x = x;
this->y = y;
Expand Down
4 changes: 2 additions & 2 deletions src/engine/sprite.hpp
Expand Up @@ -16,7 +16,7 @@ class Sprite {
// Sprite size
int w, h;

const Texture& getTexture() const { return texture; }
const Texture& getTexture() const;

// Texture source information
int src_x, src_y;
Expand All @@ -34,6 +34,6 @@ class Sprite {

private:

Texture texture;
std::string texture;

};
23 changes: 23 additions & 0 deletions src/engine/textureManager.cpp
@@ -0,0 +1,23 @@
#include "textureManager.hpp"

#include "opengl/texture.hpp"

TextureManager::TextureManager() {

}

TextureManager::~TextureManager() {

}

Texture * TextureManager::getTexture(const std::string & fileName) {
if (m_textures.find(fileName) == m_textures.end()) {
m_textures[fileName] = new Texture(fileName);
}
return m_textures[fileName];
}

void TextureManager::deleteTexture(const std::string & fileName) {
delete m_textures[fileName];
m_textures.erase(fileName);
}
19 changes: 19 additions & 0 deletions src/engine/textureManager.hpp
@@ -0,0 +1,19 @@
#pragma once

#include <string>
#include <unordered_map>

class Texture;

class TextureManager {
public:

TextureManager();
~TextureManager();

Texture* getTexture(const std::string& fileName);
void deleteTexture(const std::string& fileName);

private:
std::unordered_map<std::string, Texture*> m_textures;
};
2 changes: 1 addition & 1 deletion src/game/combat.cpp
Expand Up @@ -62,7 +62,7 @@ void Combat::handleEvent(const SDL_Event& e) {
if (e.type == SDL_KEYDOWN) {
if (e.key.keysym.sym == SDLK_RETURN) {
// Move on to the next state

changeState(new Combat());
}
}
}
Expand Down