iMaterial* cMaterialType_Diffuse::Create(const tString& asName,iLowLevelGraphics* apLowLevelGraphics, cImageManager* apImageManager, cTextureManager *apTextureManager, cRenderer2D* apRenderer, cGpuProgramManager* apProgramManager, eMaterialPicture aPicture, cRenderer3D *apRenderer3D) { if( apLowLevelGraphics->GetCaps(eGraphicCaps_GL_FragmentProgram) && iMaterial::GetQuality() >= eMaterialQuality_High) { return hplNew( cMaterial_Diffuse, (asName,apLowLevelGraphics, apImageManager,apTextureManager,apRenderer, apProgramManager,aPicture,apRenderer3D) ); } else if(apLowLevelGraphics->GetCaps(eGraphicCaps_MaxTextureImageUnits)>=3 && iMaterial::GetQuality() >= eMaterialQuality_Medium) { return hplNew( cMaterial_Fallback01_Diffuse, (asName,apLowLevelGraphics, apImageManager,apTextureManager,apRenderer, apProgramManager,aPicture,apRenderer3D) ); } else if(apLowLevelGraphics->GetCaps(eGraphicCaps_GL_VertexProgram) && iMaterial::GetQuality() >= eMaterialQuality_Low) { return hplNew( cMaterial_Fallback02_Diffuse, (asName,apLowLevelGraphics, apImageManager,apTextureManager,apRenderer, apProgramManager,aPicture,apRenderer3D) ); } else { return hplNew( cMaterial_Flat, (asName,apLowLevelGraphics, apImageManager,apTextureManager,apRenderer, apProgramManager,aPicture,apRenderer3D) ); } }
cSDLGameSetup::cSDLGameSetup() { if (SDL_Init( SDL_INIT_VIDEO | SDL_INIT_TIMER ) < 0) { FatalError("Error Initializing Display: %s",SDL_GetError()); exit(1); } mpLowLevelSystem = hplNew( cLowLevelSystemSDL, () ); mpLowLevelGraphics = hplNew( cLowLevelGraphicsSDL,() ); mpLowLevelInput = hplNew( cLowLevelInputSDL,(mpLowLevelGraphics) ); mpLowLevelResources = hplNew( cLowLevelResourcesSDL,((cLowLevelGraphicsSDL *)mpLowLevelGraphics) ); // #ifdef WIN32 // mpLowLevelSound = hplNew( cLowLevelSoundFmod, () ); // #else mpLowLevelSound = hplNew( cLowLevelSoundOpenAL,() ); // #endif mpLowLevelPhysics = hplNew( cLowLevelPhysicsNewton,() ); #ifdef INCLUDE_HAPTIC mpLowLevelHaptic = hplNew( cLowLevelHapticHaptX,() ); #else mpLowLevelHaptic = NULL; #endif }
iAction* cButtonHandler::ActionFromTypeAndVal(const tString& asName,const tString& asType, const tString& asVal) { //Log("Action %s from %s\n",asName.c_str(),asType.c_str()); if(asType == "Keyboard") { return hplNew( cActionKeyboard, (asName,mpInit->mpGame->GetInput(),(eKey)cString::ToInt(asVal.c_str(),0)) ); } else if(asType == "MouseButton" || asType == "HapticDeviceButton") { if(mpInit->mbHasHaptics && asName != "MouseClick") { int lNum = cString::ToInt(asVal.c_str(),0); if(lNum==2)lNum = 2; else if(lNum==1)lNum = 1; return hplNew( cActionHaptic, (asName,mpInit->mpGame->GetHaptic(),lNum) ); } else { return hplNew( cActionMouseButton, (asName,mpInit->mpGame->GetInput(),(eMButton)cString::ToInt(asVal.c_str(),0)) ); } } return NULL; }
cPortalContainer::cPortalContainer() { mpEntityCallback = hplNew( cPortalContainerCallback, (this) ); mpNormalEntityCallback = hplNew( cPortalContainerEntityCallback, (this) ); mlSectorVisitCount =0; mlEntityIterateCount = 0; }
cRenderList::cRenderList(cGraphics *apGraphics) { mfFrameTime = 0; mTempNode.mpState = hplNew( iRenderState, () ); mlRenderCount=0; mlLastRenderCount =0; mpGraphics = apGraphics; m_poolRenderState = hplNew( cMemoryPool<iRenderState>, (3000, NULL)); m_poolRenderNode = hplNew( cMemoryPool<cRenderNode>, (3000, NULL)); g_poolRenderState = m_poolRenderState; g_poolRenderNode = m_poolRenderNode; }
iEntity3D* cAreaLoader_GameArea::Load(const tString &asName, const cVector3f &avSize, const cMatrixf &a_mtxTransform,cWorld3D *apWorld) { Log("Loading area %s\n", asName.c_str()); cGameArea *pArea = hplNew( cGameArea, (mpInit,asName) ); pArea->m_mtxOnLoadTransform = a_mtxTransform; //Create physics data iPhysicsWorld *pPhysicsWorld = apWorld->GetPhysicsWorld(); iCollideShape* pShape = pPhysicsWorld->CreateBoxShape(avSize,NULL); std::vector<iPhysicsBody*> vBodies; vBodies.push_back(pPhysicsWorld->CreateBody(asName,pShape)); vBodies[0]->SetCollide(false); vBodies[0]->SetCollideCharacter(false); vBodies[0]->SetMatrix(a_mtxTransform); vBodies[0]->SetUserData(pArea); pArea->SetBodies(vBodies); mpInit->mpMapHandler->AddGameEntity(pArea); Log("Loaded area %s\n",asName.c_str()); //Return something else later perhaps. return NULL; }
iEntity3D* cAreaLoader_GameLadder::Load(const tString &asName, const cVector3f &avSize, const cMatrixf &a_mtxTransform,cWorld3D *apWorld) { cGameLadder *pLadder = hplNew( cGameLadder, (mpInit,asName) ); pLadder->m_mtxOnLoadTransform = a_mtxTransform; //Create physics data iPhysicsWorld *pPhysicsWorld = apWorld->GetPhysicsWorld(); iCollideShape* pShape = pPhysicsWorld->CreateBoxShape(avSize,NULL); std::vector<iPhysicsBody*> vBodies; vBodies.push_back(pPhysicsWorld->CreateBody(asName,pShape)); vBodies[0]->SetCollide(false); vBodies[0]->SetCollideCharacter(false); vBodies[0]->SetMatrix(a_mtxTransform); vBodies[0]->SetUserData(pLadder); pLadder->SetBodies(vBodies); mpInit->mpMapHandler->AddGameEntity(pLadder); pLadder->Setup(); return NULL; }
cBackgroundImage* cGraphicsDrawer::AddBackgroundImage(const tString &asFileName, const tString &asMaterialName, const cVector3f& avPos, bool abTile,const cVector2f& avSize, const cVector2f& avPosPercent, const cVector2f& avVel) { cResourceImage* pImage = mpResources->GetImageManager()->CreateImage(asFileName); if(pImage==NULL) { FatalError("Couldn't load image '%s'!\n", asFileName.c_str()); return NULL; } iMaterial* pMat = mpMaterialHandler->Create(asMaterialName, eMaterialPicture_Image); if(pMat==NULL) { FatalError("Couldn't create material '%s'!\n", asMaterialName.c_str()); return NULL; } //mpResources->GetImageManager()->FlushAll(); pMat->SetImage(pImage, eMaterialTexture_Diffuse); cBackgroundImage *pBG = hplNew( cBackgroundImage, (pMat,avPos,abTile,avSize,avPosPercent,avVel) ); m_mapBackgroundImages.insert(tBackgroundImageMap::value_type(avPos.z,pBG)); return pBG; }
cGfxObject* cGraphicsDrawer::CreateGfxObject(iBitmap2D *apBmp, const tString &asMaterialName, bool abAddToList) { cResourceImage* pImage = mpResources->GetImageManager()->CreateFromBitmap("",apBmp); if(pImage==NULL) { FatalError("Couldn't create image\n"); return NULL; } iMaterial* pMat = mpMaterialHandler->Create(asMaterialName, eMaterialPicture_Image); if(pMat==NULL) { FatalError("Couldn't create material '%s'!\n", asMaterialName.c_str()); return NULL; } //mpResources->GetImageManager()->FlushAll(); pMat->SetImage(pImage, eMaterialTexture_Diffuse); cGfxObject* pObject = hplNew( cGfxObject,(pMat,"",true)); if(abAddToList) mlstGfxObjects.push_back(pObject); return pObject; }
iVertexBuffer* cVertexBufferOGL::CreateCopy(eVertexBufferUsageType aUsageType) { cVertexBufferOGL *pVtxBuff = hplNew( cVertexBufferOGL,(mpLowLevelGraphics, mVertexFlags,mDrawType,aUsageType, GetVertexNum(),GetIndexNum()) ); //Copy the vertices to the new buffer. for(int i=0; i < klNumOfVertexFlags; i++) { if(kvVertexFlags[i] & mVertexFlags) { int lElements = kvVertexElements[i]; if(mbTangents && kvVertexFlags[i] == eVertexFlag_Texture1) lElements=4; pVtxBuff->ResizeArray(kvVertexFlags[i], (int)mvVertexArray[i].size()); memcpy(pVtxBuff->GetArray(kvVertexFlags[i]), &mvVertexArray[i][0], mvVertexArray[i].size() * sizeof(float)); } } //Copy indices to the new buffer pVtxBuff->ResizeIndices(GetIndexNum()); memcpy(pVtxBuff->GetIndices(), GetIndices(), GetIndexNum() * sizeof(unsigned int) ); pVtxBuff->mbTangents = mbTangents; pVtxBuff->mbHasShadowDouble = mbHasShadowDouble; pVtxBuff->Compile(0); return pVtxBuff; }
cMapHandlerSoundCallback::cMapHandlerSoundCallback(cInit *apInit) { mpInit = apInit; /////////////////////////////////////////// //Load all sounds that can heard by enemies tString sFile = "sounds/EnemySounds.dat"; TiXmlDocument* pXmlDoc = hplNew( TiXmlDocument, (sFile.c_str()) ); if(pXmlDoc->LoadFile()==false){ Error("Couldn't load XML file '%s'!\n",sFile.c_str()); hplDelete( pXmlDoc ); return; } //Get the root. TiXmlElement* pRootElem = pXmlDoc->RootElement(); TiXmlElement* pChildElem = pRootElem->FirstChildElement(); for(; pChildElem != NULL; pChildElem = pChildElem->NextSiblingElement()) { tString sName = cString::ToString(pChildElem->Attribute("name"),""); mvEnemyHearableSounds.push_back(sName); } hplDelete( pXmlDoc ); }
cNumericalPanel::cNumericalPanel(cInit *apInit) : iUpdateable("NumericalPanel") { mpInit = apInit; mpDrawer = mpInit->mpGame->GetGraphics()->GetDrawer(); //Load graphics (use notebook background for now). mpGfxBackground = mpDrawer->CreateGfxObject("notebook_background.bmp","diffalpha2d"); mpGfxPanel = mpDrawer->CreateGfxObject("numpanel_panel.bmp","diffalpha2d"); cVector2f vPos(307, 205); for(int i=1; i<=12; ++i) { int lNum = i; if(i==10) lNum=-1; else if(i==11)lNum=0; else if(i==12) lNum=-2; mlstButtons.push_back(hplNew( cNumericalButton, (mpInit,this,vPos,cVector2f(62,30),lNum)) ); if(i%3 ==0) { vPos.y += (30 + 16); vPos.x = 307; } else { vPos.x += 62 + 16; } } Reset(); }
iResourceBase* cImageEntityManager::Create(const tString& asName) { tString sPath; cImageEntityData* pIEData; tString asNewName; BeginLoad(asName); asNewName = cString::SetFileExt(asName,"hed"); pIEData = static_cast<cImageEntityData*>(FindLoadedResource(asNewName,sPath)); if(pIEData==NULL && sPath!="") { pIEData = hplNew( cImageEntityData, (asNewName,mpGraphics,mpResources) ); if(pIEData->CreateFromFile(sPath,mvImageHandle)==false){ EndLoad(); return NULL; } if(pIEData)AddResource(pIEData); } else { } if(pIEData)pIEData->IncUserCount(); else Error("Couldn't load image entity data '%s'\n",asNewName.c_str()); EndLoad(); return pIEData; }
cScene* cSDLGameSetup::CreateScene(cGraphics* apGraphics, cResources *apResources, cSound* apSound, cPhysics *apPhysics, cSystem *apSystem,cAI *apAI, cHaptic *apHaptic) { cScene *pScene = hplNew( cScene, (apGraphics,apResources, apSound,apPhysics, apSystem,apAI,apHaptic) ); return pScene; }
bool cResources::LoadResourceDirsFile(const tString &asFile) { TiXmlDocument* pXmlDoc = hplNew( TiXmlDocument, (asFile.c_str()) ); if(pXmlDoc->LoadFile()==false) { Error("Couldn't load XML file '%s'!\n",asFile.c_str()); hplDelete( pXmlDoc); return false; } //Get the root. TiXmlElement* pRootElem = pXmlDoc->RootElement(); TiXmlElement* pChildElem = pRootElem->FirstChildElement(); for(; pChildElem != NULL; pChildElem = pChildElem->NextSiblingElement()) { tString sPath = cString::ToString(pChildElem->Attribute("Path"),""); if(sPath==""){ continue; } if(sPath[0]=='/' || sPath[0]=='\\') sPath = sPath.substr(1); AddResourceDir(sPath); } hplDelete(pXmlDoc); return true; }
void cAStarHandler::AddOpenNode(cAINode *apAINode, cAStarNode *apParent, float afDistance) { //TODO: free path check with dynamic objects here. //TODO: Some pooling here would be good. cAStarNode *pNode = hplNew( cAStarNode, (apAINode) ); //Check if it is in closed list. tAStarNodeSetIt it = m_setClosedList.find(pNode); if(it != m_setClosedList.end()){ hplDelete(pNode); return; } //Try to add it to the open list std::pair<tAStarNodeSetIt, bool> testPair = m_setOpenList.insert(pNode); if(testPair.second == false){ hplDelete(pNode); return; } pNode->mfDistance = afDistance; pNode->mfCost = Cost(afDistance,apAINode,apParent) + Heuristic(pNode->mpAINode->GetPosition(), mvGoal); pNode->mpParent = apParent; }
cSoundEntityData* cSoundEntityManager::CreateSoundEntity(const tString& asName) { tString sPath; cSoundEntityData* pSoundEntity; tString asNewName; BeginLoad(asName); asNewName = cString::SetFileExt(asName,"snt"); pSoundEntity = static_cast<cSoundEntityData*>(this->FindLoadedResource(asNewName,sPath)); if(pSoundEntity==NULL && sPath!="") { pSoundEntity = hplNew( cSoundEntityData, (asNewName) ); if(pSoundEntity->CreateFromFile(sPath)) { AddResource(pSoundEntity); } else { hplDelete(pSoundEntity); pSoundEntity =NULL; } } if(pSoundEntity)pSoundEntity->IncUserCount(); else Error("Couldn't create SoundEntity '%s'\n",asNewName.c_str()); EndLoad(); return pSoundEntity; }
cGfxObject* cGraphicsDrawer::CreateGfxObjectFromTexture( const tString &asFileName, const tString &asMaterialName, bool abAddToList) { iTexture *pTex = mpResources->GetTextureManager()->Create2D(asFileName,false); if(pTex==NULL) { FatalError("Couldn't create texture '%s'!\n", asFileName.c_str()); return NULL; } iMaterial* pMat = mpMaterialHandler->Create(asMaterialName, eMaterialPicture_Texture); if(pMat==NULL) { FatalError("Couldn't create material '%s'!\n", asMaterialName.c_str()); return NULL; } //mpResources->GetImageManager()->FlushAll(); pMat->SetTexture(pTex, eMaterialTexture_Diffuse); cGfxObject* pObject = hplNew( cGfxObject,(pMat,asFileName,false)); if(abAddToList) mlstGfxObjects.push_back(pObject); return pObject; }
iResourceBase* cTileSetManager::Create(const tString& asName) { tString sPath; cTileSet* pTileSet; tString asNewName; BeginLoad(asName); asNewName = cString::SetFileExt(asName,"tsd"); pTileSet = static_cast<cTileSet*>(this->FindLoadedResource(asNewName,sPath)); if(pTileSet==NULL && sPath!="") { pTileSet = hplNew( cTileSet, (asNewName,mpGraphics,mpResources) ); if(pTileSet->CreateFromFile(sPath)==false) { EndLoad(); return NULL; } AddResource(pTileSet); } if(pTileSet)pTileSet->IncUserCount(); else Error("Couldn't load tileset '%s'\n",asNewName.c_str()); EndLoad(); return pTileSet; }
cAnimationTrack* cAnimation::CreateTrack(const tString &asName, tAnimTransformFlag aFlags) { cAnimationTrack *pTrack = hplNew( cAnimationTrack,(asName, aFlags, this) ); mvTracks.push_back(pTrack); return pTrack; }
cSurfaceData *cPhysics::CreateSurfaceData(const tString& asName) { cSurfaceData *pData = hplNew( cSurfaceData, (asName, this,mpResources) ); m_mapSurfaceData.insert(tSurfaceDataMap::value_type(asName, pData)); return pData; }
cSectorVisibilityContainer* cPortalContainer::CreateVisibiltyFromBV(cBoundingVolume *apBV) { cSectorVisibilityContainer *pContainer = hplNew( cSectorVisibilityContainer, (eSectorVisibilityType_BV) ); pContainer->SetBV(*apBV); pContainer->Compute(this); return pContainer; }
cSectorVisibilityContainer* cPortalContainer::CreateVisibiltyFromFrustum(cFrustum *apFrustum) { cSectorVisibilityContainer *pContainer = hplNew( cSectorVisibilityContainer, (eSectorVisibilityType_Frustum) ); pContainer->SetFrustum(*apFrustum); pContainer->Compute(this); return pContainer; }
cCamera2D* cScene::CreateCamera2D(unsigned int alW,unsigned int alH) { cCamera2D *pCamera = hplNew( cCamera2D,(alW, alH) ); //Add Camera to list mlstCamera.push_back(pCamera); return pCamera; }
void cSound::Init( cResources *apResources, bool abUseHardware, bool abForceGeneric, bool abUseEnvAudio, int alMaxChannels, int alStreamUpdateFreq, bool abUseThreading, bool abUseVoiceManagement, int alMaxMonoSourceHint, int alMaxStereoSourceHint, int alStreamingBufferSize, int alStreamingBufferCount, bool abEnableLowLevelLog, tString asDeviceName) { mpResources = apResources; Log("Initializing Sound Module\n"); Log("--------------------------------------------------------\n"); mpLowLevelSound->Init( abUseHardware, abForceGeneric, abUseEnvAudio, alMaxChannels, alStreamUpdateFreq, abUseThreading, abUseVoiceManagement, alMaxMonoSourceHint, alMaxStereoSourceHint, alStreamingBufferSize, alStreamingBufferCount, abEnableLowLevelLog, asDeviceName); mpSoundHandler = hplNew( cSoundHandler, (mpLowLevelSound, mpResources) ); mpMusicHandler = hplNew( cMusicHandler, (mpLowLevelSound, mpResources) ); Log("--------------------------------------------------------\n\n"); }
bool cGridMap2D::AddEntity(iEntity2D* apEntity) { cGrid2DObject *pObject = hplNew( cGrid2DObject, (apEntity,this,mlHandleCount) ); apEntity->SetGrid2DObject(pObject); //Insert into the all map. m_mapAllObjects.insert(tGrid2DObjectMap::value_type(mlHandleCount, pObject)); mlHandleCount++; return true; }
cResources::cResources(iLowLevelResources *apLowLevelResources,iLowLevelGraphics *apLowLevelGraphics) : iUpdateable("Resources") { mpLowLevelResources = apLowLevelResources; mpLowLevelGraphics = apLowLevelGraphics; mpFileSearcher = hplNew( cFileSearcher, (mpLowLevelResources) ); mpDefaultEntity3DLoader = NULL; mpDefaultArea3DLoader = NULL; mpLanguageFile = NULL; }
cFrameBitmap *cImageManager::CreateBitmapFrame(cVector2l avSize) { iTexture *pTex = mpLowLevelGraphics->CreateTexture(false,eTextureType_Normal,eTextureTarget_2D); cFrameTexture *pTFrame = hplNew( cFrameTexture, (pTex,mlFrameHandle) ); iBitmap2D *pBmp = mpLowLevelGraphics->CreateBitmap2D(avSize, 32); cFrameBitmap *pBFrame = hplNew( cFrameBitmap, (pBmp,pTFrame,mlFrameHandle) ); mlstBitmapFrames.push_back(pBFrame); std::pair<tFrameTextureMap::iterator, bool> ret = m_mapTextureFrames.insert(tFrameTextureMap::value_type(mlFrameHandle, pTFrame)); if(ret.second == false) { Error("Could not add texture frame %d with handle %d! Handle already exist!\n",pTFrame, mlFrameHandle); } else { //Log("Added texture frame: %d\n",pTFrame); } mlFrameHandle++; return pBFrame; }
cMapHandler::cMapHandler(cInit *apInit) : iUpdateable("MapHandler") { mpInit = apInit; mbPreUpdating = false; mpScene = apInit->mpGame->GetScene(); mpResources = apInit->mpGame->GetResources(); mpWorldCache = hplNew( cWorldCache, (apInit) ); mfGameTime =0; mbDestroyingAll = false; Reset(); mpSoundCallback = hplNew( cMapHandlerSoundCallback, (apInit) ); cSoundEntity::AddGlobalCallback(mpSoundCallback); mpMapChangeTexture = mpInit->mpGame->GetResources()->GetTextureManager()->Create2D("other_mapchange.jpg",false); }
void cPreMenu::LoadConfig() { //////////////////////////////////////////////// //Load the document TiXmlDocument *pXmlDoc = hplNew( TiXmlDocument, ("config/startup.cfg") ); if(pXmlDoc->LoadFile()==false){ Error("Couldn't load XML document 'config/startup.cfg'\n"); hplDelete( pXmlDoc ); } //////////////////////////////////////////////// //Load the root TiXmlElement *pRootElem = pXmlDoc->FirstChildElement(); if(pRootElem==NULL){ Error("Couldn't load root from XML document 'config/startup.cfg'\n"); hplDelete( pXmlDoc ); } //////////////////////////////////////////////// //Load the Main element. TiXmlElement *pMainElem = pRootElem->FirstChildElement("Main"); if(pMainElem==NULL){ Error("Couldn't load Main element from XML document 'config/startup.cfg'\n"); hplDelete( pXmlDoc ); } mbShowText = cString::ToBool(pMainElem->Attribute("ShowText"),false); //////////////////////////////////////////////// //Load the Logos element. TiXmlElement *pLogosParentElem = pRootElem->FirstChildElement("Logos"); if(pLogosParentElem==NULL){ Error("Couldn't load Logs element from XML document 'config/startup.cfg'\n"); hplDelete( pXmlDoc ); } //////////////////////////////////////////////// //Get logos TiXmlElement *pLogoElem = pLogosParentElem->FirstChildElement("Logo"); for(; pLogoElem != NULL; pLogoElem = pLogoElem->NextSiblingElement("Logo")) { tString sFile = cString::ToString(pLogoElem->Attribute("File"),""); mvTexNames.push_back(sFile); //Log("Texture %s\n",sFile.c_str()); } hplDelete( pXmlDoc ); }