-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathObjectSelection.cpp
212 lines (190 loc) · 7.82 KB
/
ObjectSelection.cpp
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#include "ObjectSelection.h"
object * GetSingleInstace(LPRDATA rdPtr, short Oi)
{
LPRH rhPtr = rdPtr->rHo.hoAdRunHeader; // get a pointer to the mmf runtime header
LPOBL ObjectList = rhPtr->rhObjectList; // get a pointer to the mmf object list
LPOIL OiList = rhPtr->rhOiList; // get a pointer to the mmf object info list
LPQOI QualToOiList =
rhPtr->rhQualToOiList; // get a pointer to the mmf qualifier to Oi list
// Read second object parameter - load first instance, ignore rest
LPOIL CurrentOi = NULL;
if (Oi & 0x8000) {
LPQOI CurrentQualToOi = PtrAddBytes(QualToOiList, Oi & 0x7FFF);
CurrentOi = GetOILPtr(OiList, CurrentQualToOi->qoiOiList);
}
else {
CurrentOi = GetOILPtr(OiList, Oi);
}
if (CurrentOi) {
bool prevSelected =
(CurrentOi->oilEventCount ==
rhPtr->rh2
.rh2EventCount); // find out if conditions have selected any objects yet
if (prevSelected &&
CurrentOi->oilNumOfSelected <=
0) // if "0" have been selected (blame qualifiers) then return
return NULL;
object * CurrentObject = NULL;
object * PrevSelected = NULL;
int iCount = 0;
int numSelected = 0;
if (prevSelected) {
CurrentObject = ObjectList[CurrentOi->oilListSelected].oblOffset;
iCount = CurrentOi->oilNumOfSelected;
}
else {
CurrentObject = ObjectList[CurrentOi->oilObject].oblOffset;
}
return CurrentObject;
}
return NULL;
}
// Run a custom filter on the SOL (via function callback)
bool FilterObjects(LPRDATA rdPtr, short Oi, bool (*filterFunction)(LPRDATA, LPRO, void *),
void * userdata, bool is_negated)
{
LPRH rhPtr = rdPtr->rHo.hoAdRunHeader; // get a pointer to the mmf runtime header
LPOBL ObjectList = rhPtr->rhObjectList; // get a pointer to the mmf object list
LPOIL OiList = rhPtr->rhOiList; // get a pointer to the mmf object info list
LPQOI QualToOiList =
rhPtr->rhQualToOiList; // get a pointer to the mmf qualifier to Oi list
bool bSelected = false;
if (Oi & 0x8000) // dealing with a qualifier...
{
// For qualifiers evpW0( & 0x7FFF ) is the offset in the qualToOi array
// And evpW1( & 0x7FFF ) is the qualifier number.
LPQOI CurrentQualToOiStart = PtrAddBytes(QualToOiList, Oi & 0x7FFF);
LPQOI CurrentQualToOi = CurrentQualToOiStart;
// Loop through all objects associated with this qualifier
for (CurrentQualToOi; CurrentQualToOi->qoiOiList >= 0;
CurrentQualToOi = PtrAddBytes(CurrentQualToOi, 4)) {
LPOIL CurrentOi =
GetOILPtr(OiList, CurrentQualToOi->qoiOiList); // get a pointer to the
// objectInfo for this
// object in the qualifier
if (CurrentOi->oilNObjects <= 0) // skip if there are none of the object
continue;
bool prevSelected = (CurrentOi->oilEventCount == rhPtr->rh2.rh2EventCount); // find out if conditions have
// selected any objects yet
if (prevSelected &&
CurrentOi->oilNumOfSelected <=
0) // if "0" have been selected (blame qualifiers) then skip
continue;
object * CurrentObject = NULL;
object * PrevSelected = NULL;
int iCount = 0;
int numSelected = 0;
if (prevSelected) {
CurrentObject = ObjectList[CurrentOi->oilListSelected].oblOffset;
iCount = CurrentOi->oilNumOfSelected;
}
else {
CurrentObject = ObjectList[CurrentOi->oilObject].oblOffset;
iCount = CurrentOi->oilNObjects;
CurrentOi->oilEventCount =
rhPtr->rh2.rh2EventCount; // tell mmf that the object
// selection is relevant to this
// event
}
for (int i = 0; i < iCount; i++) {
if (is_negated ^ filterFunction(rdPtr, (LPRO)CurrentObject, userdata)) {
if (numSelected++ == 0) {
CurrentOi->oilListSelected =
CurrentObject->hoNumber; // select the first object
}
else {
PrevSelected->hoNextSelected = CurrentObject->hoNumber;
}
PrevSelected = CurrentObject;
}
if (prevSelected) {
if (CurrentObject->hoNextSelected >= 0) {
CurrentObject = ObjectList[CurrentObject->hoNextSelected].oblOffset;
}
else {
break;
}
}
else {
if (CurrentObject->hoNumNext >= 0) {
CurrentObject = ObjectList[CurrentObject->hoNumNext].oblOffset;
}
else {
break;
}
}
}
CurrentOi->oilNumOfSelected = numSelected;
if (numSelected > 0) {
PrevSelected->hoNextSelected = -1;
bSelected = true;
}
else {
CurrentOi->oilListSelected = -1;
}
}
return bSelected ^ is_negated;
}
else {
LPOIL CurrentOi =
GetOILPtr(OiList, Oi); // get a pointer to the objectInfo for this object
if (CurrentOi->oilNObjects <= 0) // return if there are none of the object
return false ^ is_negated;
bool prevSelected =
(CurrentOi->oilEventCount ==
rhPtr->rh2.rh2EventCount); // find out if conditions have selected
// any objects yet
if (prevSelected &&
CurrentOi->oilNumOfSelected <=
0) // if "0" have been selected (blame qualifiers) then return
return false ^ is_negated;
object * CurrentObject = NULL;
object * PrevSelected = NULL;
int iCount = 0;
int numSelected = 0;
if (prevSelected) {
CurrentObject = ObjectList[CurrentOi->oilListSelected].oblOffset;
iCount = CurrentOi->oilNumOfSelected;
}
else {
CurrentObject = ObjectList[CurrentOi->oilObject].oblOffset;
iCount = CurrentOi->oilNObjects;
CurrentOi->oilEventCount =
rhPtr->rh2.rh2EventCount; // tell mmf that the object selection
// is relevant to this event
}
for (int i = 0; i < iCount; i++) {
if (is_negated ^ filterFunction(rdPtr, (LPRO)CurrentObject, userdata)) {
if (numSelected++ == 0) {
CurrentOi->oilListSelected =
CurrentObject->hoNumber; // select the first object
}
else {
PrevSelected->hoNextSelected = CurrentObject->hoNumber;
}
PrevSelected = CurrentObject;
}
if (prevSelected) {
if (CurrentObject->hoNextSelected < 0) {
break;
}
else {
CurrentObject = ObjectList[CurrentObject->hoNextSelected].oblOffset;
}
}
else {
if (CurrentObject->hoNumNext < 0) {
break;
}
else {
CurrentObject = ObjectList[CurrentObject->hoNumNext].oblOffset;
}
}
}
CurrentOi->oilNumOfSelected = numSelected;
if (numSelected > 0) {
PrevSelected->hoNextSelected = -1;
}
return (numSelected > 0) ^ is_negated;
}
}