Free Hero Mesh

Check-in [6d402e1175]
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 command to create a new empty puzzle set
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 6d402e117588fd9cda936a490fe09db2c71c5ae3
User & Date: user on 2020-12-19 22:24:37
Other Links: manifest | tags
Context
2020-12-19
22:31
Add a message that game cannot continue with no objects check-in: f1435f4c66 user: user tags: trunk
22:24
Implement command to create a new empty puzzle set check-in: 6d402e1175 user: user tags: trunk
22:21
Fix a mistake in the beginning phase in exec.c check-in: 99bee720be user: user tags: trunk
Changes

Modified commandline.doc from [4eca270fe2] to [edc9378782].

32
33
34
35
36
37
38
39
40


41
42
43
44
45
46
47
  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.

-e
  Start in the editor instead of game.

-n (not implemented yet)
  Create a new puzzle set.



-r
  Open in read-only mode.

-t
  Enable tracing.








|
|
>
>







32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
  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.

-e
  Start in the editor instead of game.

-n
  Create a new puzzle set. The .xclass and .class files should already
  exist; the .level and .solution files should not already exist, and will
  be created with minimal data.

-r
  Open in read-only mode.

-t
  Enable tracing.

Modified edit.c from [07a6400988] to [4ddc1ba4e4].

386
387
388
389
390
391
392


















          return;
        }
        redraw_editor();
        break;
    }
  }
}

























>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
          return;
        }
        redraw_editor();
        break;
    }
  }
}

void write_empty_level_set(FILE*fp) {
  static const unsigned char d[]=
    "CLASS.DEF\0\x00\x00\x02\x00"
    "\x00\x00" // no classes or messages
    "LEVEL.IDX\0\x00\x00\x02\x00"
    "\x00\x00" // only one level
    "0.LVL\0\x00\x00\x0D\x00"
    "\x00\x00" // level version
    "\x00\x00" // level code
    "\x00\x00" // width/height
    "Blank\0" // title
    "\xFF" // objects
  ;
  fwrite(d,1,sizeof(d)-1,fp);
  fflush(fp);
  rewind(fp);
}

Modified heromesh.h from [34bcd17910] to [62b3419027].

243
244
245
246
247
248
249

250
// == game ==

void run_game(void);

// == edit ==

void run_editor(void);









>

243
244
245
246
247
248
249
250
251
// == game ==

void run_game(void);

// == edit ==

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

Modified main.c from [0ebe47f999] to [55a050f2d9].

436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458

