convert line ends
[canaan.git] / prj / cam / src / editor / ged_rmap.c
blobaf61d766e5b0f9f6e83f277b8b7e8434c47c0beb
1 /*
2 @Copyright Looking Glass Studios, Inc.
3 1996,1997,1998,1999,2000 Unpublished Work.
4 */
6 // $Header: r:/t2repos/thief2/src/editor/ged_rmap.c,v 1.2 2000/02/19 13:10:47 toml Exp $
7 // support for remapping the brush ids
9 #include <string.h>
10 #include <lg.h>
12 #include <editbr.h>
13 #include <brlist.h>
14 #include <brinfo.h>
16 #include <csg.h>
17 #include <csgbrush.h>
18 #include <ged_rmap.h>
19 #include <memall.h>
20 #include <dbmem.h> // must be last header!
22 #define MAX_CALLBACKS 16
24 static ged_remap_callback remap_callbacks[MAX_CALLBACKS];
26 BOOL ged_remap_add_callback(ged_remap_callback cb)
28 int i;
29 for (i=0; i<MAX_CALLBACKS; i++)
30 if (remap_callbacks[i]==NULL)
32 remap_callbacks[i]=cb;
33 return TRUE;
35 return FALSE;
38 BOOL ged_remap_rem_callback(ged_remap_callback cb)
40 int i;
41 for (i=0; i<MAX_CALLBACKS; i++)
42 if (remap_callbacks[i]==cb)
44 remap_callbacks[i]=NULL;
45 return TRUE;
47 return FALSE;
50 // @TODO: make this have an installable callback for all systems who care
51 // compress brush id space, build new csg_brush list
52 int ged_remap_brushes(void)
54 int newid=1, hIter, i, max_id=0;
55 editBrush *us;
56 int *mapping;
58 us=blistIterStart(&hIter);
59 while (us!=NULL)
60 { // check brush_id
61 if (us->br_id>max_id) max_id=us->br_id;
62 us=blistIterNext(hIter);
64 AssertMsg(max_id<MAX_CSG_BRUSHES,"Too Many Brushes in Level");
65 mapping=(int *)Malloc(sizeof(int)*MAX_CSG_BRUSHES);
66 memset(mapping,0xff,sizeof(int)*MAX_CSG_BRUSHES);
67 us=blistIterStart(&hIter);
68 while (us!=NULL)
69 { // check brush_id
70 editBrush *nxt=blistIterNext(hIter);
71 if (us->br_id<MAX_CSG_BRUSHES)
73 mapping[us->br_id]=newid; // this mapping is
74 csg_brush[newid]=us;
75 if (us->br_id>newid) // if under newid, we have already remapped
76 csg_brush[us->br_id]=NULL; // so dont step on it
77 us->br_id=newid++;
79 else
81 Warning(("Punting brush %d\n",us->br_id));
82 // should somehow delete it, eh?
84 us=nxt;
86 for (i=0; i<MAX_CALLBACKS; i++)
87 if (remap_callbacks[i]!=NULL)
88 (*remap_callbacks[i])(mapping);
89 remap_csg_database(mapping); // this will TRASH mapping
90 // @TODO: wake up the GFH
91 Free(mapping);
92 return newid; // new max