diff Renderer/Engine/SceneGraphRoot.cc @ 575:341f1f881a9b draft

Linda API worked. (slightly unreliable)
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Fri, 23 Oct 2009 15:53:24 +0900
parents 5193d51294a2
children 9b6d0da1c12d
line wrap: on
line diff
--- a/Renderer/Engine/SceneGraphRoot.cc	Fri Oct 23 14:02:33 2009 +0900
+++ b/Renderer/Engine/SceneGraphRoot.cc	Fri Oct 23 15:53:24 2009 +0900
@@ -9,8 +9,11 @@
 //#include "SGList.h"
 #include "Application.h"
 
-int cnt = 0;
+static int cnt = 0;
 static const int SGLIST_LENGTH = 138;
+static int sg_src_size = SGLIST_LENGTH ;
+static int sg_src_id = -1;
+static SceneGraphPtr *sg_src;
 
 
 SceneGraphRoot *sgroot;
@@ -19,10 +22,10 @@
 {
     // SGLIST_LENGTH 決め打ちかぁ、動的生成にする場合上限決めておいた方がいいのかな
     //
-    sg_src = new SceneGraphPtr[SGLIST_LENGTH];
+    sg_src = (SceneGraphPtr*) malloc(sizeof(SceneGraphPtr)*SGLIST_LENGTH);
+
     camera = new Camera(w, h);
     iterator = new SceneGraphIterator;
-    sglist = new SceneGraphList;
     controller = create_controller();
 
     sg_exec_tree = NULL;
@@ -58,7 +61,7 @@
 		cnt--;
     }
 
-    delete [] sg_src;
+    free(sg_src);
     delete camera;
     delete iterator;
     delete controller;
@@ -72,6 +75,17 @@
 void
 SceneGraphRoot::registSceneGraph(SceneGraphPtr sg)
 {
+    int dup;
+    if ((dup = getSgid(sg->name))>=0) { // while...
+	sg_src[dup]->name = 0;
+	// we should remove this. but some one may use it...
+    }
+    if (sg_src_id+1> sg_src_size) {
+	sg_src_size *= 2;
+	sg_src = (SceneGraphPtr*)realloc(sg_src, sg_src_size);
+    }
+    sg->id = ++sg_src_id;
+    sg_src[sg->id] = sg;
 }
 
 void
@@ -117,8 +131,7 @@
 	/* ポリゴン(SceneGraph)生成  */
 	tmp = new SceneGraph(manager, cur);	
 
-	addSceneGraphList(manager, tmp);
-	registSceneGraphList(tmp);
+	registSceneGraph(tmp);
     }
 
     xmlFreeDoc(doc);
@@ -131,7 +144,7 @@
     SceneGraphPtr src;
     SceneGraphPtr p;
 
-    if (id < 0 || id > SGLIST_LENGTH) {
+    if (id < 0 || id > sg_src_size) {
 		return NULL;
     }
 
@@ -146,28 +159,6 @@
     return p;
 }
 
-void
-SceneGraphRoot::registSceneGraphList(SceneGraphPtr sg)
-{
-    /*
-      SceneGraphRoot にメンバ変数 SceneGraphList を持たせておくか
-      SceneGraphList sglist
-      sg->name で検索して、有れば sg_src に追加。
-      sgid は sglist のメンバ変数 sgid で管理する感じ
-     */    
-
-    SgStruct *s = sglist->get(sg->name);
-    if (s != NULL) {
-	sg->sgid = sglist->sgid;
-	s->id = sglist->sgid;
-	sg_src[sg->sgid] = sg;
-	sglist->sgid++;
-	return;
-    }
-
-    fprintf(stderr, "error: (%s:%3d) Can't find Scene \"%s\"\n",
-			__FUNCTION__, __LINE__, sg->name);
-}
 
 void
 SceneGraphRoot::createFromXMLmemory(TaskManager *manager, char *data, int len)
@@ -194,22 +185,12 @@
 	/* ポリゴン(SceneGraph)生成  */
 	SceneGraphPtr tmp = new SceneGraph(manager, cur);	
 	
-	addSceneGraphList(manager, tmp);
-	
-	registSceneGraphList(tmp);
+	registSceneGraph(tmp);
     }
     
     xmlFreeDoc(doc);
 }
 
-/* 生成された SceneGraph のを sglist に登録 */
-void
-SceneGraphRoot::addSceneGraphList(TaskManager *manager, SceneGraphPtr tmp)
-{
-    SgStruct *sg_t = (SgStruct *)manager->allocate(sizeof(SgStruct));
-    sg_t->name = tmp->name;
-    sglist->addLast(sg_t);
-}
 
 SceneGraphPtr
 SceneGraphRoot::createSceneGraph(const char *name)
@@ -217,9 +198,7 @@
     SceneGraphPtr src;
     SceneGraphPtr p;
 
-    // SceneGraphList から name を検索して id 取得
-    SgStruct *e = sglist->get(name);
-    int id = e->id;
+    int id = getSgid(name);
     if (id < 0) {
 	return NULL;
     }
@@ -238,8 +217,19 @@
 int
 SceneGraphRoot::getSgid(const char *name)
 {
-    SgStruct *e = sglist->get(name);
-    return e->id;
+    for(int i =0;i<= sg_src_id; i++) {
+	if (strcmp(name,sg_src[i]->name) )
+	    return i;
+    }
+    return -1;
+}
+
+int
+SceneGraphRoot::getLast()
+{
+    if (sg_src_id>=0)
+	return sg_src[sg_src_id]->id;
+    return -1;
 }
 
 /**