Free Hero Mesh

Check-in [0a234d4210]
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:Do not hard code number of pictures per row in the internal representation; use macros instead. This number is increased from 16 to 128 in order to avoid coordinate overflows for puzzle sets with large number of pictures if a large picture size is selected.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 0a234d421062927cbe836401f9b032815cd0fbf8
User & Date: user on 2022-09-14 23:14:25
Other Links: manifest | tags
Context
2022-10-05
23:26
Implement LastR, NextR, ThisR; this is not tested and not fully complete; it will be used in future to implement replacing objects with new ones in COLLIDE and COLLIDEBY messages. check-in: 1114ae75d5 user: user tags: trunk
2022-09-14
23:14
Do not hard code number of pictures per row in the internal representation; use macros instead. This number is increased from 16 to 128 in order to avoid coordinate overflows for puzzle sets with large number of pictures if a large picture size is selected. check-in: 0a234d4210 user: user tags: trunk
2022-09-08
05:15
TODO features; not implemented yet check-in: ba571cb343 user: user tags: trunk
Changes

Modified TODO from [1647a6cfce] to [f100d9392d].

1
2
3
4
5
6
7
8
9


10
11
12
13
14
15
16
1
2
3
4
5
6
7
8

9
10
11
12
13
14
15
16
17








-
+
+







* Sound effects
  * Compressed wave sounds (?)
  * Numeric sounds (?)
* Game engine features
  * String data (partially implemented)
  * A ,PopUp command to use a popup with arguments starting from a mark
  * Returning a class from COLLIDE/COLLIDEBY to transform
  * Possibility to define auto-generation levels mode
  * Popup inventory list (with optional possibility of choice)
  * Popup inventory list (with optional possibility of choice) (?)
  * Playfield array
* Editor
  * Mouse dragging
* Deal better with allowing to skip past corrupted levels
* Picture editor/loading
  * Allowing more altimages
* Puzzle set catalog format (using with internet; a separate program)
* Inventory/replay hybrid view

Modified comconfig.doc from [f356e676ad] to [51d7f6c934].

117
118
119
120
121
122
123




124
125
126
127
128
129
130
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134







+
+
+
+







  generator built in to SQLite. (This will override the definition of the
  SQL RANDOM() function if it is defined.)

CONFIG_USERCACHE_PERMISSIONS
  If defined as a octal number, set the default file permissions of the
  user cache database when creating it. (The user can still change them
  afterward by using chmod.)

CONFIG_USING_32BIT_COORDINATES
  If defined, allow 32-bit coordinates in SDL_Rect and in other graphics
  functions of SDL.

CONFIG_USING_APPIMAGE
  If defined, it will check the environment variables having to do with
  AppImage and will be able to load the default resources from there, as
  well as allow the configuration file to reference the AppImage directory.

CONFIG_USING_ARM_NEON

Modified picture.c from [57df01a3fa] to [ff76ebbf80].

17
18
19
20
21
22
23




24
25
26
27
28
29
30
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34







+
+
+
+







#include "smallxrm.h"
#include "pcfont.h"
#include "quarks.h"
#include "heromesh.h"
#include "cursorshapes.h"
#include "keyicons.xbm"

#define PPR 128 // pictures per row
#define PPRM 127 // pictures per row bit mask (one less than pictures per row)
#define PPRS 7 // pictures per row bit shift amount (log2 of pictures per row)

SDL_Surface*screen;
Uint16 picture_size;
int left_margin;
Uint32 codepage;

static SDL_Surface*picts;
static Uint8*curpic;
86
87
88
89
90
91
92
93

94
95
96
97
98
99
100
90
91
92
93
94
95
96

97
98
99
100
101
102
103
104







-
+







  if(fp) fclose(fp);
  SDL_SetColors(screen,pal,0,256);
  SDL_SetColors(picts,pal,0,256);
}

