forked from MergHQ/CRYENGINE
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Review: ID 67991 by Author: Thomas Wollenzin, Reviewer: Filip Lundgren, Observer: Luis Lairet (Approved by thomasw) Copied from Perforce Change: 1547332
- Loading branch information
1 parent
5c262c3
commit 5642ed7
Showing
4 changed files
with
155 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
Code/CryPlugins/CryDefaultEntities/Module/DefaultComponents/Audio/PreloadComponent.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved. | ||
|
||
#include "StdAfx.h" | ||
#include "PreloadComponent.h" | ||
#include <CryAudio/IAudioSystem.h> | ||
|
||
namespace Cry | ||
{ | ||
namespace Audio | ||
{ | ||
namespace DefaultComponents | ||
{ | ||
////////////////////////////////////////////////////////////////////////// | ||
void CPreloadComponent::Register(Schematyc::CEnvRegistrationScope& componentScope) | ||
{ | ||
{ | ||
auto pFunction = SCHEMATYC_MAKE_ENV_FUNCTION(&CPreloadComponent::Load, "A482E1A3-03C6-47D4-B775-568A4DB60352"_cry_guid, "Load"); | ||
pFunction->SetDescription("Loads the preload request."); | ||
pFunction->SetFlags(Schematyc::EEnvFunctionFlags::Construction); | ||
componentScope.Register(pFunction); | ||
} | ||
{ | ||
auto pFunction = SCHEMATYC_MAKE_ENV_FUNCTION(&CPreloadComponent::Unload, "1FF19168-A2EF-46E5-A673-E34C7E46EEFF"_cry_guid, "Unload"); | ||
pFunction->SetDescription("Unloads the preload request."); | ||
pFunction->SetFlags(Schematyc::EEnvFunctionFlags::Construction); | ||
componentScope.Register(pFunction); | ||
} | ||
} | ||
|
||
////////////////////////////////////////////////////////////////////////// | ||
void CPreloadComponent::OnShutDown() | ||
{ | ||
if (m_bLoaded) | ||
{ | ||
gEnv->pAudioSystem->UnloadSingleRequest(m_preload.m_id); | ||
} | ||
} | ||
|
||
////////////////////////////////////////////////////////////////////////// | ||
void CPreloadComponent::ReflectType(Schematyc::CTypeDesc<CPreloadComponent>& desc) | ||
{ | ||
desc.SetGUID("C098DC62-BB9F-4EC5-80EB-79B99EE29BAB"_cry_guid); | ||
desc.SetEditorCategory("Audio"); | ||
desc.SetLabel("Preload"); | ||
desc.SetDescription("Used to load/unload a preload request."); | ||
desc.SetIcon("icons:Audio/component_preload.ico"); | ||
desc.SetComponentFlags({ IEntityComponent::EFlags::Attach, IEntityComponent::EFlags::ClientOnly, IEntityComponent::EFlags::HideFromInspector }); | ||
|
||
desc.AddMember(&CPreloadComponent::m_preload, 'prel', "preload", "Preload", "The preload request to load/unload.", SPreloadSerializeHelper()); | ||
} | ||
|
||
////////////////////////////////////////////////////////////////////////// | ||
void CPreloadComponent::Load() | ||
{ | ||
if (m_preload.m_id != CryAudio::InvalidPreloadRequestId) | ||
{ | ||
gEnv->pAudioSystem->PreloadSingleRequest(m_preload.m_id, false); | ||
} | ||
} | ||
|
||
////////////////////////////////////////////////////////////////////////// | ||
void CPreloadComponent::Unload() | ||
{ | ||
if (m_preload.m_id != CryAudio::InvalidPreloadRequestId) | ||
{ | ||
gEnv->pAudioSystem->UnloadSingleRequest(m_preload.m_id); | ||
} | ||
} | ||
} // namespace DefaultComponents | ||
} // namespace Audio | ||
} // namespace Cry |
76 changes: 76 additions & 0 deletions
76
Code/CryPlugins/CryDefaultEntities/Module/DefaultComponents/Audio/PreloadComponent.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved. | ||
|
||
#pragma once | ||
|
||
#include <CryAudio/IAudioInterfacesCommonData.h> | ||
#include <CrySerialization/Forward.h> | ||
#include <CrySchematyc/Reflection/TypeDesc.h> | ||
#include <CrySchematyc/Env/IEnvRegistrar.h> | ||
|
||
class CPlugin_CryDefaultEntities; | ||
|
||
namespace Cry | ||
{ | ||
namespace Audio | ||
{ | ||
namespace DefaultComponents | ||
{ | ||
struct SPreloadSerializeHelper | ||
{ | ||
void Serialize(Serialization::IArchive& archive); | ||
bool operator==(SPreloadSerializeHelper const& other) const { return m_name == other.m_name; } | ||
|
||
CryAudio::PreloadRequestId m_id = CryAudio::InvalidPreloadRequestId; | ||
string m_name; | ||
}; | ||
|
||
class CPreloadComponent final : public IEntityComponent | ||
{ | ||
protected: | ||
|
||
friend CPlugin_CryDefaultEntities; | ||
static void Register(Schematyc::CEnvRegistrationScope& componentScope); | ||
|
||
// IEntityComponent | ||
virtual void Initialize() override {} | ||
virtual void OnShutDown() override; | ||
virtual uint64 GetEventMask() const override { return 0; } | ||
virtual void ProcessEvent(SEntityEvent& event) override {} | ||
// ~IEntityComponent | ||
|
||
// Properties exposed to UI | ||
SPreloadSerializeHelper m_preload; | ||
|
||
public: | ||
|
||
CPreloadComponent() = default; | ||
|
||
static void ReflectType(Schematyc::CTypeDesc<CPreloadComponent>& desc); | ||
|
||
void Load(); | ||
void Unload(); | ||
|
||
private: | ||
|
||
bool m_bLoaded = false; | ||
}; | ||
|
||
////////////////////////////////////////////////////////////////////////// | ||
inline void ReflectType(Schematyc::CTypeDesc<SPreloadSerializeHelper>& desc) | ||
{ | ||
desc.SetGUID("C9353DDE-5F53-482F-AFEF-7D6A500ACDD9"_cry_guid); | ||
} | ||
|
||
////////////////////////////////////////////////////////////////////////// | ||
inline void SPreloadSerializeHelper::Serialize(Serialization::IArchive& archive) | ||
{ | ||
archive(Serialization::AudioPreloadRequest<string>(m_name), "preloadName", "^"); | ||
|
||
if (archive.isInput()) | ||
{ | ||
m_id = CryAudio::StringToId_RunTime(m_name.c_str()); | ||
} | ||
} | ||
} // namespace DefaultComponents | ||
} // namespace Audio | ||
} // namespace Cry |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters