changeset 32:8abcc221bbac

sgoex separation
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sat, 21 May 2011 15:15:26 +0900
parents 3b7e57614d93
children 9a5300cedb14
files Dandy.cc Dandy.h Makefile SgoexCerium.cc SgoexCerium.h
diffstat 5 files changed, 371 insertions(+), 340 deletions(-) [+]
line wrap: on
line diff
--- a/Dandy.cc	Tue Feb 08 23:39:47 2011 +0900
+++ b/Dandy.cc	Sat May 21 15:15:26 2011 +0900
@@ -1,4 +1,5 @@
 #include "Dandy.h"
+#include "SgoexCerium.h"
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -74,7 +75,7 @@
   -length  Number of data (default DATA_NUM (Func.h))\n\
   -count   Number of task (default 1)\n";
 
-static Viewer *sgroot;
+Viewer *droot;
 
 static    int screen_w;
 static    int screen_h;
@@ -84,8 +85,8 @@
 {
     screen_w = w;
     screen_h = h;
-    sgroot = sgroot_;
-    return sgroot;
+    droot = sgroot_;
+    return droot;
 }
 
 Application *
@@ -188,12 +189,12 @@
      * timeprof があるんだけどね
      */
 
-    sgroot->createFromXMLfile("xml/character.xml");
-    sgroot->createFromXMLfile("xml/font.xml");
-    sgroot->createFromXMLfile("xml/effect.xml");
-    sgroot->createFromXMLfile("xml/boss.xml");
+    droot->createFromXMLfile("xml/character.xml");
+    droot->createFromXMLfile("xml/font.xml");
+    droot->createFromXMLfile("xml/effect.xml");
+    droot->createFromXMLfile("xml/boss.xml");
 
-    LightSysSwitch(sgroot);
+    LightSysSwitch(droot);
 
 
     init_sprite(0,0,0,0);
@@ -242,33 +243,6 @@
     return 1;
 }
 
-SceneGraphPtr root;
-
-// extern void get_matrix(float *matrix, float *rxyz, float *txyz, float *scale, float *stack);
-
-static void
-flip()
-{
-    CameraPtr camera = sgroot->sgroot->getCamera();
-
-    sgroot->sgroot->flip();
-    sgroot->sgroot->lightCalc();
-
-    root = sgroot->createSceneGraph();
-    //root->xyz[0] = screen_w/2;
-    //root->xyz[1] = screen_h/2;;
-    root->xyz[0] = 0;
-    root->xyz[1] = 0;
-    root->xyz[2] = 30.0f;
-
-    /*親の回転、座標から、子の回転、座標を算出*/
-    get_matrix(root->matrix, root->angle, root->xyz, camera->matrix);
-    /*法線用の行列。Cameraの行列を抜いている(Cameraのコンストラクタで、単位行列にしている)*/
-    get_matrix(root->real_matrix, root->angle, root->xyz, camera->real_matrix);
-
-    sgroot->setSceneData(root);
-}
-
 
 static int
 dandy_main_loop(int gamef)
@@ -527,308 +501,5 @@
 }
 
 
-SpriteTable sptable[DEFOBJ];
-
-
-void
-DefSpriteEx(int number, short middlex, short middley)
-{
-    sptable[number].mx = middlex;
-    sptable[number].my = middley;
-}
-
-
-void
-DefSprite(int number, const char *name, float w, float h, int color, OBJECT *obj)
-{
-    SpriteTable *m = &sptable[number];
-    m->w = w;
-    m->h = h;
-    m->color = (color & 32);
-    m->mx = w / 2;
-    m->my = h / 2;
-    m->tex_w = power_of_two(m->w);
-    m->tex_h = power_of_two(m->h);
-    m->texture = (int *)name;
-
-}
-
-static float my_scale = 5;
-
-void
-PutSprite(int zorder, short x, short y, int number)
-{
-    SpriteTable *m = &sptable[number];
-    char *name = (char *) m->texture;
-if (!name) {
-    printf("PutSprite %d unknown\n",number);
-    return;
-}
-    SceneGraphPtr object = sgroot->createSceneGraph(name);
-    //object->c_xyz[0] = m->mx;
-    //object->c_xyz[1] = m->my;
-    root->addChild(object);
-
-    object->xyz[0] = x - object->c_xyz[0]*my_scale;
-    object->xyz[1] = y - object->c_xyz[1]*my_scale;
-    object->xyz[2] = zorder * 0.01;
-
-    /*親の回転、座標から、子の回転、座標を算出*/
-    get_matrix(object->matrix, object->angle, object->xyz, root->matrix);
-
-    float scale[] = {my_scale,my_scale,1};
-    float c_xyz[] = {0,0,0};
-    scale_matrix(object->matrix, scale, c_xyz);
-    /*法線用の行列。Cameraの行列を抜いている(Cameraのコンストラクタで、単位行列にしている)*/
-    get_matrix(object->real_matrix, object->angle, object->xyz, root->real_matrix);
-}
-
-void
-PutSpriteEx(int number, int x, int y, float scalex, float scaley, float angle)
-{
- if (1) {
-    PutSprite(1, x, y, number);
-    return;
- }
-
-    SpriteTable *m = &sptable[number];
-    char *name = (char *) m->texture;
-if (!name) {
-    printf("PutSpriteEx %d unknown\n",number);
-    return;
-}
-    SceneGraphPtr object = sgroot->createSceneGraph(name);
-    root->addChild(object);
-
-    float scale[] = {my_scale*scalex*4,my_scale*scaley*4,1};
-
-    /*親の回転、座標から、子の回転、座標を算出*/
-    object->xyz[0] = x - object->c_xyz[0] * my_scale - m->w*my_scale;
-    object->xyz[1] = y - object->c_xyz[1] * my_scale - m->h*my_scale;
-    object->xyz[2] = number * 0.01;
-    //object->c_xyz[0] = m->mx;
-    //object->c_xyz[1] = m->my;
-    object->angle[3] = angle * (3.1415926*2/4096);
-    get_matrix(object->matrix, object->angle, object->xyz, root->matrix);
-    float c_xyz[] = {0,0,0};
-    scale_matrix(object->matrix, scale, c_xyz);
-    /*法線用の行列。Cameraの行列を抜いている(Cameraのコンストラクタで、単位行列にしている)*/
-    get_matrix(object->real_matrix, object->angle, object->xyz, root->real_matrix);
-}
-
-
-struct SGO_PAD pad[2];
-
-
-/* コントローラ状態の読み込み */
-void Pad(SDL_Joystick *joy)
-{
-    Sint16 axis;
-
-    SDL_JoystickUpdate();
-  
-    if(SDL_JoystickGetButton(joy,PS2_CROSS)==SDL_PRESSED)
-	pad[0].k0++;
-    else
-	pad[0].k0=0;
-  
-    if(SDL_JoystickGetButton(joy,PS2_CIRCLE)==SDL_PRESSED)
-	pad[0].k1++;
-    else
-	pad[0].k1=0;
-  
-    if(SDL_JoystickGetButton(joy,PS2_SQUARE)==SDL_PRESSED)
-	pad[0].k3++;
-    else
-	pad[0].k3=0;
-  
-    if(SDL_JoystickGetButton(joy,PS2_TRIANGLE)==SDL_PRESSED)
-	pad[0].k4++;
-    else
-	pad[0].k4=0;
-  
-    if(SDL_JoystickGetButton(joy,PS2_L1)==SDL_PRESSED)
-	pad[0].l1++;
-    else
-	pad[0].l1=0;
-  
-    if(SDL_JoystickGetButton(joy,PS2_R1)==SDL_PRESSED)
-	pad[0].r1++;
-    else
-	pad[0].r1=0;
-  
-    if(SDL_JoystickGetButton(joy,PS2_L2)==SDL_PRESSED)
-	pad[0].l2++;
-    else
-	pad[0].l2=0;
-  
-    if(SDL_JoystickGetButton(joy,PS2_R2)==SDL_PRESSED)
-	pad[0].r2++;
-    else
-	pad[0].r2=0;
-  
-    if(SDL_JoystickGetButton(joy,PS2_START)==SDL_PRESSED)
-	pad[0].st++;
-    else
-	pad[0].st=0;
-  
-    if(SDL_JoystickGetButton(joy,PS2_SELECT)==SDL_PRESSED)
-	pad[0].se++;
-    else
-	pad[0].se=0;
-  
-    if(SDL_JoystickGetButton(joy,PS2_L3)==SDL_PRESSED)
-	pad[0].l3++;
-    else
-	pad[0].l3=0;
-  
-    if(SDL_JoystickGetButton(joy,PS2_R3)==SDL_PRESSED)
-	pad[0].r3++;
-    else
-	pad[0].r3=0;
-    //x
-    axis=SDL_JoystickGetAxis(joy,0);
-    if(axis>=3200){
-	pad[0].left=0;
-	pad[0].right++;
-    }
-    else if(axis<=-3200){
-	pad[0].right=0;
-	pad[0].left++;
-    }
-    else {
-	pad[0].right=0;
-	pad[0].left=0;
-    }
-    //y
-    axis=SDL_JoystickGetAxis(joy,1);
-    if(axis>=3200){
-	pad[0].up=0;
-	pad[0].down++;
-    }
-    else if(axis<=-3200){
-	pad[0].down=0;
-	pad[0].up++;
-    }
-    else {
-	pad[0].down=0;
-	pad[0].up=0;
-    }
-
-    if ((pad[0].l1 != 0) && (pad[0].r1 != 0) &&
-	(pad[0].l2 != 0) && (pad[0].r2 != 0) &&
-	(pad[0].st != 0) && (pad[0].se != 0)) {
-	pad[0].quit = 1;
-    } else {
-	pad[0].quit = 0;
-    }
-	
-}
-
-
-void keybord()
-{
-    SDL_PumpEvents();
-    Uint8 *keys = SDL_GetKeyState(NULL);
-
-    if (keys[SDLK_UP]) {
-	pad[0].up++;
-    } else {
-	pad[0].up = 0;
-    }
-    if (keys[SDLK_DOWN]) {
-	pad[0].down++;
-    } else {
-	pad[0].down = 0;
-    }
-
-    if (keys[SDLK_RIGHT]) {
-	pad[0].right++;
-    } else {
-	pad[0].right = 0;
-    }
-
-    if (keys[SDLK_LEFT]) {
-	pad[0].left++;
-    } else {
-	pad[0].left = 0;
-    }
-
-    if (keys[SDLK_a]) {
-	pad[0].k0++;
-    } else {
-	pad[0].k0 = 0;
-    }
-
-    if (keys[SDLK_z]) {
-	pad[0].k1++;
-    } else {
-	pad[0].k1 = 0;
-    }
-
-    if (keys[SDLK_s]) {
-	pad[0].k3++;
-    } else {
-	pad[0].k3 = 0;
-    }
-    
-    if (keys[SDLK_x]) {
-	pad[0].k4++;
-    } else {
-	pad[0].k4 = 0;
-    }
-
-    if (keys[SDLK_r]) {
-	pad[0].r2++;
-    } else {
-	pad[0].r2 = 0;
-    }
-
-    if (keys[SDLK_e]) {
-	pad[0].r1++;
-    } else {
-	pad[0].r1 = 0;
-    }
-
-    if (keys[SDLK_w]) {
-	pad[0].l1++;
-    } else {
-	pad[0].l1 = 0;
-    }
-
-    if (keys[SDLK_q]) {
-	pad[0].l2++;
-    } else {
-	pad[0].l2 = 0;
-    }
-
-    // START ボタンは Return が似合う気がする
-    //if(keys[SDLK_1])
-    if (keys[SDLK_RETURN]) {
-	pad[0].st++;
-    } else {
-	pad[0].st = 0;
-    }
-
-    if (keys[SDLK_2]) {
-	pad[0].se++;
-    } else {
-	pad[0].se = 0;
-    }
-
-    if (keys[SDLK_ESCAPE]) {
-	SDL_Quit();
-	exit(1);
-	//pad[0].st = 1;
-	//pad[0].se = 1;
-    }
-
-    if (keys[SDLK_0]) {
-	pad[0].quit = 1;
-    } else {
-	pad[0].quit = 0;
-    }
-}
-
 
 /* end */
--- a/Dandy.h	Tue Feb 08 23:39:47 2011 +0900
+++ b/Dandy.h	Sat May 21 15:15:26 2011 +0900
@@ -13,6 +13,8 @@
     MainLoopPtr init(Viewer *viewer, int w, int h);
 };
 
+extern Viewer *droot;
+
 typedef void (*move)(SceneGraphPtr node, void *sgroot_, int w, int h);
 typedef void (*coll)(SceneGraphPtr node, void *sgroot_, int w, int h, SceneGraphPtr tree);
 
--- a/Makefile	Tue Feb 08 23:39:47 2011 +0900
+++ b/Makefile	Sat May 21 15:15:26 2011 +0900
@@ -19,8 +19,8 @@
 demo: $(OBJS) sgoex.o main.o
 	$(CC) $(ABI) -o $@ main.o sgoex.o $(OBJS) $(LIBS)
 
-dandy: $(OBJS) Dandy.o
-	$(CC) $(ABI) -o $@ $(OBJS) Dandy.o $(LIBS)
+dandy: $(OBJS) Dandy.o SgoexCerium.o
+	$(CC) $(ABI) -o $@ $(OBJS) Dandy.o SgoexCerium.o $(LIBS)
 
 clean:
 	rm -f $(TARGET) $(OBJS) main.o sgoex.o
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SgoexCerium.cc	Sat May 21 15:15:26 2011 +0900
@@ -0,0 +1,335 @@
+#include "Dandy.h"
+#include "matrix_calc.h"
+#include "SgoexCerium.h"
+
+static SceneGraphPtr root;
+
+void
+flip()
+{
+    CameraPtr camera = droot->sgroot->getCamera();
+
+    droot->sgroot->flip();
+    droot->sgroot->lightCalc();
+
+    root = droot->createSceneGraph();
+    //root->xyz[0] = screen_w/2;
+    //root->xyz[1] = screen_h/2;;
+    root->xyz[0] = 0;
+    root->xyz[1] = 0;
+    root->xyz[2] = 30.0f;
+
+    /*親の回転、座標から、子の回転、座標を算出*/
+    get_matrix(root->matrix, root->angle, root->xyz, camera->matrix);
+    /*法線用の行列。Cameraの行列を抜いている(Cameraのコンストラクタで、単位行列にしている)*/
+    get_matrix(root->real_matrix, root->angle, root->xyz, camera->real_matrix);
+
+    droot->setSceneData(root);
+}
+
+
+SpriteTable sptable[DEFOBJ];
+
+
+void
+DefSpriteEx(int number, short middlex, short middley)
+{
+    sptable[number].mx = middlex;
+    sptable[number].my = middley;
+}
+
+
+void
+DefSprite(int number, const char *name, float w, float h, int color, OBJECT *obj)
+{
+    SpriteTable *m = &sptable[number];
+    m->w = w;
+    m->h = h;
+    m->color = (color & 32);
+    m->mx = w / 2;
+    m->my = h / 2;
+    m->tex_w = power_of_two(m->w);
+    m->tex_h = power_of_two(m->h);
+    m->texture = (int *)name;
+
+}
+
+static float my_scale = 5;
+
+void
+PutSprite(int zorder, short x, short y, int number)
+{
+    SpriteTable *m = &sptable[number];
+    char *name = (char *) m->texture;
+if (!name) {
+    printf("PutSprite %d unknown\n",number);
+    return;
+}
+    SceneGraphPtr object = droot->createSceneGraph(name);
+    //object->c_xyz[0] = m->mx;
+    //object->c_xyz[1] = m->my;
+    root->addChild(object);
+
+    object->xyz[0] = x - object->c_xyz[0]*my_scale;
+    object->xyz[1] = y - object->c_xyz[1]*my_scale;
+    object->xyz[2] = zorder * 0.01;
+
+    /*親の回転、座標から、子の回転、座標を算出*/
+    get_matrix(object->matrix, object->angle, object->xyz, root->matrix);
+
+    float scale[] = {my_scale,my_scale,1};
+    float c_xyz[] = {0,0,0};
+    scale_matrix(object->matrix, scale, c_xyz);
+    /*法線用の行列。Cameraの行列を抜いている(Cameraのコンストラクタで、単位行列にしている)*/
+    get_matrix(object->real_matrix, object->angle, object->xyz, root->real_matrix);
+}
+
+void
+PutSpriteEx(int number, int x, int y, float scalex, float scaley, float angle)
+{
+ if (1) {
+    PutSprite(1, x, y, number);
+    return;
+ }
+
+    SpriteTable *m = &sptable[number];
+    char *name = (char *) m->texture;
+if (!name) {
+    printf("PutSpriteEx %d unknown\n",number);
+    return;
+}
+    SceneGraphPtr object = droot->createSceneGraph(name);
+    root->addChild(object);
+
+    float scale[] = {my_scale*scalex*4,my_scale*scaley*4,1};
+
+    /*親の回転、座標から、子の回転、座標を算出*/
+    object->xyz[0] = x - object->c_xyz[0] * my_scale - m->w*my_scale;
+    object->xyz[1] = y - object->c_xyz[1] * my_scale - m->h*my_scale;
+    object->xyz[2] = number * 0.01;
+    //object->c_xyz[0] = m->mx;
+    //object->c_xyz[1] = m->my;
+    object->angle[3] = angle * (3.1415926*2/4096);
+    get_matrix(object->matrix, object->angle, object->xyz, root->matrix);
+    float c_xyz[] = {0,0,0};
+    scale_matrix(object->matrix, scale, c_xyz);
+    /*法線用の行列。Cameraの行列を抜いている(Cameraのコンストラクタで、単位行列にしている)*/
+    get_matrix(object->real_matrix, object->angle, object->xyz, root->real_matrix);
+}
+
+
+struct SGO_PAD pad[2];
+
+
+/* コントローラ状態の読み込み */
+void Pad(SDL_Joystick *joy)
+{
+    Sint16 axis;
+
+    SDL_JoystickUpdate();
+  
+    if(SDL_JoystickGetButton(joy,PS2_CROSS)==SDL_PRESSED)
+	pad[0].k0++;
+    else
+	pad[0].k0=0;
+  
+    if(SDL_JoystickGetButton(joy,PS2_CIRCLE)==SDL_PRESSED)
+	pad[0].k1++;
+    else
+	pad[0].k1=0;
+  
+    if(SDL_JoystickGetButton(joy,PS2_SQUARE)==SDL_PRESSED)
+	pad[0].k3++;
+    else
+	pad[0].k3=0;
+  
+    if(SDL_JoystickGetButton(joy,PS2_TRIANGLE)==SDL_PRESSED)
+	pad[0].k4++;
+    else
+	pad[0].k4=0;
+  
+    if(SDL_JoystickGetButton(joy,PS2_L1)==SDL_PRESSED)
+	pad[0].l1++;
+    else
+	pad[0].l1=0;
+  
+    if(SDL_JoystickGetButton(joy,PS2_R1)==SDL_PRESSED)
+	pad[0].r1++;
+    else
+	pad[0].r1=0;
+  
+    if(SDL_JoystickGetButton(joy,PS2_L2)==SDL_PRESSED)
+	pad[0].l2++;
+    else
+	pad[0].l2=0;
+  
+    if(SDL_JoystickGetButton(joy,PS2_R2)==SDL_PRESSED)
+	pad[0].r2++;
+    else
+	pad[0].r2=0;
+  
+    if(SDL_JoystickGetButton(joy,PS2_START)==SDL_PRESSED)
+	pad[0].st++;
+    else
+	pad[0].st=0;
+  
+    if(SDL_JoystickGetButton(joy,PS2_SELECT)==SDL_PRESSED)
+	pad[0].se++;
+    else
+	pad[0].se=0;
+  
+    if(SDL_JoystickGetButton(joy,PS2_L3)==SDL_PRESSED)
+	pad[0].l3++;
+    else
+	pad[0].l3=0;
+  
+    if(SDL_JoystickGetButton(joy,PS2_R3)==SDL_PRESSED)
+	pad[0].r3++;
+    else
+	pad[0].r3=0;
+    //x
+    axis=SDL_JoystickGetAxis(joy,0);
+    if(axis>=3200){
+	pad[0].left=0;
+	pad[0].right++;
+    }
+    else if(axis<=-3200){
+	pad[0].right=0;
+	pad[0].left++;
+    }
+    else {
+	pad[0].right=0;
+	pad[0].left=0;
+    }
+    //y
+    axis=SDL_JoystickGetAxis(joy,1);
+    if(axis>=3200){
+	pad[0].up=0;
+	pad[0].down++;
+    }
+    else if(axis<=-3200){
+	pad[0].down=0;
+	pad[0].up++;
+    }
+    else {
+	pad[0].down=0;
+	pad[0].up=0;
+    }
+
+    if ((pad[0].l1 != 0) && (pad[0].r1 != 0) &&
+	(pad[0].l2 != 0) && (pad[0].r2 != 0) &&
+	(pad[0].st != 0) && (pad[0].se != 0)) {
+	pad[0].quit = 1;
+    } else {
+	pad[0].quit = 0;
+    }
+	
+}
+
+
+void keybord()
+{
+    SDL_PumpEvents();
+    Uint8 *keys = SDL_GetKeyState(NULL);
+
+    if (keys[SDLK_UP]) {
+	pad[0].up++;
+    } else {
+	pad[0].up = 0;
+    }
+    if (keys[SDLK_DOWN]) {
+	pad[0].down++;
+    } else {
+	pad[0].down = 0;
+    }
+
+    if (keys[SDLK_RIGHT]) {
+	pad[0].right++;
+    } else {
+	pad[0].right = 0;
+    }
+
+    if (keys[SDLK_LEFT]) {
+	pad[0].left++;
+    } else {
+	pad[0].left = 0;
+    }
+
+    if (keys[SDLK_a]) {
+	pad[0].k0++;
+    } else {
+	pad[0].k0 = 0;
+    }
+
+    if (keys[SDLK_z]) {
+	pad[0].k1++;
+    } else {
+	pad[0].k1 = 0;
+    }
+
+    if (keys[SDLK_s]) {
+	pad[0].k3++;
+    } else {
+	pad[0].k3 = 0;
+    }
+    
+    if (keys[SDLK_x]) {
+	pad[0].k4++;
+    } else {
+	pad[0].k4 = 0;
+    }
+
+    if (keys[SDLK_r]) {
+	pad[0].r2++;
+    } else {
+	pad[0].r2 = 0;
+    }
+
+    if (keys[SDLK_e]) {
+	pad[0].r1++;
+    } else {
+	pad[0].r1 = 0;
+    }
+
+    if (keys[SDLK_w]) {
+	pad[0].l1++;
+    } else {
+	pad[0].l1 = 0;
+    }
+
+    if (keys[SDLK_q]) {
+	pad[0].l2++;
+    } else {
+	pad[0].l2 = 0;
+    }
+
+    // START ボタンは Return が似合う気がする
+    //if(keys[SDLK_1])
+    if (keys[SDLK_RETURN]) {
+	pad[0].st++;
+    } else {
+	pad[0].st = 0;
+    }
+
+    if (keys[SDLK_2]) {
+	pad[0].se++;
+    } else {
+	pad[0].se = 0;
+    }
+
+    if (keys[SDLK_ESCAPE]) {
+	SDL_Quit();
+	exit(1);
+	//pad[0].st = 1;
+	//pad[0].se = 1;
+    }
+
+    if (keys[SDLK_0]) {
+	pad[0].quit = 1;
+    } else {
+	pad[0].quit = 0;
+    }
+}
+
+
+/* end */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SgoexCerium.h	Sat May 21 15:15:26 2011 +0900
@@ -0,0 +1,23 @@
+#ifndef SgoexCerium_h
+#define SgoexCerium_h
+
+#include "object.h"
+#include "sgoex.h"
+
+extern SpriteTable sptable[DEFOBJ];
+
+extern void flip();
+extern void DefSpriteEx(int number, short middlex, short middley);
+extern void DefSprite(int number, const char *name, float w, float h, int color, OBJECT *obj);
+extern void PutSprite(int zorder, short x, short y, int number);
+extern void PutSpriteEx(int number, int x, int y, float scalex, float scaley, float angle);
+
+extern struct SGO_PAD pad[2];
+
+/* コントローラ状態の読み込み */
+extern void Pad(SDL_Joystick *joy);
+
+
+extern void keybord();
+
+#endif