2 @Copyright Looking Glass Studios, Inc.
3 1996,1997,1998,1999,2000 Unpublished Work.
6 // $Header: r:/t2repos/thief2/src/render/rendprop.cpp,v 1.48 2000/02/18 14:17:51 MAT Exp $
52 // Must be last header
55 ////////////////////////////////////////////////////////////
56 // HAS REFS PROPERTIES
59 static sPropertyDesc refPropDesc
=
62 kPropertyInstantiate
|kPropertyNoInherit
|kPropertyNoClone
, // flags
65 { "Renderer", "Has Refs" }, // ui strings
68 typedef cGenericBoolProperty cRefPropBase
;
70 class cRefProp
: public cRefPropBase
73 cRefProp (const sPropertyDesc
* desc
)
74 : cRefPropBase(desc
,kPropertyImplSparseHash
)
78 void OnListenMsg(ePropertyListenMsg msg
, ObjID obj
, uPropListenerValue val
)
81 cRefPropBase::OnListenMsg(msg
,obj
,val
);
86 IBoolProperty
* RefProp
= NULL
;
88 BOOL
ObjHasRefs(ObjID obj
)
92 RefProp
->Get(obj
,&result
);
96 void ObjSetHasRefs(ObjID obj
,BOOL hasrefs
)
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
=
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
=
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
,
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
,
190 { "Renderer", "Render Type" }, // ui strings
196 static char* rend_type_strings
[] =
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
=
218 sizeof(rendtype_field
)/sizeof(rendtype_field
[0]),
222 static sPropertyTypeDesc rendtype_tdesc
=
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
);
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
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
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
)
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
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
312 void OnListenMsg(ePropertyListenMsg type
, ObjID obj
, uPropListenerValue val
)
314 cBaseBitmapWorldspaceProperty::OnListenMsg(type
, obj
, val
);
316 if (type
& kListenPropLoad
)
319 if (type
& (kListenPropModify
|kListenPropUnset
)) {
320 if (OBJ_IS_CONCRETE(obj
)) {
323 IObjectQuery
* query
= mpDonors
->GetAllHeirs(obj
, kObjectConcrete
);
324 for (; !query
->Done(); query
->Next()) {
325 UpdateObjBrush(query
->Object());
329 vm_redraw_from_camera();
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
,
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
=
408 sizeof(ba_field
)/sizeof(ba_field
[0]),
412 static sPropertyTypeDesc ba_tdesc
=
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
);
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
;
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
458 if (!pObjectNetworking
->ObjIsProxy(obj
))
466 BitmapFlagsProp
->IterStop(&iter
);
469 ////////////////////////////////////////////////////////////
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
;
487 cJointPosProperty(const sPropertyDesc
* 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
,
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
);
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
);
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
=
562 { "Renderer", "Invisible" },
563 kPropertyChangeLocally
, // netflags
570 void RenderPropsInit(void)
572 RefProp
= new cRefProp(&refPropDesc
);
575 AlphaRenderPropInit();
578 ParticleGroupPropInit();
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
);
598 RendFlashPropShutdown();