Browse Source

* libee/graphics.c:

+ Correct clipping in ee_putstr() for long strings.
  * libee/ee.c:
    + New ee_get_rendertime() call to provide framerate information.
  * libee/ee.h:
    + Added const keywords where it was meaningful, despite Slang's blatant
      omission of such keywords in its prototypes.


git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/ttyvaders/trunk@180 92316355-f0b4-4df1-b90c-862c8a59935f
master
sam 21 years ago
parent
commit
d2f5ab9e09
5 changed files with 39 additions and 17 deletions
  1. +19
    -6
      libee/ee.c
  2. +8
    -7
      libee/ee.h
  3. +1
    -0
      libee/ee_internals.h
  4. +9
    -2
      libee/graphics.c
  5. +2
    -2
      libee/line.c

+ 19
- 6
libee/ee.c View File

@@ -46,7 +46,7 @@
#include "ee_internals.h" #include "ee_internals.h"


/* Global array with color names */ /* Global array with color names */
char *ee_color_names[16] =
const char *ee_color_names[16] =
{ {
"black", "black",
"blue", "blue",
@@ -66,8 +66,10 @@ char *ee_color_names[16] =
"white", "white",
}; };


static int _ee_delay;
static unsigned int _ee_delay;
static unsigned int _ee_rendertime;
char *_ee_empty_line; char *_ee_empty_line;
char *_ee_scratch_line;


#if defined(USE_NCURSES) #if defined(USE_NCURSES)
int _ee_attr[16]; int _ee_attr[16];
@@ -185,12 +187,15 @@ int ee_init(void)
memset(_ee_empty_line, ' ', ee_get_width()); memset(_ee_empty_line, ' ', ee_get_width());
_ee_empty_line[ee_get_width()] = '\0'; _ee_empty_line[ee_get_width()] = '\0';


_ee_scratch_line = malloc(ee_get_width() + 1);

_ee_delay = 0; _ee_delay = 0;
_ee_rendertime = 0;


return 0; return 0;
} }


int ee_get_width(void)
unsigned int ee_get_width(void)
{ {
#if defined(USE_SLANG) #if defined(USE_SLANG)
return SLtt_Screen_Cols; return SLtt_Screen_Cols;
@@ -201,7 +206,7 @@ int ee_get_width(void)
#endif #endif
} }


int ee_get_height(void)
unsigned int ee_get_height(void)
{ {
#if defined(USE_SLANG) #if defined(USE_SLANG)
return SLtt_Screen_Rows; return SLtt_Screen_Rows;
@@ -212,11 +217,16 @@ int ee_get_height(void)
#endif #endif
} }


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


unsigned int ee_get_rendertime(void)
{
return _ee_rendertime;
}

static unsigned int _ee_getticks(void) static unsigned int _ee_getticks(void)
{ {
static unsigned int last_sec = 0, last_usec = 0; static unsigned int last_sec = 0, last_usec = 0;
@@ -239,7 +249,7 @@ static unsigned int _ee_getticks(void)


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


#if defined(USE_SLANG) #if defined(USE_SLANG)
@@ -258,6 +268,9 @@ void ee_refresh(void)
for(ticks += _ee_getticks(); ticks < _ee_delay; ticks += _ee_getticks()) for(ticks += _ee_getticks(); ticks < _ee_delay; ticks += _ee_getticks())
usleep(10000); usleep(10000);


/* Update the sliding mean of the render time */
_ee_rendertime = (7 * _ee_rendertime + ticks) / 8;

lastticks = ticks - _ee_delay; lastticks = ticks - _ee_delay;


/* If we drifted too much, it's bad, bad, bad. */ /* If we drifted too much, it's bad, bad, bad. */


+ 8
- 7
libee/ee.h View File

@@ -51,7 +51,7 @@ enum ee_colors
EE_WHITE = 15 EE_WHITE = 15
}; };


extern char *ee_color_names[16];
extern const char *ee_color_names[16];


/* /*
* Types * Types
@@ -62,9 +62,10 @@ struct ee_sprite;
* Prototypes * Prototypes
*/ */
int ee_init(void); int ee_init(void);
void ee_set_delay(int);
int ee_get_width(void);
int ee_get_height(void);
void ee_set_delay(unsigned int);
unsigned int ee_get_rendertime(void);
unsigned int ee_get_width(void);
unsigned int ee_get_height(void);
void ee_refresh(void); void ee_refresh(void);
void ee_end(void); void ee_end(void);


@@ -73,13 +74,13 @@ char ee_get_key(void);
void ee_set_color(int); void ee_set_color(int);
int ee_get_color(void); int ee_get_color(void);
void ee_putchar(int, int, char); void ee_putchar(int, int, char);
void ee_putstr(int, int, char *);
void ee_putstr(int, int, const char *);
void ee_clear(void); void ee_clear(void);


void ee_draw_line(int, int, int, int, char); void ee_draw_line(int, int, int, int, char);
void ee_draw_polyline(int[], int[], int, char);
void ee_draw_polyline(const int[], const int[], int, char);
void ee_draw_thin_line(int, int, int, int); void ee_draw_thin_line(int, int, int, int);
void ee_draw_thin_polyline(int[], int[], int);
void ee_draw_thin_polyline(const int[], const int[], int);


void ee_draw_circle(int, int, int, char); void ee_draw_circle(int, int, int, char);
void ee_draw_ellipse(int, int, int, int, char); void ee_draw_ellipse(int, int, int, int, char);


+ 1
- 0
libee/ee_internals.h View File

@@ -32,5 +32,6 @@ extern char *_ee_screen;
#endif #endif


extern char *_ee_empty_line; extern char *_ee_empty_line;
extern char *_ee_scratch_line;


#endif /* __EE_INTERNALS_H__ */ #endif /* __EE_INTERNALS_H__ */

+ 9
- 2
libee/graphics.c View File

@@ -79,11 +79,11 @@ void ee_putchar(int x, int y, char c)
#endif #endif
} }


void ee_putstr(int x, int y, char *s)
void ee_putstr(int x, int y, const char *s)
{ {
int len; int len;


if(y < 0 || y >= ee_get_height())
if(y < 0 || y >= ee_get_height() || x >= ee_get_width())
return; return;


len = strlen(s); len = strlen(s);
@@ -97,6 +97,13 @@ void ee_putstr(int x, int y, char *s)
x = 0; x = 0;
} }


if(x + len >= ee_get_width())
{
memcpy(_ee_scratch_line, s, ee_get_width() - x);
_ee_scratch_line[ee_get_width() - x] = '\0';
s = _ee_scratch_line;
}

#if defined(USE_SLANG) #if defined(USE_SLANG)
SLsmg_gotorc(y, x); SLsmg_gotorc(y, x);
SLsmg_write_string(s); SLsmg_write_string(s);


+ 2
- 2
libee/line.c View File

@@ -68,7 +68,7 @@ void ee_draw_line(int x1, int y1, int x2, int y2, char c)
clip_line(&s); clip_line(&s);
} }


void ee_draw_polyline(int x[], int y[], int n, char c)
void ee_draw_polyline(const int x[], const int y[], int n, char c)
{ {
int i; int i;
struct line s; struct line s;
@@ -105,7 +105,7 @@ void ee_draw_thin_line(int x1, int y1, int x2, int y2)
clip_line(&s); clip_line(&s);
} }


void ee_draw_thin_polyline(int x[], int y[], int n)
void ee_draw_thin_polyline(const int x[], const int y[], int n)
{ {
int i; int i;
struct line s; struct line s;


Loading…
Cancel
Save