diff options
Diffstat (limited to 'src/client')
-rw-r--r-- | src/client/Makefile.am | 6 | ||||
-rw-r--r-- | src/client/camera.cc | 46 | ||||
-rw-r--r-- | src/client/client.cc | 2 | ||||
-rw-r--r-- | src/client/client.h | 5 | ||||
-rw-r--r-- | src/client/draw.cc | 32 | ||||
-rw-r--r-- | src/client/draw.h | 2 | ||||
-rw-r--r-- | src/client/input.cc | 149 | ||||
-rw-r--r-- | src/client/input.h | 6 | ||||
-rw-r--r-- | src/client/view.cc | 4 |
9 files changed, 139 insertions, 113 deletions
diff --git a/src/client/Makefile.am b/src/client/Makefile.am index 74dc743..bd4aaf1 100644 --- a/src/client/Makefile.am +++ b/src/client/Makefile.am @@ -8,6 +8,6 @@ libclient_la_LDFLAGS = -avoid-version -no-undefined $(GL_LIBS) $(LIBSDL_LIBS) noinst_LTLIBRARIES = libclient.la noinst_HEADERS = camera.h client.h console.h draw.h input.h keyboard.h video.h \ view.h -libclient_la_LIBADD = $(top_builddir)/src/render/librender.la \ - $(top_builddir)/src/core/libcore.la $(top_builddir)/src/filesystem/libfilesystem.la \ - $(top_builddir)/src/game/libgame.la $(top_builddir)/src/math/libmath.la $(top_builddir)/src/sys/libsys.la +libclient_la_LIBADD = $(top_builddir)/src/core/libcore.la \ + $(top_builddir)/src/filesystem/libfilesystem.la $(top_builddir)/src/math/libmath.la \ + $(top_builddir)/src/render/librender.la $(top_builddir)/src/sys/libsys.la diff --git a/src/client/camera.cc b/src/client/camera.cc index 2def781..85929cc 100644 --- a/src/client/camera.cc +++ b/src/client/camera.cc @@ -4,10 +4,11 @@ the terms and conditions of the GNU General Public License version 2 */ +#include "math/mathlib.h" +#include "core/player.h" #include "client/client.h" #include "client/camera.h" #include "render/render.h" -#include "math/mathlib.h" using math::degrees360f; using math::degrees180f; @@ -78,18 +79,32 @@ void shutdown() void draw(float elapsed) { - // TODO camera needs to get this from selected core entity + if (!core::localplayer.controled) { + // switch the camera to Overview of the player is not controling anything + if (mode != Overview) { + mode = Overview; + target = math::Vector3f(0,0,0); + x_offset = 0; + z_offset = 0; + distance = 20.0f; + } + } else { + camera::target = core::localplayer.controled->location; + } + if (mode == Track) { - yaw_target = game.ship->yaw(); + yaw_target = core::localplayer.controled->direction; } - // adjust yaw - float d = degrees180f(yaw_current - yaw_target); - yaw_current = degrees360f( yaw_current - d * elapsed) ; + if ((mode == Free) || (mode == Track)) { + // adjust yaw + float d = degrees180f(yaw_current - yaw_target); + yaw_current = degrees360f( yaw_current - d * elapsed) ; - // adjust pitch target - d = degrees180f(pitch_current - pitch_target); - pitch_current = degrees360f( pitch_current - d *elapsed); + // adjust pitch target + d = degrees180f(pitch_current - pitch_target); + pitch_current = degrees360f( pitch_current - d *elapsed); + } switch (mode) { case Free: @@ -154,11 +169,20 @@ void key_down() } void next_mode() { + + if (!core::localplayer.controled) { + mode = Overview; + target = math::Vector3f(0,0,0); + x_offset = 0; + z_offset = 0; + distance = 20.0f; + } + switch(mode) { case Overview: // switch camera to Track mode mode = Track; - yaw_target = game.ship->yaw(); + yaw_target = core::localplayer.controled->direction; yaw_current = yaw_target; pitch_target = pitch_track; pitch_current = pitch_target; @@ -167,7 +191,7 @@ void next_mode() { case Track: // switch camera to Free mode mode = Free; - yaw_target = game.ship->yaw(); + yaw_target = core::localplayer.controled->direction; yaw_current = yaw_target; pitch_target = pitch_track; pitch_current = pitch_target; diff --git a/src/client/client.cc b/src/client/client.cc index 5243d28..6ae6ba8 100644 --- a/src/client/client.cc +++ b/src/client/client.cc @@ -12,7 +12,6 @@ #include "client/input.h" #include "client/view.h" #include "core/core.h" -#include "game/game.h" // SDL headers #include <SDL/SDL.h> @@ -58,7 +57,6 @@ void func_r_restart(std::stringstream &args) } //--- public ------------------------------------------------------ -game::Game game; void main(int count, char **arguments) { diff --git a/src/client/client.h b/src/client/client.h index 7c0b74d..ee2e7af 100644 --- a/src/client/client.h +++ b/src/client/client.h @@ -7,17 +7,12 @@ #ifndef __INCLUDED_CLIENT_H__ #define __INCLUDED_CLIENT_H__ -#include "game/game.h" - /// client part of the engine namespace client { /// the client main loop void main(int count, char **arguments); -/// global client Game instance -extern game::Game game; - } // namespace client #endif // __INCLUDED_CLIENT_H__ diff --git a/src/client/draw.cc b/src/client/draw.cc index 8d83ba8..021cf3a 100644 --- a/src/client/draw.cc +++ b/src/client/draw.cc @@ -1,10 +1,10 @@ /* - draw.cc + client/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 */ -// projet headers +#include "core/player.h" #include "render/render.h" #include "render/sphere.h" #include "render/box.h" @@ -89,13 +89,16 @@ math::Vector3f v6(-1.0f, 1.0f, 1.0f); math::Vector3f v7(-1.0f, -1.0f, 1.0f); float angle = 0; -void draw_ship(game::Ship *ship, float elapsed) +void draw_ship(core::EntityControlable *entity) { using math::Vector3f; using math::Color; using namespace render; - gl::rotate(ship->yaw(), 0.0f, 1.0f, 0.0f ); + gl::push(); + gl::translate(entity->location); + gl::scale(0.2f, 0.2f, 0.2f); + gl::rotate(entity->direction, 0.0f, 1.0f, 0.0f ); Vector3f tl(0.25, 0.125, 0.125); Vector3f br(-0.25, -0.125, -0.125); @@ -124,14 +127,14 @@ void draw_ship(game::Ship *ship, float elapsed) cockpit.bottomcolor = engine1.bottomcolor; cockpit.draw(); - if(ship->thrust() > 0 ) { + if(entity->target_thrust > 0 ) { gl::color(1.0f,0 ,0 ); gl::begin(gl::Lines); gl::vertex(-0.5f, 0, 0.185); - gl::vertex(-0.5f-0.25f*ship->thrust(), 0, 0.185); + gl::vertex(-0.5f-0.25f*entity->target_thrust, 0, 0.185); gl::vertex(-0.5f, 0, -0.185f); - gl::vertex(-0.5f-0.25f*ship->thrust(), 0, -0.185f); + gl::vertex(-0.5f-0.25f*entity->target_thrust, 0, -0.185f); gl::end(); } @@ -156,6 +159,8 @@ void draw_ship(game::Ship *ship, float elapsed) gl::vertex(v7); gl::vertex(v4); gl::end(); + + gl::pop(); } void draw_spacegrid() @@ -192,10 +197,10 @@ void draw_spacegrid() end(); } -void draw_world(float elapsed) +void draw_world(float seconds) { // used for animations - angle += 180.0f * elapsed; + angle += 180.0f * seconds; if( angle > 360.0f ) { angle -= 360.0f; } @@ -208,18 +213,13 @@ void draw_world(float elapsed) case core::entity::Default: draw_entity_default((*it)); break; + case core::entity::Controlable: + draw_ship(static_cast<core::EntityControlable *>(*it)); default: break; } } - // draw the ship - gl::push(); - gl::translate(game.ship->location); - gl::scale(0.2f, 0.2f, 0.2f); - draw_ship(game.ship, elapsed); - gl::pop(); - // draw the background grid draw_spacegrid(); } diff --git a/src/client/draw.h b/src/client/draw.h index a0e65eb..b6b7b31 100644 --- a/src/client/draw.h +++ b/src/client/draw.h @@ -4,8 +4,6 @@ the terms and conditions of the GNU General Public License version 2 */ -#include "game/game.h" - namespace client { diff --git a/src/client/input.cc b/src/client/input.cc index d3b2900..17c52bb 100644 --- a/src/client/input.cc +++ b/src/client/input.cc @@ -1,10 +1,10 @@ /* client/input.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 */ - +#include "core/core.h" #include "client/client.h" #include "client/input.h" #include "client/console.h" @@ -13,12 +13,15 @@ #include "SDL/SDL.h" -namespace client +namespace client { -namespace input +namespace input { +// local offset to make turns +float turn_offset; + void init() { con_print << "Initializing input..." << std::endl; @@ -33,82 +36,90 @@ void shutdown() // handle key release for the game world void keyreleased(const SDL_keysym &keysym) { - switch( keysym.sym) { - case SDLK_SPACE: - camera::next_mode(); - break; - default: - break; + switch (keysym.sym) { + case SDLK_SPACE: + camera::next_mode(); + break; + default: + break; } } // handle key press events for the game world void keypressed(const SDL_keysym &keysym) { - switch( keysym.sym) { - case SDLK_LEFT: - camera::key_left(); - break; - case SDLK_RIGHT: - camera::key_right(); - break; - case SDLK_UP: - camera::key_up(); - break; - case SDLK_DOWN: - camera::key_down(); - break; - case SDLK_KP_PLUS: - // TODO set core entity params - game.ship->set_thrust(game.ship->thrust() + 0.08f); - break; - case SDLK_KP_MINUS: - // TODO set core entity params - game.ship->set_thrust(game.ship->thrust() - 0.1f); - break; - case SDLK_KP4: - // TODO set core entity params - game.ship->set_yaw(game.ship->yaw() + 10); - break; - case SDLK_KP6: - // TODO set core entity params - game.ship->set_yaw(game.ship->yaw() - 10); - break; - default: - break; + switch (keysym.sym) { + case SDLK_LEFT: + camera::key_left(); + break; + case SDLK_RIGHT: + camera::key_right(); + break; + case SDLK_UP: + camera::key_up(); + break; + case SDLK_DOWN: + camera::key_down(); + break; + case SDLK_KP_PLUS: + // TODO set core entity params + core::localplayer.controled->target_thrust += 0.08f; + break; + case SDLK_KP_MINUS: + // TODO set core entity params + core::localplayer.controled->target_thrust -= 0.1f; + break; + case SDLK_KP4: + // TODO set core entity params + turn_offset += 5; + if (turn_offset > 90) + turn_offset = 90; + break; + case SDLK_KP6: + // TODO set core entity params + turn_offset -= 5; + if (turn_offset < -90) + turn_offset = -90; + break; + default: + break; } - + } void frame(float seconds) { - SDL_Event event; - - while( SDL_PollEvent( &event ) ) { - - switch( event.type ) { - case SDL_KEYUP: - if (!console::visible() && core::connected()) - keyreleased(event.key.keysym ); - break; - case SDL_KEYDOWN: - if (event.key.keysym.sym == '`' || event.key.keysym.sym == '~') { - console::toggle(); - } else if (console::visible()) { - // send key events to the console - console::keypressed(event.key.keysym ); - } else if (core::connected()) { - // send key events to the game world - keypressed(event.key.keysym ); + SDL_Event event; + + while (SDL_PollEvent(&event)) { + + switch (event.type) { + case SDL_KEYUP: + if (!console::visible() && core::connected() && core::localplayer.controled) + // send key events to the game world + keyreleased(event.key.keysym); + break; + case SDL_KEYDOWN: + if (event.key.keysym.sym == '`' || event.key.keysym.sym == '~') { + console::toggle(); + } else if (console::visible()) { + // send key events to the console + console::keypressed(event.key.keysym); + } else if (core::connected() && core::localplayer.controled) { + // send key events to the game world + keypressed(event.key.keysym); + } + break; + case SDL_QUIT: + core::application()->shutdown(); + break; } - break; - case SDL_QUIT: - core::application()->shutdown(); - break; - } - - } - + + } + + if (!console::visible() && core::connected() && core::localplayer.controled) { + core::localplayer.controled->target_direction = math::degrees360f(core::localplayer.controled->direction+turn_offset); + } } } // namespace input diff --git a/src/client/input.h b/src/client/input.h index 8ab6c7d..daca0d6 100644 --- a/src/client/input.h +++ b/src/client/input.h @@ -7,9 +7,11 @@ #ifndef __INCLUDED_cLIENT_INPUT_H__ #define __INCLUDED_cLIENT_INPUT_H__ -namespace client { +namespace client +{ -namespace input { +namespace input +{ /// initialize the input subsystem void init(); diff --git a/src/client/view.cc b/src/client/view.cc index b6ef28a..5c54587 100644 --- a/src/client/view.cc +++ b/src/client/view.cc @@ -11,9 +11,8 @@ #include "client/draw.h" #include "render/render.h" #include "core/core.h" -#include "game/game.h" -#include "sys/sys.h" #include "math/mathlib.h" +#include "sys/sys.h" #include <iostream> #include <string> @@ -152,7 +151,6 @@ void frame(float seconds) gl::loadidentity(); gl::rotate(90.0f, 0, 1.0, 0); - camera::target = game.ship->location; camera::draw(seconds); // draw the current camera transformation gl::enable(GL_DEPTH_TEST); // enable depth buffer writing |