From 421fc71813f08bfe359f9ac7596933a7e4cea6e0 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Wed, 7 May 2008 18:56:00 +0000 Subject: client-side frame interpolation: network updates, interpolation of position --- src/core/commandbuffer.cc | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) (limited to 'src/core/commandbuffer.cc') 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 +#include #include #include #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(); +} + } -- cgit v1.2.3