SSSF --> SnowStorm State Framework

Anything and everything that's related to OGRE or the wider graphics field that doesn't fit into the other forums.
User avatar
Robomaniac
Hobgoblin
Posts: 508
Joined: Tue Feb 03, 2004 6:39 am

Post by Robomaniac »

Sorry for the delay, had to get my comp back set up.

Here is the main.cpp file that i'm using

Code: Select all

#include <iostream>
#include <string>

#include "Ogre.h"

#include "Logging\Logger.h"
#include "SSSF\Engine\Game_Engine.h"

#include "Gamecore\Scripting\Scripting_Manager.h"


#include "Gamecore\Scripting\Bindings.h"

#ifdef NDEBUG
MiniDumper miniDumper;
#endif

int main()
{

	Core::Scripting_Manager* mgr = new Core::Scripting_Manager();
	
	SSSF::GameEngine* eng = new SSSF::GameEngine();
	if (!eng->Initialize())
		return 1;

	Core::Bind(mgr->GetVM());

	//Kick off the main script, this does everything scripting wise, sets up the game, etc.
	mgr->DoFile("../Data/Scripts/main.script");

	while (eng->Update())
	{
		
	}

	delete mgr;

	eng->Destroy();

	delete eng;
	return 0;
}
Basically, to init sssf, you need to create the engine, init it, run the loop, destroy it, and then delete it.

Hope that works
phear hingo

My Webpage

Chev
Gnoblar
Posts: 13
Joined: Fri Mar 05, 2004 6:11 pm

Post by Chev »

thanks Robo :).
In case you havent found this, I fixed a memory leak. I just added the line for destroying the input reader.

Code: Select all

	void GameEngine::Destroy()
	{
		if (m_Root)
			m_Root->shutdown();
		Ogre::PlatformManager::getSingleton().destroyInputReader(m_InputDevice);
	}
There is also a memory leak if you do not Remove all states before before calling Engine::Destroy.

User avatar
Robomaniac
Hobgoblin
Posts: 508
Joined: Tue Feb 03, 2004 6:39 am

Post by Robomaniac »

Thanks :) I knew there would be some, i think i fixed them all before i released it :)

Good find, i'll add that in.

I'll also set up a cvs for SSSF over the weekend :)
phear hingo

My Webpage

chooikw
Kobold
Posts: 32
Joined: Mon Jun 28, 2004 3:58 pm
Contact:

Post by chooikw »

Chev wrote:thanks Robo :).
In case you havent found this, I fixed a memory leak. I just added the line for destroying the input reader.

Code: Select all

	void GameEngine::Destroy()
	{
		if (m_Root)
			m_Root->shutdown();
		Ogre::PlatformManager::getSingleton().destroyInputReader(m_InputDevice);
	}
There is also a memory leak if you do not Remove all states before before calling Engine::Destroy.
This have to be changed to

Code: Select all

void GameEngine::Destroy()
	{
Ogre::PlatformManager::getSingleton().destroyInputReader(m_InputDevice);
		if (m_Root)
			m_Root->shutdown();
		
	}
or you will get a huge memory leaks file generated by ogre.(Mine is about 6mb!)
Game programming is fun!

User avatar
Robomaniac
Hobgoblin
Posts: 508
Joined: Tue Feb 03, 2004 6:39 am

Post by Robomaniac »

whoa, will change that, thanks chookiw for pointing that out to me :)
phear hingo

My Webpage

chooikw
Kobold
Posts: 32
Joined: Mon Jun 28, 2004 3:58 pm
Contact:

Post by chooikw »

Hey robo,how do you change states?
I want to do state A -> state B -> state A which is title screen,new game then go back to title screen.

my way:
when player clicked new game button:
create new game state -> call engine change 2nd state -> destroy current state

then go to 2nd state
after the game ends,call engine change to 1st state -> destroy current state


It runs smoothly from state 1->2 but will get error when change back from 2->1.


Thanks.
Game programming is fun!

User avatar
Robomaniac
Hobgoblin
Posts: 508
Joined: Tue Feb 03, 2004 6:39 am

Post by Robomaniac »

