diff --git a/polymer/eduke32/build/include/m32script.h b/polymer/eduke32/build/include/m32script.h index 4a11c9829..046e69f82 100644 --- a/polymer/eduke32/build/include/m32script.h +++ b/polymer/eduke32/build/include/m32script.h @@ -95,6 +95,7 @@ enum GameEvent_t { EVENT_PREKEYS2D, EVENT_PREKEYS3D, EVENT_LINKTAGS, + EVENT_KEYPRESS, MAXEVENTS }; diff --git a/polymer/eduke32/build/src/build.c b/polymer/eduke32/build/src/build.c index 23332dd8f..b8d32af78 100644 --- a/polymer/eduke32/build/src/build.c +++ b/polymer/eduke32/build/src/build.c @@ -419,6 +419,12 @@ static void reset_default_mapstate(void) #endif } +static void m32_keypresscallback(int32_t code, int32_t downp) +{ + g_iReturnVar = code; + VM_OnEvent(EVENT_KEYPRESS, -1); +} + #undef STARTUP_SETUP_WINDOW #if defined RENDERTYPEWIN || (defined RENDERTYPESDL && !defined __APPLE__ && defined HAVE_GTK2) # define STARTUP_SETUP_WINDOW @@ -590,6 +596,8 @@ int32_t app_main(int32_t argc, const char **argv) updatesector(pos.x,pos.y,&cursectnum); + setkeypresscallback(&m32_keypresscallback); + if (cursectnum == -1) { vid_gamma_3d = vid_gamma; diff --git a/polymer/eduke32/samples/a.m32 b/polymer/eduke32/samples/a.m32 index f45dc9841..11acbc193 100644 --- a/polymer/eduke32/samples/a.m32 +++ b/polymer/eduke32/samples/a.m32 @@ -30,6 +30,9 @@ gamevar use_custom_aspect 0 0 // this is now the same as r_usenewaspect gamevar davr 65536 0 gamevar dayx 65536 0 +// whether to remap certain widely-available keys to rare ones +// (notebook/netbook convenience, see EVENT_KEYPRESS for details) +gamevar use_notebook_keys 0 0 // see end of file for more user settings and examples @@ -300,7 +303,7 @@ defstate fiddlewithlights getnumber256 .yvel "YVEL: " 0 getnumber256 .zvel "ZVEL: " 0 } - else ifhitkey KEY_KP2 + else ifeithershift ifhitkey KEY_KP2 // alt-kp2 collides with KP* replacement { getnumber256 .owner "OWNER: " 0 ifl .owner 0 set .owner -1 @@ -1202,6 +1205,66 @@ defstate userkeys_3d ifholdkey KEY_SEMI ifhitkey KEY_C state chselshade ends +// convenience rebindings for notebooks: +// Alt-F11 --> SCROLL LOCK (set first position) +// Alt-arrows --> KP arrows (change pan/repeat in 3D mode) +onevent EVENT_KEYPRESS + var thekey + set thekey RETURN + + ifvare use_notebook_keys 0, return +/* + ifholdkey thekey + qsprintf TQUOTE "pressed %d" thekey + else + qsprintf TQUOTE "released %d" thekey + print TQUOTE +*/ + ifholdkey thekey // if the callback key was pressed (and not released) + { + ifholdkey KEY_LALT + { + ifhitkey KEY_F11, setkey KEY_SCROLL + + ifhitkey KEY_UP, setkey KEY_KP8 + ifhitkey KEY_DOWN, setkey KEY_KP2 + ifhitkey KEY_LEFT, setkey KEY_KP4 + ifhitkey KEY_RIGHT, setkey KEY_KP6 + +// would be 'cleaner' (only checking cb key) but is too much code for my taste: +/* + switch (thekey) + { + case KEY_F11: setkey KEY_SCROLL; resetkey thekey; break; + + // and so on with the rest... + } + endswitch +*/ + } + } + else // cb key was released + { + switch (thekey) + { + case KEY_LALT: + { + resetkey KEY_KP8; + resetkey KEY_KP2; + resetkey KEY_KP4; + resetkey KEY_KP6; + break; + } + + case KEY_UP: resetkey KEY_KP8; break; + case KEY_DOWN: resetkey KEY_KP2; break; + case KEY_LEFT: resetkey KEY_KP4; break; + case KEY_RIGHT: resetkey KEY_KP6; break; + } + endswitch + } +endevent + /* // example for custom labels defstate userdrawlabel diff --git a/polymer/eduke32/source/m32def.c b/polymer/eduke32/source/m32def.c index 3c62a4914..7ad7c288f 100644 --- a/polymer/eduke32/source/m32def.c +++ b/polymer/eduke32/source/m32def.c @@ -304,6 +304,7 @@ const char *keyw[] = // BUILD functions "resetkey", + "setkey", "insertsprite", "dupsprite", "tdupsprite", @@ -1253,7 +1254,7 @@ static void C_GetNextVarType(int32_t type) id = GetGamevarID(tlabel, 1); if (id < 0) //gamevar not found { - if (!type && !cs.labelsOnly) + if (!(type&GV_WRITABLE) && !cs.labelsOnly) { //try looking for a define instead id = hash_find(&h_labels, tlabel); @@ -3053,6 +3054,7 @@ repeatcase: g_numCompilerWarnings++; } case CON_RESETKEY: + case CON_SETKEY: case CON_INSERTSPRITE: case CON_DUPSPRITE: case CON_DELETESPRITE: @@ -3503,6 +3505,7 @@ static void C_AddDefaultDefinitions(void) C_AddDefinition("EVENT_PREKEYS2D", EVENT_PREKEYS2D, LABEL_EVENT); C_AddDefinition("EVENT_PREKEYS3D", EVENT_PREKEYS3D, LABEL_EVENT); C_AddDefinition("EVENT_LINKTAGS", EVENT_LINKTAGS, LABEL_EVENT); + C_AddDefinition("EVENT_KEYPRESS", EVENT_KEYPRESS, LABEL_EVENT); C_AddDefinition("CLIPMASK0", CLIPMASK0, LABEL_DEFINE); C_AddDefinition("CLIPMASK1", CLIPMASK1, LABEL_DEFINE); @@ -3607,6 +3610,8 @@ static void C_AddDefaultDefinitions(void) C_AddDefinition("KEY_gSTAR", KEYSC_gSTAR, LABEL_DEFINE); C_AddDefinition("KEY_gUP", KEYSC_gUP, LABEL_DEFINE); + C_AddDefinition("KEY_SCROLL", KEYSC_SCROLL, LABEL_DEFINE); + C_AddDefinition("KEY_HOME", KEYSC_HOME, LABEL_DEFINE); C_AddDefinition("KEY_UP", KEYSC_UP, LABEL_DEFINE); C_AddDefinition("KEY_PGUP", KEYSC_PGUP, LABEL_DEFINE); @@ -3617,6 +3622,19 @@ static void C_AddDefaultDefinitions(void) C_AddDefinition("KEY_PGDN", KEYSC_PGDN, LABEL_DEFINE); C_AddDefinition("KEY_INSERT", KEYSC_INSERT, LABEL_DEFINE); C_AddDefinition("KEY_DELETE", KEYSC_DELETE, LABEL_DEFINE); + + C_AddDefinition("KEY_F1", KEYSC_F1, LABEL_DEFINE); + C_AddDefinition("KEY_F2", KEYSC_F2, LABEL_DEFINE); + C_AddDefinition("KEY_F3", KEYSC_F3, LABEL_DEFINE); + C_AddDefinition("KEY_F4", KEYSC_F4, LABEL_DEFINE); + C_AddDefinition("KEY_F5", KEYSC_F5, LABEL_DEFINE); + C_AddDefinition("KEY_F6", KEYSC_F6, LABEL_DEFINE); + C_AddDefinition("KEY_F7", KEYSC_F7, LABEL_DEFINE); + C_AddDefinition("KEY_F8", KEYSC_F8, LABEL_DEFINE); + C_AddDefinition("KEY_F9", KEYSC_F9, LABEL_DEFINE); + C_AddDefinition("KEY_F10", KEYSC_F10, LABEL_DEFINE); + C_AddDefinition("KEY_F11", KEYSC_F11, LABEL_DEFINE); + C_AddDefinition("KEY_F12", KEYSC_F12, LABEL_DEFINE); // end keys // C_AddDefinition("STR_MAPFILENAME",STR_MAPFILENAME, LABEL_DEFINE); diff --git a/polymer/eduke32/source/m32def.h b/polymer/eduke32/source/m32def.h index 33fa091d6..676716311 100644 --- a/polymer/eduke32/source/m32def.h +++ b/polymer/eduke32/source/m32def.h @@ -449,8 +449,11 @@ enum ScriptKeywords_t CON_IFAIMINGSECTOR, CON_IFINTERACTIVE, -// BUILD functions +// keyboard CON_RESETKEY, + CON_SETKEY, + +// BUILD functions CON_INSERTSPRITE, CON_DUPSPRITE, CON_TDUPSPRITE, diff --git a/polymer/eduke32/source/m32exec.c b/polymer/eduke32/source/m32exec.c index 0f9950165..402805f40 100644 --- a/polymer/eduke32/source/m32exec.c +++ b/polymer/eduke32/source/m32exec.c @@ -1496,6 +1496,7 @@ badindex: case CON_IFHITKEY: case CON_IFHOLDKEY: case CON_RESETKEY: + case CON_SETKEY: insptr++; { int32_t key=Gv_GetVarX(*insptr); @@ -1505,7 +1506,7 @@ badindex: continue; } - if (tw != CON_RESETKEY) + if (tw == CON_IFHITKEY || tw == CON_IFHOLDKEY) VM_DoConditional(keystatus[key]); else insptr++; @@ -1515,7 +1516,7 @@ badindex: if (!(key==0 || key==KEYSC_ESC || key==KEYSC_TILDE || key==KEYSC_gENTER || key==KEYSC_LALT || key==KEYSC_RALT || key==KEYSC_LCTRL || key==KEYSC_RCTRL || key==KEYSC_LSHIFT || key==KEYSC_RSHIFT)) - keystatus[key] = 0; + keystatus[key] = (tw==CON_SETKEY); } } continue;