This is an improved Vector2 class I'm working on with suggestions from Leander Hasting, though I haven't touched upon all of them yet.  Beyond that, some of the critiques seem subjective to a point, and other professionals he pointed me to, make the same argument; and that is the argument of the use 0f non-member functions.  With intellisense working, I find using member functions to be the easiest way of doing things, as I think it is easier for other people to work with; as someone who's trying to write an engine, I understand the importance of including extra functions in a separate header file, though I think that can get messy.  So, with what is proposed you could do VectorUtil::len(vector), though having the VectorUtilthere is ugly, though without it there, how do you know that function even exists or where it's coming from?  So for starters, it's more useful to split the vector up like this, because everything doesn't need access to these functions, and it helps build times.  Though, in the end, when this engine is done, all of the information is most likely going to be included anyway;  lets say I want to add scripting support with my own version of intellisense, I want to make it as easy as possible for someone not used to my engine to be able to interactively see what they can do with a Vector by simply using "vector." and everything they have available to them pop up.  So, because the functions are accessing public members, they have no need to be member functions; so while some may claim using member functions breaks encapsulation, I think it makes it easier to open up a class to the user and what it can do.  Though it's interesting that intellisense in Visual Studio also shows private and protected functions you don't have access to...

Anyway, what I would like to do with my code is make it as easy as possible for anyone to use, I'm not worried that much about technicalities and hardcore programmers squirming over things I don't care about.  Though that makes me wonder, should I care about that, and perhaps just take it with a grain of salt?

Anyway, here's my Vector2 class in it's improved glory.

Vector2.h:

/*  __      __   ___     _____    ____
 *  \ \    / /  / _ \   |  __ \  |    |
 *   \ \/\/ /  / / \ \  | | / /  |  __|
 *    \_/\_/  /_/   \_\ |_| \_\  |_|
 *      Take it to the next Level
 *
 *  Copyright (c) 2009 Brian Ernst.
 */
#ifndef w_Vector2
#define w_Vector2

#ifndef FALSE
#define FALSE 0
#endif

#ifndef TRUE
#define TRUE 1
#endif

namespace _Warp
{
	typedef float Scalar;
	typedef int Bool;

	class Vector2
	{
	public:
		Scalar X;
		Scalar Y;

		Vector2();
		Vector2(Scalar x, Scalar y);

		Vector2& operator+=(const Vector2& pVector);
		Vector2& operator-=(const Vector2& pVector);
		Vector2& operator*=(Scalar num);
		Vector2& operator/=(Scalar num);

		Bool operator!=(const Vector2& vect) const;
		Bool operator==(const Vector2&; vect) const;

		friend Vector2 operator-(Vector2& vect);
		friend Vector2 operator+(const Vector2& vect1,const Vector2& vect2);
		friend Vector2 operator-(const Vector2& vect1,const Vector2& vect2);
		friend Vector2 operator*(const Vector2& vect1, Scalar value);
		friend Vector2 operator/(const Vector2& vect1, Scalar value);
		friend Vector2 operator*(const Vector2& vect1,const Vector2& vect2);
		friend Vector2 operator/(const Vector2& vect1,const Vector2& vect2);
	};

	inline Vector2::Vector2()
	{
	}

	inline Vector2::Vector2(Scalar x,Scalar y)
		: X( x )
		, Y( y )
	{
	}

	inline Bool Vector2::operator!=(const Vector2& vector) const
	{
		return X != vector.X || Y != vector.Y;
	}

	inline Bool Vector2::operator==(const Vector2& vect) const
	{
		return (*this != vect) == FALSE;
	}

	inline Vector2& Vector2::operator+=(const Vector2& pVector)
	{
		X += pVector.X;
		Y += pVector.Y;
		return *this;
	}

	inline Vector2& Vector2::operator-=(const Vector2& pVector)
	{
		X -= pVector.X;
		Y -= pVector.Y;
		return *this;
	}

	inline Vector2& Vector2::operator*=(Scalar num)
	{
		X *= num;
		Y *= num;
		return *this;
	}

	inline Vector2& Vector2::operator/=(Scalar num)
	{
		X /= num;
		Y /= num;
		return *this;
	}

	inline Vector2 operator+(const Vector2& vect1,const Vector2& vect2)
	{
		return Vector2(vect1.X + vect2.X,vect1.Y + vect2.Y);
	}

	inline Vector2 operator-(const Vector2& vect1,const Vector2& vect2)
	{
		return Vector2(vect1.X - vect2.X,vect1.Y - vect2.Y);
	}

	inline Vector2 operator-(Vector2& vect)
	{
		return vect * -1;
	}

	inline Vector2 operator*(const Vector2& vect1, Scalar value)
	{
		return Vector2(vect1.X * value,vect1.Y * value);
	}

	inline Vector2 operator/(const Vector2& vect1, Scalar value)
	{
		return Vector2(vect1.X / value,vect1.Y / value);
	}

	inline Vector2 operator*(const Vector2& vect1,const Vector2& vect2)
	{
		return Vector2(vect1.X * vect2.X,vect1.Y * vect2.Y);
	}

	inline Vector2 operator/(const Vector2& vect1,const Vector2& vect2)
	{
		return Vector2(vect1.X / vect2.X,vect1.Y / vect2.Y);
	}
}

#endif

VectorUtil.h

/*  __      __   ___     _____    ____
 *  \ \    / /  / _ \   |  __ \  |    |
 *   \ \/\/ /  / / \ \  | | / /  |  __|
 *    \_/\_/  /_/   \_\ |_| \_\  |_|
 *      Take it to the next Level
 *
 *  Copyright (c) 2009 Brian Ernst.
 */

#ifndef w_VectorUtil
#define w_VectorUtil

#include <cmath>

using std::sin;
using std::cos;
using std::sqrt;
using std::atan2;

#include "Vector2.h"

namespace _Warp
{
	class Vector2Util
	{
		static Scalar 	len(const Vector2& vect);
		static Scalar 	len2(const Vector2& vect);

		static Vector2& invert(Vector2& vect);
		static Vector2& normalize(Vector2& vect);
		static Vector2& clamp(Vector2& vect, Scalar value);
		static Vector2& setLength(Vector2& vect, Scalar value);

		static Vector2	polar		(Scalar x, Scalar y);
		static Vector2 	cartesian	(Scalar radius,	Scalar angle);
		static Scalar 	dot			(const Vector2& pVec1, const Vector2& pVec2);
		static Vector2 	rotate		(const Vector2& pVec, Scalar angle);
	};

	inline Scalar len(const Vector2& vect)
	{
		return sqrt(vect.X * vect.X + vect.Y * vect.Y);
	}

	inline Scalar len2(const Vector2& vect)
	{
		return vect.X * vect.X + vect.Y * vect.Y;
	}

	inline Vector2& invert(Vector2& vect)
	{
		return vect *= -1;
	}

	inline Vector2& normalize(Vector2& vect)
	{
		if(vect.X == 0 &amp;&amp; vect.Y == 0)
		{
			return vect;
		}

		Scalar length = len(vect);

		vect.X /= length;
		vect.Y /= length;
		return vect;
	}

	inline Vector2& clamp(Vector2& vect,Scalar value)
	{
		Scalar length = len2(vect);
		if(length &lt;= value * value)
		{
			return vect;
		}

		length = sqrt(length);

		vect.X *= value / length;
		vect.Y *= value / length;

		return vect;
	}

	inline Vector2& setLength(Vector2& vect, Scalar value)
	{
		if(vect.X == 0 &amp;&amp; vect.Y == 0)
		{
			return vect;
		}

		Scalar length = len(vect);

		vect.X *= value / length;
		vect.Y *= value / length;

		return vect;
	}

	inline Vector2 cartesian(Scalar radius,Scalar angle)
	{
		return Vector2(radius * cos(angle),radius * sin(angle));
	}

	inline Vector2 polar(Scalar x,Scalar y)
	{
		return Vector2(atan2(y,x),sqrt(x * x + y * y));
	}

	inline Scalar dot(const Vector2& pVec1,const Vector2& pVec2)
	{
		return pVec1.X * pVec2.X + pVec1.Y * pVec2.Y;
	}

	inline Vector2 rotate(const Vector2& pVec,Scalar angle)
	{
		Scalar cosResult = cos(angle);
		Scalar sinResult = sin(angle);

		//Essentially, apply a 2x2 rotation matrix to the vector
		Scalar newX = pVec.X * cosResult - pVec.Y * sinResult;
		Scalar newY = pVec.X * sinResult + pVec.Y * cosResult;

		return Vector2(newX,newY);
	}
}

#endif

Notes:

With this class, you can't do this:

Vector2 vect = 2;

This was possible with my old Vector2 class, and frankly should be an error.  If you are going to initialize the vars of a Vector2 at a later time, you can do this:

Vector2 vect = Vector2(Vector2::Uninitialized())

The reason for this is, doing this:

Vector2 vect = Vector2();

...creates a Vector2(0,0) by default. I could setup a default constructor and not use default values, however that could result in bugs from coders not properly initializing Vector2 objects. So, it is this reason the Uninitialized class is being used.

Feel free to use this improved Vector2 class, and if the c-style functions in VectorUtil bug you, feel free to make them member functions again in Vector2.

Download the Vector2 improved here: Vector2 class files.

[Update: As of 5/11/10 I noticed a typo, which I fixed, however I need to update the source files. I've also realized there are also a couple other utility functions I could "add", so will do so sometime soon; I got the idea from looking at another blog, however I realized he just named the functions to something easily understandable. For example, the dot and cross product; their names don't say anything about what the function really does, what the data represents. So, it seems useful to package up those functions to make it easier for programmers using this utility, and of course leaving the original functions in-tact (perhaps?) so other programmers looking for them won't be confused when they think they can't find them. So, more cool things to come! :) ]

It's a very simple class, but I wrote what I'm calling a Timer, it has similar functionality to a stop watch. The Basic timer class relies on the Windows QueryPerformanceFrequency, so here's the function necessary for my Timer class:

Time.h

#ifndef w_Time
#define w_Time

#include "../Definitions.h"

#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <Windows.h>

namespace _Warp
{
	class Time
	{
	public:

		static Real64 HiResTime()
		{
			u64 ticks;
			u64 ticksPerSecond;
			Bool result = QueryPerformanceFrequency((LARGE_INTEGER*) &ticksPerSecond);
			if(result == 0)
			{
				return -1;
			}
			result = QueryPerformanceCounter((LARGE_INTEGER*) &ticks);
			if(result == 0)
			{
				return -1;
			}
			return (Real64) ticks / ticksPerSecond;
		}
	};
};

#endif

Timer.h

#ifndef w_Timer
#define w_Timer

#include "../Definitions.h"

namespace _Warp
{
	class Timer
	{
	protected:
		Real64 _start;

		Bool _running;

	public:
		Timer();

		void Start();
		void Stop();
		void Reset();

		Real64 Get_Microseconds() const;
		Real64 Get_Milliseconds() const;
		Real64 Get_Seconds() const;

		Bool IsRunning() const;
	};
};

#endif

Timer.cpp

#include "Timer.h"

#include "Time.h"

namespace _Warp
{
	Timer::Timer()
		: _start( 0 )
		, _running( FALSE )
	{
	}

	void Timer::Start()
	{
		// this allows the timer to continue from where it left off
		_start = Time::HiResTime() - _start;
		_running = TRUE;
	}

	void Timer::Stop()
	{
		if(_running == TRUE)
		{
			_start = Time::HiResTime() - _start;
			_running = FALSE;
		}
	}

	void Timer::Reset()
	{
		if(_running == TRUE)
		{
			_start = Time::HiResTime();
		}
		else
		{
			_start = 0;
		}
	}

	Real64 Timer::Get_Microseconds() const
	{
		if(_running == TRUE)
		{
			return (Time::HiResTime() - _start) * 1000000.0;
		}
		return _start * 1000000.0;
	}

	Real64 Timer::Get_Milliseconds() const
	{
		if(_running == TRUE)
		{
			return (Time::HiResTime() - _start) * 1000.0;
		}
		return _start * 1000.0;
	}

	Real64 Timer::Get_Seconds() const
	{
		if(_running == TRUE)
		{
			return Time::HiResTime() - _start;
		}
		return _start;
	}

	Bool Timer::IsRunning() const
	{
		return _running;
	}
};

Here is a sample of how to use my timer class:

Timer timer = Timer();
timer.Start();
/* do stuff here */
timer.Stop();
Real64 seconds = timer.Get_Seconds();
timer.Reset();//reset the timer so it's total count is back to zero seconds.

timer.Start();
/* time something else */
timer.Stop();
/* do something */
timer.Start();//continue the count from where the timer left off
/* time something again*/
timer.Stop();
seconds = timer.Get_Seconds();// this is the total count of seconds from the last two timing sessions since Reset wasn't called

You can find the blog on the Definition.h file here.

Or download all of the above files and Definition.h here: Timer project files.

This is a simple definitions file that I use in my game engine, though this version was dumbed down for a 2D game engine I'll be working on.

Definitions.h

#ifndef w_Definitions
#define w_Definitions

#ifndef NULL
#define NULL 0
#endif

