added flag for autorun.
This commit is contained in:
parent
a92d3d2120
commit
eb3c0f5cd4
3 changed files with 45 additions and 40 deletions
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
//#define QUICK_TEST
|
#include "options.hpp"
|
||||||
|
|
||||||
Game::Game()
|
Game::Game()
|
||||||
{
|
{
|
||||||
|
@ -19,49 +19,49 @@ Game::Game()
|
||||||
|
|
||||||
// XXX
|
// XXX
|
||||||
// one dummy ship for testing
|
// one dummy ship for testing
|
||||||
#ifdef QUICK_TEST
|
if (ISSET_FLAG(TEST_AUTORUN)) {
|
||||||
m_state->addPlayer();
|
m_state->addPlayer();
|
||||||
#endif
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Game::cycle(float dt)
|
bool Game::cycle(float dt)
|
||||||
{
|
{
|
||||||
#ifdef QUICK_TEST
|
if (ISSET_FLAG(TEST_AUTORUN)) {
|
||||||
// XXX the following is just testing code to do things
|
// XXX the following is just testing code to do things
|
||||||
|
|
||||||
static float total = 0.0;
|
static float total = 0.0;
|
||||||
static float acc = 0.0;
|
static float acc = 0.0;
|
||||||
|
|
||||||
//if (total == 0.0) {
|
//if (total == 0.0) {
|
||||||
// float speed = 0.005;
|
// float speed = 0.005;
|
||||||
// m_state->players[0]->addCommand(new game::SetSpeedCommand(speed));
|
// m_state->players[0]->addCommand(new game::SetSpeedCommand(speed));
|
||||||
// for (int i=0; i<100; i++) {
|
// for (int i=0; i<100; i++) {
|
||||||
// float a = 2.0 * M_PI * util::randf_0_1();
|
// float a = 2.0 * M_PI * util::randf_0_1();
|
||||||
// m_state->players[0]->addCommand(new game::ShootCommand(a));
|
// m_state->players[0]->addCommand(new game::ShootCommand(a));
|
||||||
// }
|
// }
|
||||||
//}
|
|
||||||
|
|
||||||
acc += dt;
|
|
||||||
total += dt;
|
|
||||||
|
|
||||||
float spawnInterval = 0.1;
|
|
||||||
while (acc > spawnInterval) {
|
|
||||||
acc -= spawnInterval;
|
|
||||||
|
|
||||||
float angle = 360.0 * util::randf_0_1();
|
|
||||||
float speed = 0.01;
|
|
||||||
|
|
||||||
m_state->players.back()->addCommand(new game::SetSpeedCommand(speed));
|
|
||||||
m_state->players.back()->addCommand(new game::ShootCommand(angle));
|
|
||||||
|
|
||||||
//static bool done = false;
|
|
||||||
//if (total >= 10.0 && !done) {
|
|
||||||
// done = true;
|
|
||||||
|
|
||||||
// m_state->players[0]->addCommand(new game::ClearTracesCommand());
|
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
acc += dt;
|
||||||
|
total += dt;
|
||||||
|
|
||||||
|
float spawnInterval = 0.1;
|
||||||
|
while (acc > spawnInterval) {
|
||||||
|
acc -= spawnInterval;
|
||||||
|
|
||||||
|
float angle = 360.0 * util::randf_0_1();
|
||||||
|
float speed = 0.01;
|
||||||
|
|
||||||
|
m_state->players.back()->addCommand(new game::SetSpeedCommand(speed));
|
||||||
|
m_state->players.back()->addCommand(new game::ShootCommand(angle));
|
||||||
|
|
||||||
|
//static bool done = false;
|
||||||
|
//if (total >= 10.0 && !done) {
|
||||||
|
// done = true;
|
||||||
|
|
||||||
|
// m_state->players[0]->addCommand(new game::ClearTracesCommand());
|
||||||
|
//}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
// std::cout<<"adding dt: " << dt << std::endl;
|
// std::cout<<"adding dt: " << dt << std::endl;
|
||||||
m_time_for_next_step += dt;
|
m_time_for_next_step += dt;
|
||||||
|
|
|
@ -32,6 +32,7 @@ int main(int argc, char *argv[]) {
|
||||||
// {"add", no_argument, 0, 'a'},
|
// {"add", no_argument, 0, 'a'},
|
||||||
// {"append", no_argument, 0, 'b'},
|
// {"append", no_argument, 0, 'b'},
|
||||||
// {"delete", required_argument, 0, 'd'},
|
// {"delete", required_argument, 0, 'd'},
|
||||||
|
{"autorun", required_argument, 0, 'a'},
|
||||||
{"port", required_argument, 0, 'p'},
|
{"port", required_argument, 0, 'p'},
|
||||||
{"fps", no_argument, 0, 'f'},
|
{"fps", no_argument, 0, 'f'},
|
||||||
{0, 0, 0, 0}
|
{0, 0, 0, 0}
|
||||||
|
@ -40,7 +41,7 @@ int main(int argc, char *argv[]) {
|
||||||
int option_index = 0;
|
int option_index = 0;
|
||||||
|
|
||||||
while(1){
|
while(1){
|
||||||
c = getopt_long (argc, argv, "p:f",
|
c = getopt_long (argc, argv, "p:fa",
|
||||||
long_options, &option_index);
|
long_options, &option_index);
|
||||||
if (c == -1)
|
if (c == -1)
|
||||||
break;
|
break;
|
||||||
|
@ -54,6 +55,9 @@ int main(int argc, char *argv[]) {
|
||||||
strcpy(port,optarg);
|
strcpy(port,optarg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'a':
|
||||||
|
SET_FLAG(TEST_AUTORUN, true);
|
||||||
|
break;
|
||||||
|
|
||||||
case '?':
|
case '?':
|
||||||
/* getopt_long already printed an error message. */
|
/* getopt_long already printed an error message. */
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define TEST_FLAG1 0
|
#define TEST_FLAG1 0
|
||||||
#define SHOW_FPS 1
|
#define SHOW_FPS 1
|
||||||
#define TEST_FLAG2 2
|
#define TEST_FLAG2 2
|
||||||
|
#define TEST_AUTORUN 3
|
||||||
//...
|
//...
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue