[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Beta Version - Please help

"Philipp Gühring" wrote:

> >gettime();
> >while (i<UPPER_BOUND) && (keepgoing==true) {
> >  t=gettime()
> >  for (j=0; j<i; j++);
> >  if (gettime()-t==timeyouwanttodelay) keepgoing=false;
> >}
> I think that is it what the kernel guys did, which lead to the
> Bogo Mips.

But for a user program, just use usleep for the equivalent thing. It
takes microseconds as parameter, that should be more than enough
precision, yes?

> I am using neither X nor console, I am using ggi. And as far as I
> remember, there is a gii function which tells me whether there are
> things ...
> But I just don´t want to understand, why there is no glibc function
> or whatever, which is usable everywhere, in X, in console, ...
> which tells me whether there is a charakter waiting in the buffer.
> I don´t want to have to use gii or ncurses (which has a kbhit too, i
> think) only to use that simple thing.

poll is in glibc. If you use GGI, it would be nicer to use GII also,
since your input could be weird if you run the program in X!

In any case, ncurses is not the thing to use!

> I just hacked together the following code:
>   void Play_Musik(U1 Number)
>   {
>     sprintf(Filename,"%s%1d.mod",Music_Directory,Number);
>     if(module) Stop();
>     module=Player_Load(Filename,64,0);
>     if(module) Player_Start(module);
>     if((pid=fork())==0)
>     {
>       while(Player_Active())
>       {
>         usleep(10000);
>         MikMod_Update();
>       }
>       exit(0);
>     }
>   };
>   void Stop()
>   {
>     if(module)
>     {
>       Player_Stop();
>       Player_Free(module);
>       module=NULL;
>     }
>     if(pid) kill(pid,9);
>   };
> Do you have any ideas how to improve it?

Change the kill(pid, 9) in a kill(pid, SIGINT). Nicer on the

> I know a lot of theorie behind the IPC stuff, I learned in school.
> But I am not used to it.

It is often forgotten that POSIX signals *are* IPC! They just carry very
little content (the signal number!), that's all...

> Is this pthread thing useful for this?
> (I found no documentation about pthread yet, just the manpages)

Stay away from pthread. I thoroughly agree with John Carmack on this:
"One thread per CPU". Since the main program counts as a thread, don't
start any other (unless you have a multi processor machine and want your
game to use it, that's another story and is very advanced stuff anyway
that you won't get right if you don't know how to check if a key has
been pressed!). :-)

Pierre Phaneuf
Ludus Design, http://ludusdesign.com/
"First they ignore you. Then they laugh at you.
Then they fight you. Then you win." -- Gandhi