PVSnesLib  4.6.0
Documentation to code in C or ASM for the Nintendo SNES
Loading...
Searching...
No Matches
gamestates.h File Reference

snes game states engine functionality. More...

#include <snes/snestypes.h>

Go to the source code of this file.

Macros

#define GSTA_MAX   16
 
#define gstaInitEngine()   GSTATESINIT
 Initialize all the states of the game with type functions (initialize, update) Your code must define GSTATESINIT as.
 

Functions

void gstaInitFunctions (u8 staidx, void *initfct, void *updfct)
 Initialize the game state type functions (initialize, update) of a specific state (intro, menu, etc)
 
void gstaProcess (void)
 call game state engine for all states (gstaSetState must be called before)
 
void gstaSetState (u8 staidx)
 Change the current game state to a new one.
 

Detailed Description

snes game states engine functionality.

16 maximum game states managed by engine

Macro Definition Documentation

◆ GSTA_MAX

#define GSTA_MAX   16

total number of states in the game

◆ gstaInitEngine

gstaInitEngine ( )    GSTATESINIT

Initialize all the states of the game with type functions (initialize, update) Your code must define GSTATESINIT as.

#undef GSTATESINIT
#define GSTATESINIT \
_GSTATEINIT(idofstate1) \
...
_GSTATEINIT(idofstaten) \
GSTATE_DEF_END

It must also define enumeration named STATESDEF in an include file available for all c file using state engine

#define GSTATESDEF \
_GSTATEDEF(idofstate1) \
...
_GSTATEDEF(idofstaten) \
GSTATE_DEF_END
typedef enum {
GSTATESDEF
N_GSTATES
} GSTATES;

The declarations must be after the include of pvsneslib main include <snes.h>

Function Documentation

◆ gstaInitFunctions()

gstaInitFunctions ( u8  staidx,
void *  initfct,
void *  updfct 
)

Initialize the game state type functions (initialize, update) of a specific state (intro, menu, etc)

Parameters
staidxThe idx of game state depending of the game (intro, menu, etc...)
initfctThe address of the function when we init the state
updfctThe address of the function when we update the state (need to be called once per frame)

init and update functions have no parameters

functions name must begin with staini_<statename> and staupd_<statename>

◆ gstaSetState()

gstaSetState ( u8  staidx)

Change the current game state to a new one.

Parameters
staidxThe idx of game states depending of the game