The future of cinema

11. January, 2010

Everyone wants to predict the future and everyone knows that there’s a 100% chance to get it wrong. Here is my go.

Avatar is probably the movie which will be remembered as the one to turn 3D at the movies mainstream. To shoot the flic, Cameron used a new, ground-breaking technology: The virtual camera.

A virtual camera is like a real camera but it allows the director to look at the final render of the scene while the actors perform in front of the green screen. It’s a cave to carry around. The next step will be goggles.

And after that: Goggles for viewers of the movie. Avatar showed a limitation of 3D: You can’t look around. As soon as you focus on something different than the virtual camera, you get a headache. So the next generation of cinemas won’t get a pre-rendered movie but the 3D scene data. The big screen will go. Everyone in the room will wear goggles which allow to see anything. Wonder what’s inside the waste basket in the lab? You might get a peek.

From that, it’ll be a small step from one-source movies to mass-edited movies. Producers will spread the raw scene data to movie centers and fans will get a chance to fix bloopers or even rewrite certain scenes. Eventually, everyone on the floor might see the same movie but in a very personal way.

Probably won’t take long for teenagers to figure out a way to hack the cloth transparency. Virtual character don’t sue.


ePen 0.7 Status Update

9. January, 2010

I’ve pushed the code for ePen into a new set of Mercurial repositories: signal (a signal/event handling library, new BSD license), JaSpell (fork of the project jaspell.sourceforge.net; mainly a port to Java 5 and Maven 2, BSD-License) and ePen (the main editor, Eclipse Public License 1.0 since I had to copy code from the Eclipse code base).

The editor is pretty usable and I hope to wrap up 0.8 next week which should fix the following issues:

  1. Create new projects and open existing ones. The main problem here is that an ePen project is a directory and SWT doesn’t offer very good dialogs to select directories. Right now, the editor will create a demo project when you start it the first time.
  2. The translation mode is too slow
  3. Editing is sluggish.
  4. HTML export should support filtering by state (to allow to export only “final” scenes).
  5. Setting up the development environment is too complex. Especially the part where you need to copy the Eclipse plugins into the Maven repository. 0.8 will come as one huge JAR which you can start with a double click.

After that, I plan to resume work on my story “Haul” and post the first scenes in my old, desolate Philmann Dark site.


“Good” Game

7. January, 2010

Reading “The Problem of Good, in a Platform Game” got me thinking.

I doubt some of the assumptions on that page and I’d like to present my own here. It should be possible to model them into a simple agent for a game as well.

First, let’s assume that resources are finite and somewhat scarce. Changing your alignment (good/bad) need resources, so you won’t do it on a whim. I’d even say that there is a hysteresis, so you stay in your current alignment longer than in a perfect (linear) world.

So the question is: What changes you alignment?

My theory is that several forces influence your alignment (not necessarily in this order):

– Peer pressure
– Personal experience
– Prediction of the future
– Food/rest

Some comments on these forces:

1. If everyone around you is good, it’s hard to become evil, partly because they will fight this tendency, partly because you simply have no role model. We are all mimics. It’s hard to come up with something new on your own (again scarce resources: You don’t have all the time of the world nor can you change as often as you like).

You might argue that some people are born evil. I’d like to have proof of this, please.

2. Whenever you get into a situation X, you will rake your memory for similar situations to give you a guideline how to respond (again scarce resources). So if your experience tells you to be good in situation X (because that worked in the past), you will be good. Notice that only the outcome of the situation for *you* counts. So if you like to whine about being capitalized, the outcome of being abused is “good” for you – no need to get your lazy bum up and change.

3. If the situation is new, you have to come up with a plan. Again, you can’t think for years, there is some pressure on you. So the plan is never perfect and you will know that. So depending on your confidence of your plan, you will change your alignment or stay on safe (known) ground.

4. Most people are only civilized as long as they are fed and well rested. Just imagine to deprive someone from sleep for a day. They will get irritated much faster than a well rested person.

Model:

0 is neutal, > 0 is good, < 0 is selfish

1. is fairly easy to model: Just sum the influence of the people around you. Maybe multiply that with a factor depending on the psychological distance the people currently have to you. That is, your role models will feel pretty close even if they are on the other side of the globe while your neighbor could be on the other side of the moon, you couldn’t care less.

2. For every game situation, you need to calculate the net result. Use several standard games (prisoner dilemma and a couple more) and store the factors and the result in a memory per agent. When the next situation comes up, compare the setting with the memory and have the agent change its alignment according to the expected outcome of the game. When this is done, the agent is ready to play the game. Update the memory afterwards.

If the result is off the scale, change the alignment accordingly.

3. For every new game, have the agent play a few rounds against itself. Use the result as the alignment for the game. If the outcome is vastly different from what the agent expected, multiply this "unsureness" factor to the alignment change (if we’re more insecure, we are more susceptible for influence).

4. Give the agent a head and a stomach. Let them rest, eat (and work late and starve). 0 means "normal", 0 means rested/well fed. Scale this accordingly (maybe this is even logarithmic: If you are very hungry, you’ll even eat another agent) and add to the current alignment.

