C# Class Terrarium.Renderer.TerrariumGameView

Encapsulates all of the drawing code for the Terrarium Game View. This class makes heavy use of the DirectDraw APIs in order to provide high speed animation.
Inheritance: System.Windows.Forms.PictureBox
显示文件 Open project: eugeniomiro/Terrarium Class Usage Examples

Protected Properties

Property Type Description
_backBufferSurface IGraphicsSurface
_screenSurface IGraphicsSurface

Public Methods

Method Description
AddBackgroundSlide ( ) : void

Used to change the background slide of the Terrarium. Only a single background slide can be added with this revision.

AddComplexSizedSpriteSurface ( string name, int xFrames, int yFrames ) : void

Add a complex sprite surface that takes advantage of sized sprites

AddComplexSpriteSurface ( string name, int xFrames, int yFrames ) : void

Add a complex sprite surface given the number of frames.

AddSpriteSurface ( string name ) : void

Adds a generic 10frame by 40frame sprite surface that is compatible with creature animation.

CenterTo ( int xOffset, int yOffset ) : void

Controls scrolling of the viewport around the world map. Attempts to center the view to the defined point.

ClearProfiler ( ) : void

Clear the profiler

CreateFullScreenSurfaces ( ) : bool

Creates the surfaces required for full screen operation.

CreateWindowedSurfaces ( ) : bool

Method used to create the necessary surfaces required for windowed mode.

CreateWorld ( int xPixels, int yPixels ) : Rectangle

Tell the game view to create a new world and reset the rendering surfaces.

InitializeGraphicEngine ( bool fullscreen ) : bool

Initializes DirectDraw rendering APIs. The function can be called to initialize both Windowed and FullScreen mode, but FullScreen mode isn't fully implemented.

RenderFrame ( ) : void

Renders a new frame of animation. This is the entry point for drawing code and is required every time a new frame is to be drawn.

ResizeViewer ( ) : bool

Handles logic for resizing the game view

ScrollDown ( int pixels ) : int

Controls scrolling of the viewport around the world map.

ScrollLeft ( int pixels ) : int

Controls scrolling of the viewport around the world map.

ScrollRight ( int pixels ) : int

Controls scrolling of the viewport around the world map.

ScrollUp ( int pixels ) : int

Controls scrolling of the viewport around the world map.

SelectAnimalFromPoint ( Point p, bool selectThisAnimalOnly ) : void

Attempts to select a creature given the world offset point.

TerrariumGameView ( ) : System

Creates a new instance of the game view and initializes any properties.

UpdateWorld ( WorldVector worldVector ) : void

Updates the sprites controlled by the game view by providing a new world vector from the game engine.

Protected Methods

Method Description
OnMouseEnter ( EventArgs e ) : void

Overrides the OnMouseEnter event to provide custom cursor manipulation

OnMouseLeave ( EventArgs e ) : void

Overrides the OnMouseLeave event to provide custom cursor manipulation

OnMouseMove ( MouseEventArgs e ) : void

Overrides OnMouseMove to enable custom cursor rendering.

OnMouseUp ( MouseEventArgs e ) : void

Overrides OnMouseUp in order to enable creature selection.

OnPaint ( PaintEventArgs e ) : void

Overrides the Painting logic because painting will be handled using timers and DirectX. If the control is in design mode, then clear it because DirectX isn't available yet.

OnPaintBackground ( PaintEventArgs e ) : void

Don't paint the background when a background erase is requested. Hurts performance and causes flicker.

Private Methods

Method Description
CheckScroll ( ) : void

Computes whether scrolling should occur based on mouse location and hovering.

ClearBackground ( ) : void

Clear any background surfaces to black. This helps find rendering artifacts where portions of a scene aren't updated. Since the background is cleared to black, the portions not updated are clearly visible.

ComputeCursorRectangle ( ) : Rectangle
GetBoundsOfState ( OrganismBase.OrganismState orgState ) : Rectangle

Uses the bounding box computation methods to compute a box that can be printed within the graphics engine. This is used for debugging creature pathing.

InitOrganism ( OrganismBase.OrganismState orgState ) : void

Initializes a new organism state by computed and attaching a TerrariumSprite class that can be used to control on screen movement, animation skins, and selection.

InitTeleporter ( TeleportZone zone ) : void

Sets up the hack table with teleporter information. The hack table is used to quickly implement new types of sprites or implement sprites linked to immutable objects (like the teleporter).

InitializeComponent ( ) : void

Initialize Component

OnMiniMapUpdated ( Terrarium.Renderer.MiniMapUpdatedEventArgs e ) : void

Helper function for firing the MiniMapUpdated event whenever a new mini-map becomes available.

OnOrganismClicked ( OrganismClickedEventArgs e ) : void

Helper function for firing the OrganismClicked event whenever an organism is selected within the game view.

PaintBackground ( ) : void

Renders the Terrarium background image. Also renders plants on the background for static plant drawing to enable higher performance.

PaintCursor ( ) : void

Paints a custom cursor rather than the default windows cursors. Can be used to enable cursor animation, but in the current revision simply paints a custom cursor based on mouse location.

PaintMessage ( ) : void

Controls the rendering of textual messages to the Terrarium client screen. Since DrawText is invoked each time, this method is slow.

PaintSprites ( IGraphicsSurface surf, bool PlantsOnly ) : void

Paint sprites on the given surface. This method is the meat of the graphics engine. Normally, creatures are painted to the work surface using this method. To increase performance plants are rendered to the background surface only once every 10 frames. Lots of work happening in this function so either read through the code or examine the Terrarium Graphics Engine whitepaper for more information.

ReInitSurfaces ( ) : void

Reinitialize all surfaces after they have been lost. This method invokes the garbage collector to make sure that any COM references have been cleaned up, else surface renewal won't work correctly.

