HeapsIO / heaps

Heaps : Haxe Game Framework
http://heaps.io
MIT License
3.21k stars 338 forks source link

Subclass can't override x, y in Sprite #423

Closed aW4KeNiNG closed 6 years ago

aW4KeNiNG commented 6 years ago

Hi!

I'm writing the haxeui-heaps backend.

Currently I have a problem when I try to override the x and y fields, because they are inline functions. Maybe it needs to be inlined for performance reasons. So I need to check with you some kind of solution for the problem.

The Component class in HaxeUI has x and y fields (and that class extends ComponentBase, implemented for each backend). In the haxeui-heaps backend, ComponentBase extends Sprite class in Heaps. Sprite has x and y fields as (default, set), but the setter method is inlined. I don't know if it is possible to fix that with a macro.

I want to avoid the inclusion of a var sprite:Sprite inside of ComponentBase.

Anyway, here some screenshots with the progress in the implementation (almost finished).

image

image

ncannasse commented 6 years ago

I would like to keep Heaps x/y inlined, I'm not sure if I have a good solution for you, do you have any suggestion?

aW4KeNiNG commented 6 years ago

I'm not sure for a good solution. I don't know if it is possible with a macro (that already exists in haxe or a new macro implemented in HaxeUI) to avoid that behaviour and skip the error. Do you see it possible with that?

Another possible (poor) solution is a conditional compilation, like:

#if !no_inline_flag inline #end function set_x(v) { ... }

I don't pretend to remove the inline word. I understand it could be critical in the performance. Just I want to check some kind of valid solution in this case, if it is possible, ofc.

ncannasse commented 6 years ago

There might be some solution involving macros. You first need to inject @:build metadata to h2d.Sprite class using --macro patchTypes("patch.txt")

The content of the patch.txt would look like:

@:build(MyMacro.build()) h2d.Sprite

Then in that build macro you can remove the inline for the fields you need.

aW4KeNiNG commented 6 years ago

This is awesome!!

It is working :) . Thanks @ncannasse !!!