Pueblo developer examples |
This document contains explanations of several example Pueblo servers,
including source code, etc.
http://www.chaco.com/pueblo/vrml/demo/monolith/monolith.wrl
When the user contacts the server (attaches to a port, enters a room
in a mud, etc), she receives this line of IHTML:
<img xch_graph=load
href="http://www.chaco.com/pueblo/vrml/demo/monolith/monolith.wrl">
The VRML file contains this node (among others):
DEF Monolith_rotation Transform { rotation 0 1 0 0 }
This node is replaced periodically by the Pueblo server with a new
version of this node in which the rotation angle is replaced with a
new value (which is incremented in the Pueblo server before each
replacement is sent). For example:
<img xch_graph_node="DEF Monolith_rotation Transform { rotation 0 1 0 1.3 }">
<img xch_graph_node="DEF Monolith_rotation Transform { rotation 0 1 0 1.4 }">
<img xch_graph_node="DEF Monolith_rotation Transform { rotation 0 1 0 1.5 }">
The server may also output a "synchronous draw" command to the Pueblo
client, to be sure the monolith animation is drawn. This is optional, and
for the monolith example, you probably don't want this synchronous
behavior (so the monolith might skip a "frame" of the "animation" if
it's busy doing something else during a frame). For situations where
each frame of an animation must be displayed, this is how to accomplish
it:
<img xch_graph=draw>
This example works as a standalone server which listens on a port (4545 by default), accepts connections from multiple users, and displays a shared view of the monolith, spinning away. This is like a persistent CGI script waiting on a port instead of being run by an HTTP server.
Here's the source.
This server is running on zuni.chaco.com, port 4545. Just point a Pueblo client at it to see what happens.
This object handles the rotation generation, and assumes that when you walked into the room, you loaded the appropriate URL for the monolith.
(In TinyMUSH, the command '&attrname objname=value' sets the 'attrname' attribute of the object 'objname' to 'value'.)
@@ Create the object
@create Rotation
@@ Lock it so only you can pick it up
@lock Rotation==me
@@ When the MUSH starts up, trigger
@@ the rotation timer.
@Startup Rotation=@trig me/rotate_timer
@@ The 'ROTATE' attribute does several
@@ commands when it's '@trig'ed:
@@ 1. Increment the Rotation object's own
@@ "angle_val" attribute by 0.2
@@ 2. Emit the node replacement to
@@ everyone in the room.
&ROTATE Rotation=&angle_val me=[add(v(angle_val),.2)];@emit/noreturn <img xch_graph_node="DEF Monolith_rotation Transform \{ rotation 0 1 0 [v(angle_val)]\}">
@@ The 'ROTATE_TIMER' attribute is triggered when
@@ the MUSH starts up, and triggers the 'ROTATE'
@@ attribute, then waits 1 second and triggers
@@ itself.
&ROTATE_TIMER Rotation=@trig me/rotate;@wait 1=@trig me/rotate_timer
This implementation of 8-Queens is in TinyMUSH, which is a fairly grotesque language, but is okay for rapid-prototyping things like this.
The VRML file used is at this URL:
http://www.chaco.com/pueblo/vrml/pueblo/queens/board.wrl
WWWAnchor {
DEF xch_cmd Info { string "place 0 0" }
IndexedFaceSet { coordIndex [ 0, 1, 10, 9, -1, ] }
}
The Info node named xch_cmd contains a "command" which is sent to the
Pueblo server when the user clicks on the anchor. In the 8-queens
puzzle, each board location has a command of the form
"place <x-coord> <y-coord>". When the chess server receives this
command, it extracts the x and y coordinates of the board position,
and places a queen at that location.
Separator {
DEF Q0_transform Transform { translation 0 0 0 scaleFactor 0 0 0 }
DEF Queen WWWInline { name "queenbig.wrl" }
}
(the other queens all USE Queen instead of DEF'ing Queen.)
The Transform node named "Q0_transform" (or, more generally, "Q<queen-number>_transform") is used to scale and place the queen. Since the current version of Pueblo only supports replacement of transformation nodes (Transform, Rotation, etc.), we cannot just "add" a queen to the scene and "delete" a queen from the scene at will. To get around this, we set the scaleFactor of queens we want to be invisible to '0 0 0', changing the scaleFactor to '1 1 1' when we want them to appear.
So, to place Queen number 3 at location (2, 5), the 8-queens
Pueblo server would output this:
<img xch_graph_node="DEF Q3_transform { translation 2 0 5 scaleFactor 1 1 1 }">