Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2009-08-18 09:24:15 +0000
committerStijn Buys <ingar@osirion.org>2009-08-18 09:24:15 +0000
commitf030154fe727e25a2afe1f78b3998c2d2dba95e4 (patch)
treecd92baf9e4fa8a136523b9eb570e9811846c9250
parent5636fad174f0bcff857c357c394c4cc8d424b302 (diff)
astyle cleanup, corrects not loading of material textures
-rw-r--r--src/SDLMain.h3
-rw-r--r--src/audio/audio.cc34
-rw-r--r--src/audio/audio.h6
-rw-r--r--src/audio/buffers.cc21
-rw-r--r--src/audio/buffers.h10
-rw-r--r--src/audio/pcm.cc3
-rw-r--r--src/audio/pcm.h30
-rw-r--r--src/audio/sources.cc18
-rw-r--r--src/audio/sources.h18
-rw-r--r--src/audio/wav.cc19
-rw-r--r--src/audio/wav.h6
-rw-r--r--src/auxiliary/functions.cc20
-rw-r--r--src/auxiliary/functions.h25
-rw-r--r--src/client/action.cc3
-rw-r--r--src/client/action.h19
-rw-r--r--src/client/buymenu.cc38
-rw-r--r--src/client/buymenu.h4
-rw-r--r--src/client/chat.cc127
-rw-r--r--src/client/chat.h25
-rw-r--r--src/client/client.cc61
-rw-r--r--src/client/client.h29
-rw-r--r--src/client/clientext.h5
-rw-r--r--src/client/entitymenu.cc50
-rw-r--r--src/client/entitymenu.h10
-rw-r--r--src/client/hud.cc153
-rw-r--r--src/client/hud.h11
-rw-r--r--src/client/infowidget.cc30
-rw-r--r--src/client/infowidget.h8
-rw-r--r--src/client/input.cc119
-rw-r--r--src/client/joystick.cc33
-rw-r--r--src/client/joystick.h2
-rw-r--r--src/client/key.cc3
-rw-r--r--src/client/key.h35
-rw-r--r--src/client/keyboard.cc32
-rw-r--r--src/client/keyboard.h15
-rw-r--r--src/client/map.cc81
-rw-r--r--src/client/map.h11
-rw-r--r--src/client/notifications.cc12
-rw-r--r--src/client/notifications.h6
-rw-r--r--src/client/playerview.cc35
-rw-r--r--src/client/playerview.h27
-rw-r--r--src/client/soundext.cc54
-rw-r--r--src/client/soundext.h7
-rw-r--r--src/client/targeticonbutton.cc5
-rw-r--r--src/client/targeticonbutton.h6
-rw-r--r--src/client/targets.cc56
-rw-r--r--src/client/targets.h10
-rw-r--r--src/client/trademenu.cc2
-rw-r--r--src/client/trademenu.h4
-rw-r--r--src/client/video.cc104
-rw-r--r--src/client/video.h67
-rw-r--r--src/client/worldview.cc31
-rw-r--r--src/client/worldview.h11
-rw-r--r--src/core/application.cc50
-rw-r--r--src/core/application.h53
-rw-r--r--src/core/commandbuffer.cc116
-rw-r--r--src/core/commandbuffer.h5
-rw-r--r--src/core/cvar.cc8
-rw-r--r--src/core/cvar.h66
-rw-r--r--src/core/descriptions.cc47
-rw-r--r--src/core/descriptions.h55
-rw-r--r--src/core/entity.cc116
-rw-r--r--src/core/entity.h232
-rw-r--r--src/core/extension.h23
-rw-r--r--src/core/func.cc18
-rw-r--r--src/core/func.h36
-rw-r--r--src/core/gameconnection.cc12
-rw-r--r--src/core/gameconnection.h27
-rw-r--r--src/core/gameinterface.cc30
-rw-r--r--src/core/gameinterface.h28
-rw-r--r--src/core/gameserver.cc71
-rw-r--r--src/core/gameserver.h35
-rw-r--r--src/core/info.cc20
-rw-r--r--src/core/info.h26
-rw-r--r--src/core/item.cc4
-rw-r--r--src/core/item.h23
-rw-r--r--src/core/loader.cc5
-rw-r--r--src/core/loader.h13
-rw-r--r--src/core/message.h5
-rw-r--r--src/core/module.cc2
-rw-r--r--src/core/module.h32
-rw-r--r--src/core/netclient.cc44
-rw-r--r--src/core/netclient.h40
-rw-r--r--src/core/netconnection.cc158
-rw-r--r--src/core/netconnection.h52
-rw-r--r--src/core/netplayer.cc6
-rw-r--r--src/core/netplayer.h8
-rw-r--r--src/core/netserver.cc136
-rw-r--r--src/core/netserver.h44
-rw-r--r--src/core/parser.cc3
-rw-r--r--src/core/parser.h6
-rw-r--r--src/core/player.cc69
-rw-r--r--src/core/player.h90
-rw-r--r--src/core/range.h24
-rw-r--r--src/core/stats.cc5
-rw-r--r--src/core/stats.h3
-rw-r--r--src/core/timer.cc15
-rw-r--r--src/core/timer.h12
-rw-r--r--src/core/zone.cc38
-rw-r--r--src/core/zone.h60
-rw-r--r--src/dedicated/console.cc107
-rw-r--r--src/dedicated/console.h20
-rw-r--r--src/dedicated/dedicated.cc25
-rw-r--r--src/dedicated/dedicated.h12
-rw-r--r--src/filesystem/diskfile.cc7
-rw-r--r--src/filesystem/diskfile.h2
-rw-r--r--src/filesystem/file.cc3
-rw-r--r--src/filesystem/file.h13
-rw-r--r--src/filesystem/filestream.cc15
-rw-r--r--src/filesystem/filestream.h10
-rw-r--r--src/filesystem/filesystem.cc24
-rw-r--r--src/filesystem/filesystem.h3
-rw-r--r--src/filesystem/inifile.cc75
-rw-r--r--src/filesystem/inifile.h22
-rw-r--r--src/game/base/collision.cc16
-rw-r--r--src/game/base/collision.h12
-rw-r--r--src/game/base/game.cc86
-rw-r--r--src/game/base/game.h14
-rw-r--r--src/game/base/jumppoint.cc14
-rw-r--r--src/game/base/jumppoint.h25
-rw-r--r--src/game/base/navpoint.cc4
-rw-r--r--src/game/base/navpoint.h10
-rw-r--r--src/game/base/physics.cc45
-rw-r--r--src/game/base/physics.h55
-rw-r--r--src/game/base/planet.cc7
-rw-r--r--src/game/base/planet.h14
-rw-r--r--src/game/base/racetrack.cc19
-rw-r--r--src/game/base/racetrack.h21
-rw-r--r--src/game/base/ship.cc75
-rw-r--r--src/game/base/ship.h13
-rw-r--r--src/game/base/shipdealer.cc19
-rw-r--r--src/game/base/shipdealer.h15
-rw-r--r--src/game/base/shipmodel.cc43
-rw-r--r--src/game/base/shipmodel.h63
-rw-r--r--src/game/base/star.cc3
-rw-r--r--src/game/base/star.h10
-rw-r--r--src/game/base/station.cc9
-rw-r--r--src/game/base/station.h11
-rw-r--r--src/game/example/example.cc9
-rw-r--r--src/game/example/example.h4
-rw-r--r--src/game/example/spectator.cc9
-rw-r--r--src/game/example/spectator.h7
-rw-r--r--src/game/game.cc2
-rw-r--r--src/game/game.h6
-rw-r--r--src/game/intro/convoy.cc21
-rw-r--r--src/game/intro/convoy.h7
-rw-r--r--src/game/intro/intro.cc21
-rw-r--r--src/game/intro/intro.h4
-rw-r--r--src/math/axis.cc26
-rw-r--r--src/math/axis.h28
-rw-r--r--src/math/color.cc12
-rw-r--r--src/math/color.h32
-rw-r--r--src/math/functions.cc2
-rw-r--r--src/math/functions.h2
-rw-r--r--src/math/matrix4f.cc6
-rw-r--r--src/math/matrix4f.h18
-rw-r--r--src/math/vector2f.cc12
-rw-r--r--src/math/vector2f.h60
-rw-r--r--src/math/vector3f.cc46
-rw-r--r--src/math/vector3f.h86
-rw-r--r--src/model/asefile.cc86
-rw-r--r--src/model/asefile.h7
-rw-r--r--src/model/face.cc8
-rw-r--r--src/model/face.h53
-rw-r--r--src/model/fragment.cc5
-rw-r--r--src/model/fragment.h105
-rw-r--r--src/model/mapfile.cc438
-rw-r--r--src/model/mapfile.h84
-rw-r--r--src/model/material.cc53
-rw-r--r--src/model/material.h38
-rw-r--r--src/model/model.cc46
-rw-r--r--src/model/model.h96
-rw-r--r--src/model/parts.cc13
-rw-r--r--src/model/parts.h226
-rw-r--r--src/model/primitives.cc2
-rw-r--r--src/model/primitives.h23
-rw-r--r--src/model/quad.cc2
-rw-r--r--src/model/quad.h49
-rw-r--r--src/model/triangle.cc26
-rw-r--r--src/model/triangle.h160
-rw-r--r--src/model/vertexarray.cc90
-rw-r--r--src/model/vertexarray.h47
-rw-r--r--src/osirion.cc6
-rw-r--r--src/osiriond.cc4
-rw-r--r--src/render/camera.cc225
-rw-r--r--src/render/camera.h29
-rw-r--r--src/render/draw.cc369
-rw-r--r--src/render/draw.h13
-rw-r--r--src/render/dust.cc18
-rw-r--r--src/render/gl.cc111
-rw-r--r--src/render/gl.h312
-rw-r--r--src/render/image.cc28
-rw-r--r--src/render/image.h38
-rw-r--r--src/render/jpgfile.cc29
-rw-r--r--src/render/jpgfile.h5
-rw-r--r--src/render/particles.cc163
-rw-r--r--src/render/particles.h106
-rw-r--r--src/render/pngfile.cc79
-rw-r--r--src/render/pngfile.h5
-rw-r--r--src/render/render.cc15
-rw-r--r--src/render/render.h80
-rw-r--r--src/render/renderext.cc14
-rw-r--r--src/render/renderext.h31
-rw-r--r--src/render/screenshot.cc53
-rw-r--r--src/render/screenshot.h12
-rw-r--r--src/render/state.cc23
-rw-r--r--src/render/state.h26
-rw-r--r--src/render/text.cc36
-rw-r--r--src/render/text.h12
-rw-r--r--src/render/textures.cc32
-rw-r--r--src/render/tgafile.cc222
-rw-r--r--src/render/tgafile.h5
-rw-r--r--src/sys/consoleinterface.cc26
-rw-r--r--src/sys/consoleinterface.h54
-rw-r--r--src/sys/sys.cc44
-rw-r--r--src/ui/bitmap.cc2
-rw-r--r--src/ui/bitmap.h16
-rw-r--r--src/ui/button.cc8
-rw-r--r--src/ui/button.h22
-rw-r--r--src/ui/console.cc131
-rw-r--r--src/ui/console.h13
-rw-r--r--src/ui/container.cc2
-rw-r--r--src/ui/container.h6
-rw-r--r--src/ui/definitions.h4
-rw-r--r--src/ui/font.h24
-rw-r--r--src/ui/iconbutton.cc6
-rw-r--r--src/ui/iconbutton.h24
-rw-r--r--src/ui/inputbox.cc36
-rw-r--r--src/ui/inputbox.h16
-rw-r--r--src/ui/label.cc2
-rw-r--r--src/ui/label.h18
-rw-r--r--src/ui/menu.cc24
-rw-r--r--src/ui/menu.h14
-rwxr-xr-xsrc/ui/modelview.cc10
-rwxr-xr-xsrc/ui/modelview.h14
-rw-r--r--src/ui/paint.cc49
-rw-r--r--src/ui/paint.h5
-rw-r--r--src/ui/palette.cc30
-rw-r--r--src/ui/palette.h81
-rw-r--r--src/ui/scrollpane.cc28
-rw-r--r--src/ui/scrollpane.h14
-rw-r--r--src/ui/toolbar.cc3
-rw-r--r--src/ui/toolbar.h8
-rw-r--r--src/ui/ui.cc86
-rw-r--r--src/ui/ui.h60
-rw-r--r--src/ui/widget.cc44
-rw-r--r--src/ui/widget.h140
-rw-r--r--src/ui/window.cc2
-rw-r--r--src/ui/window.h8
249 files changed, 5278 insertions, 4440 deletions
diff --git a/src/SDLMain.h b/src/SDLMain.h
index 4683df5..e36ff81 100644
--- a/src/SDLMain.h
+++ b/src/SDLMain.h
@@ -7,5 +7,6 @@
#import <Cocoa/Cocoa.h>
-@interface SDLMain : NSObject
+@interface SDLMain :
+NSObject
@end
diff --git a/src/audio/audio.cc b/src/audio/audio.cc
index 2192e2f..e1eb0d3 100644
--- a/src/audio/audio.cc
+++ b/src/audio/audio.cc
@@ -29,7 +29,7 @@ void init()
}
// create the audio context
- audio_context = alcCreateContext(audio_device ,0);
+ audio_context = alcCreateContext(audio_device , 0);
if (!audio_context) {
alcCloseDevice(audio_device);
@@ -42,11 +42,11 @@ void init()
// clear errors
alGetError();
-
+
Buffers::init();
Sources::init();
-
+
//con_debug << " audio device ^B" << alcGetString(audio_device, ALC_DEFAULT_DEVICE_SPECIFIER) << std::endl;
// the "no sound" sound
@@ -64,12 +64,12 @@ void reset()
Buffers::shutdown();
Buffers::init();
Sources::init();
-
+
load("ui/nosnd");
load("ui/console");
}
-void load (const char *name)
+void load(const char *name)
{
Buffers::load(std::string(name));
}
@@ -91,7 +91,7 @@ void shutdown()
if (audio_device) {
alcCloseDevice(audio_device);
audio_device = 0;
- }
+ }
}
size_t play(const char *name)
@@ -101,14 +101,14 @@ size_t play(const char *name)
size_t buffer_index = Buffers::load(std::string(name));
- for (size_t i = 0; i < MAXUISOURCES; i++) {
+ for (size_t i = 0; i < MAXUISOURCES; i++) {
ALint srcstate = 0;
ALuint source = Sources::source(i);
alGetSourcei(source , AL_SOURCE_STATE , &srcstate);
if (srcstate != AL_PLAYING) {
Buffers::bind(source, buffer_index);
- alSourcef(source, AL_PITCH, 1.0);
- alSourcef(source, AL_GAIN, 1.0);
+ alSourcef(source, AL_PITCH, 1.0);
+ alSourcef(source, AL_GAIN, 1.0);
alSourcei(source, AL_SOURCE_RELATIVE, AL_TRUE);
ALfloat location[] = {0.0f, 0.0f, 0.0f};
alSourcefv(source, AL_POSITION, location);
@@ -121,7 +121,7 @@ size_t play(const char *name)
return 0;
}
-size_t play(size_t source_index, size_t buffer_index, float pitch, float gain)
+size_t play(size_t source_index, size_t buffer_index, float pitch, float gain)
{
if (!audio_context || !buffer_index)
return 0;
@@ -135,9 +135,9 @@ size_t play(size_t source_index, size_t buffer_index, float pitch, float gain)
Buffers::bind(source, buffer_index);
alSourcei(source, AL_SOURCE_RELATIVE, AL_FALSE);
alSourcef(source, AL_PITCH, pitch);
- alSourcef(source, AL_GAIN, gain);
+ alSourcef(source, AL_GAIN, gain);
- alSourcei(source, AL_LOOPING, AL_FALSE);
+ alSourcei(source, AL_LOOPING, AL_FALSE);
alSourceRewind(source);
alSourcePlay(source);
@@ -161,9 +161,9 @@ size_t loop(size_t source_index, size_t buffer_index, float pitch, float gain)
//alSourcef(source, AL_REFERENCE_DISTANCE, 2.0f); // might be the cause of cracks in the sound
alSourcei(source, AL_SOURCE_RELATIVE, AL_FALSE);
alSourcef(source, AL_PITCH, pitch);
- alSourcef(source, AL_GAIN, gain);
+ alSourcef(source, AL_GAIN, gain);
- alSourcei(source, AL_LOOPING, AL_TRUE);
+ alSourcei(source, AL_LOOPING, AL_TRUE);
alSourceRewind(source);
alSourcePlay(source);
@@ -190,7 +190,7 @@ void update_listener(math::Vector3f const &location, math::Axis const &axis, mat
alListenerfv(AL_POSITION, location.ptr());
ALfloat orientation[6];
- for (size_t i =0; i <3; i++) {
+ for (size_t i = 0; i < 3; i++) {
orientation[i] = axis.forward()[i];
orientation[i+3] = axis.up()[i];
}
@@ -208,7 +208,7 @@ void update_source(size_t source_index, math::Vector3f const & location, math::V
alSourcefv(source, AL_POSITION, location.ptr());
//alSourcefv(source, AL_VELOCITY, velocity.ptr());
alSourcef(source, AL_PITCH, pitch);
- alSourcef(source, AL_GAIN, gain);
+ alSourcef(source, AL_GAIN, gain);
}
-
+
}
diff --git a/src/audio/audio.h b/src/audio/audio.h
index 2849013..72a8fa4 100644
--- a/src/audio/audio.h
+++ b/src/audio/audio.h
@@ -45,16 +45,16 @@ void load(const char *name);
size_t play(const char *name);
/// playe a sound from a specific buffer on a specific source
-size_t play(size_t source_index, size_t buffer_index, float pitch=1.0f, float gain=1.0f);
+size_t play(size_t source_index, size_t buffer_index, float pitch = 1.0f, float gain = 1.0f);
/// play a looping sound on a specified source
-size_t loop( size_t source_index, const char *name, float pitch=1.0f, float gain=1.0f);
+size_t loop(size_t source_index, const char *name, float pitch = 1.0f, float gain = 1.0f);
/// play a looping sound from a specified buffer on a specified source
size_t loop(size_t source_index, size_t buffer_index, float pitch, float gain);
/// update source parameters
-void update_source(size_t source_index, math::Vector3f const & location, math::Vector3f const & velocity, float pitch=1.0f, float gain=1.0f);
+void update_source(size_t source_index, math::Vector3f const & location, math::Vector3f const & velocity, float pitch = 1.0f, float gain = 1.0f);
/// update listener parameters
void update_listener(math::Vector3f const &location, math::Axis const &axis, math::Vector3f const & velocity);
diff --git a/src/audio/buffers.cc b/src/audio/buffers.cc
index 774639e..7bf7eb1 100644
--- a/src/audio/buffers.cc
+++ b/src/audio/buffers.cc
@@ -11,7 +11,8 @@
#include "audio/wav.h"
#include "sys/sys.h"
-namespace audio {
+namespace audio
+{
std::map<std::string, size_t> Buffers::registry;
size_t Buffers::index;
@@ -19,8 +20,8 @@ ALuint Buffers::buffers[MAXBUFFERS];
void Buffers::init()
{
- clear();
-
+ clear();
+
alGenBuffers(MAXBUFFERS, buffers);
int error;
@@ -33,20 +34,20 @@ void Buffers::init()
void Buffers::shutdown()
{
alDeleteBuffers(MAXBUFFERS, buffers);
-
+
int error;
if ((error = alGetError()) != AL_NO_ERROR) {
con_warn << "Error " << error << " clearing OpenAL buffers!" << std::endl;
return;
}
-
+
clear();
}
void Buffers::clear()
{
registry.clear();
- memset(buffers,0, sizeof(buffers));
+ memset(buffers, 0, sizeof(buffers));
index = 0;
}
@@ -63,7 +64,7 @@ size_t Buffers::load(std::string name)
if (!pcm) {
registry[name] = 0;
return 0;
- }
+ }
if (index == MAXBUFFERS) {
con_error << "Buffer limit " << MAXBUFFERS << " exceeded!" << std::endl;
@@ -71,7 +72,7 @@ size_t Buffers::load(std::string name)
registry[name] = 0;
return 0;
}
-
+
ALenum format = 0;
if (pcm->bitspersample() == 16) {
if (pcm->channels() == 1) {
@@ -86,10 +87,10 @@ size_t Buffers::load(std::string name)
format = AL_FORMAT_STEREO8;
};
}
-
+
size_t id = index;
alBufferData(buffers[id], format, pcm->data(), pcm->size(), pcm->samplerate());
- if (alGetError()!= AL_NO_ERROR) {
+ if (alGetError() != AL_NO_ERROR) {
con_warn << "Error loading PCM data " << name << std::endl;
}
diff --git a/src/audio/buffers.h b/src/audio/buffers.h
index 2b31089..149c7f7 100644
--- a/src/audio/buffers.h
+++ b/src/audio/buffers.h
@@ -11,22 +11,24 @@
#ifdef _OSX
#include "OpenAL/al.h"
-#include "OpenAL/alc.h"
+#include "OpenAL/alc.h"
#else
-#include "AL/al.h"
+#include "AL/al.h"
#include "AL/alc.h"
#endif
#include <string>
#include <map>
-namespace audio {
+namespace audio
+{
const size_t MAXBUFFERS = 128;
/// OpenAL buffers wrapper class
-class Buffers {
+class Buffers
+{
public:
static void init();
static void shutdown();
diff --git a/src/audio/pcm.cc b/src/audio/pcm.cc
index 7a3f767..dacb23c 100644
--- a/src/audio/pcm.cc
+++ b/src/audio/pcm.cc
@@ -10,7 +10,8 @@
#include "audio/pcm.h"
#include "audio/wav.h"
-namespace audio {
+namespace audio
+{
PCM::PCM(unsigned int samplerate, unsigned int bitspersample, unsigned int channels, size_t size)
{
diff --git a/src/audio/pcm.h b/src/audio/pcm.h
index dc8eb16..8df44e8 100644
--- a/src/audio/pcm.h
+++ b/src/audio/pcm.h
@@ -9,10 +9,12 @@
#include <string>
-namespace audio {
+namespace audio
+{
/// class to hold PCM audio data
-class PCM {
+class PCM
+{
public:
PCM(unsigned int samplerate, unsigned int samplesize, unsigned int channels, size_t size);
@@ -21,22 +23,34 @@ public:
void clear();
/// pointer to the raw pcm data
- inline unsigned char *data() { return pcm_data; }
+ inline unsigned char *data() {
+ return pcm_data;
+ }
/// index into the raw pcm data
- inline unsigned char *operator[](size_t index) { return &pcm_data[index]; }
+ inline unsigned char *operator[](size_t index) {
+ return &pcm_data[index];
+ }
/// size in bytes
- inline size_t size() { return pcm_size; }
+ inline size_t size() {
+ return pcm_size;
+ }
/// samplerate in samples per second
- inline unsigned int samplerate() const { return pcm_samplerate; }
+ inline unsigned int samplerate() const {
+ return pcm_samplerate;
+ }
/// number of bits per sample
- inline unsigned int bitspersample() const { return pcm_bitspersample; }
+ inline unsigned int bitspersample() const {
+ return pcm_bitspersample;
+ }
/// number of channels
- inline unsigned int channels() const { return pcm_channels; }
+ inline unsigned int channels() const {
+ return pcm_channels;
+ }
private:
unsigned char *pcm_data;
diff --git a/src/audio/sources.cc b/src/audio/sources.cc
index 2ec0e26..241332b 100644
--- a/src/audio/sources.cc
+++ b/src/audio/sources.cc
@@ -19,7 +19,7 @@ void Sources::init()
{
int error;
clear();
-
+
alGenSources(MAXSOURCES, sources);
if ((error = alGetError()) != AL_NO_ERROR) {
@@ -33,7 +33,7 @@ void Sources::init()
}
// reserve ui sound sources
- for (size_t i=0; i < MAXUISOURCES; i++) {
+ for (size_t i = 0; i < MAXUISOURCES; i++) {
source_available[i] = false;
}
}
@@ -41,7 +41,7 @@ void Sources::init()
void Sources::shutdown()
{
// stop all sources
- for (size_t index= 0; index < MAXSOURCES; index++) {
+ for (size_t index = 0; index < MAXSOURCES; index++) {
alSourceRewind(sources[index]);
}
@@ -51,21 +51,21 @@ void Sources::shutdown()
void Sources::clear()
{
- memset(sources,0, sizeof(sources));
+ memset(sources, 0, sizeof(sources));
// all sources are available for use
- for (size_t i=0; i < MAXSOURCES; i++) {
+ for (size_t i = 0; i < MAXSOURCES; i++) {
source_available[i] = false;
}
}
size_t Sources::get()
{
- for (size_t i= MAXUISOURCES; i < MAXSOURCES; i++) {
+ for (size_t i = MAXUISOURCES; i < MAXSOURCES; i++) {
if (source_available[i]) {
source_available[i] = false;
- alSourcef(sources[i], AL_PITCH, 1.0);
- alSourcef(sources[i], AL_GAIN, 0.0);
+ alSourcef(sources[i], AL_PITCH, 1.0);
+ alSourcef(sources[i], AL_GAIN, 0.0);
//con_debug << "reserved source " << i << std::endl;
return i;
}
@@ -75,7 +75,7 @@ size_t Sources::get()
void Sources::remove(size_t index)
{
- if ( (index < MAXUISOURCES ) || (MAXSOURCES <= index))
+ if ((index < MAXUISOURCES) || (MAXSOURCES <= index))
return;
source_available[index] = true;
diff --git a/src/audio/sources.h b/src/audio/sources.h
index c9e38e2..6292ff6 100644
--- a/src/audio/sources.h
+++ b/src/audio/sources.h
@@ -11,29 +11,35 @@
#ifdef _OSX
#include "OpenAL/al.h"
-#include "OpenAL/alc.h"
+#include "OpenAL/alc.h"
#else
-#include "AL/al.h"
+#include "AL/al.h"
#include "AL/alc.h"
#endif
#include <string>
#include <map>
-namespace audio {
+namespace audio
+{
const size_t MAXSOURCES = 32;
const size_t MAXUISOURCES = 4;
/// OpenAL sources wrapper class
-class Sources {
+class Sources
+{
public:
static void init();
static void shutdown();
- static inline bool available(size_t index) { return source_available[index]; }
+ static inline bool available(size_t index) {
+ return source_available[index];
+ }
- static inline ALuint source(size_t index) { return sources[index]; }
+ static inline ALuint source(size_t index) {
+ return sources[index];
+ }
static size_t get();
static void remove(size_t index);
diff --git a/src/audio/wav.cc b/src/audio/wav.cc
index 178f199..b6ca710 100644
--- a/src/audio/wav.cc
+++ b/src/audio/wav.cc
@@ -5,7 +5,7 @@
*/
/*
-see
+see
http://ccrma.stanford.edu/CCRMA/Courses/422/projects/WaveFormat/
*/
@@ -19,7 +19,8 @@ http://ccrma.stanford.edu/CCRMA/Courses/422/projects/WaveFormat/
#include "filesystem/filesystem.h"
#include "sys/sys.h"
-namespace audio {
+namespace audio
+{
PCM *Wav::load(std::string const & name)
{
@@ -29,7 +30,7 @@ PCM *Wav::load(std::string const & name)
std::string filename("sounds/");
filename.append(name);
filename.append(".wav");
-
+
filesystem::File *wav_file = filesystem::open(filename.c_str());
if (!wav_file) {
con_warn << "Could not open " << filename << std::endl;
@@ -52,7 +53,7 @@ PCM *Wav::load(std::string const & name)
}
// format WAVE
- if (strncmp((char *)header+8, "WAVE", 4) != 0) {
+ if (strncmp((char *)header + 8, "WAVE", 4) != 0) {
con_warn << "Error reading " << filename << ": invalid WAVE header!" << std::endl;
filesystem::close(wav_file);
return 0;
@@ -61,7 +62,7 @@ PCM *Wav::load(std::string const & name)
// file size
//size_t chunksize = header[4] + (header[5] << 8) + (header[6] << 16) + (header[7] << 24);
- if (strncmp((char *)header+12, "fmt ", 4) != 0) {
+ if (strncmp((char *)header + 12, "fmt ", 4) != 0) {
con_warn << "Error reading " << filename << ": invalid format header!" << std::endl;
filesystem::close(wav_file);
return 0;
@@ -78,7 +79,7 @@ PCM *Wav::load(std::string const & name)
}
unsigned int channels = header[22] + (header[23] << 8);
- if ((channels < 1) || (channels >2)) {
+ if ((channels < 1) || (channels > 2)) {
con_warn << "Error reading " << filename << ": invalid number of channels!" << std::endl;
filesystem::close(wav_file);
return 0;
@@ -89,7 +90,7 @@ PCM *Wav::load(std::string const & name)
//size_t blockalign = header[32] + (header[33] << 8);
size_t bitspersample = header[34] + (header[35] << 8);
- if (strncmp((char *)header + 36, "data", 4) !=0) {
+ if (strncmp((char *)header + 36, "data", 4) != 0) {
con_warn << "Error reading " << filename << ": invalid data header!" << std::endl;
filesystem::close(wav_file);
return 0;
@@ -109,8 +110,8 @@ PCM *Wav::load(std::string const & name)
con_warn << "Error reading " << filename << ": file truncated!" << std::endl;
}
- con_debug << " " << filename << " " << pcm->samplerate()<< "Hz " << pcm->bitspersample() << "bit " <<
- pcm->channels() << " chan " << pcm->size() << " bytes" << std::endl;
+ con_debug << " " << filename << " " << pcm->samplerate() << "Hz " << pcm->bitspersample() << "bit " <<
+ pcm->channels() << " chan " << pcm->size() << " bytes" << std::endl;
filesystem::close(wav_file);
return pcm;
diff --git a/src/audio/wav.h b/src/audio/wav.h
index a94b6fb..2513b48 100644
--- a/src/audio/wav.h
+++ b/src/audio/wav.h
@@ -9,10 +9,12 @@
#include "audio/pcm.h"
-namespace audio {
+namespace audio
+{
/// class to read microsoft PCM wav files
-class Wav {
+class Wav
+{
public:
static PCM *load(std::string const & name);
};
diff --git a/src/auxiliary/functions.cc b/src/auxiliary/functions.cc
index 8cefbc5..5dbc012 100644
--- a/src/auxiliary/functions.cc
+++ b/src/auxiliary/functions.cc
@@ -13,7 +13,7 @@ const std::string plural(const char * word, size_t n)
{
std::string p(word);
- if (n != 1)
+ if (n != 1)
p += 's';
return p;
}
@@ -96,40 +96,40 @@ const std::string text_strip_lowercase(const std::string &text)
return r;
}
-const std::string pad_left(const std::string &text,size_t n)
+const std::string pad_left(const std::string &text, size_t n)
{
size_t l = text_length(text);
if (n <= l)
return text;
std::string s;
- s.assign(n-l, ' ');
+ s.assign(n - l, ' ');
s.append(text);
return s;
}
-const std::string pad_right(const std::string &text,size_t n)
+const std::string pad_right(const std::string &text, size_t n)
{
size_t l = text_length(text);
if (n <= l)
return text;
std::string s(text);
- s.append(n-l, ' ');
+ s.append(n - l, ' ');
return s;
}
void to_lowercase(std::string &text)
{
- for (std::string::iterator i = text.begin(); i != text.end(); ++i)
- (*i) = tolower(*i);
+ for (std::string::iterator i = text.begin(); i != text.end(); ++i)
+ (*i) = tolower(*i);
}
const std::string lowercase(const std::string &text)
{
std::string t;
- for (std::string::const_iterator i = text.begin(); i != text.end(); ++i)
- t += tolower(*i);
+ for (std::string::const_iterator i = text.begin(); i != text.end(); ++i)
+ t += tolower(*i);
return t;
}
@@ -139,7 +139,7 @@ void trim(std::string &text)
text.erase(0, 1);
}
while (text.size() && text[text.size()-1] == ' ') {
- text.erase(text.size()-1, 1);
+ text.erase(text.size() - 1, 1);
}
}
diff --git a/src/auxiliary/functions.h b/src/auxiliary/functions.h
index d5b590d..aeaa201 100644
--- a/src/auxiliary/functions.h
+++ b/src/auxiliary/functions.h
@@ -18,18 +18,33 @@ namespace aux
const std::string plural(const char * word, size_t n);
/// append an "s" to a word, depending on the amount
-inline const std::string plural(const std::string & word, size_t n) { return plural(word.c_str(), n); }
+inline const std::string plural(const std::string & word, size_t n)
+{
+ return plural(word.c_str(), n);
+}
/// prepend the "a" or "an" article to a word
const std::string article(const char * word);
-inline const std::string article(const std::string & word) { return article(word.c_str()); }
+inline const std::string article(const std::string & word)
+{
+ return article(word.c_str());
+}
-inline bool is_base_color_code(char const *c) { return ((*c == '^') && (*(c+1) >= '0') && (*(c+1) <= '7')); }
+inline bool is_base_color_code(char const *c)
+{
+ return ((*c == '^') && (*(c + 1) >= '0') && (*(c + 1) <= '7'));
+}
-inline bool is_core_color_code(char const *c) { return ((*c == '^') && (*(c+1) >= 'A') && (*(c+1) <= 'Z')); }
+inline bool is_core_color_code(char const *c)
+{
+ return ((*c == '^') && (*(c + 1) >= 'A') && (*(c + 1) <= 'Z'));
+}
-inline bool is_color_code(char const *c) { return (is_base_color_code(c) || is_core_color_code(c)); }
+inline bool is_color_code(char const *c)
+{
+ return (is_base_color_code(c) || is_core_color_code(c));
+}
/// length of a string, excluding color codes
size_t text_length(const std::string &text);
diff --git a/src/client/action.cc b/src/client/action.cc
index b86476e..7c7a34c 100644
--- a/src/client/action.cc
+++ b/src/client/action.cc
@@ -21,7 +21,8 @@ Action::~Action()
{
}
-void Action::set_info(const char *info) {
+void Action::set_info(const char *info)
+{
if (info)
action_info.assign(info);
else
diff --git a/src/client/action.h b/src/client/action.h
index c7086c8..778c40d 100644
--- a/src/client/action.h
+++ b/src/client/action.h
@@ -9,26 +9,33 @@
#include <string>
-namespace client {
+namespace client
+{
/// an Action that can be bound to a key
class Action
{
public:
/// actions
- enum Identifier {None=0};
+ enum Identifier {None = 0};
/// define a new action
Action(const char *name, Identifier action, const char *info = 0);
~Action();
-
+
/// name of the Action
- inline std::string const & name() const { return action_name; }
+ inline std::string const & name() const {
+ return action_name;
+ }
/// Action Identifier
- inline Identifier id() const { return action_id; }
+ inline Identifier id() const {
+ return action_id;
+ }
- inline std::string const & info() const { return action_info; }
+ inline std::string const & info() const {
+ return action_info;
+ }
/// set info
void set_info(const char *info);
diff --git a/src/client/buymenu.cc b/src/client/buymenu.cc
index 8c69a7a..d12f23e 100644
--- a/src/client/buymenu.cc
+++ b/src/client/buymenu.cc
@@ -16,9 +16,9 @@ namespace client
BuyMenu::BuyMenu(ui::Widget *parent, const char * label) : ui::Window(parent)
{
set_border(false);
- set_background(true);
+ set_background(true);
- if (label)
+ if (label)
set_label(label);
else
set_label("buymenu");
@@ -34,7 +34,7 @@ BuyMenu::BuyMenu(ui::Widget *parent, const char * label) : ui::Window(parent)
menu_modelview->set_background(false);
menu_modelview->set_border(false);
- menu_closebutton = new ui::Button(menu_modelpane, "Close","view hide");
+ menu_closebutton = new ui::Button(menu_modelpane, "Close", "view hide");
// text pane (right)
menu_textpane = new ui::Window(this);
@@ -48,7 +48,7 @@ BuyMenu::BuyMenu(ui::Widget *parent, const char * label) : ui::Window(parent)
menu_namelabel->set_border(false);
menu_namelabel->set_font(ui::root()->font_large());
menu_namelabel->set_alignment(ui::AlignCenter);
-
+
menu_scrollpane = new ui::ScrollPane(menu_textpane, menu_infotext);
menu_scrollpane->set_background(false);
menu_scrollpane->set_border(false);
@@ -83,7 +83,7 @@ void BuyMenu::set_item(std::string const & itemtype, std::string const & itemnam
menu_namelabel->set_text(0);
menu_modelview->set_modelname(0);
- core::Info *info = core::game()->info(itemtype+'/'+itemname);
+ core::Info *info = core::game()->info(itemtype + '/' + itemname);
if (info) {
menu_namelabel->set_text(info->name());
menu_modelview->set_modelname(info->modelname());
@@ -111,10 +111,10 @@ void BuyMenu::resize()
menu_modelpane->set_location(smallmargin, smallmargin * 2.0f);
menu_closebutton->set_size(ui::UI::elementsize);
- menu_closebutton->set_location((menu_modelpane->width() - menu_closebutton->width()) * 0.5f,
- menu_modelpane->height() - menu_closebutton->height() - ui::UI::elementsize.height() * 0.5f);
+ menu_closebutton->set_location((menu_modelpane->width() - menu_closebutton->width()) * 0.5f,
+ menu_modelpane->height() - menu_closebutton->height() - ui::UI::elementsize.height() * 0.5f);
- menu_modelview->set_size(menu_modelpane->width()-8, menu_modelpane->width()-8);
+ menu_modelview->set_size(menu_modelpane->width() - 8, menu_modelpane->width() - 8);
menu_modelview->set_location(4, 4);
// reposition text pane (right)
@@ -122,13 +122,13 @@ void BuyMenu::resize()
menu_textpane->set_location(smallmargin * 2.0f + menu_modelpane->width(), smallmargin * 2.0f);
menu_buybutton->set_size(ui::UI::elementsize);
- menu_buybutton->set_location((menu_textpane->width() - menu_buybutton->width()) * 0.5f,
- menu_textpane->height() - menu_buybutton->height() - ui::UI::elementsize.height() * 0.5f);
+ menu_buybutton->set_location((menu_textpane->width() - menu_buybutton->width()) * 0.5f,
+ menu_textpane->height() - menu_buybutton->height() - ui::UI::elementsize.height() * 0.5f);
menu_namelabel->set_size(menu_textpane->width(), menu_namelabel->font()->height() * 2.0f);
menu_namelabel->set_location(0, 4);
- menu_scrollpane->set_size(menu_textpane->width() - 8, menu_buybutton->top() - menu_namelabel->bottom() - 8 );
+ menu_scrollpane->set_size(menu_textpane->width() - 8, menu_buybutton->top() - menu_namelabel->bottom() - 8);
menu_scrollpane->set_location(4, menu_namelabel->bottom() + 4);
}
@@ -142,14 +142,14 @@ void BuyMenu::draw()
bool BuyMenu::on_keypress(const int key, const unsigned int modifier)
{
- switch( key ) {
-
- case SDLK_ESCAPE:
- this->hide();
- return true;
- break;
- default:
- break;
+ switch (key) {
+
+ case SDLK_ESCAPE:
+ this->hide();
+ return true;
+ break;
+ default:
+ break;
}
return Window::on_keypress(key, modifier);
diff --git a/src/client/buymenu.h b/src/client/buymenu.h
index 6a1a651..f624ec3 100644
--- a/src/client/buymenu.h
+++ b/src/client/buymenu.h
@@ -1,7 +1,7 @@
/*
client/buymenu.h
- This file is part of the Osirion project and is distributed under
- the terms of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
*/
#ifndef __INCLUDED_CLIENT_BUYMENU_H__
diff --git a/src/client/chat.cc b/src/client/chat.cc
index 137e6b1..5eb1922 100644
--- a/src/client/chat.cc
+++ b/src/client/chat.cc
@@ -1,7 +1,7 @@
/*
client/chat.cc
- This file is part of the Osirion project and is distributed under
- the terms and conditions of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
*/
#include "auxiliary/functions.h"
@@ -11,7 +11,8 @@
#include "sys/sys.h"
#include "ui/ui.h"
-namespace client {
+namespace client
+{
const size_t DEFAULT_CHAT_LOG_SIZE = 2048;
const size_t DEFAULT_CHAT_HISTO_SIZE = 512;
@@ -69,7 +70,7 @@ void Chat::show()
history_pos = history.rbegin();
(*history_pos).clear();
- chat_input->set_text((*history_pos));
+ chat_input->set_text((*history_pos));
chat_scrollpane->set_scroll(0);
}
@@ -89,67 +90,67 @@ bool Chat::on_keypress(const int key, const unsigned int modifier)
History::reverse_iterator upit;
- switch( key ) {
- case SDLK_ESCAPE:
- if (visible()) {
- hide();
+ switch (key) {
+ case SDLK_ESCAPE:
+ if (visible()) {
+ hide();
+ return true;
+ } else {
+ return false;
+ }
+ case SDLK_RETURN:
+ if (chat_input->text().size()) {
+ // store input into history
+ while (history.size() >= DEFAULT_CHAT_HISTO_SIZE) {
+ history.pop_front();
+ }
+
+ if (chat_input->text().c_str()[0] == '/' || chat_input->text().c_str()[0] == '\\') {
+ core::cmd() << &chat_input->text().c_str()[1] << std::endl;
+ } else {
+ core::cmd() << "say " << chat_input->text() << std::endl;
+ }
+ (*history.rbegin()) = chat_input->text();
+
+ history.push_back("");
+ history_pos = history.rbegin();
+ chat_input->set_text((*history_pos));
+
+ if (chat_small)
+ hide();
+ } else {
+ hide();
+ }
return true;
- } else {
- return false;
- }
- case SDLK_RETURN:
- if (chat_input->text().size()) {
- // store input into history
- while (history.size() >= DEFAULT_CHAT_HISTO_SIZE) {
- history.pop_front();
+ break;
+
+ case SDLK_UP:
+ upit = history_pos;
+ ++upit;
+ if (upit != history.rend()) {
+ history_pos = upit;
+ chat_input->set_text((*history_pos));
}
+ return true;
+ break;
- if (chat_input->text().c_str()[0] == '/' || chat_input->text().c_str()[0] == '\\') {
- core::cmd() << &chat_input->text().c_str()[1] << std::endl;
- } else {
- core::cmd() << "say " << chat_input->text() << std::endl;
+ case SDLK_DOWN:
+ if (history_pos != history.rbegin()) {
+ --history_pos;
+ chat_input->set_text((*history_pos));
}
- (*history.rbegin()) = chat_input->text();
+ return true;
+ break;
- history.push_back("");
- history_pos = history.rbegin();
- chat_input->set_text((*history_pos));
+ case SDLK_PAGEUP:
+ chat_scrollpane->inc_scroll(scroll_offset);
+ return true;
+ break;
- if (chat_small)
- hide();
- } else {
- hide();
- }
- return true;
- break;
-
- case SDLK_UP:
- upit = history_pos;
- ++upit;
- if (upit != history.rend()) {
- history_pos = upit;
- chat_input->set_text((*history_pos));
- }
- return true;
- break;
-
- case SDLK_DOWN:
- if (history_pos != history.rbegin()) {
- --history_pos;
- chat_input->set_text((*history_pos));
- }
- return true;
- break;
-
- case SDLK_PAGEUP:
- chat_scrollpane->inc_scroll(scroll_offset);
- return true;
- break;
-
- case SDLK_PAGEDOWN:
- chat_scrollpane->dec_scroll(scroll_offset);
- return true;
- break;
+ case SDLK_PAGEDOWN:
+ chat_scrollpane->dec_scroll(scroll_offset);
+ return true;
+ break;
}
return false;
@@ -169,7 +170,7 @@ void Chat::event_draw()
hide();
return;
}
-
+
if (chat_small) {
chat_scrollpane->hide();
} else {
@@ -183,12 +184,12 @@ void Chat::resize()
const float margin = 8.0f;
math::Vector2f s(size());
- s[0] -= margin*2;
- s[1] -= margin*2;
+ s[0] -= margin * 2;
+ s[1] -= margin * 2;
chat_scrollpane->set_location(margin, margin);
chat_scrollpane->set_size(s.width(), s.height() - font()->height() *1.5f);
-
+
chat_input->set_location(margin, height() - font()->height() - margin);
chat_input->set_size(s.width(), font()->height());
}
diff --git a/src/client/chat.h b/src/client/chat.h
index b7e1691..41837c5 100644
--- a/src/client/chat.h
+++ b/src/client/chat.h
@@ -1,7 +1,7 @@
/*
client/chat.h
- This file is part of the Osirion project and is distributed under
- the terms of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
*/
#ifndef __INCLUDED_CLIENT_CHAT_H__
@@ -14,7 +14,8 @@
#include "ui/scrollpane.h"
#include "ui/window.h"
-namespace client {
+namespace client
+{
class Chat : public ui::Window
{
@@ -26,19 +27,21 @@ public:
void toggle();
void event_text(const std::string & text);
-
- inline bool small_view() const { return chat_small; }
-
- void set_small_view(bool small_view=true);
+
+ inline bool small_view() const {
+ return chat_small;
+ }
+
+ void set_small_view(bool small_view = true);
void clear();
protected:
virtual void event_draw();
virtual void resize();
-
+
virtual bool on_keypress(const int key, const unsigned int modifier);
-
+
private:
bool chat_small;
@@ -46,9 +49,9 @@ private:
ui::Text chat_log;
ui::ScrollPane *chat_scrollpane;
ui::InputBox *chat_input;
-
+
typedef std::deque<std::string> History;
-
+
History history;
History::reverse_iterator history_pos;
};
diff --git a/src/client/client.cc b/src/client/client.cc
index 1fa2796..6a50743 100644
--- a/src/client/client.cc
+++ b/src/client/client.cc
@@ -1,7 +1,7 @@
/*
client/client.cc
- This file is part of the Osirion project and is distributed under
- the terms and conditions of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
*/
#include <SDL/SDL.h>
@@ -22,7 +22,7 @@
#include "render/render.h"
#include "ui/ui.h"
-namespace client
+namespace client
{
core::Cvar *cl_framerate = 0;
@@ -42,7 +42,7 @@ void run(int count, char **arguments)
{
std::cout << core::name() << " " << core::version() << std::endl;
- for (int i =0; i < count; i++)
+ for (int i = 0; i < count; i++)
std::cout << arguments[i] << " ";
std::cout << std::endl;
@@ -104,7 +104,7 @@ void Client::init(int count, char **arguments)
// initialize audio
audio::init();
-
+
// add engine functions
core::Func *func = 0;
@@ -116,19 +116,19 @@ void Client::init(int count, char **arguments)
func = core::Func::add("list_ui", func_list_ui);
func->set_info("list user interface widgets");
-
+
func = core::Func::add("list_menu", func_list_menu);
func->set_info("list available menus");
-
+
func = core::Func::add("ui", func_ui);
func->set_info("[command] user interface functions");
-
+
func = core::Func::add("ui_restart", func_ui_restart);
func->set_info("reload user interface files");
func = core::Func::add("ui_console", func_ui_console);
func->set_info("toggle console");
-
+
func = core::Func::add("ui_chat", Client::func_ui_chat);
func->set_info("toggle chat window");
@@ -160,14 +160,14 @@ void Client::run()
// default framerate 125fps, 8 milliseconds
Uint32 client_frame_lenght = 8;
-
+
Uint32 client_current_timestamp = 0;
Uint32 client_previous_timestamp = 0;
-
+
while (true) {
// current time in microseconds
client_current_timestamp = SDL_GetTicks();
-
+
// calculate the desired frame length
if (cl_framerate->value() < 0) {
(*cl_framerate) = 0.0f;
@@ -180,12 +180,12 @@ void Client::run()
} else {
client_frame_lenght = 0;
}
-
+
// only advance per microsecond frame
Uint32 d = client_current_timestamp - client_previous_timestamp;
if ((d > 0)) {
if (d >= client_frame_lenght) {
- frame(client_current_timestamp);
+ frame(client_current_timestamp);
client_previous_timestamp = client_current_timestamp;
} else {
SDL_Delay(client_frame_lenght - d);
@@ -222,7 +222,7 @@ void Client::frame(unsigned long timestamp)
if (!core::game()->interactive()) {
ui::root()->show_menu("main");
- // show the join menu when player does not control an entity
+ // show the join menu when player does not control an entity
} else if (core::game()->time() && !core::localcontrol()) {
ui::root()->show_menu("join");
}
@@ -231,13 +231,13 @@ void Client::frame(unsigned long timestamp)
// hide join menu
if (ui::root()->active()->label().compare("join") == 0) {
- ui::root()->hide_menu();
+ ui::root()->hide_menu();
}
}
}
video::frame((float)(timestamp - previous_timestamp) / 1000.0f);
-
+
previous_timestamp = timestamp;
}
@@ -248,7 +248,7 @@ void Client::shutdown()
if (connected()) disconnect();
core::Func::remove("r_restart");
- core::Func::remove("snd_restart");
+ core::Func::remove("snd_restart");
core::Func::remove("list_menu");
core::Func::remove("list_ui");
core::Func::remove("ui");
@@ -302,7 +302,7 @@ void Client::notify_zonechange()
{
video::set_loader_message();
video::frame_loader();
-
+
// unload entity sounds
for (core::Entity::Registry::iterator it = core::Entity::registry().begin(); it != core::Entity::registry().end(); it++) {
core::Entity *entity = (*it).second;
@@ -333,7 +333,7 @@ void Client::notify_message(const std::string &message)
void Client::notify_message(const core::Message::Channel channel, const std::string &message)
{
- switch(channel) {
+ switch (channel) {
case core::Message::Info: // Info message
break;
@@ -363,7 +363,8 @@ void Client::notify_message(const core::Message::Channel channel, const std::str
con_print << message << std::endl;
}
-void Client::notify_loader(const std::string &message) {
+void Client::notify_loader(const std::string &message)
+{
video::set_loader_message(message.c_str());
}
@@ -436,7 +437,7 @@ void Client::func_ui(std::string const &args)
con_warn << "User Interface not available!" << std::endl;
return;
}
-
+
if (!args.size()) {
func_ui_help();
return;
@@ -445,7 +446,7 @@ void Client::func_ui(std::string const &args)
std::string command;
argstr >> command;
aux::to_label(command);
-
+
if (command.compare("help") == 0) {
func_ui_help();
} else if (command.compare("debug") == 0) {
@@ -517,7 +518,7 @@ void Client::func_menu(std::string const &args)
con_warn << "User Interface not available!" << std::endl;
return;
}
-
+
if (!args.size()) {
con_print << "^Bmenu functions" << std::endl;
con_print << " menu help show this help" << std::endl;
@@ -533,21 +534,21 @@ void Client::func_menu(std::string const &args)
std::stringstream argstr(args);
std::string command;
argstr >> command;
-
+
aux::to_label(command);
-
+
if (command.compare("hide") == 0) {
ui::root()->hide_menu();
-
+
} else if (command.compare("close") == 0) {
ui::root()->hide_menu();
-
+
} else if (command.compare("back") == 0) {
ui::root()->previous_menu();
-
+
} else if (command.compare("previous") == 0) {
ui::root()->previous_menu();
-
+
} else if (command.compare("list") == 0) {
ui::root()->list_menus();
diff --git a/src/client/client.h b/src/client/client.h
index dbb2c44..fd762c6 100644
--- a/src/client/client.h
+++ b/src/client/client.h
@@ -1,7 +1,7 @@
/*
client/client.h
- This file is part of the Osirion project and is distributed under
- the terms and conditions of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
*/
#ifndef __INCLUDED_CLIENT_H__
@@ -16,7 +16,8 @@
#include "render/renderext.h"
/// client part of the engine
-namespace client {
+namespace client
+{
/// run the client application
void run(int count, char **arguments);
@@ -62,7 +63,9 @@ public:
virtual void notify_disconnect();
/// the main client widget
- inline WorldView *worldview() { return client_worldview; }
+ inline WorldView *worldview() {
+ return client_worldview;
+ }
protected:
/// run a client frame
@@ -95,14 +98,20 @@ private:
Client *client();
-inline ClientExt *ext_client(core::Entity *entity)
- { return static_cast<ClientExt *>(entity->extension(core::Extension::Client)); }
+inline ClientExt *ext_client(core::Entity *entity)
+{
+ return static_cast<ClientExt *>(entity->extension(core::Extension::Client));
+}
-inline SoundExt *ext_sound(core::Entity *entity)
- { return static_cast<SoundExt *>(entity->extension(core::Extension::Sound)); }
+inline SoundExt *ext_sound(core::Entity *entity)
+{
+ return static_cast<SoundExt *>(entity->extension(core::Extension::Sound));
+}
-inline render::RenderExt *ext_render(core::Entity *entity)
- { return static_cast<render::RenderExt *>(entity->extension(core::Extension::Render)); }
+inline render::RenderExt *ext_render(core::Entity *entity)
+{
+ return static_cast<render::RenderExt *>(entity->extension(core::Extension::Render));
+}
}
diff --git a/src/client/clientext.h b/src/client/clientext.h
index d76546d..123c4c0 100644
--- a/src/client/clientext.h
+++ b/src/client/clientext.h
@@ -13,7 +13,8 @@ namespace client
{
/// the client extension of an entity
-class ClientExt :public core::Extension {
+class ClientExt : public core::Extension
+{
public:
ClientExt(core::Entity *entity);
~ClientExt();
@@ -21,7 +22,7 @@ public:
virtual void frame(float elapsed);
private:
-
+
};
} // namespace client
diff --git a/src/client/entitymenu.cc b/src/client/entitymenu.cc
index 59c922c..d0fccef 100644
--- a/src/client/entitymenu.cc
+++ b/src/client/entitymenu.cc
@@ -15,7 +15,7 @@ namespace client
EntityMenu::EntityMenu(ui::Widget *parent, const char * label) : ui::Window(parent)
{
set_border(false);
- set_background(false);
+ set_background(false);
if (label)
set_label(label);
else
@@ -58,9 +58,9 @@ void EntityMenu::generate(core::Entity *entity, const char *menulabel)
menu_generated_menu.assign(menulabel);
if (!menu_generated_menu.size())
return;
-
+
//con_debug << "generating menu " << entity->label() << " " << menulabel << std::endl;
-
+
clear();
menu_container = new Container(this);
@@ -70,7 +70,7 @@ void EntityMenu::generate(core::Entity *entity, const char *menulabel)
menudescr = (*it);
}
}
-
+
if (!menudescr) {
menu_container->event_resize();
resize();
@@ -100,36 +100,36 @@ void EntityMenu::generate(core::Entity *entity, const char *menulabel)
if (c == '"') {
quote = !quote;
result += c;
-
+
} else if (c == ';') {
if (quote) {
current += c;
-
+
} else if (current.size()) {
if (buttondescr->command_type() == core::ButtonDescription::CommandGame) {
if (result.size()) {
result += ';';
}
-
+
result.append("remote ");
result.append(current);
-
+
} else if (buttondescr->command_type() == core::ButtonDescription::CommandMenu) {
if (result.size()) {
result += ';';
}
-
+
result.append("view ");
result.append(current);
}
current.clear();
}
-
+
} else {
current += c;
}
-
+
i++;
}
@@ -174,21 +174,21 @@ void EntityMenu::generate(core::Entity *entity, const char *menulabel)
bool EntityMenu::on_keypress(const int key, const unsigned int modifier)
{
- switch( key ) {
-
- case SDLK_ESCAPE:
- if (visible()) {
- if (menu_generated_menu.compare("main") != 0) {
- generate(menu_generated_entity, "main");
- } else {
- this->hide();
- ui::root()->show_menu("game");
+ switch (key) {
+
+ case SDLK_ESCAPE:
+ if (visible()) {
+ if (menu_generated_menu.compare("main") != 0) {
+ generate(menu_generated_entity, "main");
+ } else {
+ this->hide();
+ ui::root()->show_menu("game");
+ }
+ return true;
}
- return true;
- }
- break;
- default:
- break;
+ break;
+ default:
+ break;
}
return Window::on_keypress(key, modifier);
diff --git a/src/client/entitymenu.h b/src/client/entitymenu.h
index db69867..0285879 100644
--- a/src/client/entitymenu.h
+++ b/src/client/entitymenu.h
@@ -26,13 +26,17 @@ public:
/* ---- inspectors ----------------------------------------- */
/// entity the current menu was generated for
- inline core::Entity *generated_entity() { return menu_generated_entity; }
+ inline core::Entity *generated_entity() {
+ return menu_generated_entity;
+ }
/// the current generated menu
- inline const std::string & generated_menu() const { return menu_generated_menu; }
+ inline const std::string & generated_menu() const {
+ return menu_generated_menu;
+ }
/* ---- mutators ------------------------------------------- */
-
+
/// generate a menu from menu descriptions
void generate(core::Entity *entity, const char *menulabel);
diff --git a/src/client/hud.cc b/src/client/hud.cc
index 662bbe8..b7e2c43 100644
--- a/src/client/hud.cc
+++ b/src/client/hud.cc
@@ -1,7 +1,7 @@
/*
client/hud.cc
- This file is part of the Osirion project and is distributed under
- the terms and conditions of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
*/
@@ -13,7 +13,7 @@
#include "render/renderext.h"
#include "ui/ui.h"
-namespace client
+namespace client
{
HUD::HUD(ui::Widget *parent) : Widget(parent)
@@ -30,7 +30,7 @@ HUD::HUD(ui::Widget *parent) : Widget(parent)
*/
hud_center = new ui::Bitmap(this, "pointers/center");
hud_center->set_color(palette()->pointer());
-
+
}
void HUD::resize()
@@ -50,11 +50,11 @@ void HUD::draw_offscreen_target(core::Entity *entity, bool is_active_target)
float cx = 0;
float cy = 0;
- if ( target.y() * target.y() + target.z() * target.z() < 0.0001 ) {
+ if (target.y() * target.y() + target.z() * target.z() < 0.0001) {
// X - bound, behind (front is visible)
cx = 0.0f;
cy = -0.5f;
-
+
} else if (fabs(target.y()) > fabs(target.z())) {
// Y-bound
cx = math::sgnf(target.y()) * 0.5f;
@@ -67,18 +67,18 @@ void HUD::draw_offscreen_target(core::Entity *entity, bool is_active_target)
const float r = 16;
const float margin = 24;
- cx = (0.5f - cx) * ((float) render::State::width() - margin*2);
+ cx = (0.5f - cx) * ((float) render::State::width() - margin * 2);
cx += margin;
- cy = (0.5f - cy) * ((float) render::State::height() - margin*2);
+ cy = (0.5f - cy) * ((float) render::State::height() - margin * 2);
cy += margin;
gl::disable(GL_TEXTURE_2D);
gl::color(0, 0, 0, 1);
gl::begin(gl::LineLoop);
- glVertex3f(cx+r, cy+2, 0);
- glVertex3f(cx, cy+r+2, 0);
- glVertex3f(cx-r, cy+2, 0);
- glVertex3f(cx, cy-r+2, 0);
+ glVertex3f(cx + r, cy + 2, 0);
+ glVertex3f(cx, cy + r + 2, 0);
+ glVertex3f(cx - r, cy + 2, 0);
+ glVertex3f(cx, cy - r + 2, 0);
gl::end();
if (entity == core::localplayer()->mission_target()) {
@@ -90,10 +90,10 @@ void HUD::draw_offscreen_target(core::Entity *entity, bool is_active_target)
}
gl::begin(gl::LineLoop);
- glVertex3f(cx+r, cy, 0);
- glVertex3f(cx, cy+r, 0);
- glVertex3f(cx-r, cy, 0);
- glVertex3f(cx, cy-r, 0);
+ glVertex3f(cx + r, cy, 0);
+ glVertex3f(cx, cy + r, 0);
+ glVertex3f(cx - r, cy, 0);
+ glVertex3f(cx, cy - r, 0);
gl::end();
gl::enable(GL_TEXTURE_2D);
}
@@ -108,7 +108,7 @@ void HUD::draw_target(core::Entity *entity, bool is_active_target)
// don't draw target if it is outside the visible cone
Vector3f target(entity->location() - render::Camera::eye());
- if (math::dotproduct(render::Camera::axis().forward(), Vector3f::normalized(target)) < 0.75 ) {
+ if (math::dotproduct(render::Camera::axis().forward(), Vector3f::normalized(target)) < 0.75) {
draw_offscreen_target(entity, is_active_target);
return;
}
@@ -123,7 +123,7 @@ void HUD::draw_target(core::Entity *entity, bool is_active_target)
float cx = render::State::width() * (0.5 - center.y());
float cy = render::State::height() * (0.5 - center.z() * render::State::aspect());
- if ((cx < 0 ) || (cy < 0) || (cx > render::State::width()) || (cy > render::State::height())) {
+ if ((cx < 0) || (cy < 0) || (cx > render::State::width()) || (cy > render::State::height())) {
draw_offscreen_target(entity, is_active_target);
return;
}
@@ -136,18 +136,18 @@ void HUD::draw_target(core::Entity *entity, bool is_active_target)
// outer square shadow
gl::color(0, 0, 0, 1);
gl::begin(gl::LineLoop);
- gl::vertex(cx+r, cy+2);
- gl::vertex(cx, cy+r+2);
- gl::vertex(cx-r, cy+2);
- gl::vertex(cx, cy-r+2);
+ gl::vertex(cx + r, cy + 2);
+ gl::vertex(cx, cy + r + 2);
+ gl::vertex(cx - r, cy + 2);
+ gl::vertex(cx, cy - r + 2);
gl::end();
if ((entity->flags() & core::Entity::Dockable) == core::Entity::Dockable) {
gl::begin(gl::LineLoop);
- gl::vertex(cx+ (r*0.25f), cy+2);
- gl::vertex(cx, cy+(r*0.25f)+2);
- gl::vertex(cx-(r*0.25f), cy+2);
- gl::vertex(cx, cy-(r*0.25f)+2);
+ gl::vertex(cx + (r*0.25f), cy + 2);
+ gl::vertex(cx, cy + (r*0.25f) + 2);
+ gl::vertex(cx - (r*0.25f), cy + 2);
+ gl::vertex(cx, cy - (r*0.25f) + 2);
gl::end();
}
@@ -161,28 +161,28 @@ void HUD::draw_target(core::Entity *entity, bool is_active_target)
// outer square0
gl::begin(gl::LineLoop);
- gl::vertex(cx+r, cy);
- gl::vertex(cx, cy+r);
- gl::vertex(cx-r, cy);
- gl::vertex(cx, cy-r);
+ gl::vertex(cx + r, cy);
+ gl::vertex(cx, cy + r);
+ gl::vertex(cx - r, cy);
+ gl::vertex(cx, cy - r);
gl::end();
-
+
if ((entity->flags() & core::Entity::Dockable) == core::Entity::Dockable) {
gl::begin(gl::LineLoop);
- gl::vertex(cx+(r*0.25f), cy);
- gl::vertex(cx, cy+(r*0.25f));
- gl::vertex(cx-(r*0.25f), cy);
- gl::vertex(cx, cy-(r*0.25f));
+ gl::vertex(cx + (r*0.25f), cy);
+ gl::vertex(cx, cy + (r*0.25f));
+ gl::vertex(cx - (r*0.25f), cy);
+ gl::vertex(cx, cy - (r*0.25f));
gl::end();
}
-
+
gl::enable(GL_TEXTURE_2D);
if (is_active_target) {
// entity name and distance
std::stringstream strdistance;
float d = math::distance(core::localcontrol()->location(), entity->location()) - entity->radius() - core::localcontrol()->radius();
- if (d > 0 ) {
+ if (d > 0) {
if (d > 100.0f) {
strdistance << roundf(d * 0.1f) << "km";
} else {
@@ -197,8 +197,8 @@ void HUD::draw_target(core::Entity *entity, bool is_active_target)
const core::EntityControlable *ec = static_cast<core::EntityControlable *>(entity);
if (ec->owner()) {
render::Text::setcolor('B');
- render::Text::draw(cx-aux::text_length(entity->name()) * render::Text::fontwidth()*0.5f,
- cy-r-4-2*render::Text::fontheight(), ec->owner()->name());
+ render::Text::draw(cx - aux::text_length(entity->name()) * render::Text::fontwidth()*0.5f,
+ cy - r - 4 - 2*render::Text::fontheight(), ec->owner()->name());
}
render::Text::setcolor('B');
@@ -209,24 +209,24 @@ void HUD::draw_target(core::Entity *entity, bool is_active_target)
render::Text::setcolor('N');
}
- render::Text::draw(cx-aux::text_length(entity->name()) * render::Text::fontwidth()*0.5f,
- cy-r-4-render::Text::fontheight(), entity->name());
+ render::Text::draw(cx - aux::text_length(entity->name()) * render::Text::fontwidth()*0.5f,
+ cy - r - 4 - render::Text::fontheight(), entity->name());
render::Text::draw(cx - aux::text_length(strdistance.str()) * render::Text::fontwidth() * 0.5f,
- cy+r+4, strdistance);
+ cy + r + 4, strdistance);
}
}
bool HUD::on_keypress(const int key, const unsigned int modifier)
{
- switch( key ) {
- case SDLK_ESCAPE:
- if (targets::current()) {
- targets::reset();
- } else {
- ui::root()->show_menu("game");
- }
- return true;
+ switch (key) {
+ case SDLK_ESCAPE:
+ if (targets::current()) {
+ targets::reset();
+ } else {
+ ui::root()->show_menu("game");
+ }
+ return true;
}
return false;
@@ -238,21 +238,21 @@ void HUD::draw()
std::stringstream status;
if (core::localcontrol() && (input::mouse_control || input::joystick_control) &&
- (render::Camera::mode() == render::Camera::Cockpit || render::Camera::mode() == render::Camera::Track)) {
+ (render::Camera::mode() == render::Camera::Cockpit || render::Camera::mode() == render::Camera::Track)) {
hud_center->set_visible(true);
} else {
hud_center->set_visible(false);
}
-
+
gl::enable(GL_TEXTURE_2D);
Text::setfont("gui", 12, 18);
Text::setcolor('N'); //set normal color
-
+
core::Zone *zone = core::localcontrol()->zone();
// draw HUD targets
- for (core::Zone::Content::iterator it=zone->content().begin(); it != zone->content().end(); it++) {
+ for (core::Zone::Content::iterator it = zone->content().begin(); it != zone->content().end(); it++) {
core::Entity *entity = (*it);
if (entity == targets::current()) {
@@ -261,11 +261,12 @@ void HUD::draw()
} else if (entity == core::localplayer()->mission_target()) {
draw_target(entity, false);
- } else if ((entity->type() == core::Entity::Controlable) && (targets::is_valid_hud_target(entity))){
+ } else if ((entity->type() == core::Entity::Controlable) && (targets::is_valid_hud_target(entity))) {
draw_target(entity, false);
}
}
+ /*
unsigned int state = core::localcontrol()->state();
if (state) {
std::stringstream statestr;
@@ -275,13 +276,14 @@ void HUD::draw()
} else if (state == core::Entity::Impulse) {
//statestr << "^FKinetic impulse";
} else if (state == core::Entity::JumpInitiate) {
- statestr << "^FInitializing hyperspace jump drive "<< core::localcontrol()->timer();
+ statestr << "^FInitializing hyperspace jump drive " << core::localcontrol()->timer();
} else if (state == core::Entity::Jump) {
statestr << "^FJumping...";
}
- Text::draw(4, render::State::height() - Text::fontheight()*3-4, statestr);
+ Text::draw(4, render::State::height() - Text::fontheight()*3 - 4, statestr);
}
+ */
core::Entity *target = targets::current();
std::stringstream strdistance;
@@ -290,10 +292,10 @@ void HUD::draw()
std::stringstream strtarget;
strtarget << "^B" << target->name() << "\n^B";
- float d = math::distance(core::localcontrol()->location(), target->location())
- - target->radius() - core::localcontrol()->radius();
+ float d = math::distance(core::localcontrol()->location(), target->location())
+ - target->radius() - core::localcontrol()->radius();
- if (d > 0 ) {
+ if (d > 0) {
strtarget << "^Ndist:^B ";
if (d > 100.0f) {
strtarget << roundf(d * 0.1f) << "km";
@@ -303,7 +305,7 @@ void HUD::draw()
if (core::localcontrol()->speed() > 0.1f) {
strtarget << "^N eta:^B ";
- float eta = floorf(d / core::localcontrol()->speed() );
+ float eta = floorf(d / core::localcontrol()->speed());
if (eta > 60.0f) {
float etamin = floorf(eta / 60.0f);
strtarget << etamin << "min ";
@@ -315,13 +317,13 @@ void HUD::draw()
strtarget << " --";
}
strtarget << '\n';
- Text::draw(width() - 4-Text::fontwidth()*30, height() - Text::fontheight()*2 -4, strtarget);
+ Text::draw(width() - 4 - Text::fontwidth()*30, height() - Text::fontheight()*2 - 4, strtarget);
}
- // draw player info
+ // draw player info
std::stringstream playerinfostr;
- playerinfostr <<"^B" << core::localcontrol()->name() << '\n' << "^Ncredits: " << core::localplayer()->credits();
- Text::draw(width() - 4-Text::fontwidth()*52, height() - Text::fontheight()*2 -4, playerinfostr);
+ playerinfostr << "^B" << core::localcontrol()->name() << '\n' << "^Ncredits: " << core::localplayer()->credits();
+ Text::draw(width() - 4 - Text::fontwidth()*52, height() - Text::fontheight()*2 - 4, playerinfostr);
Textures::bind("bitmaps/hud/thruster_base"); // 316 x 32 bitmap
gl::color(1, 1, 1, 1);
@@ -342,14 +344,23 @@ void HUD::draw()
gl::end();
float u = core::localcontrol()->thrust();
- if (core::localcontrol()->state() == core::Entity::Impulse) {
- u = 1.0;
+
+ if (core::localcontrol()->state() != core::Entity::Normal) {
+
+ if ((core::localcontrol()->state() == core::Entity::Docked ) || (core::localcontrol()->state() == core::Entity::NoPower )) {
+ u = 0.0f;
+ } else {
+
+ u = 1.0f;
+ }
}
- if (( u > 0) || (core::localcontrol()->state() == core::Entity::Impulse)) {
+ if ((u > 0) || (core::localcontrol()->state() == core::Entity::Impulse)) {
- if (core::localcontrol()->state() == core::Entity::Impulse) {
+ if ((core::localcontrol()->state() == core::Entity::Impulse) || (core::localcontrol()->state() == core::Entity::ImpulseInitiate)) {
gl::color(0, .8, 0);
+ } else if ((core::localcontrol()->state() == core::Entity::Jump) || (core::localcontrol()->state() == core::Entity::JumpInitiate)) {
+ gl::color(0.8f, 0.0f, 0.0f);
} else {
float d = math::absf(input::local_thrust - u);
if (d > 0.1) {
@@ -379,11 +390,11 @@ void HUD::draw()
std::stringstream speedstr;
speedstr << "^B" << roundf(core::localcontrol()->speed() * 100.0f);
- Text::draw( 316+4+10, height() - 6 -16 - render::Text::fontwidth() /2, speedstr);
+ Text::draw(316 + 4 + 10, height() - 6 - 16 - render::Text::fontwidth() / 2, speedstr);
Text::setfont("gui", 12, 18);
Text::setcolor('N'); //set normal color
-
+
gl::disable(GL_TEXTURE_2D);
}
diff --git a/src/client/hud.h b/src/client/hud.h
index d89450f..bda6ea1 100644
--- a/src/client/hud.h
+++ b/src/client/hud.h
@@ -1,7 +1,7 @@
/*
client/hud.h
- This file is part of the Osirion project and is distributed under
- the terms and conditions of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
*/
#ifndef __INCLUDED_CLIENT_HUD_H__
@@ -12,7 +12,7 @@
#include "ui/toolbar.h"
#include "ui/widget.h"
-namespace client
+namespace client
{
/// widget that contains HUD elements
@@ -21,10 +21,11 @@ namespace client
* that are only visible if the client is connected
* and the core is running an interactive module
**/
-class HUD : public ui::Widget {
+class HUD : public ui::Widget
+{
public:
/// create a new HUD widget
- HUD(ui::Widget *parent=0);
+ HUD(ui::Widget *parent = 0);
protected:
/// draw hud elements
diff --git a/src/client/infowidget.cc b/src/client/infowidget.cc
index b30dfd7..da4103f 100644
--- a/src/client/infowidget.cc
+++ b/src/client/infowidget.cc
@@ -1,7 +1,7 @@
/*
client/infowidget.cc
- This file is part of the Osirion project and is distributed under
- the terms and conditions of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
*/
#include <iostream>
@@ -28,7 +28,7 @@ namespace client
void time_to_stream(std::stringstream &str, float time)
{
int minutes = (int) floorf(time / 60.0f);
- int seconds = (int) floorf( time - (float) minutes* 60.0f);
+ int seconds = (int) floorf(time - (float) minutes * 60.0f);
str << std::setfill(' ') << std::setw(4) << minutes << ":" << std::setfill('0') << std::setw(2) << seconds;
}
@@ -58,19 +58,19 @@ void DevInfoWidget::draw()
if (core::localcontrol()) {
textstream << std::fixed << std::setprecision(2)
- << "^Nx ^B" << core::localcontrol()->location().x() << " "
- << "^Ny ^B" << core::localcontrol()->location().y() << " "
- << "^Nz ^B" << core::localcontrol()->location().z() << '\n';
+ << "^Nx ^B" << core::localcontrol()->location().x() << " "
+ << "^Ny ^B" << core::localcontrol()->location().y() << " "
+ << "^Nz ^B" << core::localcontrol()->location().z() << '\n';
textstream << "^Nthurst ^B" << core::localcontrol()->thrust() << " "
- << "^Nspeed ^B" << core::localcontrol()->speed() << '\n';
-
+ << "^Nspeed ^B" << core::localcontrol()->speed() << '\n';
+
if (target) {
d = math::distance(core::localcontrol()->location(), target->location()) - target->radius() - core::localcontrol()->radius();
textstream << "^Ndist ^B" << d << '\n';
}
}
-
+
ui::paint::color(palette()->foreground());
ui::paint::text(global_location(), size(), font(), textstream);
}
@@ -84,7 +84,7 @@ StatsInfoWidget::StatsInfoWidget(ui::Widget *parent) : ui::Widget(parent)
set_background(false);
// clear counters
- for (size_t i =0; i < fps_counter_size; i++)
+ for (size_t i = 0; i < fps_counter_size; i++)
fps_counter_time[i] = 0.0f;
for (size_t i = 0; i < net_counter_size; i++)
@@ -98,9 +98,9 @@ void StatsInfoWidget::draw()
{
// average fps
fps_counter_time[fps_counter_index] = core::application()->time();
- fps_counter_index = (fps_counter_index + 1 ) % fps_counter_size;
+ fps_counter_index = (fps_counter_index + 1) % fps_counter_size;
float min_time = core::application()->time();
- for (size_t i=0; i < fps_counter_size; i++)
+ for (size_t i = 0; i < fps_counter_size; i++)
if (fps_counter_time[i] < min_time)
min_time = fps_counter_time[i];
float fps = 0.0f;
@@ -135,7 +135,7 @@ void StatsInfoWidget::draw()
float d = net_counter_time[index_max] - net_counter_time[index_min];
if (d > 0) {
float traffic = net_counter_traffic[index_max] - net_counter_traffic[index_min];
- textstream << "^Nnet ^B" << std::setw(6) << roundf( (float) traffic / d ) << "\n";
+ textstream << "^Nnet ^B" << std::setw(6) << roundf((float) traffic / d) << "\n";
}
}
}
@@ -157,7 +157,7 @@ void KeyInfoWidget::draw()
{
std::string label;
ui::paint::color(palette()->highlight());
-
+
Key::Modifier mod = input::modifier();
if (mod != Key::None) {
if (mod == Key::Shift)
@@ -168,7 +168,7 @@ void KeyInfoWidget::draw()
label.assign("alt+");
}
- if(input::last_key_pressed()) {
+ if (input::last_key_pressed()) {
label.append(input::last_key_pressed()->name());
}
diff --git a/src/client/infowidget.h b/src/client/infowidget.h
index 2cea366..48d1c9a 100644
--- a/src/client/infowidget.h
+++ b/src/client/infowidget.h
@@ -1,7 +1,7 @@
/*
client/infowidget.h
- This file is part of the Osirion project and is distributed under
- the terms and conditions of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
*/
#ifndef __INCLUDED_CLIENT_INFOWIDGET_H__
@@ -33,7 +33,7 @@ class StatsInfoWidget : public ui::Widget
{
public:
/// default constructor
- StatsInfoWidget(ui::Widget *parent=0);
+ StatsInfoWidget(ui::Widget *parent = 0);
protected:
/// draw engine statistics
@@ -53,7 +53,7 @@ class KeyInfoWidget : public ui::Widget
{
public:
// default constructor
- KeyInfoWidget(ui::Widget *parent=0);
+ KeyInfoWidget(ui::Widget *parent = 0);
protected:
// draw keypress events
diff --git a/src/client/input.cc b/src/client/input.cc
index 8b49604..790af91 100644
--- a/src/client/input.cc
+++ b/src/client/input.cc
@@ -82,15 +82,18 @@ float joystick_lastmoved = 0;
const float thruster_offset = 0.05f;
-int mouse_position_x() {
+int mouse_position_x()
+{
return mouse_x;
}
-int mouse_position_y() {
+int mouse_position_y()
+{
return mouse_y;
}
-Key *last_key_pressed() {
+Key *last_key_pressed()
+{
return last_key;
}
@@ -130,6 +133,9 @@ void func_ui_control(std::string const &args)
render::Camera::set_direction(0.0f);
render::Camera::set_pitch(0.0f);
}
+
+ con_debug << "mouse control is " << ((input_mousecontrol->value()) ? "on" : "off") << std::endl;
+
audio::play("ui/control");
}
@@ -193,7 +199,7 @@ void func_list_binds(std::string const &args)
aux::to_lowercase(keyname);
keyboard->bind(keyname, "");
} else {
- keyboard->list_binds();
+ keyboard->list_binds();
}
} else {
con_warn << "Keyboard handler not installed!" << std::endl;
@@ -207,8 +213,8 @@ void func_bind(std::string const &args)
std::string keyname;
if (argstr >> keyname) {
aux::to_lowercase(keyname);
- if (args.size() > keyname.size()+1) {
- keyboard->bind(keyname, args.substr(keyname.size()+1));
+ if (args.size() > keyname.size() + 1) {
+ keyboard->bind(keyname, args.substr(keyname.size() + 1));
} else {
keyboard->bind(keyname, "");
}
@@ -249,7 +255,7 @@ void init()
keyboard = new Keyboard();
- SDL_ShowCursor(SDL_DISABLE);
+ SDL_ShowCursor(SDL_DISABLE);
SDL_WM_GrabInput(SDL_GRAB_ON);
// SDL_EnableUNICODE(1);
@@ -268,7 +274,7 @@ void init()
input_mousedelay->set_info("[int] mouse click time-out in milliseconds");
core::Func *func = 0;
- func = core::Func::add("ui_control",func_ui_control);
+ func = core::Func::add("ui_control", func_ui_control);
func->set_info("toggle mouse control");
func = core::Func::add("list_joystick", func_list_joystick);
@@ -280,7 +286,7 @@ void init()
func = core::Func::add("list_keys", func_list_keys);
func->set_info("list key names");
- func = core::Func::add("list_binds",func_list_binds);
+ func = core::Func::add("list_binds", func_list_binds);
func->set_info("list keyb binds");
func = core::Func::add("bind", (core::FuncPtr) func_bind);
@@ -319,17 +325,17 @@ void shutdown()
core::Func::remove("unbindall");
core::Func::remove("screenshot");
-
+
core::Func::remove("ui_control");
core::Func::remove("ui_view");
-
+
if (keyboard) {
keyboard->save_binds();
delete keyboard;
keyboard = 0;
}
- SDL_ShowCursor(SDL_ENABLE);
+ SDL_ShowCursor(SDL_ENABLE);
SDL_WM_GrabInput(SDL_GRAB_OFF);
// SDL_DisableUNICODE(0);
@@ -340,11 +346,11 @@ void action_press(Key const *key, std::string const &action)
/* -- thruster ------------------------------------ */
if (action.compare("+thrustup") == 0) {
local_thrust += thruster_offset;
-
+
} else if (action.compare("+thrustdown") == 0) {
local_thrust -= 2.0f * thruster_offset;
-
+
/* -- mouse control ------------------------------- */
} else if (action.compare("+control") == 0) {
if (!mouse_control_override) {
@@ -384,7 +390,7 @@ void action_press(Key const *key, std::string const &action)
local_afterburner = -1.0f;
/* -- camera control ------------------------------ */
-
+
} else if (action.compare("+zoomin") == 0) {
render::Camera::set_zoom(-0.1f);
@@ -392,16 +398,16 @@ void action_press(Key const *key, std::string const &action)
render::Camera::set_zoom(+0.1f);
} else if (action.compare("+camleft") == 0) {
- render::Camera::set_direction( math::min(key->pressed() - core::application()->time(), 1.0f) );
+ render::Camera::set_direction(math::min(key->pressed() - core::application()->time(), 1.0f));
} else if (action.compare("+camright") == 0) {
- render::Camera::set_direction(-math::min(key->pressed() - core::application()->time(),1.0f));
+ render::Camera::set_direction(-math::min(key->pressed() - core::application()->time(), 1.0f));
} else if (action.compare("+camup") == 0) {
- render::Camera::set_pitch(math::min(key->pressed() - core::application()->time(),1.0f));
+ render::Camera::set_pitch(math::min(key->pressed() - core::application()->time(), 1.0f));
} else if (action.compare("+camdown") == 0) {
- render::Camera::set_pitch(-math::min(key->pressed() - core::application()->time(),1.0f));
+ render::Camera::set_pitch(-math::min(key->pressed() - core::application()->time(), 1.0f));
} else
con_warn << "Unknown action " << action << std::endl;
}
@@ -410,23 +416,23 @@ void action_release(Key *key, std::string const &action)
{
/* -- thruster ------------------------------------ */
if (action.compare("+thrustup") == 0) {
-
+
} else if (action.compare("+thrustdown") == 0) {
-
+
/* -- mouse control ------------------------------- */
} else if (action.compare("+control") == 0) {
if (mouse_control_override) {
mouse_control_override = false;
mouse_control_override_time = 0;
-
- if (!input_mousecontrol->value() || (joystick_control && mouse_control &&
- (render::Camera::mode() == render::Camera::Track || render::Camera::mode() == render::Camera::Cockpit))) {
+
+ if (!input_mousecontrol->value() || (joystick_control && mouse_control &&
+ (render::Camera::mode() == render::Camera::Track || render::Camera::mode() == render::Camera::Cockpit))) {
local_direction = 0.0f;
local_pitch = 0.0f;
local_roll = 0.0f;
-
+
render::Camera::set_direction(0.0f);
render::Camera::set_pitch(0.0f);
}
@@ -463,7 +469,7 @@ void action_release(Key *key, std::string const &action)
} else if (action.compare("+reverse") == 0) {
local_afterburner = 0.0f;
- /* -- camera control ------------------------------ */
+ /* -- camera control ------------------------------ */
} else if (action.compare("+camleft") == 0) {
render::Camera::set_direction(0.0f);
@@ -478,12 +484,13 @@ void action_release(Key *key, std::string const &action)
}
}
-Key::Modifier modifier() {
- if ((keyboard_modifiers & Key::Shift) > 0 )
+Key::Modifier modifier()
+{
+ if ((keyboard_modifiers & Key::Shift) > 0)
return Key::Shift;
- else if ((keyboard_modifiers & Key::Ctrl) > 0 )
+ else if ((keyboard_modifiers & Key::Ctrl) > 0)
return Key::Ctrl;
- else if ((keyboard_modifiers & Key::Alt) > 0 )
+ else if ((keyboard_modifiers & Key::Alt) > 0)
return Key::Alt;
else
return Key::None;
@@ -514,7 +521,7 @@ void key_pressed(Key *key)
render::Camera::set_direction(0.0f);
render::Camera::set_pitch(0.0f);
}
-
+
if (ui::root()->input_key(true, Keyboard::translate_keysym(key->sym(), keyboard_modifiers), keyboard_modifiers)) {
return;
@@ -525,7 +532,7 @@ void key_pressed(Key *key)
if (c == '@') {
// target bind
if (targets::current_id())
- core::cmd() << key->bind(modifier()) << " " << targets::current_id() <<"\n";
+ core::cmd() << key->bind(modifier()) << " " << targets::current_id() << "\n";
} else if (c == '+') {
// action bind
action_press(key, key->bind(modifier()));
@@ -550,13 +557,13 @@ void key_released(Key *key)
if (core::application()->connected() && core::localcontrol()) {
- // FIXME mouse release selection should be handled inside the hud
- if ((key->sym() == 512 + SDL_BUTTON_LEFT) && targets::hover() && (key->waspressed() <= (input_mousedelay->value()/1000.0f) ) ) {
+ // FIXME mouse release selection should be handled inside the hud
+ if ((key->sym() == 512 + SDL_BUTTON_LEFT) && targets::hover() && (key->waspressed() <= (input_mousedelay->value() / 1000.0f))) {
// hovering target selected
targets::select_target(targets::hover());
- }
-
-
+ }
+
+
// the release event must still be processed as usual
char c = 0;
c = key->bind(Key::None).c_str()[0];
@@ -585,7 +592,7 @@ void key_released(Key *key)
void axis_event(int axis, int value)
{
// value is in range -32768 to 32767
- switch(axis) {
+ switch (axis) {
case 0: // direction
if (value >= 0) {
local_direction = (float) value / 32767.0f;
@@ -702,7 +709,7 @@ void frame()
video::resize(event.resize.w, event.resize.h);
break;
- case SDL_MOUSEMOTION:
+ case SDL_MOUSEMOTION:
mouse_x = event.motion.x;
mouse_y = event.motion.y;
mouse_moved = true;
@@ -750,8 +757,8 @@ void frame()
core::application()->shutdown();
return;
break;
- }
-
+ }
+
if (key) {
if (pressed) {
key_pressed(key);
@@ -772,7 +779,7 @@ void frame()
delay = input_keydelay->value();
math::clamp(delay, 50.0f, 500.0f);
}
-
+
float repeat = 35.0f; // key repeat time-out in milliseconds
if (input_keyrepeat) {
repeat = input_keyrepeat->value();
@@ -783,14 +790,14 @@ void frame()
(*input_keydelay) = delay;
if (input_keyrepeat)
(*input_keyrepeat) = repeat;
-
+
repeat /= 1000.0f;
delay /= 1000.0f;
-
+
for (Keyboard::iterator it = keyboard->begin(); it != keyboard->end(); it++) {
key = (*it).second;
- if (key && (key->sym() < 512) && key->pressed()) {
- if ((key->pressed()+delay < core::application()->time()) && (key->lastpressed()+repeat < core::application()->time())) {
+ if (key && (key->sym() < 512) && key->pressed()) {
+ if ((key->pressed() + delay < core::application()->time()) && (key->lastpressed() + repeat < core::application()->time())) {
key->key_lastpressed = core::application()->time();
key_pressed(key);
}
@@ -803,7 +810,7 @@ void frame()
if (core::application()->connected() && core::localcontrol()) {
mouse_control = ui::console()->hidden() && !ui::root()->active() && ((input_mousecontrol->value() > 0) || (mouse_control_override && (mouse_control_override_time + (input_mousedelay->value() / 1000.0f) < core::application()->time())));
-
+
if (mouse_control && joystick_control && ((render::Camera::mode() == render::Camera::Track) || (render::Camera::mode() == render::Camera::Cockpit))) {
if (!(mouse_control_override && (mouse_control_override_time + (input_mousedelay->value() / 1000.0f) < core::application()->time()))) {
mouse_control = false;
@@ -817,30 +824,30 @@ void frame()
// direction
int l = mouse_x - (render::State::width() >> 1);
-
- if (abs(l) < ( deadzone_size >> 1 )) {
+
+ if (abs(l) < (deadzone_size >> 1)) {
// dead zone
mouse_direction = 0;
} else {
l = (mouse_x - deadzone_size) - ((render::State::width() - deadzone_size) >> 1);
- mouse_direction = float (-l) / (float) ((render::State::width() - deadzone_size) >> 1);
+ mouse_direction = float(-l) / (float)((render::State::width() - deadzone_size) >> 1);
mouse_deadzone = false;
}
// pitch
int h = mouse_y - (render::State::height() >> 1);
- if (abs(h) < ( deadzone_size >> 1 )) {
+ if (abs(h) < (deadzone_size >> 1)) {
// dead zone
mouse_pitch = 0;
} else {
h = (mouse_y - deadzone_size) - ((render::State::height() - deadzone_size) >> 1);
- mouse_pitch = float (-h) / (float) ((render::State::height() - deadzone_size) >> 1);
+ mouse_pitch = float(-h) / (float)((render::State::height() - deadzone_size) >> 1);
mouse_deadzone = false;
}
if ((render::Camera::mode() == render::Camera::Track) || (render::Camera::mode() == render::Camera::Cockpit)) {
-
+
//local_direction = mouse_direction * math::absf(mouse_direction);
//local_pitch = mouse_pitch * math::absf(mouse_pitch);
local_direction = mouse_direction;
@@ -848,10 +855,10 @@ void frame()
} else if (render::Camera::mode() == render::Camera::Free) {
// squared values to smoothen camera movement
- render::Camera::set_direction( -mouse_direction * math::absf(mouse_direction));
+ render::Camera::set_direction(-mouse_direction * math::absf(mouse_direction));
render::Camera::set_pitch(-mouse_pitch * math::absf(mouse_pitch));
}
-
+
}
math::clamp(local_direction, -1.0f, 1.0f);
@@ -866,7 +873,7 @@ void frame()
core::localcontrol()->set_thrust(local_thrust);
core::localcontrol()->set_direction(local_direction);
- core::localcontrol()->set_pitch(local_pitch / render::State::aspect() );
+ core::localcontrol()->set_pitch(local_pitch / render::State::aspect());
core::localcontrol()->set_roll(local_roll);
core::localcontrol()->set_strafe(local_strafe);
core::localcontrol()->set_afterburner(local_afterburner);
diff --git a/src/client/joystick.cc b/src/client/joystick.cc
index 486542e..c8f7f9d 100644
--- a/src/client/joystick.cc
+++ b/src/client/joystick.cc
@@ -24,13 +24,13 @@ void Joystick::init()
int nbjoysticks = SDL_NumJoysticks();
if (nbjoysticks) {
- for (int i=0; i < nbjoysticks; i++) {
+ for (int i = 0; i < nbjoysticks; i++) {
SDL_Joystick *joystick = SDL_JoystickOpen(i);
if (joystick) {
- con_print << " joystick " << i+1 << ": " <<
- SDL_JoystickName(i) << " " <<
- SDL_JoystickNumAxes(joystick) << " axes " <<
- SDL_JoystickNumButtons(joystick) << " buttons " << std::endl;
+ con_print << " joystick " << i + 1 << ": " <<
+ SDL_JoystickName(i) << " " <<
+ SDL_JoystickNumAxes(joystick) << " axes " <<
+ SDL_JoystickNumButtons(joystick) << " buttons " << std::endl;
SDL_JoystickClose(joystick);
}
@@ -69,13 +69,13 @@ void Joystick::list()
*/
int nbjoysticks = SDL_NumJoysticks();
if (nbjoysticks) {
- for (int i=0; i < nbjoysticks; i++) {
+ for (int i = 0; i < nbjoysticks; i++) {
SDL_Joystick *joystick = SDL_JoystickOpen(i);
if (joystick) {
- con_print << " joystick " << i+1 << ": " <<
- SDL_JoystickName(i) << " " <<
- SDL_JoystickNumAxes(joystick) << " axes " <<
- SDL_JoystickNumButtons(joystick) << " buttons " << std::endl;
+ con_print << " joystick " << i + 1 << ": " <<
+ SDL_JoystickName(i) << " " <<
+ SDL_JoystickNumAxes(joystick) << " axes " <<
+ SDL_JoystickNumButtons(joystick) << " buttons " << std::endl;
SDL_JoystickClose(joystick);
}
@@ -89,11 +89,11 @@ void Joystick::list()
(*input_joystick) = (float) current_joystick_number;
if (current_joystick_number) {
- current_joystick = SDL_JoystickOpen(current_joystick_number -1);
+ current_joystick = SDL_JoystickOpen(current_joystick_number - 1);
}
if (current_joystick) {
- con_debug << " using joystick " << SDL_JoystickName(current_joystick_number -1) << std::endl;
+ con_debug << " using joystick " << SDL_JoystickName(current_joystick_number - 1) << std::endl;
SDL_JoystickEventState(SDL_ENABLE);
}
}
@@ -105,14 +105,13 @@ bool Joystick::is_enabled()
void Joystick::frame()
{
- if (current_joystick_number != (int) input_joystick->value())
- {
+ if (current_joystick_number != (int) input_joystick->value()) {
if (current_joystick) {
SDL_JoystickEventState(SDL_IGNORE);
SDL_JoystickClose(current_joystick);
current_joystick = 0;
}
-
+
current_joystick_number = (int) input_joystick->value();
if ((current_joystick_number < 1) || (current_joystick_number > SDL_NumJoysticks())) {
current_joystick_number = 0;
@@ -120,11 +119,11 @@ void Joystick::frame()
(*input_joystick) = (float) current_joystick_number;
if (current_joystick_number) {
- current_joystick = SDL_JoystickOpen(current_joystick_number -1);
+ current_joystick = SDL_JoystickOpen(current_joystick_number - 1);
}
if (current_joystick) {
- con_debug << " using joystick " << SDL_JoystickName(current_joystick_number -1) << std::endl;
+ con_debug << " using joystick " << SDL_JoystickName(current_joystick_number - 1) << std::endl;
SDL_JoystickEventState(SDL_ENABLE);
}
}
diff --git a/src/client/joystick.h b/src/client/joystick.h
index a21e24e..9b1925d 100644
--- a/src/client/joystick.h
+++ b/src/client/joystick.h
@@ -10,7 +10,7 @@
namespace client
{
-class Joystick
+class Joystick
{
public:
static void init();
diff --git a/src/client/key.cc b/src/client/key.cc
index c2da4a7..c25fa2b 100644
--- a/src/client/key.cc
+++ b/src/client/key.cc
@@ -7,7 +7,8 @@
#include "auxiliary/functions.h"
#include "client/key.h"
-namespace client {
+namespace client
+{
Key::Key(const char *name, int keysym, char ascii, const char *bind)
{
diff --git a/src/client/key.h b/src/client/key.h
index 06e0587..3bb3e2b 100644
--- a/src/client/key.h
+++ b/src/client/key.h
@@ -11,7 +11,8 @@
#include <string>
-namespace client {
+namespace client
+{
/// a pressable key
/**
@@ -22,11 +23,11 @@ class Key
{
public:
/// define a new key
- Key(const char *name, int keysym, char ascii=0, const char *bind=0);
+ Key(const char *name, int keysym, char ascii = 0, const char *bind = 0);
~Key();
-
+
/// key modifiers
- enum Modifier { None=0, Shift=KMOD_LSHIFT+KMOD_RSHIFT, Ctrl=KMOD_LCTRL + KMOD_RCTRL, Alt=KMOD_LALT+KMOD_RALT };
+ enum Modifier { None = 0, Shift = KMOD_LSHIFT + KMOD_RSHIFT, Ctrl = KMOD_LCTRL + KMOD_RCTRL, Alt = KMOD_LALT + KMOD_RALT };
/// clear all binds
void clear();
@@ -41,19 +42,31 @@ public:
std::string const & bind(Modifier mod) const;
/// first time the key was pressed since previous release
- inline float pressed() const { return key_pressed; }
+ inline float pressed() const {
+ return key_pressed;
+ }
/// last time the key was pressed (includes repeats)
- inline float lastpressed() const { return key_lastpressed; }
+ inline float lastpressed() const {
+ return key_lastpressed;
+ }
/// time the key was pressed when it is released
- inline float waspressed() const { return key_waspressed; }
-
- inline std::string const & name() const { return key_name; }
+ inline float waspressed() const {
+ return key_waspressed;
+ }
+
+ inline std::string const & name() const {
+ return key_name;
+ }
- inline char ascii() const { return key_ascii; }
+ inline char ascii() const {
+ return key_ascii;
+ }
- inline int sym() const { return key_sym; }
+ inline int sym() const {
+ return key_sym;
+ }
float key_pressed;
float key_lastpressed;
diff --git a/src/client/keyboard.cc b/src/client/keyboard.cc
index 23e6634..bf08db1 100644
--- a/src/client/keyboard.cc
+++ b/src/client/keyboard.cc
@@ -31,7 +31,7 @@ Keyboard::Keyboard()
// ------------------ ACTIONS
// FIXME actions should be state keys and not use key repeat
-
+
add_action("+left", Action::None, "rotate left");
add_action("+right", Action::None, "rotate right");
add_action("+up", Action::None, "rotate up");
@@ -253,12 +253,12 @@ Keyboard::~Keyboard()
{
// clear key map
for (iterator it = begin(); it != end(); it++)
- delete (*it).second;
+ delete(*it).second;
keys.clear();
-
+
// clear action list
- for(std::list<Action *>::iterator ait = actions.begin(); ait != actions.end(); ait++)
- delete (*ait);
+ for (std::list<Action *>::iterator ait = actions.begin(); ait != actions.end(); ait++)
+ delete(*ait);
actions.clear();
}
@@ -317,7 +317,7 @@ void Keyboard::load_binds()
con_print << " reading keyboard binds from " << filename << std::endl;
char line[MAXCMDSIZE];
- while (ifs.getline(line, MAXCMDSIZE-1)) {
+ while (ifs.getline(line, MAXCMDSIZE - 1)) {
if (line[0] && line[0] != '#' && line[0] != ';')
core::cmd() << line << '\n';
}
@@ -383,7 +383,7 @@ void Keyboard::bind(std::string const &name, const std::string str)
{
Key::Modifier modifier = Key::None;
std::string keyname(name);
-
+
if ((keyname.size() > 6) && (keyname.substr(0, 6).compare("shift+") == 0)) {
keyname.erase(0, 6);
modifier = Key::Shift;
@@ -393,7 +393,7 @@ void Keyboard::bind(std::string const &name, const std::string str)
} else if ((keyname.size() > 4) && (keyname.substr(0, 4).compare("alt+") == 0)) {
keyname.erase(0, 4);
modifier = Key::Alt;
-
+
} else if ((keyname.size() > 6) && (keyname.substr(keyname.size() - 6, 6).compare("+shift") == 0)) {
keyname.erase(keyname.size() - 6, 6);
modifier = Key::Shift;
@@ -401,10 +401,10 @@ void Keyboard::bind(std::string const &name, const std::string str)
keyname.erase(keyname.size() - 5, 5);
modifier = Key::Ctrl;
} else if ((keyname.size() > 4) && (keyname.substr(keyname.size() - 4, 4).compare("+alt") == 0)) {
- keyname.erase(0, keyname.size() -46);
+ keyname.erase(0, keyname.size() - 46);
modifier = Key::Alt;
}
-
+
Key *key = find(keyname);
if (key) {
if (str.size())
@@ -425,10 +425,10 @@ void Keyboard::bind(std::string const &name, const std::string str)
}
void Keyboard::unbind(std::string const &name)
-{
+{
Key::Modifier modifier = Key::None;
std::string keyname(name);
-
+
if ((keyname.size() > 6) && (keyname.substr(0, 6).compare("shift+") == 0)) {
keyname.erase(0, 6);
modifier = Key::Shift;
@@ -438,7 +438,7 @@ void Keyboard::unbind(std::string const &name)
} else if ((keyname.size() > 4) && (keyname.substr(0, 4).compare("alt+") == 0)) {
keyname.erase(0, 4);
modifier = Key::Alt;
-
+
} else if ((keyname.size() > 6) && (keyname.substr(keyname.size() - 6, 6).compare("+shift") == 0)) {
keyname.erase(keyname.size() - 6, 6);
modifier = Key::Shift;
@@ -446,7 +446,7 @@ void Keyboard::unbind(std::string const &name)
keyname.erase(keyname.size() - 5, 5);
modifier = Key::Ctrl;
} else if ((keyname.size() > 4) && (keyname.substr(keyname.size() - 4, 4).compare("+alt") == 0)) {
- keyname.erase(0, keyname.size() -46);
+ keyname.erase(0, keyname.size() - 46);
modifier = Key::Alt;
}
@@ -498,7 +498,7 @@ void Keyboard::list_keys()
void Keyboard::list_binds()
{
- size_t n =0;
+ size_t n = 0;
for (iterator it = begin(); it != end(); it++) {
if ((*it).second->bind(Key::None).size()) {
con_print << " " << aux::pad_right((*it).second->name(), 6) << " " << (*it).second->bind(Key::None) << std::endl;
@@ -719,7 +719,7 @@ void setkeyboardmode(bool input)
SDL_EnableKeyRepeat(250, SDL_DEFAULT_REPEAT_INTERVAL);
else
SDL_EnableKeyRepeat(10, SDL_DEFAULT_REPEAT_INTERVAL);
-
+
}
*/
} // namespace client
diff --git a/src/client/keyboard.h b/src/client/keyboard.h
index f63bce1..f533838 100644
--- a/src/client/keyboard.h
+++ b/src/client/keyboard.h
@@ -16,7 +16,8 @@
#include "client/action.h"
#include "client/key.h"
-namespace client {
+namespace client
+{
class Keyboard
{
@@ -65,15 +66,19 @@ public:
typedef std::map<unsigned int, Key *>::iterator iterator;
- inline iterator begin() { return keys.begin(); }
-
- inline iterator end() { return keys.end(); }
+ inline iterator begin() {
+ return keys.begin();
+ }
+
+ inline iterator end() {
+ return keys.end();
+ }
/// convert SDL_keysym to a keystroke
static unsigned int translate_keysym(int keysym, int modifier);
private:
- Key *add_key(const char *name, const unsigned int keysym, const char ascii=0, const char *bind=0);
+ Key *add_key(const char *name, const unsigned int keysym, const char ascii = 0, const char *bind = 0);
Action *add_action(const char *name, Action::Identifier action, const char *info = 0);
diff --git a/src/client/map.cc b/src/client/map.cc
index aca5e97..7a6fedc 100644
--- a/src/client/map.cc
+++ b/src/client/map.cc
@@ -1,8 +1,8 @@
/*
client/map.cc
- This file is part of the Osirion project and is distributed under
- the terms of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
*/
#include "audio/audio.h"
@@ -16,7 +16,8 @@
#include "render/textures.h"
#include "render/text.h"
-namespace client {
+namespace client
+{
Map::Map(ui::Widget *parent) : ui::Window(parent)
{
@@ -72,7 +73,7 @@ void Map::draw()
const float margin = font()->width() * 2.0f;
const float s = ui::UI::elementsize.width() * 2.0f;
const float blue = 0.8f;
- const float gridsize=16;
+ const float gridsize = 16;
core::Entity *entity;
const core::Entity *current_target = map_target;
@@ -87,10 +88,10 @@ void Map::draw()
v[1] += (height() - s - 2.0f * margin) * 0.5f;
map_hover = 0;
- gl::color(0,0,blue);
+ gl::color(0, 0, blue);
gl::begin(gl::Lines);
- for (int i=0; i <= gridsize; i++) {
+ for (int i = 0; i <= gridsize; i++) {
gl::vertex(v.x(), v.y() + s / gridsize * i);
gl::vertex(v.x() + s, v.y() + s / gridsize * i);
@@ -102,7 +103,7 @@ void Map::draw()
const size_t texture_entity = render::Textures::load("bitmaps/icons/entity_default");
const size_t texture_globe = render::Textures::load("bitmaps/icons/entity_globe");
const size_t texture_bright = render::Textures::load("bitmaps/icons/entity_bright");
-
+
size_t texture_current = render::Textures::bind(texture_entity);
v[0] += s * 0.5f;
@@ -140,7 +141,7 @@ void Map::draw()
if (core::application()->time() - floorf(core::application()->time()) < 0.5f) {
draw_icon = false;
}
- }
+ }
}
if (draw_icon) {
@@ -165,7 +166,7 @@ void Map::draw()
gl::begin(gl::Quads);
}
}
-
+
if (entity == core::localplayer()->mission_target()) {
color.assign(palette()->mission());
} else {
@@ -176,55 +177,55 @@ void Map::draw()
gl::color(color);
glTexCoord2f(0.0f, 0.0f);
gl::vertex(l.x() - r, l.y() - r);
-
+
glTexCoord2f(1.0f, 0.0f);
gl::vertex(l.x() + r, l.y() - r);
-
+
glTexCoord2f(1.0f, 1.0f);
gl::vertex(l.x() + r, l.y() + r);
-
+
glTexCoord2f(0.0f, 1.0f);
gl::vertex(l.x() - r, l.y() + r);
}
-
- }
+
+ }
// draw localcontrol icon
entity = core::localcontrol();
//if (core::localcontrol()->state() != core::Entity::Docked) {
- l.assign(v);
- l[0] -= s / scale * entity->location().y();
- l[1] -= s / scale * entity->location().x();
- if (core::application()->time() - floorf(core::application()->time()) < 0.5f) {
- if (texture_current != texture_entity) {
- gl::end();
- texture_current = render::Textures::bind(texture_entity);
- gl::begin(gl::Quads);
- }
-
- math::Color color(entity->color());
- color.a = 1.0f;
- gl::color(color);
- glTexCoord2f(0.0f, 0.0f);
- gl::vertex(l.x() - r, l.y() - r);
-
- glTexCoord2f(1.0f, 0.0f);
- gl::vertex(l.x() + r, l.y() - r);
-
- glTexCoord2f(1.0f, 1.0f);
- gl::vertex(l.x() + r, l.y() + r);
-
- glTexCoord2f(0.0f, 1.0f);
- gl::vertex(l.x() - r, l.y() + r);
+ l.assign(v);
+ l[0] -= s / scale * entity->location().y();
+ l[1] -= s / scale * entity->location().x();
+ if (core::application()->time() - floorf(core::application()->time()) < 0.5f) {
+ if (texture_current != texture_entity) {
+ gl::end();
+ texture_current = render::Textures::bind(texture_entity);
+ gl::begin(gl::Quads);
}
+
+ math::Color color(entity->color());
+ color.a = 1.0f;
+ gl::color(color);
+ glTexCoord2f(0.0f, 0.0f);
+ gl::vertex(l.x() - r, l.y() - r);
+
+ glTexCoord2f(1.0f, 0.0f);
+ gl::vertex(l.x() + r, l.y() - r);
+
+ glTexCoord2f(1.0f, 1.0f);
+ gl::vertex(l.x() + r, l.y() + r);
+
+ glTexCoord2f(0.0f, 1.0f);
+ gl::vertex(l.x() - r, l.y() + r);
+ }
//}
gl::end();
gl::disable(GL_TEXTURE_2D);
if (map_target) {
- map_targetlabel->set_size(width() - s - margin * 3.0f, map_targetlabel->font()->height() * 2.0f );
+ map_targetlabel->set_size(width() - s - margin * 3.0f, map_targetlabel->font()->height() * 2.0f);
map_targetlabel->set_location(s + margin * 2.0f, 4);
map_targetlabel->set_text(map_target->name());
map_targetlabel->show();
@@ -234,7 +235,7 @@ void Map::draw()
}
bool Map::on_keypress(const int key, const unsigned int modifier)
-{
+{
if (key == 512 + SDL_BUTTON_LEFT) {
if (hover()) {
core::Entity *target = core::localplayer()->zone()->find_entity(hover());
diff --git a/src/client/map.h b/src/client/map.h
index a3d8709..1fc1547 100644
--- a/src/client/map.h
+++ b/src/client/map.h
@@ -1,7 +1,7 @@
/*
client/map.h
- This file is part of the Osirion project and is distributed under
- the terms of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
*/
#ifndef __INCLUDED_CLIENT_MAP_H__
@@ -11,7 +11,8 @@
#include "ui/label.h"
#include "core/entity.h"
-namespace client {
+namespace client
+{
class Map : public ui::Window
{
@@ -19,7 +20,9 @@ public:
Map(ui::Widget *parent = 0);
virtual ~Map();
- inline unsigned int hover() const { return map_hover; }
+ inline unsigned int hover() const {
+ return map_hover;
+ }
/// toggle the map window
void toggle();
diff --git a/src/client/notifications.cc b/src/client/notifications.cc
index 062aacb..90c5e3e 100644
--- a/src/client/notifications.cc
+++ b/src/client/notifications.cc
@@ -1,7 +1,7 @@
/*
client/notifications.cc
- This file is part of the Osirion project and is distributed under
- the terms and conditions of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
*/
#include "client/notifications.h"
@@ -48,7 +48,7 @@ void Notifications::event_text(const std::string & text)
void Notifications::draw()
{
Timestamps::iterator t = notify_timestamp.begin();
- while ( (t != notify_timestamp.end()) && ( core::application()->timestamp() > (*t) + NOTIFY_TIMEOUT )) {
+ while ((t != notify_timestamp.end()) && (core::application()->timestamp() > (*t) + NOTIFY_TIMEOUT)) {
notify_log.pop_front();
notify_timestamp.pop_front();
@@ -58,11 +58,11 @@ void Notifications::draw()
const float margin = ui::UI::elementmargin;
math::Vector2f s(size());
- s[0] -= margin*2;
- s[1] -= margin*2;
+ s[0] -= margin * 2;
+ s[1] -= margin * 2;
notify_scrollpane->set_location(margin, margin);
- notify_scrollpane->set_size(s.x(), s.y() );
+ notify_scrollpane->set_size(s.x(), s.y());
}
diff --git a/src/client/notifications.h b/src/client/notifications.h
index db3dd3e..3d596bd 100644
--- a/src/client/notifications.h
+++ b/src/client/notifications.h
@@ -1,7 +1,7 @@
/*
client/notifications.h
- This file is part of the Osirion project and is distributed under
- the terms and conditions of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
*/
#ifndef __INCLUDED_CLIENT_NOTIFICATIONS_H__
@@ -27,7 +27,7 @@ public:
protected:
/// draw notifications
void draw();
-
+
private:
typedef std::deque<unsigned long> Timestamps;
diff --git a/src/client/playerview.cc b/src/client/playerview.cc
index 889e4d4..7ec8031 100644
--- a/src/client/playerview.cc
+++ b/src/client/playerview.cc
@@ -1,7 +1,7 @@
/*
client/playerview.cc
- This file is part of the Osirion project and is distributed under
- the terms and conditions of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
*/
#include <string>
@@ -11,7 +11,8 @@
#include "client/playerview.h"
#include "ui/ui.h"
-namespace client {
+namespace client
+{
PlayerView::PlayerView(ui::Widget *parent) : ui::Widget(parent)
{
@@ -60,9 +61,9 @@ void PlayerView::event_text(const std::string & text)
void PlayerView::toggle_map()
{
-
+
if (!map()->visible()) {
- if(chat()->visible() && !chat()->small_view())
+ if (chat()->visible() && !chat()->small_view())
chat()->hide();
if (view_entitymenu->visible())
@@ -80,9 +81,9 @@ void PlayerView::toggle_map()
void PlayerView::toggle_chat()
{
if (!chat()->visible()) {
- if(map()->visible())
+ if (map()->visible())
map()->hide();
-
+
if (view_entitymenu->visible())
view_entitymenu->hide();
}
@@ -132,7 +133,7 @@ void PlayerView::show_menu(const std::string & args)
} else if (label.compare("hide") == 0) {
view_buymenu->hide();
view_entitymenu->hide();
-
+
} else {
view_entitymenu->generate(core::localplayer()->view(), label.c_str());
view_entitymenu->show();
@@ -154,7 +155,7 @@ void PlayerView::resize()
view_buymenu->event_resize();
// set hud geometry
- view_hud->set_geometry(0,0, width(), height());
+ view_hud->set_geometry(0, 0, width(), height());
view_hud->event_resize();
// reposition map
@@ -167,7 +168,7 @@ void PlayerView::resize()
// reposition labels
//label_viewname->set_size(ui::UI::elementsize.width() * 1.5f, ui::UI::elementsize.height());
//label_viewname->set_location(smallmargin, smallmargin * 0.5f);
-
+
label_viewname->set_size(ui::UI::elementsize.width() * 1.5f, ui::UI::elementsize.height());
label_viewname->set_location(width() - label_viewname->width() - smallmargin, height() - label_viewname->height() - smallmargin * 0.5f);
}
@@ -185,10 +186,10 @@ void PlayerView::draw()
if (core::localplayer()->view()->menus().size()) {
// entity with menus
-
+
if (map()->visible()) {
label_viewname->set_text(core::localplayer()->zone()->name());
- } else {
+ } else {
label_viewname->set_text(core::localplayer()->view()->name());
}
@@ -200,9 +201,9 @@ void PlayerView::draw()
map()->hide();
chat()->hide();
audio::play("ui/menu");
-
- } else if (!view_entitymenu->visible() && !view_buymenu->visible() &&
- !map()->visible() && (!chat()->visible() || chat()->small_view()) ) {
+
+ } else if (!view_entitymenu->visible() && !view_buymenu->visible() &&
+ !map()->visible() && (!chat()->visible() || chat()->small_view())) {
// show the menu if there's no other window open
view_entitymenu->show();
@@ -226,7 +227,7 @@ void PlayerView::draw()
}
if (view_entitymenu->generated_entity()) {
- view_entitymenu->generate(0,0);
+ view_entitymenu->generate(0, 0);
}
if (view_buymenu->visible()) {
@@ -247,7 +248,7 @@ void PlayerView::draw()
view_hud->show();
}
- // reposition chat widget
+ // reposition chat widget
if (view_chat->small_view()) {
view_chat->set_size(width() - smallmargin * 2, font()->height() * 2);
view_chat->set_location(smallmargin, height() - smallmargin *2 - view_chat->height());
diff --git a/src/client/playerview.h b/src/client/playerview.h
index d72b78b..300e9e5 100644
--- a/src/client/playerview.h
+++ b/src/client/playerview.h
@@ -1,7 +1,7 @@
/*
client/playerview.h
- This file is part of the Osirion project and is distributed under
- the terms and conditions of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
*/
#ifndef __INCLUDED_CLIENT_PLAYERVIEW_H__
@@ -17,7 +17,8 @@
#include "ui/widget.h"
#include "ui/label.h"
-namespace client {
+namespace client
+{
/// the player's view when joined
class PlayerView : public ui::Widget
@@ -42,11 +43,21 @@ public:
/// show entity menus
void show_menu(const std::string & label);
- inline HUD *hud() { return view_hud; }
- inline Map *map() { return view_map; }
- inline Chat *chat() { return view_chat; }
- inline Notifications *notify() { return view_notify; }
- inline EntityMenu *menu() { return view_entitymenu; }
+ inline HUD *hud() {
+ return view_hud;
+ }
+ inline Map *map() {
+ return view_map;
+ }
+ inline Chat *chat() {
+ return view_chat;
+ }
+ inline Notifications *notify() {
+ return view_notify;
+ }
+ inline EntityMenu *menu() {
+ return view_entitymenu;
+ }
protected:
virtual void draw();
diff --git a/src/client/soundext.cc b/src/client/soundext.cc
index 40b9417..1ea0c94 100644
--- a/src/client/soundext.cc
+++ b/src/client/soundext.cc
@@ -35,18 +35,17 @@ SoundExt::SoundExt(core::Entity *entity) : core::Extension(core::Extension::Soun
state_engineeventsource = 0;
// load engine sound
- if (entity->type() == core::Entity::Controlable)
- {
+ if (entity->type() == core::Entity::Controlable) {
core::EntityControlable *entityco = static_cast<core::EntityControlable *>(entity);
unsigned int enginesoundset = 0;
unsigned int impulsesoundset = 0;
-
+
if (entityco->model()) {
enginesoundset = entityco->model()->enginesound();
impulsesoundset = entityco->model()->impulsesound();
}
-
-
+
+
std::stringstream soundname;
soundname << "engines/loop" << std::setfill('0') << std::setw(2) << enginesoundset;
state_thusterloopbuffer = audio::Buffers::load(soundname.str());
@@ -91,60 +90,59 @@ void SoundExt::clear()
void SoundExt::frame(float elapsed)
{
- if (entity()->type() == core::Entity::Controlable)
- {
+ if (entity()->type() == core::Entity::Controlable) {
core::EntityControlable *entity = static_cast<core::EntityControlable *>(this->entity());
-
+
float speed = entity->speed();
float pitch = 1.0f;
float gain = 0.0;
- float r = ( entity->model() ? entity->model()->maxbbox().x() : entity->radius());
+ float r = (entity->model() ? entity->model()->maxbbox().x() : entity->radius());
if (entity->state() == core::Entity::Impulse) {
pitch = 1.0f;
gain = 1.0f;
- } else if (entity->thrust() > 0 ) {
+ } else if (entity->thrust() > 0) {
pitch = 0.2f + entity->thrust() * 0.8f;
gain = 0.8f;
- }
-
- if (entity->state() == core::Entity::ImpulseInitiate ) {
-
+ }
+
+ if (entity->state() == core::Entity::ImpulseInitiate) {
+
if (state_engineeventbuffer != state_impulsestartbuffer) {
audio::update_source(state_engineeventsource,
- entity->location() - entity->axis().forward() * r ,
- entity->axis().forward() * speed);
-
+ entity->location() - entity->axis().forward() * r ,
+ entity->axis().forward() * speed);
+
state_engineeventbuffer = audio::play(state_engineeventsource, state_impulsestartbuffer);
}
} else if (entity->state() == core::Entity::Impulse) {
-
+
state_engineeventbuffer = state_impulseloopbuffer;
-
+
if (state_engineloopbuffer != state_impulseloopbuffer) {
state_engineloopbuffer = audio::loop(state_engineloopsource, state_impulseloopbuffer, pitch, 0);
}
pitch = 1.0f;
} else {
-
- if (state_engineeventbuffer == state_impulseloopbuffer) {
+
+ if (state_engineeventbuffer == state_impulseloopbuffer) {
audio::update_source(state_engineeventsource,
- entity->location() - entity->axis().forward() * r ,
- entity->axis().forward() * speed);
+ entity->location() - entity->axis().forward() * r ,
+ entity->axis().forward() * speed);
state_engineeventbuffer = audio::play(state_engineeventsource, state_impulsestopbuffer);
}
state_engineeventbuffer = 0;
-
+
if (state_engineloopbuffer != state_thusterloopbuffer) {
state_engineloopbuffer = audio::loop(state_engineloopsource, state_thusterloopbuffer, pitch, 0);
}
}
-
+
audio::update_source(state_engineloopsource,
- entity->location() - entity->axis().forward() * r , entity->axis().forward() * speed, pitch, gain);
-
+ entity->location() - entity->axis().forward() * r , entity->axis().forward() * speed, pitch, gain);
+
audio::update_source(state_engineeventsource,
- entity->location() - entity->axis().forward() * r , entity->axis().forward() * speed);
+ entity->location() - entity->axis().forward() * r , entity->axis().forward() * speed);
}
}
diff --git a/src/client/soundext.h b/src/client/soundext.h
index d2028dd..a99cee0 100644
--- a/src/client/soundext.h
+++ b/src/client/soundext.h
@@ -13,7 +13,8 @@ namespace client
{
/// the sound extension of an entity
-class SoundExt :public core::Extension {
+class SoundExt : public core::Extension
+{
public:
SoundExt(core::Entity *Entity);
~SoundExt();
@@ -43,7 +44,7 @@ private:
};
}
- //namespace client
- //
+//namespace client
+//
#endif // __INCLUDED_CLIENT_CLIENTEXT_H__
diff --git a/src/client/targeticonbutton.cc b/src/client/targeticonbutton.cc
index cd3716f..8bd3b1a 100644
--- a/src/client/targeticonbutton.cc
+++ b/src/client/targeticonbutton.cc
@@ -9,7 +9,8 @@
#include "client/targets.h"
#include "core/commandbuffer.h"
-namespace client {
+namespace client
+{
TargetIconButton::TargetIconButton(Widget *parent, const char *icon, const char *command, unsigned int flags) : IconButton(parent, icon, command)
{
@@ -18,7 +19,7 @@ TargetIconButton::TargetIconButton(Widget *parent, const char *icon, const char
}
bool TargetIconButton::on_keypress(const int key, const unsigned int modifier)
-{
+{
if (key == 512 + SDL_BUTTON_LEFT) {
if (enabled() && command().size() && targets::current()) {
core::cmd() << "@" << command() << " " << targets::current_id() << std::endl;
diff --git a/src/client/targeticonbutton.h b/src/client/targeticonbutton.h
index a08c5c9..9907f95 100644
--- a/src/client/targeticonbutton.h
+++ b/src/client/targeticonbutton.h
@@ -9,9 +9,11 @@
#include "ui/iconbutton.h"
-namespace client {
+namespace client
+{
-class TargetIconButton : public ui::IconButton {
+class TargetIconButton : public ui::IconButton
+{
public:
/// special icon button that sends target '@' commands.
diff --git a/src/client/targets.cc b/src/client/targets.cc
index e478d84..cd3db41 100644
--- a/src/client/targets.cc
+++ b/src/client/targets.cc
@@ -1,7 +1,7 @@
/*
client/targets.cc
- This file is part of the Osirion project and is distributed under
- the terms of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
*/
#include <iostream>
@@ -28,9 +28,11 @@
#include "render/camera.h"
#include "render/state.h"
-namespace client {
+namespace client
+{
-namespace targets {
+namespace targets
+{
const float TARGETBOXRADIUS = 0.025f;
unsigned int current_target_id = 0;
@@ -157,7 +159,7 @@ void func_target_next(std::string const &args)
} else {
current_target = 0;
current_target_id = 0;
-
+
}
}
@@ -222,22 +224,22 @@ void func_target_center(std::string const &args)
{
if (!core::localcontrol())
return;
-
+
// this is essentialy the hover algorithm with the cursor in the center
core::Entity *new_target = 0;
math::Vector3f center = render::Camera::eye() + render::Camera::axis().forward() * (render::FRUSTUMFRONT + 0.001);
float smallest_d = -1;
- for (core::Zone::Content::iterator it=core::localcontrol()->zone()->content().begin(); it != core::localcontrol()->zone()->content().end(); it++) {
+ for (core::Zone::Content::iterator it = core::localcontrol()->zone()->content().begin(); it != core::localcontrol()->zone()->content().end(); it++) {
core::Entity *entity = (*it);
math::Vector3f v(entity->location() - render::Camera::eye());
v.normalize();
- if (is_valid_hud_target(entity) && math::dotproduct(render::Camera::axis().forward(), v) > 0.85 ) {
+ if (is_valid_hud_target(entity) && math::dotproduct(render::Camera::axis().forward(), v) > 0.85) {
// calculate the distance from entity location to the line [eye - cursor]
- float d = math::Vector3f::length(math::crossproduct( (center - render::Camera::eye()) , (render::Camera::eye() - entity->location()))) / math::Vector3f::length(center - render::Camera::eye());
+ float d = math::Vector3f::length(math::crossproduct((center - render::Camera::eye()) , (render::Camera::eye() - entity->location()))) / math::Vector3f::length(center - render::Camera::eye());
// the entity closer to the center beam
if (smallest_d < 0 || d < smallest_d) {
@@ -256,7 +258,7 @@ void reset()
current_target = 0;
current_target_id = 0;
current_hover = 0;
-
+
}
void init()
@@ -296,7 +298,7 @@ void render_listener_sound()
if (!(snd_engines && snd_engines->value()))
return;
- math::Vector3f velocity(0, 0 ,0);
+ math::Vector3f velocity(0, 0 , 0);
if (core::localcontrol()) {
velocity.assign(core::localcontrol()->axis().forward() * core::localcontrol()->speed());
}
@@ -308,13 +310,13 @@ void render_entity_sound(core::Entity *entity)
{
if (!(snd_engines && snd_engines->value())) {
if (ext_sound(entity))
- delete ext_sound(entity);
+ delete ext_sound(entity);
return;
}
if (!ext_render(entity) || (ext_render(entity) && !ext_render(entity)->visible())) {
if (ext_sound(entity))
- delete ext_sound(entity);
+ delete ext_sound(entity);
return;
} else {
if (!ext_sound(entity)) {
@@ -354,18 +356,18 @@ void frame()
x = 0;
y = 0;
} else {
- x = (float)(input::mouse_position_x() - render::State::width() /2) / (float)render::State::width();
- y = (float)(input::mouse_position_y() - render::State::height() /2) / (float)render::State::height() / render::State::aspect();
+ x = (float)(input::mouse_position_x() - render::State::width() / 2) / (float)render::State::width();
+ y = (float)(input::mouse_position_y() - render::State::height() / 2) / (float)render::State::height() / render::State::aspect();
}
Vector3f cursor = render::Camera::eye() + render::Camera::axis().forward() * (render::FRUSTUMFRONT + 0.001);
cursor -= render::Camera::axis().left() * x;
cursor -= render::Camera::axis().up() * y;
- math::Vector3f center = render::Camera::eye() + (render::Camera::axis().forward() * (render::FRUSTUMFRONT +0.001f));
- for (core::Zone::Content::iterator it=zone->content().begin(); it != zone->content().end(); it++) {
+ math::Vector3f center = render::Camera::eye() + (render::Camera::axis().forward() * (render::FRUSTUMFRONT + 0.001f));
+ for (core::Zone::Content::iterator it = zone->content().begin(); it != zone->content().end(); it++) {
core::Entity *entity = (*it);
-
+
// render entity sound
if (entity->type() == core::Entity::Controlable) {
render_entity_sound(entity);
@@ -377,24 +379,24 @@ void frame()
if (entity->id() == current_target_id) {
current_target = entity;
}
-
+
// check if the mouse is hovering the entity
Vector3f v(entity->location() - render::Camera::eye());
v.normalize();
- if (math::dotproduct(render::Camera::axis().forward(), v) > 0.75 ) {
+ if (math::dotproduct(render::Camera::axis().forward(), v) > 0.75) {
// calculate the distance from entity location to the line [eye - cursor]
- float d = math::Vector3f::length(math::crossproduct( (cursor - render::Camera::eye()) , (render::Camera::eye() - entity->location()))) / math::Vector3f::length(cursor - render::Camera::eye());
-
+ float d = math::Vector3f::length(math::crossproduct((cursor - render::Camera::eye()) , (render::Camera::eye() - entity->location()))) / math::Vector3f::length(cursor - render::Camera::eye());
+
float r = entity->radius() * 0.5f;
if (ext_render(entity)->distance() > 512.0f)
- math::clamp(r, 8.0f,r);
+ math::clamp(r, 8.0f, r);
else if (ext_render(entity)->distance() > 256.0f)
- math::clamp(r, 4.0f,r);
+ math::clamp(r, 4.0f, r);
else if (ext_render(entity)->distance() > 128.0f)
- math::clamp(r, 2.0f,r);
+ math::clamp(r, 2.0f, r);
// if the cursor-beam hits the entity sphere
if (d < r) {
@@ -406,7 +408,7 @@ void frame()
}
}
-
+
}
}
@@ -415,7 +417,7 @@ void frame()
} else {
current_target_id = current_target->id();
-
+
}
}
diff --git a/src/client/targets.h b/src/client/targets.h
index d421300..9bfa87d 100644
--- a/src/client/targets.h
+++ b/src/client/targets.h
@@ -1,7 +1,7 @@
/*
client/targets.h
- This file is part of the Osirion project and is distributed under
- the terms of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
*/
#ifndef __INCLUDED_CLIENT_TARGETS_H__
@@ -12,9 +12,11 @@
#include "render/gl.h"
#include "render/text.h"
-namespace client {
+namespace client
+{
-namespace targets {
+namespace targets
+{
void init();
diff --git a/src/client/trademenu.cc b/src/client/trademenu.cc
index 9db1299..dcab2f1 100644
--- a/src/client/trademenu.cc
+++ b/src/client/trademenu.cc
@@ -16,7 +16,7 @@ TradeMenu::TradeMenu(ui::Widget *parent, const char * label) : ui::Window(parent
{
set_border(false);
set_background(false);
- if (label)
+ if (label)
set_label(label);
else
set_label("trademenu");
diff --git a/src/client/trademenu.h b/src/client/trademenu.h
index feb91f4..baf3544 100644
--- a/src/client/trademenu.h
+++ b/src/client/trademenu.h
@@ -1,7 +1,7 @@
/*
client/trademenu.h
- This file is part of the Osirion project and is distributed under
- the terms of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
*/
#ifndef __INCLUDED_CLIENT_TRADEMENU_H__
diff --git a/src/client/video.cc b/src/client/video.cc
index 4ad1c97..9e9d553 100644
--- a/src/client/video.cc
+++ b/src/client/video.cc
@@ -1,7 +1,7 @@
/*
client/video.cc
- This file is part of the Osirion project and is distributed under
- the terms and conditions of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
*/
#include "client/video.h"
@@ -21,7 +21,8 @@
using namespace render;
-namespace client {
+namespace client
+{
/* -- engine variables --------------------------------------------- */
@@ -34,7 +35,8 @@ core::Cvar *draw_stats = 0;
core::Cvar *draw_devinfo = 0;
core::Cvar *draw_keypress = 0;
-namespace video {
+namespace video
+{
float fullscreen = 0;
@@ -53,7 +55,7 @@ const int height_default = 768;
std::string loader_message;
bool is_loading = false;
-bool init()
+bool init()
{
con_print << "^BInitializing video..." << std::endl;
@@ -79,7 +81,7 @@ bool init()
draw_ui = core::Cvar::get("draw_ui", "1", core::Cvar::Archive);
draw_ui->set_info("[bool] draw the user interface");
- if( SDL_InitSubSystem(SDL_INIT_VIDEO) < 0 ) {
+ if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) {
con_error << "SDL_InitSubSystem() failed: " << SDL_GetError() << std::endl;
return false;
}
@@ -97,12 +99,12 @@ bool init()
if (image) {
Uint32 colorkey = SDL_MapRGB(image->format, 255, 0, 255);
SDL_SetColorKey(image, SDL_SRCCOLORKEY, colorkey);
- SDL_WM_SetIcon(image,NULL);
+ SDL_WM_SetIcon(image, NULL);
}
}
const SDL_VideoInfo* sdl_videoinfo = SDL_GetVideoInfo();
- if( !sdl_videoinfo) {
+ if (!sdl_videoinfo) {
con_error << "SDL_GetVideoInfo() failed: " << SDL_GetError() << std::endl;
return false;
}
@@ -115,25 +117,25 @@ bool init()
bpp = sdl_videoinfo->vfmt->BitsPerPixel;
if (bpp == 32) {
- SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 8);
- SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 8);
- SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 8);
- SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 8);
+ SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
+ SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
+ SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
+ SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
} else if (bpp == 24) {
- SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 6);
- SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 6);
- SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 6);
- SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 6);
+ SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 6);
+ SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 6);
+ SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 6);
+ SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 6);
} else if (bpp == 16) {
- SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 4);
- SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 4);
- SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 4);
- SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 4);
+ SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 4);
+ SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 4);
+ SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 4);
+ SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 4);
} else {
con_warn << "Display depth " << bpp << " is not supported!" << std::endl;
}
- SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1);
+ SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
fullscreen = r_fullscreen->value();
if (r_fullscreen->value()) {
@@ -145,12 +147,12 @@ bool init()
#endif
}
- if(!SDL_SetVideoMode(width, height, bpp, flags )) {
+ if (!SDL_SetVideoMode(width, height, bpp, flags)) {
con_warn << "Failed to set video mode " << width << "x" << height << "x" << bpp << "bpp" << std::endl;
if (width_prev && height_prev) {
width = width_prev;
height = height_prev;
- if(!SDL_SetVideoMode(width, height, bpp, flags )) {
+ if (!SDL_SetVideoMode(width, height, bpp, flags)) {
con_error << "Failed to restore video mode " << width << "x" << height << "x" << bpp << "bpp" << std::endl;
return false;
}
@@ -163,11 +165,11 @@ bool init()
int red, green, blue, alpha, depth;
- SDL_GL_GetAttribute( SDL_GL_RED_SIZE, &red);
- SDL_GL_GetAttribute( SDL_GL_GREEN_SIZE, &green);
- SDL_GL_GetAttribute( SDL_GL_RED_SIZE, &blue);
- SDL_GL_GetAttribute( SDL_GL_ALPHA_SIZE, &alpha);
- SDL_GL_GetAttribute( SDL_GL_DEPTH_SIZE, &depth);
+ SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &red);
+ SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &green);
+ SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &blue);
+ SDL_GL_GetAttribute(SDL_GL_ALPHA_SIZE, &alpha);
+ SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &depth);
con_debug << " visual r: " << red << " g: " << green << " blue: " << blue << " alpha: " << alpha << " depth: " << depth << std::endl;
@@ -198,7 +200,7 @@ bool init()
// apply render options
ui::root()->apply_render_options();
-
+
// initialize target drawer
targets::init();
@@ -222,8 +224,8 @@ void resize(int w, int h)
if (w < 320) w = 320;
if (h < 200) h = 200;
-
- if (SDL_SetVideoMode(w, h, bpp, flags )) {
+
+ if (SDL_SetVideoMode(w, h, bpp, flags)) {
render::resize(w, h);
ui::root()->set_size(w, h);
ui::root()->event_resize();
@@ -247,7 +249,7 @@ void set_cursor()
if (ui::console()->visible()) {
ui::root()->set_pointer();
- } else if(core::localplayer()->view() || ui::root()->active()) {
+ } else if (core::localplayer()->view() || ui::root()->active()) {
ui::root()->set_pointer("pointer");
@@ -268,7 +270,7 @@ void set_cursor()
ui::root()->set_pointer("target", ui::Palette::Active, true);
if (input::joystick_lastmoved_time() > input::mouse_lastmoved_time()) {
- ui::root()->input_mouse(render::State::width()/2, render::State::height() /2);
+ ui::root()->input_mouse(render::State::width() / 2, render::State::height() / 2);
}
} else if (input::mouse_control) {
@@ -276,11 +278,11 @@ void set_cursor()
ui::root()->set_pointer("control", ui::Palette::Pointer);
if (input::mouse_deadzone) {
- ui::root()->input_mouse(render::State::width()/2, render::State::height() /2);
+ ui::root()->input_mouse(render::State::width() / 2, render::State::height() / 2);
}
- } else if ((input::joystick_lastmoved_time() > input::mouse_lastmoved_time()) &&
- (render::Camera::mode() == render::Camera::Cockpit || render::Camera::mode() == render::Camera::Track)) {
+ } else if ((input::joystick_lastmoved_time() > input::mouse_lastmoved_time()) &&
+ (render::Camera::mode() == render::Camera::Cockpit || render::Camera::mode() == render::Camera::Track)) {
ui::root()->set_pointer();
@@ -293,7 +295,7 @@ void set_cursor()
void set_loader_message(const std::string message)
{
loader_message.assign(message);
-
+
if (is_loading)
frame_loader();
}
@@ -304,7 +306,7 @@ void set_loader_message(const char *message)
loader_message.assign(message);
else
loader_message.clear();
-
+
if (is_loading)
frame_loader();
}
@@ -312,7 +314,7 @@ void set_loader_message(const char *message)
void draw_loader()
{
render::Camera::ortho();
-
+
gl::enable(GL_BLEND);
gl::color(1.0f, 1.0f, 1.0f, 1.0f);
@@ -322,7 +324,7 @@ void draw_loader()
if (loader_message.size()) {
using render::Text;
- gl::enable(GL_TEXTURE_2D);
+ gl::enable(GL_TEXTURE_2D);
Text::setfont("gui", 12, 18);
Text::setcolor('N'); //set normal color
Text::draw(Text::fontwidth(), Text::fontheight(), loader_message);
@@ -330,7 +332,7 @@ void draw_loader()
}
gl::disable(GL_BLEND);
-
+
is_loading = true;
}
@@ -338,9 +340,9 @@ void frame_loader()
{
// Clear the color and depth buffers.
gl::clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
+
draw_loader();
-
+
SDL_GL_SwapBuffers();
}
@@ -351,15 +353,15 @@ void frame(float elapsed)
restart();
using namespace render;
-
+
is_loading = false;
-
+
// Clear the color and depth buffers.
gl::clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
render::Stats::clear();
if (core::application()->connected()) {
-
+
if (core::game()->time() && core::localplayer()->zone()) {
render::Camera::frame(elapsed);
render::Camera::frustum();
@@ -372,12 +374,12 @@ void frame(float elapsed)
render::Camera::ortho();
client()->worldview()->show();
-
+
} else {
draw_loader();
client()->worldview()->hide();
}
-
+
} else {
client()->worldview()->hide();
render::Camera::ortho();
@@ -398,17 +400,17 @@ void frame(float elapsed)
ui::console()->event_draw();
}
-
+
gl::disable(GL_TEXTURE_2D);
gl::disable(GL_BLEND);
-
+
SDL_GL_SwapBuffers();
}
void shutdown()
{
con_print << "^BShutting down video..." << std::endl;
-
+
targets::shutdown();
render::shutdown();
diff --git a/src/client/video.h b/src/client/video.h
index 978a876..93c3ce0 100644
--- a/src/client/video.h
+++ b/src/client/video.h
@@ -1,7 +1,7 @@
/*
client/video.h
- This file is part of the Osirion project and is distributed under
- the terms and conditions of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
*/
#ifndef __INCLUDED_CLIENT_VIDEO_H__
@@ -9,40 +9,41 @@
#include "core/cvar.h"
-namespace client {
+namespace client
+{
/// the video subsystem
-namespace video
+namespace video
{
- /// initialize the video subsystem
- bool init();
-
- /// shutdown the video subsystem
- void shutdown();
-
- /// re-initialize the video subsystems
- /** the restart functions performs a full shutdown
- * and re-initializes the video subsystem
- */
- void restart();
-
- /// application window resize event in windowed mode
- void resize(int w, int h);
-
- /// draw the next client video frame
- void frame(float elapsed);
-
- /// draw the loader screen
- void frame_loader();
-
- /// update the loader screen message
- void set_loader_message(const std::string message);
-
- /// update the loader screen message
- void set_loader_message(const char *message = 0);
-
- /// set the window caption
- void set_caption();
+/// initialize the video subsystem
+bool init();
+
+/// shutdown the video subsystem
+void shutdown();
+
+/// re-initialize the video subsystems
+/** the restart functions performs a full shutdown
+ * and re-initializes the video subsystem
+ */
+void restart();
+
+/// application window resize event in windowed mode
+void resize(int w, int h);
+
+/// draw the next client video frame
+void frame(float elapsed);
+
+/// draw the loader screen
+void frame_loader();
+
+/// update the loader screen message
+void set_loader_message(const std::string message);
+
+/// update the loader screen message
+void set_loader_message(const char *message = 0);
+
+/// set the window caption
+void set_caption();
} // namespace video
diff --git a/src/client/worldview.cc b/src/client/worldview.cc
index 7f13f45..c4f932b 100644
--- a/src/client/worldview.cc
+++ b/src/client/worldview.cc
@@ -1,7 +1,7 @@
/*
client/worldview.cc
- This file is part of the Osirion project and is distributed under
- the terms and conditions of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
*/
#include "core/application.h"
@@ -10,7 +10,8 @@
#include "client/video.h"
#include "ui/ui.h"
-namespace client {
+namespace client
+{
WorldView::WorldView(ui::Widget *parent) : ui::Widget(parent)
{
@@ -55,29 +56,29 @@ void WorldView::resize()
// reposition devinfo widget
view_devinfo->set_size(font()->width()*32, font()->height()*5);
view_devinfo->set_location(smallmargin, smallmargin);
-
+
// reposition stats widget
- view_statsinfo->set_size(font()->width()*12, font()->height()*5);
+ view_statsinfo->set_size(font()->width()*12, font()->height()*5);
view_statsinfo->set_location(width() - view_statsinfo->width() - smallmargin, smallmargin);
// reposition keypress widget
- view_keyinfo->set_size(font()->width()*12, font()->height()*1);
+ view_keyinfo->set_size(font()->width()*12, font()->height()*1);
view_keyinfo->set_location(width() - view_keyinfo->width() - smallmargin,
- height() - view_keyinfo->height() - smallmargin);
+ height() - view_keyinfo->height() - smallmargin);
// icons
const float icon_margin = 4.0f;
const float icon_size = 48.0f;
const float icon_count = 6;
- const float l = (width() -((icon_count +1) * icon_margin) - (icon_count * icon_size)) * 0.5f;
-
+ const float l = (width() - ((icon_count + 1) * icon_margin) - (icon_count * icon_size)) * 0.5f;
+
view_menubutton->set_geometry(l, icon_margin, icon_size, icon_size);
// spacer
- view_dockbutton->set_geometry( l + 2.0f * (icon_margin + icon_size), icon_margin, icon_size, icon_size);
- view_launchbutton->set_geometry( l + 2.0f * (icon_margin + icon_size), icon_margin, icon_size, icon_size);
+ view_dockbutton->set_geometry(l + 2.0f *(icon_margin + icon_size), icon_margin, icon_size, icon_size);
+ view_launchbutton->set_geometry(l + 2.0f *(icon_margin + icon_size), icon_margin, icon_size, icon_size);
// spacer
- view_chatbutton->set_geometry( l + 4.0f * (icon_margin + icon_size), icon_margin, icon_size, icon_size);
- view_mapbutton->set_geometry( l + 5.0f * (icon_margin + icon_size), icon_margin, icon_size, icon_size);
+ view_chatbutton->set_geometry(l + 4.0f *(icon_margin + icon_size), icon_margin, icon_size, icon_size);
+ view_mapbutton->set_geometry(l + 5.0f *(icon_margin + icon_size), icon_margin, icon_size, icon_size);
}
void WorldView::clear()
@@ -98,8 +99,8 @@ void WorldView::draw()
view_devinfo->set_visible(draw_devinfo->value() ? true : false);
view_statsinfo->set_visible(draw_stats->value() ? true : false);
view_keyinfo->set_visible(draw_keypress->value() ? true : false);
-
- if (ui::root()->active() || !core::game()->interactive() || !core::localcontrol() || (core::localplayer()->view() && !core::localplayer()->view()->menus().size()) ) {
+
+ if (ui::root()->active() || !core::game()->interactive() || !core::localcontrol() || (core::localplayer()->view() && !core::localplayer()->view()->menus().size())) {
view_playerview->hide();
view_menubutton->hide();
view_dockbutton->hide();
diff --git a/src/client/worldview.h b/src/client/worldview.h
index e42ac86..11473f8 100644
--- a/src/client/worldview.h
+++ b/src/client/worldview.h
@@ -1,7 +1,7 @@
/*
client/worldview.h
- This file is part of the Osirion project and is distributed under
- the terms and conditions of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
*/
#ifndef __INCLUDED_CLIENT_WORLDVIEW_H__
@@ -12,7 +12,8 @@
#include "client/infowidget.h"
#include "ui/iconbutton.h"
-namespace client {
+namespace client
+{
/// the world view when connected
class WorldView : public ui::Widget
@@ -25,7 +26,9 @@ public:
void event_text(const std::string & text);
- inline PlayerView *playerview() { return view_playerview; }
+ inline PlayerView *playerview() {
+ return view_playerview;
+ }
protected:
virtual void draw();
diff --git a/src/core/application.cc b/src/core/application.cc
index 4132c33..1d7ded2 100644
--- a/src/core/application.cc
+++ b/src/core/application.cc
@@ -58,7 +58,7 @@ extern "C" void signal_handler(int signum)
break;
}
}
-#endif
+#endif
/* ---- class Application ------------------------------------------ */
@@ -84,7 +84,7 @@ Application::Application()
sys::signal(SIGWINCH, signal_handler);
#endif
#endif
-
+
}
Application::~Application()
@@ -96,7 +96,7 @@ void Application::init(int count, char **arguments)
{
con_print << "^BInitializing core...\n";
con_debug << " debug messages enabled\n";
-
+
filesystem::init(arguments[0], "base", "");
Loader::load("base");
@@ -162,7 +162,7 @@ void Application::init(int count, char **arguments)
// Initialize win32 socket library
WSADATA wsa_data;
WORD wsa_version = MAKEWORD(2, 0);
- if (WSAStartup(wsa_version, &wsa_data) != 0 ) {
+ if (WSAStartup(wsa_version, &wsa_data) != 0) {
con_warn << "Could not initialize socket library!" << std::endl;
}
#endif
@@ -175,7 +175,7 @@ void Application::init(int count, char **arguments)
func = Func::add("quit", Application::func_quit);
func->set_info("exit the application");
-
+
func = Func::add("load", Application::func_load);
func->set_info("[string] load a game module");
@@ -218,7 +218,7 @@ void Application::shutdown()
Func::remove("say");
Func::remove("help");
Func::remove("quit");
-
+
Func::remove("connect");
Func::remove("disconnect");
Func::remove("load");
@@ -268,7 +268,7 @@ void Application::connect(std::string const &host)
if (application_game) {
disconnect();
}
-
+
if (host.size()) {
notify_connect();
application_game = new GameConnection(host);
@@ -282,7 +282,7 @@ void Application::connect(std::string const &host)
application_game = new GameServer();
if (application_game->running()) {
- con_print << "^BConnected to local game.\n";
+ con_print << "^BConnected to local game.\n";
} else {
delete application_game;
application_game = 0;
@@ -293,7 +293,7 @@ void Application::connect(std::string const &host)
void Application::disconnect()
{
- if(application_game) {
+ if (application_game) {
delete application_game;
application_game = 0;
notify_disconnect();
@@ -310,11 +310,11 @@ void Application::frame(unsigned long timestamp)
if (!connected())
return;
-
- // run a game interface frame
+
+ // run a game interface frame
application_game->frame(timestamp);
-
- if (!application_game->running())
+
+ if (!application_game->running())
disconnect();
}
@@ -345,7 +345,7 @@ void Application::save_config()
for (Cvar::Registry::iterator it = Cvar::registry().begin(); it != Cvar::registry().end(); it++) {
if (((*it).second->flags() & Cvar::Archive) == Cvar::Archive) {
ofs << "# " << (*it).first << " " << (*it).second->info() << std::endl;
- ofs << "set " << (*it).first << " " << (*it).second->str() << std::endl;
+ ofs << "set " << (*it).first << " " << (*it).second->str() << std::endl;
ofs << std::endl;
}
}
@@ -369,18 +369,18 @@ void Application::load_config()
con_print << " reading configuration from " << filename << std::endl;
char line[MAXCMDSIZE];
- while (ifs.getline(line, MAXCMDSIZE-1)) {
+ while (ifs.getline(line, MAXCMDSIZE - 1)) {
if (line[0] && line[0] != '#' && line[0] != ';')
cmd() << line << '\n';
}
-
+
// execute commands in the buffer
CommandBuffer::exec();
}
void Application::load_autoexec()
{
- if (Cvar::sv_dedicated->value())
+ if (Cvar::sv_dedicated->value())
return;
std::string filename(filesystem::writedir());
@@ -391,12 +391,12 @@ void Application::load_autoexec()
con_warn << "Could not read " << filename << std::endl;
std::ofstream ofs(filename.c_str());
-
+
if (!ofs.is_open()) {
con_warn << "Could not write " << filename << std::endl;
return;
}
-
+
ofs << "# autoexec.cfg - osirion client custom settings" << std::endl;
ofs << "# put your custom settings here" << std::endl;
ofs.close();
@@ -405,13 +405,13 @@ void Application::load_autoexec()
} else {
con_print << " reading configuration from " << filename << std::endl;
-
+
char line[MAXCMDSIZE];
- while (ifs.getline(line, MAXCMDSIZE-1)) {
+ while (ifs.getline(line, MAXCMDSIZE - 1)) {
if (line[0] && line[0] != '#' && line[0] != ';')
cmd() << line << '\n';
}
-
+
CommandBuffer::exec();
}
}
@@ -421,9 +421,9 @@ void Application::load_commandline(int count, char **arguments)
if (count < 2)
return;
- for (int i=1; i < count; i++) {
+ for (int i = 1; i < count; i++) {
if (arguments[i][0] == '+') {
- if (i >1)
+ if (i > 1)
cmd() << '\n';
if (arguments[i][1])
@@ -535,7 +535,7 @@ void Application::func_rcon(std::string const &args)
if (rconpassword && rconpassword->str().size()) {
connection()->rcon(args);
} else {
- con_warn << "rconpassword not set!" << std::endl;
+ con_warn << "rconpassword not set!" << std::endl;
}
} else if (server()) {
cmd() << args << "\n";
diff --git a/src/core/application.h b/src/core/application.h
index b2d8467..fbaba9d 100644
--- a/src/core/application.h
+++ b/src/core/application.h
@@ -24,36 +24,44 @@ class Application
public:
/// default constructor
Application();
-
+
/// default destructor
virtual ~Application();
-
-/*----- inspectors ----------------------------------------------- */
+
+ /*----- inspectors ----------------------------------------------- */
/// the current application time, in microseconds
- inline unsigned long timestamp() const { return application_timestamp; }
-
+ inline unsigned long timestamp() const {
+ return application_timestamp;
+ }
+
/// the current application time, in seconds
- float time() const { return ((float)(timestamp()) / 1000.0f); }
+ float time() const {
+ return ((float)(timestamp()) / 1000.0f);
+ }
/// true if the core is connected to a running game interface
- inline bool connected() const { return (application_game && application_game->running()); }
+ inline bool connected() const {
+ return (application_game && application_game->running());
+ }
/// return the game interface, returns 0 if the application is not connected to a game
- inline GameInterface *game() { return application_game; }
+ inline GameInterface *game() {
+ return application_game;
+ }
-/*----- mutators ------------------------------------------------- */
+ /*----- mutators ------------------------------------------------- */
/// start the server or connect to remote host
void connect(std::string const &host);
-
+
/// disconnect from the game module
void disconnect();
/// load a module
bool load(std::string const &module_name);
-/*----- virtual mutators ------------------------------------------ */
+ /*----- virtual mutators ------------------------------------------ */
/// initialize the application
virtual void init(int count, char **arguments);
@@ -64,7 +72,7 @@ public:
/// quit the application without proper shutdown
virtual void quit(int status);
-/*----- notifications --------------------------------------------- */
+ /*----- notifications --------------------------------------------- */
/// sound notifications from the core to the application
virtual void notify_sound(const char * name);
@@ -85,7 +93,9 @@ public:
virtual void notify_zonechange();
/// a pointer to the current application instance
- static inline Application *instance() { return application_instance; }
+ static inline Application *instance() {
+ return application_instance;
+ }
protected:
/// run a core frame
@@ -96,7 +106,7 @@ protected:
/// load exra config
void load_autoexec();
-
+
/// save cvar config
void save_config();
@@ -125,13 +135,22 @@ private:
};
/// pointer to the application
-inline Application *application() { return Application::instance(); }
+inline Application *application()
+{
+ return Application::instance();
+}
/// pointer to the console
-inline sys::ConsoleInterface *console() { return sys::ConsoleInterface::instance(); }
+inline sys::ConsoleInterface *console()
+{
+ return sys::ConsoleInterface::instance();
+}
/// pointer to the game interface
-inline GameInterface *game() { return Application::instance()->game(); }
+inline GameInterface *game()
+{
+ return Application::instance()->game();
+}
}
diff --git a/src/core/commandbuffer.cc b/src/core/commandbuffer.cc
index fbb9cfd..eb13382 100644
--- a/src/core/commandbuffer.cc
+++ b/src/core/commandbuffer.cc
@@ -37,7 +37,7 @@ void func_print_file(std::string const &args)
std::istringstream argstream(args);
std::string filename;
if (!(argstream >> filename))
- return;
+ return;
CommandBuffer::print_file(filename);
}
@@ -155,7 +155,7 @@ void func_toggle(std::string const &args)
if (cvar->flags() && Cvar::Info) {
localplayer()->set_dirty();
}
-
+
con_debug << " " << cvar->name() << " " << cvar->str() << "\n";
}
@@ -164,16 +164,16 @@ void func_exec(std::string const &args)
std::istringstream argstream(args);
std::string filename;
if (!(argstream >> filename))
- return;
+ return;
- CommandBuffer::exec_file(filename);
+ CommandBuffer::exec_file(filename);
}
void func_remote(std::string const &args)
{
if (connection()) {
if ((args[0] == '\\') || (args[0] == '/')) {
- connection()->forward(args.substr(1, args.size()-1));
+ connection()->forward(args.substr(1, args.size() - 1));
} else {
connection()->forward(args);
}
@@ -256,11 +256,11 @@ void CommandBuffer::exec(std::string const &cmdline)
std::istringstream cmdstream(cmdline);
std::string command;
-
+
if (!(cmdstream >> command))
return;
-
- aux::to_lowercase(command);
+
+ aux::to_lowercase(command);
//con_debug << "Executing '" << cmdline << "'\n";
if ((command[0] == '\\') || (command[0] == '/')) {
@@ -294,7 +294,7 @@ void CommandBuffer::exec(std::string const &cmdline)
}
f->exec(game()->localplayer(), args);
}
- }
+ }
} else {
// regular function
std::string args;
@@ -307,13 +307,13 @@ void CommandBuffer::exec(std::string const &cmdline)
}
return;
}
-
+
// is it a cvar
Cvar *cvar = Cvar::find(command);
if (cvar) {
// cvar exists
std::string value;
- if (((cvar->flags() & Cvar::ReadOnly) == 0) && (cmdstream >> value)) {
+ if (((cvar->flags() & Cvar::ReadOnly) == 0) && (cmdstream >> value)) {
// we're setting a new value
char c;
while (cmdstream.get(c))
@@ -324,15 +324,15 @@ void CommandBuffer::exec(std::string const &cmdline)
localplayer()->set_dirty();
}
}
-
+
con_print << " " << command << " " << cvar->str() << " ^N" << cvar->info() << "\n";
return;
}
-
+
// this gets forwarded to the server
if (connection()) {
if ((cmdline[0] == '\\') || (cmdline[0] == '/')) {
- connection()->forward(cmdline.substr(1, cmdline.size()-1));
+ connection()->forward(cmdline.substr(1, cmdline.size() - 1));
} else {
connection()->forward(cmdline);
}
@@ -345,13 +345,13 @@ void CommandBuffer::exec()
{
if (cmdbuf.eof())
return;
-
+
std::string line;
char c;
bool quote = false;
- while ( core::cmd().read(&c , 1) && c) {
- if ( c =='\n') {
+ while (core::cmd().read(&c , 1) && c) {
+ if (c == '\n') {
exec(line);
line.clear();
} else if (c == '"') {
@@ -360,13 +360,13 @@ void CommandBuffer::exec()
exec(line);
line.clear();
} else {
- line +=c;
+ line += c;
}
}
if (line.size())
exec(line);
-
+
cmdbuf.clear();
}
@@ -389,7 +389,7 @@ void CommandBuffer::complete(std::string &input, size_t &pos)
//con_print << " " << (*f).first << "\n";
}
}
-
+
// search cvar registry for matches
for (Cvar::Registry::iterator c = Cvar::registry().begin(); c != Cvar::registry().end(); c++) {
if (partial == (*c).first.substr(0, partial.size())) {
@@ -397,17 +397,17 @@ void CommandBuffer::complete(std::string &input, size_t &pos)
//con_print << " " << (*c).first << "\n";
}
}
-
+
if (!match.size())
return;
-
+
std::string maxmatch(*match.begin());
-
+
if (match.size() > 1) {
std::list<std::string>::iterator l;
- for (l = match.begin(); l !=match.end(); l++) {
+ for (l = match.begin(); l != match.end(); l++) {
if (maxmatch.size()) {
- size_t i =0;
+ size_t i = 0;
while ((i < maxmatch.size() && i < (*l).size()) && (maxmatch[i] == (*l)[i])) {
i++;
}
@@ -417,70 +417,70 @@ void CommandBuffer::complete(std::string &input, size_t &pos)
con_print << " " << (*l) << "\n";
}
con_print << match.size() << " matches\n";
-
+
}
-
+
if (maxmatch.size() > partial.size()) {
- if (match.size()==1) maxmatch += ' ';
+ if (match.size() == 1) maxmatch += ' ';
input.replace(start, pos, maxmatch);
pos = maxmatch.size();
}
-
+
}
void CommandBuffer::exec_file(std::string const & filename)
{
- filesystem::File *f = filesystem::open(filename.c_str());
- if (!f) {
- con_warn << "Could not open " << filename << std::endl;
- return;
- }
+ filesystem::File *f = filesystem::open(filename.c_str());
+ if (!f) {
+ con_warn << "Could not open " << filename << std::endl;
+ return;
+ }
- std::string fn = f->path();
- fn.append(f->name());
- filesystem::close(f);
+ std::string fn = f->path();
+ fn.append(f->name());
+ filesystem::close(f);
std::ifstream ifs;
ifs.open(fn.c_str());
- if (!ifs.is_open()) {
- con_warn << "Could not stream " << fn << "!\n";
- return;
- }
+ if (!ifs.is_open()) {
+ con_warn << "Could not stream " << fn << "!\n";
+ return;
+ }
con_print << "Executing " << fn.c_str() << std::endl;
char line[MAXCMDSIZE];
- while (ifs.getline(line, MAXCMDSIZE-1)) {
- if (line[0] && line[0] != '#' && line[0] != ';')
+ while (ifs.getline(line, MAXCMDSIZE - 1)) {
+ if (line[0] && line[0] != '#' && line[0] != ';')
exec(std::string(line));
- }
+ }
ifs.close();
}
void CommandBuffer::print_file(std::string const & filename)
{
- filesystem::File *f = filesystem::open(filename.c_str());
- if (!f) {
- con_warn << "Could not open " << filename << std::endl;
- return;
- }
+ filesystem::File *f = filesystem::open(filename.c_str());
+ if (!f) {
+ con_warn << "Could not open " << filename << std::endl;
+ return;
+ }
- std::string fn = f->path();
- fn.append(f->name());
- filesystem::close(f);
+ std::string fn = f->path();
+ fn.append(f->name());
+ filesystem::close(f);
std::ifstream ifs;
ifs.open(fn.c_str());
- if (!ifs.is_open()) {
- con_warn << "Could not stream " << fn << "!\n";
- return;
- }
+ if (!ifs.is_open()) {
+ con_warn << "Could not stream " << fn << "!\n";
+ return;
+ }
char line[MAXCMDSIZE];
- while (ifs.getline(line, MAXCMDSIZE-1)) {
+ while (ifs.getline(line, MAXCMDSIZE - 1)) {
con_print << line << "\n";
- }
+ }
ifs.close();
}
diff --git a/src/core/commandbuffer.h b/src/core/commandbuffer.h
index 9cd919b..c8024ba 100644
--- a/src/core/commandbuffer.h
+++ b/src/core/commandbuffer.h
@@ -48,7 +48,10 @@ private:
};
/// the global command buffer
-inline std::stringstream & cmd() { return CommandBuffer::cmdbuf; }
+inline std::stringstream & cmd()
+{
+ return CommandBuffer::cmdbuf;
+}
}
diff --git a/src/core/cvar.cc b/src/core/cvar.cc
index 1732d1a..6b4302d 100644
--- a/src/core/cvar.cc
+++ b/src/core/cvar.cc
@@ -163,8 +163,8 @@ void Cvar::list()
if (((*it).second->flags() & Archive) == Archive)
typeindicator += 'A';
else
- typeindicator += ' ';
-
+ typeindicator += ' ';
+
if (((*it).second->flags() & Game) == Game)
typeindicator += 'G';
else
@@ -175,8 +175,8 @@ void Cvar::list()
else
typeindicator += ' ';
- con_print << " " << typeindicator <<
- " " << (*it).first << " " << (*it).second->str() << " ^N" << (*it).second->info() << std::endl;
+ con_print << " " << typeindicator <<
+ " " << (*it).first << " " << (*it).second->str() << " ^N" << (*it).second->info() << std::endl;
}
con_print << cvar_registry.size() << " registered variables" << std::endl;
}
diff --git a/src/core/cvar.h b/src/core/cvar.h
index 4c3d942..3d7b246 100644
--- a/src/core/cvar.h
+++ b/src/core/cvar.h
@@ -28,34 +28,44 @@ public:
* Game a cvar with this flag is only valid when a game is loaded
* Info a cvar that updates player info
*/
- enum Flags {Archive=1, ReadOnly=2, Game=4, Info=8};
-
+ enum Flags {Archive = 1, ReadOnly = 2, Game = 4, Info = 8};
+
/// create a new variable
Cvar(const char* name, const unsigned int flags = 0);
-/*----- inspectors ------------------------------------------------ */
+ /*----- inspectors ------------------------------------------------ */
/// returns the name of the variable
- inline const std::string& name() const { return cvar_name; }
+ inline const std::string& name() const {
+ return cvar_name;
+ }
/// returns the info of the variable
- inline const std::string& info() const { return cvar_info; }
+ inline const std::string& info() const {
+ return cvar_info;
+ }
/// returns the flags of the variable
- inline const unsigned int flags() const { return cvar_flags; }
+ inline const unsigned int flags() const {
+ return cvar_flags;
+ }
/// returns the float value of the variable
- inline const float value() const { return cvar_value; }
+ inline const float value() const {
+ return cvar_value;
+ }
/// returns the string value of the variable
- inline const std::string& str() const { return cvar_str; }
+ inline const std::string& str() const {
+ return cvar_str;
+ }
-/*----- mutators -------------------------------------------------- */
+ /*----- mutators -------------------------------------------------- */
/// set the info string
void set_info(const char* info);
- /// char * assignment operator
+ /// char * assignment operator
Cvar &operator=(const char* other);
/// std::string assignment operator
@@ -64,40 +74,40 @@ public:
/// float assignment operator
Cvar &operator=(const float other);
-/* ---- Static functions for the Cvar registry -------------------- */
+ /* ---- Static functions for the Cvar registry -------------------- */
/// type definition for the Cvar registry
typedef std::map<std::string, Cvar*> Registry;
-
+
/**
* @brief get a cvar value from the registry
* If the a cvar with the given name already exists in the registry,
- * its value will not be changed. If the cvar does not exist,
- * it will be created
- */
- static Cvar* get(const char* name, const char* value, const unsigned int flags=0);
+ * its value will not be changed. If the cvar does not exist,
+ * it will be created
+ */
+ static Cvar* get(const char* name, const char* value, const unsigned int flags = 0);
/**
* @brief get a cvar value from the registry
* If the a cvar with the given name already exists in the registry,
- * its value will not be changed. If the cvar does not exist,
- * it will be created
- */
- static Cvar* get(const char* name, const float value, const unsigned int flags=0);
+ * its value will not be changed. If the cvar does not exist,
+ * it will be created
+ */
+ static Cvar* get(const char* name, const float value, const unsigned int flags = 0);
/**
* @brief set a cvar value
* If the a cvar with the given name already exists in the registry,
- * its value will be replaced
- */
- static Cvar* set(const char* name, const char* value, const unsigned int flags=0);
+ * its value will be replaced
+ */
+ static Cvar* set(const char* name, const char* value, const unsigned int flags = 0);
/**
* @brief set a cvar value
* If the a cvar with the given name already exists in the registry,
- * its value will be replaced
- */
- static Cvar* set(const char* name, float value, const unsigned int flags=0);
+ * its value will be replaced
+ */
+ static Cvar* set(const char* name, float value, const unsigned int flags = 0);
/// search for a named cvar, returns 0 if not found
static Cvar* find(const std::string& name);
@@ -115,7 +125,9 @@ public:
static void list();
/// the cvar registry
- static inline Registry & registry() { return cvar_registry; }
+ static inline Registry & registry() {
+ return cvar_registry;
+ }
static Cvar *sv_dedicated; // dedicated server
static Cvar *sv_private; // client with private server
diff --git a/src/core/descriptions.cc b/src/core/descriptions.cc
index 8c0f4ee..307cc87 100644
--- a/src/core/descriptions.cc
+++ b/src/core/descriptions.cc
@@ -8,7 +8,8 @@
#include "auxiliary/functions.h"
#include "sys/sys.h"
-namespace core {
+namespace core
+{
/* ---- class ButtonDescription ------------------------------------ */
@@ -55,7 +56,7 @@ MenuDescription::MenuDescription()
MenuDescription::~MenuDescription()
{
for (Buttons::iterator it = buttons().begin(); it != buttons().end(); it++) {
- delete (*it);
+ delete(*it);
}
buttons().clear();
@@ -82,16 +83,16 @@ void MenuDescription::add_button(ButtonDescription *button)
void Descriptions::serialize(MenuDescription *menu, std::ostream & os)
{
os << menu->label() << " "
- << "\"" << menu->text() << "\" "
- << menu->buttons().size() << " ";
-
+ << "\"" << menu->text() << "\" "
+ << menu->buttons().size() << " ";
+
for (MenuDescription::Buttons::iterator it = menu-> buttons().begin(); it != menu->buttons().end(); it++) {
ButtonDescription *button = (*it);
os << "\"" << button->text() << "\" "
- << button->alignment() << " "
- << button->command_type() << " "
- << "\"" << button->command() << "\" "
- << "\"" << button->modelname() << "\" ";
+ << button->alignment() << " "
+ << button->command_type() << " "
+ << "\"" << button->command() << "\" "
+ << "\"" << button->modelname() << "\" ";
}
}
@@ -111,8 +112,8 @@ MenuDescription * Descriptions::receive(std::istream &is)
// menu text
n.clear();
- while ( (is.get(c)) && (c != '"'));
- while ( (is.get(c)) && (c != '"'))
+ while ((is.get(c)) && (c != '"'));
+ while ((is.get(c)) && (c != '"'))
n += c;
if (n.size())
@@ -120,12 +121,12 @@ MenuDescription * Descriptions::receive(std::istream &is)
// menu buttons
is >> nb;
- for (size_t i=0; i < nb; i++) {
+ for (size_t i = 0; i < nb; i++) {
ButtonDescription *button = new ButtonDescription();
// button text
n.clear();
- while ( (is.get(c)) && (c != '"'));
- while ( (is.get(c)) && (c != '"'))
+ while ((is.get(c)) && (c != '"'));
+ while ((is.get(c)) && (c != '"'))
n += c;
if (n.size()) button->set_text(n);
@@ -144,8 +145,8 @@ MenuDescription * Descriptions::receive(std::istream &is)
// button command
n.clear();
- while ( (is.get(c)) && (c != '"'));
- while ( (is.get(c)) && (c != '"'))
+ while ((is.get(c)) && (c != '"'));
+ while ((is.get(c)) && (c != '"'))
n += c;
if (n.size()) {
@@ -158,8 +159,8 @@ MenuDescription * Descriptions::receive(std::istream &is)
// button modelname
n.clear();
- while ( (is.get(c)) && (c != '"'));
- while ( (is.get(c)) && (c != '"'))
+ while ((is.get(c)) && (c != '"'));
+ while ((is.get(c)) && (c != '"'))
n += c;
if (n.size()) button->set_modelname(n);
@@ -167,7 +168,7 @@ MenuDescription * Descriptions::receive(std::istream &is)
}
return menu;
-
+
}
bool Descriptions::load_entity_menus(core::Entity *entity, const std::string &menufilename)
@@ -180,11 +181,11 @@ bool Descriptions::load_entity_menus(core::Entity *entity, const std::string &me
}
con_debug << " " << inifile.name() << std::endl;
-
+
std::string strval;
MenuDescription *menu = 0;
ButtonDescription *button = 0;
-
+
while (inifile.getline()) {
if (inifile.got_section()) {
@@ -216,14 +217,14 @@ bool Descriptions::load_entity_menus(core::Entity *entity, const std::string &me
}
} else if (inifile.in_section("button")) {
-
+
if (!button) {
continue;
} else if (inifile.got_key_string("text", strval)) {
aux::strip_quotes(strval);
button->set_text(strval);
} else if (inifile.got_key_string("command", strval)) {
- for (size_t i =0; i <= strval.size(); i++) {
+ for (size_t i = 0; i <= strval.size(); i++) {
if (strval[i] == ',') strval[i] = ';';
}
aux::strip_quotes(strval);
diff --git a/src/core/descriptions.h b/src/core/descriptions.h
index dec7896..2b4b1e0 100644
--- a/src/core/descriptions.h
+++ b/src/core/descriptions.h
@@ -11,7 +11,8 @@
#include <list>
#include <iostream>
-namespace core {
+namespace core
+{
class ButtonDescription;
class MenuDescription;
}
@@ -20,38 +21,51 @@ class MenuDescription;
#include "model/model.h"
#include "filesystem/inifile.h"
-namespace core {
+namespace core
+{
/// description of a menu button
class ButtonDescription
{
public:
- enum Align {Center=0, Left=1, Right=2};
+ enum Align {Center = 0, Left = 1, Right = 2};
- enum CommandType {CommandNone=0, CommandGame=1, CommandMenu=2};
+ enum CommandType {CommandNone = 0, CommandGame = 1, CommandMenu = 2};
ButtonDescription();
~ButtonDescription();
-
+
/* -- inspectors ------------------------------------------- */
/// button text
- inline const std::string & text() const { return button_text; }
+ inline const std::string & text() const {
+ return button_text;
+ }
/// button command type
- inline const CommandType command_type() const {return button_commandtype; }
+ inline const CommandType command_type() const {
+ return button_commandtype;
+ }
/// button command
- inline const std::string & command() const { return button_command; }
+ inline const std::string & command() const {
+ return button_command;
+ }
/// button info view model name
- inline const std::string & modelname() const { return button_modelname; }
+ inline const std::string & modelname() const {
+ return button_modelname;
+ }
/// button info view model
- inline const model::Model *model() { return button_model; }
-
+ inline const model::Model *model() {
+ return button_model;
+ }
+
/// button text alignment
- inline Align alignment() const { return button_align; }
+ inline Align alignment() const {
+ return button_align;
+ }
/* -- mutators -------------------------------------------- */
@@ -88,13 +102,19 @@ public:
/* -- inspectors ------------------------------------------- */
/// menu label
- inline const std::string & label() const { return menu_label; }
+ inline const std::string & label() const {
+ return menu_label;
+ }
/// menu text
- inline const std::string & text() const { return menu_text; }
+ inline const std::string & text() const {
+ return menu_text;
+ }
/// menu buttons
- inline Buttons &buttons() { return menu_buttons; }
+ inline Buttons &buttons() {
+ return menu_buttons;
+ }
/* -- mutators -------------------------------------------- */
@@ -110,13 +130,14 @@ public:
private:
std::string menu_label;
std::string menu_text;
-
+
Buttons menu_buttons;
};
/// descriptions loader class
-class Descriptions {
+class Descriptions
+{
public:
/// read entity menus from ini file
static bool load_entity_menus(core::Entity *entity, const std::string &menufilename);
diff --git a/src/core/entity.cc b/src/core/entity.cc
index 0ead5f4..ce313e6 100644
--- a/src/core/entity.cc
+++ b/src/core/entity.cc
@@ -78,9 +78,9 @@ void Entity::list()
std::string typeindicator;
Entity *entity = (*it).second;
con_print << " id " << std::setw(4) << entity->id()
- << " type " << std::setw(4) << entity->type()
- << ":" << std::setw(4) << entity->moduletype()
- << " " << entity->label() << std::endl;
+ << " type " << std::setw(4) << entity->type()
+ << ":" << std::setw(4) << entity->moduletype()
+ << " " << entity->label() << std::endl;
}
con_print << entity_registry.size() << " registered entities" << std::endl;
}
@@ -88,21 +88,21 @@ void Entity::list()
/* ---- class Entity ----------------------------------------------- */
Entity::Entity(const unsigned int flags) :
- entity_location(0.0f, 0.0f, 0.0f),
- entity_color(1.0f, 1.0f, 1.0f, 1.0f),
- entity_color_second(1.0f, 1.0f, 1.0f, 1.0f)
+ entity_location(0.0f, 0.0f, 0.0f),
+ entity_color(1.0f, 1.0f, 1.0f, 1.0f),
+ entity_color_second(1.0f, 1.0f, 1.0f, 1.0f)
{
entity_id = 0;
entity_flags = flags;
entity_moduletypeid = 0;
entity_speed = 0.0f;
-
+
entity_radius = 0.5f;
entity_shape = Diamond;
-
+
entity_created = true;
- entity_destroyed = false;
+ entity_destroyed = false;
entity_dirty = false;
entity_model = 0;
@@ -133,25 +133,25 @@ Entity::Entity(std::istream & is)
entity_created = true;
entity_destroyed = false;
-
+
memset(entity_extension, 0, sizeof(entity_extension));
}
Entity::~Entity()
{
// delete extensions
- for (size_t i =0; i < 4; i++) {
+ for (size_t i = 0; i < 4; i++) {
if (entity_extension[i])
delete entity_extension[i];
- entity_extension[i] = 0;
+ entity_extension[i] = 0;
}
// delete entity menus
for (Menus::iterator it = menus().begin(); it != menus().end(); it++) {
- delete (*it);
+ delete(*it);
}
menus().clear();
-
+
if (entity_zone)
entity_zone->remove(this);
}
@@ -234,19 +234,19 @@ void Entity::set_modelname(const std::string &modelname)
void Entity::serialize_server_create(std::ostream & os) const
{
os << moduletype() << " "
- << flags() << " "
- << (visible() ? 1 : 0) << " "
- << (zone() ? zone()->id() : 0) << " "
- << std::setprecision(8) << entity_location << " "
- << color() << " "
- << color_second() << " "
- << shape() << " "
- << radius() << " "
- << std::setprecision(8) << entity_axis.forward() << " "
- << std::setprecision(8) << entity_axis.left() << " "
- << "\"" << entity_label << "\" "
- << "\"" << entity_name << "\" "
- << "\"" << (entity_model ? entity_model->name() : "") << "\" ";
+ << flags() << " "
+ << (visible() ? 1 : 0) << " "
+ << (zone() ? zone()->id() : 0) << " "
+ << std::setprecision(8) << entity_location << " "
+ << color() << " "
+ << color_second() << " "
+ << shape() << " "
+ << radius() << " "
+ << std::setprecision(8) << entity_axis.forward() << " "
+ << std::setprecision(8) << entity_axis.left() << " "
+ << "\"" << entity_label << "\" "
+ << "\"" << entity_name << "\" "
+ << "\"" << (entity_model ? entity_model->name() : "") << "\" ";
}
void Entity::receive_server_create(std::istream &is)
@@ -271,12 +271,12 @@ void Entity::receive_server_create(std::istream &is)
if (entity_zone && !zo) {
con_warn << "Received entity " << entity_id << " for unknown zone " << zo << "!" << std::endl;
}
-
+
is >> entity_location;
is >> entity_color;
is >> entity_color_second;
-
- is >> s; // shape
+
+ is >> s; // shape
entity_shape = (Shape) s;
is >> entity_radius;
@@ -289,23 +289,23 @@ void Entity::receive_server_create(std::istream &is)
char c;
// read label
- while ( (is.get(c)) && (c != '"'));
- while ( (is.get(c)) && (c != '"'))
- n += c;
+ while ((is.get(c)) && (c != '"'));
+ while ((is.get(c)) && (c != '"'))
+ n += c;
entity_label = n;
n.clear();
// read name
- while ( (is.get(c)) && (c != '"'));
- while ( (is.get(c)) && (c != '"'))
- n += c;
+ while ((is.get(c)) && (c != '"'));
+ while ((is.get(c)) && (c != '"'))
+ n += c;
entity_name = n;
n.clear();
// read model name
- while ( (is.get(c)) && (c != '"'));
- while ( (is.get(c)) && (c != '"'))
- n += c;
+ while ((is.get(c)) && (c != '"'));
+ while ((is.get(c)) && (c != '"'))
+ n += c;
set_modelname(n);
entity_dirty = false;
@@ -354,21 +354,21 @@ void Entity::remove_menu(std::string const &label)
for (Menus::iterator it = menus().begin(); it != menus().end(); it++) {
if (label.compare((*it)->label()) == 0)
menus().erase(it);
- return;
+ return;
}
}
/* ---- class EntityDynamic ---------------------------------------- */
EntityDynamic::EntityDynamic(unsigned int flags) :
- Entity(flags)
+ Entity(flags)
{
entity_state = Normal;
entity_timer = 0;
}
EntityDynamic::EntityDynamic(std::istream & is) :
- Entity(is)
+ Entity(is)
{
entity_state = Normal;
entity_timer = 0;
@@ -403,10 +403,10 @@ void EntityDynamic::serialize_server_create(std::ostream & os) const
{
Entity::serialize_server_create(os);
os << roundf(entity_speed * 100.0f) << " "
- << entity_state << " ";
+ << entity_state << " ";
if (entity_state != Normal) {
- os << entity_timer << " ";
+ os << entity_timer << " ";
}
}
@@ -434,7 +434,7 @@ void EntityDynamic::receive_client_update(std::istream &is)
void EntityDynamic::serialize_server_update(std::ostream & os) const
{
- os << (visible() ? 1 : 0 ) << " ";
+ os << (visible() ? 1 : 0) << " ";
if (visible()) {
os << std::setprecision(8)
<< location() << " "
@@ -442,7 +442,7 @@ void EntityDynamic::serialize_server_update(std::ostream & os) const
<< axis().left() << " "
<< roundf(entity_speed * 100.0f) << " "
<< entity_state << " ";
-
+
if (entity_state != Normal) {
os << entity_timer << " ";
}
@@ -463,7 +463,7 @@ void EntityDynamic::receive_server_update(std::istream &is)
is >> entity_speed;
entity_speed /= 100.0f;
is >> entity_state;
-
+
if (entity_state != Normal) {
is >> entity_timer;
} else {
@@ -477,7 +477,7 @@ void EntityDynamic::receive_server_update(std::istream &is)
/*----- EntityControlable ------------------------------------------ */
EntityControlable::EntityControlable(Player *owner, unsigned int flags) :
- EntityDynamic(flags)
+ EntityDynamic(flags)
{
entity_thrust = 0;
entity_movement = 0;
@@ -495,7 +495,7 @@ EntityControlable::EntityControlable(Player *owner, unsigned int flags) :
}
EntityControlable::EntityControlable(std::istream & is) :
- EntityDynamic(is)
+ EntityDynamic(is)
{
entity_thrust = 0;
entity_movement = 0;
@@ -521,7 +521,7 @@ void EntityControlable::serialize_server_create(std::ostream & os) const
{
EntityDynamic::serialize_server_create(os);
os << roundf(entity_thrust*100.0f) << " "
- << ( entity_owner ? entity_owner->id() : 0) << " ";
+ << (entity_owner ? entity_owner->id() : 0) << " ";
}
void EntityControlable::receive_server_create(std::istream &is)
@@ -532,16 +532,16 @@ void EntityControlable::receive_server_create(std::istream &is)
entity_thrust /= 100.0f;
entity_owner = 0;
-
+
int owner_id = 0;
is >> owner_id;
if (owner_id) {
- for (GameInterface::Players::iterator pit = game()->players().begin(); pit != game()->players().end(); pit++ ) {
+ for (GameInterface::Players::iterator pit = game()->players().begin(); pit != game()->players().end(); pit++) {
Player *player = (*pit);
if (player->id() == owner_id) {
player->add_asset(this);
entity_owner = player;
-
+
}
}
@@ -666,7 +666,7 @@ void EntityControlable::set_afterburner(float afterburner)
/*----- EntityGlobe ------------------------------------------------ */
EntityGlobe::EntityGlobe(unsigned int flags) :
- Entity(flags)
+ Entity(flags)
{
render_texture = 0;
entity_rotationspeed = 0;
@@ -674,7 +674,7 @@ EntityGlobe::EntityGlobe(unsigned int flags) :
}
EntityGlobe::EntityGlobe(std::istream & is) :
- Entity(is)
+ Entity(is)
{
render_texture = 0;
entity_rotationspeed = 0;
@@ -699,9 +699,9 @@ void EntityGlobe::receive_server_create(std::istream &is)
std::string n;
char c;
- while ( (is.get(c)) && (c != '"'));
- while ( (is.get(c)) && (c != '"'))
- n += c;
+ while ((is.get(c)) && (c != '"'));
+ while ((is.get(c)) && (c != '"'))
+ n += c;
entity_texture = n;
n.clear();
diff --git a/src/core/entity.h b/src/core/entity.h
index 3002219..92cb5ab 100644
--- a/src/core/entity.h
+++ b/src/core/entity.h
@@ -39,16 +39,16 @@ class Entity
public:
/// Entity flags
- enum Flags {Static=1, Solid=2, Bright=4, Dockable=8, ShowOnMap=16};
+ enum Flags {Static = 1, Solid = 2, Bright = 4, Dockable = 8, ShowOnMap = 16};
/// Entity type constants
- enum Type {Default=0, Dynamic=1, Controlable=2, Globe=3};
+ enum Type {Default = 0, Dynamic = 1, Controlable = 2, Globe = 3};
/// Entity shape constants
- enum Shape {Diamond=0, Sphere=1, Cube=2, Axis=3};
+ enum Shape {Diamond = 0, Sphere = 1, Cube = 2, Axis = 3};
/// EntityDynamic State constants
- enum State {Normal=0, NoPower=1, ImpulseInitiate=2, Impulse=3, JumpInitiate=4, Jump=5, Docked=6, Destroyed=7};
+ enum State {Normal = 0, NoPower = 1, ImpulseInitiate = 2, Impulse = 3, JumpInitiate = 4, Jump = 5, Docked = 6, Destroyed = 7};
/// entity menus collection typedef
typedef std::list<MenuDescription *> Menus;
@@ -62,76 +62,122 @@ public:
/// destroy an entity
virtual ~Entity();
-/*----- inspectors ------------------------------------------------ */
-
+ /*----- inspectors ------------------------------------------------ */
+
/// entity id
- inline const unsigned int id() const { return entity_id; }
-
+ inline const unsigned int id() const {
+ return entity_id;
+ }
+
/// module type id
- inline const unsigned int moduletype() const { return entity_moduletypeid; }
+ inline const unsigned int moduletype() const {
+ return entity_moduletypeid;
+ }
/// core type id
- virtual inline const unsigned int type() const { return Default; }
+ virtual inline const unsigned int type() const {
+ return Default;
+ }
/// entity flags
- inline const unsigned int flags() const { return entity_flags; }
+ inline const unsigned int flags() const {
+ return entity_flags;
+ }
/// returns true of a flag is set
- inline const bool flag_is_set(const Flags flag) const { return ((entity_flags & (unsigned int)flag) == (unsigned int)flag); }
+ inline const bool flag_is_set(const Flags flag) const {
+ return ((entity_flags & (unsigned int)flag) == (unsigned int)flag);
+ }
/// entity label (can not contain double quotes ")
- inline const std::string& label() const { return entity_label; }
+ inline const std::string& label() const {
+ return entity_label;
+ }
/// entity name (can not contain double qoutes ")
- inline const std::string & name() const { return entity_name; }
+ inline const std::string & name() const {
+ return entity_name;
+ }
/// pointer to the model, is used client-side
- inline model::Model * model() { return entity_model; }
+ inline model::Model * model() {
+ return entity_model;
+ }
/// modelname
- inline const std::string & modelname() const { return entity_modelname; }
+ inline const std::string & modelname() const {
+ return entity_modelname;
+ }
/// pointer to the zone the entity belongs to
- inline Zone *zone() const { return entity_zone; }
+ inline Zone *zone() const {
+ return entity_zone;
+ }
/// the zone the entity left in case of a zone change
- inline Zone *oldzone() const { return entity_oldzone; }
+ inline Zone *oldzone() const {
+ return entity_oldzone;
+ }
/// dirty flag
- inline bool dirty() const { return entity_dirty; }
+ inline bool dirty() const {
+ return entity_dirty;
+ }
/// entity location
- inline const math::Vector3f& location() const { return entity_location; }
+ inline const math::Vector3f& location() const {
+ return entity_location;
+ }
/// local coordinate system of the entity
- inline const math::Axis& axis() const { return entity_axis; }
-
+ inline const math::Axis& axis() const {
+ return entity_axis;
+ }
+
/// primary color of the entity
- inline const math::Color& color() const { return entity_color; }
+ inline const math::Color& color() const {
+ return entity_color;
+ }
/// secondary
- inline const math::Color& color_second() const { return entity_color_second; }
+ inline const math::Color& color_second() const {
+ return entity_color_second;
+ }
/// base shape of the entity
- inline const Shape shape() const { return entity_shape; }
+ inline const Shape shape() const {
+ return entity_shape;
+ }
/// base radius of the entity
- inline const float radius() const { return entity_radius; }
+ inline const float radius() const {
+ return entity_radius;
+ }
/// current speed of the entity in game units per second
- inline const float speed() const { return entity_speed; }
+ inline const float speed() const {
+ return entity_speed;
+ }
/// indicates a server-side entity
- inline const bool serverside() const { return entity_serverside; }
+ inline const bool serverside() const {
+ return entity_serverside;
+ }
/// general visibility
- inline const bool visible() const { return entity_visible; }
+ inline const bool visible() const {
+ return entity_visible;
+ }
/// entity menus
- inline Menus &menus() { return entity_menus; }
+ inline Menus &menus() {
+ return entity_menus;
+ }
/// extensions
- inline Extension *extension(size_t type) const { return entity_extension[type]; }
+ inline Extension *extension(size_t type) const {
+ return entity_extension[type];
+ }
/// find a menu
MenuDescription *find_menu(const std::string &label);
@@ -140,13 +186,19 @@ public:
/* ---- mutators -------------------------------------------------- */
/// assign entity color
- inline void set_color(const math::Color &color) { entity_color.assign(color); }
+ inline void set_color(const math::Color &color) {
+ entity_color.assign(color);
+ }
/// assign entity secondary color
- inline void set_color_second(const math::Color &color) { entity_color_second.assign(color); }
+ inline void set_color_second(const math::Color &color) {
+ entity_color_second.assign(color);
+ }
/// set dirty flag
- inline void set_dirty(const bool dirty = true) { entity_dirty = dirty; }
+ inline void set_dirty(const bool dirty = true) {
+ entity_dirty = dirty;
+ }
/// mark the entity as destroyed
virtual void die();
@@ -178,10 +230,14 @@ public:
void set_name(const std::string &name);
/// set visibility
- inline void set_visible(const bool visible = true) { entity_visible = visible; }
+ inline void set_visible(const bool visible = true) {
+ entity_visible = visible;
+ }
/// set as server-side entity
- inline void set_serverside(const bool serverside = true) { entity_serverside = serverside; }
+ inline void set_serverside(const bool serverside = true) {
+ entity_serverside = serverside;
+ }
/// set the model name and load the model
void set_modelname(const std:: string &model);
@@ -190,7 +246,9 @@ public:
void set_model(model::Model *model);
/// set entity radius
- inline void set_radius(const float radius) { entity_radius = radius; }
+ inline void set_radius(const float radius) {
+ entity_radius = radius;
+ }
/* ---- actors ---------------------------------------------------- */
@@ -198,10 +256,14 @@ public:
virtual void dock(core::Entity *entity);
/// set flags
- inline void set_flag(Flags flag) { entity_flags |= flag; }
+ inline void set_flag(Flags flag) {
+ entity_flags |= flag;
+ }
/// unset flags
- inline void unset_flag(Flags flag) { entity_flags &= ~flag; }
+ inline void unset_flag(Flags flag) {
+ entity_flags &= ~flag;
+ }
/// add an entity menu
void add_menu(MenuDescription *menu);
@@ -215,23 +277,31 @@ public:
/**
* @brief mutable reference to the location
*/
- inline math::Vector3f& get_location() { return entity_location; }
+ inline math::Vector3f& get_location() {
+ return entity_location;
+ }
/**
* @brief mutable reference to the axis
*/
- inline math::Axis& get_axis() { return entity_axis; }
+ inline math::Axis& get_axis() {
+ return entity_axis;
+ }
/**
* @brief mutable reference to the primary color
*/
- inline math::Color& get_color() { return entity_color; }
+ inline math::Color& get_color() {
+ return entity_color;
+ }
/**
* @brief mutable reference to the secondary color
*/
- inline math::Color& get_color_second() { return entity_color_second; }
+ inline math::Color& get_color_second() {
+ return entity_color_second;
+ }
/* ---- deserializers -------------------------------------- */
@@ -257,7 +327,7 @@ public:
/* ---- static --------------------------------------------- */
-
+
/// type definition for the entity registry
typedef std::map<unsigned int, Entity*> Registry;
@@ -274,13 +344,15 @@ public:
static void list();
/// the entity registry
- static inline Registry & registry() { return entity_registry; }
+ static inline Registry & registry() {
+ return entity_registry;
+ }
/* entity_ variables can be set by the module */
/// speed of the entity
- float entity_speed;
- Shape entity_shape;
+ float entity_speed;
+ Shape entity_shape;
unsigned int entity_moduletypeid;
bool entity_created;
@@ -321,7 +393,7 @@ private:
Extension* entity_extension[4];
- static Registry entity_registry;
+ static Registry entity_registry;
static size_t entity_nextid;
static void add(Entity *ent);
@@ -340,17 +412,23 @@ public:
virtual ~EntityDynamic();
-/*----- inspectors ------------------------------------------------ */
+ /*----- inspectors ------------------------------------------------ */
/// core type id
- virtual inline const unsigned int type() const { return Entity::Dynamic; }
+ virtual inline const unsigned int type() const {
+ return Entity::Dynamic;
+ }
/// event state
- inline const int state() const { return entity_state; }
+ inline const int state() const {
+ return entity_state;
+ }
/// event state timer
- inline const float timer() const { return entity_timer; }
+ inline const float timer() const {
+ return entity_timer;
+ }
-/*----- serializers ----------------------------------------------- */
+ /*----- serializers ----------------------------------------------- */
/// serialize the entity to a stream
virtual void serialize_server_create(std::ostream & os) const;
@@ -361,7 +439,7 @@ public:
/// serialize a server-to-client update on a stream
virtual void serialize_server_update(std::ostream & os) const;
-/*----- mutators -------------------------------------------------- */
+ /*----- mutators -------------------------------------------------- */
/// receive a client-to-server update from a stream
virtual void receive_client_update(std::istream &is);
@@ -398,24 +476,32 @@ public:
/// create a controlable entity from stream data
EntityControlable(std::istream & is);
-
+
virtual ~EntityControlable();
-/*----- inspectors ------------------------------------------------ */
+ /*----- inspectors ------------------------------------------------ */
/// core type id
- virtual inline const unsigned int type() const { return Entity::Controlable; }
+ virtual inline const unsigned int type() const {
+ return Entity::Controlable;
+ }
/// owner of this entity
- inline Player *owner() const { return entity_owner; }
+ inline Player *owner() const {
+ return entity_owner;
+ }
/// thrust
- inline float thrust() const { return entity_thrust; }
+ inline float thrust() const {
+ return entity_thrust;
+ }
/// movement indicator
- inline float movement() const { return entity_movement; }
+ inline float movement() const {
+ return entity_movement;
+ }
-/*----- serializers ----------------------------------------------- */
+ /*----- serializers ----------------------------------------------- */
/// serialize the entity to a stream
virtual void serialize_server_create(std::ostream & os) const;
@@ -426,7 +512,7 @@ public:
/// serialize a server-to-client update on a stream
virtual void serialize_server_update(std::ostream & os) const;
-/*----- mutators -------------------------------------------------- */
+ /*----- mutators -------------------------------------------------- */
/// receive a client-to-server update from a stream
virtual void receive_client_update(std::istream &is);
@@ -442,7 +528,7 @@ public:
/// set the target direction
void set_direction(float direction);
-
+
/// set the target pitch
void set_pitch(float pitch);
@@ -494,7 +580,7 @@ private:
};
/// a Globe entity
-class EntityGlobe : public Entity
+class EntityGlobe : public Entity
{
public:
EntityGlobe(const unsigned int flags = 0);
@@ -502,14 +588,18 @@ public:
virtual ~EntityGlobe();
-/*----- inspectors ----------------------------------------------- */
+ /*----- inspectors ----------------------------------------------- */
/// texture name
- inline const std::string &texture() const { return entity_texture; }
+ inline const std::string &texture() const {
+ return entity_texture;
+ }
/// rotation speed in degrees per second
- inline float rotationspeed() const { return entity_rotationspeed; }
+ inline float rotationspeed() const {
+ return entity_rotationspeed;
+ }
-/*----- serializers ----------------------------------------------- */
+ /*----- serializers ----------------------------------------------- */
/// serialize the entity to a stream
virtual void serialize_server_create(std::ostream & os) const;
@@ -517,10 +607,12 @@ public:
/// receive a server-to-client create from a stream
virtual void receive_server_create(std::istream &is);
-/*----- inspectors ------------------------------------------------ */
+ /*----- inspectors ------------------------------------------------ */
/// core type id
- virtual inline const unsigned int type() const { return Entity::Globe; }
+ virtual inline const unsigned int type() const {
+ return Entity::Globe;
+ }
std::string entity_texture;
diff --git a/src/core/extension.h b/src/core/extension.h
index 0b9ecad..91ba906 100644
--- a/src/core/extension.h
+++ b/src/core/extension.h
@@ -7,23 +7,30 @@
#ifndef __INCLUDED_CORE_EXTENSION_H__
#define __INCLUDED_CORE_EXTENSION_H__
-namespace core {
- class Extension;
+namespace core
+{
+class Extension;
}
#include "core/entity.h"
-namespace core {
+namespace core
+{
/// a abstract base class for entity extensions
-class Extension {
+class Extension
+{
public:
/// extension types
- enum Type { Client=0, Render=1, Sound=2, Game=3 };
+ enum Type { Client = 0, Render = 1, Sound = 2, Game = 3 };
- inline Type type() const { return extension_type; }
+ inline Type type() const {
+ return extension_type;
+ }
- inline Entity *entity() { return extension_entity; }
+ inline Entity *entity() {
+ return extension_entity;
+ }
Extension(Type type, Entity *entity);
virtual ~Extension();
@@ -33,7 +40,7 @@ public:
private:
Type extension_type;
Entity *extension_entity;
-
+
};
} // namespace core
diff --git a/src/core/func.cc b/src/core/func.cc
index 42c46c8..be5aca3 100644
--- a/src/core/func.cc
+++ b/src/core/func.cc
@@ -66,8 +66,8 @@ Func *Func::add(const char *name, TargetFuncPtr targetfunctionptr)
void Func::remove(const char *name)
{
std::map<std::string, Func *>::iterator it = func_registry.find(std::string(name));
- if (it != func_registry.end()) {
- delete (*it).second;
+ if (it != func_registry.end()) {
+ delete(*it).second;
func_registry.erase(it);
//con_debug << "Function '" << name << "' unregistered." << std::endl;
}
@@ -76,11 +76,11 @@ void Func::remove(const char *name)
void Func::remove(const std::string &name)
{
std::map<std::string, Func *>::iterator it = func_registry.find(name);
- if (it != func_registry.end()) {
- delete (*it).second;
- func_registry.erase(it);
+ if (it != func_registry.end()) {
+ delete(*it).second;
+ func_registry.erase(it);
//con_debug << "Function '" << name << "' unregistered." << std::endl;
- }
+ }
}
@@ -104,7 +104,7 @@ void Func::list()
typeindicator += 'G';
else
typeindicator += ' ';
- if (((*it).second->flags() & Shared) == Shared)
+ if (((*it).second->flags() & Shared) == Shared)
typeindicator += 'S';
else
typeindicator += ' ';
@@ -150,12 +150,12 @@ void Func::exec(std::string const &args)
FuncPtr function = (FuncPtr) func_ptr;
function(args);
}
-
+
void Func::exec(Player *player, std::string const &args)
{
if (!(flags() & Game))
return;
-
+
GameFuncPtr gamefunction = (GameFuncPtr) func_ptr;
gamefunction(player, args);
}
diff --git a/src/core/func.h b/src/core/func.h
index eacd47e..f42eff7 100644
--- a/src/core/func.h
+++ b/src/core/func.h
@@ -27,49 +27,55 @@ typedef void(* GameFuncPtr)(Player *player, std::string const &args);
typedef void(* TargetFuncPtr)(Player *player, Entity *entity);
/// a function pointer encapsulation class
-class Func
+class Func
{
public:
/// function flags
- enum Flags {Game=1, Shared=2, Target=4};
-
+ enum Flags {Game = 1, Shared = 2, Target = 4};
+
/// create a new function
Func(char const * name, void *ptr, unsigned int flags = 0);
-
+
~Func();
-/*----- inspectors ------------------------------------------------ */
+ /*----- inspectors ------------------------------------------------ */
/// returns the fucuntion flags
- inline unsigned int flags() const { return func_flags; }
+ inline unsigned int flags() const {
+ return func_flags;
+ }
/// returns the name of the function
- inline std::string const &name() const { return func_name; }
+ inline std::string const &name() const {
+ return func_name;
+ }
/// returns the info of the function
- inline std::string const &info() { return func_info; }
+ inline std::string const &info() {
+ return func_info;
+ }
+
+ /*----- mutators -------------------------------------------------- */
-/*----- mutators -------------------------------------------------- */
-
/// set the info string
void set_info(const char *);
/// execute the function if the Game flag is not set
void exec(std::string const &args);
-
+
/// execute the function if the Game flag is set
void exec(Player *player, std::string const &args);
/// execute the function if the Target flag is set
void exec(Player *player, Entity *entity);
-/* ---- Static functions for the Func registry -------------------- */
+ /* ---- Static functions for the Func registry -------------------- */
/// type definition
typedef std::map<std::string, Func*> Registry;
/// add a function to the registry
- static Func *add(const char *name, FuncPtr functionptr, bool shared=false);
+ static Func *add(const char *name, FuncPtr functionptr, bool shared = false);
/// add a game function to the registry and set the Game flag
static Func *add(const char *name, GameFuncPtr functionptr);
@@ -90,7 +96,9 @@ public:
static void list();
/// the function registry
- static inline Registry & registry() { return func_registry; }
+ static inline Registry & registry() {
+ return func_registry;
+ }
private:
std::string func_name;
diff --git a/src/core/gameconnection.cc b/src/core/gameconnection.cc
index 65126e3..b615b5f 100644
--- a/src/core/gameconnection.cc
+++ b/src/core/gameconnection.cc
@@ -31,7 +31,7 @@ GameConnection::GameConnection(std::string const &connectionstr)
size_t found = host.find(':');
if (found != std::string::npos) {
- std::istringstream str(host.substr(found+1));
+ std::istringstream str(host.substr(found + 1));
if (str >> port) {
host.erase(found, std::string::npos);
} else {
@@ -82,7 +82,7 @@ unsigned long GameConnection::timestamp() const
float GameConnection::time() const
{
- return ((float)(connection_timestamp) / 1000.0f);
+ return ((float)(connection_timestamp) / 1000.0f);
}
bool GameConnection::interactive() const
@@ -165,18 +165,18 @@ void GameConnection::frame(unsigned long timestamp)
connection_network->frame();
float f = 0;
- if (core::Cvar::net_framerate->value()) {
+ if (core::Cvar::net_framerate->value()) {
f = 1000.0f / core::Cvar::net_framerate->value();
if (connection_netframe + f > timestamp) {
return;
}
- }
+ }
connection_netframe = timestamp;
if (connection_network->state() == NetConnection::Connected) {
- if(localcontrol() && localcontrol()->dirty()) {
+ if (localcontrol() && localcontrol()->dirty()) {
connection_network->send_clientupdate(localcontrol());
localcontrol()->set_dirty(false);
@@ -184,7 +184,7 @@ void GameConnection::frame(unsigned long timestamp)
if (localplayer()->dirty()) {
connection_network->send_playerinfo();
-
+
}
}
diff --git a/src/core/gameconnection.h b/src/core/gameconnection.h
index 22af910..52885f4 100644
--- a/src/core/gameconnection.h
+++ b/src/core/gameconnection.h
@@ -20,13 +20,17 @@ public:
GameConnection(std::string const &connectionstr);
virtual ~GameConnection();
-/*----- inspectors ------------------------------------------------ */
+ /*----- inspectors ------------------------------------------------ */
/// returns true if the game connection can run a time frime
- inline bool running() const { return connection_running; }
+ inline bool running() const {
+ return connection_running;
+ }
/// returns true if the game connection can not run a time frime
- inline bool error() const { return !connection_running; }
+ inline bool error() const {
+ return !connection_running;
+ }
/// returns true if the game is running an interactive module
virtual bool interactive() const;
@@ -37,7 +41,7 @@ public:
/// return the current game time
virtual unsigned long timestamp() const;
-/*----- mutators -------------------------------------------------- */
+ /*----- mutators -------------------------------------------------- */
/// run a game connection time frame
void frame(unsigned long timestamp);
@@ -57,10 +61,12 @@ public:
/// returns an info record
Info *info(const std::string &label);
-/*----- static ---------------------------------------------------- */
-
+ /*----- static ---------------------------------------------------- */
+
/// return the current game connection
- static inline GameConnection *instance() { return connection_instance; }
+ static inline GameConnection *instance() {
+ return connection_instance;
+ }
protected:
/// abort runing
@@ -72,10 +78,13 @@ private:
unsigned long connection_netframe; // last network frame timestamp
NetConnection *connection_network;
- static GameConnection *connection_instance;
+ static GameConnection *connection_instance;
};
-inline GameConnection *connection() { return GameConnection::instance(); }
+inline GameConnection *connection()
+{
+ return GameConnection::instance();
+}
}
diff --git a/src/core/gameinterface.cc b/src/core/gameinterface.cc
index ce011dd..272c349 100644
--- a/src/core/gameinterface.cc
+++ b/src/core/gameinterface.cc
@@ -25,7 +25,7 @@ namespace core
void func_list_players(std::string const &args)
{
-
+
if (args.size()) {
Player *player = game()->find_player(args);
if (!player) {
@@ -44,22 +44,22 @@ const float MIN_DELTA = 10e-10;
Player GameInterface::game_localplayer;
EntityControlable *localcontrol()
-{
+{
if (game()->localplayer())
return game()->localplayer()->control();
else
return 0;
-
+
}
Player *localplayer()
-{
+{
return game()->localplayer();
}
GameInterface::GameInterface()
{
clear();
-
+
game_localplayer.clear();
if (Cvar::sv_dedicated->value()) {
game_localplayer.player_name.assign("Console");
@@ -107,7 +107,7 @@ void GameInterface::clear()
// remove all entities
for (Entity::Registry::iterator it = Entity::registry().begin(); it != Entity::registry().end(); it++) {
- delete (*it).second;
+ delete(*it).second;
}
Entity::registry().clear();
@@ -121,8 +121,8 @@ void GameInterface::clear()
// remove all game functions
for (Func::Registry::iterator it = Func::registry().begin(); it != Func::registry().end();) {
- if ( ((*it).second->flags() & Func::Game) == Func::Game) {
- delete (*it).second;
+ if (((*it).second->flags() & Func::Game) == Func::Game) {
+ delete(*it).second;
Func::registry().erase(it++);
} else {
++it;
@@ -130,9 +130,9 @@ void GameInterface::clear()
}
// remove all game cvars
- for (Cvar::Registry::iterator it = Cvar::registry().begin(); it != Cvar::registry().end(); ) {
- if ( ((*it).second->flags() & Cvar::Game) == Cvar::Game) {
- delete (*it).second;
+ for (Cvar::Registry::iterator it = Cvar::registry().begin(); it != Cvar::registry().end();) {
+ if (((*it).second->flags() & Cvar::Game) == Cvar::Game) {
+ delete(*it).second;
Cvar::registry().erase(it++);
} else {
++it;
@@ -194,10 +194,10 @@ void GameInterface::list_players()
for (Players::iterator it = game_players.begin(); it != game_players.end(); it++) {
const Player *player = (*it);
con_print << " "
- << aux::pad_left(player->name(), 24) << "^N "
- << "id^B" << setw(4) << player->id() << " "
- << "ping^B" << setw(4) << player->ping() << "^N "
- << "level^B" << setw(4) << player->level() << "^N";
+ << aux::pad_left(player->name(), 24) << "^N "
+ << "id^B" << setw(4) << player->id() << " "
+ << "ping^B" << setw(4) << player->ping() << "^N "
+ << "level^B" << setw(4) << player->level() << "^N";
if (player->zone())
con_print << aux::pad_left(player->zone()->name(), 24) << "^N";
diff --git a/src/core/gameinterface.h b/src/core/gameinterface.h
index dbb235e..44b4230 100644
--- a/src/core/gameinterface.h
+++ b/src/core/gameinterface.h
@@ -27,22 +27,28 @@ public:
/// type definition for the Players collection
typedef std::list<Player *> Players;
-/*----- inspectors ---------------------------------------------- */
+ /*----- inspectors ---------------------------------------------- */
/// return the local player
- inline Player *localplayer() { return &game_localplayer; }
+ inline Player *localplayer() {
+ return &game_localplayer;
+ }
- inline Players & players() { return game_players; }
+ inline Players & players() {
+ return game_players;
+ }
+
+ inline model::VertexArray *vertexarray() {
+ return game_vertexarray;
+ }
- inline model::VertexArray *vertexarray() { return game_vertexarray; }
-
/// find the first player who's id or name matches the search string
Player *find_player(const std::string &search);
-
+
/// show a list of connected players
void list_players();
-/*----- virtual inspectors --------------------------------------- */
+ /*----- virtual inspectors --------------------------------------- */
/// returns true if the game server can run a time frime
virtual bool running() const = 0;
@@ -59,14 +65,14 @@ public:
/// returns an info record
virtual Info *info(const std::string &label) = 0;
-/*----- mutators ------------------------------------------------- */
-
+ /*----- mutators ------------------------------------------------- */
+
/// clear all game variables, game functions and entities
void clear();
-/*----- virtual mutators ------------------------------------------ */
-
+ /*----- virtual mutators ------------------------------------------ */
+
/// run one game time frame
/// @param timestamp current application time
virtual void frame(unsigned long timestamp) = 0;
diff --git a/src/core/gameserver.cc b/src/core/gameserver.cc
index 096d8bf..e170a4d 100644
--- a/src/core/gameserver.cc
+++ b/src/core/gameserver.cc
@@ -39,15 +39,15 @@ void func_time(std::string const &args)
using namespace std;
int minutes = (int) floorf(server()->time() / 60.0f);
- int seconds = (int) floorf(server()->time() - (float) minutes* 60.0f);
+ int seconds = (int) floorf(server()->time() - (float) minutes * 60.0f);
int syshours = sys::time() / 3600;
int sysminutes = (sys::time() - syshours * 3600) / 60;
int sysseconds = sys::time() % 60;
- con_print <<
- "Uptime " << minutes << ":" << setfill('0') << setw(2) << seconds <<
- " Local time " << setfill(' ') << setw(2) << syshours << ":" << setfill('0') << setw(2) << sysminutes << ":" << setw(2) << sysseconds << setfill(' ') << std::endl;
+ con_print <<
+ "Uptime " << minutes << ":" << setfill('0') << setw(2) << seconds <<
+ " Local time " << setfill(' ') << setw(2) << syshours << ":" << setfill('0') << setw(2) << sysminutes << ":" << setw(2) << sysseconds << setfill(' ') << std::endl;
}
void func_mute(std::string const &args)
@@ -78,7 +78,7 @@ void func_unmute(std::string const &args)
}
targetplayer->player_mute = false;
- server()->broadcast("^B" +targetplayer->name() + "^B has been unmuted", targetplayer);
+ server()->broadcast("^B" + targetplayer->name() + "^B has been unmuted", targetplayer);
targetplayer->send("^WYou have been unmuted");
}
@@ -92,8 +92,8 @@ void func_kick(std::string const &args)
if (!(targetplayer = console_find_player(name)))
return;
std::string reason;
- if (args.size() > name.size()+1)
- reason.assign(args.substr(name.size()+1));
+ if (args.size() > name.size() + 1)
+ reason.assign(args.substr(name.size() + 1));
else
reason.assign("forcefully removed.");
@@ -105,7 +105,8 @@ void func_grant_rcon(std::string const &args)
{
Player *targetplayer = 0;
if (!(targetplayer = console_find_player(args)))
- return;}
+ return;
+}
void func_revoke_rcon(std::string const &args)
{
@@ -141,7 +142,7 @@ GameServer::GameServer() : GameInterface()
if (server_module->interactive()) {
//FIXME interferes with command line because of cmd.exec
- load_config();
+ load_config();
}
// set the name of the game
@@ -217,9 +218,9 @@ GameServer::~GameServer()
Func::remove("mute");
Func::remove("unmute");
-/* Func::remove("grant_rcon");
- Func::remove("revoke_rcon");
-*/
+ /* Func::remove("grant_rcon");
+ Func::remove("revoke_rcon");
+ */
Func::remove("time");
Func::remove("who");
@@ -233,7 +234,7 @@ unsigned long GameServer::timestamp() const
float GameServer::time() const
{
- return ((float)(server_timestamp) / 1000.0f);
+ return ((float)(server_timestamp) / 1000.0f);
}
Info *GameServer::info(const std::string &label)
@@ -250,7 +251,7 @@ bool GameServer::interactive() const
{
if (!server_module) {
return false;
- } else {
+ } else {
return server_module->interactive();
}
}
@@ -320,14 +321,14 @@ void GameServer::kick(Player *player, std::string const &reason)
}
// broadcast an "info" message to all players
-void GameServer::broadcast(const std::string text, Player *ignore_player)
+void GameServer::broadcast(const std::string text, Player *ignore_player)
{
broadcast(Message::Info, text, ignore_player);
}
// broadcast a message on a specified channel to all players
-void GameServer::broadcast(const Message::Channel channel, const std::string text, Player *ignore_player)
+void GameServer::broadcast(const Message::Channel channel, const std::string text, Player *ignore_player)
{
if (!text.size())
return;
@@ -370,10 +371,10 @@ void GameServer::exec(Player *player, std::string const & cmdline)
cmdstream >> command;
Func *function = Func::find(command);
- if (function ) {
+ if (function) {
std::string args;
- if (cmdline.size() > command.size() +1 )
- args.assign(cmdline.substr(command.size()+1));
+ if (cmdline.size() > command.size() + 1)
+ args.assign(cmdline.substr(command.size() + 1));
if ((function ->flags() & Func::Game) == Func::Game) {
if ((function ->flags() & Func::Target) == Func::Target) {
@@ -382,18 +383,18 @@ void GameServer::exec(Player *player, std::string const & cmdline)
Entity *entity = Entity::find(id);
if (entity)
function->exec(player, entity);
- }
+ }
} else {
function->exec(player, args);
}
} else if ((function->flags() & Func::Shared) == Func::Shared) {
-
+
// enable rcon buffering
console()->set_rcon(true);
function->exec(args);
- while(console()->rconbuf().size()) {
+ while (console()->rconbuf().size()) {
player->message(Message::RCon, (*console()->rconbuf().begin()));
console()->rconbuf().pop_front();
}
@@ -444,12 +445,12 @@ void GameServer::player_disconnect(Player *player)
server_module->player_disconnect(player);
// manage player list
- std::list<Player *>:: iterator it = game_players.begin();
+ std::list<Player *>:: iterator it = game_players.begin();
while (((*it)->id() != player->id()) && (it != game_players.end())) {
it++;
}
if (it != game_players.end()) {
- game_players.erase(it);
+ game_players.erase(it);
}
}
@@ -469,14 +470,14 @@ void GameServer::frame(unsigned long timestamp)
}
if (localplayer()->dirty())
- localplayer()->update_info();
+ localplayer()->update_info();
/*if (!Cvar::sv_dedicated->value()) {
update_clientstate();
}*/
if ((Cvar::sv_dedicated->value() || Cvar::sv_private->value())) {
- if (core::Cvar::sv_framerate->value()) {
+ if (core::Cvar::sv_framerate->value()) {
float f = 1000.0f / core::Cvar::sv_framerate->value();
if (server_startup + server_timestamp + f > timestamp) {
return;
@@ -486,15 +487,15 @@ void GameServer::frame(unsigned long timestamp)
server_previoustime = server_timestamp;
server_timestamp = timestamp - server_startup;
- float elapsed = (float) (server_timestamp - server_previoustime) / 1000.0f;
-
+ float elapsed = (float)(server_timestamp - server_previoustime) / 1000.0f;
+
// copy the previous entity state to the client state
/*if (!Cvar::sv_dedicated->value()) {
reset_clientstate();
}*/
// run a time frame on each entity
- for (Entity::Registry::iterator it=Entity::registry().begin(); it != Entity::registry().end(); it++) {
+ for (Entity::Registry::iterator it = Entity::registry().begin(); it != Entity::registry().end(); it++) {
Entity *entity = (*it).second;
if ((entity->type() == Entity::Controlable) || (entity->type() == Entity::Dynamic)) {
@@ -512,14 +513,14 @@ void GameServer::frame(unsigned long timestamp)
return;
}
}
-
+
if (server_network) {
// send network updates
server_network->frame(server_timestamp);
}
// mark all entities as updated
- for (Entity::Registry::iterator it=Entity::registry().begin(); it != Entity::registry().end(); ) {
+ for (Entity::Registry::iterator it = Entity::registry().begin(); it != Entity::registry().end();) {
Entity *entity = (*it).second;
if (entity->entity_destroyed) {
@@ -531,7 +532,7 @@ void GameServer::frame(unsigned long timestamp)
++it;
}
}
-
+
if (localplayer()->zonechange()) {
application()->notify_zonechange();
localplayer()->set_zonechange(false);
@@ -560,7 +561,7 @@ void GameServer::save_config()
ofs << std::endl;
for (Cvar::Registry::iterator it = Cvar::registry().begin(); it != Cvar::registry().end(); it++) {
- if ((((*it).second->flags() & Cvar::Archive) == Cvar::Archive) && (((*it).second->flags() & Cvar::Game) == Cvar::Game)){
+ if ((((*it).second->flags() & Cvar::Archive) == Cvar::Archive) && (((*it).second->flags() & Cvar::Game) == Cvar::Game)) {
ofs << "# " << (*it).first << " " << (*it).second->info() << std::endl;
ofs << "set " << (*it).first << " " << (*it).second->str() << std::endl;
ofs << std::endl;
@@ -583,11 +584,11 @@ void GameServer::load_config()
con_print << " reading configuration from " << filename << std::endl;
char line[MAXCMDSIZE];
- while (ifs.getline(line, MAXCMDSIZE-1)) {
+ while (ifs.getline(line, MAXCMDSIZE - 1)) {
if (line[0] && line[0] != '#' && line[0] != ';')
cmd() << line << '\n';
}
-
+
// execute commands in the buffer
CommandBuffer::exec();
}
diff --git a/src/core/gameserver.h b/src/core/gameserver.h
index a8d96db..57feac1 100644
--- a/src/core/gameserver.h
+++ b/src/core/gameserver.h
@@ -25,13 +25,17 @@ public:
GameServer();
virtual ~GameServer();
-/*----- inspectors ------------------------------------------------ */
+ /*----- inspectors ------------------------------------------------ */
/// returns true if the game server can run a time frime
- inline bool running() const { return server_running; }
+ inline bool running() const {
+ return server_running;
+ }
/// returns true if the game server can not run a time frime
- inline bool error() const { return !server_running; }
+ inline bool error() const {
+ return !server_running;
+ }
/// returns true if the game is running an interactive module
virtual bool interactive() const;
@@ -43,9 +47,11 @@ public:
virtual unsigned long timestamp() const;
/// current module
- inline const Module *module() const { return server_module; }
+ inline const Module *module() const {
+ return server_module;
+ }
-/*----- mutators -------------------------------------------------- */
+ /*----- mutators -------------------------------------------------- */
/// is called when a player connects to the game server
void player_connect(Player *player);
@@ -55,7 +61,7 @@ public:
/// run a game server time frame
void frame(unsigned long timestamp);
-
+
/// a player sends a chat message to the public channel
void say(Player *player, std::string const &args);
@@ -78,15 +84,19 @@ public:
void exec(Player *player, std::string const &cmdline);
/// time the server was started
- inline const unsigned long startup() const { return server_startup; }
+ inline const unsigned long startup() const {
+ return server_startup;
+ }
/// returns an info record
Info *info(const std::string &label);
-/*----- static ---------------------------------------------------- */
-
+ /*----- static ---------------------------------------------------- */
+
/// return the current game server
- static inline GameServer *instance() { return server_instance; }
+ static inline GameServer *instance() {
+ return server_instance;
+ }
protected:
/// abort runing
@@ -107,7 +117,10 @@ private:
unsigned long server_startup;
};
-inline GameServer *server() { return GameServer::instance(); }
+inline GameServer *server()
+{
+ return GameServer::instance();
+}
}
diff --git a/src/core/info.cc b/src/core/info.cc
index 93837c0..745bc3b 100644
--- a/src/core/info.cc
+++ b/src/core/info.cc
@@ -87,16 +87,16 @@ void Info::receive_server_update(std::istream &is)
char c;
// read name
- while ( (is.get(c)) && (c != '"'));
- while ( (is.get(c)) && (c != '"'))
- n += c;
+ while ((is.get(c)) && (c != '"'));
+ while ((is.get(c)) && (c != '"'))
+ n += c;
info_name.assign(n);
// read model name
n.clear();
- while ( (is.get(c)) && (c != '"'));
- while ( (is.get(c)) && (c != '"'))
- n += c;
+ while ((is.get(c)) && (c != '"'));
+ while ((is.get(c)) && (c != '"'))
+ n += c;
info_modelname.assign(n);
@@ -106,9 +106,9 @@ void Info::receive_server_update(std::istream &is)
is >> s;
for (size_t i = 0; (i < s) && is.good(); i++) {
n.clear();
- while ( (is.get(c)) && (c != '"'));
- while ( (is.get(c)) && (c != '"'))
- n += c;
+ while ((is.get(c)) && (c != '"'));
+ while ((is.get(c)) && (c != '"'))
+ n += c;
info_text.push_back(n);
}
@@ -124,7 +124,7 @@ Info::~Info()
void Info::print() const
{
con_print << "label: ^B" << label() << " ^Nname: ^B" << name() << " ^Nmodel: ^B" << modelname() << "^N" << std::endl;
-
+
for (Text::const_iterator it = info_text.begin(); it != info_text.end(); it++) {
con_print << " " << (*it) << std::endl;
}
diff --git a/src/core/info.h b/src/core/info.h
index 1bc62a9..8395954 100644
--- a/src/core/info.h
+++ b/src/core/info.h
@@ -31,15 +31,25 @@ public:
typedef std::deque<std::string> Text;
- inline const std::string & label() const { return info_label; }
+ inline const std::string & label() const {
+ return info_label;
+ }
- inline const std::string & name() const { return info_name; }
+ inline const std::string & name() const {
+ return info_name;
+ }
- inline const std::string & modelname() const { return info_modelname; }
+ inline const std::string & modelname() const {
+ return info_modelname;
+ }
- inline const unsigned long &timestamp() const { return info_timestamp; }
+ inline const unsigned long &timestamp() const {
+ return info_timestamp;
+ }
- inline Text & text() { return info_text; }
+ inline Text & text() {
+ return info_text;
+ }
void set_name(const std::string & name);
@@ -73,7 +83,7 @@ public:
/// receive a server-to-client update from a stream
void receive_server_update(std::istream &is);
-/* ---- static info registry --------------------------------------- */
+ /* ---- static info registry --------------------------------------- */
typedef std::map<std::string, Info*> Registry;
@@ -93,7 +103,9 @@ public:
static void list();
/// the info registry
- static inline Registry & registry() { return info_registry; }
+ static inline Registry & registry() {
+ return info_registry;
+ }
private:
std::string info_label;
diff --git a/src/core/item.cc b/src/core/item.cc
index 7b4633c..53da74d 100644
--- a/src/core/item.cc
+++ b/src/core/item.cc
@@ -33,7 +33,7 @@ void Item::find_class(const char *label)
void Item::clear()
{
for (Registry::iterator it = item_registry.begin(); it != item_registry.end(); it++) {
- delete (*it);
+ delete(*it);
}
item_registry.clear();
}
@@ -61,7 +61,7 @@ ItemClass::ItemClass(const char *label)
ItemClass::~ItemClass()
{
for (Types::iterator it = itemclass_types.begin(); it != itemclass_types.end(); it++) {
- delete (*it);
+ delete(*it);
}
}
diff --git a/src/core/item.h b/src/core/item.h
index 8299444..0845c21 100644
--- a/src/core/item.h
+++ b/src/core/item.h
@@ -10,7 +10,8 @@
#include <string>
#include <vector>
-namespace core {
+namespace core
+{
/**
* @brief a specific type of item in the game
@@ -21,11 +22,17 @@ class ItemType
public:
ItemType(const char *label);
- inline const std::string &label() { return itemtype_label; }
+ inline const std::string &label() {
+ return itemtype_label;
+ }
- inline const std::string &name() { return itemtype_name; }
+ inline const std::string &name() {
+ return itemtype_name;
+ }
- inline const float baseprice() { return itemtype_baseprice; }
+ inline const float baseprice() {
+ return itemtype_baseprice;
+ }
void set_name(const std::string &name);
@@ -51,9 +58,13 @@ public:
ItemClass(const char *label);
~ItemClass();
- inline const std::string &label() { return itemclass_label; }
+ inline const std::string &label() {
+ return itemclass_label;
+ }
- inline const std::string &name() { return itemclass_name; }
+ inline const std::string &name() {
+ return itemclass_name;
+ }
ItemType *find_type(const char *label);
diff --git a/src/core/loader.cc b/src/core/loader.cc
index 4070c2b..168b9bf 100644
--- a/src/core/loader.cc
+++ b/src/core/loader.cc
@@ -8,7 +8,8 @@
#include "core/loader.h"
#include "sys/sys.h"
-namespace core {
+namespace core
+{
Loader::Registry Loader::loader_registry;
std::string Loader::loader_label;
@@ -21,7 +22,7 @@ Loader::FactoryFuncPtr Loader::find(const char *label)
else
return (*it).second;
}
-
+
Loader::FactoryFuncPtr Loader::find(const std::string &label)
{
return (find(label.c_str()));
diff --git a/src/core/loader.h b/src/core/loader.h
index 1fde764..e9f7e0b 100644
--- a/src/core/loader.h
+++ b/src/core/loader.h
@@ -11,7 +11,8 @@
#include "core/module.h"
-namespace core {
+namespace core
+{
/// module factory registry
/** The Loader contains a list of module factories and can load
@@ -21,11 +22,11 @@ class Loader
{
public:
/// function pointer type for a module factory
- typedef Module * (* FactoryFuncPtr)();
+ typedef Module *(* FactoryFuncPtr)();
/// find a registered mmodule factory
static FactoryFuncPtr find(const char *label);
-
+
/// find a registered module factory
static FactoryFuncPtr find(const std::string &label);
@@ -38,7 +39,9 @@ public:
/// assign the next module to init
static bool load(const std::string &label);
- static inline const std::string &label() { return loader_label; }
+ static inline const std::string &label() {
+ return loader_label;
+ }
/// initialize a game module
static Module *init();
@@ -52,7 +55,7 @@ public:
private:
typedef std::map<std::string, FactoryFuncPtr> Registry;
- static Registry loader_registry;
+ static Registry loader_registry;
static std::string loader_label;
};
diff --git a/src/core/message.h b/src/core/message.h
index b9a9661..3c53439 100644
--- a/src/core/message.h
+++ b/src/core/message.h
@@ -10,11 +10,12 @@
namespace core
{
-class Message {
+class Message
+{
public:
/// indicates the type of message
- enum Channel {Info=0, Public=1, Local=2, Private=3, RCon=4};
+ enum Channel {Info = 0, Public = 1, Local = 2, Private = 3, RCon = 4};
};
}
diff --git a/src/core/module.cc b/src/core/module.cc
index 5dd07b5..6271331 100644
--- a/src/core/module.cc
+++ b/src/core/module.cc
@@ -14,7 +14,7 @@ namespace core
Module* Module::module_instance = 0;
Module::Module(const char *name, bool interactive) :
- module_name(name)
+ module_name(name)
{
module_running = true;
module_interactive = interactive;
diff --git a/src/core/module.h b/src/core/module.h
index 76b1ba4..ac6b380 100644
--- a/src/core/module.h
+++ b/src/core/module.h
@@ -17,26 +17,36 @@ namespace core
class Module
{
public:
- Module(const char *name, bool interactive=true);
+ Module(const char *name, bool interactive = true);
virtual ~Module();
-/*----- inspectors ------------------------------------------------ */
+ /*----- inspectors ------------------------------------------------ */
/// return true if the game module can run a timeframe
- inline bool running() const { return module_running; }
+ inline bool running() const {
+ return module_running;
+ }
/// return true if the game module can not run a timeframe
- inline bool error() const { return !module_running; }
+ inline bool error() const {
+ return !module_running;
+ }
/// label of the module
- inline std::string const & label() const { return module_label; }
+ inline std::string const & label() const {
+ return module_label;
+ }
/// return the name of the module
- inline std::string const & name() const { return module_name; }
+ inline std::string const & name() const {
+ return module_name;
+ }
/// indicates if this is an interactive module or not
- inline bool interactive() const { return module_interactive; }
+ inline bool interactive() const {
+ return module_interactive;
+ }
-/*----- mutators -------------------------------------------------- */
+ /*----- mutators -------------------------------------------------- */
/// run one game frame
virtual void frame(float seconds) = 0;
@@ -50,7 +60,9 @@ public:
/// set the module label
void set_label(const std::string &label);
- static inline Module *instance() { return module_instance; }
+ static inline Module *instance() {
+ return module_instance;
+ }
protected:
/// abort a running module
@@ -61,7 +73,7 @@ private:
bool module_running;
std::string module_label;
- std::string module_name;
+ std::string module_name;
static Module* module_instance;
};
diff --git a/src/core/netclient.cc b/src/core/netclient.cc
index 253cf4f..46694a6 100644
--- a/src/core/netclient.cc
+++ b/src/core/netclient.cc
@@ -46,10 +46,10 @@ NetClient::NetClient(std::string host, int port, int fd) :
abort();
return;
}
-
+
sendq.clear();
messageblock.clear();
-
+
client_keepalive = application()->time();
client_timeout = application()->time();
@@ -69,25 +69,27 @@ void NetClient::abort()
std::string NetClient::host() const
{
- return client_host;
+ return client_host;
}
int NetClient::port() const
{
- return client_port;
+ return client_port;
}
-Player *NetClient::player()
+Player *NetClient::player()
{
return client_player;
}
-bool NetClient::has_messages() const {
- return (recvq.size() > 0 );
+bool NetClient::has_messages() const
+{
+ return (recvq.size() > 0);
}
-void NetClient::retreive(std::string & message) {
- if (recvq.size() > 0 ) {
+void NetClient::retreive(std::string & message)
+{
+ if (recvq.size() > 0) {
message.assign(recvq.front());
recvq.pop_front();
} else {
@@ -101,9 +103,9 @@ void NetClient::receive(char *data)
const char *c = data;
while (*c) {
- if (( *c == '\n') || (*c == '\r')) {
- if (messageblock.size() > 0 ) {
- recvq.push_back(messageblock);
+ if ((*c == '\n') || (*c == '\r')) {
+ if (messageblock.size() > 0) {
+ recvq.push_back(messageblock);
messageblock.clear();
}
} else {
@@ -117,7 +119,7 @@ void NetClient::receive(char *data)
c++;
}
- client_timeout = application()->time();
+ client_timeout = application()->time();
}
void NetClient::send_raw(std::string const &msg)
@@ -125,7 +127,7 @@ void NetClient::send_raw(std::string const &msg)
if (error())
return;
- if ((sendq.size()) && (sendq.size() + msg.size() >= BLOCKSIZE - 16 )) {
+ if ((sendq.size()) && (sendq.size() + msg.size() >= BLOCKSIZE - 16)) {
transmit();
}
@@ -135,12 +137,12 @@ void NetClient::send_raw(std::string const &msg)
void NetClient::transmit()
{
if (!sendq.size()) {
- if (client_keepalive + NETTIMEOUT/2 < application()->time()) {
+ if (client_keepalive + NETTIMEOUT / 2 < application()->time()) {
sendq.assign("ping\n");
} else {
return;
}
- } else if (sendq.size() >= BLOCKSIZE - 16 ) {
+ } else if (sendq.size() >= BLOCKSIZE - 16) {
con_warn << host() << ":" << port() << " outgoing data exceeds " << BLOCKSIZE - 16 << " bytes!\n";
sendq.clear();
return;
@@ -152,17 +154,17 @@ void NetClient::transmit()
uLong uncompressed_size = (uLong) sendq.size();
size_t total_size = 0;
- memset(zbuf,0, sizeof(zbuf));
+ memset(zbuf, 0, sizeof(zbuf));
Stats::network_uncompressed_bytes_sent += sendq.size();
// zlib compress
- int status = compress((Bytef*)(zbuf+4), &compressed_size, (Bytef*)sendq.c_str(), uncompressed_size);
+ int status = compress((Bytef*)(zbuf + 4), &compressed_size, (Bytef*)sendq.c_str(), uncompressed_size);
if ((status == Z_OK) && (compressed_size + 4 < sendq.size())) {
// add a header to the compress packet
data = (char *) zbuf;
- total_size = (size_t) (compressed_size + 4);
+ total_size = (size_t)(compressed_size + 4);
zbuf[0] = '\xff';
zbuf[1] = '\xff';
zbuf[2] = compressed_size % 256;
@@ -171,12 +173,12 @@ void NetClient::transmit()
data = sendq.c_str();
total_size = sendq.size();
}
-
+
size_t total_sent = 0;
while (total_sent < total_size && !error()) {
ssize_t bytes_sent = ::sendto(fd(), data, total_size - total_sent, 0,
- (struct sockaddr *)&client_addr, sizeof(client_addr));
+ (struct sockaddr *) & client_addr, sizeof(client_addr));
if (bytes_sent < 0) {
abort();
diff --git a/src/core/netclient.h b/src/core/netclient.h
index c0cdf8d..818422e 100644
--- a/src/core/netclient.h
+++ b/src/core/netclient.h
@@ -43,14 +43,14 @@ namespace core
class NetClient
{
public:
- NetClient(std::string host, int port, int fd);
- ~NetClient();
+ NetClient(std::string host, int port, int fd);
+ ~NetClient();
- /// the remote hostname the client is connected to
- std::string host() const;
+ /// the remote hostname the client is connected to
+ std::string host() const;
- /// the remote port the client is connected to
- int port() const;
+ /// the remote port the client is connected to
+ int port() const;
/// the player info associated with this client
Player *player();
@@ -69,32 +69,38 @@ public:
/// transmit messages in the send queue to the remote client
void transmit();
-
- inline bool error() const { return client_error; }
+
+ inline bool error() const {
+ return client_error;
+ }
void abort();
- enum State {Connecting=0, Pending=1, Connected=2};
+ enum State {Connecting = 0, Pending = 1, Connected = 2};
+
+ inline State state() const {
+ return client_state;
+ }
- inline State state() const { return client_state; }
-
State client_state;
-
+
float client_timeout;
float client_keepalive;
private:
- inline int fd() const { return client_fd; }
+ inline int fd() const {
+ return client_fd;
+ }
struct sockaddr_in client_addr;
- std::string client_host;
- int client_port;
+ std::string client_host;
+ int client_port;
int client_fd;
bool client_error;
NetPlayer *client_player;
-
- std::string messageblock;
+
+ std::string messageblock;
std::deque<std::string> recvq;
std::string sendq;
};
diff --git a/src/core/netconnection.cc b/src/core/netconnection.cc
index 81f5b48..c37fe05 100644
--- a/src/core/netconnection.cc
+++ b/src/core/netconnection.cc
@@ -16,7 +16,7 @@
#include "core/player.h"
#include "core/stats.h"
-namespace core
+namespace core
{
NetConnection::NetConnection()
@@ -37,7 +37,7 @@ NetConnection::~NetConnection()
void NetConnection::abort()
{
- connection_error= true;
+ connection_error = true;
}
void NetConnection::connect(std::string const &to_host, int to_port)
@@ -48,7 +48,7 @@ void NetConnection::connect(std::string const &to_host, int to_port)
if (valid())
return;
-
+
// resolve serverhostname
struct hostent *serverhostent;
serverhostent = gethostbyname(to_host.c_str());
@@ -57,7 +57,7 @@ void NetConnection::connect(std::string const &to_host, int to_port)
abort();
return;
}
-
+
// Get a socket file descriptor
connection_fd = socket(PF_INET, SOCK_DGRAM, 0);
if (connection_fd == -1) {
@@ -65,7 +65,7 @@ void NetConnection::connect(std::string const &to_host, int to_port)
abort();
return;
}
-
+
// make the connection
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(to_port);
@@ -77,7 +77,7 @@ void NetConnection::connect(std::string const &to_host, int to_port)
abort();
return;
}
-
+
connection_host = to_host;
connection_port = to_port;
connection_error = false;
@@ -94,10 +94,10 @@ void NetConnection::connect(std::string const &to_host, int to_port)
connection_state = Pending;
game()->localplayer()->set_dirty();
- std::stringstream str;
- str << "Connecting to " << inet_ntoa(*((struct in_addr *)serverhostent->h_addr)) << ":" << to_port << "...";
- con_print << str.str() << std::endl;
- application()->notify_loader(str.str());
+ std::stringstream str;
+ str << "Connecting to " << inet_ntoa(*((struct in_addr *)serverhostent->h_addr)) << ":" << to_port << "...";
+ con_print << str.str() << std::endl;
+ application()->notify_loader(str.str());
}
void NetConnection::disconnect()
@@ -114,7 +114,7 @@ void NetConnection::disconnect()
close(connection_fd);
#endif
}
-
+
connection_fd = -1;
connection_error = false;
connection_host.clear();
@@ -145,9 +145,9 @@ void NetConnection::receive()
return;
ssize_t bytes_received;
-
+
memset(recvbuf, 0, BLOCKSIZE);
- bytes_received = ::recv(connection_fd, recvbuf, BLOCKSIZE-1, 0);
+ bytes_received = ::recv(connection_fd, recvbuf, BLOCKSIZE - 1, 0);
Stats::network_bytes_received += bytes_received;
connection_timeout = core::application()->time();
@@ -173,7 +173,7 @@ void NetConnection::receive()
// uncompress
char zunbuf[BLOCKSIZE*2];
memset(zunbuf, 0, sizeof(zunbuf));
- uLong zunbuf_size = (uLong) BLOCKSIZE*2 - 1;
+ uLong zunbuf_size = (uLong) BLOCKSIZE * 2 - 1;
int status = uncompress((Bytef *) zunbuf, &zunbuf_size, (Bytef *) zrecvbuf, (uLong) compressed_size);
@@ -182,7 +182,7 @@ void NetConnection::receive()
} else {
const char *zc = zunbuf;
while (*zc) {
- if (( *zc == '\n') || (*zc == '\r')) {
+ if ((*zc == '\n') || (*zc == '\r')) {
if (messageblock.size()) {
recvq.push_back(messageblock);
messageblock.clear();
@@ -204,22 +204,22 @@ void NetConnection::receive()
received_compressed_size = 0;
compressed_size = 0;
}
- } else if (!messageblock.size() && (bytes_received > 3 ) && ( *c == '\xff') && (*(c+1) == '\xff')) {
-
- receive_compressed = true;
- received_compressed_size = 0;
- compressed_size = (uLong) (*(unsigned char *)(c+2) + (*(unsigned char *)(c+3) << 8));
- c += 3;
- bytes_received -= 3;
- memset(zrecvbuf, 0, sizeof(zrecvbuf));
- if (compressed_size > BLOCKSIZE) {
- con_warn << "Incoming compressed datablock exceeds " << BLOCKSIZE << " bytes!\n";
- receive_compressed = false;
- }
+ } else if (!messageblock.size() && (bytes_received > 3) && (*c == '\xff') && (*(c + 1) == '\xff')) {
+
+ receive_compressed = true;
+ received_compressed_size = 0;
+ compressed_size = (uLong)(*(unsigned char *)(c + 2) + (*(unsigned char *)(c + 3) << 8));
+ c += 3;
+ bytes_received -= 3;
+ memset(zrecvbuf, 0, sizeof(zrecvbuf));
+ if (compressed_size > BLOCKSIZE) {
+ con_warn << "Incoming compressed datablock exceeds " << BLOCKSIZE << " bytes!\n";
+ receive_compressed = false;
+ }
- } else if (( *c == '\n') || (*c == '\r')) {
+ } else if ((*c == '\n') || (*c == '\r')) {
if (messageblock.size()) {
- recvq.push_back(messageblock);
+ recvq.push_back(messageblock);
messageblock.clear();
}
} else {
@@ -243,7 +243,7 @@ void NetConnection::frame()
timeout.tv_usec = 0;
fd_set readset = clientset;
- int nb = select(fd()+1, &readset, NULL, NULL, &timeout);
+ int nb = select(fd() + 1, &readset, NULL, NULL, &timeout);
if (nb == 0) {
if (connection_timeout + NETTIMEOUT < core::application()->time()) {
con_error << "Connection timeout!\n";
@@ -266,7 +266,7 @@ void NetConnection::frame()
parse_incoming_message(message);
}
- nb = select(fd()+1, &readset, NULL, NULL, &timeout);
+ nb = select(fd() + 1, &readset, NULL, NULL, &timeout);
if (nb == 0) {
return;
}
@@ -284,9 +284,9 @@ void NetConnection::transmit()
if (error() || invalid())
return;
-
+
if (!sendq.size()) {
- if (connection_keepalive + NETTIMEOUT /2 < application()->time()) {
+ if (connection_keepalive + NETTIMEOUT / 2 < application()->time()) {
sendq.assign("ping\n");
} else {
return;
@@ -296,18 +296,18 @@ void NetConnection::transmit()
sendq.clear();
return;
}
-
+
ssize_t bytes_sent = 0;
-
+
while (sendq.size()) {
- bytes_sent = ::sendto(connection_fd, sendq.c_str(), sendq.size(), 0, (struct sockaddr *)&server_addr, sizeof(server_addr));
+ bytes_sent = ::sendto(connection_fd, sendq.c_str(), sendq.size(), 0, (struct sockaddr *) & server_addr, sizeof(server_addr));
if (bytes_sent <= 0) {
con_error << "Network send() error!" << std::endl;
//perror("send");
abort();
return;
}
-
+
// assert (bytes_sent <= sendbuf.size());
sendq.erase(0, bytes_sent);
Stats::network_bytes_sent += bytes_sent;
@@ -334,7 +334,7 @@ void NetConnection::send_raw(std::string const &msg)
* priv <text>
*/
-// send a "connect" message to the server
+// send a "connect" message to the server
void NetConnection::send_connect()
{
std::ostringstream msg;
@@ -441,18 +441,18 @@ void NetConnection::send_info_request(Info *info)
void NetConnection::parse_incoming_message(const std::string & message)
{
std::istringstream msgstream(message);
-
+
std::string command;
msgstream >> command;
-
+
if (command == "msg") {
std::string level;
if (msgstream >> level) {
- if (level =="info") {
+ if (level == "info") {
if (message.size() > 9) {
application()->notify_message(Message::Info, message.substr(9));
}
- } else if (level =="rcon") {
+ } else if (level == "rcon") {
if (message.size() > 9) {
application()->notify_message(Message::RCon, message.substr(9));
}
@@ -465,7 +465,7 @@ void NetConnection::parse_incoming_message(const std::string & message)
// FIXME - separate sender nickname
if (message.size() > 12) {
application()->notify_message(Message::Private, message.substr(12));
- }
+ }
} else if (level == "snd") {
if (message.size() > 8) {
application()->notify_sound(message.substr(8).c_str());
@@ -503,7 +503,7 @@ void NetConnection::parse_incoming_message(const std::string & message)
if (msgstream >> id) {
//con_debug << "Received die entity id " << id << std::endl;
Entity *e = Entity::find(id);
- if (localcontrol() == e)
+ if (localcontrol() == e)
localplayer()->set_control(0);
if (e)
Entity::erase(id);
@@ -525,26 +525,25 @@ void NetConnection::parse_incoming_message(const std::string & message)
Entity *entity = Entity::find(id);
if (!entity) {
- switch (type)
- {
- case Entity::Default:
- entity = new Entity(msgstream);
- break;
- case Entity::Dynamic:
- entity = new EntityDynamic(msgstream);
- break;
- case Entity::Controlable:
- entity = new EntityControlable(msgstream);
- break;
- case Entity::Globe:
- entity = new EntityGlobe(msgstream);
- break;
- default:
- con_warn << "Received create for unknown entity type " << type << "!" << std::endl;
- return;
- break;
+ switch (type) {
+ case Entity::Default:
+ entity = new Entity(msgstream);
+ break;
+ case Entity::Dynamic:
+ entity = new EntityDynamic(msgstream);
+ break;
+ case Entity::Controlable:
+ entity = new EntityControlable(msgstream);
+ break;
+ case Entity::Globe:
+ entity = new EntityGlobe(msgstream);
+ break;
+ default:
+ con_warn << "Received create for unknown entity type " << type << "!" << std::endl;
+ return;
+ break;
}
-
+
Entity::add(entity, id);
}
@@ -560,7 +559,7 @@ void NetConnection::parse_incoming_message(const std::string & message)
con_warn << "Received menu for NULL entity!" << std::endl;
return;
}
-
+
Entity *entity = Entity::find(id);
if (!entity) {
con_warn << "Received menu for unknown entity " << id << "!" << std::endl;
@@ -591,7 +590,7 @@ void NetConnection::parse_incoming_message(const std::string & message)
if (id) {
//con_debug << "Received zone " << id << std::endl;
Zone * zone = Zone::find(id);
-
+
// create the zone if necessary
if (!zone) {
zone = new Zone(msgstream);
@@ -618,18 +617,18 @@ void NetConnection::parse_incoming_message(const std::string & message)
if (!player_id) {
Zone *oldzone = connection()->localplayer()->zone();
connection()->localplayer()->receive_server_update(msgstream);
-
+
//con_debug << "zone " << ( connection()->localplayer()->zone() ? connection()->localplayer()->zone()->id() : 0) << std::endl;
-
+
if (connection()->localplayer()->zonechange() && oldzone && (oldzone != connection()->localplayer()->zone())) {
-
+
// notify the applciation to clear none-core zone assets (textures etc)
application()->notify_zonechange();
-
+
// delete all entities in the old zone
- for (Entity::Registry::iterator it=Entity::registry().begin(); it != Entity::registry().end(); ) {
+ for (Entity::Registry::iterator it = Entity::registry().begin(); it != Entity::registry().end();) {
Entity *entity = (*it).second;
-
+
if ((entity->zone() == oldzone)) {
delete entity;
Entity::registry().erase(it++);
@@ -640,7 +639,7 @@ void NetConnection::parse_incoming_message(const std::string & message)
oldzone->content().clear();
}
- // short "pif" message about a different player
+ // short "pif" message about a different player
} else if (player_id != localplayer()->id()) {
// find player
@@ -648,7 +647,7 @@ void NetConnection::parse_incoming_message(const std::string & message)
// search other players
for (GameInterface::Players::iterator it = game()->players().begin(); it != game()->players().end() && !player; it++) {
- if( (*it)->id() == player_id) {
+ if ((*it)->id() == player_id) {
player = (*it);
}
}
@@ -664,7 +663,7 @@ void NetConnection::parse_incoming_message(const std::string & message)
} else if (command == "pid") {
con_debug << "Received player disconnect info" << std::endl;
-
+
int player_id;
if (!(msgstream >> player_id)) {
con_warn << "Received illegal player disconnect message!" << std::endl;
@@ -680,7 +679,7 @@ void NetConnection::parse_incoming_message(const std::string & message)
// search other players
Player *player = 0;
for (GameInterface::Players::iterator it = game()->players().begin(); it != game()->players().end() && !player; it++) {
- if( (*it)->id() == player_id) {
+ if ((*it)->id() == player_id) {
game()->players().erase(it);
return;
}
@@ -691,9 +690,9 @@ void NetConnection::parse_incoming_message(const std::string & message)
std::string label;
char c;
- while ( (msgstream.get(c)) && (c != '"'));
- while ( (msgstream.get(c)) && (c != '"'))
- label += c;
+ while ((msgstream.get(c)) && (c != '"'));
+ while ((msgstream.get(c)) && (c != '"'))
+ label += c;
if (label.size()) {
Info *info = Info::find(label);
@@ -708,8 +707,7 @@ void NetConnection::parse_incoming_message(const std::string & message)
con_warn << "Received empty information record!" << std::endl;
}
} else if (command == "sup") {
- if (connection_state == Connected)
- {
+ if (connection_state == Connected) {
unsigned int id;
if (msgstream >> id) {
//con_debug << "Received update entity id " << id << std::endl;
diff --git a/src/core/netconnection.h b/src/core/netconnection.h
index 7c0b23d..36cf154 100644
--- a/src/core/netconnection.h
+++ b/src/core/netconnection.h
@@ -41,10 +41,10 @@ class NetConnection
public:
NetConnection();
virtual ~NetConnection();
-
+
/// connect to a remote host
virtual void connect(std::string const &to_host, int to_port);
-
+
/// disconnect from a remote host
virtual void disconnect();
@@ -80,28 +80,46 @@ public:
void abort();
- inline int fd() const { return connection_fd; }
-
- inline std::string host() const { return connection_host; }
+ inline int fd() const {
+ return connection_fd;
+ }
+
+ inline std::string host() const {
+ return connection_host;
+ }
- inline int port() const { return connection_port; }
+ inline int port() const {
+ return connection_port;
+ }
- inline bool valid() const { return (connection_fd != -1); }
+ inline bool valid() const {
+ return (connection_fd != -1);
+ }
- inline bool invalid() const { return (connection_fd == -1); }
+ inline bool invalid() const {
+ return (connection_fd == -1);
+ }
- inline bool error() const { return connection_error; }
+ inline bool error() const {
+ return connection_error;
+ }
- inline bool connected() const { return ((connection_fd != -1) && !connection_error); }
+ inline bool connected() const {
+ return ((connection_fd != -1) && !connection_error);
+ }
- enum State {Connecting=0, Pending=1, Connected=2};
+ enum State {Connecting = 0, Pending = 1, Connected = 2};
+
+ inline State state() const {
+ return connection_state;
+ }
- inline State state() const { return connection_state; }
-
State connection_state;
/// return the current game time
- inline unsigned long timestamp() const { return connection_timestamp; }
+ inline unsigned long timestamp() const {
+ return connection_timestamp;
+ }
protected:
/// send a ping reply
@@ -121,13 +139,13 @@ protected:
/// parse an incoming message
void parse_incoming_message(const std::string & message);
-
+
private:
- std::string messageblock;
+ std::string messageblock;
std::deque<std::string> recvq;
std::string sendq;
fd_set clientset;
-
+
float connection_timeout;
float connection_keepalive;
int connection_fd;
diff --git a/src/core/netplayer.cc b/src/core/netplayer.cc
index 0b3455f..0935b4c 100644
--- a/src/core/netplayer.cc
+++ b/src/core/netplayer.cc
@@ -37,7 +37,7 @@ void NetPlayer::message(const Message::Channel channel, const std::string text)
return;
std::string msg_channel;
- switch(channel) {
+ switch (channel) {
case core::Message::Info: // Info message
msg_channel.assign("info");
break;
@@ -53,7 +53,7 @@ void NetPlayer::message(const Message::Channel channel, const std::string text)
case core::Message::Private: // Private chat message
msg_channel.assign("private");
break;
-
+
case core::Message::RCon: // RCon message
msg_channel.assign("rcon");
break;
@@ -63,7 +63,7 @@ void NetPlayer::message(const Message::Channel channel, const std::string text)
return;
break;
}
-
+
std::string msg("msg ");
msg.append(msg_channel);
msg += ' ';
diff --git a/src/core/netplayer.h b/src/core/netplayer.h
index 5659e2e..ada1bd0 100644
--- a/src/core/netplayer.h
+++ b/src/core/netplayer.h
@@ -22,10 +22,12 @@ namespace core
class NetPlayer : public Player
{
public:
- NetPlayer(NetClient *client);
- virtual ~NetPlayer();
+ NetPlayer(NetClient *client);
+ virtual ~NetPlayer();
- NetClient *client() { return player_client; }
+ NetClient *client() {
+ return player_client;
+ }
virtual void message(const Message::Channel channel, const std::string text);
virtual void sound(const std::string name);
diff --git a/src/core/netserver.cc b/src/core/netserver.cc
index 83bbd6e..1ae928b 100644
--- a/src/core/netserver.cc
+++ b/src/core/netserver.cc
@@ -34,7 +34,7 @@
#include "core/zone.h"
#ifdef _WIN32
- typedef int socklen_t;
+typedef int socklen_t;
#endif
namespace core
@@ -56,13 +56,13 @@ NetServer::NetServer(std::string const host, unsigned int const port)
return;
}
-
+
// Get the local adress to bind to
netserver_addr.sin_family = AF_INET;
netserver_addr.sin_port = htons(port);
if (host.size()) {
netserver_addr.sin_addr.s_addr = inet_addr(host.c_str());
- if ( netserver_addr.sin_addr.s_addr == INADDR_NONE) {
+ if (netserver_addr.sin_addr.s_addr == INADDR_NONE) {
con_error << "Network invalid address " << host << "!" << std::endl;
return;
}
@@ -70,14 +70,14 @@ NetServer::NetServer(std::string const host, unsigned int const port)
netserver_addr.sin_addr.s_addr = htonl(INADDR_ANY);
}
memset(netserver_addr.sin_zero, '\0', sizeof(netserver_addr.sin_zero));
-
+
// bind the local address to the socket ( note the typecast)
if (::bind(netserver_fd, (struct sockaddr *) &netserver_addr, sizeof(struct sockaddr)) == -1) {
con_error << "Network can't bind to local address!" << std::endl;
//perror("bind");
return;
}
-
+
con_print << " listening on " << inet_ntoa(netserver_addr.sin_addr) << ":" << ntohs(netserver_addr.sin_port) << std::endl;
// add the listening socket to the file descriptor set
@@ -101,13 +101,13 @@ NetServer::~NetServer()
for (it = clients.begin(); it != clients.end(); it++) {
// notify the game server
- if ((*it)->state() == NetClient::Connected)
+ if ((*it)->state() == NetClient::Connected)
server()->player_disconnect((*it)->player());
(*it)->send_raw(netmsg);
(*it)->transmit();
-
- delete (*it);
+
+ delete(*it);
}
clients.clear();
@@ -120,7 +120,8 @@ NetServer::~NetServer()
}
}
-void NetServer::abort() {
+void NetServer::abort()
+{
netserver_error = true;
}
@@ -138,8 +139,8 @@ NetClient *NetServer::find_client(Player const *player)
// remove disconnected clients
void NetServer::reap()
{
- for (Clients:: iterator it = clients.begin(); it != clients.end(); ) {
- NetClient *client = *it;
+ for (Clients:: iterator it = clients.begin(); it != clients.end();) {
+ NetClient *client = *it;
if (client->client_timeout + NETTIMEOUT < application()->time()) {
// client timed out, send a disconnect
@@ -157,8 +158,8 @@ void NetServer::reap()
}
}
- if (client->error()) {
-
+ if (client->error()) {
+
// notify other clients
for (Clients::iterator cit = clients.begin(); cit != clients.end(); cit++) {
if ((*cit) != (*it)) {
@@ -172,13 +173,13 @@ void NetServer::reap()
}
// remove the client
- delete client;
+ delete client;
clients.erase(it++);
- } else {
+ } else {
++it;
}
- }
+ }
}
void NetServer::receive()
@@ -191,7 +192,7 @@ void NetServer::receive()
timeout.tv_usec = 2500;
fd_set readset = serverset;
- int nb = select(fd()+1, &readset, NULL, NULL, &timeout);
+ int nb = select(fd() + 1, &readset, NULL, NULL, &timeout);
if (nb == -1) {
#ifndef _WIN32
// ncurses needs SIGWINCH catched
@@ -204,13 +205,13 @@ void NetServer::receive()
return;
}
- if (nb && FD_ISSET(fd(), &readset)) {
+ if (nb && FD_ISSET(fd(), &readset)) {
// receive incoming data
struct sockaddr_in client_addr;
socklen_t client_addr_len = sizeof(client_addr);
memset(recbuf, '\0', sizeof(recbuf));
- ssize_t bytes_received = ::recvfrom(fd(), recbuf, FRAMESIZE-1, 0, (struct sockaddr *)&client_addr, &client_addr_len);
+ ssize_t bytes_received = ::recvfrom(fd(), recbuf, FRAMESIZE - 1, 0, (struct sockaddr *) & client_addr, &client_addr_len);
if (bytes_received == -1) {
con_error << "Network error on recvfrom()!" << std::endl;
this->abort();
@@ -221,19 +222,19 @@ void NetServer::receive()
Stats::network_bytes_received += bytes_received;
// originator
- std::string client_host (inet_ntoa(client_addr.sin_addr));
+ std::string client_host(inet_ntoa(client_addr.sin_addr));
unsigned int client_port = ntohs(client_addr.sin_port);
-
+
// get messages from clients
bool msg_received = false;
for (Clients::iterator it = clients.begin(); it != clients.end() && !msg_received; it++) {
NetClient *client = *it;
-
+
if ((client->host() == client_host) && (client->port() == (int) client_port)) {
// receive data
client->receive(recbuf);
-
+
// process parsed messages
while (client->has_messages()) {
std::string message;
@@ -253,7 +254,7 @@ void NetServer::receive()
if (client) {
// receive data
client->receive(recbuf);
-
+
// process parsed messages
while (client->has_messages()) {
std::string message;
@@ -264,7 +265,7 @@ void NetServer::receive()
}
}
-
+
// remove dead connections
reap();
}
@@ -286,7 +287,8 @@ NetClient * NetServer::client_connect(std::string const host, int const port)
return client;
}
-void NetServer::client_initialize(NetClient *client) {
+void NetServer::client_initialize(NetClient *client)
+{
// send welcome message
std::string welcome("^B");
@@ -328,12 +330,12 @@ void NetServer::client_frame(NetClient *client, unsigned long timestamp)
// send zone info
send_zone_update(client, zone);
-
+
// send entities in zone
- if (client->player()->zone()) {
+ if (client->player()->zone()) {
for (Zone::Content::iterator it = zone->content().begin(); it != zone->content().end(); it++) {
Entity *entity = (*it);
-
+
if (!entity->entity_destroyed) {
send_entity_create(client, entity);
}
@@ -345,25 +347,25 @@ void NetServer::client_frame(NetClient *client, unsigned long timestamp)
} else {
// send a server frame marker
send_frame_marker(client, timestamp);
-
+
// send updates for entities in the zone
for (Entity::Registry::iterator it = Entity::registry().begin(); it != Entity::registry().end(); it++) {
Entity *entity = (*it).second;
- if (entity->zone() == zone) {
+ if (entity->zone() == zone) {
if (entity->entity_destroyed) {
if (!entity->entity_created) {
send_entity_delete(client, entity);
}
} else if (entity->entity_created) {
send_entity_create(client, entity);
-
+
} else if (entity->oldzone()) {
// this entity has entered the zone
send_entity_create(client, entity);
-
- } else if (entity->dirty() && !(entity->flags() & Entity::Static) ) {
-
+
+ } else if (entity->dirty() && !(entity->flags() & Entity::Static)) {
+
// FIXME only within visual range
send_entity_update(client, entity);
}
@@ -408,7 +410,7 @@ void NetServer::frame(unsigned long timestamp)
client->transmit();
}
-
+
// clear dirty state
for (Clients::iterator it = clients.begin(); it != clients.end(); it++) {
NetClient *client = *it;
@@ -468,7 +470,7 @@ void NetServer::send_frame_marker(NetClient *client, unsigned long timestamp)
if (client->state() == NetClient::Connected) {
client->send_raw(msg.str());
}
-
+
}
// send a "ent" create entity message to all clients
@@ -533,7 +535,7 @@ void NetServer::send_player_update(NetClient *client)
{
std::ostringstream msg;
msg << "pif 0 ";
- client->player()->serialize_server_update(msg);
+ client->player()->serialize_server_update(msg);
msg << '\n';
client->send_raw(msg.str());
}
@@ -543,7 +545,7 @@ void NetServer::send_player_update(NetClient *client, Player *player)
{
std::ostringstream msg;
msg << "pif " << player->id() << ' ';
- player->serialize_short_server_update(msg);
+ player->serialize_short_server_update(msg);
msg << '\n';
client->send_raw(msg.str());
}
@@ -579,18 +581,18 @@ void NetServer::send_info_update(NetClient *client, Info *info)
* ping
* say <text>
* priv <player> <text>
- *
+ *
*/
-void NetServer::parse_incoming_message(NetClient *client, const std::string & message)
+void NetServer::parse_incoming_message(NetClient *client, const std::string & message)
{
if (!message.size())
return;
std::stringstream msgstream(message);
-
+
std::string command;
msgstream >> command;
-
+
// disconnect
if (command == "disconnect") {
client->abort();
@@ -621,7 +623,7 @@ void NetServer::parse_incoming_message(NetClient *client, const std::string & me
} else {
std::string message("Unknown client protocol version!");
con_print << client->host() << ":" << client->port() << " " << message << std::endl;
-
+
send_message(client, "info", message);
send_disconnect(client);
}
@@ -662,8 +664,8 @@ void NetServer::parse_incoming_message(NetClient *client, const std::string & me
// cmd
if (command == "cmd") {
- if (message.size() > command.size()+1) {
- std::string cmdline(message.substr(command.size()+1));
+ if (message.size() > command.size() + 1) {
+ std::string cmdline(message.substr(command.size() + 1));
server()->exec(client->player(), cmdline);
}
return;
@@ -672,9 +674,9 @@ void NetServer::parse_incoming_message(NetClient *client, const std::string & me
if (command == "inf") {
std::string n;
char c;
-
- while ( (msgstream.get(c)) && (c != '"'));
- while ( (msgstream.get(c)) && (c != '"'))
+
+ while ((msgstream.get(c)) && (c != '"'));
+ while ((msgstream.get(c)) && (c != '"'))
n += c;
if (n.size()) {
@@ -687,21 +689,21 @@ void NetServer::parse_incoming_message(NetClient *client, const std::string & me
}
if (command == "rcon") {
- if ((message.size() > command.size()+1) && Cvar::sv_password->str().size()) {
+ if ((message.size() > command.size() + 1) && Cvar::sv_password->str().size()) {
if ((Cvar::sv_password->str().compare(client->player()->rconpassword()) == 0)) {
- con_print << "^B" << client->player()->name() << "^F rcon: " << message.substr(command.size()+1) << std::endl;
-
+ con_print << "^B" << client->player()->name() << "^F rcon: " << message.substr(command.size() + 1) << std::endl;
+
core::CommandBuffer::exec();
core::console()->set_rcon(true);
-
- core::cmd() << message.substr(command.size()+1) << "\n";
+
+ core::cmd() << message.substr(command.size() + 1) << "\n";
core::CommandBuffer::exec();
-
- while(console()->rconbuf().size()) {
+
+ while (console()->rconbuf().size()) {
send_message(client, "rcon", (*console()->rconbuf().begin()));
core::console()->rconbuf().pop_front();
}
-
+
// disable rcon buffering
console()->set_rcon(false);
@@ -711,7 +713,7 @@ void NetServer::parse_incoming_message(NetClient *client, const std::string & me
}
}
return;
-
+
}
// cup - client update entity
if (command == "cup") {
@@ -722,13 +724,13 @@ void NetServer::parse_incoming_message(NetClient *client, const std::string & me
if (!entity) {
con_warn << client->host() << ":" << client->port() << " update for unknown entity " << id << "\n";
return;
- }
+ }
if (entity->type() != Entity::Controlable) {
con_warn << client->host() << ":" << client->port() << " update for non-controlable entity " << id << "\n";
return;
}
-
+
EntityControlable *entitycontrolable = (EntityControlable *)entity;
if (entitycontrolable->owner() != client->player()) {
@@ -737,27 +739,27 @@ void NetServer::parse_incoming_message(NetClient *client, const std::string & me
}
entitycontrolable->set_dirty(true);
- entitycontrolable->receive_client_update(msgstream);
+ entitycontrolable->receive_client_update(msgstream);
}
return;
}
// say
- if (command == "say") {
- if (message.size() > command.size()+1) {
- server()->say(client->player(), message.substr(command.size()+1));
+ if (command == "say") {
+ if (message.size() > command.size() + 1) {
+ server()->say(client->player(), message.substr(command.size() + 1));
}
return;
}
// priv
if (command == "priv") {
- if (message.size() > command.size()+1) {
- server()->private_message(client->player(), message.substr(command.size()+1));
+ if (message.size() > command.size() + 1) {
+ server()->private_message(client->player(), message.substr(command.size() + 1));
}
return;
}
-
+
}
}
diff --git a/src/core/netserver.h b/src/core/netserver.h
index e54ea2e..afbb5a0 100644
--- a/src/core/netserver.h
+++ b/src/core/netserver.h
@@ -21,7 +21,7 @@
#include "core/player.h"
#include "core/info.h"
-namespace core
+namespace core
{
/// network server
@@ -32,26 +32,34 @@ public:
typedef std::list<NetClient *> Clients;
/// create a new network server, listening on host:port
- NetServer(std::string const host, unsigned int const port);
+ NetServer(std::string const host, unsigned int const port);
/// disconnect clients and shutdown the network server
- ~NetServer();
-
-/*----- inspectors ------------------------------------------------ */
+ ~NetServer();
+
+ /*----- inspectors ------------------------------------------------ */
/// Returns true if the TCP server has a valid file descriptor
- inline bool valid() const { return netserver_fd != -1; }
-
+ inline bool valid() const {
+ return netserver_fd != -1;
+ }
+
/// Returns true if the TCP server has an invalid file descriptor
- inline bool invalid() const { return netserver_fd == -1; }
-
+ inline bool invalid() const {
+ return netserver_fd == -1;
+ }
+
/// Returns the error state of the TCP server
- inline bool error() const { return netserver_error; }
+ inline bool error() const {
+ return netserver_error;
+ }
/// Return the socket file descriptor
- inline int fd() const { return netserver_fd; }
+ inline int fd() const {
+ return netserver_fd;
+ }
-/*----- mutators -------------------------------------------------- */
+ /*----- mutators -------------------------------------------------- */
/// run a network server frame
void frame(unsigned long timestamp);
@@ -74,7 +82,7 @@ protected:
/// send a create entity event
void send_entity_create(NetClient *client, Entity *entity);
-
+
/// broadcast a delete entity event
void send_entity_delete(NetClient *client, Entity *entity);
@@ -99,14 +107,14 @@ protected:
/// set the error state
void abort();
- /// called when a new client connects
- NetClient *client_connect(std::string const host, int const port);
+ /// called when a new client connects
+ NetClient *client_connect(std::string const host, int const port);
/// called when a client has send the intial handshake
void client_initialize(NetClient *client);
- /// remove terminated clients
- void reap();
+ /// remove terminated clients
+ void reap();
/// parse incoming client messages
void parse_incoming_message(NetClient *client, const std::string & message);
@@ -124,7 +132,7 @@ private:
char recbuf[FRAMESIZE];
- Clients clients;
+ Clients clients;
};
}
diff --git a/src/core/parser.cc b/src/core/parser.cc
index 84590a2..c5e0a38 100644
--- a/src/core/parser.cc
+++ b/src/core/parser.cc
@@ -8,7 +8,8 @@
#include "core/parser.h"
#include "sys/sys.h"
-namespace core {
+namespace core
+{
bool Parser::got_entity_key(filesystem::IniFile &inifile, core::Entity *entity)
diff --git a/src/core/parser.h b/src/core/parser.h
index 78a1087..06ddc27 100644
--- a/src/core/parser.h
+++ b/src/core/parser.h
@@ -11,10 +11,12 @@
#include "filesystem/inifile.h"
#include "core/entity.h"
-namespace core {
+namespace core
+{
/// general parser routines
-class Parser {
+class Parser
+{
public:
/// read default entity keys from an ini file
static bool got_entity_key(filesystem::IniFile &inifile, core::Entity *entity);
diff --git a/src/core/player.cc b/src/core/player.cc
index 4276f20..e048b91 100644
--- a/src/core/player.cc
+++ b/src/core/player.cc
@@ -56,7 +56,7 @@ void Player::print() const
if (zone()) {
con_print << " zone ^B" << zone()->name() << std::endl;
}
-
+
}
void Player::send(const std::string text)
@@ -91,7 +91,7 @@ void Player::set_control(EntityControlable *entitycontrolable)
player_dirty = true;
}
-void Player::set_zone(Zone *zone)
+void Player::set_zone(Zone *zone)
{
if (zone != player_zone) {
player_zone = zone;
@@ -131,7 +131,8 @@ void Player::set_ping(const long ping)
player_ping = ping;
}
-void Player::set_level(const int level) {
+void Player::set_level(const int level)
+{
player_level = level;
}
@@ -172,10 +173,10 @@ void Player::update_info()
void Player::serialize_client_update(std::ostream & os)
{
- os << player_color << " "
- << player_color_second << " "
- << "\"" << player_name << "\" "
- << "\"" << player_rconpassword << "\" ";
+ os << player_color << " "
+ << player_color_second << " "
+ << "\"" << player_name << "\" "
+ << "\"" << player_rconpassword << "\" ";
}
@@ -186,16 +187,16 @@ void Player::receive_client_update(std::istream &is)
std::string n;
char c;
- while ( (is.get(c)) && (c != '"'));
- while ( (is.get(c)) && (c != '"'))
+ while ((is.get(c)) && (c != '"'));
+ while ((is.get(c)) && (c != '"'))
n += c;
if (n.size())
player_name.assign(n);
-
+
n.clear();
- while ( (is.get(c)) && (c != '"'));
- while ( (is.get(c)) && (c != '"'))
+ while ((is.get(c)) && (c != '"'));
+ while ((is.get(c)) && (c != '"'))
n += c;
if (n.size())
@@ -209,14 +210,14 @@ void Player::serialize_server_update(std::ostream & os) const
unsigned int control_id = (player_control ? player_control->id() : 0);
unsigned int mission_id = (player_mission_target ? player_mission_target->id() : 0);
- os << player_id << " "
- << zone_id << " "
- << view_id << " "
- << control_id << " "
- << mission_id << " "
- << player_credits << " "
- << player_level << " "
- << player_ping;
+ os << player_id << " "
+ << zone_id << " "
+ << view_id << " "
+ << control_id << " "
+ << mission_id << " "
+ << player_credits << " "
+ << player_level << " "
+ << player_ping;
}
void Player::receive_server_update(std::istream &is)
@@ -240,21 +241,21 @@ void Player::receive_server_update(std::istream &is)
unsigned int control_id = 0;
is >> control_id;
- if (control_id) {
+ if (control_id) {
Entity *e = Entity::find(control_id);
if (e && e->type() == Entity::Controlable) {
player_control = static_cast<EntityControlable *>(e);
} else {
player_control = 0;
con_warn << "control set to unknown entity " << control_id << "\n";
- }
+ }
} else {
player_control = 0;
}
unsigned int mission_id = 0;
is >> mission_id;
- if (mission_id) {
+ if (mission_id) {
player_mission_target = Entity::find(mission_id);
if (!player_mission_target) {
con_warn << "mission target set to unknown entity " << mission_id << "\n";
@@ -266,7 +267,7 @@ void Player::receive_server_update(std::istream &is)
is >> player_credits;
is >> player_level;
is >> player_ping;
-
+
/*
std::string n;
char c;
@@ -283,13 +284,13 @@ void Player::serialize_short_server_update(std::ostream & os) const
{
unsigned int zone_id = (zone() ? zone()->id() : 0);
- os << player_id << " "
- << "\"" << player_name << "\" "
- << zone_id << " "
- << player_color << " "
- << player_color_second << " "
- << player_level << " "
- << player_ping;
+ os << player_id << " "
+ << "\"" << player_name << "\" "
+ << zone_id << " "
+ << player_color << " "
+ << player_color_second << " "
+ << player_level << " "
+ << player_ping;
}
@@ -308,8 +309,8 @@ void Player::receive_short_server_update(std::istream &is)
// read player name
std::string n;
char c;
- while ( (is.get(c)) && (c != '"'));
- while ( (is.get(c)) && (c != '"'))
+ while ((is.get(c)) && (c != '"'));
+ while ((is.get(c)) && (c != '"'))
n += c;
if (n.size())
@@ -361,7 +362,7 @@ void Player::remove_asset(unsigned int id)
return;
for (std::list<EntityControlable*>::iterator asset = assets.begin(); asset != assets.end(); asset++) {
- if ( ((*asset)->id() == id) && ((*asset)->owner() == this) ) {
+ if (((*asset)->id() == id) && ((*asset)->owner() == this)) {
//con_debug << " removing asset " << (*asset)->id() << " from player " << this->id() << std::endl;
if ((*asset) == player_control)
diff --git a/src/core/player.h b/src/core/player.h
index fc6740d..20a3b2d 100644
--- a/src/core/player.h
+++ b/src/core/player.h
@@ -32,68 +32,100 @@ public:
/// default destructor
virtual ~Player();
-/*----- inspectors ------------------------------------------------ */
+ /*----- inspectors ------------------------------------------------ */
/// id of the player
- inline const int id() const { return player_id; }
-
+ inline const int id() const {
+ return player_id;
+ }
+
/// name of the player
- inline const std::string & name() const { return player_name; }
+ inline const std::string & name() const {
+ return player_name;
+ }
/// dirty flag
- inline const bool dirty() const { return player_dirty; }
+ inline const bool dirty() const {
+ return player_dirty;
+ }
/// the entity the Player is currently controling
- inline EntityControlable *control() const { return player_control; }
+ inline EntityControlable *control() const {
+ return player_control;
+ }
/// the zone the player is currently in
- inline Zone *zone() const { return player_zone; }
+ inline Zone *zone() const {
+ return player_zone;
+ }
/// set the zone the player is currently in
void set_zone(Zone *zone);
- inline const bool zonechange() const { return player_zonechange; }
+ inline const bool zonechange() const {
+ return player_zonechange;
+ }
/// player primary color
- inline const math::Color & color() const { return player_color; }
+ inline const math::Color & color() const {
+ return player_color;
+ }
/// player secondary color
- inline const math::Color & color_second() const { return player_color_second; }
+ inline const math::Color & color_second() const {
+ return player_color_second;
+ }
/// player has been muted by admin or console
- inline const bool mute() const { return player_mute; }
+ inline const bool mute() const {
+ return player_mute;
+ }
- inline const std::string &rconpassword() const { return player_rconpassword; }
+ inline const std::string &rconpassword() const {
+ return player_rconpassword;
+ }
/// mission target
- inline Entity *mission_target() { return player_mission_target; }
+ inline Entity *mission_target() {
+ return player_mission_target;
+ }
/// view
- inline Entity *view() { return player_view; }
+ inline Entity *view() {
+ return player_view;
+ }
/// credits
- inline long credits() const { return player_credits; }
+ inline long credits() const {
+ return player_credits;
+ }
/// network ping
- inline long ping() const { return player_ping; }
+ inline long ping() const {
+ return player_ping;
+ }
/// returns true of the player has enough credits to pay amount
- inline bool has_credits(const long amount) const { return (player_credits >= amount); }
+ inline bool has_credits(const long amount) const {
+ return (player_credits >= amount);
+ }
/// print player info to console
virtual void print() const;
/// player level
- const int level() const { return player_level; }
+ const int level() const {
+ return player_level;
+ }
-/*----- messages -------------------------------------------------- */
+ /*----- messages -------------------------------------------------- */
/// send a text message
void send(const std::string text);
/**
* @brief send a warning message
- * Send the player a warning message abd set the warning
+ * Send the player a warning message abd set the warning
* message timestamp to the current application time
* @see last_warning()
*/
@@ -104,10 +136,12 @@ public:
virtual void message(core::Message::Channel channel, const std::string text);
/// time of the last warning message
- float last_warning() const { return player_warningtime; }
+ float last_warning() const {
+ return player_warningtime;
+ }
+
-
-/*----- mutators -------------------------------------------------- */
+ /*----- mutators -------------------------------------------------- */
/// serialize player info to a stream
void serialize_server_update(std::ostream & os) const;
@@ -176,12 +210,16 @@ public:
void set_level(const int level);
/// set the dirty bit
- inline void set_dirty(const bool dirty = true) { player_dirty = dirty; }
+ inline void set_dirty(const bool dirty = true) {
+ player_dirty = dirty;
+ }
/// set the zonechange bit
- inline void set_zonechange(const bool dirty = true) { player_zonechange = dirty; }
+ inline void set_zonechange(const bool dirty = true) {
+ player_zonechange = dirty;
+ }
-/* -- should actually not be public --*/
+ /* -- should actually not be public --*/
/// id of the player
int player_id;
diff --git a/src/core/range.h b/src/core/range.h
index d530f0b..a133695 100644
--- a/src/core/range.h
+++ b/src/core/range.h
@@ -7,22 +7,24 @@
#ifndef __INCLUDED_CORE_RANGE_H__
#define __INCLUDED_CORE_RANGE_H__
-namespace core {
+namespace core
+{
/**
* @brief range and scale constants
*/
-namespace range {
- /// maximal visible range (world distance)
- /** This is the distance of the frustum far plane,
- * the maximal distance at which entities can be drawn.
- * the maximal radar range
- * and the maximal range to send entity updates
- */
- const float maxdistance = 1024.0f;
+namespace range
+{
+/// maximal visible range (world distance)
+/** This is the distance of the frustum far plane,
+ * the maximal distance at which entities can be drawn.
+ * the maximal radar range
+ * and the maximal range to send entity updates
+ */
+const float maxdistance = 1024.0f;
- /// detail/fx distance (world distance)
- const float fxdistance = 256.0f;
+/// detail/fx distance (world distance)
+const float fxdistance = 256.0f;
}
}
diff --git a/src/core/stats.cc b/src/core/stats.cc
index 36e942f..f95c631 100644
--- a/src/core/stats.cc
+++ b/src/core/stats.cc
@@ -6,7 +6,8 @@
#include "core/stats.h"
-namespace core {
+namespace core
+{
unsigned long Stats::network_bytes_sent = 0;
unsigned long Stats::network_bytes_received = 0;
@@ -19,4 +20,4 @@ void Stats::clear()
};
}
-
+
diff --git a/src/core/stats.h b/src/core/stats.h
index 7bcad0d..db65f81 100644
--- a/src/core/stats.h
+++ b/src/core/stats.h
@@ -11,7 +11,8 @@ namespace core
{
/// class to gather various engine statistics
-class Stats {
+class Stats
+{
public:
/// clear statistics
static void clear();
diff --git a/src/core/timer.cc b/src/core/timer.cc
index b614af1..6f2e914 100644
--- a/src/core/timer.cc
+++ b/src/core/timer.cc
@@ -1,7 +1,7 @@
/*
core/timer.cc
- This file is part of the Osirion project and is distributed under
- the terms and conditions of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
*/
#include "core/timer.h"
@@ -10,12 +10,13 @@
#include <iostream>
#include <cmath>
-namespace core {
+namespace core
+{
Timer::Timer()
{
gettimeofday(&this->timer_tick, &this->timer_tz);
- this->timer_elapsed = 0;
+ this->timer_elapsed = 0;
}
Timer::~Timer()
@@ -28,12 +29,12 @@ void Timer::mark()
}
unsigned long Timer::timestamp()
-{
+{
struct timeval tick;
struct timezone tick_tz;
-
+
gettimeofday(&tick, &tick_tz);
-
+
// calculate elapsed time in 10^-6 seconds
unsigned long delta = 0;
delta = tick.tv_sec * 1000 + tick.tv_usec / 1000;
diff --git a/src/core/timer.h b/src/core/timer.h
index b878875..5157811 100644
--- a/src/core/timer.h
+++ b/src/core/timer.h
@@ -1,7 +1,7 @@
/*
core/timer.h
- This file is part of the Osirion project and is distributed under
- the terms and conditions of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
*/
#ifndef __INCLUDED_CORE_TIMER_H__
@@ -9,13 +9,15 @@
#include <sys/time.h>
-namespace core {
+namespace core
+{
/// a timer measures intervals in seconds
/*! A timer class measures the time elapsed
* between the last two calls to its mark() function.
*/
-class Timer {
+class Timer
+{
public:
/// Constructor
Timer();
@@ -25,7 +27,7 @@ public:
/// mark the current time as zero
/*! Reset the timer, all subsequent calls too elapsed() will
* use the current timestamp as reference
- */
+ */
void mark();
/*! return the time elapsed since the last mark, in seconds
diff --git a/src/core/zone.cc b/src/core/zone.cc
index 3567090..ac3bc4d 100644
--- a/src/core/zone.cc
+++ b/src/core/zone.cc
@@ -58,13 +58,13 @@ Zone *Zone::find(std::string const & name)
Zone *Zone::search(std::string const & searchname)
{
- std::string strsearchkey(aux::lowercase(searchname));
+ std::string strsearchkey(aux::lowercase(searchname));
std::stringstream str(strsearchkey);
unsigned int id;
if (str >> id)
return find(id);
-
+
if (strsearchkey.size() < 3) {
return 0;
}
@@ -79,7 +79,7 @@ Zone *Zone::search(std::string const & searchname)
if (label.size() && (label.find(strsearchkey) != std::string::npos)) {
return zone;
}
-
+
name.assign(aux::lowercase(zone->name()));
if (name.size() && (name.find(strsearchkey) != std::string::npos)) {
return zone;
@@ -101,7 +101,7 @@ void Zone::list()
void Zone ::clear()
{
for (Registry::iterator it = zone_registry.begin(); it != zone_registry.end(); it++) {
- delete (*it).second;
+ delete(*it).second;
}
zone_registry.clear();
@@ -109,7 +109,7 @@ void Zone ::clear()
/* ---- class Zone ------------------------------------------------- */
Zone::Zone(std::string const & label) :
- zone_label(label)
+ zone_label(label)
{
zone_id = 0;
zone_name.clear();
@@ -139,10 +139,10 @@ void Zone::print()
for (Content::iterator it = zone_content.begin(); it != zone_content.end(); it++) {
Entity *entity = (*it);
con_print << " id " << std::setw(4) << entity->id()
- << " type " << std::setw(4) << entity->type()
- << ":" << std::setw(4) << entity->moduletype()
- << " " << std::setw(24) << entity->label()
- << " ^B" << entity->name() << "^N" << std::endl;
+ << " type " << std::setw(4) << entity->type()
+ << ":" << std::setw(4) << entity->moduletype()
+ << " " << std::setw(24) << entity->label()
+ << " ^B" << entity->name() << "^N" << std::endl;
}
con_print << zone_content.size() << " registered zone entities" << std::endl;
}
@@ -197,7 +197,7 @@ Entity *Zone::find_entity(const std::string & label)
Entity *Zone::search_entity(const std::string & searchname)
{
- std::string strsearchkey(aux::lowercase(searchname));
+ std::string strsearchkey(aux::lowercase(searchname));
std::stringstream str(strsearchkey);
unsigned int id;
@@ -218,7 +218,7 @@ Entity *Zone::search_entity(const std::string & searchname)
if (label.size() && (label.find(strsearchkey) != std::string::npos)) {
return entity;
}
-
+
name.assign(aux::lowercase(entity->name()));
if (name.size() && (name.find(strsearchkey) != std::string::npos)) {
return entity;
@@ -233,27 +233,27 @@ void Zone::serialize_server_update(std::ostream & os) const
os << zone_label << " ";
os << "\"" << zone_name << "\" ";
os << "\"" << zone_sky << "\" ";
- os << (zone_defaultview ? zone_defaultview->id() : 0 );
+ os << (zone_defaultview ? zone_defaultview->id() : 0);
}
void Zone::receive_server_update(std::istream &is)
{
is >> zone_label;
-
+
std::string n;
unsigned int id = 0;
char c;
- while ( (is.get(c)) && (c != '"'));
- while ( (is.get(c)) && (c != '"'))
- n += c;
+ while ((is.get(c)) && (c != '"'));
+ while ((is.get(c)) && (c != '"'))
+ n += c;
zone_name.assign(n);
n.clear();
- while ( (is.get(c)) && (c != '"'));
- while ( (is.get(c)) && (c != '"'))
- n += c;
+ while ((is.get(c)) && (c != '"'));
+ while ((is.get(c)) && (c != '"'))
+ n += c;
zone_sky.assign(n);
n.clear();
diff --git a/src/core/zone.h b/src/core/zone.h
index 32463df..6048a99 100644
--- a/src/core/zone.h
+++ b/src/core/zone.h
@@ -11,7 +11,8 @@
#include <list>
#include <map>
-namespace core {
+namespace core
+{
class Zone;
@@ -23,7 +24,8 @@ namespace core
{
/// a Zone contains a compartment of the game universe
-class Zone {
+class Zone
+{
public:
/// type definition for the content of a zone
typedef std::list<Entity *> Content;
@@ -58,8 +60,10 @@ public:
static void clear();
/// the zone registry
- static inline Registry & registry() { return zone_registry; }
-
+ static inline Registry & registry() {
+ return zone_registry;
+ }
+
/* ---- Zone class ----------------------------------------- */
/// create a new zone
@@ -77,22 +81,34 @@ public:
void print();
/// zone id
- inline unsigned int id() const { return zone_id; }
+ inline unsigned int id() const {
+ return zone_id;
+ }
/// zone label
- inline std::string const & label() const { return zone_label; }
+ inline std::string const & label() const {
+ return zone_label;
+ }
/// zone name
- inline std::string const & name() const { return zone_name; }
+ inline std::string const & name() const {
+ return zone_name;
+ }
/// the name of the texture to be used as sky for this zone
- inline std::string const & sky() const { return zone_sky; }
+ inline std::string const & sky() const {
+ return zone_sky;
+ }
/// texture id for the sky
- inline size_t sky_texture() const { return zone_sky_texture; }
+ inline size_t sky_texture() const {
+ return zone_sky_texture;
+ }
/// default zone view
- inline Entity *default_view() {return zone_defaultview; }
+ inline Entity *default_view() {
+ return zone_defaultview;
+ }
/// find an entity inside a zone
Entity *find_entity(Entity *entity);
@@ -109,19 +125,29 @@ public:
/* ---- mutators ------------------------------------------- */
/// set the Zone label
- inline void set_label(std::string const & label) { zone_label.assign(label); }
+ inline void set_label(std::string const & label) {
+ zone_label.assign(label);
+ }
/// set the Zone label
- inline void set_name(std::string const & name) { zone_name.assign(name); }
+ inline void set_name(std::string const & name) {
+ zone_name.assign(name);
+ }
/// set the sky texture name to be used for this zone
- inline void set_sky(std::string const & sky) { zone_sky.assign(sky); }
+ inline void set_sky(std::string const & sky) {
+ zone_sky.assign(sky);
+ }
/// set the texture id for the sky
- inline void set_sky_texture(size_t texture) { zone_sky_texture = texture; }
+ inline void set_sky_texture(size_t texture) {
+ zone_sky_texture = texture;
+ }
///set the default view
- inline void set_default_view(Entity *entity) { zone_defaultview = entity; }
+ inline void set_default_view(Entity *entity) {
+ zone_defaultview = entity;
+ }
/* ---- serializers ---------------------------------------- */
@@ -134,7 +160,9 @@ public:
/* ---- zone content --------------------------------------- */
/// the entities belonging to this zone
- inline Content & content() { return zone_content; }
+ inline Content & content() {
+ return zone_content;
+ }
/// add an entity to this zone
void add(Entity *entity);
diff --git a/src/dedicated/console.cc b/src/dedicated/console.cc
index 5b7d92f..2c4c0da 100644
--- a/src/dedicated/console.cc
+++ b/src/dedicated/console.cc
@@ -22,7 +22,8 @@
#include <curses.h>
#endif
-namespace dedicated {
+namespace dedicated
+{
bool console_initialized = false;
bool console_updated = false;
@@ -43,19 +44,19 @@ Console *console()
void Console::init()
{
#ifdef HAVE_CURSES
- stdwin = initscr(); // initialize the ncurses window
- cbreak(); // disable input line buffering
- noecho(); // don't show typed characters
- keypad(stdwin, TRUE); // enable special keys
- nodelay(stdwin, TRUE); // non-blocking input
- curs_set(1); // enable cursor
+ stdwin = initscr(); // initialize the ncurses window
+ cbreak(); // disable input line buffering
+ noecho(); // don't show typed characters
+ keypad(stdwin, TRUE); // enable special keys
+ nodelay(stdwin, TRUE); // non-blocking input
+ curs_set(1); // enable cursor
if (has_colors() == TRUE) {
start_color();
// this is ncurses-specific
use_default_colors();
// COLOR_PAIR(0) is terminal default
- init_pair(1, COLOR_RED, -1);
+ init_pair(1, COLOR_RED, -1);
init_pair(2, COLOR_GREEN, -1);
init_pair(3, COLOR_YELLOW, -1);
init_pair(4, COLOR_BLUE, -1);
@@ -69,10 +70,10 @@ void Console::init()
con_print << "^BInitializing console..." << std::endl;
#ifdef HAVE_CURSES
- server_console.history.clear();
- server_console.history.push_back("");
- server_console.history_pos = server_console.history.rbegin();
- server_console.input_pos = 0;
+ server_console.history.clear();
+ server_console.history.push_back("");
+ server_console.history_pos = server_console.history.rbegin();
+ server_console.input_pos = 0;
server_console.console_scroll = 0;
server_console.draw();
#endif // HAVE_CURSES
@@ -105,7 +106,7 @@ Console::~Console()
#ifdef HAVE_CURSES
void Console::dump()
{
- // dump console content
+ // dump console content
for (Queue::iterator it = log().begin(); it != log().end(); it++) {
sys::ConsoleInterface::print((*it));
}
@@ -115,11 +116,11 @@ void Console::resize()
{
if (!console_initialized)
return;
-
+
endwin();
refresh();
- draw();
+ draw();
}
void Console::print(const std::string & text)
@@ -142,7 +143,7 @@ void Console::set_color(const char *color_code)
// base colors
// Default=0, Red=1, Green=2, Yellow=3, Blue=4, Cyan=5, Magenta=6, White=7
- color = *(color_code+1) - '0';
+ color = *(color_code + 1) - '0';
if (color == 3 || color == 7)
bold = true;
else
@@ -150,7 +151,7 @@ void Console::set_color(const char *color_code)
} else if (aux::is_core_color_code(color_code)) {
- switch (*(color_code+1)) {
+ switch (*(color_code + 1)) {
case 'N': // normal color
case 'D': // debug color
color = 0;
@@ -206,7 +207,7 @@ void Console::draw_status()
attroff(A_BOLD);
color_set(2, NULL);
int minutes = (int) floorf(core::game()->time() / 60.0f);
- int seconds = (int) floorf( core::game()->time() - (float) minutes* 60.0f);
+ int seconds = (int) floorf(core::game()->time() - (float) minutes * 60.0f);
std::stringstream status;
status << "time " << std::setfill(' ') << std::setw(3) << minutes << ":" << std::setfill('0') << std::setw(2) << seconds;
mvaddnstr(0, 1, status.str().c_str(), status.str().size());
@@ -249,8 +250,8 @@ void Console::draw_text()
}
// new word, wrap if necessary
- else if ((*c == '\n' ) || ( *c == ' ')) {
-
+ else if ((*c == '\n') || (*c == ' ')) {
+
if (line_length + word_length > console_width) {
if (line.size()) {
lines.push_back(line);
@@ -260,31 +261,31 @@ void Console::draw_text()
line_length = 0;
}
}
-
+
line.append(word);
line_length += word_length;
word.clear();
word_length = 0;
wordpen = pen;
-
+
// new line
- if (*c == '\n' ) {
+ if (*c == '\n') {
lines.push_back(line);
line.clear();
line_length = 0;
- // new word
- } else if (*c == ' ' ) {
+ // new word
+ } else if (*c == ' ') {
line += ' ';
line_length++;
}
}
// new character
- else {
+ else {
word += *c;
word_length++;
-
+
if (word_length == console_width) {
if (line.size()) {
lines.push_back(line);
@@ -305,9 +306,9 @@ void Console::draw_text()
c++;
}
-
+
}
- current_line++;
+ current_line++;
}
int y = console_height - 1;
@@ -339,20 +340,20 @@ void Console::draw_input()
attron(A_BOLD);
// draw input text
mvaddstr(console_height, 0, ">");
- mvaddstr(console_height, 1, (*history_pos).c_str());
+ mvaddstr(console_height, 1, (*history_pos).c_str());
// fill the remainder with spaces
- for (int i=1 + (*history_pos).size(); i < console_width; i++)
+ for (int i = 1 + (*history_pos).size(); i < console_width; i++)
addch(' ');
}
-void Console::draw()
+void Console::draw()
{
- if (!console_initialized)
+ if (!console_initialized)
return;
#ifdef _WIN32
- console_width = stdwin->_maxx -1;
- console_height = stdwin->_maxy -1;
+ console_width = stdwin->_maxx - 1;
+ console_height = stdwin->_maxy - 1;
#else
console_width = stdwin->_maxx;
console_height = stdwin->_maxy;
@@ -381,13 +382,13 @@ void Console::frame()
while (key != ERR) {
if (key == KEY_BACKSPACE || key == 8 || key == 127) {
if ((*history_pos).size() && input_pos) {
- (*history_pos).erase(input_pos-1, 1);
+ (*history_pos).erase(input_pos - 1, 1);
input_pos--;
input_updated = true;
}
break;
- } else if (key == KEY_STAB || key ==9) {
- core::CommandBuffer::complete( (*history_pos), input_pos);
+ } else if (key == KEY_STAB || key == 9) {
+ core::CommandBuffer::complete((*history_pos), input_pos);
input_updated = true;
break;
} else if (key == KEY_LEFT) {
@@ -396,7 +397,7 @@ void Console::frame()
}
input_updated = true;
break;
- } else if (key == KEY_RIGHT) {
+ } else if (key == KEY_RIGHT) {
if (input_pos < (*history_pos).size()) {
input_pos++;
}
@@ -425,38 +426,38 @@ void Console::frame()
input_pos = (*history_pos).size();
input_updated = true;
}
- break;
- } else if (key == KEY_ENTER || key == '\n') {
+ break;
+ } else if (key == KEY_ENTER || key == '\n') {
if ((*history_pos).size()) {
// store input into history
while (history.size() >= MAXHISTOLINES) {
history.pop_front();
}
-
+
core::cmd() << (*history_pos) << std::endl;
con_print << "^B>" << (*history_pos) << std::endl;
(*history.rbegin()) = (*history_pos);
-
+
history.push_back("");
history_pos = history.rbegin();
input_pos = 0;
console_updated = true;
}
break;
- } else if (key == KEY_PPAGE) {
- console_scroll += scroll_offset;
- if (console_scroll > log().size())
+ } else if (key == KEY_PPAGE) {
+ console_scroll += scroll_offset;
+ if (console_scroll > log().size())
console_scroll = log().size();
console_updated = true;
- break;
- } else if (key == KEY_NPAGE) {
- if (console_scroll > scroll_offset)
+ break;
+ } else if (key == KEY_NPAGE) {
+ if (console_scroll > scroll_offset)
console_scroll -= scroll_offset;
- else
+ else
console_scroll = 0;
console_updated = true;
- break;
- } else if ((key >= 32) && (key < 127) && ((*history_pos).size() < MAXCMDSIZE)) {
+ break;
+ } else if ((key >= 32) && (key < 127) && ((*history_pos).size() < MAXCMDSIZE)) {
if (input_pos == (*history_pos).size()) {
(*history_pos) += (char)key;
} else {
@@ -464,7 +465,7 @@ void Console::frame()
}
input_pos++;
input_updated = true;
- }
+ }
key = wgetch(stdwin);
}
diff --git a/src/dedicated/console.h b/src/dedicated/console.h
index 19ea906..b0bafdb 100644
--- a/src/dedicated/console.h
+++ b/src/dedicated/console.h
@@ -1,7 +1,7 @@
/*
dedicated/console.h
- This file is part of the Osirion project and is distributed under
- the terms of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
*/
#ifndef __INCLUDED_DEDICATED_CONSOLE_H__
@@ -9,9 +9,11 @@
#include "sys/consoleinterface.h"
-namespace dedicated {
+namespace dedicated
+{
-class Console : public sys::ConsoleInterface {
+class Console : public sys::ConsoleInterface
+{
public:
Console();
~Console();
@@ -48,12 +50,12 @@ private:
/// set ncurses drawing color
void set_color(const char *color_code);
-
- // input history
- History history;
- History::reverse_iterator history_pos;
- size_t input_pos;
+ // input history
+ History history;
+ History::reverse_iterator history_pos;
+
+ size_t input_pos;
size_t console_scroll;
int console_width;
diff --git a/src/dedicated/dedicated.cc b/src/dedicated/dedicated.cc
index 43c636e..6812d63 100644
--- a/src/dedicated/dedicated.cc
+++ b/src/dedicated/dedicated.cc
@@ -1,7 +1,7 @@
/*
dedicated/dedicated.cc
- This file is part of the Osirion project and is distributed under
- the terms and conditions of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
*/
#include <iostream>
@@ -14,13 +14,14 @@
#include "dedicated/console.h"
#include "dedicated/dedicated.h"
-namespace dedicated {
+namespace dedicated
+{
void run(int count, char **arguments)
{
std::cout << core::name() << " " << core::version() << std::endl;
- for (int i =0; i < count; i++)
+ for (int i = 0; i < count; i++)
std::cout << arguments[i] << " ";
std::cout << std::endl;
@@ -38,7 +39,7 @@ void Dedicated::init(int count, char **arguments)
core::Cvar::set("sv_dedicated", "1", core::Cvar::ReadOnly);
- core::Application::init(count, arguments);
+ core::Application::init(count, arguments);
Console::init();
@@ -59,7 +60,7 @@ void Dedicated::run()
core::Timer timer;
timer.mark();
- while(connected()) {
+ while (connected()) {
frame(timer.timestamp());
#ifdef HAVE_CURSES
console()->frame();
@@ -67,28 +68,28 @@ void Dedicated::run()
}
}
-void Dedicated::shutdown()
+void Dedicated::shutdown()
{
con_print << "^BShutting down dedicated server..." << std::endl;
float ratio = 0;
if (core::Stats::network_uncompressed_bytes_sent > 0)
ratio = 100.0f - floorf((float)core::Stats::network_bytes_sent /
- (float) core::Stats::network_uncompressed_bytes_sent * 100.0f);
+ (float) core::Stats::network_uncompressed_bytes_sent * 100.0f);
int minutes = (int) floorf(time() / 60.0f);
- int seconds = (int) floorf(time() - (float) minutes* 60.0f);
-
+ int seconds = (int) floorf(time() - (float) minutes * 60.0f);
+
con_debug << "Statistics:" << std::endl;
con_debug << " uptime " << std::setfill(' ') << std::setw(3) << minutes << ":" << std::setfill('0') << std::setw(2) << seconds << std::endl;
con_debug << " bytes sent " << std::setfill(' ') << std::setw(6) << core::Stats::network_bytes_sent / 1024 << " Kb" << std::endl;
con_debug << " bytes received " << std::setw(6) << core::Stats::network_bytes_received / 1024 << " Kb" << std::endl;
con_debug << " compression " << std::setw(6) << ratio << " %" << std::endl;
-
+
core::Application::shutdown();
Console::shutdown();
-
+
quit(0);
}
diff --git a/src/dedicated/dedicated.h b/src/dedicated/dedicated.h
index f458895..d90b3b6 100644
--- a/src/dedicated/dedicated.h
+++ b/src/dedicated/dedicated.h
@@ -1,7 +1,7 @@
/*
dedicated/dedicated.h
- This file is part of the Osirion project and is distributed under
- the terms and conditions of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
*/
#ifndef __INCLUDED_DEDICATED_H__
@@ -10,13 +10,15 @@
#include "core/application.h"
/// contains classes and functions to run the dedicated server
-namespace dedicated {
+namespace dedicated
+{
/// run the dedicated server
void run(int count, char **arguments);
-
+
/// server application implementation
-class Dedicated : public core::Application {
+class Dedicated : public core::Application
+{
public:
/// initialize the server Application
virtual void init(int count, char **arguments);
diff --git a/src/filesystem/diskfile.cc b/src/filesystem/diskfile.cc
index 6def055..bab20d9 100644
--- a/src/filesystem/diskfile.cc
+++ b/src/filesystem/diskfile.cc
@@ -5,9 +5,10 @@
*/
#include "filesystem/filesystem.h"
-#include "filesystem/diskfile.h"
+#include "filesystem/diskfile.h"
-namespace filesystem {
+namespace filesystem
+{
DiskFile::DiskFile()
{
@@ -25,7 +26,7 @@ FILE *DiskFile::handle()
return diskfile_handle;
}
-bool DiskFile::open(const char *filename)
+bool DiskFile::open(const char *filename)
{
if (diskfile_handle) {
con_warn << file_name << " already open!" << std::endl;
diff --git a/src/filesystem/diskfile.h b/src/filesystem/diskfile.h
index 7da1a88..6a64ce5 100644
--- a/src/filesystem/diskfile.h
+++ b/src/filesystem/diskfile.h
@@ -14,7 +14,7 @@
#include <string>
-namespace filesystem
+namespace filesystem
{
/**
diff --git a/src/filesystem/file.cc b/src/filesystem/file.cc
index 91ac9f9..628ba22 100644
--- a/src/filesystem/file.cc
+++ b/src/filesystem/file.cc
@@ -7,7 +7,8 @@
// project headers
#include "filesystem/file.h"
-namespace filesystem {
+namespace filesystem
+{
File::File() {}
diff --git a/src/filesystem/file.h b/src/filesystem/file.h
index daef174..a5daf34 100644
--- a/src/filesystem/file.h
+++ b/src/filesystem/file.h
@@ -10,7 +10,8 @@
// C++ headers
#include <string>
-namespace filesystem {
+namespace filesystem
+{
/**
* @brief an abstract interface to handle file access
@@ -29,17 +30,21 @@ public:
virtual FILE *handle();
- /// read bytes
+ /// read bytes
virtual size_t read(void *buffer, size_t count) = 0;
/// skip bytes
virtual void skip(size_t count) = 0;
/// name of the file in the virtual filesystem
- inline const std::string name() const { return file_name; }
+ inline const std::string name() const {
+ return file_name;
+ }
/// the path holding the virtual filename
- inline const std::string path() const { return file_path; }
+ inline const std::string path() const {
+ return file_path;
+ }
protected:
std::string file_name;
diff --git a/src/filesystem/filestream.cc b/src/filesystem/filestream.cc
index cfbaaec..53c72d8 100644
--- a/src/filesystem/filestream.cc
+++ b/src/filesystem/filestream.cc
@@ -7,7 +7,8 @@
#include "filesystem/filesystem.h"
#include "filesystem/filestream.h"
-namespace filesystem {
+namespace filesystem
+{
IFileStream::IFileStream(const char *name) : std::ifstream()
{
@@ -38,12 +39,12 @@ void IFileStream::open(const char *name)
for (SearchPath::iterator path = searchpath().begin(); path != searchpath().end(); path++) {
fstream_filename.assign((*path));
fstream_filename.append(fstream_name);
-/*
-#ifdef _WIN32
- for (size_t i = 0; i < fstream_filename.size(); i++)
- if (fstream_filename[i] == '/') fstream_filename[i] = '\\';
-#endif
-*/
+ /*
+ #ifdef _WIN32
+ for (size_t i = 0; i < fstream_filename.size(); i++)
+ if (fstream_filename[i] == '/') fstream_filename[i] = '\\';
+ #endif
+ */
if (sys::file_exists(fstream_filename)) {
std::ifstream::open(fstream_filename.c_str());
diff --git a/src/filesystem/filestream.h b/src/filesystem/filestream.h
index 9739f38..a97d1fb 100644
--- a/src/filesystem/filestream.h
+++ b/src/filesystem/filestream.h
@@ -9,7 +9,7 @@
#include <fstream>
-namespace filesystem
+namespace filesystem
{
/**
@@ -27,10 +27,14 @@ public:
void open(const std::string &name);
/// name of the file in the virtual filesystem
- inline const std::string &name() const { return fstream_name; }
+ inline const std::string &name() const {
+ return fstream_name;
+ }
/// actual dilename
- inline const std::string &filename() const { return fstream_filename; }
+ inline const std::string &filename() const {
+ return fstream_filename;
+ }
private:
std::string fstream_name;
diff --git a/src/filesystem/filesystem.cc b/src/filesystem/filesystem.cc
index d268ccc..4ea715c 100644
--- a/src/filesystem/filesystem.cc
+++ b/src/filesystem/filesystem.cc
@@ -20,7 +20,7 @@
#include "filesystem/file.h"
#include "sys/sys.h"
-namespace filesystem
+namespace filesystem
{
SearchPath filesystem_searchpath;
@@ -56,17 +56,17 @@ void init(const std::string &binaryname, const std::string & basename, const std
filesystem_basename.assign("base");
filesystem_modname.assign(modname);
-
+
#ifndef _WIN32
// UNIX home directory is $HOME/.osirion
filesystem_homedir.assign(getenv("HOME"));
filesystem_homedir.append("/.osirion");
-
+
// create homedir if necessary
if (!sys::directory_exists(filesystem_homedir))
- sys::mkdir(filesystem_homedir);
+ sys::mkdir(filesystem_homedir);
filesystem_homedir += '/';
-
+
#else
// windows home directory is My Documents\My Games\Osirion
char mydocuments[512];
@@ -84,10 +84,10 @@ void init(const std::string &binaryname, const std::string & basename, const std
if (!sys::directory_exists(filesystem_homedir))
sys::mkdir(filesystem_homedir);
filesystem_homedir.append("\\");
-
+
} else {
con_warn << "using fallback home directory" << std::endl;
-
+
filesystem_homedir.assign("home");
if (!sys::directory_exists(filesystem_homedir))
sys::mkdir(filesystem_homedir);
@@ -111,15 +111,15 @@ void init(const std::string &binaryname, const std::string & basename, const std
// the data dir set by the configure script
std::string package_datadir(PACKAGE_DATADIR);
std::string dir;
-
+
// set writedir depending on modname and add home paths to the searchpath
filesystem_writedir.assign(filesystem_homedir);
if (filesystem_modname.size()) {
// append modname to writedir
- filesystem_writedir.append(filesystem_modname);
+ filesystem_writedir.append(filesystem_modname);
} else {
// append basename to writedir
- filesystem_writedir.append(filesystem_basename);
+ filesystem_writedir.append(filesystem_basename);
}
// create writedir if necessary
@@ -181,7 +181,7 @@ void init(const std::string &binaryname, const std::string & basename, const std
for (SearchPath::iterator path = filesystem_searchpath.begin(); path != filesystem_searchpath.end(); ++path) {
#ifdef _WIN32
for (size_t i = 0; i < (*path).size(); i++)
- if ((*path)[i] == '/') (*path)[i] = '\\';
+ if ((*path)[i] == '/')(*path)[i] = '\\';
#endif
con_print << " directory " << (*path) << std::endl;
}
@@ -203,7 +203,7 @@ void shutdown()
filesystem_writedir.clear();
}
-File *open(const char *filename)
+File *open(const char *filename)
{
// for now, File is always a DiskFile
DiskFile *f = new DiskFile();
diff --git a/src/filesystem/filesystem.h b/src/filesystem/filesystem.h
index 1bdacaa..5fe97d0 100644
--- a/src/filesystem/filesystem.h
+++ b/src/filesystem/filesystem.h
@@ -17,7 +17,8 @@
/// The filesystem namespace contains classes and functions for common file operations.
/** filesystem is a core subsystem
*/
-namespace filesystem {
+namespace filesystem
+{
typedef std::list<std::string> SearchPath;
diff --git a/src/filesystem/inifile.cc b/src/filesystem/inifile.cc
index c6cc625..52bf36d 100644
--- a/src/filesystem/inifile.cc
+++ b/src/filesystem/inifile.cc
@@ -11,7 +11,8 @@
#include <sstream>
-namespace filesystem {
+namespace filesystem
+{
IniFile::IniFile(const char *ininame)
{
@@ -25,7 +26,7 @@ IniFile::IniFile(const std::string & ininame)
open(ininame.c_str());
}
-IniFile::~IniFile()
+IniFile::~IniFile()
{
if (inifile_stream.is_open())
inifile_stream.close();
@@ -65,19 +66,23 @@ bool IniFile::open(const char *ininame)
}
-bool IniFile::got_section() const {
+bool IniFile::got_section() const
+{
return last_read_was_section;
}
-bool IniFile::got_section(const char * sectionlabel) const {
+bool IniFile::got_section(const char * sectionlabel) const
+{
return (last_read_was_section && (section_current.compare(sectionlabel) == 0));
}
-bool IniFile::in_section(const char * sectionlabel) const {
+bool IniFile::in_section(const char * sectionlabel) const
+{
return ((section_current.compare(sectionlabel) == 0));
}
-bool IniFile::getline() {
+bool IniFile::getline()
+{
char line[1024];
last_read_was_section = false;
@@ -103,7 +108,7 @@ bool IniFile::getline() {
// section header
if (s.size() > 2 && s[0] == '[' && s[s.size()-1] == ']') {
// condebug << "Inifile got section header " << s << std::endl;
- section_current = s.substr(1, s.size()-2);
+ section_current = s.substr(1, s.size() - 2);
aux::trim(section_current);
aux::to_lowercase(section_current);
@@ -121,9 +126,9 @@ bool IniFile::getline() {
aux::to_lowercase(key_current);
if (key_current.size()) {
- value_current = s.substr(found+1, s.size() - found - 1);
- aux::trim (value_current);
- last_read_was_key = true;
+ value_current = s.substr(found + 1, s.size() - found - 1);
+ aux::trim(value_current);
+ last_read_was_key = true;
//con_debug << "IniFile got " << key_current << "=" << value_current << std::endl;
return true;
}
@@ -140,8 +145,9 @@ bool IniFile::got_key() const
return last_read_was_key;
}
-bool IniFile::got_key_string(const char * keylabel, std::string & valuestring) {
- if (last_read_was_key && (key_current.compare(keylabel) == 0 )) {
+bool IniFile::got_key_string(const char * keylabel, std::string & valuestring)
+{
+ if (last_read_was_key && (key_current.compare(keylabel) == 0)) {
valuestring.assign(value_current);
return true;
} else {
@@ -149,14 +155,15 @@ bool IniFile::got_key_string(const char * keylabel, std::string & valuestring) {
}
}
-bool IniFile::got_key_vector3f(const char * keylabel, math::Vector3f & v) {
- if (last_read_was_key && (key_current.compare(keylabel) == 0 )) {
+bool IniFile::got_key_vector3f(const char * keylabel, math::Vector3f & v)
+{
+ if (last_read_was_key && (key_current.compare(keylabel) == 0)) {
std::istringstream is(value_current);
float x, y, z;
if ((is >> x) && (is >> y) && (is >> z)) {
- v = math::Vector3f(x,y,z);
+ v = math::Vector3f(x, y, z);
} else {
- v= math::Vector3f();
+ v = math::Vector3f();
}
return true;
} else {
@@ -164,8 +171,9 @@ bool IniFile::got_key_vector3f(const char * keylabel, math::Vector3f & v) {
}
}
-bool IniFile::got_key_float(const char * keylabel, float & f) {
- if (last_read_was_key && (key_current.compare(keylabel) == 0 )) {
+bool IniFile::got_key_float(const char * keylabel, float & f)
+{
+ if (last_read_was_key && (key_current.compare(keylabel) == 0)) {
std::istringstream is(value_current);
if (!(is >> f)) {
f = 0;
@@ -176,8 +184,9 @@ bool IniFile::got_key_float(const char * keylabel, float & f) {
}
}
-bool IniFile::got_key_long(const char * keylabel, long & l) {
- if (last_read_was_key && (key_current.compare(keylabel) == 0 )) {
+bool IniFile::got_key_long(const char * keylabel, long & l)
+{
+ if (last_read_was_key && (key_current.compare(keylabel) == 0)) {
std::istringstream is(value_current);
if (!(is >> l)) {
l = 0;
@@ -188,12 +197,14 @@ bool IniFile::got_key_long(const char * keylabel, long & l) {
}
}
-bool IniFile::got_key(const char * keylabel) {
- return (last_read_was_key && (key_current.compare(keylabel) == 0 ));
+bool IniFile::got_key(const char * keylabel)
+{
+ return (last_read_was_key && (key_current.compare(keylabel) == 0));
}
-bool IniFile::got_key_angle(const char * keylabel, float & f) {
- if (last_read_was_key && (key_current.compare(keylabel) == 0 )) {
+bool IniFile::got_key_angle(const char * keylabel, float & f)
+{
+ if (last_read_was_key && (key_current.compare(keylabel) == 0)) {
std::istringstream is(value_current);
if ((is >> f)) {
f = math::degrees360f(f);
@@ -206,8 +217,9 @@ bool IniFile::got_key_angle(const char * keylabel, float & f) {
}
}
-bool IniFile::got_key_color(const char * keylabel, math::Color & color) {
- if (last_read_was_key && (key_current.compare(keylabel) == 0 )) {
+bool IniFile::got_key_color(const char * keylabel, math::Color & color)
+{
+ if (last_read_was_key && (key_current.compare(keylabel) == 0)) {
std::istringstream is(value_current);
float r, g, b, a;
if ((is >> r) && (is >> g) && (is >> b)) {
@@ -215,7 +227,9 @@ bool IniFile::got_key_color(const char * keylabel, math::Color & color) {
if (is >> a) {
a /= 255.0f;
}
- r /= 255.0f; g /= 255.0f; b /= 255.0f;
+ r /= 255.0f;
+ g /= 255.0f;
+ b /= 255.0f;
} else {
if (!(is >> a)) {
a = 1.0f;
@@ -233,12 +247,13 @@ bool IniFile::got_key_color(const char * keylabel, math::Color & color) {
bool IniFile::got_key_bool(const char * keylabel, bool & b)
{
- if (last_read_was_key && (key_current.compare(keylabel) == 0 )) {
+ if (last_read_was_key && (key_current.compare(keylabel) == 0)) {
std::istringstream is(value_current);
unsigned int i;
if (is >> i) {
- if (i) b = true; else b = false;
+ if (i) b = true;
+ else b = false;
return true;
}
@@ -266,7 +281,7 @@ bool IniFile::got_key_bool(const char * keylabel, bool & b)
void IniFile::unknown_value() const
{
- con_warn << name() << " unknown value '" << value() << "' for key '" << key() << "' at line " << line() << std::endl;
+ con_warn << name() << " unknown value '" << value() << "' for key '" << key() << "' at line " << line() << std::endl;
}
void IniFile::unkown_key() const
diff --git a/src/filesystem/inifile.h b/src/filesystem/inifile.h
index fa2d81f..e5423aa 100644
--- a/src/filesystem/inifile.h
+++ b/src/filesystem/inifile.h
@@ -14,14 +14,16 @@
#include "math/color.h"
#include "filesystem/filestream.h"
-namespace filesystem {
+namespace filesystem
+{
/// a class to read .ini files
/** The IniFile class provides functions to read .ini files. A .ini file
* consists of one or more [section] headers followed by one or more key=value
* pairs. Lines starting with # or ; are considered comments
*/
-class IniFile {
+class IniFile
+{
public:
IniFile(const char *ininame = 0);
@@ -97,16 +99,24 @@ public:
void unknown_section() const;
/// return true of the ini file is open for reading
- inline bool is_open() { return inifile_stream.is_open(); }
+ inline bool is_open() {
+ return inifile_stream.is_open();
+ }
/// return true of the ini file is open for reading
- inline bool good() { return inifile_stream.good(); }
+ inline bool good() {
+ return inifile_stream.good();
+ }
/// current name in the virtual filesystem
- inline std::string const & name() const {return inifile_stream.name(); }
+ inline std::string const & name() const {
+ return inifile_stream.name();
+ }
/// current actual filename
- inline std::string const & filename() const { return inifile_stream.filename(); }
+ inline std::string const & filename() const {
+ return inifile_stream.filename();
+ }
/// close the file
void close();
diff --git a/src/game/base/collision.cc b/src/game/base/collision.cc
index 4e6f4bb..952bba2 100644
--- a/src/game/base/collision.cc
+++ b/src/game/base/collision.cc
@@ -18,18 +18,18 @@ void Collision::distance_test(core::EntityControlable *first, core::Entity *seco
{
if (!first->owner())
return;
-
+
if (first->state() == core::Entity::Docked)
return;
-
+
// FIXME - use distancesquared
const float d = math::distance(first->location(), second->location());
const float r = first->radius() + second->radius();
-
+
if (second->type() == core::Entity::Globe) {
// collision with a star or a planet
-
- if ((d-r) < 0.0f) {
+
+ if ((d - r) < 0.0f) {
// crash zone
if ((first->moduletype() == ship_enttype) && (first->state() != core::Entity::Destroyed)) {
first->owner()->send_warning("^RBOOM!^N");
@@ -38,9 +38,9 @@ void Collision::distance_test(core::EntityControlable *first, core::Entity *seco
}
} else if (first->owner()->last_warning() + 5.0f < core::application()->time()) {
// warning zone: star corona or planet atmosphere
- if ((second->moduletype() == star_enttype) && (d-r < 50.0f)) {
+ if ((second->moduletype() == star_enttype) && (d - r < 50.0f)) {
first->owner()->send_warning("^3Warning: entering star corona!^N");
- } else if ((second->moduletype() == planet_enttype) && (d-r < Planet::safe_distance)) {
+ } else if ((second->moduletype() == planet_enttype) && (d - r < Planet::safe_distance)) {
first->owner()->send_warning("^3Warning: entering planet gravity well!^N");
}
}
@@ -51,7 +51,7 @@ void Collision::frame_zone(core::Zone *zone)
{
core::Zone::Content::iterator first;
core::Zone::Content::iterator second;
-
+
for (first = zone->content().begin(); first != zone->content().end(); first ++) {
second = first;
for (second++; second != zone->content().end(); second++) {
diff --git a/src/game/base/collision.h b/src/game/base/collision.h
index 8203669..d74e6d6 100644
--- a/src/game/base/collision.h
+++ b/src/game/base/collision.h
@@ -1,7 +1,7 @@
/*
base/collision.h
- This file is part of the Osirion project and is distributed under
- the terms and conditions of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
*/
#ifndef __INCLUDED_BASE_COLLISION_H__
@@ -9,10 +9,12 @@
#include "core/zone.h"
-namespace game {
+namespace game
+{
/// collision detection functions
-class Collision {
+class Collision
+{
public:
/// do collision detection
static void frame(const float elapsed);
@@ -20,7 +22,7 @@ public:
private:
/// do collision detection for a single zone
static void frame_zone(core::Zone *zone);
-
+
/// do a distance test between two entities
static void distance_test(core::EntityControlable *first, core::Entity *second);
};
diff --git a/src/game/base/game.cc b/src/game/base/game.cc
index bcb3567..7ec54b3 100644
--- a/src/game/base/game.cc
+++ b/src/game/base/game.cc
@@ -82,12 +82,12 @@ void Game::func_join(core::Player *player, std::string const &args)
core::Entity *dock = ship->zone()->default_view();
if (dock) {
- ship->get_location().assign(dock->location() + (dock->axis().forward() * ((ship->radius()+ dock->radius())*2.0f)));
+ ship->get_location().assign(dock->location() + (dock->axis().forward() *((ship->radius() + dock->radius())*2.0f)));
ship->get_axis().assign(dock->axis());
ship->set_state(core::Entity::Docked);
player->set_view(dock);
}
-
+
std::string message("^B");
message.append(player->name());
message.append("^B joins the game.");
@@ -233,15 +233,15 @@ void Game::func_launch(core::Player *player, std::string const &args)
return;
assert(player->view()->zone() == player->control()->zone());
-
+
Ship *ship = static_cast<Ship *>(player->control());
ship->shutdown_physics();
core::Entity *dock = player->view();
if (dock->type() == core::Entity::Globe)
- ship->get_location().assign(dock->location() + (dock->axis().forward() * (Planet::safe_distance + ship->radius() + dock->radius())));
+ ship->get_location().assign(dock->location() + (dock->axis().forward() *(Planet::safe_distance + ship->radius() + dock->radius())));
else
- ship->get_location().assign(dock->location() + (dock->axis().forward() * (ship->radius() + dock->radius())));
+ ship->get_location().assign(dock->location() + (dock->axis().forward() *(ship->radius() + dock->radius())));
ship->get_axis().assign(dock->axis());
ship->set_state(core::Entity::Normal);
@@ -309,9 +309,9 @@ void Game::func_goto(core::Player *player, const std::string &args)
ship->shutdown_physics();
if (dock->type() == core::Entity::Globe)
- ship->get_location().assign(dock->location() + (dock->axis().forward() * (Planet::safe_distance + ship->radius() + dock->radius())));
+ ship->get_location().assign(dock->location() + (dock->axis().forward() *(Planet::safe_distance + ship->radius() + dock->radius())));
else
- ship->get_location().assign(dock->location() + (dock->axis().forward() * (ship->radius() + dock->radius())));
+ ship->get_location().assign(dock->location() + (dock->axis().forward() *(ship->radius() + dock->radius())));
ship->get_axis().assign(dock->axis());
ship->get_axis().change_direction(180.0f);
@@ -319,7 +319,7 @@ void Game::func_goto(core::Player *player, const std::string &args)
ship->init_physics(ship->radius());
ship->set_state(core::Entity::Jump);
-
+
player->set_view(0);
player->send("Going to " + dock->name());
} else {
@@ -333,7 +333,7 @@ Game::Game() : core::Module("Project::OSiRiON", true)
{
Default::clear();
ShipModel::clear();
-
+
Physics::init();
if (!load_ships()) {
@@ -350,13 +350,13 @@ Game::Game() : core::Module("Project::OSiRiON", true)
abort();
return;
}
-
+
// add engine functions
core::Func *func = 0;
func = core::Func::add("list_ship", Game::func_list_ship);
func->set_info("[string] list ship statistics");
-
+
func = core::Func::add("join", Game::func_join);
func->set_info("join the game");
@@ -445,7 +445,7 @@ bool Game::load_world()
}
} else if (worldini.got_key()) {
-
+
if (worldini.in_section("world")) {
if (worldini.got_key_string("zone", label)) {
@@ -521,20 +521,20 @@ bool Game::load_zone(core::Zone *zone)
while (zoneini.getline()) {
- if (zoneini.got_section()) {
+ if (zoneini.got_section()) {
if (zoneini.got_section("zone")) {
continue;
-
+
} else if (zoneini.got_section("star")) {
star = new Star();
star->set_zone(zone);
count ++;
-
+
} else if (zoneini.got_section("navpoint")) {
navpoint = new NavPoint();
navpoint->set_zone(zone);
count ++;
-
+
} else if (zoneini.got_section("jumpgate")) {
jumppoint = new JumpGate();
jumppoint->set_zone(zone);
@@ -544,17 +544,17 @@ bool Game::load_zone(core::Zone *zone)
jumppoint = new JumpPoint();
jumppoint->set_zone(zone);
count ++;
-
- } else if(zoneini.got_section("racetrack")) {
+
+ } else if (zoneini.got_section("racetrack")) {
racetrack = new RaceTrack();
racetrack->set_zone(zone);
-
- } else if(zoneini.got_section("checkpoint")) {
+
+ } else if (zoneini.got_section("checkpoint")) {
checkpoint = new CheckPoint(racetrack);
if (!racetrack) {
con_warn << zoneini.name() << " checkpoint without racetrack at line " << zoneini.line() << std::endl;
}
-
+
} else if (zoneini.got_section("planet")) {
planet = new Planet();
planet->set_zone(zone);
@@ -564,13 +564,13 @@ bool Game::load_zone(core::Zone *zone)
station = new Station();
station->set_zone(zone);
count ++;
-
+
} else if (zoneini.got_section("entity")) {
entity = new core::Entity();
entity->set_flag(core::Entity::Static);
entity->set_zone(zone);
count ++;
-
+
} else {
zoneini.unknown_section();
}
@@ -593,7 +593,7 @@ bool Game::load_zone(core::Zone *zone)
if (core::Parser::got_entity_key(zoneini, star)) {
continue;
} else if (zoneini.got_key_string("texture", star->entity_texture)) {
- continue;
+ continue;
} else {
zoneini.unkown_key();
}
@@ -619,12 +619,12 @@ bool Game::load_zone(core::Zone *zone)
if (core::Parser::got_entity_key(zoneini, planet)) {
continue;
} else if (zoneini.got_key_string("texture", planet->entity_texture)) {
- continue;
+ continue;
} else if (zoneini.got_key_float("rotationspeed", planet->entity_rotationspeed)) {
continue;
} else if (zoneini.got_key_bool("dock", b)) {
if (b) {
- planet->set_flag(core::Entity::Dockable);
+ planet->set_flag(core::Entity::Dockable);
} else {
planet->unset_flag(core::Entity::Dockable);
}
@@ -636,7 +636,7 @@ bool Game::load_zone(core::Zone *zone)
} else {
zoneini.unkown_key();
}
-
+
} else if (zoneini.in_section("station")) {
if (core::Parser::got_entity_key(zoneini, station)) {
continue;
@@ -673,7 +673,7 @@ bool Game::load_zone(core::Zone *zone)
zoneini.unkown_key();
}
}
-
+
}
}
zoneini.close();
@@ -707,7 +707,7 @@ bool Game::validate_zone(core::Zone *zone)
if ((entity->flags() & core::Entity::Dockable) == core::Entity::Dockable)
load_menus(entity, "zones/" + zone->label() + "/" + entity->label());
- }
+ }
}
return true;
@@ -733,7 +733,7 @@ bool Game::load_menus(core::Entity *entity, const std::string &menufilename)
if (inifile.is_open()) {
while (inifile.getline()) {
-
+
if (inifile.got_section()) {
if (inifile.got_section("dealer")) {
// dealer menu
@@ -741,22 +741,22 @@ bool Game::load_menus(core::Entity *entity, const std::string &menufilename)
menu_dealer = new MenuDescription();
menu_dealer->set_label("dealer");
menu_dealer->set_text("Ship dealer");
-
+
shipdealer = new ShipDealer();
if (entity->moduletype() == planet_enttype) {
static_cast<Planet *>(entity)->set_shipdealer(shipdealer);
} else if (entity->moduletype() == station_enttype) {
static_cast<Station *>(entity)->set_shipdealer(shipdealer);
}
- }
+ }
} else {
inifile.unknown_section();
}
-
+
} else if (inifile.got_key()) {
-
+
if (inifile.in_section("dealer")) {
-
+
if (inifile.got_key_string("ship", strval)) {
aux::to_label(strval);
ShipModel *model = shipdealer->add(strval);
@@ -771,7 +771,7 @@ bool Game::load_menus(core::Entity *entity, const std::string &menufilename)
} else {
inifile.unkown_key();
}
-
+
}
}
}
@@ -805,12 +805,12 @@ bool Game::load_menus(core::Entity *entity, const std::string &menufilename)
menu_main->add_button(button);
}
- if (inifile.is_open()) {
+ if (inifile.is_open()) {
size_t n = entity->menus().size();
con_debug << " " << inifile.name() << " " << n << " " << aux::plural("menu", n) << std::endl;
inifile.close();
}
-
+
return true;
}
@@ -841,8 +841,8 @@ bool Game::load_ships()
shipmodel->shipmodel_label.assign(label);
ShipModel::add(shipmodel);
continue;
- } else if (shipsini.got_key_string("name",shipmodel->shipmodel_name)) {
- continue;
+ } else if (shipsini.got_key_string("name", shipmodel->shipmodel_name)) {
+ continue;
} else if (shipsini.got_key_string("info", infostr)) {
shipmodel->shipmodel_infotext.push_back(infostr);
continue;
@@ -856,7 +856,7 @@ bool Game::load_ships()
continue;
} else if (shipsini.got_key_bool("jumpdrive", shipmodel->shipmodel_jumpdrive)) {
continue;
- } else if (shipsini.got_key_float("acceleration",f)) {
+ } else if (shipsini.got_key_float("acceleration", f)) {
shipmodel->set_acceleration(f);
continue;
} else if (shipsini.got_key_float("maxspeed", f)) {
@@ -874,7 +874,7 @@ bool Game::load_ships()
if (shipmodel && !ShipModel::find(shipmodel)) delete shipmodel;
shipmodel = new ShipModel();
if (!Default::shipmodel)
- Default::shipmodel = shipmodel;
+ Default::shipmodel = shipmodel;
} else if (shipsini.got_section()) {
shipsini.unknown_section();
@@ -934,7 +934,7 @@ bool Game::load_player()
aux::to_label(str);
Default::shipmodel = ShipModel::find(str);
}
- }
+ }
}
}
diff --git a/src/game/base/game.h b/src/game/base/game.h
index 9b2d377..65084d3 100644
--- a/src/game/base/game.h
+++ b/src/game/base/game.h
@@ -1,7 +1,7 @@
/*
base/game.h
- This file is part of the Osirion project and is distributed under
- the terms of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
*/
#ifndef __INCLUDED_BASE_H__
@@ -35,7 +35,8 @@ const unsigned int jumpgate_enttype = 261;
const unsigned int station_enttype = 262;
/// default player settings
-class Default {
+class Default
+{
public:
static core::Zone *zone;
static core::Entity *view;
@@ -46,7 +47,8 @@ public:
};
/// the base Project::OSiRiON game model
-class Game : public core::Module {
+class Game : public core::Module
+{
public:
Game();
virtual ~Game();
@@ -84,7 +86,7 @@ private:
bool load_menus(core::Entity *entity, const std::string &menufilename);
bool load_ships();
-
+
bool load_player();
/* ---- engine functions ----------------------------------- */
@@ -95,7 +97,7 @@ private:
static void func_hail(core::Player *player, std::string const &args);
static void func_jump(core::Player *player, std::string const &args);
static void func_impulse(core::Player *player, std::string const &args);
- static void func_dock(core::Player *player,core::Entity *entity);
+ static void func_dock(core::Player *player, core::Entity *entity);
static void func_launch(core::Player *player, std::string const &args);
static void func_respawn(core::Player *player, std::string const &args);
static void func_goto(core::Player *player, const std::string &args);
diff --git a/src/game/base/jumppoint.cc b/src/game/base/jumppoint.cc
index 9017f1c..5b4e689 100644
--- a/src/game/base/jumppoint.cc
+++ b/src/game/base/jumppoint.cc
@@ -1,7 +1,7 @@
/*
base/jumppoint.cc
- This file is part of the Osirion project and is distributed under
- the terms and conditions of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
*/
#include "base/game.h"
@@ -28,7 +28,7 @@ JumpPoint::~JumpPoint()
{
}
-void JumpPoint::set_targetlabel(const std::string &label)
+void JumpPoint::set_targetlabel(const std::string &label)
{
jumppoint_targetlabel.assign(label);
}
@@ -42,13 +42,13 @@ void JumpPoint::validate()
return;
}
size_t pos = targetlabel().find(':');
- if ((pos < 1 ) || (pos >= (targetlabel().size()-1))) {
+ if ((pos < 1) || (pos >= (targetlabel().size() - 1))) {
con_warn << " Jumppoint with invalid target label '" << targetlabel() << "'\n";
return;
}
std::string zonelabel(targetlabel().substr(0, pos));
- std::string entitylabel(targetlabel().substr(pos+1, targetlabel().size()-pos));
+ std::string entitylabel(targetlabel().substr(pos + 1, targetlabel().size() - pos));
core::Zone *targetzone = core::Zone::find(zonelabel);
if (!targetzone) {
@@ -68,7 +68,7 @@ void JumpPoint::validate()
}
jumppoint_target = static_cast<JumpPoint *>(targetentity);
-
+
//con_debug << " Jumppoint " << zone->label() << ":" << label() << " with target " << targetlabel() << std::endl;
}
@@ -132,7 +132,7 @@ void JumpGate::dock(core::Entity *entity)
if (ship->owner())
ship->owner()->send("Jumpgate inactive");
return;
- }
+ }
}
void JumpGate::activate()
diff --git a/src/game/base/jumppoint.h b/src/game/base/jumppoint.h
index 900f1f3..fe29727 100644
--- a/src/game/base/jumppoint.h
+++ b/src/game/base/jumppoint.h
@@ -1,7 +1,7 @@
/*
base/jumppoint.h
- This file is part of the Osirion project and is distributed under
- the terms and conditions of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
*/
#ifndef __INCLUDED_BASE_JUMPPOINT_H__
@@ -12,7 +12,8 @@
#include <string>
-namespace game {
+namespace game
+{
/// a jumppoint
/**
@@ -21,14 +22,19 @@ namespace game {
* between the current system and the target of the nearest jumppoint.
*
*/
-class JumpPoint : public core::EntityDynamic {
+class JumpPoint : public core::EntityDynamic
+{
public:
JumpPoint();
virtual ~JumpPoint();
- inline std::string const & targetlabel() { return jumppoint_targetlabel; }
+ inline std::string const & targetlabel() {
+ return jumppoint_targetlabel;
+ }
- inline JumpPoint *target() { return jumppoint_target; }
+ inline JumpPoint *target() {
+ return jumppoint_target;
+ }
/// set trget label
void set_targetlabel(const std::string &label);
@@ -42,7 +48,8 @@ private:
};
/// a jumpgate
-class JumpGate : public JumpPoint {
+class JumpGate : public JumpPoint
+{
public:
JumpGate();
virtual ~JumpGate();
@@ -53,7 +60,9 @@ public:
/// entity received a docking request
virtual void dock(core::Entity *entity);
- inline bool activated() const { return (jumpgate_timer > 0); }
+ inline bool activated() const {
+ return (jumpgate_timer > 0);
+ }
void activate();
diff --git a/src/game/base/navpoint.cc b/src/game/base/navpoint.cc
index 7b48ee7..78f1ae0 100644
--- a/src/game/base/navpoint.cc
+++ b/src/game/base/navpoint.cc
@@ -1,7 +1,7 @@
/*
base/navpoint.cc
- This file is part of the Osirion project and is distributed under
- the terms and conditions of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
*/
#include "base/navpoint.h"
diff --git a/src/game/base/navpoint.h b/src/game/base/navpoint.h
index c2fb1d6..bb2420e 100644
--- a/src/game/base/navpoint.h
+++ b/src/game/base/navpoint.h
@@ -1,7 +1,7 @@
/*
base/navpoint.h
- This file is part of the Osirion project and is distributed under
- the terms and conditions of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
*/
#ifndef __INCLUDED_BASE_NAVPOINT_H__
@@ -12,10 +12,12 @@
#include <string>
-namespace game {
+namespace game
+{
/// a navigation point
-class NavPoint : public core::Entity {
+class NavPoint : public core::Entity
+{
public:
NavPoint();
~NavPoint();
diff --git a/src/game/base/physics.cc b/src/game/base/physics.cc
index b76e0c1..3cc7427 100644
--- a/src/game/base/physics.cc
+++ b/src/game/base/physics.cc
@@ -49,12 +49,12 @@ CollisionShape::CollisionShape(model::Model *model, const bool moving)
if (group->type() == model::FragmentGroup::None) {
// for each fragment
- for (model::FragmentGroup::iterator fit = group->begin(); fit != group->end(); fit++) {
+ for (model::FragmentGroup::iterator fit = group->begin(); fit != group->end(); fit++) {
model::Fragment *fragment = (*fit);
- const size_t index = fragment->index();
- const size_t triangle_count = (fragment->structural_size() + fragment->detail_size()) / 3;
-
+ const size_t index = fragment->index();
+ const size_t triangle_count = (fragment->structural_size() + fragment->detail_size()) / 3;
+
// load vertices from the global VertexArray into the bullet shape
for (size_t i = 0; i < triangle_count; i++) {
float *f = vertexarray->vertex() + index + (i * 9);
@@ -81,8 +81,8 @@ CollisionShape::CollisionShape(model::Model *model, const bool moving)
static_shape = new btBvhTriangleMeshShape(shape_mesh, true, false);
shape_bulletshape = static_shape;
}
-
-
+
+
con_debug << " collision data for " << model->name() << ": " << count << " tris " << std::endl;
#endif
}
@@ -136,10 +136,10 @@ void Physics::init()
{
con_print << "^BInitializing bullet physics..." << std::endl;
- configuration = new btDefaultCollisionConfiguration();
+ configuration = new btDefaultCollisionConfiguration();
dispatcher = new btCollisionDispatcher(configuration);
solver = new btSequentialImpulseConstraintSolver;
-
+
}
void Physics::frame(const float seconds)
@@ -183,12 +183,12 @@ void Physics::shutdown()
PhysicsZone::PhysicsZone(const std::string &label) : core::Zone(label)
{
#ifdef HAVE_BULLET
- btVector3 worldAabbMin(-10000,-10000,-10000);
- btVector3 worldAabbMax(10000,10000,10000);
+ btVector3 worldAabbMin(-10000, -10000, -10000);
+ btVector3 worldAabbMax(10000, 10000, 10000);
const int maxProxies = 1024;
-
- zone_cache = new btAxisSweep3(worldAabbMin,worldAabbMax,maxProxies);
- zone_dynamics_world = new btDiscreteDynamicsWorld(Physics::dispatcher, zone_cache, Physics::solver,Physics::configuration);
+
+ zone_cache = new btAxisSweep3(worldAabbMin, worldAabbMax, maxProxies);
+ zone_dynamics_world = new btDiscreteDynamicsWorld(Physics::dispatcher, zone_cache, Physics::solver, Physics::configuration);
// disable gravity
zone_dynamics_world->setGravity(btVector3(0.0f, 0.0f, 0.0f));
@@ -222,7 +222,7 @@ PhysicsBody::PhysicsBody(core::Entity *entity)
#endif
}
-PhysicsBody::~PhysicsBody()
+PhysicsBody::~PhysicsBody()
{
#ifdef HAVE_BULLET
if (collider_body) {
@@ -251,22 +251,22 @@ void PhysicsBody::init_physics(const float mass)
}
if (!collider_body) {
- btVector3 inertia(0,0,0);
+ btVector3 inertia(0, 0, 0);
btTransform t;
t.setIdentity();
t.setOrigin(to_btVector3(entity()->location()));
t.setBasis(to_btMatrix3x3(entity()->axis()));
-
-
+
+
if (moving) {
- collider_shape->bullet_shape()->calculateLocalInertia(mass,inertia);
+ collider_shape->bullet_shape()->calculateLocalInertia(mass, inertia);
btMotionState *motionstate = new btDefaultMotionState(t);
btRigidBody::btRigidBodyConstructionInfo body_info(mass, motionstate, collider_shape->bullet_shape(), inertia);
- collider_body = new btRigidBody(body_info);
+ collider_body = new btRigidBody(body_info);
collider_body->setUserPointer((void *)entity());
- collider_body->setLinearFactor(btVector3(1,1,1));
+ collider_body->setLinearFactor(btVector3(1, 1, 1));
collider_body->setCcdMotionThreshold(0.0001f);
} else {
collider_body = new btRigidBody(mass, 0, collider_shape->bullet_shape(), inertia);
@@ -276,7 +276,7 @@ void PhysicsBody::init_physics(const float mass)
if (entity()->zone()) {
PhysicsZone *zone = static_cast<PhysicsZone *>(entity()->zone());
- zone->dynamics_world()->addRigidBody(collider_body);
+ zone->dynamics_world()->addRigidBody(collider_body);
if (moving) {
//collider_body->setActivationState(ISLAND_SLEEPING);
//collider_body->setActivationState(ACTIVE_TAG);
@@ -292,8 +292,7 @@ void PhysicsBody::shutdown_physics()
if (collider_body && entity()->zone()) {
PhysicsZone *zone = static_cast<PhysicsZone *>(entity()->zone());
- if(collider_body->getMotionState())
- {
+ if (collider_body->getMotionState()) {
delete collider_body->getMotionState();
}
zone->dynamics_world()->removeCollisionObject(collider_body);
diff --git a/src/game/base/physics.h b/src/game/base/physics.h
index 37ed1cf..3bbd749 100644
--- a/src/game/base/physics.h
+++ b/src/game/base/physics.h
@@ -1,7 +1,7 @@
/*
base/physics.h
- This file is part of the Osirion project and is distributed under
- the terms and conditions of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
*/
#ifndef __INCLUDED_BASE_PHYSICS_H__
@@ -23,7 +23,8 @@
*/
-namespace game {
+namespace game
+{
#ifdef HAVE_BULLET
/// helper function to convert math:Vector3f to btVector3
@@ -36,29 +37,36 @@ inline btVector3 to_btVector3(const math::Vector3f & v)
inline btMatrix3x3 to_btMatrix3x3(const math::Axis &a)
{
return btMatrix3x3(a[0][0], a[0][1], a[0][2],
- a[1][0], a[1][1], a[1][2],
- a[2][0], a[2][1], a[2][2]);
+ a[1][0], a[1][1], a[1][2],
+ a[2][0], a[2][1], a[2][2]);
};
#endif
/* ---- class CollisionShape --------------------------------------- */
/// a bullet collision shape
-class CollisionShape {
+class CollisionShape
+{
public:
CollisionShape(model::Model *model, const bool moving);
~CollisionShape();
- inline const std::string &label() const { return shape_label; }
+ inline const std::string &label() const {
+ return shape_label;
+ }
- inline const bool moving() const { return shape_moving; }
+ inline const bool moving() const {
+ return shape_moving;
+ }
#ifdef HAVE_BULLET
- inline btCollisionShape *bullet_shape() { return shape_bulletshape; }
+ inline btCollisionShape *bullet_shape() {
+ return shape_bulletshape;
+ }
#endif
-/* ----- static functions for the shape registry ------------------- */
+ /* ----- static functions for the shape registry ------------------- */
/// tpye definition for the collision shape registry
typedef std::vector<CollisionShape *> Registry;
@@ -85,7 +93,8 @@ private:
/* ---- class Physics ---------------------------------------------- */
/// main physics functions
-class Physics {
+class Physics
+{
public:
/// intialize world physics
static void init();
@@ -108,13 +117,16 @@ public:
/* ---- class PhysicsZone ------------------------------------------ */
/// a zone containing collision objects
-class PhysicsZone : public core::Zone {
+class PhysicsZone : public core::Zone
+{
public:
PhysicsZone(const std::string &label);
virtual ~PhysicsZone();
#ifdef HAVE_BULLET
- inline btDiscreteDynamicsWorld *dynamics_world() { return zone_dynamics_world; }
+ inline btDiscreteDynamicsWorld *dynamics_world() {
+ return zone_dynamics_world;
+ }
private:
btAxisSweep3 *zone_cache;
@@ -125,10 +137,11 @@ private:
/* ---- class PhysicsBody ------------------------------------------ */
/// an object that is capable of colliding with other objects
-class PhysicsBody {
+class PhysicsBody
+{
public:
/// initialize a collider attached to an entity
- /**
+ /**
* a PhysicsBody with zero mass is considered non-moving
*/
PhysicsBody(core::Entity *entity);
@@ -141,14 +154,20 @@ public:
void shutdown_physics();
/// collider mass
- inline const float mass() const { return collider_mass; }
+ inline const float mass() const {
+ return collider_mass;
+ }
/// the entity the collider is attached to
- inline core::Entity *entity() { return collider_entity; }
+ inline core::Entity *entity() {
+ return collider_entity;
+ }
#ifdef HAVE_BULLET
/// the bullet rigid body associated with this collider
- inline btRigidBody *body() { return collider_body; }
+ inline btRigidBody *body() {
+ return collider_body;
+ }
#endif
private:
diff --git a/src/game/base/planet.cc b/src/game/base/planet.cc
index b1ac976..f9535ba 100644
--- a/src/game/base/planet.cc
+++ b/src/game/base/planet.cc
@@ -8,7 +8,8 @@
#include "base/planet.h"
-namespace game {
+namespace game
+{
Planet::Planet() : core::EntityGlobe(core::Entity::Static | core::Entity::Solid)
{
@@ -46,7 +47,7 @@ void Planet::dock(core::Entity *entity)
Ship * ship = static_cast<Ship *>(entity);
- if (math::distance(location(), ship->location()) > radius() + ship->radius() + 50.0f ) {
+ if (math::distance(location(), ship->location()) > radius() + ship->radius() + 50.0f) {
if (ship->owner())
ship->owner()->send("Planet out of range");
return;
@@ -55,7 +56,7 @@ void Planet::dock(core::Entity *entity)
ship->get_location().assign(entity->location());
ship->set_state(core::Entity::Docked);
- if (ship->owner() && ship->owner()->control() == ship) {
+ if (ship->owner() && ship->owner()->control() == ship) {
ship->owner()->set_view(this);
ship->owner()->send("^BDocking at " + name());
}
diff --git a/src/game/base/planet.h b/src/game/base/planet.h
index c9bb214..f0bf75f 100644
--- a/src/game/base/planet.h
+++ b/src/game/base/planet.h
@@ -1,7 +1,7 @@
/*
base/planet.h
- This file is part of the Osirion project and is distributed under
- the terms and conditions of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
*/
#ifndef __INCLUDED_BASE_PLANET_H__
@@ -13,15 +13,19 @@
#include <string>
-namespace game {
+namespace game
+{
/// a planet
-class Planet : public core::EntityGlobe {
+class Planet : public core::EntityGlobe
+{
public:
Planet();
virtual ~Planet();
- inline ShipDealer *shipdealer() { return planet_shipdealer; }
+ inline ShipDealer *shipdealer() {
+ return planet_shipdealer;
+ }
void set_shipdealer(ShipDealer *shipdealer);
diff --git a/src/game/base/racetrack.cc b/src/game/base/racetrack.cc
index 3d1cb69..51526ea 100644
--- a/src/game/base/racetrack.cc
+++ b/src/game/base/racetrack.cc
@@ -1,7 +1,7 @@
/*
base/racetrack.cc
- This file is part of the Osirion project and is distributed under
- the terms and conditions of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
*/
#include <string>
@@ -11,7 +11,8 @@
#include "base/racetrack.h"
#include "core/gameserver.h"
-namespace game {
+namespace game
+{
/* ---- class CheckPoint ------------------------------------------- */
@@ -31,7 +32,7 @@ CheckPoint::CheckPoint(RaceTrack *parent)
CheckPoint::~CheckPoint()
{
-
+
}
/* ---- class RaceTrack -------------------------------------------- */
@@ -64,7 +65,7 @@ void RaceTrack::reset()
track_player = 0;
track_racestart = 0;
track_checkpointtime = 0;
-
+
for (CheckPoints::iterator cpit = track_checkpoints.begin(); cpit != track_checkpoints.end(); ++cpit) {
(*cpit)->set_state(core::Entity::NoPower);
}
@@ -74,7 +75,7 @@ void RaceTrack::reset()
void RaceTrack::dock(core::Entity *entity)
{
-
+
if (entity->moduletype() != ship_enttype)
return;
Ship * ship = static_cast<Ship *>(entity);
@@ -96,7 +97,7 @@ void RaceTrack::dock(core::Entity *entity)
for (CheckPoints::iterator cpit = track_checkpoints.begin(); cpit != track_checkpoints.end(); ++cpit) {
set_state(core::Entity::Normal);
}
-
+
entity_timer = 5.0f;
std::string message("^B" + track_player->name() + " ^Bactivated the race! Race starts in 5...");
core::server()->broadcast(message);
@@ -163,7 +164,7 @@ void RaceTrack::frame(float seconds)
track_player->set_mission_target((*track_checkpoint));
}
}
-
+
} else {
@@ -192,7 +193,7 @@ void RaceTrack::frame(float seconds)
} else {
std::stringstream msgstr;
- msgstr << "^BRace completed in " << core::server()->time() - track_racestart << " seconds!";
+ msgstr << "^BRace completed in " << core::server()->time() - track_racestart << " seconds!";
core::server()->broadcast(msgstr.str());
// prize money
diff --git a/src/game/base/racetrack.h b/src/game/base/racetrack.h
index 80a5766..ef7375a 100644
--- a/src/game/base/racetrack.h
+++ b/src/game/base/racetrack.h
@@ -1,7 +1,7 @@
/*
base/racetrack.h
- This file is part of the Osirion project and is distributed under
- the terms and conditions of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
*/
#ifndef __INCLUDED_BASE_RACETRACK_H__
@@ -13,14 +13,16 @@
#include <string>
-namespace game {
+namespace game
+{
class CheckPoint;
/* ---- class RaceTrack -------------------------------------------- */
/// a race track entity
-class RaceTrack : public core::EntityDynamic {
+class RaceTrack : public core::EntityDynamic
+{
public:
/// default constructor
@@ -33,7 +35,9 @@ public:
typedef std::list<CheckPoint *> CheckPoints ;
/// the player who activated the race
- inline core::Player *player() { return track_player; }
+ inline core::Player *player() {
+ return track_player;
+ }
/// add a checkpoint to the racetrack
void add_checkpoint(CheckPoint *checkpoint);
@@ -46,20 +50,21 @@ public:
/// run one time frame
virtual void frame(float elapsed);
-
+
private:
CheckPoints track_checkpoints;
core::Player *track_player;
float track_racestart;
float track_checkpointtime;
CheckPoints::iterator track_checkpoint;
-
+
};
/* ---- class CheckPoint ------------------------------------------- */
/// a checkpoint for the race track
-class CheckPoint : public core::EntityDynamic {
+class CheckPoint : public core::EntityDynamic
+{
public:
CheckPoint(RaceTrack *parent);
~CheckPoint();
diff --git a/src/game/base/ship.cc b/src/game/base/ship.cc
index 8bc7799..2c42ca8 100644
--- a/src/game/base/ship.cc
+++ b/src/game/base/ship.cc
@@ -1,7 +1,7 @@
/*
base/ship.cc
- This file is part of the Osirion project and is distributed under
- the terms and conditions of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
*/
#include <cmath>
@@ -19,13 +19,14 @@
using math::degrees360f;
using math::degrees180f;
-namespace game {
+namespace game
+{
const float MIN_DELTA = 0.000001f;
Ship::Ship(core::Player *owner, ShipModel *shipmodel) :
- core::EntityControlable(owner, ship_enttype),
- PhysicsBody(this)
+ core::EntityControlable(owner, ship_enttype),
+ PhysicsBody(this)
{
set_modelname(shipmodel->modelname());
set_name(shipmodel->name());
@@ -41,7 +42,7 @@ Ship::Ship(core::Player *owner, ShipModel *shipmodel) :
ship_shipmodel = shipmodel;
ship_jumpdrive = shipmodel->shipmodel_jumpdrive;
-
+
ship_impulsedrive_timer = 0;
ship_jumpdrive_timer = 0;
ship_jumpdepart = 0;
@@ -49,7 +50,7 @@ Ship::Ship(core::Player *owner, ShipModel *shipmodel) :
reset();
}
-Ship::~Ship()
+Ship::~Ship()
{
shutdown_physics();
}
@@ -71,16 +72,16 @@ void Ship::func_impulse()
} else if (entity_state == core::Entity::ImpulseInitiate) {
entity_state = core::Entity::Normal;
-
+
} else if (entity_state != core::Entity::Normal) {
return;
-
- } else {
+
+ } else {
if (entity_state == core::Entity::JumpInitiate) {
ship_jumpdrive_timer = 0;
entity_timer = 0;
}
-
+
entity_state = core::Entity::ImpulseInitiate;
if (Game::g_devel->value()) {
entity_timer = 0;
@@ -137,12 +138,12 @@ void Ship::func_jump(std::string const &args)
owner()->send("Usage: jump [^B" + helpstr + "^N]");
return;
}
-
+
if (jumptargetzone == zone()) {
owner()->send("Already in the " + jumptargetzone->name());
return;
}
-
+
owner()->send("Jumping to the " + jumptargetzone->name());
set_zone(jumptargetzone);
@@ -188,7 +189,7 @@ JumpPoint * Ship::find_closest_jumppoint()
}
}
}
-
+
if (jumppoint && jumppoint->target()) {
if (Game::g_jumppointrange->value() < d) {
owner()->send("Jumppoint out of range!");
@@ -201,14 +202,14 @@ JumpPoint * Ship::find_closest_jumppoint()
owner()->send("No jumppoints found!");
return 0;
}
-
+
return 0;
}
void Ship::explode()
{
set_state(core::Entity::Destroyed);
-
+
target_thrust = 0;
target_pitch = 0;
target_roll = 0;
@@ -235,7 +236,7 @@ void Ship::set_zone(core::Zone *zone)
init_physics(radius());
}
-void Ship::frame(float seconds)
+void Ship::frame(float seconds)
{
float actual_maxspeed = ship_shipmodel->maxspeed();
float actual_turnspeed = ship_shipmodel->turnspeed();
@@ -247,10 +248,10 @@ void Ship::frame(float seconds)
const float thrust_reaction = 0.5f; // thrust control reaction time factor
const float strafe_reaction = 1.5f;
const float afterburner_reaction = 1.0f; // a fterburner control reaction time
-
+
float cosangle; // cosine of an angle
- float angle; // angle in radians
+ float angle; // angle in radians
math::Vector3f n; // normal of a plane
math::Axis target_axis(axis()); // target axis
#endif
@@ -270,7 +271,7 @@ void Ship::frame(float seconds)
target_direction = 0;
target_afterburner = 0.0f;
target_thrust = 0;
-
+
entity_speed = 0;
entity_thrust = 0;
@@ -289,7 +290,7 @@ void Ship::frame(float seconds)
//entity_location += entity_axis.forward() * radius();
} else {
get_location().assign(ship_jumpdepart->target()->location() + location() - ship_jumpdepart->location());
- }
+ }
set_zone(ship_jumpdepart->target()->zone());
owner()->send("^BJumping to the " + ship_jumpdepart->target()->zone()->name());
} else {
@@ -297,7 +298,7 @@ void Ship::frame(float seconds)
}
ship_jumpdrive_timer = 0;
entity_timer = 0;
-
+
set_dirty();
return;
} else {
@@ -340,12 +341,12 @@ void Ship::frame(float seconds)
if (target_afterburner < 0.0f) {
set_state(core::Entity::Normal);
set_dirty();
- entity_timer = 0;
+ entity_timer = 0;
} else {
if (ship_impulsedrive_timer + 1.0f <= core::server()->time()) {
entity_timer -= 1.0f;
-
+
if (entity_timer <= 0) {
actual_maxspeed = Game::g_impulsespeed->value();
actual_acceleration = Game::g_impulseacceleration->value();
@@ -357,25 +358,23 @@ void Ship::frame(float seconds)
set_dirty();
}
}
-
+
// clamp input values
target_thrust = 0.0f;
math::clamp(target_pitch, -1.0f, 1.0f);
math::clamp(target_roll, -1.0f, 1.0f);
math::clamp(target_direction, -1.0f, 1.0f);
math::clamp(target_afterburner, -1.0f, 1.0f);
-
+
actual_turnspeed *= 0.5;
}
} else if (entity_state == core::Entity::Impulse) {
// clamp input values
- target_thrust = 0.0f;
math::clamp(target_pitch, -1.0f, 1.0f);
math::clamp(target_roll, -1.0f, 1.0f);
math::clamp(target_direction, -1.0f, 1.0f);
- target_afterburner = 0.0f;
// cancel impulse drive if afterburner goes reverse
if (target_afterburner < 0.0f) {
@@ -383,11 +382,13 @@ void Ship::frame(float seconds)
set_dirty();
entity_timer = 0;
target_thrust = 1.0f;
- target_thrust = 1.0f;
- } else {
+ entity_thrust = 1.0f;
+ } else {
actual_maxspeed = Game::g_impulsespeed->value();
actual_acceleration = Game::g_impulseacceleration->value();
actual_turnspeed *= 0.5;
+ target_afterburner = 0.0f;
+ target_thrust = 0.0f;
}
} else if (entity_state == core::Entity::Normal) {
@@ -412,7 +413,7 @@ void Ship::frame(float seconds)
target_direction = 0;
target_afterburner = 0.0f;
target_thrust = 0;
-
+
entity_thrust = 0;
}
@@ -448,7 +449,7 @@ void Ship::frame(float seconds)
if ((entity_state == core::Entity::ImpulseInitiate) || (entity_state == core::Entity::Impulse)) {
actual_thrust = 1.0f;
}
-
+
// update strafe control target
if (current_target_strafe < target_strafe) {
@@ -476,7 +477,7 @@ void Ship::frame(float seconds)
}
math::clamp(current_target_roll, -1.0f, 1.0f);
- if (fabs(current_target_roll) > MIN_DELTA) {
+ if (fabs(current_target_roll) > MIN_DELTA) {
float roll_offset = seconds * current_target_roll;
get_axis().change_roll(actual_turnspeed * roll_offset);
} else {
@@ -496,7 +497,7 @@ void Ship::frame(float seconds)
}
}
- if (fabs(current_target_direction) > MIN_DELTA ) {
+ if (fabs(current_target_direction) > MIN_DELTA) {
math::clamp(current_target_direction, -1.0f, 1.0f);
target_axis.change_direction(actual_turnspeed * current_target_direction);
} else {
@@ -513,7 +514,7 @@ void Ship::frame(float seconds)
if (current_target_pitch < target_pitch)
current_target_pitch = target_pitch;
}
-
+
if (fabs(current_target_pitch) > MIN_DELTA) {
math::clamp(current_target_pitch, -1.0f, 1.0f);
target_axis.change_pitch(actual_turnspeed * current_target_pitch);
@@ -538,7 +539,7 @@ void Ship::frame(float seconds)
if (entity_speed > max) {
entity_speed = max;
}
- } else if(entity_speed > max) {
+ } else if (entity_speed > max) {
entity_speed -= actual_acceleration * seconds;
if (entity_speed < max) {
entity_speed = max;
@@ -584,7 +585,7 @@ void Ship::frame(float seconds)
entity_movement = math::max(entity_movement, fabs(current_target_afterburner));
entity_movement = math::max(entity_movement, fabs(current_target_strafe));
- if ((entity_movement > 0)|| (entity_speed > 0)) {
+ if ((entity_movement > 0) || (entity_speed > 0)) {
set_dirty();
}
}
diff --git a/src/game/base/ship.h b/src/game/base/ship.h
index 21987e7..e1b8b1d 100644
--- a/src/game/base/ship.h
+++ b/src/game/base/ship.h
@@ -1,7 +1,7 @@
/*
base/ship.h
- This file is part of the Osirion project and is distributed under
- the terms and conditions of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
*/
#ifndef __INCLUDED_BASE_SHIP_H__
@@ -14,7 +14,8 @@
#include "base/jumppoint.h"
#include "math/vector3f.h"
-namespace game {
+namespace game
+{
/// A ship in the game, controled by a player
class Ship : public core::EntityControlable, public PhysicsBody
@@ -30,7 +31,9 @@ public:
virtual void set_zone(core::Zone *zone);
/// true if the ship is equiped with a jumpdrive
- inline bool jumpdrive() const { return ship_jumpdrive; }
+ inline bool jumpdrive() const {
+ return ship_jumpdrive;
+ }
/// Initiate jump, departing from a jump point
/** Initiates a jump even if the ship has no jumpdrive
@@ -65,7 +68,7 @@ private:
float ship_impulsedrive_timer;
-
+
JumpPoint *ship_jumpdepart;
};
diff --git a/src/game/base/shipdealer.cc b/src/game/base/shipdealer.cc
index 408ae43..54d3e90 100644
--- a/src/game/base/shipdealer.cc
+++ b/src/game/base/shipdealer.cc
@@ -1,7 +1,7 @@
/*
base/shipdealer.cc
- This file is part of the Osirion project and is distributed under
- the terms and conditions of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
*/
#include "auxiliary/functions.h"
@@ -11,7 +11,8 @@
#include "base/station.h"
#include "sys/sys.h"
-namespace game {
+namespace game
+{
ShipDealer::ShipDealer()
{
@@ -67,7 +68,7 @@ ShipModel *ShipDealer::find(ShipModel *shipmodel) const
void ShipDealer::func_buy(core::Player *player, const std::string &args)
{
core::Entity *dock = player->view();
-
+
ShipDealer *shipdealer = 0;
// find the ship model
@@ -102,7 +103,7 @@ void ShipDealer::func_buy(core::Player *player, const std::string &args)
}
if (!Game::g_devel->value()) {
-
+
if (!shipdealer) {
player->send("No ship dealer available");
return;
@@ -116,7 +117,7 @@ void ShipDealer::func_buy(core::Player *player, const std::string &args)
// check price
if (shipmodel->price() > player->credits()) {
std::stringstream msgstr;
- msgstr << "You require " << (shipmodel->price() - player->credits()) << " additional credits to buy the " << shipmodel->name();
+ msgstr << "You require " << (shipmodel->price() - player->credits()) << " additional credits to buy the " << shipmodel->name();
player->send(msgstr.str());
return;
}
@@ -135,7 +136,7 @@ void ShipDealer::func_buy(core::Player *player, const std::string &args)
ship->get_location().assign(dock->location());
ship->set_state(core::Entity::Docked);
ship->get_axis().assign(dock->axis());
- ship->get_axis().change_direction(180.0f);
+ ship->get_axis().change_direction(180.0f);
player->set_control(ship);
player->set_view(dock);
} else {
@@ -148,9 +149,9 @@ void ShipDealer::func_buy(core::Player *player, const std::string &args)
msgstr << "^BPurchased " << aux::article(shipmodel->name());
if (!Game::g_devel->value()) {
msgstr << " for " << shipmodel->price() << " credits";
- }
+ }
player->send(msgstr.str());
- player->sound("game/buy-ship");
+ player->sound("game/buy-ship");
}
diff --git a/src/game/base/shipdealer.h b/src/game/base/shipdealer.h
index 48f9835..1d93f03 100644
--- a/src/game/base/shipdealer.h
+++ b/src/game/base/shipdealer.h
@@ -1,7 +1,7 @@
/*
base/shipdealer.h
- This file is part of the Osirion project and is distributed under
- the terms and conditions of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
*/
#ifndef __INCLUDED_BASE_SHIPDEALER_H__
@@ -12,29 +12,30 @@
#include "base/shipmodel.h"
#include "core/entity.h"
-namespace game {
+namespace game
+{
class ShipDealer
{
public:
typedef std::list<ShipModel *> Models;
-
+
ShipDealer();
~ShipDealer();
/// add a ship model to the dealer list
ShipModel *add(const std::string &modelname);
-
+
/// find a ship model in the dealer list
ShipModel *find(const std::string &modelname) const;
-
+
/// find a ship model in the dealer list
ShipModel *find(ShipModel *shipmodel) const;
static void func_buy(core::Player *player, const std::string &args);
private:
- Models dealer_models;
+ Models dealer_models;
};
}
diff --git a/src/game/base/shipmodel.cc b/src/game/base/shipmodel.cc
index 9d905d6..6233120 100644
--- a/src/game/base/shipmodel.cc
+++ b/src/game/base/shipmodel.cc
@@ -1,7 +1,7 @@
/*
base/shipmodel.cc
- This file is part of the Osirion project and is distributed under
- the terms and conditions of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
*/
#include <iomanip>
@@ -10,7 +10,8 @@
#include "base/shipmodel.h"
#include "sys/sys.h"
-namespace game {
+namespace game
+{
// the ship model registry
std::map<std::string, ShipModel *> ShipModel::registry;
@@ -35,7 +36,7 @@ ShipModel::~ShipModel()
void ShipModel::clear()
{
for (iterator smit = registry.begin(); smit != registry.end(); smit++) {
- delete (*smit).second;
+ delete(*smit).second;
}
registry.clear();
}
@@ -43,7 +44,7 @@ void ShipModel::clear()
void ShipModel::print()
{
con_print << "label: ^B" << label() << " ^Nname: ^B" << name() << std::endl;
- con_print << " price: ^B" << price() << std::endl;
+ con_print << " price: ^B" << price() << std::endl;
con_print << " acceleration: ^B" << acceleration() << std::endl;
con_print << " turnspeed: ^B" << turnspeed() << std::endl;
con_print << " max speed: ^B" << maxspeed() << std::endl;
@@ -64,33 +65,39 @@ void ShipModel::generate_info(core::Info *info)
info->add_text("");
info->add_text("^BSpecifications:^N");
- std::stringstream str;
+ std::stringstream str;
str << "price: ^B" << price() << " ^Ncredits";
- info->add_text(str.str()); str.str("");
+ info->add_text(str.str());
+ str.str("");
str << "cargo hold: ^B" << 0.1f * maxcargo() << " ^Nmetric tonnes";
- info->add_text(str.str()); str.str("");
+ info->add_text(str.str());
+ str.str("");
str << "top speed: ^B" << 100.0f * maxspeed() << " ^Nmps";
- info->add_text(str.str()); str.str("");
+ info->add_text(str.str());
+ str.str("");
str << "response: ^B" << turnspeed() << " ^Ndps";
- info->add_text(str.str()); str.str("");
+ info->add_text(str.str());
+ str.str("");
str << "acceleration: ^B" << acceleration() << " ^Nstandard";
- info->add_text(str.str()); str.str("");
+ info->add_text(str.str());
+ str.str("");
- if(shipmodel_jumpdrive) {
+ if (shipmodel_jumpdrive) {
str << "hyperspace jump drive capable";
- info->add_text(str.str()); str.str("");
+ info->add_text(str.str());
+ str.str("");
}
}
void ShipModel::list()
{
for (iterator smit = registry.begin(); smit != registry.end(); smit++) {
- con_print << std::setw(24) << (*smit).second->label()
- << " ^B" << (*smit).second->name() << "\n";
+ con_print << std::setw(24) << (*smit).second->label()
+ << " ^B" << (*smit).second->name() << "\n";
}
con_print << registry.size() << " registered ship models\n";
}
@@ -132,12 +139,12 @@ ShipModel *ShipModel::search(const std::string searchname)
for (iterator smit = registry.begin(); smit != registry.end(); smit++) {
ShipModel *shipmodel = (*smit).second;
-
+
label.assign(shipmodel->label());
if (label.size() && (label.find(strsearchkey) != std::string::npos)) {
return shipmodel;
}
-
+
name.assign(aux::lowercase(shipmodel->name()));
if (name.size() && (name.find(strsearchkey) != std::string::npos)) {
return shipmodel;
@@ -155,7 +162,7 @@ void ShipModel::add(ShipModel *shipmodel)
con_warn << "Duplicate ship model " << shipmodel->label() << "!\n";
delete m;
}
-
+
registry[shipmodel->label()] = shipmodel;
}
diff --git a/src/game/base/shipmodel.h b/src/game/base/shipmodel.h
index 9bdf4f5..0cfe87e 100644
--- a/src/game/base/shipmodel.h
+++ b/src/game/base/shipmodel.h
@@ -1,7 +1,7 @@
/*
base/shipmodel.h
- This file is part of the Osirion project and is distributed under
- the terms and conditions of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
*/
#ifndef __INCLUDED_BASE_SHIPMODEL_H__
@@ -12,7 +12,8 @@
#include "core/info.h"
-namespace game {
+namespace game
+{
/// ship model specifications
class ShipModel
@@ -24,43 +25,69 @@ public:
void print();
/// acceleration
- inline const float acceleration() const { return shipmodel_acceleration; }
+ inline const float acceleration() const {
+ return shipmodel_acceleration;
+ }
/// maximum speed
- inline const float maxspeed() const { return shipmodel_maxspeed; }
-
+ inline const float maxspeed() const {
+ return shipmodel_maxspeed;
+ }
+
/// turn speed in rotations per second
- inline const float turnspeed() const { return shipmodel_turnspeed; }
+ inline const float turnspeed() const {
+ return shipmodel_turnspeed;
+ }
/// label of the ship model
- inline const std::string &label() const { return shipmodel_label; }
+ inline const std::string &label() const {
+ return shipmodel_label;
+ }
/// name of the ship model
- inline const std::string & name() const { return shipmodel_name; }
+ inline const std::string & name() const {
+ return shipmodel_name;
+ }
/// name of the model of the ship
- inline const std::string & modelname() const { return shipmodel_modelname; }
+ inline const std::string & modelname() const {
+ return shipmodel_modelname;
+ }
/// price of the ship
- inline const long price() const { return shipmodel_price; }
+ inline const long price() const {
+ return shipmodel_price;
+ }
/// size of the cargo hold
- inline const float maxcargo() const { return shipmodel_maxcargo; }
+ inline const float maxcargo() const {
+ return shipmodel_maxcargo;
+ }
/// set acceleration
- inline void set_acceleration(const float acceleration) { shipmodel_acceleration = acceleration; }
+ inline void set_acceleration(const float acceleration) {
+ shipmodel_acceleration = acceleration;
+ }
/// set maximum speed
- inline void set_maxspeed(const float maxspeed) { shipmodel_maxspeed = maxspeed; }
+ inline void set_maxspeed(const float maxspeed) {
+ shipmodel_maxspeed = maxspeed;
+ }
/// set turn speed
- inline void set_turnspeed(const float turnspeed) { shipmodel_turnspeed = turnspeed; }
+ inline void set_turnspeed(const float turnspeed) {
+ shipmodel_turnspeed = turnspeed;
+ }
/// set price
- inline void set_price(const long price) { shipmodel_price = price; }
+ inline void set_price(const long price) {
+ shipmodel_price = price;
+ }
/// set size of the cargo hold
- inline void set_maxcargo(const float maxcargo) { shipmodel_maxcargo = maxcargo; }
+ inline void set_maxcargo(const float maxcargo) {
+ shipmodel_maxcargo = maxcargo;
+ }
/// generate an info object for this shipmodel
void generate_info(core::Info *info);
@@ -108,7 +135,7 @@ private:
float shipmodel_maxcargo;
long shipmodel_price;
-
+
};
}
diff --git a/src/game/base/star.cc b/src/game/base/star.cc
index ba3ccba..43efd0c 100644
--- a/src/game/base/star.cc
+++ b/src/game/base/star.cc
@@ -8,7 +8,8 @@
#include "base/star.h"
-namespace game {
+namespace game
+{
Star::Star() : core::EntityGlobe(core::Entity::Static | core::Entity::Solid | core::Entity::Bright)
{
diff --git a/src/game/base/star.h b/src/game/base/star.h
index 5283894..12bec07 100644
--- a/src/game/base/star.h
+++ b/src/game/base/star.h
@@ -1,7 +1,7 @@
/*
base/star.h
- This file is part of the Osirion project and is distributed under
- the terms and conditions of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
*/
#ifndef __INCLUDED_BASE_STAR_H__
@@ -14,10 +14,12 @@
// C++ headers
#include <string>
-namespace game {
+namespace game
+{
/// a star, that shines so bright
-class Star : public core::EntityGlobe {
+class Star : public core::EntityGlobe
+{
public:
Star();
~Star();
diff --git a/src/game/base/station.cc b/src/game/base/station.cc
index 0552269..fb548bb 100644
--- a/src/game/base/station.cc
+++ b/src/game/base/station.cc
@@ -1,14 +1,15 @@
/*
base/station.cc
- This file is part of the Osirion project and is distributed under
- the terms and conditions of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
*/
#include "base/game.h"
#include "base/station.h"
#include "sys/sys.h"
-namespace game {
+namespace game
+{
Station::Station() : Entity(), PhysicsBody(this)
{
@@ -51,7 +52,7 @@ void Station::dock(core::Entity *entity)
ship->get_location().assign(entity->location());
ship->set_state(core::Entity::Docked);
- if (ship->owner() && ship->owner()->control() == ship) {
+ if (ship->owner() && ship->owner()->control() == ship) {
ship->owner()->set_view(this);
ship->owner()->send("^BDocking at " + name());
}
diff --git a/src/game/base/station.h b/src/game/base/station.h
index ae4d0f4..ad627dd 100644
--- a/src/game/base/station.h
+++ b/src/game/base/station.h
@@ -1,7 +1,7 @@
/*
base/station.h
- This file is part of the Osirion project and is distributed under
- the terms and conditions of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
*/
#ifndef __INCLUDED_BASE_STATION_H__
@@ -10,7 +10,8 @@
#include "base/shipdealer.h"
#include "base/physics.h"
-namespace game {
+namespace game
+{
class Station : public core::Entity, public PhysicsBody
{
@@ -18,7 +19,9 @@ public:
Station();
virtual ~Station();
- inline ShipDealer *shipdealer() { return station_shipdealer; }
+ inline ShipDealer *shipdealer() {
+ return station_shipdealer;
+ }
void set_shipdealer(ShipDealer *shipdealer);
diff --git a/src/game/example/example.cc b/src/game/example/example.cc
index f368556..a6372da 100644
--- a/src/game/example/example.cc
+++ b/src/game/example/example.cc
@@ -1,14 +1,15 @@
/*
intro/intro.cc
- This file is part of the Osirion project and is distributed under
- the terms of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
*/
#include "core/gameserver.h"
#include "example/example.h"
#include "example/spectator.h"
-namespace example {
+namespace example
+{
core::Module *factory()
{
@@ -47,7 +48,7 @@ Example::Example() : core::Module("The Osirion Project Example", true)
cube->get_color().assign(1, 0, 0); // set RGB color red
cube->set_radius(0.25f); // set radius, in game units
cube->set_zone(zone); // add the entity to the zone
-
+
core::Entity *sphere = new core::Entity(); // a new entity
sphere->set_label("sphere");
sphere->set_name("The Green Sphere");
diff --git a/src/game/example/example.h b/src/game/example/example.h
index 64e9e4d..f6d6ff6 100644
--- a/src/game/example/example.h
+++ b/src/game/example/example.h
@@ -1,7 +1,7 @@
/*
intro/example.h
- This file is part of the Osirion project and is distributed under
- the terms of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
*/
#ifndef __INCLUDED_EXAMPLE_H__
diff --git a/src/game/example/spectator.cc b/src/game/example/spectator.cc
index 5fad0f1..93c6fdd 100644
--- a/src/game/example/spectator.cc
+++ b/src/game/example/spectator.cc
@@ -1,12 +1,13 @@
/*
base/spectator.cc
- This file is part of the Osirion project and is distributed under
- the terms and conditions of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
*/
#include "example/spectator.h"
-namespace example {
+namespace example
+{
core::Cvar *Spectator::g_spectatorspeed = 0;
core::Cvar *Spectator::g_spectatorrotation = 0;
@@ -43,7 +44,7 @@ void Spectator::frame(float elapsed)
get_axis().change_direction(target_direction * rotation);
get_axis().change_pitch(target_pitch * rotation);
get_axis().change_roll(target_roll * rotation);
-
+
// assign speed from thruster
float maxspeed = g_spectatorspeed->value();
entity_speed = entity_thrust * maxspeed;
diff --git a/src/game/example/spectator.h b/src/game/example/spectator.h
index 435c45c..57f223b 100644
--- a/src/game/example/spectator.h
+++ b/src/game/example/spectator.h
@@ -1,7 +1,7 @@
/*
base/spectator.h
- This file is part of the Osirion project and is distributed under
- the terms and conditions of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
*/
#ifndef __INCLUDED_EXAMPLE_SPECTATOR_H__
@@ -10,7 +10,8 @@
#include "core/entity.h"
#include "core/cvar.h"
-namespace example {
+namespace example
+{
/// A spectator entity
class Spectator : public core::EntityControlable
diff --git a/src/game/game.cc b/src/game/game.cc
index 719611c..2a9ddad 100644
--- a/src/game/game.cc
+++ b/src/game/game.cc
@@ -16,7 +16,7 @@
void register_modules(bool register_noninteractive_modules)
{
con_print << "^BRegistering game modules..." << std::endl;
-
+
// non-interactive modules
core::Loader::add("base", game::factory);
core::Loader::add("example", example::factory);
diff --git a/src/game/game.h b/src/game/game.h
index 027a125..a3121bc 100644
--- a/src/game/game.h
+++ b/src/game/game.h
@@ -1,13 +1,13 @@
/*
game/game.h
- This file is part of the Osirion project and is distributed under
- the terms of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
*/
#ifndef __INCLUDED_GAME_H__
#define __INCLUDED_GAME_H__
-void register_modules(bool register_noninteractive_modules=false);
+void register_modules(bool register_noninteractive_modules = false);
#endif // __INCLUDED_GAME_H__
diff --git a/src/game/intro/convoy.cc b/src/game/intro/convoy.cc
index ac52c38..4a21071 100644
--- a/src/game/intro/convoy.cc
+++ b/src/game/intro/convoy.cc
@@ -1,12 +1,13 @@
/*
intro/convoy.h
- This file is part of the Osirion project and is distributed under
- the terms of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
*/
#include "intro/convoy.h"
-namespace intro {
+namespace intro
+{
/* ---- class Member ----------------------------------------------- */
@@ -34,10 +35,10 @@ void Member::frame(float seconds)
Convoy::Convoy(core::Zone *zone) : core::EntityDynamic()
{
- set_zone(zone);
+ set_zone(zone);
set_label("convoy");
set_name("Convoy");
-
+
entity_speed = 1.0f;
set_serverside();
}
@@ -68,20 +69,20 @@ void Convoy::add(const std::string &model)
member->get_location().assign(location());
d = ((float) convoy_members.size()) * 0.5f;
- member->get_location().get_x() += math::randomf((float) convoy_members.size()) -d;
- member->get_location().get_y() += math::randomf((float) convoy_members.size()) -d;
- member->get_location().get_z() += (math::randomf((float) convoy_members.size()) -d) * 0.5f;
+ member->get_location().get_x() += math::randomf((float) convoy_members.size()) - d;
+ member->get_location().get_y() += math::randomf((float) convoy_members.size()) - d;
+ member->get_location().get_z() += (math::randomf((float) convoy_members.size()) - d) * 0.5f;
member->get_axis().assign(axis());
}
void Convoy::frame(float seconds)
{
- for (Members::iterator it = convoy_members.begin(); it != convoy_members.end(); ) {
+ for (Members::iterator it = convoy_members.begin(); it != convoy_members.end();) {
Member *member = (*it);
if (member->location().length() > 64.0f) {
std::string model(member->model()->name());
- member->die();
+ member->die();
convoy_members.erase(it++);
add(model);
} else {
diff --git a/src/game/intro/convoy.h b/src/game/intro/convoy.h
index 2002164..64204a0 100644
--- a/src/game/intro/convoy.h
+++ b/src/game/intro/convoy.h
@@ -1,7 +1,7 @@
/*
intro/convoy.h
- This file is part of the Osirion project and is distributed under
- the terms of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
*/
#ifndef __INCLUDED_INTRO_CONVOY_H__
@@ -12,7 +12,8 @@
#include "core/entity.h"
#include "math/color.h"
-namespace intro {
+namespace intro
+{
/* ---- class Member ----------------------------------------------- */
diff --git a/src/game/intro/intro.cc b/src/game/intro/intro.cc
index 05dcec7..f2da493 100644
--- a/src/game/intro/intro.cc
+++ b/src/game/intro/intro.cc
@@ -1,7 +1,7 @@
/*
intro/intro.cc
- This file is part of the Osirion project and is distributed under
- the terms of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
*/
#include "intro/intro.h"
@@ -12,7 +12,8 @@
#include "math/color.h"
#include "sys/sys.h"
-namespace intro {
+namespace intro
+{
core::Module *factory()
{
@@ -53,7 +54,7 @@ bool Intro::load_world()
math::Vector3f v;
float f;
bool b;
-
+
while (ini.getline()) {
if (ini.got_section()) {
@@ -63,18 +64,18 @@ bool Intro::load_world()
zone->set_name("Introduction");
zone->set_sky("sky");
core::Zone::add(zone);
-
+
} else if (ini.got_section("convoy")) {
if (zone) {
convoy = new Convoy(zone);
}
-
+
} else if (ini.got_section("globe")) {
if (zone) {
globe = new core::EntityGlobe();
globe->set_zone(zone);
}
-
+
} else {
ini.unknown_section();
}
@@ -84,7 +85,7 @@ bool Intro::load_world()
if (ini.got_key_string("label", strval)) {
zone->set_label(strval);
-
+
} else if (ini.got_key_string("sky", strval)) {
zone->set_sky(strval);
@@ -128,7 +129,9 @@ bool Intro::load_world()
} else if (ini.got_key_float("rotationspeed", globe->entity_rotationspeed)) {
continue;
} else if (ini.got_key_bool("bright", b)) {
- if (b) { globe->set_flag(core::Entity::Bright); }
+ if (b) {
+ globe->set_flag(core::Entity::Bright);
+ }
} else if (ini.got_key()) {
ini.unkown_key();
}
diff --git a/src/game/intro/intro.h b/src/game/intro/intro.h
index d6d8393..7f2e58c 100644
--- a/src/game/intro/intro.h
+++ b/src/game/intro/intro.h
@@ -1,7 +1,7 @@
/*
intro/intro.h
- This file is part of the Osirion project and is distributed under
- the terms of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
*/
#ifndef __INCLUDED_INTRO_H__
diff --git a/src/math/axis.cc b/src/math/axis.cc
index 31ba26a..402b2f6 100644
--- a/src/math/axis.cc
+++ b/src/math/axis.cc
@@ -30,7 +30,7 @@ void Axis::clear()
void Axis::assign(const Axis & other)
{
- for (size_t i=0; i < 3; i++) {
+ for (size_t i = 0; i < 3; i++) {
axis_vector[i].assign(other.axis_vector[i]);
}
}
@@ -46,10 +46,10 @@ void Axis::change_direction(const float angle)
{
float cosa = cosf(angle * M_PI / 180.0f);
float sina = sinf(angle * M_PI / 180.0f);
-
+
Vector3f forward = axis_vector[0] * cosa + axis_vector[1] * sina;
- Vector3f left = axis_vector[1] *cosa - axis_vector[0] * sina;
-
+ Vector3f left = axis_vector[1] * cosa - axis_vector[0] * sina;
+
axis_vector[0].assign(forward);
axis_vector[1].assign(left);
}
@@ -59,10 +59,10 @@ void Axis::change_pitch(const float angle)
{
float cosa = cosf(angle * M_PI / 180.0f);
float sina = sinf(angle * M_PI / 180.0f);
-
+
Vector3f forward = axis_vector[0] * cosa + axis_vector[2] * sina;
Vector3f up = axis_vector[2] * cosa - axis_vector[0] * sina;
-
+
axis_vector[0].assign(forward);
axis_vector[2].assign(up);
}
@@ -72,10 +72,10 @@ void Axis::change_roll(const float angle)
{
float cosa = cosf(angle * M_PI / 180.0f);
float sina = sinf(angle * M_PI / 180.0f);
-
+
Vector3f forward = axis_vector[2] * cosa + axis_vector[1] * sina;
Vector3f up = axis_vector[1] * cosa - axis_vector[2] * sina;
-
+
axis_vector[2].assign(forward);
axis_vector[1].assign(up);
}
@@ -88,19 +88,19 @@ void Axis::rotate(Vector3f const &normal, float angle)
{
float cosa = cosf(angle);
float sina = sinf(angle);
-
- for (size_t i =0; i < 3; i++) {
+
+ for (size_t i = 0; i < 3; i++) {
axis_vector[i] =
- axis_vector[i]*cosa +
+ axis_vector[i] * cosa +
normal * dotproduct(normal, axis_vector[i]) * (1 - cosa) +
- crossproduct(axis_vector[i], normal)*sina;
+ crossproduct(axis_vector[i], normal) * sina;
}
}
const Axis Axis::transpose() const
{
Axis t;
-
+
for (size_t i = 0; i < 3; i++)
for (size_t j = 0; j < 3; j++)
t.axis_vector[i][j] = axis_vector[j][i];
diff --git a/src/math/axis.h b/src/math/axis.h
index 5f532c8..0ece016 100644
--- a/src/math/axis.h
+++ b/src/math/axis.h
@@ -20,53 +20,53 @@ class Axis
public:
Axis();
Axis(const Axis & other);
-
+
void clear();
-
+
void assign(const Axis & other);
-
+
/// global coordinates of the X-axis in the local coordinates system
inline const Vector3f & forward() const {
return axis_vector[0];
}
-
+
/// global coordinates of the Y-axis in the local coordinates system
inline const Vector3f & left() const {
return axis_vector[1];
}
-
+
/// global coordinates of the Z-axis in the local coordinates system
inline const Vector3f & up() const {
return axis_vector[2];
}
-
+
inline Vector3f & operator[](size_t index) {
return axis_vector[index];
}
-
+
inline const Vector3f & operator[](size_t index) const {
return axis_vector[index];
}
-
+
Axis & operator=(const Axis & other);
const Axis operator*(const Axis &other) const;
-
+
/// change direction, rotate around up vector (positive is left)
void change_direction(const float angle);
-
+
/// change pitch, rotate around left vector (positive is up)
void change_pitch(const float angle);
-
+
/// change roll, rotate around forward vector (positive is left)
void change_roll(const float angle);
-
+
/// rotation about an arbitrary axis
void rotate(const Vector3f & normal, const float angle);
-
+
/// return the transpose of this matrix
const Axis transpose() const;
-
+
private:
Vector3f axis_vector[3];
};
diff --git a/src/math/color.cc b/src/math/color.cc
index ff4cb5d..b807b96 100644
--- a/src/math/color.cc
+++ b/src/math/color.cc
@@ -75,21 +75,21 @@ const Color & Color::operator=(Color const & other)
void Color::clamp()
{
- for (int i =0; i < 4; i++)
+ for (int i = 0; i < 4; i++)
if (rgba_data[i] < 0)
rgba_data[i] = 0;
-
+
float tmp = rgba_data[0];
if (rgba_data[1] > tmp)
tmp = rgba_data[1];
if (rgba_data[2] > tmp)
tmp = rgba_data[2];
-
+
if (tmp > 1) {
- for (int i =0; i < 3; i++)
+ for (int i = 0; i < 3; i++)
rgba_data[i] /= tmp;
}
-
+
if (rgba_data[3] > 1)
rgba_data[3] = 1;
}
@@ -126,7 +126,7 @@ Color const operator*(float scalar, Color const & color)
Color & Color::operator*=(const float scalar)
{
- for (int i=0; i < 3; i++)
+ for (int i = 0; i < 3; i++)
rgba_data[i] *= scalar;
return (*this);
}
diff --git a/src/math/color.h b/src/math/color.h
index 762ac94..8996af2 100644
--- a/src/math/color.h
+++ b/src/math/color.h
@@ -19,12 +19,12 @@ public:
/// create the default color, white
Color();
/// create a color from float RGBA value
- Color(float red, float green, float blue, float alpha=1.0f);
+ Color(float red, float green, float blue, float alpha = 1.0f);
/// create a greyscale color
- Color(const float grey, const float=1.0f);
+ Color(const float grey, const float = 1.0f);
/// create a copy from an existing color
Color(Color const & other);
-
+
/// red channel value
float red() const;
/// green channel value
@@ -33,22 +33,22 @@ public:
float blue() const;
/// alpha channel value
float alpha() const;
-
+
/// assignment
void assign(Color const & other);
/// assignment
- void assign(float red, float green, float blue, float alpha=1.0f);
+ void assign(float red, float green, float blue, float alpha = 1.0f);
/// assignment
- void assign(float grey, float alpha=1.0f);
+ void assign(float grey, float alpha = 1.0f);
/// assignment operator
Color const &operator=(Color const & other);
-
+
/// multiply rgb values with scalar value.
Color operator*(const float scalar) const;
-
+
/// multiply rgb values with scalar value.
Color & operator*=(const float scalar);
-
+
/// assign a value to an element of this color
/*! WARNING: range is not checked
* @param index the index of the element to assign to ( 0 <= index < 4 )
@@ -56,7 +56,7 @@ public:
inline float& operator[](const size_t index) {
return rgba_data[index];
}
-
+
/// returns the value of an element of this color
/*! WARNING: range is not checked
* @param index the index of the element to return ( 0 <= index < 4 )
@@ -64,22 +64,22 @@ public:
inline float operator[](const size_t index) const {
return rgba_data[index];
}
-
-
+
+
/// pointer to the internal data
inline float *ptr() const {
return (float *) rgba_data;
}
-
+
/// clamp color values to the 0-1 range
void clamp();
-
+
float &r;
float &g;
float &b;
float &a;
-
-
+
+
private:
float rgba_data[4];
};
diff --git a/src/math/functions.cc b/src/math/functions.cc
index bb4e9bf..c4b832c 100644
--- a/src/math/functions.cc
+++ b/src/math/functions.cc
@@ -68,7 +68,7 @@ float sgnf(float value)
return -1;
else if (value == 0)
return 0;
-
+
return 1;
}
diff --git a/src/math/functions.h b/src/math/functions.h
index ed013ab..c301969 100644
--- a/src/math/functions.h
+++ b/src/math/functions.h
@@ -49,7 +49,7 @@ float degrees180f(float angle);
float degrees360f(float angle);
/// clamp a float to a specified range
-inline void clamp(float &value, const float min=0.0f, const float max=1.0f)
+inline void clamp(float &value, const float min = 0.0f, const float max = 1.0f)
{
if (value < min)
value = min;
diff --git a/src/math/matrix4f.cc b/src/math/matrix4f.cc
index 371d666..b7953e9 100644
--- a/src/math/matrix4f.cc
+++ b/src/math/matrix4f.cc
@@ -36,7 +36,7 @@ void Matrix4f::clear()
void Matrix4f::unity()
{
memset(matrix, 0, sizeof(matrix));
- for (int i=0; i <4; i++)
+ for (int i = 0; i < 4; i++)
matrix[i][i] = 1;
}
@@ -48,7 +48,7 @@ void Matrix4f::assign(const Matrix4f & other)
void Matrix4f::assign(const Axis & axis)
{
memset(matrix, 0, sizeof(matrix));
- for (int i=0; i < 3; i++) {
+ for (int i = 0; i < 3; i++) {
memcpy(&matrix[i][0], axis[i].ptr(), sizeof(float) * 3);
}
matrix[3][3] = 1;
@@ -69,7 +69,7 @@ Matrix4f & Matrix4f::operator=(const Axis & axis)
Matrix4f const Matrix4f::transpose()
{
Matrix4f t;
-
+
for (size_t i = 0; i < 4; i++)
for (size_t j = 0; j < 4; j++)
t.matrix[j][i] = matrix[i][j];
diff --git a/src/math/matrix4f.h b/src/math/matrix4f.h
index e69ae05..4148870 100644
--- a/src/math/matrix4f.h
+++ b/src/math/matrix4f.h
@@ -21,33 +21,33 @@ public:
Matrix4f();
Matrix4f(const Matrix4f & other);
Matrix4f(const Axis & axis);
-
+
/// set all values to zero
void clear();
-
+
/// set the value to a 4x4 unity matrix
void unity();
-
+
/// assignment operator
void assign(const Matrix4f & other);
-
+
/// assignment operator
inline Matrix4f & operator=(const Matrix4f &other);
-
+
/// assign the matrix transformation equivalent to the coordinate system
void assign(const Axis & axis);
-
+
/// assign the matrix transformation equivalent to the coordinate system
Matrix4f & operator=(const Axis & axis);
-
+
/// return a pointer to the internal data
inline float * ptr() const {
return (float *) matrix;
}
-
+
/// return the transpose matrix
Matrix4f const transpose();
-
+
private:
float matrix[4][4];
};
diff --git a/src/math/vector2f.cc b/src/math/vector2f.cc
index 65f1f93..878304f 100644
--- a/src/math/vector2f.cc
+++ b/src/math/vector2f.cc
@@ -17,7 +17,7 @@ Vector2f::Vector2f()
clear();
}
-Vector2f::Vector2f(const Vector2f &other)
+Vector2f::Vector2f(const Vector2f &other)
{
assign(other);
}
@@ -66,17 +66,17 @@ Vector2f &Vector2f::operator-=(const Vector2f &other)
float distance(const Vector2f& first, const Vector2f& second)
{
float r = 0;
- for (int i=0; i < 2; i++)
- r += (first[i]-second[i])*(first[i]-second[i]);
-
+ for (int i = 0; i < 2; i++)
+ r += (first[i] - second[i]) * (first[i] - second[i]);
+
return (sqrtf(r));
}
float distancesquared(const Vector2f& first, const Vector2f& second)
{
float r = 0;
- for (int i=0; i < 2; i++)
- r += (first[i]-second[i])*(first[i]-second[i]);
+ for (int i = 0; i < 2; i++)
+ r += (first[i] - second[i]) * (first[i] - second[i]);
return (r);
}
diff --git a/src/math/vector2f.h b/src/math/vector2f.h
index ba60aa1..1a5f4de 100644
--- a/src/math/vector2f.h
+++ b/src/math/vector2f.h
@@ -19,96 +19,104 @@ class Vector2f
public:
/// default constructor
Vector2f();
-
+
/// assignment constructor
Vector2f(const float x, const float y);
-
+
/// copy constructor
Vector2f(const Vector2f &other);
-
+
/// assign (0,0)
void clear();
-
+
/// assignment operator
void assign(const float x, const float y);
-
+
/// assignment operator
void assign(const Vector2f &other);
-
+
/// assignment operator
Vector2f & operator=(const Vector2f &other);
-
+
/// vector subtraction
Vector2f & operator-=(const Vector2f &other);
-
+
/// vector sum
Vector2f & operator+=(const Vector2f &other);
-
+
/// vector subtraction
inline Vector2f operator+(const Vector2f &other) const {
- Vector2f v(coord[0] + other.coord[0], coord[1]+other.coord[1]);
+ Vector2f v(coord[0] + other.coord[0], coord[1] + other.coord[1]);
return v;
}
-
+
/// vector sum
inline Vector2f operator-(const Vector2f &other) const {
Vector2f v(coord[0] - other.coord[0], coord[1] - other.coord[1]);
return v;
}
-
+
/// scalar product
inline Vector2f operator*(const float scalar) const {
Vector2f v(coord[0]*scalar, coord[1]*scalar);
return v;
}
-
+
/// scalar division
inline Vector2f operator/(const float scalar) const {
- Vector2f v(coord[0]/scalar, coord[1]/scalar);
+ Vector2f v(coord[0] / scalar, coord[1] / scalar);
return v;
}
-
+
/// array operator
inline float& operator[](const size_t index) {
return coord[index];
}
-
+
/// array operator
inline float operator[](const size_t index) const {
return coord[index];
}
-
+
/// x coordinate
inline float width() const {
return coord[0];
}
-
+
/// y coordinate
inline float height() const {
return coord[1];
}
/// x coordinate
- inline float x() const { return coord[0]; }
-
+ inline float x() const {
+ return coord[0];
+ }
+
/// y coordinate
- inline float y() const { return coord[1]; }
+ inline float y() const {
+ return coord[1];
+ }
/// mutable reference to the x coordinate
- inline float & get_x() { return coord[0]; }
+ inline float & get_x() {
+ return coord[0];
+ }
/// mutable reference to the y coordinate
- inline float & get_y() { return coord[1]; }
-
+ inline float & get_y() {
+ return coord[1];
+ }
+
/// a pointer to the internal data
inline float *ptr() const {
return (float *) coord;
}
-
+
inline bool contains(const Vector2f &other) const {
return ((other.coord[0] >= 0) && (other.coord[1] >= 0) && (other.coord[0] <= coord[0]) && (other.coord[1] <= coord[1]));
}
-
+
inline bool contains(float x, float y) const {
return ((x >= 0) && (y >= 0) && (x <= coord[0]) && (y <= coord[1]));
}
diff --git a/src/math/vector3f.cc b/src/math/vector3f.cc
index 1e9fd2b..4594665 100644
--- a/src/math/vector3f.cc
+++ b/src/math/vector3f.cc
@@ -56,35 +56,35 @@ Vector3f & Vector3f::operator=(const Vector3f & other)
Vector3f & Vector3f::operator*=(const float scalar)
{
- for (int i=0; i < 3; i++)
+ for (int i = 0; i < 3; i++)
coord[i] *= scalar;
return (*this);
}
Vector3f & Vector3f::operator/=(const float scalar)
{
- for (int i=0; i < 3; i++)
+ for (int i = 0; i < 3; i++)
coord[i] /= scalar;
return (*this);
}
Vector3f &Vector3f::operator-=(const Vector3f & other)
{
- for (int i=0; i < 3; i++)
+ for (int i = 0; i < 3; i++)
coord[i] -= other[i];
return (*this);
}
Vector3f &Vector3f::operator+=(const Vector3f &other)
{
- for (int i=0; i < 3; i++)
+ for (int i = 0; i < 3; i++)
coord[i] += other[i];
return (*this);
}
bool Vector3f::operator==(const Vector3f& other) const
{
- for (int i=0; i < 3; i++)
+ for (int i = 0; i < 3; i++)
if (coord[i] != other.coord[i])
return (false);
return (true);
@@ -93,17 +93,17 @@ bool Vector3f::operator==(const Vector3f& other) const
float Vector3f::lengthsquared() const
{
float r = 0;
- for (int i=0; i < 3; i++)
- r += coord[i]*coord[i];
+ for (int i = 0; i < 3; i++)
+ r += coord[i] * coord[i];
return ((float) r);
}
float Vector3f::length() const
{
float r = 0;
- for (int i=0; i < 3; i++)
- r += coord[i]*coord[i];
-
+ for (int i = 0; i < 3; i++)
+ r += coord[i] * coord[i];
+
return (sqrtf(r));
}
@@ -125,24 +125,24 @@ std::ostream &operator<<(std::ostream & os, const Vector3f & vector)
std::istream &operator>>(std::istream & is, Vector3f & vector)
{
- for (int i=0; i < 3; i++)
+ for (int i = 0; i < 3; i++)
is >> vector[i];
return is;
}
-const Vector3f crossproduct(const Vector3f & first, Vector3f const &second)
+const Vector3f crossproduct(const Vector3f & first, const Vector3f &second)
{
- float vx = first[1]*second[2] - first[2]*second[1];
- float vy = first[2]*second[0] - first[0]*second[2];
- float vz = first[0]*second[1] - first[1]*second[0];
-
- return(Vector3f(vx,vy,vz));
+ float vx = first[1] * second[2] - first[2] * second[1];
+ float vy = first[2] * second[0] - first[0] * second[2];
+ float vz = first[0] * second[1] - first[1] * second[0];
+
+ return(Vector3f(vx, vy, vz));
}
float dotproduct(const Vector3f& first, const Vector3f& second)
{
float r = 0;
- for (int i=0; i < 3; i++)
+ for (int i = 0; i < 3; i++)
r += first[i] * second[i];
return (r);
}
@@ -150,17 +150,17 @@ float dotproduct(const Vector3f& first, const Vector3f& second)
float distance(const Vector3f& first, const Vector3f& second)
{
float r = 0;
- for (int i=0; i < 3; i++)
- r += (first[i]-second[i])*(first[i]-second[i]);
-
+ for (int i = 0; i < 3; i++)
+ r += (first[i] - second[i]) * (first[i] - second[i]);
+
return (sqrtf(r));
}
float distancesquared(const Vector3f& first, const Vector3f& second)
{
float r = 0;
- for (int i=0; i < 3; i++)
- r += (first[i]-second[i])*(first[i]-second[i]);
+ for (int i = 0; i < 3; i++)
+ r += (first[i] - second[i]) * (first[i] - second[i]);
return (r);
}
diff --git a/src/math/vector3f.h b/src/math/vector3f.h
index 99a665f..09e6e84 100644
--- a/src/math/vector3f.h
+++ b/src/math/vector3f.h
@@ -23,81 +23,81 @@ class Vector3f
public:
/// default constructor, assigns (0,0,0)
Vector3f();
-
+
/// copy constructor
/** Create a new Vector3f that is a copy from an other
* @param other the vector to copy values from
*/
Vector3f(const Vector3f &other);
-
+
/// create a Vector3f with given coordinates
/** @param x the x-coordinate of the location
* @param y the y-coordinate of the location
* @param z the z-coordinate of the location
*/
Vector3f(const float x, const float y, const float z);
-
+
/// destructor
~Vector3f();
-
+
/* -- Assignment operators -- */
/// assign (0, 0, 0)
void clear();
-
+
/// assignment
void assign(const float x, const float y, const float z);
-
+
/// assignment
void assign(const Vector3f & other);
-
+
/// assignment operator
Vector3f& operator=(const Vector3f &other);
-
+
/// scalar multiplication assignment
/** @param scalar multiplication factor
*/
Vector3f& operator*=(const float scalar);
-
+
/// scalar division assignment
/** @param scalar divider
*/
Vector3f& operator/=(const float scalar);
-
+
/// vector sum assignment
Vector3f& operator+=(const Vector3f &other);
-
+
/// vector difference assignment
Vector3f& operator-=(const Vector3f &other);
-
+
/* -- Mathematical operators -- */
-
+
/// scalar multiplication
inline Vector3f operator*(const float scalar) const {
Vector3f v(coord[0] * scalar, coord[1] * scalar, coord[2] * scalar);
return v;
}
-
+
/// scalar division
Vector3f operator/(const float scalar) const {
Vector3f v(coord[0] / scalar, coord[1] / scalar, coord[2] / scalar);
return v;
}
-
+
/// vector sum
inline Vector3f operator+(const Vector3f &other) const {
Vector3f v(coord[0] + other.coord[0], coord[1] + other.coord[1], coord[2] + other.coord[2]);
return v;
}
-
+
/// vector difference
inline Vector3f operator-(const Vector3f &other) const {
Vector3f v(coord[0] - other.coord[0], coord[1] - other.coord[1], coord[2] - other.coord[2]);
return v;
}
-
+
/// comparison operator
bool operator==(const Vector3f &other) const;
-
+
/// assign a value to an element of this vector
/*! range is not checked
* @param index the index of the element to assign to ( 0 <= index < 3 )
@@ -105,7 +105,7 @@ public:
inline float& operator[](const size_t index) {
return coord[index];
}
-
+
/// returns the value of an element of this vector
/*! range is not checked
* @param index the index of the element to return ( 0 <= index < 3 )
@@ -113,61 +113,75 @@ public:
inline float operator[](const size_t index) const {
return coord[index];
}
-
+
/// x coordinate
- inline float x() const { return coord[0]; }
+ inline float x() const {
+ return coord[0];
+ }
/// y coordinate
- inline float y() const { return coord[1]; }
+ inline float y() const {
+ return coord[1];
+ }
/// z coordinate
- inline float z() const { return coord[2]; }
+ inline float z() const {
+ return coord[2];
+ }
- /// mutable reference to the x coordinate
- inline float & get_x() { return coord[0]; }
+ /// mutable reference to the x coordinate
+ inline float & get_x() {
+ return coord[0];
+ }
/// mutable reference to the y coordinate
- inline float & get_y() { return coord[1]; }
+ inline float & get_y() {
+ return coord[1];
+ }
/// mutable reference to the z coordinate
- inline float & get_z() { return coord[2]; }
+ inline float & get_z() {
+ return coord[2];
+ }
/// a pointer to the internal data
- inline float *ptr() const { return (float *) coord; }
+ inline float *ptr() const {
+ return (float *) coord;
+ }
/// cartesian length
float length() const;
-
+
/// cartesian length squared
float lengthsquared() const;
-
+
/// divide this Vector by its length
/// @see normalized()
/// vector must not be (0, 0, 0)
void normalize();
-
+
/* static functions */
-
+
/// Returns the unity vector on the X-axis
static inline Vector3f Xaxis() {
return Vector3f(1.0f, 0.0f, 0.0f);
}
-
+
/// Returns the unity vector on the Y-axis
static inline Vector3f Yaxis() {
return Vector3f(0.0f, 1.0f, 0.0f);
}
-
+
/// Returns the unity vector on the Z-axis
static inline Vector3f Zaxis() {
return Vector3f(0.0f, 0.0f, 1.0f);
}
-
+
/// cartesian lenght
static inline float length(const Vector3f & vector) {
return vector.length();
}
-
+
/// Return a vector divided by it's length
/// @see normalize()
/// WARNING: vector must not be (0, 0, 0)
diff --git a/src/model/asefile.cc b/src/model/asefile.cc
index 6010947..3bf0d59 100644
--- a/src/model/asefile.cc
+++ b/src/model/asefile.cc
@@ -23,7 +23,7 @@ ASEFile::ASEFile(std::string const &name)
asefile_ifs.open(asefile_name);
- for (int i=0; i < 3; i++) {
+ for (int i = 0; i < 3; i++) {
ase_minbbox[i] = MAX_BOUNDS;
ase_maxbbox[i] = -MAX_BOUNDS;
}
@@ -33,17 +33,17 @@ ASEFile::ASEFile(std::string const &name)
ASEFile::~ASEFile()
{
for (VertexList::iterator it = ase_tvertexlist.begin(); it != ase_tvertexlist.end(); it++) {
- delete (*it).second;
+ delete(*it).second;
}
ase_tvertexlist.clear();
for (VertexList::iterator it = ase_vertexlist.begin(); it != ase_vertexlist.end(); it++) {
- delete (*it).second;
+ delete(*it).second;
}
ase_vertexlist.clear();
for (FaceList::iterator it = ase_facelist.begin(); it != ase_facelist.end(); it++) {
- delete (*it).second;
+ delete(*it).second;
}
ase_facelist.clear();
@@ -60,7 +60,7 @@ bool ASEFile::read_header(std::istream &is)
char data[1024];
memset(data, 0, sizeof(data));
- if (!is.getline(data, sizeof(data) -1 )) {
+ if (!is.getline(data, sizeof(data) - 1)) {
return false;
}
@@ -82,7 +82,7 @@ bool ASEFile::read_mesh_vertex_list(std::istream &is)
char data[1024];
memset(data, 0, sizeof(data));
- while (is.getline(data, sizeof(data) -1 )) {
+ while (is.getline(data, sizeof(data) - 1)) {
std::istringstream line(data);
std::string firstword;
@@ -93,7 +93,7 @@ bool ASEFile::read_mesh_vertex_list(std::istream &is)
return true;
- } else if ( firstword.compare("*MESH_VERTEX") == 0) {
+ } else if (firstword.compare("*MESH_VERTEX") == 0) {
size_t index;
float x, y, z;
if (line >> index >> x >> y >> z) {
@@ -123,7 +123,7 @@ bool ASEFile::read_mesh_face_list(std::istream &is)
char data[1024];
memset(data, 0, sizeof(data));
- while (is.getline(data, sizeof(data) -1 )) {
+ while (is.getline(data, sizeof(data) - 1)) {
std::istringstream line(data);
std::string word;
@@ -133,22 +133,22 @@ bool ASEFile::read_mesh_face_list(std::istream &is)
//con_debug << " " << count << " mesh faces" << std::endl;
return true;
- } else if ( word.compare("*MESH_FACE") == 0) {
+ } else if (word.compare("*MESH_FACE") == 0) {
std::string facestr;
size_t a, b, c;
- if ( (line >> facestr) &&
- (line >> word) && (line >> a) &&
- (line >> word) && (line >> b) &&
- (line >> word) && (line >> c)) {
+ if ((line >> facestr) &&
+ (line >> word) && (line >> a) &&
+ (line >> word) && (line >> b) &&
+ (line >> word) && (line >> c)) {
if (facestr.size() && facestr[facestr.size()-1] == ':') {
- facestr.erase(facestr.size()-1);
+ facestr.erase(facestr.size() - 1);
}
size_t index;
std::istringstream faceindexstr(facestr);
faceindexstr >> index;
-
+
Triangle *triangle = new Triangle(*ase_vertexlist[a], *ase_vertexlist[b], *ase_vertexlist[c]);
ase_facelist[index] = triangle;
}
@@ -171,7 +171,7 @@ bool ASEFile::read_mesh_normals(std::istream &is)
float x, y, z;
FaceList::iterator it;
- while (is.getline(data, sizeof(data) -1 )) {
+ while (is.getline(data, sizeof(data) - 1)) {
std::istringstream line(data);
std::string firstword;
@@ -181,7 +181,7 @@ bool ASEFile::read_mesh_normals(std::istream &is)
//con_debug << " " << count << " face normals" << std::endl;
return true;
- } else if ( firstword.compare("*MESH_FACENORMAL") == 0) {
+ } else if (firstword.compare("*MESH_FACENORMAL") == 0) {
if (line >> index >> x >> y >> z) {
it = ase_facelist.find(index);
if (it != ase_facelist.end()) {
@@ -194,10 +194,10 @@ bool ASEFile::read_mesh_normals(std::istream &is)
} else {
it = ase_facelist.end();
}
- } else if ( firstword.compare("*MESH_VERTEXNORMAL") == 0) {
+ } else if (firstword.compare("*MESH_VERTEXNORMAL") == 0) {
+
+ if ((it != ase_facelist.end()) && (line >> index >> x >> y >> z)) {
- if ( (it != ase_facelist.end()) && (line >> index >> x >> y >> z)) {
-
if (vertindex == 0) {
(*it).second->n0().assign(x, y, z);
} else if (vertindex == 1) {
@@ -220,7 +220,7 @@ bool ASEFile::read_mesh_tvertex_list(std::istream &is)
char data[1024];
memset(data, 0, sizeof(data));
- while (is.getline(data, sizeof(data) -1 )) {
+ while (is.getline(data, sizeof(data) - 1)) {
std::istringstream line(data);
std::string firstword;
@@ -230,7 +230,7 @@ bool ASEFile::read_mesh_tvertex_list(std::istream &is)
//con_debug << " " << count << " texture vertices" << std::endl;
return true;
- } else if ( firstword.compare("*MESH_TVERT") == 0) {
+ } else if (firstword.compare("*MESH_TVERT") == 0) {
size_t index;
float x, y, z;
if (line >> index >> x >> y >> z) {
@@ -246,12 +246,12 @@ bool ASEFile::read_mesh_tvertex_list(std::istream &is)
bool ASEFile::read_mesh_tface_list(std::istream &is)
{
-size_t count = 0;
+ size_t count = 0;
char data[1024];
memset(data, 0, sizeof(data));
- while (is.getline(data, sizeof(data) -1 )) {
+ while (is.getline(data, sizeof(data) - 1)) {
std::istringstream line(data);
std::string firstword;
@@ -261,7 +261,7 @@ size_t count = 0;
//con_debug << " " << count << " face texture coordinates" << std::endl;
return true;
- } else if ( firstword.compare("*MESH_TFACE") == 0) {
+ } else if (firstword.compare("*MESH_TFACE") == 0) {
size_t index, a, b, c;
if (line >> index >> a >> b >> c) {
Triangle *triangle = ase_facelist[index];
@@ -292,38 +292,38 @@ bool ASEFile::read_mesh(std::istream &is)
ase_vertexlist.clear();
- while (is.getline(data, sizeof(data) -1 )) {
+ while (is.getline(data, sizeof(data) - 1)) {
std::istringstream line(data);
std::string word;
line >> word;
- if ((level == 1 ) && (word.compare("*MESH_VERTEX_LIST") == 0)) {
+ if ((level == 1) && (word.compare("*MESH_VERTEX_LIST") == 0)) {
if ((line >> word) && (word.compare("{") == 0)) {
//con_debug << " " << name() << " *MESH_VERTEX_LIST" << std::endl;
read_mesh_vertex_list(is);
}
- } else if ((level == 1 ) && (word.compare("*MESH_FACE_LIST") == 0)) {
+ } else if ((level == 1) && (word.compare("*MESH_FACE_LIST") == 0)) {
if ((line >> word) && (word.compare("{") == 0)) {
//con_debug << " " << name() << " *MESH_FACE_LIST" << std::endl;
read_mesh_face_list(is);
}
- } else if ((level == 1 ) && (word.compare("*MESH_NORMALS") == 0)) {
+ } else if ((level == 1) && (word.compare("*MESH_NORMALS") == 0)) {
if ((line >> word) && (word.compare("{") == 0)) {
//con_debug << " " << name() << " *MESH_NORMALS" << std::endl;
read_mesh_normals(is);
}
- } else if ((level == 1 ) && (word.compare("*MESH_TVERTLIST") == 0)) {
- if ((line >> word) && (word.compare("{") == 0)) {
+ } else if ((level == 1) && (word.compare("*MESH_TVERTLIST") == 0)) {
+ if ((line >> word) && (word.compare("{") == 0)) {
//con_debug << " " << name() << " *MESH_TVERTLIST" << std::endl;
read_mesh_tvertex_list(is);
}
- } else if ((level == 1 ) && (word.compare("*MESH_TFACELIST") == 0)) {
- if ((line >> word) && (word.compare("{") == 0)) {
+ } else if ((level == 1) && (word.compare("*MESH_TFACELIST") == 0)) {
+ if ((line >> word) && (word.compare("{") == 0)) {
//con_debug << " " << name() << " *MESH_TFACELIST" << std::endl;
read_mesh_tface_list(is);
}
@@ -352,13 +352,13 @@ bool ASEFile::read_geom(std::istream &is)
memset(data, 0, sizeof(data));
int level = 1;
- while (is.getline(data, sizeof(data) -1 )) {
+ while (is.getline(data, sizeof(data) - 1)) {
std::istringstream line(data);
std::string word;
line >> word;
- if ((level == 1 ) && (word.compare("*MESH") == 0)) {
+ if ((level == 1) && (word.compare("*MESH") == 0)) {
if ((line >> word) && (word.compare("{") == 0)) {
//con_debug << " " << name() << " " << "*MESH" << std::endl;
read_mesh(is);
@@ -391,13 +391,13 @@ bool ASEFile::read()
char data[1024];
memset(data, 0, sizeof(data));
- while (asefile_ifs.getline(data, sizeof(data) -1 )) {
+ while (asefile_ifs.getline(data, sizeof(data) - 1)) {
std::istringstream line(data);
std::string word;
line >> word;
-
- if (word.compare("*GEOMOBJECT") == 0) {
+
+ if (word.compare("*GEOMOBJECT") == 0) {
if ((line >> word) && (word.compare("{") == 0)) {
//con_debug << " " << name() << " " << "*GEOMOBJECT" << std::endl;
@@ -429,9 +429,9 @@ Model * ASEFile::load(const std::string &name)
// default material
Material *material = Material::find(name);
if (!material) {
- material = new Material(name);
+ material = new Material(name);
Material::add(material);
- material->set_flags(Material::Texture);
+ //material->set_flags(Material::Texture);
material->set_texture(material->name());
}
@@ -449,7 +449,7 @@ Model * ASEFile::load(const std::string &name)
// caculate bounding box
model->model_minbbox = (asefile.ase_minbbox - center) * scale;
- model->model_maxbbox = (asefile.ase_maxbbox - center) * scale;
+ model->model_maxbbox = (asefile.ase_maxbbox - center) * scale;
model->set_radius(model->model_maxbbox.length());
model->set_origin(center * scale);
@@ -460,14 +460,14 @@ Model * ASEFile::load(const std::string &name)
fragment->add_vertex((triangle->v0() - center) * scale , triangle->n0(), triangle->t0(), false);
fragment->add_vertex((triangle->v1() - center) * scale , triangle->n1(), triangle->t1(), false);
fragment->add_vertex((triangle->v2() - center) * scale , triangle->n2(), triangle->t2(), false);
-
+
model->model_tris_count++;
}
model->add_group(group);
con_debug << " " << asefile.name() << " " << asefile.ase_vertexlist.size() << " vertices " <<
- model->model_tris_detail_count << "/" << model->model_tris_count << " detail/tris" << std::endl;
+ model->model_tris_detail_count << "/" << model->model_tris_count << " detail/tris" << std::endl;
return model;
}
diff --git a/src/model/asefile.h b/src/model/asefile.h
index c792a9d..e129ec0 100644
--- a/src/model/asefile.h
+++ b/src/model/asefile.h
@@ -84,10 +84,11 @@ private:
*/
bool read();
- inline const std::string &name() const { return asefile_name; }
+ inline const std::string &name() const {
+ return asefile_name;
+ }
- inline bool is_open()
- {
+ inline bool is_open() {
return asefile_ifs.is_open();
}
diff --git a/src/model/face.cc b/src/model/face.cc
index 7626fac..b7d5e45 100644
--- a/src/model/face.cc
+++ b/src/model/face.cc
@@ -22,20 +22,20 @@ Face::Face(Vector3f const & point0, Vector3f const &point1, Vector3f const &poin
face_detail = false;
face_surface_flags = 0;
face_material = 0;
-
+
face_point[0] = point0;
face_point[1] = point1;
face_point[2] = point2;
-
+
face_normal = crossproduct((face_point[1] - face_point[0]) , (face_point[2] - face_point[0]));
pd = -1 * (face_normal.x() * face_point[0].x() + face_normal.y() * face_point[0].y() + face_normal.z() * face_point[0].z());
}
Face::Face(Face const & other)
{
- for (size_t i=0; i < 3; i++)
+ for (size_t i = 0; i < 3; i++)
this->face_point[i] = other.face_point[i];
-
+
face_normal = crossproduct((face_point[1] - face_point[0]) , (face_point[2] - face_point[0]));
pd = -1 * (face_normal.x() * face_point[0].x() + face_normal.y() * face_point[0].y() + face_normal.z() * face_point[0].z());
}
diff --git a/src/model/face.h b/src/model/face.h
index 725f798..cbed101 100644
--- a/src/model/face.h
+++ b/src/model/face.h
@@ -28,59 +28,50 @@ public:
/// copy constructor
Face(Face const & other);
-
+
/// normal of the plane, not normalized to lenght 1
- inline math::Vector3f const & normal() const
- {
+ inline math::Vector3f const & normal() const {
return face_normal;
}
/// the points defining the plane.
/// @param index 0 <= i < 3
- inline math::Vector3f const & point(size_t index) const
- {
+ inline math::Vector3f const & point(size_t index) const {
return face_point[index];
}
/// face material
- inline Material *material() const
- {
+ inline Material *material() const {
return face_material;
}
/// first parameter of the general plane equation
- inline float a() const
- {
+ inline float a() const {
return face_normal[0];
}
/// second parameter of the general plane equation
- inline float b() const
- {
+ inline float b() const {
return face_normal[1];
}
/// third param of the general plane equation
- inline float c() const
- {
+ inline float c() const {
return face_normal[2];
}
/// fourth parameter of the general plane equation
- inline float d() const
- {
+ inline float d() const {
return pd;
}
/// indidcates if this plane was generated from a detail brush
- inline bool detail() const
- {
+ inline bool detail() const {
return face_detail;
}
/// surface flags
- inline unsigned int surface_flags() const
- {
+ inline unsigned int surface_flags() const {
return face_surface_flags;
}
@@ -93,22 +84,34 @@ public:
}
/// return texture shift
- inline const math::Vector2f &tex_shift() { return face_tex_shift; }
+ inline const math::Vector2f &tex_shift() {
+ return face_tex_shift;
+ }
- inline void set_material(Material *material) { face_material = material; }
+ inline void set_material(Material *material) {
+ face_material = material;
+ }
- inline void set_detail(const bool detail = true) { face_detail = detail; }
+ inline void set_detail(const bool detail = true) {
+ face_detail = detail;
+ }
- inline void set_surface_flags(const unsigned int flags) { face_surface_flags = flags; }
+ inline void set_surface_flags(const unsigned int flags) {
+ face_surface_flags = flags;
+ }
/**
* @brief return texture transformation vectors
* @param index 0 <= i < 2
*/
- inline math::Vector3f &get_tex_vec(size_t index) { return face_tex_vec[index]; }
+ inline math::Vector3f &get_tex_vec(size_t index) {
+ return face_tex_vec[index];
+ }
/// return texture shift
- inline math::Vector2f &get_tex_shift() { return face_tex_shift; }
+ inline math::Vector2f &get_tex_shift() {
+ return face_tex_shift;
+ }
private:
math::Vector3f face_normal;
diff --git a/src/model/fragment.cc b/src/model/fragment.cc
index ab0f9fa..8e6483f 100644
--- a/src/model/fragment.cc
+++ b/src/model/fragment.cc
@@ -19,7 +19,7 @@ namespace model
Fragment::Fragment(const Fragment &other)
{
fragment_type = other.fragment_type;
- fragment_index = other.fragment_index;
+ fragment_index = other.fragment_index;
fragment_structural_size = other.fragment_structural_size;
fragment_detail_size = other.fragment_detail_size;
fragment_material = other.fragment_material;
@@ -71,7 +71,8 @@ FragmentGroup::~FragmentGroup()
clear();
}
-void FragmentGroup::clear() {
+void FragmentGroup::clear()
+{
for (iterator it = group_fragments.begin(); it != group_fragments.end(); it++) {
delete(*it);
diff --git a/src/model/fragment.h b/src/model/fragment.h
index 0a9ca6a..6d65f7a 100644
--- a/src/model/fragment.h
+++ b/src/model/fragment.h
@@ -23,7 +23,7 @@ class Fragment
public:
/// fragment primitive type: triangles or quads
enum Type {Triangles, Quads};
-
+
/// create a new fragment
Fragment(Type type, const Material *material);
@@ -31,43 +31,38 @@ public:
* @brief copy constructor
*/
Fragment(const Fragment &other);
-
+
/// add a vertex to the fragment
size_t add_vertex(math::Vector3f const & vertex, math::Vector3f const &normal, bool detail);
/// add a vertex to the fragment
size_t add_vertex(math::Vector3f const & vertex, math::Vector3f const &normal, math::Vector2f const &texcoord, bool detail);
-
+
/// the type of primitives this fragment consists of
- inline Type type() const
- {
+ inline Type type() const {
return fragment_type;
}
-
+
/// VertexArray index of the start of the fragment
- inline size_t index() const
- {
+ inline size_t index() const {
return fragment_index;
}
-
+
/// number of structural vertices in the fragment
- inline size_t structural_size() const
- {
+ inline size_t structural_size() const {
return fragment_structural_size;
}
-
+
/// number of detail vertices in the fragment
- inline size_t detail_size() const
- {
+ inline size_t detail_size() const {
return fragment_detail_size;
}
-
+
/// material flags
- inline const Material * material() const
- {
+ inline const Material * material() const {
return fragment_material;
}
-
+
private:
Type fragment_type;
size_t fragment_index;
@@ -92,38 +87,70 @@ public:
~FragmentGroup();
- inline const Type type() const { return group_type; }
+ inline const Type type() const {
+ return group_type;
+ }
- inline const math::Vector3f &location() const { return group_location; }
+ inline const math::Vector3f &location() const {
+ return group_location;
+ }
- inline const math::Axis & axis() const { return group_axis; }
+ inline const math::Axis & axis() const {
+ return group_axis;
+ }
- inline const float speed() const { return group_speed; }
+ inline const float speed() const {
+ return group_speed;
+ }
- inline const float scale() const { return group_scale; }
-
- inline const bool transform() const { return group_transform; }
+ inline const float scale() const {
+ return group_scale;
+ }
-
- inline void set_type(const Type type) { group_type = type; }
+ inline const bool transform() const {
+ return group_transform;
+ }
- inline void set_location(const math::Vector3f &location) { group_location.assign(location); }
- inline void set_axis(const math::Axis &axis) { group_axis.assign(axis); }
+ inline void set_type(const Type type) {
+ group_type = type;
+ }
- inline void set_speed(const float speed) { group_speed = speed; }
+ inline void set_location(const math::Vector3f &location) {
+ group_location.assign(location);
+ }
+
+ inline void set_axis(const math::Axis &axis) {
+ group_axis.assign(axis);
+ }
+
+ inline void set_speed(const float speed) {
+ group_speed = speed;
+ }
+
+ inline void set_scale(const float scale) {
+ group_scale = scale;
+ }
- inline void set_scale(const float scale) { group_scale = scale; }
+ inline void set_transform(const bool transform) {
+ group_transform = transform;
+ }
+
+ inline iterator begin() {
+ return group_fragments.begin();
+ }
- inline void set_transform(const bool transform) { group_transform = transform; }
-
- inline iterator begin() { return group_fragments.begin(); }
+ inline iterator end() {
+ return group_fragments.end();
+ }
- inline iterator end() { return group_fragments.end(); }
-
- inline const size_t size() const { return group_fragments.size(); }
-
- inline void add_fragment(Fragment *fragment) { group_fragments.push_back(fragment); }
+ inline const size_t size() const {
+ return group_fragments.size();
+ }
+
+ inline void add_fragment(Fragment *fragment) {
+ group_fragments.push_back(fragment);
+ }
void clear();
diff --git a/src/model/mapfile.cc b/src/model/mapfile.cc
index d3d19f6..8dff219 100644
--- a/src/model/mapfile.cc
+++ b/src/model/mapfile.cc
@@ -26,15 +26,14 @@ const float MAX_BOUNDS = 16384;
const float MIN_DELTA = 10e-10;
// from radiant tools/quake3/q3map2/map.c
-math::Vector3f texture_baseaxis[18] =
-{
+math::Vector3f texture_baseaxis[18] = {
// normal texture plane
- math::Vector3f(0,0,1), math::Vector3f(1,0,0), math::Vector3f(0,-1,0), // floor
- math::Vector3f(0,0,-1), math::Vector3f(1,0,0), math::Vector3f(0,-1,0), // ceiling
- math::Vector3f(1,0,0), math::Vector3f(0,1,0), math::Vector3f(0,0,-1), // west wall
- math::Vector3f(-1,0,0), math::Vector3f(0,1,0), math::Vector3f(0,0,-1), // east wall
- math::Vector3f(0,1,0), math::Vector3f(1,0,0), math::Vector3f(0,0,-1), // south wall
- math::Vector3f(0,-1,0), math::Vector3f(1,0,0), math::Vector3f(0,0,-1) // north wall
+ math::Vector3f(0, 0, 1), math::Vector3f(1, 0, 0), math::Vector3f(0, -1, 0), // floor
+ math::Vector3f(0, 0, -1), math::Vector3f(1, 0, 0), math::Vector3f(0, -1, 0), // ceiling
+ math::Vector3f(1, 0, 0), math::Vector3f(0, 1, 0), math::Vector3f(0, 0, -1), // west wall
+ math::Vector3f(-1, 0, 0), math::Vector3f(0, 1, 0), math::Vector3f(0, 0, -1), // east wall
+ math::Vector3f(0, 1, 0), math::Vector3f(1, 0, 0), math::Vector3f(0, 0, -1), // south wall
+ math::Vector3f(0, -1, 0), math::Vector3f(1, 0, 0), math::Vector3f(0, 0, -1) // north wall
};
@@ -46,19 +45,17 @@ void texture_axis_from_plane(const Face &face, math::Vector3f &xv, math::Vector3
float dot = 0;
float best = 0;
- math::Vector3f n(face.normal()*-1);
+ math::Vector3f n(face.normal()* -1);
n.normalize();
-
- for (size_t i=0 ; i<6 ; i++)
- {
+
+ for (size_t i = 0 ; i < 6 ; i++) {
dot = math::dotproduct(n, texture_baseaxis[i *3]);
- if( dot > best + MIN_DELTA ) /* ydnar: bug 637 fix, suggested by jmonroe */
- {
+ if (dot > best + MIN_DELTA) { /* ydnar: bug 637 fix, suggested by jmonroe */
best = dot;
best_axis = i;
}
}
-
+
xv.assign(texture_baseaxis[best_axis*3+1]);
yv.assign(texture_baseaxis[best_axis*3+2]);
}
@@ -74,25 +71,28 @@ void face_texture_verts(Face &face, const math::Vector2f &tex_shift, const float
float ang, sinv, cosv;
float ns, nt;
int i, j;
-
+
texture_axis_from_plane(face, vecs[0], vecs[1]);
-
+
if (!scale[0])
scale[0] = 1;
if (!scale[1])
scale[1] = 1;
// rotate axis
- if (tex_rotate == 0.0f)
- { sinv = 0.0f ; cosv = 1.0f; }
- else if (tex_rotate == 90.0f)
- { sinv = 1.0f ; cosv = 0.0f; }
- else if (tex_rotate == 180.0f)
- { sinv = 0.0f; cosv = -1.0f; }
- else if (tex_rotate == 270.0f)
- { sinv = -1.0f ; cosv = 0.0f; }
- else
- {
+ if (tex_rotate == 0.0f) {
+ sinv = 0.0f ;
+ cosv = 1.0f;
+ } else if (tex_rotate == 90.0f) {
+ sinv = 1.0f ;
+ cosv = 0.0f;
+ } else if (tex_rotate == 180.0f) {
+ sinv = 0.0f;
+ cosv = -1.0f;
+ } else if (tex_rotate == 270.0f) {
+ sinv = -1.0f ;
+ cosv = 0.0f;
+ } else {
ang = tex_rotate / 180.0f * M_PI;
sinv = sinf(ang);
cosv = cosf(ang);
@@ -112,15 +112,15 @@ void face_texture_verts(Face &face, const math::Vector2f &tex_shift, const float
else
tv = 2;
- for (i=0 ; i<2 ; i++) {
+ for (i = 0 ; i < 2 ; i++) {
ns = cosv * vecs[i][sv] - sinv * vecs[i][tv];
nt = sinv * vecs[i][sv] + cosv * vecs[i][tv];
vecs[i][sv] = ns;
vecs[i][tv] = nt;
}
- for (i=0 ; i<2 ; i++)
- for (j=0 ; j<3 ; j++)
+ for (i = 0 ; i < 2 ; i++)
+ for (j = 0 ; j < 3 ; j++)
face.get_tex_vec(i)[j] = vecs[i][j] / scale[i];
face.get_tex_shift().assign(tex_shift);
@@ -130,10 +130,10 @@ void face_texture_verts(Face &face, const math::Vector2f &tex_shift, const float
// project vertex into texture plane
const math::Vector2f map_texture_coords(Face *face, const math::Vector3f &v)
{
- return math::Vector2f (
- (face->get_tex_shift().x() + math::dotproduct(face->tex_vec(0), v)) / face->material()->size().width(),
- (face->get_tex_shift().y() + math::dotproduct(face->tex_vec(1), v)) / face->material()->size().height()
- );
+ return math::Vector2f(
+ (face->get_tex_shift().x() + math::dotproduct(face->tex_vec(0), v)) / face->material()->size().width(),
+ (face->get_tex_shift().y() + math::dotproduct(face->tex_vec(1), v)) / face->material()->size().height()
+ );
}
// function to test spawnflags
@@ -177,12 +177,12 @@ bool MapFile::open(std::string const & mapname)
classname_current = "";
line_number = 0;
parse_level = 0;
-
+
clear_materials();
-
+
mapfile_name.append(mapname);
mapfile_name.append(".map");
-
+
mapfile_ifs.open(mapfile_name);
if (!mapfile_ifs.is_open()) {
return false;
@@ -217,7 +217,7 @@ bool MapFile::read_patchdef()
return false;
else
line_number++;
-
+
// second line: "( a b c d e )"
if (!mapfile_ifs.getline(data, 1023))
return false;
@@ -235,11 +235,11 @@ bool MapFile::read_patchdef()
std::istringstream linestream(data);
std::string firstword;
-
+
if (linestream >> firstword) {
if (firstword.compare(")") == 0) {
//con_debug << " patchDef2 with " << count << " lines" << std::endl;
- return true;
+ return true;
} else {
count ++;
}
@@ -252,32 +252,32 @@ bool MapFile::read_patchdef()
bool MapFile::getline()
{
using math::Vector3f;
-
+
last_read_was_classname = false;
last_read_was_key = false;
last_read_was_classend = false;
-
+
key_current = "";
value_current = "";
-
+
if (!mapfile_ifs.is_open())
return false;
char data[1024];
memset(data, 0, sizeof(data));
-
+
if (mapfile_ifs.getline(data, 1023)) {
line_number++;
std::istringstream linestream(data);
std::string firstword;
-
+
if (linestream >> firstword) {
if (!firstword.size()) {
return true;
-
+
} else if (firstword == "//") {
return true;
-
+
} else if (firstword == "{") {
parse_level++;
@@ -286,7 +286,7 @@ bool MapFile::getline()
con_warn << name() << " error reading patchDef2 at line " << line_number << std::endl;
}
}
-
+
} else if (firstword == "}") {
if ((parse_level == 3) && (in_patchdef)) {
@@ -294,19 +294,19 @@ bool MapFile::getline()
in_patchdef = false;
} else if ((parse_level == 2) && (planes.size())) {
- // end-of-brush
+ // end-of-brush
// for every face
for (std::vector<Face *>::iterator face = planes.begin(); face != planes.end(); face++) {
make_brushface((*face));
}
-
+
// clean planes
for (std::vector<Face *>::iterator it = planes.begin(); it != planes.end(); it++) {
delete(*it);
}
planes.clear();
-
+
map_brushes++;
value_current.clear();
@@ -317,51 +317,51 @@ bool MapFile::getline()
}
parse_level--;
-
+
} else if (parse_level == 1) {
-
+
if (firstword.compare("\"classname\"") == 0) {
classname_current.clear();
-
+
if (linestream >> classname_current) {
if (classname_current.size() > 2) {
- classname_current.erase(0,1);
- classname_current.erase(classname_current.size()-1, 1);
+ classname_current.erase(0, 1);
+ classname_current.erase(classname_current.size() - 1, 1);
last_read_was_classname = true;
} else {
classname_current.clear();
}
}
-
+
} else if ((firstword.size() > 2) && (firstword[0] == '\"') && (firstword[firstword.size()-1] == '\"')) {
-
+
key_current.assign(firstword);
- key_current.erase(0,1);
- key_current.erase(key_current.size()-1, 1);
-
+ key_current.erase(0, 1);
+ key_current.erase(key_current.size() - 1, 1);
+
value_current.clear();
char c;
while ((linestream.get(c)) && (c != '"'));
while ((linestream.get(c)) && (c != '"'))
value_current += c;
-
+
last_read_was_key = true;
}
-
+
} else if (parse_level == 2) {
-
+
if (firstword.compare("(") == 0) {
// brush plane
-
+
Vector3f p1, p2, p3;
std::string tmp;
std::string texture;
int n = 0;
-
+
linestream >> p1; // first plane vertex x y z
linestream >> tmp; // )
linestream >> tmp; // (
- linestream >> p2; // second plane vertex x y z
+ linestream >> p2; // second plane vertex x y z
linestream >> tmp; // )
linestream >> tmp; // (
linestream >> p3; // third plane vertex x y z
@@ -377,11 +377,11 @@ bool MapFile::getline()
if (!material) {
material = new Material("textures/" + texture);
Material::add(material);
- material->set_flags(Material::Texture);
+ //material->set_flags(Material::Texture);
material->set_texture(material->name());
}
face->set_material(material);
-
+
// texture alignment
float tx, ty, tr, tsx, tsy;
linestream >> tx >> ty; // texture shift
@@ -390,7 +390,7 @@ bool MapFile::getline()
// store the texture transformation for this face
face_texture_verts((*face), math::Vector2f(tx, ty), tr, math::Vector2f(tsx, tsy));
-
+
// content flags
if (!(linestream >> n))
n = 0;
@@ -405,7 +405,7 @@ bool MapFile::getline()
face->set_surface_flags(n);
planes.push_back(face);
-
+
value_current.clear();
} else if (firstword.compare("patchDef2") == 0) {
@@ -414,17 +414,17 @@ bool MapFile::getline()
}
}
} else {
-
+
return false;
}
-
+
return true;
}
void MapFile::make_brushface(Face *face)
{
using math::Vector3f;
-
+
// ignore materials with the 'Ignore' flag set
if ((face->material()->flags() & Material::Ignore) == Material::Ignore) {
return;
@@ -436,18 +436,18 @@ void MapFile::make_brushface(Face *face)
if (face->detail()) {
map_faces_detail++;
}
-
+
// using suggestions from
// http://www.flipcode.com/archives/Level_Editing.shtml
-
+
// vertex list
std::vector<math::Vector3f *> vl;
-
+
// calculate initial vertices on the bounding box
-
+
// check if the face is x-axis oriented
if ((fabsf(face->normal().x()) >= fabsf(face->normal().y())) && (fabsf(face->normal().x()) >= fabsf(face->normal().z()))) {
-
+
if (face->normal().x() > MIN_DELTA) {
vl.push_back(new math::Vector3f(0, -MAX_BOUNDS, -MAX_BOUNDS));
vl.push_back(new math::Vector3f(0, -MAX_BOUNDS, MAX_BOUNDS));
@@ -462,15 +462,15 @@ void MapFile::make_brushface(Face *face)
// calculate the x coordinate of each face vertex
for (std::vector<Vector3f *>::iterator it = vl.begin(); it != vl.end(); it++) {
(*it)->get_x() = (-face->d() -
- face->normal().z() * (*it)->z() -
- face->normal().y() * (*it)->y()) /
- face->normal().x();
+ face->normal().z() * (*it)->z() -
+ face->normal().y() * (*it)->y()) /
+ face->normal().x();
}
}
-
+
// check if the face is y-axis oriented
else if ((fabsf(face->normal().y()) >= fabsf(face->normal().x())) && (fabsf(face->normal().y()) >= fabsf(face->normal().z()))) {
-
+
if (face->normal().y() > MIN_DELTA) {
vl.push_back(new Vector3f(MAX_BOUNDS, 0, -MAX_BOUNDS));
vl.push_back(new Vector3f(MAX_BOUNDS, 0, MAX_BOUNDS));
@@ -482,19 +482,19 @@ void MapFile::make_brushface(Face *face)
vl.push_back(new Vector3f(MAX_BOUNDS, 0, MAX_BOUNDS));
vl.push_back(new Vector3f(MAX_BOUNDS, 0, -MAX_BOUNDS));
}
-
+
// calculate the x coordinate of each face vertex
for (std::vector<Vector3f *>::iterator it = vl.begin(); it != vl.end(); it++) {
(*it)->get_y() = (-face->d() -
- face->normal().z() * (*it)->z() -
- face->normal().x() * (*it)->x()) /
- face->normal().y();
+ face->normal().z() * (*it)->z() -
+ face->normal().x() * (*it)->x()) /
+ face->normal().y();
}
}
-
+
// face must be z-axis oriented
else {
-
+
if (face->normal().z() > MIN_DELTA) {
vl.push_back(new Vector3f(-MAX_BOUNDS, -MAX_BOUNDS, 0));
vl.push_back(new Vector3f(-MAX_BOUNDS, MAX_BOUNDS, 0));
@@ -506,17 +506,17 @@ void MapFile::make_brushface(Face *face)
vl.push_back(new Vector3f(-MAX_BOUNDS, MAX_BOUNDS, 0));
vl.push_back(new Vector3f(-MAX_BOUNDS, -MAX_BOUNDS, 0));
}
-
+
// calculate the x coordinate of each face vertex
for (std::vector<Vector3f *>::iterator it = vl.begin(); it != vl.end(); it++) {
(*it)->get_z() = (-face->d() -
- face->normal().x() * (*it)->x() -
- face->normal().y() * (*it)->y()) /
- face->normal().z();
+ face->normal().x() * (*it)->x() -
+ face->normal().y() * (*it)->y()) /
+ face->normal().z();
}
}
-
-
+
+
// intersect the face with every plane
for (std::vector<Face *>::iterator pit = planes.begin(); pit != planes.end(); pit++) {
@@ -524,102 +524,102 @@ void MapFile::make_brushface(Face *face)
if (plane == face) {
continue;
}
-
- Vector3f fn = crossproduct(face->point(1)-face->point(0), face->point(2)-face->point(0));
- Vector3f pn = crossproduct(plane->point(1)-plane->point(0), plane->point(2)-plane->point(0));
-
+
+ Vector3f fn = crossproduct(face->point(1) - face->point(0), face->point(2) - face->point(0));
+ Vector3f pn = crossproduct(plane->point(1) - plane->point(0), plane->point(2) - plane->point(0));
+
Vector3f t = crossproduct(fn, pn);
if ((t.x() == 0) && (t.y() == 0) && (t.z() == 0)) {
continue;
}
-
+
// intersect face with plane
- for (int i=0; vl.size() - i > 0; i++) {
-
+ for (int i = 0; vl.size() - i > 0; i++) {
+
Vector3f v(*vl.at(i));
-
+
Vector3f next;
if (vl.size() - i > 1) {
- next = *vl.at(i+1);
+ next = *vl.at(i + 1);
} else {
next = *vl.front();
}
-
+
Vector3f prev;
if (i > 0) {
- prev = *vl.at(i-1);
+ prev = *vl.at(i - 1);
} else {
prev = *vl.back();
}
-
+
if ((v.x() * plane->normal().x() + v.y() * plane->normal().y() + v.z() * plane->normal().z() + plane->d()) < MIN_DELTA) {
-
+
// find current
std::vector<Vector3f *>::iterator vit = vl.begin();
while ((*vit) != vl.at(i)) {
vit++;
}
-
+
// check if prev - v intersects with plane
if ((prev.x() * plane->normal().x() + prev.y() * plane->normal().y() + prev.z() * plane->normal().z() + plane->d()) > MIN_DELTA) {
-
+
// calculate intersection
- float t1 = -plane->normal().x() * prev.x() - plane->normal().y() * prev.y() - plane->normal().z() * prev.z() -plane->d();
+ float t1 = -plane->normal().x() * prev.x() - plane->normal().y() * prev.y() - plane->normal().z() * prev.z() - plane->d();
float t2 = (plane->normal().x() * v.x() - plane->normal().x() * prev.x() +
plane->normal().y() * v.y() - plane->normal().y() * prev.y() +
plane->normal().z() * v.z() - plane->normal().z() * prev.z());
Vector3f *s = new Vector3f;
-
+
if (t2 == 0) {
*s = v;
} else {
for (int j = 0; j < 3; j++)
(*s)[j] = prev [j] + t1 * (v[j] - prev[j]) / t2;
}
-
- vit = vl.insert(vit,s);
+
+ vit = vl.insert(vit, s);
vit++;
i++;
}
-
+
// check if next - v intersects with plane
if ((next.x() * plane->normal().x() + next.y() * plane->normal().y() + next.z() * plane->normal().z() + plane->d()) > MIN_DELTA) {
-
+
// calculate intersection
- float t1 = -plane->normal().x() * v.x() - plane->normal().y() * v.y() - plane->normal().z() * v.z() -plane->d();
+ float t1 = -plane->normal().x() * v.x() - plane->normal().y() * v.y() - plane->normal().z() * v.z() - plane->d();
float t2 = (plane->normal().x() * next.x() - plane->normal().x() * v.x() +
plane->normal().y() * next.y() - plane->normal().y() * v.y() +
plane->normal().z() * next.z() - plane->normal().z() * v.z());
Vector3f *s = new Vector3f;
-
+
if (t2 == 0) {
*s = v;
} else {
for (int j = 0; j < 3; j++)
(*s)[j] = v [j] + t1 * (next[j] - v[j]) / t2;
}
-
- vit = vl.insert(vit,s);
+
+ vit = vl.insert(vit, s);
vit++;
i++;
}
-
+
// erase
delete *vit;
vl.erase(vit);
i--;
}
-
+
}
}
-
+
if (vl.size() > 2) {
// find the list if primitives for the current material, allocate a new one if necessary
Primitives *primitives = 0;
-
+
Materials::iterator mit = map_materials.find(face->material());
if (mit == map_materials.end()) {
primitives = new Primitives(face->material());
@@ -627,26 +627,26 @@ void MapFile::make_brushface(Face *face)
} else {
primitives = (*mit).second;
}
-
+
// scale vertices and calculate the bounding box
for (std::vector<Vector3f *>::iterator it = vl.begin(); it != vl.end(); it++) {
//*(*it) *= SCALE;
- for (int i=0; i < 3; i++) {
+ for (int i = 0; i < 3; i++) {
if (class_maxbbox[i] < (*(*it))[i] * SCALE)
class_maxbbox[i] = (*(*it))[i] * SCALE;
-
+
if (class_minbbox[i] > (*(*it))[i] * SCALE)
class_minbbox[i] = (*(*it))[i] * SCALE;
}
}
// the actual polygon normal is on the other side
- Vector3f face_normal(face->normal()*-1);
- face_normal.normalize();
+ Vector3f face_normal(face->normal()* -1);
+ face_normal.normalize();
-#ifndef HAVE_BULLET
+#ifndef HAVE_BULLET
- // Quads are disable to use model data for bullet physics
+ // Quads are disable to use model data for bullet physics
// split polygon into quads
while (vl.size() > 3) {
@@ -657,7 +657,7 @@ void MapFile::make_brushface(Face *face)
std::vector<Vector3f *>::reverse_iterator vn2 = vl.rbegin();
++vn2;
++vn2;
-
+
Quad *quad = new Quad(*(*vn2) * SCALE, *(*vn1) * SCALE, *(*vn) * SCALE, *(*v0) * SCALE, face_normal, face->detail());
primitives->add_quad(quad);
@@ -680,8 +680,8 @@ void MapFile::make_brushface(Face *face)
std::vector<Vector3f *>::reverse_iterator vn = vl.rbegin();
std::vector<Vector3f *>::reverse_iterator vn1 = vl.rbegin();
++vn1;
-
- Triangle * triangle = new Triangle (*(*vn1) * SCALE, *(*vn) * SCALE, *(*v0) * SCALE, face_normal, face->detail());
+
+ Triangle * triangle = new Triangle(*(*vn1) * SCALE, *(*vn) * SCALE, *(*v0) * SCALE, face_normal, face->detail());
primitives->add_triangle(triangle);
if (face->material()->flags() & Material::Texture) {
@@ -695,12 +695,12 @@ void MapFile::make_brushface(Face *face)
} else {
con_warn << name() << " unresolved face at line " << line() << std::endl;
}
-
+
// clean up the vertex list
for (std::vector<Vector3f *>::iterator it = vl.begin(); it != vl.end(); it++) {
delete(*it);
}
-
+
vl.clear();
}
@@ -720,9 +720,9 @@ bool MapFile::got_key_vector3f(const char * keylabel, math::Vector3f & v)
std::istringstream is(value_current);
float x, y, z;
if ((is >> x) && (is >> y) && (is >> z)) {
- v = math::Vector3f(x,y,z);
+ v = math::Vector3f(x, y, z);
} else {
- v= math::Vector3f();
+ v = math::Vector3f();
}
return true;
} else {
@@ -804,7 +804,7 @@ void MapFile::close()
void MapFile::clear_bbox()
{
- for (int i=0; i < 3; i++) {
+ for (int i = 0; i < 3; i++) {
class_minbbox[i] = MAX_BOUNDS;
class_maxbbox[i] = -MAX_BOUNDS;
}
@@ -814,7 +814,7 @@ void MapFile::clear_bbox()
}
void MapFile::load_worldspawn(Model *model)
-{
+{
if (!map_materials.size())
return;
@@ -832,12 +832,12 @@ void MapFile::load_fragmentgroup(Model *model, const FragmentGroup::Type class_t
{
if (!VertexArray::instance() || VertexArray::instance()->overflow())
return;
-
+
if (!map_materials.size())
return;
FragmentGroup *group = new FragmentGroup();
-
+
if (class_type == FragmentGroup::Rotate) {
if (class_speed == 0) {
// default rotation speed 45 degrees per second
@@ -862,39 +862,39 @@ void MapFile::load_fragmentgroup(Model *model, const FragmentGroup::Type class_t
for (Materials::iterator mit = map_materials.begin(); mit != map_materials.end(); mit++) {
// split the Primitives with this material into fragments
Primitives *primitives = (*mit).second;
-
+
// store triangles
if (primitives->triangles().size()) {
Fragment *fragment = new Fragment(Fragment::Triangles, primitives->material());
-
+
// add structural triangles to the fragment
for (Primitives::Triangles::iterator tris_it = primitives->triangles().begin(); tris_it != primitives->triangles().end(); tris_it++) {
Triangle *triangle = (*tris_it);
if (!triangle->detail()) {
size_t count = 0;
- count += fragment->add_vertex(triangle->v0()-group_center, triangle->normal(), triangle->t0(), false);
- count += fragment->add_vertex(triangle->v1()-group_center, triangle->normal(), triangle->t1(), false);
- count += fragment->add_vertex(triangle->v2()-group_center, triangle->normal(), triangle->t2(), false);
+ count += fragment->add_vertex(triangle->v0() - group_center, triangle->normal(), triangle->t0(), false);
+ count += fragment->add_vertex(triangle->v1() - group_center, triangle->normal(), triangle->t1(), false);
+ count += fragment->add_vertex(triangle->v2() - group_center, triangle->normal(), triangle->t2(), false);
if (count == 3)
model->model_tris_count++;
}
}
-
+
// add detail triangles to the fragment
for (Primitives::Triangles::iterator tris_it = primitives->triangles().begin(); tris_it != primitives->triangles().end(); tris_it++) {
Triangle *triangle = (*tris_it);
if (triangle->detail()) {
size_t count = 0;
- count += fragment->add_vertex(triangle->v0()-group_center, triangle->normal(), triangle->t0(), true);
- count += fragment->add_vertex(triangle->v1()-group_center, triangle->normal(), triangle->t1(), true);
- count += fragment->add_vertex(triangle->v2()-group_center, triangle->normal(), triangle->t2(), true);
+ count += fragment->add_vertex(triangle->v0() - group_center, triangle->normal(), triangle->t0(), true);
+ count += fragment->add_vertex(triangle->v1() - group_center, triangle->normal(), triangle->t1(), true);
+ count += fragment->add_vertex(triangle->v2() - group_center, triangle->normal(), triangle->t2(), true);
if (count == 3) {
model->model_tris_count++;
model->model_tris_detail_count++;
}
}
}
-
+
// add the fragment to the group
group->add_fragment(fragment);
}
@@ -902,41 +902,41 @@ void MapFile::load_fragmentgroup(Model *model, const FragmentGroup::Type class_t
// store quads
if (primitives->quads().size()) {
Fragment *fragment = new Fragment(Fragment::Quads, primitives->material());
-
+
// add structural quads to the fragment
for (Primitives::Quads::iterator quad_it = primitives->quads().begin(); quad_it != primitives->quads().end(); quad_it++) {
Quad *quad = (*quad_it);
if (!quad->detail()) {
size_t count = 0;
- count += fragment->add_vertex(quad->v0()-group_center, quad->normal(), quad->t0(), false);
- count += fragment->add_vertex(quad->v1()-group_center, quad->normal(), quad->t1(), false);
- count += fragment->add_vertex(quad->v2()-group_center, quad->normal(), quad->t2(), false);
- count += fragment->add_vertex(quad->v3()-group_center, quad->normal(), quad->t3(), false);
+ count += fragment->add_vertex(quad->v0() - group_center, quad->normal(), quad->t0(), false);
+ count += fragment->add_vertex(quad->v1() - group_center, quad->normal(), quad->t1(), false);
+ count += fragment->add_vertex(quad->v2() - group_center, quad->normal(), quad->t2(), false);
+ count += fragment->add_vertex(quad->v3() - group_center, quad->normal(), quad->t3(), false);
if (count == 4)
model->model_quad_count++;
}
}
-
+
// add detail quads to the fragment
for (Primitives::Quads::iterator quad_it = primitives->quads().begin(); quad_it != primitives->quads().end(); quad_it++) {
Quad *quad = (*quad_it);
if (quad->detail()) {
size_t count = 0;
- count += fragment->add_vertex(quad->v0()-group_center, quad->normal(), quad->t0(), false);
- count += fragment->add_vertex(quad->v1()-group_center, quad->normal(), quad->t1(), false);
- count += fragment->add_vertex(quad->v2()-group_center, quad->normal(), quad->t2(), false);
- count += fragment->add_vertex(quad->v3()-group_center, quad->normal(), quad->t3(), false);
+ count += fragment->add_vertex(quad->v0() - group_center, quad->normal(), quad->t0(), false);
+ count += fragment->add_vertex(quad->v1() - group_center, quad->normal(), quad->t1(), false);
+ count += fragment->add_vertex(quad->v2() - group_center, quad->normal(), quad->t2(), false);
+ count += fragment->add_vertex(quad->v3() - group_center, quad->normal(), quad->t3(), false);
if (count == 4) {
model->model_quad_count++;
model->model_quad_detail_count++;
}
}
}
-
+
// add the fragment to the group
group->add_fragment(fragment);
}
-
+
}
// add the group to the model
@@ -945,7 +945,7 @@ void MapFile::load_fragmentgroup(Model *model, const FragmentGroup::Type class_t
void MapFile::unknown_value() const
{
- con_warn << name() << " unknown value '" << value() << "' for '" << classname() << ":" << key() << "' at line " << line() << std::endl;
+ con_warn << name() << " unknown value '" << value() << "' for '" << classname() << ":" << key() << "' at line " << line() << std::endl;
}
void MapFile::unknown_key() const
@@ -962,14 +962,14 @@ Model * MapFile::load(std::string const &name)
{
// open the .map file
MapFile mapfile;
-
+
if (!mapfile.open(name)) {
return 0;
}
-
+
Model *model = new Model(name);
mapfile.clear_bbox();
-
+
Dock *dock = 0;
Particles *particles = 0;
Flare *flare = 0;
@@ -989,16 +989,16 @@ Model * MapFile::load(std::string const &name)
std::string str;
while (mapfile.getline()) {
-
+
if (mapfile.got_classname("worldspawn")) {
mapfile.clear_bbox();
} else if (mapfile.got_classend("worldspawn")) {
mapfile.load_worldspawn(model);
mapfile.clear_materials();
-
+
} else if (mapfile.in_class("worldspawn")) {
-
+
// worldspawn attributes
if (mapfile.got_key("name")) {
//con_debug << " model name '" << name << "'" << std::endl;
@@ -1044,7 +1044,7 @@ Model * MapFile::load(std::string const &name)
mapfile.clear_materials();
} else if (mapfile.in_class("func_rotate")) {
-
+
if (mapfile.got_key_float("angle", angle)) {
if (angle == ANGLEUP) {
mapfile.class_axis.change_pitch(90.0f);
@@ -1073,101 +1073,101 @@ Model * MapFile::load(std::string const &name)
mapfile.clear_materials();
} else if (mapfile.got_classname("light")) {
-
+
// new light
light = new Light();
model->add_light(light);
continue;
-
+
} else if (mapfile.classname().compare("light") == 0) {
-
+
// light attributes
if (mapfile.got_key_vector3f("origin", location)) {
light->get_location().assign(location * SCALE);
continue;
-
+
} else if (mapfile.got_key_color("_color", color)) {
light->get_color().assign(color);
continue;
-
+
} else if (mapfile.got_key_int("spawnflags", u)) {
light->set_strobe(spawnflag_isset(u, 1));
light->set_entity(spawnflag_isset(u, 2));
light->set_engine(spawnflag_isset(u, 4));
continue;
-
+
} else if (mapfile.got_key_float("light", r)) {
- light->set_radius( r * LIGHTSCALE);
+ light->set_radius(r * LIGHTSCALE);
continue;
-
+
} else if (mapfile.got_key_float("radius", r)) {
- light->set_radius( r * LIGHTSCALE);
+ light->set_radius(r * LIGHTSCALE);
continue;
} else if (mapfile.got_key_float("frequency", r)) {
light->set_frequency(r);
continue;
-
+
} else if (mapfile.got_key_float("offset", r)) {
light->set_offset(r);
continue;
-
+
} else if (mapfile.got_key_float("time", r)) {
light->set_time(r);
continue;
-
+
} else if (mapfile.got_key_int("flare", u)) {
light->set_flare(u);
continue;
-
+
} else if (mapfile.got_key()) {
mapfile.unknown_key();
continue;
-
+
}
} else if (mapfile.got_classname("fx_flare")) {
-
+
// new flare
flare = new Flare();
model->add_flare(flare);
} else if (mapfile.classname().compare("fx_flare") == 0) {
-
+
// flare attributes
if (mapfile.got_key_vector3f("origin", location)) {
flare->get_location().assign(location * SCALE);
continue;
-
+
} else if (mapfile.got_key_color("_color", color)) {
flare->get_color().assign(color);
continue;
-
+
} else if (mapfile.got_key_int("spawnflags", u)) {
flare->set_strobe(spawnflag_isset(u, 1));
flare->set_entity(spawnflag_isset(u, 2));
flare->set_engine(spawnflag_isset(u, 4));
-
+
} else if (mapfile.got_key_float("light", r)) {
- flare->set_radius( r * LIGHTSCALE);
+ flare->set_radius(r * LIGHTSCALE);
continue;
} else if (mapfile.got_key_float("radius", r)) {
- flare->set_radius( r * LIGHTSCALE);
+ flare->set_radius(r * LIGHTSCALE);
continue;
} else if (mapfile.got_key_float("frequency", r)) {
flare->set_frequency(r);
continue;
-
+
} else if (mapfile.got_key_float("offset", r)) {
flare->set_offset(r);
continue;
-
+
} else if (mapfile.got_key_float("time", r)) {
flare->set_time(r);
continue;
-
+
} else if (mapfile.got_key_int("flare", u)) {
flare->set_flare(u);
continue;
@@ -1188,7 +1188,7 @@ Model * MapFile::load(std::string const &name)
} else if (mapfile.got_key_float("roll", angle)) {
flare->get_axis().change_roll(angle);
-
+
} else if (mapfile.got_key_string("cull", str)) {
aux::to_lowercase(str);
@@ -1201,7 +1201,7 @@ Model * MapFile::load(std::string const &name)
} else {
mapfile.unknown_value();
}
-
+
} else if (mapfile.got_key()) {
mapfile.unknown_key();
}
@@ -1211,7 +1211,7 @@ Model * MapFile::load(std::string const &name)
// new particle system
particles = new Particles();
model->add_particles(particles);
-
+
} else if (mapfile.classname().compare("fx_particles") == 0) {
// particle system attributes
@@ -1246,7 +1246,7 @@ Model * MapFile::load(std::string const &name)
} else if (mapfile.got_key_float("radius", r)) {
particles->set_radius(r * LIGHTSCALE);
-
+
} else if (mapfile.got_key_string("cull", str)) {
aux::to_lowercase(str);
@@ -1269,7 +1269,7 @@ Model * MapFile::load(std::string const &name)
// new submodel
submodel = new SubModel();
submodel_list.push_back(submodel);
-
+
} else if (mapfile.classname().compare("misc_model") == 0) {
// submodel attributes
@@ -1281,7 +1281,7 @@ Model * MapFile::load(std::string const &name)
// remove extension
if (modelname[modelname.size()-4] == '.') {
- modelname.erase(modelname.size()-4);
+ modelname.erase(modelname.size() - 4);
}
submodel->set_name(modelname);
@@ -1303,7 +1303,7 @@ Model * MapFile::load(std::string const &name)
submodel->set_scale(1.0f);
}
}
-
+
} else if (mapfile.got_classname("location_dock")) {
// new docking location
@@ -1316,18 +1316,18 @@ Model * MapFile::load(std::string const &name)
if (mapfile.got_key_vector3f("origin", location)) {
dock->get_location().assign(location * SCALE);
continue;
-
+
} else if (mapfile.got_key_float("radius", r)) {
- dock->set_radius (r * SCALE);
+ dock->set_radius(r * SCALE);
continue;
-
+
} else if (mapfile.got_key("angle")) {
// TODO
continue;
} else if (mapfile.got_key()) {
mapfile.unknown_key();
-
+
}
} else if (mapfile.got_classname("location_cannon")) {
@@ -1356,21 +1356,21 @@ Model * MapFile::load(std::string const &name)
} else if (mapfile.got_classname()) {
- mapfile.unknown_class();
+ mapfile.unknown_class();
}
}
-
+
mapfile.close();
// reposition docks, lights, flares and particles according to the model center
for (Model::Lights::iterator lit = model->lights().begin(); lit != model->lights().end(); lit++) {
(*lit)->get_location() -= mapfile.map_center;
}
-
+
for (Model::Flares::iterator flit = model->flares().begin(); flit != model->flares().end(); flit++) {
(*flit)->get_location() -= mapfile.map_center;
}
-
+
for (Model::ParticleSystems::iterator pit = model->particles().begin(); pit != model->particles().end(); pit++) {
(*pit)->get_location() -= mapfile.map_center;
}
@@ -1399,7 +1399,7 @@ Model * MapFile::load(std::string const &name)
groupdst->set_type(groupsrc->type());
groupdst->set_scale(groupsrc->scale() * submodel->scale());
groupdst->set_speed(groupsrc->speed());
- groupdst->set_location(submodel->location() + (submodel_model->origin() + groupsrc->location()) * submodel->scale() );
+ groupdst->set_location(submodel->location() + (submodel_model->origin() + groupsrc->location()) * submodel->scale());
groupdst->set_axis(groupsrc->axis() * submodel->axis());
// copy fragments
@@ -1416,7 +1416,7 @@ Model * MapFile::load(std::string const &name)
}
// recalculate bbox
- for (size_t i =0; i < 3; i ++) {
+ for (size_t i = 0; i < 3; i ++) {
float c;
c = submodel->location()[i] + (submodel_model->origin()[i] + submodel_model->model_maxbbox[i]) * submodel->scale();
if (c > model->model_maxbbox[i]) {
@@ -1438,14 +1438,14 @@ Model * MapFile::load(std::string const &name)
light->set_radius(light->radius() * submodel->scale());
model->add_light(light);
}
-
+
for (Model::Flares::const_iterator flit = submodel_model->flares().begin(); flit != submodel_model->flares().end(); flit++) {
flare = new Flare(*(*flit));
flare->get_location().assign(submodel->location() + (submodel_model->origin() + flare->location()) * submodel->scale());
flare->set_radius(flare->radius() * submodel->scale());
model->add_flare(flare);
}
-
+
for (Model::ParticleSystems::const_iterator pit = submodel_model->particles().begin(); pit != submodel_model->particles().end(); pit++) {
particles = new Particles(*(*pit));
particles->get_location().assign(submodel->location() + (submodel_model->origin() + particles->location()) * submodel->scale());
@@ -1453,7 +1453,7 @@ Model * MapFile::load(std::string const &name)
model->add_particles(particles);
}
-
+
//con_debug << " imported submodel '" << submodel->name() << "'" << std::endl;
}
@@ -1465,8 +1465,8 @@ Model * MapFile::load(std::string const &name)
con_warn << mapfile.name() << " quake2 style brushes detected" << std::endl;
con_debug << " " << mapfile.name() << " " << mapfile.map_brushes << " brushes " <<
- model->model_tris_detail_count << "/" << model->model_tris_count << " detail/tris " <<
- model->model_quad_detail_count << "/" << model->model_quad_count << " detail/quads" << std::endl;
+ model->model_tris_detail_count << "/" << model->model_tris_count << " detail/tris " <<
+ model->model_quad_detail_count << "/" << model->model_quad_count << " detail/quads" << std::endl;
return model;
diff --git a/src/model/mapfile.h b/src/model/mapfile.h
index 0cf66a5..be1e789 100644
--- a/src/model/mapfile.h
+++ b/src/model/mapfile.h
@@ -30,42 +30,39 @@ public:
* If the file can not be read, load() returns the NULL-pointer
*/
static Model *load(std::string const &name);
-
+
private:
MapFile();
~MapFile();
-
+
/// tpye definition for a per-material list of Primitives
typedef std::map<Material *, Primitives *> Materials;
-
+
/// open the file for reading
/** the filename will get the "maps/" prefix and ".map" suffix
*/
bool open(std::string const & name);
-
+
/// parse one line, returns false on end-of-file
bool getline();
bool read_patchdef();
-
+
/// current classname
- inline std::string classname() const
- {
+ inline std::string classname() const {
return classname_current;
}
-
+
/// current key
- inline std::string key() const
- {
+ inline std::string key() const {
return key_current;
}
-
+
/// current value
- inline std::string value() const
- {
+ inline std::string value() const {
return value_current;
}
-
+
/// true if the last read line contained a new classname
bool got_classname() const;
@@ -75,67 +72,62 @@ private:
}
/// true if the last read line contained a class closing bracket
- inline bool got_classend() const
- {
+ inline bool got_classend() const {
return last_read_was_classend;
}
-
+
/// true if the last read line contained the closing bracket for the requested class
bool got_classend(const char*) const;
/// true if the last read line contained a new classname
bool got_classname(const char*) const;
-
+
/// true if the last read statement was a key=value pair
- inline bool got_key() const
- {
+ inline bool got_key() const {
return last_read_was_key;
}
-
+
bool got_key(const char * keylabel);
-
+
/// check if the last read key=value pair matches keylabel and store the value in valuestring
bool got_key_string(const char * keylabel, std::string & valuestring);
-
+
/// check if the last read key=value pair matches keylabel and store the value in color
bool got_key_color(const char * keylabel, math::Color & color);
-
+
/// check if the last read key=value pair matches keylabel and store the value in f
bool got_key_float(const char * keylabel, float & f);
-
+
/// check if the last read key=value pair matches keylabel and store the value in f
bool got_key_int(const char * keylabel, unsigned int & u);
-
+
/// check if the last read key=value pair matches keylabel and store the value in valuestring
bool got_key_angle(const char * keylabel, float & f);
-
+
bool got_key_vector3f(const char * keylabel, math::Vector3f & v);
-
-
+
+
/// return the number of lines read so far
- inline unsigned int line() const
- {
+ inline unsigned int line() const {
return line_number;
}
-
+
/// return true of the map file is open for reading
- inline bool is_open()
- {
+ inline bool is_open() {
return mapfile_ifs.is_open();
}
-
+
/// current filename
- inline std::string const & name() const
- {
+ inline std::string const & name() const {
return mapfile_name;
}
-
+
/// close the file
void close();
-
+
/// generate triangles for one plane in the plane list
void make_brushface(Face *face);
-
+
/// load parsed primitives into model worldspawn
void load_worldspawn(Model *model);
@@ -153,28 +145,28 @@ private:
void unknown_key() const;
void unknown_value() const;
-
+
/// list of planes for the current brush
std::vector<Face *> planes;
-
+
std::string classname_current;
std::string key_current;
std::string value_current;
-
+
bool last_read_was_key;
bool last_read_was_classname;
bool last_read_was_classend;
-
+
unsigned int map_brushes;
unsigned int map_faces;
unsigned int map_faces_detail;
-
+
unsigned int parse_level;
unsigned int line_number;
filesystem::IFileStream mapfile_ifs;
std::string mapfile_name;
-
+
math::Vector3f class_maxbbox;
math::Vector3f class_minbbox;
math::Axis class_axis;
diff --git a/src/model/material.cc b/src/model/material.cc
index 416e491..6baf4f9 100644
--- a/src/model/material.cc
+++ b/src/model/material.cc
@@ -19,9 +19,9 @@ Material::LoaderFuncPtr Material::material_loaderfunc = 0;
Material::Registry Material::material_registry;
Material::Material(const std::string &name) :
- material_name(name),
- material_color(1.0f) ,
- material_size(64.0f, 64.0f)
+ material_name(name),
+ material_color(1.0f) ,
+ material_size(64.0f, 64.0f)
{
aux::to_lowercase(material_name);
material_flags = 0;
@@ -41,11 +41,16 @@ void Material::set_color(const math::Color &color)
void Material::set_texture(const std::string &texture)
{
- material_texture.assign(texture);
-
- if (material_loaderfunc) {
- material_loaderfunc(this);
- //con_debug << " material " << name() << " " << size().width() << "x" << size().height() << std::endl;
+ if (texture.size()) {
+ set_flags(Texture);
+ material_texture.assign(texture);
+ if (material_loaderfunc) {
+ material_loaderfunc(this);
+ }
+ } else {
+ unset_flags(Texture);
+ material_texture.clear();
+ material_texture_id = 0;
}
}
@@ -80,8 +85,8 @@ void Material::init()
while (shaderlist.getline(line, 1023)) {
if ((line[0] == 0) || (line[0] == '#') || (line[0] == ';')) {
continue;
- if ((line[0] == '/') && (line[1] == '/'))
- continue;
+ if ((line[0] == '/') && (line[1] == '/'))
+ continue;
} else {
std::string s(line);
aux::trim(s);
@@ -115,7 +120,7 @@ void Material::load_shader(const std::string &shadername)
unsigned int linenumber = 0;
char line[1024];
unsigned int count = 0;
- float r,g,b;
+ float r, g, b;
Material *material = 0;
while (shaderfile.getline(line, 1023)) {
@@ -130,12 +135,12 @@ void Material::load_shader(const std::string &shadername)
continue;
// skip comments
- if ((s[0] == '#') || (s[0] == ';') || ((s[0] == '/') && (s[1] == '/')))
+ if ((s[0] == '#') || (s[0] == ';') || ((s[0] == '/') && (s[1] == '/')))
continue;
-
+
std::istringstream linestream(s);
std::string firstword;
-
+
if (linestream >> firstword) {
if (firstword.compare("//") == 0) {
continue;
@@ -146,7 +151,7 @@ void Material::load_shader(const std::string &shadername)
} else if (firstword.compare("{") == 0) {
parselevel++;
- } else if ((firstword.size()) && (parselevel == 0) ) {
+ } else if ((firstword.size()) && (parselevel == 0)) {
material = find(firstword);
if (material) {
@@ -163,8 +168,10 @@ void Material::load_shader(const std::string &shadername)
if (firstword.compare("color") == 0) {
if (linestream >> r >> g >> b) {
if (math::max(r, math::max(g, b)) > 1.0f) {
- r /= 255.0f; g /= 255.0f; b /= 255.0f;
- }
+ r /= 255.0f;
+ g /= 255.0f;
+ b /= 255.0f;
+ }
material->set_color(math::Color(r, g, b, 1.0f));
}
} else if (firstword.compare("engine") == 0) {
@@ -178,7 +185,7 @@ void Material::load_shader(const std::string &shadername)
} else if (firstword.compare("entitysecond") == 0) {
material->set_flags(Secondary);
} else if (firstword.compare("entitythird") == 0) {
- material->set_flags(Tertiary);
+ material->set_flags(Tertiary);
} else if (firstword.compare("ignore") == 0) {
material->set_flags(Ignore);
} else if (firstword.compare("qer_editorimage") == 0) {
@@ -189,19 +196,19 @@ void Material::load_shader(const std::string &shadername)
// texture name should not contain spaces
if (linestream >> firstword) {
+
// remove extension
if (firstword[firstword.size()-4] == '.') {
- firstword.erase(firstword.size()-4);
+ firstword.erase(firstword.size() - 4);
}
material->set_texture(firstword);
- material->set_flags(Material::Texture);
} else {
con_warn << shaderfile.name() << " texture key without filename at line " << linenumber << std::endl;
}
} else {
- con_warn << shaderfile.name() << " unknown key '" << firstword
- << "' at line " << linenumber << std::endl;
+ con_warn << shaderfile.name() << " unknown key '" << firstword
+ << "' at line " << linenumber << std::endl;
}
}
}
@@ -222,7 +229,7 @@ void Material::clear()
con_print << "^BClearing materials..." << std::endl;
for (Registry::iterator i = material_registry.begin(); i != material_registry.end(); ++i) {
- delete (*i).second;
+ delete(*i).second;
}
material_registry.clear();
diff --git a/src/model/material.h b/src/model/material.h
index 9185fd2..44470e5 100644
--- a/src/model/material.h
+++ b/src/model/material.h
@@ -24,7 +24,7 @@ public:
typedef void(* LoaderFuncPtr)(Material *);
/// surface flags
- enum SurfaceFlags { None=0, Primary=1, Secondary=2, Tertiary=3, Bright=4, Engine=8, Environment=16, Texture=32, Ignore=64};
+ enum SurfaceFlags { None = 0, Primary = 1, Secondary = 2, Tertiary = 3, Bright = 4, Engine = 8, Environment = 16, Texture = 32, Ignore = 64};
/// type definition for the material registry
typedef std::map<std::string, Material *> Registry;
@@ -35,20 +35,32 @@ public:
/* ---- inspectors ----------------------------------------- */
- inline const std::string &name() const { return material_name; }
+ inline const std::string &name() const {
+ return material_name;
+ }
- inline const math::Color &color() const { return material_color; }
+ inline const math::Color &color() const {
+ return material_color;
+ }
- inline const unsigned int flags() const { return material_flags; }
+ inline const unsigned int flags() const {
+ return material_flags;
+ }
- inline const std::string &texture() const { return material_texture; }
+ inline const std::string &texture() const {
+ return material_texture;
+ }
- inline const size_t texture_id() const { return material_texture_id; }
+ inline const size_t texture_id() const {
+ return material_texture_id;
+ }
/**
* @brief returns the material texture size
*/
- inline const math::Vector2f & size() const { return material_size; }
+ inline const math::Vector2f & size() const {
+ return material_size;
+ }
/* ---- mutators ------------------------------------------- */
@@ -74,16 +86,14 @@ public:
*/
void set_size(const math::Vector2f &size);
- inline void set_flags(SurfaceFlags flags)
- {
+ inline void set_flags(SurfaceFlags flags) {
material_flags |= flags;
}
- inline void unset_flags(SurfaceFlags flags)
- {
+ inline void unset_flags(SurfaceFlags flags) {
material_flags &= ~flags;
}
-
+
/* ---- static ----------------------------------------------------- */
/**
@@ -92,12 +102,12 @@ public:
*/
static void init();
- /**
+ /**
* @brief shutdown material registry
*/
static void shutdown();
- /**
+ /**
* @brief clear material registry
*/
static void clear();
diff --git a/src/model/model.cc b/src/model/model.cc
index 2b3ec7a..85bf609 100644
--- a/src/model/model.cc
+++ b/src/model/model.cc
@@ -17,14 +17,14 @@ namespace model
Model::Registry Model::model_registry;
Model::Model(const std::string & name) :
- model_enginecolor(1.0f, 0.0f, 0.0f),
- model_name(name)
-
+ model_enginecolor(1.0f, 0.0f, 0.0f),
+ model_name(name)
+
{
model_radius = 0.5f;
model_enginesound = 0;
model_impulsesound = 0;
-
+
model_tris_detail_count = 0;
model_tris_count = 0;
model_quad_detail_count = 0;
@@ -35,28 +35,28 @@ Model::~Model()
{
// delete all fragment groups
for (Groups::iterator git = model_groups.begin(); git != model_groups.end(); git++) {
- delete (*git);
+ delete(*git);
}
model_groups.clear();
-
+
// delete all docks
for (Docks::iterator dit = model_docks.begin(); dit != model_docks.end(); dit++) {
- delete (*dit);
+ delete(*dit);
}
model_docks.clear();
// delete all particle systems
for (Model::ParticleSystems::iterator pit = model_particles.begin(); pit != model_particles.end(); pit++) {
- delete (*pit);
+ delete(*pit);
}
model_particles.clear();
-
+
// delete all lights
for (Lights::iterator lit = model_lights.begin(); lit != model_lights.end(); lit++) {
delete(*lit);
}
model_lights.clear();
-
+
// delete all flares
for (Flares::iterator flit = model_flares.begin(); flit != model_flares.end(); flit++) {
delete(*flit);
@@ -115,18 +115,18 @@ Model *Model::load(const std::string & name)
// try loading the .map model
model = MapFile::load(name);
}
-
+
if (!model) {
// if it can't be found, try the ase model
model = ASEFile::load(name);
}
-
- if (!model) {
+
+ if (!model) {
con_warn << "Could not open model " << name << std::endl;
} else {
model_registry[model->name()] = model;
}
-
+
return model;
}
@@ -137,7 +137,7 @@ void Model::clear()
delete(*mit).second;
}
model_registry.clear();
-
+
// clear the vertex array
if (VertexArray::instance())
VertexArray::instance()->clear();
@@ -159,18 +159,18 @@ void Model::list()
{
for (Registry::iterator mit = model_registry.begin(); mit != model_registry.end(); mit++) {
list_model((*mit).second);
-
+
}
-
+
con_print << model_registry.size() << " registered models" << std::endl;
if (VertexArray::instance()) {
-
+
con_print << "vertex array "
- << VertexArray::instance()->index() * 3 * sizeof(float) / (1024*1024) << "/"
- << VertexArray::instance()->size() * 3 * sizeof(float) / (1024*1024) << "Mb "
- << VertexArray::instance()->index() / 3 << "/" << VertexArray::instance()->size() / 3 << " verts "
- << (VertexArray::instance()->index() * 100 / VertexArray::instance()->size())<< "% used"
- << std::endl;
+ << VertexArray::instance()->index() * 3 * sizeof(float) / (1024*1024) << "/"
+ << VertexArray::instance()->size() * 3 * sizeof(float) / (1024*1024) << "Mb "
+ << VertexArray::instance()->index() / 3 << "/" << VertexArray::instance()->size() / 3 << " verts "
+ << (VertexArray::instance()->index() * 100 / VertexArray::instance()->size()) << "% used"
+ << std::endl;
}
}
diff --git a/src/model/model.h b/src/model/model.h
index af3b1dc..30714d4 100644
--- a/src/model/model.h
+++ b/src/model/model.h
@@ -32,16 +32,16 @@ class Model
public:
/// type definition for the model registry
typedef std::map<std::string, Model*> Registry;
-
+
/// type definition for a list of model fragments
typedef std::list<Fragment *> Fragments;
-
+
/// type definition for a list of model lights
typedef std::list<Light *> Lights;
-
+
/// type definition for a list of model flares
typedef std::list<Flare *> Flares;
-
+
/// type definition for a lost of dockable locations
typedef std::list<Dock *> Docks;
@@ -50,97 +50,84 @@ public:
/// type definition for a list of FragmentGroups
typedef std::list<FragmentGroup *> Groups;
-
+
/// create a model with a name
Model(const std::string & name);
-
+
/// delete the model, and all fragments, lights, etc
~Model();
-
+
/// the name of the model
- inline const std::string & name() const
- {
+ inline const std::string & name() const {
return model_name;
}
-
+
/// radius
- inline float radius() const
- {
+ inline float radius() const {
return model_radius;
}
-
+
/// additional model fragment groups
- inline Groups & groups()
- {
+ inline Groups & groups() {
return model_groups;
}
/// list of lights
- inline Lights & lights()
- {
+ inline Lights & lights() {
return model_lights;
}
/// list of dockable locations
- inline Docks & docks()
- {
+ inline Docks & docks() {
return model_docks;
}
-
+
/// list of flares
- inline Flares & flares()
- {
+ inline Flares & flares() {
return model_flares;
}
-
+
/// list of engines
- inline ParticleSystems & particles()
- {
+ inline ParticleSystems & particles() {
return model_particles;
}
-
+
/// maximum values of the bounding box
- inline const math::Vector3f & maxbbox() const
- {
+ inline const math::Vector3f & maxbbox() const {
return model_maxbbox;
}
-
+
/// minimum values of the bounding box
- inline const math::Vector3f & minbbox() const
- {
+ inline const math::Vector3f & minbbox() const {
return model_minbbox;
}
-
+
/// engine sound loop for this model
- inline unsigned int enginesound() const
- {
+ inline unsigned int enginesound() const {
return model_enginesound;
}
/// impulse sound set for this model
- inline unsigned int impulsesound() const
- {
+ inline unsigned int impulsesound() const {
return model_impulsesound;
}
/// engine color for this model
- inline const math::Color & enginecolor() const
- {
+ inline const math::Color & enginecolor() const {
return model_enginecolor;
}
/// original origin
- inline const math::Vector3f & origin() const
- {
+ inline const math::Vector3f & origin() const {
return model_origin;
}
-
+
/// add a light to the model
void add_light(Light *light);
-
+
/// add a particle system to the model
void add_particles(Particles *particles);
-
+
/// add a flare to the model
void add_flare(Flare *flare);
@@ -153,15 +140,15 @@ public:
void set_radius(const float radius);
void set_origin(const math::Vector3f &origin);
-
+
math::Vector3f model_maxbbox;
math::Vector3f model_minbbox;
-
+
unsigned int model_enginesound;
unsigned int model_impulsesound;
math::Color model_enginecolor;
-
+
/// total number of triangles
size_t model_tris_count;
/// number of detail triangles
@@ -172,29 +159,28 @@ public:
size_t model_quad_detail_count;
/* ---- static functions for the Model registry -------------------- */
-
+
/// the model registry
- static inline Registry & registry()
- {
+ static inline Registry & registry() {
return model_registry;
}
-
+
/// get name model, returns 0 if not found
static Model *find(const std::string & name);
-
+
/// get named model from the registry and load it if necessary
static Model *load(const std::string & name);
-
+
/// clear the model registry
static void clear();
-
+
/// list the content of the model registry
static void list();
-
+
/// list one model
static void list_model(Model *model);
-
+
private:
std::string model_name;
diff --git a/src/model/parts.cc b/src/model/parts.cc
index ac54410..e71ad16 100644
--- a/src/model/parts.cc
+++ b/src/model/parts.cc
@@ -6,7 +6,8 @@
#include "model/parts.h"
-namespace model {
+namespace model
+{
/* ---- class Light ------------------------------------------------ */
@@ -24,12 +25,12 @@ Light::Light() :
light_time = 0.5f;
light_flare = 0;
-
+
light_texture = 0;
}
Light::Light(const Light& other) : Part(other),
- light_color(other.color())
+ light_color(other.color())
{
light_entity = other.entity();
light_engine = other.engine();
@@ -41,7 +42,7 @@ Light::Light(const Light& other) : Part(other),
light_time = other.time();
light_flare = other.flare();
-
+
light_texture = other.texture();
}
Light::~Light()
@@ -105,8 +106,8 @@ SubModel::SubModel() : Part()
}
SubModel::SubModel(const SubModel& other) : Part(other),
- submodel_name(other.name()),
- submodel_axis(other.axis())
+ submodel_name(other.name()),
+ submodel_axis(other.axis())
{
submodel_scale = other.scale();
}
diff --git a/src/model/parts.h b/src/model/parts.h
index 210a225..4df4672 100644
--- a/src/model/parts.h
+++ b/src/model/parts.h
@@ -24,7 +24,7 @@ namespace model
* Culling is a paremeter used by flares and particles to indicate
* with side of the polygons should be culled during rendering
*/
-enum Cull { CullNone=0, CullBack=1, CullFront=2 };
+enum Cull { CullNone = 0, CullBack = 1, CullFront = 2 };
/* ---- class Part ------------------------------------------------- */
@@ -37,23 +37,20 @@ public:
/**
* @brief default constructor
*/
- inline Part() : part_location()
- {
+ inline Part() : part_location() {
}
/**
* @brief copy constructor
*/
- inline Part(const Part& other) : part_location(other.location())
- {
+ inline Part(const Part& other) : part_location(other.location()) {
}
/**
* @brief constructor with location
* @param location location of this part within the parent model
*/
- inline Part(const math::Vector3f& location) : part_location(location)
- {
+ inline Part(const math::Vector3f& location) : part_location(location) {
}
/* ---- inspectors ----------------------------------------- */
@@ -61,8 +58,7 @@ public:
/**
* @brief location of this part within the parent model
*/
- inline const math::Vector3f& location() const
- {
+ inline const math::Vector3f& location() const {
return part_location;
}
@@ -70,22 +66,25 @@ public:
/**
* @brief set the location within the parent model
*/
- inline void set_location(const math::Vector3f& location) { part_location.assign(location); }
+ inline void set_location(const math::Vector3f& location) {
+ part_location.assign(location);
+ }
/**
* @brief set the location within the parent model
*/
- inline void set_location(const float x, const float y, const float z) { part_location.assign(x, y, z); }
+ inline void set_location(const float x, const float y, const float z) {
+ part_location.assign(x, y, z);
+ }
/* ---- actors --------------------------------------------- */
/**
* @brief mutable reference to the location of this part within the parent model
*/
- inline math::Vector3f& get_location()
- {
+ inline math::Vector3f& get_location() {
return part_location;
- }
+ }
private:
math::Vector3f part_location;
@@ -111,66 +110,56 @@ public:
* @brief destructor
*/
~Light();
-
+
/* ---- inspectors ----------------------------------------- */
/// light color
- inline const math::Color& color() const
- {
+ inline const math::Color& color() const {
return light_color;
};
-
+
/// true if this is a strobe light
- inline bool strobe() const
- {
+ inline bool strobe() const {
return light_strobe;
}
-
+
/// true if this light has entity color
- inline bool entity() const
- {
+ inline bool entity() const {
return light_entity;
}
/// true if this light has engine activation
- inline bool engine() const
- {
+ inline bool engine() const {
return light_engine;
}
-
+
/// size of the light, default is 1.0f
- inline float radius() const
- {
+ inline float radius() const {
return light_radius;
}
-
+
/// strobe time offset, in seconds
- inline float offset() const
- {
+ inline float offset() const {
return light_offset;
}
-
+
/// strobe frequency in strobes per second, default is 1.0f
- inline float frequency() const
- {
+ inline float frequency() const {
return light_frequency;
}
-
+
/// fraction a strobe light will be on, default is 0.5f
- inline float time() const
- {
+ inline float time() const {
return light_time;
}
-
+
/// flare texture number
- inline unsigned int flare() const
- {
+ inline unsigned int flare() const {
return light_flare;
}
-
+
/// render texture id
- inline size_t texture() const
- {
+ inline size_t texture() const {
return light_texture;
}
/* ---- mutators ------------------------------------------- */
@@ -178,53 +167,73 @@ public:
/**
* @brief set strobe color on or off
*/
- inline void set_strobe(const bool strobe) { light_strobe = strobe; }
+ inline void set_strobe(const bool strobe) {
+ light_strobe = strobe;
+ }
/**
* @brief set entity color on or off
*/
- inline void set_entity(const bool entity) { light_entity = entity; }
+ inline void set_entity(const bool entity) {
+ light_entity = entity;
+ }
/**
* @brief set engine activation on or off
*/
- inline void set_engine(const bool engine) { light_engine = engine; }
+ inline void set_engine(const bool engine) {
+ light_engine = engine;
+ }
/**
* @brief set the light radius
*/
- inline void set_radius(const float radius) { light_radius = radius; }
+ inline void set_radius(const float radius) {
+ light_radius = radius;
+ }
/**
* @brief set the light strobe frequency, in strobes per second
*/
- inline void set_frequency(const float frequency) { light_frequency = frequency; }
+ inline void set_frequency(const float frequency) {
+ light_frequency = frequency;
+ }
/**
* @brief set the light on time, from 0.0 (always off) to 1.0 (always on)
*/
- inline void set_time(const float time) { light_radius = time; }
+ inline void set_time(const float time) {
+ light_radius = time;
+ }
/**
* @brief set the light strobe time offset, in seconds
*/
- inline void set_offset(const float offset) { light_offset = offset; }
+ inline void set_offset(const float offset) {
+ light_offset = offset;
+ }
/**
* @brief set the flare texture number
*/
- inline void set_flare(unsigned int flare) { light_flare = flare; }
+ inline void set_flare(unsigned int flare) {
+ light_flare = flare;
+ }
/**
* @brief set the render texture id
*/
- inline void set_texture(size_t texture) { light_texture = texture; }
+ inline void set_texture(size_t texture) {
+ light_texture = texture;
+ }
/**
* @brief mutable reference to the color
*/
- inline math::Color& get_color() { return light_color; }
-
+ inline math::Color& get_color() {
+ return light_color;
+ }
+
private:
bool light_strobe;
bool light_engine;
@@ -256,29 +265,31 @@ public:
Flare(const Flare& other);
~Flare();
-
+
/* ---- inspectors ----------------------------------------- */
- inline const math::Axis &axis() const
- {
+ inline const math::Axis &axis() const {
return flare_axis;
}
-
- inline Cull cull() const
- {
+
+ inline Cull cull() const {
return flare_cull;
}
/* ---- mutators ------------------------------------------- */
-
- inline void set_cull(const Cull cull) { flare_cull = cull; }
+
+ inline void set_cull(const Cull cull) {
+ flare_cull = cull;
+ }
/* ---- actors --------------------------------------------- */
/**
* @brief mutable reference to the axis
*/
- inline math::Axis& get_axis() { return flare_axis; }
+ inline math::Axis& get_axis() {
+ return flare_axis;
+ }
private:
Cull flare_cull;
@@ -296,34 +307,28 @@ public:
Particles(const math::Vector3f & location);
~Particles();
-
- inline const math::Axis &axis() const
- {
+
+ inline const math::Axis &axis() const {
return particles_axis;
}
-
- inline const std::string& script() const
- {
+
+ inline const std::string& script() const {
return particles_script;
}
- inline bool entity() const
- {
+ inline bool entity() const {
return particles_entity;
}
- inline bool engine() const
- {
+ inline bool engine() const {
return particles_engine;
}
-
- inline float radius() const
- {
+
+ inline float radius() const {
return particles_radius;
}
- inline Cull cull() const
- {
+ inline Cull cull() const {
return particles_cull;
}
@@ -332,25 +337,37 @@ public:
/**
* @brief set entity color on or off
*/
- inline void set_entity(const bool entity) { particles_entity = entity; }
+ inline void set_entity(const bool entity) {
+ particles_entity = entity;
+ }
/**
* @brief set engine activation on or off
*/
- inline void set_engine(const bool engine) { particles_engine = engine; }
+ inline void set_engine(const bool engine) {
+ particles_engine = engine;
+ }
- inline void set_radius(const float radius) { particles_radius = radius; }
+ inline void set_radius(const float radius) {
+ particles_radius = radius;
+ }
- inline void set_cull(const Cull cull) { particles_cull = cull; }
+ inline void set_cull(const Cull cull) {
+ particles_cull = cull;
+ }
- inline void set_script(const std::string& script) { particles_script.assign(script); }
+ inline void set_script(const std::string& script) {
+ particles_script.assign(script);
+ }
/* ---- actors --------------------------------------------- */
/**
* @brief mutable reference to the axis
*/
- inline math::Axis& get_axis() { return particles_axis; }
+ inline math::Axis& get_axis() {
+ return particles_axis;
+ }
private:
bool particles_entity;
@@ -360,7 +377,7 @@ private:
float particles_radius;
- math::Axis particles_axis;
+ math::Axis particles_axis;
std::string particles_script;
};
@@ -378,15 +395,16 @@ public:
Dock(const Dock& other);
~Dock();
-
+
/// dock radius, default is 0.01f
- inline float radius() const
- {
+ inline float radius() const {
return dock_radius;
}
- /// set dock radius
- inline void set_radius(const float radius) { dock_radius = radius; }
+ /// set dock radius
+ inline void set_radius(const float radius) {
+ dock_radius = radius;
+ }
private:
float dock_radius;
@@ -404,25 +422,39 @@ public:
~SubModel();
- inline const std::string& name() const { return submodel_name; }
+ inline const std::string& name() const {
+ return submodel_name;
+ }
- inline const math::Axis& axis() const { return submodel_axis; }
+ inline const math::Axis& axis() const {
+ return submodel_axis;
+ }
- inline float scale() const { return submodel_scale; }
+ inline float scale() const {
+ return submodel_scale;
+ }
- inline void set_scale(const float scale) { submodel_scale = scale; }
+ inline void set_scale(const float scale) {
+ submodel_scale = scale;
+ }
- inline void set_name(const std::string& name) { submodel_name.assign(name); }
+ inline void set_name(const std::string& name) {
+ submodel_name.assign(name);
+ }
- inline void set_axis(const math::Axis& axis) { submodel_axis.assign(axis); }
+ inline void set_axis(const math::Axis& axis) {
+ submodel_axis.assign(axis);
+ }
/* ---- actors --------------------------------------------- */
/**
* @brief mutable reference to the axis
*/
- inline math::Axis& get_axis() { return submodel_axis; }
+ inline math::Axis& get_axis() {
+ return submodel_axis;
+ }
private:
float submodel_scale;
diff --git a/src/model/primitives.cc b/src/model/primitives.cc
index f21a6d5..85b07ee 100644
--- a/src/model/primitives.cc
+++ b/src/model/primitives.cc
@@ -20,7 +20,7 @@ Primitives::~Primitives()
for (std::list<Triangle *>::iterator tris_it = primitives_triangles.begin(); tris_it != primitives_triangles.end(); tris_it++)
delete(*tris_it);
primitives_triangles.clear();
-
+
// clear list of quads
for (std::list<Quad *>::iterator quad_it = primitives_quads.begin(); quad_it != primitives_quads.end(); quad_it++)
delete(*quad_it);
diff --git a/src/model/primitives.h b/src/model/primitives.h
index 84c3f9b..43fd380 100644
--- a/src/model/primitives.h
+++ b/src/model/primitives.h
@@ -23,31 +23,28 @@ class Primitives
public:
/// type definition for a list of triangles
typedef std::list<Triangle *> Triangles;
-
+
/// type definition for a list of quads
typedef std::list<Quad *> Quads;
-
+
Primitives(Material *material);
~Primitives();
-
+
/// the material to be used for these primitives
- inline const Material *material() const
- {
+ inline const Material *material() const {
return primitives_material;
}
-
+
/// list of triangles
- inline Triangles & triangles()
- {
+ inline Triangles & triangles() {
return primitives_triangles;
}
-
+
/// list of quads
- inline Quads & quads()
- {
+ inline Quads & quads() {
return primitives_quads;
}
-
+
/// add a Triangle primitive
void add_triangle(Triangle *triangle);
@@ -57,7 +54,7 @@ public:
private:
Triangles primitives_triangles;
Quads primitives_quads;
-
+
Material * primitives_material;
};
diff --git a/src/model/quad.cc b/src/model/quad.cc
index c012bf0..0830fe7 100644
--- a/src/model/quad.cc
+++ b/src/model/quad.cc
@@ -9,7 +9,7 @@
namespace model
{
-Quad::Quad(const math::Vector3f &v0,const math::Vector3f &v1, const math::Vector3f &v2, const math::Vector3f &v3, const math::Vector3f &normal, const bool detail) :
+Quad::Quad(const math::Vector3f &v0, const math::Vector3f &v1, const math::Vector3f &v2, const math::Vector3f &v3, const math::Vector3f &normal, const bool detail) :
quad_v0(v0),
quad_n0(normal),
quad_v1(v1),
diff --git a/src/model/quad.h b/src/model/quad.h
index 4728866..b7dd7af 100644
--- a/src/model/quad.h
+++ b/src/model/quad.h
@@ -21,85 +21,72 @@ public:
* @brief a new quad with 4 vertices
* this constructor assigns the face normal to every vertex normal
*/
- Quad(const math::Vector3f &v0,const math::Vector3f &v1, const math::Vector3f &v2, const math::Vector3f &v3, const math::Vector3f &normal, const bool detail = false);
+ Quad(const math::Vector3f &v0, const math::Vector3f &v1, const math::Vector3f &v2, const math::Vector3f &v3, const math::Vector3f &normal, const bool detail = false);
/// delete quad
~Quad();
-
+
/// quad vertex 0
- inline math::Vector3f & v0()
- {
+ inline math::Vector3f & v0() {
return quad_v0;
}
-
+
/// quad vertex 0 normal
- inline math::Vector3f & n0()
- {
+ inline math::Vector3f & n0() {
return quad_n0;
}
/// quad vertex 0 texture coordinates
- inline math::Vector2f & t0()
- {
+ inline math::Vector2f & t0() {
return quad_t0;
}
/// quad vertex 1
- inline math::Vector3f & v1()
- {
+ inline math::Vector3f & v1() {
return quad_v1;
}
/// quad vertex 1 normal
- inline math::Vector3f & n1()
- {
+ inline math::Vector3f & n1() {
return quad_n1;
}
/// quad vertex 1 texture coordinates
- inline math::Vector2f & t1()
- {
+ inline math::Vector2f & t1() {
return quad_t1;
}
-
+
/// quad vertex 2
- inline math::Vector3f & v2()
- {
+ inline math::Vector3f & v2() {
return quad_v2;
}
/// quad vertex 2 normal
- inline math::Vector3f & n2()
- {
+ inline math::Vector3f & n2() {
return quad_n2;
}
/// quad vertex 2 texture coordinates
- inline math::Vector2f & t2()
- {
+ inline math::Vector2f & t2() {
return quad_t2;
}
/// quad vertex 3
- inline math::Vector3f & v3()
- {
+ inline math::Vector3f & v3() {
return quad_v3;
}
/// quad vertex 3 normal
- inline math::Vector3f & n3()
- {
+ inline math::Vector3f & n3() {
return quad_n3;
}
/// quad vertex 3 texture coordinates
- inline math::Vector2f & t3()
- {
+ inline math::Vector2f & t3() {
return quad_t3;
}
/// indidcates if this quad was generated from a detail brush
- inline bool detail() const
- {
+ inline bool detail() const {
return quad_detail;
}
@@ -125,7 +112,7 @@ private:
math::Vector3f quad_v3;
math::Vector3f quad_n3;
math::Vector2f quad_t3;
-
+
math::Vector3f quad_normal;
bool quad_detail;
};
diff --git a/src/model/triangle.cc b/src/model/triangle.cc
index 40c34a3..0fb7224 100644
--- a/src/model/triangle.cc
+++ b/src/model/triangle.cc
@@ -10,23 +10,23 @@ namespace model
{
Triangle::Triangle(const math::Vector3f &v0, const math::Vector3f &v1, const math::Vector3f &v2) :
- triangle_v0(v0),
- triangle_v1(v1),
- triangle_v2(v2)
+ triangle_v0(v0),
+ triangle_v1(v1),
+ triangle_v2(v2)
{
- triangle_detail = false;
+ triangle_detail = false;
}
-Triangle::Triangle(const math::Vector3f &v0,const math::Vector3f &v1, const math::Vector3f &v2, const math::Vector3f &normal, const bool detail) :
- triangle_v0(v0),
- triangle_n0(normal),
- triangle_v1(v1),
- triangle_n1(normal),
- triangle_v2(v2),
- triangle_n2(normal),
- triangle_normal(normal)
+Triangle::Triangle(const math::Vector3f &v0, const math::Vector3f &v1, const math::Vector3f &v2, const math::Vector3f &normal, const bool detail) :
+ triangle_v0(v0),
+ triangle_n0(normal),
+ triangle_v1(v1),
+ triangle_n1(normal),
+ triangle_v2(v2),
+ triangle_n2(normal),
+ triangle_normal(normal)
{
- triangle_detail = detail;
+ triangle_detail = detail;
}
Triangle::~Triangle()
diff --git a/src/model/triangle.h b/src/model/triangle.h
index 8e8d1e2..06a8810 100644
--- a/src/model/triangle.h
+++ b/src/model/triangle.h
@@ -17,92 +17,92 @@ namespace model
class Triangle
{
public:
- /**
- * @brief a new triangle with 3 vertices
- * this constructor is used by the ASE reader sets the detail flag to false
- */
- Triangle(const math::Vector3f &v0, const math::Vector3f &v1, const math::Vector3f &v2);
-
- /**
- * @brief a new triangle with 3 vertices
- * this constructor is used by the MAP reader and assigns the face normal to every vertex normal
- */
- Triangle(const math::Vector3f &v0,const math::Vector3f &v1, const math::Vector3f &v2, const math::Vector3f &normal, const bool detail = false);
-
- /// delete triangle
- ~Triangle();
-
- /// triangle vertex 0
- inline math::Vector3f & v0() {
- return triangle_v0;
- }
-
- /// triangle vertex 0 normal
- inline math::Vector3f & n0() {
- return triangle_n0;
- }
-
- /// triangle vertex 0 texture coordinates
- inline math::Vector2f & t0() {
- return triangle_t0;
- }
-
- /// triangle vertex 1
- inline math::Vector3f & v1() {
- return triangle_v1;
- }
-
- /// triangle vertex 1 normal
- inline math::Vector3f & n1() {
- return triangle_n1;
- }
-
- /// triangle vertex 1 texture coordinates
- inline math::Vector2f & t1() {
- return triangle_t1;
- }
-
- /// triangle vertex 2
- inline math::Vector3f & v2() {
- return triangle_v2;
- }
-
- /// triangle vertex 2 normal
- inline math::Vector3f & n2() {
- return triangle_n2;
- }
-
- /// triangle vertex 2 texture coordinates
- inline math::Vector2f & t2() {
- return triangle_t2;
- }
-
- /// indidcates if this triangle was generated from a detail brush
- inline bool detail() const {
- return triangle_detail;
- }
-
- /// face normal
- inline math::Vector3f &normal() {
- return triangle_normal;
- }
+ /**
+ * @brief a new triangle with 3 vertices
+ * this constructor is used by the ASE reader sets the detail flag to false
+ */
+ Triangle(const math::Vector3f &v0, const math::Vector3f &v1, const math::Vector3f &v2);
+
+ /**
+ * @brief a new triangle with 3 vertices
+ * this constructor is used by the MAP reader and assigns the face normal to every vertex normal
+ */
+ Triangle(const math::Vector3f &v0, const math::Vector3f &v1, const math::Vector3f &v2, const math::Vector3f &normal, const bool detail = false);
+
+ /// delete triangle
+ ~Triangle();
+
+ /// triangle vertex 0
+ inline math::Vector3f & v0() {
+ return triangle_v0;
+ }
+
+ /// triangle vertex 0 normal
+ inline math::Vector3f & n0() {
+ return triangle_n0;
+ }
+
+ /// triangle vertex 0 texture coordinates
+ inline math::Vector2f & t0() {
+ return triangle_t0;
+ }
+
+ /// triangle vertex 1
+ inline math::Vector3f & v1() {
+ return triangle_v1;
+ }
+
+ /// triangle vertex 1 normal
+ inline math::Vector3f & n1() {
+ return triangle_n1;
+ }
+
+ /// triangle vertex 1 texture coordinates
+ inline math::Vector2f & t1() {
+ return triangle_t1;
+ }
+
+ /// triangle vertex 2
+ inline math::Vector3f & v2() {
+ return triangle_v2;
+ }
+
+ /// triangle vertex 2 normal
+ inline math::Vector3f & n2() {
+ return triangle_n2;
+ }
+
+ /// triangle vertex 2 texture coordinates
+ inline math::Vector2f & t2() {
+ return triangle_t2;
+ }
+
+ /// indidcates if this triangle was generated from a detail brush
+ inline bool detail() const {
+ return triangle_detail;
+ }
+
+ /// face normal
+ inline math::Vector3f &normal() {
+ return triangle_normal;
+ }
private:
- math::Vector3f triangle_v0;
- math::Vector3f triangle_n0;
- math::Vector2f triangle_t0;
+ math::Vector3f triangle_v0;
+ math::Vector3f triangle_n0;
+ math::Vector2f triangle_t0;
- math::Vector3f triangle_v1;
- math::Vector3f triangle_n1;
- math::Vector2f triangle_t1;
+ math::Vector3f triangle_v1;
+ math::Vector3f triangle_n1;
+ math::Vector2f triangle_t1;
- math::Vector3f triangle_v2;
- math::Vector3f triangle_n2;
- math::Vector2f triangle_t2;
+ math::Vector3f triangle_v2;
+ math::Vector3f triangle_n2;
+ math::Vector2f triangle_t2;
- math::Vector3f triangle_normal;
- bool triangle_detail;
+ math::Vector3f triangle_normal;
+ bool triangle_detail;
};
}
diff --git a/src/model/vertexarray.cc b/src/model/vertexarray.cc
index 8509dc6..057b80d 100644
--- a/src/model/vertexarray.cc
+++ b/src/model/vertexarray.cc
@@ -19,17 +19,17 @@ VertexArray *VertexArray::vertex_instance = 0 ;
VertexArray::VertexArray(size_t size)
{
vertex_instance = this;
- vertex_size = size * 1024*1024; // megabytes
+ vertex_size = size * 1024 * 1024; // megabytes
vertex_size = vertex_size / sizeof(float); // sizeof float
vertex_size = vertex_size / 3; // 3 arrays
-
+
vertex_vertex = (float *) malloc(vertex_size * sizeof(float));
vertex_normal = (float *) malloc(vertex_size * sizeof(float));
vertex_texture = (float *) malloc(vertex_size * sizeof(float));
-
+
con_print << "^BInitializing vertex array..." << std::endl;
con_print << " " << size << " Mb allocated" << std::endl;
-
+
clear();
}
@@ -38,7 +38,7 @@ VertexArray::~VertexArray()
free(vertex_vertex);
free(vertex_normal);
free(vertex_texture);
-
+
vertex_instance = 0 ;
}
@@ -46,90 +46,90 @@ void VertexArray::clear()
{
vertex_index = 0;
vertex_overflow = false;
-
+
memset(vertex_vertex, 0, sizeof(vertex_vertex));
memset(vertex_normal, 0, sizeof(vertex_normal));
memset(vertex_texture, 0, sizeof(vertex_texture));
-
+
add_sphere();
}
void VertexArray::add_sphere()
{
// load sphere vertices into the VertexArray
-
+
// build sin/cos table
float *sintable;
float *costable;
-
+
sintable = new float[SPHERESEGMENTS];
costable = new float[SPHERESEGMENTS];
- float d = 2 * M_PI / (SPHERESEGMENTS-1);
-
- for (int i=0; i < SPHERESEGMENTS; i++) {
+ float d = 2 * M_PI / (SPHERESEGMENTS - 1);
+
+ for (int i = 0; i < SPHERESEGMENTS; i++) {
sintable[i] = sin(d * (float) i);
costable[i] = cos(d * (float) i);
}
-
+
// draw body
math::Vector3f v;
math::Vector3f n;
float texx, texy;
-
+
int quad_count = 0;
-
+
// add sphere
- for (int j=0; j < (SPHERESEGMENTS-1) / 2; j++) {
-
+ for (int j = 0; j < (SPHERESEGMENTS - 1) / 2; j++) {
+
float r = sintable[j];
float r1 = sintable[j+1];
-
+
for (int i = 0; i < SPHERESEGMENTS; i++) {
- v = math::Vector3f(r*costable[i], r*sintable[i], costable[j]);
+ v = math::Vector3f(r * costable[i], r * sintable[i], costable[j]);
n = v;
n.normalize();
- texx = (float)i/(float)(SPHERESEGMENTS-1);
- texy = -costable[j]/2 + 0.5f;
+ texx = (float)i / (float)(SPHERESEGMENTS - 1);
+ texy = -costable[j] / 2 + 0.5f;
add_vertex(v, n, texx, texy);
-
- v = math::Vector3f(r1*costable[i], r1*sintable[i], costable[j+1]);
+
+ v = math::Vector3f(r1 * costable[i], r1 * sintable[i], costable[j+1]);
n = v;
n.normalize();
- texx = (float)i/(float)(SPHERESEGMENTS-1);
- texy = -costable[j+1]/2 + 0.5f;
+ texx = (float)i / (float)(SPHERESEGMENTS - 1);
+ texy = -costable[j+1] / 2 + 0.5f;
add_vertex(v, n, texx, texy);
-
+
quad_count++;
}
quad_count--;
}
-
-
+
+
// add inside-out sphere
- for (int j=0; j < (SPHERESEGMENTS-1) / 2; j++) {
-
+ for (int j = 0; j < (SPHERESEGMENTS - 1) / 2; j++) {
+
float r = sintable[j];
float r1 = sintable[j+1];
-
-
- for (int i = SPHERESEGMENTS -1 ; i >= 0; i--) {
- v = math::Vector3f(r*costable[i], r*sintable[i], costable[j]);
+
+
+ for (int i = SPHERESEGMENTS - 1 ; i >= 0; i--) {
+ v = math::Vector3f(r * costable[i], r * sintable[i], costable[j]);
n = v;
n.normalize();
- texx = 1-(float)i/(float)(SPHERESEGMENTS-1);
- texy = -costable[j]/2 + 0.5f;
+ texx = 1 - (float)i / (float)(SPHERESEGMENTS - 1);
+ texy = -costable[j] / 2 + 0.5f;
add_vertex(v, n, texx, texy);
-
- v = math::Vector3f(r1*costable[i], r1*sintable[i], costable[j+1]);
+
+ v = math::Vector3f(r1 * costable[i], r1 * sintable[i], costable[j+1]);
n = v;
n.normalize();
- texx = 1-(float)i/(float)(SPHERESEGMENTS-1);
- texy = -costable[j+1]/2 + 0.5f;
+ texx = 1 - (float)i / (float)(SPHERESEGMENTS - 1);
+ texy = -costable[j+1] / 2 + 0.5f;
add_vertex(v, n, texx, texy);
}
-
+
}
-
+
delete[] sintable;
delete[] costable;
}
@@ -143,7 +143,7 @@ size_t VertexArray::add_vertex(math::Vector3f const &v, math::Vector3f const &n,
}
return 0;
}
-
+
for (int i = 0; i < 3; i ++) {
vertex_vertex[vertex_index+i] = v[i];
vertex_normal[vertex_index+i] = n[i];
@@ -152,9 +152,9 @@ size_t VertexArray::add_vertex(math::Vector3f const &v, math::Vector3f const &n,
vertex_texture[vertex_index] = tex_x;
vertex_texture[vertex_index+1] = tex_y;
vertex_texture[vertex_index+2] = 0;
-
+
vertex_index += 3;
-
+
return 1;
}
diff --git a/src/model/vertexarray.h b/src/model/vertexarray.h
index 4277442..4377f67 100644
--- a/src/model/vertexarray.h
+++ b/src/model/vertexarray.h
@@ -24,61 +24,54 @@ public:
/// create a new VertexArray with size in Mb
VertexArray(size_t size);
~VertexArray();
-
+
void clear();
-
- size_t add_vertex(math::Vector3f const &v, math::Vector3f const &n, float tex_x=0.0f, float tex_y=0.0f);
-
- inline float *vertex()
- {
+
+ size_t add_vertex(math::Vector3f const &v, math::Vector3f const &n, float tex_x = 0.0f, float tex_y = 0.0f);
+
+ inline float *vertex() {
return vertex_vertex;
}
- inline float *normal()
- {
+ inline float *normal() {
return vertex_normal;
}
- inline float *texture()
- {
+ inline float *texture() {
return vertex_texture;
}
-
- inline bool overflow() const
- {
+
+ inline bool overflow() const {
return vertex_overflow;
}
-
+
/// size of the vertex array in number of floats (for a single array)
- inline size_t size() const
- {
+ inline size_t size() const {
return vertex_size;
}
-
+
/// number of allocated floats
- inline size_t index() const
- {
+ inline size_t index() const {
return vertex_index;
}
-
- static inline VertexArray *instance()
- {
+
+ static inline VertexArray *instance() {
return vertex_instance;
}
-
+
private:
/// model vertices
float *vertex_vertex;
float *vertex_normal;
float *vertex_texture;
-
+
size_t vertex_index;
size_t vertex_size;
-
+
void add_sphere();
-
+
static VertexArray *vertex_instance;
-
+
bool vertex_overflow;
};
diff --git a/src/osirion.cc b/src/osirion.cc
index 4db5e6f..e6dd419 100644
--- a/src/osirion.cc
+++ b/src/osirion.cc
@@ -1,7 +1,7 @@
-/*
+/*
osirion.cc
- This file is part of the Osirion project and is distributed under
- the terms and conditions of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
*/
#include "SDL/SDL.h"
diff --git a/src/osiriond.cc b/src/osiriond.cc
index 8d941ca..7fa3d09 100644
--- a/src/osiriond.cc
+++ b/src/osiriond.cc
@@ -1,7 +1,7 @@
/*
osiriond.cc
- This file is part of the Osirion project and is distributed under
- the terms and conditions of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
*/
#include "dedicated/dedicated.h"
diff --git a/src/render/camera.cc b/src/render/camera.cc
index 913adfb..329ab36 100644
--- a/src/render/camera.cc
+++ b/src/render/camera.cc
@@ -1,7 +1,7 @@
-/*
+/*
render/camera.cc
- This file is part of the Osirion project and is distributed under
- the terms and conditions of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
*/
#include <cmath>
@@ -50,10 +50,10 @@ float Camera::camera_zoom;
void Camera::init()
{
direction_current = 0;
- direction_target = 0;
+ direction_target = 0;
- pitch_current = pitch_track * 2;
- pitch_target = pitch_track;
+ pitch_current = pitch_track * 2;
+ pitch_target = pitch_track;
target_pitch = 0.0f;
target_direction = 0.0f;
@@ -68,15 +68,16 @@ void Camera::init()
camera_axis.clear();
camera_eye.clear();
camera_target.clear();
-
+
}
void Camera::shutdown()
{
}
-void Camera::set_mode(Mode newmode) {
-
+void Camera::set_mode(Mode newmode)
+{
+
direction_target = 0;
direction_current = direction_target;
pitch_target = pitch_track;
@@ -91,103 +92,103 @@ void Camera::set_mode(Mode newmode) {
if (camera_mode != Overview)
camera_previous_mode = camera_mode;
- switch(newmode) {
- case Track:
- // switch camera to Track mode
- camera_mode = Track;
- if (core::localcontrol()) {
- camera_axis.assign(core::localcontrol()->axis());
- }
- break;
+ switch (newmode) {
+ case Track:
+ // switch camera to Track mode
+ camera_mode = Track;
+ if (core::localcontrol()) {
+ camera_axis.assign(core::localcontrol()->axis());
+ }
+ break;
- case Free:
- // switch camera to Free mode
- camera_mode = Free;
- pitch_target = pitch_free;
- pitch_current = pitch_target;
- break;
+ case Free:
+ // switch camera to Free mode
+ camera_mode = Free;
+ pitch_target = pitch_free;
+ pitch_current = pitch_target;
+ break;
- case Cockpit:
- camera_mode = Cockpit;
- break;
+ case Cockpit:
+ camera_mode = Cockpit;
+ break;
- case Overview:
- // switch camera to Overview mode
- camera_mode = Overview;
+ case Overview:
+ // switch camera to Overview mode
+ camera_mode = Overview;
- default:
- break;
+ default:
+ break;
}
}
void Camera::view_next()
{
-
- if (!core::localcontrol()) {
+
+ if (!core::localcontrol()) {
set_mode(Overview);
return;
}
- switch(camera_mode) {
- case Free:
- // switch camera to Track mode
- set_mode(Track);
- //con_print << "view: track" << std::endl;
- core::application()->notify_message(core::Message::Info, std::string("view: track"));
- break;
-
- case Track:
- // switch camera to Cockpit mode
- set_mode(Cockpit);
- //con_print << "view: cockpit" << std::endl;
- core::application()->notify_message(core::Message::Info, std::string("view: cockpit"));
- break;
-
- case Cockpit:
- // switch camera to Free mode
- set_mode(Free);
- //con_print << "view: free" << std::endl;
- core::application()->notify_message(core::Message::Info, std::string("view: free"));
- break;
-
- default:
- break;
+ switch (camera_mode) {
+ case Free:
+ // switch camera to Track mode
+ set_mode(Track);
+ //con_print << "view: track" << std::endl;
+ core::application()->notify_message(core::Message::Info, std::string("view: track"));
+ break;
+
+ case Track:
+ // switch camera to Cockpit mode
+ set_mode(Cockpit);
+ //con_print << "view: cockpit" << std::endl;
+ core::application()->notify_message(core::Message::Info, std::string("view: cockpit"));
+ break;
+
+ case Cockpit:
+ // switch camera to Free mode
+ set_mode(Free);
+ //con_print << "view: free" << std::endl;
+ core::application()->notify_message(core::Message::Info, std::string("view: free"));
+ break;
+
+ default:
+ break;
}
}
void Camera::view_previous()
{
-
- if (!core::localcontrol()) {
+
+ if (!core::localcontrol()) {
set_mode(Overview);
return;
}
- switch(camera_mode) {
- case Cockpit:
- // switch camera to Track mode
- set_mode(Track);
- //con_print << "view: track" << std::endl;
- core::application()->notify_message(core::Message::Info, std::string("view: track"));
- break;
-
- case Free:
- // switch camera to Cockpit mode
- set_mode(Cockpit);
- //con_print << "view: cockpit" << std::endl;
- core::application()->notify_message(core::Message::Info, std::string("view: cockpit"));
- break;
-
- case Track:
- // switch camera to Free mode
- set_mode(Free);
- //con_print << "view: free" << std::endl;
- core::application()->notify_message(core::Message::Info, std::string("view: free"));
- break;
-
- default:
- break;
+ switch (camera_mode) {
+ case Cockpit:
+ // switch camera to Track mode
+ set_mode(Track);
+ //con_print << "view: track" << std::endl;
+ core::application()->notify_message(core::Message::Info, std::string("view: track"));
+ break;
+
+ case Free:
+ // switch camera to Cockpit mode
+ set_mode(Cockpit);
+ //con_print << "view: cockpit" << std::endl;
+ core::application()->notify_message(core::Message::Info, std::string("view: cockpit"));
+ break;
+
+ case Track:
+ // switch camera to Free mode
+ set_mode(Free);
+ //con_print << "view: free" << std::endl;
+ core::application()->notify_message(core::Message::Info, std::string("view: free"));
+ break;
+
+ default:
+ break;
}
}
@@ -197,8 +198,8 @@ void Camera::set_zoom(float zoom)
math::clamp(camera_zoom, 1.0f, 10.0f);
}
-void Camera::frame(float seconds)
-{
+void Camera::frame(float seconds)
+{
math::Axis target_axis;
float d = 0;
@@ -218,10 +219,10 @@ void Camera::frame(float seconds)
if (mode() == Overview) {
camera_eye.clear();
-
+
if (core::localplayer()->view()) {
// player view entity
-
+
camera_axis.assign(core::localplayer()->view()->axis());
if (core::localplayer()->view() == core::localcontrol()) {
camera_axis.change_pitch(pitch_free);
@@ -230,17 +231,17 @@ void Camera::frame(float seconds)
} else {
distance = math::max(core::localplayer()->view()->radius(), 1.0f) * 3.0f;
camera_axis.change_direction(180.0f);
- camera_target.assign(core::localplayer()->view()->location() - core::localplayer()->view()->axis().left()* (math::max(core::localplayer()->view()->radius(), 1.0f)*0.5f) );
+ camera_target.assign(core::localplayer()->view()->location() - core::localplayer()->view()->axis().left()*(math::max(core::localplayer()->view()->radius(), 1.0f)*0.5f));
}
-
-/*
- } else if (core::localplayer()->zone()->default_view()) {
- // default zone view entity
- camera_target.assign(core::localplayer()->zone()->default_view()->location());
- camera_axis.assign(core::localplayer()->zone()->default_view()->axis());
- camera_axis.change_direction(180.0f);
- distance = math::max(core::localplayer()->zone()->default_view()->radius(), 1.0f) * 2.0f;
-*/
+
+ /*
+ } else if (core::localplayer()->zone()->default_view()) {
+ // default zone view entity
+ camera_target.assign(core::localplayer()->zone()->default_view()->location());
+ camera_axis.assign(core::localplayer()->zone()->default_view()->axis());
+ camera_axis.change_direction(180.0f);
+ distance = math::max(core::localplayer()->zone()->default_view()->radius(), 1.0f) * 2.0f;
+ */
} else {
// default location (0,0,0)
camera_target.clear();
@@ -258,7 +259,7 @@ void Camera::frame(float seconds)
if (mode() == Track) {
float cosangle; // cosine of an angle
- float angle; // angle in radians
+ float angle; // angle in radians
math::Vector3f n; // normal of a plane
n.assign(math::crossproduct(camera_axis.forward(), target_axis.forward()));
@@ -286,36 +287,36 @@ void Camera::frame(float seconds)
angle = acos(cosangle) * seconds; // * 180.0f / M_PI;
if (angle > MIN_DELTA)
camera_axis.rotate(n, -angle);
- }
+ }
if (core::localcontrol()->model()) {
camera_target -= camera_axis.forward() * math::max(FRUSTUMFRONT / WORLDSCALE, core::localcontrol()->model()->maxbbox().x());
camera_target += camera_axis.up() * math::max(FRUSTUMFRONT / WORLDSCALE, core::localcontrol()->model()->maxbbox().z() * 2.0f);
} else {
- camera_target -= camera_axis.forward() * math::max (FRUSTUMFRONT / WORLDSCALE, FRUSTUMFRONT / WORLDSCALE + core::localcontrol()->radius());
- camera_target += camera_axis.up() * math::max (FRUSTUMFRONT / WORLDSCALE, FRUSTUMFRONT / WORLDSCALE + core::localcontrol()->radius());
+ camera_target -= camera_axis.forward() * math::max(FRUSTUMFRONT / WORLDSCALE, FRUSTUMFRONT / WORLDSCALE + core::localcontrol()->radius());
+ camera_target += camera_axis.up() * math::max(FRUSTUMFRONT / WORLDSCALE, FRUSTUMFRONT / WORLDSCALE + core::localcontrol()->radius());
}
- distance = math::max (FRUSTUMFRONT / WORLDSCALE, FRUSTUMFRONT / WORLDSCALE + camera_zoom * core::localcontrol()->radius()) + 0.001f;
+ distance = math::max(FRUSTUMFRONT / WORLDSCALE, FRUSTUMFRONT / WORLDSCALE + camera_zoom * core::localcontrol()->radius()) + 0.001f;
} else if (mode() == Free) {
camera_axis.assign(target_axis);
-
+
direction_target = direction_current - 90 * target_direction;
pitch_target = pitch_current - 90 * target_pitch;
// adjust direction
d = degrees180f(direction_current - direction_target);
- direction_current = degrees360f( direction_current - d * seconds);
+ direction_current = degrees360f(direction_current - d * seconds);
camera_axis.change_direction(direction_current);
- // adjust pitch
+ // adjust pitch
d = degrees180f(pitch_current - pitch_target);
pitch_current = degrees360f(pitch_current - d * seconds);
camera_axis.change_pitch(pitch_current);
- distance = math::max (FRUSTUMFRONT / WORLDSCALE, FRUSTUMFRONT / WORLDSCALE + camera_zoom * core::localcontrol()->radius()) + 0.001f;
+ distance = math::max(FRUSTUMFRONT / WORLDSCALE, FRUSTUMFRONT / WORLDSCALE + camera_zoom * core::localcontrol()->radius()) + 0.001f;
} else if (mode() == Cockpit) {
@@ -323,10 +324,10 @@ void Camera::frame(float seconds)
if (core::localcontrol()->model()) {
camera_target += (core::localcontrol()->model()->maxbbox().x()) *
- core::localcontrol()->axis().forward();
+ core::localcontrol()->axis().forward();
} else {
camera_target += (core::localcontrol()->radius()) *
- core::localcontrol()->axis().forward();
+ core::localcontrol()->axis().forward();
}
distance = (FRUSTUMFRONT / WORLDSCALE) - 0.001f;
}
@@ -342,7 +343,7 @@ void Camera::frustum()
gl::matrixmode(GL_PROJECTION);
gl::loadidentity();
- gl::frustum(-FRUSTUMSIZE, FRUSTUMSIZE, -FRUSTUMSIZE/State::aspect(), FRUSTUMSIZE/State::aspect(), FRUSTUMFRONT, core::range::maxdistance * WORLDSCALE);
+ gl::frustum(-FRUSTUMSIZE, FRUSTUMSIZE, -FRUSTUMSIZE / State::aspect(), FRUSTUMSIZE / State::aspect(), FRUSTUMFRONT, core::range::maxdistance * WORLDSCALE);
gl::matrixmode(GL_MODELVIEW);
gl::loadidentity();
@@ -369,9 +370,9 @@ void Camera::frustum_default(float distance, float cx, float cy)
// move eye to (cx, cy)
// note: the factor 2.0f probably has to be 1.0f/frustum_size
- gl::translate(2.0f*(-State::width() * 0.5f + cx)/State::width() , 2.0f*(State::height() * 0.5f - cy)/State::height(), 0.0f);
+ gl::translate(2.0f*(-State::width() * 0.5f + cx) / State::width() , 2.0f*(State::height() * 0.5f - cy) / State::height(), 0.0f);
- gl::frustum(-FRUSTUMSIZE, FRUSTUMSIZE, -FRUSTUMSIZE/State::aspect(), FRUSTUMSIZE/State::aspect(), FRUSTUMFRONT, 1023.0f);
+ gl::frustum(-FRUSTUMSIZE, FRUSTUMSIZE, -FRUSTUMSIZE / State::aspect(), FRUSTUMSIZE / State::aspect(), FRUSTUMFRONT, 1023.0f);
gl::matrixmode(GL_MODELVIEW);
gl::loadidentity();
@@ -380,7 +381,7 @@ void Camera::frustum_default(float distance, float cx, float cy)
gl::rotate(90.0f, 0.0f, 1.0f, 0.0f);
gl::rotate(-90.0f, 1.0f , 0.0f, 0.0f);
- gl::translate(distance+1.0f, 0.0f, 0.0f);
+ gl::translate(distance + 1.0f, 0.0f, 0.0f);
// extra model rotation
gl::rotate(-core::application()->time() / 8.0f *360.0f , 0.0f, 0.0f, 1.0f);
diff --git a/src/render/camera.h b/src/render/camera.h
index 49cba74..80fdb36 100644
--- a/src/render/camera.h
+++ b/src/render/camera.h
@@ -1,7 +1,7 @@
-/*
+/*
render/camera.h
- This file is part of the Osirion project and is distributed under
- the terms and conditions of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
*/
#ifndef __INCLUDED_RENDER_CAMERA_H__
@@ -10,7 +10,8 @@
#include "math/mathlib.h"
#include "core/range.h"
-namespace render {
+namespace render
+{
const float WORLDSCALE = 4.0f;
const float FARPLANE = core::range::maxdistance;
@@ -32,16 +33,24 @@ public:
static void shutdown();
/// gameworld coordinates of the camera eye
- static inline const math::Vector3f & eye() { return camera_eye; }
+ static inline const math::Vector3f & eye() {
+ return camera_eye;
+ }
/// gameworld coordinates of the camera target
- static inline const math::Vector3f & target() { return camera_target; }
+ static inline const math::Vector3f & target() {
+ return camera_target;
+ }
/// gameworld camera axis
- static inline const math::Axis & axis() { return camera_axis; }
+ static inline const math::Axis & axis() {
+ return camera_axis;
+ }
/// current camera mode
- static inline Mode mode() { return camera_mode; }
+ static inline Mode mode() {
+ return camera_mode;
+ }
/// reset the current mode
static void reset();
@@ -63,7 +72,7 @@ public:
/** The ortographic projetion is used to draw the user interface
*/
static void ortho();
-
+
/// set target zoom
static void set_zoom(float zoom);
@@ -106,5 +115,5 @@ private:
};
} // namespace client
-
+
#endif // __INCLUDED_RENDER_CAMERA_H__
diff --git a/src/render/draw.cc b/src/render/draw.cc
index 4dc6e53..dea24bc 100644
--- a/src/render/draw.cc
+++ b/src/render/draw.cc
@@ -1,7 +1,7 @@
/*
render/draw.cc
- This file is part of the Osirion project and is distributed under
- the terms and conditions of the GNU General Public License version 2
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
*/
#include <sstream>
@@ -59,15 +59,15 @@ void pass_prepare(float seconds)
using namespace model;
// lighting settings for the default light GL_LIGHT0
- GLfloat light_position[] = { 0.0, 0.0, 0.0, 1.0 };
+ GLfloat light_position[] = { 0.0, 0.0, 0.0, 1.0 };
GLfloat ambient_light[] = { 0.01f, 0.01f, 0.01f, 1.0f };
GLfloat diffuse_light[] = { 0.2f, 0.2f, 0.2f, 1.0f };
GLfloat specular_light[] = { 0.2f, 0.2f, 0.2f, 1.0f };
- for (size_t i=0; i <3; i++) {
- light_position[i] = Camera::eye()[i];
+ for (size_t i = 0; i < 3; i++) {
+ light_position[i] = Camera::eye()[i];
}
-
+
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glLightfv(GL_LIGHT0, GL_AMBIENT, ambient_light);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse_light);
@@ -86,14 +86,14 @@ void pass_prepare(float seconds)
for (core::Zone::Content::iterator it = zone->content().begin(); it != zone->content().end(); it++) {
core::Entity *entity = (*it);
-
+
if (!ext_render(entity)) {
new RenderExt(entity);
}
entity->extension((size_t) core::Extension::Render)->frame(seconds);
// globes
- if (entity->type() == core::Entity::Globe) {
+ if (entity->type() == core::Entity::Globe) {
core::EntityGlobe *globe = static_cast<core::EntityGlobe *>(entity);
// add the globe to the globes list
@@ -109,14 +109,14 @@ void pass_prepare(float seconds)
GLfloat ambient_light[] = { 0.0f, 0.0f, 0.0f, 1.0f };
GLfloat specular_light[] = { 0.2f, 0.2f, 0.2f, 1.0f };
- for (size_t i=0; i <3; i++) {
+ for (size_t i = 0; i < 3; i++) {
zone_light[i] = globe->location()[i];
zone_color[i] = globe->color()[i];
diffuse_light[i] = globe->color()[i] * 0.4;
}
zone_light[3] = 1.0f;
diffuse_light[3] = 1.0f;
-
+
glLightfv(GL_LIGHT1, GL_POSITION, zone_light);
glLightfv(GL_LIGHT1, GL_AMBIENT, ambient_light);
glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse_light);
@@ -132,18 +132,18 @@ void pass_prepare(float seconds)
/* ----- Skybox ---------------------------------------------------- */
void draw_sphere_inside(math::Color const & color, float radius)
-{
+{
gl::scale(radius, radius, radius);
gl::color(color);
- size_t index = (model::SPHERESEGMENTS) * (model::SPHERESEGMENTS-1);
- size_t count = (model::SPHERESEGMENTS)*2;
+ size_t index = (model::SPHERESEGMENTS) * (model::SPHERESEGMENTS - 1);
+ size_t count = (model::SPHERESEGMENTS) * 2;
// draw body
- for (int j=0; j < (model::SPHERESEGMENTS-1)/2; j++) {
+ for (int j = 0; j < (model::SPHERESEGMENTS - 1) / 2; j++) {
glDrawArrays(gl::QuadStrip, index, count);
index += count;
- Stats::quads += count/2-1;
+ Stats::quads += count / 2 - 1;
}
}
@@ -175,7 +175,7 @@ void draw_pass_sky()
gl::enable(GL_TEXTURE_2D);
gl::push();
- gl::translate(Camera::eye());
+ gl::translate(Camera::eye());
draw_sphere_inside(math::Color(), 1016.0f);
gl::pop();
@@ -186,33 +186,33 @@ void draw_pass_sky()
/* ---- Globes ----------------------------------------------------- */
void draw_sphere(math::Color const & color, float radius)
-{
+{
gl::scale(radius, radius, radius);
gl::color(color);
size_t index = 0;
- size_t count = (model::SPHERESEGMENTS)*2;
+ size_t count = (model::SPHERESEGMENTS) * 2;
// draw body
- for (int j=0; j < (model::SPHERESEGMENTS-1)/2; j++) {
+ for (int j = 0; j < (model::SPHERESEGMENTS - 1) / 2; j++) {
glDrawArrays(gl::QuadStrip, index, count);
index += count;
- Stats::quads += count/2-1;
+ Stats::quads += count / 2 - 1;
}
}
void draw_globe(const core::EntityGlobe* globe)
{
- /*
+ /*
Globes have to be rendered distance sorted, closest last.
Globes behind farplane are rescaled and repositioned.
*/
math::Vector3f location(globe->location());
float radius = globe->radius();
- if(globe->flag_is_set(core::Entity::Bright)) {
+ if (globe->flag_is_set(core::Entity::Bright)) {
// bright globe, render fullbright
- gl::disable(GL_LIGHTING);
+ gl::disable(GL_LIGHTING);
} else {
// disable camera light, level light only
gl::disable(GL_LIGHT0);
@@ -234,10 +234,10 @@ void draw_globe(const core::EntityGlobe* globe)
if (has_zone_light) {
// move zone light
float fake_light[4];
- for (size_t i=0; i < 3; i++) {
+ for (size_t i = 0; i < 3; i++) {
fake_light[i] = zone_light[i] + location[i] - globe->location()[i];
}
- fake_light[3] = 1.0f;
+ fake_light[3] = 1.0f;
glLightfv(GL_LIGHT1, GL_POSITION, fake_light);
}
}
@@ -255,7 +255,7 @@ void draw_globe(const core::EntityGlobe* globe)
gl::pop();
- if(globe->flag_is_set(core::Entity::Bright)) {
+ if (globe->flag_is_set(core::Entity::Bright)) {
math::Vector3f v = globe->location() - Camera::eye();
v.normalize();
@@ -264,7 +264,7 @@ void draw_globe(const core::EntityGlobe* globe)
// FIXME a corona is actually just a giant flare
if (!globe->render_texture) {
gl::enable(GL_TEXTURE_2D);
- }
+ }
Textures::bind("textures/fx/corona");
/*
if (ext_render(globe)->distance() <= farplane) {
@@ -274,23 +274,23 @@ void draw_globe(const core::EntityGlobe* globe)
math::Color color(globe->color());
color.a = a - 0.1f;
-
+
gl::color(color);
- gl::enable(GL_BLEND);
-
+ gl::enable(GL_BLEND);
+
gl::begin(gl::Quads);
- glTexCoord2f(0,1);
- gl::vertex(location+ (Camera::axis().up() - Camera::axis().left()) * radius * 4.0f);
- glTexCoord2f(0,0);
- gl::vertex(location+ (Camera::axis().up() + Camera::axis().left()) * radius * 4.0f);
- glTexCoord2f(1,0);
- gl::vertex(location+ (Camera::axis().up() * -1 + Camera::axis().left()) * radius * 4.0f);
- glTexCoord2f(1,1);
- gl::vertex(location+ (Camera::axis().up() * -1 - Camera::axis().left()) * radius * 4.0f);
+ glTexCoord2f(0, 1);
+ gl::vertex(location + (Camera::axis().up() - Camera::axis().left()) * radius * 4.0f);
+ glTexCoord2f(0, 0);
+ gl::vertex(location + (Camera::axis().up() + Camera::axis().left()) * radius * 4.0f);
+ glTexCoord2f(1, 0);
+ gl::vertex(location + (Camera::axis().up() * -1 + Camera::axis().left()) * radius * 4.0f);
+ glTexCoord2f(1, 1);
+ gl::vertex(location + (Camera::axis().up() * -1 - Camera::axis().left()) * radius * 4.0f);
gl::end();
-
+
Stats::quads++;
-
+
gl::disable(GL_BLEND);
/*
if (ext_render(globe)->distance() <= farplane) {
@@ -316,11 +316,11 @@ void draw_globe(const core::EntityGlobe* globe)
}
if (globe->flag_is_set(core::Entity::Bright)) {
- gl::enable(GL_LIGHTING);
+ gl::enable(GL_LIGHTING);
} else {
gl::enable(GL_LIGHT0);
}
-
+
if (globe->render_texture) {
gl::disable(GL_TEXTURE_2D);
}
@@ -349,52 +349,52 @@ void draw_entity_cube(const core::Entity* entity)
gl::color(entity->color());
gl::begin(gl::Quads);
-
+
// top
- gl::normal(0,0,1);
+ gl::normal(0, 0, 1);
gl::vertex(v0);
gl::vertex(v1);
- gl::vertex(v2);
+ gl::vertex(v2);
gl::vertex(v3);
// bottom
- gl::normal(0,0, -1);
+ gl::normal(0, 0, -1);
gl::vertex(v7);
gl::vertex(v6);
- gl::vertex(v5);
+ gl::vertex(v5);
gl::vertex(v4);
-
+
// sides
- gl::normal(1,0,0);
+ gl::normal(1, 0, 0);
gl::vertex(v1);
- gl::vertex(v0);
- gl::vertex(v4);
- gl::vertex(v5);
+ gl::vertex(v0);
+ gl::vertex(v4);
+ gl::vertex(v5);
- gl::normal(-1,0,0);
- gl::vertex(v3);
- gl::vertex(v2);
- gl::vertex(v6);
- gl::vertex(v7);
+ gl::normal(-1, 0, 0);
+ gl::vertex(v3);
+ gl::vertex(v2);
+ gl::vertex(v6);
+ gl::vertex(v7);
- gl::normal(0,1,0);
+ gl::normal(0, 1, 0);
gl::vertex(v2);
- gl::vertex(v1);
- gl::vertex(v5);
- gl::vertex(v6);
+ gl::vertex(v1);
+ gl::vertex(v5);
+ gl::vertex(v6);
- gl::normal(0,-1,0);
+ gl::normal(0, -1, 0);
gl::vertex(v0);
- gl::vertex(v3);
- gl::vertex(v7);
- gl::vertex(v4);
+ gl::vertex(v3);
+ gl::vertex(v7);
+ gl::vertex(v4);
gl::end();
}
void draw_entity_diamond(const core::Entity* entity)
{
- float radius = entity->radius()/2;
+ float radius = entity->radius() / 2;
/* ---- draw axis lines ---- */
gl::color(entity->color_second());
@@ -411,7 +411,7 @@ void draw_entity_diamond(const core::Entity* entity)
gl::vertex(-1.25f * radius, 0, 0);
gl::vertex(-2 * radius, 0, 0);
-
+
gl::vertex(0, -1.25f * radius, 0);
gl::vertex(0, -2 * radius, 0);
@@ -421,7 +421,7 @@ void draw_entity_diamond(const core::Entity* entity)
gl::end();
/* ---- draw rotating body lines ---- */
- float angle = (core::application()->time() + ext_render(entity)->fuzz() ) * 45.0f;
+ float angle = (core::application()->time() + ext_render(entity)->fuzz()) * 45.0f;
angle = angle - 360.0f * floorf(angle / 360.0f);
gl::rotate(angle, math::Vector3f::Zaxis());
@@ -430,19 +430,19 @@ void draw_entity_diamond(const core::Entity* entity)
}
gl::color(entity->color());
- gl::begin(gl::TriangleFan );
+ gl::begin(gl::TriangleFan);
gl::normal(0, 0 , 1);
gl::vertex(0, 0, radius);
- gl::normal(1, 0 ,0);
+ gl::normal(1, 0 , 0);
gl::vertex(radius, 0.0f, 0.0f);
gl::normal(0, 1, 0);
gl::vertex(0.0f, radius, 0.0f);
- gl::normal(-1, 0 ,0);
+ gl::normal(-1, 0 , 0);
gl::vertex(-radius, 0.0f, 0.0f);