+ 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.tags/v0.99.beta14
@@ -140,6 +140,16 @@ Explosions | |||
####### | |||
### ### | |||
## ## | |||
# # | |||
# # | |||
# # | |||
## ## | |||
### ### | |||
####### | |||
####### | |||
### ### | |||
## ## | |||
@@ -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 */ |
@@ -26,7 +26,7 @@ ttyvaders_SOURCES = \ | |||
collide.c \ | |||
common.h \ | |||
explosions.c \ | |||
graphics.c \ | |||
../libee/ee.c \ | |||
main.c \ | |||
math.c \ | |||
overlay.c \ | |||
@@ -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' ) | |||
{ | |||
@@ -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,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 ); | |||