Free Hero Mesh

Check-in [e17ab8c4ed]
Login
This is a mirror of the main repository for Free Hero Mesh. New tickets and changes will not be accepted at this mirror.
Overview
Comment:Start to implement loading dependent pictures (the file format isn't implemented yet, nor even defined yet, nor does the picture editor support this yet).
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: e17ab8c4ed8f848b91ecde9e1e87fce301a82bb9
User & Date: user on 2021-04-11 04:56:34
Other Links: manifest | tags
Context
2021-04-11
17:12
Add another item into TODO list check-in: 52cb71156f user: user tags: trunk
04:56
Start to implement loading dependent pictures (the file format isn't implemented yet, nor even defined yet, nor does the picture editor support this yet). check-in: e17ab8c4ed user: user tags: trunk
01:11
Add "min", "max", "eq2", "Coloc", and "Target" instructions. check-in: aa4fea4bb5 user: user tags: trunk
Changes

Modified main.c from [9136db6a90] to [9dbf73c467].

33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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 TABLE IF NOT EXISTS `USERCACHEDATA`(`ID` INTEGER PRIMARY KEY, `FILE` INT, `LEVEL` INT, `NAME` TEXT COLLATE NOCASE, `OFFSET` INT, `DATA` BLOB, `USERSTATE` BLOB);"
  "CREATE UNIQUE INDEX IF NOT EXISTS `USERCACHEDATA_I1` ON `USERCACHEDATA`(`FILE`, `LEVEL`);"
  "CREATE TEMPORARY TABLE `PICTURES`(`ID` INTEGER PRIMARY KEY, `NAME` TEXT COLLATE NOCASE, `OFFSET` INT);"
  "CREATE TEMPORARY TABLE `VARIABLES`(`ID` INTEGER PRIMARY KEY, `NAME` TEXT);"
  "COMMIT;"
;

sqlite3*userdb;
xrm_db*resourcedb;
const char*basefilename;







|







33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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 TABLE IF NOT EXISTS `USERCACHEDATA`(`ID` INTEGER PRIMARY KEY, `FILE` INT, `LEVEL` INT, `NAME` TEXT COLLATE NOCASE, `OFFSET` INT, `DATA` BLOB, `USERSTATE` BLOB);"
  "CREATE UNIQUE INDEX IF NOT EXISTS `USERCACHEDATA_I1` ON `USERCACHEDATA`(`FILE`, `LEVEL`);"
  "CREATE TEMPORARY TABLE `PICTURES`(`ID` INTEGER PRIMARY KEY, `NAME` TEXT COLLATE NOCASE, `OFFSET` INT, `DEPENDENT` INT);"
  "CREATE TEMPORARY TABLE `VARIABLES`(`ID` INTEGER PRIMARY KEY, `NAME` TEXT);"
  "COMMIT;"
;

sqlite3*userdb;
xrm_db*resourcedb;
const char*basefilename;

Modified picture.c from [612e3375bc] to [32631e0ed2].

389
390
391
392
393
394
395




396
397
398
399
400
401
402
        if(meth&2) i=size-i-1;
      }
      pix+=pitch-picture_size;
    }
  }
  SDL_UnlockSurface(picts);
}





void load_pictures(void) {
  sqlite3_stmt*st=0;
  FILE*fp;
  Uint8 wantsize[32];
  Uint8 nwantsize=0;
  Uint8 altImage;







>
>
>
>







389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
        if(meth&2) i=size-i-1;
      }
      pix+=pitch-picture_size;
    }
  }
  SDL_UnlockSurface(picts);
}

static void load_dependent_picture(FILE*fp,Uint16 img,int alt) {
  //TODO
}

void load_pictures(void) {
  sqlite3_stmt*st=0;
  FILE*fp;
  Uint8 wantsize[32];
  Uint8 nwantsize=0;
  Uint8 altImage;
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445

446
447
448
449
450
451
452
    sscanf(v," %d %n",&i,&j);
    if(!j) break;
    if(i<2 || i>255) fatal("Invalid picture size %d\n",i);
    wantsize[nwantsize++]=i;
    v+=j;
  }
  if(n=sqlite3_exec(userdb,"BEGIN;",0,0,0)) fatal("SQL error (%d): %s\n",n,sqlite3_errmsg(userdb));
  if(sqlite3_prepare_v2(userdb,"INSERT INTO `PICTURES`(`ID`,`NAME`,`OFFSET`) VALUES(?1,?2,?3);",-1,&st,0))
   fatal("Unable to prepare SQL statement while loading pictures: %s\n",sqlite3_errmsg(userdb));
  nam=malloc(256);
  if(!nam) fatal("Allocation failed\n");
  n=0;
  memset(havesize,0,256*sizeof(Uint16));
  while(!feof(fp)) {
    i=0;
    while(j=fgetc(fp)) {
      if(j==EOF) goto nomore1;
      if(i<255) nam[i++]=j;
    }
    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;
    i|=fgetc(fp)<<24;







|












|
|





>







423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
    sscanf(v," %d %n",&i,&j);
    if(!j) break;
    if(i<2 || i>255) fatal("Invalid picture size %d\n",i);
    wantsize[nwantsize++]=i;
    v+=j;
  }
  if(n=sqlite3_exec(userdb,"BEGIN;",0,0,0)) fatal("SQL error (%d): %s\n",n,sqlite3_errmsg(userdb));
  if(sqlite3_prepare_v2(userdb,"INSERT INTO `PICTURES`(`ID`,`NAME`,`OFFSET`,`DEPENDENT`) VALUES(?1,?2,?3,?4);",-1,&st,0))
   fatal("Unable to prepare SQL statement while loading pictures: %s\n",sqlite3_errmsg(userdb));
  nam=malloc(256);
  if(!nam) fatal("Allocation failed\n");
  n=0;
  memset(havesize,0,256*sizeof(Uint16));
  while(!feof(fp)) {
    i=0;
    while(j=fgetc(fp)) {
      if(j==EOF) goto nomore1;
      if(i<255) nam[i++]=j;
    }
    nam[i]=0;
    if(i>4 && (!memcmp(".IMG",nam+i-4,4) || !memcmp(".DEP",nam+i-4,4))) {
      if(nam[i-3]=='D') j=0; else 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);
      sqlite3_bind_int(st,4,j^1);
      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;
    i|=fgetc(fp)<<24;
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487



488
489
490











491
492
493
494
495
496
497
  for(i=255;i;--i) if(havesize[i]) {
    curpic=malloc(i*i);
    break;
  }
  if(!curpic) fatal("Allocation failed\n");
  picture_size=decide_picture_size(nwantsize,wantsize,havesize,n);
  if(main_options['x']) goto done;
  if(sqlite3_prepare_v2(userdb,"SELECT `ID`, `OFFSET` FROM `PICTURES`;",-1,&st,0))
   fatal("Unable to prepare SQL statement while loading pictures: %s\n",sqlite3_errmsg(userdb));
  optionquery[1]=Q_screenFlags;
  v=xrm_get_resource(resourcedb,optionquery,optionquery,2);
  i=v&&strchr(v,'h');
  picts=SDL_CreateRGBSurface((i?SDL_HWSURFACE:SDL_SWSURFACE)|SDL_SRCCOLORKEY,picture_size<<4,picture_size*((n+15)>>4),8,0,0,0,0);
  if(!picts) fatal("Error allocating surface for pictures: %s\n",SDL_GetError());
  init_palette();
  for(i=0;i<n;i++) {
    if((j=sqlite3_step(st))!=SQLITE_ROW) fatal("SQL error (%d): %s\n",j,j==SQLITE_DONE?"Incorrect number of rows in a temporary table":sqlite3_errmsg(userdb));



    fseek(fp,sqlite3_column_int64(st,1),SEEK_SET);
    load_one_picture(fp,sqlite3_column_int(st,0),altImage);
  }











  sqlite3_finalize(st);
  fclose(fp);
  SDL_SetColorKey(picts,SDL_SRCCOLORKEY|SDL_RLEACCEL,0);
done:
  if(n=sqlite3_exec(userdb,"COMMIT;",0,0,0)) fatal("SQL error (%d): %s\n",n,sqlite3_errmsg(userdb));
  fprintf(stderr,"Done\n");
}







|








|
>
>
>



>
>
>
>
>
>
>
>
>
>
>







476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
  for(i=255;i;--i) if(havesize[i]) {
    curpic=malloc(i*i);
    break;
  }
  if(!curpic) fatal("Allocation failed\n");
  picture_size=decide_picture_size(nwantsize,wantsize,havesize,n);
  if(main_options['x']) goto done;
  if(sqlite3_prepare_v2(userdb,"SELECT `ID`, `OFFSET` FROM `PICTURES` WHERE NOT `DEPENDENT`;",-1,&st,0))
   fatal("Unable to prepare SQL statement while loading pictures: %s\n",sqlite3_errmsg(userdb));
  optionquery[1]=Q_screenFlags;
  v=xrm_get_resource(resourcedb,optionquery,optionquery,2);
  i=v&&strchr(v,'h');
  picts=SDL_CreateRGBSurface((i?SDL_HWSURFACE:SDL_SWSURFACE)|SDL_SRCCOLORKEY,picture_size<<4,picture_size*((n+15)>>4),8,0,0,0,0);
  if(!picts) fatal("Error allocating surface for pictures: %s\n",SDL_GetError());
  init_palette();
  for(i=0;i<n;i++) {
    if((j=sqlite3_step(st))!=SQLITE_ROW) {
      if(j==SQLITE_DONE) break;
      fatal("SQL error (%d): %s\n",j,sqlite3_errmsg(userdb));
    }
    fseek(fp,sqlite3_column_int64(st,1),SEEK_SET);
    load_one_picture(fp,sqlite3_column_int(st,0),altImage);
  }
  sqlite3_finalize(st);
  if(sqlite3_prepare_v2(userdb,"SELECT `ID`, `OFFSET` FROM `PICTURES` WHERE `DEPENDENT`;",-1,&st,0))
   fatal("Unable to prepare SQL statement while loading pictures: %s\n",sqlite3_errmsg(userdb));
  for(i=0;i<n;i++) {
    if((j=sqlite3_step(st))!=SQLITE_ROW) {
      if(j==SQLITE_DONE) break;
      fatal("SQL error (%d): %s\n",j,sqlite3_errmsg(userdb));
    }
    fseek(fp,sqlite3_column_int64(st,1)-4,SEEK_SET);
    load_dependent_picture(fp,sqlite3_column_int(st,0),altImage);
  }
  sqlite3_finalize(st);
  fclose(fp);
  SDL_SetColorKey(picts,SDL_SRCCOLORKEY|SDL_RLEACCEL,0);
done:
  if(n=sqlite3_exec(userdb,"COMMIT;",0,0,0)) fatal("SQL error (%d): %s\n",n,sqlite3_errmsg(userdb));
  fprintf(stderr,"Done\n");
}

Modified sql.doc from [fa10274d55] to [8a70d5bf69].

119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
  must be numbers, classes, messages, or strings. Once an object is
  created, you cannot change its class; you must delete it and then add
  a new object of the correct class. DENSITY is read-only, but you can
  use ORDER BY DENSITY to sort in the stacking order of the objects.
  UP and DOWN are also read-only.

CREATE TEMPORARY TABLE "PICTURES"("ID" INTEGER PRIMARY KEY, "NAME" TEXT
COLLATE NOCASE, "OFFSET" INT);
  List of all pictures available in this puzzle set.

CREATE TABLE "USERCACHEDATA"("ID" INTEGER PRIMARY KEY, "FILE" INT,
"LEVEL" INT, "NAME" TEXT COLLATE NOCASE, "OFFSET" INT, "DATA" BLOB,
"USERSTATE" BLOB);
  Contains the user cache data for the .level and .solution files of each
  puzzle set, in order to speed up loading and saving. The DATA will be







|







119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
  must be numbers, classes, messages, or strings. Once an object is
  created, you cannot change its class; you must delete it and then add
  a new object of the correct class. DENSITY is read-only, but you can
  use ORDER BY DENSITY to sort in the stacking order of the objects.
  UP and DOWN are also read-only.

CREATE TEMPORARY TABLE "PICTURES"("ID" INTEGER PRIMARY KEY, "NAME" TEXT
COLLATE NOCASE, "OFFSET" INT, "DEPENDENT" INT);
  List of all pictures available in this puzzle set.

CREATE TABLE "USERCACHEDATA"("ID" INTEGER PRIMARY KEY, "FILE" INT,
"LEVEL" INT, "NAME" TEXT COLLATE NOCASE, "OFFSET" INT, "DATA" BLOB,
"USERSTATE" BLOB);
  Contains the user cache data for the .level and .solution files of each
  puzzle set, in order to speed up loading and saving. The DATA will be