Skip to content

Commit

Permalink
Reworked a bit, and added some error trapping
Browse files Browse the repository at this point in the history
  • Loading branch information
cobrajs committed Mar 23, 2012
1 parent 30cedc7 commit 1b31c17
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 39 deletions.
9 changes: 2 additions & 7 deletions framebuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,10 @@ void drawLine(frameBuffer *fb, int x1, int y1, int x2, int y2, int r, int g, int
lineRGBA(fb->screen, x1, fb->height-1-y1, x2, fb->height-1-y2, r, g, b, alpha);
}

void drawPolygon(frameBuffer *fb, Sint16* xv, Sint16* yv, int n, int filled, int r, int g, int b, int alpha) {
void drawPolygon(frameBuffer *fb, Sint16* xv, Sint16* yv, int n, int r, int g, int b, int alpha) {
int i;
for (i=0; i<n; i++) yv[i] = fb->height-1-yv[i];
if (filled) {
filledPolygonRGBA(fb->screen, xv, yv, n, r, g, b, alpha);
}
else {
polygonRGBA(fb->screen, xv, yv, n, r, g, b, alpha);
}
filledPolygonRGBA(fb->screen, xv, yv, n, r, g, b, alpha);
}

/* ============================= Bitmap font =============================== */
Expand Down
2 changes: 1 addition & 1 deletion framebuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void drawEllipse(frameBuffer *fb, int xc, int yc, int radx, int rady, int r, int
void drawBox(frameBuffer *fb, int x1, int y1, int x2, int y2, int r, int g, int b, int alpha);
void drawTriangle(frameBuffer *fb, int x1, int y1, int x2, int y2, int x3, int y3, int r, int g, int b, int alpha);
void drawLine(frameBuffer *fb, int x1, int y1, int x2, int y2, int r, int g, int b, int alpha);
void drawPolygon(frameBuffer *fb, Sint16* xv, Sint16* yv, int n, int filled, int r, int g, int b, int alpha);
void drawPolygon(frameBuffer *fb, Sint16* xv, Sint16* yv, int n, int r, int g, int b, int alpha);

/* Bitmap font */
void bfLoadFont(char **c);
Expand Down
62 changes: 31 additions & 31 deletions load81.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,39 +216,39 @@ int polygonBinding(lua_State *L) {
Sint16* polyBufferX;
Sint16* polyBufferY;

int size=0, i=0;
int good=0;

if (lua_gettop(L) == 2) {
if (lua_istable(L,-1)) {
size = (int)lua_objlen(L,-1);
polyBufferY = (Sint16*)malloc(size * sizeof(Sint16));
lua_pushnil(L);
while(lua_next(L,-2) != 0) {
polyBufferY[i++] = (Sint16)lua_tonumber(L,-1);
lua_pop(L,1);
if (i > size) break;
}
good++;
lua_pop(L,1);
}
if (lua_istable(L,-1)) {
polyBufferX = (Sint16*)malloc(size * sizeof(Sint16));
lua_pushnil(L);
i=0;
while(lua_next(L,-2) != 0) {
polyBufferX[i++] = (Sint16)lua_tonumber(L,-1);
lua_pop(L,1);
if (i > size) break;
}
good++;
}
if (!(lua_gettop(L) == 2 && lua_istable(L,-1) && lua_istable(L,-2))) {
programError("Invalid arguments for polygon");
return 0;
}

int size = (int)lua_objlen(L,-1), i=0;
polyBufferY = (Sint16*)malloc(size * sizeof(Sint16));
lua_pushnil(L);
while(lua_next(L,-2) != 0) {
polyBufferY[i++] = (Sint16)lua_tonumber(L,-1);
lua_pop(L,1);
if (i > size) break;
}

lua_pop(L,1);

if (size != (int)lua_objlen(L,-1)) {
programError("Array size mismatch in call to polygon");
return 0;
}
if (good == 2) {
drawPolygon(l81.fb, polyBufferX, polyBufferY, size, filled, l81.r, l81.g, l81.b, l81.alpha);
free(polyBufferX);
free(polyBufferY);
polyBufferX = (Sint16*)malloc(size * sizeof(Sint16));
lua_pushnil(L);
i=0;
while(lua_next(L,-2) != 0) {
polyBufferX[i++] = (Sint16)lua_tonumber(L,-1);
lua_pop(L,1);
if (i > size) break;
}

drawPolygon(l81.fb, polyBufferX, polyBufferY, size, l81.r, l81.g, l81.b, l81.alpha);

free(polyBufferX);
free(polyBufferY);
return 0;
}

Expand Down

0 comments on commit 1b31c17

Please sign in to comment.