Permalink
Browse files

git ribbon, other minor tweaks

  • Loading branch information...
1 parent 5d9e47d commit b5ec0e09ae171684e733363350879bd831b6c3ac coryondrejka committed Apr 18, 2011
Showing with 7,776 additions and 0 deletions.
  1. BIN images/forkme.png
  2. +765 −0 perf/css/perf.css
  3. +180 −0 test/engine/core/browser.js
  4. +107 −0 test/engine/core/canvas_render.js
  5. +106 −0 test/engine/core/clientcmd.js
  6. +19 −0 test/engine/core/clientutils.js
  7. +257 −0 test/engine/core/dom_render.js
  8. +259 −0 test/engine/core/gameframe.js
  9. +165 −0 test/engine/core/gob.js
  10. +77 −0 test/engine/core/igob.js
  11. +174 −0 test/engine/core/init.js
  12. +263 −0 test/engine/core/input.js
  13. +29 −0 test/engine/core/json2.min.js
  14. +281 −0 test/engine/core/render.js
  15. +186 −0 test/engine/core/spriteload.js
  16. +119 −0 test/engine/core/sprites.js
  17. +70 −0 test/engine/core/tick.js
  18. +477 −0 test/engine/core/ui.js
  19. +113 −0 test/engine/core/utils.js
  20. +401 −0 test/engine/core/webgl_debug.js
  21. +179 −0 test/engine/core/webgl_material.js
  22. +154 −0 test/engine/core/webgl_model.js
  23. +178 −0 test/engine/core/webgl_render.js
  24. +167 −0 test/engine/core/webgl_sprite.js
  25. +58 −0 test/engine/core/webgl_texture.js
  26. +324 −0 test/engine/core/webgl_util.js
  27. +184 −0 test/engine/core/world.js
  28. +186 −0 test/engine/core/world_3d.js
  29. +147 −0 test/engine/css/style.css
  30. +244 −0 test/engine/shared/grid.js
  31. +106 −0 test/engine/shared/gridclient.js
  32. +37 −0 test/engine/utils/math.js
  33. +491 −0 test/engine/utils/math_3d.js
  34. +124 −0 test/engine/utils/vec.js
  35. +110 −0 test/perf/benchmark.js
  36. +62 −0 test/perf/fbmark.js
  37. +62 −0 test/perf/index.html
  38. +407 −0 test/perf/perf.js
  39. +449 −0 test/perf/perftest.js
  40. +59 −0 test/perf/static.html
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -0,0 +1,180 @@
+// Copyright 2004-present Facebook. All Rights Reserved.
+
+// Licensed under the Apache License, Version 2.0 (the "License"); you may
+// not use this file except in compliance with the License. You may obtain
+// a copy of the License at
+
+// http://www.apache.org/licenses/LICENSE-2.0
+
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations
+// under the License.
+
+var exports = {}; // compatibility with nodejs
+
+var Browser = (function() {
+ var Browser = {
+ CHROME: 1,
+ FIREFOX: 2,
+ WEBKIT: 3,
+ IE: 4,
+ IE9: 5,
+ OPERA: 6,
+ OTHER: -99,
+
+ browser: 0,
+ mobile: false,
+ ios: false,
+ threeD: false,
+ os: '',
+
+ winsize: [0,0],
+ winpos: [0,0]
+ }
+
+ function detect() {
+ var user_agent = navigator.userAgent.toLowerCase();
+
+ if (/chrome/.test(user_agent)) {
+ Browser.browser = Browser.CHROME;
+ Browser.threeD = true;
+ }
+ else if (/webkit/.test(user_agent)) {
+ Browser.browser = Browser.WEBKIT;
+ Browser.threeD = true;
+ }
+ else if (/gecko/.test(user_agent)) {
+ Browser.browser = Browser.FIREFOX;
+ Browser.threeD = false;
+ }
+ else if (/msie 9/.test(user_agent)) {
+ Browser.browser = Browser.IE9;
+ Browser.threeD = false;
+ }
+ else if (/msie/.test(user_agent)) {
+ Browser.browser = Browser.IE;
+ Browser.threeD = false;
+ }
+ else if (/opera/.test(user_agent)) {
+ Browser.browser = Browser.OPERA;
+ Browser.threeD = false;
+ }
+ else {
+ Browser.browser = Browser.OTHER;
+ Browser.threeD = false;
+ }
+
+ if (/iphone/.test(user_agent)) {
+ Browser.threeD = true;
+ Browser.mobile = true;
+ Browser.ios = true;
+ Browser.os = 'iPhone';
+ }
+ else if (/ipod/.test(user_agent)) {
+ Browser.threeD = true;
+ Browser.mobile = true;
+ Browser.os = 'iPod';
+ }
+ else if (/ipad/.test(user_agent)) {
+ Browser.threeD = true;
+ Browser.mobile = true;
+ Browser.ios = true;
+ Browser.os = 'iPad';
+ }
+ else if (/os x/.test(user_agent)) {
+ Browser.os = 'OS X';
+ }
+ else if (/android/.test(user_agent)) {
+ Browser.mobile = true;
+ Browser.threeD = false;
+ Browser.os = 'Android';
+ }
+ else if (/linux/.test(user_agent)) {
+ Browser.os = 'Linux';
+ }
+ else if (/windows phone/.test(user_agent)) {
+ Browser.os = 'Win Mobile';
+ }
+ else if (/windows/.test(user_agent)) {
+ Browser.os = 'Windows';
+ }
+ else {
+ Browser.os = '?';
+ }
+
+ switch (Browser.browser) {
+ case Browser.CHROME:
+ version = user_agent.toLowerCase().match(/chrome\/([\d\w\.]+)\s/);
+ if (version) {
+ Browser.browser_version = 'Chrome ' + version[1].match(/(\d+)\..*/)[1];
+ } else {
+ Browser.browser_version = 'Chrome';
+ }
+ break;
+ case Browser.FIREFOX:
+ version = user_agent.toLowerCase().match(/firefox\/([\d\w\.]+)/);
+ if (version) {
+ Browser.browser_version = 'Firefox ' + version[1].match(/(\d+)\..*/)[1];
+ } else {
+ Browser.browser_version = 'Firefox';
+ }
+ break;
+ case Browser.WEBKIT:
+ version = user_agent.toLowerCase().match(/safari\/([\d\w\.]+)/);
+ if (version) {
+ Browser.browser_version = 'Safari ' + version[1].match(/(\d+)\..*/)[1];
+ } else {
+ Browser.browser_version = 'Safari';
+ }
+ break;
+ case Browser.IE:
+ case Browser.IE9:
+ version = user_agent.toLowerCase().match(/msie ([\d\w\.]+);/);
+ if (version) {
+ Browser.browser_version = 'IE ' + version[1].match(/(\d+)\..*/)[1];
+ } else {
+ Browser.browser_version = 'IE';
+ }
+ break;
+ case Browser.OPERA:
+ version = user_agent.toLowerCase().match(/version\/([\d\w\.]+)/);
+ if (version) {
+ Browser.browser_version = 'Opera ' + version[1].match(/(\d+)\..*/)[1];
+ } else {
+ Browser.browser_version = 'Opera';
+ }
+ break;
+ }
+ Browser.browser_version = Browser.os + ' ' + Browser.browser_version;
+ console.log('browser_version ' + Browser.browser_version);
+ }
+
+ function getWindowSize() {
+ var width = 0;
+ var height = 0;
+
+ if (typeof(window.innerWidth) == 'number') {
+ width = window.innerWidth;
+ height = window.innerHeight;
+ } else if (window.document.documentElement &&
+ (window.document.documentElement.clientWidth ||
+ window.document.documentElement.clientHeight)) {
+ width = window.document.documentElement.clientWidth;
+ height = window.document.documentElement.clientHeight;
+ } else if (window.document.body &&
+ (window.document.body.clientWidth ||
+ window.document.body.clientHeight)) {
+ width = window.document.body.clientWidth;
+ height = window.document.body.clientHeight;
+ }
+
+ Browser.winsize[0] = width;
+ Browser.winsize[1] = height;
+ }
+
+ Browser.getWindowSize = getWindowSize;
+ Browser.detect = detect;
+ return Browser;
+ })();
@@ -0,0 +1,107 @@
+// Copyright 2004-present Facebook. All Rights Reserved.
+
+// Licensed under the Apache License, Version 2.0 (the "License"); you may
+// not use this file except in compliance with the License. You may obtain
+// a copy of the License at
+
+// http://www.apache.org/licenses/LICENSE-2.0
+
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations
+// under the License.
+
+var CanvasRender = (function() {
+ var ctx, bctx, parel, canvasel, bgel, cwidth, cheight, first, fdtctx;
+
+ function init(pid,width,height,pixelwidth,pixelheight) {
+ parel = document.getElementById(pid);
+ cwidth = pixelwidth;
+ cheight = pixelheight;
+
+ parel.innerHTML += '<canvas id="gcbg" width="' + pixelwidth + '" height="' +
+ pixelheight + '" style="position:absolute;left:0px;top:0px;width:' + width + 'px;height:' + height + 'px;"></canvas>';
+ parel.innerHTML += '<canvas id="gamecanvas" width="' + pixelwidth + '" height="' +
+ pixelheight + '" style="position:absolute;left:0px,top:0px;width:' + width + 'px;height:' + height + 'px;"></canvas>';
+ bgel = document.getElementById('gcbg');
+ bctx = bgel.getContext('2d');
+ canvasel = document.getElementById('gamecanvas');
+ ctx = canvasel.getContext('2d');
+ }
+
+ function initFDT() {
+ var el = document.getElementById('framedraw');
+ if (!el) {
+ el = document.createElement('canvas');
+ el.id = "framedraw";
+ el.width = 1;
+ el.height = 1;
+ document.body.appendChild(el);
+ }
+ fdtctx = el.getContext('2d');
+ }
+
+ function setFDT(number) {
+ if (fdtctx) {
+ fdtctx.fillStyle = "#" + number;
+ fdtctx.fillRect(0,0,1,1);
+ }
+ }
+
+ function readFDT() {
+ if (fdtctx) {
+ var data = fdtctx.getImageData(0,0,1,1);
+ var value = data.data[0]*256*256+data.data[1]*256+data.data[2];
+ }
+ return value;
+ }
+
+ function clear() {
+ ctx.clearRect(0, 0, cwidth, cheight);
+ if (GameFrame.settings.canvas_background && World.dirty) {
+ bctx.clearRect(0, 0, cwidth, cheight);
+ }
+ first = true;
+ }
+
+ function bgdraw(framedata) {
+ bctx.drawImage(framedata.image, framedata.x, framedata.y, framedata.size[0],
+ framedata.size[1], framedata.pos[0], framedata.pos[1],
+ framedata.size[0], framedata.size[1]);
+ }
+
+ function bg2fg() {
+ ctx.drawImage(bctx.canvas, 0, 0, cwidth, cheight, 0, 0, cwidth, cheight);
+ }
+
+ function draw(framedata) {
+ if (first || framedata.theta || framedata.scale != 1.0) {
+ first = false;
+ var ct = Math.cos(framedata.theta);
+ var st = Math.sin(framedata.theta);
+ var nst = -st;
+ ctx.transform(ct + 0.000001, st, nst, ct + 0.000001, (framedata.pos[0]+framedata.size[0]*0.5)|0, (framedata.pos[1]+framedata.size[1]*0.5)|0);
+// ctx.transform(ct, st, nst, ct, framedata.pos[0], framedata.pos[1]);
+ ctx.drawImage(framedata.image, framedata.x | 0, framedata.y | 0, framedata.size[0],
+ framedata.size[1], (-framedata.size[0]*0.5*framedata.scale) | 0, (-framedata.size[1]*0.5*framedata.scale) | 0, framedata.size[0]*framedata.scale, framedata.size[1]*framedata.scale);
+ ctx.setTransform(1, 0, 0, 1, 0, 0);
+ } else {
+ ctx.drawImage(framedata.image, framedata.x, framedata.y, framedata.size[0],
+ framedata.size[1], framedata.pos[0], framedata.pos[1],
+ framedata.size[0]*framedata.scale, framedata.size[1]*framedata.scale);
+ }
+
+ }
+
+ var CanvasRender = {};
+ CanvasRender.init = init;
+ CanvasRender.clear = clear;
+ CanvasRender.draw = draw;
+ CanvasRender.bgdraw = bgdraw;
+ CanvasRender.bg2fg = bg2fg;
+ CanvasRender.initFDT = initFDT;
+ CanvasRender.setFDT = setFDT;
+ CanvasRender.readFDT = readFDT;
+ return CanvasRender;
+ })();
@@ -0,0 +1,106 @@
+// Copyright 2004-present Facebook. All Rights Reserved.
+
+// Licensed under the Apache License, Version 2.0 (the "License"); you may
+// not use this file except in compliance with the License. You may obtain
+// a copy of the License at
+
+// http://www.apache.org/licenses/LICENSE-2.0
+
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations
+// under the License.
+
+var world_grid = {idx: 0};
+var ent_grid = {idx: 1, interp: {} };
+
+var client_user = {
+ unique_id: 0,
+ world_grid: world_grid,
+ ent_grid: ent_grid,
+ grids: [world_grid, ent_grid]
+};
+
+
+var ClientCmd = (function() {
+ function resetSession() {
+ client_user.unique_id = 0;
+ }
+
+ function startSession(id, app_id) {
+ client_user.unique_id = id;
+ client_user.app_id = app_id;
+ Init.reset();
+ }
+
+ function clientTest(a, b) {
+// console.log('clienttest: ' + [a, b]);
+ }
+
+ function disconnected(id) {
+// console.log('disconnected: ' + id);
+ }
+
+ function add(idx,obj) {
+ GridClient.recvAdd(client_user.grids[idx], obj);
+ }
+
+ function remove(idx,uuid,timestamp) {
+ GridClient.recvRemove(client_user.grids[idx], uuid, timestamp);
+ }
+
+ function transform(idx, uuid, options) {
+ GridClient.recvTransform(client_user.grids[idx], uuid, options);
+ }
+
+ var last_clock;
+ function clock(curr_msecs, frame_msecs) {
+ clock = parseInt(curr_msecs);
+ GridClient.params.clock_skew = clock - (new Date).getTime();
+ GridClient.params.frame_msecs = parseInt(frame_msecs);
+ Grid.setClockSkew(GridClient.params.clock_skew);
+ if (last_clock) {
+ var push_latency = clock - last_clock;
+ }
+ last_clock = clock;
+ }
+
+ var client_cmds = {};
+
+ var ClientCmd = {};
+
+ function install(name, func) {
+ client_cmds[name] = {func: func};
+ ClientCmd[name] = function() {
+ var command = {cmd: name, args: Array.prototype.slice.call(arguments)};
+ var ret = Utils.cmd_exec(client_cmds, null, command, true);
+ if (ret)
+ return ret;
+ }
+ }
+
+ install('resetsession', resetSession);
+ install('startsession', startSession);
+ install('clienttest', clientTest);
+ install('disconnected', disconnected);
+ install('add', add);
+ install('remove', remove);
+ install('transform', transform);
+ install('clock', clock);
+
+ function exec(cmd) {
+ //console.log("clientcmd: " + JSON.stringify(str));
+ var err = Utils.cmd_exec(client_cmds, null, cmd, false);
+ if (err)
+ {
+ console.log(err.args[0]);
+ }
+ }
+
+ ClientCmd.exec = exec;
+ ClientCmd.install = install;
+ return ClientCmd;
+ })();
+
+var Cmds = ClientCmd;
Oops, something went wrong.

0 comments on commit b5ec0e0

Please sign in to comment.