changeset 756:2575791a333a

add Test/create_task {spe, task}/Property
author hiroki@henri.cr.ie.u-ryukyu.ac.jp
date Fri, 29 Jan 2010 11:34:43 +0900
parents 0a013d0935a9
children 5238f3e854fc
files Renderer/Engine/RenderingTasks.h Renderer/Engine/spe/ChainCal.cc Renderer/Engine/spe/Property.cc Renderer/Engine/spe/Property.h Renderer/Engine/spe/spe-main.cc Renderer/Engine/task/Property.cc Renderer/Engine/task/Property.h Renderer/Engine/task/task_init.cc Renderer/Test/Chain.h Renderer/Test/Makefile.cell Renderer/Test/create_task.cc Renderer/Test/create_task.h Renderer/Test/property_test.cc Renderer/Test/property_test.h
diffstat 14 files changed, 263 insertions(+), 68 deletions(-) [+]
line wrap: on
line diff
--- a/Renderer/Engine/RenderingTasks.h	Wed Jan 27 18:57:23 2010 +0900
+++ b/Renderer/Engine/RenderingTasks.h	Fri Jan 29 11:34:43 2010 +0900
@@ -31,7 +31,7 @@
      ChainMove,
      ChainCal,
      ChainInit,
-
+     PropertyTask,
 
      RUN_FINISH,
 
--- a/Renderer/Engine/spe/ChainCal.cc	Wed Jan 27 18:57:23 2010 +0900
+++ b/Renderer/Engine/spe/ChainCal.cc	Fri Jan 29 11:34:43 2010 +0900
@@ -8,86 +8,87 @@
 /* これは必須 */
 SchedDefineTask(ChainCal);
 
-#define CHAIN_LEN 50
+#define CHAIN_LEN	50
 
