# HG changeset patch # User John Tsiombikas # Date 1305081277 -10800 # Node ID 0c13a30be2c1dc73f199adf316a9d7da1520d21d # Parent 40491760d6e38dace21a87d32d306315e86ba548 wsys diff -r 40491760d6e3 -r 0c13a30be2c1 Makefile --- a/Makefile Tue May 10 00:06:20 2011 +0300 +++ b/Makefile Wed May 11 05:34:37 2011 +0300 @@ -22,7 +22,7 @@ AR = ar CC = gcc -CFLAGS = -pedantic -Wall -g -Iinclude +CFLAGS = -pedantic -Wall -g -fPIC -Iinclude -Isrc .PHONY: all all: $(lib_so) $(lib_a) diff -r 40491760d6e3 -r 0c13a30be2c1 include/sgl.h --- a/include/sgl.h Tue May 10 00:06:20 2011 +0300 +++ b/include/sgl.h Wed May 11 05:34:37 2011 +0300 @@ -20,11 +20,14 @@ SGL_NUM_CALLBACKS }; +int sgl_init(void); +void sgl_shutdown(void); + int sgl_set_video_mode(int xsz, int ysz, int bpp); int sgl_get_video_mode(int *xsz, int *ysz, int *bpp); -int sgl_window(int x, int y, unsigned int mode); -void sgl_close(int win); +int sgl_window(int xsz, int ysz, unsigned int mode); +void sgl_close_window(int win); int sgl_push_callbacks(void); int sgl_pop_callbacks(void); diff -r 40491760d6e3 -r 0c13a30be2c1 src/sgl.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/sgl.c Wed May 11 05:34:37 2011 +0300 @@ -0,0 +1,29 @@ +#include "sgl.h" + +int sgl_init(void) +{ + /*if(wsys_init() <= 0) { + fprintf(stderr, "no window system modules found\n"); + return -1; + }*/ + return 0; +} + +int sgl_set_video_mode(int xsz, int ysz, int bpp) +{ + return 0; +} + +int sgl_get_video_mode(int *xsz, int *ysz, int *bpp) +{ + return 0; +} + +int sgl_window(int x, int y, unsigned int mode) +{ + return 0; +} + +void sgl_close(int win) +{ +} diff -r 40491760d6e3 -r 0c13a30be2c1 src/wsys.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/wsys.c Wed May 11 05:34:37 2011 +0300 @@ -0,0 +1,66 @@ +#include +#include "wsys.h" + +struct wsys_module *wslist; +int wscount; + +int sgl_register_module(struct wsys_module *ws) +{ + ws->next = wslist; + wslist = ws; + wscount++; + return 0; +} + +#define APPEND(node) \ + do { \ + if(!res) { \ + res = tail = node; \ + } else { \ + tail->next = (node); \ + tail = (node); \ + } \ + (node) = (node)->next; \ + tail->next = 0; \ + } while(0) + +static struct wsys_module *merge(struct wsys_module *list1, struct wsys_module *list2) +{ + struct wsys_module *res, *tail; + + res = tail = 0; + + while(list1 || list2) { + if(list1 && list2) { + if(list1->prio <= list2->prio) { + APPEND(list1); + } else { + APPEND(list2); + } + } else if(list1) { + APPEND(list1); + } else { + APPEND(list2); + } + } + return res; +} + +static struct wsys_module *msort(struct wsys_module *list, int count) +{ + int i, mid = count / 2; + struct wsys_module *prev, *list2 = list; + + if(!list->next) { + return list; + } + for(i=0; inext; + } + prev->next = 0; + + list = msort(list, mid); + list2 = msort(list2, count - mid); + return merge(list, list2); +} diff -r 40491760d6e3 -r 0c13a30be2c1 src/wsys.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/wsys.h Wed May 11 05:34:37 2011 +0300 @@ -0,0 +1,24 @@ +#ifndef WSYS_H_ +#define WSYS_H_ + +struct wsys_module { + char *name; + int prio; + + int (*init)(void); + void (*shutdown)(void); + + int (*set_vidmode)(int, int, int); + int (*get_vidmode)(int*, int*, int*); + int (*window)(int, int, unsigned int); + void (*close_win)(int); + + struct wsys_module *next; +}; + +int sgl_register_module(struct wsys_module *ws); +struct wsys_module *sgl_wsys_module(void); + +void dbg(void); + +#endif /* WSYS_H_ */