summaryrefslogtreecommitdiff
path: root/src/components.hpp
blob: 3e7521f177f87d91ffd86d1a39c8895a49184cd0 (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
#ifndef PKE_COMPONENTS_HPP
#define PKE_COMPONENTS_HPP

#include "macros.hpp"
#include "dynamic-array.hpp"

#include <BulletCollision/CollisionShapes/btCollisionShape.h>
#include <LinearMath/btDefaultMotionState.h>
#include <BulletDynamics/Dynamics/btRigidBody.h>
#include <glm/gtc/quaternion.hpp>
#include <vulkan/vulkan_core.h>

const uint64_t ECS_UNSET_VAL = 0xFFFFFFFFFFFFFFFF;

TypeSafeInt_H(EntityHandle, uint64_t, ECS_UNSET_VAL);
TypeSafeInt_H(GrBindsHandle, uint64_t, ECS_UNSET_VAL);
TypeSafeInt_H(InstanceHandle, uint64_t, ECS_UNSET_VAL);

struct Entity {
	EntityHandle handle = EntityHandle_MAX;
	EntityHandle parentHandle = EntityHandle_MAX;
	GrBindsHandle grBindsHandle = GrBindsHandle_MAX;
	InstanceHandle instanceHandle = InstanceHandle_MAX;
	bool isMarkedForRemoval = false;
};

struct CompGrBinds {
	EntityHandle entHandle = EntityHandle_MAX;
	GrBindsHandle grBindsHandle = GrBindsHandle_MAX;
	VkPipelineLayout vkPipelineLayout = VK_NULL_HANDLE;
	VkPipeline graphicsPipeline = VK_NULL_HANDLE;
	VkDescriptorSet *vkDescriptorSets = nullptr;
	VkBuffer vertexBuffer = VK_NULL_HANDLE;
	uint32_t vertexFirstBinding = 0;
	uint32_t vertexBindingCount = 0;
	VkDeviceSize vertexOffsets = 0;
	VkBuffer normalsBuffer = VK_NULL_HANDLE;
	uint32_t normalsFirstBinding = 0;
	uint32_t normalsBindingCount = 0;
	VkDeviceSize normalsOffsets = 0;
	VkBuffer uvBuffer = VK_NULL_HANDLE;
	uint32_t uvFirstBinding = 0;
	uint32_t uvBindingCount = 0;
	VkDeviceSize uvOffsets = 0;
	VkBuffer indexBuffer = VK_NULL_HANDLE;
	uint32_t indexBindingCount = 0;
	VkDeviceSize indexOffsets = 0;
	VkDeviceSize indexCount = 0;
	VkBuffer instanceBuffer = VK_NULL_HANDLE;
	uint32_t instanceFirstBinding = 0;
	uint32_t instanceBindingCount = 0;
	uint32_t instanceCounter = 0;
	uint32_t instanceBufferMaxCount = 0;
	VkDeviceSize instanceOffsets = 0;
};

struct InstPos {
	glm::vec3 pos;
	glm::quat rot;
	glm::vec3 scale;
};

struct CompInstance {
	EntityHandle entHandle = EntityHandle_MAX;
	GrBindsHandle grBindsHandle = GrBindsHandle_MAX;
	InstanceHandle instanceHandle = InstanceHandle_MAX;
	uint64_t index = ECS_UNSET_VAL;
	InstPos instPos;
	struct {
		btVector3 localInertia;
		btCollisionShape *collisionShape;
		btDefaultMotionState defaultMotionState;
		btRigidBody *rigidBody;
	} bt;
	bool isNeedingUpdated = false;
};

#endif /* PKE_COMPONENTS_HPP */