How to convert this c# code to haxe

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

How to convert this c# code to haxe

Dinko Pavicic
Good day to all haxers!
I'm porting some c# code to haxe and stumbled to this kind of function:

public void AddComponent<T>(Entity e, Component component) where T : Component {}

What would be haxe equivalent to this function using generics. Actually i'm puzzled with the last part(where T : Component {}).

Also in that c# code there's also a lot of usage of 'long' types with some bitshifting operations for creating unique id for objects in code.
I saw in haxe docs that there's no long type, only int. If I would use int for those, the number of possible ids would be a lot smaller. What could be a good workaround for that kind of a problem?

Many thanks in advance,
Dinko
Reply | Threaded
Open this post in threaded view
|

Re: How to convert this c# code to haxe

Yanis Benson

If each of your objects have a size of 4 bytes, which means they consist only of your int id, you need  16 GiB of memory to store the maximum number of objects with unique ids. While some apllications need such amounts of objects (and much more memory, because objects will obviously consist not only from their uids) , they are particularly rare. But if you hit such border I guess you will be compiling your application to C, so you will have some options on longs.

On 12 Aug 2011 13:20, "Dinko Pavicic" <[hidden email]> wrote:
> Good day to all haxers!
> I'm porting some c# code to haxe and stumbled to this kind of function:
>
> public void AddComponent<T>(Entity e, Component component) where T :
> Component {}
>
> What would be haxe equivalent to this function using generics. Actually i'm
> puzzled with the last part(where T : Component {}).
>
> Also in that c# code there's also a lot of usage of 'long' types with some
> bitshifting operations for creating unique id for objects in code.
> I saw in haxe docs that there's no long type, only int. If I would use int
> for those, the number of possible ids would be a lot smaller. What could be
> a good workaround for that kind of a problem?
>
> Many thanks in advance,
> Dinko
>
> --
> View this message in context: http://haxe.1354130.n2.nabble.com/How-to-convert-this-c-code-to-haxe-tp6679750p6679750.html
> Sent from the Haxe mailing list archive at Nabble.com.
>
> --
> haXe - an open source web programming language
> http://haxe.org

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: How to convert this c# code to haxe

Dinko Pavicic
Thanks, that should be large enough for the ids I suppose.

I'm trying to convert Artemis entity system to haxe. Originally it is written in Java but there's also a c# port.
http://gamadu.com/artemis/
https://github.com/thelinuxlich/artemis_CSharp

There's a note on id's and longs on the authors website so I was concerned about it.
Quote:

Because each system and component has it's own bit identifier, and Java's long is only 64 bit, which means there's a built-in limit of 64 to the number of systems and components. It's actually quite easy to change this to Java's BitSet which supports virtually unlimited bits, but it will require slight more nanoseconds than simple long bit calculation. We chose not to add it because we don't think there's real need for it since most games use far less distinct systems and components than 64. However, if you need it you know about this.


D.

D.
Reply | Threaded
Open this post in threaded view
|

Re: How to convert this c# code to haxe

Nicolas Cannasse
In reply to this post by Yanis Benson
Le 12/08/2011 11:42, Yanis Benson a écrit :
> If each of your objects have a size of 4 bytes, which means they consist
> only of your int id, you need  16 GiB of memory to store the maximum
> number of objects with unique ids.

A bit more since actually you will need additional informations for the
garbage collector (1 mark bit per object at least), and a pointer to the
virtual method table as well ;)

Nicolas

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: How to convert this c# code to haxe

Dinko Pavicic
In reply to this post by Dinko Pavicic
I checked out that id code more deeply and it seems that if using an int there would be maximum of 32 components in the game code.
Guess I have to do something different with that id code not to use ints for ids.
Reply | Threaded
Open this post in threaded view
|

Re: How to convert this c# code to haxe

Yanis Benson
In reply to this post by Dinko Pavicic

Nicolass, + virtual table reference usually, but that was a humble estimation.

Dinko, now it's a bit different. This is a set, not uid, and it's limitations lay in a different plane. However, overall statement is a bit strange for me without deeper knowledge of the code. In case every entity in this system can belong to all the entity types at once the set system makes sense, however with a little slowdown (and without using bitsets) it can be reduced to unique typeset ids usage based on ints (as my first estimation also says). If you don't want to add such system I'd suggest you to use 1 int and add a switch for using 2 ints, since it's so easy in haxe.