To map the linear alignment to the “good/selfish” alignment, use a hysteresis curve. The final result should show some “resistance” to change the current alignment and a preference to return to the current state (so if you’re currently selfish, being treated nice won’t count as much as being treated badly).


inFAMOUS

5. January, 2010

A lot has been said about this game (official website, 9.2 on IGN). I’ve played the demo and I liked it but the handling was a bit overwhelming in the demo, so I didn’t buy it right away. Now, it’s out in the platinums series and I must admit, the game is better than the demo. The handling is pretty good except when you try to rain death and pain on your enemies from the corner of a building: The corner is in the way too often. While it’s smart of the enemies to clump in your dead angle, in the real world, I’d just extend my arm over the edge and deal some blind damage.

But the other things work well. Cole jumps well, clings to edges, pipes and cables as if he was Spiderman. A 100m sheer drop is met with a tumble and Cole is on his feet again. Walking electric cables is fun and it’s great fun when you learn to glide them. Especially since they charge you up so you can really dish out. When you get to protect a box with medicine, the best place is on the cables above the area where you hail wrath and worse on the mortals below.

With time, you’ll learn several ways to deal damage which, used in strategic ways, will make the game a piece of cake. Taking enemies down will get you positive points, killing them (especially when they are already down) gives you negative score. Helping people gives you positive score, hurting them reduces your score. Just as in real life, your score doesn’t stop at 0 but can go bad. Really bad. Bad as in people running away from your shadow, gathering in mobs and throwing stones at you. Or they can become your fans, hurl stones at your enemies when they attack you and ask to you spend the night with them (an offer which you can’t accept).

Just like in Black and White, you decide to become a superhero or a supervillain. If you go the good route, your powers will be more controlled. If you go evil, mass destruction is your toy.

On top of that, we have a nice, complex background story which keeps things together. The side missions aren’t too thrilling but it’s a lot of fun to jump off and on buildings, scale walls, sheds, cars, train tracks. The enemies don’t just stand there but try to take cover, they disperse when you jump them from above like an angry thunder cloud. There are various parties involved, each trying to sell their own version of the truth. It’s moving when a group of policemen salute you after helping to arrest a gang member who killed one of them. To gain control over the city, the gangs turned off the power and your vision becomes blurred when you have to go into such an area.

Recommendation: Buy.


Making web development a bit more simple

3. January, 2010

When someone starts to make a path, most people tend to follow the trail. So when Sun introduced the Servlet API, most people were uneasy about the design problems:

  • Servlets are singletons (which are evil; this is due to performance problems in Java 1.2 which have been fixed about ten years ago).
  • The resulting code smells (feature envy since you call many methods of HttpServletRequest/Response, long method since you can’t call subdivide the doGet() without passing at least two parameters to each new method, duplicated code since you have to walk instance trees to get at a lot of information, …)

Whenever I see Java servlet code, I always wonder why people don’t solve this. It’s so simple:

public abstract class ServletRequestHandler {
    protected HttpServlet servlet;
    protected HttpServletRequest request;
    protected HttpServletResponse response;
    protected String contentType = "text/html";

    public void init(
        HttpServlet servlet, 
        HttpServletRequest request, 
        HttpServletResponse response
    ) {
        this.servlet = servlet;
        this.request = request;
        this.response = response;
    }

    public abstract void process();

    public PrintWriter out() {
        if( null == out ) {
            response.setContentType( contentType );
            
            try {
                out = response.getWriter();
            } catch( IOException e ) {
                throw new RuntimeException( 
                    "Can't get writer", e 
                );
            }
        }
        return out;
    }
    
    public ServletRequestHandler html( String html ) {
        out().print( html );
        return this;
    }
    
    public ServletRequestHandler attribute( String value ) {
        out().print( escape( value ) );
        return this;
    }
    
    public ServletRequestHandler attribute(
        String name,
        String value
    ) {
        if( StringUtils.isBlank( value ) ) {
            return this;
        }
        
        PrintWriter out = out();
        out.print( ' ' );
        out.print( name );
        out.print( "=\"" );
        out.print( escape( value ) );
        out.print( "\"" );
        return this;
    }
    
    public ServletRequestHandler text( String value ) {
        out().print( escape( value ) );
        return this;
    }
    
    // Add more methods to support your favorite
    // web design patterns
}

Now, all your servlets look the same: They accept the request, create a new instance of the right implementation of ServletRequestHandler, and call init() plus process(). With a bit of glue code, you can even use Spring to manage all your servlets for you. No more dabbling with web.xml!

And the best part: This pattern allows you to test the servlet code from a unit test without any container. Just use Spring or Mockrunner to get mock-ups for the J2EE API classes.


Nation and the 6th part of the Hitchhiker

1. January, 2010

Just finished reading two books: “Nation” (Terry Pratchett) and “And Another Thing …” by Eoin Colfer.

