SDLGameEngine

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

Data Structures | Functions | Variables

# SgeGameState

Game states and event handlers. More...

## Data Structures
struct | SGEGAMESTATEMANAGER
struct | SGEGAMESTATE
## Functions
SGEGAMESTATEMANAGER * | sgeGameStateManagerNew (void)
| Create a new state manager.
int | sgeGameStateManagerChange (SGEGAMESTATEMANAGER *manager, SGEGAMESTATE *next_state)
| Change to a new state.
void | sgeGameStateManagerRun (SGEGAMESTATEMANAGER *manager, int fps)
| Run the game with the current states, redrawing at certain frames per second.
void | sgeGameStateManagerQuit (SGEGAMESTATEMANAGER *manager)
| Quit the game state manager.
SGEGAMESTATE * | sgeGameStateNew (void)
| Create new game state.
## Variables
void * | SGEGAMESTATE::data
| A pointer to your data.
void(* | SGEGAMESTATE::onRedraw )(struct _SGEGAMESTATE *state)
| A function pointer to the states redraw function.
int(* | SGEGAMESTATE::onKeyDown )(struct _SGEGAMESTATE *state, SGEEVENT *event)
| (optional) A function pointer to the states key down handler
int(* | SGEGAMESTATE::onKeyUp )(struct _SGEGAMESTATE *state, SGEEVENT *event)
| (optional) A function pointer to the states key up handler
int(* | SGEGAMESTATE::onJoystickButtonDown )(struct _SGEGAMESTATE *state, SGEEVENT *event)
| (optional) A function pointer to the states joystick button down handler
int(* | SGEGAMESTATE::onJoystickButtonUp )(struct _SGEGAMESTATE *state, SGEEVENT *event)
| (optional) A function pointer to the states joystick button up handler
void(* | SGEGAMESTATE::onJoystickMove )(struct _SGEGAMESTATE *state, SGEEVENT *event)
| (optional) A function pointer to the states joystick move handler
void(* | SGEGAMESTATE::onMouseDown )(struct _SGEGAMESTATE *state, SGEEVENT *event)
| (optional) A function pointer to the states mouse button down handler
void(* | SGEGAMESTATE::onMouseUp )(struct _SGEGAMESTATE *state, SGEEVENT *event)
| (optional) A function pointer to the states mouse button up handler
void(* | SGEGAMESTATE::onMouseMove )(struct _SGEGAMESTATE *state, SGEEVENT *event)
| (optional) A function pointer to the states mouse move handler
int(* | SGEGAMESTATE::onStateChange )(struct _SGEGAMESTATE *state, struct _SGEGAMESTATE *previous)
| (optional) A function pointer to a state change handler

## Detailed Description

Game states and event handlers.

Split your game into single states to switch between.

Also provides event callbacks for handling user input.

## Function Documentation

int sgeGameStateManagerChange | ( | SGEGAMESTATEMANAGER * | manager,
|  | SGEGAMESTATE * | next_state
| ) |  |

Change to a new state.

Parameters:

  manager | The game state manager
  next_state | The SGEGAMESTATE to switch to

Definition at line 31 of file sgegamestate.c.

void sgeGameStateManagerRun | ( | SGEGAMESTATEMANAGER * | manager,
|  | int | fps
| ) |  |

Run the game with the current states, redrawing at certain frames per second.

Parameters:

  manager | The game state manager
  fps | The frames per seconds the game should run

Definition at line 43 of file sgegamestate.c.

SGEGAMESTATE* sgeGameStateNew | ( | void |  | ) |

Create new game state.

The sge game state struct is given to all function callbacks to enable them to call the manager and get its data.

It needs at least a onRedraw function, the rest of the callbacks are optional.

Definition at line 19 of file sgegamestate.c.

## Variable Documentation

int(* SGEGAMESTATE::onJoystickButtonDown)(struct _SGEGAMESTATE *state, SGEEVENT *event)`[inherited]`

(optional) A function pointer to the states joystick button down handler

Parameters:

  state | The current state
  event | The current event object

Returns:
  EVENT_HANDLED or EVENT_UNHANDLED, depending if the handler did or did not handle the event

If the handler did not handle the event, the event is passed on to the gamepad event system.

See also:
  SgeEvent

Definition at line 96 of file sgegamestate.h.

int(* SGEGAMESTATE::onJoystickButtonUp)(struct _SGEGAMESTATE *state, SGEEVENT *event)`[inherited]`

(optional) A function pointer to the states joystick button up handler

Parameters:

  state | The current state
  event | The current event object

Returns:
  EVENT_HANDLED or EVENT_UNHANDLED, depending if the handler did or did not handle the event

If the handler did not handle the event, the event is passed on to the gamepad event system.

See also:
  SgeEvent

Definition at line 106 of file sgegamestate.h.

void(* SGEGAMESTATE::onJoystickMove)(struct _SGEGAMESTATE *state, SGEEVENT *event)`[inherited]`

(optional) A function pointer to the states joystick move handler

Parameters:

  state | The current state
  event | The current event object

Definition at line 113 of file sgegamestate.h.

int(* SGEGAMESTATE::onKeyDown)(struct _SGEGAMESTATE *state, SGEEVENT *event)`[inherited]`

(optional) A function pointer to the states key down handler

Parameters:

  state | The current state
  event | The current event object

Returns:
  EVENT_HANDLED or EVENT_UNHANDLED, depending if the handler did or did not handle the event

If the handler did not handle the event, the event is passed on to the gamepad event system.

See also:
  SgeEvent

Definition at line 76 of file sgegamestate.h.

int(* SGEGAMESTATE::onKeyUp)(struct _SGEGAMESTATE *state, SGEEVENT *event)`[inherited]`

(optional) A function pointer to the states key up handler

Parameters:

  state | The current state
  event | The current event object

Returns:
  EVENT_HANDLED or EVENT_UNHANDLED, depending if the handler did or did not handle the event

If the handler did not handle the event, the event is passed on to the gamepad event system.

See also:
  SgeEvent

Definition at line 86 of file sgegamestate.h.

void(* SGEGAMESTATE::onMouseDown)(struct _SGEGAMESTATE *state, SGEEVENT *event)`[inherited]`

(optional) A function pointer to the states mouse button down handler

Parameters:

  state | The current state
  event | The current event object

Definition at line 120 of file sgegamestate.h.

void(* SGEGAMESTATE::onMouseMove)(struct _SGEGAMESTATE *state, SGEEVENT *event)`[inherited]`

(optional) A function pointer to the states mouse move handler

Parameters:

  state | The current state
  event | The current event object

Definition at line 134 of file sgegamestate.h.

void(* SGEGAMESTATE::onMouseUp)(struct _SGEGAMESTATE *state, SGEEVENT *event)`[inherited]`

(optional) A function pointer to the states mouse button up handler

Parameters:

  state | The current state
  event | The current event object

Definition at line 127 of file sgegamestate.h.

void(* SGEGAMESTATE::onRedraw)(struct _SGEGAMESTATE *state)`[inherited]`

A function pointer to the states redraw function.

Parameters:

  state | The current state

Definition at line 66 of file sgegamestate.h.

int(* SGEGAMESTATE::onStateChange)(struct _SGEGAMESTATE *state, struct _SGEGAMESTATE *previous)`[inherited]`

(optional) A function pointer to a state change handler

Parameters:

  state | The current state
  event | The current event object

Returns:
  1 or 0, 1 = state changed worked, 0 = state change failed (must be handled by the state changing function)

Definition at line 142 of file sgegamestate.h.

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines