From f46be446304dcb2d609fcd2648fd36d3f2fda054 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 28 Sep 2008 18:02:06 +0000 Subject: intro module groundworks --- src/core/Makefile.am | 6 ++--- src/core/entity.cc | 25 +++++++++++++++++++ src/core/entity.h | 17 +++++++++++-- src/core/netserver.h | 6 ++++- src/core/parser.cc | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/core/parser.h | 25 +++++++++++++++++++ 6 files changed, 143 insertions(+), 6 deletions(-) create mode 100644 src/core/parser.cc create mode 100644 src/core/parser.h (limited to 'src/core') diff --git a/src/core/Makefile.am b/src/core/Makefile.am index 8c44d13..18d8185 100644 --- a/src/core/Makefile.am +++ b/src/core/Makefile.am @@ -3,8 +3,8 @@ INCLUDES = -I$(top_srcdir)/src libcore_la_SOURCES = application.cc clientstate.cc commandbuffer.cc core.cc \ cvar.cc entity.cc func.cc gameconnection.cc gameinterface.cc gameserver.cc \ - module.cc netclient.cc netconnection.cc netserver.cc player.cc stats.cc timer.cc \ - zone.cc + module.cc netclient.cc netconnection.cc netserver.cc parser.cc player.cc stats.cc \ + timer.cc zone.cc libcore_la_LDFLAGS = -avoid-version -no-undefined libcore_la_LIBADD = $(top_builddir)/src/model/libmodel.la \ $(top_builddir)/src/filesystem/libfilesystem.la $(top_builddir)/src/math/libmath.la $(top_builddir)/src/sys/libsys.la \ @@ -13,4 +13,4 @@ libcore_la_LIBADD = $(top_builddir)/src/model/libmodel.la \ noinst_LTLIBRARIES = libcore.la noinst_HEADERS = application.h clientstate.h commandbuffer.h core.h cvar.h \ entity.h func.h gameconnection.h gameinterface.h gameserver.h message.h module.h net.h \ - netclient.h netconnection.h netserver.h player.h range.h stats.h timer.h + netclient.h netconnection.h netserver.h player.h range.h stats.h timer.h parser.h diff --git a/src/core/entity.cc b/src/core/entity.cc index bed17fb..e74b8b5 100644 --- a/src/core/entity.cc +++ b/src/core/entity.cc @@ -7,6 +7,7 @@ #include #include +#include "auxiliary/functions.h" #include "sys/sys.h" #include "core/entity.h" #include "core/cvar.h" @@ -170,6 +171,30 @@ void Entity::set_zone(Zone *zone) entity_zone->add(this); } +void Entity::set_label(char const *label) +{ + entity_label.assign(label); + aux::to_label(entity_label); +} + +void Entity::set_label(std::string const &label) +{ + entity_label.assign(label); + aux::to_label(entity_label); +} + +void Entity::set_name(char const *name) +{ + entity_name.assign(name); + aux::strip_quotes(entity_name); +} + +void Entity::set_name(std::string const &name) +{ + entity_name.assign(name); + aux::strip_quotes(entity_name); +} + void Entity::serialize_server_create(std::ostream & os) const { os << entity_moduletypeid << " " diff --git a/src/core/entity.h b/src/core/entity.h index c988143..4861b07 100644 --- a/src/core/entity.h +++ b/src/core/entity.h @@ -155,6 +155,18 @@ public: */ virtual void set_zone(Zone *zone); + /// set the label + void set_label(char const *label); + + /// set the label + void set_label(std::string const &label); + + /// set the name + void set_name(char const *name); + + /// set the name + void set_name(std::string const &name); + /// clear all update flags virtual void clear_updates(); @@ -183,8 +195,6 @@ public: math::Axis entity_axis; float entity_radius; - std::string entity_name; - std::string entity_label; std::string entity_modelname; model::Model *entity_model; Shape entity_shape; @@ -210,6 +220,9 @@ protected: bool entity_serverside; + std::string entity_name; + std::string entity_label; + private: // add an entity to the registry static void add(Entity *ent); diff --git a/src/core/netserver.h b/src/core/netserver.h index 4dcae69..1d2e131 100644 --- a/src/core/netserver.h +++ b/src/core/netserver.h @@ -23,13 +23,17 @@ namespace core { -/// Network server +/// network server class NetServer { public: + /// type definition for a list of network clients typedef std::list Clients; + /// create a new network server, listening on host:port NetServer(std::string const host, unsigned int const port); + + /// disconnect clients and shutdown the network server ~NetServer(); /*----- inspectors ------------------------------------------------ */ diff --git a/src/core/parser.cc b/src/core/parser.cc new file mode 100644 index 0000000..99dc1d5 --- /dev/null +++ b/src/core/parser.cc @@ -0,0 +1,70 @@ +/* + core/parser.h + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 +*/ + +#include "core/parser.h" +#include "auxiliary/functions.h" +#include "sys/sys.h" + +namespace core { + +bool Parser::got_entity_key(filesystem::IniFile &inifile, core::Entity *entity) +{ + std::string shapename; + std::string strval; + float direction; + float pitch; + float roll; + + if (inifile.got_key_string("shape", shapename)) { + + if (shapename.compare("axis") == 0) { + entity->entity_shape = core::Entity::Axis; + return true; + } else if (shapename.compare("cube") == 0) { + entity->entity_shape = core::Entity::Cube; + return true; + } else if (shapename.compare("diamond") == 0) { + entity->entity_shape = core::Entity::Diamond; + return true; + } else if (shapename.compare("sphere") == 0) { + entity->entity_shape = core::Entity::Sphere; + return true; + } else { + con_warn << inifile.name() << " unknown shape '" << shapename << "' at line " << inifile.line() << std::endl; + return false; + } + + } else if (inifile.got_key_string("label", strval)) { + entity->set_label(strval); + return true; + } else if (inifile.got_key_string("name", strval)) { + entity->set_name(strval); + return true; + } else if (inifile.got_key_string("model", entity->entity_modelname)) { + return true; + } else if (inifile.got_key_angle("direction", direction)) { + entity->axis().change_direction(direction); + return true; + } else if (inifile.got_key_angle("pitch", pitch)) { + entity->axis().change_pitch(pitch); + return true; + } else if (inifile.got_key_angle("roll", roll)) { + entity->axis().change_roll(roll); + return true; + } else if (inifile.got_key_angle("radius", entity->entity_radius)) { + return true; + } else if (inifile.got_key_vector3f("location", entity->entity_location)) { + return true; + } else if (inifile.got_key_color("color", entity->entity_color)) { + return true; + } else if (inifile.got_key_color("colorsecond", entity->entity_color_second)) { + return true; + } + + return false; +} + +} diff --git a/src/core/parser.h b/src/core/parser.h new file mode 100644 index 0000000..4f7b843 --- /dev/null +++ b/src/core/parser.h @@ -0,0 +1,25 @@ +/* + core/parser.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_PARSER_H__ +#define __INCLUDED_CORE_PARSER_H__ + + +#include "filesystem/inifile.h" +#include "core/entity.h" + +namespace core { + +/// general parser routines +class Parser { +public: + /// read default entity keys from an ini file + static bool got_entity_key(filesystem::IniFile &inifile, core::Entity *entity); +}; + +} + +#endif // __INCLUDED_CORE_PARSER_H__ \ No newline at end of file -- cgit v1.2.3