Loading...
Searching...
No Matches
engine.c File Reference
`#include "arc/engine/engine.h"`
`#include <stdlib.h>`
`#include "arc/engine/state.h"`
`#include "arc/graphics/window.h"`
`#include "arc/graphics/renderer.h"`
`#include "arc/input/mouse.h"`
`#include "arc/input/keyboard.h"`
`#include "arc/std/bool.h"`
`#include "arc/std/errno.h"`
`#include "arc/std/handler.h"`

Go to the source code of this file.

## Functions

void | ARC_EngineData_Create (ARC_EngineData **data, ARC_Handler_CleanDataFn cleanFn, ARC_Point windowSize)
void | ARC_EngineData_Destroy (ARC_EngineData *data)
void | ARC_Engine_RunUncapped (ARC_EngineData *data)
| runs ARC_Engine with an uncapped framerate

## Function Documentation

## ARC_Engine_RunUncapped()

void ARC_Engine_RunUncapped | ( | ARC_EngineData * | data | ) |

runs ARC_Engine with an uncapped framerate

Note
  data must be created before this function
  data should be destroyed after this function

Parameters

  data | engine data that will be used

Definition at line 59 of file engine.c.

{
if(arc_errno){
return;
}
//double lastTime = 0, currentTime;
data->running = ARC_True;
while(data->running){
//currentTime = SDL_GetTicks();
//data->dt = currentTime - lastTime;
//lastTime = currentTime;
data->running = ARC_Input_Update(data->input);
ARC_Handler_Clean(data->state);
ARC_Handler_Iterate(data->state, ARC_State_Update);
ARC_Renderer_Clear(data->renderer);
ARC_Handler_Iterate(data->state, ARC_State_Render);
ARC_Renderer_Render(data->renderer);
}
}
ARC_True
#define ARC_True
Definition bool.h:11
arc_errno
int32_t arc_errno
Definition errno.c:5
ARC_Handler_Iterate
void ARC_Handler_Iterate(ARC_Handler *handler, ARC_Handler_DataFn datafn)
calls provided function on each element in handler
Definition handler.c:50
ARC_Handler_Clean
void ARC_Handler_Clean(ARC_Handler *handler)
clears trash from handler
Definition handler.c:63
ARC_Renderer_Clear
void ARC_Renderer_Clear(ARC_Renderer *renderer)
Definition renderer.c:32
ARC_Renderer_Render
void ARC_Renderer_Render(ARC_Renderer *renderer)
renders the renderer
Definition renderer.c:39
ARC_Input_Update
ARC_Bool ARC_Input_Update(ARC_Input *input)
Definition input.c:27
ARC_State_Render
void ARC_State_Render(void *data)
Definition state.c:8
ARC_State_Update
void ARC_State_Update(void *data)
Definition state.c:4
ARC_EngineData::input
ARC_Input * input
Definition engine.h:21
ARC_EngineData::running
ARC_Bool running
Definition engine.h:26
ARC_EngineData::state
ARC_Handler * state
Definition engine.h:20
ARC_EngineData::renderer
ARC_Renderer * renderer
Definition engine.h:19

References arc_errno, ARC_Handler_Clean(), ARC_Handler_Iterate(), ARC_Input_Update(), ARC_Renderer_Clear(), ARC_Renderer_Render(), ARC_State_Render(), ARC_State_Update(), ARC_True, ARC_EngineData::input, ARC_EngineData::renderer, ARC_EngineData::running, and ARC_EngineData::state.

## ARC_EngineData_Create()

void ARC_EngineData_Create | ( | ARC_EngineData ** | data,
|  | ARC_Handler_CleanDataFn | cleanFn,
|  | ARC_Point | windowSize )

@breif creates an ARC_EngineData type to be used when running an ARC_Engine

Parameters

  data | the ARC_EngineData to create
  cleanFn | the state cleanup function
  windowSIze | the size of window to create passed as an ARC_Point

Definition at line 17 of file engine.c.

