summaryrefslogtreecommitdiffstats
path: root/src/modelinfo/BaseModelInfo.cpp
blob: 7cb72009a5e9052848c19b9624a1f0a3b51442b8 (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
#include "common.h"

#include "templates.h"
#include "main.h"
#include "TxdStore.h"
#include "2dEffect.h"
#include "BaseModelInfo.h"
#include "ModelInfo.h"
#include "KeyGen.h"
#include "Streaming.h"
#include "smallHeap.h"

// LCS: file done except for TODO

CBaseModelInfo::CBaseModelInfo(ModelInfoType type)
{
	m_colModel = nil;
	m_2dEffectsID = -1;
	m_objectId = -1;
	m_refCount = 0;
	m_txdSlot = -1;
	m_type = type;
	m_num2dEffects = 0;
	m_bOwnsColModel = false;
	m_nameKey = 0;
	m_unk1 = 0;
	m_unk2 = 0;
	m_name = new char[MAX_MODEL_NAME];
	*(int32*)m_name = 0;
}

void
CBaseModelInfo::Shutdown(void)
{
	DeleteCollisionModel();
	DeleteRwObject();
	DeleteChunk();
	m_2dEffectsID = -1;
	m_num2dEffects = 0;
	m_txdSlot = -1;
}

void
CBaseModelInfo::DeleteCollisionModel(void)
{
	if(!gUseChunkFiles && m_colModel && m_bOwnsColModel){
		if(m_colModel)
			delete m_colModel;
	}
	m_colModel = nil;
}

void
CBaseModelInfo::AddRef(void)
{
	m_refCount++;
	AddTexDictionaryRef();
}

void
CBaseModelInfo::RemoveRef(void)
{
	if(m_refCount > 0){
		m_refCount--;
		RemoveTexDictionaryRef();
	}
}

void
CBaseModelInfo::SetTexDictionary(const char *name)
{
	int slot = CTxdStore::FindTxdSlot(name);
	if(slot == -1)
		slot = CTxdStore::AddTxdSlot(name);
	m_txdSlot = slot;
}

void
CBaseModelInfo::AddTexDictionaryRef(void)
{
	CTxdStore::AddRef(m_txdSlot);
}

void
CBaseModelInfo::AddTexDictionaryRefGu(void)
{
	CTxdStore::AddRefGu(m_txdSlot);
}

void
CBaseModelInfo::RemoveTexDictionaryRef(void)
{
	CTxdStore::RemoveRef(m_txdSlot);
}

void
CBaseModelInfo::RemoveTexDictionaryRefGu(void)
{
	CTxdStore::RemoveRefGu(m_txdSlot);
}

void
CBaseModelInfo::Init2dEffects(void)
{
	m_2dEffectsID = -1;
	m_num2dEffects = 0;
}

void
CBaseModelInfo::Add2dEffect(C2dEffect *fx)
{
	if(m_2dEffectsID >= 0)
		m_num2dEffects++;
	else{
		m_2dEffectsID = CModelInfo::Get2dEffectStore().GetIndex(fx);
		m_num2dEffects = 1;
	}
}

C2dEffect*
CBaseModelInfo::Get2dEffect(int n)
{
	if(m_2dEffectsID >= 0)
		return CModelInfo::Get2dEffectStore().GetItem(m_2dEffectsID+n);
	else
		return nil;
}


void
CBaseModelInfo::SetModelName(const char *name)
{
	m_nameKey = CKeyGen::GetUppercaseKey(name);
	if (!gUseChunkFiles)
		strcpy(m_name, name);
}

void
CBaseModelInfo::DeleteChunk(void)
{
	// BUG? what if we're not using chunks?
	if(m_chunk){
		CStreaming::UnregisterPointer(&m_chunk, 2);
		cSmallHeap::msInstance.Free(m_chunk);
		m_chunk = nil;
	}
}

void
CBaseModelInfo::Write(base::cRelocatableChunkWriter &writer)
{
	m_chunk = nil;
	RcWriteThis(writer);
	if(m_colModel){
		assert(0 && "TODO");
	}
}