Free Hero Mesh

Check-in [b629fea66f]
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:Implement pattern strings and some other commands, an da few more corrections, in the (LevelTable) block implementation.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: b629fea66f46354f57484854f90ce7a1c971fcfa
User & Date: user on 2021-12-30 21:49:06
Other Links: manifest | tags
Context
2021-12-30
23:44
More explanation of how the results of calculations are used for the level table. check-in: 30d372f39a user: user tags: trunk
21:49
Implement pattern strings and some other commands, an da few more corrections, in the (LevelTable) block implementation. check-in: b629fea66f user: user tags: trunk
2021-12-29
00:29
Implement all of the rest of the (LevelTable) block and its displaying and processing, except the string matching, which will be implemented later. check-in: d24dfda327 user: user tags: trunk
Changes

Modified TODO from [be82d4c6e3] to [e85d57e738].

13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
  * Returning a class from COLLIDE/COLLIDEBY to transform
  * Coordinate input (may be suitable for some kind of games)
  * Possibility to define auto-generation levels mode
* Editor
  * Mouse dragging
  * Level index editor
* Table of contents for levels (partially implemented)
  * Can define your own columns
  * Can be divisions by sections
* Deal better with allowing to skip past corrupted levels
* Picture editor/loading
  * Allowing more altimages
  * Batch insert multiple dependent image lumps
* Puzzle set catalog format (using with internet; a separate program)
* Inventory/replay hybrid view







<







13
14
15
16
17
18
19

20
21
22
23
24
25
26
  * Returning a class from COLLIDE/COLLIDEBY to transform
  * Coordinate input (may be suitable for some kind of games)
  * Possibility to define auto-generation levels mode
* Editor
  * Mouse dragging
  * Level index editor
* Table of contents for levels (partially implemented)

  * Can be divisions by sections
* Deal better with allowing to skip past corrupted levels
* Picture editor/loading
  * Allowing more altimages
  * Batch insert multiple dependent image lumps
* Puzzle set catalog format (using with internet; a separate program)
* Inventory/replay hybrid view

Modified class.doc from [6d0262fd53] to [94e8d147ec].

2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658






2659







2660


































 Bitwise:  band bor bxor bnot lsh rsh ,rsh

 Logical:  land lor lxor lnot

 Compare:  eq ne lt ,lt gt ,gt le ,le ge ,ge

 Misc:  Level _ in nin ret if else then

 Object:  Xloc Yloc Class Dir Misc1 Misc2 Misc3 Misc4 Misc5 Misc6 Misc7
   Temperature Density Player Input Bizarro CollisionLayers

Additionally, you can include numbers, strings (see below for their
meaning, which is different from the meaning in class codes), aggregate
names (with % at first), user flags (with ^ at first), class names, and
message names (both built-in messages and user messages are possible).
Accessing values of objects other than the current one is not possible.







(TODO: Usage of strings as instructions in this block.)
















































|










>
>
>
>
>
>
|
>
>
>
>
>
>
>

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706

 Bitwise:  band bor bxor bnot lsh rsh ,rsh

 Logical:  land lor lxor lnot

 Compare:  eq ne lt ,lt gt ,gt le ,le ge ,ge

 Misc:  Level _ in nin ret if else then c? m? n? . dup Trace

 Object:  Xloc Yloc Class Dir Misc1 Misc2 Misc3 Misc4 Misc5 Misc6 Misc7
   Temperature Density Player Input Bizarro CollisionLayers

Additionally, you can include numbers, strings (see below for their
meaning, which is different from the meaning in class codes), aggregate
names (with % at first), user flags (with ^ at first), class names, and
message names (both built-in messages and user messages are possible).
Accessing values of objects other than the current one is not possible.

The Trace instruction in the (LevelTable) block is not the same as in the
class codes. In this block, it doesn't consume anything from the stack;
instead, if both -t and -v switches are enabled, then it will display data
relating to the level table calculation on stdout, at the time when the
level table is loaded. (If the table is dropped, it will automatically be
reloaded the next time it is accessed.)

If a string is found where an instruction is expected in this block, then
unlike class codes it is not simply pushing the string to the stack.
Instead, if it starts with @ then the rest of it is a literal string, but
otherwise it represents a pattern to match. If the match is successful,
it pushes the matched substring (or sometimes, a number) to the stack,
and then pushes 1; if unsuccessful, only pushes 0. These patterns will
match the title string of the level. Pattern codes are:

  =    Follow by a delimited string; match that string at the current
        position and skip past it, or if it doesn't match, fail.
  /    Follow by a delimited string; match that string at the current or
        any later position (at the first place where it is found), or if
        it doesn't match, fail.
  [    Set beginning of slice.
  ]    Set end of slice.
  (    Set beginning of slice (same as the [ command);
  )    Set end of slice, but use the position just before the matched item
        instead of just after it.
  \n   Skip until a line break of horizontal bar, and past it. If it is
        followed by any more consecutive line breaks without anything else
        in between, skips those ones too.
  \d   Follow by some text and then : and \ or just \ to skip to and find
        the data in the string that has the same text. If it contains a
        question mark then any single character is matched. Between : and \
        you can have usual other matching commands such as [ and ].
  +    Follow by one more character, skip past any number of them.
  -    Skip past any number of digits.
  _    Skip past any number of spaces and line breaks.
  <    Rewind back to the beginning.
  >    Skip to the end.
  #    Successful match; the result is a number within the slice, converted
        from a string (parsed as decimal) to a number.
  $    Successful match; the result is the matched slice.
  %    Successful match; the result is the length of the matched slice.

A "delimited string" in this block is delimited by any printable
character on both sides (except a character with code less than 32).

(The above list of pattern codes maybe it isn't explained very well;
hopefully someone else know how to improve it better.)

Modified function.c from [89407dfd1e] to [c810f6f9c4].

1209
1210
1211
1212
1213
1214
1215













1216




















1217

1218
















































































1219
1220


















1221
1222
1223
1224
1225
1226






1227
1228
1229
1230
1231
1232
1233

typedef struct {
  Value misc1,misc2,misc3;
  Uint8 x,y,dir,bizarro;
  Uint16 class;
} ObjInfo;














#define ArithOp1(aa) ({ if(sp<1 || stack[sp-1].t) goto bad; Value t1=stack[sp-1]; stack[sp-1]=NVALUE(aa); })




















#define ArithOp2(aa) ({ if(sp<2 || stack[sp-1].t || stack[sp-2].t) goto bad; Value t1=stack[sp-2]; Value t2=stack[sp-1]; sp--; stack[sp-1]=NVALUE(aa); })

#define ArithDivOp2(aa) ({ if(sp<2 || stack[sp-1].t || stack[sp-2].t || !stack[sp-1].u) goto bad; Value t1=stack[sp-2]; Value t2=stack[sp-1]; sp--; stack[sp-1]=NVALUE(aa); })
















































































#define OtherOp1(aa) ({ if(sp<1) goto bad; Value t1=stack[sp-1]; stack[sp-1]=(aa); })
#define OtherOp2(aa) ({ if(sp<2) goto bad; Value t1=stack[sp-2]; Value t2=stack[sp-1]; sp--; stack[sp-1]=(aa); })



















static inline Uint32 ll_in(Value*stack,Sint16 top,Sint16 m) {
  while(--top>m) if(stack[top].t==stack[m-1].t && stack[top].u==stack[m-1].u) return 1;
  return 0;
}







static Sint16 level_table_exec(Uint16 ptr,const unsigned char*lvl,long sz,ObjInfo*ob,Value*stack,Value*agg) {
  Sint16 sp=0;
  Uint32 k,m;
  while(sp<62) switch(ll_code[ptr++]) {
    case 0 ... 255: stack[sp++]=NVALUE(ll_code[ptr-1]); break;
    case 0x0200 ... 0x02FF: stack[sp++]=MVALUE(ll_code[ptr-1]&255); break;
    case 0x4000 ... 0x7FFF: stack[sp++]=CVALUE(ll_code[ptr-1]&0x3FFF); break;







>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>






>
>
>
>
>
>







1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371

typedef struct {
  Value misc1,misc2,misc3;
  Uint8 x,y,dir,bizarro;
  Uint16 class;
} ObjInfo;

static const unsigned char*ll_find(const unsigned char*p,Uint8 c) {
  int j;
  for(j=0;*p;p++) {
    if(j) {
      if(*p=='\\') j=0;
    } else {
      if(*p==c) return p;
      if(*p==14 || *p==30) j=1;
      if(*p==31 && p[1]) p++;
    }
  }
  return 0;
}

static inline Sint16 ll_string(const unsigned char*str,const unsigned char*title,Value*stack,Sint16 sp) {
  const unsigned char*ps=str; // pointer of string
  const unsigned char*pt=title; // pointer of title
  const unsigned char*so=0; // start offset
  const unsigned char*eo=0; // end offset
  const unsigned char*pp=pt;
  const unsigned char*q;
  int i,j,k;
  while(*ps) {
    switch(*ps++) {
      case '=':
        k=*ps++;
        if(k<32) return 64;
        while(*ps && *ps!=k && *pt==*ps) ps++,pt++;
        if(*ps!=k) goto notfound;
        ps++;
        break;
      case '/':
        k=*ps++;
        if(k<32) return 64;
        if(*ps==k) goto bad;
        q=strchr(ps,k);
        if(!q) goto bad;
        j=q-ps;
        while(*pt) {
          pt=ll_find(pt,*ps);
          if(!pt) goto notfound;
          for(i=1;i<j && pt[i]==ps[i];i++);
          if(i==j) break;
          pt++;
        }
        if(!*pt) goto notfound;
        pp=pt;
        ps+=j+1;
        pt+=j;
        break;
      case '[': so=pt; break;
      case ']': eo=pt; break;
      case '(': so=pt; break;
      case ')': eo=pp; break;
      case 10: // "\n"
        if(pt==title) break;
        for(j=0;*pt;pt++) {
          if(j) {
            if(*pt=='\\') j=0;
          } else {
            if(*pt==10 || *pt==15) break;
            if(*pt==14 || *pt==30) j=1;
            if(*pt==31 && pt[1]) pt++;
          }
        }
        if(!*pt) goto notfound;
        pp=pt++;
        while(*pt==10) pt++;
        break;
      case 30: // "\d"
        re:
        pp=pt=ll_find(pt,30);
        if(!pt) goto notfound;
        for(i=0;ps[i];i++) {
          if(ps[i]==':' || ps[i]=='\\') break;
          if(ps[i]!=pt[i] && ps[i]!='?') {
            pt+=i;
            goto re;
          }
        }
        ps+=i+1;
        pt+=i+2;
        break;
      case '+':
        k=*ps++;
        if(k<31) return 64;
        if(k==31) {
          k=*ps++;
          if(!k) return 64;
          while(*pt==31 && pt[1]==k) pt+=2;
        } else {
          while(*pt==k) pt++;
        }
        break;
      case '-':
        while(*pt>='0' && *pt<='9') pt++;
        break;
      case '_':
        while(*pt==' ' || *pt==10) pt++;
        break;
      case '\\':
        pt=ll_find(pt,'\\');
        if(!pt) goto notfound;
        pp=pt++;
        break;
      case '.':
        if(*pt==31 && pt[1]) pt+=2;
        else if(*pt==14 || *pt==30) pt=strchr(pt,'\\'),pt+=pt?1:0;
        else if(*pt) pt++;
        if(!pt) return 64;
        break;
      case '<': pt=title; break;
      case '>': pt+=strlen(pt); break;
      case '#':
        if(!so || !eo || so>eo) break;
        k=0;
        while(*so>='0' && *so<='9') k=10*k+*so++-'0';
        stack[sp++]=NVALUE(k);
        stack[sp++]=NVALUE(1);
        return sp;
      case '$':
        if(!so || !eo || so>eo) break;
        stack[sp++]=UVALUE(((so-title)<<16)|(eo-title),TY_FOR);
        stack[sp++]=NVALUE(1);
        return sp;
      case '%':
        if(!so || !eo || so>eo) break;
        stack[sp++]=NVALUE(eo-so);
        stack[sp++]=NVALUE(1);
        return sp;
      default: bad:
        if(main_options['v']) fprintf(stderr,"Invalid character (0x%02X) in string in LevelTable definition\n",ps[-1]);
        return 64;
    }
  }
  notfound: stack[sp++]=NVALUE(0); return sp;
}

static inline Uint32 ll_in(Value*stack,Sint16 top,Sint16 m) {
  while(--top>m) if(stack[top].t==stack[m-1].t && stack[top].u==stack[m-1].u) return 1;
  return 0;
}

#define ArithOp1(aa) ({ if(sp<1 || stack[sp-1].t) goto bad; Value t1=stack[sp-1]; stack[sp-1]=NVALUE(aa); })
#define ArithOp2(aa) ({ if(sp<2 || stack[sp-1].t || stack[sp-2].t) goto bad; Value t1=stack[sp-2]; Value t2=stack[sp-1]; sp--; stack[sp-1]=NVALUE(aa); })
#define ArithDivOp2(aa) ({ if(sp<2 || stack[sp-1].t || stack[sp-2].t || !stack[sp-1].u) goto bad; Value t1=stack[sp-2]; Value t2=stack[sp-1]; sp--; stack[sp-1]=NVALUE(aa); })
#define OtherOp1(aa) ({ if(sp<1) goto bad; Value t1=stack[sp-1]; stack[sp-1]=(aa); })
#define OtherOp2(aa) ({ if(sp<2) goto bad; Value t1=stack[sp-2]; Value t2=stack[sp-1]; sp--; stack[sp-1]=(aa); })

static Sint16 level_table_exec(Uint16 ptr,const unsigned char*lvl,long sz,ObjInfo*ob,Value*stack,Value*agg) {
  Sint16 sp=0;
  Uint32 k,m;
  while(sp<62) switch(ll_code[ptr++]) {
    case 0 ... 255: stack[sp++]=NVALUE(ll_code[ptr-1]); break;
    case 0x0200 ... 0x02FF: stack[sp++]=MVALUE(ll_code[ptr-1]&255); break;
    case 0x4000 ... 0x7FFF: stack[sp++]=CVALUE(ll_code[ptr-1]&0x3FFF); break;
1241
1242
1243
1244
1245
1246
1247


1248
1249
1250
1251
1252
1253
1254
    case OP_CLASS: if(!ob) goto bad; stack[sp++]=CVALUE(ob->class); break;
    case OP_COLLISIONLAYERS: if(!ob) goto bad; stack[sp++]=NVALUE(classes[ob->class]->collisionLayers); break;
    case OP_DELTA: ArithOp2(t1.u>t2.u?t1.u-t2.u:t2.u-t1.u); break;
    case OP_DENSITY: if(!ob) goto bad; stack[sp++]=NVALUE(classes[ob->class]->density); break;
    case OP_DIR: if(!ob) goto bad; stack[sp++]=NVALUE(ob->dir); break;
    case OP_DIV: ArithDivOp2(t1.u/t2.u); break;
    case OP_DIV_C: ArithDivOp2(t1.s/t2.s); break;


    case OP_EQ: OtherOp2(NVALUE((t1.u==t2.u && t1.t==t2.t)?1:0)); break;
    case OP_GE: ArithOp2(t1.u>=t2.u?1:0); break;
    case OP_GE_C: ArithOp2(t1.s>=t2.s?1:0); break;
    case OP_GOTO: ptr=ll_code[ptr]; break;
    case OP_GT: ArithOp2(t1.u>t2.u?1:0); break;
    case OP_GT_C: ArithOp2(t1.s>t2.s?1:0); break;
    case OP_IF:







>
>







1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
    case OP_CLASS: if(!ob) goto bad; stack[sp++]=CVALUE(ob->class); break;
    case OP_COLLISIONLAYERS: if(!ob) goto bad; stack[sp++]=NVALUE(classes[ob->class]->collisionLayers); break;
    case OP_DELTA: ArithOp2(t1.u>t2.u?t1.u-t2.u:t2.u-t1.u); break;
    case OP_DENSITY: if(!ob) goto bad; stack[sp++]=NVALUE(classes[ob->class]->density); break;
    case OP_DIR: if(!ob) goto bad; stack[sp++]=NVALUE(ob->dir); break;
    case OP_DIV: ArithDivOp2(t1.u/t2.u); break;
    case OP_DIV_C: ArithDivOp2(t1.s/t2.s); break;
    case OP_DROP: if(sp) --sp; break;
    case OP_DUP: if(!sp) goto bad; stack[sp]=stack[sp-1]; sp++; break;
    case OP_EQ: OtherOp2(NVALUE((t1.u==t2.u && t1.t==t2.t)?1:0)); break;
    case OP_GE: ArithOp2(t1.u>=t2.u?1:0); break;
    case OP_GE_C: ArithOp2(t1.s>=t2.s?1:0); break;
    case OP_GOTO: ptr=ll_code[ptr]; break;
    case OP_GT: ArithOp2(t1.u>t2.u?1:0); break;
    case OP_GT_C: ArithOp2(t1.s>t2.s?1:0); break;
    case OP_IF:
1294
1295
1296
1297
1298
1299
1300



1301
1302
1303
1304
1305
1306
1307
1308
1309






1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328





















1329
1330
1331
1332
1333
1334
1335
    case OP_MOD: ArithDivOp2(t1.u%t2.u); break;
    case OP_MOD_C: ArithDivOp2(t1.s%t2.s); break;
    case OP_MUL: ArithOp2(t1.u*t2.u); break;
    case OP_MUL_C: ArithOp2(t1.s*t2.s); break;
    case OP_NE: OtherOp2(NVALUE((t1.u==t2.u && t1.t==t2.t)?0:1)); break;
    case OP_NEG: ArithOp1(-t1.s); break;
    case OP_PLAYER: if(!ob) goto bad; stack[sp++]=NVALUE(classes[ob->class]->cflags&CF_PLAYER?1:0); break;



    case OP_RET: return sp;
    case OP_RSH: ArithOp2(t2.u&~31?0:t1.u>>t2.u); break;
    case OP_RSH_C: ArithOp2(t2.u&~31?(t1.s<0?-1:0):t1.s>>t2.u); break;
    case OP_STRING:
      // If starting with @ then a literal string, otherwise match a part of the level title.
      //TODO
      break;
    case OP_SUB: ArithOp2(t1.u-t2.u); break;
    case OP_TEMPERATURE: if(!ob) goto bad; stack[sp++]=NVALUE(classes[ob->class]->temperature); break;






    case OP_USERFLAG:
      if(!ob) goto bad;
      if(ll_code[ptr]<0x1020) k=classes[ob->class]->misc4;
      else if(ll_code[ptr]<0x1040) k=classes[ob->class]->misc5;
      else if(ll_code[ptr]<0x1060) k=classes[ob->class]->misc6;
      else if(ll_code[ptr]<0x1080) k=classes[ob->class]->misc7;
      else k=classes[ob->class]->collisionLayers;
      stack[sp].t=TY_NUMBER;
      stack[sp].u=(k&(1LL<<(ll_code[ptr++]&31)))?1:0;
      sp++;
      break;
    case OP_XLOC: if(!ob) goto bad; stack[sp++]=NVALUE(ob->x); break;
    case OP_YLOC: if(!ob) goto bad; stack[sp++]=NVALUE(ob->y); break;
    default: goto bad;
  }
  bad:
  if(main_options['v']) fprintf(stderr,"Error in LevelTable definition (at 0x%04X)\n",ptr);
  return -1;
}






















static void calculate_level_columns(sqlite3_stmt*st,const unsigned char*lvl,long sz) {
  ObjInfo ob;
  ObjInfo mru[2];
  Value stack[64];
  Value agg[64];
  int i,j,n,z;







>
>
>




|
|



>
>
>
>
>
>



















>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
    case OP_MOD: ArithDivOp2(t1.u%t2.u); break;
    case OP_MOD_C: ArithDivOp2(t1.s%t2.s); break;
    case OP_MUL: ArithOp2(t1.u*t2.u); break;
    case OP_MUL_C: ArithOp2(t1.s*t2.s); break;
    case OP_NE: OtherOp2(NVALUE((t1.u==t2.u && t1.t==t2.t)?0:1)); break;
    case OP_NEG: ArithOp1(-t1.s); break;
    case OP_PLAYER: if(!ob) goto bad; stack[sp++]=NVALUE(classes[ob->class]->cflags&CF_PLAYER?1:0); break;
    case OP_QC: OtherOp1(NVALUE(t1.t==TY_CLASS?1:0)); break;
    case OP_QM: OtherOp1(NVALUE(t1.t==TY_MESSAGE?1:0)); break;
    case OP_QN: OtherOp1(NVALUE(t1.t==TY_NUMBER?1:0)); break;
    case OP_RET: return sp;
    case OP_RSH: ArithOp2(t2.u&~31?0:t1.u>>t2.u); break;
    case OP_RSH_C: ArithOp2(t2.u&~31?(t1.s<0?-1:0):t1.s>>t2.u); break;
    case OP_STRING:
      k=ll_code[ptr++];
      if(stringpool[k][0]=='@') stack[sp++]=UVALUE(k,TY_STRING); else sp=ll_string(stringpool[k],lvl+6,stack,sp);
      break;
    case OP_SUB: ArithOp2(t1.u-t2.u); break;
    case OP_TEMPERATURE: if(!ob) goto bad; stack[sp++]=NVALUE(classes[ob->class]->temperature); break;
    case OP_TRACE:
      if(main_options['t'] && main_options['v']) {
        printf("'' ptr=0x%04X sp=%d ll_ndata=%d ll_naggregate=%d\n",ptr,sp,ll_ndata,ll_naggregate);
        for(k=0;k<sp;k++) printf("''  k=%d u=%u t=%u\n",k,stack[k].u,stack[k].t);
      }
      break;
    case OP_USERFLAG:
      if(!ob) goto bad;
      if(ll_code[ptr]<0x1020) k=classes[ob->class]->misc4;
      else if(ll_code[ptr]<0x1040) k=classes[ob->class]->misc5;
      else if(ll_code[ptr]<0x1060) k=classes[ob->class]->misc6;
      else if(ll_code[ptr]<0x1080) k=classes[ob->class]->misc7;
      else k=classes[ob->class]->collisionLayers;
      stack[sp].t=TY_NUMBER;
      stack[sp].u=(k&(1LL<<(ll_code[ptr++]&31)))?1:0;
      sp++;
      break;
    case OP_XLOC: if(!ob) goto bad; stack[sp++]=NVALUE(ob->x); break;
    case OP_YLOC: if(!ob) goto bad; stack[sp++]=NVALUE(ob->y); break;
    default: goto bad;
  }
  bad:
  if(main_options['v']) fprintf(stderr,"Error in LevelTable definition (at 0x%04X)\n",ptr);
  return -1;
}

static void ll_append_str(sqlite3_str*str,const unsigned char*p,long n) {
  const unsigned char*end=p+n;
  while(p<end) {
    if(*p>=32) {
      sqlite3_str_appendchar(str,1,*p++);
    } else if(*p==31) {
      p++;
      if(p<end && *p) sqlite3_str_appendchar(str,1,*p++);
    } else if(*p==10 || *p==15) {
      sqlite3_str_appendchar(str,1,32);
      p++;
    } else if(*p==14 || *p==30) {
      p=memchr(p,'\\',end-p);
      if(!p) return;
      p++;
    } else {
      p++;
    }
  }
}

static void calculate_level_columns(sqlite3_stmt*st,const unsigned char*lvl,long sz) {
  ObjInfo ob;
  ObjInfo mru[2];
  Value stack[64];
  Value agg[64];
  int i,j,n,z;
1415
1416
1417
1418
1419
1420
1421
1422


1423













1424





1425
1426

1427

1428
1429
1430
1431
1432
1433
1434
1435
1436
    }
  }
  // Data column values
  for(i=0;i<ll_ndata;i++) {
    j=level_table_exec(ll_data[i].ptr,lvl,sz,0,stack,agg);
    if(j<=0 || stack->t==TY_MARK) {
      sqlite3_bind_null(st,i+8);
    } else if(j>1 && (stack->t==TY_STRING || stack->t==TY_FOR)) {


      //TODO













    } else if(stack->t==TY_FOR) {





      sqlite3_bind_blob(st,i+8,lvl+(stack->u>>16)+6,stack->u&0xFFFF,SQLITE_TRANSIENT);
    } else if(stack->t==TY_STRING) {

      sqlite3_bind_blob(st,i+8,stringpool[stack->u]+1,strlen(stringpool[stack->u]+1),0);

    } else {
      if(ll_data[i].sgn) sqlite3_bind_int64(st,i+8,stack->s); else sqlite3_bind_int64(st,i+8,stack->u); break;
    }
  }
}

