bool GraphicManager::loadSpriteMetadata(const FileName& datafile, wxString& error, wxArrayString& warnings) { // items.otb has most of the info we need. This only loads the GameSprite metadata FileReadHandle file(nstr(datafile.GetFullPath())); if(!file.isOk()) { error += "Failed to open " + datafile.GetFullPath() + " for reading\nThe error reported was:" + wxstr(file.getErrorMessage()); return false; } uint16_t effect_count, distance_count; uint32_t datSignature; file.getU32(datSignature); //get max id file.getU16(item_count); file.getU16(creature_count); file.getU16(effect_count); file.getU16(distance_count); uint32_t minclientID = 100; // tibia.dat start with id 100 // We don't load distance/effects, if we would, just add effect_count & distance_count here uint32_t maxclientID = item_count + creature_count; dat_format = client_version->getDatFormatForSignature(datSignature); if(!otfi_found) { is_extended = dat_format >= DAT_FORMAT_96; has_frame_durations = dat_format >= DAT_FORMAT_1050; has_frame_groups = dat_format >= DAT_FORMAT_1057; } uint16_t id = minclientID; // loop through all ItemDatabase until we reach the end of file while(id <= maxclientID) { GameSprite* sType = newd GameSprite(); sprite_space[id] = sType; sType->id = id; // Load the sprite flags if(!loadSpriteMetadataFlags(file, sType, error, warnings)) { wxString msg; msg << "Failed to load flags for sprite " << sType->id; warnings.push_back(msg); } // Reads the group count uint8_t group_count = 1; if(has_frame_groups && id > item_count) { file.getU8(group_count); } for(uint32_t k = 0; k < group_count; ++k) { // Skipping the group type if(has_frame_groups && id > item_count) { file.skip(1); } // Size and GameSprite data file.getByte(sType->width); file.getByte(sType->height); // Skipping the exact size if((sType->width > 1) || (sType->height > 1)){ file.skip(1); } file.getU8(sType->layers); // Number of blendframes (some sprites consist of several merged sprites) file.getU8(sType->pattern_x); file.getU8(sType->pattern_y); if(dat_format <= DAT_FORMAT_74) sType->pattern_z = 1; else file.getU8(sType->pattern_z); file.getU8(sType->frames); // Length of animation if(sType->frames > 1) { uint8_t async = 0; int loop_count = 0; int8_t start_frame = 0; if(has_frame_durations) { file.getByte(async); file.get32(loop_count); file.getSByte(start_frame); } sType->animator = newd Animator(sType->frames, start_frame, loop_count, async == 1); if(has_frame_durations) { for(int i = 0; i < sType->frames; i++) { uint32_t min; uint32_t max; file.getU32(min); file.getU32(max); FrameDuration* frame_duration = sType->animator->getFrameDuration(i); frame_duration->setValues(int(min), int(max)); } sType->animator->reset(); } } sType->numsprites = (int)sType->width * (int)sType->height * (int)sType->layers * (int)sType->pattern_x * (int)sType->pattern_y * sType->pattern_z * (int)sType->frames; // Read the sprite ids for(uint32_t i = 0; i < sType->numsprites; ++i) { uint32_t sprite_id; if(is_extended) { file.getU32(sprite_id); } else { uint16_t u16 = 0; file.getU16(u16); sprite_id = u16; } if(image_space[sprite_id] == nullptr) { GameSprite::NormalImage* img = newd GameSprite::NormalImage(); img->id = sprite_id; image_space[sprite_id] = img; } sType->spriteList.push_back(static_cast<GameSprite::NormalImage*>(image_space[sprite_id])); } } ++id; } return true; }
bool eae6320::Graphics::LoadObjects() { s_camera = new CameraObject(); // Loading level s_boxes_obj = new GameObject("data/boxes.binMesh", "data/boxes.binMaterial"); s_ceiling_obj = new GameObject("data/ceiling.binMesh", "data/ceiling.binMaterial"); s_floor_obj = new GameObject("data/floor.binMesh", "data/floor.binMaterial"); s_innerWalls_obj = new GameObject("data/innerWalls.binMesh", "data/innerWalls.binMaterial"); s_metal_obj = new GameObject("data/metal.binMesh", "data/metal.binMaterial"); s_outerWalls_obj = new GameObject("data/outerWalls.binMesh", "data/outerWalls.binMaterial"); s_railing_obj = new GameObject("data/railing.binMesh", "data/railing.binMaterial"); // Debug Shapes s_debugLine1 = eae6320::Graphics::DebugLine(Math::cVector(100.0f, 0.0f, 0.0f), Math::cVector(75.0f, -50.0f, -50.0f), Math::cVector(0.0f, 0.4f, 0.2f)); s_debugLine2 = eae6320::Graphics::DebugLine(Math::cVector(-100.0f, 0.0f, -70.0f), Math::cVector(-50.0f, -50.0f, -50.0f), Math::cVector(1.0f, 0.0f, 0.0f)); s_debugBox1 = eae6320::Graphics::DebugBox(Math::cVector(30.0f, -20.0f, -40.0f), 20.0f, Math::cVector(1.0f, 0.0f, 1.0f)); s_debugBox2 = eae6320::Graphics::DebugBox(Math::cVector(-30.0f, 20.0f, -40.0f), 15.0f, Math::cVector(0.0f, 0.0f, 0.3f)); s_debugSphere1 = new DebugSphere(Math::cVector(-50.0f, 0.0f, -150.0f), 20.0f, 20, 20, Math::cVector(0.2f, 0.4f, 0.0f)); s_debugSphere2 = eae6320::Graphics::DebugSphere(Math::cVector(-50.0f, 0.0f, -250.0f), 30.0f, 20, 20, Math::cVector(0.0f, 1.0f, 1.0f)); s_debugCylinder1 = new GameObject("data/cylinder1.binMesh", "data/cylinder1.binMaterial"); s_debugCylinder2 = new GameObject("data/cylinder2.binMesh", "data/cylinder2.binMaterial"); // Game Sprites s_logo = GameSprite(10, 10); s_numbers = new GameSprite(650, 100); // Third person snowman s_snowman = new GameObject("data/snowman.binMesh", "data/snowman.binMaterial"); s_snowmanClient = new GameObject("data/snowman.binMesh", "data/snowmanClient.binMaterial"); s_snowmanLine = new eae6320::Graphics::DebugLine(Math::cVector(100.0f, 0.0f, 0.0f), Math::cVector(75.0f, -50.0f, -50.0f), Math::cVector(0.0f, 0.0f, 1.0f)); s_collisionDet = new eae6320::Graphics::CollisionDetection(); // Capture the Flag s_flag1 = new GameObject("data/flag1.binMesh", "data/flag1.binMaterial"); s_flag2 = new GameObject("data/flag2.binMesh", "data/flag2.binMaterial"); s_bullet1 = new GameObject("data/bullet.binMesh", "data/bullet1.binMaterial"); s_bullet2 = new GameObject("data/bullet.binMesh", "data/bullet2.binMaterial"); s_sprintBar = new DebugMenuBar("Sprint ", 300, 20, 200, 50); s_snowmanScore = new DebugMenuScore("Player 1 Score = ", 300, 50, 200, 50); s_snowmanClientScore = new DebugMenuScore("Player 2 Score = ", 300, 80, 200, 50); #ifdef _DEBUG // Debug Menu Stuff s_debugMenuTextFPS = eae6320::Graphics::DebugMenuText("FPS = ", 20, 20, 150, 50); s_debugMenuCheckBox = new eae6320::Graphics::DebugMenuCheckBox("Enable Debug Sphere ", 20, 50, 200, 50); s_debugMenuSlider = new eae6320::Graphics::DebugMenuSlider("Volume ", 20, 80, 200, 50); s_debugMenuButton = new eae6320::Graphics::DebugMenuButton("Reset Radius of Debug Sphere ", 20, 110, 275, 50); s_toggleFPSCheckBox = new eae6320::Graphics::DebugMenuCheckBox("Enable Fly Camera ", 20, 140, 200, 50); #endif // Initialize the level if (!s_boxes_obj->LoadObject() || !s_ceiling_obj->LoadObject() || !s_floor_obj->LoadObject() || !s_innerWalls_obj->LoadObject() || !s_metal_obj->LoadObject() || !s_outerWalls_obj->LoadObject() || !s_railing_obj->LoadObject() ) { return false; } // Loading Debug Shapes s_debugLine1.LoadDebugLine(); s_debugLine2.LoadDebugLine(); s_debugBox1.LoadDebugBox(); s_debugBox2.LoadDebugBox(); s_debugSphere1->LoadDebugSphere(); s_debugSphere2.LoadDebugSphere(); s_debugCylinder1->LoadObject(); s_debugCylinder2->LoadObject(); // Loading Game Sprites s_logo.Initialize(GetLocalDirect3dDevice(), "data/logo.texture", 256, 256); s_numbers->Initialize(GetLocalDirect3dDevice(), "data/numbers.texture", 512, 64); #ifdef _DEBUG // Loading DebugMebu Items s_activeMenuItem = DebugMenuSelection::Text; s_debugMenuTextFPS.LoadDebugText(); s_debugMenuCheckBox->LoadDebugCheckBox(); s_debugMenuSlider->LoadDebugSlider(); s_debugMenuButton->LoadDebugButton(); s_toggleFPSCheckBox->LoadDebugCheckBox(); #endif // Enabling third person camera s_toggleFPSCheckBox->m_isChecked = false; // Loading Third person Snowman s_snowmanLine->LoadDebugLine(); s_snowman->LoadObject(); s_snowman->m_position.x -= 50; s_snowman->m_position.y -= 220; s_snowman->m_position.z -= 300; s_snowmanClient->LoadObject(); s_snowmanClient->m_position.x -= 50; s_snowmanClient->m_position.y -= 220; s_snowmanClient->m_position.z -= 0; s_collisionDet->LoadCollisionData("data/CollisionData.binmesh"); // Capture the Flag s_flag1->LoadObject(); s_flag2->LoadObject(); s_bullet1->LoadObject(); s_bullet2->LoadObject(); s_sprintBar->LoadDebugBar(); s_snowmanScore->LoadDebugText(); s_snowmanClientScore->LoadDebugText(); s_flag1->m_position = s_flag1->m_defaultPosition = Math::cVector(1487, 57, -1452); s_flag2->m_position = s_flag2->m_defaultPosition = Math::cVector(-1487, 57, 1452); s_bullet1->m_isActive = false; s_bullet2->m_isActive = false; s_snowmanScore->m_score = 0; s_snowmanClientScore->m_score = 0; return true; }