diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main.c | 36 | ||||
-rw-r--r-- | src/main.h | 13 | ||||
-rw-r--r-- | src/scene00.c | 6 | ||||
-rw-r--r-- | src/scene01.c | 8 | ||||
-rw-r--r-- | src/scene02.c | 7 |
5 files changed, 43 insertions, 27 deletions
@@ -42,9 +42,6 @@ #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 TEXT_MIN_SIZE "80x25" - #define SEM_POST(sem,errcode) \ do { \ TRACE_SEM(sem,"sem_post",""); \ @@ -99,6 +96,7 @@ int main() { int do_fork1() { TRACE("call"); + fflush(stdout); switch (fork()) { case -1: return 4; break; case 0: return worker_sdl(); break; @@ -108,6 +106,7 @@ int do_fork1() { int do_fork2() { TRACE("call"); + fflush(stdout); switch (fork()) { case -1: return 5; break; case 0: return worker_gl(); break; @@ -125,7 +124,7 @@ int parent() { shm->ge.dp = caca_create_display(NULL); if(!shm->ge.dp) return 1; caca_set_display_title(shm->ge.dp, "demoscene-eo"); - caca_set_display_time(shm->ge.dp, 16666); // 1e6µs/60 = 16666.66... It is ~60 fps + caca_set_display_time(shm->ge.dp, 41666); // 1e6µs/24 = 41666.66... It is ~24 fps 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); @@ -234,9 +233,13 @@ static void worker_sdl_sighandler(int sig) { int worker_sdl() { int lastscene=-1, res; struct sigaction sa; +#ifdef DEBUG Uint32 sdl_win_flags = 0; //XXX for final version, consider adding SDL_WINDOW_HIDDEN - SDL_RendererInfo renderer_info; SDL_Event sdl_ev; +#else + Uint32 sdl_win_flags = SDL_WINDOW_HIDDEN; +#endif + SDL_RendererInfo renderer_info; TRACE("call"); @@ -297,6 +300,7 @@ int worker_sdl() { } if (skip) skip = 0; +#ifdef DEBUG // Event handling for the SDL window (debug purposes) while(SDL_PollEvent(&sdl_ev)) { switch(sdl_ev.type) { @@ -314,7 +318,7 @@ int worker_sdl() { break; } } - +#endif SEM_POST(&shm->parent_can_read_result, 21); } @@ -336,9 +340,13 @@ static void worker_gl_sighandler(int sig) { int worker_gl() { int lastscene=-1, res; struct sigaction sa; - Uint32 sdl_win_flags = SDL_WINDOW_OPENGL; //XXX for final version, consider adding SDL_WINDOW_HIDDEN - SDL_RendererInfo renderer_info; +#ifdef DEBUG + Uint32 sdl_win_flags = SDL_WINDOW_OPENGL; SDL_Event gl_ev; +#else + Uint32 sdl_win_flags = SDL_WINDOW_OPENGL | SDL_WINDOW_HIDDEN; +#endif + SDL_RendererInfo renderer_info; TRACE("call"); @@ -376,7 +384,12 @@ int worker_gl() { 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; - +/* + glBindFramebuffer(GL_FRAMEBUFFER,0); + glClearColor(0,0,0,1); + glClear(GL_COLOR_BUFFER_BIT); + SDL_GL_SwapWindow(shm->ge.gl_win); +*/ while (!shm->done) { alarm(1); SEM_WAIT(&shm->worker_gl_can_render,10); @@ -413,6 +426,7 @@ int worker_gl() { } if (skip) skip = 0; +#ifdef DEBUG // Event handling for the GL window (debug purposes) while(SDL_PollEvent(&gl_ev)) { switch(gl_ev.type) { @@ -430,11 +444,11 @@ int worker_gl() { break; } } - +#endif SEM_POST(&shm->parent_can_read_result, 11); } - //SDL_DestroyTexture(shm->ge.gl_target); + SDL_DestroyTexture(shm->ge.gl_target); SDL_GL_DeleteContext(shm->ge.gl_ctx); SDL_DestroyWindow(shm->ge.gl_win); @@ -8,15 +8,18 @@ #include <SDL2/SDL_opengl.h> #include <GL/glu.h> -#define FBUF_W 256 -#define FBUF_H 256 +#define EXPR_MIN_SIZE (shm->ge.w<80 || shm->ge.h<24) +#define TEXT_MIN_SIZE "80x24" +// 80x24 xterm as rendered on Debian 10 (size doen't matter so much, keep the right ratio) +#define FBUF_W 478 +#define FBUF_H 371 #ifdef DEBUG -#define TRACE(hint) do { printf("%s(): %s\n", __func__, hint); fflush(stdout); } while(0) -#define TRACE_ONCE(hint) if (firsttime) { printf("%s(): %s\n", __func__, hint); fflush(stdout); firsttime=0; } +#define TRACE(hint) do { printf("%s(): %s\n", __func__, hint); } while(0) +#define TRACE_CALL_ONCE static int firsttime=1; if (firsttime) { printf("%s(): %s\n", __func__, "call"); firsttime=0; } #else #define TRACE(hint) -#define TRACE_ONCE(hint) +#define TRACE_CALL_ONCE #endif typedef struct { diff --git a/src/scene00.c b/src/scene00.c index f418146..976cb9f 100644 --- a/src/scene00.c +++ b/src/scene00.c @@ -52,7 +52,7 @@ void scene00_free_caca(graphical_env_t *ge, scene00_env_t *se) { } int scene00_next_gl(graphical_env_t *ge, scene00_env_t *se) { - static int firsttime=1; TRACE_ONCE("call"); + TRACE_CALL_ONCE; return 0; } @@ -60,7 +60,7 @@ int scene00_next_sdl(graphical_env_t *ge, scene00_env_t *se) { // Shorthands SDL_Renderer *r = ge->sdl_rndr; - static int firsttime=1; TRACE_ONCE("call"); + TRACE_CALL_ONCE; // https://gist.github.com/Twinklebear/8265888 // https://forums.libsdl.org/viewtopic.php?p=51634 @@ -90,7 +90,7 @@ int scene00_next_caca(graphical_env_t *ge, scene00_env_t *se) { int w = ge->w, h = ge->h; Uint32 frame = ge->sc_framecount; - static int firsttime=1; TRACE_ONCE("call"); + TRACE_CALL_ONCE; // "convert" the raw pixel stream from SDL to ASCII art on caca canevas caca_dither_bitmap(cv, 0, 0, w, h, ge->d, ge->raw_target); diff --git a/src/scene01.c b/src/scene01.c index a2f1345..39083d0 100644 --- a/src/scene01.c +++ b/src/scene01.c @@ -167,7 +167,7 @@ void scene01_free_caca(graphical_env_t *ge, scene01_env_t *se) { int scene01_next_gl(graphical_env_t *ge, scene01_env_t *se) { SDL_Renderer *r = ge->gl_rndr; - static int firsttime=1; TRACE_ONCE("call"); + TRACE_CALL_ONCE; // https://gist.github.com/Twinklebear/8265888 // https://forums.libsdl.org/viewtopic.php?p=51634 @@ -177,7 +177,7 @@ int scene01_next_gl(graphical_env_t *ge, scene01_env_t *se) { glDrawArrays(GL_TRIANGLES, 0, 6); // [...] - SDL_GL_SwapWindow(ge->gl_win); + //SDL_GL_SwapWindow(ge->gl_win); // Download the rendered texture from videocard to main memory SDL_RenderReadPixels(r, NULL, 0, ge->raw_target, FBUF_W*4); @@ -186,7 +186,7 @@ int scene01_next_gl(graphical_env_t *ge, scene01_env_t *se) { } int scene01_next_sdl(graphical_env_t *ge, scene01_env_t *se) { - static int firsttime=1; TRACE_ONCE("call"); + TRACE_CALL_ONCE; return 0; } @@ -195,7 +195,7 @@ int scene01_next_caca(graphical_env_t *ge, scene01_env_t *se) { caca_canvas_t *cv = ge->cv; int w = ge->w, h = ge->h; Uint32 frame = ge->sc_framecount; - static int firsttime=1; TRACE_ONCE("call"); + TRACE_CALL_ONCE; // "convert" the raw pixel stream from SDL to ASCII art on caca canevas caca_set_dither_gamma(ge->d, 1.0); diff --git a/src/scene02.c b/src/scene02.c index f268f1f..14629ca 100644 --- a/src/scene02.c +++ b/src/scene02.c @@ -46,14 +46,13 @@ void scene02_free_caca(graphical_env_t *ge, scene02_env_t *se) { TRACE("call"); } - int scene02_next_gl(graphical_env_t *ge, scene02_env_t *se) { - static int firsttime=1; TRACE_ONCE("call"); + TRACE_CALL_ONCE; return 0; } int scene02_next_sdl(graphical_env_t *ge, scene02_env_t *se) { - static int firsttime=1; TRACE_ONCE("call"); + TRACE_CALL_ONCE; return 0; } @@ -63,7 +62,7 @@ int scene02_next_caca(graphical_env_t *ge, scene02_env_t *se) { //int w = ge->w, h = ge->h; Uint32 frame = ge->sc_framecount; - static int firsttime=1; TRACE_ONCE("call"); + TRACE_CALL_ONCE; caca_clear_canvas(cv); |