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-17 18:59:52 +0000
committerStijn Buys <ingar@osirion.org>2008-02-17 18:59:52 +0000
commit982562fa19bb87a3dab352e562f386f61c171b7b (patch)
treeaeade8d5b7d3c68f5c222af1d8ecc6a734e1b43f /src/core/commandbuffer.cc
parentd198b7b8d9ff713d891f35ab173d1f428f610e7d (diff)
major rewrite of Cvar, Func and Entity
Diffstat (limited to 'src/core/commandbuffer.cc')
-rw-r--r--src/core/commandbuffer.cc129
1 files changed, 81 insertions, 48 deletions
diff --git a/src/core/commandbuffer.cc b/src/core/commandbuffer.cc
index a15708c..8f02f71 100644
--- a/src/core/commandbuffer.cc
+++ b/src/core/commandbuffer.cc
@@ -4,88 +4,123 @@
the terms of the GNU General Public License version 2
*/
-#include "core/commandbuffer.h"
-#include "sys/sys.h"
-
-// C++ headers
#include <string>
#include <sstream>
#include <list>
+#include "sys/sys.h"
+#include "core/commandbuffer.h"
+#include "core/func.h"
+#include "core/cvar.h"
+#include "core/gameinterface.h"
+
namespace core
{
-std::stringstream cmd(std::stringstream::in | std::stringstream::out);
+void func_list_func(std::istringstream const &args)
+{
+ Func::list();
+}
+
+void func_list_var(std::istringstream const &args)
+{
+ Cvar::list();
+}
+
+void func_list_ent(std::istringstream const &args)
+{
+ Entity::list();
+}
+
+std::stringstream CommandBuffer::cmdbuf(std::stringstream::in | std::stringstream::out);
+
+void CommandBuffer::init()
+{
+ 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);
+}
-namespace commandbuffer
+void CommandBuffer::shutdown()
{
+ con_debug << "Shutting down command buffer...\n";
-void exec(const char *text)
+ Func::remove("list_var");
+ Func::remove("list_func");
+ Func::remove("list_ent");
+}
+
+void CommandBuffer::exec(std::string const &cmdline)
{
- std::stringstream cmdstream(text);
+ if (!cmdline.size())
+ return;
+
+ std::istringstream cmdstream(cmdline);
std::string command;
if (!(cmdstream >> command))
return;
+ con_debug << "Executing '" << cmdline << "'\n";
+
// is it a function
- Func f = func::find(command);
+ Func *f = Func::find(command);
if (f) {
- // function exists, execute it
- if (f->flags() && func::Game) {
- // it's a game function
+ std::string args;
+ char c;
+ if (cmdstream >> args) {
+ while (cmdstream >> c)
+ args += c;
+ }
+ if ((f->flags() & Func::Game)) {
if (game() && game()->connected) {
- GameFuncPtr function = (GameFuncPtr) f->ptr;
- function(localplayer, cmdstream);
+ f->exec(&Player::local, args);
}
} else {
- // it's a normal function
- FuncPtr function = (FuncPtr) f->ptr;
- function(cmdstream);
+ f->exec(args);
}
return;
}
// is it a cvar
- Cvar cv = cvar::find(command);
- if (cv) {
+ Cvar *cvar = Cvar::find(command);
+ if (cvar) {
// cvar exists
- std::string args;
- if (((cv->flags() & cvar::ReadOnly) == 0) && (cmdstream >> args)) {
+ std::string value;
+ if (((cvar->flags() & Cvar::ReadOnly) == 0) && (cmdstream >> value)) {
// we're setting a new value
char c;
while (cmdstream >> c)
- args += c;
- (*cv) = args;
+ value += c;
+ (*cvar) = value;
}
- con_print << command << " " << cv->text() << std::endl;
+ con_print << command << " " << cvar->str() << "\n";
return;
}
- con_print << "Unknown command '" << command << "'" << std::endl;
+ // TODO this must get forwarded to the server
+
+ con_print << "Unknown command '" << command << "'\n";
}
-void execute()
+void CommandBuffer::exec()
{
- if (core::cmd.eof())
+ if (cmdbuf.eof())
return;
char line[MAXCMDSIZE];
- while (core::cmd.getline(line, MAXCMDSIZE-1)) {
- exec(line);
+
+ while (core::cmd().getline(line, MAXCMDSIZE-1)) {
+ exec(std::string(line));
}
- cmd.clear();
+ cmdbuf.clear();
}
-void clear()
-{
- char line[MAXCMDSIZE];
- while (core::cmd.getline(line, MAXCMDSIZE-1));
-}
-
-void complete(std::string &input, size_t &pos)
+void CommandBuffer::complete(std::string &input, size_t &pos)
{
std::list<std::string> match;
@@ -94,20 +129,20 @@ void complete(std::string &input, size_t &pos)
return;
// search function registry for matches
- std::map<std::string, Func>::iterator f;
- for (f = func::registry.begin(); f != func::registry.end(); f++) {
+ std::map<std::string, Func *>::iterator f;
+ for (f = Func::registry.begin(); f != Func::registry.end(); f++) {
if (partial == (*f).first.substr(0, partial.size())) {
match.push_back((*f).first);
- //con_print << " " << (*f).first << std::endl;
+ //con_print << " " << (*f).first << "\n";
}
}
// search cvar registry for matches
- std::map<std::string, Cvar>::iterator c;
- for (c = cvar::registry.begin(); c != cvar::registry.end(); c++) {
+ std::map<std::string, Cvar *>::iterator c;
+ for (c = Cvar::registry.begin(); c != Cvar::registry.end(); c++) {
if (partial == (*c).first.substr(0, partial.size())) {
match.push_back((*c).first);
- //con_print << " " << (*c).first << std::endl;
+ //con_print << " " << (*c).first << "\n";
}
}
@@ -127,9 +162,9 @@ void complete(std::string &input, size_t &pos)
if (i < maxmatch.size())
maxmatch.erase(i);
}
- con_print << " " << (*l) << std::endl;
+ con_print << " " << (*l) << "\n";
}
- con_print << match.size() << " matches" << std::endl;
+ con_print << match.size() << " matches\n";
}
@@ -141,7 +176,5 @@ void complete(std::string &input, size_t &pos)
}
-} // namespace commandbuffer
-
-} // namespace core
+}