Began work on the server's generic entity system
This commit is contained in:
@@ -0,0 +1,74 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
|
*
|
||||||
|
* 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 BBOX_HPP_
|
||||||
|
#define BBOX_HPP_
|
||||||
|
|
||||||
|
#include <type_traits>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
class BBox {
|
||||||
|
public:
|
||||||
|
double x, y;
|
||||||
|
double w, h;
|
||||||
|
|
||||||
|
BBox() = default;
|
||||||
|
BBox(double i, double j, double k, double l): x(i), y(j), w(k), h(l) {};
|
||||||
|
~BBox() = default;
|
||||||
|
BBox& operator=(BBox const&) = default;
|
||||||
|
|
||||||
|
double Size() {
|
||||||
|
return std::max(w*h,0.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IsCollision(BBox rhs) {
|
||||||
|
return not (
|
||||||
|
x >= rhs.x + rhs.w ||
|
||||||
|
y >= rhs.y + rhs.h ||
|
||||||
|
rhs.x >= x + w ||
|
||||||
|
rhs.y >= y + h
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
BBox Intersection(BBox rhs) {
|
||||||
|
if (!IsCollision(rhs)) {
|
||||||
|
return {0, 0, 0, 0};
|
||||||
|
}
|
||||||
|
BBox 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
double operator[](size_t i) {
|
||||||
|
if (i >= 4)
|
||||||
|
throw(std::domain_error("Out of range"));
|
||||||
|
return *(&x+i);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//This is explicitly a POD
|
||||||
|
static_assert(std::is_pod<BBox>::value, "BBox is not a POD");
|
||||||
|
|
||||||
|
#endif
|
||||||
+4
-1
@@ -22,6 +22,7 @@
|
|||||||
#ifndef VECTOR2_HPP_
|
#ifndef VECTOR2_HPP_
|
||||||
#define VECTOR2_HPP_
|
#define VECTOR2_HPP_
|
||||||
|
|
||||||
|
#include <type_traits>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
@@ -29,7 +30,6 @@ class Vector2 {
|
|||||||
public:
|
public:
|
||||||
double x, y;
|
double x, y;
|
||||||
|
|
||||||
//This is explicitly a POD
|
|
||||||
Vector2() = default;
|
Vector2() = default;
|
||||||
Vector2(double i, double j): x(i), y(j) {};
|
Vector2(double i, double j): x(i), y(j) {};
|
||||||
~Vector2() = default;
|
~Vector2() = default;
|
||||||
@@ -112,4 +112,7 @@ template<typename T> Vector2 operator/(T t, Vector2 v) { return v / t; }
|
|||||||
template<typename T> bool operator==(T t, Vector2 v) { return v == t; }
|
template<typename T> bool operator==(T t, Vector2 v) { return v == t; }
|
||||||
template<typename T> bool operator!=(T t, Vector2 v) { return v != t; }
|
template<typename T> bool operator!=(T t, Vector2 v) { return v != t; }
|
||||||
|
|
||||||
|
//This is explicitly a POD
|
||||||
|
static_assert(std::is_pod<Vector2>::value, "Vector2 is not a POD");
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2014
|
||||||
|
*
|
||||||
|
* 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 "entity.hpp"
|
||||||
|
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
|
//This is explicitly a POD
|
||||||
|
static_assert(std::is_pod<Entity>::value, "Entity is not a POD");
|
||||||
|
|
||||||
|
unsigned int Entity::uidCounter;
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2014
|
||||||
|
*
|
||||||
|
* 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 ENTITY_HPP_
|
||||||
|
#define ENTITY_HPP_
|
||||||
|
|
||||||
|
//POD members
|
||||||
|
#include "vector2.hpp"
|
||||||
|
#include "bbox.hpp"
|
||||||
|
|
||||||
|
struct Entity {
|
||||||
|
enum Type {
|
||||||
|
PLAYER,
|
||||||
|
PORTAL,
|
||||||
|
ITEMS,
|
||||||
|
CHEST,
|
||||||
|
DOOR,
|
||||||
|
};
|
||||||
|
|
||||||
|
Type type;
|
||||||
|
int mapIndex;
|
||||||
|
Vector2 position;
|
||||||
|
Vector2 motion;
|
||||||
|
BBox bbox;
|
||||||
|
unsigned int uid;
|
||||||
|
static unsigned int uidCounter;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2014
|
||||||
|
*
|
||||||
|
* 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 PLAYERENTITY_HPP_
|
||||||
|
#define PLAYERENTITY_HPP_
|
||||||
|
|
||||||
|
struct PlayerEntity {
|
||||||
|
//TODO: stuff
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -53,7 +53,8 @@ void ServerApplication::Init(int argc, char** argv) {
|
|||||||
cout << "Beginning startup" << endl;
|
cout << "Beginning startup" << endl;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
//load config
|
//initial setup
|
||||||
|
Entity::uidCounter = 0;
|
||||||
config.Load("rsc\\config.cfg");
|
config.Load("rsc\\config.cfg");
|
||||||
|
|
||||||
//Init SDL
|
//Init SDL
|
||||||
|
|||||||
@@ -22,6 +22,10 @@
|
|||||||
#ifndef SERVERAPPLICATION_HPP_
|
#ifndef SERVERAPPLICATION_HPP_
|
||||||
#define SERVERAPPLICATION_HPP_
|
#define SERVERAPPLICATION_HPP_
|
||||||
|
|
||||||
|
//server specific stuff
|
||||||
|
#include "entity.hpp"
|
||||||
|
#include "player_entity.hpp"
|
||||||
|
|
||||||
//maps
|
//maps
|
||||||
#include "map_generator.hpp"
|
#include "map_generator.hpp"
|
||||||
#include "map_file_format.hpp"
|
#include "map_file_format.hpp"
|
||||||
|
|||||||
Reference in New Issue
Block a user