459
460
461
462
463
464
465
466
467
468
469
470
471
  char*nam3;
  struct stat fst;
  fprintf(stderr,"Initializing user cache...\n");
  if(z=sqlite3_exec(userdb,"BEGIN;",0,0,0)) fatal("SQL error (%d): %s\n",z,sqlite3_errmsg(userdb));
  if(z=sqlite3_prepare_v2(userdb,"SELECT `ID`, `TIME` FROM `USERCACHEINDEX` WHERE `NAME` = ?1;",-1,&st,0)) fatal("SQL error (%d): %s\n",z,sqlite3_errmsg(userdb));
  nam1=sqlite3_mprintf("%s.level",basefilename);
  if(!nam1) fatal("Allocation failed\n");
  nam2=realpath(nam1,0);
  if(!nam2) fatal("Cannot find real path of '%s': %m\n",nam1);
  levelfp=fopen(nam2,main_options['r']?"r":"r+");
  if(!levelfp) fatal("Cannot open '%s' for reading%s: %m\n",nam2,main_options['r']?"":"/writing");
  sqlite3_free(nam1);
  sqlite3_bind_text(st,1,nam2,-1,0);
  z=sqlite3_step(st);
  if(z==SQLITE_ROW) {
    leveluc=sqlite3_column_int64(st,0);
    t1=sqlite3_column_int64(st,1);
  } else if(z==SQLITE_DONE) {
    leveluc=t1=-1;
  } else {
    fatal("SQL error (%d): %s\n",z,sqlite3_errmsg(userdb));
  }
  sqlite3_reset(st);

  nam1=sqlite3_mprintf("%s.solution",basefilename);
  if(!nam1) fatal("Allocation failed\n");
  nam3=realpath(nam1,0);
  if(!nam3) fatal("Cannot find real path of '%s': %m\n",nam1);
  if(!strcmp(nam2,nam3)) fatal("Level and solution files seem to be the same file\n");
  solutionfp=fopen(nam3,main_options['r']?"r":"r+");
  if(!solutionfp) fatal("Cannot open '%s' for reading%s: %m\n",nam3,main_options['r']?"":"/writing");
  sqlite3_free(nam1);
  sqlite3_bind_text(st,1,nam3,-1,0);
  z=sqlite3_step(st);
  if(z==SQLITE_ROW) {
    solutionuc=sqlite3_column_int64(st,0);
    t2=sqlite3_column_int64(st,1);







|

|













>


|


|







436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
  char*nam3;
  struct stat fst;
  fprintf(stderr,"Initializing user cache...\n");
  if(z=sqlite3_exec(userdb,"BEGIN;",0,0,0)) fatal("SQL error (%d): %s\n",z,sqlite3_errmsg(userdb));
  if(z=sqlite3_prepare_v2(userdb,"SELECT `ID`, `TIME` FROM `USERCACHEINDEX` WHERE `NAME` = ?1;",-1,&st,0)) fatal("SQL error (%d): %s\n",z,sqlite3_errmsg(userdb));
  nam1=sqlite3_mprintf("%s.level",basefilename);
  if(!nam1) fatal("Allocation failed\n");
  nam2=main_options['n']?strdup(nam1):realpath(nam1,0);
  if(!nam2) fatal("Cannot find real path of '%s': %m\n",nam1);
  levelfp=fopen(nam2,main_options['n']?"w+x":main_options['r']?"r":"r+");
  if(!levelfp) fatal("Cannot open '%s' for reading%s: %m\n",nam2,main_options['r']?"":"/writing");
  sqlite3_free(nam1);
  sqlite3_bind_text(st,1,nam2,-1,0);
  z=sqlite3_step(st);
  if(z==SQLITE_ROW) {
    leveluc=sqlite3_column_int64(st,0);
    t1=sqlite3_column_int64(st,1);
  } else if(z==SQLITE_DONE) {
    leveluc=t1=-1;
  } else {
    fatal("SQL error (%d): %s\n",z,sqlite3_errmsg(userdb));
  }
  sqlite3_reset(st);
  if(main_options['n']) write_empty_level_set(levelfp);
  nam1=sqlite3_mprintf("%s.solution",basefilename);
  if(!nam1) fatal("Allocation failed\n");
  nam3=main_options['n']?strdup(nam1):realpath(nam1,0);
  if(!nam3) fatal("Cannot find real path of '%s': %m\n",nam1);
  if(!strcmp(nam2,nam3)) fatal("Level and solution files seem to be the same file\n");
  solutionfp=fopen(nam3,main_options['n']?"w+x":main_options['r']?"r":"r+");
  if(!solutionfp) fatal("Cannot open '%s' for reading%s: %m\n",nam3,main_options['r']?"":"/writing");
  sqlite3_free(nam1);
  sqlite3_bind_text(st,1,nam3,-1,0);
  z=sqlite3_step(st);
  if(z==SQLITE_ROW) {
    solutionuc=sqlite3_column_int64(st,0);
    t2=sqlite3_column_int64(st,1);
827
828
829
830
831
832
833




834
835
836
837
838
839
840
  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;




  }
  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();







>
>
>
>







828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
  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;
  }
  if(main_options['n']) {
    if(main_options['r']) fatal("Switches -r and -n are conflicting\n");
    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();
848
849
850
851
852
853
854

855
856
857
858
859
860
861
  init_screen();
  load_pictures();
  if(main_options['T']) {
    test_mode();
    return 0;
  }
  init_usercache();

  load_classes();
  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;







>







853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
  init_screen();
  load_pictures();
  if(main_options['T']) {
    test_mode();
    return 0;
  }
  init_usercache();
  if(main_options['n']) return 0;
  load_classes();
  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;