minor changes

This commit is contained in:
Gero Müller 2011-10-07 12:07:36 +02:00
parent dafe52c4cd
commit dbed4abb0b
4 changed files with 70 additions and 52 deletions

View File

@ -1,3 +1,5 @@
syntax: regexp syntax: regexp
^build$ ^build$
syntax: regexp
^libs/log4cplus/src/Makefile\.am$

View File

@ -16,6 +16,7 @@ endif(UNIX)
include_directories (${GREMLIN_SOURCE_DIR}/libs/glfw/include) include_directories (${GREMLIN_SOURCE_DIR}/libs/glfw/include)
include_directories (${GREMLIN_SOURCE_DIR}/libs/spark/include) include_directories (${GREMLIN_SOURCE_DIR}/libs/spark/include)
include_directories (${GREMLIN_SOURCE_DIR}/libs/enet/include) include_directories (${GREMLIN_SOURCE_DIR}/libs/enet/include)
include_directories (${GREMLIN_SOURCE_DIR}/libs/log4cplus/include)
include_directories (${GREMLIN_SOURCE_DIR}/libs/bullet) include_directories (${GREMLIN_SOURCE_DIR}/libs/bullet)
include_directories (${GREMLIN_SOURCE_DIR}/libs/yaml-cpp/include) include_directories (${GREMLIN_SOURCE_DIR}/libs/yaml-cpp/include)
include_directories (${GREMLIN_SOURCE_DIR}/libs/trimeshloader/include) include_directories (${GREMLIN_SOURCE_DIR}/libs/trimeshloader/include)
@ -26,6 +27,7 @@ add_subdirectory (libs/enet)
add_subdirectory (libs/pugixml) add_subdirectory (libs/pugixml)
add_subdirectory (libs/bullet) add_subdirectory (libs/bullet)
add_subdirectory (libs/yaml-cpp) add_subdirectory (libs/yaml-cpp)
add_subdirectory (libs/log4cplus)
add_subdirectory (libs/trimeshloader) add_subdirectory (libs/trimeshloader)
add_subdirectory (src/common) add_subdirectory (src/common)
add_subdirectory (src/server) add_subdirectory (src/server)

View File

