The submodules and common/ compiles
Please note that there are duplicate copies of vector2.hpp and bounding_box.hpp
This commit is contained in:
+2
-4
@@ -1,12 +1,10 @@
|
||||
#output
|
||||
export OUTDIR=..
|
||||
export OUTDIR=../..
|
||||
export OUT=$(addprefix $(OUTDIR)/,libcommon.a)
|
||||
|
||||
all: $(OUTDIR)
|
||||
$(MAKE) -C debugging
|
||||
$(MAKE) -C gameplay
|
||||
$(MAKE) -C graphics
|
||||
$(MAKE) -C map
|
||||
$(MAKE) -C global_defines
|
||||
$(MAKE) -C network
|
||||
$(MAKE) -C utilities
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#config
|
||||
INCLUDES+=. packet_types ../gameplay ../map ../utilities
|
||||
INCLUDES+=. packet_types ../global_defines ../utilities ../../TurtleMap
|
||||
LIBS+=
|
||||
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#config
|
||||
INCLUDES+=. .. ../../gameplay ../../map ../../utilities
|
||||
INCLUDES+=. .. ../../global_defines ../../utilities ../../../TurtleMap
|
||||
LIBS+=
|
||||
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <type_traits>
|
||||
#include <algorithm>
|
||||
|
||||
class BoundingBox {
|
||||
public:
|
||||
//This is explicitly a POD
|
||||
int x, y;
|
||||
int w, h;
|
||||
|
||||
BoundingBox() = default;
|
||||
BoundingBox(int i, int j): x(i), y(j), w(0), h(0) {};
|
||||
BoundingBox(int i, int j, int k, int l): x(i), y(j), w(k), h(l) {};
|
||||
~BoundingBox() = default;
|
||||
BoundingBox& operator=(BoundingBox const&) = default;
|
||||
|
||||
int Size() {
|
||||
return std::max(w*h,0);
|
||||
}
|
||||
|
||||
bool CheckOverlap(BoundingBox rhs) {
|
||||
return !(
|
||||
x >= rhs.x + rhs.w ||
|
||||
y >= rhs.y + rhs.h ||
|
||||
rhs.x >= x + w ||
|
||||
rhs.y >= y + h);
|
||||
}
|
||||
|
||||
BoundingBox CalcOverlap(BoundingBox rhs) {
|
||||
if (!CheckOverlap(rhs)) {
|
||||
return {0, 0, 0, 0};
|
||||
}
|
||||
BoundingBox ret;
|
||||
ret.x = std::max(x, rhs.x);
|
||||
ret.y = std::max(y, rhs.y);
|
||||
ret.w = std::min(x+w, rhs.x+rhs.w) - ret.x;
|
||||
ret.h = std::min(y+h, rhs.y+rhs.h) - ret.y;
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
|
||||
//This is explicitly a POD
|
||||
static_assert(std::is_pod<BoundingBox>::value, "BoundingBox is not a POD");
|
||||
|
||||
#include "vector2.hpp"
|
||||
|
||||
//operators
|
||||
inline BoundingBox operator+(BoundingBox b, Vector2 v) {
|
||||
return {b.x + (int)v.x, b.y + (int)v.y, b.w, b.h};
|
||||
}
|
||||
inline BoundingBox operator+(Vector2 v, BoundingBox b) {
|
||||
return b + v;
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <type_traits>
|
||||
#include <stdexcept>
|
||||
#include <cmath>
|
||||
|
||||
class Vector2 {
|
||||
public:
|
||||
double x, y;
|
||||
|
||||
Vector2() = default;
|
||||
Vector2(double i, double j): x(i), y(j) {};
|
||||
~Vector2() = default;
|
||||
Vector2& operator=(Vector2 const&) = default;
|
||||
|
||||
double Length() const {
|
||||
return sqrt(x*x+y*y);
|
||||
}
|
||||
double SquaredLength() const {
|
||||
return x*x+y*y;
|
||||
}
|
||||
void Normalize() {
|
||||
double l = Length();
|
||||
if (l == 0)
|
||||
throw(std::domain_error("Divide by zero"));
|
||||
x /= l;
|
||||
y /= l;
|
||||
}
|
||||
|
||||
//Arithmetic operators
|
||||
Vector2 operator+(Vector2 v) const {
|
||||
Vector2 ret;
|
||||
ret.x = x + v.x;
|
||||
ret.y = y + v.y;
|
||||
return ret;
|
||||
}
|
||||
Vector2 operator-(Vector2 v) const {
|
||||
Vector2 ret;
|
||||
ret.x = x - v.x;
|
||||
ret.y = y - v.y;
|
||||
return ret;
|
||||
}
|
||||
Vector2 operator*(Vector2 v) const {
|
||||
Vector2 ret;
|
||||
ret.x = x * v.x;
|
||||
ret.y = y * v.y;
|
||||
return ret;
|
||||
}
|
||||
Vector2 operator*(double d) const {
|
||||
Vector2 ret;
|
||||
ret.x = x * d;
|
||||
ret.y = y * d;
|
||||
return ret;
|
||||
}
|
||||
|
||||
Vector2 operator/(Vector2 v) {
|
||||
if (!v.x || !v.y)
|
||||
throw(std::domain_error("Divide by zero"));
|
||||
Vector2 ret;
|
||||
ret.x = x / v.x;
|
||||
ret.y = y / v.y;
|
||||
return ret;
|
||||
}
|
||||
Vector2 operator/(double d) {
|
||||
if (!d)
|
||||
throw(std::domain_error("Divide by zero"));
|
||||
Vector2 ret;
|
||||
ret.x = x / d;
|
||||
ret.y = y / d;
|
||||
return ret;
|
||||
}
|
||||
|
||||
//unary operators
|
||||
Vector2 operator-() { return {-x, -y}; }
|
||||
|
||||
//comparison operators
|
||||
bool operator==(Vector2 v) { return (x == v.x && y == v.y); }
|
||||
bool operator!=(Vector2 v) { return (x != v.x || y != v.y); }
|
||||
|
||||
//member templates (curry the above operators)
|
||||
template<typename T> Vector2 operator+=(T t) { return *this = *this + t; }
|
||||
template<typename T> Vector2 operator-=(T t) { return *this = *this - t; }
|
||||
template<typename T> Vector2 operator*=(T t) { return *this = *this * t; }
|
||||
template<typename T> Vector2 operator/=(T t) { return *this = *this / t; }
|
||||
template<typename T> bool operator==(T t) { return (x == t && y == t); }
|
||||
template<typename T> bool operator!=(T t) { return (x != t || y != t); }
|
||||
};
|
||||
|
||||
//This is explicitly a POD
|
||||
static_assert(std::is_pod<Vector2>::value, "Vector2 is not a POD");
|
||||
@@ -7,10 +7,12 @@
|
||||
OUTDIR=out
|
||||
BINDIR=bin
|
||||
|
||||
all: $(OUTDIR) binary
|
||||
all: $(OUTDIR) dll
|
||||
$(MAKE) -C TurtleGUI
|
||||
$(MAKE) -C TurtleMap
|
||||
$(MAKE) -C common
|
||||
$(MAKE) -C server
|
||||
$(MAKE) -C client
|
||||
# $(MAKE) -C server
|
||||
# $(MAKE) -C client
|
||||
|
||||
debug: export CXXFLAGS+=-g
|
||||
debug: clean all
|
||||
@@ -27,7 +29,7 @@ else ifeq ($(shell uname), Linux)
|
||||
tar -C $(OUTDIR) -zcvf Tortuga-linux.tar client server ../rsc ../copyright.txt ../instructions.txt
|
||||
endif
|
||||
|
||||
binary: $(OUTDIR)
|
||||
dll: $(OUTDIR)
|
||||
ifeq ($(OS),Windows_NT)
|
||||
xcopy /Y $(BINDIR)\\*.dll $(OUTDIR)
|
||||
endif
|
||||
|
||||
Reference in New Issue
Block a user