aboutsummaryrefslogtreecommitdiff
path: root/sons_of_sol
diff options
context:
space:
mode:
Diffstat (limited to 'sons_of_sol')
-rw-r--r--sons_of_sol/AIShip.hpp67
-rw-r--r--sons_of_sol/ControlMotionEvent.hpp65
-rw-r--r--sons_of_sol/ControlMotionListener.hpp10
-rw-r--r--sons_of_sol/ControlMultiplexer.hpp108
-rw-r--r--sons_of_sol/PlayerShip.hpp177
-rw-r--r--sons_of_sol/Projectile.hpp41
-rw-r--r--sons_of_sol/SonsOfSolApplication.hpp272
-rw-r--r--sons_of_sol/Updaters.hpp52
-rw-r--r--sons_of_sol/private_db/AIShip.cpp196
-rw-r--r--sons_of_sol/private_db/ApplicationDisplay.cpp246
-rw-r--r--sons_of_sol/private_db/ApplicationInit.cpp449
-rw-r--r--sons_of_sol/private_db/ControlMultiplexer.cpp93
-rw-r--r--sons_of_sol/private_db/PlayerShip.cpp235
-rw-r--r--sons_of_sol/private_db/Projectile.cpp98
-rw-r--r--sons_of_sol/private_db/SonsOfSolApplication.cpp210
15 files changed, 1138 insertions, 1181 deletions
diff --git a/sons_of_sol/AIShip.hpp b/sons_of_sol/AIShip.hpp
index b508a4b..d54c2bf 100644
--- a/sons_of_sol/AIShip.hpp
+++ b/sons_of_sol/AIShip.hpp
@@ -7,59 +7,58 @@
* AIShip.hpp: <description>
*/
-#include "slox/loader/SloxModelObject.hpp"
#include "glox/GloxCommon.hpp"
#include "glox/GloxState.hpp"
#include "glox/objects/GloxCube.hpp"
+#include "slox/loader/SloxModelObject.hpp"
-#include "slox/SloxCommon.hpp"
#include "glox/GloxPoint.hpp"
+#include "slox/SloxCommon.hpp"
class AIShip {
-public:
- class Updater {
- public:
- virtual glox::GloxPoint<> update( uint32_t ) = 0;
- };
- inline AIShip( Updater* update = NULL ) :
- update_func( update ), m_roll( 0 ), m_roll_to( 0 ) {}
-
- void update() ;
-
- void draw( float dist ) ;
+ public:
+ class Updater {
+ public:
+ virtual glox::GloxPoint<> update(uint32_t) = 0;
+ };
+ inline AIShip(Updater* update = NULL)
+ : update_func(update), m_roll(0), m_roll_to(0) {}
- void setTimeOffset( uint32_t off ) ;
+ void update();
- inline void setUpdateFunction( Updater* updater ) ;
+ void draw(float dist);
- static void setModel( slox::SloxModelObject* high, slox::SloxModelObject* med, slox::SloxModelObject* low ) ;
+ void setTimeOffset(uint32_t off);
- inline const glox::GloxPoint<>& getPosition() { return m_position ; }
+ inline void setUpdateFunction(Updater* updater);
-private:
- Updater* update_func;
+ static void setModel(slox::SloxModelObject* high, slox::SloxModelObject* med,
+ slox::SloxModelObject* low);
- void calculate_roll_to();
+ inline const glox::GloxPoint<>& getPosition() { return m_position; }
- float m_ptich ;
- float m_yaw ;
- float m_roll ;
+ private:
+ Updater* update_func;
- float m_roll_to ;
- float m_weight ;
- uint32_t m_time_offset ;
+ void calculate_roll_to();
- glox::GloxPoint<> m_position ;
- glox::GloxPoint<> m_last_position ;
- glox::GloxPoint<> m_future_position ;
+ float m_ptich;
+ float m_yaw;
+ float m_roll;
- static slox::SloxModelObject* s_high_model ;
- static slox::SloxModelObject* s_med_model ;
- static slox::SloxModelObject* s_low_model ;
+ float m_roll_to;
+ float m_weight;
+ uint32_t m_time_offset;
- static glox::GloxCube* s_really_far_away_model;
-} ;
+ glox::GloxPoint<> m_position;
+ glox::GloxPoint<> m_last_position;
+ glox::GloxPoint<> m_future_position;
+ static slox::SloxModelObject* s_high_model;
+ static slox::SloxModelObject* s_med_model;
+ static slox::SloxModelObject* s_low_model;
+ static glox::GloxCube* s_really_far_away_model;
+};
#endif /* AISHIP_HPP_ */
diff --git a/sons_of_sol/ControlMotionEvent.hpp b/sons_of_sol/ControlMotionEvent.hpp
index 5a93a69..930539b 100644
--- a/sons_of_sol/ControlMotionEvent.hpp
+++ b/sons_of_sol/ControlMotionEvent.hpp
@@ -12,54 +12,39 @@
*
* These values have been normalized */
class ControlMotionEvent {
-public:
- enum MotionEventType {
- NONE
- , PITCH
- , ROLL
- , YAW
- , THROTTLE
- , STRAFE_SIDE
- , STRAFE_UP
- , FIRE_PRIMARY
- };
+ public:
+ enum MotionEventType {
+ NONE,
+ PITCH,
+ ROLL,
+ YAW,
+ THROTTLE,
+ STRAFE_SIDE,
+ STRAFE_UP,
+ FIRE_PRIMARY
+ };
- enum MotionOrigin {
- JOYSTICK,
- MOUSE,
- BUTTON
- };
+ enum MotionOrigin { JOYSTICK, MOUSE, BUTTON };
- ControlMotionEvent( MotionEventType type, double mag, MotionOrigin origin ) :
- mag( mag ), type( type ), origin( origin ) {}
+ ControlMotionEvent(MotionEventType type, double mag, MotionOrigin origin)
+ : mag(mag), type(type), origin(origin) {}
- inline double getMagnitude() const {
- return mag;
- }
+ inline double getMagnitude() const { return mag; }
- inline MotionEventType getType() const {
- return type;
- }
+ inline MotionEventType getType() const { return type; }
- inline MotionOrigin getOrigin() const {
- return origin;
- }
+ inline MotionOrigin getOrigin() const { return origin; }
- inline void setMagnitude( double mag ) {
- this->mag = mag;
- }
+ inline void setMagnitude(double mag) { this->mag = mag; }
- inline void setType( MotionEventType type ) {
- this->type = type;
- }
+ inline void setType(MotionEventType type) { this->type = type; }
- inline void setOrigin( MotionOrigin origin ) {
- this->origin = origin;
- }
-private:
- double mag;
- MotionEventType type;
- MotionOrigin origin;
+ inline void setOrigin(MotionOrigin origin) { this->origin = origin; }
+
+ private:
+ double mag;
+ MotionEventType type;
+ MotionOrigin origin;
};
#endif /* CONTROLMOTIONEVENT_HPP_ */
diff --git a/sons_of_sol/ControlMotionListener.hpp b/sons_of_sol/ControlMotionListener.hpp
index 8269ebe..9cf7e09 100644
--- a/sons_of_sol/ControlMotionListener.hpp
+++ b/sons_of_sol/ControlMotionListener.hpp
@@ -10,11 +10,11 @@
#include "sons_of_sol/ControlMotionEvent.hpp"
class ControlMotionListener {
-public:
- /* Called once there is a control motion */
- virtual inline void onControlMotion( const ControlMotionEvent& event ) {
- (void) event;
- }
+ public:
+ /* Called once there is a control motion */
+ virtual inline void onControlMotion(const ControlMotionEvent& event) {
+ (void)event;
+ }
};
#endif /* CONTROLMOTIONLISTENER_HPP_ */
diff --git a/sons_of_sol/ControlMultiplexer.hpp b/sons_of_sol/ControlMultiplexer.hpp
index 33ae28d..025fdd0 100644
--- a/sons_of_sol/ControlMultiplexer.hpp
+++ b/sons_of_sol/ControlMultiplexer.hpp
@@ -19,77 +19,77 @@
#include <map>
#include <vector>
-class ControlMultiplexer :
- public slox::SloxKeyListener,
- public slox::SloxMouseMotionListener {
-public:
- /* Construct a new control multiplexer */
- ControlMultiplexer();
-
- /* Adds a listener to this ControlMultiplexer */
- inline void addControlMotionListener( ControlMotionListener* listener ) {
- m_motion_listeners.push_back( listener );
- }
-
- /* Called when a key is released. This event will be converted
+class ControlMultiplexer : public slox::SloxKeyListener,
+ public slox::SloxMouseMotionListener {
+ public:
+ /* Construct a new control multiplexer */
+ ControlMultiplexer();
+
+ /* Adds a listener to this ControlMultiplexer */
+ inline void addControlMotionListener(ControlMotionListener* listener) {
+ m_motion_listeners.push_back(listener);
+ }
+
+ /* Called when a key is released. This event will be converted
* into ControlMotionEvent and sent */
- virtual void onKeyUp( const SDL_KeyboardEvent& evt ) ;
+ virtual void onKeyUp(const SDL_KeyboardEvent& evt);
- /* Called when there was a key press. This event may be converted
+ /* Called when there was a key press. This event may be converted
* into ControlMotionEvent which is then sent off to all
* the listeners. If there is no mapping then the motion
* event is not sent */
- virtual void onKeyDown( const SDL_KeyboardEvent& evt ) ;
+ virtual void onKeyDown(const SDL_KeyboardEvent& evt);
- /* Called when the mouse is moved. This
+ /* Called when the mouse is moved. This
* is interpreted as a joystick event */
- virtual void onMouseMoved( const SDL_MouseMotionEvent& evt );
+ virtual void onMouseMoved(const SDL_MouseMotionEvent& evt);
- /* Called when there is an event that is called */
- void fireControlEvent( const ControlMotionEvent& evt );
+ /* Called when there is an event that is called */
+ void fireControlEvent(const ControlMotionEvent& evt);
- /* Adds a mapping from a key to a MotionEventType. Keys are represented
+ /* Adds a mapping from a key to a MotionEventType. Keys are represented
* as a 1 for pressed and 0 for not pressed, so some normalization must
* be done with a joystick in order to received the desired results */
- inline void setKeyMapping( SDLKey key, ControlMotionEvent::MotionEventType to, float mult=1.0f ) {
- m_keysym_map[ key ] = M_MapVal( to, mult );;
- }
+ inline void setKeyMapping(SDLKey key, ControlMotionEvent::MotionEventType to,
+ float mult = 1.0f) {
+ m_keysym_map[key] = M_MapVal(to, mult);
+ ;
+ }
- /* Removes a mapping from this multiplexer, such that
+ /* Removes a mapping from this multiplexer, such that
* a key of this type pressed will no longer fire that
* event */
- inline void removeKeyMapping( SDLKey key ) {
- m_keysym_map.erase( key );
- }
+ inline void removeKeyMapping(SDLKey key) { m_keysym_map.erase(key); }
- /* Sets a joystick axis mapping. If the joystick_index = 255 then it
+ /* Sets a joystick axis mapping. If the joystick_index = 255 then it
* is interpreted as the mouse */
- inline void setJoyAxisMapping( uint8_t joystick_index, uint8_t axis_index,
- ControlMotionEvent::MotionEventType to, float mult=1.0f ) {
- m_joy_axis_map[ joystick_index << 8 | axis_index ] = M_MapVal( to, mult );
- }
-
- inline void removeJoyAxisMapping( uint8_t joystick_index, uint8_t axis_index ) {
- m_joy_axis_map.erase( joystick_index << axis_index );
- }
-
-private:
- struct M_MapVal {
- inline M_MapVal( ControlMotionEvent::MotionEventType typ, float mult ) :
- type( typ ), multiplier( mult ) {}
- inline M_MapVal( ) : type( ControlMotionEvent::NONE ), multiplier( 0.0f ) {}
- ControlMotionEvent::MotionEventType type;
- float multiplier;
- };
- /* The listeners on this multiplexer */
- std::vector< ControlMotionListener* > m_motion_listeners;
-
- /* The keysym map */
- std::map< SDLKey, M_MapVal > m_keysym_map;
-
- /* Mapping of a bit oring of joystick index and axis index to
+ inline void setJoyAxisMapping(uint8_t joystick_index, uint8_t axis_index,
+ ControlMotionEvent::MotionEventType to,
+ float mult = 1.0f) {
+ m_joy_axis_map[joystick_index << 8 | axis_index] = M_MapVal(to, mult);
+ }
+
+ inline void removeJoyAxisMapping(uint8_t joystick_index, uint8_t axis_index) {
+ m_joy_axis_map.erase(joystick_index << axis_index);
+ }
+
+ private:
+ struct M_MapVal {
+ inline M_MapVal(ControlMotionEvent::MotionEventType typ, float mult)
+ : type(typ), multiplier(mult) {}
+ inline M_MapVal() : type(ControlMotionEvent::NONE), multiplier(0.0f) {}
+ ControlMotionEvent::MotionEventType type;
+ float multiplier;
+ };
+ /* The listeners on this multiplexer */
+ std::vector<ControlMotionListener*> m_motion_listeners;
+
+ /* The keysym map */
+ std::map<SDLKey, M_MapVal> m_keysym_map;
+
+ /* Mapping of a bit oring of joystick index and axis index to
* an event type */
- std::map< uint16_t, M_MapVal > m_joy_axis_map;
+ std::map<uint16_t, M_MapVal> m_joy_axis_map;
};
#endif /* CONTROLMULTIPLEXER_HPP_ */
diff --git a/sons_of_sol/PlayerShip.hpp b/sons_of_sol/PlayerShip.hpp
index b87e731..03c7e71 100644
--- a/sons_of_sol/PlayerShip.hpp
+++ b/sons_of_sol/PlayerShip.hpp
@@ -7,17 +7,17 @@
* Ship.hpp: <description>
*/
+#include "glox/GloxLookAtPerspective.hpp"
#include "glox/GloxPoint.hpp"
#include "glox/GloxVector3.hpp"
-#include "glox/GloxLookAtPerspective.hpp"
#include "slox/events/SloxKeyListener.hpp"
#include "ControlMotionListener.hpp"
#include "sons_of_sol/Projectile.hpp"
-#include <vector>
#include <queue>
+#include <vector>
#define GUN_RATE 1
#define N_LIVING_PROJECTILES (TTL / GUN_RATE)
@@ -26,137 +26,114 @@
* for the first person
* ship */
class PlayerShip : public ControlMotionListener {
-public:
- inline PlayerShip() :
- m_forward( 0, 0, -1 ), m_up( 0, 1, 0 ), m_right( 1, 0, 0 ),
- m_dpitch( 0 ),
- m_dyaw( 0 ),
- m_droll( 0 ),
- m_droll_to( 0 ),
- m_dforward( 0 ),
- m_dforward_to( 0 ),
- m_dup( 0 ),
- m_dup_to( 0 ),
- m_dright( 0 ),
- m_dright_to( 0 ),
- m_jitter( 0 ),
- m_is_firing( false ){}
-
- /* Draw the heads-up-display of the
+ public:
+ inline PlayerShip()
+ : m_forward(0, 0, -1),
+ m_up(0, 1, 0),
+ m_right(1, 0, 0),
+ m_dpitch(0),
+ m_dyaw(0),
+ m_droll(0),
+ m_droll_to(0),
+ m_dforward(0),
+ m_dforward_to(0),
+ m_dup(0),
+ m_dup_to(0),
+ m_dright(0),
+ m_dright_to(0),
+ m_jitter(0),
+ m_is_firing(false) {}
+
+ /* Draw the heads-up-display of the
* ship */
- void drawHUD();
+ void drawHUD();
- /* Render the perspective of
+ /* Render the perspective of
* this ship */
- void renderPerspective();
+ void renderPerspective();
+
+ /* Move the ship up and down */
+ void pitch(float angle);
- /* Move the ship up and down */
- void pitch( float angle );
+ /* Roll the ship */
+ void roll(float angle);
- /* Roll the ship */
- void roll( float angle );
+ /* Rotate the ship side to side */
+ void yaw(float angle);
- /* Rotate the ship side to side */
- void yaw( float angle );
+ /* Update this object */
+ void update();
- /* Update this object */
- void update();
+ const glox::GloxStandardProjection& getPerspective() const {
+ return m_perspective;
+ }
- const glox::GloxStandardProjection& getPerspective( ) const {
- return m_perspective;
- }
+ glox::GloxStandardProjection& getPerspective() { return m_perspective; }
- glox::GloxStandardProjection& getPerspective( ) {
- return m_perspective;
- }
+ void setPerspective(const glox::GloxLookAtPerspective& perspective) {
+ m_perspective = perspective;
+ }
- void setPerspective( const glox::GloxLookAtPerspective& perspective ) {
- m_perspective = perspective;
- }
+ inline void setDPitch(float dpitch) { this->m_dpitch = dpitch; }
- inline void setDPitch( float dpitch ) {
- this->m_dpitch = dpitch;
- }
+ inline void setDRoll(float droll) { this->m_droll = droll; }
- inline void setDRoll( float droll ) {
- this->m_droll = droll;
- }
+ inline void setDYaw(float dyaw) { this->m_dyaw = dyaw; }
- inline void setDYaw( float dyaw ) {
- this->m_dyaw = dyaw;
- }
+ inline float getDPitch() const { return m_dpitch; }
- inline float getDPitch() const {
- return m_dpitch;
- }
+ inline float getDYaw() const { return m_dyaw; }
- inline float getDYaw() const {
- return m_dyaw;
- }
+ inline float getDRoll() const { return m_droll; }
- inline float getDRoll() const {
- return m_droll;
- }
+ inline void setDForwardTo(float dforward) { m_dforward_to = dforward; }
- inline void setDForwardTo( float dforward ) {
- m_dforward_to = dforward ;
- }
+ inline float getDForward() { return m_dforward; }
- inline float getDForward() {
- return m_dforward;
- }
+ virtual void onControlMotion(const ControlMotionEvent& evt);
- virtual void onControlMotion( const ControlMotionEvent& evt );
+ inline const glox::GloxPoint<> getPosition() const { return m_position; }
- inline const glox::GloxPoint<> getPosition() const {
- return m_position;
- }
+ inline void setPosition(const glox::GloxPoint<>& pos) { m_position = pos; }
- inline void setPosition( const glox::GloxPoint<>& pos ) {
- m_position = pos;
- }
+ inline void setJitter(float jitter) { m_jitter = jitter; }
- inline void setJitter( float jitter ) {
- m_jitter = jitter ;
- }
+ inline float getJitter() { return m_jitter; }
- inline float getJitter( ) {
- return m_jitter ;
- }
+ void drawProjectiles();
- void drawProjectiles() ;
-private:
- /* The position of the ship */
- glox::GloxPoint<> m_position;
+ private:
+ /* The position of the ship */
+ glox::GloxPoint<> m_position;
- /* The orientation of the ship */
- glox::GloxVector3<> m_forward;
- glox::GloxVector3<> m_up;
- glox::GloxVector3<> m_right;
+ /* The orientation of the ship */
+ glox::GloxVector3<> m_forward;
+ glox::GloxVector3<> m_up;
+ glox::GloxVector3<> m_right;
- /* The perspective of the ship */
- glox::GloxLookAtPerspective m_perspective;
+ /* The perspective of the ship */
+ glox::GloxLookAtPerspective m_perspective;
- float m_dpitch;
- float m_dyaw;
+ float m_dpitch;
+ float m_dyaw;
- float m_droll;
- float m_droll_to;
+ float m_droll;
+ float m_droll_to;
- float m_dforward;
- float m_dforward_to;
+ float m_dforward;
+ float m_dforward_to;
- float m_dup;
- float m_dup_to;
+ float m_dup;
+ float m_dup_to;
- float m_dright;
- float m_dright_to;
+ float m_dright;
+ float m_dright_to;
- float m_jitter ;
+ float m_jitter;
- bool m_is_firing ;
- std::vector<Projectile> m_living_projectiles ;
- std::queue<int> m_open_positions;
+ bool m_is_firing;
+ std::vector<Projectile> m_living_projectiles;
+ std::queue<int> m_open_positions;
};
#endif /* SHIP_HPP_ */
diff --git a/sons_of_sol/Projectile.hpp b/sons_of_sol/Projectile.hpp
index 0949314..5f298a7 100644
--- a/sons_of_sol/Projectile.hpp
+++ b/sons_of_sol/Projectile.hpp
@@ -7,39 +7,40 @@
* Projectile.hpp: <description>
*/
+#include "glox/GloxCommon.hpp"
#include "glox/GloxPoint.hpp"
-#include "glox/objects/GloxCube.hpp"
#include "glox/GloxState.hpp"
-#include "glox/GloxCommon.hpp"
+#include "glox/objects/GloxCube.hpp"
#include <iostream>
#define TTL 50
class Projectile {
-public:
- Projectile( const glox::GloxPoint<>& position, const glox::GloxPoint<>& vector ) ;
-
- inline void update() {
- if( m_ttl == 0 || -- m_ttl == 0 ) {
- return ;
- }
- m_position += m_dpos;
+ public:
+ Projectile(const glox::GloxPoint<>& position,
+ const glox::GloxPoint<>& vector);
+
+ inline void update() {
+ if (m_ttl == 0 || --m_ttl == 0) {
+ return;
}
+ m_position += m_dpos;
+ }
- inline bool isDead() { return m_ttl == 0; }
+ inline bool isDead() { return m_ttl == 0; }
- void draw() ;
+ void draw();
- static void loadModel() ;
-private:
- uint8_t m_ttl ;
- float m_roty;
- float m_rotz;
- glox::GloxPoint<> m_position;
- glox::GloxPoint<> m_dpos;
- static glox::GloxCube* m_model ;
+ static void loadModel();
+ private:
+ uint8_t m_ttl;
+ float m_roty;
+ float m_rotz;
+ glox::GloxPoint<> m_position;
+ glox::GloxPoint<> m_dpos;
+ static glox::GloxCube* m_model;
};
#endif /* PROJECTILE_HPP_ */
diff --git a/sons_of_sol/SonsOfSolApplication.hpp b/sons_of_sol/SonsOfSolApplication.hpp
index ea56614..8d03e61 100644
--- a/sons_of_sol/SonsOfSolApplication.hpp
+++ b/sons_of_sol/SonsOfSolApplication.hpp
@@ -9,175 +9,175 @@
#include "glox/GloxCommon.hpp"
#include "slox/SloxApplication.hpp"
-#include "slox/SloxTextureFactory.hpp"
#include "slox/SloxRawEventHandler.hpp"
+#include "slox/SloxTextureFactory.hpp"
#include "slox/events/SloxFunctionQuitListener.hpp"
#include "slox/loader/SloxModelObject.hpp"
#include "slox/loader/SloxObjectLoader.hpp"
-#include "glox/GloxViewport.hpp"
-#include "glox/GloxFirstPersonPerspective.hpp"
-#include "glox/objects/GloxTexturedCube.hpp"
-#include "glox/objects/GloxTexturedSphere.hpp"
#include "glox/GloxColor.hpp"
-#include "glox/GloxLookAtPerspective.hpp"
+#include "glox/GloxFirstPersonPerspective.hpp"
#include "glox/GloxLightSourceManager.hpp"
-#include "glox/objects/GloxCube.hpp"
+#include "glox/GloxLookAtPerspective.hpp"
#include "glox/GloxProgram.hpp"
+#include "glox/GloxViewport.hpp"
+#include "glox/objects/GloxCube.hpp"
+#include "glox/objects/GloxTexturedCube.hpp"
+#include "glox/objects/GloxTexturedSphere.hpp"
-#include "sons_of_sol/PlayerShip.hpp"
-#include "sons_of_sol/ControlMultiplexer.hpp"
#include "sons_of_sol/AIShip.hpp"
+#include "sons_of_sol/ControlMultiplexer.hpp"
+#include "sons_of_sol/PlayerShip.hpp"
#include "sons_of_sol/Updaters.hpp"
#define FAR_DISTANCE_START 1
-#define FAR_DISTANCE_END 1000000
+#define FAR_DISTANCE_END 1000000
#define MID_DISTANCE_START 10
-#define MID_DISTANCE_END 100000
-
-class SonsOfSolApplication : public
- slox::SloxApplication,
- slox::SloxRawEventHandler,
- slox::SloxResizeListener,
- slox::SloxKeyListener,
- slox::SloxQuitListener {
-public:
- /* Process an event */
- virtual inline void onEvent( const SDL_Event& event ) {
- SloxRawEventHandler::onEvent( event );
- }
-
- virtual inline void onKeyDown( const SDL_KeyboardEvent& evt ) {
- if( evt.keysym.sym == SDLK_ESCAPE ) exit( 0 );
- if( evt.keysym.sym == SDLK_f ) {
- setFullScreen();
- };
- if( evt.keysym.sym == SDLK_p ) {
- pause();
- };
- }
-
- /* Initializes this application;
+#define MID_DISTANCE_END 100000
+
+class SonsOfSolApplication : public slox::SloxApplication,
+ slox::SloxRawEventHandler,
+ slox::SloxResizeListener,
+ slox::SloxKeyListener,
+ slox::SloxQuitListener {
+ public:
+ /* Process an event */
+ virtual inline void onEvent(const SDL_Event& event) {
+ SloxRawEventHandler::onEvent(event);
+ }
+
+ virtual inline void onKeyDown(const SDL_KeyboardEvent& evt) {
+ if (evt.keysym.sym == SDLK_ESCAPE)
+ exit(0);
+ if (evt.keysym.sym == SDLK_f) {
+ setFullScreen();
+ };
+ if (evt.keysym.sym == SDLK_p) {
+ pause();
+ };
+ }
+
+ /* Initializes this application;
* returns true if initialization
* succeeded, false otherwise */
- virtual bool initialize( int argc, char** argv );
+ virtual bool initialize(int argc, char** argv);
- /* The main loop of the application */
- virtual bool loop( uint32_t ticks ) {
- /* Update things that we might
+ /* The main loop of the application */
+ virtual bool loop(uint32_t ticks) {
+ /* Update things that we might
* want to */
- update( ticks );
+ update(ticks);
- /* Some boilder OpenGL stuff */
- glox::GloxState::clear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
- glox::GloxState::loadIdentity();
- glox::GloxState::enable( GL_DEPTH_TEST );
+ /* Some boilder OpenGL stuff */
+ glox::GloxState::clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ glox::GloxState::loadIdentity();
+ glox::GloxState::enable(GL_DEPTH_TEST);
- /* Display some stuff */
- display();
+ /* Display some stuff */
+ display();
- /* Flush the buffers and
+ /* Flush the buffers and
* do the appropriate delay */
- glFlush();
- SDL_GL_SwapBuffers();
- SDL_Delay( 5 );
+ glFlush();
+ SDL_GL_SwapBuffers();
+ SDL_Delay(5);
- return !m_quit;
- }
+ return !m_quit;
+ }
- /* What happens when a quit event is
+ /* What happens when a quit event is
* intercepted */
- virtual inline void onQuit( const SDL_QuitEvent& evt ) {
- (void) evt;
- m_quit = true;
- }
-
- inline virtual ~SonsOfSolApplication() {
-
- }
-
- /* Resizes the perspective for OpenGL */
- inline void onResize( const SDL_ResizeEvent& evt ) {
- m_screen = SDL_SetVideoMode(evt.w,evt.h,0,SDL_OPENGL|SDL_RESIZABLE|SDL_DOUBLEBUF);
- reshape( evt.w, evt.h );
- }
-
- void pause() ;
-private:
- /* Render the background. (This is the Earth and skybox) */
- void renderFar();
- /* Render whats in the middle */
- void renderMid();
-
- void setupControls() ;
- void reshape( int width, int height );
-
- /* Sets up the lights to be used */
- void enableLighting( );
- void update( uint32_t ticks );
- void display( ) ;
- bool loadTextures();
- void setFullScreen();
-
- /* perspective stuff */
- glox::GloxViewport m_viewport;
- glox::GloxLookAtPerspective m_perspective;
-
- /* The sky */
- glox::GloxTexturedCube* m_sky;
- glox::GloxTexturedCube* m_crate;
- glox::GloxTexturedSphere* m_earth;
- glox::GloxTexturedSphere* m_moon;
-
- /* Textures */
- glox::GloxTexture m_sky_tex;
- glox::GloxTexture m_leaf_tex;
- glox::GloxTexture m_crate_tex;
- glox::GloxTexture m_star_tex;
- glox::GloxTexture m_earth_tex;
- glox::GloxTexture m_moon_tex;
-
- /* The sun */
- glox::GloxPointCollection<glox::GloxPointNormalTexture> m_star;
-
- std::vector<AIShip> m_aiships ;
- std::vector<AIShip::Updater*> m_updaters;
-
- /* The little test object */
- slox::SloxModelObject* m_probe;
- slox::SloxModelObject* m_frigate_industrial;
- slox::SloxModelObject* m_other_ship;
- slox::SloxModelObject* m_test_cube;
- slox::SloxModelObject* m_deathstar;
- slox::SloxModelObject* m_acceleration_cannon ;
-
- slox::SloxTextureFactory m_texture_factory;
- slox::SloxObjectLoader m_object_loader;
- /* A boolean stating if it is time
+ virtual inline void onQuit(const SDL_QuitEvent& evt) {
+ (void)evt;
+ m_quit = true;
+ }
+
+ inline virtual ~SonsOfSolApplication() {}
+
+ /* Resizes the perspective for OpenGL */
+ inline void onResize(const SDL_ResizeEvent& evt) {
+ m_screen = SDL_SetVideoMode(evt.w, evt.h, 0,
+ SDL_OPENGL | SDL_RESIZABLE | SDL_DOUBLEBUF);
+ reshape(evt.w, evt.h);
+ }
+
+ void pause();
+
+ private:
+ /* Render the background. (This is the Earth and skybox) */
+ void renderFar();
+ /* Render whats in the middle */
+ void renderMid();
+
+ void setupControls();
+ void reshape(int width, int height);
+
+ /* Sets up the lights to be used */
+ void enableLighting();
+ void update(uint32_t ticks);
+ void display();
+ bool loadTextures();
+ void setFullScreen();
+
+ /* perspective stuff */
+ glox::GloxViewport m_viewport;
+ glox::GloxLookAtPerspective m_perspective;
+
+ /* The sky */
+ glox::GloxTexturedCube* m_sky;
+ glox::GloxTexturedCube* m_crate;
+ glox::GloxTexturedSphere* m_earth;
+ glox::GloxTexturedSphere* m_moon;
+
+ /* Textures */
+ glox::GloxTexture m_sky_tex;
+ glox::GloxTexture m_leaf_tex;
+ glox::GloxTexture m_crate_tex;
+ glox::GloxTexture m_star_tex;
+ glox::GloxTexture m_earth_tex;
+ glox::GloxTexture m_moon_tex;
+
+ /* The sun */
+ glox::GloxPointCollection<glox::GloxPointNormalTexture> m_star;
+
+ std::vector<AIShip> m_aiships;
+ std::vector<AIShip::Updater*> m_updaters;
+
+ /* The little test object */
+ slox::SloxModelObject* m_probe;
+ slox::SloxModelObject* m_frigate_industrial;
+ slox::SloxModelObject* m_other_ship;
+ slox::SloxModelObject* m_test_cube;
+ slox::SloxModelObject* m_deathstar;
+ slox::SloxModelObject* m_acceleration_cannon;
+
+ slox::SloxTextureFactory m_texture_factory;
+ slox::SloxObjectLoader m_object_loader;
+ /* A boolean stating if it is time
* to quit */
- bool m_quit;
+ bool m_quit;
- glox::GloxLightSourceManager m_light_manager;
- PlayerShip m_ship;
+ glox::GloxLightSourceManager m_light_manager;
+ PlayerShip m_ship;
- SDL_Surface* m_screen;
- ControlMultiplexer m_event_multiplexer;
+ SDL_Surface* m_screen;
+ ControlMultiplexer m_event_multiplexer;
- int m_screen_width;
- int m_screen_height;
+ int m_screen_width;
+ int m_screen_height;
- int m_script_ttl ;
+ int m_script_ttl;
- bool m_is_paused;
+ bool m_is_paused;
- glox::GloxProgram* m_earth_prog ;
- glox::GloxProgram* m_moon_prog ;
- int m_earth_shader_light_pos ;
- int m_earth_shader_camera_pos ;
- int m_earth_shader_time ;
- int m_moon_shader_light_pos ;
- int m_moon_shader_camera_pos ;
+ glox::GloxProgram* m_earth_prog;
+ glox::GloxProgram* m_moon_prog;
+ int m_earth_shader_light_pos;
+ int m_earth_shader_camera_pos;
+ int m_earth_shader_time;
+ int m_moon_shader_light_pos;
+ int m_moon_shader_camera_pos;
};
#endif /* SONSOFSOLAPPLICATION_HPP_ */
diff --git a/sons_of_sol/Updaters.hpp b/sons_of_sol/Updaters.hpp
index 1f81112..e2e8b2d 100644
--- a/sons_of_sol/Updaters.hpp
+++ b/sons_of_sol/Updaters.hpp
@@ -7,37 +7,37 @@
* Updaters.hpp: <description>
*/
-#include "sons_of_sol/AIShip.hpp"
-#include "glox/GloxPoint.hpp"
#include "glox/GloxCommon.hpp"
+#include "glox/GloxPoint.hpp"
+#include "sons_of_sol/AIShip.hpp"
class EllipseUpdater : public AIShip::Updater {
-public:
- inline EllipseUpdater( const glox::GloxPoint<>& center,
- const glox::GloxPoint<>& major, const glox::GloxPoint<>& minor,
- float speed_factor ) :
- m_center( center ),
- m_major( major ),
- m_minor( minor ),
- m_speed( speed_factor ) {
- m_a = major.getMagnitude();
- m_b = minor.getMagnitude();
- }
+ public:
+ inline EllipseUpdater(const glox::GloxPoint<>& center,
+ const glox::GloxPoint<>& major,
+ const glox::GloxPoint<>& minor, float speed_factor)
+ : m_center(center),
+ m_major(major),
+ m_minor(minor),
+ m_speed(speed_factor) {
+ m_a = major.getMagnitude();
+ m_b = minor.getMagnitude();
+ }
+
+ inline glox::GloxPoint<> update(uint32_t time) {
+ float t = m_speed * time;
+ return m_center + (m_major * m_a * glox::GloxCos(t) +
+ m_minor * m_b * glox::GloxSin(t));
+ }
- inline glox::GloxPoint<> update( uint32_t time ) {
- float t = m_speed * time ;
- return m_center + ( m_major * m_a * glox::GloxCos( t ) +
- m_minor * m_b * glox::GloxSin( t ) );
- }
-
-private:
- glox::GloxPoint<> m_center;
- glox::GloxPoint<> m_major;
- glox::GloxPoint<> m_minor;
+ private:
+ glox::GloxPoint<> m_center;
+ glox::GloxPoint<> m_major;
+ glox::GloxPoint<> m_minor;
- float m_a;
- float m_b;
- float m_speed ;
+ float m_a;
+ float m_b;
+ float m_speed;
};
#endif /* UPDATERS_HPP_ */
diff --git a/sons_of_sol/private_db/AIShip.cpp b/sons_of_sol/private_db/AIShip.cpp
index 5940e42..b487d3c 100644
--- a/sons_of_sol/private_db/AIShip.cpp
+++ b/sons_of_sol/private_db/AIShip.cpp
@@ -3,124 +3,120 @@
#include <cmath>
#include <iostream>
+#include "glox/GloxColor.hpp"
#include "glox/GloxScopedRotation.hpp"
#include "glox/GloxScopedTranslation.hpp"
-#include "glox/GloxColor.hpp"