On 12 Aug 2011 14:04, "Dinko Pavicic" <[hidden email]> wrote:
> Thanks, that should be large enough for the ids I suppose.
>
> I'm trying to convert Artemis entity system to haxe. Originally it is
> written in Java but there's also a c# port.
> http://gamadu.com/artemis/
> https://github.com/thelinuxlich/artemis_CSharp
>
> There's a note on id's and longs on the authors website so I was concerned
> about it.
> Quote:
>
> Because each system and component has it's own bit identifier, and Java's
> long is only 64 bit, which means there's a built-in limit of 64 to the
> number of systems and components. It's actually quite easy to change this to
> Java's BitSet which supports virtually unlimited bits, but it will require
> slight more nanoseconds than simple long bit calculation. We chose not to
> add it because we don't think there's real need for it since most games use
> far less distinct systems and components than 64. However, if you need it
> you know about this.
>
>
> D.
>
> D.
>
> --
> View this message in context: http://haxe.1354130.n2.nabble.com/How-to-convert-this-c-code-to-haxe-tp6679750p6679833.html
> Sent from the Haxe mailing list archive at Nabble.com.
>
> --
> haXe - an open source web programming language
> http://haxe.org

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: How to convert this c# code to haxe

Yanis Benson
In reply to this post by Nicolas Cannasse

Omg, so sorry Nicolass, my eyes are failing me. I oberlooked your statement about virtual table.

On 12 Aug 2011 14:08, "Nicolas Cannasse" <[hidden email]> wrote:
> Le 12/08/2011 11:42, Yanis Benson a écrit :
>> If each of your objects have a size of 4 bytes, which means they consist
>> only of your int id, you need 16 GiB of memory to store the maximum
>> number of objects with unique ids.
>
> A bit more since actually you will need additional informations for the
> garbage collector (1 mark bit per object at least), and a pointer to the
> virtual method table as well ;)
>
> Nicolas
>
> --
> haXe - an open source web programming language
> http://haxe.org

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: How to convert this c# code to haxe

Dion Whitehead Amago
In reply to this post by Dinko Pavicic
If you are porting an Entity/Component game engine, I would recommend
looking at the Pushbutton Engine.  I've made a haxe port "hydrax"
available on haxelib, it it built around components and entities.

Dion

On Fri, Aug 12, 2011 at 4:19 AM, Dinko Pavicic
<[hidden email]> wrote:

> Good day to all haxers!
> I'm porting some c# code to haxe and stumbled to this kind of function:
>
> public void AddComponent<T>(Entity e, Component component) where T :
> Component {}
>
> What would be haxe equivalent to this function using generics. Actually i'm
> puzzled with the last part(where T : Component {}).
>
> Also in that c# code there's also a lot of usage of 'long' types with some
> bitshifting operations for creating unique id for objects in code.
> I saw in haxe docs that there's no long type, only int. If I would use int
> for those, the number of possible ids would be a lot smaller. What could be
> a good workaround for that kind of a problem?
>
> Many thanks in advance,
> Dinko
>
> --
> View this message in context: http://haxe.1354130.n2.nabble.com/How-to-convert-this-c-code-to-haxe-tp6679750p6679750.html
> Sent from the Haxe mailing list archive at Nabble.com.
>
> --
> haXe - an open source web programming language
> http://haxe.org
>

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: How to convert this c# code to haxe

Dinko Pavicic
Thanks! I'm aware of Hydrax and worked before with PushButton engine. I'll check it out.
Thanks,
D.
Reply | Threaded
Open this post in threaded view
|

Re: Re: [haXe] How to convert this c# code to haxe

Rob Fell
In reply to this post by Dion Whitehead Amago
Likewise Dinko, "awe6" offers a twist on a related theme
(awe6.interfaces.IEntityCollection):
http://awe6.org


On 11:59 AM, Dion Whitehead Amago wrote:

> If you are porting an Entity/Component game engine, I would recommend
> looking at the Pushbutton Engine.  I've made a haxe port "hydrax"
> available on haxelib, it it built around components and entities.
>
> Dion
>
> On Fri, Aug 12, 2011 at 4:19 AM, Dinko Pavicic
> <[hidden email]>  wrote:
>> Good day to all haxers!
>> I'm porting some c# code to haxe and stumbled to this kind of function:
>>
>> public void AddComponent<T>(Entity e, Component component) where T :
>> Component {}
>>
>> What would be haxe equivalent to this function using generics. Actually i'm
>> puzzled with the last part(where T : Component {}).
>>
>> Also in that c# code there's also a lot of usage of 'long' types with some
>> bitshifting operations for creating unique id for objects in code.
>> I saw in haxe docs that there's no long type, only int. If I would use int
>> for those, the number of possible ids would be a lot smaller. What could be
>> a good workaround for that kind of a problem?
>>
>> Many thanks in advance,
>> Dinko
>>
>> --
>> View this message in context: http://haxe.1354130.n2.nabble.com/How-to-convert-this-c-code-to-haxe-tp6679750p6679750.html
>> Sent from the Haxe mailing list archive at Nabble.com.
>>
>> --
>> haXe - an open source web programming language
>> http://haxe.org
>>
>

--
haXe - an open source web programming language
http://haxe.org