Page 1 of 1

Clone numbering

PostPosted: Wed Feb 18, 2015 6:04 pm
by digiot
Hi !

There are 2 questions I have about actor-clones and their numbering system :

1) Is their any limit, e.g. 256 ( actor.0 - actor.255 ), how many clones of
an actor you can have ?

2) When you have destroyed some of the clones, there are gaps in the clones list.
Afaik, GE only expands the list, always using the last clone +1 in the "CreateActor"
function.
Is there a way, to use destroyed clones ( getclone-output -1 and "" ) in the list
for newly created clones ?
Imagine, when you have shot clones, which you are destroying and creating all the
time, GE has sooner or later to deal with large clone numbers.
Idk, if this can become a real performance issue ?
Or maybe, this is not the right way, to handle shots ?
My idea for an alternative way is, just to position the finished shots out of the
view, and marking them as "free for use".


Cheers !

Re: Clone numbering

PostPosted: Thu Feb 19, 2015 5:52 am
by skydereign
digiot wrote:1) Is their any limit, e.g. 256 ( actor.0 - actor.255 ), how many clones of
an actor you can have ?

The cloneindex variable is a long so 2147483647 I believe.

digiot wrote:2) When you have destroyed some of the clones, there are gaps in the clones list.
Afaik, GE only expands the list, always using the last clone +1 in the "CreateActor"
function.
Is there a way, to use destroyed clones ( getclone-output -1 and "" ) in the list
for newly created clones ?
Imagine, when you have shot clones, which you are destroying and creating all the
time, GE has sooner or later to deal with large clone numbers.
Idk, if this can become a real performance issue ?
Or maybe, this is not the right way, to handle shots ?
My idea for an alternative way is, just to position the finished shots out of the
view, and marking them as "free for use".

gE creates clones by taking the index of the clone with the highest index and increasing it by 1. That means that you can get lower cloneindexed numbers, but you have to delete the higher indexed clones first. Allowing gE to create clones with the free indexes has been something I've considered adding, but I do like the fact that any Create Actor event will guarantee that that is the highest indexed clone, which is helpful for a bunch of things.

Re: Clone numbering

PostPosted: Fri Feb 20, 2015 2:06 pm
by digiot
skydereign wrote:The cloneindex variable is a long so 2147483647 I believe.

Ok, that should be enough for a while...
skydereign wrote:gE creates clones by taking the index of the clone with the highest index
and increasing it by 1. That means that you can get lower cloneindexed numbers,
but you have to delete the higher indexed clones first. Allowing gE to create
clones with the free indexes has been something I've considered adding, but I do
like the fact that any Create Actor event will guarantee that that is the highest
indexed clone, which is helpful for a bunch of things.

So, limiting the amount of clones is recommended ?
Or is the ressource hogging for reading large lists insignificant ?
Idk, how the computing of large types is carried out.
But only using 8-bit (0-255) should gain some speed, traversing the index ?


Cheers !

Re: Clone numbering

PostPosted: Fri Feb 20, 2015 5:58 pm
by Hares
digiot wrote:Imagine, when you have shot clones, which you are destroying and creating all the
time, GE has sooner or later to deal with large clone numbers.

If you are using a lot of shot actors, maybe it is better to use an object pool pattern.
http://en.wikipedia.org/wiki/Object_pool_pattern

This allows you to reduce the number of clones and to reduce the number of create actor events.

Re: Clone numbering

PostPosted: Fri Feb 20, 2015 6:07 pm
by digiot
@Hares :
That's exactly what I've meant with my "alternative way", never heard about
"object pool pattern" before, now I've learned something new, +1 !


Cheers !

Re: Clone numbering

PostPosted: Thu Jul 30, 2015 12:47 pm
by bat78
You can encounter the limit of any variable.

To determine the LENGTH of a variable, create a text actor and in Create Actor add this code:

Code: Select all
sprintf(text, "2 (^%i) = ? - 1", sizeof(cloneindex) * 8);

Execute/Test the game, get a calculator and calculate what is given.
Game-Editor std function sprintf will not allow printing int/uint64s. (on windows that I know).

To calculate the RANGE, simply do this
Code: Select all
sprintf(text, "(2 (^%i)) / 2 = -?  to (2 (^%i)) / 2 = +? - 1", sizeof(cloneindex) * 8, sizeof(cloneindex) * 8);

Re: Clone numbering

PostPosted: Thu Jul 30, 2015 9:16 pm
by digiot
@ bat78 : Thanks, but that is not what I wanted to know.

Since the clonenumber is an integer, it will take 4 bytes in memory.

For any calculation with it, the cpu takes one byte after the other, interpreting
it according to the Endian-mode in use.

But what will happen here, if really only the lowest byte has some value, the other
3 bytes not being in use, i.e. if the clonenumber in this case is limited up to 255 ?

Can the cpu perform a kind of shorter/faster calculation with 8-bit values, than with
larger ones ?

That's, what I'm curious about !


Cheers !

Re: Clone numbering

PostPosted: Thu Jul 30, 2015 9:47 pm
by bat78
I saw different things in your OP.

First of all, int is not always necessarily to be 4 bytes. It is:
1. Compiler Specific
2. System architecture specific
While this compiler puts them in 4 bytes, on some 8 or 16 bit systems, it may be 2 bytes.

Second, everything is in BITS, not in bytes.. compilers never account something byte by byte.

Also no, there are no performance differences, the compiler is smart enough to optimize it (and 4 byte value will be parsed in 32 bits despite the value it represents)

Re: Clone numbering

PostPosted: Thu Jul 30, 2015 10:03 pm
by digiot
bat78 wrote:First of all, int is not always necessarily to be 4 bytes. It is:
1. Compiler Specific
2. System architecture specific
While this compiler puts them in 4 bytes, on some 8 or 16 bit systems, it may be 2 bytes.

Yes, I know. But I don't believe, GE is running on any such system anywhere.
bat78 wrote:Also no, there are no performance differences, the compiler is smart enough to optimize it (and 4 byte value will be parsed in 32 bits despite the value it represents)

That's, what I wanted to know ! So the compiler is setting the rules, ok.
+1

Cheers !

Re: Clone numbering

PostPosted: Thu Jul 30, 2015 10:11 pm
by bat78
Yeah and gE uses an interpreter, but compiler however this is another topic.

Re: Clone numbering

PostPosted: Thu Jul 30, 2015 11:12 pm
by digiot
GE is using an interpreter ? That's totally new for me.

Ok, exactly asked: How does GE internally handle integer calculations,
when the values are only 8 bit large ?
Is GE also so "smart", to use the full bandwith of 32 bits for 8 bit calculations ?

Re: Clone numbering

PostPosted: Fri Jul 31, 2015 6:08 am
by bat78
Yes, gE's Script Editor is based on EiC, which stands for "Extensible, Interactive C-interpreter". It is a complete and clean ANSI-C Interpreter.

How does "gE" handle integer calculations - too broad to answer
but just like any other C-interpreter does, it parses one statement at a time.

char is 1 byte (8 bits). Since char is signed by default it has a range of negative to positive value and it's MSB is 64
while unsigned char (aka "byte") stores in the range of 0 - 255 so the MSB is 128

Re: Clone numbering

PostPosted: Tue Aug 25, 2015 4:29 pm
by songramislam12
Very nice post. it is very helpful for me.