14 September 2008

JOGL woes!

So after the successful test of HyperUtils and the decision to slow development on it, I went on to begin my statistical analysis toolkit. I knew that I wanted to separate the view from the data model, more than just by modules, but actually using what I felt was the best tool for the job. I ended up deciding to use java backed by JOGL as a visualization platform. The first step was to set up the JOGL testing harness. This seemed easy enough, although my OpenGL was a little rusty I was able to quickly get back into the feel of the API. JOGL uses such a minimalist approach in wrapping OpenGL that it feels just like talking to the C++ API. I quickly implemented an extremely basic scene graph and began working on a camera for traversing the visualizations. Unfortunately, I was having an issue where every graph node that I rendered was translated correctly relative to its parent, but the scene root was always stuck to the camera! My code was so simple that I spent two days trying to figure out what the problem was. I checked and rechecked my matrix math, my hierarchy flattening code, and verified I was using the right matrix format (column vs row major). All of this turned up no errors! Disheartened, I scoured the internet and found that JOGL has practically no documentation. I downloaded and looked at example code, but nobody else was setting transforms directly (glLoadMatrixf) or if they were, they were not using any sort of a hierarchy. I was at my wits end when I found a link that pointed to a book my bosses wrote, Practical Java Game Programming. This link reminded me that I had a copy of the book on my shelf, so I began flipping through the chapters. Lo and behold, there it was, a chapter on JOGL! With a few pages I found the magic fact that I had been missing (p.388):
The glPushMatrix function duplicates the current matrix and then pushes that matrix onto the stack.
That was it! I had been assuming that the matrix stack was "flattened" intrinsically. Because of this faulty assumption, I was overwriting my camera transform with each rendered object's world matrix. After learning that I was quickly able to fix the issue!
The next goal is to build the first piece of the statistical analysis toolkit using (as portable as possible) C++ code and using the Java Native Interface (JNI) to link it with my visualization framework.

--Dahlgren

12 September 2008

Success!

Today marked the first successful test of HyperUtils on the Nintendo DS. It was integrated smoothly and the tests were quickly converted (simply changed cout for a system library print function). My goal of having zero external dependencies has been proven effective for embedded systems! I'm going to slow down new feature development on HyperUtils for a bit while I work on another small project. I want to test the utils on the iPhone next!

31 August 2008

Solution Hint

I successfully solved my template problem for a ListBehavior template mechanism. The syntax is a bit hairy (good reason not to expose this layer) but it works.

So here's a hint for the "left as an exercise for the reader" part:


<template <template <typename>
Pretty ugly eh? Stay tuned for more exciting breakthroughs... hahah

--Dahlgren

30 August 2008

The C++ Wall

I have just had my first encounter with the C++ Wall. This is a term that I once heard a classmate use when talking about advanced object oriented designs. Basically there is a lot of OO sort of things that C++ does not provide support for. To put things in more concrete terms, let me share a little bit of the development process that I'm going through with the HyperUtil library.
The initially stated goals of the HyperUtil library include being MT Hot with zero dependencies to the stdlib. This meant having an architecture to support a pluggable memory model and a pluggable threading model.
The first components that I made were the rudimentary interfaces for the AbstractThreadingModel and AbstractMemoryModel base classes. Next I made an AbstractList interface to encapsulate the implementation details (backed by linked list or primative array for example). In Java, this sort of thing is quite easy to do and I frequently use Abstract Container-type interfaces. After fighting with the compiler and various syntax iterations I resigned myself to scouring the internet for help, only to find that there is no way to subclass a templated Abstract Base Class. This is due to a number of characteristics of the language. First, the template mechanism is really more like a fancy macro system. The code for the templated type is only created during specialization (the process of telling a templated class / function what type you will be using) and two specializations of the same type are not the same in the language!
I sort of put the problem aside for a while and went on with developing an array type for the library (resizable, maintains a length) that is templated. I want to use the flexibility provided by templates, but I strongly dislike how using a templated type anywhere causes the template keyword to infest more and more of your code until it begins to resemble the STL. As a temporary workaround for my list interface issue, I have been considering another use of templated types. Consider the following C++ code (Note: exposing 'T' from the templated concrete list to this template is left as an exercise to the reader):

