Skip to content

Commit

Permalink
- Added jeash.Memory
Browse files Browse the repository at this point in the history
- 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
soywiz committed Sep 4, 2012
1 parent ff17f62 commit cfed4c7
Show file tree
Hide file tree
Showing 4 changed files with 257 additions and 126 deletions.
111 changes: 111 additions & 0 deletions jeash/Memory.hx
@@ -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);
});
}

}
3 changes: 3 additions & 0 deletions jeash/events/MouseEvent.hx
Expand Up @@ -52,6 +52,9 @@ class MouseEvent extends Event
public static var MOUSE_OVER : String = "mouseOver";
public static var MOUSE_UP : String = "mouseUp";
public static var MOUSE_WHEEL : String = "mouseWheel";
public static var RIGHT_CLICK : String = "rightClick";
public static var RIGHT_MOUSE_DOWN : String = "rightMouseDown";
public static var RIGHT_MOUSE_UP : String = "rightMouseUp";
public static var ROLL_OUT : String = "rollOut";
public static var ROLL_OVER : String = "rollOver";

Expand Down

0 comments on commit cfed4c7

Please sign in to comment.