aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/library.js17
-rw-r--r--src/library_openal.js71
-rw-r--r--src/parseTools.js4
3 files changed, 70 insertions, 22 deletions
diff --git a/src/library.js b/src/library.js
index d5f11cf3..382c21ad 100644
--- a/src/library.js
+++ b/src/library.js
@@ -2642,7 +2642,7 @@ LibraryManager.library = {
// format: A pointer to the format string.
// varargs: A pointer to the start of the arguments list.
// Returns the resulting string string as a character array.
- _formatString__deps: ['strlen'],
+ _formatString__deps: ['strlen', '_reallyNegative'],
_formatString: function(format, varargs) {
var textIndex = format;
var argIndex = 0;
@@ -2897,7 +2897,6 @@ LibraryManager.library = {
// Float.
var currArg = getNextArg('double');
var argText;
-
if (isNaN(currArg)) {
argText = 'nan';
flagZeroPad = false;
@@ -2932,6 +2931,9 @@ LibraryManager.library = {
}
} else if (next == {{{ charCode('f') }}} || next == {{{ charCode('F') }}}) {
argText = currArg.toFixed(effectivePrecision);
+ if (currArg === 0 && __reallyNegative(currArg)) {
+ argText = '-' + argText;
+ }
}
var parts = argText.split('e');
@@ -4950,7 +4952,7 @@ LibraryManager.library = {
var ret = 0;
while (x) {
if (x&1) ret++;
- x >>= 1;
+ x >>>= 1;
}
return ret;
},
@@ -5478,9 +5480,14 @@ LibraryManager.library = {
return isNaN(x);
},
__isnan: 'isnan',
+
+ _reallyNegative: function(x) {
+ return x < 0 || (x === 0 && (1/x) === -Infinity);
+ },
+
+ copysign__deps: ['_reallyNegative'],
copysign: function(a, b) {
- if (a < 0 === b < 0) return a;
- return -a;
+ return __reallyNegative(a) === __reallyNegative(b) ? a : -a;
},
copysignf: 'copysign',
__signbit__deps: ['copysign'],
diff --git a/src/library_openal.js b/src/library_openal.js
index 6bd0f6b0..3d3c11f2 100644
--- a/src/library_openal.js
+++ b/src/library_openal.js
@@ -57,6 +57,7 @@ var LibraryOpenAL = {
}
if (ctx) {
+ ctx.listener.panningModel = "equalpower";
AL.contexts.push({ctx: ctx, err: 0, src: [], buf: []});
return AL.contexts.length;
} else {
@@ -81,7 +82,7 @@ var LibraryOpenAL = {
return;
}
for (var i = 0; i < count; ++i) {
- var sourceIdx = {{{ makeGetValue('sources', 'i', 'i32') }}} - 1;
+ var sourceIdx = {{{ makeGetValue('sources', 'i*4', 'i32') }}} - 1;
delete AL.currentContext.src[sourceIdx];
}
},
@@ -196,15 +197,15 @@ var LibraryOpenAL = {
case 0x1004 /* AL_POSITION */:
AL.currentContext.src[source - 1].panner.setPosition(
{{{ makeGetValue('value', '0', 'float') }}},
- {{{ makeGetValue('value', '1', 'float') }}},
- {{{ makeGetValue('value', '2', 'float') }}}
+ {{{ makeGetValue('value', '4', 'float') }}},
+ {{{ makeGetValue('value', '8', 'float') }}}
);
break;
case 0x1006 /* AL_VELOCITY */:
AL.currentContext.src[source - 1].panner.setVelocity(
{{{ makeGetValue('value', '0', 'float') }}},
- {{{ makeGetValue('value', '1', 'float') }}},
- {{{ makeGetValue('value', '2', 'float') }}}
+ {{{ makeGetValue('value', '4', 'float') }}},
+ {{{ makeGetValue('value', '8', 'float') }}}
);
break;
default:
@@ -235,7 +236,7 @@ var LibraryOpenAL = {
return;
}
for (var i = 0; i < count; ++i) {
- var buffer = {{{ makeGetValue('buffers', 'i', 'i32') }}};
+ var buffer = {{{ makeGetValue('buffers', 'i*4', 'i32') }}};
if (buffer > AL.currentContext.buf.length) {
#if OPENAL_DEBUG
console.error("alSourceQueueBuffers called with an invalid buffer");
@@ -287,7 +288,7 @@ var LibraryOpenAL = {
return;
}
for (var i = 0; i < count; ++i) {
- var bufferIdx = {{{ makeGetValue('buffers', 'i', 'i32') }}} - 1;
+ var bufferIdx = {{{ makeGetValue('buffers', 'i*4', 'i32') }}} - 1;
var buffer = AL.currentContext.buf[bufferIdx].buf;
for (var j = 0; j < AL.currentContext.src.length; ++j) {
if (buffer == AL.currentContext.src[j].buffer) {
@@ -385,14 +386,18 @@ var LibraryOpenAL = {
return;
}
var offset = 0;
- if ("src" in AL.currentContext.src[source - 1]) {
- // If the source is already playing, we need to resume from beginning.
- // We do that by stopping the current source and replaying it.
- _alSourceStop(source);
- } else if (AL.currentContext.src[source - 1].paused) {
- // So now we have to resume playback, remember the offset here.
- offset = AL.currentContext.src[source - 1].pausedTime -
- AL.currentContext.src[source - 1].playTime;
+ if ("src" in AL.currentContext.src[source - 1] &&
+ AL.currentContext.src[source - 1]["src"].buffer ==
+ AL.currentContext.src[source - 1].buffer) {
+ if (AL.currentContext.src[source - 1].paused) {
+ // So now we have to resume playback, remember the offset here.
+ offset = AL.currentContext.src[source - 1].pausedTime -
+ AL.currentContext.src[source - 1].playTime;
+ } else {
+ // If the source is already playing, we need to resume from beginning.
+ // We do that by stopping the current source and replaying it.
+ _alSourceStop(source);
+ }
}
var src = AL.currentContext.ctx.createBufferSource();
src.loop = AL.currentContext.src[source - 1].loop;
@@ -513,9 +518,43 @@ var LibraryOpenAL = {
},
alListenerfv: function(param, values) {
+ if (!AL.currentContext) {
#if OPENAL_DEBUG
- console.log("alListenerfv is not supported yet");
+ console.error("alListenerfv called without a valid context");
#endif
+ return;
+ }
+ switch (param) {
+ case 0x1004 /* AL_POSITION */:
+ AL.currentContext.ctx.listener.setPosition(
+ {{{ makeGetValue('values', '0', 'float') }}},
+ {{{ makeGetValue('values', '4', 'float') }}},
+ {{{ makeGetValue('values', '8', 'float') }}}
+ );
+ break;
+ case 0x1006 /* AL_VELOCITY */:
+ AL.currentContext.ctx.listener.setVelocity(
+ {{{ makeGetValue('values', '0', 'float') }}},
+ {{{ makeGetValue('values', '4', 'float') }}},
+ {{{ makeGetValue('values', '8', 'float') }}}
+ );
+ break;
+ case 0x100F /* AL_ORIENTATION */:
+ AL.currentContext.ctx.listener.setOrientation(
+ {{{ makeGetValue('values', '0', 'float') }}},
+ {{{ makeGetValue('values', '4', 'float') }}},
+ {{{ makeGetValue('values', '8', 'float') }}},
+ {{{ makeGetValue('values', '12', 'float') }}},
+ {{{ makeGetValue('values', '16', 'float') }}},
+ {{{ makeGetValue('values', '20', 'float') }}}
+ );
+ break;
+ default:
+#if OPENAL_DEBUG
+ console.log("alListenerfv with param " + param + " not implemented yet");
+#endif
+ break;
+ }
},
alIsExtensionPresent: function(extName) {
diff --git a/src/parseTools.js b/src/parseTools.js
index 2664baed..9fddacbb 100644
--- a/src/parseTools.js
+++ b/src/parseTools.js
@@ -818,7 +818,9 @@ function parseNumerical(value, type) {
return '0';
}
if (isNumber(value)) {
- return parseFloat(value).toString(); // will change e.g. 5.000000e+01 to 50
+ var ret = parseFloat(value); // will change e.g. 5.000000e+01 to 50
+ if (type in Runtime.FLOAT_TYPES && value[0] == '-' && ret === 0) return '-0'; // fix negative 0, toString makes it 0
+ return ret.toString();
} else {
return value;
}