#ifndef TRUE
#define TRUE 1
#endif

#ifndef FALSE
#define FALSE 0
#endif

#define NUKE(object)	{ if(object)	{ delete (object);		(object) = nullptr; } }
#define NUKE_ARRAY(object) { if(object) { delete[] (object);	(object) = nullptr; } }
#define RELEASE(object) { if(object)	{ (object)->Release();	(object) = nullptr; } }

namespace _Warp
{
	typedef signed char s8;
	typedef unsigned char u8;
	typedef signed short s16;
	typedef unsigned short u16;
	typedef signed int s32;
	typedef unsigned int u32;
	typedef signed long long s64;
	typedef unsigned long long u64;

	typedef unsigned int Bool;
	typedef u8 Byte;

	typedef float Real32;
	typedef double Real64;
};
#endif

These are the base data types I use everywhere in my game. Instead of using the 1 byte bool, I use a custom defined Bool which is the size of an integer; when compiled for a 32 bit system will coincide with 4 byte alignment, and compiled for a 64bit platform will coincide with 8 byte alignment. For more information on byte alignment, check out this wikipedia article.

Some of the macros are also useful for memory management, specifically NUKE, NUKE_ARRAY, and RELEASE. RELEASE is used on things like DirectX objects: RELEASE(_d3dDevice); basically, if you can't tell, any object that has a function called Release can be used with this macro. It checks to see if the object is valid, releases it, and sets the pointer to NULL. NUKE works on object you create using the 'new' operator, and properly sets the pointer to NULL. For example, cleaning up a Vector3:

Vector3* pVect = new Vector3(0,1,0);
/* other code here */
NUKE(pVect); // pVect gets cleaned up and set to NULL, aka, it is now nuked. ;p

And NUKE_ARRAY is used similarly on an array that was dynamically allocated, using new.

Definitions.zip

[Edit: Checkout the improved Vector2 class here: improved Vector2 blog post.]

Hey, it's been a while since I've posted anything, and I've been wanting to share this Vector2 class that I have written. It started being developed less than a year ago, and has undergone some minor changes since then to try to improve efficiency and add functionality. I haven't touched it in a while since then, as I'm now working on a 3D game engine, but here is what I've got.

/*  __      __   ___     _____    ____
 *  \ \    / /  / _ \   |  __ \  |    |
 *   \ \/\/ /  / / \ \  | | / /  |  __|
 *    \_/\_/  /_/   \_\ |_| \_\  |_|
 *      Take it to the next Level
 *
 *  Copyright (c) 2009 Brian Ernst.
 */

#ifndef w_Vector2
#define w_Vector2

#include <math.h>

namespace _Warp
{
	typedef float Scalar;
	typedef int Bool;

	class Vector2
	{
	public:
		Scalar X;
		Scalar Y;

		Vector2(const Scalar x = 0,const Scalar y = 0);
		~Vector2();

		Vector2 operator+(const Vector2& pVector) const;
		Vector2 operator-(const Vector2& pVector) const;
		Vector2 operator*(const Scalar& num) const;
		Vector2 operator/(const Scalar& num) const;
		Vector2 operator*(const Vector2& vector) const;
		Vector2 operator/(const Vector2& vector) const;
		void operator+=(const Vector2& pVector);
		void operator-=(const Vector2& pVector);
		void operator*=(const Scalar& num);
		void operator/=(const Scalar& num);
		void operator=(const Vector2& pVector);
		Bool operator==(const Vector2& vector) const;
		Bool operator!=(const Vector2& vector) const;

		void Clamp(const Scalar& value);
		void Normalize(const Scalar& value = 1.0f);
		void Invert();

		Scalar Length() const;

		Vector2 Copy() const;

		static Vector2 Cartesian(const Scalar& x,const Scalar& y);
		static Vector2 Polar(const Scalar& radius,const Scalar& angle);
		static Scalar Dot(const Vector2& pVec1,const Vector2& pVec2);
		static Vector2 Rotate(const Vector2& pVec,const Scalar& angle);
		static const Vector2 Zero;
	};

	inline Vector2 Vector2::Copy() const
	{
		return Vector2(X,Y);
	}

	inline Bool Vector2::operator==(const Vector2& vector) const
	{
		return X == vector.X && Y == vector.Y;
	}

	inline Bool Vector2::operator!=(const Vector2& vector) const
	{
		return X != vector.X || Y != vector.Y;
	}

