Move item-related functions into a separate module
authorparasti <parasti@78b8d119-cf0a-0410-b17c-f493084dd1d7>
Tue, 10 Jun 2008 15:17:18 +0000 (15:17 +0000)
committerparasti <parasti@78b8d119-cf0a-0410-b17c-f493084dd1d7>
Tue, 10 Jun 2008 15:17:18 +0000 (15:17 +0000)
git-svn-id: https://s.snth.net/svn/neverball/trunk@2285 78b8d119-cf0a-0410-b17c-f493084dd1d7

Makefile
ball/game.c
ball/st_conf.c
share/geom.c
share/geom.h
share/item.c [new file with mode: 0644]
share/item.h [new file with mode: 0644]

index 24eae4a..218e358 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -150,6 +150,7 @@ BALL_OBJS := \
        share/part.o        \
        share/back.o        \
        share/geom.o        \
+       share/item.o        \
        share/ball.o        \
        share/gui.o         \
        share/base_config.o \
index 94cc2d4..27b6159 100644 (file)
@@ -19,6 +19,7 @@
 #include "game.h"
 #include "vec3.h"
 #include "geom.h"
+#include "item.h"
 #include "back.h"
 #include "part.h"
 #include "ball.h"
index 917e3e7..44eb191 100644 (file)
@@ -16,6 +16,7 @@
 #include "hud.h"
 #include "back.h"
 #include "geom.h"
+#include "item.h"
 #include "ball.h"
 #include "part.h"
 #include "game.h"
index def22ab..eedddbf 100644 (file)
@@ -79,201 +79,6 @@ void mark_free(void)
 
 /*---------------------------------------------------------------------------*/
 
-static void coin_head(int n, float radius, float thick)
-{
-    int i;
-
-    glBegin(GL_TRIANGLE_FAN);
-    {
-        glNormal3f(0.f, 0.f, +1.f);
-
-        for (i = 0; i < n; i++)
-        {
-            float x = fcosf(+2.f * PI * i / n);
-            float y = fsinf(+2.f * PI * i / n);
-
-            glTexCoord2f(+x * 0.5f + 0.5f, +y * 0.5f + 0.5f);
-            glVertex3f(radius * x, radius * y, +thick);
-        }
-    }
-    glEnd();
-}
-
-static void coin_tail(int n, float radius, float thick)
-{
-    int i;
-
-    glBegin(GL_TRIANGLE_FAN);
-    {
-        glNormal3f(0.f, 0.f, -1.f);
-
-        for (i = 0; i < n; i++)
-        {
-            float x = fcosf(-2.f * PI * i / n);
-            float y = fsinf(-2.f * PI * i / n);
-
-            glTexCoord2f(-x * 0.5f + 0.5f, +y * 0.5f + 0.5f);
-            glVertex3f(radius * x, radius * y, -thick);
-        }
-    }
-    glEnd();
-}
-
-static void coin_edge(int n, float radius, float thick)
-{
-    int i;
-
-    glBegin(GL_QUAD_STRIP);
-    {
-        for (i = 0; i <= n; i++)
-        {
-            float x = fcosf(2.f * PI * i / n);
-            float y = fsinf(2.f * PI * i / n);
-
-            glNormal3f(x, y, 0.0f);
-            glVertex3f(radius * x, radius * y, +thick);
-            glVertex3f(radius * x, radius * y, -thick);
-        }
-    }
-    glEnd();
-}
-
-/*---------------------------------------------------------------------------*/
-
-static GLuint item_coin_text;
-static GLuint item_grow_text;
-static GLuint item_shrink_text;
-static GLuint item_list;
-
-void item_color(const struct s_item *hp, float *c)
-{
-    switch (hp->t)
-    {
-
-    case ITEM_COIN:
-
-        if (hp->n >= 1)
-        {
-            c[0] = 1.0f;
-            c[1] = 1.0f;
-            c[2] = 0.2f;
-        }
-        if (hp->n >= 5)
-        {
-            c[0] = 1.0f;
-            c[1] = 0.2f;
-            c[2] = 0.2f;
-        }
-        if (hp->n >= 10)
-        {
-            c[0] = 0.2f;
-            c[1] = 0.2f;
-            c[2] = 1.0f;
-        }
-        break;
-
-    case ITEM_GROW:
-    case ITEM_SHRINK:
-
-    default:
-
-        c[0] = 1.0f;
-        c[1] = 1.0f;
-        c[2] = 1.0f;
-
-        break;
-    }
-}
-
-void item_init(int b)
-{
-    int n = b ? 32 : 8;
-
-    item_coin_text   = make_image_from_file(IMG_ITEM_COIN);
-    item_grow_text   = make_image_from_file(IMG_ITEM_GROW);
-    item_shrink_text = make_image_from_file(IMG_ITEM_SHRINK);
-
-    item_list = glGenLists(1);
-
-    glNewList(item_list, GL_COMPILE);
-    {
-        glDisable(GL_TEXTURE_2D);
-        coin_edge(n, COIN_RADIUS, COIN_THICK);
-        glEnable (GL_TEXTURE_2D);
-        coin_head(n, COIN_RADIUS, COIN_THICK);
-        coin_tail(n, COIN_RADIUS, COIN_THICK);
-    }
-    glEndList();
-}
-
-void item_free(void)
-{
-    if (glIsList(item_list))
-        glDeleteLists(item_list, 1);
-
-    if (glIsTexture(item_coin_text))
-        glDeleteTextures(1, &item_coin_text);
-
-    if (glIsTexture(item_grow_text))
-        glDeleteTextures(1, &item_grow_text);
-
-    if (glIsTexture(item_shrink_text))
-        glDeleteTextures(1, &item_shrink_text);
-
-    item_list = 0;
-    item_coin_text = 0;
-    item_grow_text = 0;
-    item_shrink_text = 0;
-}
-
-void item_push(int type)
-{
-    static const float  a[4] = { 0.2f, 0.2f, 0.2f, 1.0f };
-    static const float  s[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
-    static const float  e[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
-    static const float  h[1] = { 10.0f };
-
-    glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT,   a);
-    glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR,  s);
-    glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION,  e);
-    glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, h);
-
-    glEnable(GL_COLOR_MATERIAL);
-
-    switch (type)
-    {
-    case ITEM_COIN:
-        glBindTexture(GL_TEXTURE_2D, item_coin_text);
-        break;
-
-    case ITEM_GROW:
-        glBindTexture(GL_TEXTURE_2D, item_grow_text);
-        break;
-
-    case ITEM_SHRINK:
-        glBindTexture(GL_TEXTURE_2D, item_shrink_text);
-        break;
-    }
-}
-
-void item_draw(const struct s_item *hp, float r)
-{
-    float c[3];
-
-    item_color(hp, c);
-
-    glColor3fv(c);
-    glCallList(item_list);
-}
-
-void item_pull(void)
-{
-    glColor3f(1.0f, 1.0f, 1.0f);
-    glDisable(GL_COLOR_MATERIAL);
-}
-
-/*---------------------------------------------------------------------------*/
-
 static GLuint goal_list;
 
 void goal_init(int b)
index bc73828..a21b660 100644 (file)
@@ -9,12 +9,6 @@
 
 #define IMG_SHAD "png/shadow.png"
 
-#define IMG_ITEM_COIN   _("png/coin.png")
-#define IMG_ITEM_GROW    "png/grow.png"
-#define IMG_ITEM_SHRINK  "png/shrink.png"
-
-#define COIN_RADIUS   0.15f
-#define COIN_THICK    0.01f
 #define JUMP_HEIGHT   2.00f
 #define SWCH_HEIGHT   2.00f
 #define GOAL_HEIGHT   3.00f
