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/application.cc49
-rw-r--r--src/core/application.h6
-rw-r--r--src/core/commandbuffer.cc38
-rw-r--r--src/core/func.cc6
4 files changed, 88 insertions, 11 deletions
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;
}
}