Merge branch 'anim-api-cleanup' into 'master'

Anim api cleanup (close #8081)

Closes #8081

See merge request OpenMW/openmw!4274
pull/3236/head
psi29a 5 months ago
commit fc2f30dc4a

@ -82,7 +82,7 @@ message(STATUS "Configuring OpenMW...")
set(OPENMW_VERSION_MAJOR 0) set(OPENMW_VERSION_MAJOR 0)
set(OPENMW_VERSION_MINOR 49) set(OPENMW_VERSION_MINOR 49)
set(OPENMW_VERSION_RELEASE 0) set(OPENMW_VERSION_RELEASE 0)
set(OPENMW_LUA_API_REVISION 64) set(OPENMW_LUA_API_REVISION 65)
set(OPENMW_POSTPROCESSING_API_REVISION 1) set(OPENMW_POSTPROCESSING_API_REVISION 1)
set(OPENMW_VERSION_COMMITHASH "") set(OPENMW_VERSION_COMMITHASH "")

@ -234,9 +234,9 @@ namespace MWLua
[mechanics](const sol::object& object, const std::string& groupname, const sol::table& options) { [mechanics](const sol::object& object, const std::string& groupname, const sol::table& options) {
uint32_t numberOfLoops = options.get_or("loops", std::numeric_limits<uint32_t>::max()); uint32_t numberOfLoops = options.get_or("loops", std::numeric_limits<uint32_t>::max());
float speed = options.get_or("speed", 1.f); float speed = options.get_or("speed", 1.f);
std::string startKey = options.get_or<std::string>("startkey", "start"); std::string startKey = options.get_or<std::string>("startKey", "start");
std::string stopKey = options.get_or<std::string>("stopkey", "stop"); std::string stopKey = options.get_or<std::string>("stopKey", "stop");
bool forceLoop = options.get_or("forceloop", false); bool forceLoop = options.get_or("forceLoop", false);
MWWorld::Ptr ptr = getMutablePtrOrThrow(ObjectVariant(object)); MWWorld::Ptr ptr = getMutablePtrOrThrow(ObjectVariant(object));
mechanics->playAnimationGroupLua(ptr, groupname, numberOfLoops, speed, startKey, stopKey, forceLoop); mechanics->playAnimationGroupLua(ptr, groupname, numberOfLoops, speed, startKey, stopKey, forceLoop);
@ -247,20 +247,22 @@ namespace MWLua
ptr, groupname, std::numeric_limits<int>::max(), 1, "start", "stop", false); ptr, groupname, std::numeric_limits<int>::max(), 1, "start", "stop", false);
}); });
api["playBlended"] = [](const sol::object& object, std::string_view groupname, const sol::table& options) { api["playBlended"] = [](const sol::object& object, std::string_view groupName, const sol::table& options) {
uint32_t loops = options.get_or("loops", 0u); uint32_t loops = options.get_or("loops", 0u);
MWRender::Animation::AnimPriority priority = getPriorityArgument(options); MWRender::Animation::AnimPriority priority = getPriorityArgument(options);
BlendMask blendMask = options.get_or("blendmask", BlendMask::BlendMask_All); BlendMask blendMask = options.get_or("blendMask", BlendMask::BlendMask_All);
bool autoDisable = options.get_or("autodisable", true); bool autoDisable = options.get_or("autoDisable", true);
float speed = options.get_or("speed", 1.0f); float speed = options.get_or("speed", 1.0f);
std::string start = options.get_or<std::string>("startkey", "start"); std::string start = options.get_or<std::string>("startKey", "start");
std::string stop = options.get_or<std::string>("stopkey", "stop"); std::string stop = options.get_or<std::string>("stopKey", "stop");
float startpoint = options.get_or("startpoint", 0.0f); float startPoint = options.get_or("startPoint", 0.0f);
bool forceLoop = options.get_or("forceloop", false); bool forceLoop = options.get_or("forceLoop", false);
const std::string_view lowerGroup = { Misc::StringUtils::lowerCase(groupName) };
auto animation = getMutableAnimationOrThrow(ObjectVariant(object)); auto animation = getMutableAnimationOrThrow(ObjectVariant(object));
animation->play(groupname, priority, blendMask, autoDisable, speed, start, stop, startpoint, loops, animation->play(lowerGroup, priority, blendMask, autoDisable, speed, start, stop, startPoint, loops,
forceLoop || animation->isLoopingAnimation(groupname)); forceLoop || animation->isLoopingAnimation(lowerGroup));
}; };
api["hasGroup"] = [](const sol::object& object, std::string_view groupname) -> bool { api["hasGroup"] = [](const sol::object& object, std::string_view groupname) -> bool {
@ -287,11 +289,11 @@ namespace MWLua
context.mLuaManager->addAction( context.mLuaManager->addAction(
[object = ObjectVariant(object), model = getStaticModelOrThrow(staticOrID), [object = ObjectVariant(object), model = getStaticModelOrThrow(staticOrID),
effectId = options.get_or<std::string>("vfxId", ""), loop = options.get_or("loop", false), effectId = options.get_or<std::string>("vfxId", ""), loop = options.get_or("loop", false),
bonename = options.get_or<std::string>("bonename", ""), boneName = options.get_or<std::string>("boneName", ""),
particleTexture = options.get_or<std::string>("particleTextureOverride", "")] { particleTexture = options.get_or<std::string>("particleTextureOverride", "")] {
MWRender::Animation* anim = getMutableAnimationOrThrow(ObjectVariant(object)); MWRender::Animation* anim = getMutableAnimationOrThrow(ObjectVariant(object));
anim->addEffect(model, effectId, loop, bonename, particleTexture); anim->addEffect(model, effectId, loop, boneName, particleTexture);
}, },
"addVfxAction"); "addVfxAction");
}); });

