Free Hero Mesh

Check-in [42f95966ca]
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 autotest mode and add the config.doc file
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 42f95966ca0916ccd1e29f0fa60d0a4af36741f9
User & Date: user on 2021-01-10 03:23:24.209
Other Links: manifest | tags
Context
2021-01-10
23:58
Mention in the documentation about the autotest mode, regular expression to find errors check-in: 839e21c938 user: user tags: trunk
03:23
Implement autotest mode and add the config.doc file check-in: 42f95966ca user: user tags: trunk
2021-01-09
03:03
Fix a mistake in the solution replay and document that command. check-in: 8524828a0e user: user tags: trunk
Changes
21
22
23
24
25
26
27
28

29
30
31
32
33
34
35
21
22
23
24
25
26
27

28
29
30
31
32
33
34
35







-
+







-M
  Write details of macro expansion to stdout.

-T
  Mode for testing some internal functions of Free Hero Mesh and SDL. You
  probably do not need to use this mode yourself.

-a (not implemented yet)
-a
  Autotest levels, ensuring that the provided solution is valid.

-c
  Only load classes and then terminate. This can be used to test that
  the class definition file does not contain syntax errors, or it can be
  used together with -C, -H, -L, -M to see how it is parsing it.

Added config.doc version [f70dddc30c].
Modified game.c from [5f7adb0422] to [bcb10cb33f].
698
699
700
701
702
703
704


























































705
706
707
708
709
710
711
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







        break;
    }
  }
  quit:
  save_replay();
  exit(0);
}

void run_auto_test(void) {
  Uint8 rc=0;
  int lvl,pro,i,n;
  const char*t;
  setbuf(stdout,0);
  solution_replay=1;
  optionquery[1]=Q_progress;
  t=xrm_get_resource(resourcedb,optionquery,optionquery,2);
  pro=t?strtol(t,0,10):0;
  optionquery[1]=Q_level;
  t=xrm_get_resource(resourcedb,optionquery,optionquery,2);
  if(n=lvl=t?strtol(t,0,10):0) goto start;
  for(n=1;n<=level_nindex;n++) {
    if(lvl) break;
    start:
    printf("Level %d",n);
    if(t=load_level(-n)) {
      printf(": Error during loading: %s\n",t);
      rc=1; continue;
    }
    load_replay();
    if(!replay_count) {
      printf(": Solution is absent, invalid, or for wrong version of this level\n");
      rc=1; continue;
    }
    if(t=init_level()) {
      printf(": Error during initialization: %s\n",t);
      rc=1; continue;
    }
    if(gameover==-1) {
      printf(": Lose during initialization\n");
      rc=1; continue;
    }
    for(i=0;i<replay_count;i++) {
      if(gameover) {
        printf(": Premature termination on move %d\n",i);
        rc=1; goto cont;
      }
      if(pro && !(i%pro)) putchar('.');
      if(t=execute_turn(replay_list[i])) {
        printf(": Error on move %d: %s\n",i+1,t);
        rc=1; goto cont;
      }
      if(gameover==-1) {
        printf(": Game loss on move %d\n",i+1);
        rc=1; goto cont;
      }
    }
    if(gameover<=0) {
      printf(": Game not terminated after %d moves\n",replay_count);
      rc=1; continue;
    }
    printf(": OK\n");
    cont: ;
  }
  exit(rc);
}

void locate_me(int x,int y) {
  Uint8 c=7;
  SDL_Rect r,rh,rv;
  SDL_Event ev;
  if(!screen) return;
  redraw_game();
257
258
259
260
261
262
263

264
265
266
267
268
269
270
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271







+







// == game ==

extern Uint8*replay_list;
extern Uint16 replay_size,replay_count,replay_pos,replay_mark;
extern Uint8 solution_replay;

void run_game(void);
void run_auto_test(void);
void locate_me(int x,int y);

// == edit ==

void run_editor(void);
void write_empty_level_set(FILE*);

Modified main.c from [46407c4aee] to [e9e638bdea].
862
863
864
865
866
867
868

869
870
871
872
873
874
875
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876







+







    globalclassname=strrchr(basefilename,'/');
    globalclassname=globalclassname?globalclassname+1:basefilename;
  }
  if(main_options['n']) {
    if(main_options['r']) fatal("Switches -r and -n are conflicting\n");
    main_options['x']=1;
  }
  if(main_options['a']) main_options['r']=main_options['x']=1;
  if(!main_options['c']) load_options();
  if(argc>optind) read_options(argc-optind,argv+optind);
  *optionquery=xrm_make_quark(globalclassname,0)?:xrm_anyq;
#ifdef __GNUC__
  stack_protect_mark=__builtin_frame_address(0);
  set_stack_protection();
#endif
891
892
893
894
895
896
897

898
899
900
901
902
903
904
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906







+







  load_level_index();
  optionquery[1]=Q_maxObjects;
  max_objects=strtoll(xrm_get_resource(resourcedb,optionquery,optionquery,2)?:"",0,0)?:0xFFFF0000L;
  set_tracing();
  annihilate();
  optionquery[1]=Q_level;
  if(level_ord=strtol(xrm_get_resource(resourcedb,optionquery,optionquery,2)?:"",0,10)) log_if_error(load_level(-level_ord));
  if(main_options['a']) run_auto_test();
  if(main_options['x']) {
    fprintf(stderr,"Ready for executing SQL statements.\n");
    do_sql_mode();
    return 0;
  }
  for(;;) { if(main_options['e']) run_editor(); else run_game(); }
}
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
19
20
21
22
23
24
25

26
27
28
29
30
31
32







-







Dump all class data.
.IP -H
Dump the hash table.
.IP -L
Display all tokens being read from the class definition file.
.IP -a
Autotest levels, ensuring that the provided solution is valid.
(Not implemented yet)
.IP -c
Only load classes and then terminate.
This can be used to verify that the class definition file does not contain syntax errors.
You can also use it with some other options to display details.
.IP -e
Start the level editor.
.IP -n
Modified quarks from [1be78c1f08] to [64ae3938b3].
212
213
214
215
216
217
218

219
212
213
214
215
216
217
218
219
220







+

level
tracePrefix
stackProtection
maxObjects
traceAll
traceObject
showInventory
progress

Modified quarks.h from [eb6ffb657a] to [600f40dc0a].
177
178
179
180
181
182
183

184
185
186
187
188
189
190
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191







+







#define Q_level 178
#define Q_tracePrefix 179
#define Q_stackProtection 180
#define Q_maxObjects 181
#define Q_traceAll 182
#define Q_traceObject 183
#define Q_showInventory 184
#define Q_progress 185
static const char*const global_quarks[]={
  "screenWidth",
  "screenHeight",
  "margin",
  "palette",
  "popupColors",
  "imageSize",
361
362
363
364
365
366
367

368
369
370
371
372
373
374
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376







+







  "level",
  "tracePrefix",
  "stackProtection",
  "maxObjects",
  "traceAll",
  "traceObject",
  "showInventory",
  "progress",
0};
#ifdef HEROMESH_BINDINGS
static const SDLKey quark_to_key[Q_undo+1-Q_backspace]={
SDLK_BACKSPACE,
SDLK_TAB,
SDLK_CLEAR,
SDLK_RETURN,