![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
Well, I'd said that I was going to post information about my event system for my Tetris-Power project, so here it is.
The main idea behind this is a simple means for defining and detecting achievements.
If everything done in the game can be represented by a large list of events, you can simply scan the list for a matching sequence to see if an achievement has been matched.
In this case, everything really does mean everything, including keyboard commands, block motions, rows filled, rows removed, scores added, the advancement of time, error and warning messages for the log, and so on and so forth.
The overall structure of the modules then is heavily involved with the event system, with messages getting passed to the events system instead of directly calling other system, and each system that needs to read messages registers with the event system for the types of messages they're interested in.
(for example, if the logging system were enabled, it would read log_info, log_warning, and log_error message types)
This should greatly simplify the overall structure of the code so that not everything would need to know about everything else.
One of the main issues I have right now is that too many systems need to know about each other, which overly complicates my code.
So far I haven't actually added any code yet, as I'm still working on the concept itself.
Once I have that figured out, I'll have to rewrite large swathes of code to use the events system instead of directly calling.
Supposedly, it should be possible to gradually move over to the events system, starting with adding in code to trigger events, having each module listen for appropriate events, actually using the event listeners instead of the function calls as used now, then removing the functions used previously, then refactoring code to simplify things.
I hope it doesn't break while I switch over, but you can't tell until you start what might happen.
The main idea behind this is a simple means for defining and detecting achievements.
If everything done in the game can be represented by a large list of events, you can simply scan the list for a matching sequence to see if an achievement has been matched.
In this case, everything really does mean everything, including keyboard commands, block motions, rows filled, rows removed, scores added, the advancement of time, error and warning messages for the log, and so on and so forth.
The overall structure of the modules then is heavily involved with the event system, with messages getting passed to the events system instead of directly calling other system, and each system that needs to read messages registers with the event system for the types of messages they're interested in.
(for example, if the logging system were enabled, it would read log_info, log_warning, and log_error message types)
This should greatly simplify the overall structure of the code so that not everything would need to know about everything else.
One of the main issues I have right now is that too many systems need to know about each other, which overly complicates my code.
So far I haven't actually added any code yet, as I'm still working on the concept itself.
Once I have that figured out, I'll have to rewrite large swathes of code to use the events system instead of directly calling.
Supposedly, it should be possible to gradually move over to the events system, starting with adding in code to trigger events, having each module listen for appropriate events, actually using the event listeners instead of the function calls as used now, then removing the functions used previously, then refactoring code to simplify things.
I hope it doesn't break while I switch over, but you can't tell until you start what might happen.