Hello,
First of all, my question is linked to this page :
http://content.gpwiki.org/index.php/SDL ... _a_cApp.3FI've been torturing my mind for the two last hours trying to understand how to deal with this non-type pointer named
CallerPtr and, in general, the
cStateManager class.
I think i understood the mechanics of it, but i can't create any code line working like i want to.
cStateManager Class Header:
Code:
#ifndef STATE_MAN
#define STATE_MAN
#include "globals.h"
#include "ePurpose.h"
struct sState
{
sState* Prev;
void (*Function)(void* CallerPtr, Purpose Purp);
sState()
{
Prev = NULL;
Function = NULL;
}
~sState()
{
delete Prev;
}
};
class cStateManager
{
public:
cStateManager();
~cStateManager();
bool Push( void (*Function)(void* CallerPtr, Purpose Purp), void* CallerPtr = NULL);
bool Pop( void* CallerPtr = NULL);
bool PopAll( void* CallerPtr = NULL);
bool Process( void* CallerPtr = NULL);
private:
sState* m_CurrentState;
};
cStateManager Class :
Code:
/*
* cStateManager.cpp
* Kore-Engine
*
* Created by Sean Chapel on 11/15/05.
* Copyright 2005 Seoushi Games. All rights reserved.
*
*/
#include "cStateManager.h"
cStateManager::cStateManager()
{
m_CurrentState = NULL;
}
cStateManager::~cStateManager()
{
PopAll(NULL);
}
bool cStateManager::Push( void (*Function)(void* CallerPtr, Purpose Purp), void* CallerPtr )
{
//only add if the function is valid
if(Function != NULL)
{
//create the new state
sState* newState = new sState();
newState->Prev = m_CurrentState;
newState->Function = Function;
//set the current state to the new one
m_CurrentState = newState;
//do init function on state
newState->Function(CallerPtr, INIT_PURPOSE);
return true; // indicate success
}
return false; // indicate failer
}
bool cStateManager::cStateManager::Pop( void* CallerPtr)
{
//only pop if there is a state
if(m_CurrentState != NULL)
{
//tell the state we all killing it
m_CurrentState->Function(CallerPtr, STOP_PURPOSE);
//create a temporary pointer to the state
sState* delState = m_CurrentState;
//make the current state the previous one
m_CurrentState = m_CurrentState->Prev;
//set the Prev to NULL so we only delete this state
delState->Prev = NULL;
delete delState;
return true; //indicate success
}
return false; //indicate failure
}
bool cStateManager::PopAll( void* CallerPtr )
{
//check to see if there are states to delete
if(m_CurrentState != NULL)
{
while( m_CurrentState != NULL )
{
Pop( CallerPtr );
}
return true; //indicate success
}
return false; //indicate failer
}
bool cStateManager::Process( void* CallerPtr)
{
//if there is a state then do it
if(m_CurrentState != NULL)
{
m_CurrentState->Function( CallerPtr, FRAME_PURPOSE );
return true; //indicate success
}
return false; //indicate success
}
So, i create a cStateManager object and then i try to Push a state (such as it has been designed to) it doesn't do anything.
In the wiki, i found "
If you haven't figured it out it is just a pointer to what called the function." about CallerPtr.
When i read that, keeping in mind that i call the cStateManager object function from the main, I can't find wath it is.
Here is my code :
Code:
#include "globals.h"
#include "SystemCore.h"
using namespace std;
void mainInitialisation(void* CallerPtr, Purpose Purp);
int main(int argc, char *argv[])
{
cApp Window(1024, 768, 0, "Electron", false);
cStateManager StateMan;
StateMan.Push(mainInitialisation(Window, INIT_PURPOSE), NULL);
StateMan.Process(NULL);
StateMan.Pop();
// Cleanup
return 0;
}
void mainInitialisation(void* CallerPtr, Purpose Purp) {
switch(Purp)
{
case STOP_PURPOSE:
cout << "Core initialisation ended with success." << endl;
break;
case INIT_PURPOSE:
cout << "Core initialisation begin." << endl;
break;
case FRAME_PURPOSE:
cout << "Core initialisation processing." << endl;
break;
default:
cout << "Strange event in the core." << endl;
break;
}
}
If anyone could help, it would be great. This is the first application of the game designing tutorial, 'getting a little bit frustrated
And 'ya, I hope my english is good enough, i don't use it often
