flags refactor
This commit is contained in:
parent
e1520b4737
commit
d8c3776df4
14 changed files with 140 additions and 193 deletions
|
@ -64,18 +64,16 @@ struct AnimationModuleImpl final : AnimationModule {
|
|||
};
|
||||
|
||||
|
||||
struct PropertyAnimator
|
||||
{
|
||||
struct Key
|
||||
{
|
||||
struct PropertyAnimator {
|
||||
struct Key {
|
||||
int frame0;
|
||||
int frame1;
|
||||
float value0;
|
||||
float value1;
|
||||
};
|
||||
|
||||
enum Flags
|
||||
{
|
||||
enum Flags {
|
||||
NONE = 0,
|
||||
LOOPED = 1 << 0,
|
||||
DISABLED = 1 << 1
|
||||
};
|
||||
|
@ -85,7 +83,7 @@ struct AnimationModuleImpl final : AnimationModule {
|
|||
PropertyAnimation* animation;
|
||||
Array<Key> keys;
|
||||
|
||||
FlagSet<Flags, u32> flags;
|
||||
Flags flags = Flags::NONE;
|
||||
float time;
|
||||
};
|
||||
|
||||
|
@ -422,14 +420,14 @@ struct AnimationModuleImpl final : AnimationModule {
|
|||
|
||||
bool isPropertyAnimatorEnabled(EntityRef entity) override
|
||||
{
|
||||
return !m_property_animators[entity].flags.isSet(PropertyAnimator::DISABLED);
|
||||
return !isFlagSet(m_property_animators[entity].flags, PropertyAnimator::DISABLED);
|
||||
}
|
||||
|
||||
|
||||
void enablePropertyAnimator(EntityRef entity, bool enabled) override
|
||||
{
|
||||
PropertyAnimator& animator = m_property_animators[entity];
|
||||
animator.flags.set(PropertyAnimator::DISABLED, !enabled);
|
||||
setFlag(animator.flags, PropertyAnimator::DISABLED, !enabled);
|
||||
animator.time = 0;
|
||||
if (!enabled)
|
||||
{
|
||||
|
@ -802,7 +800,7 @@ struct AnimationModuleImpl final : AnimationModule {
|
|||
if (!animation || !animation->isReady()) continue;
|
||||
if (animation->curves.empty()) continue;
|
||||
if (animation->curves[0].frames.empty()) continue;
|
||||
if (animator.flags.isSet(PropertyAnimator::DISABLED)) continue;
|
||||
if (animator.flags & PropertyAnimator::DISABLED) continue;
|
||||
|
||||
animator.time += time_delta;
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "animation.h"
|
||||
#include "engine/flag_set.h"
|
||||
#include "engine/hash.h"
|
||||
#include "engine/resource.h"
|
||||
#include "engine/stream.h"
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
#include "engine/allocator.h"
|
||||
#include "engine/array.h"
|
||||
#include "engine/delegate_list.h"
|
||||
#include "engine/flag_set.h"
|
||||
#include "engine/hash_map.h"
|
||||
#include "engine/metaprogramming.h"
|
||||
#include "engine/log.h"
|
||||
|
@ -19,23 +18,23 @@ namespace Lumix {
|
|||
|
||||
struct AsyncItem {
|
||||
enum class Flags : u32 {
|
||||
NONE = 0,
|
||||
FAILED = 1 << 0,
|
||||
CANCELED = 1 << 1,
|
||||
};
|
||||
|
||||
AsyncItem(IAllocator& allocator) : data(allocator) {}
|
||||
|
||||
bool isFailed() const { return flags.isSet(Flags::FAILED); }
|
||||
bool isCanceled() const { return flags.isSet(Flags::CANCELED); }
|
||||
bool isFailed() const { return isFlagSet(flags, Flags::FAILED); }
|
||||
bool isCanceled() const { return isFlagSet(flags, Flags::CANCELED); }
|
||||
|
||||
FileSystem::ContentCallback callback;
|
||||
OutputMemoryStream data;
|
||||
Path path;
|
||||
u32 id = 0;
|
||||
FlagSet<Flags, u32> flags;
|
||||
Flags flags = Flags::NONE;
|
||||
};
|
||||
|
||||
|
||||
struct FileSystemImpl;
|
||||
|
||||
|
||||
|
@ -140,14 +139,14 @@ struct FileSystemImpl : FileSystem {
|
|||
MutexGuard lock(m_mutex);
|
||||
for (AsyncItem& item : m_queue) {
|
||||
if (item.id == async.value) {
|
||||
item.flags.set(AsyncItem::Flags::CANCELED);
|
||||
item.flags |= AsyncItem::Flags::CANCELED;
|
||||
--m_work_counter;
|
||||
return;
|
||||
}
|
||||
}
|
||||
for (AsyncItem& item : m_finished) {
|
||||
if (item.id == async.value) {
|
||||
item.flags.set(AsyncItem::Flags::CANCELED);
|
||||
item.flags |= AsyncItem::Flags::CANCELED;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -280,7 +279,7 @@ int FSTask::task()
|
|||
m_fs.m_finished.emplace(static_cast<AsyncItem&&>(m_fs.m_queue[0]));
|
||||
m_fs.m_finished.back().data = static_cast<OutputMemoryStream&&>(data);
|
||||
if(!success) {
|
||||
m_fs.m_finished.back().flags.set(AsyncItem::Flags::FAILED);
|
||||
m_fs.m_finished.back().flags |= AsyncItem::Flags::FAILED;
|
||||
}
|
||||
}
|
||||
m_fs.m_queue.erase(0);
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
|
||||
namespace Lumix
|
||||
{
|
||||
|
||||
|
||||
template <typename Enum, typename Base>
|
||||
struct FlagSet
|
||||
{
|
||||
void clear() { base = 0; }
|
||||
void set(Enum value, bool on) { if (on) set(value); else unset(value); }
|
||||
void set(Enum value) { base |= (Base)value; }
|
||||
void unset(Enum value) { base &= ~(Base)value; }
|
||||
bool isSet(Enum value) const { return base & (Base)value; }
|
||||
|
||||
private:
|
||||
Base base = 0;
|
||||
};
|
||||
|
||||
|
||||
} // namespace Lumix
|
|
@ -140,6 +140,22 @@ struct Span
|
|||
T* m_end;
|
||||
};
|
||||
|
||||
template<bool, class T> struct EnableIf {};
|
||||
template <class T> struct EnableIf<true, T> { using Type = T; };
|
||||
template <class T> inline constexpr bool is_enum_v = __is_enum(T);
|
||||
template <typename T, typename EnableIf<is_enum_v<T>, int>::Type = 0> constexpr T operator | (T a, T b) { return T(u64(a) | u64(b)); }
|
||||
template <typename T, typename EnableIf<is_enum_v<T>, int>::Type = 0> constexpr T operator & (T a, T b) { return T(u64(a) & u64(b)); }
|
||||
template <typename T, typename EnableIf<is_enum_v<T>, int>::Type = 0> constexpr T operator ^ (T a, T b) { return T(u64(a) ^ u64(b)); }
|
||||
template <typename T, typename EnableIf<is_enum_v<T>, int>::Type = 0> constexpr T operator |= (T a, T b) { return T(u64(a) | u64(b)); }
|
||||
template <typename T, typename EnableIf<is_enum_v<T>, int>::Type = 0> constexpr T operator &= (T a, T b) { return T(u64(a) & u64(b)); }
|
||||
template <typename T, typename EnableIf<is_enum_v<T>, int>::Type = 0> constexpr T operator ^= (T a, T b) { return T(u64(a) ^ u64(b)); }
|
||||
template <typename T, typename EnableIf<is_enum_v<T>, int>::Type = 0> constexpr T operator ~ (T a) { return T(~u64(a)); }
|
||||
template <typename E> bool isFlagSet(E flags, E flag) { return ((u64)flags & (u64)flag); }
|
||||
template <typename E> void setFlag(E& flags, E flag, bool set) {
|
||||
if (set) flags = E((u64)flags | (u64)flag);
|
||||
else flags = E(u64(flags) & ~u64(flag));
|
||||
}
|
||||
|
||||
#pragma pack(1)
|
||||
struct Color {
|
||||
Color() {}
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#include "engine/allocator.h"
|
||||
#include "engine/associative_array.h"
|
||||
#include "engine/crt.h"
|
||||
#include "engine/flag_set.h"
|
||||
#include "engine/input_system.h"
|
||||
#include "engine/log.h"
|
||||
#include "engine/os.h"
|
||||
|
@ -112,18 +111,18 @@ struct GUIImage {
|
|||
if (sprite) sprite->decRefCount();
|
||||
}
|
||||
|
||||
enum Flags : u32
|
||||
{
|
||||
enum Flags : u32 {
|
||||
NONE = 0,
|
||||
IS_ENABLED = 1 << 1
|
||||
};
|
||||
Sprite* sprite = nullptr;
|
||||
u32 color = 0xffffFFFF;
|
||||
FlagSet<Flags, u32> flags;
|
||||
Flags flags = Flags::NONE;
|
||||
};
|
||||
|
||||
|
||||
struct GUIRect {
|
||||
enum Flags : u32 {
|
||||
NONE = 0,
|
||||
IS_VALID = 1 << 0,
|
||||
IS_ENABLED = 1 << 1,
|
||||
IS_CLIP = 1 << 2
|
||||
|
@ -135,7 +134,7 @@ struct GUIRect {
|
|||
};
|
||||
|
||||
EntityRef entity;
|
||||
FlagSet<Flags, u32> flags;
|
||||
Flags flags = Flags::NONE;
|
||||
Anchor top;
|
||||
Anchor right = { 0, 1 };
|
||||
Anchor bottom = { 0, 1 };
|
||||
|
@ -147,7 +146,6 @@ struct GUIRect {
|
|||
gpu::TextureHandle* render_target = nullptr;
|
||||
};
|
||||
|
||||
|
||||
struct GUIModuleImpl final : GUIModule {
|
||||
enum class Version : i32 {
|
||||
CANVAS_3D,
|
||||
|
@ -195,15 +193,15 @@ struct GUIModuleImpl final : GUIModule {
|
|||
|
||||
void renderRect(GUIRect& rect, Draw2D& draw, const Rect& parent_rect, bool is_main)
|
||||
{
|
||||
if (!rect.flags.isSet(GUIRect::IS_VALID)) return;
|
||||
if (!rect.flags.isSet(GUIRect::IS_ENABLED)) return;
|
||||
if (!isFlagSet(rect.flags, GUIRect::IS_VALID)) return;
|
||||
if (!isFlagSet(rect.flags, GUIRect::IS_ENABLED)) return;
|
||||
|
||||
float l = parent_rect.x + rect.left.points + parent_rect.w * rect.left.relative;
|
||||
float r = parent_rect.x + rect.right.points + parent_rect.w * rect.right.relative;
|
||||
float t = parent_rect.y + rect.top.points + parent_rect.h * rect.top.relative;
|
||||
float b = parent_rect.y + rect.bottom.points + parent_rect.h * rect.bottom.relative;
|
||||
|
||||
if (rect.flags.isSet(GUIRect::IS_CLIP)) draw.pushClipRect({ l, t }, { r, b });
|
||||
if (rect.flags & GUIRect::IS_CLIP) draw.pushClipRect({ l, t }, { r, b });
|
||||
|
||||
auto button_iter = m_buttons.find(rect.entity);
|
||||
const Color* img_color = rect.image ? (Color*)&rect.image->color : nullptr;
|
||||
|
@ -220,7 +218,7 @@ struct GUIModuleImpl final : GUIModule {
|
|||
}
|
||||
}
|
||||
|
||||
if (rect.image && rect.image->flags.isSet(GUIImage::IS_ENABLED))
|
||||
if (rect.image && isFlagSet(rect.image->flags, GUIImage::IS_ENABLED))
|
||||
{
|
||||
const Color color = *img_color;
|
||||
if (rect.image->sprite && rect.image->sprite->getTexture())
|
||||
|
@ -309,7 +307,7 @@ struct GUIModuleImpl final : GUIModule {
|
|||
renderRect(*iter.value(), draw, { l, t, r - l, b - t }, is_main);
|
||||
}
|
||||
}
|
||||
if (rect.flags.isSet(GUIRect::IS_CLIP)) draw.popClipRect();
|
||||
if (rect.flags & GUIRect::IS_CLIP) draw.popClipRect();
|
||||
}
|
||||
|
||||
IVec2 getCursorPosition() override { return m_cursor_pos; }
|
||||
|
@ -366,8 +364,8 @@ struct GUIModuleImpl final : GUIModule {
|
|||
m_buttons[entity].hovered_cursor = cursor;
|
||||
}
|
||||
|
||||
void enableImage(EntityRef entity, bool enable) override { m_rects[entity]->image->flags.set(GUIImage::IS_ENABLED, enable); }
|
||||
bool isImageEnabled(EntityRef entity) override { return m_rects[entity]->image->flags.isSet(GUIImage::IS_ENABLED); }
|
||||
void enableImage(EntityRef entity, bool enable) override { setFlag(m_rects[entity]->image->flags, GUIImage::IS_ENABLED, enable); }
|
||||
bool isImageEnabled(EntityRef entity) override { return m_rects[entity]->image->flags & GUIImage::IS_ENABLED; }
|
||||
|
||||
|
||||
Vec4 getImageColorRGBA(EntityRef entity) override
|
||||
|
@ -436,14 +434,14 @@ struct GUIModuleImpl final : GUIModule {
|
|||
{
|
||||
auto iter = m_rects.find(entity);
|
||||
if (!iter.isValid()) return false;
|
||||
return iter.value()->flags.isSet(GUIRect::IS_VALID);
|
||||
return iter.value()->flags & GUIRect::IS_VALID;
|
||||
}
|
||||
|
||||
|
||||
EntityPtr getRectAt(const GUIRect& rect, const Vec2& pos, const Rect& parent_rect, EntityPtr limit) const
|
||||
{
|
||||
if (!rect.flags.isSet(GUIRect::IS_VALID)) return INVALID_ENTITY;
|
||||
if (!rect.flags.isSet(GUIRect::IS_ENABLED)) return INVALID_ENTITY;
|
||||
if (!isFlagSet(rect.flags, GUIRect::IS_VALID)) return INVALID_ENTITY;
|
||||
if (!isFlagSet(rect.flags, GUIRect::IS_ENABLED)) return INVALID_ENTITY;
|
||||
if (rect.entity.index == limit.index) return INVALID_ENTITY;
|
||||
|
||||
Rect r;
|
||||
|
@ -525,10 +523,10 @@ struct GUIModuleImpl final : GUIModule {
|
|||
return { l, t, r - l, b - t };
|
||||
}
|
||||
|
||||
void setRectClip(EntityRef entity, bool enable) override { m_rects[entity]->flags.set(GUIRect::IS_CLIP, enable); }
|
||||
bool getRectClip(EntityRef entity) override { return m_rects[entity]->flags.isSet(GUIRect::IS_CLIP); }
|
||||
void enableRect(EntityRef entity, bool enable) override { return m_rects[entity]->flags.set(GUIRect::IS_ENABLED, enable); }
|
||||
bool isRectEnabled(EntityRef entity) override { return m_rects[entity]->flags.isSet(GUIRect::IS_ENABLED); }
|
||||
void setRectClip(EntityRef entity, bool enable) override { setFlag(m_rects[entity]->flags, GUIRect::IS_CLIP, enable); }
|
||||
bool getRectClip(EntityRef entity) override { return m_rects[entity]->flags & GUIRect::IS_CLIP; }
|
||||
void enableRect(EntityRef entity, bool enable) override { return setFlag(m_rects[entity]->flags, GUIRect::IS_ENABLED, enable); }
|
||||
bool isRectEnabled(EntityRef entity) override { return m_rects[entity]->flags & GUIRect::IS_ENABLED; }
|
||||
float getRectLeftPoints(EntityRef entity) override { return m_rects[entity]->left.points; }
|
||||
void setRectLeftPoints(EntityRef entity, float value) override { m_rects[entity]->left.points = value; }
|
||||
float getRectLeftRelative(EntityRef entity) override { return m_rects[entity]->left.relative; }
|
||||
|
@ -631,7 +629,7 @@ struct GUIModuleImpl final : GUIModule {
|
|||
|
||||
~GUIModuleImpl() {
|
||||
for (GUIRect* rect : m_rects) {
|
||||
if (rect->flags.isSet(GUIRect::IS_VALID)) {
|
||||
if (rect->flags & GUIRect::IS_VALID) {
|
||||
LUMIX_DELETE(m_allocator, rect->input_field);
|
||||
LUMIX_DELETE(m_allocator, rect->image);
|
||||
LUMIX_DELETE(m_allocator, rect->text);
|
||||
|
@ -659,7 +657,7 @@ struct GUIModuleImpl final : GUIModule {
|
|||
|
||||
void handleMouseAxisEvent(const Rect& parent_rect, GUIRect& rect, const Vec2& mouse_pos, const Vec2& prev_mouse_pos)
|
||||
{
|
||||
if (!rect.flags.isSet(GUIRect::IS_ENABLED)) return;
|
||||
if (!isFlagSet(rect.flags, GUIRect::IS_ENABLED)) return;
|
||||
|
||||
const Rect& r = getRectOnCanvas(parent_rect, rect);
|
||||
|
||||
|
@ -694,7 +692,7 @@ struct GUIModuleImpl final : GUIModule {
|
|||
|
||||
bool handleMouseButtonEvent(const Rect& parent_rect, const GUIRect& rect, const InputSystem::Event& event)
|
||||
{
|
||||
if (!rect.flags.isSet(GUIRect::IS_ENABLED)) return false;
|
||||
if (!isFlagSet(rect.flags, GUIRect::IS_ENABLED)) return false;
|
||||
const bool is_up = !event.data.button.down;
|
||||
|
||||
Vec2 pos(event.data.button.x, event.data.button.y);
|
||||
|
@ -901,8 +899,7 @@ struct GUIModuleImpl final : GUIModule {
|
|||
rect->bottom = {0, 1};
|
||||
rect->left = {0, 0};
|
||||
rect->entity = entity;
|
||||
rect->flags.set(GUIRect::IS_VALID);
|
||||
rect->flags.set(GUIRect::IS_ENABLED);
|
||||
rect->flags |= GUIRect::IS_VALID | GUIRect::IS_ENABLED;
|
||||
m_world.onComponentCreated(entity, GUI_RECT_TYPE, this);
|
||||
}
|
||||
|
||||
|
@ -984,7 +981,7 @@ struct GUIModuleImpl final : GUIModule {
|
|||
}
|
||||
GUIRect& rect = *iter.value();
|
||||
rect.image = LUMIX_NEW(m_allocator, GUIImage);
|
||||
rect.image->flags.set(GUIImage::IS_ENABLED);
|
||||
rect.image->flags |= GUIImage::IS_ENABLED;
|
||||
|
||||
m_world.onComponentCreated(entity, GUI_IMAGE_TYPE, this);
|
||||
}
|
||||
|
@ -993,7 +990,7 @@ struct GUIModuleImpl final : GUIModule {
|
|||
void destroyRect(EntityRef entity)
|
||||
{
|
||||
GUIRect* rect = m_rects[entity];
|
||||
rect->flags.set(GUIRect::IS_VALID, false);
|
||||
rect->flags &= ~GUIRect::IS_VALID;
|
||||
if (!rect->image && !rect->text && !rect->input_field && !rect->render_target)
|
||||
{
|
||||
LUMIX_DELETE(m_allocator, rect);
|
||||
|
@ -1038,7 +1035,7 @@ struct GUIModuleImpl final : GUIModule {
|
|||
if (rect.text) return;
|
||||
if (rect.input_field) return;
|
||||
if (rect.render_target) return;
|
||||
if (rect.flags.isSet(GUIRect::IS_VALID)) return;
|
||||
if (rect.flags & GUIRect::IS_VALID) return;
|
||||
|
||||
const EntityRef e = rect.entity;
|
||||
LUMIX_DELETE(m_allocator, &rect);
|
||||
|
@ -1138,14 +1135,13 @@ struct GUIModuleImpl final : GUIModule {
|
|||
}
|
||||
GUIRect* rect = iter.value();
|
||||
rect->entity = entity;
|
||||
rect->flags.clear();
|
||||
rect->flags.set(flags);
|
||||
rect->flags = flags;
|
||||
|
||||
serializer.read(rect->top);
|
||||
serializer.read(rect->right);
|
||||
serializer.read(rect->bottom);
|
||||
serializer.read(rect->left);
|
||||
if (rect->flags.isSet(GUIRect::IS_VALID)) {
|
||||
if (rect->flags & GUIRect::IS_VALID) {
|
||||
m_world.onComponentCreated(rect->entity, GUI_RECT_TYPE, this);
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
#include "engine/associative_array.h"
|
||||
#include "engine/hash.h"
|
||||
#include "engine/engine.h"
|
||||
#include "engine/flag_set.h"
|
||||
#include "engine/allocator.h"
|
||||
#include "engine/input_system.h"
|
||||
#include "engine/metaprogramming.h"
|
||||
|
@ -320,6 +319,7 @@ namespace Lumix
|
|||
struct ScriptInstance : ScriptEnvironment
|
||||
{
|
||||
enum Flags : u32 {
|
||||
NONE = 0,
|
||||
ENABLED = 1 << 0,
|
||||
LOADED = 1 << 1,
|
||||
MOVED_FROM = 1 << 2
|
||||
|
@ -359,7 +359,7 @@ namespace Lumix
|
|||
lua_setfield(m_state, -2, "this"); // [env]
|
||||
lua_pop(m_state, 1); // []
|
||||
|
||||
m_flags.set(ENABLED);
|
||||
m_flags = Flags(m_flags | ENABLED);
|
||||
}
|
||||
|
||||
ScriptInstance(const ScriptInstance&) = delete;
|
||||
|
@ -370,17 +370,15 @@ namespace Lumix
|
|||
, m_script(rhs.m_script)
|
||||
, m_flags(rhs.m_flags)
|
||||
{
|
||||
ASSERT(!rhs.m_flags.isSet(MOVED_FROM));
|
||||
m_environment = rhs.m_environment;
|
||||
m_thread_ref = rhs.m_thread_ref;
|
||||
m_state = rhs.m_state;
|
||||
rhs.m_script = nullptr;
|
||||
rhs.m_flags.set(MOVED_FROM);
|
||||
rhs.m_flags = Flags(rhs.m_flags | MOVED_FROM);
|
||||
}
|
||||
|
||||
void operator =(ScriptInstance&& rhs)
|
||||
{
|
||||
ASSERT(!rhs.m_flags.isSet(MOVED_FROM));
|
||||
m_properties = rhs.m_properties.move();
|
||||
m_environment = rhs.m_environment;
|
||||
m_thread_ref = rhs.m_thread_ref;
|
||||
|
@ -389,11 +387,11 @@ namespace Lumix
|
|||
m_state = rhs.m_state;
|
||||
m_flags = rhs.m_flags;
|
||||
rhs.m_script = nullptr;
|
||||
rhs.m_flags.set(MOVED_FROM);
|
||||
rhs.m_flags = Flags(rhs.m_flags | MOVED_FROM);
|
||||
}
|
||||
|
||||
~ScriptInstance() {
|
||||
if (!m_flags.isSet(MOVED_FROM)) {
|
||||
if (!(m_flags & MOVED_FROM)) {
|
||||
if (m_script) {
|
||||
m_script->getObserverCb().unbind<&ScriptComponent::onScriptLoaded>(m_cmp);
|
||||
m_script->decRefCount();
|
||||
|
@ -427,7 +425,7 @@ namespace Lumix
|
|||
ScriptComponent* m_cmp;
|
||||
LuaScript* m_script = nullptr;
|
||||
Array<Property> m_properties;
|
||||
FlagSet<Flags, u32> m_flags;
|
||||
Flags m_flags = Flags::NONE;
|
||||
};
|
||||
|
||||
struct InlineScriptComponent : ScriptEnvironment {
|
||||
|
@ -1667,7 +1665,7 @@ namespace Lumix
|
|||
}
|
||||
|
||||
void startScript(EntityRef entity, ScriptInstance& instance, bool is_reload) {
|
||||
if (!instance.m_flags.isSet(ScriptInstance::ENABLED)) return;
|
||||
if (!(instance.m_flags & ScriptInstance::ENABLED)) return;
|
||||
|
||||
if (is_reload) disableScript(instance);
|
||||
startScriptInternal(entity, instance, is_reload);
|
||||
|
@ -2074,7 +2072,7 @@ namespace Lumix
|
|||
auto& instance = scr->m_scripts[j];
|
||||
if (!instance.m_script) continue;
|
||||
if (!instance.m_script->isReady()) continue;
|
||||
if (!instance.m_flags.isSet(ScriptInstance::ENABLED)) continue;
|
||||
if (!(instance.m_flags & ScriptInstance::ENABLED)) continue;
|
||||
|
||||
startScript(instance.m_cmp->m_entity, instance, false);
|
||||
}
|
||||
|
@ -2331,9 +2329,9 @@ namespace Lumix
|
|||
void enableScript(EntityRef entity, int scr_index, bool enable) override
|
||||
{
|
||||
ScriptInstance& inst = m_scripts[entity]->m_scripts[scr_index];
|
||||
if (inst.m_flags.isSet(ScriptInstance::ENABLED) == enable) return;
|
||||
if (isFlagSet(inst.m_flags, ScriptInstance::ENABLED) == enable) return;
|
||||
|
||||
inst.m_flags.set(ScriptInstance::ENABLED, enable);
|
||||
setFlag(inst.m_flags, ScriptInstance::ENABLED, enable);
|
||||
|
||||
setEnableProperty(entity, scr_index, inst, enable);
|
||||
|
||||
|
@ -2350,7 +2348,7 @@ namespace Lumix
|
|||
|
||||
bool isScriptEnabled(EntityRef entity, int scr_index) override
|
||||
{
|
||||
return m_scripts[entity]->m_scripts[scr_index].m_flags.isSet(ScriptInstance::ENABLED);
|
||||
return m_scripts[entity]->m_scripts[scr_index].m_flags & ScriptInstance::ENABLED;
|
||||
}
|
||||
|
||||
|
||||
|
@ -2415,7 +2413,7 @@ namespace Lumix
|
|||
void LuaScriptModuleImpl::ScriptInstance::onScriptLoaded(LuaScriptModuleImpl& module, struct ScriptComponent& cmp, int scr_index) {
|
||||
LuaWrapper::DebugGuard guard(m_state);
|
||||
|
||||
bool is_reload = m_flags.isSet(LOADED);
|
||||
bool is_reload = m_flags & LOADED;
|
||||
|
||||
lua_rawgeti(m_state, LUA_REGISTRYINDEX, m_environment); // [env]
|
||||
ASSERT(lua_type(m_state, -1) == LUA_TTABLE);
|
||||
|
@ -2444,9 +2442,9 @@ namespace Lumix
|
|||
|
||||
cmp.detectProperties(*this);
|
||||
|
||||
bool enabled = m_flags.isSet(ScriptInstance::ENABLED);
|
||||
bool enabled = m_flags & ScriptInstance::ENABLED;
|
||||
module.setEnableProperty(cmp.m_entity, scr_index, *this, enabled);
|
||||
m_flags.set(LOADED);
|
||||
m_flags = Flags(m_flags | LOADED);
|
||||
|
||||
lua_rawgeti(m_state, LUA_REGISTRYINDEX, m_environment); // [env]
|
||||
lua_getfield(m_state, -1, "awake"); // [env, awake]
|
||||
|
|
|
@ -2233,7 +2233,7 @@ struct ModelPlugin final : AssetBrowser::IPlugin, AssetCompiler::IPlugin {
|
|||
int tri_count = 0;
|
||||
for (i32 j = lods[i].from; j <= lods[i].to; ++j) {
|
||||
i32 indices_count = (i32)m_resource->getMesh(j).indices.size() >> 1;
|
||||
if (!m_resource->getMesh(j).flags.isSet(Mesh::Flags::INDICES_16_BIT)) {
|
||||
if (!isFlagSet(m_resource->getMesh(j).flags, Mesh::Flags::INDICES_16_BIT)) {
|
||||
indices_count >>= 1;
|
||||
}
|
||||
tri_count += indices_count / 3;
|
||||
|
@ -3652,7 +3652,7 @@ struct EnvironmentProbePlugin final : PropertyGrid::IPlugin
|
|||
if (m_probe_counter) ImGui::Text("Generating...");
|
||||
else {
|
||||
const ReflectionProbe& probe = module->getReflectionProbe(e);
|
||||
if (probe.flags.isSet(ReflectionProbe::ENABLED)) {
|
||||
if (probe.flags & ReflectionProbe::ENABLED) {
|
||||
const Path path("universes/probes/", probe.guid, ".lbc");
|
||||
ImGuiEx::Label("Path");
|
||||
ImGuiEx::TextUnformatted(path);
|
||||
|
|
|
@ -356,33 +356,6 @@ inline StateFlags getStencilStateBits(u8 write_mask, StencilFuncs func, u8 ref,
|
|||
{
|
||||
return StateFlags(((u64)write_mask << 23) | ((u64)func << 31) | ((u64)ref << 35) | ((u64)mask << 43) | ((u64)sfail << 51) | ((u64)dpfail << 55) | ((u64)dppass << 59));
|
||||
}
|
||||
|
||||
constexpr MemoryBarrierType operator ~(MemoryBarrierType a) { return MemoryBarrierType(~(u64)a); }
|
||||
constexpr MemoryBarrierType operator | (MemoryBarrierType a, MemoryBarrierType b) { return MemoryBarrierType((u64)a | (u64)b); }
|
||||
constexpr MemoryBarrierType operator & (MemoryBarrierType a, MemoryBarrierType b) { return MemoryBarrierType((u64)a & (u64)b); }
|
||||
|
||||
constexpr StateFlags operator ~(StateFlags a) { return StateFlags(~(u64)a); }
|
||||
constexpr StateFlags operator | (StateFlags a, StateFlags b) { return StateFlags((u64)a | (u64)b); }
|
||||
constexpr StateFlags operator & (StateFlags a, StateFlags b) { return StateFlags((u64)a & (u64)b); }
|
||||
|
||||
constexpr ClearFlags operator | (ClearFlags a, ClearFlags b) { return ClearFlags((u32)a | (u32)b); }
|
||||
constexpr ClearFlags operator & (ClearFlags a, ClearFlags b) { return ClearFlags((u32)a & (u32)b); }
|
||||
|
||||
constexpr FramebufferFlags operator | (FramebufferFlags a, FramebufferFlags b) { return FramebufferFlags((u32)a | (u32)b); }
|
||||
constexpr FramebufferFlags operator & (FramebufferFlags a, FramebufferFlags b) { return FramebufferFlags((u32)a & (u32)b); }
|
||||
|
||||
constexpr TextureFlags operator ~(TextureFlags a) { return TextureFlags(~(u32)a); }
|
||||
constexpr TextureFlags operator | (TextureFlags a, TextureFlags b) { return TextureFlags((u32)a | (u32)b); }
|
||||
constexpr TextureFlags operator & (TextureFlags a, TextureFlags b) { return TextureFlags((u32)a & (u32)b); }
|
||||
|
||||
constexpr BufferFlags operator | (BufferFlags a, BufferFlags b) { return BufferFlags((u32)a | (u32)b); }
|
||||
constexpr BufferFlags operator & (BufferFlags a, BufferFlags b) { return BufferFlags((u32)a & (u32)b); }
|
||||
|
||||
constexpr BindShaderBufferFlags operator & (BindShaderBufferFlags a, BindShaderBufferFlags b) { return BindShaderBufferFlags((u32)a & (u32)b); }
|
||||
|
||||
constexpr InitFlags operator ~(InitFlags a) { return InitFlags(~(u32)a); }
|
||||
constexpr InitFlags operator | (InitFlags a, InitFlags b) { return InitFlags((u32)a | (u32)b); }
|
||||
constexpr InitFlags operator & (InitFlags a, InitFlags b) { return InitFlags((u32)a & (u32)b); }
|
||||
|
||||
} // namespace gpu
|
||||
|
||||
|
|
|
@ -191,7 +191,7 @@ RayCastModelHit Model::castRay(const Vec3& origin, const Vec3& dir, const Pose*
|
|||
const bool is_mesh_skinned = !mesh.skin.empty() && is_skinned;
|
||||
const u16* indices16 = (const u16*)mesh.indices.data();
|
||||
const u32* indices32 = (const u32*)mesh.indices.data();
|
||||
const bool is16 = mesh.flags.isSet(Mesh::Flags::INDICES_16_BIT);
|
||||
const bool is16 = mesh.flags & Mesh::Flags::INDICES_16_BIT;
|
||||
const int index_size = is16 ? 2 : 4;
|
||||
const Vec3* vertices = mesh.vertices.begin();
|
||||
|
||||
|
@ -505,7 +505,7 @@ bool Model::parseMeshes(InputMemoryStream& file, FileVersion version)
|
|||
mesh.indices_count = indices_count;
|
||||
file.read(mesh.indices.getMutableData(), mesh.indices.size());
|
||||
|
||||
if (index_size == 2) mesh.flags.set(Mesh::Flags::INDICES_16_BIT);
|
||||
if (index_size == 2) mesh.flags |= Mesh::Flags::INDICES_16_BIT;
|
||||
const Renderer::MemRef mem = m_renderer.copy(mesh.indices.data(), (u32)mesh.indices.size());
|
||||
mesh.index_buffer_handle = m_renderer.createBuffer(mem, gpu::BufferFlags::IMMUTABLE);
|
||||
mesh.index_type = index_size == 2 ? gpu::DataType::U16 : gpu::DataType::U32;
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include "engine/allocators.h"
|
||||
#include "engine/array.h"
|
||||
#include "engine/flag_set.h"
|
||||
#include "engine/geometry.h"
|
||||
#include "engine/hash.h"
|
||||
#include "engine/hash_map.h"
|
||||
|
@ -75,7 +74,10 @@ struct LUMIX_RENDERER_API Mesh {
|
|||
LAST_TYPE
|
||||
};
|
||||
|
||||
enum Flags : u8 { INDICES_16_BIT = 1 << 0 };
|
||||
enum Flags : u8 {
|
||||
NONE = 0,
|
||||
INDICES_16_BIT = 1 << 0
|
||||
};
|
||||
|
||||
Mesh(Material* mat,
|
||||
const gpu::VertexDecl& vertex_decl,
|
||||
|
@ -90,13 +92,13 @@ struct LUMIX_RENDERER_API Mesh {
|
|||
void operator=(Mesh&&) = delete;
|
||||
|
||||
void setMaterial(Material* material, Model& model, Renderer& renderer);
|
||||
bool areIndices16() const { return flags.isSet(Flags::INDICES_16_BIT); }
|
||||
bool areIndices16() const { return flags & Flags::INDICES_16_BIT; }
|
||||
|
||||
Type type;
|
||||
OutputMemoryStream indices;
|
||||
Array<Vec3> vertices;
|
||||
Array<Skin> skin;
|
||||
FlagSet<Flags, u8> flags;
|
||||
Flags flags = Flags::NONE;
|
||||
u32 sort_key;
|
||||
u8 layer;
|
||||
String name;
|
||||
|
@ -113,7 +115,6 @@ struct LUMIX_RENDERER_API Mesh {
|
|||
int indices_count;
|
||||
};
|
||||
|
||||
|
||||
struct LODMeshIndices
|
||||
{
|
||||
int from;
|
||||
|
|
|
@ -2234,7 +2234,7 @@ struct PipelineImpl final : Pipeline
|
|||
for (auto iter = furs.begin(); iter.isValid(); ++iter) {
|
||||
const EntityRef e = iter.key();
|
||||
if (e.index >= (i32)mi.length()) continue;
|
||||
if (!mi[e.index].flags.isSet(ModelInstance::VALID)) continue;
|
||||
if ((mi[e.index].flags & ModelInstance::VALID) == 0) continue;
|
||||
if (!iter.value().enabled) continue;
|
||||
|
||||
const Model* model = mi[e.index].model;
|
||||
|
@ -3032,7 +3032,7 @@ struct PipelineImpl final : Pipeline
|
|||
light.attenuation_param = pl.attenuation_param;
|
||||
|
||||
auto iter = m_shadow_atlas.map.find(e);
|
||||
if (pl.flags.isSet(PointLight::CAST_SHADOWS)) {
|
||||
if (pl.flags & PointLight::CAST_SHADOWS) {
|
||||
light.atlas_idx = iter.isValid() ? iter.value() : -1;
|
||||
atlas_sorter.push(i, computeShadowPriority(light.radius, light_pos, cam_pos), e);
|
||||
}
|
||||
|
@ -3069,7 +3069,7 @@ struct PipelineImpl final : Pipeline
|
|||
light.atlas_idx = m_shadow_atlas.add(ShadowAtlas::getGroup(i), e);
|
||||
bakeShadow(pl, light.atlas_idx);
|
||||
}
|
||||
else if (pl.flags.isSet(PointLight::DYNAMIC)) {
|
||||
else if (pl.flags & PointLight::DYNAMIC) {
|
||||
bakeShadow(pl, light.atlas_idx);
|
||||
}
|
||||
shadow_atlas_matrices[light.atlas_idx] = getShadowMatrix(pl, light.atlas_idx);
|
||||
|
@ -3136,7 +3136,7 @@ struct PipelineImpl final : Pipeline
|
|||
const Span<EntityRef> refl_probe_entities = m_module->getReflectionProbesEntities();
|
||||
for (u32 i = 0, c = module_refl_probes.length(); i < c; ++i) {
|
||||
const ReflectionProbe& refl_probe = module_refl_probes[i];
|
||||
if (!refl_probe.flags.isSet(ReflectionProbe::ENABLED)) continue;
|
||||
if (!isFlagSet(refl_probe.flags, ReflectionProbe::ENABLED)) continue;
|
||||
const EntityRef e = refl_probe_entities[i];
|
||||
ClusterReflProbe& probe = refl_probes[i];
|
||||
probe.pos = Vec3(world.getPosition(e) - cam_pos);
|
||||
|
@ -3158,7 +3158,7 @@ struct PipelineImpl final : Pipeline
|
|||
const Span<EntityRef> env_probe_entities = m_module->getEnvironmentProbesEntities();
|
||||
for (u32 probe_idx = 0, c = module_env_probes.length(); probe_idx < c; ++probe_idx) {
|
||||
const EnvironmentProbe& env_probe = module_env_probes[probe_idx];
|
||||
if (!env_probe.flags.isSet(EnvironmentProbe::ENABLED)) continue;
|
||||
if (!isFlagSet(env_probe.flags, EnvironmentProbe::ENABLED)) continue;
|
||||
|
||||
const EntityRef e = env_probe_entities[probe_idx];
|
||||
ClusterEnvProbe& probe = env_probes[probe_idx];
|
||||
|
|
|
@ -204,7 +204,7 @@ struct RenderModuleImpl final : RenderModule {
|
|||
|
||||
for (ModelInstance& i : m_model_instances)
|
||||
{
|
||||
if (i.flags.isSet(ModelInstance::VALID) && i.model) {
|
||||
if ((i.flags & ModelInstance::VALID) && i.model) {
|
||||
i.model->decRefCount();
|
||||
if (i.custom_material) i.custom_material->decRefCount();
|
||||
i.custom_material = nullptr;
|
||||
|
@ -511,7 +511,7 @@ struct RenderModuleImpl final : RenderModule {
|
|||
if (parent.isValid() && parent.index < m_model_instances.size())
|
||||
{
|
||||
ModelInstance& mi = m_model_instances[parent.index];
|
||||
mi.flags.set(ModelInstance::IS_BONE_ATTACHMENT_PARENT);
|
||||
mi.flags |= ModelInstance::IS_BONE_ATTACHMENT_PARENT;
|
||||
}
|
||||
updateRelativeMatrix(ba);
|
||||
}
|
||||
|
@ -611,7 +611,7 @@ struct RenderModuleImpl final : RenderModule {
|
|||
serializer.write((i32)m_model_instances.size());
|
||||
for (const ModelInstance& r : m_model_instances) {
|
||||
serializer.write(r.flags);
|
||||
if(r.flags.isSet(ModelInstance::VALID)) {
|
||||
if(r.flags & ModelInstance::VALID) {
|
||||
serializer.write(u32(r.model ? offsets[r.model] : 0xffFFffFF));
|
||||
serializer.writeString(r.custom_material ? r.custom_material->getPath().c_str() : "");
|
||||
}
|
||||
|
@ -952,16 +952,15 @@ struct RenderModuleImpl final : RenderModule {
|
|||
serializer.read(size);
|
||||
m_model_instances.reserve(nextPow2(size + m_model_instances.size()));
|
||||
for (u32 i = 0; i < size; ++i) {
|
||||
FlagSet<ModelInstance::Flags, u8> flags;
|
||||
ModelInstance::Flags flags;
|
||||
serializer.read(flags);
|
||||
|
||||
if(flags.isSet(ModelInstance::VALID)) {
|
||||
if(flags & ModelInstance::VALID) {
|
||||
const EntityRef e = entity_map.get(EntityRef{(i32)i});
|
||||
|
||||
while (e.index >= m_model_instances.size()) {
|
||||
auto& r = m_model_instances.emplace();
|
||||
r.flags.clear();
|
||||
r.flags.set(ModelInstance::VALID, false);
|
||||
r.flags = ModelInstance::NONE;
|
||||
r.model = nullptr;
|
||||
r.pose = nullptr;
|
||||
}
|
||||
|
@ -998,16 +997,15 @@ struct RenderModuleImpl final : RenderModule {
|
|||
serializer.read(size);
|
||||
m_model_instances.reserve(nextPow2(size + m_model_instances.size()));
|
||||
for (u32 i = 0; i < size; ++i) {
|
||||
FlagSet<ModelInstance::Flags, u8> flags;
|
||||
ModelInstance::Flags flags;
|
||||
serializer.read(flags);
|
||||
|
||||
if(flags.isSet(ModelInstance::VALID)) {
|
||||
if(flags & ModelInstance::VALID) {
|
||||
const EntityRef e = entity_map.get(EntityRef{(i32)i});
|
||||
|
||||
while (e.index >= m_model_instances.size()) {
|
||||
ModelInstance& r = m_model_instances.emplace();
|
||||
r.flags.clear();
|
||||
r.flags.set(ModelInstance::VALID, false);
|
||||
r.flags = ModelInstance::NONE;
|
||||
r.model = nullptr;
|
||||
r.pose = nullptr;
|
||||
}
|
||||
|
@ -1158,7 +1156,7 @@ struct RenderModuleImpl final : RenderModule {
|
|||
if (parent_entity.isValid() && parent_entity.index < m_model_instances.size())
|
||||
{
|
||||
ModelInstance& mi = m_model_instances[bone_attachment.parent_entity.index];
|
||||
mi.flags.unset(ModelInstance::IS_BONE_ATTACHMENT_PARENT);
|
||||
mi.flags &= ~ModelInstance::IS_BONE_ATTACHMENT_PARENT;
|
||||
}
|
||||
m_bone_attachments.erase(entity);
|
||||
m_world.onComponentDestroyed(entity, BONE_ATTACHMENT_TYPE, this);
|
||||
|
@ -1282,8 +1280,7 @@ struct RenderModuleImpl final : RenderModule {
|
|||
auto& model_instance = m_model_instances[entity.index];
|
||||
LUMIX_DELETE(m_allocator, model_instance.pose);
|
||||
model_instance.pose = nullptr;
|
||||
model_instance.flags.clear();
|
||||
model_instance.flags.set(ModelInstance::VALID, false);
|
||||
model_instance.flags = ModelInstance::NONE;
|
||||
if (model_instance.custom_material) model_instance.custom_material->decRefCount();
|
||||
model_instance.custom_material = nullptr;
|
||||
m_world.onComponentDestroyed(entity, MODEL_INSTANCE_TYPE, this);
|
||||
|
@ -1390,11 +1387,11 @@ struct RenderModuleImpl final : RenderModule {
|
|||
}
|
||||
|
||||
bool getEnvironmentCastShadows(EntityRef entity) override {
|
||||
return m_environments[entity].flags.isSet(Environment::CAST_SHADOWS);
|
||||
return m_environments[entity].flags & Environment::CAST_SHADOWS;
|
||||
}
|
||||
|
||||
void setEnvironmentCastShadows(EntityRef entity, bool enable) override {
|
||||
m_environments[entity].flags.set(Environment::CAST_SHADOWS, enable);
|
||||
setFlag(m_environments[entity].flags, Environment::CAST_SHADOWS, enable);
|
||||
}
|
||||
|
||||
Environment& getEnvironment(EntityRef entity) override
|
||||
|
@ -1876,11 +1873,10 @@ struct RenderModuleImpl final : RenderModule {
|
|||
}
|
||||
|
||||
Pose* lockPose(EntityRef entity) override { return m_model_instances[entity.index].pose; }
|
||||
void unlockPose(EntityRef entity, bool changed) override
|
||||
{
|
||||
void unlockPose(EntityRef entity, bool changed) override {
|
||||
if (!changed) return;
|
||||
if (entity.index < m_model_instances.size()
|
||||
&& (m_model_instances[entity.index].flags.isSet(ModelInstance::IS_BONE_ATTACHMENT_PARENT)) == 0)
|
||||
&& (m_model_instances[entity.index].flags & ModelInstance::IS_BONE_ATTACHMENT_PARENT) == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -1902,14 +1898,14 @@ struct RenderModuleImpl final : RenderModule {
|
|||
bool isModelInstanceEnabled(EntityRef entity) override
|
||||
{
|
||||
ModelInstance& model_instance = m_model_instances[entity.index];
|
||||
return model_instance.flags.isSet(ModelInstance::ENABLED);
|
||||
return model_instance.flags & ModelInstance::ENABLED;
|
||||
}
|
||||
|
||||
|
||||
void enableModelInstance(EntityRef entity, bool enable) override
|
||||
{
|
||||
ModelInstance& model_instance = m_model_instances[entity.index];
|
||||
model_instance.flags.set(ModelInstance::ENABLED, enable);
|
||||
model_instance.flags |= ModelInstance::ENABLED;
|
||||
if (enable)
|
||||
{
|
||||
if (!model_instance.model || !model_instance.model->isReady()) return;
|
||||
|
@ -2123,7 +2119,7 @@ struct RenderModuleImpl final : RenderModule {
|
|||
{
|
||||
for(int i = entity.index + 1; i < m_model_instances.size(); ++i)
|
||||
{
|
||||
if (m_model_instances[i].flags.isSet(ModelInstance::VALID)) return EntityPtr{i};
|
||||
if (m_model_instances[i].flags & ModelInstance::VALID) return EntityPtr{i};
|
||||
}
|
||||
return INVALID_ENTITY;
|
||||
}
|
||||
|
@ -2641,8 +2637,7 @@ struct RenderModuleImpl final : RenderModule {
|
|||
const World& world = getWorld();
|
||||
for (int i = 0; i < m_model_instances.size(); ++i) {
|
||||
auto& r = m_model_instances[i];
|
||||
if (!r.flags.isSet(ModelInstance::ENABLED)) continue;
|
||||
if (!r.flags.isSet(ModelInstance::VALID)) continue;
|
||||
if ((r.flags & (ModelInstance::ENABLED | ModelInstance::VALID)) == 0) continue;
|
||||
if (!r.model) continue;
|
||||
|
||||
const EntityRef entity{i};
|
||||
|
@ -2725,19 +2720,19 @@ struct RenderModuleImpl final : RenderModule {
|
|||
}
|
||||
|
||||
bool getPointLightCastShadows(EntityRef entity) override {
|
||||
return m_point_lights[entity].flags.isSet(PointLight::CAST_SHADOWS);
|
||||
return m_point_lights[entity].flags & PointLight::CAST_SHADOWS;
|
||||
}
|
||||
|
||||
void setPointLightCastShadows(EntityRef entity, bool value) override {
|
||||
m_point_lights[entity].flags.set(PointLight::CAST_SHADOWS, value);
|
||||
setFlag(m_point_lights[entity].flags, PointLight::CAST_SHADOWS, value);
|
||||
}
|
||||
|
||||
bool getPointLightDynamic(EntityRef entity) override {
|
||||
return m_point_lights[entity].flags.isSet(PointLight::DYNAMIC);
|
||||
return m_point_lights[entity].flags & PointLight::DYNAMIC;
|
||||
}
|
||||
|
||||
void setPointLightDynamic(EntityRef entity, bool value) override {
|
||||
m_point_lights[entity].flags.set(PointLight::DYNAMIC, value);
|
||||
setFlag(m_point_lights[entity].flags, PointLight::DYNAMIC, value);
|
||||
}
|
||||
|
||||
void setLightRange(EntityRef entity, float value) override
|
||||
|
@ -2763,11 +2758,11 @@ struct RenderModuleImpl final : RenderModule {
|
|||
}
|
||||
|
||||
void enableReflectionProbe(EntityRef entity, bool enable) override {
|
||||
m_reflection_probes[entity].flags.set(ReflectionProbe::ENABLED, enable);
|
||||
setFlag(m_reflection_probes[entity].flags, ReflectionProbe::ENABLED, enable);
|
||||
}
|
||||
|
||||
bool isReflectionProbeEnabled(EntityRef entity) override {
|
||||
return m_reflection_probes[entity].flags.isSet(ReflectionProbe::ENABLED);
|
||||
return m_reflection_probes[entity].flags & ReflectionProbe::ENABLED;
|
||||
}
|
||||
|
||||
Span<const ReflectionProbe> getReflectionProbes() override {
|
||||
|
@ -2807,13 +2802,13 @@ struct RenderModuleImpl final : RenderModule {
|
|||
|
||||
void enableEnvironmentProbe(EntityRef entity, bool enable) override
|
||||
{
|
||||
m_environment_probes[entity].flags.set(EnvironmentProbe::ENABLED, enable);
|
||||
setFlag(m_environment_probes[entity].flags, EnvironmentProbe::ENABLED, enable);
|
||||
}
|
||||
|
||||
|
||||
bool isEnvironmentProbeEnabled(EntityRef entity) override
|
||||
{
|
||||
return m_environment_probes[entity].flags.isSet(EnvironmentProbe::ENABLED);
|
||||
return m_environment_probes[entity].flags & EnvironmentProbe::ENABLED;
|
||||
}
|
||||
|
||||
|
||||
|
@ -2838,7 +2833,7 @@ struct RenderModuleImpl final : RenderModule {
|
|||
const Vec3& scale = m_world.getScale(entity);
|
||||
const DVec3 pos = m_world.getPosition(entity);
|
||||
const float radius = bounding_radius * maximum(scale.x, scale.y, scale.z);
|
||||
if(r.flags.isSet(ModelInstance::ENABLED)) {
|
||||
if(r.flags & ModelInstance::ENABLED) {
|
||||
const RenderableTypes type = getRenderableType(*model, r.custom_material);
|
||||
m_culling_system->add(entity, (u8)type, pos, radius);
|
||||
}
|
||||
|
@ -2851,7 +2846,7 @@ struct RenderModuleImpl final : RenderModule {
|
|||
r.mesh_count = r.model->getMeshCount();
|
||||
r.meshes = r.mesh_count > 0 ? &r.model->getMesh(0) : nullptr;
|
||||
|
||||
if (r.flags.isSet(ModelInstance::IS_BONE_ATTACHMENT_PARENT)) {
|
||||
if (r.flags & ModelInstance::IS_BONE_ATTACHMENT_PARENT) {
|
||||
for (auto& attachment : m_bone_attachments) {
|
||||
if (attachment.parent_entity == entity) {
|
||||
updateBoneAttachment(attachment);
|
||||
|
@ -2872,7 +2867,7 @@ struct RenderModuleImpl final : RenderModule {
|
|||
{
|
||||
for (int i = 0, c = m_model_instances.size(); i < c; ++i)
|
||||
{
|
||||
if (m_model_instances[i].flags.isSet(ModelInstance::VALID) && m_model_instances[i].model == model)
|
||||
if ((m_model_instances[i].flags & ModelInstance::VALID) && m_model_instances[i].model == model)
|
||||
{
|
||||
modelUnloaded(model, {i});
|
||||
}
|
||||
|
@ -3009,7 +3004,7 @@ struct RenderModuleImpl final : RenderModule {
|
|||
void setModel(EntityRef entity, Model* model)
|
||||
{
|
||||
auto& model_instance = m_model_instances[entity.index];
|
||||
ASSERT(model_instance.flags.isSet(ModelInstance::VALID));
|
||||
ASSERT(model_instance.flags & ModelInstance::VALID);
|
||||
Model* old_model = model_instance.model;
|
||||
bool no_change = model == old_model && old_model;
|
||||
if (no_change)
|
||||
|
@ -3048,7 +3043,7 @@ struct RenderModuleImpl final : RenderModule {
|
|||
void createEnvironment(EntityRef entity)
|
||||
{
|
||||
Environment light;
|
||||
light.flags.set(Environment::CAST_SHADOWS);
|
||||
light.flags = Environment::CAST_SHADOWS;
|
||||
light.entity = entity;
|
||||
light.light_color = Vec3(1, 1, 1);
|
||||
light.direct_intensity = 1;
|
||||
|
@ -3069,7 +3064,7 @@ struct RenderModuleImpl final : RenderModule {
|
|||
light.color = Vec3(1, 1, 1);
|
||||
light.intensity = 1;
|
||||
light.fov = degreesToRadians(360);
|
||||
light.flags.clear();
|
||||
light.flags = PointLight::Flags::NONE;
|
||||
light.attenuation_param = 2;
|
||||
light.range = 10;
|
||||
light.guid = randGUID();
|
||||
|
@ -3129,7 +3124,7 @@ struct RenderModuleImpl final : RenderModule {
|
|||
|
||||
probe.outer_range = Vec3(9001.f);
|
||||
probe.inner_range = Vec3(4500.f);
|
||||
probe.flags.set(EnvironmentProbe::ENABLED);
|
||||
probe.flags |= EnvironmentProbe::ENABLED;
|
||||
memset(probe.sh_coefs, 0, sizeof(probe.sh_coefs));
|
||||
probe.sh_coefs[0] = Vec3(0.5f, 0.5f, 0.5f);
|
||||
|
||||
|
@ -3155,7 +3150,7 @@ struct RenderModuleImpl final : RenderModule {
|
|||
{
|
||||
ReflectionProbe& probe = m_reflection_probes.insert(entity);
|
||||
probe.guid = randGUID();
|
||||
probe.flags.set(ReflectionProbe::ENABLED);
|
||||
probe.flags |= ReflectionProbe::ENABLED;
|
||||
|
||||
m_world.onComponentCreated(entity, REFLECTION_PROBE_TYPE, this);
|
||||
}
|
||||
|
@ -3187,8 +3182,7 @@ struct RenderModuleImpl final : RenderModule {
|
|||
while(entity.index >= m_model_instances.size())
|
||||
{
|
||||
auto& r = m_model_instances.emplace();
|
||||
r.flags.clear();
|
||||
r.flags.set(ModelInstance::VALID, false);
|
||||
r.flags = ModelInstance::NONE;
|
||||
r.model = nullptr;
|
||||
r.pose = nullptr;
|
||||
}
|
||||
|
@ -3196,9 +3190,7 @@ struct RenderModuleImpl final : RenderModule {
|
|||
r.model = nullptr;
|
||||
r.meshes = nullptr;
|
||||
r.pose = nullptr;
|
||||
r.flags.clear();
|
||||
r.flags.set(ModelInstance::VALID);
|
||||
r.flags.set(ModelInstance::ENABLED);
|
||||
r.flags = ModelInstance::VALID | ModelInstance::ENABLED;
|
||||
r.mesh_count = 0;
|
||||
m_world.onComponentCreated(entity, MODEL_INSTANCE_TYPE, this);
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include "engine/array.h"
|
||||
#include "engine/lumix.h"
|
||||
#include "engine/flag_set.h"
|
||||
#include "engine/geometry.h"
|
||||
#include "engine/hash_map.h"
|
||||
#include "engine/math.h"
|
||||
|
@ -96,9 +95,9 @@ struct CurveDecal {
|
|||
Vec2 bezier_p2;
|
||||
};
|
||||
|
||||
struct Environment
|
||||
{
|
||||
struct Environment {
|
||||
enum Flags : u32 {
|
||||
NONE = 0,
|
||||
CAST_SHADOWS = 1 << 0
|
||||
};
|
||||
|
||||
|
@ -107,13 +106,12 @@ struct Environment
|
|||
float indirect_intensity;
|
||||
EntityRef entity;
|
||||
Vec4 cascades;
|
||||
FlagSet<Flags, u32> flags;
|
||||
Flags flags = Flags::NONE;
|
||||
};
|
||||
|
||||
|
||||
struct PointLight
|
||||
{
|
||||
struct PointLight {
|
||||
enum Flags : u32 {
|
||||
NONE = 0,
|
||||
CAST_SHADOWS = 1 << 0,
|
||||
DYNAMIC = 1 << 1
|
||||
};
|
||||
|
@ -124,18 +122,18 @@ struct PointLight
|
|||
float fov;
|
||||
float attenuation_param;
|
||||
float range;
|
||||
FlagSet<Flags, u32> flags;
|
||||
Flags flags = Flags::NONE;
|
||||
u64 guid;
|
||||
};
|
||||
|
||||
struct ReflectionProbe
|
||||
{
|
||||
struct ReflectionProbe {
|
||||
enum Flags {
|
||||
NONE = 0,
|
||||
ENABLED = 1 << 2,
|
||||
};
|
||||
|
||||
u64 guid;
|
||||
FlagSet<Flags, u32> flags;
|
||||
Flags flags = Flags::NONE;
|
||||
u32 size = 128;
|
||||
Vec3 half_extents = Vec3(100, 100, 100);
|
||||
u32 texture_id = 0xffFFffFF;
|
||||
|
@ -144,23 +142,22 @@ struct ReflectionProbe
|
|||
LoadJob* load_job = nullptr;
|
||||
};
|
||||
|
||||
struct EnvironmentProbe
|
||||
{
|
||||
struct EnvironmentProbe {
|
||||
enum Flags {
|
||||
NONE = 0,
|
||||
ENABLED = 1 << 2,
|
||||
};
|
||||
|
||||
Vec3 inner_range;
|
||||
Vec3 outer_range;
|
||||
FlagSet<Flags, u32> flags;
|
||||
Flags flags = Flags::NONE;
|
||||
Vec3 sh_coefs[9];
|
||||
};
|
||||
|
||||
|
||||
struct ModelInstance
|
||||
{
|
||||
enum Flags : u8
|
||||
{
|
||||
enum Flags : u8 {
|
||||
NONE = 0,
|
||||
IS_BONE_ATTACHMENT_PARENT = 1 << 0,
|
||||
ENABLED = 1 << 1,
|
||||
VALID = 1 << 2,
|
||||
|
@ -173,7 +170,7 @@ struct ModelInstance
|
|||
EntityPtr next_model = INVALID_ENTITY;
|
||||
EntityPtr prev_model = INVALID_ENTITY;
|
||||
float lod = 4;
|
||||
FlagSet<Flags, u8> flags;
|
||||
Flags flags = Flags::NONE;
|
||||
u16 mesh_count;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue