diff options
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 85 |
1 files changed, 40 insertions, 45 deletions
@@ -47,19 +47,19 @@ #define SCENE_COUNT 3 #define SCENE_NEXT do { shm->scene = (shm->scene+1)%SCENE_COUNT; } while(0) -#define EXPR_MIN_SIZE ( shm->ge.w<80 || shm->ge.h<25 ) +#define EXPR_MIN_SIZE (shm->ge.w<80 || shm->ge.h<25) #define TEXT_MIN_SIZE "80x25" #define SEM_POST(sem,errcode) \ do { \ TRACE_SEM(sem,"sem_post",""); \ - if ( sem_post(sem) == -1 ) { return errcode; } \ + if (sem_post(sem) == -1) { return errcode; } \ } while(0) #define SEM_WAIT(sem,errcode) \ do { \ TRACE_SEM(sem,"sem_wait","call"); \ - while ( sem_wait(sem) == -1 ) { \ + while (sem_wait(sem) == -1) { \ switch(errno) { \ case EINTR: \ case EAGAIN: \ @@ -91,7 +91,7 @@ shm_t *shm; int main() { TRACE("call"); shm = mmap(NULL, sizeof(shm_t), PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANONYMOUS, 0, 0); - if ( shm == NULL ) return 1; + if (shm == NULL) return 1; bzero(shm, sizeof(shm_t)); if (sem_init(&shm->worker_gl_can_render, 1, 0) < 0) return 2; @@ -133,7 +133,7 @@ int parent() { shm->ge.cv = caca_get_canvas(shm->ge.dp); shm->ge.d = caca_create_dither(32, FBUF_W, FBUF_H, FBUF_W*4, 0x00ff0000, 0x0000ff00, 0x000000ff, 0); - if ( !shm->ge.d ) return 2; + if (!shm->ge.d) return 2; caca_set_dither_color(shm->ge.d, "16"); // Main libcaca loop for caca window @@ -148,14 +148,14 @@ int parent() { caca_put_str(shm->ge.cv, 0, 0, "Need a minimum of " TEXT_MIN_SIZE " terminal"); } else if (!shm->paused) { // init / free if scene transition - if ( lastscene != shm->scene ) { + if (lastscene != shm->scene) { switch(lastscene) { case 0: scene00_free_caca(&shm->ge, &shm->s00e); break; case 1: scene01_free_caca(&shm->ge, &shm->s01e); break; case 2: scene02_free_caca(&shm->ge, &shm->s02e); break; } } - while ( lastscene != shm->scene ) { + while (lastscene != shm->scene) { shm->ge.sdl_ticks = SDL_GetTicks(); shm->ge.sc_framecount = 0; switch(shm->scene) { @@ -188,7 +188,7 @@ int parent() { caca_refresh_display(shm->ge.dp); // Auto framerate limiting (see caca_set_display_time()) // Event handling for the libcaca "window" (depending on CACA_DRIVER env variable) - if ( caca_get_event(shm->ge.dp, CACA_EVENT_KEY_PRESS|CACA_EVENT_RESIZE|CACA_EVENT_QUIT, &caca_ev, 0) ) { + if (caca_get_event(shm->ge.dp, CACA_EVENT_KEY_PRESS|CACA_EVENT_RESIZE|CACA_EVENT_QUIT, &caca_ev, 0)) { switch(caca_get_event_type(&caca_ev)) { case CACA_EVENT_QUIT: shm->done = 1; @@ -218,11 +218,11 @@ int parent() { shm->ge.cv=NULL; // reap forked processes (order doesn't matter) - if ( wait(&child_status) != -1 ) { - if ( child_status > 0 ) return child_status; + if (wait(&child_status) != -1) { + if (child_status > 0) return child_status; } - if ( wait(&child_status) != -1 ) { - if ( child_status > 0 ) return child_status; + if (wait(&child_status) != -1) { + if (child_status > 0) return child_status; } return 0; } @@ -238,33 +238,33 @@ int worker_sdl() { // Initialize SDL (http://wiki.libsdl.org/SDL_CreateWindowAndRenderer) // Useful snippet : https://gist.github.com/koute/7391344 res = SDL_Init(SDL_INIT_VIDEO); - if ( res == -1) return 3; + if (res == -1) return 3; atexit(SDL_Quit); res = SDL_CreateWindowAndRenderer(FBUF_W, FBUF_H, sdl_win_flags, &shm->ge.sdl_win, &shm->ge.sdl_rndr); - if ( res == -1) return 4; + if (res == -1) return 4; SDL_SetWindowTitle(shm->ge.sdl_win, "SDL debug"); res = SDL_GetRendererInfo(shm->ge.sdl_rndr, &renderer_info); - if ( res < 0 ) return 5; - if ( !(renderer_info.flags & SDL_RENDERER_ACCELERATED)) return 6; - if ( !(renderer_info.flags & SDL_RENDERER_TARGETTEXTURE)) return 7; + if (res < 0) return 5; + if (!(renderer_info.flags & SDL_RENDERER_ACCELERATED)) return 6; + if (!(renderer_info.flags & SDL_RENDERER_TARGETTEXTURE)) return 7; shm->ge.sdl_target = SDL_CreateTexture(shm->ge.sdl_rndr, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, FBUF_W, FBUF_H); - if ( shm->ge.sdl_target == NULL ) return 9; + if (shm->ge.sdl_target == NULL) return 9; - while ( !shm->done ) { + while (!shm->done) { //FIXME change for TRYWAIT for event handling (+delay) SEM_WAIT(&shm->worker_sdl_can_render,20); if (!shm->paused) { // init / free if scene transition - if ( lastscene != shm->scene ) { + if (lastscene != shm->scene) { switch(lastscene) { case 0: scene00_free_sdl(&shm->ge, &shm->s00e); break; case 1: scene01_free_sdl(&shm->ge, &shm->s01e); break; case 2: scene02_free_sdl(&shm->ge, &shm->s02e); break; } } - while ( lastscene != shm->scene ) { + while (lastscene != shm->scene ) { shm->ge.sdl_ticks = SDL_GetTicks(); shm->ge.sc_framecount = 0; switch(shm->scene) { @@ -277,8 +277,6 @@ int worker_sdl() { } } - TRACE("before next_sdl"); - printf("DEBUG shm->scene : %i\n", shm->scene); // Compute current scene frame (sdl part) switch(shm->scene) { case 0: res = scene00_next_sdl(&shm->ge, &shm->s00e); break; @@ -286,7 +284,6 @@ int worker_sdl() { case 2: res = scene02_next_sdl(&shm->ge, &shm->s02e); break; } if (res) SCENE_NEXT; - TRACE("after next_sdl"); // Event handling for the SDL window (debug purposes) while(SDL_PollEvent(&sdl_ev)) { @@ -305,10 +302,8 @@ int worker_sdl() { break; } } - TRACE("after SDL_PollEvent loop"); SEM_POST(&shm->parent_can_read_result, 21); - TRACE("after sem_post"); } SDL_DestroyRenderer(shm->ge.sdl_rndr); @@ -329,48 +324,48 @@ int worker_gl() { // Initialize SDL (http://wiki.libsdl.org/SDL_CreateWindowAndRenderer) // Useful snippet : https://gist.github.com/koute/7391344 res = SDL_Init(SDL_INIT_VIDEO); - if ( res == -1) return 3; + if (res == -1) return 3; atexit(SDL_Quit); - SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); - SDL_GL_SetAttribute( SDL_GL_ACCELERATED_VISUAL, 1 ); - SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 8 ); - SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 8 ); - SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 8 ); - SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 8 ); - SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION, 3 ); - SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION, 2 ); - SDL_GL_SetAttribute( SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE ); + SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); + SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1); + SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); // Initialize OpenGL //shm->ge.gl_win = SDL_CreateWindow("GL Debug", SDL_WINDOWPOS_CENTERED, 0, FBUF_W, FBUF_H, sdl_win_flags); res = SDL_CreateWindowAndRenderer(FBUF_W, FBUF_H, sdl_win_flags, &shm->ge.gl_win, &shm->ge.gl_rndr); - if ( res == -1) return 4; + if (res == -1) return 4; SDL_SetWindowTitle(shm->ge.gl_win, "GL debug"); res = SDL_GetRendererInfo(shm->ge.gl_rndr, &renderer_info); - if ( res < 0 ) return 5; - if ( !(renderer_info.flags & SDL_RENDERER_ACCELERATED)) return 6; - if ( !(renderer_info.flags & SDL_RENDERER_TARGETTEXTURE)) return 7; + if (res < 0) return 5; + if (!(renderer_info.flags & SDL_RENDERER_ACCELERATED)) return 6; + if (!(renderer_info.flags & SDL_RENDERER_TARGETTEXTURE)) return 7; shm->ge.gl_target = SDL_CreateTexture(shm->ge.gl_rndr, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, FBUF_W, FBUF_H); - if ( shm->ge.gl_target == NULL ) return 9; + if (shm->ge.gl_target == NULL) return 9; shm->ge.gl_ctx = SDL_GL_CreateContext(shm->ge.gl_win); - if ( shm->ge.gl_ctx == NULL ) return 11; + if (shm->ge.gl_ctx == NULL) return 11; - while ( !shm->done ) { + while (!shm->done) { //FIXME change for TRYWAIT for event handling (+delay) SEM_WAIT(&shm->worker_gl_can_render,10); if (!shm->paused) { // init / free if scene transition - if ( lastscene != shm->scene ) { + if (lastscene != shm->scene) { switch(lastscene) { case 0: scene00_free_gl(&shm->ge, &shm->s00e); break; case 1: scene01_free_gl(&shm->ge, &shm->s01e); break; case 2: scene02_free_gl(&shm->ge, &shm->s02e); break; } } - while ( lastscene != shm->scene ) { + while (lastscene != shm->scene) { shm->ge.sdl_ticks = SDL_GetTicks(); shm->ge.sc_framecount = 0; switch(shm->scene) { |