# HG changeset patch # User koba # Date 1292313339 -32400 # Node ID 9a92435eaee6bca93890fc8240948d19ccf46b52 # Parent c9e9b605f08e59d5ebd3153021c5320862b39fe5 divide SG Dandy and Task Dandy. diff -r c9e9b605f08e -r 9a92435eaee6 Character_state.c --- a/Character_state.c Tue Dec 14 15:29:13 2010 +0900 +++ b/Character_state.c Tue Dec 14 16:55:39 2010 +0900 @@ -29,8 +29,6 @@ CHARACTER *asteroiddt[200]; int asteroidi = 0; int enemyfaste = 0; -int sf; -int amari; int fastebos = 0; CHARACTER * noaction(CHARACTER *p) @@ -417,6 +415,8 @@ CHARACTER * chara_state22(CHARACTER *p) { + int sf; + sf = rand() % 4; if((sf == 0) || (sf == 1)) { @@ -470,6 +470,8 @@ CHARACTER * chara_state25(CHARACTER *p) { + int amari; + if(p->dt1 <= 360) { p->x = Mycos(p->dt1) * 30 / SANKAKU + 82 + 32; diff -r c9e9b605f08e -r 9a92435eaee6 Dandy.cc --- a/Dandy.cc Tue Dec 14 15:29:13 2010 +0900 +++ b/Dandy.cc Tue Dec 14 16:55:39 2010 +0900 @@ -50,7 +50,6 @@ static int gamesyokika(int gamef); static int game_pause(int); -extern void task_init(); //static char *pad_trace_file; /** @@ -125,6 +124,12 @@ return next; }; +void +task_init() +{ + +} + int TMmain(TaskManager *manager,int argc, char *argv[]) { diff -r c9e9b605f08e -r 9a92435eaee6 Makefile --- a/Makefile Tue Dec 14 15:29:13 2010 +0900 +++ b/Makefile Tue Dec 14 16:55:39 2010 +0900 @@ -22,18 +22,18 @@ test: $(TARGET) ./demo -test -demo: $(OBJS) sgoex.o main.o collision.o - $(CC) $(ABI) -o $@ main.o sgoex.o collision.o $(OBJS) $(LIBS) +demo: $(OBJS) main.o collision.o sgoex.o + $(CC) $(ABI) -o $@ main.o collision.o sgoex.o $(OBJS) $(LIBS) dandy: $(OBJS) Dandy.o collision.o $(CC) $(ABI) -o $@ $(OBJS) Dandy.o collision.o $(LIBS) -t_dandy: $(OBJS) $(TASK_OBJS) collision_task.o Dandy.o - $(CC) $(ABI) -o $@ $(OBJS) $(TASK_OBJS) collision_task.o Dandy.o $(LIBS) +t_dandy: $(OBJS) $(TASK_OBJS) TaskDandy.o state_task.o collision_task.o + $(CC) $(ABI) -o $@ $(OBJS) $(TASK_OBJS) TaskDandy.o state_task.o collision_task.o $(LIBS) clean: rm -f $(TARGET) $(OBJS) $(TASK_OBJS) - rm -f Dandy.o collision.o sgoex.o collision_task.o main.o + rm -f main.o TaskDandy.o collision.o state_task.o collision_task.o sgoex.o .c.o: $(CC) $(CFLAGS) $(INCLUDES) -c $< diff -r c9e9b605f08e -r 9a92435eaee6 TaskDandy.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TaskDandy.cc Tue Dec 14 16:55:39 2010 +0900 @@ -0,0 +1,803 @@ +#include "Dandy.h" +#include +#include +#include +#include +#include +#include +#include +#include "SDL_opengl.h" +#include "object.h" +#include "tree_controll.h" +#include "xml.h" +#include "profile.h" +#include "syokika.h" +#include "sankaku.h" +#include "sgoex.h" +#include "sound.h" +#include "bool.h" +#include "bom.h" +#include "count2.h" +#include "tokuten.h" +#include "schedule.h" +#include "tama.h" +#include "debug.h" +#include "trace.h" +#include "LoadSprite.h" +#include +#include "error.h" +#include "matrix_calc.h" +#include "Character.h" +#include "Character_state.h" +#include "property.h" + +int use_keybord = 0; +int cdp[20] = { 16, 16, 16, 17, 18, 0 }; +int d, i; + +int rswait = 0; +int cf = 0; +int cc = 0; + +//static SDL_Surface *screen; +// static Uint32 background; +// static char *pad_trace_file; + +extern void schedule(); +extern void tokuten(); +extern void Pad(); +extern void keybord(); +static int gamesyokika(int gamef); +static int game_pause(int); + +extern void task_init(); +//static char *pad_trace_file; + +/** + * runmode: + * 0 - normal game + * 1 - capture mode + * program will capture all pad traces on a play and + * dump it into a file + * 2 - trace mode + * program will run with a trace file which is generated + * by capture-mode + */ +int runmode; + +SDL_Joystick *joy; + + + +const char *usr_help_str = "Usage: ./twice [-length data_length] [-count task_num]\n\ + -length Number of data (default DATA_NUM (Func.h))\n\ + -count Number of task (default 1)\n"; + +static Viewer *sgroot; + +TaskManager *tmanager; + +static int screen_w; +static int screen_h; + +MainLoopPtr +Dandy::init(Viewer *sgroot_, int w, int h) +{ + screen_w = w; + screen_h = h; + sgroot = sgroot_; + tmanager = sgroot->manager; + return sgroot; +} + +Application * +application() { + return new Dandy(); +} + + +static int opening(int gamef); +static int dandy_closing(int gamef); +static int dandy_main_loop(int gamef); +static int dandy_main_init(int gamef); +extern int init(TaskManager *manager, int argc, char *argv[]); +extern void task_initialize(); +static void TMend(TaskManager *manager); + +bool +Dandy::app_loop(Viewer *viewer){ + // don't use allExecute + return 0; +}; + +static int gamef = 0; + +HTaskPtr +Dandy::application_task(HTaskPtr next, Viewer* viewer){ + // printf("gamef = %d\n",gamef); + switch (gamef) { + case 0: gamef= dandy_main_init(gamef); break; + case 1: gamef= gamesyokika(gamef); break; + case 2: gamef= opening(gamef); break; + case 3: gamef= dandy_main_loop(gamef); break; + case 4: gamef= dandy_closing(gamef); break; + } + return next; +}; + +int +TMmain(TaskManager *manager,int argc, char *argv[]) +{ + task_init(); + task_initialize(); + manager->set_TMend(TMend); + + return init(manager,argc, argv); +} + +void +TMend(TaskManager *manager) +{ + printf("game end\n"); +} + +static int light_sysswitch = 1; +static int light_num = 4; + +static void +_LightSysSwitch(Viewer *sgroot) { + if (light_sysswitch == 1) { + sgroot->OnLightSysSwitch(); + for (int i = 0; i < light_num; i++) { + SceneGraphPtr light = sgroot->getLight(i); + sgroot->OnLightSwitch(i); + light->xyz[0] = screen_w / 2; + light->xyz[1] = screen_h / 2; + light->xyz[2] = -100; + } + } else if (light_sysswitch == 0) { + sgroot->OffLightSysSwitch(); + } +} + + +static int +dandy_main_init(int gamef) +{ + //Timeprof timeprof_move; + //timeprof_move = timeprof_new(); + dbg_init("/dev/stdout"); + + /** + * timeprof があるんだけどね + */ + + sgroot->createFromXMLfile("xml/character.xml"); + sgroot->createFromXMLfile("xml/font.xml"); + sgroot->createFromXMLfile("xml/effect.xml"); + sgroot->createFromXMLfile("xml/boss.xml"); + + _LightSysSwitch(sgroot); + + init_sprite(0,0,0,0); + + __debug("syokikaが呼びだされました\n"); + joy=SDL_JoystickOpen(0); + if(!joy) { + fprintf(stderr,"failed to open joystick 0\n"); + use_keybord = 1; + } + + /** + * sound.c に移しました + * 代わりに InitSdlMixer(void); を使います。 + * まあ中身一緒なんだけどね + */ + /** + if (Mix_OpenAudio(MIX_DEFAULT_FREQUENCY,MIX_DEFAULT_FORMAT,2,1024) < 0) { + fprintf(stderr,"failed to initialize SDL_mixer.\n"); + SDL_Quit(); + exit(-1); + } + */ + + // SDL_mixer とかいろいろ初期化 + // もし Init に失敗したら + // 以後の Mixer 関連の関数を呼び出しても + // 中では何も行われないとかいう小細工を入れました。 + InitSdlMixer(); + + // 音楽ファイルの読み込み + LoadSdlMixer(); + + // ボリューム調整 + InitVolume(); + + // 音出しテスト + PlaySdlMixer(-1, BGM); + + if(!(init_chara_list(1024))){ + __debug("failed to init_chara_list\n"); + } + + __debug("finished init_chara_list\n"); + + return 1; +} + +SceneGraphPtr root; + +// extern void get_matrix(float *matrix, float *rxyz, float *txyz, float *scale, float *stack); + +static void +flip() +{ + CameraPtr camera = sgroot->sgroot->getCamera(); + + sgroot->sgroot->flip(); + sgroot->sgroot->lightCalc(); + + root = sgroot->createSceneGraph(); + root->xyz[0] = screen_w/2; + root->xyz[1] = screen_h/2;; + root->xyz[2] = 30.0f; + + /*親の回転、座標から、子の回転、座標を算出*/ + get_matrix(root->matrix, root->angle, root->xyz, root->scale, camera->matrix); + /*法線用の行列。Cameraの行列を抜いている(Cameraのコンストラクタで、単位行列にしている)*/ + get_matrix(root->real_matrix, root->angle, root->xyz, root->scale, camera->real_matrix); + + sgroot->setSceneData(root); +} + + +static int +dandy_main_loop(int gamef) +{ + if ((pad[0].l1 != 0) && (pad[0].r1 != 0) && + (pad[0].l2 != 0) && (pad[0].r2 != 0)) { + gamef = gamesyokika(gamef); + } + + if (pad[0].quit != 0) { + gamef = 4; + } + flip(); + + //SDL_FillRect(screen, NULL, background); + + schedule(); + enemyfaste = count; + + // timeprof_begin(timeprof_move); + //Move(); //enemy move + collision_detect(); + outofwindow(); + // timeprof_end(timeprof_move); + state_update(); + asteroidi = 0; + //charpatern(); + //bosguage(); + + if (jiki.bf == TRUE) { + Player(0); + count++; + PutSprite(count, jiki.x, jiki.y, jiki.ch); + } + + Putbom(); + tokuten(); + + count++; + //PutSprite(count, 0, 960 - 96, 10); + /*インフレゲージ */ + count++; + //PutSprite(count, 0, 0, 48); + + obj_draw(); + gamef = game_pause(gamef); + + if (use_keybord) { + keybord(); + } else { + Pad(joy); + } + filpcount++; + count = 0; + + return gamef; +} + +static int +dandy_closing(int gamef) +{ + + //_______________________________________________ + // SDL_mixerの後始末 + Mix_CloseAudio(); + Mix_HaltMusic(); + FreeSdlMixer() ; + //_______________________________________________ + return 0; +} + + +static int +gamesyokika(int gamef) +{ + laser_lv3[0].r = 62; + laser_lv3[0].r = 62; + for (i = 0; i < 3; i++) { + tlv3[i].y = -1; + } + filpcount = 0; + stage = 0; + //for (i = 0; i < 300; i++) + //enemy[i].f = FALSE; + jiki.zanki = 3; + jiki.x = 60; + jiki.y = 200; + jiki.ch = 3; + jiki.point = 0; + jiki.bf = FALSE; + jiki.muteki = 120; + enemycount = 0; + lg.stg = 4096; + pg.stg = 4096; + infg.stg = 0; + infg_level = 0; + //kyeenemyno = -1; + fastebos = 0; + jiki.ccount = 99; + p_extend = 200000; + pad[0].up=0; + pad[0].down=0; + pad[0].right=0; + pad[0].left=0; + pad[0].st=0; + pad[0].se=0; + + SoundStop(); + SoundPlay(7); + gamef = 2; + flip(); + return gamef; +} + +static int +opening(int gamef) +{ + if(use_keybord == 1) { + keybord(); + } else { + Pad(joy); + } + + count = 1; + + PutSprite(count, 700, 480, 53); // put `push start' string on screen. + count++; + PutSprite(count, 224, 776, 119); // put `super dandy' + count++; + // PutSprite(count, 200, 64, 190); + // PutSpriteEx(count, 8192, 8192, 0); + PutSpriteEx(190, 800, 264, 2, 2, 5); + count++; + PutSprite(count, 396, 432, 191); + //PutSpriteEx(count, 8192, 8192, 0); + count++; + PutSprite(count, 640, 640, 192); + //PutSpriteEx(count, 8192, 8192, 0); + + if (pad[0].st > 1) { + jiki.bf = TRUE; + + //CdPlay(1,&cdp[0],0); + SoundStop(); + SoundPlay(0); + + gamef = 3; + pad[0].st = 1; + } else if ((pad[0].se > 0) && (pad[0].st > 0)) { + gamef = 2; + } + flip(); + return gamef; +} + +static int +game_pause(int gamef) +{ + gamef = 3; + if (jiki.zanki != 0 && jiki.bf != FALSE) { + if (pad[0].se == 1) { + //Mix_Pause(BGM); + PauseSdlMixer(BGM); + while(1){ + if(use_keybord == 1) { + keybord(); + } else { + Pad(joy); + } + if(pad[0].st == 0) + continue; + pad[0].up=0; + pad[0].down=0; + pad[0].right=0; + pad[0].left=0; + pad[0].se=0; + pad[0].st=0; + //Mix_Resume(BGM); + ResumeSdlMixer(BGM); + break; + } + } + } + if (jiki.zanki == 0) { + // RECT *recp; + if ((jiki.ccount > 0) && (cf == 0)) { + cf = 1; + count++; + //cgcg(2); + PutSprite(2, 480, 480, 110); + count++; + //cgcg(1); + } + if ((jiki.ccount > 0) && (cf == 1)) { + while (1) { + if (pad[0].st > 0) { + cf = 0; + jiki.ccount--; + jiki.zanki = 3; + enemycount++; + cc = 0; + for (i = 0; i < 4; i++) { + clear_result[i] = 0; + } + goto f; + } + cc++; + if (29 - cc / 60 < 20) { + cc = 0; + cf = 3; + break; + } + SDL_Delay(100); + PutSprite(1, 640, 640, 29 - cc / 60); + // PutSpriteEx(1, 409 * ((cc % 60) + 1), 409 * ((cc % 60) + 1), 0); + + Pad(joy); + flip(); // this is not correct + } + } + if (rswait > 60 * 6) { + cf = 0; + rswait = 0; + gamef = gamesyokika(gamef); + } + rswait++; + count++; + //cgcg(1); + PutSprite(1, 480, 480, 19); + return gamef; + } + if (jiki.bf == FALSE) { + f: + if (rswait < 80) { + rswait++; + return gamef; + } else { + rswait = 0; + jiki.x = 60; + jiki.y = 200; + jiki.bf = TRUE; + + pad[0].st = 0; + lg.stg = 4096; + pg.stg = 4096; + laser_lv3[0].r = 62; + tlv3[0].r = 0; + tlv3[0].y = -1; + return gamef; + // sb_size = -1; + } + } + return gamef; +} + + +SpriteTable sptable[DEFOBJ]; + + +void +DefSpriteEx(int number, short middlex, short middley) +{ + sptable[number].mx = middlex; + sptable[number].my = middley; +} + + +void +DefSprite(int number, const char *name, float w, float h, int color, OBJECT *obj) +{ + 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(sptable[number].w); + m->tex_h = power_of_two(sptable[number].h); + //texMinX[number] = 0.0f; + //texMinY[number] = 0.0f; + //texMaxX[number] = (GLfloat)sptable[number].w / sptable[number].tex_w; + //texMaxY[number] = (GLfloat)sptable[number].h / sptable[number].tex_h; + // printf("texMaxX = %f, w = %d, tex_w = %d\n", texMaxX[number], sptable[number].w, sptable[number].tex_w); + m->texture = (int *)name; + +} + +void +PutSprite(int zorder, short x, short y, int number) +{ + SpriteTable *m = &sptable[number]; + char *name = (char *) m->texture; +if (!name) { + printf("PutSprite %d unknown\n",number); + return; +} + SceneGraphPtr object = sgroot->createSceneGraph(name); + object->xyz[0] = x; + object->xyz[1] = y; + object->xyz[2] = 0; + root->addChild(object); + + float scale[] = {5,5,1}; + /*親の回転、座標から、子の回転、座標を算出*/ + get_matrix(object->matrix, object->angle, object->xyz, scale, root->matrix); + /*法線用の行列。Cameraの行列を抜いている(Cameraのコンストラクタで、単位行列にしている)*/ + get_matrix(object->real_matrix, object->angle, object->xyz, scale, root->real_matrix); + +} + +void +PutSpriteEx(int number, int x, int y, float scalex, float scaley, float angle) +{ + SpriteTable *m = &sptable[number]; + char *name = (char *) m->texture; +if (!name) { + printf("PutSpriteEx %d unknown\n",number); + return; +} + SceneGraphPtr object = sgroot->createSceneGraph(name); + object->xyz[0] = x; + object->xyz[1] = y; + object->xyz[2] = 0; + object->c_xyz[0] = m->mx; + object->c_xyz[1] = m->my; + object->angle[3] = angle; + root->addChild(object); + + float scale[] = {5*scalex,5*scaley,1}; + /*親の回転、座標から、子の回転、座標を算出*/ + get_matrix(object->matrix, object->angle, object->xyz, scale, root->matrix); + /*法線用の行列。Cameraの行列を抜いている(Cameraのコンストラクタで、単位行列にしている)*/ + get_matrix(object->real_matrix, object->angle, object->xyz, scale, root->real_matrix); +} + + +struct SGO_PAD pad[2]; + + +/* コントローラ状態の読み込み */ +void Pad(SDL_Joystick *joy) +{ + Sint16 axis; + + SDL_JoystickUpdate(); + + if(SDL_JoystickGetButton(joy,PS2_CROSS)==SDL_PRESSED) + pad[0].k0++; + else + pad[0].k0=0; + + if(SDL_JoystickGetButton(joy,PS2_CIRCLE)==SDL_PRESSED) + pad[0].k1++; + else + pad[0].k1=0; + + if(SDL_JoystickGetButton(joy,PS2_SQUARE)==SDL_PRESSED) + pad[0].k3++; + else + pad[0].k3=0; + + if(SDL_JoystickGetButton(joy,PS2_TRIANGLE)==SDL_PRESSED) + pad[0].k4++; + else + pad[0].k4=0; + + if(SDL_JoystickGetButton(joy,PS2_L1)==SDL_PRESSED) + pad[0].l1++; + else + pad[0].l1=0; + + if(SDL_JoystickGetButton(joy,PS2_R1)==SDL_PRESSED) + pad[0].r1++; + else + pad[0].r1=0; + + if(SDL_JoystickGetButton(joy,PS2_L2)==SDL_PRESSED) + pad[0].l2++; + else + pad[0].l2=0; + + if(SDL_JoystickGetButton(joy,PS2_R2)==SDL_PRESSED) + pad[0].r2++; + else + pad[0].r2=0; + + if(SDL_JoystickGetButton(joy,PS2_START)==SDL_PRESSED) + pad[0].st++; + else + pad[0].st=0; + + if(SDL_JoystickGetButton(joy,PS2_SELECT)==SDL_PRESSED) + pad[0].se++; + else + pad[0].se=0; + + if(SDL_JoystickGetButton(joy,PS2_L3)==SDL_PRESSED) + pad[0].l3++; + else + pad[0].l3=0; + + if(SDL_JoystickGetButton(joy,PS2_R3)==SDL_PRESSED) + pad[0].r3++; + else + pad[0].r3=0; + //x + axis=SDL_JoystickGetAxis(joy,0); + if(axis>=3200){ + pad[0].left=0; + pad[0].right++; + } + else if(axis<=-3200){ + pad[0].right=0; + pad[0].left++; + } + else { + pad[0].right=0; + pad[0].left=0; + } + //y + axis=SDL_JoystickGetAxis(joy,1); + if(axis>=3200){ + pad[0].up=0; + pad[0].down++; + } + else if(axis<=-3200){ + pad[0].down=0; + pad[0].up++; + } + else { + pad[0].down=0; + pad[0].up=0; + } + + if ((pad[0].l1 != 0) && (pad[0].r1 != 0) && + (pad[0].l2 != 0) && (pad[0].r2 != 0) && + (pad[0].st != 0) && (pad[0].se != 0)) { + pad[0].quit = 1; + } else { + pad[0].quit = 0; + } + +} + + +void keybord() +{ + SDL_PumpEvents(); + Uint8 *keys = SDL_GetKeyState(NULL); + + if (keys[SDLK_UP]) { + pad[0].up++; + } else { + pad[0].up = 0; + } + if (keys[SDLK_DOWN]) { + pad[0].down++; + } else { + pad[0].down = 0; + } + + if (keys[SDLK_RIGHT]) { + pad[0].right++; + } else { + pad[0].right = 0; + } + + if (keys[SDLK_LEFT]) { + pad[0].left++; + } else { + pad[0].left = 0; + } + + if (keys[SDLK_a]) { + pad[0].k0++; + } else { + pad[0].k0 = 0; + } + + if (keys[SDLK_z]) { + pad[0].k1++; + } else { + pad[0].k1 = 0; + } + + if (keys[SDLK_s]) { + pad[0].k3++; + } else { + pad[0].k3 = 0; + } + + if (keys[SDLK_x]) { + pad[0].k4++; + } else { + pad[0].k4 = 0; + } + + if (keys[SDLK_r]) { + pad[0].r2++; + } else { + pad[0].r2 = 0; + } + + if (keys[SDLK_e]) { + pad[0].r1++; + } else { + pad[0].r1 = 0; + } + + if (keys[SDLK_w]) { + pad[0].l1++; + } else { + pad[0].l1 = 0; + } + + if (keys[SDLK_q]) { + pad[0].l2++; + } else { + pad[0].l2 = 0; + } + + // START ボタンは Return が似合う気がする + //if(keys[SDLK_1]) + if (keys[SDLK_RETURN]) { + pad[0].st++; + } else { + pad[0].st = 0; + } + + if (keys[SDLK_2]) { + pad[0].se++; + } else { + pad[0].se = 0; + } + + if (keys[SDLK_ESCAPE]) { + SDL_Quit(); + exit(1); + //pad[0].st = 1; + //pad[0].se = 1; + } + + if (keys[SDLK_0]) { + pad[0].quit = 1; + } else { + pad[0].quit = 0; + } +} + + +/* end */ diff -r c9e9b605f08e -r 9a92435eaee6 game_task.h --- a/game_task.h Tue Dec 14 15:29:13 2010 +0900 +++ b/game_task.h Tue Dec 14 16:55:39 2010 +0900 @@ -1,2 +1,3 @@ // Game で使用する Task ID ATARI, + SIMPLE_STATE, diff -r c9e9b605f08e -r 9a92435eaee6 ppe/Character_state.h --- a/ppe/Character_state.h Tue Dec 14 15:29:13 2010 +0900 +++ b/ppe/Character_state.h Tue Dec 14 16:55:39 2010 +0900 @@ -1,3 +1,9 @@ +#ifndef INCLUDE_CHARACTER_STATE +#define INCLUDE_CHARACTER_STATE + +#ifndef INCLUDE_OBJECT +#include "tobject.h" +#endif CHARACTER * noaction(CHARACTER *p); CHARACTER * chara_state0(CHARACTER *p); @@ -47,3 +53,5 @@ extern int enemyfaste; extern int fastebos; extern int asteroidi; + +#endif diff -r c9e9b605f08e -r 9a92435eaee6 ppe/task_init.cc --- a/ppe/task_init.cc Tue Dec 14 15:29:13 2010 +0900 +++ b/ppe/task_init.cc Tue Dec 14 16:55:39 2010 +0900 @@ -3,6 +3,7 @@ /* 必ずこの位置に書いて */ SchedExternTask(Atari); +SchedExternTask(SimpleState); /** * この関数は ../spe/spe-main と違って @@ -13,4 +14,5 @@ task_init(void) { SchedRegisterTask(ATARI, Atari); + SchedRegisterTask(SIMPLE_STATE, SimpleState); }