<?xml version='1.0' encoding='UTF-8'?><rss xmlns:atom='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:thr='http://purl.org/syndication/thread/1.0' version='2.0'><channel><atom:id>tag:blogger.com,1999:blog-5488893796912675313</atom:id><lastBuildDate>Sun, 21 Mar 2010 18:53:06 +0000</lastBuildDate><title>CPU Dreams</title><description></description><link>http://www.cpudreams.com/</link><managingEditor>fernando@cpudreams.com (Fernando Zapata)</managingEditor><generator>Blogger</generator><openSearch:totalResults>5</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-5488893796912675313.post-5115849554256689499</guid><pubDate>Thu, 18 Feb 2010 01:04:00 +0000</pubDate><atom:updated>2010-02-17T19:13:40.066-06:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>unity</category><category domain='http://www.blogger.com/atom/ns#'>code</category><category domain='http://www.blogger.com/atom/ns#'>coroutines</category><title>All About Coroutines</title><description>One of my favorite features in Unity is its built-in support for coroutines.&lt;a name='more'&gt;&lt;/a&gt; Coroutines are a kind of cooperative multithreading, where coroutines all running on a single "regular" thread take turns executing by yielding control of execution to one another. Because switching between coroutines is cooperative they are easier to program than regular threads since you do not have to worry about managing locks to protect shared state.&lt;br /&gt;&lt;br /&gt;Coroutines make scripting behavior that is spread out over multiple frames a breeze. For example if you wanted to have a traffic light cycle between red, yellow, and green you could do it all in a single coroutine:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;function TrafficLight() {&lt;br /&gt;  color = Red;&lt;br /&gt;  yield WaitForSeconds(1.0);&lt;br /&gt;  color = Yellow;&lt;br /&gt;  yield WaitForSeconds(1.0);&lt;br /&gt;  color = Green;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Coroutines can also wait for one another which makes ordered cooperation between coroutines a breeze.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;function RunOnGreen() {&lt;br /&gt;  // wait for green light&lt;br /&gt;  // traffic light cycle ends in green&lt;br /&gt;  yield TrafficLight();&lt;br /&gt;  // model reaction time&lt;br /&gt;  yield WaitForSeconds(0.1);&lt;br /&gt;  print("Catch me if you can!");&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Now you can do all this without coroutines, but alternatives such as event driven callbacks, and state machines are usually not as elegant or concise. Needless to say coroutines are a nice programming tool.&lt;br /&gt;&lt;br /&gt;Because I needed more complete control over coroutines in a portion of my code for Wisp I ended up writing my own CoroutineScheduler similar to the one built-in to Unity. Today I contributed this code to the Unity community &lt;a href="http://www.unifycommunity.com/wiki/index.php?title=CoroutineScheduler"&gt;wiki&lt;/a&gt;. Most Unity games will never need this level of control over coroutines and are better off using the built-in support. But seeing how coroutine support is implemented on top of standard .Net/Mono generators leads to a better understanding of how coroutines work behind the scenes which is something anyone can benefit from. The coroutine scheduler is also useful if you want to add coroutine support to a non-Unity based project, and I think you will find the code easy to follow.&lt;br /&gt;&lt;br /&gt;To understand coroutines at an even deeper level, you should understand how generators work behind the scenes. Generators allow you to create a function that returns a lazy IEnumerator that yields a sequence of objects. You can also get an IEnumerator by calling GetEnumerator on a regular collection such as an ArrayList.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;// if array contents are 1, 2, 3&lt;br /&gt;// then this will print 1 2 3&lt;br /&gt;var arrayEnumerator = someArray.GetEnumerator();&lt;br /&gt;while (arrayEnumerator.MoveNext()) {&lt;br /&gt;  print(arrayEnumerator.Current);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;When you use a "for in" or "foreach" loop construct an IEnumerator is used behind the scenes.&lt;br /&gt;&lt;br /&gt;Here are similar examples this time using generators.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;function CountTo3() {&lt;br /&gt;  yield 1;&lt;br /&gt;  yield 2;&lt;br /&gt;  yield 3;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;function CountToN(n : int) {&lt;br /&gt;  for (var i = 1; i &amp;lt;= n; i++) {&lt;br /&gt;    yield i;&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;// print 1 2 3 &lt;br /&gt;// without allocating an array of size 3&lt;br /&gt;var generator = CountToN(3);&lt;br /&gt;while (generator.MoveNext()) {&lt;br /&gt;  print(generator.Current);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Behind the scenes a generator is translated to a state machine. This is where the magic happens. As I noted earlier an alternative to the TrafficLight coroutine is to use a state machine. In fact the TrafficLight coroutine is implemented as a state machine it just happens automatically when the generator is translated into one by the compiler. You can see the state machine class for any generator function by inspecting the .Net assembly using Reflector. But to give you a general idea of what is happening here is a simple example. &lt;br /&gt;&lt;br /&gt;&lt;pre&gt;function ThreeMore(start : int) {&lt;br /&gt;  yield ++start;&lt;br /&gt;  yield ++start;&lt;br /&gt;  yield ++start;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;// ThreeMore as a state machine&lt;br /&gt;class ThreeMore {&lt;br /&gt;  var state = 0;&lt;br /&gt;  var current;&lt;br /&gt;  var start : int;&lt;br /&gt;&lt;br /&gt;  // function parameters become object attributes&lt;br /&gt;  function CounToN(start : int) {&lt;br /&gt;    this.start = start;&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  function MoveNext() : boolean {&lt;br /&gt;    switch (state) {&lt;br /&gt;      case 0: current = ++start; break;&lt;br /&gt;      case 1: current = ++start; break;&lt;br /&gt;      case 2: current = ++start; break;&lt;br /&gt;      default: return false;&lt;br /&gt;    }&lt;br /&gt;    state++;&lt;br /&gt;    return true;&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The actual state machine classes generated by the compiler will be a bit different from this example. But the key points to take away are that generators are implemented as classes and on each call to a coroutine function a new instance of their compiler generated state machine class is created. The function parameters are translated into object attributes and function code is spread across multiple state machine states to allow execution to enter and leave the coroutine while maintaining parameter and stack state as object attributes.&lt;br /&gt;&lt;br /&gt;That does it for now. I hope you find this post useful.&lt;br /&gt;&lt;br /&gt;Disclaimer: Example code was typed into blog editor and may not compile.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5488893796912675313-5115849554256689499?l=www.cpudreams.com' alt='' /&gt;&lt;/div&gt;</description><link>http://www.cpudreams.com/2010/02/coroutines.html</link><author>fernando@cpudreams.com (Fernando Zapata)</author><thr:total>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-5488893796912675313.post-6863568844181019601</guid><pubDate>Fri, 12 Feb 2010 01:11:00 +0000</pubDate><atom:updated>2010-02-11T19:13:56.668-06:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>unity</category><category domain='http://www.blogger.com/atom/ns#'>lisp</category><category domain='http://www.blogger.com/atom/ns#'>storm</category><title>The Storm Programming Language</title><description>One of my goals with Wisp is to give players the ability to easily generate their own content &lt;b&gt;without leaving the game&lt;/b&gt;. From maps, to campaigns, and custom scenarios. The editors to support this player generated content should allow you to go beyond simple map building and into the realm of &lt;b&gt;custom gameplay&lt;/b&gt; through scripting. With this in mind, I created Storm a scripting language for the strategy game Wisp. My other motivation was that creating Storm would help me get experience in language implementation and design.&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Since, I've discussed my language with some of you I thought I'd post a &lt;a href="http://www.snoopbaron.com/storm/"&gt;demo&lt;/a&gt; so you could try it out first hand and describe my work in more detail. Storm is a not an object oriented language, but it does let you create .Net objects and invoke/access their members. Its design was inspired by Clojure, Boo, Arc, Go, and JavaScript. Storm is an s-expression based language, so it has a Lisp like syntax. It currently has the following features:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Integer and floating point numbers, with a full set of math operators&lt;/li&gt;&lt;li&gt;Booleans, with a full set of relational operators&lt;/li&gt;&lt;li&gt;looping and conditional expressions, with support for iterators&lt;/li&gt;&lt;li&gt;Literal syntax and built-ins for arrays and hashtables&lt;/li&gt;&lt;li&gt;Generic .Net object integration (use this for other data structures and foreign code)&lt;/li&gt;&lt;li&gt;Functions and variables with lexical scoping&lt;/li&gt;&lt;li&gt;A module system with public and private functions and variables (case based visibility)&lt;/li&gt;&lt;li&gt;Foreign modules, expose arbitrary .Net objects and functions as Storm modules&lt;/li&gt;&lt;li&gt;Configurable execution time limits (an infinite loop will not freeze the game)&lt;/li&gt;&lt;li&gt;Configurable stack limits (infinite recursion will not crash the game)&lt;/li&gt;&lt;li&gt;Sandboxing, limit API access and run multiple interpreters&lt;/li&gt;&lt;li&gt;Optional dynamic scopes, for things like mapping a single module to multiple game objects&lt;/li&gt;&lt;li&gt;Chain operator, (-&gt; obj foo (bar baz)) becomes (bar (foo obj) baz) think "obj.foo.bar(baz)"&lt;/li&gt;&lt;/ul&gt;Storm currently does not have macros, closures, generators/coroutines, or exceptions. Not much work is left to add macro and closure support, but I stopped work on Storm before getting them in, they will come later. I'm leaning against adding exception support. Generators are more work as rewriting them as state machines is not trivial, but it is something I would like to include at some point. I haven't done any optimization, but performance seems adequate for my needs. The implementation uses a hand written recursive descent lexer and parser and an AST based interpreter.&lt;br /&gt;&lt;br /&gt;If your curious the best way to learn more about the language is to look at the Doc module in the demo then try code in the Scratch module. I've included a description of the grammar and sample code for all features. The Game module shows how you could use Storm's dynamic scopes to support a MonoBehaviour like scripting interface (it drives the cube in the demo).&lt;br /&gt;&lt;br /&gt;While this demo exposes Storm as a low level scripting language that you can use to create your own Unity like MonoBehaviour scripts, this is not how I expect to use the language in Wisp. Players will probably never see any Storm code or be able to type in scripts. Instead players will work at a higher level of abstraction with GUIs that in the back end generate Storm code. Think of Storm as executable XML or JSON format that can be serialized and stored in a central database of user content.&lt;br /&gt;&lt;br /&gt;On other fronts, pun intended ;), I've begun work on the AI behaviour engine and I recently completed the networking engine with resynchronization support. The main technical components of Wisp are coming together nicely and I'm looking forward to doing more game play specific implementation work.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5488893796912675313-6863568844181019601?l=www.cpudreams.com' alt='' /&gt;&lt;/div&gt;</description><link>http://www.cpudreams.com/2010/02/storm-programming-language.html</link><author>fernando@cpudreams.com (Fernando Zapata)</author><thr:total>2</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-5488893796912675313.post-6980592127495214650</guid><pubDate>Wed, 20 Jan 2010 18:26:00 +0000</pubDate><atom:updated>2010-01-20T12:37:26.633-06:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>goals</category><title>Resolutions</title><description>Resolutions are easier to keep if you share them with friends.&lt;a name='more'&gt;&lt;/a&gt; My wife and I took a short working vacation to the &lt;a href="http://www.rose-hill.com/"&gt;Texas Hill Country&lt;/a&gt; to plan our goals for 2010. My primary goal is to launch a private beta of Wisp before the end of the year, preferably before this years Unite. Some of my other goals for the year are to read 52 books (finished 26 last year), exercise (Monday through Friday), and practice drawing (Tuesday, Thursday, and Saturday). What are your goals for 2010?&lt;br /&gt;&lt;br /&gt;I just finished the networking engine for Wisp and have begun work on the AI layer. After the AI layer is complete I'll have finished the main technical components of Wisp and part of the gameplay. There will still be plenty to be done but I'll have a solid foundation to build on.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5488893796912675313-6980592127495214650?l=www.cpudreams.com' alt='' /&gt;&lt;/div&gt;</description><link>http://www.cpudreams.com/2010/01/resolutions.html</link><author>fernando@cpudreams.com (Fernando Zapata)</author><thr:total>5</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-5488893796912675313.post-3010271841499429006</guid><pubDate>Thu, 12 Nov 2009 22:52:00 +0000</pubDate><atom:updated>2010-01-20T12:05:39.734-06:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>unity</category><category domain='http://www.blogger.com/atom/ns#'>conference</category><category domain='http://www.blogger.com/atom/ns#'>code</category><title>Unite 2009</title><description>It's been over a week now since I got back from Unite so this post is long over due :). As expected I had a great time at the conference and Unity brought out the &lt;a href="http://blogs.unity3d.com/2009/10/29/a-free-unity/"&gt;big guns&lt;/a&gt;. &lt;a name='more'&gt;&lt;/a&gt;A huge part of the Unity crew was there and all of them were &lt;a href="http://unity3d.com/company/"&gt;first class acts&lt;/a&gt;. One of my favorite parts of the conference were the hands on sessions where you could talk one on one with a Unity developer on any Unity related topic. Nothing beats going straight to the source :). For example, I got to speak with the &lt;a href="http://blogs.codehaus.org/people/bamboo/"&gt;creator of Boo&lt;/a&gt; about future language support. I also met a wonderful engineer from &lt;a href="http://www.exitgames.com/"&gt;Photon&lt;/a&gt; which gave me a head start in networking. And these are just two of many such conversations. Suffice it to say, if you are interested in Unity then Unite is well worth it. There were over 500 attendees and everyone was really exited about the future. It was encouraging to meet other Unity developers and artists not to mention educational. On the last day a bunch of us got together for dinner and had a great time :). &lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/_qaiKqmKKQWw/SvyRfploR-I/AAAAAAAAAVI/baaZWwnNVIA/s1600-h/UnitedBeforeAlcatraz2009cropsmall.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/_qaiKqmKKQWw/SvyRfploR-I/AAAAAAAAAVI/baaZWwnNVIA/s400/UnitedBeforeAlcatraz2009cropsmall.png" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: auto;"&gt;(Photo by &lt;a href="http://www.anbsoft.com/"&gt;Brady&lt;/a&gt;)&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: auto;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: auto;"&gt;But now the time for conferences is over. This next year is going to be an exiting ride as I prepare my game for release. I probably won't be attending any conferences until many months from now. But I won't miss next years Unite :).&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;On another note, I recently uploaded my &lt;a href="http://www.unifycommunity.com/wiki/index.php?title=Interpolate"&gt;interpolation library&lt;/a&gt; to the Unity wiki, and &lt;a href="http://www.anbsoft.com/"&gt;Brady&lt;/a&gt; released an updated version of his &lt;a href="http://www.anbsoft.com/middleware/sm2/"&gt;SpriteManager 2&lt;/a&gt; with a sweet &lt;a href="http://forum.unity3d.com/viewtopic.php?t=36307"&gt;timeline editor&lt;/a&gt; for 2D sprites. Check it out!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5488893796912675313-3010271841499429006?l=www.cpudreams.com' alt='' /&gt;&lt;/div&gt;</description><link>http://www.cpudreams.com/2009/11/unite-2009.html</link><author>fernando@cpudreams.com (Fernando Zapata)</author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_qaiKqmKKQWw/SvyRfploR-I/AAAAAAAAAVI/baaZWwnNVIA/s72-c/UnitedBeforeAlcatraz2009cropsmall.png' height='72' width='72'/><thr:total>0</thr:total></item><item><guid isPermaLink='false'>tag:blogger.com,1999:blog-5488893796912675313.post-6458495573809100085</guid><pubDate>Thu, 22 Oct 2009 21:00:00 +0000</pubDate><atom:updated>2010-01-20T12:06:45.570-06:00</atom:updated><category domain='http://www.blogger.com/atom/ns#'>unity</category><category domain='http://www.blogger.com/atom/ns#'>code</category><title>Community</title><description>Welcome to the CPU Dreams blog. I start this blog to share my experiences as an indie game developer, to share resources with other members of the gaming community, and to share information on CPU Dreams first game, "Wisp".&lt;a name='more'&gt;&lt;/a&gt; This summer I began my dream of becoming an independent game developer by creating CPU Dreams. My first project, the strategy game Wisp, will use the &lt;a href="http://unity3d.com/"&gt;Unity&lt;/a&gt;  engine. Even though this is my first time working as a game developer, I have over a decade's worth of experience as a professional software developer. Until now, I have kept my game development a hobby. All the horror stories permeating the game industry kept me away from pursuing my true passion. In recent years, the industry has changed, and there are new and exciting opportunities for small independent studios. Seeing this window of opportunity open, and not knowing when I would get a better chance, I took a leap of faith to start my dream. I know I still have a long road ahead of me, but I have no regrets, and I'm enjoying every minute of my new calling.&lt;br /&gt;&lt;br /&gt;In fact, I've been enjoying programming in Unity so much that it is difficult to pull myself away from it, even for a little bit, to start this blog. Without Unity, I don't think working full time on Wisp would be possilbe. The Unity community is equally helpful and I want to give something back by sharing code that others in the community might find useful. &lt;br /&gt;&lt;br /&gt;I just posted my &lt;a href="http://www.unifycommunity.com/wiki/index.php?title=MessageRouter"&gt;MessageRouter module&lt;/a&gt; to the &lt;a href="http://www.unifycommunity.com/wiki/"&gt;Unity Community Wiki&lt;/a&gt;. MessageRouter is a subscription based messaging/event system that provides an efficient method for broadcasting game events to interested parties while maintaining loose coupling. There are several other messaging/event systems in the wiki but this implementation has several features not available in the other implementations which some may find useful. I picked this module because it was generic and easy to extract from the rest of my game's specific code. I plan on extracting and sharing as much as I can. I have several other modules already in mind (dolly-zoom component, interpolation module, and a message timeline) and hope to contribute them soon.&lt;br /&gt;&lt;br /&gt;Back in September I attended &lt;a href="http://www.gdcaustin.com/"&gt;GDC Austin&lt;/a&gt; for the first time. I didn't know exactly what to expect, but wanted to meet new people in the community so that I wouldn't feel like that much of an outsider. I had a great time and met many indie developers that I always &lt;a href="http://www.tigsource.com/"&gt;admired&lt;/a&gt;. I was also fortunate enough to meet &lt;a href="http://forum.unity3d.com/viewtopic.php?t=31676"&gt;fellow Unity users&lt;/a&gt; and meet some of my heroes at Unity Technologies :D. Meeting just a small part of the Unity community was so wonderful that it made up my mind to go to &lt;a href="http://unity3d.com/unite/"&gt;Unite&lt;/a&gt; conference. If you are going, I hope to see you there next week =)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5488893796912675313-6458495573809100085?l=www.cpudreams.com' alt='' /&gt;&lt;/div&gt;</description><link>http://www.cpudreams.com/2009/10/community.html</link><author>fernando@cpudreams.com (Fernando Zapata)</author><thr:total>7</thr:total></item></channel></rss>