aboutsummaryrefslogtreecommitdiff
path: root/src/parsec/con_cani.cpp
blob: 4e66fca262b15198191c07e0018425fedb0fced1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
/*
 * PARSEC - Color Animation Commands
 *
 * $Author: uberlinuxguy $ - $Date: 2004/09/26 03:43:34 $
 *
 * Orginally written by:
 *   Copyright (c) Markus Hadwiger     <msh@parsec.org>   1999
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */ 

// C library
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// compilation flags/debug support
#include "config.h"
#include "debug.h"

// general definitions
#include "general.h"
#include "objstruc.h"

// global externals
#include "globals.h"

// mathematics header
#include "utl_math.h"

// local module header
#include "con_cani.h"

// proprietary module headers
#include "con_arg.h"
#include "con_aux.h"
#include "con_main.h"
#include "e_colani.h"



// string constants -----------------------------------------------------------
//
static char colanim_name_missing[]	= "name of colanim must be specified.";
static char colanim_name_invalid[]	= "name invalid.";
static char colanim_mode_invalid[]	= "mode invalid.";
static char colanim_len0_invalid[]	= "len invalid.";
static char colanim_len1_invalid[]	= "len2 invalid.";
static char colanim_len1_missing[]	= "len2 missing but src2 specified.";
static char colanim_tab1_missing[]	= "src2 missing but len2 specified.";
static char colanim_comp0_invalid[]	= "comp is invalid (src).";
static char colanim_comp1_invalid[]	= "comp is invalid (src2).";
static char colanim_t0_invalid[]	= "tequi is invalid (src).";
static char colanim_t1_invalid[]	= "tequi is invalid (src2).";
static char colanim_tl0_invalid[]	= "tlist is invalid (src).";
static char colanim_tl1_invalid[]	= "tlist is invalid (src2).";
static char colanim_w0_invalid[]	= "invalid wave spec (src).";
static char colanim_w1_invalid[]	= "invalid wave spec (src2).";
static char colanim_min0_invalid[]	= "invalid min value (src).";
static char colanim_min1_invalid[]	= "invalid min value (src2).";
static char colanim_max0_invalid[]	= "invalid max value (src).";
static char colanim_max1_invalid[]	= "invalid max value (src2).";
static char colanim_mask0_invalid[]	= "invalid channel mask (src).";
static char colanim_mask1_invalid[]	= "invalid channel mask (src2).";
static char colanim_reg_failed[]	= "colanim registration failed.";


// key tables for colanim registration via console command --------------------
//
key_value_s colanim_key_value[] = {

	{ "src",		NULL,	KEYVALFLAG_PARENTHESIZE	| KEYVALFLAG_MANDATORY	},
	{ "len",		NULL,	KEYVALFLAG_NONE			| KEYVALFLAG_MANDATORY	},
	{ "src2",		NULL,	KEYVALFLAG_PARENTHESIZE							},
	{ "len2",		NULL,	KEYVALFLAG_NONE									},
	{ "mode",		NULL,	KEYVALFLAG_NONE									},

	{ NULL,			NULL,	KEYVALFLAG_NONE									},
};

enum {

	KEY_COLANI_SRC0,
	KEY_COLANI_LEN0,
	KEY_COLANI_SRC1,
	KEY_COLANI_LEN1,
	KEY_COLANI_MODE
};


key_value_s colanim_tab_key_value[] = {

	{ "tab",		NULL,	KEYVALFLAG_PARENTHESIZE	| KEYVALFLAG_MANDATORY	},
	{ "comp",		NULL,	KEYVALFLAG_NONE									},
	{ "t",			NULL,	KEYVALFLAG_NONE									},
	{ "tl",			NULL,	KEYVALFLAG_PARENTHESIZE							},
	{ "mask",		NULL,	KEYVALFLAG_NONE									},

	{ NULL,			NULL,	KEYVALFLAG_NONE									},
};

enum {

	KEY_COLANI_TAB_TAB,
	KEY_COLANI_TAB_COMP,
	KEY_COLANI_TAB_TEQUI,
	KEY_COLANI_TAB_TLIST,
	KEY_COLANI_TAB_MASK
};


key_value_s colanim_wav_key_value[] = {

	{ "wave",		NULL,	KEYVALFLAG_MANDATORY	},
	{ "t",			NULL,	KEYVALFLAG_NONE			},
	{ "max",		NULL,	KEYVALFLAG_NONE			},
	{ "min",		NULL,	KEYVALFLAG_NONE			},
	{ "mask",		NULL,	KEYVALFLAG_NONE			},

	{ NULL,			NULL,	KEYVALFLAG_NONE			},
};

enum {

	KEY_COLANI_WAV_WAVE,
	KEY_COLANI_WAV_TEQUI,
	KEY_COLANI_WAV_MAX,
	KEY_COLANI_WAV_MIN,
	KEY_COLANI_WAV_MASK
};

static char colanim_wave_separator[]	= "wave ";
static int  colanim_wave_seplen			= strlen( colanim_wave_separator );


// waveform specs -------------------------------------------------------------
//
static char colanim_wave_tri[]	= "tri";
static char colanim_wave_saw[]	= "saw";
static char colanim_wave_ramp[]	= "ramp";
static char colanim_wave_sine[]	= "sine";


// store color and timing info into colanim entry -----------------------------
//
#define SET_COLTAB_ENTRY(p,v,t)	{ \
	coltab[ p ].color.R = ( mask & 0x01 ) ? (byte)(v) : 0x00; \
	coltab[ p ].color.G = ( mask & 0x02 ) ? (byte)(v) : 0x00; \
	coltab[ p ].color.B = ( mask & 0x04 ) ? (byte)(v) : 0x00; \
	coltab[ p ].color.A = ( mask & 0x08 ) ? (byte)(v) : 0x00; \
	coltab[ p ].deltatime = (t); \
}


// check and parse color channel mask -----------------------------------------
//
PRIVATE
int CheckChannelMask( char *maskstr, dword *mask )
{
	ASSERT( mask != NULL );

	if ( maskstr != NULL ) {

		*mask = 0x00;

		if ( maskstr[ 0 ] == 'r' ) {
			*mask |= 0x01;
			maskstr++;
		}
		if ( maskstr[ 0 ] == 'g' ) {
			*mask |= 0x02;
			maskstr++;
		}
		if ( maskstr[ 0 ] == 'b' ) {
			*mask |= 0x04;
			maskstr++;
		}
		if ( maskstr[ 0 ] == 'a' ) {
			*mask |= 0x08;
			maskstr++;
		}
		if ( ( maskstr[ 0 ] != ' ' ) && ( maskstr[ 0 ] != 0 ) ) {
			return FALSE;
		}
	}

	return TRUE;
}


