Put metadata near the begin of the sol files, therefore loading set is realy faster
[neverball] / share / geom.c
index b42b9a5..d8ee649 100644 (file)
@@ -1,4 +1,4 @@
-/*   
+/*
  * Copyright (C) 2003 Robert Kooima
  *
  * NEVERBALL is  free software; you can redistribute  it and/or modify
@@ -30,7 +30,7 @@
 /*---------------------------------------------------------------------------*/
 
 static GLuint ball_list;
-static GLuint ball_text;
+static GLuint ball_text[2];
 
 void ball_init(int b)
 {
@@ -39,14 +39,16 @@ void ball_init(int b)
     int j, stacks = b ? 16 :  8;
 
     config_get_s(CONFIG_BALL, name, MAXSTR);
+    ball_text[0] = make_image_from_file(NULL, NULL, NULL, NULL, name);
 
-    ball_text = make_image_from_file(NULL, NULL, NULL, NULL, name);
+    config_get_s(CONFIG_BALL_BONUS, name, MAXSTR);
+    ball_text[1] = make_image_from_file(NULL, NULL, NULL, NULL, name);
 
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
 
     ball_list = glGenLists(1);
-    
+
     glNewList(ball_list, GL_COMPILE);
     {
         for (i = 0; i < stacks; i++)
@@ -87,14 +89,18 @@ void ball_free(void)
     if (glIsList(ball_list))
         glDeleteLists(ball_list, 1);
 
-    if (glIsTexture(ball_text))
-        glDeleteTextures(1, &ball_text);
+    if (glIsTexture(ball_text[0]))
+        glDeleteTextures(1, &ball_text[0]);
+
+    if (glIsTexture(ball_text[1]))
+        glDeleteTextures(1, &ball_text[1]);
 
-    ball_list = 0;
-    ball_text = 0;
+    ball_list    = 0;
+    ball_text[0] = 0;
+    ball_text[1] = 0;
 }
 
-void ball_draw(void)
+void ball_draw(int i)
 {
     glPushAttrib(GL_POLYGON_BIT |
                  GL_LIGHTING_BIT |
@@ -110,7 +116,7 @@ void ball_draw(void)
 
         glEnable(GL_COLOR_MATERIAL);
 
-        glBindTexture(GL_TEXTURE_2D, ball_text);
+        glBindTexture(GL_TEXTURE_2D, ball_text[i]);
 
         /* Render the ball back to front in case it is translucent. */
 
@@ -149,7 +155,7 @@ void mark_init(int b)
     int i, slices = b ? 32 : 16;
 
     mark_list = glGenLists(1);
-    
+
     glNewList(mark_list, GL_COMPILE);
     {
         glBegin(GL_TRIANGLE_FAN);
@@ -197,6 +203,8 @@ void mark_free(void)
 /*---------------------------------------------------------------------------*/
 
 static GLuint coin_text;
+static GLuint coin_grup;
+static GLuint coin_grdn;
 static GLuint coin_list;
 
 static void coin_head(int n, float radius, float thick)
@@ -278,16 +286,27 @@ void coin_color(float *c, int n)
         c[1] = 0.2f;
         c[2] = 1.0f;
     }
+    if (n == 50) /*white's kind of boring, but you can do a colored png that way.*/
+    {
+        c[0] = 1.0f;
+        c[1] = 1.0f;
+        c[2] = 1.0f;
+    }
+    if (n == 150)
+    {
+        c[0] = 1.0f;
+        c[1] = 1.0f;
+        c[2] = 1.0f;
+    }
 }
 
 void coin_init(int b)
 {
-    char name[MAXSTR];
     int n = b ? 32 : 8;
 
-    config_get_s(CONFIG_COIN, name, MAXSTR);
-
-    coin_text = make_image_from_file(NULL, NULL, NULL, NULL, name);
+    coin_text = make_image_from_file(NULL, NULL, NULL, NULL, IMG_COIN);
+    coin_grup = make_image_from_file(NULL, NULL, NULL, NULL, IMG_COIN_GRUP);
+    coin_grdn = make_image_from_file(NULL, NULL, NULL, NULL, IMG_COIN_GRDN);
     coin_list = glGenLists(1);
 
     glNewList(coin_list, GL_COMPILE);
@@ -307,8 +326,16 @@ void coin_free(void)
     if (glIsTexture(coin_text))
         glDeleteTextures(1, &coin_text);
 
+    if (glIsTexture(coin_grup))
+        glDeleteTextures(1, &coin_grup);
+
+    if (glIsTexture(coin_grdn))
+        glDeleteTextures(1, &coin_grdn);
+
     coin_list = 0;
     coin_text = 0;
+    coin_grup = 0;
+    coin_grdn = 0;
 }
 
 void coin_push(void)
@@ -324,9 +351,17 @@ void coin_push(void)
     glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR,  s);
     glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION,  e);
     glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, h);
