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

View File

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

View File

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