diff --git a/game/main.cpp b/game/main.cpp index 946b8e0..d28c5e6 100644 --- a/game/main.cpp +++ b/game/main.cpp @@ -14,13 +14,10 @@ uint64_t optionsFlags; using asio::ip::tcp; -using namespace std; - -int main(int argc, char *argv[]) { - - +int main(int argc, char *argv[]) +{ + bool devMode = false; char port[]="3490"; - char c; static struct option long_options[] = { @@ -35,13 +32,14 @@ int main(int argc, char *argv[]) { {"autorun", required_argument, 0, 'a'}, {"port", required_argument, 0, 'p'}, {"fps", no_argument, 0, 'f'}, + {"dev", no_argument, 0, 'd'}, {0, 0, 0, 0} }; int option_index = 0; while(1){ - c = getopt_long (argc, argv, "p:fa", + char c = getopt_long (argc, argv, "p:fad", long_options, &option_index); if (c == -1) break; @@ -51,6 +49,11 @@ int main(int argc, char *argv[]) { case 'f': SET_FLAG(SHOW_FPS,true); break; + case 'd': + std::cout<<"enabling developer mode" << std::endl; + devMode = true; + break; + case 'p': strcpy(port,optarg); break; @@ -69,6 +72,7 @@ int main(int argc, char *argv[]) { } Game game; + game.state()->setDeveloperMode(devMode); asio::io_service io_service; Server s(io_service, game.state(), atoi(port) ); diff --git a/game/network/session.cpp b/game/network/session.cpp index e8727e8..f44d3e6 100644 --- a/game/network/session.cpp +++ b/game/network/session.cpp @@ -6,12 +6,37 @@ #include -using namespace std; +#include -bool Session::parse(string s) +void trim(std::string &str) { - s.erase(std::find_if(s.rbegin(), s.rend(), - std::not1(std::ptr_fun(std::isspace))).base(), s.end()); + const std::string ws = " \t\r\n"; + size_t endpos = str.find_last_not_of(ws); + if (endpos != std::string::npos) { + str = str.substr(0, endpos+1); + } + + // trim leading spaces + size_t startpos = str.find_first_not_of(ws); + if (startpos != std::string::npos) { + str = str.substr(startpos); + } +} + +bool Session::parse(std::string s) +{ + // strip leading/trailing whitespace/newlines as they are always unintional + trim(s); + + std::istringstream iss(s); + + std::string token; + iss >> token; + + // skip token + next whitespace + std::string rest = s.substr(std::min(s.size(), token.size()+1)); + + //std::cout<<"[session] token='" << token << "' rest='" << rest << "'" << std::endl; // TODO: // from knoc: @@ -23,21 +48,29 @@ bool Session::parse(string s) m_socket.close(); m_state->quitPlayer(m_pid); return false; + } else if (s.size()==1&&s[0]=='c') { //clear m_state->clear(m_pid); + } else if (s.size()>=3&&s[0]=='n'&&s[1]==' ') { //set name m_state->setName(m_pid, s.substr(2)); + } else if (s.size()>=3&&s[0]=='v'&&s[1]==' ') { //set speed double speed = atof(s.substr(2).c_str()); m_state->setSpeed(m_pid, speed); + + } else if (token == "dev") { + m_state->commandForPlayer(m_pid, new game::DeveloperCommand(rest)); + } else { //shoot double angle = atof(s.c_str()); m_state->commandForPlayer(m_pid, new game::ShootCommand(angle)); } + return true; } diff --git a/game/renderer_polygon_3d/polygon_model.cpp b/game/renderer_polygon_3d/polygon_model.cpp index 3bc1347..0bb6f55 100644 --- a/game/renderer_polygon_3d/polygon_model.cpp +++ b/game/renderer_polygon_3d/polygon_model.cpp @@ -25,7 +25,7 @@ namespace endofthejedi { return; } - std::cout<<"program: " << shader->program() << std::endl; + //std::cout<<"program: " << shader->program() << std::endl; m_shader = shader; @@ -50,9 +50,9 @@ namespace endofthejedi { << "') is invalid!" << std::endl; } else { - std::cout<<"[polygonmodel] attribute location #" - << i << " (for '" << name - << "') is " << m_attr_locations[i] << std::endl; + //std::cout<<"[polygonmodel] attribute location #" + // << i << " (for '" << name + // << "') is " << m_attr_locations[i] << std::endl; } } } diff --git a/game/state/player.hpp b/game/state/player.hpp index 06fa8d4..af58142 100644 --- a/game/state/player.hpp +++ b/game/state/player.hpp @@ -23,7 +23,7 @@ namespace game { std::string name; std::list missiles; - Player(int id) : id(id), alive(true), speed(0.01), energy(0.0), ship(nullptr), name("") + Player(int id) : id(id), alive(true), speed(1.0), energy(0.0), ship(nullptr), name("") { } diff --git a/game/state/state.cpp b/game/state/state.cpp index 74df578..e0412c7 100644 --- a/game/state/state.cpp +++ b/game/state/state.cpp @@ -184,10 +184,10 @@ namespace game { void State::advancePlayerMissiles(float dt) { - std::vector rm; - // advance missiles for (Player *player : players) { + + std::vector rm; for (Missile *missile : player->missiles) { //std::cout<<"missile: " << (long unsigned int) missile << std::endl; @@ -339,8 +339,6 @@ namespace game { void State::deleteTrace(Trace *trace) { - traces.remove(trace); - if (trace->missile != nullptr) { // delete backlink. // XXX: there's a missile without a trace now. @@ -373,7 +371,7 @@ namespace game { for (Trace *trace : rm) { traces.remove(trace); - delete(trace); + deleteTrace(trace); } } } diff --git a/test/100players..py b/test/100players..py new file mode 100755 index 0000000..a9cab5e --- /dev/null +++ b/test/100players..py @@ -0,0 +1,9 @@ +#!/usr/bin/env python3 +import os +import random + +for i in range(100): + a = random.randint(0, 360) + print("spawn #%d +shoot %d" % (i, a)) + os.system("echo %d | ncat 192.168.0.191 3490" % a) +