diff --git a/libee/ee.c b/libee/ee.c index 7b69f20..a9185a4 100644 --- a/libee/ee.c +++ b/libee/ee.c @@ -46,7 +46,7 @@ #include "ee_internals.h" /* Global array with color names */ -char *ee_color_names[16] = +const char *ee_color_names[16] = { "black", "blue", @@ -66,8 +66,10 @@ char *ee_color_names[16] = "white", }; -static int _ee_delay; +static unsigned int _ee_delay; +static unsigned int _ee_rendertime; char *_ee_empty_line; +char *_ee_scratch_line; #if defined(USE_NCURSES) int _ee_attr[16]; @@ -185,12 +187,15 @@ int ee_init(void) memset(_ee_empty_line, ' ', ee_get_width()); _ee_empty_line[ee_get_width()] = '\0'; + _ee_scratch_line = malloc(ee_get_width() + 1); + _ee_delay = 0; + _ee_rendertime = 0; return 0; } -int ee_get_width(void) +unsigned int ee_get_width(void) { #if defined(USE_SLANG) return SLtt_Screen_Cols; @@ -201,7 +206,7 @@ int ee_get_width(void) #endif } -int ee_get_height(void) +unsigned int ee_get_height(void) { #if defined(USE_SLANG) return SLtt_Screen_Rows; @@ -212,11 +217,16 @@ int ee_get_height(void) #endif } -void ee_set_delay(int usec) +void ee_set_delay(unsigned int usec) { _ee_delay = usec; } +unsigned int ee_get_rendertime(void) +{ + return _ee_rendertime; +} + static unsigned int _ee_getticks(void) { static unsigned int last_sec = 0, last_usec = 0; @@ -239,7 +249,7 @@ static unsigned int _ee_getticks(void) void ee_refresh(void) { - static int lastticks = 0; + static unsigned int lastticks = 0; unsigned int ticks = lastticks + _ee_getticks(); #if defined(USE_SLANG) @@ -258,6 +268,9 @@ void ee_refresh(void) for(ticks += _ee_getticks(); ticks < _ee_delay; ticks += _ee_getticks()) usleep(10000); + /* Update the sliding mean of the render time */ + _ee_rendertime = (7 * _ee_rendertime + ticks) / 8; + lastticks = ticks - _ee_delay; /* If we drifted too much, it's bad, bad, bad. */ diff --git a/libee/ee.h b/libee/ee.h index 4da5944..5481568 100644 --- a/libee/ee.h +++ b/libee/ee.h @@ -51,7 +51,7 @@ enum ee_colors EE_WHITE = 15 }; -extern char *ee_color_names[16]; +extern const char *ee_color_names[16]; /* * Types @@ -62,9 +62,10 @@ struct ee_sprite; * Prototypes */ 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_end(void); @@ -73,13 +74,13 @@ char ee_get_key(void); void ee_set_color(int); int ee_get_color(void); 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_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_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_ellipse(int, int, int, int, char); diff --git a/libee/ee_internals.h b/libee/ee_internals.h index 7bb8b7e..6148fa2 100644 --- a/libee/ee_internals.h +++ b/libee/ee_internals.h @@ -32,5 +32,6 @@ extern char *_ee_screen; #endif extern char *_ee_empty_line; +extern char *_ee_scratch_line; #endif /* __EE_INTERNALS_H__ */ diff --git a/libee/graphics.c b/libee/graphics.c index b930bc5..ef0399e 100644 --- a/libee/graphics.c +++ b/libee/graphics.c @@ -79,11 +79,11 @@ void ee_putchar(int x, int y, char c) #endif } -void ee_putstr(int x, int y, char *s) +void ee_putstr(int x, int y, const char *s) { int len; - if(y < 0 || y >= ee_get_height()) + if(y < 0 || y >= ee_get_height() || x >= ee_get_width()) return; len = strlen(s); @@ -97,6 +97,13 @@ void ee_putstr(int x, int y, char *s) 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) SLsmg_gotorc(y, x); SLsmg_write_string(s); diff --git a/libee/line.c b/libee/line.c index 4f4ee60..598bfb7 100644 --- a/libee/line.c +++ b/libee/line.c @@ -68,7 +68,7 @@ void ee_draw_line(int x1, int y1, int x2, int y2, char c) 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; struct line s; @@ -105,7 +105,7 @@ void ee_draw_thin_line(int x1, int y1, int x2, int y2) 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; struct line s;