An optimization that automatically suspends timers.
Automatically suspended timers
In order to minimize CPU usage, timers for rooms and NPCs are automatically
suspended when players aren't in them.
The oDatabase object does the following once every second:
-
Un-suspend all the timers in one
randomly selected room, calling room.RoomSleep (FALSE).
This will cause one room to wake up, even if there aren't any
players in it, allowing NPCs to act (albiet slowly) even when players
aren't in the room.
-
Suspend all the timers in two randomly select rooms
using room.RoomSleep(TRUE).
If players are in the room, timers are not suspended.
These suspensions ensure that if a player walks out of a room the room
is eventually suspended.
Plus, whenever a player or NPC walks into a room, the
room ands its adjacent rooms are un-suspended so that NPCs
become active.
If you want a room whose timers don't get suspended then override
RoomSleep() for the room.
13 Instances
Created instanced spaces in your world.
Many multiplayer virtual worlds have "instances" that are private
regions of the world that only the player and his friends can
enter. For example: A player's house might be an instance. Or,
a dungeon that's guaranteed private will have an instance.
In MIFL, you can instance a map and all the rooms
it contains, along with the contents of the rooms. If you wish
a region or zone to be instanced, then just ensure that all the
maps within the region or zone are individually instanced.
You cannot instance individual rooms though,
unless you put them into their own map.
Making an instance is easy:
-
Create an oMapMyInstance object based off of cMap,
just like you would create any map object.
-
Set pMapInstanced to TRUE.
-
You may wish an instance to be deleted after it hasn't been used
for a few days. To do so,
set pMapInstancedExpires.
-
Normally, if a player leaves an item in an instance, the
item will be deleted when the instance saves. This ensures
that players can't use instances to store equipment, instead of
storing equipment in the bank. However, if you wish players
to be able to store equipment in an instance, then
set pMapInstanceSaveAll to TRUE.
When you mark a map as pMapInstanced, the map's rooms and all the objects
in the room are treated like a "template". When an instance of the
map are created, all the rooms and objects of the template are cloned.
Therefore, never allow player characters or non-template NPCs
to move into the template. This shouldn't be difficult since all the methods
and functions test for the instance and prevent movement into it.
NPCs that are checked out of the database (those
based on cSaveToDatabase) can't move into an instance. However,
NPCs not in the database can move freely between instances. This ensures that
a major NPC doesn't follow a player into an instance, and then the player shuts
down the instance, permenantly trapping the NPC.
Unless players form up into a party, they will go their separate ways
when they enter an instance, even if they're following one another. If
they form a party, they enter the leader's instance.
NPCs that are intentionally chasing players will be to enter the player's
instance.
Here's how instancing works behind the scenes:
-
Whenever a player character (or NPC) moves from room to
room, InstanceRoomRedirect() is called to see if the
player has entered a new instance. If the PC or NPC doesn't
switch instances then InstanceRoomRedirect() doesn't make any
changes to the movement.
-
If a PC or NPC enters a room with a different
instance, InstanceRoomRedirect() determines
if the instance has been loaded already. If it has, it just
remaps the new room to the instanced room.
-
If the instance hasn't been loaded, InstanceRoomRedirect() attempts
to load a saved instance. If that succedes, the saved instance
is used.
-
If a saved instance cannot be found, then
InstanceRoomRedirect() clones the template rooms and
objects in the map and uses those.
-
Once every 15 seconds (approximately), a timer tries to shut down one
of the running instances. If any players are in the instance,
the shutdown fails right away. If no players are there, the instance
is saved to disk, and all the instance rooms and objects are deleted.
-
The same background timer also deletes saved instanced that
haven't been used for awhile (as specificed by pMapInstancedExpires).
Share with your friends: |