compile dependencies

Discuss about anything related to the Irrlicht Engine, or read announcements about any significant features or usage changes.
Post Reply
ngc92
Posts: 11
Joined: Thu Nov 19, 2009 3:56 pm

compile dependencies

Post by ngc92 »

I've noticed that the IEventReceiver.h file provides too much if you only want to derive your own class from IEventReceiver.

for IEventReceiver, the following code would be sufficient:

Code: Select all

class SEvent;

//! Interface of an object which can receive events.
/** Many of the engine's classes inherit IEventReceiver so they are able to
process events. Events usually start at a postEventFromUser function and are
passed down through a chain of event receivers until OnEvent returns true. See
irr::EEVENT_TYPE for a description of where each type of event starts, and the
path it takes through the system. */
class IEventReceiver
{
public:

	//! Destructor
	virtual ~IEventReceiver() {}

	//! Called if an event happened.
	/** Please take care that you should only return 'true' when you want to _prevent_ Irrlicht
	* from processing the event any further. So 'true' does mean that an event is completely done.
	* Therefore your return value for all unprocessed events should be 'false'.
	\return True if the event was processed.
	*/
	virtual bool OnEvent(const SEvent& event) = 0;
};
instead of the nearly 500 lines of code this are now. the enums and Event structures could be placed in another file (SEvent.h?).

this would reduce the dependencies drastically, especially because there is no need anymore for including ILogger.h, irrString.h position2d.h (which is never used in the current implementation, too) and Keycodes.h in IEventReceiver.

Is there a special reason for putting all these things together in one file?

Otherwise, i would suggest splitting because now every class derived from IEventReceiver gets a dependency to irrString.h for example, even if it is never needed.
[/code]

edit corrected forward decl
Last edited by ngc92 on Sat May 29, 2010 10:39 pm, edited 1 time in total.
DtD
Posts: 264
Joined: Mon Aug 11, 2008 7:05 am
Location: Kansas
Contact:

Post by DtD »

I wouldn't get too worked up over internal dependencies. Besides, if it relies on SEvent then it will rely on everything it relies on, it really just makes more files than necessary. IMO it doesn't make sense for the SEvent struct to be in a seperate file unless multiple things use it, which they do not.
ngc92
Posts: 11
Joined: Thu Nov 19, 2009 3:56 pm

Post by ngc92 »

Yes, it relies on SEvent, but SEvent is only needed as a const ref function parameter, thus, a forward declaration would be sufficient.

Of cause, if you want to pass an event to en event manager, you need to include also SEvent, but for all other purposes the users of the Event Receiver don't need to know anything about Events.

Example:
An EventReceiver waiting for Keyboard Input for Controlling a game character. The receiver itself waits for the event and sets internal flags saving the keys currently pressed. The Game Logic asks the EventReceiver whether the keys are pressed and acts accordingly.
There is no need for game logic to know the SEvent struct because Events are processed internally in the EventReveicer, so there is no dependency.

Nevertheless, with the current design, the game logic gets to know all event structs and also the stuff included for them, i.e. irrString and ILogger.
DtD
Posts: 264
Joined: Mon Aug 11, 2008 7:05 am
Location: Kansas
Contact:

Post by DtD »

Personally I don't see how this is a bad thing. Including irrlicht.h will include everything else anyway. Splitting things up too much will just make it unorganized.

Also, I'd be more worried about external dependencies than interdependencies. There really is no reason for your game logic to not see the SEvent structure. Also, 500 lines is nothing.
CuteAlien
Admin
Posts: 9733
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Removing position2d.h there should certainly be fine (must be added to CSceneNodeAnimatorCameraFPS.h then). Just can't do it right now as I'm working on another patch, but I've put it on my todo.

About splitting - it might actually be useful in this case. It's rather common to include classes derived from the eventreceiver without caring about SEevent, so I can see your point. And I suppose the reason it wasn't done that way in the past was that originally OnEvent didn't work with references, so back then it didn't matter.

edit: But I guess you want a forward declaration to SEvent instead of IEventReceiver in that header then ;-)
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
ngc92
Posts: 11
Joined: Thu Nov 19, 2009 3:56 pm

Post by ngc92 »

oops, I see, in the code i posted the forward declaration of IEventReceiver should of cause be SEvent :oops:

DtD:
including irrlicht.h is what i usually try to avoid...
there is no reason for game logic to see SEvent, so SEvent and all dependencies are not needed here.
you are right, 500 LOC are not many, but this is only IEventReceiver.h.
ILogger.h: ~100 LOC
irrString.h ~1100 LOC
keycodes.h ~150 LOC
these files also have dependencies, so this ends up including also irrAllocator.h, irrMath.h, irrTypes.h, IReferenceCounted.h, IrrCompileConfig.h...
some of them (like IReferenceCounted.h) are likely to be used by some other part of the file, so this would not be a really new dependency, but at lest sth. like irrString could be new, so that the total number auf added lines of code are maybe not 500 but 2000.
DtD
Posts: 264
Joined: Mon Aug 11, 2008 7:05 am
Location: Kansas
Contact:

Post by DtD »

What is wrong with including irrlicht.h? It won't make your binary larger or anything, the worst it might do is slow down the compile a bit.
CuteAlien
Admin
Posts: 9733
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

I did the simple change now (removing position2d.h) in the 1.7 branch. Probably will add SEvent.h also (unless someone complains), but I think I'll rather put that into 1.8.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply