Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
Component.h
Go to the documentation of this file.
1/* Copyright (C) 2022 Wildfire Games.
2 * This file is part of 0 A.D.
3 *
4 * 0 A.D. is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * 0 A.D. is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef INCLUDED_COMPONENT
19#define INCLUDED_COMPONENT
20
21// These headers are included because they are required in component implementation,
22// so including them here transitively makes sense.
31
32#define REGISTER_COMPONENT_TYPE(cname) \
33 void RegisterComponentType_##cname(CComponentManager& mgr) \
34 { \
35 IComponent::RegisterComponentType(mgr, CCmp##cname::GetInterfaceId(), CID_##cname, CCmp##cname::Allocate, CCmp##cname::Deallocate, #cname, CCmp##cname::GetSchema()); \
36 CCmp##cname::ClassInit(mgr); \
37 }
38
39#define DEFAULT_COMPONENT_ALLOCATOR(cname) \
40 static IComponent* Allocate(const ScriptInterface&, JS::HandleValue) { return new CCmp##cname(); } \
41 static void Deallocate(IComponent* cmp) { delete static_cast<CCmp##cname*> (cmp); } \
42 int GetComponentTypeId() const override \
43 { \
44 return CID_##cname; \
45 }
46
47#define DEFAULT_MOCK_COMPONENT() \
48 int GetComponentTypeId() const override \
49 { \
50 return -1; \
51 } \
52 void Init(const CParamNode& UNUSED(paramNode)) override \
53 { \
54 } \
55 void Deinit() override \
56 { \
57 } \
58 void Serialize(ISerializer& UNUSED(serialize)) override \
59 { \
60 } \
61 void Deserialize(const CParamNode& UNUSED(paramNode), IDeserializer& UNUSED(deserialize)) override \
62 { \
63 } \
64
65#endif // INCLUDED_COMPONENT