Bladeren bron

* libee/ee.c:

+ First file in libee, from src/graphics.c.
    + Disable cursor upon initialisation.
    + Added delay code for constant framerate.
  * src/common.h:
    + Minor compilation fix for latest ncurses.


git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/ttyvaders/trunk@76 92316355-f0b4-4df1-b90c-862c8a59935f
master
sam 21 jaren geleden
bovenliggende
commit
ca2c8bac14
6 gewijzigde bestanden met toevoegingen van 79 en 25 verwijderingen
  1. +10
    -0
      doc/shapes.txt
  2. +57
    -12
      libee/ee.c
  3. +1
    -1
      src/Makefile.am
  4. +3
    -3
      src/ceo.c
  5. +5
    -4
      src/common.h
  6. +3
    -5
      src/main.c

+ 10
- 0
doc/shapes.txt Bestand weergeven

@@ -140,6 +140,16 @@ Explosions



#######
### ###
## ##
# #
# #
# #
## ##
### ###
#######

#######
### ###
## ##


src/graphics.c → libee/ee.c Bestand weergeven

@@ -3,7 +3,7 @@
* Copyright (c) 2002 Sam Hocevar <sam@zoy.org>
* All Rights Reserved
*
* $Id: graphics.c,v 1.6 2002/12/23 16:21:38 sam Exp $
* $Id$
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -24,6 +24,8 @@

#include <stdlib.h>
#include <unistd.h>
#include <sys/time.h>
#include <time.h>

#include "common.h"

@@ -51,6 +53,7 @@ int init_graphics( void )
SLsig_unblock_signals();

SLsmg_cls();
SLtt_set_cursor_visibility( 0 );
SLsmg_refresh();
#elif USE_NCURSES
/* Initialize ncurses library */
@@ -60,6 +63,7 @@ int init_graphics( void )
cbreak();
noecho();
nodelay(stdscr, TRUE);
curs_set( 0 );
#else
/* Dummy driver */
#endif
@@ -135,31 +139,61 @@ char get_key( void )
return 0;
}

void gfx_delay( void )
void clear_graphics( game *g )
{
#ifdef USE_SLANG
usleep(40000);
//SLsmg_cls();
int y;
for( y = 0; y < g->h; y++ )
{
gfx_goto( 0, y );
gfx_putstr( " " );
}
#elif USE_NCURSES
usleep(40000);
//clear();
int y;
for( y = 0; y < g->h; y++ )
{
gfx_goto( 0, y );
gfx_putstr( " " );
}
#else
/* Use dummy driver */
#endif
}

void clear_graphics( void )
static int64_t local_time(void)
{
#ifdef USE_SLANG
SLsmg_cls();
#elif USE_NCURSES
clear();
#else
/* Use dummy driver */
#endif
struct timeval tv;
int64_t now;

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

#define DELAY 40000

void refresh_graphics( void )
{
static int64_t local_clock = 0;
int64_t now;

gfx_goto( 0, 0 );

if( !local_clock )
{
/* Initialize local_clock */
local_clock = local_time();
}

if( local_time() > local_clock + 10000 )
{
/* If we are late, we shouldn't display anything */
}

#ifdef USE_SLANG
SLsmg_refresh();
#elif USE_NCURSES
@@ -167,14 +201,25 @@ void refresh_graphics( void )
#else
/* Use dummy driver */
#endif

now = local_time();

if( now < local_clock + DELAY - 10000 )
{
usleep( local_clock + DELAY - 10000 - now );
}

local_clock += DELAY;
}

void end_graphics( void )
{
#ifdef USE_SLANG
SLtt_set_cursor_visibility( 1 );
SLang_reset_tty();
SLsmg_reset_smg();
#elif USE_NCURSES
curs_set( 1 );
endwin();
#else
/* Use dummy driver */

+ 1
- 1
src/Makefile.am Bestand weergeven

@@ -26,7 +26,7 @@ ttyvaders_SOURCES = \
collide.c \
common.h \
explosions.c \
graphics.c \
../libee/ee.c \
main.c \
math.c \
overlay.c \


+ 3
- 3
src/ceo.c Bestand weergeven

@@ -3,7 +3,7 @@
* Copyright (c) 2002 Sam Hocevar <sam@zoy.org>
* All Rights Reserved
*
* $Id: ceo.c,v 1.5 2002/12/23 10:06:27 sam Exp $
* $Id$
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -27,13 +27,13 @@

#include "common.h"

void ceo_alert( void )
void ceo_alert( game *g )
{
int end = 0;

while( !end )
{
clear_graphics();
clear_graphics( g );

if( get_key() == '\t' )
{


+ 5
- 4
src/common.h Bestand weergeven

@@ -3,7 +3,7 @@
* Copyright (c) 2002 Sam Hocevar <sam@zoy.org>
* All Rights Reserved
*
* $Id: common.h,v 1.16 2003/02/09 11:17:40 sam Exp $
* $Id$
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -49,7 +49,9 @@
# define gfx_putchar(x) SLsmg_write_char(x)
# define gfx_putstr(x) SLsmg_write_string(x)
#elif USE_NCURSES
#define box box_other
# include <curses.h>
#undef box
# define gfx_color(x) attrset(COLOR_PAIR(x))
# define gfx_goto(x,y) move(y,x)
# define gfx_putchar(x) addch(x)
@@ -199,7 +201,7 @@ void free_box( box *b );
/*
* From ceo.c
*/
void ceo_alert( void );
void ceo_alert( game *g );

/*
* From collide.c
@@ -222,8 +224,7 @@ void update_explosions( game *g, explosions *ex );
int init_graphics( void );
void init_game( game *g );
char get_key( void );
void gfx_delay( void );
void clear_graphics( void );
void clear_graphics( game *g );
void refresh_graphics( void );
void end_graphics( void );



+ 3
- 5
src/main.c Bestand weergeven

@@ -3,7 +3,7 @@
* Copyright (c) 2002 Sam Hocevar <sam@zoy.org>
* All Rights Reserved
*
* $Id: main.c,v 1.17 2003/02/09 11:17:40 sam Exp $
* $Id$
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -103,7 +103,7 @@ static void start_game (game *g)
}
break;
case '\t':
ceo_alert();
ceo_alert( g );
poz = 1;
break;
case 's':
@@ -176,8 +176,6 @@ static void start_game (game *g)
}
}

gfx_delay();

if( !poz || skip )
{
skip = 0;
@@ -216,7 +214,7 @@ static void start_game (game *g)
}

/* Clear screen */
clear_graphics();
clear_graphics( g );

/* Print starfield, tunnel, aliens, player and explosions */
draw_starfield( g, g->sf );


Laden…
Annuleren
Opslaan