From f416e6b792e5dda143f60b7a2724db6b3ec33d75 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Fri, 28 Dec 2012 22:55:35 +0000 Subject: Support for rendering globes with rings, removed hardcoded 'corona' prefix for corona textures, added support for projectile fire sounds. --- src/audio/buffers.cc | 2 +- src/audio/buffers.h | 2 +- src/audio/sources.cc | 12 +++++++++ src/audio/sources.h | 3 +++ src/client/mapwindow.cc | 6 +++-- src/client/soundext.cc | 29 ++++++++++++++++------ src/client/soundext.h | 2 -- src/client/targets.cc | 2 +- src/game/base/ship.cc | 1 + src/game/base/star.cc | 2 +- src/game/base/weapon.cc | 4 +++ src/game/base/weapon.h | 20 ++++++++++++++- src/render/draw.cc | 66 +++++++++++++++++++++++++++++++++++++++++++++++-- src/render/draw.h | 5 +++- src/render/render.cc | 12 +++++++-- src/render/renderext.cc | 9 ++++++- src/ui/modelview.cc | 14 +++++++++-- src/ui/modelview.h | 3 ++- 18 files changed, 169 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/audio/buffers.cc b/src/audio/buffers.cc index 99c9e2e..b5dc8e3 100644 --- a/src/audio/buffers.cc +++ b/src/audio/buffers.cc @@ -79,7 +79,7 @@ size_t Buffers::load(std::string name) pcm = Vorbis::load(filename); } - // try the .oga version + // try the .ogg version if (!pcm) { filename.assign("sounds/"); filename.append(name); diff --git a/src/audio/buffers.h b/src/audio/buffers.h index 149c7f7..1086a5c 100644 --- a/src/audio/buffers.h +++ b/src/audio/buffers.h @@ -23,7 +23,7 @@ namespace audio { -const size_t MAXBUFFERS = 128; +const size_t MAXBUFFERS = 1024; /// OpenAL buffers wrapper class diff --git a/src/audio/sources.cc b/src/audio/sources.cc index 241332b..a3d7a8f 100644 --- a/src/audio/sources.cc +++ b/src/audio/sources.cc @@ -85,4 +85,16 @@ void Sources::remove(size_t index) //con_debug << "removed source " << index << std::endl; } +bool Sources::is_playing(size_t index) +{ + + if ((index < MAXUISOURCES) || (MAXSOURCES <= index)) + return false; + + ALint srcstate = 0; + alGetSourcei(sources[index] , AL_SOURCE_STATE , &srcstate); + + return (srcstate == AL_PLAYING); +} + } diff --git a/src/audio/sources.h b/src/audio/sources.h index 6292ff6..9bab08c 100644 --- a/src/audio/sources.h +++ b/src/audio/sources.h @@ -42,7 +42,10 @@ public: } static size_t get(); + static void remove(size_t index); + + static bool is_playing(size_t index); private: static void clear(); diff --git a/src/client/mapwindow.cc b/src/client/mapwindow.cc index c8ebaa8..19cf687 100644 --- a/src/client/mapwindow.cc +++ b/src/client/mapwindow.cc @@ -238,8 +238,10 @@ void MapWindow::show_entity_info(const core::Entity *entity) mapwindow_modelview->set_colors(globe->color(), globe->color_second()); mapwindow_modelview->set_globetexturename( globe->texturename(), - globe->has_flag(core::Entity::Bright), - globe->coronaname() + globe->coronaname(), + globe->ringsname(), + globe->has_flag(core::Entity::Bright) + ); mapwindow_modelview->set_zoom(2.5f); if (globe->has_flag(core::Entity::Bright)) { diff --git a/src/client/soundext.cc b/src/client/soundext.cc index aeb3bd1..477919c 100644 --- a/src/client/soundext.cc +++ b/src/client/soundext.cc @@ -11,6 +11,7 @@ #include "auxiliary/functions.h" #include "core/gameinterface.h" #include "core/entity.h" +#include "core/entityprojectile.h" #include "client/soundext.h" #include "client/client.h" #include "render/camera.h" @@ -128,6 +129,18 @@ SoundExt::SoundExt(core::Entity *entity) : core::Extension(core::Extension::Soun state_engineloopsource = audio::Sources::get(); state_engineeventsource = audio::Sources::get(); + + + } else if (entity->type() == core::Entity::Projectile) { + core::EntityProjectile *projectile = static_cast(entity); + + state_engineeventsource = audio::Sources::get(); + if (state_engineeventsource) { + state_impulsestartbuffer = audio::Buffers::load("projectiles/" + projectile->projectile_soundname()); + + audio::update_source(state_engineeventsource, entity->location(), math::Vector3f()); + audio::play(state_engineeventsource, state_impulsestartbuffer); + } } // load model sounds @@ -151,11 +164,6 @@ SoundExt::SoundExt(core::Entity *entity) : core::Extension(core::Extension::Soun } SoundExt::~SoundExt() -{ - clear(); -} - -void SoundExt::clear() { for (Sounds::iterator it = state_soundlist.begin(); it != state_soundlist.end(); it++) { client::Sound *sound = *it; @@ -193,11 +201,11 @@ void SoundExt::frame(float elapsed) float pitch = 1.0f; float gain = 0.0; - float r = (entity()->model() ? entity()->model()->box().max().x() * entity()->radius() / entity()->model()->radius() : entity()->radius()); - + float r = (entity()->model() ? entity()->model()->box().max().x() * entity()->radius() / entity()->model()->radius() : entity()->radius()); math::Vector3f velocity; if (entity()->type() == core::Entity::Controlable) { + // update engine sounds core::EntityControlable *entity = static_cast(this->entity()); speed = entity->speed(); @@ -271,6 +279,13 @@ void SoundExt::frame(float elapsed) audio::update_source(state_engineeventsource, entity->location() - entity->axis().forward() * r , velocity); + + } else if (entity()->type() == core::Entity::Projectile) { + + if (state_engineeventsource && !audio::Sources::is_playing(state_engineeventsource)) { + audio::Sources::remove(state_engineeventsource); + state_engineeventsource = 0; + } } for (Sounds::iterator it = state_soundlist.begin(); it != state_soundlist.end(); it++) { diff --git a/src/client/soundext.h b/src/client/soundext.h index cf5585e..2750afd 100644 --- a/src/client/soundext.h +++ b/src/client/soundext.h @@ -73,8 +73,6 @@ public: typedef std::list Sounds; private: - void clear(); - /// index of the audio buffer containing the thruster sound loop size_t state_thusterloopbuffer; /// index of the audio buffer containing the impulse sound loop diff --git a/src/client/targets.cc b/src/client/targets.cc index c76d621..6809939 100644 --- a/src/client/targets.cc +++ b/src/client/targets.cc @@ -341,7 +341,7 @@ void frame() core::Entity *entity = (*it); // render entity sound - if ((entity->type() == core::Entity::Controlable) || (entity->model() && entity->model()->sounds().size())) { + if ((entity->type() == core::Entity::Controlable) || (entity->type() == core::Entity::Projectile) || (entity->model() && entity->model()->sounds().size())) { render_entity_sound(entity); } diff --git a/src/game/base/ship.cc b/src/game/base/ship.cc index a7695dd..2368352 100644 --- a/src/game/base/ship.cc +++ b/src/game/base/ship.cc @@ -914,6 +914,7 @@ void Ship::frame(const unsigned long elapsed) projectile->set_damage(weapon->damage()); projectile->set_lifespan(weapon->projectile_lifespan()); projectile->set_projectile_modelname(weapon->projectile_modelname()); + projectile->set_projectile_soundname(weapon->projectile_soundname()); projectile->set_color(color()); projectile->set_color_second(color_second()); projectile->set_zone(zone()); diff --git a/src/game/base/star.cc b/src/game/base/star.cc index c54788a..c9dbb39 100644 --- a/src/game/base/star.cc +++ b/src/game/base/star.cc @@ -23,7 +23,7 @@ Star::Star() : core::EntityGlobe() entity_moduletypeid = star_enttype; // default star corona name - set_coronaname("default"); + set_coronaname("corona/default"); } Star::~Star() diff --git a/src/game/base/weapon.cc b/src/game/base/weapon.cc index 22527c2..1838733 100644 --- a/src/game/base/weapon.cc +++ b/src/game/base/weapon.cc @@ -187,6 +187,10 @@ bool Weapon::init() weapon->set_projectile_modelname(str); continue; + } else if (weaponsini.got_key_string("sound", str)) { + weapon->set_projectile_soundname(str); + continue; + } else { weaponsini.unknown_key(); diff --git a/src/game/base/weapon.h b/src/game/base/weapon.h index 746a9ad..31ce5de 100644 --- a/src/game/base/weapon.h +++ b/src/game/base/weapon.h @@ -75,6 +75,14 @@ public: { return weapon_projectile_modelname; } + + /** + * @brief name of the sound used when a projectile is fired by this weapon + * */ + inline const std::string & projectile_soundname() const + { + return weapon_projectile_soundname; + } /* --- mutators -------------------------------------------- */ @@ -117,12 +125,20 @@ public: } /** - * @brief set_projectile model name + * @brief set projectile model name * */ inline void set_projectile_modelname(const std::string & projectile_modelname) { weapon_projectile_modelname.assign(projectile_modelname); } + + /** + * @brief set the projectile sound name + * */ + inline void set_projectile_soundname(const std::string soundname) + { + weapon_projectile_soundname.assign(soundname); + } /** * @brief generate specifications info. @@ -161,6 +177,8 @@ private: float weapon_damage; std::string weapon_projectile_modelname; + + std::string weapon_projectile_soundname; }; } // namespace game diff --git a/src/render/draw.cc b/src/render/draw.cc index 46d0906..a49b017 100644 --- a/src/render/draw.cc +++ b/src/render/draw.cc @@ -239,6 +239,7 @@ void draw_globe_corona(const math::Vector3f location, const math::Color & color, if (a > 0.1f) { gl::enable(GL_BLEND); gl::disable(GL_DEPTH_TEST); + gl::depthmask(GL_FALSE); // disable depth buffer writes gl::enable(GL_TEXTURE_2D); Textures::bind(corona_id); @@ -263,11 +264,66 @@ void draw_globe_corona(const math::Vector3f location, const math::Color & color, gl::disable(GL_TEXTURE_2D); gl::enable(GL_DEPTH_TEST); + gl::depthmask(GL_TRUE); // enable depth buffer writes gl::disable(GL_BLEND); } } } +void draw_globe_rings(const math::Color & color, const size_t rings_id) +{ + gl::color(color); + + gl::enable(GL_BLEND); + //gl::disable(GL_CULL_FACE); + gl::depthmask(GL_FALSE); // disable depth buffer writes + + Textures::bind(rings_id); + + gl::begin(gl::Quads); + + // top + gl::normal(0.0f, 0.0f, 1.0f); + gl::texcoord(0, 0); + gl::vertex(-2.0f, -2.0f, 0.0f); + + gl::normal(0.0f, 0.0f, 1.0f); + gl::texcoord(1, 0); + gl::vertex(2.0f, -2.0f, 0.0f); + + gl::normal(0.0f, 0.0f, 1.0f); + gl::texcoord(1, 1); + gl::vertex(2.0f, 2.0f, 0.0f); + + gl::normal(0.0f, 0.0f, 1.0f); + gl::texcoord(0, 1); + gl::vertex(-2.0f, 2.0f, 0.0f); + + //bottom + gl::normal(0.0f, 0.0f, -1.0f); + gl::texcoord(0, 1); + gl::vertex(-2.0f, 2.0f, 0.0f); + + gl::normal(0.0f, 0.0f, -1.0f); + gl::texcoord(1, 1); + gl::vertex(2.0f, 2.0f, 0.0f); + + gl::normal(0.0f, 0.0f, -1.0f); + gl::texcoord(1, 0); + gl::vertex(2.0f, -2.0f, 0.0f); + + gl::normal(0.0f, 0.0f, -1.0f); + gl::texcoord(0, 0); + gl::vertex(-2.0f, -2.0f, 0.0f); + + gl::end(); + + gl::depthmask(GL_TRUE); // enable depth buffer writes + + //gl::enable(GL_CULL_FACE); + gl::disable(GL_BLEND); +} + void draw_pass_globes() { // FIXME is this ever reset ? @@ -311,17 +367,23 @@ void draw_pass_globes() } gl::multmatrix(globe->axis()); - if (globe->rotationspeed()) { float angle = math::degrees360f(core::application()->time() * globe->rotationspeed()); gl::rotate(angle, math::Vector3f::Zaxis()); } draw_sphere(globe->color(), radius); + + if (globe->rings_id()) { + if (!globe->texture_id()) { + gl::enable(GL_TEXTURE_2D); + } + draw_globe_rings(globe->color(), globe->rings_id()); + } gl::pop(); - if (globe->texture_id()) { + if (globe->texture_id() || globe->rings_id()) { gl::disable(GL_TEXTURE_2D); } diff --git a/src/render/draw.h b/src/render/draw.h index 122d7cd..a3b4d30 100644 --- a/src/render/draw.h +++ b/src/render/draw.h @@ -30,9 +30,12 @@ void reset(); /// draw a sphere void draw_sphere(const math::Color & color, float radius); -/// draw a corona +/// draw globe corona void draw_globe_corona(const math::Vector3f location, const math::Color & color, const float radius, const size_t corona_id); +/// draw globe rings +void draw_globe_rings(const math::Color & color, const size_t rings_id); + /// draw mode lights and flares void draw_model_lights( model::Model *model, const float scale, diff --git a/src/render/render.cc b/src/render/render.cc index 794d777..bf14e7d 100644 --- a/src/render/render.cc +++ b/src/render/render.cc @@ -154,9 +154,13 @@ void unload() globe->set_texture_id(0); } if (globe->corona_id()) { - render::Textures::unload("textures/corona/" + globe->coronaname()); + render::Textures::unload("textures/" + globe->coronaname()); globe->set_corona_id(0); } + if (globe->rings_id()) { + render::Textures::unload("textures/" + globe->ringsname()); + globe->set_rings_id(0); + } } if (ext_render(entity)) { @@ -182,9 +186,13 @@ void clear() globe->set_texture_id(0); } if (globe->corona_id()) { - render::Textures::unload("textures/corona/" + globe->coronaname()); + render::Textures::unload("textures/" + globe->coronaname()); globe->set_corona_id(0); } + if (globe->rings_id()) { + render::Textures::unload("textures/" + globe->ringsname()); + globe->set_rings_id(0); + } } if (ext_render(entity)) { diff --git a/src/render/renderext.cc b/src/render/renderext.cc index 0f781c5..1dc82f8 100644 --- a/src/render/renderext.cc +++ b/src/render/renderext.cc @@ -95,11 +95,18 @@ RenderExt::RenderExt(core::Entity *entity) : core::Extension(core::Extension::Re } if (!globe->corona_id() && globe->coronaname().size()) { - globe->set_corona_id(Textures::bind("textures/corona/" + globe->coronaname())); + globe->set_corona_id(Textures::load("textures/" + globe->coronaname())); if (!globe->corona_id()) { globe->set_coronaname(""); } } + + if (!globe->rings_id() && globe->ringsname().size()) { + globe->set_rings_id(Textures::load("textures/" + globe->ringsname())); + if (!globe->rings_id()) { + globe->set_ringsname(""); + } + } } } diff --git a/src/ui/modelview.cc b/src/ui/modelview.cc index 71fff6c..679c7b6 100755 --- a/src/ui/modelview.cc +++ b/src/ui/modelview.cc @@ -63,6 +63,7 @@ void ModelView::reset() modelview_globetexturename.clear(); modelview_globecoronaname.clear(); + modelview_globeringsname.clear(); modelview_globebright = false; } @@ -72,11 +73,12 @@ void ModelView::clear() modelview_mode = Model; } -void ModelView::set_globetexturename(const std::string & texturename, const bool bright, const std::string & coronaname) +void ModelView::set_globetexturename(const std::string & texturename, const std::string & coronaname, const std::string ringsname, const bool bright) { reset(); modelview_globetexturename.assign(texturename); modelview_globecoronaname.assign(coronaname); + modelview_globeringsname.assign(ringsname); modelview_globebright = bright; } @@ -231,7 +233,7 @@ void ModelView::draw_globe() gl::disable(GL_LIGHTING); if (modelview_globecoronaname.size()) { - size_t corona_id = render::Textures::load("textures/corona/" + modelview_globecoronaname); + size_t corona_id = render::Textures::load("textures/" + modelview_globecoronaname); render::draw_globe_corona(math::Vector3f(0.0f, 0.0f, 0.0f), modelview_color_primary, reference_radius, corona_id); } } @@ -246,6 +248,14 @@ void ModelView::draw_globe() render::draw_sphere(modelview_color_primary, reference_radius); + if (modelview_globeringsname.size()) { + size_t rings_id = render::Textures::load("textures/" + modelview_globeringsname); + if (!modelview_globetexturename.size()) { + gl::enable(GL_TEXTURE_2D); + } + render::draw_globe_rings(modelview_color_primary, rings_id); + } + gl::pop(); render::State::set_normalize(false); diff --git a/src/ui/modelview.h b/src/ui/modelview.h index 4642551..e23fd1c 100755 --- a/src/ui/modelview.h +++ b/src/ui/modelview.h @@ -45,7 +45,7 @@ public: /** * @brief show a textured globe with an optional corona * */ - void set_globetexturename(const std::string & texturename, const bool bright, const std::string & coronaname); + void set_globetexturename(const std::string & texturename, const std::string & coronaname, const std::string ringsname, const bool bright = false); /** * @brief show a model @@ -111,6 +111,7 @@ private: std::string modelview_modelname; std::string modelview_globetexturename; std::string modelview_globecoronaname; + std::string modelview_globeringsname; bool modelview_globebright; math::Color modelview_color_primary; -- cgit v1.2.3