view collision_task.cc @ 53:b31bed246abd

fix code and add log.
author koba <koba@cr.ie.u-ryukyu.ac.jp>
date Tue, 25 Jan 2011 17:43:30 +0900
parents 6989f8cb0259
children 3acdeb3dc3e8
line wrap: on
line source

#include <stdio.h>
#include <stdlib.h>
#include <SDL.h>
#include "SDL_opengl.h"
#include "Character.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;

static CollisionPropertyPtr
get_property(CHARACTER *p)
{
    CollisionPropertyPtr property = (CollisionPropertyPtr)tmanager->allocate(sizeof(CollisionProperty));

    property->collision_type = NO;
    property->enemycount = 0;
    property->tlv3 = tlv3[0];
    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)
{
    CollisionPropertyPtr property = (CollisionPropertyPtr)prop;

    switch(property->collision_type) {
	check_collision();

    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;

    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;

    case LASERLV2:
	lg.stg -= 26;
	infg = property->infg;
	break;
	
    case LASERLV3:
	infg = property->infg;

	break;

    default:
	break;
    }

    ObjContainer *new_obj = (ObjContainerPtr)obj;
    
    if (new_obj->flag == true){
	ObjDataPtr obj_data = new_obj->data;
	Bom(obj_data->x, obj_data->y);

	enemycount += property->enemycount;
    }

    free(new_obj);
    free(prop);
}


CHARACTER*
atari(CHARACTER *p)
{
    int w, h, charno;
    CollisionPropertyPtr property = get_property(p);

    charno = p->charano;
    w = sptable[charno].w;
    h = sptable[charno].h;

    int obj_size = sizeof(ObjContainer);
    ObjContainerPtr obj = (ObjContainerPtr)tmanager->allocate(obj_size);
    obj->flag = false;
    obj->length = 0;

    HTaskPtr collision_task = tmanager->create_task(ATARI);

    collision_task->set_param(0,(memaddr)w);
    collision_task->set_param(1,(memaddr)h);

    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_outData(0, property, sizeof(CollisionProperty));
    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->spawn();

    return p;
}