forked from mirror/openmw-tes3mp
[General] Add (very) partial animation sync for NPCs
This commit is contained in:
parent
e8638d9884
commit
d829d219c3
8 changed files with 151 additions and 6 deletions
|
@ -44,14 +44,19 @@ void Cell::updateLocal()
|
|||
else
|
||||
{
|
||||
//LOG_APPEND(Log::LOG_VERBOSE, "- Updating LocalActor %s", it->first.c_str());
|
||||
//actor->update();
|
||||
actor->update();
|
||||
MWWorld::Ptr ptr = actor->getPtr();
|
||||
|
||||
mwmp::WorldObject worldObject;
|
||||
worldObject.refId = ptr.getCellRef().getRefId();
|
||||
worldObject.refNumIndex = ptr.getCellRef().getRefNum().mIndex;
|
||||
worldObject.mpNum = ptr.getCellRef().getMpNum();
|
||||
worldObject.pos = ptr.getRefData().getPosition();
|
||||
worldObject.pos = actor->position;
|
||||
worldObject.direction = actor->direction;
|
||||
worldObject.drawState = actor->drawState;
|
||||
worldObject.movementFlags = actor->movementFlags;
|
||||
worldObject.headPitch = actor->headPitch;
|
||||
worldObject.headYaw = actor->headYaw;
|
||||
|
||||
worldEvent->addObject(worldObject);
|
||||
|
||||
|
@ -121,7 +126,15 @@ void Cell::readCellFrame(mwmp::WorldEvent& worldEvent)
|
|||
{
|
||||
DedicatedActor *actor = dedicatedActors[mapIndex];
|
||||
actor->position = worldObject.pos;
|
||||
actor->direction = worldObject.direction;
|
||||
actor->drawState = worldObject.drawState;
|
||||
actor->movementFlags = worldObject.movementFlags;
|
||||
actor->headPitch = worldObject.headPitch;
|
||||
actor->headYaw = worldObject.headYaw;
|
||||
actor->move();
|
||||
actor->setDrawState();
|
||||
actor->setMovementFlags();
|
||||
actor->setAnimation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "../mwbase/environment.hpp"
|
||||
#include "../mwmechanics/creaturestats.hpp"
|
||||
#include "../mwmechanics/movement.hpp"
|
||||
#include "../mwmechanics/npcstats.hpp"
|
||||
#include "../mwrender/animation.hpp"
|
||||
#include "../mwworld/class.hpp"
|
||||
#include "../mwworld/worldimp.hpp"
|
||||
|
||||
|
@ -11,7 +12,7 @@ using namespace std;
|
|||
|
||||
DedicatedActor::DedicatedActor()
|
||||
{
|
||||
|
||||
movementFlags = 0;
|
||||
}
|
||||
|
||||
DedicatedActor::~DedicatedActor()
|
||||
|
@ -29,9 +30,54 @@ void DedicatedActor::move()
|
|||
MWBase::World *world = MWBase::Environment::get().getWorld();
|
||||
|
||||
world->moveObject(ptr, position.pos[0], position.pos[1], position.pos[2]);
|
||||
|
||||
MWMechanics::Movement *move = &ptr.getClass().getMovementSettings(ptr);
|
||||
move->mPosition[0] = direction.pos[0];
|
||||
move->mPosition[1] = direction.pos[1];
|
||||
move->mPosition[2] = direction.pos[2];
|
||||
|
||||
world->rotateObject(ptr, position.rot[0], position.rot[1], position.rot[2]);
|
||||
}
|
||||
|
||||
void DedicatedActor::setDrawState()
|
||||
{
|
||||
using namespace MWMechanics;
|
||||
|
||||
if (drawState == 0)
|
||||
ptr.getClass().getNpcStats(ptr).setDrawState(DrawState_Nothing);
|
||||
else if (drawState == 1)
|
||||
ptr.getClass().getNpcStats(ptr).setDrawState(DrawState_Weapon);
|
||||
else if (drawState == 2)
|
||||
ptr.getClass().getNpcStats(ptr).setDrawState(DrawState_Spell);
|
||||
}
|
||||
|
||||
void DedicatedActor::setMovementFlags()
|
||||
{
|
||||
using namespace MWMechanics;
|
||||
|
||||
MWMechanics::NpcStats *ptrNpcStats = &ptr.getClass().getNpcStats(ptr);
|
||||
ptrNpcStats->setMovementFlag(CreatureStats::Flag_Run, (movementFlags & CreatureStats::Flag_Run) != 0);
|
||||
ptrNpcStats->setMovementFlag(CreatureStats::Flag_Sneak, (movementFlags & CreatureStats::Flag_Sneak) != 0);
|
||||
ptrNpcStats->setMovementFlag(CreatureStats::Flag_ForceJump, (movementFlags & CreatureStats::Flag_ForceJump) != 0);
|
||||
ptrNpcStats->setMovementFlag(CreatureStats::Flag_ForceMoveJump, (movementFlags & CreatureStats::Flag_ForceMoveJump) != 0);
|
||||
}
|
||||
|
||||
void DedicatedActor::setAnimation()
|
||||
{
|
||||
MWBase::World *world = MWBase::Environment::get().getWorld();
|
||||
|
||||
if (headPitch != -1 && headYaw != -1)
|
||||
{
|
||||
MWRender::Animation *animation = world->getAnimation(ptr);
|
||||
|
||||
if (animation)
|
||||
{
|
||||
animation->setHeadPitch(headPitch);
|
||||
animation->setHeadYaw(headYaw);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MWWorld::Ptr DedicatedActor::getPtr()
|
||||
{
|
||||
return ptr;
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define OPENMW_DEDICATEDACTOR_HPP
|
||||
|
||||
#include <components/openmw-mp/Base/BaseActor.hpp>
|
||||
#include "../mwmechanics/aisequence.hpp"
|
||||
#include "../mwworld/manualref.hpp"
|
||||
|
||||
namespace mwmp
|
||||
|
@ -15,6 +16,9 @@ namespace mwmp
|
|||
|
||||
void update();
|
||||
void move();
|
||||
void setDrawState();
|
||||
void setMovementFlags();
|
||||
void setAnimation();
|
||||
|
||||
MWWorld::Ptr getPtr();
|
||||
void setPtr(const MWWorld::Ptr& newPtr);
|
||||
|
|
|
@ -1,4 +1,9 @@
|
|||
#include <components/openmw-mp/Log.hpp>
|
||||
#include "../mwbase/environment.hpp"
|
||||
#include "../mwmechanics/movement.hpp"
|
||||
#include "../mwmechanics/npcstats.hpp"
|
||||
#include "../mwrender/animation.hpp"
|
||||
#include "../mwworld/class.hpp"
|
||||
#include "../mwworld/worldimp.hpp"
|
||||
|
||||
#include "LocalActor.hpp"
|
||||
|
||||
|
@ -7,7 +12,8 @@ using namespace std;
|
|||
|
||||
LocalActor::LocalActor()
|
||||
{
|
||||
|
||||
headPitch = -1;
|
||||
headYaw = -1;
|
||||
}
|
||||
|
||||
LocalActor::~LocalActor()
|
||||
|
@ -17,7 +23,60 @@ LocalActor::~LocalActor()
|
|||
|
||||
void LocalActor::update()
|
||||
{
|
||||
updatePosition();
|
||||
updateDrawState();
|
||||
updateMovementFlags();
|
||||
updateAnimation();
|
||||
}
|
||||
|
||||
void LocalActor::updatePosition()
|
||||
{
|
||||
position = ptr.getRefData().getPosition();
|
||||
|
||||
MWMechanics::Movement &move = ptr.getClass().getMovementSettings(ptr);
|
||||
direction.pos[0] = move.mPosition[0];
|
||||
direction.pos[1] = move.mPosition[1];
|
||||
direction.pos[2] = move.mPosition[2];
|
||||
}
|
||||
|
||||
void LocalActor::updateDrawState()
|
||||
{
|
||||
drawState = ptr.getClass().getNpcStats(ptr).getDrawState();
|
||||
}
|
||||
|
||||
void LocalActor::updateMovementFlags()
|
||||
{
|
||||
using namespace MWMechanics;
|
||||
|
||||
MWBase::World *world = MWBase::Environment::get().getWorld();
|
||||
MWMechanics::NpcStats ptrNpcStats = ptr.getClass().getNpcStats(ptr);
|
||||
|
||||
bool run = ptrNpcStats.getMovementFlag(CreatureStats::Flag_Run);
|
||||
bool sneak = ptrNpcStats.getMovementFlag(CreatureStats::Flag_Sneak);
|
||||
bool forceJump = ptrNpcStats.getMovementFlag(CreatureStats::Flag_ForceJump);
|
||||
bool forceMoveJump = ptrNpcStats.getMovementFlag(CreatureStats::Flag_ForceMoveJump);
|
||||
|
||||
#define __SETFLAG(flag, value) (value) ? (movementFlags | flag) : (movementFlags & ~flag)
|
||||
|
||||
movementFlags = __SETFLAG(CreatureStats::Flag_Sneak, sneak);
|
||||
movementFlags = __SETFLAG(CreatureStats::Flag_Run, run);
|
||||
movementFlags = __SETFLAG(CreatureStats::Flag_ForceJump, forceJump);
|
||||
movementFlags = __SETFLAG(CreatureStats::Flag_ForceMoveJump, forceMoveJump);
|
||||
|
||||
#undef __SETFLAG
|
||||
}
|
||||
|
||||
void LocalActor::updateAnimation()
|
||||
{
|
||||
MWBase::World *world = MWBase::Environment::get().getWorld();
|
||||
|
||||
MWRender::Animation *animation = world->getAnimation(ptr);
|
||||
|
||||
if (animation)
|
||||
{
|
||||
headPitch = animation->getHeadPitch();
|
||||
headYaw = animation->getHeadYaw();
|
||||
}
|
||||
}
|
||||
|
||||
MWWorld::Ptr LocalActor::getPtr()
|
||||
|
|
|
@ -15,6 +15,11 @@ namespace mwmp
|
|||
|
||||
void update();
|
||||
|
||||
void updatePosition();
|
||||
void updateDrawState();
|
||||
void updateMovementFlags();
|
||||
void updateAnimation();
|
||||
|
||||
MWWorld::Ptr getPtr();
|
||||
void setPtr(const MWWorld::Ptr& newPtr);
|
||||
|
||||
|
|
|
@ -22,6 +22,9 @@ namespace mwmp
|
|||
ESM::Position position;
|
||||
ESM::Position direction;
|
||||
ESM::Cell cell;
|
||||
|
||||
float headPitch;
|
||||
float headYaw;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -35,7 +35,16 @@ namespace mwmp
|
|||
int count;
|
||||
int charge;
|
||||
int goldValue;
|
||||
|
||||
ESM::Position pos;
|
||||
ESM::Position direction;
|
||||
|
||||
unsigned int movementFlags;
|
||||
char movementAnim;
|
||||
int drawState;
|
||||
|
||||
float headPitch;
|
||||
float headYaw;
|
||||
|
||||
int doorState;
|
||||
int lockLevel;
|
||||
|
|
|
@ -37,6 +37,12 @@ void PacketActorFrame::Packet(RakNet::BitStream *bs, bool send)
|
|||
RW(worldObject.refNumIndex, send);
|
||||
RW(worldObject.mpNum, send);
|
||||
RW(worldObject.pos, send);
|
||||
RW(worldObject.direction, send);
|
||||
RW(worldObject.movementFlags, send);
|
||||
RW(worldObject.drawState, send);
|
||||
|
||||
RW(worldObject.headPitch, send);
|
||||
RW(worldObject.headYaw, send);
|
||||
|
||||
if (!send)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue