[2072] | 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: |
---|
[2662] | 25 | * Reto Grieder |
---|
[2072] | 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | #include "OrxonoxStableHeaders.h" |
---|
| 30 | #include "ControllableEntity.h" |
---|
| 31 | |
---|
[2662] | 32 | #include <OgreSceneManager.h> |
---|
| 33 | |
---|
[2072] | 34 | #include "core/CoreIncludes.h" |
---|
[2662] | 35 | #include "core/ConfigValueIncludes.h" |
---|
[2896] | 36 | #include "core/GameMode.h" |
---|
[2072] | 37 | #include "core/XMLPort.h" |
---|
| 38 | #include "core/Template.h" |
---|
| 39 | |
---|
[2662] | 40 | #include "objects/Scene.h" |
---|
[2072] | 41 | #include "objects/infos/PlayerInfo.h" |
---|
[3049] | 42 | #include "objects/controllers/Controller.h" |
---|
[2072] | 43 | #include "objects/worldentities/Camera.h" |
---|
| 44 | #include "objects/worldentities/CameraPosition.h" |
---|
| 45 | #include "overlays/OverlayGroup.h" |
---|
| 46 | |
---|
| 47 | namespace orxonox |
---|
| 48 | { |
---|
| 49 | CreateFactory(ControllableEntity); |
---|
| 50 | |
---|
[2662] | 51 | ControllableEntity::ControllableEntity(BaseObject* creator) : MobileEntity(creator) |
---|
[2072] | 52 | { |
---|
| 53 | RegisterObject(ControllableEntity); |
---|
| 54 | |
---|
[2662] | 55 | this->bHasLocalController_ = false; |
---|
| 56 | this->bHasHumanController_ = false; |
---|
| 57 | |
---|
[2072] | 58 | this->server_overwrite_ = 0; |
---|
| 59 | this->client_overwrite_ = 0; |
---|
| 60 | this->player_ = 0; |
---|
[2171] | 61 | this->playerID_ = OBJECTID_UNKNOWN; |
---|
[2072] | 62 | this->hud_ = 0; |
---|
| 63 | this->camera_ = 0; |
---|
[3049] | 64 | this->xmlcontroller_ = 0; |
---|
[2072] | 65 | this->bDestroyWhenPlayerLeft_ = false; |
---|
[2662] | 66 | this->cameraPositionRootNode_ = this->node_->createChildSceneNode(); |
---|
| 67 | this->bMouseLook_ = false; |
---|
| 68 | this->mouseLookSpeed_ = 200; |
---|
[2072] | 69 | |
---|
[2662] | 70 | this->server_position_ = Vector3::ZERO; |
---|
| 71 | this->client_position_ = Vector3::ZERO; |
---|
| 72 | this->server_linear_velocity_ = Vector3::ZERO; |
---|
| 73 | this->client_linear_velocity_ = Vector3::ZERO; |
---|
| 74 | this->server_orientation_ = Quaternion::IDENTITY; |
---|
| 75 | this->client_orientation_ = Quaternion::IDENTITY; |
---|
| 76 | this->server_angular_velocity_ = Vector3::ZERO; |
---|
| 77 | this->client_angular_velocity_ = Vector3::ZERO; |
---|
[2072] | 78 | |
---|
[2662] | 79 | |
---|
| 80 | this->setConfigValues(); |
---|
| 81 | this->setPriority( priority::very_high ); |
---|
[2072] | 82 | this->registerVariables(); |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | ControllableEntity::~ControllableEntity() |
---|
| 86 | { |
---|
| 87 | if (this->isInitialized()) |
---|
| 88 | { |
---|
[2662] | 89 | this->bDestroyWhenPlayerLeft_ = false; |
---|
[2072] | 90 | |
---|
[2662] | 91 | if (this->bHasLocalController_ && this->bHasHumanController_) |
---|
| 92 | this->stopLocalHumanControl(); |
---|
| 93 | |
---|
| 94 | if (this->getPlayer() && this->getPlayer()->getControllableEntity() == this) |
---|
[3038] | 95 | this->getPlayer()->stopControl(); |
---|
[2662] | 96 | |
---|
[3049] | 97 | if (this->xmlcontroller_) |
---|
| 98 | delete this->xmlcontroller_; |
---|
| 99 | |
---|
[2072] | 100 | if (this->hud_) |
---|
| 101 | delete this->hud_; |
---|
| 102 | |
---|
| 103 | if (this->camera_) |
---|
| 104 | delete this->camera_; |
---|
| 105 | |
---|
[2662] | 106 | for (std::list<CameraPosition*>::const_iterator it = this->cameraPositions_.begin(); it != this->cameraPositions_.end(); ++it) |
---|
| 107 | delete (*it); |
---|
| 108 | |
---|
| 109 | if (this->getScene()->getSceneManager()) |
---|
| 110 | this->getScene()->getSceneManager()->destroySceneNode(this->cameraPositionRootNode_->getName()); |
---|
[2072] | 111 | } |
---|
| 112 | } |
---|
| 113 | |
---|
| 114 | void ControllableEntity::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
| 115 | { |
---|
| 116 | SUPER(ControllableEntity, XMLPort, xmlelement, mode); |
---|
| 117 | |
---|
| 118 | XMLPortParam(ControllableEntity, "hudtemplate", setHudTemplate, getHudTemplate, xmlelement, mode); |
---|
| 119 | XMLPortParam(ControllableEntity, "camerapositiontemplate", setCameraPositionTemplate, getCameraPositionTemkplate, xmlelement, mode); |
---|
| 120 | |
---|
| 121 | XMLPortObject(ControllableEntity, CameraPosition, "camerapositions", addCameraPosition, getCameraPosition, xmlelement, mode); |
---|
[3049] | 122 | XMLPortObject(ControllableEntity, Controller, "controller", setXMLController, getXMLController, xmlelement, mode); |
---|
[2072] | 123 | } |
---|
| 124 | |
---|
[2662] | 125 | void ControllableEntity::setConfigValues() |
---|
| 126 | { |
---|
| 127 | SetConfigValue(mouseLookSpeed_, 3.0f); |
---|
| 128 | } |
---|
| 129 | |
---|
[2072] | 130 | void ControllableEntity::addCameraPosition(CameraPosition* position) |
---|
| 131 | { |
---|
[2826] | 132 | if (!position->getIsAbsolute()) |
---|
| 133 | { |
---|
| 134 | if (position->getAllowMouseLook()) |
---|
| 135 | position->attachToNode(this->cameraPositionRootNode_); |
---|
| 136 | else |
---|
| 137 | this->attach(position); |
---|
| 138 | } |
---|
[2662] | 139 | else |
---|
[2826] | 140 | { |
---|
| 141 | WorldEntity* parent = this->getParent(); |
---|
| 142 | if (parent) |
---|
| 143 | parent->attach(position); |
---|
| 144 | } |
---|
[2072] | 145 | this->cameraPositions_.push_back(position); |
---|
| 146 | } |
---|
| 147 | |
---|
| 148 | CameraPosition* ControllableEntity::getCameraPosition(unsigned int index) const |
---|
| 149 | { |
---|
| 150 | unsigned int i = 0; |
---|
| 151 | for (std::list<CameraPosition*>::const_iterator it = this->cameraPositions_.begin(); it != this->cameraPositions_.end(); ++it) |
---|
| 152 | { |
---|
| 153 | if (i == index) |
---|
| 154 | return (*it); |
---|
| 155 | ++i; |
---|
| 156 | } |
---|
| 157 | return 0; |
---|
| 158 | } |
---|
| 159 | |
---|
| 160 | void ControllableEntity::switchCamera() |
---|
| 161 | { |
---|
| 162 | if (this->camera_) |
---|
| 163 | { |
---|
| 164 | if (this->camera_->getParent() == this && this->cameraPositions_.size() > 0) |
---|
| 165 | { |
---|
| 166 | this->cameraPositions_.front()->attachCamera(this->camera_); |
---|
| 167 | } |
---|
| 168 | else if (this->cameraPositions_.size() > 0) |
---|
| 169 | { |
---|
| 170 | for (std::list<CameraPosition*>::const_iterator it = this->cameraPositions_.begin(); it != this->cameraPositions_.end(); ++it) |
---|
| 171 | { |
---|
| 172 | if ((*it) == this->camera_->getParent()) |
---|
| 173 | { |
---|
| 174 | ++it; |
---|
| 175 | if (it != this->cameraPositions_.end()) |
---|
| 176 | (*it)->attachCamera(this->camera_); |
---|
| 177 | else |
---|
| 178 | (*this->cameraPositions_.begin())->attachCamera(this->camera_); |
---|
| 179 | break; |
---|
| 180 | } |
---|
| 181 | } |
---|
| 182 | } |
---|
| 183 | else |
---|
| 184 | { |
---|
[2662] | 185 | this->camera_->attachToNode(this->cameraPositionRootNode_); |
---|
[2072] | 186 | } |
---|
| 187 | } |
---|
| 188 | } |
---|
| 189 | |
---|
[2662] | 190 | void ControllableEntity::mouseLook() |
---|
| 191 | { |
---|
| 192 | this->bMouseLook_ = !this->bMouseLook_; |
---|
| 193 | |
---|
| 194 | if (!this->bMouseLook_) |
---|
| 195 | this->cameraPositionRootNode_->setOrientation(Quaternion::IDENTITY); |
---|
| 196 | } |
---|
| 197 | |
---|
| 198 | void ControllableEntity::rotateYaw(const Vector2& value) |
---|
| 199 | { |
---|
| 200 | if (this->bMouseLook_) |
---|
| 201 | this->cameraPositionRootNode_->yaw(Radian(value.y * this->mouseLookSpeed_), Ogre::Node::TS_LOCAL); |
---|
| 202 | } |
---|
| 203 | |
---|
| 204 | void ControllableEntity::rotatePitch(const Vector2& value) |
---|
| 205 | { |
---|
| 206 | if (this->bMouseLook_) |
---|
| 207 | this->cameraPositionRootNode_->pitch(Radian(value.y * this->mouseLookSpeed_), Ogre::Node::TS_LOCAL); |
---|
| 208 | } |
---|
| 209 | |
---|
| 210 | void ControllableEntity::rotateRoll(const Vector2& value) |
---|
| 211 | { |
---|
| 212 | if (this->bMouseLook_) |
---|
| 213 | this->cameraPositionRootNode_->roll(Radian(value.y * this->mouseLookSpeed_), Ogre::Node::TS_LOCAL); |
---|
| 214 | } |
---|
| 215 | |
---|
[2072] | 216 | void ControllableEntity::setPlayer(PlayerInfo* player) |
---|
| 217 | { |
---|
| 218 | if (!player) |
---|
| 219 | { |
---|
| 220 | this->removePlayer(); |
---|
| 221 | return; |
---|
| 222 | } |
---|
| 223 | |
---|
| 224 | this->player_ = player; |
---|
| 225 | this->playerID_ = player->getObjectID(); |
---|
[2662] | 226 | this->bHasLocalController_ = player->isLocalPlayer(); |
---|
| 227 | this->bHasHumanController_ = player->isHumanPlayer(); |
---|
| 228 | |
---|
| 229 | if (this->bHasLocalController_ && this->bHasHumanController_) |
---|
[2072] | 230 | { |
---|
[2662] | 231 | this->startLocalHumanControl(); |
---|
[2072] | 232 | |
---|
[2896] | 233 | if (!GameMode::isMaster()) |
---|
[2072] | 234 | { |
---|
| 235 | this->client_overwrite_ = this->server_overwrite_; |
---|
[2662] | 236 | this->setObjectMode(objectDirection::bidirectional); |
---|
[2072] | 237 | } |
---|
| 238 | } |
---|
[2839] | 239 | |
---|
| 240 | this->changedPlayer(); |
---|
[2072] | 241 | } |
---|
| 242 | |
---|
| 243 | void ControllableEntity::removePlayer() |
---|
| 244 | { |
---|
[2662] | 245 | if (this->bHasLocalController_ && this->bHasHumanController_) |
---|
| 246 | this->stopLocalHumanControl(); |
---|
[2072] | 247 | |
---|
| 248 | this->player_ = 0; |
---|
[2171] | 249 | this->playerID_ = OBJECTID_UNKNOWN; |
---|
[2662] | 250 | this->bHasLocalController_ = false; |
---|
| 251 | this->bHasHumanController_ = false; |
---|
| 252 | this->setObjectMode(objectDirection::toclient); |
---|
[2072] | 253 | |
---|
[2839] | 254 | this->changedPlayer(); |
---|
| 255 | |
---|
[2072] | 256 | if (this->bDestroyWhenPlayerLeft_) |
---|
| 257 | delete this; |
---|
| 258 | } |
---|
| 259 | |
---|
| 260 | void ControllableEntity::networkcallback_changedplayerID() |
---|
| 261 | { |
---|
| 262 | // just do this in case the entity wasn't yet synchronized when the corresponding PlayerInfo got our objectID |
---|
[2171] | 263 | if (this->playerID_ != OBJECTID_UNKNOWN) |
---|
[2072] | 264 | { |
---|
[2171] | 265 | this->player_ = dynamic_cast<PlayerInfo*>(Synchronisable::getSynchronisable(this->playerID_)); |
---|
[2072] | 266 | if (this->player_ && (this->player_->getControllableEntity() != this)) |
---|
| 267 | this->player_->startControl(this); |
---|
| 268 | } |
---|
| 269 | } |
---|
| 270 | |
---|
[2662] | 271 | void ControllableEntity::startLocalHumanControl() |
---|
| 272 | { |
---|
| 273 | if (!this->camera_) |
---|
[2072] | 274 | { |
---|
[2662] | 275 | this->camera_ = new Camera(this); |
---|
| 276 | this->camera_->requestFocus(); |
---|
| 277 | if (this->cameraPositionTemplate_ != "") |
---|
| 278 | this->addTemplate(this->cameraPositionTemplate_); |
---|
| 279 | if (this->cameraPositions_.size() > 0) |
---|
| 280 | this->cameraPositions_.front()->attachCamera(this->camera_); |
---|
| 281 | else |
---|
| 282 | this->camera_->attachToNode(this->cameraPositionRootNode_); |
---|
[2072] | 283 | } |
---|
[2662] | 284 | |
---|
| 285 | if (!this->hud_) |
---|
| 286 | { |
---|
| 287 | if (this->hudtemplate_ != "") |
---|
| 288 | { |
---|
| 289 | this->hud_ = new OverlayGroup(this); |
---|
| 290 | this->hud_->addTemplate(this->hudtemplate_); |
---|
| 291 | this->hud_->setOwner(this); |
---|
| 292 | } |
---|
| 293 | } |
---|
[2072] | 294 | } |
---|
| 295 | |
---|
[2662] | 296 | void ControllableEntity::stopLocalHumanControl() |
---|
[2072] | 297 | { |
---|
[2662] | 298 | if (this->camera_) |
---|
| 299 | { |
---|
| 300 | this->camera_->detachFromParent(); |
---|
| 301 | delete this->camera_; |
---|
| 302 | this->camera_ = 0; |
---|
| 303 | } |
---|
[2072] | 304 | |
---|
[2662] | 305 | if (this->hud_) |
---|
| 306 | { |
---|
| 307 | delete this->hud_; |
---|
| 308 | this->hud_ = 0; |
---|
| 309 | } |
---|
[2072] | 310 | } |
---|
| 311 | |
---|
[3049] | 312 | void ControllableEntity::setXMLController(Controller* controller) |
---|
| 313 | { |
---|
| 314 | if (!this->xmlcontroller_) |
---|
| 315 | { |
---|
| 316 | this->xmlcontroller_ = controller; |
---|
| 317 | this->bHasLocalController_ = true; |
---|
| 318 | this->xmlcontroller_->setControllableEntity(this); |
---|
| 319 | } |
---|
| 320 | else |
---|
| 321 | COUT(2) << "Warning: ControllableEntity \"" << this->getName() << "\" already has a Controller." << std::endl; |
---|
| 322 | } |
---|
| 323 | |
---|
[2851] | 324 | void ControllableEntity::parentChanged() |
---|
| 325 | { |
---|
| 326 | WorldEntity::parentChanged(); |
---|
| 327 | |
---|
| 328 | WorldEntity* parent = this->getParent(); |
---|
| 329 | if (parent) |
---|
| 330 | { |
---|
| 331 | for (std::list<CameraPosition*>::iterator it = this->cameraPositions_.begin(); it != this->cameraPositions_.end(); ++it) |
---|
| 332 | if ((*it)->getIsAbsolute()) |
---|
| 333 | parent->attach((*it)); |
---|
| 334 | } |
---|
| 335 | } |
---|
| 336 | |
---|
[2072] | 337 | void ControllableEntity::tick(float dt) |
---|
| 338 | { |
---|
[2662] | 339 | MobileEntity::tick(dt); |
---|
| 340 | |
---|
[2072] | 341 | if (this->isActive()) |
---|
| 342 | { |
---|
[2662] | 343 | // Check whether Bullet doesn't do the physics for us |
---|
| 344 | if (!this->isDynamic()) |
---|
[2072] | 345 | { |
---|
[2896] | 346 | if (GameMode::isMaster()) |
---|
[2662] | 347 | { |
---|
| 348 | this->server_position_ = this->getPosition(); |
---|
| 349 | this->server_orientation_ = this->getOrientation(); |
---|
| 350 | this->server_linear_velocity_ = this->getVelocity(); |
---|
| 351 | this->server_angular_velocity_ = this->getAngularVelocity(); |
---|
| 352 | } |
---|
| 353 | else if (this->bHasLocalController_) |
---|
| 354 | { |
---|
| 355 | this->client_position_ = this->getPosition(); |
---|
| 356 | this->client_orientation_ = this->getOrientation(); |
---|
| 357 | this->client_linear_velocity_ = this->getVelocity(); |
---|
| 358 | this->client_angular_velocity_ = this->getAngularVelocity(); |
---|
| 359 | } |
---|
[2072] | 360 | } |
---|
| 361 | } |
---|
| 362 | } |
---|
| 363 | |
---|
| 364 | void ControllableEntity::registerVariables() |
---|
| 365 | { |
---|
[2662] | 366 | registerVariable(this->cameraPositionTemplate_, variableDirection::toclient); |
---|
| 367 | registerVariable(this->hudtemplate_, variableDirection::toclient); |
---|
[2072] | 368 | |
---|
[2662] | 369 | registerVariable(this->server_position_, variableDirection::toclient, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerPosition)); |
---|
| 370 | registerVariable(this->server_linear_velocity_, variableDirection::toclient, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerLinearVelocity)); |
---|
| 371 | registerVariable(this->server_orientation_, variableDirection::toclient, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerOrientation)); |
---|
| 372 | registerVariable(this->server_angular_velocity_, variableDirection::toclient, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerAngularVelocity)); |
---|
[2072] | 373 | |
---|
[2662] | 374 | registerVariable(this->server_overwrite_, variableDirection::toclient, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processOverwrite)); |
---|
| 375 | registerVariable(this->client_overwrite_, variableDirection::toserver); |
---|
[2072] | 376 | |
---|
[2662] | 377 | registerVariable(this->client_position_, variableDirection::toserver, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processClientPosition)); |
---|
| 378 | registerVariable(this->client_linear_velocity_, variableDirection::toserver, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processClientLinearVelocity)); |
---|
| 379 | registerVariable(this->client_orientation_, variableDirection::toserver, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processClientOrientation)); |
---|
| 380 | registerVariable(this->client_angular_velocity_, variableDirection::toserver, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processClientAngularVelocity)); |
---|
[3084] | 381 | |
---|
[2072] | 382 | |
---|
[2662] | 383 | registerVariable(this->playerID_, variableDirection::toclient, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::networkcallback_changedplayerID)); |
---|
[2072] | 384 | } |
---|
| 385 | |
---|
| 386 | void ControllableEntity::processServerPosition() |
---|
| 387 | { |
---|
[2662] | 388 | if (!this->bHasLocalController_) |
---|
| 389 | MobileEntity::setPosition(this->server_position_); |
---|
[2072] | 390 | } |
---|
| 391 | |
---|
[2662] | 392 | void ControllableEntity::processServerLinearVelocity() |
---|
[2072] | 393 | { |
---|
[2662] | 394 | if (!this->bHasLocalController_) |
---|
| 395 | MobileEntity::setVelocity(this->server_linear_velocity_); |
---|
[2072] | 396 | } |
---|
| 397 | |
---|
| 398 | void ControllableEntity::processServerOrientation() |
---|
| 399 | { |
---|
[2662] | 400 | if (!this->bHasLocalController_) |
---|
| 401 | MobileEntity::setOrientation(this->server_orientation_); |
---|
[2072] | 402 | } |
---|
| 403 | |
---|
[2662] | 404 | void ControllableEntity::processServerAngularVelocity() |
---|
| 405 | { |
---|
| 406 | if (!this->bHasLocalController_) |
---|
| 407 | MobileEntity::setAngularVelocity(this->server_angular_velocity_); |
---|
| 408 | } |
---|
| 409 | |
---|
[2072] | 410 | void ControllableEntity::processOverwrite() |
---|
| 411 | { |
---|
[2662] | 412 | if (this->bHasLocalController_) |
---|
[2072] | 413 | { |
---|
| 414 | this->setPosition(this->server_position_); |
---|
| 415 | this->setOrientation(this->server_orientation_); |
---|
[2662] | 416 | this->setVelocity(this->server_linear_velocity_); |
---|
| 417 | this->setAngularVelocity(this->server_angular_velocity_); |
---|
[2072] | 418 | |
---|
| 419 | this->client_overwrite_ = this->server_overwrite_; |
---|
| 420 | } |
---|
| 421 | } |
---|
| 422 | |
---|
| 423 | void ControllableEntity::processClientPosition() |
---|
| 424 | { |
---|
| 425 | if (this->server_overwrite_ == this->client_overwrite_) |
---|
| 426 | { |
---|
[2662] | 427 | MobileEntity::setPosition(this->client_position_); |
---|
| 428 | this->server_position_ = this->getPosition(); |
---|
[2072] | 429 | } |
---|
| 430 | } |
---|
| 431 | |
---|
[2662] | 432 | void ControllableEntity::processClientLinearVelocity() |
---|
[2072] | 433 | { |
---|
| 434 | if (this->server_overwrite_ == this->client_overwrite_) |
---|
| 435 | { |
---|
[2662] | 436 | MobileEntity::setVelocity(this->client_linear_velocity_); |
---|
| 437 | this->server_linear_velocity_ = this->getVelocity(); |
---|
[2072] | 438 | } |
---|
| 439 | } |
---|
| 440 | |
---|
| 441 | void ControllableEntity::processClientOrientation() |
---|
| 442 | { |
---|
| 443 | if (this->server_overwrite_ == this->client_overwrite_) |
---|
| 444 | { |
---|
[2662] | 445 | MobileEntity::setOrientation(this->client_orientation_); |
---|
| 446 | this->server_orientation_ = this->getOrientation(); |
---|
[2072] | 447 | } |
---|
| 448 | } |
---|
| 449 | |
---|
[2662] | 450 | void ControllableEntity::processClientAngularVelocity() |
---|
[2072] | 451 | { |
---|
[2662] | 452 | if (this->server_overwrite_ == this->client_overwrite_) |
---|
[2072] | 453 | { |
---|
[2662] | 454 | MobileEntity::setAngularVelocity(this->client_angular_velocity_); |
---|
| 455 | this->server_angular_velocity_ = this->getAngularVelocity(); |
---|
[2072] | 456 | } |
---|
| 457 | } |
---|
| 458 | |
---|
[2662] | 459 | void ControllableEntity::setPosition(const Vector3& position) |
---|
[2072] | 460 | { |
---|
[2896] | 461 | if (GameMode::isMaster()) |
---|
[2072] | 462 | { |
---|
[2662] | 463 | MobileEntity::setPosition(position); |
---|
| 464 | this->server_position_ = this->getPosition(); |
---|
[2072] | 465 | ++this->server_overwrite_; |
---|
| 466 | } |
---|
[2662] | 467 | else if (this->bHasLocalController_) |
---|
[2072] | 468 | { |
---|
[2662] | 469 | MobileEntity::setPosition(position); |
---|
| 470 | this->client_position_ = this->getPosition(); |
---|
[2072] | 471 | } |
---|
| 472 | } |
---|
| 473 | |
---|
| 474 | void ControllableEntity::setOrientation(const Quaternion& orientation) |
---|
| 475 | { |
---|
[2896] | 476 | if (GameMode::isMaster()) |
---|
[2072] | 477 | { |
---|
[2662] | 478 | MobileEntity::setOrientation(orientation); |
---|
| 479 | this->server_orientation_ = this->getOrientation(); |
---|
[2072] | 480 | ++this->server_overwrite_; |
---|
| 481 | } |
---|
[2662] | 482 | else if (this->bHasLocalController_) |
---|
[2072] | 483 | { |
---|
[2662] | 484 | MobileEntity::setOrientation(orientation); |
---|
| 485 | this->client_orientation_ = this->getOrientation(); |
---|
[2072] | 486 | } |
---|
| 487 | } |
---|
| 488 | |
---|
[2662] | 489 | void ControllableEntity::setVelocity(const Vector3& velocity) |
---|
[2072] | 490 | { |
---|
[2896] | 491 | if (GameMode::isMaster()) |
---|
[2072] | 492 | { |
---|
[2662] | 493 | MobileEntity::setVelocity(velocity); |
---|
| 494 | this->server_linear_velocity_ = this->getVelocity(); |
---|
[2072] | 495 | ++this->server_overwrite_; |
---|
| 496 | } |
---|
[2662] | 497 | else if (this->bHasLocalController_) |
---|
[2072] | 498 | { |
---|
[2662] | 499 | MobileEntity::setVelocity(velocity); |
---|
| 500 | this->client_linear_velocity_ = this->getVelocity(); |
---|
[2072] | 501 | } |
---|
| 502 | } |
---|
| 503 | |
---|
[2662] | 504 | void ControllableEntity::setAngularVelocity(const Vector3& velocity) |
---|
[2072] | 505 | { |
---|
[2896] | 506 | if (GameMode::isMaster()) |
---|
[2072] | 507 | { |
---|
[2662] | 508 | MobileEntity::setAngularVelocity(velocity); |
---|
| 509 | this->server_angular_velocity_ = this->getAngularVelocity(); |
---|
[2072] | 510 | ++this->server_overwrite_; |
---|
| 511 | } |
---|
[2662] | 512 | else if (this->bHasLocalController_) |
---|
[2072] | 513 | { |
---|
[2662] | 514 | MobileEntity::setAngularVelocity(velocity); |
---|
| 515 | this->client_angular_velocity_ = this->getAngularVelocity(); |
---|
[2072] | 516 | } |
---|
| 517 | } |
---|
| 518 | |
---|
[2662] | 519 | void ControllableEntity::setWorldTransform(const btTransform& worldTrans) |
---|
[2072] | 520 | { |
---|
[2662] | 521 | MobileEntity::setWorldTransform(worldTrans); |
---|
[2896] | 522 | if (GameMode::isMaster()) |
---|
[2072] | 523 | { |
---|
[2662] | 524 | this->server_position_ = this->getPosition(); |
---|
| 525 | this->server_orientation_ = this->getOrientation(); |
---|
| 526 | this->server_linear_velocity_ = this->getVelocity(); |
---|
| 527 | this->server_angular_velocity_ = this->getAngularVelocity(); |
---|
[2072] | 528 | } |
---|
[2662] | 529 | else if (this->bHasLocalController_) |
---|
[2072] | 530 | { |
---|
[2662] | 531 | this->client_position_ = this->getPosition(); |
---|
| 532 | this->client_orientation_ = this->getOrientation(); |
---|
| 533 | this->client_linear_velocity_ = this->getVelocity(); |
---|
| 534 | this->client_angular_velocity_ = this->getAngularVelocity(); |
---|
[2072] | 535 | } |
---|
| 536 | } |
---|
| 537 | } |
---|