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,96 @@
/*
* 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.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
// Description : Part of CryEngine's extension framework.
#ifndef CRYINCLUDE_CRYEXTENSION_CRYCREATECLASSINSTANCE_H
#define CRYINCLUDE_CRYEXTENSION_CRYCREATECLASSINSTANCE_H
#pragma once
#include "ICryUnknown.h"
#include "ICryFactory.h"
#include "ICryFactoryRegistry.h"
#include <ISystem.h> // <> required for Interfuscator
template <class T>
bool CryCreateClassInstance(const CryClassID& cid, AZStd::shared_ptr<T>& p)
{
p = AZStd::shared_ptr<T>();
ICryFactoryRegistry* pFactoryReg = gEnv->pSystem->GetCryFactoryRegistry();
if (pFactoryReg)
{
ICryFactory* pFactory = pFactoryReg->GetFactory(cid);
if (pFactory && pFactory->ClassSupports(cryiidof<T>()))
{
ICryUnknownPtr pUnk = pFactory->CreateClassInstance();
AZStd::shared_ptr<T> pT = cryinterface_cast<T>(pUnk);
if (pT)
{
p = pT;
}
}
}
return p.get() != NULL;
}
template <class T>
bool CryCreateClassInstance(const char* cname, AZStd::shared_ptr<T>& p)
{
p = AZStd::shared_ptr<T>();
ICryFactoryRegistry* pFactoryReg = gEnv->pSystem->GetCryFactoryRegistry();
if (pFactoryReg)
{
ICryFactory* pFactory = pFactoryReg->GetFactory(cname);
if (pFactory != NULL && pFactory->ClassSupports(cryiidof<T>()))
{
ICryUnknownPtr pUnk = pFactory->CreateClassInstance();
AZStd::shared_ptr<T> pT = cryinterface_cast<T>(pUnk);
if (pT)
{
p = pT;
}
}
}
return p.get() != NULL;
}
template <class T>
bool CryCreateClassInstanceForInterface(const CryInterfaceID& iid, AZStd::shared_ptr<T>& p)
{
p = AZStd::shared_ptr<T>();
ICryFactoryRegistry* pFactoryReg = gEnv->pSystem->GetCryFactoryRegistry();
if (pFactoryReg)
{
size_t numFactories = 1;
ICryFactory* pFactory = 0;
pFactoryReg->IterateFactories(iid, &pFactory, numFactories);
if (numFactories == 1 && pFactory)
{
ICryUnknownPtr pUnk = pFactory->CreateClassInstance();
AZStd::shared_ptr<T> pT = cryinterface_cast<T>(pUnk);
if (pT)
{
p = pT;
}
}
}
return p.get() != NULL;
}
#endif // CRYINCLUDE_CRYEXTENSION_CRYCREATECLASSINSTANCE_H
@@ -0,0 +1,123 @@
/*
* 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.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
// Description : Part of CryEngine's extension framework.
#ifndef CRYINCLUDE_CRYEXTENSION_CRYGUID_H
#define CRYINCLUDE_CRYEXTENSION_CRYGUID_H
#pragma once
#include "Serialization/IArchive.h"
#include "Random.h"
#include <functional>
struct CryGUID
{
uint64 hipart;
uint64 lopart;
// !!! Do NOT turn CryGUID into a non-aggregate !!!
// It will prevent inlining and type list unrolling opportunities within
// cryinterface_cast<T>() and cryiidof<T>(). As such prevent constructors,
// non-public members, base classes and virtual functions!
//CryGUID() : hipart(0), lopart(0) {}
//CryGUID(uint64 h, uint64 l) : hipart(h), lopart(l) {}
static CryGUID Construct(const uint64& hipart, const uint64& lopart)
{
CryGUID guid = {hipart, lopart};
return guid;
}
static CryGUID Create()
{
uint64 lopart = 0;
uint64 hipart = 0;
while (lopart == 0 || hipart == 0)
{
const uint32 a = cry_random_uint32();
const uint32 b = cry_random_uint32();
const uint32 c = cry_random_uint32();
const uint32 d = cry_random_uint32();
lopart = (uint64)a | ((uint64)b << 32);
hipart = (uint64)c | ((uint64)d << 32);
}
return Construct(lopart, hipart);
}
static CryGUID Null()
{
return Construct(0, 0);
}
bool operator ==(const CryGUID& rhs) const {return hipart == rhs.hipart && lopart == rhs.lopart; }
bool operator !=(const CryGUID& rhs) const {return hipart != rhs.hipart || lopart != rhs.lopart; }
bool operator <(const CryGUID& rhs) const {return hipart == rhs.hipart ? lopart < rhs.lopart : hipart < rhs.hipart; }
void Serialize(Serialization::IArchive& ar)
{
if (ar.IsInput())
{
uint32 dwords[4];
ar(dwords, "guid");
lopart = (((uint64)dwords[1]) << 32) | (uint64)dwords[0];
hipart = (((uint64)dwords[3]) << 32) | (uint64)dwords[2];
}
else
{
uint32 guid[4] = {
(uint32)(lopart & 0xFFFFFFFF), (uint32)((lopart >> 32) & 0xFFFFFFFF),
(uint32)(hipart & 0xFFFFFFFF), (uint32)((hipart >> 32) & 0xFFFFFFFF)
};
ar(guid, "guid");
}
}
};
// This is only used by the editor where we use C++ 11.
namespace std
{
template<>
struct hash<CryGUID>
{
public:
size_t operator()(const CryGUID& guid) const
{
std::hash<uint64> hasher;
return hasher(guid.lopart) ^ hasher(guid.hipart);
}
};
}
namespace AZStd
{
template<>
struct hash<CryGUID>
{
public:
size_t operator()(const CryGUID& guid) const
{
std::hash<CryGUID> hasher;
return hasher(guid);
}
};
}
#define MAKE_CRYGUID(high, low) CryGUID::Construct((uint64) high##LL, (uint64) low##LL)
#endif // CRYINCLUDE_CRYEXTENSION_CRYGUID_H
@@ -0,0 +1,29 @@
/*
* 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.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
// Description : Part of CryEngine's extension framework.
#ifndef CRYINCLUDE_CRYEXTENSION_CRYTYPEID_H
#define CRYINCLUDE_CRYEXTENSION_CRYTYPEID_H
#pragma once
#include "CryGUID.h"
typedef CryGUID CryInterfaceID;
typedef CryGUID CryClassID;
#endif // CRYINCLUDE_CRYEXTENSION_CRYTYPEID_H
@@ -0,0 +1,41 @@
/*
* 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.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
// Description : Part of CryEngine's extension framework.
#ifndef CRYINCLUDE_CRYEXTENSION_ICRYFACTORY_H
#define CRYINCLUDE_CRYEXTENSION_ICRYFACTORY_H
#pragma once
#include "CryTypeID.h"
#include <SmartPointersHelpers.h>
struct ICryUnknown;
DECLARE_SMART_POINTERS(ICryUnknown);
struct ICryFactory
{
virtual const char* GetName() const = 0;
virtual const CryClassID& GetClassID() const = 0;
virtual bool ClassSupports(const CryInterfaceID& iid) const = 0;
virtual void ClassSupports(const CryInterfaceID*& pIIDs, size_t& numIIDs) const = 0;
virtual ICryUnknownPtr CreateClassInstance() const = 0;
protected:
// prevent explicit destruction from client side (delete, shared_ptr, etc)
virtual ~ICryFactory() {}
};
#endif // CRYINCLUDE_CRYEXTENSION_ICRYFACTORY_H
@@ -0,0 +1,56 @@
/*
* 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.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
// Description : Part of CryEngine's extension framework.
#ifndef CRYINCLUDE_CRYEXTENSION_ICRYFACTORYREGISTRY_H
#define CRYINCLUDE_CRYEXTENSION_ICRYFACTORYREGISTRY_H
#pragma once
#include "CryTypeID.h"
struct ICryFactory;
struct ICryFactoryRegistry
{
virtual ICryFactory* GetFactory(const char* cname) const = 0;
virtual ICryFactory* GetFactory(const CryClassID& cid) const = 0;
/**
* Iterates all factories implementing the interface specified by \p iid.
* \param[in] iid ID of the interface to iterate. Often procured using cryiidof<...>().
* \param[out] pFactories A pointer of the array of factories to fill in. May be nullptr (see below).
* \param[in] Size (in elements) of the pFactories array [out] Number of elements actually written to pFactories or, when pFactories is null, the number of elements that would be written if sufficient storage was available.
*
* Example:
* \code{.cpp}
* size_t factoryCount = 0;
* // Assigns the number of found factories to factoryCount
* factoryRegistry->IterateFactories(cryiidof<TPointer>(), 0, factoryCount);
* // Allocate an array of the proper length on the stack
* ICryFactory** factories = static_cast<ICryFactory**>(alloca(sizeof(ICryFactory*) * factoryCount);
* // Fill in factories with factoryCount results.
* factoryRegistry->IterateFactories(cryiidof<TPointer>(), factories, factoryCount);
* \endcode
*/
virtual void IterateFactories(const CryInterfaceID& iid, ICryFactory** pFactories, size_t& numFactories) const = 0;
protected:
// prevent explicit destruction from client side (delete, shared_ptr, etc)
virtual ~ICryFactoryRegistry() {}
};
#endif // CRYINCLUDE_CRYEXTENSION_ICRYFACTORYREGISTRY_H
@@ -0,0 +1,224 @@
/*
* 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.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
// Description : Part of CryEngine's extension framework.
#ifndef CRYINCLUDE_CRYEXTENSION_ICRYUNKNOWN_H
#define CRYINCLUDE_CRYEXTENSION_ICRYUNKNOWN_H
#pragma once
#include "CryTypeID.h"
#include <SmartPointersHelpers.h>
struct ICryFactory;
struct ICryUnknown;
namespace InterfaceCastSemantics
{
template <class T>
const CryInterfaceID& cryiidof()
{
return T::IID();
}
#define _BEFRIEND_CRYIIDOF() \
template <class T> \
friend const CryInterfaceID&InterfaceCastSemantics::cryiidof();
template <class Dst, class Src>
Dst* cryinterface_cast(Src* p)
{
return static_cast<Dst*>(p ? p->QueryInterface(cryiidof<Dst>()) : 0);
}
template <class Dst, class Src>
Dst* cryinterface_cast(const Src* p)
{
return static_cast<const Dst*>(p ? p->QueryInterface(cryiidof<Dst>()) : 0);
}
namespace Internal
{
template <class Dst, class Src>
struct cryinterface_cast_shared_ptr_helper;
template <class Dst, class Src>
struct cryinterface_cast_shared_ptr_helper
{
static AZStd::shared_ptr<Dst> Op(const AZStd::shared_ptr<Src>& p)
{
Dst* dp = cryinterface_cast<Dst>(p.get());
return dp ? AZStd::shared_ptr<Dst>(p, dp) : AZStd::shared_ptr<Dst>();
}
};
template <class Src>
struct cryinterface_cast_shared_ptr_helper<ICryUnknown, Src>
{
static AZStd::shared_ptr<ICryUnknown> Op(const AZStd::shared_ptr<Src>& p)
{
ICryUnknown* dp = cryinterface_cast<ICryUnknown>(p.get());
return dp ? AZStd::shared_ptr<ICryUnknown>(*((const AZStd::shared_ptr<ICryUnknown>*) & p), dp) : AZStd::shared_ptr<ICryUnknown>();
}
};
template <class Src>
struct cryinterface_cast_shared_ptr_helper<const ICryUnknown, Src>
{
static AZStd::shared_ptr<const ICryUnknown> Op(const AZStd::shared_ptr<Src>& p)
{
const ICryUnknown* dp = cryinterface_cast<const ICryUnknown>(p.get());
return dp ? AZStd::shared_ptr<const ICryUnknown>(*((const AZStd::shared_ptr<const ICryUnknown>*) & p), dp) : AZStd::shared_ptr<const ICryUnknown>();
}
};
} // namespace Internal
template <class Dst, class Src>
AZStd::shared_ptr<Dst> cryinterface_cast(const AZStd::shared_ptr<Src>& p)
{
return Internal::cryinterface_cast_shared_ptr_helper<Dst, Src>::Op(p);
}
#define _BEFRIEND_CRYINTERFACE_CAST() \
template <class Dst, class Src> \
friend Dst * InterfaceCastSemantics::cryinterface_cast(Src*); \
template <class Dst, class Src> \
friend Dst * InterfaceCastSemantics::cryinterface_cast(const Src*); \
template <class Dst, class Src> \
friend AZStd::shared_ptr<Dst> InterfaceCastSemantics::cryinterface_cast(const AZStd::shared_ptr<Src>&);
} // namespace InterfaceCastSemantics
using InterfaceCastSemantics::cryiidof;
using InterfaceCastSemantics::cryinterface_cast;
template <class S, class T>
bool CryIsSameClassInstance(S* p0, T* p1)
{
return static_cast<const void*>(p0) == static_cast<const void*>(p1) || cryinterface_cast<const ICryUnknown>(p0) == cryinterface_cast<const ICryUnknown>(p1);
}
template <class S, class T>
bool CryIsSameClassInstance(const AZStd::shared_ptr<S>& p0, T* p1)
{
return CryIsSameClassInstance(p0.get(), p1);
}
template <class S, class T>
bool CryIsSameClassInstance(S* p0, const AZStd::shared_ptr<T>& p1)
{
return CryIsSameClassInstance(p0, p1.get());
}
template <class S, class T>
bool CryIsSameClassInstance(const AZStd::shared_ptr<S>& p0, const AZStd::shared_ptr<T>& p1)
{
return CryIsSameClassInstance(p0.get(), p1.get());
}
namespace CompositeQuerySemantics
{
template <class Src>
AZStd::shared_ptr<ICryUnknown> crycomposite_query(Src* p, const char* name, bool* pExposed = 0)
{
void* pComposite = p ? p->QueryComposite(name) : 0;
pExposed ? *pExposed = pComposite != 0 : 0;
return pComposite ? *static_cast<AZStd::shared_ptr<ICryUnknown>*>(pComposite) : AZStd::shared_ptr<ICryUnknown>();
}
template <class Src>
AZStd::shared_ptr<const ICryUnknown> crycomposite_query(const Src* p, const char* name, bool* pExposed = 0)
{
void* pComposite = p ? p->QueryComposite(name) : 0;
pExposed ? *pExposed = pComposite != 0 : 0;
return pComposite ? *static_cast<AZStd::shared_ptr<const ICryUnknown>*>(pComposite) : AZStd::shared_ptr<const ICryUnknown>();
}
template <class Src>
AZStd::shared_ptr<ICryUnknown> crycomposite_query(const AZStd::shared_ptr<Src>& p, const char* name, bool* pExposed = 0)
{
return crycomposite_query(p.get(), name, pExposed);
}
template <class Src>
AZStd::shared_ptr<const ICryUnknown> crycomposite_query(const AZStd::shared_ptr<const Src>& p, const char* name, bool* pExposed = 0)
{
return crycomposite_query(p.get(), name, pExposed);
}
#define _BEFRIEND_CRYCOMPOSITE_QUERY() \
template <class Src> \
friend AZStd::shared_ptr<ICryUnknown> CompositeQuerySemantics::crycomposite_query(Src*, const char*, bool*); \
template <class Src> \
friend AZStd::shared_ptr<const ICryUnknown> CompositeQuerySemantics::crycomposite_query(const Src*, const char*, bool*); \
template <class Src> \
friend AZStd::shared_ptr<ICryUnknown> CompositeQuerySemantics::crycomposite_query(const AZStd::shared_ptr<Src>&, const char*, bool*); \
template <class Src> \
friend AZStd::shared_ptr<const ICryUnknown> CompositeQuerySemantics::crycomposite_query(const AZStd::shared_ptr<const Src>&, const char*, bool*);
} // namespace CompositeQuerySemantics
using CompositeQuerySemantics::crycomposite_query;
#define _BEFRIEND_MAKE_SHARED() \
template <class T> \
friend class AZStd::Internal::sp_ms_deleter; \
template <class T> \
friend AZStd::shared_ptr<T> AZStd::make_shared(); \
template <class T, class A> \
friend AZStd::shared_ptr<T> AZStd::allocate_shared(A const& a);
// prevent explicit destruction from client side
#define _PROTECTED_DTOR(iname) \
protected: \
virtual ~iname() {}
// Befriending cryinterface_cast<T>() and crycomposite_query() via CRYINTERFACE_DECLARE is actually only needed for ICryUnknown
// since QueryInterface() and QueryComposite() are usually not redeclared in derived interfaces but it doesn't hurt either
#define CRYINTERFACE_DECLARE(iname, iidHigh, iidLow) \
_BEFRIEND_CRYIIDOF() \
_BEFRIEND_CRYINTERFACE_CAST() \
_BEFRIEND_CRYCOMPOSITE_QUERY() \
_BEFRIEND_MAKE_SHARED() \
_PROTECTED_DTOR(iname) \
\
private: \
static const CryInterfaceID& IID() \
{ \
static const CryInterfaceID iid = {(uint64) iidHigh##LL, (uint64) iidLow##LL}; \
return iid; \
} \
public:
struct ICryUnknown
{
CRYINTERFACE_DECLARE(ICryUnknown, 0x1000000010001000, 0x1000100000000000)
virtual ICryFactory * GetFactory() const = 0;
protected:
virtual void* QueryInterface(const CryInterfaceID& iid) const = 0;
virtual void* QueryComposite(const char* name) const = 0;
};
DECLARE_SMART_POINTERS(ICryUnknown);
#endif // CRYINCLUDE_CRYEXTENSION_ICRYUNKNOWN_H
@@ -0,0 +1,461 @@
/*
* 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.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
// Description : Part of CryEngine's extension framework.
#ifndef CRYINCLUDE_CRYEXTENSION_IMPL_CLASSWEAVER_H
#define CRYINCLUDE_CRYEXTENSION_IMPL_CLASSWEAVER_H
#pragma once
#include "TypeList.h"
#include "Conversion.h"
#include "RegFactoryNode.h"
#include "../ICryUnknown.h"
#include "../ICryFactory.h"
#include <AzCore/Memory/Memory.h>
namespace CW
{
namespace Internal
{
template <class Dst>
struct InterfaceCast;
template <class Dst>
struct InterfaceCast
{
template <class T>
static void* Op(T* p)
{
return (Dst*) p;
}
};
template <>
struct InterfaceCast<ICryUnknown>
{
template <class T>
static void* Op(T* p)
{
return const_cast<ICryUnknown*>(static_cast<const ICryUnknown*>(static_cast<const void*>(p)));
}
};
}
template <class TList>
struct InterfaceCast;
template <>
struct InterfaceCast<TL::NullType>
{
template <class T>
static void* Op(T*, const CryInterfaceID&)
{
return 0;
}
};
template <class Head, class Tail>
struct InterfaceCast<TL::Typelist<Head, Tail> >
{
template <class T>
static void* Op(T* p, const CryInterfaceID& iid)
{
if (cryiidof<Head>() == iid)
{
return Internal::InterfaceCast<Head>::Op(p);
}
return InterfaceCast<Tail>::Op(p, iid);
}
};
template <class TList>
struct FillIIDs;
template <>
struct FillIIDs<TL::NullType>
{
static void Op(CryInterfaceID*)
{
}
};
template <class Head, class Tail>
struct FillIIDs<TL::Typelist<Head, Tail> >
{
static void Op(CryInterfaceID* p)
{
*p++ = cryiidof<Head>();
FillIIDs<Tail>::Op(p);
}
};
namespace Internal
{
template <bool, typename S>
struct PickList;
template <bool, typename S>
struct PickList
{
typedef TL::BuildTypelist<>::Result Result;
};
template <typename S>
struct PickList<true, S>
{
typedef typename S::FullCompositeList Result;
};
}
template <typename T>
struct ProbeFullCompositeList
{
private:
typedef char y[1];
typedef char n[2];
template <typename S>
static y& test(typename S::FullCompositeList*);
template <typename>
static n& test(...);
public:
enum
{
listFound = sizeof(test<T>(0)) == sizeof(y)
};
typedef typename Internal::PickList<listFound, T>::Result ListType;
};
namespace Internal
{
template <class TList>
struct CompositeQuery;
template <>
struct CompositeQuery<TL::NullType>
{
template<typename T>
static void* Op(const T&, const char*)
{
return 0;
}
};
template <class Head, class Tail>
struct CompositeQuery<TL::Typelist<Head, Tail> >
{
template<typename T>
static void* Op(const T& ref, const char* name)
{
void* p = ref.Head::CompositeQueryImpl(name);
return p ? p : CompositeQuery<Tail>::Op(ref, name);
}
};
}
struct CompositeQuery
{
template <typename T>
static void* Op(const T& ref, const char* name)
{
return Internal::CompositeQuery<typename ProbeFullCompositeList<T>::ListType>::Op(ref, name);
}
};
inline bool NameMatch(const char* name, const char* compositeName)
{
if (!name || !compositeName)
{
return false;
}
size_t i = 0;
for (; name[i] && name[i] == compositeName[i]; ++i)
{
}
return name[i] == compositeName[i];
}
template <typename T>
void* CheckCompositeMatch(const char* name, const AZStd::shared_ptr<T>& composite, const char* compositeName)
{
typedef TC::SuperSubClass<ICryUnknown, T> Rel;
COMPILE_TIME_ASSERT(Rel::exists);
return NameMatch(name, compositeName) ? const_cast<void*>(static_cast<const void*>(&composite)) : 0;
}
} // namespace CW
#define CRYINTERFACE_BEGIN() \
private: \
typedef TL::BuildTypelist < ICryUnknown
#define CRYINTERFACE_ADD(iname) , iname
#define CRYINTERFACE_END() > ::Result _UserDefinedPartialInterfaceList; \
protected: \
typedef TL::NoDuplicates<_UserDefinedPartialInterfaceList>::Result FullInterfaceList;
#define _CRY_TPL_APPEND0(base) TL::Append<base::FullInterfaceList, _UserDefinedPartialInterfaceList>::Result
#define _CRY_TPL_APPEND(base, intermediate) TL::Append<base::FullInterfaceList, intermediate>::Result
#define CRYINTERFACE_ENDWITHBASE(base) > ::Result _UserDefinedPartialInterfaceList; \
protected: \
typedef TL::NoDuplicates<_CRY_TPL_APPEND0(base)>::Result FullInterfaceList;
#define CRYINTERFACE_ENDWITHBASE2(base0, base1) > ::Result _UserDefinedPartialInterfaceList; \
protected: \
typedef TL::NoDuplicates<_CRY_TPL_APPEND(base0, _CRY_TPL_APPEND0(base1))>::Result FullInterfaceList;
#define CRYINTERFACE_ENDWITHBASE3(base0, base1, base2) > ::Result _UserDefinedPartialInterfaceList; \
protected: \
typedef TL::NoDuplicates<_CRY_TPL_APPEND(base0, _CRY_TPL_APPEND(base1, _CRY_TPL_APPEND0(base2)))>::Result FullInterfaceList;
#define CRYINTERFACE_SIMPLE(iname) \
CRYINTERFACE_BEGIN() \
CRYINTERFACE_ADD(iname) \
CRYINTERFACE_END()
#define CRYCOMPOSITE_BEGIN() \
private: \
void* CompositeQueryImpl(const char* name) const \
{ \
(void)(name); \
void* res = 0; (void)(res); \
#define CRYCOMPOSITE_ADD(member, membername) \
COMPILE_TIME_ASSERT((sizeof(membername) / sizeof(membername[0])) > 1); \
if ((res = CW::CheckCompositeMatch(name, member, membername)) != 0) { \
return res; }
#define _CRYCOMPOSITE_END(implclassname) \
return 0; \
}; \
protected: \
typedef TL::BuildTypelist<implclassname>::Result _PartialCompositeList; \
\
template <bool, typename S> \
friend struct CW::Internal::PickList;
#define CRYCOMPOSITE_END(implclassname) \
_CRYCOMPOSITE_END(implclassname) \
protected: \
typedef _PartialCompositeList FullCompositeList;
#define _CRYCOMPOSITE_APPEND0(base) TL::Append<_PartialCompositeList, CW::ProbeFullCompositeList<base>::ListType>::Result
#define _CRYCOMPOSITE_APPEND(base, intermediate) TL::Append<intermediate, CW::ProbeFullCompositeList<base>::ListType>::Result
#define CRYCOMPOSITE_ENDWITHBASE(implclassname, base) \
_CRYCOMPOSITE_END(implclassname) \
protected: \
typedef _CRYCOMPOSITE_APPEND0 (base) FullCompositeList;
#define CRYCOMPOSITE_ENDWITHBASE2(implclassname, base0, base1) \
_CRYCOMPOSITE_END(implclassname) \
protected: \
typedef TL::NoDuplicates<_CRYCOMPOSITE_APPEND(base1, _CRYCOMPOSITE_APPEND0(base0))>::Result FullCompositeList;
#define CRYCOMPOSITE_ENDWITHBASE3(implclassname, base0, base1, base2) \
_CRYCOMPOSITE_END(implclassname) \
protected: \
typedef TL::NoDuplicates<_CRYCOMPOSITE_APPEND(base2, _CRYCOMPOSITE_APPEND(base1, _CRYCOMPOSITE_APPEND0(base0)))>::Result FullCompositeList;
template<typename T>
class CFactory
: public ICryFactory
{
public:
virtual const char* GetName() const
{
return T::GetCName();
}
virtual const CryClassID& GetClassID() const
{
return T::GetCID();
}
virtual bool ClassSupports(const CryInterfaceID& iid) const
{
for (size_t i = 0; i < m_numIIDs; ++i)
{
if (iid == m_pIIDs[i])
{
return true;
}
}
return false;
}
virtual void ClassSupports(const CryInterfaceID*& pIIDs, size_t& numIIDs) const
{
pIIDs = m_pIIDs;
numIIDs = m_numIIDs;
}
public:
virtual ICryUnknownPtr CreateClassInstance() const
{
AZStd::shared_ptr<T> p = AZStd::make_shared<T>();
return cryinterface_cast<ICryUnknown> (p);
}
CFactory<T>()
: m_numIIDs(0)
, m_pIIDs(0)
, m_regFactory()
{
static CryInterfaceID supportedIIDs[TL::Length < typename T::FullInterfaceList > ::value];
CW::FillIIDs<typename T::FullInterfaceList>::Op(supportedIIDs);
m_pIIDs = &supportedIIDs[0];
m_numIIDs = TL::Length<typename T::FullInterfaceList>::value;
new(&m_regFactory)SRegFactoryNode(this);
}
protected:
CFactory(const CFactory&);
CFactory& operator =(const CFactory&);
size_t m_numIIDs;
CryInterfaceID* m_pIIDs;
SRegFactoryNode m_regFactory;
};
template<typename T>
class CSingletonFactory
: public CFactory<T>
{
public:
CSingletonFactory()
: CFactory<T>()
, m_csCreateClassInstance()
{
}
virtual ICryUnknownPtr CreateClassInstance() const
{
CryAutoLock<CryCriticalSection> lock(m_csCreateClassInstance);
// override the allocator. These function static instances are being destroyed after the AZ alloctor has been deleted.
// On win, TerminateProcess() prevents these destructors from being called, but that is not the case on OSX.
static typename AZStd::aligned_storage<sizeof(AZStd::Internal::sp_counted_impl_pda<T*, AZStd::Internal::sp_ms_deleter<T>,SingletonAllocator>), AZStd::alignment_of<T>::value>::type m_storage;
static ICryUnknownPtr p = AZStd::allocate_shared<T>(SingletonAllocator(AZStd::addressof(m_storage)));
return p;
}
mutable CryCriticalSection m_csCreateClassInstance;
struct SingletonAllocator
{
SingletonAllocator(void* ptr) :
m_data(ptr)
{}
void* allocate(size_t /*byteSize*/, size_t /*alignment*/, int /*flags*/ = 0)
{
return m_data;
}
void deallocate(void* /*ptr*/, size_t /*byteSize*/, size_t /*alignment*/)
{
// nothing to see here
}
void* m_data;
};
};
#define _CRYFACTORY_DECLARE(implclassname) \
private: \
friend class CFactory<implclassname>; \
static CFactory<implclassname> s_factory;
#define _CRYFACTORY_DECLARE_SINGLETON(implclassname) \
private: \
friend class CFactory<implclassname>; \
friend void* Get##implclassname##Factory(); \
static CSingletonFactory<implclassname> s_factory;
#define _IMPLEMENT_ICRYUNKNOWN() \
public: \
virtual ICryFactory* GetFactory() const \
{ \
return &s_factory; \
} \
\
protected: \
virtual void* QueryInterface(const CryInterfaceID&iid) const \
{ \
return CW::InterfaceCast<FullInterfaceList>::Op(this, iid); \
} \
\
template <class TList> \
friend struct CW::Internal::CompositeQuery; \
\
virtual void* QueryComposite(const char* name) const \
{ \
return CW::CompositeQuery::Op(*this, name); \
}
#define _ENFORCE_CRYFACTORY_USAGE(implclassname, cname, cidHigh, cidLow) \
public: \
static const char* GetCName() \
{ \
return cname; \
} \
static const CryClassID& GetCID() \
{ \
static const CryClassID cid = {(uint64) cidHigh##LL, (uint64) cidLow##LL}; \
return cid; \
} \
static AZStd::shared_ptr<implclassname> CreateClassInstance() \
{ \
ICryUnknownPtr p = s_factory.CreateClassInstance(); \
return AZStd::shared_ptr<implclassname>(*static_cast<AZStd::shared_ptr<implclassname>*>(static_cast<void*>(&p))); \
} \
\
protected: \
implclassname(); \
virtual ~implclassname();
#define _BEFRIEND_OPS() \
_BEFRIEND_CRYINTERFACE_CAST() \
_BEFRIEND_CRYCOMPOSITE_QUERY() \
_BEFRIEND_MAKE_SHARED()
#define CRYGENERATE_CLASS(implclassname, cname, cidHigh, cidLow) \
_CRYFACTORY_DECLARE(implclassname) \
_BEFRIEND_OPS() \
_IMPLEMENT_ICRYUNKNOWN() \
_ENFORCE_CRYFACTORY_USAGE(implclassname, cname, cidHigh, cidLow)
#define CRYGENERATE_SINGLETONCLASS(implclassname, cname, cidHigh, cidLow) \
_CRYFACTORY_DECLARE_SINGLETON(implclassname) \
_BEFRIEND_OPS() \
_IMPLEMENT_ICRYUNKNOWN() \
_ENFORCE_CRYFACTORY_USAGE(implclassname, cname, cidHigh, cidLow)
#define CRYREGISTER_CLASS(implclassname) \
CFactory<implclassname> implclassname::s_factory;
#define DECLARE_CRYREGISTER_SINGLETON_CLASS(implclassname) \
void* Get##implclassname##Factory();
#define CRYREGISTER_SINGLETON_CLASS(implclassname) \
CSingletonFactory<implclassname> implclassname::s_factory; \
void* Get##implclassname##Factory() { \
return &implclassname::s_factory; \
}
#endif // CRYINCLUDE_CRYEXTENSION_IMPL_CLASSWEAVER_H
@@ -0,0 +1,109 @@
/*
* 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.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
// Description : Part of CryEngine's extension framework.
#ifndef CRYINCLUDE_CRYEXTENSION_IMPL_CONVERSION_H
#define CRYINCLUDE_CRYEXTENSION_IMPL_CONVERSION_H
#pragma once
namespace TC
{
//template <class T, class U>
//struct Conversion
//{
//private:
// typedef char y[1];
// typedef char n[2];
// static y& Test(U);
// static n& Test(...);
// static T MakeT();
//public:
// enum
// {
// exists = sizeof(Test(MakeT())) == sizeof(y),
// sameType = false
// };
//};
//template <class T>
//struct Conversion<T, T>
//{
//public:
// enum
// {
// exists = true,
// sameType = true
// };
//};
//template<typename Base, typename Derived>
//struct CheckInheritance
//{
// enum
// {
// exists = Conversion<const Derived*, const Base*>::exists && !Conversion<const Base*, const void*>::sameType
// };
//};
//template<typename Base, typename Derived>
//struct CheckStrictInheritance
//{
// enum
// {
// exists = CheckInheritance<Base, Derived>::exists && !Conversion<const Base*, const Derived*>::sameType
// };
//};
template <typename Base, typename Derived>
struct SuperSubClass
{
private:
typedef char y[1];
typedef char n[2];
template<typename T>
static y& check(const volatile Derived&, T);
static n& check(const volatile Base&, int);
struct C
{
operator const volatile Base&() const;
operator const volatile Derived&();
};
static C getC();
public:
enum
{
exists = sizeof(check(getC(), 0)) == sizeof(y),
sameType = false
};
};
template <typename T>
struct SuperSubClass<T, T>
{
enum
{
exists = true
};
};
} // namespace TC
#endif // CRYINCLUDE_CRYEXTENSION_IMPL_CONVERSION_H
@@ -0,0 +1,67 @@
/*
* 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.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
// Description : Part of CryEngine's extension framework.
#ifndef CRYINCLUDE_CRYEXTENSION_IMPL_CRYGUIDHELPER_H
#define CRYINCLUDE_CRYEXTENSION_IMPL_CRYGUIDHELPER_H
#pragma once
#include "../CryGUID.h"
#include "../../CryString.h"
namespace CryGUIDHelper
{
string Print(const CryGUID& val)
{
char buf[39]; // sizeof("{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}")
static const char hex[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
char* p = buf;
*p++ = '{';
for (int i = 15; i >= 8; --i)
{
*p++ = hex[(unsigned char) ((val.hipart >> (i << 2)) & 0xF)];
}
*p++ = '-';
for (int i = 7; i >= 4; --i)
{
*p++ = hex[(unsigned char) ((val.hipart >> (i << 2)) & 0xF)];
}
*p++ = '-';
for (int i = 3; i >= 0; --i)
{
*p++ = hex[(unsigned char) ((val.hipart >> (i << 2)) & 0xF)];
}
*p++ = '-';
for (int i = 15; i >= 12; --i)
{
*p++ = hex[(unsigned char) ((val.lopart >> (i << 2)) & 0xF)];
}
*p++ = '-';
for (int i = 11; i >= 0; --i)
{
*p++ = hex[(unsigned char) ((val.lopart >> (i << 2)) & 0xF)];
}
*p++ = '}';
*p++ = '\0';
return string(buf);
}
}
#endif // CRYINCLUDE_CRYEXTENSION_IMPL_CRYGUIDHELPER_H
@@ -0,0 +1,58 @@
/*
* 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.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
// Description : Part of CryEngine's extension framework.
#ifndef CRYINCLUDE_CRYEXTENSION_IMPL_ICRYFACTORYREGISTRYIMPL_H
#define CRYINCLUDE_CRYEXTENSION_IMPL_ICRYFACTORYREGISTRYIMPL_H
#pragma once
#include "../ICryFactoryRegistry.h"
struct SRegFactoryNode;
struct ICryFactoryRegistryCallback
{
virtual void OnNotifyFactoryRegistered(ICryFactory* pFactory) = 0;
virtual void OnNotifyFactoryUnregistered(ICryFactory* pFactory) = 0;
protected:
virtual ~ICryFactoryRegistryCallback() {}
};
struct ICryFactoryRegistryImpl
: public ICryFactoryRegistry
{
virtual ICryFactory* GetFactory(const char* cname) const = 0;
virtual ICryFactory* GetFactory(const CryClassID& cid) const = 0;
virtual void IterateFactories(const CryInterfaceID& iid, ICryFactory** pFactories, size_t& numFactories) const = 0;
virtual void RegisterCallback(ICryFactoryRegistryCallback* pCallback) = 0;
virtual void UnregisterCallback(ICryFactoryRegistryCallback* pCallback) = 0;
virtual void RegisterFactories(const SRegFactoryNode* pFactories) = 0;
virtual void UnregisterFactories(const SRegFactoryNode* pFactories) = 0;
virtual void UnregisterFactory(ICryFactory* const pFactory) = 0;
protected:
// prevent explicit destruction from client side (delete, shared_ptr, etc)
virtual ~ICryFactoryRegistryImpl() {}
};
#endif // CRYINCLUDE_CRYEXTENSION_IMPL_ICRYFACTORYREGISTRYIMPL_H
@@ -0,0 +1,52 @@
/*
* 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.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
// Description : Part of CryEngine's extension framework.
#ifndef CRYINCLUDE_CRYEXTENSION_IMPL_REGFACTORYNODE_H
#define CRYINCLUDE_CRYEXTENSION_IMPL_REGFACTORYNODE_H
#pragma once
struct ICryFactory;
struct SRegFactoryNode;
extern SRegFactoryNode* g_pHeadToRegFactories;
struct SRegFactoryNode
{
SRegFactoryNode()
{
}
SRegFactoryNode(ICryFactory* pFactory)
: m_pFactory(pFactory)
, m_pNext(g_pHeadToRegFactories)
{
g_pHeadToRegFactories = this;
}
static void* operator new(size_t, void* p)
{
return p;
}
static void operator delete(void*, void*)
{
}
ICryFactory* m_pFactory;
SRegFactoryNode* m_pNext;
};
#endif // CRYINCLUDE_CRYEXTENSION_IMPL_REGFACTORYNODE_H
@@ -0,0 +1,236 @@
/*
* 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.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
// Description : Part of CryEngine's extension framework.
#ifndef CRYINCLUDE_CRYEXTENSION_TYPELIST_H
#define CRYINCLUDE_CRYEXTENSION_TYPELIST_H
#pragma once
namespace TL
{
// typelist terminator
class NullType
{
};
// structure for typelist generation
template <class T, class U = NullType>
struct Typelist
{
typedef T Head;
typedef U Tail;
};
// helper structure to automatically build typelists containing n types
template
<
typename T0 = NullType, typename T1 = NullType, typename T2 = NullType, typename T3 = NullType, typename T4 = NullType,
typename T5 = NullType, typename T6 = NullType, typename T7 = NullType, typename T8 = NullType, typename T9 = NullType,
typename T10 = NullType, typename T11 = NullType, typename T12 = NullType, typename T13 = NullType, typename T14 = NullType,
typename T15 = NullType, typename T16 = NullType, typename T17 = NullType, typename T18 = NullType, typename T19 = NullType
>
struct BuildTypelist
{
private:
typedef typename BuildTypelist<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19>::Result TailResult;
public:
typedef Typelist<T0, TailResult> Result;
};
template <>
struct BuildTypelist<>
{
typedef NullType Result;
};
// typelist operation : Length
template <class TList>
struct Length;
template <>
struct Length<NullType>
{
enum
{
value = 0
};
};
template <class T, class U>
struct Length<Typelist<T, U> >
{
enum
{
value = 1 + Length<U>::value
};
};
// typelist operation : TypeAt
template <class TList, unsigned int index>
struct TypeAt;
template <class Head, class Tail>
struct TypeAt<Typelist<Head, Tail>, 0>
{
typedef Head Result;
};
template <class Head, class Tail, unsigned int index>
struct TypeAt<Typelist<Head, Tail>, index>
{
typedef typename TypeAt<Tail, index - 1>::Result Result;
};
// typelist operation : IndexOf
template <class TList, class T>
struct IndexOf;
template <class T>
struct IndexOf<NullType, T>
{
enum
{
value = -1
};
};
template <class T, class Tail>
struct IndexOf<Typelist<T, Tail>, T>
{
enum
{
value = 0
};
};
template <class Head, class Tail, class T>
struct IndexOf<Typelist<Head, Tail>, T>
{
private:
enum
{
temp = IndexOf<Tail, T>::value
};
public:
enum
{
value = temp == -1 ? -1 : 1 + temp
};
};
// typelist operation : Append
template <class TList, class T>
struct Append;
template <>
struct Append<NullType, NullType>
{
typedef NullType Result;
};
template <class T>
struct Append<NullType, T>
{
typedef Typelist<T, NullType> Result;
};
template <class Head, class Tail>
struct Append<NullType, Typelist<Head, Tail> >
{
typedef Typelist<Head, Tail> Result;
};
template <class Head, class Tail, class T>
struct Append<Typelist<Head, Tail>, T>
{
typedef Typelist<Head, typename Append<Tail, T>::Result> Result;
};
// typelist operation : Erase
template <class TList, class T>
struct Erase;
template <class T>
struct Erase<NullType, T>
{
typedef NullType Result;
};
template <class T, class Tail>
struct Erase<Typelist<T, Tail>, T>
{
typedef Tail Result;
};
template <class Head, class Tail, class T>
struct Erase<Typelist<Head, Tail>, T>
{
typedef Typelist<Head, typename Erase<Tail, T>::Result> Result;
};
// typelist operation : Erase All
template <class TList, class T>
struct EraseAll;
template <class T>
struct EraseAll<NullType, T>
{
typedef NullType Result;
};
template <class T, class Tail>
struct EraseAll<Typelist<T, Tail>, T>
{
typedef typename EraseAll<Tail, T>::Result Result;
};
template <class Head, class Tail, class T>
struct EraseAll<Typelist<Head, Tail>, T>
{
typedef Typelist<Head, typename EraseAll<Tail, T>::Result> Result;
};
// typelist operation : NoDuplicates
template <class TList>
struct NoDuplicates;
template <>
struct NoDuplicates<NullType>
{
typedef NullType Result;
};
template <class Head, class Tail>
struct NoDuplicates<Typelist<Head, Tail> >
{
private:
typedef typename NoDuplicates<Tail>::Result L1;
typedef typename Erase<L1, Head>::Result L2;
public:
typedef Typelist<Head, L2> Result;
};
} // namespace TL
#endif // CRYINCLUDE_CRYEXTENSION_TYPELIST_H