+}
 
+void coin_push_text(int n)
+{
     glEnable(GL_COLOR_MATERIAL);
-    glBindTexture(GL_TEXTURE_2D, coin_text);
+    if (n == 50)
+        glBindTexture(GL_TEXTURE_2D, coin_grdn);
+    else if (n == 150)
+        glBindTexture(GL_TEXTURE_2D, coin_grup);
+    else
+        glBindTexture(GL_TEXTURE_2D, coin_text);
 }
 
 void coin_draw(int n, float r)
@@ -371,7 +406,7 @@ void goal_init(int b)
                 {
                     float x = fcosf(2.f * PI * i / n);
                     float y = fsinf(2.f * PI * i / n);
-            
+
                     glColor4f(1.0f, 1.0f, 0.0f, 0.5f);
                     glVertex3f(x, 0.0f, y);
 
@@ -405,40 +440,41 @@ static GLuint jump_list;
 
 void jump_init(int b)
 {
-    int i, n = b ? 32 : 8;
+    int k, i, n = b ? 32 : 8;
 
-    jump_list = glGenLists(1);
+    jump_list = glGenLists(2);
 
-    glNewList(jump_list, GL_COMPILE);
+    for (k = 0; k < 12; k++)
     {
-        glPushAttrib(GL_TEXTURE_BIT  |
-                     GL_LIGHTING_BIT |
-                     GL_DEPTH_BUFFER_BIT);
+        glNewList(jump_list + k, GL_COMPILE);
         {
-            glEnable(GL_COLOR_MATERIAL);
-            glDisable(GL_LIGHTING);
-            glDisable(GL_TEXTURE_2D);
-            glDepthMask(GL_FALSE);
-
-            glBegin(GL_QUAD_STRIP);
+            glPushAttrib(GL_TEXTURE_BIT | GL_LIGHTING_BIT | GL_DEPTH_BUFFER_BIT);
             {
-                for (i = 0; i <= n; i++)
+                glEnable(GL_COLOR_MATERIAL);
+                glDisable(GL_LIGHTING);
+                glDisable(GL_TEXTURE_2D);
+                glDepthMask(GL_FALSE);
+
+                glBegin(GL_QUAD_STRIP);
                 {
-                    float x = fcosf(2.f * PI * i / n);
-                    float y = fsinf(2.f * PI * i / n);
-            
-                    glColor4f(1.0f, 1.0f, 1.0f, 0.5f);
-                    glVertex3f(x, 0.0f, y);
+                    for (i = 0; i <= n; i++)
+                    {
+                        float x = fcosf(2.f * PI * i / n);
+                        float y = fsinf(2.f * PI * i / n);
 
-                    glColor4f(1.0f, 1.0f, 1.0f, 0.0f);
-                    glVertex3f(x, JUMP_HEIGHT, y);
+                        glColor4f(1.0f, 1.0f, 1.0f, (k == 0 ? 0.5f : 0.8f));
+                        glVertex3f(x, 0.0f, y);
+
+                        glColor4f(1.0f, 1.0f, 1.0f, 0.0f);
+                        glVertex3f(x, JUMP_HEIGHT, y);
+                    }
                 }
+                glEnd();
             }
-            glEnd();
+            glPopAttrib();
         }
-        glPopAttrib();
+        glEndList();
     }
-    glEndList();
 }
 
 void jump_free(void)
@@ -449,86 +485,64 @@ void jump_free(void)
     jump_list = 0;
 }
 
-void jump_draw(void)
+void jump_draw(int highlight)
 {
-    glCallList(jump_list);
+    glCallList(jump_list + highlight);
 }
 
 /*---------------------------------------------------------------------------*/
 
 static GLuint swch_list;
 
