Commit 4301bfdf authored by Gerhard Stein's avatar Gerhard Stein

Adapted new Event System to the Galaxy Engine

parent 871bca72
......@@ -20,9 +20,10 @@
#include <map>
#include "CTileProperties.h"
#include "CPhysicsSettings.h"
#include "../fileio/TypeDefinitions.h"
#include "fileio/TypeDefinitions.h"
#include "engine/CEventContainer.h"
#include "../CSingleton.h"
#include "CSingleton.h"
#define g_pBehaviorEngine CBehaviorEngine::Get()
typedef struct{
......@@ -54,6 +55,8 @@ public:
virtual ~CBehaviorEngine();
CEventContainer m_EventList;
private:
std::vector<CTileProperties> m_TileProperties[2];
CPhysicsSettings m_PhysicsSettings;
......
......@@ -28,6 +28,14 @@ size(0)
}
}
CEvent::CEvent(const CEvent& Event)
{
this->size = Event.size;
this->data = malloc(size);
this->event_type = Event.event_type;
memcpy(this->data, Event.data, size);
}
/**
* This function just looks if it is the same event we are looking for and removes it, because
* in case it was detected
......
......@@ -27,6 +27,7 @@ enum wm_event{
class CEvent {
public:
CEvent(const wm_event event_type, const void *data, const size_t size);
CEvent(const CEvent& Event);
bool occurred(wm_event event_type);
......
......@@ -7,6 +7,7 @@
#include "CEventContainer.h"
#include <string.h>
#include "CLogFile.h"
CEventContainer::CEventContainer() {
// TODO Auto-generated constructor stub
......@@ -25,7 +26,7 @@ void CEventContainer::add(const wm_event event_type)
void CEventContainer::add(const wm_event event_type, const void *data, const size_t size)
{
CEvent Event(event_type, data, size);
m_EventList.push_front(Event);
m_EventList.push_back(Event);
}
/**
......@@ -44,8 +45,14 @@ bool CEventContainer::occurredEvent( const wm_event event_type )
bool CEventContainer::ReadData(void *data, const size_t size)
{
CEvent &Event = m_EventList.front();
if(size != Event.Size() || Event.getData() == NULL)
{
std::string text = "Warning! The read type differs form the requested type! Report that issue to the CG-Team!!!";
g_pLogFile->textOut(text);
throw;
return false;
}
memcpy(data, Event.getData(), size);
return true;
......@@ -60,3 +67,4 @@ void CEventContainer::pop_Event()
CEventContainer::~CEventContainer() {
// TODO Auto-generated destructor stub
}
......@@ -8,10 +8,10 @@
#include "CPlayGameGalaxy.h"
#include "CMapLoaderGalaxy.h"
#include "../../graphics/CGfxEngine.h"
#include "../../sdl/CVideoDriver.h"
#include "../../sdl/CInput.h"
#include "../../StringUtils.h"
#include "graphics/CGfxEngine.h"
#include "sdl/CVideoDriver.h"
#include "sdl/CInput.h"
#include "StringUtils.h"
namespace galaxy
{
......@@ -83,12 +83,6 @@ void CPlayGameGalaxy::process()
{
Uint8 new_level;
m_WorldMap.process();
// TODO: Let's see, if Keen has selected a new level
if(m_WorldMap.PollNewLevel(new_level))
{
}
}
// process World Map if active. At the start it's enabled
......@@ -101,6 +95,24 @@ void CPlayGameGalaxy::process()
processRendering();
}
// In this part we will poll all the relevant Events that are important for the
// Galaxy Main Engine itself. For example, load map, setup world map, show Highscore
// are some of those events.
CEventContainer& EventContainer = g_pBehaviorEngine->m_EventList;
if( EventContainer.occurredEvent( ENTER_LEVEL ) )
{
Uint16 Data;
EventContainer.ReadData(Data);
//m_WorldMap.setActive(false);
printf("Start a new level!\n");
//m_WorldMap.finishLevel(object);
// Start a new level!
EventContainer.pop_Event();
EventContainer.add(EXIT_LEVEL, Data);
}
}
void CPlayGameGalaxy::processInput()
......
......@@ -38,8 +38,6 @@ void CWorldMap::init()
void CWorldMap::process()
{
processInput();
// Animate the tiles of the map
m_Map.animateAllTiles();
......@@ -57,56 +55,9 @@ void CWorldMap::process()
{
(*obj)->draw();
}
}
/**
* \brief This is called every game cycle. Here we check if the Player has chosen a new level
* \param new_level the new level that has been detected in case of
* \return return true, if player tries opening a level or false if not
*/
bool CWorldMap::PollNewLevel(Uint8 &new_level)
{
if(m_newLevel)
{
}
}
/*
* makes the player finish the level
*/
void CWorldMap::finishLevel(Uint16 object)
{
// if a door or other blocker was found remove it
int x, y;
Uint16 door = (object - 0xC000) + 0xD000;
while(mp_Map->findTile(door, &x, &y, 2))
{
// Open blocks in case there are
mp_Map->setTile( x, y, 0, true, 1);
mp_Map->setTile( x, y, 0, true, 2);
mp_Map->redrawAt( x, y);
}
Uint16 flag_dest = (object - 0xC000) + 0xF000;
if(mp_Map->findTile(flag_dest, &x, &y, 2))
{
// spawn the flag
VectorD2<Uint32> src(this->x, this->y);
VectorD2<Uint32> dst((x<<CSF), (y<<CSF));
CFlag *pFlag = new CFlag(mp_Map, src, dst);
m_ObjectPtrs.push_back(pFlag);
// Mark the tileinfo on the map as marked!!
mp_Map->setTile( x, y, 0, true, 2);
}
}
void CWorldMap::processInput()
{
}
CWorldMap::~CWorldMap() {
while(!m_ObjectPtr.empty())
......
......@@ -24,7 +24,6 @@ public:
void init();
void process();
void processInput();
virtual ~CWorldMap();
......
......@@ -46,6 +46,16 @@ void CPlayerWM::process()
else m_animation_ticker++;
processWalking();
// Events for the Player are processed here.
CEventContainer& EventContainer = g_pBehaviorEngine->m_EventList;
if( EventContainer.occurredEvent( EXIT_LEVEL ) )
{
Uint16 Data;
EventContainer.ReadData(Data);
finishLevel(Data);
EventContainer.pop_Event();
}
}
/*
......@@ -117,7 +127,6 @@ void CPlayerWM::processWalking()
// This will trigger between swim and walkmode
checkforSwimming();
}
/**
......@@ -125,9 +134,39 @@ void CPlayerWM::processWalking()
*/
void CPlayerWM::startLevel(Uint16 object)
{
g_pBehaviorEngine->m_EventList.add(ENTER_LEVEL, object);
}
/*
* makes the player finish the level
*/
void CPlayerWM::finishLevel(Uint16 object)
{
// if a door or other blocker was found remove it
int x, y;
Uint16 door = (object - 0xC000) + 0xD000;
while(mp_Map->findTile(door, &x, &y, 2))
{
// Open blocks in case there are
mp_Map->setTile( x, y, 0, true, 1);
mp_Map->setTile( x, y, 0, true, 2);
mp_Map->redrawAt( x, y);
}
Uint16 flag_dest = (object - 0xC000) + 0xF000;
if(mp_Map->findTile(flag_dest, &x, &y, 2))
{
// spawn the flag
VectorD2<Uint32> src(this->x, this->y);
VectorD2<Uint32> dst((x<<CSF), (y<<CSF));
CFlag *pFlag = new CFlag(mp_Map, src, dst);
m_ObjectPtrs.push_back(pFlag);
// Mark the tileinfo on the map as marked!!
mp_Map->setTile( x, y, 0, true, 2);
}
}
/**
* This is the function will switch between swim and walk mode
* Those are the tileproperties to check for
......
......@@ -8,7 +8,8 @@
#ifndef CPLAYERWM_H_
#define CPLAYERWM_H_
#include "../../../common/CObject.h"
#include "common/CObject.h"
#include "engine/CEvent.h"
namespace galaxy {
......@@ -20,6 +21,7 @@ public:
void processWalking();
void startLevel(Uint16 object);
void finishLevel(Uint16 object);
void checkforSwimming();
void performWalkingAnimation(bool walking);
......@@ -34,6 +36,8 @@ private:
Uint8 m_animation_time;
Uint8 m_animation_ticker;
std::vector<CObject*>& m_ObjectPtrs;
};
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment