I'm coding a MUD
In PHP
And I've built enough helper functions to truly give me the flexible design tools I need to accomplish the task, from referenced cell search returns to a dynamic object container that saves its own data to a file automatically... everything is going smooth! The entire package so far is 90k in solid, well-documented, modular code.
But data flow is killing me...
- A SOCKET is socket/server data about the actual connection. A connection holds the sock_id, the IP, the input buffer, a temporary cache, and the account id it is logged in on.
- A PLAYER is human data about the CONNECTION as well as a list of characters the CONNECTION has at his disposal.
- A CHARACTER is server data about the virtual character within the game.
Game Loop Core
{
Update gametime
(CHECK) Socket Activity
{
(CHECK) Activity on listening port
{
Create a new connection and set’s state to new_user
Show menu;
}
Else activity is from an established socket
{
(CHECK) To see if not link dead
{
(CHECK) Activity for return carriage:
Parse input;
Appent input to the Event List;
}
Else player is link dead
{
Remove connection;
}
}
}
(CHECK) AI Activity
{
Add weather, map, monster, and other automated activity to
the Event List.
}
Run Event Handler;
}
The EVENT LIST contains a massive array of all changes that have taken place since the last game loop. The EVENT HANDLER navigates the event list and determines how and what events are executed. All events are timestamped in gametime for when they are to be processed. Player inputs are timestamped at 0 for immediate execution.
Event Handler
{
(CHECK) Events that have already expired
{
(CHECK) Player Event
{
Based on connection status, send the player to the appropriate area.
If the player is currently playing: Execute Event;
}
Else it is a different kind of event (combat, item, spell, etc.)
{
And do it!;
}
}
}
A problem I just realized is that since my event handler is using timestamps... I've hit what appears to be equivilent to red/blueshifting.
When the game loop runs, it checks to see what tick the game is at. (I've set it to 1 tick being equal to three seconds, but this can be changed.) The game loops once and it updates the time at 1 tick... it runs though 1000 playerss input and 10000000 AI event appending and then proceeds to check to see what events are executed based on the clock.
Now given that when the timer was updated way before the original loops, the real-time has progressed significantly at this point. When I run the game loop again, I appear to hit a situation where upon calculation, it is possible for the tick sequence to
skip numbers. One solution is to not base it off the timer, but the actual loop itself. I disagree with this because the faster yoru CPU is, the faster the game loop will go, and thus, the entire game will move at a ridiculous pace. MY question is: is the tick skipping detrimental to an event handler that triggers based on tick-count? Events only are executed when its timestamp is less then the current tick. This would mean I need some sort of compensator to determine event priority then, correct?