+static GLfloat swch_colors[8][4] = {
+    {1.0f, 0.0f, 0.0f, 0.5f}, /* red out */
+    {1.0f, 0.0f, 0.0f, 0.0f},
+    {1.0f, 0.0f, 0.0f, 0.8f}, /* red in */
+    {1.0f, 0.0f, 0.0f, 0.0f},
+    {0.0f, 1.0f, 0.0f, 0.5f}, /* green out */
+    {0.0f, 1.0f, 0.0f, 0.0f},
+    {0.0f, 1.0f, 0.0f, 0.8f}, /* green in */
+    {0.0f, 1.0f, 0.0f, 0.0f}};
+
 void swch_init(int b)
 {
-    int i, n = b ? 32 : 8;
+    int k, i, n = b ? 32 : 8;
 
-    swch_list = glGenLists(2);
+    swch_list = glGenLists(4);
 
-    /* Create the ON display list. */
+    /* Create the display lists. */
 
-    glNewList(swch_list, GL_COMPILE);
+    for (k = 0; k < 4; k++)
     {
-        glPushAttrib(GL_TEXTURE_BIT  |
-                     GL_LIGHTING_BIT |
-                     GL_DEPTH_BUFFER_BIT);
+        glNewList(swch_list + k, GL_COMPILE);
         {
-            glEnable(GL_COLOR_MATERIAL);
-            glDisable(GL_LIGHTING);
-            glDisable(GL_TEXTURE_2D);
-            glDepthMask(GL_FALSE);
-
-            glBegin(GL_QUAD_STRIP);
+            glPushAttrib(GL_TEXTURE_BIT | GL_LIGHTING_BIT | GL_DEPTH_BUFFER_BIT);
             {
-                for (i = 0; i <= n; i++)
-                {
-                    float x = fcosf(2.f * PI * i / n);
-                    float y = fsinf(2.f * PI * i / n);
-            
-                    glColor4f(1.0f, 0.0f, 0.0f, 0.5f);
-                    glVertex3f(x, 0.0f, y);
-
-                    glColor4f(1.0f, 0.0f, 0.0f, 0.0f);
-                    glVertex3f(x, SWCH_HEIGHT, y);
-                }
-            }
-            glEnd();
-        }
-        glPopAttrib();
-    }
-    glEndList();
-
-    /* Create the OFF display list. */
-
-    glNewList(swch_list + 1, GL_COMPILE);
-    {
-        glPushAttrib(GL_TEXTURE_BIT  |
-                     GL_LIGHTING_BIT |
-                     GL_DEPTH_BUFFER_BIT);
-        {
-            glEnable(GL_COLOR_MATERIAL);
-            glDisable(GL_LIGHTING);
-            glDisable(GL_TEXTURE_2D);
-            glDepthMask(GL_FALSE);
+                glEnable(GL_COLOR_MATERIAL);
+                glDisable(GL_LIGHTING);
+                glDisable(GL_TEXTURE_2D);
+                glDepthMask(GL_FALSE);
 
-            glBegin(GL_QUAD_STRIP);
-            {
-                for (i = 0; i <= n; i++)
+                glBegin(GL_QUAD_STRIP);
                 {
-                    float x = fcosf(2.f * PI * i / n);
-                    float y = fsinf(2.f * PI * i / n);
-            
-                    glColor4f(0.0f, 1.0f, 0.0f, 0.5f);
-                    glVertex3f(x, 0.0f, y);
+                    for (i = 0; i <= n; i++)
+                    {
+                        float x = fcosf(2.f * PI * i / n);
+                        float y = fsinf(2.f * PI * i / n);
+
+                        glColor4fv(swch_colors[2 * k]);
+                        glVertex3f(x, 0.0f, y);
 
-                    glColor4f(0.0f, 1.0f, 0.0f, 0.0f);
-                    glVertex3f(x, SWCH_HEIGHT, y);
+                        glColor4fv(swch_colors[2 * k + 1]);
+                        glVertex3f(x, SWCH_HEIGHT, y);
+                    }
                 }
+                glEnd();
             }
-            glEnd();
+            glPopAttrib();
         }
-        glPopAttrib();
+        glEndList();
     }
-    glEndList();
 }
 
 void swch_free(void)
@@ -539,12 +553,9 @@ void swch_free(void)
     swch_list = 0;
 }
 
-void swch_draw(int b)
+void swch_draw(int b, int e)
 {
-    if (b)
-        glCallList(swch_list + 1);
-    else
-        glCallList(swch_list);
+    glCallList(swch_list + b * 2 + e);
 }
 
 /*---------------------------------------------------------------------------*/
@@ -571,7 +582,7 @@ void flag_init(int b)
                 {
                     float x = fcosf(2.f * PI * i / n) * 0.01f;
                     float y = fsinf(2.f * PI * i / n) * 0.01f;
-            
+
                     glColor3f(1.0f, 1.0f, 1.0f);
                     glVertex3f(x, 0.0f,        y);
                     glVertex3f(x, GOAL_HEIGHT, y);
@@ -688,7 +699,7 @@ void fade_draw(float k)
             glDisable(GL_LIGHTING);
             glDisable(GL_DEPTH_TEST);
             glDisable(GL_TEXTURE_2D);
-            
+
             glColor4f(0.0f, 0.0f, 0.0f, k);
 
             glBegin(GL_QUADS);