CorsixTH engine (the C++ part)
Open source implementation of Theme Hospital
Loading...
Searching...
No Matches
Classes | Public Member Functions | List of all members
animation_manager Class Reference

Theme Hospital sprite animation manager. More...

#include <th_gfx.h>

Public Member Functions

 animation_manager ()=default
 
void set_sprite_sheet (sprite_sheet *pSpriteSheet)
 
bool load_from_th_file (const uint8_t *pStartData, size_t iStartDataLength, const uint8_t *pFrameData, size_t iFrameDataLength, const uint8_t *pListData, size_t iListDataLength, const uint8_t *pElementData, size_t iElementDataLength)
 Load original animations.
 
void set_canvas (render_target *pCanvas)
 Set the video target.
 
bool load_custom_animations (const uint8_t *pData, size_t iDataLength)
 Load free animations.
 
size_t get_animation_count () const
 Get the total number of animations.
 
size_t get_frame_count () const
 Get the total number of animation frames.
 
size_t get_first_frame (size_t iAnimation) const
 Get the index of the first frame of an animation.
 
size_t get_next_frame (size_t iFrame) const
 Get the index of the frame after a given frame.
 
void set_animation_alt_palette_map (size_t iAnimation, const uint8_t *pMap, uint32_t iAlt32)
 Set the palette remap data for an animation.
 
void draw_frame (render_target *pCanvas, size_t iFrame, const ::layers &oLayers, int iX, int iY, uint32_t iFlags, animation_effect patient_effect=animation_effect::none, size_t patient_effect_offset=0) const
 Draw an animation frame.
 
void get_frame_extent (size_t iFrame, const ::layers &oLayers, int *pMinX, int *pMaxX, int *pMinY, int *pMaxY, uint32_t iFlags) const
 
size_t get_frame_sound (size_t iFrame)
 
bool hit_test (size_t iFrame, const ::layers &oLayers, int iX, int iY, uint32_t iFlags, int iTestX, int iTestY) const
 
bool set_frame_primary_marker (size_t iFrame, int iX, int iY)
 
bool set_frame_secondary_marker (size_t iFrame, int iX, int iY)
 
bool get_frame_primary_marker (size_t iFrame, int *pX, int *pY)
 
bool get_frame_secondary_marker (size_t iFrame, int *pX, int *pY)
 
const animation_start_framesget_named_animations (std::string_view sName, int iTilesize) const
 Retrieve a custom animation by name and tile size.
 
void tick ()
 Notified every world tick to allow tracking rate of game time passage.
 

Detailed Description

Theme Hospital sprite animation manager.

An animation manager takes a sprite sheet and four animation information files, and uses them to draw animation frames and provide information about the animations.

Constructor & Destructor Documentation

◆ animation_manager()

animation_manager::animation_manager ( )
default

Member Function Documentation

◆ draw_frame()

void animation_manager::draw_frame ( render_target pCanvas,
size_t  iFrame,
const ::layers oLayers,
int  iX,
int  iY,
uint32_t  iFlags,
animation_effect  patient_effect = animation_effect::none,
size_t  patient_effect_offset = 0 
) const

Draw an animation frame.

Parameters
pCanvasThe render target to draw onto.
iFrameThe frame index to draw (should be in range [0, getFrameCount() - 1])
oLayersInformation to decide what to draw on each layer. An animation is comprised of up to thirteen layers, numbered 0 through 12. Some animations will have different options for what to render on each layer. For example, patient animations generally have the different options on layer 1 as different clothes, so if layer 1 is set to the value 0, they may have their default clothes, and if set to the value 2 or 4 or 6, they may have other clothes. Play with the AnimView tool for a better understanding of layers, though note that while it can draw more than one option on each layer, this class can only draw a single option for each layer.
iXThe screen position to use as the animation X origin.
iYThe screen position to use as the animation Y origin.
iFlagsZero or more THDrawFlags flags.
patient_effectThe animation effect to apply to the patient.
patient_effect_offsetThe number of ticks to offset the effect animation by.

◆ get_animation_count()

size_t animation_manager::get_animation_count ( ) const

