diff --git a/client/base_scene.cpp b/client/base_scene.cpp index 240269d..baa8ab9 100644 --- a/client/base_scene.cpp +++ b/client/base_scene.cpp @@ -1,24 +1,3 @@ -/* Copyright: (c) Kayne Ruse 2013 - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. -*/ #include "base_scene.hpp" #include diff --git a/client/base_scene.hpp b/client/base_scene.hpp index 1080d5b..42f30a7 100644 --- a/client/base_scene.hpp +++ b/client/base_scene.hpp @@ -1,24 +1,3 @@ -/* Copyright: (c) Kayne Ruse 2013 - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. -*/ #ifndef BASESCENE_HPP_ #define BASESCENE_HPP_ diff --git a/client/main.cpp b/client/main.cpp index 7a76519..35f3e36 100644 --- a/client/main.cpp +++ b/client/main.cpp @@ -1,24 +1,3 @@ -/* Copyright: (c) Kayne Ruse 2013 - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. -*/ #include "scene_manager.hpp" #include diff --git a/client/makefile b/client/makefile index 8e1c861..c2427f2 100644 --- a/client/makefile +++ b/client/makefile @@ -1,6 +1,7 @@ #config -CXXFLAGS+=-std=c++11 -DDEBUG -LIB=-lmingw32 -lSDL_net -lSDLmain -lSDL -lwsock32 -liphlpapi +INCLUDES=../common +CXXFLAGS+=-std=c++11 -DDEBUG $(addprefix -I,$(INCLUDES)) +LIB=../common/out/common.a -lmingw32 -lSDL_net -lSDLmain -lSDL -lwsock32 -liphlpapi #source SRC=$(filter-out unit.cpp, $(wildcard *.cpp)) diff --git a/client/button.cpp b/common/button.cpp similarity index 100% rename from client/button.cpp rename to common/button.cpp diff --git a/client/button.hpp b/common/button.hpp similarity index 100% rename from client/button.hpp rename to common/button.hpp diff --git a/client/config_utility.cpp b/common/config_utility.cpp similarity index 100% rename from client/config_utility.cpp rename to common/config_utility.cpp diff --git a/client/config_utility.hpp b/common/config_utility.hpp similarity index 100% rename from client/config_utility.hpp rename to common/config_utility.hpp diff --git a/client/delta.hpp b/common/delta.hpp similarity index 100% rename from client/delta.hpp rename to common/delta.hpp diff --git a/client/frame_rate.hpp b/common/frame_rate.hpp similarity index 100% rename from client/frame_rate.hpp rename to common/frame_rate.hpp diff --git a/client/image.cpp b/common/image.cpp similarity index 100% rename from client/image.cpp rename to common/image.cpp diff --git a/client/image.hpp b/common/image.hpp similarity index 100% rename from client/image.hpp rename to common/image.hpp diff --git a/common/makefile b/common/makefile new file mode 100644 index 0000000..10e9ab1 --- /dev/null +++ b/common/makefile @@ -0,0 +1,37 @@ +#config +INCLUDES= +CXXFLAGS+=-std=c++11 -DDEBUG $(addprefix -I,$(INCLUDES)) +LIB= + +#source +SRC=$(wildcard *.cpp) + +#objects +OBJDIR=obj +OBJ=$(addprefix $(OBJDIR)/,$(SRC:.cpp=.o)) + +#output +OUTDIR=out +OUT=$(addprefix $(OUTDIR)/,common.a) + +#targets +all: $(OBJ) $(OUT) + ar -crs $(OUT) $(OBJ) + +$(OBJ): | $(OBJDIR) + +$(OUT): | $(OUTDIR) + +$(OBJDIR): + mkdir $(OBJDIR) + +$(OUTDIR): + mkdir $(OUTDIR) + +$(OBJDIR)/%.o: %.cpp + $(CXX) $(CXXFLAGS) -c -o $@ $< + +clean: + $(RM) *.o *.a *.exe + +rebuild: clean all diff --git a/client/raster_font.cpp b/common/raster_font.cpp similarity index 100% rename from client/raster_font.cpp rename to common/raster_font.cpp diff --git a/client/raster_font.hpp b/common/raster_font.hpp similarity index 100% rename from client/raster_font.hpp rename to common/raster_font.hpp diff --git a/client/sprite_sheet.cpp b/common/sprite_sheet.cpp similarity index 100% rename from client/sprite_sheet.cpp rename to common/sprite_sheet.cpp diff --git a/client/sprite_sheet.hpp b/common/sprite_sheet.hpp similarity index 100% rename from client/sprite_sheet.hpp rename to common/sprite_sheet.hpp diff --git a/client/surface_manager.cpp b/common/surface_manager.cpp similarity index 100% rename from client/surface_manager.cpp rename to common/surface_manager.cpp diff --git a/client/surface_manager.hpp b/common/surface_manager.hpp similarity index 100% rename from client/surface_manager.hpp rename to common/surface_manager.hpp diff --git a/server/udp_network_utility.hpp b/common/udp_network_utility.hpp similarity index 100% rename from server/udp_network_utility.hpp rename to common/udp_network_utility.hpp diff --git a/client/vector2.hpp b/common/vector2.hpp similarity index 100% rename from client/vector2.hpp rename to common/vector2.hpp diff --git a/server/config_utility.cpp b/server/config_utility.cpp deleted file mode 100644 index d6cc812..0000000 --- a/server/config_utility.cpp +++ /dev/null @@ -1,76 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013 - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. -*/ -#include "config_utility.hpp" - -#include -#include - -using namespace std; - -void ConfigUtility::Load(string fname) { - ifstream is(fname); - - if (!is.is_open()) { - throw(runtime_error("Failed to open config file")); - } - - string key, val; - - for (;;) { //forever - //eat whitespace - while(isspace(is.peek())) - is.ignore(); - - //end of file - if (is.eof()) - break; - - //skip comment lines - if (is.peek() == '#') { - while(is.peek() != '\n' && !is.eof()) { - is.ignore(); - } - continue; - } - - //read in the pair - getline(is, key,'='); - getline(is, val); - - //trim the strings at the start & end - while(key.size() && isspace(*key.begin())) key.erase(0, 1); - while(val.size() && isspace(*val.begin())) val.erase(0, 1); - - while(key.size() && isspace(*(key.end()-1))) key.erase(key.end() - 1); - while(val.size() && isspace(*(val.end()-1))) val.erase(val.end() - 1); - - //allow empty/wiped values - if (key.size() == 0) { - continue; - } - - //save the pair - table[key] = val; - } - - is.close(); -} diff --git a/server/config_utility.hpp b/server/config_utility.hpp deleted file mode 100644 index c5e0977..0000000 --- a/server/config_utility.hpp +++ /dev/null @@ -1,68 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013 - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. -*/ -#ifndef CONFIGUTILITY_HPP_ -#define CONFIGUTILITY_HPP_ - -#include -#include -#include - -class ConfigUtility { -public: - ConfigUtility() {} - ConfigUtility(std::string s) { Load(s); } - - void Load(std::string fname); - - std::string String(std::string s) { - return table[s]; - } - const char* CString(std::string s) { - return table[s].c_str(); - } - int Integer(std::string s) { - return atoi(table[s].c_str()); - } - double Double(std::string s) { - return atof(table[s].c_str()); - } - bool Boolean(std::string s) { - return table[s] == "true"; - } - - std::string& operator[](std::string s) { - return table[s]; - } - int Int(std::string s) { - return Integer(s); - } - int Bool(std::string s) { - return Boolean(s); - } - std::map* GetMap() { - return &table; - } -private: - std::map table; -}; - -#endif diff --git a/server/delta.hpp b/server/delta.hpp deleted file mode 100644 index 25423a0..0000000 --- a/server/delta.hpp +++ /dev/null @@ -1,45 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013 - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. -*/ -#ifndef DELTA_HPP_ -#define DELTA_HPP_ - -#include - -class Delta { -public: - Delta() { - time = tick = 0; - } - int Calculate() { - int c = clock(); - time = c - tick; - tick = c; - return time; - } - int GetDelta() const { - return time; - }; -private: - int time, tick; -}; - -#endif diff --git a/server/makefile b/server/makefile index 7ec6eaf..4ae339d 100644 --- a/server/makefile +++ b/server/makefile @@ -1,6 +1,7 @@ #config -CXXFLAGS+=-std=c++11 -DDEBUG -LIB=-lmingw32 -lSDL_net -lSDLmain -lSDL -lwsock32 -liphlpapi +INCLUDES=../common +CXXFLAGS+=-std=c++11 -DDEBUG $(addprefix -I,$(INCLUDES)) +LIB=../common/out/common.a -lmingw32 -lSDL_net -lSDLmain -lSDL -lwsock32 -liphlpapi #source SRC=$(filter-out unit.cpp main.cpp, $(wildcard *.cpp)) diff --git a/server/vector2.hpp b/server/vector2.hpp deleted file mode 100644 index 1cd36aa..0000000 --- a/server/vector2.hpp +++ /dev/null @@ -1,76 +0,0 @@ -/* Copyright: (c) Kayne Ruse 2013 - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. -*/ -#ifndef VECTOR2_HPP_ -#define VECTOR2_HPP_ - -#include -#include - -class Vector2 { -public: - double x, y; - Vector2() { - x = y = 0; - } - Vector2(double i, double j) { - x = i; y = j; - } - double Length() const { - return sqrt(x*x+y*y); - } - double SquaredLength() const { - return x*x+y*y; - } - double operator[](size_t i) { - if (i >= 2) - throw(std::runtime_error("Out of range")); - return *(&x+i); - } - //Arithmetic operators - Vector2 operator+(Vector2 v) const { return Vector2(x + v.x, y + v.y); } - Vector2 operator-(Vector2 v) const { return Vector2(x - v.x, y - v.y); } - Vector2 operator*(Vector2 v) const { return Vector2(x * v.x, y * v.y); } - Vector2 operator*(double d) const { return Vector2(x * d, y * d); } - - Vector2 operator/(Vector2 v) { - if (!v.x || !v.y) - throw(std::runtime_error("Divide by zero")); - return Vector2(x / v.x, y / v.y); - } - Vector2 operator/(double d) { - if (!d) - throw(std::runtime_error("Divide by zero")); - return Vector2(x / d, y / d); - } - - bool operator==(Vector2 v) { return (x == v.x && y == v.y); } - bool operator!=(Vector2 v) { return (x != v.x || y != v.y); } - - template Vector2 operator+=(T t) { return *this = *this + t; } - template Vector2 operator-=(T t) { return *this = *this - t; } - template Vector2 operator*=(T t) { return *this = *this * t; } - template Vector2 operator/=(T t) { return *this = *this / t; } - template bool operator==(T t) { return (x == t && y == t); } - template bool operator!=(T t) { return (x != t || y != t); } -}; - -#endif