event stuff working again. a bit too much boiler plate code but functionality counts.

This commit is contained in:
Andreas Ortmann 2016-10-03 13:37:49 +02:00
parent 2d0608b205
commit becf8602d7
18 changed files with 235 additions and 149 deletions

View file

@ -3,6 +3,8 @@
#include <iostream>
#include "state/events/explosion_event.hpp"
#include "state/events/missile_event.hpp"
#include "state/events/ship_event.hpp"
namespace endofthejedi {
void RendererPolygon3d::setup()
@ -51,9 +53,10 @@ namespace endofthejedi {
// TODO: add dust particles
// TODO: add little rocks flying around
//glClearColor(0.0, 0.0, 0.0, 1.0);
float s = 0.1;
glClearColor(s, s, 1.2*s, 1.0);
glClearColor(0.0, 0.0, 0.0, 1.0);
//float s = 0.1;
//glClearColor(s, s, 1.2*s, 1.0);
m_shader_game_objects.bind();
@ -272,19 +275,46 @@ namespace endofthejedi {
}
#endif
for (game::StateUpdateEvent *evt : m_state->currentStateUpdateEvents()) {
if (evt->eventType() == game::StateUpdateEvent::EventType::Explosion) {
auto cycle = evt->lifeCycle();
if (cycle == game::StateUpdateEvent::LifeCycle::Create) {
for (auto *evt : m_state->currentStateUpdateEvents()) {
auto type = evt->eventType();
auto cycle = evt->lifeCycle();
if (type == game::EventType::Explosion) {
if (cycle == game::LifeCycle::Create) {
game::ExplosionEvent *ee = static_cast<game::ExplosionEvent*>(evt);
const game::Explosion *expl = ee->explosion;
game::Explosion *expl = static_cast<game::Explosion*>(ee->object());
addExplosionEffect(
expl->id, expl->position,
expl->missileVelocity,
(expl->hit == game::Hit::Planet),
1000, 1.0);
}
} else if (type == game::EventType::Ship) {
game::ShipEvent *me = static_cast<game::ShipEvent*>(evt);
game::Ship *ship = static_cast<game::Ship*>(me->object());
std::cout<<"adding [graphic] explosion for #" << expl->id << std::endl;
// is always modificated
if (cycle == game::LifeCycle::Create) {
//std::cout<<"[renderer] adding missile #" << missile->id << std::endl;
m_ships.push_back(ship);
} else if (cycle == game::LifeCycle::Destroy) {
//std::cout<<"[renderer] removing missile #" << missile->id << std::endl;
m_ships.remove(ship);
}
} else if (type == game::EventType::Missile) {
game::MissileEvent *me = static_cast<game::MissileEvent*>(evt);
game::Missile *missile = static_cast<game::Missile*>(me->object());
// is always modificated
if (cycle == game::LifeCycle::Create) {
//std::cout<<"[renderer] adding missile #" << missile->id << std::endl;
m_missiles.push_back(missile);
} else if (cycle == game::LifeCycle::Destroy) {
//std::cout<<"[renderer] removing missile #" << missile->id << std::endl;
m_missiles.remove(missile);
}
}
}
@ -333,16 +363,16 @@ namespace endofthejedi {
m_missileModel->bind();
for (const game::Player *player : m_state->players) {
for (const game::Missile *missile : player->missiles) {
glm::vec3 c = glm::vec3(1.0, 1.0, 0.3);
glUniform3f(m_shader_game_objects.location("materialColor"), c.x, c.y, c.z);
for (const game::Missile *missile : m_missiles) {
glm::vec3 c = glm::vec3(1.0, 1.0, 0.3);
glUniform3f(m_shader_game_objects.location("materialColor"), c.x, c.y, c.z);
glm::mat4 model = computeModelMatrix(missile);
glUniformMatrix4fv(m_shader_game_objects.location("model"), 1, GL_FALSE, glm::value_ptr(model));
// TODO: rename functions so their name represents what args they
// take
glm::mat4 model = computeModelMatrix(missile);
glUniformMatrix4fv(m_shader_game_objects.location("model"), 1, GL_FALSE, glm::value_ptr(model));
m_missileModel->render();
}
m_missileModel->render();
}
}
@ -350,7 +380,7 @@ namespace endofthejedi {
{
m_shipModel->bind();
for (const game::Ship *ship : m_state->ships) {
for (const game::Ship *ship : m_ships) {
glm::mat4 model = computeModelMatrix(ship);
glUniformMatrix4fv(m_shader_game_objects.location("model"), 1, GL_FALSE, glm::value_ptr(model));

View file

@ -83,5 +83,9 @@ namespace endofthejedi {
float m_lastTime;
float m_aspectRatio;
// TODO: put representation specialized for rendering in here
std::list<const game::Missile*> m_missiles;
std::list<const game::Ship*> m_ships;
};
}