- Timestamp:
- Dec 10, 2008, 1:38:17 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/physics/src/orxonox/objects/worldentities/ControllableEntity.cc
r2300 r2374 57 57 this->bDestroyWhenPlayerLeft_ = false; 58 58 59 this-> acceleration_= Vector3::ZERO;60 61 this->server_ position_= Vector3::ZERO;62 this->client_ position_= Vector3::ZERO;63 this->server_ velocity_ = Vector3::ZERO;64 this->client_ velocity_ = Vector3::ZERO;65 this->server_ orientation_ = Quaternion::IDENTITY;66 this->client_ orientation_ = Quaternion::IDENTITY;59 this->server_position_ = Vector3::ZERO; 60 this->client_position_ = Vector3::ZERO; 61 this->server_linear_velocity_ = Vector3::ZERO; 62 this->client_linear_velocity_ = Vector3::ZERO; 63 this->server_orientation_ = Quaternion::IDENTITY; 64 this->client_orientation_ = Quaternion::IDENTITY; 65 this->server_angular_velocity_ = Vector3::ZERO; 66 this->client_angular_velocity_ = Vector3::ZERO; 67 67 68 68 this->registerVariables(); … … 226 226 void ControllableEntity::tick(float dt) 227 227 { 228 MovableEntity::tick(dt); 229 228 230 if (this->isActive()) 229 231 { 230 if (!this->isDynamic())231 {232 this->velocity_ += (dt * this->acceleration_);233 this->node_->translate(dt * this->velocity_, Ogre::Node::TS_LOCAL);234 }235 236 if (Core::isMaster())237 {238 this->server_velocity_ = this->velocity_;239 this->server_position_ = this->node_->getPosition();240 }241 else if (this->bControlled_)242 {243 // COUT(2) << "setting client position" << endl;244 this->client_velocity_ = this->velocity_;245 this->client_position_ = this->node_->getPosition();246 }247 232 } 248 233 } … … 252 237 REGISTERSTRING(this->cameraPositionTemplate_, network::direction::toclient); 253 238 254 REGISTERDATA(this->server_position_, network::direction::toclient, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerPosition)); 255 REGISTERDATA(this->server_velocity_, network::direction::toclient, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerVelocity)); 256 REGISTERDATA(this->server_orientation_, network::direction::toclient, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerOrientation)); 257 258 REGISTERDATA(this->server_overwrite_, network::direction::toclient, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processOverwrite)); 259 REGISTERDATA(this->client_overwrite_, network::direction::toserver); 260 261 REGISTERDATA(this->client_position_, network::direction::toserver, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processClientPosition)); 262 REGISTERDATA(this->client_velocity_, network::direction::toserver, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processClientVelocity)); 263 REGISTERDATA(this->client_orientation_, network::direction::toserver, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processClientOrientation)); 264 239 REGISTERDATA(this->server_position_, network::direction::toclient, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerPosition)); 240 REGISTERDATA(this->server_linear_velocity_, network::direction::toclient, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerLinearVelocity)); 241 REGISTERDATA(this->server_orientation_, network::direction::toclient, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerOrientation)); 242 REGISTERDATA(this->server_angular_velocity_, network::direction::toclient, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerAngularVelocity)); 243 244 REGISTERDATA(this->server_overwrite_, network::direction::toclient, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processOverwrite)); 245 REGISTERDATA(this->client_overwrite_, network::direction::toserver); 246 247 REGISTERDATA(this->client_position_, network::direction::toserver, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processClientPosition)); 248 REGISTERDATA(this->client_linear_velocity_, network::direction::toserver, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processClientLinearVelocity)); 249 REGISTERDATA(this->client_orientation_, network::direction::toserver, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processClientOrientation)); 250 REGISTERDATA(this->client_angular_velocity_, network::direction::toserver, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processClientAngularVelocity)); 265 251 266 252 REGISTERDATA(this->playerID_, network::direction::toclient, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::networkcallback_changedplayerID)); … … 270 256 { 271 257 if (!this->bControlled_) 272 this->node_->setPosition(this->server_position_); 273 } 274 275 void ControllableEntity::processServerVelocity() 276 { 277 if (!this->bControlled_) 278 this->velocity_ = this->server_velocity_; 258 { 259 //COUT(0) << "override with server position: " << this << std::endl; 260 this->setPosition(this->server_position_); 261 } 262 } 263 264 void ControllableEntity::processServerLinearVelocity() 265 { 266 if (!this->bControlled_) 267 this->setVelocity(this->server_linear_velocity_); 279 268 } 280 269 … … 282 271 { 283 272 if (!this->bControlled_) 284 this->node_->setOrientation(this->server_orientation_); 273 this->setOrientation(this->server_orientation_); 274 } 275 276 void ControllableEntity::processServerAngularVelocity() 277 { 278 if (!this->bControlled_) 279 this->setAngularVelocity(this->server_angular_velocity_); 285 280 } 286 281 287 282 void ControllableEntity::processOverwrite() 288 283 { 289 if (this->bControlled_) 290 { 291 this->setPosition(this->server_position_); 292 this->setVelocity(this->server_velocity_); 293 this->setOrientation(this->server_orientation_); 294 295 this->client_overwrite_ = this->server_overwrite_; 296 } 284 //if (this->bControlled_) 285 //{ 286 // COUT(0) << "complete override: " << this << std::endl; 287 // this->setPosition(this->server_position_); 288 // this->setVelocity(this->server_velocity_); 289 // this->setOrientation(this->server_orientation_); 290 291 // this->client_overwrite_ = this->server_overwrite_; 292 //} 297 293 } 298 294 299 295 void ControllableEntity::processClientPosition() 300 296 { 301 if (this->server_overwrite_ == this->client_overwrite_) 302 { 297 //if (this->server_overwrite_ == this->client_overwrite_) 298 if (!this->bControlled_) 299 { 300 //COUT(0) << "override with client position: " << this << std::endl; 303 301 // COUT(2) << "callback: setting client position" << endl; 304 this->node_->setPosition(this->client_position_); 305 this->server_position_ = this->client_position_; 306 } 307 // else 308 // COUT(2) << "callback: not setting client position" << endl; 309 } 310 311 void ControllableEntity::processClientVelocity() 312 { 313 if (this->server_overwrite_ == this->client_overwrite_) 314 { 315 this->velocity_ = this->client_velocity_; 316 this->server_velocity_ = this->client_velocity_; 302 this->setPosition(this->client_position_); 303 //this->server_position_ = this->client_position_; 304 } 305 //else 306 // COUT(2) << "callback: not setting client position" << endl; 307 } 308 309 void ControllableEntity::processClientLinearVelocity() 310 { 311 if (!this->bControlled_) 312 //if (this->server_overwrite_ == this->client_overwrite_) 313 { 314 this->setVelocity(this->client_linear_velocity_); 315 //this->server_velocity_ = this->client_velocity_; 317 316 } 318 317 } … … 320 319 void ControllableEntity::processClientOrientation() 321 320 { 322 if (this->server_overwrite_ == this->client_overwrite_) 323 { 324 this->node_->setOrientation(this->client_orientation_); 325 this->server_orientation_ = this->client_orientation_; 326 } 327 } 328 329 void ControllableEntity::positionChanged() 321 if (!this->bControlled_) 322 //if (this->server_overwrite_ == this->client_overwrite_) 323 { 324 this->setOrientation(this->client_orientation_); 325 //this->server_orientation_ = this->client_orientation_; 326 } 327 } 328 329 void ControllableEntity::processClientAngularVelocity() 330 { 331 if (!this->bControlled_) 332 //if (this->server_overwrite_ == this->client_overwrite_) 333 { 334 this->setAngularVelocity(this->client_angular_velocity_); 335 //this->server_velocity_ = this->client_velocity_; 336 } 337 } 338 339 void ControllableEntity::positionChanged(bool bContinuous) 330 340 { 331 341 if (Core::isMaster()) … … 340 350 } 341 351 342 void ControllableEntity::orientationChanged( )352 void ControllableEntity::orientationChanged(bool bContinuous) 343 353 { 344 354 if (Core::isMaster()) … … 353 363 } 354 364 355 void ControllableEntity:: velocityChanged()365 void ControllableEntity::linearVelocityChanged(bool bContinuous) 356 366 { 357 367 if (Core::isMaster()) 358 368 { 359 this->server_ velocity_ = this->getVelocity();369 this->server_linear_velocity_ = this->getVelocity(); 360 370 ++this->server_overwrite_; 361 371 } 362 372 else if (this->bControlled_) 363 373 { 364 this->client_velocity_ = this->getVelocity(); 374 this->client_linear_velocity_ = this->getVelocity(); 375 } 376 } 377 378 void ControllableEntity::angularVelocityChanged(bool bContinuous) 379 { 380 if (Core::isMaster()) 381 { 382 this->server_angular_velocity_ = this->getAngularVelocity(); 383 ++this->server_overwrite_; 384 } 385 else if (this->bControlled_) 386 { 387 this->client_angular_velocity_ = this->getAngularVelocity(); 365 388 } 366 389 }
Note: See TracChangeset
for help on using the changeset viewer.