void *DataChunker::alloc(S32 size) { if (size > mChunkSize) { DataBlock * temp = (DataBlock*)dMalloc(DataChunker::PaddDBSize + size); AssertFatal(temp, "Malloc failed"); constructInPlace(temp); if (mCurBlock) { temp->next = mCurBlock->next; mCurBlock->next = temp; } else { mCurBlock = temp; temp->curIndex = mChunkSize; } return temp->getData(); } if(!mCurBlock || size + mCurBlock->curIndex > mChunkSize) { const U32 paddDBSize = (sizeof(DataBlock) + 3) & ~3; DataBlock *temp = (DataBlock*)dMalloc(paddDBSize+ mChunkSize); AssertFatal(temp, "Malloc failed"); constructInPlace(temp); temp->next = mCurBlock; mCurBlock = temp; } void *ret = mCurBlock->getData() + mCurBlock->curIndex; mCurBlock->curIndex += (size + 3) & ~3; // dword align return ret; }
void CAlly::refreshAlly(bool isFire) { BYTE buf[zSocket::MAX_DATASIZE]; Cmd::Session::_allyItem* tempItem = NULL; Cmd::Session::t_updateAlly_SceneSession* send = (Cmd::Session::t_updateAlly_SceneSession*)buf; constructInPlace(send); tempItem = (Cmd::Session::_allyItem*)send->data; send->dwSize = 0; if (isFire) { tempItem->dwCountryID = this->dwCountryID; tempItem->dwAllyCountryID = this->dwAllyCountryID; tempItem->dwFriendDegree = 0; } else { tempItem->dwCountryID = this->dwCountryID; tempItem->dwAllyCountryID = this->dwAllyCountryID; tempItem->dwFriendDegree = this->friendDegree(); } send->dwSize++; SessionTaskManager::getInstance().broadcastScene(send,send->dwSize*sizeof(Cmd::Session::_allyItem) + sizeof(Cmd::Session::t_updateAlly_SceneSession)); }
RenderPassManager::RenderPassManager() { mSceneManager = NULL; VECTOR_SET_ASSOCIATION( mRenderBins ); mMatrixSet = reinterpret_cast<MatrixSet *>(dMalloc_aligned(sizeof(MatrixSet), 16)); constructInPlace(mMatrixSet); }
CollisionWorkingList* CollisionWorkingList::alloc() { if (sFreeList.wLink.mNext != &sFreeList) { CollisionWorkingList* nxt = sFreeList.wLink.mNext; nxt->unlink(); return nxt; } return constructInPlace((CollisionWorkingList*)sChunker.alloc(sizeof(CollisionWorkingList))); }
CollisionStateList* CollisionStateList::alloc() { if (!sFreeList.isEmpty()) { CollisionStateList* nxt = sFreeList.mNext; nxt->unlink(); nxt->mState = NULL; return nxt; } return constructInPlace((CollisionStateList*)sChunker.alloc(sizeof(CollisionStateList))); }
/** * \brief 菜单 * * 重载了done函数,设置用户访问的npc的任务菜单 * * \param user: 触发动作的用户 * \param vars: 用户所带的该任务相关变量 * \return SUCCESS表示成功,FAILED表示失败,DISABLE表示禁用某项功能 */ int MainMenuAction::done (SceneUser* user,Vars* vars) { BYTE buf[x_socket::MAX_DATASIZE]; Cmd::stVisitNpcTradeUserCmd *cmd=(Cmd::stVisitNpcTradeUserCmd *)buf; bzero(buf,sizeof(buf)); constructInPlace(cmd); strcpy(cmd->menuTxt,_menu.c_str()); cmd->byReturn = 1; user->sendCmdToMe(cmd,sizeof(Cmd::stVisitNpcTradeUserCmd) + strlen(cmd->menuTxt)); return Action::SUCCESS; }
bool SessionChannel::sendCmdToZone(DWORD zone, const void* cmd, int len) { if(!cmd) return false; BYTE buf[zSocket::MAX_DATASIZE]; bzero(buf, sizeof(buf)); Cmd::Super::t_ForwardMsg_Scene *send = (Cmd::Super::t_ForwardMsg_Scene *)buf; constructInPlace(send); send->toGameZone.id = zone; send->size = len; bcopy(cmd, send->msg, len); SessionService::getInstance().sendCmdToSuperServer(send, sizeof(Cmd::Super::t_ForwardMsg_Scene)+len); return true; }
/** * \brief 脚本接口,弹出对话框 * * \param npc : 对话的npc * \param menu : 对话框内容 */ void show_dialog(SceneNpc* npc,const char* menu) { BYTE buf[4096]; Cmd::stVisitNpcTradeUserCmd *cmd=(Cmd::stVisitNpcTradeUserCmd *)buf; memset(buf,0,sizeof(buf)); constructInPlace(cmd); strncpy(cmd->menuTxt,menu,strlen(menu)); if (npc && NpcTrade::getInstance().getNpcMenu(npc->id,cmd->menuTxt+strlen(menu))) { //intended to be blank } cmd->byReturn = 1; if (current_user) { current_user->sendCmdToMe(cmd,sizeof(Cmd::stVisitNpcTradeUserCmd) + strlen(cmd->menuTxt)); } }
void Top100::send(MiniUser *u) { if (!u || !top100.size()) return; char buf[x_socket::MAX_DATASIZE]; bzero(buf,sizeof(buf)); Cmd::stRetTopCommonMiniGameCmd * cmd = (Cmd::stRetTopCommonMiniGameCmd *)buf; constructInPlace(cmd); top_iter it = top100.begin(); for (DWORD i=0; i<top100.size() && i<=100; i++,it++) { cmd->data[cmd->num] = *it; cmd->num++; } u->sendCmdToMe(cmd,sizeof(Cmd::stRetTopCommonMiniGameCmd)+sizeof(Cmd::MiniUserData)*cmd->num); }
void SFX3DWorld::setListener( SceneObject* object ) { SFX3DObject* oldListener = mSFXWorld.getReferenceObject(); // If it's the same object as our current listener, // return. if( oldListener && oldListener->getObject() == object ) return; // Create a SFX3DObject for the given SceneObject. SFX3DObject* sfxObject = NULL; if( object ) { AssertFatal( !dynamic_cast< SFX3DObject* >( SFX3DObject::getLinkForTracker( this, object ) ), "SFX3DWorld::setListener - listener objects must not be registered for tracking" ); sfxObject = mChunker.alloc(); constructInPlace( sfxObject, this, object ); sfxObject->setFlags( SFXObjectListener ); } #ifdef DEBUG_SPEW if( object ) Platform::outputDebugString( "[SFX3DWorld] Listener is now %i:%s (%s)", object->getId(), object->getClassName(), object->getName() ); else Platform::outputDebugString( "[SFX3DWorld] Unsetting listener" ); #endif // Make this object the center of our SFX world. mSFXWorld.setReferenceObject( sfxObject ); // Remove the tracking links from the old listener so we // don't see further updates on it. if( oldListener ) { destructInPlace( oldListener ); mChunker.free( oldListener ); } }
SkyBox::SkyBox() { mTypeMask |= EnvironmentObjectType | StaticObjectType; mNetFlags.set(Ghostable | ScopeAlways); mMatName = ""; mMatInstance = NULL; mIsVBDirty = false; mDrawBottom = true; mPrimCount = 0; mFogBandHeight = 0; mMatrixSet = reinterpret_cast<MatrixSet *>(dMalloc_aligned(sizeof(MatrixSet), 16)); constructInPlace(mMatrixSet); mFogBandMat = NULL; mFogBandMatInst = NULL; }
void SFX3DWorld::registerObject( SceneObject* object ) { if( !_isTrackableObject( object ) ) return; // Construct a new scene object link. SFX3DObject* sfxObject = mChunker.alloc(); constructInPlace( sfxObject, this, object ); // Register it with the SFX world. #ifdef DEBUG_SPEW Platform::outputDebugString( "[SFX3DWorld] Registering %i:%s as 0x%x", object->getId(), object->getClassName(), sfxObject ); #endif mSFXWorld.registerObject( sfxObject ); }
Sun::Sun() { mNetFlags.set(Ghostable | ScopeAlways); mTypeMask = EnvironmentObjectType | LightObjectType | StaticObjectType; mLightColor.set(0.7f, 0.7f, 0.7f); mLightAmbient.set(0.3f, 0.3f, 0.3f); mBrightness = 1.0f; mSunAzimuth = 0.0f; mSunElevation = 35.0f; mCastShadows = true; mStaticRefreshFreq = 250; mDynamicRefreshFreq = 8; mAnimateSun = false; mTotalTime = 0.0f; mCurrTime = 0.0f; mStartAzimuth = 0.0f; mEndAzimuth = 0.0f; mStartElevation = 0.0f; mEndElevation = 0.0f; mLight = LightManager::createLightInfo(); mLight->setType( LightInfo::Vector ); mFlareData = NULL; mFlareState.clear(); mFlareScale = 1.0f; mCoronaEnabled = true; mCoronaScale = 0.5f; mCoronaTint.set( 1.0f, 1.0f, 1.0f, 1.0f ); mCoronaUseLightColor = true; mCoronaMatInst = NULL; mMatrixSet = reinterpret_cast<MatrixSet *>(dMalloc_aligned(sizeof(MatrixSet), 16)); constructInPlace(mMatrixSet); mCoronaWorldRadius = 0.0f; mLightWorldPos = Point3F::Zero; }
ScatterSky::ScatterSky() { mPrimCount = 0; mVertCount = 0; // Rayleigh scattering constant. mRayleighScattering = 0.0035f; mRayleighScattering4PI = mRayleighScattering * 4.0f * M_PI_F; // Mie scattering constant. mMieScattering = 0.0045f; mMieScattering4PI = mMieScattering * 4.0f * M_PI_F; // Overall scatter scalar. mSkyBrightness = 25.0f; // The Mie phase asymmetry factor. mMiePhaseAssymetry = -0.75f; mSphereInnerRadius = 1.0f; mSphereOuterRadius = 1.0f * 1.025f; mScale = 1.0f / (mSphereOuterRadius - mSphereInnerRadius); // 650 nm for red // 570 nm for green // 475 nm for blue mWavelength.set( 0.650f, 0.570f, 0.475f, 0 ); mWavelength4[0] = mPow(mWavelength[0], 4.0f); mWavelength4[1] = mPow(mWavelength[1], 4.0f); mWavelength4[2] = mPow(mWavelength[2], 4.0f); mRayleighScaleDepth = 0.25f; mMieScaleDepth = 0.1f; mAmbientColor.set( 0, 0, 0, 1.0f ); mAmbientScale.set( 1.0f, 1.0f, 1.0f, 1.0f ); mSunColor.set( 0, 0, 0, 1.0f ); mSunScale = ColorF::WHITE; mFogColor.set( 0, 0, 0, 1.0f ); mFogScale = ColorF::WHITE; mExposure = 1.0f; mNightInterpolant = 0; mShader = NULL; mTimeOfDay = 0; mSunAzimuth = 0.0f; mSunElevation = 35.0f; mMoonAzimuth = 0.0f; mMoonElevation = 45.0f; mBrightness = 1.0f; mCastShadows = true; mDirty = true; mLight = LightManager::createLightInfo(); mLight->setType( LightInfo::Vector ); mFlareData = NULL; mFlareState.clear(); mFlareScale = 1.0f; mMoonEnabled = true; mMoonScale = 0.2f; mMoonTint.set( 0.192157f, 0.192157f, 0.192157f, 1.0f ); MathUtils::getVectorFromAngles( mMoonLightDir, 0.0f, 45.0f ); mMoonLightDir.normalize(); mMoonLightDir = -mMoonLightDir; mNightCubemap = NULL; mNightColor.set( 0.0196078f, 0.0117647f, 0.109804f, 1.0f ); mNightFogColor = mNightColor; mUseNightCubemap = false; mSunSize = 1.0f; mMoonMatInst = NULL; mNetFlags.set( Ghostable | ScopeAlways ); mTypeMask |= EnvironmentObjectType | LightObjectType | StaticObjectType; _generateSkyPoints(); mMatrixSet = reinterpret_cast<MatrixSet *>(dMalloc_aligned(sizeof(MatrixSet), 16)); constructInPlace(mMatrixSet); mColorizeAmt = 0; mColorize.set(0,0,0); }
WaterObject::WaterObject() : mViscosity( 1.0f ), mDensity( 1.0f ), mReflectivity( 0.5f ), mReflectNormalUp( true ), mDistortStartDist( 0.1f ), mDistortEndDist( 20.0f ), mDistortFullDepth( 3.5f ), mUndulateMaxDist(50.0f), mOverallFoamOpacity( 1.0f ), mFoamMaxDepth( 2.0f ), mFoamAmbientLerp( 0.5f ), mFoamRippleInfluence( 0.05f ), mUnderwaterPostFx( NULL ), mLiquidType( "Water" ), mFresnelBias( 0.3f ), mFresnelPower( 6.0f ), mClarity( 0.5f ), mBasicLighting( false ), mMiscParamW( 0.0f ), mOverallWaveMagnitude( 1.0f ), mOverallRippleMagnitude( 0.1f ), mCubemap( NULL ), mSoundAmbience( NULL ), mSpecularPower( 48.0f ), mSpecularColor( 1.0f, 1.0f, 1.0f, 1.0f ), mDepthGradientMax( 50.0f ), mEmissive( false ), mUnderwaterColor(9, 6, 5, 240) { mTypeMask = WaterObjectType | StaticObjectType; for( U32 i=0; i < MAX_WAVES; i++ ) { mRippleDir[i].set( 0.0f, 0.0f ); mRippleSpeed[i] = 0.0f; mRippleTexScale[i].set( 0.0f, 0.0f ); mWaveDir[i].set( 0.0f, 0.0f ); mWaveSpeed[i] = 0.0f; mWaveMagnitude[i] = 0.0f; } for ( U32 i = 0; i < MAX_FOAM; i++ ) { mFoamDir[i].set( 0.0f, 0.0f ); mFoamSpeed[i] = 0.0f; mFoamTexScale[i].set( 0.0f, 0.0f ); mFoamOpacity[i] = 0.0f; } mFoamDir[0].set( 1, 0 ); mFoamDir[1].set( 0, 1 ); mFoamTexScale[0].set( 1, 1 ); mFoamTexScale[1].set( 3, 3 ); mRippleMagnitude[0] = 1.0f; mRippleMagnitude[1] = 1.0f; mRippleMagnitude[2] = 0.3f; mWaterFogData.density = 0.1f; mWaterFogData.densityOffset = 1.0f; mWaterFogData.wetDepth = 1.5f; mWaterFogData.wetDarkening = 0.2f; mWaterFogData.color = ColorI::BLUE; mSurfMatName[WaterMat] = "WaterMat"; mSurfMatName[UnderWaterMat] = "UnderWaterMat"; mSurfMatName[BasicWaterMat] = "WaterBasicMat"; mSurfMatName[BasicUnderWaterMat] = "UnderWaterBasicMat"; dMemset( mMatInstances, 0, sizeof(mMatInstances) ); mWaterPos.set( 0,0,0 ); mWaterPlane.set( mWaterPos, Point3F(0,0,1) ); mGenerateVB = true; mMatrixSet = reinterpret_cast<MatrixSet *>(dMalloc_aligned(sizeof(MatrixSet), 16)); constructInPlace(mMatrixSet); }
/** * \brief 发送简单社会关系列表 */ void CRelationManager::sendRelationList() { BYTE buf[x_socket::MAX_DATASIZE]; DWORD count; Cmd::stRelation *tempPoint; //rwlock.rdlock(); Cmd::stSendRelationListCmd *retCmd=(Cmd::stSendRelationListCmd *)buf; constructInPlace(retCmd); tempPoint = (Cmd::stRelation *)retCmd->member; count = 0; for(zEntryName::hashmap::iterator it=zEntryName::ets.begin();it!=zEntryName::ets.end();it++) { CRelation *temp=(CRelation *)it->second; tempPoint->level = temp->level; if (temp->online) { UserSession *pUser = UserSessionManager::getInstance()->getUserByID(temp->id); if (pUser) { tempPoint->user_level = pUser->level; tempPoint->exploit = pUser->dwExploit; tempPoint->country = pUser->country; CUnion* pUnion = CUnionM::getMe().getUnionByID(pUser->unionid); if (pUnion) { strncpy(tempPoint->unionName,pUnion->name,MAX_NAMESIZE); } else { bzero(tempPoint->unionName,MAX_NAMESIZE); } } } else { bzero(tempPoint->unionName,MAX_NAMESIZE); tempPoint->user_level = 0; tempPoint->exploit = 0; tempPoint->country = 0; } tempPoint->online = temp->isOnline(); tempPoint->type = temp->type; tempPoint->occupation = temp->occupation; strncpy(tempPoint->name,temp->name,MAX_NAMESIZE); tempPoint++; count++; if (400==count) { goto breakRation; // 当记录超过100的时候会超过命令发送的最大限制 } } breakRation: //rwlock.unlock(); retCmd->size = count; user->sendCmdToMe(retCmd,(count*sizeof(Cmd::stRelation)+sizeof(Cmd::stSendRelationListCmd))); }