Free Hero Mesh

Check-in [4d0fdefe0c]
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:Begin implementing the editor; also start to implement execution of key binding commands
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 4d0fdefe0caeef412d83017eaaab8025f5fa87ac
User & Date: user on 2018-10-20 18:09:19
Other Links: manifest | tags
Context
2018-10-22
05:41
More stuff in editor and key binding check-in: 02cc36cf71 user: user tags: trunk
2018-10-20
18:09
Begin implementing the editor; also start to implement execution of key binding commands check-in: 4d0fdefe0c user: user tags: trunk
2018-10-07
04:25
Make some improvements to compile script, and start edit.c (just a stub so far) check-in: 3f12058d2d user: user tags: trunk
Changes

Modified bindings.c from [faaaf44809] to [d28603a681].

1
2
3
4
5
6
7
8
9
#if 0
gcc ${CFLAGS:--s -O2} -c -Wno-unused-result bindings.c `sdl-config --cflags`
exit
#endif

/*
  This program is part of Free Hero Mesh and is public domain.
*/


|







1
2
3
4
5
6
7
8
9
#if 0
gcc ${CFLAGS:--s -O2} -c -Wno-multichar bindings.c `sdl-config --cflags`
exit
#endif

/*
  This program is part of Free Hero Mesh and is public domain.
*/

153
154
155
156
157
158
159


























  if(m&KMOD_SHIFT) i|=MOD_SHIFT;
  if(m&KMOD_ALT) i|=MOD_ALT;
  if(m&KMOD_META) i|=MOD_META;
  if((m&KMOD_NUM) && kb->m[i|MOD_NUMLOCK].cmd) i|=MOD_NUMLOCK;
  return kb->m+i;
}


































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
  if(m&KMOD_SHIFT) i|=MOD_SHIFT;
  if(m&KMOD_ALT) i|=MOD_ALT;
  if(m&KMOD_META) i|=MOD_META;
  if((m&KMOD_NUM) && kb->m[i|MOD_NUMLOCK].cmd) i|=MOD_NUMLOCK;
  return kb->m+i;
}

int exec_key_binding(SDL_Event*ev,int editing,int x,int y,int(*cb)(int prev,int cmd,int number,int argc,sqlite3_stmt*args,void*aux),void*aux) {
  const UserCommand*cmd=find_key_binding(ev,editing);
  int prev=0;
  int i;
  switch(cmd->cmd) {
    case 0:
      return 0;
    case '^':
      return cb(0,cmd->n*'\0\1'+'^\0',0,0,0,aux);
    case '=': case '-': case '+':
      return cb(0,cmd->cmd*'\1\0'+'\0 ',cmd->n,0,0,aux);
    case '\'':
      return cb(0,'\' ',cmd->n,0,0,aux);
    case '!':
      system(cmd->txt);
      return 0;
    case 's':
      sqlite3_reset(cmd->stmt);
      sqlite3_clear_bindings(cmd->stmt);
      
      break;
    default:
      fprintf(stderr,"Confusion in exec_key_binding()\n");
      return 0;
  }
}

Modified edit.c from [240eb74098] to [574b134f31].

1
2
3
4
5
6
7
8
9
10
11
12

13




































14



15










16
#if 0
gcc ${CFLAGS:--s -O2} -c edit.c `sdl-config --cflags`
exit
#endif

#include "SDL.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "sqlite3.h"
#include "smallxrm.h"
#include "heromesh.h"






































void run_editor(void) {



  fatal("[Editor not implemented yet]\n"); // so far just a stub










}












>

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

>
>
>
|
>
>
>
>
>
>
>
>
>
>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#if 0
gcc ${CFLAGS:--s -O2} -c edit.c `sdl-config --cflags`
exit
#endif

#include "SDL.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "sqlite3.h"
#include "smallxrm.h"
#include "heromesh.h"
#include "quarks.h"

static void redraw_editor(void) {
  SDL_Rect r;
  int x,y;
  r.x=r.y=0;
  r.h=screen->h;
  r.w=left_margin;
  SDL_FillRect(screen,&r,0xF0);
  r.x=left_margin-1;
  r.w=1;
  SDL_FillRect(screen,&r,0xF7);
  r.x=left_margin;
  r.w=screen->w-r.x;
  SDL_FillRect(screen,&r,back_color);
  for(x=1;x<=pfwidth;x++) for(y=1;y<=pfheight;y++) draw_cell(x,y);
  SDL_Flip(screen);
}

static void set_caption(void) {
  const char*r;
  char*s;
  sqlite3_str*m;
  int c;
  optionquery[1]=Q_editTitle;
  r=xrm_get_resource(resourcedb,optionquery,optionquery,2)?:"Free Hero Mesh - ~ - Edit";
  m=sqlite3_str_new(0);
  c=strcspn(r,"~");
  sqlite3_str_append(m,r,c);
  if(r[c]=='~') {
    sqlite3_str_appendall(m,basefilename);
    sqlite3_str_appendall(m,r+c+1);
  }
  s=sqlite3_str_finish(m);
  if(s) SDL_WM_SetCaption(s,s); else SDL_WM_SetCaption("Free Hero Mesh","Free Hero Mesh");
  sqlite3_free(s);
}

void run_editor(void) {
  SDL_Event ev;
  set_caption();
  load_level(level_id);
  redraw_editor();
  while(SDL_WaitEvent(&ev)) {
    switch(ev.type) {
      case SDL_VIDEOEXPOSE:
        redraw_editor();
        break;
      case SDL_QUIT:
        exit(0);
        break;
    }
  }
}

Modified picture.c from [cbe344cbd2] to [51eec2ef53].

93
94
95
96
97
98
99
100
101
102
103
104

105
106
107
108
109
110
111
void draw_cell(int x,int y) {
  // To be called only when screen is unlocked!
  Uint32 o;
  Class*c;
  SDL_Rect dst={x,y,picture_size,picture_size};
  if(x<1 || x>64 || y<1 || y>64) return;
  SDL_FillRect(screen,&dst,back_color);
  o=playfield[y*64+x+65];
  while(o!=VOIDLINK) {
    if(!(objects[o]->oflags&OF_INVISIBLE)) {
      c=classes[objects[o]->class];
      if(objects[o]->image<c->nimages) draw_picture(x*picture_size+left_margin,y*picture_size,c->images[objects[o]->image]&0x7FFF);

    }
    o=objects[o]->up;
  }
}

void draw_text(int x,int y,const unsigned char*t,int bg,int fg) {
  // To be called only when screen is locked!







|



|
>







93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
void draw_cell(int x,int y) {
  // To be called only when screen is unlocked!
  Uint32 o;
  Class*c;
  SDL_Rect dst={x,y,picture_size,picture_size};
  if(x<1 || x>64 || y<1 || y>64) return;
  SDL_FillRect(screen,&dst,back_color);
  o=playfield[y*64+x-65];
  while(o!=VOIDLINK) {
    if(!(objects[o]->oflags&OF_INVISIBLE)) {
      c=classes[objects[o]->class];
      if(objects[o]->image<c->nimages)
       draw_picture((x-1)*picture_size+left_margin,(y-1)*picture_size,c->images[objects[o]->image]&0x7FFF);
    }
    o=objects[o]->up;
  }
}

void draw_text(int x,int y,const unsigned char*t,int bg,int fg) {
  // To be called only when screen is locked!