C# Класс 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.
Наследование: System.Windows.Forms.PictureBox
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
_backBufferSurface IGraphicsSurface
_screenSurface IGraphicsSurface

Открытые методы

Метод Описание
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.

Защищенные методы

Метод Описание
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.

Приватные методы

Метод Описание
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.

Описание методов

AddBackgroundSlide() публичный Метод

Used to change the background slide of the Terrarium. Only a single background slide can be added with this revision.
public AddBackgroundSlide ( ) : void
Результат void

AddComplexSizedSpriteSurface() публичный Метод

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.
Результат void

AddComplexSpriteSurface() публичный Метод

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.
Результат void

AddSpriteSurface() публичный Метод

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.
Результат void

CenterTo() публичный Метод

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.
Результат void

ClearProfiler() публичный Метод

Clear the profiler
public ClearProfiler ( ) : void
Результат void

CreateFullScreenSurfaces() публичный Метод

Creates the surfaces required for full screen operation.
public CreateFullScreenSurfaces ( ) : bool
Результат bool

CreateWindowedSurfaces() публичный Метод

Method used to create the necessary surfaces required for windowed mode.
public CreateWindowedSurfaces ( ) : bool
Результат bool

CreateWorld() публичный Метод

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
Результат System.Drawing.Rectangle

InitializeGraphicEngine() публичный Метод

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.
Результат bool

OnMouseEnter() защищенный Метод

Overrides the OnMouseEnter event to provide custom cursor manipulation
protected OnMouseEnter ( EventArgs e ) : void
e System.EventArgs Null
Результат void

OnMouseLeave() защищенный Метод

Overrides the OnMouseLeave event to provide custom cursor manipulation
protected OnMouseLeave ( EventArgs e ) : void
e System.EventArgs Null
Результат void

OnMouseMove() защищенный Метод

Overrides OnMouseMove to enable custom cursor rendering.
protected OnMouseMove ( MouseEventArgs e ) : void
e MouseEventArgs
Результат void

OnMouseUp() защищенный Метод

Overrides OnMouseUp in order to enable creature selection.
protected OnMouseUp ( MouseEventArgs e ) : void
e MouseEventArgs
Результат void

OnPaint() защищенный Метод

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
Результат void

OnPaintBackground() защищенный Метод

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
Результат void

RenderFrame() публичный Метод

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
Результат void

ResizeViewer() публичный Метод

Handles logic for resizing the game view
public ResizeViewer ( ) : bool
Результат bool

ScrollDown() публичный Метод

Controls scrolling of the viewport around the world map.
public ScrollDown ( int pixels ) : int
pixels int The number of pixels to scroll down
Результат int

ScrollLeft() публичный Метод

Controls scrolling of the viewport around the world map.
public ScrollLeft ( int pixels ) : int
pixels int The number of pixels to scroll left
Результат int

ScrollRight() публичный Метод

Controls scrolling of the viewport around the world map.
public ScrollRight ( int pixels ) : int
pixels int The number of pixels to scroll right
Результат int

ScrollUp() публичный Метод

Controls scrolling of the viewport around the world map.
public ScrollUp ( int pixels ) : int
pixels int The number of pixels to scroll up
Результат int

SelectAnimalFromPoint() публичный Метод

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
Результат void

TerrariumGameView() публичный Метод

Creates a new instance of the game view and initializes any properties.
public TerrariumGameView ( ) : System
Результат System

UpdateWorld() публичный Метод

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.
Результат void

Описание свойств

_backBufferSurface защищенное свойство

The back buffer surface used with the picture box.
protected IGraphicsSurface _backBufferSurface
Результат IGraphicsSurface

_screenSurface защищенное свойство

The primary screen surface for the picture box.
protected IGraphicsSurface _screenSurface
Результат IGraphicsSurface