Thread View: comp.lang.c
13 messages
13 total messages
Started by fir
Fri, 27 Nov 2026 17:13
fir's bag visualisation
Author: fir
Date: Fri, 27 Nov 2026 17:13
Date: Fri, 27 Nov 2026 17:13
140 lines
4239 bytes
4239 bytes
maybe this group recently lacks a post of strict hard c so this is
strict hard c
to use in lean fire shots i wrote and ad-hoc container named bag
note i was not thinking wrting it becouse if im in creative mode
even 5 or 30 minutes of slowdown matters (and later i also not lookd on
that) so maybe or even possibly this have some errors
but i find it as a good interesting topic on clc so the question is:
how to improve that?
enum {MAX_WORLDS = 30};
int bag_i_tab[MAX_WORLDS];
int bag_max_tab[MAX_WORLDS];
Object3D *bag_tab[MAX_WORLDS];
int bag_i=0;
int bag_max=0;
Object3D *bag=NULL;
SwitchBag(int from, int to)
{
bag_i_tab[from] = bag_i ;
bag_max_tab[from] = bag_max;
bag_tab[from] = bag;
bag_i = bag_i_tab[to];
bag_max = bag_max_tab[to];
bag = bag_tab[to];
}
inline int countOcupationInBag()
{
int counter=0;
for(int i=0;i<bag_max;i++) if(bag[i].enabled) counter++;
return counter;
}
inline void ResizeBag(int new_size)
{
int old_size=bag_max;
Object3D *new_bag=(Object3D*) realloc(bag,new_size*sizeof(Object3D));
if(!new_bag) return;
bag=new_bag;
for(int i=old_size;i<new_size;i++) memset(&bag[i],0,sizeof(Object3D));
bag_max=new_size;
if(bag_i>=bag_max) bag_i=0;
}
inline int FindEmptySlotInBag()
{
if(bag_max==0) ResizeBag(3000);
if(bag_max==0) return -1;
if(bag_i>=bag_max) bag_i=0;
for(int i=0;i<bag_max;i++)
{
if(!bag[bag_i].enabled) return bag_i;
bag_i++;
if(bag_i>=bag_max) bag_i=0;
}
int old_size=bag_max;
ResizeBag(bag_max*2);
if(bag_max==old_size) return -1;
return FindEmptySlotInBag();
}
void ResetBag()
{
for(int i=0;i<bag_max;i++) bag[i].enabled=0;
bag_i=0;
}
void VisualizeBag()
{
for(int i=0; i<bag_max; i++)
{
int x = i%200;
int y = i/200;
if(x>=frame_size_x) continue;
if(y>=frame_size_y) continue;
int color = 0x00c0c0;
if(!bag[i].enabled) color = 0x003010;
else
{
if(bag[i].type=='smo') color = 0x808080;
if(bag[i].type=='deb') color = 0xc00000;
if(bag[i].type=='bull') color = 0xffff00;
}
for(int q=0; q<3; q++)
for(int p=0; p<3; p++)
SetPixelUnsafe(10+x*3+p,10+ y*3+q,color);
}
}
i also made this function above to visualise it in runtime
this video shows it at worrk
https://www.youtube.com/watch?v=DN9kmveSYTs
note those grreen blocks are for empty slots,
gray are for smokes (those trails) yellow for bullets and
red are for debris (this what is generated in explosions)
- normally its not easy to overflow initial 3000
size but i specially shooted many rockets to make
unusual amount of debris to create and bag growed
(which is seen)
hovever this growing may be a problem to potential errors as as
i once wrote i just reallock the bag in loops that iterate over it
(but as for a moment i was not checking for those errors
Re: fir's bag visualisation
Author: fir
Date: Fri, 27 Nov 2026 17:17
Date: Fri, 27 Nov 2026 17:17
3 lines
1422 bytes
1422 bytes
ps i changed my mind and david brown can comment my post (but onlu unlike he talks lies on me..specially lying m not doin science.. becouse this is really dumb (dumb + lies = bad thing, non acceptable)
Re: fir's bag visualisation
Author: fir
Date: Fri, 27 Nov 2026 17:32
Date: Fri, 27 Nov 2026 17:32
167 lines
5745 bytes
5745 bytes
fir pisze:
> maybe this group recently lacks a post of strict hard c so this is
> strict hard c
>
> to use in lean fire shots i wrote and ad-hoc container named bag
>
> note i was not thinking wrting it becouse if im in creative mode
> even 5 or 30 minutes of slowdown matters (and later i also not lookd on
> that) so maybe or even possibly this have some errors
>
> but i find it as a good interesting topic on clc so the question is:
> how to improve that?
>
>
>
> enum {MAX_WORLDS = 30};
>
> int bag_i_tab[MAX_WORLDS];
> int bag_max_tab[MAX_WORLDS];
> Object3D *bag_tab[MAX_WORLDS];
>
>
> int bag_i=0;
> int bag_max=0;
> Object3D *bag=NULL;
>
> SwitchBag(int from, int to)
> {
>
> bag_i_tab[from] = bag_i ;
> bag_max_tab[from] = bag_max;
> bag_tab[from] = bag;
>
>
> bag_i = bag_i_tab[to];
> bag_max = bag_max_tab[to];
> bag = bag_tab[to];
> }
>
>
>
> inline int countOcupationInBag()
> {
> int counter=0;
> for(int i=0;i<bag_max;i++) if(bag[i].enabled) counter++;
> return counter;
> }
>
>
> inline void ResizeBag(int new_size)
> {
>
> int old_size=bag_max;
> Object3D *new_bag=(Object3D*) realloc(bag,new_size*sizeof(Object3D));
> if(!new_bag) return;
>
> bag=new_bag;
> for(int i=old_size;i<new_size;i++) memset(&bag[i],0,sizeof(Object3D));
>
> bag_max=new_size;
> if(bag_i>=bag_max) bag_i=0;
> }
>
>
> inline int FindEmptySlotInBag()
> {
> if(bag_max==0) ResizeBag(3000);
> if(bag_max==0) return -1;
>
> if(bag_i>=bag_max) bag_i=0;
>
> for(int i=0;i<bag_max;i++)
> {
> if(!bag[bag_i].enabled) return bag_i;
> bag_i++;
> if(bag_i>=bag_max) bag_i=0;
> }
>
> int old_size=bag_max;
> ResizeBag(bag_max*2);
> if(bag_max==old_size) return -1;
>
> return FindEmptySlotInBag();
> }
>
>
> void ResetBag()
> {
> for(int i=0;i<bag_max;i++) bag[i].enabled=0;
> bag_i=0;
> }
>
> void VisualizeBag()
> {
>
> for(int i=0; i<bag_max; i++)
> {
> int x = i%200;
> int y = i/200;
>
> if(x>=frame_size_x) continue;
> if(y>=frame_size_y) continue;
>
> int color = 0x00c0c0;
> if(!bag[i].enabled) color = 0x003010;
> else
> {
>
> if(bag[i].type=='smo') color = 0x808080;
> if(bag[i].type=='deb') color = 0xc00000;
> if(bag[i].type=='bull') color = 0xffff00;
>
> }
>
> for(int q=0; q<3; q++)
> for(int p=0; p<3; p++)
> SetPixelUnsafe(10+x*3+p,10+ y*3+q,color);
> }
> }
>
>
> i also made this function above to visualise it in runtime
> this video shows it at worrk
>
> https://www.youtube.com/watch?v=DN9kmveSYTs
>
> note those grreen blocks are for empty slots,
> gray are for smokes (those trails) yellow for bullets and
> red are for debris (this what is generated in explosions)
> - normally its not easy to overflow initial 3000
> size but i specially shooted many rockets to make
> unusual amount of debris to create and bag growed
> (which is seen)
>
> hovever this growing may be a problem to potential errors as as
> i once wrote i just reallock the bag in loops that iterate over it
> (but as for a moment i was not checking for those errors
>
>
especialy what is worthdoin is probably make 'compacting'
maybe each frame thus lowering bag_max and all those loops whose iterate
to bag_max will thank me
wonder should i do it each frame or once a N frames?
i thinked a bit of reallocking ram down but this probably has no sense
hovever it seems that if i will do the compacting i wil to add another
variable
int bag_i=0; // <- iterator
int bag_max=0; // <-- max capacity
Object3D *bag=NULL;
something as bag_top or bag_capacity
probably i would add bag_capacity as a lot of code uses now bag_max and
i dont want to revrite it all...
if i would compact and realloc down than i still could use only bag_max
so this is serios question better to reallock down after comactions
or introduce new variable?
Re: fir's bag visualisation
Author: fir
Date: Fri, 27 Nov 2026 17:33
Date: Fri, 27 Nov 2026 17:33
142 lines
4980 bytes
4980 bytes
fir pisze:
> maybe this group recently lacks a post of strict hard c so this is
> strict hard c
>
> to use in lean fire shots i wrote and ad-hoc container named bag
>
> note i was not thinking wrting it becouse if im in creative mode
> even 5 or 30 minutes of slowdown matters (and later i also not lookd on
> that) so maybe or even possibly this have some errors
>
> but i find it as a good interesting topic on clc so the question is:
> how to improve that?
>
>
>
> enum {MAX_WORLDS = 30};
>
> int bag_i_tab[MAX_WORLDS];
> int bag_max_tab[MAX_WORLDS];
> Object3D *bag_tab[MAX_WORLDS];
>
>
> int bag_i=0;
> int bag_max=0;
> Object3D *bag=NULL;
>
> SwitchBag(int from, int to)
> {
>
> bag_i_tab[from] = bag_i ;
> bag_max_tab[from] = bag_max;
> bag_tab[from] = bag;
>
>
> bag_i = bag_i_tab[to];
> bag_max = bag_max_tab[to];
> bag = bag_tab[to];
> }
>
>
>
> inline int countOcupationInBag()
> {
> int counter=0;
> for(int i=0;i<bag_max;i++) if(bag[i].enabled) counter++;
> return counter;
> }
>
>
> inline void ResizeBag(int new_size)
> {
>
> int old_size=bag_max;
> Object3D *new_bag=(Object3D*) realloc(bag,new_size*sizeof(Object3D));
> if(!new_bag) return;
>
> bag=new_bag;
> for(int i=old_size;i<new_size;i++) memset(&bag[i],0,sizeof(Object3D));
>
> bag_max=new_size;
> if(bag_i>=bag_max) bag_i=0;
> }
>
>
> inline int FindEmptySlotInBag()
> {
> if(bag_max==0) ResizeBag(3000);
> if(bag_max==0) return -1;
>
> if(bag_i>=bag_max) bag_i=0;
>
> for(int i=0;i<bag_max;i++)
> {
> if(!bag[bag_i].enabled) return bag_i;
> bag_i++;
> if(bag_i>=bag_max) bag_i=0;
> }
>
> int old_size=bag_max;
> ResizeBag(bag_max*2);
> if(bag_max==old_size) return -1;
>
> return FindEmptySlotInBag();
> }
>
>
> void ResetBag()
> {
> for(int i=0;i<bag_max;i++) bag[i].enabled=0;
> bag_i=0;
> }
>
> void VisualizeBag()
> {
>
> for(int i=0; i<bag_max; i++)
> {
> int x = i%200;
> int y = i/200;
>
> if(x>=frame_size_x) continue;
> if(y>=frame_size_y) continue;
>
> int color = 0x00c0c0;
> if(!bag[i].enabled) color = 0x003010;
> else
> {
>
> if(bag[i].type=='smo') color = 0x808080;
> if(bag[i].type=='deb') color = 0xc00000;
> if(bag[i].type=='bull') color = 0xffff00;
>
> }
>
> for(int q=0; q<3; q++)
> for(int p=0; p<3; p++)
> SetPixelUnsafe(10+x*3+p,10+ y*3+q,color);
> }
> }
>
>
> i also made this function above to visualise it in runtime
> this video shows it at worrk
>
> https://www.youtube.com/watch?v=DN9kmveSYTs
>
> note those grreen blocks are for empty slots,
> gray are for smokes (those trails) yellow for bullets and
> red are for debris (this what is generated in explosions)
> - normally its not easy to overflow initial 3000
> size but i specially shooted many rockets to make
> unusual amount of debris to create and bag growed
> (which is seen)
>
> hovever this growing may be a problem to potential errors as as
> i once wrote i just reallock the bag in loops that iterate over it
> (but as for a moment i was not checking for those errors
>
>
>
>
bonita close your eyes
Re: fir's bag visualisation
Author: Bonita Montero
Date: Fri, 27 Nov 2026 17:36
Date: Fri, 27 Nov 2026 17:36
5 lines
1405 bytes
1405 bytes
Am 27.11.2026 um 18:33 schrieb fir: > bonita close your eyes Why do you always reply to yourself so many times ?
Re: fir's bag visualisation
Author: fir
Date: Fri, 27 Nov 2026 17:43
Date: Fri, 27 Nov 2026 17:43
12 lines
1699 bytes
1699 bytes
Bonita Montero pisze: > Am 27.11.2026 um 18:33 schrieb fir: > >> bonita close your eyes > > Why do you always reply to yourself so many times ? your alike with your attitude when you write on chat/irc you wait untill you send second line until someone wrote something? there is difference among continuation and answering - difference not hard to realize
Re: fir's bag visualisation
Author: fir
Date: Fri, 27 Nov 2026 17:47
Date: Fri, 27 Nov 2026 17:47
166 lines
5355 bytes
5355 bytes
fir pisze:
> maybe this group recently lacks a post of strict hard c so this is
> strict hard c
>
> to use in lean fire shots i wrote and ad-hoc container named bag
>
> note i was not thinking wrting it becouse if im in creative mode
> even 5 or 30 minutes of slowdown matters (and later i also not lookd on
> that) so maybe or even possibly this have some errors
>
> but i find it as a good interesting topic on clc so the question is:
> how to improve that?
>
>
>
> enum {MAX_WORLDS = 30};
>
> int bag_i_tab[MAX_WORLDS];
> int bag_max_tab[MAX_WORLDS];
> Object3D *bag_tab[MAX_WORLDS];
>
>
> int bag_i=0;
> int bag_max=0;
> Object3D *bag=NULL;
>
> SwitchBag(int from, int to)
> {
>
> bag_i_tab[from] = bag_i ;
> bag_max_tab[from] = bag_max;
> bag_tab[from] = bag;
>
>
> bag_i = bag_i_tab[to];
> bag_max = bag_max_tab[to];
> bag = bag_tab[to];
> }
>
>
>
> inline int countOcupationInBag()
> {
> int counter=0;
> for(int i=0;i<bag_max;i++) if(bag[i].enabled) counter++;
> return counter;
> }
>
>
> inline void ResizeBag(int new_size)
> {
>
> int old_size=bag_max;
> Object3D *new_bag=(Object3D*) realloc(bag,new_size*sizeof(Object3D));
> if(!new_bag) return;
>
> bag=new_bag;
> for(int i=old_size;i<new_size;i++) memset(&bag[i],0,sizeof(Object3D));
>
> bag_max=new_size;
> if(bag_i>=bag_max) bag_i=0;
> }
>
>
> inline int FindEmptySlotInBag()
> {
> if(bag_max==0) ResizeBag(3000);
> if(bag_max==0) return -1;
>
> if(bag_i>=bag_max) bag_i=0;
>
> for(int i=0;i<bag_max;i++)
> {
> if(!bag[bag_i].enabled) return bag_i;
> bag_i++;
> if(bag_i>=bag_max) bag_i=0;
> }
>
> int old_size=bag_max;
> ResizeBag(bag_max*2);
> if(bag_max==old_size) return -1;
>
> return FindEmptySlotInBag();
> }
>
>
> void ResetBag()
> {
> for(int i=0;i<bag_max;i++) bag[i].enabled=0;
> bag_i=0;
> }
>
> void VisualizeBag()
> {
>
> for(int i=0; i<bag_max; i++)
> {
> int x = i%200;
> int y = i/200;
>
> if(x>=frame_size_x) continue;
> if(y>=frame_size_y) continue;
>
> int color = 0x00c0c0;
> if(!bag[i].enabled) color = 0x003010;
> else
> {
>
> if(bag[i].type=='smo') color = 0x808080;
> if(bag[i].type=='deb') color = 0xc00000;
> if(bag[i].type=='bull') color = 0xffff00;
>
> }
>
> for(int q=0; q<3; q++)
> for(int p=0; p<3; p++)
> SetPixelUnsafe(10+x*3+p,10+ y*3+q,color);
> }
> }
>
>
> i also made this function above to visualise it in runtime
> this video shows it at worrk
>
> https://www.youtube.com/watch?v=DN9kmveSYTs
>
> note those grreen blocks are for empty slots,
> gray are for smokes (those trails) yellow for bullets and
> red are for debris (this what is generated in explosions)
> - normally its not easy to overflow initial 3000
> size but i specially shooted many rockets to make
> unusual amount of debris to create and bag growed
> (which is seen)
>
> hovever this growing may be a problem to potential errors as as
> i once wrote i just reallock the bag in loops that iterate over it
> (but as for a moment i was not checking for those errors
>
>
>
i should add yet method of addition
int BagAdd(Position *p,int type,int ttl)
{
int i=FindEmptySlotInBag();
if(i<0) return -1;
memset(&bag[i],0,sizeof(Object3D));
bag[i].enabled=1;
bag[i].p=*p;
bag[i].type=type;
bag[i].ttl=ttl;
//..... more fields to initialise
bag_i=i+1; if(bag_i>=bag_max) bag_i=0;
return i;
}
Re: fir's bag visualisation
Author: fir
Date: Fri, 27 Nov 2026 17:50
Date: Fri, 27 Nov 2026 17:50
16 lines
1919 bytes
1919 bytes
fir pisze: > Bonita Montero pisze: >> Am 27.11.2026 um 18:33 schrieb fir: >> >>> bonita close your eyes >> >> Why do you always reply to yourself so many times ? > > your alike with your attitude when you write on chat/irc > you wait untill you send second line until someone wrote something? > there is difference among continuation and answering - difference not > hard to realize > there is a number of people having problem with such simple think how high their iq must be?? (well some got a proper c post to comment not a place to talk on low iq things)
Re: fir's bag visualisation
Author: Bonita Montero
Date: Fri, 27 Nov 2026 17:56
Date: Fri, 27 Nov 2026 17:56
12 lines
1836 bytes
1836 bytes
Am 27.11.2026 um 18:43 schrieb fir: > Bonita Montero pisze: >> Why do you always reply to yourself so many times ? > your alike with your attitude when you write on chat/irc > you wait untill you send second line until someone wrote something? > there is difference among continuation and answering - difference not > hard to realize I’d say you’re simply unable to organize your thoughts and wait to post until everything has a structure.
Re: fir's bag visualisation
Author: fir
Date: Fri, 27 Nov 2026 18:09
Date: Fri, 27 Nov 2026 18:09
18 lines
2121 bytes
2121 bytes
Bonita Montero pisze: > Am 27.11.2026 um 18:43 schrieb fir: > >> Bonita Montero pisze: > >>> Why do you always reply to yourself so many times ? > >> your alike with your attitude when you write on chat/irc >> you wait untill you send second line until someone wrote something? >> there is difference among continuation and answering - difference not >> hard to realize > I’d say you’re simply unable to organize your thoughts > and wait to post until everything has a structure. i dont want to do that becouse it is bad, some insights when you write something at live are the best..if i would wait they will be lost..i only not write when i have no valuable insight at all
Re: fir's bag visualisation
Author: fir
Date: Fri, 27 Nov 2026 19:21
Date: Fri, 27 Nov 2026 19:21
253 lines
8051 bytes
8051 bytes
fir pisze:
> fir pisze:
>> maybe this group recently lacks a post of strict hard c so this is
>> strict hard c
>>
>> to use in lean fire shots i wrote and ad-hoc container named bag
>>
>> note i was not thinking wrting it becouse if im in creative mode
>> even 5 or 30 minutes of slowdown matters (and later i also not lookd
>> on that) so maybe or even possibly this have some errors
>>
>> but i find it as a good interesting topic on clc so the question is:
>> how to improve that?
>>
>>
>>
>> enum {MAX_WORLDS = 30};
>>
>> int bag_i_tab[MAX_WORLDS];
>> int bag_max_tab[MAX_WORLDS];
>> Object3D *bag_tab[MAX_WORLDS];
>>
>>
>> int bag_i=0;
>> int bag_max=0;
>> Object3D *bag=NULL;
>>
>> SwitchBag(int from, int to)
>> {
>>
>> bag_i_tab[from] = bag_i ;
>> bag_max_tab[from] = bag_max;
>> bag_tab[from] = bag;
>>
>>
>> bag_i = bag_i_tab[to];
>> bag_max = bag_max_tab[to];
>> bag = bag_tab[to];
>> }
>>
>>
>>
>> inline int countOcupationInBag()
>> {
>> int counter=0;
>> for(int i=0;i<bag_max;i++) if(bag[i].enabled) counter++;
>> return counter;
>> }
>>
>>
>> inline void ResizeBag(int new_size)
>> {
>>
>> int old_size=bag_max;
>> Object3D *new_bag=(Object3D*)
>> realloc(bag,new_size*sizeof(Object3D));
>> if(!new_bag) return;
>>
>> bag=new_bag;
>> for(int i=old_size;i<new_size;i++)
>> memset(&bag[i],0,sizeof(Object3D));
>>
>> bag_max=new_size;
>> if(bag_i>=bag_max) bag_i=0;
>> }
>>
>>
>> inline int FindEmptySlotInBag()
>> {
>> if(bag_max==0) ResizeBag(3000);
>> if(bag_max==0) return -1;
>>
>> if(bag_i>=bag_max) bag_i=0;
>>
>> for(int i=0;i<bag_max;i++)
>> {
>> if(!bag[bag_i].enabled) return bag_i;
>> bag_i++;
>> if(bag_i>=bag_max) bag_i=0;
>> }
>>
>> int old_size=bag_max;
>> ResizeBag(bag_max*2);
>> if(bag_max==old_size) return -1;
>>
>> return FindEmptySlotInBag();
>> }
>>
>>
>> void ResetBag()
>> {
>> for(int i=0;i<bag_max;i++) bag[i].enabled=0;
>> bag_i=0;
>> }
>>
>> void VisualizeBag()
>> {
>>
>> for(int i=0; i<bag_max; i++)
>> {
>> int x = i%200;
>> int y = i/200;
>>
>> if(x>=frame_size_x) continue;
>> if(y>=frame_size_y) continue;
>>
>> int color = 0x00c0c0;
>> if(!bag[i].enabled) color = 0x003010;
>> else
>> {
>>
>> if(bag[i].type=='smo') color = 0x808080;
>> if(bag[i].type=='deb') color = 0xc00000;
>> if(bag[i].type=='bull') color = 0xffff00;
>>
>> }
>>
>> for(int q=0; q<3; q++)
>> for(int p=0; p<3; p++)
>> SetPixelUnsafe(10+x*3+p,10+ y*3+q,color);
>> }
>> }
>>
>>
>> i also made this function above to visualise it in runtime
>> this video shows it at worrk
>>
>> https://www.youtube.com/watch?v=DN9kmveSYTs
>>
>> note those grreen blocks are for empty slots,
>> gray are for smokes (those trails) yellow for bullets and
>> red are for debris (this what is generated in explosions)
>> - normally its not easy to overflow initial 3000
>> size but i specially shooted many rockets to make
>> unusual amount of debris to create and bag growed
>> (which is seen)
>>
>> hovever this growing may be a problem to potential errors as as
>> i once wrote i just reallock the bag in loops that iterate over it
>> (but as for a moment i was not checking for those errors
>>
>>
> especialy what is worthdoin is probably make 'compacting'
> maybe each frame thus lowering bag_max and all those loops whose iterate
> to bag_max will thank me
>
> wonder should i do it each frame or once a N frames?
>
> i thinked a bit of reallocking ram down but this probably has no sense
>
> hovever it seems that if i will do the compacting i wil to add another
> variable
>
>
>
> int bag_i=0; // <- iterator
> int bag_max=0; // <-- max capacity
> Object3D *bag=NULL;
>
>
> something as bag_top or bag_capacity
>
> probably i would add bag_capacity as a lot of code uses now bag_max and
> i dont want to revrite it all...
> if i would compact and realloc down than i still could use only bag_max
> so this is serios question better to reallock down after comactions
> or introduce new variable?
>
>
i added some compaction - though this compaction copies also a full
records to preserve order (which im not sure is ok..it may be doze of
copying bag of 3000 is 800 KB, so its probbaly copying of 400 KB this
compacting, quite heavy)
void CompactBag()
{
int dst=0;
for(int src=0;src<bag_max;src++)
{
if(!bag[src].enabled) continue;
if(dst!=src) bag[dst]=bag[src];
dst++;
}
for(int i=dst;i<bag_max;i++) bag[i].enabled=0;
bag_i=dst;
bag_max=dst+500;
ResizeBag(bag_max);
}
also changed ResizeBag
inline void ResizeBag(int new_size)
{
if(new_size>bag_capacity)
{
Object3D *new_bag=(Object3D*)realloc(bag,new_size*sizeof(Object3D));
if(!new_bag && new_size>0) { ERROR_("realloc failed in bag
resize"); return; }
bag=new_bag;
if(new_size>bag_capacity)
memset(&bag[bag_capacity],0,(new_size-bag_capacity)*sizeof(Object3D));
bag_capacity=new_size;
}
bag_max=new_size;
if(bag_i>=bag_max) bag_i=0;
}
now bag max is less than it was so loops shuld be happy
(i am not sure it has not some bug/errors in it but in run
it seem ok)
after compacting i still set bag_max to compacted size + 500
so loops could be happier but i think its maybe bettar to have some
space for insertions without need to insertions would call resize
(though such resize is veru cheap so i maybe could set it lower)
now on awerage bag_max is like 1000-1500 instead of constant 3000
and also iterator behaves differently it not rolls up whole bag but
goes forward empty space on compactions jumbs back and go another clear
scpae forward... im not sure if this not makes generally the program
faster but it would need tests
https://www.youtube.com/watch?v=cZpWaGa0AWQ
generally it makes some mysteries here, like mentioned if i should
preserve order or not, i will probably write second one which not
preserves order yet and eventually wil switch one to another
Re: fir's bag visualisation
Author: fir
Date: Fri, 27 Nov 2026 20:00
Date: Fri, 27 Nov 2026 20:00
173 lines
4671 bytes
4671 bytes
i tested yet thoce no order compactor... by the eye its hard to see
difference in time frames etc (becouse overally scene is dynamic, by my
eye not lurking to much its no clearly visible difference but logically
i think smaller loops are better and no order compactor probably better)
so fial code as for now for the bag would be
enum {MAX_WORLDS = 30};
int bag_i_tab[MAX_WORLDS];
int bag_max_tab[MAX_WORLDS];
int bag_capacity_tab[MAX_WORLDS];
Object3D *bag_tab[MAX_WORLDS];
int bag_i=0;
int bag_max=0;
int bag_capacity=0;
Object3D *bag=NULL;
SwitchBag(int from, int to)
{
bag_i_tab[from] = bag_i ;
bag_max_tab[from] = bag_max;
bag_capacity_tab[from] = bag_capacity;
bag_tab[from] = bag;
bag_i = bag_i_tab[to];
bag_max = bag_max_tab[to];
bag_capacity = bag_capacity_tab[to] ;
bag = bag_tab[to];
}
inline int countOcupationInBag()
{
int counter=0;
for(int i=0;i<bag_max;i++) if(bag[i].enabled) counter++;
return counter;
}
inline void ResizeBag(int new_size)
{
if(new_size>bag_capacity)
{
Object3D *new_bag=(Object3D*)realloc(bag,new_size*sizeof(Object3D));
if(!new_bag && new_size>0) { ERROR_("realloc failed in bag
resize"); return; }
bag=new_bag;
if(new_size>bag_capacity)
memset(&bag[bag_capacity],0,(new_size-bag_capacity)*sizeof(Object3D));
bag_capacity=new_size;
}
bag_max=new_size;
if(bag_i>=bag_max) bag_i=0;
}
inline int FindEmptySlotInBag()
{
if(bag_max==0) ResizeBag(3000);
if(bag_max==0) { ERROR_("unexpected state in FindEmptySlotInBag");
return -1; }
if(bag_i>=bag_max) bag_i=0;
for(int i=0;i<bag_max;i++)
{
if(!bag[bag_i].enabled) return bag_i;
bag_i++;
if(bag_i>=bag_max) bag_i=0;
}
int old_size=bag_max;
ResizeBag(bag_max*1.5);
if(bag_max==old_size) { ERROR_("unexpected state in
FindEmptySlotInBag"); return -1; }
return FindEmptySlotInBag();
}
void ResetBag()
{
for(int i=0;i<bag_max;i++) bag[i].enabled=0;
bag_i=0;
}
void VisualizeBag()
{
for(int i=0; i<bag_max; i++)
{
int x = i%200;
int y = i/200;
if(x>=frame_size_x) continue;
if(y>=frame_size_y) continue;
int color = 0x00c0c0;
if(!bag[i].enabled) color = 0x003010;
else
{
if(bag[i].type=='smo') color = 0x808080;
if(bag[i].type=='deb') color = 0xc00000;
if(bag[i].type=='bull') color = 0xffff00;
}
for(int q=0; q<3; q++)
for(int p=0; p<3; p++)
SetPixelUnsafe(10+x*3+p,10+ y*3+q,color);
}
}
void CompactBag_KeepOrder()
{
int dst=0;
for(int src=0;src<bag_max;src++)
{
if(!bag[src].enabled) continue;
if(dst!=src) bag[dst]=bag[src];
dst++;
}
for(int i=dst;i<bag_max;i++) bag[i].enabled=0;
bag_i=dst;
bag_max=dst+200;
ResizeBag(bag_max);
}
void CompactBag_NoOrder()
{
int dst=0;
int src=bag_max-1;
while(dst<src)
{
if(bag[dst].enabled) { dst++; continue; }
if(!bag[src].enabled) { src--; continue; }
bag[dst]=bag[src];
bag[src].enabled=0;
dst++;
src--;
}
bag_i=dst;
bag_max=dst+200;
ResizeBag(bag_max);
}
fir
Re: fir's bag visualisation
Author: fir
Date: Tue, 01 Dec 2026 13:03
Date: Tue, 01 Dec 2026 13:03
230 lines
7285 bytes
7285 bytes
fir pisze:
> i tested yet thoce no order compactor... by the eye its hard to see
> difference in time frames etc (becouse overally scene is dynamic, by my
> eye not lurking to much its no clearly visible difference but logically
> i think smaller loops are better and no order compactor probably better)
>
> so fial code as for now for the bag would be
>
>
> enum {MAX_WORLDS = 30};
>
> int bag_i_tab[MAX_WORLDS];
> int bag_max_tab[MAX_WORLDS];
> int bag_capacity_tab[MAX_WORLDS];
> Object3D *bag_tab[MAX_WORLDS];
>
>
> int bag_i=0;
> int bag_max=0;
> int bag_capacity=0;
> Object3D *bag=NULL;
>
> SwitchBag(int from, int to)
> {
>
> bag_i_tab[from] = bag_i ;
> bag_max_tab[from] = bag_max;
> bag_capacity_tab[from] = bag_capacity;
> bag_tab[from] = bag;
>
>
> bag_i = bag_i_tab[to];
> bag_max = bag_max_tab[to];
> bag_capacity = bag_capacity_tab[to] ;
> bag = bag_tab[to];
> }
>
>
>
> inline int countOcupationInBag()
> {
> int counter=0;
> for(int i=0;i<bag_max;i++) if(bag[i].enabled) counter++;
> return counter;
> }
>
>
> inline void ResizeBag(int new_size)
> {
> if(new_size>bag_capacity)
> {
>
> Object3D *new_bag=(Object3D*)realloc(bag,new_size*sizeof(Object3D));
> if(!new_bag && new_size>0) { ERROR_("realloc failed in bag
> resize"); return; }
>
> bag=new_bag;
>
> if(new_size>bag_capacity)
> memset(&bag[bag_capacity],0,(new_size-bag_capacity)*sizeof(Object3D));
>
> bag_capacity=new_size;
> }
>
> bag_max=new_size;
> if(bag_i>=bag_max) bag_i=0;
>
> }
>
> inline int FindEmptySlotInBag()
> {
> if(bag_max==0) ResizeBag(3000);
> if(bag_max==0) { ERROR_("unexpected state in FindEmptySlotInBag");
> return -1; }
>
> if(bag_i>=bag_max) bag_i=0;
>
> for(int i=0;i<bag_max;i++)
> {
> if(!bag[bag_i].enabled) return bag_i;
> bag_i++;
> if(bag_i>=bag_max) bag_i=0;
> }
>
> int old_size=bag_max;
> ResizeBag(bag_max*1.5);
> if(bag_max==old_size) { ERROR_("unexpected state in
> FindEmptySlotInBag"); return -1; }
>
> return FindEmptySlotInBag();
> }
>
>
> void ResetBag()
> {
> for(int i=0;i<bag_max;i++) bag[i].enabled=0;
> bag_i=0;
> }
>
> void VisualizeBag()
> {
>
> for(int i=0; i<bag_max; i++)
> {
> int x = i%200;
> int y = i/200;
>
> if(x>=frame_size_x) continue;
> if(y>=frame_size_y) continue;
>
> int color = 0x00c0c0;
> if(!bag[i].enabled) color = 0x003010;
> else
> {
>
> if(bag[i].type=='smo') color = 0x808080;
> if(bag[i].type=='deb') color = 0xc00000;
> if(bag[i].type=='bull') color = 0xffff00;
>
> }
>
> for(int q=0; q<3; q++)
> for(int p=0; p<3; p++)
> SetPixelUnsafe(10+x*3+p,10+ y*3+q,color);
> }
> }
>
>
> void CompactBag_KeepOrder()
> {
> int dst=0;
>
> for(int src=0;src<bag_max;src++)
> {
> if(!bag[src].enabled) continue;
> if(dst!=src) bag[dst]=bag[src];
> dst++;
> }
>
> for(int i=dst;i<bag_max;i++) bag[i].enabled=0;
>
>
> bag_i=dst;
> bag_max=dst+200;
> ResizeBag(bag_max);
>
>
>
> }
>
> void CompactBag_NoOrder()
> {
> int dst=0;
> int src=bag_max-1;
>
> while(dst<src)
> {
> if(bag[dst].enabled) { dst++; continue; }
> if(!bag[src].enabled) { src--; continue; }
>
> bag[dst]=bag[src];
> bag[src].enabled=0;
>
> dst++;
> src--;
> }
>
> bag_i=dst;
> bag_max=dst+200;
> ResizeBag(bag_max);
> }
>
>
> fir
as to this bag the matter is yet more a bit more complex it seems
in this my own fame time measurign framework (i name it dhud -
diagnostic hud) i displayed 2 plots - physical time (including 7ms
sleep) and time for some frame generation but excluding sleep, blit and
dispatch events loop...now i included dispatch events tima nad blit
(and it showed thsi my plot like more jumps, not so flat as before)
and im not quite sure coz it generally jumps.varies but those
bac compacting maybe makes some dose of more jumps so it would be quite
noticable (now i got no time to spend more time on this observing)
its generally weird as this compacting is in strict frame code
not in events and not in blit..so maybe those are cache efects, if i
compact bag cache is desorganised? (im not sure as im not even quite
sure this additional jittering definitely occur)
but ist possible maybe if so i could yet add another version of
compacting which does only portion of compacting o call not compacting
all which in turn should probably lower potential jittering
void CompactSomeBag_NoOrder(int some)
{
int dst=0;
int src=bag_max-1;
while(dst<src)
{
if(bag[dst].enabled) { dst++; continue; }
if(!bag[src].enabled) { src--; continue; }
bag[dst]=bag[src];
bag[src].enabled=0;
dst++;
src--;
if(dst<src && --some<=0) return;
}
bag_i=dst;
if(dst==src && bag[dst].enabled) bag_i++;
bag_max=bag_i+200;
ResizeBag(bag_max);
}
overally this may need further investigation but im not in a mood for it
right today
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads