Bitte melden Sie sich an, um diesen Link zu sehen.
Bitte melden Sie sich an, um diesen Link zu sehen.
ThingInstance
Code
- #include "StdAfx.h"
- #include "../eterbase/Debug.h"
- #include "../eterlib/Camera.h"
- #include "../eterBase/Timer.h"
- #include "ThingInstance.h"
- #include "Thing.h"
- #include "ModelInstance.h"
- #include "../UserInterface/PythonSystem.h"
- #ifdef ENABLE_OBJ_SCALLING
- #include "../UserInterface/Locale_inc.h"
- #endif
- CDynamicPool<CGraphicThingInstance> CGraphicThingInstance::ms_kPool;
- CGraphicThing* CGraphicThingInstance::GetBaseThingPtr()
- { if (m_modelThingSetVector.empty()) return NULL;
- TModelThingSet& rkModelThingSet=m_modelThingSetVector[0]; if (rkModelThingSet.m_pLODThingRefVector.empty()) return NULL;
- CGraphicThing::TRef* proThing=rkModelThingSet.m_pLODThingRefVector[0]; if (!proThing) return NULL;
- CGraphicThing::TRef roThing=*proThing; return roThing.GetPointer();
- }
- bool CGraphicThingInstance::LessRenderOrder(CGraphicThingInstance* pkThingInst)
- { return (GetBaseThingPtr()<pkThingInst->GetBaseThingPtr());
- }
- void CGraphicThingInstance::CreateSystem(UINT uCapacity)
- { ms_kPool.Create(uCapacity);
- }
- void CGraphicThingInstance::DestroySystem()
- { ms_kPool.Destroy();
- }
- CGraphicThingInstance* CGraphicThingInstance::New()
- { return ms_kPool.Alloc();
- }
- void CGraphicThingInstance::Delete(CGraphicThingInstance* pkThingInst)
- { pkThingInst->Clear(); ms_kPool.Free(pkThingInst);
- }
- void CGraphicThingInstance::SetMotionAtEnd()
- { std::for_each(m_LODControllerVector.begin(), m_LODControllerVector.end(), std::void_mem_fun(&CGrannyLODController::SetMotionAtEnd));
- }
- bool CGraphicThingInstance::Picking(const D3DXVECTOR3 & v, const D3DXVECTOR3 & dir, float & out_x, float & out_y)
- { if (!m_pHeightAttributeInstance) return false; return m_pHeightAttributeInstance->Picking(v,dir,out_x,out_y);
- }
- void CGraphicThingInstance::OnUpdateCollisionData(const CStaticCollisionDataVector * pscdVector)
- { assert(pscdVector); CStaticCollisionDataVector::const_iterator it; for(it = pscdVector->begin();it!=pscdVector->end();++it) { AddCollision(&(*it),&GetTransform()); }
- }
- void CGraphicThingInstance::OnUpdateHeighInstance(CAttributeInstance * pAttributeInstance)
- { assert(pAttributeInstance); SetHeightInstance(pAttributeInstance);
- }
- bool CGraphicThingInstance::OnGetObjectHeight(float fX, float fY, float * pfHeight)
- { if (m_pHeightAttributeInstance && m_pHeightAttributeInstance->GetHeight(fX, fY, pfHeight)) return true; return false;
- }
- void CGraphicThingInstance::BuildBoundingSphere()
- { D3DXVECTOR3 v3Min, v3Max; GetBoundBox(0, &v3Min, &v3Max); m_v3Center = (v3Min + v3Max) * 0.5f; D3DXVECTOR3 vDelta = (v3Max - v3Min);
- m_fRadius = D3DXVec3Length(&vDelta) * 0.5f + 50.0f; // extra length for attached objects
- }
- bool CGraphicThingInstance::GetBoundingSphere(D3DXVECTOR3 & v3Center, float & fRadius)
- { if (m_fRadius <= 0) { BuildBoundingSphere();
- fRadius = m_fRadius; v3Center = m_v3Center; } else { fRadius = m_fRadius; v3Center = m_v3Center; }
- D3DXVec3TransformCoord(&v3Center, &v3Center, &GetTransform()); return true;
- }
- void CGraphicThingInstance::BuildBoundingAABB()
- { D3DXVECTOR3 v3Min, v3Max; GetBoundBox(0, &v3Min, &v3Max); m_v3Center = (v3Min + v3Max) * 0.5f; m_v3Min = v3Min; m_v3Max = v3Max;
- }
- bool CGraphicThingInstance::GetBoundingAABB(D3DXVECTOR3 & v3Min, D3DXVECTOR3 & v3Max)
- { BuildBoundingAABB();
- v3Min = m_v3Min; v3Max = m_v3Max;
- D3DXVec3TransformCoord(&m_v3Center, &m_v3Center, &GetTransform()); return true;
- }
- void CGraphicThingInstance::CalculateBBox()
- { GetBoundBox(&m_v3BBoxMin, &m_v3BBoxMax);
- m_v4TBBox[0] = D3DXVECTOR4(m_v3BBoxMin.x, m_v3BBoxMin.y, m_v3BBoxMin.z, 1.0f); m_v4TBBox[1] = D3DXVECTOR4(m_v3BBoxMin.x, m_v3BBoxMax.y, m_v3BBoxMin.z, 1.0f); m_v4TBBox[2] = D3DXVECTOR4(m_v3BBoxMax.x, m_v3BBoxMin.y, m_v3BBoxMin.z, 1.0f); m_v4TBBox[3] = D3DXVECTOR4(m_v3BBoxMax.x, m_v3BBoxMax.y, m_v3BBoxMin.z, 1.0f); m_v4TBBox[4] = D3DXVECTOR4(m_v3BBoxMin.x, m_v3BBoxMin.y, m_v3BBoxMax.z, 1.0f); m_v4TBBox[5] = D3DXVECTOR4(m_v3BBoxMin.x, m_v3BBoxMax.y, m_v3BBoxMax.z, 1.0f); m_v4TBBox[6] = D3DXVECTOR4(m_v3BBoxMax.x, m_v3BBoxMin.y, m_v3BBoxMax.z, 1.0f); m_v4TBBox[7] = D3DXVECTOR4(m_v3BBoxMax.x, m_v3BBoxMax.y, m_v3BBoxMax.z, 1.0f);
- const D3DXMATRIX & c_rmatTransform = GetTransform();
- for (DWORD i = 0; i < 8; ++i) { D3DXVec4Transform(&m_v4TBBox[i], &m_v4TBBox[i], &c_rmatTransform); if (0 == i) { m_v3TBBoxMin.x = m_v4TBBox[i].x; m_v3TBBoxMin.y = m_v4TBBox[i].y; m_v3TBBoxMin.z = m_v4TBBox[i].z; m_v3TBBoxMax.x = m_v4TBBox[i].x; m_v3TBBoxMax.y = m_v4TBBox[i].y; m_v3TBBoxMax.z = m_v4TBBox[i].z; } else { if (m_v3TBBoxMin.x > m_v4TBBox[i].x) m_v3TBBoxMin.x = m_v4TBBox[i].x; if (m_v3TBBoxMax.x < m_v4TBBox[i].x) m_v3TBBoxMax.x = m_v4TBBox[i].x; if (m_v3TBBoxMin.y > m_v4TBBox[i].y) m_v3TBBoxMin.y = m_v4TBBox[i].y; if (m_v3TBBoxMax.y < m_v4TBBox[i].y) m_v3TBBoxMax.y = m_v4TBBox[i].y; if (m_v3TBBoxMin.z > m_v4TBBox[i].z) m_v3TBBoxMin.z = m_v4TBBox[i].z; if (m_v3TBBoxMax.z < m_v4TBBox[i].z) m_v3TBBoxMax.z = m_v4TBBox[i].z; } }
- }
- bool CGraphicThingInstance::CreateDeviceObjects()
- { CGrannyLODController::FCreateDeviceObjects createDeviceObjects; std::for_each(m_LODControllerVector.begin(), m_LODControllerVector.end(), createDeviceObjects); return true;
- }
- void CGraphicThingInstance::DestroyDeviceObjects()
- { CGrannyLODController::FDestroyDeviceObjects destroyDeviceObjects; std::for_each(m_LODControllerVector.begin(), m_LODControllerVector.end(), destroyDeviceObjects);
- }
- bool CGraphicThingInstance::CheckModelInstanceIndex(int iModelInstance)
- { if (iModelInstance < 0) return false;
- int max = m_LODControllerVector.size();
- if (iModelInstance >= max) return false;
- return true;
- }
- bool CGraphicThingInstance::CheckModelThingIndex(int iModelThing)
- { if (iModelThing < 0) return false;
- int max = m_modelThingSetVector.size();
- if (iModelThing >= max) return false;
- return true;
- }
- bool CGraphicThingInstance::CheckMotionThingIndex(DWORD dwMotionKey)
- { std::map<DWORD, CGraphicThing::TRef *>::iterator itor = m_roMotionThingMap.find(dwMotionKey);
- if (m_roMotionThingMap.end() == itor) return false;
- return true;
- }
- bool CGraphicThingInstance::GetMotionThingPointer(DWORD dwKey, CGraphicThing ** ppMotion)
- { if (!CheckMotionThingIndex(dwKey)) return false;
- *ppMotion = m_roMotionThingMap[dwKey]->GetPointer(); return true;
- }
- bool CGraphicThingInstance::IsMotionThing()
- { return !m_roMotionThingMap.empty();
- }
- void CGraphicThingInstance::ReserveModelInstance(int iCount)
- { stl_wipe(m_LODControllerVector);
- for (int i = 0; i < iCount; ++i) { CGrannyLODController * pInstance = new CGrannyLODController; m_LODControllerVector.push_back(pInstance); }
- }
- void CGraphicThingInstance::ReserveModelThing(int iCount)
- { m_modelThingSetVector.resize(iCount);
- }
- bool CGraphicThingInstance::FindBoneIndex(int iModelInstance, const char* c_szBoneName, int* iRetBone)
- { assert(CheckModelInstanceIndex(iModelInstance));
- CGrannyModelInstance * pModelInstance = m_LODControllerVector[iModelInstance]->GetModelInstance();
- if (!pModelInstance) return false;
- return pModelInstance->GetBoneIndexByName(c_szBoneName, iRetBone);
- }
- void CGraphicThingInstance::AttachModelInstance(int iDstModelInstance, const char * c_szBoneName, int iSrcModelInstance)
- { if (!CheckModelInstanceIndex(iSrcModelInstance)) { TraceError("CGraphicThingInstance::AttachModelInstance(iDstModelInstance=%d, c_szBoneName=%s, iSrcModelInstance=%d)", iDstModelInstance, c_szBoneName, iSrcModelInstance); return; } if (!CheckModelInstanceIndex(iDstModelInstance)) { TraceError("CGraphicThingInstance::AttachModelInstance(iDstModelInstance=%d, c_szBoneName=%s, iSrcModelInstance=%d)", iDstModelInstance, c_szBoneName, iSrcModelInstance); return; }
- CGrannyLODController * pSrcLODController = m_LODControllerVector[iSrcModelInstance]; CGrannyLODController * pDstLODController = m_LODControllerVector[iDstModelInstance]; pDstLODController->AttachModelInstance(pSrcLODController, c_szBoneName);
- }
- void CGraphicThingInstance::AttachModelInstance(int iDstModelInstance, const char * c_szBoneName, CGraphicThingInstance & rSrcInstance, int iSrcModelInstance)
- { if (!CheckModelInstanceIndex(iDstModelInstance)) { TraceError("CGraphicThingInstance::AttachModelInstance(iDstModelInstance=%d, c_szBoneName=%s, iSrcModelInstance=%d)", iDstModelInstance, c_szBoneName, iSrcModelInstance); return; } if (!rSrcInstance.CheckModelInstanceIndex(iSrcModelInstance)) { TraceError("CGraphicThingInstance::AttachModelInstance(iDstModelInstance=%d, c_szBoneName=%s, iSrcModelInstance=%d)", iDstModelInstance, c_szBoneName, iSrcModelInstance); return; }
- CGrannyLODController * pDstLODController = m_LODControllerVector[iDstModelInstance]; CGrannyLODController * pSrcLODController = rSrcInstance.m_LODControllerVector[iSrcModelInstance]; pDstLODController->AttachModelInstance(pSrcLODController, c_szBoneName);
- }
- void CGraphicThingInstance::DetachModelInstance(int iDstModelInstance, CGraphicThingInstance & rSrcInstance, int iSrcModelInstance)
- { if (!CheckModelInstanceIndex(iDstModelInstance)) { TraceError("CGraphicThingInstance::AttachModelInstance(iDstModelInstance=%d, iSrcModelInstance=%d)", iDstModelInstance, iSrcModelInstance); return; } if (!rSrcInstance.CheckModelInstanceIndex(iSrcModelInstance)) { TraceError("CGraphicThingInstance::AttachModelInstance(iDstModelInstance=%d, iSrcModelInstance=%d)", iDstModelInstance, iSrcModelInstance); return; }
- CGrannyLODController * pDstLODController = m_LODControllerVector[iDstModelInstance]; CGrannyLODController * pSrcLODController = rSrcInstance.m_LODControllerVector[iSrcModelInstance]; pDstLODController->DetachModelInstance(pSrcLODController);
- }
- bool CGraphicThingInstance::GetBonePosition(int iModelIndex, int iBoneIndex, float * pfx, float * pfy, float * pfz)
- { assert(CheckModelInstanceIndex(iModelIndex));
- CGrannyModelInstance * pModelInstance = m_LODControllerVector[iModelIndex]->GetModelInstance();
- if (!pModelInstance) return false;
- const float * pfMatrix = pModelInstance->GetBoneMatrixPointer(iBoneIndex);
- *pfx = pfMatrix[12]; *pfy = pfMatrix[13]; *pfz = pfMatrix[14]; return true;
- }
- //iSkelInstance 가 있으면 기본 본에 Link(본이 붙는것)시키고,
- //없으면 기본 본에 attach(좌표만 가져다 쓰는것) 됩니다.
- bool CGraphicThingInstance::SetModelInstance(int iDstModelInstance, int iSrcModelThing, int iSrcModel,int iSkelInstance)
- { if (!CheckModelInstanceIndex(iDstModelInstance)) { TraceError("CGraphicThingInstance::SetModelInstance(iDstModelInstance=%d, pModelThing=%d, iSrcModel=%d)\n", iDstModelInstance, iSrcModelThing, iSrcModel); return false; } if (!CheckModelThingIndex(iSrcModelThing)) { TraceError("CGraphicThingInstance::SetModelInstance(iDstModelInstance=%d, pModelThing=%d, iSrcModel=%d)\n", iDstModelInstance, iSrcModelThing, iSrcModel); return false; }
- CGrannyLODController * pController = m_LODControllerVector[iDstModelInstance]; if (!pController) return false;
- // HAIR_LINK CGrannyLODController * pSkelController = NULL; if (iSkelInstance != DONTUSEVALUE) { if (!CheckModelInstanceIndex(iSkelInstance)) { TraceError("CGraphicThingInstance::SetModelInstanceByOtherSkeletonInstance(iSkelInstance=%d, iDstModelInstance=%d, pModelThing=%d, iSrcModel=%d)\n", iSkelInstance, iDstModelInstance, iSrcModelThing, iSrcModel); return false; } pSkelController = m_LODControllerVector[iSkelInstance]; if (!pSkelController) return false; } // END_OF_HAIR_LINK
- TModelThingSet & rModelThingSet = m_modelThingSetVector[iSrcModelThing];
- pController->Clear();
- for (DWORD i = 0; i < rModelThingSet.m_pLODThingRefVector.size(); ++i) { if (rModelThingSet.m_pLODThingRefVector[i]->IsNull()) return false;
- pController->AddModel(rModelThingSet.m_pLODThingRefVector[i]->GetPointer(), iSrcModel, pSkelController); } return true;
- }
- void CGraphicThingInstance::SetMaterialImagePointer(UINT ePart, const char* c_szImageName, CGraphicImage* pImage)
- { if (ePart>=m_LODControllerVector.size()) { TraceError("CGraphicThingInstance::SetMaterialImagePointer(ePart(%d)<uPartCount(%d), c_szImageName=%s, pImage=%s) - ePart OUT OF RANGE", ePart, m_LODControllerVector.size(), c_szImageName, pImage->GetFileName());
- return; }
- if (!m_LODControllerVector[ePart]) { TraceError("CGraphicThingInstance::SetMaterialImagePointer(ePart(%d), c_szImageName=%s, pImage=%s) - ePart Data is NULL", ePart, m_LODControllerVector.size(), c_szImageName, pImage->GetFileName());
- return; }
- m_LODControllerVector[ePart]->SetMaterialImagePointer(c_szImageName, pImage);
- }
- void CGraphicThingInstance::SetMaterialData(UINT ePart, const char* c_szImageName, SMaterialData kMaterialData)
- { if (ePart>=m_LODControllerVector.size()) { TraceError("CGraphicThingInstance::SetMaterialData(ePart(%d)<uPartCount(%d)) - ePart OUT OF RANGE", ePart, m_LODControllerVector.size());
- return; }
- if (!m_LODControllerVector[ePart]) { TraceError("CGraphicThingInstance::SetMaterialData(ePart(%d)) - ePart Data is NULL", ePart, m_LODControllerVector.size());
- return; }
- m_LODControllerVector[ePart]->SetMaterialData(c_szImageName, kMaterialData);
- }
- void CGraphicThingInstance::SetSpecularInfo(UINT ePart, const char* c_szMtrlName, BOOL bEnable, float fPower)
- { if (ePart>=m_LODControllerVector.size()) { TraceError("CGraphicThingInstance::SetSpecularInfo(ePart(%d)<uPartCount(%d)) - ePart OUT OF RANGE", ePart, m_LODControllerVector.size());
- return; }
- if (!m_LODControllerVector[ePart]) { TraceError("CGraphicThingInstance::SetSpecularInfo(ePart(%d)) - ePart Data is NULL", ePart, m_LODControllerVector.size());
- return; }
- m_LODControllerVector[ePart]->SetSpecularInfo(c_szMtrlName, bEnable, fPower);
- }
- bool CGraphicThingInstance::SetMotion(DWORD dwMotionKey, float blendTime, int loopCount, float speedRatio)
- { if (!CheckMotionThingIndex(dwMotionKey)) return false;
- std::map<DWORD, CGraphicThing::TRef *>::iterator itor = m_roMotionThingMap.find(dwMotionKey); CGraphicThing::TRef * proMotionThing = itor->second; CGraphicThing * pMotionThing = proMotionThing->GetPointer();
- if (!pMotionThing) return false;
- if (!pMotionThing->CheckMotionIndex(0)) return false;
- CGrannyLODController::FSetMotionPointer SetMotionPointer; SetMotionPointer.m_pMotion = pMotionThing->GetMotionPointer(0); SetMotionPointer.m_blendTime = blendTime; SetMotionPointer.m_loopCount = loopCount; SetMotionPointer.m_speedRatio = speedRatio;
- std::for_each(m_LODControllerVector.begin(), m_LODControllerVector.end(), SetMotionPointer); return true;
- }
- bool CGraphicThingInstance::ChangeMotion(DWORD dwMotionKey, int loopCount, float speedRatio)
- { if (!CheckMotionThingIndex(dwMotionKey)) return false;
- std::map<DWORD, CGraphicThing::TRef *>::iterator itor = m_roMotionThingMap.find(dwMotionKey); CGraphicThing::TRef * proMotionThing = itor->second; CGraphicThing * pMotionThing = proMotionThing->GetPointer();
- if (!pMotionThing) return false;
- if (!pMotionThing->CheckMotionIndex(0)) return false;
- CGrannyLODController::FChangeMotionPointer ChangeMotionPointer; ChangeMotionPointer.m_pMotion = pMotionThing->GetMotionPointer(0); ChangeMotionPointer.m_loopCount = loopCount; ChangeMotionPointer.m_speedRatio = speedRatio;
- std::for_each(m_LODControllerVector.begin(), m_LODControllerVector.end(), ChangeMotionPointer); return true;
- }
- void CGraphicThingInstance::SetEndStopMotion()
- { std::for_each(m_LODControllerVector.begin(), m_LODControllerVector.end(), CGrannyLODController::FEndStopMotionPointer());
- }
- void CGraphicThingInstance::RegisterModelThing(int iModelThing, CGraphicThing * pModelThing)
- { if (!CheckModelThingIndex(iModelThing)) { TraceError("CGraphicThingInstance::RegisterModelThing(iModelThing=%d, pModelThing=%s)\n", iModelThing, pModelThing->GetFileName()); return; }
- m_modelThingSetVector[iModelThing].Clear();
- if (pModelThing) RegisterLODThing(iModelThing, pModelThing);
- }
- void CGraphicThingInstance::RegisterLODThing(int iModelThing, CGraphicThing * pModelThing)
- { assert(CheckModelThingIndex(iModelThing)); CGraphicThing::TRef * pModelRef = new CGraphicThing::TRef; pModelRef->SetPointer(pModelThing); m_modelThingSetVector[iModelThing].m_pLODThingRefVector.push_back(pModelRef);
- }
- void CGraphicThingInstance::RegisterMotionThing(DWORD dwMotionKey, CGraphicThing* pMotionThing)
- { CGraphicThing::TRef * pMotionRef = new CGraphicThing::TRef; pMotionRef->SetPointer(pMotionThing); m_roMotionThingMap.insert(std::map<DWORD, CGraphicThing::TRef *>::value_type(dwMotionKey, pMotionRef));
- }
- void CGraphicThingInstance::ResetLocalTime()
- { //m_clockLast = GrannyGetSystemSeconds(); m_fLastLocalTime = 0.0f; m_fLocalTime = 0.0f;
- CGrannyLODController::FResetLocalTime resetLocalTime; std::for_each(m_LODControllerVector.begin(), m_LODControllerVector.end(), resetLocalTime);
- }
- /*
- void CGraphicThingInstance::SetMotionSpeed(float fRate)
- { m_fMotionTimeSpeed = fRate;
- }
- */
- void CGraphicThingInstance::InsertDelay(float fDelay)
- { m_fDelay = fDelay;
- }
- float CGraphicThingInstance::GetLastLocalTime()
- { return m_fLastLocalTime;
- }
- float CGraphicThingInstance::GetLocalTime()
- { return m_fLocalTime;
- }
- float CGraphicThingInstance::GetSecondElapsed()
- { return m_fSecondElapsed;
- }
- float CGraphicThingInstance::GetAverageSecondElapsed()
- { return m_fAverageSecondElapsed;
- }
- bool CGraphicThingInstance::Intersect(float* pu, float* pv, float* pt)
- { if (!CGraphicObjectInstance::isShow()) return false; if (!m_bUpdated) return false;
- if (m_LODControllerVector.empty()) { //TraceError("CGraphicThingInstance::Intersect - m_LODControllerVector is empty"); return false; }
- return m_LODControllerVector[0]->Intersect(&GetTransform(), pu, pv, pt);
- }
- void CGraphicThingInstance::GetBoundBox(D3DXVECTOR3* vtMin, D3DXVECTOR3* vtMax)
- { vtMin->x = vtMin->y = vtMin->z = 100000.0f; vtMax->x = vtMax->y = vtMax->z = -100000.0f; std::for_each(m_LODControllerVector.begin(), m_LODControllerVector.end(), CGrannyLODController::FBoundBox(vtMin, vtMax));
- }
- BOOL CGraphicThingInstance::GetBoundBox(DWORD dwModelInstanceIndex, D3DXVECTOR3 * vtMin, D3DXVECTOR3 * vtMax)
- { if (!CheckModelInstanceIndex(dwModelInstanceIndex)) return FALSE;
- vtMin->x = vtMin->y = vtMin->z = 100000.0f; vtMax->x = vtMax->y = vtMax->z = -100000.0f;
- CGrannyLODController * pController = m_LODControllerVector[dwModelInstanceIndex]; if (!pController->isModelInstance()) return FALSE;
- CGrannyModelInstance * pModelInstance = pController->GetModelInstance(); pModelInstance->GetBoundBox(vtMin, vtMax); return TRUE;
- }
- BOOL CGraphicThingInstance::GetBoneMatrix(DWORD dwModelInstanceIndex, DWORD dwBoneIndex, D3DXMATRIX ** ppMatrix)
- { if (!CheckModelInstanceIndex(dwModelInstanceIndex)) return FALSE;
- CGrannyModelInstance * pModelInstance = m_LODControllerVector[dwModelInstanceIndex]->GetModelInstance(); if (!pModelInstance) return FALSE;
- *ppMatrix = (D3DXMATRIX *)pModelInstance->GetBoneMatrixPointer(dwBoneIndex); if (!*ppMatrix) return FALSE;
- return TRUE;
- }
- BOOL CGraphicThingInstance::GetCompositeBoneMatrix(DWORD dwModelInstanceIndex, DWORD dwBoneIndex, D3DXMATRIX ** ppMatrix)
- { if (!CheckModelInstanceIndex(dwModelInstanceIndex)) return FALSE;
- CGrannyModelInstance * pModelInstance = m_LODControllerVector[dwModelInstanceIndex]->GetModelInstance(); if (!pModelInstance) { //TraceError("CGraphicThingInstance::GetCompositeBoneMatrix(dwModelInstanceIndex=%d, dwBoneIndex=%d, D3DXMATRIX ** ppMatrix)", dwModelInstanceIndex, dwBoneIndex); return FALSE; }
- *ppMatrix = (D3DXMATRIX *)pModelInstance->GetCompositeBoneMatrixPointer(dwBoneIndex);
- return TRUE;
- }
- void CGraphicThingInstance::UpdateTransform(D3DXMATRIX * pMatrix, float fSecondsElapsed, int iModelInstanceIndex)
- { //TraceError("%s",GetBaseThingPtr()->GetFileName()); int nLODCount=m_LODControllerVector.size(); if (iModelInstanceIndex>=nLODCount) { //TraceError("void CGraphicThingInstance::UpdateTransform(pMatrix, fSecondsElapsed=%f, iModelInstanceIndex=%d/nLODCount=%d)", // fSecondsElapsed, iModelInstanceIndex, nLODCount); return; }
- CGrannyLODController* pkLODCtrl=m_LODControllerVector[iModelInstanceIndex]; if (!pkLODCtrl) { //TraceError("void CGraphicThingInstance::UpdateTransform(pMatrix, fSecondsElapsed=%f, iModelInstanceIndex=%d/nLODCount=%d) - m_LODControllerVector[iModelInstanceIndex] == NULL", // fSecondsElapsed, iModelInstanceIndex, nLODCount); return; }
- CGrannyModelInstance * pModelInstance = pkLODCtrl->GetModelInstance(); if (!pModelInstance) { /* TraceError("void CGraphicThingInstance::UpdateTransform(pMatrix, fSecondsElapsed=%f, iModelInstanceIndex=%d/nLODCount=%d) - pkLODCtrl->GetModelInstance() == NULL", fSecondsElapsed, iModelInstanceIndex, nLODCount);*/ return; }
- pModelInstance->UpdateTransform(pMatrix, fSecondsElapsed);
- }
- void CGraphicThingInstance::DeformAll()
- { m_bUpdated = true;
- CGrannyLODController::FDeformAll deform; deform.mc_pWorldMatrix = &m_worldMatrix; std::for_each(m_LODControllerVector.begin(), m_LODControllerVector.end(), deform);
- }
- void CGraphicThingInstance::DeformNoSkin()
- { m_bUpdated = true; for (std::vector<CGrannyLODController*>::size_type iMod = 0; iMod != m_LODControllerVector.size(); iMod++) { CGrannyLODController * pkLOD = m_LODControllerVector[iMod]; if (!pkLOD->isModelInstance()) continue; #ifdef ENABLE_OBJ_SCALLING if (m_modelThingSetVector.size() == 1) pkLOD->DeformNoSkin(&m_TransformMatrix); #ifdef ENABLE_ACCE_SYSTEM else if (iMod == 5) /* CRaceData::PART_ACCE */ pkLOD->DeformNoSkin(&m_TransformMatrix); #endif else #endif pkLOD->DeformNoSkin(&m_worldMatrix); }
- }
- void CGraphicThingInstance::OnDeform()
- { m_bUpdated = true; for (std::vector<CGrannyLODController*>::size_type iMod = 0; iMod != m_LODControllerVector.size(); iMod++) { CGrannyLODController * pkLOD = m_LODControllerVector[iMod]; if (!pkLOD->isModelInstance()) continue; #ifdef ENABLE_OBJ_SCALLING if (m_modelThingSetVector.size() == 1) pkLOD->Deform(&m_TransformMatrix); #ifdef ENABLE_ACCE_SYSTEM else if (iMod == 5) /* CRaceData::PART_ACCE */ pkLOD->Deform(&m_TransformMatrix); #endif else #endif pkLOD->Deform(&m_worldMatrix); }
- }
- void CGraphicThingInstance::__SetLocalTime(float fLocalTime)
- { m_fLastLocalTime = m_fLocalTime; m_fLocalTime = fLocalTime;
- CGrannyLODController::FSetLocalTime SetLocalTime; SetLocalTime.fLocalTime = fLocalTime; std::for_each(m_LODControllerVector.begin(), m_LODControllerVector.end(), SetLocalTime);
- }
- void CGraphicThingInstance::UpdateLODLevel()
- { CCamera * pcurCamera = CCameraManager::Instance().GetCurrentCamera(); if (!pcurCamera) { TraceError("CGraphicThingInstance::UpdateLODLevel - GetCurrentCamera() == NULL"); return; }
- const D3DXVECTOR3 & c_rv3TargetPosition = pcurCamera->GetTarget(); const D3DXVECTOR3 & c_rv3CameraPosition = pcurCamera->GetEye(); const D3DXVECTOR3 & c_v3Position = GetPosition();
- // NOTE : 중심으로부터의 거리 계산에 z값 차이는 사용하지 않는다. - [levites] CGrannyLODController::FUpdateLODLevel update; update.fDistanceFromCenter = sqrtf((c_rv3TargetPosition.x - c_v3Position.x) * (c_rv3TargetPosition.x - c_v3Position.x) + (c_rv3TargetPosition.y - c_v3Position.y) * (c_rv3TargetPosition.y - c_v3Position.y)); update.fDistanceFromCamera = sqrtf((c_rv3CameraPosition.x - c_v3Position.x) * (c_rv3CameraPosition.x - c_v3Position.x) + (c_rv3CameraPosition.y - c_v3Position.y) * (c_rv3CameraPosition.y - c_v3Position.y) + (c_rv3CameraPosition.z - c_v3Position.z) * (c_rv3CameraPosition.z - c_v3Position.z));
- std::for_each(m_LODControllerVector.begin(), m_LODControllerVector.end(), update);
- }
- void CGraphicThingInstance::UpdateTime()
- { //granny_system_clock clockNow = GrannyGetSystemSeconds(); //m_fSecondElapsed = GrannyGetSecondsElapsed(&m_clockLast, &clockNow) * m_fMotionTimeSpeed;
- //DWORD t1=ELTimer_GetMSec();
- m_fSecondElapsed=CTimer::Instance().GetElapsedSecond();
- if (m_fDelay > m_fSecondElapsed) { m_fDelay -= m_fSecondElapsed; m_fSecondElapsed = 0.0f; } else { m_fSecondElapsed -= m_fDelay; m_fDelay = 0.0f; }
- m_fLastLocalTime = m_fLocalTime; m_fLocalTime += m_fSecondElapsed; m_fAverageSecondElapsed = m_fAverageSecondElapsed + (m_fSecondElapsed - m_fAverageSecondElapsed) / 4.0f; //m_clockLast = clockNow;
- CGrannyLODController::FUpdateTime update; update.fElapsedTime = m_fSecondElapsed; std::for_each(m_LODControllerVector.begin(), m_LODControllerVector.end(), update);
- }
- void CGraphicThingInstance::OnUpdate()
- {
- #ifdef __PERFORMANCE_CHECKER__ DWORD t1=timeGetTime();
- #endif UpdateLODLevel();
- #ifdef __PERFORMANCE_CHECKER__ DWORD t2=timeGetTime();
- #endif UpdateTime();
- #ifdef __PERFORMANCE_CHECKER__ DWORD t3=timeGetTime();
- #endif
- #ifdef __PERFORMANCE_CHECKER__ { static FILE* fp=fopen("perf_thing_onupdate.txt", "w");
- if (t3-t1>3) { fprintf(fp, "GTU.Total %d (Time %f)\n", t3-t1, ELTimer_GetMSec()/1000.0f); fprintf(fp, "GTU.CAL %d\n", t2-t1); fprintf(fp, "GTU.UP %d\n", t3-t2); fprintf(fp, "-------------------------------- \n"); fflush(fp); } fflush(fp); }
- #endif
- }
- void CGraphicThingInstance::OnRender()
- { RenderWithOneTexture();
- }
- void CGraphicThingInstance::OnBlendRender()
- { BlendRenderWithOneTexture();
- }
- void CGraphicThingInstance::RenderWithOneTexture()
- { if (!m_bUpdated) return; for (std::vector::size_type i = 0; i != m_LODControllerVector.size(); i++) { if (i == 5) { if (CPythonSystem::instance().IsShowAcce()) { CGrannyLODController* pkLOD = m_LODControllerVector[i]; if (pkLOD->isModelInstance()) pkLOD->RenderWithOneTexture(); } } else { CGrannyLODController* pkLOD = m_LODControllerVector[i]; if (pkLOD->isModelInstance()) pkLOD->RenderWithOneTexture(); } }
- }
- void CGraphicThingInstance::BlendRenderWithOneTexture()
- { //assert(m_bUpdated); if (!m_bUpdated) return;
- CGrannyLODController::FBlendRenderWithOneTexture blendRender; std::for_each(m_LODControllerVector.begin(), m_LODControllerVector.end(), blendRender);
- }
- void CGraphicThingInstance::RenderWithTwoTexture()
- { if (!m_bUpdated) return; for (std::vector::size_type i = 0; i != m_LODControllerVector.size(); i++) { if (i == 5) { if (CPythonSystem::instance().IsShowAcce()) { CGrannyLODController* pkLOD = m_LODControllerVector[i]; if (pkLOD->isModelInstance()) pkLOD->RenderWithTwoTexture(); } } else { CGrannyLODController* pkLOD = m_LODControllerVector[i]; if (pkLOD->isModelInstance()) pkLOD->RenderWithTwoTexture(); } }
- }
- void CGraphicThingInstance::BlendRenderWithTwoTexture()
- { //assert(m_bUpdated); if (!m_bUpdated) return;
- CGrannyLODController::FRenderWithTwoTexture blendRender; std::for_each(m_LODControllerVector.begin(), m_LODControllerVector.end(), blendRender);
- }
- void CGraphicThingInstance::OnRenderToShadowMap()
- { if (!m_bUpdated) return;
- CGrannyLODController::FRenderToShadowMap RenderToShadowMap; std::for_each(m_LODControllerVector.begin(), m_LODControllerVector.end(), RenderToShadowMap);
- }
- void CGraphicThingInstance::OnRenderShadow()
- { CGrannyLODController::FRenderShadow RenderShadow; std::for_each(m_LODControllerVector.begin(), m_LODControllerVector.end(), RenderShadow);
- }
- void CGraphicThingInstance::OnRenderPCBlocker()
- { CGrannyLODController::FRenderWithOneTexture RenderPCBlocker; std::for_each(m_LODControllerVector.begin(), m_LODControllerVector.end(), RenderPCBlocker);
- }
- DWORD CGraphicThingInstance::GetLODControllerCount() const
- { return m_LODControllerVector.size();
- }
- CGrannyLODController * CGraphicThingInstance::GetLODControllerPointer(DWORD dwModelIndex) const
- { assert(dwModelIndex < m_LODControllerVector.size()); return m_LODControllerVector[dwModelIndex];
- }
- CGrannyLODController * CGraphicThingInstance::GetLODControllerPointer(DWORD dwModelIndex)
- { assert(dwModelIndex < m_LODControllerVector.size()); return m_LODControllerVector[dwModelIndex];
- }
- BYTE CGraphicThingInstance::GetLODLevel(DWORD dwModelInstance)
- { assert(dwModelInstance < m_LODControllerVector.size()); return (m_LODControllerVector[dwModelInstance]->GetLODLevel());
- }
- float CGraphicThingInstance::GetHeight()
- { if (m_LODControllerVector.empty()) return 0.0f;
- CGrannyModelInstance * pModelInstance = m_LODControllerVector[0]->GetModelInstance(); if (!pModelInstance) return 0.0f;
- D3DXVECTOR3 vtMin, vtMax; pModelInstance->GetBoundBox(&vtMin, &vtMax);
- return fabs(vtMin.z - vtMax.z);
- }
- void CGraphicThingInstance::ReloadTexture()
- { CGrannyLODController::FReloadTexture ReloadTexture; std::for_each(m_LODControllerVector.begin(), m_LODControllerVector.end(), ReloadTexture);
- }
- bool CGraphicThingInstance::HaveBlendThing()
- { for (int i = 0; i < m_LODControllerVector.size(); i++) { if (m_LODControllerVector[i]->HaveBlendThing()) return true; } return false;
- }
- void CGraphicThingInstance::OnClear()
- { stl_wipe(m_LODControllerVector); stl_wipe_second(m_roMotionThingMap);
- for (DWORD d = 0; d < m_modelThingSetVector.size(); ++d) m_modelThingSetVector[d].Clear();
- }
- void CGraphicThingInstance::OnInitialize()
- { m_bUpdated = false; m_fLastLocalTime = 0.0f; m_fLocalTime = 0.0f; m_fDelay = 0.0; m_fSecondElapsed = 0.0f; m_fAverageSecondElapsed = 0.03f; m_fRadius = -1.0f; m_v3Center = D3DXVECTOR3(0.0f, 0.0f, 0.0f);
- ResetLocalTime();
- }
- CGraphicThingInstance::CGraphicThingInstance()
- { Initialize();
- }
- CGraphicThingInstance::~CGraphicThingInstance()
- {
- }
PythonSystemModule
Code
- #include "StdAfx.h"
- #include "PythonSystem.h"
- PyObject * systemGetWidth(PyObject* poSelf, PyObject* poArgs)
- { return Py_BuildValue("i", CPythonSystem::Instance().GetWidth());
- }
- PyObject * systemGetHeight(PyObject* poSelf, PyObject* poArgs)
- { return Py_BuildValue("i", CPythonSystem::Instance().GetHeight());
- }
- PyObject * systemSetInterfaceHandler(PyObject* poSelf, PyObject* poArgs)
- { PyObject* poHandler; if (!PyTuple_GetObject(poArgs, 0, &poHandler)) return Py_BuildException();
- CPythonSystem::Instance().SetInterfaceHandler(poHandler); return Py_BuildNone();
- }
- PyObject * systemDestroyInterfaceHandler(PyObject* poSelf, PyObject* poArgs)
- { CPythonSystem::Instance().DestroyInterfaceHandler(); return Py_BuildNone();
- }
- PyObject * systemReserveResource(PyObject* poSelf, PyObject* poArgs)
- { std::set<std::string> ResourceSet; CResourceManager::Instance().PushBackgroundLoadingSet(ResourceSet); return Py_BuildNone();
- }
- PyObject * systemisInterfaceConfig(PyObject* poSelf, PyObject* poArgs)
- { int isInterfaceConfig = CPythonSystem::Instance().isInterfaceConfig(); return Py_BuildValue("i", isInterfaceConfig);
- }
- PyObject * systemSaveWindowStatus(PyObject* poSelf, PyObject* poArgs)
- { int iIndex; if (!PyTuple_GetInteger(poArgs, 0, &iIndex)) return Py_BuildException();
- int iVisible; if (!PyTuple_GetInteger(poArgs, 1, &iVisible)) return Py_BuildException();
- int iMinimized; if (!PyTuple_GetInteger(poArgs, 2, &iMinimized)) return Py_BuildException();
- int ix; if (!PyTuple_GetInteger(poArgs, 3, &ix)) return Py_BuildException();
- int iy; if (!PyTuple_GetInteger(poArgs, 4, &iy)) return Py_BuildException();
- int iHeight; if (!PyTuple_GetInteger(poArgs, 5, &iHeight)) return Py_BuildException();
- CPythonSystem::Instance().SaveWindowStatus(iIndex, iVisible, iMinimized, ix, iy, iHeight); return Py_BuildNone();
- }
- PyObject * systemGetWindowStatus(PyObject* poSelf, PyObject* poArgs)
- { int iIndex; if (!PyTuple_GetInteger(poArgs, 0, &iIndex)) return Py_BuildException();
- const CPythonSystem::TWindowStatus & c_rWindowStatus = CPythonSystem::Instance().GetWindowStatusReference(iIndex); return Py_BuildValue("iiiii", c_rWindowStatus.isVisible, c_rWindowStatus.isMinimized, c_rWindowStatus.ixPosition, c_rWindowStatus.iyPosition, c_rWindowStatus.iHeight);
- }
- PyObject * systemGetConfig(PyObject * poSelf, PyObject * poArgs)
- { CPythonSystem::TConfig *tmp = CPythonSystem::Instance().GetConfig();
- int iRes = CPythonSystem::Instance().GetResolutionIndex(tmp->width, tmp->height, tmp->bpp); int iFrequency = CPythonSystem::Instance().GetFrequencyIndex(iRes, tmp->frequency);
- return Py_BuildValue("iiiiiiii", iRes, iFrequency, tmp->is_software_cursor, tmp->is_object_culling, tmp->music_volume, tmp->voice_volume, tmp->gamma, tmp->iDistance);
- }
- PyObject * systemSetSaveID(PyObject * poSelf, PyObject * poArgs)
- { int iValue; if (!PyTuple_GetInteger(poArgs, 0, &iValue)) return Py_BuildException();
- char * szSaveID; if (!PyTuple_GetString(poArgs, 1, &szSaveID)) return Py_BuildException();
- CPythonSystem::Instance().SetSaveID(iValue, szSaveID); return Py_BuildNone();
- }
- PyObject * systemisSaveID(PyObject * poSelf, PyObject * poArgs)
- { int value = CPythonSystem::Instance().IsSaveID(); return Py_BuildValue("i", value);
- }
- PyObject * systemGetSaveID(PyObject * poSelf, PyObject * poArgs)
- { const char * c_szSaveID = CPythonSystem::Instance().GetSaveID(); return Py_BuildValue("s", c_szSaveID);
- }
- PyObject * systemGetMusicVolume(PyObject * poSelf, PyObject * poArgs)
- { return Py_BuildValue("f", CPythonSystem::Instance().GetMusicVolume());
- }
- PyObject * systemGetSoundVolume(PyObject * poSelf, PyObject * poArgs)
- { return Py_BuildValue("i", CPythonSystem::Instance().GetSoundVolume());
- }
- PyObject * systemSetMusicVolume(PyObject * poSelf, PyObject * poArgs)
- { float fVolume; if (!PyTuple_GetFloat(poArgs, 0, &fVolume)) return Py_BuildException();
- CPythonSystem::Instance().SetMusicVolume(fVolume); return Py_BuildNone();
- }
- PyObject * systemSetShowAcce(PyObject * poSelf, PyObject * poArgs)
- { int iFlag; if (!PyTuple_GetInteger(poArgs, 0, &iFlag)) return Py_BuildException(); CPythonSystem::Instance().SetShowAcce(iFlag); return Py_BuildNone();
- }
- PyObject * systemIsShowAcce(PyObject * poSelf, PyObject * poArgs)
- { return Py_BuildValue("i", CPythonSystem::Instance().IsShowAcce());
- }
- PyObject * systemSetSoundVolumef(PyObject * poSelf, PyObject * poArgs)
- { float fVolume; if (!PyTuple_GetFloat(poArgs, 0, &fVolume)) return Py_BuildException();
- CPythonSystem::Instance().SetSoundVolumef(fVolume); return Py_BuildNone();
- }
- PyObject * systemIsSoftwareCursor(PyObject * poSelf, PyObject * poArgs)
- { return Py_BuildValue("i", CPythonSystem::Instance().IsSoftwareCursor());
- }
- PyObject * systemSetViewChatFlag(PyObject * poSelf, PyObject * poArgs)
- { int iFlag; if (!PyTuple_GetInteger(poArgs, 0, &iFlag)) return Py_BuildException();
- CPythonSystem::Instance().SetViewChatFlag(iFlag);
- return Py_BuildNone();
- }
- PyObject * systemIsViewChat(PyObject * poSelf, PyObject * poArgs)
- { return Py_BuildValue("i", CPythonSystem::Instance().IsViewChat());
- }
- PyObject * systemSetAlwaysShowNameFlag(PyObject * poSelf, PyObject * poArgs)
- { int iFlag; if (!PyTuple_GetInteger(poArgs, 0, &iFlag)) return Py_BuildException();
- CPythonSystem::Instance().SetAlwaysShowNameFlag(iFlag);
- return Py_BuildNone();
- }
- PyObject * systemSetShowDamageFlag(PyObject * poSelf, PyObject * poArgs)
- { int iFlag; if (!PyTuple_GetInteger(poArgs, 0, &iFlag)) return Py_BuildException();
- CPythonSystem::Instance().SetShowDamageFlag(iFlag);
- return Py_BuildNone();
- }
- PyObject * systemSetShowSalesTextFlag(PyObject * poSelf, PyObject * poArgs)
- { int iFlag; if (!PyTuple_GetInteger(poArgs, 0, &iFlag)) return Py_BuildException();
- CPythonSystem::Instance().SetShowSalesTextFlag(iFlag);
- return Py_BuildNone();
- }
- #ifdef WJ_SHOW_MOB_INFO
- #include "PythonCharacterManager.h"
- #include "PythonNonPlayer.h"
- #include "PythonSystem.h"
- #if defined(WJ_SHOW_MOB_INFO) && defined(ENABLE_SHOW_MOBAIFLAG)
- PyObject * systemIsShowMobAIFlag(PyObject * poSelf, PyObject * poArgs)
- { return Py_BuildValue("i", CPythonSystem::Instance().IsShowMobAIFlag());
- }
- PyObject * systemSetShowMobAIFlag(PyObject * poSelf, PyObject * poArgs)
- { int iFlag; if (!PyTuple_GetInteger(poArgs, 0, &iFlag)) return Py_BuildException();
- CPythonSystem::Instance().SetShowMobAIFlagFlag(iFlag);
- for (CPythonCharacterManager::CharacterIterator it=CPythonCharacterManager::Instance().CharacterInstanceBegin(), ti=CPythonCharacterManager::Instance().CharacterInstanceEnd(); it!=ti; ++it) { CInstanceBase * pkInst = *it; if (pkInst && pkInst->IsEnemy()) pkInst->MobInfoAiFlagRefresh(); } return Py_BuildNone();
- }
- #endif
- #if defined(WJ_SHOW_MOB_INFO) && defined(ENABLE_SHOW_MOBLEVEL)
- PyObject * systemIsShowMobLevel(PyObject * poSelf, PyObject * poArgs)
- { return Py_BuildValue("i", CPythonSystem::Instance().IsShowMobLevel());
- }
- PyObject * systemSetShowMobLevel(PyObject * poSelf, PyObject * poArgs)
- { int iFlag; if (!PyTuple_GetInteger(poArgs, 0, &iFlag)) return Py_BuildException();
- CPythonSystem::Instance().SetShowMobLevelFlag(iFlag);
- for (CPythonCharacterManager::CharacterIterator it=CPythonCharacterManager::Instance().CharacterInstanceBegin(), ti=CPythonCharacterManager::Instance().CharacterInstanceEnd(); it!=ti; ++it) { CInstanceBase * pkInst = *it; if (pkInst && pkInst->IsEnemy()) pkInst->MobInfoLevelRefresh(); } return Py_BuildNone();
- }
- #endif
- #endif
- PyObject * systemIsAlwaysShowName(PyObject * poSelf, PyObject * poArgs)
- { return Py_BuildValue("i", CPythonSystem::Instance().IsAlwaysShowName());
- }
- PyObject * systemIsShowDamage(PyObject * poSelf, PyObject * poArgs)
- { return Py_BuildValue("i", CPythonSystem::Instance().IsShowDamage());
- }
- PyObject * systemIsShowSalesText(PyObject * poSelf, PyObject * poArgs)
- { return Py_BuildValue("i", CPythonSystem::Instance().IsShowSalesText());
- }
- PyObject * systemSetConfig(PyObject * poSelf, PyObject * poArgs)
- { int res_index; int width; int height; int bpp; int frequency_index; int frequency; int software_cursor; int shadow; int object_culling; int music_volume; int voice_volume; int gamma; int distance;
- if (!PyTuple_GetInteger(poArgs, 0, &res_index)) return Py_BuildException();
- if (!PyTuple_GetInteger(poArgs, 1, &frequency_index)) return Py_BuildException();
- if (!PyTuple_GetInteger(poArgs, 2, &software_cursor)) return Py_BuildException();
- if (!PyTuple_GetInteger(poArgs, 3, &shadow)) return Py_BuildException();
- if (!PyTuple_GetInteger(poArgs, 4, &object_culling)) return Py_BuildException();
- if (!PyTuple_GetInteger(poArgs, 5, &music_volume)) return Py_BuildException();
- if (!PyTuple_GetInteger(poArgs, 6, &voice_volume)) return Py_BuildException();
- if (!PyTuple_GetInteger(poArgs, 7, &gamma)) return Py_BuildException();
- if (!PyTuple_GetInteger(poArgs, 8, &distance)) return Py_BuildException();
- if (!CPythonSystem::Instance().GetResolution(res_index, (DWORD *) &width, (DWORD *) &height, (DWORD *) &bpp)) return Py_BuildNone();
- if (!CPythonSystem::Instance().GetFrequency(res_index,frequency_index, (DWORD *) &frequency)) return Py_BuildNone();
- CPythonSystem::TConfig tmp;
- memcpy(&tmp, CPythonSystem::Instance().GetConfig(), sizeof(tmp));
- tmp.width = width; tmp.height = height; tmp.bpp = bpp; tmp.frequency = frequency; tmp.is_software_cursor = software_cursor ? true : false; tmp.is_object_culling = object_culling ? true : false; tmp.music_volume = (char) music_volume; tmp.voice_volume = (char) voice_volume; tmp.gamma = gamma; tmp.iDistance = distance;
- CPythonSystem::Instance().SetConfig(&tmp); return Py_BuildNone();
- }
- PyObject * systemApplyConfig(PyObject * poSelf, PyObject * poArgs)
- { CPythonSystem::Instance().ApplyConfig(); return Py_BuildNone();
- }
- PyObject * systemSaveConfig(PyObject * poSelf, PyObject * poArgs)
- { int ret = CPythonSystem::Instance().SaveConfig(); return Py_BuildValue("i", ret);
- }
- PyObject * systemGetResolutionCount(PyObject * poSelf, PyObject * poArgs)
- { return Py_BuildValue("i", CPythonSystem::Instance().GetResolutionCount());
- }
- PyObject * systemGetFrequencyCount(PyObject * poSelf, PyObject * poArgs)
- { int index;
- if (!PyTuple_GetInteger(poArgs, 0, &index)) return Py_BuildException();
- return Py_BuildValue("i", CPythonSystem::Instance().GetFrequencyCount(index));
- }
- PyObject * systemGetResolution(PyObject * poSelf, PyObject * poArgs)
- { int index; DWORD width = 0, height = 0, bpp = 0;
- if (!PyTuple_GetInteger(poArgs, 0, &index)) return Py_BuildException();
- CPythonSystem::Instance().GetResolution(index, &width, &height, &bpp); return Py_BuildValue("iii", width, height, bpp);
- }
- PyObject * systemGetCurrentResolution(PyObject * poSelf, PyObject *poArgs)
- { CPythonSystem::TConfig *tmp = CPythonSystem::Instance().GetConfig(); return Py_BuildValue("iii", tmp->width, tmp->height, tmp->bpp);
- }
- PyObject * systemGetFrequency(PyObject * poSelf, PyObject * poArgs)
- { int index, frequency_index; DWORD frequency = 0;
- if (!PyTuple_GetInteger(poArgs, 0, &index)) return Py_BuildException();
- if (!PyTuple_GetInteger(poArgs, 1, &frequency_index)) return Py_BuildException();
- CPythonSystem::Instance().GetFrequency(index, frequency_index, &frequency); return Py_BuildValue("i", frequency);
- }
- PyObject * systemGetShadowLevel(PyObject * poSelf, PyObject * poArgs)
- { return Py_BuildValue("i", CPythonSystem::Instance().GetShadowLevel());
- }
- PyObject * systemSetShadowLevel(PyObject * poSelf, PyObject * poArgs)
- { int level;
- if (!PyTuple_GetInteger(poArgs, 0, &level)) return Py_BuildException();
- if (level > 0) CPythonSystem::Instance().SetShadowLevel(level);
- return Py_BuildNone();
- }
- void initsystemSetting()
- { static PyMethodDef s_methods[] = { { "GetWidth", systemGetWidth, METH_VARARGS }, { "GetHeight", systemGetHeight, METH_VARARGS },
- { "SetInterfaceHandler", systemSetInterfaceHandler, METH_VARARGS }, { "DestroyInterfaceHandler", systemDestroyInterfaceHandler, METH_VARARGS }, { "ReserveResource", systemReserveResource, METH_VARARGS },
- { "isInterfaceConfig", systemisInterfaceConfig, METH_VARARGS }, { "SaveWindowStatus", systemSaveWindowStatus, METH_VARARGS }, { "GetWindowStatus", systemGetWindowStatus, METH_VARARGS },
- { "GetResolutionCount", systemGetResolutionCount, METH_VARARGS }, { "GetFrequencyCount", systemGetFrequencyCount, METH_VARARGS },
- { "GetCurrentResolution", systemGetCurrentResolution, METH_VARARGS },
- { "GetResolution", systemGetResolution, METH_VARARGS }, { "GetFrequency", systemGetFrequency, METH_VARARGS },
- { "ApplyConfig", systemApplyConfig, METH_VARARGS }, { "SetConfig", systemSetConfig, METH_VARARGS }, { "SaveConfig", systemSaveConfig, METH_VARARGS }, { "GetConfig", systemGetConfig, METH_VARARGS },
- { "SetSaveID", systemSetSaveID, METH_VARARGS }, { "isSaveID", systemisSaveID, METH_VARARGS }, { "GetSaveID", systemGetSaveID, METH_VARARGS },
- { "GetMusicVolume", systemGetMusicVolume, METH_VARARGS }, { "GetSoundVolume", systemGetSoundVolume, METH_VARARGS },
- { "SetMusicVolume", systemSetMusicVolume, METH_VARARGS }, { "SetSoundVolumef", systemSetSoundVolumef, METH_VARARGS }, { "IsSoftwareCursor", systemIsSoftwareCursor, METH_VARARGS }, { "SetShowAcceFlag", systemSetShowAcce, METH_VARARGS }, { "IsShowAcce", systemIsShowAcce, METH_VARARGS },
- { "SetViewChatFlag", systemSetViewChatFlag, METH_VARARGS }, { "IsViewChat", systemIsViewChat, METH_VARARGS },
- { "SetAlwaysShowNameFlag", systemSetAlwaysShowNameFlag, METH_VARARGS }, { "IsAlwaysShowName", systemIsAlwaysShowName, METH_VARARGS },
- { "SetShowDamageFlag", systemSetShowDamageFlag, METH_VARARGS }, { "IsShowDamage", systemIsShowDamage, METH_VARARGS },
- { "SetShowSalesTextFlag", systemSetShowSalesTextFlag, METH_VARARGS }, { "IsShowSalesText", systemIsShowSalesText, METH_VARARGS },
- { "GetShadowLevel", systemGetShadowLevel, METH_VARARGS }, { "SetShadowLevel", systemSetShadowLevel, METH_VARARGS },
- #ifdef WJ_SHOW_MOB_INFO { "IsShowMobAIFlag", systemIsShowMobAIFlag, METH_VARARGS }, { "SetShowMobAIFlag", systemSetShowMobAIFlag, METH_VARARGS },
- { "IsShowMobLevel", systemIsShowMobLevel, METH_VARARGS }, { "SetShowMobLevel", systemSetShowMobLevel, METH_VARARGS },
- #endif
- { NULL, NULL, NULL } };
- PyObject * poModule = Py_InitModule("systemSetting", s_methods);
- PyModule_AddIntConstant(poModule, "WINDOW_STATUS", CPythonSystem::WINDOW_STATUS); PyModule_AddIntConstant(poModule, "WINDOW_INVENTORY", CPythonSystem::WINDOW_INVENTORY); PyModule_AddIntConstant(poModule, "WINDOW_ABILITY", CPythonSystem::WINDOW_ABILITY); PyModule_AddIntConstant(poModule, "WINDOW_SOCIETY", CPythonSystem::WINDOW_SOCIETY); PyModule_AddIntConstant(poModule, "WINDOW_JOURNAL", CPythonSystem::WINDOW_JOURNAL); PyModule_AddIntConstant(poModule, "WINDOW_COMMAND", CPythonSystem::WINDOW_COMMAND);
- PyModule_AddIntConstant(poModule, "WINDOW_QUICK", CPythonSystem::WINDOW_QUICK); PyModule_AddIntConstant(poModule, "WINDOW_GAUGE", CPythonSystem::WINDOW_GAUGE); PyModule_AddIntConstant(poModule, "WINDOW_MINIMAP", CPythonSystem::WINDOW_MINIMAP); PyModule_AddIntConstant(poModule, "WINDOW_CHAT", CPythonSystem::WINDOW_CHAT);
- }
PythonSystem.h
Code
- #pragma once
- class CPythonSystem : public CSingleton<CPythonSystem>
- { public: enum EWindow { WINDOW_STATUS, WINDOW_INVENTORY, WINDOW_ABILITY, WINDOW_SOCIETY, WINDOW_JOURNAL, WINDOW_COMMAND,
- WINDOW_QUICK, WINDOW_GAUGE, WINDOW_MINIMAP, WINDOW_CHAT,
- WINDOW_MAX_NUM, };
- enum { FREQUENCY_MAX_NUM = 30, RESOLUTION_MAX_NUM = 100 };
- typedef struct SResolution { DWORD width; DWORD height; DWORD bpp; // bits per pixel (high-color = 16bpp, true-color = 32bpp)
- DWORD frequency[20]; BYTE frequency_count; } TResolution;
- typedef struct SWindowStatus { int isVisible; int isMinimized;
- int ixPosition; int iyPosition; int iHeight; } TWindowStatus;
- typedef struct SConfig { DWORD width; DWORD height; DWORD bpp; DWORD frequency;
- bool is_software_cursor; bool is_object_culling; int iDistance; int iShadowLevel;
- FLOAT music_volume; BYTE voice_volume;
- int gamma;
- int isSaveID; char SaveID[20];
- bool bWindowed; bool bDecompressDDS; bool bNoSoundCard; bool bUseDefaultIME; BYTE bSoftwareTiling; bool bViewChat; bool bAlwaysShowName; bool bShowDamage; bool bShowSalesText; bool bShowAcce;
- #if defined(WJ_SHOW_MOB_INFO) && defined(ENABLE_SHOW_MOBAIFLAG) bool bShowMobAIFlag;
- #endif
- #if defined(WJ_SHOW_MOB_INFO) && defined(ENABLE_SHOW_MOBLEVEL) bool bShowMobLevel;
- #endif } TConfig;
- public: CPythonSystem(); virtual ~CPythonSystem();
- void Clear(); void SetInterfaceHandler(PyObject * poHandler); void DestroyInterfaceHandler();
- // Config void SetDefaultConfig(); bool LoadConfig(); bool SaveConfig(); void ApplyConfig(); void SetConfig(TConfig * set_config); TConfig * GetConfig(); void ChangeSystem();
- // Interface bool LoadInterfaceStatus(); void SaveInterfaceStatus(); bool isInterfaceConfig(); const TWindowStatus & GetWindowStatusReference(int iIndex);
- DWORD GetWidth(); DWORD GetHeight(); DWORD GetBPP(); DWORD GetFrequency(); bool IsSoftwareCursor(); bool IsWindowed(); bool IsViewChat(); bool IsAlwaysShowName(); bool IsShowDamage(); bool IsShowSalesText(); bool IsUseDefaultIME(); bool IsNoSoundCard(); bool IsAutoTiling(); bool IsSoftwareTiling(); void SetSoftwareTiling(bool isEnable); void SetViewChatFlag(int iFlag); void SetAlwaysShowNameFlag(int iFlag); void SetShowDamageFlag(int iFlag); void SetShowSalesTextFlag(int iFlag);
- #if defined(WJ_SHOW_MOB_INFO) && defined(ENABLE_SHOW_MOBAIFLAG) bool IsShowMobAIFlag(); void SetShowMobAIFlagFlag(int iFlag);
- #endif
- #if defined(WJ_SHOW_MOB_INFO) && defined(ENABLE_SHOW_MOBLEVEL) bool IsShowMobLevel(); void SetShowMobLevelFlag(int iFlag);
- #endif
- // Window void SaveWindowStatus(int iIndex, int iVisible, int iMinimized, int ix, int iy, int iHeight);
- // SaveID int IsSaveID(); const char * GetSaveID(); void SetSaveID(int iValue, const char * c_szSaveID);
- /// Display void GetDisplaySettings();
- int GetResolutionCount(); int GetFrequencyCount(int index); bool GetResolution(int index, OUT DWORD *width, OUT DWORD *height, OUT DWORD *bpp); bool GetFrequency(int index, int freq_index, OUT DWORD *frequncy); int GetResolutionIndex(DWORD width, DWORD height, DWORD bpp); int GetFrequencyIndex(int res_index, DWORD frequency); bool isViewCulling();
- // Sound float GetMusicVolume(); int GetSoundVolume(); void SetMusicVolume(float fVolume); void SetSoundVolumef(float fVolume);
- int GetDistance(); int GetShadowLevel(); void SetShadowLevel(unsigned int level); bool IsShowAcce() { return m_Config.bShowAcce; } void SetShowAcce(int iFlag) { m_Config.bShowAcce = iFlag; }
- protected: TResolution m_ResolutionList[RESOLUTION_MAX_NUM]; int m_ResolutionCount;
- TConfig m_Config; TConfig m_OldConfig;
- bool m_isInterfaceConfig; PyObject * m_poInterfaceHandler; TWindowStatus m_WindowStatus[WINDOW_MAX_NUM];
- };
Pythonsystem.cpp
Code
- #include "StdAfx.h"
- #include "PythonSystem.h"
- #include "PythonApplication.h"
- #define DEFAULT_VALUE_ALWAYS_SHOW_NAME true
- void CPythonSystem::SetInterfaceHandler(PyObject * poHandler)
- {
- // NOTE : 레퍼런스 카운트는 바꾸지 않는다. 레퍼런스가 남아 있어 Python에서 완전히 지워지지 않기 때문.
- // 대신에 __del__때 Destroy를 호출해 Handler를 NULL로 셋팅한다. - [levites]
- // if (m_poInterfaceHandler)
- // Py_DECREF(m_poInterfaceHandler);
- m_poInterfaceHandler = poHandler;
- // if (m_poInterfaceHandler)
- // Py_INCREF(m_poInterfaceHandler);
- }
- void CPythonSystem::DestroyInterfaceHandler()
- { m_poInterfaceHandler = NULL;
- }
- void CPythonSystem::SaveWindowStatus(int iIndex, int iVisible, int iMinimized, int ix, int iy, int iHeight)
- { m_WindowStatus[iIndex].isVisible = iVisible; m_WindowStatus[iIndex].isMinimized = iMinimized; m_WindowStatus[iIndex].ixPosition = ix; m_WindowStatus[iIndex].iyPosition = iy; m_WindowStatus[iIndex].iHeight = iHeight;
- }
- void CPythonSystem::GetDisplaySettings()
- { memset(m_ResolutionList, 0, sizeof(TResolution) * RESOLUTION_MAX_NUM); m_ResolutionCount = 0;
- LPDIRECT3D8 lpD3D = CPythonGraphic::Instance().GetD3D();
- D3DADAPTER_IDENTIFIER8 d3dAdapterIdentifier; D3DDISPLAYMODE d3ddmDesktop;
- lpD3D->GetAdapterIdentifier(0, D3DENUM_NO_WHQL_LEVEL, &d3dAdapterIdentifier); lpD3D->GetAdapterDisplayMode(0, &d3ddmDesktop);
- // 이 어뎁터가 가지고 있는 디스플래이 모드갯수를 나열한다.. DWORD dwNumAdapterModes = lpD3D->GetAdapterModeCount(0);
- for (UINT iMode = 0; iMode < dwNumAdapterModes; iMode++) { D3DDISPLAYMODE DisplayMode; lpD3D->EnumAdapterModes(0, iMode, &DisplayMode); DWORD bpp = 0;
- // 800 600 이상만 걸러낸다. if (DisplayMode.Width < 800 || DisplayMode.Height < 600) continue;
- // 일단 16bbp 와 32bbp만 취급하자. // 16bbp만 처리하게끔 했음 - [levites] if (DisplayMode.Format == D3DFMT_R5G6B5) bpp = 16; else if (DisplayMode.Format == D3DFMT_X8R8G8B8) bpp = 32; else continue;
- int check_res = false;
- for (int i = 0; !check_res && i < m_ResolutionCount; ++i) { if (m_ResolutionList[i].bpp != bpp || m_ResolutionList[i].width != DisplayMode.Width || m_ResolutionList[i].height != DisplayMode.Height) continue;
- int check_fre = false;
- // 프리퀀시만 다르므로 프리퀀시만 셋팅해준다. for (int j = 0; j < m_ResolutionList[i].frequency_count; ++j) { if (m_ResolutionList[i].frequency[j] == DisplayMode.RefreshRate) { check_fre = true; break; } }
- if (!check_fre) if (m_ResolutionList[i].frequency_count < FREQUENCY_MAX_NUM) m_ResolutionList[i].frequency[m_ResolutionList[i].frequency_count++] = DisplayMode.RefreshRate;
- check_res = true; }
- if (!check_res) { // 새로운 거니까 추가해주자. if (m_ResolutionCount < RESOLUTION_MAX_NUM) { m_ResolutionList[m_ResolutionCount].width = DisplayMode.Width; m_ResolutionList[m_ResolutionCount].height = DisplayMode.Height; m_ResolutionList[m_ResolutionCount].bpp = bpp; m_ResolutionList[m_ResolutionCount].frequency[0] = DisplayMode.RefreshRate; m_ResolutionList[m_ResolutionCount].frequency_count = 1;
- ++m_ResolutionCount; } } }
- }
- int CPythonSystem::GetResolutionCount()
- { return m_ResolutionCount;
- }
- int CPythonSystem::GetFrequencyCount(int index)
- { if (index >= m_ResolutionCount) return 0;
- return m_ResolutionList[index].frequency_count;
- }
- bool CPythonSystem::GetResolution(int index, OUT DWORD *width, OUT DWORD *height, OUT DWORD *bpp)
- { if (index >= m_ResolutionCount) return false;
- *width = m_ResolutionList[index].width; *height = m_ResolutionList[index].height; *bpp = m_ResolutionList[index].bpp; return true;
- }
- bool CPythonSystem::GetFrequency(int index, int freq_index, OUT DWORD *frequncy)
- { if (index >= m_ResolutionCount) return false;
- if (freq_index >= m_ResolutionList[index].frequency_count) return false;
- *frequncy = m_ResolutionList[index].frequency[freq_index]; return true;
- }
- int CPythonSystem::GetResolutionIndex(DWORD width, DWORD height, DWORD bit)
- { DWORD re_width, re_height, re_bit; int i = 0;
- while (GetResolution(i, &re_width, &re_height, &re_bit)) { if (re_width == width) if (re_height == height) if (re_bit == bit) return i; i++; }
- return 0;
- }
- int CPythonSystem::GetFrequencyIndex(int res_index, DWORD frequency)
- { DWORD re_frequency; int i = 0;
- while (GetFrequency(res_index, i, &re_frequency)) { if (re_frequency == frequency) return i;
- i++; }
- return 0;
- }
- DWORD CPythonSystem::GetWidth()
- { return m_Config.width;
- }
- DWORD CPythonSystem::GetHeight()
- { return m_Config.height;
- }
- DWORD CPythonSystem::GetBPP()
- { return m_Config.bpp;
- }
- DWORD CPythonSystem::GetFrequency()
- { return m_Config.frequency;
- }
- bool CPythonSystem::IsNoSoundCard()
- { return m_Config.bNoSoundCard;
- }
- bool CPythonSystem::IsSoftwareCursor()
- { return m_Config.is_software_cursor;
- }
- float CPythonSystem::GetMusicVolume()
- { return m_Config.music_volume;
- }
- int CPythonSystem::GetSoundVolume()
- { return m_Config.voice_volume;
- }
- void CPythonSystem::SetMusicVolume(float fVolume)
- { m_Config.music_volume = fVolume;
- }
- void CPythonSystem::SetSoundVolumef(float fVolume)
- { m_Config.voice_volume = int(5 * fVolume);
- }
- int CPythonSystem::GetDistance()
- { return m_Config.iDistance;
- }
- int CPythonSystem::GetShadowLevel()
- { return m_Config.iShadowLevel;
- }
- void CPythonSystem::SetShadowLevel(unsigned int level)
- { m_Config.iShadowLevel = MIN(level, 5); CPythonBackground::instance().RefreshShadowLevel();
- }
- int CPythonSystem::IsSaveID()
- { return m_Config.isSaveID;
- }
- const char * CPythonSystem::GetSaveID()
- { return m_Config.SaveID;
- }
- bool CPythonSystem::isViewCulling()
- { return m_Config.is_object_culling;
- }
- void CPythonSystem::SetSaveID(int iValue, const char * c_szSaveID)
- { if (iValue != 1) return;
- m_Config.isSaveID = iValue; strncpy(m_Config.SaveID, c_szSaveID, sizeof(m_Config.SaveID) - 1);
- }
- CPythonSystem::TConfig * CPythonSystem::GetConfig()
- { return &m_Config;
- }
- void CPythonSystem::SetConfig(TConfig * pNewConfig)
- { m_Config = *pNewConfig;
- }
- void CPythonSystem::SetDefaultConfig()
- { memset(&m_Config, 0, sizeof(m_Config));
- m_Config.width = 1024; m_Config.height = 768; m_Config.bpp = 32;
- #if defined( LOCALE_SERVICE_WE_JAPAN ) m_Config.bWindowed = true;
- #else m_Config.bWindowed = false;
- #endif
- m_Config.is_software_cursor = false; m_Config.is_object_culling = true; m_Config.iDistance = 3;
- m_Config.gamma = 3; m_Config.music_volume = 1.0f; m_Config.voice_volume = 5;
- m_Config.bDecompressDDS = 0; m_Config.bSoftwareTiling = 0; m_Config.iShadowLevel = 3; m_Config.bViewChat = true; m_Config.bAlwaysShowName = DEFAULT_VALUE_ALWAYS_SHOW_NAME; m_Config.bShowDamage = true; m_Config.bShowSalesText = true; m_Config.bShowAcce = true;
- #if defined(WJ_SHOW_MOB_INFO) && defined(ENABLE_SHOW_MOBAIFLAG) m_Config.bShowMobAIFlag = true;
- #endif
- #if defined(WJ_SHOW_MOB_INFO) && defined(ENABLE_SHOW_MOBLEVEL) m_Config.bShowMobLevel = true;
- #endif
- }
- bool CPythonSystem::IsWindowed()
- { return m_Config.bWindowed;
- }
- bool CPythonSystem::IsViewChat()
- { return m_Config.bViewChat;
- }
- void CPythonSystem::SetViewChatFlag(int iFlag)
- { m_Config.bViewChat = iFlag == 1 ? true : false;
- }
- bool CPythonSystem::IsAlwaysShowName()
- { return m_Config.bAlwaysShowName;
- }
- void CPythonSystem::SetAlwaysShowNameFlag(int iFlag)
- { m_Config.bAlwaysShowName = iFlag == 1 ? true : false;
- }
- bool CPythonSystem::IsShowDamage()
- { return m_Config.bShowDamage;
- }
- void CPythonSystem::SetShowDamageFlag(int iFlag)
- { m_Config.bShowDamage = iFlag == 1 ? true : false;
- }
- bool CPythonSystem::IsShowSalesText()
- { return m_Config.bShowSalesText;
- }
- void CPythonSystem::SetShowSalesTextFlag(int iFlag)
- { m_Config.bShowSalesText = iFlag == 1 ? true : false;
- }
- #if defined(WJ_SHOW_MOB_INFO) && defined(ENABLE_SHOW_MOBAIFLAG)
- bool CPythonSystem::IsShowMobAIFlag()
- { return m_Config.bShowMobAIFlag;
- }
- void CPythonSystem::SetShowMobAIFlagFlag(int iFlag)
- { m_Config.bShowMobAIFlag = iFlag == 1 ? true : false;
- }
- #endif
- #if defined(WJ_SHOW_MOB_INFO) && defined(ENABLE_SHOW_MOBLEVEL)
- bool CPythonSystem::IsShowMobLevel()
- { return m_Config.bShowMobLevel;
- }
- void CPythonSystem::SetShowMobLevelFlag(int iFlag)
- { m_Config.bShowMobLevel = iFlag == 1 ? true : false;
- }
- #endif
- bool CPythonSystem::IsAutoTiling()
- { if (m_Config.bSoftwareTiling == 0) return true;
- return false;
- }
- void CPythonSystem::SetSoftwareTiling(bool isEnable)
- { if (isEnable) m_Config.bSoftwareTiling=1; else m_Config.bSoftwareTiling=2;
- }
- bool CPythonSystem::IsSoftwareTiling()
- { if (m_Config.bSoftwareTiling==1) return true;
- return false;
- }
- bool CPythonSystem::IsUseDefaultIME()
- { return m_Config.bUseDefaultIME;
- }
- bool CPythonSystem::LoadConfig()
- { FILE * fp = NULL;
- if (NULL == (fp = fopen("metin2.cfg", "rt"))) return false;
- char buf[256]; char command[256]; char value[256];
- while (fgets(buf, 256, fp)) { if (sscanf(buf, " %s %s\n", command, value) == EOF) break;
- if (!stricmp(command, "WIDTH")) m_Config.width = atoi(value); else if (!stricmp(command, "HEIGHT")) m_Config.height = atoi(value); else if (!stricmp(command, "BPP")) m_Config.bpp = atoi(value); else if (!stricmp(command, "FREQUENCY")) m_Config.frequency = atoi(value); else if (!stricmp(command, "SOFTWARE_CURSOR")) m_Config.is_software_cursor = atoi(value) ? true : false; else if (!stricmp(command, "OBJECT_CULLING")) m_Config.is_object_culling = atoi(value) ? true : false; else if (!stricmp(command, "VISIBILITY")) m_Config.iDistance = atoi(value); else if (!stricmp(command, "MUSIC_VOLUME")) { if(strchr(value, '.') == 0) { // Old compatiability m_Config.music_volume = pow(10.0f, (-1.0f + (((float) atoi(value)) / 5.0f))); if(atoi(value) == 0) m_Config.music_volume = 0.0f; } else m_Config.music_volume = atof(value); } else if (!stricmp(command, "VOICE_VOLUME")) m_Config.voice_volume = (char) atoi(value); else if (!stricmp(command, "GAMMA")) m_Config.gamma = atoi(value); else if (!stricmp(command, "IS_SAVE_ID")) m_Config.isSaveID = atoi(value); else if (!stricmp(command, "SAVE_ID")) strncpy(m_Config.SaveID, value, 20); else if (!stricmp(command, "PRE_LOADING_DELAY_TIME")) g_iLoadingDelayTime = atoi(value); else if (!stricmp(command, "SHOW_ACCE")) m_Config.bShowAcce = atoi(value) == 1 ? true : false; else if (!stricmp(command, "WINDOWED")) { m_Config.bWindowed = atoi(value) == 1 ? true : false; } else if (!stricmp(command, "USE_DEFAULT_IME")) m_Config.bUseDefaultIME = atoi(value) == 1 ? true : false; else if (!stricmp(command, "SOFTWARE_TILING")) m_Config.bSoftwareTiling = atoi(value); else if (!stricmp(command, "SHADOW_LEVEL")) m_Config.iShadowLevel = atoi(value); else if (!stricmp(command, "DECOMPRESSED_TEXTURE")) m_Config.bDecompressDDS = atoi(value) == 1 ? true : false; else if (!stricmp(command, "NO_SOUND_CARD")) m_Config.bNoSoundCard = atoi(value) == 1 ? true : false; else if (!stricmp(command, "VIEW_CHAT")) m_Config.bViewChat = atoi(value) == 1 ? true : false; else if (!stricmp(command, "ALWAYS_VIEW_NAME")) m_Config.bAlwaysShowName = atoi(value) == 1 ? true : false; else if (!stricmp(command, "SHOW_DAMAGE")) m_Config.bShowDamage = atoi(value) == 1 ? true : false; else if (!stricmp(command, "SHOW_SALESTEXT")) m_Config.bShowSalesText = atoi(value) == 1 ? true : false;
- #if defined(WJ_SHOW_MOB_INFO) && defined(ENABLE_SHOW_MOBAIFLAG) else if (!stricmp(command, "SHOW_MOBAIFLAG")) m_Config.bShowMobAIFlag = atoi(value) == 1 ? true : false;
- #endif
- #if defined(WJ_SHOW_MOB_INFO) && defined(ENABLE_SHOW_MOBLEVEL) else if (!stricmp(command, "SHOW_MOBLEVEL")) m_Config.bShowMobLevel = atoi(value) == 1 ? true : false;
- #endif }
- if (m_Config.bWindowed) { unsigned screen_width = GetSystemMetrics(SM_CXFULLSCREEN); unsigned screen_height = GetSystemMetrics(SM_CYFULLSCREEN);
- if (m_Config.width >= screen_width) { m_Config.width = screen_width; } if (m_Config.height >= screen_height) { m_Config.height = screen_height; } }
- m_OldConfig = m_Config;
- fclose(fp);
- // Tracef("LoadConfig: Resolution: %dx%d %dBPP %dHZ Software Cursor: %d, Music/Voice Volume: %d/%d Gamma: %d\n",
- // m_Config.width,
- // m_Config.height,
- // m_Config.bpp,
- // m_Config.frequency,
- // m_Config.is_software_cursor,
- // m_Config.music_volume,
- // m_Config.voice_volume,
- // m_Config.gamma);
- return true;
- }
- bool CPythonSystem::SaveConfig()
- { FILE *fp;
- if (NULL == (fp = fopen("metin2.cfg", "wt"))) return false;
- fprintf(fp, "WIDTH %d\n" "HEIGHT %d\n" "BPP %d\n" "FREQUENCY %d\n" "SOFTWARE_CURSOR %d\n" "OBJECT_CULLING %d\n" "VISIBILITY %d\n" "MUSIC_VOLUME %.3f\n" "VOICE_VOLUME %d\n" "GAMMA %d\n" "IS_SAVE_ID %d\n" "SAVE_ID %s\n" "PRE_LOADING_DELAY_TIME %d\n" "DECOMPRESSED_TEXTURE %d\n", m_Config.width, m_Config.height, m_Config.bpp, m_Config.frequency, m_Config.is_software_cursor, m_Config.is_object_culling, m_Config.iDistance, m_Config.music_volume, m_Config.voice_volume, m_Config.gamma, m_Config.isSaveID, m_Config.SaveID, g_iLoadingDelayTime, m_Config.bDecompressDDS);
- if (m_Config.bWindowed == 1) fprintf(fp, "WINDOWED %d\n", m_Config.bWindowed); if (m_Config.bViewChat == 0) fprintf(fp, "VIEW_CHAT %d\n", m_Config.bViewChat); if (m_Config.bAlwaysShowName != DEFAULT_VALUE_ALWAYS_SHOW_NAME) fprintf(fp, "ALWAYS_VIEW_NAME %d\n", m_Config.bAlwaysShowName); if (m_Config.bShowDamage == 0) fprintf(fp, "SHOW_DAMAGE %d\n", m_Config.bShowDamage); if (m_Config.bShowSalesText == 0) fprintf(fp, "SHOW_SALESTEXT %d\n", m_Config.bShowSalesText);
- #if defined(WJ_SHOW_MOB_INFO) && defined(ENABLE_SHOW_MOBAIFLAG) if (m_Config.bShowMobAIFlag == 0) fprintf(fp, "SHOW_MOBAIFLAG %d\n", m_Config.bShowMobAIFlag);
- #endif
- #if defined(WJ_SHOW_MOB_INFO) && defined(ENABLE_SHOW_MOBLEVEL) if (m_Config.bShowMobLevel == 0) fprintf(fp, "SHOW_MOBLEVEL %d\n", m_Config.bShowMobLevel);
- #endif
- fprintf(fp, "USE_DEFAULT_IME %d\n", m_Config.bUseDefaultIME); fprintf(fp, "SOFTWARE_TILING %d\n", m_Config.bSoftwareTiling); fprintf(fp, "SHADOW_LEVEL %d\n", m_Config.iShadowLevel); fprintf(fp, "SHOW_ACCE %d\n", m_Config.bShowAcce); fprintf(fp, "\n");
- fclose(fp); return true;
- }
- bool CPythonSystem::LoadInterfaceStatus()
- { FILE * File; File = fopen("interface.cfg", "rb");
- if (!File) return false;
- fread(m_WindowStatus, 1, sizeof(TWindowStatus) * WINDOW_MAX_NUM, File); fclose(File); return true;
- }
- void CPythonSystem::SaveInterfaceStatus()
- { if (!m_poInterfaceHandler) return;
- PyCallClassMemberFunc(m_poInterfaceHandler, "OnSaveInterfaceStatus", Py_BuildValue("()"));
- FILE * File;
- File = fopen("interface.cfg", "wb");
- if (!File) { TraceError("Cannot open interface.cfg"); return; }
- fwrite(m_WindowStatus, 1, sizeof(TWindowStatus) * WINDOW_MAX_NUM, File); fclose(File);
- }
- bool CPythonSystem::isInterfaceConfig()
- { return m_isInterfaceConfig;
- }
- const CPythonSystem::TWindowStatus & CPythonSystem::GetWindowStatusReference(int iIndex)
- { return m_WindowStatus[iIndex];
- }
- void CPythonSystem::ApplyConfig() // 이전 설정과 현재 설정을 비교해서 바뀐 설정을 적용 한다.
- { if (m_OldConfig.gamma != m_Config.gamma) { float val = 1.0f;
- switch (m_Config.gamma) { case 0: val = 0.4f; break; case 1: val = 0.7f; break; case 2: val = 1.0f; break; case 3: val = 1.2f; break; case 4: val = 1.4f; break; }
- CPythonGraphic::Instance().SetGamma(val); }
- if (m_OldConfig.is_software_cursor != m_Config.is_software_cursor) { if (m_Config.is_software_cursor) CPythonApplication::Instance().SetCursorMode(CPythonApplication::CURSOR_MODE_SOFTWARE); else CPythonApplication::Instance().SetCursorMode(CPythonApplication::CURSOR_MODE_HARDWARE); }
- m_OldConfig = m_Config;
- ChangeSystem();
- }
- void CPythonSystem::ChangeSystem()
- { // Shadow /* if (m_Config.is_shadow) CScreen::SetShadowFlag(true); else CScreen::SetShadowFlag(false); */ CSoundManager& rkSndMgr = CSoundManager::Instance(); /* float fMusicVolume; if (0 == m_Config.music_volume) fMusicVolume = 0.0f; else fMusicVolume= (float)pow(10.0f, (-1.0f + (float)m_Config.music_volume / 5.0f)); */ rkSndMgr.SetMusicVolume(m_Config.music_volume);
- /* float fVoiceVolume; if (0 == m_Config.voice_volume) fVoiceVolume = 0.0f; else fVoiceVolume = (float)pow(10.0f, (-1.0f + (float)m_Config.voice_volume / 5.0f)); */ rkSndMgr.SetSoundVolumeGrade(m_Config.voice_volume);
- }
- void CPythonSystem::Clear()
- { SetInterfaceHandler(NULL);
- }
- CPythonSystem::CPythonSystem()
- { memset(&m_Config, 0, sizeof(TConfig));
- m_poInterfaceHandler = NULL;
- SetDefaultConfig();
- LoadConfig();
- ChangeSystem();
- if (LoadInterfaceStatus()) m_isInterfaceConfig = true; else m_isInterfaceConfig = false;
- }
- CPythonSystem::~CPythonSystem()
- { assert(m_poInterfaceHandler==NULL && "CPythonSystem MUST CLEAR!");
- }