完善快照功能
This commit is contained in:
parent
fdfaf25289
commit
e1dc96ddea
@ -48,29 +48,25 @@ function screenshot() {
|
|||||||
function savestate() {
|
function savestate() {
|
||||||
gbaCon.pause();
|
gbaCon.pause();
|
||||||
var state = core.freeze();
|
var state = core.freeze();
|
||||||
console.log(state);
|
console.log('saveState:', state);
|
||||||
Serializer.serializePNG(Serializer.serialize(state), document.getElementById('screen'), function(url) {
|
Serializer.serializePNG(Serializer.serialize(state), document.getElementById('screen'), function(url) {
|
||||||
var img = document.getElementById('saveState');
|
var img = document.getElementById('saveState');
|
||||||
img.setAttribute('src', url);
|
img.setAttribute('src', url);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
var globalState;
|
|
||||||
function savestateDirct() {
|
|
||||||
gbaCon.pause();
|
|
||||||
var state = core.freeze();
|
|
||||||
console.log(state);
|
|
||||||
globalState = Serializer.serialize(state)
|
|
||||||
}
|
|
||||||
function loadState() {
|
function loadState() {
|
||||||
if (globalState) {
|
let image = document.getElementById('saveState');
|
||||||
Serializer.deserialize(globalState, function (state) {
|
if (image) {
|
||||||
console.log(state);
|
Serializer.deserializeCurrentPNG(image, function (state) {
|
||||||
|
console.log('loadState', state);
|
||||||
core.defrost(state);
|
core.defrost(state);
|
||||||
|
core.DEBUG('Loaded state');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function loadSavestate(state) {
|
function loadSavestate(state) {
|
||||||
Serializer.deserializePNG(state, function (result) {
|
Serializer.deserializePNG(state, function (result) {
|
||||||
|
console.log('loadSavestate', state);
|
||||||
core.defrost(result);
|
core.defrost(result);
|
||||||
core.DEBUG('Loaded state');
|
core.DEBUG('Loaded state');
|
||||||
});
|
});
|
||||||
@ -164,9 +160,8 @@ window.onload = function() {
|
|||||||
<button onclick="screenshot()">Take screenshot</button>
|
<button onclick="screenshot()">Take screenshot</button>
|
||||||
<button onclick="savestate()">Freeze</button>
|
<button onclick="savestate()">Freeze</button>
|
||||||
<input type="file" id="uploadSavestate" onchange="loadSavestate(this.files[0])" style="display: none">
|
<input type="file" id="uploadSavestate" onchange="loadSavestate(this.files[0])" style="display: none">
|
||||||
<button onclick="document.getElementById('uploadSavestate').click()">Defrost</button>
|
<button onclick="document.getElementById('uploadSavestate').click()">载入</button>
|
||||||
<button onclick="savestateDirct()">Freeze2</button>
|
<button onclick="loadState()">直接载入</button>
|
||||||
<button onclick="loadState()">Defrost2</button>
|
|
||||||
</section>
|
</section>
|
||||||
<section id="registers">
|
<section id="registers">
|
||||||
<div>
|
<div>
|
||||||
|
@ -164,12 +164,10 @@ GameBoyAdvanceIO.prototype.freeze = function() {
|
|||||||
GameBoyAdvanceIO.prototype.defrost = function(frost) {
|
GameBoyAdvanceIO.prototype.defrost = function(frost) {
|
||||||
this.registers = new Uint16Array(frost.registers);
|
this.registers = new Uint16Array(frost.registers);
|
||||||
// Video registers don't serialize themselves
|
// Video registers don't serialize themselves
|
||||||
// for (var i = 0; i <= this.BLDY; i += 2) {
|
// 将背景和背景类似的layer数据写回
|
||||||
// this.store16(this.registers[i >> 1]);
|
for (var i = 0; i < this.registers.length; i += 2 ) {
|
||||||
// }
|
this.store16(i, this.registers[i >> 1]);
|
||||||
// for (var i = 0; i <= this.registers.length; i += 2 ) {
|
}
|
||||||
// this.store16(i, this.registers[i >> 1]);
|
|
||||||
// }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
GameBoyAdvanceIO.prototype.load8 = function(offset) {
|
GameBoyAdvanceIO.prototype.load8 = function(offset) {
|
||||||
|
@ -207,7 +207,7 @@ Serializer = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
newBlob = new Blob(data.map(function (byte) {
|
var newBlob = new Blob(data.map(function (byte) {
|
||||||
var array = new Uint8Array(1);
|
var array = new Uint8Array(1);
|
||||||
array[0] = byte;
|
array[0] = byte;
|
||||||
return array;
|
return array;
|
||||||
@ -219,6 +219,7 @@ Serializer = {
|
|||||||
reader.onload = function(dataImg) {
|
reader.onload = function(dataImg) {
|
||||||
var image = document.createElement('img');
|
var image = document.createElement('img');
|
||||||
image.setAttribute('src', dataImg.target.result);
|
image.setAttribute('src', dataImg.target.result);
|
||||||
|
image.onload = function () {
|
||||||
var canvas = document.createElement('canvas');
|
var canvas = document.createElement('canvas');
|
||||||
canvas.setAttribute('height', image.height);
|
canvas.setAttribute('height', image.height);
|
||||||
canvas.setAttribute('width', image.width);
|
canvas.setAttribute('width', image.width);
|
||||||
@ -241,13 +242,14 @@ Serializer = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
newBlob = new Blob(data.map(function (byte) {
|
var newBlob = new Blob(data.map(function (byte) {
|
||||||
var array = new Uint8Array(1);
|
var array = new Uint8Array(1);
|
||||||
array[0] = byte;
|
array[0] = byte;
|
||||||
return array;
|
return array;
|
||||||
}), { type: Serializer.TYPE});
|
}), { type: Serializer.TYPE});
|
||||||
Serializer.deserialize(newBlob, callback);
|
Serializer.deserialize(newBlob, callback);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
reader.readAsDataURL(blob);
|
reader.readAsDataURL(blob);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -854,30 +854,109 @@ GameBoyAdvanceSoftwareRenderer.prototype.clearSubsets = function(mmu, regions) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
GameBoyAdvanceSoftwareRenderer.prototype.freeze = function() {
|
GameBoyAdvanceSoftwareRenderer.prototype.freeze = function() {
|
||||||
console.log('GameBoyAdvanceSoftwareRenderer.freeze', this.bg, this.pixelData);
|
console.log('GameBoyAdvanceSoftwareRenderer.freeze', this);
|
||||||
return {
|
return {
|
||||||
pixelData: Serializer.prefix(this.pixelData.data.buffer),
|
palette: this.palette.freeze(),
|
||||||
width: this.pixelData.width,
|
// oam: this.oam.freeze(),
|
||||||
height: this.pixelData.height,
|
vram: this.vram.freeze(),
|
||||||
scanline: {
|
|
||||||
color: Serializer.prefix(this.scanline.color.buffer),
|
|
||||||
stencil: Serializer.prefix(this.scanline.stencil.buffer)
|
|
||||||
},
|
|
||||||
palette: JSON.stringify(this.palette)
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
GameBoyAdvanceSoftwareRenderer.prototype.defrost = function(f) {
|
GameBoyAdvanceSoftwareRenderer.prototype.defrost = function(f) {
|
||||||
this.pixelData = f.pixelData;
|
// 游戏人物
|
||||||
// let backing = new ImageData(new Uint8ClampedArray(f.pixelData), f.width, f.height);
|
this.palette.defrost(f.palette);
|
||||||
// this.setBacking(backing);
|
// this.oam.defrost(f.oam);
|
||||||
// this.scanline = {
|
// 恢复子弹, 血条等数据的显示
|
||||||
// color: new Uint16Array(f.scanline.color),
|
this.vram.defrost(f.vram);
|
||||||
// stencil: new Uint8Array(f.scanline.stencil)
|
|
||||||
// };
|
|
||||||
// this.palette = eval("("+f.palette+")");
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// GameBoyAdvanceOAM.prototype.freeze = function() {
|
||||||
|
// return {
|
||||||
|
// buffer: Serializer.prefix(this.buffer.buffer),
|
||||||
|
// oam: Serializer.prefix(this.oam.buffer),
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// GameBoyAdvanceOAM.prototype.defrost = function(frost) {
|
||||||
|
// this.buffer = new Uint16Array(frost.buffer);
|
||||||
|
// this.oam = new Uint16Array(frost.oam);
|
||||||
|
// }
|
||||||
|
|
||||||
|
GameBoyAdvancePalette.prototype.freeze = function() {
|
||||||
|
return {
|
||||||
|
colors: this.colors,
|
||||||
|
adjustedColors: this.adjustedColors,
|
||||||
|
passthroughColors: this.passthroughColors
|
||||||
|
}
|
||||||
|
};
|
||||||
|
GameBoyAdvancePalette.prototype.defrost = function(frost) {
|
||||||
|
this.colors = frost.colors;
|
||||||
|
this.adjustedColors = frost.adjustedColors;
|
||||||
|
this.passthroughColors = frost.passthroughColors;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
GameBoyAdvanceVRAM.prototype.freeze = function() {
|
||||||
|
return {
|
||||||
|
buffer: Serializer.prefix(this.buffer.buffer),
|
||||||
|
vram: Serializer.prefix(this.vram.buffer),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GameBoyAdvanceVRAM.prototype.defrost = function(frost) {
|
||||||
|
this.buffer = new Uint16Array(frost.buffer);
|
||||||
|
this.vram = new Uint16Array(frost.vram);
|
||||||
|
}
|
||||||
|
|
||||||
|
// GameBoyAdvanceOBJ.prototype.freeze = function() {
|
||||||
|
// return {
|
||||||
|
// cachedHeight: this.cachedHeight,
|
||||||
|
// cachedWidth: this.cachedWidth,
|
||||||
|
// disable: this.disable,
|
||||||
|
// doublesize: this.doublesize,
|
||||||
|
// hflip: this.hflip,
|
||||||
|
// index: this.index,
|
||||||
|
// mode: this.mode,
|
||||||
|
// mosaic: this.mosaic,
|
||||||
|
// multipalette: this.multipalette,
|
||||||
|
// palette: this.palette,
|
||||||
|
// priority: this.priority,
|
||||||
|
// scalerot: this.scalerot,
|
||||||
|
// scalerotOam: this.scalerotOam,
|
||||||
|
// scalerotParam: this.scalerotParam,
|
||||||
|
// shape: this.shape,
|
||||||
|
// size: this.size,
|
||||||
|
// tileBase: this.tileBase,
|
||||||
|
// vflip: this.vflip,
|
||||||
|
// x: this.x,
|
||||||
|
// y: this.y,
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// GameBoyAdvanceOBJ.prototype.defrost = function(f) {
|
||||||
|
// this.cachedHeight = f.cachedHeight;
|
||||||
|
// this.cachedWidth = f.cachedWidth;
|
||||||
|
// this.disable = f.disable;
|
||||||
|
// this.doublesize = f.doublesize;
|
||||||
|
// this.hflip = f.hflip;
|
||||||
|
// this.index = f.index;
|
||||||
|
// this.mode = f.mode;
|
||||||
|
// this.mosaic = f.mosaic;
|
||||||
|
// this.multipalette = f.multipalette;
|
||||||
|
// this.palette = f.palette;
|
||||||
|
// this.priority = f.priority;
|
||||||
|
// this.scalerot = f.scalerot;
|
||||||
|
// this.scalerotOam = f.scalerotOam;
|
||||||
|
// this.scalerotParam = f.scalerotParam;
|
||||||
|
// this.shape = f.shape;
|
||||||
|
// this.size = f.size;
|
||||||
|
// this.tileBase = f.tileBase;
|
||||||
|
// this.vflip = f.vflip;
|
||||||
|
// this.x = f.x;
|
||||||
|
// this.y = f.y;
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
GameBoyAdvanceSoftwareRenderer.prototype.setBacking = function(backing) {
|
GameBoyAdvanceSoftwareRenderer.prototype.setBacking = function(backing) {
|
||||||
this.pixelData = backing;
|
this.pixelData = backing;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user