This commit is contained in:
Mikulas Florek 2018-01-12 17:01:26 +01:00
parent 917af860a8
commit 119b2aa5e4
58 changed files with 2313 additions and 2913 deletions

View file

@ -35,6 +35,7 @@ enum class AnimationSceneVersion
};
static const ComponentType MODEL_INSTANCE_TYPE = Reflection::getComponentType("renderable");
static const ComponentType ANIMABLE_TYPE = Reflection::getComponentType("animable");
static const ComponentType PROPERTY_ANIMATOR_TYPE = Reflection::getComponentType("property_animator");
static const ComponentType CONTROLLER_TYPE = Reflection::getComponentType("anim_controller");
@ -162,9 +163,9 @@ struct AnimationSceneImpl LUMIX_FINAL : public AnimationScene
}
void serializeSharedController(ISerializer& serializer, ComponentHandle cmp)
void serializeSharedController(ISerializer& serializer, Entity entity)
{
SharedController& ctrl = m_shared_controllers[{cmp.index}];
SharedController& ctrl = m_shared_controllers[entity];
serializer.write("parent", ctrl.parent);
}
@ -174,13 +175,13 @@ struct AnimationSceneImpl LUMIX_FINAL : public AnimationScene
Entity parent;
serializer.read(&parent);
m_shared_controllers.insert(entity, {entity, parent});
m_universe.onComponentCreated(entity, SHARED_CONTROLLER_TYPE, this, {entity.index});
m_universe.onComponentCreated(entity, SHARED_CONTROLLER_TYPE, this);
}
void serializePropertyAnimator(ISerializer& serializer, ComponentHandle cmp)
void serializePropertyAnimator(ISerializer& serializer, Entity entity)
{
int idx = m_property_animators.find({ cmp.index });
int idx = m_property_animators.find(entity);
PropertyAnimator& animator = m_property_animators.at(idx);
serializer.write("animation", animator.animation ? animator.animation->getPath().c_str() : "");
serializer.write("flags", animator.flags.base);
@ -195,13 +196,13 @@ struct AnimationSceneImpl LUMIX_FINAL : public AnimationScene
serializer.read(tmp, lengthOf(tmp));
animator.animation = loadPropertyAnimation(Path(tmp));
serializer.read(&animator.flags.base);
m_universe.onComponentCreated(entity, PROPERTY_ANIMATOR_TYPE, this, {entity.index});
m_universe.onComponentCreated(entity, PROPERTY_ANIMATOR_TYPE, this);
}
void serializeAnimable(ISerializer& serializer, ComponentHandle cmp)
void serializeAnimable(ISerializer& serializer, Entity entity)
{
Animable& animable = m_animables[{cmp.index}];
Animable& animable = m_animables[entity];
serializer.write("time_scale", animable.time_scale);
serializer.write("start_time", animable.start_time);
serializer.write("animation", animable.animation ? animable.animation->getPath().c_str() : "");
@ -218,13 +219,13 @@ struct AnimationSceneImpl LUMIX_FINAL : public AnimationScene
serializer.read(tmp, lengthOf(tmp));
auto* res = tmp[0] ? m_engine.getResourceManager().get(Animation::TYPE)->load(Path(tmp)) : nullptr;
animable.animation = (Animation*)res;
m_universe.onComponentCreated(entity, ANIMABLE_TYPE, this, {entity.index});
m_universe.onComponentCreated(entity, ANIMABLE_TYPE, this);
}
void serializeController(ISerializer& serializer, ComponentHandle cmp)
void serializeController(ISerializer& serializer, Entity entity)
{
Controller& controller = m_controllers.get({cmp.index});
Controller& controller = m_controllers.get(entity);
serializer.write("source", controller.resource ? controller.resource->getPath().c_str() : "");
serializer.write("default_set", controller.default_set);
}
@ -245,7 +246,7 @@ struct AnimationSceneImpl LUMIX_FINAL : public AnimationScene
}
auto* res = tmp[0] ? m_engine.getResourceManager().get(Anim::ControllerResource::TYPE)->load(Path(tmp)) : nullptr;
setControllerResource(controller, (Anim::ControllerResource*)res);
m_universe.onComponentCreated(entity, CONTROLLER_TYPE, this, {entity.index});
m_universe.onComponentCreated(entity, CONTROLLER_TYPE, this);
}
@ -281,8 +282,8 @@ struct AnimationSceneImpl LUMIX_FINAL : public AnimationScene
static int setIK(lua_State* L)
{
AnimationSceneImpl* scene = LuaWrapper::checkArg<AnimationSceneImpl*>(L, 1);
ComponentHandle cmp = LuaWrapper::checkArg<ComponentHandle>(L, 2);
Controller& controller = scene->m_controllers.get({ cmp.index });
Entity entity = LuaWrapper::checkArg<Entity>(L, 2);
Controller& controller = scene->m_controllers.get(entity);
int index = LuaWrapper::checkArg<int>(L, 3);
Controller::IK& ik = controller.inverse_kinematics[index];
ik.weight = LuaWrapper::checkArg<float>(L, 4);
@ -304,9 +305,9 @@ struct AnimationSceneImpl LUMIX_FINAL : public AnimationScene
}
int getControllerInputIndex(ComponentHandle cmp, const char* name) const override
int getControllerInputIndex(Entity entity, const char* name) const override
{
const Controller& controller = m_controllers[{cmp.index}];
const Controller& controller = m_controllers[entity];
Anim::InputDecl& decl = controller.resource->m_input_decl;
for (int i = 0; i < lengthOf(decl.inputs); ++i)
{
@ -316,9 +317,9 @@ struct AnimationSceneImpl LUMIX_FINAL : public AnimationScene
}
void setControllerFloatInput(ComponentHandle cmp, int input_idx, float value)
void setControllerFloatInput(Entity entity, int input_idx, float value)
{
Controller& controller = m_controllers.get({ cmp.index });
Controller& controller = m_controllers.get(entity);
if (!controller.root)
{
g_log_warning.log("Animation") << "Trying to set input " << input_idx << " before the controller is ready";
@ -337,9 +338,9 @@ struct AnimationSceneImpl LUMIX_FINAL : public AnimationScene
}
void setControllerIntInput(ComponentHandle cmp, int input_idx, int value)
void setControllerIntInput(Entity entity, int input_idx, int value)
{
Controller& controller = m_controllers.get({ cmp.index });
Controller& controller = m_controllers.get(entity);
if (!controller.root)
{
g_log_warning.log("Animation") << "Trying to set input " << input_idx << " before the controller is ready";
@ -357,9 +358,9 @@ struct AnimationSceneImpl LUMIX_FINAL : public AnimationScene
}
void setControllerBoolInput(ComponentHandle cmp, int input_idx, bool value)
void setControllerBoolInput(Entity entity, int input_idx, bool value)
{
Controller& controller = m_controllers.get({ cmp.index });
Controller& controller = m_controllers.get(entity);
if (!controller.root)
{
g_log_warning.log("Animation") << "Trying to set input " << input_idx << " before the controller is ready";
@ -385,21 +386,21 @@ struct AnimationSceneImpl LUMIX_FINAL : public AnimationScene
}
float getAnimableTime(ComponentHandle cmp) override
float getAnimableTime(Entity entity) override
{
return m_animables[{cmp.index}].time;
return m_animables[entity].time;
}
void setAnimableTime(ComponentHandle cmp, float time) override
void setAnimableTime(Entity entity, float time) override
{
m_animables[{cmp.index}].time = time;
m_animables[entity].time = time;
}
Animation* getAnimableAnimation(ComponentHandle cmp) override
Animation* getAnimableAnimation(Entity entity) override
{
return m_animables[{cmp.index}].animation;
return m_animables[entity].animation;
}
@ -427,32 +428,6 @@ struct AnimationSceneImpl LUMIX_FINAL : public AnimationScene
Universe& getUniverse() override { return m_universe; }
ComponentHandle getComponent(Entity entity, ComponentType type) override
{
if (type == ANIMABLE_TYPE)
{
if (m_animables.find(entity) < 0) return INVALID_COMPONENT;
return {entity.index};
}
else if (type == PROPERTY_ANIMATOR_TYPE)
{
if (m_property_animators.find(entity) < 0) return INVALID_COMPONENT;
return {entity.index};
}
else if (type == CONTROLLER_TYPE)
{
if (m_controllers.find(entity) < 0) return INVALID_COMPONENT;
return {entity.index};
}
else if (type == SHARED_CONTROLLER_TYPE)
{
if (m_shared_controllers.find(entity) < 0) return INVALID_COMPONENT;
return {entity.index};
}
return INVALID_COMPONENT;
}
static void unloadResource(Resource* res)
{
if (!res) return;
@ -500,42 +475,39 @@ struct AnimationSceneImpl LUMIX_FINAL : public AnimationScene
}
void destroyPropertyAnimator(ComponentHandle component)
void destroyPropertyAnimator(Entity entity)
{
Entity entity = { component.index };
int idx = m_property_animators.find(entity);
auto& animator = m_property_animators.at(idx);
unloadResource(animator.animation);
m_property_animators.erase(entity);
m_universe.onComponentDestroyed(entity, PROPERTY_ANIMATOR_TYPE, this, component);
m_universe.onComponentDestroyed(entity, PROPERTY_ANIMATOR_TYPE, this);
}
void destroyAnimable(ComponentHandle component)
void destroyAnimable(Entity entity)
{
Entity entity = { component.index };
auto& animable = m_animables[entity];
unloadResource(animable.animation);
m_animables.erase(entity);
m_universe.onComponentDestroyed(entity, ANIMABLE_TYPE, this, component);
m_universe.onComponentDestroyed(entity, ANIMABLE_TYPE, this);
}
void destroyController(ComponentHandle component)
void destroyController(Entity entity)
{
Entity entity = { component.index };
auto& controller = m_controllers.get(entity);
unloadResource(controller.resource);
setControllerResource(controller, nullptr);
m_controllers.erase(entity);
m_universe.onComponentDestroyed(entity, CONTROLLER_TYPE, this, component);
m_universe.onComponentDestroyed(entity, CONTROLLER_TYPE, this);
}
void destroySharedController(ComponentHandle component)
void destroySharedController(Entity entity)
{
Entity entity = {component.index};
m_shared_controllers.erase(entity);
m_universe.onComponentDestroyed(entity, SHARED_CONTROLLER_TYPE, this, component);
m_universe.onComponentDestroyed(entity, SHARED_CONTROLLER_TYPE, this);
}
@ -594,8 +566,7 @@ struct AnimationSceneImpl LUMIX_FINAL : public AnimationScene
serializer.readString(path, sizeof(path));
animable.animation = path[0] == '\0' ? nullptr : loadAnimation(Path(path));
m_animables.insert(animable.entity, animable);
ComponentHandle cmp = {animable.entity.index};
m_universe.onComponentCreated(animable.entity, ANIMABLE_TYPE, this, cmp);
m_universe.onComponentCreated(animable.entity, ANIMABLE_TYPE, this);
}
serializer.read(count);
@ -611,8 +582,7 @@ struct AnimationSceneImpl LUMIX_FINAL : public AnimationScene
serializer.read(animator.flags.base);
animator.time = 0;
animator.animation = loadPropertyAnimation(Path(path));
ComponentHandle cmp = { entity.index };
m_universe.onComponentCreated(entity, PROPERTY_ANIMATOR_TYPE, this, cmp);
m_universe.onComponentCreated(entity, PROPERTY_ANIMATOR_TYPE, this);
}
@ -627,8 +597,7 @@ struct AnimationSceneImpl LUMIX_FINAL : public AnimationScene
serializer.readString(tmp, lengthOf(tmp));
setControllerResource(controller, tmp[0] ? loadController(Path(tmp)) : nullptr);
m_controllers.insert(controller.entity, controller);
ComponentHandle cmp = { controller.entity.index };
m_universe.onComponentCreated(controller.entity, CONTROLLER_TYPE, this, cmp);
m_universe.onComponentCreated(controller.entity, CONTROLLER_TYPE, this);
}
serializer.read(count);
@ -639,30 +608,29 @@ struct AnimationSceneImpl LUMIX_FINAL : public AnimationScene
serializer.read(controller.entity);
serializer.read(controller.parent);
m_shared_controllers.insert(controller.entity, controller);
ComponentHandle cmp = {controller.entity.index};
m_universe.onComponentCreated(controller.entity, SHARED_CONTROLLER_TYPE, this, cmp);
m_universe.onComponentCreated(controller.entity, SHARED_CONTROLLER_TYPE, this);
}
}
void setSharedControllerParent(ComponentHandle cmp, Entity parent) override
void setSharedControllerParent(Entity entity, Entity parent) override
{
m_shared_controllers[{cmp.index}].parent = parent;
m_shared_controllers[entity].parent = parent;
}
Entity getSharedControllerParent(ComponentHandle cmp) override { return m_shared_controllers[{cmp.index}].parent; }
Entity getSharedControllerParent(Entity entity) override { return m_shared_controllers[entity].parent; }
float getAnimableTimeScale(ComponentHandle cmp) override { return m_animables[{cmp.index}].time_scale; }
void setAnimableTimeScale(ComponentHandle cmp, float time_scale) override { m_animables[{cmp.index}].time_scale = time_scale; }
float getAnimableStartTime(ComponentHandle cmp) override { return m_animables[{cmp.index}].start_time; }
void setAnimableStartTime(ComponentHandle cmp, float time) override { m_animables[{cmp.index}].start_time = time; }
float getAnimableTimeScale(Entity entity) override { return m_animables[entity].time_scale; }
void setAnimableTimeScale(Entity entity, float time_scale) override { m_animables[entity].time_scale = time_scale; }
float getAnimableStartTime(Entity entity) override { return m_animables[entity].start_time; }
void setAnimableStartTime(Entity entity, float time) override { m_animables[entity].start_time = time; }
void setControllerSource(ComponentHandle cmp, const Path& path) override
void setControllerSource(Entity entity, const Path& path) override
{
auto& controller = m_controllers.get({cmp.index});
auto& controller = m_controllers.get(entity);
unloadResource(controller.resource);
setControllerResource(controller, loadController(path));
if (controller.resource->isReady() && m_is_game_running)
@ -672,46 +640,40 @@ struct AnimationSceneImpl LUMIX_FINAL : public AnimationScene
}
Path getControllerSource(ComponentHandle cmp) override
Path getControllerSource(Entity entity) override
{
const auto& controller = m_controllers.get({cmp.index});
const auto& controller = m_controllers.get(entity);
return controller.resource ? controller.resource->getPath() : Path("");
}
PropertyAnimator& getPropertyAnimator(ComponentHandle cmp)
{
int idx = m_property_animators.find({ cmp.index });
return m_property_animators.at(idx);
}
Path getPropertyAnimation(ComponentHandle cmp) override
Path getPropertyAnimation(Entity entity) override
{
const auto& animator = getPropertyAnimator(cmp);
const auto& animator = m_property_animators.get(entity);
return animator.animation ? animator.animation->getPath() : Path("");
}
void setPropertyAnimation(ComponentHandle cmp, const Path& path) override
void setPropertyAnimation(Entity entity, const Path& path) override
{
auto& animator = getPropertyAnimator(cmp);
auto& animator = m_property_animators.get(entity);
animator.time = 0;
unloadResource(animator.animation);
animator.animation = loadPropertyAnimation(path);
}
Path getAnimation(ComponentHandle cmp) override
Path getAnimation(Entity entity) override
{
const auto& animable = m_animables[{cmp.index}];
const auto& animable = m_animables[entity];
return animable.animation ? animable.animation->getPath() : Path("");
}
void setAnimation(ComponentHandle cmp, const Path& path) override
void setAnimation(Entity entity, const Path& path) override
{
auto& animable = m_animables[{cmp.index}];
auto& animable = m_animables[entity];
unloadResource(animable.animation);
animable.animation = loadAnimation(path);
animable.time = 0;
@ -721,13 +683,13 @@ struct AnimationSceneImpl LUMIX_FINAL : public AnimationScene
void updateAnimable(Animable& animable, float time_delta) const
{
if (!animable.animation || !animable.animation->isReady()) return;
ComponentHandle model_instance = m_render_scene->getModelInstanceComponent(animable.entity);
if (model_instance == INVALID_COMPONENT) return;
Entity entity = animable.entity;
if (!m_universe.hasComponent(entity, MODEL_INSTANCE_TYPE)) return;
Model* model = m_render_scene->getModelInstanceModel(model_instance);
Model* model = m_render_scene->getModelInstanceModel(entity);
if (!model->isReady()) return;
Pose* pose = m_render_scene->lockPose(model_instance);
Pose* pose = m_render_scene->lockPose(entity);
if (!pose) return;
model->getRelativePose(*pose);
@ -739,29 +701,29 @@ struct AnimationSceneImpl LUMIX_FINAL : public AnimationScene
while (t > l) t -= l;
animable.time = t;
m_render_scene->unlockPose(model_instance, true);
m_render_scene->unlockPose(entity, true);
}
void updateAnimable(ComponentHandle cmp, float time_delta) override
void updateAnimable(Entity entity, float time_delta) override
{
Animable& animable = m_animables[{cmp.index}];
Animable& animable = m_animables[entity];
updateAnimable(animable, time_delta);
}
void updateController(ComponentHandle cmp, float time_delta) override
void updateController(Entity entity, float time_delta) override
{
Controller& controller = m_controllers.get({cmp.index});
Controller& controller = m_controllers.get(entity);
updateController(controller, time_delta);
processEventStream();
m_event_stream.clear();
}
void setControllerInput(ComponentHandle cmp, int input_idx, float value) override
void setControllerInput(Entity entity, int input_idx, float value) override
{
Controller& ctrl = m_controllers.get({ cmp.index });
Controller& ctrl = m_controllers.get(entity);
Anim::InputDecl& decl = ctrl.resource->m_input_decl;
if (!ctrl.root) return;
if (input_idx >= lengthOf(decl.inputs)) return;
@ -770,9 +732,9 @@ struct AnimationSceneImpl LUMIX_FINAL : public AnimationScene
}
void setControllerInput(ComponentHandle cmp, int input_idx, bool value) override
void setControllerInput(Entity entity, int input_idx, bool value) override
{
Controller& ctrl = m_controllers.get({ cmp.index });
Controller& ctrl = m_controllers.get(entity);
Anim::InputDecl& decl = ctrl.resource->m_input_decl;
if (!ctrl.root) return;
if (input_idx >= lengthOf(decl.inputs)) return;
@ -781,9 +743,9 @@ struct AnimationSceneImpl LUMIX_FINAL : public AnimationScene
}
void setControllerInput(ComponentHandle cmp, int input_idx, int value) override
void setControllerInput(Entity entity, int input_idx, int value) override
{
Controller& ctrl = m_controllers.get({ cmp.index });
Controller& ctrl = m_controllers.get(entity);
Anim::InputDecl& decl = ctrl.resource->m_input_decl;
if (!ctrl.root) return;
if (input_idx >= lengthOf(decl.inputs)) return;
@ -792,32 +754,29 @@ struct AnimationSceneImpl LUMIX_FINAL : public AnimationScene
}
Anim::ComponentInstance* getControllerRoot(ComponentHandle cmp) override
Anim::ComponentInstance* getControllerRoot(Entity entity) override
{
return m_controllers.get({cmp.index}).root;
return m_controllers.get(entity).root;
}
RigidTransform getControllerRootMotion(ComponentHandle cmp) override
RigidTransform getControllerRootMotion(Entity entity) override
{
Controller& ctrl = m_controllers.get({cmp.index});
Controller& ctrl = m_controllers.get(entity);
return ctrl.root ? ctrl.root->getRootMotion() : RigidTransform({0, 0, 0}, {0, 0, 0, 1});
}
Entity getControllerEntity(ComponentHandle cmp) override { return {cmp.index}; }
u8* getControllerInput(ComponentHandle cmp) override
u8* getControllerInput(Entity entity) override
{
auto& input = m_controllers.get({cmp.index}).input;
auto& input = m_controllers.get(entity).input;
return input.empty() ? nullptr : &input[0];
}
void applyControllerSet(ComponentHandle cmp, const char* set_name) override
void applyControllerSet(Entity entity, const char* set_name) override
{
Controller& ctrl = m_controllers.get({cmp.index});
Controller& ctrl = m_controllers.get(entity);
u32 set_name_hash = crc32(set_name);
int set_idx = ctrl.resource->m_sets_names.find([set_name_hash](const StaticString<32>& val) {
return crc32(val) == set_name_hash;
@ -833,16 +792,16 @@ struct AnimationSceneImpl LUMIX_FINAL : public AnimationScene
}
void setControllerDefaultSet(ComponentHandle cmp, int set) override
void setControllerDefaultSet(Entity entity, int set) override
{
Controller& ctrl = m_controllers.get({cmp.index});
Controller& ctrl = m_controllers.get(entity);
ctrl.default_set = ctrl.resource ? crc32(ctrl.resource->m_sets_names[set]) : 0;
}
int getControllerDefaultSet(ComponentHandle cmp) override
int getControllerDefaultSet(Entity entity) override
{
Controller& ctrl = m_controllers.get({ cmp.index });
Controller& ctrl = m_controllers.get(entity);
auto is_default_set = [&ctrl](const StaticString<32>& val) {
return crc32(val) == ctrl.default_set;
};
@ -852,9 +811,9 @@ struct AnimationSceneImpl LUMIX_FINAL : public AnimationScene
}
Anim::ControllerResource* getControllerResource(ComponentHandle cmp) override
Anim::ControllerResource* getControllerResource(Entity entity) override
{
return m_controllers.get({cmp.index}).resource;
return m_controllers.get(entity).resource;
}
@ -902,13 +861,13 @@ struct AnimationSceneImpl LUMIX_FINAL : public AnimationScene
Controller& parent_controller = m_controllers.at(parent_controller_idx);
if (!parent_controller.root) return;
ComponentHandle model_instance = m_render_scene->getModelInstanceComponent(controller.entity);
if (model_instance == INVALID_COMPONENT) return;
Entity entity = controller.entity;
if (!m_universe.hasComponent(entity, MODEL_INSTANCE_TYPE)) return;
Pose* pose = m_render_scene->lockPose(model_instance);
Pose* pose = m_render_scene->lockPose(entity);
if (!pose) return;
Model* model = m_render_scene->getModelInstanceModel(model_instance);
Model* model = m_render_scene->getModelInstanceModel(entity);
model->getPose(*pose);
pose->computeRelative(*model);
@ -916,7 +875,7 @@ struct AnimationSceneImpl LUMIX_FINAL : public AnimationScene
parent_controller.root->fillPose(m_engine, *pose, *model, 1, nullptr);
pose->computeAbsolute(*model);
m_render_scene->unlockPose(model_instance, true);
m_render_scene->unlockPose(entity, true);
}
@ -941,13 +900,13 @@ struct AnimationSceneImpl LUMIX_FINAL : public AnimationScene
rc.controller = {controller.entity.index};
controller.root = controller.root->update(rc, true);
ComponentHandle model_instance = m_render_scene->getModelInstanceComponent(controller.entity);
if (model_instance == INVALID_COMPONENT) return;
Entity entity = controller.entity;
if (!m_universe.hasComponent(entity, MODEL_INSTANCE_TYPE)) return;
Pose* pose = m_render_scene->lockPose(model_instance);
Pose* pose = m_render_scene->lockPose(entity);
if (!pose) return;
Model* model = m_render_scene->getModelInstanceModel(model_instance);
Model* model = m_render_scene->getModelInstanceModel(entity);
model->getRelativePose(*pose);
@ -961,7 +920,7 @@ struct AnimationSceneImpl LUMIX_FINAL : public AnimationScene
updateIK(ik, *pose, *model);
}
m_render_scene->unlockPose(model_instance, true);
m_render_scene->unlockPose(entity, true);
}
@ -1056,7 +1015,6 @@ struct AnimationSceneImpl LUMIX_FINAL : public AnimationScene
ComponentUID cmp;
cmp.type = curve.cmp_type;
cmp.scene = m_universe.getScene(cmp.type);
cmp.handle = cmp.scene->getComponent(entity, cmp.type);
cmp.entity = entity;
InputBlob blob(&v, sizeof(v));
curve.property->setValue(cmp, -1, blob);
@ -1131,15 +1089,15 @@ struct AnimationSceneImpl LUMIX_FINAL : public AnimationScene
{
u32 type;
u8 size;
ComponentHandle cmp;
Entity entity;
blob.read(type);
blob.read(cmp);
blob.read(entity);
blob.read(size);
if (type == set_input_type)
{
Anim::SetInputEvent event;
blob.read(event);
Controller& ctrl = m_controllers.get({cmp.index});
Controller& ctrl = m_controllers.get(entity);
if (ctrl.resource->isReady())
{
Anim::InputDecl& decl = ctrl.resource->m_input_decl;
@ -1183,18 +1141,16 @@ struct AnimationSceneImpl LUMIX_FINAL : public AnimationScene
}
ComponentHandle createPropertyAnimator(Entity entity)
void createPropertyAnimator(Entity entity)
{
PropertyAnimator& animator = m_property_animators.emplace(entity, m_allocator);
animator.animation = nullptr;
animator.time = 0;
ComponentHandle cmp = { entity.index };
m_universe.onComponentCreated(entity, PROPERTY_ANIMATOR_TYPE, this, cmp);
return cmp;
m_universe.onComponentCreated(entity, PROPERTY_ANIMATOR_TYPE, this);
}
ComponentHandle createAnimable(Entity entity)
void createAnimable(Entity entity)
{
Animable& animable = m_animables.insert(entity);
animable.time = 0;
@ -1203,28 +1159,24 @@ struct AnimationSceneImpl LUMIX_FINAL : public AnimationScene
animable.time_scale = 1;
animable.start_time = 0;
ComponentHandle cmp = {entity.index};
m_universe.onComponentCreated(entity, ANIMABLE_TYPE, this, cmp);
return cmp;
m_universe.onComponentCreated(entity, ANIMABLE_TYPE, this);
}
ComponentHandle createController(Entity entity)
void createController(Entity entity)
{
Controller& controller = m_controllers.emplace(entity, m_allocator);
controller.entity = entity;
ComponentHandle cmp = {entity.index};
m_universe.onComponentCreated(entity, CONTROLLER_TYPE, this, cmp);
return cmp;
m_universe.onComponentCreated(entity, CONTROLLER_TYPE, this);
}
ComponentHandle createSharedController(Entity entity)
void createSharedController(Entity entity)
{
m_shared_controllers.insert(entity, {entity, INVALID_ENTITY});
ComponentHandle cmp = {entity.index};
m_universe.onComponentCreated(entity, SHARED_CONTROLLER_TYPE, this, cmp);
return cmp;
m_universe.onComponentCreated(entity, SHARED_CONTROLLER_TYPE, this);
}

View file

@ -29,35 +29,34 @@ struct AnimationScene : public IScene
static void registerLuaAPI(lua_State* L);
virtual const OutputBlob& getEventStream() const = 0;
virtual Path getPropertyAnimation(ComponentHandle cmp) = 0;
virtual void setPropertyAnimation(ComponentHandle cmp, const Path& path) = 0;
virtual class Animation* getAnimableAnimation(ComponentHandle cmp) = 0;
virtual Path getAnimation(ComponentHandle cmp) = 0;
virtual void setAnimation(ComponentHandle cmp, const Path& path) = 0;
virtual float getAnimableTime(ComponentHandle cmp) = 0;
virtual void setAnimableTime(ComponentHandle cmp, float time) = 0;
virtual void updateAnimable(ComponentHandle cmp, float time_delta) = 0;
virtual void updateController(ComponentHandle cmp, float time_delta) = 0;
virtual Entity getControllerEntity(ComponentHandle cmp) = 0;
virtual float getAnimableTimeScale(ComponentHandle cmp) = 0;
virtual void setAnimableTimeScale(ComponentHandle cmp, float time_scale) = 0;
virtual float getAnimableStartTime(ComponentHandle cmp) = 0;
virtual void setAnimableStartTime(ComponentHandle cmp, float time) = 0;
virtual u8* getControllerInput(ComponentHandle cmp) = 0;
virtual void setControllerInput(ComponentHandle cmp, int input_idx, int value) = 0;
virtual void setControllerInput(ComponentHandle cmp, int input_idx, float value) = 0;
virtual void setControllerInput(ComponentHandle cmp, int input_idx, bool value) = 0;
virtual struct RigidTransform getControllerRootMotion(ComponentHandle cmp) = 0;
virtual void setControllerSource(ComponentHandle cmp, const Path& path) = 0;
virtual class Path getControllerSource(ComponentHandle cmp) = 0;
virtual Anim::ComponentInstance* getControllerRoot(ComponentHandle cmp) = 0;
virtual int getControllerInputIndex(ComponentHandle cmp, const char* name) const = 0;
virtual Entity getSharedControllerParent(ComponentHandle cmp) = 0;
virtual void setSharedControllerParent(ComponentHandle cmp, Entity parent) = 0;
virtual void applyControllerSet(ComponentHandle cmp, const char* set_name) = 0;
virtual void setControllerDefaultSet(ComponentHandle cmp, int set) = 0;
virtual int getControllerDefaultSet(ComponentHandle cmp) = 0;
virtual Anim::ControllerResource* getControllerResource(ComponentHandle cmp) = 0;
virtual Path getPropertyAnimation(Entity entity) = 0;
virtual void setPropertyAnimation(Entity entity, const Path& path) = 0;
virtual class Animation* getAnimableAnimation(Entity entity) = 0;
virtual Path getAnimation(Entity entity) = 0;
virtual void setAnimation(Entity entity, const Path& path) = 0;
virtual float getAnimableTime(Entity entity) = 0;
virtual void setAnimableTime(Entity entity, float time) = 0;
virtual void updateAnimable(Entity entity, float time_delta) = 0;
virtual void updateController(Entity entity, float time_delta) = 0;
virtual float getAnimableTimeScale(Entity entity) = 0;
virtual void setAnimableTimeScale(Entity entity, float time_scale) = 0;
virtual float getAnimableStartTime(Entity entity) = 0;
virtual void setAnimableStartTime(Entity entity, float time) = 0;
virtual u8* getControllerInput(Entity entity) = 0;
virtual void setControllerInput(Entity entity, int input_idx, int value) = 0;
virtual void setControllerInput(Entity entity, int input_idx, float value) = 0;
virtual void setControllerInput(Entity entity, int input_idx, bool value) = 0;
virtual struct RigidTransform getControllerRootMotion(Entity entity) = 0;
virtual void setControllerSource(Entity entity, const Path& path) = 0;
virtual class Path getControllerSource(Entity entity) = 0;
virtual Anim::ComponentInstance* getControllerRoot(Entity entity) = 0;
virtual int getControllerInputIndex(Entity entity, const char* name) const = 0;
virtual Entity getSharedControllerParent(Entity entity) = 0;
virtual void setSharedControllerParent(Entity entity, Entity parent) = 0;
virtual void applyControllerSet(Entity entity, const char* set_name) = 0;
virtual void setControllerDefaultSet(Entity entity, int set) = 0;
virtual int getControllerDefaultSet(Entity entity) = 0;
virtual Anim::ControllerResource* getControllerResource(Entity entity) = 0;
virtual float getAnimationLength(int animation_idx) = 0;
};

View file

@ -33,7 +33,7 @@ struct AnimSetProperty : public Reflection::IEnumProperty
void getValue(ComponentUID cmp, int index, OutputBlob& stream) const override
{
AnimationScene* scene = static_cast<AnimationScene*>(cmp.scene);
int value = scene->getControllerDefaultSet(cmp.handle);
int value = scene->getControllerDefaultSet(cmp.entity);
stream.write(value);
}
@ -42,21 +42,21 @@ struct AnimSetProperty : public Reflection::IEnumProperty
{
AnimationScene* scene = static_cast<AnimationScene*>(cmp.scene);
int value = stream.read<int>();
scene->setControllerDefaultSet(cmp.handle, value);
scene->setControllerDefaultSet(cmp.entity, value);
}
int getEnumCount(ComponentUID cmp) const override
{
Anim::ControllerResource* res = static_cast<AnimationScene*>(cmp.scene)->getControllerResource(cmp.handle);
Anim::ControllerResource* res = static_cast<AnimationScene*>(cmp.scene)->getControllerResource(cmp.entity);
return res ? res->m_sets_names.size() : 0;
}
const char* getEnumName(ComponentUID cmp, int index) const override
{
Anim::ControllerResource* res = static_cast<AnimationScene*>(cmp.scene)->getControllerResource(cmp.handle);
Anim::ControllerResource* res = static_cast<AnimationScene*>(cmp.scene)->getControllerResource(cmp.entity);
return res->m_sets_names[index];
}
};

View file

@ -32,7 +32,7 @@ struct RunningContext
struct Edge* edge;
AnimSet* anim_set;
OutputBlob* event_stream;
ComponentHandle controller;
Entity controller;
};

View file

@ -147,19 +147,20 @@ struct InputValueCustomUI
const auto& selected_entities = app.getWorldEditor().getSelectedEntities();
auto* scene = (AnimationScene*)app.getWorldEditor().getUniverse()->getScene(ANIMABLE_HASH);
ComponentHandle cmp = selected_entities.empty() ? INVALID_COMPONENT : scene->getComponent(selected_entities[0], CONTROLLER_TYPE);
u8* input_data = cmp.isValid() ? scene->getControllerInput(cmp) : nullptr;
if (!scene->getUniverse().hasComponent(selected_entities[0], CONTROLLER_TYPE)) return;
u8* input_data = scene->getControllerInput(selected_entities[0]);
if (!input_data) return;
Anim::InputDecl& input_decl = owner.resource.getEngineResource()->m_input_decl;
Anim::InputDecl::Input& input = input_decl.inputs[owner.engine_idx];
if (input_data)
switch (input.type)
{
switch (input.type)
{
case Anim::InputDecl::FLOAT: ImGui::DragFloat("Value", (float*)(input_data + input.offset)); break;
case Anim::InputDecl::BOOL: ImGui::CheckboxEx("Value", (bool*)(input_data + input.offset)); break;
case Anim::InputDecl::INT: ImGui::InputInt("Value", (int*)(input_data + input.offset)); break;
default: ASSERT(false); break;
}
case Anim::InputDecl::FLOAT: ImGui::DragFloat("Value", (float*)(input_data + input.offset)); break;
case Anim::InputDecl::BOOL: ImGui::CheckboxEx("Value", (bool*)(input_data + input.offset)); break;
case Anim::InputDecl::INT: ImGui::InputInt("Value", (int*)(input_data + input.offset)); break;
default: ASSERT(false); break;
}
}
};
@ -925,10 +926,9 @@ void AnimationEditor::drawGraph()
Anim::ComponentInstance* runtime = nullptr;
if (!entities.empty())
{
ComponentHandle ctrl = scene->getComponent(entities[0], CONTROLLER_TYPE);
if (ctrl.isValid())
if(scene->getUniverse().hasComponent(entities[0], CONTROLLER_TYPE))
{
runtime = scene->getControllerRoot(ctrl);
runtime = scene->getControllerRoot(entities[0]);
}
}
@ -945,11 +945,12 @@ void AnimationEditor::loadFromEntity()
{
auto& entities = m_app.getWorldEditor().getSelectedEntities();
if (entities.empty()) return;
auto* scene = (AnimationScene*)m_app.getWorldEditor().getUniverse()->getScene(ANIMABLE_HASH);
ComponentHandle ctrl = scene->getComponent(entities[0], CONTROLLER_TYPE);
if (!ctrl.isValid()) return;
if (!scene->getUniverse().hasComponent(entities[0], CONTROLLER_TYPE)) return;
newController();
m_path = scene->getControllerSource(ctrl).c_str();
m_path = scene->getControllerSource(entities[0]).c_str();
clearUndoStack();
load();
}
@ -1111,12 +1112,14 @@ void AnimationEditor::clearUndoStack()
void AnimationEditor::update(float time_delta)
{
if (!m_is_playing) return;
auto& entities = m_app.getWorldEditor().getSelectedEntities();
if (entities.empty()) return;
auto* scene = (AnimationScene*)m_app.getWorldEditor().getUniverse()->getScene(ANIMABLE_HASH);
ComponentHandle ctrl = scene->getComponent(entities[0], CONTROLLER_TYPE);
if (!ctrl.isValid()) return;
scene->updateController(ctrl, time_delta);
if (!scene->getUniverse().hasComponent(entities[0], CONTROLLER_TYPE)) return;
scene->updateController(entities[0], time_delta);
}

View file

@ -195,32 +195,31 @@ struct PropertyGridPlugin : PropertyGrid::IPlugin
if (cmp.type != ANIMABLE_TYPE) return;
auto* scene = static_cast<AnimationScene*>(cmp.scene);
auto* animation = scene->getAnimableAnimation(cmp.handle);
auto* animation = scene->getAnimableAnimation(cmp.entity);
if (!animation) return;
if (!animation->isReady()) return;
ImGui::Checkbox("Preview", &m_is_playing);
float time = scene->getAnimableTime(cmp.handle);
float time = scene->getAnimableTime(cmp.entity);
if (ImGui::SliderFloat("Time", &time, 0, animation->getLength()))
{
scene->setAnimableTime(cmp.handle, time);
scene->updateAnimable(cmp.handle, 0);
scene->setAnimableTime(cmp.entity, time);
scene->updateAnimable(cmp.entity, 0);
}
if (m_is_playing)
{
float time_delta = m_app.getWorldEditor().getEngine().getLastTimeDelta();
scene->updateAnimable(cmp.handle, time_delta);
scene->updateAnimable(cmp.entity, time_delta);
}
if (ImGui::CollapsingHeader("Transformation"))
{
auto* render_scene = (RenderScene*)scene->getUniverse().getScene(RENDERABLE_TYPE);
ComponentHandle renderable = render_scene->getComponent(cmp.entity, RENDERABLE_TYPE);
if (renderable.isValid())
if (scene->getUniverse().hasComponent(cmp.entity, RENDERABLE_TYPE))
{
const Pose* pose = render_scene->lockPose(renderable);
Model* model = render_scene->getModelInstanceModel(renderable);
const Pose* pose = render_scene->lockPose(cmp.entity);
Model* model = render_scene->getModelInstanceModel(cmp.entity);
if (pose && model)
{
ImGui::Columns(3);
@ -235,7 +234,7 @@ struct PropertyGridPlugin : PropertyGrid::IPlugin
}
ImGui::Columns();
}
if (pose) render_scene->unlockPose(renderable, false);
if (pose) render_scene->unlockPose(cmp.entity, false);
}
}
}

View file

@ -164,9 +164,9 @@ struct AudioSceneImpl LUMIX_FINAL : public AudioScene
}
void serializeEchoZone(ISerializer& serializer, ComponentHandle cmp)
void serializeEchoZone(ISerializer& serializer, Entity entity)
{
EchoZone& zone = m_echo_zones[{cmp.index}];
EchoZone& zone = m_echo_zones[entity];
serializer.write("radius", zone.radius);
serializer.write("delay", zone.delay);
}
@ -178,12 +178,12 @@ struct AudioSceneImpl LUMIX_FINAL : public AudioScene
zone.entity = entity;
serializer.read(&zone.radius);
serializer.read(&zone.delay);
m_universe.onComponentCreated(entity, ECHO_ZONE_TYPE, this, {entity.index});
m_universe.onComponentCreated(entity, ECHO_ZONE_TYPE, this);
}
void serializeChorusZone(ISerializer& serializer, ComponentHandle cmp)
void serializeChorusZone(ISerializer& serializer, Entity entity)
{
ChorusZone& zone = m_chorus_zones[{cmp.index}];
ChorusZone& zone = m_chorus_zones[entity];
serializer.write("radius", zone.radius);
serializer.write("delay", zone.delay);
serializer.write("depth", zone.depth);
@ -205,12 +205,12 @@ struct AudioSceneImpl LUMIX_FINAL : public AudioScene
serializer.read(&zone.frequency);
serializer.read(&zone.phase);
serializer.read(&zone.wet_dry_mix);
m_universe.onComponentCreated(entity, CHORUS_ZONE_TYPE, this, { entity.index });
m_universe.onComponentCreated(entity, CHORUS_ZONE_TYPE, this);
}
void serializeAmbientSound(ISerializer& serializer, ComponentHandle cmp)
void serializeAmbientSound(ISerializer& serializer, Entity entity)
{
AmbientSound& sound = m_ambient_sounds[{cmp.index}];
AmbientSound& sound = m_ambient_sounds[entity];
serializer.write("clip", m_clips.indexOf(sound.clip));
serializer.write("is_3d", sound.is_3d);
}
@ -225,17 +225,17 @@ struct AudioSceneImpl LUMIX_FINAL : public AudioScene
serializer.read(&clip);
serializer.read(&sound.is_3d);
sound.clip = clip >= 0 ? m_clips[clip] : nullptr;
m_universe.onComponentCreated(entity, AMBIENT_SOUND_TYPE, this, {entity.index});
m_universe.onComponentCreated(entity, AMBIENT_SOUND_TYPE, this);
}
void serializeListener(ISerializer&, ComponentHandle) {}
void serializeListener(ISerializer&, Entity) {}
void deserializeListener(IDeserializer&, Entity entity, int /*scene_version*/)
{
m_listener.entity = entity;
m_universe.onComponentCreated(entity, LISTENER_TYPE, this, {0});
m_universe.onComponentCreated(entity, LISTENER_TYPE, this);
}
@ -274,16 +274,15 @@ struct AudioSceneImpl LUMIX_FINAL : public AudioScene
{
u32 type;
u8 size;
ComponentHandle cmp;
Entity entity;
blob.read(type);
blob.read(cmp);
blob.read(entity);
blob.read(size);
if (type == sound_type)
{
SoundAnimationEvent event;
blob.read(event);
ClipInfo* clip = getClipInfo(event.clip);
Entity entity = m_animation_scene->getControllerEntity(cmp);
if (clip)
{
play(entity, clip, event.is_3d);
@ -332,15 +331,15 @@ struct AudioSceneImpl LUMIX_FINAL : public AudioScene
}
bool isAmbientSound3D(ComponentHandle cmp) override
bool isAmbientSound3D(Entity entity) override
{
return m_ambient_sounds[{cmp.index}].is_3d;
return m_ambient_sounds[entity].is_3d;
}
void setAmbientSound3D(ComponentHandle cmp, bool is_3d) override
void setAmbientSound3D(Entity entity, bool is_3d) override
{
m_ambient_sounds[{cmp.index}].is_3d = is_3d;
m_ambient_sounds[entity].is_3d = is_3d;
}
@ -373,23 +372,16 @@ struct AudioSceneImpl LUMIX_FINAL : public AudioScene
}
ComponentHandle createListener(Entity entity)
void createListener(Entity entity)
{
if (m_listener.entity != INVALID_ENTITY)
{
g_log_warning.log("Audio") << "Listener already exists";
return INVALID_COMPONENT;
}
m_listener.entity = entity;
m_universe.onComponentCreated(entity, LISTENER_TYPE, this, {0});
return {0};
m_universe.onComponentCreated(entity, LISTENER_TYPE, this);
}
ClipInfo* getAmbientSoundClip(ComponentHandle cmp) override
ClipInfo* getAmbientSoundClip(Entity entity) override
{
return m_ambient_sounds[{cmp.index}].clip;
return m_ambient_sounds[entity].clip;
}
@ -403,69 +395,66 @@ struct AudioSceneImpl LUMIX_FINAL : public AudioScene
}
int getAmbientSoundClipIndex(ComponentHandle cmp) override
int getAmbientSoundClipIndex(Entity entity) override
{
return m_clips.indexOf(m_ambient_sounds[{cmp.index}].clip);
return m_clips.indexOf(m_ambient_sounds[entity].clip);
}
void setAmbientSoundClipIndex(ComponentHandle cmp, int index) override
void setAmbientSoundClipIndex(Entity entity, int index) override
{
m_ambient_sounds[{cmp.index}].clip = m_clips[index];
m_ambient_sounds[entity].clip = m_clips[index];
}
void setAmbientSoundClip(ComponentHandle cmp, ClipInfo* clip) override
void setAmbientSoundClip(Entity entity, ClipInfo* clip) override
{
m_ambient_sounds[{cmp.index}].clip = clip;
m_ambient_sounds[entity].clip = clip;
}
ComponentHandle createEchoZone(Entity entity)
void createEchoZone(Entity entity)
{
EchoZone& zone = m_echo_zones.insert(entity);
zone.entity = entity;
zone.delay = 500.0f;
zone.radius = 10;
ComponentHandle cmp = {entity.index};
m_universe.onComponentCreated(entity, ECHO_ZONE_TYPE, this, cmp);
return cmp;
m_universe.onComponentCreated(entity, ECHO_ZONE_TYPE, this);
}
float getEchoZoneDelay(ComponentHandle cmp) override
float getEchoZoneDelay(Entity entity) override
{
return m_echo_zones[{cmp.index}].delay;
return m_echo_zones[entity].delay;
}
void setEchoZoneDelay(ComponentHandle cmp, float delay) override
void setEchoZoneDelay(Entity entity, float delay) override
{
m_echo_zones[{cmp.index}].delay = delay;
m_echo_zones[entity].delay = delay;
}
float getEchoZoneRadius(ComponentHandle cmp) override
float getEchoZoneRadius(Entity entity) override
{
return m_echo_zones[{cmp.index}].radius;
return m_echo_zones[entity].radius;
}
void setEchoZoneRadius(ComponentHandle cmp, float radius) override
void setEchoZoneRadius(Entity entity, float radius) override
{
m_echo_zones[{cmp.index}].radius = radius;
m_echo_zones[entity].radius = radius;
}
void destroyEchoZone(ComponentHandle component)
void destroyEchoZone(Entity entity)
{
Entity entity = {component.index};
int idx = m_echo_zones.find(entity);
m_echo_zones.eraseAt(idx);
m_universe.onComponentDestroyed(entity, ECHO_ZONE_TYPE, this, component);
m_universe.onComponentDestroyed(entity, ECHO_ZONE_TYPE, this);
}
ComponentHandle createChorusZone(Entity entity)
void createChorusZone(Entity entity)
{
ChorusZone& zone = m_chorus_zones.insert(entity);
zone.entity = entity;
@ -476,71 +465,63 @@ struct AudioSceneImpl LUMIX_FINAL : public AudioScene
zone.frequency = 1;
zone.phase = 0;
zone.wet_dry_mix = 0.5f;
ComponentHandle cmp = { entity.index };
m_universe.onComponentCreated(entity, CHORUS_ZONE_TYPE, this, cmp);
return cmp;
m_universe.onComponentCreated(entity, CHORUS_ZONE_TYPE, this);
}
float getChorusZoneDelay(ComponentHandle cmp) override
float getChorusZoneDelay(Entity entity) override
{
return m_chorus_zones[{cmp.index}].delay;
return m_chorus_zones[entity].delay;
}
void setChorusZoneDelay(ComponentHandle cmp, float delay) override
void setChorusZoneDelay(Entity entity, float delay) override
{
m_chorus_zones[{cmp.index}].delay = delay;
m_chorus_zones[entity].delay = delay;
}
float getChorusZoneRadius(ComponentHandle cmp) override
float getChorusZoneRadius(Entity entity) override
{
return m_chorus_zones[{cmp.index}].radius;
return m_chorus_zones[entity].radius;
}
void setChorusZoneRadius(ComponentHandle cmp, float radius) override
void setChorusZoneRadius(Entity entity, float radius) override
{
m_chorus_zones[{cmp.index}].radius = radius;
m_chorus_zones[entity].radius = radius;
}
void destroyChorusZone(ComponentHandle component)
void destroyChorusZone(Entity entity)
{
Entity entity = { component.index };
int idx = m_chorus_zones.find(entity);
m_chorus_zones.eraseAt(idx);
m_universe.onComponentDestroyed(entity, CHORUS_ZONE_TYPE, this, component);
m_universe.onComponentDestroyed(entity, CHORUS_ZONE_TYPE, this);
}
ComponentHandle createAmbientSound(Entity entity)
void createAmbientSound(Entity entity)
{
AmbientSound& sound = m_ambient_sounds.insert(entity);
sound.entity = entity;
sound.clip = nullptr;
sound.playing_sound = -1;
ComponentHandle cmp = {entity.index};
m_universe.onComponentCreated(entity, AMBIENT_SOUND_TYPE, this, cmp);
return cmp;
m_universe.onComponentCreated(entity, AMBIENT_SOUND_TYPE, this);
}
void destroyListener(ComponentHandle component)
void destroyListener(Entity entity)
{
ASSERT(component.index == 0);
auto entity = m_listener.entity;
m_listener.entity = INVALID_ENTITY;
m_universe.onComponentDestroyed(entity, LISTENER_TYPE, this, component);
m_universe.onComponentDestroyed(entity, LISTENER_TYPE, this);
}
void destroyAmbientSound(ComponentHandle component)
void destroyAmbientSound(Entity entity)
{
Entity entity = {component.index};
m_ambient_sounds.erase(entity);
m_universe.onComponentDestroyed(entity, AMBIENT_SOUND_TYPE, this, component);
m_universe.onComponentDestroyed(entity, AMBIENT_SOUND_TYPE, this);
}
@ -588,7 +569,7 @@ struct AudioSceneImpl LUMIX_FINAL : public AudioScene
serializer.read(m_listener.entity);
if (m_listener.entity != INVALID_ENTITY)
{
m_universe.onComponentCreated(m_listener.entity, LISTENER_TYPE, this, {0});
m_universe.onComponentCreated(m_listener.entity, LISTENER_TYPE, this);
}
int count = 0;
@ -627,9 +608,8 @@ struct AudioSceneImpl LUMIX_FINAL : public AudioScene
serializer.read(sound.entity);
serializer.read(sound.is_3d);
ComponentHandle cmp = {sound.entity.index};
m_ambient_sounds.insert(sound.entity, sound);
m_universe.onComponentCreated(sound.entity, AMBIENT_SOUND_TYPE, this, cmp);
m_universe.onComponentCreated(sound.entity, AMBIENT_SOUND_TYPE, this);
}
serializer.read(count);
@ -640,7 +620,7 @@ struct AudioSceneImpl LUMIX_FINAL : public AudioScene
serializer.read(zone);
m_echo_zones.insert(zone.entity, zone);
m_universe.onComponentCreated(zone.entity, ECHO_ZONE_TYPE, this, {zone.entity.index});
m_universe.onComponentCreated(zone.entity, ECHO_ZONE_TYPE, this);
}
serializer.read(count);
@ -651,40 +631,11 @@ struct AudioSceneImpl LUMIX_FINAL : public AudioScene
serializer.read(zone);
m_chorus_zones.insert(zone.entity, zone);
m_universe.onComponentCreated(zone.entity, CHORUS_ZONE_TYPE, this, { zone.entity.index });
m_universe.onComponentCreated(zone.entity, CHORUS_ZONE_TYPE, this);
}
}
ComponentHandle getComponent(Entity entity, ComponentType type) override
{
if (type == LISTENER_TYPE)
{
ComponentHandle listener_cmp = { 0 };
return m_listener.entity == entity ? listener_cmp : INVALID_COMPONENT;
}
if (type == AMBIENT_SOUND_TYPE)
{
if (m_ambient_sounds.find(entity) < 0) return INVALID_COMPONENT;
return {entity.index};
}
if (type == ECHO_ZONE_TYPE)
{
int idx = m_echo_zones.find(entity);
if (idx < 0) return INVALID_COMPONENT;
return {entity.index};
}
if (type == CHORUS_ZONE_TYPE)
{
int idx = m_chorus_zones.find(entity);
if (idx < 0) return INVALID_COMPONENT;
return { entity.index };
}
return INVALID_COMPONENT;
}
int getClipCount() const override { return m_clips.size(); }

View file

@ -55,22 +55,22 @@ public:
virtual void removeClip(ClipInfo* clip) = 0;
virtual void setClip(int clip_id, const Path& path) = 0;
virtual float getEchoZoneRadius(ComponentHandle cmp) = 0;
virtual void setEchoZoneRadius(ComponentHandle cmp, float radius) = 0;
virtual float getEchoZoneDelay(ComponentHandle cmp) = 0;
virtual void setEchoZoneDelay(ComponentHandle cmp, float delay) = 0;
virtual float getEchoZoneRadius(Entity entity) = 0;
virtual void setEchoZoneRadius(Entity entity, float radius) = 0;
virtual float getEchoZoneDelay(Entity entity) = 0;
virtual void setEchoZoneDelay(Entity entity, float delay) = 0;
virtual float getChorusZoneDelay(ComponentHandle cmp) = 0;
virtual void setChorusZoneDelay(ComponentHandle cmp, float delay) = 0;
virtual float getChorusZoneRadius(ComponentHandle cmp) = 0;
virtual void setChorusZoneRadius(ComponentHandle cmp, float radius) = 0;
virtual float getChorusZoneDelay(Entity entity) = 0;
virtual void setChorusZoneDelay(Entity entity, float delay) = 0;
virtual float getChorusZoneRadius(Entity entity) = 0;
virtual void setChorusZoneRadius(Entity entity, float radius) = 0;
virtual ClipInfo* getAmbientSoundClip(ComponentHandle cmp) = 0;
virtual int getAmbientSoundClipIndex(ComponentHandle cmp) = 0;
virtual void setAmbientSoundClipIndex(ComponentHandle cmp, int index) = 0;
virtual void setAmbientSoundClip(ComponentHandle cmp, ClipInfo* clip) = 0;
virtual bool isAmbientSound3D(ComponentHandle cmp) = 0;
virtual void setAmbientSound3D(ComponentHandle cmp, bool is_3d) = 0;
virtual ClipInfo* getAmbientSoundClip(Entity entity) = 0;
virtual int getAmbientSoundClipIndex(Entity entity) = 0;
virtual void setAmbientSoundClipIndex(Entity entity, int index) = 0;
virtual void setAmbientSoundClip(Entity entity, ClipInfo* clip) = 0;
virtual bool isAmbientSound3D(Entity entity) = 0;
virtual void setAmbientSound3D(Entity entity, bool is_3d) = 0;
virtual SoundHandle play(Entity entity, ClipInfo* clip, bool is_3d) = 0;
virtual void stop(SoundHandle sound_id) = 0;

View file

@ -249,7 +249,7 @@ struct EditorPlugin LUMIX_FINAL : public WorldEditor::Plugin
if (cmp.type == ECHO_ZONE_TYPE)
{
auto* audio_scene = static_cast<AudioScene*>(cmp.scene);
float radius = audio_scene->getEchoZoneRadius(cmp.handle);
float radius = audio_scene->getEchoZoneRadius(cmp.entity);
Universe& universe = audio_scene->getUniverse();
Vec3 pos = universe.getPosition(cmp.entity);
@ -261,7 +261,7 @@ struct EditorPlugin LUMIX_FINAL : public WorldEditor::Plugin
else if (cmp.type == CHORUS_ZONE_TYPE)
{
auto* audio_scene = static_cast<AudioScene*>(cmp.scene);
float radius = audio_scene->getChorusZoneRadius(cmp.handle);
float radius = audio_scene->getChorusZoneRadius(cmp.entity);
Universe& universe = audio_scene->getUniverse();
Vec3 pos = universe.getPosition(cmp.entity);

View file

@ -196,7 +196,7 @@ struct EditorIconsImpl LUMIX_FINAL : public EditorIcons
if(!render_interface) return hit;
const auto& universe = *m_editor.getUniverse();
ComponentHandle camera = m_editor.getEditCamera().handle;
Entity camera = m_editor.getEditCamera().entity;
if (!camera.isValid()) return hit;
Matrix camera_mtx = universe.getMatrix(m_editor.getEditCamera().entity);
bool is_ortho = render_interface->isCameraOrtho(camera);
@ -284,7 +284,7 @@ struct EditorIconsImpl LUMIX_FINAL : public EditorIcons
if(!render_interface) return;
const auto& universe = *m_editor.getUniverse();
ComponentHandle camera = m_editor.getEditCamera().handle;
Entity camera = m_editor.getEditCamera().entity;
if (!camera.isValid()) return;
Matrix camera_mtx = universe.getMatrix(m_editor.getEditCamera().entity);
Vec3 camera_pos = camera_mtx.getTranslation();

View file

@ -658,14 +658,14 @@ struct GizmoImpl LUMIX_FINAL : public Gizmo
auto edit_camera = m_editor.getEditCamera();
auto* render_interface = m_editor.getRenderInterface();
bool is_ortho = render_interface->isCameraOrtho(edit_camera.handle);
bool is_ortho = render_interface->isCameraOrtho(edit_camera.entity);
auto camera_pos = m_editor.getUniverse()->getPosition(edit_camera.entity);
auto camera_dir = m_editor.getUniverse()->getRotation(edit_camera.entity).rotate(Vec3(0, 0, -1));
float fov = render_interface->getCameraFOV(edit_camera.handle);
float fov = render_interface->getCameraFOV(edit_camera.entity);
Vec3 origin, cursor_dir;
Vec2 mouse_pos = m_editor.getMousePos();
m_editor.getRenderInterface()->getRay(edit_camera.handle, mouse_pos, origin, cursor_dir);
m_editor.getRenderInterface()->getRay(edit_camera.entity, mouse_pos, origin, cursor_dir);
Axis axis = Axis::NONE;
switch(m_mode)
@ -698,7 +698,7 @@ struct GizmoImpl LUMIX_FINAL : public Gizmo
auto edit_camera = m_editor.getEditCamera();
Vec3 origin, cursor_dir;
Vec2 mouse_pos = m_editor.getMousePos();
m_editor.getRenderInterface()->getRay(edit_camera.handle, mouse_pos, origin, cursor_dir);
m_editor.getRenderInterface()->getRay(edit_camera.entity, mouse_pos, origin, cursor_dir);
m_transform_axis = Axis::NONE;
m_active = -1;
@ -736,7 +736,7 @@ struct GizmoImpl LUMIX_FINAL : public Gizmo
{
auto camera = m_editor.getEditCamera();
Vec3 origin, dir;
m_editor.getRenderInterface()->getRay(camera.handle, mouse_pos, origin, dir);
m_editor.getRenderInterface()->getRay(camera.entity, mouse_pos, origin, dir);
dir.normalize();
bool is_two_axed = transform_axis == Axis::XZ || transform_axis == Axis::XY || transform_axis == Axis::YZ;
if (is_two_axed)
@ -1082,10 +1082,10 @@ struct GizmoImpl LUMIX_FINAL : public Gizmo
{
auto edit_camera = m_editor.getEditCamera();
auto* render_interface = m_editor.getRenderInterface();
bool is_ortho = render_interface->isCameraOrtho(edit_camera.handle);
bool is_ortho = render_interface->isCameraOrtho(edit_camera.entity);
auto camera_pos = m_editor.getUniverse()->getPosition(edit_camera.entity);
auto camera_dir = m_editor.getUniverse()->getRotation(edit_camera.entity).rotate(Vec3(0, 0, -1));
float fov = render_interface->getCameraFOV(edit_camera.handle);
float fov = render_interface->getCameraFOV(edit_camera.entity);
switch (m_mode)
{
@ -1109,10 +1109,10 @@ struct GizmoImpl LUMIX_FINAL : public Gizmo
{
auto edit_camera = m_editor.getEditCamera();
auto* render_interface = m_editor.getRenderInterface();
bool is_ortho = render_interface->isCameraOrtho(edit_camera.handle);
bool is_ortho = render_interface->isCameraOrtho(edit_camera.entity);
auto camera_pos = m_editor.getUniverse()->getPosition(edit_camera.entity);
auto camera_dir = m_editor.getUniverse()->getRotation(edit_camera.entity).rotate(Vec3(0, 0, -1));
float fov = render_interface->getCameraFOV(edit_camera.handle);
float fov = render_interface->getCameraFOV(edit_camera.entity);
collide(camera_pos, camera_dir, fov, is_ortho);
transform();

View file

@ -522,7 +522,7 @@ public:
serializer.write(cmp_name, type_hash);
int scene_version = universe->getScene(cmp.type)->getVersion();
serializer.write("scene_version", scene_version);
universe->serializeComponent(serializer, cmp.type, cmp.handle);
universe->serializeComponent(serializer, cmp.type, cmp.entity);
}
serializer.write("cmp_end", 0);

View file

@ -66,7 +66,6 @@ struct GridUIVisitor LUMIX_FINAL : Reflection::IPropertyVisitor
first_entity_cmp.type = m_cmp_type;
first_entity_cmp.scene = m_editor.getUniverse()->getScene(m_cmp_type);
first_entity_cmp.entity = m_entities[0];
first_entity_cmp.handle = first_entity_cmp.scene->getComponent(m_entities[0], m_cmp_type);
return first_entity_cmp;
}
@ -576,7 +575,6 @@ static bool componentTreeNode(StudioApp& app, ComponentType cmp_type, const Enti
cmp.type = cmp_type;
cmp.entity = entities[0];
cmp.scene = app.getWorldEditor().getUniverse()->getScene(cmp_type);
cmp.handle = cmp.scene->getComponent(cmp.entity, cmp.type);
OutputBlob blob(&b, sizeof(b));
enabled_prop->getValue(cmp, -1, blob);
if(ImGui::Checkbox(cmp_type_name, &b))
@ -623,7 +621,6 @@ void PropertyGrid::showComponentProperties(const Array<Entity>& entities, Compon
cmp.type = cmp_type;
cmp.scene = m_editor.getUniverse()->getScene(cmp.type);
cmp.entity = entities[0];
cmp.handle = cmp.scene->getComponent(cmp.entity, cmp.type);
for (auto* i : m_plugins)
{
i->onGUI(*this, cmp);

View file

@ -32,14 +32,13 @@ public:
virtual ~RenderInterface() {}
virtual AABB getEntityAABB(Universe& universe, Entity entity) = 0;
virtual float getCameraFOV(ComponentHandle cmp) = 0;
virtual bool isCameraOrtho(ComponentHandle cmp) = 0;
virtual float getCameraOrthoSize(ComponentHandle cmp) = 0;
virtual Vec2 getCameraScreenSize(ComponentHandle cmp) = 0;
virtual ComponentHandle getCameraInSlot(const char* slot) = 0;
virtual void setCameraSlot(ComponentHandle cmp, const char* slot) = 0;
virtual Entity getCameraEntity(ComponentHandle cmp) = 0;
virtual void getRay(ComponentHandle camera_index, const Vec2& screen_pos, Vec3& origin, Vec3& dir) = 0;
virtual float getCameraFOV(Entity entity) = 0;
virtual bool isCameraOrtho(Entity entity) = 0;
virtual float getCameraOrthoSize(Entity entity) = 0;
virtual Vec2 getCameraScreenSize(Entity entity) = 0;
virtual Entity getCameraInSlot(const char* slot) = 0;
virtual void setCameraSlot(Entity entity, const char* slot) = 0;
virtual void getRay(Entity entity, const Vec2& screen_pos, Vec3& origin, Vec3& dir) = 0;
virtual float castRay(ModelHandle model, const Vec3& origin, const Vec3& dir, const Matrix& mtx, const Pose* pose) = 0;
virtual void renderModel(ModelHandle model, const Matrix& mtx) = 0;
virtual ModelHandle loadModel(Path& path) = 0;
@ -53,8 +52,8 @@ public:
virtual void addDebugCube(const Vec3& minimum, const Vec3& maximum, u32 color, float life) = 0;
virtual void addDebugCross(const Vec3& pos, float size, u32 color, float life) = 0;
virtual void addDebugLine(const Vec3& from, const Vec3& to, u32 color, float life) = 0;
virtual WorldEditor::RayHit castRay(const Vec3& origin, const Vec3& dir, ComponentHandle ignored) = 0;
virtual Path getModelInstancePath(ComponentHandle cmp) = 0;
virtual WorldEditor::RayHit castRay(const Vec3& origin, const Vec3& dir, Entity ignored) = 0;
virtual Path getModelInstancePath(Entity entity) = 0;
virtual void render(const Matrix& mtx,
u16* indices,
int indices_count,
@ -66,8 +65,8 @@ public:
virtual void addText2D(float x, float y, float font_size, u32 color, const char* text) = 0;
virtual void addRect2D(const Vec2& a, const Vec2& b, u32 color) = 0;
virtual void addRectFilled2D(const Vec2& a, const Vec2& b, u32 color) = 0;
virtual void getModelInstaces(Array<Entity>& entity, const Frustum& frustum, const Vec3& lod_ref_point, ComponentHandle camera) = 0;
virtual Frustum getFrustum(ComponentHandle camera_cmp, const Vec2& a, const Vec2& b) = 0;
virtual void getModelInstaces(Array<Entity>& entity, const Frustum& frustum, const Vec3& lod_ref_point, Entity camera) = 0;
virtual Frustum getFrustum(Entity camera, const Vec2& a, const Vec2& b) = 0;
virtual Vec2 worldToScreenPixels(const Vec3& world) = 0;
};

View file

@ -1785,7 +1785,7 @@ public:
IScene* scene = editor.getUniverse()->getScene(cmp_type);
if (scene)
{
ComponentUID cmp(e, cmp_type, scene, scene->getComponent(e, cmp_type));
ComponentUID cmp(e, cmp_type, scene);
const Reflection::ComponentBase* cmp_des = Reflection::getComponent(cmp_type);
if (cmp.isValid())
{

View file

@ -140,11 +140,10 @@ void getEntityListDisplayName(WorldEditor& editor, char* buf, int max_size, Enti
}
const char* name = editor.getUniverse()->getEntityName(entity);
static const auto MODEL_INSTANCE_TYPE = Reflection::getComponentType("renderable");
ComponentHandle model_instance = editor.getUniverse()->getComponent(entity, MODEL_INSTANCE_TYPE).handle;
if (model_instance.isValid())
if (editor.getUniverse()->hasComponent(entity, MODEL_INSTANCE_TYPE))
{
auto* render_interface = editor.getRenderInterface();
auto path = render_interface->getModelInstancePath(model_instance);
auto path = render_interface->getModelInstancePath(entity);
if (path.isValid())
{
char basename[MAX_PATH_LENGTH];

View file

@ -828,7 +828,6 @@ public:
{
serializer.serialize("inedx", m_index);
serializer.serialize("entity_index", m_component.entity);
serializer.serialize("component_index", m_component.handle);
serializer.serialize("component_type", Reflection::getComponentTypeHash(m_component.type));
serializer.serialize("property_name_hash", crc32(m_property->name));
}
@ -838,7 +837,6 @@ public:
{
serializer.deserialize("inedx", m_index, 0);
serializer.deserialize("entity_index", m_component.entity, INVALID_ENTITY);
serializer.deserialize("component_index", m_component.handle, INVALID_COMPONENT);
u32 hash;
serializer.deserialize("component_type", hash, 0);
m_component.type = Reflection::getComponentTypeFromHash(hash);
@ -903,7 +901,6 @@ public:
{
serializer.serialize("inedx", m_index);
serializer.serialize("entity_index", m_component.entity);
serializer.serialize("component_index", m_component.handle);
serializer.serialize("component_type", Reflection::getComponentTypeHash(m_component.type));
serializer.serialize("property_name_hash", crc32(m_property->name));
}
@ -913,7 +910,6 @@ public:
{
serializer.deserialize("inedx", m_index, 0);
serializer.deserialize("entity_index", m_component.entity, INVALID_ENTITY);
serializer.deserialize("component_index", m_component.handle, INVALID_COMPONENT);
u32 hash;
serializer.deserialize("component_type", hash, 0);
m_component.type = Reflection::getComponentTypeFromHash(hash);
@ -1206,8 +1202,8 @@ private:
for (int j = 0; j < m_entities.size(); ++j)
{
ComponentHandle cmp = universe->createComponent(m_type, m_entities[j]);
if (cmp.isValid())
universe->createComponent(m_type, m_entities[j]);
if (universe->hasComponent(m_entities[j], m_type))
{
ret = true;
}
@ -1221,7 +1217,7 @@ private:
for (int i = 0; i < m_entities.size(); ++i)
{
const ComponentUID& cmp = m_editor.getUniverse()->getComponent(m_entities[i], m_type);
m_editor.getUniverse()->destroyComponent(cmp.handle, cmp.type);
m_editor.getUniverse()->destroyComponent(cmp.entity, cmp.type);
}
}
@ -1501,7 +1497,7 @@ private:
ComponentUID new_component;
IScene* scene = universe->getScene(cmp_type);
ASSERT(scene);
new_component.handle = universe->createComponent(cmp_type, new_entity);
universe->createComponent(cmp_type, new_entity);
new_component.entity = new_entity;
new_component.scene = scene;
new_component.type = cmp_type;
@ -1617,8 +1613,8 @@ private:
InputBlob blob(m_old_values);
for (Entity entity : m_entities)
{
universe->createComponent(cmp.type, cmp.entity);
cmp.entity = entity;
cmp.handle = universe->createComponent(cmp.type, cmp.entity);
::Lumix::load(cmp, -1, blob);
}
}
@ -1643,7 +1639,6 @@ private:
for (Entity entity : m_entities)
{
cmp.entity = entity;
cmp.handle = cmp.scene->getComponent(entity, m_cmp_type);
SaveVisitor save;
save.cmp = cmp;
save.stream = &m_old_values;
@ -1656,7 +1651,7 @@ private:
gather.resource_manager = &resource_manager;
cmp_desc->visit(gather);
m_editor.getUniverse()->destroyComponent(cmp.handle, m_cmp_type);
m_editor.getUniverse()->destroyComponent(cmp.entity, m_cmp_type);
}
return true;
}
@ -1829,8 +1824,8 @@ public:
ComponentUID camera_cmp = getUniverse()->getComponent(m_camera, CAMERA_TYPE);
if (!camera_cmp.isValid()) return;
m_render_interface->getRay(camera_cmp.handle, m_mouse_pos, origin, dir);
auto hit = m_render_interface->castRay(origin, dir, INVALID_COMPONENT);
m_render_interface->getRay(camera_cmp.entity, m_mouse_pos, origin, dir);
auto hit = m_render_interface->castRay(origin, dir, INVALID_ENTITY);
//if (m_gizmo->isActive()) return;
if (!hit.is_hit) return;
@ -1973,8 +1968,8 @@ public:
ComponentUID camera_cmp = getUniverse()->getComponent(m_camera, CAMERA_TYPE);
if (!camera_cmp.isValid()) return;
m_render_interface->getRay(camera_cmp.handle, {(float)x, (float)y}, origin, dir);
auto hit = m_render_interface->castRay(origin, dir, INVALID_COMPONENT);
m_render_interface->getRay(camera_cmp.entity, {(float)x, (float)y}, origin, dir);
auto hit = m_render_interface->castRay(origin, dir, INVALID_ENTITY);
if (m_gizmo->isActive()) return;
for (int i = 0; i < m_plugins.size(); ++i)
@ -2037,14 +2032,14 @@ public:
ComponentUID camera_cmp = getUniverse()->getComponent(m_camera, CAMERA_TYPE);
if (!camera_cmp.isValid()) return;
Entity camera_entity = m_render_interface->getCameraEntity(camera_cmp.handle);
Entity camera_entity = camera_cmp.entity;
Vec3 camera_pos = m_universe->getPosition(camera_entity);
Vec2 min = m_rect_selection_start;
Vec2 max = m_mouse_pos;
if (min.x > max.x) Math::swap(min.x, max.x);
if (min.y > max.y) Math::swap(min.y, max.y);
Frustum frustum = m_render_interface->getFrustum(camera_cmp.handle, min, max);
m_render_interface->getModelInstaces(entities, frustum, camera_pos, camera_cmp.handle);
Frustum frustum = m_render_interface->getFrustum(camera_entity, min, max);
m_render_interface->getModelInstaces(entities, frustum, camera_pos, camera_entity);
selectEntities(entities.empty() ? nullptr : &entities[0], entities.size());
}
@ -2064,8 +2059,8 @@ public:
ComponentUID camera_cmp = getUniverse()->getComponent(m_camera, CAMERA_TYPE);
if (!camera_cmp.isValid()) return;
m_render_interface->getRay(camera_cmp.handle, m_mouse_pos, origin, dir);
auto hit = m_render_interface->castRay(origin, dir, INVALID_COMPONENT);
m_render_interface->getRay(camera_cmp.entity, m_mouse_pos, origin, dir);
auto hit = m_render_interface->castRay(origin, dir, INVALID_ENTITY);
if (m_snap_mode != SnapMode::NONE && !m_selected_entities.empty() && hit.is_hit)
{
@ -2345,7 +2340,7 @@ public:
if (prefab != 0) m_entity_map.create({i});
}
});
m_camera = m_render_interface->getCameraEntity(m_render_interface->getCameraInSlot("editor"));
m_camera = m_render_interface->getCameraInSlot("editor");
}
@ -2392,13 +2387,13 @@ public:
serializer.write("parent", parent);
EntityGUID guid = m_entity_map.get(entity);
StaticString<MAX_PATH_LENGTH> entity_file_path(dir, guid.value, ".ent");
for (ComponentUID cmp = m_universe->getFirstComponent(entity); cmp.handle.isValid();
for (ComponentUID cmp = m_universe->getFirstComponent(entity); cmp.entity.isValid();
cmp = m_universe->getNextComponent(cmp))
{
const char* cmp_name = Reflection::getComponentTypeID(cmp.type.index);
u32 type_hash = Reflection::getComponentTypeHash(cmp.type);
serializer.write(cmp_name, type_hash);
m_universe->serializeComponent(serializer, cmp.type, cmp.handle);
m_universe->serializeComponent(serializer, cmp.type, cmp.entity);
}
serializer.write("cmp_end", (u32)0);
saveFile(entity_file_path);
@ -2475,8 +2470,8 @@ public:
ComponentUID camera_cmp = getUniverse()->getComponent(m_camera, CAMERA_TYPE);
if (!camera_cmp.isValid()) return;
m_render_interface->getRay(camera_cmp.handle, m_mouse_pos, origin, dir);
auto hit = m_render_interface->castRay(origin, dir, INVALID_COMPONENT);
m_render_interface->getRay(camera_cmp.entity, m_mouse_pos, origin, dir);
auto hit = m_render_interface->castRay(origin, dir, INVALID_ENTITY);
if (!hit.is_hit || hit.entity != m_selected_entities[0]) return;
Vec3 snap_pos = getClosestVertex(hit);
@ -2498,16 +2493,15 @@ public:
{
Entity entity = m_selected_entities[i];
ComponentUID model_instance = getUniverse()->getComponent(m_selected_entities[i], MODEL_INSTANCE_TYPE);
Vec3 origin = universe->getPosition(entity);
auto hit = m_render_interface->castRay(origin, Vec3(0, -1, 0), model_instance.handle);
auto hit = m_render_interface->castRay(origin, Vec3(0, -1, 0), m_selected_entities[i]);
if (hit.is_hit)
{
new_positions.push(origin + Vec3(0, -hit.t, 0));
}
else
{
hit = m_render_interface->castRay(origin, Vec3(0, 1, 0), model_instance.handle);
hit = m_render_interface->castRay(origin, Vec3(0, 1, 0), m_selected_entities[i]);
if (hit.is_hit)
{
new_positions.push(origin + Vec3(0, hit.t, 0));
@ -2606,21 +2600,19 @@ public:
Entity addEntity() override
{
ComponentUID cmp = getUniverse()->getComponent(m_camera, CAMERA_TYPE);
Vec2 size = m_render_interface->getCameraScreenSize(cmp.handle);
Vec2 size = m_render_interface->getCameraScreenSize(m_camera);
return addEntityAt((int)size.x >> 1, (int)size.y >> 1);
}
Entity addEntityAt(int camera_x, int camera_y) override
{
ComponentUID camera_cmp = getUniverse()->getComponent(m_camera, CAMERA_TYPE);
Universe* universe = getUniverse();
Vec3 origin;
Vec3 dir;
m_render_interface->getRay(camera_cmp.handle, {(float)camera_x, (float)camera_y}, origin, dir);
auto hit = m_render_interface->castRay(origin, dir, INVALID_COMPONENT);
m_render_interface->getRay(m_camera, {(float)camera_x, (float)camera_y}, origin, dir);
auto hit = m_render_interface->castRay(origin, dir, INVALID_ENTITY);
Vec3 pos;
if (hit.is_hit)
{
@ -2639,15 +2631,14 @@ public:
Vec3 getCameraRaycastHit() override
{
ComponentUID camera_cmp = getUniverse()->getComponent(m_camera, CAMERA_TYPE);
Universe* universe = getUniverse();
Vec2 screen_size = m_render_interface->getCameraScreenSize(camera_cmp.handle);
Vec2 screen_size = m_render_interface->getCameraScreenSize(m_camera);
screen_size *= 0.5f;
Vec3 origin;
Vec3 dir;
m_render_interface->getRay(camera_cmp.handle, {(float)screen_size.x, (float)screen_size.y}, origin, dir);
auto hit = m_render_interface->castRay(origin, dir, INVALID_COMPONENT);
m_render_interface->getRay(m_camera, {(float)screen_size.x, (float)screen_size.y}, origin, dir);
auto hit = m_render_interface->castRay(origin, dir, INVALID_ENTITY);
Vec3 pos;
if (hit.is_hit)
{
@ -2990,7 +2981,8 @@ public:
void cloneComponent(const ComponentUID& src, Entity entity) override
{
IScene* scene = m_universe->getScene(src.type);
ComponentUID clone(entity, src.type, scene, m_universe->createComponent(src.type, entity));
m_universe->createComponent(src.type, entity);
ComponentUID clone(entity, src.type, scene);
const Reflection::ComponentBase* cmp_desc = Reflection::getComponent(src.type);
OutputBlob stream(m_allocator);
@ -3130,7 +3122,7 @@ public:
if (m_engine->deserialize(*m_universe, blob))
{
m_prefab_system->deserialize(blob);
m_camera = m_render_interface->getCameraEntity(m_render_interface->getCameraInSlot("editor"));
m_camera = m_render_interface->getCameraInSlot("editor");
g_log_info.log("Editor") << "Universe parsed in " << timer->getTimeSinceStart() << " seconds";
}
@ -3509,7 +3501,7 @@ public:
universe->setEntityName(m_camera, "editor_camera");
ComponentUID cmp = m_engine->createComponent(*universe, m_camera, CAMERA_TYPE);
ASSERT(cmp.isValid());
m_render_interface->setCameraSlot(cmp.handle, "editor");
m_render_interface->setCameraSlot(cmp.entity, "editor");
}

View file

@ -537,19 +537,20 @@ public:
}
static ComponentHandle LUA_createComponent(Universe* universe, Entity entity, const char* type)
static bool LUA_createComponent(Universe* universe, Entity entity, const char* type)
{
if (!universe) return INVALID_COMPONENT;
if (!universe) return false;
ComponentType cmp_type = Reflection::getComponentType(type);
IScene* scene = universe->getScene(cmp_type);
if (!scene) return INVALID_COMPONENT;
if (scene->getComponent(entity, cmp_type) != INVALID_COMPONENT)
if (!scene) return false;
if (universe->hasComponent(entity, cmp_type))
{
g_log_error.log("Lua Script") << "Component " << type << " already exists in entity " << entity.index;
return INVALID_COMPONENT;
return false;
}
return universe->createComponent(cmp_type, entity);
universe->createComponent(cmp_type, entity);
return true;
}
@ -713,15 +714,9 @@ public:
}
static ComponentHandle LUA_getComponent(Universe* universe, Entity entity, int component_type)
static bool LUA_hasComponent(Universe* universe, Entity entity, int component_type)
{
if (!universe->hasComponent(entity, {component_type})) return INVALID_COMPONENT;
ComponentType type = {component_type};
IScene* scene = universe->getScene(type);
if (scene) return scene->getComponent(entity, type);
ASSERT(false);
return INVALID_COMPONENT;
return universe->hasComponent(entity, {component_type});
}
@ -753,25 +748,23 @@ public:
IScene* scene = ctx->getScene(cmp_type);
if (scene)
{
ComponentUID cmp(e, cmp_type, scene, ctx->createComponent(cmp_type, e));
ComponentUID cmp(e, cmp_type, scene);
const Reflection::ComponentBase* cmp_des = Reflection::getComponent(cmp_type);
if (cmp.isValid())
ctx->createComponent(cmp_type, e);
lua_pushvalue(L, -1);
lua_pushnil(L);
while (lua_next(L, -2) != 0)
{
lua_pushvalue(L, -1);
lua_pushnil(L);
while (lua_next(L, -2) != 0)
{
const char* property_name = luaL_checkstring(L, -2);
SetPropertyVisitor v;
v.property_name = property_name;
v.cmp = cmp;
v.L = L;
cmp_des->visit(v);
const char* property_name = luaL_checkstring(L, -2);
SetPropertyVisitor v;
v.property_name = property_name;
v.cmp = cmp;
v.L = L;
cmp_des->visit(v);
lua_pop(L, 1);
}
lua_pop(L, 1);
}
lua_pop(L, 1);
}
}
lua_pop(L, 1);
@ -1009,7 +1002,7 @@ public:
REGISTER_FUNCTION(createUniverse);
REGISTER_FUNCTION(destroyEntity);
REGISTER_FUNCTION(destroyUniverse);
REGISTER_FUNCTION(getComponent);
REGISTER_FUNCTION(hasComponent);
REGISTER_FUNCTION(getComponentType);
REGISTER_FUNCTION(getEntityDirection);
REGISTER_FUNCTION(getEntityPosition);
@ -1554,7 +1547,8 @@ public:
IScene* scene = universe.getScene(type);
if (!scene) return ComponentUID::INVALID;
return ComponentUID(entity, type, scene, universe.createComponent(type, entity));
universe.createComponent(type, entity);
return ComponentUID(entity, type, scene);
}

View file

@ -75,16 +75,6 @@ namespace Lumix
}
};
template<>
struct HashFunc<ComponentHandle>
{
static u32 get(const ComponentHandle& key)
{
static_assert(sizeof(i32) == sizeof(key.index), "Check this");
return HashFunc<i32>::get(key.index);
}
};
template<>
struct HashFunc<Entity>
{

View file

@ -27,7 +27,6 @@ namespace Lumix
virtual IPlugin& getPlugin() const = 0;
virtual void update(float time_delta, bool paused) = 0;
virtual void lateUpdate(float time_delta, bool paused) {}
virtual ComponentHandle getComponent(Entity entity, ComponentType type) = 0;
virtual Universe& getUniverse() = 0;
virtual void startGame() {}
virtual void stopGame() {}

View file

@ -93,12 +93,6 @@ void JsonSerializer::serialize(const char* label, Entity value)
}
void JsonSerializer::serialize(const char* label, ComponentHandle value)
{
serialize(label, value.index);
}
void JsonSerializer::serialize(const char* label, unsigned int value)
{
writeBlockComma();
@ -255,12 +249,6 @@ void JsonSerializer::serializeArrayItem(Entity value)
}
void JsonSerializer::serializeArrayItem(ComponentHandle value)
{
serializeArrayItem(value.index);
}
void JsonSerializer::serializeArrayItem(int value)
{
writeBlockComma();
@ -319,12 +307,6 @@ void JsonDeserializer::deserialize(const char* label, Entity& value, Entity defa
}
void JsonDeserializer::deserialize(const char* label, ComponentHandle& value, ComponentHandle default_value)
{
deserialize(label, value.index, default_value.index);
}
void JsonDeserializer::deserialize(bool& value, bool default_value)
{
value = !m_is_string_token ? m_token_size == 4 && (compareStringN(m_token, "true", 4) == 0)
@ -594,12 +576,6 @@ void JsonDeserializer::deserializeArrayItem(Entity& value, Entity default_value)
}
void JsonDeserializer::deserializeArrayItem(ComponentHandle& value, ComponentHandle default_value)
{
deserializeArrayItem(value.index, default_value.index);
}
void JsonDeserializer::deserializeArrayItem(u32& value, u32 default_value)
{
deserializeArrayComma();

View file

@ -24,7 +24,6 @@ class LUMIX_ENGINE_API JsonSerializer
JsonSerializer(FS::IFile& file, const Path& path);
void serialize(const char* label, Entity value);
void serialize(const char* label, ComponentHandle value);
void serialize(const char* label, u32 value);
void serialize(const char* label, u16 value);
void serialize(const char* label, float value);
@ -38,7 +37,6 @@ class LUMIX_ENGINE_API JsonSerializer
void beginArray(const char* label);
void endArray();
void serializeArrayItem(Entity value);
void serializeArrayItem(ComponentHandle value);
void serializeArrayItem(u32 value);
void serializeArrayItem(i32 value);
void serializeArrayItem(i64 value);
@ -69,7 +67,6 @@ public:
~JsonDeserializer();
void deserialize(const char* label, Entity& value, Entity default_value);
void deserialize(const char* label, ComponentHandle& value, ComponentHandle default_value);
void deserialize(const char* label, u32& value, u32 default_value);
void deserialize(const char* label, u16& value, u16 default_value);
void deserialize(const char* label, float& value, float default_value);
@ -87,7 +84,6 @@ public:
void deserializeArrayEnd();
bool isArrayEnd();
void deserializeArrayItem(Entity& value, Entity default_value);
void deserializeArrayItem(ComponentHandle& value, ComponentHandle default_value);
void deserializeArrayItem(u32& value, u32 default_value);
void deserializeArrayItem(i32& value, i32 default_value);
void deserializeArrayItem(i64& value, i64 default_value);

View file

@ -30,10 +30,6 @@ template <> inline Entity toType(lua_State* L, int index)
{
return {(int)lua_tointeger(L, index)};
}
template <> inline ComponentHandle toType(lua_State* L, int index)
{
return {(int)lua_tointeger(L, index)};
}
template <> inline Vec3 toType(lua_State* L, int index)
{
Vec3 v;
@ -161,10 +157,6 @@ template <> inline const char* typeToString<Entity>()
{
return "entity";
}
template <> inline const char* typeToString<ComponentHandle>()
{
return "component";
}
template <> inline const char* typeToString<u32>()
{
return "number|integer";
@ -200,10 +192,6 @@ template <> inline bool isType<Entity>(lua_State* L, int index)
{
return lua_isinteger(L, index) != 0;
}
template <> inline bool isType<ComponentHandle>(lua_State* L, int index)
{
return lua_isinteger(L, index) != 0;
}
template <> inline bool isType<Vec3>(lua_State* L, int index)
{
return lua_istable(L, index) != 0 && lua_rawlen(L, index) == 3;
@ -270,10 +258,6 @@ template <> inline void push(lua_State* L, Entity value)
{
lua_pushinteger(L, value.index);
}
template <> inline void push(lua_State* L, ComponentHandle value)
{
lua_pushinteger(L, value.index);
}
inline void push(lua_State* L, const Vec2& value)
{
lua_createtable(L, 2, 0);

View file

@ -72,15 +72,6 @@ static_assert(sizeof(i16) == 2, "Incorrect size of i16");
static_assert(sizeof(i8) == 1, "Incorrect size of i8");
const u32 MAX_PATH_LENGTH = 260;
struct ComponentHandle
{
int index;
bool operator==(const ComponentHandle& rhs) const { return rhs.index == index; }
bool operator<(const ComponentHandle& rhs) const { return rhs.index < index; }
bool operator>(const ComponentHandle& rhs) const { return rhs.index > index; }
bool operator!=(const ComponentHandle& rhs) const { return rhs.index != index; }
bool isValid() const { return index >= 0; }
};
struct Entity
{
@ -104,7 +95,6 @@ struct ComponentType
};
const ComponentType INVALID_COMPONENT_TYPE = {-1};
const Entity INVALID_ENTITY = {-1};
const ComponentHandle INVALID_COMPONENT = {-1};
template <typename T, int count> int lengthOf(const T (&)[count])
{

View file

@ -119,23 +119,23 @@ template <> LUMIX_ENGINE_API void writeToStream<const char*>(OutputBlob& stream,
template <typename Getter> struct GetterProxy;
template <typename R, typename C>
struct GetterProxy<R(C::*)(ComponentHandle, int)>
struct GetterProxy<R(C::*)(Entity, int)>
{
using Getter = R(C::*)(ComponentHandle, int);
static void invoke(OutputBlob& stream, C* inst, Getter getter, ComponentHandle cmp, int index)
using Getter = R(C::*)(Entity, int);
static void invoke(OutputBlob& stream, C* inst, Getter getter, Entity entity, int index)
{
R value = (inst->*getter)(cmp, index);
R value = (inst->*getter)(entity, index);
writeToStream(stream, value);
}
};
template <typename R, typename C>
struct GetterProxy<R(C::*)(ComponentHandle)>
struct GetterProxy<R(C::*)(Entity)>
{
using Getter = R(C::*)(ComponentHandle);
static void invoke(OutputBlob& stream, C* inst, Getter getter, ComponentHandle cmp, int index)
using Getter = R(C::*)(Entity);
static void invoke(OutputBlob& stream, C* inst, Getter getter, Entity entity, int index)
{
R value = (inst->*getter)(cmp);
R value = (inst->*getter)(entity);
writeToStream(stream, value);
}
};
@ -144,26 +144,26 @@ struct GetterProxy<R(C::*)(ComponentHandle)>
template <typename Setter> struct SetterProxy;
template <typename C, typename A>
struct SetterProxy<void (C::*)(ComponentHandle, int, A)>
struct SetterProxy<void (C::*)(Entity, int, A)>
{
using Setter = void (C::*)(ComponentHandle, int, A);
static void invoke(InputBlob& stream, C* inst, Setter setter, ComponentHandle cmp, int index)
using Setter = void (C::*)(Entity, int, A);
static void invoke(InputBlob& stream, C* inst, Setter setter, Entity entity, int index)
{
using Value = RemoveCR<A>;
auto value = readFromStream<Value>(stream);
(inst->*setter)(cmp, index, value);
(inst->*setter)(entity, index, value);
}
};
template <typename C, typename A>
struct SetterProxy<void (C::*)(ComponentHandle, A)>
struct SetterProxy<void (C::*)(Entity, A)>
{
using Setter = void (C::*)(ComponentHandle, A);
static void invoke(InputBlob& stream, C* inst, Setter setter, ComponentHandle cmp, int index)
using Setter = void (C::*)(Entity, A);
static void invoke(InputBlob& stream, C* inst, Setter setter, Entity entity, int index)
{
using Value = RemoveCR<A>;
auto value = readFromStream<Value>(stream);
(inst->*setter)(cmp, value);
(inst->*setter)(entity, value);
}
};
@ -321,7 +321,7 @@ struct EnumProperty : IEnumProperty
using C = typename ClassOf<Getter>::Type;
C* inst = static_cast<C*>(cmp.scene);
static_assert(4 == sizeof(typename ResultOf<Getter>::Type), "enum must have 4 bytes");
detail::GetterProxy<Getter>::invoke(stream, inst, getter, cmp.handle, index);
detail::GetterProxy<Getter>::invoke(stream, inst, getter, cmp.entity, index);
}
void setValue(ComponentUID cmp, int index, InputBlob& stream) const override
@ -330,7 +330,7 @@ struct EnumProperty : IEnumProperty
C* inst = static_cast<C*>(cmp.scene);
static_assert(4 == sizeof(typename ResultOf<Getter>::Type), "enum must have 4 bytes");
detail::SetterProxy<Setter>::invoke(stream, inst, setter, cmp.handle, index);
detail::SetterProxy<Setter>::invoke(stream, inst, setter, cmp.entity, index);
}
@ -360,7 +360,7 @@ struct DynEnumProperty : IEnumProperty
using C = typename ClassOf<Getter>::Type;
C* inst = static_cast<C*>(cmp.scene);
static_assert(4 == sizeof(typename ResultOf<Getter>::Type), "enum must have 4 bytes");
detail::GetterProxy<Getter>::invoke(stream, inst, getter, cmp.handle, index);
detail::GetterProxy<Getter>::invoke(stream, inst, getter, cmp.entity, index);
}
void setValue(ComponentUID cmp, int index, InputBlob& stream) const override
@ -369,7 +369,7 @@ struct DynEnumProperty : IEnumProperty
C* inst = static_cast<C*>(cmp.scene);
static_assert(4 == sizeof(typename ResultOf<Getter>::Type), "enum must have 4 bytes");
detail::SetterProxy<Setter>::invoke(stream, inst, setter, cmp.handle, index);
detail::SetterProxy<Setter>::invoke(stream, inst, setter, cmp.entity, index);
}
@ -403,9 +403,9 @@ struct SampledFuncProperty : ISampledFuncProperty
ASSERT(index == -1);
using C = typename ClassOf<Getter>::Type;
C* inst = static_cast<C*>(cmp.scene);
int count = (inst->*counter)(cmp.handle);
int count = (inst->*counter)(cmp.entity);
stream.write(count);
const Vec2* values = (inst->*getter)(cmp.handle);
const Vec2* values = (inst->*getter)(cmp.entity);
stream.write(values, sizeof(float) * 2 * count);
}
@ -417,7 +417,7 @@ struct SampledFuncProperty : ISampledFuncProperty
int count;
stream.read(count);
auto* buf = (const Vec2*)stream.skip(sizeof(float) * 2 * count);
(inst->*setter)(cmp.handle, buf, count);
(inst->*setter)(cmp.entity, buf, count);
}
float getMaxX() const override { return max_x; }
@ -438,14 +438,14 @@ struct BlobProperty : IBlobProperty
{
using C = typename ClassOf<Getter>::Type;
C* inst = static_cast<C*>(cmp.scene);
(inst->*getter)(cmp.handle, stream);
(inst->*getter)(cmp.entity, stream);
}
void setValue(ComponentUID cmp, int index, InputBlob& stream) const override
{
using C = typename ClassOf<Getter>::Type;
C* inst = static_cast<C*>(cmp.scene);
(inst->*setter)(cmp.handle, stream);
(inst->*setter)(cmp.entity, stream);
}
void visit(IAttributeVisitor& visitor) const override {
@ -470,14 +470,14 @@ struct CommonProperty : Property<T>
{
using C = typename ClassOf<Getter>::Type;
C* inst = static_cast<C*>(cmp.scene);
detail::GetterProxy<Getter>::invoke(stream, inst, getter, cmp.handle, index);
detail::GetterProxy<Getter>::invoke(stream, inst, getter, cmp.entity, index);
}
void setValue(ComponentUID cmp, int index, InputBlob& stream) const override
{
using C = typename ClassOf<Getter>::Type;
C* inst = static_cast<C*>(cmp.scene);
detail::SetterProxy<Setter>::invoke(stream, inst, setter, cmp.handle, index);
detail::SetterProxy<Setter>::invoke(stream, inst, setter, cmp.entity, index);
}
@ -563,7 +563,7 @@ struct ArrayProperty : IArrayProperty
{
using C = typename ClassOf<Counter>::Type;
C* inst = static_cast<C*>(cmp.scene);
(inst->*adder)(cmp.handle, index);
(inst->*adder)(cmp.entity, index);
}
@ -571,7 +571,7 @@ struct ArrayProperty : IArrayProperty
{
using C = typename ClassOf<Counter>::Type;
C* inst = static_cast<C*>(cmp.scene);
(inst->*remover)(cmp.handle, index);
(inst->*remover)(cmp.entity, index);
}
@ -579,7 +579,7 @@ struct ArrayProperty : IArrayProperty
{
using C = typename ClassOf<Counter>::Type;
C* inst = static_cast<C*>(cmp.scene);
return (inst->*counter)(cmp.handle);
return (inst->*counter)(cmp.entity);
}
@ -673,7 +673,7 @@ struct ConstArrayProperty : IArrayProperty
{
using C = typename ClassOf<Counter>::Type;
C* inst = static_cast<C*>(cmp.scene);
return (inst->*counter)(cmp.handle);
return (inst->*counter)(cmp.entity);
}

View file

@ -31,11 +31,6 @@ void TextSerializer::write(const char* label, Entity entity)
blob << "#" << label << "\n\t" << guid.value << "\n";
}
void TextSerializer::write(const char* label, ComponentHandle value)
{
blob << "#" << label << "\n\t" << value.index << "\n";
}
void TextSerializer::write(const char* label, const RigidTransform& value)
{
blob << "#" << label << " (" << value.pos.x << ", " << value.pos.y << ", " << value.pos.z << ") "
@ -179,13 +174,6 @@ void TextDeserializer::read(Quat* value)
}
void TextDeserializer::read(ComponentHandle* value)
{
skip();
value->index = readU32();
}
void TextDeserializer::read(float* value)
{
skip();

View file

@ -45,7 +45,6 @@ struct LUMIX_ENGINE_API ISerializer
virtual ~ISerializer() {}
virtual void write(const char* label, Entity entity) = 0;
virtual void write(const char* label, ComponentHandle value) = 0;
virtual void write(const char* label, const RigidTransform& value) = 0;
virtual void write(const char* label, const Vec4& value) = 0;
virtual void write(const char* label, const Vec3& value) = 0;
@ -68,7 +67,6 @@ struct LUMIX_ENGINE_API IDeserializer
virtual ~IDeserializer() {}
virtual void read(Entity* entity) = 0;
virtual void read(ComponentHandle* value) = 0;
virtual void read(RigidTransform* value) = 0;
virtual void read(Vec4* value) = 0;
virtual void read(Vec3* value) = 0;
@ -96,7 +94,6 @@ struct LUMIX_ENGINE_API TextSerializer LUMIX_FINAL : public ISerializer
}
void write(const char* label, Entity entity) override;
void write(const char* label, ComponentHandle value) override;
void write(const char* label, const RigidTransform& value) override;
void write(const char* label, const Vec4& value) override;
void write(const char* label, const Vec3& value) override;
@ -126,7 +123,6 @@ struct LUMIX_ENGINE_API TextDeserializer LUMIX_FINAL : public IDeserializer
}
void read(Entity* entity) override;
void read(ComponentHandle* value) override;
void read(RigidTransform* value) override;
void read(Vec4* value) override;
void read(Vec3* value) override;

View file

@ -5,7 +5,7 @@ namespace Lumix
{
const ComponentUID ComponentUID::INVALID(INVALID_ENTITY, { -1 }, 0, INVALID_COMPONENT);
const ComponentUID ComponentUID::INVALID(INVALID_ENTITY, { -1 }, 0);
}

View file

@ -16,32 +16,29 @@ struct LUMIX_ENGINE_API ComponentUID final
ComponentUID()
{
handle = INVALID_COMPONENT;
scene = nullptr;
entity = INVALID_ENTITY;
type = {-1};
}
ComponentUID(Entity _entity, ComponentType _type, IScene* _scene, ComponentHandle _handle)
ComponentUID(Entity _entity, ComponentType _type, IScene* _scene)
: entity(_entity)
, type(_type)
, scene(_scene)
, handle(_handle)
{
}
Entity entity;
ComponentType type;
IScene* scene;
ComponentHandle handle;
static const ComponentUID INVALID;
bool operator==(const ComponentUID& rhs) const
{
return type == rhs.type && scene == rhs.scene && handle == rhs.handle;
return type == rhs.type && scene == rhs.scene && entity == rhs.entity;
}
bool isValid() const { return handle.isValid(); }
bool isValid() const { return entity.isValid(); }
};

View file

@ -370,7 +370,7 @@ void Universe::destroyEntity(Entity entity)
auto original_mask = mask;
IScene* scene = m_component_type_map[i].scene;
auto destroy_method = m_component_type_map[i].destroy;
(scene->*destroy_method)(scene->getComponent(entity, type));
(scene->*destroy_method)(entity);
mask = entity_data.components;
ASSERT(original_mask != mask);
}
@ -624,11 +624,11 @@ float Universe::getLocalScale(Entity entity) const
void Universe::serializeComponent(ISerializer& serializer, ComponentType type, ComponentHandle cmp)
void Universe::serializeComponent(ISerializer& serializer, ComponentType type, Entity entity)
{
auto* scene = m_component_type_map[type.index].scene;
auto& method = m_component_type_map[type.index].serialize;
(scene->*method)(serializer, cmp);
(scene->*method)(serializer, entity);
}
@ -785,7 +785,7 @@ ComponentUID Universe::getFirstComponent(Entity entity) const
if ((mask & (u64(1) << i)) != 0)
{
IScene* scene = m_component_type_map[i].scene;
return ComponentUID(entity, {i}, scene, scene->getComponent(entity, {i}));
return ComponentUID(entity, {i}, scene);
}
}
return ComponentUID::INVALID;
@ -800,7 +800,7 @@ ComponentUID Universe::getNextComponent(const ComponentUID& cmp) const
if ((mask & (u64(1) << i)) != 0)
{
IScene* scene = m_component_type_map[i].scene;
return ComponentUID(cmp.entity, {i}, scene, scene->getComponent(cmp.entity, {i}));
return ComponentUID(cmp.entity, {i}, scene);
}
}
return ComponentUID::INVALID;
@ -812,7 +812,7 @@ ComponentUID Universe::getComponent(Entity entity, ComponentType component_type)
u64 mask = m_entities[entity.index].components;
if ((mask & (u64(1) << component_type.index)) == 0) return ComponentUID::INVALID;
IScene* scene = m_component_type_map[component_type.index].scene;
return ComponentUID(entity, component_type, scene, scene->getComponent(entity, component_type));
return ComponentUID(entity, component_type, scene);
}
@ -823,36 +823,36 @@ bool Universe::hasComponent(Entity entity, ComponentType component_type) const
}
void Universe::onComponentDestroyed(Entity entity, ComponentType component_type, IScene* scene, ComponentHandle index)
void Universe::onComponentDestroyed(Entity entity, ComponentType component_type, IScene* scene)
{
auto mask = m_entities[entity.index].components;
auto old_mask = mask;
mask &= ~((u64)1 << component_type.index);
ASSERT(old_mask != mask);
m_entities[entity.index].components = mask;
m_component_destroyed.invoke(ComponentUID(entity, component_type, scene, index));
m_component_destroyed.invoke(ComponentUID(entity, component_type, scene));
}
ComponentHandle Universe::createComponent(ComponentType type, Entity entity)
void Universe::createComponent(ComponentType type, Entity entity)
{
IScene* scene = m_component_type_map[type.index].scene;
auto& create_method = m_component_type_map[type.index].create;
return (scene->*create_method)(entity);
(scene->*create_method)(entity);
}
void Universe::destroyComponent(ComponentHandle cmp, ComponentType type)
void Universe::destroyComponent(Entity entity, ComponentType type)
{
IScene* scene = m_component_type_map[type.index].scene;
auto& destroy_method = m_component_type_map[type.index].destroy;
(scene->*destroy_method)(cmp);
(scene->*destroy_method)(entity);
}
void Universe::onComponentCreated(Entity entity, ComponentType component_type, IScene* scene, ComponentHandle index)
void Universe::onComponentCreated(Entity entity, ComponentType component_type, IScene* scene)
{
ComponentUID cmp(entity, component_type, scene, index);
ComponentUID cmp(entity, component_type, scene);
m_entities[entity.index].components |= (u64)1 << component_type.index;
m_component_added.invoke(cmp);
}

View file

@ -26,16 +26,16 @@ struct PrefabResource;
class LUMIX_ENGINE_API Universe
{
public:
typedef ComponentHandle (IScene::*Create)(Entity);
typedef void (IScene::*Destroy)(ComponentHandle);
typedef void (IScene::*Serialize)(ISerializer&, ComponentHandle);
typedef void (IScene::*Create)(Entity);
typedef void (IScene::*Destroy)(Entity);
typedef void (IScene::*Serialize)(ISerializer&, Entity);
typedef void (IScene::*Deserialize)(IDeserializer&, Entity, int);
struct ComponentTypeEntry
{
IScene* scene = nullptr;
ComponentHandle(IScene::*create)(Entity);
void (IScene::*destroy)(ComponentHandle);
void (IScene::*serialize)(ISerializer&, ComponentHandle);
void (IScene::*create)(Entity);
void (IScene::*destroy)(Entity);
void (IScene::*serialize)(ISerializer&, Entity);
void (IScene::*deserialize)(IDeserializer&, Entity, int);
};
@ -49,10 +49,10 @@ public:
void emplaceEntity(Entity entity);
Entity createEntity(const Vec3& position, const Quat& rotation);
void destroyEntity(Entity entity);
ComponentHandle createComponent(ComponentType type, Entity entity);
void destroyComponent(ComponentHandle cmp, ComponentType type);
void onComponentCreated(Entity entity, ComponentType component_type, IScene* scene, ComponentHandle index);
void onComponentDestroyed(Entity entity, ComponentType component_type, IScene* scene, ComponentHandle index);
void createComponent(ComponentType type, Entity entity);
void destroyComponent(Entity entity, ComponentType type);
void onComponentCreated(Entity entity, ComponentType component_type, IScene* scene);
void onComponentDestroyed(Entity entity, ComponentType component_type, IScene* scene);
bool hasComponent(Entity entity, ComponentType component_type) const;
ComponentUID getComponent(Entity entity, ComponentType type) const;
ComponentUID getFirstComponent(Entity entity) const;
@ -119,7 +119,7 @@ public:
DelegateList<void(const ComponentUID&)>& componentDestroyed() { return m_component_destroyed; }
DelegateList<void(const ComponentUID&)>& componentAdded() { return m_component_added; }
void serializeComponent(ISerializer& serializer, ComponentType type, ComponentHandle cmp);
void serializeComponent(ISerializer& serializer, ComponentType type, Entity entity);
void deserializeComponent(IDeserializer& serializer, Entity entity, ComponentType type, int scene_version);
void serialize(OutputBlob& serializer);
void deserialize(InputBlob& serializer);

View file

@ -171,19 +171,18 @@ private:
};
MouseMode ret = MouseMode::NONE;
ComponentHandle cmp = scene.getComponent(e, GUI_RECT_TYPE);
if (drawHandle(bottom_right, mouse_canvas_pos))
{
m_bottom_right_start_transform.x = scene.getRectRightPoints(cmp);
m_bottom_right_start_transform.y = scene.getRectBottomPoints(cmp);
m_bottom_right_start_transform.x = scene.getRectRightPoints(e);
m_bottom_right_start_transform.y = scene.getRectBottomPoints(e);
ret = MouseMode::RESIZE;
}
if (drawHandle(mid, mouse_canvas_pos))
{
m_bottom_right_start_transform.x = scene.getRectRightPoints(cmp);
m_bottom_right_start_transform.y = scene.getRectBottomPoints(cmp);
m_top_left_start_move.y = scene.getRectTopPoints(cmp);
m_top_left_start_move.x = scene.getRectLeftPoints(cmp);
m_bottom_right_start_transform.x = scene.getRectRightPoints(e);
m_bottom_right_start_transform.y = scene.getRectBottomPoints(e);
m_top_left_start_move.y = scene.getRectTopPoints(e);
m_top_left_start_move.x = scene.getRectLeftPoints(e);
ret = MouseMode::MOVE;
}
return ret;
@ -217,28 +216,27 @@ private:
if (m_editor->getSelectedEntities().size() == 1)
{
Entity e = m_editor->getSelectedEntities()[0];
ComponentHandle cmp = scene->getComponent(e, GUI_RECT_TYPE);
switch (m_mouse_mode)
{
case MouseMode::RESIZE:
{
float b = m_bottom_right_start_transform.y + ImGui::GetMouseDragDelta(0).y;
scene->setRectBottomPoints(cmp, b);
scene->setRectBottomPoints(e, b);
float r = m_bottom_right_start_transform.x + ImGui::GetMouseDragDelta(0).x;
scene->setRectRightPoints(cmp, r);
scene->setRectRightPoints(e, r);
}
break;
case MouseMode::MOVE:
{
float b = m_bottom_right_start_transform.y + ImGui::GetMouseDragDelta(0).y;
scene->setRectBottomPoints(cmp, b);
scene->setRectBottomPoints(e, b);
float r = m_bottom_right_start_transform.x + ImGui::GetMouseDragDelta(0).x;
scene->setRectRightPoints(cmp, r);
scene->setRectRightPoints(e, r);
float t = m_top_left_start_move.y + ImGui::GetMouseDragDelta(0).y;
scene->setRectTopPoints(cmp, t);
scene->setRectTopPoints(e, t);
float l = m_top_left_start_move.x + ImGui::GetMouseDragDelta(0).x;
scene->setRectLeftPoints(cmp, l);
scene->setRectLeftPoints(e, l);
}
break;
}
@ -246,12 +244,8 @@ private:
if (ImGui::IsMouseClicked(0) && m_mouse_mode == MouseMode::NONE)
{
ComponentHandle cmp = scene->getRectAt(toLumix(mouse_canvas_pos), toLumix(size));
if (cmp.isValid())
{
Entity e = scene->getRectEntity(cmp);
if(e.isValid()) m_editor->selectEntities(&e, 1);
}
Entity e = scene->getRectAt(toLumix(mouse_canvas_pos), toLumix(size));
if (e.isValid()) m_editor->selectEntities(&e, 1);
}
m_pipeline->resize(int(size.x), int(size.y));

View file

@ -201,9 +201,9 @@ struct GUISceneImpl LUMIX_FINAL : public GUIScene
}
Vec4 getImageColorRGBA(ComponentHandle cmp) override
Vec4 getImageColorRGBA(Entity entity) override
{
GUIImage* image = m_rects[{cmp.index}]->image;
GUIImage* image = m_rects[entity]->image;
return ABGRu32ToRGBAVec4(image->color);
}
@ -230,16 +230,16 @@ struct GUISceneImpl LUMIX_FINAL : public GUIScene
}
Path getImageSprite(ComponentHandle cmp) override
Path getImageSprite(Entity entity) override
{
GUIImage* image = m_rects[{cmp.index}]->image;
GUIImage* image = m_rects[entity]->image;
return image->sprite ? image->sprite->getPath() : Path();
}
void setImageSprite(ComponentHandle cmp, const Path& path) override
void setImageSprite(Entity entity, const Path& path) override
{
GUIImage* image = m_rects[{cmp.index}]->image;
GUIImage* image = m_rects[entity]->image;
if (image->sprite)
{
image->sprite->getResourceManager().unload(*image->sprite);
@ -256,9 +256,9 @@ struct GUISceneImpl LUMIX_FINAL : public GUIScene
}
void setImageColorRGBA(ComponentHandle cmp, const Vec4& color) override
void setImageColorRGBA(Entity entity, const Vec4& color) override
{
GUIImage* image = m_rects[{cmp.index}]->image;
GUIImage* image = m_rects[entity]->image;
image->color = RGBAVec4ToABGRu32(color);
}
@ -271,15 +271,9 @@ struct GUISceneImpl LUMIX_FINAL : public GUIScene
}
Entity getRectEntity(ComponentHandle cmp) const override
Entity getRectAt(GUIRect& rect, const Vec2& pos, const Rect& parent_rect) const
{
return {cmp.index};
}
ComponentHandle getRectAt(GUIRect& rect, const Vec2& pos, const Rect& parent_rect) const
{
if (!rect.flags.isSet(GUIRect::IS_VALID)) return INVALID_COMPONENT;
if (!rect.flags.isSet(GUIRect::IS_VALID)) return INVALID_ENTITY;
Rect r;
r.x = parent_rect.x + rect.left.points + parent_rect.w * rect.left.relative;
@ -298,18 +292,17 @@ struct GUISceneImpl LUMIX_FINAL : public GUIScene
if (idx < 0) continue;
GUIRect* child_rect = m_rects.at(idx);
ComponentHandle cmp = getRectAt(*child_rect, pos, r);
if (cmp.isValid()) return cmp;
Entity entity = getRectAt(*child_rect, pos, r);
if (entity.isValid()) return entity;
}
ComponentHandle cmp = { rect.entity.index };
return intersect ? cmp : INVALID_COMPONENT;
return intersect ? rect.entity : INVALID_ENTITY;
}
ComponentHandle getRectAt(const Vec2& pos, const Vec2& canvas_size) const override
Entity getRectAt(const Vec2& pos, const Vec2& canvas_size) const override
{
if (!m_root) return INVALID_COMPONENT;
if (!m_root) return INVALID_ENTITY;
return getRectAt(*m_root, pos, { 0, 0, canvas_size.x, canvas_size.y });
}
@ -331,32 +324,32 @@ struct GUISceneImpl LUMIX_FINAL : public GUIScene
}
void enableRect(ComponentHandle cmp, bool enable) override { m_rects[{cmp.index}]->flags.set(GUIRect::IS_ENABLED, enable); }
bool isRectEnabled(ComponentHandle cmp) override { return m_rects[{cmp.index}]->flags.isSet(GUIRect::IS_ENABLED); }
float getRectLeftPoints(ComponentHandle cmp) override { return m_rects[{cmp.index}]->left.points; }
void setRectLeftPoints(ComponentHandle cmp, float value) override { m_rects[{cmp.index}]->left.points = value; }
float getRectLeftRelative(ComponentHandle cmp) override { return m_rects[{cmp.index}]->left.relative; }
void setRectLeftRelative(ComponentHandle cmp, float value) override { m_rects[{cmp.index}]->left.relative = value; }
void enableRect(Entity entity, bool enable) override { m_rects[entity]->flags.set(GUIRect::IS_ENABLED, enable); }
bool isRectEnabled(Entity entity) override { return m_rects[entity]->flags.isSet(GUIRect::IS_ENABLED); }
float getRectLeftPoints(Entity entity) override { return m_rects[entity]->left.points; }
void setRectLeftPoints(Entity entity, float value) override { m_rects[entity]->left.points = value; }
float getRectLeftRelative(Entity entity) override { return m_rects[entity]->left.relative; }
void setRectLeftRelative(Entity entity, float value) override { m_rects[entity]->left.relative = value; }
float getRectRightPoints(ComponentHandle cmp) override { return m_rects[{cmp.index}]->right.points; }
void setRectRightPoints(ComponentHandle cmp, float value) override { m_rects[{cmp.index}]->right.points = value; }
float getRectRightRelative(ComponentHandle cmp) override { return m_rects[{cmp.index}]->right.relative; }
void setRectRightRelative(ComponentHandle cmp, float value) override { m_rects[{cmp.index}]->right.relative = value; }
float getRectRightPoints(Entity entity) override { return m_rects[entity]->right.points; }
void setRectRightPoints(Entity entity, float value) override { m_rects[entity]->right.points = value; }
float getRectRightRelative(Entity entity) override { return m_rects[entity]->right.relative; }
void setRectRightRelative(Entity entity, float value) override { m_rects[entity]->right.relative = value; }
float getRectTopPoints(ComponentHandle cmp) override { return m_rects[{cmp.index}]->top.points; }
void setRectTopPoints(ComponentHandle cmp, float value) override { m_rects[{cmp.index}]->top.points = value; }
float getRectTopRelative(ComponentHandle cmp) override { return m_rects[{cmp.index}]->top.relative; }
void setRectTopRelative(ComponentHandle cmp, float value) override { m_rects[{cmp.index}]->top.relative = value; }
float getRectTopPoints(Entity entity) override { return m_rects[entity]->top.points; }
void setRectTopPoints(Entity entity, float value) override { m_rects[entity]->top.points = value; }
float getRectTopRelative(Entity entity) override { return m_rects[entity]->top.relative; }
void setRectTopRelative(Entity entity, float value) override { m_rects[entity]->top.relative = value; }
float getRectBottomPoints(ComponentHandle cmp) override { return m_rects[{cmp.index}]->bottom.points; }
void setRectBottomPoints(ComponentHandle cmp, float value) override { m_rects[{cmp.index}]->bottom.points = value; }
float getRectBottomRelative(ComponentHandle cmp) override { return m_rects[{cmp.index}]->bottom.relative; }
void setRectBottomRelative(ComponentHandle cmp, float value) override { m_rects[{cmp.index}]->bottom.relative = value; }
float getRectBottomPoints(Entity entity) override { return m_rects[entity]->bottom.points; }
void setRectBottomPoints(Entity entity, float value) override { m_rects[entity]->bottom.points = value; }
float getRectBottomRelative(Entity entity) override { return m_rects[entity]->bottom.relative; }
void setRectBottomRelative(Entity entity, float value) override { m_rects[entity]->bottom.relative = value; }
void setTextFontSize(ComponentHandle cmp, int value) override
void setTextFontSize(Entity entity, int value) override
{
GUIText* gui_text = m_rects[{cmp.index}]->text;
GUIText* gui_text = m_rects[entity]->text;
FontResource* res = gui_text->font_resource;
if (res) res->removeRef(*gui_text->font);
gui_text->font_size = value;
@ -364,37 +357,37 @@ struct GUISceneImpl LUMIX_FINAL : public GUIScene
}
int getTextFontSize(ComponentHandle cmp) override
int getTextFontSize(Entity entity) override
{
GUIText* gui_text = m_rects[{cmp.index}]->text;
GUIText* gui_text = m_rects[entity]->text;
return gui_text->font_size;
}
Vec4 getTextColorRGBA(ComponentHandle cmp) override
Vec4 getTextColorRGBA(Entity entity) override
{
GUIText* gui_text = m_rects[{cmp.index}]->text;
GUIText* gui_text = m_rects[entity]->text;
return ABGRu32ToRGBAVec4(gui_text->color);
}
void setTextColorRGBA(ComponentHandle cmp, const Vec4& color) override
void setTextColorRGBA(Entity entity, const Vec4& color) override
{
GUIText* gui_text = m_rects[{cmp.index}]->text;
GUIText* gui_text = m_rects[entity]->text;
gui_text->color = RGBAVec4ToABGRu32(color);
}
Path getTextFontPath(ComponentHandle cmp) override
Path getTextFontPath(Entity entity) override
{
GUIText* gui_text = m_rects[{cmp.index}]->text;
GUIText* gui_text = m_rects[entity]->text;
return gui_text->font_resource == nullptr ? Path() : gui_text->font_resource->getPath();
}
void setTextFontPath(ComponentHandle cmp, const Path& path) override
void setTextFontPath(Entity entity, const Path& path) override
{
GUIText* gui_text = m_rects[{cmp.index}]->text;
GUIText* gui_text = m_rects[entity]->text;
FontResource* res = gui_text->font_resource;
if (res)
{
@ -412,23 +405,23 @@ struct GUISceneImpl LUMIX_FINAL : public GUIScene
}
void setText(ComponentHandle cmp, const char* value) override
void setText(Entity entity, const char* value) override
{
GUIText* gui_text = m_rects[{cmp.index}]->text;
GUIText* gui_text = m_rects[entity]->text;
gui_text->text = value;
}
const char* getText(ComponentHandle cmp) override
const char* getText(Entity entity) override
{
GUIText* text = m_rects[{cmp.index}]->text;
GUIText* text = m_rects[entity]->text;
return text->text.c_str();
}
void serializeRect(ISerializer& serializer, ComponentHandle cmp)
void serializeRect(ISerializer& serializer, Entity entity)
{
const GUIRect& rect = *m_rects[{cmp.index}];
const GUIRect& rect = *m_rects[entity];
serializer.write("flags", rect.flags.base);
serializer.write("top_pts", rect.top.points);
@ -447,8 +440,6 @@ struct GUISceneImpl LUMIX_FINAL : public GUIScene
void deserializeRect(IDeserializer& serializer, Entity entity, int /*scene_version*/)
{
ComponentHandle cmp = { entity.index };
int idx = m_rects.find(entity);
GUIRect* rect;
if (idx >= 0)
@ -476,13 +467,13 @@ struct GUISceneImpl LUMIX_FINAL : public GUIScene
m_root = findRoot();
m_universe.onComponentCreated(entity, GUI_RECT_TYPE, this, cmp);
m_universe.onComponentCreated(entity, GUI_RECT_TYPE, this);
}
void serializeImage(ISerializer& serializer, ComponentHandle cmp)
void serializeImage(ISerializer& serializer, Entity entity)
{
const GUIRect& rect = *m_rects[{cmp.index}];
const GUIRect& rect = *m_rects[entity];
serializer.write("color", rect.image->color);
}
@ -501,14 +492,13 @@ struct GUISceneImpl LUMIX_FINAL : public GUIScene
serializer.read(&rect.image->color);
ComponentHandle cmp = {entity.index};
m_universe.onComponentCreated(entity, GUI_IMAGE_TYPE, this, cmp);
m_universe.onComponentCreated(entity, GUI_IMAGE_TYPE, this);
}
void serializeText(ISerializer& serializer, ComponentHandle cmp)
void serializeText(ISerializer& serializer, Entity entity)
{
const GUIRect& rect = *m_rects[{cmp.index}];
const GUIRect& rect = *m_rects[entity];
serializer.write("font", rect.text->font_resource ? rect.text->font_resource->getPath().c_str() : "");
serializer.write("color", rect.text->color);
serializer.write("font_size", rect.text->font_size);
@ -544,8 +534,7 @@ struct GUISceneImpl LUMIX_FINAL : public GUIScene
rect.text->font = rect.text->font_resource->addRef(rect.text->font_size);
}
ComponentHandle cmp = { entity.index };
m_universe.onComponentCreated(entity, GUI_TEXT_TYPE, this, cmp);
m_universe.onComponentCreated(entity, GUI_TEXT_TYPE, this);
}
@ -566,10 +555,8 @@ struct GUISceneImpl LUMIX_FINAL : public GUIScene
}
ComponentHandle createRect(Entity entity)
void createRect(Entity entity)
{
ComponentHandle cmp = { entity.index };
int idx = m_rects.find(entity);
GUIRect* rect;
if (idx >= 0)
@ -584,14 +571,12 @@ struct GUISceneImpl LUMIX_FINAL : public GUIScene
rect->entity = entity;
rect->flags.set(GUIRect::IS_VALID);
rect->flags.set(GUIRect::IS_ENABLED);
m_universe.onComponentCreated(entity, GUI_RECT_TYPE, this, cmp);
m_universe.onComponentCreated(entity, GUI_RECT_TYPE, this);
m_root = findRoot();
return cmp;
}
ComponentHandle createText(Entity entity)
void createText(Entity entity)
{
int idx = m_rects.find(entity);
if (idx < 0)
@ -602,13 +587,12 @@ struct GUISceneImpl LUMIX_FINAL : public GUIScene
GUIRect& rect = *m_rects.at(idx);
rect.text = LUMIX_NEW(m_allocator, GUIText)(m_allocator);
rect.text->font = m_font_manager->getDefaultFont();
ComponentHandle cmp = {entity.index};
m_universe.onComponentCreated(entity, GUI_TEXT_TYPE, this, cmp);
return cmp;
m_universe.onComponentCreated(entity, GUI_TEXT_TYPE, this);
}
ComponentHandle createImage(Entity entity)
void createImage(Entity entity)
{
int idx = m_rects.find(entity);
if (idx < 0)
@ -618,9 +602,8 @@ struct GUISceneImpl LUMIX_FINAL : public GUIScene
}
GUIRect& rect = *m_rects.at(idx);
rect.image = LUMIX_NEW(m_allocator, GUIImage);
ComponentHandle cmp = {entity.index};
m_universe.onComponentCreated(entity, GUI_IMAGE_TYPE, this, cmp);
return cmp;
m_universe.onComponentCreated(entity, GUI_IMAGE_TYPE, this);
}
@ -640,9 +623,8 @@ struct GUISceneImpl LUMIX_FINAL : public GUIScene
}
void destroyRect(ComponentHandle component)
void destroyRect(Entity entity)
{
Entity entity = {component.index};
GUIRect* rect = m_rects[entity];
rect->flags.set(GUIRect::IS_VALID, false);
if (rect->image == nullptr && rect->text == nullptr)
@ -655,27 +637,25 @@ struct GUISceneImpl LUMIX_FINAL : public GUIScene
{
m_root = findRoot();
}
m_universe.onComponentDestroyed(entity, GUI_RECT_TYPE, this, component);
m_universe.onComponentDestroyed(entity, GUI_RECT_TYPE, this);
}
void destroyImage(ComponentHandle component)
void destroyImage(Entity entity)
{
Entity entity = {component.index};
GUIRect* rect = m_rects[entity];
LUMIX_DELETE(m_allocator, rect->image);
rect->image = nullptr;
m_universe.onComponentDestroyed(entity, GUI_IMAGE_TYPE, this, component);
m_universe.onComponentDestroyed(entity, GUI_IMAGE_TYPE, this);
}
void destroyText(ComponentHandle component)
void destroyText(Entity entity)
{
Entity entity = { component.index };
GUIRect* rect = m_rects[entity];
LUMIX_DELETE(m_allocator, rect->text);
rect->text = nullptr;
m_universe.onComponentDestroyed(entity, GUI_TEXT_TYPE, this, component);
m_universe.onComponentDestroyed(entity, GUI_TEXT_TYPE, this);
}
@ -725,7 +705,7 @@ struct GUISceneImpl LUMIX_FINAL : public GUIScene
m_rects.insert(rect->entity, rect);
if (rect->flags.isSet(GUIRect::IS_VALID))
{
m_universe.onComponentCreated(rect->entity, GUI_RECT_TYPE, this, {rect->entity.index});
m_universe.onComponentCreated(rect->entity, GUI_RECT_TYPE, this);
}
bool has_image = serializer.read<bool>();
@ -733,7 +713,7 @@ struct GUISceneImpl LUMIX_FINAL : public GUIScene
{
rect->image = LUMIX_NEW(m_allocator, GUIImage);
serializer.read(rect->image->color);
m_universe.onComponentCreated(rect->entity, GUI_IMAGE_TYPE, this, {rect->entity.index});
m_universe.onComponentCreated(rect->entity, GUI_IMAGE_TYPE, this);
}
bool has_text = serializer.read<bool>();
@ -756,37 +736,13 @@ struct GUISceneImpl LUMIX_FINAL : public GUIScene
text.font_resource = (FontResource*)m_font_manager->load(Path(tmp));
text.font = text.font_resource->addRef(text.font_size);
}
m_universe.onComponentCreated(rect->entity, GUI_TEXT_TYPE, this, {rect->entity.index});
m_universe.onComponentCreated(rect->entity, GUI_TEXT_TYPE, this);
}
}
m_root = findRoot();
}
ComponentHandle getComponent(Entity entity, ComponentType type) override
{
if (type == GUI_TEXT_TYPE)
{
int idx = m_rects.find(entity);
if (idx < 0) return INVALID_COMPONENT;
if (!m_rects.at(idx)->text) return INVALID_COMPONENT;
return {entity.index};
}
if (type == GUI_RECT_TYPE)
{
if (m_rects.find(entity) < 0) return INVALID_COMPONENT;
return {entity.index};
}
if (type == GUI_IMAGE_TYPE)
{
int idx = m_rects.find(entity);
if (idx < 0) return INVALID_COMPONENT;
if (!m_rects.at(idx)->image) return INVALID_COMPONENT;
return {entity.index};
}
return INVALID_COMPONENT;
}
Universe& getUniverse() override { return m_universe; }
IPlugin& getPlugin() const override { return m_system; }

View file

@ -33,44 +33,43 @@ public:
virtual bool hasGUI(Entity entity) const = 0;
virtual Rect getRectOnCanvas(Entity entity, const Vec2& canva_size) const = 0;
virtual Entity getRectEntity(ComponentHandle cmp) const = 0;
virtual ComponentHandle getRectAt(const Vec2& pos, const Vec2& canvas_size) const = 0;
virtual Entity getRectAt(const Vec2& pos, const Vec2& canvas_size) const = 0;
virtual void enableRect(ComponentHandle cmp, bool enable) = 0;
virtual bool isRectEnabled(ComponentHandle cmp) = 0;
virtual float getRectLeftPoints(ComponentHandle cmp) = 0;
virtual void setRectLeftPoints(ComponentHandle cmp, float value) = 0;
virtual float getRectLeftRelative(ComponentHandle cmp) = 0;
virtual void setRectLeftRelative(ComponentHandle cmp, float value) = 0;
virtual void enableRect(Entity entity, bool enable) = 0;
virtual bool isRectEnabled(Entity entity) = 0;
virtual float getRectLeftPoints(Entity entity) = 0;
virtual void setRectLeftPoints(Entity entity, float value) = 0;
virtual float getRectLeftRelative(Entity entity) = 0;
virtual void setRectLeftRelative(Entity entity, float value) = 0;
virtual float getRectRightPoints(ComponentHandle cmp) = 0;
virtual void setRectRightPoints(ComponentHandle cmp, float value) = 0;
virtual float getRectRightRelative(ComponentHandle cmp) = 0;
virtual void setRectRightRelative(ComponentHandle cmp, float value) = 0;
virtual float getRectRightPoints(Entity entity) = 0;
virtual void setRectRightPoints(Entity entity, float value) = 0;
virtual float getRectRightRelative(Entity entity) = 0;
virtual void setRectRightRelative(Entity entity, float value) = 0;
virtual float getRectTopPoints(ComponentHandle cmp) = 0;
virtual void setRectTopPoints(ComponentHandle cmp, float value) = 0;
virtual float getRectTopRelative(ComponentHandle cmp) = 0;
virtual void setRectTopRelative(ComponentHandle cmp, float value) = 0;
virtual float getRectTopPoints(Entity entity) = 0;
virtual void setRectTopPoints(Entity entity, float value) = 0;
virtual float getRectTopRelative(Entity entity) = 0;
virtual void setRectTopRelative(Entity entity, float value) = 0;
virtual float getRectBottomPoints(ComponentHandle cmp) = 0;
virtual void setRectBottomPoints(ComponentHandle cmp, float value) = 0;
virtual float getRectBottomRelative(ComponentHandle cmp) = 0;
virtual void setRectBottomRelative(ComponentHandle cmp, float value) = 0;
virtual float getRectBottomPoints(Entity entity) = 0;
virtual void setRectBottomPoints(Entity entity, float value) = 0;
virtual float getRectBottomRelative(Entity entity) = 0;
virtual void setRectBottomRelative(Entity entity, float value) = 0;
virtual Vec4 getImageColorRGBA(ComponentHandle cmp) = 0;
virtual void setImageColorRGBA(ComponentHandle cmp, const Vec4& color) = 0;
virtual Path getImageSprite(ComponentHandle cmp) = 0;
virtual void setImageSprite(ComponentHandle cmp, const Path& path) = 0;
virtual Vec4 getImageColorRGBA(Entity entity) = 0;
virtual void setImageColorRGBA(Entity entity, const Vec4& color) = 0;
virtual Path getImageSprite(Entity entity) = 0;
virtual void setImageSprite(Entity entity, const Path& path) = 0;
virtual void setText(ComponentHandle cmp, const char* text) = 0;
virtual const char* getText(ComponentHandle cmp) = 0;
virtual void setTextFontSize(ComponentHandle cmp, int value) = 0;
virtual int getTextFontSize(ComponentHandle cmp) = 0;
virtual Vec4 getTextColorRGBA(ComponentHandle cmp) = 0;
virtual void setTextColorRGBA(ComponentHandle cmp, const Vec4& color) = 0;
virtual Path getTextFontPath(ComponentHandle cmp) = 0;
virtual void setTextFontPath(ComponentHandle cmp, const Path& path) = 0;
virtual void setText(Entity entity, const char* text) = 0;
virtual const char* getText(Entity entity) = 0;
virtual void setTextFontSize(Entity entity, int value) = 0;
virtual int getTextFontSize(Entity entity) = 0;
virtual Vec4 getTextColorRGBA(Entity entity) = 0;
virtual void setTextColorRGBA(Entity entity, const Vec4& color) = 0;
virtual Path getTextFontPath(Entity entity) = 0;
virtual void setTextFontPath(Entity entity, const Path& path) = 0;
};

View file

@ -48,7 +48,7 @@ struct PropertyGridPlugin LUMIX_FINAL : public PropertyGrid::IPlugin
bool execute() override
{
auto* scene = static_cast<LuaScriptScene*>(editor.getUniverse()->getScene(crc32("lua_script")));
scr_index = scene->addScript(cmp);
scr_index = scene->addScript(entity);
return true;
}
@ -56,16 +56,16 @@ struct PropertyGridPlugin LUMIX_FINAL : public PropertyGrid::IPlugin
void undo() override
{
auto* scene = static_cast<LuaScriptScene*>(editor.getUniverse()->getScene(crc32("lua_script")));
scene->removeScript(cmp, scr_index);
scene->removeScript(entity, scr_index);
}
void serialize(JsonSerializer& serializer) override { serializer.serialize("component", cmp); }
void serialize(JsonSerializer& serializer) override { serializer.serialize("entity", entity); }
void deserialize(JsonDeserializer& serializer) override
{
serializer.deserialize("component", cmp, INVALID_COMPONENT);
serializer.deserialize("entity", entity, INVALID_ENTITY);
}
@ -76,7 +76,7 @@ struct PropertyGridPlugin LUMIX_FINAL : public PropertyGrid::IPlugin
WorldEditor& editor;
ComponentHandle cmp;
Entity entity;
int scr_index;
};
@ -86,7 +86,7 @@ struct PropertyGridPlugin LUMIX_FINAL : public PropertyGrid::IPlugin
explicit MoveScriptCommand(WorldEditor& editor)
: blob(editor.getAllocator())
, scr_index(-1)
, cmp(INVALID_COMPONENT)
, entity(INVALID_ENTITY)
, up(true)
{
scene = static_cast<LuaScriptScene*>(editor.getUniverse()->getScene(crc32("lua_script")));
@ -97,7 +97,7 @@ struct PropertyGridPlugin LUMIX_FINAL : public PropertyGrid::IPlugin
: blob(allocator)
, scene(nullptr)
, scr_index(-1)
, cmp(INVALID_COMPONENT)
, entity(INVALID_ENTITY)
, up(true)
{
}
@ -105,20 +105,20 @@ struct PropertyGridPlugin LUMIX_FINAL : public PropertyGrid::IPlugin
bool execute() override
{
scene->moveScript(cmp, scr_index, up);
scene->moveScript(entity, scr_index, up);
return true;
}
void undo() override
{
scene->moveScript(cmp, up ? scr_index - 1 : scr_index + 1, !up);
scene->moveScript(entity, up ? scr_index - 1 : scr_index + 1, !up);
}
void serialize(JsonSerializer& serializer) override
{
serializer.serialize("component", cmp);
serializer.serialize("entity", entity);
serializer.serialize("scr_index", scr_index);
serializer.serialize("up", up);
}
@ -126,7 +126,7 @@ struct PropertyGridPlugin LUMIX_FINAL : public PropertyGrid::IPlugin
void deserialize(JsonDeserializer& serializer) override
{
serializer.deserialize("component", cmp, INVALID_COMPONENT);
serializer.deserialize("entity", entity, INVALID_ENTITY);
serializer.deserialize("scr_index", scr_index, 0);
serializer.deserialize("up", up, false);
}
@ -140,7 +140,7 @@ struct PropertyGridPlugin LUMIX_FINAL : public PropertyGrid::IPlugin
OutputBlob blob;
LuaScriptScene* scene;
ComponentHandle cmp;
Entity entity;
int scr_index;
bool up;
};
@ -151,7 +151,7 @@ struct PropertyGridPlugin LUMIX_FINAL : public PropertyGrid::IPlugin
explicit RemoveScriptCommand(WorldEditor& editor)
: blob(editor.getAllocator())
, scr_index(-1)
, cmp(INVALID_COMPONENT)
, entity(INVALID_ENTITY)
{
scene = static_cast<LuaScriptScene*>(editor.getUniverse()->getScene(crc32("lua_script")));
}
@ -161,37 +161,37 @@ struct PropertyGridPlugin LUMIX_FINAL : public PropertyGrid::IPlugin
: blob(allocator)
, scene(nullptr)
, scr_index(-1)
, cmp(INVALID_COMPONENT)
, entity(INVALID_ENTITY)
{
}
bool execute() override
{
scene->serializeScript(cmp, scr_index, blob);
scene->removeScript(cmp, scr_index);
scene->serializeScript(entity, scr_index, blob);
scene->removeScript(entity, scr_index);
return true;
}
void undo() override
{
scene->insertScript(cmp, scr_index);
scene->insertScript(entity, scr_index);
InputBlob input(blob);
scene->deserializeScript(cmp, scr_index, input);
scene->deserializeScript(entity, scr_index, input);
}
void serialize(JsonSerializer& serializer) override
{
serializer.serialize("component", cmp);
serializer.serialize("entity", entity);
serializer.serialize("scr_index", scr_index);
}
void deserialize(JsonDeserializer& serializer) override
{
serializer.deserialize("component", cmp, INVALID_COMPONENT);
serializer.deserialize("entity", entity, INVALID_ENTITY);
serializer.deserialize("scr_index", scr_index, 0);
}
@ -203,7 +203,7 @@ struct PropertyGridPlugin LUMIX_FINAL : public PropertyGrid::IPlugin
OutputBlob blob;
LuaScriptScene* scene;
ComponentHandle cmp;
Entity entity;
int scr_index;
};
@ -220,7 +220,7 @@ struct PropertyGridPlugin LUMIX_FINAL : public PropertyGrid::IPlugin
SetPropertyCommand(WorldEditor& _editor,
ComponentHandle cmp,
Entity entity,
int scr_index,
const char* property_name,
const char* val,
@ -228,20 +228,20 @@ struct PropertyGridPlugin LUMIX_FINAL : public PropertyGrid::IPlugin
: property_name(property_name, allocator)
, value(val, allocator)
, old_value(allocator)
, component(cmp)
, entity(entity)
, script_index(scr_index)
, editor(_editor)
{
auto* scene = static_cast<LuaScriptScene*>(editor.getUniverse()->getScene(crc32("lua_script")));
if (property_name[0] == '-')
{
old_value = scene->getScriptPath(component, script_index).c_str();
old_value = scene->getScriptPath(entity, script_index).c_str();
}
else
{
char tmp[1024];
tmp[0] = '\0';
scene->getPropertyValue(cmp, scr_index, property_name, tmp, lengthOf(tmp));
scene->getPropertyValue(entity, scr_index, property_name, tmp, lengthOf(tmp));
old_value = tmp;
return;
}
@ -253,11 +253,11 @@ struct PropertyGridPlugin LUMIX_FINAL : public PropertyGrid::IPlugin
auto* scene = static_cast<LuaScriptScene*>(editor.getUniverse()->getScene(crc32("lua_script")));
if (property_name.length() > 0 && property_name[0] == '-')
{
scene->setScriptPath(component, script_index, Path(value.c_str()));
scene->setScriptPath(entity, script_index, Path(value.c_str()));
}
else
{
scene->setPropertyValue(component, script_index, property_name.c_str(), value.c_str());
scene->setPropertyValue(entity, script_index, property_name.c_str(), value.c_str());
}
return true;
}
@ -268,18 +268,18 @@ struct PropertyGridPlugin LUMIX_FINAL : public PropertyGrid::IPlugin
auto* scene = static_cast<LuaScriptScene*>(editor.getUniverse()->getScene(crc32("lua_script")));
if (property_name.length() > 0 && property_name[0] == '-')
{
scene->setScriptPath(component, script_index, Path(old_value.c_str()));
scene->setScriptPath(entity, script_index, Path(old_value.c_str()));
}
else
{
scene->setPropertyValue(component, script_index, property_name.c_str(), old_value.c_str());
scene->setPropertyValue(entity, script_index, property_name.c_str(), old_value.c_str());
}
}
void serialize(JsonSerializer& serializer) override
{
serializer.serialize("component", component);
serializer.serialize("entity", entity);
serializer.serialize("script_index", script_index);
serializer.serialize("property_name", property_name.c_str());
serializer.serialize("value", value.c_str());
@ -289,7 +289,7 @@ struct PropertyGridPlugin LUMIX_FINAL : public PropertyGrid::IPlugin
void deserialize(JsonDeserializer& serializer) override
{
serializer.deserialize("component", component, INVALID_COMPONENT);
serializer.deserialize("entity", entity, INVALID_ENTITY);
serializer.deserialize("script_index", script_index, 0);
char buf[256];
serializer.deserialize("property_name", buf, lengthOf(buf), "");
@ -321,7 +321,7 @@ struct PropertyGridPlugin LUMIX_FINAL : public PropertyGrid::IPlugin
string property_name;
string value;
string old_value;
ComponentHandle component;
Entity entity;
int script_index;
};
@ -343,23 +343,23 @@ struct PropertyGridPlugin LUMIX_FINAL : public PropertyGrid::IPlugin
if (ImGui::Button("Add script"))
{
auto* cmd = LUMIX_NEW(allocator, AddLuaScriptCommand)(editor);
cmd->cmp = cmp.handle;
cmd->entity = cmp.entity;
editor.executeCommand(cmd);
}
for (int j = 0; j < scene->getScriptCount(cmp.handle); ++j)
for (int j = 0; j < scene->getScriptCount(cmp.entity); ++j)
{
char buf[MAX_PATH_LENGTH];
copyString(buf, scene->getScriptPath(cmp.handle, j).c_str());
copyString(buf, scene->getScriptPath(cmp.entity, j).c_str());
StaticString<MAX_PATH_LENGTH + 20> header;
PathUtils::getBasename(header.data, lengthOf(header.data), buf);
if (header.empty()) header << j;
ImGui::Unindent();
bool open = ImGui::TreeNodeEx(StaticString<32>("###", j), ImGuiTreeNodeFlags_AllowOverlapMode);
bool enabled = scene->isScriptEnabled(cmp.handle, j);
bool enabled = scene->isScriptEnabled(cmp.entity, j);
ImGui::SameLine();
if (ImGui::Checkbox(header, &enabled))
{
scene->enableScript(cmp.handle, j, enabled);
scene->enableScript(cmp.entity, j, enabled);
}
if (open)
@ -367,7 +367,7 @@ struct PropertyGridPlugin LUMIX_FINAL : public PropertyGrid::IPlugin
if (ImGui::Button("Remove script"))
{
auto* cmd = LUMIX_NEW(allocator, RemoveScriptCommand)(allocator);
cmd->cmp = cmp.handle;
cmd->entity = cmp.entity;
cmd->scr_index = j;
cmd->scene = scene;
editor.executeCommand(cmd);
@ -379,7 +379,7 @@ struct PropertyGridPlugin LUMIX_FINAL : public PropertyGrid::IPlugin
if (ImGui::Button("Up"))
{
auto* cmd = LUMIX_NEW(allocator, MoveScriptCommand)(allocator);
cmd->cmp = cmp.handle;
cmd->entity = cmp.entity;
cmd->scr_index = j;
cmd->scene = scene;
cmd->up = true;
@ -392,7 +392,7 @@ struct PropertyGridPlugin LUMIX_FINAL : public PropertyGrid::IPlugin
if (ImGui::Button("Down"))
{
auto* cmd = LUMIX_NEW(allocator, MoveScriptCommand)(allocator);
cmd->cmp = cmp.handle;
cmd->entity = cmp.entity;
cmd->scr_index = j;
cmd->scene = scene;
cmd->up = false;
@ -405,16 +405,16 @@ struct PropertyGridPlugin LUMIX_FINAL : public PropertyGrid::IPlugin
if (m_app.getAssetBrowser().resourceInput(
"Source", "src", buf, lengthOf(buf), LuaScript::TYPE))
{
auto* cmd = LUMIX_NEW(allocator, SetPropertyCommand)(editor, cmp.handle, j, "-source", buf, allocator);
auto* cmd = LUMIX_NEW(allocator, SetPropertyCommand)(editor, cmp.entity, j, "-source", buf, allocator);
editor.executeCommand(cmd);
}
for (int k = 0, kc = scene->getPropertyCount(cmp.handle, j); k < kc; ++k)
for (int k = 0, kc = scene->getPropertyCount(cmp.entity, j); k < kc; ++k)
{
char buf[256];
const char* property_name = scene->getPropertyName(cmp.handle, j, k);
const char* property_name = scene->getPropertyName(cmp.entity, j, k);
if (!property_name) continue;
scene->getPropertyValue(cmp.handle, j, property_name, buf, lengthOf(buf));
switch (scene->getPropertyType(cmp.handle, j, k))
scene->getPropertyValue(cmp.entity, j, property_name, buf, lengthOf(buf));
switch (scene->getPropertyType(cmp.entity, j, k))
{
case LuaScriptScene::Property::BOOLEAN:
{
@ -422,7 +422,7 @@ struct PropertyGridPlugin LUMIX_FINAL : public PropertyGrid::IPlugin
if (ImGui::Checkbox(property_name, &b))
{
auto* cmd = LUMIX_NEW(allocator, SetPropertyCommand)(
editor, cmp.handle, j, property_name, b ? "true" : "false", allocator);
editor, cmp.entity, j, property_name, b ? "true" : "false", allocator);
editor.executeCommand(cmd);
}
}
@ -434,7 +434,7 @@ struct PropertyGridPlugin LUMIX_FINAL : public PropertyGrid::IPlugin
{
toCString(f, buf, sizeof(buf), 5);
auto* cmd = LUMIX_NEW(allocator, SetPropertyCommand)(
editor, cmp.handle, j, property_name, buf, allocator);
editor, cmp.entity, j, property_name, buf, allocator);
editor.executeCommand(cmd);
}
}
@ -443,11 +443,11 @@ struct PropertyGridPlugin LUMIX_FINAL : public PropertyGrid::IPlugin
{
Entity e;
fromCString(buf, sizeof(buf), &e.index);
if (grid.entityInput(property_name, StaticString<50>(property_name, cmp.handle.index), e))
if (grid.entityInput(property_name, StaticString<50>(property_name, cmp.entity.index), e))
{
toCString(e.index, buf, sizeof(buf));
auto* cmd = LUMIX_NEW(allocator, SetPropertyCommand)(
editor, cmp.handle, j, property_name, buf, allocator);
editor, cmp.entity, j, property_name, buf, allocator);
editor.executeCommand(cmd);
}
}
@ -457,18 +457,18 @@ struct PropertyGridPlugin LUMIX_FINAL : public PropertyGrid::IPlugin
if (ImGui::InputText(property_name, buf, sizeof(buf)))
{
auto* cmd = LUMIX_NEW(allocator, SetPropertyCommand)(
editor, cmp.handle, j, property_name, buf, allocator);
editor, cmp.entity, j, property_name, buf, allocator);
editor.executeCommand(cmd);
}
break;
case LuaScriptScene::Property::RESOURCE:
{
ResourceType res_type = scene->getPropertyResourceType(cmp.handle, j, k);
ResourceType res_type = scene->getPropertyResourceType(cmp.entity, j, k);
if (m_app.getAssetBrowser().resourceInput(
property_name, property_name, buf, lengthOf(buf), res_type))
{
auto* cmd = LUMIX_NEW(allocator, SetPropertyCommand)(
editor, cmp.handle, j, property_name, buf, allocator);
editor, cmp.entity, j, property_name, buf, allocator);
editor.executeCommand(cmd);
}
}
@ -476,7 +476,7 @@ struct PropertyGridPlugin LUMIX_FINAL : public PropertyGrid::IPlugin
default: ASSERT(false); break;
}
}
if (scene->beginFunctionCall(cmp.handle, j, "onGUI"))
if (scene->beginFunctionCall(cmp.entity, j, "onGUI"))
{
scene->endFunctionCall();
}
@ -862,15 +862,14 @@ struct AddComponentPlugin LUMIX_FINAL : public StudioApp::IAddComponentPlugin
auto* cmd = LUMIX_NEW(allocator, PropertyGridPlugin::AddLuaScriptCommand)(editor);
auto* script_scene = static_cast<LuaScriptScene*>(editor.getUniverse()->getScene(LUA_SCRIPT_TYPE));
ComponentHandle cmp = editor.getUniverse()->getComponent(entity, LUA_SCRIPT_TYPE).handle;
cmd->cmp = cmp;
cmd->entity = entity;
editor.executeCommand(cmd);
if (!create_empty)
{
int scr_count = script_scene->getScriptCount(cmp);
int scr_count = script_scene->getScriptCount(entity);
auto* set_source_cmd = LUMIX_NEW(allocator, PropertyGridPlugin::SetPropertyCommand)(
editor, cmp, scr_count - 1, "-source", buf, allocator);
editor, entity, scr_count - 1, "-source", buf, allocator);
editor.executeCommand(set_source_cmd);
}
@ -903,10 +902,10 @@ struct EditorPlugin : public WorldEditor::Plugin
if (cmp.type == LUA_SCRIPT_TYPE)
{
auto* scene = static_cast<LuaScriptScene*>(cmp.scene);
int count = scene->getScriptCount(cmp.handle);
int count = scene->getScriptCount(cmp.entity);
for (int i = 0; i < count; ++i)
{
if (scene->beginFunctionCall(cmp.handle, i, "onDrawGizmo"))
if (scene->beginFunctionCall(cmp.entity, i, "onDrawGizmo"))
{
scene->endFunctionCall();
}

View file

@ -335,18 +335,11 @@ namespace Lumix
int getVersion() const override { return (int)LuaSceneVersion::LATEST; }
ComponentHandle getComponent(Entity entity) override
{
if (m_scripts.find(entity) == m_scripts.end()) return INVALID_COMPONENT;
return {entity.index};
}
IFunctionCall* beginFunctionCall(ComponentHandle cmp, int scr_index, const char* function) override
IFunctionCall* beginFunctionCall(Entity entity, int scr_index, const char* function) override
{
ASSERT(!m_function_call.is_in_progress);
auto* script_cmp = m_scripts[{cmp.index}];
auto* script_cmp = m_scripts[entity];
auto& script = script_cmp->m_scripts[scr_index];
if (!script.m_state) return nullptr;
@ -386,33 +379,33 @@ namespace Lumix
}
int getPropertyCount(ComponentHandle cmp, int scr_index) override
int getPropertyCount(Entity entity, int scr_index) override
{
return m_scripts[{cmp.index}]->m_scripts[scr_index].m_properties.size();
return m_scripts[entity]->m_scripts[scr_index].m_properties.size();
}
const char* getPropertyName(ComponentHandle cmp, int scr_index, int prop_index) override
const char* getPropertyName(Entity entity, int scr_index, int prop_index) override
{
return getPropertyName(m_scripts[{cmp.index}]->m_scripts[scr_index].m_properties[prop_index].name_hash);
return getPropertyName(m_scripts[entity]->m_scripts[scr_index].m_properties[prop_index].name_hash);
}
ResourceType getPropertyResourceType(ComponentHandle cmp, int scr_index, int prop_index) override
ResourceType getPropertyResourceType(Entity entity, int scr_index, int prop_index) override
{
return m_scripts[{cmp.index}]->m_scripts[scr_index].m_properties[prop_index].resource_type;
return m_scripts[entity]->m_scripts[scr_index].m_properties[prop_index].resource_type;
}
Property::Type getPropertyType(ComponentHandle cmp, int scr_index, int prop_index) override
Property::Type getPropertyType(Entity entity, int scr_index, int prop_index) override
{
return m_scripts[{cmp.index}]->m_scripts[scr_index].m_properties[prop_index].type;
return m_scripts[entity]->m_scripts[scr_index].m_properties[prop_index].type;
}
void getScriptData(ComponentHandle cmp, OutputBlob& blob) override
void getScriptData(Entity entity, OutputBlob& blob) override
{
auto* scr = m_scripts[{cmp.index}];
auto* scr = m_scripts[entity];
blob.write(scr->m_scripts.size());
for (int i = 0; i < scr->m_scripts.size(); ++i)
{
@ -427,26 +420,26 @@ namespace Lumix
char tmp[1024];
tmp[0] = '\0';
const char* prop_name = getPropertyName(prop.name_hash);
if(prop_name) getPropertyValue(cmp, i, getPropertyName(prop.name_hash), tmp, lengthOf(tmp));
if(prop_name) getPropertyValue(entity, i, getPropertyName(prop.name_hash), tmp, lengthOf(tmp));
blob.writeString(prop_name ? tmp : prop.stored_value.c_str());
}
}
}
void setScriptData(ComponentHandle cmp, InputBlob& blob) override
void setScriptData(Entity entity, InputBlob& blob) override
{
auto* scr = m_scripts[{cmp.index}];
auto* scr = m_scripts[entity];
int count;
blob.read(count);
for (int i = 0; i < count; ++i)
{
int idx = addScript(cmp);
int idx = addScript(entity);
auto& inst = scr->m_scripts[idx];
char tmp[MAX_PATH_LENGTH];
blob.readString(tmp, lengthOf(tmp));
blob.read(inst.m_flags);
setScriptPath(cmp, idx, Path(tmp));
setScriptPath(entity, idx, Path(tmp));
int prop_count;
blob.read(prop_count);
@ -489,9 +482,9 @@ namespace Lumix
}
lua_State* getState(ComponentHandle cmp, int scr_index) override
lua_State* getState(Entity entity, int scr_index) override
{
return m_scripts[{cmp.index}]->m_scripts[scr_index].m_state;
return m_scripts[entity]->m_scripts[scr_index].m_state;
}
@ -552,20 +545,19 @@ namespace Lumix
Entity entity = LuaWrapper::checkArg<Entity>(L, 2);
int scr_index = LuaWrapper::checkArg<int>(L, 3);
ComponentHandle cmp = scene->getComponent(entity);
if (cmp == INVALID_COMPONENT)
if (!scene->getUniverse().hasComponent(entity, LUA_SCRIPT_TYPE))
{
lua_pushnil(L);
return 1;
}
int count = scene->getScriptCount(cmp);
int count = scene->getScriptCount(entity);
if (scr_index >= count)
{
lua_pushnil(L);
return 1;
}
int env = scene->getEnvironment(cmp, scr_index);
int env = scene->getEnvironment(entity, scr_index);
if (env < 0)
{
lua_pushnil(L);
@ -633,8 +625,7 @@ namespace Lumix
visitor.L = L;
visitor.cmp.type = { LuaWrapper::toType<int>(L, lua_upvalueindex(2)) };
visitor.cmp.scene = LuaWrapper::checkArg<IScene*>(L, 1);
visitor.cmp.handle = LuaWrapper::checkArg<ComponentHandle>(L, 2);
visitor.cmp.entity = INVALID_ENTITY;
visitor.cmp.entity = LuaWrapper::checkArg<Entity>(L, 2);
visitor.visit(*prop);
return 1;
}
@ -691,9 +682,8 @@ namespace Lumix
SetPropertyVisitor visitor;
visitor.L = L;
visitor.cmp.scene = LuaWrapper::checkArg<IScene*>(L, 1);
visitor.cmp.handle = LuaWrapper::checkArg<ComponentHandle>(L, 2);
visitor.cmp.type = type;
visitor.cmp.entity = INVALID_ENTITY;
visitor.cmp.entity = LuaWrapper::checkArg<Entity>(L, 2);
visitor.visit(*prop);
return 0;
@ -828,9 +818,9 @@ namespace Lumix
}
void setScriptSource(ComponentHandle cmp, int scr_index, const char* path)
void setScriptSource(Entity entity, int scr_index, const char* path)
{
setScriptPath(cmp, scr_index, Path(path));
setScriptPath(entity, scr_index, Path(path));
}
@ -866,9 +856,9 @@ namespace Lumix
}
int getEnvironment(ComponentHandle cmp, int scr_index) override
int getEnvironment(Entity entity, int scr_index) override
{
return m_scripts[{cmp.index}]->m_scripts[scr_index].m_environment;
return m_scripts[entity]->m_scripts[scr_index].m_environment;
}
@ -936,14 +926,14 @@ namespace Lumix
}
void setPropertyValue(ComponentHandle cmp,
void setPropertyValue(Entity entity,
int scr_index,
const char* name,
const char* value) override
{
auto* script_cmp = m_scripts[{cmp.index}];
auto* script_cmp = m_scripts[entity];
if (!script_cmp) return;
Property& prop = getScriptProperty(cmp, scr_index, name);
Property& prop = getScriptProperty(entity, scr_index, name);
if (!script_cmp->m_scripts[scr_index].m_state)
{
prop.stored_value = value;
@ -954,17 +944,17 @@ namespace Lumix
}
const char* getPropertyName(ComponentHandle cmp, int scr_index, int index) const
const char* getPropertyName(Entity entity, int scr_index, int index) const
{
auto& script = m_scripts[{cmp.index}]->m_scripts[scr_index];
auto& script = m_scripts[entity]->m_scripts[scr_index];
return getPropertyName(script.m_properties[index].name_hash);
}
int getPropertyCount(ComponentHandle cmp, int scr_index) const
int getPropertyCount(Entity entity, int scr_index) const
{
auto& script = m_scripts[{cmp.index}]->m_scripts[scr_index];
auto& script = m_scripts[entity]->m_scripts[scr_index];
return script.m_properties.size();
}
@ -1129,21 +1119,18 @@ namespace Lumix
}
ComponentHandle createLuaScriptComponent(Entity entity)
void createLuaScriptComponent(Entity entity)
{
auto& allocator = m_system.m_allocator;
ScriptComponent* script = LUMIX_NEW(allocator, ScriptComponent)(*this, allocator);
ComponentHandle cmp = {entity.index};
script->m_entity = entity;
m_scripts.insert(entity, script);
m_universe.onComponentCreated(entity, LUA_SCRIPT_TYPE, this, cmp);
return cmp;
m_universe.onComponentCreated(entity, LUA_SCRIPT_TYPE, this);
}
void destroyLuaScriptComponent(ComponentHandle component)
void destroyLuaScriptComponent(Entity entity)
{
Entity entity = {component.index};
auto* script = m_scripts[entity];
for (auto& scr : script->m_scripts)
{
@ -1157,11 +1144,11 @@ namespace Lumix
}
LUMIX_DELETE(m_system.m_allocator, script);
m_scripts.erase(entity);
m_universe.onComponentDestroyed(entity, LUA_SCRIPT_TYPE, this, component);
m_universe.onComponentDestroyed(entity, LUA_SCRIPT_TYPE, this);
}
void getPropertyValue(ComponentHandle cmp,
void getPropertyValue(Entity entity,
int scr_index,
const char* property_name,
char* out,
@ -1170,7 +1157,7 @@ namespace Lumix
ASSERT(max_size > 0);
u32 hash = crc32(property_name);
auto& inst = m_scripts[{cmp.index}]->m_scripts[scr_index];
auto& inst = m_scripts[entity]->m_scripts[scr_index];
for (auto& prop : inst.m_properties)
{
if (prop.name_hash == hash)
@ -1241,9 +1228,9 @@ namespace Lumix
}
void serializeLuaScript(ISerializer& serializer, ComponentHandle cmp)
void serializeLuaScript(ISerializer& serializer, Entity entity)
{
ScriptComponent* script = m_scripts[{cmp.index}];
ScriptComponent* script = m_scripts[entity];
serializer.write("count", script->m_scripts.size());
for (ScriptInstance& inst : script->m_scripts)
{
@ -1296,7 +1283,6 @@ namespace Lumix
{
auto& allocator = m_system.m_allocator;
ScriptComponent* script = LUMIX_NEW(allocator, ScriptComponent)(*this, allocator);
ComponentHandle cmp = {entity.index};
script->m_entity = entity;
m_scripts.insert(entity, script);
@ -1308,7 +1294,7 @@ namespace Lumix
ScriptInstance& inst = script->m_scripts.emplace(allocator);
char tmp[MAX_PATH_LENGTH];
serializer.read(tmp, lengthOf(tmp));
setScriptPath(cmp, i, Path(tmp));
setScriptPath(entity, i, Path(tmp));
if(scene_version >(int)LuaSceneVersion::FLAGS)
serializer.read(&inst.m_flags.base);
@ -1351,7 +1337,7 @@ namespace Lumix
}
}
m_universe.onComponentCreated(entity, LUA_SCRIPT_TYPE, this, cmp);
m_universe.onComponentCreated(entity, LUA_SCRIPT_TYPE, this);
}
@ -1425,8 +1411,7 @@ namespace Lumix
}
setScriptPath(*script, scr, Path(tmp));
}
ComponentHandle cmp = {script->m_entity.index};
m_universe.onComponentCreated(script->m_entity, LUA_SCRIPT_TYPE, this, cmp);
m_universe.onComponentCreated(script->m_entity, LUA_SCRIPT_TYPE, this);
}
}
@ -1617,17 +1602,10 @@ namespace Lumix
}
ComponentHandle getComponent(Entity entity, ComponentType type) override
{
if (m_scripts.find(entity) == m_scripts.end()) return INVALID_COMPONENT;
return {entity.index};
}
Property& getScriptProperty(ComponentHandle cmp, int scr_index, const char* name)
Property& getScriptProperty(Entity entity, int scr_index, const char* name)
{
u32 name_hash = crc32(name);
ScriptComponent* script_cmp = m_scripts[{cmp.index}];
ScriptComponent* script_cmp = m_scripts[entity];
for (auto& prop : script_cmp->m_scripts[scr_index].m_properties)
{
if (prop.name_hash == name_hash)
@ -1643,44 +1621,44 @@ namespace Lumix
}
Path getScriptPath(ComponentHandle cmp, int scr_index) override
Path getScriptPath(Entity entity, int scr_index) override
{
auto& tmp = m_scripts[{cmp.index}]->m_scripts[scr_index];
auto& tmp = m_scripts[entity]->m_scripts[scr_index];
return tmp.m_script ? tmp.m_script->getPath() : Path("");
}
void setScriptPath(ComponentHandle cmp, int scr_index, const Path& path) override
void setScriptPath(Entity entity, int scr_index, const Path& path) override
{
auto* script_cmp = m_scripts[{cmp.index}];
auto* script_cmp = m_scripts[entity];
if (script_cmp->m_scripts.size() <= scr_index) return;
setScriptPath(*script_cmp, script_cmp->m_scripts[scr_index], path);
}
int getScriptCount(ComponentHandle cmp) override
int getScriptCount(Entity entity) override
{
return m_scripts[{cmp.index}]->m_scripts.size();
return m_scripts[entity]->m_scripts.size();
}
void insertScript(ComponentHandle cmp, int idx) override
void insertScript(Entity entity, int idx) override
{
m_scripts[{cmp.index}]->m_scripts.emplaceAt(idx, m_system.m_allocator);
m_scripts[entity]->m_scripts.emplaceAt(idx, m_system.m_allocator);
}
int addScript(ComponentHandle cmp) override
int addScript(Entity entity) override
{
ScriptComponent* script_cmp = m_scripts[{cmp.index}];
ScriptComponent* script_cmp = m_scripts[entity];
script_cmp->m_scripts.emplace(m_system.m_allocator);
return script_cmp->m_scripts.size() - 1;
}
void moveScript(ComponentHandle cmp, int scr_index, bool up) override
void moveScript(Entity entity, int scr_index, bool up) override
{
auto* script_cmp = m_scripts[{cmp.index}];
auto* script_cmp = m_scripts[entity];
if (!up && scr_index > script_cmp->m_scripts.size() - 2) return;
if (up && scr_index == 0) return;
int other = up ? scr_index - 1 : scr_index + 1;
@ -1690,9 +1668,9 @@ namespace Lumix
}
void enableScript(ComponentHandle cmp, int scr_index, bool enable) override
void enableScript(Entity entity, int scr_index, bool enable) override
{
ScriptInstance& inst = m_scripts[{cmp.index}]->m_scripts[scr_index];
ScriptInstance& inst = m_scripts[entity]->m_scripts[scr_index];
if (inst.m_flags.isSet(ScriptInstance::ENABLED) == enable) return;
inst.m_flags.set(ScriptInstance::ENABLED, enable);
@ -1707,22 +1685,22 @@ namespace Lumix
}
bool isScriptEnabled(ComponentHandle cmp, int scr_index) const override
bool isScriptEnabled(Entity entity, int scr_index) const override
{
return m_scripts[{cmp.index}]->m_scripts[scr_index].m_flags.isSet(ScriptInstance::ENABLED);
return m_scripts[entity]->m_scripts[scr_index].m_flags.isSet(ScriptInstance::ENABLED);
}
void removeScript(ComponentHandle cmp, int scr_index) override
void removeScript(Entity entity, int scr_index) override
{
setScriptPath(cmp, scr_index, Path());
m_scripts[{cmp.index}]->m_scripts.eraseFast(scr_index);
setScriptPath(entity, scr_index, Path());
m_scripts[entity]->m_scripts.eraseFast(scr_index);
}
void serializeScript(ComponentHandle cmp, int scr_index, OutputBlob& blob) override
void serializeScript(Entity entity, int scr_index, OutputBlob& blob) override
{
auto& scr = m_scripts[{cmp.index}]->m_scripts[scr_index];
auto& scr = m_scripts[entity]->m_scripts[scr_index];
blob.writeString(scr.m_script ? scr.m_script->getPath().c_str() : "");
blob.write(scr.m_flags);
blob.write(scr.m_properties.size());
@ -1744,9 +1722,9 @@ namespace Lumix
}
void deserializeScript(ComponentHandle cmp, int scr_index, InputBlob& blob) override
void deserializeScript(Entity entity, int scr_index, InputBlob& blob) override
{
auto& scr = m_scripts[{cmp.index}]->m_scripts[scr_index];
auto& scr = m_scripts[entity]->m_scripts[scr_index];
int count;
char path[MAX_PATH_LENGTH];
blob.readString(path, lengthOf(path));
@ -1763,7 +1741,7 @@ namespace Lumix
blob.readString(buf, lengthOf(buf));
prop.stored_value = buf;
}
setScriptPath(cmp, scr_index, Path(path));
setScriptPath(entity, scr_index, Path(path));
}

View file

@ -58,30 +58,29 @@ public:
typedef int (*lua_CFunction) (lua_State *L);
public:
virtual Path getScriptPath(ComponentHandle cmp, int scr_index) = 0;
virtual void setScriptPath(ComponentHandle cmp, int scr_index, const Path& path) = 0;
virtual ComponentHandle getComponent(Entity entity) = 0;
virtual int getEnvironment(ComponentHandle cmp, int scr_index) = 0;
virtual IFunctionCall* beginFunctionCall(ComponentHandle cmp, int scr_index, const char* function) = 0;
virtual Path getScriptPath(Entity entity, int scr_index) = 0;
virtual void setScriptPath(Entity entity, int scr_index, const Path& path) = 0;
virtual int getEnvironment(Entity entity, int scr_index) = 0;
virtual IFunctionCall* beginFunctionCall(Entity entity, int scr_index, const char* function) = 0;
virtual void endFunctionCall() = 0;
virtual int getScriptCount(ComponentHandle cmp) = 0;
virtual lua_State* getState(ComponentHandle cmp, int scr_index) = 0;
virtual void insertScript(ComponentHandle cmp, int idx) = 0;
virtual int addScript(ComponentHandle cmp) = 0;
virtual void removeScript(ComponentHandle cmp, int scr_index) = 0;
virtual void enableScript(ComponentHandle cmp, int scr_index, bool enable) = 0;
virtual bool isScriptEnabled(ComponentHandle cmp, int scr_index) const = 0;
virtual void moveScript(ComponentHandle cmp, int scr_index, bool up) = 0;
virtual void serializeScript(ComponentHandle cmp, int scr_index, OutputBlob& blob) = 0;
virtual void deserializeScript(ComponentHandle cmp, int scr_index, InputBlob& blob) = 0;
virtual void setPropertyValue(ComponentHandle cmp, int scr_index, const char* name, const char* value) = 0;
virtual void getPropertyValue(ComponentHandle cmp, int scr_index, const char* property_name, char* out, int max_size) = 0;
virtual int getPropertyCount(ComponentHandle cmp, int scr_index) = 0;
virtual const char* getPropertyName(ComponentHandle cmp, int scr_index, int prop_index) = 0;
virtual Property::Type getPropertyType(ComponentHandle cmp, int scr_index, int prop_index) = 0;
virtual ResourceType getPropertyResourceType(ComponentHandle cmp, int scr_index, int prop_index) = 0;
virtual void getScriptData(ComponentHandle cmp, OutputBlob& blob) = 0;
virtual void setScriptData(ComponentHandle cmp, InputBlob& blob) = 0;
virtual int getScriptCount(Entity entity) = 0;
virtual lua_State* getState(Entity entity, int scr_index) = 0;
virtual void insertScript(Entity entity, int idx) = 0;
virtual int addScript(Entity entity) = 0;
virtual void removeScript(Entity entity, int scr_index) = 0;
virtual void enableScript(Entity entity, int scr_index, bool enable) = 0;
virtual bool isScriptEnabled(Entity entity, int scr_index) const = 0;
virtual void moveScript(Entity entity, int scr_index, bool up) = 0;
virtual void serializeScript(Entity entity, int scr_index, OutputBlob& blob) = 0;
virtual void deserializeScript(Entity entity, int scr_index, InputBlob& blob) = 0;
virtual void setPropertyValue(Entity entity, int scr_index, const char* name, const char* value) = 0;
virtual void getPropertyValue(Entity entity, int scr_index, const char* property_name, char* out, int max_size) = 0;
virtual int getPropertyCount(Entity entity, int scr_index) = 0;
virtual const char* getPropertyName(Entity entity, int scr_index, int prop_index) = 0;
virtual Property::Type getPropertyType(Entity entity, int scr_index, int prop_index) = 0;
virtual ResourceType getPropertyResourceType(Entity entity, int scr_index, int prop_index) = 0;
virtual void getScriptData(Entity entity, OutputBlob& blob) = 0;
virtual void setScriptData(Entity entity, InputBlob& blob) = 0;
};

View file

@ -40,6 +40,7 @@ enum class NavigationSceneVersion : int
};
static const ComponentType LUA_SCRIPT_TYPE = Reflection::getComponentType("lua_script");
static const ComponentType NAVMESH_AGENT_TYPE = Reflection::getComponentType("navmesh_agent");
static const ComponentType ANIM_CONTROLLER_TYPE = Reflection::getComponentType("anim_controller");
static const int CELLS_PER_TILE_SIDE = 256;
@ -181,14 +182,13 @@ struct NavigationSceneImpl LUMIX_FINAL : public NavigationScene
auto render_scene = static_cast<RenderScene*>(m_universe.getScene(crc32("renderer")));
if (!render_scene) return;
ComponentHandle cmp = render_scene->getFirstTerrain();
while (cmp != INVALID_COMPONENT)
Entity entity = render_scene->getFirstTerrain();
while (entity.isValid())
{
Entity entity = render_scene->getTerrainEntity(cmp);
Vec3 pos = m_universe.getPosition(entity);
Quat rot = m_universe.getRotation(entity);
Vec2 res = render_scene->getTerrainResolution(cmp);
float scaleXZ = render_scene->getTerrainXZScale(cmp);
Vec2 res = render_scene->getTerrainResolution(entity);
float scaleXZ = render_scene->getTerrainXZScale(entity);
AABB terrain_space_aabb = getTerrainSpaceAABB(pos, rot, aabb);
int from_z = (int)Math::clamp(terrain_space_aabb.min.z / scaleXZ - 1, 0.0f, res.y - 1);
int to_z = (int)Math::clamp(terrain_space_aabb.max.z / scaleXZ + 1, 0.0f, res.y - 1);
@ -200,22 +200,22 @@ struct NavigationSceneImpl LUMIX_FINAL : public NavigationScene
{
float x = i * scaleXZ;
float z = j * scaleXZ;
float h0 = render_scene->getTerrainHeightAt(cmp, x, z);
float h0 = render_scene->getTerrainHeightAt(entity, x, z);
Vec3 p0 = pos + rot.rotate(Vec3(x, h0, z));
x = (i + 1) * scaleXZ;
z = j * scaleXZ;
float h1 = render_scene->getTerrainHeightAt(cmp, x, z);
float h1 = render_scene->getTerrainHeightAt(entity, x, z);
Vec3 p1 = pos + rot.rotate(Vec3(x, h1, z));
x = (i + 1) * scaleXZ;
z = (j + 1) * scaleXZ;
float h2 = render_scene->getTerrainHeightAt(cmp, x, z);
float h2 = render_scene->getTerrainHeightAt(entity, x, z);
Vec3 p2 = pos + rot.rotate(Vec3(x, h2, z));
x = i * scaleXZ;
z = (j + 1) * scaleXZ;
float h3 = render_scene->getTerrainHeightAt(cmp, x, z);
float h3 = render_scene->getTerrainHeightAt(entity, x, z);
Vec3 p3 = pos + rot.rotate(Vec3(x, h3, z));
Vec3 n = crossProduct(p1 - p0, p0 - p2).normalized();
@ -228,7 +228,7 @@ struct NavigationSceneImpl LUMIX_FINAL : public NavigationScene
}
}
cmp = render_scene->getNextTerrain(cmp);
entity = render_scene->getNextTerrain(entity);
}
}
@ -243,14 +243,14 @@ struct NavigationSceneImpl LUMIX_FINAL : public NavigationScene
u32 no_navigation_flag = Material::getCustomFlag("no_navigation");
u32 nonwalkable_flag = Material::getCustomFlag("nonwalkable");
for (auto model_instance = render_scene->getFirstModelInstance(); model_instance != INVALID_COMPONENT;
for (Entity model_instance = render_scene->getFirstModelInstance(); model_instance.isValid();
model_instance = render_scene->getNextModelInstance(model_instance))
{
auto* model = render_scene->getModelInstanceModel(model_instance);
if (!model) return;
ASSERT(model->isReady());
Entity entity = render_scene->getModelInstanceEntity(model_instance);
Entity entity = model_instance;
Matrix mtx = m_universe.getMatrix(entity);
AABB model_aabb = model->getAABB();
model_aabb.transform(mtx);
@ -302,12 +302,11 @@ struct NavigationSceneImpl LUMIX_FINAL : public NavigationScene
{
if (!m_script_scene) return;
auto cmp = m_script_scene->getComponent(agent.entity);
if (cmp == INVALID_COMPONENT) return;
if (!m_universe.hasComponent(agent.entity, LUA_SCRIPT_TYPE)) return;
for (int i = 0, c = m_script_scene->getScriptCount(cmp); i < c; ++i)
for (int i = 0, c = m_script_scene->getScriptCount(agent.entity); i < c; ++i)
{
auto* call = m_script_scene->beginFunctionCall(cmp, i, "onPathFinished");
auto* call = m_script_scene->beginFunctionCall(agent.entity, i, "onPathFinished");
if (!call) continue;
m_script_scene->endFunctionCall();
@ -315,27 +314,27 @@ struct NavigationSceneImpl LUMIX_FINAL : public NavigationScene
}
bool isFinished(ComponentHandle cmp) override
bool isFinished(Entity entity) override
{
return m_agents[{cmp.index}].is_finished;
return m_agents[entity].is_finished;
}
float getAgentSpeed(ComponentHandle cmp) override
float getAgentSpeed(Entity entity) override
{
return m_agents[{cmp.index}].speed;
return m_agents[entity].speed;
}
float getAgentYawDiff(ComponentHandle cmp) override
float getAgentYawDiff(Entity entity) override
{
return m_agents[{cmp.index}].yaw_diff;
return m_agents[entity].yaw_diff;
}
void setAgentRootMotion(ComponentHandle cmp, const Vec3& root_motion) override
void setAgentRootMotion(Entity entity, const Vec3& root_motion) override
{
m_agents[{cmp.index}].root_motion = root_motion;
m_agents[entity].root_motion = root_motion;
}
@ -389,10 +388,12 @@ struct NavigationSceneImpl LUMIX_FINAL : public NavigationScene
Quat rot = m_universe.getRotation(agent.entity);
if (agent.flags & Agent::GET_ROOT_MOTION_FROM_ANIM_CONTROLLER && anim_scene)
{
ComponentHandle ctrl = anim_scene->getComponent(agent.entity, ANIM_CONTROLLER_TYPE);
RigidTransform root_motion = anim_scene->getControllerRootMotion(ctrl);
agent.root_motion = root_motion.pos;
//m_universe.setRotation(agent.entity, m_universe.getRotation(agent.entity) * root_motion.rot);
if (anim_scene->getUniverse().hasComponent(agent.entity, ANIM_CONTROLLER_TYPE))
{
RigidTransform root_motion = anim_scene->getControllerRootMotion(agent.entity);
agent.root_motion = root_motion.pos;
//m_universe.setRotation(agent.entity, m_universe.getRotation(agent.entity) * root_motion.rot);
}
}
if (agent.flags & Agent::USE_ROOT_MOTION)
{
@ -429,9 +430,11 @@ struct NavigationSceneImpl LUMIX_FINAL : public NavigationScene
}
else if (agent.flags & Agent::GET_ROOT_MOTION_FROM_ANIM_CONTROLLER && anim_scene)
{
ComponentHandle ctrl = anim_scene->getComponent(agent.entity, ANIM_CONTROLLER_TYPE);
RigidTransform root_motion = anim_scene->getControllerRootMotion(ctrl);
m_universe.setRotation(agent.entity, m_universe.getRotation(agent.entity) * root_motion.rot);
if (anim_scene->getUniverse().hasComponent(agent.entity, ANIM_CONTROLLER_TYPE))
{
RigidTransform root_motion = anim_scene->getControllerRootMotion(agent.entity);
m_universe.setRotation(agent.entity, m_universe.getRotation(agent.entity) * root_motion.rot);
}
}
if (dt_agent->ncorners == 0 && dt_agent->targetState != DT_CROWDAGENT_TARGET_REQUESTING)
@ -519,11 +522,11 @@ struct NavigationSceneImpl LUMIX_FINAL : public NavigationScene
}
const dtCrowdAgent* getDetourAgent(ComponentHandle cmp) override
const dtCrowdAgent* getDetourAgent(Entity entity) override
{
if (!m_crowd) return nullptr;
auto iter = m_agents.find({cmp.index});
auto iter = m_agents.find(entity);
if (iter == m_agents.end()) return nullptr;
const Agent& agent = iter.value();
@ -532,13 +535,13 @@ struct NavigationSceneImpl LUMIX_FINAL : public NavigationScene
}
void debugDrawPath(ComponentHandle cmp) override
void debugDrawPath(Entity entity) override
{
auto render_scene = static_cast<RenderScene*>(m_universe.getScene(crc32("renderer")));
if (!render_scene) return;
if (!m_crowd) return;
auto iter = m_agents.find({cmp.index});
auto iter = m_agents.find(entity);
if (iter == m_agents.end()) return;
const Agent& agent = iter.value();
if (agent.agent < 0) return;
@ -565,7 +568,7 @@ struct NavigationSceneImpl LUMIX_FINAL : public NavigationScene
}
render_scene->addDebugCross(*(Vec3*)dt_agent->targetPos, 1.0f, 0xffffffff, 0);
Vec3 vel = *(Vec3*)dt_agent->vel;
Vec3 pos = m_universe.getPosition({cmp.index});
Vec3 pos = m_universe.getPosition(entity);
render_scene->addDebugLine(pos, pos + vel, 0xff0000ff, 0);
}
@ -965,9 +968,8 @@ struct NavigationSceneImpl LUMIX_FINAL : public NavigationScene
}
void cancelNavigation(ComponentHandle cmp) override
void cancelNavigation(Entity entity) override
{
Entity entity = {cmp.index};
auto iter = m_agents.find(entity);
if (iter == m_agents.end()) return;
@ -978,12 +980,12 @@ struct NavigationSceneImpl LUMIX_FINAL : public NavigationScene
}
void setActorActive(ComponentHandle cmp, bool active) override
void setActorActive(Entity entity, bool active) override
{
if (!m_crowd) return;
if (!cmp.isValid()) return;
if (!entity.isValid()) return;
auto iter = m_agents.find({cmp.index});
auto iter = m_agents.find(entity);
if (iter == m_agents.end()) return;
Agent& agent = iter.value();
@ -994,9 +996,8 @@ struct NavigationSceneImpl LUMIX_FINAL : public NavigationScene
}
bool navigate(ComponentHandle cmp, const Vec3& dest, float speed, float stop_distance) override
bool navigate(Entity entity, const Vec3& dest, float speed, float stop_distance) override
{
Entity entity = {cmp.index};
if (!m_navquery) return false;
if (!m_crowd) return false;
if (entity == INVALID_ENTITY) return false;
@ -1234,7 +1235,7 @@ struct NavigationSceneImpl LUMIX_FINAL : public NavigationScene
auto* render_scene = static_cast<RenderScene*>(m_universe.getScene(crc32("renderer")));
if (!render_scene) return;
for (auto model_instance = render_scene->getFirstModelInstance(); model_instance != INVALID_COMPONENT;
for (Entity model_instance = render_scene->getFirstModelInstance(); model_instance.isValid();
model_instance = render_scene->getNextModelInstance(model_instance))
{
auto* model = render_scene->getModelInstanceModel(model_instance);
@ -1242,20 +1243,20 @@ struct NavigationSceneImpl LUMIX_FINAL : public NavigationScene
ASSERT(model->isReady());
AABB model_bb = model->getAABB();
Matrix mtx = m_universe.getMatrix(render_scene->getModelInstanceEntity(model_instance));
Matrix mtx = m_universe.getMatrix(model_instance);
model_bb.transform(mtx);
m_aabb.merge(model_bb);
}
ComponentHandle cmp = render_scene->getFirstTerrain();
while (cmp != INVALID_COMPONENT)
Entity entity = render_scene->getFirstTerrain();
while (entity.isValid())
{
AABB terrain_aabb = render_scene->getTerrainAABB(cmp);
Matrix mtx = m_universe.getMatrix(render_scene->getTerrainEntity(cmp));
AABB terrain_aabb = render_scene->getTerrainAABB(entity);
Matrix mtx = m_universe.getMatrix(render_scene->getTerrainEntity(entity));
terrain_aabb.transform(mtx);
m_aabb.merge(terrain_aabb);
cmp = render_scene->getNextTerrain(cmp);
entity = render_scene->getNextTerrain(entity);
}
}
@ -1345,7 +1346,7 @@ struct NavigationSceneImpl LUMIX_FINAL : public NavigationScene
}
ComponentHandle createAgent(Entity entity)
void createAgent(Entity entity)
{
Agent agent;
agent.entity = entity;
@ -1356,29 +1357,26 @@ struct NavigationSceneImpl LUMIX_FINAL : public NavigationScene
agent.is_finished = true;
if (m_crowd) addCrowdAgent(agent);
m_agents.insert(entity, agent);
ComponentHandle cmp = {entity.index};
m_universe.onComponentCreated(entity, NAVMESH_AGENT_TYPE, this, cmp);
return cmp;
m_universe.onComponentCreated(entity, NAVMESH_AGENT_TYPE, this);
}
void destroyAgent(ComponentHandle component)
void destroyAgent(Entity entity)
{
Entity entity = { component.index };
auto iter = m_agents.find(entity);
const Agent& agent = iter.value();
if (m_crowd && agent.agent >= 0) m_crowd->removeAgent(agent.agent);
m_agents.erase(iter);
m_universe.onComponentDestroyed(entity, NAVMESH_AGENT_TYPE, this, component);
m_universe.onComponentDestroyed(entity, NAVMESH_AGENT_TYPE, this);
}
int getVersion() const override { return (int)NavigationSceneVersion::LATEST; }
void serializeAgent(ISerializer& serializer, ComponentHandle cmp)
void serializeAgent(ISerializer& serializer, Entity entity)
{
Agent& agent = m_agents[{cmp.index}];
Agent& agent = m_agents[entity];
serializer.write("radius", agent.radius);
serializer.write("height", agent.height);
serializer.write("use_root_motion", (agent.flags & Agent::USE_ROOT_MOTION) != 0);
@ -1410,8 +1408,8 @@ struct NavigationSceneImpl LUMIX_FINAL : public NavigationScene
agent.agent = -1;
if (m_crowd) addCrowdAgent(agent);
m_agents.insert(agent.entity, agent);
ComponentHandle cmp = {agent.entity.index};
m_universe.onComponentCreated(agent.entity, NAVMESH_AGENT_TYPE, this, cmp);
m_universe.onComponentCreated(agent.entity, NAVMESH_AGENT_TYPE, this);
}
@ -1444,22 +1442,20 @@ struct NavigationSceneImpl LUMIX_FINAL : public NavigationScene
agent.is_finished = true;
agent.agent = -1;
m_agents.insert(agent.entity, agent);
ComponentHandle cmp = {agent.entity.index};
m_universe.onComponentCreated(agent.entity, NAVMESH_AGENT_TYPE, this, cmp);
Entity entity = {agent.entity.index};
m_universe.onComponentCreated(agent.entity, NAVMESH_AGENT_TYPE, this);
}
}
bool isGettingRootMotionFromAnim(ComponentHandle cmp) override
bool isGettingRootMotionFromAnim(Entity entity) override
{
Entity entity = {cmp.index};
return (m_agents[entity].flags & Agent::GET_ROOT_MOTION_FROM_ANIM_CONTROLLER) != 0;
}
void setIsGettingRootMotionFromAnim(ComponentHandle cmp, bool is) override
void setIsGettingRootMotionFromAnim(Entity entity, bool is) override
{
Entity entity = {cmp.index};
if (is)
m_agents[entity].flags |= Agent::GET_ROOT_MOTION_FROM_ANIM_CONTROLLER;
else
@ -1467,16 +1463,14 @@ struct NavigationSceneImpl LUMIX_FINAL : public NavigationScene
}
bool useAgentRootMotion(ComponentHandle cmp) override
bool useAgentRootMotion(Entity entity) override
{
Entity entity = {cmp.index};
return (m_agents[entity].flags & Agent::USE_ROOT_MOTION) != 0;
}
void setUseAgentRootMotion(ComponentHandle cmp, bool use_root_motion) override
void setUseAgentRootMotion(Entity entity, bool use_root_motion) override
{
Entity entity = {cmp.index};
if (use_root_motion)
m_agents[entity].flags |= Agent::USE_ROOT_MOTION;
else
@ -1484,40 +1478,31 @@ struct NavigationSceneImpl LUMIX_FINAL : public NavigationScene
}
void setAgentRadius(ComponentHandle cmp, float radius) override
void setAgentRadius(Entity entity, float radius) override
{
Entity entity = {cmp.index};
m_agents[entity].radius = radius;
}
float getAgentRadius(ComponentHandle cmp) override
float getAgentRadius(Entity entity) override
{
Entity entity = { cmp.index };
return m_agents[entity].radius;
}
void setAgentHeight(ComponentHandle cmp, float height) override
void setAgentHeight(Entity entity, float height) override
{
Entity entity = { cmp.index };
m_agents[entity].height = height;
}
float getAgentHeight(ComponentHandle cmp) override
float getAgentHeight(Entity entity) override
{
Entity entity = {cmp.index};
return m_agents[entity].height;
}
IPlugin& getPlugin() const override { return m_system; }
ComponentHandle getComponent(Entity entity, ComponentType type) override
{
if (type == NAVMESH_AGENT_TYPE) return {entity.index};
return INVALID_COMPONENT;
}
Universe& getUniverse() override { return m_universe; }
IAllocator& m_allocator;

View file

@ -20,21 +20,21 @@ public:
static NavigationScene* create(Engine& engine, IPlugin& system, Universe& universe, IAllocator& allocator);
static void destroy(NavigationScene& scene);
virtual bool isFinished(ComponentHandle cmp) = 0;
virtual bool navigate(ComponentHandle cmp, const struct Vec3& dest, float speed, float stop_distance) = 0;
virtual void cancelNavigation(ComponentHandle cmp) = 0;
virtual void setActorActive(ComponentHandle cmp, bool active) = 0;
virtual float getAgentSpeed(ComponentHandle cmp) = 0;
virtual float getAgentYawDiff(ComponentHandle cmp) = 0;
virtual void setAgentRadius(ComponentHandle cmp, float radius) = 0;
virtual float getAgentRadius(ComponentHandle cmp) = 0;
virtual void setAgentHeight(ComponentHandle cmp, float height) = 0;
virtual float getAgentHeight(ComponentHandle cmp) = 0;
virtual void setAgentRootMotion(ComponentHandle cmp, const Vec3& root_motion) = 0;
virtual bool useAgentRootMotion(ComponentHandle cmp) = 0;
virtual void setUseAgentRootMotion(ComponentHandle cmp, bool use_root_motion) = 0;
virtual bool isGettingRootMotionFromAnim(ComponentHandle cmp) = 0;
virtual void setIsGettingRootMotionFromAnim(ComponentHandle cmp, bool is) = 0;
virtual bool isFinished(Entity entity) = 0;
virtual bool navigate(Entity entity, const struct Vec3& dest, float speed, float stop_distance) = 0;
virtual void cancelNavigation(Entity entity) = 0;
virtual void setActorActive(Entity entity, bool active) = 0;
virtual float getAgentSpeed(Entity entity) = 0;
virtual float getAgentYawDiff(Entity entity) = 0;
virtual void setAgentRadius(Entity entity, float radius) = 0;
virtual float getAgentRadius(Entity entity) = 0;
virtual void setAgentHeight(Entity entity, float height) = 0;
virtual float getAgentHeight(Entity entity) = 0;
virtual void setAgentRootMotion(Entity entity, const Vec3& root_motion) = 0;
virtual bool useAgentRootMotion(Entity entity) = 0;
virtual void setUseAgentRootMotion(Entity entity, bool use_root_motion) = 0;
virtual bool isGettingRootMotionFromAnim(Entity entity) = 0;
virtual void setIsGettingRootMotionFromAnim(Entity entity, bool is) = 0;
virtual bool generateNavmesh() = 0;
virtual bool generateTile(int x, int z, bool keep_data) = 0;
virtual bool generateTileAt(const Vec3& pos, bool keep_data) = 0;
@ -45,8 +45,8 @@ public:
virtual void debugDrawCompactHeightfield() = 0;
virtual void debugDrawHeightfield() = 0;
virtual void debugDrawContours() = 0;
virtual void debugDrawPath(ComponentHandle cmp) = 0;
virtual const dtCrowdAgent* getDetourAgent(ComponentHandle cmp) = 0;
virtual void debugDrawPath(Entity entity) = 0;
virtual const dtCrowdAgent* getDetourAgent(Entity entity) = 0;
virtual bool isNavmeshReady() const = 0;
virtual bool hasDebugDrawData() const = 0;
virtual DelegateList<void(float)>& onUpdate() = 0;

View file

@ -23,6 +23,7 @@ namespace
{
const ComponentType MODEL_INSTANCE_TYPE = Reflection::getComponentType("renderable");
const ComponentType RAGDOLL_TYPE = Reflection::getComponentType("ragdoll");
const ComponentType BOX_ACTOR_TYPE = Reflection::getComponentType("box_rigid_actor");
const ComponentType SPHERE_ACTOR_TYPE = Reflection::getComponentType("sphere_rigid_actor");
@ -154,11 +155,11 @@ struct EditorPlugin LUMIX_FINAL : public WorldEditor::Plugin
auto* render_scene = static_cast<RenderScene*>(universe.getScene(RENDERER_HASH));
if (!render_scene) return;
Entity other_entity = phy_scene->getJointConnectedBody(cmp.handle);
Entity other_entity = phy_scene->getJointConnectedBody(cmp.entity);
if (!other_entity.isValid()) return;
RigidTransform local_frame0 = phy_scene->getJointLocalFrame(cmp.handle);
RigidTransform local_frame0 = phy_scene->getJointLocalFrame(cmp.entity);
RigidTransform global_frame0 = universe.getTransform(cmp.entity).getRigidPart() * local_frame0;
Vec3 joint_pos = global_frame0.pos;
Matrix mtx0 = global_frame0.toMatrix();
@ -167,14 +168,14 @@ struct EditorPlugin LUMIX_FINAL : public WorldEditor::Plugin
render_scene->addDebugLine(joint_pos, joint_pos + mtx0.getYVector(), 0xff00ff00, 0);
render_scene->addDebugLine(joint_pos, joint_pos + mtx0.getZVector(), 0xff0000ff, 0);
RigidTransform local_frame1 = phy_scene->getJointConnectedBodyLocalFrame(cmp.handle);
RigidTransform local_frame1 = phy_scene->getJointConnectedBodyLocalFrame(cmp.entity);
RigidTransform global_frame1 = universe.getTransform(other_entity).getRigidPart() * local_frame1;
Matrix mtx1 = global_frame1.toMatrix();
bool use_limit = phy_scene->getSphericalJointUseLimit(cmp.handle);
bool use_limit = phy_scene->getSphericalJointUseLimit(cmp.entity);
if (use_limit)
{
Vec2 limit = phy_scene->getSphericalJointLimit(cmp.handle);
Vec2 limit = phy_scene->getSphericalJointLimit(cmp.entity);
Vec3 other_pos = universe.getPosition(other_entity);
render_scene->addDebugLine(joint_pos, other_pos, 0xffff0000, 0);
render_scene->addDebugCone(joint_pos,
@ -203,9 +204,9 @@ struct EditorPlugin LUMIX_FINAL : public WorldEditor::Plugin
auto* render_scene = static_cast<RenderScene*>(universe.getScene(RENDERER_HASH));
if (!render_scene) return;
Entity other_entity = phy_scene->getJointConnectedBody(cmp.handle);
Entity other_entity = phy_scene->getJointConnectedBody(cmp.entity);
if (!other_entity.isValid()) return;
RigidTransform local_frame = phy_scene->getJointConnectedBodyLocalFrame(cmp.handle);
RigidTransform local_frame = phy_scene->getJointConnectedBodyLocalFrame(cmp.entity);
Vec3 pos = universe.getPosition(other_entity);
Vec3 other_pos = (universe.getTransform(other_entity).getRigidPart() * local_frame).pos;
@ -223,7 +224,7 @@ struct EditorPlugin LUMIX_FINAL : public WorldEditor::Plugin
right *= Math::minimum(1.0f, 5 * dir_len);
up *= Math::minimum(1.0f, 5 * dir_len);
Vec3 force = phy_scene->getDistanceJointLinearForce(cmp.handle);
Vec3 force = phy_scene->getDistanceJointLinearForce(cmp.entity);
float t = Math::minimum(force.length() / 10.0f, 1.0f);
u32 color = 0xff000000 + (u32(t * 0xff) << 16) + u32((1 - t) * 0xff);
@ -248,11 +249,11 @@ struct EditorPlugin LUMIX_FINAL : public WorldEditor::Plugin
static void showHingeJointGizmo(ComponentUID cmp)
{
auto* phy_scene = static_cast<PhysicsScene*>(cmp.scene);
Entity connected_body = phy_scene->getJointConnectedBody(cmp.handle);
Vec2 limit = phy_scene->getHingeJointLimit(cmp.handle);
bool use_limit = phy_scene->getHingeJointUseLimit(cmp.handle);
Entity connected_body = phy_scene->getJointConnectedBody(cmp.entity);
Vec2 limit = phy_scene->getHingeJointLimit(cmp.entity);
bool use_limit = phy_scene->getHingeJointUseLimit(cmp.entity);
if (!connected_body.isValid()) return;
RigidTransform global_frame1 = phy_scene->getJointConnectedBodyLocalFrame(cmp.handle);
RigidTransform global_frame1 = phy_scene->getJointConnectedBodyLocalFrame(cmp.entity);
global_frame1 = phy_scene->getUniverse().getTransform(connected_body).getRigidPart() * global_frame1;
showHingeJointGizmo(*phy_scene, limit, use_limit, global_frame1.toMatrix());
}
@ -301,7 +302,7 @@ struct EditorPlugin LUMIX_FINAL : public WorldEditor::Plugin
auto* phy_scene = static_cast<PhysicsScene*>(cmp.scene);
Universe& universe = phy_scene->getUniverse();
Vec3 extents = phy_scene->getHalfExtents(cmp.handle);
Vec3 extents = phy_scene->getHalfExtents(cmp.entity);
Matrix mtx = universe.getPositionAndRotation(cmp.entity);
render_scene.addDebugCube(mtx.getTranslation(),
@ -318,7 +319,7 @@ struct EditorPlugin LUMIX_FINAL : public WorldEditor::Plugin
auto* phy_scene = static_cast<PhysicsScene*>(cmp.scene);
Universe& universe = phy_scene->getUniverse();
float radius = phy_scene->getSphereRadius(cmp.handle);
float radius = phy_scene->getSphereRadius(cmp.entity);
Vec3 pos = universe.getPosition(cmp.entity);
render_scene.addDebugSphere(pos, radius, 0xffff0000, 0);
@ -330,8 +331,8 @@ struct EditorPlugin LUMIX_FINAL : public WorldEditor::Plugin
auto* phy_scene = static_cast<PhysicsScene*>(cmp.scene);
Universe& universe = phy_scene->getUniverse();
float radius = phy_scene->getCapsuleRadius(cmp.handle);
float height = phy_scene->getCapsuleHeight(cmp.handle);
float radius = phy_scene->getCapsuleRadius(cmp.entity);
float height = phy_scene->getCapsuleHeight(cmp.entity);
Matrix mtx = universe.getPositionAndRotation(cmp.entity);
Vec3 physx_capsule_up = mtx.getXVector();
mtx.setXVector(mtx.getYVector());
@ -351,8 +352,8 @@ struct EditorPlugin LUMIX_FINAL : public WorldEditor::Plugin
if (cmp.type == CONTROLLER_TYPE)
{
float height = phy_scene->getControllerHeight(cmp.handle);
float radius = phy_scene->getControllerRadius(cmp.handle);
float height = phy_scene->getControllerHeight(cmp.entity);
float radius = phy_scene->getControllerRadius(cmp.entity);
Vec3 pos = universe.getPosition(cmp.entity);
render_scene->addDebugCapsule(pos, height, radius, 0xff0000ff, 0);
@ -379,7 +380,7 @@ struct EditorPlugin LUMIX_FINAL : public WorldEditor::Plugin
if (cmp.type == D6_JOINT_TYPE)
{
physx::PxD6Joint* joint = static_cast<physx::PxD6Joint*>(phy_scene->getJoint(cmp.handle));
physx::PxD6Joint* joint = static_cast<physx::PxD6Joint*>(phy_scene->getJoint(cmp.entity));
showD6JointGizmo(universe.getTransform(cmp.entity).getRigidPart(), *render_scene, joint);
return true;
}
@ -528,11 +529,10 @@ struct StudioAppPlugin LUMIX_FINAL : public StudioApp::IPlugin
for (int i = 0; i < count; ++i)
{
ComponentUID cmp;
cmp.handle = scene->getJointComponent(i);
cmp.entity = scene->getJointEntity(i);
cmp.scene = scene;
cmp.entity = scene->getJointEntity(cmp.handle);
physx::PxJoint* joint = scene->getJoint(cmp.handle);
switch ((physx::PxJointConcreteType::Enum)scene->getJoint(cmp.handle)->getConcreteType())
physx::PxJoint* joint = scene->getJoint(cmp.entity);
switch ((physx::PxJointConcreteType::Enum)scene->getJoint(cmp.entity)->getConcreteType())
{
case physx::PxJointConcreteType::eDISTANCE:
cmp.type = DISTANCE_JOINT_TYPE;
@ -562,7 +562,7 @@ struct StudioAppPlugin LUMIX_FINAL : public StudioApp::IPlugin
if (ImGui::Selectable(tmp, &b)) m_editor.selectEntities(&cmp.entity, 1);
ImGui::NextColumn();
Entity other_entity = scene->getJointConnectedBody(cmp.handle);
Entity other_entity = scene->getJointConnectedBody(cmp.entity);
getEntityListDisplayName(m_editor, tmp, lengthOf(tmp), other_entity);
if (other_entity.isValid() && ImGui::Selectable(tmp, &b)) m_editor.selectEntities(&other_entity, 1);
ImGui::NextColumn();
@ -638,7 +638,7 @@ struct StudioAppPlugin LUMIX_FINAL : public StudioApp::IPlugin
if (ImGui::Selectable(tmp, &selected)) m_editor.selectEntities(&cmp.entity, 1);
ImGui::NextColumn();
auto type = scene->getActorType(i);
cmp.handle = scene->getActorComponentHandle(i);
cmp.entity = scene->getActorEntity(i);
cmp.scene = scene;
switch (type)
{
@ -743,17 +743,17 @@ struct StudioAppPlugin LUMIX_FINAL : public StudioApp::IPlugin
}
void autogeneratePhySkeleton(PhysicsScene& scene, ComponentHandle cmp, Model* model)
void autogeneratePhySkeleton(PhysicsScene& scene, Entity entity, Model* model)
{
while (scene.getRagdollRootBone(cmp))
while (scene.getRagdollRootBone(entity))
{
scene.destroyRagdollBone(cmp, scene.getRagdollRootBone(cmp));
scene.destroyRagdollBone(entity, scene.getRagdollRootBone(entity));
}
for (int i = 0; i < model->getBoneCount(); ++i)
{
auto& bone = model->getBone(i);
scene.createRagdollBone(cmp, crc32(bone.name.c_str()));
scene.createRagdollBone(entity, crc32(bone.name.c_str()));
}
}
@ -772,18 +772,18 @@ struct StudioAppPlugin LUMIX_FINAL : public StudioApp::IPlugin
if (!render_scene) return;
Entity entity = m_editor.getSelectedEntities()[0];
ComponentHandle model_instance = render_scene->getModelInstanceComponent(entity);
bool has_model_instance = render_scene->getUniverse().hasComponent(entity, MODEL_INSTANCE_TYPE);
auto* phy_scene = static_cast<PhysicsScene*>(m_editor.getUniverse()->getScene(crc32("physics")));
ComponentHandle cmp = phy_scene->getComponent(entity, RAGDOLL_TYPE);
if (!cmp.isValid() || !model_instance.isValid())
bool has_ragdoll = render_scene->getUniverse().hasComponent(entity, RAGDOLL_TYPE);
if (!has_ragdoll || !has_model_instance)
{
ImGui::Text("%s", "Please select an entity with ragdoll and mesh components.");
return;
}
Matrix mtx = m_editor.getUniverse()->getMatrix(entity);
Model* model = render_scene->getModelInstanceModel(model_instance);
Model* model = render_scene->getModelInstanceModel(entity);
if (!model || !model->isReady()) return;
static bool visualize = true;
@ -795,13 +795,13 @@ struct StudioAppPlugin LUMIX_FINAL : public StudioApp::IPlugin
if (m_selected_bone >= 0 && m_selected_bone < model->getBoneCount())
{
u32 hash = crc32(model->getBone(m_selected_bone).name.c_str());
selected_bone = phy_scene->getRagdollBoneByName(cmp, hash);
selected_bone = phy_scene->getRagdollBoneByName(entity, hash);
}
if (visualize) renderBone(*render_scene, *phy_scene, phy_scene->getRagdollRootBone(cmp), selected_bone);
if (visualize) renderBone(*render_scene, *phy_scene, phy_scene->getRagdollRootBone(entity), selected_bone);
ImGui::SameLine();
if (ImGui::Button("Autogenerate")) autogeneratePhySkeleton(*phy_scene, cmp, model);
if (ImGui::Button("Autogenerate")) autogeneratePhySkeleton(*phy_scene, entity, model);
ImGui::SameLine();
auto* root = phy_scene->getRagdollRootBone(cmp);
auto* root = phy_scene->getRagdollRootBone(entity);
if (ImGui::Button("All kinematic")) phy_scene->setRagdollBoneKinematicRecursive(root, true);
PhysicsScene::BoneOrientation new_bone_orientation = phy_scene->getNewBoneOrientation();
if (ImGui::Combo("New bone orientation", (int*)&new_bone_orientation, "X\0Y\0"))
@ -830,28 +830,28 @@ struct StudioAppPlugin LUMIX_FINAL : public StudioApp::IPlugin
else
{
auto& bone = model->getBone(m_selected_bone);
onBonePropertiesGUI(*phy_scene, cmp, crc32(bone.name.c_str()));
onBonePropertiesGUI(*phy_scene, entity, crc32(bone.name.c_str()));
}
}
ImGui::EndChild();
}
void onBonePropertiesGUI(PhysicsScene& scene, ComponentHandle cmp, u32 bone_name_hash)
void onBonePropertiesGUI(PhysicsScene& scene, Entity entity, u32 bone_name_hash)
{
auto* bone_handle = scene.getRagdollBoneByName(cmp, bone_name_hash);
auto* bone_handle = scene.getRagdollBoneByName(entity, bone_name_hash);
if (!bone_handle)
{
if (ImGui::Button("Add"))
{
scene.createRagdollBone(cmp, bone_name_hash);
scene.createRagdollBone(entity, bone_name_hash);
}
return;
}
if (ImGui::Button("Remove"))
{
scene.destroyRagdollBone(cmp, bone_handle);
scene.destroyRagdollBone(entity, bone_handle);
return;
}

File diff suppressed because it is too large Load diff

View file

@ -97,26 +97,25 @@ public:
virtual PhysicsSystem& getSystem() const = 0;
virtual DelegateList<void(const ContactData&)>& onContact() = 0;
virtual ComponentHandle getActorComponent(Entity entity) = 0;
virtual void setActorLayer(ComponentHandle cmp, int layer) = 0;
virtual int getActorLayer(ComponentHandle cmp) = 0;
virtual bool getIsTrigger(ComponentHandle cmp) = 0;
virtual void setIsTrigger(ComponentHandle cmp, bool is_trigger) = 0;
virtual DynamicType getDynamicType(ComponentHandle cmp) = 0;
virtual void setDynamicType(ComponentHandle cmp, DynamicType) = 0;
virtual Vec3 getHalfExtents(ComponentHandle cmp) = 0;
virtual void setHalfExtents(ComponentHandle cmp, const Vec3& size) = 0;
virtual Path getShapeSource(ComponentHandle cmp) = 0;
virtual void setShapeSource(ComponentHandle cmp, const Path& str) = 0;
virtual Path getHeightmapSource(ComponentHandle cmp) = 0;
virtual void setHeightmapSource(ComponentHandle cmp, const Path& path) = 0;
virtual float getHeightmapXZScale(ComponentHandle cmp) = 0;
virtual void setHeightmapXZScale(ComponentHandle cmp, float scale) = 0;
virtual float getHeightmapYScale(ComponentHandle cmp) = 0;
virtual void setHeightmapYScale(ComponentHandle cmp, float scale) = 0;
virtual int getHeightfieldLayer(ComponentHandle cmp) = 0;
virtual void setHeightfieldLayer(ComponentHandle cmp, int layer) = 0;
virtual void updateHeighfieldData(ComponentHandle cmp,
virtual void setActorLayer(Entity entity, int layer) = 0;
virtual int getActorLayer(Entity entity) = 0;
virtual bool getIsTrigger(Entity entity) = 0;
virtual void setIsTrigger(Entity entity, bool is_trigger) = 0;
virtual DynamicType getDynamicType(Entity entity) = 0;
virtual void setDynamicType(Entity entity, DynamicType) = 0;
virtual Vec3 getHalfExtents(Entity entity) = 0;
virtual void setHalfExtents(Entity entity, const Vec3& size) = 0;
virtual Path getShapeSource(Entity entity) = 0;
virtual void setShapeSource(Entity entity, const Path& str) = 0;
virtual Path getHeightmapSource(Entity entity) = 0;
virtual void setHeightmapSource(Entity entity, const Path& path) = 0;
virtual float getHeightmapXZScale(Entity entity) = 0;
virtual void setHeightmapXZScale(Entity entity, float scale) = 0;
virtual float getHeightmapYScale(Entity entity) = 0;
virtual void setHeightmapYScale(Entity entity, float scale) = 0;
virtual int getHeightfieldLayer(Entity entity) = 0;
virtual void setHeightfieldLayer(Entity entity, int layer) = 0;
virtual void updateHeighfieldData(Entity entity,
int x,
int y,
int w,
@ -124,121 +123,119 @@ public:
const u8* data,
int bytes_per_pixel) = 0;
virtual float getCapsuleRadius(ComponentHandle cmp) = 0;
virtual void setCapsuleRadius(ComponentHandle cmp, float value) = 0;
virtual float getCapsuleHeight(ComponentHandle cmp) = 0;
virtual void setCapsuleHeight(ComponentHandle cmp, float value) = 0;
virtual float getCapsuleRadius(Entity entity) = 0;
virtual void setCapsuleRadius(Entity entity, float value) = 0;
virtual float getCapsuleHeight(Entity entity) = 0;
virtual void setCapsuleHeight(Entity entity, float value) = 0;
virtual float getSphereRadius(ComponentHandle cmp) = 0;
virtual void setSphereRadius(ComponentHandle cmp, float value) = 0;
virtual float getSphereRadius(Entity entity) = 0;
virtual void setSphereRadius(Entity entity, float value) = 0;
virtual D6Motion getD6JointXMotion(ComponentHandle cmp) = 0;
virtual void setD6JointXMotion(ComponentHandle cmp, D6Motion motion) = 0;
virtual D6Motion getD6JointYMotion(ComponentHandle cmp) = 0;
virtual void setD6JointYMotion(ComponentHandle cmp, D6Motion motion) = 0;
virtual D6Motion getD6JointZMotion(ComponentHandle cmp) = 0;
virtual void setD6JointZMotion(ComponentHandle cmp, D6Motion motion) = 0;
virtual D6Motion getD6JointSwing1Motion(ComponentHandle cmp) = 0;
virtual void setD6JointSwing1Motion(ComponentHandle cmp, D6Motion motion) = 0;
virtual D6Motion getD6JointSwing2Motion(ComponentHandle cmp) = 0;
virtual void setD6JointSwing2Motion(ComponentHandle cmp, D6Motion motion) = 0;
virtual D6Motion getD6JointTwistMotion(ComponentHandle cmp) = 0;
virtual void setD6JointTwistMotion(ComponentHandle cmp, D6Motion motion) = 0;
virtual float getD6JointLinearLimit(ComponentHandle cmp) = 0;
virtual void setD6JointLinearLimit(ComponentHandle cmp, float limit) = 0;
virtual Vec2 getD6JointTwistLimit(ComponentHandle cmp) = 0;
virtual void setD6JointTwistLimit(ComponentHandle cmp, const Vec2& limit) = 0;
virtual Vec2 getD6JointSwingLimit(ComponentHandle cmp) = 0;
virtual void setD6JointSwingLimit(ComponentHandle cmp, const Vec2& limit) = 0;
virtual float getD6JointDamping(ComponentHandle cmp) = 0;
virtual void setD6JointDamping(ComponentHandle cmp, float value) = 0;
virtual float getD6JointStiffness(ComponentHandle cmp) = 0;
virtual void setD6JointStiffness(ComponentHandle cmp, float value) = 0;
virtual float getD6JointRestitution(ComponentHandle cmp) = 0;
virtual void setD6JointRestitution(ComponentHandle cmp, float value) = 0;
virtual D6Motion getD6JointXMotion(Entity entity) = 0;
virtual void setD6JointXMotion(Entity entity, D6Motion motion) = 0;
virtual D6Motion getD6JointYMotion(Entity entity) = 0;
virtual void setD6JointYMotion(Entity entity, D6Motion motion) = 0;
virtual D6Motion getD6JointZMotion(Entity entity) = 0;
virtual void setD6JointZMotion(Entity entity, D6Motion motion) = 0;
virtual D6Motion getD6JointSwing1Motion(Entity entity) = 0;
virtual void setD6JointSwing1Motion(Entity entity, D6Motion motion) = 0;
virtual D6Motion getD6JointSwing2Motion(Entity entity) = 0;
virtual void setD6JointSwing2Motion(Entity entity, D6Motion motion) = 0;
virtual D6Motion getD6JointTwistMotion(Entity entity) = 0;
virtual void setD6JointTwistMotion(Entity entity, D6Motion motion) = 0;
virtual float getD6JointLinearLimit(Entity entity) = 0;
virtual void setD6JointLinearLimit(Entity entity, float limit) = 0;
virtual Vec2 getD6JointTwistLimit(Entity entity) = 0;
virtual void setD6JointTwistLimit(Entity entity, const Vec2& limit) = 0;
virtual Vec2 getD6JointSwingLimit(Entity entity) = 0;
virtual void setD6JointSwingLimit(Entity entity, const Vec2& limit) = 0;
virtual float getD6JointDamping(Entity entity) = 0;
virtual void setD6JointDamping(Entity entity, float value) = 0;
virtual float getD6JointStiffness(Entity entity) = 0;
virtual void setD6JointStiffness(Entity entity, float value) = 0;
virtual float getD6JointRestitution(Entity entity) = 0;
virtual void setD6JointRestitution(Entity entity, float value) = 0;
virtual float getDistanceJointDamping(ComponentHandle cmp) = 0;
virtual void setDistanceJointDamping(ComponentHandle cmp, float value) = 0;
virtual float getDistanceJointStiffness(ComponentHandle cmp) = 0;
virtual void setDistanceJointStiffness(ComponentHandle cmp, float value) = 0;
virtual float getDistanceJointTolerance(ComponentHandle cmp) = 0;
virtual void setDistanceJointTolerance(ComponentHandle cmp, float value) = 0;
virtual Vec2 getDistanceJointLimits(ComponentHandle cmp) = 0;
virtual void setDistanceJointLimits(ComponentHandle cmp, const Vec2& value) = 0;
virtual Vec3 getDistanceJointLinearForce(ComponentHandle cmp) = 0;
virtual float getDistanceJointDamping(Entity entity) = 0;
virtual void setDistanceJointDamping(Entity entity, float value) = 0;
virtual float getDistanceJointStiffness(Entity entity) = 0;
virtual void setDistanceJointStiffness(Entity entity, float value) = 0;
virtual float getDistanceJointTolerance(Entity entity) = 0;
virtual void setDistanceJointTolerance(Entity entity, float value) = 0;
virtual Vec2 getDistanceJointLimits(Entity entity) = 0;
virtual void setDistanceJointLimits(Entity entity, const Vec2& value) = 0;
virtual Vec3 getDistanceJointLinearForce(Entity entity) = 0;
virtual int getJointCount() = 0;
virtual ComponentHandle getJointComponent(int index) = 0;
virtual Entity getJointEntity(ComponentHandle cmp) = 0;
virtual Entity getJointEntity(int index) = 0;
virtual float getHingeJointDamping(ComponentHandle cmp) = 0;
virtual void setHingeJointDamping(ComponentHandle cmp, float value) = 0;
virtual float getHingeJointStiffness(ComponentHandle cmp) = 0;
virtual void setHingeJointStiffness(ComponentHandle cmp, float value) = 0;
virtual bool getHingeJointUseLimit(ComponentHandle cmp) = 0;
virtual void setHingeJointUseLimit(ComponentHandle cmp, bool use_limit) = 0;
virtual Vec2 getHingeJointLimit(ComponentHandle cmp) = 0;
virtual void setHingeJointLimit(ComponentHandle cmp, const Vec2& limit) = 0;
virtual float getHingeJointDamping(Entity entity) = 0;
virtual void setHingeJointDamping(Entity entity, float value) = 0;
virtual float getHingeJointStiffness(Entity entity) = 0;
virtual void setHingeJointStiffness(Entity entity, float value) = 0;
virtual bool getHingeJointUseLimit(Entity entity) = 0;
virtual void setHingeJointUseLimit(Entity entity, bool use_limit) = 0;
virtual Vec2 getHingeJointLimit(Entity entity) = 0;
virtual void setHingeJointLimit(Entity entity, const Vec2& limit) = 0;
virtual Entity getJointConnectedBody(ComponentHandle cmp) = 0;
virtual void setJointConnectedBody(ComponentHandle cmp, Entity entity) = 0;
virtual Vec3 getJointAxisPosition(ComponentHandle cmp) = 0;
virtual void setJointAxisPosition(ComponentHandle cmp, const Vec3& value) = 0;
virtual Vec3 getJointAxisDirection(ComponentHandle cmp) = 0;
virtual void setJointAxisDirection(ComponentHandle cmp, const Vec3& value) = 0;
virtual RigidTransform getJointLocalFrame(ComponentHandle cmp) = 0;
virtual RigidTransform getJointConnectedBodyLocalFrame(ComponentHandle cmp) = 0;
virtual physx::PxJoint* getJoint(ComponentHandle cmp) = 0;
virtual Entity getJointConnectedBody(Entity entity) = 0;
virtual void setJointConnectedBody(Entity entity, Entity connected_body) = 0;
virtual Vec3 getJointAxisPosition(Entity entity) = 0;
virtual void setJointAxisPosition(Entity entity, const Vec3& value) = 0;
virtual Vec3 getJointAxisDirection(Entity entity) = 0;
virtual void setJointAxisDirection(Entity entity, const Vec3& value) = 0;
virtual RigidTransform getJointLocalFrame(Entity entity) = 0;
virtual RigidTransform getJointConnectedBodyLocalFrame(Entity entity) = 0;
virtual physx::PxJoint* getJoint(Entity entity) = 0;
virtual bool getSphericalJointUseLimit(ComponentHandle cmp) = 0;
virtual void setSphericalJointUseLimit(ComponentHandle cmp, bool use_limit) = 0;
virtual Vec2 getSphericalJointLimit(ComponentHandle cmp) = 0;
virtual void setSphericalJointLimit(ComponentHandle cmp, const Vec2& limit) = 0;
virtual bool getSphericalJointUseLimit(Entity entity) = 0;
virtual void setSphericalJointUseLimit(Entity entity, bool use_limit) = 0;
virtual Vec2 getSphericalJointLimit(Entity entity) = 0;
virtual void setSphericalJointLimit(Entity entity, const Vec2& limit) = 0;
virtual void applyForceToActor(ComponentHandle cmp, const Vec3& force) = 0;
virtual float getActorSpeed(ComponentHandle cmp) = 0;
virtual void putToSleep(ComponentHandle cmp) = 0;
virtual void applyForceToActor(Entity entity, const Vec3& force) = 0;
virtual float getActorSpeed(Entity entity) = 0;
virtual void putToSleep(Entity entity) = 0;
virtual bool isControllerCollisionDown(ComponentHandle cmp) const = 0;
virtual void moveController(ComponentHandle cmp, const Vec3& v) = 0;
virtual ComponentHandle getController(Entity entity) = 0;
virtual int getControllerLayer(ComponentHandle cmp) = 0;
virtual void setControllerLayer(ComponentHandle cmp, int layer) = 0;
virtual float getControllerRadius(ComponentHandle cmp) = 0;
virtual void setControllerRadius(ComponentHandle cmp, float radius) = 0;
virtual float getControllerHeight(ComponentHandle cmp) = 0;
virtual void setControllerHeight(ComponentHandle cmp, float height) = 0;
virtual bool isControllerTouchingDown(ComponentHandle cmp) = 0;
virtual void resizeController(ComponentHandle cmp, float height) = 0;
virtual bool isControllerCollisionDown(Entity entity) const = 0;
virtual void moveController(Entity entity, const Vec3& v) = 0;
virtual int getControllerLayer(Entity entity) = 0;
virtual void setControllerLayer(Entity entity, int layer) = 0;
virtual float getControllerRadius(Entity entity) = 0;
virtual void setControllerRadius(Entity entity, float radius) = 0;
virtual float getControllerHeight(Entity entity) = 0;
virtual void setControllerHeight(Entity entity, float height) = 0;
virtual bool isControllerTouchingDown(Entity entity) = 0;
virtual void resizeController(Entity entity, float height) = 0;
virtual void addBoxGeometry(ComponentHandle cmp, int index) = 0;
virtual void removeBoxGeometry(ComponentHandle cmp, int index) = 0;
virtual int getBoxGeometryCount(ComponentHandle cmp) = 0;
virtual Vec3 getBoxGeomHalfExtents(ComponentHandle cmp, int index) = 0;
virtual void setBoxGeomHalfExtents(ComponentHandle cmp, int index, const Vec3& size) = 0;
virtual Vec3 getBoxGeomOffsetPosition(ComponentHandle cmp, int index) = 0;
virtual void setBoxGeomOffsetPosition(ComponentHandle cmp, int index, const Vec3& pos) = 0;
virtual Vec3 getBoxGeomOffsetRotation(ComponentHandle cmp, int index) = 0;
virtual void setBoxGeomOffsetRotation(ComponentHandle cmp, int index, const Vec3& euler_angles) = 0;
virtual void addBoxGeometry(Entity entity, int index) = 0;
virtual void removeBoxGeometry(Entity entity, int index) = 0;
virtual int getBoxGeometryCount(Entity entity) = 0;
virtual Vec3 getBoxGeomHalfExtents(Entity entity, int index) = 0;
virtual void setBoxGeomHalfExtents(Entity entity, int index, const Vec3& size) = 0;
virtual Vec3 getBoxGeomOffsetPosition(Entity entity, int index) = 0;
virtual void setBoxGeomOffsetPosition(Entity entity, int index, const Vec3& pos) = 0;
virtual Vec3 getBoxGeomOffsetRotation(Entity entity, int index) = 0;
virtual void setBoxGeomOffsetRotation(Entity entity, int index, const Vec3& euler_angles) = 0;
virtual void addSphereGeometry(ComponentHandle cmp, int index) = 0;
virtual void removeSphereGeometry(ComponentHandle cmp, int index) = 0;
virtual int getSphereGeometryCount(ComponentHandle cmp) = 0;
virtual float getSphereGeomRadius(ComponentHandle cmp, int index) = 0;
virtual void setSphereGeomRadius(ComponentHandle cmp, int index, float size) = 0;
virtual Vec3 getSphereGeomOffsetPosition(ComponentHandle cmp, int index) = 0;
virtual void setSphereGeomOffsetPosition(ComponentHandle cmp, int index, const Vec3& pos) = 0;
virtual Vec3 getSphereGeomOffsetRotation(ComponentHandle cmp, int index) = 0;
virtual void setSphereGeomOffsetRotation(ComponentHandle cmp, int index, const Vec3& euler_angles) = 0;
virtual void addSphereGeometry(Entity entity, int index) = 0;
virtual void removeSphereGeometry(Entity entity, int index) = 0;
virtual int getSphereGeometryCount(Entity entity) = 0;
virtual float getSphereGeomRadius(Entity entity, int index) = 0;
virtual void setSphereGeomRadius(Entity entity, int index, float size) = 0;
virtual Vec3 getSphereGeomOffsetPosition(Entity entity, int index) = 0;
virtual void setSphereGeomOffsetPosition(Entity entity, int index, const Vec3& pos) = 0;
virtual Vec3 getSphereGeomOffsetRotation(Entity entity, int index) = 0;
virtual void setSphereGeomOffsetRotation(Entity entity, int index, const Vec3& euler_angles) = 0;
virtual BoneOrientation getNewBoneOrientation() const = 0;
virtual void setNewBoneOrientation(BoneOrientation orientation) = 0;
virtual RagdollBone* createRagdollBone(ComponentHandle cmp, u32 bone_name_hash) = 0;
virtual void destroyRagdollBone(ComponentHandle cmp, RagdollBone* bone) = 0;
virtual RagdollBone* createRagdollBone(Entity entity, u32 bone_name_hash) = 0;
virtual void destroyRagdollBone(Entity entity, RagdollBone* bone) = 0;
virtual physx::PxJoint* getRagdollBoneJoint(RagdollBone* bone) const = 0;
virtual RagdollBone* getRagdollRootBone(ComponentHandle cmp) const = 0;
virtual RagdollBone* getRagdollRootBone(Entity entity) const = 0;
virtual RagdollBone* getRagdollBoneChild(RagdollBone* bone) = 0;
virtual RagdollBone* getRagdollBoneSibling(RagdollBone* bone) = 0;
virtual RagdollBone* getRagdollBoneByName(ComponentHandle cmp, u32 bone_name_hash) = 0;
virtual RagdollBone* getRagdollBoneByName(Entity entity, u32 bone_name_hash) = 0;
virtual const char* getRagdollBoneName(RagdollBone* bone) = 0;
virtual float getRagdollBoneHeight(RagdollBone* bone) = 0;
virtual float getRagdollBoneRadius(RagdollBone* bone) = 0;
@ -247,13 +244,13 @@ public:
virtual RigidTransform getRagdollBoneTransform(RagdollBone* bone) = 0;
virtual void setRagdollBoneTransform(RagdollBone* bone, const RigidTransform& matrix) = 0;
virtual void changeRagdollBoneJoint(RagdollBone* child, int type) = 0;
virtual void getRagdollData(ComponentHandle cmp, OutputBlob& blob) = 0;
virtual void setRagdollData(ComponentHandle cmp, InputBlob& blob) = 0;
virtual void getRagdollData(Entity entity, OutputBlob& blob) = 0;
virtual void setRagdollData(Entity entity, InputBlob& blob) = 0;
virtual void setRagdollBoneKinematicRecursive(RagdollBone* bone, bool is_kinematic) = 0;
virtual void setRagdollBoneKinematic(RagdollBone* bone, bool is_kinematic) = 0;
virtual bool isRagdollBoneKinematic(RagdollBone* bone) = 0;
virtual void setRagdollLayer(ComponentHandle cmp, int layer) = 0;
virtual int getRagdollLayer(ComponentHandle cmp) = 0;
virtual void setRagdollLayer(Entity entity, int layer) = 0;
virtual int getRagdollLayer(Entity entity) = 0;
virtual const char* getCollisionLayerName(int index) = 0;
virtual void setCollisionLayerName(int index, const char* name) = 0;
@ -272,7 +269,6 @@ public:
virtual ActorType getActorType(int index) = 0;
virtual bool isActorDebugEnabled(int index) const = 0;
virtual void enableActorDebug(int index, bool enable) const = 0;
virtual ComponentHandle getActorComponentHandle(int index) = 0;
};

View file

@ -11,14 +11,14 @@ namespace Lumix
{
typedef Array<u64> LayerMasks;
typedef Array<int> ModelInstancetoSphereMap;
typedef Array<ComponentHandle> SphereToModelInstanceMap;
typedef Array<Entity> SphereToModelInstanceMap;
static void doCulling(int start_index,
const Sphere* LUMIX_RESTRICT start,
const Sphere* LUMIX_RESTRICT end,
const Frustum* LUMIX_RESTRICT frustum,
const u64* LUMIX_RESTRICT layer_masks,
const ComponentHandle* LUMIX_RESTRICT sphere_to_model_instance_map,
const Entity* LUMIX_RESTRICT sphere_to_model_instance_map,
u64 layer_mask,
CullingSystem::Subresults& results)
{
@ -159,25 +159,25 @@ public:
}
void setLayerMask(ComponentHandle model_instance, u64 layer) override
void setLayerMask(Entity model_instance, u64 layer) override
{
m_layer_masks[m_model_instance_to_sphere_map[model_instance.index]] = layer;
}
u64 getLayerMask(ComponentHandle model_instance) override
u64 getLayerMask(Entity model_instance) override
{
return m_layer_masks[m_model_instance_to_sphere_map[model_instance.index]];
}
bool isAdded(ComponentHandle model_instance) override
bool isAdded(Entity model_instance) override
{
return model_instance.index < m_model_instance_to_sphere_map.size() && m_model_instance_to_sphere_map[model_instance.index] != -1;
}
void addStatic(ComponentHandle model_instance, const Sphere& sphere, u64 layer_mask) override
void addStatic(Entity model_instance, const Sphere& sphere, u64 layer_mask) override
{
if (model_instance.index < m_model_instance_to_sphere_map.size() &&
m_model_instance_to_sphere_map[model_instance.index] != -1)
@ -197,7 +197,7 @@ public:
}
void removeStatic(ComponentHandle model_instance) override
void removeStatic(Entity model_instance) override
{
if (model_instance.index >= m_model_instance_to_sphere_map.size()) return;
int index = m_model_instance_to_sphere_map[model_instance.index];
@ -216,14 +216,14 @@ public:
}
void updateBoundingSphere(const Sphere& sphere, ComponentHandle model_instance) override
void updateBoundingSphere(const Sphere& sphere, Entity model_instance) override
{
int idx = m_model_instance_to_sphere_map[model_instance.index];
if (idx >= 0) m_spheres[idx] = sphere;
}
void insert(const InputSpheres& spheres, const Array<ComponentHandle>& model_instances) override
void insert(const InputSpheres& spheres, const Array<Entity>& model_instances) override
{
for (int i = 0; i < spheres.size(); i++)
{
@ -239,7 +239,7 @@ public:
}
const Sphere& getSphere(ComponentHandle model_instance) override
const Sphere& getSphere(Entity model_instance) override
{
return m_spheres[m_model_instance_to_sphere_map[model_instance.index]];
}

View file

@ -18,7 +18,7 @@ namespace Lumix
{
public:
typedef Array<Sphere> InputSpheres;
typedef Array<ComponentHandle> Subresults;
typedef Array<Entity> Subresults;
typedef Array<Subresults> Results;
CullingSystem() { }
@ -32,16 +32,16 @@ namespace Lumix
virtual Results& cull(const Frustum& frustum, u64 layer_mask) = 0;
virtual bool isAdded(ComponentHandle model_instance) = 0;
virtual void addStatic(ComponentHandle model_instance, const Sphere& sphere, u64 layer_mask) = 0;
virtual void removeStatic(ComponentHandle model_instance) = 0;
virtual bool isAdded(Entity model_instance) = 0;
virtual void addStatic(Entity model_instance, const Sphere& sphere, u64 layer_mask) = 0;
virtual void removeStatic(Entity model_instance) = 0;
virtual void setLayerMask(ComponentHandle model_instance, u64 layer) = 0;
virtual u64 getLayerMask(ComponentHandle model_instance) = 0;
virtual void setLayerMask(Entity model_instance, u64 layer) = 0;
virtual u64 getLayerMask(Entity model_instance) = 0;
virtual void updateBoundingSphere(const Sphere& sphere, ComponentHandle model_instance) = 0;
virtual void updateBoundingSphere(const Sphere& sphere, Entity model_instance) = 0;
virtual void insert(const InputSpheres& spheres, const Array<ComponentHandle>& model_instances) = 0;
virtual const Sphere& getSphere(ComponentHandle model_instance) = 0;
virtual void insert(const InputSpheres& spheres, const Array<Entity>& model_instances) = 0;
virtual const Sphere& getSphere(Entity model_instance) = 0;
};
} // ~namespace Lux

View file

@ -3011,29 +3011,29 @@ static bool createBillboard(ImportAssetDialog& dialog,
auto mesh_entity = universe.createEntity({0, 0, 0}, {0, 0, 0, 0});
static const auto MODEL_INSTANCE_TYPE = Reflection::getComponentType("renderable");
auto mesh_cmp = universe.createComponent(MODEL_INSTANCE_TYPE, mesh_entity);
render_scene->setModelInstancePath(mesh_cmp, mesh_path);
universe.createComponent(MODEL_INSTANCE_TYPE, mesh_entity);
render_scene->setModelInstancePath(mesh_entity, mesh_path);
auto mesh_left_entity = universe.createEntity({ 0, 0, 0 }, { Vec3(0, 1, 0), Math::PI * 0.5f });
auto mesh_left_cmp = universe.createComponent(MODEL_INSTANCE_TYPE, mesh_left_entity);
render_scene->setModelInstancePath(mesh_left_cmp, mesh_path);
universe.createComponent(MODEL_INSTANCE_TYPE, mesh_left_entity);
render_scene->setModelInstancePath(mesh_left_entity, mesh_path);
auto mesh_back_entity = universe.createEntity({ 0, 0, 0 }, { Vec3(0, 1, 0), Math::PI });
auto mesh_back_cmp = universe.createComponent(MODEL_INSTANCE_TYPE, mesh_back_entity);
render_scene->setModelInstancePath(mesh_back_cmp, mesh_path);
universe.createComponent(MODEL_INSTANCE_TYPE, mesh_back_entity);
render_scene->setModelInstancePath(mesh_back_entity, mesh_path);
auto mesh_right_entity = universe.createEntity({ 0, 0, 0 }, { Vec3(0, 1, 0), Math::PI * 1.5f});
auto mesh_right_cmp = universe.createComponent(MODEL_INSTANCE_TYPE, mesh_right_entity);
render_scene->setModelInstancePath(mesh_right_cmp, mesh_path);
universe.createComponent(MODEL_INSTANCE_TYPE, mesh_right_entity);
render_scene->setModelInstancePath(mesh_right_entity, mesh_path);
auto light_entity = universe.createEntity({0, 0, 0}, {0, 0, 0, 0});
static const auto GLOBAL_LIGHT_TYPE = Reflection::getComponentType("global_light");
auto light_cmp = universe.createComponent(GLOBAL_LIGHT_TYPE, light_entity);
render_scene->setGlobalLightIntensity(light_cmp, 0);
universe.createComponent(GLOBAL_LIGHT_TYPE, light_entity);
render_scene->setGlobalLightIntensity(light_entity, 0);
while (engine.getFileSystem().hasWork()) engine.getFileSystem().updateAsyncTransactions();
auto* model = render_scene->getModelInstanceModel(mesh_cmp);
auto* model = render_scene->getModelInstanceModel(mesh_entity);
int width = 640, height = 480;
float original_lod_0 = FLT_MAX;
if (model->isReady())
@ -3050,12 +3050,12 @@ static bool createBillboard(ImportAssetDialog& dialog,
BillboardSceneData data(aabb, texture_size);
auto camera_entity = universe.createEntity(data.position, { 0, 0, 0, 1 });
static const auto CAMERA_TYPE = Reflection::getComponentType("camera");
auto camera_cmp = universe.createComponent(CAMERA_TYPE, camera_entity);
render_scene->setCameraOrtho(camera_cmp, true);
render_scene->setCameraSlot(camera_cmp, "main");
universe.createComponent(CAMERA_TYPE, camera_entity);
render_scene->setCameraOrtho(camera_entity, true);
render_scene->setCameraSlot(camera_entity, "main");
width = data.width;
height = data.height;
render_scene->setCameraOrthoSize(camera_cmp, data.ortho_size);
render_scene->setCameraOrthoSize(camera_entity, data.ortho_size);
}
pipeline->setScene(render_scene);

View file

@ -381,9 +381,8 @@ struct ModelPlugin LUMIX_FINAL : public AssetBrowser::IPlugin
{
explicit ModelPlugin(StudioApp& app)
: m_app(app)
, m_camera_cmp(INVALID_COMPONENT)
, m_camera_entity(INVALID_ENTITY)
, m_mesh(INVALID_COMPONENT)
, m_mesh(INVALID_ENTITY)
, m_pipeline(nullptr)
, m_universe(nullptr)
, m_is_mouse_captured(false)
@ -513,13 +512,13 @@ struct ModelPlugin LUMIX_FINAL : public AssetBrowser::IPlugin
Entity light_entity = m_tile.universe->createEntity({ 0, 0, 0 }, { 0, 0, 0, 1 });
RenderScene* render_scene = (RenderScene*)m_tile.universe->getScene(MODEL_INSTANCE_TYPE);
ComponentHandle light_cmp = m_tile.universe->createComponent(GLOBAL_LIGHT_TYPE, light_entity);
render_scene->setGlobalLightIntensity(light_cmp, 1);
render_scene->setGlobalLightIndirectIntensity(light_cmp, 1);
m_tile.universe->createComponent(GLOBAL_LIGHT_TYPE, light_entity);
render_scene->setGlobalLightIntensity(light_entity, 1);
render_scene->setGlobalLightIndirectIntensity(light_entity, 1);
m_tile.camera_entity = m_tile.universe->createEntity({ 0, 0, 0 }, { 0, 0, 0, 1 });
m_tile.camera_cmp = m_tile.universe->createComponent(CAMERA_TYPE, m_tile.camera_entity);
render_scene->setCameraSlot(m_tile.camera_cmp, "editor");
m_tile.universe->createComponent(CAMERA_TYPE, m_tile.camera_entity);
render_scene->setCameraSlot(m_tile.camera_entity, "editor");
m_tile.pipeline->setScene(render_scene);
}
@ -535,15 +534,16 @@ struct ModelPlugin LUMIX_FINAL : public AssetBrowser::IPlugin
auto mesh_entity = m_universe->createEntity({ 0, 0, 0 }, { 0, 0, 0, 1 });
auto* render_scene = static_cast<RenderScene*>(m_universe->getScene(MODEL_INSTANCE_TYPE));
m_mesh = m_universe->createComponent(MODEL_INSTANCE_TYPE, mesh_entity);
m_mesh = mesh_entity;
m_universe->createComponent(MODEL_INSTANCE_TYPE, mesh_entity);
auto light_entity = m_universe->createEntity({ 0, 0, 0 }, { 0, 0, 0, 1 });
auto light_cmp = m_universe->createComponent(GLOBAL_LIGHT_TYPE, light_entity);
render_scene->setGlobalLightIntensity(light_cmp, 1);
m_universe->createComponent(GLOBAL_LIGHT_TYPE, light_entity);
render_scene->setGlobalLightIntensity(light_entity, 1);
m_camera_entity = m_universe->createEntity({ 0, 0, 0 }, { 0, 0, 0, 1 });
m_camera_cmp = m_universe->createComponent(CAMERA_TYPE, m_camera_entity);
render_scene->setCameraSlot(m_camera_cmp, "editor");
m_universe->createComponent(CAMERA_TYPE, m_camera_entity);
render_scene->setCameraSlot(m_camera_entity, "editor");
m_pipeline->setScene(render_scene);
}
@ -866,10 +866,9 @@ struct ModelPlugin LUMIX_FINAL : public AssetBrowser::IPlugin
Entity mesh_entity = m_tile.universe->instantiatePrefab(*prefab, Vec3::ZERO, Quat::IDENTITY, 1);
if (!mesh_entity.isValid()) return;
ComponentHandle tile_mesh = render_scene->getModelInstanceComponent(mesh_entity);
if (!tile_mesh.isValid()) return;
if (!render_scene->getUniverse().hasComponent(mesh_entity, MODEL_INSTANCE_TYPE)) return;
Model* model = render_scene->getModelInstanceModel(tile_mesh);
Model* model = render_scene->getModelInstanceModel(mesh_entity);
if (!model) return;
m_tile.path_hash = prefab->getPath().getHash();
@ -933,9 +932,9 @@ struct ModelPlugin LUMIX_FINAL : public AssetBrowser::IPlugin
if (!renderer) return;
Entity mesh_entity = m_tile.universe->createEntity({ 0, 0, 0 }, { 0, 0, 0, 1 });
ComponentHandle tile_mesh = m_tile.universe->createComponent(MODEL_INSTANCE_TYPE, mesh_entity);
m_tile.universe->createComponent(MODEL_INSTANCE_TYPE, mesh_entity);
render_scene->setModelInstancePath(tile_mesh, model->getPath());
render_scene->setModelInstancePath(mesh_entity, model->getPath());
AABB aabb = model->getAABB();
Matrix mtx;
@ -1012,7 +1011,6 @@ struct ModelPlugin LUMIX_FINAL : public AssetBrowser::IPlugin
Pipeline* pipeline = nullptr;
Entity m_entity_in_fly = INVALID_ENTITY;
Entity camera_entity = INVALID_ENTITY;
ComponentHandle camera_cmp = INVALID_COMPONENT;
int frame_countdown = -1;
u32 path_hash;
Array<u8> data;
@ -1025,9 +1023,8 @@ struct ModelPlugin LUMIX_FINAL : public AssetBrowser::IPlugin
StudioApp& m_app;
Universe* m_universe;
Pipeline* m_pipeline;
ComponentHandle m_mesh;
Entity m_mesh;
Entity m_camera_entity;
ComponentHandle m_camera_cmp;
bool m_is_mouse_captured;
int m_captured_mouse_x;
int m_captured_mouse_y;
@ -1295,7 +1292,7 @@ struct EnvironmentProbePlugin LUMIX_FINAL : public PropertyGrid::IPlugin
{
g_log_error.log("Editor") << "Failed to create " << path;
}
u64 probe_guid = ((RenderScene*)cmp.scene)->getEnvironmentProbeGUID(cmp.handle);
u64 probe_guid = ((RenderScene*)cmp.scene)->getEnvironmentProbeGUID(cmp.entity);
path << probe_guid << postfix << ".dds";
if (!file.open(path, FS::Mode::CREATE_AND_WRITE))
{
@ -1358,15 +1355,14 @@ struct EnvironmentProbePlugin LUMIX_FINAL : public PropertyGrid::IPlugin
Vec3 probe_position = universe->getPosition(cmp.entity);
auto* scene = static_cast<RenderScene*>(universe->getScene(CAMERA_TYPE));
ComponentHandle camera_cmp = scene->getCameraInSlot("probe");
if (!camera_cmp.isValid())
Entity camera_entity = scene->getCameraInSlot("probe");
if (!camera_entity.isValid())
{
g_log_error.log("Renderer") << "No camera in slot 'probe'.";
return;
}
Entity camera_entity = scene->getCameraEntity(camera_cmp);
scene->setCameraFOV(camera_cmp, Math::degreesToRadians(90));
scene->setCameraFOV(camera_entity, Math::degreesToRadians(90));
m_pipeline->setScene(scene);
m_pipeline->resize(TEXTURE_SIZE, TEXTURE_SIZE);
@ -1451,7 +1447,7 @@ struct EnvironmentProbePlugin LUMIX_FINAL : public PropertyGrid::IPlugin
saveCubemap(cmp, &data[0], TEXTURE_SIZE, "");
bgfx::destroy(texture);
scene->reloadEnvironmentProbe(cmp.handle);
scene->reloadEnvironmentProbe(cmp.entity);
}
@ -1460,7 +1456,7 @@ struct EnvironmentProbePlugin LUMIX_FINAL : public PropertyGrid::IPlugin
if (cmp.type != ENVIRONMENT_PROBE_TYPE) return;
auto* scene = static_cast<RenderScene*>(cmp.scene);
auto* texture = scene->getEnvironmentProbeTexture(cmp.handle);
auto* texture = scene->getEnvironmentProbeTexture(cmp.entity);
ImGui::LabelText("Path", "%s", texture->getPath().c_str());
if (ImGui::Button("View")) m_app.getAssetBrowser().selectResource(texture->getPath(), true);
ImGui::SameLine();
@ -1493,14 +1489,14 @@ struct EmitterPlugin LUMIX_FINAL : public PropertyGrid::IPlugin
ImGui::Checkbox("Update", &m_particle_emitter_updating);
auto* scene = static_cast<RenderScene*>(cmp.scene);
ImGui::SameLine();
if (ImGui::Button("Reset")) scene->resetParticleEmitter(cmp.handle);
if (ImGui::Button("Reset")) scene->resetParticleEmitter(cmp.entity);
if (m_particle_emitter_updating)
{
ImGui::DragFloat("Timescale", &m_particle_emitter_timescale, 0.01f, 0.01f, 10000.0f);
float time_delta = m_app.getWorldEditor().getEngine().getLastTimeDelta();
scene->updateEmitter(cmp.handle, time_delta * m_particle_emitter_timescale);
scene->getParticleEmitter(cmp.handle)->drawGizmo(m_app.getWorldEditor(), *scene);
scene->updateEmitter(cmp.entity, time_delta * m_particle_emitter_timescale);
scene->getParticleEmitter(cmp.entity)->drawGizmo(m_app.getWorldEditor(), *scene);
}
}
@ -1563,7 +1559,7 @@ struct FurPainter LUMIX_FINAL : public WorldEditor::Plugin
if (!model_instance.isValid()) return;
RenderScene* scene = static_cast<RenderScene*>(model_instance.scene);
Model* model = scene->getModelInstanceModel(model_instance.handle);
Model* model = scene->getModelInstanceModel(model_instance.entity);
if (!model || !model->isReady()) return;
@ -1609,7 +1605,7 @@ struct FurPainter LUMIX_FINAL : public WorldEditor::Plugin
if (!model_instance.isValid()) return;
RenderScene* scene = static_cast<RenderScene*>(model_instance.scene);
Model* model = scene->getModelInstanceModel(model_instance.handle);
Model* model = scene->getModelInstanceModel(model_instance.entity);
if (!model || !model->isReady() || model->getMeshCount() < 1) return;
if (!model->getMesh(0).material) return;
@ -1904,7 +1900,7 @@ struct FurPainter LUMIX_FINAL : public WorldEditor::Plugin
if (!model_instance.isValid()) return;
RenderScene* scene = static_cast<RenderScene*>(model_instance.scene);
Model* model = scene->getModelInstanceModel(model_instance.handle);
Model* model = scene->getModelInstanceModel(model_instance.entity);
if (!model || !model->isReady() || model->getMeshCount() < 1) return;
if (!model->getMesh(0).material) return;
@ -1912,15 +1908,15 @@ struct FurPainter LUMIX_FINAL : public WorldEditor::Plugin
Texture* texture = model->getMesh(0).material->getTexture(0);
if (!texture || texture->data.empty()) return;
const Pose* pose = scene->lockPose(model_instance.handle);
const Pose* pose = scene->lockPose(model_instance.entity);
if (!pose) return;
Vec3 origin, dir;
scene->getRay(editor.getEditCamera().handle, {(float)x, (float)y}, origin, dir);
scene->getRay(editor.getEditCamera().entity, {(float)x, (float)y}, origin, dir);
RayCastModelHit hit = model->castRay(origin, dir, universe->getMatrix(entities[0]), pose);
if (!hit.m_is_hit)
{
scene->unlockPose(model_instance.handle, false);
scene->unlockPose(model_instance.entity, false);
return;
}
@ -1928,7 +1924,7 @@ struct FurPainter LUMIX_FINAL : public WorldEditor::Plugin
hit_pos = universe->getTransform(entities[0]).inverted().transform(hit_pos);
paint(texture, model, hit_pos);
scene->unlockPose(model_instance.handle, false);
scene->unlockPose(model_instance.entity, false);
}
@ -1985,7 +1981,7 @@ struct FurPainterPlugin LUMIX_FINAL : public StudioApp::IPlugin
goto end;
}
Model* model = scene->getModelInstanceModel(model_instance.handle);
Model* model = scene->getModelInstanceModel(model_instance.entity);
if (!model)
{
ImGui::Text("Entity does not have model.");
@ -2055,7 +2051,7 @@ struct FurPainterPlugin LUMIX_FINAL : public StudioApp::IPlugin
if (!model_instance.isValid()) return;
RenderScene* scene = static_cast<RenderScene*>(model_instance.scene);
Model* model = scene->getModelInstanceModel(model_instance.handle);
Model* model = scene->getModelInstanceModel(model_instance.entity);
if (!model || !model->isReady() || model->getMeshCount() < 1) return;
if (!model->getMesh(0).material) return;
@ -2063,21 +2059,21 @@ struct FurPainterPlugin LUMIX_FINAL : public StudioApp::IPlugin
Texture* texture = model->getMesh(0).material->getTexture(0);
if (!texture || texture->data.empty()) return;
const Pose* pose = scene->lockPose(model_instance.handle);
const Pose* pose = scene->lockPose(model_instance.entity);
if (!pose) return;
Vec3 origin, dir;
scene->getRay(editor.getEditCamera().handle, editor.getMousePos(), origin, dir);
scene->getRay(editor.getEditCamera().entity, editor.getMousePos(), origin, dir);
RayCastModelHit hit = model->castRay(origin, dir, editor.getUniverse()->getMatrix(entities[0]), pose);
if (!hit.m_is_hit)
{
scene->unlockPose(model_instance.handle, false);
scene->unlockPose(model_instance.entity, false);
return;
}
Vec3 hit_pos = hit.m_origin + hit.m_t * hit.m_dir;
scene->addDebugSphere(hit_pos, fur_painter->brush_radius, 0xffffFFFF, 0);
scene->unlockPose(model_instance.handle, false);
scene->unlockPose(model_instance.entity, false);
}
@ -2142,9 +2138,9 @@ struct RenderInterfaceImpl LUMIX_FINAL : public RenderInterface
inv_mtx.inverse();
Vec3 lpos = inv_mtx.transformPoint(wpos);
auto* scene = (RenderScene*)universe->getScene(MODEL_INSTANCE_TYPE);
ComponentHandle model_instance = scene->getModelInstanceComponent(entity);
if (!model_instance.isValid()) return wpos;
Model* model = scene->getModelInstanceModel(model_instance);
if (!universe->hasComponent(entity, MODEL_INSTANCE_TYPE)) return wpos;
Model* model = scene->getModelInstanceModel(entity);
float min_dist_squared = FLT_MAX;
Vec3 closest_vertex = lpos;
@ -2288,7 +2284,7 @@ struct RenderInterfaceImpl LUMIX_FINAL : public RenderInterface
}
WorldEditor::RayHit castRay(const Vec3& origin, const Vec3& dir, ComponentHandle ignored) override
WorldEditor::RayHit castRay(const Vec3& origin, const Vec3& dir, Entity ignored) override
{
auto hit = m_render_scene->castRay(origin, dir, ignored);
@ -2296,9 +2292,9 @@ struct RenderInterfaceImpl LUMIX_FINAL : public RenderInterface
}
void getRay(ComponentHandle camera_index, const Vec2& screen_pos, Vec3& origin, Vec3& dir) override
void getRay(Entity camera, const Vec2& screen_pos, Vec3& origin, Vec3& dir) override
{
m_render_scene->getRay(camera_index, screen_pos, origin, dir);
m_render_scene->getRay(camera, screen_pos, origin, dir);
}
@ -2317,10 +2313,10 @@ struct RenderInterfaceImpl LUMIX_FINAL : public RenderInterface
AABB getEntityAABB(Universe& universe, Entity entity) override
{
AABB aabb;
auto cmp = m_render_scene->getModelInstanceComponent(entity);
if (cmp != INVALID_COMPONENT)
if (universe.hasComponent(entity, MODEL_INSTANCE_TYPE))
{
Model* model = m_render_scene->getModelInstanceModel(cmp);
Model* model = m_render_scene->getModelInstanceModel(entity);
if (!model) return aabb;
aabb = model->getAABB();
@ -2344,45 +2340,39 @@ struct RenderInterfaceImpl LUMIX_FINAL : public RenderInterface
}
void setCameraSlot(ComponentHandle cmp, const char* slot) override
void setCameraSlot(Entity entity, const char* slot) override
{
m_render_scene->setCameraSlot(cmp, slot);
m_render_scene->setCameraSlot(entity, slot);
}
ComponentHandle getCameraInSlot(const char* slot) override
Entity getCameraInSlot(const char* slot) override
{
return m_render_scene->getCameraInSlot(slot);
}
Entity getCameraEntity(ComponentHandle cmp) override
Vec2 getCameraScreenSize(Entity entity) override
{
return m_render_scene->getCameraEntity(cmp);
return m_render_scene->getCameraScreenSize(entity);
}
Vec2 getCameraScreenSize(ComponentHandle cmp) override
float getCameraOrthoSize(Entity entity) override
{
return m_render_scene->getCameraScreenSize(cmp);
return m_render_scene->getCameraOrthoSize(entity);
}
float getCameraOrthoSize(ComponentHandle cmp) override
bool isCameraOrtho(Entity entity) override
{
return m_render_scene->getCameraOrthoSize(cmp);
return m_render_scene->isCameraOrtho(entity);
}
bool isCameraOrtho(ComponentHandle cmp) override
float getCameraFOV(Entity entity) override
{
return m_render_scene->isCameraOrtho(cmp);
}
float getCameraFOV(ComponentHandle cmp) override
{
return m_render_scene->getCameraFOV(cmp);
return m_render_scene->getCameraFOV(entity);
}
@ -2415,17 +2405,16 @@ struct RenderInterfaceImpl LUMIX_FINAL : public RenderInterface
Vec3 getModelCenter(Entity entity) override
{
auto cmp = m_render_scene->getModelInstanceComponent(entity);
if (cmp == INVALID_COMPONENT) return Vec3(0, 0, 0);
Model* model = m_render_scene->getModelInstanceModel(cmp);
if (!m_render_scene->getUniverse().hasComponent(entity, MODEL_INSTANCE_TYPE)) return Vec3::ZERO;
Model* model = m_render_scene->getModelInstanceModel(entity);
if (!model) return Vec3(0, 0, 0);
return (model->getAABB().min + model->getAABB().max) * 0.5f;
}
Path getModelInstancePath(ComponentHandle cmp) override
Path getModelInstancePath(Entity entity) override
{
return m_render_scene->getModelInstancePath(cmp);
return m_render_scene->getModelInstancePath(entity);
}
@ -2463,7 +2452,7 @@ struct RenderInterfaceImpl LUMIX_FINAL : public RenderInterface
Vec2 worldToScreenPixels(const Vec3& world) override
{
ComponentHandle camera = m_pipeline.getAppliedCamera();
Entity camera = m_pipeline.getAppliedCamera();
Matrix mtx = m_render_scene->getCameraViewProjection(camera);
Vec4 pos = mtx * Vec4(world, 1);
float inv = 1 / pos.w;
@ -2473,13 +2462,13 @@ struct RenderInterfaceImpl LUMIX_FINAL : public RenderInterface
}
Frustum getFrustum(ComponentHandle camera_cmp, const Vec2& viewport_min, const Vec2& viewport_max) override
Frustum getFrustum(Entity camera, const Vec2& viewport_min, const Vec2& viewport_max) override
{
return m_render_scene->getCameraFrustum(camera_cmp, viewport_min, viewport_max);
return m_render_scene->getCameraFrustum(camera, viewport_min, viewport_max);
}
void getModelInstaces(Array<Entity>& entities, const Frustum& frustum, const Vec3& lod_ref_point, ComponentHandle camera) override
void getModelInstaces(Array<Entity>& entities, const Frustum& frustum, const Vec3& lod_ref_point, Entity camera) override
{
Array<Array<ModelInstanceMesh>>& res = m_render_scene->getModelInstanceInfos(frustum, lod_ref_point, camera, ~0ULL);
for (auto& sub : res)
@ -2836,7 +2825,7 @@ struct WorldEditorPlugin LUMIX_FINAL : public WorldEditor::Plugin
RenderScene* scene = static_cast<RenderScene*>(light.scene);
Universe& universe = scene->getUniverse();
float range = scene->getLightRange(light.handle);
float range = scene->getLightRange(light.entity);
Vec3 pos = universe.getPosition(light.entity);
scene->addDebugSphere(pos, range, 0xff0000ff, 0);
@ -2888,7 +2877,7 @@ struct WorldEditorPlugin LUMIX_FINAL : public WorldEditor::Plugin
{
RenderScene* scene = static_cast<RenderScene*>(cmp.scene);
Universe& universe = scene->getUniverse();
Vec3 scale = scene->getDecalScale(cmp.handle);
Vec3 scale = scene->getDecalScale(cmp.entity);
Matrix mtx = universe.getMatrix(cmp.entity);
scene->addDebugCube(mtx.getTranslation(),
mtx.getXVector() * scale.x,
@ -2903,7 +2892,7 @@ struct WorldEditorPlugin LUMIX_FINAL : public WorldEditor::Plugin
{
RenderScene* scene = static_cast<RenderScene*>(cmp.scene);
scene->addDebugFrustum(scene->getCameraFrustum(cmp.handle), 0xffff0000, 0);
scene->addDebugFrustum(scene->getCameraFrustum(cmp.entity), 0xffff0000, 0);
}

View file

@ -195,15 +195,15 @@ void SceneView::renderSelection()
Universe& universe = scene->getUniverse();
for (Entity e : entities)
{
ComponentHandle cmp = scene->getModelInstanceComponent(e);
if (!cmp.isValid()) continue;
Model* model = scene->getModelInstanceModel(cmp);
if (!scene->getUniverse().hasComponent(e, MODEL_INSTANCE_TYPE)) continue;
Model* model = scene->getModelInstanceModel(e);
Matrix mtx = universe.getMatrix(e);
if (model)
{
Pose* pose = scene->lockPose(cmp);
Pose* pose = scene->lockPose(e);
m_pipeline->renderModel(*model, pose, mtx);
scene->unlockPose(cmp, false);
scene->unlockPose(e, false);
}
}
}
@ -234,14 +234,14 @@ RayCastModelHit SceneView::castRay(float x, float y)
ASSERT(scene);
ComponentUID camera_cmp = m_editor.getEditCamera();
Vec2 screen_size = scene->getCameraScreenSize(camera_cmp.handle);
Vec2 screen_size = scene->getCameraScreenSize(camera_cmp.entity);
screen_size.x *= x;
screen_size.y *= y;
Vec3 origin;
Vec3 dir;
scene->getRay(camera_cmp.handle, screen_size, origin, dir);
return scene->castRay(origin, dir, INVALID_COMPONENT);
scene->getRay(camera_cmp.entity, screen_size, origin, dir);
return scene->castRay(origin, dir, INVALID_ENTITY);
}
@ -314,7 +314,8 @@ void SceneView::handleDrop(const char* path, float x, float y)
else if (hit.m_is_hit && PathUtils::hasExtension(path, "mat") && hit.m_mesh)
{
m_editor.selectEntities(&hit.m_entity, 1);
auto* model = m_pipeline->getScene()->getModelInstanceModel(hit.m_component);
RenderScene* scene = m_pipeline->getScene();
Model* model = scene->getModelInstanceModel(hit.m_entity);
int mesh_index = 0;
for (int i = 0; i < model->getMeshCount(); ++i)
{

View file

@ -95,7 +95,7 @@ struct PaintTerrainCommand LUMIX_FINAL : public IEditorCommand
Matrix entity_mtx = editor.getUniverse()->getMatrix(terrain.entity);
entity_mtx.fastInverse();
Vec3 local_pos = entity_mtx.transformPoint(hit_pos);
float terrain_size = static_cast<RenderScene*>(terrain.scene)->getTerrainSize(terrain.handle).x;
float terrain_size = static_cast<RenderScene*>(terrain.scene)->getTerrainSize(terrain.entity).x;
local_pos = local_pos / terrain_size;
local_pos.y = -1;
@ -231,7 +231,7 @@ private:
Material* getMaterial()
{
auto* scene = static_cast<RenderScene*>(m_terrain.scene);
return scene->getTerrainMaterial(m_terrain.handle);
return scene->getTerrainMaterial(m_terrain.entity);
}
@ -571,7 +571,7 @@ private:
}
}
texture->onDataUpdated(m_x, m_y, m_width, m_height);
static_cast<RenderScene*>(m_terrain.scene)->forceGrassUpdate(m_terrain.handle);
static_cast<RenderScene*>(m_terrain.scene)->forceGrassUpdate(m_terrain.entity);
if (m_action_type != TerrainEditor::LAYER && m_action_type != TerrainEditor::COLOR &&
m_action_type != TerrainEditor::ADD_GRASS && m_action_type != TerrainEditor::REMOVE_GRASS)
@ -580,10 +580,9 @@ private:
if (!scene) return;
auto* phy_scene = static_cast<PhysicsScene*>(scene);
ComponentHandle cmp = scene->getComponent(m_terrain.entity, HEIGHTFIELD_TYPE);
if (!cmp.isValid()) return;
if (!scene->getUniverse().hasComponent(m_terrain.entity, HEIGHTFIELD_TYPE)) return;
phy_scene->updateHeighfieldData(cmp, m_x, m_y, m_width, m_height, &data[0], bpp);
phy_scene->updateHeighfieldData(m_terrain.entity, m_x, m_y, m_width, m_height, &data[0], bpp);
}
}
@ -691,7 +690,7 @@ TerrainEditor::~TerrainEditor()
void TerrainEditor::onUniverseDestroyed()
{
m_component.scene = nullptr;
m_component.handle = INVALID_COMPONENT;
m_component.entity = INVALID_ENTITY;
}
@ -769,7 +768,7 @@ TerrainEditor::TerrainEditor(WorldEditor& editor, StudioApp& app)
void TerrainEditor::splitSplatmap(const char* dir)
{
auto* render_scene = (RenderScene*)m_component.scene;
Material* material = render_scene->getTerrainMaterial(m_component.handle);
Material* material = render_scene->getTerrainMaterial(m_component.entity);
if (!material)
{
g_log_error.log("Renderer") << "Terrain has no material";
@ -816,7 +815,7 @@ void TerrainEditor::splitSplatmap(const char* dir)
fs.close(*file);
}
int grasses_count = render_scene->getGrassCount(m_component.handle);
int grasses_count = render_scene->getGrassCount(m_component.entity);
for (int i = 0; i < grasses_count; ++i)
{
StaticString<MAX_PATH_LENGTH> out_path_str(dir, "//grass", i, ".tga");
@ -843,7 +842,7 @@ void TerrainEditor::splitSplatmap(const char* dir)
void TerrainEditor::mergeSplatmap(const char* dir)
{
auto* render_scene = (RenderScene*)m_component.scene;
Material* material = render_scene->getTerrainMaterial(m_component.handle);
Material* material = render_scene->getTerrainMaterial(m_component.entity);
if (!material)
{
g_log_error.log("Renderer") << "Terrain has no material";
@ -965,7 +964,7 @@ void TerrainEditor::mergeSplatmap(const char* dir)
void TerrainEditor::nextTerrainTexture()
{
auto* scene = static_cast<RenderScene*>(m_component.scene);
auto* material = scene->getTerrainMaterial(m_component.handle);
auto* material = scene->getTerrainMaterial(m_component.entity);
Texture* tex = material->getTextureByUniform(TEX_COLOR_UNIFORM);
if (tex)
{
@ -1002,7 +1001,7 @@ void TerrainEditor::decreaseBrushSize()
}
void TerrainEditor::drawCursor(RenderScene& scene, ComponentHandle terrain, const Vec3& center)
void TerrainEditor::drawCursor(RenderScene& scene, Entity terrain, const Vec3& center)
{
PROFILE_FUNCTION();
static const int SLICE_COUNT = 30;
@ -1107,7 +1106,7 @@ u16 TerrainEditor::getHeight(const Vec3& world_pos)
auto* data = (u16*)heightmap->getData();
auto* scene = (RenderScene*)m_component.scene;
float scale = scene->getTerrainXZScale(m_component.handle);
float scale = scene->getTerrainXZScale(m_component.entity);
return data[int(rel_pos.x / scale) + int(rel_pos.z / scale) * heightmap->width];
}
@ -1333,12 +1332,12 @@ void TerrainEditor::paintEntities(const Vec3& hit_pos)
-m_terrain_brush_size,
m_terrain_brush_size);
ComponentUID camera = m_world_editor.getEditCamera();
Entity camera_entity = scene->getCameraEntity(camera.handle);
Entity camera_entity = camera.entity;
Vec3 camera_pos = scene->getUniverse().getPosition(camera_entity);
auto& meshes = scene->getModelInstanceInfos(frustum, camera_pos, camera.handle, ~0ULL);
auto& meshes = scene->getModelInstanceInfos(frustum, camera_pos, camera.entity, ~0ULL);
Vec2 size = scene->getTerrainSize(m_component.handle);
Vec2 size = scene->getTerrainSize(m_component.entity);
float scale = 1.0f - Math::maximum(0.01f, m_terrain_brush_strength);
for (int i = 0; i <= m_terrain_brush_size * m_terrain_brush_size / 1000.0f; ++i)
{
@ -1349,13 +1348,13 @@ void TerrainEditor::paintEntities(const Vec3& hit_pos)
Vec3 terrain_pos = inv_terrain_matrix.transformPoint(pos);
if (terrain_pos.x >= 0 && terrain_pos.z >= 0 && terrain_pos.x <= size.x && terrain_pos.z <= size.y)
{
pos.y = scene->getTerrainHeightAt(m_component.handle, terrain_pos.x, terrain_pos.z) + y;
pos.y = scene->getTerrainHeightAt(m_component.entity, terrain_pos.x, terrain_pos.z) + y;
pos.y += terrain_matrix.getTranslation().y;
Quat rot(0, 0, 0, 1);
if(m_is_align_with_normal)
{
RenderScene* scene = static_cast<RenderScene*>(m_component.scene);
Vec3 normal = scene->getTerrainNormalAt(m_component.handle, pos.x, pos.z);
Vec3 normal = scene->getTerrainNormalAt(m_component.entity, pos.x, pos.z);
Vec3 dir = crossProduct(normal, Vec3(1, 0, 0)).normalized();
Matrix mtx = Matrix::IDENTITY;
mtx.setXVector(crossProduct(normal, dir));
@ -1393,11 +1392,13 @@ void TerrainEditor::paintEntities(const Vec3& hit_pos)
Entity entity = prefab_system.instantiatePrefab(*m_selected_prefabs[random_idx], pos, rot, size);
if (entity.isValid())
{
ComponentHandle cmp = scene->getComponent(entity, MODEL_INSTANCE_TYPE);
Model* model = scene->getModelInstanceModel(cmp);
if (isOBBCollision(*scene, meshes, pos, model, scale))
if (scene->getUniverse().hasComponent(entity, MODEL_INSTANCE_TYPE))
{
m_world_editor.undo();
Model* model = scene->getModelInstanceModel(entity);
if (isOBBCollision(*scene, meshes, pos, model, scale))
{
m_world_editor.undo();
}
}
}
}
@ -1416,8 +1417,8 @@ void TerrainEditor::onMouseMove(int x, int y, int, int)
ComponentUID camera_cmp = m_world_editor.getEditCamera();
RenderScene* scene = static_cast<RenderScene*>(camera_cmp.scene);
Vec3 origin, dir;
scene->getRay(camera_cmp.handle, {(float)x, (float)y}, origin, dir);
RayCastModelHit hit = scene->castRayTerrain(m_component.handle, origin, dir);
scene->getRay(camera_cmp.entity, {(float)x, (float)y}, origin, dir);
RayCastModelHit hit = scene->castRayTerrain(m_component.entity, origin, dir);
if (hit.m_is_hit)
{
bool is_terrain = m_world_editor.getUniverse()->hasComponent(hit.m_entity, TERRAIN_TYPE);
@ -1449,7 +1450,7 @@ void TerrainEditor::onMouseUp(int, int, MouseButton::Value)
Material* TerrainEditor::getMaterial()
{
auto* scene = static_cast<RenderScene*>(m_component.scene);
return scene->getTerrainMaterial(m_component.handle);
return scene->getTerrainMaterial(m_component.entity);
}
@ -1598,7 +1599,7 @@ void TerrainEditor::onGUI()
case GRASS:
{
m_action_type = TerrainEditor::ADD_GRASS;
int type_count = scene->getGrassCount(m_component.handle);
int type_count = scene->getGrassCount(m_component.entity);
for (int i = 0; i < type_count; ++i)
{
if (i % 4 != 0) ImGui::SameLine();
@ -1759,19 +1760,18 @@ void TerrainEditor::onGUI()
for(auto entity : m_world_editor.getSelectedEntities())
{
ComponentHandle terrain = m_world_editor.getUniverse()->getComponent(entity, TERRAIN_TYPE).handle;
if(!terrain.isValid()) continue;
if (!m_world_editor.getUniverse()->hasComponent(entity, TERRAIN_TYPE)) continue;
ComponentUID camera_cmp = m_world_editor.getEditCamera();
RenderScene* scene = static_cast<RenderScene*>(camera_cmp.scene);
Vec3 origin, dir;
scene->getRay(camera_cmp.handle, {(float)mouse_x, (float)mouse_y}, origin, dir);
RayCastModelHit hit = scene->castRayTerrain(terrain, origin, dir);
scene->getRay(camera_cmp.entity, {(float)mouse_x, (float)mouse_y}, origin, dir);
RayCastModelHit hit = scene->castRayTerrain(entity, origin, dir);
if(hit.m_is_hit)
{
Vec3 center = hit.m_origin + hit.m_dir * hit.m_t;
drawCursor(*scene, terrain, center);
drawCursor(*scene, entity, center);
ImGui::TreePop();
ImGui::Indent();
return;

View file

@ -50,7 +50,7 @@ private:
void mergeSplatmap(const char* dir);
void onUniverseDestroyed();
void detectModifiers();
void drawCursor(RenderScene& scene, ComponentHandle cmp, const Vec3& center);
void drawCursor(RenderScene& scene, Entity terrain, const Vec3& center);
Material* getMaterial();
void paint(const Vec3& hit, TerrainEditor::ActionType action_type, bool new_stroke);

View file

@ -41,7 +41,6 @@ struct LUMIX_RENDERER_API RayCastModelHit
Vec3 m_origin;
Vec3 m_dir;
Mesh* m_mesh;
ComponentHandle m_component;
Entity m_entity;
ComponentType m_component_type;
};

View file

@ -251,7 +251,7 @@ struct PipelineImpl LUMIX_FINAL : public Pipeline
struct PointLightShadowmap
{
ComponentHandle light;
Entity light;
FrameBuffer* framebuffer;
Matrix matrices[4];
};
@ -791,10 +791,10 @@ struct PipelineImpl LUMIX_FINAL : public Pipeline
{
if (!m_current_view) return;
if (m_applied_camera == INVALID_COMPONENT) return;
Entity cam = m_scene->getCameraEntity(m_applied_camera);
if (!m_applied_camera.isValid()) return;
Entity cam = m_applied_camera;
Vec3 pos = m_scene->getUniverse().getPosition(cam);
ComponentHandle probe = m_scene->getNearestEnvironmentProbe(pos);
Entity probe = m_scene->getNearestEnvironmentProbe(pos);
m_current_view->command_buffer.beginAppend();
if (probe.isValid())
{
@ -880,17 +880,17 @@ struct PipelineImpl LUMIX_FINAL : public Pipeline
void applyCamera(const char* slot)
{
ComponentHandle cmp = m_scene->getCameraInSlot(slot);
if (!cmp.isValid()) return;
Entity camera = m_scene->getCameraInSlot(slot);
if (!camera.isValid()) return;
m_scene->setCameraScreenSize(cmp, m_width, m_height);
m_applied_camera = cmp;
m_camera_frustum = m_scene->getCameraFrustum(cmp);
m_scene->setCameraScreenSize(camera, m_width, m_height);
m_applied_camera = camera;
m_camera_frustum = m_scene->getCameraFrustum(camera);
Matrix projection_matrix = m_scene->getCameraProjection(cmp);
Matrix projection_matrix = m_scene->getCameraProjection(camera);
Universe& universe = m_scene->getUniverse();
Matrix view = universe.getMatrix(m_scene->getCameraEntity(cmp));
Matrix view = universe.getMatrix(camera);
view.fastInverse();
bgfx::setViewTransform(m_current_view->bgfx_id, &view.m11, &projection_matrix.m11);
bgfx::setViewRect(m_current_view->bgfx_id, 0, 0, (u16)m_width, (u16)m_height);
@ -915,7 +915,7 @@ struct PipelineImpl LUMIX_FINAL : public Pipeline
}
ComponentHandle getAppliedCamera() const override
Entity getAppliedCamera() const override
{
return m_applied_camera;
}
@ -1265,13 +1265,13 @@ struct PipelineImpl LUMIX_FINAL : public Pipeline
void renderLightVolumes(int material_index)
{
PROFILE_FUNCTION();
if (m_applied_camera == INVALID_COMPONENT) return;
if (!m_applied_camera.isValid()) return;
Resource* res = m_scene->getEngine().getLuaResource(material_index);
Material* material = static_cast<Material*>(res);
if (!material->isReady()) return;
IAllocator& frame_allocator = m_renderer.getEngine().getLIFOAllocator();
Array<ComponentHandle> local_lights(frame_allocator);
Array<Entity> local_lights(frame_allocator);
m_scene->getPointLights(m_camera_frustum, local_lights);
PROFILE_INT("light count", local_lights.size());
@ -1363,7 +1363,7 @@ struct PipelineImpl LUMIX_FINAL : public Pipeline
void renderDecalsVolumes()
{
PROFILE_FUNCTION();
if (m_applied_camera == INVALID_COMPONENT) return;
if (!m_applied_camera.isValid()) return;
if (!m_current_view) return;
IAllocator& frame_allocator = m_renderer.getEngine().getLIFOAllocator();
@ -1394,7 +1394,7 @@ struct PipelineImpl LUMIX_FINAL : public Pipeline
}
void renderSpotLightShadowmap(ComponentHandle light)
void renderSpotLightShadowmap(Entity light)
{
newView("point_light", ~0ULL);
@ -1431,7 +1431,7 @@ struct PipelineImpl LUMIX_FINAL : public Pipeline
}
void renderOmniLightShadowmap(ComponentHandle light)
void renderOmniLightShadowmap(Entity light)
{
Entity light_entity = m_scene->getPointLightEntity(light);
Vec3 light_pos = m_scene->getUniverse().getPosition(light_entity);
@ -1516,15 +1516,14 @@ struct PipelineImpl LUMIX_FINAL : public Pipeline
}
void renderLocalLightShadowmaps(ComponentHandle camera, FrameBuffer** fbs, int framebuffers_count)
void renderLocalLightShadowmaps(Entity camera, FrameBuffer** fbs, int framebuffers_count)
{
if (!camera.isValid()) return;
Universe& universe = m_scene->getUniverse();
Entity camera_entity = m_scene->getCameraEntity(camera);
Vec3 camera_pos = universe.getPosition(camera_entity);
Vec3 camera_pos = universe.getPosition(camera);
ComponentHandle lights[16];
Entity lights[16];
int light_count = m_scene->getClosestPointLights(camera_pos, lights, lengthOf(lights));
int fb_index = 0;
@ -1600,12 +1599,12 @@ struct PipelineImpl LUMIX_FINAL : public Pipeline
{
if (!m_current_view) return;
Universe& universe = m_scene->getUniverse();
ComponentHandle light_cmp = m_scene->getActiveGlobalLight();
if (!light_cmp.isValid() || !m_applied_camera.isValid()) return;
Entity light = m_scene->getActiveGlobalLight();
if (!light.isValid() || !m_applied_camera.isValid()) return;
float camera_height = m_scene->getCameraScreenHeight(m_applied_camera);
if (!camera_height) return;
Matrix light_mtx = universe.getMatrix(m_scene->getGlobalLightEntity(light_cmp));
Matrix light_mtx = universe.getMatrix(light);
m_global_light_shadowmap = m_current_framebuffer;
float shadowmap_height = (float)m_current_framebuffer->getHeight();
float shadowmap_width = (float)m_current_framebuffer->getWidth();
@ -1613,7 +1612,7 @@ struct PipelineImpl LUMIX_FINAL : public Pipeline
float viewports_gl[] = { 0, 0.5f, 0.5f, 0.5f, 0, 0, 0.5f, 0};
float camera_fov = m_scene->getCameraFOV(m_applied_camera);
float camera_ratio = m_scene->getCameraScreenWidth(m_applied_camera) / camera_height;
Vec4 cascades = m_scene->getShadowmapCascades(light_cmp);
Vec4 cascades = m_scene->getShadowmapCascades(light);
float split_distances[] = {0.1f, cascades.x, cascades.y, cascades.z, cascades.w};
m_is_rendering_in_shadowmap = true;
bgfx::setViewClear(m_current_view->bgfx_id, BGFX_CLEAR_DEPTH | BGFX_CLEAR_COLOR, 0xffffffff, 1.0f, 0);
@ -1626,7 +1625,7 @@ struct PipelineImpl LUMIX_FINAL : public Pipeline
(u16)(0.5f * shadowmap_height - 2));
Frustum camera_frustum;
Matrix camera_matrix = universe.getMatrix(m_scene->getCameraEntity(m_applied_camera));
Matrix camera_matrix = universe.getMatrix(m_applied_camera);
camera_frustum.computePerspective(camera_matrix.getTranslation(),
-camera_matrix.getZVector(),
camera_matrix.getYVector(),
@ -1856,21 +1855,21 @@ struct PipelineImpl LUMIX_FINAL : public Pipeline
}
void setPointLightUniforms(ComponentHandle light_cmp)
void setPointLightUniforms(Entity light)
{
if (!light_cmp.isValid()) return;
if (!light.isValid()) return;
if (!m_current_view) return;
Universe& universe = m_scene->getUniverse();
Entity light_entity = m_scene->getPointLightEntity(light_cmp);
Entity light_entity = m_scene->getPointLightEntity(light);
Vec3 light_pos = universe.getPosition(light_entity);
Vec3 light_dir = universe.getRotation(light_entity).rotate(Vec3(0, 0, -1));
float fov = m_scene->getLightFOV(light_cmp);
float intensity = m_scene->getPointLightIntensity(light_cmp);
float fov = m_scene->getLightFOV(light);
float intensity = m_scene->getPointLightIntensity(light);
intensity *= intensity;
Vec3 color = m_scene->getPointLightColor(light_cmp) * intensity;
float range = m_scene->getLightRange(light_cmp);
float attenuation = m_scene->getLightAttenuation(light_cmp);
Vec3 color = m_scene->getPointLightColor(light) * intensity;
float range = m_scene->getLightRange(light);
float attenuation = m_scene->getLightAttenuation(light);
Vec4 light_pos_radius(light_pos, range);
Vec4 light_color_attenuation(color, attenuation);
Vec4 light_dir_fov(light_dir, fov);
@ -1880,16 +1879,16 @@ struct PipelineImpl LUMIX_FINAL : public Pipeline
m_current_view->command_buffer.setUniform(m_light_dir_fov_uniform, light_dir_fov);
FrameBuffer* shadowmap = nullptr;
if (m_scene->getLightCastShadows(light_cmp))
if (m_scene->getLightCastShadows(light))
{
for (auto& info : m_point_light_shadowmaps)
{
if (info.light == light_cmp)
if (info.light == light)
{
shadowmap = info.framebuffer;
m_current_view->command_buffer.setUniform(m_shadowmap_matrices_uniform,
&info.matrices[0],
m_scene->getLightFOV(light_cmp) > Math::PI ? 4 : 1);
m_scene->getLightFOV(light) > Math::PI ? 4 : 1);
break;
}
}
@ -2003,7 +2002,7 @@ struct PipelineImpl LUMIX_FINAL : public Pipeline
}
void renderPointLightInfluencedGeometry(ComponentHandle light)
void renderPointLightInfluencedGeometry(Entity light)
{
PROFILE_FUNCTION();
@ -2017,13 +2016,13 @@ struct PipelineImpl LUMIX_FINAL : public Pipeline
{
PROFILE_FUNCTION();
Array<ComponentHandle> lights(m_allocator);
Array<Entity> lights(m_allocator);
m_scene->getPointLights(frustum, lights);
IAllocator& frame_allocator = m_renderer.getEngine().getLIFOAllocator();
m_is_current_light_global = false;
for (int i = 0; i < lights.size(); ++i)
{
ComponentHandle light = lights[i];
Entity light = lights[i];
setPointLightUniforms(light);
{
@ -2034,8 +2033,7 @@ struct PipelineImpl LUMIX_FINAL : public Pipeline
{
Array<TerrainInfo> tmp_terrains(frame_allocator);
Entity camera_entity = m_scene->getCameraEntity(m_applied_camera);
Vec3 lod_ref_point = m_scene->getUniverse().getPosition(camera_entity);
Vec3 lod_ref_point = m_scene->getUniverse().getPosition(m_applied_camera);
Frustum frustum = m_scene->getCameraFrustum(m_applied_camera);
m_scene->getTerrainInfos(frustum, lod_ref_point, tmp_terrains);
renderTerrains(tmp_terrains);
@ -2156,8 +2154,7 @@ struct PipelineImpl LUMIX_FINAL : public Pipeline
float near_plane = m_scene->getCameraNearPlane(m_applied_camera);
float far_plane = m_scene->getCameraFarPlane(m_applied_camera);
float ratio = float(m_width) / m_height;
Entity camera_entity = m_scene->getCameraEntity(m_applied_camera);
Matrix inv_view_matrix = universe.getPositionAndRotation(camera_entity);
Matrix inv_view_matrix = universe.getPositionAndRotation(m_applied_camera);
Matrix view_matrix = inv_view_matrix;
view_matrix.fastInverse();
projection_matrix.setPerspective(fov, ratio, near_plane, far_plane, bgfx::getCaps()->homogeneousDepth);
@ -2192,14 +2189,13 @@ struct PipelineImpl LUMIX_FINAL : public Pipeline
}
void renderAll(const Frustum& frustum, bool render_grass, ComponentHandle camera, u64 layer_mask)
void renderAll(const Frustum& frustum, bool render_grass, Entity camera, u64 layer_mask)
{
PROFILE_FUNCTION();
if (!m_applied_camera.isValid()) return;
Entity camera_entity = m_scene->getCameraEntity(camera);
Vec3 lod_ref_point = m_scene->getUniverse().getPosition(camera_entity);
Vec3 lod_ref_point = m_scene->getUniverse().getPosition(camera);
m_is_current_light_global = true;
m_grasses_buffer.clear();
@ -2248,8 +2244,7 @@ struct PipelineImpl LUMIX_FINAL : public Pipeline
void renderModel(Model& model, Pose* pose, const Matrix& mtx) override
{
Entity camera_entity = m_scene->getCameraEntity(m_applied_camera);
Vec3 camera_pos = m_scene->getUniverse().getPosition(camera_entity);
Vec3 camera_pos = m_scene->getUniverse().getPosition(m_applied_camera);
for (int i = 0; i < model.getMeshCount(); ++i)
{
@ -2682,7 +2677,7 @@ struct PipelineImpl LUMIX_FINAL : public Pipeline
Matrix inv_world_matrix = info.m_world_matrix;
inv_world_matrix.fastInverse();
Vec3 camera_pos =
m_scene->getUniverse().getPosition(m_scene->getCameraEntity(m_applied_camera));
m_scene->getUniverse().getPosition(m_applied_camera);
Vec4 rel_cam_pos(
inv_world_matrix.transformPoint(camera_pos) / info.m_terrain->getXZScale(), 1);
@ -2903,7 +2898,7 @@ struct PipelineImpl LUMIX_FINAL : public Pipeline
if (!m_scene) return false;
m_stats = {};
m_applied_camera = INVALID_COMPONENT;
m_applied_camera = INVALID_ENTITY;
m_global_light_shadowmap = nullptr;
m_current_view = nullptr;
m_view_idx = -1;
@ -2990,7 +2985,7 @@ struct PipelineImpl LUMIX_FINAL : public Pipeline
bool cameraExists(const char* slot_name)
{
return m_scene->getCameraInSlot(slot_name) != INVALID_COMPONENT;
return m_scene->getCameraInSlot(slot_name).isValid();
}
@ -3081,7 +3076,7 @@ struct PipelineImpl LUMIX_FINAL : public Pipeline
FrameBuffer* m_global_light_shadowmap;
InstanceData m_instances_data[128];
int m_instance_data_idx;
ComponentHandle m_applied_camera;
Entity m_applied_camera;
bgfx::VertexBufferHandle m_cube_vb;
bgfx::IndexBufferHandle m_cube_ib;
bool m_is_current_light_global;
@ -3272,7 +3267,7 @@ int renderModels(lua_State* L)
{
auto* pipeline = LuaWrapper::checkArg<PipelineImpl*>(L, 1);
ComponentHandle cam = pipeline->m_applied_camera;
Entity cam = pipeline->m_applied_camera;
pipeline->renderAll(pipeline->m_camera_frustum, true, cam, pipeline->m_layer_mask);
pipeline->m_layer_mask = 0;
@ -3348,7 +3343,7 @@ int renderLocalLightsShadowmaps(lua_State* L)
}
RenderScene* scene = pipeline->m_scene;
ComponentHandle camera = scene->getCameraInSlot(camera_slot);
Entity camera = scene->getCameraInSlot(camera_slot);
pipeline->renderLocalLightShadowmaps(camera, fbs, len);
return 0;

View file

@ -129,7 +129,7 @@ class LUMIX_RENDERER_API Pipeline
virtual Path& getPath() = 0;
virtual void callLuaFunction(const char* func) = 0;
virtual ComponentHandle getAppliedCamera() const = 0;
virtual Entity getAppliedCamera() const = 0;
virtual void render(const bgfx::VertexBufferHandle& vertex_buffer,
const bgfx::IndexBufferHandle& index_buffer,
const bgfx::InstanceDataBuffer& instance_buffer,

File diff suppressed because it is too large Load diff

View file

@ -81,7 +81,7 @@ struct ModelInstance
struct ModelInstanceMesh
{
ComponentHandle model_instance;
Entity model_instance;
Mesh* mesh;
float depth;
};
@ -138,22 +138,22 @@ public:
static void destroyInstance(RenderScene* scene);
static void registerLuaAPI(lua_State* L);
virtual RayCastModelHit castRay(const Vec3& origin, const Vec3& dir, ComponentHandle ignore) = 0;
virtual RayCastModelHit castRayTerrain(ComponentHandle terrain, const Vec3& origin, const Vec3& dir) = 0;
virtual void getRay(ComponentHandle camera, const Vec2& screen_pos, Vec3& origin, Vec3& dir) = 0;
virtual RayCastModelHit castRay(const Vec3& origin, const Vec3& dir, Entity ignore) = 0;
virtual RayCastModelHit castRayTerrain(Entity entity, const Vec3& origin, const Vec3& dir) = 0;
virtual void getRay(Entity entity, const Vec2& screen_pos, Vec3& origin, Vec3& dir) = 0;
virtual Frustum getCameraFrustum(ComponentHandle camera) const = 0;
virtual Frustum getCameraFrustum(ComponentHandle camera, const Vec2& a, const Vec2& b) const = 0;
virtual Frustum getCameraFrustum(Entity entity) const = 0;
virtual Frustum getCameraFrustum(Entity entity, const Vec2& a, const Vec2& b) const = 0;
virtual float getTime() const = 0;
virtual Engine& getEngine() const = 0;
virtual IAllocator& getAllocator() = 0;
virtual Pose* lockPose(ComponentHandle cmp) = 0;
virtual void unlockPose(ComponentHandle cmp, bool changed) = 0;
virtual ComponentHandle getActiveGlobalLight() = 0;
virtual void setActiveGlobalLight(ComponentHandle cmp) = 0;
virtual Vec4 getShadowmapCascades(ComponentHandle cmp) = 0;
virtual void setShadowmapCascades(ComponentHandle cmp, const Vec4& value) = 0;
virtual Pose* lockPose(Entity entity) = 0;
virtual void unlockPose(Entity entity, bool changed) = 0;
virtual Entity getActiveGlobalLight() = 0;
virtual void setActiveGlobalLight(Entity entity) = 0;
virtual Vec4 getShadowmapCascades(Entity entity) = 0;
virtual void setShadowmapCascades(Entity entity, const Vec4& value) = 0;
virtual void addDebugTriangle(const Vec3& p0,
const Vec3& p1,
@ -204,211 +204,206 @@ public:
u32 color,
float life) = 0;
virtual Entity getBoneAttachmentParent(ComponentHandle cmp) = 0;
virtual void setBoneAttachmentParent(ComponentHandle cmp, Entity entity) = 0;
virtual void setBoneAttachmentBone(ComponentHandle cmp, int value) = 0;
virtual int getBoneAttachmentBone(ComponentHandle cmp) = 0;
virtual Vec3 getBoneAttachmentPosition(ComponentHandle cmp) = 0;
virtual void setBoneAttachmentPosition(ComponentHandle cmp, const Vec3& pos) = 0;
virtual Vec3 getBoneAttachmentRotation(ComponentHandle cmp) = 0;
virtual void setBoneAttachmentRotation(ComponentHandle cmp, const Vec3& rot) = 0;
virtual void setBoneAttachmentRotationQuat(ComponentHandle cmp, const Quat& rot) = 0;
virtual Entity getBoneAttachmentParent(Entity entity) = 0;
virtual void setBoneAttachmentParent(Entity entity, Entity parent) = 0;
virtual void setBoneAttachmentBone(Entity entity, int value) = 0;
virtual int getBoneAttachmentBone(Entity entity) = 0;
virtual Vec3 getBoneAttachmentPosition(Entity entity) = 0;
virtual void setBoneAttachmentPosition(Entity entity, const Vec3& pos) = 0;
virtual Vec3 getBoneAttachmentRotation(Entity entity) = 0;
virtual void setBoneAttachmentRotation(Entity entity, const Vec3& rot) = 0;
virtual void setBoneAttachmentRotationQuat(Entity entity, const Quat& rot) = 0;
virtual const Array<DebugTriangle>& getDebugTriangles() const = 0;
virtual const Array<DebugLine>& getDebugLines() const = 0;
virtual const Array<DebugPoint>& getDebugPoints() const = 0;
virtual Matrix getCameraProjection(ComponentHandle camera) = 0;
virtual Matrix getCameraViewProjection(ComponentHandle camera) = 0;
virtual Entity getCameraEntity(ComponentHandle camera) const = 0;
virtual ComponentHandle getCameraInSlot(const char* slot) = 0;
virtual float getCameraFOV(ComponentHandle camera) = 0;
virtual void setCameraFOV(ComponentHandle camera, float fov) = 0;
virtual void setCameraFarPlane(ComponentHandle camera, float far) = 0;
virtual void setCameraNearPlane(ComponentHandle camera, float near) = 0;
virtual float getCameraFarPlane(ComponentHandle camera) = 0;
virtual float getCameraNearPlane(ComponentHandle camera) = 0;
virtual float getCameraScreenWidth(ComponentHandle camera) = 0;
virtual float getCameraScreenHeight(ComponentHandle camera) = 0;
virtual void setCameraSlot(ComponentHandle camera, const char* slot) = 0;
virtual const char* getCameraSlot(ComponentHandle camera) = 0;
virtual void setCameraScreenSize(ComponentHandle camera, int w, int h) = 0;
virtual bool isCameraOrtho(ComponentHandle camera) = 0;
virtual void setCameraOrtho(ComponentHandle camera, bool is_ortho) = 0;
virtual float getCameraOrthoSize(ComponentHandle camera) = 0;
virtual void setCameraOrthoSize(ComponentHandle camera, float value) = 0;
virtual Vec2 getCameraScreenSize(ComponentHandle camera) = 0;
virtual Matrix getCameraProjection(Entity entity) = 0;
virtual Matrix getCameraViewProjection(Entity entity) = 0;
virtual Entity getCameraInSlot(const char* slot) = 0;
virtual float getCameraFOV(Entity entity) = 0;
virtual void setCameraFOV(Entity entity, float fov) = 0;
virtual void setCameraFarPlane(Entity entity, float far) = 0;
virtual void setCameraNearPlane(Entity entity, float near) = 0;
virtual float getCameraFarPlane(Entity entity) = 0;
virtual float getCameraNearPlane(Entity entity) = 0;
virtual float getCameraScreenWidth(Entity entity) = 0;
virtual float getCameraScreenHeight(Entity entity) = 0;
virtual void setCameraSlot(Entity entity, const char* slot) = 0;
virtual const char* getCameraSlot(Entity entity) = 0;
virtual void setCameraScreenSize(Entity entity, int w, int h) = 0;
virtual bool isCameraOrtho(Entity entity) = 0;
virtual void setCameraOrtho(Entity entity, bool is_ortho) = 0;
virtual float getCameraOrthoSize(Entity entity) = 0;
virtual void setCameraOrthoSize(Entity entity, float value) = 0;
virtual Vec2 getCameraScreenSize(Entity entity) = 0;
virtual void setScriptedParticleEmitterMaterialPath(ComponentHandle cmp, const Path& path) = 0;
virtual Path getScriptedParticleEmitterMaterialPath(ComponentHandle cmp) = 0;
virtual void setScriptedParticleEmitterMaterialPath(Entity entity, const Path& path) = 0;
virtual Path getScriptedParticleEmitterMaterialPath(Entity entity) = 0;
virtual const AssociativeArray<Entity, class ScriptedParticleEmitter*>& getScriptedParticleEmitters() const = 0;
virtual class ParticleEmitter* getParticleEmitter(ComponentHandle cmp) = 0;
virtual void resetParticleEmitter(ComponentHandle cmp) = 0;
virtual void updateEmitter(ComponentHandle cmp, float time_delta) = 0;
virtual class ParticleEmitter* getParticleEmitter(Entity entity) = 0;
virtual void resetParticleEmitter(Entity entity) = 0;
virtual void updateEmitter(Entity entity, float time_delta) = 0;
virtual const AssociativeArray<Entity, class ParticleEmitter*>& getParticleEmitters() const = 0;
virtual const Vec2* getParticleEmitterAlpha(ComponentHandle cmp) = 0;
virtual int getParticleEmitterAlphaCount(ComponentHandle cmp) = 0;
virtual const Vec2* getParticleEmitterSize(ComponentHandle cmp) = 0;
virtual int getParticleEmitterSizeCount(ComponentHandle cmp) = 0;
virtual bool getParticleEmitterAutoemit(ComponentHandle cmp) = 0;
virtual bool getParticleEmitterLocalSpace(ComponentHandle cmp) = 0;
virtual Vec3 getParticleEmitterAcceleration(ComponentHandle cmp) = 0;
virtual Vec2 getParticleEmitterLinearMovementX(ComponentHandle cmp) = 0;
virtual Vec2 getParticleEmitterLinearMovementY(ComponentHandle cmp) = 0;
virtual Vec2 getParticleEmitterLinearMovementZ(ComponentHandle cmp) = 0;
virtual Vec2 getParticleEmitterInitialLife(ComponentHandle cmp) = 0;
virtual Int2 getParticleEmitterSpawnCount(ComponentHandle cmp) = 0;
virtual Vec2 getParticleEmitterSpawnPeriod(ComponentHandle cmp) = 0;
virtual Vec2 getParticleEmitterInitialSize(ComponentHandle cmp) = 0;
virtual void setParticleEmitterAutoemit(ComponentHandle cmp, bool autoemit) = 0;
virtual void setParticleEmitterLocalSpace(ComponentHandle cmp, bool autoemit) = 0;
virtual void setParticleEmitterAlpha(ComponentHandle cmp, const Vec2* value, int count) = 0;
virtual void setParticleEmitterSize(ComponentHandle cmp, const Vec2* values, int count) = 0;
virtual void setParticleEmitterAcceleration(ComponentHandle cmp, const Vec3& value) = 0;
virtual void setParticleEmitterLinearMovementX(ComponentHandle cmp, const Vec2& value) = 0;
virtual void setParticleEmitterLinearMovementY(ComponentHandle cmp, const Vec2& value) = 0;
virtual void setParticleEmitterLinearMovementZ(ComponentHandle cmp, const Vec2& value) = 0;
virtual void setParticleEmitterInitialLife(ComponentHandle cmp, const Vec2& value) = 0;
virtual void setParticleEmitterSpawnCount(ComponentHandle cmp, const Int2& value) = 0;
virtual void setParticleEmitterSpawnPeriod(ComponentHandle cmp, const Vec2& value) = 0;
virtual void setParticleEmitterInitialSize(ComponentHandle cmp, const Vec2& value) = 0;
virtual void setParticleEmitterMaterialPath(ComponentHandle cmp, const Path& path) = 0;
virtual void setParticleEmitterSubimageRows(ComponentHandle cmp, const int& value) = 0;
virtual void setParticleEmitterSubimageCols(ComponentHandle cmp, const int& value) = 0;
virtual Path getParticleEmitterMaterialPath(ComponentHandle cmp) = 0;
virtual int getParticleEmitterPlaneCount(ComponentHandle cmp) = 0;
virtual int getParticleEmitterSubimageRows(ComponentHandle cmp) = 0;
virtual int getParticleEmitterSubimageCols(ComponentHandle cmp) = 0;
virtual void addParticleEmitterPlane(ComponentHandle cmp, int index) = 0;
virtual void removeParticleEmitterPlane(ComponentHandle cmp, int index) = 0;
virtual Entity getParticleEmitterPlaneEntity(ComponentHandle cmp, int index) = 0;
virtual void setParticleEmitterPlaneEntity(ComponentHandle cmp, int index, Entity entity) = 0;
virtual float getParticleEmitterPlaneBounce(ComponentHandle cmp) = 0;
virtual void setParticleEmitterPlaneBounce(ComponentHandle cmp, float value) = 0;
virtual float getParticleEmitterShapeRadius(ComponentHandle cmp) = 0;
virtual void setParticleEmitterShapeRadius(ComponentHandle cmp, float value) = 0;
virtual const Vec2* getParticleEmitterAlpha(Entity entity) = 0;
virtual int getParticleEmitterAlphaCount(Entity entity) = 0;
virtual const Vec2* getParticleEmitterSize(Entity entity) = 0;
virtual int getParticleEmitterSizeCount(Entity entity) = 0;
virtual bool getParticleEmitterAutoemit(Entity entity) = 0;
virtual bool getParticleEmitterLocalSpace(Entity entity) = 0;
virtual Vec3 getParticleEmitterAcceleration(Entity entity) = 0;
virtual Vec2 getParticleEmitterLinearMovementX(Entity entity) = 0;
virtual Vec2 getParticleEmitterLinearMovementY(Entity entity) = 0;
virtual Vec2 getParticleEmitterLinearMovementZ(Entity entity) = 0;
virtual Vec2 getParticleEmitterInitialLife(Entity entity) = 0;
virtual Int2 getParticleEmitterSpawnCount(Entity entity) = 0;
virtual Vec2 getParticleEmitterSpawnPeriod(Entity entity) = 0;
virtual Vec2 getParticleEmitterInitialSize(Entity entity) = 0;
virtual void setParticleEmitterAutoemit(Entity entity, bool autoemit) = 0;
virtual void setParticleEmitterLocalSpace(Entity entity, bool autoemit) = 0;
virtual void setParticleEmitterAlpha(Entity entity, const Vec2* value, int count) = 0;
virtual void setParticleEmitterSize(Entity entity, const Vec2* values, int count) = 0;
virtual void setParticleEmitterAcceleration(Entity entity, const Vec3& value) = 0;
virtual void setParticleEmitterLinearMovementX(Entity entity, const Vec2& value) = 0;
virtual void setParticleEmitterLinearMovementY(Entity entity, const Vec2& value) = 0;
virtual void setParticleEmitterLinearMovementZ(Entity entity, const Vec2& value) = 0;
virtual void setParticleEmitterInitialLife(Entity entity, const Vec2& value) = 0;
virtual void setParticleEmitterSpawnCount(Entity entity, const Int2& value) = 0;
virtual void setParticleEmitterSpawnPeriod(Entity entity, const Vec2& value) = 0;
virtual void setParticleEmitterInitialSize(Entity entity, const Vec2& value) = 0;
virtual void setParticleEmitterMaterialPath(Entity entity, const Path& path) = 0;
virtual void setParticleEmitterSubimageRows(Entity entity, const int& value) = 0;
virtual void setParticleEmitterSubimageCols(Entity entity, const int& value) = 0;
virtual Path getParticleEmitterMaterialPath(Entity entity) = 0;
virtual int getParticleEmitterPlaneCount(Entity entity) = 0;
virtual int getParticleEmitterSubimageRows(Entity entity) = 0;
virtual int getParticleEmitterSubimageCols(Entity entity) = 0;
virtual void addParticleEmitterPlane(Entity entity, int index) = 0;
virtual void removeParticleEmitterPlane(Entity entity, int index) = 0;
virtual Entity getParticleEmitterPlaneEntity(Entity entity, int index) = 0;
virtual void setParticleEmitterPlaneEntity(Entity module, int index, Entity entity) = 0;
virtual float getParticleEmitterPlaneBounce(Entity entity) = 0;
virtual void setParticleEmitterPlaneBounce(Entity entity, float value) = 0;
virtual float getParticleEmitterShapeRadius(Entity entity) = 0;
virtual void setParticleEmitterShapeRadius(Entity entity, float value) = 0;
virtual int getParticleEmitterAttractorCount(ComponentHandle cmp) = 0;
virtual void addParticleEmitterAttractor(ComponentHandle cmp, int index) = 0;
virtual void removeParticleEmitterAttractor(ComponentHandle cmp, int index) = 0;
virtual Entity getParticleEmitterAttractorEntity(ComponentHandle cmp, int index) = 0;
virtual void setParticleEmitterAttractorEntity(ComponentHandle cmp,
virtual int getParticleEmitterAttractorCount(Entity entity) = 0;
virtual void addParticleEmitterAttractor(Entity entity, int index) = 0;
virtual void removeParticleEmitterAttractor(Entity entity, int index) = 0;
virtual Entity getParticleEmitterAttractorEntity(Entity entity, int index) = 0;
virtual void setParticleEmitterAttractorEntity(Entity module,
int index,
Entity entity) = 0;
virtual float getParticleEmitterAttractorForce(ComponentHandle cmp) = 0;
virtual void setParticleEmitterAttractorForce(ComponentHandle cmp, float value) = 0;
virtual float getParticleEmitterAttractorForce(Entity entity) = 0;
virtual void setParticleEmitterAttractorForce(Entity entity, float value) = 0;
virtual void enableModelInstance(ComponentHandle cmp, bool enable) = 0;
virtual bool isModelInstanceEnabled(ComponentHandle cmp) = 0;
virtual ComponentHandle getModelInstanceComponent(Entity entity) = 0;
virtual ModelInstance* getModelInstance(ComponentHandle cmp) = 0;
virtual void enableModelInstance(Entity entity, bool enable) = 0;
virtual bool isModelInstanceEnabled(Entity entity) = 0;
virtual ModelInstance* getModelInstance(Entity entity) = 0;
virtual ModelInstance* getModelInstances() = 0;
virtual bool getModelInstanceKeepSkin(ComponentHandle cmp) = 0;
virtual void setModelInstanceKeepSkin(ComponentHandle cmp, bool keep) = 0;
virtual Path getModelInstancePath(ComponentHandle cmp) = 0;
virtual void setModelInstanceMaterial(ComponentHandle cmp, int index, const Path& path) = 0;
virtual Path getModelInstanceMaterial(ComponentHandle cmp, int index) = 0;
virtual int getModelInstanceMaterialsCount(ComponentHandle cmp) = 0;
virtual void setModelInstancePath(ComponentHandle cmp, const Path& path) = 0;
virtual bool getModelInstanceKeepSkin(Entity entity) = 0;
virtual void setModelInstanceKeepSkin(Entity entity, bool keep) = 0;
virtual Path getModelInstancePath(Entity entity) = 0;
virtual void setModelInstanceMaterial(Entity entity, int index, const Path& path) = 0;
virtual Path getModelInstanceMaterial(Entity entity, int index) = 0;
virtual int getModelInstanceMaterialsCount(Entity entity) = 0;
virtual void setModelInstancePath(Entity entity, const Path& path) = 0;
virtual Array<Array<ModelInstanceMesh>>& getModelInstanceInfos(const Frustum& frustum,
const Vec3& lod_ref_point,
ComponentHandle camera,
Entity entity,
u64 layer_mask) = 0;
virtual void getModelInstanceEntities(const Frustum& frustum, Array<Entity>& entities) = 0;
virtual Entity getModelInstanceEntity(ComponentHandle cmp) = 0;
virtual ComponentHandle getFirstModelInstance() = 0;
virtual ComponentHandle getNextModelInstance(ComponentHandle cmp) = 0;
virtual Model* getModelInstanceModel(ComponentHandle cmp) = 0;
virtual Entity getFirstModelInstance() = 0;
virtual Entity getNextModelInstance(Entity entity) = 0;
virtual Model* getModelInstanceModel(Entity entity) = 0;
virtual void setDecalMaterialPath(ComponentHandle cmp, const Path& path) = 0;
virtual Path getDecalMaterialPath(ComponentHandle cmp) = 0;
virtual void setDecalScale(ComponentHandle cmp, const Vec3& value) = 0;
virtual Vec3 getDecalScale(ComponentHandle cmp) = 0;
virtual void setDecalMaterialPath(Entity entity, const Path& path) = 0;
virtual Path getDecalMaterialPath(Entity entity) = 0;
virtual void setDecalScale(Entity entity, const Vec3& value) = 0;
virtual Vec3 getDecalScale(Entity entity) = 0;
virtual void getDecals(const Frustum& frustum, Array<DecalInfo>& decals) = 0;
virtual void getGrassInfos(const Frustum& frustum,
ComponentHandle camera,
Entity entity,
Array<GrassInfo>& infos) = 0;
virtual void forceGrassUpdate(ComponentHandle cmp) = 0;
virtual void forceGrassUpdate(Entity entity) = 0;
virtual void getTerrainInfos(const Frustum& frustum, const Vec3& lod_ref_point, Array<TerrainInfo>& infos) = 0;
virtual float getTerrainHeightAt(ComponentHandle cmp, float x, float z) = 0;
virtual Vec3 getTerrainNormalAt(ComponentHandle cmp, float x, float z) = 0;
virtual void setTerrainMaterialPath(ComponentHandle cmp, const Path& path) = 0;
virtual Path getTerrainMaterialPath(ComponentHandle cmp) = 0;
virtual Material* getTerrainMaterial(ComponentHandle cmp) = 0;
virtual void setTerrainXZScale(ComponentHandle cmp, float scale) = 0;
virtual float getTerrainXZScale(ComponentHandle cmp) = 0;
virtual void setTerrainYScale(ComponentHandle cmp, float scale) = 0;
virtual float getTerrainYScale(ComponentHandle cmp) = 0;
virtual Vec2 getTerrainSize(ComponentHandle cmp) = 0;
virtual AABB getTerrainAABB(ComponentHandle cmp) = 0;
virtual ComponentHandle getTerrainComponent(Entity entity) = 0;
virtual Entity getTerrainEntity(ComponentHandle cmp) = 0;
virtual Vec2 getTerrainResolution(ComponentHandle cmp) = 0;
virtual ComponentHandle getFirstTerrain() = 0;
virtual ComponentHandle getNextTerrain(ComponentHandle cmp) = 0;
virtual float getTerrainHeightAt(Entity entity, float x, float z) = 0;
virtual Vec3 getTerrainNormalAt(Entity entity, float x, float z) = 0;
virtual void setTerrainMaterialPath(Entity entity, const Path& path) = 0;
virtual Path getTerrainMaterialPath(Entity entity) = 0;
virtual Material* getTerrainMaterial(Entity entity) = 0;
virtual void setTerrainXZScale(Entity entity, float scale) = 0;
virtual float getTerrainXZScale(Entity entity) = 0;
virtual void setTerrainYScale(Entity entity, float scale) = 0;
virtual float getTerrainYScale(Entity entity) = 0;
virtual Vec2 getTerrainSize(Entity entity) = 0;
virtual AABB getTerrainAABB(Entity entity) = 0;
virtual Entity getTerrainEntity(Entity entity) = 0;
virtual Vec2 getTerrainResolution(Entity entity) = 0;
virtual Entity getFirstTerrain() = 0;
virtual Entity getNextTerrain(Entity entity) = 0;
virtual bool isGrassEnabled() const = 0;
virtual int getGrassRotationMode(ComponentHandle cmp, int index) = 0;
virtual void setGrassRotationMode(ComponentHandle cmp, int index, int value) = 0;
virtual float getGrassDistance(ComponentHandle cmp, int index) = 0;
virtual void setGrassDistance(ComponentHandle cmp, int index, float value) = 0;
virtual int getGrassRotationMode(Entity entity, int index) = 0;
virtual void setGrassRotationMode(Entity entity, int index, int value) = 0;
virtual float getGrassDistance(Entity entity, int index) = 0;
virtual void setGrassDistance(Entity entity, int index, float value) = 0;
virtual void enableGrass(bool enabled) = 0;
virtual void setGrassPath(ComponentHandle cmp, int index, const Path& path) = 0;
virtual Path getGrassPath(ComponentHandle cmp, int index) = 0;
virtual void setGrassDensity(ComponentHandle cmp, int index, int density) = 0;
virtual int getGrassDensity(ComponentHandle cmp, int index) = 0;
virtual int getGrassCount(ComponentHandle cmp) = 0;
virtual void addGrass(ComponentHandle cmp, int index) = 0;
virtual void removeGrass(ComponentHandle cmp, int index) = 0;
virtual void setGrassPath(Entity entity, int index, const Path& path) = 0;
virtual Path getGrassPath(Entity entity, int index) = 0;
virtual void setGrassDensity(Entity entity, int index, int density) = 0;
virtual int getGrassDensity(Entity entity, int index) = 0;
virtual int getGrassCount(Entity entity) = 0;
virtual void addGrass(Entity entity, int index) = 0;
virtual void removeGrass(Entity entity, int index) = 0;
virtual int getClosestPointLights(const Vec3& pos, ComponentHandle* lights, int max_lights) = 0;
virtual void getPointLights(const Frustum& frustum, Array<ComponentHandle>& lights) = 0;
virtual void getPointLightInfluencedGeometry(ComponentHandle light_cmp,
Array<ModelInstanceMesh>& infos) = 0;
virtual void getPointLightInfluencedGeometry(ComponentHandle light_cmp,
virtual int getClosestPointLights(const Vec3& pos, Entity* lights, int max_lights) = 0;
virtual void getPointLights(const Frustum& frustum, Array<Entity>& lights) = 0;
virtual void getPointLightInfluencedGeometry(Entity light, Array<ModelInstanceMesh>& infos) = 0;
virtual void getPointLightInfluencedGeometry(Entity light,
const Frustum& frustum,
Array<ModelInstanceMesh>& infos) = 0;
virtual void setLightCastShadows(ComponentHandle cmp, bool cast_shadows) = 0;
virtual bool getLightCastShadows(ComponentHandle cmp) = 0;
virtual float getLightAttenuation(ComponentHandle cmp) = 0;
virtual void setLightAttenuation(ComponentHandle cmp, float attenuation) = 0;
virtual float getLightFOV(ComponentHandle cmp) = 0;
virtual void setLightFOV(ComponentHandle cmp, float fov) = 0;
virtual float getLightRange(ComponentHandle cmp) = 0;
virtual void setLightRange(ComponentHandle cmp, float value) = 0;
virtual void setPointLightIntensity(ComponentHandle cmp, float intensity) = 0;
virtual void setGlobalLightIntensity(ComponentHandle cmp, float intensity) = 0;
virtual void setGlobalLightIndirectIntensity(ComponentHandle cmp, float intensity) = 0;
virtual void setPointLightColor(ComponentHandle cmp, const Vec3& color) = 0;
virtual void setGlobalLightColor(ComponentHandle cmp, const Vec3& color) = 0;
virtual void setFogDensity(ComponentHandle cmp, float density) = 0;
virtual void setFogColor(ComponentHandle cmp, const Vec3& color) = 0;
virtual float getPointLightIntensity(ComponentHandle cmp) = 0;
virtual Entity getPointLightEntity(ComponentHandle cmp) const = 0;
virtual Entity getGlobalLightEntity(ComponentHandle cmp) const = 0;
virtual float getGlobalLightIntensity(ComponentHandle cmp) = 0;
virtual float getGlobalLightIndirectIntensity(ComponentHandle cmp) = 0;
virtual Vec3 getPointLightColor(ComponentHandle cmp) = 0;
virtual Vec3 getGlobalLightColor(ComponentHandle cmp) = 0;
virtual float getFogDensity(ComponentHandle cmp) = 0;
virtual float getFogBottom(ComponentHandle cmp) = 0;
virtual float getFogHeight(ComponentHandle cmp) = 0;
virtual void setFogBottom(ComponentHandle cmp, float value) = 0;
virtual void setFogHeight(ComponentHandle cmp, float value) = 0;
virtual Vec3 getFogColor(ComponentHandle cmp) = 0;
virtual Vec3 getPointLightSpecularColor(ComponentHandle cmp) = 0;
virtual void setPointLightSpecularColor(ComponentHandle cmp, const Vec3& color) = 0;
virtual float getPointLightSpecularIntensity(ComponentHandle cmp) = 0;
virtual void setPointLightSpecularIntensity(ComponentHandle cmp, float color) = 0;
virtual void setLightCastShadows(Entity entity, bool cast_shadows) = 0;
virtual bool getLightCastShadows(Entity entity) = 0;
virtual float getLightAttenuation(Entity entity) = 0;
virtual void setLightAttenuation(Entity entity, float attenuation) = 0;
virtual float getLightFOV(Entity entity) = 0;
virtual void setLightFOV(Entity entity, float fov) = 0;
virtual float getLightRange(Entity entity) = 0;
virtual void setLightRange(Entity entity, float value) = 0;
virtual void setPointLightIntensity(Entity entity, float intensity) = 0;
virtual void setGlobalLightIntensity(Entity entity, float intensity) = 0;
virtual void setGlobalLightIndirectIntensity(Entity entity, float intensity) = 0;
virtual void setPointLightColor(Entity entity, const Vec3& color) = 0;
virtual void setGlobalLightColor(Entity entity, const Vec3& color) = 0;
virtual void setFogDensity(Entity entity, float density) = 0;
virtual void setFogColor(Entity entity, const Vec3& color) = 0;
virtual float getPointLightIntensity(Entity entity) = 0;
virtual Entity getPointLightEntity(Entity entity) const = 0;
virtual Entity getGlobalLightEntity(Entity entity) const = 0;
virtual float getGlobalLightIntensity(Entity entity) = 0;
virtual float getGlobalLightIndirectIntensity(Entity entity) = 0;
virtual Vec3 getPointLightColor(Entity entity) = 0;
virtual Vec3 getGlobalLightColor(Entity entity) = 0;
virtual float getFogDensity(Entity entity) = 0;
virtual float getFogBottom(Entity entity) = 0;
virtual float getFogHeight(Entity entity) = 0;
virtual void setFogBottom(Entity entity, float value) = 0;
virtual void setFogHeight(Entity entity, float value) = 0;
virtual Vec3 getFogColor(Entity entity) = 0;
virtual Vec3 getPointLightSpecularColor(Entity entity) = 0;
virtual void setPointLightSpecularColor(Entity entity, const Vec3& color) = 0;
virtual float getPointLightSpecularIntensity(Entity entity) = 0;
virtual void setPointLightSpecularIntensity(Entity entity, float color) = 0;
virtual Texture* getEnvironmentProbeTexture(ComponentHandle cmp) const = 0;
virtual Texture* getEnvironmentProbeIrradiance(ComponentHandle cmp) const = 0;
virtual Texture* getEnvironmentProbeRadiance(ComponentHandle cmp) const = 0;
virtual void reloadEnvironmentProbe(ComponentHandle cmp) = 0;
virtual ComponentHandle getNearestEnvironmentProbe(const Vec3& pos) const = 0;
virtual u64 getEnvironmentProbeGUID(ComponentHandle cmp) const = 0;
virtual Texture* getEnvironmentProbeTexture(Entity entity) const = 0;
virtual Texture* getEnvironmentProbeIrradiance(Entity entity) const = 0;
virtual Texture* getEnvironmentProbeRadiance(Entity entity) const = 0;
virtual void reloadEnvironmentProbe(Entity entity) = 0;
virtual Entity getNearestEnvironmentProbe(const Vec3& pos) const = 0;
virtual u64 getEnvironmentProbeGUID(Entity entity) const = 0;
protected:
virtual ~RenderScene() {}

View file

@ -84,6 +84,9 @@ static const char* getGrassRotationModeName(int index)
}
static const ComponentType MODEL_INSTANCE_TYPE = Reflection::getComponentType("renderable");
struct BoneProperty : Reflection::IEnumProperty
{
BoneProperty() { name = "Bone"; }
@ -92,7 +95,7 @@ struct BoneProperty : Reflection::IEnumProperty
void getValue(ComponentUID cmp, int index, OutputBlob& stream) const override
{
RenderScene* scene = static_cast<RenderScene*>(cmp.scene);
int value = scene->getBoneAttachmentBone(cmp.handle);
int value = scene->getBoneAttachmentBone(cmp.entity);
stream.write(value);
}
@ -101,26 +104,27 @@ struct BoneProperty : Reflection::IEnumProperty
{
RenderScene* scene = static_cast<RenderScene*>(cmp.scene);
int value = stream.read<int>();
scene->setBoneAttachmentBone(cmp.handle, value);
scene->setBoneAttachmentBone(cmp.entity, value);
}
ComponentHandle getModelInstance(RenderScene* render_scene, ComponentHandle bone_attachment_cmp) const
Entity getModelInstance(RenderScene* render_scene, Entity bone_attachment) const
{
Entity parent_entity = render_scene->getBoneAttachmentParent(bone_attachment_cmp);
if (parent_entity == INVALID_ENTITY) return INVALID_COMPONENT;
ComponentHandle model_instance = render_scene->getModelInstanceComponent(parent_entity);
return model_instance;
Entity parent_entity = render_scene->getBoneAttachmentParent(bone_attachment);
if (parent_entity == INVALID_ENTITY) return INVALID_ENTITY;
return render_scene->getUniverse().hasComponent(parent_entity, MODEL_INSTANCE_TYPE) ? parent_entity : INVALID_ENTITY;
}
int getEnumCount(ComponentUID cmp) const override
{
RenderScene* render_scene = static_cast<RenderScene*>(cmp.scene);
ComponentHandle model_instance = getModelInstance(render_scene, cmp.handle);
if (model_instance == INVALID_COMPONENT) return 0;
Entity model_instance = getModelInstance(render_scene, cmp.entity);
if (!model_instance.isValid()) return 0;
auto* model = render_scene->getModelInstanceModel(model_instance);
if (!model || !model->isReady()) return 0;
return model->getBoneCount();
}
@ -128,10 +132,12 @@ struct BoneProperty : Reflection::IEnumProperty
const char* getEnumName(ComponentUID cmp, int index) const override
{
RenderScene* render_scene = static_cast<RenderScene*>(cmp.scene);
ComponentHandle model_instance = getModelInstance(render_scene, cmp.handle);
if (model_instance == INVALID_COMPONENT) return "";
Entity model_instance = getModelInstance(render_scene, cmp.entity);
if (!model_instance.isValid()) return "";
auto* model = render_scene->getModelInstanceModel(model_instance);
if (!model) return "";
return model->getBone(index).name.c_str();
}
};

View file

@ -365,7 +365,7 @@ void Terrain::forceGrassUpdate()
}
}
Array<Terrain::GrassQuad*>& Terrain::getQuads(ComponentHandle camera)
Array<Terrain::GrassQuad*>& Terrain::getQuads(Entity camera)
{
int quads_index = m_grass_quads.find(camera);
if (quads_index < 0)
@ -459,14 +459,13 @@ void Terrain::generateGrassTypeQuad(GrassPatch& patch, const Matrix& terrain_mat
}
void Terrain::updateGrass(ComponentHandle camera)
void Terrain::updateGrass(Entity camera)
{
PROFILE_FUNCTION();
if (!m_splatmap) return;
Universe& universe = m_scene.getUniverse();
Entity camera_entity = m_scene.getCameraEntity(camera);
Vec3 camera_pos = universe.getPosition(camera_entity);
Vec3 camera_pos = universe.getPosition(camera);
if ((m_last_camera_position[camera] - camera_pos).length() <= FLT_MIN && !m_force_grass_update) return;
m_last_camera_position[camera] = camera_pos;
@ -555,13 +554,12 @@ void Terrain::grassLoaded(Resource::State, Resource::State, Resource&)
}
void Terrain::getGrassInfos(const Frustum& frustum, Array<GrassInfo>& infos, ComponentHandle camera)
void Terrain::getGrassInfos(const Frustum& frustum, Array<GrassInfo>& infos, Entity camera)
{
if (!m_material || !m_material->isReady()) return;
Universe& universe = m_scene.getUniverse();
Entity camera_entity = m_scene.getCameraEntity(camera);
Vec3 camera_pos = universe.getPosition(camera_entity);
Vec3 camera_pos = universe.getPosition(camera);
updateGrass(camera);
Array<GrassQuad*>& quads = getQuads(camera);
@ -616,7 +614,6 @@ void Terrain::setMaterial(Material* material)
void Terrain::deserialize(InputBlob& serializer, Universe& universe, RenderScene& scene)
{
serializer.read(m_entity);
ComponentHandle cmp = {m_entity.index};
serializer.read(m_layer_mask);
char path[MAX_PATH_LENGTH];
serializer.readString(path, MAX_PATH_LENGTH);
@ -643,7 +640,7 @@ void Terrain::deserialize(InputBlob& serializer, Universe& universe, RenderScene
serializer.read(m_grass_types[i].m_rotation_mode);
setGrassTypePath(i, Path(path));
}
universe.onComponentCreated(m_entity, TERRAIN_HASH, &scene, cmp);
universe.onComponentCreated(m_entity, TERRAIN_HASH, &scene);
}

View file

@ -117,7 +117,7 @@ class Terrain
void setMaterial(Material* material);
void getInfos(Array<TerrainInfo>& infos, const Frustum& frustum, const Vec3& lod_ref_point);
void getGrassInfos(const Frustum& frustum, Array<GrassInfo>& infos, ComponentHandle camera);
void getGrassInfos(const Frustum& frustum, Array<GrassInfo>& infos, Entity camera);
RayCastModelHit castRay(const Vec3& origin, const Vec3& dir);
void serialize(OutputBlob& serializer);
@ -128,9 +128,9 @@ class Terrain
void forceGrassUpdate();
private:
Array<Terrain::GrassQuad*>& getQuads(ComponentHandle camera);
Array<Terrain::GrassQuad*>& getQuads(Entity camera);
TerrainQuad* generateQuadTree(float size);
void updateGrass(ComponentHandle camera);
void updateGrass(Entity camera);
void generateGrassTypeQuad(GrassPatch& patch, const Matrix& terrain_matrix, const Vec2& quad_pos_hm_space);
void generateGeometry();
void onMaterialLoaded(Resource::State, Resource::State new_state, Resource&);
@ -151,8 +151,8 @@ class Terrain
Texture* m_detail_texture;
RenderScene& m_scene;
Array<GrassType> m_grass_types;
AssociativeArray<ComponentHandle, Array<GrassQuad*> > m_grass_quads;
AssociativeArray<ComponentHandle, Vec3> m_last_camera_position;
AssociativeArray<Entity, Array<GrassQuad*> > m_grass_quads;
AssociativeArray<Entity, Vec3> m_last_camera_position;
bool m_force_grass_update;
Renderer& m_renderer;
};

View file

@ -42,7 +42,7 @@ namespace
DefaultAllocator allocator;
JobSystem::init(allocator);
Array<Sphere> spheres(allocator);
Array<ComponentHandle> model_instances(allocator);
Array<Entity> model_instances(allocator);
int model_instance = 0;
for(float i = 0.f; i < 30000000.0f; i += 15.f)
{