1
0
mirror of https://github.com/pevans/erc-c.git synced 2024-07-20 07:28:56 +00:00

Don't create a window when testing

We do this by creating the notion of a "headless" mode, and skip window
creation in SDL.
This commit is contained in:
Peter Evans 2017-12-26 17:06:08 -06:00
parent 5b35e2294e
commit 8146687110
2 changed files with 7 additions and 1 deletions

View File

@ -74,6 +74,7 @@ vm_screen_set_logical_coords(vm_screen *screen, int xcoords, int ycoords)
int int
vm_screen_add_window(vm_screen *screen, int width, int height) vm_screen_add_window(vm_screen *screen, int width, int height)
{ {
#ifndef HEADLESS
SDL_CreateWindowAndRenderer( SDL_CreateWindowAndRenderer(
width, height, 0, &screen->window, &screen->render); width, height, 0, &screen->window, &screen->render);
@ -81,6 +82,7 @@ vm_screen_add_window(vm_screen *screen, int width, int height)
log_critical("Could not create window: %s", SDL_GetError()); log_critical("Could not create window: %s", SDL_GetError());
return ERR_GFXINIT; return ERR_GFXINIT;
} }
#endif
// We plan to draw onto a surface that is xcoords x ycoords in area, // We plan to draw onto a surface that is xcoords x ycoords in area,
// regardless of the actual size of the window. // regardless of the actual size of the window.
@ -150,7 +152,9 @@ vm_screen_set_color(vm_screen *screen,
uint8_t blue, uint8_t blue,
uint8_t alpha) uint8_t alpha)
{ {
SDL_SetRenderDrawColor(screen->render, red, green, blue, alpha); if (screen->render) {
SDL_SetRenderDrawColor(screen->render, red, green, blue, alpha);
}
} }
/* /*

View File

@ -4,6 +4,8 @@ project(erc-test)
set(CMAKE_BUILD_TYPE Debug) set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DHEADLESS")
if(DEFINED ENV{STATIC_ANALYSIS}) if(DEFINED ENV{STATIC_ANALYSIS})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --analyze") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --analyze")
endif() endif()