ComponentHandle refactor

This commit is contained in:
Mikulas Florek 2016-06-22 15:05:19 +02:00
parent ee5386fa6d
commit db2d9af58f
48 changed files with 1499 additions and 1443 deletions

View file

@ -92,21 +92,21 @@ struct AnimationSceneImpl : public AnimationScene
}
float getAnimableTime(ComponentIndex cmp) override
float getAnimableTime(ComponentHandle cmp) override
{
return m_animables[cmp].time;
return m_animables[cmp.index].time;
}
void setAnimableTime(ComponentIndex cmp, float time) override
void setAnimableTime(ComponentHandle cmp, float time) override
{
m_animables[cmp].time = time;
m_animables[cmp.index].time = time;
}
Animation* getAnimableAnimation(ComponentIndex cmp) override
Animation* getAnimableAnimation(ComponentHandle cmp) override
{
return m_animables[cmp].animation;
return m_animables[cmp.index].animation;
}
@ -115,12 +115,12 @@ struct AnimationSceneImpl : public AnimationScene
Universe& getUniverse() override { return m_universe; }
ComponentIndex getComponent(Entity entity, ComponentType type) override
ComponentHandle getComponent(Entity entity, ComponentType type) override
{
ASSERT(ownComponentType(type));
for (int i = 0; i < m_animables.size(); ++i)
{
if ((m_animables[i].flags & Animable::FREE) == 0 && m_animables[i].entity == entity) return i;
if ((m_animables[i].flags & Animable::FREE) == 0 && m_animables[i].entity == entity) return {i};
}
return INVALID_COMPONENT;
}
@ -129,7 +129,7 @@ struct AnimationSceneImpl : public AnimationScene
bool ownComponentType(ComponentType type) const override { return type == ANIMABLE_TYPE; }
ComponentIndex createComponent(ComponentType type, Entity entity) override
ComponentHandle createComponent(ComponentType type, Entity entity) override
{
if (type == ANIMABLE_TYPE) return createAnimable(entity);
return INVALID_COMPONENT;
@ -146,13 +146,13 @@ struct AnimationSceneImpl : public AnimationScene
}
void destroyComponent(ComponentIndex component, ComponentType type) override
void destroyComponent(ComponentHandle component, ComponentType type) override
{
if (type == ANIMABLE_TYPE)
{
unloadAnimation(m_animables[component].animation);
m_animables[component].flags |= Animable::FREE;
m_universe.destroyComponent(m_animables[component].entity, type, this, component);
unloadAnimation(m_animables[component.index].animation);
m_animables[component.index].flags |= Animable::FREE;
m_universe.destroyComponent(m_animables[component.index].entity, type, this, component);
}
}
@ -216,38 +216,38 @@ struct AnimationSceneImpl : public AnimationScene
m_animables[i].animation = path[0] == '\0' ? nullptr : loadAnimation(Path(path));
if ((m_animables[i].flags & Animable::FREE) == 0)
{
m_universe.addComponent(m_animables[i].entity, ANIMABLE_TYPE, this, i);
m_universe.addComponent(m_animables[i].entity, ANIMABLE_TYPE, this, {i});
}
}
}
float getTimeScale(ComponentIndex cmp) { return m_animables[cmp].time_scale; }
void setTimeScale(ComponentIndex cmp, float time_scale) { m_animables[cmp].time_scale = time_scale; }
float getStartTime(ComponentIndex cmp) { return m_animables[cmp].start_time; }
void setStartTime(ComponentIndex cmp, float time) { m_animables[cmp].start_time = time; }
float getTimeScale(ComponentHandle cmp) { return m_animables[cmp.index].time_scale; }
void setTimeScale(ComponentHandle cmp, float time_scale) { m_animables[cmp.index].time_scale = time_scale; }
float getStartTime(ComponentHandle cmp) { return m_animables[cmp.index].start_time; }
void setStartTime(ComponentHandle cmp, float time) { m_animables[cmp.index].start_time = time; }
Path getAnimation(ComponentIndex cmp)
Path getAnimation(ComponentHandle cmp)
{
return m_animables[cmp].animation ? m_animables[cmp].animation->getPath() : Path("");
return m_animables[cmp.index].animation ? m_animables[cmp.index].animation->getPath() : Path("");
}
void setAnimation(ComponentIndex cmp, const Path& path)
void setAnimation(ComponentHandle cmp, const Path& path)
{
unloadAnimation(m_animables[cmp].animation);
m_animables[cmp].animation = loadAnimation(path);
m_animables[cmp].time = 0;
unloadAnimation(m_animables[cmp.index].animation);
m_animables[cmp.index].animation = loadAnimation(path);
m_animables[cmp.index].time = 0;
}
void updateAnimable(ComponentIndex cmp, float time_delta) override
void updateAnimable(ComponentHandle cmp, float time_delta) override
{
Animable& animable = m_animables[cmp];
Animable& animable = m_animables[cmp.index];
if ((animable.flags & Animable::FREE) != 0) return;
if (!animable.animation || !animable.animation->isReady()) return;
ComponentIndex renderable = m_render_scene->getRenderableComponent(animable.entity);
ComponentHandle renderable = m_render_scene->getRenderableComponent(animable.entity);
if (renderable == INVALID_COMPONENT) return;
auto* pose = m_render_scene->getPose(renderable);
@ -277,7 +277,7 @@ struct AnimationSceneImpl : public AnimationScene
for (int i = 0, c = m_animables.size(); i < c; ++i)
{
AnimationSceneImpl::updateAnimable(i, time_delta);
AnimationSceneImpl::updateAnimable({i}, time_delta);
}
}
@ -289,7 +289,7 @@ struct AnimationSceneImpl : public AnimationScene
}
ComponentIndex createAnimable(Entity entity)
ComponentHandle createAnimable(Entity entity)
{
Animable* src = nullptr;
int cmp = m_animables.size();
@ -310,8 +310,8 @@ struct AnimationSceneImpl : public AnimationScene
animable.time_scale = 1;
animable.start_time = 0;
m_universe.addComponent(entity, ANIMABLE_TYPE, this, cmp);
return cmp;
m_universe.addComponent(entity, ANIMABLE_TYPE, this, {cmp});
return {cmp};
}

View file

@ -12,10 +12,10 @@ namespace Lumix
class AnimationScene : public IScene
{
public:
virtual class Animation* getAnimableAnimation(ComponentIndex cmp) = 0;
virtual float getAnimableTime(ComponentIndex cmp) = 0;
virtual void setAnimableTime(ComponentIndex cmp, float time) = 0;
virtual void updateAnimable(ComponentIndex cmp, float time_delta) = 0;
virtual class Animation* getAnimableAnimation(ComponentHandle cmp) = 0;
virtual float getAnimableTime(ComponentHandle cmp) = 0;
virtual void setAnimableTime(ComponentHandle cmp, float time) = 0;
virtual void updateAnimable(ComponentHandle cmp, float time_delta) = 0;
};

View file

@ -86,22 +86,22 @@ struct PropertyGridPlugin : PropertyGrid::IPlugin
if (cmp.type != ANIMABLE_HASH) return;
auto* scene = static_cast<AnimationScene*>(cmp.scene);
auto* animation = scene->getAnimableAnimation(cmp.index);
auto* animation = scene->getAnimableAnimation(cmp.handle);
if (!animation) return;
if (!animation->isReady()) return;
ImGui::Checkbox("Preview", &m_is_playing);
float time = scene->getAnimableTime(cmp.index);
float time = scene->getAnimableTime(cmp.handle);
if (ImGui::SliderFloat("Time", &time, 0, animation->getLength()))
{
scene->setAnimableTime(cmp.index, time);
scene->updateAnimable(cmp.index, 0);
scene->setAnimableTime(cmp.handle, time);
scene->updateAnimable(cmp.handle, 0);
}
if (m_is_playing)
{
float time_delta = m_app.getWorldEditor()->getEngine().getLastTimeDelta();
scene->updateAnimable(cmp.index, time_delta);
scene->updateAnimable(cmp.handle, time_delta);
}
}

View file

@ -44,14 +44,14 @@ struct EchoZone
Entity entity;
float radius;
float delay;
ComponentIndex component;
ComponentHandle component;
};
struct AmbientSound
{
Entity entity;
ComponentIndex component;
ComponentHandle component;
AudioScene::ClipInfo* clip;
bool is_3d;
int playing_sound;
@ -78,8 +78,8 @@ struct AudioSceneImpl : public AudioScene
, m_ambient_sounds(allocator)
, m_echo_zones(allocator)
{
m_last_echo_zone_id = 0;
m_last_ambient_sound_id = 0;
m_last_echo_zone_cmp.index = 0;
m_last_ambient_sound_cmp.index = 0;
m_listener.entity = INVALID_ENTITY;
for (auto& i : m_playing_sounds)
{
@ -137,13 +137,13 @@ struct AudioSceneImpl : public AudioScene
}
bool isAmbientSound3D(ComponentIndex cmp) override
bool isAmbientSound3D(ComponentHandle cmp) override
{
return m_ambient_sounds[getAmbientSoundIdx(cmp)].is_3d;
}
void setAmbientSound3D(ComponentIndex cmp, bool is_3d) override
void setAmbientSound3D(ComponentHandle cmp, bool is_3d) override
{
m_ambient_sounds[getAmbientSoundIdx(cmp)].is_3d = is_3d;
}
@ -176,7 +176,7 @@ struct AudioSceneImpl : public AudioScene
}
ComponentIndex createListener(Entity entity)
ComponentHandle createListener(Entity entity)
{
if (m_listener.entity != INVALID_ENTITY)
{
@ -185,12 +185,12 @@ struct AudioSceneImpl : public AudioScene
}
m_listener.entity = entity;
m_universe.addComponent(entity, LISTENER_TYPE, this, 0);
return 0;
m_universe.addComponent(entity, LISTENER_TYPE, this, {0});
return {0};
}
ClipInfo* getAmbientSoundClip(ComponentIndex cmp) override
ClipInfo* getAmbientSoundClip(ComponentHandle cmp) override
{
return m_ambient_sounds[getAmbientSoundIdx(cmp)].clip;
}
@ -206,29 +206,30 @@ struct AudioSceneImpl : public AudioScene
}
int getAmbientSoundClipIndex(ComponentIndex cmp) override
int getAmbientSoundClipIndex(ComponentHandle cmp) override
{
return m_clips.indexOf(m_ambient_sounds[getAmbientSoundIdx(cmp)].clip);
}
void setAmbientSoundClipIndex(ComponentIndex cmp, int index) override
void setAmbientSoundClipIndex(ComponentHandle cmp, int index) override
{
m_ambient_sounds[getAmbientSoundIdx(cmp)].clip = m_clips[index];
}
void setAmbientSoundClip(ComponentIndex cmp, ClipInfo* clip) override
void setAmbientSoundClip(ComponentHandle cmp, ClipInfo* clip) override
{
m_ambient_sounds[getAmbientSoundIdx(cmp)].clip = clip;
}
ComponentIndex createEchoZone(Entity entity)
ComponentHandle createEchoZone(Entity entity)
{
auto& zone = m_echo_zones.emplace();
zone.entity = entity;
zone.component = ++m_last_echo_zone_id;
++m_last_echo_zone_cmp.index;
zone.component = m_last_echo_zone_cmp;
zone.delay = 500.0f;
zone.radius = 10;
m_universe.addComponent(entity, ECHO_ZONE_TYPE, this, zone.component);
@ -236,31 +237,31 @@ struct AudioSceneImpl : public AudioScene
}
float getEchoZoneDelay(ComponentIndex cmp) override
float getEchoZoneDelay(ComponentHandle cmp) override
{
return m_echo_zones[getEchoZoneIdx(cmp)].delay;
}
void setEchoZoneDelay(ComponentIndex cmp, float delay) override
void setEchoZoneDelay(ComponentHandle cmp, float delay) override
{
m_echo_zones[getEchoZoneIdx(cmp)].delay = delay;
}
float getEchoZoneRadius(ComponentIndex cmp) override
float getEchoZoneRadius(ComponentHandle cmp) override
{
return m_echo_zones[getEchoZoneIdx(cmp)].radius;
}
void setEchoZoneRadius(ComponentIndex cmp, float radius) override
void setEchoZoneRadius(ComponentHandle cmp, float radius) override
{
m_echo_zones[getEchoZoneIdx(cmp)].radius = radius;
}
int getEchoZoneIdx(ComponentIndex component)
int getEchoZoneIdx(ComponentHandle component)
{
for(int i = 0, c = m_echo_zones.size(); i < c; ++i)
{
@ -270,7 +271,7 @@ struct AudioSceneImpl : public AudioScene
}
void destroyEchoZone(ComponentIndex component)
void destroyEchoZone(ComponentHandle component)
{
int idx = getEchoZoneIdx(component);
auto entity = m_echo_zones[idx].entity;
@ -280,10 +281,11 @@ struct AudioSceneImpl : public AudioScene
}
ComponentIndex createAmbientSound(Entity entity)
ComponentHandle createAmbientSound(Entity entity)
{
auto& sound = m_ambient_sounds.emplace();
sound.component = ++m_last_ambient_sound_id;
++m_last_ambient_sound_cmp.index;
sound.component = m_last_ambient_sound_cmp;
sound.entity = entity;
sound.clip = nullptr;
sound.playing_sound = -1;
@ -292,10 +294,10 @@ struct AudioSceneImpl : public AudioScene
}
ComponentIndex createComponent(ComponentType type, Entity entity) override;
ComponentHandle createComponent(ComponentType type, Entity entity) override;
int getAmbientSoundIdx(ComponentIndex component) const
int getAmbientSoundIdx(ComponentHandle component) const
{
for (int i = 0, c = m_ambient_sounds.size(); i < c; ++i)
{
@ -305,16 +307,16 @@ struct AudioSceneImpl : public AudioScene
}
void destroyListener(ComponentIndex component)
void destroyListener(ComponentHandle component)
{
ASSERT(component == 0);
ASSERT(component.index == 0);
auto entity = m_listener.entity;
m_listener.entity = INVALID_ENTITY;
m_universe.destroyComponent(entity, LISTENER_TYPE, this, component);
}
void destroyAmbientSound(ComponentIndex component)
void destroyAmbientSound(ComponentHandle component)
{
int idx = getAmbientSoundIdx(component);
auto entity = m_ambient_sounds[idx].entity;
@ -323,7 +325,7 @@ struct AudioSceneImpl : public AudioScene
}
void destroyComponent(ComponentIndex component, ComponentType type) override;
void destroyComponent(ComponentHandle component, ComponentType type) override;
void serialize(OutputBlob& serializer) override
@ -340,7 +342,7 @@ struct AudioSceneImpl : public AudioScene
serializer.writeString(clip->clip->getPath().c_str());
}
serializer.write(m_last_ambient_sound_id);
serializer.write(m_last_ambient_sound_cmp);
serializer.write(m_ambient_sounds.size());
for (auto& i : m_ambient_sounds)
{
@ -375,7 +377,7 @@ struct AudioSceneImpl : public AudioScene
serializer.read(m_listener.entity);
if (m_listener.entity != INVALID_ENTITY)
{
m_universe.addComponent(m_listener.entity, LISTENER_TYPE, this, 0);
m_universe.addComponent(m_listener.entity, LISTENER_TYPE, this, {0});
}
int count = 0;
@ -403,7 +405,7 @@ struct AudioSceneImpl : public AudioScene
clip->clip = static_cast<Clip*>(m_system.getClipManager().load(Path(path)));
}
serializer.read(m_last_ambient_sound_id);
serializer.read(m_last_ambient_sound_cmp);
serializer.read(count);
m_ambient_sounds.resize(count);
for (int i = 0; i < count; ++i)
@ -442,9 +444,13 @@ struct AudioSceneImpl : public AudioScene
}
ComponentIndex getComponent(Entity entity, ComponentType type) override
ComponentHandle getComponent(Entity entity, ComponentType type) override
{
if (type == LISTENER_TYPE) return m_listener.entity == entity ? 0 : INVALID_COMPONENT;
if (type == LISTENER_TYPE)
{
ComponentHandle listener_cmp = { 0 };
return m_listener.entity == entity ? listener_cmp : INVALID_COMPONENT;
}
if (type == AMBIENT_SOUND_TYPE)
{
@ -616,10 +622,10 @@ struct AudioSceneImpl : public AudioScene
Universe& getUniverse() override { return m_universe; }
IPlugin& getPlugin() const override { return m_system; }
int m_last_ambient_sound_id;
ComponentHandle m_last_ambient_sound_cmp;
Array<AmbientSound> m_ambient_sounds;
Array<EchoZone> m_echo_zones;
int m_last_echo_zone_id;
ComponentHandle m_last_echo_zone_cmp;
AudioDevice& m_device;
Listener m_listener;
IAllocator& m_allocator;
@ -633,8 +639,8 @@ struct AudioSceneImpl : public AudioScene
static struct
{
ComponentType type;
ComponentIndex(AudioSceneImpl::*creator)(Entity);
void (AudioSceneImpl::*destroyer)(ComponentIndex);
ComponentHandle(AudioSceneImpl::*creator)(Entity);
void (AudioSceneImpl::*destroyer)(ComponentHandle);
} COMPONENT_INFOS[] = {
{ LISTENER_TYPE, &AudioSceneImpl::createListener, &AudioSceneImpl::destroyListener },
{ AMBIENT_SOUND_TYPE, &AudioSceneImpl::createAmbientSound, &AudioSceneImpl::destroyAmbientSound },
@ -642,7 +648,7 @@ static struct
};
ComponentIndex AudioSceneImpl::createComponent(ComponentType type, Entity entity)
ComponentHandle AudioSceneImpl::createComponent(ComponentType type, Entity entity)
{
for(auto& i : COMPONENT_INFOS)
{
@ -656,7 +662,7 @@ ComponentIndex AudioSceneImpl::createComponent(ComponentType type, Entity entity
}
void AudioSceneImpl::destroyComponent(ComponentIndex component, ComponentType type)
void AudioSceneImpl::destroyComponent(ComponentHandle component, ComponentType type)
{
for(auto& i : COMPONENT_INFOS)
{

View file

@ -46,17 +46,17 @@ public:
virtual void removeClip(ClipInfo* clip) = 0;
virtual void setClip(int clip_id, const Lumix::Path& path) = 0;
virtual float getEchoZoneRadius(ComponentIndex cmp) = 0;
virtual void setEchoZoneRadius(ComponentIndex cmp, float radius) = 0;
virtual float getEchoZoneDelay(ComponentIndex cmp) = 0;
virtual void setEchoZoneDelay(ComponentIndex cmp, float delay) = 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 ClipInfo* getAmbientSoundClip(ComponentIndex cmp) = 0;
virtual int getAmbientSoundClipIndex(ComponentIndex cmp) = 0;
virtual void setAmbientSoundClipIndex(ComponentIndex cmp, int index) = 0;
virtual void setAmbientSoundClip(ComponentIndex cmp, ClipInfo* clip) = 0;
virtual bool isAmbientSound3D(ComponentIndex cmp) = 0;
virtual void setAmbientSound3D(ComponentIndex cmp, bool is_3d) = 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 SoundHandle play(Entity entity, ClipInfo* clip, bool is_3d) = 0;
virtual void stop(SoundHandle sound_id) = 0;

View file

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

View file

@ -190,8 +190,8 @@ struct EditorIconsImpl : public EditorIcons
if(!render_interface) return hit;
const auto& universe = *m_editor.getUniverse();
ComponentIndex camera = m_editor.getEditCamera().index;
if(camera < 0) return hit;
ComponentHandle camera = m_editor.getEditCamera().handle;
if (!isValid(camera)) return hit;
Matrix camera_mtx = universe.getMatrix(m_editor.getEditCamera().entity);
Vec3 camera_pos = camera_mtx.getTranslation();
bool is_ortho = render_interface->isCameraOrtho(camera);
@ -279,8 +279,8 @@ struct EditorIconsImpl : public EditorIcons
if(!render_interface) return;
const auto& universe = *m_editor.getUniverse();
ComponentIndex camera = m_editor.getEditCamera().index;
if(camera < 0) return;
ComponentHandle camera = m_editor.getEditCamera().handle;
if (!isValid(camera)) return;
Matrix camera_mtx = universe.getMatrix(m_editor.getEditCamera().entity);
Vec3 camera_pos = camera_mtx.getTranslation();
float fov = m_editor.getRenderInterface()->getCameraFOV(camera);

View file

@ -368,7 +368,7 @@ struct GizmoImpl : public Gizmo
auto edit_camera = m_editor.getEditCamera();
Vec3 origin, cursor_dir;
m_editor.getRenderInterface()->getRay(edit_camera.index, m_editor.getMouseX(), m_editor.getMouseY(), origin, cursor_dir);
m_editor.getRenderInterface()->getRay(edit_camera.handle, m_editor.getMouseX(), m_editor.getMouseY(), origin, cursor_dir);
m_transform_axis = Axis::NONE;
m_active = -1;
@ -479,7 +479,7 @@ struct GizmoImpl : public Gizmo
auto gizmo_mtx = m_editor.getUniverse()->getMatrix(m_entities[m_active]);
auto camera = m_editor.getEditCamera();
Vec3 origin, dir;
m_editor.getRenderInterface()->getRay(camera.index, m_editor.getMouseX(), m_editor.getMouseY(), origin, dir);
m_editor.getRenderInterface()->getRay(camera.handle, m_editor.getMouseX(), m_editor.getMouseY(), origin, dir);
dir.normalize();
Matrix camera_mtx = m_editor.getUniverse()->getPositionAndRotation(camera.entity);
bool is_two_axed = m_transform_axis == Axis::XZ || m_transform_axis == Axis::XY || m_transform_axis == Axis::YZ;
@ -660,10 +660,10 @@ struct GizmoImpl : public Gizmo
{
auto edit_camera = m_editor.getEditCamera();
auto* render_interface = m_editor.getRenderInterface();
bool is_ortho = render_interface->isCameraOrtho(edit_camera.index);
bool is_ortho = render_interface->isCameraOrtho(edit_camera.handle);
auto camera_pos = m_editor.getUniverse()->getPosition(edit_camera.entity);
auto camera_dir = m_editor.getUniverse()->getRotation(edit_camera.entity) * Vec3(0, 0, -1);
float fov = render_interface->getCameraFOV(edit_camera.index);
float fov = render_interface->getCameraFOV(edit_camera.handle);
collide(camera_pos, camera_dir, fov, is_ortho);
transform();

View file

@ -231,12 +231,12 @@ void PropertyGrid::showEnumProperty(Lumix::ComponentUID cmp, int index, Lumix::I
Lumix::OutputBlob blob(m_editor.getAllocator());
desc.get(cmp, index, blob);
int value = *(int*)blob.getData();
int count = desc.getEnumCount(cmp.scene, cmp.index);
int count = desc.getEnumCount(cmp.scene, cmp.handle);
struct Data
{
Lumix::IEnumPropertyDescriptor* descriptor;
Lumix::ComponentIndex cmp;
Lumix::ComponentHandle cmp;
Lumix::IScene* scene;
};
@ -256,7 +256,7 @@ void PropertyGrid::showEnumProperty(Lumix::ComponentUID cmp, int index, Lumix::I
};
Data data;
data.cmp = cmp.index;
data.cmp = cmp.handle;
data.scene = cmp.scene;
data.descriptor = &desc;

View file

@ -30,14 +30,14 @@ public:
virtual ~RenderInterface() {}
virtual AABB getEntityAABB(Universe& universe, Entity entity) = 0;
virtual float getCameraFOV(ComponentIndex cmp) = 0;
virtual bool isCameraOrtho(ComponentIndex cmp) = 0;
virtual float getCameraOrthoSize(ComponentIndex cmp) = 0;
virtual Vec2 getCameraScreenSize(ComponentIndex cmp) = 0;
virtual ComponentIndex getCameraInSlot(const char* slot) = 0;
virtual void setCameraSlot(ComponentIndex cmp, const char* slot) = 0;
virtual Entity getCameraEntity(ComponentIndex cmp) = 0;
virtual void getRay(ComponentIndex camera_index, float x, float y, Vec3& origin, Vec3& dir) = 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, float x, float y, Vec3& origin, Vec3& dir) = 0;
virtual float castRay(ModelHandle model, const Vec3& origin, const Vec3& dir, const Matrix& mtx) = 0;
virtual void renderModel(ModelHandle model, const Matrix& mtx) = 0;
virtual ModelHandle loadModel(Lumix::Path& path) = 0;
@ -48,8 +48,8 @@ public:
virtual void addDebugCube(const Vec3& minimum, const Vec3& maximum, uint32 color, float life) = 0;
virtual void addDebugCross(const Vec3& pos, float size, uint32 color, float life) = 0;
virtual void addDebugLine(const Vec3& from, const Vec3& to, uint32 color, float life) = 0;
virtual WorldEditor::RayHit castRay(const Vec3& origin, const Vec3& dir, ComponentIndex ignored) = 0;
virtual Path getRenderablePath(ComponentIndex cmp) = 0;
virtual WorldEditor::RayHit castRay(const Vec3& origin, const Vec3& dir, ComponentHandle ignored) = 0;
virtual Path getRenderablePath(ComponentHandle cmp) = 0;
virtual void render(const Matrix& mtx,
uint16* indices,
int indices_count,

View file

@ -18,7 +18,7 @@ void getEntityListDisplayName(Lumix::WorldEditor& editor, char* buf, int max_siz
if (renderable.isValid())
{
auto* render_interface = editor.getRenderInterface();
auto path = render_interface->getRenderablePath(renderable.index);
auto path = render_interface->getRenderablePath(renderable.handle);
if (path.isValid())
{
char basename[Lumix::MAX_PATH_LENGTH];

View file

@ -560,7 +560,7 @@ public:
{
serializer.serialize("inedx", m_index);
serializer.serialize("entity_index", m_component.entity);
serializer.serialize("component_index", m_component.index);
serializer.serialize("component_index", m_component.handle);
serializer.serialize("component_type", PropertyRegister::getComponentTypeHash(m_component.type));
serializer.serialize("property_name_hash", m_descriptor->getNameHash());
}
@ -570,7 +570,7 @@ public:
{
serializer.deserialize("inedx", m_index, 0);
serializer.deserialize("entity_index", m_component.entity, INVALID_ENTITY);
serializer.deserialize("component_index", m_component.index, 0);
serializer.deserialize("component_index", m_component.handle, INVALID_COMPONENT);
uint32 hash;
serializer.deserialize("component_type", hash, 0);
m_component.type = PropertyRegister::getComponentTypeFromHash(hash);
@ -643,7 +643,7 @@ public:
{
serializer.serialize("inedx", m_index);
serializer.serialize("entity_index", m_component.entity);
serializer.serialize("component_index", m_component.index);
serializer.serialize("component_index", m_component.handle);
serializer.serialize("component_type", PropertyRegister::getComponentTypeHash(m_component.type));
serializer.serialize("property_name_hash", m_descriptor->getNameHash());
}
@ -653,7 +653,7 @@ public:
{
serializer.deserialize("inedx", m_index, 0);
serializer.deserialize("entity_index", m_component.entity, INVALID_ENTITY);
serializer.deserialize("component_index", m_component.index, 0);
serializer.deserialize("component_index", m_component.handle, INVALID_COMPONENT);
uint32 hash;
serializer.deserialize("component_type", hash, 0);
m_component.type = PropertyRegister::getComponentTypeFromHash(hash);
@ -991,7 +991,7 @@ private:
{
const ComponentUID& cmp =
m_editor.getComponent(m_entities[i], m_type);
cmp.scene->destroyComponent(cmp.index, cmp.type);
cmp.scene->destroyComponent(cmp.handle, cmp.type);
}
}
@ -1123,7 +1123,7 @@ private:
ComponentUID new_component;
for (int i = 0; i < scenes.size(); ++i)
{
new_component.index = scenes[i]->createComponent(cmp_type, new_entity);
new_component.handle = scenes[i]->createComponent(cmp_type, new_entity);
new_component.entity = new_entity;
new_component.scene = scenes[i];
new_component.type = cmp_type;
@ -1190,7 +1190,7 @@ private:
void serialize(JsonSerializer& serializer) override
{
serializer.serialize("entity", m_component.entity);
serializer.serialize("component", m_component.index);
serializer.serialize("component", m_component.handle);
serializer.serialize("component_type", PropertyRegister::getComponentTypeHash(m_component.type));
}
@ -1198,7 +1198,7 @@ private:
void deserialize(JsonSerializer& serializer) override
{
serializer.deserialize("entity", m_component.entity, INVALID_ENTITY);
serializer.deserialize("component", m_component.index, 0);
serializer.deserialize("component", m_component.handle, INVALID_COMPONENT);
uint32 hash;
serializer.deserialize("component_type", hash, 0);
m_component.type = PropertyRegister::getComponentTypeFromHash(hash);
@ -1215,11 +1215,11 @@ private:
{
for (int i = 0; i < scenes.size(); ++i)
{
ComponentIndex cmp =
ComponentHandle cmp =
scenes[i]->createComponent(m_component.type, m_component.entity);
if (cmp != INVALID_COMPONENT)
if (isValid(cmp))
{
m_component.index = cmp;
m_component.handle = cmp;
m_component.scene = scenes[i];
break;
}
@ -1289,13 +1289,13 @@ private:
ComponentUID cmp = m_editor.getComponent(instances[i], m_component.type);
if (cmp.isValid())
{
cmp.scene->destroyComponent(cmp.index, cmp.type);
cmp.scene->destroyComponent(cmp.handle, cmp.type);
}
}
}
else
{
m_component.scene->destroyComponent(m_component.index, m_component.type);
m_component.scene->destroyComponent(m_component.handle, m_component.type);
}
return true;
}
@ -1586,7 +1586,7 @@ public:
ComponentUID camera_cmp = getComponent(m_camera, CAMERA_TYPE);
if (camera_cmp.isValid())
{
m_render_interface->getRay(camera_cmp.index, (float)x, (float)y, origin, dir);
m_render_interface->getRay(camera_cmp.handle, (float)x, (float)y, origin, dir);
auto hit = m_render_interface->castRay(origin, dir, INVALID_COMPONENT);
if (m_gizmo->isActive()) return;
@ -1771,14 +1771,14 @@ public:
ComponentUID renderable = getComponent(m_selected_entities[i], RENDERABLE_TYPE);
Vec3 origin = universe->getPosition(entity);
auto hit = m_render_interface->castRay(origin, Vec3(0, -1, 0), renderable.index);
auto hit = m_render_interface->castRay(origin, Vec3(0, -1, 0), renderable.handle);
if (hit.is_hit)
{
new_positions.push(origin + Vec3(0, -hit.t, 0));
}
else
{
hit = m_render_interface->castRay(origin, Vec3(0, 1, 0), renderable.index);
hit = m_render_interface->castRay(origin, Vec3(0, 1, 0), renderable.handle);
if (hit.is_hit)
{
new_positions.push(origin + Vec3(0, hit.t, 0));
@ -1813,7 +1813,7 @@ public:
Entity addEntity() override
{
ComponentUID cmp = getComponent(m_camera, CAMERA_TYPE);
Vec2 size = m_render_interface->getCameraScreenSize(cmp.index);
Vec2 size = m_render_interface->getCameraScreenSize(cmp.handle);
return addEntityAt((int)size.x >> 1, (int)size.y >> 1);
}
@ -1825,7 +1825,7 @@ public:
Vec3 origin;
Vec3 dir;
m_render_interface->getRay(camera_cmp.index, (float)camera_x, (float)camera_y, origin, 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);
Vec3 pos;
if (hit.is_hit)
@ -1847,12 +1847,12 @@ public:
{
ComponentUID camera_cmp = getComponent(m_camera, CAMERA_TYPE);
Universe* universe = getUniverse();
Vec2 screen_size = m_render_interface->getCameraScreenSize(camera_cmp.index);
Vec2 screen_size = m_render_interface->getCameraScreenSize(camera_cmp.handle);
screen_size *= 0.5f;
Vec3 origin;
Vec3 dir;
m_render_interface->getRay(camera_cmp.index, (float)screen_size.x, (float)screen_size.y, origin, 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);
Vec3 pos;
if (hit.is_hit)
@ -2544,7 +2544,7 @@ public:
static const uint32 SLOT_HASH = crc32("Slot");
if (component_type == CAMERA_TYPE && property.getNameHash() == SLOT_HASH)
{
if (m_render_interface->getCameraEntity(cmp.index) == m_camera)
if (m_render_interface->getCameraEntity(cmp.handle) == m_camera)
{
return;
}
@ -2772,7 +2772,7 @@ public:
universe->setEntityName(m_camera, "editor_camera");
ComponentUID cmp = createComponent(CAMERA_TYPE, m_camera);
ASSERT(cmp.isValid());
m_render_interface->setCameraSlot(cmp.index, "editor");
m_render_interface->setCameraSlot(cmp.handle, "editor");
}
}

View file

@ -134,16 +134,16 @@ public:
}
static ComponentIndex LUA_createComponent(IScene* scene, const char* type, int entity_idx)
static ComponentHandle LUA_createComponent(IScene* scene, const char* type, int entity_idx)
{
if (!scene) return -1;
if (!scene) return INVALID_COMPONENT;
Entity e = {entity_idx};
ComponentType handle = PropertyRegister::getComponentType(type);
if (scene->getComponent(e, handle) != INVALID_COMPONENT)
{
g_log_error.log("Lua Script") << "Component " << type << " already exists in entity "
<< entity_idx;
return -1;
return INVALID_COMPONENT;
}
return scene->createComponent(handle, e);

View file

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

View file

@ -19,14 +19,14 @@ namespace Lumix
public:
virtual ~IScene() {}
virtual ComponentIndex createComponent(ComponentType, Entity) = 0;
virtual void destroyComponent(ComponentIndex component, ComponentType type) = 0;
virtual ComponentHandle createComponent(ComponentType, Entity) = 0;
virtual void destroyComponent(ComponentHandle component, ComponentType type) = 0;
virtual void serialize(OutputBlob& serializer) = 0;
virtual void deserialize(InputBlob& serializer, int version) = 0;
virtual IPlugin& getPlugin() const = 0;
virtual void update(float time_delta, bool paused) = 0;
virtual bool ownComponentType(ComponentType type) const = 0;
virtual ComponentIndex getComponent(Entity entity, ComponentType type) = 0;
virtual ComponentHandle getComponent(Entity entity, ComponentType type) = 0;
virtual Universe& getUniverse() = 0;
virtual void startGame() {}
virtual void stopGame() {}

View file

@ -99,9 +99,9 @@ public:
{
}
virtual int getEnumCount(IScene* scene, ComponentIndex cmp) = 0;
virtual const char* getEnumItemName(IScene* scene, ComponentIndex cmp, int index) = 0;
virtual void getEnumItemName(IScene* scene, ComponentIndex cmp, int index, char* buf, int max_size) {}
virtual int getEnumCount(IScene* scene, ComponentHandle cmp) = 0;
virtual const char* getEnumItemName(IScene* scene, ComponentHandle cmp, int index) = 0;
virtual void getEnumItemName(IScene* scene, ComponentHandle cmp, int index, char* buf, int max_size) {}
};

View file

@ -95,6 +95,12 @@ 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();
@ -239,6 +245,12 @@ void JsonSerializer::serializeArrayItem(Entity value)
}
void JsonSerializer::serializeArrayItem(ComponentHandle value)
{
serializeArrayItem(value.index);
}
void JsonSerializer::serializeArrayItem(int value)
{
writeBlockComma();
@ -296,6 +308,13 @@ void JsonSerializer::deserialize(const char* label, Entity& value, Entity defaul
deserialize(label, value.index, default_value.index);
}
void JsonSerializer::deserialize(const char* label, ComponentHandle& value, ComponentHandle default_value)
{
deserialize(label, value.index, default_value.index);
}
void JsonSerializer::deserialize(bool& value, bool default_value)
{
value = !m_is_string_token ? m_token_size == 4 && (compareStringN(m_token, "true", 4) == 0)
@ -551,6 +570,12 @@ void JsonSerializer::deserializeArrayItem(Entity& value, Entity default_value)
}
void JsonSerializer::deserializeArrayItem(ComponentHandle& value, ComponentHandle default_value)
{
deserializeArrayItem(value.index, default_value.index);
}
void JsonSerializer::deserializeArrayItem(uint32& value, uint32 default_value)
{
deserializeArrayComma();

View file

@ -34,6 +34,7 @@ namespace Lumix
// serialize
void serialize(const char* label, Entity value);
void serialize(const char* label, ComponentHandle value);
void serialize(const char* label, uint32 value);
void serialize(const char* label, float value);
void serialize(const char* label, int32 value);
@ -46,6 +47,7 @@ namespace Lumix
void beginArray(const char* label);
void endArray();
void serializeArrayItem(Entity value);
void serializeArrayItem(ComponentHandle value);
void serializeArrayItem(uint32 value);
void serializeArrayItem(int32 value);
void serializeArrayItem(int64 value);
@ -55,6 +57,7 @@ namespace Lumix
// deserialize
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, uint32& value, uint32 default_value);
void deserialize(const char* label, float& value, float default_value);
void deserialize(const char* label, int32& value, int32 default_value);
@ -71,6 +74,7 @@ namespace Lumix
void deserializeArrayEnd();
bool isArrayEnd();
void deserializeArrayItem(Entity& value, Entity default_value);
void deserializeArrayItem(ComponentHandle& value, ComponentHandle default_value);
void deserializeArrayItem(uint32& value, uint32 default_value);
void deserializeArrayItem(int32& value, int32 default_value);
void deserializeArrayItem(int64& value, int64 default_value);

View file

@ -25,7 +25,11 @@ template <> inline int toType(lua_State* L, int index)
}
template <> inline Entity toType(lua_State* L, int index)
{
return {(int)lua_tointeger(L, 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)
{
@ -186,6 +190,10 @@ template <> inline void pushLua(lua_State* L, Entity value)
{
lua_pushnumber(L, value.index);
}
template <> inline void pushLua(lua_State* L, ComponentHandle value)
{
lua_pushnumber(L, value.index);
}
inline void pushLua(lua_State* L, const Vec2& value)
{
lua_createtable(L, 2, 0);

View file

@ -70,7 +70,16 @@ static_assert(sizeof(int16) == 2, "Incorrect size of int16");
static_assert(sizeof(int8) == 1, "Incorrect size of int8");
const uint32 MAX_PATH_LENGTH = 260;
typedef int ComponentIndex;
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; };
};
inline bool isValid(ComponentHandle cmp) { return cmp.index >= 0; }
struct Entity
{
int index;
@ -89,7 +98,7 @@ struct ComponentType
bool operator!=(const ComponentType& rhs) const { return rhs.index != index; };
};
const Entity INVALID_ENTITY = {-1};
const int INVALID_COMPONENT = -1;
const ComponentHandle INVALID_COMPONENT = {-1};
template <typename T, int count> int lengthOf(const T (&)[count])
{

View file

@ -30,10 +30,10 @@ private:
static const int MAX_STRING_SIZE = 300;
public:
typedef const char* (S::*Getter)(ComponentIndex);
typedef void (S::*Setter)(ComponentIndex, const char*);
typedef const char* (S::*ArrayGetter)(ComponentIndex, int);
typedef void (S::*ArraySetter)(ComponentIndex, int, const char*);
typedef const char* (S::*Getter)(ComponentHandle);
typedef void (S::*Setter)(ComponentHandle, const char*);
typedef const char* (S::*ArrayGetter)(ComponentHandle, int);
typedef void (S::*ArraySetter)(ComponentHandle, int, const char*);
public:
StringPropertyDescriptor(const char* name, Getter getter, Setter setter, IAllocator& allocator)
@ -68,11 +68,11 @@ public:
if (index < 0)
{
(static_cast<S*>(cmp.scene)->*m_single.setter)(cmp.index, tmp);
(static_cast<S*>(cmp.scene)->*m_single.setter)(cmp.handle, tmp);
}
else
{
(static_cast<S*>(cmp.scene)->*m_array.setter)(cmp.index, index, tmp);
(static_cast<S*>(cmp.scene)->*m_array.setter)(cmp.handle, index, tmp);
}
}
@ -82,11 +82,11 @@ public:
const char* value;
if (index < 0)
{
value = (static_cast<S*>(cmp.scene)->*m_single.getter)(cmp.index);
value = (static_cast<S*>(cmp.scene)->*m_single.getter)(cmp.handle);
}
else
{
value = (static_cast<S*>(cmp.scene)->*m_array.getter)(cmp.index, index);
value = (static_cast<S*>(cmp.scene)->*m_array.getter)(cmp.handle, index);
}
int len = stringLength(value) + 1;
stream.write(value, len);
@ -113,9 +113,9 @@ private:
template <class S> class ArrayDescriptor : public IArrayDescriptor
{
public:
typedef int (S::*Counter)(ComponentIndex);
typedef void (S::*Adder)(ComponentIndex, int);
typedef void (S::*Remover)(ComponentIndex, int);
typedef int (S::*Counter)(ComponentHandle);
typedef void (S::*Adder)(ComponentHandle, int);
typedef void (S::*Remover)(ComponentHandle, int);
public:
ArrayDescriptor(const char* name,
@ -188,19 +188,19 @@ public:
int getCount(ComponentUID cmp) const override
{
return (static_cast<S*>(cmp.scene)->*m_counter)(cmp.index);
return (static_cast<S*>(cmp.scene)->*m_counter)(cmp.handle);
}
void addArrayItem(ComponentUID cmp, int index) const override
{
if (m_adder) (static_cast<S*>(cmp.scene)->*m_adder)(cmp.index, index);
if (m_adder) (static_cast<S*>(cmp.scene)->*m_adder)(cmp.handle, index);
}
void removeArrayItem(ComponentUID cmp, int index) const override
{
(static_cast<S*>(cmp.scene)->*m_remover)(cmp.index, index);
(static_cast<S*>(cmp.scene)->*m_remover)(cmp.handle, index);
}
@ -227,10 +227,10 @@ private:
template <class S> class IntPropertyDescriptor : public IPropertyDescriptor
{
public:
typedef int (S::*Getter)(ComponentIndex);
typedef void (S::*Setter)(ComponentIndex, int);
typedef int (S::*ArrayGetter)(ComponentIndex, int);
typedef void (S::*ArraySetter)(ComponentIndex, int, int);
typedef int (S::*Getter)(ComponentHandle);
typedef void (S::*Setter)(ComponentHandle, int);
typedef int (S::*ArrayGetter)(ComponentHandle, int);
typedef void (S::*ArraySetter)(ComponentHandle, int, int);
public:
IntPropertyDescriptor() {}
@ -265,11 +265,11 @@ public:
stream.read(&i, sizeof(i));
if(index < 0)
{
(static_cast<S*>(cmp.scene)->*m_single.setter)(cmp.index, i);
(static_cast<S*>(cmp.scene)->*m_single.setter)(cmp.handle, i);
}
else
{
(static_cast<S*>(cmp.scene)->*m_array.setter)(cmp.index, index, i);
(static_cast<S*>(cmp.scene)->*m_array.setter)(cmp.handle, index, i);
}
};
@ -279,11 +279,11 @@ public:
int32 i = 0;
if(index < 0)
{
i = (static_cast<S*>(cmp.scene)->*m_single.getter)(cmp.index);
i = (static_cast<S*>(cmp.scene)->*m_single.getter)(cmp.handle);
}
else
{
i = (static_cast<S*>(cmp.scene)->*m_array.getter)(cmp.index, index);
i = (static_cast<S*>(cmp.scene)->*m_array.getter)(cmp.handle, index);
}
stream.write(i);
};
@ -323,8 +323,8 @@ private:
template <class S> class BoolPropertyDescriptor : public IPropertyDescriptor
{
public:
typedef bool (S::*Getter)(ComponentIndex);
typedef void (S::*Setter)(ComponentIndex, bool);
typedef bool (S::*Getter)(ComponentHandle);
typedef void (S::*Setter)(ComponentHandle, bool);
public:
BoolPropertyDescriptor(const char* name, Getter getter, Setter setter, IAllocator& allocator)
@ -342,14 +342,14 @@ public:
ASSERT(index == -1);
bool b;
stream.read(&b, sizeof(b));
(static_cast<S*>(cmp.scene)->*m_setter)(cmp.index, b);
(static_cast<S*>(cmp.scene)->*m_setter)(cmp.handle, b);
};
void get(ComponentUID cmp, int index, OutputBlob& stream) const override
{
ASSERT(index == -1);
bool b = (static_cast<S*>(cmp.scene)->*m_getter)(cmp.index);
bool b = (static_cast<S*>(cmp.scene)->*m_getter)(cmp.handle);
int len = sizeof(b);
stream.write(&b, len);
};
@ -363,10 +363,10 @@ private:
template <typename T, class S> class SimplePropertyDescriptor : public IPropertyDescriptor
{
public:
typedef T (S::*Getter)(ComponentIndex);
typedef void (S::*Setter)(ComponentIndex, const T&);
typedef T(S::*ArrayGetter)(ComponentIndex, int);
typedef void (S::*ArraySetter)(ComponentIndex, int, const T&);
typedef T (S::*Getter)(ComponentHandle);
typedef void (S::*Setter)(ComponentHandle, const T&);
typedef T(S::*ArrayGetter)(ComponentHandle, int);
typedef void (S::*ArraySetter)(ComponentHandle, int, const T&);
public:
SimplePropertyDescriptor(const char* name, Getter getter, Setter setter, IAllocator& allocator)
@ -395,11 +395,11 @@ public:
stream.read(&v, sizeof(v));
if (index < 0)
{
(static_cast<S*>(cmp.scene)->*m_single.setter)(cmp.index, v);
(static_cast<S*>(cmp.scene)->*m_single.setter)(cmp.handle, v);
}
else
{
(static_cast<S*>(cmp.scene)->*m_array.setter)(cmp.index, index, v);
(static_cast<S*>(cmp.scene)->*m_array.setter)(cmp.handle, index, v);
}
};
@ -409,12 +409,12 @@ public:
int len = sizeof(T);
if (index < 0)
{
T v = (static_cast<S*>(cmp.scene)->*m_single.getter)(cmp.index);
T v = (static_cast<S*>(cmp.scene)->*m_single.getter)(cmp.handle);
stream.write(&v, len);
}
else
{
T v = (static_cast<S*>(cmp.scene)->*m_array.getter)(cmp.index, index);
T v = (static_cast<S*>(cmp.scene)->*m_array.getter)(cmp.handle, index);
stream.write(&v, len);
}
};
@ -441,10 +441,10 @@ template <class S>
class FilePropertyDescriptor : public IPropertyDescriptor
{
public:
typedef Path (S::*Getter)(ComponentIndex);
typedef void (S::*Setter)(ComponentIndex, const Path&);
typedef Path (S::*ArrayGetter)(ComponentIndex, int);
typedef void (S::*ArraySetter)(ComponentIndex, int, const Path&);
typedef Path (S::*Getter)(ComponentHandle);
typedef void (S::*Setter)(ComponentHandle, const Path&);
typedef Path (S::*ArrayGetter)(ComponentHandle, int);
typedef void (S::*ArraySetter)(ComponentHandle, int, const Path&);
public:
FilePropertyDescriptor(const char* name,
@ -490,11 +490,11 @@ public:
if(index < 0)
{
(static_cast<S*>(cmp.scene)->*m_single.setter)(cmp.index, Path(tmp));
(static_cast<S*>(cmp.scene)->*m_single.setter)(cmp.handle, Path(tmp));
}
else
{
(static_cast<S*>(cmp.scene)->*m_array.setter)(cmp.index, index, Path(tmp));
(static_cast<S*>(cmp.scene)->*m_array.setter)(cmp.handle, index, Path(tmp));
}
}
@ -504,11 +504,11 @@ public:
Path value;
if(index < 0)
{
value = (static_cast<S*>(cmp.scene)->*m_single.getter)(cmp.index);
value = (static_cast<S*>(cmp.scene)->*m_single.getter)(cmp.handle);
}
else
{
value = (static_cast<S*>(cmp.scene)->*m_array.getter)(cmp.index, index);
value = (static_cast<S*>(cmp.scene)->*m_array.getter)(cmp.handle, index);
}
int len = value.length() + 1;
stream.write(value.c_str(), len);
@ -589,9 +589,9 @@ public:
template <class S> class SampledFunctionDescriptor : public ISampledFunctionDescriptor
{
public:
typedef const Lumix::Vec2* (S::*Getter)(ComponentIndex);
typedef int (S::*CountGetter)(ComponentIndex);
typedef void (S::*Setter)(ComponentIndex, const Lumix::Vec2*, int);
typedef const Lumix::Vec2* (S::*Getter)(ComponentHandle);
typedef int (S::*CountGetter)(ComponentHandle);
typedef void (S::*Setter)(ComponentHandle, const Lumix::Vec2*, int);
public:
SampledFunctionDescriptor(const char* name,
@ -619,16 +619,16 @@ public:
int count;
stream.read(count);
auto* buf = (const Lumix::Vec2*)stream.skip(sizeof(Lumix::Vec2) * count);
(static_cast<S*>(cmp.scene)->*m_setter)(cmp.index, buf, count);
(static_cast<S*>(cmp.scene)->*m_setter)(cmp.handle, buf, count);
};
void get(ComponentUID cmp, int index, OutputBlob& stream) const override
{
ASSERT(index == -1);
int count = (static_cast<S*>(cmp.scene)->*m_count_getter)(cmp.index);
int count = (static_cast<S*>(cmp.scene)->*m_count_getter)(cmp.handle);
stream.write(count);
const Lumix::Vec2* values = (static_cast<S*>(cmp.scene)->*m_getter)(cmp.index);
const Lumix::Vec2* values = (static_cast<S*>(cmp.scene)->*m_getter)(cmp.handle);
stream.write(values, sizeof(values[0]) * count);
};
@ -649,10 +649,10 @@ private:
template <class S> class EntityPropertyDescriptor : public IPropertyDescriptor
{
public:
typedef Entity(S::*Getter)(ComponentIndex);
typedef void (S::*Setter)(ComponentIndex, Entity);
typedef Entity(S::*ArrayGetter)(ComponentIndex, int);
typedef void (S::*ArraySetter)(ComponentIndex, int, Entity);
typedef Entity(S::*Getter)(ComponentHandle);
typedef void (S::*Setter)(ComponentHandle, Entity);
typedef Entity(S::*ArrayGetter)(ComponentHandle, int);
typedef void (S::*ArraySetter)(ComponentHandle, int, Entity);
public:
EntityPropertyDescriptor(const char* name,
@ -689,11 +689,11 @@ template <class S> class EntityPropertyDescriptor : public IPropertyDescriptor
value < 0 ? INVALID_ENTITY : cmp.scene->getUniverse().getEntityFromDenseIdx(value);
if(index == -1)
{
(static_cast<S*>(cmp.scene)->*m_single.setter)(cmp.index, entity);
(static_cast<S*>(cmp.scene)->*m_single.setter)(cmp.handle, entity);
}
else
{
(static_cast<S*>(cmp.scene)->*m_array.setter)(cmp.index, index, entity);
(static_cast<S*>(cmp.scene)->*m_array.setter)(cmp.handle, index, entity);
}
};
@ -703,11 +703,11 @@ template <class S> class EntityPropertyDescriptor : public IPropertyDescriptor
Entity value;
if(index == -1)
{
value = (static_cast<S*>(cmp.scene)->*m_single.getter)(cmp.index);
value = (static_cast<S*>(cmp.scene)->*m_single.getter)(cmp.handle);
}
else
{
value = (static_cast<S*>(cmp.scene)->*m_array.getter)(cmp.index, index);
value = (static_cast<S*>(cmp.scene)->*m_array.getter)(cmp.handle, index);
}
auto dense_idx = cmp.scene->getUniverse().getDenseIdx(value);
int len = sizeof(dense_idx);
@ -734,10 +734,10 @@ template <class S> class EntityPropertyDescriptor : public IPropertyDescriptor
template <class S> class DecimalPropertyDescriptor : public IDecimalPropertyDescriptor
{
public:
typedef float (S::*Getter)(ComponentIndex);
typedef void (S::*Setter)(ComponentIndex, float);
typedef float (S::*ArrayGetter)(ComponentIndex, int);
typedef void (S::*ArraySetter)(ComponentIndex, int,float);
typedef float (S::*Getter)(ComponentHandle);
typedef void (S::*Setter)(ComponentHandle, float);
typedef float (S::*ArrayGetter)(ComponentHandle, int);
typedef void (S::*ArraySetter)(ComponentHandle, int,float);
public:
DecimalPropertyDescriptor(const char* name,
@ -789,11 +789,11 @@ public:
stream.read(&f, sizeof(f));
if(index >= 0)
{
(static_cast<S*>(cmp.scene)->*m_array_setter)(cmp.index, index, f);
(static_cast<S*>(cmp.scene)->*m_array_setter)(cmp.handle, index, f);
}
else
{
(static_cast<S*>(cmp.scene)->*m_setter)(cmp.index, f);
(static_cast<S*>(cmp.scene)->*m_setter)(cmp.handle, f);
}
};
@ -803,11 +803,11 @@ public:
float f = 0;
if(index >= 0)
{
f = (static_cast<S*>(cmp.scene)->*m_array_getter)(cmp.index, index);
f = (static_cast<S*>(cmp.scene)->*m_array_getter)(cmp.handle, index);
}
else
{
f = (static_cast<S*>(cmp.scene)->*m_getter)(cmp.index);
f = (static_cast<S*>(cmp.scene)->*m_getter)(cmp.handle);
}
int len = sizeof(f);
stream.write(&f, len);
@ -840,8 +840,8 @@ public:
template <class S> class EnumPropertyDescriptor : public IEnumPropertyDescriptor
{
public:
typedef int (S::*Getter)(ComponentIndex);
typedef void (S::*Setter)(ComponentIndex, int);
typedef int (S::*Getter)(ComponentHandle);
typedef void (S::*Setter)(ComponentHandle, int);
typedef int (S::*EnumCountGetter)() const;
typedef const char* (S::*EnumNameGetter)(int);
@ -868,23 +868,23 @@ public:
ASSERT(index == -1);
int value;
stream.read(&value, sizeof(value));
(static_cast<S*>(cmp.scene)->*m_setter)(cmp.index, value);
(static_cast<S*>(cmp.scene)->*m_setter)(cmp.handle, value);
};
void get(ComponentUID cmp, int index, OutputBlob& stream) const override
{
ASSERT(index == -1);
int value = (static_cast<S*>(cmp.scene)->*m_getter)(cmp.index);
int value = (static_cast<S*>(cmp.scene)->*m_getter)(cmp.handle);
int len = sizeof(value);
stream.write(&value, len);
};
int getEnumCount(IScene* scene, ComponentIndex) override { return (static_cast<S*>(scene)->*m_enum_count_getter)(); }
int getEnumCount(IScene* scene, ComponentHandle) override { return (static_cast<S*>(scene)->*m_enum_count_getter)(); }
const char* getEnumItemName(IScene* scene, ComponentIndex, int index) override
const char* getEnumItemName(IScene* scene, ComponentHandle, int index) override
{
return (static_cast<S*>(scene)->*m_enum_name_getter)(index);
}

View file

@ -1,4 +1,4 @@
#include "engine/universe/component.h"
const Lumix::ComponentUID Lumix::ComponentUID::INVALID(Lumix::INVALID_ENTITY, {-1}, 0, -1);
const Lumix::ComponentUID Lumix::ComponentUID::INVALID(Lumix::INVALID_ENTITY, {-1}, 0, Lumix::INVALID_COMPONENT);

View file

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

View file

@ -45,23 +45,24 @@ public:
}
ComponentIndex createComponent(ComponentType type, Entity entity) override
ComponentHandle createComponent(ComponentType type, Entity entity) override
{
if (HIERARCHY_TYPE_HANDLE == type)
{
m_parents.insert(entity, INVALID_ENTITY);
m_universe.addComponent(entity, type, this, entity.index);
return entity.index;
m_universe.addComponent(entity, type, this, {entity.index});
return {entity.index};
}
return INVALID_COMPONENT;
}
void destroyComponent(ComponentIndex component, ComponentType type) override
void destroyComponent(ComponentHandle component, ComponentType type) override
{
if (HIERARCHY_TYPE_HANDLE == type)
{
auto parent_iter = m_parents.find({component});
Entity entity = {component.index};
auto parent_iter = m_parents.find(entity);
if (parent_iter.isValid())
{
@ -74,7 +75,7 @@ public:
m_parents.erase(parent_iter);
}
m_universe.destroyComponent({component}, type, this, component);
m_universe.destroyComponent(entity, type, this, component);
}
}
@ -86,10 +87,11 @@ public:
IAllocator& getAllocator() { return m_allocator; }
ComponentIndex getComponent(Entity entity, ComponentType type) override
ComponentHandle getComponent(Entity entity, ComponentType type) override
{
ASSERT(ownComponentType(type));
return m_parents.find(entity) != m_parents.end() ? entity.index : INVALID_COMPONENT;
ComponentHandle cmp = {entity.index};
return m_parents.find(entity) != m_parents.end() ? cmp : INVALID_COMPONENT;
}
@ -151,9 +153,9 @@ public:
}
void setLocalPosition(ComponentIndex cmp, const Vec3& position) override
void setLocalPosition(ComponentHandle cmp, const Vec3& position) override
{
Entity entity = {cmp};
Entity entity = {cmp.index};
Parents::iterator parent_iter = m_parents.find(entity);
if (parent_iter.isValid())
@ -168,9 +170,9 @@ public:
}
Vec3 getLocalPosition(ComponentIndex cmp) override
Vec3 getLocalPosition(ComponentHandle cmp) override
{
Entity entity = {cmp};
Entity entity = {cmp.index};
Parents::iterator parent_iter = m_parents.find(entity);
if (parent_iter.isValid() && isValid(parent_iter.value()))
@ -206,9 +208,9 @@ public:
}
Quat getLocalRotation(ComponentIndex cmp) override
Quat getLocalRotation(ComponentHandle cmp) override
{
Entity entity = {cmp};
Entity entity = {cmp.index};
Parents::iterator parent_iter = m_parents.find(entity);
if (parent_iter.isValid())
@ -233,9 +235,9 @@ public:
const Children& getAllChildren() const override { return m_children; }
void setParent(ComponentIndex child, Entity parent) override
void setParent(ComponentHandle child, Entity parent) override
{
Entity child_entity = {child};
Entity child_entity = {child.index};
Parents::iterator old_parent_iter = m_parents.find(child_entity);
if (old_parent_iter.isValid())
{
@ -275,9 +277,9 @@ public:
}
Entity getParent(ComponentIndex child) override
Entity getParent(ComponentHandle child) override
{
Entity child_entity = {child};
Entity child_entity = {child.index};
Parents::iterator parent_iter = m_parents.find(child_entity);
if (parent_iter.isValid())
{
@ -307,11 +309,12 @@ public:
serializer.read(size);
for (int i = 0; i < size; ++i)
{
int32 child, parent;
Entity child, parent;
serializer.read(child);
serializer.read(parent);
setParent({child}, {parent});
m_universe.addComponent({child}, HIERARCHY_TYPE_HANDLE, this, child);
ComponentHandle cmp = {child.index};
setParent(cmp, parent);
m_universe.addComponent(child, HIERARCHY_TYPE_HANDLE, this, cmp);
}
}

View file

@ -52,12 +52,12 @@ namespace Lumix
virtual ~Hierarchy() {}
virtual void setLocalPosition(ComponentIndex cmp, const Vec3& position) = 0;
virtual Vec3 getLocalPosition(ComponentIndex cmp) = 0;
virtual void setLocalPosition(ComponentHandle cmp, const Vec3& position) = 0;
virtual Vec3 getLocalPosition(ComponentHandle cmp) = 0;
virtual void setLocalRotation(Entity entity, const Quat& rotation) = 0;
virtual Quat getLocalRotation(ComponentIndex cmp) = 0;
virtual void setParent(ComponentIndex cmp, Entity parent) = 0;
virtual Entity getParent(ComponentIndex cmp) = 0;
virtual Quat getLocalRotation(ComponentHandle cmp) = 0;
virtual void setParent(ComponentHandle cmp, Entity parent) = 0;
virtual Entity getParent(ComponentHandle cmp) = 0;
virtual Array<Child>* getChildren(Entity parent) = 0;
virtual const Children& getAllChildren() const = 0;
};

View file

@ -378,7 +378,7 @@ float Universe::getScale(Entity entity)
}
void Universe::destroyComponent(Entity entity, ComponentType component_type, IScene* scene, ComponentIndex index)
void Universe::destroyComponent(Entity entity, ComponentType component_type, IScene* scene, ComponentHandle index)
{
auto mask = m_components[m_entity_map[entity.index]];
auto old_mask = mask;
@ -390,7 +390,7 @@ void Universe::destroyComponent(Entity entity, ComponentType component_type, ISc
}
void Universe::addComponent(Entity entity, ComponentType component_type, IScene* scene, ComponentIndex index)
void Universe::addComponent(Entity entity, ComponentType component_type, IScene* scene, ComponentHandle index)
{
ComponentUID cmp(entity, component_type, scene, index);
m_components[m_entity_map[entity.index]] |= (uint64)1 << component_type.index;

View file

@ -32,8 +32,8 @@ public:
void createEntity(Entity entity);
Entity createEntity(const Vec3& position, const Quat& rotation);
void destroyEntity(Entity entity);
void addComponent(Entity entity, ComponentType component_type, IScene* scene, ComponentIndex index);
void destroyComponent(Entity entity, ComponentType component_type, IScene* scene, ComponentIndex index);
void addComponent(Entity entity, ComponentType component_type, IScene* scene, ComponentHandle index);
void destroyComponent(Entity entity, ComponentType component_type, IScene* scene, ComponentHandle index);
int getEntityCount() const { return m_transformations.size(); }
int getDenseIdx(Entity entity);

View file

@ -147,7 +147,10 @@ struct PropertyGridPlugin : public PropertyGrid::IPlugin
void serialize(JsonSerializer& serializer) override { serializer.serialize("component", cmp); }
void deserialize(JsonSerializer& serializer) override { serializer.deserialize("component", cmp, 0); }
void deserialize(JsonSerializer& serializer) override
{
serializer.deserialize("component", cmp, INVALID_COMPONENT);
}
uint32 getType() override
@ -161,7 +164,7 @@ struct PropertyGridPlugin : public PropertyGrid::IPlugin
LuaScriptScene* scene;
ComponentIndex cmp;
ComponentHandle cmp;
int scr_index;
};
@ -211,7 +214,7 @@ struct PropertyGridPlugin : public PropertyGrid::IPlugin
void deserialize(JsonSerializer& serializer) override
{
serializer.deserialize("component", cmp, 0);
serializer.deserialize("component", cmp, INVALID_COMPONENT);
serializer.deserialize("scr_index", scr_index, 0);
}
@ -227,7 +230,7 @@ struct PropertyGridPlugin : public PropertyGrid::IPlugin
OutputBlob blob;
LuaScriptScene* scene;
ComponentIndex cmp;
ComponentHandle cmp;
int scr_index;
};
@ -244,7 +247,7 @@ struct PropertyGridPlugin : public PropertyGrid::IPlugin
SetPropertyCommand(LuaScriptScene* scene,
ComponentIndex cmp,
ComponentHandle cmp,
int scr_index,
const char* property_name,
const char* val,
@ -311,7 +314,7 @@ struct PropertyGridPlugin : public PropertyGrid::IPlugin
void deserialize(JsonSerializer& serializer) override
{
serializer.deserialize("component", component, 0);
serializer.deserialize("component", component, INVALID_COMPONENT);
serializer.deserialize("script_index", script_index, 0);
char buf[256];
serializer.deserialize("property_name", buf, lengthOf(buf), "");
@ -346,7 +349,7 @@ struct PropertyGridPlugin : public PropertyGrid::IPlugin
string property_name;
string value;
string old_value;
ComponentIndex component;
ComponentHandle component;
int script_index;
};
@ -389,14 +392,14 @@ struct PropertyGridPlugin : public PropertyGrid::IPlugin
{
auto* cmd = LUMIX_NEW(allocator, AddScriptCommand);
cmd->scene = scene;
cmd->cmp = cmp.index;
cmd->cmp = cmp.handle;
editor.executeCommand(cmd);
}
for (int j = 0; j < scene->getScriptCount(cmp.index); ++j)
for (int j = 0; j < scene->getScriptCount(cmp.handle); ++j)
{
char buf[MAX_PATH_LENGTH];
copyString(buf, scene->getScriptPath(cmp.index, j).c_str());
copyString(buf, scene->getScriptPath(cmp.handle, j).c_str());
StaticString<Lumix::MAX_PATH_LENGTH + 20> header;
PathUtils::getBasename(header.data, lengthOf(header.data), buf);
if (header.data[0] == 0) header << j;
@ -407,7 +410,7 @@ struct PropertyGridPlugin : public PropertyGrid::IPlugin
if (ImGui::Button("Remove script"))
{
auto* cmd = LUMIX_NEW(allocator, RemoveScriptCommand)(allocator);
cmd->cmp = cmp.index;
cmd->cmp = cmp.handle;
cmd->scr_index = j;
cmd->scene = scene;
editor.executeCommand(cmd);
@ -417,16 +420,16 @@ struct PropertyGridPlugin : public PropertyGrid::IPlugin
if (m_app.getAssetBrowser()->resourceInput("Source", "src", buf, lengthOf(buf), LUA_SCRIPT_HASH))
{
auto* cmd =
LUMIX_NEW(allocator, SetPropertyCommand)(scene, cmp.index, j, "-source", buf, allocator);
LUMIX_NEW(allocator, SetPropertyCommand)(scene, cmp.handle, j, "-source", buf, allocator);
editor.executeCommand(cmd);
}
for (int k = 0, kc = scene->getPropertyCount(cmp.index, j); k < kc; ++k)
for (int k = 0, kc = scene->getPropertyCount(cmp.handle, j); k < kc; ++k)
{
char buf[256];
const char* property_name = scene->getPropertyName(cmp.index, j, k);
const char* property_name = scene->getPropertyName(cmp.handle, j, k);
if (!property_name) continue;
scene->getPropertyValue(cmp.index, j, property_name, buf, lengthOf(buf));
switch (scene->getPropertyType(cmp.index, j, k))
scene->getPropertyValue(cmp.handle, j, property_name, buf, lengthOf(buf));
switch (scene->getPropertyType(cmp.handle, j, k))
{
case LuaScriptScene::Property::BOOLEAN:
{
@ -434,7 +437,7 @@ struct PropertyGridPlugin : public PropertyGrid::IPlugin
if (ImGui::Checkbox(property_name, &b))
{
auto* cmd = LUMIX_NEW(allocator, SetPropertyCommand)(
scene, cmp.index, j, property_name, b ? "true" : "false", allocator);
scene, cmp.handle, j, property_name, b ? "true" : "false", allocator);
editor.executeCommand(cmd);
}
}
@ -446,7 +449,7 @@ struct PropertyGridPlugin : public PropertyGrid::IPlugin
{
Lumix::toCString(f, buf, sizeof(buf), 5);
auto* cmd = LUMIX_NEW(allocator, SetPropertyCommand)(
scene, cmp.index, j, property_name, buf, allocator);
scene, cmp.handle, j, property_name, buf, allocator);
editor.executeCommand(cmd);
}
}
@ -455,11 +458,11 @@ struct PropertyGridPlugin : public PropertyGrid::IPlugin
{
Lumix::Entity e;
Lumix::fromCString(buf, sizeof(buf), &e.index);
if (grid.entityInput(property_name, StaticString<50>(property_name, cmp.index), e))
if (grid.entityInput(property_name, StaticString<50>(property_name, cmp.handle.index), e))
{
Lumix::toCString(e.index, buf, sizeof(buf));
auto* cmd = LUMIX_NEW(allocator, SetPropertyCommand)(
scene, cmp.index, j, property_name, buf, allocator);
scene, cmp.handle, j, property_name, buf, allocator);
editor.executeCommand(cmd);
}
}
@ -468,13 +471,13 @@ struct PropertyGridPlugin : public PropertyGrid::IPlugin
if (ImGui::InputText(property_name, buf, sizeof(buf)))
{
auto* cmd = LUMIX_NEW(allocator, SetPropertyCommand)(
scene, cmp.index, j, property_name, buf, allocator);
scene, cmp.handle, j, property_name, buf, allocator);
editor.executeCommand(cmd);
}
break;
}
}
if (auto* call = scene->beginFunctionCall(cmp.index, j, "onGUI"))
if (auto* call = scene->beginFunctionCall(cmp.handle, j, "onGUI"))
{
scene->endFunctionCall(*call);
}
@ -652,7 +655,7 @@ struct AddComponentPlugin : public StudioApp::IAddComponentPlugin
cmd->scene = static_cast<LuaScriptScene*>(editor.getUniverse()->getScene(LUA_SCRIPT_HASH));
Entity entity = editor.getSelectedEntities()[0];
cmd->cmp = editor.getComponent(entity, LUA_SCRIPT_TYPE).index;
cmd->cmp = editor.getComponent(entity, LUA_SCRIPT_TYPE).handle;
editor.executeCommand(cmd);
auto* set_source_cmd = LUMIX_NEW(allocator, PropertyGridPlugin::SetPropertyCommand)(

View file

@ -271,7 +271,7 @@ namespace Lumix
int parameter_count;
lua_State* state;
bool is_in_progress;
ComponentIndex cmp;
ComponentHandle cmp;
int scr_index;
};
@ -294,7 +294,7 @@ namespace Lumix
}
ComponentIndex getComponent(Entity entity) override
ComponentHandle getComponent(Entity entity) override
{
auto iter = m_entity_script_map.find(entity);
if (!iter.isValid()) return INVALID_COMPONENT;
@ -303,11 +303,11 @@ namespace Lumix
}
IFunctionCall* beginFunctionCall(ComponentIndex cmp, int scr_index, const char* function) override
IFunctionCall* beginFunctionCall(ComponentHandle cmp, int scr_index, const char* function) override
{
ASSERT(!m_function_call.is_in_progress);
auto& script = m_scripts[cmp]->m_scripts[scr_index];
auto& script = m_scripts[cmp.index]->m_scripts[scr_index];
if (!script.m_state) return nullptr;
bool is_env_valid = lua_rawgeti(script.m_state, LUA_REGISTRYINDEX, script.m_environment) == LUA_TTABLE;
@ -335,7 +335,7 @@ namespace Lumix
m_function_call.is_in_progress = false;
auto& script = m_scripts[m_function_call.cmp]->m_scripts[m_function_call.scr_index];
auto& script = m_scripts[m_function_call.cmp.index]->m_scripts[m_function_call.scr_index];
if (!script.m_state) return;
if (lua_pcall(script.m_state, m_function_call.parameter_count, 0, 0) != LUA_OK)
@ -347,21 +347,21 @@ namespace Lumix
}
int getPropertyCount(ComponentIndex cmp, int scr_index) override
int getPropertyCount(ComponentHandle cmp, int scr_index) override
{
return m_scripts[cmp]->m_scripts[scr_index].m_properties.size();
return m_scripts[cmp.index]->m_scripts[scr_index].m_properties.size();
}
const char* getPropertyName(ComponentIndex cmp, int scr_index, int prop_index) override
const char* getPropertyName(ComponentHandle cmp, int scr_index, int prop_index) override
{
return getPropertyName(m_scripts[cmp]->m_scripts[scr_index].m_properties[prop_index].name_hash);
return getPropertyName(m_scripts[cmp.index]->m_scripts[scr_index].m_properties[prop_index].name_hash);
}
Property::Type getPropertyType(ComponentIndex cmp, int scr_index, int prop_index) override
Property::Type getPropertyType(ComponentHandle cmp, int scr_index, int prop_index) override
{
return m_scripts[cmp]->m_scripts[scr_index].m_properties[prop_index].type;
return m_scripts[cmp.index]->m_scripts[scr_index].m_properties[prop_index].type;
}
@ -389,9 +389,9 @@ namespace Lumix
}
lua_State* getState(ComponentIndex cmp, int scr_index) override
lua_State* getState(ComponentHandle cmp, int scr_index) override
{
return m_scripts[cmp]->m_scripts[scr_index].m_state;
return m_scripts[cmp.index]->m_scripts[scr_index].m_state;
}
@ -438,7 +438,7 @@ namespace Lumix
Entity entity = LuaWrapper::checkArg<Entity>(L, 2);
int scr_index = LuaWrapper::checkArg<int>(L, 3);
ComponentIndex cmp = scene->getComponent(entity);
ComponentHandle cmp = scene->getComponent(entity);
if (cmp == INVALID_COMPONENT)
{
lua_pushnil(L);
@ -466,7 +466,7 @@ namespace Lumix
ComponentType type = { LuaWrapper::toType<int>(L, lua_upvalueindex(2)) };
ComponentUID cmp;
cmp.scene = LuaWrapper::checkArg<IScene*>(L, 1);
cmp.index = LuaWrapper::checkArg<ComponentIndex>(L, 2);
cmp.handle = LuaWrapper::checkArg<ComponentHandle>(L, 2);
cmp.type = type;
cmp.entity = INVALID_ENTITY;
switch (desc->getType())
@ -542,7 +542,7 @@ namespace Lumix
ComponentType type = { LuaWrapper::toType<int>(L, lua_upvalueindex(2)) };
ComponentUID cmp;
cmp.scene = LuaWrapper::checkArg<IScene*>(L, 1);
cmp.index = LuaWrapper::checkArg<ComponentIndex>(L, 2);
cmp.handle = LuaWrapper::checkArg<ComponentHandle>(L, 2);
cmp.type = type;
cmp.entity = INVALID_ENTITY;
switch(desc->getType())
@ -711,7 +711,7 @@ namespace Lumix
}
void setScriptSource(ComponentIndex cmp, int scr_index, const char* path)
void setScriptSource(ComponentHandle cmp, int scr_index, const char* path)
{
setScriptPath(cmp, scr_index, Lumix::Path(path));
}
@ -751,9 +751,9 @@ namespace Lumix
}
int getEnvironment(ComponentIndex cmp, int scr_index) override
int getEnvironment(ComponentHandle cmp, int scr_index) override
{
return m_scripts[cmp]->m_scripts[scr_index].m_environment;
return m_scripts[cmp.index]->m_scripts[scr_index].m_environment;
}
@ -802,30 +802,30 @@ namespace Lumix
}
void setPropertyValue(Lumix::ComponentIndex cmp,
void setPropertyValue(Lumix::ComponentHandle cmp,
int scr_index,
const char* name,
const char* value) override
{
if (!m_scripts[cmp]) return;
if(!m_scripts[cmp]->m_scripts[scr_index].m_state) return;
if (!m_scripts[cmp.index]) return;
if(!m_scripts[cmp.index]->m_scripts[scr_index].m_state) return;
Property& prop = getScriptProperty(cmp, scr_index, name);
applyProperty(m_scripts[cmp]->m_scripts[scr_index], prop, value);
applyProperty(m_scripts[cmp.index]->m_scripts[scr_index], prop, value);
}
const char* getPropertyName(Lumix::ComponentIndex cmp, int scr_index, int index) const
const char* getPropertyName(Lumix::ComponentHandle cmp, int scr_index, int index) const
{
auto& script = m_scripts[cmp]->m_scripts[scr_index];
auto& script = m_scripts[cmp.index]->m_scripts[scr_index];
return getPropertyName(script.m_properties[index].name_hash);
}
int getPropertyCount(Lumix::ComponentIndex cmp, int scr_index) const
int getPropertyCount(Lumix::ComponentHandle cmp, int scr_index) const
{
auto& script = m_scripts[cmp]->m_scripts[scr_index];
auto& script = m_scripts[cmp.index]->m_scripts[scr_index];
return script.m_properties.size();
}
@ -970,25 +970,25 @@ namespace Lumix
}
ComponentIndex createComponent(ComponentType type, Entity entity) override
ComponentHandle createComponent(ComponentType type, Entity entity) override
{
if (type != LUA_SCRIPT_TYPE) return INVALID_COMPONENT;
auto& allocator = m_system.getAllocator();
ScriptComponent& script = *LUMIX_NEW(allocator, ScriptComponent)(*this, allocator);
ComponentIndex cmp = INVALID_COMPONENT;
ComponentHandle cmp = INVALID_COMPONENT;
for (int i = 0; i < m_scripts.size(); ++i)
{
if (m_scripts[i] == nullptr)
{
cmp = i;
cmp = {i};
m_scripts[i] = &script;
break;
}
}
if (cmp == INVALID_COMPONENT)
if (!isValid(cmp))
{
cmp = m_scripts.size();
cmp = {m_scripts.size()};
m_scripts.push(&script);
}
m_entity_script_map.insert(entity, cmp);
@ -999,29 +999,29 @@ namespace Lumix
}
void destroyComponent(ComponentIndex component, ComponentType type) override
void destroyComponent(ComponentHandle component, ComponentType type) override
{
if (type != LUA_SCRIPT_TYPE) return;
for (auto& scr : m_scripts[component]->m_scripts)
auto* script = m_scripts[component.index];
for (auto& scr : script->m_scripts)
{
if (scr.m_state) destroyInstance(*m_scripts[component], scr);
if (scr.m_state) destroyInstance(*script, scr);
if (scr.m_script)
{
auto& cb = scr.m_script->getObserverCb();
cb.unbind<ScriptComponent, &ScriptComponent::onScriptLoaded>(m_scripts[component]);
cb.unbind<ScriptComponent, &ScriptComponent::onScriptLoaded>(script);
m_system.getScriptManager().unload(*scr.m_script);
}
}
m_entity_script_map.erase(m_scripts[component]->m_entity);
auto* script = m_scripts[component];
m_scripts[component] = nullptr;
m_entity_script_map.erase(script->m_entity);
m_scripts[component.index] = nullptr;
m_universe.destroyComponent(script->m_entity, type, this, component);
LUMIX_DELETE(m_system.getAllocator(), script);
}
void getPropertyValue(ComponentIndex cmp,
void getPropertyValue(ComponentHandle cmp,
int scr_index,
const char* property_name,
char* out,
@ -1030,7 +1030,7 @@ namespace Lumix
ASSERT(max_size > 0);
uint32 hash = crc32(property_name);
auto& inst = m_scripts[cmp]->m_scripts[scr_index];
auto& inst = m_scripts[cmp.index]->m_scripts[scr_index];
if (inst.m_script->isReady())
{
for (auto& prop : inst.m_properties)
@ -1148,7 +1148,7 @@ namespace Lumix
int scr_count;
serializer.read(m_scripts[i]->m_entity);
serializer.read(scr_count);
m_entity_script_map.insert(m_scripts[i]->m_entity, i);
m_entity_script_map.insert(m_scripts[i]->m_entity, {i});
for (int j = 0; j < scr_count; ++j)
{
auto& scr = script.m_scripts.emplace(allocator);
@ -1171,8 +1171,7 @@ namespace Lumix
}
setScriptPath(*m_scripts[i], scr, Path(tmp));
}
m_universe.addComponent(
Entity(m_scripts[i]->m_entity), LUA_SCRIPT_TYPE, this, i);
m_universe.addComponent(Entity(m_scripts[i]->m_entity), LUA_SCRIPT_TYPE, this, {i});
}
}
@ -1195,7 +1194,7 @@ namespace Lumix
ScriptComponent& script = *LUMIX_NEW(m_system.getAllocator(), ScriptComponent)(*this, m_system.getAllocator());
m_scripts.push(&script);
serializer.read(m_scripts[i]->m_entity);
m_entity_script_map.insert(m_scripts[i]->m_entity, i);
m_entity_script_map.insert(m_scripts[i]->m_entity, {i});
char tmp[MAX_PATH_LENGTH];
serializer.readString(tmp, MAX_PATH_LENGTH);
auto& scr = script.m_scripts.emplace(m_system.m_allocator);
@ -1215,7 +1214,7 @@ namespace Lumix
prop.stored_value = tmp;
}
setScriptPath(script, scr, Path(tmp));
m_universe.addComponent(m_scripts[i]->m_entity, LUA_SCRIPT_TYPE, this, i);
m_universe.addComponent(m_scripts[i]->m_entity, LUA_SCRIPT_TYPE, this, {i});
}
}
@ -1285,7 +1284,7 @@ namespace Lumix
}
ComponentIndex getComponent(Entity entity, ComponentType type) override
ComponentHandle getComponent(Entity entity, ComponentType type) override
{
ASSERT(ownComponentType(type));
auto iter = m_entity_script_map.find(entity);
@ -1300,10 +1299,10 @@ namespace Lumix
}
Property& getScriptProperty(ComponentIndex cmp, int scr_index, const char* name)
Property& getScriptProperty(ComponentHandle cmp, int scr_index, const char* name)
{
uint32 name_hash = crc32(name);
for (auto& prop : m_scripts[cmp]->m_scripts[scr_index].m_properties)
for (auto& prop : m_scripts[cmp.index]->m_scripts[scr_index].m_properties)
{
if (prop.name_hash == name_hash)
{
@ -1311,56 +1310,58 @@ namespace Lumix
}
}
m_scripts[cmp]->m_scripts[scr_index].m_properties.emplace(m_system.getAllocator());
auto& prop = m_scripts[cmp]->m_scripts[scr_index].m_properties.back();
m_scripts[cmp.index]->m_scripts[scr_index].m_properties.emplace(m_system.getAllocator());
auto& prop = m_scripts[cmp.index]->m_scripts[scr_index].m_properties.back();
prop.name_hash = name_hash;
return prop;
}
Path getScriptPath(ComponentIndex cmp, int scr_index) override
Path getScriptPath(ComponentHandle cmp, int scr_index) override
{
return m_scripts[cmp]->m_scripts[scr_index].m_script ? m_scripts[cmp]->m_scripts[scr_index].m_script->getPath() : Path("");
auto& tmp = m_scripts[cmp.index]->m_scripts[scr_index];
return tmp.m_script ? tmp.m_script->getPath() : Path("");
}
void setScriptPath(ComponentIndex cmp, int scr_index, const Path& path) override
void setScriptPath(ComponentHandle cmp, int scr_index, const Path& path) override
{
if (!m_scripts[cmp]) return;
if (m_scripts[cmp]->m_scripts.size() <= scr_index) return;
setScriptPath(*m_scripts[cmp], m_scripts[cmp]->m_scripts[scr_index], path);
auto* tmp = m_scripts[cmp.index];
if (!tmp) return;
if (tmp->m_scripts.size() <= scr_index) return;
setScriptPath(*tmp, tmp->m_scripts[scr_index], path);
}
int getScriptCount(ComponentIndex cmp) override
int getScriptCount(ComponentHandle cmp) override
{
return m_scripts[cmp]->m_scripts.size();
return m_scripts[cmp.index]->m_scripts.size();
}
void insertScript(ComponentIndex cmp, int idx) override
void insertScript(ComponentHandle cmp, int idx) override
{
m_scripts[cmp]->m_scripts.emplaceAt(idx, m_system.m_allocator);
m_scripts[cmp.index]->m_scripts.emplaceAt(idx, m_system.m_allocator);
}
int addScript(ComponentIndex cmp) override
int addScript(ComponentHandle cmp) override
{
m_scripts[cmp]->m_scripts.emplace(m_system.m_allocator);
return m_scripts[cmp]->m_scripts.size() - 1;
m_scripts[cmp.index]->m_scripts.emplace(m_system.m_allocator);
return m_scripts[cmp.index]->m_scripts.size() - 1;
}
void removeScript(ComponentIndex cmp, int scr_index) override
void removeScript(ComponentHandle cmp, int scr_index) override
{
setScriptPath(cmp, scr_index, Path());
m_scripts[cmp]->m_scripts.eraseFast(scr_index);
m_scripts[cmp.index]->m_scripts.eraseFast(scr_index);
}
void serializeScript(ComponentIndex cmp, int scr_index, OutputBlob& blob) override
void serializeScript(ComponentHandle cmp, int scr_index, OutputBlob& blob) override
{
auto& scr = m_scripts[cmp]->m_scripts[scr_index];
auto& scr = m_scripts[cmp.index]->m_scripts[scr_index];
blob.writeString(scr.m_script ? scr.m_script->getPath().c_str() : "");
blob.write(scr.m_properties.size());
for (auto prop : scr.m_properties)
@ -1381,9 +1382,9 @@ namespace Lumix
}
void deserializeScript(ComponentIndex cmp, int scr_index, InputBlob& blob) override
void deserializeScript(ComponentHandle cmp, int scr_index, InputBlob& blob) override
{
auto& scr = m_scripts[cmp]->m_scripts[scr_index];
auto& scr = m_scripts[cmp.index]->m_scripts[scr_index];
int count;
char path[MAX_PATH_LENGTH];
blob.readString(path, lengthOf(path));
@ -1405,7 +1406,7 @@ namespace Lumix
LuaScriptSystemImpl& m_system;
Array<ScriptComponent*> m_scripts;
HashMap<Entity, ComponentIndex> m_entity_script_map;
HashMap<Entity, ComponentHandle> m_entity_script_map;
AssociativeArray<uint32, string> m_property_names;
Universe& m_universe;
Array<UpdateData> m_updates;

View file

@ -53,24 +53,24 @@ public:
typedef int (*lua_CFunction) (lua_State *L);
public:
virtual Path getScriptPath(ComponentIndex cmp, int scr_index) = 0;
virtual void setScriptPath(ComponentIndex cmp, int scr_index, const Path& path) = 0;
virtual ComponentIndex getComponent(Entity entity) = 0;
virtual int getEnvironment(ComponentIndex cmp, int scr_index) = 0;
virtual IFunctionCall* beginFunctionCall(ComponentIndex cmp, int scr_index, const char* function) = 0;
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 void endFunctionCall(IFunctionCall& caller) = 0;
virtual int getScriptCount(ComponentIndex cmp) = 0;
virtual lua_State* getState(ComponentIndex cmp, int scr_index) = 0;
virtual void insertScript(ComponentIndex cmp, int idx) = 0;
virtual int addScript(ComponentIndex cmp) = 0;
virtual void removeScript(ComponentIndex cmp, int scr_index) = 0;
virtual void serializeScript(ComponentIndex cmp, int scr_index, OutputBlob& blob) = 0;
virtual void deserializeScript(ComponentIndex cmp, int scr_index, InputBlob& blob) = 0;
virtual void setPropertyValue(Lumix::ComponentIndex cmp, int scr_index, const char* name, const char* value) = 0;
virtual void getPropertyValue(ComponentIndex cmp, int scr_index, const char* property_name, char* out, int max_size) = 0;
virtual int getPropertyCount(ComponentIndex cmp, int scr_index) = 0;
virtual const char* getPropertyName(ComponentIndex cmp, int scr_index, int prop_index) = 0;
virtual Property::Type getPropertyType(ComponentIndex cmp, int scr_index, int prop_index) = 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 serializeScript(ComponentHandle cmp, int scr_index, OutputBlob& blob) = 0;
virtual void deserializeScript(ComponentHandle cmp, int scr_index, InputBlob& blob) = 0;
virtual void setPropertyValue(Lumix::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;
};

View file

@ -218,7 +218,7 @@ struct NavigationSceneImpl : public NavigationScene
auto render_scene = static_cast<RenderScene*>(m_universe.getScene(crc32("renderer")));
if (!render_scene) return;
ComponentIndex cmp = render_scene->getFirstTerrain();
ComponentHandle cmp = render_scene->getFirstTerrain();
while (cmp != INVALID_COMPONENT)
{
Entity entity = render_scene->getTerrainEntity(cmp);
@ -947,7 +947,7 @@ struct NavigationSceneImpl : public NavigationScene
m_aabb.merge(model_bb);
}
ComponentIndex cmp = render_scene->getFirstTerrain();
ComponentHandle cmp = render_scene->getFirstTerrain();
while (cmp != INVALID_COMPONENT)
{
AABB terrain_aabb = render_scene->getTerrainAABB(cmp);
@ -1041,7 +1041,7 @@ struct NavigationSceneImpl : public NavigationScene
}
ComponentIndex createComponent(ComponentType type, Entity entity) override
ComponentHandle createComponent(ComponentType type, Entity entity) override
{
if (type == NAVMESH_AGENT_TYPE)
{
@ -1053,23 +1053,25 @@ struct NavigationSceneImpl : public NavigationScene
agent->is_finished = true;
if (m_crowd) addCrowdAgent(agent);
m_agents.insert(entity, agent);
m_universe.addComponent(entity, type, this, entity.index);
return entity.index;
ComponentHandle cmp = {entity.index};
m_universe.addComponent(entity, type, this, cmp);
return cmp;
}
return INVALID_COMPONENT;
}
void destroyComponent(ComponentIndex component, ComponentType type) override
void destroyComponent(ComponentHandle component, ComponentType type) override
{
if (type == NAVMESH_AGENT_TYPE)
{
auto iter = m_agents.find({component});
Entity entity = { component.index };
auto iter = m_agents.find(entity);
Agent* agent = iter.value();
if (m_crowd && agent->agent >= 0) m_crowd->removeAgent(agent->agent);
LUMIX_DELETE(m_allocator, iter.value());
m_agents.erase(iter);
m_universe.destroyComponent({component}, type, this, component);
m_universe.destroyComponent(entity, type, this, component);
}
else
{
@ -1108,41 +1110,46 @@ struct NavigationSceneImpl : public NavigationScene
serializer.read(agent->height);
agent->agent = -1;
m_agents.insert(entity, agent);
m_universe.addComponent(entity, NAVMESH_AGENT_TYPE, this, entity.index);
ComponentHandle cmp = { entity.index };
m_universe.addComponent(entity, NAVMESH_AGENT_TYPE, this, cmp);
}
}
}
void setAgentRadius(ComponentIndex cmp, float radius)
void setAgentRadius(ComponentHandle cmp, float radius)
{
m_agents[{cmp}]->radius = radius;
Entity entity = {cmp.index};
m_agents[entity]->radius = radius;
}
float getAgentRadius(ComponentIndex cmp)
float getAgentRadius(ComponentHandle cmp)
{
return m_agents[{cmp}]->radius;
Entity entity = { cmp.index };
return m_agents[entity]->radius;
}
void setAgentHeight(ComponentIndex cmp, float height)
void setAgentHeight(ComponentHandle cmp, float height)
{
m_agents[{cmp}]->height = height;
Entity entity = { cmp.index };
m_agents[entity]->height = height;
}
float getAgentHeight(ComponentIndex cmp)
float getAgentHeight(ComponentHandle cmp)
{
return m_agents[{cmp}]->height;
Entity entity = {cmp.index};
return m_agents[entity]->height;
}
IPlugin& getPlugin() const override { return m_system; }
bool ownComponentType(ComponentType type) const override { return type == NAVMESH_AGENT_TYPE; }
ComponentIndex getComponent(Entity entity, ComponentType type) override
ComponentHandle getComponent(Entity entity, ComponentType type) override
{
if (type == NAVMESH_AGENT_TYPE) return entity.index;
if (type == NAVMESH_AGENT_TYPE) return {entity.index};
return INVALID_COMPONENT;
}
Universe& getUniverse() override { return m_universe; }

View file

@ -38,8 +38,8 @@ struct EditorPlugin : public WorldEditor::Plugin
if (cmp.type == CONTROLLER_TYPE)
{
auto* scene = static_cast<RenderScene*>(m_editor.getUniverse()->getScene(crc32("renderer")));
float height = phy_scene->getControllerHeight(cmp.index);
float radius = phy_scene->getControllerRadius(cmp.index);
float height = phy_scene->getControllerHeight(cmp.handle);
float radius = phy_scene->getControllerRadius(cmp.handle);
Universe& universe = scene->getUniverse();
Vec3 pos = universe.getPosition(cmp.entity);
@ -50,7 +50,7 @@ struct EditorPlugin : public WorldEditor::Plugin
if (cmp.type == BOX_ACTOR_TYPE)
{
auto* scene = static_cast<RenderScene*>(m_editor.getUniverse()->getScene(crc32("renderer")));
Vec3 extents = phy_scene->getHalfExtents(cmp.index);
Vec3 extents = phy_scene->getHalfExtents(cmp.handle);
Universe& universe = scene->getUniverse();
Matrix mtx = universe.getPositionAndRotation(cmp.entity);

View file

@ -316,14 +316,14 @@ struct PhysicsSceneImpl : public PhysicsScene
}
ComponentIndex getComponent(Entity entity, ComponentType type) override
ComponentHandle getComponent(Entity entity, ComponentType type) override
{
ASSERT(ownComponentType(type));
if (type == BOX_ACTOR_TYPE || type == MESH_ACTOR_TYPE)
{
for (int i = 0; i < m_actors.size(); ++i)
{
if (m_actors[i] && m_actors[i]->getEntity() == entity) return i;
if (m_actors[i] && m_actors[i]->getEntity() == entity) return {i};
}
return INVALID_COMPONENT;
}
@ -331,7 +331,7 @@ struct PhysicsSceneImpl : public PhysicsScene
{
for (int i = 0; i < m_controllers.size(); ++i)
{
if (!m_controllers[i].m_is_free && m_controllers[i].m_entity == entity) return i;
if (!m_controllers[i].m_is_free && m_controllers[i].m_entity == entity) return {i};
}
return INVALID_COMPONENT;
}
@ -339,7 +339,7 @@ struct PhysicsSceneImpl : public PhysicsScene
{
for (int i = 0; i < m_terrains.size(); ++i)
{
if (m_terrains[i] && m_terrains[i]->m_entity == entity) return i;
if (m_terrains[i] && m_terrains[i]->m_entity == entity) return {i};
}
return INVALID_COMPONENT;
}
@ -350,22 +350,22 @@ struct PhysicsSceneImpl : public PhysicsScene
IPlugin& getPlugin() const override { return *m_system; }
int getControllerLayer(ComponentIndex cmp) override
int getControllerLayer(ComponentHandle cmp) override
{
return m_controllers[cmp].m_layer;
return m_controllers[cmp.index].m_layer;
}
void setControllerLayer(ComponentIndex cmp, int layer) override
void setControllerLayer(ComponentHandle cmp, int layer) override
{
ASSERT(layer < lengthOf(m_layers_names));
m_controllers[cmp].m_layer = layer;
m_controllers[cmp.index].m_layer = layer;
physx::PxFilterData data;
data.word0 = 1 << layer;
data.word1 = m_collision_filter[layer];
physx::PxShape* shapes[8];
int shapes_count = m_controllers[cmp].m_controller->getActor()->getShapes(shapes, lengthOf(shapes));
int shapes_count = m_controllers[cmp.index].m_controller->getActor()->getShapes(shapes, lengthOf(shapes));
for (int i = 0; i < shapes_count; ++i)
{
shapes[i]->setSimulationFilterData(data);
@ -373,29 +373,30 @@ struct PhysicsSceneImpl : public PhysicsScene
}
void setActorLayer(ComponentIndex cmp, int layer) override
void setActorLayer(ComponentHandle cmp, int layer) override
{
ASSERT(layer < lengthOf(m_layers_names));
m_actors[cmp]->setLayer(layer);
updateFilterData(m_actors[cmp]->getPhysxActor(), m_actors[cmp]->getLayer());
auto* actor = m_actors[cmp.index];
actor->setLayer(layer);
updateFilterData(actor->getPhysxActor(), actor->getLayer());
}
int getActorLayer(ComponentIndex cmp) override { return m_actors[cmp]->getLayer(); }
int getHeightfieldLayer(ComponentIndex cmp) override { return m_terrains[cmp]->m_layer; }
int getActorLayer(ComponentHandle cmp) override { return m_actors[cmp.index]->getLayer(); }
int getHeightfieldLayer(ComponentHandle cmp) override { return m_terrains[cmp.index]->m_layer; }
void setHeightfieldLayer(ComponentIndex cmp, int layer) override
void setHeightfieldLayer(ComponentHandle cmp, int layer) override
{
ASSERT(layer < lengthOf(m_layers_names));
m_terrains[cmp]->m_layer = layer;
m_terrains[cmp.index]->m_layer = layer;
if (m_terrains[cmp]->m_actor)
if (m_terrains[cmp.index]->m_actor)
{
physx::PxFilterData data;
data.word0 = 1 << layer;
data.word1 = m_collision_filter[layer];
physx::PxShape* shapes[8];
int shapes_count = m_terrains[cmp]->m_actor->getShapes(shapes, lengthOf(shapes));
int shapes_count = m_terrains[cmp.index]->m_actor->getShapes(shapes, lengthOf(shapes));
for (int i = 0; i < shapes_count; ++i)
{
shapes[i]->setSimulationFilterData(data);
@ -404,7 +405,7 @@ struct PhysicsSceneImpl : public PhysicsScene
}
ComponentIndex createComponent(ComponentType component_type, Entity entity) override
ComponentHandle createComponent(ComponentType component_type, Entity entity) override
{
if (component_type == HEIGHTFIELD_TYPE)
{
@ -426,27 +427,27 @@ struct PhysicsSceneImpl : public PhysicsScene
}
void destroyComponent(ComponentIndex cmp, ComponentType type) override
void destroyComponent(ComponentHandle cmp, ComponentType type) override
{
if (type == HEIGHTFIELD_TYPE)
{
Entity entity = m_terrains[cmp]->m_entity;
LUMIX_DELETE(m_allocator, m_terrains[cmp]);
m_terrains[cmp] = nullptr;
Entity entity = m_terrains[cmp.index]->m_entity;
LUMIX_DELETE(m_allocator, m_terrains[cmp.index]);
m_terrains[cmp.index] = nullptr;
m_universe.destroyComponent(entity, type, this, cmp);
}
else if (type == CONTROLLER_TYPE)
{
Entity entity = m_controllers[cmp].m_entity;
m_controllers[cmp].m_is_free = true;
Entity entity = m_controllers[cmp.index].m_entity;
m_controllers[cmp.index].m_is_free = true;
m_universe.destroyComponent(entity, type, this, cmp);
}
else if (type == MESH_ACTOR_TYPE || type == BOX_ACTOR_TYPE)
{
Entity entity = m_actors[cmp]->getEntity();
m_actors[cmp]->setEntity(INVALID_ENTITY);
m_actors[cmp]->setPhysxActor(nullptr);
m_dynamic_actors.eraseItem(m_actors[cmp]);
Entity entity = m_actors[cmp.index]->getEntity();
m_actors[cmp.index]->setEntity(INVALID_ENTITY);
m_actors[cmp.index]->setPhysxActor(nullptr);
m_dynamic_actors.eraseItem(m_actors[cmp.index]);
m_universe.destroyComponent(entity, type, this, cmp);
}
else
@ -456,7 +457,7 @@ struct PhysicsSceneImpl : public PhysicsScene
}
ComponentIndex createHeightfield(Entity entity)
ComponentHandle createHeightfield(Entity entity)
{
Heightfield* terrain = LUMIX_NEW(m_allocator, Heightfield)();
m_terrains.push(terrain);
@ -464,13 +465,13 @@ struct PhysicsSceneImpl : public PhysicsScene
terrain->m_scene = this;
terrain->m_actor = nullptr;
terrain->m_entity = entity;
m_universe.addComponent(
entity, HEIGHTFIELD_TYPE, this, m_terrains.size() - 1);
return m_terrains.size() - 1;
ComponentHandle cmp = {m_terrains.size() - 1};
m_universe.addComponent(entity, HEIGHTFIELD_TYPE, this, cmp);
return cmp;
}
ComponentIndex createController(Entity entity)
ComponentHandle createController(Entity entity)
{
physx::PxCapsuleControllerDesc cDesc;
cDesc.material = m_default_material;
@ -503,12 +504,13 @@ struct PhysicsSceneImpl : public PhysicsScene
shapes[i]->setSimulationFilterData(data);
}
m_universe.addComponent(entity, CONTROLLER_TYPE, this, m_controllers.size() - 1);
return m_controllers.size() - 1;
ComponentHandle cmp = { m_controllers.size() - 1 };
m_universe.addComponent(entity, CONTROLLER_TYPE, this, cmp);
return cmp;
}
ComponentIndex createBoxRigidActor(Entity entity)
ComponentHandle createBoxRigidActor(Entity entity)
{
RigidActor* actor = LUMIX_NEW(m_allocator, RigidActor)(*this);
m_actors.push(actor);
@ -521,111 +523,114 @@ struct PhysicsSceneImpl : public PhysicsScene
physx::PxTransform transform;
Matrix mtx = m_universe.getPositionAndRotation(entity);
matrix2Transform(mtx, transform);
physx::PxRigidStatic* physx_actor =
PxCreateStatic(*m_system->getPhysics(), transform, geom, *m_default_material);
actor->setPhysxActor(physx_actor);
m_universe.addComponent(entity, BOX_ACTOR_TYPE, this, m_actors.size() - 1);
return m_actors.size() - 1;
ComponentHandle cmp = {m_actors.size() - 1};
m_universe.addComponent(entity, BOX_ACTOR_TYPE, this, cmp);
return cmp;
}
ComponentIndex createMeshRigidActor(Entity entity)
ComponentHandle createMeshRigidActor(Entity entity)
{
RigidActor* actor = LUMIX_NEW(m_allocator, RigidActor)(*this);
m_actors.push(actor);
actor->setEntity(entity);
m_universe.addComponent(
entity, MESH_ACTOR_TYPE, this, m_actors.size() - 1);
return m_actors.size() - 1;
ComponentHandle cmp = {m_actors.size() - 1};
m_universe.addComponent(entity, MESH_ACTOR_TYPE, this, cmp);
return cmp;
}
Path getHeightmap(ComponentIndex cmp) override
Path getHeightmap(ComponentHandle cmp) override
{
return m_terrains[cmp]->m_heightmap
? m_terrains[cmp]->m_heightmap->getPath()
return m_terrains[cmp.index]->m_heightmap
? m_terrains[cmp.index]->m_heightmap->getPath()
: Path("");
}
float getHeightmapXZScale(ComponentIndex cmp) override
float getHeightmapXZScale(ComponentHandle cmp) override
{
return m_terrains[cmp]->m_xz_scale;
return m_terrains[cmp.index]->m_xz_scale;
}
void setHeightmapXZScale(ComponentIndex cmp, float scale) override
void setHeightmapXZScale(ComponentHandle cmp, float scale) override
{
if (scale != m_terrains[cmp]->m_xz_scale)
auto* terrain = m_terrains[cmp.index];
if (scale != terrain->m_xz_scale)
{
m_terrains[cmp]->m_xz_scale = scale;
if (m_terrains[cmp]->m_heightmap &&
m_terrains[cmp]->m_heightmap->isReady())
terrain->m_xz_scale = scale;
if (terrain->m_heightmap && terrain->m_heightmap->isReady())
{
heightmapLoaded(m_terrains[cmp]);
heightmapLoaded(terrain);
}
}
}
float getHeightmapYScale(ComponentIndex cmp) override
float getHeightmapYScale(ComponentHandle cmp) override
{
return m_terrains[cmp]->m_y_scale;
return m_terrains[cmp.index]->m_y_scale;
}
void setHeightmapYScale(ComponentIndex cmp, float scale) override
void setHeightmapYScale(ComponentHandle cmp, float scale) override
{
if (scale != m_terrains[cmp]->m_y_scale)
auto* terrain = m_terrains[cmp.index];
if (scale != terrain->m_y_scale)
{
m_terrains[cmp]->m_y_scale = scale;
if (m_terrains[cmp]->m_heightmap && m_terrains[cmp]->m_heightmap->isReady())
terrain->m_y_scale = scale;
if (terrain->m_heightmap && terrain->m_heightmap->isReady())
{
heightmapLoaded(m_terrains[cmp]);
heightmapLoaded(terrain);
}
}
}
void setHeightmap(ComponentIndex cmp, const Path& str) override
void setHeightmap(ComponentHandle cmp, const Path& str) override
{
auto& resource_manager = m_engine->getResourceManager();
auto* old_hm = m_terrains[cmp]->m_heightmap;
auto* terrain = m_terrains[cmp.index];
auto* old_hm = terrain->m_heightmap;
if (old_hm)
{
resource_manager.get(TEXTURE_HASH)->unload(*old_hm);
auto& cb = old_hm->getObserverCb();
cb.unbind<Heightfield, &Heightfield::heightmapLoaded>(m_terrains[cmp]);
cb.unbind<Heightfield, &Heightfield::heightmapLoaded>(terrain);
}
auto* texture_manager = resource_manager.get(TEXTURE_HASH);
if (str.isValid())
{
auto* new_hm = static_cast<Texture*>(texture_manager->load(str));
m_terrains[cmp]->m_heightmap = new_hm;
new_hm->onLoaded<Heightfield, &Heightfield::heightmapLoaded>(m_terrains[cmp]);
terrain->m_heightmap = new_hm;
new_hm->onLoaded<Heightfield, &Heightfield::heightmapLoaded>(terrain);
new_hm->addDataReference();
}
else
{
m_terrains[cmp]->m_heightmap = nullptr;
terrain->m_heightmap = nullptr;
}
}
Path getShapeSource(ComponentIndex cmp) override
Path getShapeSource(ComponentHandle cmp) override
{
return m_actors[cmp]->getResource() ? m_actors[cmp]->getResource()->getPath() : Path("");
return m_actors[cmp.index]->getResource() ? m_actors[cmp.index]->getResource()->getPath() : Path("");
}
void setShapeSource(ComponentIndex cmp, const Path& str) override
void setShapeSource(ComponentHandle cmp, const Path& str) override
{
ASSERT(m_actors[cmp]);
ASSERT(m_actors[cmp.index]);
bool is_dynamic = isDynamic(cmp);
auto& actor = *m_actors[cmp];
auto& actor = *m_actors[cmp.index];
if (actor.getResource() && actor.getResource()->getPath() == str &&
(!actor.getPhysxActor() || is_dynamic == !actor.getPhysxActor()->isRigidStatic()))
{
@ -635,8 +640,8 @@ struct PhysicsSceneImpl : public PhysicsScene
ResourceManagerBase* manager = m_engine->getResourceManager().get(PHYSICS_HASH);
PhysicsGeometry* geom_res = static_cast<PhysicsGeometry*>(manager->load(str));
m_actors[cmp]->setPhysxActor(nullptr);
m_actors[cmp]->setResource(geom_res);
actor.setPhysxActor(nullptr);
actor.setResource(geom_res);
}
@ -723,7 +728,7 @@ struct PhysicsSceneImpl : public PhysicsScene
{
for (auto& i : m_queued_forces)
{
auto* actor = m_actors[i.cmp];
auto* actor = m_actors[i.cmp.index];
if (!actor->isDynamic())
{
g_log_warning.log("Physics") << "Trying to apply force to static object";
@ -753,56 +758,43 @@ struct PhysicsSceneImpl : public PhysicsScene
}
ComponentIndex getActorComponent(Entity entity) override
ComponentHandle getActorComponent(Entity entity) override
{
for (int i = 0; i < m_actors.size(); ++i)
{
if (m_actors[i]->getEntity() == entity) return i;
if (m_actors[i]->getEntity() == entity) return {i};
}
return -1;
return INVALID_COMPONENT;
}
void startGame() override
{
{
auto* scene = m_universe.getScene(crc32("lua_script"));
m_script_scene = static_cast<LuaScriptScene*>(scene);
m_is_game_running = true;
m_is_game_running = true;
}
void stopGame() override { m_is_game_running = false; }
float getControllerRadius(ComponentHandle cmp) override { return m_controllers[cmp.index].m_radius; }
float getControllerHeight(ComponentHandle cmp) override { return m_controllers[cmp.index].m_height; }
float getControllerRadius(ComponentIndex cmp) override
{
return m_controllers[cmp].m_radius;
}
float getControllerHeight(ComponentIndex cmp) override
{
return m_controllers[cmp].m_height;
}
ComponentIndex getController(Entity entity) override
ComponentHandle getController(Entity entity) override
{
for (int i = 0; i < m_controllers.size(); ++i)
{
if (m_controllers[i].m_entity == entity)
{
return i;
return {i};
}
}
return INVALID_COMPONENT;
}
void moveController(ComponentIndex cmp, const Vec3& v) override
{
m_controllers[cmp].m_frame_change += v;
}
void moveController(ComponentHandle cmp, const Vec3& v) override { m_controllers[cmp.index].m_frame_change += v; }
static int LUA_raycast(lua_State* L)
@ -832,22 +824,17 @@ struct PhysicsSceneImpl : public PhysicsScene
}
bool raycastEx(const Vec3& origin,
const Vec3& dir,
float distance,
RaycastHit& result) override
bool raycastEx(const Vec3& origin, const Vec3& dir, float distance, RaycastHit& result) override
{
physx::PxVec3 physx_origin(origin.x, origin.y, origin.z);
physx::PxVec3 unit_dir(dir.x, dir.y, dir.z);
physx::PxReal max_distance = distance;
physx::PxRaycastHit hit;
const physx::PxSceneQueryFlags outputFlags = physx::PxSceneQueryFlag::eDISTANCE |
physx::PxSceneQueryFlag::eIMPACT |
physx::PxSceneQueryFlag::eNORMAL;
const physx::PxSceneQueryFlags outputFlags =
physx::PxSceneQueryFlag::eDISTANCE | physx::PxSceneQueryFlag::eIMPACT | physx::PxSceneQueryFlag::eNORMAL;
bool status =
m_scene->raycastSingle(physx_origin, unit_dir, max_distance, outputFlags, hit);
bool status = m_scene->raycastSingle(physx_origin, unit_dir, max_distance, outputFlags, hit);
result.normal.x = hit.normal.x;
result.normal.y = hit.normal.y;
result.normal.z = hit.normal.z;
@ -1151,9 +1138,9 @@ struct PhysicsSceneImpl : public PhysicsScene
}
bool isDynamic(ComponentIndex cmp) override
bool isDynamic(ComponentHandle cmp) override
{
RigidActor* actor = m_actors[cmp];
RigidActor* actor = m_actors[cmp.index];
return isDynamic(actor);
}
@ -1171,13 +1158,13 @@ struct PhysicsSceneImpl : public PhysicsScene
}
Vec3 getHalfExtents(ComponentIndex cmp) override
Vec3 getHalfExtents(ComponentHandle cmp) override
{
Vec3 size;
physx::PxRigidActor* actor = m_actors[cmp]->getPhysxActor();
physx::PxRigidActor* actor = m_actors[cmp.index]->getPhysxActor();
physx::PxShape* shapes;
if (actor->getNbShapes() == 1 &&
m_actors[cmp]->getPhysxActor()->getShapes(&shapes, 1))
m_actors[cmp.index]->getPhysxActor()->getShapes(&shapes, 1))
{
physx::PxVec3& half = shapes->getGeometry().box().halfExtents;
size.x = half.x;
@ -1188,12 +1175,11 @@ struct PhysicsSceneImpl : public PhysicsScene
}
void setHalfExtents(ComponentIndex cmp, const Vec3& size) override
void setHalfExtents(ComponentHandle cmp, const Vec3& size) override
{
physx::PxRigidActor* actor = m_actors[cmp]->getPhysxActor();
physx::PxRigidActor* actor = m_actors[cmp.index]->getPhysxActor();
physx::PxShape* shapes;
if (actor->getNbShapes() == 1 &&
m_actors[cmp]->getPhysxActor()->getShapes(&shapes, 1))
if (actor->getNbShapes() == 1 && m_actors[cmp.index]->getPhysxActor()->getShapes(&shapes, 1))
{
physx::PxBoxGeometry box;
bool is_box = shapes->getBoxGeometry(box);
@ -1207,54 +1193,43 @@ struct PhysicsSceneImpl : public PhysicsScene
}
void setIsDynamic(ComponentIndex cmp, bool new_value) override
void setIsDynamic(ComponentHandle cmp, bool new_value) override
{
RigidActor* actor = m_actors[cmp];
RigidActor* actor = m_actors[cmp.index];
int dynamic_index = m_dynamic_actors.indexOf(actor);
bool is_dynamic = dynamic_index != -1;
if (is_dynamic != new_value)
if (is_dynamic == new_value) return;
actor->setDynamic(new_value);
if (new_value)
{
m_actors[cmp]->setDynamic(new_value);
m_dynamic_actors.push(actor);
}
else
{
m_dynamic_actors.eraseItemFast(actor);
}
physx::PxShape* shapes;
if (actor->getPhysxActor()->getNbShapes() == 1 && actor->getPhysxActor()->getShapes(&shapes, 1, 0))
{
physx::PxGeometryHolder geom = shapes->getGeometry();
physx::PxTransform transform;
matrix2Transform(m_universe.getPositionAndRotation(actor->getEntity()), transform);
physx::PxRigidActor* physx_actor;
if (new_value)
{
m_dynamic_actors.push(actor);
physx_actor = PxCreateDynamic(*m_system->getPhysics(), transform, geom.any(), *m_default_material, 1.0f);
}
else
{
m_dynamic_actors.eraseItemFast(actor);
}
physx::PxShape* shapes;
if (m_actors[cmp]->getPhysxActor()->getNbShapes() == 1 &&
m_actors[cmp]->getPhysxActor()->getShapes(&shapes, 1, 0))
{
physx::PxGeometryHolder geom = shapes->getGeometry();
physx::PxTransform transform;
matrix2Transform(
m_universe.getPositionAndRotation(m_actors[cmp]->getEntity()),
transform);
physx::PxRigidActor* actor;
if (new_value)
{
actor = PxCreateDynamic(*m_system->getPhysics(),
transform,
geom.any(),
*m_default_material,
1.0f);
}
else
{
actor = PxCreateStatic(*m_system->getPhysics(),
transform,
geom.any(),
*m_default_material);
}
ASSERT(actor);
actor->userData = (void*)(intptr_t)m_actors[cmp]->getEntity().index;
actor->setActorFlag(physx::PxActorFlag::eVISUALIZATION, true);
m_actors[cmp]->setPhysxActor(actor);
physx_actor = PxCreateStatic(*m_system->getPhysics(), transform, geom.any(), *m_default_material);
}
ASSERT(actor);
physx_actor->userData = (void*)(intptr_t)actor->getEntity().index;
physx_actor->setActorFlag(physx::PxActorFlag::eVISUALIZATION, true);
actor->setPhysxActor(physx_actor);
}
}
@ -1305,11 +1280,12 @@ struct PhysicsSceneImpl : public PhysicsScene
}
void deserializeActor(InputBlob& serializer, int idx, int version)
void deserializeActor(InputBlob& serializer, ComponentHandle cmp, int version)
{
int layer = 0;
if (version > (int)PhysicsSceneVersion::LAYERS) serializer.read(layer);
m_actors[idx]->setLayer(layer);
auto* actor = m_actors[cmp.index];
actor->setLayer(layer);
ActorType type;
serializer.read((int32&)type);
@ -1320,24 +1296,23 @@ struct PhysicsSceneImpl : public PhysicsScene
{
physx::PxBoxGeometry box_geom;
physx::PxTransform transform;
Matrix mtx = m_universe.getPositionAndRotation(m_actors[idx]->getEntity());
Matrix mtx = m_universe.getPositionAndRotation(actor->getEntity());
matrix2Transform(mtx, transform);
serializer.read(box_geom.halfExtents.x);
serializer.read(box_geom.halfExtents.y);
serializer.read(box_geom.halfExtents.z);
physx::PxRigidActor* actor;
if (isDynamic(idx))
physx::PxRigidActor* physx_actor;
if (isDynamic(cmp))
{
actor = PxCreateDynamic(
*m_system->getPhysics(), transform, box_geom, *m_default_material, 1.0f);
physx_actor =
PxCreateDynamic(*m_system->getPhysics(), transform, box_geom, *m_default_material, 1.0f);
}
else
{
actor = PxCreateStatic(
*m_system->getPhysics(), transform, box_geom, *m_default_material);
physx_actor = PxCreateStatic(*m_system->getPhysics(), transform, box_geom, *m_default_material);
}
m_actors[idx]->setPhysxActor(actor);
m_universe.addComponent(m_actors[idx]->getEntity(), BOX_ACTOR_TYPE, this, idx);
actor->setPhysxActor(physx_actor);
m_universe.addComponent(actor->getEntity(), BOX_ACTOR_TYPE, this, cmp);
}
break;
case TRIMESH:
@ -1347,8 +1322,8 @@ struct PhysicsSceneImpl : public PhysicsScene
serializer.readString(tmp, sizeof(tmp));
ResourceManagerBase* manager = m_engine->getResourceManager().get(PHYSICS_HASH);
auto* geometry = manager->load(Lumix::Path(tmp));
m_actors[idx]->setResource(static_cast<PhysicsGeometry*>(geometry));
m_universe.addComponent(m_actors[idx]->getEntity(), MESH_ACTOR_TYPE, this, idx);
actor->setResource(static_cast<PhysicsGeometry*>(geometry));
m_universe.addComponent(actor->getEntity(), MESH_ACTOR_TYPE, this, cmp);
}
break;
default:
@ -1366,7 +1341,7 @@ struct PhysicsSceneImpl : public PhysicsScene
serializer.write((int32)m_actors.size());
for (int i = 0; i < m_actors.size(); ++i)
{
serializer.write(isDynamic(i));
serializer.write(isDynamic({i}));
serializer.write(m_actors[i]->getEntity());
if (isValid(m_actors[i]->getEntity()))
{
@ -1437,7 +1412,7 @@ struct PhysicsSceneImpl : public PhysicsScene
if (isValid(m_actors[i]->getEntity()))
{
deserializeActor(serializer, i, version);
deserializeActor(serializer, {i}, version);
}
}
}
@ -1466,32 +1441,30 @@ struct PhysicsSceneImpl : public PhysicsScene
c.m_is_free = is_free;
c.m_frame_change.set(0, 0, 0);
if (!is_free)
if (is_free) continue;
if (version > (int)PhysicsSceneVersion::LAYERS)
{
if (version > (int)PhysicsSceneVersion::LAYERS)
{
serializer.read(c.m_layer);
}
else
{
c.m_layer = 0;
}
physx::PxCapsuleControllerDesc cDesc;
cDesc.material = m_default_material;
cDesc.height = 1.8f;
cDesc.radius = 0.25f;
cDesc.slopeLimit = 0.0f;
cDesc.contactOffset = 0.1f;
cDesc.stepOffset = 0.02f;
cDesc.callback = nullptr;
cDesc.behaviorCallback = nullptr;
Vec3 position = m_universe.getPosition(e);
cDesc.position.set(position.x, position.y - cDesc.height * 0.5f, position.z);
c.m_controller =
m_controller_manager->createController(*m_system->getPhysics(), m_scene, cDesc);
c.m_entity = e;
m_universe.addComponent(e, CONTROLLER_TYPE, this, i);
serializer.read(c.m_layer);
}
else
{
c.m_layer = 0;
}
physx::PxCapsuleControllerDesc cDesc;
cDesc.material = m_default_material;
cDesc.height = 1.8f;
cDesc.radius = 0.25f;
cDesc.slopeLimit = 0.0f;
cDesc.contactOffset = 0.1f;
cDesc.stepOffset = 0.02f;
cDesc.callback = nullptr;
cDesc.behaviorCallback = nullptr;
Vec3 position = m_universe.getPosition(e);
cDesc.position.set(position.x, position.y - cDesc.height * 0.5f, position.z);
c.m_controller = m_controller_manager->createController(*m_system->getPhysics(), m_scene, cDesc);
c.m_entity = e;
m_universe.addComponent(e, CONTROLLER_TYPE, this, {i});
}
}
@ -1539,9 +1512,9 @@ struct PhysicsSceneImpl : public PhysicsScene
if (m_terrains[i]->m_heightmap == nullptr ||
!equalStrings(tmp, m_terrains[i]->m_heightmap->getPath().c_str()))
{
setHeightmap(i, Path(tmp));
setHeightmap({i}, Path(tmp));
}
m_universe.addComponent(m_terrains[i]->m_entity, HEIGHTFIELD_TYPE, this, i);
m_universe.addComponent(m_terrains[i]->m_entity, HEIGHTFIELD_TYPE, this, {i});
}
}
}
@ -1570,9 +1543,9 @@ struct PhysicsSceneImpl : public PhysicsScene
int getVersion() const override { return (int)PhysicsSceneVersion::LATEST; }
float getActorSpeed(ComponentIndex cmp) override
float getActorSpeed(ComponentHandle cmp) override
{
auto* actor = m_actors[cmp];
auto* actor = m_actors[cmp.index];
if (!actor->isDynamic())
{
g_log_warning.log("Physics") << "Trying to get speed of static object";
@ -1585,9 +1558,9 @@ struct PhysicsSceneImpl : public PhysicsScene
}
void putToSleep(ComponentIndex cmp) override
void putToSleep(ComponentHandle cmp) override
{
auto* actor = m_actors[cmp];
auto* actor = m_actors[cmp.index];
if (!actor->isDynamic())
{
g_log_warning.log("Physics") << "Trying to put static object to sleep";
@ -1600,7 +1573,7 @@ struct PhysicsSceneImpl : public PhysicsScene
}
void applyForceToActor(ComponentIndex cmp, const Vec3& force) override
void applyForceToActor(ComponentHandle cmp, const Vec3& force) override
{
auto& i = m_queued_forces.emplace();
i.cmp = cmp;
@ -1631,7 +1604,7 @@ struct PhysicsSceneImpl : public PhysicsScene
struct QueuedForce
{
ComponentIndex cmp;
ComponentHandle cmp;
Vec3 force;
};

View file

@ -50,34 +50,34 @@ public:
virtual bool raycastEx(const Vec3& origin, const Vec3& dir, float distance, RaycastHit& result) = 0;
virtual PhysicsSystem& getSystem() const = 0;
virtual ComponentIndex getActorComponent(Entity entity) = 0;
virtual void setActorLayer(ComponentIndex cmp, int layer) = 0;
virtual int getActorLayer(ComponentIndex cmp) = 0;
virtual bool isDynamic(ComponentIndex cmp) = 0;
virtual void setIsDynamic(ComponentIndex cmp, bool) = 0;
virtual Vec3 getHalfExtents(ComponentIndex cmp) = 0;
virtual void setHalfExtents(ComponentIndex cmp, const Vec3& size) = 0;
virtual Path getShapeSource(ComponentIndex cmp) = 0;
virtual void setShapeSource(ComponentIndex cmp, const Path& str) = 0;
virtual Path getHeightmap(ComponentIndex cmp) = 0;
virtual void setHeightmap(ComponentIndex cmp, const Path& path) = 0;
virtual float getHeightmapXZScale(ComponentIndex cmp) = 0;
virtual void setHeightmapXZScale(ComponentIndex cmp, float scale) = 0;
virtual float getHeightmapYScale(ComponentIndex cmp) = 0;
virtual void setHeightmapYScale(ComponentIndex cmp, float scale) = 0;
virtual int getHeightfieldLayer(ComponentIndex cmp) = 0;
virtual void setHeightfieldLayer(ComponentIndex cmp, int layer) = 0;
virtual ComponentHandle getActorComponent(Entity entity) = 0;
virtual void setActorLayer(ComponentHandle cmp, int layer) = 0;
virtual int getActorLayer(ComponentHandle cmp) = 0;
virtual bool isDynamic(ComponentHandle cmp) = 0;
virtual void setIsDynamic(ComponentHandle cmp, bool) = 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 getHeightmap(ComponentHandle cmp) = 0;
virtual void setHeightmap(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 applyForceToActor(ComponentIndex cmp, const Vec3& force) = 0;
virtual float getActorSpeed(ComponentIndex cmp) = 0;
virtual void putToSleep(ComponentIndex cmp) = 0;
virtual void applyForceToActor(ComponentHandle cmp, const Vec3& force) = 0;
virtual float getActorSpeed(ComponentHandle cmp) = 0;
virtual void putToSleep(ComponentHandle cmp) = 0;
virtual void moveController(ComponentIndex cmp, const Vec3& v) = 0;
virtual ComponentIndex getController(Entity entity) = 0;
virtual int getControllerLayer(ComponentIndex cmp) = 0;
virtual void setControllerLayer(ComponentIndex cmp, int layer) = 0;
virtual float getControllerRadius(ComponentIndex cmp) = 0;
virtual float getControllerHeight(ComponentIndex cmp) = 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 float getControllerHeight(ComponentHandle cmp) = 0;
virtual const char* getCollisionLayerName(int index) = 0;
virtual void setCollisionLayerName(int index, const char* name) = 0;

View file

@ -32,10 +32,10 @@ namespace Lumix
class PhysicsLayerPropertyDescriptor : public IEnumPropertyDescriptor
{
public:
typedef int (PhysicsScene::*Getter)(ComponentIndex);
typedef void (PhysicsScene::*Setter)(ComponentIndex, int);
typedef int (PhysicsScene::*ArrayGetter)(ComponentIndex, int);
typedef void (PhysicsScene::*ArraySetter)(ComponentIndex, int, int);
typedef int (PhysicsScene::*Getter)(ComponentHandle);
typedef void (PhysicsScene::*Setter)(ComponentHandle, int);
typedef int (PhysicsScene::*ArrayGetter)(ComponentHandle, int);
typedef void (PhysicsScene::*ArraySetter)(ComponentHandle, int, int);
public:
PhysicsLayerPropertyDescriptor(const char* name,
@ -70,11 +70,11 @@ namespace Lumix
stream.read(&value, sizeof(value));
if (index == -1)
{
(static_cast<PhysicsScene*>(cmp.scene)->*m_single.setter)(cmp.index, value);
(static_cast<PhysicsScene*>(cmp.scene)->*m_single.setter)(cmp.handle, value);
}
else
{
(static_cast<PhysicsScene*>(cmp.scene)->*m_array.setter)(cmp.index, index, value);
(static_cast<PhysicsScene*>(cmp.scene)->*m_array.setter)(cmp.handle, index, value);
}
};
@ -84,30 +84,30 @@ namespace Lumix
int value;
if (index == -1)
{
value = (static_cast<PhysicsScene*>(cmp.scene)->*m_single.getter)(cmp.index);
value = (static_cast<PhysicsScene*>(cmp.scene)->*m_single.getter)(cmp.handle);
}
else
{
value = (static_cast<PhysicsScene*>(cmp.scene)->*m_array.getter)(cmp.index, index);
value = (static_cast<PhysicsScene*>(cmp.scene)->*m_array.getter)(cmp.handle, index);
}
stream.write(&value, sizeof(value));
};
int getEnumCount(IScene* scene, ComponentIndex) override
int getEnumCount(IScene* scene, ComponentHandle) override
{
return static_cast<PhysicsScene*>(scene)->getCollisionsLayersCount();
}
const char* getEnumItemName(IScene* scene, ComponentIndex, int index) override
const char* getEnumItemName(IScene* scene, ComponentHandle, int index) override
{
auto* phy_scene = static_cast<PhysicsScene*>(scene);
return phy_scene->getCollisionLayerName(index);
}
void getEnumItemName(IScene* scene, ComponentIndex, int index, char* buf, int max_size) override {}
void getEnumItemName(IScene* scene, ComponentHandle, int index, char* buf, int max_size) override {}
private:
union

View file

@ -13,8 +13,8 @@
namespace Lumix
{
typedef Array<int64> LayerMasks;
typedef Array<ComponentIndex> RenderabletoSphereMap;
typedef Array<int> SphereToRenderableMap;
typedef Array<int> RenderabletoSphereMap;
typedef Array<ComponentHandle> SphereToRenderableMap;
static const int MIN_ENTITIES_PER_THREAD = 50;
@ -23,7 +23,7 @@ static void doCulling(int start_index,
const Sphere* LUMIX_RESTRICT end,
const Frustum* LUMIX_RESTRICT frustum,
const int64* LUMIX_RESTRICT layer_masks,
const int* LUMIX_RESTRICT sphere_to_renderable_map,
const ComponentHandle* LUMIX_RESTRICT sphere_to_renderable_map,
int64 layer_mask,
CullingSystem::Subresults& results)
{
@ -236,27 +236,27 @@ public:
}
void setLayerMask(ComponentIndex renderable, int64 layer) override
void setLayerMask(ComponentHandle renderable, int64 layer) override
{
m_layer_masks[m_renderable_to_sphere_map[renderable]] = layer;
m_layer_masks[m_renderable_to_sphere_map[renderable.index]] = layer;
}
int64 getLayerMask(ComponentIndex renderable) override
int64 getLayerMask(ComponentHandle renderable) override
{
return m_layer_masks[m_renderable_to_sphere_map[renderable]];
return m_layer_masks[m_renderable_to_sphere_map[renderable.index]];
}
bool isAdded(ComponentIndex renderable) override
bool isAdded(ComponentHandle renderable) override
{
return renderable < m_renderable_to_sphere_map.size() && m_renderable_to_sphere_map[renderable] != -1;
return renderable.index < m_renderable_to_sphere_map.size() && m_renderable_to_sphere_map[renderable.index] != -1;
}
void addStatic(ComponentIndex renderable, const Sphere& sphere) override
void addStatic(ComponentHandle renderable, const Sphere& sphere) override
{
if (renderable < m_renderable_to_sphere_map.size() && m_renderable_to_sphere_map[renderable] != -1)
if (renderable.index < m_renderable_to_sphere_map.size() && m_renderable_to_sphere_map[renderable.index] != -1)
{
ASSERT(false);
return;
@ -264,22 +264,22 @@ public:
m_spheres.push(sphere);
m_sphere_to_renderable_map.push(renderable);
while(renderable >= m_renderable_to_sphere_map.size())
while(renderable.index >= m_renderable_to_sphere_map.size())
{
m_renderable_to_sphere_map.push(-1);
}
m_renderable_to_sphere_map[renderable] = m_spheres.size() - 1;
m_renderable_to_sphere_map[renderable.index] = m_spheres.size() - 1;
m_layer_masks.push(1);
}
void removeStatic(ComponentIndex renderable) override
void removeStatic(ComponentHandle renderable) override
{
int index = m_renderable_to_sphere_map[renderable];
int index = m_renderable_to_sphere_map[renderable.index];
if (index < 0) return;
ASSERT(index < m_spheres.size());
m_renderable_to_sphere_map[m_sphere_to_renderable_map.back()] = index;
m_renderable_to_sphere_map[m_sphere_to_renderable_map.back().index] = index;
m_spheres[index] = m_spheres.back();
m_sphere_to_renderable_map[index] = m_sphere_to_renderable_map.back();
m_layer_masks[index] = m_layer_masks.back();
@ -287,41 +287,41 @@ public:
m_spheres.pop();
m_sphere_to_renderable_map.pop();
m_layer_masks.pop();
m_renderable_to_sphere_map[renderable] = -1;
m_renderable_to_sphere_map[renderable.index] = -1;
}
void updateBoundingRadius(float radius, ComponentIndex renderable) override
void updateBoundingRadius(float radius, ComponentHandle renderable) override
{
m_spheres[m_renderable_to_sphere_map[renderable]].m_radius = radius;
m_spheres[m_renderable_to_sphere_map[renderable.index]].m_radius = radius;
}
void updateBoundingPosition(const Vec3& position, ComponentIndex renderable) override
void updateBoundingPosition(const Vec3& position, ComponentHandle renderable) override
{
m_spheres[m_renderable_to_sphere_map[renderable]].m_position = position;
m_spheres[m_renderable_to_sphere_map[renderable.index]].m_position = position;
}
void insert(const InputSpheres& spheres, const Array<ComponentIndex>& renderables) override
void insert(const InputSpheres& spheres, const Array<ComponentHandle>& renderables) override
{
for (int i = 0; i < spheres.size(); i++)
{
m_spheres.push(spheres[i]);
while(m_renderable_to_sphere_map.size() <= renderables[i])
while(m_renderable_to_sphere_map.size() <= renderables[i].index)
{
m_renderable_to_sphere_map.push(-1);
}
m_renderable_to_sphere_map[renderables[i]] = m_spheres.size() - 1;
m_renderable_to_sphere_map[renderables[i].index] = m_spheres.size() - 1;
m_sphere_to_renderable_map.push(renderables[i]);
m_layer_masks.push(1);
}
}
const Sphere& getSphere(ComponentIndex renderable) override
const Sphere& getSphere(ComponentHandle renderable) override
{
return m_spheres[m_renderable_to_sphere_map[renderable]];
return m_spheres[m_renderable_to_sphere_map[renderable.index]];
}

View file

@ -22,7 +22,7 @@ namespace Lumix
{
public:
typedef Array<Sphere> InputSpheres;
typedef Array<int> Subresults;
typedef Array<ComponentHandle> Subresults;
typedef Array<Subresults> Results;
CullingSystem() { }
@ -37,17 +37,17 @@ namespace Lumix
virtual void cullToFrustum(const Frustum& frustum, int64 layer_mask) = 0;
virtual void cullToFrustumAsync(const Frustum& frustum, int64 layer_mask) = 0;
virtual bool isAdded(ComponentIndex renderable) = 0;
virtual void addStatic(ComponentIndex renderable, const Sphere& sphere) = 0;
virtual void removeStatic(ComponentIndex renderable) = 0;
virtual bool isAdded(ComponentHandle renderable) = 0;
virtual void addStatic(ComponentHandle renderable, const Sphere& sphere) = 0;
virtual void removeStatic(ComponentHandle renderable) = 0;
virtual void setLayerMask(ComponentIndex renderable, int64 layer) = 0;
virtual int64 getLayerMask(ComponentIndex renderable) = 0;
virtual void setLayerMask(ComponentHandle renderable, int64 layer) = 0;
virtual int64 getLayerMask(ComponentHandle renderable) = 0;
virtual void updateBoundingRadius(float radius, int index) = 0;
virtual void updateBoundingPosition(const Vec3& position, int index) = 0;
virtual void updateBoundingRadius(float radius, ComponentHandle renderable) = 0;
virtual void updateBoundingPosition(const Vec3& position, ComponentHandle renderable) = 0;
virtual void insert(const InputSpheres& spheres, const Array<ComponentIndex>& renderables) = 0;
virtual const Sphere& getSphere(ComponentIndex renderable) = 0;
virtual void insert(const InputSpheres& spheres, const Array<ComponentHandle>& renderables) = 0;
virtual const Sphere& getSphere(ComponentHandle renderable) = 0;
};
} // ~namespace Lux

View file

@ -540,9 +540,9 @@ struct ModelPlugin : public AssetBrowser::IPlugin
StudioApp& m_app;
Universe* m_universe;
Pipeline* m_pipeline;
ComponentIndex m_mesh;
ComponentHandle m_mesh;
Entity m_camera_entity;
ComponentIndex m_camera_cmp;
ComponentHandle m_camera_cmp;
bool m_is_mouse_captured;
};
@ -768,7 +768,7 @@ struct EnvironmentProbePlugin : public PropertyGrid::IPlugin
if (!PlatformInterface::makePath(path)) g_log_error.log("Editor") << "Failed to create " << path;
path << "/probes/";
if (!PlatformInterface::makePath(path)) g_log_error.log("Editor") << "Failed to create " << path;
path << cmp.index << ".dds";
path << cmp.handle.index << ".dds";
auto& allocator = m_app.getWorldEditor()->getAllocator();
if (!file.open(path, Lumix::FS::Mode::CREATE_AND_WRITE, allocator))
{
@ -836,11 +836,11 @@ struct EnvironmentProbePlugin : public PropertyGrid::IPlugin
Vec3 probe_position = universe->getPosition(cmp.entity);
auto* scene = static_cast<RenderScene*>(universe->getScene(crc32("renderer")));
ComponentIndex original_camera = scene->getCameraInSlot("main");
ComponentHandle original_camera = scene->getCameraInSlot("main");
if(original_camera != INVALID_COMPONENT) scene->setCameraSlot(original_camera, "");
Entity camera_entity = universe->createEntity({ 0, 0, 0 }, { 0, 0, 0, 1 });
ComponentIndex camera_cmp = scene->createComponent(CAMERA_TYPE, camera_entity);
ComponentHandle camera_cmp = scene->createComponent(CAMERA_TYPE, camera_entity);
scene->setCameraSlot(camera_cmp, "main");
scene->setCameraFOV(camera_cmp, 90);
@ -901,7 +901,7 @@ struct EnvironmentProbePlugin : public PropertyGrid::IPlugin
universe->destroyEntity(camera_entity);
if (original_camera != INVALID_COMPONENT) scene->setCameraSlot(original_camera, "main");
scene->reloadEnvironmentProbe(cmp.index);
scene->reloadEnvironmentProbe(cmp.handle);
}
@ -910,7 +910,7 @@ struct EnvironmentProbePlugin : public PropertyGrid::IPlugin
if (cmp.type != ENVIRONMENT_PROBE_TYPE) return;
auto* scene = static_cast<RenderScene*>(cmp.scene);
auto* texture = scene->getEnvironmentProbeTexture(cmp.index);
auto* texture = scene->getEnvironmentProbeTexture(cmp.handle);
ImGui::LabelText("Path", "%s", texture->getPath().c_str());
if (ImGui::Button("View")) m_app.getAssetBrowser()->selectResource(texture->getPath(), true);
ImGui::SameLine();
@ -941,14 +941,14 @@ struct EmitterPlugin : 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.index);
if (ImGui::Button("Reset")) scene->resetParticleEmitter(cmp.handle);
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.index, time_delta * m_particle_emitter_timescale);
scene->getParticleEmitter(cmp.index)->drawGizmo(*m_app.getWorldEditor(), *scene);
scene->updateEmitter(cmp.handle, time_delta * m_particle_emitter_timescale);
scene->getParticleEmitter(cmp.handle)->drawGizmo(*m_app.getWorldEditor(), *scene);
}
}
@ -1027,7 +1027,7 @@ struct SceneViewPlugin : public StudioApp::IPlugin
}
WorldEditor::RayHit castRay(const Vec3& origin, const Vec3& dir, ComponentIndex ignored) override
WorldEditor::RayHit castRay(const Vec3& origin, const Vec3& dir, ComponentHandle ignored) override
{
auto hit = m_render_scene->castRay(origin, dir, ignored);
@ -1035,7 +1035,7 @@ struct SceneViewPlugin : public StudioApp::IPlugin
}
void getRay(ComponentIndex camera_index, float x, float y, Vec3& origin, Vec3& dir) override
void getRay(ComponentHandle camera_index, float x, float y, Vec3& origin, Vec3& dir) override
{
m_render_scene->getRay(camera_index, x, y, origin, dir);
}
@ -1083,43 +1083,43 @@ struct SceneViewPlugin : public StudioApp::IPlugin
}
void setCameraSlot(ComponentIndex cmp, const char* slot) override
void setCameraSlot(ComponentHandle cmp, const char* slot) override
{
m_render_scene->setCameraSlot(cmp, slot);
}
ComponentIndex getCameraInSlot(const char* slot) override
ComponentHandle getCameraInSlot(const char* slot) override
{
return m_render_scene->getCameraInSlot(slot);
}
Entity getCameraEntity(ComponentIndex cmp) override
Entity getCameraEntity(ComponentHandle cmp) override
{
return m_render_scene->getCameraEntity(cmp);
}
Vec2 getCameraScreenSize(ComponentIndex cmp) override
Vec2 getCameraScreenSize(ComponentHandle cmp) override
{
return m_render_scene->getCameraScreenSize(cmp);
}
float getCameraOrthoSize(ComponentIndex cmp) override
float getCameraOrthoSize(ComponentHandle cmp) override
{
return m_render_scene->getCameraOrthoSize(cmp);
}
bool isCameraOrtho(ComponentIndex cmp) override
bool isCameraOrtho(ComponentHandle cmp) override
{
return m_render_scene->isCameraOrtho(cmp);
}
float getCameraFOV(ComponentIndex cmp) override
float getCameraFOV(ComponentHandle cmp) override
{
return m_render_scene->getCameraFOV(cmp);
}
@ -1190,7 +1190,7 @@ struct SceneViewPlugin : public StudioApp::IPlugin
void showEntity(Entity entity) override
{
ComponentIndex cmp = m_render_scene->getRenderableComponent(entity);
ComponentHandle cmp = m_render_scene->getRenderableComponent(entity);
if (cmp == INVALID_COMPONENT) return;
m_render_scene->showRenderable(cmp);
}
@ -1198,13 +1198,13 @@ struct SceneViewPlugin : public StudioApp::IPlugin
void hideEntity(Entity entity) override
{
ComponentIndex cmp = m_render_scene->getRenderableComponent(entity);
ComponentHandle cmp = m_render_scene->getRenderableComponent(entity);
if (cmp == INVALID_COMPONENT) return;
m_render_scene->hideRenderable(cmp);
}
Path getRenderablePath(ComponentIndex cmp) override
Path getRenderablePath(ComponentHandle cmp) override
{
return m_render_scene->getRenderablePath(cmp);
}
@ -1555,7 +1555,7 @@ struct WorldEditorPlugin : public WorldEditor::Plugin
RenderScene* scene = static_cast<RenderScene*>(light.scene);
Universe& universe = scene->getUniverse();
float range = scene->getLightRange(light.index);
float range = scene->getLightRange(light.handle);
Vec3 pos = universe.getPosition(light.entity);
scene->addDebugSphere(pos, range, 0xff0000ff, 0);
@ -1582,7 +1582,7 @@ struct WorldEditorPlugin : public WorldEditor::Plugin
{
RenderScene* scene = static_cast<RenderScene*>(renderable.scene);
Universe& universe = scene->getUniverse();
Model* model = scene->getRenderableModel(renderable.index);
Model* model = scene->getRenderableModel(renderable.handle);
Vec3 points[8];
if (!model) return;
@ -1646,19 +1646,19 @@ struct WorldEditorPlugin : public WorldEditor::Plugin
Universe& universe = scene->getUniverse();
Vec3 pos = universe.getPosition(cmp.entity);
bool is_ortho = scene->isCameraOrtho(cmp.index);
float near_distance = scene->getCameraNearPlane(cmp.index);
float far_distance = scene->getCameraFarPlane(cmp.index);
bool is_ortho = scene->isCameraOrtho(cmp.handle);
float near_distance = scene->getCameraNearPlane(cmp.handle);
float far_distance = scene->getCameraFarPlane(cmp.handle);
Vec3 dir = universe.getRotation(cmp.entity) * Vec3(0, 0, -1);
Vec3 right = universe.getRotation(cmp.entity) * Vec3(1, 0, 0);
Vec3 up = universe.getRotation(cmp.entity) * Vec3(0, 1, 0);
float w = scene->getCameraScreenWidth(cmp.index);
float h = scene->getCameraScreenHeight(cmp.index);
float w = scene->getCameraScreenWidth(cmp.handle);
float h = scene->getCameraScreenHeight(cmp.handle);
float ratio = h < 1.0f ? 1 : w / h;
if (is_ortho)
{
float ortho_size = scene->getCameraOrthoSize(cmp.index);
float ortho_size = scene->getCameraOrthoSize(cmp.handle);
Vec3 center = pos;
center += (far_distance - near_distance) * dir * 0.5f;
scene->addDebugCube(center,
@ -1670,7 +1670,7 @@ struct WorldEditorPlugin : public WorldEditor::Plugin
}
else
{
float fov = scene->getCameraFOV(cmp.index);
float fov = scene->getCameraFOV(cmp.handle);
scene->addDebugFrustum(pos, dir, up, fov, ratio, near_distance, far_distance, 0xffff0000, 0);
}
}

View file

@ -82,19 +82,19 @@ struct InsertMeshCommand : public Lumix::IEditorCommand
m_entity = universe->createEntity({ 0, 0, 0 }, { 0, 0, 0, 1 });
universe->setPosition(m_entity, m_position);
const auto& scenes = universe->getScenes();
Lumix::ComponentIndex cmp = -1;
Lumix::ComponentHandle cmp = Lumix::INVALID_COMPONENT;
Lumix::IScene* scene = nullptr;
for (int i = 0; i < scenes.size(); ++i)
{
cmp = scenes[i]->createComponent(RENDERABLE_TYPE, m_entity);
if (cmp >= 0)
if (isValid(cmp))
{
scene = scenes[i];
break;
}
}
if (cmp >= 0) static_cast<Lumix::RenderScene*>(scene)->setRenderablePath(cmp, m_mesh_path);
if (isValid(cmp)) static_cast<Lumix::RenderScene*>(scene)->setRenderablePath(cmp, m_mesh_path);
return true;
}
@ -280,13 +280,13 @@ Lumix::RayCastModelHit SceneView::castRay(float x, float y)
ASSERT(scene);
Lumix::ComponentUID camera_cmp = m_editor->getEditCamera();
Lumix::Vec2 screen_size = scene->getCameraScreenSize(camera_cmp.index);
Lumix::Vec2 screen_size = scene->getCameraScreenSize(camera_cmp.handle);
screen_size.x *= x;
screen_size.y *= y;
Lumix::Vec3 origin;
Lumix::Vec3 dir;
scene->getRay(camera_cmp.index, (float)screen_size.x, (float)screen_size.y, origin, dir);
scene->getRay(camera_cmp.handle, (float)screen_size.x, (float)screen_size.y, origin, dir);
return scene->castRay(origin, dir, Lumix::INVALID_COMPONENT);
}

View file

@ -89,12 +89,10 @@ struct PaintTerrainCommand : public Lumix::IEditorCommand
}
m_width = m_height = m_x = m_y = -1;
Lumix::Matrix entity_mtx =
editor.getUniverse()->getMatrix(terrain.entity);
Lumix::Matrix entity_mtx = editor.getUniverse()->getMatrix(terrain.entity);
entity_mtx.fastInverse();
Lumix::Vec3 local_pos = entity_mtx.multiplyPosition(hit_pos);
float xz_scale = static_cast<Lumix::RenderScene*>(terrain.scene)
->getTerrainXZScale(terrain.index);
float xz_scale = static_cast<Lumix::RenderScene*>(terrain.scene)->getTerrainXZScale(terrain.handle);
local_pos = local_pos / xz_scale;
local_pos.y = -1;
@ -230,13 +228,11 @@ private:
private:
Lumix::Material* getMaterial()
{
auto* material = static_cast<Lumix::RenderScene*>(m_terrain.scene)
->getTerrainMaterial(m_terrain.index);
return static_cast<Lumix::Material*>(
m_world_editor.getEngine()
.getResourceManager()
.get(MATERIAL_HASH)
->get(Lumix::Path(material->getPath().c_str())));
auto* material = static_cast<Lumix::RenderScene*>(m_terrain.scene)->getTerrainMaterial(m_terrain.handle);
return static_cast<Lumix::Material*>(m_world_editor.getEngine()
.getResourceManager()
.get(MATERIAL_HASH)
->get(Lumix::Path(material->getPath().c_str())));
}
@ -525,7 +521,7 @@ private:
}
}
texture->onDataUpdated(m_x, m_y, m_width, m_height);
static_cast<Lumix::RenderScene*>(m_terrain.scene)->forceGrassUpdate(m_terrain.index);
static_cast<Lumix::RenderScene*>(m_terrain.scene)->forceGrassUpdate(m_terrain.handle);
}
@ -636,7 +632,7 @@ TerrainEditor::~TerrainEditor()
void TerrainEditor::onUniverseDestroyed()
{
m_component.scene = nullptr;
m_component.index = Lumix::INVALID_COMPONENT;
m_component.handle = Lumix::INVALID_COMPONENT;
}
@ -713,7 +709,7 @@ TerrainEditor::TerrainEditor(Lumix::WorldEditor& editor, StudioApp& app)
void TerrainEditor::nextTerrainTexture()
{
auto* scene = static_cast<Lumix::RenderScene*>(m_component.scene);
auto* material = scene->getTerrainMaterial(m_component.index);
auto* material = scene->getTerrainMaterial(m_component.handle);
Lumix::Texture* tex = material->getTextureByUniform(TEX_COLOR_UNIFORM);
if (tex)
{
@ -773,11 +769,11 @@ void TerrainEditor::drawCursor(Lumix::RenderScene& scene,
float angle = i * angle_step;
float next_angle = i * angle_step + angle_step;
Lumix::Vec3 local_from = local_center + Lumix::Vec3(cos(angle), 0, sin(angle)) * brush_size;
local_from.y = scene.getTerrainHeightAt(terrain.index, local_from.x, local_from.z);
local_from.y = scene.getTerrainHeightAt(terrain.handle, local_from.x, local_from.z);
local_from.y += 0.25f;
Lumix::Vec3 local_to =
local_center + Lumix::Vec3(cos(next_angle), 0, sin(next_angle)) * brush_size;
local_to.y = scene.getTerrainHeightAt(terrain.index, local_to.x, local_to.z);
local_to.y = scene.getTerrainHeightAt(terrain.handle, local_to.x, local_to.z);
local_to.y += 0.25f;
Lumix::Vec3 from = terrain_matrix.multiplyPosition(local_from);
@ -853,7 +849,7 @@ bool TerrainEditor::onEntityMouseDown(const Lumix::WorldEditor::RayHit& hit, int
{
if (m_world_editor.getSelectedEntities().size() != 1) return false;
auto terrain = m_world_editor.getComponent(m_world_editor.getSelectedEntities()[0], TERRAIN_TYPE);
if (terrain.index == Lumix::INVALID_COMPONENT) return false;
if (terrain.handle == Lumix::INVALID_COMPONENT) return false;
if (!m_is_enabled) return false;
if (m_type == NOT_SET || !m_component.isValid()) return false;
@ -1060,7 +1056,7 @@ void TerrainEditor::paintEntities(const Lumix::Vec3& hit_pos)
struct Tpl
{
Lumix::ComponentIndex cmp;
Lumix::ComponentHandle cmp;
int template_idx;
};
@ -1073,7 +1069,7 @@ void TerrainEditor::paintEntities(const Lumix::Vec3& hit_pos)
if(!isValid(tpl)) continue;
Lumix::ComponentUID renderable = m_world_editor.getComponent(tpl, RENDERABLE_TYPE);
if(!renderable.isValid()) continue;
tpls.push({renderable.index, idx});
tpls.push({renderable.handle, idx});
}
Lumix::Frustum frustum;
@ -1086,7 +1082,7 @@ void TerrainEditor::paintEntities(const Lumix::Vec3& hit_pos)
m_terrain_brush_size);
auto& meshes = scene->getRenderableInfos(frustum, frustum.position);
Lumix::Vec2 size = scene->getTerrainSize(m_component.index);
Lumix::Vec2 size = scene->getTerrainSize(m_component.handle);
float scale = 1.0f - Lumix::Math::maximum(0.01f, m_terrain_brush_strength);
for (int i = 0; i <= m_terrain_brush_size * m_terrain_brush_size / 1000.0f; ++i)
{
@ -1101,7 +1097,7 @@ void TerrainEditor::paintEntities(const Lumix::Vec3& hit_pos)
Lumix::Vec3 terrain_pos = inv_terrain_matrix.multiplyPosition(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.index, terrain_pos.x, terrain_pos.z) + y;
pos.y = scene->getTerrainHeightAt(m_component.handle, terrain_pos.x, terrain_pos.z) + y;
pos.y += terrain_matrix.getTranslation().y;
if(!isOBBCollision(*scene, meshes, pos, model, scale))
{
@ -1109,7 +1105,7 @@ void TerrainEditor::paintEntities(const Lumix::Vec3& hit_pos)
if(m_is_align_with_normal)
{
Lumix::RenderScene* scene = static_cast<Lumix::RenderScene*>(m_component.scene);
Lumix::Vec3 normal = scene->getTerrainNormalAt(m_component.index, pos.x, pos.z);
Lumix::Vec3 normal = scene->getTerrainNormalAt(m_component.handle, pos.x, pos.z);
Lumix::Vec3 dir = Lumix::crossProduct(normal, Lumix::Vec3(1, 0, 0)).normalized();
Lumix::Matrix mtx = Lumix::Matrix::IDENTITY;
mtx.setXVector(Lumix::crossProduct(normal, dir));
@ -1160,8 +1156,8 @@ void TerrainEditor::onMouseMove(int x, int y, int, int)
Lumix::ComponentUID camera_cmp = m_world_editor.getEditCamera();
Lumix::RenderScene* scene = static_cast<Lumix::RenderScene*>(camera_cmp.scene);
Lumix::Vec3 origin, dir;
scene->getRay(camera_cmp.index, (float)x, (float)y, origin, dir);
Lumix::RayCastModelHit hit = scene->castRayTerrain(m_component.index, origin, dir);
scene->getRay(camera_cmp.handle, (float)x, (float)y, origin, dir);
Lumix::RayCastModelHit hit = scene->castRayTerrain(m_component.handle, origin, dir);
if (hit.m_is_hit)
{
Lumix::ComponentUID terrain = m_world_editor.getComponent(hit.m_entity, TERRAIN_TYPE);
@ -1192,7 +1188,7 @@ void TerrainEditor::onMouseUp(int, int, Lumix::MouseButton::Value)
Lumix::Material* TerrainEditor::getMaterial()
{
auto* scene = static_cast<Lumix::RenderScene*>(m_component.scene);
return scene->getTerrainMaterial(m_component.index);
return scene->getTerrainMaterial(m_component.handle);
}
@ -1449,8 +1445,8 @@ void TerrainEditor::onGUI()
Lumix::ComponentUID camera_cmp = m_world_editor.getEditCamera();
Lumix::RenderScene* scene = static_cast<Lumix::RenderScene*>(camera_cmp.scene);
Lumix::Vec3 origin, dir;
scene->getRay(camera_cmp.index, (float)mouse_x, (float)mouse_y, origin, dir);
Lumix::RayCastModelHit hit = scene->castRayTerrain(terrain.index, origin, dir);
scene->getRay(camera_cmp.handle, (float)mouse_x, (float)mouse_y, origin, dir);
Lumix::RayCastModelHit hit = scene->castRayTerrain(terrain.handle, origin, dir);
if(hit.m_is_hit)
{

View file

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

View file

@ -701,8 +701,8 @@ struct PipelineImpl : public Pipeline
void applyCamera(const char* slot)
{
ComponentIndex cmp = m_scene->getCameraInSlot(slot);
if (cmp < 0) return;
ComponentHandle cmp = m_scene->getCameraInSlot(slot);
if (!isValid(cmp)) return;
m_scene->setCameraScreenSize(cmp, m_width, m_height);
m_applied_camera = cmp;
@ -941,11 +941,11 @@ struct PipelineImpl : public Pipeline
{
auto scr_scene = static_cast<LuaScriptScene*>(m_scene->getUniverse().getScene(crc32("lua_script")));
if (!scr_scene) return false;
ComponentIndex camera = m_scene->getCameraInSlot(camera_slot);
ComponentHandle camera = m_scene->getCameraInSlot(camera_slot);
if (camera == INVALID_COMPONENT) return false;
Entity camera_entity = m_scene->getCameraEntity(camera);
ComponentIndex scr_cmp = scr_scene->getComponent(camera_entity);
ComponentHandle scr_cmp = scr_scene->getComponent(camera_entity);
if (scr_cmp == INVALID_COMPONENT) return false;
bool ret = false;
@ -1065,7 +1065,7 @@ struct PipelineImpl : public Pipeline
}
void renderSpotLightShadowmap(ComponentIndex light)
void renderSpotLightShadowmap(ComponentHandle light)
{
newView("point_light");
@ -1102,7 +1102,7 @@ struct PipelineImpl : public Pipeline
}
void renderOmniLightShadowmap(ComponentIndex light)
void renderOmniLightShadowmap(ComponentHandle light)
{
Entity light_entity = m_scene->getPointLightEntity(light);
Vec3 light_pos = m_scene->getUniverse().getPosition(light_entity);
@ -1186,15 +1186,15 @@ struct PipelineImpl : public Pipeline
}
void renderLocalLightShadowmaps(ComponentIndex camera, FrameBuffer** fbs, int framebuffers_count)
void renderLocalLightShadowmaps(ComponentHandle camera, FrameBuffer** fbs, int framebuffers_count)
{
if (camera < 0) return;
if (!isValid(camera)) return;
Universe& universe = m_scene->getUniverse();
Entity camera_entity = m_scene->getCameraEntity(camera);
Vec3 camera_pos = universe.getPosition(camera_entity);
ComponentIndex lights[16];
ComponentHandle lights[16];
int light_count = m_scene->getClosestPointLights(camera_pos, lights, lengthOf(lights));
int fb_index = 0;
@ -1238,8 +1238,8 @@ struct PipelineImpl : public Pipeline
void renderShadowmap(int split_index)
{
Universe& universe = m_scene->getUniverse();
ComponentIndex light_cmp = m_scene->getActiveGlobalLight();
if (light_cmp < 0 || m_applied_camera < 0) return;
ComponentHandle light_cmp = m_scene->getActiveGlobalLight();
if (!isValid(light_cmp) || !isValid(m_applied_camera)) return;
float camera_height = m_scene->getCameraScreenHeight(m_applied_camera);
if (!camera_height) return;
@ -1485,9 +1485,9 @@ struct PipelineImpl : public Pipeline
}
void setPointLightUniforms(ComponentIndex light_cmp)
void setPointLightUniforms(ComponentHandle light_cmp)
{
if (light_cmp < 0) return;
if (!isValid(light_cmp)) return;
Universe& universe = m_scene->getUniverse();
Entity light_entity = m_scene->getPointLightEntity(light_cmp);
@ -1637,7 +1637,7 @@ struct PipelineImpl : public Pipeline
}
void renderPointLightInfluencedGeometry(ComponentIndex light)
void renderPointLightInfluencedGeometry(ComponentHandle light)
{
PROFILE_FUNCTION();
@ -1653,7 +1653,7 @@ struct PipelineImpl : public Pipeline
{
PROFILE_FUNCTION();
Array<ComponentIndex> lights(m_allocator);
Array<ComponentHandle> lights(m_allocator);
m_scene->getPointLights(frustum, lights);
for (int i = 0; i < lights.size(); ++i)
{
@ -1661,7 +1661,7 @@ struct PipelineImpl : public Pipeline
m_tmp_meshes.clear();
m_tmp_terrains.clear();
ComponentIndex light = lights[i];
ComponentHandle light = lights[i];
m_is_current_light_global = false;
setPointLightUniforms(light);
m_scene->getPointLightInfluencedGeometry(light, frustum, m_tmp_meshes);
@ -1788,7 +1788,7 @@ struct PipelineImpl : public Pipeline
executeCommandBuffer(material->getCommandBuffer(), material);
executeCommandBuffer(m_views[m_view_idx].command_buffer.buffer, material);
if (m_applied_camera >= 0)
if (isValid(m_applied_camera))
{
Matrix projection_matrix;
Universe& universe = m_scene->getUniverse();
@ -1829,7 +1829,7 @@ struct PipelineImpl : public Pipeline
{
PROFILE_FUNCTION();
if (m_applied_camera < 0) return;
if (!isValid(m_applied_camera)) return;
m_tmp_grasses.clear();
m_tmp_terrains.clear();
@ -2241,7 +2241,7 @@ struct PipelineImpl : public Pipeline
PROFILE_INT("mesh count", meshes.size());
for(auto& mesh : meshes)
{
Renderable& renderable = renderables[mesh.renderable];
Renderable& renderable = renderables[mesh.renderable.index];
if(renderable.pose && renderable.pose->count > 0)
{
renderSkinnedMesh(renderable, mesh);
@ -2266,7 +2266,7 @@ struct PipelineImpl : public Pipeline
mesh_count += submeshes.size();
for (auto& mesh : submeshes)
{
Renderable& renderable = renderables[mesh.renderable];
Renderable& renderable = renderables[mesh.renderable.index];
if (renderable.pose && renderable.pose->count > 0)
{
renderSkinnedMesh(renderable, mesh);
@ -2492,7 +2492,7 @@ struct PipelineImpl : public Pipeline
struct PointLightShadowmap
{
ComponentIndex m_light;
ComponentHandle m_light;
FrameBuffer* m_framebuffer;
Matrix m_matrices[4];
};
@ -2529,7 +2529,7 @@ struct PipelineImpl : public Pipeline
FrameBuffer* m_global_light_shadowmap;
InstanceData m_instances_data[128];
int m_instance_data_idx;
ComponentIndex m_applied_camera;
ComponentHandle m_applied_camera;
bgfx::VertexBufferHandle m_cube_vb;
bgfx::IndexBufferHandle m_cube_ib;
bool m_is_current_light_global;
@ -2552,7 +2552,7 @@ struct PipelineImpl : public Pipeline
Array<RenderableMesh> m_tmp_meshes;
Array<const TerrainInfo*> m_tmp_terrains;
Array<GrassInfo> m_tmp_grasses;
Array<ComponentIndex> m_tmp_local_lights;
Array<ComponentHandle> m_tmp_local_lights;
bgfx::UniformHandle m_bone_matrices_uniform;
bgfx::UniformHandle m_layer_uniform;
@ -2730,7 +2730,7 @@ int renderLocalLightsShadowmaps(lua_State* L)
}
RenderScene* scene = pipeline->m_scene;
ComponentIndex camera = scene->getCameraInSlot(camera_slot);
ComponentHandle camera = scene->getCameraInSlot(camera_slot);
pipeline->renderLocalLightShadowmaps(camera, fbs, len);
return 0;

File diff suppressed because it is too large Load diff

View file

@ -81,7 +81,7 @@ struct Renderable
struct RenderableMesh
{
ComponentIndex renderable;
ComponentHandle renderable;
Mesh* mesh;
};
@ -142,24 +142,24 @@ public:
static void destroyInstance(RenderScene* scene);
static void registerLuaAPI(lua_State* L);
virtual RayCastModelHit castRay(const Vec3& origin, const Vec3& dir, ComponentIndex ignore) = 0;
virtual RayCastModelHit castRay(const Vec3& origin, const Vec3& dir, ComponentHandle ignore) = 0;
virtual RayCastModelHit castRayTerrain(ComponentIndex terrain,
virtual RayCastModelHit castRayTerrain(ComponentHandle terrain,
const Vec3& origin,
const Vec3& dir) = 0;
virtual void getRay(ComponentIndex camera, float x, float y, Vec3& origin, Vec3& dir) = 0;
virtual void getRay(ComponentHandle camera, float x, float y, Vec3& origin, Vec3& dir) = 0;
virtual Frustum getCameraFrustum(ComponentIndex camera) const = 0;
virtual Frustum getCameraFrustum(ComponentHandle camera) const = 0;
virtual float getTime() const = 0;
virtual Engine& getEngine() const = 0;
virtual IAllocator& getAllocator() = 0;
virtual Pose* getPose(ComponentIndex cmp) = 0;
virtual ComponentIndex getActiveGlobalLight() = 0;
virtual void setActiveGlobalLight(ComponentIndex cmp) = 0;
virtual Vec4 getShadowmapCascades(ComponentIndex cmp) = 0;
virtual void setShadowmapCascades(ComponentIndex cmp, const Vec4& value) = 0;
virtual Pose* getPose(ComponentHandle cmp) = 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 void addDebugTriangle(const Vec3& p0,
const Vec3& p1,
@ -208,192 +208,192 @@ public:
uint32 color,
float life) = 0;
virtual Entity getBoneAttachmentParent(ComponentIndex cmp) = 0;
virtual void setBoneAttachmentParent(ComponentIndex cmp, Entity entity) = 0;
virtual void setBoneAttachmentBone(ComponentIndex cmp, int value) = 0;
virtual int getBoneAttachmentBone(ComponentIndex cmp) = 0;
virtual Vec3 getBoneAttachmentPosition(ComponentIndex cmp) = 0;
virtual void setBoneAttachmentPosition(ComponentIndex cmp, const Vec3& pos) = 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 const Array<DebugTriangle>& getDebugTriangles() const = 0;
virtual const Array<DebugLine>& getDebugLines() const = 0;
virtual const Array<DebugPoint>& getDebugPoints() const = 0;
virtual Matrix getCameraProjection(ComponentIndex camera) = 0;
virtual Entity getCameraEntity(ComponentIndex camera) const = 0;
virtual ComponentIndex getCameraInSlot(const char* slot) = 0;
virtual float getCameraFOV(ComponentIndex camera) = 0;
virtual void setCameraFOV(ComponentIndex camera, float fov) = 0;
virtual void setCameraFarPlane(ComponentIndex camera, float far) = 0;
virtual void setCameraNearPlane(ComponentIndex camera, float near) = 0;
virtual float getCameraFarPlane(ComponentIndex camera) = 0;
virtual float getCameraNearPlane(ComponentIndex camera) = 0;
virtual float getCameraScreenWidth(ComponentIndex camera) = 0;
virtual float getCameraScreenHeight(ComponentIndex camera) = 0;
virtual void setCameraSlot(ComponentIndex camera, const char* slot) = 0;
virtual const char* getCameraSlot(ComponentIndex camera) = 0;
virtual void setCameraScreenSize(ComponentIndex camera, int w, int h) = 0;
virtual bool isCameraOrtho(ComponentIndex camera) = 0;
virtual void setCameraOrtho(ComponentIndex camera, bool is_ortho) = 0;
virtual float getCameraOrthoSize(ComponentIndex camera) = 0;
virtual void setCameraOrthoSize(ComponentIndex camera, float value) = 0;
virtual Vec2 getCameraScreenSize(ComponentIndex camera) = 0;
virtual Matrix getCameraProjection(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 class ParticleEmitter* getParticleEmitter(ComponentIndex cmp) = 0;
virtual void resetParticleEmitter(ComponentIndex cmp) = 0;
virtual void updateEmitter(ComponentIndex cmp, float time_delta) = 0;
virtual class ParticleEmitter* getParticleEmitter(ComponentHandle cmp) = 0;
virtual void resetParticleEmitter(ComponentHandle cmp) = 0;
virtual void updateEmitter(ComponentHandle cmp, float time_delta) = 0;
virtual const Array<class ParticleEmitter*>& getParticleEmitters() const = 0;
virtual const Vec2* getParticleEmitterAlpha(ComponentIndex cmp) = 0;
virtual int getParticleEmitterAlphaCount(ComponentIndex cmp) = 0;
virtual const Vec2* getParticleEmitterSize(ComponentIndex cmp) = 0;
virtual int getParticleEmitterSizeCount(ComponentIndex cmp) = 0;
virtual Vec3 getParticleEmitterAcceleration(ComponentIndex cmp) = 0;
virtual Vec2 getParticleEmitterLinearMovementX(ComponentIndex cmp) = 0;
virtual Vec2 getParticleEmitterLinearMovementY(ComponentIndex cmp) = 0;
virtual Vec2 getParticleEmitterLinearMovementZ(ComponentIndex cmp) = 0;
virtual Vec2 getParticleEmitterInitialLife(ComponentIndex cmp) = 0;
virtual Int2 getParticleEmitterSpawnCount(ComponentIndex cmp) = 0;
virtual Vec2 getParticleEmitterSpawnPeriod(ComponentIndex cmp) = 0;
virtual Vec2 getParticleEmitterInitialSize(ComponentIndex cmp) = 0;
virtual void setParticleEmitterAlpha(ComponentIndex cmp, const Vec2* value, int count) = 0;
virtual void setParticleEmitterSize(ComponentIndex cmp, const Vec2* values, int count) = 0;
virtual void setParticleEmitterAcceleration(ComponentIndex cmp, const Vec3& value) = 0;
virtual void setParticleEmitterLinearMovementX(ComponentIndex cmp, const Vec2& value) = 0;
virtual void setParticleEmitterLinearMovementY(ComponentIndex cmp, const Vec2& value) = 0;
virtual void setParticleEmitterLinearMovementZ(ComponentIndex cmp, const Vec2& value) = 0;
virtual void setParticleEmitterInitialLife(ComponentIndex cmp, const Vec2& value) = 0;
virtual void setParticleEmitterSpawnCount(ComponentIndex cmp, const Int2& value) = 0;
virtual void setParticleEmitterSpawnPeriod(ComponentIndex cmp, const Vec2& value) = 0;
virtual void setParticleEmitterInitialSize(ComponentIndex cmp, const Vec2& value) = 0;
virtual void setParticleEmitterMaterialPath(ComponentIndex cmp, const Path& path) = 0;
virtual Path getParticleEmitterMaterialPath(ComponentIndex cmp) = 0;
virtual int getParticleEmitterPlaneCount(ComponentIndex cmp) = 0;
virtual void addParticleEmitterPlane(ComponentIndex cmp, int index) = 0;
virtual void removeParticleEmitterPlane(ComponentIndex cmp, int index) = 0;
virtual Entity getParticleEmitterPlaneEntity(ComponentIndex cmp, int index) = 0;
virtual void setParticleEmitterPlaneEntity(ComponentIndex cmp, int index, Entity entity) = 0;
virtual float getParticleEmitterPlaneBounce(ComponentIndex cmp) = 0;
virtual void setParticleEmitterPlaneBounce(ComponentIndex cmp, float value) = 0;
virtual float getParticleEmitterShapeRadius(ComponentIndex cmp) = 0;
virtual void setParticleEmitterShapeRadius(ComponentIndex cmp, float value) = 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 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 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 Path getParticleEmitterMaterialPath(ComponentHandle cmp) = 0;
virtual int getParticleEmitterPlaneCount(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 int getParticleEmitterAttractorCount(ComponentIndex cmp) = 0;
virtual void addParticleEmitterAttractor(ComponentIndex cmp, int index) = 0;
virtual void removeParticleEmitterAttractor(ComponentIndex cmp, int index) = 0;
virtual Entity getParticleEmitterAttractorEntity(ComponentIndex cmp, int index) = 0;
virtual void setParticleEmitterAttractorEntity(ComponentIndex cmp,
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,
int index,
Entity entity) = 0;
virtual float getParticleEmitterAttractorForce(ComponentIndex cmp) = 0;
virtual void setParticleEmitterAttractorForce(ComponentIndex cmp, float value) = 0;
virtual float getParticleEmitterAttractorForce(ComponentHandle cmp) = 0;
virtual void setParticleEmitterAttractorForce(ComponentHandle cmp, float value) = 0;
virtual DelegateList<void(ComponentIndex)>& renderableCreated() = 0;
virtual DelegateList<void(ComponentIndex)>& renderableDestroyed() = 0;
virtual void showRenderable(ComponentIndex cmp) = 0;
virtual void hideRenderable(ComponentIndex cmp) = 0;
virtual ComponentIndex getRenderableComponent(Entity entity) = 0;
virtual Renderable* getRenderable(ComponentIndex cmp) = 0;
virtual DelegateList<void(ComponentHandle)>& renderableCreated() = 0;
virtual DelegateList<void(ComponentHandle)>& renderableDestroyed() = 0;
virtual void showRenderable(ComponentHandle cmp) = 0;
virtual void hideRenderable(ComponentHandle cmp) = 0;
virtual ComponentHandle getRenderableComponent(Entity entity) = 0;
virtual Renderable* getRenderable(ComponentHandle cmp) = 0;
virtual Renderable* getRenderables() = 0;
virtual Path getRenderablePath(ComponentIndex cmp) = 0;
virtual void setRenderableMaterial(ComponentIndex cmp, int index, const Path& path) = 0;
virtual Path getRenderableMaterial(ComponentIndex cmp, int index) = 0;
virtual int getRenderableMaterialsCount(ComponentIndex cmp) = 0;
virtual void setRenderableLayer(ComponentIndex cmp, const int32& layer) = 0;
virtual void setRenderablePath(ComponentIndex cmp, const Path& path) = 0;
virtual Path getRenderablePath(ComponentHandle cmp) = 0;
virtual void setRenderableMaterial(ComponentHandle cmp, int index, const Path& path) = 0;
virtual Path getRenderableMaterial(ComponentHandle cmp, int index) = 0;
virtual int getRenderableMaterialsCount(ComponentHandle cmp) = 0;
virtual void setRenderableLayer(ComponentHandle cmp, const int32& layer) = 0;
virtual void setRenderablePath(ComponentHandle cmp, const Path& path) = 0;
virtual Array<Array<RenderableMesh>>& getRenderableInfos(const Frustum& frustum,
const Vec3& lod_ref_point) = 0;
virtual void getRenderableEntities(const Frustum& frustum, Array<Entity>& entities) = 0;
virtual Entity getRenderableEntity(ComponentIndex cmp) = 0;
virtual ComponentIndex getFirstRenderable() = 0;
virtual ComponentIndex getNextRenderable(ComponentIndex cmp) = 0;
virtual Model* getRenderableModel(ComponentIndex cmp) = 0;
virtual Entity getRenderableEntity(ComponentHandle cmp) = 0;
virtual ComponentHandle getFirstRenderable() = 0;
virtual ComponentHandle getNextRenderable(ComponentHandle cmp) = 0;
virtual Model* getRenderableModel(ComponentHandle cmp) = 0;
virtual void getGrassInfos(const Frustum& frustum,
Array<GrassInfo>& infos,
ComponentIndex camera) = 0;
virtual void forceGrassUpdate(ComponentIndex cmp) = 0;
ComponentHandle camera) = 0;
virtual void forceGrassUpdate(ComponentHandle cmp) = 0;
virtual void getTerrainInfos(Array<const TerrainInfo*>& infos,
const Vec3& camera_pos,
LIFOAllocator& allocator) = 0;
virtual float getTerrainHeightAt(ComponentIndex cmp, float x, float z) = 0;
virtual Vec3 getTerrainNormalAt(ComponentIndex cmp, float x, float z) = 0;
virtual void setTerrainMaterialPath(ComponentIndex cmp, const Path& path) = 0;
virtual Path getTerrainMaterialPath(ComponentIndex cmp) = 0;
virtual Material* getTerrainMaterial(ComponentIndex cmp) = 0;
virtual void setTerrainXZScale(ComponentIndex cmp, float scale) = 0;
virtual float getTerrainXZScale(ComponentIndex cmp) = 0;
virtual void setTerrainYScale(ComponentIndex cmp, float scale) = 0;
virtual float getTerrainYScale(ComponentIndex cmp) = 0;
virtual Vec2 getTerrainSize(ComponentIndex cmp) = 0;
virtual AABB getTerrainAABB(ComponentIndex cmp) = 0;
virtual ComponentIndex getTerrainComponent(Entity entity) = 0;
virtual Entity getTerrainEntity(ComponentIndex cmp) = 0;
virtual Vec2 getTerrainResolution(ComponentIndex cmp) = 0;
virtual ComponentIndex getFirstTerrain() = 0;
virtual ComponentIndex getNextTerrain(ComponentIndex cmp) = 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 bool isGrassEnabled() const = 0;
virtual float getGrassDistance(ComponentIndex cmp, int index) = 0;
virtual void setGrassDistance(ComponentIndex cmp, int index, float value) = 0;
virtual float getGrassDistance(ComponentHandle cmp, int index) = 0;
virtual void setGrassDistance(ComponentHandle cmp, int index, float value) = 0;
virtual void enableGrass(bool enabled) = 0;
virtual void setGrassPath(ComponentIndex cmp, int index, const Path& path) = 0;
virtual Path getGrassPath(ComponentIndex cmp, int index) = 0;
virtual void setGrassGround(ComponentIndex cmp, int index, int ground) = 0;
virtual int getGrassGround(ComponentIndex cmp, int index) = 0;
virtual void setGrassDensity(ComponentIndex cmp, int index, int density) = 0;
virtual int getGrassDensity(ComponentIndex cmp, int index) = 0;
virtual int getGrassCount(ComponentIndex cmp) = 0;
virtual void addGrass(ComponentIndex cmp, int index) = 0;
virtual void removeGrass(ComponentIndex cmp, int index) = 0;
virtual void setGrassPath(ComponentHandle cmp, int index, const Path& path) = 0;
virtual Path getGrassPath(ComponentHandle cmp, int index) = 0;
virtual void setGrassGround(ComponentHandle cmp, int index, int ground) = 0;
virtual int getGrassGround(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 int getClosestPointLights(const Vec3& pos, ComponentIndex* lights, int max_lights) = 0;
virtual void getPointLights(const Frustum& frustum, Array<ComponentIndex>& lights) = 0;
virtual void getPointLightInfluencedGeometry(ComponentIndex light_cmp,
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<RenderableMesh>& infos) = 0;
virtual void getPointLightInfluencedGeometry(ComponentIndex light_cmp,
virtual void getPointLightInfluencedGeometry(ComponentHandle light_cmp,
const Frustum& frustum,
Array<RenderableMesh>& infos) = 0;
virtual void setLightCastShadows(ComponentIndex cmp, bool cast_shadows) = 0;
virtual bool getLightCastShadows(ComponentIndex cmp) = 0;
virtual float getLightAttenuation(ComponentIndex cmp) = 0;
virtual void setLightAttenuation(ComponentIndex cmp, float attenuation) = 0;
virtual float getLightFOV(ComponentIndex cmp) = 0;
virtual void setLightFOV(ComponentIndex cmp, float fov) = 0;
virtual float getLightRange(ComponentIndex cmp) = 0;
virtual void setLightRange(ComponentIndex cmp, float value) = 0;
virtual void setPointLightIntensity(ComponentIndex cmp, float intensity) = 0;
virtual void setGlobalLightIntensity(ComponentIndex cmp, float intensity) = 0;
virtual void setPointLightColor(ComponentIndex cmp, const Vec3& color) = 0;
virtual void setGlobalLightColor(ComponentIndex cmp, const Vec3& color) = 0;
virtual void setGlobalLightSpecular(ComponentIndex cmp, const Vec3& color) = 0;
virtual void setGlobalLightSpecularIntensity(ComponentIndex cmp, float intensity) = 0;
virtual void setLightAmbientIntensity(ComponentIndex cmp, float intensity) = 0;
virtual void setLightAmbientColor(ComponentIndex cmp, const Vec3& color) = 0;
virtual void setFogDensity(ComponentIndex cmp, float density) = 0;
virtual void setFogColor(ComponentIndex cmp, const Vec3& color) = 0;
virtual float getPointLightIntensity(ComponentIndex cmp) = 0;
virtual Entity getPointLightEntity(ComponentIndex cmp) const = 0;
virtual Entity getGlobalLightEntity(ComponentIndex cmp) const = 0;
virtual float getGlobalLightIntensity(ComponentIndex cmp) = 0;
virtual Vec3 getPointLightColor(ComponentIndex cmp) = 0;
virtual Vec3 getGlobalLightColor(ComponentIndex cmp) = 0;
virtual Vec3 getGlobalLightSpecular(ComponentIndex cmp) = 0;
virtual float getGlobalLightSpecularIntensity(ComponentIndex cmp) = 0;
virtual float getLightAmbientIntensity(ComponentIndex cmp) = 0;
virtual Vec3 getLightAmbientColor(ComponentIndex cmp) = 0;
virtual float getFogDensity(ComponentIndex cmp) = 0;
virtual float getFogBottom(ComponentIndex cmp) = 0;
virtual float getFogHeight(ComponentIndex cmp) = 0;
virtual void setFogBottom(ComponentIndex cmp, float value) = 0;
virtual void setFogHeight(ComponentIndex cmp, float value) = 0;
virtual Vec3 getFogColor(ComponentIndex cmp) = 0;
virtual Vec3 getPointLightSpecularColor(ComponentIndex cmp) = 0;
virtual void setPointLightSpecularColor(ComponentIndex cmp, const Vec3& color) = 0;
virtual float getPointLightSpecularIntensity(ComponentIndex cmp) = 0;
virtual void setPointLightSpecularIntensity(ComponentIndex cmp, float color) = 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 setPointLightColor(ComponentHandle cmp, const Vec3& color) = 0;
virtual void setGlobalLightColor(ComponentHandle cmp, const Vec3& color) = 0;
virtual void setGlobalLightSpecular(ComponentHandle cmp, const Vec3& color) = 0;
virtual void setGlobalLightSpecularIntensity(ComponentHandle cmp, float intensity) = 0;
virtual void setLightAmbientIntensity(ComponentHandle cmp, float intensity) = 0;
virtual void setLightAmbientColor(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 Vec3 getPointLightColor(ComponentHandle cmp) = 0;
virtual Vec3 getGlobalLightColor(ComponentHandle cmp) = 0;
virtual Vec3 getGlobalLightSpecular(ComponentHandle cmp) = 0;
virtual float getGlobalLightSpecularIntensity(ComponentHandle cmp) = 0;
virtual float getLightAmbientIntensity(ComponentHandle cmp) = 0;
virtual Vec3 getLightAmbientColor(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 Texture* getEnvironmentProbeTexture(ComponentIndex cmp) const = 0;
virtual void reloadEnvironmentProbe(ComponentIndex cmp) = 0;
virtual Texture* getEnvironmentProbeTexture(ComponentHandle cmp) const = 0;
virtual void reloadEnvironmentProbe(ComponentHandle cmp) = 0;
protected:
virtual ~RenderScene() {}

View file

@ -97,7 +97,7 @@ struct BonePropertyDescriptor : public IEnumPropertyDescriptor
int value;
stream.read(&value, sizeof(value));
auto* render_scene = static_cast<RenderScene*>(cmp.scene);
render_scene->setBoneAttachmentBone(cmp.index, value);
render_scene->setBoneAttachmentBone(cmp.handle, value);
}
@ -105,25 +105,25 @@ struct BonePropertyDescriptor : public IEnumPropertyDescriptor
{
ASSERT(index == -1);
auto* render_scene = static_cast<RenderScene*>(cmp.scene);
int value = render_scene->getBoneAttachmentBone(cmp.index);
int value = render_scene->getBoneAttachmentBone(cmp.handle);
int len = sizeof(value);
stream.write(&value, len);
}
ComponentIndex getRenderable(RenderScene* render_scene, ComponentIndex bone_attachment_cmp)
ComponentHandle getRenderable(RenderScene* render_scene, ComponentHandle bone_attachment_cmp)
{
Entity parent_entity = render_scene->getBoneAttachmentParent(bone_attachment_cmp);
if (parent_entity == INVALID_ENTITY) return INVALID_COMPONENT;
ComponentIndex renderable = render_scene->getRenderableComponent(parent_entity);
ComponentHandle renderable = render_scene->getRenderableComponent(parent_entity);
return renderable;
}
int getEnumCount(IScene* scene, ComponentIndex cmp) override
int getEnumCount(IScene* scene, ComponentHandle cmp) override
{
auto* render_scene = static_cast<RenderScene*>(scene);
ComponentIndex renderable = getRenderable(render_scene, cmp);
ComponentHandle renderable = getRenderable(render_scene, cmp);
if (renderable == INVALID_COMPONENT) return 0;
auto* model = render_scene->getRenderableModel(renderable);
if (!model || !model->isReady()) return 0;
@ -131,10 +131,10 @@ struct BonePropertyDescriptor : public IEnumPropertyDescriptor
}
const char* getEnumItemName(IScene* scene, ComponentIndex cmp, int index) override
const char* getEnumItemName(IScene* scene, ComponentHandle cmp, int index) override
{
auto* render_scene = static_cast<RenderScene*>(scene);
ComponentIndex renderable = getRenderable(render_scene, cmp);
ComponentHandle renderable = getRenderable(render_scene, cmp);
if (renderable == INVALID_COMPONENT) return "";
auto* model = render_scene->getRenderableModel(renderable);
if (!model) return "";

View file

@ -387,7 +387,7 @@ void Terrain::forceGrassUpdate()
}
}
Array<Terrain::GrassQuad*>& Terrain::getQuads(ComponentIndex camera)
Array<Terrain::GrassQuad*>& Terrain::getQuads(ComponentHandle camera)
{
int quads_index = m_grass_quads.find(camera);
if (quads_index < 0)
@ -442,7 +442,7 @@ void Terrain::generateGrassTypeQuad(GrassPatch& patch,
}
void Terrain::updateGrass(ComponentIndex camera)
void Terrain::updateGrass(ComponentHandle camera)
{
PROFILE_FUNCTION();
if (!m_splatmap)
@ -554,7 +554,7 @@ void Terrain::GrassType::grassLoaded(Resource::State, Resource::State)
}
void Terrain::getGrassInfos(const Frustum& frustum, Array<GrassInfo>& infos, ComponentIndex camera)
void Terrain::getGrassInfos(const Frustum& frustum, Array<GrassInfo>& infos, ComponentHandle camera)
{
if (!m_material || !m_material->isReady()) return;
@ -613,7 +613,11 @@ void Terrain::setMaterial(Material* material)
}
}
void Terrain::deserialize(InputBlob& serializer, Universe& universe, RenderScene& scene, int index, int version)
void Terrain::deserialize(InputBlob& serializer,
Universe& universe,
RenderScene& scene,
ComponentHandle cmp,
int version)
{
serializer.read(m_entity);
serializer.read(m_layer_mask);
@ -646,7 +650,7 @@ void Terrain::deserialize(InputBlob& serializer, Universe& universe, RenderScene
}
setGrassTypePath(i, Path(path));
}
universe.addComponent(m_entity, TERRAIN_HASH, &scene, index);
universe.addComponent(m_entity, TERRAIN_HASH, &scene, cmp);
}

View file

@ -109,21 +109,25 @@ class Terrain
void setMaterial(Material* material);
void getInfos(Array<const TerrainInfo*>& infos, const Vec3& camera_pos, LIFOAllocator& allocator);
void getGrassInfos(const Frustum& frustum, Array<GrassInfo>& infos, ComponentIndex camera);
void getGrassInfos(const Frustum& frustum, Array<GrassInfo>& infos, ComponentHandle camera);
RayCastModelHit castRay(const Vec3& origin, const Vec3& dir);
void serialize(OutputBlob& serializer);
void deserialize(InputBlob& serializer, Universe& universe, RenderScene& scene, int index, int version);
void deserialize(InputBlob& serializer,
Universe& universe,
RenderScene& scene,
ComponentHandle cmp,
int version);
void addGrassType(int index);
void removeGrassType(int index);
void forceGrassUpdate();
private:
Array<Terrain::GrassQuad*>& getQuads(ComponentIndex camera);
Array<Terrain::GrassQuad*>& getQuads(ComponentHandle camera);
TerrainQuad* generateQuadTree(float size);
float getHeight(int x, int z) const;
void updateGrass(ComponentIndex camera);
void updateGrass(ComponentHandle camera);
void generateGrassTypeQuad(GrassPatch& patch,
const Matrix& terrain_matrix,
float quad_x,
@ -150,8 +154,8 @@ class Terrain
RenderScene& m_scene;
Array<GrassType*> m_grass_types;
Array<GrassQuad*> m_free_grass_quads;
AssociativeArray<ComponentIndex, Array<GrassQuad*> > m_grass_quads;
AssociativeArray<ComponentIndex, Vec3> m_last_camera_position;
AssociativeArray<ComponentHandle, Array<GrassQuad*> > m_grass_quads;
AssociativeArray<ComponentHandle, Vec3> m_last_camera_position;
bool m_force_grass_update;
Renderer& m_renderer;
};

View file

@ -37,12 +37,12 @@ namespace
{
Lumix::DefaultAllocator allocator;
Lumix::Array<Lumix::Sphere> spheres(allocator);
Lumix::Array<Lumix::ComponentIndex> renderables(allocator);
Lumix::Array<Lumix::ComponentHandle> renderables(allocator);
int renderable = 0;
for (float i = 0.f; i < 30000000.0f; i += 15.f)
{
spheres.push(Lumix::Sphere(i, 0.f, 50.f, 5.f));
renderables.push(renderable);
renderables.push({renderable});
++renderable;
}
@ -73,7 +73,7 @@ namespace
const Lumix::CullingSystem::Subresults& subresult = result[i];
for (int j = 0; j < subresult.size(); ++j)
{
LUMIX_EXPECT(subresult[i] < 6);
LUMIX_EXPECT(subresult[i].index < 6);
}
}
@ -87,12 +87,12 @@ namespace
{
Lumix::DefaultAllocator allocator;
Lumix::Array<Lumix::Sphere> spheres(allocator);
Lumix::Array<Lumix::ComponentIndex> renderables(allocator);
Lumix::Array<Lumix::ComponentHandle> renderables(allocator);
int renderable = 0;
for(float i = 0.f; i < 30000000.0f; i += 15.f)
{
spheres.push(Lumix::Sphere(i, 0.f, 50.f, 5.f));
renderables.push(renderable);
renderables.push({renderable});
++renderable;
}
@ -124,7 +124,7 @@ namespace
const Lumix::CullingSystem::Subresults& subresult = result[i];
for (int j = 0; j < subresult.size(); ++j)
{
LUMIX_EXPECT(subresult[i] < 6);
LUMIX_EXPECT(subresult[i].index < 6);
}
}