void DirectX12Render::Initialize(UINT width, UINT height) { Width = width; Height = height; InitializeDX(); InitializeAssets(); }
// Initialize each member in turn. This is logically just one function, since // the order of initialization cannot be changed. However, it's nice for // debugging and readability to have each section lexographically separate. bool Game::Initialize(const char* const binary_directory) { LogInfo("Zooshi Initializing..."); #if defined(BENCHMARK_MOTIVE) InitBenchmarks(10); #endif // defined(BENCHMARK_MOTIVE) input_.Initialize(); input_.AddAppEventCallback(AudioEngineVolumeControl(&audio_engine_)); #ifdef ANDROID_HMD input_.head_mounted_display_input().EnableDeviceOrientationCorrection(); #endif // ANDROID_HMD SystraceInit(); if (!fplbase::ChangeToUpstreamDir(binary_directory, kAssetsDir)) return false; if (!LoadFile(kConfigFileName, &config_source_)) return false; if (!InitializeRenderer()) return false; if (!LoadFile(GetConfig().input_config()->c_str(), &input_config_source_)) return false; if (!LoadFile(GetConfig().assets_filename()->c_str(), &asset_manifest_source_)) { return false; } const auto& asset_manifest = GetAssetManifest(); if (!InitializeAssets()) return false; if (!audio_engine_.Initialize(GetConfig().audio_config()->c_str())) { return false; } audio_engine_.LoadSoundBank(asset_manifest.sound_bank()->c_str()); audio_engine_.StartLoadingSoundFiles(); InitializeBreadboardModules(); for (size_t i = 0; i < asset_manifest.font_list()->size(); i++) { flatbuffers::uoffset_t index = static_cast<flatbuffers::uoffset_t>(i); font_manager_.Open(asset_manifest.font_list()->Get(index)->c_str()); } font_manager_.SetRenderer(renderer_); SetPerformanceMode(fplbase::kHighPerformance); scene_lab_.reset(new scene_lab::SceneLab()); world_.Initialize(GetConfig(), &input_, &asset_manager_, &world_renderer_, &font_manager_, &audio_engine_, &graph_factory_, &renderer_, scene_lab_.get()); #ifdef __ANDROID__ if (fplbase::SupportsHeadMountedDisplay()) { BasePlayerController* controller = new AndroidCardboardController(); controller->set_input_config(&GetInputConfig()); controller->set_input_system(&input_); controller->set_enabled(ZOOSHI_FORCE_ONSCREEN_CONTROLLER == 0); world_.AddController(controller); world_.hmd_controller = controller; } #endif // __ANDROID__ // If this is a mobile platform or the onscreen controller is forced on // instance the onscreen controller. #if defined(PLATFORM_MOBILE) || ZOOSHI_FORCE_ONSCREEN_CONTROLLER { OnscreenController* onscreen_controller = new OnscreenController(); onscreen_controller->set_input_config(&GetInputConfig()); onscreen_controller->set_input_system(&input_); onscreen_controller->set_enabled(!fplbase::SupportsHeadMountedDisplay() || ZOOSHI_FORCE_ONSCREEN_CONTROLLER); world_.AddController(onscreen_controller); world_.onscreen_controller_ui.set_controller(onscreen_controller); #ifdef ANDROID_HMD world_.onscreen_controller = onscreen_controller; #endif // ANDROID_HMD } #endif // defined(PLATFORM_MOBILE) || ZOOSHI_FORCE_ONSCREEN_CONTROLLER // If this is a desktop platform and we're not forcing the onscreen controller // instance the mouse controller. #if !defined(PLATFORM_MOBILE) && !ZOOSHI_FORCE_ONSCREEN_CONTROLLER { BasePlayerController* controller = new MouseController(); controller->set_input_config(&GetInputConfig()); controller->set_input_system(&input_); world_.AddController(controller); } #endif // !ZOOSHI_FORCE_ONSCREEN_CONTROLLER && !defined(PLATFORM_MOBILE) #ifdef ANDROID_GAMEPAD { GamepadController* controller = new GamepadController(); controller->set_input_config(&GetInputConfig()); controller->set_input_system(&input_); world_.AddController(controller); } #endif // ANDROID_GAMEPAD world_renderer_.Initialize(&world_); scene_lab_->Initialize(GetConfig().scene_lab_config(), &world_.entity_manager, &font_manager_); scene_lab_->AddComponentToUpdate( corgi::component_library::TransformComponent::GetComponentId()); scene_lab_->AddComponentToUpdate(ShadowControllerComponent::GetComponentId()); scene_lab_->AddComponentToUpdate( corgi::component_library::RenderMeshComponent::GetComponentId()); gpg_manager_.Initialize(false); auto fader_material = asset_manager_.FindMaterial(asset_manifest.fader_material()->c_str()); assert(fader_material); fader_.Init(fader_material, shader_textured_); const Config* config = &GetConfig(); loading_state_.Initialize(&input_, &world_, asset_manifest, &asset_manager_, &audio_engine_, shader_textured_, &fader_); pause_state_.Initialize(&input_, &world_, config, &asset_manager_, &font_manager_, &audio_engine_); gameplay_state_.Initialize(&input_, &world_, config, &GetInputConfig(), &world_.entity_manager, scene_lab_.get(), &gpg_manager_, &audio_engine_, &fader_); game_menu_state_.Initialize(&input_, &world_, config, &asset_manager_, &font_manager_, &GetAssetManifest(), &gpg_manager_, &audio_engine_, &fader_); game_over_state_.Initialize(&input_, &world_, config, &asset_manager_, &font_manager_, &gpg_manager_, &audio_engine_); intro_state_.Initialize(&input_, &world_, config, &fader_, &audio_engine_); scene_lab_state_.Initialize(&renderer_, &input_, scene_lab_.get(), &world_); state_machine_.AssignState(kGameStateLoading, &loading_state_); state_machine_.AssignState(kGameStateGameplay, &gameplay_state_); state_machine_.AssignState(kGameStatePause, &pause_state_); state_machine_.AssignState(kGameStateGameMenu, &game_menu_state_); state_machine_.AssignState(kGameStateIntro, &intro_state_); state_machine_.AssignState(kGameStateGameOver, &game_over_state_); state_machine_.AssignState(kGameStateSceneLab, &scene_lab_state_); state_machine_.SetCurrentStateId(kGameStateLoading); #ifdef ANDROID_HMD if (fplbase::AndroidGetActivityName() == "com.google.fpl.zooshi.ZooshiHmdActivity") { world_.SetIsInCardboard(true); } #endif // ANDROID_HMD LogInfo("Initialization complete\n"); return true; }