changeset 793:c260205d3185

add light switch api
author yutaka@localhost.localdomain
date Mon, 03 May 2010 05:09:58 +0900
parents f2497e0ecd7c
children 088f64aad843
files Renderer/Engine/SceneGraphRoot.cc Renderer/Engine/SceneGraphRoot.h Renderer/Engine/spe/DrawSpan.cc Renderer/Engine/viewer.cc Renderer/Engine/viewer.h Renderer/Test/viewer.cc
diffstat 6 files changed, 112 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/Renderer/Engine/SceneGraphRoot.cc	Sun May 02 04:17:34 2010 +0900
+++ b/Renderer/Engine/SceneGraphRoot.cc	Mon May 03 05:09:58 2010 +0900
@@ -39,6 +39,7 @@
     screen_w = (int)w;
     screen_h = (int)h;
     int light_num = 4;
+    light_sysswitch = 0;
 
     for (int i = 0; i < light_num; i++) {
       light[i] = new SceneGraph;
@@ -46,8 +47,7 @@
       light[i]->xyz[1] = 0;
       light[i]->xyz[2] = 0;
 
-      light_switch[i] = 1;
-      light_sysswitch = 0;
+      light_switch[i] = 0;
 
     }
 
@@ -664,4 +664,32 @@
   return light_sysswitch;
 }
 
+void
+SceneGraphRoot::OnLightSwitch(int id)
+{
+  light_switch[id] = 1;
+}
+
+void
+SceneGraphRoot::OffLightSwitch(int id)
+{
+  light_switch[id] = 0;
+}
+
+void
+SceneGraphRoot::OnLightSysSwitch()
+{
+
+  light_sysswitch = 1;
+
+}
+
+void
+SceneGraphRoot::OffLightSysSwitch()
+{
+
+  light_sysswitch = 0;
+
+}
+
 /* end */
--- a/Renderer/Engine/SceneGraphRoot.h	Sun May 02 04:17:34 2010 +0900
+++ b/Renderer/Engine/SceneGraphRoot.h	Mon May 03 05:09:58 2010 +0900
@@ -103,9 +103,10 @@
     SceneGraphIteratorPtr getIterator(SceneGraphPtr list);
     CameraPtr getCamera();
     SceneGraphPtr getLight(int id);
-    float* getLightVector();
-    int* getLightSwitch();
-    int getLightSysSwitch();
+    void OnLightSwitch(int id);
+    void OffLightSwitch(int id);
+    void OnLightSysSwitch();
+    void OffLightSysSwitch();
 
     /* Other System API */
     void allExecute(int screen_w, int screen_h);
@@ -116,6 +117,9 @@
     void updateControllerState();
     void regist_execute();
     void move_finish();
+    float* getLightVector();
+    int* getLightSwitch();
+    int getLightSysSwitch();
 
     void speExecute(int screen_w, int screen_h);
     void speExecute(int screen_w, int screen_h, Application *app);
--- a/Renderer/Engine/spe/DrawSpan.cc	Sun May 02 04:17:34 2010 +0900
+++ b/Renderer/Engine/spe/DrawSpan.cc	Mon May 03 05:09:58 2010 +0900
@@ -226,9 +226,10 @@
 #endif
     /*完全に透けているか判断*/
     int flag = (alpha != 0);
-    int *light_sys_switch = (int*)smanager->global_get(LightSysSwitch);
+    int *light_sysswitch = (int*)smanager->global_get(LightSysSwitch);
+    //smanager->printf("sys %d\n",light_sysswitch);
 
-    if ( *light_sys_switch == 1) {
+    if ( *light_sysswitch == 1) {
         color = infinity_light_calc(color,normal_x,normal_y,normal_z,
 				    smanager,localx,localy,zpos,
 				    world_x,world_y,world_z);
@@ -445,7 +446,7 @@
     vector float v_world[4] __attribute__((aligned(16))) = {{world_x, world_y, -world_z, 0},
                                                             {world_x, world_y, -world_z, 0},
                                                             {world_x, world_y, -world_z, 0},
-                                                            {0,       0,        0,       0}};
+                                                            {world_x, world_y, -world_z, 0}};
 
 
     int light_rgb;
--- a/Renderer/Engine/viewer.cc	Sun May 02 04:17:34 2010 +0900
+++ b/Renderer/Engine/viewer.cc	Mon May 03 05:09:58 2010 +0900
@@ -113,7 +113,6 @@
     light_xyz_stock = (float *)manager->allocate(size);
     light_xyz = (float *)manager->allocate(size);
 
-
     for (int i = 0; i < light_size ; i++) {
       light_xyz[i] = 0.0f;
     }
@@ -128,6 +127,7 @@
 
     size = light_num * sizeof(int);
     light_switch = (int*)manager->allocate(size);
+
     for (int i = 0; i < light_num; i++) {
         light_switch[i] = 0;
     }
@@ -142,6 +142,12 @@
 
     size = 16; // LightSysSwitch は 4byte. 残り 12byte は DMA転送の為のパディング
 
+    light_sysswitch = (int*)manager->allocate(size);
+
+    for (int i = 0; i < size / sizeof(int); i++) {
+      light_sysswitch[i] = 0;
+    }
+
     for(int i = 0; i < spe_num; i++) {
 	HTaskPtr data_load = manager->create_task(DataLoad);
 	data_load->set_param(0,(memaddr)size);
@@ -324,6 +330,7 @@
     sgroot->allExecute(width, height);
     light_xyz_stock = sgroot->getLightVector();
     light_switch_stock = sgroot->getLightSwitch();
+    light_sysswitch_stock = sgroot->getLightSysSwitch();
     //sgroot->checkRemove();
 
     // ここから下は Rendering という関数にする
@@ -513,7 +520,7 @@
 
     //Light info update
                                                                    
-    HTaskPtr data_update;
+    //HTaskPtr data_update;
     HTaskPtr data_update_wait;
     int light_num = 4;
     int size = sizeof(float)*4*light_num; //xyz+alpha(4) * light_num(4) 
@@ -526,6 +533,8 @@
     for (int i = 0; i < light_num; i++) {
         light_switch[i] = light_switch_stock[i];
     }
+
+    light_sysswitch[0] = light_sysswitch_stock;
  
     data_update_wait = manager->create_task(DataUpdate);
     data_update_wait->add_inData(light_xyz,size);
@@ -540,13 +549,13 @@
     size = light_num * sizeof(int);
 
     for (int i = 0; i < spe_num; i++) {
-      update_task_create(light_xyz,size,LightSwitch,(int)SPE_0+i,data_update_wait);
+      update_task_create(light_switch,size,LightSwitch,(int)SPE_0+i,data_update_wait);
     }
 
     size = 16; // LightSysSwitch は 4byte. 残り 12byte は DMA転送の為のパディング
 
     for (int i = 0; i < spe_num; i++) {
-      update_task_create(light_xyz,size,LightSysSwitch,(int)SPE_0+i,data_update_wait);
+      update_task_create(light_sysswitch,size,LightSysSwitch,(int)SPE_0+i,data_update_wait);
     }
     
 
--- a/Renderer/Engine/viewer.h	Sun May 02 04:17:34 2010 +0900
+++ b/Renderer/Engine/viewer.h	Mon May 03 05:09:58 2010 +0900
@@ -43,6 +43,8 @@
     float *light_xyz_stock;
     int *light_switch;
     int *light_switch_stock;
+    int *light_sysswitch;
+    int light_sysswitch_stock;
 
     Uint32 video_flags;
     Uint32 *pixels;
@@ -125,6 +127,31 @@
 	return sgroot->getLast();
     }
 
+    SceneGraphPtr getLight(int id)
+    {
+      return sgroot->getLight(id);
+    }
+
+    void OnLightSwitch(int id)
+    {
+      sgroot->OnLightSwitch(id);
+    }
+
+    void OffLightSwitch(int id)
+    {
+      sgroot->OffLightSwitch(id);
+    }
+
+    void OnLightSysSwitch()
+    {
+      sgroot->OnLightSysSwitch();
+    }
+
+    void OffLightSysSwitch()
+    {
+      sgroot->OffLightSysSwitch();
+    }
+
 };
 
 #define default_sdl_flag SDL_INIT_TIMER | SDL_INIT_JOYSTICK
--- a/Renderer/Test/viewer.cc	Sun May 02 04:17:34 2010 +0900
+++ b/Renderer/Test/viewer.cc	Mon May 03 05:09:58 2010 +0900
@@ -20,8 +20,19 @@
 
 static float h0; // 初期高さ
 static float ball_radius = 100.0f;
+static float speed = 10.0f;
 
-static float speed = 10.0f;
+char *light_sysswitch = NULL;
+int light_num = 4;
+
+void LightSysSwitch(Viewer *sgroot) {
+  if (strcmp(light_sysswitch,"on") == 0) {
+    sgroot->OnLightSysSwitch();
+  } else if (strcmp(light_sysswitch,"off") == 0) {
+    sgroot->OffLightSysSwitch();
+  }
+}
+
 
 static void
 ball_move_idle2(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h)
@@ -81,9 +92,9 @@
 static void
 ball_move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h)
 {
-    vy += g * dt;
-    node->xyz[1] += vy * dt;
-    //    node->xyz[0] += 10.0f;
+  vy += g * dt;
+  node->xyz[1] += vy * dt;
+  //node->xyz[0] += 10.0f;
 }
 
 static void
@@ -114,8 +125,19 @@
 MainLoopPtr 
 viewer::init(Viewer *sgroot, int screen_w, int screen_h)
 {
+
+    LightSysSwitch(sgroot);
+
     SceneGraphPtr ball;
 
+    for (int i = 0; i < light_num; i++) {
+        SceneGraphPtr light = sgroot->getLight(i);
+	sgroot->OnLightSwitch(i);
+	light->xyz[0] = screen_w / 2;
+	light->xyz[1] = screen_h / 2;
+	light->xyz[2] = -100;
+    }
+
     // 固定した値で srandom すると、毎回同じ、random() 列が生成される
     // random な値が欲しいなら、man random に方法が書いてあります。
     srandom(100);
@@ -163,7 +185,11 @@
             xmlfile = argv[i+1];
         } else if (strcmp(argv[i],"-name") == 0 && i+1<=argc) {
            parts[parts_cnt++] = argv[i+1];
-        }
+        } else if (strcmp(argv[i],"-lightsys") == 0 && i+1<=argc) {
+	  light_sysswitch = argv[i+1];
+	} else if (strcmp(argv[i],"-lightnum") == 0 && i+1<=argc) {
+	  light_num = atoi(argv[i+1]);
+	}
     }
     return init(manager, argc, argv);