[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.

At the moment I'm in a turning point in my life, almost ready to graduate from college, and trying to figure out what I'm going to do with my life.  I find myself with an internal confrontation.  I've been spending much of my life worrying about school, spending lots of time working on school work, not so much time hanging out and having fun with friends.  This hasn't been a problem: I've been doing good, got into the schools I wanted to get into.  I've made good decisions for the most part, as far as my long term goals, it seems.

So, let me tell you some of the new stuff I have to worry about (though if you've been in college, some of this shouldn't be anything new).

  1. Worry about applying to Grad Schools
  2. Worry about requirements for Grad Schools, including taking the GRE Exams if any of the schools I want to go to, require them.
  3. Get the transcript for my summer courses, taken at a community college, sent to my school, and hope they transfer.  Otherwise I can't graduate early.
  4. Worry about getting my summer programming project work on Upwards passed as co-op credit. If I can't, then I HAVE to make sure I get my summer courses transferred, so I can work on a Spring Co-op.
  5. I NEED to learn a lot of things in my own time, as I wasn't as productive for the last year as I would've liked to be (due to personal issues).  This creates problems where I feel awkward with my social situation:
  6. I don't have a strong urge to hang out with my friends atm, I'm perfectly satisfied chilling at home, listening to music, programming away, and getting my schoolwork done.  I don't know what to make of it, whether it's laziness, wanting to use school, my future, and personal progress as an excuse.  I know if I had someone close, like a gf, that would give me reason to go out and do things; as I've found out, on my own, I don't tend to feel as inspired for variety and doing new things on my own.  I need a little push, I guess.  I want to try to find some friends I can grow close to, either trying to strengthen existing relationships, or find new ones.  Also, I should be finding new friends to hang out with where I am, not just online.  Because I'm inside working on my stuff, I find it easy to stay in touch with my friends from afar, while neglecting the ones who are here (as I'm busy with work).

And that pretty much sums it up, the last point being most of the personal conflict of me being unsure of what I want to do.  I really, really want to get into this one graduate school in Texas, and I feel I need to step up my game and get things done to do that (which means sacrificing the social time).  My plan of attack socially, was to join the tennis club, and meet people who are enthusiastic about tennis so I can play on a regular basis (and probably find a girl there to encourage me to go out and do things more).  Ugh, don't get me started on girls.  But let me share this comic I just found recently, which takes a load off of my mind:

[caption id="" align="aligncenter" width="800" caption="When A Guy Does Something Wrong"]When A Guy Does Something Wrong[/caption]

