diff options
author | Ludovic Pouzenc <ludovic@pouzenc.fr> | 2019-09-07 00:32:19 +0200 |
---|---|---|
committer | Ludovic Pouzenc <ludovic@pouzenc.fr> | 2019-09-07 00:32:19 +0200 |
commit | df3ce9eb9e0d8633cdb32a0106a5aa1ca9300e2b (patch) | |
tree | 38ded5717f8f9d48060e3bbdd8daa929ecbbd090 | |
parent | 5fc35fb36f6658dc486bf2c5e05510c575f3efec (diff) | |
download | demoscene-eo-df3ce9eb9e0d8633cdb32a0106a5aa1ca9300e2b.tar.gz demoscene-eo-df3ce9eb9e0d8633cdb32a0106a5aa1ca9300e2b.tar.bz2 demoscene-eo-df3ce9eb9e0d8633cdb32a0106a5aa1ca9300e2b.zip |
Multi-process is quite there. Need to call init_sdl() and init_gl()..
-rw-r--r-- | src/main.c | 34 | ||||
-rw-r--r-- | src/main.h | 11 | ||||
-rw-r--r-- | src/scene00.c | 18 | ||||
-rw-r--r-- | src/scene00.h | 8 | ||||
-rw-r--r-- | src/scene01.c | 20 | ||||
-rw-r--r-- | src/scene01.h | 8 | ||||
-rw-r--r-- | src/scene02.c | 19 | ||||
-rw-r--r-- | src/scene02.h | 8 |
8 files changed, 90 insertions, 36 deletions
@@ -18,6 +18,9 @@ * along with demoscene-eo. If not, see <http://www.gnu.org/licenses/> */ #include "main.h" +#include "scene00.h" +#include "scene01.h" +#include "scene02.h" #include <stdlib.h> // calloc() #include <strings.h> // bzero() @@ -29,6 +32,7 @@ #include <stdint.h> // uint32_t #include <stdio.h> // printf() + #define TRACE(hint) printf("%s(): %s\n", __func__, hint) #define SCENE_COUNT 3 #define SCENE_NEXT do { shm->scene = (shm->scene+1)%SCENE_COUNT; } while(0) @@ -38,15 +42,14 @@ #define SEM_POST(sem,errcode) \ do { \ - printf("%s(): sem_post(%s,%i) call\n", __func__, #sem, errcode);\ + /* printf("%s(): sem_post(%s,%i)\n", __func__, #sem, errcode); */ \ if ( sem_post(sem) == -1 ) { return errcode; } \ - printf("%s(): sem_post(%s,%i) done\n", __func__, #sem, errcode);\ } while(0) #define SEM_WAIT(sem,errcode) \ do { \ - printf("%s(): sem_wait(%s,%i) call\n", __func__, #sem, errcode);\ - while ( sem_wait(&shm->parent_can_read_result) == -1 ) { \ + /* printf("%s(): sem_wait(%s,%i) call\n", __func__, #sem, errcode); */\ + while ( sem_wait(sem) == -1 ) { \ switch(errno) { \ case EINTR: \ case EAGAIN: \ @@ -55,7 +58,7 @@ return errcode; \ } \ } \ - printf("%s(): sem_wait(%s,%i) done\n", __func__, #sem, errcode);\ + /* printf("%s(): sem_wait(%s,%i) done\n", __func__, #sem, errcode); */\ } while(0) typedef struct { @@ -85,9 +88,6 @@ int main() { if (sem_init(&shm->worker_sdl_can_render, 1, 0) < 0) return 3; if (sem_init(&shm->parent_can_read_result, 1, 0) < 0) return 4; - shm->ge.raw_target = calloc(FBUF_W*FBUF_H, sizeof(uint32_t)); - if ( shm->ge.raw_target == NULL ) return 5; - return do_fork1(); } @@ -129,6 +129,7 @@ int parent() { // Main libcaca loop for caca window shm->ge.framecount=0; do { + // Check canvas size at every frame because of unreliable CACA_EVENT_RESIZE shm->ge.w = caca_get_canvas_width(shm->ge.cv); shm->ge.h = caca_get_canvas_height(shm->ge.cv); @@ -139,18 +140,20 @@ int parent() { // init / free if scene transition if ( lastscene != shm->scene ) { switch(lastscene) { - case 0: scene00_free(&shm->ge, &shm->s00e); break; - case 1: scene01_free(&shm->ge, &shm->s01e); break; - case 2: scene02_free(&shm->ge, &shm->s02e); break; + //FIXME call free_gl and free_sdl in respective processes too + 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 ) { shm->ge.sdl_ticks = SDL_GetTicks(); shm->ge.sc_framecount = 0; switch(shm->scene) { - case 0: res = scene00_init(&shm->ge, &shm->s00e); break; - case 1: res = scene01_init(&shm->ge, &shm->s01e); break; - case 2: res = scene02_init(&shm->ge, &shm->s02e); break; + //FIXME call init_gl and init_sdl in respective processes too + case 0: res = scene00_init_caca(&shm->ge, &shm->s00e); break; + case 1: res = scene01_init_caca(&shm->ge, &shm->s01e); break; + case 2: res = scene02_init_caca(&shm->ge, &shm->s02e); break; } // If scene init fail, skip to the next one if (res) SCENE_NEXT; else lastscene = shm->scene; @@ -304,7 +307,7 @@ int worker_gl() { SDL_GL_SetAttribute( SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE ); // Initialize OpenGL - shm->ge.gl_win = SDL_CreateWindow("GL Debug", 0, SDL_WINDOWPOS_CENTERED, FBUF_W, FBUF_H, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN ); + shm->ge.gl_win = SDL_CreateWindow("GL Debug", SDL_WINDOWPOS_CENTERED, 0, FBUF_W, FBUF_H, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN ); shm->ge.gl_ctx = SDL_GL_CreateContext(shm->ge.gl_win); if ( shm->ge.gl_ctx == NULL ) return 11; @@ -320,7 +323,6 @@ int worker_gl() { } if (res) SCENE_NEXT; - // Event handling for the GL window (debug purposes) while(SDL_PollEvent(&gl_ev)) { switch(gl_ev.type) { @@ -8,6 +8,9 @@ #include <SDL2/SDL_opengl.h> #include <GL/glu.h> +#define FBUF_W 256 +#define FBUF_H 256 + typedef struct { // libcaca caca_display_t *dp; @@ -22,17 +25,11 @@ typedef struct { SDL_Window* gl_win; SDL_GLContext gl_ctx; // framebuffer to inject OpenGL or SDL result in caca canvas - uint32_t *raw_target; + uint32_t raw_target[FBUF_W*FBUF_H]; // Timing Uint32 sdl_ticks; Uint32 framecount; Uint32 sc_framecount; } graphical_env_t; -#define FBUF_W 256 -#define FBUF_H 256 - -#include "scene00.h" -#include "scene01.h" -#include "scene02.h" #endif diff --git a/src/scene00.c b/src/scene00.c index 7bb1738..b1e4e57 100644 --- a/src/scene00.c +++ b/src/scene00.c @@ -19,7 +19,11 @@ */ #include "scene00.h" -int scene00_init(graphical_env_t *ge, scene00_env_t *se) { +int scene00_init_gl(graphical_env_t *ge, scene00_env_t *se) { + return 0; +} + +int scene00_init_sdl(graphical_env_t *ge, scene00_env_t *se) { SDL_Surface *bmpSurf = SDL_LoadBMP("./res/eo1.bmp"); se->eo1 = SDL_CreateTextureFromSurface(ge->sdl_rndr, bmpSurf); SDL_FreeSurface(bmpSurf); @@ -27,10 +31,20 @@ int scene00_init(graphical_env_t *ge, scene00_env_t *se) { return 0; } -void scene00_free(graphical_env_t *ge, scene00_env_t *se) { +int scene00_init_caca(graphical_env_t *ge, scene00_env_t *se) { + return 0; +} + +void scene00_free_gl(graphical_env_t *ge, scene00_env_t *se) { +} + +void scene00_free_sdl(graphical_env_t *ge, scene00_env_t *se) { SDL_DestroyTexture(se->eo1); se->eo1=NULL; } +void scene00_free_caca(graphical_env_t *ge, scene00_env_t *se) { +} + int scene00_next_gl(graphical_env_t *ge, scene00_env_t *se) { return 0; } diff --git a/src/scene00.h b/src/scene00.h index ec6eb9a..2be36b7 100644 --- a/src/scene00.h +++ b/src/scene00.h @@ -6,8 +6,12 @@ typedef struct { SDL_Texture *eo1; } scene00_env_t; -int scene00_init(graphical_env_t *ge, scene00_env_t *se); -void scene00_free(graphical_env_t *ge, scene00_env_t *se); +int scene00_init_gl(graphical_env_t *ge, scene00_env_t *se); +int scene00_init_sdl(graphical_env_t *ge, scene00_env_t *se); +int scene00_init_caca(graphical_env_t *ge, scene00_env_t *se); +void scene00_free_gl(graphical_env_t *ge, scene00_env_t *se); +void scene00_free_sdl(graphical_env_t *ge, scene00_env_t *se); +void scene00_free_caca(graphical_env_t *ge, scene00_env_t *se); int scene00_next_gl(graphical_env_t *ge, scene00_env_t *se); int scene00_next_sdl(graphical_env_t *ge, scene00_env_t *se); int scene00_next_caca(graphical_env_t *ge, scene00_env_t *se); diff --git a/src/scene01.c b/src/scene01.c index b817e71..527e81a 100644 --- a/src/scene01.c +++ b/src/scene01.c @@ -74,7 +74,7 @@ typedef enum t_attrib_id attrib_color } t_attrib_id; -int scene01_init(graphical_env_t *ge, scene01_env_t *se) { +int scene01_init_gl(graphical_env_t *ge, scene01_env_t *se) { GLuint vs, fs, program; vs = glCreateShader( GL_VERTEX_SHADER ); @@ -150,8 +150,22 @@ int scene01_init(graphical_env_t *ge, scene01_env_t *se) { return 0; } -void scene01_free(graphical_env_t *ge, scene01_env_t *se) { - //FIXME scene00 cannot be rendered coorectly after scene01_init done once +int scene01_init_sdl(graphical_env_t *ge, scene01_env_t *se) { + return 0; +} + +int scene01_init_caca(graphical_env_t *ge, scene01_env_t *se) { + return 0; +} + +void scene01_free_gl(graphical_env_t *ge, scene01_env_t *se) { + //TODO +} + +void scene01_free_sdl(graphical_env_t *ge, scene01_env_t *se) { +} + +void scene01_free_caca(graphical_env_t *ge, scene01_env_t *se) { } int scene01_next_gl(graphical_env_t *ge, scene01_env_t *se) { diff --git a/src/scene01.h b/src/scene01.h index f6544fb..a8b5312 100644 --- a/src/scene01.h +++ b/src/scene01.h @@ -6,8 +6,12 @@ typedef struct { GLuint vao; } scene01_env_t; -int scene01_init(graphical_env_t *ge, scene01_env_t *se); -void scene01_free(graphical_env_t *ge, scene01_env_t *se); +int scene01_init_gl(graphical_env_t *ge, scene01_env_t *se); +int scene01_init_sdl(graphical_env_t *ge, scene01_env_t *se); +int scene01_init_caca(graphical_env_t *ge, scene01_env_t *se); +void scene01_free_gl(graphical_env_t *ge, scene01_env_t *se); +void scene01_free_sdl(graphical_env_t *ge, scene01_env_t *se); +void scene01_free_caca(graphical_env_t *ge, scene01_env_t *se); int scene01_next_gl(graphical_env_t *ge, scene01_env_t *se); int scene01_next_sdl(graphical_env_t *ge, scene01_env_t *se); int scene01_next_caca(graphical_env_t *ge, scene01_env_t *se); diff --git a/src/scene02.c b/src/scene02.c index e8e7340..b947234 100644 --- a/src/scene02.c +++ b/src/scene02.c @@ -19,13 +19,28 @@ */ #include "scene02.h" -int scene02_init(graphical_env_t *ge, scene02_env_t *se) { +int scene02_init_gl(graphical_env_t *ge, scene02_env_t *se) { return 0; } -void scene02_free(graphical_env_t *ge, scene02_env_t *se) { +int scene02_init_sdl(graphical_env_t *ge, scene02_env_t *se) { + return 0; +} + +int scene02_init_caca(graphical_env_t *ge, scene02_env_t *se) { + return 0; +} + +void scene02_free_gl(graphical_env_t *ge, scene02_env_t *se) { } +void scene02_free_sdl(graphical_env_t *ge, scene02_env_t *se) { +} + +void scene02_free_caca(graphical_env_t *ge, scene02_env_t *se) { +} + + int scene02_next_gl(graphical_env_t *ge, scene02_env_t *se) { return 0; } diff --git a/src/scene02.h b/src/scene02.h index 7032d50..17c67b3 100644 --- a/src/scene02.h +++ b/src/scene02.h @@ -6,8 +6,12 @@ typedef struct { } scene02_env_t; -int scene02_init(graphical_env_t *ge, scene02_env_t *se); -void scene02_free(graphical_env_t *ge, scene02_env_t *se); +int scene02_init_gl(graphical_env_t *ge, scene02_env_t *se); +int scene02_init_sdl(graphical_env_t *ge, scene02_env_t *se); +int scene02_init_caca(graphical_env_t *ge, scene02_env_t *se); +void scene02_free_gl(graphical_env_t *ge, scene02_env_t *se); +void scene02_free_sdl(graphical_env_t *ge, scene02_env_t *se); +void scene02_free_caca(graphical_env_t *ge, scene02_env_t *se); int scene02_next_gl(graphical_env_t *ge, scene02_env_t *se); int scene02_next_sdl(graphical_env_t *ge, scene02_env_t *se); int scene02_next_caca(graphical_env_t *ge, scene02_env_t *se); |