(C++) Simple to use Event Receiver class for Irrlicht 1.3

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Re: this does'nt work

Post by rogerborg »

3DModelerMan wrote: And here's the error that I get

Code: Select all

 error: base operand of `->' has non-pointer type `MastEventReceiver'
Thanks :D .
And here's the top Google hit for that error, which took me all of 30 seconds to find.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Dorth
Posts: 931
Joined: Sat May 26, 2007 11:03 pm

Post by Dorth »

And this is code snippet section, not Beginner help nor Advanced help
3DModelerMan
Posts: 1691
Joined: Sun May 18, 2008 9:42 pm

oh

Post by 3DModelerMan »

Oh sorry, and thanks for the help.
I thought it was fine to post questions about the projects.
That would be illogical captain...

My first full game:
http://www.kongregate.com/games/3DModel ... tor#tipjar
Dorth
Posts: 931
Joined: Sat May 26, 2007 11:03 pm

Post by Dorth »

Questions, maybe.
Huge block of code, one line error and "Can someone help me?" no.
3DModelerMan
Posts: 1691
Joined: Sun May 18, 2008 9:42 pm

.h file for mast event receiver

Post by 3DModelerMan »

Does this need many modifications to be put in a .h file instead of a .cpp?.
That would be illogical captain...

My first full game:
http://www.kongregate.com/games/3DModel ... tor#tipjar
timetokill
Posts: 74
Joined: Tue Jul 22, 2008 4:28 am
Location: Los Angeles

Post by timetokill »

Hi,

I just started using this and everything seemed to be going fine, until I let the program run for a minute or two.

I won't press any keys, I'll just let it run, and Visual Studio tells me that I've hit a break point here:

Code: Select all

	//! Direct const access operator
	const T& operator [](u32 index) const
	{
		_IRR_DEBUG_BREAK_IF(index>=used) // access violation

		return data[index];
	}

For reference, the test I'm doing with the class is this:

Code: Select all

		if(eventReceiver.keyDown(KEY_RIGHT))
		{
			a++;
		}
		else if(eventReceiver.keyDown(KEY_LEFT))
		{
			a--;
		}
		else if(eventReceiver.keyPressed(KEY_DOWN))
		{
			a=0;
		}

I'm really not sure why this is happening, or if it's a problem with the class or my code, the compiler, etc. Hopefully somebody can help.



EDIT: After some other tests, I don't think it's the class that is causing the issue. It seems to happen even in the Hello World app... I'll check around the forums for help, but if anybody can point me in the right direction I'd really appreciate it.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

It looks like you use 'a' for access to some limited array. This will crash once you pressed a often enough. Other causes are definitely not related to the standard examples' code. Just post your code in the beginner's forum and there will be someone looking at it.
Angus5
Posts: 2
Joined: Tue Dec 18, 2007 2:37 am

Post by Angus5 »

I don't know what I'm doing. I'm trying to figure out how this works, I do this but it crashes:

Code: Select all

MastEventReceiver* input;

...
...
...

if(input->keyPressed(KEY_SPACE))
    do stuff;
Obviously I'm not doing it right.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Hmm, might be the right time to read about the C++ basics in a book or tutorial elsewhere...
You're using an uninitialized pointer, there's no receiver object created so far. Hence, any access to 'input' will lead to undesired results!
kingdutch
Posts: 76
Joined: Tue Sep 02, 2008 7:01 am

WooT!

Post by kingdutch »

Works like a charm after I changed

Code: Select all

SEvent event
into

Code: Select all

const SEvent& event
baldong
Posts: 1
Joined: Wed Oct 29, 2008 7:56 am

Post by baldong »

kingdutch is right, without it, you will receive a error about can't initialize a abstract class.
Arcoroc
Posts: 51
Joined: Wed Oct 01, 2008 11:40 pm
Location: Canada

Post by Arcoroc »

Just to clarify, the modification is on line 64

Code: Select all

  virtual bool OnEvent(SEvent event) 
into

Code: Select all

 virtual bool OnEvent(const SEvent& event) 
to make it work with irrlicht 1.4.2.

Thanks for sharing.
Ulf
Posts: 281
Joined: Mon Jun 15, 2009 8:53 am
Location: Australia

Post by Ulf »

I've just started using Irrlicht to make a game engine. I've been creating my event handling procedures.

Is this MastEventReceiver designed for a game engine?

I am a newbie, but still I feel that there is so much wrong with this MastEventReceiver. But I'm confused why noone has questioned it.
My biggest problem is that I don't understand what it is trying to achieve.
It seems overly complex (though not complete) and redundant in some ways.

Please enlighten me if I overlook or misunderstand something.

Firstly, why have a Down() and an Up() function? Why not just have:

boolean KeyDown(EKEY_CODE keyCode) or
MouseButtonDown(int mouseButton) ??

With the MouseButtonDown, you could make one function (as above) and pass the mouse button parameter to the function.

Also, what is the Pressed() and Released() for?.. and then you update the actual values in the function startEventProcess().
Why would you want to start the event process at the end of the loop and stop it at the start?

For a game engine, I'd always take events since the user can set their own delays for their game input. The game loop (device->run()) will be calling game specific event handlers HandleKeys(), MouseMove(), MouseButton() and HandleJoystick() etc.
I understand turning off event handling just prior to the actual game specific game cycle, then turn it back on after. It may be required to keep the engine in a whole state so to speak, since the actual event handling in the app(window) is always happening and hence it is updating keystates etc. Even that may not be necessary? (anyone's opinion?)
e.g.
while (device->run())
{
HandleKeys();
evtHandler->Stop();
GameCycle();
evtHandler->Start();
}

Anyway, what is it for? Nowhere can I find explanations for the purpose of Pressed and Released.
Why would you only want to set the state to PRESSED on the first press? Instead of putting it straight to DOWN?
I can't see the benefit.
LOOK BELOW:

//Left Mouse Button Pressed
if (event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN)
{
if (mouseButtonState[0] == UP || mouseButtonState[0] == RELEASED)
{
mouseButtonState[0] = PRESSED;
}
else
{
mouseButtonState[0] = DOWN;
}
}

Please explain?

I'll post my event handler for a game engine when I complete it.
I'd appreciate any constructive comments about my comments or about Mastiff's event handler.
wITTus
Posts: 167
Joined: Tue Jun 24, 2008 7:41 pm
Location: Germany

Post by wITTus »

I agree.

The MastEventReceiver is a very ugly piece of C++ code.
If you don't like it, don't use it. :wink:
Generated Documentation for BlindSide's irrNetLite.
"When I heard birds chirping, I knew I didn't have much time left before my mind would go." - clinko
Ulf
Posts: 281
Joined: Mon Jun 15, 2009 8:53 am
Location: Australia

Birds are chirping

Post by Ulf »

Ok, thanks.
I never was going to use it, but I wanted to know if my idea was right, or if there really was a practical reason for all the confusing PRESSED and RELEASED, and so on..

Noone even asked what it's for. Anyway... :roll:
Post Reply