convert line ends
[canaan.git] / prj / cam / src / render / rendprop.cpp
blob8f5940b18292ec1a9969b528de918e53f6c53642
1 /*
2 @Copyright Looking Glass Studios, Inc.
3 1996,1997,1998,1999,2000 Unpublished Work.
4 */
6 // $Header: r:/t2repos/thief2/src/render/rendprop.cpp,v 1.48 2000/02/18 14:17:51 MAT Exp $
8 #include <lg.h>
9 #include <mprintf.h>
11 #include <wrtype.h>
12 #include <wrobj.h>
13 #include <refsys.h>
15 #include <rendprop.h>
16 #include <property.h>
17 #include <propert_.h>
18 #include <propface.h>
19 #include <propfac_.h>
20 #include <dataops_.h>
21 #include <propsprs.h>
22 #include <propbase.h>
23 #include <prophash.h>
24 #include <propbase.h>
25 #include <objquery.h>
27 #include <linkbase.h>
28 #include <lnkquery.h>
29 #include <relation.h>
31 #include <traitman.h>
32 #include <trait.h>
33 #include <traitbas.h>
34 #include <objsys.h>
35 #include <iobjsys.h>
36 #include <objnotif.h>
37 #include <objedit.h>
38 #include <editobj.h>
39 #include <iobjnet.h>
41 #include <parttype.h>
42 #include <pgrpprop.h>
43 #include <objpos.h>
44 #include <fasprop.h>
45 #include <fastype.h>
46 #include <rndflash.h>
47 #include <viewmgr.h>
49 #include <sdesbase.h>
50 #include <sdestool.h>
52 // Must be last header
53 #include <dbmem.h>
55 ////////////////////////////////////////////////////////////
56 // HAS REFS PROPERTIES
59 static sPropertyDesc refPropDesc =
61 PROP_REF_NAME,
62 kPropertyInstantiate|kPropertyNoInherit|kPropertyNoClone, // flags
63 NULL, // constraints
64 0, 0, // Version
65 { "Renderer", "Has Refs" }, // ui strings
68 typedef cGenericBoolProperty cRefPropBase;
70 class cRefProp : public cRefPropBase
72 public:
73 cRefProp (const sPropertyDesc* desc)
74 : cRefPropBase(desc,kPropertyImplSparseHash)
78 void OnListenMsg(ePropertyListenMsg msg, ObjID obj, uPropListenerValue val)
80 ObjPosTouch(obj);
81 cRefPropBase::OnListenMsg(msg,obj,val);
86 IBoolProperty* RefProp = NULL;
88 BOOL ObjHasRefs(ObjID obj)
90 Assert_(RefProp);
91 BOOL result = TRUE;
92 RefProp->Get(obj,&result);
93 return result;
96 void ObjSetHasRefs(ObjID obj,BOOL hasrefs)
98 Assert_(RefProp);
99 RefProp->Set(obj,hasrefs);
103 ////////////////////////////////////////////////////////////////////
104 // This property is used in some lighting situations (light gem) to
105 // cast against those objects objects that have this property
108 #define OBJSHAD_IMP kPropertyImplVerySparse
110 sPropertyDesc objshad_render_desc =
112 PROP_OBJSHAD_NAME,
113 0, // flags
114 NULL, // constraints
115 1,0, // version
117 "Renderer",
118 "Runtime Object Shadow"
122 IBoolProperty *g_pObjShadowProp = NULL;
125 static void ObjShadPropInit(void)
127 g_pObjShadowProp = CreateBoolProperty(&objshad_render_desc, OBJSHAD_IMP);
132 ////////////////////////////////////////////////////////////
133 // RENDER ALPHA PROPERTY
136 #define ALPHA_IMP kPropertyImplVerySparse
138 sPropertyDesc alpha_render_desc =
140 PROP_ALPHA_NAME,
141 0, // flags
142 NULL, // constraints
143 1,0, // version
145 "Renderer",
146 "Transparency (alpha)"
150 IFloatProperty *gAlphaRenderProp;
151 static void AlphaRenderPropInit(void)
153 gAlphaRenderProp = CreateFloatProperty(&alpha_render_desc, ALPHA_IMP);
156 ////////////////////////////////////////////////////////////
157 // SELF-ILLUMINATION PROPERTY
160 #define SELF_ILLUM_IMP kPropertyImplVerySparse
162 sPropertyDesc self_illum_render_desc =
164 PROP_SELF_ILLUM_NAME,
165 0, // flags
166 NULL, // constraints
167 1,0, // version
169 "Renderer",
170 "Self Illumination"
174 IFloatProperty *g_pSelfIlluminationProp;
175 static void SelfIllumPropInit(void)
177 g_pSelfIlluminationProp = CreateFloatProperty(&self_illum_render_desc, SELF_ILLUM_IMP);
180 ////////////////////////////////////////////////////////////
181 // RENDER TYPE PROPERTY
184 static sPropertyDesc rTypePropDesc =
186 PROP_RENDER_TYPE_NAME,
187 0, // flags
188 NULL, // constraints
189 0, 0, // Version
190 { "Renderer", "Render Type" }, // ui strings
194 // Render type sdesc
196 static char* rend_type_strings[] =
198 "Normal",
199 "Not Rendered",
200 "Unlit",
201 "Editor Only",
204 #define NUM_REND_STRINGS (sizeof(rend_type_strings)/sizeof(rend_type_strings[0]))
206 #define RENDTYPE_TYPENAME "tRendType"
208 static sFieldDesc rendtype_field[] =
210 { "", kFieldTypeEnum, sizeof(int), 0, kFieldFlagUnsigned, 0, NUM_REND_STRINGS, NUM_REND_STRINGS, rend_type_strings },
213 static sStructDesc rendtype_sdesc =
215 RENDTYPE_TYPENAME,
216 sizeof(int),
217 kStructFlagNone,
218 sizeof(rendtype_field)/sizeof(rendtype_field[0]),
219 rendtype_field,
222 static sPropertyTypeDesc rendtype_tdesc =
224 RENDTYPE_TYPENAME,
225 sizeof(int),
228 #define RTYPE_IMPL kPropertyImplSparseHash
230 IIntProperty* RenderTypeProp = NULL;
232 eRenderType ObjRenderType(ObjID obj)
234 Assert_(RenderTypeProp);
235 eRenderType result = kRenderNormally;
236 RenderTypeProp->Get(obj,&result);
237 return result;
240 void ObjSetRenderType(ObjID obj,eRenderType type)
242 Assert_(RenderTypeProp);
243 RenderTypeProp->Set(obj,type);
246 static void RendTypePropInit()
248 AutoAppIPtr_(StructDescTools,pTools);
249 pTools->Register(&rendtype_sdesc);
250 RenderTypeProp = CreateIntegralProperty(&rTypePropDesc,&rendtype_tdesc,RTYPE_IMPL);
253 ////////////////////////////////////////////////////////////
254 // BITMAP WORLDSPACE PROPERTY
257 #undef INTERFACE
258 #define INTERFACE IBitmapWorldspaceProperty
260 DECLARE_PROPERTY_INTERFACE(IBitmapWorldspaceProperty)
262 DECLARE_UNKNOWN_PURE();
263 DECLARE_PROPERTY_PURE();
264 DECLARE_PROPERTY_ACCESSORS(sBitmapWorldspace *);
267 static sPropertyDesc g_BitmapWorldspaceDesc
269 "BitmapWorld",
270 0, // flags
271 NULL, // constraints
272 1, 0, // version
273 { "Renderer", "Bitmap Worldspace", "bitmap not always facing camera" },
274 kPropertyChangeLocally,
277 class cBitmapWorldspaceOps : public cClassDataOps<sBitmapWorldspace>
281 class cBitmapWorldspaceStore : public cHashPropertyStore<cBitmapWorldspaceOps>
285 typedef cSpecificProperty<IBitmapWorldspaceProperty,
286 &IID_IBitmapWorldspaceProperty, sBitmapWorldspace *,
287 cBitmapWorldspaceStore> cBaseBitmapWorldspaceProperty;
289 static void UpdateObjBrush(ObjID obj)
291 mxs_vector Scale;
292 mx_mk_vec(&Scale, 0, 0, 0);
293 editobjUpdateBrushFromObjScale(obj, &Scale);
294 mx_mk_vec(&Scale, 1, 1, 1);
295 editobjUpdateBrushFromObjScale(obj, &Scale);
298 class cBitmapWorldspaceProperty : public cBaseBitmapWorldspaceProperty
300 public:
301 cBitmapWorldspaceProperty(const sPropertyDesc *desc)
302 : cBaseBitmapWorldspaceProperty(desc)
306 STANDARD_DESCRIBE_TYPE(cBitmapWorldspaceProperty);
308 // In the editor we want changes to this property to force updates
309 // of object brushes, since this property is sort of acting as a
310 // scale.
311 #ifdef EDITOR
312 void OnListenMsg(ePropertyListenMsg type, ObjID obj, uPropListenerValue val)
314 cBaseBitmapWorldspaceProperty::OnListenMsg(type, obj, val);
316 if (type & kListenPropLoad)
317 return;
319 if (type & (kListenPropModify|kListenPropUnset)) {
320 if (OBJ_IS_CONCRETE(obj)) {
321 UpdateObjBrush(obj);
322 } else {
323 IObjectQuery* query = mpDonors->GetAllHeirs(obj, kObjectConcrete);
324 for (; !query->Done(); query->Next()) {
325 UpdateObjBrush(query->Object());
327 SafeRelease(query);
329 vm_redraw_from_camera();
332 #endif // EDITOR
334 protected:
335 void CreateEditor();
339 static sFieldDesc g_aBitmapWorldspaceFieldDesc[] =
341 { "x size (feet)", kFieldTypeFloat,
342 FieldLocation(sBitmapWorldspace, m_fXSize) },
343 { "y size (feet)", kFieldTypeFloat,
344 FieldLocation(sBitmapWorldspace, m_fYSize) },
345 { "x feet per tile", kFieldTypeFloat,
346 FieldLocation(sBitmapWorldspace, m_fXFeetPerTile) },
347 { "y feet per tile", kFieldTypeFloat,
348 FieldLocation(sBitmapWorldspace, m_fYFeetPerTile) },
351 static sStructDesc g_BitmapWorldspaceStructDesc
352 = StructDescBuild(cBitmapWorldspaceProperty, kStructFlagNone,
353 g_aBitmapWorldspaceFieldDesc);
355 void cBitmapWorldspaceProperty::CreateEditor()
357 AutoAppIPtr(StructDescTools);
358 pStructDescTools->Register(&g_BitmapWorldspaceStructDesc);
359 cPropertyBase::CreateEditor(this);
362 IBitmapWorldspaceProperty *g_pBitmapWorldspaceProperty;
364 static void BitmapWorldspacePropInit()
366 AutoAppIPtr_(StructDescTools, pTools);
367 pTools->Register(&g_BitmapWorldspaceStructDesc);
368 g_pBitmapWorldspaceProperty
369 = new cBitmapWorldspaceProperty(&g_BitmapWorldspaceDesc);
372 BOOL ObjBitmapWorldspace(ObjID obj, sBitmapWorldspace **ppBWS)
374 return g_pBitmapWorldspaceProperty->Get(obj, ppBWS);
378 ////////////////////////////////////////////////////////////
379 // BITMAP ANIMATION PROPERTY
382 static sPropertyDesc baPropDesc =
384 PROP_BITMAP_ANIMATION_NAME,
385 kPropertyInstantiate,
386 NULL, // constraints
387 0, 0, // Version
388 { "Renderer", "Bitmap Animation" }, // ui strings
391 static char* bitmap_flags[] =
393 "Kill on completion",
396 #define BA_TYPENAME "tBitmapAnimationType"
398 static sFieldDesc ba_field[] =
400 { "Flags", kFieldTypeBits, sizeof(int), 0, FullFieldNames(bitmap_flags) },
403 static sStructDesc ba_sdesc =
405 BA_TYPENAME,
406 sizeof(int),
407 kStructFlagNone,
408 sizeof(ba_field)/sizeof(ba_field[0]),
409 ba_field,
412 static sPropertyTypeDesc ba_tdesc =
414 BA_TYPENAME,
415 sizeof(int),
418 #define BA_IMPL kPropertyImplHash
420 static IIntProperty* BitmapFlagsProp = NULL;
422 BitmapFlags ObjBitmapFlags(ObjID obj)
424 Assert_(BitmapFlagsProp);
425 BitmapFlags result = 0;
426 BitmapFlagsProp->Get(obj,&result);
427 return result;
430 static void BitmapAnimationPropInit()
432 AutoAppIPtr_(StructDescTools,pTools);
433 pTools->Register(&ba_sdesc);
434 BitmapFlagsProp = CreateIntegralProperty(&baPropDesc,&ba_tdesc,BA_IMPL);
437 EXTERN BOOL rendobj_bitmap_retire(ObjID obj);
438 EXTERN void UpdateBitmapAnimations(int time)
440 sPropertyObjIter iter;
441 ObjID obj;
442 BitmapFlags flags;
444 BitmapFlagsProp->IterStart(&iter);
445 while (BitmapFlagsProp->IterNextValue(&iter, &obj, &flags))
447 if (OBJ_IS_CONCRETE(obj) && (flags & kKillOnComplete))
449 FrameAnimationConfig *cfg = ObjGetFrameAnimationConfig(obj);
450 if (cfg && cfg->clamp && !cfg->bounce) // kill on wrap is set
451 if (rendobj_bitmap_retire(obj)) // and we can detect the case
453 #ifdef NEW_NETWORK_ENABLED
454 AutoAppIPtr(ObjectNetworking);
455 // In multiplayer, all of the machines will be running this
456 // destroy in parallel; only the object's owner should actually
457 // destroy it.
458 if (!pObjectNetworking->ObjIsProxy(obj))
459 DestroyObject(obj);
460 #else
461 DestroyObject(obj);
462 #endif
466 BitmapFlagsProp->IterStop(&iter);
469 ////////////////////////////////////////////////////////////
470 // JOINT POSITIONS
473 class cJointPosOps : public cClassDataOps<sJointPos>
477 class cJointPosStore : public cSparseHashPropertyStore<cJointPosOps>
482 class cJointPosProperty : public cSpecificProperty<IJointPosProperty,&IID_IJointPosProperty,sJointPos*,cJointPosStore>
484 typedef cSpecificProperty<IJointPosProperty,&IID_IJointPosProperty,sJointPos*,cJointPosStore> cParent;
486 public:
487 cJointPosProperty(const sPropertyDesc* desc)
488 : cParent(desc)
493 STANDARD_DESCRIBE_TYPE(sJointPos);
497 // @TBD (justin 10-14-98): Currently, this property is being set locally
498 // on each machine. This isn't ideal -- we would like at least major
499 // changes to be reflected the same on all machines. However, this property
500 // is currently being changed for every tweq joint, every frame, causing
501 // huge numbers of network messages. We need to make this subtle, so that
502 // only real, important state changes get sent.
503 static sPropertyDesc jointPosPropDesc =
505 PROP_JOINTPOS_TYPE_NAME,
506 kPropertyNoInherit|kPropertyInstantiate,
507 NULL, // constraints
508 0,0, // version
509 { "Shape", "Joint Positions" },
510 kPropertyChangeLocally,
513 // structure descriptor fun
514 static sFieldDesc joint_fields [] =
516 { "Joint 1", kFieldTypeFloat, FieldLocation(sJointPos,el[0]) },
517 { "Joint 2", kFieldTypeFloat, FieldLocation(sJointPos,el[1]) },
518 { "Joint 3", kFieldTypeFloat, FieldLocation(sJointPos,el[2]) },
519 { "Joint 4", kFieldTypeFloat, FieldLocation(sJointPos,el[3]) },
520 { "Joint 5", kFieldTypeFloat, FieldLocation(sJointPos,el[4]) },
521 { "Joint 6", kFieldTypeFloat, FieldLocation(sJointPos,el[5]) }
524 static sStructDesc jointpos_struct = StructDescBuild(sJointPos,kStructFlagNone,joint_fields);
526 IJointPosProperty* JointPosProp = NULL;
528 BOOL JointPosPropInit(void)
530 AutoAppIPtr_(StructDescTools,pTools);
531 pTools->Register(&jointpos_struct);
533 JointPosProp=new cJointPosProperty(&jointPosPropDesc);
534 return TRUE;
537 static float null_parms[MAX_REND_JOINTS];
539 float *ObjJointPos(ObjID obj)
541 Assert_(JointPosProp);
542 float *result = null_parms;
543 JointPosProp->Get(obj,(sJointPos **)&result);
544 return result;
547 void ObjSetJointPos(ObjID obj, float *parms)
549 Assert_(JointPosProp);
550 JointPosProp->Set(obj,(sJointPos *)parms);
556 IIntProperty *g_pIsInvisibleProperty = 0;
557 static sPropertyDesc _g_IsInvisibleProperty =
559 "INVISIBLE",
561 NULL, 0, 0,
562 { "Renderer", "Invisible" },
563 kPropertyChangeLocally, // netflags
567 //////////////////
568 // init
570 void RenderPropsInit(void)
572 RefProp = new cRefProp(&refPropDesc);
573 RendTypePropInit();
574 JointPosPropInit();
575 AlphaRenderPropInit();
576 SelfIllumPropInit();
577 ObjShadPropInit();
578 ParticleGroupPropInit();
579 FASPropInit();
580 RendFlashPropInit();
581 BitmapWorldspacePropInit();
582 BitmapAnimationPropInit();
584 g_pIsInvisibleProperty = CreateIntProperty(&_g_IsInvisibleProperty,kPropertyImplSparse);
587 void RenderPropsShutdown(void)
589 SafeRelease(g_pIsInvisibleProperty);
590 SafeRelease(JointPosProp);
591 SafeRelease(RenderTypeProp);
592 SafeRelease(gAlphaRenderProp);
593 SafeRelease(g_pObjShadowProp);
594 SafeRelease(g_pSelfIlluminationProp);
595 ParticleGroupPropTerm();
596 SafeRelease(BitmapFlagsProp);
597 FASPropShutdown();
598 RendFlashPropShutdown();