Overview
Comment: | Types, bug fixes, and test mode |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
3df78ec087d196b27c71c781e45e8988 |
User & Date: | user on 2018-04-08 23:31:47 |
Other Links: | manifest | tags |
Context
2018-04-09
| ||
04:15 | Faster key bindings, and testing for key bindings check-in: c8eb0a9e48 user: user tags: trunk | |
2018-04-08
| ||
23:31 | Types, bug fixes, and test mode check-in: 3df78ec087 user: user tags: trunk | |
2018-04-06
| ||
21:00 | Add init_screen() and starting the type defintions for classes, and fix the picture loader to work with zoomed pictures check-in: 88e748ef6d user: user tags: trunk | |
Changes
Modified heromesh.h from [89443417d7] to [0f695d01fc].
1 2 3 4 | /* This file is part of Free Hero Mesh and is public domain. */ | | > > > > > > > > > > > > > > > > > > > > > > > | | > | | | | | | | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | /* This file is part of Free Hero Mesh and is public domain. */ // == main == #define fatal(...) do{ fprintf(stderr,__VA_ARGS__); exit(1); }while(0) #define boolxrm(a,b) (*a=='1'||*a=='y'||*a=='t'||*a=='Y'||*a=='T'?1:*a=='0'||*a=='n'||*a=='f'||*a=='N'||*a=='F'?0:b) #define TY_NUMBER 0 #define TY_CLASS 1 #define TY_MESSAGE 2 #define TY_SOUND 3 #define TY_USOUND 4 #define TY_STRING 5 #define TY_LEVELSTRING 6 #define TY_MAXTYPE 15 typedef struct { union { Sint32 s; Uint32 u; }; Uint32 t; // Type 0-15, or a generation_number of an object } Value; extern sqlite3*userdb; extern xrm_db*resourcedb; extern const char*basefilename; extern xrm_quark optionquery[16]; extern Uint32 generation_number; void set_cursor(int id); // == picture == extern SDL_Surface*screen; extern Uint16 picture_size; void draw_picture(int x,int y,Uint16 img); void draw_text(int x,int y,const unsigned char*t,int bg,int fg); void load_pictures(void); // == class == #define CF_PLAYER 0x01 #define CF_INPUT 0x02 #define CF_COMPATIBLE 0x04 #define CF_QUIZ 0x08 #define CF_GROUP 0x10 // this is a group of classes; you can't create an object of this class #define CF_NOCLASS1 0x40 // if only the name has been loaded so far, from the .class file #define CF_NOCLASS2 0x80 // if only the name has been loaded so far, from the CLASS.DEF lump #define OF_INVISIBLE 0x0001 #define OF_VISUALONLY 0x0002 #define OF_STEALTHY 0x0004 #define OF_BUSY 0x0008 #define OF_USERSTATE 0x0010 #define OF_USERSIGNAL 0x0020 #define OF_MOVED 0x0040 #define OF_DONE 0x0080 #define OF_KEYCLEARED 0x0100 #define OF_DESTROYED 0x0200 typedef struct { const char*name; const char*edithelp; // not present if CF_GROUP const char*gamehelp; // not present if CF_GROUP Uint16*codes; // if this is CF_GROUP, then instead a zero-terminated list of classes Uint16*messages; // use 0xFFFF if no such message block; not present if CF_GROUP Uint16*images; // high bit is set if available to editor; not present if CF_GROUP Sint32 height,weight,climb,density,volume,strength,arrivals,departures; Sint32 temperature,misc4,misc5,misc6,misc7; Uint16 uservars,oflags; Uint16 sharp[4]; Uint16 hard[4]; Uint8 cflags,shape,shovable; } Class; extern Class*classes[0x4000]; // 0 isn't used extern const char*messages[0x4000]; // index is 256 less than message number extern int max_animation; // max steps in animation queue extern Sint32 max_volume; // max total volume to allow moving diagonally (default 10000) |
Modified main.c from [6d5db62424] to [9c681f49a8].
︙ | ︙ | |||
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | #define MOD_META 8 #define MOD_NUMLOCK 14 typedef struct { UserCommand m[16]; } KeyBinding; static const char schema[]= "PRAGMA APPLICATION_ID(1296388936);" "PRAGMA RECURSIVE_TRIGGERS(1);" "CREATE TABLE IF NOT EXISTS `USERCACHEINDEX`(`ID` INTEGER PRIMARY KEY, `NAME` TEXT, `TIME` INT);" "CREATE TEMPORARY TABLE `PICTURES`(`ID` INTEGER PRIMARY KEY, `NAME` TEXT, `OFFSET` INT);" ; sqlite3*userdb; xrm_db*resourcedb; const char*basefilename; xrm_quark optionquery[16]; static const char*globalclassname; static SDL_Cursor*cursor[77]; static FILE*levelfp; static FILE*solutionfp; static FILE*hamarc_fp; static long hamarc_pos; static KeyBinding*editor_bindings[SDLK_LAST]; static KeyBinding*game_bindings[SDLK_LAST]; static KeyBinding*editor_mouse_bindings[4]; static KeyBinding*game_mouse_bindings[4]; | > > > > < < < | 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | #define MOD_META 8 #define MOD_NUMLOCK 14 typedef struct { UserCommand m[16]; } KeyBinding; static const char schema[]= "BEGIN;" "PRAGMA APPLICATION_ID(1296388936);" "PRAGMA RECURSIVE_TRIGGERS(1);" "CREATE TABLE IF NOT EXISTS `USERCACHEINDEX`(`ID` INTEGER PRIMARY KEY, `NAME` TEXT, `TIME` INT);" "CREATE TEMPORARY TABLE `PICTURES`(`ID` INTEGER PRIMARY KEY, `NAME` TEXT, `OFFSET` INT);" "COMMIT;" ; sqlite3*userdb; xrm_db*resourcedb; const char*basefilename; xrm_quark optionquery[16]; Uint32 generation_number; static const char*globalclassname; static SDL_Cursor*cursor[77]; static FILE*levelfp; static FILE*solutionfp; static FILE*hamarc_fp; static long hamarc_pos; static char main_options[128]; static KeyBinding*editor_bindings[SDLK_LAST]; static KeyBinding*game_bindings[SDLK_LAST]; static KeyBinding*editor_mouse_bindings[4]; static KeyBinding*game_mouse_bindings[4]; static void hamarc_begin(FILE*fp,const char*name) { while(*name) fputc(*name++,fp); fwrite("\0\0\0\0",1,5,hamarc_fp=fp); hamarc_pos=ftell(fp); } static long hamarc_end(void) { |
︙ | ︙ | |||
129 130 131 132 133 134 135 | } if(sqlite3_exec(userdb,schema,0,0,&s)) fatal("Failed to initialize database schema (%s)\n",s?:"unknown error"); optionquery[1]=Q_sqlInit; v=xrm_get_resource(resourcedb,optionquery,optionquery,2); if(v && sqlite3_exec(userdb,v,0,0,&s)) fatal("Failed to execute user-defined SQL statements (%s)\n",s?:"unknown error"); } | | | 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | } if(sqlite3_exec(userdb,schema,0,0,&s)) fatal("Failed to initialize database schema (%s)\n",s?:"unknown error"); optionquery[1]=Q_sqlInit; v=xrm_get_resource(resourcedb,optionquery,optionquery,2); if(v && sqlite3_exec(userdb,v,0,0,&s)) fatal("Failed to execute user-defined SQL statements (%s)\n",s?:"unknown error"); } void set_cursor(int id) { id>>=1; if(!cursor[id]) cursor[id]=SDL_CreateCursor((void*)cursorimg+(id<<6),(void*)cursorimg+(id<<6)+32,16,16,cursorhot[id]>>4,cursorhot[id]&15); SDL_SetCursor(cursor[id]); } static void load_options(void) { const char*home=getenv("HOME")?:"."; |
︙ | ︙ | |||
274 275 276 277 278 279 280 281 282 | optionquery[2]=Q_ctrl; SetMouseBinding(SDL_BUTTON_RIGHT,4,MOD_CTRL); optionquery[2]=Q_alt; SetMouseBinding(SDL_BUTTON_RIGHT,4,MOD_ALT); optionquery[2]=Q_meta; SetMouseBinding(SDL_BUTTON_RIGHT,4,MOD_META); } int main(int argc,char**argv) { | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | | | | < | > > > > > | 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 | optionquery[2]=Q_ctrl; SetMouseBinding(SDL_BUTTON_RIGHT,4,MOD_CTRL); optionquery[2]=Q_alt; SetMouseBinding(SDL_BUTTON_RIGHT,4,MOD_ALT); optionquery[2]=Q_meta; SetMouseBinding(SDL_BUTTON_RIGHT,4,MOD_META); } static int test_sql_callback(void*usr,int argc,char**argv,char**name) { int i; if(argc) printf("%s",*argv); for(i=1;i<argc;i++) printf("|%s",argv[i]); putchar('\n'); return 0; } static void test_mode(void) { Uint32 n=0; SDL_Event ev; char buf[32]; set_cursor(XC_tcross); SDL_LockSurface(screen); draw_text(0,0,"Hello, World!",0xF0,0xFF); SDL_UnlockSurface(screen); SDL_Flip(screen); while(SDL_WaitEvent(&ev)) switch(ev.type) { case SDL_KEYDOWN: switch(ev.key.keysym.sym) { case SDLK_BACKSPACE: n/=10; snprintf(buf,30,"%u",n); SDL_WM_SetCaption(buf,buf); break; case SDLK_SPACE: n=0; SDL_WM_SetCaption("0","0"); break; case SDLK_0 ... SDLK_9: n=10*n+ev.key.keysym.sym-SDLK_0; snprintf(buf,30,"%u",n); SDL_WM_SetCaption(buf,buf); break; case SDLK_c: SDL_FillRect(screen,0,n); SDL_Flip(screen); break; case SDLK_p: sqlite3_exec(userdb,"SELECT * FROM `PICTURES`;",test_sql_callback,0,0); break; case SDLK_q: exit(0); break; } break; case SDL_MOUSEBUTTONDOWN: draw_picture(ev.button.x,ev.button.y,n); SDL_Flip(screen); break; case SDL_QUIT: exit(0); break; } fatal("An error occurred waiting for events.\n"); } int main(int argc,char**argv) { int optind=1; while(argc>optind && argv[optind][0]=='-') { int i; const char*s=argv[optind++]; if(s[1]=='-' && !s[2]) break; for(i=1;s[i];i++) main_options[s[i]&127]=1; } if(argc<=optind) fatal("usage: %s [switches] [--] basename [options...]\n",argc?argv[0]:"heromesh"); if(xrm_init(realloc)) fatal("Failed to initialize resource manager\n"); if(xrm_init_quarks(global_quarks)) fatal("Failed to initialize resource manager\n"); resourcedb=xrm_create(); if(!resourcedb) fatal("Allocation of resource database failed\n"); basefilename=argv[optind++]; if(argc>optind && argv[1][0]=='=') { globalclassname=argv[optind++]+1; } else if(find_globalclassname()) { globalclassname=strrchr(basefilename,'/'); globalclassname=globalclassname?globalclassname+1:basefilename; } load_options(); if(argc>optind) read_options(argc-optind,argv+optind); *optionquery=xrm_make_quark(globalclassname,0)?:xrm_anyq; init_sql(); init_screen(); load_pictures(); if(main_options['T']) { test_mode(); return 0; } return 0; } |
Modified picture.c from [a53d3b6194] to [2526d2ec5f].
︙ | ︙ | |||
15 16 17 18 19 20 21 | #include <string.h> #include "sqlite3.h" #include "smallxrm.h" #include "pcfont.h" #include "quarks.h" #include "heromesh.h" | < < | 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | #include <string.h> #include "sqlite3.h" #include "smallxrm.h" #include "pcfont.h" #include "quarks.h" #include "heromesh.h" SDL_Surface*screen; Uint16 picture_size; static SDL_Surface*picts; static Uint8*curpic; static const char default_palette[]= |
︙ | ︙ | |||
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | int xx,yy; const unsigned char*f; if(x+8*len>screen->w) len=(screen->w-x)>>3; if(len<=0 || y+8>screen->h) return; pix+=y*pitch+x; while(*t) { f=fontdata+(*t<<3); for(yy=0;yy<8;yy++) { for(xx=0;xx<8;xx++) p[xx]=(*f<<xx)&128?fg:bg; p+=pitch; ++f; } t++; if(!--len) return; } } static Uint16 decide_picture_size(int nwantsize,const Uint8*wantsize,const Uint16*havesize) { int i,j; if(!nwantsize) fatal("Unable to determine what picture size is wanted\n"); for(i=0;i<nwantsize;i++) if(havesize[j=wantsize[i]]) return j; | > > | 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | int xx,yy; const unsigned char*f; if(x+8*len>screen->w) len=(screen->w-x)>>3; if(len<=0 || y+8>screen->h) return; pix+=y*pitch+x; while(*t) { f=fontdata+(*t<<3); p=pix; for(yy=0;yy<8;yy++) { for(xx=0;xx<8;xx++) p[xx]=(*f<<xx)&128?fg:bg; p+=pitch; ++f; } t++; if(!--len) return; pix+=8; } } static Uint16 decide_picture_size(int nwantsize,const Uint8*wantsize,const Uint16*havesize) { int i,j; if(!nwantsize) fatal("Unable to determine what picture size is wanted\n"); for(i=0;i<nwantsize;i++) if(havesize[j=wantsize[i]]) return j; |
︙ | ︙ | |||
245 246 247 248 249 250 251 | } nam[i]=0; if(i>4 && !memcmp(".IMG",nam+i-4,4)) { j=1; if(n++==32768) fatal("Too many pictures\n"); sqlite3_reset(st); sqlite3_bind_int(st,1,n); | | | 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 | } nam[i]=0; if(i>4 && !memcmp(".IMG",nam+i-4,4)) { j=1; if(n++==32768) fatal("Too many pictures\n"); sqlite3_reset(st); sqlite3_bind_int(st,1,n); sqlite3_bind_text(st,2,nam,i-4,SQLITE_TRANSIENT); sqlite3_bind_int64(st,3,ftell(fp)+4); while((i=sqlite3_step(st))==SQLITE_ROW); if(i!=SQLITE_DONE) fatal("SQL error (%d): %s\n",i,sqlite3_errmsg(userdb)); } else { j=0; } i=fgetc(fp)<<16; |
︙ | ︙ | |||
319 320 321 322 323 324 325 | case 'p': i|=SDL_HWPALETTE; break; case 'r': i|=SDL_RESIZABLE; break; case 'y': i|=SDL_ASYNCBLIT; break; } if(!(i&SDL_HWSURFACE)) i|=SDL_SWSURFACE; screen=SDL_SetVideoMode(w,h,8,i); if(!screen) fatal("Failed to initialize screen mode: %s\n",SDL_GetError()); | > > > > > > > | > | 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 | case 'p': i|=SDL_HWPALETTE; break; case 'r': i|=SDL_RESIZABLE; break; case 'y': i|=SDL_ASYNCBLIT; break; } if(!(i&SDL_HWSURFACE)) i|=SDL_SWSURFACE; screen=SDL_SetVideoMode(w,h,8,i); if(!screen) fatal("Failed to initialize screen mode: %s\n",SDL_GetError()); optionquery[1]=Q_keyRepeat; if(v=xrm_get_resource(resourcedb,optionquery,optionquery,2)) { w=strtol(v,(void*)&v,10); h=strtol(v,0,10); SDL_EnableKeyRepeat(w,h); } else { SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY,SDL_DEFAULT_REPEAT_INTERVAL); } } |
Modified quarks from [58f69cd9fa] to [d5aac816d7].
︙ | ︙ | |||
200 201 202 203 204 205 206 207 | ! SQL settings sqlInit sqlExtensions sqlMemStatus sqlSmallAllocations sqlCoveringIndexScan sqlPowerSafe | > > > | 200 201 202 203 204 205 206 207 208 209 210 | ! SQL settings sqlInit sqlExtensions sqlMemStatus sqlSmallAllocations sqlCoveringIndexScan sqlPowerSafe ! Miscellaneous level |
Modified quarks.h from [6487272797] to [16698ee816].
︙ | ︙ | |||
167 168 169 170 171 172 173 174 175 176 177 178 179 180 | #define Q_solutionTimestamp 168 #define Q_sqlInit 169 #define Q_sqlExtensions 170 #define Q_sqlMemStatus 171 #define Q_sqlSmallAllocations 172 #define Q_sqlCoveringIndexScan 173 #define Q_sqlPowerSafe 174 static const char*const global_quarks[]={ "screenWidth", "screenHeight", "palette", "popupColors", "imageSize", "altImage", | > | 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | #define Q_solutionTimestamp 168 #define Q_sqlInit 169 #define Q_sqlExtensions 170 #define Q_sqlMemStatus 171 #define Q_sqlSmallAllocations 172 #define Q_sqlCoveringIndexScan 173 #define Q_sqlPowerSafe 174 #define Q_level 175 static const char*const global_quarks[]={ "screenWidth", "screenHeight", "palette", "popupColors", "imageSize", "altImage", |
︙ | ︙ | |||
341 342 343 344 345 346 347 348 349 350 351 352 353 354 | "solutionTimestamp", "sqlInit", "sqlExtensions", "sqlMemStatus", "sqlSmallAllocations", "sqlCoveringIndexScan", "sqlPowerSafe", 0}; #ifdef HEROMESH_MAIN static const SDLKey quark_to_key[Q_undo+1-Q_backspace]={ SDLK_BACKSPACE, SDLK_TAB, SDLK_CLEAR, SDLK_RETURN, | > | 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 | "solutionTimestamp", "sqlInit", "sqlExtensions", "sqlMemStatus", "sqlSmallAllocations", "sqlCoveringIndexScan", "sqlPowerSafe", "level", 0}; #ifdef HEROMESH_MAIN static const SDLKey quark_to_key[Q_undo+1-Q_backspace]={ SDLK_BACKSPACE, SDLK_TAB, SDLK_CLEAR, SDLK_RETURN, |
︙ | ︙ |