Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
collect.cpp
Go to the documentation of this file.
1/*
2** Command & Conquer Generals Zero Hour(tm)
3** Copyright 2025 Electronic Arts Inc.
4**
5** This program is free software: you can redistribute it and/or modify
6** it under the terms of the GNU General Public License as published by
7** the Free Software Foundation, either version 3 of the License, or
8** (at your option) any later version.
9**
10** This program is distributed in the hope that it will be useful,
11** but WITHOUT ANY WARRANTY; without even the implied warranty of
12** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13** GNU General Public License for more details.
14**
15** You should have received a copy of the GNU General Public License
16** along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19/***********************************************************************************************
20 *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
21 ***********************************************************************************************
22 * *
23 * Project Name : WW3D *
24 * *
25 * $Archive:: /Commando/Code/ww3d2/collect.cpp $*
26 * *
27 * Author:: Greg Hjelstrom *
28 * *
29 * $Modtime:: 1/08/01 10:04a $*
30 * *
31 * $Revision:: 1 $*
32 * *
33 *---------------------------------------------------------------------------------------------*
34 * Functions: *
35 * CollectionClass::CollectionClass -- default constructor for collection render object *
36 * CollectionClass::CollectionClass -- constructor for collection render object *
37 * CollectionClass::CollectionClass -- copy constructor *
38 * CollectionClass::CollectionClass -- assignment operator *
39 * CollectionClass::~CollectionClass -- destructor *
40 * CollectionClass::Clone -- virtual copy constructor *
41 * CollectionClass::Free -- releases all assets in use by this collection *
42 * CollectionClass::Class_ID -- returns class id for collection render objects *
43 * CollectionClass::Get_Num_Polys -- returns the number of polygons in this collection *
44 * CollectionClass::Render -- render this collection *
45 * CollectionClass::Special_Render -- passes the special render call to all sub-objects *
46 * CollectionClass::Set_Transform -- set the transform for this collection *
47 * CollectionClass::Set_Position -- set the position for this collection *
48 * CollectionClass::Get_Num_Sub_Objects -- returns the number of sub objects *
49 * CollectionClass::Get_Sub_Object -- returns a pointer to the desired sub object *
50 * CollectionClass::Add_Sub_Object -- adds another object into this collection *
51 * CollectionClass::Remove_Sub_Object -- removes a sub object from this collection *
52 * CollectionClass::Cast_Ray -- passes the ray test to each sub object *
53 * CollectionClass::Cast_AABox -- passes the axis-aligned box test to each sub object *
54 * CollectionClass::Cast_OBBox -- passes the oriented box test to each sub object *
55 * CollectionClass::Intersect_AABox -- test for intersection with an AABox *
56 * CollectionClass::Intersect_OBBox -- test for intersection with an OBBox *
57 * CollectionClass::Get_Obj_Space_Bounding_Sphere -- returns the object space bounding spher *
58 * CollectionClass::Get_Obj_Space_Bounding_Box -- returns the object-space bounding box *
59 * CollectionClass::Snap_Point_Count -- returns the number of snap points in this collecion *
60 * CollectionClass::Get_Snap_Point -- return the desired snap point *
61 * CollectionClass::Scale -- scale the objects in this collection *
62 * CollectionClass::Scale -- scale the objects in this collection *
63 * CollectionClass::Update_Obj_Space_Bounding_Volumes -- recomputes the object space boundin *
64 * CollectionClass::Update_Sub_Object_Transforms -- recomputes all sub object transforms *
65 * CollectionLoaderClass::Load -- reads a collection from a w3d file *
66 * CollectionDefClass::CollectionDefClass -- constructor *
67 * CollectionDefClass::~CollectionDefClass -- destructor for collection definition *
68 * CollectionDefClass::Free -- releases assets in use by a collection definition *
69 * CollectionDefClass::Get_Name -- returns name of the collection *
70 * CollectionDefClass::Load -- loads a collection definition from a w3d file *
71 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
72
73
74#include "collect.h"
75#include "chunkio.h"
76#include "camera.h"
77#include "wwdebug.h"
78#include "snappts.h"
79#include "assetmgr.h"
80#include "ww3d.h"
81#include "w3derr.h"
82//#include "sr.hpp"
83
84
86
87/*
88** CollectionDefClass. This is the "blueprint" for a collection object
89** The asset manager will store these until someone actually asks it to
90** create an instance of the collection object
91*/
93{
94public:
95
98
99 const char * Get_Name(void) const;
101
102protected:
103
104 void Free(void);
105
109
110 DynamicVectorClass <ProxyClass> ProxyList;
111
112 friend class CollectionClass;
113};
114
115
116/*
117** CollectionPrototypeClass this is the render object prototype for
118** Collections.
119*/
121{
123public:
125
126 virtual const char * Get_Name(void) const { return ColDef->Get_Name(); }
127 virtual int Get_Class_ID(void) const { return RenderObjClass::CLASSID_COLLECTION; }
128 virtual RenderObjClass * Create(void) { return NEW_REF( CollectionClass, (*ColDef)); }
129 virtual void DeleteSelf() { delete this; }
130
132
133protected:
134 virtual ~CollectionPrototypeClass(void) { delete ColDef; }
135};
136
137
138/***********************************************************************************************
139 * CollectionClass::CollectionClass -- default constructor for collection render object *
140 * *
141 * INPUT: *
142 * *
143 * OUTPUT: *
144 * *
145 * WARNINGS: *
146 * *
147 * HISTORY: *
148 * 23/8/00 GTH : Created. *
149 *=============================================================================================*/
155
156
157/***********************************************************************************************
158 * CollectionClass::CollectionClass -- constructor for collection render object *
159 * *
160 * INPUT: *
161 * *
162 * OUTPUT: *
163 * *
164 * WARNINGS: *
165 * *
166 * HISTORY: *
167 * 12/8/98 GTH : Created. *
168 *=============================================================================================*/
170 SubObjects(def.ObjectNames.Count()),
172{
173 // Set our name
174 Set_Name (def.Get_Name ());
175
176 // create the sub objects
177 SubObjects.Resize(def.ObjectNames.Count());
178 for (int i=0; i<def.ObjectNames.Count(); i++) {
179 WWASSERT(SubObjects.Count() == i);
180 SubObjects.Add(WW3DAssetManager::Get_Instance()->Create_Render_Obj(def.ObjectNames[i]));
181 SubObjects[i]->Set_Container(this);
182 }
183
184 // Copy the list of placeholder objects from the definition
185 ProxyList = def.ProxyList;
186
187 // grab ahold of the snap points.
189 if (SnapPoints) SnapPoints->Add_Ref();
190
191 // set up our collision typeas the union of all of our sub-objects
193
194 // update the object bounding volumes
196}
197
198
199/***********************************************************************************************
200 * CollectionClass::CollectionClass -- copy constructor *
201 * *
202 * INPUT: *
203 * *
204 * OUTPUT: *
205 * *
206 * WARNINGS: *
207 * *
208 * HISTORY: *
209 * 12/8/98 GTH : Created. *
210 *=============================================================================================*/
213 SubObjects(src.SubObjects.Count()),
215{
216 *this = src;
217}
218
219
220/***********************************************************************************************
221 * CollectionClass::CollectionClass -- assignment operator *
222 * *
223 * INPUT: *
224 * *
225 * OUTPUT: *
226 * *
227 * WARNINGS: *
228 * *
229 * HISTORY: *
230 * 12/8/98 GTH : Created. *
231 *=============================================================================================*/
233{
234 if (this != &that) {
235 Free();
237
238 SubObjects.Resize(that.SubObjects.Count());
239 for (int i=0; i<that.SubObjects.Count(); i++) {
240 WWASSERT(SubObjects.Count() == i);
241 SubObjects.Add(that.SubObjects[i]->Clone());
242 SubObjects[i]->Set_Container(this);
243 }
244
245 // Copy the list of placeholder objects from the definition
246 ProxyList = that.ProxyList;
247
248 SnapPoints = that.SnapPoints;
249 if (SnapPoints) SnapPoints->Add_Ref();
250
253 }
254 return * this;
255}
256
257
258/***********************************************************************************************
259 * CollectionClass::~CollectionClass -- destructor *
260 * *
261 * INPUT: *
262 * *
263 * OUTPUT: *
264 * *
265 * WARNINGS: *
266 * *
267 * HISTORY: *
268 * 12/8/98 GTH : Created. *
269 *=============================================================================================*/
274
275
276/***********************************************************************************************
277 * CollectionClass::Clone -- virtual copy constructor *
278 * *
279 * INPUT: *
280 * *
281 * OUTPUT: *
282 * *
283 * WARNINGS: *
284 * *
285 * HISTORY: *
286 * 12/8/98 GTH : Created. *
287 *=============================================================================================*/
289{
290 return NEW_REF( CollectionClass, (*this));
291}
292
293
294/***********************************************************************************************
295 * CollectionClass::Free -- releases all assets in use by this collection *
296 * *
297 * INPUT: *
298 * *
299 * OUTPUT: *
300 * *
301 * WARNINGS: *
302 * *
303 * HISTORY: *
304 * 12/8/98 GTH : Created. *
305 *=============================================================================================*/
307{
308 for (int i=0; i<SubObjects.Count(); i++) {
309 SubObjects[i]->Set_Container(NULL);
310 SubObjects[i]->Release_Ref();
311 SubObjects[i] = NULL;
312 }
313 SubObjects.Delete_All();
314 ProxyList.Delete_All ();
315
317}
318
319
320/***********************************************************************************************
321 * CollectionClass::Class_ID -- returns class id for collection render objects *
322 * *
323 * INPUT: *
324 * *
325 * OUTPUT: *
326 * *
327 * WARNINGS: *
328 * *
329 * HISTORY: *
330 * 12/8/98 GTH : Created. *
331 *=============================================================================================*/
336
337
338/***********************************************************************************************
339 * CollectionClass::Get_Num_Polys -- returns the number of polygons in this collection *
340 * *
341 * INPUT: *
342 * *
343 * OUTPUT: *
344 * *
345 * WARNINGS: *
346 * *
347 * HISTORY: *
348 * 12/8/98 GTH : Created. *
349 *=============================================================================================*/
351{
352 int pcount = 0;
353 for (int i=0; i<SubObjects.Count(); i++) {
354 pcount += SubObjects[i]->Get_Num_Polys();
355 }
356 return pcount;
357}
358
359
360/***********************************************************************************************
361 * CollectionClass::Render -- render this collection *
362 * *
363 * INPUT: *
364 * *
365 * OUTPUT: *
366 * *
367 * WARNINGS: *
368 * *
369 * HISTORY: *
370 * 12/8/98 GTH : Created. *
371 *=============================================================================================*/
373{
374 if (Is_Not_Hidden_At_All() == false) {
375 return;
376 }
377
380 }
381
382 for (int i=0; i<SubObjects.Count(); i++) {
383 SubObjects[i]->Render(rinfo);
384 }
385}
386
387
388/***********************************************************************************************
389 * CollectionClass::Special_Render -- passes the special render call to all sub-objects *
390 * *
391 * INPUT: *
392 * *
393 * OUTPUT: *
394 * *
395 * WARNINGS: *
396 * *
397 * HISTORY: *
398 * 3/2/99 GTH : Created. *
399 *=============================================================================================*/
401{
402 if (Is_Not_Hidden_At_All() == false) {
403 return;
404 }
405
408 }
409
410 for (int i=0; i<SubObjects.Count(); i++) {
411 SubObjects[i]->Special_Render(rinfo);
412 }
413}
414
415/***********************************************************************************************
416 * CollectionClass::Set_Transform -- set the transform for this collection *
417 * *
418 * INPUT: *
419 * *
420 * OUTPUT: *
421 * *
422 * WARNINGS: *
423 * *
424 * HISTORY: *
425 * 12/8/98 GTH : Created. *
426 *=============================================================================================*/
432
433
434/***********************************************************************************************
435 * CollectionClass::Set_Position -- set the position for this collection *
436 * *
437 * INPUT: *
438 * *
439 * OUTPUT: *
440 * *
441 * WARNINGS: *
442 * *
443 * HISTORY: *
444 * 12/8/98 GTH : Created. *
445 *=============================================================================================*/
451
452
453/***********************************************************************************************
454 * CollectionClass::Get_Num_Sub_Objects -- returns the number of sub objects *
455 * *
456 * INPUT: *
457 * *
458 * OUTPUT: *
459 * *
460 * WARNINGS: *
461 * *
462 * HISTORY: *
463 * 12/8/98 GTH : Created. *
464 *=============================================================================================*/
466{
467 return SubObjects.Count();
468}
469
470
471/***********************************************************************************************
472 * CollectionClass::Get_Sub_Object -- returns a pointer to the desired sub object *
473 * *
474 * INPUT: *
475 * *
476 * OUTPUT: *
477 * *
478 * WARNINGS: *
479 * *
480 * HISTORY: *
481 * 12/8/98 GTH : Created. *
482 *=============================================================================================*/
484{
485 if (SubObjects[index]) {
486 SubObjects[index]->Add_Ref();
487 }
488 return SubObjects[index];
489}
490
491
492/***********************************************************************************************
493 * CollectionClass::Add_Sub_Object -- adds another object into this collection *
494 * *
495 * INPUT: *
496 * *
497 * OUTPUT: *
498 * *
499 * WARNINGS: *
500 * *
501 * HISTORY: *
502 * 12/8/98 GTH : Created. *
503 *=============================================================================================*/
505{
506 WWASSERT(subobj);
507 subobj->Add_Ref();
508 subobj->Set_Container(this);
509 subobj->Set_Transform(Transform);
510 int res = SubObjects.Add(subobj);
513 if (Is_In_Scene()) {
514 subobj->Notify_Added(Scene);
515 }
516 return res;
517}
518
519
520/***********************************************************************************************
521 * CollectionClass::Remove_Sub_Object -- removes a sub object from this collection *
522 * *
523 * INPUT: *
524 * *
525 * OUTPUT: *
526 * *
527 * WARNINGS: *
528 * *
529 * HISTORY: *
530 * 12/8/98 GTH : Created. *
531 *=============================================================================================*/
533{
534 if (robj == NULL) return 0;
535
536 int res = 0;
537
538 Matrix3D tm = Get_Transform();
539
540 for (int i=0; i<SubObjects.Count(); i++) {
541 if (robj == SubObjects[i]) {
542
543 if (Is_In_Scene()) {
544 SubObjects[i]->Notify_Removed(Scene);
545 }
546 SubObjects[i]->Set_Container(NULL);
547 SubObjects[i]->Set_Transform(tm);
548 SubObjects[i]->Release_Ref();
549 res = SubObjects.Delete(i);
550 break;
551 }
552 }
553
554 if (res != 0) {
557 }
558
559 return res;
560}
561
562
563/***********************************************************************************************
564 * CollectionClass::Cast_Ray -- passes the ray test to each sub object *
565 * *
566 * INPUT: *
567 * *
568 * OUTPUT: *
569 * *
570 * WARNINGS: *
571 * *
572 * HISTORY: *
573 * 12/8/98 GTH : Created. *
574 *=============================================================================================*/
576{
577 bool res = false;
578 for (int i=0; i<SubObjects.Count(); i++) {
579 res |= SubObjects[i]->Cast_Ray(raytest);
580 }
581 return res;
582}
583
584
585/***********************************************************************************************
586 * CollectionClass::Cast_AABox -- passes the axis-aligned box test to each sub object *
587 * *
588 * INPUT: *
589 * *
590 * OUTPUT: *
591 * *
592 * WARNINGS: *
593 * *
594 * HISTORY: *
595 * 12/8/98 GTH : Created. *
596 *=============================================================================================*/
598{
599 bool res = false;
600 for (int i=0; i<SubObjects.Count(); i++) {
601 res |= SubObjects[i]->Cast_AABox(boxtest);
602 }
603 return res;
604}
605
606
607/***********************************************************************************************
608 * CollectionClass::Cast_OBBox -- passes the oriented box test to each sub object *
609 * *
610 * INPUT: *
611 * *
612 * OUTPUT: *
613 * *
614 * WARNINGS: *
615 * *
616 * HISTORY: *
617 * 12/8/98 GTH : Created. *
618 *=============================================================================================*/
620{
621 bool res = false;
622 for (int i=0; i<SubObjects.Count(); i++) {
623 res |= SubObjects[i]->Cast_OBBox(boxtest);
624 }
625 return res;
626}
627
628
629/***********************************************************************************************
630 * CollectionClass::Intersect_AABox -- test for intersection with an AABox *
631 * *
632 * INPUT: *
633 * *
634 * OUTPUT: *
635 * *
636 * WARNINGS: *
637 * *
638 * HISTORY: *
639 * 1/19/00 gth : Created. *
640 *=============================================================================================*/
642{
643 bool res = false;
644 for (int i=0; i<SubObjects.Count(); i++) {
645 res |= SubObjects[i]->Intersect_AABox(boxtest);
646 }
647 return res;
648}
649
650
651/***********************************************************************************************
652 * CollectionClass::Intersect_OBBox -- test for intersection with an OBBox *
653 * *
654 * INPUT: *
655 * *
656 * OUTPUT: *
657 * *
658 * WARNINGS: *
659 * *
660 * HISTORY: *
661 * 1/19/00 gth : Created. *
662 *=============================================================================================*/
664{
665 bool res = false;
666 for (int i=0; i<SubObjects.Count(); i++) {
667 res |= SubObjects[i]->Intersect_OBBox(boxtest);
668 }
669 return res;
670}
671
672/***********************************************************************************************
673 * CollectionClass::Get_Obj_Space_Bounding_Sphere -- returns the object space bounding sphere. *
674 * *
675 * INPUT: *
676 * *
677 * OUTPUT: *
678 * *
679 * WARNINGS: *
680 * *
681 * HISTORY: *
682 * 12/8/98 GTH : Created. *
683 *=============================================================================================*/
685{
686 sphere = BoundSphere;
687}
688
689
690/***********************************************************************************************
691 * CollectionClass::Get_Obj_Space_Bounding_Box -- returns the object-space bounding box *
692 * *
693 * INPUT: *
694 * *
695 * OUTPUT: *
696 * *
697 * WARNINGS: *
698 * *
699 * HISTORY: *
700 * 12/8/98 GTH : Created. *
701 *=============================================================================================*/
706
707
708/***********************************************************************************************
709 * CollectionClass::Snap_Point_Count -- returns the number of snap points in this collecion *
710 * *
711 * INPUT: *
712 * *
713 * OUTPUT: *
714 * *
715 * WARNINGS: *
716 * *
717 * HISTORY: *
718 * 12/8/98 GTH : Created. *
719 *=============================================================================================*/
721{
722 if (SnapPoints) {
723 return SnapPoints->Count();
724 } else {
725 return 0;
726 }
727}
728
729
730/***********************************************************************************************
731 * CollectionClass::Get_Snap_Point -- return the desired snap point *
732 * *
733 * This function will set the passed vector to be equal to the object space coordinates of *
734 * the desired snap point. *
735 * *
736 * INPUT: *
737 * *
738 * OUTPUT: *
739 * *
740 * WARNINGS: *
741 * *
742 * HISTORY: *
743 * 12/8/98 GTH : Created. *
744 *=============================================================================================*/
746{
747 WWASSERT(set != NULL);
748 if (SnapPoints) {
749 *set = (*SnapPoints)[index];
750 } else {
751 set->X = set->Y = set->Z = 0;
752 }
753}
754
755
756/***********************************************************************************************
757 * CollectionClass::Scale -- scale the objects in this collection *
758 * *
759 * INPUT: *
760 * *
761 * OUTPUT: *
762 * *
763 * WARNINGS: *
764 * *
765 * HISTORY: *
766 * 12/8/98 GTH : Created. *
767 *=============================================================================================*/
769{
770 for (int i=0; i<SubObjects.Count(); i++) {
771 SubObjects[i]->Scale(scale);
772 }
773}
774
775
776/***********************************************************************************************
777 * CollectionClass::Scale -- scale the objects in this collection *
778 * *
779 * INPUT: *
780 * *
781 * OUTPUT: *
782 * *
783 * WARNINGS: *
784 * *
785 * HISTORY: *
786 * 12/8/98 GTH : Created. *
787 *=============================================================================================*/
788void CollectionClass::Scale(float scalex, float scaley, float scalez)
789{
790 for (int i=0; i<SubObjects.Count(); i++) {
791 SubObjects[i]->Scale(scalex,scaley,scalez);
792 }
793}
794
795
796/***********************************************************************************************
797 * CollectionClass::Update_Obj_Space_Bounding_Volumes -- recomputes the object space bounding *
798 * *
799 * INPUT: *
800 * *
801 * OUTPUT: *
802 * *
803 * WARNINGS: *
804 * *
805 * HISTORY: *
806 * 12/8/98 GTH : Created. *
807 *=============================================================================================*/
809{
810 int i;
811 if (SubObjects.Count() <= 0) {
812 BoundSphere = SphereClass(Vector3(0,0,0),0);
813 BoundBox.Center.Set(0,0,0);
814 BoundBox.Extent.Set(0,0,0);
815 return;
816 }
817
818 Matrix3D tm = Get_Transform();
820
821 // loop through all sub-objects, combining their bounding spheres.
822 BoundSphere = SubObjects[0]->Get_Bounding_Sphere();
823 for (i=1; i < SubObjects.Count(); i++) {
824 BoundSphere.Add_Sphere(SubObjects[i]->Get_Bounding_Sphere());
825 }
826
827 // loop through the sub-objects, computing a box in the root coordinate
828 // system which bounds all of the meshes. Note that we've set the
829 // root coordinate system to identity for this.
830 MinMaxAABoxClass box(Vector3(FLT_MAX,FLT_MAX,FLT_MAX),Vector3(-FLT_MAX,-FLT_MAX,-FLT_MAX));
831
832 for (i=0; i < SubObjects.Count(); i++) {
834 }
835
836 BoundBox.Init(box);
837
839
840 // Now update the object space bounding volumes of this object's container:
841 RenderObjClass *container = Get_Container();
842 if (container) container->Update_Obj_Space_Bounding_Volumes();
843
844 Set_Transform(tm);
845}
846
847
848/***********************************************************************************************
849 * CollectionClass::Update_Sub_Object_Transforms -- recomputes all sub object transforms *
850 * *
851 * INPUT: *
852 * *
853 * OUTPUT: *
854 * *
855 * WARNINGS: *
856 * *
857 * HISTORY: *
858 * 12/8/98 GTH : Created. *
859 *=============================================================================================*/
861{
863 for (int i=0; i<SubObjects.Count(); i++) {
864 SubObjects[i]->Set_Transform(Transform);
865 SubObjects[i]->Update_Sub_Object_Transforms();
866 }
868}
869
870
871/***********************************************************************************************
872 * CollectionClass::Get_Placeholder -- Returns information about a placeholder object.
873 * *
874 * INPUT: *
875 * *
876 * OUTPUT: *
877 * *
878 * WARNINGS: *
879 * *
880 * HISTORY: *
881 * 4/28/99 PDS : Created. *
882 *=============================================================================================*/
883bool CollectionClass::Get_Proxy (int index, ProxyClass &proxy) const
884{
885 bool retval = false;
886
887 if (index >= 0 && index < ProxyList.Count ()) {
888
889 //
890 // Return the proxy information to the caller
891 //
892 proxy = ProxyList[index];
893 retval = true;
894 }
895
896 return retval;
897}
898
899
900/***********************************************************************************************
901 * CollectionClass::Get_Proxy_Count -- Returns the count of proxy objects in the collection.
902 * *
903 * INPUT: *
904 * *
905 * OUTPUT: *
906 * *
907 * WARNINGS: *
908 * *
909 * HISTORY: *
910 * 4/28/99 PDS : Created. *
911 *=============================================================================================*/
913{
914 return ProxyList.Count ();
915}
916
917
918/***********************************************************************************************
919 * CollectionDefClass::CollectionDefClass -- constructor *
920 * *
921 * INPUT: *
922 * *
923 * OUTPUT: *
924 * *
925 * WARNINGS: *
926 * *
927 * HISTORY: *
928 * 12/8/98 GTH : Created. *
929 *=============================================================================================*/
934
935
936/***********************************************************************************************
937 * CollectionDefClass::~CollectionDefClass -- destructor for collection definition *
938 * *
939 * INPUT: *
940 * *
941 * OUTPUT: *
942 * *
943 * WARNINGS: *
944 * *
945 * HISTORY: *
946 * 12/8/98 GTH : Created. *
947 *=============================================================================================*/
952
953
954/***********************************************************************************************
955 * CollectionDefClass::Free -- releases assets in use by a collection definition *
956 * *
957 * INPUT: *
958 * *
959 * OUTPUT: *
960 * *
961 * WARNINGS: *
962 * *
963 * HISTORY: *
964 * 12/8/98 GTH : Created. *
965 *=============================================================================================*/
967{
968 for (int i=0; i<ObjectNames.Count(); i++) {
969 delete[] ObjectNames[i];
970 }
971
972 ProxyList.Delete_All ();
973}
974
975
976/***********************************************************************************************
977 * CollectionDefClass::Get_Name -- returns name of the collection *
978 * *
979 * INPUT: *
980 * *
981 * OUTPUT: *
982 * *
983 * WARNINGS: *
984 * *
985 * HISTORY: *
986 * 12/8/98 GTH : Created. *
987 *=============================================================================================*/
988const char * CollectionDefClass::Get_Name(void) const
989{
990 return Name;
991}
992
993
994/***********************************************************************************************
995 * CollectionDefClass::Load -- loads a collection definition from a w3d file *
996 * *
997 * INPUT: *
998 * *
999 * OUTPUT: *
1000 * *
1001 * WARNINGS: *
1002 * *
1003 * HISTORY: *
1004 * 12/8/98 GTH : Created. *
1005 *=============================================================================================*/
1007{
1008 Free();
1009
1010 // open the header chunk and read it in
1012 if (!cload.Open_Chunk()) goto Error;
1013 if (cload.Cur_Chunk_ID() != W3D_CHUNK_COLLECTION_HEADER) goto Error;
1014 if (cload.Read(&header,sizeof(header)) != sizeof(header)) goto Error;
1015 if (!cload.Close_Chunk()) goto Error;
1016
1017 strncpy(Name,header.Name,W3D_NAME_LEN);
1018 ObjectNames.Resize(header.RenderObjectCount);
1019
1020 while (cload.Open_Chunk()) {
1021 switch (cload.Cur_Chunk_ID())
1022 {
1024 {
1025 WWASSERT(cload.Cur_Chunk_Length() > 0);
1026 char * name = W3DNEWARRAY char [cload.Cur_Chunk_Length()];
1027 cload.Read(name,cload.Cur_Chunk_Length());
1028 ObjectNames.Add(name);
1029 break;
1030 }
1031
1033 {
1034 // Read the placeholder information from the chunk
1035 WWASSERT(cload.Cur_Chunk_Length() > 0);
1037 cload.Read(&info, sizeof (info));
1038
1039 // Read the placeholder name from the chunk
1040 char *name = W3DNEWARRAY char[info.name_len + 1];
1041 cload.Read(name, info.name_len);
1042 name[info.name_len] = 0;
1043
1044 // Create a matrix from the data in the chunk
1045 Matrix3D transform (info.transform[0][0], info.transform[1][0], info.transform[2][0], info.transform[3][0],
1046 info.transform[0][1], info.transform[1][1], info.transform[2][1], info.transform[3][1],
1047 info.transform[0][2], info.transform[1][2], info.transform[2][2], info.transform[3][2]);
1048
1049 // Add this placeholder to our list
1050 ProxyList.Add (ProxyClass (name, transform));
1051
1052 // Free the name array
1053 delete [] name;
1054 break;
1055 }
1056
1057 case W3D_CHUNK_POINTS:
1059 SnapPoints->Load_W3D(cload);
1060 break;
1061 }
1062
1063 cload.Close_Chunk();
1064 }
1065
1066 return WW3D_ERROR_OK;
1067
1068Error:
1069
1071}
1072
1073/***********************************************************************************************
1074 * CollectionLoaderClass::Load -- reads a collection from a w3d file *
1075 * *
1076 * INPUT: *
1077 * *
1078 * OUTPUT: *
1079 * *
1080 * WARNINGS: *
1081 * *
1082 * HISTORY: *
1083 * 12/8/98 GTH : Created. *
1084 *=============================================================================================*/
1086{
1088
1089 if (def == NULL) {
1090 return NULL;
1091 }
1092
1093 if (def->Load(cload) != WW3D_ERROR_OK) {
1094
1095 // load failed, delete the model and return an error
1096 delete def;
1097 return NULL;
1098
1099 } else {
1100
1101 // ok, accept this model!
1103 return proto;
1104
1105 }
1106}
1107
1108
1109
#define NULL
Definition BaseType.h:92
Color scale(const Color &a, const Color &b)
Definition GameMtl.cpp:722
#define WWASSERT
#define W3D_NAME_LEN
Definition w3d_file.h:319
@ W3D_CHUNK_PLACEHOLDER
Definition w3d_file.h:433
@ W3D_CHUNK_POINTS
Definition w3d_file.h:436
@ W3D_CHUNK_COLLECTION_HEADER
Definition w3d_file.h:431
@ W3D_CHUNK_COLLECTION_OBJ_NAME
Definition w3d_file.h:432
#define W3DNEWARRAY
Definition always.h:110
#define W3DMPO_GLUE(ARGCLASS)
Definition always.h:120
#define W3DNEW
Definition always.h:109
bool Close_Chunk()
Definition chunkio.cpp:448
uint32 Cur_Chunk_ID()
Definition chunkio.cpp:484
uint32 Cur_Chunk_Length()
Definition chunkio.cpp:503
uint32 Read(void *buf, uint32 nbytes)
Definition chunkio.cpp:692
bool Open_Chunk()
Definition chunkio.cpp:412
virtual int Class_ID(void) const
Definition collect.cpp:332
virtual void Special_Render(SpecialRenderInfoClass &rinfo)
Definition collect.cpp:400
void Update_Sub_Object_Transforms(void)
Definition collect.cpp:860
virtual bool Intersect_OBBox(OBBoxIntersectionTestClass &boxtest)
Definition collect.cpp:663
virtual int Add_Sub_Object(RenderObjClass *subobj)
Definition collect.cpp:504
virtual void Render(RenderInfoClass &rinfo)
Definition collect.cpp:372
virtual void Get_Obj_Space_Bounding_Sphere(SphereClass &sphere) const
Definition collect.cpp:684
virtual bool Intersect_AABox(AABoxIntersectionTestClass &boxtest)
Definition collect.cpp:641
CollectionClass(void)
Definition collect.cpp:150
virtual bool Cast_Ray(RayCollisionTestClass &raytest)
Definition collect.cpp:575
void Free(void)
Definition collect.cpp:306
virtual void Set_Position(const Vector3 &v)
Definition collect.cpp:446
AABoxClass BoundBox
Definition collect.h:131
SnapPointsClass * SnapPoints
Definition collect.h:128
virtual void Set_Transform(const Matrix3D &m)
Definition collect.cpp:427
virtual int Get_Num_Polys(void) const
Definition collect.cpp:350
DynamicVectorClass< ProxyClass > ProxyList
Definition collect.h:126
virtual int Remove_Sub_Object(RenderObjClass *robj)
Definition collect.cpp:532
CollectionClass & operator=(const CollectionClass &)
Definition collect.cpp:232
virtual bool Cast_AABox(AABoxCollisionTestClass &boxtest)
Definition collect.cpp:597
virtual void Update_Obj_Space_Bounding_Volumes(void)
Definition collect.cpp:808
virtual bool Get_Proxy(int index, ProxyClass &proxy) const
Definition collect.cpp:883
virtual bool Cast_OBBox(OBBoxCollisionTestClass &boxtest)
Definition collect.cpp:619
DynamicVectorClass< RenderObjClass * > SubObjects
Definition collect.h:127
virtual void Scale(float scale)
Definition collect.cpp:768
virtual RenderObjClass * Get_Sub_Object(int index) const
Definition collect.cpp:483
virtual RenderObjClass * Clone(void) const
Definition collect.cpp:288
virtual int Get_Proxy_Count(void) const
Definition collect.cpp:912
virtual int Snap_Point_Count(void)
Definition collect.cpp:720
virtual int Get_Num_Sub_Objects(void) const
Definition collect.cpp:465
SphereClass BoundSphere
Definition collect.h:130
virtual void Get_Snap_Point(int index, Vector3 *set)
Definition collect.cpp:745
virtual ~CollectionClass(void)
Definition collect.cpp:270
virtual void Get_Obj_Space_Bounding_Box(AABoxClass &box) const
Definition collect.cpp:702
~CollectionDefClass(void)
Definition collect.cpp:948
SnapPointsClass * SnapPoints
Definition collect.cpp:108
char Name[W3D_NAME_LEN]
Definition collect.cpp:106
void Free(void)
Definition collect.cpp:966
const char * Get_Name(void) const
Definition collect.cpp:988
DynamicVectorClass< char * > ObjectNames
Definition collect.cpp:107
friend class CollectionClass
Definition collect.cpp:112
DynamicVectorClass< ProxyClass > ProxyList
Definition collect.cpp:110
WW3DErrorType Load(ChunkLoadClass &cload)
Definition collect.cpp:1006
virtual PrototypeClass * Load_W3D(ChunkLoadClass &cload)
Definition collect.cpp:1085
virtual const char * Get_Name(void) const
Definition collect.cpp:126
virtual RenderObjClass * Create(void)
Definition collect.cpp:128
CollectionDefClass * ColDef
Definition collect.cpp:131
CollectionPrototypeClass(CollectionDefClass *def)
Definition collect.cpp:124
virtual ~CollectionPrototypeClass(void)
Definition collect.cpp:134
virtual void DeleteSelf()
Definition collect.cpp:129
virtual int Get_Class_ID(void) const
Definition collect.cpp:127
CompositeRenderObjClass & operator=(const CompositeRenderObjClass &that)
virtual void Set_Name(const char *name)
int Count(void) const
Definition Vector.H:507
void Add_Box(const MinMaxAABoxClass &box)
Definition aabox.h:586
PrototypeClass(void)
Definition proto.h:90
void Add_Ref(void) const
Definition refcount.cpp:171
virtual void Set_Transform(const Matrix3D &m)
Definition rendobj.cpp:423
virtual int Is_Not_Hidden_At_All(void)
Definition rendobj.h:463
RenderObjClass(void)
Definition rendobj.cpp:170
virtual void Set_Position(const Vector3 &v)
Definition rendobj.cpp:444
virtual void Update_Obj_Space_Bounding_Volumes(void)
Definition rendobj.h:394
virtual const SphereClass & Get_Bounding_Sphere(void) const
Definition rendobj.h:567
virtual void Notify_Added(SceneClass *scene)
Definition rendobj.cpp:862
virtual void Update_Sub_Object_Transforms(void)
Definition rendobj.cpp:777
void Invalidate_Cached_Bounding_Volumes(void) const
Definition rendobj.h:523
virtual const AABoxClass & Get_Bounding_Box(void) const
Definition rendobj.h:575
virtual void Update_Sub_Object_Bits(void)
Definition rendobj.cpp:730
SceneClass * Scene
Definition rendobj.h:557
void Set_Sub_Object_Transforms_Dirty(bool onoff)
Definition rendobj.h:494
virtual bool Is_In_Scene(void)
Definition rendobj.h:487
bool Are_Sub_Object_Transforms_Dirty(void)
Definition rendobj.h:495
virtual void Set_Container(RenderObjClass *con)
Definition rendobj.cpp:382
const Matrix3D & Get_Transform(void) const
Definition rendobj.h:617
RenderObjClass * Get_Container(void) const
Definition rendobj.h:291
Matrix3D Transform
Definition rendobj.h:549
float X
Definition vector3.h:90
float Z
Definition vector3.h:92
float Y
Definition vector3.h:91
static WW3DAssetManager * Get_Instance(void)
Definition assetmgr.h:205
CollectionLoaderClass _CollectionLoader
Definition collect.cpp:85
#define REF_PTR_RELEASE(x)
Definition refcount.h:80
#define NEW_REF(C, P)
Definition refcount.h:62
char Name[W3D_NAME_LEN]
Definition w3d_file.h:1645
float32 transform[4][3]
Definition w3d_file.h:1664
WW3DErrorType
Definition w3derr.h:51
@ WW3D_ERROR_LOAD_FAILED
Definition w3derr.h:54
@ WW3D_ERROR_OK
Definition w3derr.h:52