Archive for the 'Programming' Category

Physics Models

Thursday, December 20th, 2007

So I have been thinking about what level of physics model I want to implement in Razor. Specifically I have been doing a lot of thinking about collision detection. There are a lot of different ways of doing things with their own strengths and drawbacks. I have initially made the decision of going for more precision and complexity versus speed and ease of computation. I have been spending a lot of time at Wolfram Mathworld trying to remember all the stuff I learned in college.

In preparation for the impending physics tests I have added optional bounding box drawing to all the Actor objects:

Razor Bounding Boxes

I looked around and didn’t immediately see any optimized math libraries that calculate determinants on the mac. If anybody knows of one please let me know. I did find this thread which had some helpful ways of doing it manually.

Why is it called Razor? I don’t know, I just needed a name.

Tuesday, December 18th, 2007

I actually had a very hard time thinking of a name for this project. Nothing really seemed to fit too well or sound that good. But I needed some sort of name for my new project. You have to call it something… I finally settled on “Razor”. What does it mean? Nothing. What does it have to do with the project? Nothing other than now that is what the project will be known by. After not being able to think of a name for a while and itching to just start coding on the darn thing I just picked the name and it has just kind of settled.

Ok, so what is it? On the Google Code page that it is hosted at I wrote:

Razor is a strategy game engine which is oriented around programming the AI of the units rather than direct control by humans. The idea is that human players compete by engineering the intelligence of the units under their control in order to fulfill an objective. The game world is in 3D and will employ some basic physics. Units, AI, physics models and many other aspects are extensible through a plugin system.

Razor is for Mac OS X Leopard only due to leverage of certain Leopard exclusive features such as dynamic loading/unloading of Objective-C, Garbage Collection and more as time goes on.

This is an idea I have had banging around in my head for a long time. Ever since I worked on an AI lab in college where the final semester objective was to program the AI of 5 tanks to play capture the flag against 5 other tanks controlled by one of the AIs of my many classmates. At the end of the semester the class had a tournament in which the prize was an instant ‘A’ in the class and didn’t have to take the final! My lab partner and I won the tournament and even though we both had As in the class at that point, not having to take the final exam was a big time relief at the end of a very busy semester. Perhaps I will make a blog post on our winning strategy later.

Along with that, I have always loved the great strategy involved in RTS games like Starcraft (which in my opinion is the best RTS ever made). I loved thinking of crazy new strategies that would find kinks in established defenses or play with the psychology of the other players. The only thing that prevented me from pulling off my grand designs was the limitations of my own reflexes. Some people just have the twitch and can bounce from scene to scene, keep everything in their heads at once and make lightning fast and precise mouse movements. But if the Korean Starcraft scene is any indicator, these cyber-athletes like gymnasts have a limited lifespan. Once you hit the ripe old age of 22 your reflexes aren’t what they used to be and some pretty young 16 year old is going to take your spot. What I want in some respects is AI programmable Starcraft.

Now the project is only in its infancy and is nowhere near doing anything of significant interest at this point but I decided that I wanted to get the code into an initial functional state that would at least be worthy of initial check-in. Because the project is open source I will be commenting here about the work that I am doing on it, future feature additions and other issues with great openness and frequency unlike my closed projects.

Below is a screenshot of the Simulation Viewer app that you can build and run right now from the source that is posted on the project page. It is not much but it is a start.

Razor, first commit

MDBG plugin for Language Aid released!

Monday, October 15th, 2007
MDBG logo

At long last we have another plugin for Language Aid! Today a plugin for the Chinese dictionary lookup site MDBG was released for Language Aid version 1.1. This plugin is similar in function to the WWJDIC plugin in that it can take small or large chunks of Chinese text, send them off to the MDBG which provides dictionary lookups for words that it parses out of the text and then display the results. Much thanks goes to the administrator of the MDBG who was very cooperative and helpful in the development of the plugin! You can get the MDBG plugin by clicking on the “Add New Modules” button the Language Aid preference pane and selecting the MDBG plugin. You may need to wait a bit before it shows up in the plugin modules list after installing and restart Language Aid to get it to work correctly. If you know of a web service that can perform translation or dictionary lookups for your favorite language let me know. Also, Language Aid 1.1.1 is just around the corner with some small (but nice) new features.

Death to [NSBundle pathsForResources*]

Monday, August 27th, 2007
bug

Ugh, this bug was so nasty to track down… Apparently if you call this family of methods a couple of times it screws up whether NSBundle can find resources in the future. My specific situation is that I would call this method to find what bundles are in a directory. I would then run it one more time (because that is how the code is laid out). Then when kqueue tells me that something has changed in that directory (because I added a new bundle to the target directory) I call it one more time. It finds the new bundle just fine, but for some reason it completely ignores the stuff in Resources/ when trying to query the contents of said new bundle! I don’t know if this is the result of some errant caching or what but it is consistently reproducible. The old bundles work fine but there is nothing that can make Cocoa see the contents of this new bundle. This is a big problem because it means that [NSBundle loadNibNamed:owner:] now can’t find any nibs in the new bundle (which was what first tipped me off to the problem). In the current Developer Tools Documentation under the entry for [NSBundle pathsForResourcesOfType:inDirectory:] there is a statement:

