sending commands trough the events

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
elfuz
Posts: 14
Joined: Wed Oct 13, 2010 10:20 am

sending commands trough the events

Post by elfuz »

Hi all

as i'm progressing trough the engine's features, i'm looking for a way to send custom commands trough the irrlicht engine. a custom command could for example be: LOADSCENE "test.dat" or "MOVE_MAP_LEFT WORLDMAP". It would be best to use the SUserEvent however as i try to change the s32 data variables (UserData1 && UserData2) to stringc i run into an error

Code: Select all


Error: invalid union member -- class "irr::SEvent::SUserEvent" has a disallowed member function

where am i going wrong?

greetings
elFuz
sash
Competition winner
Posts: 35
Joined: Thu Nov 05, 2009 8:46 am
Location: Novosibirsk

Re: sending commands trough the events

Post by sash »

as i try to change the s32 data variables (UserData1 && UserData2) to stringc
You just cannot "change" s32 (integer) to stringc (let's call it array) even with a typecast.

It's common practice to submit just a pointers to your data (whatever it is - strings, structs, objects) casting them to (required by interface declaration type - s32) and once in the handler - cast it back to original type.

Moreover you dont even need to pass a pointer to user event - just make your data (string, structure) visible both to submitter and handler parts, fill it, and signal by some specific flag (enum is the best) in userdata 1 or 2 that new data is available. And once in handler, just read that structure directly.
blAaarg
Posts: 94
Joined: Tue Mar 02, 2010 9:11 pm
Location: SoCal

Post by blAaarg »

Also note that OnEvent ( const SEvent & event ) sends a const event parameter so you can't use, say,

Code: Select all

event.<member> = something
to change the event before passing it on to the next event handler.
"Computers don't make mistakes! What they do they do on purpose!!"

-Dale Gribble
elfuz
Posts: 14
Joined: Wed Oct 13, 2010 10:20 am

Post by elfuz »

blAaarg wrote:Also note that OnEvent ( const SEvent & event ) sends a const event parameter so you can't use, say,

Code: Select all

event.<member> = something
to change the event before passing it on to the next event handler.
i'm all pretty new to this (i'm originally a pascal programmer) however thanks to this thread i've found something that could be useful. However it seems like i'm having some problems with the const declarations.

what i'm running into is this:

i can printf the variables, but i cant pass them to another function...

Code: Select all

	virtual bool OnEvent(const SEvent& event)
	{
	  if (event.EventType == EET_USER_EVENT)
	  {
		  const tCommandEvent& custom = (const tCommandEvent&)event;
		  printf ("%s",custom.GetCommand());  <-- this works
//		  Context.scenemanager->ProcessCommand(custom.GetCommand(),custom.GetParameter()); <- this gives me an error
	  }
		return false;
	}
the declaration of processcommand:

Code: Select all

void SceneManager::ProcessCommand(core::stringc _COMMAND, core::stringc _PARAMETER)
{
	printf("[COMMAND]: %s PARAM: %s",_COMMAND,_PARAMETER);
}
and this is the CustomEvents.h file

Code: Select all

#ifndef CUSTOMEVENTS_H
#define CUSTOMEVENTS_H

#include "irrlicht.h"

using namespace irr;



class tCommandEvent : public SEvent
{
struct CommandData
{
	core::stringc COMMAND;
	core::stringc PARAMETER;
};
public:
  tCommandEvent() {  EventType = EET_USER_EVENT; }
  // no destructor needed, lifetime of s is longer than the instance
  // that uses it.
  void SetCommand(core::stringc _COMMAND)
  {
	  MyData.COMMAND = _COMMAND;
  }

  void SetParameter(core::stringc _PARAM)
  {
	  MyData.PARAMETER = _PARAM;
  }

  core::stringc GetCommand() const
  {
	  return MyData.COMMAND;
  }

  core::stringc GetParameter() const
  {
	  return MyData.PARAMETER;
  }
private:
	CommandData MyData;
}; 

#endif //CUSTOMEVENTS_H 
Post Reply