Skip to content

Commit

Permalink
closure compiler advanced #1
Browse files Browse the repository at this point in the history
  • Loading branch information
octopoulos authored and Aloril committed Feb 16, 2021
1 parent 5f82b8b commit 6292b8b
Show file tree
Hide file tree
Showing 21 changed files with 1,586 additions and 1,511 deletions.
1 change: 1 addition & 0 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ DONE CREATED DESCRIPTION
- : 2021-01-23 : speed: add_moves_string should reuse the nodes, instead of HTML(...)
- : 2021-01-27 : pv should show fails
- : 2021-01-29 : precalculate agree + agree2 in a worker thread with wasm.js
2021-02-05 : 2021-02-05 : closure compiler advanced #1
2021-01-27 : 2021-01-27 : add engine tests
2021-01-27 : 2021-01-27 : improve inspector.py
2021-01-27 : 2021-01-27 : move populate_areas + move_pane to engine
Expand Down
6 changes: 3 additions & 3 deletions analyse_pgn.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// analyse_pgn.js
// @author octopoulo <[email protected]>
// @version 2021-02-02
// @version 2021-02-05
/*
globals
process, require
Expand Down Expand Up @@ -302,7 +302,7 @@ function merge_stats(result) {
* Open a file and process it
* @param {string} filename
* @param {Object} result
* @param {function} callback
* @param {Function} callback
*/
function open_file(filename, result, callback) {
let ext = filename.split('.').slice(-1)[0],
Expand Down Expand Up @@ -359,7 +359,7 @@ function open_file(filename, result, callback) {
/**
* Show the results
* @param {Object} result
* @param {string[]} filenames
* @param {Array<string>} filenames
*/
function done(result, filenames) {
let [day] = FromTimestamp(),
Expand Down
5 changes: 2 additions & 3 deletions chat_server.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// chat_server.js
// @authors octopoulo <[email protected]>, Aloril <[email protected]>
// @version 2020-10-30
// @version 2021-02-05
/*
globals
console, exports, require
Expand Down Expand Up @@ -32,8 +32,7 @@ async function load_wasm() {
LS('chess library loaded');
}

function vote(data)
{
function vote(data) {
LS('vote, data=' + Stringify(data));
if (typeof data.fen == "string") { //needed because fen string here don't match fen strings in Python
let lst = data.fen.split(" ");
Expand Down
3 changes: 1 addition & 2 deletions check.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ var fs = require('fs');
// var path = require('path');
const argv = require('yargs').argv;

function checkJson(gameJson)
{
function checkJson(gameJson) {
// var jsonStr = '';
try {
JSON.parse(fs.readFileSync(gameJson, "utf-8"));
Expand Down
81 changes: 47 additions & 34 deletions js/3d.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
// 3d.js
// @author octopoulo <[email protected]>
// @version 2021-02-03
// @version 2021-02-05
//
// general 3d rendering code
//
// included after: common, engine, global
// jshint -W069
/*
globals
_, Abs, add_timeout, AnimationFrame, Assign, Attrs, Audio, C, CameraControls, clear_timeout,
DefaultInt, DEV, document, Events, Exp, exports, Format, global, HTML, Id, IsString, KEY_TIMES, Keys, KEYS,
load_library, LS, navigator, Now, require,
S, save_option, set_modal_events, Show, Stats, Style, T:true, THREE, translate_nodes, Visible, window, Y
S, save_option, set_modal_events, Show, Stats, Style, T:true, THREE, translate_nodes, Vector2:true, Visible, window, Y
*/
'use strict';

Expand Down Expand Up @@ -95,12 +96,10 @@ let audiobox = {
next_paused,
now,
now2,
Object3D,
old_pos,
old_rot,
PARENT_3D = 'body',
PARTS = [],
Quaternion,
raycaster,
rendered = 0,
renderer,
Expand Down Expand Up @@ -133,8 +132,6 @@ let audiobox = {
VECTOR_X,
VECTOR_Y,
VECTOR_Z,
Vector2,
Vector3,
VECTORS,
vibration,
virtual_animate_scenery,
Expand All @@ -161,6 +158,21 @@ let audiobox = {

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/** @typedef {{x:number, y:number, z:number, w:number}} */
let Quaternion;
/** @typedef {{x:number, y:number, z:number}} */
let Vector3;

/**
* @typedef {{
* position: Vector3,
* quaternion: Quaternion,
* rotation: *,
* }} */
let Object3D;

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// 3D
/////

Expand Down Expand Up @@ -252,11 +264,11 @@ function init_3d(force) {
shadowMapSoft: true,
toneMappingExposure: 3.2,
});
renderer.shadowMap.enabled = !!Y.shadow;
renderer.shadowMap.enabled = !!Y['shadow'];
// renderer.shadowMap.type = T.PCFSoftShadowMap;

// more
if (DEV.frame) {
if (DEV['frame']) {
stats = new window.Stats();
stats.showPanel(0); // 0: fps, 1: ms, 2: mb, 3+: custom
document.body.appendChild(stats.dom);
Expand Down Expand Up @@ -393,7 +405,7 @@ function load_model(name, filename, callback) {

/**
* Load multiple models
* @param {Object} filenames
* @param {!Object} filenames
* @param {Function} callback
*/
function load_models(filenames, callback) {
Expand All @@ -419,7 +431,7 @@ function load_models(filenames, callback) {
* @param {number=} y
* @param {number=} z
* @param {number=} w
* @returns {Object}
* @returns {Quaternion}
*/
function new_quaternion(x, y, z, w) {
return new Quaternion(x, y, z, w);
Expand Down Expand Up @@ -622,12 +634,12 @@ function render() {

/**
* Request a render
* @param {Object|number} timer
* @param {Object|number=} timer
*/
function request_render(timer) {
if (dirty & 4)
return;
if (dirty && (!timer || !Number.isFinite(timer)))
if (dirty && (!timer || isNaN(timer)))
return;
dirty = 2;
AnimationFrame(render);
Expand Down Expand Up @@ -697,7 +709,7 @@ function resize_3d() {

/**
* Set controls to the current camera
* @param {boolean=} pause
* @param {boolean} pause
* @param {Vector3} target
* @param {boolean=} transition
*/
Expand Down Expand Up @@ -764,7 +776,7 @@ function update_light_settings() {

let exists = light_main.quality,
[main_intensity, under_intensity, quality] =
virtual_update_light_settings_special? virtual_update_light_settings_special(): [1, 1, Y.shadow];
virtual_update_light_settings_special? virtual_update_light_settings_special(): [1, 1, Y['shadow']];

light_main.intensity = main_intensity;
light_main.castShadow = !!quality;
Expand Down Expand Up @@ -808,14 +820,14 @@ function update_renderer() {
if (renderer) {
let ratio = 4;
if (Y.x == 'play')
ratio = DefaultInt((Y.resolution || '').split(':').slice(-1)[0], 2);
ratio = DefaultInt((Y['resolution'] || '').split(':').slice(-1)[0], 2);

if (three_loaded)
renderer.outputEncoding = T[`${Y.encoding}Encoding`] || T.sRGBEncoding;
renderer.toneMappingExposure = Y.exposure;
renderer.gammaFactor = Y.gamma;
renderer.outputEncoding = T[`${Y['encoding']}Encoding`] || T.sRGBEncoding;
renderer.toneMappingExposure = Y['exposure'];
renderer.gammaFactor = Y['gamma'];
renderer.setPixelRatio(window.devicePixelRatio / ratio);
renderer.shadowMap.enabled = !!Y.shadow;
renderer.shadowMap.enabled = !!Y['shadow'];
}
update_light_settings();

Expand All @@ -839,7 +851,7 @@ function update_time(delta) {

/**
* Convert a btQuaternion to Quaternion
* @param {Object} quaternion
* @param {!Object} quaternion
* @param {Object=} target
* @returns {Object}
*/
Expand All @@ -851,7 +863,7 @@ function three_quat(quaternion, target) {

/**
* Convert a bVector3 to T.Vector3
* @param {Object} vector
* @param {!Object} vector
* @param {Vector3=} target
* @returns {Vector3}
*/
Expand Down Expand Up @@ -963,15 +975,16 @@ function gamepad_update() {
* Play a sound
* @param {Cube} cube
* @param {string} name
* @param {string=} _ filename
* @param {string=} ext
* @param {number=} cycle end of the cycle
* @param {boolean=} inside
* @param {boolean=} interrupt play the sound again even if it's being played
* @param {Function=} loaded only load the audio
* @param {number=} start start of the 2nd cycle
* @param {boolean=} voice
* @param {number=} volume
* @param {Object} obj
* @param {string=} obj._ filename
* @param {string=} obj.ext
* @param {number=} obj.cycle end of the cycle
* @param {boolean=} obj.inside
* @param {boolean=} obj.interrupt play the sound again even if it's being played
* @param {Function=} obj.loaded only load the audio
* @param {number=} obj.start start of the 2nd cycle
* @param {boolean=} obj.voice
* @param {number=} obj.volume
* @returns {boolean}
*/
function play_sound(cube, name, {_, cycle, ext='ogg', inside, interrupt, loaded, start=0, voice, volume=1}={}) {
Expand All @@ -995,7 +1008,7 @@ function play_sound(cube, name, {_, cycle, ext='ogg', inside, interrupt, loaded,
if (!isNaN(cube.camera))
volume *= Exp(-cube.camera * 0.0072);

volume *= Y.volume / 10;
volume *= Y['volume'] / 10;
if ((inside || voice) && !cube.see)
volume *= 0.05;

Expand Down Expand Up @@ -1083,7 +1096,7 @@ function gamepad_modal() {
* @returns {boolean}
*/
function is_overlay_visible() {
return Visible(Id('overlay'));
return !!Visible(Id('overlay'));
}

/**
Expand Down Expand Up @@ -1146,7 +1159,7 @@ function update_debug() {
sep = ' : ';

// gamepad
if (DEV.input) {
if (DEV['input']) {
lines.push('&nbsp;');
lines.push(`id=${gamepad_id}`);
lines.push(`axes=${Format(axes, sep)}`);
Expand All @@ -1157,7 +1170,7 @@ function update_debug() {
}

// debugs
if (DEV.debug) {
if (DEV['debug']) {
let debug_keys = Keys(debugs).sort();
if (debug_keys.length) {
lines.push('&nbsp;');
Expand Down
Loading

0 comments on commit 6292b8b

Please sign in to comment.