LibT2FS 0.1
C API for accessing TEngine data in memory.
Loading...
Searching...
No Matches
models/common.h
Go to the documentation of this file.
1/* This file is part of LibT2FS.
2 *
3 * LibT2FS is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
7 *
8 * LibT2FS is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <https://www.gnu.org/licenses/>.
15 */
16
17#ifndef H_T2FS_DATA_COMMON
18#define H_T2FS_DATA_COMMON
19
20#include <stdint.h>
21
22#ifdef T2FS_DEBUG
23#define SASSERT_SIZE(what, size) \
24 _Static_assert((sizeof(what) == size), "" #what " expected to be " #size " in size");
25#else
26#define SASSERT_SIZE(what, size)
27#endif
28
29
30// Some helpers for endianess swapping structures
31#define T2FS_STRINGIFY(x) #x
32#define T2FS_CONCAT(a, b) a##b
33#define T2FS_GET_SWAP_STRUCT(name) T2FS_CONCAT(T2FS_SWAP_, name)
34
35#define T2FS_SWAP_STRUCT_ARGS(...) __VA_ARGS__
36#define T2FS_CREATE_SWAP_STRUCT(name, sizes) \
37 const static uint8_t T2FS_GET_SWAP_STRUCT(name)[] = {T2FS_SWAP_STRUCT_ARGS sizes}; \
38 SASSERT_SIZE(name, T2FS_ADD_CONST_ARRAY_NUMBERS(T2FS_SWAP_STRUCT_ARGS sizes))
39
40#define T2FS_SWAP_STRUCT_COUNT(name) \
41 sizeof(T2FS_GET_SWAP_STRUCT(name)) / sizeof(T2FS_GET_SWAP_STRUCT(name)[0])
42
43#include "models/assert.h"
44
45#define _T2FS_ADD_CONST_ARRAY_NUMBERS_x(n, ...) T2FS_CONCAT(_T2FS_ADD_CONST_ARRAY_NUMBERS_, n)(__VA_ARGS__)
46#define T2FS_ADD_CONST_ARRAY_NUMBERS(...) _T2FS_ADD_CONST_ARRAY_NUMBERS_x(_T2FS_N_VA_ARGS(__VA_ARGS__), __VA_ARGS__)
47
48void
49t2fs_endian_swap_struct(void *struc, const uint8_t *const swap, uint32_t swapCount);
50
51
54#define T2FS_15BIT_SCALE_FACTOR(v) (v / 0b0111111111111111)
55#define T2FS_BONE_ROT_SCALE_FACTOR T2FS_15BIT_SCALE_FACTOR(1.f)
56#define T2FS_OBJ_ROT_SCALE_FACTOR T2FS_15BIT_SCALE_FACTOR(180.f)
57
58
61typedef struct __attribute__((__packed__)) s_T2FSDataCoordF32 {
62 float x, y, z;
64
67typedef struct __attribute__((__packed__)) s_T2FSDataWorldCoordF32 {
68 float x, z, y;
70
74typedef struct __attribute__((__packed__)) s_T2FSDataCoordS32 {
75 int32_t x, y, z;
77
78
84typedef struct __attribute__((__packed__)) s_T2FSDataCoordS16 {
85 int16_t x, y, z;
87
88
94typedef struct __attribute__((__packed__)) s_T2FSDataWorldCoordS16 {
95 int16_t x, z, y;
97
98#endif
struct s_T2FSDataWorldCoordS16 T2FSDataWorldCoordS16
struct s_T2FSDataCoordS16 T2FSDataCoordS16
struct s_T2FSDataWorldCoordF32 T2FSDataWorldCoordF32
struct s_T2FSDataCoordF32 T2FSDataCoordF32
struct s_T2FSDataCoordS32 T2FSDataCoordS32
yeah.. not kiddin
void t2fs_endian_swap_struct(void *struc, const uint8_t *const swap, uint32_t swapCount)
Definition models/common.h:61
float y
Definition models/common.h:62
float z
Definition models/common.h:62
float x
Definition models/common.h:62
Definition models/common.h:84
int16_t x
Definition models/common.h:85
int16_t y
Definition models/common.h:85
int16_t z
Definition models/common.h:85
yeah.. not kiddin
Definition models/common.h:74
int32_t y
Definition models/common.h:75
int32_t z
Definition models/common.h:75
int32_t x
Definition models/common.h:75
Definition models/common.h:67
float y
Definition models/common.h:68
float z
Definition models/common.h:68
float x
Definition models/common.h:68
Definition models/common.h:94
int16_t x
Definition models/common.h:95
int16_t y
Definition models/common.h:95
int16_t z
Definition models/common.h:95