I need to be able to execute certain events at a given time in my game, for example, say the player "Builds a building" this building should take 15mins to process. Implementing this seems straightforward enough, simply enter the event into the database and execute the event when the time comes for it to be completed.
However, it is my understanding that i would need a script that is running permanently on the server and continually checks the event database for delayed events to execute and process them as needed. My question is, is this the right approach or should i be tackling the "event que" differently?
Some of the events that will be processed can effect many different players so they would need to happen in real time, as opposed to be lazy loaded.
You can see similar such event queues in browser games such as travian, grepolis etc.
Update - If i was to implement a purely lazy load method, are there any flaws in the following pseudo code?
## upon player_x pages load
## start a loop that will only exit once all needed events have been processed
## check for any events initiated by player_x that are overdue
## get event and lock it for processing
## does this event involve another players object?
## if it does, then lets check if said object also has any events that should happen before this event
## if it has, then lets process one of those events instead, and loop again once processed
## if it doesnt have any previous events, then we're free to process this event, do it
## loop till all overdue events for player_x's object are done
No comments:
Post a Comment