Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-02-18 17:52:15 +0000
committerStijn Buys <ingar@osirion.org>2008-02-18 17:52:15 +0000
commit0b8582a9aa825024edbd0a21c6287bfcccec28de (patch)
tree2d9a46c60b028300b1b9133b84764b6c39964c33 /src/core/application.cc
parent982562fa19bb87a3dab352e562f386f61c171b7b (diff)
core redesign, part II
Diffstat (limited to 'src/core/application.cc')
-rw-r--r--src/core/application.cc202
1 files changed, 44 insertions, 158 deletions
diff --git a/src/core/application.cc b/src/core/application.cc
index 5d313ad..9c7620a 100644
--- a/src/core/application.cc
+++ b/src/core/application.cc
@@ -18,17 +18,11 @@
#include "core/cvar.h"
#include "core/entity.h"
#include "core/func.h"
-#include "core/netserver.h"
+#include "core/gameserver.h"
namespace core
{
-// return the global application object
-Application *application()
-{
- return Application::instance();
-}
-
// --------------- engine functions ------------------------------
void func_print(std::string const &args)
{
@@ -61,24 +55,7 @@ void func_disconnect(std::string const &args)
application()->disconnect();
}
-// FIXME this is a game function
-void func_say(std::string const &args)
-{
- if (application()->netserver) {
- std::ostringstream osstream;
- osstream << "msg public " << Player::local.name() << " " << args << "\n";
- application()->netserver->broadcast(osstream.str());
- con_print << Player::local.name() << ": " << args << "\n";
- } else if (application()->netconnection.connected()) {
- std::ostringstream osstream;
- osstream << args << "\n";
- application()->netconnection.send(args);
- } else if (game() && game()->connected) {
- con_print << args << "\n";
- } else
- con_print << "Not connected.";
-}
-
+/*
void func_name(std::string const &args) {
std::istringstream argstream(args);
std::string name;
@@ -113,6 +90,7 @@ void func_name(std::string const &args) {
Player::local.player_name = name;
}
+*/
// --------------- signal_handler -----------------------------------
@@ -151,8 +129,8 @@ Application::Application()
}
application_instance = this;
- netserver = 0;
- gameinterface_preload = 0;
+ application_time = 0;
+ application_game = 0;
sys::signal(SIGHUP, signal_handler);
sys::signal(SIGINT, signal_handler);
@@ -163,22 +141,6 @@ Application::Application()
Application::~Application()
{
application_instance = 0;
- }
-
-Application *Application::instance()
-{
- return application_instance;
-}
-
-float Application::time() const
-{
- return game_time;
-}
-
-bool Application::connected() const
-{
- return (Application::instance()->netconnection.connected() ||
- (GameInterface::instance() && GameInterface::instance()->connected));
}
void Application::init()
@@ -190,24 +152,11 @@ void Application::init()
CommandBuffer::init();
- gameinterface_preload = core::GameInterface::gameinterface_instance;
- core::GameInterface::gameinterface_instance = 0;
- if (gameinterface_preload) {
- con_print << " preloaded game found: " << gameinterface_preload->name() << "\n";
- }
- game_time = 0;
-
- // dedicated server should set this to 1
+ // dedicated server has set this to 1
Cvar::sv_dedicated = Cvar::get("sv_dedicated", "0", Cvar::ReadOnly);
-
// client can set this to 1
Cvar::sv_private = Cvar::get("sv_private", "0");
- if (Cvar::sv_dedicated->value())
- Player::local.player_name = "Console";
- else
- Player::local.player_name = "Player0";
-
// network settings
Cvar::net_host = Cvar::get("net_host", "0.0.0.0");
Cvar::net_port = Cvar::get("net_port", "8042");
@@ -220,8 +169,7 @@ void Application::init()
Func::add("connect", func_connect);
Func::add("disconnect", func_disconnect);
- Func::add("say", func_say);
- Func::add("name", func_name);
+ //Func::add("name", func_name);
}
void Application::shutdown()
@@ -231,6 +179,11 @@ void Application::shutdown()
if (connected())
disconnect();
+ if (application_game) {
+ delete application_game;
+ application_game = 0;
+ }
+
// remove our engine functions
Func::remove("print");
Func::remove("help");
@@ -238,9 +191,7 @@ void Application::shutdown()
Func::remove("connect");
Func::remove("disconnect");
-
- Func::remove("say");
- Func::remove("name");
+ //Func::remove("name");
CommandBuffer::shutdown();
@@ -252,48 +203,22 @@ void Application::quit(int status)
sys::quit(status);
}
-// clear all game realted objects
-void Application::clear()
-{
- // remove all entities
- for (std::map<unsigned int, Entity*>::iterator it = Entity::registry.begin(); it != Entity::registry.end(); it++) {
- delete (*it).second;
- }
- Entity::registry.clear();
-
- // remove all game functions
- for (std::map<std::string, Func*>::iterator it = Func::registry.begin(); it != Func::registry.end(); it++) {
- if ( ((*it).second->flags() & Func::Game) == Func::Game) {
- delete (*it).second;
- Func::registry.erase(it);
- }
- }
-
- // remove all game cvars
- for (std::map<std::string, Cvar*>::iterator it = Cvar::registry.begin(); it != Cvar::registry.end(); it++) {
- if ( ((*it).second->flags() & Cvar::Game) == Cvar::Game) {
- delete (*it).second;
- Cvar::registry.erase(it);
- }
- }
-}
void Application::connect(std::string const &host)
{
- if (game() && game()->connected || netconnection.connected()) {
+ if (connected()) {
con_warn << "Connected. Disconnect first.\n";
return;
}
+
- if (game()) {
- // unload previous game
- if (game() != gameinterface_preload)
- delete core::GameInterface::gameinterface_instance;
+ if (application_game) {
+ delete application_game;
+ application_game = 0;
}
-
- clear();
-
+
if (host.size()) {
+ /*
// connect to remote core
core::GameInterface::gameinterface_instance = 0;
std::string remotehost(host);
@@ -316,97 +241,58 @@ void Application::connect(std::string const &host)
netconnection.disconnect();
con_warn << "Could not connect to '" << host << "'\n";
}
+ */
+ con_warn << "Can not connect to remote core.... yet!\n";
} else {
- // use preloaded game
- core::GameInterface::gameinterface_instance = gameinterface_preload;
+ application_game = new GameServer();
- // reset everything
- game_time = 0;
-
- if (game()->connected = game()->init()) {
+ if (application_game->running()) {
con_print << "Connected.\n";
} else {
+ delete application_game;
+ application_game = 0;
con_warn << "Could not connect.\n";
- return;
- }
-
- if (!netserver && (Cvar::sv_dedicated->value() || Cvar::sv_private->value())) {
- netserver = new NetServer(Cvar::net_host->str(), (unsigned int)Cvar::net_port->value());
- if (!netserver->valid()) {
- delete netserver;
- if (Cvar::sv_dedicated->value())
- shutdown();
- }
}
}
}
void Application::disconnect()
{
- if (netserver) {
- delete netserver;
- netserver = 0;
+
+ if(application_game) {
+ delete application_game;
+ application_game = 0;
+ con_print << "Disconnected.\n";
}
+ /*
if (netconnection.connected()) {
netconnection.disconnect();
con_print << "Disconnected.\n";
return;
}
-
- if (game()) {
- if (!game()->connected) {
- con_warn << "Not connected.\n";
- return;
- }
-
- game()->shutdown();
- game()->connected = false;
- game_time = 0;
-
- clear();
-
- con_print << "Disconnected.\n";
- }
+ */
}
void Application::frame(float seconds)
{
- if (seconds == 0.0f)
- return;
-
// execute commands in the buffer
CommandBuffer::exec();
- // update entities
- if (connected()) {
- std::map<unsigned int, Entity *>::iterator it;
- for (it=Entity::registry.begin(); it != Entity::registry.end(); it++) {
- Entity *entity = (*it).second;
- if ((entity->type() == Entity::Controlable) || (entity->type() == Entity::Dynamic)) {
- entity->frame(seconds);
- }
- }
- }
+ // don't run zero lenght time frames
+ if (seconds == 0.0f)
+ return;
- // netstuff
- if (netconnection.connected()) {
- netconnection.frame(seconds);
- // TODO this should come from server
- game_time += seconds;
- } else {
- if (netserver) {
- // TODO limit netserver frames in local mode
- netserver->frame(seconds);
- }
+ application_time += seconds;
- if (game() && game()->connected) {
- game_time += seconds;
+ if (!connected())
+ return;
+
+ // run a game interface frame
+ application_game->frame(seconds);
- game()->frame(seconds);
- }
- }
+ if (!application_game->running())
+ disconnect();
}
}
-