Loading of test.vif now handled by an XMLHttpRequest to the local file, rather than an iframe. The iframe pretty much only worked on Safari, and was rather clunky in comparison to the XMLHttpRequest method - I thought it couldn't handle file://, but it can.

master
kts@vger 2013-08-04 23:11:59 -07:00
parent 5fdd9b2d36
commit 046af3da81
2 changed files with 18 additions and 5 deletions

BIN
test.txt

Binary file not shown.

23
vif.js
View File

@ -22,7 +22,7 @@ JVIV = function() {
help_text.setColor("#FFFFFF");
events = new CBDL.Event(["keydown", "keyup"], document.body);
events.addEvent(["resize"], window);
vif_loader = new VL.Loader('test.txt');
vif_loader = new VL.Loader('test.vif');
(loop = new CBDL.Loop(this, onLoop)).start();
};
var offset = 0;
@ -45,8 +45,6 @@ JVIV = function() {
var current_mod = 1;
function onLoop(loop_time) {
debug_text.setText(debug_string);
help_text.setText(help_string);
if (state == 0) {
if (vif_loader.state == 1) {
display.Fill(100, 50, 50);
@ -187,6 +185,7 @@ JVIV = function() {
voxel_count++;
}
debug_string += "v:"+voxel_count+" ";
debug_text.setText(debug_string);
};
}; CBDL.extend(CBDL.App, JVIV);
@ -199,7 +198,21 @@ Returns 1 on failure, 0 on success
VL.Loader = function(vif_file) {
this.state = 0;
this.raw_data = [];
var iframe = document.createElement('iframe');
var req = new XMLHttpRequest();
req.open('GET', vif_file, true);
req.overrideMimeType('text\/plain; charset=x-user-defined')
CBDL.addEvent(req, 'load', (function(req, scope) {
return function() {
data = this.responseText;
for(var i=0;i<data.length;i++) {
scope.raw_data[i] = data.charCodeAt(i) & 0xff;
}
scope.state = 1;
}
})(req, this));
req.send(null);
/*var iframe = document.createElement('iframe');
iframe.content = 'text\/plain; charset=x-user-defined'
iframe.style.display = 'none';
document.body.appendChild(iframe);
@ -224,7 +237,7 @@ VL.Loader = function(vif_file) {
})(iframe), 0);
}
})(iframe, this));
iframe.src = vif_file;
iframe.src = vif_file;*/
};
VL.loadVif = function(vif_file, byte_array) {
var iframe = document.createElement('iframe');