@ -10,6 +10,7 @@
#include "Explosion.h" #include "Explosion.h"
#include "Time.h" #include "Time.h"
#include "btBulletDynamicsCommon.h"
#include <GL/glfw.h> #include <GL/glfw.h>
#include <stdio.h> #include <stdio.h>
@ -30,9 +31,9 @@ void setup_light() {
glLightfv(GL_LIGHT0, GL_AMBIENT, LightAmbient); glLightfv(GL_LIGHT0, GL_AMBIENT, LightAmbient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, LightDiffuse); glLightfv(GL_LIGHT0, GL_DIFFUSE, LightDiffuse);
glLightfv(GL_LIGHT0, GL_POSITION, LightPosition); glLightfv(GL_LIGHT0, GL_POSITION, LightPosition);
glEnable( GL_LIGHT0); glEnable(GL_LIGHT0);
glEnable( GL_LIGHTING); glEnable(GL_LIGHTING);
} }
void setup_opengl() { void setup_opengl() {
@ -49,14 +50,14 @@ void setup_opengl() {
glfwEnable(GLFW_STICKY_KEYS); glfwEnable(GLFW_STICKY_KEYS);
// general settings // general settings
glShadeModel( GL_SMOOTH); glShadeModel(GL_SMOOTH);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glEnable( GL_CULL_FACE); glEnable(GL_CULL_FACE);
// setup depth buffer // setup depth buffer
glClearDepth(1.0f); glClearDepth(1.0f);
glEnable( GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
glDepthFunc( GL_LEQUAL); glDepthFunc(GL_LEQUAL);
// Enable vertical sync (on cards that support it) // Enable vertical sync (on cards that support it)
glfwSwapInterval(0); glfwSwapInterval(0);
@ -65,7 +66,7 @@ void setup_opengl() {
void draw_team(Team *team) { void draw_team(Team *team) {
size_t i = 0; size_t i = 0;
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, team->color); glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, team->color);
glMatrixMode( GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glPushMatrix(); glPushMatrix();
glTranslated(team->x, team->y, team->z); glTranslated(team->x, team->y, team->z);
gluSphere(quadratic, 50.f, 32, 32); gluSphere(quadratic, 50.f, 32, 32);
@ -76,12 +77,12 @@ void Client::drawPlayer(player_t *player) {
if (player->status == 0) if (player->status == 0)
return; return;
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, player->team->color); glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, player->team->color);
glMatrixMode( GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glPushMatrix(); glPushMatrix();
glMultMatrixf(player->m); glMultMatrixf(player->m);
glEnableClientState( GL_VERTEX_ARRAY); glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState( GL_TEXTURE_COORD_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState( GL_NORMAL_ARRAY); glEnableClientState(GL_NORMAL_ARRAY);
glVertexPointer(3, GL_FLOAT, game.shipMesh->vertex_size, glVertexPointer(3, GL_FLOAT, game.shipMesh->vertex_size,
game.shipMesh->vertices); game.shipMesh->vertices);
glTexCoordPointer(2, GL_FLOAT, game.shipMesh->vertex_size, glTexCoordPointer(2, GL_FLOAT, game.shipMesh->vertex_size,
@ -103,18 +104,19 @@ void draw_bomb(bomb_t *bomb) {
return; return;
GLfloat red[] = { 1.0f, 0.0f, 0.0f, 1.0f }; GLfloat red[] = { 1.0f, 0.0f, 0.0f, 1.0f };
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red); glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red);
glMatrixMode( GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glPushMatrix(); glPushMatrix();
glTranslated(bomb->x, bomb->y, bomb->z); glTranslated(bomb->x, bomb->y, bomb->z);
gluSphere(quadratic, 3.f, 4, 4); gluSphere(quadratic, 0.5f, 4, 4);
glPopMatrix(); glPopMatrix();
} }
void draw_point(point_t *point) { void draw_point(point_t *point) {
if (point->status == 0) if (point->status == 0)
return; return;
GLfloat red[] = { 0.0f, 0.0f, 1.0f, 1.0f }; GLfloat red[] = { 0.0f, 0.0f, 1.0f, 1.0f };
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red); glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red);
glMatrixMode( GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glPushMatrix(); glPushMatrix();
glTranslated(point->x, point->y, point->z); glTranslated(point->x, point->y, point->z);
gluSphere(quadratic, 3.f, 12, 12); gluSphere(quadratic, 3.f, 12, 12);
@ -172,7 +174,7 @@ void Client::drawLevel() {
if (wallTex == 0) { if (wallTex == 0) {
glGenTextures(1, &wallTex); glGenTextures(1, &wallTex);
glBindTexture(GL_TEXTURE_2D, wallTex); glBindTexture(GL_TEXTURE_2D, wallTex);
glEnable( GL_TEXTURE_2D); glEnable(GL_TEXTURE_2D);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 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_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
@ -181,20 +183,20 @@ void Client::drawLevel() {
glfwLoadTexture2D("data/wall.tga", GLFW_BUILD_MIPMAPS_BIT); glfwLoadTexture2D("data/wall.tga", GLFW_BUILD_MIPMAPS_BIT);
} else { } else {
glBindTexture(GL_TEXTURE_2D, wallTex); glBindTexture(GL_TEXTURE_2D, wallTex);
glEnable( GL_TEXTURE_2D); glEnable(GL_TEXTURE_2D);
} }
GLfloat red[] = { 1.0f, 1.0f, 1.0f, 1.0f }; GLfloat red[] = { 1.0f, 1.0f, 1.0f, 1.0f };
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red); glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red);
// Enable/Disable features // Enable/Disable features
glPushAttrib( GL_ENABLE_BIT); glPushAttrib(GL_ENABLE_BIT);
glEnable( GL_TEXTURE_2D); glEnable(GL_TEXTURE_2D);
//glDisable( GL_DEPTH_TEST); //glDisable( GL_DEPTH_TEST);
// glEnable( GL_LIGHTING); // glEnable( GL_LIGHTING);
// glDisable( GL_BLEND); // glDisable( GL_BLEND);
glColor4f(1, 1, 1, 1); glColor4f(1, 1, 1, 1);
glMatrixMode( GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glPushMatrix(); glPushMatrix();
#if 0 #if 0
glTranslated(2000.0, 0.0, 0.0); glTranslated(2000.0, 0.0, 0.0);
@ -293,9 +295,9 @@ void Client::drawLevel() {
glVertex3f(s, -s, -s); glVertex3f(s, -s, -s);
glEnd(); glEnd();
#else #else
glEnableClientState( GL_VERTEX_ARRAY); glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState( GL_TEXTURE_COORD_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState( GL_NORMAL_ARRAY); glEnableClientState(GL_NORMAL_ARRAY);
glVertexPointer(3, GL_FLOAT, game.levelMesh->vertex_size, glVertexPointer(3, GL_FLOAT, game.levelMesh->vertex_size,
game.levelMesh->vertices); game.levelMesh->vertices);
glTexCoordPointer(2, GL_FLOAT, game.levelMesh->vertex_size, glTexCoordPointer(2, GL_FLOAT, game.levelMesh->vertex_size,
@ -328,21 +330,24 @@ void Client::accelerate(double x, double y, double z) {
m << msg; m << msg;
network.send(m); network.send(m);
} }
#if 0
void Client::drop_bomb(double rx, double ry, double rz, double ttl) { void Client::drop_bomb(double rx, double ry, double rz, double ttl) {
bomb_drop_meesage_t msg; bomb_drop_meesage_t msg;
msg.x = game.local_player->x + rx * 20; btVector3 p = game.local_player->body->getWorldTransform().getOrigin();
msg.y = game.local_player->y + ry * 20; btVector3 v = game.local_player->body->getLinearVelocity();
msg.z = game.local_player->z + rz * 20;
msg.vx = game.local_player->vx + rx * 100; msg.x = p.x() + rx * 1;
msg.vy = game.local_player->vy + ry * 100; msg.y = p.y() + ry * 1;
msg.vz = game.local_player->vz + rz * 100; msg.z = p.z() + rz * 1;
msg.vx = v.x() + rx * 500;
msg.vy = v.y() + ry * 500;
msg.vz = v.z() + rz * 500;
msg.ttl = ttl; msg.ttl = ttl;
YAML::Emitter m; YAML::Emitter m;
m << msg; m << msg;
network.send(m); network.send(m);
} }
#endif
void Client::loadConsoleFont() { void Client::loadConsoleFont() {
GLuint font_id = 0; GLuint font_id = 0;
@ -373,15 +378,15 @@ void Client::prepareFrame(double rx, double ry, double rz) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Select and setup the projection matrix // Select and setup the projection matrix
glMatrixMode( GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glLoadIdentity(); glLoadIdentity();
gluPerspective(60.0f, (GLfloat) width / (GLfloat) height, 1.0f, 10000.0f); gluPerspective(60.0f, (GLfloat) width / (GLfloat) height, 1.0f, 10000.0f);
// Select and setup the modelview matrix // Select and setup the modelview matrix
glMatrixMode( GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); glLoadIdentity();
gluLookAt(camX, camY, camZ, camX + rx * 10.0f, camY + ry * 10.0f, camZ + rz gluLookAt(camX, camY, camZ, camX + rx * 10.0f, camY + ry * 10.0f,
* 10.0f, 0.0f, 1.0f, 0.0f); camZ + rz * 10.0f, 0.0f, 1.0f, 0.0f);
} }
@ -413,6 +418,9 @@ void Client::initialize(Arguments &arg) {
accelerate_schudule.setExact(true); accelerate_schudule.setExact(true);
accelerate_schudule.setInterval(0.05); accelerate_schudule.setInterval(0.05);
theta = 0.0;
phi = 0.0;
loadConsoleFont(); loadConsoleFont();
// setup signals // setup signals
@ -435,6 +443,7 @@ void Client::update() {
} }
last_x = x; last_x = x;
last_y = y; last_y = y;
double rx = cos(phi) * cos(theta); double rx = cos(phi) * cos(theta);
double ry = sin(theta); double ry = sin(theta);
double rz = sin(phi) * cos(theta); double rz = sin(phi) * cos(theta);
@ -453,55 +462,59 @@ void Client::update() {
} else if (glfwGetKey('D')) { } else if (glfwGetKey('D')) {
accelerate(-rz * v, 0, rx * v); accelerate(-rz * v, 0, rx * v);
} }
#if 0 #if 0
if (glfwGetKey(GLFW_KEY_SPACE)) { if (glfwGetKey(GLFW_KEY_SPACE)) {
accelerate(game.local_player->vx * -0.1, game.local_player->vy accelerate(game.local_player->vx * -0.1,
* -0.1, game.local_player->vz * -0.1); game.local_player->vy * -0.1, game.local_player->vz * -0.1);
} }
#endif #endif
} }
#if 0
if (glfwGetKey(GLFW_KEY_LCTRL)) { if (glfwGetKey(GLFW_KEY_LCTRL)) {
if (time - last_bomb > 1.0) { if (time - last_bomb > 1.0) {
last_bomb = time; last_bomb = time;
drop_bomb(rx, ry, rz, 5.0); drop_bomb(rx, ry, rz, 5.0);
} }
} }
#endif
if (game.local_player) { if (game.local_player) {
camX = game.local_player->m[12]; btVector3 p = game.local_player->body->getWorldTransform().getOrigin();
camY = game.local_player->m[13];
camZ = game.local_player->m[14]; camX = p.x();
camY = p.y();
camZ = p.z();
} else { } else {
camX = 1000.0; camX = 1000.0;
camY = 1000.0; camY = 1000.0;
camZ = 1000.0; camZ = 1000.0;
} }
prepareFrame(rx, ry, rz); prepareFrame(rx, ry, rz);
setup_light(); setup_light();
glEnable( GL_LIGHT0); glEnable(GL_LIGHT0);
glEnable( GL_LIGHTING); glEnable(GL_LIGHTING);
glEnable( GL_CULL_FACE); glEnable(GL_CULL_FACE);
glDisable( GL_TEXTURE_2D); glDisable(GL_TEXTURE_2D);
// for (size_t i = 0; i < game.teams.size(); i++) // for (size_t i = 0; i < game.teams.size(); i++)
// draw_team(&game.teams[i]); // draw_team(&game.teams[i]);
for (size_t i = 0; i < GAME_PLAYER_COUNT; i++) for (size_t i = 0; i < GAME_PLAYER_COUNT; i++)
drawPlayer(&game.player[i]); drawPlayer(&game.player[i]);
// for (size_t i = 0; i < GAME_BOMB_COUNT; i++) for (size_t i = 0; i < GAME_BOMB_COUNT; i++)
// draw_bomb(&game.bomb[i]); draw_bomb(&game.bomb[i]);
// //
// for (size_t i = 0; i < GAME_POINT_COUNT; i++) // for (size_t i = 0; i < GAME_POINT_COUNT; i++)
// draw_point(&game.point[i]); // draw_point(&game.point[i]);
drawLevel(); drawLevel();
explosion.update(dt * 1000.0, camX, camY, camZ);
explosion.render();
glDisable(GL_LIGHT0); glDisable(GL_LIGHT0);
glDisable(GL_LIGHTING); glDisable(GL_LIGHTING);
glDisable(GL_CULL_FACE); glDisable(GL_CULL_FACE);
explosion.update(dt * 1000.0, camX, camY, camZ);
explosion.render();
oglf_begin(&font, width, height); oglf_begin(&font, width, height);
size_t fy = 1; size_t fy = 1;
if (game.local_player) { if (game.local_player) {
@ -523,8 +536,8 @@ void Client::update() {
{ {
std::stringstream sstr; std::stringstream sstr;
sstr << "FPS: " << (int) (1 / dt) << " Time: " << floor(dt * 10000.0 sstr << "FPS: " << (int) (1 / dt) << " Time: "
+ 0.5) / 10.0; << floor(dt * 10000.0 + 0.5) / 10.0;
oglf_print(&font, 10, 25 * fy++, sstr.str().c_str()); oglf_print(&font, 10, 25 * fy++, sstr.str().c_str());
} }

View File

@ -214,6 +214,7 @@ player_t *Game::getFreePlayer() {
if (player[i].status == 0) if (player[i].status == 0)
return &player[i]; return &player[i];
} }
return 0;
} }
player_t *Game::spawnPlayer(Team *team) { player_t *Game::spawnPlayer(Team *team) {