Initial commit

This commit is contained in:
alexpete
2021-03-05 11:26:34 -08:00
commit a10351f38d
27091 changed files with 5521199 additions and 0 deletions
@@ -0,0 +1,106 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include <AzCore/Component/ComponentApplication.h>
#include <AzCore/Component/ComponentApplicationBus.h>
#include <AzCore/Component/Entity.h>
#include <AzCore/IO/FileIO.h>
#include <AzCore/Module/ModuleManager.h>
#include <AzCore/RTTI/RTTI.h>
#include <AzCore/Serialization/SerializeContext.h>
#include <AzCore/Serialization/ObjectStream.h>
#include <SceneAPI/SceneCore/Components/SceneSystemComponent.h>
#include <SceneAPI/SceneCore/Components/Utilities/EntityConstructor.h>
#include <SceneAPI/SceneCore/Utilities/Reporting.h>
namespace AZ
{
namespace SceneAPI
{
namespace SceneCore
{
namespace EntityConstructor
{
EntityPointer BuildEntity(const char* entityName, const AZ::Uuid& baseComponentType)
{
return EntityPointer(BuildEntityRaw(entityName, baseComponentType), [](AZ::Entity* entity)
{
entity->Deactivate();
delete entity;
});
}
Entity* BuildEntityRaw(const char* entityName, const AZ::Uuid& baseComponentType)
{
SerializeContext* context = nullptr;
ComponentApplicationBus::BroadcastResult(context, &ComponentApplicationBus::Events::GetSerializeContext);
Entity* entity = aznew AZ::Entity(entityName);
if (context)
{
context->EnumerateDerived(
[entity](const AZ::SerializeContext::ClassData* data, const AZ::Uuid& /*typeId*/) -> bool
{
entity->CreateComponent(data->m_typeId);
return true;
}, baseComponentType, baseComponentType);
}
entity->Init();
entity->Activate();
return entity;
}
Entity* BuildSceneSystemEntity()
{
SerializeContext* context = nullptr;
ComponentApplicationBus::BroadcastResult(context, &ComponentApplicationBus::Events::GetSerializeContext);
if (!context)
{
AZ_TracePrintf(SceneAPI::Utilities::ErrorWindow, "Unable to retrieve serialize context.");
return nullptr;
}
// Starting all system components would be too expensive for a builder/ResourceCompiler, so only the system components needed
// for the SceneAPI will be created.
AZStd::unique_ptr<Entity> entity(aznew AZ::Entity("Scene System"));
const Uuid sceneSystemComponentType = azrtti_typeid<AZ::SceneAPI::SceneCore::SceneSystemComponent>();
context->EnumerateDerived(
[&entity](const AZ::SerializeContext::ClassData* data, const AZ::Uuid& typeId) -> bool
{
AZ_UNUSED(typeId);
// Before adding a new instance of a SceneSystemComponent, first check if the entity already has
// a component of the same type. Just like regular system components, there should only ever be
// a single instance of a SceneSystemComponent.
bool alreadyAdded = false;
for (const Component* component : entity->GetComponents())
{
if (component->RTTI_GetType() == data->m_typeId)
{
alreadyAdded = true;
break;
}
}
if (!alreadyAdded)
{
entity->CreateComponent(data->m_typeId);
}
return true;
}, sceneSystemComponentType, sceneSystemComponentType);
return entity.release();
}
} // namespace EntityConstructor
} // namespace SceneCore
} // namespace SceneAPI
} // namespace AZ
@@ -0,0 +1,37 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <AzCore/std/smart_ptr/unique_ptr.h>
#include <SceneAPI/SceneCore/SceneCoreConfiguration.h>
namespace AZ
{
class Entity;
struct Uuid;
namespace SceneAPI
{
namespace SceneCore
{
namespace EntityConstructor
{
using EntityPointer = AZStd::unique_ptr<AZ::Entity, void(*)(AZ::Entity*)>;
SCENE_CORE_API EntityPointer BuildEntity(const char* entityName, const AZ::Uuid& baseComponentType);
SCENE_CORE_API Entity* BuildEntityRaw(const char* entityName, const AZ::Uuid& baseComponentType);
SCENE_CORE_API Entity* BuildSceneSystemEntity();
} // namespace EntityConstructor
} // namespace SceneCore
} // namespace SceneAPI
} // namespace AZ