// check for waveform specs ---------------------------------------------------
//
PRIVATE
int CheckWaveSpec( char *tabstr, colfrm_s *coltab, size_t tabsize, int tid )
{
	ASSERT( tabstr != NULL );
	ASSERT( coltab != NULL );
	ASSERT( ( tid == 0 ) || ( tid == 1 ) );

	// scan out all values to colanim_wav keys
	if ( !ScanKeyValuePairs( colanim_wav_key_value, tabstr ) ) {
		return FALSE;
	}

	// timing
	int tequi = 200;
	if ( colanim_wav_key_value[ KEY_COLANI_WAV_TEQUI ].value != NULL ) {
		if ( ScanKeyValueInt( &colanim_wav_key_value[ KEY_COLANI_WAV_TEQUI ], &tequi ) < 0 ) {
			CON_AddLine( tid ? colanim_t1_invalid : colanim_t0_invalid );
			return FALSE;
		}
		if ( tequi < 1 ) {
			CON_AddLine( tid ? colanim_t1_invalid : colanim_t0_invalid );
			return FALSE;
		}
	}

	// lower bound
	int minval = 0;
	if ( colanim_wav_key_value[ KEY_COLANI_WAV_MIN ].value != NULL ) {
		if ( ScanKeyValueInt( &colanim_wav_key_value[ KEY_COLANI_WAV_MIN ], &minval ) < 0 ) {
			CON_AddLine( tid ? colanim_min1_invalid : colanim_min0_invalid );
			return FALSE;
		}
		if ( ( minval < 0 ) || ( minval > 255 ) ) {
			CON_AddLine( tid ? colanim_min1_invalid : colanim_min0_invalid );
			return FALSE;
		}
	}

	// upper bound
	int maxval = 255;
	if ( colanim_wav_key_value[ KEY_COLANI_WAV_MAX ].value != NULL ) {
		if ( ScanKeyValueInt( &colanim_wav_key_value[ KEY_COLANI_WAV_MAX ], &maxval ) < 0 ) {
			CON_AddLine( tid ? colanim_max1_invalid : colanim_max0_invalid );
			return FALSE;
		}
		if ( ( maxval < minval ) || ( maxval > 255 ) ) {
			CON_AddLine( tid ? colanim_max1_invalid : colanim_max0_invalid );
			return FALSE;
		}
	}

	// check for color channel mask
	dword mask = 0x0f;
	if ( !CheckChannelMask( colanim_wav_key_value[ KEY_COLANI_WAV_MASK ].value, &mask ) ) {
		CON_AddLine( tid ? colanim_mask1_invalid : colanim_mask0_invalid );
		return FALSE;
	}

	// generate specified waveform
	char *wave = colanim_wav_key_value[ KEY_COLANI_WAV_WAVE ].value;

	if ( strcmp( wave, colanim_wave_tri ) == 0 ) {

		// triangle: "/\"
		if ( tabsize < 2 ) {
			SET_COLTAB_ENTRY( 0, minval, tequi );
			return TRUE;
		}
		unsigned int     halft  = tabsize / 2;
		float step   = (float)( maxval - minval ) / (float)halft;
		float curval = (float)minval;
		unsigned int tpos = 0;
		for ( tpos = 0; tpos < halft; tpos++ ) {
			SET_COLTAB_ENTRY( tpos, curval, tequi );
			curval += step;
		}
		for ( ; tpos < tabsize; tpos++ ) {
			SET_COLTAB_ENTRY( tpos, curval, tequi );
			curval -= step;
		}

	} else if ( strcmp( wave, colanim_wave_saw ) == 0 ) {

		// sawtooth: "|\"
		if ( tabsize < 2 ) {
			SET_COLTAB_ENTRY( 0, minval, tequi );
			return TRUE;
		}
		float step   = (float)( maxval - minval ) / (float)( tabsize - 1 );
		float curval = (float)maxval;
		for ( unsigned int tpos = 0; tpos < tabsize; tpos++ ) {
			SET_COLTAB_ENTRY( tpos, curval, tequi );
			curval -= step;
		}

	} else if ( strcmp( wave, colanim_wave_ramp ) == 0 ) {

		// ramp: "/|"
		if ( tabsize < 2 ) {
			SET_COLTAB_ENTRY( 0, minval, tequi );
			return TRUE;
		}
		float step   = (float)( maxval - minval ) / (float)( tabsize - 1 );
		float curval = (float)minval;
		for ( unsigned int tpos = 0; tpos < tabsize; tpos++ ) {
			SET_COLTAB_ENTRY( tpos, curval, tequi );
			curval += step;
		}

	} else if ( strcmp( wave, colanim_wave_sine ) == 0 ) {

		// sine
		float step   = (float)BAMS_DEG360 / (float)tabsize;
		float base   = (float)( maxval + minval ) / 2;
		float ampl   = (float)( maxval - minval ) / 2;
		float curval = (float)BAMS_DEG0;
		for ( unsigned int tpos = 0; tpos < tabsize; tpos++ ) {
			sincosval_s sincos;
			GetSinCos( (dword)curval, &sincos );
			float cursig = ampl * GEOMV_TO_FLOAT( sincos.sinval );
			SET_COLTAB_ENTRY( tpos, base + cursig, tequi );
			curval += step;
		}

	} else {

		CON_AddLine( tid ? colanim_w1_invalid : colanim_w0_invalid );
		return FALSE;
	}

	return TRUE;
}