	inline Vector2 Vector2::operator+(const Vector2& pVector) const
	{
		return Vector2(X + pVector.X,Y + pVector.Y);
	}

	inline Vector2 Vector2::operator-(const Vector2& pVector) const
	{
		return Vector2(X - pVector.X,Y - pVector.Y);
	}

	inline Vector2 Vector2::operator*(const Scalar& num) const
	{
		return Vector2(X * num,Y * num);
	}

	inline Vector2 Vector2::operator/(const Scalar& num) const
	{
		return Vector2(X / num,Y / num);
	}

	inline Vector2 Vector2::operator*(const Vector2& vector) const
	{
		return Vector2(X * vector.X,Y * vector.Y);
	}

	inline Vector2 Vector2::operator/(const Vector2& vector) const
	{
		return Vector2(X / vector.X,Y / vector.Y);
	}
}

#endif

And yes, I realize I need to comment this class, and I will. I might include the source files, but you can just as easily click on the "Source" button on the top right corner of the code box. And here's the cpp definitions file for the Vector2 functions:

#include "Vector2.h"

namespace _Warp
{
	const Vector2 Vector2::Zero = Vector2();

	Vector2::Vector2(const Scalar x,const Scalar y)
	{
		X = x;
		Y = y;
	}

	Vector2::~Vector2()
	{
	}

	void Vector2::operator+=(const Vector2& pVector)
	{
		X += pVector.X;
		Y += pVector.Y;
	}

	void Vector2::operator-=(const Vector2& pVector)
	{
		X -= pVector.X;
		Y -= pVector.Y;
	}

	void Vector2::operator*=(const Scalar& num)
	{
		X *= num;
		Y *= num;
	}

	void Vector2::operator/=(const Scalar& num)
	{
		X /= num;
		Y /= num;
	}

	void Vector2::operator=(const Vector2& pVector)
	{
		X = pVector.X;
		Y = pVector.Y;
	}

	Scalar Vector2::Length() const
	{
		return sqrt(pow(X,2.0f) + pow(Y,2.0f));
	}

	void Vector2::Clamp(const Scalar& value)
	{
		if(Length() <= value)
			return;
		Normalize();
		*this *= value;
	}

	void Vector2::Normalize(const Scalar& value)
	{
		Scalar vecLength = Length();

		if(vecLength == 0)
			return;

		X = X/vecLength * value;
		Y = Y/vecLength * value;
	}

	void Vector2::Invert()
	{
		X *= -1;
		Y *= -1;
	}

	Vector2 Vector2::Polar(const Scalar& x,const Scalar& y)
	{
		Vector2 pVector = Vector2();
		pVector.X = atan2(y,x);
		pVector.Y = sqrt(x * x + y * y);
		return pVector;
	}

	Vector2 Vector2::Cartesian(const Scalar& radius,const Scalar& angle)
	{
		Vector2 pVector = Vector2();
		pVector.X = radius * cos(angle);
		pVector.Y = radius * sin(angle);
		return pVector;
	}

	Scalar Vector2::Dot(const Vector2& pVec1,const Vector2& pVec2)
	{
		return pVec1.X * pVec2.X + pVec1.Y * pVec2.Y;
	}

	Vector2 Vector2::Rotate(const Vector2& pVec,const Scalar& angle)
	{
		Scalar cosResult = cos(angle);
		Scalar sinResult = sin(angle);

		//Essentially, apply a 2x2 rotation matrix to the vector
		Scalar newX = pVec.X * cosResult - pVec.Y * sinResult;
		Scalar newY = pVec.X * sinResult + pVec.Y * cosResult;

		return Vector2(newX,newY);
	}
}

It's pretty simple, but quite useful and powerful I think. I put it up here for other people to use for quick reference; let me know what you think or just drop me a line telling me you're using it for something, that'd make my day. (:

So here's a zip file you can download: Vector2

[Disclaimer: This is an experimental post, I would not actually completely condone using this; heck, I'm not even using this. I'm using a queue based event system with reference counting smart pointers.]

For the sake of experimenting, and to make a new and "safer" Event, I found out I could call a protected function from outside of the scope of that class, from using a function pointer assigned by the parent class.  Certainly this doesn't sound safe, as it bypasses encapsulation measures; however, this allowed me to fire an event in a way only the parent could.


So I was trying to come up with an ideal Event for an EventSystem, and I had a couple ideas, though things bugged me in each.  So, this is a typical Event, which I do have a slight problem with:

 

class Event
{
public:

