changeset 1033:431936c0cc96

add application main method and task.
author koba <koba@cr.ie.u-ryukyu.ac.jp>
date Fri, 26 Nov 2010 04:32:59 +0900
parents 44b2c4cb539d
children a0faa0cfc271
files Renderer/Engine/Application.cc Renderer/Engine/Application.h Renderer/Engine/SceneGraph.cc Renderer/Engine/SceneGraph.h Renderer/Engine/SceneGraphRoot.cc Renderer/Engine/SceneGraphRoot.h Renderer/Engine/viewer.cc Renderer/Engine/viewer.h
diffstat 8 files changed, 70 insertions(+), 45 deletions(-) [+]
line wrap: on
line diff
--- a/Renderer/Engine/Application.cc	Thu Oct 28 17:40:13 2010 +0900
+++ b/Renderer/Engine/Application.cc	Fri Nov 26 04:32:59 2010 +0900
@@ -3,5 +3,3 @@
 
 Application::Application(){}
 Application::~Application(){}
-
-
--- a/Renderer/Engine/Application.h	Thu Oct 28 17:40:13 2010 +0900
+++ b/Renderer/Engine/Application.h	Fri Nov 26 04:32:59 2010 +0900
@@ -14,7 +14,9 @@
 public:
     Application();
     virtual ~Application();
-    
+
+    virtual void app_main(Viewer *viewer){};
+    virtual HTaskPtr application_task(HTaskPtr next, Viewer* viewer){return next;};
     virtual MainLoopPtr init(Viewer *viewer, int w, int h)  = 0;
 };
 
--- a/Renderer/Engine/SceneGraph.cc	Thu Oct 28 17:40:13 2010 +0900
+++ b/Renderer/Engine/SceneGraph.cc	Fri Nov 26 04:32:59 2010 +0900
@@ -601,6 +601,17 @@
     (*create_sg)(this->sgroot, property, update_property);
 }
 
