#include "Console.h" #include #include #include void InitConsole(VConsole * c, VPlayer * p, int * f) { c->p = p; c->f = f; c->Paused = 0; c->MessageStack = NULL; c->TextFade = 0.0; InitModel(&c->CockpitModel); BuildCockpitModel(&c->CockpitModel); } void CleanUpConsole(VConsole * c) { VConsoleMessage * next; CleanUpModel(&c->CockpitModel); while (c->MessageStack != NULL) { next = c->MessageStack->next; DisposePtr((Ptr) c->MessageStack); c->MessageStack = next; } } void DrawConsole(VConsole * c, float interval) { char string[16]; glEnable(GL_LINE_SMOOTH); glDisable(GL_DEPTH_TEST); glPushMatrix(); glLoadIdentity(); DrawModel(&c->CockpitModel); glColor4f(1.0, 1.0, 1.0, 1.0); glPushMatrix(); glTranslatef(-0.5, -0.8, -1.6); glScalef(2.0, 2.0, 2.0); sprintf(string, "ROCKETS: %d", c->p->NumRockets); DrawCStringWithVectorFont(string); glPopMatrix(); glPushMatrix(); glTranslatef(-0.5, -1.0, -1.6); glScalef(2.0, 2.0, 2.0); sprintf(string, "SHIELDS: %d", c->p->Shields); DrawCStringWithVectorFont(string); glPopMatrix(); glPushMatrix(); glTranslatef(0.0, -1.0, -1.6); glScalef(2.0, 2.0, 2.0); if(*c->f == -1) sprintf(string, "FPS: "); else sprintf(string, "FPS: %d", *c->f); DrawCStringWithVectorFont(string); glPopMatrix(); if (c->Paused) { glPushMatrix(); glTranslatef(0.0, -0.8, -1.6); glScalef(2.0, 2.0, 2.0); DrawCStringWithVectorFont("Paused"); glPopMatrix(); } if (c->MessageStack != NULL) { GLfloat alpha; c->TextFade += (1.0 / interval); if (c->TextFade > (CONSOLETEXTFADEIN + CONSOLETEXTDURATION + CONSOLETEXTFADEOUT)) { VConsoleMessage * next; next = c->MessageStack->next; DisposePtr((Ptr) c->MessageStack); c->MessageStack = next; c->TextFade = 0.0; } else { if (c->TextFade < CONSOLETEXTFADEIN) alpha = (c->TextFade / CONSOLETEXTFADEIN); else if (c->TextFade < (CONSOLETEXTFADEIN + CONSOLETEXTDURATION)) alpha = 1.0; else alpha = (1.0 - ((c->TextFade - (CONSOLETEXTFADEIN + CONSOLETEXTDURATION)) / CONSOLETEXTFADEOUT)); glPushMatrix(); glTranslatef(((0.013 * strlen(c->MessageStack->Message)) / -0.2), -0.5, -1.6); glScalef(10.0, 10.0, 10.0); glLineWidth(3); glColor4f(0.0, 0.0, 0.0, alpha); glPushMatrix(); DrawCStringWithVectorFont(c->MessageStack->Message); glPopMatrix(); glLineWidth(1); glColor4f(0.3, 1.0, 0.3, alpha); DrawCStringWithVectorFont(c->MessageStack->Message); glPopMatrix(); } } glPopMatrix(); glEnable(GL_DEPTH_TEST); glDisable(GL_LINE_SMOOTH); } void PushConsoleMessage(VConsole * c, char * msg) { VConsoleMessage ** message; int wChar; message = &c->MessageStack; while (*message != NULL) { message = &(**message).next; } *message = (VConsoleMessage *) NewPtr(sizeof(VConsoleMessage)); for (wChar = 0; wChar < 255 && msg[wChar] != '\x00'; wChar++) { (**message).Message[wChar] = toupper(msg[wChar]); } (**message).Message[wChar] = '\x00'; (**message).next = NULL; }