Просмотр исходного кода

* libee/ee.c:

+ Error checking in ee_init().
    + Pre-generate the empty line for ee_clear().
  * libee/sprite.c:
    + Better error checking in ee_sprite_load().


git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/ttyvaders/trunk@168 92316355-f0b4-4df1-b90c-862c8a59935f
master
sam 21 лет назад
Родитель
Сommit
3022049352
4 измененных файлов: 58 добавлений и 29 удалений
  1. +9
    -2
      libee/ee.c
  2. +2
    -0
      libee/ee_internals.h
  3. +1
    -10
      libee/graphics.c
  4. +46
    -17
      libee/sprite.c

+ 9
- 2
libee/ee.c Просмотреть файл

@@ -67,6 +67,7 @@ char *ee_color_names[16] =
};

static int _ee_delay;
char *_ee_empty_line;

#if defined(USE_NCURSES)
int _ee_attr[16];
@@ -166,11 +167,13 @@ int ee_init(void)
}

#elif defined(USE_CONIO)
gettextinfo(&ti);
_ee_screen = malloc(2 * ti.screenwidth * ti.screenheight);
if(_ee_screen == NULL)
return -1;
_wscroll = 0;
_setcursortype(_NOCURSOR);
clrscr();
gettextinfo(&ti);
_ee_screen = malloc(2 * ti.screenwidth * ti.screenheight);
# if defined(SCREENUPDATE_IN_PC_H)
ScreenRetrieve(_ee_screen);
# else
@@ -178,6 +181,10 @@ int ee_init(void)
# endif

#endif
_ee_empty_line = malloc(ee_get_width() + 1);
memset(_ee_empty_line, ' ', ee_get_width());
_ee_empty_line[ee_get_width()] = '\0';

_ee_delay = 0;

return 0;


+ 2
- 0
libee/ee_internals.h Просмотреть файл

@@ -31,4 +31,6 @@ extern int _ee_attr[];
extern char *_ee_screen;
#endif

extern char *_ee_empty_line;

#endif /* __EE_INTERNALS_H__ */

+ 1
- 10
libee/graphics.c Просмотреть файл

@@ -118,18 +118,9 @@ void ee_putstr(int x, int y, char *s)
void ee_clear(void)
{
/* We could use SLsmg_cls() etc., but drawing empty lines is much faster */
int x = ee_get_width();
int y = ee_get_height();
char *empty_line = malloc((x + 1) * sizeof(char));

memset(empty_line, ' ', x);
empty_line[x] = '\0';

while(y--)
{
ee_putstr(0, y, empty_line);
}

free(empty_line);
ee_putstr(0, y, _ee_empty_line);
}


+ 46
- 17
libee/sprite.c Просмотреть файл

@@ -54,6 +54,9 @@ struct ee_sprite *ee_load_sprite(const char *file)
return NULL;

sprite = malloc(sizeof(struct ee_sprite));
if(sprite == NULL)
goto sprite_alloc_failed;

sprite->nf = 0;
sprite->frames = NULL;

@@ -71,11 +74,23 @@ struct ee_sprite *ee_load_sprite(const char *file)
if(w <= 0 || h <= 0 || w > BUFSIZ / 2)
break;

if(sprite->nf++)
sprite->frames = realloc(sprite->frames,
sprite->nf * sizeof(struct ee_frame));
if(sprite->nf)
{
void *tmp = realloc(sprite->frames,
(sprite->nf + 1) * sizeof(struct ee_frame));
if(tmp == NULL)
goto frame_failed;
sprite->frames = tmp;
sprite->nf++;
}
else
sprite->frames = malloc(sprite->nf * sizeof(struct ee_frame));
{
sprite->frames = malloc((sprite->nf + 1) * sizeof(struct ee_frame));
if(sprite->frames == NULL)
goto sprite_failed;
sprite->nf++;
}

frame = &sprite->frames[sprite->nf - 1];

frame->w = w;
@@ -83,12 +98,23 @@ struct ee_sprite *ee_load_sprite(const char *file)
frame->dx = dx;
frame->dy = dy;
frame->chars = malloc(w * h * sizeof(char));
if(frame->chars == NULL)
{
sprite->nf--;
goto frame_failed;
}
frame->color = malloc(w * h * sizeof(int));
if(frame->color == NULL)
{
free(frame->chars);
sprite->nf--;
goto frame_failed;
}

for(y = 0; y < h; y++)
{
if(!fgets(buf, BUFSIZ, fd))
goto failed;
goto frame_failed;

for(x = 0; x < w && buf[x] && buf[x] != '\r' && buf[x] != '\n'; x++)
frame->chars[w * y + x] = buf[x];
@@ -100,7 +126,7 @@ struct ee_sprite *ee_load_sprite(const char *file)
for(y = 0; y < h; y++)
{
if(!fgets(buf, BUFSIZ, fd))
goto failed;
goto frame_failed;

for(x = 0; x < w && buf[x] && buf[x] != '\r' && buf[x] != '\n'; x++)
frame->color[w * y + x] = buf[x] - 'a';
@@ -110,23 +136,26 @@ struct ee_sprite *ee_load_sprite(const char *file)
}

continue;

failed:
free(sprite->frames[sprite->nf - 1].chars);
free(sprite->frames[sprite->nf - 1].color);
sprite->nf--;
break;
}

if(sprite->nf == 0)
goto sprite_failed;

fclose(fd);
return sprite;

if(sprite->nf == 0)
frame_failed:
while(sprite->nf)
{
free(sprite);
return NULL;
free(sprite->frames[sprite->nf - 1].color);
free(sprite->frames[sprite->nf - 1].chars);
sprite->nf--;
}

return sprite;
sprite_failed:
free(sprite);
sprite_alloc_failed:
fclose(fd);
return NULL;
}

int ee_get_sprite_frames(struct ee_sprite *sprite)


Загрузка…
Отмена
Сохранить