Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-05-01 16:02:51 +0000
committerStijn Buys <ingar@osirion.org>2008-05-01 16:02:51 +0000
commit4e5343ce9aa83a5c0b04bf744dd287fb56ff39fc (patch)
tree2f5944d3426529a973e78137f8ce5a9a29a7c54f /src
parentf5266b403c50cb2b6d712e6d8f41b62ad2433efb (diff)
various silly fixes
Diffstat (limited to 'src')
-rw-r--r--src/client/client.cc34
-rw-r--r--src/core/entity.h3
-rw-r--r--src/core/gameconnection.cc22
-rw-r--r--src/core/netserver.cc2
-rw-r--r--src/math/vector3f.h4
-rw-r--r--src/render/draw.cc92
6 files changed, 65 insertions, 92 deletions
diff --git a/src/client/client.cc b/src/client/client.cc
index 2079c71..c607c64 100644
--- a/src/client/client.cc
+++ b/src/client/client.cc
@@ -4,6 +4,12 @@
the terms and conditions of the GNU General Public License version 2
*/
+#include <SDL/SDL.h>
+
+#include <iostream>
+#include <cmath>
+#include <iomanip>
+
#include "client/chat.h"
#include "client/client.h"
#include "client/video.h"
@@ -13,13 +19,6 @@
#include "client/view.h"
#include "core/core.h"
-// SDL headers
-#include <SDL/SDL.h>
-
-// C++ headers
-#include <iostream>
-#include <cmath>
-
namespace client
{
@@ -128,26 +127,27 @@ void Client::run()
Uint32 client_framerate = (Uint32)(1000/120);
Uint32 elapsed = 0;
-
+
while (true) {
- if (cl_framerate->value())
- client_framerate = (Uint32) (1000.0f / cl_framerate->value());
-
Uint32 chrono = SDL_GetTicks();
core::Application::frame((float)elapsed / 1000.0f);
video::frame((float)elapsed / 1000.0f);
input::frame((float)elapsed / 1000.0f);
- // sleep
Uint32 current = SDL_GetTicks();
-
elapsed = current - chrono;
- if (elapsed < client_framerate) {
- SDL_Delay(client_framerate - elapsed);
- elapsed = client_framerate;
- }
+ if (cl_framerate->value()) {
+ client_framerate = (Uint32) (1000.0f / cl_framerate->value());
+ if (client_framerate && (elapsed < client_framerate)) {
+ SDL_Delay(client_framerate - elapsed);
+ elapsed = client_framerate;
+ }
+ };
+
+ //con_debug << "tick " << std::setw(8) << chrono << " " << std::setw(8) << current << " " << elapsed;
+
}
}
diff --git a/src/core/entity.h b/src/core/entity.h
index 46dd36c..05ca641 100644
--- a/src/core/entity.h
+++ b/src/core/entity.h
@@ -32,6 +32,9 @@ public:
/// Entity flags
enum Flags {Static=1, Solid=2, Bright=4};
+ /// Entity render state flags
+ enum State {InRange=1, InCloseRange=2};
+
/// Entity type constants
enum Type {Default=0, Dynamic=1, Controlable=2, Globe=3};
diff --git a/src/core/gameconnection.cc b/src/core/gameconnection.cc
index 923d9a3..4f410d5 100644
--- a/src/core/gameconnection.cc
+++ b/src/core/gameconnection.cc
@@ -88,29 +88,18 @@ void GameConnection::frame(float seconds)
return;
}
-
+ connection_frametime += seconds;
+
float f = 0;
- if (core::Cvar::sv_framerate->value()) {
- connection_frametime += seconds;
+ if (core::Cvar::sv_framerate->value()) {
f = 1.0f / core::Cvar::sv_framerate->value();
if (connection_frametime < f) {
- /*
- // run client prediction
- std::map<unsigned int, Entity *>::iterator it;
- for (it=Entity::registry.begin(); it != Entity::registry.end(); it++) {
- Entity *entity = (*it).second;
- if ((entity->type() == Entity::Controlable) || (entity->type() == Entity::Dynamic)) {
- entity->frame(seconds);
- }
- }
- */
return;
}
- } else {
- connection_frametime = seconds;
}
-
+
connection_network->frame(connection_frametime);
+ connection_frametime = 0;
if (localcontrol() && localcontrol()->dirty()) {
std::ostringstream netmsg;
@@ -135,7 +124,6 @@ void GameConnection::frame(float seconds)
}
connection_network->transmit();
- connection_frametime += f;
}
}
diff --git a/src/core/netserver.cc b/src/core/netserver.cc
index 064229b..50702ac 100644
--- a/src/core/netserver.cc
+++ b/src/core/netserver.cc
@@ -178,7 +178,7 @@ void NetServer::receive()
timeval timeout;
timeout.tv_sec = 0;
- timeout.tv_usec = 25000;
+ timeout.tv_usec = 500;
fd_set readset = serverset;
int nb = select(fd()+1, &readset, NULL, NULL, &timeout);
diff --git a/src/math/vector3f.h b/src/math/vector3f.h
index 1b4028f..25fcbff 100644
--- a/src/math/vector3f.h
+++ b/src/math/vector3f.h
@@ -93,7 +93,7 @@ public:
/*! WARNING: range is not checked
* @param index the index of the element to assign to ( 0 <= index < 3 )
*/
- inline float& operator[](const unsigned int index) {
+ inline float& operator[](const size_t index) {
return coord[index];
}
@@ -101,7 +101,7 @@ public:
/*! WARNING: range is not checked
* @param index the index of the element to return ( 0 <= index < 3 )
*/
- inline float operator[](const unsigned int index) const {
+ inline float operator[](const size_t index) const {
return coord[index];
}
diff --git a/src/render/draw.cc b/src/render/draw.cc
index 5697cae..d125420 100644
--- a/src/render/draw.cc
+++ b/src/render/draw.cc
@@ -45,14 +45,12 @@ float angle = 0;
inline bool test_draw_distance(core::Entity *entity)
{
- return (entity->model() &&
- (math::distancesquared(camera_eye, entity->location()) <= (drawdistance*drawdistance*entity->model()->radius())));
+ return (entity->entity_renderstate > 0);
}
inline bool test_drawfx_distance(core::Entity *entity)
{
- return (entity->model() &&
- (math::distancesquared(camera_eye, entity->location()) <= (drawfxdistance*drawfxdistance*entity->model()->radius())));
+ return ((entity->entity_renderstate & core::Entity::InCloseRange) == core::Entity::InCloseRange);
}
@@ -247,6 +245,37 @@ void draw_model_shield(core::EntityControlable *entity)
/* ----- Render passes --------------------------------------------- */
+/* calculate entity visibility */
+void pass_visibility()
+{
+ std::map<unsigned int, core::Entity *>::iterator it;
+ for (it=core::Entity::registry.begin(); it != core::Entity::registry.end(); it++) {
+
+ core::Entity *entity = (*it).second;
+ entity->entity_renderstate = 0;
+
+ // load entity models if necessary
+ if (!entity->model() && entity->modelname().size()) {
+ entity->entity_model = core::Model::get(entity->modelname());
+
+ if (!entity->model())
+ entity->entity_modelname.clear();
+ }
+
+ if (entity->model()) {
+ float dq = math::distancesquared(camera_eye, entity->location());
+
+ if (dq <= drawfxdistance*drawfxdistance*entity->model()->radius()) {
+ // entites withint drawfxdistance
+ entity->entity_renderstate = core::Entity::InCloseRange;
+ } else if (dq <= drawdistance*drawdistance*entity->model()->radius()) {
+ // entities within drawdistance
+ entity->entity_renderstate = core::Entity::InRange;
+ }
+ }
+ }
+}
+
/* Draw entities without model */
void draw_pass_default()
{
@@ -298,21 +327,9 @@ void draw_pass_model_vertex()
for (it=core::Entity::registry.begin(); it != core::Entity::registry.end(); it++) {
core::Entity *entity = (*it).second;
-
- // load entity models if necessary
- if (!entity->model() && entity->modelname().size()) {
- entity->entity_model = core::Model::get(entity->modelname());
-
- if (!entity->model())
- entity->entity_modelname.clear();
- }
-
-
if (test_draw_distance(entity)) {
gl::push();
gl::translate(entity->location());
- // FIXME
- //gl::rotate(entity->direction(), 0.0f, 0.0f, 1.0f );
gl::multmatrix(entity->axis());
draw_model_vertex(entity);
@@ -333,8 +350,6 @@ void draw_pass_model_evertex()
if (test_draw_distance(entity)) {
gl::push();
gl::translate(entity->location());
- // FIXME
- //gl::rotate(entity->direction(), 0.0f, 0.0f, 1.0f );
gl::multmatrix(entity->axis());
draw_model_evertex(entity);
@@ -369,7 +384,6 @@ void draw_pass_model_fx() {
}
/* draw model lights */
-
void draw_pass_model_lights()
{
//glPointSize(10);
@@ -403,6 +417,8 @@ void draw_pass_model_lights()
gl::vertex(location + (camera_axis.up() * -1 + camera_axis.left()) * light_size);
glTexCoord2f(-1,1);
gl::vertex(location + (camera_axis.up() * -1 - camera_axis.left()) * light_size);
+
+ Stats::quads++;
}
}
}
@@ -472,42 +488,6 @@ void draw_pass_spacegrid()
gl::pop();
}
-void draw_local_axis()
-{
- if (!core::localcontrol())
- return;
-
- gl::push();
- gl::translate(core::localcontrol()->location());
-
- gl::begin(gl::Lines);
- gl::color(0.5f, 0.0f,0.0f);
- gl::vertex(core::localcontrol()->axis()[0] * -1.0f);
- gl::color(1.0f, 0.0f, 0.0f);
- gl::vertex(core::localcontrol()->axis()[0]);
-
- gl::color(0.5f, 0.5f,0.0f);
- gl::vertex(core::localcontrol()->axis()[1] * -1.0f);
- gl::color(1.0f, 1.0f, 0.0f);
- gl::vertex(0.0f, 0.0f, 0.0f);
-
- gl::color(0.5f, 0.5f,0.0f);
- gl::vertex(core::localcontrol()->axis()[1]);
- gl::color(1.0f, 1.0f, 0.0f);
- gl::vertex(0.0f, 0.0f, 0.0f);
-
- gl::color(0.0f, 0.5f,0.0f);
- gl::vertex(core::localcontrol()->axis()[2] * -1.0f);
- gl::color(0.0f, 1.0f, 0.0f);
- gl::vertex(0.0f, 0.0f, 0.0f);
-
- gl::color(0.0f, 0.5f,0.0f);
- gl::vertex(core::localcontrol()->axis()[2]);
- gl::color(0.0f, 1.0f, 0.0f);
- gl::vertex(0.0f, 0.0f, 0.0f);
-
- gl::pop();
-}
/* ----- Main draw routine ----------------------------------------- */
void draw(math::Axis const &axis, math::Vector3f const &eye, math::Vector3f const &target, float seconds)
@@ -523,6 +503,8 @@ void draw(math::Axis const &axis, math::Vector3f const &eye, math::Vector3f cons
camera_target.assign(target);
camera_eye.assign(eye);
camera_axis.assign(axis);
+
+ pass_visibility();
gl::enable(GL_DEPTH_TEST); // enable depth buffer writing
gl::enable(GL_CULL_FACE); // enable culling