void GameBase::processTick(const Move * move) { #ifdef TORQUE_DEBUG_NET_MOVES if (!move) mTicksSinceLastMove++; const char * srv = isClientObject() ? "client" : "server"; const char * who = ""; if (isClientObject()) { if (this == (GameBase*)GameConnection::getConnectionToServer()->getControlObject()) who = " player"; else who = " ghost"; if (mIsAiControlled) who = " ai"; } if (isServerObject()) { if (dynamic_cast<AIConnection*>(getControllingClient())) { who = " ai"; mIsAiControlled = true; } else if (getControllingClient()) { who = " player"; mIsAiControlled = false; } else { who = ""; mIsAiControlled = false; } } U32 moveid = mLastMoveId+mTicksSinceLastMove; if (move) moveid = move->id; if (getTypeMask() & GameBaseHiFiObjectType) { if (move) Con::printf("Processing (%s%s id %i) move %i",srv,who,getId(), move->id); else Con::printf("Processing (%s%s id %i) move %i (%i)",srv,who,getId(),mLastMoveId+mTicksSinceLastMove,mTicksSinceLastMove); } if (move) { mLastMoveId = move->id; mTicksSinceLastMove=0; } #endif }
bool Forest::onAdd() { if (!Parent::onAdd()) return false; const char *name = getName(); if(name && name[0] && getClassRep()) { Namespace *parent = getClassRep()->getNameSpace(); Con::linkNamespaces(parent->mName, name); mNameSpace = Con::lookupNamespace(name); } setGlobalBounds(); resetWorldBox(); // TODO: Make sure this calls the script "onAdd" which will // populate the object with forest entries before creation. addToScene(); // If we don't have a file name and the editor is // enabled then create an empty forest data file. if ( isServerObject() && ( !mDataFileName || !mDataFileName[0] ) ) createNewFile(); else { // Try to load the forest file. mData = ResourceManager::get().load( mDataFileName ); if ( !mData ) { if ( isClientObject() ) NetConnection::setLastError( "You are missing a file needed to play this mission: %s", mDataFileName ); return false; } } updateCollision(); smCreatedSignal.trigger( this ); if ( isClientObject() ) { mZoningDirty = true; SceneZoneSpaceManager::getZoningChangedSignal().notify( this, &Forest::_onZoningChanged ); ForestWindMgr::getAdvanceSignal().notify( this, &Forest::getLocalWindTrees ); } return true; }
//----------------------------------------------------------------------------- // onAdd //----------------------------------------------------------------------------- bool ParticleEmitterNode::onAdd() { if( !Parent::onAdd() ) return false; if( !mEmitterDatablock && mEmitterDatablockId != 0 ) { if( Sim::findObject(mEmitterDatablockId, mEmitterDatablock) == false ) Con::errorf(ConsoleLogEntry::General, "ParticleEmitterNode::onAdd: Invalid packet, bad datablockId(mEmitterDatablock): %d", mEmitterDatablockId); } if( isClientObject() ) { setEmitterDataBlock( mEmitterDatablock ); } else { setMaskBits( StateMask | EmitterDBMask ); } mObjBox.minExtents.set(-0.5, -0.5, -0.5); mObjBox.maxExtents.set( 0.5, 0.5, 0.5); resetWorldBox(); addToScene(); return true; }
void DecalRoad::_onTerrainChanged( U32 type, TerrainBlock* tblock, const Point2I &min, const Point2I &max ) { // The client side object just stores the area that has changed // and waits for the (delayed) update event from the server // to actually perform the update. if ( isClientObject() && tblock->isClientObject() ) { // Convert the min and max into world space. const F32 size = tblock->getSquareSize(); const Point3F pos = tblock->getPosition(); // TODO: I don't think this works right with tiling! Box3F dirty( F32( min.x * size ) + pos.x, F32( min.y * size ) + pos.y, -F32_MAX, F32( max.x * size ) + pos.x, F32( max.y * size ) + pos.y, F32_MAX ); if ( !mTerrainUpdateRect.isValidBox() ) mTerrainUpdateRect = dirty; else mTerrainUpdateRect.intersect( dirty ); } // The server object only updates edges (doesn't clip to geometry) // and schedules an update to be sent to the client. else if ( isServerObject() && tblock->isServerObject() ) { //_generateEdges(); scheduleUpdate( TerrainChangedMask ); } }
bool GroundPlane::onAdd() { if( !Parent::onAdd() ) return false; if( isClientObject() ) _updateMaterial(); if( mSquareSize < sMIN_SQUARE_SIZE ) { Con::errorf( "GroundPlane - squareSize below threshold; re-setting to %.02f", sMIN_SQUARE_SIZE ); mSquareSize = sMIN_SQUARE_SIZE; } Parent::setScale( VectorF( 1.0f, 1.0f, 1.0f ) ); Parent::setTransform( MatrixF::Identity ); setGlobalBounds(); resetWorldBox(); addToScene(); if ( PHYSICSMGR ) { PhysicsCollision *colShape = PHYSICSMGR->createCollision(); colShape->addPlane( PlaneF( Point3F::Zero, Point3F( 0, 0, 1 ) ) ); PhysicsWorld *world = PHYSICSMGR->getWorld( isServerObject() ? "server" : "client" ); mPhysicsRep = PHYSICSMGR->createBody(); mPhysicsRep->init( colShape, 0, 0, this, world ); } return true; }
bool VolumetricFog::onAdd() { if (!Parent::onAdd()) return false; if (!VFRTM->IsInitialized()) { Con::errorf("No VolumetricFogRTManager present!!"); return false; } resetWorldBox(); mShapeLoaded = LoadShape(); setRenderTransform(mObjToWorld); addToScene(); ColBox.set(getTransform(), (mObjBox.getExtents() * getScale() * COLBOX_SCALE)); mObjSize = mWorldBox.getGreatestDiagonalLength(); mObjScale = getScale(); mTexTiles = mAbs(mTexTiles); mSpeed.set(mSpeed1.x, mSpeed1.y, mSpeed2.x, mSpeed2.y); mInvScale = (1.0f / getMax(getMax(mObjScale.x, mObjScale.y), mObjScale.z)); if (isClientObject()) { InitTexture(); return setupRenderer(); } VFRTM->IncFogObjects(); return true; }
bool WaterObject::onAdd() { if ( !Parent::onAdd() ) return false; Con::NotifyDelegate clbk( this, &WaterObject::_onDisableTrueRelfections ); Con::addVariableNotify( "$pref::Water::disableTrueReflections", clbk ); if ( isClientObject() ) { GFXStateBlockDesc desc; desc.blendDefined = true; desc.blendEnable = true; desc.blendSrc = GFXBlendSrcAlpha; desc.blendDest = GFXBlendInvSrcAlpha; desc.zDefined = true; desc.zEnable = false; desc.cullDefined = true; desc.cullMode = GFXCullNone; mUnderwaterSB = GFX->createStateBlock( desc ); initTextures(); if ( mFullReflect && !smDisableTrueReflections ) mPlaneReflector.registerReflector( this, &mReflectorDesc ); } return true; }
bool LevelInfo::onAdd() { if ( !Parent::onAdd() ) return false; // If no sound ambience has been set, default to // 'AudioAmbienceDefault'. if( !mSoundAmbience ) Sim::findObject( "AudioAmbienceDefault", mSoundAmbience ); // Set up sound on client. if( isClientObject() ) { SFX->setDistanceModel( mSoundDistanceModel ); // Set up the global ambient soundscape. mSoundscape = SFX->getSoundscapeManager()->getGlobalSoundscape(); if( mSoundAmbience ) mSoundscape->setAmbience( mSoundAmbience ); } _updateSceneGraph(); return true; }
bool CloudLayer::onAdd() { if ( !Parent::onAdd() ) return false; setGlobalBounds(); resetWorldBox(); addToScene(); if ( isClientObject() ) { _initTexture(); _initBuffers(); // Find ShaderData ShaderData *shaderData; mShader = Sim::findObject( "CloudLayerShader", shaderData ) ? shaderData->getShader() : NULL; if ( !mShader ) { Con::errorf( "CloudLayer::onAdd - could not find CloudLayerShader" ); return false; } // Create ShaderConstBuffer and Handles mShaderConsts = mShader->allocConstBuffer(); mModelViewProjSC = mShader->getShaderConstHandle( "$modelView" ); mEyePosWorldSC = mShader->getShaderConstHandle( "$eyePosWorld" ); mSunVecSC = mShader->getShaderConstHandle( "$sunVec" ); mTexOffsetSC[0] = mShader->getShaderConstHandle( "$texOffset0" ); mTexOffsetSC[1] = mShader->getShaderConstHandle( "$texOffset1" ); mTexOffsetSC[2] = mShader->getShaderConstHandle( "$texOffset2" ); mTexScaleSC = mShader->getShaderConstHandle( "$texScale" ); mAmbientColorSC = mShader->getShaderConstHandle( "$ambientColor" ); mSunColorSC = mShader->getShaderConstHandle( "$sunColor" ); mCoverageSC = mShader->getShaderConstHandle( "$cloudCoverage" ); mExposureSC = mShader->getShaderConstHandle( "$cloudExposure" ); mBaseColorSC = mShader->getShaderConstHandle( "$cloudBaseColor" ); mNormalHeightMapSC = mShader->getShaderConstHandle( "$normalHeightMap" ); // Create StateBlocks GFXStateBlockDesc desc; desc.setCullMode( GFXCullNone ); desc.setBlend( true ); desc.setZReadWrite( false, false ); desc.samplersDefined = true; desc.samplers[0].addressModeU = GFXAddressWrap; desc.samplers[0].addressModeV = GFXAddressWrap; desc.samplers[0].addressModeW = GFXAddressWrap; desc.samplers[0].magFilter = GFXTextureFilterLinear; desc.samplers[0].minFilter = GFXTextureFilterLinear; desc.samplers[0].mipFilter = GFXTextureFilterLinear; desc.samplers[0].textureColorOp = GFXTOPModulate; mStateblock = GFX->createStateBlock( desc ); } return true; }
bool GroundPlane::onAdd() { if( !Parent::onAdd() ) return false; if( isClientObject() ) _updateMaterial(); if( mSquareSize < sMIN_SQUARE_SIZE ) { Con::errorf( "GroundPlane - squareSize below threshold; re-setting to %.02f", sMIN_SQUARE_SIZE ); mSquareSize = sMIN_SQUARE_SIZE; } setScale( VectorF( 1.0f, 1.0f, 1.0f ) ); setGlobalBounds(); resetWorldBox(); addToScene(); if( gPhysicsPlugin ) mPhysicsRep = gPhysicsPlugin->createStatic( this ); return true; }
void TimeOfDay::_updatePosition() { //// Full azimuth/elevation calculation. //// calculate sun decline and meridian angle (in radians) //F32 sunDecline = mSin( M_2PI * mTimeOfYear ) * mDegToRad( mAxisTilt ); //F32 meridianAngle = mTimeOfDay * M_2PI - mDegToRad( mLongitude ); //// calculate the elevation and azimuth (in radians) //mElevation = _calcElevation( mDegToRad( mLatitude ), sunDecline, meridianAngle ); //mAzimuth = _calcAzimuth( mDegToRad( mLatitude ), sunDecline, meridianAngle ); // Simplified azimuth/elevation calculation. // calculate sun decline and meridian angle (in radians) F32 sunDecline = mDegToRad( mAxisTilt ); F32 meridianAngle = mTimeOfDay * M_2PI; mPrevElevation = mNextElevation; // calculate the elevation and azimuth (in radians) mElevation = _calcElevation( 0.0f, sunDecline, meridianAngle ); mAzimuth = _calcAzimuth( 0.0f, sunDecline, meridianAngle ); if ( mFabs( mAzimuthOverride ) ) { mElevation = mDegToRad( mTimeOfDay * 360.0f ); mAzimuth = mAzimuthOverride; } mNextElevation = mElevation; // Only the client updates the sun position! if ( isClientObject() ) smTimeOfDayUpdateSignal.trigger( this, mTimeOfDay ); }
ProcessList* SceneObject::getProcessList() const { if ( isClientObject() ) return ClientProcessList::get(); else return ServerProcessList::get(); }
bool TimeOfDay::onAdd() { if ( !Parent::onAdd() ) return false; // The server initializes to the specified starting values. // The client initializes itself to the server time from // unpackUpdate. if ( isServerObject() ) { mTimeOfDay = mStartTimeOfDay; } // We don't use a bounds. setGlobalBounds(); resetWorldBox(); addToScene(); // Lets receive ghost events so we can resolve // the sun object. if ( isClientObject() ) NetConnection::smGhostAlwaysDone.notify( this, &TimeOfDay::_onGhostAlwaysDone ); if ( isServerObject() ) Con::executef( this, "onAdd" ); return true; }
void TimeOfDay::onRemove() { if ( isClientObject() ) NetConnection::smGhostAlwaysDone.remove( this, &TimeOfDay::_onGhostAlwaysDone ); removeFromScene(); Parent::onRemove(); }
void SceneSpace::onEditorEnable() { // If we haven't created a material for editor rendering yet, // try so now. if( isClientObject() && !mEditorRenderMaterial ) mEditorRenderMaterial = _createEditorRenderMaterial(); }
void ScatterSky::onRemove() { removeFromScene(); if ( isClientObject() ) TimeOfDay::getTimeOfDayUpdateSignal().remove( this, &ScatterSky::_updateTimeOfDay ); Parent::onRemove(); }
void AccumulationVolume::onRemove() { if ( isClientObject() ) { smAccuVolumes.remove(this); refreshVolumes(); } Parent::onRemove(); }
bool VolumetricFog::onAdd() { if (!Parent::onAdd()) return false; if (!VFRTM->IsInitialized()) { Con::errorf("No VolumetricFogRTManager present!!"); return false; } resetWorldBox(); mShapeLoaded = LoadShape(); setRenderTransform(mObjToWorld); addToScene(); ColBox.set(getTransform(), (mObjBox.getExtents() * getScale() * COLBOX_SCALE)); mObjSize = mWorldBox.getGreatestDiagonalLength(); mObjScale = getScale(); mTexTiles = mAbs(mTexTiles); mSpeed.set(mSpeed1.x, mSpeed1.y, mSpeed2.x, mSpeed2.y); mInvScale = (1.0f / getMax(getMax(mObjScale.x, mObjScale.y), mObjScale.z)); if (isClientObject()) { conn = GameConnection::getConnectionToServer(); if (!conn) { Con::errorf("VolumetricFog::onAdd - No Serverconnection"); return false; } glowFX = static_cast<PostEffect*>(Sim::findObject("VolFogGlowPostFx")); mOldLightRayStrength = Con::getFloatVariable("$LightRayPostFX::brightScalar",1.0f); GuiCanvas* cv = dynamic_cast<GuiCanvas*>(Sim::findObject("Canvas")); if (cv == NULL) { Con::errorf("VolumetricFog::onAdd - Canvas not found!!"); return false; } mPlatformWindow = cv->getPlatformWindow(); VolumetricFogRTManager::getVolumetricFogRTMResizeSignal().notify(this, &VolumetricFog::handleResize); GuiCanvas::getCanvasSizeChangeSignal().notify(this, &VolumetricFog::handleCanvasResize); InitTexture(); return setupRenderer(); } VFRTM->IncFogObjects(); return true; }
void RPGSpell::processTick( const Move* m ) { Parent::processTick(m); if (isClientObject()) return; _processServer(); _mTimePassed += TickMs; }
void SceneObject::addToScene() { if( mSceneManager ) return; if( isClientObject() ) gClientSceneGraph->addObjectToScene( this ); else gServerSceneGraph->addObjectToScene( this ); }
void ForestWindEmitter::setTransform( const MatrixF &mat ) { Parent::setTransform( mat ); // Force the client update! setMaskBits(0xffffffff); if ( isClientObject() ) _initWind(); }
void ScatterSky::_onSelected() { #ifdef TORQUE_DEBUG // Enable debug rendering on the light. if( isClientObject() ) mLight->enableDebugRendering( true ); #endif Parent::_onSelected(); }
void LightBase::_onUnselected() { #ifdef TORQUE_DEBUG // Disable debug rendering on the light. if( isClientObject() ) mLight->enableDebugRendering( false ); #endif Parent::_onUnselected(); }
//-------------------------------------------------------------------------- void Projectile::onCollision(const Point3F& hitPosition, const Point3F& hitNormal, SceneObject* hitObject) { // No client specific code should be placed or branched from this function if(isClientObject()) return; if (hitObject != NULL && isServerObject()) { mDataBlock->onCollision_callback( this, hitObject, mFadeValue, hitPosition, hitNormal ); } }
void AccumulationVolume::setTexture( const String& name ) { mTextureName = name; if ( isClientObject() && mTextureName.isNotEmpty() ) { mAccuTexture.set(mTextureName, &GFXDefaultStaticDiffuseProfile, "AccumulationVolume::mAccuTexture"); if ( mAccuTexture.isNull() ) Con::warnf( "AccumulationVolume::setTexture - Unable to load texture: %s", mTextureName.c_str() ); } refreshVolumes(); }
String NetObject::describeSelf() const { String desc = Parent::describeSelf(); if( isClientObject() ) desc += "|net: client"; else desc += "|net: server"; return desc; }
void ForestWindEmitter::updateMountPosition() { AssertFatal( isClientObject(), "ForestWindEmitter::updateMountPosition - This should only happen on the client!" ); if ( !mHasMount || !mMountObject ) return; MatrixF mat( true ); mat.setPosition( mMountObject->getPosition() ); Parent::setTransform( mat ); }
void Forest::updateCollision() { if ( !mData ) return; mData->buildPhysicsRep( this ); // Make the assumption that if collision needs // to be updated that the zoning probably changed too. if ( isClientObject() ) mZoningDirty = true; }
bool NavMesh::build() { if(mBuildThreaded) return buildThreaded(); // If we're running a local server, just steal the server's navmesh MutexHandle handle; if(!handle.lock(&mBuildLock, true) || isClientObject()) return false; return buildProcess(); }
void GameBase::setControllingClient(GameConnection* client) { if (isClientObject()) { if (mControllingClient) setControl_callback( 0 ); if (client) setControl_callback( 1 ); } mControllingClient = client; }