2 @Copyright Looking Glass Studios, Inc.
3 1996,1997,1998,1999,2000 Unpublished Work.
6 // $Header: r:/t2repos/thief2/libsrc/portold/pt_clut.c,v 1.3 1996/09/10 18:25:19 buzzard Exp $
13 // pointer to user cluts
14 uchar
*pt_clut_list
[256];
16 // number of cluts we keep cached
17 #define CLUT_CACHE_SIZE 4
19 // length of clut chain we cache
20 #define CLUT_CACHE_IDSIZE 8
22 // storage for the clut cache
23 static uchar pt_clut_cache
[CLUT_CACHE_SIZE
][256];
25 static uchar pt_clut_cache_idlist
[CLUT_CACHE_SIZE
][CLUT_CACHE_IDSIZE
];
26 static uchar pt_clut_cache_idlist_len
[CLUT_CACHE_SIZE
];
28 // compare a clut chain with an idlist, assuming first one already matched
29 static bool compare_clut_chain(ClutChain
*cc
, int n
)
31 int i
=0, len
= pt_clut_cache_idlist_len
[n
];
33 if (cc
->clut_id
!= pt_clut_cache_idlist
[n
][i
])
37 if (i
>= len
) return FALSE
;
39 if (cc
->clut_id2
!= pt_clut_cache_idlist
[n
][i
])
50 uchar
*pt_get_clut(ClutChain
*cc
)
55 // check if it's just a single clut
56 if (!cc
->next
&& !cc
->clut_id2
)
57 return pt_clut_list
[cc
->clut_id
];
59 // check if we already have this one cached
61 for (i
=0; i
< CLUT_CACHE_SIZE
; ++i
)
62 if (pt_clut_cache_idlist
[i
][0] == c
&& pt_clut_cache_idlist_len
[i
])
63 if (compare_clut_chain(cc
, i
))
64 return pt_clut_cache
[i
];
66 // cycle through to the next cache entry
67 // note lack of LRUness... who cares,
68 // this should be super rare if it every happens at all
69 if (++ref
== CLUT_CACHE_SIZE
) ref
= 0;
72 uchar
*dest
= pt_clut_cache
[ref
];
73 uchar
*s1
= pt_clut_list
[cc
->clut_id
];
77 pt_clut_cache_idlist
[ref
][0] = cc
->clut_id
;
80 s2
= pt_clut_list
[cc
->clut_id2
];
81 pt_clut_cache_idlist
[ref
][1] = cc
->clut_id2
;
82 for (j
=0; j
< 256; ++j
)
86 memcpy(dest
, s1
, 256);
92 if (n
< CLUT_CACHE_IDSIZE
)
93 pt_clut_cache_idlist
[ref
][n
] = cc
->clut_id
;
96 s2
= pt_clut_list
[cc
->clut_id
];
97 for (j
=0; j
< 256; ++j
)
98 dest
[j
] = s2
[dest
[j
]];
101 if (n
< CLUT_CACHE_IDSIZE
)
102 pt_clut_cache_idlist
[ref
][n
] = cc
->clut_id2
;
105 s2
= pt_clut_list
[cc
->clut_id2
];
106 for (j
=0; j
< 256; ++j
)
107 dest
[j
] = s2
[dest
[j
]];
111 pt_clut_cache_idlist_len
[ref
] = (n
<= CLUT_CACHE_IDSIZE
? n
: 0);
114 return pt_clut_cache
[ref
];