+void
+SceneGraph::set_move_collision(move_func new_move)
+{
+    this->move = new_move;
+}
+
+void
+SceneGraph::set_move_collision(collision_func new_collision)
+{
+    this->collision = new_collision;
+}
 
 void
 SceneGraph::set_move_collision(move_func new_move,
--- a/Renderer/Engine/SceneGraph.h	Thu Oct 28 17:40:13 2010 +0900
+++ b/Renderer/Engine/SceneGraph.h	Fri Nov 26 04:32:59 2010 +0900
@@ -35,11 +35,11 @@
 	// とりあえず動かしたいので追加
 	int seq, seq_rd, resend_flag;
 
+    // task 生成用の情報
     int property_size;
     void *propertyptr;
     int move_id;
     int coll_id;
-    PostFunction post_func;
     memaddr property;
     memaddr update_property;
 
@@ -92,6 +92,8 @@
     SceneGraphPtr clone(void);
     SceneGraphPtr clone(void *buf);
     SceneGraphPtr searchSceneGraph(const char *name);
+    void set_move_collision(move_func new_move);
+    void set_move_collision(collision_func new_collision);
     void set_move_collision(move_func new_move, collision_func new_collision);
     void set_move_collision(move_func new_move, collision_func new_collision, void *sgroot);
     void set_move_collision(move_func new_move, collision_func new_collision, create_sg_func new_create_sg);
--- a/Renderer/Engine/SceneGraphRoot.cc	Thu Oct 28 17:40:13 2010 +0900
+++ b/Renderer/Engine/SceneGraphRoot.cc	Fri Nov 26 04:32:59 2010 +0900
@@ -8,7 +8,6 @@
 #include "texture.h"
 #include "Application.h"
 
-
 static int cnt = 0;
 static const int SGLIST_LENGTH = 138;
 static int sg_src_size = SGLIST_LENGTH ;
@@ -409,7 +408,7 @@
     while (t) {
 	SceneGraphPtr c = NULL;
 	if (!t->isRemoved()) {
-	    c = t->clone();	    
+	    c = t->clone();
 	    addNext(c);
 	    cur_parent->addChild(c);
 	    c->frame = t->frame;
@@ -723,7 +722,7 @@
 }
 
 void
-SceneGraphRoot::set_game_task(int id, void *property, int size, PostFunction post_func)
+SceneGraphRoot::set_gtask_array(int id, void *property, int size, PostFunction post_func)
 {
     gtask_array->next_task_array(id);
 
@@ -733,7 +732,7 @@
 }
 
 void
-SceneGraphRoot::set_game_task(int id, void *property, void *pad, int size, PostFunction post_func)
+SceneGraphRoot::set_gtask_array(int id, void *property, void *pad, int size, PostFunction post_func)
 {
     gtask_array->next_task_array(id);
 
@@ -744,20 +743,40 @@
 }
 
 void
+SceneGraphRoot::set_game_task(int id, void *property, int size)
+{
+    HTask *task = sgroot->tmanager->create_task(id);
+    task->set_cpu(SPE_ANY);
+    task->add_inData(property, size);
+    task->add_outData(property, size);
+    task->spawn();
+}
+
+void
+SceneGraphRoot::set_game_task(int id, void *property, void *pad, int size)
+{
+    HTask *task = sgroot->tmanager->create_task(id);
+    task->set_cpu(SPE_ANY);
+    task->add_inData(property, size);
+    task->add_inData(pad, sizeof(Pad));
+    task->add_outData(property, size);
+    task->spawn();
+}
+
+
+void
 main_task_move(SceneGraphPtr node, void *sgroot_, int screen_w, int screen_h)
 {
     int size = node->property_size;
     void *e  = node->propertyptr;
     int move = node->move_id;
-    PostFunction post_func = node->post_func;
+    SceneGraphRoot *sgroottmp = (SceneGraphRoot*)sgroot_;
 /*
-    ObjPropertyPtr property = (ObjPropertyPtr)node->propertyptr;
-    property->root = node;
+  ObjPropertyPtr property = (ObjPropertyPtr)node->propertyptr;
+  node->xyz[0] = property->x;
+  node->xyz[1] = property->y;
 */
-
-    SceneGraphRoot *sgroottmp = (SceneGraphRoot*)sgroot_;
-
-    sgroottmp->set_game_task(move, (void*)e, size, post_func);
+    sgroottmp->set_game_task(move, (void*)e, size);
 }
 
 void
@@ -766,35 +785,32 @@
     int size = node->property_size;
     void *e  = node->propertyptr;
     int move = node->move_id;
-    PostFunction post_func = node->post_func;
-/*
-    ObjPropertyPtr property = (ObjPropertyPtr)node->propertyptr;
-    property->root = node;
-*/
-
     SceneGraphRoot *sgroottmp = (SceneGraphRoot*)sgroot_;
     void *pad = (void*)sgroottmp->getController();
 
-    sgroottmp->set_game_task(move, (void*)e, pad, size, post_func);
+/*
+    ObjPropertyPtr property = (ObjPropertyPtr)node->propertyptr;
+    property->root = node;
+    node->xyz[0] = property->x;
+    node->xyz[1] = property->y;
+*/
+
+    sgroottmp->set_game_task(move, (void*)e, pad, size);
 }
 
 void
-SceneGraphRoot::set_move_task(SceneGraphPtr node, int move, void *property, int size,
-			      PostFunction post_func)
+SceneGraphRoot::set_move_task(SceneGraphPtr node, int move, void *property, int size)
 {
     node->move = main_task_move;
-    node->post_func = post_func;
     node->move_id = move;
     node->propertyptr = property;
     node->property_size = size;
 }
 
 void
-SceneGraphRoot::set_pad_task(SceneGraphPtr node, int move, void *property, int size,
-			     PostFunction post_func)
+SceneGraphRoot::set_pad_task(SceneGraphPtr node, int move, void *property, int size)
 {
     node->move = pad_task_move;
-    node->post_func = post_func;
     node->move_id = move;
     node->propertyptr = property;
     node->property_size = size;
--- a/Renderer/Engine/SceneGraphRoot.h	Thu Oct 28 17:40:13 2010 +0900
+++ b/Renderer/Engine/SceneGraphRoot.h	Fri Nov 26 04:32:59 2010 +0900
@@ -112,10 +112,12 @@
     void task_array_init(int id, int task_num, int param, int inData_num, int outData_num);
     void create_task_array();
     void task_array_finish();
-    void set_game_task(int id, void *property, int size, PostFunction post_func);
-    void set_game_task(int id, void *property, void* pad, int size, PostFunction post_func);
-    void set_move_task(SceneGraphPtr node, int move, void *property, int size, PostFunction post_func);
-    void set_pad_task(SceneGraphPtr node, int move, void *property, int size, PostFunction post_func);
+    void set_gtask_array(int id, void *property, int size, PostFunction post_func);
+    void set_gtask_array(int id, void *property, void* pad, int size, PostFunction post_func);
+    void set_game_task(int id, void *property, int size);
+    void set_game_task(int id, void *property, void *pad, int size);
+    void set_move_task(SceneGraphPtr node, int move, void *property, int size);
+    void set_pad_task(SceneGraphPtr node, int move, void *property, int size);
 
     /* Other System API */
     void allExecute(int screen_w, int screen_h);
--- a/Renderer/Engine/viewer.cc	Thu Oct 28 17:40:13 2010 +0900
+++ b/Renderer/Engine/viewer.cc	Fri Nov 26 04:32:59 2010 +0900
@@ -142,6 +142,7 @@
     this_time  = 0;
     frames     = 0;
 
+    this->app = app;
     MainLoop *mainloop = app->init(this, this->width, this->height);
     mainloop->mainLoop();
 }
@@ -292,6 +293,7 @@
 {
     HTaskPtr task_next = initLoop();
 
+    task_next = app->application_task(task_next, this);
     task_next->set_post(&post2runLoop, (void *)this, (void*)pixels); // set_post(function(this->run_loop()), NULL)
     task_next->spawn();
 }
@@ -312,8 +314,8 @@
     dev->clean_pixels();
 
     pixels = dev->flip_screen(pixels);
-
     sgroot->updateControllerState();
+    app->app_main(this);
 
     //TaskArray を使うか使わないか
     if (sgroot->gtask_array != NULL) {
--- a/Renderer/Engine/viewer.h	Thu Oct 28 17:40:13 2010 +0900
+++ b/Renderer/Engine/viewer.h	Fri Nov 26 04:32:59 2010 +0900
@@ -108,21 +108,13 @@
     {
       sgroot->task_array_init(id, task_num, param, inData_num, outData_num);
     }
-    void set_game_task(int id, void *property, int size, PostFunction post_func)
+    void set_move_task(SceneGraphPtr node, int move, void *titlep, int size)
     {
-      sgroot->set_game_task(id, property, size, post_func);
-    }
-    void set_game_task(int id, void *property, void *pad, int size, PostFunction post_func)
-    {
-      sgroot->set_game_task(id, property, pad, size, post_func);
+      sgroot->set_move_task(node, move, titlep, size);
     }
-    void set_move_task(SceneGraphPtr node, int move, void *titlep, int size, PostFunction post_func)
+    void set_pad_task(SceneGraphPtr node, int move, void *property, int size)
     {
-      sgroot->set_move_task(node, move, titlep, size, post_func);
-    }
-    void set_pad_task(SceneGraphPtr node, int move, void *property, int size, PostFunction post_func)
-    {
-      sgroot->set_pad_task(node, move, property, size, post_func);
+      sgroot->set_pad_task(node, move, property, size);
     }
 
     void createFromXMLmemory(SceneGraph * node, char *data, int len)