static int vt1_levels_open(sqlite3_vtab*vt,sqlite3_vtab_cursor**cur) {
  sqlite3_str*str;
  sqlite3_stmt*st1;







|
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
|
|
>
|
>

|







1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
    }
  }
  // Data column values
  for(i=0;i<ll_ndata;i++) {
    j=level_table_exec(ll_data[i].ptr,lvl,sz,0,stack,agg);
    if(j<=0 || stack->t==TY_MARK) {
      sqlite3_bind_null(st,i+8);
    } else if(stack->t==TY_STRING || stack->t==TY_FOR || stack->t==TY_LEVELSTRING) {
      sqlite3_str*str=sqlite3_str_new(userdb);
      for(n=0;n<j;n++) switch(stack[n].t) {
        case TY_NUMBER:
          sqlite3_str_appendf(str,"%u",(unsigned int)stack[n].u);
          break;
        case TY_CLASS:
          z=stack[n].u&0x3FFF;
          if(classes[z] && classes[z]->name) sqlite3_str_appendf(str,"%s",classes[z]->name);
          break;
        case TY_LEVELSTRING:
          if(stack[n].u>=nlevelstrings) break;
          ll_append_str(str,levelstrings[stack[n].u],strlen(levelstrings[stack[n].u]));
          break;
        case TY_STRING:
          sqlite3_str_appendall(str,stringpool[stack[n].u]+1);
          break;
        case TY_FOR:
          ll_append_str(str,lvl+(stack[n].u>>16)+6,stack[n].u&0xFFFF);
          break;
        // Otherwise, do nothing
      }
      if(z=sqlite3_str_length(str)) {
        sqlite3_bind_blob(st,i+8,sqlite3_str_finish(str),z,sqlite3_free);
      } else {
        sqlite3_free(sqlite3_str_finish(str));
        sqlite3_bind_zeroblob(st,i+8,0);
      }
    } else {
      if(ll_data[i].sgn) sqlite3_bind_int64(st,i+8,stack->s); else sqlite3_bind_int64(st,i+8,stack->u);
    }
  }
}

