Mercurial > hg > Members > koba > t_dandy
view state_task.cc @ 55:2c33aa6a4a37
debug global_alloc.but new bugs appear
author | koba <koba@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 28 Jan 2011 19:05:00 +0900 |
parents | 3acdeb3dc3e8 |
children | a80422eb44a9 |
line wrap: on
line source
#include <stdio.h> #include <stdlib.h> #include <SDL.h> #include "SDL_opengl.h" #include "object.h" #include "Character.h" #include "Character_state.h" #include "tokuten.h" #include "collision.h" #include "bom.h" #include "count2.h" #include "sgoex.h" #include "sankaku.h" #include "tama.h" #include "TaskManager.h" #include "Func.h" #include "property.h" #include "ObjectType.h" #include "debug_db.h" #include "StateList.h" extern DebugDB dtable[DEFOBJ]; extern SpriteTable sptable[DEFOBJ]; extern TaskManager *tmanager; CHARACTER *kyeenemyno = NULL; CHARACTER *tekino0 = NULL; CHARACTER *enemy_part1 = NULL; CHARACTER *enemy_part2 = NULL; CHARACTER *enemy_part3 = NULL; CHARACTER *enemy_part4 = NULL; CHARACTER *enemy_part5 = NULL; //int tekino0; int rinkx = 0; int rinky = 0; int rinkf1 = 0, rinkf2 = 0; CHARACTER *asteroiddt[200]; int enemyfaste = 0; int fastebos = 0; int asteroidi = 0; static int cpu_counter = SPE_1; /* output 0~3 */ static CPU_TYPE get_cpunum() { cpu_counter += 1; if ((cpu_counter % SPE_5) == 0) { cpu_counter = SPE_1; } return (CPU_TYPE)cpu_counter; } static int power_of_two(int input) { int value = 1; while ( value < input ) { value <<= 1; } return value; } static void ReDefSprite(int number, float w, float h, int color) { SpriteTable *m = &sptable[number]; m->w = w; m->h = h; m->color = (color & 32); m->mx = w / 2; m->my = h / 2; m->tex_w = power_of_two(m->w); m->tex_h = power_of_two(m->h); } void updateState(SchedTask *s, void *chara, void *arg) { CHARACTER *p = (CHARACTER*)chara; int num = GetStateNum(p->task); p->state = state_list[num].state; } void PrintCoordinate(SchedTask *s, void *chara, void *arg) { CHARACTER *p = (CHARACTER*)chara; printf("x = %f, y = %f, vx = %f, vy = %f\n",p->x, p->y, p->vx, p->vy); int num = GetStateNum(p->task); p->state = state_list[num].state; } void freeObject(SchedTask *s, void *chara, void *obj) { free(obj); CHARACTER *p = (CHARACTER*)chara; int num = GetStateNum(p->task); p->state = state_list[num].state; } void checkContainer(SchedTask *s, void *chara, void *obj) { CHARACTER *p = (CHARACTER*)chara; ObjContainer *new_obj = (ObjContainerPtr)obj; if (new_obj->flag == true) { int length = new_obj->length; for (int i=0; i < length; i++) { ObjDataPtr obj_data = &new_obj->data[i]; int type = obj_data->type; switch (type) { case Boms: Bom(obj_data->x, obj_data->y); break; case Tama: Puttama(obj_data->tama_type, obj_data->x, obj_data->y); break; case Enemy: { int task_num = GetStateNum(obj_data->task); Putenemy(obj_data->charano, obj_data->x, obj_data->y, obj_data->vx, obj_data->vy, state_list[task_num].state); break; } case Def: ReDefSprite(obj_data->number, obj_data->w, obj_data->h, obj_data->color); break; case DefEx: DefSpriteEx(obj_data->number, obj_data->middlex, obj_data->middley); break; case Put: PutSprite(obj_data->zorder, obj_data->x, obj_data->y, obj_data->number); break; case PutEx: PutSpriteEx(obj_data->number, obj_data->x, obj_data->y, obj_data->scalex, obj_data->scaley, obj_data->angle); break; } } } int num = GetStateNum(p->task); p->state = state_list[num].state; free(new_obj); } CHARACTER* SimpleStateTask(CHARACTER *p) { int task_num = p->task; HTaskPtr state_task = tmanager->create_task(task_num); state_task->set_inData(0, p, sizeof(CHARACTER)); state_task->set_outData(0, p, sizeof(CHARACTER)); state_task->set_post(updateState, (void*)p, NULL); state_task->set_cpu(get_cpunum()); state_task->spawn(); return p; } static int myrand = 1; CHARACTER* FixRandomTask(CHARACTER *p) { int task_num = p->task; HTaskPtr state_task = tmanager->create_task(task_num); state_task->set_param(0, (memaddr)myrand); state_task->set_inData(0, p, sizeof(CHARACTER)); state_task->set_outData(0, p, sizeof(CHARACTER)); state_task->set_post(PrintCoordinate, (void*)p, NULL); state_task->set_cpu(get_cpunum()); state_task->spawn(); return p; } CHARACTER* withJikiTask(CHARACTER *p) { int task_num = p->task; HTaskPtr state_task = tmanager->create_task(task_num); state_task->set_inData(0, p, sizeof(CHARACTER)); state_task->set_inData(1, &jiki, sizeof(player)); state_task->set_outData(0, p, sizeof(CHARACTER)); state_task->set_post(updateState, (void*)p, NULL); state_task->set_cpu(get_cpunum()); state_task->spawn(); return p; } CHARACTER* sendContainerTask(CHARACTER *p) { int task_num = p->task; int obj_size = sizeof(ObjContainer)+sizeof(ObjData)*DATA_LENGTH; HTaskPtr state_task = tmanager->create_task(task_num); ObjContainerPtr obj = (ObjContainerPtr)tmanager->allocate(obj_size); obj->flag = false; obj->length = 0; state_task->set_inData(0, p, sizeof(CHARACTER)); state_task->set_outData(0, p, sizeof(CHARACTER)); state_task->set_outData(1, obj, 0); state_task->set_post(checkContainer, (void*)p, (void*)obj); state_task->set_cpu(get_cpunum()); state_task->spawn(); return p; } CHARACTER* JikiContainerTask(CHARACTER *p) { int task_num = p->task; int obj_size = sizeof(ObjContainer)+sizeof(ObjData)*DATA_LENGTH; HTaskPtr state_task = tmanager->create_task(task_num); ObjContainerPtr obj = (ObjContainerPtr)tmanager->allocate(obj_size); obj->flag = false; obj->length = 0; state_task->set_inData(0, p, sizeof(CHARACTER)); state_task->set_inData(1, &jiki, sizeof(player)); state_task->set_outData(0, p, sizeof(CHARACTER)); state_task->set_outData(1, obj, 0); state_task->set_post(checkContainer, (void*)p, (void*)obj); state_task->set_cpu(get_cpunum()); state_task->spawn(); return p; } CHARACTER* AsteroidTask(CHARACTER *p) { asteroiddt[asteroidi] = p; int task_num = ASTEROID_TASK; HTaskPtr state_task = tmanager->create_task(task_num); state_task->set_param(0, (memaddr)asteroidi); state_task->set_inData(0, p, sizeof(CHARACTER)); state_task->set_outData(0, p, sizeof(CHARACTER)); int array_size = sizeof(CHARACTER)*asteroidi; if (array_size > 0) { CHARACTER *asteroid_array = (CHARACTER*)tmanager->allocate(array_size); for (int i = 0; i < asteroidi; i++) { asteroid_array[i] = *asteroiddt[i]; } state_task->set_inData(1, asteroid_array, array_size); state_task->set_post(freeObject, (void*)p, (void*)asteroid_array); } else { state_task->set_post(updateState, (void*)p, NULL); } state_task->set_cpu(get_cpunum()); state_task->spawn(); asteroidi++; return p; } CHARACTER* Boss1Task1(CHARACTER *p) { int task_num = p->task; int obj_size = sizeof(ObjContainer)+sizeof(ObjData)*DATA_LENGTH; HTaskPtr state_task = tmanager->create_task(task_num); ObjContainerPtr obj = (ObjContainerPtr)tmanager->allocate(obj_size); obj->flag = false; obj->length = 0; state_task->set_inData(0, p, sizeof(CHARACTER)); state_task->set_inData(1, &count, sizeof(int)); state_task->set_outData(0, p, sizeof(CHARACTER)); state_task->set_outData(1, &count, sizeof(int)); state_task->set_outData(2, obj, 0); state_task->set_post(checkContainer, (void*)p, (void*)obj); state_task->set_cpu(get_cpunum()); state_task->spawn(); return p; } CHARACTER* Boss1Task2(CHARACTER *p) { int task_num = p->task; int obj_size = sizeof(ObjContainer)+sizeof(ObjData)*DATA_LENGTH; HTaskPtr state_task = tmanager->create_task(task_num); ObjContainerPtr obj = (ObjContainerPtr)tmanager->allocate(obj_size); obj->flag = false; obj->length = 0; state_task->set_inData(0, p, sizeof(CHARACTER)); state_task->set_inData(1, &count, sizeof(int)); state_task->set_outData(0, p, sizeof(CHARACTER)); state_task->set_outData(1, &count, sizeof(int)); state_task->set_outData(2, &rinkx, sizeof(int)); state_task->set_outData(3, &rinky, sizeof(int)); state_task->set_outData(4, obj, 0); state_task->set_post(checkContainer, (void*)p, (void*)obj); state_task->set_cpu(get_cpunum()); state_task->spawn(); return p; } CHARACTER* Boss1Task3(CHARACTER *p) { int task_num = p->task; HTaskPtr state_task = tmanager->create_task(task_num); state_task->set_param(0, (memaddr)rinkx); state_task->set_param(1, (memaddr)rinky); state_task->set_inData(0, p, sizeof(CHARACTER)); state_task->set_outData(0, p, sizeof(CHARACTER)); state_task->set_outData(1, &rinkf1, sizeof(int)); state_task->set_post(updateState, (void*)p, NULL); state_task->set_cpu(get_cpunum()); state_task->spawn(); return p; } CHARACTER* Boss1Task4(CHARACTER *p) { int task_num = p->task; int obj_size = sizeof(ObjContainer)+sizeof(ObjData)*DATA_LENGTH; HTaskPtr state_task = tmanager->create_task(task_num); ObjContainerPtr obj = (ObjContainerPtr)tmanager->allocate(obj_size); obj->flag = false; obj->length = 0; state_task->set_param(0, (memaddr)rinkf1); state_task->set_param(1, (memaddr)count); state_task->set_inData(0, p, sizeof(CHARACTER)); state_task->set_outData(0, p, sizeof(CHARACTER)); state_task->set_outData(1, &count, sizeof(int)); state_task->set_outData(2, obj, 0); state_task->set_post(checkContainer, (void*)p, (void*)obj); state_task->set_cpu(get_cpunum()); state_task->spawn(); return p; } CHARACTER* Boss1Task5(CHARACTER *p) { int task_num = p->task; int obj_size = sizeof(ObjContainer)+sizeof(ObjData)*DATA_LENGTH; HTaskPtr state_task = tmanager->create_task(task_num); ObjContainerPtr obj = (ObjContainerPtr)tmanager->allocate(obj_size); obj->flag = false; obj->length = 0; state_task->set_param(0, (memaddr)fastebos); state_task->set_param(1, (memaddr)count); state_task->set_param(2, (memaddr)rinkx); state_task->set_param(3, (memaddr)rinky); state_task->set_inData(0, p, sizeof(CHARACTER)); state_task->set_inData(1, &jiki, sizeof(player)); state_task->set_outData(0, p, sizeof(CHARACTER)); state_task->set_outData(1, &count, sizeof(int)); state_task->set_outData(2, &fastebos, sizeof(int)); state_task->set_outData(3, &rinkx, sizeof(int)); state_task->set_outData(4, &rinky, sizeof(int)); state_task->set_outData(5, &rinkf2, sizeof(int)); state_task->set_outData(6, obj, 0); state_task->set_post(checkContainer, (void*)p, (void*)obj); state_task->set_cpu(get_cpunum()); state_task->spawn(); return p; } CHARACTER* Boss1Task6(CHARACTER *p) { int task_num = p->task; int obj_size = sizeof(ObjContainer)+sizeof(ObjData)*DATA_LENGTH; HTaskPtr state_task = tmanager->create_task(task_num); ObjContainerPtr obj = (ObjContainerPtr)tmanager->allocate(obj_size); obj->flag = false; obj->length = 0; state_task->set_param(0, (memaddr)rinkx); state_task->set_param(1, (memaddr)rinky); state_task->set_param(2, (memaddr)filpcount); state_task->set_param(3, (memaddr)tekino0->f); state_task->set_param(4, (memaddr)count); state_task->set_inData(0, p, sizeof(CHARACTER)); state_task->set_inData(1, &rinkf2, sizeof(int)); state_task->set_outData(0, p, sizeof(CHARACTER)); state_task->set_outData(1, &count, sizeof(int)); state_task->set_outData(2, obj, 0); state_task->set_post(checkContainer, (void*)p, (void*)obj); state_task->set_cpu(get_cpunum()); state_task->spawn(); return p; } CHARACTER* Boss2Task1(CHARACTER *p) { int task_num = p->task; int obj_size = sizeof(ObjContainer)+sizeof(ObjData)*DATA_LENGTH; HTaskPtr state_task = tmanager->create_task(task_num); ObjContainerPtr obj = (ObjContainerPtr)tmanager->allocate(obj_size); obj->flag = false; obj->length = 0; state_task->set_param(0, (memaddr)enemy_part1->f); state_task->set_param(1, (memaddr)enemy_part5->f); state_task->set_param(2, (memaddr)myrand); state_task->set_inData(0, p, sizeof(CHARACTER)); state_task->set_inData(1, &count, sizeof(int)); state_task->set_inData(2, &rinkx, sizeof(int)); state_task->set_inData(3, &rinkf1, sizeof(int)); state_task->set_outData(0, p, sizeof(CHARACTER)); state_task->set_outData(1, &count, sizeof(int)); state_task->set_outData(2, &rinkx, sizeof(int)); state_task->set_outData(3, &rinkf1, sizeof(int)); state_task->set_outData(4, obj, 0); state_task->set_post(checkContainer, (void*)p, (void*)obj); state_task->set_cpu(get_cpunum()); state_task->spawn(); return p; } CHARACTER* Boss2Task2(CHARACTER *p, int num1, int num2) { int task_num = p->task; int obj_size = sizeof(ObjContainer)+sizeof(ObjData)*DATA_LENGTH; HTaskPtr state_task = tmanager->create_task(task_num); ObjContainerPtr obj = (ObjContainerPtr)tmanager->allocate(obj_size); obj->flag = false; obj->length = 0; state_task->set_param(0, (memaddr)enemy_part1->f); state_task->set_param(1, (memaddr)enemy_part2->f); state_task->set_param(2, (memaddr)enemy_part3->f); state_task->set_param(3, (memaddr)enemy_part4->f); state_task->set_param(4, (memaddr)enemystate[num1].charano); state_task->set_param(5, (memaddr)enemystate[num2].charano); state_task->set_param(6, (memaddr)myrand); state_task->set_inData(0, p, sizeof(CHARACTER)); state_task->set_inData(1, kyeenemyno, sizeof(CHARACTER)); state_task->set_inData(2, &count, sizeof(int)); state_task->set_inData(3, &rinkf1, sizeof(int)); state_task->set_outData(0, p, sizeof(CHARACTER)); state_task->set_outData(1, &count, sizeof(int)); state_task->set_outData(2, obj, 0); state_task->set_post(checkContainer, (void*)p, (void*)obj); state_task->set_cpu(get_cpunum()); state_task->spawn(); return p; } CHARACTER* Boss4Task(CHARACTER *p) { kyeenemyno = p; int task_num = p->task; int obj_size = sizeof(ObjContainer)+sizeof(ObjData)*DATA_LENGTH; HTaskPtr state_task = tmanager->create_task(task_num); ObjContainerPtr obj = (ObjContainerPtr)tmanager->allocate(obj_size); obj->flag = false; obj->length = 0; state_task->set_param(0, (memaddr)myrand); state_task->set_inData(0, p, sizeof(CHARACTER)); state_task->set_inData(1, &count, sizeof(int)); state_task->set_outData(0, p, sizeof(CHARACTER)); state_task->set_outData(1, &count, sizeof(int)); state_task->set_outData(2, obj, 0); state_task->set_post(checkContainer, (void*)p, (void*)obj); state_task->set_cpu(get_cpunum()); state_task->spawn(); return p; } CHARACTER* Boss5Task(CHARACTER *p) { int task_num = p->task; int obj_size = sizeof(ObjContainer)+sizeof(ObjData)*DATA_LENGTH; HTaskPtr state_task = tmanager->create_task(task_num); ObjContainerPtr obj = (ObjContainerPtr)tmanager->allocate(obj_size); obj->flag = false; obj->length = 0; state_task->set_param(0, (memaddr)myrand); state_task->set_inData(0, p, sizeof(CHARACTER)); state_task->set_inData(1, &jiki, sizeof(player)); state_task->set_outData(0, p, sizeof(CHARACTER)); state_task->set_outData(1, obj, 0); state_task->set_post(checkContainer, (void*)p, (void*)obj); state_task->set_cpu(get_cpunum()); state_task->spawn(); return p; } CHARACTER* noaction(CHARACTER *p) { return p; } CHARACTER* delete_chara(CHARACTER *p) { if (p->tama == FALSE) { printf("F%d: DELETE [NAME]%s_%d [COORD]x= %f y= %f vx= %f vy= %f\n", filpcount, dtable[p->charano].name, p->chara_id, p->x, p->y, p->vx, p->vy); printf(" [TAMA]lv1 = %d, lv2 = %d [LASER]lv1 = %d\n", tama_lv1_end, tama_lv2_end, laser_lv1_end); } CHARACTER *parent = p; p->f = FALSE; p->state = noaction; p->collision = noaction; return parent; } CHARACTER* chara_state0(CHARACTER *p) { p->task = STATE0; return SimpleStateTask(p); } CHARACTER* chara_state1(CHARACTER *p) { p->task = STATE1; return SimpleStateTask(p); } CHARACTER* chara_state2(CHARACTER *p) { p->task = STATE2; return SimpleStateTask(p); } CHARACTER* chara_state3(CHARACTER *p) { p->task = STATE3; return sendContainerTask(p); } CHARACTER* chara_state4(CHARACTER *p) { p->task = STATE4; return withJikiTask(p); } CHARACTER* chara_state5(CHARACTER *p) { p->task = STATE5; return withJikiTask(p); } CHARACTER* chara_state6(CHARACTER *p) { p->task = STATE6; return withJikiTask(p); } CHARACTER* chara_state7(CHARACTER *p) { p->task = STATE7; return sendContainerTask(p); } // state1 boss patern CHARACTER* chara_state8(CHARACTER *p) { tekino0 = p; kyeenemyno = p; p->task = STATE8; return Boss1Task1(p); } CHARACTER* chara_state9(CHARACTER *p) { p->task = STATE9; return Boss1Task2(p); } CHARACTER* chara_state10(CHARACTER *p) { p->task =STATE10; return Boss1Task3(p); } CHARACTER* chara_state11(CHARACTER *p) { p->task = STATE11; return Boss1Task4(p); } CHARACTER* chara_state12(CHARACTER *p) { p->task = STATE12; return Boss1Task5(p); } CHARACTER* chara_state13(CHARACTER *p) { p->task = STATE13; return Boss1Task6(p); } CHARACTER* chara_state20(CHARACTER *p) { p->task = STATE20; return SimpleStateTask(p); } CHARACTER* chara_state21(CHARACTER *p) { p->task = STATE21; return SimpleStateTask(p); } //ここまでgetate boss CHARACTER* chara_state22(CHARACTER *p) { p->task = STATE22; return FixRandomTask(p); } CHARACTER* chara_state23(CHARACTER *p) { p->task = STATE23; return AsteroidTask(p); } CHARACTER* chara_state24(CHARACTER *p) { kyeenemyno = p; tekino0 = 0; enemy_part1 = p->next; enemy_part2 = enemy_part1->next; enemy_part3 = enemy_part2->next; enemy_part4 = enemy_part3->next; enemy_part5 = enemy_part4->next; rinkx = 0; rinky = 0; rinkf1 = 0; rinkf2 = 0; p->task = STATE25; int num = GetStateNum(p->task); p->state = state_list[num].state; return p; } CHARACTER* chara_state25(CHARACTER *p) { p->task = STATE25; return Boss2Task1(p); } CHARACTER* chara_state26(CHARACTER *p) { p->task = STATE26; return Boss2Task1(p); } CHARACTER* chara_state27(CHARACTER *p) //rocket punch { p->task = STATE27; return Boss2Task1(p); } CHARACTER* chara_state28(CHARACTER *p) { p->task = STATE28; return Boss2Task1(p); } CHARACTER* chara_state29(CHARACTER *p) { p->task = STATE29; return sendContainerTask(p); } CHARACTER* chara_state30(CHARACTER *p) { p->task = STATE30; return SimpleStateTask(p); } CHARACTER* chara_state31(CHARACTER *p) //right hand { p->task = STATE31; return Boss2Task2(p, 0, 0); } CHARACTER* chara_state32(CHARACTER *p) //left hand { p->task = STATE32; return Boss2Task2(p, 14, 20); } CHARACTER* chara_state33(CHARACTER *p) // right shoulder { p->task = STATE33; return Boss2Task2(p, 11, 19); } CHARACTER* chara_state34(CHARACTER *p) //left shoulder { p->task = STATE34; return Boss2Task2(p, 12, 21); } CHARACTER* chara_state35(CHARACTER *p) // bust { p->task = STATE35; return Boss2Task2(p, 15, 16); } CHARACTER* chara_state40(CHARACTER *p) //arm vulkan { p->task = STATE40; return Boss2Task2(p, 0, 0); } CHARACTER* chara_state41(CHARACTER *p) //left arm up arm vulkan { p->task = STATE41; return Boss2Task2(p, 0, 0); } CHARACTER* chara_state400(CHARACTER *p) { p->task = STATE400; return SimpleStateTask(p); } CHARACTER* chara_state401(CHARACTER *p) { p->task = STATE401; return JikiContainerTask(p); } CHARACTER* chara_state402(CHARACTER *p) { p->task = STATE402; return JikiContainerTask(p); } CHARACTER* chara_state410(CHARACTER *p) { kyeenemyno = p; p->task = STATE411; int num = GetStateNum(p->task); p->state = state_list[num].state; return p; } CHARACTER* chara_state411(CHARACTER *p) { p->task = STATE411; return JikiContainerTask(p); } CHARACTER* chara_state500(CHARACTER *p) { p->task = STATE500; return Boss4Task(p); } CHARACTER* chara_state501(CHARACTER *p) { p->task = STATE501; return sendContainerTask(p); } CHARACTER* chara_state600(CHARACTER *p) { kyeenemyno = p; p->task = STATE600; return sendContainerTask(p); } CHARACTER* chara_state601(CHARACTER *p) { p->task = STATE601; return Boss5Task(p); } CHARACTER* chara_state602(CHARACTER *p) { p->task = STATE602; return Boss5Task(p); }