File: tiki_shared.h

package info (click to toggle)
openmohaa 0.82.1%2Bdfsg-1
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid
  • size: 34,192 kB
  • sloc: cpp: 315,720; ansic: 275,789; sh: 312; xml: 246; asm: 141; makefile: 7
file content (433 lines) | stat: -rw-r--r-- 11,863 bytes parent folder | download | duplicates (2)
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
/*
===========================================================================
Copyright (C) 2023 the OpenMoHAA team

This file is part of OpenMoHAA source code.

OpenMoHAA source code 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.

OpenMoHAA source code 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 OpenMoHAA source code; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
===========================================================================
*/

// tiki_shared.h : Skeletor

#pragma once

#ifdef __cplusplus
#    include "../skeletor/skeletor_name_lists.h"
#endif

#include "../skeletor/skeletor_model_file_format.h"

// animation flags
#define TAF_RANDOM              0x1                         // random
#define TAF_NOREPEAT            0x2                         // no loop
#define TAF_DONTREPEAT          (TAF_RANDOM | TAF_NOREPEAT) // don't repeat
#define TAF_DEFAULT_ANGLES      0x8                         // ?
#define TAF_NOTIMECHECK         0x10                        // don't check for timing
#define TAF_DELTADRIVEN         0x20                        // animation is based on skeletor animation's delta
#define TAF_AUTOSTEPS           0x400                       // footsteps for dogs
#define TAF_AUTOSTEPS_RUNNING   0x800                       // footsteps for dogs
#define TAF_AUTOSTEPS_EQUIPMENT 0x1000

// skeletor animation flags
#define TAF_HASDELTA 0x40
#define TAF_HASMORPH 0x80
#define TAF_HASUPPER 0x100

// tiki anim command frames
#define TIKI_FRAME_LAST         -5 // exec at last
#define TIKI_FRAME_END          -4 // exec at end
#define TIKI_FRAME_ENTRY        -3 // exec at entry
#define TIKI_FRAME_EXIT         -2 // exec at exit
#define TIKI_FRAME_EVERY        -1 // exec each frame
#define TIKI_FRAME_FIRST        0  // exec at first frame
#define TIKI_FRAME_MAXFRAMERATE 60

#define TIKI_SKEL_LOD_INDEXES 10

// skb skeletor
#define TIKI_SKB_HEADER_IDENT   (*(int *)"SKL ")
#define TIKI_SKB_HEADER_VER_3   3
#define TIKI_SKB_HEADER_VERSION 4

// skd skeletor
#define TIKI_SKD_HEADER_IDENT       (*(int *)"SKMD")
#define TIKI_SKD_HEADER_OLD_VERSION 5
#define TIKI_SKD_HEADER_VERSION     6

// skc skeletor animations
#define TIKI_SKC_HEADER_IDENT       (*(int *)"SKAN")
#define TIKI_SKC_HEADER_OLD_VERSION 13
#define TIKI_SKC_HEADER_VERSION     14

// tiki limitations
#define TIKI_MAX_BONES       100
#define TIKI_MAX_VERTEXES    1000
#define TIKI_MAX_TRIANGLES   2000
#define TIKI_MAX_SKELCACHE   1024
#define TIKI_MAX_COMMANDS    128

#define TIKI_MAX_ENTITIES              2048
#define TIKI_MAX_ENTITY_CACHE_PER_ENT  2
#define TIKI_MAX_ENTITY_CACHE          (TIKI_MAX_ENTITIES*TIKI_MAX_ENTITY_CACHE_PER_ENT)

// tiki surface flags
#define TIKI_SURF_SKIN1     (1 << 0)
#define TIKI_SURF_SKIN2     (1 << 1)
#define TIKI_SURF_SKIN3     (TIKI_SURF_SKIN1 | TIKI_SURF_SKIN2)
#define TIKI_SURF_NODRAW    (1 << 2)
#define TIKI_SURF_CROSSFADE (1 << 6)
#define TIKI_SURF_NODAMAGE  (1 << 7)
#define TIKI_SURF_NOMIPMAPS (1 << 8)
#define TIKI_SURF_NOPICMIP  (1 << 9)

#define MAX_SKELMODELS        12
#define MAX_TIKI_SHADER       4
#define MAX_TIKI_ALIASES      4095
#define MAX_GLOBAL_FROM_LOCAL 200

#define MAX_LOD_CURVE_POINTS  5
#define MAX_LOD_CURVE_CONSTS  4

typedef struct AliasList_s     AliasList_t;
typedef struct AliasListNode_s AliasListNode_t;

typedef struct tiki_singlecmd_s {
    int    num_args;
    char **args;
} tiki_singlecmd_t;

typedef struct tiki_cmd_s {
    int              num_cmds;
    tiki_singlecmd_t cmds[TIKI_MAX_COMMANDS];
} tiki_cmd_t;

#ifdef __cplusplus

typedef class skelChannelList_s
{
public:
    short int m_numChannels;

private:
    short int  m_numLocalFromGlobal;
    short int *m_chanLocalFromGlobal;

public:
    short int m_chanGlobalFromLocal[MAX_GLOBAL_FROM_LOCAL];

    int         NumChannels(void) const;
    void        ZeroChannels(void);
    void        PackChannels(void);
    void        InitChannels(void);
    void        CleanUpChannels();
    int         GlobalChannel(int localchannel) const;
    int         LocalChannel(int channel) const;
    int         GetLocalFromGlobal(int globalChannel) const;
    void        SetLocalFromGlobal(int channel, int localchannel);
    qboolean    HasChannel(ChannelNameTable *nameTable, const char *channelName) const;
    qboolean    HasChannel(int channel) const;
    int         AddChannel(int newGlobalChannelNum);
    const char *ChannelName(ChannelNameTable *nameTable, int localChannelNum) const;
} skelChannelList_c;

#else

typedef struct skelChannelList_s {
    short int  m_numChannels;
    short int  m_numLocalFromGlobal;
    short int *m_chanLocalFromGlobal;
    short int  m_chanGlobalFromLocal[MAX_GLOBAL_FROM_LOCAL];
} skelChannelList_c;

#endif

typedef struct dtikianim_s {
    char                  *name;
    int                    num_anims;
    void                  *alias_list;
    int                    num_client_initcmds;
    struct dtikicmd_s     *client_initcmds;
    int                    num_server_initcmds;
    struct dtikicmd_s     *server_initcmds;
    byte                  *modelData;
    size_t                 modelDataSize;
    vec3_t                 mins;
    vec3_t                 maxs;
    short int             *m_aliases;
    char                  *headmodels;
    char                  *headskins;
    qboolean               bIsCharacter;
    struct dtikianimdef_s *animdefs[1];
} dtikianim_t;

typedef struct dtiki_s {
    char                  *name;
    dtikianim_t           *a;
    void                  *skeletor;
    int                    num_surfaces;
    struct dtikisurface_s *surfaces;
    float                  load_scale;
    float                  lod_scale;
    float                  lod_bias;
    vec3_t                 light_offset;
    vec3_t                 load_origin;
    float                  radius;
    skelChannelList_c      m_boneList;
    int                    numMeshes;
    short int              mesh[1];

#ifdef __cplusplus
    int         GetBoneNumFromName(const char *name);
    const char *GetBoneNameFromNum(int num) const;
#endif
} dtiki_t;

typedef struct {
    int   ident;
    int   version;
    char  name[64];
    int   numSurfaces;
    int   numBones;
    int   ofsBones;
    int   ofsSurfaces;
    int   ofsEnd;
    int   lodIndex[TIKI_SKEL_LOD_INDEXES];
    int   numBoxes;
    int   ofsBoxes;
    int   numMorphTargets;
    int   ofsMorphTargets;
    // Added in 2.0 (SKD version 6)
    float scale;
} skelHeader_t;

typedef struct {
    short int parent;
    short int boxIndex;
    int       flags;
    char      name[64];
} skelBoneName_t;

typedef struct {
    int  ident;
    char name[64];
    int  numTriangles;
    int  numVerts;
    int  staticSurfProcessed;
    int  ofsTriangles;
    int  ofsVerts;
    int  ofsCollapse;
    int  ofsEnd;
    int  ofsCollapseIndex;
} skelSurface_t;

typedef short int skelIndex_t;

typedef struct skelSurfaceGame_s {
    int     ident;
    char    name[MAX_QPATH];
    int     numTriangles;
    int     numVerts;
    vec4_t *pStaticXyz;
    vec4_t *pStaticNormal;
    vec2_t (*pStaticTexCoords)[2];
    skelIndex_t              *pTriangles;
    struct skeletorVertex_s  *pVerts;
    skelIndex_t              *pCollapse;
    struct skelSurfaceGame_s *pNext;
    skelIndex_t              *pCollapseIndex;

#ifdef __cplusplus
    skelSurfaceGame_s();
#endif
} skelSurfaceGame_t;

typedef struct skelHeaderGame_s {
    int                  version;
    char                 name[64];
    int                  numSurfaces;
    int                  numBones;
    struct boneData_s   *pBones;
    skelSurfaceGame_t   *pSurfaces;
    int                  lodIndex[TIKI_SKEL_LOD_INDEXES];
    int                  numBoxes;
    struct skelHitBox_s *pBoxes;
    struct lodControl_s *pLOD;
    int                  numMorphTargets;
    char                *pMorphTargets;
    float                scale;
} skelHeaderGame_t;

typedef struct boneData_s {
    short int  channel;
    boneType_t boneType;
    short int  parent;
    short int  numChannels;
    short int  numRefs;
    short int  channelIndex[2];
    short int  refIndex[2];
    vec3_t     offset;
    float      length;
    float      weight;
    float      bendRatio;
    float      bendMax;
    float      spinRatio;
} boneData_t;

typedef struct tikiSurface_s {
    int  ident;
    char name[64];
    int  numFrames;
    int  numVerts;
    int  minLod;
    int  numTriangles;
    int  ofsTriangles;
    int  ofsCollapseMap;
    int  ofsSt;
    int  ofsXyzNormals;
    int  ofsEnd;
} tikiSurface_t;

typedef struct dtikisurface_s {
    char  name[MAX_QPATH];
    char  shader[MAX_TIKI_SHADER][MAX_QPATH];
    int   hShader[MAX_TIKI_SHADER];
    int   numskins;
    int   flags;
    float damage_multiplier;
} dtikisurface_t;

/*typedef struct tikiFrame_s {
	vec3_t bounds[ 2 ];
	vec3_t scale;
	vec3_t offset;
	vec3_t delta;
	float radius;
	float frametime;
} tikiFrame_t;*/

typedef struct tiki_tess_data_s {
    int            ident;
    tikiSurface_t *newsurface;
    tikiSurface_t *oldsurface;
} tiki_tess_data_t;

typedef struct skelWeight_s {
    int    boneIndex;
    float  boneWeight;
    vec3_t offset;
} skelWeight_t;

typedef struct skelVertex_s {
    vec3_t       normal;
    vec2_t       texCoords;
    int          numWeights;
    skelWeight_t weights[1];
} skelVertex_t;

typedef struct skeletorVertex_s {
    vec3_t normal;
    vec2_t texCoords;
    int    numWeights;
    int    numMorphs;
} skeletorVertex_t;

typedef struct skeletorVertexGame_s {
    vec3_t normal;
    vec2_t texCoords;
    int    numWeights;
    int    numMorphs;
} skeletorVertexGame_t;

typedef struct staticSurface_s {
    int                ident;
    int                ofsStaticData;
    skelSurfaceGame_t *surface;
    int                meshNum;
} staticSurface_t;

typedef struct {
    int    morphIndex;
    vec3_t offset;
} skeletorMorph_t;

typedef struct dtikianimdef_s {
    char               alias[48];
    float              weight;
    float              blendtime;
    int                flags;
    int                num_client_cmds;
    struct dtikicmd_s *client_cmds;
    int                num_server_cmds;
    struct dtikicmd_s *server_cmds;
} dtikianimdef_t;

typedef struct {
    short int shortQuat[4];
    short int shortOffset[3];
    short int pad;
} skelBone_t;

typedef struct {
    vec3_t     bounds[2];
    float      radius;
    vec3_t     delta;
    skelBone_t bones[1];
} skelFrame_t;

typedef struct {
    int    ident;
    int    version;
    char   name[64];
    int    type;
    int    numFrames;
    int    numbones;
    float  totaltime;
    float  frametime;
    vec3_t totaldelta;
    int    ofsFrames;
} skelAnimHeader_t;

typedef struct {
    float offset[4];
    float matrix[3][4];
} skelBoneCache_t;

typedef struct {
    float pos;
    float val;
} lodCurvePoint_t;

typedef struct {
    float base;
    float scale;
    float cutoff;
} lodCurvePointConstants_t;

typedef struct lodControl_s {
    float                    minMetric;
    float                    maxMetric;
    lodCurvePoint_t          curve[MAX_LOD_CURVE_POINTS];
    lodCurvePointConstants_t consts[MAX_LOD_CURVE_CONSTS];
} lodControl_t;

typedef struct {
    char              path[96];
    skelHeaderGame_t *skel;
    size_t            size;
    int               numuses;
} skelcache_t;

typedef int skeletorMorphCache_t;