Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/Makefile.am4
-rw-r--r--src/core/application.cc18
-rw-r--r--src/core/core.h30
-rw-r--r--src/core/entity.cc30
-rw-r--r--src/core/entity.h91
-rw-r--r--src/core/gameinterface.cc8
-rw-r--r--src/core/gameinterface.h3
-rw-r--r--src/core/player.cc6
-rw-r--r--src/core/player.h13
9 files changed, 147 insertions, 56 deletions
diff --git a/src/core/Makefile.am b/src/core/Makefile.am
index ced2ce5..bf98501 100644
--- a/src/core/Makefile.am
+++ b/src/core/Makefile.am
@@ -1,8 +1,8 @@
METASOURCES = AUTO
INCLUDES = -I$(top_srcdir)/src
-libcore_la_SOURCES = application.cc commandbuffer.cc cvar.cc entity.cc func.cc \
- gameinterface.cc player.cc
+libcore_la_SOURCES = application.cc commandbuffer.cc core.cc cvar.cc entity.cc \
+ func.cc gameinterface.cc player.cc
libcore_la_LDFLAGS = -avoid-version -no-undefined
libcore_la_LIBADD = $(top_builddir)/src/math/libmath.la \
$(top_builddir)/src/sys/libsys.la $(top_builddir)/src/filesystem/libfilesystem.la
diff --git a/src/core/application.cc b/src/core/application.cc
index 36d1c5a..c9239cf 100644
--- a/src/core/application.cc
+++ b/src/core/application.cc
@@ -4,15 +4,20 @@
the terms of the GNU General Public License version 2
*/
+#include <errno.h>
+#include <signal.h>
+
+#include <iostream>
+#include <vector>
+#include <sstream>
+
+#include "math/mathlib.h"
#include "sys/sys.h"
#include "filesystem/filesystem.h"
-#include "core/entity.h"
#include "core/application.h"
#include "core/core.h"
-
-#include <iostream>
-#include <errno.h>
-#include <signal.h>
+#include "core/entity.h"
+#include "core/func.h"
namespace core
{
@@ -211,6 +216,8 @@ void Application::frame(float seconds)
current_time += seconds;
if (game() && game()->connected) {
+ entity::frame(seconds);
+
game()->current_time += seconds;
game()->frame(seconds);
}
@@ -220,3 +227,4 @@ void Application::frame(float seconds)
}
}
+
diff --git a/src/core/core.h b/src/core/core.h
index 0e23386..a3c5f0d 100644
--- a/src/core/core.h
+++ b/src/core/core.h
@@ -7,41 +7,31 @@
#ifndef __INCLUDED_CORE_H__
#define __INCLUDED_CORE_H__
+#include "core/entity.h"
#include "core/player.h"
#include "core/gameinterface.h"
#include "core/application.h"
+#include "core/commandbuffer.h"
+#include "core/cvar.h"
+#include "core/func.h"
/// core contains the basic functionality of the engine
namespace core
{
+
/// pointer to the current GameInterface
-inline GameInterface *game()
-{
- return GameInterface::instance();
-}
+GameInterface *game();
/// pointer to the current ApplicationInterface
-inline Application *application()
-{
- return Application::instance();
-}
+Application *application();
/// true if the core is connected to a game module
-inline bool connected()
-{
- return (GameInterface::instance() && GameInterface::instance()->connected);
-}
+bool connected();
/// return the time the core has been running, in seconds
-inline float time()
-{
- return Application::instance()->current_time;
-}
-};
+float time();
-#include "core/commandbuffer.h"
-#include "core/cvar.h"
-#include "core/func.h"
+}
#endif // __INCLUDED_CORE_H__
diff --git a/src/core/entity.cc b/src/core/entity.cc
index b0808fb..6115e71 100644
--- a/src/core/entity.cc
+++ b/src/core/entity.cc
@@ -6,6 +6,7 @@
#include "sys/sys.h"
#include "core/entity.h"
+
#include <iomanip>
namespace core
@@ -24,6 +25,7 @@ Entity::Entity(unsigned int entity_flags)
core::entity::add(this);
type = 0;
+ direction = 0;
}
Entity::~Entity()
@@ -31,19 +33,28 @@ Entity::~Entity()
// --- EntityDynamic ------------------------------------------
-EntityDynamic::EntityDynamic(unsigned int entity_flags) :
- Entity(entity_flags),
- speed(0,0,0)
+EntityDynamic::EntityDynamic(unsigned int entity_flags) :
+ Entity(entity_flags)
{
+ speed = 0.0f;
+}
+EntityDynamic::~EntityDynamic()
+{
}
// --- EntityControlable ------------------------------------------
-EntityControlable::EntityControlable(unsigned int entity_flags) :
+EntityControlable::EntityControlable(unsigned int entity_flags) :
EntityDynamic(entity_flags)
{
owner = 0;
+ target_direction = 0.0f;
+ target_thrust = 0.0f;
+}
+
+EntityControlable::~EntityControlable()
+{
}
// --- namespace entity -------------------------------------------
@@ -97,6 +108,17 @@ void list()
}
con_print << registry.size() << " registered entities" << std::endl;
}
+
+void frame(float seconds)
+{
+ std::vector<Entity *>::iterator it;
+ for (it=registry.begin(); it != registry.end(); it++) {
+ if ((*it)->core_type() == entity::Controlable) {
+ static_cast<EntityControlable *>(*it)->frame(seconds);
+ }
+ }
+}
+
}
}
diff --git a/src/core/entity.h b/src/core/entity.h
index 62b8a39..6ff3be1 100644
--- a/src/core/entity.h
+++ b/src/core/entity.h
@@ -7,9 +7,15 @@
#ifndef __INCLUDED_CORE_ENTITY_H__
#define __INCLUDED_CORE_ENTITY_H__
+namespace core
+{
+class EntityControlable;
+}
+
#include "core/core.h"
#include "core/player.h"
#include "math/mathlib.h"
+
#include <vector>
namespace core
@@ -24,7 +30,7 @@ enum Flags {Static=1, Solid=2};
/// Entity type constants
enum Type {Default = 0, Dynamic = 1, Controlable = 2};
-/// Entity shaoe constants
+/// Entity shape constants
enum Shape {Diamond=0, Sphere=1, Cube=2};
}
@@ -37,62 +43,103 @@ public:
Entity(unsigned int entity_flags = 0);
virtual ~Entity();
- /// core type of this entity
+ /**
+ * @brief core type id
+ */
virtual inline unsigned int core_type() { return entity::Default; }
- /// core shape
+ /// unique instance identifier, automaticly set
+ unsigned int id;
+
+ /// core shape id
entity::Shape core_shape;
- /// core color
+ /// core color id
math::Color core_color;
- /// core radius
+ /// core radius, in game units
float core_radius;
/// label
std::string label;
- /// custom game type of this entity
+ /// custom game type id of this entity
unsigned int type;
- /// id of the entity
- unsigned int id;
-
/// flags
unsigned int flags;
- /* updateable */
+ /* updateable by game */
/// location of the entity
math::Vector3f location;
+
+ /**
+ * @brief 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
+/**
+ * @brief 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 of this entity
+ /**
+ * @brief core type id
+ */
virtual inline unsigned int core_type() { return entity::Dynamic; }
- /* updateable */
+ /* updateable by game */
- /// speed vector, in game units / second
- math::Vector3f speed;
+ /**
+ * @brief current speed of the entity in game units per second
+ */
+ float speed;
};
-/// an entity that can be controlled by a player
+/**
+ * @brief an entity that can be controlled by a player
+ */
class EntityControlable : public EntityDynamic
{
public:
EntityControlable(unsigned int entity_flags = 0);
+ virtual ~EntityControlable();
- /// core type of this entity
+ /**
+ * @brief core type id
+ */
virtual inline unsigned int core_type() { return entity::Controlable; }
- /// owner of this controllable entity
+ /**
+ * @brief owner of this controllable entity
+ */
Player *owner;
+
+ /* updatable by client */
+
+ /**
+ * @brief the direction the client wants to travel the entity to
+ * @see direction
+ */
+ float target_direction;
+
+ /**
+ * @brief engine thrust as set by the client, 0.0f - 1.0f
+ */
+ float target_thrust;
+
+ /**
+ * @brief runs one game frame for the entity, to be implemented by game
+ */
+ virtual void frame(float seconds) = 0;
};
@@ -105,13 +152,21 @@ 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__
+
diff --git a/src/core/gameinterface.cc b/src/core/gameinterface.cc
index 26e05da..ebca24b 100644
--- a/src/core/gameinterface.cc
+++ b/src/core/gameinterface.cc
@@ -4,11 +4,13 @@
the terms of the GNU General Public License version 2
*/
-#include "core/gameinterface.h"
-
+#include <stdlib.h>
#include <iostream>
-#include <stdlib.h>
+class GameInterface;
+
+#include "core/gameinterface.h"
+#include "core/player.h"
namespace core
{
diff --git a/src/core/gameinterface.h b/src/core/gameinterface.h
index b7df479..3e2a5f7 100644
--- a/src/core/gameinterface.h
+++ b/src/core/gameinterface.h
@@ -37,6 +37,9 @@ public:
/// a player joins the game
virtual void event_join(Player *player) = 0;
+ /// a player leaves the game
+ virtual void event_leave(Player *player) = 0;
+
/// a pointer to the current game instance
static GameInterface * instance();
diff --git a/src/core/player.cc b/src/core/player.cc
index 5eae8ec..1734d9b 100644
--- a/src/core/player.cc
+++ b/src/core/player.cc
@@ -9,18 +9,20 @@
namespace core
{
+Player localplayer;
+
Player::Player()
{
id = 0;
name.clear();
dirty = false;
+
+ controled=0;
}
Player::~Player()
{
}
-Player localplayer;
-
}
diff --git a/src/core/player.h b/src/core/player.h
index e5ff396..1f63d63 100644
--- a/src/core/player.h
+++ b/src/core/player.h
@@ -1,5 +1,5 @@
/*
- core/clientstate.h
+ core/player.h
This file is part of the Osirion project and is distributed under
the terms of the GNU General Public License version 2.
*/
@@ -7,9 +7,15 @@
#ifndef __INCLUDED_CORE_PLAYER_H__
#define __INCLUDED_CORE_PLAYER_H__
-#include "core/core.h"
+namespace core
+{
+class Player;
+}
+
+#include "core/entity.h"
#include <string>
+
namespace core
{
@@ -27,6 +33,9 @@ public:
/// dirty state
bool dirty;
+
+ /// the entity the Player is currently controling
+ EntityControlable *controled;
};
extern Player localplayer;