diff --git a/CMakeLists.txt b/CMakeLists.txt index 854fca5..a266d70 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -100,6 +100,8 @@ add_executable( src/packages/test/IZ_test.h __mocks__/minIni.mock.h + __mocks__/SDL_stdinc.mock.h + __mocks__/SDL_render.mock.h src/packages/game/IZ_config.h diff --git a/__mocks__/SDL_render.mock.h b/__mocks__/SDL_render.mock.h new file mode 100644 index 0000000..fb75883 --- /dev/null +++ b/__mocks__/SDL_render.mock.h @@ -0,0 +1,53 @@ +#ifndef SDL_RENDER_MOCK_H +#define SDL_RENDER_MOCK_H + +#include "../src/packages/test/IZ_test.h" + +typedef struct SDL_Renderer SDL_Renderer; + +typedef struct SDL_Window SDL_Window; + +typedef struct SDL_FRect SDL_FRect; + +mock(SDL_CreateWindow) SDL_Window* SDL_CreateWindow( + const char *title, + int x, int y, int w, + int h, unsigned int flags +) { + static SDL_Window* window = (SDL_Window*) 1; + mock_return(SDL_CreateWindow) window; +} + +mock(SDL_CreateRenderer) SDL_Renderer* SDL_CreateRenderer(SDL_Window* window, int index, unsigned int flags) { + static SDL_Renderer* renderer = (SDL_Renderer*) 1; + mock_return(SDL_CreateRenderer) renderer; +} + +mock(SDL_SetRenderDrawColor) int SDL_SetRenderDrawColor( + SDL_Renderer* renderer, + unsigned char r, unsigned char g, unsigned char b, + unsigned char a +) { + mock_return(SDL_SetRenderDrawColor) 0; +} + +mock(SDL_RenderFillRectF) int SDL_RenderFillRectF( + SDL_Renderer* renderer, + const SDL_FRect* rect +) { + mock_return(SDL_RenderFillRectF) 0; +} + +mock(SDL_RenderClear) int SDL_RenderClear(SDL_Renderer* renderer) { + mock_return(SDL_RenderClear) 0; +} + +mock(SDL_RenderPresent) void SDL_RenderPresent(SDL_Renderer* renderer) { + mock_return(SDL_RenderPresent); +} + +mock(SDL_DestroyWindow) void SDL_DestroyWindow(SDL_Window* window) { + mock_return(SDL_DestroyWindow); +} + +#endif diff --git a/src/packages/game/IZ_app.c b/src/packages/game/IZ_app.c index 80c23e7..6cc128c 100644 --- a/src/packages/game/IZ_app.c +++ b/src/packages/game/IZ_app.c @@ -1,24 +1,26 @@ #include "IZ_app.h" IZ_ProcedureResult IZ_AppInitialize(IZ_App* app) { - if (SDL_Init( + u32 flags = ( SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER | SDL_INIT_EVENTS - ) < 0) { + ); + + if (SDL_Init(flags) < 0) { + // TODO fix logging fprintf_s(stderr, "SDL could not initialize! SDL_Error: %s\n", SDL_GetError()); return 1; } char config_path[128]; IZ_ConfigGetPath(config_path, 128); - if (IZ_VideoInitialize(config_path, &app->video_state)) { return 2; } IZ_InputInitialize(config_path, &app->input_state); - IZ_PoolInitialize(&app->memory_pool); + IZ_PoolInitialize(&app->pool); // void* p1 = IZ_PoolAllocate(&app->memory_pool, sizeof(u16), 0)->pointer; // void* p2 = IZ_PoolAllocate(&app->memory_pool, sizeof(u8), 0)->pointer; // void* p3 = IZ_PoolAllocate(&app->memory_pool, sizeof(u64), 0)->pointer; @@ -27,12 +29,15 @@ IZ_ProcedureResult IZ_AppInitialize(IZ_App* app) { // IZ_PoolDeallocate(p1); // void* p5 = IZ_PoolAllocate(&app->memory_pool, sizeof(u16), 0)->pointer; // printf("\n%p\n", p5); - app->quit = false; + + // TODO put into its timer module app->ticks = 0; + app->quit = false; return 0; } void IZ_AppTeardown(IZ_App* app) { + IZ_PoolTeardown(&app->pool); IZ_InputTeardown(&app->input_state); IZ_VideoTeardown(&app->video_state); SDL_Quit(); diff --git a/src/packages/game/IZ_app.h b/src/packages/game/IZ_app.h index fdfbab0..cda03fe 100644 --- a/src/packages/game/IZ_app.h +++ b/src/packages/game/IZ_app.h @@ -18,7 +18,7 @@ typedef struct { IZ_InputState input_state; IZ_VideoState video_state; - IZ_Pool memory_pool; + IZ_Pool pool; u64 ticks; bool quit; } IZ_App; diff --git a/src/packages/game/memory/IZ_pool.c b/src/packages/game/memory/IZ_pool.c index 0b11e2c..9b314d5 100644 --- a/src/packages/game/memory/IZ_pool.c +++ b/src/packages/game/memory/IZ_pool.c @@ -46,3 +46,7 @@ void IZ_PoolDeallocate(IZ_PoolItem* item) { return; } } + +void IZ_PoolTeardown(IZ_Pool* pool) { + SDL_free(pool->memory); +} diff --git a/src/packages/game/memory/IZ_pool.h b/src/packages/game/memory/IZ_pool.h index 44ed3ff..abec363 100644 --- a/src/packages/game/memory/IZ_pool.h +++ b/src/packages/game/memory/IZ_pool.h @@ -29,4 +29,6 @@ IZ_PoolItem* IZ_PoolAllocate(IZ_Pool*, size_t, u64); void IZ_PoolDeallocate(IZ_PoolItem*); +void IZ_PoolTeardown(IZ_Pool*); + #endif diff --git a/src/packages/game/memory/memory.test.c b/src/packages/game/memory/memory.test.c index e69de29..41451d4 100644 --- a/src/packages/game/memory/memory.test.c +++ b/src/packages/game/memory/memory.test.c @@ -0,0 +1,18 @@ +#include "../../test/IZ_test.h" +#include "IZ_pool.h" + +spec("memory") { + describe("pool") { + describe("PoolInitialize") { + + } + + describe("PoolAllocate") { + + } + + describe("PoolDeallocate") { + + } + } +} diff --git a/src/packages/game/output/IZ_video.c b/src/packages/game/output/IZ_video.c index 838ca12..c682a8b 100644 --- a/src/packages/game/output/IZ_video.c +++ b/src/packages/game/output/IZ_video.c @@ -25,7 +25,7 @@ IZ_ProcedureResult IZ_VideoInitialize(const char* config_path, IZ_VideoState* st IZ_VideoLoadConfig(config_path, &state->config); if (IZ_VideoSaveConfig(config_path, &state->config)) { - fprintf_s(stderr, "Error committing video config.\n"); +// fprintf_s(stderr, "Error committing video config.\n"); } state->last_update_at = 0u; @@ -38,7 +38,7 @@ IZ_ProcedureResult IZ_VideoInitialize(const char* config_path, IZ_VideoState* st SDL_WINDOW_SHOWN ); if (window == NULL) { - fprintf_s(stderr, "Window could not be created! SDL_Error: %s\n", SDL_GetError()); +// fprintf_s(stderr, "Window could not be created! SDL_Error: %s\n", SDL_GetError()); return 1; } state->window = window; diff --git a/src/packages/game/output/IZ_video.h b/src/packages/game/output/IZ_video.h index 918a89a..3daddcc 100644 --- a/src/packages/game/output/IZ_video.h +++ b/src/packages/game/output/IZ_video.h @@ -3,7 +3,6 @@ #include #include -#include #include // TODO move this out from video, refer to app's state instead diff --git a/src/packages/game/output/output.test.c b/src/packages/game/output/output.test.c index b5dd54d..11ffa33 100644 --- a/src/packages/game/output/output.test.c +++ b/src/packages/game/output/output.test.c @@ -1,9 +1,11 @@ #include "../../../__mocks__/minIni.mock.h" +#include "../../../__mocks__/SDL_stdinc.mock.h" +#include "../../../__mocks__/SDL_render.mock.h" #include "IZ_video.h" spec("output") { describe("video") { - describe("SaveVideoConfig") { + describe("VideoSaveConfig") { static IZ_VideoConfig config; after_each() {