Skip to content

Commit

Permalink
Merge pull request #171 from curiousdannii/cumulative
Browse files Browse the repository at this point in the history
More cumulative Glk updates
  • Loading branch information
ganelson authored Nov 17, 2024
2 parents f92a964 + a3cd3ed commit 873327a
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Cannot handle new event while not handling events

The `handle (event)` phrase was used, but Glk events aren't being handled at all right now. This phrase can only be used in `glk event handling` rules, or in rulebooks that are themselves run in `glk event handling` rules.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Glk mouse event created with invalid coordinates

Glk mouse events must be created with valid coordinates. Note in particular that graphics windows are 0-based (meaning the top left is (0, 0)), while grid windows are 1-based (meaning the top left is (1, 1)).
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,10 @@ Global current_glk_object_reference = 0;
statuswin_cursize = 0;
gg_foregroundchan = 0;
gg_backgroundchan = 0;
#Ifdef COMMAND_STREAM;
gg_commandstr = 0;
gg_command_reading = false;
#Endif;
rfalse;
];

Expand Down Expand Up @@ -134,13 +136,17 @@ Global current_glk_object_reference = 0;
gg_savestr = current_glk_object_reference;
GG_SCRIPTSTR_ROCK:
gg_scriptstr = current_glk_object_reference;
}
#Ifdef COMMAND_STREAM;
switch (current_glk_object_rock) {
GG_COMMANDWSTR_ROCK:
gg_commandstr = current_glk_object_reference;
gg_command_reading = false;
GG_COMMANDRSTR_ROCK:
gg_commandstr = current_glk_object_reference;
gg_command_reading = true;
}
#Endif;
rfalse;
];

Expand Down Expand Up @@ -367,8 +373,12 @@ event BVs.
}
! Fix the coordinates of grid window mouse events
if (win_obj.glk_window_type == wintype_TextGrid) {
val1 = val1--;
val2 = val2--;
val1--;
val2--;
}
if (val1 < 0 || val2 < 0) {
IssueRTP("EventInvalidMouseCoords", "GLK_EVENT_TY_New: Glk mouse event created with invalid coordinates.", Architecture32KitRTPs);
return ev;
}
}
ev-->GLK_EVENT_TYPE_SF = evtype;
Expand All @@ -394,17 +404,19 @@ event BVs.
return nothing;
];

