removed pointless pointers in rectange, reset background clear color, fixed entity, and added some state functions
This commit is contained in:
parent
dd1f3ca3e0
commit
bd7e3212da
12 changed files with 161 additions and 86 deletions
|
|
@ -12,15 +12,17 @@ extern "C" {
|
|||
#include "arc/input/keyboard.h"
|
||||
#include "arc/math/point.h"
|
||||
#include "arc/std/bool.h"
|
||||
#include "arc/std/entity.h"
|
||||
#include "arc/std/handler.h"
|
||||
|
||||
typedef struct ARC_EngineData {
|
||||
ARC_Window *window;
|
||||
ARC_Renderer *renderer;
|
||||
ARC_Handler *state;
|
||||
ARC_Input *input;
|
||||
ARC_Mouse *mouse;
|
||||
ARC_Keyboard *keyboard;
|
||||
ARC_Window *window;
|
||||
ARC_Renderer *renderer;
|
||||
ARC_Handler *state;
|
||||
ARC_Input *input;
|
||||
ARC_Mouse *mouse;
|
||||
ARC_Keyboard *keyboard;
|
||||
ARC_EntitySystem *entitySystem;
|
||||
|
||||
double dt;
|
||||
ARC_Bool running;
|
||||
|
|
@ -34,7 +36,7 @@ typedef struct ARC_EngineData {
|
|||
* @param cleanFn the state cleanup function
|
||||
* @param windowSIze the size of window to create passed as an ARC_Point
|
||||
*/
|
||||
void ARC_EngineData_Create(ARC_EngineData **data, ARC_Handler_CleanDataFn cleanFn, ARC_Point windowSize);
|
||||
void ARC_EngineData_Create(ARC_EngineData **data, ARC_Point windowSize);
|
||||
|
||||
/**
|
||||
* @breif destroys an ARC_EngineData type
|
||||
|
|
|
|||
|
|
@ -5,20 +5,54 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*/
|
||||
typedef void (* ARC_State_UpdateFn)(void *data);
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*/
|
||||
typedef void (* ARC_State_RenderFn)(void *data);
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*/
|
||||
typedef void (* ARC_State_DestroyDataFn)(void *data);
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*/
|
||||
typedef struct ARC_State {
|
||||
ARC_State_UpdateFn updateFn;
|
||||
ARC_State_RenderFn renderFn;
|
||||
|
||||
void *data;
|
||||
ARC_State_DestroyDataFn *destroyDataFn;
|
||||
} ARC_State;
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*/
|
||||
void ARC_State_Create(ARC_State **state, ARC_State_UpdateFn updateFn, ARC_State_RenderFn renderFn, void *data, ARC_State_DestroyDataFn *destroyDataFn);
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*/
|
||||
void ARC_State_Destroy(ARC_State *state);
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*/
|
||||
void ARC_State_Update(void *data);
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*/
|
||||
void ARC_State_Render(void *data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // ARC_ENGINE_STATE_H_
|
||||
#endif // ARC_ENGINE_STATE_H_
|
||||
|
|
|
|||
|
|
@ -10,13 +10,13 @@ extern "C" {
|
|||
#include "arc/math/rectangle.h"
|
||||
#include <stdint.h>
|
||||
|
||||
void ARC_Rect_Render(ARC_Rect *rect, ARC_Renderer *renderer, ARC_Color *color);
|
||||
void ARC_Rect_Render(ARC_Rect rect, ARC_Renderer *renderer, ARC_Color color);
|
||||
|
||||
void ARC_Rect_RenderFill(ARC_Rect *rect, ARC_Renderer *renderer, ARC_Color *color);
|
||||
void ARC_Rect_RenderFill(ARC_Rect rect, ARC_Renderer *renderer, ARC_Color color);
|
||||
|
||||
void ARC_FRect_Render(ARC_FRect *rect, ARC_Renderer *renderer, ARC_Color *color);
|
||||
void ARC_FRect_Render(ARC_FRect rect, ARC_Renderer *renderer, ARC_Color color);
|
||||
|
||||
void ARC_FRect_RenderFill(ARC_FRect *rect, ARC_Renderer *renderer, ARC_Color *color);
|
||||
void ARC_FRect_RenderFill(ARC_FRect rect, ARC_Renderer *renderer, ARC_Color color);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
#include <stdint.h>
|
||||
#include "point.h"
|
||||
#include "vector2.h"
|
||||
#include "arc/std/bool.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
|
@ -53,7 +54,7 @@ void ARC_FRect_CenterOn(ARC_FRect *rect, ARC_FRect *bounds);
|
|||
*
|
||||
* @return ARC_FRect
|
||||
*/
|
||||
ARC_FRect ARC_Rect_CastToFRect(ARC_Rect *rect);
|
||||
ARC_FRect ARC_Rect_CastToFRect(ARC_Rect rect);
|
||||
|
||||
/**
|
||||
* @brief casts FRect to Rect
|
||||
|
|
@ -62,7 +63,7 @@ ARC_FRect ARC_Rect_CastToFRect(ARC_Rect *rect);
|
|||
*
|
||||
* @return ARC_Rect
|
||||
*/
|
||||
ARC_Rect ARC_FRect_CastToRect(ARC_FRect *rect);
|
||||
ARC_Rect ARC_FRect_CastToRect(ARC_FRect rect);
|
||||
|
||||
/**
|
||||
* @brief checks if two ARC_Rects intersect
|
||||
|
|
@ -70,9 +71,9 @@ ARC_Rect ARC_FRect_CastToRect(ARC_FRect *rect);
|
|||
* @param rect1 ARC_Rect that will be checked against rect2
|
||||
* @param rect2 ARC_Rect that will be checked against rect1
|
||||
*
|
||||
* @return 1 if they intersect, 0 if they don't intersect
|
||||
* @return ARC_True if they intersect, ARC_False if they don't intersect
|
||||
*/
|
||||
int32_t ARC_Rect_Intersects(ARC_Rect *rect1, ARC_Rect *rect2);
|
||||
ARC_Bool ARC_Rect_Intersects(ARC_Rect rect1, ARC_Rect rect2);
|
||||
|
||||
/**
|
||||
* @brief checks if two ARC_FRects intersect
|
||||
|
|
@ -80,9 +81,9 @@ int32_t ARC_Rect_Intersects(ARC_Rect *rect1, ARC_Rect *rect2);
|
|||
* @param rect1 ARC_FRect that will be checked against rect2
|
||||
* @param rect2 ARC_FRect that will be checked against rect1
|
||||
*
|
||||
* @return 1 if they intersect, 0 if they don't intersect
|
||||
* @return ARC_True if they intersect, ARC_False if they don't intersect
|
||||
*/
|
||||
int32_t ARC_FRect_Intersects(ARC_FRect *rect1, ARC_FRect *rect2);
|
||||
ARC_Bool ARC_FRect_Intersects(ARC_FRect rect1, ARC_FRect rect2);
|
||||
|
||||
/**
|
||||
* @brief checks if ARC_Rect intersects with point
|
||||
|
|
@ -90,9 +91,9 @@ int32_t ARC_FRect_Intersects(ARC_FRect *rect1, ARC_FRect *rect2);
|
|||
* @param rect ARC_Rect that will be checked against point
|
||||
* @param point ARC_Point that will be checked against rect
|
||||
*
|
||||
* @return 1 if they intersect, 0 if they don't intersect
|
||||
* @return ARC_True if they intersect, ARC_False if they don't intersect
|
||||
*/
|
||||
int32_t ARC_Rect_IntersectsPoint(ARC_Rect *rect, ARC_Point *point);
|
||||
ARC_Bool ARC_Rect_IntersectsPoint(ARC_Rect rect, ARC_Point point);
|
||||
|
||||
/**
|
||||
* @brief checks if ARC_FRect intersects with point
|
||||
|
|
@ -100,9 +101,9 @@ int32_t ARC_Rect_IntersectsPoint(ARC_Rect *rect, ARC_Point *point);
|
|||
* @param rect ARC_FRect that will be checked against point
|
||||
* @param point ARC_Point that will be checked against rect
|
||||
*
|
||||
* @return 1 if they intersect, 0 if they don't intersect
|
||||
* @return ARC_True if they intersect, ARC_False if they don't intersect
|
||||
*/
|
||||
int32_t ARC_FRect_IntersectsPoint(ARC_FRect *rect, ARC_Point *point);
|
||||
ARC_Bool ARC_FRect_IntersectsPoint(ARC_FRect rect, ARC_Point point);
|
||||
|
||||
/**
|
||||
* @brief checks if ARC_Rect intersects a line
|
||||
|
|
|
|||
|
|
@ -2,22 +2,22 @@
|
|||
#include "renderer.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
void ARC_Rect_Render(ARC_Rect *rect, ARC_Renderer *renderer, ARC_Color *color){
|
||||
SDL_SetRenderDrawColor((SDL_Renderer *)renderer, color->r, color->g, color->b, color->a);
|
||||
SDL_RenderDrawRect((SDL_Renderer *)renderer, (SDL_Rect *) rect);
|
||||
void ARC_Rect_Render(ARC_Rect rect, ARC_Renderer *renderer, ARC_Color color){
|
||||
SDL_SetRenderDrawColor((SDL_Renderer *)renderer, color.r, color.g, color.b, color.a);
|
||||
SDL_RenderDrawRect((SDL_Renderer *)renderer, (SDL_Rect *)&rect);
|
||||
}
|
||||
|
||||
void ARC_Rect_RenderFill(ARC_Rect *rect, ARC_Renderer *renderer, ARC_Color *color){
|
||||
SDL_SetRenderDrawColor((SDL_Renderer *)renderer, color->r, color->g, color->b, color->a);
|
||||
SDL_RenderFillRect((SDL_Renderer *)renderer, (SDL_Rect *) rect);
|
||||
void ARC_Rect_RenderFill(ARC_Rect rect, ARC_Renderer *renderer, ARC_Color color){
|
||||
SDL_SetRenderDrawColor((SDL_Renderer *)renderer, color.r, color.g, color.b, color.a);
|
||||
SDL_RenderFillRect((SDL_Renderer *)renderer, (SDL_Rect *)&rect);
|
||||
}
|
||||
|
||||
void ARC_FRect_Render(ARC_FRect *rect, ARC_Renderer *renderer, ARC_Color *color){
|
||||
void ARC_FRect_Render(ARC_FRect rect, ARC_Renderer *renderer, ARC_Color color){
|
||||
ARC_Rect casted = ARC_FRect_CastToRect(rect);
|
||||
ARC_Rect_Render(&casted, renderer, color);
|
||||
ARC_Rect_Render(casted, renderer, color);
|
||||
}
|
||||
|
||||
void ARC_FRect_RenderFill(ARC_FRect *rect, ARC_Renderer *renderer, ARC_Color *color){
|
||||
void ARC_FRect_RenderFill(ARC_FRect rect, ARC_Renderer *renderer, ARC_Color color){
|
||||
ARC_Rect casted = ARC_FRect_CastToRect(rect);
|
||||
ARC_Rect_RenderFill(&casted, renderer, color);
|
||||
}
|
||||
ARC_Rect_RenderFill(casted, renderer, color);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,9 +30,7 @@ void ARC_Renderer_Destroy(ARC_Renderer *renderer){
|
|||
}
|
||||
|
||||
void ARC_Renderer_Clear(ARC_Renderer *renderer){
|
||||
//TODO: changed for school, also need to add the ability to change render draw color
|
||||
//SDL_SetRenderDrawColor((SDL_Renderer *)renderer, 0x1c, 0x2c, 0x3c, 0x00);
|
||||
SDL_SetRenderDrawColor((SDL_Renderer *)renderer, 0x15, 0x2a, 0x26, 0x00);
|
||||
SDL_SetRenderDrawColor((SDL_Renderer *)renderer, 0x1c, 0x2c, 0x3c, 0xff);
|
||||
SDL_RenderClear((SDL_Renderer *)renderer);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,16 +14,21 @@
|
|||
//TODO: remove this
|
||||
//#include <SDL.h>
|
||||
|
||||
void ARC_EngineData_Create(ARC_EngineData **data, ARC_Handler_CleanDataFn cleanFn, ARC_Point windowSize){
|
||||
void ARC_EngineData_HandlerDestroyStateFn(void *data){
|
||||
ARC_State_Destroy((ARC_State *)data);
|
||||
}
|
||||
|
||||
void ARC_EngineData_Create(ARC_EngineData **data, ARC_Point windowSize){
|
||||
*data = (ARC_EngineData *)malloc(sizeof(ARC_EngineData));
|
||||
(*data)->window = NULL;
|
||||
(*data)->renderer = NULL;
|
||||
(*data)->input = NULL;
|
||||
(*data)->keyboard = NULL;
|
||||
(*data)->mouse = NULL;
|
||||
(*data)->window = NULL;
|
||||
(*data)->renderer = NULL;
|
||||
(*data)->input = NULL;
|
||||
(*data)->keyboard = NULL;
|
||||
(*data)->mouse = NULL;
|
||||
(*data)->entitySystem = NULL;
|
||||
|
||||
//TODO: set the destroy callback
|
||||
ARC_Handler_Create(&((*data)->state), NULL, cleanFn);
|
||||
ARC_Handler_Create(&((*data)->state), NULL, ARC_EngineData_HandlerDestroyStateFn);
|
||||
|
||||
(*data)->dt = 0.0;
|
||||
(*data)->running = ARC_False;
|
||||
|
|
@ -46,9 +51,12 @@ void ARC_EngineData_Create(ARC_EngineData **data, ARC_Handler_CleanDataFn cleanF
|
|||
|
||||
(*data)->keyboard = ARC_Input_GetKeyboard((*data)->input);
|
||||
(*data)->mouse = ARC_Input_GetMouse((*data)->input);
|
||||
|
||||
ARC_EntitySystem_Create(&((*data)->entitySystem));
|
||||
}
|
||||
|
||||
void ARC_EngineData_Destroy(ARC_EngineData *data){
|
||||
ARC_EntitySystem_Destroy(data->entitySystem);
|
||||
ARC_Mouse_Destroy(data->mouse);
|
||||
ARC_Keyboard_Destroy(data->keyboard);
|
||||
ARC_Renderer_Destroy(data->renderer);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,29 @@
|
|||
#include "arc/engine/state.h"
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void ARC_State_Create(ARC_State **state, ARC_State_UpdateFn updateFn, ARC_State_RenderFn renderFn, void *data, ARC_State_DestroyDataFn *destroyDataFn){
|
||||
*state = (ARC_State *)malloc(sizeof(ARC_State));
|
||||
|
||||
(*state)->updateFn = updateFn;
|
||||
(*state)->renderFn = renderFn;
|
||||
|
||||
(*state)->data = data;
|
||||
|
||||
(*state)->destroyDataFn = NULL;
|
||||
if(destroyDataFn != NULL){
|
||||
(*state)->destroyDataFn = (ARC_State_DestroyDataFn *)malloc(sizeof(ARC_State_DestroyDataFn));
|
||||
*((*state)->destroyDataFn) = *destroyDataFn;
|
||||
}
|
||||
}
|
||||
|
||||
void ARC_State_Destroy(ARC_State *state){
|
||||
if(state->destroyDataFn != NULL){
|
||||
(*(state->destroyDataFn))(state->data);
|
||||
}
|
||||
|
||||
free(state);
|
||||
}
|
||||
|
||||
void ARC_State_Update(void *data){
|
||||
((ARC_State *)data)->updateFn(((ARC_State *)data)->data);
|
||||
|
|
@ -7,4 +31,4 @@ void ARC_State_Update(void *data){
|
|||
|
||||
void ARC_State_Render(void *data){
|
||||
((ARC_State *)data)->renderFn(((ARC_State *)data)->data);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,20 +3,20 @@
|
|||
#include "arc/graphics/rectangle.h"
|
||||
#include <stdio.h>
|
||||
|
||||
void ARC_Rect_Render(ARC_Rect *rect, ARC_Renderer *renderer, ARC_Color *color){
|
||||
void ARC_Rect_Render(ARC_Rect rect, ARC_Renderer *renderer, ARC_Color color){
|
||||
printf("No Graphics Backend Selected\n");
|
||||
}
|
||||
|
||||
void ARC_Rect_RenderFill(ARC_Rect *rect, ARC_Renderer *renderer, ARC_Color *color){
|
||||
void ARC_Rect_RenderFill(ARC_Rect rect, ARC_Renderer *renderer, ARC_Color color){
|
||||
printf("No Graphics Backend Selected\n");
|
||||
}
|
||||
|
||||
void ARC_FRect_Render(ARC_FRect *rect, ARC_Renderer *renderer, ARC_Color *color){
|
||||
void ARC_FRect_Render(ARC_FRect rect, ARC_Renderer *renderer, ARC_Color color){
|
||||
printf("No Graphics Backend Selected\n");
|
||||
}
|
||||
|
||||
void ARC_FRect_RenderFill(ARC_FRect *rect, ARC_Renderer *renderer, ARC_Color *color){
|
||||
void ARC_FRect_RenderFill(ARC_FRect rect, ARC_Renderer *renderer, ARC_Color color){
|
||||
printf("No Graphics Backend Selected\n");
|
||||
}
|
||||
|
||||
#endif // !ARC_NONE_GRAPHICS
|
||||
#endif // !ARC_NONE_GRAPHICS
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#include "arc/math/rectangle.h"
|
||||
#include "arc/std/bool.h"
|
||||
|
||||
//VERY TEMP
|
||||
// #include <SDL.h>
|
||||
|
|
@ -13,54 +14,54 @@ void ARC_FRect_CenterOn(ARC_FRect *rect, ARC_FRect *bounds){
|
|||
rect->y = (bounds->y + (bounds->h / 2.0f)) - (rect->h / 2.0f);
|
||||
}
|
||||
|
||||
ARC_FRect ARC_Rect_CastToFRect(ARC_Rect *rect){
|
||||
ARC_FRect ARC_Rect_CastToFRect(ARC_Rect rect){
|
||||
return (ARC_FRect){
|
||||
.x = (float)rect->x,
|
||||
.y = (float)rect->y,
|
||||
.w = (float)rect->w,
|
||||
.h = (float)rect->h,
|
||||
.x = (float)rect.x,
|
||||
.y = (float)rect.y,
|
||||
.w = (float)rect.w,
|
||||
.h = (float)rect.h,
|
||||
};
|
||||
}
|
||||
|
||||
ARC_Rect ARC_FRect_CastToRect(ARC_FRect *rect){
|
||||
ARC_Rect ARC_FRect_CastToRect(ARC_FRect rect){
|
||||
return (ARC_Rect){
|
||||
.x = (int32_t)rect->x,
|
||||
.y = (int32_t)rect->y,
|
||||
.w = (int32_t)rect->w,
|
||||
.h = (int32_t)rect->h,
|
||||
.x = (int32_t)rect.x,
|
||||
.y = (int32_t)rect.y,
|
||||
.w = (int32_t)rect.w,
|
||||
.h = (int32_t)rect.h,
|
||||
};
|
||||
}
|
||||
|
||||
int32_t ARC_Rect_Intersects(ARC_Rect *rect1, ARC_Rect *rect2){
|
||||
if(rect1->x <= rect2->x + rect2->w && rect1->x + rect1->w >= rect2->x &&
|
||||
rect1->y <= rect2->y + rect2->h && rect1->y + rect1->h >= rect2->y){
|
||||
return 1;
|
||||
ARC_Bool ARC_Rect_Intersects(ARC_Rect rect1, ARC_Rect rect2){
|
||||
if(rect1.x <= rect2.x + rect2.w && rect1.x + rect1.w >= rect2.x &&
|
||||
rect1.y <= rect2.y + rect2.h && rect1.y + rect1.h >= rect2.y){
|
||||
return ARC_True;
|
||||
}
|
||||
return 0;
|
||||
return ARC_False;
|
||||
}
|
||||
|
||||
int32_t ARC_FRect_Intersects(ARC_FRect *rect1, ARC_FRect *rect2){
|
||||
if(rect1->x <= rect2->x + rect2->w && rect1->x + rect1->w >= rect2->x &&
|
||||
rect1->y <= rect2->y + rect2->h && rect1->y + rect1->h >= rect2->y){
|
||||
return 1;
|
||||
ARC_Bool ARC_FRect_Intersects(ARC_FRect rect1, ARC_FRect rect2){
|
||||
if(rect1.x <= rect2.x + rect2.w && rect1.x + rect1.w >= rect2.x &&
|
||||
rect1.y <= rect2.y + rect2.h && rect1.y + rect1.h >= rect2.y){
|
||||
return ARC_True;
|
||||
}
|
||||
return 0;
|
||||
return ARC_False;
|
||||
}
|
||||
|
||||
int32_t ARC_Rect_IntersectsPoint(ARC_Rect *rect, ARC_Point *point){
|
||||
if(rect->x <= point->x && rect->x + rect->w >= point->x &&
|
||||
rect->y <= point->y && rect->y + rect->h >= point->y){
|
||||
return 1;
|
||||
ARC_Bool ARC_Rect_IntersectsPoint(ARC_Rect rect, ARC_Point point){
|
||||
if(rect.x <= point.x && rect.x + rect.w >= point.x &&
|
||||
rect.y <= point.y && rect.y + rect.h >= point.y){
|
||||
return ARC_True;
|
||||
}
|
||||
return 0;
|
||||
return ARC_False;
|
||||
}
|
||||
|
||||
int32_t ARC_FRect_IntersectsPoint(ARC_FRect *rect, ARC_Point *point){
|
||||
if(rect->x <= point->x && rect->x + rect->w >= point->x &&
|
||||
rect->y <= point->y && rect->y + rect->h >= point->y){
|
||||
return 1;
|
||||
ARC_Bool ARC_FRect_IntersectsPoint(ARC_FRect rect, ARC_Point point){
|
||||
if(rect.x <= point.x && rect.x + rect.w >= point.x &&
|
||||
rect.y <= point.y && rect.y + rect.h >= point.y){
|
||||
return ARC_True;
|
||||
}
|
||||
return 0;
|
||||
return ARC_False;
|
||||
}
|
||||
|
||||
int32_t ARC_Rect_LineIntersects(ARC_Rect *rect, int32_t *x1, int32_t *y1, int32_t *x2, int32_t *y2){
|
||||
|
|
@ -80,19 +81,19 @@ void ARC_FRect_CollideAndSlide(ARC_FRect *rect, ARC_Vector2 *velocity, ARC_FRect
|
|||
};
|
||||
|
||||
//there is no collision, return
|
||||
if(!ARC_FRect_Intersects(&nextRectPosition, wall)){
|
||||
if(!ARC_FRect_Intersects(nextRectPosition, *wall)){
|
||||
return;
|
||||
}
|
||||
|
||||
nextRectPosition.x = rect->x + velocity->x;
|
||||
nextRectPosition.y = rect->y;
|
||||
if(ARC_FRect_Intersects(&nextRectPosition, wall)){
|
||||
if(ARC_FRect_Intersects(nextRectPosition, *wall)){
|
||||
velocity->x = 0;
|
||||
}
|
||||
|
||||
nextRectPosition.x = rect->x;
|
||||
nextRectPosition.y = rect->y + velocity->y;
|
||||
if(ARC_FRect_Intersects(&nextRectPosition, wall)){
|
||||
if(ARC_FRect_Intersects(nextRectPosition, *wall)){
|
||||
velocity->y = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -76,7 +76,10 @@ uint32_t ARC_EntitySystem_RegisterComponent(ARC_EntitySystem *entitySystem, uint
|
|||
|
||||
//get the total component size
|
||||
uint32_t offsetEndIndex = ARC_VectorInline_GetSize(entitySystem->offsetVector);
|
||||
uint32_t totalSize = *(uint32_t *)ARC_VectorInline_Get(entitySystem->offsetVector, offsetEndIndex);
|
||||
uint32_t totalSize = 0;
|
||||
if(ARC_VectorInline_GetSize(entitySystem->offsetVector) != 0){
|
||||
totalSize = *(uint32_t *)ARC_VectorInline_Get(entitySystem->offsetVector, offsetEndIndex);
|
||||
}
|
||||
|
||||
//if the new component size would overflow, throw an error
|
||||
if(totalSize > (~(uint32_t)0) - componentSize){
|
||||
|
|
@ -120,6 +123,8 @@ ARC_Entity ARC_EntitySystem_InitEntity(ARC_EntitySystem *entitySystem){
|
|||
ARC_Entity entity = (ARC_Entity)ARC_VectorInline_GetSize(entitySystem->data);
|
||||
//TODO: check if this works
|
||||
ARC_VectorInline_Add(entitySystem->data, NULL);
|
||||
ARC_VectorInline_Add(entitySystem->flagVector, NULL);
|
||||
ARC_VectorInline_Add(entitySystem->maskVector, NULL);
|
||||
|
||||
//set the flag to make the current entity alive
|
||||
uint8_t *flagData = (uint8_t *)ARC_VectorInline_Get(entitySystem->flagVector, (uint32_t)entity);
|
||||
|
|
|
|||
|
|
@ -90,7 +90,9 @@ void ARC_VectorInline_Add(ARC_VectorInline *vectorInline, void *data){
|
|||
}
|
||||
|
||||
//add to the vectors array and increase its current size
|
||||
memcpy(vectorInline->data + (vectorInline->currentSize * vectorInline->typeSize), data, vectorInline->typeSize);
|
||||
if(data != NULL){
|
||||
memcpy(vectorInline->data + (vectorInline->currentSize * vectorInline->typeSize), data, vectorInline->typeSize);
|
||||
}
|
||||
vectorInline->currentSize++;
|
||||
}
|
||||
|
||||
|
|
@ -161,7 +163,7 @@ void *ARC_VectorInline_Get(ARC_VectorInline *vectorInline, uint32_t index){
|
|||
//check to make sure the given index is in bounds of the vector
|
||||
if(index >= vectorInline->currentSize){
|
||||
arc_errno = ARC_ERRNO_DATA;
|
||||
ARC_DEBUG_LOG_ERROR_WITH_VARIABLES("ARC_VectorInline_Get(vectorInline, %u), index %u bounds", index, index);
|
||||
ARC_DEBUG_LOG_ERROR_WITH_VARIABLES("ARC_VectorInline_Get(vectorInline, %u), index %u out of bounds", index, index);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue