@@ -100,6 +100,8 @@ add_executable( | |||||
src/packages/test/IZ_test.h | src/packages/test/IZ_test.h | ||||
__mocks__/minIni.mock.h | __mocks__/minIni.mock.h | ||||
__mocks__/SDL_stdinc.mock.h | |||||
__mocks__/SDL_render.mock.h | |||||
src/packages/game/IZ_config.h | src/packages/game/IZ_config.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 |
@@ -1,24 +1,26 @@ | |||||
#include "IZ_app.h" | #include "IZ_app.h" | ||||
IZ_ProcedureResult IZ_AppInitialize(IZ_App* app) { | IZ_ProcedureResult IZ_AppInitialize(IZ_App* app) { | ||||
if (SDL_Init( | |||||
u32 flags = ( | |||||
SDL_INIT_VIDEO | SDL_INIT_VIDEO | ||||
| SDL_INIT_GAMECONTROLLER | | SDL_INIT_GAMECONTROLLER | ||||
| SDL_INIT_EVENTS | | 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()); | fprintf_s(stderr, "SDL could not initialize! SDL_Error: %s\n", SDL_GetError()); | ||||
return 1; | return 1; | ||||
} | } | ||||
char config_path[128]; | char config_path[128]; | ||||
IZ_ConfigGetPath(config_path, 128); | IZ_ConfigGetPath(config_path, 128); | ||||
if (IZ_VideoInitialize(config_path, &app->video_state)) { | if (IZ_VideoInitialize(config_path, &app->video_state)) { | ||||
return 2; | return 2; | ||||
} | } | ||||
IZ_InputInitialize(config_path, &app->input_state); | 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* p1 = IZ_PoolAllocate(&app->memory_pool, sizeof(u16), 0)->pointer; | ||||
// void* p2 = IZ_PoolAllocate(&app->memory_pool, sizeof(u8), 0)->pointer; | // void* p2 = IZ_PoolAllocate(&app->memory_pool, sizeof(u8), 0)->pointer; | ||||
// void* p3 = IZ_PoolAllocate(&app->memory_pool, sizeof(u64), 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); | // IZ_PoolDeallocate(p1); | ||||
// void* p5 = IZ_PoolAllocate(&app->memory_pool, sizeof(u16), 0)->pointer; | // void* p5 = IZ_PoolAllocate(&app->memory_pool, sizeof(u16), 0)->pointer; | ||||
// printf("\n%p\n", p5); | // printf("\n%p\n", p5); | ||||
app->quit = false; | |||||
// TODO put into its timer module | |||||
app->ticks = 0; | app->ticks = 0; | ||||
app->quit = false; | |||||
return 0; | return 0; | ||||
} | } | ||||
void IZ_AppTeardown(IZ_App* app) { | void IZ_AppTeardown(IZ_App* app) { | ||||
IZ_PoolTeardown(&app->pool); | |||||
IZ_InputTeardown(&app->input_state); | IZ_InputTeardown(&app->input_state); | ||||
IZ_VideoTeardown(&app->video_state); | IZ_VideoTeardown(&app->video_state); | ||||
SDL_Quit(); | SDL_Quit(); | ||||
@@ -18,7 +18,7 @@ typedef struct { | |||||
IZ_InputState input_state; | IZ_InputState input_state; | ||||
IZ_VideoState video_state; | IZ_VideoState video_state; | ||||
IZ_Pool memory_pool; | |||||
IZ_Pool pool; | |||||
u64 ticks; | u64 ticks; | ||||
bool quit; | bool quit; | ||||
} IZ_App; | } IZ_App; | ||||
@@ -46,3 +46,7 @@ void IZ_PoolDeallocate(IZ_PoolItem* item) { | |||||
return; | return; | ||||
} | } | ||||
} | } | ||||
void IZ_PoolTeardown(IZ_Pool* pool) { | |||||
SDL_free(pool->memory); | |||||
} |
@@ -29,4 +29,6 @@ IZ_PoolItem* IZ_PoolAllocate(IZ_Pool*, size_t, u64); | |||||
void IZ_PoolDeallocate(IZ_PoolItem*); | void IZ_PoolDeallocate(IZ_PoolItem*); | ||||
void IZ_PoolTeardown(IZ_Pool*); | |||||
#endif | #endif |
@@ -0,0 +1,18 @@ | |||||
#include "../../test/IZ_test.h" | |||||
#include "IZ_pool.h" | |||||
spec("memory") { | |||||
describe("pool") { | |||||
describe("PoolInitialize") { | |||||
} | |||||
describe("PoolAllocate") { | |||||
} | |||||
describe("PoolDeallocate") { | |||||
} | |||||
} | |||||
} |
@@ -25,7 +25,7 @@ IZ_ProcedureResult IZ_VideoInitialize(const char* config_path, IZ_VideoState* st | |||||
IZ_VideoLoadConfig(config_path, &state->config); | IZ_VideoLoadConfig(config_path, &state->config); | ||||
if (IZ_VideoSaveConfig(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; | state->last_update_at = 0u; | ||||
@@ -38,7 +38,7 @@ IZ_ProcedureResult IZ_VideoInitialize(const char* config_path, IZ_VideoState* st | |||||
SDL_WINDOW_SHOWN | SDL_WINDOW_SHOWN | ||||
); | ); | ||||
if (window == NULL) { | 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; | return 1; | ||||
} | } | ||||
state->window = window; | state->window = window; | ||||
@@ -3,7 +3,6 @@ | |||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <minIni.h> | #include <minIni.h> | ||||
#include <SDL_video.h> | |||||
#include <SDL_render.h> | #include <SDL_render.h> | ||||
// TODO move this out from video, refer to app's state instead | // TODO move this out from video, refer to app's state instead | ||||
@@ -1,9 +1,11 @@ | |||||
#include "../../../__mocks__/minIni.mock.h" | #include "../../../__mocks__/minIni.mock.h" | ||||
#include "../../../__mocks__/SDL_stdinc.mock.h" | |||||
#include "../../../__mocks__/SDL_render.mock.h" | |||||
#include "IZ_video.h" | #include "IZ_video.h" | ||||
spec("output") { | spec("output") { | ||||
describe("video") { | describe("video") { | ||||
describe("SaveVideoConfig") { | |||||
describe("VideoSaveConfig") { | |||||
static IZ_VideoConfig config; | static IZ_VideoConfig config; | ||||
after_each() { | after_each() { | ||||