Remember when I mentioned personal issues? Yeaah.  *cough* a girl *cough* So I tend to think a lot, analyzing things, sometimes looking for things that aren't there.  I'm a person who likes to question things (which is also why I don't have a firm belief in God, and consider myself an agnostic atm, among other things, like questioning laws and government decisions).  But don't worry, I'm not thaat bad, I don't typically like looking for things that aren't there, which is why I typically look down on English classes; I hate when they analyze things that the author probably never intended.  Oh, so one thing I figured out is that I have no idea how to approach girls.  There is this girl I like living not far from me on campus, she's cute, and is pretty awesome; I just don't have a class with her anymore, and she has alll sorts of guy friends she hangs out with already anyway.  And because of all of the stuff I have to worry about, there's no way I'm going to be in the top of my game, especially if I want to try to be humorous.  So yeah, don't have any idea how to approach her to just hang out or something; though I'm sure I'm worrying about it more than I should.  And a topic for another post perhaps, love, and that other girl I haven't gotten over.

Anyyway, perhaps this is too much of a rant for a blog site, and is better meant for a journal.  So, I'm open to new friends, and don't consider myself a pessimist in the least, despite what you may think from reading this post. So don't even think I am!!  Ever!  My aim sn is: optimisticSorrow, for I am neither always completely optimistic or pessimistic, I am somewhere in between.

*nods* Soo college, yeaah. Life. Yeaah, dude.  Totally. Okay, I have reading to do, work to do.  Just needed to rant, since all of this has been running through my head while I've been trying to do this dry reading.  Drop me a line, and I'll have more contact information up here in the future!

UT3 Logo

MEGA KILL!

I love UT3, and since it's the first in the UT series I really played, it is my favorite.  I know, saying this will enrage countless hardcore UT fans.  I had my friend Brett play online last night, and omg he was getting excited playing it!  It was seriously like watching an excited kid opening presents.  He was playing a crazy CTF match, and left and right everyone was dying, explosions taking out groups of players.  It was INSANE.  The maps on this server just kind of stunk, it was a killing frenzy where it's hard to shine when you're killing multiple guys in front of you, you get taken out by some backstabber; large open maps where there is limited cover, are ridiculous.  I'm not going to play them, I've made my mind up that much.

ULTRA KILL!

God I love hearing those phrases chanted out, and I bask in the moment of me, a killing machine. ;P  I'm not bad, but I won't pretend to be an amazing player; I need to play online more with the good players, because bots just don't do you fighting justice. Though, before I do that, I'm now playing to become an expert with each weapon. My latest experiments, have been with the sniper rifle. I was never good with the thing, and in close quarters I was as good as dead. From my experience, it's good to play against Average bots when you're trying to learn and master weapons, because you get second and third chances. So I've been playing a couple levels now (I forget the names off the top of my head). I had the number of bots (or is that players, I forget), set to 10, and set the game to a deathmatch for 20 minutes with no score limit. On the first run I got 269 kills, 8 deaths. That run, was incredibly hard to top, and I'll try to top it today; yesterday I wasn't able to. So during my runs, I'm excited to say I've gotten to hear, "MONSTER KILLL!" XD I used to suck with the sniper rifle, now I'm getting quite handy with it. Nearly every shot I get is a head shot, though I still have more training to do; and these were just against bots, I need practice against fast moving players. On Arsenal I got like 147 kills, and 0 deaths. After looking on YouTube, I may post some of my playthroughs.

UT3 is one of the games I enjoy playing the most, it's just good mindless fun!

Anyway, I'm on a mission to become a kick-ass UT3 player! Let me know if you want to play sometime, it'll be fun. :)

Here's a playthrough I did the other day:

Is this not a fitting line for the start of a programmer's blog? ;P  I know, I know, you must be sick of seeing it by now!

leetNightshade is my alias, and this is my blog.  This is my realm. Welcome, visitors.

Okay, so this is the start of my new blog at leetNightshade.com, previously I had a tech blog up at briansport.com, but I have a different vision for that site and domain name.  leetNightshade is an alias I came up with from piecing together different names from handle generators, trying to come up with an XBox Live name.  I soon discovered that this particular sn isn't really used by anyone, so I claimed it for myself.  Google leetNightshade, and you should find me.  So unlike my last blog, this one is a personal blog for me, not just a tech blog; so it will include anything and everything I desire to write.

I realized since I'm going to be making a wordpress layout, it would be easy enough to swap in that I shouldn't delay putting wordpress up any longer... so here it is!

I'm currently working on a C++ Project I'll get into more detail about in another post, but the game engine I'm developing is called the Warp  Engine.  Though I intended this imagery for this engine to be a warp hole, portal, something that takes you to new and interesting places.  When I say Warp Engine, I think something from Startrek, which isn't what I intended at all; though I think it still works.

So, I'm on a short break before classes start, here's my schedule.  Classes begin September 6th.  The above mentioned engine will continue to be worked on as a part of an independent study, and I JUST started to get my motivation back to start programming; though it's not all back yet.  But at least I had a spark of motivation!! That's alll that counts, rightt?!1 :)

Okay, stuff to do, later!

(hm, just noticed the font for the temporary layout is kinda smalll....)

Oh, and welcome to the Realm of leetNightshade!

Archive