Permalink
Browse files

second commit

  • Loading branch information...
1 parent 4138e00 commit 2dbc34f36a0fed6ab893ef27d78980aafecbc62c Tema committed Jun 3, 2011
Showing with 11,209 additions and 0 deletions.
  1. +56 −0 app.js
  2. +10,864 −0 box2d.js
  3. +121 −0 common.js
  4. +168 −0 demo.html
View
56 app.js
@@ -0,0 +1,56 @@
+var http = require('http'), io = require('socket.io'), sys = require("sys"), fs = require('fs');
+
+var Box2D = require('/home/tema/Desktop/boxxy/box2d.js');
+
+eval(fs.readFileSync('common.js') + '');
+
+var clients = [];
+
+function update() {
+ world.Step(1 / 60, 10, 10);
+ world.ClearForces();
+}
+setInterval(update, 1000 / 60);
+
+function jointsToClients(data) {
+ for (var i = 0; i < clients.length; i++) {
+ clients[i].send(data);
+ }
+}
+
+setupWorld();
+
+// SOCKETS
+
+var server = http.createServer(
+ function(req, res){
+ res.writeHead(200, {'Content-Type': 'text/html'});
+ res.end('<h1>Hello world</h1>');
+ }
+);
+server.listen(xport, "127.0.0.1");
+
+var socket = io.listen(server);
+
+socket.on('connection', function(client) {
+ clients.push(client);
+ console.log("Total clients: " + clients.length);
+
+ client.send({"startId" : clients.length});
+
+ client.on('message', function(data){
+
+ if (data.hasOwnProperty("destroyId")) {
+ deleteJoint(data.destroyId);
+ console.log('destroyed');
+ } else {
+ updateJoints(data);
+ }
+
+ jointsToClients(data);
+ });
+
+ client.on('disconnect', function(){
+ console.log("disconnect");
+ });
+});
Oops, something went wrong.

0 comments on commit 2dbc34f

Please sign in to comment.