forked from haxenme/nme
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Lots of improvements and fixes on jeash.utils.ByteArray - It initialized the ByteArray as LITTLE_ENDIAN (flash initializes it a BIG_ENDIAN) - readUTF and writeUTF didn't read/write the unsigned short with the length in bytes of the string - It initialized the length of the ByteArray with a predefined 8192 value, now it initializes it with a length of 0, but includes a allocated length in order to improve performance and reduce reallocations. - Simplified writings - Added MouseEvent.RIGHT* strings (thought those events are not triggered yet) - Changed Endian enum to a class with strings to make it more compatible with flash and neash NOTE: It seems that there is a bug implementing ArrayAccess in the js target, so I have included the code related to implement it, to make it easy to enable when fixed
- Loading branch information
Showing
4 changed files
with
257 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package jeash; | ||
|
||
|
||
import haxe.io.BytesData; | ||
import jeash.utils.ByteArray; | ||
|
||
class Memory | ||
{ | ||
static var gcRef:ByteArray; | ||
static var len:Int; | ||
|
||
static public function select(inBytes:ByteArray):Void | ||
{ | ||
gcRef = inBytes; | ||
len = (inBytes != null) ? inBytes.length : 0; | ||
} | ||
|
||
static private function _setPositionTemporarily<T>(position:Int, action:Void -> T):T { | ||
var oldPosition:Int = gcRef.position; | ||
gcRef.position = position; | ||
var value:T = action(); | ||
gcRef.position = oldPosition; | ||
return value; | ||
} | ||
|
||
static #if !debug inline #end public function getByte(addr:Int):Int | ||
{ | ||
#if debug if (addr < 0 || addr + 1 > len) throw("Bad address"); #end | ||
return gcRef.jeashGet(addr); | ||
} | ||
|
||
static #if !debug inline #end public function getDouble(addr:Int):Float | ||
{ | ||
#if debug if (addr < 0 || addr + 8 > len) throw("Bad address"); #end | ||
return _setPositionTemporarily(addr, function() { | ||
return gcRef.readDouble(); | ||
}); | ||
} | ||
|
||
|
||
static #if !debug inline #end public function getFloat(addr:Int):Float | ||
{ | ||
#if debug if (addr < 0 || addr + 4 > len) throw("Bad address"); #end | ||
return _setPositionTemporarily(addr, function() { | ||
return gcRef.readFloat(); | ||
}); | ||
} | ||
|
||
|
||
static #if !debug inline #end public function getI32(addr:Int):Int | ||
{ | ||
#if debug if (addr < 0 || addr + 4 > len) throw("Bad address"); #end | ||
return _setPositionTemporarily(addr, function() { | ||
return gcRef.readInt(); | ||
}); | ||
|
||
} | ||
|
||
|
||
static #if !debug inline #end public function getUI16(addr:Int):Int | ||
{ | ||
#if debug if (addr < 0 || addr + 2 > len) throw("Bad address"); #end | ||
return _setPositionTemporarily(addr, function() { | ||
return gcRef.readUnsignedShort(); | ||
}); | ||
} | ||
|
||
|
||
static #if !debug inline #end public function setByte(addr:Int, v:Int):Void | ||
{ | ||
#if debug if (addr < 0 || addr + 1 > len) throw("Bad address"); #end | ||
gcRef.jeashSet(addr, v); | ||
} | ||
|
||
|
||
static #if !debug inline #end public function setDouble(addr:Int, v:Float):Void | ||
{ | ||
#if debug if (addr < 0 || addr + 8 > len) throw("Bad address"); #end | ||
_setPositionTemporarily(addr, function() { | ||
gcRef.writeDouble(v); | ||
}); | ||
} | ||
|
||
|
||
static #if !debug inline #end public function setFloat(addr:Int, v:Float):Void | ||
{ | ||
#if debug if (addr < 0 || addr + 4 > len) throw("Bad address"); #end | ||
_setPositionTemporarily(addr, function() { | ||
gcRef.writeFloat(v); | ||
}); | ||
} | ||
|
||
|
||
static #if !debug inline #end public function setI16(addr:Int, v:Int):Void | ||
{ | ||
#if debug if (addr < 0 || addr + 2 > len) throw("Bad address"); #end | ||
_setPositionTemporarily(addr, function() { | ||
gcRef.writeUnsignedShort(v); | ||
}); | ||
} | ||
|
||
|
||
static #if !debug inline #end public function setI32(addr:Int, v:Int):Void | ||
{ | ||
#if debug if (addr < 0 || addr + 4 > len) throw("Bad address"); #end | ||
_setPositionTemporarily(addr, function() { | ||
gcRef.writeInt(v); | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.