Multiplayer Interactive-Fiction Game-Design Blog


Automatically suspended timers



Download 8.87 Mb.
Page114/151
Date02.02.2017
Size8.87 Mb.
#15199
1   ...   110   111   112   113   114   115   116   117   ...   151

12 Automatically suspended timers


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:







  1. 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.





  2. 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.


Instances

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:







  1. Create an oMapMyInstance object based off of cMap,

    just like you would create any map object.





  2. Set pMapInstanced to TRUE.





  3. You may wish an instance to be deleted after it hasn't been used

    for a few days. To do so,

    set pMapInstancedExpires.





  4. 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.






Some important points

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.


Behind the scenes

Here's how instancing works behind the scenes:





  1. 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.





  2. 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.



  3. If the instance hasn't been loaded, InstanceRoomRedirect() attempts

    to load a saved instance. If that succedes, the saved instance

    is used.




  4. If a saved instance cannot be found, then

    InstanceRoomRedirect() clones the template rooms and

    objects in the map and uses those.





  5. 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.



  6. The same background timer also deletes saved instanced that

    haven't been used for awhile (as specificed by pMapInstancedExpires).






Download 8.87 Mb.

Share with your friends:
1   ...   110   111   112   113   114   115   116   117   ...   151




The database is protected by copyright ©ininet.org 2024
send message

    Main page