added switch for developer mode and fixed crash with removing missiles

This commit is contained in:
Andreas Ortmann 2016-09-30 19:03:22 +02:00
parent b5efac002e
commit 5a4e6aaaed
6 changed files with 65 additions and 21 deletions

View file

@ -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) );

View file

@ -6,12 +6,37 @@
#include <iostream>
using namespace std;
#include <sstream>
bool Session::parse(string s)
void trim(std::string &str)
{
s.erase(std::find_if(s.rbegin(), s.rend(),
std::not1(std::ptr_fun<int, int>(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;
}

View file

@ -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;
}
}
}

View file

@ -23,7 +23,7 @@ namespace game {
std::string name;
std::list<Missile*> missiles;
Player(int id) : id(id), alive(true), speed(0.01), energy(0.0), ship(nullptr), name("<unnamed>")
Player(int id) : id(id), alive(true), speed(1.0), energy(0.0), ship(nullptr), name("<unnamed>")
{
}

View file

@ -184,10 +184,10 @@ namespace game {
void State::advancePlayerMissiles(float dt)
{
std::vector<Missile*> rm;
// advance missiles
for (Player *player : players) {
std::vector<Missile*> 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);
}
}
}

9
test/100players..py Executable file
View file

@ -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)