diff collision_task.cc @ 54:3acdeb3dc3e8

collision use global_alloc (not work)
author koba <koba@cr.ie.u-ryukyu.ac.jp>
date Thu, 27 Jan 2011 21:05:30 +0900
parents b31bed246abd
children 2c33aa6a4a37
line wrap: on
line diff
--- a/collision_task.cc	Tue Jan 25 17:43:30 2011 +0900
+++ b/collision_task.cc	Thu Jan 27 21:05:30 2011 +0900
@@ -1,107 +1,140 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <SDL.h>
-#include "SDL_opengl.h"
+#include "Func.h"
+#include "TaskManager.h"
+#include "collision_task.h"
 #include "Character.h"
+#include "count2.h"
 #include "tokuten.h"
-#include "bom.h"
-#include "count2.h"
 #include "object.h"
 #include "sgoex.h"
-#include "TaskManager.h"
-#include "Func.h"
-#include "ObjectType.h"
+
 #include "property.h"
 
 
 extern SpriteTable sptable[DEFOBJ];
 extern TaskManager *tmanager;
 
+HTaskPtr update_task;
+HTaskPtr reflect_task;
+
 static CollisionPropertyPtr
-get_property(CHARACTER *p)
+get_property()
 {
     CollisionPropertyPtr property = (CollisionPropertyPtr)tmanager->allocate(sizeof(CollisionProperty));
 
-    property->collision_type = NO;
-    property->enemycount = 0;
+    property->infg_level = infg_level;
+
+    property->tama_lv1_end = tama_lv1_end;
+    property->tama_lv2_end = tama_lv2_end;
+    property->laser_lv1_end = laser_lv1_end;
+
+    property->enemycount = enemycount;
+
+    property->jiki = jiki;
+
+    property->lg = lg;
+    property->infg = infg;
+
+    memcpy(property->tama_lv1, tama_lv1, sizeof(tama1)*20);
+    memcpy(property->tama_lv2, tama_lv2, sizeof(tama2)*20);
     property->tlv3 = tlv3[0];
+    memcpy(property->laser_lv1, laser_lv1, sizeof(laser)*20);
     property->laser_lv2 = laser_lv2[0];
-    property->p = *p;
-
-    memcpy(property->tama_lv1, tama_lv1, sizeof(tama1)*(tama_lv1_end+1));
-    memcpy(property->tama_lv2, tama_lv2, sizeof(tama2)*(tama_lv2_end+1));
-    memcpy(property->laser_lv1, laser_lv1, sizeof(laser)*(laser_lv1_end+1));
     memcpy(property->laser_lv3, laser_lv3, sizeof(laser)*128);
 
     return property;
 }
 
-static void
-check_collision()
-{
-    
-}
-
 void
-free_property(SchedTask *s, void *prop, void *obj)
+reflect_property(SchedTask *s, void *prop, void *none)
 {
     CollisionPropertyPtr property = (CollisionPropertyPtr)prop;
 
-    switch(property->collision_type) {
-	check_collision();
+    infg_level = property->infg_level;
+
+    tama_lv1_end = property->tama_lv1_end;
+    tama_lv2_end = property->tama_lv2_end;
+    laser_lv1_end = property->laser_lv1_end;
+
+    enemycount = property->enemycount;
+
+    jiki = property->jiki;
+
+    lg = property->lg;
+    infg = property->infg;
 
-    case JIKI:
-	jiki.bf = property->jiki.bf;
-	jiki.zanki = property->jiki.zanki;
-	jiki.muteki = property->jiki.muteki;
-	infg = property->infg;
-	infg_level = property->infg_level;
-	break;
+    memcpy(tama_lv1, property->tama_lv1, sizeof(tama1)*20);
+    memcpy(tama_lv2, property->tama_lv2, sizeof(tama2)*20);
+    tlv3[0] = property->tlv3;
+    memcpy(laser_lv1, property->laser_lv1, sizeof(laser)*20);
+    laser_lv2[0] = property->laser_lv2;
+    memcpy(laser_lv3, property->laser_lv3, sizeof(laser)*128);
+}
+
+void
+after_free(SchedTask *s, void *object, void *none)
+{
+    free(object);
+}
+
+
+void
+collision_allocate()
+{
+    HTaskPtr alloc_task = tmanager->create_task(DataAllocate);
+
+    alloc_task->set_param(0, (memaddr)1);
+    alloc_task->set_param(1, (memaddr)sizeof(CollisionProperty));
+    alloc_task->set_param(2, (memaddr)COLLDATA);
+
+    alloc_task->set_cpu(SPE_0);
+    alloc_task->spawn();
+}
 
-    case TAMALV1:
-	infg = property->infg;
-	memcpy(tama_lv1, property->tama_lv1, sizeof(tama1)*(tama_lv1_end+1));
-	break;
-	
-    case TAMALV2:
-	infg = property->infg;
-	memcpy(tama_lv2, property->tama_lv2, sizeof(tama2)*(tama_lv2_end+1));
-	break;
-	
-    case TAMALV3:
-	infg = property->infg;
-	break;
-	
-    case LASERLV1:
-	infg = property->infg;
-	memcpy(laser_lv1, property->laser_lv1, sizeof(laser)*laser_lv1_end+1);
-	break;
+HTaskPtr
+collision_update()
+{
+    update_task = tmanager->create_task(DataUpdate);
+    CollisionPropertyPtr property = get_property();
+
+    update_task->set_param(0, (memaddr)1);
+    update_task->set_param(1, (memaddr)COLLDATA);
+
+    update_task->set_inData(0, property, sizeof(CollisionProperty));
+
+    update_task->set_post(after_free, (void*)property, NULL);
+    update_task->set_cpu(SPE_0);
+
+    return update_task;
+}
 
-    case LASERLV2:
-	lg.stg -= 26;
-	infg = property->infg;
-	break;
-	
-    case LASERLV3:
-	infg = property->infg;
+HTaskPtr
+collision_reflect()
+{
+    reflect_task = tmanager->create_task(COLLDATA_REFLECT);
+    CollisionPropertyPtr property = (CollisionPropertyPtr)tmanager->allocate(sizeof(CollisionProperty));
 
-	break;
+    reflect_task->set_param(0, (memaddr)COLLDATA);
+
+    reflect_task->set_outData(0, property, sizeof(CollisionProperty));
+
+    reflect_task->set_post(reflect_property, (void*)property, NULL);
+    reflect_task->set_cpu(SPE_0);
 
-    default:
-	break;
-    }
+    return reflect_task;
+}
 
-    ObjContainer *new_obj = (ObjContainerPtr)obj;
-    
-    if (new_obj->flag == true){
-	ObjDataPtr obj_data = new_obj->data;
-	Bom(obj_data->x, obj_data->y);
+void
+collision_free()
+{
+    HTaskPtr free_task = tmanager->create_task(DataFree);
 
-	enemycount += property->enemycount;
-    }
+    free_task->set_param(0, (memaddr)COLLDATA);
 
-    free(new_obj);
-    free(prop);
+    free_task->set_cpu(SPE_0);
+    free_task->spawn();
 }
 
 
@@ -109,7 +142,6 @@
 atari(CHARACTER *p)
 {
     int w, h, charno;
-    CollisionPropertyPtr property = get_property(p);
 
     charno = p->charano;
     w = sptable[charno].w;
@@ -124,21 +156,19 @@
 
     collision_task->set_param(0,(memaddr)w);
     collision_task->set_param(1,(memaddr)h);
+    collision_task->set_param(2, (memaddr)COLLDATA);
 
-    collision_task->set_inData(0, property, sizeof(CollisionProperty));
-    collision_task->set_inData(1, &jiki, sizeof(player));
-    collision_task->set_inData(2, &lg, sizeof(stge));
-    collision_task->set_inData(3, &infg, sizeof(stge));
-    collision_task->set_inData(4, &infg_level, sizeof(int));
-    collision_task->set_inData(5, &tama_lv1_end, sizeof(int));
-    collision_task->set_inData(6, &tama_lv2_end, sizeof(int));
-    collision_task->set_inData(7, &laser_lv1_end, sizeof(int));
+    collision_task->set_inData(0, p, sizeof(player));
 
-    collision_task->set_outData(0, property, sizeof(CollisionProperty));
+    collision_task->set_outData(0, p, sizeof(player));
     collision_task->set_outData(1, obj, sizeof(ObjContainer));
 
-    collision_task->set_post(free_property, (void*)property, (void*)obj);
-    collision_task->set_cpu(SPE_ANY);
+    collision_task->set_post(after_free, (void*)obj, NULL);
+    collision_task->set_cpu(SPE_0);
+
+    collision_task->wait_for(update_task);
+    reflect_task->wait_for(collision_task);
+
     collision_task->spawn();
 
     return p;