Changeset 522
- Timestamp:
- 09/22/08 02:54:07 (5 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 1 deleted
- 10 edited
-
CHDK/GAMES (added)
-
CHDK/GAMES/SOKOBAN.LEV (added)
-
core/Makefile (modified) (1 diff)
-
core/gui.c (modified) (6 diffs)
-
core/gui_sokoban.c (modified) (7 diffs)
-
core/gui_sokoban.h (modified) (1 diff)
-
core/gui_sokoban_levels.h (deleted)
-
core/luascript.c (modified) (2 diffs)
-
lib/lua/Makefile (modified) (1 diff)
-
lib/lua/linit.c (modified) (1 diff)
-
makefile.inc (modified) (1 diff)
-
platform/a450/sub/100d/makefile.inc (modified) (1 diff)
-
platform/tx1/sub/100g/makefile.inc (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/core/Makefile
r521 r522 12 12 all: main.bin 13 13 14 OPT_OBJS= 15 ifdef OPT_GAME_REVERSI 16 CFLAGS+=-DOPT_GAME_REVERSI 17 OPT_OBJS+=gui_reversi.o 18 endif 19 ifdef OPT_GAME_SOKOBAN 20 CFLAGS+=-DOPT_GAME_SOKOBAN 21 OPT_OBJS+=gui_sokoban.o 22 endif 23 14 24 OBJS=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 \ 17 27 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) 19 29 20 30 gui.o: FORCE -
trunk/core/gui.c
r521 r522 266 266 267 267 static CMenuItem games_submenu_items[] = { 268 #ifdef OPT_GAME_REVERSI 268 269 {0x38,LANG_MENU_GAMES_REVERSI, MENUITEM_PROC, (int*)gui_draw_reversi }, 270 #endif 271 #ifdef OPT_GAME_SOKOBAN 269 272 {0x38,LANG_MENU_GAMES_SOKOBAN, MENUITEM_PROC, (int*)gui_draw_sokoban }, 273 #endif 270 274 {0x51,LANG_MENU_BACK, MENUITEM_UP }, 271 275 {0} … … 1856 1860 gui_mbox_draw(); 1857 1861 break; 1862 #ifdef OPT_GAME_REVERSI 1858 1863 case GUI_MODE_REVERSI: 1859 1864 gui_reversi_draw(); 1860 1865 break; 1866 #endif 1867 #ifdef OPT_GAME_SOKOBAN 1861 1868 case GUI_MODE_SOKOBAN: 1862 1869 gui_sokoban_draw(); 1863 1870 break; 1871 #endif 1864 1872 case GUI_MODE_DEBUG: 1865 1873 gui_debug_draw(); … … 2082 2090 gui_mbox_kbd_process(); 2083 2091 break; 2092 #ifdef OPT_GAME_REVERSI 2084 2093 case GUI_MODE_REVERSI: 2085 2094 gui_reversi_kbd_process(); 2086 2095 break; 2096 #endif 2097 #ifdef OPT_GAME_SOKOBAN 2087 2098 case GUI_MODE_SOKOBAN: 2088 2099 gui_sokoban_kbd_process(); 2089 2100 break; 2101 #endif 2090 2102 case GUI_MODE_DEBUG: 2091 2103 gui_debug_kbd_process(); … … 2539 2551 2540 2552 //------------------------------------------------------------------- 2553 #ifdef OPT_GAME_REVERSI 2541 2554 void gui_draw_reversi(int arg) { 2542 2555 if ((mode_get()&MODE_MASK) != MODE_PLAY) { … … 2548 2561 gui_reversi_init(); 2549 2562 } 2550 2551 //------------------------------------------------------------------- 2563 #endif 2564 2565 //------------------------------------------------------------------- 2566 #ifdef OPT_GAME_SOKOBAN 2552 2567 void gui_draw_sokoban(int arg) { 2553 2568 if ((mode_get()&MODE_MASK) != MODE_PLAY) { … … 2556 2571 return; 2557 2572 } 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 2562 2577 //------------------------------------------------------------------- 2563 2578 void gui_draw_debug(int arg) { -
trunk/core/gui_sokoban.c
r515 r522 33 33 #define MARKER_PLAYER '@' 34 34 #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 "#$.*@+_" 36 40 37 41 #define UNDO_SIZE 1000 38 42 39 43 //------------------------------------------------------------------- 40 #include "gui_sokoban_levels.h" 41 #define NUM_LEVELS (sizeof(fields)/sizeof(fields[0])) 44 static const char *level_file_name="A/CHDK/GAMES/SOKOBAN.LEV"; 45 #define MAX_LEVELS 200 46 static unsigned short level_start_list[MAX_LEVELS]; 47 static unsigned char level_length_list[MAX_LEVELS]; 48 static unsigned num_levels; 42 49 43 50 static int need_redraw; … … 128 135 static void sokoban_set_level(int lvl) { 129 136 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; 131 166 132 167 // determine dimensions 133 168 while (*p) { 134 if (*p== '|') {169 if (*p==MARKER_LINE_END) { 135 170 ++h; 136 171 if (x>w) w=x; … … 142 177 } 143 178 if (x>w) w=x; 179 h-=1; //the last line didn't previously have an end marker 144 180 145 181 // clear field … … 149 185 150 186 // place maze at the center 151 p= fields[lvl];187 p=buf; 152 188 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) { 154 190 field[y][x]=*p; 155 191 if (field[y][x] == MARKER_PLAYER || field[y][x] == MARKER_PLAYER_PLACE) { … … 157 193 } 158 194 } 159 if (!*p) break; 160 } 161 195 if (!*p || (*p == MARKER_LINE_END && !*(p+1))) break; 196 } 197 198 free(buf); 162 199 conf.sokoban_level = lvl; 163 200 moves = 0; … … 178 215 //------------------------------------------------------------------- 179 216 static 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; 181 218 sokoban_set_level(conf.sokoban_level); 182 219 need_redraw = 1; … … 221 258 222 259 //------------------------------------------------------------------- 223 void gui_sokoban_init() { 260 int 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 } 224 319 cell_size = screen_height/FIELD_HEIGHT; 225 320 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 } 226 325 need_redraw = 1; 326 return 1; 227 327 } 228 328 -
trunk/core/gui_sokoban.h
r515 r522 3 3 4 4 //------------------------------------------------------------------- 5 extern voidgui_sokoban_init();5 extern int gui_sokoban_init(); 6 6 extern void gui_sokoban_kbd_process(); 7 7 extern void gui_sokoban_draw(); -
trunk/core/luascript.c
r520 r522 574 574 static int luaCB_get_propset( lua_State* L ) 575 575 { 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 ); 583 577 return 1; 584 578 } … … 747 741 static int luaCB_get_buildinfo( lua_State* L ) 748 742 { 749 lua_createtable(L, 0, 6); /* 9= number of fields */743 lua_createtable(L, 0, 6); /* 6 = number of fields */ 750 744 set_string_field( L,"platform", PLATFORM ); 751 745 set_string_field( L,"platsub", PLATFORMSUB ); -
trunk/lib/lua/Makefile
r517 r522 7 7 LUA_OPTLIB_OBJS= 8 8 9 ifdef CHDK_LUA_IOLIB10 CFLAGS+=-D CHDK_LUA_IOLIB9 ifdef OPT_LUA_IOLIB 10 CFLAGS+=-DOPT_LUA_IOLIB 11 11 LUA_OPTLIB_OBJS+=liolib.o 12 12 endif 13 13 14 ifdef CHDK_LUA_OSLIB15 CFLAGS+=-D CHDK_LUA_OSLIB14 ifdef OPT_LUA_OSLIB 15 CFLAGS+=-DOPT_LUA_OSLIB 16 16 LUA_OPTLIB_OBJS+=loslib.o 17 17 endif 18 18 19 ifdef CHDK_LUA_STRLIB20 CFLAGS+=-D CHDK_LUA_STRLIB19 ifdef OPT_LUA_STRLIB 20 CFLAGS+=-DOPT_LUA_STRLIB 21 21 LUA_OPTLIB_OBJS+=lstrlib.o 22 22 endif -
trunk/lib/lua/linit.c
r517 r522 19 19 {LUA_LOADLIBNAME, luaopen_package}, 20 20 {LUA_TABLIBNAME, luaopen_table}, 21 #ifdef CHDK_LUA_IOLIB21 #ifdef OPT_LUA_IOLIB 22 22 {LUA_IOLIBNAME, luaopen_io}, 23 23 #endif 24 #ifdef CHDK_LUA_OSLIB24 #ifdef OPT_LUA_OSLIB 25 25 {LUA_OSLIBNAME, luaopen_os}, 26 26 #endif 27 #ifdef CHDK_LUA_STRLIB27 #ifdef OPT_LUA_STRLIB 28 28 // {LUA_STRLIBNAME, luaopen_string}, 29 29 #endif -
trunk/makefile.inc
r521 r522 161 161 162 162 # build time optional components 163 CHDK_LUA_IOLIB=1 164 CHDK_LUA_OSLIB=1 165 #CHDK_LUA_STRLIB=1 163 OPT_LUA_IOLIB=1 164 OPT_LUA_OSLIB=1 165 #OPT_LUA_STRLIB=1 166 OPT_GAME_REVERSI=1 167 OPT_GAME_SOKOBAN=1 166 168 167 169 MEMISOSIZE="(&_end-&_start)" -
trunk/platform/a450/sub/100d/makefile.inc
r521 r522 11 11 12 12 #temp until we get a dump 13 CHDK_LUA_IOLIB=14 CHDK_LUA_OSLIB=15 CHDK_LUA_STRLIB=13 OPT_LUA_IOLIB= 14 OPT_LUA_OSLIB= 15 OPT_LUA_STRLIB= 16 16 17 17 TARGET_PRIMARY=$(topdir)platform/$(PLATFORM)/sub/$(PLATFORMSUB)/PRIMARY.BIN -
trunk/platform/tx1/sub/100g/makefile.inc
r521 r522 11 11 12 12 #temp until we get a dump 13 CHDK_LUA_IOLIB=14 CHDK_LUA_OSLIB=15 CHDK_LUA_STRLIB=13 OPT_LUA_IOLIB= 14 OPT_LUA_OSLIB= 15 OPT_LUA_STRLIB= 16 16 17 17 TARGET_PRIMARY=$(topdir)platform/$(PLATFORM)/sub/$(PLATFORMSUB)/PRIMARY.BIN
Note: See TracChangeset
for help on using the changeset viewer.