There swhould be no need to create a new state each time you want to go from one to the other. At the start of the game, create the states by calling the constructor. Then add the state to the engine w/ m_Engine->AddState(...); then just change to that state. The engine will automatically call the Create funciton, which is where you should handle all of your creation, etc.

When you want to change out've it, just change to the different state and then change back, it should work.
phear hingo

My Webpage

chooikw
Kobold
Posts: 32
Joined: Mon Jun 28, 2004 3:58 pm
Contact:

Post by chooikw »

I've followed your instructions but the main menu won't go after i changed the state. Isn't it a waste of memory if create all the states and leave them there? I'm using ogretok and the simulation will eat alot of memory :roll:

btw,i've replaced the code to hide the menu after the player clicked new game.I tried to call the engine change state function again but it won't call the first stage's create function. I know that by adding a messagebox pop up in the create function and where the changestate is called.

there is an error when quitting the game too.Both states would destory the scene manager and in my case,the titlescreen is added first so its destructor will be called first. The screen objects will be destroyed during the first scene manager destructor is called and then in the second state,the physics simulation will try to destroy the objects too and here comes the error. :(
Game programming is fun!

chooikw
Kobold
Posts: 32
Joined: Mon Jun 28, 2004 3:58 pm
Contact:

Post by chooikw »

Problem fixed by correcting the error in Game_State_Handler::ChangeState function.
Game programming is fun!

User avatar
Robomaniac
Hobgoblin
Posts: 508
Joined: Tue Feb 03, 2004 6:39 am

Post by Robomaniac »

sweet, please tell me what u fixed so i can change it on my copy and the cvs copy when i get the chance to this weekend
phear hingo

My Webpage

chooikw
Kobold
Posts: 32
Joined: Mon Jun 28, 2004 3:58 pm
Contact:

Post by chooikw »

They are at Game_State_Handler.cpp

Change 1:

Code: Select all

void Game_State_Handler::RemoveState(GameState* state)
	{
		if (state)
		{
			std::vector<GameState*>::iterator i;
			for (i=m_States.begin();i != m_States.end();i++)
			{
				if ((*i) == state)
				{
					m_States.erase(i);
					m_StatesMap.erase(state->GetName());
					delete state;
					break;
				}
			}
		}
	}
Change 2:

Code: Select all

bool Game_State_Handler::ChangeState(std::string name)
	{
		std::map<std::string, GameState*>::iterator i ;

		for (i=m_StatesMap.begin();i!=m_StatesMap.end();++i)
		{
			if (i->first == name)
			{
				m_CurrentState = i->second;
				m_CurrentState->Create();
				break;
			}
		}

		return true;
	}
I remember you mentioned this before :p

Btw,always delete the child game state before calling engine->Destroy(); Otherwise you will get error message when calling destructor in child game state :lol:
Game programming is fun!

User avatar
Robomaniac
Hobgoblin
Posts: 508
Joined: Tue Feb 03, 2004 6:39 am

Post by Robomaniac »

yes, i actually had that destructor error a few days ago :)

Reordered some things, and it seems to be wokring fine now!,

I'll apply those changes in a few minutes ;)
phear hingo

My Webpage

Xothin
Gnoblar
Posts: 4
Joined: Fri Oct 08, 2004 5:13 pm
Location: Portland, OR

Post by Xothin »

Chooik and I have been looking at your code, and it looks as though you are taking unbuffered keyboard and mouse input.

Do you have plans to change this? In small scale, it's not a big deal, but when you start getting deeper in and get a lot going on, having unbuffered input can bog ya down.

User avatar
Robomaniac
Hobgoblin
Posts: 508
Joined: Tue Feb 03, 2004 6:39 am

Post by Robomaniac »

I use unbuffered input that's true

From what i've heard, buffered input is good for gui's, but bad for ingame, so i was going w/ unbuffered.

I'll check it out more and change it before i reupload
phear hingo

My Webpage

Xothin
Gnoblar
Posts: 4
Joined: Fri Oct 08, 2004 5:13 pm
Location: Portland, OR

Another thing I noticed

Post by Xothin »