	void Attach(IEventObserver* eventObserver);
	void Detach(IEventObserver* eventObserver);

	void FireEvent(const EventArgs& eventArgs);
};

So, an IEventObserver can both register itself AND fire off an event; the IEventObserver shouldn't be able to fire the event it's registering to, should it? Only the parent that contains the Event should, in my belief. So I thought, is there any way I can allow the parent class to fire off the event and still allow the Event to be public?  Okay, I figured I could setup accessors to the event; however, this meant I'd have to setup an accessor for each and every single event I have, which could get ugly fast.

I eventually thought of a sneaky way, that actually shouldn't even be possible. Giving the parent class, what I call the trigger, a function pointer to a protected function that fires the event. After writing it, I realized while I liked the idea, everything about coding the use of the Event was a lot more difficult, so I provided macros to do the dirty work for you; however, it still seems like an annoying setup to me. I usually code things to be easy to interact with, and what I came up with clearly goes against my programming paradigms.

So, here's the tiny change in the Event:

class Event
{
protected:
	void FireEvent(const EventArgs& eventArgs);

public:

	void Attach(IEventObserver* eventObserver);
	void Detach(IEventObserver* eventObserver);
};

Obviously there isn't much of a difference here, there isn't much to add. The difference is here in the full version:

template <class IEventArgs>
class Event
{
	typedef std::list<IEventObserver<EventArgs>*> EList;
protected:
	EList _observers;

	void FireEvent(IEventArgs& eventArgs)
	{
		EList::iterator iter = _observers.begin();

		while(iter != _observers.end())
		{
			(*iter)->CatchEvent(eventArgs);
			++iter;
		}
	}

public:
	typedef void (Event<IEventArgs>::*IEventTrigger)(IEventArgs& eventArgs);//use an event trigger mechanism

	Event(EventTrigger& trigger)
	{
		trigger = &Event::FireEvent;
	}

	virtual ~Event()
	{
	}

	void Attach(IEventObserver<IEventArgs>* eventObserver)
	{
		_observers.push_back(eventObserver);
	}

	void Detach(IEventObserver<IEventArgs>* eventObserver)
	{
		_observers.remove(eventObserver);
	}
};

Note the EventTrigger; to create an Event you have to pass in a reference to a function pointer. Here are the three Macros I have at the top of my Event.h file (they looked ugly and hard to read inside of the code block, so here they are in a pre tag):

#define EVENT_H(variable,argType) Event::EventTrigger trigger##variable; Event* variable;
#define EVENT_CPP(variable,argType) trigger##variable = NULL; variable = new Event(trigger##variable);
#define EVENT_FIRE(variable,args) ((variable)->*(trigger##variable))(args);

You place a macro call to EVENT_H inside of the .h file, a call to EVENT_CPP in the .cpp file where the event is being constructed, and EVENT_FIRE when you want to fire the event (though, EVENT_H and EVENT_CPP are actually more annoying to use than just setting up the Event by hand, so I'll probably remove those two macros, as they don't actually help at all).

So, ignoring the macros, lets say I want to create an event, I can do this.

Event::EventTrigger keyTrigger= NULL;
Event* keyEvent = new Event(keyTrigger);

This will create an Event for me to use as well as hook up a trigger to fire the event. When I finally want to fire the event I can do something like this;

(keyEvent->*(keyTrigger))(KeyEvent(FK_F11));//this event and argument are just for example

So, this system is what I came up with, though I'm still not so sure if I like it.  I'd love to get any comments or suggestions for a better system.  Even if I don't use this setup, I still found this process to be an interesting learning experience.  I just wanted to find out if I could get access to a protected function using a function pointer; I found out I could, and I find that intriguing.  For clarification, the Event in the above example would be public, and the trigger protected (or private); so I have to update my macro EVENT_H to include those overrides.  I'll provide the source code in a couple days or so when I get everything properly packaged together; right now the code is sitting inside of my engine, and are tied into various systems, so the source files won't compile for you without modification (because I can't include all of the other misc. files).  So, this still isn't a lot nicer than the other solution; it's merely replacing an accessor with a trigger.  So, either way it's kind of ugly I think, to ensure safe firing of an event.

Anyway, I haven't touched Event Systems in more than a couple weeks, it's something I'll have to worry about very shortly; so when I revisit them, I'll probably make a blog post concerning my more finalized systems with what I finally decide to use.  Any feedback would be greatly appreciated. Thanks!

I apologize if the post jumps around a bit, it is very late as I type this.

Archive