static int vt1_levels_open(sqlite3_vtab*vt,sqlite3_vtab_cursor**cur) {
  sqlite3_str*str;
  sqlite3_stmt*st1;

Modified game.c from [7219595d81] to [2c724763e6].

727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
  int i;
  const char*p;
  sqlite3_int64 v;
  if(t==SQLITE_NULL) return;
  if(dc->flag&1) w=255;
  if(t==SQLITE_BLOB || t==SQLITE_TEXT) {
    blob:
    i=copy_text_to_plain(buf,w,sqlite3_column_text(st,nc));
    if(dc->form[0]=='R') a=w-i;
    if(dc->flag&2) co=0xFF;
  } else {
    // This implementation does not check that the format is necessarily valid.
    // You should not rely on the use of any undocumented format.
    v=sqlite3_column_int64(st,nc);
    if(dc->flag&2) {
      co=0xFF;







|
|







727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
  int i;
  const char*p;
  sqlite3_int64 v;
  if(t==SQLITE_NULL) return;
  if(dc->flag&1) w=255;
  if(t==SQLITE_BLOB || t==SQLITE_TEXT) {
    blob:
    i=snprintf(buf,w,"%s",sqlite3_column_text(st,nc));
    if(dc->form[0]=='R' && i<w) a=w-i;
    if(dc->flag&2) co=0xFF;
  } else {
    // This implementation does not check that the format is necessarily valid.
    // You should not rely on the use of any undocumented format.
    v=sqlite3_column_int64(st,nc);
    if(dc->flag&2) {
      co=0xFF;