Skip to content

Commit

Permalink
Initial work to update CM for the new SGW
Browse files Browse the repository at this point in the history
  • Loading branch information
curiousdannii committed Oct 3, 2016
1 parent 6f0f478 commit a390bad
Show file tree
Hide file tree
Showing 9 changed files with 2,107 additions and 352 deletions.
3 changes: 1 addition & 2 deletions Counterfeit Monkey.inform/Source/story.ni
Expand Up @@ -75,7 +75,7 @@ Include version 1/160501 of Ultra Undo by Dannii Willis.
The release number is 6.

Use scoring.
Use no deprecated features.
[Use no deprecated features.]

Include Scope Caching by Mike Ciul.
Include Large Game Speedup by Andrew Plotkin.
Expand All @@ -85,7 +85,6 @@ Include Subcommands by Daniel Stelzer.
Include version 1/160718 of Startup Precomputation by Dannii Willis.
The finalise startup precomputation rule is listed last in the when play begins rules.
The initial conversation rule is listed after the finalise startup precomputation rule in the when play begins rules.
The graphics window construction rule is listed after the finalise startup precomputation rule in the when play begins rules.

Last after starting the virtual machine rule (this is the apologise for a slow start rule):
say "Counterfeit Monkey is starting. This may take a short moment.";
Expand Down
Expand Up @@ -199,27 +199,32 @@ To decide what figure-name is the visited image of (way - a direction):

A direction has a number called x-coordinate. A direction has a number called y-coordinate.

Include Simple Graphical Window by Emily Short. The graphics window proportion is 50. The graphics window position is g-left.
Include version 10 of Simple Graphical Window by Emily Short.
The measurement of the graphics window is 50.
The position of the graphics window is g-placeleft.

The graphics window construction rule is not listed in any rulebook.

The compass width is a number that varies. The compass width is 120.

Include Graphic Links by Jeff Sheets.

The setting directional hyperlinks rule is listed after the graphics window construction rule in the when play begins rules.
[The setting directional hyperlinks rule is listed after the graphics window construction rule in the when play begins rules.
When play begins (this is the setting directional hyperlinks rule):
follow the compass-drawing rule.
follow the compass-drawing rule.]

To establish compass graphlinks:
let ZE be grid-margin;
let D be grid-size;
let DD be 2 * D;
let DDD be compass width;
let top-edge be current graphics window height - (D * 4);
let graphics window height be the height of the graphics window;
let top-edge be graphics window height - (D * 4);
let upper-mid be top-edge + D;
let lower-mid be top-edge + DD;
let bottom-edge be current graphics window height - D;
let super-top be current graphics window height - (D * 5);
let true-bottom be current graphics window height;
let bottom-edge be graphics window height - D;
let super-top be graphics window height - (D * 5);
let true-bottom be graphics window height;
increase D by grid-margin;
increase DD by grid-margin;
increase DDD by grid-margin;
Expand Down Expand Up @@ -286,8 +291,8 @@ After someone going somewhere when the actor encloses the player:
[We want the compass to stay down in a corner of the screen and not to scale up too huge if the screen is resized. One of the irritating things about Glulx window management is that it's impossible to force an aspect ratio on the player, so I have no idea whether they're going to go tall-and-skinny or short-and-wide. Testers playing in full-screen mode sometimes found that the compass got way too large and encroached on the upper part of the map if I just set the compass to be one quarter the width of the window.]