RenderTeleporter ( int lowZ, int highZ ) : void

Renders any teleporters that exist between the given z ordered locations.

ResetTerrarium ( ) : void

Resets the Terrarium and prepares it for a new world, without having to reboot the entire game.

TeleporterZIndex ( ) : int[]

ZIndexes the teleporters so they can be properly rendered on the screen.

Method Details

AddBackgroundSlide() public method

Used to change the background slide of the Terrarium. Only a single background slide can be added with this revision.
public AddBackgroundSlide ( ) : void
return void

AddComplexSizedSpriteSurface() public method

Add a complex sprite surface that takes advantage of sized sprites
public AddComplexSizedSpriteSurface ( string name, int xFrames, int yFrames ) : void
name string The name of the sprite sheet.
xFrames int The number of frames width wise.
yFrames int The number of frames height wise.
return void

AddComplexSpriteSurface() public method

Add a complex sprite surface given the number of frames.
public AddComplexSpriteSurface ( string name, int xFrames, int yFrames ) : void
name string The name of the sprite sheet.
xFrames int The number of frames width-wise.
yFrames int The number of frames height-wise.
return void

AddSpriteSurface() public method

Adds a generic 10frame by 40frame sprite surface that is compatible with creature animation.
public AddSpriteSurface ( string name ) : void
name string The name of the sprite sheet.
return void

CenterTo() public method

Controls scrolling of the viewport around the world map. Attempts to center the view to the defined point.
public CenterTo ( int xOffset, int yOffset ) : void
xOffset int X location to center to.
yOffset int Y location to center to.
return void

ClearProfiler() public method

Clear the profiler
public ClearProfiler ( ) : void
return void

CreateFullScreenSurfaces() public method

Creates the surfaces required for full screen operation.
public CreateFullScreenSurfaces ( ) : bool
return bool

CreateWindowedSurfaces() public method

Method used to create the necessary surfaces required for windowed mode.
public CreateWindowedSurfaces ( ) : bool
return bool

CreateWorld() public method

Tell the game view to create a new world and reset the rendering surfaces.
public CreateWorld ( int xPixels, int yPixels ) : Rectangle
xPixels int The number of world pixels
yPixels int The number of world pixels
return System.Drawing.Rectangle

InitializeGraphicEngine() public method

Initializes DirectDraw rendering APIs. The function can be called to initialize both Windowed and FullScreen mode, but FullScreen mode isn't fully implemented.
public InitializeGraphicEngine ( bool fullscreen ) : bool
fullscreen bool If true then fullscreen will be enabled.
return bool

OnMouseEnter() protected method

Overrides the OnMouseEnter event to provide custom cursor manipulation
protected OnMouseEnter ( EventArgs e ) : void
e System.EventArgs Null
return void

OnMouseLeave() protected method

Overrides the OnMouseLeave event to provide custom cursor manipulation
protected OnMouseLeave ( EventArgs e ) : void
e System.EventArgs Null
return void

OnMouseMove() protected method

Overrides OnMouseMove to enable custom cursor rendering.
protected OnMouseMove ( MouseEventArgs e ) : void
e MouseEventArgs
return void

OnMouseUp() protected method

Overrides OnMouseUp in order to enable creature selection.
protected OnMouseUp ( MouseEventArgs e ) : void
e MouseEventArgs
return void

OnPaint() protected method

Overrides the Painting logic because painting will be handled using timers and DirectX. If the control is in design mode, then clear it because DirectX isn't available yet.
protected OnPaint ( PaintEventArgs e ) : void
e PaintEventArgs Graphics context objects
return void

OnPaintBackground() protected method

Don't paint the background when a background erase is requested. Hurts performance and causes flicker.
protected OnPaintBackground ( PaintEventArgs e ) : void
e PaintEventArgs Graphics context objects
return void

RenderFrame() public method

Renders a new frame of animation. This is the entry point for drawing code and is required every time a new frame is to be drawn.
public RenderFrame ( ) : void
return void

ResizeViewer() public method

Handles logic for resizing the game view
public ResizeViewer ( ) : bool
return bool

ScrollDown() public method

Controls scrolling of the viewport around the world map.
public ScrollDown ( int pixels ) : int
pixels int The number of pixels to scroll down
return int

ScrollLeft() public method

Controls scrolling of the viewport around the world map.
public ScrollLeft ( int pixels ) : int
pixels int The number of pixels to scroll left
return int

ScrollRight() public method

Controls scrolling of the viewport around the world map.
public ScrollRight ( int pixels ) : int
pixels int The number of pixels to scroll right
return int

ScrollUp() public method

Controls scrolling of the viewport around the world map.
public ScrollUp ( int pixels ) : int
pixels int The number of pixels to scroll up
return int

SelectAnimalFromPoint() public method

Attempts to select a creature given the world offset point.
public SelectAnimalFromPoint ( Point p, bool selectThisAnimalOnly ) : void
p Point Point to check for creature intersection.
selectThisAnimalOnly bool Determines if this creature should be added to the selection
return void

TerrariumGameView() public method

Creates a new instance of the game view and initializes any properties.
public TerrariumGameView ( ) : System
return System

UpdateWorld() public method

Updates the sprites controlled by the game view by providing a new world vector from the game engine.
public UpdateWorld ( WorldVector worldVector ) : void
worldVector Terrarium.Game.WorldVector The new world vector of organisms.
return void

Property Details

_backBufferSurface protected_oe property

The back buffer surface used with the picture box.
protected IGraphicsSurface _backBufferSurface
return IGraphicsSurface

_screenSurface protected_oe property

The primary screen surface for the picture box.
protected IGraphicsSurface _screenSurface
return IGraphicsSurface