// parse entire color table of 1, 3, or 4 components --------------------------
//
PRIVATE
int ParseColorTable( char *tabstr, colfrm_s *coltab, int *intlist, size_t tabsize, int tid )
{
	ASSERT( tabstr != NULL );
	ASSERT( coltab != NULL );
	ASSERT( intlist != NULL );
	ASSERT( ( tid == 0 ) || ( tid == 1 ) );

	// check for wave spec instead of table
	while ( *tabstr == ' ' )
		tabstr++;
	if ( strncmp( tabstr, colanim_wave_separator, colanim_wave_seplen ) == 0 ) {
		return CheckWaveSpec( tabstr, coltab, tabsize, tid );
	}

	// scan out all values to colanim_tab keys
	if ( !ScanKeyValuePairs( colanim_tab_key_value, tabstr ) ) {
		return FALSE;
	}

	// number of color components
	int comp = 1;
	if ( ScanKeyValueInt( &colanim_tab_key_value[ KEY_COLANI_TAB_COMP ], &comp ) < 0 ) {
		CON_AddLine( tid ? colanim_comp1_invalid : colanim_comp0_invalid );
		return FALSE;
	}
	if ( ( comp != 1 ) && ( comp != 3 ) && ( comp != 4 ) ) {
		CON_AddLine( tid ? colanim_comp1_invalid : colanim_comp0_invalid );
		return FALSE;
	}

	// check for color channel mask
	dword mask = 0x0f;
	if ( !CheckChannelMask( colanim_tab_key_value[ KEY_COLANI_TAB_MASK ].value, &mask ) ) {
		CON_AddLine( tid ? colanim_mask1_invalid : colanim_mask0_invalid );
		return FALSE;
	}

	// timing
	int tequi = 200;
	int tlist = FALSE;
	if ( colanim_tab_key_value[ KEY_COLANI_TAB_TEQUI ].value != NULL ) {

		if ( ScanKeyValueInt( &colanim_tab_key_value[ KEY_COLANI_TAB_TEQUI ], &tequi ) < 0 ) {
			CON_AddLine( tid ? colanim_t1_invalid : colanim_t0_invalid );
			return FALSE;
		}
		if ( tequi < 1 ) {
			CON_AddLine( tid ? colanim_t1_invalid : colanim_t0_invalid );
			return FALSE;
		}

	} else if ( colanim_tab_key_value[ KEY_COLANI_TAB_TLIST ].value != NULL ) {

		if ( ScanKeyValueIntList( &colanim_tab_key_value[ KEY_COLANI_TAB_TLIST ],
			 intlist, tabsize, tabsize ) == 0 ) {
			CON_AddLine( tid ? colanim_tl1_invalid : colanim_tl0_invalid );
			return FALSE;
		}
		tlist = TRUE;
	}
	if ( tlist ) {
		for ( unsigned int eid = 0; eid < tabsize; eid++ ) {
			if ( intlist[ eid ] < 1 ) {
				CON_AddLine( tid ? colanim_t1_invalid : colanim_t0_invalid );
				return FALSE;
			}
			coltab[ eid ].deltatime = intlist[ eid ];
		}
	} else {
		for ( unsigned int eid = 0; eid < tabsize; eid++ ) {
			coltab[ eid ].deltatime = tequi;
		}
	}

	// color components
	size_t complistlen = comp * tabsize;
	if ( ScanKeyValueIntList( &colanim_tab_key_value[ KEY_COLANI_TAB_TAB ],
		 intlist, complistlen, complistlen ) == 0 ) {
		CON_AddLine( tid ? colanim_tl1_invalid : colanim_tl0_invalid );
		return FALSE;
	}
	int *complist = intlist;
	for ( unsigned int eid = 0; eid < tabsize; eid++, complist += comp ) {

		switch ( comp ) {

			case 1:
				coltab[ eid ].color.R = ( mask & 0x01 ) ? complist[ 0 ] : 0x00;
				coltab[ eid ].color.G = ( mask & 0x02 ) ? complist[ 0 ] : 0x00;
				coltab[ eid ].color.B = ( mask & 0x04 ) ? complist[ 0 ] : 0x00;
				coltab[ eid ].color.A = ( mask & 0x08 ) ? complist[ 0 ] : 0x00;
				break;

			case 3:
				coltab[ eid ].color.R = ( mask & 0x01 ) ? complist[ 0 ] : 0x00;
				coltab[ eid ].color.G = ( mask & 0x02 ) ? complist[ 1 ] : 0x00;
				coltab[ eid ].color.B = ( mask & 0x04 ) ? complist[ 2 ] : 0x00;
				coltab[ eid ].color.A = ( mask & 0x08 ) ? 0xff          : 0x00;
				break;

			case 4:
				coltab[ eid ].color.R = ( mask & 0x01 ) ? complist[ 0 ] : 0x00;
				coltab[ eid ].color.G = ( mask & 0x02 ) ? complist[ 1 ] : 0x00;
				coltab[ eid ].color.B = ( mask & 0x04 ) ? complist[ 2 ] : 0x00;
				coltab[ eid ].color.A = ( mask & 0x08 ) ? complist[ 3 ] : 0x00;
				break;
		}
	}

	return TRUE;
}