If a person doesn't have a .cfg file in the directory, the app created will crash.

in your GameEngine::Initialize() function change

Code: Select all

if(!m_Root->restoreConfig())
     return false;
to

Code: Select all


try
{
     m_Root->restoreConfig()
}
catch
{
     if(!m_Root->showConfigDialog())
     {
          return false;
     }
}
m_RenderWindow = m_Root->initialise(true, "Window Name");
m_RenderSystem = m_Root->getRenderSystem();

// rest of your code here..
Or something to this nature. ^.^

All in all, good work on the base, I look forward to seeing what else you have hidden up your sleeve. ^.^

Xothin

User avatar
Robomaniac
Hobgoblin
Posts: 508
Joined: Tue Feb 03, 2004 6:39 am

Post by Robomaniac »

hehe, thanks, i'll cahnge that too;

I need to go through this weekend and add some more robust error checking and user friendliness.
phear hingo

My Webpage

chooikw
Kobold
Posts: 32
Joined: Mon Jun 28, 2004 3:58 pm
Contact:

Post by chooikw »

Robomaniac wrote: From what i've heard, buffered input is good for gui's, but bad for ingame,
I agree.With buffered input,the key is "repeated" very fast. I have a test program that changes camera view from 1st person to 3rd person.If use buffred input,it will change the view n times when i hit the key down :D
Game programming is fun!

Xothin
Gnoblar
Posts: 4
Joined: Fri Oct 08, 2004 5:13 pm
Location: Portland, OR

Post by Xothin »

Teach me to code when I don't have a compiler in front of me...

A correction to my code, for some reason the try catch just didn't want to go...

Code: Select all

if(!m_Root->restoreConfig())
    if(!m_Root->showConfigDialog())
	return false;

User avatar
IainC
Gnoblar
Posts: 3
Joined: Sun Jan 11, 2004 2:51 am
Location: Southampton, England
Contact:

Post by IainC »

Hi Robomaniac, was about to have a play with this but can't see the updated download with the lua bindings etc anywhere...

Is it up yet? No pressure, just checking I'm not blind :)
www.coldcity.com
coding, life

User avatar
Robomaniac
Hobgoblin
Posts: 508
Joined: Tue Feb 03, 2004 6:39 am

Post by Robomaniac »

I have the version here sitting on this computer all zipped up and ready to upload. However, my school blocks uploading through ftp, so i'm screwed until thursday afternoon-friday (woot! xmas break!). Expect a long overdue update to all the things i'm working on. (CF, SSSF, and the N00b Tuts!)
phear hingo

My Webpage

Vectrex
Ogre Magi
Posts: 1266
Joined: Tue Aug 12, 2003 1:53 am
Location: Melbourne, Australia
x 1
Contact:

Post by Vectrex »

sweet, appreciate the work Robo (especially the noob tutes ;) )
hmm I'm wanting an official wiki more and more now because the info in the forums is either out of date and/or 30 pages long :)

eeheeehe
Gnoblar
Posts: 22
Joined: Sun Mar 20, 2005 9:46 pm

Post by eeheeehe »

Is there a way to add mouse listeners to Statemanager 0.4 - 0.5? I can't get SSSC to work, and I would prefer to use the Statemanager 0.4-0.5, b/c that is what I already have working.

User avatar
Robomaniac
Hobgoblin
Posts: 508
Joined: Tue Feb 03, 2004 6:39 am

Post by Robomaniac »

I'm in the middle of coding a new version of SSSF after my game code got flushed down the drain (*tear*). I'll post it if its finished on sunday, someone remind me to do so (e-mail or irc :))
phear hingo

My Webpage

eeheeehe
Gnoblar
Posts: 22
Joined: Sun Mar 20, 2005 9:46 pm

Post by eeheeehe »

*poke* Reminder

User avatar
Robomaniac
Hobgoblin
Posts: 508
Joined: Tue Feb 03, 2004 6:39 am

Post by Robomaniac »

http://www.ogre3d.org/phpBB2/viewtopic. ... 6&start=25

just use the "CF/Centaur Force/src/GSM folder
phear hingo

My Webpage

Post Reply