switch to horde3d

This commit is contained in:
Gero Müller 2018-11-26 13:15:41 +01:00
parent dbed4abb0b
commit 08ac71b995
18 changed files with 319 additions and 549 deletions

View File

@ -121,9 +121,6 @@ elseif (WIN32)
#set (log4cplus_postfix "${log4cplus_postfix}S")
endif ()
message (STATUS "Headers: ${log4cplus_headers}")
message (STATUS "Sources: ${log4cplus_sources}")
include_directories ("include")
set (log4cplus_all_sources ${log4cplus_sources} ${log4cplus_headers})

View File

@ -1,4 +1,5 @@
include_directories (${GREMLIN_SOURCE_DIR}/src/common)
include_directories (${CMAKE_SOURCE_DIR}/libs/horde3d-1.0.0-beta5/Include)
# define executable
add_executable( gremlin
@ -6,14 +7,10 @@ add_executable( gremlin
Explosion
main
oglfont
)
add_dependencies( gremlin
common
glfw
spark
Window
Renderer
)
target_link_libraries(gremlin
common enet glfw spark log4cplus ${PLATFORM_LIBRARIES} ${OPENGL_LIBRARIES}
common enet glfw spark horde3d log4cplus ${PLATFORM_LIBRARIES} ${OPENGL_LIBRARIES}
)

View File

@ -1,16 +1,11 @@
/*
* Client.cpp
*
* Created on: 14.01.2011
* Author: gmueller
*/
#include "Client.h"
#include "Network.h"
#include "Explosion.h"
#include "Time.h"
#include "btBulletDynamicsCommon.h"
#include "Horde3D.h"
#include <GL/glfw.h>
#include <stdio.h>
@ -19,110 +14,9 @@
#include <string.h>
#include <sstream>
GLUquadricObj *quadratic;
namespace gln {
Explosion explosion;
void setup_light() {
GLfloat LightAmbient[] = { 0.5f, 0.5f, 0.5f, 1.0f };
GLfloat LightDiffuse[] = { 0.5f, 0.5f, 0.5f, 1.0f };
GLfloat LightPosition[] = { 1.0f, 1.0f, 1.0f, 0.0f };
// setup directional light
glLightfv(GL_LIGHT0, GL_AMBIENT, LightAmbient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, LightDiffuse);
glLightfv(GL_LIGHT0, GL_POSITION, LightPosition);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHTING);
}
void setup_opengl() {
// Open OpenGL window
if (!glfwOpenWindow(640, 480, 0, 0, 0, 0, 0, 0, GLFW_WINDOW)) {
fprintf(stderr, "Failed to open GLFW window\n");
glfwTerminate();
exit(EXIT_FAILURE);
}
//glfwDisable(GLFW_MOUSE_CURSOR);
glfwSetWindowTitle("Gremlin Lan Party Game");
// Enable sticky keys
glfwEnable(GLFW_STICKY_KEYS);
// general settings
glShadeModel(GL_SMOOTH);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glEnable(GL_CULL_FACE);
// setup depth buffer
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
// Enable vertical sync (on cards that support it)
glfwSwapInterval(0);
}
void draw_team(Team *team) {
size_t i = 0;
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, team->color);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glTranslated(team->x, team->y, team->z);
gluSphere(quadratic, 50.f, 32, 32);
glPopMatrix();
}
GLuint wallTex = 0;
void Client::drawPlayer(player_t *player) {
if (player->status == 0)
return;
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, player->team->color);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glMultMatrixf(player->m);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glVertexPointer(3, GL_FLOAT, game.shipMesh->vertex_size,
game.shipMesh->vertices);
glTexCoordPointer(2, GL_FLOAT, game.shipMesh->vertex_size,
game.shipMesh->vertices + 3);
glNormalPointer(GL_FLOAT, game.shipMesh->vertex_size,
game.shipMesh->vertices + 5);
for (size_t i = 0; i < game.shipMesh->object_count; i++) {
glDrawElements(GL_TRIANGLES, game.shipMesh->objects[i].face_count * 3,
GL_UNSIGNED_SHORT,
&game.shipMesh->faces[game.shipMesh->objects[i].face_index]);
}
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glPopMatrix();
}
void draw_bomb(bomb_t *bomb) {
if (bomb->status != 1)
return;
GLfloat red[] = { 1.0f, 0.0f, 0.0f, 1.0f };
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glTranslated(bomb->x, bomb->y, bomb->z);
gluSphere(quadratic, 0.5f, 4, 4);
glPopMatrix();
}
void draw_point(point_t *point) {
if (point->status == 0)
return;
GLfloat red[] = { 0.0f, 0.0f, 1.0f, 1.0f };
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glTranslated(point->x, point->y, point->z);
gluSphere(quadratic, 3.f, 12, 12);
glPopMatrix();
}
void setup_explosion() {
// Loads particle texture
@ -169,155 +63,6 @@ void setup_explosion() {
textures[4]);
}
void Client::drawLevel() {
if (wallTex == 0) {
glGenTextures(1, &wallTex);
glBindTexture(GL_TEXTURE_2D, wallTex);
glEnable(GL_TEXTURE_2D);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
GL_LINEAR_MIPMAP_LINEAR);
glfwLoadTexture2D("data/wall.tga", GLFW_BUILD_MIPMAPS_BIT);
} else {
glBindTexture(GL_TEXTURE_2D, wallTex);
glEnable(GL_TEXTURE_2D);
}
GLfloat red[] = { 1.0f, 1.0f, 1.0f, 1.0f };
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red);
// Enable/Disable features
glPushAttrib(GL_ENABLE_BIT);
glEnable(GL_TEXTURE_2D);
//glDisable( GL_DEPTH_TEST);
// glEnable( GL_LIGHTING);
// glDisable( GL_BLEND);
glColor4f(1, 1, 1, 1);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
#if 0
glTranslated(2000.0, 0.0, 0.0);
//glScaled(5000.0f, 5000.0f, 5000.0f);
float s = 3000.0f, t = 10.0f;
// Just in case we set all vertices to white.
// Render the front quad
glBegin( GL_QUADS);
glTexCoord2f(0, t);
glNormal3f(0.0, 0.0, 1.0);
glVertex3f(-s, s, -s);
glTexCoord2f(0, 0);
glNormal3f(0.0, 0.0, 1.0);
glVertex3f(-s, -s, -s);
glTexCoord2f(t, 0);
glNormal3f(0.0, 0.0, 1.0);
glVertex3f(s, -s, -s);
glTexCoord2f(t, t);
glNormal3f(0.0, 0.0, 1.0);
glVertex3f(s, s, -s);
glEnd();
// Render the left quad
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex3f(s, -s, s);
glTexCoord2f(0, t);
glVertex3f(s, s, s);
glTexCoord2f(t, t);
glVertex3f(s, s, -s);
glTexCoord2f(t, 0);
glVertex3f(s, -s, -s);
glEnd();
// Render the back quad
// glBindTexture(GL_TEXTURE_2D, _skybox[2]);
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex3f(-s, -s, s);
glTexCoord2f(0, t);
glVertex3f(-s, s, s);
glTexCoord2f(t, t);
glVertex3f(s, s, s);
glTexCoord2f(t, 0);
glVertex3f(s, -s, s);
glEnd();
// Render the right quad
// glBindTexture(GL_TEXTURE_2D, _skybox[3]);
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex3f(-s, -s, -s);
glTexCoord2f(0, t);
glVertex3f(-s, s, -s);
glTexCoord2f(t, t);
glVertex3f(-s, s, s);
glTexCoord2f(t, 0);
glVertex3f(-s, -s, s);
glEnd();
// Render the top quad
//glBindTexture(GL_TEXTURE_2D, _skybox[4]);
glBegin(GL_QUADS);
glTexCoord2f(0, t);
glVertex3f(-s, s, -s);
glTexCoord2f(t, t);
glVertex3f(s, s, -s);
glTexCoord2f(t, 0);
glVertex3f(s, s, s);
glTexCoord2f(0, 0);
glVertex3f(-s, s, s);
glEnd();
// Render the bottom quad
//glBindTexture(GL_TEXTURE_2D, _skybox[5]);
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex3f(-s, -s, -s);
glTexCoord2f(0, t);
glVertex3f(-s, -s, s);
glTexCoord2f(t, t);
glVertex3f(s, -s, s);
glTexCoord2f(t, 0);
glVertex3f(s, -s, -s);
glEnd();
#else
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glVertexPointer(3, GL_FLOAT, game.levelMesh->vertex_size,
game.levelMesh->vertices);
glTexCoordPointer(2, GL_FLOAT, game.levelMesh->vertex_size,
game.levelMesh->vertices + 3);
glNormalPointer(GL_FLOAT, game.levelMesh->vertex_size,
game.levelMesh->vertices + 5);
for (size_t i = 0; i < game.levelMesh->object_count; i++) {
glDrawElements(GL_TRIANGLES, game.levelMesh->objects[i].face_count * 3,
GL_UNSIGNED_SHORT,
&game.levelMesh->faces[game.levelMesh->objects[i].face_index]);
}
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
#endif
// Restore enable bits and matrix
glPopAttrib();
glPopMatrix();
}
void Client::accelerate(double x, double y, double z) {
if (game.local_player == 0)
return;
@ -365,44 +110,14 @@ void Client::loadConsoleFont() {
oglf_load(&font, "data/fonts/console.fnt", font_id);
}
void Client::prepareFrame(double rx, double ry, double rz) {
// Get window size (may be different than the requested size)
glfwGetWindowSize(&width, &height);
height = height > 0 ? height : 1;
void Client::initialize(Config &config) {
Application::initialize(config);
// Set viewport
glViewport(0, 0, width, height);
window.initialize(config);
renderer.initialize(&window, config);
// Clear color buffer
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Select and setup the projection matrix
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0f, (GLfloat) width / (GLfloat) height, 1.0f, 10000.0f);
// Select and setup the modelview matrix
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(camX, camY, camZ, camX + rx * 10.0f, camY + ry * 10.0f,
camZ + rz * 10.0f, 0.0f, 1.0f, 0.0f);
}
void Client::initialize(Arguments &arg) {
Application::initialize(arg);
// Initialise GLFW
if (!glfwInit()) {
throw("Failed to initialize GLFW");
}
setup_opengl();
setup_explosion();
quadratic = gluNewQuadric();
gluQuadricNormals(quadratic, GLU_SMOOTH);
gluQuadricTexture(quadratic, GL_TRUE);
loadConsoleFont();
//setup_explosion();
if (isMaster()) {
Team *team = game.getTeam(0);
@ -425,12 +140,132 @@ void Client::initialize(Arguments &arg) {
// setup signals
game.ExplosionSignal.connect(this, &Client::onExplosion);
}
renderer.create("level");
}
void Client::processInput(double step) {
if (!game.local_player)
return;
btRigidBody *body = game.local_player->body.get();
if (!body)
return;
btMatrix3x3 &basis = body->getWorldTransform().getBasis();
btVector3 front = basis * btVector3(0, 0, -10) * step;
btVector3 right = basis * btVector3(10, 0, 0) * step;
btVector3 up = basis * btVector3(0, 10, 0) * step;
float accelSpeed = 200 / body->getInvMass();
btVector3 accel(0, 0, 0);
if (glfwGetKey('W') == GLFW_PRESS) {
accel += accelSpeed * front;
}
if (glfwGetKey('A') == GLFW_PRESS) {
accel += -accelSpeed * right;
}
if (glfwGetKey('S') == GLFW_PRESS) {
accel += -accelSpeed * front;
}
if (glfwGetKey('D') == GLFW_PRESS) {
accel += accelSpeed * right;
}
if (glfwGetKey('R') == GLFW_PRESS) {
accel += accelSpeed * up;
}
if (glfwGetKey('F') == GLFW_PRESS) {
accel += -accelSpeed * up;
}
accel *= step;
accelerate(accel.x(), accel.y(), accel.z());
#if 0
float rotationSpeed = 1000 / body->getInvMass();
float lx = (mouseX - 0.5) * 2;
float ly = (mouseY - 0.5) * 2;
btVector3 desiredLocalAngualarVelocity = btVector3(0, -2 * lx, 0)
+ btVector3(-2 * ly, 0, 0);
btVector3 desiredAngualarVelocity = body->getWorldTransform().getBasis()
* desiredLocalAngualarVelocity;
btVector3 angularVelocity = body->getAngularVelocity();
btVector3 a = desiredAngualarVelocity - angularVelocity;
float turningAngle = a.length();
a *= fabs(turningAngle);
Steering *s = 0;
if (entity->getComponent(s))
s->setAngularForce(a);
//}
if (turningAngle > 0.001) {
activate = true;
jetStrength += std::min(0.2f, turningAngle * turningAngle * 10);
}
if (glfwGetKey(GLFW_KEY_LEFT) == GLFW_PRESS) {
body->applyForce(-rotationSpeed * right, front);
body->applyForce(rotationSpeed * right, -front);
activate = true;
}
if (glfwGetKey(GLFW_KEY_RIGHT) == GLFW_PRESS) {
body->applyForce(rotationSpeed * right, front);
body->applyForce(-rotationSpeed * right, -front);
activate = true;
}
if (glfwGetKey(GLFW_KEY_UP) == GLFW_PRESS) {
body->applyForce(-rotationSpeed * up, front);
body->applyForce(rotationSpeed * up, -front);
activate = true;
}
if (glfwGetKey(GLFW_KEY_DOWN) == GLFW_PRESS) {
body->applyForce(rotationSpeed * up, front);
body->applyForce(-rotationSpeed * up, -front);
activate = true;
}
// roll
if (glfwGetKey('Q') == GLFW_PRESS) {
body->applyForce(rotationSpeed * up, right);
body->applyForce(-rotationSpeed * up, -right);
jetStrength += 0.1;
activate = true;
}
if (glfwGetKey('E') == GLFW_PRESS) {
body->applyForce(-rotationSpeed * up, right);
body->applyForce(rotationSpeed * up, -right);
jetStrength += 0.1;
activate = true;
}
if (activate) {
body->activate();
}
if (jetStrength > 0) {
jet->setVolume(jetStrength);
if (!jet->isPlaying()) {
jet->play2d(true);
}
} else {
jet->stop();
}
#endif
}
void Client::update() {
Application::update();
window.update();
int x, y;
glfwGetMousePos(&x, &y);
if (glfwGetMouseButton(GLFW_MOUSE_BUTTON_2) == GLFW_PRESS) {
@ -450,25 +285,7 @@ void Client::update() {
if (accelerate_schudule.next(time)) {
double t = accelerate_schudule.getInterval();
double v = 50.0 * t;
if (glfwGetKey('W')) {
accelerate(rx * v, ry * v, rz * v);
} else if (glfwGetKey('S')) {
accelerate(rx * -v, ry * -v, rz * -v);
}
if (glfwGetKey('A')) {
accelerate(rz * v, 0, -rx * v);
} else if (glfwGetKey('D')) {
accelerate(-rz * v, 0, rx * v);
}
#if 0
if (glfwGetKey(GLFW_KEY_SPACE)) {
accelerate(game.local_player->vx * -0.1,
game.local_player->vy * -0.1, game.local_player->vz * -0.1);
}
#endif
processInput(t);
}
if (glfwGetKey(GLFW_KEY_LCTRL)) {
if (time - last_bomb > 1.0) {
@ -477,18 +294,30 @@ void Client::update() {
}
}
btScalar bullet_trafo[16];
if (game.local_player) {
btVector3 p = game.local_player->body->getWorldTransform().getOrigin();
camX = p.x();
camY = p.y();
camZ = p.z();
game.local_player->body->getWorldTransform().getOpenGLMatrix(
bullet_trafo);
// bullet_trafo[12] -= origin.x();
// bullet_trafo[13] -= origin.y();
// bullet_trafo[14] -= origin.z();
} else {
camX = 1000.0;
camY = 1000.0;
camZ = 1000.0;
bullet_trafo[12] = 1000.0;
bullet_trafo[13] = 1000.0;
bullet_trafo[14] = 1000.0;
}
float trafo[16];
for (size_t i = 0; i < 16; i++)
trafo[i] = bullet_trafo[i];
h3dSetNodeTransMat(renderer.getCameraNode(), trafo);
// h3dSetNodeTransform(renderer.getCameraNode(), camX, camY, camZ,
// -theta * 180 / M_PI - 90, phi * 180 / M_PI, 0, 1, 1, 1);
// H3DNode cam = renderer.getCameraNode();
renderer.draw();
#if 0
prepareFrame(rx, ry, rz);
setup_light();
glEnable(GL_LIGHT0);
@ -511,7 +340,7 @@ void Client::update() {
explosion.update(dt * 1000.0, camX, camY, camZ);
explosion.render();
#endif
glDisable(GL_LIGHT0);
glDisable(GL_LIGHTING);
glDisable(GL_CULL_FACE);
@ -558,7 +387,6 @@ void Client::shutdown() {
Application::shutdown();
gluDeleteQuadric(quadratic);
oglf_destroy(&font);
glfwTerminate();
}
@ -567,3 +395,4 @@ void Client::onExplosion(double x, double y, double z) {
explosion.add(x, y, z);
}
} // namespace grln

View File

@ -10,14 +10,21 @@
#include "Application.h"
#include "Schedule.h"
#include "Renderer.h"
#include "Window.h"
#include "oglfont.h"
namespace gln {
class Client: public Application {
public:
void initialize(Arguments &arg);
void initialize(Config &config);
void update();
void shutdown();
private:
Window window;
Renderer renderer;
double last_bomb; //TODO: use bomb schedule;
int last_x, last_y;
double phi, theta;
@ -26,8 +33,7 @@ private:
int width, height;
//TrueTyeFont font;
oglf_font_t font;
void prepareFrame(double rx, double ry, double rz);
void processInput(double step);
void accelerate(double x, double y, double z);
void drop_bomb(double rx, double ry, double rz, double ttl);
void loadConsoleFont();
@ -38,4 +44,6 @@ private:
void drawPlayer(player_t *player);
};
} // namespace grln
#endif /* CLIENT_H_ */

View File

@ -1,15 +1,10 @@
/*
* Explosion.cpp
*
* Created on: 05.01.2011
* Author: gmueller
*/
#include "Explosion.h"
using namespace SPK;
using namespace SPK::GL;
namespace gln {
Explosion::~Explosion() {
SPKFactory::getInstance().destroyAll();
}
@ -51,7 +46,7 @@ void Explosion::initialize(GLuint textureExplosion, GLuint textureFlash,
flashRenderer->setBlending(BLENDING_ADD);
flashRenderer->enableRenderingHint(DEPTH_WRITE, false);
flashRenderer->setShared(true);
flashRenderer->setScale(scale,scale);
flashRenderer->setScale(scale, scale);
// spark 1 renderer
GLQuadRenderer* spark1Renderer = GLQuadRenderer::create();
@ -111,9 +106,9 @@ void Explosion::initialize(GLuint textureExplosion, GLuint textureFlash,
Interpolator* interpolator = NULL; // pointer to an interpolator that is used to retrieve interpolators
// smoke model
Model* smokeModel = Model::create(FLAG_RED | FLAG_GREEN | FLAG_BLUE
| FLAG_ALPHA | FLAG_SIZE | FLAG_ANGLE | FLAG_TEXTURE_INDEX,
FLAG_SIZE | FLAG_ANGLE,
Model* smokeModel = Model::create(
FLAG_RED | FLAG_GREEN | FLAG_BLUE | FLAG_ALPHA | FLAG_SIZE
| FLAG_ANGLE | FLAG_TEXTURE_INDEX, FLAG_SIZE | FLAG_ANGLE,
FLAG_SIZE | FLAG_ANGLE | FLAG_TEXTURE_INDEX, FLAG_ALPHA);
smokeModel->setParam(PARAM_RED, 0.2f);
smokeModel->setParam(PARAM_GREEN, 0.2f);
@ -131,10 +126,11 @@ void Explosion::initialize(GLuint textureExplosion, GLuint textureFlash,
interpolator->addEntry(1.0f, 0.0f);
// flame model
Model* flameModel = Model::create(FLAG_RED | FLAG_GREEN | FLAG_BLUE
| FLAG_ALPHA | FLAG_SIZE | FLAG_ANGLE | FLAG_TEXTURE_INDEX,
FLAG_ANGLE | FLAG_RED | FLAG_GREEN | FLAG_BLUE, FLAG_ANGLE
| FLAG_TEXTURE_INDEX, FLAG_SIZE | FLAG_ALPHA);
Model* flameModel = Model::create(
FLAG_RED | FLAG_GREEN | FLAG_BLUE | FLAG_ALPHA | FLAG_SIZE
| FLAG_ANGLE | FLAG_TEXTURE_INDEX,
FLAG_ANGLE | FLAG_RED | FLAG_GREEN | FLAG_BLUE,
FLAG_ANGLE | FLAG_TEXTURE_INDEX, FLAG_SIZE | FLAG_ALPHA);
flameModel->setParam(PARAM_RED, 1.0f, 0.2f);
flameModel->setParam(PARAM_GREEN, 0.5f, 0.2f);
flameModel->setParam(PARAM_BLUE, 0.2f, 0.2f);
@ -176,8 +172,9 @@ void Explosion::initialize(GLuint textureExplosion, GLuint textureFlash,
spark1Model->setShared(true);
// spark 2 model
Model* spark2Model = Model::create(FLAG_RED | FLAG_GREEN | FLAG_BLUE
| FLAG_ALPHA, FLAG_GREEN | FLAG_BLUE | FLAG_ALPHA, FLAG_GREEN);
Model* spark2Model = Model::create(
FLAG_RED | FLAG_GREEN | FLAG_BLUE | FLAG_ALPHA,
FLAG_GREEN | FLAG_BLUE | FLAG_ALPHA, FLAG_GREEN);
spark2Model->setParam(PARAM_ALPHA, 1.0f, 0.0f);
spark2Model->setParam(PARAM_RED, 1.0f);
spark2Model->setParam(PARAM_GREEN, 1.0f, 1.0f, 0.3f, 1.0f);
@ -186,8 +183,8 @@ void Explosion::initialize(GLuint textureExplosion, GLuint textureFlash,
spark2Model->setShared(true);
// wave model
Model* waveModel = Model::create(FLAG_ALPHA | FLAG_SIZE, FLAG_SIZE
| FLAG_ALPHA);
Model* waveModel = Model::create(FLAG_ALPHA | FLAG_SIZE,
FLAG_SIZE | FLAG_ALPHA);
waveModel->setParam(PARAM_SIZE, 0.0f, 4.0f);
waveModel->setParam(PARAM_ALPHA, 0.2f, 0.0f);
waveModel->setLifeTime(0.8f, 0.8f);
@ -198,8 +195,10 @@ void Explosion::initialize(GLuint textureExplosion, GLuint textureFlash,
//////////////
// This zone will be used by several emitters
Sphere* explosionSphere = Sphere::create(Vector3D(0.0f, 0.0f, 0.0f), 0.4f * scale);
Sphere* explosionSphere2 = Sphere::create(Vector3D(0.0f, 0.0f, 0.0f), 0.4f * 2.5* scale);
Sphere* explosionSphere = Sphere::create(Vector3D(0.0f, 0.0f, 0.0f),
0.4f * scale);
Sphere* explosionSphere2 = Sphere::create(Vector3D(0.0f, 0.0f, 0.0f),
0.4f * 2.5 * scale);
// smoke emitter
RandomEmitter* smokeEmitter = RandomEmitter::create();
@ -302,8 +301,8 @@ void Explosion::initialize(GLuint textureExplosion, GLuint textureFlash,
void Explosion::render() {
GLRenderer::saveGLStates();
// Renders all the particle systems
for (std::list<System*>::const_iterator it = particleSystems.begin(); it
!= particleSystems.end(); ++it)
for (std::list<System*>::const_iterator it = particleSystems.begin();
it != particleSystems.end(); ++it)
(*it)->render();
GLRenderer::restoreGLStates();
}
@ -349,3 +348,5 @@ void Explosion::update(double dt, double cx, double cy, double cz) {
++it;
}
}
} // namespace grln

View File

@ -11,6 +11,8 @@
#include "SPK.h"
#include "SPK_GL.h"
namespace gln {
class Explosion {
public:
~Explosion();
@ -24,4 +26,6 @@ private:
std::list<SPK::System*> particleSystems;
};
} // namespace grln
#endif /* EXPLOSION_H_ */

View File

@ -20,9 +20,11 @@ int main(int argc, const char **argv) {
LOG4CPLUS_INFO(logger, " - " << argv[i]);
try {
Client app;
Arguments args(argc, argv);
app.initialize(args);
gln::Client app;
gln::Config config;
config.load(argc, argv);
app.initialize(config);
while (app.isRunning())
app.update();
app.shutdown();

View File

@ -1,16 +1,11 @@
/*
* Application.cpp
*
* Created on: 14.01.2011
* Author: gmueller
*/
#include "Application.h"
#include "Time.h"
#include "Network.h"
#include <iostream>
namespace gln {
Application::Application() :
running(false), master(false), time(0.0), network(&game) {
@ -34,7 +29,7 @@ void Application::stop() {
running = false;
}
void Application::initialize(Arguments &arg) {
void Application::initialize(Config &config) {
std::cout << "[Application] initialize" << std::endl;
// setup time
@ -49,7 +44,8 @@ void Application::initialize(Arguments &arg) {
gameUpdateSchudule.setExact(true);
gameUpdateSchudule.setInterval(0.05);
std::string host = arg.getString("-h", std::string());
std::string host;
config.get("host", host);
network.initialize(host);
// setup network
@ -89,3 +85,5 @@ void Application::setMaster(bool master) {
this->master = master;
game.set_master(master ? 1 : 0);
}
} // namespace grln

View File

@ -1,10 +1,3 @@
/*
* Application.h
*
* Created on: 14.01.2011
* Author: gmueller
*/
#ifndef APPLICATION_H_
#define APPLICATION_H_
@ -13,14 +6,16 @@
#include "Game.h"
#include "Schedule.h"
#include "Arguments.h"
#include "Network.h"
#include "Config.h"
namespace gln {
class Application: public sigslot::has_slots<> {
public:
Application();
virtual ~Application();
virtual void initialize(Arguments &arg);
virtual void initialize(Config &config);
virtual void update();
virtual void shutdown();
@ -50,4 +45,6 @@ protected:
double time;
};
} // namespace grln
#endif /* APPLICATION_H_ */

View File

@ -6,6 +6,7 @@ add_library( common
Game
Time
Network
Config
)
add_dependencies( common

View File

@ -1,18 +1,19 @@
#include "Game.h"
#include "btBulletDynamicsCommon.h"
#include <stdlib.h>
#include <math.h>
#include <stdlib.h>
#include <iostream>
#include "btBulletDynamicsCommon.h"
namespace gln {
Game::Game() :
local_player(0), collisionConfiguration(
new btDefaultCollisionConfiguration()), dispatcher(
new btCollisionDispatcher(collisionConfiguration.get())),
overlappingPairCache(new btDbvtBroadphase), solver(
new btCollisionDispatcher(collisionConfiguration.get())), overlappingPairCache(
new btDbvtBroadphase), solver(
new btSequentialImpulseConstraintSolver), dynamicsWorld(
new btDiscreteDynamicsWorld(dispatcher.get(),
overlappingPairCache.get(), solver.get(),
@ -39,8 +40,8 @@ void reset_player(player_t *player) {
if (player->body.get() == 0)
return;
if (player->team) {
player->body->getWorldTransform().setOrigin(btVector3(player->team->x,
player->team->y, player->team->z));
player->body->getWorldTransform().setOrigin(
btVector3(player->team->x, player->team->y, player->team->z));
} else {
player->body->getWorldTransform().setOrigin(btVector3(0, 0, 0));
}
@ -96,8 +97,8 @@ void setup_bomb(bomb_t *bomb) {
}
void Game::loadLevelShape() {
levelMesh = tlLoadTrimesh("data/level.obj", TL_FVF_XYZ | TL_FVF_UV
| TL_FVF_NORMAL);
levelMesh = tlLoadTrimesh("data/level.obj",
TL_FVF_XYZ | TL_FVF_UV | TL_FVF_NORMAL);
if (levelMesh == 0)
throw("level mesh not found! (data/level.obj)");
@ -124,8 +125,8 @@ void Game::loadLevelShape() {
}
void Game::loadShipShape() {
shipMesh = tlLoadTrimesh("data/ship.obj", TL_FVF_XYZ | TL_FVF_UV
| TL_FVF_NORMAL);
shipMesh = tlLoadTrimesh("data/ship.obj",
TL_FVF_XYZ | TL_FVF_UV | TL_FVF_NORMAL);
/*
btIndexedMesh sim;
sim.m_numTriangles = shipMesh->face_count;
@ -151,8 +152,9 @@ void Game::loadShipShape() {
shipShape.reset(_shipShape);
*/
shipShape.reset(new btBoxShape(btVector3(btScalar(1.5), btScalar(1.5),
btScalar(1.5))));
shipShape.reset(
new btBoxShape(
btVector3(btScalar(1.5), btScalar(1.5), btScalar(1.5))));
}
void Game::setupLevel() {
@ -283,8 +285,8 @@ void Game::update_players(double dt) {
p->state->getWorldTransform(player_transform);
player_transform.getOpenGLMatrix(p->m);
double distance2 =
player_transform.getOrigin().distance2(team_position);
double distance2 = player_transform.getOrigin().distance2(
team_position);
if (distance2 < 10000) {
p->team->points += p->points;
p->points = 0;
@ -478,3 +480,5 @@ point_t *Game::spawn_point() {
void Game::set_master(int master) {
this->master = master;
}
} // namespace grln

View File

@ -20,6 +20,8 @@ class btTriangleIndexVertexArray;
class btRigidBody;
class btMotionState;
namespace gln {
typedef struct Team Team;
typedef struct player_t player_t;
class Game;
@ -122,4 +124,6 @@ private:
Schedule slaveUpdate;
};
} // namespace grln
#endif

View File

@ -1,10 +1,3 @@
/*
* network.cpp
*
* Created on: 12.01.2011
* Author: gmueller
*/
#include "Network.h"
#include "btBulletDynamicsCommon.h"
@ -14,6 +7,8 @@
#include <typeinfo>
#include <istream>
namespace gln {
Network::Network(Game *game) :
game(game), client_peer(0) {
}
@ -56,8 +51,8 @@ void Network::initialize(const std::string &hostname) {
}
/* Wait up to 5 seconds for the connection attempt to succeed. */
if (enet_host_service(host, &event, 2000) > 0 && event.type
== ENET_EVENT_TYPE_CONNECT) {
if (enet_host_service(host, &event, 2000) > 0
&& event.type == ENET_EVENT_TYPE_CONNECT) {
std::cout << "[Network] connected" << std::endl;
} else {
/* Either the 5 seconds are up or a disconnect event was */
@ -134,126 +129,77 @@ T *_message_cast(void *p, size_t l) {
#define EMIT_END() out << YAML::EndMap;return out;}
// player_spawn_message_t
EMIT_START(player_spawn_message_t)
EMIT_FIELD(team_id)
EMIT_FIELD(player_id)
EMIT_START(player_spawn_message_t) EMIT_FIELD(team_id)EMIT_FIELD(player_id)
EMIT_END()
PARSE_START(player_spawn_message_t) PARSE_FIELD(team_id)
PARSE_FIELD(player_id)PARSE_END()
// player_kill_message_t
EMIT_START(player_kill_message_t)
EMIT_FIELD(player_id)
EMIT_START(player_kill_message_t) EMIT_FIELD(player_id)
EMIT_END()
PARSE_START(player_kill_message_t) PARSE_FIELD(player_id)PARSE_END()
// accept_message_t
EMIT_START(accept_message_t)
EMIT_FIELD(player_id)
EMIT_START(accept_message_t) EMIT_FIELD(player_id)
EMIT_END()
PARSE_START(accept_message_t) PARSE_FIELD(player_id)PARSE_END()
// player_update_message_t
EMIT_START(player_update_message_t)
EMIT_FIELD(player_id)
EMIT_FIELD(x)
EMIT_FIELD(y)
EMIT_FIELD(z)
EMIT_FIELD(vx)
EMIT_FIELD(vy)
EMIT_FIELD(vz)
EMIT_FIELD(points)
EMIT_START(player_update_message_t) EMIT_FIELD(player_id)EMIT_FIELD(x)EMIT_FIELD(
y)EMIT_FIELD(z)EMIT_FIELD(vx)EMIT_FIELD(vy)EMIT_FIELD(vz)EMIT_FIELD(
points)
EMIT_END()
PARSE_START(player_update_message_t) PARSE_FIELD(player_id)
PARSE_FIELD(x)
PARSE_FIELD(y)
PARSE_FIELD(z)
PARSE_FIELD(vx)
PARSE_FIELD(vy)
PARSE_FIELD(vz)
PARSE_START(player_update_message_t) PARSE_FIELD(player_id)PARSE_FIELD(x)PARSE_FIELD(
y)PARSE_FIELD(z)PARSE_FIELD(vx)PARSE_FIELD(vy)PARSE_FIELD(vz)
PARSE_FIELD(points)PARSE_END()
// player_accelerate_message_t
EMIT_START(player_accelerate_message_t)
EMIT_FIELD(player_id)
EMIT_FIELD(x)
EMIT_FIELD(y)
EMIT_FIELD(z)
EMIT_START(player_accelerate_message_t) EMIT_FIELD(player_id)EMIT_FIELD(x)EMIT_FIELD(
y)EMIT_FIELD(z)EMIT_FIELD(rx)EMIT_FIELD( ry)EMIT_FIELD(rz)
EMIT_END()
PARSE_START(player_accelerate_message_t) PARSE_FIELD(player_id)
PARSE_FIELD(x)
PARSE_FIELD(y)
PARSE_FIELD(z)PARSE_END()
PARSE_START(player_accelerate_message_t) PARSE_FIELD(player_id)PARSE_FIELD(x)PARSE_FIELD(
y)PARSE_FIELD(rx)PARSE_FIELD( ry)
PARSE_FIELD(rz)PARSE_END()
// bomb_drop_meesage_t
EMIT_START(bomb_drop_meesage_t)
EMIT_FIELD(x)
EMIT_FIELD(y)
EMIT_FIELD(z)
EMIT_FIELD(vx)
EMIT_FIELD(vy)
EMIT_FIELD(vz)
EMIT_FIELD(ttl)
EMIT_START(bomb_drop_meesage_t) EMIT_FIELD(x)EMIT_FIELD(y)EMIT_FIELD(z)EMIT_FIELD(
vx)EMIT_FIELD(vy)EMIT_FIELD(vz)EMIT_FIELD(ttl)
EMIT_END()
PARSE_START(bomb_drop_meesage_t) PARSE_FIELD(x)
PARSE_FIELD(y)
PARSE_FIELD(z)
PARSE_FIELD(vx)
PARSE_FIELD(vy)
PARSE_FIELD(vz)
PARSE_START(bomb_drop_meesage_t) PARSE_FIELD(x)PARSE_FIELD(y)PARSE_FIELD(z)PARSE_FIELD(
vx)PARSE_FIELD(vy)PARSE_FIELD(vz)
PARSE_FIELD(ttl)PARSE_END()
// bomb_update_meesage_t
EMIT_START(bomb_update_meesage_t)
EMIT_FIELD(bomb_index)
EMIT_FIELD(x)
EMIT_FIELD(y)
EMIT_FIELD(z)
EMIT_FIELD(vx)
EMIT_FIELD(vy)
EMIT_FIELD(vz)
EMIT_FIELD(ttl)
EMIT_START(bomb_update_meesage_t) EMIT_FIELD(bomb_index)EMIT_FIELD(x)EMIT_FIELD(
y)EMIT_FIELD(z)EMIT_FIELD(vx)EMIT_FIELD(vy)EMIT_FIELD(vz)EMIT_FIELD(
ttl)
EMIT_END()
PARSE_START(bomb_update_meesage_t) PARSE_FIELD(bomb_index)
PARSE_FIELD(x)
PARSE_FIELD(y)
PARSE_FIELD(z)
PARSE_FIELD(vx)
PARSE_FIELD(vy)
PARSE_FIELD(vz)
PARSE_START(bomb_update_meesage_t) PARSE_FIELD(bomb_index)PARSE_FIELD(x)PARSE_FIELD(
y)PARSE_FIELD(z)PARSE_FIELD(vx)PARSE_FIELD(vy)PARSE_FIELD(vz)
PARSE_FIELD(ttl)PARSE_END()
// point_update_mesage_t
EMIT_START(point_update_mesage_t)
EMIT_FIELD(point_index)
EMIT_FIELD(x)
EMIT_FIELD(y)
EMIT_FIELD(z)
EMIT_FIELD(status)
EMIT_START(point_update_mesage_t) EMIT_FIELD(point_index)EMIT_FIELD(x)EMIT_FIELD(
y)EMIT_FIELD(z)EMIT_FIELD(status)
EMIT_END()
PARSE_START(point_update_mesage_t) PARSE_FIELD(point_index)
PARSE_FIELD(x)
PARSE_FIELD(y)
PARSE_FIELD(z)
PARSE_START(point_update_mesage_t) PARSE_FIELD(point_index)PARSE_FIELD(x)PARSE_FIELD(
y)PARSE_FIELD(z)
PARSE_FIELD(status)PARSE_END()
// team_update_message_t
EMIT_START(team_update_message_t)
EMIT_FIELD(team_id)
EMIT_FIELD(points)
EMIT_FIELD(wins)
EMIT_START(team_update_message_t) EMIT_FIELD(team_id)EMIT_FIELD(points)EMIT_FIELD(
wins)
EMIT_END()
PARSE_START(team_update_message_t) PARSE_FIELD(team_id)
PARSE_FIELD(points)
PARSE_START(team_update_message_t) PARSE_FIELD(team_id)PARSE_FIELD(points)
PARSE_FIELD(wins)PARSE_END()
void Network::dispatch(enet_uint8 *data, size_t length) {
@ -418,9 +364,8 @@ void Network::service(uint32_t timeout) {
spwan_msg.player_id = game->player[i].id;
YAML::Emitter em;
em << spwan_msg;
ENetPacket * packet = enet_packet_create(
(uint8_t *) em.c_str(), em.size(),
ENET_PACKET_FLAG_RELIABLE);
ENetPacket * packet = enet_packet_create((uint8_t *) em.c_str(),
em.size(), ENET_PACKET_FLAG_RELIABLE);
enet_peer_send(event.peer, 0, packet);
}
@ -436,9 +381,8 @@ void Network::service(uint32_t timeout) {
YAML::Emitter em;
em << msg;
ENetPacket * packet = enet_packet_create(
(uint8_t *) em.c_str(), em.size(),
ENET_PACKET_FLAG_RELIABLE);
ENetPacket * packet = enet_packet_create((uint8_t *) em.c_str(),
em.size(), ENET_PACKET_FLAG_RELIABLE);
enet_peer_send(event.peer, 0, packet);
}
@ -453,9 +397,8 @@ void Network::service(uint32_t timeout) {
YAML::Emitter em;
em << spwan_msg;
ENetPacket * packet = enet_packet_create(
(uint8_t *) em.c_str(), em.size(),
ENET_PACKET_FLAG_RELIABLE);
ENetPacket * packet = enet_packet_create((uint8_t *) em.c_str(),
em.size(), ENET_PACKET_FLAG_RELIABLE);
enet_host_broadcast(host, 0, packet);
}
{
@ -465,9 +408,8 @@ void Network::service(uint32_t timeout) {
YAML::Emitter em;
em << msg;
ENetPacket * packet = enet_packet_create(
(uint8_t *) em.c_str(), em.size(),
ENET_PACKET_FLAG_RELIABLE);
ENetPacket * packet = enet_packet_create((uint8_t *) em.c_str(),
em.size(), ENET_PACKET_FLAG_RELIABLE);
enet_peer_send(event.peer, 0, packet);
}
// send state
@ -527,3 +469,5 @@ void Network::sendMessage(uint8_t *data, size_t length) {
dispatch(data, length);
}
}
} // namespace grln

View File

@ -1,10 +1,3 @@
/*
* network.h
*
* Created on: 12.01.2011
* Author: gmueller
*/
#ifndef NETWORK_H_
#define NETWORK_H_
@ -16,6 +9,8 @@
#include <string>
namespace gln {
#define EMIT_DEFINE(msg) YAML::Emitter& operator <<(YAML::Emitter& out, const msg& m);
#define MESSAGE_PLAYER_SPAWN 0
@ -71,6 +66,7 @@ struct player_accelerate_message_t {
};
uint16_t player_id;
double x, y, z;
double rx, ry, rz;
};
EMIT_DEFINE(player_accelerate_message_t)
@ -131,4 +127,6 @@ protected:
ENetPeer *client_peer;
};
} // namespace gln
#endif /* NETWORK_H_ */

View File

@ -1,12 +1,6 @@
/*
* Schedule.h
*
* Created on: 12.06.2010
* Author: gmueller
*/
#ifndef SCHEDULE_H_
#define SCHEDULE_H_
namespace gln {
class Schedule {
double last;
@ -53,4 +47,5 @@ public:
}
}
};
} // namespace grln
#endif /* SCHEDULE_H_ */

View File

@ -1,12 +1,5 @@
/*
* Timer.cpp
*
* Created on: 12.01.2011
* Author: gmueller
*/
#include "Time.h"
namespace gln {
#ifdef _WIN32
#define MEAN_AND_LEAN
@ -128,3 +121,4 @@ void PerformanceTimer::set(double t) {
}
#endif // else _WIN32
} // namespace grln

View File

@ -1,17 +1,11 @@
/*
* Timer.h
*
* Created on: 12.01.2011
* Author: gmueller
*/
#ifndef TIME_H_
#define TIME_H_
namespace gln {
class PerformanceTimer {
public:
static double get();
static void set(double);
};
} // namespace grln
#endif /* TIME_H_ */

View File

@ -3,18 +3,21 @@
#include <iostream>
#include <csignal>
Application app;
#include "Config.h"
gln::Application app;
void terminate(int param) {
app.stop();
}
int main(int argc, const char **argv) {
Arguments args(argc, argv);
gln::Config config;
config.load(argc, argv);
try {
::signal(SIGTERM, terminate);
app.setMaster(true);
app.initialize(args);
app.initialize(config);
while (app.isRunning())
app.update();
app.shutdown();