Beispiel #1
0
// Load textures for cardboard into 'materials_'. The 'renderer_' and
// 'asset_manager_' members have been initialized at this point.
bool Game::InitializeAssets() {
  // Load up all of our assets, as defined in the manifest.
  // Load the loading-material first, since we display that while the others
  // load.
  const AssetManifest& asset_manifest = GetAssetManifest();

  if (fplbase::GetSystemRamSize() <= kLowRamProfileThreshold) {
    // Reduce material size.
    asset_manager_.SetTextureScale(kLowRamDeviceTextureScale);
  }

  asset_manager_.LoadMaterial(asset_manifest.loading_material()->c_str());
  asset_manager_.LoadMaterial(asset_manifest.fader_material()->c_str());
  for (size_t i = 0; i < asset_manifest.mesh_list()->size(); i++) {
    flatbuffers::uoffset_t index = static_cast<flatbuffers::uoffset_t>(i);
    asset_manager_.LoadMesh(asset_manifest.mesh_list()->Get(index)->c_str());
  }
  for (size_t i = 0; i < asset_manifest.shader_list()->size(); i++) {
    flatbuffers::uoffset_t index = static_cast<flatbuffers::uoffset_t>(i);
    asset_manager_.LoadShader(asset_manifest.shader_list()->Get(index)->c_str());
  }
  for (size_t i = 0; i < asset_manifest.material_list()->size(); i++) {
    flatbuffers::uoffset_t index = static_cast<flatbuffers::uoffset_t>(i);
    asset_manager_.LoadMaterial(
        asset_manifest.material_list()->Get(index)->c_str());
  }
  asset_manager_.StartLoadingTextures();

  shader_lit_textured_normal_ =
      asset_manager_.LoadShader("shaders/lit_textured_normal");
  shader_textured_ = asset_manager_.LoadShader("shaders/textured");

  // Load the animation table and all animations it references.
  motive::AnimTable& anim_table = world_.animation_component.anim_table();
  const bool anim_ok =
      anim_table.InitFromFlatBuffers(*asset_manifest.anims(), LoadRigAnim);
  if (!anim_ok) return false;

  return true;
}
Beispiel #2
0
// 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;
}
Beispiel #3
0
void VenomModuleRender(GameMemory* memory) {
  RenderState* rs = &memory->renderState;
  GameData* data = (GameData*)memory->userdata;
  EditorData* editorData = &memory->editor;
  EditorData* editor = editorData;

  const V3 sunDirection = Normalize(V3(1.0, 0.5, 0.0f));
  AddDirectionalLight(sunDirection, V3(1.0, 1.0, 1.0), &rs->drawList);

  auto sunModelID = GetModelID("Sun", GetAssetManifest());
  auto sunModel = GetModelAsset(sunModelID);
  AddStaticModelToDrawList(&rs->drawList, sunModel, sunDirection * 10);

  
  
  const F32 deltaTime = memory->deltaTime;
  EntityContainer* entityContainer = &data->entityContainer;
  
  auto engine = GetEngine();



  EntityBlock* block = entityContainer->firstAvaibleBlock;
  for (U64 i = 0; i < entityContainer->capacityPerBlock; i++) {
    if (block->flags[i] & EntityFlag_PRESENT) {
      Entity* entity = &block->entities[i];

      if(block->types[i] == EntityType_PointLight) {
        AddShadowCastingPointLight(entity->position, entity->pointLight.color, 
          entity->pointLight.radius, &rs->drawList);
      }

      ModelAsset *model = GetModelAsset(entity->modelID, &memory->assetManifest);
      if (model == nullptr) continue;
      bool is_entity_animated = model->jointCount > 0;

      if (block->flags[i] & EntityFlag_VISIBLE) {        
        if (editor->selectedEntities.ContainsValue(i)) {
          V3 rotation = QuaternionToEuler(entity->rotation);
          AddOutlinedModelToDrawList(&rs->drawList, model, entity->position, rotation); 
        } else if (is_entity_animated) {
          V3 rotation = QuaternionToEuler(entity->rotation);
          V3 position = entity->position;
          position.y += model->size.y * 0.5f;
          AddAnimatedModelToDrawList(&rs->drawList, model, &entity->animation_state, position, rotation);
        } else {
          V3 rotation = QuaternionToEuler(entity->rotation);
          V3 position = entity->position;
          position.y += model->size.y * 0.5f;
          AddStaticModelToDrawList(&rs->drawList, model, position, rotation); 
        }
      }
    }
  }

  Camera *camera = nullptr;
  camera = &data->camera;
#if 0
  if (editor->isEditorVisible) {
    //camera = &editor->editorCamera;
    ..draw_debug_camera(&data->camera);
  } else {