forked from facebookarchive/jsgamebench
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial checkin of the webgl benchmark
- Loading branch information
Showing
32 changed files
with
9,142 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,5 +62,5 @@ http.createServer(function(req, res) { | |
break; | ||
} | ||
} | ||
}).listen(8080); | ||
}).listen(8081); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<script type="text/javascript" src="http://connect.facebook.net/en_US/all.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<html> | ||
<head> | ||
<title>Trench Runner</title> | ||
|
||
<script type="text/javascript" src="http://connect.facebook.net/en_US/all.js"></script> | ||
|
||
#include 'app$id' | ||
#include 'app$url' | ||
#include '../engine/include/core.include' | ||
|
||
<!-- game stuff --> | ||
<script type="text/javascript" src="/models/Box_Model.js"></script> | ||
<script type="text/javascript" src="/models/Ship_Junebug_01.js"></script> | ||
<script type="text/javascript" src="/js/materials.js"></script> | ||
<script type="text/javascript" src="/js/track.js"></script> | ||
<script type="text/javascript" src="/js/camera.js"></script> | ||
<script type="text/javascript" src="/js/geometry_scaling.js"></script> | ||
<script type="text/javascript" src="/js/player.js"></script> | ||
<script type="text/javascript" src="/js/projectile.js"></script> | ||
<script type="text/javascript" src="/js/publish.js"></script> | ||
<script type="text/javascript" src="/js/init.js"></script> | ||
|
||
</head> | ||
<body | ||
onresize="Init.winresize();" | ||
onload="Init.init();" | ||
onorientationchange="Init.winresize();" | ||
onunload="Init.quit()"> | ||
<div id="fb-root"></div> | ||
<div id="gamebody"></div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
function init() { | ||
var canvas = document.getElementById("frontBuf"); | ||
try { | ||
gl = canvas.getContext("experimental-webgl"); | ||
} catch (e) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// 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 TrenchCamera = (function() { | ||
|
||
var aspect_ratio; | ||
var fovy = 0.55; | ||
var nearplane = 0.75; | ||
var farplane = 1000.0; | ||
var camera_distance = 6; | ||
|
||
var rotation_distance = 4; | ||
var rotation_rate = Math.PI * -0.2; | ||
var rotation = 0; | ||
|
||
function init(viewport) { | ||
// set up projection matrix, and thus the coordinate system as well | ||
aspect_ratio = viewport.width / viewport.height; | ||
World3D.setPerspectiveZUp(fovy, | ||
aspect_ratio, | ||
nearplane, | ||
farplane); | ||
} | ||
|
||
function reset() { | ||
var camera_matrix = Math3D.mat4x4(); | ||
World3D.setCamera(camera_matrix); | ||
} | ||
|
||
function tick(dt, paused) { | ||
var camera_pos = [0,0,0]; | ||
var camera_dir = [0,1,0]; | ||
var camera_up = [0,0,1]; | ||
|
||
// rotation_rate = 0; | ||
|
||
camera_up[2] = -Math.sin(rotation); | ||
camera_up[0] = Math.cos(rotation); | ||
rotation += dt * rotation_rate; | ||
while (rotation > 2 * Math.PI) { | ||
rotation -= 2 * Math.PI; | ||
} | ||
|
||
/* | ||
var player_pos = TrenchPlayer.getPosition(); | ||
if (paused) { | ||
camera_dir[0] = Math.sin(rotation); | ||
camera_dir[1] = Math.cos(rotation); | ||
Math3D.addVec3Self(camera_pos, | ||
Math3D.scaleVec3(camera_dir, | ||
-rotation_distance) | ||
); | ||
rotation += dt * rotation_rate; | ||
while (rotation > 2 * Math.PI) { | ||
rotation -= 2 * Math.PI; | ||
} | ||
} else { | ||
camera_pos[1] = player_pos[1] - camera_distance; | ||
player_pos[1] = 0; | ||
var dist = Math3D.normalizeVec3(player_pos); | ||
var cam_dist = dist * dist * 0.25; | ||
if (cam_dist > dist * 0.75) { | ||
cam_dist = dist * 0.75; | ||
} | ||
Math3D.scaleVec3Self(player_pos, cam_dist); | ||
camera_pos[0] = player_pos[0]; | ||
camera_pos[2] = player_pos[2] + 2.5; | ||
rotation = 0; | ||
} | ||
*/ | ||
var camera_matrix = Math3D.mat4x4(); | ||
Math3D.orientMat4x4(camera_matrix, camera_dir, camera_up); | ||
Math3D.translateMat4x4(camera_matrix, camera_pos); | ||
World3D.setCamera(camera_matrix); | ||
} | ||
|
||
var TrenchCamera = {}; | ||
TrenchCamera.init = init; | ||
TrenchCamera.reset = reset; | ||
TrenchCamera.tick = tick; | ||
return TrenchCamera; | ||
})(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// 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 GeometryScaling = (function() { | ||
|
||
var block_counter = 0; | ||
var block_model; | ||
|
||
function placeBlock(vmin, vmax) { | ||
var worldmat = Math3D.mat4x4(); | ||
worldmat[0] = vmax[0] - vmin[0]; | ||
worldmat[5] = vmax[1] - vmin[1]; | ||
worldmat[10] = vmax[2] - vmin[2]; | ||
worldmat[12] = vmin[0]; | ||
worldmat[13] = vmin[1]; | ||
worldmat[14] = vmin[2]; | ||
World3D.addStatic(block_counter, block_model, worldmat, vmin, vmax); | ||
++block_counter; | ||
} | ||
|
||
function init(model) { | ||
block_model = model; | ||
for (var ii = 0; ii < block_counter; ++ii) { | ||
World3D.updateStatic(ii, block_model); | ||
} | ||
} | ||
|
||
function reset(block_count_x, block_count_y, block_count_z) { | ||
for (var ii = 0; ii < block_counter; ++ii) { | ||
World3D.removeStatic(ii); | ||
} | ||
block_counter = 0; | ||
|
||
var aspect_ratio = 640 / 480; | ||
var block_delta_x = 200 / block_count_x; | ||
var block_delta_y = 100 / block_count_y; | ||
var block_delta_z = 200 / block_count_z; | ||
|
||
var block_start_x = -block_delta_x * block_count_x / 2 + block_delta_x / 2; | ||
var block_start_y = 150; | ||
var block_start_z = -block_delta_z * block_count_z / 2 + block_delta_y / 2; | ||
|
||
block_size = block_delta_x * 0.45; | ||
|
||
for (var iz = 0; iz < block_count_z; ++iz) { | ||
for (var iy = 0; iy < block_count_y; ++iy) { | ||
for (var ix = 0; ix < block_count_x; ++ix) { | ||
var x = block_delta_x * ix + block_start_x; | ||
var y = block_delta_y * iy + block_start_y; | ||
var z = block_delta_z * iz + block_start_z; | ||
|
||
placeBlock([x - block_size/2, y - block_size/2, z - block_size/2], | ||
[x + block_size/2, y + block_size/2, z + block_size/2]); | ||
} | ||
} | ||
} | ||
} | ||
|
||
function tick(dt) { | ||
} | ||
|
||
var GeometryScaling = {}; | ||
GeometryScaling.init = init; | ||
GeometryScaling.reset = reset; | ||
GeometryScaling.tick = tick; | ||
return GeometryScaling; | ||
})(); |
Oops, something went wrong.