// possible colanim_s::col_flags modes (COLANIM_SOURCExx) ---------------------
//
static char colanim_mode_sourcenocomb[]	= "nocombine";
static char colanim_mode_sourceadd[]	= "add";
static char colanim_mode_sourcemul[]	= "mul";


// console command for registering new colanim ("colanim") --------------------
//
int Cmd_DefColAnim( char *command )
{
	//NOTE:
	//CONCOM:
	// colanim_command ::= 'colanim' <name> <coltab0> [<coltab1>] [<mode-spec>]
	// name            ::= "may be parenthesized to include whitespace"
	// coltab0         ::= 'src'  <coltab-src> 'len'  <coltab-len>
	// coltab1         ::= 'src2' <coltab-src> 'len2' <coltab-len>
	// coltab_src      ::= '(' <tab-spec> | <wave-spec> ')'
	// coltab_len      ::= <int>
	// mode_spec       ::= 'mode' 'add' | 'mul'
	// tab_spec        ::= 'tab' <col-list> [<comp>] [<mask>] [<t-equi> | <t-list>]
	// col_list        ::= '(' <int>+ ')'
	// comp            ::= 'comp' '1' | '3' | '4'
	// t_equi          ::= 't' <int>
	// t_list          ::= 'tl' '(' <int>+ ')'
	// wave_spec       ::= 'wave' <wave-name> [<t-equi>] [<max>] [<min>] [<mask>]
	// wave_name       ::= 'tri' | 'saw' | 'ramp' | 'sine'
	// max             ::= 'max' <int>
	// min             ::= 'min' <int>
	// mask            ::= 'mask' ['r'] ['g'] ['b'] ['a']

	ASSERT( command != NULL );
	HANDLE_COMMAND_DOMAIN_SEP( command );

	// this flag is used during internal data reloads
	if ( AUX_ALLOW_ONLY_TEXTURE_LOADING ) {
		return TRUE;
	}

	// create pointer to list of parameters (first is always the name)
	char *colanimname = strtok( command, " " );
	if ( colanimname == NULL ) {
		CON_AddLine( colanim_name_missing );
		return TRUE;
	}

	// allow name to be parenthesized to include whitespace
	colanimname = GetParenthesizedName( colanimname );
	if ( colanimname == NULL ) {
		CON_AddLine( colanim_name_invalid );
		return TRUE;
	}

	// scan out all values to colanim keys
	if ( !ScanKeyValuePairs( colanim_key_value, NULL ) )
		return TRUE;

	// fetch length of coltab0
	int len0;
	if ( ScanKeyValueInt( &colanim_key_value[ KEY_COLANI_LEN0 ], &len0 ) < 0 ) {
		CON_AddLine( colanim_len0_invalid );
		return TRUE;
	}
	if ( ( len0 < 1 ) || ( len0 > 256 ) ) {
		CON_AddLine( colanim_len0_invalid );
		return TRUE;
	}

	// fetch length of coltab1
	int len1 = 0;
	if ( colanim_key_value[ KEY_COLANI_LEN1 ].value != NULL ) {
		if ( ScanKeyValueInt( &colanim_key_value[ KEY_COLANI_LEN1 ], &len1 ) < 0 ) {
			CON_AddLine( colanim_len1_invalid );
			return TRUE;
		}
		if ( ( len1 < 1 ) || ( len1 > 256 ) ) {
			CON_AddLine( colanim_len1_invalid );
			return TRUE;
		}
	}

	// check whether both len1 and coltab1 specified or none at all
	if ( colanim_key_value[ KEY_COLANI_SRC1 ].value != NULL ) {
		if ( len1 < 1 ) {
			CON_AddLine( colanim_len1_missing );
			return TRUE;
		}
	} else {
		if ( len1 > 0 ) {
			CON_AddLine( colanim_tab1_missing );
			return TRUE;
		}
	}

	// parse mode if supplied
	dword mode = COLANIM_SOURCEADD;
	if ( colanim_key_value[ KEY_COLANI_MODE ].value != NULL ) {
		char *modestr = colanim_key_value[ KEY_COLANI_MODE ].value;
		if ( strcmp( modestr, colanim_mode_sourceadd ) == 0 ) {
			mode = COLANIM_SOURCEADD;
		} else if ( strcmp( modestr, colanim_mode_sourcemul ) == 0 ) {
			mode = COLANIM_SOURCEMUL;
		} else if ( strcmp( modestr, colanim_mode_sourcenocomb ) == 0 ) {
			mode = COLANIM_SOURCENOCOMBINE;
		} else {
			CON_AddLine( colanim_mode_invalid );
			return TRUE;
		}
	}

	// reserve table memory (both tables in one block)
	size_t tabsize = ( len0 + len1 );
	char *tabmem = (char *) ALLOCMEM( tabsize * sizeof( colfrm_s ) );
	if ( tabmem == NULL )
		OUTOFMEM( 0 );
	colfrm_s *coltab0 = (colfrm_s *) tabmem;
	colfrm_s *coltab1 = ( len1 > 0 ) ? &coltab0[ len0 ] : NULL;

	// need tempmem for color lists (maximum four components per color)
	size_t tempsize = max( len0, len1 ) * 4;
	char *tempmem = (char *) ALLOCMEM( tempsize * sizeof( int ) );
	if ( tempmem == NULL )
		OUTOFMEM( 0 );
	int *intlist = (int *) tempmem;

	// parse coltab0
	char *coltab0str = colanim_key_value[ KEY_COLANI_SRC0 ].value;
	if ( !ParseColorTable( coltab0str, coltab0, intlist, len0, 0 ) ) {
		FREEMEM( tempmem );
		FREEMEM( tabmem );
		return TRUE;
	}

	// parse coltab1 if supplied
	char *coltab1str = colanim_key_value[ KEY_COLANI_SRC1 ].value;
	if ( coltab1str != NULL ) {
		if ( !ParseColorTable( coltab1str, coltab1, intlist, len1, 1 ) ) {
			FREEMEM( tempmem );
			FREEMEM( tabmem );
			return TRUE;
		}
	}

	// init registration info
	colanim_s colanim;
	colanim.col_table0 = coltab0;
	colanim.col_table1 = coltab1;
	colanim.col_end0   = ( len0 - 1 );
	colanim.col_end1   = ( len1 > 0 ) ? ( len1 - 1 ) : 0;
	colanim.col_flags  = mode;

	colanimreg_s colanimreg;
	colanimreg.name    = colanimname;
	colanimreg.colanim = colanim;

	// do registration
	if ( !RegisterColAnim( &colanimreg ) ) {

		CON_AddLine( colanim_reg_failed );
		FREEMEM( tempmem );
		FREEMEM( tabmem );
		return TRUE;
	}

	// free temporary mem
	FREEMEM( tempmem );

	return TRUE;
}