diff options
author | Stijn Buys <ingar@osirion.org> | 2008-05-07 18:56:00 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2008-05-07 18:56:00 +0000 |
commit | 421fc71813f08bfe359f9ac7596933a7e4cea6e0 (patch) | |
tree | 15b3630488281280d6634804b4a1a41fc402ab0a /src/core/commandbuffer.cc | |
parent | 91d3a0352088611d3b78d3344b7a2bf2d4955a0a (diff) |
client-side frame interpolation: network updates, interpolation of position
Diffstat (limited to 'src/core/commandbuffer.cc')
-rw-r--r-- | src/core/commandbuffer.cc | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/src/core/commandbuffer.cc b/src/core/commandbuffer.cc index ead2a98..56aba16 100644 --- a/src/core/commandbuffer.cc +++ b/src/core/commandbuffer.cc @@ -5,10 +5,12 @@ */ #include <string> +#include <fstream> #include <sstream> #include <list> #include "sys/sys.h" +#include "filesystem/filesystem.h" #include "core/application.h" #include "core/commandbuffer.h" #include "core/gameconnection.h" @@ -59,6 +61,16 @@ void func_set(std::string const &args) return; } +void func_exec(std::string const &args) +{ + std::istringstream argstream(args); + std::string filename; + if (!(argstream >> filename)) + return; + + CommandBuffer::exec_file(filename); +} + std::stringstream CommandBuffer::cmdbuf(std::stringstream::in | std::stringstream::out); void CommandBuffer::init() @@ -77,6 +89,9 @@ void CommandBuffer::init() func = Func::add("set", (FuncPtr)func_set); func->set_info("[variable] [str] set variable value"); + + func = Func::add("exec", (FuncPtr)exec); + func->set_info("[filename] execute commands from file"); } void CommandBuffer::shutdown() @@ -142,7 +157,7 @@ void CommandBuffer::exec(std::string const &cmdline) return; } - // TODO this must get forwarded to the server + // this gets forwarded to the server if (connection()) connection()->forward(cmdline); else @@ -219,5 +234,33 @@ void CommandBuffer::complete(std::string &input, size_t &pos) } +void CommandBuffer::exec_file(std::string const & filename) +{ + filesystem::File *f = filesystem::open(filename.c_str()); + if (!f) { + con_warn << "Could not open " << filename << std::endl; + return; + } + + std::string fn = f->path(); + fn.append(f->name()); + filesystem::close(f); + + std::ifstream ifs; + ifs.open(fn.c_str()); + if (!ifs.is_open()) { + con_warn << "Could not stream " << fn << "!\n"; + return; + } + + char line[MAXCMDSIZE]; + while (ifs.getline(line, MAXCMDSIZE-1)) { + if (line[0] && line[0] != '#' && line[0] != ';') + exec(std::string(line)); + } + + ifs.close(); +} + } |