diff --git a/doc/shapes.txt b/doc/shapes.txt index 9f703fe..50632b6 100644 --- a/doc/shapes.txt +++ b/doc/shapes.txt @@ -140,6 +140,16 @@ Explosions + ####### + ### ### + ## ## + # # + # # + # # + ## ## + ### ### + ####### + ####### ### ### ## ## diff --git a/src/graphics.c b/libee/ee.c similarity index 73% rename from src/graphics.c rename to libee/ee.c index 8ea1aa2..1fbdf53 100644 --- a/src/graphics.c +++ b/libee/ee.c @@ -3,7 +3,7 @@ * Copyright (c) 2002 Sam Hocevar * 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 #include +#include +#include #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 */ diff --git a/src/Makefile.am b/src/Makefile.am index 9a565b9..c1da2a0 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -26,7 +26,7 @@ ttyvaders_SOURCES = \ collide.c \ common.h \ explosions.c \ - graphics.c \ + ../libee/ee.c \ main.c \ math.c \ overlay.c \ diff --git a/src/ceo.c b/src/ceo.c index cf882ce..295d6be 100644 --- a/src/ceo.c +++ b/src/ceo.c @@ -3,7 +3,7 @@ * Copyright (c) 2002 Sam Hocevar * 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' ) { diff --git a/src/common.h b/src/common.h index 5550322..09c89ef 100644 --- a/src/common.h +++ b/src/common.h @@ -3,7 +3,7 @@ * Copyright (c) 2002 Sam Hocevar * 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 +#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 ); diff --git a/src/main.c b/src/main.c index e9398a9..444c6da 100644 --- a/src/main.c +++ b/src/main.c @@ -3,7 +3,7 @@ * Copyright (c) 2002 Sam Hocevar * 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 );