Friday, June 1, 2012

Gladius "Old Develop"

‹prev | My Chain | next›

I made a go at Gladius last night, but was thwarted. The last obstacle into which I ran was require.js, of which I am quite familiar. So hopefully tonight, I can see Gladius in action.

I copy the require.js in gladius-core into my local test app:
➜  gladius-my git:(master) ✗ cp ../gladius-core/lib/require.js public/javascripts 
Now I wrap the example code in require.js:
<script src='/javascripts/require.js'></script>
<script>
require.config({
  baseUrl: 'javascripts'
});
require(['gladius-core'], function(Gladius){
  // ...
  var testCanvas = document.getElementById( "test-canvas" );
  Gladius.create(
    {
      services: {
        graphics: {
          src: 'graphics/service',
          options: {
            canvas: testCanvas
          }
        }
      }
    },
    game
  );
});
</script>
At this point, I begin to wonder if I have a version mismatch, primarily because of the src attribute being passed into Gladius.create(). I do not have a graphics/service directory or file anywhere in my code or in gladius-core. I note that gladius-code has an "old-develop" branch in addition to the current default of "develop". And indeed, in that branch resides graphics/service.js:
➜  gladius-core git:(develop) git co old-develop 
Switched to branch 'old-develop'
➜  gladius-core git:(old-develop) ✗ ls ./src/graphics/service.js
./src/graphics/service.js
So it seems that I have a choice. Abandon the tutorial and dig through some other Gladius code to get this new require.js version working? Or abandon the currently compiled gladius core, and restart on "old-develop"? I opt for the latter in the hopes that I am closer to a quick win.

So, back in gladius-core, I run make-setup (say, I wondered where that was last night):
➜  gladius-core git:(old-develop) ✗ make setup
Submodule 'external/CubicVR.js' (git://github.com/cjcliffe/CubicVR.js.git) registered for path 'external/CubicVR.js'
Submodule 'external/math' (git@github.com:gladiusjs/math.git) registered for path 'external/math'
Submodule 'tools/qunit' (git://github.com/jquery/qunit.git) registered for path 'tools/qunit'
...
 4e747b71f6298a701c6c8e5f1f339dba3ab88092 external/CubicVR.js (v0.2.1-42-g4e747b7)
 bcddb83947f1355eda2706526409a04110ba1d74 external/math (remotes/origin/refactor-22-gbcddb83)
 167e41f35c49d54c9dda84a074c6e6a89917cd20 external/math/tools/qunit (v1.0.0~3)
 7cf3bf7e49785c076e010f014d4ded301569ec81 tools/qunit (v1.0.0~14)
rm -f .git/hooks/pre-commit
ln -s "../../tools/pre-commit.sh" .git/hooks/pre-commit
Hrm... the contents of src in "old-develop" look suspiciously like the Javascript files required by the example. So I sym-link them in my sample application:
➜  javascripts git:(old-develop) pwd    
/home/chris/repos/gladius-my/public/javascripts
➜  javascripts git:(old-develop) ln -s ../../../gladius-core/src/* .
➜  javascripts git:(old-develop) ✗ ls
base  common  core  gladius.js  gladius-src.js  graphics  input  lang.js  logic  network  order.js  physics  README.md  sound
➜  javascripts git:(old-develop) ✗ ls -l
total 0
lrwxrwxrwx 1 chris chris 30 Jun  1 23:40 base -> ../../../gladius-core/src/base
lrwxrwxrwx 1 chris chris 32 Jun  1 23:40 common -> ../../../gladius-core/src/common
lrwxrwxrwx 1 chris chris 30 Jun  1 23:40 core -> ../../../gladius-core/src/core
lrwxrwxrwx 1 chris chris 36 Jun  1 23:40 gladius.js -> ../../../gladius-core/src/gladius.js
lrwxrwxrwx 1 chris chris 40 Jun  1 23:40 gladius-src.js -> ../../../gladius-core/src/gladius-src.js
lrwxrwxrwx 1 chris chris 34 Jun  1 23:40 graphics -> ../../../gladius-core/src/graphics
lrwxrwxrwx 1 chris chris 31 Jun  1 23:40 input -> ../../../gladius-core/src/input
lrwxrwxrwx 1 chris chris 33 Jun  1 23:40 lang.js -> ../../../gladius-core/src/lang.js
lrwxrwxrwx 1 chris chris 31 Jun  1 23:40 logic -> ../../../gladius-core/src/logic
lrwxrwxrwx 1 chris chris 33 Jun  1 23:40 network -> ../../../gladius-core/src/network
lrwxrwxrwx 1 chris chris 34 Jun  1 23:40 order.js -> ../../../gladius-core/src/order.js
lrwxrwxrwx 1 chris chris 33 Jun  1 23:40 physics -> ../../../gladius-core/src/physics
lrwxrwxrwx 1 chris chris 35 Jun  1 23:40 README.md -> ../../../gladius-core/src/README.md
lrwxrwxrwx 1 chris chris 31 Jun  1 23:40 sound -> ../../../gladius-core/src/sound
After loading my sample, however, I find some errors in the Javascript console:
GET http://localhost:3000/external/require.js 404 (Not Found) gladius.js:31
Uncaught ReferenceError: requirejs is not defined :3000/:6
Uncaught ReferenceError: Gladius is not defined :3000/:78
Ew. I can see why this is "old-develop"—it has hard-coded the path to require.js inside gladius.js. In the interests of seeing something, I move require.js into external:
➜  public git:(old-develop) ✗ mkdir external
➜  public git:(old-develop) ✗ mv javascripts/require.js external
It turns out that I also need some of gladius-core's other "external" libraries:
➜  public git:(old-develop) ✗ cd external
➜  external git:(old-develop) ✗ ln -s ../../../gladius-core/external/* .
ln: failed to create symbolic link `./require.js': File exists
➜  external git:(old-develop) ✗ ls -l
total 80
lrwxrwxrwx 1 chris chris    39 Jun  1 23:47 box2d.js -> ../../../gladius-core/external/box2d.js
lrwxrwxrwx 1 chris chris    41 Jun  1 23:47 CubicVR.js -> ../../../gladius-core/external/CubicVR.js
lrwxrwxrwx 1 chris chris    35 Jun  1 23:47 math -> ../../../gladius-core/external/math
-rw-rw-r-- 1 chris chris 80727 Jun  1 23:43 require.js
Also, as mentioned in tutorial, I need two "procedural" files:
➜  external git:(old-develop) ✗ cd ..
➜  public git:(old-develop) ✗ cp ../../gladius-core/example/cube/procedural-m* .
➜  public git:(old-develop) ✗ ls -l
total 28
drwxrwxr-x 2 chris chris 4096 Jun  1 23:47 external
drwxr-xr-x 2 chris chris 4096 May 31 23:22 images
-rw-rw-r-- 1 chris chris 2540 Jun  1 23:48 index.html
drwxr-xr-x 2 chris chris 4096 Jun  1 23:44 javascripts
-rw-rw-r-- 1 chris chris   96 Jun  1 23:50 procedural-material.js
-rw-rw-r-- 1 chris chris 1313 Jun  1 23:50 procedural-mesh.js
drwxr-xr-x 2 chris chris 4096 May 31 23:22 stylesheets
No doubt I will learn what those do eventually, but for now...

I finally see something:


That is not terribly exciting and it does not move or anything. But after two nights, I think it is beautiful. Tomorrow, mayhaps I can get "develop" working in addition to "old-develop".


Day #404

No comments:

Post a Comment