Skip to content
This repository has been archived by the owner on Jan 13, 2022. It is now read-only.

Commit

Permalink
Merge branch 'master' of github.com:facebook/jsgamebench
Browse files Browse the repository at this point in the history
  • Loading branch information
brucero committed May 3, 2011
2 parents 9a6b00a + 37330b3 commit 80381e2
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 7 deletions.
5 changes: 5 additions & 0 deletions engine/core/gameframe.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,14 @@ var GameFrame = (function() {
css_keyframe: true,
int_snap: true,
transform3d: true,
disable_world_elements: false,
disable_sprite_anim: false,
sprite_url_override: null,
sprite_scale: 1.0,
webgl_blended_canvas: false,
webgl_debug: false,
webgl_batch_sprites: false,
use_request_animation_frame: true,
offset: 0,
hidefps: false,
viewport: 'fluid'
Expand Down
6 changes: 4 additions & 2 deletions engine/core/gob.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ var Gob = (function() {
// go looking for non-sprite sheet version
sprite = Sprites.spritedictionary[spriteid+"0"];
}
if (frame >= sprite.frames)
if (frame >= sprite.frames || sprite.no_anim) {
frame = 0;
gobs[id] = {id: id, spriteid: basesprite, frame: frame, pos: pos, vel: (vel ? vel : vel), theta: (vel ? Math.atan2(vel[1],vel[0]) : 0), scale: (scale ? scale : 1), z: (z ? z : Math.random() * 2000), dirty: true, time: Tick.current, atime: Tick.current, animate: false, discon: true};
}
scale = (scale || 1.0) * GameFrame.settings.sprite_scale;
gobs[id] = {id: id, spriteid: basesprite, frame: frame, pos: pos, vel: vel, theta: (vel ? Math.atan2(vel[1],vel[0]) : 0), scale: scale, z: (z ? z : Math.random() * 2000), dirty: true, time: Tick.current, atime: Tick.current, animate: false, discon: true};
return gobs[id];
}

Expand Down
23 changes: 20 additions & 3 deletions engine/core/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ var Init = (function() {
var teardownFunc = null;
var quitFunc = null;
var resizeFunc = null;
var requestAnimationFrameFunc = null;
var maxFPS = 1000;
var spritesLoaded = false;

Expand All @@ -37,7 +38,7 @@ var Init = (function() {
maxFPS = args.fps || undefined;
}

function quit() {
function quit() {
quitFunc();
}

Expand All @@ -46,10 +47,18 @@ var Init = (function() {

function timer_kick_off() {
Render.setupBrowserSpecific();
setInterval('Init.tick();', parseInt(1000/maxFPS));
requestAnimationFrameFunc = (window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function(callback, element) {
window.setTimeout(callback, 1000/maxFPS);
});
initFunc();
winresize();
setupFunc();
kickoff_tick();
}

function tick() {
Expand All @@ -63,6 +72,15 @@ var Init = (function() {
drawFunc();
}
uiFunc();
kickoff_tick();
}

function kickoff_tick() {
if (GameFrame.settings.use_request_animation_frame) {
requestAnimationFrameFunc(tick);
} else {
window.setTimeout(tick, 1000/maxFPS);
}
}

function reset() {
Expand Down Expand Up @@ -166,7 +184,6 @@ var Init = (function() {
Init.init = init;
Init.winresize = winresize;
Init.quit = quit;
Init.tick = tick;
Init.reset = reset;
Init.hideBar = hideBar;
Init.setFunctions = setFunctions;
Expand Down
5 changes: 4 additions & 1 deletion engine/core/sprites.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ var Sprites = (function() {
data.width /= 2;
data.height /= 2;
}

data.url = GameFrame.settings.sprite_url_override || data.url;

if (spritedictionary[id] === undefined) {
if (data.left === undefined) {
data.left = 0;
Expand All @@ -57,7 +60,7 @@ var Sprites = (function() {
}
spritedictionary[id] = data;
spritedictionary[id].id = spriteid++;
spritedictionary[id].no_anim = data.no_anim;
spritedictionary[id].no_anim = data.no_anim || GameFrame.settings.disable_sprite_anim;
spritedictionary[id].imageel = new Image();
spritedictionary[id].imageel.id = id;
spritedictionary[id].imageel.onload = function(event) {
Expand Down
1 change: 1 addition & 0 deletions engine/core/webgl_render.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ var WebGLRender = (function() {
return;
}

gl.setDrawContext(null);
gl.flush();
}

Expand Down
5 changes: 4 additions & 1 deletion engine/core/world.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ var World = (function() {
var elements = {};

function add(id, spriteid, pos, zindex) {
if (GameFrame.settings.disable_world_elements) {
return;
}
if (!elements[id] || elements[id].pos[0] != pos[0] || elements[id].pos[1] != pos[1] || elements[id].spriteid != spriteid) {
World.dirty = true;
elements[id] = {id: id, spriteid: spriteid, pos: pos,
Expand Down Expand Up @@ -155,7 +158,7 @@ var World = (function() {
var retval = {dirty: element.dirty,
pos: pos,
size: [sprite.width, sprite.height],
theta: 0,scale:1,
theta: 0, scale: GameFrame.settings.sprite_scale,
x: 0,
y: 0,
zindex: sprite.zindex,
Expand Down
Binary file added images/white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions perf/perf.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ var Perf = (function() {
{
render_mode: GameFrame.WEBGL,
sprite_sheets: true, int_snap: false,
//disable_sprite_anim: true, sprite_url_override: 'images/white.png', sprite_scale: 0.01,
disable_world_elements: true,
webgl_debug: false, webgl_blended_canvas: false, webgl_batch_sprites: true
},
tfps: 30, background: 'world', sprites: 'rot', demo: true
Expand Down

0 comments on commit 80381e2

Please sign in to comment.