From 48aa068b036f565d6b94d4207242066ba655afe4 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sat, 9 Feb 2008 17:48:16 +0000 Subject: entities, step 1 --- src/core/Makefile.am | 6 +++--- src/core/application.cc | 31 ++++++++++++++++++--------- src/core/application.h | 2 +- src/core/clientstate.cc | 26 +++++++++++++++++++++++ src/core/clientstate.h | 29 +++++++++++++++++++++++++ src/core/core.h | 1 + src/core/entity.cc | 56 +++++++++++++++++++++++++++++++++++++++++++++++++ src/core/entity.h | 53 ++++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 190 insertions(+), 14 deletions(-) create mode 100644 src/core/clientstate.cc create mode 100644 src/core/clientstate.h create mode 100644 src/core/entity.cc create mode 100644 src/core/entity.h (limited to 'src/core') diff --git a/src/core/Makefile.am b/src/core/Makefile.am index 75a2f6c..1d330ef 100644 --- a/src/core/Makefile.am +++ b/src/core/Makefile.am @@ -1,13 +1,13 @@ METASOURCES = AUTO INCLUDES = -I$(top_srcdir)/src -libcore_la_SOURCES = application.cc commandbuffer.cc cvar.cc func.cc \ - gameinterface.cc +libcore_la_SOURCES = application.cc clientstate.cc commandbuffer.cc cvar.cc \ + entity.cc func.cc gameinterface.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 noinst_LTLIBRARIES = libcore.la -noinst_HEADERS = application.h commandbuffer.h core.h cvar.h func.h \ +noinst_HEADERS = application.h commandbuffer.h core.h cvar.h entity.h func.h \ gameinterface.h diff --git a/src/core/application.cc b/src/core/application.cc index e444b14..5979fc7 100644 --- a/src/core/application.cc +++ b/src/core/application.cc @@ -4,9 +4,11 @@ the terms of the GNU General Public License version 2 */ -#include "core/core.h" -#include "filesystem/filesystem.h" #include "sys/sys.h" +#include "filesystem/filesystem.h" +#include "core/entity.h" +#include "core/application.h" +#include "core/core.h" #include #include @@ -16,7 +18,7 @@ namespace core { // --------------- engine functions ------------------------------ -extern "C" void func_print(std::stringstream &args) +void func_print(std::stringstream &args) { char text[MAXCMDSIZE]; if (args.getline(text, MAXCMDSIZE)) { @@ -27,12 +29,12 @@ extern "C" void func_print(std::stringstream &args) } } -extern "C" void func_help(std::stringstream &args) +void func_help(std::stringstream &args) { con_print << "This is the help function" << std::endl; } -extern "C" void func_quit(std::stringstream &args) +void func_quit(std::stringstream &args) { if (Application::instance()) { Application::instance()->shutdown(); @@ -40,28 +42,32 @@ extern "C" void func_quit(std::stringstream &args) } } -extern "C" void func_connect(std::stringstream &args) +void func_connect(std::stringstream &args) { if (Application::instance()) Application::instance()->connect(); } -extern "C" void func_disconnect(std::stringstream &args) +void func_disconnect(std::stringstream &args) { if (Application::instance()) Application::instance()->disconnect(); } -extern "C" void func_list_func(std::stringstream &args) +void func_list_func(std::stringstream &args) { func::list(); } -extern "C" void func_list_var(std::stringstream &args) +void func_list_var(std::stringstream &args) { cvar::list(); } +void func_list_ent(std::stringstream &args) +{ + entity::list(); +} // --------------- signal_handler ----------------------------------- extern "C" void signal_handler(int signum) @@ -133,6 +139,7 @@ void Application::init() func::add("list_var", func_list_var); func::add("list_func", func_list_func); + func::add("list_ent", func_list_ent); if (game()) game()->connected = false; @@ -166,8 +173,10 @@ void Application::connect() if (game()->connected) { con_warn << "Connected. Disconnect first." << std::endl; } - + + entity::clear(); game()->current_time = 0; + if (game()->connected = game()->init()) { con_print << "Connected." << std::endl; } else { @@ -192,6 +201,8 @@ void Application::disconnect() game()->connected = false; game()->current_time = 0; + entity::clear(); + con_print << "Disconnected." << std::endl; } diff --git a/src/core/application.h b/src/core/application.h index 985c823..34e0a97 100644 --- a/src/core/application.h +++ b/src/core/application.h @@ -33,7 +33,7 @@ public: /// quit the application virtual void quit(int status); - /// connect to the game module + /// load the game module void connect(); /// disconnect from the game module diff --git a/src/core/clientstate.cc b/src/core/clientstate.cc new file mode 100644 index 0000000..19daab9 --- /dev/null +++ b/src/core/clientstate.cc @@ -0,0 +1,26 @@ +/* + core/clientstate.cc + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2. +*/ + +#include "core/clientstate.h" + +namespace core +{ + +ClientState::ClientState() +{ + dirty = false; + id = 0; + name.clear(); +} + +ClientState::~ClientState() +{ +} + +ClientState localstate; + +} + diff --git a/src/core/clientstate.h b/src/core/clientstate.h new file mode 100644 index 0000000..ef912ed --- /dev/null +++ b/src/core/clientstate.h @@ -0,0 +1,29 @@ +/* + core/clientstate.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_CLIENTSTATE_H__ +#define __INCLUDED_CORE_CLIENTSTATE_H__ + +#include + +namespace core +{ + +class ClientState { +public: + ClientState(); + ~ClientState(); + + std::string name; + unsigned int id; + bool dirty; +}; + +extern ClientState localstate; + +} + +#endif // __INCLUDED_CORE_CLIENTSTATE_H__ diff --git a/src/core/core.h b/src/core/core.h index 688d4c9..6a2d855 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -7,6 +7,7 @@ #ifndef __INCLUDED_CORE_H__ #define __INCLUDED_CORE_H__ +#include "core/clientstate.h" #include "core/gameinterface.h" #include "core/application.h" diff --git a/src/core/entity.cc b/src/core/entity.cc new file mode 100644 index 0000000..c8736da --- /dev/null +++ b/src/core/entity.cc @@ -0,0 +1,56 @@ +/* + core/entity.cc + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2. +*/ + +#include "sys/sys.h" +#include "core/entity.h" +#include + +namespace core +{ + +Entity::Entity(unsigned int entity_type, unsigned int entity_flags) +{ + flags = entity_flags; + type = entity_type; + core::entity::add(this); +} + +Entity::~Entity() +{ +} + +namespace entity +{ + +std::vector registry; + +void add(Entity *ent) +{ + ent->id = (unsigned int) registry.size(); + registry.push_back(ent); +} + +void clear() +{ + std::vector::iterator it; + for (it=registry.begin(); it != registry.end(); it++) { + delete (*it); + (*it) = 0; + } + registry.clear(); +} + +void list() +{ + std::vector::iterator it; + for (it=registry.begin(); it != registry.end(); it++) { + con_print << " id " << std::setw(3) << (*it)->id << " type " << std::setw(2) << (*it)->type << std::endl; + } + con_print << registry.size() << " registered entities" << std::endl; +} +} + +} diff --git a/src/core/entity.h b/src/core/entity.h new file mode 100644 index 0000000..ef9168b --- /dev/null +++ b/src/core/entity.h @@ -0,0 +1,53 @@ +/* + 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__ + +#include "math/mathlib.h" +#include + +namespace core +{ + +/// 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_type, unsigned int entity_flags=0); + virtual ~Entity(); + + /// core id of the entity + unsigned int id; + + /// location of the entity + math::Vector3f location; + + /// flags + unsigned int flags; + + /// type + unsigned int type; +}; + +namespace entity { + + /// the entity registry + extern std::vector registry; + + /// add an entity to the registry + void add(Entity *ent); + + /// clear the entity registry + void clear(); + + /// list the entity registry + void list(); +} + +} + +#endif // __INCLUDED_CORE_ENTITY_H__ -- cgit v1.2.3