template <typename AbstractList>
class ListBehavior
{
private:
AbstractList* m_pListImplementation; // Delegate
public:
// Constructor, destructor etc omitted for clarity
T& operator[](int index);
const T& operator[](int index) const;

int size(void) const;
};

Given this class, we then begin to see that the ListBehavior templated class can be used as a way of providing an interface (or even a contract of sorts). With that idea in mind, those methods can be defined in such a way that we get free compile-time checking to ensure that the list behavior we define is adhered to (just like an interface class).


template <typename AbstractList>
T& ListBehavior::operator[](int index)
{
return (*m_pListImplementation)[index];
}

template <typename AbstractList>
const T& ListBehavior::operator[](int index) const
{
return (*m_pListImplementation)[index];
}

template
AbstractList>
int size(void) const
{
return
m_pListImplementation->size();
}

Now, when a ListBehavior object is specialized, the compiler will create the simple delegation code and cause an error if the type used to specialize it doesn't implement all of the AbstractList functionality!
I understand that this is a slightly complex usage model (using a templated type as a wrapper for a certain subset of behaviors), but the intention if only to expose this to the Library internally, for flexible swapping of implementations and such.
The next hurdle I see is the same sort of problem. I'd like the AbstractMemoryModel type to be templated. I want this so that calls to the underlying implementation can actually allocate the correct types rather than just char pointers. I have a suspicion that the casting from char* to indiscriminate types may cause serious performance issues if not outright crashes due to byte-alignment considerations. This is not a terrible problem on PC platforms, but could be debilitating on embedded systems not equipped to handle sloppy coding.

More to follow,

--Dahlgren

24 August 2008

Side project decision

I decided on a side project that should be pretty rewarding. I am going to make a C++ library of data structures (both common and exotic) and math utilities. The thing that will differentiate this from say, the STL, is an architecture meant to exploit massive parallelism from the bottom up. This will be provided through execution contexts that define both a threading and memory allocation model. The other major difference is that my library will not rely on any of standard libraries, making the library itself very lightweight (good for embedded systems maybe?). Furthermore, the configurable memory and threading models allow for the library to be optimized for specific platforms without unnecessarily wading through plumbing code.

Completion of this will allow me to use this library to get other utilities that I may craft up and running. What exactly those other utilities might be is still up in the air... hahah.

--Dahlgren

23 August 2008

Side projects, oh side projects

So I have been stuck in a kind of rut lately with determining what, exactly, I would like to work on as a side-project in my free time. The first thing that always pops into my head is "Make something useful!". Right... that seems pretty obvious. But what does useful mean on a qualitative level? Well for me, I would say that I split this into a couple of broad categories:
  • It helps (or forces) me to learn some tool / library / language that I am unfamiliar with currently.
  • It is a new (more efficient or more robust) method of solving some old problem.
  • It could be used in production code (at IMI) if my solution is a good one.
Initially, I started work on a curses based client for xmms2. This is a GNU application that features a client-server based model for a local music player. The interesting thing is that the client side API is very simple and easy to work with, yet it provides all the functionality of the underlying server (including playlist management, a transparent repository of media files [local and remote], and even equalization). An important distinction to be made is that the server-side is not streaming data, it just sends the sound to its machine's sound hardware. So, why make a curses client instead of a GUI? Well, I am a big fan of keyboard shortcuts and the command line in general. I find that when using xfce4, I can be FAR more productive using the keyboard almost exclusively. That being said, my desktop is typically littered with terminals and having a media player that fits nicely in that terminal would be pretty sweet. The other reason is to get in touch with the developers that still have interest in command line utilities. I had hoped that by putting this offering out, I may be able to contact others with similar interests.