Get the total number of animations.

◆ get_first_frame()

size_t animation_manager::get_first_frame ( size_t  iAnimation) const

Get the index of the first frame of an animation.

◆ get_frame_count()

size_t animation_manager::get_frame_count ( ) const

Get the total number of animation frames.

◆ get_frame_extent()

void animation_manager::get_frame_extent ( size_t  iFrame,
const ::layers oLayers,
int pMinX,
int pMaxX,
int pMinY,
int pMaxY,
uint32_t  iFlags 
) const

◆ get_frame_primary_marker()

bool animation_manager::get_frame_primary_marker ( size_t  iFrame,
int pX,
int pY 
)

◆ get_frame_secondary_marker()

bool animation_manager::get_frame_secondary_marker ( size_t  iFrame,
int pX,
int pY 
)

◆ get_frame_sound()

size_t animation_manager::get_frame_sound ( size_t  iFrame)

◆ get_named_animations()

const animation_start_frames & animation_manager::get_named_animations ( std::string_view  sName,
int  iTilesize 
) const

Retrieve a custom animation by name and tile size.

Parameters
sNameName of the animation.
iTilesizeTile size of the animation.
Returns
A set starting frames for the queried animation.

◆ get_next_frame()

size_t animation_manager::get_next_frame ( size_t  iFrame) const

Get the index of the frame after a given frame.

To draw an animation frame by frame, call get_first_frame() to get the index of the first frame, and then keep on calling get_next_frame() using the most recent return value from get_next_frame() or get_first_frame().

◆ hit_test()

bool animation_manager::hit_test ( size_t  iFrame,
const ::layers oLayers,
int  iX,
int  iY,
uint32_t  iFlags,
int  iTestX,
int  iTestY 
) const

◆ load_custom_animations()

bool animation_manager::load_custom_animations ( const uint8_t *  pData,
size_t  iDataLength 
)

Load free animations.

Parameters
pDataStart of the loaded data.
iDataLengthLength of the loaded data.
Returns
Loading was successful.

◆ load_from_th_file()

bool animation_manager::load_from_th_file ( const uint8_t *  pStartData,
size_t  iStartDataLength,
const uint8_t *  pFrameData,
size_t  iFrameDataLength,
const uint8_t *  pListData,
size_t  iListDataLength,
const uint8_t *  pElementData,
size_t  iElementDataLength 
)

Load original animations.

set_sprite_sheet() must be called before calling this.

Parameters
pStartDataAnimation first frame indices (e.g. VSTART-1.ANI)
iStartDataLengthLength of pStartData.
pFrameDataFrame details (e.g. VFRA-1.ANI)
iFrameDataLengthLength of pFrameData
pListDataElement indices list (e.g. VLIST-1.ANI)
iListDataLengthLength of pListData
pElementDataElement details (e.g. VELE-1.ANI)
iElementDataLengthLength of pElementData
Returns
Loading was successful.

◆ set_animation_alt_palette_map()

void animation_manager::set_animation_alt_palette_map ( size_t  iAnimation,
const uint8_t *  pMap,
uint32_t  iAlt32 
)

Set the palette remap data for an animation.

This sets the palette remap data for every single sprite used by the given animation. If the animation (or any of its sprites) are drawn using the thdf_alt_palette flag, then palette indices will be mapped to new palette indices by the 256 byte array pMap. This is typically used to draw things in different colours or in greyscale.

◆ set_canvas()

void animation_manager::set_canvas ( render_target pCanvas)

Set the video target.

Parameters
pCanvasVideo surface to use.

◆ set_frame_primary_marker()

bool animation_manager::set_frame_primary_marker ( size_t  iFrame,
int  iX,
int  iY 
)

◆ set_frame_secondary_marker()

bool animation_manager::set_frame_secondary_marker ( size_t  iFrame,
int  iX,
int  iY 
)

◆ set_sprite_sheet()

void animation_manager::set_sprite_sheet ( sprite_sheet pSpriteSheet)

◆ tick()

void animation_manager::tick ( )

Notified every world tick to allow tracking rate of game time passage.


The documentation for this class was generated from the following files: