A
AzizMandar
C++ Event Coding Questions
I have done some simple programs in C++ and read a lot of good C++
books (Including The C++ Programing Language, and C++ Primer) I am
trying to understand and implement an Event based program and Message
system. I have a very basic event engine that I'm feeling works a bit
backwards. I'm looking for documents, source code, and books that may
help me better understand how to implement this type of code. I am not
a student and this is not homework, just a hobby at the moment.
I have a few requirements that are making my search difficult.
1. I'm trying to develop some cross platform programming skills so I
want the code to be as generic as possible. (No MFC)
2. I'm happy to use the STL but no other external libraries
3. I am coding this on a Linux Box but that should not matter because
of point 1
4. Simpler is better. I understand and am able to read most code and
have many samples but they are very poorly documented and are so
ingrained with some external framework (like MFC) that I am having a
bear of a time trying to make heads or tails of it.
5. I have a very archaic but working garbage collector and memory
management system. After I get this all figured out I'll be happy to
let you all rip it to shreds and tell me how evil and silly I am. (It's
creative but not necessarily in a good way)
6. I'm not using threads. I hear that they are not dependable for
execution speed and time and can be problematic and in many cases are
unnecessary.
I keep reading about Event handlers and Dispatchers and I don't think
that is what I am doing
My code is a bit long and not commented well so I will spare you all
reading it at this point.
In general I have an Event Controller that all events are sent to.
When it receives an event it determines if it runs now or is on hold.
If it runs now it gets added to the end of the NOW link list. If it
runs later it gets sorted into the HOLD list. Once a cycle the
Controller checks the front of the HOLD lists for things that should
run now (and pulls off the events and pushes them onto the front of the
NOW list) Then it executes every event in the NOW list. Events are
deleted after they return from execution by the Controller.
The Events work by calling a function pointer that points to a static
function of the object or factory that created it. These then do
something and usually generate a new event. The Function Pointers
ActionFunction(Object* Me,int Action) for what the object (Me) is doing
(Action) and InteractFunction(Object* Me,Object* You, int Action) for
Object (Me) doing (Action) to Object(You)
I have some great casting in these functions that just shout out EVIL
and I'm certain I can get rid of them by changing the way either the
function Pointers work or the way the Events work.
Also I think this will need a better State Machine because using an
enumerated Type cast on an int is EVIL and using a raw int and trying
to keep track of what it means is EVIL and making the base objects and
events use a pre-defined enumerated Type is inflexible and therefor
EVIL.
Please help me get rid of the EVIL.
Thanks
I have done some simple programs in C++ and read a lot of good C++
books (Including The C++ Programing Language, and C++ Primer) I am
trying to understand and implement an Event based program and Message
system. I have a very basic event engine that I'm feeling works a bit
backwards. I'm looking for documents, source code, and books that may
help me better understand how to implement this type of code. I am not
a student and this is not homework, just a hobby at the moment.
I have a few requirements that are making my search difficult.
1. I'm trying to develop some cross platform programming skills so I
want the code to be as generic as possible. (No MFC)
2. I'm happy to use the STL but no other external libraries
3. I am coding this on a Linux Box but that should not matter because
of point 1
4. Simpler is better. I understand and am able to read most code and
have many samples but they are very poorly documented and are so
ingrained with some external framework (like MFC) that I am having a
bear of a time trying to make heads or tails of it.
5. I have a very archaic but working garbage collector and memory
management system. After I get this all figured out I'll be happy to
let you all rip it to shreds and tell me how evil and silly I am. (It's
creative but not necessarily in a good way)
6. I'm not using threads. I hear that they are not dependable for
execution speed and time and can be problematic and in many cases are
unnecessary.
I keep reading about Event handlers and Dispatchers and I don't think
that is what I am doing
My code is a bit long and not commented well so I will spare you all
reading it at this point.
In general I have an Event Controller that all events are sent to.
When it receives an event it determines if it runs now or is on hold.
If it runs now it gets added to the end of the NOW link list. If it
runs later it gets sorted into the HOLD list. Once a cycle the
Controller checks the front of the HOLD lists for things that should
run now (and pulls off the events and pushes them onto the front of the
NOW list) Then it executes every event in the NOW list. Events are
deleted after they return from execution by the Controller.
The Events work by calling a function pointer that points to a static
function of the object or factory that created it. These then do
something and usually generate a new event. The Function Pointers
ActionFunction(Object* Me,int Action) for what the object (Me) is doing
(Action) and InteractFunction(Object* Me,Object* You, int Action) for
Object (Me) doing (Action) to Object(You)
I have some great casting in these functions that just shout out EVIL
and I'm certain I can get rid of them by changing the way either the
function Pointers work or the way the Events work.
Also I think this will need a better State Machine because using an
enumerated Type cast on an int is EVIL and using a raw int and trying
to keep track of what it means is EVIL and making the base objects and
events use a pre-defined enumerated Type is inflexible and therefor
EVIL.
Please help me get rid of the EVIL.
Thanks