aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/Component.h
blob: fc0268cec7b9a159f5e23d0cf51e5ed9bc519947 (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
#pragma once

#include <memory>

#include "types.h"

namespace crepe {

class ComponentManager;

/**
 * \brief Base class for all components
 *
 * This class is the base class for all components. It provides a common interface for all
 * components.
 */
class Component {
public:
	//! Whether the component is active
	bool active = true;
	/**
	 * \brief The id of the GameObject this component belongs to
	 *
	 * \note Only systems are supposed to use this member, but since friend
	 * relations aren't inherited this needs to be public.
	 */
	const game_object_id_t game_object_id;

protected:
	/**
	 * \param id The id of the GameObject this component belongs to
	 */
	Component(game_object_id_t id);
	//! Only ComponentManager can create components
	friend class ComponentManager;

	// components are never moved
	Component(Component &&) = delete;
	virtual Component & operator=(Component &&) = delete;

protected:
	virtual std::unique_ptr<Component> save() const;
	Component(const Component &) = default;
	virtual void restore(const Component & snapshot);
	virtual Component & operator=(const Component &);

public:
	virtual ~Component() = default;

public:
	/**
	 * \brief Get the maximum number of instances for this component
	 *
	 * This method returns -1 by default, which means that there is no limit for the number of
	 * instances. Concrete components can override this method to set a limit.
	 *
	 * \return The maximum number of instances for this component
	 */
	virtual int get_instances_max() const { return -1; }
};

} // namespace crepe