From c05c456b1130700fb4026b10676fb12f2822aede Mon Sep 17 00:00:00 2001 From: David Cernat Date: Mon, 17 Apr 2017 18:50:20 +0300 Subject: [PATCH] [Client] Clean up parts of LocalPlayer and DedicatedPlayer --- apps/openmw/mwmp/DedicatedPlayer.cpp | 97 ---------------------------- apps/openmw/mwmp/DedicatedPlayer.hpp | 24 ++++--- apps/openmw/mwmp/LocalPlayer.cpp | 23 ++----- 3 files changed, 22 insertions(+), 122 deletions(-) diff --git a/apps/openmw/mwmp/DedicatedPlayer.cpp b/apps/openmw/mwmp/DedicatedPlayer.cpp index a9dbab106..6d6082277 100644 --- a/apps/openmw/mwmp/DedicatedPlayer.cpp +++ b/apps/openmw/mwmp/DedicatedPlayer.cpp @@ -181,35 +181,6 @@ MWWorld::ManualRef *DedicatedPlayer::getRef() return reference; } -ESM::Position Slerp(ESM::Position start, ESM::Position end, float percent) -{ - // dot product - the cosine of the angle between 2 vectors. - float dot = start.asVec3() * end.asVec3(); - // clamp it to be in the range of Acos() - // This may be unnecessary, but floating point - // precision can be a fickle mistress. - dot = boost::algorithm::clamp(dot, -1.0f, 1.0f); - // acos(dot) returns the angle between start and end, - // And multiplying that by percent returns the angle between - // start and the final result. - float theta = acos(dot) * percent; - osg::Vec3f relativeVec = end.asVec3() - start.asVec3() * dot; - relativeVec.normalize(); // Orthonormal basis - - // result - osg::Vec3f tmp ((start.asVec3() * cos(theta)) + (relativeVec * sin(theta))); - ESM::Position result; - - result.pos[0] = tmp.x(); - result.pos[1] = tmp.y(); - result.pos[2] = tmp.z(); - - result.rot[0] = start.rot[0]; - result.rot[1] = start.rot[1]; - result.rot[2] = result.rot[2]; - return result; -} - void DedicatedPlayer::move(float dt) { if (state != 2) return; @@ -340,74 +311,6 @@ void DedicatedPlayer::updateEquipment() } } -const std::string DedicatedPlayer::getAnim() -{ - static string anim; - static string animDir; - static string animWeap; - - MWMechanics::NpcStats *npcStats = &ptr.getClass().getNpcStats(ptr); - - if (movementFlags & MWMechanics::CreatureStats::Flag_Run) - anim = "run"; - else if (movementFlags & MWMechanics::CreatureStats::Flag_Sneak) - anim = "sneak"; - else - anim = "walk"; - - if (movementAnim != 0) - { - - if (movementAnim == 3) - animDir = "forward"; - else if (movementAnim == 4) - animDir = "back"; - else if (movementAnim == 2) - animDir = "left"; - else if (movementAnim == 1) - animDir = "right"; - } - else - { - anim = "idle"; - animDir = ""; - } - - if (npcStats->getDrawState() == MWMechanics::DrawState_Weapon) - { - MWWorld::InventoryStore& invStore = ptr.getClass().getInventoryStore(ptr); - MWWorld::ContainerStoreIterator weaponSlot = invStore.getSlot(MWWorld::InventoryStore::Slot_CarriedRight); - - if (weaponSlot != invStore.end() && weaponSlot->getTypeName() == typeid(ESM::Weapon).name()) - { - int type = weaponSlot->get()->mBase->mData.mType; - if (type == ESM::Weapon::ShortBladeOneHand || - type == ESM::Weapon::LongBladeOneHand || - type == ESM::Weapon::BluntOneHand || - type == ESM::Weapon::AxeOneHand /*|| - type == ESM::Weapon::MarksmanThrown || - type == ESM::Weapon::MarksmanCrossbow || - type == ESM::Weapon::MarksmanBow*/) - animWeap = "1h"; - else if (type == ESM::Weapon::LongBladeTwoHand || - type == ESM::Weapon::BluntTwoClose || - type == ESM::Weapon::AxeTwoHand) - animWeap = "2c"; - else if (type == ESM::Weapon::BluntTwoWide || - type == ESM::Weapon::SpearTwoWide) - animWeap = "2w"; - } - else - animWeap = "hh"; - } - else if (movementAnim == 0 && npcStats->getDrawState() == MWMechanics::DrawState_Spell) - animWeap = "spell"; - else - animWeap = ""; - - return (anim + animDir + animWeap); -} - DedicatedPlayer *Players::getPlayer(const MWWorld::Ptr &ptr) { std::map ::iterator it = players.begin(); diff --git a/apps/openmw/mwmp/DedicatedPlayer.hpp b/apps/openmw/mwmp/DedicatedPlayer.hpp index b3bf6e0c0..f793b033e 100644 --- a/apps/openmw/mwmp/DedicatedPlayer.hpp +++ b/apps/openmw/mwmp/DedicatedPlayer.hpp @@ -2,18 +2,20 @@ // Created by koncord on 02.01.16. // -#ifndef OPENMW_PLAYER_HPP -#define OPENMW_PLAYER_HPP +#ifndef OPENMW_DEDICATEDPLAYER_HPP +#define OPENMW_DEDICATEDPLAYER_HPP +#include #include +#include + +#include "../mwmechanics/aisequence.hpp" + #include "../mwworld/manualref.hpp" + #include -#include "../mwmechanics/aisequence.hpp" #include -#include -#include - namespace MWMechanics { class Actor; @@ -26,6 +28,7 @@ namespace mwmp class Players { public: + static DedicatedPlayer *newPlayer(RakNet::RakNetGUID guid); static void createPlayer(RakNet::RakNetGUID guid); static void disconnectPlayer(RakNet::RakNetGUID guid); @@ -33,13 +36,16 @@ namespace mwmp static DedicatedPlayer *getPlayer(RakNet::RakNetGUID guid); static DedicatedPlayer *getPlayer(const MWWorld::Ptr &ptr); static void update(float dt); + private: + static std::map players; }; class DedicatedPlayer : public BasePlayer { friend class Players; + public: MWWorld::Ptr getPtr(); @@ -55,11 +61,13 @@ namespace mwmp void removeMarker(); void setMarkerState(bool state); void updateActor(MWMechanics::Actor *actor); + private: + DedicatedPlayer(RakNet::RakNetGUID guid); virtual ~DedicatedPlayer(); void updatePtr(MWWorld::Ptr newPtr); - const std::string getAnim(); + int state; MWWorld::ManualRef* reference; @@ -69,4 +77,4 @@ namespace mwmp bool markerEnabled; }; } -#endif //OPENMW_PLAYER_HPP +#endif //OPENMW_DEDICATEDPLAYER_HPP diff --git a/apps/openmw/mwmp/LocalPlayer.cpp b/apps/openmw/mwmp/LocalPlayer.cpp index 3ad5e0453..62c4c0ea9 100644 --- a/apps/openmw/mwmp/LocalPlayer.cpp +++ b/apps/openmw/mwmp/LocalPlayer.cpp @@ -523,32 +523,22 @@ void LocalPlayer::updateAttackState(bool forceUpdate) static bool attackPressed = false; // prevent flood MWMechanics::DrawState_ state = player.getClass().getNpcStats(player).getDrawState(); - //player.getClass().hit(player, 1, ESM::Weapon::AT_Chop); + if (world->getPlayer().getAttackingOrSpell() && !attackPressed) { MWWorld::Ptr weapon = MWWorld::Ptr(); // hand-to-hand - //player.getClass().onHit(player, 0.5, true, weapon, 0, 1); + if (state == MWMechanics::DrawState_Spell) { - const string &spell = MWBase::Environment::get().getWindowManager()->getSelectedSpell(); - attack.type = Attack::MAGIC; attack.pressed = true; - attack.spellId = spell; - } - else if (state == MWMechanics::DrawState_Weapon) - { - //PrepareAttack(2); + attack.spellId = MWBase::Environment::get().getWindowManager()->getSelectedSpell(); } + attackPressed = true; } else if (!world->getPlayer().getAttackingOrSpell() && attackPressed) { - if (/*state == MWMechanics::DrawState_Spell ||*/ state == MWMechanics::DrawState_Weapon) - { - //localNetPlayer->getAttack()->success = false; - //SendAttack(0); - } attackPressed = false; } } @@ -1181,10 +1171,9 @@ void LocalPlayer::prepareAttack(Attack::TYPE type, bool state) if (dstate == MWMechanics::DrawState_Spell) { - const string &spell = MWBase::Environment::get().getWindowManager()->getSelectedSpell(); - attack.success = Misc::Rng::roll0to99() < MWMechanics::getSpellSuccessChance(spell, getPlayerPtr()); + attack.spellId = MWBase::Environment::get().getWindowManager()->getSelectedSpell(); + attack.success = Misc::Rng::roll0to99() < MWMechanics::getSpellSuccessChance(attack.spellId, getPlayerPtr()); state = true; - attack.spellId = spell; } else {