[ GLK_EVENT_TY_Value1 ev;
switch (ev-->GLK_EVENT_TYPE_SF) {
evtype_CharInput:
return MapGlkKeyCodeToUnicode(ev-->GLK_EVENT_VALUE1_SF);
evtype_MouseInput:
if ((ev-->GLK_EVENT_WINDOW_SF).glk_window_type == wintype_TextGrid) {
return ev-->GLK_EVENT_VALUE1_SF + 1;
}
return ev-->GLK_EVENT_VALUE1_SF;
evtype_Hyperlink:
return ev-->GLK_EVENT_VALUE1_SF;
[ GLK_EVENT_TY_Value1 ev evtype;
if (evtype == ev-->GLK_EVENT_TYPE_SF) {
switch (evtype) {
evtype_CharInput:
return MapGlkKeyCodeToUnicode(ev-->GLK_EVENT_VALUE1_SF);
evtype_MouseInput:
if ((ev-->GLK_EVENT_WINDOW_SF).glk_window_type == wintype_TextGrid) {
return ev-->GLK_EVENT_VALUE1_SF + 1;
}
return ev-->GLK_EVENT_VALUE1_SF;
evtype_Hyperlink:
return ev-->GLK_EVENT_VALUE1_SF;
}
}
IssueRTP("EventWrongType", "GLK_EVENT_TY_Value1: Glk event phrase called for wrong event type.", Architecture32KitRTPs);
return 0;
Expand Down Expand Up @@ -488,16 +500,26 @@ the event struct.
event_struct-->3 = ev-->GLK_EVENT_VALUE2_SF;
];

@ |GLK_EVENT_TY_Process| applies a glk event onto the current glk event, and
@ |GLK_EVENT_TY_Handle_Instead| applies a glk event onto the current glk event, and
tells glk_select to re-run the glk event handling rules. It also ensures that
if there are any pending keyboard input requests they will be cancelled if the
new event is a keyboard event.

=
Array current_glk_event --> [ BLK_BVBITMAP_SBONLY; GLK_EVENT_TY; 0; 0; 0; 0; 0; 0; 0; ];
Global glk_event_replaced;

[ GLK_EVENT_TY_Process ev evtype win_obj;
Constant GLK_EVENT_HANDLING_INACTIVE 0;
Constant GLK_EVENT_HANDLING_ACTIVE 1;
Constant GLK_EVENT_HANDLING_REHANDLING 2;
Global glk_event_handling_status = GLK_EVENT_HANDLING_INACTIVE;

[ GLK_EVENT_TY_Handle_Instead ev evtype win_obj;
if (glk_event_handling_status == GLK_EVENT_HANDLING_INACTIVE) {
IssueRTP("EventHandledWhileInactive", "Cannot handle new event while not handling events.", Architecture32KitRTPs);
RulebookSucceeds();
rtrue;
}

evtype = ev-->GLK_EVENT_TYPE_SF;
win_obj = ev-->GLK_EVENT_WINDOW_SF;

Expand Down Expand Up @@ -528,7 +550,7 @@ Global glk_event_replaced;
current_glk_event-->GLK_EVENT_VALUE2_SF = ev-->GLK_EVENT_VALUE2_SF;

RulebookSucceeds();
glk_event_replaced = 1;
glk_event_handling_status = GLK_EVENT_HANDLING_REHANDLING;
];

@ To handle events we intercept the |glk_select| function. This allows us to handle
Expand All @@ -546,9 +568,10 @@ events early and consistently.
@push debug_rules; @push say__p; @push say__pc;
debug_rules = false; ClearParagraphing(1);
do {
glk_event_replaced = 0;
glk_event_handling_status = GLK_EVENT_HANDLING_ACTIVE;
FollowRulebook(GLK_EVENT_HANDLING_RB, current_glk_event-->GLK_EVENT_TYPE_SF, true);
} until (glk_event_replaced == 0);
} until (glk_event_handling_status == GLK_EVENT_HANDLING_ACTIVE);
glk_event_handling_status = GLK_EVENT_HANDLING_INACTIVE;
@pull say__pc; @pull say__p; @pull debug_rules;

GLK_EVENT_TY_To_Struct(current_glk_event, event_struct);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ Constant GG_STATUSWIN_ROCK 202;
Constant GG_QUOTEWIN_ROCK 203;
Constant GG_SAVESTR_ROCK 301;
Constant GG_SCRIPTSTR_ROCK 302;
#Ifdef COMMAND_STREAM;
Constant GG_COMMANDWSTR_ROCK 303;
Constant GG_COMMANDRSTR_ROCK 304;
#Endif;
Constant GG_SCRIPTFREF_ROCK 401;
Constant GG_FOREGROUNDCHAN_ROCK 410;
Constant GG_BACKGROUNDCHAN_ROCK 411;
Expand Down Expand Up @@ -137,8 +139,10 @@ Global gg_mainwin = 0;
Global gg_statuswin = 0;
Global gg_quotewin = 0;
Global gg_savestr = 0;
#Ifdef COMMAND_STREAM;
Global gg_commandstr = 0;
Global gg_command_reading = 0; ! true if gg_commandstr is being replayed
#Endif;
Global gg_foregroundchan = 0;
Global gg_backgroundchan = 0;

Expand Down Expand Up @@ -180,6 +184,7 @@ to document all of that.
[ VM_KeyChar win done res ix jx ch;
jx = ch; ! squash compiler warnings
if (win == 0) win = gg_mainwin;
#Ifdef COMMAND_STREAM;
if (gg_commandstr ~= 0 && gg_command_reading ~= false) {
done = glk_get_line_stream(gg_commandstr, gg_arguments, 31);
if (done == 0) {
Expand Down Expand Up @@ -210,6 +215,7 @@ to document all of that.
jump KCPContinue;
}
}
#Endif;
done = false;
glk_request_char_event(win);
while (~~done) {
Expand All @@ -222,6 +228,7 @@ to document all of that.
}
}
}
#Ifdef COMMAND_STREAM;
if (gg_commandstr ~= 0 && gg_command_reading == false) {
if (res < 32 || res >= 256 || (res == '\' or ' ')) {
glk_put_char_stream(gg_commandstr, '\');
Expand All @@ -244,6 +251,7 @@ to document all of that.
glk_put_char_stream(gg_commandstr, 10); ! newline
}
.KCPContinue;
#Endif;
return MapGlkKeyCodeToUnicode(res);
];

Expand All @@ -266,6 +274,7 @@ Array UnicodeWhitespace --> 133 160 5760 8232 8233 8239 8287 12288;
Constant UnicodeWhitespaceLen = 8;

[ VM_ReadKeyboard a_buffer a_table done ix chr;
#Ifdef COMMAND_STREAM;
if (gg_commandstr ~= 0 && gg_command_reading ~= false) {
done = glk_get_line_stream_uni(gg_commandstr, a_buffer+WORDSIZE,
(INPUT_BUFFER_LEN-1)-1);
Expand All @@ -284,6 +293,7 @@ Constant UnicodeWhitespaceLen = 8;
jump KPContinue;
}
}
#Endif;
done = false;
glk_request_line_event_uni(gg_mainwin, a_buffer+WORDSIZE, INPUT_BUFFER_LEN-1, 0);
while (~~done) {
Expand All @@ -303,11 +313,13 @@ Constant UnicodeWhitespaceLen = 8;
glk_set_style(style_Normal);
glk_put_char(10); ! newline
}
#Ifdef COMMAND_STREAM;
if (gg_commandstr ~= 0 && gg_command_reading == false) {
glk_put_buffer_stream(gg_commandstr, a_buffer+WORDSIZE, a_buffer-->0);
glk_put_char_stream(gg_commandstr, 10); ! newline
}
.KPContinue;
#Endif;

for ( ix = 1 : ix <= (a_buffer-->0) : ix++ ) {
chr = a_buffer-->ix;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1818,19 +1818,19 @@ To decide what glk window is window of (ev - glk event)

To decide what unicode character is the character value of (ev - glk event)
(documented at ph_glkeventcharactervalue):
(- GLK_EVENT_TY_Value1({ev}) -).
(- GLK_EVENT_TY_Value1({ev}, evtype_CharInput) -).

To decide what number is the x coordinate of (ev - glk event):
(- GLK_EVENT_TY_Value1({ev}) -).
(- GLK_EVENT_TY_Value1({ev}, evtype_MouseInput) -).
To decide what number is the y coordinate of (ev - glk event):
(- GLK_EVENT_TY_Value2({ev}) -).
To decide what number is the row of (ev - glk event):
(- GLK_EVENT_TY_Value2({ev}) -).
To decide what number is the column of (ev - glk event):
(- GLK_EVENT_TY_Value1({ev}) -).
To decide what number is the column/col of (ev - glk event):
(- GLK_EVENT_TY_Value1({ev}, evtype_MouseInput) -).

To decide what number is the hyperlink value of (ev - glk event):
(- GLK_EVENT_TY_Value1({ev}) -).
(- GLK_EVENT_TY_Value1({ev}, evtype_Hyperlink) -).

To decide what text is the text of (ev - glk event)
(documented at ph_glkeventtextvalue):
Expand All @@ -1848,8 +1848,8 @@ First glk event handling rule for a glk event type
(this is the set glk event processing variables rule):
now the event is the current glk event initialiser.

To process (ev - glk event):
(- GLK_EVENT_TY_Process({ev}); rtrue; -).
To handle (ev - glk event):
(- GLK_EVENT_TY_Handle_Instead({ev}); rtrue; -).

Glk event handling rule for a screen resize event (this is the redraw the status line rule):
redraw the status window;
Expand Down
14 changes: 7 additions & 7 deletions inform7/extensions/basic_inform/Sections/Glulx and Glk.w
Original file line number Diff line number Diff line change
Expand Up @@ -156,19 +156,19 @@ To decide what glk window is window of (ev - glk event)

To decide what unicode character is the character value of (ev - glk event)
(documented at ph_glkeventcharactervalue):
(- GLK_EVENT_TY_Value1({ev}) -).
(- GLK_EVENT_TY_Value1({ev}, evtype_CharInput) -).

To decide what number is the x coordinate of (ev - glk event):
(- GLK_EVENT_TY_Value1({ev}) -).
(- GLK_EVENT_TY_Value1({ev}, evtype_MouseInput) -).
To decide what number is the y coordinate of (ev - glk event):
(- GLK_EVENT_TY_Value2({ev}) -).
To decide what number is the row of (ev - glk event):
(- GLK_EVENT_TY_Value2({ev}) -).
To decide what number is the column of (ev - glk event):
(- GLK_EVENT_TY_Value1({ev}) -).
To decide what number is the column/col of (ev - glk event):
(- GLK_EVENT_TY_Value1({ev}, evtype_MouseInput) -).

To decide what number is the hyperlink value of (ev - glk event):
(- GLK_EVENT_TY_Value1({ev}) -).
(- GLK_EVENT_TY_Value1({ev}, evtype_Hyperlink) -).

To decide what text is the text of (ev - glk event)
(documented at ph_glkeventtextvalue):
Expand All @@ -189,8 +189,8 @@ First glk event handling rule for a glk event type
(this is the set glk event processing variables rule):
now the event is the current glk event initialiser.

To process (ev - glk event):
(- GLK_EVENT_TY_Process({ev}); rtrue; -).
To handle (ev - glk event):
(- GLK_EVENT_TY_Handle_Instead({ev}); rtrue; -).

Glk event handling rule for a screen resize event (this is the redraw the status line rule):
redraw the status window;
Expand Down

0 comments on commit 873327a

Please sign in to comment.