<?xml version='1.0' encoding='UTF-8' ?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title>Bob Westergaard - Blog</title>
	<updated>2008-07-27T16:05:23-04:00</updated>
	<id>http://www.cincomsmalltalk.com/userblogs/bobw/blogView</id>
	<rights>Copyright 2005 Bob Westergaard</rights>
	<generator uri="/CincomSmalltalkWiki/Silt" version="1.0">Silt Syndication Generator</generator>
	<link href="http://www.cincomsmalltalk.com/userblogs/bobw/blogView" rel="alternate" type="text/html"></link>
	<link href="/rssBlog/bobw-atom02.xml" rel="self" type="application/atom+xml"></link>
	<entry>
		<title>Interactive Compiler Settings</title>
		<id>http://www.cincomsmalltalk.com/userblogs/bobw/blogView?showComments=true&amp;printTitle=Interactive_Compiler_Settings&amp;entry=3371999512</id>
		<updated>2007-11-08T18:31:52-05:00</updated>
		<author>
			<name>Bob Westergaard</name>
			<uri>http://www.cincomsmalltalk.com/userblogs/bobw/blogView</uri>
			<email>bobw@cincom.com</email>
		</author>
		<content type="html" xml:lang="en-us"><![CDATA[<div xmlns="http://www.w3.org/1999/xhtml">
<p>When compiling Smalltalk methods in the system interactively, i.e. accepting in a browser or doing a do-it in a Workspace, the compiler will use the InteractiveCompilerErrorHandler to warn you about any problems.  There are a number of useful warnings that the InteractiveCompilerErrorHandler can tell you about.  For example, a temporary variable that is declared and not referenced or a message is being sent that does not exist yet.</p>

<p>Sometimes, all of these helpful warnings simply get in the way.</p>

<p>I've published a package, InteractiveCompilerSettings, to the public repository that overrides the InteractiveCompilerErrorHandler in such a way that allows you to turn these warnings on and off.   The settings will appear in the VisualWorks settings tool.   The warnings that can be turned on and off are:</p>

<UL>

<LI>Never Read - A variable has been defined, assigned a value and that value is never used.

<LI>Never Used - A variable has been defined and is never used

<LI> Read before written -A variable has been defined, and before it is assigned a value a message is sent to it.

<LI> New Message - A message is being sent that does not exist in the system

<LI> Unknown Pragma - The method being compiled has a pragma that is not defined by the class

</UL>
</div>]]></content>
		<link href="http://www.cincomsmalltalk.com/userblogs/bobw/blogView?showComments=true&amp;entry=3371999512" rel="alternate" type="text/html"></link>
		<category term="Enhancements, Extensions or Effluents?"></category>
	</entry>
	<entry>
		<title>Two Steps Forward</title>
		<id>http://www.cincomsmalltalk.com/userblogs/bobw/blogView?showComments=true&amp;printTitle=Two_Steps_Forward&amp;entry=3366043381</id>
		<updated>2007-08-31T20:03:01-04:00</updated>
		<author>
			<name>Bob Westergaard</name>
			<uri>http://www.cincomsmalltalk.com/userblogs/bobw/blogView</uri>
			<email>bobw@cincom.com</email>
		</author>
		<content type="html" xml:lang="en-us"><![CDATA[<div xmlns="http://www.w3.org/1999/xhtml">
<p>

A couple of days ago, I received an email that got me thinking about popular music back from the late 80s and early 90s.  I remembered watching a video for the song, <a href="http://en.wikipedia.org/wiki/Opposites_Attract">Opposites Attract</a>, on MTV.  That is the video where Paula Abdul is dancing with <a href="http://www.paula-abdul.net/html/mc_skat_kat.html">MC Skat Kat</a> while singing about taking two steps forward and two steps back.  I'll use that song lyric as inspiration for this blog entry, and show you another step forward with the Doom port before I start blogging about the translation and implementation effort (the steps back).

</p>

<p>

I've done a few tweaks to get the rendering to be a little faster than the last screencast.  One of the things slowing down the last screencast was the conversion of a Depth8Image (Doom has a small palette) to a Depth32Image for displaying.  Dave Wallen made some suggestions that improved this specific conversion from one palette to another one.  Another fairly big slowdown can only be blamed on me being dope, which I will explain at a later time, because frankly it is embarassing.  

</p>

<p>

I still have the same fixed lighting (it does not get darker as you look into the distance) issue.  However, I've added the message displaying ("Picked up a clip") and added the part where the palette shifts when you pick something up or are attacked.   Because this is the second screencast of the port, I've decided to show the second demo (demo2) in the ultimate doom.wad file.  This screencast is on a window rendering the 320x200 bitmap.  It is a little long (nearly two minutes and half minutes) and a little violent.  If you don't like seeing <a href="http://doom.wikia.com/wiki/Imp">imps</a> being <a href="http://doom.wikia.com/wiki/Berserk_pack">berserked</a> <a href="http://doom.wikia.com/wiki/Fists">punched</a>, then you might want to skip this one.

</p>

<p align=center><a href="http://www.cincomsmalltalk.com/files/bobw/screencasts/Doom_Demo2/"><IMG SRC="http://www.cincomsmalltalk.com/files/bobw/images/demo2.jpg" ALIGN="middle" ALT="Doom2 Demo Picture"></a>

</p>

<p>

Click through the DOOM title picture above to see a screencast of the port as it plays the second demo in the <a href="http://www.idsoftware.com/games/doom/doom-ultimate/">Ultimate Doom</a> <a href="http://en.wikipedia.org/wiki/Doom_WAD">WAD file</a>.

</p>
</div>]]></content>
		<link href="http://www.cincomsmalltalk.com/userblogs/bobw/blogView?showComments=true&amp;entry=3366043381" rel="alternate" type="text/html"></link>
		<category term="Porting Fun"></category>
	</entry>
	<entry>
		<title>VisualWorks is DOOMed</title>
		<id>http://www.cincomsmalltalk.com/userblogs/bobw/blogView?showComments=true&amp;printTitle=VisualWorks_is_DOOMed&amp;entry=3363467171</id>
		<updated>2007-08-02T00:26:11-04:00</updated>
		<author>
			<name>Bob Westergaard</name>
			<uri>http://www.cincomsmalltalk.com/userblogs/bobw/blogView</uri>
			<email>bobw@cincom.com</email>
		</author>
		<content type="html" xml:lang="en-us"><![CDATA[<div xmlns="http://www.w3.org/1999/xhtml">
<p>

Last weekend my brother was giving me some grief about not blogging enough.  Hopefully this one will keep me on his <a href="http://www.google.com/ig">iGoogle</a> front page a little while longer.  After all, if I can't keep my family readership numbers up then what is the point of blogging?

</p>

<p>

To pick up where I left off, I was put into a position where I felt I could not publish the Elite code because of what looked like copyright issues.  So, a little more than a year ago, I was forced to find something else to port.  It did not take me very long to decide it had to be <a href="http://en.wikipedia.org/wiki/Doom">DOOM</a>.  After all, <a href="http://en.wikipedia.org/wiki/Versions_and_ports_of_Doom">DOOM has been ported to all sorts of things</a>, including the <a href="http://www.ipodhacks.com/article.php?sid=741">iPod</a>.  I'm sure it will be on the iPhone soon.  However, I don't believe anyone has ported it to VisualWorks (or Smalltalk).  Perhaps I'm wrong.

</p>

<p>

I think instead of writing some rambling blog entries about what I did to get the port going, which eventually lead to the lamest screencast you've ever seen.  I will <a href="http://en.wikipedia.org/wiki/The_Betrayal">start at the end and end at the start</a> and show you my current work in progress.

</p>

<p align=center><a href="http://www.cincomsmalltalk.com/files/bobw/screencasts/Doom_Demo1/"><IMG SRC="http://www.cincomsmalltalk.com/files/bobw/images/doom_title.jpg" ALIGN="middle" ALT="DOOM Title Picture"></a>

</p>

<p>

Click through the DOOM title picture above to see a screencast of the port as it plays the first demo in the <a href="http://www.idsoftware.com/games/doom/doom-ultimate/">Ultimate Doom</a> <a href="http://en.wikipedia.org/wiki/Doom_WAD">WAD file</a>.

</p>
</div>]]></content>
		<link href="http://www.cincomsmalltalk.com/userblogs/bobw/blogView?showComments=true&amp;entry=3363467171" rel="alternate" type="text/html"></link>
		<category term="Porting Fun"></category>
	</entry>
	<entry>
		<title>CompareDifferentMethods</title>
		<id>http://www.cincomsmalltalk.com/userblogs/bobw/blogView?showComments=true&amp;printTitle=CompareDifferentMethods&amp;entry=3363276724</id>
		<updated>2007-07-30T19:32:04-04:00</updated>
		<author>
			<name>Bob Westergaard</name>
			<uri>http://www.cincomsmalltalk.com/userblogs/bobw/blogView</uri>
			<email>bobw@cincom.com</email>
		</author>
		<content type="html" xml:lang="en-us"><![CDATA[<div xmlns="http://www.w3.org/1999/xhtml">
<p>I find myself often needing to compare two different methods in two different class hierarchies.  I mostly have the desire to do this when using the ChangeList and am viewing changes.  For a while, I've had a little hack in my private database that gives me this feature in the ChangeList.  Back in May I cleaned it up a bit and published it to the public repository.  I'll have to thank <a href="http://wiki.cs.uiuc.edu/VisualWorks/Eliot+Miranda">Eliot</a> for the suggestion of enumerating the system with #allBehaviorsDo:, instead of using #allInstances on CompiliedMethod.  Also, thanks to <a href="http://blog.3plus4.org/">Vassili</a> for writing the Tool-Modules framework which makes it easier to add these sorts of things.  You have no idea how delighted I was when I found the #extent: method to change the opening size of the window.

</p>

<p>

This package, <a href="http://www.cincomsmalltalk.com/publicRepository/CompareDifferentMethods.html">CompareDifferentMethods</a>, extends the ChangeList, the Browser and the Store comparison browser so that you can compare a selected method with any other method in the system (a new menu item called "Differator this with...").   Admittedly, this is a little limited and painful to use.   However, it can sometimes be useful when methods that exist in different hierarchies.

</p>

<p>

The package extends the IncrementalSearchDialog and IncrementalSearchDialog to allow for incremental searching on all methods in the system.  For example the following do-it will open up a method browser on a selected method (if any):

</p>

<link rel="stylesheet" type="text/css" href="http://www.cincomsmalltalk.com/files/bobw/color_syntax.css"/><pre><span class="code_parenthesis">(</span><span class="code_classReference">IncrementalSearchDialog</span>

	<span class="code_messageSend">requestSpecificSelector:</span> <span class="code_string">'Specify specific selector:'</span>

	<span class="code_messageSend">initialEntry:</span> <span class="code_string">'send*th'</span><span class="code_parenthesis">)</span> <span class="code_messageSend">ifNotNil:</span>

	<span class="bold">[</span><span class="code_blockArgument">:md</span> | 

	<span class="code_classReference">MethodCollector</span> <span class="code_messageSend">new</span>

		<span class="code_messageSend">openListBrowserOn:</span> <span class="code_parenthesis">(</span><span class="code_classReference">Array</span> <span class="code_messageSend">with:</span> <span class="code_temporaryVariable">md</span><span class="code_parenthesis">)</span>

		<span class="code_messageSend">label:</span> <span class="code_string">'Method Browser'</span><span class="bold">]</span></pre>
</div>]]></content>
		<link href="http://www.cincomsmalltalk.com/userblogs/bobw/blogView?showComments=true&amp;entry=3363276724" rel="alternate" type="text/html"></link>
		<category term="Enhancements, Extensions or Effluents?"></category>
	</entry>
	<entry>
		<title>ExternalWebBrowser-ToolOverrides</title>
		<id>http://www.cincomsmalltalk.com/userblogs/bobw/blogView?showComments=true&amp;printTitle=ExternalWebBrowser-ToolOverrides&amp;entry=3360488223</id>
		<updated>2007-06-28T12:57:03-04:00</updated>
		<author>
			<name>Bob Westergaard</name>
			<uri>http://www.cincomsmalltalk.com/userblogs/bobw/blogView</uri>
			<email>bobw@cincom.com</email>
		</author>
		<content type="html" xml:lang="en-us"><![CDATA[<div xmlns="http://www.w3.org/1999/xhtml">
<p><a href="http://www.cincomsmalltalk.com/blog/View.ssp">James Robertson</a> recently did a <a href="http://www.cincomsmalltalk.com/blog/blogView?showComments=true&printTitle=Smalltalk_Daily_6/19/07:_Launching_a_Web_Browser_from_CST&entry=3359708842">screencast where he demonstrates starting a external web browser from Cincom Smalltalk VisualWorks</a>.  This uses the <a href="http://www.cincomsmalltalk.com/userblogs/travis/blogView?showComments=true&entry=3352501957">ExternalWebBrowser package which Travis blogged about back in March</a>.</p>



<p>There is a <a href="http://www.cincomsmalltalk.com/userblogs/travis/blogView?showComments=true&printTitle=Browser_Dev_Stream&entry=3352506418">development stream for the Tools-RefactoringBrowser bundle</a>, which <a href="http://www.cincomsmalltalk.com/userblogs/travis/">Travis</a> has blogged about.

One of the things he did was use the functionality from the <a href="http://www.cincomsmalltalk.com/publicRepository/ExternalWebBrowser.html">External-WebBrowser</a> in the development browser so you can click on URLs and spawn a web browser.  With Travis' permission, I pulled out the extensions that added the Text emphasis for URLs into its own package, <a href="http://www.cincomsmalltalk.com/publicRepository/ExternalWebBrowser-Text.html">ExternalWebBrowser-Text</a>.</p>



<p>It dawned on me the other day, I'd like the behavior of clicking in URLs in the browser without having to load the development stream of the Tools-RefactoringBrowser bundle.  It would also be nice to have the feature on the published items tool and Workspace.  So, I've published the <a href="http://www.cincomsmalltalk.com/publicRepository/ExternalWebBrowser-ToolOverrides.html">ExternalWebBrowser-ToolOverrides</a> package to the <a href="http://www.cincomsmalltalk.com/CincomSmalltalkWiki/PostgreSQL+Access+Page">Cincom public repository </a> which by overriding three methods adds this functionality.</p>
</div>]]></content>
		<link href="http://www.cincomsmalltalk.com/userblogs/bobw/blogView?showComments=true&amp;entry=3360488223" rel="alternate" type="text/html"></link>
		<category term="Enhancements, Extensions or Effluents?"></category>
	</entry>
	<entry>
		<title>Docking Computers On</title>
		<id>http://www.cincomsmalltalk.com/userblogs/bobw/blogView?showComments=true&amp;printTitle=Docking_Computers_On&amp;entry=3358093705</id>
		<updated>2007-05-31T19:48:25-04:00</updated>
		<author>
			<name>Bob Westergaard</name>
			<uri>http://www.cincomsmalltalk.com/userblogs/bobw/blogView</uri>
			<email>bobw@cincom.com</email>
		</author>
		<content type="html" xml:lang="en-us"><![CDATA[<div xmlns="http://www.w3.org/1999/xhtml">
<p>Back in November of 2005, I was chatting with <a href="http://blog.3plus4.org/">Vassili</a> and the topic of games (as usual) came up.  I mentioned to him that <a href="http://www.cincomsmalltalk.com/userblogs/bobw/blogView?showComments=true&entry=3356639621">I had starting porting Elite the New Kind to VisualWorks</a>, but it was broken because of a broken laptop.  He seemed interested, so I decided to dig up the work around and show him.  

</p>



<p>Quite some time had passed since I last looked at the code.  One thing became immediately clear, I could not easily tell which functions I had finished porting.  It was obvious if a function was not ported at all, because there was no corresponding method.  However, for methods that had code that looked like the C function, it was not clear if the translation bugs were fixed yet.  I found myself wanting a way to compare the method source with the corresponding source in the C source file.</p>



<p>

Finally, it occurred to me that if could annotate a method with a pragma that described the location of the original C function (which C file and where in the file),  I could then use the Differator to compare the Smalltalk with the original C source.  Using a pragma was a huge leap for me.  I had been aware for pragmas as long as they had been in VisualWorks.  However, for some reason (probably one reason: I'm a dope), I never found the need to create my own.

</p>



<p>I re-parented all my Elite classes under a new superclass, which I called CFileThing. On the class side, I created the following method:<link rel="stylesheet" type="text/css" href="http://www.cincomsmalltalk.com/files/bobw/color_syntax.css"/><pre><span class="code_unaryMethodName">filePragma</span>



	<span class="code_primitive">&lt;pragmas: </span><span class="code_symbol">#class</span><span class="code_primitive">></span>

	<span class="code_primitive">&lt;pragmas: </span><span class="code_symbol">#instance</span><span class="code_primitive">></span>

	<span class="code_return">^</span><span class="code_array">#(</span>file:start:stop:<span class="code_array">)</span></pre>



<p>Then it is a trivial exercise to use the Differator to compare the two implementations side by side.  Here's how one method comparison looks in the differator:

</p><a href="http://www.cincomsmalltalk.com/files/bobw/images/differator_large.jpg">

<p><img alt="Differator comparing a C function with corresponding Smalltalk function" src="http://www.cincomsmalltalk.com/files/bobw/images/differator_small.jpg"></img></a>

</p>



<p>

With a little more work, it was not too hard to integrate this behavior into a new subclass of the CodeCompareTool:

</p>

<p><a href="http://www.cincomsmalltalk.com/files/bobw/images/browsediff_large.jpg">

<img alt="CodeCompareTool comparing a C function with corresponding Smalltalk function" src="http://www.cincomsmalltalk.com/files/bobw/images/browsediff_small.jpg"></img></a>

</p>



<p>Before I knew it, I was in position where I could publish a work in progress to the <a href="http://www.cincomsmalltalk.com/CincomSmalltalkWiki/PostgreSQL+Access+Page">public repository</a>.  However, it was also the same time I noticed the <a href="http://groups.google.com/group/alt.fan.elite/browse_frm/thread/ac0b0e4fc947025c/"> copyright problems</a> <a href="http://www.newkind.co.uk/about.php">Christian Pinder</a> was having with having released Elite the new Kind.   The <a href="http://en.wikipedia.org/wiki/Elite_(computer_game)">wikipedia entry on Elite</a> claims: "The dispute has since been settled and Elite: The New Kind can be downloaded once more".  However, I can't find a reference confirming this.  So, I'm reluctant to publish to the public repository. 

</p>



<p>In the meantime, I have a <a href="http://www.cincomsmalltalk.com/files/bobw/screencasts/EliteDemo/">screencast showing the port in VisualWorks</a>.  Here you'll see me leave the space station, show the different views, turn around and dock back in the station.  The docking was courtesy of the docking computer which I added so I would not have to buy it first. 

</p>



<p>

For the screencast, I again used <a href="http://www.techsmith.com/camtasia.asp">Camtasia studio</a> again (like I did with the last <a href="http://www.cincomsmalltalk.com/userblogs/bobw/blogView?showComments=true&printTitle=Refactoring_Steroids&entry=3355515270">screencast for refactoring Steroids</a>).

</p>
</div>]]></content>
		<link href="http://www.cincomsmalltalk.com/userblogs/bobw/blogView?showComments=true&amp;entry=3358093705" rel="alternate" type="text/html"></link>
		<category term="Porting Fun"></category>
	</entry>
	<entry>
		<title>I am not l33t</title>
		<id>http://www.cincomsmalltalk.com/userblogs/bobw/blogView?showComments=true&amp;printTitle=I_am_not_l33t&amp;entry=3356639621</id>
		<updated>2007-05-14T23:53:41-04:00</updated>
		<author>
			<name>Bob Westergaard</name>
			<uri>http://www.cincomsmalltalk.com/userblogs/bobw/blogView</uri>
			<email>bobw@cincom.com</email>
		</author>
		<content type="html" xml:lang="en-us"><![CDATA[<div xmlns="http://www.w3.org/1999/xhtml">
<p>

After the Java Asteroids experience, I was eager to try to port something else.  Around this time I had stumbled across <a href="http://www.newkind.co.uk/games/">Elite the New Kind</a>, by <a href="http://www.newkind.co.uk/about.php">Christan Pinder</a>.  This was a reverse engineering of the classic space trading game <a href="http://en.wikipedia.org/wiki/Elite_(computer_game)">Elite</a>, by <a href="http://www.iancgbell.clara.net/">Ian Bell</a> and <a href="http://www.frontier.co.uk/">David Braben</a>.  I used to play this game for hours on my <a href="http://www.c64.com/">Commodore 64</a> and I still remember being amazed at the real-time 3D wireframe display.  Converting Elite the New Kind had to be experiment number two.  I already had a plan for the first change I would make to the game: give myself the auto docking computer.

</p>



<p>

Elite the New Kind was written in <a href="http://en.wikipedia.org/wiki/C_(programming_language)">C</a>.  For this blog entry, I ran <a href="http://www.dwheeler.com/sloccount">SLOCCount</a> over the source and it told me that it had 11,051 lines of code all contained in 21 .c files and 25 .h files.  The game was using the <a href="http://www.talula.demon.co.uk/allegro/">Allegro</a> game programming library for graphics and sound.

</p>



<p>I decided to take a similar approach I took with Java Asteroids.  I'd create a class for each C source file and a class for each structure used in the C Source.  Classes that came from C Structures would simply have instance variables for each member in the structure, and all these instance variables had getters and setters.   Functions would end up as similar named methods, with an initial body being the C source code in a Smalltalk comment.  My plan was to do the same manual translation along with copy, paste, search and replace.

</p>



<p>As an example, here is the original C source for finishing rendering the polylines that have been queued up in C:<pre>



	if (total_polys == 0)

		return;

		

	for (i = start_poly; i != -1; i = poly_chain[i].next)

	{

		num_points = poly_chain[i].no_points;

		pl = poly_chain[i].point_list;

		col = poly_chain[i].face_colour;



		if (num_points == 2)

		{

			gfx_draw_colour_line (pl[0], pl[1], pl[2], pl[3], col);

			continue;

		}

		

		gfx_polygon (num_points, pl, col); 

	};

</pre>

</p>



<p>

The Smalltalk code looks similar:<link rel="stylesheet" type="text/css" href="http://www.cincomsmalltalk.com/files/bobw/color_syntax.css"/><pre>



	| <span class="code_temporaryVariableDefinition">i</span> |

	<span class="code_instanceVariable">totalPolys</span> <span class="code_messageSend">=</span> <span class="code_number">0</span> <span class="code_messageSend">ifTrue:</span> <span class="code_bracket">[</span><span class="code_return">^</span><span class="code_self">self</span><span class="code_bracket">]</span>.

	<span class="code_temporaryVariable">i</span> <span class="code_assignment">:=</span> <span class="code_instanceVariable">startPoly</span>.

	<span class="code_bracket">[</span><span class="code_temporaryVariable">i</span> <span class="code_messageSend">~=</span> <span class="code_number">-1</span><span class="code_bracket">]</span> <span class="code_messageSend">whileTrue:</span>

		<span class="code_bracket">[</span>| <span class="code_temporaryVariableDefinition">numPoints</span> <span class="code_temporaryVariableDefinition">pl</span> <span class="code_temporaryVariableDefinition">col</span> |

		<span class="code_temporaryVariable">numPoints</span> <span class="code_assignment">:=</span> <span class="code_parenthesis">(</span><span class="code_instanceVariable">polyChain</span> <span class="code_messageSend">at:</span> <span class="code_temporaryVariable">i</span> <span class="code_messageSend">+</span> <span class="code_number">1</span><span class="code_parenthesis">)</span> <span class="code_messageSend">noPoints</span>.

		<span class="code_temporaryVariable">pl</span> <span class="code_assignment">:=</span> <span class="code_parenthesis">(</span><span class="code_instanceVariable">polyChain</span> <span class="code_messageSend">at:</span> <span class="code_temporaryVariable">i</span> <span class="code_messageSend">+</span> <span class="code_number">1</span><span class="code_parenthesis">)</span> <span class="code_messageSend">pointList</span>.

		<span class="code_temporaryVariable">col</span> <span class="code_assignment">:=</span> <span class="code_parenthesis">(</span><span class="code_instanceVariable">polyChain</span> <span class="code_messageSend">at:</span> <span class="code_temporaryVariable">i</span> <span class="code_messageSend">+</span> <span class="code_number">1</span><span class="code_parenthesis">)</span> <span class="code_messageSend">faceColor</span>.

		<span class="code_temporaryVariable">numPoints</span> <span class="code_messageSend">=</span> <span class="code_number">2</span>

			<span class="code_messageSend">ifTrue:</span>

				<span class="code_bracket">[</span><span class="code_self">self</span>

					<span class="code_messageSend">gfxDrawColorLine_x1:</span> <span class="code_parenthesis">(</span><span class="code_temporaryVariable">pl</span> <span class="code_messageSend">at:</span> <span class="code_number">1</span><span class="code_parenthesis">)</span>

					<span class="code_messageSend">y1:</span> <span class="code_parenthesis">(</span><span class="code_temporaryVariable">pl</span> <span class="code_messageSend">at:</span> <span class="code_number">2</span><span class="code_parenthesis">)</span>

					<span class="code_messageSend">x2:</span> <span class="code_parenthesis">(</span><span class="code_temporaryVariable">pl</span> <span class="code_messageSend">at:</span> <span class="code_number">3</span><span class="code_parenthesis">)</span>

					<span class="code_messageSend">y2:</span> <span class="code_parenthesis">(</span><span class="code_temporaryVariable">pl</span> <span class="code_messageSend">at:</span> <span class="code_number">4</span><span class="code_parenthesis">)</span>

					<span class="code_messageSend">color:</span> <span class="code_temporaryVariable">col</span><span class="code_bracket">]</span>

			<span class="code_messageSend">ifFalse:</span>

				<span class="code_bracket">[</span><span class="code_self">self</span>

					<span class="code_messageSend">gfxPolygon:</span> <span class="code_temporaryVariable">numPoints</span>

					<span class="code_messageSend">points:</span> <span class="code_temporaryVariable">pl</span>

					<span class="code_messageSend">color:</span> <span class="code_temporaryVariable">col</span><span class="code_bracket">]</span>.

		<span class="code_temporaryVariable">i</span> <span class="code_assignment">:=</span> <span class="code_parenthesis">(</span><span class="code_instanceVariable">polyChain</span> <span class="code_messageSend">at:</span> <span class="code_temporaryVariable">i</span> <span class="code_messageSend">+</span> <span class="code_number">1</span><span class="code_parenthesis">)</span> <span class="code_messageSend">next</span><span class="code_bracket">]</span></pre>

</p>



<p>Remarkably, for being such tedious way to convert the C code to <a href="http://en.wikipedia.org/wiki/Smalltalk">Smalltalk</a>, I felt I made pretty good progress.  At some point, I managed get the <a href="http://elite.acornarcade.com/ships/cobra3.htm">Cobra MK III</a> to display at the beginning of the game just like the <a href="http://www.mobygames.com/game/c64/elite/screenshots/gameShotId,131048/" title="Link to screenshot on C64 at MobyGames.com">original</a>.  Once I reached this point, I felt the urge to refactor.   

</p>



<p>

A few days later, I had a small failure lap-top failure.  Nothing too serious, I didn't loose everything.  Just enough to not show you the results.  I hadn't published to my local database for quite some time and the changes file was truncated in a poor place.  Fortunately, the story with this conversion doesn't end there.  However, I'll save that for the next blog entry.

</p>

 
</div>]]></content>
		<link href="http://www.cincomsmalltalk.com/userblogs/bobw/blogView?showComments=true&amp;entry=3356639621" rel="alternate" type="text/html"></link>
		<category term="Porting Fun"></category>
	</entry>
	<entry>
		<title>Refactoring Steroids</title>
		<id>http://www.cincomsmalltalk.com/userblogs/bobw/blogView?showComments=true&amp;printTitle=Refactoring_Steroids&amp;entry=3355515270</id>
		<updated>2007-05-01T23:34:30-04:00</updated>
		<author>
			<name>Bob Westergaard</name>
			<uri>http://www.cincomsmalltalk.com/userblogs/bobw/blogView</uri>
			<email>bobw@cincom.com</email>
		</author>
		<content type="html" xml:lang="en-us"><![CDATA[<div xmlns="http://www.w3.org/1999/xhtml">
<p><b>Update:</b> I was playing around with Camtasia Studio and used that to create a embedded flash animation to replace the compressed AVI file <a href="#demo_links">below</a>.  

</p>

<p>

<a href="http://www.cincomsmalltalk.com/userblogs/mls/blogView">Micheal Lucas-Smith</a> commented in a previous blog post that now would a good time to refactor.  I agree with him.  Once the game was completely ported and running it is a great time to refactor.  So, if anyone wants to refactor it, you can find it in your contributed directory in your VisualWorks installation.  

</p>

<p>

I have never done any refactoring on it, mostly because a few other things caught my interest after the port to VisualWorks.  I've always thought that the goody would make a good example of live-refactoring with the game running.  As an example of that here are a sequence of steps that you can follow that will refactor out the bit in Asteroids>>#paint: that paints the asteroid into the Asteroid class as its own paint method.  </p>

<p>



<OL>

<LI> Start up VisualWorks and Load Steroids.  You can find it in the parcel manager.

<LI> Once it is loaded you can open it by clicking on one of the Play Throtted Asteroids toolbar button on the launcher or do: <pre>

	Steroids.ThrottledAsteroidsAppModel open

</pre>

in a workspace.

<LI>  Play the game for a while! Once you are done, leave Steroids running so that you can see the asteroids moving around

<LI> Open up a browser on the class Steroids.Asteroids and select the method #paint:

<LI> Scroll down to where the asteroids are drawn, here is the code:

<link rel="stylesheet" type="text/css" href="http://www.cincomsmalltalk.com/files/bobw/color_syntax.css"/><pre>

    <span class="code_comment">"Draw the asteroids."</span>

    <span class="code_number">1</span> <span class="code_messageSend">to:</span> <span class="code_sharedVariableReference">MAX_ROCKS</span> <span class="code_messageSend">do:</span>

        <span class="code_bracket">[</span><span class="code_blockArgument">:i</span>| | <span class="code_temporaryVariableDefinition">asteroid</span> |

        <span class="code_parenthesis">(</span><span class="code_temporaryVariable">asteroid</span> <span class="code_assignment">:=</span> <span class="code_instanceVariable">asteroids</span> <span class="code_messageSend">at:</span> <span class="code_temporaryVariable">i</span><span class="code_parenthesis">)</span> <span class="code_messageSend">active</span> <span class="code_messageSend">ifTrue:</span> 

            <span class="code_bracket">[</span><span class="code_instanceVariable">detail</span> <span class="code_messageSend">ifTrue:</span> 

                <span class="code_bracket">[</span><span class="code_temporaryVariable">gc</span> <span class="code_messageSend">paint:</span> <span class="code_classReference">ColorValue</span> <span class="code_messageSend">black</span>.

                 <span class="code_temporaryVariable">gc</span> <span class="code_messageSend">displayPolygon:</span> <span class="code_temporaryVariable">asteroid</span> <span class="code_messageSend">sprite</span> <span class="code_messageSend">points</span><span class="code_bracket">]</span>.

            <span class="code_temporaryVariable">gc</span> <span class="code_messageSend">paint:</span> <span class="code_classReference">ColorValue</span> <span class="code_messageSend">white</span>.

            <span class="code_temporaryVariable">gc</span> <span class="code_messageSend">displayPolyline:</span> <span class="code_parenthesis">(</span><span class="code_temporaryVariable">asteroid</span> <span class="code_assignment">:=</span> <span class="code_instanceVariable">asteroids</span> <span class="code_messageSend">at:</span> <span class="code_temporaryVariable">i</span><span class="code_parenthesis">)</span> <span class="code_messageSend">sprite</span> <span class="code_messageSend">points</span><span class="code_bracket">]</span><span class="code_bracket">]</span>.</pre>

<LI> Edit the method to change  the last line in the #ifTrue: block argument to be:

<link rel="stylesheet" type="text/css" href="http://www.cincomsmalltalk.com/files/bobw/color_syntax.css"/><pre>

	<span class="code_temporaryVariable">gc</span> <span class="code_messageSend">displayPolyline:</span> <span class="code_temporaryVariable">asteroid</span> <span class="code_messageSend">sprite</span> <span class="code_messageSend">points]].</span></pre>

<LI> Now select the whole block being sent to ifTrue:

<LI> Pop up your operate menu and select: Refactor->Extract to component.  <a href="http://www.cincomsmalltalk.com/userblogs/buck">David Buck</a> provides a <a href="http://www.cincomsmalltalk.com/userblogs/buck/blogView?showComments=true&entry=3303669891">great explanation and example of extracting to a component</a>.

<LI> Select asteroid as the variable to move the method into

<LI> Select Steroids.AsteroidsSprite in the next dialog

<LI> For the next dialog, supply a name to replace self, I use game

<LI> You'll be asked to create getters and setters for direct variable references, answer yes to the dialog

<LI> You'll be told that the method contains references to variables which are inaccessible in the namespace of the destination.  Answer yes

<LI> You'll be asked how to handle references to ColorValue, select "Specific Import"

<LI> You'll be asked to supply a the new method name (a default is provided), type something like: #displayOn:game: then click OK

<LI> You're watching the game right? If you missed it, then just undo the changes by clicking on "undo the last action" in the tool bar twice (once for the method to component refactoring, the other for the first change we did above).  Then click redo the last action toolbar button and watch the method and game change.

</OL>

</p>



<p>

There are two interesting things being shown here.  First, the only bit of actually typing of Smalltalk code was replacing <b>(asteroids at: i)</b> with <b>asteroid</b>.  Writing the new method with what was selected from step seven above, putting it into a different class and fixing up the original method was all taken care of by the refactoring engine that the browser uses.  The second interesting thing is the game was <b>still running</b> while the changes were being made.  

</p>

<p><a name="demo_links"></a>

As a bonus, I've put a <a href="http://www.cincomsmalltalk.com/files/bobw/clip0024.avi.gz">compressed avi file (17 MB)</a> up that shows me making the above changes in VisualWorks 7.5.  I've also included a <a href="http://www.cincomsmalltalk.com/files/bobw/screencasts/Refactoring_Steroids/">screencast of the refactoring</a>.

</p>
</div>]]></content>
		<link href="http://www.cincomsmalltalk.com/userblogs/bobw/blogView?showComments=true&amp;entry=3355515270" rel="alternate" type="text/html"></link>
		<category term="Porting Fun"></category>
	</entry>
</feed>
