2 @Copyright Looking Glass Studios, Inc.
3 1996,1997,1998,1999,2000 Unpublished Work.
6 // $Header: r:/t2repos/thief2/src/render/antxloop.cpp,v 1.3 1998/09/08 13:48:24 mahk Exp $
35 // Must be last header
45 #define MY_GUID LOOPID_AnimTexture
47 cTexturePatchTable gTexturePatchTable
;
48 cTexturePatchTable gTextureInverseTable
;
56 typedef struct _StateRecord
61 //////////////////////////////////////////////////
62 // tag file structures
64 TagFileTag TexturePatchTag
= { "TXTPAT_DB" };
65 TagVersion TexturePatchVersion
= { 0, 1 };
67 static ITagFile
* tagfile
= NULL
;
68 static long movefunc(void *buf
, size_t elsize
, size_t nelem
)
70 return ITagFile_Move(tagfile
,(char*)buf
,elsize
*nelem
);
73 static BOOL
setup_tagfile(ITagFile
* file
, TagFileTag
*tag
,
77 TagVersion found_version
= *version
;
80 result
= file
->OpenBlock(tag
, &found_version
);
81 if (!VersionNumsEqual(&found_version
,version
))
87 return result
== S_OK
;
90 static void cleanup_tagfile(ITagFile
* file
)
95 ////////////////////////////////////////////////////////////
98 static void AnimTextureSave(msgDatabaseData
*data
)
101 cTexturePatchTable::cIter iter
;
103 // dump the contents of the hashtable out to disk
104 if (setup_tagfile(data
->save
, &TexturePatchTag
,
105 &TexturePatchVersion
))
107 len
= gTexturePatchTable
.nElems();
108 movefunc((void *)&len
, sizeof(int), 1);
109 iter
= gTexturePatchTable
.Iter();
113 movefunc((void *)&val
, sizeof(int), 1);
115 movefunc((void *)&val
, sizeof(int), 1);
120 cleanup_tagfile(data
->save
);
124 ////////////////////////////////////////////////////////////
125 // Actually apply the patches, like craze, detox, etc.
127 void AnimTextureApplyPatches(cTexturePatchTable
*pTable
)
129 cTexturePatchTable::cIter iter
;
130 int cellid
,polyid
,texval
;
131 iter
= pTable
->Iter();
132 PortalPolygonRenderInfo
*ppri
;
135 // for each entry in the patch table, break it down into the cell and renderpoly
136 // ids, then go poke in the correct new values.
139 cellid
= iter
.Key() >> 8;
140 polyid
= iter
.Key() & 0xFF;
141 texval
= iter
.Value();
143 pcell
= WR_CELL(cellid
);
144 ppri
= &pcell
->render_list
[polyid
];
145 ppri
->texture_id
= texval
;
150 ////////////////////////////////////////////////////////////
153 static void AnimTextureLoad(msgDatabaseData
*data
)
158 // read back in the patch table
159 if (setup_tagfile(data
->load
, &TexturePatchTag
,
160 &TexturePatchVersion
))
162 movefunc((void *)&len
, sizeof(int), 1);
163 for (i
=0; i
< len
; i
++)
165 movefunc((void *)&key
, sizeof(int), 1);
166 movefunc((void *)&val
, sizeof(int), 1);
167 gTexturePatchTable
.Set(key
,val
);
169 cleanup_tagfile(data
->load
);
172 // now read through the table and apply the patches
173 AnimTextureApplyPatches(&gTexturePatchTable
);
176 ////////////////////////////////////////////////////////////
177 // Database message handler
180 static void db_message(DispatchData
* msg
)
182 msgDatabaseData data
;
183 data
.raw
= msg
->data
;
185 switch (DB_MSG(msg
->subtype
))
188 case kDatabaseDefault
:
189 gTexturePatchTable
.Clear();
193 if (msg
->subtype
& kDBMission
)
194 AnimTextureSave(&data
);
198 if (msg
->subtype
& kDBMission
)
199 AnimTextureLoad(&data
);
204 ////////////////////////////////////////
206 // LOOP/DISPATCH callback
207 // Here's where we do the dirty work.
210 #pragma off(unreferenced)
211 static eLoopMessageResult LGAPI
_LoopFunc(void* data
, eLoopMessage msg
, tLoopMessageData hdata
)
213 // useful stuff for most clients
214 eLoopMessageResult result
= kLoopDispatchContinue
;
215 StateRecord
* state
= (StateRecord
*)data
;
229 db_message(info
.dispatch
);
239 ////////////////////////////////////////////////////////////
241 // Loop client factory function.
244 #pragma off(unreferenced)
245 static ILoopClient
* LGAPI
_CreateClient(sLoopClientDesc
* pDesc
, tLoopClientData data
)
248 // allocate space for our state, and fill out the fields
249 state
= (StateRecord
*)Malloc(sizeof(StateRecord
));
250 state
->context
= (Context
*)data
;
252 return CreateSimpleLoopClient(_LoopFunc
,state
,pDesc
);
254 #pragma on(unreferenced)
261 sLoopClientDesc AnimTextureLoopClientDesc
=
264 "Animating Texture System",
266 kMsgDatabase
| kMsgsAppOuter
, // interests