adding event stuff to renderer to notify of new explosions

This commit is contained in:
Andreas Ortmann 2016-10-03 00:23:21 +02:00
parent f49d07fdc5
commit 544282dd84
6 changed files with 85 additions and 12 deletions

View file

@ -107,9 +107,19 @@ int main(int argc, char *argv[])
window.poll();
io_service.poll();
size_t numEvents = game.state()->currentStateUpdateEvents().size();
if (numEvents != 0) {
std::cout<<"game state update events: " << numEvents << std::endl;
for (game::StateUpdateEvent *evt : game.state()->currentStateUpdateEvents()) {
std::cout<< evt->description() << std::endl;
}
}
//if (sounds != nullptr) {
// sounds.advance(game->state());
//}
game.state()->applyAndClearAllOldStateUpdates();
}
return 0;

View file

@ -2,6 +2,8 @@
#include <iostream>
#include "state/events/explosion_event.hpp"
namespace endofthejedi {
void RendererPolygon3d::setup()
{
@ -250,6 +252,7 @@ namespace endofthejedi {
void RendererPolygon3d::advanceGraphicObjects(float dt)
{
#if 0
for (const game::Explosion *expl : m_state->explosions) {
bool gotIt = false;
for (ParticleBatch *batch : m_particles) {
@ -267,6 +270,24 @@ namespace endofthejedi {
1000, 1.0);
}
}
#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) {
game::ExplosionEvent *ee = static_cast<game::ExplosionEvent*>(evt);
const game::Explosion *expl = ee->explosion;
addExplosionEffect(
expl->id, expl->position,
expl->missileVelocity,
(expl->hit == game::Hit::Planet),
1000, 1.0);
std::cout<<"adding [graphic] explosion for #" << expl->id << std::endl;
}
}
}
//if (m_particles.size() == 0) {
// addExplosionEffect(0, glm::vec2(0.0, 0.0), glm::vec2(0.0, 0.0), false, 10000, 2.0);

View file

@ -16,6 +16,6 @@ namespace game {
}
public:
Explosion *explosion;
const Explosion *explosion;
};
}

View file

@ -366,7 +366,11 @@ namespace game {
//std::cout<<"[state] (before move) cycle: update events length is " << m_nextEvents.size() << std::endl;
// put collected events into that list.
m_allEvents.push_back(std::move(m_nextEvents));
//m_allEvents.push_back(std::move(m_nextEvents));
for (StateUpdateEvent *evt : m_nextEvents) {
m_allEvents.push_back(evt);
}
m_nextEvents.clear();
//std::cout<<"[state] (after move) cycle: update events length is " << m_nextEvents.size() << std::endl;
@ -511,12 +515,39 @@ namespace game {
// TODO: delete the items for events that are to be removed in proper
// way
for (std::list<StateUpdateEvent*> list : m_allEvents) {
for (StateUpdateEvent *evt : list) {
delete(evt);
//for (std::list<StateUpdateEvent*> list : m_allEvents) {
// for (StateUpdateEvent *evt : list) {
// delete(evt);
// }
// list.clear();
//}
for (StateUpdateEvent *evt : m_allEvents) {
if (evt->lifeCycle() == StateUpdateEvent::LifeCycle::Destroy) {
switch(evt->eventType()) {
case StateUpdateEvent::EventType::Explosion:
{
ExplosionEvent *ee = static_cast<ExplosionEvent*>(evt);
std::cout<<"got explosion delete event, finally deleting explosion #"
<< ee->explosion->id << std::endl;
delete(ee->explosion);
}
break;
default:
std::cout<<"warning: unhandled deletion event for: event type "
<< (int) evt->eventType() << std::endl;
}
}
list.clear();
delete(evt);
}
m_allEvents.clear();
}
std::list<StateUpdateEvent*> State::currentStateUpdateEvents() const
{
return m_allEvents;
}
}

View file

@ -105,6 +105,8 @@ namespace game {
void applyAndClearAllOldStateUpdates();
std::list<StateUpdateEvent*> currentStateUpdateEvents() const;
/*************************************************************************/
/* Rendering */
@ -161,6 +163,7 @@ namespace game {
glm::vec2 m_playingFieldSize;
std::list<StateUpdateEvent*> m_nextEvents;
std::vector<std::list<StateUpdateEvent*>> m_allEvents;
std::list<StateUpdateEvent*> m_allEvents;
//std::vector<std::list<StateUpdateEvent*>> m_allEvents;
};
}

View file

@ -31,16 +31,24 @@ namespace game {
std::string description() const
{
// TODO
return "<event>";
return "StateUpdateEvent(" + lifeCycleToString(m_lifeCycle) + ", " + eventTypeToString(m_eventType) + ")";
}
static std::string lifeCycleToString(LifeCycle lifeCycle)
{
switch(lifeCycle) {
case StateUpdateEvent::LifeCycle::Create: return "create";
case StateUpdateEvent::LifeCycle::Modify: return "modify";
case StateUpdateEvent::LifeCycle::Destroy: return "destroy";
default: return "<invalid>";
case LifeCycle::Create: return "create";
case LifeCycle::Modify: return "modify";
case LifeCycle::Destroy: return "destroy";
default: return "<no name>";
}
}
static std::string eventTypeToString(EventType eventType)
{
switch(eventType) {
case EventType::Explosion: return "explosion";
default: return "<no name>";
}
}