-static const    double m = 100.0;
-static const    double k = 7000.0;
-static const    double g = 9.8;
-static const    double dt = 0.003;
-static const    double chain_width = 10;
-static const    double safe = 0.995;
+static const    double	m	    = 100.0;
+static const    double	k	    = 7000.0;
+static const    double	g	    = 9.8;
+static const    double	dt	    = 0.003;
+static const    double	chain_width = 10;
+static const    double	safe	    = 0.995;
 
 typedef struct {
-    double x, y, next_x, next_y;
-    double vx, vy, next_vx, next_vy;
-    double angle[3];
-    int can_move;
-    uint32 parent;
-    int id;
+    double	x, y, next_x, next_y;
+    double	vx, vy, next_vx, next_vy;
+    double	angle[3];
+    int		can_move;
+    uint32	parent;
+    int		id;
     //int parent;
 } ChainProperty, *ChainPropertyPtr;
 
 static int
 run(SchedTask *s,void *rbuf, void *wbuf)
 {
-	ChainPropertyPtr property = (ChainPropertyPtr)s->get_input(rbuf, 0);
-    ChainPropertyPtr update_property = (ChainPropertyPtr)s->get_output(wbuf, 0);
+    ChainPropertyPtr	property	= (ChainPropertyPtr)s->get_input(rbuf, 0);
+    ChainPropertyPtr	update_property = (ChainPropertyPtr)s->get_output(wbuf, 0);
 
 //    ChainPropertyPtr property = (ChainPropertyPtr)rbuf;
-//    int id = get_param(0);
+//    int id			= get_param(0);
     
     //ChainPropertyPtr o_property = (ChainPropertyPtr)wbuf;
     
     for(int cnt = 0; cnt < 600; cnt++) {
-		for(int i = 0; i < CHAIN_LEN; i++) {
-			if(property[i].can_move) {
-				double dx = property[i-1].x - property[i].x;
-				double dy = property[i-1].y - property[i].y;
-				double l = sqrt(dx * dx + dy * dy);
-				double a = k * (l - chain_width) / m;
-				double ax = a * dx / l;
-				double ay = a * dy / l;
-				if(i < CHAIN_LEN - 1) {
-					dx = property[i+1].x - property[i].x;
-					dy = property[i+1].y - property[i].y;
-					l = sqrt(dx * dx + dy * dy);
-					a = k * (l - chain_width) / m;
-					ax += a * dx / l;
-					ay += a * dy / l;
-				}
-				ay += g;
-				property[i].vx *= safe;
-				property[i].vy *= safe;
-				property[i].next_vx = property[i].vx + ax * dt;
-				property[i].next_vy = property[i].vy + ay * dt;
-				property[i].next_x = property[i].x + property[i].vx * dt;
-				property[i].next_y = property[i].y + property[i].vy * dt;
-			} else {
-				property[i].next_x = property[i].x;
-				property[i].next_y = property[i].y;
-			}
+	for(int i = 0; i < CHAIN_LEN; i++) {
+	    if(property[i].can_move) {
+		double	dx  = property[i-1].x - property[i].x;
+		double	dy  = property[i-1].y - property[i].y;
+		double	l   = sqrt(dx * dx + dy * dy);
+		double	a   = k * (l - chain_width) / m;
+		double	ax  = a * dx / l;
+		double	ay  = a * dy / l;
+		if(i < CHAIN_LEN - 1) {
+		    dx  = property[i+1].x - property[i].x;
+		    dy  = property[i+1].y - property[i].y;
+		    l   = sqrt(dx * dx + dy * dy);
+		    a   = k * (l - chain_width) / m;
+		    ax += a * dx / l;
+		    ay += a * dy / l;
 		}
-		for(int i = 0; i < CHAIN_LEN; i++) {
-			property[i].vx = property[i].next_vx;
-			property[i].vy = property[i].next_vy;
-			property[i].x = property[i].next_x;
-			property[i].y = property[i].next_y;
-		}
+		ay		    += g;
+		property[i].vx	    *= safe;
+		property[i].vy	    *= safe;
+		property[i].next_vx  = property[i].vx + ax *		dt;
+		property[i].next_vy  = property[i].vy + ay *		dt;
+		property[i].next_x   = property[i].x + property[i].vx *	dt;
+		property[i].next_y   = property[i].y + property[i].vy *	dt;
+	    } else {
+		property[i].next_x   = property[i].x;
+		property[i].next_y   = property[i].y;
+	    }
+	}
+	for(int i = 0; i < CHAIN_LEN; i++) {
+	    property[i].vx = property[i].next_vx;
+	    property[i].vy = property[i].next_vy;
+	    property[i].x  = property[i].next_x;
+	    property[i].y  = property[i].next_y;
+	}
     }
 	
     for (int j = 0; j < CHAIN_LEN; j++) {
-		int p, n;
-		int id = property[j].id;
-		p = n = id;
-		if(p != 0) {
-			p--;
-		}
-		if(n != CHAIN_LEN - 1) {
-			n++;
-		}
-		property[j].angle[2-(id%2)*2]
-			= 90 + atan((property[p].next_y - property[n].next_y) / (property[p].next_x - property[n].next_x)) * 180 / M_PI;
+	int	p, n;
+	int	id = property[j].id;
+	p	   = n = id;
+	if(p != 0) {
+	    p--;
+	}
+	if(n != CHAIN_LEN - 1) {
+	    n++;
+	}
+	property[j].angle[2-(id%2)*2]
+	    = 90 + atan((property[p].next_y - property[n].next_y) / (property[p].next_x - property[n].next_x)) * 180 / M_PI;
     }
-    memcpy((void*)update_property, (void*)property, sizeof(ChainProperty) * CHAIN_LEN);    
+
+    memcpy((void*)update_property, (void*)property, sizeof(ChainProperty) *	CHAIN_LEN);    
     return 0;
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Renderer/Engine/spe/Property.cc	Fri Jan 29 11:34:43 2010 +0900
@@ -0,0 +1,27 @@
+#include <stdio.h>
+#include <string.h>
+#include <math.h>
+#include "Property.h"
+#include "Func.h"
+#include "types.h"
+
+/* これは必須 */
+SchedDefineTask(PropertyTask);
+
+typedef struct {
+    float x, y, z;
+} Property, *PropertyPtr;
+
+static int
+run(SchedTask *s,void *rbuf, void *wbuf)
+{
+    PropertyPtr	property	= (PropertyPtr)s->get_input(rbuf, 0);
+    PropertyPtr	update_property = (PropertyPtr)s->get_output(wbuf, 0);
+
+    property->x += 1.0f;
+    property->y += 1.0f;
+    property->z += 1.0f;
+
+    memcpy((void*)update_property, (void*)property, sizeof(Property));
+    return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Renderer/Engine/spe/Property.h	Fri Jan 29 11:34:43 2010 +0900
@@ -0,0 +1,9 @@
+#ifndef INCLUDED_TASK_PROPERTY
+#define INCLUDED_TASK_PROPERTY
+
+#ifndef INCLUDED_SCHED_TASK
+#  include "SchedTask.h"
+#endif
+
+
+#endif
--- a/Renderer/Engine/spe/spe-main.cc	Wed Jan 27 18:57:23 2010 +0900
+++ b/Renderer/Engine/spe/spe-main.cc	Fri Jan 29 11:34:43 2010 +0900
@@ -21,6 +21,8 @@
 SchedExternTask(InitKey);
 SchedExternTask(UpdateKey);
 
+SchedExternTask(PropertyTask);
+
 void
 task_init(Scheduler *s)
 {
@@ -40,6 +42,7 @@
 
     SchedRegister( ShowTime);
 
-	SchedRegister( InitKey);
-	SchedRegister( UpdateKey);
+    SchedRegister( PropertyTask);
+    SchedRegister( InitKey);
+    SchedRegister( UpdateKey);
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Renderer/Engine/task/Property.cc	Fri Jan 29 11:34:43 2010 +0900
@@ -0,0 +1,27 @@
+#include <stdio.h>
+#include <string.h>
+#include <math.h>
+#include "Property.h"
+#include "Func.h"
+#include "types.h"
+
+/* これは必須 */
+SchedDefineTask(PropertyTask);
+
+typedef struct {
+    float x, y, z;
+} Property, *PropertyPtr;
+
+static int
+run(SchedTask *s,void *rbuf, void *wbuf)
+{
+    PropertyPtr	property	= (PropertyPtr)s->get_input(rbuf, 0);
+    PropertyPtr	update_property = (PropertyPtr)s->get_output(wbuf, 0);
+
+    property->x += 1.0f;
+    property->y += 1.0f;
+    property->z += 1.0f;
+
+    memcpy((void*)update_property, (void*)property, sizeof(Property));
+    return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Renderer/Engine/task/Property.h	Fri Jan 29 11:34:43 2010 +0900
@@ -0,0 +1,9 @@
+#ifndef INCLUDED_TASK_PROPERTY
+#define INCLUDED_TASK_PROPERTY
+
+#ifndef INCLUDED_SCHED_TASK
+#  include "SchedTask.h"
+#endif
+
+
+#endif
--- a/Renderer/Engine/task/task_init.cc	Wed Jan 27 18:57:23 2010 +0900
+++ b/Renderer/Engine/task/task_init.cc	Fri Jan 29 11:34:43 2010 +0900
@@ -30,6 +30,8 @@
 SchedExternTask(Switch);
 SchedExternTask(RunMove);
 
+SchedExternTask(PropertyTask);
+
 
 /**
  * set_cpu(CPU_PPE) で動作する task
@@ -64,5 +66,6 @@
     // usr
     SchedRegister( ChainMove);
     SchedRegister( RunMove);
+    SchedRegister( PropertyTask);
 
 }
--- a/Renderer/Test/Chain.h	Wed Jan 27 18:57:23 2010 +0900
+++ b/Renderer/Test/Chain.h	Fri Jan 29 11:34:43 2010 +0900
@@ -17,7 +17,7 @@
 
     SceneGraphPtr scenegraph_factory(void *p, int size);
     SceneGraphPtr scenegraph_connector(void *p, int size, SceneGraphPtr s, SceneGraphPtr sg_available_list);
-	void init(TaskManager *manager, int w, int h);
+    void init(TaskManager *manager, int w, int h);
     void init_chain_vars(ChainPropertyPtr cv);
     void chain_move(TaskManager *manager, SceneGraphPtr sg, int w, int h);
     void chain_collision(SceneGraphPtr sg, int w, int h, SceneGraphPtr osg);
--- a/Renderer/Test/Makefile.cell	Wed Jan 27 18:57:23 2010 +0900
+++ b/Renderer/Test/Makefile.cell	Fri Jan 29 11:34:43 2010 +0900
@@ -11,7 +11,7 @@
 .cc.o:
 	$(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@
 
-ALL = spe-main ball_bound boss1_action direction gaplant ieshoot node panel universe untitled vacuum dynamic viewer SgRootChange
+ALL = spe-main ball_bound boss1_action direction gaplant ieshoot node panel universe untitled vacuum dynamic viewer SgRootChange property_test create_task
 all: $(ALL)
 
 speobject:
@@ -78,7 +78,15 @@
 
 SG_CHANGE_OBJ = SgRootChange.o
 SgRootChange : $(SG_CHANGE_OBJ) 
-	   $(CC) -o $@ $?   $(LIBS)
+	$(CC) -o $@ $?   $(LIBS)
+
+PROPERTY_TEST_OBJ = property_test.o
+property_test : $(PROPERTY_TEST_OBJ)
+	$(CC) -o $@ $?   $(LIBS)
+
+CREATE_TASK_OBJ = create_task.o
+create_task : $(CREATE_TASK_OBJ)
+	$(CC) -o $@ $?   $(LIBS)
 	
 debug: $(TARGET)
 	sudo ppu-gdb ./$(TARGET) 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Renderer/Test/create_task.cc	Fri Jan 29 11:34:43 2010 +0900
@@ -0,0 +1,81 @@
+#include <math.h>
+#include <stdlib.h>
+#include "SceneGraphRoot.h"
+#include "MainLoop.h"
+#include "create_task.h"
+#include "sys.h"
+#include "Func.h"
+
+// prototype
+static void move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h);
+static void collision(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h, SceneGraphPtr tree);
+
+static void
+move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h)
+{
+    SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_;
+    TaskManager *manager = sgroot->tmanager;
+    HTaskPtr property_task = manager->create_task(PropertyTask);
+
+    Property *property        = (Property *)manager->allocate(sizeof(Property));
+    Property *property_update = (Property *)manager->allocate(sizeof(Property));
+
+    property_task->add_inData(property, sizeof(Property));
+    property_task->add_outData(property_update, sizeof(Property));
+    property_task->set_cpu(SPE_ANY);
+
+    property_task->spawn();
+}
+
+static void
+collision(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h,
+	  SceneGraphPtr tree)
+{
+}
+
+MainLoopPtr 
+create_task::init(Viewer *sgroot, int screen_w, int screen_h)
+{
+    SceneGraphPtr ball;
+
+    sgroot->createFromXMLfile("xml_file/Ball.xml");
+
+    ball = sgroot->createSceneGraph("Ball");
+    ball->set_move_collision(move, collision);
+
+    ball->xyz[0] = screen_w/2;
+    ball->xyz[1] = screen_h/2;
+    ball->xyz[2] = 30.0f;
+
+    sgroot->setSceneData(ball);
+
+    return sgroot;
+}
+
+extern Application *
+application() {
+    return new create_task();
+}
+
+const char *usr_help_str = "Usage: ./test_nogl [OPTION]\n";
+
+extern int init(TaskManager *manager, int argc, char *argv[]);
+extern void task_initialize();
+static void TMend(TaskManager *manager);
+
+int
+TMmain(TaskManager *manager, int argc, char *argv[])
+{
+    task_initialize();
+    manager->set_TMend(TMend);
+    return init(manager, argc, argv);
+
+}
+
+void
+TMend(TaskManager *manager)
+{
+    printf("test_nogl end\n");
+}
+
+/* end */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Renderer/Test/create_task.h	Fri Jan 29 11:34:43 2010 +0900
@@ -0,0 +1,16 @@
+#include <math.h>
+#include <stdlib.h>
+#include "SceneGraphRoot.h"
+#include "Application.h"
+#include "MainLoop.h"
+#include "viewer.h"
+
+typedef struct {
+    float x, y, z;
+} *PropertyPtr, Property;
+
+class create_task : public Application {
+
+    MainLoopPtr init(Viewer *viewer, int screen_w, int screen_h);
+
+};
--- a/Renderer/Test/property_test.cc	Wed Jan 27 18:57:23 2010 +0900
+++ b/Renderer/Test/property_test.cc	Fri Jan 29 11:34:43 2010 +0900
@@ -10,7 +10,8 @@
 ChainProperty cv[CHAIN_LEN];
 
 //
-void createSceneGraphFromProperty(SceneGraphPtr root, ChainPropertyPtr cv, Viewer *sgroot);
+//void createSceneGraphFromProperty(SceneGraphPtr root, ChainPropertyPtr cv, Viewer *sgroot);
+void createSceneGraphFromProperty(SceneGraphPtr root, ChainPropertyPtr cv, SgChange *sgroot);
 
 void
 init_chainold_vars(ChainPropertyPtr cv) {
@@ -140,7 +141,11 @@
 
 
 void
+#if 1
 createSceneGraphFromProperty(SceneGraphPtr root, ChainPropertyPtr cv, Viewer *sgroot)
+#else
+createSceneGraphFromProperty(SceneGraphPtr root, ChainPropertyPtr cv, SgChange *sgroot)
+#endif
 {
     SceneGraphPtr node;
 
@@ -172,6 +177,11 @@
 MainLoopPtr
 Chain::init(Viewer *sgroot, int w, int h)
 {
+#if 0
+    SgChange *sgroot = new SgChange(sgroot_);
+    sgroot->run_init();
+#endif
+
     SceneGraphPtr root, chain;
     sgroot->createFromXMLfile("xml_file/chain.xml");
 
--- a/Renderer/Test/property_test.h	Wed Jan 27 18:57:23 2010 +0900
+++ b/Renderer/Test/property_test.h	Fri Jan 29 11:34:43 2010 +0900
@@ -1,4 +1,5 @@
 #include "Application.h"
+#include "SgChange.h"
 
 typedef void (*spe_move_func)(void *cv, int screen_w, int screen_h);
 typedef void (*spe_collision_func)(void *cv, int screen_w, int screen_h);