| 1 | /* |
|---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
|---|
| 3 | * > www.orxonox.net < |
|---|
| 4 | * |
|---|
| 5 | * |
|---|
| 6 | * License notice: |
|---|
| 7 | * |
|---|
| 8 | * This program is free software; you can redistribute it and/or |
|---|
| 9 | * modify it under the terms of the GNU General Public License |
|---|
| 10 | * as published by the Free Software Foundation; either version 2 |
|---|
| 11 | * of the License, or (at your option) any later version. |
|---|
| 12 | * |
|---|
| 13 | * This program is distributed in the hope that it will be useful, |
|---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 16 | * GNU General Public License for more details. |
|---|
| 17 | * |
|---|
| 18 | * You should have received a copy of the GNU General Public License |
|---|
| 19 | * along with this program; if not, write to the Free Software |
|---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|---|
| 21 | * |
|---|
| 22 | * Author: |
|---|
| 23 | * Fabian 'x3n' Landau |
|---|
| 24 | * Co-authors: |
|---|
| 25 | * ... |
|---|
| 26 | * |
|---|
| 27 | */ |
|---|
| 28 | |
|---|
| 29 | #include "OrxonoxStableHeaders.h" |
|---|
| 30 | #include "LinearEntity.h" |
|---|
| 31 | |
|---|
| 32 | #include "core/CoreIncludes.h" |
|---|
| 33 | #include "core/XMLPort.h" |
|---|
| 34 | #include "core/Executor.h" |
|---|
| 35 | #include "tools/Timer.h" |
|---|
| 36 | |
|---|
| 37 | namespace orxonox |
|---|
| 38 | { |
|---|
| 39 | static const float MAX_RESYNCHRONIZE_TIME = 3.0f; |
|---|
| 40 | |
|---|
| 41 | CreateFactory(LinearEntity); |
|---|
| 42 | |
|---|
| 43 | LinearEntity::LinearEntity(BaseObject* creator) : MovableEntity(creator) |
|---|
| 44 | { |
|---|
| 45 | RegisterObject(LinearEntity); |
|---|
| 46 | |
|---|
| 47 | this->overwrite_position_ = Vector3::ZERO; |
|---|
| 48 | this->overwrite_orientation_ = Quaternion::IDENTITY; |
|---|
| 49 | |
|---|
| 50 | this->registerVariables(); |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | LinearEntity::~LinearEntity() |
|---|
| 54 | { |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | void LinearEntity::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
|---|
| 58 | { |
|---|
| 59 | SUPER(LinearEntity, XMLPort, xmlelement, mode); |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | void LinearEntity::registerVariables() |
|---|
| 63 | { |
|---|
| 64 | REGISTERDATA(this->linearVelocity_, network::direction::toclient, new network::NetworkCallback<LinearEntity>(this, &LinearEntity::processLinearVelocity)); |
|---|
| 65 | REGISTERDATA(this->angularVelocity_, network::direction::toclient, new network::NetworkCallback<LinearEntity>(this, &LinearEntity::processAngularVelocity)); |
|---|
| 66 | |
|---|
| 67 | REGISTERDATA(this->overwrite_position_, network::direction::toclient, new network::NetworkCallback<LinearEntity>(this, &LinearEntity::overwritePosition)); |
|---|
| 68 | REGISTERDATA(this->overwrite_orientation_, network::direction::toclient, new network::NetworkCallback<LinearEntity>(this, &LinearEntity::overwriteOrientation)); |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | void LinearEntity::tick(float dt) |
|---|
| 72 | { |
|---|
| 73 | MovableEntity::tick(dt); |
|---|
| 74 | |
|---|
| 75 | if (this->isActive()) |
|---|
| 76 | { |
|---|
| 77 | } |
|---|
| 78 | } |
|---|
| 79 | |
|---|
| 80 | void LinearEntity::overwritePosition() |
|---|
| 81 | { |
|---|
| 82 | //COUT(0) << "Setting position on client: " << this->overwrite_position_ << std::endl; |
|---|
| 83 | this->setPosition(this->overwrite_position_); |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | void LinearEntity::overwriteOrientation() |
|---|
| 87 | { |
|---|
| 88 | //COUT(0) << "Setting orientation on client: " << this->overwrite_orientation_ << std::endl; |
|---|
| 89 | this->setOrientation(this->overwrite_orientation_); |
|---|
| 90 | } |
|---|
| 91 | |
|---|
| 92 | void LinearEntity::clientConnected(unsigned int clientID) |
|---|
| 93 | { |
|---|
| 94 | resynchronize(); |
|---|
| 95 | new Timer<LinearEntity>(rnd() * MAX_RESYNCHRONIZE_TIME, true, this, createExecutor(createFunctor(&LinearEntity::resynchronize)), false); |
|---|
| 96 | } |
|---|
| 97 | |
|---|
| 98 | void LinearEntity::clientDisconnected(unsigned int clientID) |
|---|
| 99 | { |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | void LinearEntity::resynchronize() |
|---|
| 103 | { |
|---|
| 104 | positionChanged(false); |
|---|
| 105 | orientationChanged(false); |
|---|
| 106 | } |
|---|
| 107 | |
|---|
| 108 | void LinearEntity::positionChanged(bool bContinuous) |
|---|
| 109 | { |
|---|
| 110 | if (!bContinuous) |
|---|
| 111 | { |
|---|
| 112 | //if (Core::isMaster()) |
|---|
| 113 | // COUT(0) << "Setting position on server: " << this->getPosition() << std::endl; |
|---|
| 114 | this->overwrite_position_ = this->getPosition(); |
|---|
| 115 | } |
|---|
| 116 | } |
|---|
| 117 | |
|---|
| 118 | void LinearEntity::orientationChanged(bool bContinuous) |
|---|
| 119 | { |
|---|
| 120 | if (!bContinuous) |
|---|
| 121 | { |
|---|
| 122 | //if (Core::isMaster()) |
|---|
| 123 | // COUT(0) << "Setting orientation on server: " << this->getOrientation() << std::endl; |
|---|
| 124 | this->overwrite_orientation_ = this->getOrientation(); |
|---|
| 125 | } |
|---|
| 126 | } |
|---|
| 127 | } |
|---|