{
*data = (ARC_EngineData *)malloc(sizeof(ARC_EngineData));
(*data)->window = NULL;
(*data)->renderer = NULL;
(*data)->input = NULL;
(*data)->keyboard = NULL;
(*data)->mouse = NULL;
//TODO: set the destroy callback
ARC_Handler_Create(&((*data)->state), NULL, cleanFn);
(*data)->dt = 0.0;
(*data)->running = ARC_False;
(*data)->windowSize = windowSize;
ARC_WindowInfo windowInfo = (ARC_WindowInfo){ "title", (*data)->windowSize.x, (*data)->windowSize.y };
ARC_Window_Create(&((*data)->window), &windowInfo);
if(arc_errno){
free(data);
return;
}
ARC_Renderer_CreateWithEngineData(&((*data)->renderer), *data);
if(arc_errno){
ARC_Window_Destroy((*data)->window);
free(data);
}
ARC_Input_CreateWithEngineData(&((*data)->input), *data);
(*data)->keyboard = ARC_Input_GetKeyboard((*data)->input);
(*data)->mouse = ARC_Input_GetMouse((*data)->input);
}
ARC_False
#define ARC_False
Definition bool.h:12
ARC_Handler_Create
void ARC_Handler_Create(ARC_Handler **handler, ARC_Handler_CompareDataFn *compareFn, ARC_Handler_CleanDataFn cleanFn)
creates ARC_Handler type
Definition handler.c:14
ARC_Renderer_CreateWithEngineData
void ARC_Renderer_CreateWithEngineData(ARC_Renderer **renderer, ARC_EngineData *data)
creates ARC_Renderer type with ARC_EngineData
Definition renderer.c:10
ARC_Window_Create
void ARC_Window_Create(ARC_Window **window, ARC_WindowInfo *info)
creates ARC_Window type
Definition window.c:7
ARC_WindowInfo
struct ARC_WindowInfo ARC_WindowInfo
ARC_Window_Destroy
void ARC_Window_Destroy(ARC_Window *window)
destroys ARC_Window type
Definition window.c:29
ARC_Input_GetKeyboard
ARC_Keyboard * ARC_Input_GetKeyboard(ARC_Input *input)
Definition input.c:39
ARC_Input_GetMouse
ARC_Mouse * ARC_Input_GetMouse(ARC_Input *input)
Definition input.c:43
ARC_Input_CreateWithEngineData
void ARC_Input_CreateWithEngineData(ARC_Input **input, ARC_EngineData *data)
Definition input.c:10
ARC_EngineData
Definition engine.h:17
ARC_EngineData::window
ARC_Window * window
Definition engine.h:18
ARC_WindowInfo
Definition window.h:18

References arc_errno, ARC_False, ARC_Handler_Create(), ARC_Input_CreateWithEngineData(), ARC_Input_GetKeyboard(), ARC_Input_GetMouse(), ARC_Renderer_CreateWithEngineData(), ARC_Window_Create(), ARC_Window_Destroy(), and ARC_EngineData::window.

## ARC_EngineData_Destroy()

void ARC_EngineData_Destroy | ( | ARC_EngineData * | data | ) |

@breif destroys an ARC_EngineData type

Parameters

  data | the ARC_EngineData to destroy

Definition at line 51 of file engine.c.

{
ARC_Mouse_Destroy(data->mouse);
ARC_Keyboard_Destroy(data->keyboard);
ARC_Renderer_Destroy(data->renderer);
ARC_Window_Destroy(data->window);
ARC_Handler_Destroy(data->state);
}
ARC_Handler_Destroy
void ARC_Handler_Destroy(ARC_Handler *handler)
destroyes ARC_Handler type
Definition handler.c:21
ARC_Renderer_Destroy
void ARC_Renderer_Destroy(ARC_Renderer *renderer)
destroys ARC_Renderer type
Definition renderer.c:28
ARC_Keyboard_Destroy
void ARC_Keyboard_Destroy(ARC_Keyboard *keyboard)
Definition keyboard.c:23
ARC_Mouse_Destroy
void ARC_Mouse_Destroy(ARC_Mouse *mouse)
Definition mouse.c:31
ARC_EngineData::keyboard
ARC_Keyboard * keyboard
Definition engine.h:23
ARC_EngineData::mouse
ARC_Mouse * mouse
Definition engine.h:22

References ARC_Handler_Destroy(), ARC_Keyboard_Destroy(), ARC_Mouse_Destroy(), ARC_Renderer_Destroy(), ARC_Window_Destroy(), ARC_EngineData::keyboard, ARC_EngineData::mouse, ARC_EngineData::renderer, ARC_EngineData::state, and ARC_EngineData::window.