add signal/slot

This commit is contained in:
gmueller 2011-01-18 23:31:41 +01:00
parent b55b687cd9
commit 6fcb3dbff4
6 changed files with 2580 additions and 23 deletions

View File

@ -152,10 +152,6 @@ void setup_explosion() {
textures[4]); textures[4]);
} }
void explosion_callback(double x, double y, double z, void *data) {
explosion.add(x, y, z);
}
GLuint wallTex = 0; GLuint wallTex = 0;
void draw_box() { void draw_box() {
@ -364,7 +360,6 @@ void Client::initialize(Arguments &arg) {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
game.setup_explosion_callback(explosion_callback, 0);
setup_opengl(); setup_opengl();
setup_explosion(); setup_explosion();
quadratic = gluNewQuadric(); quadratic = gluNewQuadric();
@ -384,6 +379,9 @@ void Client::initialize(Arguments &arg) {
accelerate_schudule.setInterval(0.05); accelerate_schudule.setInterval(0.05);
loadConsoleFont(); loadConsoleFont();
// setup signals
game.ExplosionSignal.connect(this, &Client::onExplosion);
} }
void Client::update() { void Client::update() {
@ -514,3 +512,8 @@ void Client::shutdown() {
oglf_destroy(&font); oglf_destroy(&font);
glfwTerminate(); glfwTerminate();
} }
void Client::onExplosion(double x, double y, double z) {
explosion.add(x, y, z);
}

View File

@ -31,6 +31,8 @@ private:
void accelerate(double x, double y, double z); void accelerate(double x, double y, double z);
void drop_bomb(double rx, double ry, double rz, double ttl); void drop_bomb(double rx, double ry, double rz, double ttl);
void loadConsoleFont(); void loadConsoleFont();
void onExplosion(double x, double y, double z);
}; };
#endif /* CLIENT_H_ */ #endif /* CLIENT_H_ */

View File

@ -8,13 +8,15 @@
#ifndef APPLICATION_H_ #ifndef APPLICATION_H_
#define APPLICATION_H_ #define APPLICATION_H_
#include "Game.h" #include "sigslot.h"
#include "common.h"
#include "Game.h"
#include "Schedule.h" #include "Schedule.h"
#include "Arguments.h" #include "Arguments.h"
#include "Network.h" #include "Network.h"
class Application { class Application: public sigslot::has_slots<> {
public: public:
Application(); Application();
virtual ~Application(); virtual ~Application();

View File

@ -95,7 +95,6 @@ void Game::setup() {
max_player_id = 0; max_player_id = 0;
master = 0; master = 0;
updateTime = 0.0; updateTime = 0.0;
explosion_callback = 0;
local_player = 0; local_player = 0;
} }
@ -207,8 +206,7 @@ void Game::explode_bomb(bomb_t *bomb) {
double distance2 = pow(p->x - bomb->x, 2) + pow(p->y - bomb->y, 2) double distance2 = pow(p->x - bomb->x, 2) + pow(p->y - bomb->y, 2)
+ pow(p->z - bomb->z, 2); + pow(p->z - bomb->z, 2);
if (distance2 < pow(150., 2.)) { if (distance2 < pow(150., 2.)) {
if (explosion_callback) ExplosionSignal(p->x, p->y, p->z);
explosion_callback(p->x, p->y, p->z, explosion_callback_data);
p->x = p->team->x + 100; p->x = p->team->x + 100;
p->y = p->team->y; p->y = p->team->y;
p->z = p->team->z; p->z = p->team->z;
@ -259,9 +257,7 @@ void Game::update_bombs(double dt) {
if (b->ttl < 0) { if (b->ttl < 0) {
if (b->status == 1) { if (b->status == 1) {
if (explosion_callback) ExplosionSignal(b->x, b->y, b->z);
explosion_callback(b->x, b->y, b->z,
explosion_callback_data);
b->status = 2; b->status = 2;
} else if (b->ttl < -0.2) { } else if (b->ttl < -0.2) {
if (master) { if (master) {
@ -376,12 +372,6 @@ point_t *Game::spawn_point() {
return NULL; return NULL;
} }
void Game::setup_explosion_callback(void(*explosion_callback)(double x,
double y, double z, void *data), void *data) {
this->explosion_callback = explosion_callback;
explosion_callback_data = data;
}
void Game::set_master(int master) { void Game::set_master(int master) {
this->master = master; this->master = master;
} }

View File

@ -2,6 +2,7 @@
#define GREMLIN_GAME_H #define GREMLIN_GAME_H
#include "common.h" #include "common.h"
#include "sigslot.h"
#include <vector> #include <vector>
@ -54,8 +55,7 @@ public:
int master; int master;
double updateTime; double updateTime;
player_t *local_player; player_t *local_player;
void(*explosion_callback)(double x, double y, double z, void *data); sigslot::signal3<double, double, double> ExplosionSignal;
void *explosion_callback_data;
void setup(); void setup();
void reset(); void reset();
@ -71,8 +71,6 @@ public:
void update_bombs(double dt); void update_bombs(double dt);
void update_points(double dt); void update_points(double dt);
void update(double dt); void update(double dt);
void setup_explosion_callback(void(*explosion_callback)(double x, double y,
double z, void *data), void *data);
void set_master(int master); void set_master(int master);
player_t *getFreePlayer(); player_t *getFreePlayer();
void explode_bomb(bomb_t *bomb); void explode_bomb(bomb_t *bomb);

2562
src/common/sigslot.h Normal file

File diff suppressed because it is too large Load Diff