Procházet zdrojové kódy

* libee/ee.c:

+ Implemented correct framerate wait loop.
    + No framedropping yet.
  * test/demo.c src/main.c:
    + Set an arbitrary framerate for demos.


git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/ttyvaders/trunk@178 92316355-f0b4-4df1-b90c-862c8a59935f
master
sam před 21 roky
rodič
revize
eb7b841f6c
3 změnil soubory, kde provedl 32 přidání a 38 odebrání
  1. +28
    -38
      libee/ee.c
  2. +2
    -0
      src/main.c
  3. +2
    -0
      test/demo.c

+ 28
- 38
libee/ee.c Zobrazit soubor

@@ -190,11 +190,6 @@ int ee_init(void)
return 0;
}

void ee_set_delay(int usec)
{
_ee_delay = usec;
}

int ee_get_width(void)
{
#if defined(USE_SLANG)
@@ -217,37 +212,35 @@ int ee_get_height(void)
#endif
}

#if !defined(USE_CONIO)
static int64_t local_time(void)
void ee_set_delay(int usec)
{
struct timeval tv;
int64_t now;

gettimeofday(&tv, NULL);
now = tv.tv_sec;
now *= 1000000;
now += tv.tv_usec;
return now;
_ee_delay = usec;
}
#endif

void ee_refresh(void)
static unsigned int _ee_getticks(void)
{
#if !defined(USE_CONIO)
static int64_t local_clock = 0;
int64_t now;
static unsigned int last_sec = 0, last_usec = 0;

if(!local_clock)
{
/* Initialize local_clock */
local_clock = local_time();
}
struct timeval tv;
unsigned int ticks = 0;

gettimeofday(&tv, NULL);

if(local_time() > local_clock + 10000)
if(last_sec != 0)
{
/* If we are late, we shouldn't display anything */
ticks = (tv.tv_sec - last_sec) * 1000000 + (tv.tv_usec - last_usec);
}
#endif

last_sec = tv.tv_sec;
last_usec = tv.tv_usec;

return ticks;
}

void ee_refresh(void)
{
static int lastticks = 0;
unsigned int ticks = lastticks + _ee_getticks();

#if defined(USE_SLANG)
SLsmg_refresh();
@@ -261,18 +254,15 @@ void ee_refresh(void)
# endif
#endif

#if !defined(USE_CONIO)
now = local_time();
/* Wait until _ee_delay + time of last call */
for(ticks += _ee_getticks(); ticks < _ee_delay; ticks += _ee_getticks())
usleep(10000);

if(now < local_clock + _ee_delay - 10000)
{
usleep(local_clock + _ee_delay - 10000 - now);
}
lastticks = ticks - _ee_delay;

local_clock += _ee_delay;
#else
delay(5);
#endif
/* If we drifted too much, it's bad, bad, bad. */
if(lastticks > _ee_delay)
lastticks = 0;
}

void ee_end(void)


+ 2
- 0
src/main.c Zobrazit soubor

@@ -46,6 +46,8 @@ int main (int argc, char **argv)
return 1;
}

ee_set_delay(100000);

/* Initialize our program */
g->w = ee_get_width();
g->h = ee_get_height();


+ 2
- 0
test/demo.c Zobrazit soubor

@@ -55,6 +55,8 @@ int main(int argc, char **argv)
return 1;
}

ee_set_delay(40000);

/* Initialize data */
sprite = ee_load_sprite("data/barboss.txt");



Načítá se…
Zrušit
Uložit