diff options
author | Stijn Buys <ingar@osirion.org> | 2008-08-07 23:27:42 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2008-08-07 23:27:42 +0000 |
commit | a743791e624590e0b41229f28f940db5272b60ba (patch) | |
tree | 6a6ec736e4ed34d5254a292889e6e33300919a63 | |
parent | 1f36b993d603c56251aa15eb6edc6b92ecf599ae (diff) |
rotating planets, navpoints, network protocol updates, entity event state
-rw-r--r-- | osirion.kdevelop | 2 | ||||
-rw-r--r-- | src/client/targets.cc | 16 | ||||
-rw-r--r-- | src/client/view.cc | 29 | ||||
-rw-r--r-- | src/core/entity.cc | 104 | ||||
-rw-r--r-- | src/core/entity.h | 45 | ||||
-rw-r--r-- | src/core/net.h | 2 | ||||
-rw-r--r-- | src/core/zone.cc | 3 | ||||
-rw-r--r-- | src/game/Makefile.am | 4 | ||||
-rw-r--r-- | src/game/game.cc | 60 | ||||
-rw-r--r-- | src/game/game.h | 1 | ||||
-rw-r--r-- | src/game/navpoint.cc | 27 | ||||
-rw-r--r-- | src/game/navpoint.h | 27 | ||||
-rw-r--r-- | src/game/planet.cc | 4 | ||||
-rw-r--r-- | src/game/ship.cc | 35 | ||||
-rw-r--r-- | src/game/star.cc | 2 | ||||
-rw-r--r-- | src/render/draw.cc | 78 |
16 files changed, 324 insertions, 115 deletions
diff --git a/osirion.kdevelop b/osirion.kdevelop index 58a8bfc..82878a1 100644 --- a/osirion.kdevelop +++ b/osirion.kdevelop @@ -21,7 +21,7 @@ </general> <kdevautoproject> <general> - <activetarget>src/client/libclient.la</activetarget> + <activetarget>src/game/libgame.la</activetarget> <useconfiguration>debug</useconfiguration> </general> <run> diff --git a/src/client/targets.cc b/src/client/targets.cc index b913d55..f922199 100644 --- a/src/client/targets.cc +++ b/src/client/targets.cc @@ -369,7 +369,12 @@ void draw_entity_offscreen_target(core::Entity *entity, bool is_active_target) glVertex3f(cx, cy-r+2, 0); render::gl::end(); - render::gl::color(1, 1, 1, 1); + if (entity->type() == core::Entity::Controlable) { + render::gl::color(0, 1, 0, 1); + } else { + render::gl::color(1, 1, 1, 1); + } + render::gl::begin(render::gl::LineLoop); glVertex3f(cx+r, cy, 0); glVertex3f(cx, cy+r, 0); @@ -415,7 +420,7 @@ void draw_entity_target(core::Entity *entity, bool is_active_target) r *= 0.5; render::gl::disable(GL_TEXTURE_2D); - + // outer square shadow render::gl::color(0, 0, 0, 1); render::gl::begin(render::gl::LineLoop); glVertex3f(cx+r, cy+2, 0); @@ -424,7 +429,12 @@ void draw_entity_target(core::Entity *entity, bool is_active_target) glVertex3f(cx, cy-r+2, 0); render::gl::end(); - render::gl::color(1, 1, 1, 1); + if (entity->type() == core::Entity::Controlable) { + render::gl::color(0, 1, 0, 1); + } else { + render::gl::color(1, 1, 1, 1); + } + // outer square0 render::gl::begin(render::gl::LineLoop); glVertex3f(cx+r, cy, 0); glVertex3f(cx, cy+r, 0); diff --git a/src/client/view.cc b/src/client/view.cc index 5879728..eef3920 100644 --- a/src/client/view.cc +++ b/src/client/view.cc @@ -170,15 +170,32 @@ void draw_status() status << "^Nspeed ^B" << std::setfill(' ') << std::setw(5) << std::fixed << std::setprecision(2) << core::localcontrol()->speed(); - Text::draw(4, video::height - Text::fontheight() -4, status); + Text::draw(4, video::height - Text::fontheight()-4, status); + + unsigned int state = core::localcontrol()->eventstate(); + if (state) { + std::stringstream statestr; + statestr.clear(); + if (state == core::Entity::ImpulseInitiate) { + statestr << "^FInitializing kinetic impulse drive " << core::localcontrol()->timer(); + } else if (state == core::Entity::Impulse) { + statestr << "^FKinetic impulse"; + } else if (state == core::Entity::JumpInitiate) { + statestr << "^FInitializing hyperspace jump drive "<< core::localcontrol()->timer(); + } else if (state == core::Entity::Jump) { + statestr << "^FJumping..."; + } + + Text::draw(4, video::height - Text::fontheight()*2-4, statestr); + } if (draw_location->value()) { std::stringstream location; - location << "^Nloc ^B" << std::fixed << std::setprecision(2) << std::setfill(' ') << - std::setw(7) << core::localcontrol()->location().x << " " << - std::setw(7) << core::localcontrol()->location().y << " " << - std::setw(7) << core::localcontrol()->location().z; - Text::draw(4, video::height - Text::fontheight()*2 -4, location); + location << std::fixed << std::setprecision(2) + << "^Nx:^B" << core::localcontrol()->location().x << " " + << "^Ny:^B" << core::localcontrol()->location().y << " " + << "^Nz:^B" << core::localcontrol()->location().z << '\n'; + Text::draw(4, video::height - Text::fontheight()*3 -4, location); } float y = 1.0f; diff --git a/src/core/entity.cc b/src/core/entity.cc index 483f58c..a4b6ee5 100644 --- a/src/core/entity.cc +++ b/src/core/entity.cc @@ -170,18 +170,18 @@ void Entity::set_zone(Zone *zone) void Entity::serialize_server_create(std::ostream & os) const { os << entity_moduletypeid << " " - << entity_flags << " " - << (entity_zone ? entity_zone->id() : 0) << " " - << entity_location << " " - << entity_color << " " - << entity_color_second << " " - << entity_shape << " " - << entity_radius << " " - << entity_axis.forward() << " " - << entity_axis.left() << " " - << "\"" << entity_label << "\" " - << "\"" << entity_name << "\" " - << "\"" << entity_modelname << "\""; + << entity_flags << " " + << (entity_zone ? entity_zone->id() : 0) << " " + << entity_location << " " + << entity_color << " " + << entity_color_second << " " + << entity_shape << " " + << entity_radius << " " + << entity_axis.forward() << " " + << entity_axis.left() << " " + << "\"" << entity_label << "\" " + << "\"" << entity_name << "\" " + << "\"" << entity_modelname << "\" "; } void Entity::receive_server_create(std::istream &is) @@ -263,12 +263,16 @@ EntityDynamic::EntityDynamic(unsigned int flags) : Entity(flags) { entity_speed = 0.0f; + entity_eventstate = Normal; + entity_timer = 0; } EntityDynamic::EntityDynamic(std::istream & is) : Entity(is) { entity_speed = 0.0f; + entity_eventstate = Normal; + entity_timer = 0; } EntityDynamic::~EntityDynamic() @@ -291,13 +295,26 @@ void EntityDynamic::frame(float seconds) void EntityDynamic::serialize_server_create(std::ostream & os) const { Entity::serialize_server_create(os); - os << " " << entity_speed; + os << roundf(entity_speed * 100.0f) << " " + << entity_eventstate << " "; + + if (entity_eventstate != Normal) { + os << entity_timer << " "; + } } void EntityDynamic::receive_server_create(std::istream &is) { Entity::receive_server_create(is); is >> entity_speed; + entity_speed /= 100.0f; + is >> entity_eventstate; + + if (entity_eventstate != Normal) { + is >> entity_timer; + } else { + entity_timer = 0; + } } void EntityDynamic::serialize_client_update(std::ostream & os) const @@ -310,10 +327,15 @@ void EntityDynamic::receive_client_update(std::istream &is) void EntityDynamic::serialize_server_update(std::ostream & os) const { - os << entity_location << " "; - os << entity_axis.forward() << " "; - os << entity_axis.left() << " "; - os << entity_speed; + os << entity_location << " " + << entity_axis.forward() << " " + << entity_axis.left() << " " + << roundf(entity_speed * 100.0f) << " " + << entity_eventstate << " "; + + if (entity_eventstate != Normal) { + os << entity_timer << " "; + } } void EntityDynamic::receive_server_update(std::istream &is) @@ -324,6 +346,14 @@ void EntityDynamic::receive_server_update(std::istream &is) is >> entity_axis[1]; entity_axis[2] = math::crossproduct(entity_axis.forward(), entity_axis.left()); is >> entity_speed; + entity_speed /= 100.0f; + is >> entity_eventstate; + + if (entity_eventstate != Normal) { + is >> entity_timer; + } else { + entity_timer = 0; + } } /*----- EntityControlable ------------------------------------------ */ @@ -332,7 +362,6 @@ EntityControlable::EntityControlable(Player *owner, unsigned int flags) : EntityDynamic(flags) { entity_thrust = 0; - entity_autolevel = false; target_direction = 0.0f; target_thrust = 0.0f; @@ -348,7 +377,6 @@ EntityControlable::EntityControlable(std::istream & is) : EntityDynamic(is) { entity_thrust = 0; - entity_autolevel = false; target_direction = 0.0f; target_thrust = 0.0f; @@ -368,8 +396,8 @@ EntityControlable::~EntityControlable() void EntityControlable::serialize_server_create(std::ostream & os) const { EntityDynamic::serialize_server_create(os); - os << " " << entity_thrust; - os << " " << ( entity_owner ? entity_owner->id() : 0); + os << roundf(entity_thrust*100.0f) << " " + << ( entity_owner ? entity_owner->id() : 0) << " "; } void EntityControlable::receive_server_create(std::istream &is) @@ -378,6 +406,7 @@ void EntityControlable::receive_server_create(std::istream &is) EntityDynamic::receive_server_create(is); is >> entity_thrust; + entity_thrust /= 100.0f; is >> o; // FIXME resolve owner @@ -387,12 +416,10 @@ void EntityControlable::receive_server_create(std::istream &is) void EntityControlable::serialize_client_update(std::ostream & os) const { EntityDynamic::serialize_client_update(os); - os << " " << target_direction; - os << " " << target_pitch; - os << " " << target_thrust; - os << " " << target_roll; - os << " " << (autolevel() ? 1 : 0); - + os << target_direction << " "; + os << target_pitch << " "; + os << target_thrust << " "; + os << target_roll << " "; } void EntityControlable::receive_client_update(std::istream &is) @@ -402,25 +429,19 @@ void EntityControlable::receive_client_update(std::istream &is) is >> target_pitch; is >> target_thrust; is >> target_roll; - - unsigned int b = 0; - is >> b; - if (b) - entity_autolevel = true; - else - entity_autolevel = false; } void EntityControlable::serialize_server_update(std::ostream & os) const { EntityDynamic::serialize_server_update(os); - os << " " << entity_thrust; + os << roundf(entity_thrust*100.0f) << " "; } void EntityControlable::receive_server_update(std::istream &is) { EntityDynamic::receive_server_update(is); is >> entity_thrust; + entity_thrust /= 100.0f; } void EntityControlable::frame(float seconds) @@ -442,13 +463,6 @@ void EntityControlable::set_thrust(float thrust) } } -void EntityControlable::set_autolevel(bool autolevel) -{ - if (entity_autolevel != autolevel) { - entity_autolevel = autolevel; - entity_dirty = true; - } -} void EntityControlable::set_direction(float direction) { if ((flags() & Static) == Static) @@ -488,6 +502,7 @@ EntityGlobe::EntityGlobe(unsigned int flags) : Entity(flags) { render_texture = 0; + entity_rotationspeed = 0; entity_shape = Sphere; } @@ -495,6 +510,7 @@ EntityGlobe::EntityGlobe(std::istream & is) : Entity(is) { render_texture = 0; + entity_rotationspeed = 0; entity_shape = Sphere; } @@ -505,13 +521,15 @@ EntityGlobe::~EntityGlobe() void EntityGlobe::serialize_server_create(std::ostream & os) const { Entity::serialize_server_create(os); - os << " \"" << entity_texture << "\""; + os << entity_rotationspeed << " \"" << entity_texture << "\" "; } void EntityGlobe::receive_server_create(std::istream &is) { Entity::receive_server_create(is); + is >> entity_rotationspeed; + std::string n; char c; while ( (is.get(c)) && (c != '"')); diff --git a/src/core/entity.h b/src/core/entity.h index 40d1ffa..2b2ed00 100644 --- a/src/core/entity.h +++ b/src/core/entity.h @@ -46,6 +46,9 @@ public: /// Entity shape constants enum Shape {Diamond=0, Sphere=1, Cube=2, Axis=3}; + /// EntityDynamic event state classes + enum Event {Normal=0, ImpulseInitiate=2, Impulse=3, JumpInitiate=4, Jump=5}; + /// create a new entity and add it to the registry Entity(unsigned int flags = 0); @@ -111,6 +114,8 @@ public: /// base radius of the entity inline float radius() const { return entity_radius; } +/*----- serializers ----------------------------------------------- */ + /// serialize the entity to a stream virtual void serialize_server_create(std::ostream & os) const; @@ -120,7 +125,6 @@ public: /// serialize a server-to-client update on a stream virtual void serialize_server_update(std::ostream & os) const; - /*----- mutators -------------------------------------------------- */ /// receive a client-to-server update from a stream @@ -227,7 +231,6 @@ public: virtual ~EntityDynamic(); - /*----- inspectors ------------------------------------------------ */ /// core type id virtual inline unsigned int type() const { return Entity::Dynamic; } @@ -235,6 +238,14 @@ public: /// current speed of the entity in game units per second inline float speed() const { return entity_speed; } + /// event state + inline unsigned int eventstate() const { return entity_eventstate; } + + /// event state timer + inline float timer() const { return entity_timer; } + +/*----- serializers ----------------------------------------------- */ + /// serialize the entity to a stream virtual void serialize_server_create(std::ostream & os) const; @@ -264,13 +275,17 @@ public: /// speed of the entity float entity_speed; + +protected: + unsigned int entity_eventstate; + float entity_timer; + }; /// an entity that can be controlled by a player class EntityControlable : public EntityDynamic { friend class Player; - public: /// create a controlable entity EntityControlable(Player *owner, unsigned int flags = 0); @@ -292,6 +307,8 @@ public: /// thrust inline float thrust() const { return entity_thrust; } +/*----- serializers ----------------------------------------------- */ + /// serialize the entity to a stream virtual void serialize_server_create(std::ostream & os) const; @@ -301,10 +318,6 @@ public: /// serialize a server-to-client update on a stream virtual void serialize_server_update(std::ostream & os) const; - /// autolevel mode - bool autolevel() const { return entity_autolevel; } - - /*----- mutators -------------------------------------------------- */ /// receive a client-to-server update from a stream @@ -322,9 +335,6 @@ public: /// set the target direction void set_direction(float direction); - /// set autolevel request - void set_autolevel(bool autolevel); - /// set the target pitch void set_pitch(float pitch); @@ -360,7 +370,6 @@ public: private: // owner of the entity Player *entity_owner; - bool entity_autolevel; }; /// a Globe entity @@ -372,14 +381,21 @@ public: ~EntityGlobe(); +/*----- inspectors ----------------------------------------------- */ + /// texture name + inline const std::string &texture() const { return entity_texture; } + + /// rotation speed in degrees per second + inline float rotationspeed() const { return entity_rotationspeed; } + +/*----- serializers ----------------------------------------------- */ + /// serialize the entity to a stream virtual void serialize_server_create(std::ostream & os) const; /// receive a server-to-client create from a stream virtual void receive_server_create(std::istream &is); - inline const std::string &texture() const { return entity_texture; } - /*----- inspectors ------------------------------------------------ */ /// core type id @@ -389,6 +405,9 @@ public: /// client side, texture id unsigned int render_texture; + + /// rotation speed in degrees/second; + float entity_rotationspeed; }; } diff --git a/src/core/net.h b/src/core/net.h index 0c2b5a6..d5a95a9 100644 --- a/src/core/net.h +++ b/src/core/net.h @@ -11,7 +11,7 @@ namespace core { /// network protocol version -const unsigned int PROTOCOLVERSION = 6; +const unsigned int PROTOCOLVERSION = 7; /// maximum lenght of a (compressed) network message block const unsigned int FRAMESIZE = 1152; diff --git a/src/core/zone.cc b/src/core/zone.cc index a81736d..87ab9b4 100644 --- a/src/core/zone.cc +++ b/src/core/zone.cc @@ -103,7 +103,8 @@ void Zone::list_zone(std::string const & searchname) con_print << " id " << std::setw(4) << entity->id() << " type " << std::setw(4) << entity->type() << ":" << std::setw(4) << entity->moduletype() - << " " << entity->label() << std::endl; + << " " << std::setw(24) << entity->label() + << " ^B" << entity->name() << "^N" << std::endl; } con_print << zone->zone_content.size() << " zone entities" << std::endl; } diff --git a/src/game/Makefile.am b/src/game/Makefile.am index 394e209..17bd6d3 100644 --- a/src/game/Makefile.am +++ b/src/game/Makefile.am @@ -2,7 +2,7 @@ INCLUDES = -I$(top_srcdir)/src METASOURCES = AUTO libgame_la_LDFLAGS = -avoid-version -libgame_la_SOURCES = game.cc planet.cc ship.cc shipmodel.cc star.cc +libgame_la_SOURCES = game.cc navpoint.cc planet.cc ship.cc shipmodel.cc star.cc noinst_LTLIBRARIES = libgame.la -noinst_HEADERS = game.h planet.h ship.h shipmodel.h star.h +noinst_HEADERS = game.h navpoint.h planet.h ship.h shipmodel.h star.h diff --git a/src/game/game.cc b/src/game/game.cc index e469a31..f35670a 100644 --- a/src/game/game.cc +++ b/src/game/game.cc @@ -11,6 +11,7 @@ #include "filesystem/filesystem.h" #include "filesystem/inifile.h" #include "game/game.h" +#include "game/navpoint.h" #include "game/planet.h" #include "game/ship.h" #include "game/star.h" @@ -311,6 +312,7 @@ bool Game::load_zone(core::Zone *zone) Planet *planet = 0; Star *star = 0; + NavPoint *navpoint = 0; core::Entity *entity = 0; float direction; @@ -344,34 +346,63 @@ bool Game::load_zone(core::Zone *zone) aux::to_label(strval); star->entity_label.assign(strval); continue; - } else if (zoneini.got_key_string("name", star->entity_name)) + } else if (zoneini.got_key_string("name", star->entity_name)) { continue; - else if (zoneini.got_key_vector3f("location", star->entity_location )) + } else if (zoneini.got_key_vector3f("location", star->entity_location )) { continue; - else if (zoneini.got_key_color("color", star->entity_color)) + } else if (zoneini.got_key_color("color", star->entity_color)) { continue; - else if (zoneini.got_key_angle("radius", star->entity_radius)) + } else if (zoneini.got_key_angle("radius", star->entity_radius)) { continue; - else + } else if (zoneini.got_key_angle("direction", direction)) { + planet->axis().change_direction(direction); + continue; + } else if (zoneini.got_key_string("texture", planet->entity_texture)) { + continue; + } else if (zoneini.got_key_angle("pitch", pitch)) { + planet->axis().change_pitch(pitch); + continue; + } else { con_warn << zoneini.name() << " unknown key '" << zoneini.key() << "' at line " << zoneini.line() << std::endl; - + } + } else if (zoneini.section().compare("navpoint") == 0) { + if (zoneini.got_key_string("label", strval)) { + aux::to_label(strval); + navpoint->entity_label.assign(strval); + continue; + } else if (zoneini.got_key_string("name", navpoint->entity_name)) { + continue; + } else if (zoneini.got_key_vector3f("location", navpoint->entity_location )) { + continue; + } else { + con_warn << zoneini.name() << " unknown key '" << zoneini.key() << "' at line " << zoneini.line() << std::endl; + } } else if (zoneini.section().compare("planet") == 0) { if (zoneini.got_key_string("label", strval)) { aux::to_label(strval); planet->entity_label.assign(strval); continue; - } else if (zoneini.got_key_string("name", planet->entity_name)) + } else if (zoneini.got_key_string("name", planet->entity_name)) { continue; - else if (zoneini.got_key_string("texture", planet->entity_texture)) + } else if (zoneini.got_key_string("texture", planet->entity_texture)) { continue; - else if (zoneini.got_key_vector3f("location", planet->entity_location )) + } else if (zoneini.got_key_vector3f("location", planet->entity_location )) { + continue; + } else if (zoneini.got_key_color("color", planet->entity_color)) { + continue; + } else if (zoneini.got_key_angle("radius", planet->entity_radius)) { + continue; + } else if (zoneini.got_key_angle("direction", direction)) { + planet->axis().change_direction(direction); continue; - else if (zoneini.got_key_color("color", planet->entity_color)) + } else if (zoneini.got_key_angle("pitch", pitch)) { + planet->axis().change_pitch(pitch); continue; - else if (zoneini.got_key_angle("radius", planet->entity_radius)) + } else if (zoneini.got_key_float("rotationspeed", planet->entity_rotationspeed)) { continue; - else + } else { con_warn << zoneini.name() << " unknown key '" << zoneini.key() << "' at line " << zoneini.line() << std::endl; + } } else if (zoneini.section().compare("entity") == 0) { std::string shapename; @@ -425,6 +456,11 @@ bool Game::load_zone(core::Zone *zone) star->set_zone(zone); count ++; + } else if (zoneini.got_section("navpoint")) { + navpoint = new NavPoint(); + navpoint->set_zone(zone); + count ++; + } else if (zoneini.got_section("planet")) { planet = new Planet(); planet->set_zone(zone); diff --git a/src/game/game.h b/src/game/game.h index 2ad977f..36f7321 100644 --- a/src/game/game.h +++ b/src/game/game.h @@ -27,6 +27,7 @@ namespace game const unsigned int ship_enttype = 256; const unsigned int star_enttype = 257; const unsigned int planet_enttype = 258; +const unsigned int navpoint_enttype = 259; class Game : public core::Module { public: diff --git a/src/game/navpoint.cc b/src/game/navpoint.cc new file mode 100644 index 0000000..24e87ca --- /dev/null +++ b/src/game/navpoint.cc @@ -0,0 +1,27 @@ +/* + game/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 +*/ + +#include "game/navpoint.h" +#include "game/game.h" + +namespace game +{ + +NavPoint::NavPoint() : core::Entity(core::Entity::Static | core::Entity::Bright) +{ + entity_shape = core::Entity::Diamond; + entity_color.assign(1.0f, 1.0f); + entity_color_second.assign(0.6f, 1.0f); + entity_radius = 0.25f; + + entity_moduletypeid = navpoint_enttype; +} + +NavPoint::~NavPoint() +{ +} + +} diff --git a/src/game/navpoint.h b/src/game/navpoint.h new file mode 100644 index 0000000..ef60267 --- /dev/null +++ b/src/game/navpoint.h @@ -0,0 +1,27 @@ +/* + game/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 +*/ + +#ifndef __INCLUDED_GAME_NAVPOINT_H__ +#define __INCLUDED_GAME_NAVPOINT_H__ + +#include "core/entity.h" +#include "math/mathlib.h" + +#include <string> + +namespace game { + +/// a navigation point +class NavPoint : public core::Entity { +public: + NavPoint(); + ~NavPoint(); +}; + +} + +#endif // __INCLUDED_GAME_NAVPOINT_H__ + diff --git a/src/game/planet.cc b/src/game/planet.cc index 91055b7..80e4922 100644 --- a/src/game/planet.cc +++ b/src/game/planet.cc @@ -13,9 +13,11 @@ namespace game { Planet::Planet() : core::EntityGlobe(core::Entity::Static | core::Entity::Solid) { entity_color = math::Color(1,1,1,1); // white - entity_radius = 32; // 32 game units + entity_radius = 64; // 64 game units entity_moduletypeid = planet_enttype; + + entity_rotationspeed = 1.0f; } Planet::~Planet() diff --git a/src/game/ship.cc b/src/game/ship.cc index 8492b68..f8a1143 100644 --- a/src/game/ship.cc +++ b/src/game/ship.cc @@ -7,6 +7,7 @@ // project headers #include "auxiliary/functions.h" #include "core/gameserver.h" +#include "core/entity.h" #include "game/game.h" #include "game/ship.h" #include "math/mathlib.h" @@ -56,7 +57,7 @@ void Ship::impulse() { if (ship_impulse) { ship_impulse = false; - + entity_eventstate = core::Entity::Normal; } else { if (ship_jumpdrive_activated) { ship_jumpdrive_activated = 0; @@ -64,8 +65,10 @@ void Ship::impulse() ship_countdown = 0; } + entity_eventstate = core::Entity::Impulse; ship_impulse = true; } + entity_dirty = true; } void Ship::jump(std::string const &args) @@ -80,6 +83,7 @@ void Ship::jump(std::string const &args) ship_jumpdrive_activated = 0; ship_jumptargetzone = 0; ship_countdown = 0; + entity_eventstate = core::Entity::Normal; return; } @@ -112,13 +116,16 @@ void Ship::jump(std::string const &args) } ship_jumpdrive_activated = core::server()->time(); - ship_countdown = 5; + ship_countdown = 10; ship_impulse = false; std::stringstream msg(""); - msg << "Hyperspace drive activated. Jumping in " << ship_countdown << "..."; + msg << "Initializing hyperspace jump drive..."; core::server()->send(owner(), msg.str()); + entity_eventstate = core::Entity::JumpInitiate; + entity_timer = ship_countdown; // countdown to jump, in seconds + entity_dirty = true; } void Ship::frame(float seconds) @@ -144,6 +151,8 @@ void Ship::frame(float seconds) if (ship_jumpdrive_activated + 1.0f <= core::server()->time()) { ship_countdown -= 1.0f; + entity_timer = ship_countdown; + if (ship_countdown <= 0) { core::server()->send(owner(), "Jumping to '" + ship_jumptargetzone->name() + '\''); set_zone(ship_jumptargetzone); @@ -151,12 +160,17 @@ void Ship::frame(float seconds) owner()->set_zone(ship_jumptargetzone); ship_jumpdrive_activated = 0; ship_jumptargetzone = 0; + entity_dirty = true; + entity_eventstate = core::Entity::Jump; return; } else { - std::stringstream msg(""); - msg << ship_countdown << "..."; - core::server()->send(owner(), msg.str()); + if (ship_countdown <= 5) { + std::stringstream msg(""); + msg << ship_countdown << "..."; + core::server()->send(owner(), msg.str()); + } ship_jumpdrive_activated = core::server()->time(); + entity_dirty = true; } } @@ -166,6 +180,15 @@ void Ship::frame(float seconds) target_roll = 0; target_direction = 0; + } else if (entity_eventstate == core::Entity::Jump) { + // FIXME jump location and axis + math::Axis default_axis; + entity_axis.assign(default_axis); + entity_dirty = true; + + // FIXME 5 second cooldown + entity_eventstate = core::Entity::Normal; + } else if (ship_impulse) { // clamp input values diff --git a/src/game/star.cc b/src/game/star.cc index 367054f..fd0c57b 100644 --- a/src/game/star.cc +++ b/src/game/star.cc @@ -13,7 +13,7 @@ namespace game { Star::Star() : core::EntityGlobe(core::Entity::Static | core::Entity::Solid | core::Entity::Bright) { entity_color = math::Color(1,1,1,1); // white - entity_radius = 48; // 48 game units + entity_radius = 96; // 96 game units entity_moduletypeid = star_enttype; } diff --git a/src/render/draw.cc b/src/render/draw.cc index 3e3a13e..26b1109 100644 --- a/src/render/draw.cc +++ b/src/render/draw.cc @@ -8,6 +8,7 @@ #include <iomanip> #include "core/core.h" +#include "core/range.h" #include "model/fragment.h" #include "model/material.h" #include "model/model.h" @@ -39,7 +40,7 @@ math::Vector3f v5(1, 1, -1); math::Vector3f v6(-1, 1, -1); math::Vector3f v7(-1, -1, -1); -const float drawdistance = 128.0f; +const float drawdistance = 256.0f; const float drawfxdistance = 64.0f; const float farplane = 1016.0f; @@ -133,7 +134,7 @@ void pass_prepare(float seconds) // entites within detail range entity->state()->state_visible = true; entity->state()->state_detailvisible = true; - } else if (entity->state()->distance() < drawdistance * r) { + } else if (entity->state()->distance() < drawdistance * r && entity->state()->distance() < core::range::max) { // entities within drawing distance, outside detail range entity->state()->state_visible = true; entity->state()->state_detailvisible = false; @@ -297,7 +298,13 @@ void draw_globe(core::EntityGlobe *globe) gl::translate(location); gl::multmatrix(globe->state()->axis()); + if (globe->rotationspeed()) { + float angle = core::application()->time() * globe->rotationspeed(); + angle = angle - 360.0f * floorf(angle / 360.0f); + gl::rotate(angle, math::Vector3f::Zaxis()); + } draw_sphere(globe->color(), radius); + gl::pop(); if (globe->state()->distance() > farplane) { @@ -391,6 +398,38 @@ void draw_entity_diamond(core::Entity *entity) { float radius = entity->radius()/2; + /* ---- draw axis lines ---- */ + gl::color(entity->color_second()); + gl::begin(gl::Lines); + + 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); + + gl::vertex(0, 0, 1.25f * radius); + gl::vertex(0, 0, 2 * radius); + + 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); + + gl::vertex(0, 0, -1.25f * radius); + gl::vertex(0, 0, -2 * radius); + + gl::end(); + + /* ---- draw rotating body lines ---- */ + float angle = (core::application()->time() + entity->state()->fuzz() ) * 45.0f; + angle = angle - 360.0f * floorf(angle / 360.0f); + gl::rotate(angle, math::Vector3f::Zaxis()); + + if (r_wireframe->value() == 0.0f) { + glPolygonMode(GL_FRONT, GL_LINE); + } gl::color(entity->color()); gl::begin(gl::TriangleFan ); @@ -430,28 +469,9 @@ void draw_entity_diamond(core::Entity *entity) gl::vertex(radius, 0.0f, 0.0f); gl::end(); - - gl::begin(gl::Lines); - - gl::vertex(radius, 0, 0); - gl::vertex(2* radius, 0, 0); - - gl::vertex(0, radius, 0); - gl::vertex(0, 2* radius, 0); - - gl::vertex(0, 0, radius); - gl::vertex(0, 0, 2 * radius); - - gl::vertex(-radius, 0, 0); - gl::vertex(-2 * radius, 0, 0); - - gl::vertex(0, -radius, 0); - gl::vertex(0, -2 * radius, 0); - - gl::vertex(0, 0, -radius); - gl::vertex(0, 0, -2 * radius); - - gl::end(); + if (r_wireframe->value() == 0.0f) { + glPolygonMode(GL_FRONT, GL_FILL); + } } void draw_entity_axis(core::Entity *entity) @@ -459,7 +479,7 @@ void draw_entity_axis(core::Entity *entity) float r = entity->radius(); gl::begin(gl::Lines); - gl::color(1.0f, 0.0f, 0.0f); + gl::color(entity->color_second()); gl::vertex(r,0.0f,0.0f); gl::color(entity->color()); gl::vertex(-r,0.0f,0.0f); @@ -483,6 +503,10 @@ void draw_pass_default() gl::translate(entity->state()->location()); gl::multmatrix(entity->state()->axis()); + if (flag_is_set(entity->flags(), core::Entity::Bright)) { + gl::disable(GL_LIGHTING); + } + switch(entity->shape()) { case core::Entity::Sphere: draw_entity_sphere(entity); @@ -503,6 +527,10 @@ void draw_pass_default() break; } + if (flag_is_set(entity->flags(), core::Entity::Bright)) { + gl::enable(GL_LIGHTING); + } + gl::pop(); } } |