168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
|
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
|
s=malloc(256);
if(!s) fatal("Allocation failed\n");
if(fscanf(fp," %255s",s)!=1) fatal("Unable to scan name of class set\n");
globalclassname=s;
return !*s;
}
static void set_key_binding(KeyBinding**pkb,int mod,const char*txt) {
int i;
KeyBinding*kb=*pkb;
UserCommand*uc;
if(!*txt) return;
if(!kb) kb=*pkb=calloc(1,sizeof(KeyBinding));
uc=kb->m+mod;
switch(*txt) {
case '^': // Miscellaneous
uc->cmd='^';
uc->n=txt[1];
break;
case '=': case '-': case '+': // Restart, rewind, advance
uc->cmd=*txt;
uc->n=strtol(txt+1,0,0);
break;
case '\'': // Input move
uc->cmd='\'';
for(i=1;i<256;i++) if(heromesh_key_names[i] && !strcmp(txt+1,heromesh_key_names[i])) {
uc->n=i;
return;
}
fatal("Error in key binding: %s\nInvalid Hero Mesh key name\n",txt);
break;
case '!': // System command
uc->cmd='!';
uc->txt=txt+1;
break;
case 'A' ... 'Z': case 'a' ... 'z': // Execute SQL statement
uc->cmd='s';
if(i=sqlite3_prepare_v3(userdb,txt+1,-1,SQLITE_PREPARE_PERSISTENT,&uc->stmt,0)) fatal("Error in key binding: %s\n%s\n",txt,sqlite3_errmsg(userdb));
break;
default:
fatal("Error in key binding: %s\nUnrecognized character\n",txt);
}
}
#define SetKeyBinding(n,m) do { \
optionquery[1]=Q_editKey; \
if(s=xrm_get_resource(resourcedb,optionquery,optionquery,n)) set_key_binding(editor_bindings+quark_to_key[q-FirstKeyQuark],m,s); \
optionquery[1]=Q_gameKey; \
if(s=xrm_get_resource(resourcedb,optionquery,optionquery,n)) set_key_binding(game_bindings+quark_to_key[q-FirstKeyQuark],m,s); \
} while(0)
#define SetMouseBinding(o,n,m) do { \
optionquery[1]=Q_editClick; \
if(s=xrm_get_resource(resourcedb,optionquery,optionquery,n)) set_key_binding(editor_mouse_bindings+o,m,s); \
optionquery[1]=Q_gameClick; \
if(s=xrm_get_resource(resourcedb,optionquery,optionquery,n)) set_key_binding(game_mouse_bindings+o,m,s); \
} while(0)
static void load_key_bindings(void) {
xrm_quark q;
const char*s;
for(q=FirstKeyQuark;q<=LastKeyQuark;q++) {
optionquery[2]=optionquery[3]=optionquery[4]=q;
SetKeyBinding(3,0);
optionquery[2]=Q_shift;
SetKeyBinding(4,MOD_SHIFT);
optionquery[2]=Q_ctrl;
SetKeyBinding(4,MOD_CTRL);
optionquery[2]=Q_alt;
SetKeyBinding(4,MOD_ALT);
optionquery[2]=Q_meta;
SetKeyBinding(4,MOD_META);
optionquery[2]=Q_numLock;
SetKeyBinding(4,MOD_NUMLOCK);
optionquery[3]=Q_shift;
SetKeyBinding(5,MOD_NUMLOCK|MOD_SHIFT);
#if 0
optionquery[2]=Q_alt;
SetKeyBinding(5,MOD_ALT|MOD_SHIFT);
optionquery[2]=Q_ctrl;
SetKeyBinding(5,MOD_CTRL|MOD_SHIFT);
optionquery[2]=Q_meta;
SetKeyBinding(5,MOD_META|MOD_SHIFT);
#endif
}
optionquery[2]=optionquery[3]=Q_left;
SetMouseBinding(SDL_BUTTON_LEFT,3,0);
optionquery[2]=Q_shift;
SetMouseBinding(SDL_BUTTON_LEFT,4,MOD_SHIFT);
optionquery[2]=Q_ctrl;
SetMouseBinding(SDL_BUTTON_LEFT,4,MOD_CTRL);
optionquery[2]=Q_alt;
SetMouseBinding(SDL_BUTTON_LEFT,4,MOD_ALT);
optionquery[2]=Q_meta;
SetMouseBinding(SDL_BUTTON_LEFT,4,MOD_META);
optionquery[2]=optionquery[3]=Q_middle;
SetMouseBinding(SDL_BUTTON_MIDDLE,3,0);
optionquery[2]=Q_shift;
SetMouseBinding(SDL_BUTTON_MIDDLE,4,MOD_SHIFT);
optionquery[2]=Q_ctrl;
SetMouseBinding(SDL_BUTTON_MIDDLE,4,MOD_CTRL);
optionquery[2]=Q_alt;
SetMouseBinding(SDL_BUTTON_MIDDLE,4,MOD_ALT);
optionquery[2]=Q_meta;
SetMouseBinding(SDL_BUTTON_MIDDLE,4,MOD_META);
optionquery[2]=optionquery[3]=Q_right;
SetMouseBinding(SDL_BUTTON_RIGHT,3,0);
optionquery[2]=Q_shift;
SetMouseBinding(SDL_BUTTON_RIGHT,4,MOD_SHIFT);
optionquery[2]=Q_ctrl;
SetMouseBinding(SDL_BUTTON_RIGHT,4,MOD_CTRL);
optionquery[2]=Q_alt;
SetMouseBinding(SDL_BUTTON_RIGHT,4,MOD_ALT);
optionquery[2]=Q_meta;
SetMouseBinding(SDL_BUTTON_RIGHT,4,MOD_META);
}
static int test_sql_callback(void*usr,int argc,char**argv,char**name) {
int i;
if(argc) printf("%s",*argv);
for(i=1;i<argc;i++) printf("|%s",argv[i]);
putchar('\n');
return 0;
}
static void test_mode(void) {
Uint32 n=0;
SDLKey k;
SDL_Event ev;
char buf[32];
const UserCommand*uc;
set_cursor(XC_tcross);
SDL_LockSurface(screen);
draw_text(0,0,"Hello, World!",0xF0,0xFF);
SDL_UnlockSurface(screen);
SDL_Flip(screen);
while(SDL_WaitEvent(&ev)) switch(ev.type) {
case SDL_KEYDOWN:
|
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
|
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
|
snprintf(buf,30,"%u",n);
SDL_WM_SetCaption(buf,buf);
break;
case SDLK_c:
SDL_FillRect(screen,0,n);
SDL_Flip(screen);
break;
case SDLK_e:
n=1;
goto keytest;
case SDLK_g:
n=0;
goto keytest;
case SDLK_p:
sqlite3_exec(userdb,"SELECT * FROM `PICTURES`;",test_sql_callback,0,0);
break;
case SDLK_q:
exit(0);
break;
}
break;
case SDL_MOUSEBUTTONDOWN:
draw_picture(ev.button.x,ev.button.y,n);
SDL_Flip(screen);
break;
case SDL_QUIT:
exit(0);
break;
}
fatal("An error occurred waiting for events.\n");
keytest:
SDL_FillRect(screen,0,0xF0);
SDL_LockSurface(screen);
draw_text(1,5,n?"Edit Key":"Game Key",0xF1,0xF7);
SDL_UnlockSurface(screen);
SDL_EnableUNICODE(1);
SDL_Flip(screen);
set_cursor(XC_arrow);
while(SDL_WaitEvent(&ev)) switch(ev.type) {
case SDL_KEYDOWN:
printf("[%d %d %d %d] ",ev.key.keysym.scancode,ev.key.keysym.sym,ev.key.keysym.mod,ev.key.keysym.unicode);
goto bindingtest;
case SDL_MOUSEBUTTONDOWN:
printf("[%d %d %d] ",ev.button.x,ev.button.y,ev.button.button);
bindingtest:
uc=find_key_binding(&ev,n);
switch(uc->cmd) {
case 0: printf("<Unbound>\n"); break;
case '^': printf("<Misc> %c\n",uc->n); break;
case '=': printf("<Reset> %d\n",uc->n); break;
case '-': printf("<Rewind> %d\n",uc->n); break;
case '+': printf("<Advance> %d\n",uc->n); break;
case '\'': printf("<Play> %s (%d)\n",heromesh_key_names[uc->n],uc->n); break;
case '!': printf("<System> %s",uc->txt); break;
case 's': printf("<SQL> %s",sqlite3_sql(uc->stmt)); break;
default: printf("<Unknown>\n");
}
}
break;
case SDL_QUIT:
exit(0);
break;
}
}
int main(int argc,char**argv) {
int optind=1;
fprintf(stderr,"FREE HERO MESH\n");
while(argc>optind && argv[optind][0]=='-') {
int i;
const char*s=argv[optind++];
if(s[1]=='-' && !s[2]) break;
for(i=1;s[i];i++) main_options[s[i]&127]=1;
}
if(argc<=optind) fatal("usage: %s [switches] [--] basename [options...]\n",argc?argv[0]:"heromesh");
|