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
|
#include "gameCommon.h"
#include "util.h"
#include "PID.h"
#ifndef ENTITY_H
#define ENTITY_H
enum {
ENTITY_NONE = -1,
ENTITY_ANTIFA,
ENTITY_SOLDATO,
ENTITY_CAPORALE,
ENTITY_SERGENTE,
ENTITY_MARESCIALLO,
ENTITY_GENERALE,
ENTITY_MUSSOLINI,
ENTITY_GUIDED_MISSILE,
ENTITY_MISSILE
};
#define ENTITY_TYPE_COUNT 9
typedef int8_t EntityType;
typedef int16_t EntityId; // Id in world.
typedef uint32_t EntityFingerprint;
// Callbacks.
typedef void (*EntityUpdateCb)(Game * game, Entity * entity);
typedef void (*EntityDrawCb)(Game * game, Entity * entity);
// Acceleration indeed hehehe.
typedef struct EntityAcceleration {
Vector3 rotation;
float speedUp;
float speedDown;
} EntityAcceleration;
float accelerateValue(float value, float lastValue, float up, float down);
Vector3 accelerateVector3(Vector3 value, Vector3 lastValue, Vector3 up, Vector3 down);
typedef struct EntityVelocity {
Vector3 velocity;
AxisAngle angularVelocity;
Vector3 stick; // Pilot control stick.
float speed; // Somewhat general use (:
} EntityVelocity;
EntityVelocity entityVelocityIdentity();
typedef struct EntityCollisionMesh {
size_t triangleCount;
Triangle3D * triangles;
Vector3 * normals;
} EntityCollisionMesh;
typedef struct EntityCollisionModel {
size_t meshCount;
EntityCollisionMesh * meshes;
} EntityCollisionModel;
EntityCollisionModel entityCreateCollisionModel(Model model);
void entityFreeCollisionModel(EntityCollisionModel model);
// Only use if both collision models came from the same model.
void entityTransformCollisionModel(Entity * entity);
// Checks if collision model will need to be transformed.
void entityCheckTransformedCollisionModel(Entity * entity);
// This fucker hit something.
typedef struct EntityCollision {
bool hit;
EntityId fromId;
EntityFingerprint fromFingerprint;
} EntityCollision;
// Used for hanlding the soldato follower and leader thing.
typedef struct EntityFollow {
EntityId leaderId;
EntityFingerprint leaderFingerprint;
EntityId followerId;
EntityFingerprint followerFingerprint;
} EntityFollow;
// Health stuff.
#define ENTITY_MIN_HEALTH 0.0
#define ENTITY_MAX_HEALTH 1.0
// This fucker is a entity.
typedef struct Entity {
EntityId id;
EntityFingerprint fingerprint;
EntityType type;
Model * model;
float radius; // Used for quick collision detection.
EntityCollisionModel collisionModel;
EntityCollisionModel transformedCollisionModel;
// Use for checking if model been transformed indeed.
bool collisionModelTransformed;
Vector3 position;
Quaternion rotation;
Vector3 lastPosition;
Quaternion lastRotation;
EntityVelocity velocity;
EntityVelocity lastVelocity;
bool useAcceleration;
EntityAcceleration acceleration;
EntityUpdateCb updateCb;
EntityDrawCb drawCb;
EntityFollow follow;
// Health is a percent from 1.0 to 0.0.
float health;
EntityCollision collision;
// Used for whatever.
void * data;
} Entity;
typedef void (*EntityInitCb)(Entity * entity, Game * game);
typedef void (*EntityCloseCb)(Entity * entity);
// Info for each entity type.
typedef struct EntityTypeInfo {
EntityInitCb initCb;
EntityCloseCb closeCb;
EntityUpdateCb updateCb;
EntityDrawCb drawCb;
} EntityTypeInfo;
const extern EntityTypeInfo entityTypeInfo[ENTITY_TYPE_COUNT];
// Do I need a fucking comment?
Entity createEntity(EntityType type, Game * game);
void closeEntity(Entity * entity);
void setEntityRadius(Entity * entity); // Uses model to set radius;
bool checkEntityCollision(Entity * entity1, Entity * entity2);
RayCollision traceRayToEntity(Entity entity, Ray ray);
RayCollision traceRayToEntityRadius(Entity entity, Ray ray, float scale);
// Helper functions for updating, drawing...
void entityDraw(Entity * entity);
void entityUpdatePosition(Entity * entity);
void entityUpdateRotation(Entity * entity);
void entityUpdateLastValues(Entity * entity); // Should be at top of update function.
void entityJoystickControl(Entity * entity, Vector3 stick, float speed);
enum {
ENTITY_FLY_TO_POINT_PID,
ENTITY_FLY_TO_POINT_BANG_BANG
};
// Shit for fly to point.
typedef struct EntityFlyToPointInfo {
union {
PID speedPID;
struct {
float speed;
float stopAt;
} bangbang;
} controller;
uint8_t controlType;
float rotationSpeed; // 0.0 to not use.
bool applyRotation;
} EntityFlyToPointInfo;
void entityFlyToPoint(Entity * entity, Vector3 point, EntityFlyToPointInfo * info);
#endif
|