From 583ec3285c41e9d253c4aaabd2af4dadac75f3a7 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 23 Nov 2008 12:34:07 +0000 Subject: clean module consturction/destruction --- src/core/application.cc | 66 +++++++++++++++++-------------------------------- 1 file changed, 22 insertions(+), 44 deletions(-) (limited to 'src/core/application.cc') diff --git a/src/core/application.cc b/src/core/application.cc index f24f0f7..1cba59a 100644 --- a/src/core/application.cc +++ b/src/core/application.cc @@ -23,6 +23,7 @@ #include "core/func.h" #include "core/gameconnection.h" #include "core/gameserver.h" +#include "core/loader.h" namespace core { @@ -66,7 +67,7 @@ Application *Application::application_instance = 0; Application::Application() { if (application_instance) { - std::cerr << "multiple core::Application instances!\n"; + std::cerr << "multiple core::Application instances\n"; sys::quit(2); } @@ -74,8 +75,6 @@ Application::Application() application_timestamp = 0; application_game = 0; - module_interactive = 0; - #ifndef _WIN32 sys::signal(SIGHUP, signal_handler); sys::signal(SIGINT, signal_handler); @@ -97,7 +96,9 @@ void Application::init(int count, char **arguments) { con_print << "^BInitializing core...\n"; con_debug << " debug messages enabled\n"; + filesystem::init("base", ""); + Loader::load("base"); CommandBuffer::init(); @@ -210,7 +211,7 @@ void Application::shutdown() save_config(); - Module::clear(); + Loader::clear(); // remove our engine functions Func::remove("msg"); @@ -238,57 +239,34 @@ void Application::quit(int status) } -Module *Application::load(std::string const &module_label) +bool Application::load(std::string const &label) { - if (!module_label.size()) { - if (Module::active()) { - con_print << " active module: " << Module::active()->label() << " " << Module::active()->name() << std::endl; - } - if (Module::loaded()) { - con_print << " loaded module: " << Module::loaded()->label() << " " << Module::loaded()->name() << std::endl; - } - if (module_interactive) { - con_print << " fallback module: " << module_interactive->label() << " " << module_interactive->name() << std::endl; - } - std::string helpstr(" available modules:"); - for(Module::Registry::iterator it = Module::registry().begin(); it != Module::registry().end(); it++) { - helpstr += ' '; - helpstr += (*it).first; - } - con_print << helpstr << std::endl; - return 0; + if (!label.size()) { + Loader::list(); + return false; } -/* - if (Module::active() && Module::active()->interactive()) { + + if (connected() && game()->interactive()) { con_warn << "Connected. Disconnect first.\n"; - return 0; + return false; } -*/ - if (Module::loaded() && Module::loaded()->interactive()) { - module_interactive = Module::loaded(); + + if (!Loader::load(label)) { + return false; } - return Module::load(module_label.c_str()); + + return true; } void Application::connect(std::string const &host) { - if (connected()) { - if (!Module::active()->interactive()) { - if ((Module::loaded() == Module::active()) && (module_interactive)) { - disconnect(); - Module::load(module_interactive->label().c_str()); - } else { - disconnect(); - } - } else { - con_warn << "Connected. Disconnect first.\n"; - return; - } + if (connected() && game()->interactive()) { + con_warn << "Connected. Disconnect first.\n"; + return; } if (application_game) { - delete application_game; - application_game = 0; + disconnect(); } if (host.size()) { @@ -317,9 +295,9 @@ void Application::connect(std::string const &host) void Application::disconnect() { if(application_game) { - notify_disconnect(); delete application_game; application_game = 0; + notify_disconnect(); con_print << "^BDisconnected.\n"; } } -- cgit v1.2.3