Article View: comp.lang.c
Article #2055Re: fir's bag visualisation
From: 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
Technical Details
Message-ID:
<11emgi9$1m92f$1@dont-email.me>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mailReferences:
<11ecdnp$1qvjl$1@dont-email.me> <11ecerh$1reea$1@dont-email.me> <11ecl7q$1u08b$1@dont-email.me> <11ecng8$1uu5l$1@dont-email.me>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: fir <profesor.fir@gmail.com> Newsgroups: comp.lang.c Subject: Re: fir's bag visualisation Date: Tue, 1 Dec 2026 14:03:02 +0100 Organization: A noiseless patient Spider Lines: 230 Message-ID: <11emgi9$1m92f$1@dont-email.me> References: <11ecdnp$1qvjl$1@dont-email.me> <11ecerh$1reea$1@dont-email.me> <11ecl7q$1u08b$1@dont-email.me> <11ecng8$1uu5l$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Tue, 01 Dec 2026 13:03:06 +0000 (UTC) Injection-Info: dont-email.me; logging-data="1778767"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/mk+bnnLLEOKSj81dBSwvfCnXu52+7nyQ="; posting-host="7a19f3f1b9c4b11a1d98366ec728cc9c" User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:140.0) Gecko/20100101 Firefox/140.0 SeaMonkey/2.53.24 Cancel-Lock: sha1:yBhcxe7cnAeVCNcSXqHD/28AO8o= sha256:VTTO4kHhspIzllUZR6rckqcR6d+rp/0vQ6ZK5v/b6C0= sha1:+1Y3qD0eaNPkZ5pw+PKemx6FrvM= sha256:GopNoE3jirisj48HhPNjlrXCFGWKl60Yb4/Mqc+p0QU= In-Reply-To: <11ecng8$1uu5l$1@dont-email.me>