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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
|
#pragma once
#include "ieclass.h"
#include "irender.h"
#include "ifilesystem.h"
#include "math/Vector3.h"
#include "math/AABB.h"
#include "string/string.h"
#include "generic/Lazy.h"
#include "parser/DefTokeniser.h"
#include "decl/DeclarationBase.h"
#include <vector>
#include <map>
#include <memory>
#include <optional>
#include <sigc++/connection.h>
/* FORWARD DECLS */
class Shader;
namespace eclass
{
/// Implementation of the IEntityClass interface.
class EntityClass :
public decl::DeclarationBase<IEntityClass>
{
public:
/// EntityClass pointer type
using Ptr = std::shared_ptr<EntityClass>;
private:
// Parent class pointer (or NULL)
EntityClass* _parent = nullptr;
// UI visibility of this entity class
Lazy<vfs::Visibility> _visibility;
// Should this entity type be treated as a light?
bool _isLight = false;
// Colour of this entity
Vector4 _colour;
bool _colourTransparent = false;
// Does this entity have a fixed size?
bool _fixedSize;
// Map of named EntityAttribute structures. EntityAttributes are picked
// up from the DEF file during parsing. Ignores key case.
using EntityAttributeMap = std::map<std::string, EntityClassAttribute, string::ILess>;
EntityAttributeMap _attributes;
// Flag to indicate inheritance resolved. An EntityClass resolves its
// inheritance by copying all values from the parent onto the child,
// after recursively instructing the parent to resolve its own inheritance.
bool _inheritanceResolved = false;
// Emitted when contents are reloaded
sigc::signal<void> _changedSignal;
bool _blockChangeSignal = false;
sigc::connection _parentChangedConnection;
private:
// Resolve inheritance for this class.
void resolveInheritance();
vfs::Visibility determineVisibilityFromValues();
// Clear all contents (done before parsing from tokens)
void clear();
void parseEditorSpawnarg(const std::string& key, const std::string& value);
void setIsLight(bool val);
// Visit attributes recursively, parent first then child
using InternalAttrVisitor = std::function<void(const EntityClassAttribute&)>;
void forEachAttributeInternal(InternalAttrVisitor visitor,
bool editorKeys) const;
// Return attribute if found, possibly checking parents
EntityClassAttribute* getAttribute(const std::string&, bool includeInherited = true);
public:
/// Construct a named EntityClass
EntityClass(const std::string& name);
~EntityClass();
/// Create a heap-allocated default/empty EntityClass
static Ptr CreateDefault(const std::string& name);
Type getClassType() override;
void emplaceAttribute(EntityClassAttribute&& attribute);
// IEntityClass implementation
IEntityClass* getParent() override;
vfs::Visibility getVisibility() override;
sigc::signal<void>& changedSignal() override;
bool isFixedSize() override;
AABB getBounds() override;
bool isLight() override;
const Vector4& getColour() override;
/// Set the display colour
void setColour(const Vector4& colour) override;
// Resets the colour to the value defined in the attributes
void resetColour();
std::string getAttributeValue(const std::string&, bool includeInherited = true) override;
std::string getAttributeType(const std::string& name) override;
std::string getAttributeDescription(const std::string& name) override;
void forEachAttribute(AttributeVisitor, bool) override;
bool isOfType(const std::string& className) override;
void emitChangedSignal()
{
if (!_blockChangeSignal)
{
_changedSignal.emit();
}
}
void blockChangedSignal(bool block)
{
_blockChangeSignal = block;
}
protected:
// Initialises this class from the given tokens
void parseFromTokens(parser::DefTokeniser& tokeniser) override;
// Clears the structure before parsing
void onBeginParsing() override;
// After parsing, inheritance and colour overrides will be resolved
void onParsingFinished() override;
void onSyntaxBlockAssigned(const decl::DeclarationBlockSyntax& block) override;
};
}
|