Skip to content

Commit 8550ac4

Browse files
committed
Merge branch 'add_loop_and_vfx_id_to_world_vfx_spawn' into 'master'
add loop + vfxId params to world.vfx.spawn and add world.vfx.remove See merge request OpenMW/openmw!4503
2 parents 3ef9237 + 0d68fb2 commit 8550ac4

File tree

11 files changed

+92
-17
lines changed

11 files changed

+92
-17
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ message(STATUS "Configuring OpenMW...")
8282
set(OPENMW_VERSION_MAJOR 0)
8383
set(OPENMW_VERSION_MINOR 51)
8484
set(OPENMW_VERSION_RELEASE 0)
85-
set(OPENMW_LUA_API_REVISION 105)
85+
set(OPENMW_LUA_API_REVISION 106)
8686
set(OPENMW_POSTPROCESSING_API_REVISION 4)
8787

8888
set(OPENMW_VERSION_COMMITHASH "")

apps/openmw/mwbase/world.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,9 +529,12 @@ namespace MWBase
529529
virtual void spawnRandomCreature(const ESM::RefId& creatureList) = 0;
530530

531531
virtual void spawnEffect(VFS::Path::NormalizedView model, const std::string& textureOverride,
532-
const osg::Vec3f& worldPos, float scale = 1.f, bool isMagicVFX = true, bool useAmbientLight = true)
532+
const osg::Vec3f& worldPos, float scale = 1.f, bool isMagicVFX = true, bool useAmbientLight = true,
533+
std::string_view effectId = {}, bool loop = false)
533534
= 0;
534535

536+
virtual void removeEffect(std::string_view effectId) = 0;
537+
535538
/// @see MWWorld::WeatherManager::isInStorm
536539
virtual bool isInStorm() const = 0;
537540

apps/openmw/mwlua/animationbindings.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,19 +291,27 @@ namespace MWLua
291291
{
292292
sol::table api(context.mLua->unsafeState(), sol::create);
293293

294+
api["remove"] = [context](std::string vfxId) {
295+
context.mLuaManager->addAction(
296+
[vfxId = std::move(vfxId)] { MWBase::Environment::get().getWorld()->removeEffect(vfxId); },
297+
"openmw.vfx.remove");
298+
};
299+
294300
api["spawn"]
295301
= [context](std::string_view model, const osg::Vec3f& worldPos, sol::optional<sol::table> options) {
296302
if (options)
297303
{
298304
bool magicVfx = options->get_or("mwMagicVfx", true);
299305
std::string texture = options->get_or<std::string>("particleTextureOverride", "");
300306
float scale = options->get_or("scale", 1.f);
307+
std::string vfxId = options->get_or<std::string>("vfxId", "");
308+
bool loop = options->get_or("loop", false);
301309
bool useAmbientLight = options->get_or("useAmbientLight", true);
302310
context.mLuaManager->addAction(
303311
[model = VFS::Path::Normalized(model), texture = std::move(texture), worldPos, scale,
304-
magicVfx, useAmbientLight]() {
312+
magicVfx, useAmbientLight, vfxId = std::move(vfxId), loop]() {
305313
MWBase::Environment::get().getWorld()->spawnEffect(
306-
model, texture, worldPos, scale, magicVfx, useAmbientLight);
314+
model, texture, worldPos, scale, magicVfx, useAmbientLight, vfxId, loop);
307315
},
308316
"openmw.vfx.spawn");
309317
}

apps/openmw/mwrender/effectmanager.cpp

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,17 @@ namespace MWRender
2828
}
2929

3030
void EffectManager::addEffect(VFS::Path::NormalizedView model, std::string_view textureOverride,
31-
const osg::Vec3f& worldPosition, float scale, bool isMagicVFX, bool useAmbientLight)
31+
const osg::Vec3f& worldPosition, float scale, bool isMagicVFX, bool useAmbientLight, std::string_view effectId,
32+
bool loop)
3233
{
3334
osg::ref_ptr<osg::Node> node = mResourceSystem->getSceneManager()->getInstance(model);
3435

3536
node->setNodeMask(Mask_Effect);
3637

3738
Effect effect;
3839
effect.mAnimTime = std::make_shared<EffectAnimationTime>();
40+
effect.mLoop = loop;
41+
effect.mEffectId = effectId;
3942

4043
SceneUtil::FindMaxControllerLengthVisitor findMaxLengthVisitor;
4144
node->accept(findMaxLengthVisitor);
@@ -70,14 +73,41 @@ namespace MWRender
7073
mEffects.push_back(std::move(effect));
7174
}
7275

76+
void EffectManager::removeEffect(std::string_view effectId)
77+
{
78+
mEffects.erase(std::remove_if(mEffects.begin(), mEffects.end(),
79+
[effectId, this](Effect& effect) {
80+
if (effectId == effect.mEffectId)
81+
{
82+
mParentNode->removeChild(effect.mTransform);
83+
return true;
84+
}
85+
86+
return false;
87+
}),
88+
mEffects.end());
89+
}
90+
7391
void EffectManager::update(float dt)
7492
{
7593
mEffects.erase(std::remove_if(mEffects.begin(), mEffects.end(),
7694
[dt, this](Effect& effect) {
95+
bool remove = false;
7796
effect.mAnimTime->addTime(dt);
78-
const auto remove = effect.mAnimTime->getTime() >= effect.mMaxControllerLength;
79-
if (remove)
80-
mParentNode->removeChild(effect.mTransform);
97+
if (effect.mAnimTime->getTime() >= effect.mMaxControllerLength)
98+
{
99+
if (effect.mLoop)
100+
{
101+
float remainder = effect.mAnimTime->getTime() - effect.mMaxControllerLength;
102+
effect.mAnimTime->resetTime(remainder);
103+
}
104+
else
105+
{
106+
mParentNode->removeChild(effect.mTransform);
107+
remove = true;
108+
}
109+
}
110+
81111
return remove;
82112
}),
83113
mEffects.end());

apps/openmw/mwrender/effectmanager.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ namespace MWRender
3535

3636
/// Add an effect. When it's finished playing, it will be removed automatically.
3737
void addEffect(VFS::Path::NormalizedView model, std::string_view textureOverride,
38-
const osg::Vec3f& worldPosition, float scale, bool isMagicVFX = true, bool useAmbientLight = true);
38+
const osg::Vec3f& worldPosition, float scale, bool isMagicVFX = true, bool useAmbientLight = true,
39+
std::string_view effectId = {}, bool loop = false);
40+
41+
void removeEffect(std::string_view effectId);
3942

4043
void update(float dt);
4144

@@ -45,7 +48,9 @@ namespace MWRender
4548
private:
4649
struct Effect
4750
{
51+
std::string mEffectId;
4852
float mMaxControllerLength;
53+
bool mLoop;
4954
std::shared_ptr<EffectAnimationTime> mAnimTime;
5055
osg::ref_ptr<osg::PositionAttitudeTransform> mTransform;
5156
};

apps/openmw/mwrender/renderingmanager.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,9 +1252,15 @@ namespace MWRender
12521252
}
12531253

12541254
void RenderingManager::spawnEffect(VFS::Path::NormalizedView model, std::string_view texture,
1255-
const osg::Vec3f& worldPosition, float scale, bool isMagicVFX, bool useAmbientLight)
1255+
const osg::Vec3f& worldPosition, float scale, bool isMagicVFX, bool useAmbientLight, std::string_view effectId,
1256+
bool loop)
12561257
{
1257-
mEffectManager->addEffect(model, texture, worldPosition, scale, isMagicVFX, useAmbientLight);
1258+
mEffectManager->addEffect(model, texture, worldPosition, scale, isMagicVFX, useAmbientLight, effectId, loop);
1259+
}
1260+
1261+
void RenderingManager::removeEffect(std::string_view effectId)
1262+
{
1263+
mEffectManager->removeEffect(effectId);
12581264
}
12591265

12601266
void RenderingManager::notifyWorldSpaceChanged()

apps/openmw/mwrender/renderingmanager.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,10 @@ namespace MWRender
196196
SkyManager* getSkyManager();
197197

198198
void spawnEffect(VFS::Path::NormalizedView model, std::string_view texture, const osg::Vec3f& worldPosition,
199-
float scale = 1.f, bool isMagicVFX = true, bool useAmbientLight = true);
199+
float scale = 1.f, bool isMagicVFX = true, bool useAmbientLight = true, std::string_view effectId = {},
200+
bool loop = false);
201+
202+
void removeEffect(std::string_view effectId);
200203

201204
/// Clear all savegame-specific data
202205
void clear();

apps/openmw/mwworld/worldimp.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3713,9 +3713,15 @@ namespace MWWorld
37133713
}
37143714

37153715
void World::spawnEffect(VFS::Path::NormalizedView model, const std::string& textureOverride,
3716-
const osg::Vec3f& worldPos, float scale, bool isMagicVFX, bool useAmbientLight)
3716+
const osg::Vec3f& worldPos, float scale, bool isMagicVFX, bool useAmbientLight, std::string_view effectId,
3717+
bool loop)
37173718
{
3718-
mRendering->spawnEffect(model, textureOverride, worldPos, scale, isMagicVFX, useAmbientLight);
3719+
mRendering->spawnEffect(model, textureOverride, worldPos, scale, isMagicVFX, useAmbientLight, effectId, loop);
3720+
}
3721+
3722+
void World::removeEffect(std::string_view effectId)
3723+
{
3724+
mRendering->removeEffect(effectId);
37193725
}
37203726

37213727
struct ResetActorsVisitor

apps/openmw/mwworld/worldimp.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -611,8 +611,10 @@ namespace MWWorld
611611
void spawnRandomCreature(const ESM::RefId& creatureList) override;
612612

613613
void spawnEffect(VFS::Path::NormalizedView model, const std::string& textureOverride,
614-
const osg::Vec3f& worldPos, float scale = 1.f, bool isMagicVFX = true,
615-
bool useAmbientLight = true) override;
614+
const osg::Vec3f& worldPos, float scale = 1.f, bool isMagicVFX = true, bool useAmbientLight = true,
615+
std::string_view effectId = {}, bool loop = false) override;
616+
617+
void removeEffect(std::string_view effectId) override;
616618

617619
/// @see MWWorld::WeatherManager::isInStorm
618620
bool isInStorm() const override;

files/data/scripts/omw/worldeventhandlers.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ return {
77
SetGameTimeScale = function(scale) world.setGameTimeScale(scale) end,
88
SetSimulationTimeScale = function(scale) world.setSimulationTimeScale(scale) end,
99
SpawnVfx = function(data) world.vfx.spawn(data.model, data.position, data.options) end,
10+
RemoveVfx = function(vfxId) world.vfx.remove(vfxId) end,
1011
},
1112
}

0 commit comments

Comments
 (0)