aboutsummaryrefslogtreecommitdiff
path: root/sdk/toolkit/source/NvBlastTkFrameworkImpl.h
blob: 1310bebf599351bc1f7f0a5038699b54016c28e7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
// This code contains NVIDIA Confidential Information and is disclosed to you
// under a form of NVIDIA software license agreement provided separately to you.
//
// Notice
// NVIDIA Corporation and its licensors retain all intellectual property and
// proprietary rights in and to this software and related documentation and
// any modifications thereto. Any use, reproduction, disclosure, or
// distribution of this software and related documentation without an express
// license agreement from NVIDIA Corporation is strictly prohibited.
//
// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES
// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT,
// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
//
// Information and code furnished is believed to be accurate and reliable.
// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such
// information or for any infringement of patents or other rights of third parties that may
// result from its use. No license is granted by implication or otherwise under any patent
// or patent rights of NVIDIA Corporation. Details are subject to change without notice.
// This code supersedes and replaces all information previously supplied.
// NVIDIA Corporation products are not authorized for use as critical
// components in life support devices or systems without express written approval of
// NVIDIA Corporation.
//
// Copyright (c) 2016-2020 NVIDIA Corporation. All rights reserved.


#ifndef NVBLASTTKFRAMEWORKIMPL_H
#define NVBLASTTKFRAMEWORKIMPL_H

#include "NvBlastTkFramework.h"
#include "NvBlastProfilerInternal.h"

#include "NvBlastTkCommon.h"

#include "NvBlastArray.h"
#include "NvBlastHashMap.h"
#include "NvBlastHashSet.h"


namespace Nv
{
namespace Blast
{

// Forward declarations
class TkTypeImpl;
class TkJointImpl;

/**
Implementation of TkFramework
*/
class TkFrameworkImpl : public TkFramework
{
public:
										TkFrameworkImpl();
										~TkFrameworkImpl();

	// Begin TkFramework
	virtual void						release() override;

	virtual const TkType*				getType(TkTypeIndex::Enum typeIndex) const override;

	virtual TkIdentifiable*				findObjectByID(const NvBlastID& id) const override;

	virtual uint32_t					getObjectCount(const TkType& type) const override;

	virtual uint32_t					getObjects(TkIdentifiable** buffer, uint32_t bufferSize, const TkType& type, uint32_t indexStart = 0) const override;

	virtual bool						reorderAssetDescChunks(NvBlastChunkDesc* chunkDescs, uint32_t chunkCount, NvBlastBondDesc* bondDescs, uint32_t bondCount, uint32_t* chunkReorderMap = nullptr, bool keepBondNormalChunkOrder = false) const override;

	virtual bool						ensureAssetExactSupportCoverage(NvBlastChunkDesc* chunkDescs, uint32_t chunkCount) const override;

	virtual TkAsset*					createAsset(const TkAssetDesc& desc) override;

	virtual TkAsset*					createAsset(const NvBlastAsset* assetLL, Nv::Blast::TkAssetJointDesc* jointDescs = nullptr, uint32_t jointDescCount = 0, bool ownsAsset = false) override;

	virtual TkGroup*					createGroup(const TkGroupDesc& desc) override;

	virtual TkActor*					createActor(const TkActorDesc& desc) override;

	virtual TkJoint*					createJoint(const TkJointDesc& desc) override;
	// End TkFramework

	// Public methods
	/**
	To be called by any TkIdentifiable object when it is created, so the framework can track it.
	*/
	void								onCreate(TkIdentifiable& object);

	/**
	To be called by any TkIdentifiable object when it is deleted, so the framework can stop tracking it.
	*/
	void								onDestroy(TkIdentifiable& object);

	/**
	Special onCreate method for joints, since they are not TkIdentifiable.
	*/
	void								onCreate(TkJointImpl& joint);

	/**
	Special onDestroy method for joints, since they are not TkIdentifiable.
	*/
	void								onDestroy(TkJointImpl& joint);

	/**
	Must be called whenever a TkIdentifiable object's ID is changed, so that the framework can associate the new ID with it.
	*/
	void								onIDChange(TkIdentifiable& object, const NvBlastID& IDPrev, const NvBlastID& IDCurr);

	/**
	Internal (non-virtual) method to find a TkIdentifiable object based upon its NvBlastID.
	*/
	TkIdentifiable*						findObjectByIDInternal(const NvBlastID& id) const;

	// Access to singleton

	/** Retrieve the global singleton. */
	static TkFrameworkImpl*				get();

	/** Set the global singleton, if it's not already set, or set it to NULL.  Returns true iff successful. */
	static bool							set(TkFrameworkImpl* framework);

private:
	// Enums
	enum { ClassID = NVBLAST_FOURCC('T', 'K', 'F', 'W') };	//!< TkFramework identifier token, used in serialization

	// Static data
	static TkFrameworkImpl*														s_framework;			//!< Global (singleton) object pointer

	// Types
	InlineArray<const TkTypeImpl*, TkTypeIndex::TypeCount>::type				m_types;				//!< TkIdentifiable static type data
	HashMap<uint32_t, uint32_t>::type											m_typeIDToIndex;		//!< Map to type data keyed by ClassID

	// Objects and object names
	HashMap<NvBlastID, TkIdentifiable*>::type									m_IDToObject;			//!< Map to all TkIdentifiable objects, keyed by NvBlastID
	InlineArray<Array<TkIdentifiable*>::type, TkTypeIndex::TypeCount>::type		m_objects;				//!< Catalog of all TkIdentifiable objects, grouped by type.  (Revisit implementation.)

	// Track external joints (to do: make this a pool)
	HashSet<TkJointImpl*>::type													m_joints;				//!< All internal joints
};


//////// TkFrameworkImpl inline methods ////////

NV_INLINE TkIdentifiable* TkFrameworkImpl::findObjectByIDInternal(const NvBlastID& id) const
{
	const auto entry = m_IDToObject.find(id);
	if (entry == nullptr)
	{
		return nullptr;
	}

	return entry->second;
}

} // namespace Blast
} // namespace Nv


#endif // ifndef NVBLASTTKFRAMEWORKIMPL_H