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]);
}
void explosion_callback(double x, double y, double z, void *data) {
explosion.add(x, y, z);
}
GLuint wallTex = 0;
void draw_box() {
@ -364,7 +360,6 @@ void Client::initialize(Arguments &arg) {
exit(EXIT_FAILURE);
}
game.setup_explosion_callback(explosion_callback, 0);
setup_opengl();
setup_explosion();
quadratic = gluNewQuadric();
@ -384,6 +379,9 @@ void Client::initialize(Arguments &arg) {
accelerate_schudule.setInterval(0.05);
loadConsoleFont();
// setup signals
game.ExplosionSignal.connect(this, &Client::onExplosion);
}
void Client::update() {
@ -514,3 +512,8 @@ void Client::shutdown() {
oglf_destroy(&font);
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 drop_bomb(double rx, double ry, double rz, double ttl);
void loadConsoleFont();
void onExplosion(double x, double y, double z);
};
#endif /* CLIENT_H_ */

View File

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

View File

@ -95,7 +95,6 @@ void Game::setup() {
max_player_id = 0;
master = 0;
updateTime = 0.0;
explosion_callback = 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)
+ pow(p->z - bomb->z, 2);
if (distance2 < pow(150., 2.)) {
if (explosion_callback)
explosion_callback(p->x, p->y, p->z, explosion_callback_data);
ExplosionSignal(p->x, p->y, p->z);
p->x = p->team->x + 100;
p->y = p->team->y;
p->z = p->team->z;
@ -259,9 +257,7 @@ void Game::update_bombs(double dt) {
if (b->ttl < 0) {
if (b->status == 1) {
if (explosion_callback)
explosion_callback(b->x, b->y, b->z,
explosion_callback_data);
ExplosionSignal(b->x, b->y, b->z);
b->status = 2;
} else if (b->ttl < -0.2) {
if (master) {
@ -376,12 +372,6 @@ point_t *Game::spawn_point() {
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) {
this->master = master;
}

View File

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

2562
src/common/sigslot.h Normal file

File diff suppressed because it is too large Load Diff