From 90c206b75fa027150759160e89ac3e65d6003ea7 Mon Sep 17 00:00:00 2001 From: Ludovic Pouzenc Date: Sat, 7 Sep 2019 10:58:29 +0200 Subject: Remove TRACE() calls and make spaces in ( EXPR ) uniform --- src/main.c | 85 ++++++++++++++++++++++++++++------------------------------- src/scene00.c | 2 +- src/scene01.c | 79 ++++++++++++++++++++++++------------------------------ src/scene02.c | 2 +- 4 files changed, 77 insertions(+), 91 deletions(-) diff --git a/src/main.c b/src/main.c index d519034..0bb2307 100644 --- a/src/main.c +++ b/src/main.c @@ -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) { diff --git a/src/scene00.c b/src/scene00.c index f8df185..0d6a02e 100644 --- a/src/scene00.c +++ b/src/scene00.c @@ -90,7 +90,7 @@ int scene00_next_caca(graphical_env_t *ge, scene00_env_t *se) { caca_draw_line(cv,6,6,w-14,11, '*'); caca_draw_thin_line(cv,frame%10,frame%10,w-10+frame%10,h-10+frame%10); - if ( frame >= 100 ) { + if (frame >= 100) { return 1; } return 0; diff --git a/src/scene01.c b/src/scene01.c index 7a6aed1..f8027c4 100644 --- a/src/scene01.c +++ b/src/scene01.c @@ -22,7 +22,7 @@ // Mostly inspired by CC0 https://gist.github.com/koute/7391344 typedef float t_mat4x4[16]; -static inline void mat4x4_ortho( t_mat4x4 out, float left, float right, float bottom, float top, float znear, float zfar ) +static inline void mat4x4_ortho(t_mat4x4 out, float left, float right, float bottom, float top, float znear, float zfar) { #define T(a, b) (a * 4 + b) @@ -57,7 +57,7 @@ static const char * vertex_shader = "uniform mat4 u_projection_matrix;\n" "void main() {\n" " v_color = i_color;\n" - " gl_Position = u_projection_matrix * vec4( i_position, 0.0, 1.0 );\n" + " gl_Position = u_projection_matrix * vec4(i_position, 0.0, 1.0);\n" "}\n"; static const char * fragment_shader = @@ -77,59 +77,50 @@ typedef enum t_attrib_id int scene01_init_gl(graphical_env_t *ge, scene01_env_t *se) { GLuint vs, fs, program; - vs = glCreateShader( GL_VERTEX_SHADER ); - fs = glCreateShader( GL_FRAGMENT_SHADER ); + vs = glCreateShader(GL_VERTEX_SHADER); + fs = glCreateShader(GL_FRAGMENT_SHADER); - int length = strlen( vertex_shader ); - glShaderSource( vs, 1, ( const GLchar ** )&vertex_shader, &length ); - glCompileShader( vs ); + int length = strlen(vertex_shader); + glShaderSource(vs, 1, (const GLchar **)&vertex_shader, &length); + glCompileShader(vs); GLint status; - glGetShaderiv( vs, GL_COMPILE_STATUS, &status ); - if( status == GL_FALSE ) - { - fprintf( stderr, "vertex shader compilation failed\n" ); - return 1; - } + glGetShaderiv(vs, GL_COMPILE_STATUS, &status); + if(status == GL_FALSE) return 40; - length = strlen( fragment_shader ); - glShaderSource( fs, 1, ( const GLchar ** )&fragment_shader, &length ); - glCompileShader( fs ); + length = strlen(fragment_shader); + glShaderSource(fs, 1, (const GLchar **)&fragment_shader, &length); + glCompileShader(fs); - glGetShaderiv( fs, GL_COMPILE_STATUS, &status ); - if( status == GL_FALSE ) - { - fprintf( stderr, "fragment shader compilation failed\n" ); - return 1; - } + glGetShaderiv(fs, GL_COMPILE_STATUS, &status); + if(status == GL_FALSE) return 41; program = glCreateProgram(); - glAttachShader( program, vs ); - glAttachShader( program, fs ); + glAttachShader(program, vs); + glAttachShader(program, fs); - glBindAttribLocation( program, attrib_position, "i_position" ); - glBindAttribLocation( program, attrib_color, "i_color" ); - glLinkProgram( program ); + glBindAttribLocation(program, attrib_position, "i_position"); + glBindAttribLocation(program, attrib_color, "i_color"); + glLinkProgram(program); - glUseProgram( program ); + glUseProgram(program); - glDisable( GL_DEPTH_TEST ); - //glClearColor( 0.5, 0.0, 0.0, 0.0 ); - glClearColor( 0.5, 0.5, 0.0, 0.0 ); - glViewport( 0, 0, FBUF_W, FBUF_H ); + glDisable(GL_DEPTH_TEST); + glClearColor(0.5, 0.0, 0.0, 0.0); + glViewport(0, 0, FBUF_W, FBUF_H); GLuint vbo; - glGenVertexArrays( 1, &(se->vao) ); - glGenBuffers( 1, &vbo ); - glBindVertexArray( se->vao ); - glBindBuffer( GL_ARRAY_BUFFER, vbo ); + glGenVertexArrays(1, &(se->vao)); + glGenBuffers(1, &vbo); + glBindVertexArray(se->vao); + glBindBuffer(GL_ARRAY_BUFFER, vbo); - glEnableVertexAttribArray( attrib_position ); - glEnableVertexAttribArray( attrib_color ); + glEnableVertexAttribArray(attrib_position); + glEnableVertexAttribArray(attrib_color); - glVertexAttribPointer( attrib_color, 4, GL_FLOAT, GL_FALSE, sizeof( float ) * 6, 0 ); - glVertexAttribPointer( attrib_position, 2, GL_FLOAT, GL_FALSE, sizeof( float ) * 6, ( void * )(4 * sizeof(float)) ); + glVertexAttribPointer(attrib_color, 4, GL_FLOAT, GL_FALSE, sizeof(float)*6, 0); + glVertexAttribPointer(attrib_position, 2, GL_FLOAT, GL_FALSE, sizeof(float)*6, (void *)(4*sizeof(float))); const GLfloat g_vertex_buffer_data[] = { /* R, G, B, A, X, Y */ @@ -142,11 +133,11 @@ int scene01_init_gl(graphical_env_t *ge, scene01_env_t *se) { 1, 1, 1, 1, 0, FBUF_H }; - glBufferData( GL_ARRAY_BUFFER, sizeof( g_vertex_buffer_data ), g_vertex_buffer_data, GL_STATIC_DRAW ); + glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data), g_vertex_buffer_data, GL_STATIC_DRAW); t_mat4x4 projection_matrix; - mat4x4_ortho( projection_matrix, 0.0f, (float)FBUF_W, (float)FBUF_H, 0.0f, 0.0f, 100.0f ); - glUniformMatrix4fv( glGetUniformLocation( program, "u_projection_matrix" ), 1, GL_FALSE, projection_matrix ); + mat4x4_ortho(projection_matrix, 0.0f, (float)FBUF_W, (float)FBUF_H, 0.0f, 0.0f, 100.0f); + glUniformMatrix4fv(glGetUniformLocation(program, "u_projection_matrix"), 1, GL_FALSE, projection_matrix); return 0; } @@ -205,7 +196,7 @@ int scene01_next_caca(graphical_env_t *ge, scene01_env_t *se) { caca_set_color_ansi(cv, CACA_WHITE, CACA_BLACK); caca_put_str(cv, (w-17)/2, h/2, "This is a message"); - if ( frame >= 300 ) { + if (frame >= 300) { return 1; } return 0; diff --git a/src/scene02.c b/src/scene02.c index b947234..03f02a4 100644 --- a/src/scene02.c +++ b/src/scene02.c @@ -57,7 +57,7 @@ int scene02_next_caca(graphical_env_t *ge, scene02_env_t *se) { caca_clear_canvas(cv); - if ( frame >= 100 ) { + if (frame >= 100) { return 1; } return 0; -- cgit v1.2.3