Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
Commands.h
Go to the documentation of this file.
1/*
2Copyright (c) 2018 DIVIDE-Studio
3Copyright (c) 2009 Ionut Cava
4
5This file is part of DIVIDE Framework.
6
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software
9and associated documentation files (the "Software"), to deal in the Software
10without restriction,
11including without limitation the rights to use, copy, modify, merge, publish,
12distribute, sublicense,
13and/or sell copies of the Software, and to permit persons to whom the
14Software is furnished to do so,
15subject to the following conditions:
16
17The above copyright notice and this permission notice shall be included in
18all copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21IMPLIED,
22INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23PARTICULAR PURPOSE AND NONINFRINGEMENT.
24IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25DAMAGES OR OTHER LIABILITY,
26WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
27IN CONNECTION WITH THE SOFTWARE
28OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30*/
31
32#pragma once
33#ifndef DVD_GFX_COMMAND_H_
34#define DVD_GFX_COMMAND_H_
35
36namespace Divide {
37
38namespace GFX {
39
40enum class CommandType : U8;
41class CommandBuffer;
42
43struct CommandBase;
44
45template <CommandType> struct MapToDataType_t;
46
47template <CommandType T>
49
51{
52 explicit CommandBase(CommandType type) : _type( type ) {}
53
54 CommandBase(const CommandBase&) = default;
55 CommandBase& operator=(const CommandBase&) = default;
56
57 virtual ~CommandBase() = default;
58
59 template<typename T> requires std::is_base_of_v<CommandBase, T>
60 [[nodiscard]] FORCE_INLINE T* As() { return static_cast<T*>(this); }
61
62 virtual void addToBuffer(CommandBuffer* buffer) const = 0;
63
65
66protected:
67 friend class CommandBuffer;
68 virtual void DeleteCmd( CommandBase*& cmd ) const = 0;
69};
70
71template<CommandType EnumVal>
73{
74 static constexpr CommandType EType = EnumVal;
75
77
78 virtual void addToBuffer(CommandBuffer* buffer) const final;
79
80protected:
81 virtual void DeleteCmd(CommandBase*& cmd) const final;
82};
83
84string ToString(const CommandBase& cmd, CommandType type, U16 indent);
85
86
87#define DEFINE_COMMAND_BEGIN(Name, Enum) \
88struct Name;\
89template<> struct MapToDataType_t<Enum> { using type = Name; }; \
90struct Name final : public Command<Enum> { \
91PROPERTY_RW(bool, flag, false)
92
93#define DEFINE_COMMAND_END(Name) }
94
95#define DEFINE_COMMAND(Name, Enum) \
96DEFINE_COMMAND_BEGIN(Name, Enum);\
97DEFINE_COMMAND_END(Name)
98
99}; //namespace GFX
100}; //namespace Divide
101
102#endif //DVD_GFX_COMMAND_H_
103
104#include "Commands.inl"
#define FORCE_INLINE
void ToString(const CommandBase &cmd, const CommandType type, I32 &crtIndent, string &out)
typename MapToDataType_t< T >::type MapToDataType
Definition: Commands.h:48
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
uint8_t U8
uint16_t U16
CommandBase(const CommandBase &)=default
virtual void addToBuffer(CommandBuffer *buffer) const =0
virtual ~CommandBase()=default
PROPERTY_R(CommandType, type)
CommandBase & operator=(const CommandBase &)=default
CommandBase(CommandType type)
Definition: Commands.h:52
FORCE_INLINE T * As()
Definition: Commands.h:60
virtual void DeleteCmd(CommandBase *&cmd) const =0
static constexpr CommandType EType
Definition: Commands.h:74
virtual void DeleteCmd(CommandBase *&cmd) const final
Definition: Commands.inl:64
virtual void addToBuffer(CommandBuffer *buffer) const final
Definition: Commands.inl:57