<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>blog.jacius.info</title>
	<atom:link href="http://blog.jacius.info/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.jacius.info</link>
	<description></description>
	<lastBuildDate>Fri, 18 May 2012 23:59:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Ambienome Brain Dump</title>
		<link>http://blog.jacius.info/2012/04/17/ambienome-brain-dump/</link>
		<comments>http://blog.jacius.info/2012/04/17/ambienome-brain-dump/#comments</comments>
		<pubDate>Tue, 17 Apr 2012 18:42:08 +0000</pubDate>
		<dc:creator>John Croisant</dc:creator>
				<category><![CDATA[Ambienome]]></category>

		<guid isPermaLink="false">http://blog.jacius.info/?p=949</guid>
		<description><![CDATA[Lately, I&#8217;ve been focusing so much on Common Lisp itself, that I have barely spent any time on Ambienome, the whole reason I&#8217;ve been learning it. It has been so long that I can barely remember what I was working on. (Physics engine integration, I think?) That&#8217;s no good, so I wanted to take some [...]]]></description>
			<content:encoded><![CDATA[<p>Lately, I&#8217;ve been focusing so much on Common Lisp itself, that I have barely spent any time on Ambienome, the whole reason I&#8217;ve been learning it. It has been so long that I can barely remember what I was working on. (Physics engine integration, I think?)</p>
<p>That&#8217;s no good, so I wanted to take some time to set my thoughts and ideas for Ambienome onto paper (so to speak). This will help me slide back into that mode of thinking, hone my ideas by putting them into words, leave a journal of how the game evolves, and maybe spark some interest in anyone reading this.</p>
<p>Caveat: you should not interpret any part of this as a promise or firm description of how the actual game will be. I&#8217;m just unloading my thoughts and ideas as they exist now. Everything is still subject to change, etc. <span id="more-949"></span></p>
<h2>Creation vs Play</h2>
<p>One thing I have not yet decided is how much focus will be on <em>creating</em> content, and how much focus will be on <em>playing</em> (or consuming) content. In other words, is Ambienome a game with a built-in creature creator, or a creative tool for designing interactive motion graphics and audio? Does the player create things to play with, or is the act of creation itself the gameplay? Where do I strike the balance?</p>
<p>I think it should lean more towards being a game that you can create custom content for. A typical user might spend two thirds of their time playing with user-created content, and one third creating new content. Naturally, individual users will have different interests and focuses, but I really want creating content to be accessible, highly interactive, and engaging. <a href="https://www.youtube.com/watch?v=ZRr3lgckIAM">Spore</a>,<a href="https://www.youtube.com/watch?v=qss4uy6C_g0">Minecraft</a>, and <a href="https://www.youtube.com/watch?v=_vHdU9ctp7M">Little Big Planet</a> are all excellent examples of this.</p>
<p>As I&#8217;m envisioning it now, users would create scenes, which would have various creatures as well as level geometry (walls, etc.) and maybe some non-creature objects/items. The game would come with a variety of pre-built creatures, and the user could also build their own from scratch or by modifying an existing creature. Creatures could be saved and re-used between scenes, exported or imported as files, and easily shared online. Likewise, scenes could be exported, imported, and shared online.</p>
<p>Ambienome would likely come with a few dozen pre-made scenes that gradually introduce new creatures and gameplay mechanics, as puzzle games often do. Some of the scenes would have specific puzzles or goals to solve, while others would be &#8220;free play&#8221; mode like <a href="https://www.youtube.com/watch?v=onmrp_FuoDE">Electroplankton</a>, where the only goal is to have fun playing with the creatures.</p>
<h2>Gameplay Mechanics</h2>
<p>There are many possible gameplay mechanics, ways in which you can interact with the scene, and creatures can interact with each other. Here are some that have been floating around in my head:</p>
<ul>
<li>Light/darkness (bioluminescence, light sensitivity)</li>
<li>Heat/cold (energy transfer)</li>
<li>Attraction/repulsion (magnetism)</li>
<li>Falling/floating (gravity, buoyancy)</li>
<li>Water/air currents (lines, splines, vortices)</li>
<li>Bubbles (for air supply, or carrying objects)</li>
<li>Sound pitch/harmony</li>
<li>Playing a melody (correct notes in correct order)</li>
<li>Physical contact (collision, bouncing, overlapping)</li>
<li>Eating food or other creatures</li>
<li>Life cycles (birth, growth, death)</li>
<li>Controlling creature directly with keyboard, mouse, or joystick</li>
<li>Creatures follow mouse pointer</li>
<li>Clicking and dragging to move creatures and objects</li>
</ul>
<p>These mechanics can be combined in interesting ways to create fun puzzles and free play scenes. For example, there might be a puzzle scene where you guide a creature to find some fruit and bring it back to the creature&#8217;s hungry offspring. But of course, there are obstacles in the way! First you have to bump into some singing sea cucumbers that each play a different note and glow a different color. When you play the correct melody, a hot magma stone appears. You carry the stone to a dormant hydrothermal vent, thereby heating up the vent. When the vent is hot, it produces a rising current which carries you up to reach some fruit hanging on a vine on the ceiling. You carry the fruit back to the hungry offspring, thus completing the scene. (This is all 100% scientifically accurate, of course. I saw it on the Discovery Channel. Honest!)</p>
<p>The game mechanics can also be used for free play scenes. One scene might have some jellies whose long tendrils ring like wind chimes when they move. When you move the mouse cursor, it creates a brief current, stirring the tendrils and making relaxing sounds. Perhaps there are schools of tiny fish hiding among some kelp, but they are attracted by the sound of the jellies&#8217; tendrils, so they emerge and start swimming around, leaving colorful trails as they move. There&#8217;s no goal to accomplish or puzzle to solve, you can just relax and enjoy the sights and sounds for as long as you wish.</p>
<p>Naturally, all the creatures and game mechanics used in the scenes that came with the game would also be available for users to create their own scenes. And, players would be able to use those scenes and creatures as starting points for their own creations. Maybe you want to add some hydrothermal vents from that puzzle scene to create warm water currents that stir the jellies&#8217; tendrils in the free play scene. Just press a button to switch to &#8220;create&#8221; mode, drag some vents into the scene, and voilà.</p>
<p>Ideally, creatures and scenes uploaded by other users would also be available for creating derivative works. But, that starts to get into some complex issues. How much control do users have over the license? Do all uploaded creations have to be under a certain license (perhaps some form of Creative Commons)? What about creations they don&#8217;t upload to a central service, just export as files? Can they choose &#8220;no derivatives&#8221;? Would the game try to enforce the license, for example by not allowing other users to modify scenes marked as &#8220;no derivatives&#8221;? These are some of the issues I&#8217;ll probably have to think about eventually. But, thankfully, not today.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jacius.info/2012/04/17/ambienome-brain-dump/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Rubyist&#8217;s Impressions of Common Lisp</title>
		<link>http://blog.jacius.info/2012/04/04/a-rubyists-impressions-of-common-lisp/</link>
		<comments>http://blog.jacius.info/2012/04/04/a-rubyists-impressions-of-common-lisp/#comments</comments>
		<pubDate>Wed, 04 Apr 2012 22:26:34 +0000</pubDate>
		<dc:creator>John Croisant</dc:creator>
				<category><![CDATA[Lisp]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[lisp]]></category>

		<guid isPermaLink="false">http://blog.jacius.info/?p=872</guid>
		<description><![CDATA[It has been nearly 6 months since I dove into Common Lisp. I have been studying and/or using Common Lisp almost every day, working on Ambienome and related code. So, I wanted to take some time to document my observations, feelings, and impressions of Common Lisp at this time. Be advised that this is a [...]]]></description>
			<content:encoded><![CDATA[<p>It has been nearly 6 months since I dove into Common Lisp. I have been studying and/or using Common Lisp almost every day, working on <a href="http://blog.jacius.info/category/projects/ambienome/">Ambienome</a> and related code. So, I wanted to take some time to document my observations, feelings, and impressions of Common Lisp at this time. Be advised that this is a fairly long post, even though I have trimmed out a lot of details and examples to keep it from growing even longer. (Apparently I have a <em>lot</em> of impressions!)</p>
<p>I have approached CL from nearly 8 years of programming in Ruby. I mention this because my experience with Ruby has certainly colored my impressions of CL, and many of my observations are about how CL compares to Ruby. <span id="more-872"></span></p>
<h2>Different Yet Similar</h2>
<p>Overall, I&#8217;d rate Ruby and CL as being about equal, on my personal, subjective scale of programming language goodness. They differ in many ways, both good and bad, but it feels to me like the differences balance out. So, the two languages are <em>different</em>, but neither one is clearly <em>superior</em>.</p>
<p>On a conceptual level, the two languages are actually fairly similar. They are certainly more similar to each other than either one is to a language like C, for example. They both have an interactive prompt, automatic memory management and garbage collection, first-class functions, anonymous functions and closures, arrays and hash tables, mutable strings, arbitrarily large integers, namespaces (modules in Ruby, packages in CL), and class-based <abbrev title="Object Oriented Programming">OOP</abbrev> systems that don&#8217;t force you into an OOP style. There are probably many other smaller similarities that I could think of if I took the time. (A dedicated Lisper would point out that many of these concepts originated in some Lisp dialect or another.)</p>
<p>Naturally, the details of many of these things are different. For example, CL&#8217;s packages work very differently than Ruby&#8217;s modules, despite fulfilling the same basic purpose. But in general, the concepts in each language are similar enough that knowing one language will make it significantly easier to learn the other.</p>
<h2>Strengths (In Brief)</h2>
<p>There are several aspects of Ruby that I feel are especially strong relative to Common Lisp. Stated briefly, they are:</p>
<ul>
<li>Community (active, supportive, sharing)</li>
<li>Approachability (easy for someone new to get started)</li>
<li>Convenience (many useful constructs and patterns are built in)</li>
<li>Consistency of the object model (e.g. everything has a class)</li>
<li>Wide variety of available libraries (both standard and installable)</li>
</ul>
<p>Of course, Common Lisp has several areas where I feel it has the advantage:</p>
<ul>
<li>Flexibility (macros and read macros)</li>
<li>Generic functions system</li>
<li>Conditions and restarts</li>
<li><abbrev title="Integrated Development Environments">IDEs</abbrev>, built-in documentation</li>
<li>Optimization hints</li>
</ul>
<p>I describe these in more detail near the end of this post.</p>
<h2>Weaknesses</h2>
<p>I&#8217;d like to be able to make a list of the areas each language is weak, but I&#8217;m too close to Ruby because of my years of use, yet also distant from it because I haven&#8217;t used it actively for perhaps a year. Both of those situations affect my perspective and make it hard to see Ruby&#8217;s real flaws.</p>
<p>Of course, Ruby has some weird bits of syntax (like <code>{|args| ... }</code> code blocks) and other quirks, but no more so than most languages, including CL. Ruby&#8217;s performance is traditionally a bit weak, but that varies across implementations, and is improving in leaps and bounds. The community is generally pretty great, although I find the &#8220;<a href="http://www.businessweek.com/articles/2012-03-01/the-rise-of-the-brogrammer">brogrammer</a>&#8221; trend in some parts of the community to be distasteful and regressive.</p>
<p>My relationship to Common Lisp is a different situation. My eyes are still fresh and I&#8217;m actively using it, so I can see and describe Common Lisp&#8217;s shortcomings pretty clearly. But, I want to emphasize that just because I can still see the flaws in Common Lisp, that doesn&#8217;t mean there are no flaws in Ruby. I&#8217;m sure someone else could point out just as many problems in Ruby as I can in Common Lisp.</p>
<p>So, with that caveat, I&#8217;ll describe what I consider to be Common Lisp&#8217;s problem areas.</p>
<h3>Minor Problem: Batteries Not Included</h3>
<p>Ruby, Python, and other &#8220;batteries included&#8221; languages come with all kinds of nifty features (e.g. networking, regular expressions, XML/JSON/etc. support) right out of the box. A programmer coming to CL from one of those languages might expect CL to be the same way, but it&#8217;s not. Why?</p>
<p>The main reason is that CL has a formal ANSI standard, designed in the 1980s and early 1990s as a way to consolidate several different Lisp dialects. It took 10 years, countless man hours, and hundreds of thousands of dollars in direct expenses to finish the standard. Every detail was weighed and debated to make sure it was acceptable to the many people and groups with a vested interest in the process, such as the vendors who sold implementations of the old dialects.</p>
<p>So basically, only features that were acceptable to everybody were put in the standard. Things that they disagreed about, or that would put too much burden on the implementors, or that didn&#8217;t even exist back then, are not in the standard. Adding a new feature to the standard now would probably take many more years of debate and nitpicking, and would only succeed if practically everybody agreed that it was such a great feature that it is worth the effort. In other words, it would take a miracle and a half.</p>
<p>That is a very different scenario than you have with Ruby/Python/etc., where someone can submit a new feature to the most popular implementation, a core dev likes the features and commits it, and it&#8217;s released in the next version.</p>
<p>So, why is this not a huge deal in Common Lisp?</p>
<p>Well, most features can be written as libraries that you can install when you need them. CL is so flexible that even major changes to the language syntax can be installed as libraries! And with the advent of <a href="http://www.quicklisp.org/">Quicklisp</a>, installing libraries in CL is just as easy as installing gems in Ruby, or eggs in Python.</p>
<p>As for the features that can&#8217;t be written as libraries, individual CL implementations can provide them as extensions. For example, the implementation I use comes with a bunch of goodies that aren&#8217;t in the ANSI standard, such as threading, networking, code coverage and profiling tools, and a foreign function interface (FFI) for wrapping C libraries (such as OpenGL, as I&#8217;m using for Ambienome). If a feature is popular and many implementations provide it, someone will usually create a wrapper library that smooths out the differences between implementations, so that programmers can use the feature without being tied to one particular implementation.</p>
<p>(That&#8217;s an idealized scenario, of course. It doesn&#8217;t always work out so smoothly. Some implementations don&#8217;t add new features very often, if ever. Sometimes an implementation adds a feature in a way that isn&#8217;t compatible with other implementations, making it difficult or impossible to create a portable wrapper library. In such cases, if a programmer really needs the feature, they might target a specific implementation, rather than trying to keep their code portable. If they really need their code to be portable too, they can write code that acts differently for each implementation.)</p>
<p>That process of adding a feature to an implementation, letting other implementations copy it, and writing a wrapper library on top, is far from perfect. But, it&#8217;s faster, less onerous, and more flexible than trying to update the ANSI standard, and the results are usually satisfactory.</p>
<p>So, once you realize the implications of Common Lisp being formally standardized, and find out that there&#8217;s an easy way to install libraries, it&#8217;s not such a big deal that Common Lisp does not come with &#8220;batteries included&#8221;. </p>
<p>But, it&#8217;s still a minor problem that affects new Lispers coming from other languages. It might be possible to alleviate the problem through expectations management. If new Lispers understood from the start that many features are not part of the standard, but nevertheless are readily available as libraries, they wouldn&#8217;t be so surprised and disappointed.</p>
<p>I&#8217;m not sure who would be most effective at this sort of expectations management, though. Implementations? Book authors? Teachers? Bloggers? Wiki editors? IRC and newsgroup participants? I suspect all of the above are already doing it to some degree, yet many newcomers are still surprised. This is one area where having an &#8220;official website&#8221; for Common Lisp might make things easier.</p>
<h3>Moderate Problem: Historical Baggage</h3>
<p>Common Lisp has a lot of historical baggage: things that are done a certain way just because that&#8217;s how they were done in the past, even if they don&#8217;t make much sense nowadays. Perhaps that&#8217;s only natural for a programming language with such a long history. CL itself is nearly 20 years old (or 30, if you count from the first edition of <a href="http://en.wikipedia.org/wiki/Common_Lisp_the_Language"><i class="title">Common Lisp the Language</i></a>), and it inherited baggage from several older Lisp dialects, going all the way back to the original Lisp over 60 years ago.</p>
<p>That&#8217;s not to say that other languages don&#8217;t have some historical baggage of their own. For example, Ruby and many other languages inherit the bizarre old syntax of putting a 0 (zero) in front of a number to interpret it as octal form. (E.g. <code>10</code> means ten, yet <code>010</code> means eight. Surprise!) CL seems to have an especially large amount of baggage, though, and many Common Lispers seem to cling to that baggage rather tightly.</p>
<p>Historical baggage manifests itself in CL in many ways. One way is as individual quirks, like the setq operator. Setq was, I hear, originally invented as shorthand, so you could write <code>(setq x 3)</code> instead of <code>(set (quote x) 3)</code>. But that was before the read macros were available; these days you can type <code>(set 'x 3)</code>, which also means <code>(set (quote x) 3)</code> and is not any more characters than using setq. (Although, setq works a bit differently in CL than in earlier Lisps, so <code>(setq x 3)</code> isn&#8217;t quite the same as either <code>(set (quote x) 3)</code> or <code>(set 'x 3)</code> anymore.) Furthermore, CL has the set<strong>f</strong> operator, which can do everything setq can do and more, so there&#8217;s not really any reason to retain setq. It&#8217;s just historical baggage, kept around because that&#8217;s what they used in the old days. (Setq is still quite widely used today, usually with the rationale that it expresses the programmer&#8217;s intentions more clearly because it can do fewer things than setf.)</p>
<p>Historical baggage also manifests as old idioms that affect many parts of the language. Take for example the idiom of adding &#8220;p&#8221; to the names of predicate functions, functions that check something and return true or false (actually t or nil, another bit of historical baggage). For example, <code>(evenp x)</code> returns true if the value of x is an even number. It could have been <code>(even? x)</code>, which I would argue is significantly clearer. But, Lispers used &#8220;p&#8221; in the old days, so (most, but not all) predicate functions in the CL standard use &#8220;p&#8221;, and therefore most Common Lispers still use &#8220;p&#8221; when they write their own predicate functions today.</p>
<p>Historical baggage also manifests itself as strange inconsistencies and curiosities in the underlying architecture. For example, Common Lisp has <em>types</em>, which it inherited from older Lisp dialects. It also has <em>classes</em>, which were added fairly late in the ANSI standardization process. Types and classes are very similar in many ways, but just different enough that they can&#8217;t be unified without breaking tons of old code. As a result, CL has both systems existing simultaneously, where each class has a corresponding type, but not all types have a corresponding class. Some features use types (like function and variable type declarations), while other features use classes (like generic function dispatching). I suppose the standards committee made the right choice given the circumstances back then, to avoid breaking all that old code. But, it is nevertheless historical baggage that all Common Lispers still carry nearly 20 years later.</p>
<p>Finally, historical baggage manifests itself as concepts and features that were useful many decades ago, but are pretty much obsolete today (and in some cases were already obsolete when the standard was written). For example, every symbol in Common Lisp has &#8220;properties&#8221;, a list of data that the symbol carries around in its guts. But nowadays, it would often be just as efficient to store that data in hash tables with the symbol as the key, and doing so would entirely avoid the possibility of two unrelated pieces of code coincidentally using the same property names. But, Lisp has had symbol properties since the very beginning, so Common Lisp has symbol properties too, along with the half-dozen functions used to manipulate them. (Symbol properties don&#8217;t seem to be used much anymore.)</p>
<p>These kinds of historical baggage aren&#8217;t a <em>serious</em> problem, because for the most part you can ignore the obsolete features, and either cover up or learn to live with the weird idioms and inconsistencies. But it is a moderate problem, because this historical baggage adds to the mental burden of every Common Lisp programmer in the world. (There are many, many other examples of historical baggage that I have omitted for the sake of brevity.)</p>
<p>It&#8217;s especially burdensome for new Lispers. Year after year, new Lispers have to go through a kind of rite of passage, learning the obscure idioms of years gone by, separating the useful features from the cruft, and trying to remember function names that seem arbitrary and inconsistent. Many of them give up and leave for other languages because of needless obstacles (this being just one of many they face). Some of them could have contributed a lot to the community over time, if only &#8220;the wall&#8221; hadn&#8217;t been built so high.</p>
<h3>Serious Problem: The Community Atmosphere</h3>
<p>That brings me to the most serious problem Common Lisp has: the community&#8217;s atmosphere, its prevailing moods and attitudes. This is such an important topic that it deserves its own post, but I&#8217;ll summarize the problem here.</p>
<p>I&#8217;ll admit that I started learning CL with the knowledge that many people (usually people who tried to join the community but were repelled) consider the community to be antagonistic, especially towards newcomers. So, I may be exhibiting some confirmation bias: seeing what I expected to see, and tending to ignore evidence to the contrary. But with issues like this, the widespread <em>perception</em> of a problem can be just as damaging as the reality of the problem itself.</p>
<p>I suspect that most people who use Common Lisp, as with any language, are probably decent folk who just want to write nifty code without a lot of fuss or drama. But these people are not very visible or active in community discussion venues (e.g. the comp.lang.lisp newsgroup or #lisp IRC channel). They&#8217;re off somewhere else, writing their nifty code in peace.</p>
<p>Alas, many of the people who <em>are</em> highly visible and active can best be characterized as &#8220;toxic&#8221;. These are people who, because of the nature of their personalities and attitudes, have a consistently negative emotional effect on the people they interact with. Without necessarily intending to do so, they have created a constant miasma of disrespect, nitpicking, defensiveness, discouragement, and intolerance. This toxic atmosphere permeates the entire culture, gradually driving less toxic people into seclusion or to other languages, or souring their moods such that they become toxic as well. This leaves an even higher concentration of toxicity, affecting even more people, on and on.</p>
<p>Is it possible to reverse this trend? I don&#8217;t know. It may be too late. If it can be reversed, I suspect the way to do it is for the quiet, decent folk to put on emotional hazmat suits and start being more active in the community. Participate in discussions, help new Lispers, and discourage toxic behavior by privately and tactfully informing people about the effect they have. Reducing the toxicity of the community atmosphere would be a major culture shift, but with a sustained effort it might be possible to create a more healthy and positive atmosphere.</p>
<p>I can&#8217;t help but compare this to the Ruby community&#8217;s notion of <abbrev>MINSWAN</abbrev> (Matz Is Nice So We Are Nice), and wish there were more positive role models in the CL community to set a good example. Most of the people who are revered in the CL community are quite intelligent and knowledgeable about CL and computer science, but are also very toxic. The motto for this community would be something along the lines of <abbrev>NaWTSWAT</abbrev>: <a href="http://en.wikipedia.org/wiki/Erik_Naggum">Naggum</a> Was Toxic So We Are Toxic. The community discussion venues have become an echo chamber, perpetuating and reinforcing the notion that it is okay to be derogatory and inflammatory, as long as you are intelligent or know a lot about CL. The people who disagree with this attitude tend to give up in disgust and either leave or stop talking, so you won&#8217;t hear many dissenting opinions about that from the people who remain.</p>
<p>This may seem like a gloomy assessment, but the situation is not all bad. There are some awesome people making cool things with Common Lisp, and many people who will try to help as best they can when you have a problem. It&#8217;s just a shame that the predominant attitude is so negative.</p>
<h2>It&#8217;s Not All Bad!</h2>
<p>I have spent many more words so far describing the weaknesses and problems of Common Lisp, than describing its strengths and interesting features. But despite its quirks and baggage and toxic people, Common Lisp is an incredibly flexible and powerful tool for creating software. Ruby may offer a more polished baseline experience, but you can&#8217;t take it as far as you can take CL.</p>
<p>The ANSI Common Lisp standard may stand still, but Common Lisp does not. It is constantly growing and evolving on top of the stable (albeit lumpy and uneven) foundation provided by the standard. For example, <a href="http://common-lisp.net/project/asdf/">ASDF</a> (which is a bit like Rake or Make) was created in 2001, and revolutionized the way CL libraries are defined and loaded. ASDF laid the groundwork for <a href="http://www.quicklisp.org/">Quicklisp</a> (CL&#8217;s analog to RubyGems), created in 2010, to revolutionize the way CL libraries are downloaded and installed. That in turn lays the groundwork for further development and progress.</p>
<h3>Flexibility (Macros and Read Macros)</h3>
<p>One reason CL can keep evolving without needing to change the standard, is the flexibility provided by features like macros and read macros. In addition to the usual small utility macros, I&#8217;ve created macros for Ambienome to implement a <a href="http://blog.jacius.info/2012/01/05/mini-project-proto-slots/">limited form of prototypal inheritance</a>, and extensible object properties. They are somewhat longer than the average macro, but fairly mundane; they merely expand into a few formulaic functions with the details filled in. There are much more complex and interesting things you can do with macros, like the famous (or infamous) <code>loop</code> macro, which implements a specialized mini-language within CL, dedicated to making it easy to write fairly sophisticated code loops. Even the Common Lisp Object System (CLOS), which provides CL&#8217;s class-based OOP system, is largely implemented via some very complex macros. CLOS and loop are both defined in the standard, but they probably could have been implemented as separate libraries. (I&#8217;m guessing that having those things standardized enables implementations to optimize their performance. Or maybe they were just considered fundamental to the language.)</p>
<p>Read macros take flexibility and extensibility even further. They let you write code in CL that reprograms the way CL parses the text of your source code, potentially altering the language in radical ways. One fairly common and not-so-radical use for read macros is adding syntax sugar. For example, the CL standard doesn&#8217;t have a literal syntax for reading or printing hash tables, but thanks to read macros you can <a href="http://frank.kank.net/essays/hash.html">add Ruby&#8217;s hash table syntax to CL</a> in 40 lines of code (or less if you don&#8217;t need the hashrockets and commas). Similarly, you can <a href="http://letoverlambda.com/index.cl/guest/chap4.html#sec_4">add literal syntax for regular expressions</a>, even though regular expressions are provided by libraries like <a href="http://weitz.de/cl-ppcre/">CL-PPCRE</a> instead of being defined in the standard. I don&#8217;t know of any other language where you can think of some syntax that would make the language more expressive or powerful, then add it with just a couple of afternoon hacking sessions.</p>
<h3>Generic Functions</h3>
<p>Next to CL&#8217;s flexibility from macros and read macros, the thing I find most interesting in CL is the generic functions system. Classes in CL don&#8217;t (usually) have methods in the same sense that classes in Ruby do. Instead, CL has generic functions, and each method implements the behavior as it relates to instances of a certain class (or combination of classes). It&#8217;s quite different from Ruby or any other object-oriented language I&#8217;ve used, but very flexible and powerful. I&#8217;d like to write more about the CLOS object model and how it compares to Ruby&#8217;s, but this post is already rather long.</p>
<h3>Conditions and Restarts</h3>
<p>Another interesting feature of CL is its condition system. Conditions are analogous to Ruby&#8217;s exceptions, but much more flexible and powerful. (That seems to be a recurring theme.) Besides raising errors and warnings, you can use conditions to send any kind of signal up the call chain, with the lower-level code possibly providing some &#8220;restarts&#8221;, ways to proceed. Depending on how you set up the restarts, your higher-level code might interrupt the lower-level code like in Ruby, or ignore the signal and resume the lower-level code where it left off, or modify something and <em>then</em> resume, or pretty much anything else you can imagine. I haven&#8217;t had much opportunity to use conditions in a substantial way yet, but I&#8217;m sure they will prove useful as my code matures.</p>
<h3>Integrated Development Environments</h3>
<p>CL also has some nice IDEs. I use Emacs with <a href="http://common-lisp.net/project/slime/"><abbrev title="Superior Lisp Interaction Mode for Emacs">SLIME</abbrev></a>, which is a big step up from my Ruby workflow.  It offers the usual IDE amenities like tab-completion, parameter hints, jumping to function definitions, and looking up documentation (which is stored in each function/macro/etc., not derived from scanning comments like RDoc and YARD do). It also lets you inspect and modify the guts of most objects, which is pretty handy for debugging. And apparently even SLIME pales in comparison to the fancy IDEs provided by some commercial CL implementations.</p>
<h3>Optimization Hints</h3>
<p>Finally, CL has a system for declaring optimization hints to tweak the way the implementation compiles or interprets your code. (These are hints, so the implementation decides what to actually do. Some implementations might just ignore your hints.) Besides optimizing for computational speed, you can optimize for space (compiled code size, and runtime memory use), safety (run-time error checks), compilation speed, and/or ease of debugging. You can also optionally declare the argument and/or return types for functions, which can help the implementation generate even more efficient code. And finally, you can declare that a function can be compiled inline into other code that calls it, which can reduce or eliminate the overhead from function dispatch (this works well for short utility functions). I have read that with the right optimization hints, some implementations can compile number-crunching functions into code that is nearly as performant as C code. I&#8217;m pretty relaxed about performance (I used Ruby for over 7 years, after all!), but it&#8217;s nice to have extra tools available for dealing with bottlenecks.</p>
<h2>Final Thoughts</h2>
<p>So, those are my impressions of Common Lisp after 6 months of focused study and use. There are a lot of good things about CL, but also some really bad. It&#8217;s a pretty amazing language, but has some warts and flaws. The community is mostly decent people, but anyone who tries to participate in discussion ends up choking in the toxic atmosphere. The warts and flaws can be covered up or worked around pretty easily, but creating a more healthy community atmosphere seems nearly impossible. But I hope it can happen somehow, because it&#8217;s a shame to see the language being held back like this.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jacius.info/2012/04/04/a-rubyists-impressions-of-common-lisp/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>Physics Engine and Object Selection</title>
		<link>http://blog.jacius.info/2012/02/27/physics-engine-and-object-selection/</link>
		<comments>http://blog.jacius.info/2012/02/27/physics-engine-and-object-selection/#comments</comments>
		<pubDate>Tue, 28 Feb 2012 00:15:38 +0000</pubDate>
		<dc:creator>John Croisant</dc:creator>
				<category><![CDATA[Ambienome]]></category>
		<category><![CDATA[Lisp]]></category>

		<guid isPermaLink="false">http://blog.jacius.info/?p=859</guid>
		<description><![CDATA[This is the second part of my post about what I&#8217;ve been working on lately. In the first part, I talked about data structures and serialization. In this post, I talk about the physics engine and object selection via mouse picking. For Ambienome&#8217;s physics engine, I&#8217;m using SquirL, a Common Lisp port of the popular [...]]]></description>
			<content:encoded><![CDATA[<p>This is the second part of my post about what I&#8217;ve been working on lately. In the first part, I talked about <a href="http://blog.jacius.info/2012/02/24/data-structures-and-serialization/">data structures and serialization</a>. In this post, I talk about the physics engine and object selection via mouse picking.</p>
<p>For Ambienome&#8217;s physics engine, I&#8217;m using <a href="https://github.com/sykopomp/squirl">SquirL</a>, a Common Lisp port of the popular <a href="http://chipmunk-physics.net/">Chipmunk</a> 2D game physics engine. I&#8217;m not far enough along yet to know how well it performs in my own game, but from running the demos, it certainly seems performant enough for my purposes. If it turns out to be somewhat sluggish, many Common Lisp implementations can perform some pretty aggressive optimization, given the right type declarations. As a last resort, I could create an FFI binding to the actual Chipmunk library, although that might not be any faster than a well-optimized Common Lisp port. One benefit of a binding to Chipmunk would be using its new features that have not been ported to SquirL (which hasn&#8217;t been updated in 2 years).</p>
<p><span id="more-859"></span> As I explained in the previous post, a creature in Ambienome is composed of a hierarchy of &#8220;parts&#8221;, or shapes. This hierarchical nature means that a child&#8217;s transformation (position, rotation, scale) are defined relative to the parent, and the parent&#8217;s transformation affects all the children (and the children&#8217;s children, and so on). But, SquirL/Chipmunk only has the concept of a body composed of a flat list of shapes; they don&#8217;t understand hierarchies. So, when generating the physical representation of a creature, the code must &#8220;walk&#8221; the hierarchy, converting each part&#8217;s parent-relative transformation to a root-relative transformation.</p>
<p>Actually, though, not every creature will be made of a single physical body. In SquirL/Chipmunk, each body is a <em>rigid</em> body, meaning its component shapes are not supposed to move relative to each other. Physical joints (springs, pivots, etc. &mdash; &#8220;constraints&#8221; in SquirL/Chipmunk parlance) only connect bodies, not shapes within a body. So, any creature that has parts connected via joints will have to be split up into multiple physical bodies. This would happen automatically behind the scenes, of course; Ambienome users don&#8217;t need to care about the underlying physical representation.</p>
<p>One potential pitfall is that if a part&#8217;s transformation is changed, the physical representation of it and everything lower in the hierarchy must be updated or regenerated. If a part is changing often, that could be a significant performance hit, and also cause problems with the physics engine. So, it may be that some creatures will have to be split up into multiple physical bodies, even if they don&#8217;t use explicit joints. A part that will move or rotate often could be automatically split into a separate physical body, then connected to the main body via a joint (or combination of joints) to hold it in place.</p>
<p>Unfortunately, SquirL/Chipmunk cannot handle scale changes in such a graceful way. So, it would still be necessary to regenerate the physical shapes after a scale change, with all the performance and simulation stability issues that entails. Of course, if that turns out to be a big problem, the ability for behaviors to change scale could be limited in some way. I might even disable it at first, then only add that ability later if it can be done without causing problems.</p>
<p>Two other things that I&#8217;ll need to address with regards to the physics engine, are static creatures and phantom creatures. Static creatures are creatures that don&#8217;t move, but other creatures can collide and bounce off of them. SquirL and Chipmunk both support fairly simple (but different) ways of accomplishing that, so the technical side is not a problem. But, I&#8217;ll have to give some thought to how this option is presented to users. For example, is the user able to make a static creature with non-static limbs, like an anemone whose base doesn&#8217;t move, but whose tendrils do? This has some implications about how creatures are built and structured; it may be necessary or desirable to explicitly divide creatures into segments (corresponding to SquirL/Chipmunk bodies), which are then divided into parts (corresponding to SquirL/Chipmunk shapes).</p>
<p>Phantom creatures are creatures that do not have a solid form, do not collide or bounce off other creatures, but can still move around. This can be accomplished easily in SquirL/Chipmunk by putting all phantom creatures on a designated layer (so they will not collide with non-phantom creatures), and putting them in the same group (so they will not collide with other phantom creatures). But, just like static creatures, the concept of phantom creatures has implications about how a creature is structured. Can some parts of the creature be phantom, while others are not? Ideally, this should be allowed, but it does suggest that my current concepts of creatures and parts needs to be reformed.</p>
<p>The final topic for this post is object selection via mouse picking. This isn&#8217;t always related to physics engine, but in this case, I&#8217;m planning to leverage the physics engine to make picking easier. SquirL and Chipmunk both have ways to check what shapes intersect a point, and Chipmunk additionally has ways to check for intersection with a line segment, axis-aligned bounding box, or shape.</p>
<p>This does mean, though, that all possibly selectable creatures must be added to the physics engine. If I used a different technique for mouse picking, only creatures that actually participate in the physics simulation would need to be added. But I don&#8217;t expect this to be much of a problem, because the only creatures that could have stayed out of the simulation would be creatures that are both phantom and static, which I think will be relatively rare.</p>
<p>There are <a href="http://www.opengl.org/resources/faq/technical/selection.htm">several other picking techniques available</a>. Two popular techniques for OpenGL applications are <a href="http://content.gpwiki.org/index.php/OpenGL:Tutorials:Picking">the GL_SELECTION rendering mode</a>, and <a href="http://content.gpwiki.org/index.php/OpenGL:Tutorials:Picking">unique color rendering</a>. These are certainly feasible, but implementing them would take time and effort I could spend on other things, and would add complexity to my code base. So, I&#8217;ll save them as backup plans, in case using the physics engine for mouse picking doesn&#8217;t work out.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jacius.info/2012/02/27/physics-engine-and-object-selection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Data Structures and Serialization</title>
		<link>http://blog.jacius.info/2012/02/24/data-structures-and-serialization/</link>
		<comments>http://blog.jacius.info/2012/02/24/data-structures-and-serialization/#comments</comments>
		<pubDate>Sat, 25 Feb 2012 03:52:26 +0000</pubDate>
		<dc:creator>John Croisant</dc:creator>
				<category><![CDATA[Ambienome]]></category>
		<category><![CDATA[Lisp]]></category>

		<guid isPermaLink="false">http://blog.jacius.info/?p=855</guid>
		<description><![CDATA[Lately, I&#8217;ve been tackling several separate, but interconnected, systems in Ambienome: data structures, serialization, object selection, and the physics engine. These are complex topics, so I&#8217;ve written this in two parts. In this first part, I talk about data structures and serialization, and in the second part I talk about the physics engine and object [...]]]></description>
			<content:encoded><![CDATA[<p>Lately, I&#8217;ve been tackling several separate, but interconnected, systems in Ambienome: data structures, serialization, object selection, and the physics engine. These are complex topics, so I&#8217;ve written this in two parts. In this first part, I talk about data structures and serialization, and in the second part I talk about <a href="http://blog.jacius.info/2012/02/27/physics-engine-and-object-selection/">the physics engine and object selection</a>.</p>
<p>Data structure simply means the way some data is structured or organized, either in memory while the program is running, or when the data is saved to a file or sent over a network. Is it stored in a hash table? An array? An instance of a class? What slots/members does the class have? How are different pieces of data related to each other? And so on.</p>
<p>Serialization is a topic very closely related to data structure. Serialization involves converting from one data structure to a simpler data structure, usually some human-redable text or a raw binary sequence with some specific order or pattern. The reverse process, deserialization, involves converting the simpler data structure back into the original structure (or a similar one). Serialization is most often used when saving data to a file or sending it over a network.</p>
<p>Personally, I consider binary serialization to be a measure of last resort, to be used only when performance is absolutely critical. Binary formats are notoriously fragile and difficult to extend, especially if they are poorly designed.</p>
<p><span id="more-855"></span>(I recently worked on a project where the previous programmer wrote code to &#8220;serialize&#8221; a C struct by copying a chunk of raw bytes from memory and sending it over the network. To &#8220;deserialize&#8221; it, they would &mdash; I kid you not &mdash; copy the bytes into memory and type-cast it to the struct type! They had given absolutely no thought to portability, extensibility, validation, or robustness. And the person who wrote it was ostensibly a professional programmer, and had been paid for the work.)</p>
<p>So, I use human-readable text formats whenever possible. Probably the two most popular formats for this kind of serialization are XML and JSON. But Lisp already has a simple, human-readable, portable, built-in serialization format: S-expressions, the same format used for Lisp code. I&#8217;m still experimenting with the structure, but here&#8217;s an example of a simple scene as it is serialized now:</p>
<p><code>
<pre>
(:instance :scene
 :props nil
 :creatures
 ((:instance :creature
   :name "Creature 1"
   :body
   (:instance :part
    :props
    ((:shape :label "Shape" :value :rectangle)
     (:angle :label "Angle" :type :angle :value 0)
     (:scale :label "Scale" :type :real :value 120)
     (:size :label "Size" :type :vec :value #C(1.0d0 1.0d0))
     (:pos :label "Position" :type :vec :value #C(75.0d0 150.0d0))
     (:depth :label "Depth" :type :real :value 0)
     (:color :label "Color" :type :color :value #(0.7 0.1 0.6))
     (:name :label "Name" :type :string :value nil))
    :children nil))))
</pre>
<p></code></p>
<p>It&#8217;s human-readable, very compact for how much information it expresses, and Lisp intrinsically knows how to read and print it. I might write a little bit of code to get rid of the colons (which indicate Lisp keyword symbols) to make it even easier for humans to read.</p>
<p>I should point out that even though the structure is serialized as lists, the data is actually stored in the program as class instances, arrays, and hash tables. They are converted to lists before being serialized, then inserted back into an array or hash table when deserialized. In addition to making the output easier for humans to read, adding this layer of abstraction means I can change the internal data structure while easily maintaining compatibility with older versions.</p>
<p>Besides decisions about whether to use lists, arrays, hash tables, or whatnot, I&#8217;ve also been experimenting with how the various kinds of objects relate to each other. As it is now, there are three main kinds of objects:</p>
<ul>
<li>Scene objects, which represent a particular scenario of creatures, scene-wide behaviors, and properties such as background color and the scene&#8217;s creator.</li>
<li>Creature objects, which represent a collection of parts with some behaviors and properties such as its name and creator. A creature directly holds a main part, called the body, of which all the other shapes are &#8220;descendants&#8221;.</li>
<li>Parts, which represent a shape, like a circle or triangle, with properties such as its size, color, density. A part can have &#8220;children&#8221;, meaning they are linked together in a hierarchy.</li>
</ul>
<p>One noteworthy thing about these data structures is the way object properties are stored. Instead of storing color, position, size, etc. directly as slots/members of a class instance, they are all stored together in the object&#8217;s &#8220;props&#8221; hash table. This makes it more flexible, as props can be added or removed at any time. At some point, scene creators will be able to add their own props that are used by custom behaviors. For that same purpose, props are stored with metadata about their type, label, and so on.</p>
<p>There&#8217;s another kind of object that I may be adding soon: joints, which are used with the physics engine to connect parts that move independently, but are joined together with a spring, pivot, or whatnot. But, I might just make joints another type of part. I&#8217;ll talk about this and other physics engine stuff in my next post.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jacius.info/2012/02/24/data-structures-and-serialization/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Complicated Code and Creative Blocks</title>
		<link>http://blog.jacius.info/2012/02/02/complicated-code-and-creative-blocks/</link>
		<comments>http://blog.jacius.info/2012/02/02/complicated-code-and-creative-blocks/#comments</comments>
		<pubDate>Thu, 02 Feb 2012 21:01:09 +0000</pubDate>
		<dc:creator>John Croisant</dc:creator>
				<category><![CDATA[Ambienome]]></category>

		<guid isPermaLink="false">http://blog.jacius.info/?p=843</guid>
		<description><![CDATA[The past several weeks have been a struggle, productivity-wise. First, I spent quite a lot of time working on proto-slots. That may seem productive, but the amount of effort I put into polishing and documenting it was way out of proportion to the benefit I would get from it. I think I did a pretty [...]]]></description>
			<content:encoded><![CDATA[<p>The past several weeks have been a struggle, productivity-wise.</p>
<p>First, I spent quite a lot of time working on <a href="https://github.com/jacius/proto-slots">proto-slots</a>. That may seem productive, but the amount of effort I put into polishing and documenting it was way out of proportion to the benefit I would get from it. I think I did a pretty good job on that project, but I also recognize now that I was using it as a way to avoid actually working on Ambienome.</p>
<p>It was about three weeks ago that I realized what was happening, so I tried to force myself to focus on Ambienome. That didn&#8217;t really work, and I just ended up with a serious creative block. I spent about two weeks making almost no progress. My code had been accruing unnecessary complexity, mostly due to exploring a lot of unfamiliar territory (Lisp, and OpenGL), which made it difficult to work on when my motivation was not very high. Each time I would try to focus on Ambienome, I&#8217;d run into some obstacle, grimace, and reflexively go find some way to distract myself. (In hindsight, it was probably not wise to start a challenging new project at the beginning of winter, since my energy levels and motivation always dip during the winter.)</p>
<p>(Those two weeks weren&#8217;t a complete loss, though; I did beat a lot of games! :P If you&#8217;re curious: <a href="http://dungeonsofdredmor.com/">Dungeons of Dredmor</a>, <a href="http://bindingofisaac.com/">The Binding of Isaac</a>, <a href="http://limbogame.org/">Limbo</a>, <a href="http://www.mumbojumbo.com/game/Glowfish/prod370033?technology=WINDOWS">Glowfish</a>, <a href="http://www.swingswingsubmarine.com/games/blocks-that-matter/">Blocks That Matter</a>, and a couple others that I can&#8217;t recall at the moment.)</p>
<p><span id="more-843"></span>I finally broke through the creative block about a week ago, by unplugging the internet, shutting out all distractions, and just tackling my code head-on. I spent 3 days just simplifying and cleaning up my code to make further development feasible. All told, I managed to eliminate 9 classes:</p>
<ul>
<li><code>job</code>, which acted as a central coordinating structure for the OpenGL rendering pipeline. The important functionality was transformed into methods of the <code>program</code> class, which is slightly lower-level coordinating structure for the rendering pipeline. The rest of the code was scrapped.</li>
<li><code>uniform</code> and <code>attribute</code>, which represented OpenGL shader uniforms and attributes. These classes were also reduced into methods of <code>program</code>, and the unnecessary code scrapped.</li>
<li><code>rectangle</code>, <code>triangle</code>, and <code>circle</code>, which represented instances of those geometric shapes. They were reduced into a <code>render-shape</code> generic function, with a method implemented for each shape based on a keyword. For example, to render a circle you&#8217;d do <code>(render-shape :circle ...)</code>. Lisp&#8217;s method dispatching system is pretty handy sometimes!</li>
<li><code>shape</code>, which was the parent class of the three shapes mentioned above. Aside from the rendering code, which (as I said) became methods, this class also stored the shape&#8217;s transformation (position, rotation, scale), and other properties such as color. I moved this functionality to the <code>part</code> class, which represents a creature body part.</li>
<li><code>group</code>, which held multiple shapes that would move together, just like SVG&#8217;s <code>g</code> element. Instead, I decided that it&#8217;s simpler and more intuitive to allow body parts to be parented to other parts. To handle the case of an invisible pivot point, the parent shape can be made invisible, in which case it&#8217;s functionally equivalent to a group.</li>
<li><code>prop</code>, which represented a property of a shape, such as its color. The idea behind this class was that it would contain not only the data, but also some metadata (its type, human-readable name, etc.) that could be used later to generate an appropriate user interface to edit the property. For example, the color property would have some metadata indicating that the data was a color, so it should be edited using a color swatch widget. I decided to just store the data and metadata in hash tables instead.</li>
</ul>
<p>My code is now much leaner and more function-oriented than before, and much more approachable and easier to work with. I actually  eliminated (temporarily, I think) the need for my proto-slots library &mdash; which, after all the work I put into it, is either really funny or really frustrating.</p>
<p>Yesterday and today, I&#8217;ve been making progress (not a great deal, but enough) on new code, specifically the ability to serialize and deserialize creatures and their body parts, so that they can be saved and loaded from file. I&#8217;m nearly done with this, but I&#8217;m not sure yet what I&#8217;ll tackle next.</p>
<p>Perhaps I&#8217;ll try to plot out a more concrete roadmap, start to define and narrow the scope of the game, and lay out some specific tasks and goals. I&#8217;m sure my unorganized, exploratory approach is a significant cause of my slow progress. It would be good to have some concrete milestones to chase after, and maybe even some deadlines to push myself forward. What a radical notion!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jacius.info/2012/02/02/complicated-code-and-creative-blocks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mini-project: proto-slots</title>
		<link>http://blog.jacius.info/2012/01/05/mini-project-proto-slots/</link>
		<comments>http://blog.jacius.info/2012/01/05/mini-project-proto-slots/#comments</comments>
		<pubDate>Thu, 05 Jan 2012 06:35:07 +0000</pubDate>
		<dc:creator>John Croisant</dc:creator>
				<category><![CDATA[Lisp]]></category>
		<category><![CDATA[Projects]]></category>

		<guid isPermaLink="false">http://blog.jacius.info/?p=838</guid>
		<description><![CDATA[I&#8217;ve just released proto-slots, a mini-project I created as part of Ambienome. From the README: proto-slots provides a macro for defining prototypal accessor methods so that CLOS instances will support protoypal inheritance. Prototypal inheritance means that an instance&#8217;s slots can inherit values from another instance, known in these docs as the &#8220;base object&#8221; (but more [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve just released <strong><a href="https://github.com/jacius/proto-slots">proto-slots</a></strong>, a mini-project I created as part of <a href="http://blog.jacius.info/category/projects/ambienome/">Ambienome</a>. From the README:</p>
<blockquote><p>proto-slots provides a macro for defining prototypal accessor methods so that CLOS instances will support protoypal inheritance. Prototypal inheritance means that an instance&#8217;s slots can inherit values from another instance, known in these docs as the &#8220;base object&#8221; (but more commonly known elsewhere as the &#8220;prototype&#8221;).</p></blockquote>
<p>I wrote the first version of what eventually because the def-proto-slots macro to solve a problem I described in my previous post:</p>
<blockquote><p>But, for each shape instance to have its own color (or other such data in the future), each shape instance must have its own job, because the color would be a uniform contained in that job. If I set the color in the base job, all instances of that kind of shape would have the same color. But if each instance has its own job, I lose the benefit of having the vertex data stored in one place.</p>
<p>I solved this by letting a job have a &#8220;parent&#8221;, from which it inherits anything it’s missing, such as a program or elements. For vertex attribs and uniforms, the inheritance works by merging the parent’s list of attribs/uniforms with the child&#8217;s list, with any of the child&#8217;s attribs/uniforms taking precedence when it has the same name as one of the parent&#8217;s.</p></blockquote>
<p>I realized later that I was going to need prototypal inheritance for other parts of Ambienome, too. For example, I&#8217;m pretty sure the creature class will use this pretty heavily. So, I took my ad hoc macro, made it more flexible (it now supports different &#8220;inheritance strategies&#8221;), and polished it up. Along the way I decided to release it as a separate library, to maybe save someone else the trouble of implementing this same sort of thing.</p>
<p>proto-slots is <a href="https://github.com/jacius/proto-slots">available at GitHub</a>, released under the X11/MIT license. If you find a bug, <a href="https://github.com/jacius/proto-slots/issues">make an issue</a>. To submit a patch, fork my repo and send a pull request.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jacius.info/2012/01/05/mini-project-proto-slots/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Colored Shapes</title>
		<link>http://blog.jacius.info/2011/12/17/colored-shapes/</link>
		<comments>http://blog.jacius.info/2011/12/17/colored-shapes/#comments</comments>
		<pubDate>Sat, 17 Dec 2011 23:19:51 +0000</pubDate>
		<dc:creator>John Croisant</dc:creator>
				<category><![CDATA[Ambienome]]></category>

		<guid isPermaLink="false">http://blog.jacius.info/?p=831</guid>
		<description><![CDATA[I got a bit sidetracked while working on creature components, but still ended up making important progress for the overall system. First, I created a new transform class by abstracting and cleaning up the shape class&#8217;s position, angle, and size attributes and methods. I also created a transformable &#8220;mixin&#8221; class, which can be used by [...]]]></description>
			<content:encoded><![CDATA[<p>I got a bit sidetracked while working on creature components, but still ended up making important progress for the overall system.</p>
<p>First, I created a new <code>transform</code> class by abstracting and cleaning up the <code>shape</code> class&#8217;s position, angle, and size attributes and methods. I also created a <code>transformable</code> &#8220;mixin&#8221; class, which can be used by any class that has a transform. (Lisp doesn&#8217;t have mixins in the same sense that Ruby does, but since Lisp supports multiple inheritance, you can get more or less the same effect by designing a class in a mixin-ish style.) The transformable class provides accessors for the transform&#8217;s position, angle, and size, so that you can treat them as if they were direct slots of the object holding the transform.</p>
<p>Next, I decided to enhance the shape class so that shapes can have a color. This turned out to be somewhat challenging, because of how I had designed the OpenGL wrapper classes.</p>
<p><span id="more-831"></span>I have a <code>job</code> class that holds a program object (which is a collection of compiled shaders linked together) and the vertex attribs, uniforms, and elements used to render a certain thing (such as a shape). For memory efficiency, each kind of shape (rectangle, triangle, or circle) has a base job which holds the generated vertex data and elements. </p>
<p>But, for each shape instance to have its own color (or other such data in the future), each shape instance must have its own job, because the color would be a uniform contained in that job. If I set the color in the base job, all instances of that kind of shape would have the same color. But if each instance has its own job, I lose the benefit of having the vertex data stored in one place.</p>
<p>I solved this by letting a job have a &#8220;parent&#8221;, from which it inherits anything it&#8217;s missing, such as a program or elements. For vertex attribs and uniforms, the inheritance works by merging the parent&#8217;s list of attribs/uniforms with the child&#8217;s list, with any of the child&#8217;s attribs/uniforms taking precedence when it has the same name as one of the parent&#8217;s. It&#8217;s wonderfully easy to do that in Lisp:</p>
<pre><code>(union (attribs parent) (own-attribs job)
       :key #'name :test #'string=)</code></pre>
<p>This code takes the attribs list from the parent, including any attribs the parent itself inherits from <em>its</em> parent, and the list of attribs belonging directly to the job, and performs a set union of those two lists, which discards duplicates. But what is a &#8220;duplicate&#8221;? By providing the <code>:key #'name</code>, I&#8217;m telling it to call the <code>name</code> function on each attrib, and then check the names to see if they are duplicates. The <code>:test #'string=</code> part tells it to use the <code>string=</code> function, which performs case-sensitive string comparison, to decide if the two names are the same. The result is that if an attrib in the parent&#8217;s list and an attrib in the child&#8217;s list have the same name, only the child&#8217;s is used (since it is given as a later argument to the <code>union</code> function).</p>
<p>While doing this, I noticed that the inheritance code was exactly the same for attribs and uniforms, except for the word &#8220;attrib&#8221; or &#8220;uniform&#8221;. So, I wrote a fairly simple, albeit long, macro to keep things <abbrev title="Don't Repeat Yourself">DRY. Then I wrote shorter macro to reduce the redundancy in the simpler inheritance behavior for the other slots, which only inherit from the parent if their slot is empty/null, but don&#8217;t have to perform any merging.</p>
<p>Now that jobs can have a parent, I can use each shape class base job (the job containing the vertex data and elements) as the parent for each shape instance&#8217;s job (the job containing the color and other instance-specific data). So, the instance&#8217;s job can inherit the vertex data and elements, while still having its own color. And later, I&#8217;ll be able to have base jobs at different levels of detail, and easily change the instances&#8217; parents whenever I want to change their level of detail.</p>
<p>After a bit more work, I finally had support for different colors in each shape instance. Victory!</p>
<p><img src="http://blog.jacius.info/wp-content/uploads/2011/12/colored_shapes.png" alt="Screenshot of a purple square, blue triangle, and orange circle." title="Colored Shapes" width="406" height="326" class="aligncenter size-full wp-image-832" /></p>
<p>It was a long detour, but my code base is much better for all the work. Now I can <em>finally</em> get around to shape groups and creature components!</abbrev></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jacius.info/2011/12/17/colored-shapes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Shape Mesh Progress</title>
		<link>http://blog.jacius.info/2011/12/09/shape-mesh-progress/</link>
		<comments>http://blog.jacius.info/2011/12/09/shape-mesh-progress/#comments</comments>
		<pubDate>Fri, 09 Dec 2011 18:26:13 +0000</pubDate>
		<dc:creator>John Croisant</dc:creator>
				<category><![CDATA[Ambienome]]></category>

		<guid isPermaLink="false">http://blog.jacius.info/?p=826</guid>
		<description><![CDATA[Yesterday, I completed the code to generate triangle and circle meshes: The triangle looks like it&#8217;s too small, but it fits perfectly in the circle, and the circle fits perfectly in the square. Yay, geometry! Of course, when building a creature, they can be scaled to whatever size you like, and the algorithms can produce [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday, I completed the code to generate triangle and circle meshes:</p>
<p><img src="http://blog.jacius.info/wp-content/uploads/2011/12/meshes.png" alt="Screenshot of a rectangle mesh, a triangle mesh, and a circle mesh." title="Meshes" width="406" height="326" class="aligncenter size-full wp-image-828" /></p>
<p>The triangle looks like it&#8217;s too small, but it fits perfectly in the circle, and the circle fits perfectly in the square. Yay, geometry! Of course, when building a creature, they can be scaled to whatever size you like, and the algorithms can produce meshes at any level of detail. Eventually, I&#8217;ll make it so the game automatically adjusts the level of detail based on the shape&#8217;s size on the screen.</p>
<p>As I mentioned in the previous post, these aren&#8217;t the only shapes that will be available, but they are enough to let me move on to other things. One of the core concepts of Ambienome is that I can program new shapes later, even after the game has been released. If I&#8217;m feeling really clever, I could probably leverage Lisp&#8217;s power to allow users to program new kinds of shapes, too. That&#8217;s not a high priority, though.</p>
<p>Today I&#8217;ll start code-sketching the concept of components and creatures. A creature is built from one or more components, which are basically shapes with some associated behavior. Components can be grouped to move together, and groups can contain other groups, so it&#8217;s essentially a &#8220;tree&#8221; (hierarchy) of transformation nodes, with each &#8220;leaf&#8221; being a shape. This is the same concept as grouping in SVG or Flash, or parenting in 3D software like Blender or Maya.</p>
<p>After weeks of just studying and debugging OpenGL, it sure is nice to be making visible progress again!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jacius.info/2011/12/09/shape-mesh-progress/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Adventures with the OpenGL shader pipeline</title>
		<link>http://blog.jacius.info/2011/12/07/adventures-opengl-shader-pipeline/</link>
		<comments>http://blog.jacius.info/2011/12/07/adventures-opengl-shader-pipeline/#comments</comments>
		<pubDate>Wed, 07 Dec 2011 18:31:41 +0000</pubDate>
		<dc:creator>John Croisant</dc:creator>
				<category><![CDATA[Ambienome]]></category>

		<guid isPermaLink="false">http://blog.jacius.info/?p=812</guid>
		<description><![CDATA[For the past several weeks, I&#8217;ve been learning &#8220;modern&#8221; OpenGL programming practices, by which I mean using a GLSL shader pipeline with vertex and fragment shaders. Even before starting Ambienome, I was already somewhat familiar with the old OpenGL &#8220;fixed function pipeline&#8221;, using glBegin/glEnd, glColor, glVertex, etc. Ambienome is going to be visually simple enough [...]]]></description>
			<content:encoded><![CDATA[<p>For the past several weeks, I&#8217;ve been learning &#8220;modern&#8221; OpenGL programming practices, by which I mean using a <a href="https://en.wikipedia.org/wiki/GLSL">GLSL</a> shader pipeline with vertex and fragment shaders.</p>
<p>Even before starting Ambienome, I was already somewhat familiar with the old OpenGL &#8220;fixed function pipeline&#8221;, using glBegin/glEnd, glColor, glVertex, etc. Ambienome is going to be visually simple enough that I probably could have used the fixed function pipeline, but I decided to learn the shader pipeline to improve my knowledge and skills, to allow nicer visual effects, and to leverage the GPU&#8217;s number-crunching power as much as I can.</p>
<p>Grokking the shader pipeline was a challenge. There are many separate concepts to learn, and then you must understand how they fit together. Also, there are fewer learning resources for the shader pipeline than there are for the older fixed function pipeline. I relied mostly on <a href="http://duriansoftware.com/joe/An-intro-to-modern-OpenGL.-Table-of-Contents.html">Joe Groff&#8217;s &#8220;An intro to modern OpenGL&#8221; article series</a>, but if I were doing it over again, I might try to find a good book. Unfortunately, the selection is somewhat thin. I&#8217;m considering <a href="http://www.amazon.com/OpenGL-Shading-Language-Randi-Rost/dp/0321637631/"><i>OpenGL Shading Language</i><i></i></a> (the so-called &#8220;Orange Book&#8221;) or the <a href="http://www.amazon.com/OpenGL-ES-2-0-Programming-Guide/dp/0321502795/"><i>OpenGL ES 2.0 Programming Guide</i></a>. (OpenGL ES 2.0 is conceptually very similar to the OpenGL shader pipeline, and also very similar to WebGL.) Unfortunately, the reviews suggest those two are not very well written, organized, or proofread. <a href="http://www.amazon.com/Real-Time-Rendering-Third-Tomas-Akenine-Moller/dp/1568814240/"><i>Real-Time Rendering</i></a> looks like it might provide a good high-level understanding of shaders and rendering, but it&#8217;s not specific to OpenGL or GLSL, and I&#8217;m not really interested in advanced photorealistic shader effects. Maybe if there are any book stores still open in this town, I&#8217;ll see if any of these books are on the shelf so I can assess them before I buy.</p>
<p>Anyway, even after I had scraped together a modest understanding of the concepts behind the shader pipeline, applying that knowledge in practice took longer than I anticipated. It was fairly frustrating at times, partly due to some (minor) shortcomings of cl-opengl and lispbuilder-sdl, and partly due to me misinterpreting some vague parts of the OpenGL documentation. There were many times when I felt like putting the shader pipeline aside, and just using the fixed function pipeline for a while, so I could keep my momentum up. But I stubbornly stuck with it, and now I&#8217;ve got a working, reusable rendering framework built atop the shader pipeline. Huzzah!</p>
<p>My next task is to write code to algorithmically generate mesh data for several geometric primitives. Yesterday, I finished the code for a rectangle mesh built from triangle strips (well, actually one long strip with degenerate triangles connecting each row). Here&#8217;s a screenshot of a 10&times;10 rectangle mesh rendered in wireframe mode:</p>
<p><img src="http://blog.jacius.info/wp-content/uploads/2011/11/rectangle_mesh.png" alt="Screenshot of a rectangle mesh" title="Rectangle Mesh" width="406" height="326" class="aligncenter size-full wp-image-809" /></p>
<p>It&#8217;s not much to look at in itself. I could have achieved that in an afternoon using the fixed function pipeline! But that humble mesh, rendered here using the simplest possible vertex and fragment shaders, represents weeks of learning. Now that I have the basics working, I can write more interesting shaders to morph the shape and create cool visual effects. For example, Ambienome takes place underwater, so I&#8217;ll probably write a shader to make things sway and ripple as if they were being affected by a water current.</p>
<p>Next, I&#8217;ll be writing the code for a triangle mesh, and then a circle mesh. I have plans for more shapes, like teardrop, leaf, ring (circle with a hole in the middle), and tentacle (a Bézier curve with thickness controlled by another Bézier curve). But, I&#8217;m going to save those for later. Once I&#8217;ve got rectangle, triangle, and circle, I&#8217;m going to take a step back from the low-level foundation for a while, and start fleshing out higher-level concepts like components, creatures, and scenes.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jacius.info/2011/12/07/adventures-opengl-shader-pipeline/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ambienome &#8211; Technology</title>
		<link>http://blog.jacius.info/2011/11/13/ambienome-technology/</link>
		<comments>http://blog.jacius.info/2011/11/13/ambienome-technology/#comments</comments>
		<pubDate>Sun, 13 Nov 2011 06:24:45 +0000</pubDate>
		<dc:creator>John Croisant</dc:creator>
				<category><![CDATA[Ambienome]]></category>
		<category><![CDATA[Lisp]]></category>

		<guid isPermaLink="false">http://blog.jacius.info/?p=766</guid>
		<description><![CDATA[In my previous post, I described the concept and roadmap for my new project, Ambienome. In this post, I&#8217;ll be describing the technology (programming language and libraries) I&#8217;m using, and why I chose them. Even though I have seven years of experience with Ruby, and my own game library, Rubygame, already available and ready to [...]]]></description>
			<content:encoded><![CDATA[<p>In my <a href="http://blog.jacius.info/2011/11/04/new-project-ambienome/">previous post</a>, I described the concept and roadmap for my new project, Ambienome. In this post, I&#8217;ll be describing the technology (programming language and libraries) I&#8217;m using, and why I chose them.</p>
<p>Even though I have seven years of experience with Ruby, and my own game library, Rubygame, already available and ready to use, I&#8217;ve decided not to write Ambienome in Ruby. Instead, I&#8217;m writing it in Common Lisp, using OpenGL and OpenAL for graphics and audio. <span id="more-766"></span></p>
<h3>Libraries</h3>
<p>OpenGL and OpenAL were natural choices, since they&#8217;re free, cross-platform, and widely supported with pretty much any programming language. I would have chosen these no matter what language I settled on.</p>
<p>OpenGL doesn&#8217;t provide window management or input event processing, though, so I&#8217;ll need another library to handle that. The main choices for that are <a href="http://www.libsdl.org/">SDL</a>, <a href="http://www.glfw.org/">GLFW</a>, and GLUT.</p>
<p>GLUT is a very popular and widely supported framework, but I don&#8217;t like how you have to shape your entire program structure around GLUT&#8217;s expectations, so I quickly dismissed it. SDL is also popular, but my years of experience with it have made me keenly aware of its shortcomings. So, I decided to try GLFW first.</p>
<p>GLFW is pretty nice, like a less obtrusive version of GLUT. I played around with it long enough to create an abstraction layer for opening and closing the window, but then discovered that GLFW currently has no API for setting the window&#8217;s icon. That may seem like a minor detail, but it was enough to nudge me into reconsidering SDL.</p>
<p>Two other points in SDL&#8217;s favor are that I&#8217;m already familiar with it &mdash; unlike everything else about this project! &mdash; and that SDL 1.3 will have support for multi-touch devices, and possibly multiple mice, both of which could provide some cool ways of interacting with the game. SDL 1.3 hasn&#8217;t been released yet (after many years&#8230;), but I might try taking a snapshot of the development repository, and working with that.</p>
<p>So, I ported the window abstraction layer from GLFW to SDL (1.2), and added an input event abstraction layer. I&#8217;m not entirely happy with it, so I might reevaluate GLFW (or even GLUT, since I&#8217;ve read that freeglut and Apple&#8217;s GLUT let you avoid the glutMainLoop function). But for now, SDL will be enough while I figure out the challenging new stuff with OpenGL and OpenAL.</p>
<p>One final library worth mentioning is <a href="http://www.clutter-project.org/">Clutter</a>, which I&#8217;m considering using to create the in-game GUI. When it gets to that point, I&#8217;ll try Clutter, then look into alternative libraries if Clutter doesn&#8217;t work out. As a last resort, I could just roll my own GUI widgets, but I&#8217;d rather avoid that if I can.</p>
<h3>Lisp</h3>
<p>OpenGL and OpenAL are pretty popular, &#8220;safe&#8221; choices of technology for game development. There are countless web articles, tutorials, books, and other learning resources available, and many experienced programmers I could turn to for help if needed. Both libraries are available on Linux, Mac, and Windows, and have bindings for many programming languages. There&#8217;s nothing particularly surprising or unusual about using OpenGL or OpenAL.</p>
<p><a href="http://www.lisperati.com/logo.html"><img src="http://blog.jacius.info/wp-content/uploads/2011/11/lisplogo_fancy_128.png" alt="The Lisp Alien Mascot; Made with secret alien technology" title="Lisp Alien" width="128" height="111" class="alignleft size-full wp-image-777" /></a></p>
<p>The choice to use Common Lisp, on the other hand, is likely to raise a few eyebrows. After all, it&#8217;s <a href="http://lispers.org/">secret alien technology</a> powered by excessive parentheses!</p>
<p>Lisp, despite its elegance and power, is not nearly as commonly used for game programming as the C language family (C++, C#, Java, etc.), Python, or probably even Ruby. If I had to speculate as to why Lisp has a low adoption rate among game programmers, I&#8217;d cite the usual factors that affect Lisp&#8217;s adoption rate in general: difficulty getting started (choosing and installing a Lisp implementation and IDE, finding good tutorials, etc.), the &#8220;strange&#8221; syntax, Lisp&#8217;s reputation as being more academic than practical, and the Lisp community&#8217;s reputation (whether deserved or not) for being somewhat elitist and unfriendly. Also, many game programmers are obsessed with raw performance, as if brute-force number crunching was the key ingredient in making a fun game. Those programmers will usually stick with C or C++, and dismiss anything else as being &#8220;too slow&#8221;.</p>
<p>But, I don&#8217;t particularly care about Lisp&#8217;s popularity or why other people like or dislike it. I care about having an interesting, powerful language that fits the project well.</p>
<ul>
<li>Like Ruby, Python, etc., Lisp promotes rapid prototyping with concise and flexible code, and sustains <em>creative flow</em> in a way &#8220;stop-and-compile&#8221; languages like C cannot.</li>
<li>Common Lisp can be compiled to native executables, and I can declare optimizations for those situations where number crunching efficiency is needed, such as generating custom audio data.</li>
<li>Lisp&#8217;s notion of &#8220;code as data&#8221; should work well with the concept of expressing behaviors as objects, and saving each creature&#8217;s behavior in a file.</li>
<li>Lisp&#8217;s macro and package systems should make it really easy to create a safe, simple, and efficient domain-specific language to allow users to define new creature parts and behaviors.</li>
<li>Lisp is a novel language to me, so this project is sure to be an interesting learning experience!</li>
</ul>
<p>Before settling on Common Lisp, I also considered CoffeeScript and Clojure. CoffeeScript (using HTML5 Canvas and Audio elements) was very tempting because of the ease of deployment and cross-platform compatibility. But, HTML5 does not yet have a workable API for generating and manipulating audio data, and running in a browser would also limit my options for player-to-player file sharing and multiplayer gameplay.</p>
<p>As for Clojure: it&#8217;s a really interesting Lisp, and the ability to use Java libraries and compile to Java bytecode could be useful. But, learning to write a game using only immutable data structures and <abbrev title="Software Transactional Memory">STM</abbrev>/agents would be a bit <em>too much</em> of a novel learning experience, and this project is going to be a lot to wrap my head around already. Also, Clojure&#8217;s strengths, such as safe multithreading, don&#8217;t provide much of a practical benefit to this particular project.</p>
<p>So far, I&#8217;m really enjoying Common Lisp. I&#8217;ve been reading <a href="http://gigamonkeys.com/book/">Practical Common Lisp</a>, which is a really excellent resource for learning Common Lisp, and available online at no cost. I&#8217;m certainly not a Lisp guru yet, but I can already feel the amazing expressive power and freedom Lisp provides. This is sure to be an interesting project!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jacius.info/2011/11/13/ambienome-technology/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

