Skip to content
This repository has been archived by the owner on Dec 11, 2023. It is now read-only.

Issue/android compilation issues #88

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/gecko/Assets.hx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Assets {
static private function _parseAssetName(name:String, ext:Bool = false) : String {
name = ext ? name : Path.withoutExtension(name);
name = Std.parseInt(name.charAt(0)) != null ? "_" + name : name;
return (~/[\/\.-\s]/gi).replace(Path.normalize(name), "_");
return new EReg("[\\/\\.\\-\\s]", "gi").replace(Path.normalize(name), "_");
}

static inline private function _existsAssetsName(name:String, type:String) : Bool {
Expand Down
10 changes: 5 additions & 5 deletions Sources/gecko/Transform.hx
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ class Transform {
public var size(get, null):Point;
private var _size:Point;

public var flip(get, null):Vector2g<Bool>;
private var _flip:Vector2g<Bool>;
public var flip(get, null):Vector2g;
private var _flip:Vector2g;

public var rotation(get, set):Float;
private var _rotation:Float = 0;
Expand Down Expand Up @@ -372,7 +372,7 @@ class Transform {
_dirtyPosition = false;
}

private function _vecDirty(vec:Vector2g<Bool>) {
private function _vecDirty(vec:Vector2g) {
_setDirty(true);
_dirtyPosition = false;
}
Expand Down Expand Up @@ -546,7 +546,7 @@ class Transform {
return _pivot;
}

function get_flip():Vector2g<Bool> {
function get_flip():Vector2g {
if(_dirty)updateTransform();
return _flip;
}
Expand Down Expand Up @@ -718,4 +718,4 @@ private typedef SkewCache = {
var sinX:Float;
var cosY:Float;
var sinY:Float;
};
};
3 changes: 1 addition & 2 deletions Sources/gecko/macros/PoolBuilder.hx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class PoolBuilder {
//todo add a instancePoolId (unique id) to debug?
var poolFields = (macro class {
static var __pool__ = new gecko.utils.Pool($p{path}, {amount: $v{amount}/*, args: $v{arguments}*/});
static inline public function getPool() return __pool__;
}).fields;

//add create function
Expand Down Expand Up @@ -321,4 +320,4 @@ class PoolBuilder {
default: false;
}
}
}
}
40 changes: 20 additions & 20 deletions Sources/gecko/math/Vector2g.hx
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package gecko.math;

class Vector2g<T> { //todo add observer
public var x(get, set):T;
private var _x:T;
public var y(get, set):T;
private var _y:T;
class Vector2g { //todo add observer
public var x(get, set):Bool;
private var _x:Bool;
public var y(get, set):Bool;
private var _y:Bool;

private var _observer:Vector2g<T> -> Void;
private var _observer:Vector2g -> Void;
public var isObserved(default, null):Bool;

inline public function new(x:T, y:T) {
inline public function new(x:Bool, y:Bool) {
set(x, y);
}

public function setObserver(cb:Vector2g<T> -> Void) : Void {
public function setObserver(cb:Vector2g -> Void) : Void {
isObserved = true;
_observer = cb;
}
Expand All @@ -22,57 +22,57 @@ class Vector2g<T> { //todo add observer
isObserved = false;
}

public inline function set(x:T, y:T) {
public inline function set(x:Bool, y:Bool) {
if(x != _x || y != _y){
_setX(x);
_setY(y);
if(isObserved)_observer(this);
}
}

inline private function _setX(x:T) {
inline private function _setX(x:Bool) {
_x = x;
}

inline private function _setY(y:T) {
inline private function _setY(y:Bool) {
_y = y;
}

public inline function clone(vec:Vector2g<T>) : Vector2g<T> {
return new Vector2g<T>(x, y);
public inline function clone(vec:Vector2g) : Vector2g {
return new Vector2g(x, y);
}

public inline function copy(vec:Vector2g<T>) : Void {
public inline function copy(vec:Vector2g) : Void {
set(vec.x, vec.y);
}

public inline function isEqual(vec:Vector2g<T>) : Bool {
public inline function isEqual(vec:Vector2g) : Bool {
return (x == vec.x && y == vec.y);
}

inline function get_x():T {
inline function get_x():Bool {
return _x;
}

function set_x(value:T):T {
function set_x(value:Bool):Bool {
if(value == _x)return _x;
_x = value;
if(isObserved)_observer(this);
return value;
}

inline function set_y(value:T):T {
inline function set_y(value:Bool):Bool {
if(value == _y)return _y;
_y = value;
if(isObserved)_observer(this);
return value;
}

inline function get_y():T {
inline function get_y():Bool {
return _y;
}

inline public function toString() : String {
return 'Vector2g($_x, $_y)';
}
}
}
14 changes: 7 additions & 7 deletions docs/guide/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Base Object
This framework use object pooling to avoid garbage collector issues. Some objects, like scenes, entites, componentes, or systems (among other objects) inherit from `gecko.BaseObject`, which is a special object without functionality defined, but allow us to recycle our instances.
This framework use object pooling to avoid garbage collector issues. Some objects, like scenes, entites, componentes, or systems (among other objects) inherit from `gecko.BaseObject`, which is a special object without functionality defined, but allow us to recycle our instances.

Every object inherited from `gecko.BaseObject` must be instantiated via the static method `MyObject.create()`, this will check his pool to get and reuse an old instance, or if no one exists create it. When you're done with your object, just destroy it with the instance method `myObject.destroy()` and it will be returned to his pool.

To manage how your objects are created or destroyed you can use two instance methods, `init` and `beforeDestroy`.
- __init__: this method is executed always when you use `MyObject.create()`. You can add some parameters to it, and this params will be passed to the __create__ method.
- __beforeDestroy__: this method is executed before your object is destroyed, use it to clean it or do whatever you need before recycle it. This methods needs to be override because is inherited from __BaseObject__.
- __beforeDestroy__: this method is executed before your object is destroyed, use it to clean it or do whatever you need before recycle it. This methods needs to be override because is inherited from __BaseObject__.

For example:
For example:
```haxe
class MyObject extends gecko.BaseObject {
var name:String = "";
Expand All @@ -21,15 +21,15 @@ class MyObject extends gecko.BaseObject {
trace("i will be destroyed!!!!");
}
}
```
```

```haxe
var myObject = MyObject.create("Jonh Doe"); //print "Jonh Doe"

//do something with your object and when you're done just destroy it
myObject.destroy();
myObject.destroy();
```

Keep in mind that is possible `beforeDestroy` may not be executed when you use `myObject.destroy()`. If the game loop o the rendering loop is running the destruction of your object will be delayed to the end of the frame. If you need to know the state of your object use `myObject.isAlreadyDestroyed` which is a boolean value.
Keep in mind that is possible `beforeDestroy` may not be executed when you use `myObject.destroy()`. If the game loop o the rendering loop is running the destruction of your object will be delayed to the end of the frame. If you need to know the state of your object use `myObject.isAlreadyDestroyed` which is a boolean value.

In some (unsual) cases maybe you want acces to your object's pool to check their length, clear, debug, or whatever, just use `MyObject.getPool()`.
In some (unsual) cases maybe you want acces to your object's pool to check their length, clear, debug, or whatever, just use `MyObject.__pool__`.