// samplmanager.c.h // mfstdlib.h //reference thingno // sample index // volume sample_vol_max, // pan sample_pan_center // freq sample_freq_orig, signed offset from base // priority slong /* SAVE INGAME store data 4 Pap_Hi -> 98304 tot 98304 (16384) Pap_Lo -> 8192 tot 106496 (1024) net_peep -> 40 tot 106536 (10) net_plyr -> 40 tot 106576 (10) f-links -> 11450 tot 118026 (5725/32000) dbuildings -> 4848 tot 122874 (202/1024) dfacets -> 76180 tot 199054 (2930/16384) dwalkables -> 6468 tot 205522 (294/2048) dstyles -> 9356 tot 214878 (4678/10000) dstoreys -> 3360 tot 218238 (560/10000) paintmem -> 2446 tot 220684 (2446/64000) insideStoreys -> 110 tot 220794 (5/2000) insideStairs -> 20 tot 220814 (2/8000) insideblock -> 709 tot 221523 (709/64000) roof bounds -> 6 tot 221529 (1/2000) prim_points -> 99930 tot 321459 (16655/65000) prim_faces4 -> 195330 tot 516789 (5745/32760) prim_faces3 -> 151928 tot 668717 (5426/32000) prim_objects -> 7536 tot 676253 (471/2000) prim_Mobjects -> 120 tot 676373 (15/100) ob_ob -> 9296 tot 685669 (1162/2048) ob_ mapwho -> 2048 tot 687717 (1024) EWAY_mess -> 492 tot 688209 (123/128) EWAY_mess buf -> 4457 tot 692666 (4457/8192) EWAY_timer -> 0 tot 692666 (32) EWAY_cond -> 114 tot 692780 (19/128) EWAY_way -> 15136 tot 707916 (473/512) EWAY_edef -> 1488 tot 709404 (124/150) vehicles -> 9024 tot 718428 (48) people -> 21600 tot 740028 (150) animals -> 120 tot 740148 (6) choppers -> 336 tot 740484 (4) pyro -> 5376 tot 745860 (64) players -> 1216 tot 747076 (8) projectiles -> 240 tot 747316 (10) special -> 2880 tot 750196 (80) switches -> 440 tot 750636 (10) bats -> 1024 tot 751660 (32) thing -> 45120 tot 796780 (752) drawtween -> 9360 tot 806140 (180) drawmesh -> 5000 tot 811140 (500) bike -> 640 tot 811780 (8) barrelsphere -> 4200 tot 815980 (150) barrels -> 354 tot 816334 (59/150) plat -> 12 tot 816346 (1/32) wmove -> 4608 tot 820954 (192) mav_opt -> 2820 tot 823774 (705/1024) mav_nav -> 32768 tot 856542 (16384) road_noads -> 150 tot 856692 (25/256) balloons -> 104 tot 856796 (1/32) tracks -> 9600 tot 866396 (300) roofface4 -> 38900 tot 905296 (3890/10000) fastnav -> 2048 tot 907344 (2048) night_slight -> 1968 tot 909312 (246/256) night_smap -> 2048 tot 911360 (1024) night_dlight -> 768 tot 912128 (64) WARE_ware -> 32 tot 912160 (1/32) WARE_nav -> 0 tot 912160 (0/4096) WARE_height -> 0 tot 912160 (0/8192) WARE_rooftex -> 0 tot 912160 (0/4096) Trip_Wire -> 14 tot 912174 (1/32) Road_edges -> 0 tot 912174 (0/8) Thing_heads -> 38 tot 912212 (19) psx_remap -> 256 tot 912468 (128) psx_tex_xy -> 2000 tot 914468 (1000) */ //#include "Editor.hpp" #include "stdio.h" #include "game.h" //#include "engine.h" #include "animate.h" #include "cop.h" #include "io.h" //#include "prim_draw.h" #include "memory.h" //poostruct GameKeyFrameElement gamekeyframeelements[MAX_NUMBER_OF_ELEMENTS]; #ifdef EDITOR extern struct KeyFrameChunk edit_chunk1,edit_chunk2; extern struct KeyFrameElement *elements_bank1,*elements_bank2; #endif SLONG build_psx=0; //save_psx extern SLONG save_psx; #define NROPER_ANIM_YOMP (1) #define NROPER_ANIM_STAND_READY (2) #define NROPER_ANIM_BREATHE (3) #define NROPER_ANIM_RUNNING_JUMP (4) #define NROPER_ANIM_RUNNING_JUMP_FLY (5) #define NROPER_ANIM_RUNNING_JUMP_LAND (6) #define NROPER_ANIM_RUNNING_JUMP_LAND_RUN (7) #define NROPER_ANIM_DRAW_GUN (8) #define NROPER_ANIM_GUN_AIM (9) #define NROPER_ANIM_GUN_SHOOT (10) #define NROPER_ANIM_LISTEN (11) #define NROPER_ANIM_JUMP_SPOT_TAKEOFF (12) #define NROPER_ANIM_JUMP_SPOT_LAND (13) #define NROPER_ANIM_JUMP_SPOT_STATIC (14) #define NROPER_ANIM_TELL (15) #define NROPER_ANIM_SHOTGUN_TAKEOUT (16) #define NROPER_ANIM_SHOTGUN_SHOOT (17) //#define NROPER_ANIM_SHOTGUN_AIM (18) #define NROPER_ANIM_SWIG_FLASK (19) #define NROPER_ANIM_YOMP_START (20) #define NROPER_ANIM_AK_TAKEOUT (21) #define NROPER_ANIM_AK_SHOOT (22) #define NROPER_ANIM_AK_AIM (23) #define NROPER_ANIM_AK_AIM_L (24) #define NROPER_ANIM_AK_AIM_R (25) #define NROPER_ANIM_SHOTGUN_AIM (26) #define NROPER_ANIM_SHOTGUN_AIM_L (27) #define NROPER_ANIM_SHOTGUN_AIM_R (28) #define NROPER_ANIM_GUN_AIM_L (30) #define NROPER_ANIM_GUN_AIM_R (31) #define NROPER_ANIM_WALK_BACKWARDS (46) #define NROPER_ANIM_RUN_WITH_AK (47) #define NROPER_ANIM_WALK_BACKWARDS_WITH_AK (48) #define NROPER_PICKUP_CARRY (34) #define NROPER_START_WALK_CARRY (35) #define NROPER_WALK_CARRY (36) #define NROPER_WALK_STOP_CARRY (37) #define NROPER_PUTDOWN_CARRY (38) #define NROPER_PICKUP_CARRY_V (39) #define NROPER_START_WALK_CARRY_V (40) #define NROPER_WALK_CARRY_V (41) #define NROPER_WALK_STOP_CARRY_V (42) #define NROPER_PUTDOWN_CARRY_V (43) #define NROPER_STAND_CARRY (44) #define NROPER_STAND_CARRY_V (45) #define NROPER_TO_WALL (49) #define NROPER_TO_WALL_STATIC (65) #define NROPER_TO_WALL_SHOTGUN (50) #define NROPER_ALONG_WALL (51) #define NROPER_ALONG_WALL_B (52) #define NROPER_ALONG_WALL_SHOTGUN (53) #define NROPER_ALONG_WALL_SHOTGUN_B (54) #define NROPER_ALONG_WALL_SHOTGUN_C (61) #define NROPER_ALONG_WALL_SHOTGUN_D (62) #define NROPER_AIM_WALL_SHOTGUN (55) #define NROPER_AIM_WALL_SHOTGUN_B (56) #define NROPER_AIM_WALL_PISTOL (57) #define NROPER_AIM_WALL_PISTOL_B (63) #define NROPER_AIM_WALL_PISTOL_C (64) #define NROPER_FIGHT_WALL (60) #define NROPER_TWO_PISTOL_DRAW (76) #define NROPER_TWO_PISTOL_FIRE (77) #define NROPER_TWO_PISTOL_AWAY (78) #define NROPER_TWO_PISTOL_RUN (72) #define NROPER_TWO_PISTOL_AIM (90) #define NROPER_TWO_PISTOL_AIM_L (79) #define NROPER_TWO_PISTOL_AIM_R (80) #define NROPER_TWO_PISTOL_CROUCH (87) #define NROPER_TWO_PISTOL_CROUCH_HOLD (88) #define NROPER_TWO_PISTOL_CROUCH_STAND_UP (89) #define NROPER_SHOTGUN_CROUCH (84) #define NROPER_SHOTGUN_CROUCH_HOLD (85) #define NROPER_SHOTGUN_CROUCH_STAND_UP (86) #define NROPER_ANIM_SHOTGUN_RUN (74) #define NROPER_ANIM_SHOTGUN_START_RUN (82) #define NROPER_ANIM_CLIMB_OVER_FENCE (91) UWORD next_prim_point=1; UWORD next_prim_face4=1; UWORD next_prim_face3=1; UWORD next_prim_object=1; UWORD next_prim_multi_object=1; UBYTE roper_pickup=0; void set_next_prim_point(SLONG v) { next_prim_point=v; } //UWORD matrix_index_pool[MAX_MATRIX_POOL]; //struct AnimItem anim_index[MAX_CREATURE_TYPES][MAX_ANIMS_PER_CREATURE]; #if defined(PSX) || defined(TARGET_DC) struct PrimMultiAnim prim_multi_anims[1]; #else struct PrimMultiAnim prim_multi_anims[10000]; #endif UWORD next_prim_multi_anim=1; #ifndef PSX void ANIM_init(void) { SLONG c0; for(c0=0;c0Pad = 0; // need to store the two smallest elements of the top row for accuracy SBYTE a, b, c; a = ((cm->M[0] & CMAT0_MASK) >> 22); b = ((cm->M[0] & CMAT1_MASK) >> 12); c = ((cm->M[0] & CMAT2_MASK) >> 02); if (abs(a) > abs(b)) { if (abs(a) > abs(c)) { e->m00 = b; e->m01 = c; e->Pad |= 0; if (a < 0) e->Pad |= 1; } else { e->m00 = a; e->m01 = b; e->Pad |= 4; if (c < 0) e->Pad |= 1; } } else { if (abs(b) > abs(c)) { e->m00 = a; e->m01 = c; e->Pad |= 8; if (b < 0) e->Pad |= 1; } else { e->m00 = a; e->m01 = b; e->Pad |= 4; if (c < 0) e->Pad |= 1; } } a = ((cm->M[1] & CMAT0_MASK) >> 22); b = ((cm->M[1] & CMAT1_MASK) >> 12); c = ((cm->M[1] & CMAT2_MASK) >> 02); if (abs(a) > abs(b)) { if (abs(a) > abs(c)) { e->m10 = b; e->m11 = c; e->Pad |= 0; if (a < 0) e->Pad |= 2; } else { e->m10 = a; e->m11 = b; e->Pad |= 16; if (c < 0) e->Pad |= 2; } } else { if (abs(b) > abs(c)) { e->m10 = a; e->m11 = c; e->Pad |= 32; if (b < 0) e->Pad |= 2; } else { e->m10 = a; e->m11 = b; e->Pad |= 16; if (c < 0) e->Pad |= 2; } } } void convert_to_psx_gke(GameKeyFrameElementComp *to, GameKeyFrameElement *from) { to->OffsetX=(from->OffsetX);//&0xff; to->OffsetY=(from->OffsetY);//&0xff; to->OffsetZ=(from->OffsetZ);//&0xff; SetCMatrixComp(to, &from->CMatrix); } #endif #ifdef ULTRA_COMPRESSED_ANIMATIONS //JCL //! this could be halved in size(ish) -> symmetrical about diagonal SBYTE UCA_Lookup[256][256]; void UCA_LookupSetup() { SLONG c0; SLONG c1; for (c0 = -128; c0 < 128; c0 ++) for (c1 = -128; c1 < 128; c1 ++) UCA_Lookup[(UBYTE)c0][(UBYTE)c1] = Root(16383 - ((c0 * c0) + (c1 * c1))); } #ifndef PSX void SetCMatrix(GameKeyFrameElement *e, CMatrix33 *cm) { e->Pad = 0; // need to store the two smallest elements of the top row for accuracy SBYTE a, b, c; a = ((cm->M[0] & CMAT0_MASK) >> 22); b = ((cm->M[0] & CMAT1_MASK) >> 12); c = ((cm->M[0] & CMAT2_MASK) >> 02); if (abs(a) > abs(b)) { if (abs(a) > abs(c)) { e->m00 = b; e->m01 = c; e->Pad |= 0; if (a < 0) e->Pad |= 1; } else { e->m00 = a; e->m01 = b; e->Pad |= 4; if (c < 0) e->Pad |= 1; } } else { if (abs(b) > abs(c)) { e->m00 = a; e->m01 = c; e->Pad |= 8; if (b < 0) e->Pad |= 1; } else { e->m00 = a; e->m01 = b; e->Pad |= 4; if (c < 0) e->Pad |= 1; } } a = ((cm->M[1] & CMAT0_MASK) >> 22); b = ((cm->M[1] & CMAT1_MASK) >> 12); c = ((cm->M[1] & CMAT2_MASK) >> 02); if (abs(a) > abs(b)) { if (abs(a) > abs(c)) { e->m10 = b; e->m11 = c; e->Pad |= 0; if (a < 0) e->Pad |= 2; } else { e->m10 = a; e->m11 = b; e->Pad |= 16; if (c < 0) e->Pad |= 2; } } else { if (abs(b) > abs(c)) { e->m10 = a; e->m11 = c; e->Pad |= 32; if (b < 0) e->Pad |= 2; } else { e->m10 = a; e->m11 = b; e->Pad |= 16; if (c < 0) e->Pad |= 2; } } } #endif void GetCMatrix(GameKeyFrameElement *e, CMatrix33 *cm) { SLONG a, b, c; SLONG m00, m01, m02; SLONG m10, m11, m12; SLONG data; data=*((SLONG*)e); a=(data<<24)>>24; b=(data<<16)>>24; // ASSERT(a==e->m00); // ASSERT(b==e->m01); // DebugText(" AA a = %d b =%d \n",a,b); // a = e->m00; //if(a > 127) a -= 256; // b = e->m01; //if(b > 127) b -= 256; DebugText("BB a = %d b =%d \n",a,b); c = UCA_Lookup[(UBYTE)a][(UBYTE)b]; if (e->Pad & 1) c = -c; if ((e->Pad & 12) == 0) { m00 = c; m01 = a; m02 = b; } else if ((e->Pad & 12) == 4) { m00 = a; m01 = b; m02 = c; } else if ((e->Pad & 12) == 8) { m00 = a; m01 = c; m02 = b; } a=(data<<8)>>24; b=(data<<0)>>24; // ASSERT(a==e->m10); // ASSERT(b==e->m11); // DebugText(" CC a = %d b =%d \n",a,b); // a = e->m10; //if(a > 127) a -= 256; // b = e->m11; //if(b > 127) b -= 256; // DebugText(" DD a = %d b =%d \n",a,b); c = UCA_Lookup[(UBYTE)a][(UBYTE)b]; if (e->Pad & 2) c = -c; if ((e->Pad & 48) == 0) { m10 = c; m11 = a; m12 = b; } else if ((e->Pad & 48) == 16) { m10 = a; m11 = b; m12 = c; } else if ((e->Pad & 48) == 32) { m10 = a; m11 = c; m12 = b; } // // cross product PSX_OPT // SLONG m20 = ((m01 * m12) >> 7) - ((m02 * m11) >> 7); SLONG m21 = ((m02 * m10) >> 7) - ((m00 * m12) >> 7); SLONG m22 = ((m00 * m11) >> 7) - ((m01 * m10) >> 7); // damn.... if (m20 > 127) m20 =127; //-= m20 - 127; if (m20 < -127) m20 =-127; //+= m20 + 127; if (m21 > 127) m21 =127; //-= m21 - 127; if (m21 < -127) m21 =-127; //+= m21 + 127; if (m22 > 127) m22 =127; //-= m22 - 127; if (m22 < -127) m22 = -127; //+= m22 + 127; cm->M[0] = ((m00 << 22) & CMAT0_MASK) + ((m01 << 12) & CMAT1_MASK) + ((m02 << 02) & CMAT2_MASK); cm->M[1] = ((m10 << 22) & CMAT0_MASK) + ((m11 << 12) & CMAT1_MASK) + ((m12 << 02) & CMAT2_MASK); cm->M[2] = ((m20 << 22) & CMAT0_MASK) + ((m21 << 12) & CMAT1_MASK) + ((m22 << 02) & CMAT2_MASK); } #endif //************************************************************************************************ void convert_anim(Anim *key_list,GameKeyFrameChunk *p_chunk,KeyFrameChunk *the_chunk); #ifndef PSX void init_anim_prims(void) { SLONG c0; for(c0=0;c0MultiObject=0; test_chunk->ElementCount=0; // MemFree(test_chunk); } #ifdef EDITOR if(elements_bank1) MemFree(elements_bank1); if(elements_bank2) MemFree(elements_bank2); #endif // if(the_elements) // MemFree(the_elements); } #ifdef EDITOR void load_anim(MFFileHandle file_handle,Anim *the_anim,KeyFrameChunk *the_chunk) { CBYTE anim_name[ANIM_NAME_SIZE]; SLONG anim_flags, c0, frame_count, frame_id, tween_step; KeyFrame *the_frame; SWORD chunk_id; SWORD fixed=0; CBYTE version=0; FileRead(file_handle,&version,1); if(version==0||version>20) { anim_name[0]=version; FileRead(file_handle,&anim_name[1],ANIM_NAME_SIZE-1); version=0; } else FileRead(file_handle,anim_name,ANIM_NAME_SIZE); FileRead(file_handle,&anim_flags,sizeof(anim_flags)); FileRead(file_handle,&frame_count,sizeof(frame_count)); the_anim->SetAnimName(anim_name); if(version>3) { UBYTE speed; FileRead(file_handle,&speed,1); the_anim->SetTweakSpeed(speed); } else the_anim->SetTweakSpeed(128); for(c0=0;c00) FileRead(file_handle,&fixed,sizeof(fixed)); the_frame = &the_chunk->KeyFrames[frame_id]; the_frame->TweenStep = tween_step; the_frame->Fixed = fixed; the_frame->Fight = 0; if(version>1) { struct FightCol *fcol,*fcol_prev=0; SLONG count,c0; FileRead(file_handle,&count,sizeof(count)); // LogText(" fight count load = %d \n",count); for(c0=0;c0Fight=fcol; } else { fcol_prev->Next=fcol; } fcol_prev=fcol; } } } the_anim->AddKeyFrame(the_frame); the_frame->Fight=0; } the_anim->SetAnimFlags(anim_flags); if(anim_flags&ANIM_LOOP) the_anim->StartLooping(); } Anim *current_anim; void create_anim(Anim **the_list) { CBYTE text[32]; Anim *next_anim, *the_anim; the_anim = MFnew(); if(the_anim) { // anim_count++; // sprintf(text,"New Anim %d",anim_count); // the_anim->SetAnimName(text); if(*the_list) { next_anim = *the_list; while(1) { if(next_anim->GetNextAnim()) next_anim = next_anim->GetNextAnim(); else break; } next_anim->SetNextAnim(the_anim); the_anim->SetLastAnim(next_anim); } else { *the_list = the_anim; } current_anim = the_anim; } } void load_body_part_info(MFFileHandle file_handle,SLONG version,KeyFrameChunk *the_chunk) { SLONG c0,c1; SLONG no_people,no_body_bits,string_len; FileRead(file_handle,&no_people,sizeof(SLONG)); FileRead(file_handle,&no_body_bits,sizeof(SLONG)); FileRead(file_handle,&string_len,sizeof(SLONG)); for(c0=0;c0PeopleNames[c0],string_len); for(c1=0;c1PeopleTypes[c0].BodyPart[c1],sizeof(UBYTE)); } } void load_all_anims(KeyFrameChunk *the_chunk,Anim **anim_list) { //#ifdef EDITOR SLONG anim_count,version, c0; MFFileHandle file_handle; file_handle = FileOpen(the_chunk->ANMName); if(file_handle!=FILE_OPEN_ERROR) { FileRead(file_handle,&anim_count,sizeof(anim_count)); if(anim_count<0) { version=anim_count; FileRead(file_handle,&anim_count,sizeof(anim_count)); load_body_part_info(file_handle,version,the_chunk); } for(c0=0;c0GetFrameList(); curr = curr->GetNextAnim(); c0++; } } */ #else #ifndef TARGET_DC //extern SLONG load_anim_system(struct GameKeyFrameChunk *game_chunk,CBYTE *name); extern SLONG load_anim_system(struct GameKeyFrameChunk *game_chunk,CBYTE *name,SLONG peep=0); void setup_extra_anims(void) { Anim *key_list; key_list = NULL; /* load_key_frame_chunks(test_chunk,"van.vue"); load_all_anims(test_chunk,&key_list); load_anim_system(&game_chunk[5],"van.all"); */ /* if(key_list) { SLONG c0 = 0; Anim *curr; convert_anim(key_list,&game_chunk[5],test_chunk); // game_chunk[ANIM_TYPE_CIV].MultiObject[0]=test_chunk->MultiObject; // game_chunk[ANIM_TYPE_CIV].ElementCount=test_chunk->ElementCount; // memcpy(game_chunk[ANIM_TYPE_CIV].PeopleTypes,test_chunk->PeopleTypes,sizeof(struct BodyDef)*MAX_PEOPLE_TYPES); save_anim_system(&game_chunk[5],"u:\\urbanchaos\\data\\van.all"); extern void convert_keyframe_to_pointer(GameKeyFrame *p,GameKeyFrameElement *p_ele,GameFightCol *p_fight,SLONG count); extern void convert_animlist_to_pointer(GameKeyFrame **p,GameKeyFrame *p_anim,SLONG count); extern void convert_fightcol_to_pointer(GameFightCol *p,GameFightCol *p_fight,SLONG count); convert_keyframe_to_pointer(game_chunk[5].AnimKeyFrames,game_chunk[5].TheElements,game_chunk[5].FightCols,game_chunk[5].MaxKeyFrames); convert_animlist_to_pointer(game_chunk[5].AnimList,game_chunk[5].AnimKeyFrames,game_chunk[5].MaxAnimFrames); convert_fightcol_to_pointer(game_chunk[5].FightCols,game_chunk[5].FightCols,game_chunk[5].MaxFightCols); curr = key_list; while(curr) { van_array[c0] = curr->GetFrameList(); curr = curr->GetNextAnim(); c0++; } // if(anim_array[ANIM_PUNCH2]) // fix_anim_pos(anim_array[ANIM_PUNCH2],test_chunk); } */ // load_anim_system(&game_chunk[6],"data\\dog2.all"); next_game_chunk=4; } extern UWORD darci_normal_count; extern SLONG append_anim_system(struct GameKeyFrameChunk *p_chunk,CBYTE *name,SLONG start_anim,SLONG load_mesh); void setup_people_anims(void) { #ifdef ULTRA_COMPRESSED_ANIMATIONS UCA_LookupSetup(); #endif setup_anim_stuff(); load_anim_system(&game_chunk[ANIM_TYPE_DARCI],"darci1.all",1); // load_anim_system(&game_chunk[1],"police1.all"); // if(!build_psx) if(save_psx) { if(roper_pickup) { // ASSERT(0); load_anim_system(&game_chunk[ANIM_TYPE_ROPER],"roper_up.all"); } else load_anim_system(&game_chunk[ANIM_TYPE_ROPER],"psxroper.all"); } else { load_anim_system(&game_chunk[ANIM_TYPE_ROPER],"roper.all"); } if(save_psx) load_anim_system(&game_chunk[ANIM_TYPE_CIV],"rthug.all",2); //rpsxthug.all else load_anim_system(&game_chunk[ANIM_TYPE_CIV],"rthug.all",2); if(!save_psx)// || roper_pickup) load_anim_system(&game_chunk[ANIM_TYPE_ROPER2],"roper2.all"); append_anim_system(&game_chunk[ANIM_TYPE_ROPER],"police1.all",200,0); append_anim_system(&game_chunk[ANIM_TYPE_CIV],"newciv.all",CIV_M_START,1); append_anim_system(&game_chunk[ANIM_TYPE_CIV],"newcivf.all",CIV_F_START,1); extern SLONG playing_combat_tutorial(void); extern SLONG playing_level(const CBYTE *name); if(!save_psx) if(playing_combat_tutorial()) { game_chunk[ANIM_TYPE_CIV].MultiObject[0]=next_prim_multi_object; game_chunk[ANIM_TYPE_CIV].MultiObject[1]=next_prim_multi_object; game_chunk[ANIM_TYPE_CIV].MultiObject[2]=next_prim_multi_object; append_anim_system(&game_chunk[ANIM_TYPE_ROPER],"trainer.all",240,1); } if(playing_level("semtex.ucm")) { semtex=1; } else { semtex=0; } if(playing_level("estate2.ucm") || playing_level("Album1.ucm")) { // bodge bodge bodge game_chunk[ANIM_TYPE_CIV].MultiObject[6]=next_prim_multi_object; append_anim_system(&game_chunk[ANIM_TYPE_ROPER],"banesuit.all",240,1); estate=1; } else { estate=0; } darci_normal_count=next_prim_point; } #endif #endif void setup_global_anim_array(void) { // // Make everyone use Darci's animations (including Darci!) // SLONG c0; for(c0=0;c0FirstElement[object]; *x = (anim_info->OffsetX)>>TWEEN_OFFSET_SHIFT; *y = (anim_info->OffsetY)>>TWEEN_OFFSET_SHIFT; *z = (anim_info->OffsetZ)>>TWEEN_OFFSET_SHIFT; } /* void fix_anim_pos(struct KeyFrame *keyframe,struct KeyFrameChunk *chunk) { struct KeyFrame *first_frame; SLONG o_count,c0; SLONG dx,dy,dz; calc_sub_objects_position_no_tween(keyframe,SUB_OBJECT_LEFT_FOOT,&dx,&dy,&dz); o_count=prim_multi_objects[chunk->MultiObject].EndObject-prim_multi_objects[chunk->MultiObject].StartObject; first_frame=keyframe; while(keyframe) { struct KeyFrameElement *the_element; for(c0=0;c0<=o_count;c0++) { the_element=&keyframe->FirstElement[c0]; the_element->OffsetX-=dx; the_element->OffsetY-=dy; the_element->OffsetZ-=dz; } keyframe=keyframe->NextFrame; if(keyframe==first_frame) break; } } */ #ifndef PSX void fix_multi_object_for_anim(UWORD obj,struct PrimMultiAnim *p_anim) { SLONG sp,ep; UWORD c0,c1; struct PrimObject *p_obj; struct Matrix33 *mat; struct Matrix31 temp; #ifdef EDITOR for(c0=prim_multi_objects[obj].StartObject;c0<=prim_multi_objects[obj].EndObject;c0++) { p_obj=&prim_objects[c0]; sp=p_obj->StartPoint; ep=p_obj->EndPoint; for(c1=sp;c1DX; prim_points[c1].Y-=p_anim->DY; prim_points[c1].Z-=p_anim->DZ; } p_anim++; } #endif } //--------------------------------------------------------------- // class Anim //--------------------------------------------------------------- Anim::Anim() { CurrentFrame = NULL; FrameListStart = NULL; FrameListEnd = NULL; FrameCount = 0; LastAnim = NULL; NextAnim = NULL; AnimFlags = 0; } //--------------------------------------------------------------- Anim::~Anim() { while(FrameCount) { CurrentFrame = FrameListStart; FrameListStart = CurrentFrame->NextFrame; if(CurrentFrame) MemFree(CurrentFrame); FrameCount--; } } //--------------------------------------------------------------- void Anim::StartLooping(void) { if(FrameListEnd) { FrameListEnd->NextFrame=FrameListStart; } } void Anim::StopLooping(void) { if(FrameListEnd) { FrameListEnd->NextFrame=0; } } void Anim::SetAllTweens(SLONG tween) { KeyFrame *frame_ptr; frame_ptr=FrameListStart; while(frame_ptr) { frame_ptr->TweenStep=tween; if(frame_ptr==FrameListEnd) break; frame_ptr=frame_ptr->NextFrame; } } //--------------------------------------------------------------- void Anim::AddKeyFrame(KeyFrame *the_frame) { KeyFrame *frame_ptr; if(the_frame) { StopLooping(); frame_ptr = (KeyFrame*)MemAlloc(sizeof(KeyFrame)); ERROR_MSG(frame_ptr,"Unable to allocate memory for key frame."); *frame_ptr = *the_frame; frame_ptr->NextFrame = NULL; frame_ptr->PrevFrame = NULL; frame_ptr->TweenStep = the_frame->TweenStep; frame_ptr->Fight = the_frame->Fight; if(FrameListStart==NULL) { FrameListStart = frame_ptr; FrameListEnd = FrameListStart; FrameListEnd->Flags |= ANIM_FLAG_LAST_FRAME; } else if(CurrentFrame==NULL) { if(FrameListEnd) { FrameListEnd->NextFrame = frame_ptr; frame_ptr->PrevFrame = FrameListEnd; } FrameListEnd->Flags &= ~ANIM_FLAG_LAST_FRAME; FrameListEnd = frame_ptr; FrameListEnd->Flags |= ANIM_FLAG_LAST_FRAME; } else { frame_ptr->PrevFrame = CurrentFrame->PrevFrame; if(CurrentFrame->PrevFrame) CurrentFrame->PrevFrame->NextFrame = frame_ptr; else FrameListStart = frame_ptr; CurrentFrame->PrevFrame = frame_ptr; frame_ptr->NextFrame = CurrentFrame; CurrentFrame = 0; } FrameCount++; if(AnimFlags&ANIM_LOOP) StartLooping(); } } /* // // Untested // void Anim::AppendKeyFrame(KeyFrame *the_frame) { KeyFrame *frame_ptr; if(the_frame) { StopLooping(); frame_ptr = (KeyFrame*)MemAlloc(sizeof(KeyFrame)); ERROR_MSG(frame_ptr,"Unable to allocate memory for key frame."); *frame_ptr = *the_frame; frame_ptr->NextFrame = NULL; frame_ptr->PrevFrame = NULL; frame_ptr->TweenStep = the_frame->TweenStep; frame_ptr->Fight = the_frame->Fight; if(FrameListStart==NULL) { FrameListStart = frame_ptr; FrameListEnd = FrameListStart; FrameListEnd->Flags |= ANIM_FLAG_LAST_FRAME; } else if(CurrentFrame==NULL) { if(FrameListEnd) { FrameListEnd->NextFrame = frame_ptr; frame_ptr->PrevFrame = FrameListEnd; } FrameListEnd->Flags &= ~ANIM_FLAG_LAST_FRAME; FrameListEnd = frame_ptr; FrameListEnd->Flags |= ANIM_FLAG_LAST_FRAME; } else { frame_ptr->PrevFrame = CurrentFrame; frame_ptr->NextFrame = CurrentFrame->NextFrame; if(CurrentFrame->NextFrame ==0) FrameListEnd = frame_ptr; CurrentFrame->NextFrame = frame_ptr; CurrentFrame = 0; } FrameCount++; if(AnimFlags&ANIM_LOOP) StartLooping(); } } */ //--------------------------------------------------------------- void Anim::RemoveKeyFrame(KeyFrame *the_frame) { if(the_frame) { StopLooping(); if(the_frame->NextFrame) { the_frame->NextFrame->PrevFrame = the_frame->PrevFrame; } else { FrameListEnd = the_frame->PrevFrame; if(FrameListEnd) FrameListEnd->Flags = ANIM_FLAG_LAST_FRAME; } if(the_frame->PrevFrame) { the_frame->PrevFrame->NextFrame = the_frame->NextFrame; } else FrameListStart = the_frame->NextFrame; MemFree(the_frame); FrameCount--; if(AnimFlags&ANIM_LOOP) StartLooping(); } } //--------------------------------------------------------------- // class Character //--------------------------------------------------------------- void Character::AddAnim(Anim *the_anim) { } //--------------------------------------------------------------- void Character::RemoveAnim(Anim *the_anim) { } //--------------------------------------------------------------- // // go through all the elements converting them to the compressed matrix format // void convert_elements(KeyFrameChunk *the_chunk,GameKeyFrameChunk *game_chunk,UWORD *p_reloc,SLONG max_ele) { struct KeyFrameElement *first_element; struct KeyFrameElement *last_element; struct KeyFrameElement *element,*e2; SLONG count=0; SLONG unique=0; UWORD pos=0; first_element=the_chunk->FirstElement; last_element=the_chunk->LastElement; for(element=first_element;elementTheElements[pos], &element->CMatrix); game_chunk->TheElements[pos].OffsetX=(SWORD)element->OffsetX; game_chunk->TheElements[pos].OffsetY=(SWORD)element->OffsetY; game_chunk->TheElements[pos].OffsetZ=(SWORD)element->OffsetZ; /* for(e2=first_element;e2TheElements[count].CMatrix,(UBYTE*)&e2->CMatrix,sizeof(struct CMatrix33))==0) { if(e2!=element) { unique--; break; } } } unique++; */ } count++; } game_chunk->MaxElements=max_ele; LogText(" unique matrix count %d out of %d\n",unique,count); } #ifdef EDITOR extern UBYTE unused_flags[]; void convert_anim(Anim *key_list,GameKeyFrameChunk *p_chunk,KeyFrameChunk *the_chunk) { struct KeyFrame *keyframe; struct GameKeyFrame *firstframe,*lastframe; SLONG count_frame=1; SLONG anim_count=1; SLONG fight_count=1; struct FightCol *fight; UWORD *p_reloc; SLONG element_count=0; SLONG elements_per_frame=15; //for humans; DebugText(" convert_anim \n"); elements_per_frame=the_chunk->ElementCount; p_reloc=(UWORD*)MemAlloc(MAX_NUMBER_OF_ELEMENTS*2); memset((UBYTE*)p_reloc,-1,MAX_NUMBER_OF_ELEMENTS*2); if(p_chunk->PeopleTypes==0) { p_chunk->PeopleTypes=(struct BodyDef*)MemAlloc(MAX_PEOPLE_TYPES*sizeof(struct BodyDef)); p_chunk->AnimKeyFrames=(struct GameKeyFrame*)MemAlloc(MAX_NUMBER_OF_FRAMES*sizeof(struct GameKeyFrame)); p_chunk->AnimList=(struct GameKeyFrame**)MemAlloc(400*sizeof(struct GameKeyFrame*)); p_chunk->TheElements=(struct GameKeyFrameElement*)MemAlloc(MAX_NUMBER_OF_ELEMENTS*sizeof(struct GameKeyFrameElement)); p_chunk->FightCols=(struct GameFightCol*)MemAlloc(200*sizeof(struct GameFightCol)); // p_chunk->TweakSpeeds=(struct GameFightCol*)MemAlloc(200); } else { LogText(" chunk mem allready allocated\n"); } key_list=key_list->GetNextAnim(); while(key_list) { SLONG tweak_speed; if(!unused_flags[anim_count]) { keyframe=key_list->GetFrameList(); firstframe=&p_chunk->AnimKeyFrames[count_frame]; p_chunk->AnimList[anim_count]=&p_chunk->AnimKeyFrames[count_frame]; tweak_speed=key_list->GetTweakSpeed(); DebugText("set AnimList[%d]= addr %x count_frame %d\n",anim_count,&p_chunk->AnimKeyFrames[count_frame],count_frame); // ASSERT(anim_count!=130); while(keyframe) { SLONG ele_pos; SLONG reqd_step; reqd_step=((tweak_speed+128)/(keyframe->TweenStep+1))>>1; p_chunk->AnimKeyFrames[count_frame].TweenStep=reqd_step; //keyframe->TweenStep; ele_pos=(UWORD)(keyframe->FirstElement-the_chunk->FirstElement); if(p_reloc[ele_pos]!=0xffff) { ele_pos=p_reloc[ele_pos]; } else { SLONG offset; for(offset=0;offsetAnimKeyFrames[count_frame].FirstElement=&p_chunk->TheElements[ele_pos]; fight=keyframe->Fight; if(fight) { DebugText(" count frame %d fight %d \n",count_frame,fight_count); p_chunk->AnimKeyFrames[count_frame].Fight=&p_chunk->FightCols[fight_count]; } else { p_chunk->AnimKeyFrames[count_frame].Fight=0; } while(fight) { p_chunk->FightCols[fight_count].Dist1=fight->Dist1; p_chunk->FightCols[fight_count].Dist2=fight->Dist2; p_chunk->FightCols[fight_count].Angle=fight->Angle; p_chunk->FightCols[fight_count].Priority=fight->Priority; p_chunk->FightCols[fight_count].Damage=fight->Damage; p_chunk->FightCols[fight_count].Tween=fight->Tween; p_chunk->FightCols[fight_count].AngleHitFrom=fight->AngleHitFrom; p_chunk->FightCols[fight_count].Height=fight->Height; p_chunk->FightCols[fight_count].Width=fight->Width; if(fight->Next) { DebugText("fight next count frame %d fight %d \n",count_frame,fight_count); p_chunk->FightCols[fight_count].Next=&p_chunk->FightCols[fight_count+1]; } else { p_chunk->FightCols[fight_count].Next=0; } fight_count++; fight=fight->Next; } if(count_frame) p_chunk->AnimKeyFrames[count_frame].PrevFrame=&p_chunk->AnimKeyFrames[count_frame-1]; p_chunk->AnimKeyFrames[count_frame].NextFrame=&p_chunk->AnimKeyFrames[count_frame+1]; // p_chunk->AnimKeyFrames[count_frame].Fixed=keyframe->Fixed; p_chunk->AnimKeyFrames[count_frame].Flags=0; // p_chunk->AnimKeyFrames[count_frame].Fight=keyframe->Fight; if(keyframe->Flags&ANIM_FLAG_LAST_FRAME) { DebugText(" anim %d ends at frame %d \n",anim_count,count_frame); lastframe=&p_chunk->AnimKeyFrames[count_frame]; lastframe->Flags=keyframe->Flags; if(keyframe->NextFrame) { // looped firstframe->PrevFrame=lastframe; lastframe->NextFrame=firstframe; } else { firstframe->PrevFrame=0; lastframe->NextFrame=0; } count_frame++; break; } else if(keyframe->NextFrame==0) { // // anim not looped // lastframe=&p_chunk->AnimKeyFrames[count_frame]; lastframe->Flags=keyframe->Flags; firstframe->PrevFrame=0; lastframe->NextFrame=0; } count_frame++; keyframe=keyframe->NextFrame; ASSERT(element_countAnimList[anim_count]=0; key_list=key_list->GetNextAnim(); anim_count++; // ASSERT(anim_count<397); } p_chunk->MaxPeopleTypes=10; p_chunk->MaxAnimFrames=anim_count; p_chunk->MaxFightCols=fight_count; p_chunk->MaxKeyFrames=count_frame; convert_elements(the_chunk,p_chunk,p_reloc,element_count); { SLONG count=0,c0; for(c0=the_chunk->MultiObjectStart;c0<=the_chunk->MultiObjectEnd;c0++) { p_chunk->MultiObject[count++]=c0; } p_chunk->MultiObject[count]=0; } p_chunk->ElementCount=the_chunk->ElementCount; memcpy(p_chunk->PeopleTypes,the_chunk->PeopleTypes,sizeof(struct BodyDef)*MAX_PEOPLE_TYPES); MemFree((UBYTE*)p_reloc); void convert_keyframe_to_index(GameKeyFrame *p,GameKeyFrameElement *p_ele,GameFightCol *p_fight,SLONG count); void convert_animlist_to_index(GameKeyFrame **p,GameKeyFrame *p_anim,SLONG count); void convert_fightcol_to_index(GameFightCol *p,GameFightCol *p_fight,SLONG count); convert_keyframe_to_index(p_chunk->AnimKeyFrames,p_chunk->TheElements,p_chunk->FightCols,p_chunk->MaxKeyFrames); convert_animlist_to_index(p_chunk->AnimList,p_chunk->AnimKeyFrames,p_chunk->MaxAnimFrames); convert_fightcol_to_index(p_chunk->FightCols,p_chunk->FightCols,p_chunk->MaxFightCols); } #endif void free_game_chunk(GameKeyFrameChunk *the_chunk) { if(the_chunk->PeopleTypes) MemFree((UBYTE*)the_chunk->PeopleTypes); // if(the_chunk->TweakSpeeds) // MemFree((UBYTE*)the_chunk->TweakSpeeds); if(the_chunk->AnimKeyFrames) MemFree((UBYTE*)the_chunk->AnimKeyFrames); if(the_chunk->AnimList) MemFree((UBYTE*)the_chunk->AnimList); if(the_chunk->TheElements) MemFree((UBYTE*)the_chunk->TheElements); if(the_chunk->FightCols) MemFree((UBYTE*)the_chunk->FightCols); the_chunk->PeopleTypes=0; the_chunk->AnimKeyFrames=0; the_chunk->AnimList=0; the_chunk->TheElements=0; the_chunk->FightCols=0; // the_chunk->TweakSpeeds=0; } #else void free_game_chunk(GameKeyFrameChunk *the_chunk) { } #endif