scenevr / server

:heart_eyes: Create multiuser 3d environments using html-like tags and javascript
http://www.scenevr.com/
BSD 3-Clause "New" or "Revised" License
144 stars 19 forks source link

Get multi-scene serving working #11

Closed bnolan closed 9 years ago

bnolan commented 9 years ago

I started work on this in the multi branch, and it sort of works for static scenes, but due to the document global, I don't think it'll work for scenes with scripts. Refactor how we use document, so that when the scripts are eval'd - there is a unique scene and document object in the scope. The branch also doesn't automatically serve every file in the directory, nor does it successfully restart on scene change. Fix these and it should be good to merge.

bnolan commented 9 years ago

Working on this. Using glob to find all .xml files to serve. I want to start catching some user script errors to prevent the node process going down when <script /> blocks cause uncaught errors. Might want to wrap setInterval and setTimeout so that they can't raise errors.

bnolan commented 9 years ago

Totally using a document singleton (and I don't know how to make copies of Documents at the moment). I'll write a test, and once that's fixed we should be a lot closer.

bnolan commented 9 years ago

Got this spec:

describe 'compartmentalization', ->
  xml1 = "<scene><script>document.foo = 'bar';</script></scene>"
  xml2 = "<scene><script>console.dump(document.foo)</script></scene>"

  it 'should have seperate document instances', ->
    dumped = {}

    console.dump = (obj) ->
      console.log JSON.stringify(obj)
      dumped = obj

    Scene.load xml1, (scene1) ->
      Scene.load xml2, (scene2) ->
        expect(dumped).toBeNull()

Fails at the moment. Once I get this (and the rest of the suite) passing we should be most of the way there.

bnolan commented 9 years ago

All the specs pass woo! I've refactored so that scene isn't exported as a global, you need to use document.scene, which means I have to fix all the sample scenes. Also, the 'ready' event is fired on document, modelleted on domcontentloaded.

sirkitree commented 9 years ago

:+1:

bnolan commented 9 years ago

Handling exceptions in the parsing the scene now. The line numbers are wrong though, since we don't keep track of the line number of the start of the script block when we parse the xml. See issue #22.

[server] ./scenes/click_to_divide.xml
  ReferenceError: scene is not defined
    at ./scenes/click_to_divide.xml:23:5
bnolan commented 9 years ago

Got pretty close in fc79e0d, but scripts aren't running properly now. Will try and get this sorted tonight.

bnolan commented 9 years ago

Okay everything works on bbe7e9e8eef9f28f7944fc2def08e2d87e0716fe. I'm gonna call that working, and ship it. Opening a new issue to kill intervals and timeouts when calling scene#stop, see #24.