mirror of
https://github.com/boxgaming/qbjs.git
synced 2024-09-20 04:24:45 +00:00
Cleaned up code, alphabetized messy sections, etc.
This commit is contained in:
parent
249e527cda
commit
4c98443861
1 changed files with 49 additions and 51 deletions
100
qb.js
100
qb.js
|
@ -6,41 +6,41 @@ var QB = new function() {
|
||||||
this.SQUAREPIXELS = Symbol("SQUAREPIXELS");
|
this.SQUAREPIXELS = Symbol("SQUAREPIXELS");
|
||||||
this.OFF = Symbol("OFF");
|
this.OFF = Symbol("OFF");
|
||||||
|
|
||||||
var _strokeLineThickness = 2;
|
var _activeImage = 0;
|
||||||
var _windowDef = [];
|
|
||||||
var _windowAspect = [];
|
|
||||||
var _screenDiag;
|
|
||||||
var _strokeDrawLength = null;
|
|
||||||
var _strokeDrawAngle = null;
|
|
||||||
var _strokeDrawColor = null;
|
|
||||||
var _fgColor = null;
|
|
||||||
var _bgColor = null;
|
var _bgColor = null;
|
||||||
var _colormap = [];
|
var _colormap = [];
|
||||||
var _locX = 0;
|
var _currScreenImage = null;
|
||||||
var _locY = 0;
|
var _dataBulk = [];
|
||||||
var _lastKey = null;
|
var _dataLabelMap;
|
||||||
|
var _fgColor = null;
|
||||||
|
var _haltedFlag = false;
|
||||||
|
var _images = {};
|
||||||
var _inkeyBuffer = [];
|
var _inkeyBuffer = [];
|
||||||
var _keyHitBuffer = [];
|
|
||||||
var _keyDownMap = {};
|
|
||||||
var _inkeymap = {};
|
var _inkeymap = {};
|
||||||
var _inkeynp = {};
|
var _inkeynp = {};
|
||||||
var _keyhitmap = {};
|
|
||||||
var _inputMode = false;
|
var _inputMode = false;
|
||||||
var _haltedFlag = false;
|
var _keyDownMap = {};
|
||||||
var _runningFlag = false;
|
var _keyHitBuffer = [];
|
||||||
var _images = {};
|
var _keyhitmap = {};
|
||||||
var _activeImage = 0;
|
var _lastLimitTime;
|
||||||
var _sourceImage = 0;
|
var _lastKey = null;
|
||||||
|
var _locX = 0;
|
||||||
|
var _locY = 0;
|
||||||
var _nextImageId = 1000;
|
var _nextImageId = 1000;
|
||||||
var _lastLimitTime = new Date();
|
var _readCursorPosition;
|
||||||
var _resize = false;
|
var _resize = false;
|
||||||
var _resizeWidth = 0;
|
var _resizeWidth = 0;
|
||||||
var _resizeHeight = 0;
|
var _resizeHeight = 0;
|
||||||
var _currScreenImage = null;
|
var _rndSeed;
|
||||||
var _dataBulk = [];
|
var _runningFlag = false;
|
||||||
var _readCursorPosition;
|
var _screenDiagInv;
|
||||||
var _dataLabelMap = new Map();
|
var _sourceImage = 0;
|
||||||
var _rndSeed = 327680;
|
var _strokeDrawLength = null;
|
||||||
|
var _strokeDrawAngle = null;
|
||||||
|
var _strokeDrawColor = null;
|
||||||
|
var _strokeLineThickness = 2;
|
||||||
|
var _windowAspect = [];
|
||||||
|
var _windowDef = [];
|
||||||
|
|
||||||
// Array handling methods
|
// Array handling methods
|
||||||
// ----------------------------------------------------
|
// ----------------------------------------------------
|
||||||
|
@ -117,12 +117,16 @@ var QB = new function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.start = function() {
|
this.start = function() {
|
||||||
_runningFlag = true;
|
|
||||||
_haltedFlag = false;
|
|
||||||
_nextImageId = 1000;
|
|
||||||
_activeImage = 0;
|
_activeImage = 0;
|
||||||
_sourceImage = 0;
|
|
||||||
_currScreenImage = null;
|
_currScreenImage = null;
|
||||||
|
_dataLabelMap = new Map();
|
||||||
|
_haltedFlag = false;
|
||||||
|
_lastLimitTime = new Date();
|
||||||
|
_nextImageId = 1000;
|
||||||
|
_readCursorPosition = 0;
|
||||||
|
_rndSeed = 327680;
|
||||||
|
_runningFlag = true;
|
||||||
|
_sourceImage = 0;
|
||||||
GX._enableTouchMouse(true);
|
GX._enableTouchMouse(true);
|
||||||
GX.registerGameEvents(function(e){});
|
GX.registerGameEvents(function(e){});
|
||||||
QB.sub_Screen(0);
|
QB.sub_Screen(0);
|
||||||
|
@ -142,12 +146,12 @@ var QB = new function() {
|
||||||
// --------------------------------------------
|
// --------------------------------------------
|
||||||
this.func__Alpha = function(rgb, imageHandle) {
|
this.func__Alpha = function(rgb, imageHandle) {
|
||||||
// TODO: implement corresponding logic when an image handle is supplied (maybe)
|
// TODO: implement corresponding logic when an image handle is supplied (maybe)
|
||||||
return _color(rgb).a;// * 255;
|
return _color(rgb).a;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.func__Alpha32 = function(rgb) {
|
this.func__Alpha32 = function(rgb) {
|
||||||
// TODO: implement corresponding logic when an image handle is supplied (maybe)
|
// TODO: implement corresponding logic when an image handle is supplied (maybe)
|
||||||
return _color(rgb).a;// * 255;
|
return _color(rgb).a;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.func__Atan2 = function(y, x) {
|
this.func__Atan2 = function(y, x) {
|
||||||
|
@ -935,14 +939,12 @@ var QB = new function() {
|
||||||
vy = ux * Math.sin(ang) + uy * Math.cos(ang);
|
vy = ux * Math.sin(ang) + uy * Math.cos(ang);
|
||||||
vx *= (_strokeDrawLength/4);
|
vx *= (_strokeDrawLength/4);
|
||||||
vy *= (_strokeDrawLength/4);
|
vy *= (_strokeDrawLength/4);
|
||||||
wx = vx;
|
|
||||||
wy = vy;
|
|
||||||
} else {
|
} else {
|
||||||
vx = ux;
|
vx = ux;
|
||||||
vy = uy;
|
vy = uy;
|
||||||
wx = vx;
|
|
||||||
wy = vy;
|
|
||||||
}
|
}
|
||||||
|
wx = vx;
|
||||||
|
wy = vy;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cursXt = ux0 + wx;
|
cursXt = ux0 + wx;
|
||||||
|
@ -1184,7 +1186,7 @@ var QB = new function() {
|
||||||
screen.lastY = y;
|
screen.lastY = y;
|
||||||
|
|
||||||
ctx.lineWidth = _strokeLineThickness;
|
ctx.lineWidth = _strokeLineThickness;
|
||||||
ctx.lineWidth += Math.tanh(16*radius/_screenDiag); // Adds some radius to compensate for antialiasing. The 16 is arbitrary.
|
ctx.lineWidth += Math.tanh(8*radius*_screenDiagInv); // Adds some radius to compensate for antialiasing. The prefactor is arbitrary. //
|
||||||
ctx.strokeStyle = color.rgba();
|
ctx.strokeStyle = color.rgba();
|
||||||
ctx.beginPath();
|
ctx.beginPath();
|
||||||
if (aspect == undefined) {
|
if (aspect == undefined) {
|
||||||
|
@ -1263,9 +1265,9 @@ var QB = new function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var ctx = screen.ctx;
|
||||||
|
ctx.lineWidth = _strokeLineThickness;
|
||||||
if (pattern == undefined) {
|
if (pattern == undefined) {
|
||||||
var ctx = screen.ctx;
|
|
||||||
ctx.lineWidth = _strokeLineThickness;
|
|
||||||
if (style == "B") {
|
if (style == "B") {
|
||||||
ctx.strokeStyle = color.rgba();
|
ctx.strokeStyle = color.rgba();
|
||||||
ctx.beginPath();
|
ctx.beginPath();
|
||||||
|
@ -1284,8 +1286,6 @@ var QB = new function() {
|
||||||
ctx.stroke();
|
ctx.stroke();
|
||||||
}
|
}
|
||||||
} else { // Stylized line.
|
} else { // Stylized line.
|
||||||
var ctx = screen.ctx;
|
|
||||||
ctx.lineWidth = _strokeLineThickness;
|
|
||||||
ctx.fillStyle = color.rgba();
|
ctx.fillStyle = color.rgba();
|
||||||
ctx.beginPath();
|
ctx.beginPath();
|
||||||
if (style == "B") {
|
if (style == "B") {
|
||||||
|
@ -1301,12 +1301,12 @@ var QB = new function() {
|
||||||
_strokeDrawColor = _color(color);
|
_strokeDrawColor = _color(color);
|
||||||
};
|
};
|
||||||
|
|
||||||
function bitTread(num, cnt) { // Bitwise treadmill left.
|
function bitTreadLeft(num, cnt) { // Bitwise treadmill left.
|
||||||
var val = (num << cnt) | (num >>> (32 - cnt));
|
var val = (num << cnt) | (num >>> (32 - cnt));
|
||||||
return (val | (~~bitTest(num, 15))<<0);
|
return (val | (~~bitTest(num, 15))<<0);
|
||||||
}
|
}
|
||||||
|
|
||||||
function bitTest(num, bit) { // true or false
|
function bitTest(num, bit) { // Returns true or false.
|
||||||
return ((num>>bit) % 2 != 0)
|
return ((num>>bit) % 2 != 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1327,7 +1327,7 @@ var QB = new function() {
|
||||||
lx += 1;
|
lx += 1;
|
||||||
while (lx -= 1) {
|
while (lx -= 1) {
|
||||||
if (y1f < 0) {ytmp = y1f - 0.5; } else { ytmp = y1f + 0.5; }
|
if (y1f < 0) {ytmp = y1f - 0.5; } else { ytmp = y1f + 0.5; }
|
||||||
ptn = bitTread(ptn, 1);
|
ptn = bitTreadLeft(ptn, 1);
|
||||||
if (bitTest(ptn, 0) == true) { ctx.fillRect(xtmp, ytmp, 1, 1); }
|
if (bitTest(ptn, 0) == true) { ctx.fillRect(xtmp, ytmp, 1, 1); }
|
||||||
xtmp += mi;
|
xtmp += mi;
|
||||||
y1f -= slope;
|
y1f -= slope;
|
||||||
|
@ -1339,7 +1339,7 @@ var QB = new function() {
|
||||||
ly += 1;
|
ly += 1;
|
||||||
while (ly -= 1) {
|
while (ly -= 1) {
|
||||||
if (x1f < 0) {xtmp = x1f - 0.5; } else { xtmp = x1f + 0.5; }
|
if (x1f < 0) {xtmp = x1f - 0.5; } else { xtmp = x1f + 0.5; }
|
||||||
ptn = bitTread(ptn, 1);
|
ptn = bitTreadLeft(ptn, 1);
|
||||||
if (bitTest(ptn, 0) == true) { ctx.fillRect(xtmp, ytmp, 1, 1); }
|
if (bitTest(ptn, 0) == true) { ctx.fillRect(xtmp, ytmp, 1, 1); }
|
||||||
ytmp += mi;
|
ytmp += mi;
|
||||||
x1f += slope;
|
x1f += slope;
|
||||||
|
@ -1784,7 +1784,7 @@ var QB = new function() {
|
||||||
_images[0].lastX = _images[0].canvas.width/2;
|
_images[0].lastX = _images[0].canvas.width/2;
|
||||||
_images[0].lastY = _images[0].canvas.height/2;
|
_images[0].lastY = _images[0].canvas.height/2;
|
||||||
|
|
||||||
_screenDiag = Math.sqrt(_images[0].canvas.width*_images[0].canvas.width + _images[0].canvas.height*_images[0].canvas.height);
|
_screenDiagInv = 1/Math.sqrt(_images[0].canvas.width*_images[0].canvas.width + _images[0].canvas.height*_images[0].canvas.height);
|
||||||
|
|
||||||
// initialize the graphics
|
// initialize the graphics
|
||||||
_fgColor = _color(7);
|
_fgColor = _color(7);
|
||||||
|
@ -1803,8 +1803,6 @@ var QB = new function() {
|
||||||
_keyHitBuffer = [];
|
_keyHitBuffer = [];
|
||||||
_keyDownMap = {};
|
_keyDownMap = {};
|
||||||
|
|
||||||
_readCursorPosition = 0;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
this.func_Sgn = function(value) {
|
this.func_Sgn = function(value) {
|
||||||
|
@ -1943,17 +1941,17 @@ var QB = new function() {
|
||||||
|
|
||||||
function windowContendY(v, h) {
|
function windowContendY(v, h) {
|
||||||
if (_windowAspect[2] < 0) {
|
if (_windowAspect[2] < 0) {
|
||||||
return h * (1 - (v - _windowDef[1]) / (_windowDef[3] - _windowDef[1]));
|
return h - h * (v - _windowDef[1]) / (_windowDef[3] - _windowDef[1]);
|
||||||
} else {
|
} else {
|
||||||
return h * (v - _windowDef[1]) / (_windowDef[3] - _windowDef[1]);
|
return 0 + h * (v - _windowDef[1]) / (_windowDef[3] - _windowDef[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function windowUnContendY(v, h) {
|
function windowUnContendY(v, h) {
|
||||||
if (_windowAspect[2] < 0) {
|
if (_windowAspect[2] < 0) {
|
||||||
return _windowDef[1] - (v - h) * (_windowDef[3] - _windowDef[1]) / h;
|
return _windowDef[3] - (v/h) * (_windowDef[3] - _windowDef[1]);
|
||||||
} else {
|
} else {
|
||||||
return _windowDef[1] + v * (_windowDef[3] - _windowDef[1]) / h;
|
return _windowDef[1] + (v/h) * (_windowDef[3] - _windowDef[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue