aboutsummaryrefslogtreecommitdiff
path: root/src/parsec/e_texani.cpp
blob: 04687aa15865be1b07d529a2ee7ada9e6dcdd688 (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
/*
 * PARSEC - Texture Animations
 *
 * $Author: uberlinuxguy $ - $Date: 2004/09/15 12:25:22 $
 *
 * 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"

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

// proprietary module headers
#include "con_main.h"



// maximum number of registered texanims --------------------------------------
//
#define MAX_NUM_REGISTERED_TEXANIMS		256


// tables for registered texanims ---------------------------------------------
//
PUBLIC int			num_registered_texanims = 0;
PUBLIC texanimreg_s	registered_texanims[ MAX_NUM_REGISTERED_TEXANIMS ];


// fetch already registered texanim via name ----------------------------------
//
texanimreg_s *FetchTexAnim( char *name, dword *texanimid )
{
	ASSERT( name != NULL );

	for ( int tid = 0; tid < num_registered_texanims; tid++ ) {

		ASSERT( registered_texanims[ tid ].name != NULL );
		if ( stricmp( registered_texanims[ tid ].name, name ) == 0 ) {

			if ( texanimid != NULL )
				*texanimid = tid;
			return &registered_texanims[ tid ];
		}
	}

	return NULL;
}


// init texanim in specified face anim state ----------------------------------
//
void InitAnimStateTexAnim( FaceAnimState *animstate, texanim_s *texanim )
{
	ASSERT( animstate != NULL );
	ASSERT( texanim != NULL );

	animstate->TexAnim = texanim;
	animstate->tex_pos = texanim->tex_start;
	animstate->xfo_pos = texanim->xfo_start;

	ASSERT( texanim->tex_table != NULL );
	texfrm_s *firsttexframe = &texanim->tex_table[ animstate->tex_pos ];
	animstate->tex_time	= firsttexframe->deltatime;

	if ( texanim->xfo_table != NULL ) {
		xfofrm_s *firstxfoframe = &texanim->xfo_table[ animstate->xfo_pos ];
		animstate->xfo_time = firstxfoframe->deltatime;
	}
}


// register new texanim -------------------------------------------------------
//
int RegisterTexAnim( texanimreg_s *texanimreg )
{
	ASSERT( texanimreg != NULL );

	if ( num_registered_texanims >= MAX_NUM_REGISTERED_TEXANIMS )
		return FALSE;

	// name is mandatory
	if ( texanimreg->name == NULL )
		return FALSE;

	int			overwrite = FALSE;
	dword		texanimid = num_registered_texanims;
//	texanim_s*	texanim   = &registered_texanims[ texanimid ].texanim;

	// check for already registered texanim of same name
	if ( FetchTexAnim( texanimreg->name, &texanimid ) != NULL ) {

//		if ( !AUX_ENABLE_COLANIM_OVERLOADING )
//			return FALSE;

		// previously registered texanim will be overwritten
//		texanim   = &registered_texanims[ texanimid ].texanim;
		overwrite = TRUE;

		// mem was reserved in one block for both tables
//		ASSERT( colanim->col_table0 != NULL );
//		FREEMEM( colanim->col_table0 );
//		memset( colanim, 0, sizeof( colanim_s ) );

	} else {

		// allocate new texanim name
		char *name = (char *) ALLOCMEM( strlen( texanimreg->name ) + 1 );
		if ( name == NULL )
			OUTOFMEM( 0 );
		strcpy( name, texanimreg->name );

		ASSERT( registered_texanims[ texanimid ].name == NULL );
		registered_texanims[ texanimid ].name = name;

		num_registered_texanims++;
	}

	return TRUE;
}