minor changes to handler and removed some comments from engine
This commit is contained in:
parent
bd7e3212da
commit
585768f33d
3 changed files with 25 additions and 74 deletions
|
|
@ -5,7 +5,7 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "arc/std/bool.h"
|
||||
#include "arc/std/vector.h"
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
|
|
@ -13,18 +13,6 @@ extern "C" {
|
|||
*/
|
||||
typedef struct ARC_Handler ARC_Handler;
|
||||
|
||||
/**
|
||||
* @brief data comparison function ptr
|
||||
*
|
||||
* @note this is used for comparison within vectors
|
||||
*
|
||||
* @param a first data struct
|
||||
* @param b second data struct
|
||||
*
|
||||
* @return 0 when a == b
|
||||
*/
|
||||
typedef ARC_Bool (* ARC_Handler_CompareDataFn)(void *a, void *b);
|
||||
|
||||
/**
|
||||
* @brief a function that will take iterated data
|
||||
*
|
||||
|
|
@ -32,22 +20,13 @@ typedef ARC_Bool (* ARC_Handler_CompareDataFn)(void *a, void *b);
|
|||
*/
|
||||
typedef void (* ARC_Handler_DataFn)(void *data);
|
||||
|
||||
/**
|
||||
* @brief a function that will be used during destruction of trash vector
|
||||
*
|
||||
* @param data data that is being destroyed from trash
|
||||
*/
|
||||
typedef void (* ARC_Handler_CleanDataFn)(void *data);
|
||||
|
||||
/**
|
||||
* @brief creates ARC_Handler type
|
||||
*
|
||||
* @param config ARC_Handler to initialize
|
||||
* @param compareFn function to remove handler data
|
||||
* @param cleanFn function to clean data in handler
|
||||
* can be null
|
||||
* @param destroyDataFn function to clean data in handler, can be null
|
||||
*/
|
||||
void ARC_Handler_Create(ARC_Handler **handler, ARC_Handler_CompareDataFn *compareFn, ARC_Handler_CleanDataFn cleanFn);
|
||||
void ARC_Handler_Create(ARC_Handler **handler, ARC_Vector_DestroyDataFn *destroyDataFn);
|
||||
|
||||
/**
|
||||
* @brief destroyes ARC_Handler type
|
||||
|
|
@ -64,18 +43,6 @@ void ARC_Handler_Destroy(ARC_Handler *handler);
|
|||
*/
|
||||
void ARC_Handler_Add(ARC_Handler *handler, void *data);
|
||||
|
||||
/**
|
||||
* @brief remove from handler
|
||||
*
|
||||
* @note the data that is removed is stored in a trash vector
|
||||
* the ARC_Handler_Clean function must be called clean the trash vector
|
||||
* the trash vector is to make sure a state is not deleted while being run
|
||||
*
|
||||
* @param handler ARC_Handler to remove from
|
||||
* @param data data that is being removed
|
||||
*/
|
||||
void ARC_Handler_Remove(ARC_Handler *handler, void *data);
|
||||
|
||||
/**
|
||||
* @brief remove from handler
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
#include "arc/engine/engine.h"
|
||||
|
||||
//NOTE: some of this file is temporary, mostly to get smthn running so I can test out different ideas
|
||||
#include <stdlib.h>
|
||||
#include "arc/engine/state.h"
|
||||
#include "arc/graphics/window.h"
|
||||
#include "arc/graphics/renderer.h"
|
||||
|
|
@ -10,11 +9,10 @@
|
|||
#include "arc/std/bool.h"
|
||||
#include "arc/std/errno.h"
|
||||
#include "arc/std/handler.h"
|
||||
#include <stdlib.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
//TODO: remove this
|
||||
//#include <SDL.h>
|
||||
|
||||
void ARC_EngineData_HandlerDestroyStateFn(void *data){
|
||||
void ARC_EngineData_VectorDestroyStateFn(void *data){
|
||||
ARC_State_Destroy((ARC_State *)data);
|
||||
}
|
||||
|
||||
|
|
@ -27,8 +25,8 @@ void ARC_EngineData_Create(ARC_EngineData **data, ARC_Point windowSize){
|
|||
(*data)->mouse = NULL;
|
||||
(*data)->entitySystem = NULL;
|
||||
|
||||
//TODO: set the destroy callback
|
||||
ARC_Handler_Create(&((*data)->state), NULL, ARC_EngineData_HandlerDestroyStateFn);
|
||||
ARC_Vector_DestroyDataFn destroyDataFn = ARC_EngineData_VectorDestroyStateFn;
|
||||
ARC_Handler_Create(&((*data)->state), &destroyDataFn);
|
||||
|
||||
(*data)->dt = 0.0;
|
||||
(*data)->running = ARC_False;
|
||||
|
|
@ -69,13 +67,18 @@ void ARC_Engine_RunUncapped(ARC_EngineData *data){
|
|||
return;
|
||||
}
|
||||
|
||||
//double lastTime = 0, currentTime;
|
||||
//TODO: probably want to do this in a better way
|
||||
struct timeval currentTime;
|
||||
struct timeval lastTime;
|
||||
|
||||
gettimeofday(¤tTime, NULL);
|
||||
|
||||
lastTime = currentTime;
|
||||
|
||||
data->running = ARC_True;
|
||||
while(data->running){
|
||||
//currentTime = SDL_GetTicks();
|
||||
//data->dt = currentTime - lastTime;
|
||||
//lastTime = currentTime;
|
||||
data->dt = (lastTime.tv_sec - currentTime.tv_sec) + (lastTime.tv_usec - currentTime.tv_usec);
|
||||
lastTime = currentTime;
|
||||
|
||||
data->running = ARC_Input_Update(data->input);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,21 +1,17 @@
|
|||
#include "arc/std/handler.h"
|
||||
|
||||
#include "arc/std/errno.h"
|
||||
#include "arc/std/vector.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
struct ARC_Handler {
|
||||
ARC_Vector *data;
|
||||
ARC_Vector *trash;
|
||||
|
||||
ARC_Handler_CleanDataFn cleanfn;
|
||||
};
|
||||
|
||||
void ARC_Handler_Create(ARC_Handler **handler, ARC_Handler_CompareDataFn *compareFn, ARC_Handler_CleanDataFn cleanfn){
|
||||
void ARC_Handler_Create(ARC_Handler **handler, ARC_Vector_DestroyDataFn *destroyDataFn){
|
||||
*handler = (ARC_Handler *) malloc(sizeof(ARC_Handler));
|
||||
ARC_Vector_Create(&((*handler)->data), NULL, NULL);
|
||||
ARC_Vector_Create(&((*handler)->trash), compareFn, NULL);
|
||||
(*handler)->cleanfn = cleanfn;
|
||||
ARC_Vector_Create(&((*handler)->data) , NULL, NULL );
|
||||
ARC_Vector_Create(&((*handler)->trash), NULL, destroyDataFn);
|
||||
}
|
||||
|
||||
void ARC_Handler_Destroy(ARC_Handler *handler){
|
||||
|
|
@ -32,11 +28,6 @@ void ARC_Handler_Add(ARC_Handler *handler, void *data){
|
|||
ARC_Vector_Add(handler->data, data);
|
||||
}
|
||||
|
||||
void ARC_Handler_Remove(ARC_Handler *handler, void *data){
|
||||
ARC_Vector_Add(handler->trash, data);
|
||||
ARC_Vector_Remove(handler->data, data);
|
||||
}
|
||||
|
||||
void ARC_Handler_RemoveIndex(ARC_Handler *handler, uint32_t index){
|
||||
if(ARC_Vector_GetSize(handler->data) == 0){
|
||||
return;
|
||||
|
|
@ -54,23 +45,13 @@ void ARC_Handler_Iterate(ARC_Handler *handler, ARC_Handler_DataFn datafn){
|
|||
}
|
||||
|
||||
void ARC_Handler_Clear(ARC_Handler *handler){
|
||||
uint32_t zeroIndex = 0;
|
||||
while(ARC_Vector_GetSize(handler->data)){
|
||||
ARC_Handler_RemoveIndex(handler, zeroIndex);
|
||||
while(ARC_Vector_GetSize(handler->data) != 0){
|
||||
ARC_Handler_RemoveIndex(handler, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void ARC_Handler_Clean(ARC_Handler *handler){
|
||||
uint32_t i = 0;
|
||||
while(ARC_Vector_GetSize(handler->trash)){
|
||||
void *data = ARC_Vector_Get(handler->trash, i);
|
||||
|
||||
if(handler->cleanfn){
|
||||
handler->cleanfn(data);
|
||||
}
|
||||
|
||||
ARC_Vector_RemoveIndex(handler->trash, i);
|
||||
}
|
||||
ARC_Vector_Clear(handler->trash);
|
||||
}
|
||||
|
||||
uint32_t ARC_Handler_GetSize(ARC_Handler *handler){
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue