wyvern.world
Class BackgroundMapLoader

java.lang.Object
  extended bywyvern.world.BackgroundMapLoader
All Implemented Interfaces:
GameMap.UnloadMapConstants

public final class BackgroundMapLoader
extends java.lang.Object
implements GameMap.UnloadMapConstants

This class spawns threads to load maps, so that the server doesn't have to block while maps load (which would freeze the game).

Version:
1.0, Jan 29, 2000
Author:
Steve Yegge

Field Summary
 wyvern.kernel.data.MultiHashMap loading_
          Keeps track of the maps that are currently loading, so incoming requests to load them can be merged together.
 EDU.oswego.cs.dl.util.concurrent.ConcurrentHashMap maps_
          This variable holds all the maps currently loaded in the game.
 
Fields inherited from interface wyvern.lib.GameMap.UnloadMapConstants
MAP_CONTAINS_PLAYERS, MAP_NOT_LOADED, SUCCESS
 
Method Summary
 void autoloadMap(java.lang.String path)
          Used for autoloading the destinations of "autoload" teleporters.
static BackgroundMapLoader getInstance()
           
 GameMap getMap(MapLoaderListener callback, java.lang.String name)
          Returns a reference to a map, loading it if necessary on a background thread.
 GameMap getMap(MapLoaderListener callback, java.lang.String name, GameMapLoader loader, boolean cache)
          Loads a map in the background using a custom map loader.
 GameMap getMapNoLoad(java.lang.String name)
          Retrieves the specified map if it's already loaded in memory, else returns null.
static java.lang.String getProfilingInfo()
          Prints information about the health/status of the object.
 java.lang.String[] getRegisteredMaps()
          Returns a list of all currently loaded maps.
 void registerMap(GameMap map)
          Adds a map to the World.
 int unloadMap(java.lang.String name)
          Attempts to unload a map from the game.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

maps_

public EDU.oswego.cs.dl.util.concurrent.ConcurrentHashMap maps_
This variable holds all the maps currently loaded in the game.


loading_

public wyvern.kernel.data.MultiHashMap loading_
Keeps track of the maps that are currently loading, so incoming requests to load them can be merged together. Keys are paths to the maps that are currently loading. Values are lists of MapLoaderListeners who want to be notified when the map is done loading.

Method Detail

getInstance

public static BackgroundMapLoader getInstance()

getMap

public GameMap getMap(MapLoaderListener callback,
                      java.lang.String name)
Returns a reference to a map, loading it if necessary on a background thread. The map will be placed in the system cache after loading, and the callbacks will be notified that it's now available.

Parameters:
callback - the callback wanting to know when it's loaded
name - the map path, e.g. "village/blacksmith" or "wiz/rhialto/maps/desert/pyramid", or a virtual path for per-player maps, such as "players/bob/village/blacksmith".
Returns:
the requested GameMap.

getMap

public GameMap getMap(MapLoaderListener callback,
                      java.lang.String name,
                      GameMapLoader loader,
                      boolean cache)
Loads a map in the background using a custom map loader. The map will be loaded to start monsters, and marked as not in the map editor.

Parameters:
name - the map path, e.g. "village/blacksmith" or "wiz/rhialto/maps/desert/pyramid", or a virtual path for per-player maps, such as "players/bob/village/blacksmith".
callback - the callback wanting to know when it's loaded
loader - a custom map loader, perhaps one that constructs the map dynamically without reading it from a mapfile. Also called by getMap(MapLoaderListener, String), passing in a standard MapLoader.
cache - true to cache the map in the World list by its path after loading the map. If you're passing in a custom GameMapLoader, then you probably want to pass false, and register the map yourself after the map is completely constructed, using World.registerMap().
Returns:
the requested GameMap, or null if it's begun loading

getMapNoLoad

public GameMap getMapNoLoad(java.lang.String name)
Retrieves the specified map if it's already loaded in memory, else returns null. Doesn't attempt to load the map.

Parameters:
name - the map path, e.g. "village/blacksmith" or "wiz/rhialto/maps/desert/pyramid", or a virtual path for per-player maps, such as "players/bob/village/blacksmith".
Returns:
the map, null if not currently loaded

autoloadMap

public void autoloadMap(java.lang.String path)
Used for autoloading the destinations of "autoload" teleporters. This can help give the game a more seamless effect - when you enter an area, any teleporters in that area that are marked "autoload" will have their destinations begin loading silently in the background. Autoloaded maps have shorter unload-delay timers, in case nobody ever goes in them.

Parameters:
path - the map path, e.g. "village/blacksmith" or "wiz/rhialto/maps/desert/pyramid"

unloadMap

public int unloadMap(java.lang.String name)
Attempts to unload a map from the game.

Parameters:
name - the map path, e.g. "village/blacksmith" or "wiz/rhialto/maps/desert/pyramid", or a virtual path for per-player maps, such as "players/bob/village/blacksmith".
Returns:
an error code (GameMap.UnloadMapConstants)

registerMap

public void registerMap(GameMap map)
Adds a map to the World. Required if you create a map at run-time, and you want people to be able to teleport to it with teleporters or "goto"/"teleport". Not required if you invoke the World object to load a map file via World.getMap() or World.getMapSynchronously()

Parameters:
map - the map to add; must have its path set

getRegisteredMaps

public java.lang.String[] getRegisteredMaps()
Returns a list of all currently loaded maps.


getProfilingInfo

public static java.lang.String getProfilingInfo()
Prints information about the health/status of the object.