@@ -120,7 +120,7 @@ IZ_AppResult IZ_AppRun(struct IZ_App* app, u8 argc, const char* argv[]) { | |||||
char asset_dir[255]; | char asset_dir[255]; | ||||
IZ_AssetResolveDir("weapon-operator", asset_dir); | IZ_AssetResolveDir("weapon-operator", asset_dir); | ||||
u16 sprite_slot_index = IZ_VideoGetNextFreeSpriteSlot(&app->video_state); | |||||
u16 sprite_slot_index = IZ_VideoGetNextFreeSpriteSlot(&app->video_state, IZ_VIDEO_SPRITE_PRIORITY_MEDIUM); | |||||
IZ_VideoLoadSprite(&app->video_state, (IZ_VideoLoadSpriteParams) { | IZ_VideoLoadSprite(&app->video_state, (IZ_VideoLoadSpriteParams) { | ||||
.dir = asset_dir, | .dir = asset_dir, | ||||
.filename = "sprite.svg", | .filename = "sprite.svg", | ||||
@@ -130,7 +130,7 @@ IZ_AppResult IZ_AppRun(struct IZ_App* app, u8 argc, const char* argv[]) { | |||||
app->video_state.active_sprites[sprite_slot_index].sprite.position = (IZ_Vector2D) { 100.f, 100.f }; | app->video_state.active_sprites[sprite_slot_index].sprite.position = (IZ_Vector2D) { 100.f, 100.f }; | ||||
IZ_AssetResolveDir("weapon-specialist", asset_dir); | IZ_AssetResolveDir("weapon-specialist", asset_dir); | ||||
sprite_slot_index = IZ_VideoGetNextFreeSpriteSlot(&app->video_state); | |||||
sprite_slot_index = IZ_VideoGetNextFreeSpriteSlot(&app->video_state, IZ_VIDEO_SPRITE_PRIORITY_MEDIUM); | |||||
IZ_VideoLoadSprite(&app->video_state, (IZ_VideoLoadSpriteParams) { | IZ_VideoLoadSprite(&app->video_state, (IZ_VideoLoadSpriteParams) { | ||||
.dir = asset_dir, | .dir = asset_dir, | ||||
.filename = "sprite.svg", | .filename = "sprite.svg", | ||||
@@ -1 +1,8 @@ | |||||
#include "IZ_entity.h" | #include "IZ_entity.h" | ||||
IZ_Entity* IZ_EntityNew(IZ_Entity attrs) { | |||||
// TODO let pool allocate memory for entity instead of malloc! | |||||
IZ_Entity* new_entity = (IZ_Entity*) malloc(sizeof(IZ_Entity)); | |||||
return new_entity; | |||||
} |
@@ -1,11 +1,16 @@ | |||||
#ifndef IZ_ENTITY_H | #ifndef IZ_ENTITY_H | ||||
#define IZ_ENTITY_H | #define IZ_ENTITY_H | ||||
#include <stdlib.h> | |||||
#include "../geometry/IZ_vector2d.h" | #include "../geometry/IZ_vector2d.h" | ||||
typedef struct { | typedef struct { | ||||
IZ_Vector2D pos; | IZ_Vector2D pos; | ||||
IZ_Vector2D speed; | |||||
// TODO object appearance (sprite, sprites contain bounding boxes, collisions contain bounding boxes) | // TODO object appearance (sprite, sprites contain bounding boxes, collisions contain bounding boxes) | ||||
} IZ_Entity; | } IZ_Entity; | ||||
IZ_Entity* IZ_EntityNew(IZ_Entity); | |||||
#endif | #endif |
@@ -9,7 +9,6 @@ typedef struct { | |||||
IZ_Entity as_entity; | IZ_Entity as_entity; | ||||
IZ_Rect collision_rect; | IZ_Rect collision_rect; | ||||
IZ_Vector2D speed; | |||||
} IZ_Object; | } IZ_Object; | ||||
#endif | #endif |
@@ -109,7 +109,7 @@ spec("memory") { | |||||
it("deallocates old items to make way for new ones when the memory is full") { | it("deallocates old items to make way for new ones when the memory is full") { | ||||
IZ_PoolInitialize(&pool, sizeof(u32)); | IZ_PoolInitialize(&pool, sizeof(u32)); | ||||
IZ_PoolAllocate(&pool, (IZ_PoolAllocationArgs){ | |||||
void* p1 = IZ_PoolAllocate(&pool, (IZ_PoolAllocationArgs){ | |||||
.size = sizeof(u16), | .size = sizeof(u16), | ||||
.priority = 0, | .priority = 0, | ||||
.timestamp = 0, | .timestamp = 0, | ||||
@@ -117,18 +117,48 @@ spec("memory") { | |||||
IZ_PoolAllocate(&pool, (IZ_PoolAllocationArgs){ | IZ_PoolAllocate(&pool, (IZ_PoolAllocationArgs){ | ||||
.size = sizeof(u8), | .size = sizeof(u8), | ||||
.priority = 0, | .priority = 0, | ||||
.timestamp = 0, | |||||
.timestamp = 1, | |||||
}); | }); | ||||
IZ_PoolAllocate(&pool, (IZ_PoolAllocationArgs){ | IZ_PoolAllocate(&pool, (IZ_PoolAllocationArgs){ | ||||
.size = sizeof(u8), | .size = sizeof(u8), | ||||
.priority = 0, | .priority = 0, | ||||
.timestamp = 0, | |||||
.timestamp = 2, | |||||
}); | }); | ||||
IZ_PoolAllocate(&pool, (IZ_PoolAllocationArgs){ | |||||
void* p2 = IZ_PoolAllocate(&pool, (IZ_PoolAllocationArgs){ | |||||
.size = sizeof(u8), | .size = sizeof(u8), | ||||
.priority = 0, | .priority = 0, | ||||
.timestamp = 0, | |||||
.timestamp = 3, | |||||
}); | }); | ||||
check( | |||||
p1 == p2, | |||||
"Old memory not properly deallocated." | |||||
); | |||||
void* p3 = IZ_PoolAllocate(&pool, (IZ_PoolAllocationArgs){ | |||||
.size = sizeof(u8), | |||||
.priority = 0, | |||||
.timestamp = 4, | |||||
}); | |||||
// FIXME here onwards | |||||
check( | |||||
p3 == p2 + sizeof(u8), | |||||
"Free memory not properly utilized." | |||||
); | |||||
void* p4 = IZ_PoolAllocate(&pool, (IZ_PoolAllocationArgs){ | |||||
.size = sizeof(u8), | |||||
.priority = 0, | |||||
.timestamp = 5, | |||||
}); | |||||
check( | |||||
p4 == p3 + sizeof(u8), | |||||
"Free memory not properly utilized." | |||||
); | |||||
} | } | ||||
} | } | ||||