Mercurial > hg > Members > koba > t_dandy
comparison 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 |
comparison
equal
deleted
inserted
replaced
53:b31bed246abd | 54:3acdeb3dc3e8 |
---|---|
1 #include <stdio.h> | 1 #include <stdio.h> |
2 #include <stdlib.h> | 2 #include <stdlib.h> |
3 #include <SDL.h> | 3 #include <SDL.h> |
4 #include "SDL_opengl.h" | 4 #include "Func.h" |
5 #include "TaskManager.h" | |
6 #include "collision_task.h" | |
5 #include "Character.h" | 7 #include "Character.h" |
8 #include "count2.h" | |
6 #include "tokuten.h" | 9 #include "tokuten.h" |
7 #include "bom.h" | |
8 #include "count2.h" | |
9 #include "object.h" | 10 #include "object.h" |
10 #include "sgoex.h" | 11 #include "sgoex.h" |
11 #include "TaskManager.h" | 12 |
12 #include "Func.h" | |
13 #include "ObjectType.h" | |
14 #include "property.h" | 13 #include "property.h" |
15 | 14 |
16 | 15 |
17 extern SpriteTable sptable[DEFOBJ]; | 16 extern SpriteTable sptable[DEFOBJ]; |
18 extern TaskManager *tmanager; | 17 extern TaskManager *tmanager; |
19 | 18 |
19 HTaskPtr update_task; | |
20 HTaskPtr reflect_task; | |
21 | |
20 static CollisionPropertyPtr | 22 static CollisionPropertyPtr |
21 get_property(CHARACTER *p) | 23 get_property() |
22 { | 24 { |
23 CollisionPropertyPtr property = (CollisionPropertyPtr)tmanager->allocate(sizeof(CollisionProperty)); | 25 CollisionPropertyPtr property = (CollisionPropertyPtr)tmanager->allocate(sizeof(CollisionProperty)); |
24 | 26 |
25 property->collision_type = NO; | 27 property->infg_level = infg_level; |
26 property->enemycount = 0; | 28 |
29 property->tama_lv1_end = tama_lv1_end; | |
30 property->tama_lv2_end = tama_lv2_end; | |
31 property->laser_lv1_end = laser_lv1_end; | |
32 | |
33 property->enemycount = enemycount; | |
34 | |
35 property->jiki = jiki; | |
36 | |
37 property->lg = lg; | |
38 property->infg = infg; | |
39 | |
40 memcpy(property->tama_lv1, tama_lv1, sizeof(tama1)*20); | |
41 memcpy(property->tama_lv2, tama_lv2, sizeof(tama2)*20); | |
27 property->tlv3 = tlv3[0]; | 42 property->tlv3 = tlv3[0]; |
43 memcpy(property->laser_lv1, laser_lv1, sizeof(laser)*20); | |
28 property->laser_lv2 = laser_lv2[0]; | 44 property->laser_lv2 = laser_lv2[0]; |
29 property->p = *p; | |
30 | |
31 memcpy(property->tama_lv1, tama_lv1, sizeof(tama1)*(tama_lv1_end+1)); | |
32 memcpy(property->tama_lv2, tama_lv2, sizeof(tama2)*(tama_lv2_end+1)); | |
33 memcpy(property->laser_lv1, laser_lv1, sizeof(laser)*(laser_lv1_end+1)); | |
34 memcpy(property->laser_lv3, laser_lv3, sizeof(laser)*128); | 45 memcpy(property->laser_lv3, laser_lv3, sizeof(laser)*128); |
35 | 46 |
36 return property; | 47 return property; |
37 } | 48 } |
38 | 49 |
39 static void | 50 void |
40 check_collision() | 51 reflect_property(SchedTask *s, void *prop, void *none) |
41 { | 52 { |
42 | 53 CollisionPropertyPtr property = (CollisionPropertyPtr)prop; |
54 | |
55 infg_level = property->infg_level; | |
56 | |
57 tama_lv1_end = property->tama_lv1_end; | |
58 tama_lv2_end = property->tama_lv2_end; | |
59 laser_lv1_end = property->laser_lv1_end; | |
60 | |
61 enemycount = property->enemycount; | |
62 | |
63 jiki = property->jiki; | |
64 | |
65 lg = property->lg; | |
66 infg = property->infg; | |
67 | |
68 memcpy(tama_lv1, property->tama_lv1, sizeof(tama1)*20); | |
69 memcpy(tama_lv2, property->tama_lv2, sizeof(tama2)*20); | |
70 tlv3[0] = property->tlv3; | |
71 memcpy(laser_lv1, property->laser_lv1, sizeof(laser)*20); | |
72 laser_lv2[0] = property->laser_lv2; | |
73 memcpy(laser_lv3, property->laser_lv3, sizeof(laser)*128); | |
43 } | 74 } |
44 | 75 |
45 void | 76 void |
46 free_property(SchedTask *s, void *prop, void *obj) | 77 after_free(SchedTask *s, void *object, void *none) |
47 { | 78 { |
48 CollisionPropertyPtr property = (CollisionPropertyPtr)prop; | 79 free(object); |
80 } | |
49 | 81 |
50 switch(property->collision_type) { | |
51 check_collision(); | |
52 | 82 |
53 case JIKI: | 83 void |
54 jiki.bf = property->jiki.bf; | 84 collision_allocate() |
55 jiki.zanki = property->jiki.zanki; | 85 { |
56 jiki.muteki = property->jiki.muteki; | 86 HTaskPtr alloc_task = tmanager->create_task(DataAllocate); |
57 infg = property->infg; | |
58 infg_level = property->infg_level; | |
59 break; | |
60 | 87 |
61 case TAMALV1: | 88 alloc_task->set_param(0, (memaddr)1); |
62 infg = property->infg; | 89 alloc_task->set_param(1, (memaddr)sizeof(CollisionProperty)); |
63 memcpy(tama_lv1, property->tama_lv1, sizeof(tama1)*(tama_lv1_end+1)); | 90 alloc_task->set_param(2, (memaddr)COLLDATA); |
64 break; | |
65 | |
66 case TAMALV2: | |
67 infg = property->infg; | |
68 memcpy(tama_lv2, property->tama_lv2, sizeof(tama2)*(tama_lv2_end+1)); | |
69 break; | |
70 | |
71 case TAMALV3: | |
72 infg = property->infg; | |
73 break; | |
74 | |
75 case LASERLV1: | |
76 infg = property->infg; | |
77 memcpy(laser_lv1, property->laser_lv1, sizeof(laser)*laser_lv1_end+1); | |
78 break; | |
79 | 91 |
80 case LASERLV2: | 92 alloc_task->set_cpu(SPE_0); |
81 lg.stg -= 26; | 93 alloc_task->spawn(); |
82 infg = property->infg; | 94 } |
83 break; | |
84 | |
85 case LASERLV3: | |
86 infg = property->infg; | |
87 | 95 |
88 break; | 96 HTaskPtr |
97 collision_update() | |
98 { | |
99 update_task = tmanager->create_task(DataUpdate); | |
100 CollisionPropertyPtr property = get_property(); | |
89 | 101 |
90 default: | 102 update_task->set_param(0, (memaddr)1); |
91 break; | 103 update_task->set_param(1, (memaddr)COLLDATA); |
92 } | |
93 | 104 |
94 ObjContainer *new_obj = (ObjContainerPtr)obj; | 105 update_task->set_inData(0, property, sizeof(CollisionProperty)); |
95 | |
96 if (new_obj->flag == true){ | |
97 ObjDataPtr obj_data = new_obj->data; | |
98 Bom(obj_data->x, obj_data->y); | |
99 | 106 |
100 enemycount += property->enemycount; | 107 update_task->set_post(after_free, (void*)property, NULL); |
101 } | 108 update_task->set_cpu(SPE_0); |
102 | 109 |
103 free(new_obj); | 110 return update_task; |
104 free(prop); | 111 } |
112 | |
113 HTaskPtr | |
114 collision_reflect() | |
115 { | |
116 reflect_task = tmanager->create_task(COLLDATA_REFLECT); | |
117 CollisionPropertyPtr property = (CollisionPropertyPtr)tmanager->allocate(sizeof(CollisionProperty)); | |
118 | |
119 reflect_task->set_param(0, (memaddr)COLLDATA); | |
120 | |
121 reflect_task->set_outData(0, property, sizeof(CollisionProperty)); | |
122 | |
123 reflect_task->set_post(reflect_property, (void*)property, NULL); | |
124 reflect_task->set_cpu(SPE_0); | |
125 | |
126 return reflect_task; | |
127 } | |
128 | |
129 void | |
130 collision_free() | |
131 { | |
132 HTaskPtr free_task = tmanager->create_task(DataFree); | |
133 | |
134 free_task->set_param(0, (memaddr)COLLDATA); | |
135 | |
136 free_task->set_cpu(SPE_0); | |
137 free_task->spawn(); | |
105 } | 138 } |
106 | 139 |
107 | 140 |
108 CHARACTER* | 141 CHARACTER* |
109 atari(CHARACTER *p) | 142 atari(CHARACTER *p) |
110 { | 143 { |
111 int w, h, charno; | 144 int w, h, charno; |
112 CollisionPropertyPtr property = get_property(p); | |
113 | 145 |
114 charno = p->charano; | 146 charno = p->charano; |
115 w = sptable[charno].w; | 147 w = sptable[charno].w; |
116 h = sptable[charno].h; | 148 h = sptable[charno].h; |
117 | 149 |
122 | 154 |
123 HTaskPtr collision_task = tmanager->create_task(ATARI); | 155 HTaskPtr collision_task = tmanager->create_task(ATARI); |
124 | 156 |
125 collision_task->set_param(0,(memaddr)w); | 157 collision_task->set_param(0,(memaddr)w); |
126 collision_task->set_param(1,(memaddr)h); | 158 collision_task->set_param(1,(memaddr)h); |
159 collision_task->set_param(2, (memaddr)COLLDATA); | |
127 | 160 |
128 collision_task->set_inData(0, property, sizeof(CollisionProperty)); | 161 collision_task->set_inData(0, p, sizeof(player)); |
129 collision_task->set_inData(1, &jiki, sizeof(player)); | |
130 collision_task->set_inData(2, &lg, sizeof(stge)); | |
131 collision_task->set_inData(3, &infg, sizeof(stge)); | |
132 collision_task->set_inData(4, &infg_level, sizeof(int)); | |
133 collision_task->set_inData(5, &tama_lv1_end, sizeof(int)); | |
134 collision_task->set_inData(6, &tama_lv2_end, sizeof(int)); | |
135 collision_task->set_inData(7, &laser_lv1_end, sizeof(int)); | |
136 | 162 |
137 collision_task->set_outData(0, property, sizeof(CollisionProperty)); | 163 collision_task->set_outData(0, p, sizeof(player)); |
138 collision_task->set_outData(1, obj, sizeof(ObjContainer)); | 164 collision_task->set_outData(1, obj, sizeof(ObjContainer)); |
139 | 165 |
140 collision_task->set_post(free_property, (void*)property, (void*)obj); | 166 collision_task->set_post(after_free, (void*)obj, NULL); |
141 collision_task->set_cpu(SPE_ANY); | 167 collision_task->set_cpu(SPE_0); |
168 | |
169 collision_task->wait_for(update_task); | |
170 reflect_task->wait_for(collision_task); | |
171 | |
142 collision_task->spawn(); | 172 collision_task->spawn(); |
143 | 173 |
144 return p; | 174 return p; |
145 } | 175 } |