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.am6
-rw-r--r--src/core/application.cc151
-rw-r--r--src/core/application.h30
-rw-r--r--src/core/commandbuffer.cc2
-rw-r--r--src/core/entity.cc2
-rw-r--r--src/core/entity.h4
-rw-r--r--src/core/net.h2
-rw-r--r--src/core/parser.cc15
-rw-r--r--src/core/parser.h3
-rw-r--r--src/core/player.cc18
-rw-r--r--src/core/player.h8
-rw-r--r--src/core/zone.cc8
-rw-r--r--src/core/zone.h9
13 files changed, 161 insertions, 97 deletions
diff --git a/src/core/Makefile.am b/src/core/Makefile.am
index 18d8185..edd62e1 100644
--- a/src/core/Makefile.am
+++ b/src/core/Makefile.am
@@ -12,5 +12,7 @@ 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 parser.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 parser.h
+
diff --git a/src/core/application.cc b/src/core/application.cc
index 09e900d..300aaa6 100644
--- a/src/core/application.cc
+++ b/src/core/application.cc
@@ -27,69 +27,7 @@
namespace core
{
-// --------------- engine functions ------------------------------
-void func_help(std::string const &args)
-{
- std::istringstream argstream(args);
- std::string topic;
- if (!(argstream >> topic))
- topic.assign("help");
-
- topic.append(".txt");
- CommandBuffer::print_file("help/" + topic);
-}
-
-void func_quit(std::string const &args)
-{
- application()->shutdown();
- application()->quit(0);
-}
-
-void func_connect(std::string const &args)
-{
- std::istringstream argstream(args);
- std::string host;
- if (!(argstream >> host))
- host.clear();
-
- application()->connect(host);
-}
-
-void func_disconnect(std::string const &args)
-{
- application()->disconnect();
-}
-
-void func_say(std::string const &args)
-{
- if (connection()) {
- connection()->say(args);
- } else if (server()) {
- server()->say(localplayer(), args);
- } else {
- con_print << "Not connected." << std::endl;
- }
-}
-
-void func_msg(std::string const &args)
-{
- if (connection()) {
- connection()->private_message(args);
- } else if (server()) {
- server()->private_message(localplayer(), args);
- } else {
- con_print << "Not connected." << std::endl;
- }
-}
-
-void func_load(std::string const &args)
-{
- std::string name(args);
- aux::to_label(name);
- application()->load(name);
-}
-
-// --------------- signal_handler -----------------------------------
+/* ---- signal handler --------------------------------------------- */
#ifndef _WIN32
extern "C" void signal_handler(int signum)
@@ -101,11 +39,11 @@ extern "C" void signal_handler(int signum)
case SIGTERM:
if (Application::instance()) {
con_warn << "Received signal " << signum << ", shutting down...\n";
- application()->shutdown();
- application()->quit(0);
+ Application::instance()->shutdown();
+ Application::instance()->quit(0);
} else {
std::cerr << "Received signal " << signum << ", terminated...\n";
- application()->quit(1);
+ Application::instance()->quit(1);
}
break;
#ifdef HAVE_CURSES
@@ -115,13 +53,13 @@ extern "C" void signal_handler(int signum)
#endif
default:
std::cerr << "Received signal " << signum << ", terminated...\n";
- application()->quit(1);
+ Application::instance()->quit(1);
break;
}
}
#endif
-// --------------- Application -----------------------------
+/* ---- class Application ------------------------------------------ */
Application *Application::application_instance = 0;
@@ -229,25 +167,25 @@ void Application::init(int count, char **arguments)
// register our engine functions
Func *func = 0;
- func = Func::add("help", func_help);
+ func = Func::add("help", Application::func_help);
func->set_info("help function");
- func = Func::add("quit", func_quit);
+ func = Func::add("quit", Application::func_quit);
func->set_info("exit the application");
- func = Func::add("load", func_load);
+ func = Func::add("load", Application::func_load);
func->set_info("[str] load a game module");
- func = Func::add("connect", func_connect);
+ func = Func::add("connect", Application::func_connect);
func->set_info("[ip] without ip, create a game");
- func = Func::add("disconnect", func_disconnect);
+ func = Func::add("disconnect", Application::func_disconnect);
func->set_info("leave the current game");
- func = Func::add("say", func_say);
+ func = Func::add("say", Application::func_say);
func->set_info("say [text] say something on the public chat");
- func = Func::add("msg", func_msg);
+ func = Func::add("msg", Application::func_msg);
func->set_info("msg [player] [text] send a private message to another player");
func = 0;
@@ -552,4 +490,67 @@ void Application::notify_remove_sound(size_t source)
// Dedicated servers don't need sounds
}
+/* -- static engine functions -------------------------------------- */
+
+void Application::func_help(std::string const &args)
+{
+ std::istringstream argstream(args);
+ std::string topic;
+ if (!(argstream >> topic))
+ topic.assign("help");
+
+ topic.append(".txt");
+ CommandBuffer::print_file("help/" + topic);
+}
+
+void Application::func_quit(std::string const &args)
+{
+ Application::instance()->shutdown();
+ Application::instance()->quit(0);
+}
+
+void Application::func_connect(std::string const &args)
+{
+ std::istringstream argstream(args);
+ std::string host;
+ if (!(argstream >> host))
+ host.clear();
+
+ Application::instance()->connect(host);
+}
+
+void Application::func_disconnect(std::string const &args)
+{
+ Application::instance()->disconnect();
+}
+
+void Application::func_say(std::string const &args)
+{
+ if (connection()) {
+ connection()->say(args);
+ } else if (server()) {
+ server()->say(localplayer(), args);
+ } else {
+ con_print << "Not connected." << std::endl;
+ }
+}
+
+void Application::func_msg(std::string const &args)
+{
+ if (connection()) {
+ connection()->private_message(args);
+ } else if (server()) {
+ server()->private_message(localplayer(), args);
+ } else {
+ con_print << "Not connected." << std::endl;
+ }
+}
+
+void Application::func_load(std::string const &args)
+{
+ std::string name(args);
+ aux::to_label(name);
+ Application::instance()->load(name);
+}
+
}
diff --git a/src/core/application.h b/src/core/application.h
index f241aa3..bb76cfe 100644
--- a/src/core/application.h
+++ b/src/core/application.h
@@ -39,7 +39,7 @@ public:
/// true if the core is connected to a running game interface
inline bool connected() const { return (application_game && application_game->running()); }
- /// return the game interface, returns 0 if the pplication is not connected to a game
+ /// return the game interface, returns 0 if the application is not connected to a game
inline GameInterface *game() { return application_game; }
/*----- mutators ------------------------------------------------- */
@@ -84,8 +84,6 @@ public:
/// remove sound source notification
virtual void notify_remove_sound(size_t source);
-/*----- static --------------------------------------------------- */
-
/// a pointer to the current application instance
static inline Application *instance() { return application_instance; }
@@ -108,23 +106,31 @@ protected:
private:
/// time the core has been running
unsigned long application_timestamp;
+
GameInterface *application_game;
+ Module *module_interactive;
+
static Application *application_instance;
- /// last loaded interactive module
- Module *module_interactive;
+ /*-- engine functions --*/
+
+ static void func_help(std::string const &args);
+ static void func_quit(std::string const &args);
+ static void func_connect(std::string const &args);
+ static void func_disconnect(std::string const &args);
+ static void func_say(std::string const &args);
+ static void func_msg(std::string const &args);
+ static void func_load(std::string const &args);
};
-/// pointer to the current Application
+/// pointer to the application
inline Application *application() { return Application::instance(); }
-/// pointer to the current GameInterface
-inline GameInterface *game() { return Application::instance()->game(); }
-
/// pointer to the console
-inline sys::ConsoleInterface *console() { return sys::ConsoleInterface::instance(); };
+inline sys::ConsoleInterface *console() { return sys::ConsoleInterface::instance(); }
-} // namespace core
+/// pointer to the game interface
+inline GameInterface *game() { return Application::instance()->game(); }
+}
#endif // __INCLUDED_CORE_APPLICATION_H__
-
diff --git a/src/core/commandbuffer.cc b/src/core/commandbuffer.cc
index d3cb4f2..71ad37f 100644
--- a/src/core/commandbuffer.cc
+++ b/src/core/commandbuffer.cc
@@ -240,7 +240,7 @@ void CommandBuffer::exec(std::string const &cmdline)
// target function
unsigned int id = 0;
if ((cmdstream >> id)) {
- con_debug << "target function " << command << " " << id << std::endl;
+ //con_debug << "target function " << command << " " << id << std::endl;
Entity *entity = Entity::find(id);
if (entity)
f->exec(game()->localplayer(), entity);
diff --git a/src/core/entity.cc b/src/core/entity.cc
index 539c8d5..9bc3f3c 100644
--- a/src/core/entity.cc
+++ b/src/core/entity.cc
@@ -83,7 +83,7 @@ void Entity::list()
con_print << entity_registry.size() << " registered entities" << std::endl;
}
-/*----- class Entity ----------------------------------------------- */
+/* ---- class Entity ----------------------------------------------- */
Entity::Entity(unsigned int flags) :
entity_location(0.0f, 0.0f, 0.0f),
diff --git a/src/core/entity.h b/src/core/entity.h
index 149419b..09b52a1 100644
--- a/src/core/entity.h
+++ b/src/core/entity.h
@@ -35,7 +35,7 @@ class Entity
{
public:
/// Entity flags
- enum Flags {Static=1, Solid=2, Bright=4, Dock=8};
+ enum Flags {Static=1, Solid=2, Bright=4, Dockable=8};
/// Entity type constants
enum Type {Default=0, Dynamic=1, Controlable=2, Globe=3};
@@ -44,7 +44,7 @@ public:
enum Shape {Diamond=0, Sphere=1, Cube=2, Axis=3};
/// EntityDynamic event state classes
- enum Event {Normal=0, NoPower=1, ImpulseInitiate=2, Impulse=3, JumpInitiate=4, Jump=5};
+ enum Event {Normal=0, NoPower=1, ImpulseInitiate=2, Impulse=3, JumpInitiate=4, Jump=5, Docked=6};
/// create a new entity and add it to the registry
Entity(unsigned int flags = 0);
diff --git a/src/core/net.h b/src/core/net.h
index 92a17c5..fe264e8 100644
--- a/src/core/net.h
+++ b/src/core/net.h
@@ -11,7 +11,7 @@ namespace core
{
/// network protocol version
-const unsigned int PROTOCOLVERSION = 12;
+const unsigned int PROTOCOLVERSION = 13;
/// maximum lenght of a (compressed) network message block
const unsigned int FRAMESIZE = 1152;
diff --git a/src/core/parser.cc b/src/core/parser.cc
index 39eb073..6af3903 100644
--- a/src/core/parser.cc
+++ b/src/core/parser.cc
@@ -10,6 +10,21 @@
namespace core {
+bool Parser::read_entity_menu(core::Entity *entity, const std::string &menufilename)
+{
+ filesystem::IniFile inifile;
+ inifile.open(menufilename);
+
+ if (!inifile.is_open()) {
+ return false;
+ }
+
+ con_debug << " " << inifile.name() << std::endl;
+
+ inifile.close();
+ return true;
+}
+
bool Parser::got_entity_key(filesystem::IniFile &inifile, core::Entity *entity)
{
std::string shapename;
diff --git a/src/core/parser.h b/src/core/parser.h
index 78a1087..fec27c4 100644
--- a/src/core/parser.h
+++ b/src/core/parser.h
@@ -18,6 +18,9 @@ class Parser {
public:
/// read default entity keys from an ini file
static bool got_entity_key(filesystem::IniFile &inifile, core::Entity *entity);
+
+ /// read entity menus
+ static bool read_entity_menu(core::Entity *entity, const std::string &menufilename);
};
}
diff --git a/src/core/player.cc b/src/core/player.cc
index 26ea070..f5f28bd 100644
--- a/src/core/player.cc
+++ b/src/core/player.cc
@@ -35,6 +35,7 @@ void Player::clear()
player_rcon = false;
player_mute = false;
player_mission_target = 0;
+ player_view = 0;
clear_assets();
player_control = 0;
@@ -46,6 +47,7 @@ void Player::set_control(EntityControlable *entitycontrolable)
if (entitycontrolable) {
set_zone(entitycontrolable->zone());
+ player_view = 0;
}
player_dirty = true;
}
@@ -58,6 +60,15 @@ void Player::set_zone(Zone *zone)
}
}
+void Player::set_view(Entity *view)
+{
+ player_view = view;
+ player_dirty = true;
+ if (player_view) {
+ set_zone(player_view->zone());
+ }
+}
+
void Player::set_mission_target(Entity *new_mission_target)
{
if (new_mission_target != player_mission_target) {
@@ -119,8 +130,9 @@ void Player::serialize_server_update(std::ostream & os) const
unsigned int zo = (zone() ? zone()->id() : 0);
unsigned int co = (player_control ? player_control->id() : 0);
unsigned int mission = (player_mission_target ? player_mission_target->id() : 0);
+ unsigned int view = (player_view ? player_view->id() : 0);
- os << player_id << " " << zo << " " << co << " " << mission << " " << player_color << " \"" << player_name << "\"";
+ os << player_id << " " << zo << " " << view << " " << co << " " << mission << " " << player_color << " \"" << player_name << "\"";
}
void Player::receive_server_update(std::istream &is)
@@ -131,6 +143,10 @@ void Player::receive_server_update(std::istream &is)
is >> zo;
set_zone(Zone::find(zo));
+ unsigned int view = 0;
+ is >> view;
+ set_view(Entity::find(view));
+
unsigned int co = 0;
is >> co;
if (co) {
diff --git a/src/core/player.h b/src/core/player.h
index c527433..44ee923 100644
--- a/src/core/player.h
+++ b/src/core/player.h
@@ -70,6 +70,9 @@ public:
/// mission target
inline Entity *mission_target() { return player_mission_target; }
+ /// view
+ inline Entity *view() { return player_view; }
+
/*----- mutators -------------------------------------------------- */
/// serialize player info to a stream
@@ -104,6 +107,8 @@ public:
void set_mission_target(Entity *new_mission_target);
+ void set_view(Entity *view);
+
inline void set_dirty() { player_dirty = true; }
/* -- should actually not be public --*/
@@ -138,6 +143,9 @@ private:
// the entity the Player is currently controling
EntityControlable *player_control;
+ // the entity the PLayer is currently looking at
+ Entity *player_view;
+
Entity *player_mission_target;
// the zone the player is currently in
diff --git a/src/core/zone.cc b/src/core/zone.cc
index 2dfc5c2..5d9c48f 100644
--- a/src/core/zone.cc
+++ b/src/core/zone.cc
@@ -118,7 +118,7 @@ void Zone ::clear()
zone_registry.clear();
}
-/* ---- The Zone class --------------------------------------------- */
+/* ---- class Zone ------------------------------------------------- */
Zone::Zone(std::string const & label) :
zone_label(label)
@@ -127,6 +127,7 @@ Zone::Zone(std::string const & label) :
zone_name.clear();
zone_sky.clear();
zone_sky_texture = 0;
+ zone_defaultview = 0;
}
Zone::Zone(std::istream & is)
@@ -197,6 +198,7 @@ void Zone::serialize_server_update(std::ostream & os) const
os << zone_label << " ";
os << "\"" << zone_name << "\" ";
os << "\"" << zone_sky << "\" ";
+ os << (zone_defaultview ? zone_defaultview->id() : 0 );
}
@@ -205,6 +207,7 @@ void Zone::receive_server_update(std::istream &is)
is >> zone_label;
std::string n;
+ unsigned int id = 0;
char c;
while ( (is.get(c)) && (c != '"'));
@@ -218,6 +221,9 @@ void Zone::receive_server_update(std::istream &is)
n += c;
zone_sky.assign(n);
n.clear();
+
+ is >> id;
+ zone_defaultview = Entity::find(id);
}
}
diff --git a/src/core/zone.h b/src/core/zone.h
index bb2074e..4b64ffb 100644
--- a/src/core/zone.h
+++ b/src/core/zone.h
@@ -71,7 +71,6 @@ public:
/// create a zone from stream data
Zone(std::istream & is);
-
/// delete a zone
~Zone();
@@ -92,6 +91,9 @@ public:
/// texture id for the sky
inline size_t sky_texture() const { return zone_sky_texture; }
+ /// default zone view
+ inline Entity *default_view() {return zone_defaultview; }
+
/// find an entity inside a zone
Entity *find_entity(Entity *entity);
@@ -115,6 +117,9 @@ public:
/// set the texture id for the sky
inline void set_sky_texture(size_t texture) { zone_sky_texture = texture; }
+ ///set the default view
+ inline void set_default_view(Entity *entity) { zone_defaultview = entity; }
+
/* ---- serializers ---------------------------------------- */
/// serialize a server-to-client update on a stream
@@ -145,6 +150,8 @@ private:
Content zone_content;
static Registry zone_registry;
+
+ Entity *zone_defaultview;
};
}