+ 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
| @@ -140,6 +140,16 @@ Explosions | |||||
| ####### | |||||
| ### ### | |||||
| ## ## | |||||
| # # | |||||
| # # | |||||
| # # | |||||
| ## ## | |||||
| ### ### | |||||
| ####### | |||||
| ####### | ####### | ||||
| ### ### | ### ### | ||||
| ## ## | ## ## | ||||
| @@ -3,7 +3,7 @@ | |||||
| * Copyright (c) 2002 Sam Hocevar <sam@zoy.org> | * Copyright (c) 2002 Sam Hocevar <sam@zoy.org> | ||||
| * All Rights Reserved | * 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 | * 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 | * it under the terms of the GNU General Public License as published by | ||||
| @@ -24,6 +24,8 @@ | |||||
| #include <stdlib.h> | #include <stdlib.h> | ||||
| #include <unistd.h> | #include <unistd.h> | ||||
| #include <sys/time.h> | |||||
| #include <time.h> | |||||
| #include "common.h" | #include "common.h" | ||||
| @@ -51,6 +53,7 @@ int init_graphics( void ) | |||||
| SLsig_unblock_signals(); | SLsig_unblock_signals(); | ||||
| SLsmg_cls(); | SLsmg_cls(); | ||||
| SLtt_set_cursor_visibility( 0 ); | |||||
| SLsmg_refresh(); | SLsmg_refresh(); | ||||
| #elif USE_NCURSES | #elif USE_NCURSES | ||||
| /* Initialize ncurses library */ | /* Initialize ncurses library */ | ||||
| @@ -60,6 +63,7 @@ int init_graphics( void ) | |||||
| cbreak(); | cbreak(); | ||||
| noecho(); | noecho(); | ||||
| nodelay(stdscr, TRUE); | nodelay(stdscr, TRUE); | ||||
| curs_set( 0 ); | |||||
| #else | #else | ||||
| /* Dummy driver */ | /* Dummy driver */ | ||||
| #endif | #endif | ||||
| @@ -135,31 +139,61 @@ char get_key( void ) | |||||
| return 0; | return 0; | ||||
| } | } | ||||
| void gfx_delay( void ) | |||||
| void clear_graphics( game *g ) | |||||
| { | { | ||||
| #ifdef USE_SLANG | #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 | #elif USE_NCURSES | ||||
| usleep(40000); | |||||
| //clear(); | |||||
| int y; | |||||
| for( y = 0; y < g->h; y++ ) | |||||
| { | |||||
| gfx_goto( 0, y ); | |||||
| gfx_putstr( " " ); | |||||
| } | |||||
| #else | #else | ||||
| /* Use dummy driver */ | /* Use dummy driver */ | ||||
| #endif | #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 ) | void refresh_graphics( void ) | ||||
| { | { | ||||
| static int64_t local_clock = 0; | |||||
| int64_t now; | |||||
| gfx_goto( 0, 0 ); | 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 | #ifdef USE_SLANG | ||||
| SLsmg_refresh(); | SLsmg_refresh(); | ||||
| #elif USE_NCURSES | #elif USE_NCURSES | ||||
| @@ -167,14 +201,25 @@ void refresh_graphics( void ) | |||||
| #else | #else | ||||
| /* Use dummy driver */ | /* Use dummy driver */ | ||||
| #endif | #endif | ||||
| now = local_time(); | |||||
| if( now < local_clock + DELAY - 10000 ) | |||||
| { | |||||
| usleep( local_clock + DELAY - 10000 - now ); | |||||
| } | |||||
| local_clock += DELAY; | |||||
| } | } | ||||
| void end_graphics( void ) | void end_graphics( void ) | ||||
| { | { | ||||
| #ifdef USE_SLANG | #ifdef USE_SLANG | ||||
| SLtt_set_cursor_visibility( 1 ); | |||||
| SLang_reset_tty(); | SLang_reset_tty(); | ||||
| SLsmg_reset_smg(); | SLsmg_reset_smg(); | ||||
| #elif USE_NCURSES | #elif USE_NCURSES | ||||
| curs_set( 1 ); | |||||
| endwin(); | endwin(); | ||||
| #else | #else | ||||
| /* Use dummy driver */ | /* Use dummy driver */ | ||||
| @@ -26,7 +26,7 @@ ttyvaders_SOURCES = \ | |||||
| collide.c \ | collide.c \ | ||||
| common.h \ | common.h \ | ||||
| explosions.c \ | explosions.c \ | ||||
| graphics.c \ | |||||
| ../libee/ee.c \ | |||||
| main.c \ | main.c \ | ||||
| math.c \ | math.c \ | ||||
| overlay.c \ | overlay.c \ | ||||
| @@ -3,7 +3,7 @@ | |||||
| * Copyright (c) 2002 Sam Hocevar <sam@zoy.org> | * Copyright (c) 2002 Sam Hocevar <sam@zoy.org> | ||||
| * All Rights Reserved | * 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 | * 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 | * it under the terms of the GNU General Public License as published by | ||||
| @@ -27,13 +27,13 @@ | |||||
| #include "common.h" | #include "common.h" | ||||
| void ceo_alert( void ) | |||||
| void ceo_alert( game *g ) | |||||
| { | { | ||||
| int end = 0; | int end = 0; | ||||
| while( !end ) | while( !end ) | ||||
| { | { | ||||
| clear_graphics(); | |||||
| clear_graphics( g ); | |||||
| if( get_key() == '\t' ) | if( get_key() == '\t' ) | ||||
| { | { | ||||
| @@ -3,7 +3,7 @@ | |||||
| * Copyright (c) 2002 Sam Hocevar <sam@zoy.org> | * Copyright (c) 2002 Sam Hocevar <sam@zoy.org> | ||||
| * All Rights Reserved | * 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 | * 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 | * 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_putchar(x) SLsmg_write_char(x) | ||||
| # define gfx_putstr(x) SLsmg_write_string(x) | # define gfx_putstr(x) SLsmg_write_string(x) | ||||
| #elif USE_NCURSES | #elif USE_NCURSES | ||||
| #define box box_other | |||||
| # include <curses.h> | # include <curses.h> | ||||
| #undef box | |||||
| # define gfx_color(x) attrset(COLOR_PAIR(x)) | # define gfx_color(x) attrset(COLOR_PAIR(x)) | ||||
| # define gfx_goto(x,y) move(y,x) | # define gfx_goto(x,y) move(y,x) | ||||
| # define gfx_putchar(x) addch(x) | # define gfx_putchar(x) addch(x) | ||||
| @@ -199,7 +201,7 @@ void free_box( box *b ); | |||||
| /* | /* | ||||
| * From ceo.c | * From ceo.c | ||||
| */ | */ | ||||
| void ceo_alert( void ); | |||||
| void ceo_alert( game *g ); | |||||
| /* | /* | ||||
| * From collide.c | * From collide.c | ||||
| @@ -222,8 +224,7 @@ void update_explosions( game *g, explosions *ex ); | |||||
| int init_graphics( void ); | int init_graphics( void ); | ||||
| void init_game( game *g ); | void init_game( game *g ); | ||||
| char get_key( void ); | char get_key( void ); | ||||
| void gfx_delay( void ); | |||||
| void clear_graphics( void ); | |||||
| void clear_graphics( game *g ); | |||||
| void refresh_graphics( void ); | void refresh_graphics( void ); | ||||
| void end_graphics( void ); | void end_graphics( void ); | ||||
| @@ -3,7 +3,7 @@ | |||||
| * Copyright (c) 2002 Sam Hocevar <sam@zoy.org> | * Copyright (c) 2002 Sam Hocevar <sam@zoy.org> | ||||
| * All Rights Reserved | * 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 | * 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 | * it under the terms of the GNU General Public License as published by | ||||
| @@ -103,7 +103,7 @@ static void start_game (game *g) | |||||
| } | } | ||||
| break; | break; | ||||
| case '\t': | case '\t': | ||||
| ceo_alert(); | |||||
| ceo_alert( g ); | |||||
| poz = 1; | poz = 1; | ||||
| break; | break; | ||||
| case 's': | case 's': | ||||
| @@ -176,8 +176,6 @@ static void start_game (game *g) | |||||
| } | } | ||||
| } | } | ||||
| gfx_delay(); | |||||
| if( !poz || skip ) | if( !poz || skip ) | ||||
| { | { | ||||
| skip = 0; | skip = 0; | ||||
| @@ -216,7 +214,7 @@ static void start_game (game *g) | |||||
| } | } | ||||
| /* Clear screen */ | /* Clear screen */ | ||||
| clear_graphics(); | |||||
| clear_graphics( g ); | |||||
| /* Print starfield, tunnel, aliens, player and explosions */ | /* Print starfield, tunnel, aliens, player and explosions */ | ||||
| draw_starfield( g, g->sf ); | draw_starfield( g, g->sf ); | ||||