Changeset 522


Ignore:
Timestamp:
09/22/08 02:54:07 (5 years ago)
Author:
reyalp
Message:
  • Made games compile time optional. Set or unset OPT_GAME_* in root makefile.inc
  • Moved sokoban levels from static data (gui_sokoban_levels.h) to file CHDK/GAMES/SOKOBAN.LEV

See http://chdk.setepontos.com/index.php/topic,688.msg21578.html#msg21578 for details

  • Renamed lua compile option variables CHDK_->OPT_
  • Minor tweaks in luascript
Location:
trunk
Files:
2 added
1 deleted
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/core/Makefile

    r521 r522  
    1212all: main.bin 
    1313 
     14OPT_OBJS= 
     15ifdef OPT_GAME_REVERSI 
     16CFLAGS+=-DOPT_GAME_REVERSI 
     17OPT_OBJS+=gui_reversi.o 
     18endif 
     19ifdef OPT_GAME_SOKOBAN 
     20CFLAGS+=-DOPT_GAME_SOKOBAN 
     21OPT_OBJS+=gui_sokoban.o 
     22endif 
     23 
    1424OBJS=entry.o nothumb.o main.o gui_draw.o gui_menu.o gui_palette.o gui_mbox.o \ 
    15      gui_reversi.o gui_debug.o gui_fselect.o gui_read.o gui.o kbd.o conf.o \ 
    16      histogram.o gui_batt.o gui_space.o gui_osd.o script.o curves.o raw.o gui_sokoban.o gui_calendar.o \ 
     25     gui_debug.o gui_fselect.o gui_read.o gui.o kbd.o conf.o \ 
     26     histogram.o gui_batt.o gui_space.o gui_osd.o script.o curves.o raw.o gui_calendar.o \ 
    1727     gui_lang.o gui_bench.o gui_mpopup.o gui_grid.o motion_detector.o raw_merge.o \ 
    18      luascript.o edgeoverlay.o shot_histogram.o 
     28     luascript.o edgeoverlay.o shot_histogram.o $(OPT_OBJS) 
    1929 
    2030gui.o: FORCE 
  • trunk/core/gui.c

    r521 r522  
    266266 
    267267static CMenuItem games_submenu_items[] = { 
     268#ifdef OPT_GAME_REVERSI 
    268269    {0x38,LANG_MENU_GAMES_REVERSI,           MENUITEM_PROC,  (int*)gui_draw_reversi }, 
     270#endif 
     271#ifdef OPT_GAME_SOKOBAN 
    269272    {0x38,LANG_MENU_GAMES_SOKOBAN,           MENUITEM_PROC,  (int*)gui_draw_sokoban }, 
     273#endif 
    270274    {0x51,LANG_MENU_BACK,                    MENUITEM_UP }, 
    271275    {0} 
     
    18561860            gui_mbox_draw(); 
    18571861            break; 
     1862#ifdef OPT_GAME_REVERSI 
    18581863        case GUI_MODE_REVERSI: 
    18591864            gui_reversi_draw(); 
    18601865            break; 
     1866#endif 
     1867#ifdef OPT_GAME_SOKOBAN 
    18611868        case GUI_MODE_SOKOBAN: 
    18621869            gui_sokoban_draw(); 
    18631870            break; 
     1871#endif 
    18641872        case GUI_MODE_DEBUG: 
    18651873            gui_debug_draw(); 
     
    20822090            gui_mbox_kbd_process(); 
    20832091            break; 
     2092#ifdef OPT_GAME_REVERSI 
    20842093        case GUI_MODE_REVERSI: 
    20852094            gui_reversi_kbd_process(); 
    20862095            break; 
     2096#endif 
     2097#ifdef OPT_GAME_SOKOBAN 
    20872098        case GUI_MODE_SOKOBAN: 
    20882099            gui_sokoban_kbd_process(); 
    20892100            break; 
     2101#endif 
    20902102        case GUI_MODE_DEBUG: 
    20912103            gui_debug_kbd_process(); 
     
    25392551 
    25402552//------------------------------------------------------------------- 
     2553#ifdef OPT_GAME_REVERSI 
    25412554void gui_draw_reversi(int arg) { 
    25422555    if ((mode_get()&MODE_MASK) != MODE_PLAY) { 
     
    25482561    gui_reversi_init(); 
    25492562} 
    2550  
    2551 //------------------------------------------------------------------- 
     2563#endif 
     2564 
     2565//------------------------------------------------------------------- 
     2566#ifdef OPT_GAME_SOKOBAN 
    25522567void gui_draw_sokoban(int arg) { 
    25532568    if ((mode_get()&MODE_MASK) != MODE_PLAY) { 
     
    25562571        return; 
    25572572    } 
    2558     gui_mode = GUI_MODE_SOKOBAN; 
    2559     gui_sokoban_init(); 
    2560 } 
    2561  
     2573    if ( gui_sokoban_init() ) 
     2574        gui_mode = GUI_MODE_SOKOBAN; 
     2575} 
     2576#endif 
    25622577//------------------------------------------------------------------- 
    25632578void gui_draw_debug(int arg) { 
  • trunk/core/gui_sokoban.c

    r515 r522  
    3333#define MARKER_PLAYER           '@' 
    3434#define MARKER_PLAYER_PLACE     '+' 
    35 #define MARKER_EMPTY            ' ' 
     35#define MARKER_EMPTY            '_' // was space 
     36#define MARKER_LINE_END        '\n' // was | 
     37#define MARKER_LEVEL_END        '!' 
     38 
     39#define LEVEL_CHARS "#$.*@+_" 
    3640 
    3741#define UNDO_SIZE               1000 
    3842 
    3943//------------------------------------------------------------------- 
    40 #include "gui_sokoban_levels.h" 
    41 #define NUM_LEVELS (sizeof(fields)/sizeof(fields[0])) 
     44static const char *level_file_name="A/CHDK/GAMES/SOKOBAN.LEV"; 
     45#define MAX_LEVELS 200 
     46static unsigned short level_start_list[MAX_LEVELS]; 
     47static unsigned char level_length_list[MAX_LEVELS]; 
     48static unsigned num_levels; 
    4249 
    4350static int need_redraw; 
     
    128135static void sokoban_set_level(int lvl) { 
    129136    int x=0, y, w=0, h=0; 
    130     const char *p=fields[lvl]; 
     137    const char *p; 
     138    char *buf; 
     139    int fd;     
     140    int start,len; 
     141 
     142    len=level_length_list[lvl]; 
     143    start=level_start_list[lvl]; 
     144    fd=fopen(level_file_name,"rb"); 
     145    if(!fd) { 
     146        num_levels=0; 
     147        return; 
     148    } 
     149 
     150    buf=malloc(len+1); 
     151    if(!buf) { 
     152        fclose(fd); 
     153        return; 
     154    } 
     155 
     156    if(fseek(fd,start,SEEK_SET) != 0) { 
     157        fclose(fd); 
     158        free(buf); 
     159        return; 
     160    } 
     161    fread(buf,1,len,fd); 
     162    buf[len]=0; 
     163    fclose(fd); 
     164 
     165    p=buf; 
    131166 
    132167    // determine dimensions 
    133168    while (*p) { 
    134       if (*p=='|') { 
     169      if (*p==MARKER_LINE_END) { 
    135170          ++h; 
    136171          if (x>w) w=x; 
     
    142177    } 
    143178    if (x>w) w=x; 
     179    h-=1; //the last line didn't previously have an end marker 
    144180 
    145181    // clear field 
     
    149185     
    150186    // place maze at the center 
    151     p=fields[lvl]; 
     187    p=buf; 
    152188    for (y=(FIELD_HEIGHT-h)/2; y<FIELD_HEIGHT; ++y, ++p) { 
    153         for (x=(FIELD_WIDTH-w)/2; x<FIELD_WIDTH && *p && *p!='|'; ++x, ++p) { 
     189        for (x=(FIELD_WIDTH-w)/2; x<FIELD_WIDTH && *p && *p!=MARKER_LINE_END; ++x, ++p) { 
    154190            field[y][x]=*p; 
    155191            if (field[y][x] == MARKER_PLAYER || field[y][x] == MARKER_PLAYER_PLACE) { 
     
    157193            } 
    158194        } 
    159         if (!*p) break; 
    160     } 
    161  
     195        if (!*p || (*p == MARKER_LINE_END && !*(p+1))) break; 
     196    } 
     197     
     198    free(buf); 
    162199    conf.sokoban_level = lvl; 
    163200    moves = 0; 
     
    178215//------------------------------------------------------------------- 
    179216static void sokoban_next_level() { 
    180     if (++conf.sokoban_level >= NUM_LEVELS) conf.sokoban_level = 0; 
     217    if (++conf.sokoban_level >= num_levels) conf.sokoban_level = 0; 
    181218    sokoban_set_level(conf.sokoban_level); 
    182219    need_redraw = 1; 
     
    221258 
    222259//------------------------------------------------------------------- 
    223 void gui_sokoban_init() { 
     260int gui_sokoban_init() { 
     261    /* first time through, load the file and make an index 
     262     if would could tell when the user left sokoban,  
     263     we could avoid this and malloc all the data structures 
     264     unfortunately, gui_mode gets set all over the place */ 
     265    if(!num_levels) { 
     266        char *buf,*p,*p_start; 
     267        int fd;     
     268        struct stat st; 
     269        int prev_index = 0; 
     270 
     271        if (stat((char *)level_file_name,&st) != 0 || st.st_size==0)  
     272            return 0; 
     273 
     274        fd=fopen(level_file_name,"rb"); 
     275        if(!fd)  
     276            return 0; 
     277 
     278        buf=malloc(st.st_size+1); 
     279        if(!buf) { 
     280            fclose(fd); 
     281            return 0; 
     282        } 
     283 
     284        fread(buf,1,st.st_size,fd); 
     285        buf[st.st_size]=0; 
     286        fclose(fd); 
     287        p = buf; 
     288        do { 
     289            // skip to the first level char 
     290            p = strpbrk(p,LEVEL_CHARS); 
     291            // found a level char, store the start 
     292            if (p) { 
     293                unsigned pos = p - buf; 
     294                if ( pos > 65535 ) { 
     295                    break; 
     296                } 
     297                level_start_list[num_levels] = (unsigned short)pos; 
     298                p=strchr(p,MARKER_LEVEL_END); 
     299                // found the end char, store the end 
     300                if(p) { 
     301                    unsigned len = p - (buf + level_start_list[num_levels]); 
     302                    // bail on invalid level 
     303                    if ( len > 255 ) { 
     304                        break; 
     305                    } 
     306                    level_length_list[num_levels] = (unsigned char)len; 
     307                    ++num_levels; 
     308                } 
     309            } 
     310        } while(p && num_levels < MAX_LEVELS); 
     311        free(buf); 
     312    } 
     313    if(!num_levels) { 
     314        return 0; 
     315    } 
     316    else if(conf.sokoban_level >= num_levels) { 
     317        conf.sokoban_level = 0; 
     318    } 
    224319    cell_size = screen_height/FIELD_HEIGHT; 
    225320    sokoban_set_level(conf.sokoban_level); 
     321        // if the file is no longer readable, set_level will set this 
     322    if(!num_levels) { 
     323        return 0; 
     324    } 
    226325    need_redraw = 1; 
     326    return 1; 
    227327} 
    228328 
  • trunk/core/gui_sokoban.h

    r515 r522  
    33 
    44//------------------------------------------------------------------- 
    5 extern void gui_sokoban_init(); 
     5extern int gui_sokoban_init(); 
    66extern void gui_sokoban_kbd_process(); 
    77extern void gui_sokoban_draw(); 
  • trunk/core/luascript.c

    r520 r522  
    574574static int luaCB_get_propset( lua_State* L ) 
    575575{ 
    576   int to; 
    577   #if CAM_PROPSET == 1 
    578   to = 1; 
    579   #elif CAM_PROPSET == 2 
    580   to = 2; 
    581   #endif 
    582   lua_pushnumber( L, to ); 
     576  lua_pushnumber( L, CAM_PROPSET ); 
    583577  return 1; 
    584578} 
     
    747741static int luaCB_get_buildinfo( lua_State* L ) 
    748742{ 
    749   lua_createtable(L, 0, 6);  /* 9 = number of fields */ 
     743  lua_createtable(L, 0, 6);  /* 6 = number of fields */ 
    750744  set_string_field( L,"platform", PLATFORM ); 
    751745  set_string_field( L,"platsub", PLATFORMSUB ); 
  • trunk/lib/lua/Makefile

    r517 r522  
    77LUA_OPTLIB_OBJS= 
    88 
    9 ifdef CHDK_LUA_IOLIB 
    10 CFLAGS+=-DCHDK_LUA_IOLIB 
     9ifdef OPT_LUA_IOLIB 
     10CFLAGS+=-DOPT_LUA_IOLIB 
    1111LUA_OPTLIB_OBJS+=liolib.o 
    1212endif 
    1313 
    14 ifdef CHDK_LUA_OSLIB 
    15 CFLAGS+=-DCHDK_LUA_OSLIB 
     14ifdef OPT_LUA_OSLIB 
     15CFLAGS+=-DOPT_LUA_OSLIB 
    1616LUA_OPTLIB_OBJS+=loslib.o 
    1717endif 
    1818 
    19 ifdef CHDK_LUA_STRLIB 
    20 CFLAGS+=-DCHDK_LUA_STRLIB 
     19ifdef OPT_LUA_STRLIB 
     20CFLAGS+=-DOPT_LUA_STRLIB 
    2121LUA_OPTLIB_OBJS+=lstrlib.o 
    2222endif 
  • trunk/lib/lua/linit.c

    r517 r522  
    1919  {LUA_LOADLIBNAME, luaopen_package}, 
    2020  {LUA_TABLIBNAME, luaopen_table}, 
    21 #ifdef CHDK_LUA_IOLIB 
     21#ifdef OPT_LUA_IOLIB 
    2222  {LUA_IOLIBNAME, luaopen_io}, 
    2323#endif 
    24 #ifdef CHDK_LUA_OSLIB 
     24#ifdef OPT_LUA_OSLIB 
    2525  {LUA_OSLIBNAME, luaopen_os}, 
    2626#endif 
    27 #ifdef CHDK_LUA_STRLIB 
     27#ifdef OPT_LUA_STRLIB 
    2828  //  {LUA_STRLIBNAME, luaopen_string}, 
    2929#endif 
  • trunk/makefile.inc

    r521 r522  
    161161 
    162162# build time optional components 
    163 CHDK_LUA_IOLIB=1 
    164 CHDK_LUA_OSLIB=1 
    165 #CHDK_LUA_STRLIB=1 
     163OPT_LUA_IOLIB=1 
     164OPT_LUA_OSLIB=1 
     165#OPT_LUA_STRLIB=1 
     166OPT_GAME_REVERSI=1 
     167OPT_GAME_SOKOBAN=1 
    166168 
    167169MEMISOSIZE="(&_end-&_start)" 
  • trunk/platform/a450/sub/100d/makefile.inc

    r521 r522  
    1111 
    1212#temp until we get a dump 
    13 CHDK_LUA_IOLIB= 
    14 CHDK_LUA_OSLIB= 
    15 CHDK_LUA_STRLIB= 
     13OPT_LUA_IOLIB= 
     14OPT_LUA_OSLIB= 
     15OPT_LUA_STRLIB= 
    1616 
    1717TARGET_PRIMARY=$(topdir)platform/$(PLATFORM)/sub/$(PLATFORMSUB)/PRIMARY.BIN 
  • trunk/platform/tx1/sub/100g/makefile.inc

    r521 r522  
    1111 
    1212#temp until we get a dump 
    13 CHDK_LUA_IOLIB= 
    14 CHDK_LUA_OSLIB= 
    15 CHDK_LUA_STRLIB= 
     13OPT_LUA_IOLIB= 
     14OPT_LUA_OSLIB= 
     15OPT_LUA_STRLIB= 
    1616 
    1717TARGET_PRIMARY=$(topdir)platform/$(PLATFORM)/sub/$(PLATFORMSUB)/PRIMARY.BIN 
Note: See TracChangeset for help on using the changeset viewer.