@@ -28,16 +22,6 @@ void mark_draw(void);
 
 /*---------------------------------------------------------------------------*/
 
-void item_color(const struct s_item *, float *);
-void item_init(int);
-void item_free(void);
-
-void item_push(int);
-void item_draw(const struct s_item *, float);
-void item_pull(void);
-
-/*---------------------------------------------------------------------------*/
-
 void goal_init(int);
 void goal_free(void);
 void goal_draw(void);
diff --git a/share/item.c b/share/item.c
new file mode 100644 (file)
index 0000000..914127c
--- /dev/null
@@ -0,0 +1,219 @@
+/*
+ * Copyright (C) 2003 Robert Kooima
+ *
+ * NEVERBALL is  free software; you can redistribute  it and/or modify
+ * it under the  terms of the GNU General  Public License as published
+ * by the Free  Software Foundation; either version 2  of the License,
+ * or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT  ANY  WARRANTY;  without   even  the  implied  warranty  of
+ * MERCHANTABILITY or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU
+ * General Public License for more details.
+ */
+
+#include "item.h"
+#include "glext.h"
+#include "vec3.h"
+#include "solid.h"
+#include "image.h"
+
+#define PI 3.1415926535897932
+
+/*---------------------------------------------------------------------------*/
+
+static void coin_head(int n, float radius, float thick)
+{
+    int i;
+
+    glBegin(GL_TRIANGLE_FAN);
+    {
+        glNormal3f(0.f, 0.f, +1.f);
+
+        for (i = 0; i < n; i++)
+        {
+            float x = fcosf(+2.f * PI * i / n);
+            float y = fsinf(+2.f * PI * i / n);
+
+            glTexCoord2f(+x * 0.5f + 0.5f, +y * 0.5f + 0.5f);
+            glVertex3f(radius * x, radius * y, +thick);
+        }
+    }
+    glEnd();
+}
+
+static void coin_tail(int n, float radius, float thick)
+{
+    int i;
+
+    glBegin(GL_TRIANGLE_FAN);
+    {
+        glNormal3f(0.f, 0.f, -1.f);
+
+        for (i = 0; i < n; i++)
+        {
+            float x = fcosf(-2.f * PI * i / n);
+            float y = fsinf(-2.f * PI * i / n);
+
+            glTexCoord2f(-x * 0.5f + 0.5f, +y * 0.5f + 0.5f);
+            glVertex3f(radius * x, radius * y, -thick);
+        }
+    }
+    glEnd();
+}
+
+static void coin_edge(int n, float radius, float thick)
+{
+    int i;
+
+    glBegin(GL_QUAD_STRIP);
+    {
+        for (i = 0; i <= n; i++)
+        {
+            float x = fcosf(2.f * PI * i / n);
+            float y = fsinf(2.f * PI * i / n);
+
+            glNormal3f(x, y, 0.0f);
+            glVertex3f(radius * x, radius * y, +thick);
+            glVertex3f(radius * x, radius * y, -thick);
+        }
+    }
+    glEnd();
+}
+
+/*---------------------------------------------------------------------------*/
+
+static GLuint item_coin_text;
+static GLuint item_grow_text;
+static GLuint item_shrink_text;
+static GLuint item_list;
+
+void item_color(const struct s_item *hp, float *c)
+{
+    switch (hp->t)
+    {
+
+    case ITEM_COIN:
+
+        if (hp->n >= 1)
+        {
+            c[0] = 1.0f;
+            c[1] = 1.0f;
+            c[2] = 0.2f;
+        }
+        if (hp->n >= 5)
+        {
+            c[0] = 1.0f;
+            c[1] = 0.2f;
+            c[2] = 0.2f;
+        }
+        if (hp->n >= 10)
+        {
+            c[0] = 0.2f;
+            c[1] = 0.2f;
+            c[2] = 1.0f;
+        }
+        break;
+
+    case ITEM_GROW:
+    case ITEM_SHRINK:
+
+    default:
+
+        c[0] = 1.0f;
+        c[1] = 1.0f;
+        c[2] = 1.0f;
+
+        break;
+    }
+}
+
+void item_init(int b)
+{
+    int n = b ? 32 : 8;
+
+    item_coin_text   = make_image_from_file(IMG_ITEM_COIN);
+    item_grow_text   = make_image_from_file(IMG_ITEM_GROW);
+    item_shrink_text = make_image_from_file(IMG_ITEM_SHRINK);
+
+    item_list = glGenLists(1);
+
+    glNewList(item_list, GL_COMPILE);
+    {
+        glDisable(GL_TEXTURE_2D);
+        coin_edge(n, COIN_RADIUS, COIN_THICK);
+        glEnable (GL_TEXTURE_2D);
+        coin_head(n, COIN_RADIUS, COIN_THICK);
+        coin_tail(n, COIN_RADIUS, COIN_THICK);
+    }
+    glEndList();
+}
+
+void item_free(void)
+{
+    if (glIsList(item_list))
+        glDeleteLists(item_list, 1);
+
+    if (glIsTexture(item_coin_text))
+        glDeleteTextures(1, &item_coin_text);
+
+    if (glIsTexture(item_grow_text))
+        glDeleteTextures(1, &item_grow_text);
+
+    if (glIsTexture(item_shrink_text))
+        glDeleteTextures(1, &item_shrink_text);
+
+    item_list = 0;
+    item_coin_text = 0;
+    item_grow_text = 0;
+    item_shrink_text = 0;
+}
+
+void item_push(int type)
+{
+    static const float  a[4] = { 0.2f, 0.2f, 0.2f, 1.0f };
+    static const float  s[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
+    static const float  e[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
+    static const float  h[1] = { 10.0f };
+
+    glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT,   a);
+    glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR,  s);
+    glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION,  e);
+    glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, h);
+
+    glEnable(GL_COLOR_MATERIAL);
+
+    switch (type)
+    {
+    case ITEM_COIN:
+        glBindTexture(GL_TEXTURE_2D, item_coin_text);
+        break;
+
+    case ITEM_GROW:
+        glBindTexture(GL_TEXTURE_2D, item_grow_text);
+        break;
+
+    case ITEM_SHRINK:
+        glBindTexture(GL_TEXTURE_2D, item_shrink_text);
+        break;
+    }
+}
+
+void item_draw(const struct s_item *hp, float r)
+{
+    float c[3];
+
+    item_color(hp, c);
+
+    glColor3fv(c);
+    glCallList(item_list);
+}
+
+void item_pull(void)
+{
+    glColor3f(1.0f, 1.0f, 1.0f);
+    glDisable(GL_COLOR_MATERIAL);
+}
+
+/*---------------------------------------------------------------------------*/
+
diff --git a/share/item.h b/share/item.h
new file mode 100644 (file)
index 0000000..5bd90f0
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2003 Robert Kooima
+ *
+ * NEVERBALL is  free software; you can redistribute  it and/or modify
+ * it under the  terms of the GNU General  Public License as published
+ * by the Free  Software Foundation; either version 2  of the License,
+ * or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT  ANY  WARRANTY;  without   even  the  implied  warranty  of
+ * MERCHANTABILITY or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU
+ * General Public License for more details.
+ */
+
+#ifndef ITEM_H
+#define ITEM_H
+
+#include "lang.h"
+#include "solid.h"
+
+#define IMG_ITEM_COIN   _("png/coin.png")
+#define IMG_ITEM_GROW     "png/grow.png"
+#define IMG_ITEM_SHRINK   "png/shrink.png"
+
+#define COIN_RADIUS   0.15f
+#define COIN_THICK    0.01f
+
+void item_color(const struct s_item *, float *);
+void item_init(int);
+void item_free(void);
+
+void item_push(int);
+void item_draw(const struct s_item *, float);
+void item_pull(void);
+
+#endif