[Change] ai/toolkit compilable under C99. I'll get to the rest of it at some point.

This commit is contained in:
Allanis 2013-02-26 16:10:35 +00:00
parent d2e952fb88
commit 301ea07a69
3 changed files with 45 additions and 45 deletions

View File

@ -346,7 +346,7 @@ static void ai_freetask(Task* t) {
if(t->next) ai_freetask(t->next); // Woot, recursive freeing!
if(t->name) free(t->name);
if(t->dtype == TYPE_PTR) free(t->target);
if(t->dtype == TYPE_PTR) free(t->dat.target);
free(t);
}
@ -363,18 +363,18 @@ static int ai_pushtask(lua_State* L) {
Task* t = MALLOC_L(Task);
t->name = (lua_isstring(L, 2)) ? strdup((char*) lua_tostring(L, 2)) : NULL;
t->next = NULL;
t->target = NULL;
t->dat.target = NULL;
if(lua_gettop(L) > 2) {
if(lua_isnumber(L, 3)) {
t->dtype = TYPE_INT;
t->ID = (unsigned int) lua_tonumber(L, 3);
t->dat.ID = (unsigned int) lua_tonumber(L, 3);
}
else if(lua_islightuserdata(L, 3)) {
// Only pointer valid is Vec2* in Lua.
t->dtype = TYPE_PTR;
t->target = MALLOC_L(Vec2);
vectcpy(t->target, (Vec2*)lua_topointer(L,3));
t->dat.target = MALLOC_L(Vec2);
vectcpy(t->dat.target, (Vec2*)lua_topointer(L,3));
} else
t->dtype = TYPE_NULL;
}
@ -414,7 +414,7 @@ static int ai_taskname(lua_State* L) {
// Grab the target pointer.
static int ai_gettarget(lua_State* L) {
if(cur_pilot->task->dtype == TYPE_PTR) {
lua_pushlightuserdata(L, cur_pilot->task->target);
lua_pushlightuserdata(L, cur_pilot->task->dat.target);
return 1;
}
return 0;
@ -423,7 +423,7 @@ static int ai_gettarget(lua_State* L) {
// Get the ID.
static int ai_gettargetid(lua_State* L) {
if(cur_pilot->task->dtype == TYPE_INT) {
lua_pushnumber(L, cur_pilot->task->ID);
lua_pushnumber(L, cur_pilot->task->dat.ID);
return 1;
}
return 0;

View File

@ -20,7 +20,7 @@ typedef struct Task_ {
union {
void* target; // Vec2 etc.
unsigned int ID; // Pilot ID etc.
};
} dat;
} Task;
// Ai profile.

View File

@ -31,25 +31,25 @@ typedef struct Widget_ {
struct {
void(*fptr) (char*); // Callback.
char* display; // Stored text.
};
} btn;
// Widget text.
struct {
char* text; // Use printMid for centered printText if not.
glFont* font;
glColour* colour;
int centered;
};
} txt;
struct {
// Widget image.
glTexture* image;
};
} img;
struct {
// Widget list.
char** options; // Pointer to the options.
int noptions; // total number of options.
int selected; // Currently selected option.
};
};
} lst;
} dat;
} Widget;
typedef struct Window_ {
@ -91,7 +91,7 @@ void window_addButton(const unsigned int wid, const int x, const int y, const in
wgt->type = WIDGET_BUTTON;
wgt->name = strdup(name);
wgt->display = strdup(display);
wgt->dat.btn.display = strdup(display);
// Set the properties.
wgt->w = (double) w;
@ -100,7 +100,7 @@ void window_addButton(const unsigned int wid, const int x, const int y, const in
else wgt->x = (double)x;
if(y < 0) wgt->y = wdw->h - wgt->h + y;
else wgt->y = (double)y;
wgt->fptr = call;
wgt->dat.btn.fptr = call;
}
// Add text to the window.
@ -117,15 +117,15 @@ void window_addText(const unsigned int wid, const int x, const int y,
// Set the properties.
wgt->w = (double) w;
wgt->h = (double) h;
if(font == NULL) wgt->font = &gl_defFont;
else wgt->font = font;
if(font == NULL) wgt->dat.txt.font = &gl_defFont;
else wgt->dat.txt.font = font;
if(x < 0) wgt->x = wdw->w - wgt->w + x;
else wgt->x = (double)x;
if(y < 0) wgt->y = wdw->h + y;
else wgt->y = (double) y;
wgt->colour = colour;
wgt->centered = centered;
wgt->text = strdup(string);
wgt->dat.txt.colour = colour;
wgt->dat.txt.centered = centered;
wgt->dat.txt.text = strdup(string);
}
// Add a graphic to the window.
@ -139,8 +139,8 @@ void window_addImage(const unsigned int wid, const int x, const int y,
wgt->name = strdup(name);
// Set the propertied.
wgt->image = image;
if(x < 0) wgt->x = wdw->w - wgt->image->sw + x;
wgt->dat.img.image = image;
if(x < 0) wgt->x = wdw->w - wgt->dat.img.image->sw + x;
else wgt->x = (double)x;
if(y < 0) wgt->y = wdw->h + y;
else wgt->y = (double)y;
@ -155,9 +155,9 @@ void window_addList(const unsigned int wid, const int x, const int y,
wgt->type = WIDGET_LIST;
wgt->name = strdup(name);
wgt->options = items;
wgt->noptions = nitems;
wgt->selected = defitem; // -1 would be none.
wgt->dat.lst.options = items;
wgt->dat.lst.noptions = nitems;
wgt->dat.lst.selected = defitem; // -1 would be none.
wgt->w = (double) w;
wgt->h = (double) h;
if(x < 0) wgt->x = wdw->w - wgt->w + x;
@ -254,10 +254,10 @@ static void widget_cleanup(Widget* widget) {
switch(widget->type) {
case WIDGET_BUTTON:
if(widget->display) free(widget->display);
if(widget->dat.btn.display) free(widget->dat.btn.display);
break;
case WIDGET_TEXT:
if(widget->text) free(widget->text);
if(widget->dat.txt.text) free(widget->dat.txt.text);
break;
default:
break;
@ -590,20 +590,20 @@ static void toolkit_renderButton(Widget* btn, double bx, double by) {
gl_printMid(NULL, (int)btn->w,
bx + (double)gl_screen.w/2. + btn->x,
by + (double)gl_screen.h/2. + btn->y + (btn->h - gl_defFont.h)/2.,
&cDarkRed, btn->display);
&cDarkRed, btn->dat.btn.display);
}
static void toolkit_renderText(Widget* txt, double bx, double by) {
if(txt->centered)
gl_printMid(txt->font, txt->w,
if(txt->dat.txt.centered)
gl_printMid(txt->dat.txt.font, txt->w,
bx + (double)gl_screen.w/2. + txt->x,
by + (double)gl_screen.h/2. + txt->y,
txt->colour, txt->text);
txt->dat.txt.colour, txt->dat.txt.text);
else
gl_printText(txt->font, txt->w, txt->h,
gl_printText(txt->dat.txt.font, txt->w, txt->h,
bx + (double)gl_screen.w/2. + txt->x,
by + (double)gl_screen.h/2. + txt->y,
txt->colour, txt->text);
txt->dat.txt.colour, txt->dat.txt.text);
}
// Render the image.
@ -618,7 +618,7 @@ static void toolkit_renderImage(Widget* img, double bx, double by) {
oc = &cGrey30;
// Image.
gl_blitStatic(img->image,
gl_blitStatic(img->dat.img.image,
x + (double)gl_screen.w/2.,
y + (double)gl_screen.h/2., NULL);
@ -627,16 +627,16 @@ static void toolkit_renderImage(Widget* img, double bx, double by) {
glBegin(GL_LINE_LOOP);
COLOUR(*lc);
// Top.
glVertex2d(x-1, y+img->image->sh+1.);
glVertex2d(x+img->image->sw, y+img->image->sh+1.);
glVertex2d(x-1, y+img->dat.img.image->sh+1.);
glVertex2d(x+img->dat.img.image->sw, y+img->dat.img.image->sh+1.);
// Right.
COLOUR(*c);
glVertex2d(x+img->image->sw, y);
glVertex2d(x+img->dat.img.image->sw, y);
// Bottom.
glVertex2d(x-1., y);
// Left.
COLOUR(*lc);
glVertex2d(x-1., y+img->image->sh+1.);
glVertex2d(x-1., y+img->dat.img.image->sh+1.);
glEnd();
// Outter outline.
@ -644,14 +644,14 @@ static void toolkit_renderImage(Widget* img, double bx, double by) {
glBegin(GL_LINE_LOOP);
COLOUR(*oc);
// Top.
glVertex2d(x-2., y+img->image->sh+2.);
glVertex2d(x+img->image->sw+1., y+img->image->sh+2.);
glVertex2d(x-2., y+img->dat.img.image->sh+2.);
glVertex2d(x+img->dat.img.image->sw+1., y+img->dat.img.image->sh+2.);
// Right.
glVertex2d(x+img->image->sw+1., y-1.);
glVertex2d(x+img->dat.img.image->sw+1., y-1.);
// Bottom.
glVertex2d(x-2., y-1.);
// Left.
glVertex2d(x-2., y+img->image->sh+2.);
glVertex2d(x-2., y+img->dat.img.image->sh+2.);
glEnd();
}
@ -715,7 +715,7 @@ void toolkit_mouseEvent(SDL_Event* event) {
break;
case SDL_MOUSEBUTTONUP:
if(wgt->status == WIDGET_STATUS_MOUSEDOWN) {
if(wgt->type == WIDGET_BUTTON) (*wgt->fptr)(wgt->name);
if(wgt->type == WIDGET_BUTTON) (*wgt->dat.btn.fptr)(wgt->name);
}
wgt->status = WIDGET_STATUS_NORMAL;
break;