Note: This method is best suited only for the occasional retrieval of resource files. In most cases where you need to retrieve bundle resources, it is preferable to use the NSBundle instance methods instead.

I hope that is not implying this weird (caching?) behavior. Also, after the damage has been done NSBundle instance methods no longer work either. The solution to this has been to instead use a UNIXy way like scandir() to find out what bundles are in a directory. Not nearly as graceful, but at least I don’t have weird peripheral behavior. So anyway…fair warning to all against using these routines.

Digital Quoteboard

Saturday, August 18th, 2007

So one idea that I have had knocking around in my head for a while has been a digital quoteboard. I remember how in college I would go over to somebody’s apartment and there would be this quoteboard full of funny one-liners which if taken of context or more often, taken in the context of who said them, were hilarious. Of course they are usually only funny if you knew the people that said them. I thought about how there are a lot of online communities of tight knit people who could have a little bit of fun with a digital equivalent and so I whipped up this little example. I will probably refine it here and there over time and will probably release the source soon (it is not that much code). Other things I have thought of were live javascript based editing and Wordpress permissions hook ins. It currently works by having a php page render a csv quote database into a jpg so you can have static links to the results, ensuring that it will work in every browser (the above image is the actual linked image and thus may change as the database changes). So far what I have found is that there is a great disparity in exact results or even basic functionality in using the same Truetype font on different operating systems and different versions of the graphics libraries that PHP hooks into. Also, it appears that some fonts do not fully define things like punctuation and formating such as tabs. Feel free to leave a quote by going here. Although I may decide to remove general access to it in the future ;)

SVK rules

Thursday, July 26th, 2007
c++ file icon

I really have to give props to svk. It really does excel where the svn client stutters (much in the same way that Subversion surpassed cvs). I have been using svk on my client machines for a while now and have found it rather nice and easy to use. There is of course the great benefit of not having to drag those annoying .svn directories around, but little things like being able to ’svk ignore’ my build directories just make it sweeter to work with. That and the fact that it actually works. I tried to ’svn co’ one of my projects on my source/build server and it would always choke at the same place and complain that it “Can’t copy ‘blahblah-base’ to ‘blahblah.tmp.tmp’: No such file or directory”. I tried to re-check it out but it complained that I needed to svn cleanup, but that would fail because of a similar “Can’t copy…” error message. I installed svk and it was able to successfully perform a check out and all is good now. There are of course downsides. Svk seems to have trouble with capitalization differentiation and it also seems to not like spaces in paths (those times I drop back to svn to fix those single instances). Also, much of the goodness of svk comes at the cost of drive space to mirror your repository and having to sync regularly. Despite its rough edges, it is now my source control client of choice and is on the whole a pleasure to work with.

Where have all the differs gone?

Monday, July 23rd, 2007
exec

Every once in a while I find a need for a tool that doesn’t yet exist. Or rather, a tool that doesn’t exist for Mac OS X that does things in the way that I want. My original motivation for writing Language Aid was that I wanted a program that provided Japanese text lookup functionality and I couldn’t find any. The other day I found myself once again craving a tool that I have frequently desired: a binary diff tool. For some reason I can’t find anything that will just do straight-up diffs of binary files. Every differ out there seems to be completely oriented around text. When running /usr/bin/diff on binary files it will just return that the files are indeed different and nothing more. Filemerge will attempt to interpret the files textually and show you what it thinks is different but the output is rarely useful. I recently found myself needing this functionality again and did another quick net survey for the imaginary tool in vain. I decided to whip up my own binary differ real quick (bdiff) and implement just the limited functionality that I currently desire. The thing about binary diffing is that without the assumptions on the meaning of the data (like with textual data) you really have few efficient ways to determine whether data has been changed or whether data has been inserted/deleted. This is quite the quandary and presents a more complicated situation than textual diffing when you present two files that are completely different. In my binary differ I have decided that if the two files have the same length then it chooses a heuristic that assumes that the files are variations of each other and do not have information inserted or deleted. If they aren’t of the same length then it chooses and a more general approach. I might improve it in the future but for now it serves my very simple need to just figure out what exact bytes are different from one file to another.

The Biggest Graphics Problem You Have Never Heard Of

Saturday, July 15th, 2006
OpenGL

I am now pleased to announce the second of many tech oriented articles that will be placed here on the Blue Lotus Blog. This time it is about a problem in computer graphics that I have been working on for years called Order Independent Translucency. It is something so simple and basic that you might wonder why nobody has solved it. So have I. That is why I have decided to write about it and have included some example source code to go with it. In this article I outline the problem, discuss and implement the currently most promising solution and suggest a better hardware-based solution. Come on in and let us make you aware of a problem that you were happy to be oblivious to.