From 99c175dc7a143a889154adcff09c6fbf8f7de3bd Mon Sep 17 00:00:00 2001 From: Thomas Galvin Date: Thu, 6 Feb 2014 19:32:34 -0500 Subject: [PATCH] Added makefile and small changes for compiling on Linux --- include/aw/application.hpp | 6 +-- include/aw/general/settings.cpp | 63 ++++++++++++++++++------------ include/aw/states/stateMachine.hpp | 4 +- include/game/states/menuState.cpp | 5 ++- include/game/states/menuState.hpp | 4 +- makefile | 54 +++++++++++++++++++++++++ 6 files changed, 102 insertions(+), 34 deletions(-) create mode 100644 makefile diff --git a/include/aw/application.hpp b/include/aw/application.hpp index 5e044d0..c55cb01 100644 --- a/include/aw/application.hpp +++ b/include/aw/application.hpp @@ -4,8 +4,8 @@ #include #include -#include "general\settings.hpp" -#include "states\stateMachine.hpp" +#include "general/settings.hpp" +#include "states/stateMachine.hpp" namespace aw @@ -34,4 +34,4 @@ namespace aw }; } -#endif \ No newline at end of file +#endif diff --git a/include/aw/general/settings.cpp b/include/aw/general/settings.cpp index 3945fb4..b2a77cb 100644 --- a/include/aw/general/settings.cpp +++ b/include/aw/general/settings.cpp @@ -43,29 +43,39 @@ namespace aw if (line == "[window]") { //Next row = size, format: "width height" - std::getline(file, line); - std::stringstream sstr(line); - sstr >> windowSettings.size.x >> windowSettings.size.y; + { + std::getline(file, line); + std::stringstream sstr(line); + sstr >> windowSettings.size.x >> windowSettings.size.y; + } //Next row = title std::getline(file, windowSettings.title); //Next row = style - std::getline(file, line); - sstr = std::stringstream(line); - sstr >> windowSettings.style; + { + std::getline(file, line); + std::stringstream sstr(line); + sstr >> windowSettings.style; + } //Next row = contextSettings format: "depth stencil antialiasing major minor" - std::getline(file, line); - sstr = std::stringstream(line); - sstr >> windowSettings.settings.depthBits >> windowSettings.settings.stencilBits >> - windowSettings.settings.antialiasingLevel >> windowSettings.settings.majorVersion >> - windowSettings.settings.minorVersion; + { + std::getline(file, line); + std::stringstream sstr(line); + sstr >> windowSettings.settings.depthBits >> windowSettings.settings.stencilBits >> + windowSettings.settings.antialiasingLevel >> windowSettings.settings.majorVersion >> + windowSettings.settings.minorVersion; + } //Next row = vsync - std::getline(file, line); - sstr = std::stringstream(line); - sstr >> windowSettings.vsync; + { + std::getline(file, line); + std::stringstream sstr(line); + sstr >> windowSettings.vsync; + } //Next row = shaders - std::getline(file, line); - sstr = std::stringstream(line); - sstr >> windowSettings.shaders; + { + std::getline(file, line); + std::stringstream sstr(line); + sstr >> windowSettings.shaders; + } //Read everything file.close(); return true; @@ -89,14 +99,17 @@ namespace aw if (line == "[sound]") { //Next row = enabled - std::getline(file, line); - std::stringstream sstr(line); - sstr >> soundSettings.enabled; + { + std::getline(file, line); + std::stringstream sstr(line); + sstr >> soundSettings.enabled; + } //Next row = volumes format: "menu game" - std::getline(file, line); - sstr = std::stringstream(line); - sstr >> soundSettings.volumeMusic >> soundSettings.volumeVFX; - + { + std::getline(file, line); + std::stringstream sstr(line); + sstr >> soundSettings.volumeMusic >> soundSettings.volumeVFX; + } //Read everything file.close(); return true; @@ -129,4 +142,4 @@ namespace aw file << "\n"; } -} \ No newline at end of file +} diff --git a/include/aw/states/stateMachine.hpp b/include/aw/states/stateMachine.hpp index fd05a4b..ebeede8 100644 --- a/include/aw/states/stateMachine.hpp +++ b/include/aw/states/stateMachine.hpp @@ -31,8 +31,8 @@ namespace aw private: std::stack mStateStack; - std::atomic mShouldPopState = 0; //Loading screen is working due to multithreading = protect this var + std::atomic mShouldPopState{0}; //Loading screen is working due to multithreading = protect this var }; } -#endif \ No newline at end of file +#endif diff --git a/include/game/states/menuState.cpp b/include/game/states/menuState.cpp index 3df1fed..8971b78 100644 --- a/include/game/states/menuState.cpp +++ b/include/game/states/menuState.cpp @@ -51,7 +51,8 @@ namespace aw if (callback.id > 100 && callback.id < 200) { std::string path = "data/levels/Level" + std::to_string(callback.id - 100) + ".txt"; - pushState(StateMachine::State_ptr(new GameState(getStateMachine(), mWindow, mSettings, path))); + auto state = StateMachine::State_ptr(new GameState(getStateMachine(), mWindow, mSettings, path)); + pushState(state); } } } @@ -65,4 +66,4 @@ namespace aw { mGui.draw(true); } -} \ No newline at end of file +} diff --git a/include/game/states/menuState.hpp b/include/game/states/menuState.hpp index f3d5ebb..cbf1333 100644 --- a/include/game/states/menuState.hpp +++ b/include/game/states/menuState.hpp @@ -3,7 +3,7 @@ #include "../../aw/states/state.hpp" -#include +#include namespace sf { @@ -33,4 +33,4 @@ namespace aw }; } -#endif \ No newline at end of file +#endif diff --git a/makefile b/makefile new file mode 100644 index 0000000..ec65a22 --- /dev/null +++ b/makefile @@ -0,0 +1,54 @@ +#------------------------------------------------------------------------------- +# General makefile for C/C++ projects using SFML on linux +#------------------------------------------------------------------------------- + +TARGET := $(shell basename $(CURDIR)) +SOURCES := include include/game/camera include/game/map include/game/misc include/game/player include/game/spawner include/game/states include/aw/ include/aw/colSystem include/aw/general include/aw/states include/aw/utilities +INCLUDES := include include/aw include/game +BUILD := build + +#------------------------------------------------------------------------------- +SYSTEM := $(shell uname -s) +CFILES := $(foreach dir,$(SOURCES),$(wildcard $(dir)/*.c)) +CPPFILES := $(foreach dir,$(SOURCES),$(wildcard $(dir)/*.cpp)) +OFILES := $(addprefix $(BUILD)/,$(CFILES:%.c=%.o)\ + $(CPPFILES:%.cpp=%.o)) +DEPENDFILES := $(OFILES:%.o=%.d) +CC := gcc +CXX := g++ +INCLUDEFILES := $(foreach dir,$(INCLUDES),$(wildcard $(dir)/*.h)) +INCLUDE := $(addprefix -I,$(INCLUDES)) +DEPENDFLAGS := -MMD -MP +CFLAGS := $(INCLUDE) -Wall -O2 +CXXFLAGS := $(CFLAGS) -std=c++11 +# Set LIBSUFFIX to -s for static build (for some reason not working :/ ) +LIBSUFFIX := +LIBS := tgui$(LIBSUFFIX) sfml-audio$(LIBSUFFIX) sfml-graphics$(LIBSUFFIX) sfml-window$(LIBSUFFIX) sfml-system$(LIBSUFFIX) GL GLU X11 Xrandr freetype GLEW jpeg sndfile openal +LDFLAGS := $(addprefix -l,$(LIBS)) + +all: setup $(TARGET) + +$(TARGET): $(OFILES) + $(CXX) $(CFLAGS) -o $(TARGET) $^ $(LDFLAGS) + +.PHONY: setup clean + +setup: + $(foreach source,$(SOURCES),$(shell echo \ + $(shell [ -d $(BUILD)/$(source) ] || ( mkdir -p $(BUILD)/$(source)) ))) + +clean: + -rm -fr $(TARGET) $(BUILD) + +-include $(DEPENDFILES) + +#------------------------------------------------------------------------------- +$(BUILD)/%.o: %.c + @echo $(notdir $<) + $(CC) $(DEPENDFLAGS) $(CXXFLAGS) $(INCLUDE) -c $< -o $@ + @echo + +$(BUILD)/%.o: %.cpp + @echo $(notdir $<) + $(CXX) $(DEPENDFLAGS) $(CXXFLAGS) $(INCLUDE) -c $< -o $@ + @echo