To decide what number is grid-size:
let width-quarter be (current graphics window width / 4);
let height-quarter be (current graphics window height / 4);
let width-quarter be (the width of the graphics window / 4);
let height-quarter be (the height of the graphics window / 4);
if width-quarter is greater than height-quarter:
now compass width is height-quarter;
else:
Expand All @@ -310,10 +315,11 @@ To determine compass coordinates:
let D be grid-size;
let DD be 2 * D;
let DDD be compass width;
let TE be current graphics window height - (D * 4);
let graphics window height be the height of the graphics window;
let TE be graphics window height - (D * 4);
let UM be TE + D;
let LM be TE + DD;
let BEE be current graphics window height - D;
let BEE be graphics window height - D;
increase D by grid-margin;
increase DD by grid-margin;
increase DDD by grid-margin;
Expand Down Expand Up @@ -359,29 +365,29 @@ To determine compass coordinates:
In theory, it would have been possible to make the map images carry the compass directions as well. In practice, that presented several problems: more difficult to cope with minor map changes during final revisions, inability to indicate which directions have already been explored.]
To refresh compass with current directions:
if glulx graphics is supported:
blank window to graphics background color;
now currently shown picture is the figure of background;
clear the graphics window;
[now currently shown picture is the figure of background;
follow the bottom wide drawing rule;
now currently shown picture is the local map of the location;
follow the bottom scaled drawing rule;
draw Figure of center-squiggle from the x-coordinate of north by y-coordinate of west to grid-size by grid-size;
follow the bottom scaled drawing rule;]
draw Figure of center-squiggle in graphics window at x x-coordinate of north and y y-coordinate of west scaled to width grid-size and height grid-size;
determine compass coordinates;
repeat with way running through directions:
if the way is a listable exit:
let X be the x-coordinate of way;
let Y be the y-coordinate of way;
if the room way from the location is visited:
draw the visited image of the way from X by Y to grid-size by grid-size;
draw the visited image of the way in graphics window at x X and y Y scaled to width grid-size and height grid-size;
otherwise:
draw the unvisited image of the way from X by Y to grid-size by grid-size;
draw the unvisited image of the way in graphics window at x X and y Y scaled to width grid-size and height grid-size;

Section 2 - Local Maps

A room has a figure-name called the local map. [Actual file names and assignments are made later, after all the rooms have been defined.]

[Simple Graphical Window provides instructions for scaling an image and putting it in the middle of the screen if the aspect ratio of the window it needs to fill is slightly wrong. In this case, though, we want to put the map at the bottom of the screen and fill the background above it with black, so there is no apparent top and bottom margin at all.]

This is the bottom wide drawing rule:
[This is the bottom wide drawing rule:
draw wide image in graphics window;
To draw wide image in graphics window:
Expand Down Expand Up @@ -474,7 +480,7 @@ Include (-
];
-)
-)]

Chapter 2 - Sounds

Expand Down
@@ -0,0 +1,73 @@
Version 1/160919 of Glk Events (for Glulx only) by Dannii Willis begins here.

"A low level event handling system"

Use authorial modesty.

Include version 1/160919 of Glulx Definitions by Dannii Willis.



Chapter - Basic event handling

Section - Event result variables

Include (-
Global GE_Event_Struct_type;
Global GE_Event_Struct_win;
Global GE_Event_Struct_val1;
Global GE_Event_Struct_val2;
-) before "Glulx.i6t".

The glk event type is a g-event variable.
The glk event type variable translates into I6 as "GE_Event_Struct_type".
The glk event window ref is a number variable.
The glk event window ref variable translates into I6 as "GE_Event_Struct_win".
The glk event value 1 is a number variable.
The glk event value 1 variable translates into I6 as "GE_Event_Struct_val1".
The glk event value 2 is a number variable.
The glk event value 2 variable translates into I6 as "GE_Event_Struct_val2".



Section - The glulx input handling rules

The glulx input handling rules are a g-event based rulebook.



Section - Intercepting glk_select()

[ Rather than implementing HandleGlkEvent() as GEP did, we will intercept glk_select(). This allows us to intercept events before the Inform 7 template starts processing them. ]
Include (-
Replace glk_select;
-) before "Glulx.i6t".

Include (-
! Replacement function from Glk Events by Dannii Willis
[ glk_select event_struct;
! Call the real glk_select
@push event_struct;
@glk 192 1 0;
! Copy values to our variables
GE_Event_Struct_type = event_struct-->0;
GE_Event_Struct_win = event_struct-->1;
GE_Event_Struct_val1 = event_struct-->2;
GE_Event_Struct_val2 = event_struct-->3;
! Run the glulx input handling rules
FollowRulebook( (+ the glulx input handling rules +), GE_Event_Struct_type, true );
! Copy back to the original event structure
event_struct-->0 = GE_Event_Struct_type;
event_struct-->1 = GE_Event_Struct_win;
event_struct-->2 = GE_Event_Struct_val1;
event_struct-->3 = GE_Event_Struct_val2;
return 0;
];
-) after "Infglk" in "Glulx.i6t".



Glk Events ends here.
@@ -0,0 +1,195 @@
Version 1/160919 of Glk Object Recovery (for Glulx only) by Dannii Willis begins here.

"A low level utility library for managing Glk references after restarting or restoring"

[ This extension was extracted from Glulx Entry points. See http://www.intfiction.org/forum/viewtopic.php?f=7&t=19605 for more discussion. ]

Use authorial modesty.



Section - Glk object recovery

[ These should technically all be called 'glk' rulebooks, but we'll keep them named 'glulx' for compatibility. ]
The glulx zeroing-reference rules is a rulebook.
The glulx resetting-windows rules is a rulebook.
The glulx resetting-streams rules is a rulebook.
The glulx resetting-filerefs rules is a rulebook.
The glulx resetting-channels rules is a rulebook.
The glulx object-updating rules is a rulebook.

Current glulx rock is a number that varies.
Current glulx rock-ref is a number that varies.



Section - GGRecoverObjects

[ Rather than intercepting IdentifyGlkObject() as GEP does, replace GGRecoverObjects(). This allows us to move the built in I6 variable management to rules which can be replaced by other extensions if needed. ]
Include (-
Replace GGRecoverObjects;
-) before "Glulx.i6t".

Include (-
! Replacement GGRecoverObjects from Glk Object Recovery by Dannii Willis
[ GGRecoverObjects ref;
! Reset all Glk references as if none existed
FollowRulebook( (+ glulx zeroing-reference rules +) );
! Iterate through each of the windows, streams, file refs and sound channels
while ( ref = glk_window_iterate( ref, gg_arguments ) )
{
(+ current glulx rock +) = gg_arguments-->0;
(+ current glulx rock-ref +) = ref;
FollowRulebook( (+ glulx resetting-windows rules +) );
}
ref = 0;
while ( ref = glk_stream_iterate( ref, gg_arguments ) )
{
(+ current glulx rock +) = gg_arguments-->0;
(+ current glulx rock-ref +) = ref;
FollowRulebook( (+ glulx resetting-streams rules +) );
}
ref = 0;
while ( ref = glk_fileref_iterate( ref, gg_arguments ) )
{
(+ current glulx rock +) = gg_arguments-->0;
(+ current glulx rock-ref +) = ref;
FollowRulebook( (+ glulx resetting-filerefs rules +) );
}
if ( glk_gestalt( gestalt_Sound, 0 ) )
{
ref = 0;
while ( ref = glk_schannel_iterate( ref, gg_arguments ) )
{
(+ current glulx rock +) = gg_arguments-->0;
(+ current glulx rock-ref +) = ref;
FollowRulebook( (+ glulx resetting-channels rules +) );
}
}
! Tell the game to tie up any loose ends
FollowRulebook( (+ glulx object-updating rules +) );
rfalse;
];
-) after "Starting Up" in "Glulx.i6t".



Section - The built in object recovery rules

[ The following code was extracted from the original GGRecoverObjects() ]
The built in object zeroing rule is listed first in the glulx zeroing-reference rules.
The built in object zeroing rule translates into I6 as "GOR_zeroing".
Include (-
[ GOR_zeroing;
gg_mainwin = 0;
gg_statuswin = 0;
gg_quotewin = 0;
gg_scriptfref = 0;
gg_scriptstr = 0;
gg_savestr = 0;
statuswin_cursize = 0;
gg_foregroundchan = 0;
gg_backgroundchan = 0;
#Ifdef DEBUG;
gg_commandstr = 0;
gg_command_reading = false;
#Endif;
rfalse;
];
-).

The identify built in windows rule is listed first in the glulx resetting-windows rules.
The identify built in windows rule translates into I6 as "GOR_indentify_windows".
Include (-
[ GOR_indentify_windows;
switch ( (+ current glulx rock +) )
{
GG_MAINWIN_ROCK:
gg_mainwin = (+ current glulx rock-ref +);
GG_STATUSWIN_ROCK:
gg_statuswin = (+ current glulx rock-ref +);
GG_QUOTEWIN_ROCK:
gg_quotewin = (+ current glulx rock-ref +);
}
rfalse;
];
-).

The identify built in windows streams rule is listed first in the glulx resetting-streams rules.
The identify built in windows streams rule translates into I6 as "GOR_indentify_streams".
Include (-
[ GOR_indentify_streams;
switch ( (+ current glulx rock +) )
{
GG_SAVESTR_ROCK:
gg_savestr = (+ current glulx rock-ref +);
GG_SCRIPTSTR_ROCK:
gg_scriptstr = (+ current glulx rock-ref +);
#Ifdef DEBUG;
GG_COMMANDWSTR_ROCK:
gg_commandstr = (+ current glulx rock-ref +);
gg_command_reading = false;
GG_COMMANDRSTR_ROCK:
gg_commandstr = (+ current glulx rock-ref +);
gg_command_reading = true;
#Endif;
}
rfalse;
];
-).

The identify built in file refs rule is listed first in the glulx resetting-filerefs rules.
The identify built in file refs rule translates into I6 as "GOR_indentify_filerefs".
Include (-
[ GOR_indentify_filerefs;
switch ( (+ current glulx rock +) )
{
GG_SCRIPTFREF_ROCK:
gg_scriptfref = (+ current glulx rock-ref +);
}
rfalse;
];
-).

The identify built in sound channels rule is listed first in the glulx resetting-channels rules.
The identify built in sound channels rule translates into I6 as "GOR_indentify_schannels".
Include (-
[ GOR_indentify_schannels;
switch ( (+ current glulx rock +) )
{
GG_FOREGROUNDCHAN_ROCK:
gg_foregroundchan = (+ current glulx rock-ref +);
GG_BACKGROUNDCHAN_ROCK:
gg_backgroundchan = (+ current glulx rock-ref +);
}
if ( gg_foregroundchan ~= 0 )
{
glk_schannel_stop( gg_foregroundchan );
}
if ( gg_backgroundchan ~= 0 )
{
glk_schannel_stop( gg_backgroundchan );
}
rfalse;
];
-).



Glk Object Recovery ends here.

---- Documentation ----
This extension is a low level utility library for managing Glk references. When a Glulx game restarts and restores, the current Glk IO state is not reset. All the old windows, sound channels etc. will be kept as they were, even though the game file might be expecting a different state. This extension allows Inform 7 game files to ensure that the IO state is as it should be. It does this in three stages:
1. The "glulx zeroing-reference rulebook" is run. Rules should be added to reset all Glk references as if none existed.
2. The "glulx resetting-windows rulebook" etc. are run. These rulebooks will be run once for each Glk IO object which does currently exist.
3. The "glulx object-updating rulebook" is run. Rules should be added to correct the Glk IO state by, for example, closing windows which shouldn't exist, and opening windows which should but currently do not.
See the extension Flexible Windows by Jon Ingold for a practical demonstration of how these rulebooks are used.
This extension is released under the Creative Commons Attribution licence. Bug reports, feature requests or questions should be made at <https://github.com/i7/extensions/issues>.

0 comments on commit a390bad

Please sign in to comment.