@ -425,14 +425,14 @@ namespace MWLua
std::string_view start, std::string_view stop, float startpoint, uint32_t loops, bool loopfallback) std::string_view start, std::string_view stop, float startpoint, uint32_t loops, bool loopfallback)
{ {
sol::table options = mLua.newTable(); sol::table options = mLua.newTable();
options["blendmask"] = blendMask; options["blendMask"] = blendMask;
options["autodisable"] = autodisable; options["autoDisable"] = autodisable;
options["speed"] = speedmult; options["speed"] = speedmult;
options["startkey"] = start; options["startKey"] = start;
options["stopkey"] = stop; options["stopKey"] = stop;
options["startpoint"] = startpoint; options["startPoint"] = startpoint;
options["loops"] = loops; options["loops"] = loops;
options["forceloop"] = loopfallback; options["forceLoop"] = loopfallback;
bool priorityAsTable = false; bool priorityAsTable = false;
for (uint32_t i = 1; i < MWRender::sNumBlendMasks; i++) for (uint32_t i = 1; i < MWRender::sNumBlendMasks; i++)

@ -71,20 +71,20 @@
-- Check if the given animation group is currently playing -- Check if the given animation group is currently playing
-- @function [parent=#animation] isPlaying -- @function [parent=#animation] isPlaying
-- @param openmw.core#GameObject actor -- @param openmw.core#GameObject actor
-- @param #string groupname -- @param #string groupName
-- @return #boolean -- @return #boolean
--- ---
-- Get the current absolute time of the given animation group if it is playing, or -1 if it is not playing. -- Get the current absolute time of the given animation group if it is playing, or -1 if it is not playing.
-- @function [parent=#animation] getCurrentTime -- @function [parent=#animation] getCurrentTime
-- @param openmw.core#GameObject actor -- @param openmw.core#GameObject actor
-- @param #string groupname -- @param #string groupName
-- @return #number -- @return #number
--- ---
-- Check whether the animation is a looping animation or not. This is determined by a combination -- Check whether the animation is a looping animation or not. This is determined by a combination
-- of groupname, some of which are hardcoded to be looping, and the presence of loop start/stop keys. -- of groupName, some of which are hardcoded to be looping, and the presence of loop start/stop keys.
-- The groupnames that are hardcoded as looping are the following, as well as per-weapon-type suffixed variants of each. -- The groupNames that are hardcoded as looping are the following, as well as per-weapon-type suffixed variants of each.
-- "walkforward", "walkback", "walkleft", "walkright", "swimwalkforward", "swimwalkback", "swimwalkleft", "swimwalkright", -- "walkforward", "walkback", "walkleft", "walkright", "swimwalkforward", "swimwalkback", "swimwalkleft", "swimwalkright",
-- "runforward", "runback", "runleft", "runright", "swimrunforward", "swimrunback", "swimrunleft", "swimrunright", -- "runforward", "runback", "runleft", "runright", "swimrunforward", "swimrunback", "swimrunleft", "swimrunright",
-- "sneakforward", "sneakback", "sneakleft", "sneakright", "turnleft", "turnright", "swimturnleft", "swimturnright", -- "sneakforward", "sneakback", "sneakleft", "sneakright", "turnleft", "turnright", "swimturnleft", "swimturnright",
@ -93,7 +93,7 @@
-- "inventoryweapontwohand", "inventoryweapontwowide" -- "inventoryweapontwohand", "inventoryweapontwowide"
-- @function [parent=#animation] isLoopingAnimation -- @function [parent=#animation] isLoopingAnimation
-- @param openmw.core#GameObject actor -- @param openmw.core#GameObject actor
-- @param #string groupname -- @param #string groupName
-- @return #boolean -- @return #boolean
@ -102,35 +102,35 @@
-- Can be used only in local scripts on self. -- Can be used only in local scripts on self.
-- @function [parent=#animation] cancel -- @function [parent=#animation] cancel
-- @param openmw.core#GameObject actor -- @param openmw.core#GameObject actor
-- @param #string groupname -- @param #string groupName
--- ---
-- Enables or disables looping for the given animation group. Looping is enabled by default. -- Enables or disables looping for the given animation group. Looping is enabled by default.
-- Can be used only in local scripts on self. -- Can be used only in local scripts on self.
-- @function [parent=#animation] setLoopingEnabled -- @function [parent=#animation] setLoopingEnabled
-- @param openmw.core#GameObject actor -- @param openmw.core#GameObject actor
-- @param #string groupname -- @param #string groupName
-- @param #boolean enabled -- @param #boolean enabled
--- ---
-- Returns the completion of the animation, or nil if the animation group is not active. -- Returns the completion of the animation, or nil if the animation group is not active.
-- @function [parent=#animation] getCompletion -- @function [parent=#animation] getCompletion
-- @param openmw.core#GameObject actor -- @param openmw.core#GameObject actor
-- @param #string groupname -- @param #string groupName
-- @return #number, #nil -- @return #number, #nil
--- ---
-- Returns the remaining number of loops, not counting the current loop, or nil if the animation group is not active. -- Returns the remaining number of loops, not counting the current loop, or nil if the animation group is not active.
-- @function [parent=#animation] getLoopCount -- @function [parent=#animation] getLoopCount
-- @param openmw.core#GameObject actor -- @param openmw.core#GameObject actor
-- @param #string groupname -- @param #string groupName
-- @return #number, #nil -- @return #number, #nil
--- ---
-- Get the current playback speed of an animation group, or nil if the animation group is not active. -- Get the current playback speed of an animation group, or nil if the animation group is not active.
-- @function [parent=#animation] getSpeed -- @function [parent=#animation] getSpeed
-- @param openmw.core#GameObject actor -- @param openmw.core#GameObject actor
-- @param #string groupname -- @param #string groupName
-- @return #number, #nil -- @return #number, #nil
--- ---
@ -139,7 +139,7 @@
-- Can be used only in local scripts on self. -- Can be used only in local scripts on self.
-- @function [parent=#animation] setSpeed -- @function [parent=#animation] setSpeed
-- @param openmw.core#GameObject actor -- @param openmw.core#GameObject actor
-- @param #string groupname -- @param #string groupName
-- @param #number speed The new animation speed, where speed=1 is normal speed. -- @param #number speed The new animation speed, where speed=1 is normal speed.
--- ---
@ -156,14 +156,14 @@
-- Can be used only in local scripts on self. -- Can be used only in local scripts on self.
-- @function [parent=#animation] playQueued -- @function [parent=#animation] playQueued
-- @param openmw.core#GameObject actor -- @param openmw.core#GameObject actor
-- @param #string groupname -- @param #string groupName
-- @param #table options A table of play options. Can contain: -- @param #table options A table of play options. Can contain:
-- --
-- * `loops` - a number >= 0, the number of times the animation should loop after the first play (default: infinite). -- * `loops` - a number >= 0, the number of times the animation should loop after the first play (default: infinite).
-- * `speed` - a floating point number >= 0, the speed at which the animation should play (default: 1); -- * `speed` - a floating point number >= 0, the speed at which the animation should play (default: 1);
-- * `startkey` - the animation key at which the animation should start (default: "start") -- * `startKey` - the animation key at which the animation should start (default: "start")
-- * `stopkey` - the animation key at which the animation should end (default: "stop") -- * `stopKey` - the animation key at which the animation should end (default: "stop")
-- * `forceloop` - a boolean, to set if the animation should loop even if it's not a looping animation (default: false) -- * `forceLoop` - a boolean, to set if the animation should loop even if it's not a looping animation (default: false)
-- --
-- @usage -- Play death1 without waiting. Equivalent to playgroup, death1, 1 -- @usage -- Play death1 without waiting. Equivalent to playgroup, death1, 1
-- anim.clearAnimationQueue(self, false) -- anim.clearAnimationQueue(self, false)
@ -171,7 +171,7 @@
-- --
-- @usage -- Play an animation group with custom start/stop keys -- @usage -- Play an animation group with custom start/stop keys
-- anim.clearAnimationQueue(self, false) -- anim.clearAnimationQueue(self, false)
-- anim.playQueued(self, 'spellcast', { startkey = 'self start', stopkey = 'self stop' }) -- anim.playQueued(self, 'spellcast', { startKey = 'self start', stopKey = 'self stop' })
-- --
--- ---
@ -182,38 +182,38 @@
-- Can be used only in local scripts on self. -- Can be used only in local scripts on self.
-- @function [parent=#animation] playBlended -- @function [parent=#animation] playBlended
-- @param openmw.core#GameObject actor -- @param openmw.core#GameObject actor
-- @param #string groupname -- @param #string groupName
-- @param #table options A table of play options. Can contain: -- @param #table options A table of play options. Can contain:
-- --
-- * `loops` - a number >= 0, the number of times the animation should loop after the first play (default: 0). -- * `loops` - a number >= 0, the number of times the animation should loop after the first play (default: 0).
-- * `priority` - Either a single #Priority value that will be assigned to all bone groups. Or a table mapping bone groups to its priority (default: PRIORITY.Default). -- * `priority` - Either a single #Priority value that will be assigned to all bone groups. Or a table mapping bone groups to its priority (default: PRIORITY.Default).
-- * `blendmask` - A mask of which bone groups to include in the animation (Default: BLEND_MASK.All. -- * `blendMask` - A mask of which bone groups to include in the animation (Default: BLEND_MASK.All.
-- * `autodisable` - If true, the animation will be immediately removed upon finishing, which means information will not be possible to query once completed. (Default: true) -- * `autoDisable` - If true, the animation will be immediately removed upon finishing, which means information will not be possible to query once completed. (Default: true)
-- * `speed` - a floating point number >= 0, the speed at which the animation should play (default: 1) -- * `speed` - a floating point number >= 0, the speed at which the animation should play (default: 1)
-- * `startkey` - the animation key at which the animation should start (default: "start") -- * `startKey` - the animation key at which the animation should start (default: "start")
-- * `stopkey` - the animation key at which the animation should end (default: "stop") -- * `stopKey` - the animation key at which the animation should end (default: "stop")
-- * `startpoint` - a floating point number 0 <= value <= 1, starting completion of the animation (default: 0) -- * `startPoint` - a floating point number 0 <= value <= 1, starting completion of the animation (default: 0)
-- * `forceloop` - a boolean, to set if the animation should loop even if it's not a looping animation (default: false) -- * `forceLoop` - a boolean, to set if the animation should loop even if it's not a looping animation (default: false)
--- ---
-- Check if the actor's animation has the given animation group or not. -- Check if the actor's animation has the given animation group or not.
-- @function [parent=#animation] hasGroup -- @function [parent=#animation] hasGroup
-- @param openmw.core#GameObject actor -- @param openmw.core#GameObject actor
-- @param #string groupname -- @param #string groupName
-- @return #boolean -- @return #boolean
--- ---
-- Check if the actor's skeleton has the given bone or not -- Check if the actor's skeleton has the given bone or not
-- @function [parent=#animation] hasBone -- @function [parent=#animation] hasBone
-- @param openmw.core#GameObject actor -- @param openmw.core#GameObject actor
-- @param #string bonename -- @param #string boneName
-- @return #boolean -- @return #boolean
--- ---
-- Get the current active animation for a bone group -- Get the current active animation for a bone group
-- @function [parent=#animation] getActiveGroup -- @function [parent=#animation] getActiveGroup
-- @param openmw.core#GameObject actor -- @param openmw.core#GameObject actor
-- @param #number bonegroup Bone group enum, see @{openmw.animation#BONE_GROUP} -- @param #number boneGroup Bone group enum, see @{openmw.animation#BONE_GROUP}
-- @return #string -- @return #string
--- ---
@ -225,12 +225,12 @@
-- @param #table options optional table of parameters. Can contain: -- @param #table options optional table of parameters. Can contain:
-- --
-- * `loop` - boolean, if true the effect will loop until removed (default: 0). -- * `loop` - boolean, if true the effect will loop until removed (default: 0).
-- * `bonename` - name of the bone to attach the vfx to. (default: "") -- * `boneName` - name of the bone to attach the vfx to. (default: "")
-- * `particle` - name of the particle texture to use. (default: "") -- * `particle` - name of the particle texture to use. (default: "")
-- * `vfxId` - a string ID that can be used to remove the effect later, using #removeVfx, and to avoid duplicate effects. The default value of "" can have duplicates. To avoid interaction with the engine, use unique identifiers unrelated to magic effect IDs. The engine uses this identifier to add and remove magic effects based on what effects are active on the actor. If this is set equal to the @{openmw.core#MagicEffectId} identifier of the magic effect being added, for example core.magic.EFFECT_TYPE.FireDamage, then the engine will remove it once the fire damage effect on the actor reaches 0. (Default: ""). -- * `vfxId` - a string ID that can be used to remove the effect later, using #removeVfx, and to avoid duplicate effects. The default value of "" can have duplicates. To avoid interaction with the engine, use unique identifiers unrelated to magic effect IDs. The engine uses this identifier to add and remove magic effects based on what effects are active on the actor. If this is set equal to the @{openmw.core#MagicEffectId} identifier of the magic effect being added, for example core.magic.EFFECT_TYPE.FireDamage, then the engine will remove it once the fire damage effect on the actor reaches 0. (Default: "").
-- --
-- @usage local mgef = core.magic.effects.records[myEffectName] -- @usage local mgef = core.magic.effects.records[myEffectName]
-- anim.addVfx(self, 'VFX_Hands', {bonename = 'Bip01 L Hand', particle = mgef.particle, loop = mgef.continuousVfx, vfxId = mgef.id..'_myuniquenamehere'}) -- anim.addVfx(self, 'VFX_Hands', {boneName = 'Bip01 L Hand', particle = mgef.particle, loop = mgef.continuousVfx, vfxId = mgef.id..'_myuniquenamehere'})
-- -- later: -- -- later:
-- anim.removeVfx(self, mgef.id..'_myuniquenamehere') -- anim.removeVfx(self, mgef.id..'_myuniquenamehere')
-- --

Loading…
Cancel
Save