monkey v66: dataview compatibility

Monkey Forums/Monkey Bug Reports/monkey v66: dataview compatibility

AdamRedwoods(Posted 2012) [#1]
Just a note on DataView (HTML5), since it isn't widely accepted yet.

Thought you could do an undefined check on it and if undefined, use backward compatibility:
backwards check example:
	if (typeof DataView !== 'undefined') {
		this.dataView=new DataView( buffer );
	} else {
		//compatibility
		this.dataView=new DataView__( buffer );
	}


function DataView__(buffer) {
	//this.buffer = buffer;
	this.byteArray=new Int8Array( buffer );
	this.shortArray=new Int16Array( buffer );
	this.intArray=new Int32Array( buffer );
	this.floatArray=new Float32Array( buffer );
}

DataView__.prototype.setInt8 = function(addr,value) {
	this.byteArray[addr]=value;
}
DataView__.prototype.setInt16 = function(addr,value) {
	this.shortArray[addr>>1]=value;
}
DataView__.prototype.setInt32 = function(addr,value) {
	this.intArray[addr>>2]=value;
}
DataView__.prototype.setFloat32 = function(addr,value) {
	this.floatArray[addr>>2]=value;
}

DataView__.prototype.getInt8 = function(addr,value) {
	return this.byteArray[addr];
}
DataView__.prototype.getInt16 = function(addr,value) {
	return this.shortArray[addr>>1];
}
DataView__.prototype.getInt32 = function(addr,value) {
	return this.intArray[addr>>2];
}
DataView__.prototype.getFloat32 = function(addr,value) {
	return this.floatArray[addr>>2];
}


otherwise this breaks quite a few browsers.


marksibly(Posted 2012) [#2]
Hi,

Here's a DataView-less version that handles misaligned data I was working on a while back.

If it works OK for you I'll include it in next release...




AdamRedwoods(Posted 2012) [#3]
works, thanks.

but the asyncdataloader in html5 is corrupting or truncating data (was my code/can't load images through arraybuffer in js yet), and in main.js (from trans targets) the loadDataBuffer() still uses DataView... so, those are still things to think about.


skid(Posted 2012) [#4]
IE9 doesn't seem to support ArrayBuffers.


AdamRedwoods(Posted 2012) [#5]
True, but it is in IE10, and IE9 doesn't have dataview either.
http://msdn.microsoft.com/en-us/library/s4esdbwz(v=vs.94).aspx

(and FWIW, no webgl on IE either...)


skid(Posted 2012) [#6]
I mistook them for banks and went with them for some audio stuff, my bad, have replaced with int[] based bindings for now.