diff options
-rw-r--r-- | INSTALL | 4 | ||||
-rw-r--r-- | osirion.kdevelop.pcs | bin | 520260 -> 456490 bytes | |||
-rw-r--r-- | osirion.kdevses | 23 | ||||
-rw-r--r-- | src/client/client.cc | 4 | ||||
-rw-r--r-- | src/core/application.cc | 49 | ||||
-rw-r--r-- | src/core/application.h | 6 | ||||
-rw-r--r-- | src/core/commandbuffer.cc | 38 | ||||
-rw-r--r-- | src/core/func.cc | 6 |
8 files changed, 108 insertions, 22 deletions
@@ -32,7 +32,7 @@ Compiling the source code At present, 'make install' is neither tested nor supported. -Game Data +Installing game data The game data should be located in the 'data' subdirectory of the main distribution. @@ -66,7 +66,7 @@ Updating Rebuild the game: - autoreconf + autoreconf -fi ./configure make diff --git a/osirion.kdevelop.pcs b/osirion.kdevelop.pcs Binary files differindex a21a08c..d218712 100644 --- a/osirion.kdevelop.pcs +++ b/osirion.kdevelop.pcs diff --git a/osirion.kdevses b/osirion.kdevses index 52484c5..98b982a 100644 --- a/osirion.kdevses +++ b/osirion.kdevses @@ -1,16 +1,25 @@ <?xml version = '1.0' encoding = 'UTF-8'?> <!DOCTYPE KDevPrjSession> <KDevPrjSession> - <DocsAndViews NumberOfDocuments="3" > - <Doc0 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/core/netserver.cc" > - <View0 Encoding="" line="0" Type="Source" /> + <DocsAndViews NumberOfDocuments="6" > + <Doc0 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/client/console.cc" > + <View0 Encoding="" line="296" Type="Source" /> </Doc0> - <Doc1 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/core/entity.cc" > - <View0 Encoding="" line="289" Type="Source" /> + <Doc1 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/core/application.cc" > + <View0 Encoding="" line="145" Type="Source" /> </Doc1> - <Doc2 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/core/gameserver.cc" > - <View0 Encoding="" line="0" Type="Source" /> + <Doc2 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/core/cvar.cc" > + <View0 Encoding="" line="146" Type="Source" /> </Doc2> + <Doc3 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/core/application.h" > + <View0 Encoding="" line="67" Type="Source" /> + </Doc3> + <Doc4 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/core/commandbuffer.cc" > + <View0 Encoding="" line="73" Type="Source" /> + </Doc4> + <Doc5 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/client/client.cc" > + <View0 Encoding="" line="91" Type="Source" /> + </Doc5> </DocsAndViews> <pluginList> <kdevdebugger> diff --git a/src/client/client.cc b/src/client/client.cc index 4874e55..f232c12 100644 --- a/src/client/client.cc +++ b/src/client/client.cc @@ -88,8 +88,8 @@ void Client::init() core::Application::init(); // client variables - core::Cvar::get("cl_name", "Player"); - core::Cvar::get("cl_color", "1.0 1.0 1.0"); + core::Cvar::get("cl_name", "Player", core::Cvar::Archive); + core::Cvar::get("cl_color", "1.0 1.0 1.0", core::Cvar::Archive); // initialize SDL, but do not initialize any subsystems SDL_Init(0); diff --git a/src/core/application.cc b/src/core/application.cc index b55df34..7d6f62a 100644 --- a/src/core/application.cc +++ b/src/core/application.cc @@ -10,6 +10,7 @@ #include <iostream> #include <vector> #include <sstream> +#include <fstream> #include "sys/sys.h" #include "math/mathlib.h" @@ -152,11 +153,15 @@ void Application::init() filesystem::init(); CommandBuffer::init(); - // 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"); + + // load save cvars + load_config(); + + // framerate settings Cvar::sv_framerate = Cvar::get("sv_framerate", "25"); // network settings @@ -186,6 +191,8 @@ void Application::shutdown() application_game = 0; } + save_config(); + // remove our engine functions Func::remove("print"); Func::remove("help"); @@ -272,4 +279,44 @@ void Application::frame(float seconds) disconnect(); } +void Application::save_config() +{ + std::string filename(filesystem::writedir); + filename.append("config.txt"); + std::ofstream ofs(filename.c_str()); + + if (!ofs.is_open()) { + con_warn << "Could not write " << filename << std::endl; + return; + } + + std::map<std::string, Cvar*>::iterator it; + for (it = Cvar::registry.begin(); it != Cvar::registry.end(); it++) { + + if (((*it).second->flags() & Cvar::Archive) == Cvar::Archive) + ofs << "set " << (*it).first << " " << (*it).second->str() << std::endl; + } + ofs.close(); +} + +void Application::load_config() +{ + std::string filename(filesystem::writedir); + filename.append("config.txt"); + std::ifstream ifs(filename.c_str(), std::ifstream::in); + + if (!ifs.is_open()) { + con_warn << "Could not read " << filename << std::endl; + return; + } + + char line[MAXCMDSIZE]; + while (ifs.getline(line, MAXCMDSIZE-1)) { + cmd() << line << "\n"; + + } + + // execute commands in the buffer + CommandBuffer::exec(); +} } diff --git a/src/core/application.h b/src/core/application.h index de0ab35..f0f03b5 100644 --- a/src/core/application.h +++ b/src/core/application.h @@ -64,6 +64,12 @@ protected: /// run a core frame virtual void frame(float seconds); + /// load cvar config + void load_config(); + + /// save cvar config + void save_config(); + private: /// time the core has been running float application_time; diff --git a/src/core/commandbuffer.cc b/src/core/commandbuffer.cc index 831489f..2cf8d26 100644 --- a/src/core/commandbuffer.cc +++ b/src/core/commandbuffer.cc @@ -18,36 +18,60 @@ namespace core { -void func_list_func(std::istringstream const &args) +void func_list_func(std::string const &args) { Func::list(); } -void func_list_var(std::istringstream const &args) +void func_list_var(std::string const &args) { Cvar::list(); } -void func_list_ent(std::istringstream const &args) +void func_list_ent(std::string const &args) { Entity::list(); } +void func_set(std::string const &args) +{ + std::istringstream argstream(args); + std::string varname; + if (!(argstream >> varname)) + return; + + // we're setting a new value + std::string value; + if (!(argstream >> value)) + return; + + char c; + while (argstream.get(c)) + value += c; + + Cvar *cvar = Cvar::set(varname.c_str(), value.c_str(), Cvar::Archive); + + con_print << cvar->name() << " " << cvar->str() << "\n"; + return; +} + std::stringstream CommandBuffer::cmdbuf(std::stringstream::in | std::stringstream::out); void CommandBuffer::init() { - con_debug << "Initializing command buffer...\n"; + //con_debug << "Initializing command buffer...\n"; - Func::add("list_var", (FuncPtr)func_list_var); - Func::add("list_func", (FuncPtr)func_list_func); Func::add("list_ent", (FuncPtr)func_list_ent); + Func::add("list_func", (FuncPtr)func_list_func); + Func::add("list_var", (FuncPtr)func_list_var); + Func::add("set", (FuncPtr)func_set); } void CommandBuffer::shutdown() { - con_debug << "Shutting down command buffer...\n"; + //con_debug << "Shutting down command buffer...\n"; + Func::remove("set"); Func::remove("list_var"); Func::remove("list_func"); Func::remove("list_ent"); diff --git a/src/core/func.cc b/src/core/func.cc index afe4787..4db8dcf 100644 --- a/src/core/func.cc +++ b/src/core/func.cc @@ -33,7 +33,7 @@ void Func::add(const char *name, GameFuncPtr gamefunctionptr, unsigned int flags std::map<std::string, Func*>::iterator it = registry.find(name); if (it == registry.end()) { registry[std::string(name)] = new Func(name, (void *)gamefunctionptr, flags | Func::Game); - con_debug << "Function '" << name << "' registered." << std::endl; + //con_debug << "Function '" << name << "' registered." << std::endl; } else { con_warn << "Function '" << name << "' already registered!" << std::endl; } @@ -45,7 +45,7 @@ void Func::remove(const char *name) if (it != registry.end()) { delete (*it).second; registry.erase(it); - con_debug << "Function '" << name << "' unregistered." << std::endl; + //con_debug << "Function '" << name << "' unregistered." << std::endl; } } @@ -55,7 +55,7 @@ void Func::remove(const std::string &name) if (it != registry.end()) { delete (*it).second; registry.erase(it); - con_debug << "Function '" << name << "' unregistered." << std::endl; + //con_debug << "Function '" << name << "' unregistered." << std::endl; } } |