void draw_picture(int x,int y,Uint16 img) {
  // To be called only when screen is unlocked!
  SDL_Rect src={(img&15)*picture_size,(img>>4)*picture_size,picture_size,picture_size};
  SDL_Rect src={(img&PPRM)*picture_size,(img>>PPRS)*picture_size,picture_size,picture_size};
  SDL_Rect dst={x,y,picture_size,picture_size};
  SDL_BlitSurface(picts,&src,screen,&dst);
}

void draw_cell(int x,int y) {
  // To be called only when screen is unlocked!
  Uint32 o;
449
450
451
452
453
454
455
456

457
458
459
460
461
462
463
453
454
455
456
457
458
459

460
461
462
463
464
465
466
467







-
+







  which=i;
  i=1;
  while(which--) load_one_picture_sub(fp,size=buf[i],meth=(i==1?*buf>>4:buf[(*buf&15)+1+((i-2)>>1)]>>(i&1?4:0))&15),i++;
  if(meth==5 || meth==6) meth^=3;
  if(meth==15) meth=0;
  SDL_LockSurface(picts);
  pitch=picts->pitch;
  pix=picts->pixels+((img&15)+pitch*(img>>4))*picture_size;
  pix=picts->pixels+((img&PPRM)+pitch*(img>>PPRS))*picture_size;
  for(i=0;i<size;i++) {
    for(h=0;h<zoom;h++) {
      for(j=0;j<size;j++) {
        if(meth&1) j=size-j-1;
        if(meth&2) i=size-i-1;
        for(k=0;k<zoom;k++) *pix++=curpic[meth&4?j*size+i:i*size+j];
        if(meth&1) j=size-j-1;
533
534
535
536
537
538
539
540

541
542
543
544
545
546
547
537
538
539
540
541
542
543

544
545
546
547
548
549
550
551







-
+







  }
  SDL_UnlockSurface(picts);
  free(d);
}

static void load_dependent_picture(FILE*fp,Sint32 sz,Uint16 img,int alt) {
  SDL_Rect src={0,0,picture_size,picture_size};
  SDL_Rect dst={(img&15)*picture_size,(img>>4)*picture_size,picture_size,picture_size};
  SDL_Rect dst={(img&PPRM)*picture_size,(img>>PPRS)*picture_size,picture_size,picture_size};
  sqlite3_stmt*st;
  int c,i,x,y;
  char nam[128];
  Uint8 buf[512];
  Uint8*p;
  if(sqlite3_prepare_v2(userdb,"SELECT `ID` FROM `PICTURES` WHERE `NAME` = ?1 AND NOT `DEPENDENT`;",-1,&st,0))
   fatal("Unable to prepare SQL statement while loading pictures: %s\n",sqlite3_errmsg(userdb));
561
562
563
564
565
566
567
568
569


570
571
572
573
574
575
576
577
578
579
580
581
582
583
584

585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603

604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622

623
624
625
626
627
628
629
565
566
567
568
569
570
571


572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587

588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606

607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625

626
627
628
629
630
631
632
633







-
-
+
+














-
+


















-
+


















-
+







      sqlite3_finalize(st);
      return;
    } else if(i!=SQLITE_ROW) {
      fatal("SQL error (%d): %s\n",i,sqlite3_errmsg(userdb));
    }
    i=sqlite3_column_int(st,0);
    sqlite3_reset(st);
    src.x=(i&15)*picture_size;
    src.y=(i>>4)*picture_size;
    src.x=(i&PPRM)*picture_size;
    src.y=(i>>PPRS)*picture_size;
    SDL_SetColorKey(picts,0,0);
    SDL_BlitSurface(picts,&src,picts,&dst);
  } else {
    SDL_FillRect(picts,&dst,0);
  }
  while(sz-->0) switch(c=fgetc(fp)) {
    case 0 ... 7: // Flip/rotate
      pic_orientation(&dst,c);
      break;
    case 8: // *->* *->* *->*
      c=fgetc(fp);
      sz-=c+1;
      fread(buf,1,c&255,fp);
      SDL_LockSurface(picts);
      p=picts->pixels+((img&15)+picts->pitch*(img>>4))*picture_size;
      p=picts->pixels+((img&PPRM)+picts->pitch*(img>>PPRS))*picture_size;
      for(y=0;y<picture_size;y++) {
        for(x=0;x<picture_size;x++) {
          for(i=0;i<c;i+=2) {
            if(p[x]==buf[i]) {
              p[x]=buf[i+1];
              break;
            }
          }
        }
        p+=picts->pitch;
      }
      SDL_UnlockSurface(picts);
      break;
    case 9: // *->*->*->*->*
      c=fgetc(fp);
      sz-=c+1;
      fread(buf,1,c&255,fp);
      SDL_LockSurface(picts);
      p=picts->pixels+((img&15)+picts->pitch*(img>>4))*picture_size;
      p=picts->pixels+((img&PPRM)+picts->pitch*(img>>PPRS))*picture_size;
      for(y=0;y<picture_size;y++) {
        for(x=0;x<picture_size;x++) {
          for(i=0;i<c-1;i++) {
            if(p[x]==buf[i]) {
              p[x]=buf[i+1];
              break;
            }
          }
        }
        p+=picts->pitch;
      }
      SDL_UnlockSurface(picts);
      break;
    case 10: // *<->* *<->* *<->*
      c=fgetc(fp);
      sz-=c+1;
      fread(buf,1,c&255,fp);
      SDL_LockSurface(picts);
      p=picts->pixels+((img&15)+picts->pitch*(img>>4))*picture_size;
      p=picts->pixels+((img&PPRM)+picts->pitch*(img>>PPRS))*picture_size;
      for(y=0;y<picture_size;y++) {
        for(x=0;x<picture_size;x++) {
          for(i=0;i<c;i+=2) {
            if(p[x]==buf[i]) {
              p[x]=buf[i+1];
              break;
            } else if(p[x]==buf[i+1]) {
652
653
654
655
656
657
658
659
660


661
662
663
664
665
666
667
656
657
658
659
660
661
662


663
664
665
666
667
668
669
670
671







-
-
+
+







        fprintf(stderr,"Cannot find overlay for a dependent picture; ignoring\n");
        break;
      } else if(i!=SQLITE_ROW) {
        fatal("SQL error (%d): %s\n",i,sqlite3_errmsg(userdb));
      }
      i=sqlite3_column_int(st,0);
      sqlite3_reset(st);
      src.x=(i&15)*picture_size;
      src.y=(i>>4)*picture_size;
      src.x=(i&PPRM)*picture_size;
      src.y=(i>>PPRS)*picture_size;
      SDL_BlitSurface(picts,&src,picts,&dst);
      break;
    case 12 ... 15: // Shift (up/down/right/left)
      while(sz>0) {
        x=fgetc(fp);
        y=fgetc(fp);
        sz-=2;
681
682
683
684
685
686
687
688

689
690
691
692
693
694
695
685
686
687
688
689
690
691

692
693
694
695
696
697
698
699







-
+







      }
      break;
    case 16: // Hue/shade
      fread(buf,1,2,fp);
      c=(Sint8)buf[1];
      sz-=2;
      SDL_LockSurface(picts);
      p=picts->pixels+((img&15)+picts->pitch*(img>>4))*picture_size;
      p=picts->pixels+((img&PPRM)+picts->pitch*(img>>PPRS))*picture_size;
      for(y=0;y<picture_size;y++) {
        for(x=0;x<picture_size;x++) {
          if(p[x] && p[x]<=225) {
            i=(p[x]-1)%15+c;
            p[x]=15*(((p[x]-1)/15+buf[0])%15)+1;
            if(i<0) p[x]=1; else if(i>14) p[x]=15; else p[x]+=i;
          }
875
876
877
878
879
880
881
882

883
884
885
886
887
888
889
879
880
881
882
883
884
885

886
887
888
889
890
891
892
893







-
+







  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+16)>>4),8,0,0,0,0);
  picts=SDL_CreateRGBSurface((i?SDL_HWSURFACE:SDL_SWSURFACE)|SDL_SRCCOLORKEY,picture_size<<PPRS,picture_size*((n+PPR)>>PPRS),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));
    }