1 /*---------------------------------------------------------------------*
2 Project:  tc library
3 File:     TCTextureList.cpp
4 
5 Copyright 1998-2001 Nintendo.  All rights reserved.
6 
7 These coded instructions, statements and computer programs contain
8 proprietary information of Nintendo of America Inc. and/or Nintendo
9 Company Ltd., and are protected by Federal copyright law.  They may
10 not be disclosed to third parties or copied or duplicated in any form,
11 in whole or in part, without the prior written consent of Nintendo.
12 
13 Change History:
14 
15  $Log: TCTextureList.cpp,v $
16  Revision 1.1  2006/02/17 09:01:53  mitu
17  1st version
18 
19 
20     4    4/11/01 3:08p John
21     Updated header copyrights and pathname.
22 
23     3     8/10/00 6:03p Mikepc
24 
25     2     3/17/00 1:19p Mikepc
26     change tc to use indices numbered from 0.
27 
28     1     12/03/99 3:45p Ryan
29 
30     7     9/16/99 8:47p Mikepc
31     updated code for auto-palette generation
32 
33     6     8/26/99 4:59p Mikepc
34     renamed file extensions from .c to .cpp.
35     .cpp extension allows addition of namespace protection to remove
36     potential name collisions with tool code.  Exceptions are CreateTplFile
37     and QuickConvert.  These are extern "C" linked.
38 
39     5     8/26/99 11:38a Mikepc
40 
41     4     8/26/99 11:03a Mikepc
42     tplCon rewrite for efficient memory usage, batch file processing
43     ability.
44 
45  $NoKeywords: $
46 
47 -----------------------------------------------------------------------*/
48 
49 
50 #include <charPipeline/tc/TCCommon.h>
51 
52 #include "TCTextureList.h"
53 #include "TCMem.h"
54 
55 /********************************/
56 // global internal linked list variables
57 TCTexture*     TxHead    = NULL;
58 
59 /*>*******************************(*)*******************************<*/
60 static void TCSwapTexture				( TCTexture* thisTex, TCTexture* thatTex );
61 
62 /*>*******************************(*)*******************************<*/
TCNewTexture(void)63 TCTexture* TCNewTexture ( void )
64 {
65 	TCTexture* newTx, *tail;
66 
67 	newTx = (TCTexture*)TCCalloc( 1, sizeof(TCTexture) );
68 
69 	if( TxHead == NULL )
70 	{
71 		TxHead = newTx;
72 	}
73 	else
74 	{
75 		tail = TxHead;
76 		while( tail->next )
77 		{
78 			tail = tail->next;
79 		}
80 
81 		tail->next  = newTx;
82 		newTx->prev = tail;
83 		newTx->next = NULL;
84 	}
85 
86 	return newTx;
87 }
88 
89 /*>*******************************(*)*******************************<*/
TCSetTextureAttributes(TCTexture * tx,u32 index,u32 image,u32 palette)90 void TCSetTextureAttributes ( TCTexture* tx, u32 index, u32 image,
91 							  u32 palette )
92 {
93     TCAssertMsg( (tx != NULL), "TCSetTextureAttributes: NULL TCTexture ptr.\n" );
94 
95 	tx->index   = index;
96 	tx->image   = image;
97 	tx->palette = palette;
98 }
99 
100 /*>*******************************(*)*******************************<*/
101 // sort indices from lowest to highest
102 // check for 0 index, missing indices, duplicate indices
103 /*>*******************************(*)*******************************<*/
TCSortTextureByIndex(void)104 void TCSortTextureByIndex ( void )
105 {
106 	TCTexture* thisTex, *nextTex;
107 
108 
109     // empty or single-node list (already sorted)
110 	if( (TxHead == NULL) || (TxHead->next == NULL) )
111 	{
112 		return;
113 	}
114 
115 	thisTex = TxHead;
116 	while( thisTex->next)
117 	{
118 		nextTex = thisTex->next;
119 
120 		if( nextTex->index < thisTex->index )
121 		{
122 			// swap just the data, not the pointers
123 			TCSwapTexture( thisTex, nextTex );
124 
125 			thisTex = TxHead;
126 			continue;
127 		}
128 
129 		thisTex = thisTex->next;
130 	}
131 }
132 
133 /*>*******************************(*)*******************************<*/
134 // swap data members only, not pointers
135 /*>*******************************(*)*******************************<*/
TCSwapTexture(TCTexture * thisTex,TCTexture * thatTex)136 static void TCSwapTexture( TCTexture* thisTex, TCTexture* thatTex )
137 {
138 	TCTexture tmpTx;
139 
140 
141 	tmpTx.index               = thisTex->index;
142 	tmpTx.image               = thisTex->image;
143 	tmpTx.palette             = thisTex->palette;
144     tmpTx.tplImageOffset      = thisTex->tplImageOffset;
145     tmpTx.tplPaletteOffset    = thisTex->tplPaletteOffset;
146 
147 	thisTex->index            = thatTex->index;
148 	thisTex->image            = thatTex->image;
149 	thisTex->palette          = thatTex->palette;
150     thisTex->tplImageOffset   = thatTex->tplImageOffset;
151     thisTex->tplPaletteOffset = thatTex->tplPaletteOffset;
152 
153 	thatTex->index            = tmpTx.index;
154 	thatTex->image            = tmpTx.image;
155 	thatTex->palette          = tmpTx.palette;
156     thatTex->tplImageOffset   = tmpTx.tplImageOffset;
157     thatTex->tplPaletteOffset = tmpTx.tplPaletteOffset;
158 }
159 
160 /*>*******************************(*)*******************************<*/
161 
162