Top Level Events (TLE)
What is a TLE ?
As any real time game engine, C2 has to update its state 60 time every seconds so it can keep its 60FPS frame-rate. So every time, it has 160ms to run every events and redraw itself. TLE are all the events on the "top level", directly in the root of one of the event sheets open or in an active group, evaluated every tick.
Their can be different types of events though, and some don't cost anything to the system, so let's look a little more into them.
Different types of events
The first type of event is the trigger, event called at a given time, never evaluated on its own.
You can easily find those events by looking at the green arrow in front of their line in C2 :
A trigger isn't evaluated every tick. Instead, it is called at a given time (here at the start of the layout) and just ignored rest of the time, effectively costing no CPU at all.
Conclusion : you can have all the triggers you want, it won't cost you any frame-rate.
Second type of events are the evaluations, the static events that are evaluated every single tick :
And here you are going to tell me : Yes, I know, there is an "every tick" for a condition !
You wouldn't be wrong, that's the intended behavior, have this event run every tick. But it's also the case of every single evaluations, like these two events :
What is to understand here is :
- First event : every tick, for every currently existing monster, let's compare its life to 0, and run the actions on it if it is inferior or equal.
- Second event : every tick, let's run the other actions
Yes, an empty condition is exactly the same as an "every tick", regarding event evaluation.
Last event type are the fake triggers. Those one, displaying with a green arrow just like the triggers, don't work the same. They are evaluated every tick to see if the condition is met, and run when they first meet the conditions, acting in most case as an evaluation plus a "once while true" condition.
The 4th event of the tutorial is a good example of this :
In practice, this event is quite costly as it will, every tick, take every (bullet,monster) couple, evaluate if they are overlapping, and trigger the event if they weren't the previous tick.
Collision detection ? has to be checked.
On click ? initiated by a user input, can be triggered.
Now that we've looked at the basics, let's see how we can reduce the count of TLE in this example with some techniques.