DiK2Pos ArMoveProperty::GetIntersectionLineRound(const DiK2Pos& linePos1, const DiK2Pos& linePos2, const DiK2Pos& roundCenter, float fRadius) { DI_ASSERT(linePos1.Distance(roundCenter) >= fRadius); DI_ASSERT(linePos2.Distance(roundCenter) <= fRadius); DiVec3 vLinePos1(linePos1.x, 0.0f, linePos1.z); DiVec3 vLinePos2(linePos2.x, 0.0f, linePos2.z); DiVec3 vRoundCenter(roundCenter.x, 0.0f, roundCenter.z); vLinePos1 -= vRoundCenter; vLinePos2 -= vRoundCenter; DiVec3 vRotation1 = vLinePos1 - vLinePos2; vRotation1.normalise(); DiVec3 vRotation2(1.0f, 0.0f, 0.0f); vRotation2.normalise(); DiQuat quaternion = vRotation1.getRotationTo(vRotation2); vLinePos1 = quaternion*vLinePos1; vLinePos2 = quaternion*vLinePos2; float x = fRadius*fRadius - vLinePos1.z*vLinePos1.z; x = (float)sqrt(x); if (vLinePos1.x < vLinePos2.x) x = -x; DiVec3 vFinalPos(x, 0.0f, vLinePos1.z); DiQuat quaternion2 = vRotation2.getRotationTo(vRotation1); vFinalPos = quaternion2*vFinalPos; vFinalPos += vRoundCenter; DiK2Pos intersection(vFinalPos.x, vFinalPos.z); return intersection; }
void* DiD3D9TextureDrv::LockLevel(uint32 level, uint32 &pitch, uint32 surface) { void *buffer = nullptr; if (mTexture) { if (mParent->GetTextureType() == TEXTURE_2D) { DI_ASSERT(surface == 0); IDirect3DTexture9* tex2D = static_cast<IDirect3DTexture9*>(mTexture); D3DLOCKED_RECT lockedRect; HRESULT result = tex2D->LockRect((DWORD)level, &lockedRect, 0, D3DLOCK_NOSYSLOCK); DX9_CHKERR(result); if (result == D3D_OK) { buffer = lockedRect.pBits; pitch = (uint32)lockedRect.Pitch; } } else if (mParent->GetTextureType() == TEXTURE_CUBE) { DI_ASSERT(surface >= 0 && surface <= 5); IDirect3DCubeTexture9* texCUBE = static_cast<IDirect3DCubeTexture9*>(mTexture); D3DLOCKED_RECT lockedRect; HRESULT result = texCUBE->LockRect((D3DCUBEMAP_FACES)surface, (DWORD)level, &lockedRect, 0, D3DLOCK_NOSYSLOCK); DX9_CHKERR(result); if (result == D3D_OK) { buffer = lockedRect.pBits; pitch = (uint32)lockedRect.Pitch; } } } return buffer; }
void DiD3D9TextureDrv::CreateTexture() { mD3DUsage = 0; mPool = D3DPOOL_MANAGED; if (mParent->GetResourceUsage() & RU_DYNAMIC) { mD3DUsage = D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY; mPool = D3DPOOL_DEFAULT; } if (mParent->GetUsage() & TU_DEPTH_STENCIL) { mD3DUsage |= D3DUSAGE_DEPTHSTENCIL; mPool = D3DPOOL_DEFAULT; } if (mParent->GetUsage() & TU_RENDER_TARGET) { mD3DUsage |= D3DUSAGE_RENDERTARGET; mPool = D3DPOOL_DEFAULT; } uint32 width = mParent->GetWidth(); uint32 height = mParent->GetHeight(); uint32 numLevels = mParent->GetNumLevels(); DiPixelFormat fmt = mParent->GetFormat(); D3DFORMAT d3dfmt = DiD3D9Mappings::D3D9FormatMapping[fmt]; if (mD3DUsage & D3DUSAGE_DEPTHSTENCIL) { mTexture = nullptr; mSurface = DiD3D9Driver::CreateDepthStencil(width, height, d3dfmt); DI_ASSERT(mSurface); DI_DEBUG("D3D9 Depth stencil buffer created: (%d,%d), ptr:%x", width, height, (void*)mSurface); } else { if (mParent->GetTextureType() == TEXTURE_2D) { IDirect3DTexture9* tex2D = DiD3D9Driver::CreateTexture(width, height, numLevels, mD3DUsage, d3dfmt, mPool); DI_ASSERT(tex2D); tex2D->GetSurfaceLevel(0, &mSurface); mTexture = tex2D; DI_DEBUG("D3D9 2D texture created: (%d,%d), pool:%d, usage:%d, ptr:%x", width, height, mPool, mD3DUsage, (void*)tex2D); } else if (mParent->GetTextureType() == TEXTURE_CUBE) { DI_ASSERT(width == height); IDirect3DCubeTexture9* texCUBE = DiD3D9Driver::CreateCubeTexture(width, numLevels, mD3DUsage, d3dfmt, mPool); DI_ASSERT(texCUBE); mTexture = texCUBE; mSurface = nullptr; } } }
DiConsoleVar* DiCommandManager::GetConsoleVar(const DiString& varName) { DI_ASSERT(this); DI_ASSERT(varName); auto it = mMapVariables.find(varName); if(it != mMapVariables.end()) return it->second; return nullptr; }
DiQuat RotationalSpline::Interpolate(unsigned int fromIndex, float t, bool useShortestPath) { DI_ASSERT (fromIndex >= 0 && fromIndex < mPoints.size()); if ((fromIndex + 1) == mPoints.size()) { return mPoints[fromIndex]; } if (t == 0.0f) { return mPoints[fromIndex]; } else if(t == 1.0f) { return mPoints[fromIndex + 1]; } DiQuat &p = mPoints[fromIndex]; DiQuat &q = mPoints[fromIndex+1]; DiQuat &a = mTangents[fromIndex]; DiQuat &b = mTangents[fromIndex+1]; return DiQuat::Squad(t, p, a, b, q, useShortestPath); }
void DiRenderWindow::Create(DiWndHandle hwnd) { DI_ASSERT(hwnd); mWndHandle = hwnd; Init(); }
uint32 DiInstanceBatchHardware::UpdateVertexBuffer( DiCamera *currentCamera ) { size_t retVal = 0; DiVertexBuffer* vb = mSourceData.back(); float *pDest = static_cast<float*>(vb->Lock(0,vb->GetBufferSize())); InstancedModelVec::const_iterator itor = mInstancedModels.begin(); InstancedModelVec::const_iterator end = mInstancedModels.end(); while( itor != end ) { if( (*itor)->IsInUse()/* && (*itor)->FindVisible( currentCamera )*/ ) { const size_t floatsWritten = (*itor)->GetTransforms3x4( pDest ); pDest += floatsWritten; ++retVal; } ++itor; } vb->Unlock(); DI_ASSERT(mSourceData.size() > 1); for (size_t i=0; i < mSourceData.size()-1; i++) { mSourceData[i]->SetInstanceNum(retVal); } return retVal; }
void DiGLFrameBuffer::DetarchSurface(uint32 attachment) { DI_ASSERT(attachment < MAX_MRT); mColorBuffer[attachment].reset(); if (mColorBuffer[attachment]) Init(); }
DiInstanceBatch::DiInstanceBatch( DiInstanceManager*creator, DiMeshPtr meshReference, DiMotionPtr motionReference, const DiMaterialPtr &material, size_t instancesPerBatch, const DiSubMesh::IndexMap *indexToBoneMap, const DiString &batchName ) :mInstancesPerBatch( instancesPerBatch ), mCreator( creator ), mMeshReference( meshReference ), mMotionReference( motionReference ), mIndexToBoneMap( indexToBoneMap ), mBoundsDirty( false ), mBoundsUpdated( false ), mCurrentCamera( 0 ), mTechnSupportsSkeletal( true ), mCachedCamera( 0 ), mTransformSharingDirty(true), mRemoveOwnVertexData(false), mRemoveOwnIndexData(false), mAddToBatch(false) { mMaterial = material; DI_ASSERT(mInstancesPerBatch); mFullBoundingBox.SetExtents( -DiVec3::ZERO, DiVec3::ZERO ); mPrimitiveType = PT_TRIANGLELIST; mName = batchName; }
void DiCullNode::AttachSilently(DiTransUnitPtr obj) { DI_ASSERT(!mObjectsByName.contains(obj->GetName())); mObjectsByName.insert(ObjectMap::value_type(obj->GetName(), obj)); NeedUpdate(); }
void DiInstanceManager::SetSetting( BatchSettingId id, bool value, const DiString& materialName /*= DiString::BLANK */ ) { DI_ASSERT( id < NUM_SETTINGS ); if( materialName == DiString::BLANK ) { InstanceBatchMap::iterator itor = mInstanceBatches.begin(); InstanceBatchMap::iterator end = mInstanceBatches.end(); while( itor != end ) { mBatchSettings[itor->first].setting[id] = value; ApplySettingToBatches( id, value, itor->second ); ++itor; } } else { mBatchSettings[materialName].setting[id] = value; InstanceBatchMap::const_iterator itor = mInstanceBatches.find( materialName ); if( itor != mInstanceBatches.end() ) { ApplySettingToBatches( id, value, itor->second ); } } }
void DiK2BillboardConfig::Load(DiXMLElement& element) { DI_ASSERT(element.CheckName("billboard")); element.GetInt("expirelife", expirelife); element.GetAttribute("bone", bone); element.GetInt("delay", delay); element.GetVector3("position", position); element.GetInt("life", life); element.GetColor("color", color); element.GetColor("startcolor", startcolor); element.GetColor("midcolor", midcolor); element.GetColor("endcolor", endcolor); element.GetInt("size", size); element.GetFloat("rollspeed", rollspeed); element.GetInt("depthbias", depthbias); element.GetAttribute("material", material); element.GetAttribute("directionalspace", directionalspace); element.GetInt("yaw", yaw); element.GetInt("pitch", pitch); element.GetInt("roll", roll); element.GetBool("lockup", lockup); element.GetBool("lockright", lockright); element.GetFloat("minheight", minheight); element.GetFloat("minheight", minheight); }
void DiK2SimpleEmitterConfig::Load(DiXMLElement& element) { DI_ASSERT(element.CheckName("simpleemitter")); element.GetInt("delay", delay); element.GetAttribute("bone", bone); element.GetVector3("position", position); element.GetInt("spawnrate", spawnrate); element.GetInt("particlelife", particlelife); element.GetFloat("gravity", gravity); element.GetInt("offsetsphere", offsetsphere); element.GetInt("speed", speed); element.GetInt("drag", drag); element.GetInt("acceleration", acceleration); element.GetAttribute("material", material); element.GetInt("minangle", minangle); element.GetInt("maxangle", maxangle); element.GetVector3("direction", direction); DiXMLElement child = element.GetChild(); while (child) { if (child.CheckName("particle")) { particles.push_back(DiK2ParticleConfig()); particles.back().Load(child); } child = child.GetNext(); } }
int DiInstanceBatchHardware::RemoveBlendData(DiVertexElements& elements) { bool hasBlendid = elements.Contains(VERT_USAGE_BLENDINDICES); bool hasBlendWt = elements.Contains(VERT_USAGE_BLENDWEIGHT); if(!hasBlendid && !hasBlendWt) { return -1; } uint16 blendIDSrc = 0; if (hasBlendid) { blendIDSrc = elements.GetUsageAtStream(VERT_USAGE_BLENDINDICES); } uint16 blendWtSrc = 0; if (hasBlendWt) { blendWtSrc = elements.GetUsageAtStream(VERT_USAGE_BLENDWEIGHT); } uint16 srcToDel = 0; if (hasBlendWt && hasBlendid) { DI_ASSERT(blendIDSrc==blendWtSrc); srcToDel = blendIDSrc; } else { srcToDel = hasBlendid?blendIDSrc:blendWtSrc; } elements.DeleteSource(srcToDel); return (int)srcToDel; }
void DiGLFrameBuffer::AttachSurface(uint32 attachment, DiTexturePtr surface) { DI_ASSERT(attachment < MAX_MRT); mColorBuffer[attachment] = surface; if (mColorBuffer[attachment]) Init(); }
void DiEditorManager::InitCommands() { CommandMgr->AddCommand("removeObj", [&](Demi::DiCmdArgs* args){ if (mCurrentSel) { DeleteEditorObject(mCurrentSel); return true; } else { DI_WARNING("No object selected, cannot remove!"); return false; } }); CommandMgr->AddCommand("createChild", [&](Demi::DiCmdArgs* args){ if (mCurrentSel) { DI_ASSERT(args->GetArgCount() == 2); mCurrentSel->_CreateChild(args->GetArg(1)); return true; } else { DI_WARNING("No object selected, cannot create child!"); return false; } }); CommandMgr->AddCommand("selectLast", [&](Demi::DiCmdArgs* args){ mCurrentSel = mLastCreatedObject; return true; }); }
void DiEditorManager::DeleteEditorObject(DiBaseEditorObj* obj) { if(mLastCreatedObject == obj) mLastCreatedObject = nullptr; if(obj->GetType() == "ParticleSystem") { if(dynamic_cast<DiParticleSystemObj*>(obj)->GetParticleSystem() == mSelectingFx) { if(mSelectingFx) { DI_DEBUG("Change selecting ps from [name = %s] to nullptr", mSelectingFx->GetName().c_str()); } mSelectingFx = nullptr; } } bool triggerChangemodel = obj->GetType() == "ReferenceModel"; DI_ASSERT(obj); obj->Release(); SAFE_DELETE(obj); mCurrentSel = nullptr; if(triggerChangemodel) { DiEditorManager::Get()->TriggerEvent("RefModel"); } }
DiBaseEditorObj* DiEditorManager::LoadParticleSystem(DiParticleSystemPtr ps) { DI_ASSERT(ps); auto psObj = mRootObject->_CreateChildFrom("ParticleSystem", DiAny(ps)); size_t numElements = ps->GetNumElements(); for(size_t i = 0; i < numElements; ++i) { DiParticleElement* element = ps->GetElement(i); auto elementObj = psObj->_CreateChildFrom("ParticleElement", DiAny(element)); // emitters size_t numEmits = element->GetNumEmitters(); for(size_t e = 0; e < numEmits; ++e) { DiParticleEmitter* emitter = element->GetEmitter(e); auto type = emitter->GetEmitterType() + "Emitter"; elementObj->_CreateChildFrom(type, DiAny(emitter)); } // controllers size_t numCtrls = element->GetNumControllers(); for(size_t c = 0; c < numCtrls; ++c) { DiParticleController* ctrl = element->GetController(c); auto type = ctrl->GetControllerType() + "Controller"; elementObj->_CreateChildFrom(type, DiAny(ctrl)); } } return psObj; }
void ArMoveProperty::MoveTo(const DiK2Pos& source, const DiK2Pos& target, float fRange /*= 0.0f*/) { //DiTimer timer; auto& pathFinder = ArGameApp::Get()->GetWorld()->GetTerrain()->GetPathFinder(); bool found = pathFinder.FindPath(&source, &target, mPosNode + 1, mNumNode, HeavyPathFinder::BLOCK_LEVEL_WALK); if (found) { mPosNode[0] = source; mNumNode++; mTargetPosition = target; mWalkMode = ENUM_WALK_MODE_WALK; mTargetDirection = INVALID_INT_VALUE; mNormalPos = mEntity->GetRenderObj()->GetPosition(); mNumCurTarget = 1; mDistance = 0; if (mNumNode > 0) { mPosNode[mNumNode - 1] = target; if (fRange > 0.001f) { int nEndNodeIndex = INVALID_INT_VALUE; DiK2Pos endTruePos(INVALID_FLOAT_VALUE, INVALID_FLOAT_VALUE); for (int i = mNumNode - 2; i >= 0; i--) { if (mPosNode[i].Distance(target) >= fRange || !pathFinder.IsReachable(mPosNode[i], HeavyPathFinder::BLOCK_LEVEL_WALK)) { nEndNodeIndex = i + 1; endTruePos = GetIntersectionLineRound(mPosNode[i], mPosNode[i + 1], target, fRange); break; } } DI_ASSERT(nEndNodeIndex != INVALID_INT_VALUE); DI_ASSERT(endTruePos.x != INVALID_FLOAT_VALUE); DI_ASSERT(endTruePos.z != INVALID_FLOAT_VALUE); mNumNode = nEndNodeIndex + 1; mPosNode[mNumNode - 1] = endTruePos; } } } //double loadingTime = timer.GetElapse(); //DI_LOG("Pathfinding time: %f", loadingTime); }
bool DiInputManager::registerKeyReleaseEvent(const DiString& name, KeyReleaseCallback cb) { DI_ASSERT(cb); if (mKeyReleases.contains(name)) return false; mKeyReleases[name] = cb; return true; }
bool DiInputManager::registerMousePressEvent(const DiString& name, MousePressCallback cb) { DI_ASSERT(cb); if (mMousePresses.contains(name)) return false; mMousePresses[name] = cb; return true; }
DWORD WINAPI DiTheradWin32::ThreadProc(LPVOID self) { DI_ASSERT(0 != self); DiTheradWin32* threadObj = (DiTheradWin32*)self; DiTheradWin32::SetMyThreadName(threadObj->GetName().c_str()); threadObj->threadStartedEvent.Signal(); threadObj->DoWork(); return 0; }
KyRefHandle::~KyRefHandle() { DI_ASSERT(GetMain()); KyObject* pkObj = GetMain()->GetObj(*this); if (pkObj) { pkObj->_DecRefCount(); } }
void DiTheradWin32::Stop() { DI_ASSERT(this->IsRunning()); DI_ASSERT(0 != this->threadHandle); // signal the thread to stop this->stopRequestEvent.Signal(); // call the wakeup-thread method, may be derived in a subclass // if the threads needs to be woken up, it is important that this // method is called AFTER the stopRequestEvent is signalled! this->EmitWakeupSignal(); // wait for the thread to terminate WaitForSingleObject(this->threadHandle, INFINITE); CloseHandle(this->threadHandle); this->threadHandle = 0; }
void RotationalSpline::UpdatePoint(unsigned short index, const DiQuat& value) { DI_ASSERT (index < mPoints.size()); mPoints[index] = value; if (mAutoCalc) { RecalcTangents(); } }
DiGLFBOManager::DiGLFBOManager(bool atimode) :mATIMode(atimode) { DI_ASSERT(!DiGLDriver::FBOManager); DiGLDriver::FBOManager = this; DetectFBOFormats(); glGenFramebuffersEXT(1, &mTempFBO); }
KyRefHandle::KyRefHandle(const KyHandle& handle, KyMain* mainContext) : KyHandle(handle) , KyMainContext(mainContext) { DI_ASSERT(GetMain()); KyObject* pkObj = GetMain()->GetObj(*this); if (pkObj) { pkObj->_IncRefCount(); } }
bool DiInstanceManager::GetSetting( BatchSettingId id, const DiString &materialName ) const { DI_ASSERT( id < NUM_SETTINGS ); BatchSettingsMap::const_iterator itor = mBatchSettings.find( materialName ); if( itor != mBatchSettings.end() ) { return itor->second.setting[id]; } return BatchSettings().setting[id]; }
void DiShaderParameter::AddParameter(ParamType type, const DiString& name) { DI_ASSERT(type < NUM_VARIABLE_TYPES); auto it = mShaderParams[type].find(name); if (it != mShaderParams[type].end()) { DI_WARNING("The parameter with name %s has already existed.", name.c_str()); return; } mShaderParams[type][name] = GetDefault(type); }
void ArAIProperty::PopCommand() { DI_ASSERT(!mAIList.empty()); mAIList.front()->Leave(); DI_DELETE mAIList.front(); mAIList.erase(mAIList.begin()); if (!mAIList.empty()) { mAIList.front()->Enter(); } }