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
Afficher le fichier Open project: eugeniomiro/Terrarium Class Usage Examples

Protected Properties

Свойство Type Description
_backBufferSurface IGraphicsSurface
_screenSurface IGraphicsSurface

Méthodes publiques

Méthode 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.

Méthodes protégées

Méthode 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

Méthode 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 méthode

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

AddComplexSizedSpriteSurface() public méthode

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.
Résultat void

AddComplexSpriteSurface() public méthode

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.
Résultat void

AddSpriteSurface() public méthode

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.
Résultat void

CenterTo() public méthode

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.
Résultat void

ClearProfiler() public méthode

Clear the profiler
public ClearProfiler ( ) : void
Résultat void

CreateFullScreenSurfaces() public méthode

Creates the surfaces required for full screen operation.
public CreateFullScreenSurfaces ( ) : bool
Résultat bool

CreateWindowedSurfaces() public méthode

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

CreateWorld() public méthode

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
Résultat System.Drawing.Rectangle

InitializeGraphicEngine() public méthode

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.
Résultat bool

OnMouseEnter() protected méthode

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

OnMouseLeave() protected méthode

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

OnMouseMove() protected méthode

Overrides OnMouseMove to enable custom cursor rendering.
protected OnMouseMove ( MouseEventArgs e ) : void
e MouseEventArgs
Résultat void

OnMouseUp() protected méthode

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

OnPaint() protected méthode

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
Résultat void

OnPaintBackground() protected méthode

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
Résultat void

RenderFrame() public méthode

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
Résultat void

ResizeViewer() public méthode

Handles logic for resizing the game view
public ResizeViewer ( ) : bool
Résultat bool

ScrollDown() public méthode

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

ScrollLeft() public méthode

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

ScrollRight() public méthode

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

ScrollUp() public méthode

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

SelectAnimalFromPoint() public méthode

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
Résultat void

TerrariumGameView() public méthode

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

UpdateWorld() public méthode

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.
Résultat void

Property Details

_backBufferSurface protected_oe property

The back buffer surface used with the picture box.
protected IGraphicsSurface _backBufferSurface
Résultat IGraphicsSurface

_screenSurface protected_oe property

The primary screen surface for the picture box.
protected IGraphicsSurface _screenSurface
Résultat IGraphicsSurface