Free Hero Mesh

Check-in [1c62f22813]
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 replay. (The replay implementation is not yet complete; it doesn't display the replay list anywhere, nor does it save it, nor replay solutions.)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 1c62f22813b87ee215d981c1b0fa1e3d068675c0
User & Date: user on 2021-01-04 00:39:07
Other Links: manifest | tags
Context
2021-01-04
02:44
Implement replay marks. check-in: 0393bebb68 user: user tags: trunk
00:39
Start to implement replay. (The replay implementation is not yet complete; it doesn't display the replay list anywhere, nor does it save it, nor replay solutions.) check-in: 1c62f22813 user: user tags: trunk
2021-01-03
09:43
Implement sliding check-in: 1490be64d5 user: user tags: trunk
Changes

Modified function.c from [5bdde93d2d] to [ee9cae7e1c].

237
238
239
240
241
242
243




244
245
246
247
248
249
250
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254







+
+
+
+







  s=load_level(sqlite3_value_int(*argv));
  if(s) sqlite3_result_error(cxt,s,-1);
}

static void fn_modstate(sqlite3_context*cxt,int argc,sqlite3_value**argv) {
  sqlite3_result_int(cxt,SDL_GetModState());
}

static void fn_movenumber(sqlite3_context*cxt,int argc,sqlite3_value**argv) {
  sqlite3_result_int(cxt,replay_pos);
}

static void fn_mvalue(sqlite3_context*cxt,int argc,sqlite3_value**argv) {
  int a;
  if(sqlite3_value_type(*argv)==SQLITE_NULL) return;
  a=sqlite3_value_int(*argv)&0xFFFF;
  sqlite3_result_int64(cxt,a|((sqlite3_int64)TY_MESSAGE<<32LL));
}
933
934
935
936
937
938
939

940
941
942
943
944
945
946
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951







+







  sqlite3_create_function(userdb,"HEROMESH_UNESCAPE",1,SQLITE_UTF8|SQLITE_DETERMINISTIC,0,fn_heromesh_unescape,0,0);
  sqlite3_create_function(userdb,"LEVEL",0,SQLITE_UTF8,&level_ord,fn_level,0,0);
  sqlite3_create_function(userdb,"LEVEL_CACHEID",0,SQLITE_UTF8|SQLITE_DETERMINISTIC,ptr0,fn_cacheid,0,0);
  sqlite3_create_function(userdb,"LEVEL_ID",0,SQLITE_UTF8,&level_id,fn_level,0,0);
  sqlite3_create_function(userdb,"LEVEL_TITLE",0,SQLITE_UTF8,0,fn_level_title,0,0);
  sqlite3_create_function(userdb,"LOAD_LEVEL",1,SQLITE_UTF8,0,fn_load_level,0,0);
  sqlite3_create_function(userdb,"MODSTATE",0,SQLITE_UTF8,0,fn_modstate,0,0);
  sqlite3_create_function(userdb,"MOVENUMBER",0,SQLITE_UTF8,0,fn_movenumber,0,0);
  sqlite3_create_function(userdb,"MVALUE",1,SQLITE_UTF8|SQLITE_DETERMINISTIC,0,fn_mvalue,0,0);
  sqlite3_create_function(userdb,"NVALUE",1,SQLITE_UTF8|SQLITE_DETERMINISTIC,0,fn_zero_extend,0,0);
  sqlite3_create_function(userdb,"OVALUE",1,SQLITE_UTF8,0,fn_ovalue,0,0);
  sqlite3_create_function(userdb,"PFHEIGHT",0,SQLITE_UTF8,&pfheight,fn_pfsize,0,0);
  sqlite3_create_function(userdb,"PFWIDTH",0,SQLITE_UTF8,&pfwidth,fn_pfsize,0,0);
  sqlite3_create_function(userdb,"PICTURE_SIZE",0,SQLITE_UTF8|SQLITE_DETERMINISTIC,0,fn_picture_size,0,0);
  sqlite3_create_function(userdb,"READ_LUMP_AT",2,SQLITE_UTF8,0,fn_read_lump_at,0,0);

Modified game.c from [9af2d99ebb] to [6ca5fb9cf3].

14
15
16
17
18
19
20



21
22
23
24
25
26
27
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30







+
+
+







#include "sqlite3.h"
#include "smallxrm.h"
#include "heromesh.h"
#include "quarks.h"
#include "cursorshapes.h"
#include "names.h"

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

static volatile Uint8 timerflag;
static int exam_scroll;
static Uint8*inputs;
static int inputs_size,inputs_count;

static void redraw_game(void) {
  char buf[32];
137
138
139
140
141
142
143
144
145
146


147
148
149
150
151
152
153
140
141
142
143
144
145
146



147
148
149
150
151
152
153
154
155







-
-
-
+
+







  draw_text(0,40,buf,0xF0,0xF1);
  SDL_UnlockSurface(screen);
  SDL_Flip(screen);
}

static void begin_level(int id) {
  const char*t;
  free(inputs);
  inputs=0;
  inputs_size=inputs_count=0;
  inputs_count=0;
  replay_pos=0;
  t=load_level(id)?:init_level();
  if(t) {
    gameover=-1;
    screen_message(t);
  } else {
    gameover=0;
  }
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412























413
414
415
416
417
418
419
394
395
396
397
398
399
400

401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
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







-













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







  if(xy<0 || xy>=64*64) return;
  n=playfield[xy];
  if(n==VOIDLINK) return;
  while(n!=VOIDLINK && objects[n]->up!=VOIDLINK) n=objects[n]->up;
  if(!classes[objects[n]->class]->gamehelp) return;
  s=sqlite3_mprintf("\x0C\x0E%s:%d\\ %s\x0B\x0F%s",classes[objects[n]->class]->name,objects[n]->image,classes[objects[n]->class]->name,classes[objects[n]->class]->gamehelp);
  if(!s) fatal("Allocation failed\n");
  
  modal_draw_popup(s);
  sqlite3_free(s);
}

static int game_command(int prev,int cmd,int number,int argc,sqlite3_stmt*args,void*aux) {
  switch(cmd) {
    case '\' ': // Play a move
      if(inputs_count>=inputs_size) {
        inputs=realloc(inputs,inputs_size+=32);
        if(!inputs) fatal("Allocation failed\n");
      }
      inputs[inputs_count++]=number;
      return 0;
    case '+ ': // Replay
      if(number>replay_count-replay_pos) number=replay_count-replay_pos;
      if(inputs_count+number>=inputs_size) {
        inputs=realloc(inputs,inputs_size+=number+1);
        if(!inputs) fatal("Allocation failed\n");
      }
      memcpy(inputs+inputs_count,replay_list+replay_pos,number);
      inputs_count+=number;
      return 0;
    case '- ': // Rewind
      number=replay_pos-number;
      if(number<0) number=0;
      //fallthru
    case '= ': // Restart
      begin_level(level_id);
      if(!number) return 1;
      if(number>replay_count) number=replay_count;
      if(number>=inputs_size) {
        inputs=realloc(inputs,inputs_size=number+1);
        if(!inputs) fatal("Allocation failed\n");
      }
      memcpy(inputs,replay_list,inputs_count=number);
      return 1;
    case '^E': // Edit
      return -2;
    case '^Q': // Quit
      return -1;
    case '^T': // Show title
      modal_draw_popup(level_title);
      return prev;
457
458
459
460
461
462
463

464
465
466
467
468
469








470
471
472
473
474
475
476
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







+





-
+
+
+
+
+
+
+
+







  }
  timerflag=1;
  return n;
}

static inline void input_move(Uint8 k) {
  const char*t=execute_turn(k);
  if(replay_pos==65534 && !gameover) t="Too many moves played";
  if(t) {
    screen_message(t);
    gameover=-1;
    return;
  }
  //TODO: Record this move, if applicable
  if(!key_ignored) {
    if(replay_pos>=replay_size) {
      replay_list=realloc(replay_list,replay_size+=0x200);
      if(!replay_list) fatal("Allocation failed\n");
    }
    replay_list[replay_pos++]=k;
    if(replay_pos>replay_count) replay_count=replay_pos;
  }
}

void run_game(void) {
  int i;
  SDL_Event ev;
  set_caption();
  begin_level(level_id);

Modified heromesh.h from [ec8cb61a20] to [02acfa099d].

247
248
249
250
251
252
253



254
255
256
257
258
259
260
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263







+
+
+







void objtrash(Uint32 n);
void annihilate(void);
const char*execute_turn(int key);
const char*init_level(void);

// == game ==

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

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

// == edit ==

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