2016-09-28 05:34:37 +00:00
|
|
|
|
#define ASIO_STANDALONE
|
|
|
|
|
|
2016-09-13 19:03:36 +00:00
|
|
|
|
#include <iostream>
|
2016-09-27 18:38:36 +00:00
|
|
|
|
#include <getopt.h>
|
2016-09-27 22:26:36 +00:00
|
|
|
|
#include <asio.hpp>
|
|
|
|
|
#include <cstdlib>
|
2016-09-13 19:03:36 +00:00
|
|
|
|
|
2016-09-27 22:26:36 +00:00
|
|
|
|
#include "opengl.hpp"
|
2016-09-27 17:01:21 +00:00
|
|
|
|
#include "game_window.hpp"
|
2016-09-28 09:50:35 +00:00
|
|
|
|
#include "network/server.hpp"
|
2016-09-27 18:38:36 +00:00
|
|
|
|
#include "options.hpp"
|
2016-09-13 19:03:36 +00:00
|
|
|
|
|
2016-10-03 16:45:24 +00:00
|
|
|
|
#include "sound/sound.hpp"
|
2016-10-02 21:49:40 +00:00
|
|
|
|
#include "sound/sound_effects.hpp"
|
2016-10-03 16:45:24 +00:00
|
|
|
|
|
2016-10-02 21:49:40 +00:00
|
|
|
|
#include "state/state_update_event.hpp"
|
|
|
|
|
|
2016-09-30 21:15:51 +00:00
|
|
|
|
#include <sys/time.h>
|
|
|
|
|
|
2016-09-27 18:56:57 +00:00
|
|
|
|
uint64_t optionsFlags;
|
2016-09-27 18:38:36 +00:00
|
|
|
|
|
2016-09-27 22:26:36 +00:00
|
|
|
|
using asio::ip::tcp;
|
|
|
|
|
|
2016-09-30 17:03:22 +00:00
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
|
{
|
|
|
|
|
bool devMode = false;
|
2016-10-02 21:49:40 +00:00
|
|
|
|
bool soundEnabled = false;
|
2016-09-27 22:26:36 +00:00
|
|
|
|
char port[]="3490";
|
2016-09-27 18:38:36 +00:00
|
|
|
|
|
|
|
|
|
static struct option long_options[] =
|
|
|
|
|
{
|
|
|
|
|
/* These options set a flag. */
|
|
|
|
|
// {"verbose", no_argument, &verbose_flag, 1},
|
|
|
|
|
// {"brief", no_argument, &verbose_flag, 0},
|
|
|
|
|
/* These options don’t set a flag.
|
|
|
|
|
We distinguish them by their indices. */
|
|
|
|
|
// {"add", no_argument, 0, 'a'},
|
|
|
|
|
// {"append", no_argument, 0, 'b'},
|
|
|
|
|
// {"delete", required_argument, 0, 'd'},
|
2016-09-28 19:38:13 +00:00
|
|
|
|
{"autorun", required_argument, 0, 'a'},
|
2016-09-27 23:48:34 +00:00
|
|
|
|
{"port", required_argument, 0, 'p'},
|
2016-10-02 21:49:40 +00:00
|
|
|
|
{"sound", no_argument, 0, 's'},
|
2016-09-27 18:38:36 +00:00
|
|
|
|
{"fps", no_argument, 0, 'f'},
|
2016-09-30 17:03:22 +00:00
|
|
|
|
{"dev", no_argument, 0, 'd'},
|
2016-09-27 18:38:36 +00:00
|
|
|
|
{0, 0, 0, 0}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
int option_index = 0;
|
|
|
|
|
|
|
|
|
|
while(1){
|
2016-10-02 21:49:40 +00:00
|
|
|
|
char c = getopt_long (argc, argv, "p:fads",
|
2016-09-27 18:38:36 +00:00
|
|
|
|
long_options, &option_index);
|
|
|
|
|
if (c == -1)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
switch (c)
|
|
|
|
|
{
|
|
|
|
|
case 'f':
|
|
|
|
|
SET_FLAG(SHOW_FPS,true);
|
|
|
|
|
break;
|
2016-10-02 21:49:40 +00:00
|
|
|
|
|
2016-09-30 17:03:22 +00:00
|
|
|
|
case 'd':
|
|
|
|
|
std::cout<<"enabling developer mode" << std::endl;
|
|
|
|
|
devMode = true;
|
|
|
|
|
break;
|
|
|
|
|
|
2016-09-27 23:48:34 +00:00
|
|
|
|
case 'p':
|
|
|
|
|
strcpy(port,optarg);
|
|
|
|
|
break;
|
|
|
|
|
|
2016-10-02 21:49:40 +00:00
|
|
|
|
case 's':
|
|
|
|
|
soundEnabled = true;
|
|
|
|
|
break;
|
|
|
|
|
|
2016-09-28 19:38:13 +00:00
|
|
|
|
case 'a':
|
|
|
|
|
SET_FLAG(TEST_AUTORUN, true);
|
|
|
|
|
break;
|
2016-09-27 18:38:36 +00:00
|
|
|
|
|
|
|
|
|
case '?':
|
|
|
|
|
/* getopt_long already printed an error message. */
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
abort();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-30 21:15:51 +00:00
|
|
|
|
srand(time(NULL));
|
|
|
|
|
|
2016-10-03 16:45:24 +00:00
|
|
|
|
sound::SoundEffects *sounds = nullptr;
|
2016-10-02 21:49:40 +00:00
|
|
|
|
if (soundEnabled) {
|
2016-10-03 16:45:24 +00:00
|
|
|
|
if (sound::initSound()) {
|
|
|
|
|
sounds = new sound::SoundEffects();
|
|
|
|
|
}
|
2016-10-02 21:49:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-09-27 23:48:34 +00:00
|
|
|
|
Game game;
|
2016-09-30 17:03:22 +00:00
|
|
|
|
game.state()->setDeveloperMode(devMode);
|
2016-09-27 23:48:34 +00:00
|
|
|
|
|
2016-09-27 22:26:36 +00:00
|
|
|
|
asio::io_service io_service;
|
2016-09-27 23:48:34 +00:00
|
|
|
|
Server s(io_service, game.state(), atoi(port) );
|
2016-09-27 22:26:36 +00:00
|
|
|
|
|
2016-09-30 20:04:14 +00:00
|
|
|
|
//GameWindow window(500, 500, &game);
|
2016-09-30 21:15:51 +00:00
|
|
|
|
GameWindow window(500, 500, &game);
|
2016-09-27 18:38:36 +00:00
|
|
|
|
window.set_maxfps(60.0);
|
2016-09-28 11:00:40 +00:00
|
|
|
|
window.open();
|
2016-09-27 22:26:36 +00:00
|
|
|
|
|
|
|
|
|
while(window.running()){
|
|
|
|
|
window.poll();
|
|
|
|
|
io_service.poll();
|
2016-10-02 21:49:40 +00:00
|
|
|
|
|
2016-10-03 11:37:49 +00:00
|
|
|
|
//size_t numEvents = game.state()->currentStateUpdateEvents().size();
|
|
|
|
|
//if (numEvents != 0) {
|
|
|
|
|
// std::cout<<"game state update events: " << numEvents << std::endl;
|
|
|
|
|
// for (game::StateUpdateEvent *evt : game.state()->currentStateUpdateEvents()) {
|
|
|
|
|
// std::cout<< evt->description() << std::endl;
|
|
|
|
|
// }
|
|
|
|
|
//}
|
2016-10-02 22:23:21 +00:00
|
|
|
|
|
2016-10-03 16:45:24 +00:00
|
|
|
|
if (sounds != nullptr) {
|
|
|
|
|
// TODO: get time diff too
|
|
|
|
|
sounds->advance(1/50.0f, game.state()->currentStateUpdateEvents());
|
|
|
|
|
// TODO: use flag to now when to do this.
|
|
|
|
|
sound::deleteOldSounds();
|
|
|
|
|
}
|
2016-10-02 22:23:21 +00:00
|
|
|
|
|
|
|
|
|
game.state()->applyAndClearAllOldStateUpdates();
|
2016-09-27 22:26:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
2016-09-13 19:03:36 +00:00
|
|
|
|
}
|