Thursday, July 23, 2009

Live and collaborative coding in Croquet

Open Croquet and Cobalt SDK are built on top of the Squeak self-exploratory environment, where everything could be modified/inspected in real time. It means that the environment is just created for live coding and interactive programming in SmallTalk.

Everything is OK, when you use just one computer with only one running vm/image on it (default for Squeak programming model).
But, Croquet/Cobalt were built for creating replicated 3D environments, which are distributed over the network, and several vm's/images running at the same time define the Island.
And so, for saving the identity of replicas of the shared Island, nobody from the participants couldn't change anything in the code in the local images. They are allowed just modify parameters had been programed earlier, or update their images using changeSets, Monticello etc. or just copy/paste the whole image.
But, if we want to program on the Island in all replicas at the same time?
For example it is often needed, when you have already run several images defining Island, but need to modify something in code, without stopping everything.
Or for collaborative coding between several programmers at the same time, forming one image, but working on it's replicas, being at different places.

The feature is missed in the current Croquet SDK (may be XPForums project for collaborative programming using Croquet will solve this, but it is closed yet).

So, as proof of "live coding" concept in Croquet we could do the following:

1. Create the new TObject or TFrame subclass, with instance method like:

TLiveCode>> compileMethod: aCodeString inClass: aClassName

Utilities authorInitialsPerSe isEmpty ifTrue:[ Utilities setAuthorInitials: 'sn'].
aClassName compile: aCodeString.

2. Add this object into the existed island (or register during initialization):

liveCodeFrame := self harness activeIsland future new: TLiveCode.
liveCodeFrame future registerGlobal: #liveCoding.

3. Then add instance method to the used harness class, like:

CroquetHarness>> makeMethodInFuture: aCodeString inClass: aClassName

| liveCodeFrame|

liveCodeFrame := self activeIsland future at: #liveCode.
liveCodeFrame whenResolved:[
liveCodeFrame futureDo: #compileMethod:inClass: at:0 args: {aCodeString. aClassName}

The calling of this method on any participant will leads to the equal modification of the source code in all connected Island replicas.

This proof of concept code for Croquet/Cobalt image can be downloaded here.
Experimental Seaside based ClassBrowser with support for live coding in Croquet island directly from web-browser is here (the Croquet-Seaside 2.9 imge and above code is needed to run).

Next steps could be the development of corresponding tools using existed SystemBrowser or OmniBrowser for full support of live coding/collaborative programming in the shared Islands.

Monday, July 13, 2009

Seaside 2.9 and Comet to control replicated Croquet islands.

I want to share some of my experiments in combination of Open Croquet and Seaside/Comet at image level.

The main aim is: to allow multi-user interactions with shared content on the Croquet island just from web browser in real time (from any place, device like smart-phone, low-end machine (sometimes without OpenGL) etc. so, that a connection to the network and http web based browser just needed.
Also, it could help to implement open source "Forum pages" like features , which are existed only in Qwaq forums 2.0 (access recent activity from your web browser etc.).

I have prepared the ready-to-go image for those, who want to explore the infinite possibilities :)
1. CroquetSDK.v1.0.18 with new image.
2. Just one image for using with manual downloaded any Croquet SDK.

Also, I prepared the Script for loading Seaside 2.9 alpha updated (13-07-09) into any fresh OpenCroquet image (1.0.18 users should update from sources to the latest, or use this one Croquet.1.0.25 )

For examples look at SmotriniWorldControl class.

Here on the screen-shot there are two participants and two opened web browsers (Safari, Firefox).
Just only one participant run Seaside/Comet application.
Changing any of the RGB sliders (in one of browser window) causes the change of the active space color, and glad to Comet in all opened Web browsers slider's handles change their visual state automatically (without manual refreshing).

All callbacks from seaside to croquet island are future events, like from proper harness in Croquet, so they dose not destroy the replicated state.
onSlide: (html jQuery ajax
callback: [ :value |
aColor = #red ifTrue:[self class valueRGB red: value asNumber.
aFrame future color: (Color r: self class valueRGB red g: aFrame color green b: aFrame color blue)].

How to run:

1. Start WAListenerAdaptor (support Comet Seaside applications)

WAListenerAdaptor startOn: 8888. (different ports for several participants, if needed)

2. Open Croquet master (KAT Demo harness is used in this example, from default Croquet SDK).

KCroquetParticipant new openInWorld.

When it asks about interactivity server, leave it blank, as ( could not work, so it will start locally.

3. Point your any web browser (Firefox, Safari preferable) to:


4. To test Comet functions (RGB Slider), just open another browser window and point it also to:


To be continued..