fponticelli / edge Goto Github PK
View Code? Open in Web Editor NEWEntity system for Haxe
License: MIT License
Entity system for Haxe
License: MIT License
instances of ISystemProcess are created at compilation time (with macros) and remove all the checks at runtime.
Hi, I'm using Edge with HaxeFlixel. And I use FlxSprite as a IComponent.
This should reproduce the problem:
var sprite = new FlxSprite();
var entity = engine.create([sprite]);
trace(entity.exists(sprite)); // false
Why?
FlxSprite extends FlxObject and FlxObject extends FlxBasic, thus the key for FlxSprite is flixel.FlxBasic
.
But exists()
uses Type.getClass()
on FlxSprite and it returns flixel.FlxSprite
, of course. Hence false
.
This is kinda a design problem, I guess.
In the mean time, I'll just replace this in the Entity class:
function key(component : {}) {
var t : Class<Dynamic> = Type.getClass(component),
s = Type.getSuperClass(t);
while(s != null && s != edge.IComponent) {
t = s;
s = Type.getSuperClass(t);
}
return Type.getClassName(t);
}
with this:
function key(component : {}) {
return Type.getClassName(Type.getClass(component));
}
https://github.com/fponticelli/edge/blob/master/src/edge/Engine.hx#L96
He man, I was just browsing your source, shouldnt this be Cycle.postframe?
Hello! Is there any reason why IComponent#toString
requires arguments? Or is it accidental copy'n'paste from injectConstructor
?
Defined here:
With the release of Haxe 3.3.0-rc1, my game no longer seems to work.
I was able to "fix" the problem here in edge.core.macro.Macros by manually adding a "meta" property to the object with the value "null". At the moment, I'm not completely sure why this works. I'm looking at the listed breaking changes, but since I'm still new to haxe, nothing jumps out at me.
I'm thinking a native method either returns or accepts a differently shaped object in 3.3.0 vs 3.2.1.
I'll circle back to this and see if I can find the solution (or better understand the one mentioned).
Another note on this. It seems the tests still pass, but I don't see any classes implement IComponent.
I tried to profile my project using hxscout, and I saw some worrying results. I reproduced it in small repo: https://github.com/Misiur/Alloc/blob/402a0344d8577113fad40df7fc0bc301b78006ee/Source/Main.hx
After just a few frames things get messy. For 1000 entities iterators generate 800000 allocations (last frame only has 550000)
I'm not even sure how to debug that. Should I be worried? Or is it normal?
I wanted more frames, but app stops responding after that frame.
(Self time on left, total on right)
(
Line 11 in 1bc5874
Trying to compile anything using edge (including the basic demo included in this repo), I get:
/home/kenton/.haxe/edge/0,7,0/src/edge/core/macro/Macros.hx:11: lines 11-18 : Array<Null<{ value : Null<Null<haxe.macro.Expr>>, type : Null<haxe.macro.ComplexType>, opt : Null<Bool>, name : String }>> should be Array<haxe.macro.FunctionArg>
/home/kenton/.haxe/edge/0,7,0/src/edge/core/macro/Macros.hx:11: lines 11-18 : Type parameters are invariant
/home/kenton/.haxe/edge/0,7,0/src/edge/core/macro/Macros.hx:11: lines 11-18 : { value : Null<Null<haxe.macro.Expr>>, type : Null<haxe.macro.ComplexType>, opt : Null<Bool>, name : String } should be haxe.macro.FunctionArg
/home/kenton/.haxe/edge/0,7,0/src/edge/core/macro/Macros.hx:11: lines 11-18 : { value : Null<Null<haxe.macro.Expr>>, type : Null<haxe.macro.ComplexType>, opt : Null<Bool>, name : String } should be { ?value : Null<Null<haxe.macro.Expr>>, type : Null<haxe.macro.ComplexType>, ?opt : Null<Bool>, name : String, ?meta : Null<haxe.macro.Metadata> }
/home/kenton/.haxe/edge/0,7,0/src/edge/core/macro/Macros.hx:11: lines 11-18 : { value : Null<Null<haxe.macro.Expr>>, type : Null<haxe.macro.ComplexType>, opt : Null<Bool>, name : String } has no field meta
/home/kenton/.haxe/edge/0,7,0/src/edge/ISystem.hx:5: characters 2-11 : Build failure
Any idea what's up?
Thanks!
update
member:
fdorg/flashdevelop#689
Maybe it's a haxe issue ?
Workaround is set the upate
funtion return Bool instead of Void, so it's just a low priority issue.
add pool for creating/reusing entities
I tried to see if I can integrate this system into OpenFL, but all I get is the error above, with "Build failure".
lime [2.8.3]
openfl [3.5.3]
thx.core [0.39.0]
edge [0.7.0]
Code is here:
package;
import edge.ISystem;
import edge.World;
import openfl.display.Sprite;
class Main extends Sprite implements ISystem
{
public function new()
{
super();
var world = new World();
world.render.add(this);
world.start();
}
function update()
trace("hello");
}
Sorry if I'm actually missing out an important detail here.
World should contain a default schedule implementation and a few standard phases (frame, update, render)
move SystemInfo typedef to a class
where Phase is a class instance with a collection of Nodes (linked list) each containing a reference to a system to be able to prioritize the systems.
From the API, doesn't seem to support it. From the code, it appears as if it's always meant to using base class implementation as identifier for given component type?
Why does the macro consider s=superClass
to have a possibility of being IComponent
? This will never happen because IComponent
is an interface, not a class, anyway (I think, from what i remembered with superClass
).
Also, when I use reference-based typedef instead for View<T>
(eg. typedef SomethingReusable = { }
) , it doesn't work properly when I wish the macro was also capable of determining the component fields from typedefs, class fields, etc. besides anonymous structure.
the macro type generation tends to make for unreadable/unrelated errors.
In implementations of ISystem, every field variable with the following format should be automatically populated:
var enemies : View<{ pos : Position, entity : Entity }>;
or if a View class is too much:
var enemies : Iterator<{ pos : Position, entity : Entity }>;
Implementing View might have the advantage of an easy way to count items and a faster iterator implementation.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.