Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
blob: b3dd7efc56b3c7ffeb21ff972d3bf078cd582fff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
   core/entity.h
   This file is part of the Osirion project and is distributed under
   the terms of the GNU General Public License version 2.
*/

#ifndef __INCLUDED_CORE_ENTITY_H__
#define __INCLUDED_CORE_ENTITY_H__

namespace core
{
class EntityControlable;
}

#include "core/player.h"
#include "math/mathlib.h"

#include <vector>

namespace core
{

namespace entity
{

/// Entity flags
enum Flags {Static=1, Solid=2};

/// Entity type constants
enum Type {Default = 0, Dynamic = 1, Controlable = 2};

/// Entity shape constants
enum Shape {Diamond=0, Sphere=1, Cube=2};

}

/// The base world entity. All gameworld entities must derive from this class.
class Entity
{
public:
	/// create a new entity and add it to the registry
	Entity(unsigned int entity_flags = 0);
	virtual ~Entity();
	
	///  core type id
	virtual inline unsigned int core_type() { return entity::Default; }

	/// unique instance identifier, automaticly set
	unsigned int id;

	/// core shape id
	entity::Shape core_shape;

	/// core color
	math::Color core_color;

	/// core radius, in game units
	float core_radius;
	
	/// the entities label
	std::string label;

	/// custom game type id of this entity
	unsigned int type;

	/// flags
	/// @see core::entity::Flags
	unsigned int flags;

	/* updateable by game */

	/// location of the entity
	math::Vector3f location;

	/// direction the entity is facing, in degrees
	/// A direction of 0 degrees means the entity is looking
	/// along the positive X-axis.
	float direction;
};

/// an entity that can move around in the game world
class EntityDynamic : public Entity
{
public:
	EntityDynamic(unsigned int entity_flags = 0);
	virtual ~EntityDynamic();

	/// core type id
	virtual inline unsigned int core_type() { return entity::Dynamic; }

	/* updateable by game */

	/// current speed of the entity in game units per second
	float speed;
};

/// an entity that can be controlled by a player
class EntityControlable : public EntityDynamic
{
public:
	EntityControlable(unsigned int entity_flags = 0);
	virtual ~EntityControlable();

	/// core type id
	virtual inline unsigned int core_type() { return entity::Controlable; }

	/// runs one game frame for the entity, to be implemented by game
	virtual void frame(float seconds) = 0;

	/* updateable by game */

	/// owner of this controllable entity
	Player *owner;

	/* updatable by client */

	/// the direction the client wants to travel the entity to
	/// @see direction
	float target_direction;

	/// engine thrust as set by the client, 0.0f - 1.0f
	float target_thrust;
};


namespace entity
{

/// the entity registry
extern std::vector<Entity*> registry;

/// add an entity to the registry
void add(Entity *ent);

/// remove one entity from the registry
void remove(unsigned int entity_id);

/// clear the entity registry
void clear();

/// list the entity registry
void list();

/// run a game frame on each entity in the registry
void frame(float seconds);

}

}

#endif // __INCLUDED_CORE_ENTITY_H__