Free Hero Mesh

Diff
Login
This is a mirror of the main repository for Free Hero Mesh. New tickets and changes will not be accepted at this mirror.

Differences From Artifact [d0dfda7e81]:

To Artifact [2c811f4938]:


16
17
18
19
20
21
22


23
24
25
26
27
28
29
#include "heromesh.h"
#include "quarks.h"
#include "cursorshapes.h"
#include "names.h"

static volatile Uint8 timerflag;
static int exam_scroll;



static void redraw_game(void) {
  char buf[32];
  SDL_Rect r;
  int x,y;
  r.x=r.y=0;
  r.h=screen->h;







>
>







16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include "heromesh.h"
#include "quarks.h"
#include "cursorshapes.h"
#include "names.h"

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];
  SDL_Rect r;
  int x,y;
  r.x=r.y=0;
  r.h=screen->h;
134
135
136
137
138
139
140



141
142
143
144
145
146
147
  draw_text(0,40,buf,0xF0,0xF1);
  SDL_UnlockSurface(screen);
  SDL_Flip(screen);
}

static void begin_level(int id) {
  const char*t;



  t=load_level(id)?:init_level();
  if(t) {
    gameover=-1;
    screen_message(t);
  } else {
    gameover=0;
  }







>
>
>







136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
  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;
  t=load_level(id)?:init_level();
  if(t) {
    gameover=-1;
    screen_message(t);
  } else {
    gameover=0;
  }
380
381
382
383
384
385
386





387
388
389
390
391
392
393
394
    }
  }
}

static int game_command(int prev,int cmd,int number,int argc,sqlite3_stmt*args,void*aux) {
  switch(cmd) {
    case '\' ': // Play a move





      return number;
    case '^E': // Edit
      return -2;
    case '^Q': // Quit
      return -1;
    case '^o': // List objects
      list_objects_at(number-65);
      return prev;







>
>
>
>
>
|







385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
    }
  }
}

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 '^E': // Edit
      return -2;
    case '^Q': // Quit
      return -1;
    case '^o': // List objects
      list_objects_at(number-65);
      return prev;
423
424
425
426
427
428
429










430
431
432
433
434
435
436
  if(!timerflag) {
    static SDL_Event ev={SDL_USEREVENT};
    SDL_PushEvent(&ev);
  }
  timerflag=1;
  return n;
}











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







>
>
>
>
>
>
>
>
>
>







433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
  if(!timerflag) {
    static SDL_Event ev={SDL_USEREVENT};
    SDL_PushEvent(&ev);
  }
  timerflag=1;
  return n;
}

static inline void input_move(Uint8 k) {
  const char*t=execute_turn(k);
  if(t) {
    screen_message(t);
    gameover=-1;
    return;
  }
  //TODO: Record this move, if applicable
}

void run_game(void) {
  int i;
  SDL_Event ev;
  set_caption();
  begin_level(level_id);
  redraw_game();
464
465
466
467
468
469
470





471
472
473
474
475
476
      command:
        if(i==-1) exit(0);
        if(i==-2) {
          main_options['e']=1;
          SDL_SetTimer(0,0);
          return;
        }





        redraw_game();
        timerflag=0;
        break;
    }
  }
}







>
>
>
>
>

|




484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
      command:
        if(i==-1) exit(0);
        if(i==-2) {
          main_options['e']=1;
          SDL_SetTimer(0,0);
          return;
        }
        if(inputs_count) {
          //TODO: Check for solution replay
          for(i=0;i<inputs_count && !gameover;i++) input_move(inputs[i]);
          inputs_count=0;
        }
        redraw_game();
        timerflag=0; // ensure we have not missed a timer event
        break;
    }
  }
}