Archive for November, 2012

Working Draw2D touch Bezier curve connector

I wanted a working Bezier curve connection for the nice Draw2d touch package; the one included doesn’t actually work, so I created this one:

javascript

  1. draw2d.layout.connection.NewBezierConnectionRouter = draw2d.layout.connection.ManhattanConnectionRouter.extend({
  2.                 NAME : "draw2d.layout.connection.NewBezierConnectionRouter",
  3.                 init : function()
  4.                 {
  5.                     this.cheapRouter = null;
  6.                     this.iteration = 5;
  7.                 },
  8.                 route : function(conn)
  9.                 {
  10.  
  11.                     var start  = conn.getStartPoint();
  12.                     var fromDir = this.getStartDirection(conn);
  13.                    
  14.                     var end  = conn.getEndPoint();
  15.                     var toDir = this.getEndDirection(conn);
  16.  
  17.                     var x1 = start.x;
  18.                     var y1 = start.y;
  19.  
  20.                     var x4 = end.x;
  21.                     var y4 = end.y;
  22.                    
  23.                     var dx = Math.max(Math.abs(x1 - x4) / 2, 10);
  24.                     var dy = Math.max(Math.abs(y1 - y4) / 2, 10);
  25.                            
  26.                     var x2 = [x1,      x1 + dx, x1,      x1 - dx][fromDir].toFixed(3),
  27.                         y2 = [y1 - dy, y1,      y1 + dy, y1     ][fromDir].toFixed(3),
  28.                         x3 = [x4,      x4 + dx, x4,      x4 - dx][toDir].toFixed(3),
  29.                         y3 = [y4 - dy, y4     , y4 + dy, y4     ][toDir].toFixed(3);
  30.                
  31.                     var path = ["M", x1.toFixed(3), y1.toFixed(3), "C", x2, y2, x3, y3, x4.toFixed(3), y4.toFixed(3)].join(",");
  32.                
  33.                     conn.svgPathString = path;
  34.                 }
  35.  
  36.             });

Note that I didn’t figure out yet how to add the contact points for the hit tests; the ones I add always seem to be off, so I have to read up on how to properly do that. Resulting in, for all ports:

OpenMSX keybindings on OpenPandora

Annoyed by the default settings for the OpenMSX emulator on the Pandora, I decided to pen some ways down to fix it:

by default the the cursor keys are mapped to the joypad, so that fine. The nurbs are not working but I don’t like those for MSX anyway.

However the X,Y,A,B are not connected to anything sensible while playing games. OpenMSX was written on SDL and SDL sees XAYB as page down, home, page up, end.

To bind keys in OpenMSX you need the MSX keymappings:

The matrix and OpenMSX work pretty simple: when you want to bind a key press, you press F10 and then run:

bind PAGEDOWN “keymatrixdown 8 1” 

which binds the X button to the MSX spacebar.

The code “8 1” is calculated by:

  • the bit row number (8 in this case for space) 
  • 2^columnumber, so 2^0 = 1

So if you want the ‘n’:

  • row 4 
  • 2^3 = 8 
  • bind PAGEDOWN “keymatrixdown 4 8”

Here are my settings for Metal Gear 1:

    bind end “keymatrixup 8 1″

    bind end,release “keymatrixdown 8 1″

    bind pagedown “keymatrixup 4 8″

    bind pagedown,release “keymatrixdown 4 8″

    bind pageup “keymatrixdown 6 64″

    bind pageup,release “keymatrixup 6 64″

    bind home “keymatrixdown 6 128″

    bind home,release “keymatrixup 6 128″

So:

  • X = n = hit/shoot
  • B = space = use
  • Y = F2 = inventory
  • A = F3 = weapons

Have fun!

Mac OS X (10.8), SDL & Homebrew: Undefined symbols

On OS X, running:

brew install sdl

Won’t link and

sudo brew link sdl

Won’t link either (not supposed to run brew as root either).

When you compile something for SDL (even the most trivial SDL program), it’ll report:

Undefined symbols for architecture x86_64:

  “_SDL_GetError”, referenced from:

      _SDL_main in ccKV9YwC.o

  “_SDL_GetKeyName”, referenced from:

      _DisplayKey in ccKV9YwC.o

  “_SDL_Init”, referenced from:

      _SDL_main in ccKV9YwC.o

  “_SDL_PollEvent”, referenced from:

      _SDL_main in ccKV9YwC.o

  “_SDL_Quit”, referenced from:

      _SDL_main in ccKV9YwC.o

  “_SDL_SetVideoMode”, referenced from:

      _SDL_main in ccKV9YwC.o

  “_main”, referenced from:

      start in crt1.10.6.o

     (maybe you meant: _SDL_main)

ld: symbol(s) not found for architecture x86_64

collect2: ld returned 1 exit status

To fix that, do the following:

sudo ln -s /usr/local/Cellar/sdl/1.2.15/include/SDL /usr/local/include/

sudo ln -s /usr/local/Cellar/sdl/1.2.15/ /usr/local/opt/sdl 

After this, SDL software compiles like this:

gcc -L/usr/local/opt/sdl/lib -lSDLmain -lSDL -framework Cocoa SDL_Keyboard.c