[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Beta Version - Please help
Am Die, 17 Aug 1999 hast Du wahrscheinlich geschrieben:
>On Tue, 17 Aug 1999, Philipp GXhring wrote:
>>
>> The first thing I need is delay(long n).
>> delay should wait for n milliseconds. (thousands of a second)
>as i see it, there are two ways to do this.
>the first is to use the gettimeofday function, and set a variable, say
>oldtime, to it. then just loop, or sleep until the gettimeofday function
>returns the first oldtime+delaytime...but personally (and i'm not sure
>how true this is) i've found that the gettimeofday function is really slow.
You know, I already did it. And it ports to Linux nicely. There was
just some obstacle I don´ t remember, which lead mit to uncomment
#ifndef __linux
Clock = CLOCKS_PER_SEC;
#endif
So just remove those #ifndef and #endif from the wurst.cpp, and
you have Würstelstand Beta #2, and as far as I know all of those
timing problems are solved.
Additionally the line
int Clock;
has to be changed to
clock_t Clock;
I used the Clock value in an integer to be a bit faster, because the
CLOCKS_PER_SEC was a macro in Watcom, and it isn´t a good idea to
recalculate the Clocks_per_Second everytime you need it. :)
And I accidentally removed the Clock=CLOCKS_PER_SEC, which made
Clock=0, and then I waited 0.1*Clock, which should be a thenth of a
second. .... *g*
>theres also the select function which i read somewhere (though don't ask
>me where) is a good way to do a delay type situation...
>but wait, theres more...
>way back in my dos programming days, there was a technique suggested to
>me where at the beginning of your program, you make a function that is as
>follows:
>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.
>a modified home-brew delay as described above might work.
I already solved the problem in DOS. I used Watcom, and the main
advantage of Watcom is that it came from the Unix world. :)
And many guys used it to port their Unix programs to Dos. :)
Watcom implemented all the nice things like buffered I/O, good Time
and Timezone functions, ...
>> While playing the above way, it should be possible to skip the video
>> or a sequence of videos by pressing a key on the keyboard. I realized
>> this under DOS with kbhit(), which i couldn´t find in Linux.
>> (kbhit is a non-blocking getch)
>um, excuse my ignorence, but i don't rightly know if you're doing this
>under x or console. if you're doing it under x, then the main idle loop
>can look for keyboard hits at any time. if you're doing it under
>console, i believe there is a way to make io non-blocking via fcntl,
>using the F_SETFL operation and setting the O_NONBLOCK bit, or using
>ioctl with the FIONBIO operation (?????)
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.
>> And the last thing is the Background music. I just forked and updated
>> mikmod in the background, but it is still playing, when I stop the
>> program with CTRL+C.
>you just have to let your different forked processes talk to each other
>either via a pipe, shared memory, or the like, and then if one gets an
>exit signal then it will the tell the other accordingly.
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?
I know a lot of theorie behind the IPC stuff, I learned in school.
But I am not used to it.
Is this pthread thing useful for this?
(I found no documentation about pthread yet, just the manpages)
>well, rather a long winded response, but i hope you can glean some
>usefull information...tell me if any of this actually works...
Yes, thanks for you help!
--
~ Philipp Gühring p.guehring@poboxes.com
~ http://www.poboxes.com/p.guehring ICQ UIN: 6588261