wyvern.kernel.kernel
Class CameraManager

java.lang.Object
  extended bywyvern.kernel.kernel.CameraManager

public final class CameraManager
extends java.lang.Object

Keeps track of dirty maps and dirty cameras. Dirty maps are maps that have had a visible event. Any cameras that could see the event need to be refreshed. Dirty cameras are cameras that have become fully invalid by moving or entering a new map.

Note: this class has static methods for manipulating cameras, but this is NOT the correct way to move them around. You should call the camera move/position methods directly, and they will call the CameraManager methods to get refreshed.

Under the current scheduler design, camera refreshes currently have to be done on the event-processing thread as an event. This ensures that the maps aren't being updated during a camera refresh. (This is fixable, long-term.)

We only want a camera refresh to happen if both the following conditions are met:

The game event scheduler takes care of tracking the first condition, in a private camera-timer subsystem. The CameraManager takes care of the second condition by knowing if anything has become dirty since the last camera refresh..

The whole system is incredibly inefficient and needs a redesign.

Version:
1.0, Dec 31, 1997
Author:
Steve Yegge

Method Summary
static void addCamera(GameMap map, Camera camera)
          Registers a camera with a specified map.
static void dirtyCamera(Camera camera)
          Notifies the CameraManager that a camera wants to be refreshed, regardless of whether any changes have occurred in the map the camera is viewing.
static void dirtyMap(GameMap map)
          Notifies the CameraManager that a map has become visually dirty, so that on the next refresh it will be processed.
static void flushCameras()
          Flushes all changes to all maps that we've gathered since the last refresh.
static java.util.Map getCameras(GameMap map)
           
static java.lang.String getProfilingInfo()
          Returns profiling information about the cameras, for debugging.
static void invalidateCameras(GameMap map, int x, int y)
          Invalidates all the cameras that can see (x, y).
static void printMaps()
          Prints the maps and their camera sets.
static void removeCamera(GameMap map, Camera camera)
          Unregisters a camera from a map.
static void removeMap(GameMap map)
          Notifies the CameraManager that a map should be removed from the lists, usually because it's being unloaded.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

addCamera

public static void addCamera(GameMap map,
                             Camera camera)
Registers a camera with a specified map.

Parameters:
camera - the camera to add
map - the map the camera wants to view

removeCamera

public static void removeCamera(GameMap map,
                                Camera camera)
Unregisters a camera from a map.

Parameters:
camera - the Camera to unregister
map - the map to remove the camera from

dirtyMap

public static void dirtyMap(GameMap map)
Notifies the CameraManager that a map has become visually dirty, so that on the next refresh it will be processed. Called by GameMap.visUpdate(). Normally you don't have to call this directly, since the map takes care of it. Can be called by any thread in the game, though.

Parameters:
map - the GameMap that's become dirty

removeMap

public static void removeMap(GameMap map)
Notifies the CameraManager that a map should be removed from the lists, usually because it's being unloaded.


dirtyCamera

public static void dirtyCamera(Camera camera)
Notifies the CameraManager that a camera wants to be refreshed, regardless of whether any changes have occurred in the map the camera is viewing. This is useful for "floating" cameras that can move around in a map without dirtying the map.

Parameters:
camera - the camera to refresh, at kernel refresh-time

invalidateCameras

public static void invalidateCameras(GameMap map,
                                     int x,
                                     int y)
Invalidates all the cameras that can see (x, y). Called by AbstractGameMap when someone has updated the opaque bit at (x, y) - forces the cameras to redo their raycast.

Parameters:
map - the map
x - map x location
y - map y location

flushCameras

public static void flushCameras()
Flushes all changes to all maps that we've gathered since the last refresh. Called by the Scheduler whenever it's time to update the cameras. CALLED BY: CameraAgent.execute() [EXECUTIVE WORKER THREAD]


getCameras

public static java.util.Map getCameras(GameMap map)

printMaps

public static void printMaps()
Prints the maps and their camera sets. For debugging.


getProfilingInfo

public static java.lang.String getProfilingInfo()
Returns profiling information about the cameras, for debugging.

Returns:
a string for wizards to examine