aboutsummaryrefslogtreecommitdiff
path: root/APEX_1.4/common/include/ApexLegacyModule.h
blob: 49ef03586264570b77b3a85ea485038492324242 (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
163
164
165
166
167
168
169
170
/*
 * Copyright (c) 2008-2017, NVIDIA CORPORATION.  All rights reserved.
 *
 * NVIDIA CORPORATION and its licensors retain all intellectual property
 * and proprietary rights in and to this software, 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.
 */


#ifndef APEX_LEGACY_MODULE
#define APEX_LEGACY_MODULE

#include "nvparameterized/NvParameterizedTraits.h"

#include "ModuleIntl.h"
#include "ModuleBase.h"

namespace nvidia
{
namespace apex
{

struct LegacyClassEntry
{
	uint32_t version;
	uint32_t nextVersion;
	NvParameterized::Factory* factory;
	void (*freeParameterDefinitionTable)(NvParameterized::Traits* t);
	NvParameterized::Conversion* (*createConv)(NvParameterized::Traits*);
	NvParameterized::Conversion* conv;
};

template<typename IFaceT>
class TApexLegacyModule : public IFaceT, public ModuleIntl, public ModuleBase
{
public:
	virtual ~TApexLegacyModule() {}

	// base class methods
	void						init(NvParameterized::Interface&) {}

	NvParameterized::Interface* getDefaultModuleDesc()
	{
		return 0;
	}

	void release()
	{
		ModuleBase::release();
	}
	void destroy()
	{
		releaseLegacyObjects();
		ModuleBase::destroy();
		delete this;
	}

	const char*					getName() const
	{
		return ModuleBase::getName();
	}

	ModuleSceneIntl* 				createInternalModuleScene(SceneIntl&, RenderDebugInterface*)
	{
		return NULL;
	}
	void						releaseModuleSceneIntl(ModuleSceneIntl&) {}
	uint32_t				forceLoadAssets()
	{
		return 0;
	}
	AuthObjTypeID				getModuleID() const
	{
		return UINT32_MAX;
	}
	RenderableIterator* 	createRenderableIterator(const Scene&)
	{
		return NULL;
	}

protected:
	virtual void releaseLegacyObjects() = 0;

	void registerLegacyObjects(LegacyClassEntry* e)
	{
		NvParameterized::Traits* t = mSdk->getParameterizedTraits();
		if (!t)
		{
			return;
		}

		for (; e->factory; ++e)
		{
			t->registerFactory(*e->factory);

			e->conv = e->createConv(t);
			t->registerConversion(e->factory->getClassName(), e->version, e->nextVersion, *e->conv);
		}
	}

	void unregisterLegacyObjects(LegacyClassEntry* e)
	{
		NvParameterized::Traits* t = mSdk->getParameterizedTraits();
		if (!t)
		{
			return;
		}

		for (; e->factory; ++e)
		{
			t->removeConversion(
			    e->factory->getClassName(),
			    e->version,
			    e->nextVersion
			);
			e->conv->release();

			t->removeFactory(e->factory->getClassName(), e->factory->getVersion());

			e->freeParameterDefinitionTable(t);
		}
	}
};

typedef TApexLegacyModule<Module> ApexLegacyModule;

} // namespace apex
} // namespace nvidia

#define DEFINE_CREATE_MODULE(ModuleBase) \
	ApexSDKIntl* gApexSdk = 0; \
	ApexSDK* GetApexSDK() { return gApexSdk; } \
	ApexSDKIntl* GetInternalApexSDK() { return gApexSdk; } \
	APEX_API Module*  CALL_CONV createModule( \
	        ApexSDKIntl* inSdk, \
	        ModuleIntl** niRef, \
	        uint32_t APEXsdkVersion, \
	        uint32_t PhysXsdkVersion, \
	        ApexCreateError* errorCode) \
	{ \
		if (APEXsdkVersion != APEX_SDK_VERSION) \
		{ \
			if (errorCode) *errorCode = APEX_CE_WRONG_VERSION; \
			return NULL; \
		} \
		\
		if (PhysXsdkVersion != PHYSICS_SDK_VERSION) \
		{ \
			if (errorCode) *errorCode = APEX_CE_WRONG_VERSION; \
			return NULL; \
		} \
		\
		gApexSdk = inSdk; \
		\
		ModuleBase *impl = PX_NEW(ModuleBase)(inSdk); \
		*niRef  = (ModuleIntl *) impl; \
		return (Module *) impl; \
	}

#define DEFINE_INSTANTIATE_MODULE(ModuleBase) \
	void instantiate##ModuleBase() \
	{ \
		ApexSDKIntl *sdk = GetInternalApexSDK(); \
		ModuleBase *impl = PX_NEW(ModuleBase)(sdk); \
		sdk->registerExternalModule((Module *) impl, (ModuleIntl *) impl); \
	}

#endif // __APEX_LEGACY_MODULE__