Skip to content

Commit

Permalink
!A (Audio) added preload component
Browse files Browse the repository at this point in the history
Review: ID 67991 by Author: Thomas Wollenzin, Reviewer: Filip Lundgren, Observer: Luis Lairet
 (Approved by thomasw)

Copied from Perforce
 Change: 1547332
  • Loading branch information
Cry-Thomas committed Aug 25, 2017
1 parent 5c262c3 commit 5642ed7
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Code/CryPlugins/CryDefaultEntities/Module/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ add_sources("CryDefaultEntities_uber_0.cpp"
"DefaultComponents/Audio/ListenerComponent.h"
"DefaultComponents/Audio/ParameterComponent.cpp"
"DefaultComponents/Audio/ParameterComponent.h"
"DefaultComponents/Audio/PreloadComponent.cpp"
"DefaultComponents/Audio/PreloadComponent.h"
"DefaultComponents/Audio/SwitchComponent.cpp"
"DefaultComponents/Audio/SwitchComponent.h"
"DefaultComponents/Audio/TriggerComponent.cpp"
Expand Down
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
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
7 changes: 6 additions & 1 deletion Code/CryPlugins/CryDefaultEntities/Module/PluginDll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "DefaultComponents/Audio/AreaComponent.h"
#include "DefaultComponents/Audio/ListenerComponent.h"
#include "DefaultComponents/Audio/ParameterComponent.h"
#include "DefaultComponents/Audio/PreloadComponent.h"
#include "DefaultComponents/Audio/SwitchComponent.h"
#include "DefaultComponents/Audio/TriggerComponent.h"
#include "DefaultComponents/Cameras/CameraComponent.h"
Expand Down Expand Up @@ -80,6 +81,10 @@ void CPlugin_CryDefaultEntities::RegisterComponents(Schematyc::IEnvRegistrar& re
Schematyc::CEnvRegistrationScope componentScope = scope.Register(SCHEMATYC_MAKE_ENV_COMPONENT(Cry::Audio::DefaultComponents::CParameterComponent));
Cry::Audio::DefaultComponents::CParameterComponent::Register(componentScope);
}
{
Schematyc::CEnvRegistrationScope componentScope = scope.Register(SCHEMATYC_MAKE_ENV_COMPONENT(Cry::Audio::DefaultComponents::CPreloadComponent));
Cry::Audio::DefaultComponents::CPreloadComponent::Register(componentScope);
}
{
Schematyc::CEnvRegistrationScope componentScope = scope.Register(SCHEMATYC_MAKE_ENV_COMPONENT(Cry::Audio::DefaultComponents::CSwitchComponent));
Cry::Audio::DefaultComponents::CSwitchComponent::Register(componentScope);
Expand Down Expand Up @@ -218,7 +223,7 @@ void CPlugin_CryDefaultEntities::OnSystemEvent(ESystemEvent event, UINT_PTR wpar

gEnv->pSchematyc->GetEnvRegistry().RegisterPackage(
stl::make_unique<Schematyc::CEnvPackage>(
CPlugin_CryDefaultEntities::GetCID(),
CPlugin_CryDefaultEntities::GetCID(),
"EntityComponents",
"Crytek GmbH",
"CRYENGINE Default Entity Components",
Expand Down

0 comments on commit 5642ed7

Please sign in to comment.