aboutsummaryrefslogtreecommitdiff
path: root/src/entity.h
blob: 0f9ec3d719e4015a277eff8b4741c9843e81d3ea (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
#include "gameCommon.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
};

#define ENTITY_TYPE_COUNT 7

typedef int8_t EntityType;
typedef int16_t EntityId; // Id in world.

// Callbacks.
typedef void (*EntityUpdateCb)(Game * game, Entity * entity, EntityId id);
typedef void (*EntityDrawCb)(Game * game, Entity * entity, EntityId id);

// This fucker is a entity.
typedef struct Entity {
	EntityType type;
	Model model;

	Vector3 position;
	Vector3 velocity;

	float angularVelocity;
	Vector3 rotationAxis;
 
	Quaternion rotation;

	EntityUpdateCb updateCb;
	EntityDrawCb drawCb;

	// Used for whatever.
	void * data;
} Entity;

typedef void (*EntityInitCb)(Entity * entity);
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);
void closeEntity(Entity * entity);

// Helper functions for updating and drawing.
void entityDraw(Entity * entity);
void entityUpdatePosition(Entity * entity);
void entityUpdateRotation(Entity * entity);

void entityJoystickControl(Entity * entity, Vector3 stick, float speed);

#endif