When I browse through my favorite book store here in Zurich, I’m always looking for something new by Terry Pratchett. I’m a huge fan of his Diskworld series and always torn when there still isn’t another volume out. On one hand, I really miss his witty way to look at the world, on the other, a good thing takes time. So this time, I ambled into the other works of Pratchett but after the the carpet people and “Johnny and the bomb”, I wasn’t too thrilled. But I couldn’t walk away from “Just possibly the best book Pratchett has ever written” (Fantasy and Science Fiction).

And it is. It’s a hugely different setting than Diskworld but as witty and smart as you’d expect. It’s the story of a boy who sets out to become a man and becomes so much more. It’s about standing up against peril, evil and bullies. If you like Diskworld, you must read this, too.

Eoin Colfer was a similar issue: Part 6 of the THHGTTG? You’ve got to be kidding! I loved the stories around Artemis Fowl but The Hitchhiker? Is Eoin out of his mind? Luckily, he asked himself the same questions.

The net result: Definitely not a book by Douglas Adams but also definitely a book from the Hitchhiker series. Ever wondered where the animals come from that want to be eaten and can argue in their favor? There must be herds, right? There are. When Thor (the Norse god) needs some aiming practice, they “provide moo-ving targets”. Just like Adams, Eoin (pronounced Owen) likes to take things to the tip and I mean the utmost protruding electron. It’s a book about a world where all your wishes were granted. And you know the old saying. A fun read and at least one good laugh on every page. To put it another way: The worst thing about the book is its title.

If you’re still worrying whether you should dare to complete the trilogy with part 6, stop and buy.

Recommendation: Buy. Both. Now.


ePen 0.7

31. December, 2009

I’ve started to work on ePen again. This time, I’m using Java and SWT/JFace. Python Traits was nice but too slow for my purpose, especially the editor.

This is the main window. As you can see, there is an outline with all characters, places, items, wiki pages and books (with chapters and scenes). The whole thing is meant to save all the information in one place so you can easily find and use them.

Do you see all those nice links? The editor will create them for you from names of characters and other things. If you click on them, you’ll jump right to the meat. I’m thinking of a hover mode where you get a summary but there is a bug somewhere.

The other feature is: No save button. The editor will save your work as you type. If it crashes or your whole computer crashes or there is a power failure? No sweat. Worked for an hour and forgot to save? Won’t happen again. I’m still working on automated backups plus a client/server mode so you can have automatic off-site backups, too.

Right now, I’m shaving off a few rough edges. Then, I’ll drop it on sourceforge.

[EDIT] The project home page is at http://sourceforge.net/projects/epen/


SWT Tree and tooltips

26. December, 2009

If you need tooltips for elements in an SWT Tree or JFace TreeViewer, you had to jump through some hoops as Snippet 125 shows.

Since SWT/JFace 3.3, you should use a TreeViewer, a ColumnLabelProvider (which has all those cool getTooltip() methods) and this line of code:

ColumnViewerToolTipSupport.enableFor (viewer);

That’s it. There is a catch, though: The tooltip doesn’t wrap automatically. If you have long lines of text, you need commons-lang and this piece of code:

    private String wrap (String s)
    {
        StringBuilder buffer = new StringBuilder ();
        
        String delim = "";
        for (String line: s.trim ().split ("\n"))
        {
            buffer.append (delim);
            delim = "\n";
            buffer.append (WordUtils.wrap (line, 60, "\n", true));
        }
        
        return buffer.toString ();
    }

Note that this code is only necessary if you have several lines of text in the tooltip. For single long lines, WordUtils.wrap() alone is enough.

Link to the JFace snippet.


How to make Eclipse 3.5 work on gtk2 2.18

24. December, 2009

If you’re using Eclipse in Linux with gtk2, then you might have run into this issue: Buttons don’t work when you click on them, tree views are initially empty, icons are missing or not drawn correctly. To fix this, just run this command before you start Eclipse:

export GDK_NATIVE_WINDOWS=1

I suggest that you put it into a little wrapper script. With this option enabled, Eclipse works like it should, even on Linux/gtk.

It’s a good example of the pain when working with Eclipse developers: Everyone agrees that it’s a bug and it’s pretty clear what needs to be done. The fix apparently even exists and “just” needs to be copied from the 3.6 sources to 3.5. And nothing happens because the release process is so involved that it just takes too much time and the workaround (adding the line above or control Eclipse with the keyboard) is too simple.

I can’t say on which side I’m on here. I understand why nothing happens but it still freaks me out.


At the restaurant

22. December, 2009

After having been served a soup, the patron calls the waiter: “Please try the soup.”
The waiter is alarmed: “I will return it to the kitchen immediately!”
“No, no!” The patron shakes his head. “Please try the soup.”
W: “Is it too hot?”
P: “No. Please try it.”
W: “Too salty?”
P: “No. Please try it.”
W: “Is the taste not to your liking?”
Patron is getting irritated: “No. Just try it, will you?”
The waiter is confused and bends down, pauses. “Where is the spoon?”
Patron: “Ah!”