Re: logically weird loop

Liste des GroupesRevenir à cl c  
Sujet : Re: logically weird loop
De : profesor.fir (at) *nospam* gmail.com (fir)
Groupes : comp.lang.c
Date : 24. Nov 2024, 11:20:48
Autres entêtes
Organisation : i2pn2 (i2pn.org)
Message-ID : <62d347f5a0fa65e98ff2610a3e28a6012b83befb@i2pn2.org>
References : 1 2 3 4 5
User-Agent : Mozilla/5.0 (Windows NT 10.0; WOW64; rv:91.0) Gecko/20100101 Firefox/91.0 SeaMonkey/2.53.19
fir pisze:
fir pisze:
Lawrence D'Oliveiro pisze:
On Wed, 20 Nov 2024 17:34:34 +0100, Janis Papanagnou wrote:
>
[*] A friend of mine just recently implemented the code frame for a
roguelike and followed the suggestion of an event based object-oriented
implementation; it worked well, he told me.
>
The next step would be to use coroutines so the logic of a longer-running
task, which has to wait for other events at multiple points, can be
written in a single linear stream without having to be fragmented into
multiple callbacks.
>
i dont know to much on coroutines (what i knew i forgot as even my memory this year is terribly bad) or simule bot from some other
reasoning i know thet "call queue" is veru good thing
>
possibly it may be better or at least equal in thiat coroutines or
what was in simula
>
in basic call queue it gioes klike this afai
>
for(int i=0; i<all; i++)
    add_queue foo(i);
>
foo() are storred in queue so then can be run i pseudo parralel
mode at some point
>
add_queue stores function adress and argument on stack like queue
>
here in rogualike it would use this time variable also
>
  DoAction(int i)
  {
    if(character[i].action_end > current_time) return;
// do nothing until time comes
>
// time has come do something
   character[i],action_end += 300;
  add_queue DoAction(i); //put yourself on queue
>
>
}
>
StartUp()
{
for(int i=0; i<all; i++) add_queue DoAction(i);
>
}
>
// in some code
  run_queue // queue may add soem alelemnts but also executed things are taken out of queue
>
i guess it should be something like that
>
  i once said probably call queues should be a god way to do multithreading becouse say you got a routine that calculates and draw a vertical line of mandelbrot
 for(int i=0; i<1000; i++)
  add_queue1 draw_mandelbrot(i);
 run_queue1;
 as thoise calculations are independant the run_queue may execute queue
(which is table of 1000 pointers and 1000 ints)
pararelly in 1000 threads and its very easy
 when items may be dependant soem could add them to queue but also
store some tag (like group number) when eech group is independant versus other groups so each group could be run separatelly on threads with knowledge there is no conflict
  int group ;
for(int i=0; i<1000; i++)
{
if(bot[i].x<300) group = 1;
else if(bot[i].x>700) group = 2;
else if(bot[i].x>400 && bot[i].x<600) group = 3;
else group = 4;
 add_queue1[group] run_bot(i);
  }
now its an error becouse when gorups 1 2 3 could run in parralel group 4 can not (but someteimes when i post something i see an error but not bother to correct as its seen)
but becouse this is error it shows that eventually something more
could or shoudl be used than raw number of groups to encode a group
dependancy (like 4 can be executed after 1,2,3..but im not sure as for now
this queue hovever as i already said seem to me probably the most
conveniant way to d multithreading in c (some extended c) -
simply you feel queue and compiler or system simply runs it and it knows
the marked things are independant... so you get  easy and cklear on code side and easy and clear on hardware side
 something like that but with better syntax.. it asumes bots act locally on map and if are distant 100 distance they will not interract..than those 4 groups can be run on 4 threads assumning nio collision is possible
  something like that

Date Sujet#  Auteur
20 Nov 24 * logically weird loop32fir
20 Nov 24 +- Re: logically weird loop1fir
20 Nov 24 `* Re: logically weird loop30Janis Papanagnou
20 Nov 24  +* Re: logically weird loop4fir
20 Nov 24  i`* Re: logically weird loop3fir
20 Nov 24  i `* Re: logically weird loop2fir
21 Nov 24  i  `- Re: logically weird loop1fir
21 Nov 24  `* Re: logically weird loop25Lawrence D'Oliveiro
21 Nov 24   +* Re: logically weird loop21Janis Papanagnou
21 Nov 24   i+* Re: logically weird loop6fir
21 Nov 24   ii`* Re: logically weird loop5fir
21 Nov 24   ii `* Re: logically weird loop4Janis Papanagnou
21 Nov 24   ii  `* Re: logically weird loop3fir
21 Nov 24   ii   `* Re: logically weird loop2Janis Papanagnou
22 Nov 24   ii    `- Re: logically weird loop1fir
22 Nov 24   i+* Re: logically weird loop9Lawrence D'Oliveiro
22 Nov 24   ii+- Re: logically weird loop1Janis Papanagnou
22 Nov 24   ii`* Re: logically weird loop7Michael S
22 Nov 24   ii +* Re: logically weird loop2fir
22 Nov 24   ii i`- Re: logically weird loop1fir
5 Dec 24   ii `* Re: logically weird loop4Tim Rentsch
5 Dec 24   ii  `* Re: logically weird loop3Janis Papanagnou
5 Dec 24   ii   `* Re: logically weird loop2David Brown
5 Dec 24   ii    `- Re: logically weird loop1Janis Papanagnou
5 Dec 24   i`* Re: logically weird loop5Tim Rentsch
5 Dec 24   i `* Re: logically weird loop4Janis Papanagnou
7 Dec 24   i  `* Re: logically weird loop3Tim Rentsch
7 Dec 24   i   `* Re: logically weird loop2Keith Thompson
8 Dec 24   i    `- Re: logically weird loop1Kaz Kylheku
22 Nov 24   `* Re: logically weird loop3fir
22 Nov 24    `* Re: logically weird loop2fir
24 Nov 24     `- Re: logically weird loop1fir

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal