2 @Copyright Looking Glass Studios, Inc.
3 1996,1997,1998,1999,2000 Unpublished Work.
6 // $Header: r:/t2repos/thief2/src/editor/objhistp.cpp,v 1.5 2000/02/19 13:11:08 toml Exp $
25 #include <dbmem.h> // must be last header!
34 typedef cHashTableFunctions
<ObjID
> ObjNameHashFunctions
;
35 typedef cHashTable
<ObjID
, int, ObjNameHashFunctions
> cObjHistCBTable
;
38 template cObjHistCBTable
;
41 static cObjHistCBTable objs_used
;
43 int ObjHistCompare(const void *p
, const void *q
)
45 ObjHistData
*a
= (ObjHistData
*) p
;
46 ObjHistData
*b
= (ObjHistData
*) q
;
48 if (a
->count
> b
->count
)
51 return a
->count
< b
->count
;
54 static int BuildObjData(char ***objstrings
, ObjHistData
**histdata
)
58 IObjectSystem
* pOS
= AppGetObj(IObjectSystem
);
59 ITraitManager
* traitman
= AppGetObj(ITraitManager
);
63 cObjHistCBTable::cIter hashiter
;
67 // okay, sift through every object in the world and collect stats
68 pQuery
= pOS
->Iter(kObjectConcrete
);
69 while (!pQuery
->Done())
71 obj
= pQuery
->Object();
73 // reject transients, like texture concretes
74 if (pOS
->ObjIsTransient(obj
))
80 arch
= traitman
->GetArchetype(obj
);
81 if ((obj
!= OBJ_NULL
) && (arch
!= OBJ_NULL
))
83 count
= objs_used
.Search(arch
);
84 objs_used
.Set(arch
,count
+1);
90 // take those stats and generate a list
91 entries
= objs_used
.nElems();
92 // extra entry for total
93 *objstrings
= (char **)Malloc(sizeof(char *) * (entries
+1));
94 for (i
=0; i
< entries
+1; i
++)
95 (*objstrings
)[i
] = (char *)Malloc(sizeof(char) * STRLEN
);
97 *histdata
= (ObjHistData
*)Malloc(sizeof(ObjHistData
) * entries
);
99 hashiter
= objs_used
.Iter();
101 while (!hashiter
.Done())
103 (*histdata
)[count
].arch
= hashiter
.Key();
104 (*histdata
)[count
].count
= hashiter
.Value();
115 // handy dandy object histogram palette
116 void popup_obj_histogram(void)
120 ObjHistData
*histdata
;
124 IObjectSystem
* pOS
= AppGetObj(IObjectSystem
);
127 total
= BuildObjData(&objstrings
,&histdata
);
129 entries
= objs_used
.nElems();
132 qsort(histdata
, entries
, sizeof(ObjHistData
), ObjHistCompare
);
134 sprintf(objstrings
[0],"Total %d", total
);
135 // form the stringlist
136 for (count
=0; count
< entries
; count
++)
138 sprintf(objstrings
[count
+1],"(%02d) %03d %s",count
, histdata
[count
].count
,pOS
->GetName(histdata
[count
].arch
));
140 // make the selection
141 choice
= PickFromStringList("Object Histogram", (const char* const*)objstrings
, entries
+1);
143 // now set the default object
146 arch
= histdata
[choice
].arch
;
147 editObjSetDefaultArchetype(arch
);
151 for (i
=0; i
< entries
; i
++)
159 // simple alphabetical list of placed objects
160 void popup_obj_alpha(void)
164 ObjHistData
*histdata
;
168 IObjectSystem
* pOS
= AppGetObj(IObjectSystem
);
170 BuildObjData(&objstrings
,&histdata
);
171 entries
= objs_used
.nElems();
173 // form the stringlist
174 for (count
=0; count
< entries
; count
++)
176 sprintf(objstrings
[count
],"%s %03d",pOS
->GetName(histdata
[count
].arch
),histdata
[count
].count
);
179 // make the selection
180 choice
= PickFromStringList("Object Alpha List", (const char* const*)objstrings
, entries
);
182 // now set the default object
185 arch
= histdata
[choice
].arch
;
186 editObjSetDefaultArchetype(arch
);
190 for (i
=0; i
< entries
; i
++)