Unfortunately, I kind of lost interest in this project shortly after completing most of the command portion (my initial test driver was a REPL for the implemented client commands such as play, stop, forward [time], etc). The main reason to this was the extremely limiting ncurses API. I tried wrapping up the functionality in C++ objects and implementing a tree of windows but quickly found that the provided ncurses functionality just was not intended to be used this way. Thus was my grand vision crushed! There is still a part of me that wants to complete this, it has just been such slow moving progress that I feel like I am wasting my time working on it. The future of my as-yet unnamed xmms2 client is uncertain.
Aside from this project, one of the ideas I have been tossing around include fleshing out a game idea using the currently available technology from the project I am working on at IMI and then pitching this idea if I think it will fly. I won't share too much about this idea, but it is going to be a java webstart app. And finally, the last possibility is working on a proof of concept of some advanced piece of gaming technology. This could be some new animation technique (since character animation is sort of becoming a specialty of mine), or some sort of an interesting visualization of force vectors in a volume, etc.

Something will be completed eventually... hahah.

--Dahlgren

17 August 2008

10 Reasons why I love my Jaguar

I really felt compelled to make note of these after an incredibly enjoyable drive today. For those that do not know me personally, I acquired a 1998 Jaguar XJ8 Vander Plas edition. I received the car in INCREDIBLY good condition (it definitely does not appear almost eleven years old). A lot of people like to discourage Jaguar ownership, often citing electrical problems and poor gas mileage. Well, these points may be true, but here is my list of counter points! (In no particular order)
  1. Quiet ride - This car has more noise cancellation features than any other vehicle I have ever driven or rode in. The ride is pristinely quiet and relaxing despite whatever may be going on outside (including riding alongside an 18-wheeler or past an active construction site).
  2. Comfortable seating - The seats in the car are leather and just the right firmness. The shape of the seat provides adequate lumbar support by default and driving for long periods causes little to no discomfort.
  3. Cool steering wheel - The steering wheel is a sort of lacquered wood and leather hybrid with a protruding Jaguar logo in the center. It is a pleasure to grip and encourages using both hands to steer (an oft neglected safety consideration).
  4. Smooth ride - Whether I am driving at 18 miles per hour or 80, the ride is just as floaty. This floating feel makes driving (even on I-4) an enjoyable experience.
  5. Long reflective hood - It's much longer than a Japanese car's hood and extremely shiny, which means it is cool to look at :)
  6. Unexpected power - This can has some serious pickup. Despite weighing 1,873 kilograms completely unloaded, the Jaguar has an extremely responsive accelerator. This really comes in handy when trying to merge onto I-4 during heavy traffic (i.e. any given time on any day.. lol).
  7. Too many small niceties to count - It seems like every time I do a thorough detailing on my car, I find some cool amenity I never before noticed. The most recent was penholders on the sides of the front seats for use with the fold down tray tables. They really put attention into the details.
  8. Graciously spacious interior - Because the car is huge ( length [meters]: 5.151, width [meters]: 1.798, height [meters]: 1.359 ) there is plenty of space inside. Leg room for all occupants (front and back) is ample.
  9. Stereo controls integrated into steering wheel - I know this is pretty standard on vehicles these days, but this is the first car I have owned with controls on the steering wheel. It's not only quite convenient, but also helps to again enforce keeping both hands on the steering wheel.
  10. The body is sturdy - The doors are thick and heavy and the bumpers are designed to deal well with an impact. Contrast this with my previous car (a 2000 Nissan Sentra) which had paper thin doors and fiberglass bumpers that are built to disintegrate on impact. This adds a real feeling of safety and security.
So let the nay-sayers talk down to the Jaguar, but the owners know that the pleasures provided are worth the risk of some additional maintenance expenses!