adding event stuff to renderer to notify of new explosions
This commit is contained in:
parent
f49d07fdc5
commit
544282dd84
6 changed files with 85 additions and 12 deletions
|
@ -107,9 +107,19 @@ int main(int argc, char *argv[])
|
||||||
window.poll();
|
window.poll();
|
||||||
io_service.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) {
|
//if (sounds != nullptr) {
|
||||||
// sounds.advance(game->state());
|
// sounds.advance(game->state());
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
game.state()->applyAndClearAllOldStateUpdates();
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "state/events/explosion_event.hpp"
|
||||||
|
|
||||||
namespace endofthejedi {
|
namespace endofthejedi {
|
||||||
void RendererPolygon3d::setup()
|
void RendererPolygon3d::setup()
|
||||||
{
|
{
|
||||||
|
@ -250,6 +252,7 @@ namespace endofthejedi {
|
||||||
|
|
||||||
void RendererPolygon3d::advanceGraphicObjects(float dt)
|
void RendererPolygon3d::advanceGraphicObjects(float dt)
|
||||||
{
|
{
|
||||||
|
#if 0
|
||||||
for (const game::Explosion *expl : m_state->explosions) {
|
for (const game::Explosion *expl : m_state->explosions) {
|
||||||
bool gotIt = false;
|
bool gotIt = false;
|
||||||
for (ParticleBatch *batch : m_particles) {
|
for (ParticleBatch *batch : m_particles) {
|
||||||
|
@ -267,6 +270,24 @@ namespace endofthejedi {
|
||||||
1000, 1.0);
|
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) {
|
//if (m_particles.size() == 0) {
|
||||||
// addExplosionEffect(0, glm::vec2(0.0, 0.0), glm::vec2(0.0, 0.0), false, 10000, 2.0);
|
// addExplosionEffect(0, glm::vec2(0.0, 0.0), glm::vec2(0.0, 0.0), false, 10000, 2.0);
|
||||||
|
|
|
@ -16,6 +16,6 @@ namespace game {
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Explosion *explosion;
|
const Explosion *explosion;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -366,7 +366,11 @@ namespace game {
|
||||||
//std::cout<<"[state] (before move) cycle: update events length is " << m_nextEvents.size() << std::endl;
|
//std::cout<<"[state] (before move) cycle: update events length is " << m_nextEvents.size() << std::endl;
|
||||||
|
|
||||||
// put collected events into that list.
|
// 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;
|
//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
|
// TODO: delete the items for events that are to be removed in proper
|
||||||
// way
|
// way
|
||||||
|
|
||||||
for (std::list<StateUpdateEvent*> list : m_allEvents) {
|
//for (std::list<StateUpdateEvent*> list : m_allEvents) {
|
||||||
for (StateUpdateEvent *evt : list) {
|
// for (StateUpdateEvent *evt : list) {
|
||||||
delete(evt);
|
// 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();
|
m_allEvents.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::list<StateUpdateEvent*> State::currentStateUpdateEvents() const
|
||||||
|
{
|
||||||
|
return m_allEvents;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,6 +105,8 @@ namespace game {
|
||||||
|
|
||||||
void applyAndClearAllOldStateUpdates();
|
void applyAndClearAllOldStateUpdates();
|
||||||
|
|
||||||
|
std::list<StateUpdateEvent*> currentStateUpdateEvents() const;
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************/
|
/*************************************************************************/
|
||||||
/* Rendering */
|
/* Rendering */
|
||||||
|
@ -161,6 +163,7 @@ namespace game {
|
||||||
glm::vec2 m_playingFieldSize;
|
glm::vec2 m_playingFieldSize;
|
||||||
|
|
||||||
std::list<StateUpdateEvent*> m_nextEvents;
|
std::list<StateUpdateEvent*> m_nextEvents;
|
||||||
std::vector<std::list<StateUpdateEvent*>> m_allEvents;
|
std::list<StateUpdateEvent*> m_allEvents;
|
||||||
|
//std::vector<std::list<StateUpdateEvent*>> m_allEvents;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,16 +31,24 @@ namespace game {
|
||||||
std::string description() const
|
std::string description() const
|
||||||
{
|
{
|
||||||
// TODO
|
// TODO
|
||||||
return "<event>";
|
return "StateUpdateEvent(" + lifeCycleToString(m_lifeCycle) + ", " + eventTypeToString(m_eventType) + ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string lifeCycleToString(LifeCycle lifeCycle)
|
static std::string lifeCycleToString(LifeCycle lifeCycle)
|
||||||
{
|
{
|
||||||
switch(lifeCycle) {
|
switch(lifeCycle) {
|
||||||
case StateUpdateEvent::LifeCycle::Create: return "create";
|
case LifeCycle::Create: return "create";
|
||||||
case StateUpdateEvent::LifeCycle::Modify: return "modify";
|
case LifeCycle::Modify: return "modify";
|
||||||
case StateUpdateEvent::LifeCycle::Destroy: return "destroy";
|
case LifeCycle::Destroy: return "destroy";
|
||||||
default: return "<invalid>";
|
default: return "<no name>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::string eventTypeToString(EventType eventType)
|
||||||
|
{
|
||||||
|
switch(eventType) {
|
||||||
|
case EventType::Explosion: return "explosion";
|
||||||
|
default: return "<no name>";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue