-
Notifications
You must be signed in to change notification settings - Fork 395
Expand file tree
/
Copy pathComponent.h
More file actions
74 lines (65 loc) · 1.88 KB
/
Component.h
File metadata and controls
74 lines (65 loc) · 1.88 KB
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
// ----------------------------------------------------------------
// From Game Programming in C++ by Sanjay Madhav
// Copyright (C) 2017 Sanjay Madhav. All rights reserved.
//
// Released under the BSD License
// See LICENSE in root directory for full details.
// ----------------------------------------------------------------
#pragma once
#include "Math.h"
#include <rapidjson/document.h>
class Component
{
public:
enum TypeID
{
TComponent = 0,
TAudioComponent,
TBallMove,
TBoxComponent,
TCameraComponent,
TFollowCamera,
TMeshComponent,
TMoveComponent,
TSkeletalMeshComponent,
TSpriteComponent,
TMirrorCamera,
TPointLightComponent,
TTargetComponent,
NUM_COMPONENT_TYPES
};
static const char* TypeNames[NUM_COMPONENT_TYPES];
// Constructor
// (the lower the update order, the earlier the component updates)
Component(class Actor* owner, int updateOrder = 100);
// Destructor
virtual ~Component();
// Update this component by delta time
virtual void Update(float deltaTime);
// Process input for this component
virtual void ProcessInput(const uint8_t* keyState) {}
// Called when world transform changes
virtual void OnUpdateWorldTransform();
class Actor* GetOwner() { return mOwner; }
int GetUpdateOrder() const { return mUpdateOrder; }
virtual TypeID GetType() const = 0;
// Load/Save
virtual void LoadProperties(const rapidjson::Value& inObj);
virtual void SaveProperties(rapidjson::Document::AllocatorType& alloc,
rapidjson::Value& inObj) const;
// Create a component with specified properties
template <typename T>
static Component* Create(class Actor* actor, const rapidjson::Value& inObj)
{
// Dynamically allocate component of type T
T* t = new T(actor);
// Call LoadProperties on new component
t->LoadProperties(inObj);
return t;
}
protected:
// Owning actor
class Actor* mOwner;
// Update order of component
int mUpdateOrder;
};