Browse Source

* libee/sprite.c:

+ Added sanity checks in ee_sprite_* functions.
  * libee/conic.c:
    + Use ellipsepoints() in ee_draw_circle().
tags/v0.99.beta14
Sam Hocevar sam 21 years ago
parent
commit
67a16319c6
2 changed files with 27 additions and 18 deletions
  1. +12
    -17
      libee/conic.c
  2. +15
    -1
      libee/sprite.c

+ 12
- 17
libee/conic.c View File

@@ -26,6 +26,8 @@


#include "ee.h" #include "ee.h"


static void ellipsepoints(int, int, int, int, char);

void ee_draw_circle(int x, int y, int r, char c) void ee_draw_circle(int x, int y, int r, char c)
{ {
int test, dx, dy; int test, dx, dy;
@@ -33,28 +35,13 @@ void ee_draw_circle(int x, int y, int r, char c)
/* Optimized Bresenham. Kick ass. */ /* Optimized Bresenham. Kick ass. */
for(test = 0, dx = 0, dy = r ; dx <= dy ; dx++) for(test = 0, dx = 0, dy = r ; dx <= dy ; dx++)
{ {
ee_putcharTO(x + dx, y + dy / 2, c);
ee_putcharTO(x - dx, y + dy / 2, c);
ee_putcharTO(x + dx, y - dy / 2, c);
ee_putcharTO(x - dx, y - dy / 2, c);

ee_putcharTO(x + dy, y + dx / 2, c);
ee_putcharTO(x - dy, y + dx / 2, c);
ee_putcharTO(x + dy, y - dx / 2, c);
ee_putcharTO(x - dy, y - dx / 2, c);
ellipsepoints(x, y, dx, dy, c);
ellipsepoints(x, y, dy, dx, c);


test += test > 0 ? dx - dy-- : dx; test += test > 0 ? dx - dy-- : dx;
} }
} }


static void ellipsepoints(int xo, int yo, int x, int y, char c)
{
ee_putcharTO(xo + x, yo + y, c);
ee_putcharTO(xo - x, yo + y, c);
ee_putcharTO(xo + x, yo - y, c);
ee_putcharTO(xo - x, yo - y, c);
}

void ee_draw_ellipse(int xo, int yo, int a, int b, char c) void ee_draw_ellipse(int xo, int yo, int a, int b, char c)
{ {
int d2; int d2;
@@ -97,3 +84,11 @@ void ee_draw_ellipse(int xo, int yo, int a, int b, char c)
} }
} }


static void ellipsepoints(int xo, int yo, int x, int y, char c)
{
ee_putcharTO(xo + x, yo + y, c);
ee_putcharTO(xo - x, yo + y, c);
ee_putcharTO(xo + x, yo - y, c);
ee_putcharTO(xo - x, yo - y, c);
}


+ 15
- 1
libee/sprite.c View File

@@ -130,6 +130,9 @@ struct ee_sprite *ee_load_sprite(const char *file)


void ee_set_sprite_frame(struct ee_sprite *sprite, int f) void ee_set_sprite_frame(struct ee_sprite *sprite, int f)
{ {
if(sprite == NULL)
return;

if(f < 0 || f >= sprite->nf) if(f < 0 || f >= sprite->nf)
return; return;


@@ -138,13 +141,21 @@ void ee_set_sprite_frame(struct ee_sprite *sprite, int f)


int ee_get_sprite_frame(struct ee_sprite *sprite) int ee_get_sprite_frame(struct ee_sprite *sprite)
{ {
if(sprite == NULL)
return -1;

return sprite->f; return sprite->f;
} }


void ee_draw_sprite(int x, int y, struct ee_sprite *sprite) void ee_draw_sprite(int x, int y, struct ee_sprite *sprite)
{ {
int i, j; int i, j;
struct ee_frame *frame = &sprite->frames[sprite->f];
struct ee_frame *frame;

if(sprite == NULL)
return;

frame = &sprite->frames[sprite->f];


for(j = 0; j < frame->h; j++) for(j = 0; j < frame->h; j++)
{ {
@@ -165,6 +176,9 @@ void ee_free_sprite(struct ee_sprite *sprite)
{ {
int i; int i;


if(sprite == NULL)
return;

for(i = sprite->nf; i--;) for(i = sprite->nf; i--;)
{ {
struct ee_frame *frame = &sprite->frames[i]; struct ee_frame *frame = &sprite->frames[i];


Loading…
Cancel
Save