Initial commit
This commit is contained in:
165
engines/hpl1/engine/resources/AnimationManager.cpp
Normal file
165
engines/hpl1/engine/resources/AnimationManager.cpp
Normal file
@@ -0,0 +1,165 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#include "hpl1/engine/resources/AnimationManager.h"
|
||||
#include "hpl1/engine/graphics/Animation.h"
|
||||
#include "hpl1/engine/graphics/Mesh.h"
|
||||
#include "hpl1/engine/resources/FileSearcher.h"
|
||||
#include "hpl1/engine/resources/MeshLoaderHandler.h"
|
||||
#include "hpl1/engine/resources/Resources.h"
|
||||
#include "hpl1/engine/system/String.h"
|
||||
#include "hpl1/engine/system/System.h"
|
||||
#include "hpl1/engine/system/low_level_system.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cAnimationManager::cAnimationManager(cGraphics *apGraphic, cResources *apResources)
|
||||
: iResourceManager(apResources->GetFileSearcher(), apResources->GetLowLevel(),
|
||||
apResources->GetLowLevelSystem()) {
|
||||
mpGraphics = apGraphic;
|
||||
mpResources = apResources;
|
||||
}
|
||||
|
||||
cAnimationManager::~cAnimationManager() {
|
||||
DestroyAll();
|
||||
|
||||
Log(" Done with animations\n");
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cAnimation *cAnimationManager::CreateAnimation(const tString &asName) {
|
||||
tString sPath;
|
||||
cAnimation *pAnimation = NULL;
|
||||
tString asNewName;
|
||||
|
||||
BeginLoad(asName);
|
||||
|
||||
asNewName = asName;
|
||||
|
||||
// If the file is missing an extension, search for an existing file.
|
||||
if (cString::GetFileExt(asNewName) == "") {
|
||||
bool bFound = false;
|
||||
tStringVec *pTypes = mpResources->GetMeshLoaderHandler()->GetSupportedTypes();
|
||||
for (size_t i = 0; i < pTypes->size(); i++) {
|
||||
asNewName = cString::SetFileExt(asNewName, (*pTypes)[i]);
|
||||
sPath = mpResources->GetFileSearcher()->GetFilePath(asNewName);
|
||||
if (sPath != "") {
|
||||
bFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (bFound == false) {
|
||||
Error("Couldn't create mesh '%s'\n", asName.c_str());
|
||||
EndLoad();
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
pAnimation = static_cast<cAnimation *>(this->FindLoadedResource(asNewName, sPath));
|
||||
|
||||
if (pAnimation == NULL && sPath != "") {
|
||||
cMeshLoaderHandler *pMeshLoadHandler = mpResources->GetMeshLoaderHandler();
|
||||
|
||||
// try to load animation from mesh
|
||||
cMesh *pTempMesh = pMeshLoadHandler->LoadMesh(sPath, 0);
|
||||
if (pTempMesh == NULL) {
|
||||
Error("Couldn't load animation from '%s'\n", sPath.c_str());
|
||||
EndLoad();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (pTempMesh->GetAnimationNum() <= 0) {
|
||||
Error("No animations found in '%s'\n", sPath.c_str());
|
||||
hplDelete(pTempMesh);
|
||||
EndLoad();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pAnimation = pTempMesh->GetAnimation(0);
|
||||
pTempMesh->ClearAnimations(false);
|
||||
|
||||
hplDelete(pTempMesh);
|
||||
|
||||
AddResource(pAnimation);
|
||||
}
|
||||
|
||||
if (pAnimation)
|
||||
pAnimation->IncUserCount();
|
||||
else
|
||||
Error("Couldn't create animation '%s'\n", asNewName.c_str());
|
||||
|
||||
EndLoad();
|
||||
return pAnimation;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iResourceBase *cAnimationManager::Create(const tString &asName) {
|
||||
return CreateAnimation(asName);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cAnimationManager::Unload(iResourceBase *apResource) {
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cAnimationManager::Destroy(iResourceBase *apResource) {
|
||||
apResource->DecUserCount();
|
||||
|
||||
if (apResource->HasUsers() == false) {
|
||||
RemoveResource(apResource);
|
||||
hplDelete(apResource);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PRIVATE METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
} // namespace hpl
|
||||
57
engines/hpl1/engine/resources/AnimationManager.h
Normal file
57
engines/hpl1/engine/resources/AnimationManager.h
Normal file
@@ -0,0 +1,57 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#ifndef HPL_ANIMATION_MANAGER_H
|
||||
#define HPL_ANIMATION_MANAGER_H
|
||||
|
||||
#include "hpl1/engine/resources/ResourceManager.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class cGraphics;
|
||||
class cResources;
|
||||
class cAnimation;
|
||||
|
||||
class cAnimationManager : public iResourceManager {
|
||||
public:
|
||||
cAnimationManager(cGraphics *apGraphics, cResources *apResources);
|
||||
~cAnimationManager();
|
||||
|
||||
iResourceBase *Create(const tString &asName);
|
||||
cAnimation *CreateAnimation(const tString &asName);
|
||||
|
||||
void Destroy(iResourceBase *apResource);
|
||||
void Unload(iResourceBase *apResource);
|
||||
|
||||
private:
|
||||
cGraphics *mpGraphics;
|
||||
cResources *mpResources;
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_ANIMATION_MANAGER_H
|
||||
165
engines/hpl1/engine/resources/ConfigFile.cpp
Normal file
165
engines/hpl1/engine/resources/ConfigFile.cpp
Normal file
@@ -0,0 +1,165 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#include "hpl1/engine/resources/ConfigFile.h"
|
||||
#include "common/file.h"
|
||||
#include "hpl1/debug.h"
|
||||
#include "hpl1/engine/impl/tinyXML/tinyxml.h"
|
||||
#include "hpl1/engine/resources/FileSearcher.h"
|
||||
#include "hpl1/engine/system/String.h"
|
||||
#include "hpl1/engine/system/low_level_system.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cConfigFile::cConfigFile(const tWString &asFile) {
|
||||
msFile = asFile;
|
||||
mpXmlDoc = hplNew(TiXmlDocument, ());
|
||||
// mpFileSearcher = apFileSearcher;
|
||||
}
|
||||
|
||||
cConfigFile::~cConfigFile() {
|
||||
hplDelete(mpXmlDoc);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cConfigFile::Load() {
|
||||
Common::File cf;
|
||||
if (!cf.open(Common::Path(Common::String(msFile)))) {
|
||||
Hpl1::logWarning(Hpl1::kDebugFilePath, "file %S could not be opened", msFile.c_str());
|
||||
return false;
|
||||
}
|
||||
return mpXmlDoc->LoadFile(cf);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cConfigFile::Save() {
|
||||
return mpXmlDoc->SaveFile(Common::String(msFile).c_str());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cConfigFile::SetString(tString asLevel, tString asName, tString asVal) {
|
||||
TiXmlElement *pLevelElem = mpXmlDoc->FirstChildElement(asLevel.c_str());
|
||||
|
||||
if (pLevelElem == NULL) {
|
||||
TiXmlElement *pNodeChild = hplNew(TiXmlElement, (asLevel.c_str()));
|
||||
pLevelElem = static_cast<TiXmlElement *>(mpXmlDoc->InsertEndChild(*pNodeChild));
|
||||
hplDelete(pNodeChild);
|
||||
}
|
||||
|
||||
pLevelElem->SetAttribute(asName.c_str(), asVal.c_str());
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cConfigFile::SetInt(tString asLevel, tString asName, int alVal) {
|
||||
char sBuffer[40];
|
||||
snprintf(sBuffer, 40, "%d", alVal);
|
||||
|
||||
SetString(asLevel, asName, sBuffer);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cConfigFile::SetFloat(tString asLevel, tString asName, float afVal) {
|
||||
char sBuffer[40];
|
||||
snprintf(sBuffer, 40, "%f", afVal);
|
||||
|
||||
SetString(asLevel, asName, sBuffer);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cConfigFile::SetBool(tString asLevel, tString asName, bool abVal) {
|
||||
SetString(asLevel, asName, abVal ? "true" : "false");
|
||||
}
|
||||
|
||||
tString cConfigFile::GetString(tString asLevel, tString asName, tString asDefault) {
|
||||
const char *sVal = GetCharArray(asLevel, asName);
|
||||
if (sVal == NULL) {
|
||||
return asDefault;
|
||||
}
|
||||
|
||||
return sVal;
|
||||
}
|
||||
|
||||
int cConfigFile::GetInt(tString asLevel, tString asName, int alDefault) {
|
||||
const char *sVal = GetCharArray(asLevel, asName);
|
||||
if (sVal == NULL)
|
||||
return alDefault;
|
||||
|
||||
return cString::ToInt(sVal, alDefault);
|
||||
}
|
||||
|
||||
float cConfigFile::GetFloat(tString asLevel, tString asName, float afDefault) {
|
||||
const char *sVal = GetCharArray(asLevel, asName);
|
||||
if (sVal == NULL)
|
||||
return afDefault;
|
||||
|
||||
return cString::ToFloat(sVal, afDefault);
|
||||
}
|
||||
|
||||
bool cConfigFile::GetBool(tString asLevel, tString asName, bool abDefault) {
|
||||
const char *sVal = GetCharArray(asLevel, asName);
|
||||
if (sVal == NULL)
|
||||
return abDefault;
|
||||
|
||||
return cString::ToBool(sVal, abDefault);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PRIVATE METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
const char *cConfigFile::GetCharArray(tString asLevel, tString asName) {
|
||||
TiXmlElement *pLevelElem = mpXmlDoc->FirstChildElement(asLevel.c_str());
|
||||
if (pLevelElem == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return pLevelElem->Attribute(asName.c_str());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
} // namespace hpl
|
||||
75
engines/hpl1/engine/resources/ConfigFile.h
Normal file
75
engines/hpl1/engine/resources/ConfigFile.h
Normal file
@@ -0,0 +1,75 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#ifndef HPL_CONFIGFILE_H
|
||||
#define HPL_CONFIGFILE_H
|
||||
|
||||
#include "hpl1/engine/system/SystemTypes.h"
|
||||
|
||||
class TiXmlDocument;
|
||||
class cFileSearcher;
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class cConfigFile {
|
||||
public:
|
||||
cConfigFile(const tWString &asFile);
|
||||
~cConfigFile();
|
||||
|
||||
/**
|
||||
* Loads data from file
|
||||
* \return true if loading ws ok, else false
|
||||
*/
|
||||
bool Load();
|
||||
/**
|
||||
* Saves the data to file
|
||||
* \return true if loading ws ok, else false
|
||||
*/
|
||||
bool Save();
|
||||
|
||||
void SetString(tString asLevel, tString asName, tString asVal);
|
||||
void SetInt(tString asLevel, tString asName, int alVal);
|
||||
void SetFloat(tString asLevel, tString asName, float afVal);
|
||||
void SetBool(tString asLevel, tString asName, bool abVal);
|
||||
|
||||
tString GetString(tString asLevel, tString asName, tString asDefault);
|
||||
int GetInt(tString asLevel, tString asName, int alDefault);
|
||||
float GetFloat(tString asLevel, tString asName, float afDefault);
|
||||
bool GetBool(tString asLevel, tString asName, bool abDefault);
|
||||
|
||||
private:
|
||||
tWString msFile;
|
||||
// cFileSearcher *mpFileSearcher;
|
||||
|
||||
TiXmlDocument *mpXmlDoc;
|
||||
|
||||
const char *GetCharArray(tString asLevel, tString asName);
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_CONFIGFILE_H
|
||||
904
engines/hpl1/engine/resources/EntityLoader_Object.cpp
Normal file
904
engines/hpl1/engine/resources/EntityLoader_Object.cpp
Normal file
@@ -0,0 +1,904 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#include "hpl1/engine/resources/EntityLoader_Object.h"
|
||||
|
||||
#include "hpl1/engine/impl/tinyXML/tinyxml.h"
|
||||
#include "hpl1/engine/scene/World3D.h"
|
||||
#include "hpl1/engine/system/String.h"
|
||||
#include "hpl1/engine/system/low_level_system.h"
|
||||
|
||||
#include "hpl1/engine/physics/CollideShape.h"
|
||||
#include "hpl1/engine/physics/PhysicsBody.h"
|
||||
#include "hpl1/engine/physics/PhysicsController.h"
|
||||
#include "hpl1/engine/physics/PhysicsJoint.h"
|
||||
#include "hpl1/engine/physics/PhysicsJointBall.h"
|
||||
#include "hpl1/engine/physics/PhysicsJointHinge.h"
|
||||
#include "hpl1/engine/physics/PhysicsJointScrew.h"
|
||||
#include "hpl1/engine/physics/PhysicsJointSlider.h"
|
||||
#include "hpl1/engine/physics/PhysicsWorld.h"
|
||||
|
||||
#include "hpl1/engine/math/Math.h"
|
||||
|
||||
#include "hpl1/engine/resources/AnimationManager.h"
|
||||
#include "hpl1/engine/resources/FileSearcher.h"
|
||||
#include "hpl1/engine/resources/MaterialManager.h"
|
||||
#include "hpl1/engine/resources/MeshLoaderHandler.h"
|
||||
#include "hpl1/engine/resources/MeshManager.h"
|
||||
|
||||
#include "hpl1/engine/graphics/Animation.h"
|
||||
#include "hpl1/engine/graphics/Mesh.h"
|
||||
#include "hpl1/engine/graphics/SubMesh.h"
|
||||
#include "hpl1/engine/scene/AnimationState.h"
|
||||
#include "hpl1/engine/scene/MeshEntity.h"
|
||||
#include "hpl1/engine/scene/Node3D.h"
|
||||
|
||||
#include "hpl1/engine/scene/Light3DSpot.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iEntity3D *cEntityLoader_Object::Load(const tString &asName, TiXmlElement *apRootElem, const cMatrixf &a_mtxTransform,
|
||||
cWorld3D *apWorld, const tString &asFileName, bool abLoadReference) {
|
||||
////////////////////////////////////////
|
||||
// Init
|
||||
mvBodies.clear();
|
||||
mvJoints.clear();
|
||||
|
||||
mvParticleSystems.clear();
|
||||
mvBillboards.clear();
|
||||
mvSoundEntities.clear();
|
||||
mvLights.clear();
|
||||
mvBeams.clear();
|
||||
|
||||
mpEntity = NULL;
|
||||
mpMesh = NULL;
|
||||
|
||||
msFileName = asFileName;
|
||||
|
||||
cMatrixf transformMatrix = a_mtxTransform;
|
||||
if (asFileName == "boat_dynamicparaffin.ent") {
|
||||
// WORKAROUND: the light is placed inside another mesh, which results in janky movement
|
||||
// which wasn't present in the original game. The following just shifts the light down a bit.
|
||||
// The value was chosen by trial and error.
|
||||
transformMatrix.m[1][3] -= 0.07f;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
// Load MAIN
|
||||
|
||||
TiXmlElement *pMainElem = apRootElem->FirstChildElement("MAIN");
|
||||
if (pMainElem == NULL) {
|
||||
Error("Couldn't load element MAIN");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
msName = cString::ToString(pMainElem->Attribute("Name"), "");
|
||||
msSubType = cString::ToString(pMainElem->Attribute("Subtype"), "");
|
||||
|
||||
// Before load virtual call.
|
||||
BeforeLoad(apRootElem, transformMatrix, apWorld);
|
||||
|
||||
////////////////////////////////////////
|
||||
// Load GRAPHICS
|
||||
TiXmlElement *pGfxElem = apRootElem->FirstChildElement("GRAPHICS");
|
||||
if (pGfxElem == NULL) {
|
||||
Error("Couldn't load element GRAPHICS");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// load XML properties
|
||||
tString sMeshFile = cString::ToString(pGfxElem->Attribute("ModelFile"), "");
|
||||
bool bShadows = cString::ToBool(pGfxElem->Attribute("CastShadows"), true);
|
||||
|
||||
bool bAnimationLoop = cString::ToBool(pGfxElem->Attribute("AnimationLoop"), true);
|
||||
bool bAnimationRandStart = cString::ToBool(pGfxElem->Attribute("AnimationRandStart"), true);
|
||||
|
||||
mpMesh = apWorld->GetResources()->GetMeshManager()->CreateMesh(sMeshFile);
|
||||
if (mpMesh == NULL)
|
||||
return NULL;
|
||||
|
||||
////////////////////////////////////////
|
||||
// CREATE ENTITY
|
||||
|
||||
mpEntity = apWorld->CreateMeshEntity(asName, mpMesh);
|
||||
|
||||
// Set entity properties
|
||||
mpEntity->SetCastsShadows(bShadows);
|
||||
|
||||
////////////////////////////////////////
|
||||
// Load SUBMESHES
|
||||
TiXmlElement *pSubMeshElem = apRootElem->FirstChildElement("SUBMESH");
|
||||
for (; pSubMeshElem != NULL; pSubMeshElem = pSubMeshElem->NextSiblingElement("SUBMESH")) {
|
||||
tString sName = cString::ToString(pSubMeshElem->Attribute("Name"), "");
|
||||
tString sMaterialFile = cString::ToString(pSubMeshElem->Attribute("MaterialFile"), "");
|
||||
|
||||
cSubMeshEntity *pSubEntity = mpEntity->GetSubMeshEntityName(sName);
|
||||
if (pSubEntity == NULL) {
|
||||
Warning("Sub mesh '%s' does not exist in mesh '%s'!\n", sName.c_str(),
|
||||
mpMesh->GetName().c_str());
|
||||
continue;
|
||||
}
|
||||
|
||||
if (sMaterialFile != "") {
|
||||
iMaterial *pMaterial = apWorld->GetResources()->GetMaterialManager()->CreateMaterial(sMaterialFile);
|
||||
if (pMaterial) {
|
||||
pSubEntity->SetCustomMaterial(pMaterial);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
// Load ANIMATIONS
|
||||
TiXmlElement *pAnimRootElem = apRootElem->FirstChildElement("ANIMATIONS");
|
||||
if (pAnimRootElem) {
|
||||
mpEntity->ClearAnimations();
|
||||
|
||||
TiXmlElement *pAnimElem = pAnimRootElem->FirstChildElement("Animation");
|
||||
for (; pAnimElem != NULL; pAnimElem = pAnimElem->NextSiblingElement("Animation")) {
|
||||
tString sFile = cString::ToString(pAnimElem->Attribute("File"), "");
|
||||
tString sName = cString::ToString(pAnimElem->Attribute("Name"), "Unknown");
|
||||
float fSpeed = cString::ToFloat(pAnimElem->Attribute("Speed"), 1.0f);
|
||||
float fSpecialEventTime = cString::ToFloat(pAnimElem->Attribute("SpecialEventTime"), 0.0f);
|
||||
|
||||
cAnimationManager *pAnimManager = apWorld->GetResources()->GetAnimationManager();
|
||||
|
||||
cAnimation *pAnimation = pAnimManager->CreateAnimation(sFile);
|
||||
|
||||
if (pAnimation) {
|
||||
cAnimationState *pState = mpEntity->AddAnimation(pAnimation, sName, fSpeed);
|
||||
pState->SetSpecialEventTime(fSpecialEventTime);
|
||||
|
||||
////////////////////////////////
|
||||
// Get Events
|
||||
TiXmlElement *pAnimEventElem = pAnimElem->FirstChildElement("Event");
|
||||
for (; pAnimEventElem != NULL; pAnimEventElem = pAnimEventElem->NextSiblingElement("Event")) {
|
||||
cAnimationEvent *pEvent = pState->CreateEvent();
|
||||
|
||||
pEvent->mfTime = cString::ToFloat(pAnimEventElem->Attribute("Time"), 1.0f);
|
||||
pEvent->mType = GetAnimationEventType(pAnimEventElem->Attribute("Type"));
|
||||
pEvent->msValue = cString::ToString(pAnimEventElem->Attribute("Value"), "");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
// Load PHYSICS
|
||||
bool bUsingNodeBodies = false;
|
||||
|
||||
//////////////////////////////////
|
||||
// Properties for entities with joints
|
||||
if ((mpMesh->GetPhysicsJointNum() > 0 || mpMesh->HasSeveralBodies()) &&
|
||||
(mpMesh->GetAnimationNum() <= 0 || mpMesh->GetSkeleton())) {
|
||||
mpMesh->CreateJointsAndBodies(&mvBodies, mpEntity, &mvJoints, transformMatrix, apWorld->GetPhysicsWorld());
|
||||
|
||||
////////////////////////////////////
|
||||
// Properties for bodies
|
||||
TiXmlElement *pPhysicsElem = apRootElem->FirstChildElement("PHYSICS");
|
||||
for (; pPhysicsElem != NULL; pPhysicsElem = pPhysicsElem->NextSiblingElement("PHYSICS")) {
|
||||
iPhysicsBody *pBody = NULL;
|
||||
|
||||
// load XML properties
|
||||
tString sSubName = asName + "_" + cString::ToString(pPhysicsElem->Attribute("SubName"), "");
|
||||
|
||||
tString sMaterial = cString::ToString(pPhysicsElem->Attribute("Material"), "Default");
|
||||
|
||||
bool bStaticMeshCollider = cString::ToBool(pPhysicsElem->Attribute("StaticMeshCollider"), false);
|
||||
tString sColliderMesh = cString::ToString(pPhysicsElem->Attribute("ColliderMesh"), "");
|
||||
|
||||
if (bStaticMeshCollider) {
|
||||
cSubMesh *pSubMesh = mpMesh->GetSubMeshName(sColliderMesh);
|
||||
if (pSubMesh) {
|
||||
iCollideShape *pShape = apWorld->GetPhysicsWorld()->CreateMeshShape(
|
||||
pSubMesh->GetVertexBuffer());
|
||||
pBody = apWorld->GetPhysicsWorld()->CreateBody(sColliderMesh, pShape);
|
||||
} else {
|
||||
Error("Couldn't find sub mesh '%s' to create collision mesh\n", sColliderMesh.c_str());
|
||||
continue;
|
||||
}
|
||||
|
||||
cSubMeshEntity *pSubEntity = mpEntity->GetSubMeshEntityName(sColliderMesh);
|
||||
|
||||
pBody->CreateNode()->AddEntity(pSubEntity);
|
||||
pBody->SetMass(0);
|
||||
pBody->SetMatrix(transformMatrix);
|
||||
|
||||
pSubEntity->SetBody(pBody);
|
||||
|
||||
mvBodies.push_back(pBody);
|
||||
} else {
|
||||
pBody = (iPhysicsBody *)STLFindByName(mvBodies, sSubName);
|
||||
if (pBody == NULL) {
|
||||
Error("Cannot find sub entity '%s' in mesh '%s'\n", sSubName.c_str(), mpMesh->GetName().c_str());
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
SetBodyProperties(pBody, pPhysicsElem);
|
||||
|
||||
iPhysicsMaterial *pMaterial = apWorld->GetPhysicsWorld()->GetMaterialFromName(sMaterial);
|
||||
if (pMaterial) {
|
||||
pBody->SetMaterial(pMaterial);
|
||||
} else {
|
||||
Error("Physics Material '%s' for body '%s' in mesh '%s' doesn't exist!\n",
|
||||
sMaterial.c_str(), pBody->GetName().c_str(), mpMesh->GetName().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////
|
||||
// Properties for joints
|
||||
TiXmlElement *pJointElem = apRootElem->FirstChildElement("JOINT");
|
||||
for (; pJointElem != NULL; pJointElem = pJointElem->NextSiblingElement("JOINT")) {
|
||||
tString sName = asName + "_" + cString::ToString(pJointElem->Attribute("Name"), "");
|
||||
|
||||
iPhysicsJoint *pJoint = (iPhysicsJoint *)STLFindByName(mvJoints, sName);
|
||||
if (pJoint) {
|
||||
SetJointProperties(pJoint, pJointElem, apWorld);
|
||||
} else {
|
||||
Error("Joint '%s' not found in mesh '%s'\n", sName.c_str(), mpMesh->GetName().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
// for(size_t i=0; i< vJoints.size(); i++)
|
||||
//{
|
||||
// Log("Created joint: %s\n",vJoints[i]->GetName().c_str());
|
||||
// }
|
||||
}
|
||||
//////////////////////////////////
|
||||
// Properties for entities nodes and animation
|
||||
else if (mpMesh->GetNodeNum() > 0) {
|
||||
// Log("nodes and anim\n");
|
||||
iPhysicsBody *pRootBody = NULL;
|
||||
|
||||
bUsingNodeBodies = true;
|
||||
|
||||
mpMesh->CreateNodeBodies(&pRootBody, &mvBodies, mpEntity, apWorld->GetPhysicsWorld(),
|
||||
transformMatrix);
|
||||
|
||||
TiXmlElement *pPhysicsElem = apRootElem->FirstChildElement("PHYSICS");
|
||||
for (; pPhysicsElem != NULL; pPhysicsElem = pPhysicsElem->NextSiblingElement("PHYSICS")) {
|
||||
iPhysicsBody *pBody = NULL;
|
||||
|
||||
// load XML properties
|
||||
tString sSubName = cString::ToString(pPhysicsElem->Attribute("SubName"), "");
|
||||
if (sSubName != "")
|
||||
sSubName = asName + "_" + sSubName;
|
||||
else
|
||||
sSubName = asName;
|
||||
|
||||
tString sMaterial = cString::ToString(pPhysicsElem->Attribute("Material"), "Default");
|
||||
|
||||
bool bStaticMeshCollider = cString::ToBool(pPhysicsElem->Attribute("StaticMeshCollider"), false);
|
||||
tString sColliderMesh = cString::ToString(pPhysicsElem->Attribute("ColliderMesh"), "");
|
||||
|
||||
if (bStaticMeshCollider) {
|
||||
cSubMesh *pSubMesh = mpMesh->GetSubMeshName(sColliderMesh);
|
||||
if (pSubMesh) {
|
||||
iCollideShape *pShape = apWorld->GetPhysicsWorld()->CreateMeshShape(
|
||||
pSubMesh->GetVertexBuffer());
|
||||
pBody = apWorld->GetPhysicsWorld()->CreateBody(sColliderMesh, pShape);
|
||||
} else {
|
||||
Error("Couldn't find sub mesh '%s' to create collision mesh\n", sColliderMesh.c_str());
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
pBody = (iPhysicsBody *)STLFindByName(mvBodies, sSubName);
|
||||
if (pBody == NULL) {
|
||||
Error("Cannot find sub entity '%s' in mesh '%s'\n", sSubName.c_str(), mpMesh->GetName().c_str());
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
SetBodyProperties(pBody, pPhysicsElem);
|
||||
|
||||
// pBody->SetMass(0);
|
||||
// pBody->SetGravity(false);
|
||||
|
||||
iPhysicsMaterial *pMaterial = apWorld->GetPhysicsWorld()->GetMaterialFromName(sMaterial);
|
||||
if (pMaterial) {
|
||||
pBody->SetMaterial(pMaterial);
|
||||
} else {
|
||||
Error("Physics Material '%s' for body '%s' in mesh '%s' doesn't exist!\n",
|
||||
sMaterial.c_str(), pBody->GetName().c_str(), mpMesh->GetName().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
// Only allow for one joint
|
||||
if (mpMesh->GetPhysicsJointNum() == 1 && mvBodies.size() == 1) {
|
||||
iPhysicsJoint *pJoint = mpMesh->CreateJointInWorld(asName, mpMesh->GetPhysicsJoint(0),
|
||||
NULL, mvBodies[0], transformMatrix,
|
||||
apWorld->GetPhysicsWorld());
|
||||
if (pJoint) {
|
||||
TiXmlElement *pJointElem = apRootElem->FirstChildElement("JOINT");
|
||||
if (pJointElem) {
|
||||
SetJointProperties(pJoint, pJointElem, apWorld);
|
||||
}
|
||||
}
|
||||
} else if (mpMesh->GetPhysicsJointNum() > 1) {
|
||||
Error("Over 1 joints in '%s'!Animated body meshes only allow for one joint!\n",
|
||||
mpMesh->GetName().c_str());
|
||||
}
|
||||
|
||||
}
|
||||
//////////////////////////////////
|
||||
// Properties for other entities
|
||||
else {
|
||||
TiXmlElement *pPhysicsElem = apRootElem->FirstChildElement("PHYSICS");
|
||||
if (pPhysicsElem) {
|
||||
iPhysicsBody *pBody = NULL;
|
||||
|
||||
// load XML properties
|
||||
tString sSubName = cString::ToString(pPhysicsElem->Attribute("SubName"), "");
|
||||
|
||||
bool bCollides = cString::ToBool(pPhysicsElem->Attribute("Collides"), false);
|
||||
bool bHasPhysics = cString::ToBool(pPhysicsElem->Attribute("HasPhysics"), false);
|
||||
tString sMaterial = cString::ToString(pPhysicsElem->Attribute("Material"), "Default");
|
||||
|
||||
bool bStaticMeshCollider = cString::ToBool(pPhysicsElem->Attribute("StaticMeshCollider"), false);
|
||||
tString sColliderMesh = cString::ToString(pPhysicsElem->Attribute("ColliderMesh"), "");
|
||||
|
||||
// Check if this entity should have a body.
|
||||
if (bCollides) {
|
||||
if (bStaticMeshCollider) {
|
||||
cSubMesh *pSubMesh = mpMesh->GetSubMeshName(sColliderMesh);
|
||||
if (pSubMesh) {
|
||||
iCollideShape *pShape = apWorld->GetPhysicsWorld()->CreateMeshShape(
|
||||
pSubMesh->GetVertexBuffer());
|
||||
pBody = apWorld->GetPhysicsWorld()->CreateBody(sColliderMesh, pShape);
|
||||
} else {
|
||||
Error("Couldn't find sub mesh '%s' to create collision mesh\n", sColliderMesh.c_str());
|
||||
}
|
||||
} else {
|
||||
if (mpMesh->GetColliderNum() > 0) {
|
||||
pBody = apWorld->GetPhysicsWorld()->CreateBody(asName,
|
||||
mpMesh->CreateCollideShape(apWorld->GetPhysicsWorld()));
|
||||
} else {
|
||||
Warning("No collider found for '%s'\n", asFileName.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
if (pBody) {
|
||||
iPhysicsMaterial *pMaterial = apWorld->GetPhysicsWorld()->GetMaterialFromName(sMaterial);
|
||||
if (pMaterial) {
|
||||
pBody->SetMaterial(pMaterial);
|
||||
} else {
|
||||
Error("Physics Material '%s' for body '%s' in mesh '%s' doesn't exist!\n",
|
||||
sMaterial.c_str(), pBody->GetName().c_str(), mpMesh->GetName().c_str());
|
||||
}
|
||||
|
||||
SetBodyProperties(pBody, pPhysicsElem);
|
||||
|
||||
if (bHasPhysics) {
|
||||
} else {
|
||||
pBody->SetMass(0);
|
||||
}
|
||||
|
||||
pBody->CreateNode()->AddEntity(mpEntity);
|
||||
// cMatrixf mtxTemp = transformMatrix;
|
||||
// Log("-- Body: %s Mtx: %s\n", pBody->GetName().c_str(),
|
||||
// mtxTemp.ToString().c_str());
|
||||
// pBody->GetBV()->GetSize().ToString().c_str());
|
||||
|
||||
pBody->SetMatrix(transformMatrix);
|
||||
|
||||
mpEntity->SetBody(pBody);
|
||||
|
||||
mvBodies.push_back(pBody);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
// Create lights
|
||||
for (int i = 0; i < mpMesh->GetLightNum(); i++) {
|
||||
iLight3D *pLight = mpMesh->CreateLightInWorld(asName, mpMesh->GetLight(i), mpEntity, apWorld);
|
||||
if (pLight)
|
||||
mvLights.push_back(pLight);
|
||||
}
|
||||
|
||||
// Iterate light elements
|
||||
TiXmlElement *pLightElem = apRootElem->FirstChildElement("LIGHT");
|
||||
for (; pLightElem != NULL; pLightElem = pLightElem->NextSiblingElement("LIGHT")) {
|
||||
tString sName = cString::ToString(pLightElem->Attribute("Name"), "");
|
||||
|
||||
iLight3D *pLight = (iLight3D *)STLFindByName(mvLights, asName + "_" + sName);
|
||||
if (pLight == NULL) {
|
||||
Error("Couldn't find light %s among entity %s type: %s lights\n", sName.c_str(), asName.c_str(), asFileName.c_str());
|
||||
continue;
|
||||
}
|
||||
|
||||
pLight->SetFarAttenuation(cString::ToFloat(pLightElem->Attribute("Attenuation"),
|
||||
pLight->GetFarAttenuation()));
|
||||
pLight->SetDiffuseColor(cString::ToColor(pLightElem->Attribute("Color"),
|
||||
pLight->GetDiffuseColor()));
|
||||
pLight->SetCastShadows(cString::ToBool(pLightElem->Attribute("CastShadows"),
|
||||
pLight->GetCastShadows()));
|
||||
|
||||
if (pLight->GetLightType() == eLight3DType_Spot) {
|
||||
cLight3DSpot *pSpotLight = static_cast<cLight3DSpot *>(pLight);
|
||||
|
||||
pSpotLight->SetFOV(cString::ToFloat(pLightElem->Attribute("FOV"),
|
||||
pSpotLight->GetFOV()));
|
||||
pSpotLight->SetAspect(cString::ToFloat(pLightElem->Attribute("Aspect"),
|
||||
pSpotLight->GetAspect()));
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
// Create billboards
|
||||
for (int i = 0; i < mpMesh->GetBillboardNum(); i++) {
|
||||
cBillboard *pBill = mpMesh->CreateBillboardInWorld(asName, mpMesh->GetBillboard(i), mpEntity, apWorld);
|
||||
if (pBill)
|
||||
mvBillboards.push_back(pBill);
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
// Create beams
|
||||
for (int i = 0; i < mpMesh->GetBeamNum(); i++) {
|
||||
cBeam *pBeam = mpMesh->CreateBeamInWorld(asName, mpMesh->GetBeam(i), mpEntity, apWorld);
|
||||
if (pBeam)
|
||||
mvBeams.push_back(pBeam);
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
// Create particle systems
|
||||
for (int i = 0; i < mpMesh->GetParticleSystemNum(); i++) {
|
||||
cParticleSystem3D *pPS = mpMesh->CreateParticleSystemInWorld(asName, mpMesh->GetParticleSystem(i), mpEntity, apWorld);
|
||||
if (pPS)
|
||||
mvParticleSystems.push_back(pPS);
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
// Create sound entities
|
||||
for (int i = 0; i < mpMesh->GetSoundEntityNum(); i++) {
|
||||
cSoundEntity *pSound = mpMesh->CreateSoundEntityInWorld(asName, mpMesh->GetSoundEntity(i), mpEntity, apWorld);
|
||||
if (pSound)
|
||||
mvSoundEntities.push_back(pSound);
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
// ATTACH BILLBOARDS
|
||||
TiXmlElement *pAttachElem = apRootElem->FirstChildElement("ATTACH_BILLBOARDS");
|
||||
if (pAttachElem != NULL) {
|
||||
TiXmlElement *pPairElem = pAttachElem->FirstChildElement();
|
||||
for (; pPairElem != NULL; pPairElem = pPairElem->NextSiblingElement()) {
|
||||
tString sLight = asName + "_" + cString::ToString(pPairElem->Attribute("Light"), "");
|
||||
tString sBillboard = asName + "_" + cString::ToString(pPairElem->Attribute("Billboard"), "");
|
||||
|
||||
iLight3D *pLight = apWorld->GetLight(sLight);
|
||||
if (pLight == NULL) {
|
||||
Warning("Couldn't find light '%s'\n", sLight.c_str());
|
||||
continue;
|
||||
}
|
||||
|
||||
cBillboard *pBillboard = apWorld->GetBillboard(sBillboard);
|
||||
if (pBillboard == NULL) {
|
||||
Warning("Couldn't find billboard '%s'\n", sBillboard.c_str());
|
||||
continue;
|
||||
}
|
||||
pLight->AttachBillboard(pBillboard);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
// Set matrix on entity if there are no bodies.
|
||||
if ((mvBodies.size() <= 0 || bUsingNodeBodies) && mpEntity->GetBody() == NULL) {
|
||||
mpEntity->SetMatrix(transformMatrix);
|
||||
|
||||
// to make sure everything is in place.
|
||||
mpEntity->UpdateLogic(0);
|
||||
}
|
||||
|
||||
// Play animation if there is any.
|
||||
if (mpEntity->GetAnimationStateNum() > 0) {
|
||||
cAnimationState *pAnimState = mpEntity->GetAnimationState(0);
|
||||
|
||||
pAnimState->SetActive(true);
|
||||
pAnimState->SetLoop(bAnimationLoop);
|
||||
if (bAnimationRandStart)
|
||||
pAnimState->SetTimePosition(cMath::RandRectf(0, pAnimState->GetLength()));
|
||||
else
|
||||
pAnimState->SetTimePosition(0);
|
||||
} else if (mpMesh->GetSkeleton()) {
|
||||
mpEntity->SetSkeletonPhysicsActive(true);
|
||||
}
|
||||
|
||||
// After load virtual call.
|
||||
// This is where the user adds extra stuff.
|
||||
AfterLoad(apRootElem, transformMatrix, apWorld);
|
||||
|
||||
////////////////////////////////////////
|
||||
// Create references
|
||||
if (abLoadReference) {
|
||||
cMeshEntity *pEntityCopy = mpEntity;
|
||||
cMesh *pMeshCopy = mpMesh;
|
||||
for (int i = 0; i < pMeshCopy->GetReferenceNum(); i++) {
|
||||
/*iEntity3D *pRef = */
|
||||
mpMesh->CreateReferenceInWorld(asName, pMeshCopy->GetReference(i), pEntityCopy,
|
||||
apWorld, transformMatrix);
|
||||
// if(pPS) mvParticleSystems.push_back(pPS);
|
||||
}
|
||||
return pEntityCopy;
|
||||
} else {
|
||||
return mpEntity;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cEntityLoader_Object::SetBodyProperties(iPhysicsBody *apBody, TiXmlElement *apPhysicsElem) {
|
||||
float fMass = cString::ToFloat(apPhysicsElem->Attribute("Mass"), 1);
|
||||
tString sInertiaVec = cString::ToString(apPhysicsElem->Attribute("InertiaScale"), "1 1 1");
|
||||
|
||||
float fAngluarDamping = cString::ToFloat(apPhysicsElem->Attribute("AngularDamping"), 0.1f);
|
||||
float fLinearDamping = cString::ToFloat(apPhysicsElem->Attribute("LinearDamping"), 0.1f);
|
||||
|
||||
bool bBlocksSound = cString::ToBool(apPhysicsElem->Attribute("BlocksSound"), false);
|
||||
bool bCollideCharacter = cString::ToBool(apPhysicsElem->Attribute("CollideCharacter"), true);
|
||||
bool bCollide = cString::ToBool(apPhysicsElem->Attribute("CollideNonCharacter"), true);
|
||||
|
||||
bool bHasGravity = cString::ToBool(apPhysicsElem->Attribute("HasGravity"), true);
|
||||
|
||||
float fMaxAngluarSpeed = cString::ToFloat(apPhysicsElem->Attribute("MaxAngluarSpeed"), 0);
|
||||
float fMaxLinearSpeed = cString::ToFloat(apPhysicsElem->Attribute("MaxLinearSpeed"), 0);
|
||||
|
||||
bool bContinuousCollision = cString::ToBool(apPhysicsElem->Attribute("ContinuousCollision"), true);
|
||||
|
||||
bool bPushedByCharacterGravity = cString::ToBool(apPhysicsElem->Attribute("PushedByCharacterGravity"), false);
|
||||
#if 0
|
||||
float fAutoDisableLinearThreshold = cString::ToFloat(apPhysicsElem->Attribute("AutoDisableLinearThreshold"), 0.1f);
|
||||
float fAutoDisableAngularThreshold = cString::ToFloat(apPhysicsElem->Attribute("AutoDisableAngularThreshold"), 0.1f);
|
||||
int lAutoDisableNumSteps = cString::ToInt(apPhysicsElem->Attribute("AutoDisableNumSteps"), 10);
|
||||
#endif
|
||||
bool bVolatile = cString::ToBool(apPhysicsElem->Attribute("Volatile"), false);
|
||||
|
||||
bool bCanAttachCharacter = cString::ToBool(apPhysicsElem->Attribute("CanAttachCharacter"), false);
|
||||
|
||||
tFloatVec vInertiaScale;
|
||||
cString::GetFloatVec(sInertiaVec, vInertiaScale);
|
||||
|
||||
apBody->SetMass(fMass);
|
||||
apBody->SetAngularDamping(fAngluarDamping);
|
||||
apBody->SetLinearDamping(fLinearDamping);
|
||||
apBody->SetBlocksSound(bBlocksSound);
|
||||
apBody->SetCollideCharacter(bCollideCharacter);
|
||||
apBody->SetCollide(bCollide);
|
||||
apBody->SetGravity(bHasGravity);
|
||||
|
||||
apBody->SetVolatile(bVolatile);
|
||||
|
||||
apBody->SetCanAttachCharacter(bCanAttachCharacter);
|
||||
|
||||
apBody->SetContinuousCollision(bContinuousCollision);
|
||||
#if 0
|
||||
apBody->SetAutoDisableLinearThreshold(fAutoDisableLinearThreshold);
|
||||
apBody->SetAutoDisableAngularThreshold(fAutoDisableAngularThreshold);
|
||||
apBody->SetAutoDisableNumSteps(lAutoDisableNumSteps);
|
||||
#endif
|
||||
apBody->SetPushedByCharacterGravity(bPushedByCharacterGravity);
|
||||
|
||||
// Log("Body %s contin: %d\n",apBody->GetName().c_str(), apBody->GetContinuousCollision()?1:0);
|
||||
|
||||
apBody->SetMaxAngularSpeed(fMaxAngluarSpeed);
|
||||
apBody->SetMaxLinearSpeed(fMaxLinearSpeed);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cEntityLoader_Object::SetJointProperties(iPhysicsJoint *pJoint, TiXmlElement *pJointElem,
|
||||
cWorld3D *apWorld) {
|
||||
float fMinValue = cString::ToFloat(pJointElem->Attribute("MinValue"), -1);
|
||||
float fMaxValue = cString::ToFloat(pJointElem->Attribute("MaxValue"), -1);
|
||||
|
||||
tString sMoveSound = cString::ToString(pJointElem->Attribute("MoveSound"), "");
|
||||
float fMinMoveSpeed = cString::ToFloat(pJointElem->Attribute("MinMoveSpeed"), 0.5f);
|
||||
float fMinMoveFreq = cString::ToFloat(pJointElem->Attribute("MinMoveFreq"), 0.9f);
|
||||
float fMinMoveVolume = cString::ToFloat(pJointElem->Attribute("MinMoveVolume"), 0.3f);
|
||||
float fMinMoveFreqSpeed = cString::ToFloat(pJointElem->Attribute("MinMoveFreqSpeed"), 0.9f);
|
||||
float fMaxMoveFreq = cString::ToFloat(pJointElem->Attribute("MaxMoveFreq"), 1.1f);
|
||||
float fMaxMoveVolume = cString::ToFloat(pJointElem->Attribute("MaxMoveVolume"), 1.0f);
|
||||
float fMaxMoveFreqSpeed = cString::ToFloat(pJointElem->Attribute("MaxMoveFreqSpeed"), 1.1f);
|
||||
float fMiddleMoveSpeed = cString::ToFloat(pJointElem->Attribute("MiddleMoveSpeed"), 1.0f);
|
||||
float fMiddleMoveVolume = cString::ToFloat(pJointElem->Attribute("MiddleMoveVolume"), 1.0f);
|
||||
tString sMoveType = cString::ToString(pJointElem->Attribute("MoveType"), "Linear");
|
||||
sMoveType = cString::ToLowerCase(sMoveType);
|
||||
|
||||
float fStickyMinDistance = cString::ToFloat(pJointElem->Attribute("StickyMinDistance"), 0.0f);
|
||||
float fStickyMaxDistance = cString::ToFloat(pJointElem->Attribute("StickyMaxDistance"), 0.0f);
|
||||
|
||||
bool bBreakable = cString::ToBool(pJointElem->Attribute("Breakable"), false);
|
||||
tString sBreakSound = cString::ToString(pJointElem->Attribute("BreakSound"), "");
|
||||
float fBreakForce = cString::ToFloat(pJointElem->Attribute("BreakForce"), 1000);
|
||||
|
||||
bool bLimitAutoSleep = cString::ToBool(pJointElem->Attribute("LimitAutoSleep"), false);
|
||||
float fLimitAutoSleepDist = cString::ToFloat(pJointElem->Attribute("LimitAutoSleepDist"), 0.02f);
|
||||
int lLimitAutoSleepNumSteps = cString::ToInt(pJointElem->Attribute("LimitAutoSleepNumSteps"), 10);
|
||||
|
||||
pJoint->SetMoveSound(sMoveSound);
|
||||
pJoint->SetMinMoveSpeed(fMinMoveSpeed);
|
||||
pJoint->SetMinMoveFreq(fMinMoveFreq);
|
||||
pJoint->SetMinMoveVolume(fMinMoveVolume);
|
||||
pJoint->SetMinMoveFreqSpeed(fMinMoveFreqSpeed);
|
||||
pJoint->SetMaxMoveFreq(fMaxMoveFreq);
|
||||
pJoint->SetMaxMoveVolume(fMaxMoveVolume);
|
||||
pJoint->SetMaxMoveFreqSpeed(fMaxMoveFreqSpeed);
|
||||
pJoint->SetMiddleMoveSpeed(fMiddleMoveSpeed);
|
||||
pJoint->SetMiddleMoveVolume(fMiddleMoveVolume);
|
||||
pJoint->SetMoveSpeedType(sMoveType == "angular" ? ePhysicsJointSpeed_Angular : ePhysicsJointSpeed_Linear);
|
||||
|
||||
pJoint->GetMaxLimit()->msSound = cString::ToString(pJointElem->Attribute("MaxLimit_Sound"), "");
|
||||
pJoint->GetMaxLimit()->mfMaxSpeed = cString::ToFloat(pJointElem->Attribute("MaxLimit_MaxSpeed"), 10.0f);
|
||||
pJoint->GetMaxLimit()->mfMinSpeed = cString::ToFloat(pJointElem->Attribute("MaxLimit_MinSpeed"), 20.0f);
|
||||
|
||||
pJoint->GetMinLimit()->msSound = cString::ToString(pJointElem->Attribute("MinLimit_Sound"), "");
|
||||
pJoint->GetMinLimit()->mfMaxSpeed = cString::ToFloat(pJointElem->Attribute("MinLimit_MaxSpeed"), 10.0f);
|
||||
pJoint->GetMinLimit()->mfMinSpeed = cString::ToFloat(pJointElem->Attribute("MinLimit_MinSpeed"), 20.0f);
|
||||
|
||||
pJoint->SetStickyMinDistance(fStickyMinDistance);
|
||||
pJoint->SetStickyMaxDistance(fStickyMaxDistance);
|
||||
|
||||
pJoint->SetBreakable(bBreakable);
|
||||
pJoint->SetBreakForce(fBreakForce);
|
||||
pJoint->SetBreakSound(sBreakSound);
|
||||
|
||||
pJoint->SetLimitAutoSleep(bLimitAutoSleep);
|
||||
pJoint->SetLimitAutoSleepDist(fLimitAutoSleepDist);
|
||||
pJoint->SetLimitAutoSleepNumSteps(lLimitAutoSleepNumSteps);
|
||||
|
||||
// Set min/max values
|
||||
if (fMaxValue >= 0 && fMinValue >= 0) {
|
||||
switch (pJoint->GetType()) {
|
||||
case ePhysicsJointType_Ball: {
|
||||
iPhysicsJointBall *pBallJoint = static_cast<iPhysicsJointBall *>(pJoint);
|
||||
pBallJoint->SetConeLimits(pBallJoint->GetPinDir(), cMath::ToRad(fMinValue), cMath::ToRad(fMaxValue));
|
||||
break;
|
||||
}
|
||||
case ePhysicsJointType_Hinge: {
|
||||
iPhysicsJointHinge *pHingeJoint = static_cast<iPhysicsJointHinge *>(pJoint);
|
||||
pHingeJoint->SetMaxAngle(cMath::ToRad(fMaxValue));
|
||||
pHingeJoint->SetMinAngle(cMath::ToRad(-fMinValue));
|
||||
break;
|
||||
}
|
||||
case ePhysicsJointType_Screw: {
|
||||
iPhysicsJointScrew *pScrewJoint = static_cast<iPhysicsJointScrew *>(pJoint);
|
||||
pScrewJoint->SetMinDistance(-fMinValue / 100);
|
||||
pScrewJoint->SetMaxDistance(fMaxValue / 100);
|
||||
break;
|
||||
}
|
||||
case ePhysicsJointType_Slider: {
|
||||
iPhysicsJointSlider *pSliderJoint = static_cast<iPhysicsJointSlider *>(pJoint);
|
||||
pSliderJoint->SetMinDistance(-fMinValue / 100);
|
||||
pSliderJoint->SetMaxDistance(fMaxValue / 100);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Load all controllers
|
||||
TiXmlElement *pControllerElem = pJointElem->FirstChildElement("Controller");
|
||||
for (; pControllerElem != NULL; pControllerElem = pControllerElem->NextSiblingElement("Controller")) {
|
||||
LoadController(pJoint, apWorld->GetPhysicsWorld(), pControllerElem);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
ePhysicsControllerType GetControllerType(const char *apString) {
|
||||
if (apString == NULL)
|
||||
return ePhysicsControllerType_LastEnum;
|
||||
|
||||
tString sName = apString;
|
||||
|
||||
if (sName == "Pid")
|
||||
return ePhysicsControllerType_Pid;
|
||||
else if (sName == "Spring")
|
||||
return ePhysicsControllerType_Spring;
|
||||
|
||||
return ePhysicsControllerType_LastEnum;
|
||||
}
|
||||
|
||||
/////////////////////////
|
||||
|
||||
static ePhysicsControllerInput GetControllerInput(const char *apString) {
|
||||
if (apString == NULL)
|
||||
return ePhysicsControllerInput_LastEnum;
|
||||
|
||||
tString sName = apString;
|
||||
|
||||
if (sName == "JointAngle")
|
||||
return ePhysicsControllerInput_JointAngle;
|
||||
else if (sName == "JointDist")
|
||||
return ePhysicsControllerInput_JointDist;
|
||||
else if (sName == "LinearSpeed")
|
||||
return ePhysicsControllerInput_LinearSpeed;
|
||||
else if (sName == "AngularSpeed")
|
||||
return ePhysicsControllerInput_AngularSpeed;
|
||||
|
||||
return ePhysicsControllerInput_LastEnum;
|
||||
}
|
||||
|
||||
/////////////////////////
|
||||
|
||||
static ePhysicsControllerOutput GetControllerOutput(const char *apString) {
|
||||
if (apString == NULL)
|
||||
return ePhysicsControllerOutput_LastEnum;
|
||||
|
||||
tString sName = apString;
|
||||
|
||||
if (sName == "Force")
|
||||
return ePhysicsControllerOutput_Force;
|
||||
else if (sName == "Torque")
|
||||
return ePhysicsControllerOutput_Torque;
|
||||
|
||||
return ePhysicsControllerOutput_LastEnum;
|
||||
}
|
||||
|
||||
/////////////////////////
|
||||
|
||||
static ePhysicsControllerAxis GetControllerAxis(const char *apString) {
|
||||
if (apString == NULL)
|
||||
return ePhysicsControllerAxis_LastEnum;
|
||||
|
||||
tString sName = apString;
|
||||
|
||||
if (sName == "X")
|
||||
return ePhysicsControllerAxis_X;
|
||||
else if (sName == "Y")
|
||||
return ePhysicsControllerAxis_Y;
|
||||
else if (sName == "Z")
|
||||
return ePhysicsControllerAxis_Z;
|
||||
|
||||
return ePhysicsControllerAxis_LastEnum;
|
||||
}
|
||||
|
||||
/////////////////////////
|
||||
|
||||
static ePhysicsControllerEnd GetControllerEnd(const char *apString) {
|
||||
if (apString == NULL)
|
||||
return ePhysicsControllerEnd_Null;
|
||||
|
||||
tString sName = apString;
|
||||
|
||||
if (sName == "OnMax")
|
||||
return ePhysicsControllerEnd_OnMax;
|
||||
else if (sName == "OnMin")
|
||||
return ePhysicsControllerEnd_OnMin;
|
||||
else if (sName == "OnDest")
|
||||
return ePhysicsControllerEnd_OnDest;
|
||||
|
||||
return ePhysicsControllerEnd_Null;
|
||||
}
|
||||
|
||||
/////////////////////////
|
||||
|
||||
void cEntityLoader_Object::LoadController(iPhysicsJoint *apJoint, iPhysicsWorld *apPhysicsWorld,
|
||||
TiXmlElement *apElem) {
|
||||
//////////////////////////////
|
||||
// Get the properties
|
||||
tString sName = cString::ToString(apElem->Attribute("Name"), "");
|
||||
bool bActive = cString::ToBool(apElem->Attribute("Active"), false);
|
||||
|
||||
ePhysicsControllerType CtrlType = GetControllerType(apElem->Attribute("Type"));
|
||||
float fA = cString::ToFloat(apElem->Attribute("A"), 0);
|
||||
float fB = cString::ToFloat(apElem->Attribute("B"), 0);
|
||||
float fC = cString::ToFloat(apElem->Attribute("C"), 0);
|
||||
int lIntegralSize = cString::ToInt(apElem->Attribute("IntegralSize"), 1);
|
||||
|
||||
ePhysicsControllerInput CtrlInput = GetControllerInput(apElem->Attribute("Input"));
|
||||
ePhysicsControllerAxis CtrlInputAxis = GetControllerAxis(apElem->Attribute("InputAxis"));
|
||||
float fDestValue = cString::ToFloat(apElem->Attribute("DestValue"), 0);
|
||||
float fMaxOutput = cString::ToFloat(apElem->Attribute("MaxOutput"), 0);
|
||||
|
||||
ePhysicsControllerOutput CtrlOutput = GetControllerOutput(apElem->Attribute("Output"));
|
||||
ePhysicsControllerAxis CtrlOutputAxis = GetControllerAxis(apElem->Attribute("OutputAxis"));
|
||||
bool bMulMassWithOutput = cString::ToBool(apElem->Attribute("MulMassWithOutput"), false);
|
||||
|
||||
ePhysicsControllerEnd CtrlEnd = GetControllerEnd(apElem->Attribute("EndType"));
|
||||
tString sNextCtrl = cString::ToString(apElem->Attribute("NextController"), "");
|
||||
|
||||
bool bLogInfo = cString::ToBool(apElem->Attribute("LogInfo"), false);
|
||||
|
||||
// Convert degrees to radians.
|
||||
if (CtrlInput == ePhysicsControllerInput_JointAngle) {
|
||||
fDestValue = cMath::ToRad(fDestValue);
|
||||
}
|
||||
|
||||
//////////////////////////////
|
||||
// Create the controller
|
||||
iPhysicsController *pController = apPhysicsWorld->CreateController(sName);
|
||||
|
||||
pController->SetType(CtrlType);
|
||||
|
||||
pController->SetA(fA);
|
||||
pController->SetB(fB);
|
||||
pController->SetC(fC);
|
||||
|
||||
pController->SetPidIntegralSize(lIntegralSize);
|
||||
|
||||
pController->SetActive(bActive);
|
||||
pController->SetInputType(CtrlInput, CtrlInputAxis);
|
||||
pController->SetDestValue(fDestValue);
|
||||
|
||||
pController->SetOutputType(CtrlOutput, CtrlOutputAxis);
|
||||
pController->SetMaxOutput(fMaxOutput);
|
||||
pController->SetMulMassWithOutput(bMulMassWithOutput);
|
||||
|
||||
pController->SetEndType(CtrlEnd);
|
||||
pController->SetNextController(sNextCtrl);
|
||||
|
||||
pController->SetLogInfo(bLogInfo);
|
||||
|
||||
apJoint->AddController(pController);
|
||||
|
||||
// Log("Controller: %s active: %d val: %f %f %f input: %d %d output: %d %d\n",
|
||||
// sName.c_str(),bActive, fA,fB,fC, (int)CtrlInput, (int)CtrlInputAxis, (int)CtrlOutput,(int)CtrlOutputAxis);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
eAnimationEventType cEntityLoader_Object::GetAnimationEventType(const char *apString) {
|
||||
if (apString == NULL)
|
||||
return eAnimationEventType_LastEnum;
|
||||
|
||||
tString sName = apString;
|
||||
sName = cString::ToLowerCase(sName);
|
||||
|
||||
if (sName == "playsound") {
|
||||
return eAnimationEventType_PlaySound;
|
||||
}
|
||||
|
||||
Warning("Animation event type '%s' does not exist!\n", apString);
|
||||
return eAnimationEventType_LastEnum;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PRIVATE METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
} // namespace hpl
|
||||
91
engines/hpl1/engine/resources/EntityLoader_Object.h
Normal file
91
engines/hpl1/engine/resources/EntityLoader_Object.h
Normal file
@@ -0,0 +1,91 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#ifndef HPL_ENTITY_LOADER_OBJECT_H
|
||||
#define HPL_ENTITY_LOADER_OBJECT_H
|
||||
|
||||
#include "hpl1/engine/graphics/GraphicsTypes.h"
|
||||
#include "hpl1/engine/math/MathTypes.h"
|
||||
#include "hpl1/engine/system/SystemTypes.h"
|
||||
|
||||
#include "hpl1/engine/resources/Resources.h"
|
||||
|
||||
class TiXmlElement;
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class iPhysicsBody;
|
||||
class iPhysicsJoint;
|
||||
class iPhysicsWorld;
|
||||
class cMesh;
|
||||
class cMeshEntity;
|
||||
class cParticleSystem3D;
|
||||
class cBillboard;
|
||||
class cBeam;
|
||||
class cSoundEntity;
|
||||
class iLight3D;
|
||||
|
||||
class cEntityLoader_Object : public iEntity3DLoader {
|
||||
public:
|
||||
cEntityLoader_Object(const tString &asName) : iEntity3DLoader(asName) {}
|
||||
virtual ~cEntityLoader_Object() {}
|
||||
|
||||
iEntity3D *Load(const tString &asName, TiXmlElement *apRootElem, const cMatrixf &a_mtxTransform,
|
||||
cWorld3D *apWorld, const tString &asFileName, bool abLoadReferences);
|
||||
|
||||
protected:
|
||||
virtual void BeforeLoad(TiXmlElement *apRootElem, const cMatrixf &a_mtxTransform, cWorld3D *apWorld){};
|
||||
virtual void AfterLoad(TiXmlElement *apRootElem, const cMatrixf &a_mtxTransform, cWorld3D *apWorld){};
|
||||
|
||||
void SetBodyProperties(iPhysicsBody *apBody, TiXmlElement *apPhysicsElem);
|
||||
void SetJointProperties(iPhysicsJoint *apJoint, TiXmlElement *apJointElem, cWorld3D *apWorld);
|
||||
|
||||
void LoadController(iPhysicsJoint *apJoint, iPhysicsWorld *apPhysicsWorld, TiXmlElement *apElem);
|
||||
|
||||
eAnimationEventType GetAnimationEventType(const char *apString);
|
||||
|
||||
tString msSubType;
|
||||
tString msName;
|
||||
|
||||
tString msFileName;
|
||||
|
||||
Common::Array<iPhysicsBody *> mvBodies;
|
||||
Common::Array<iPhysicsJoint *> mvJoints;
|
||||
|
||||
Common::Array<iLight3D *> mvLights;
|
||||
Common::Array<cParticleSystem3D *> mvParticleSystems;
|
||||
Common::Array<cBillboard *> mvBillboards;
|
||||
Common::Array<cBeam *> mvBeams;
|
||||
Common::Array<cSoundEntity *> mvSoundEntities;
|
||||
|
||||
cMeshEntity *mpEntity;
|
||||
cMesh *mpMesh;
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_ENTITY_LOADER_OBJECT_H
|
||||
95
engines/hpl1/engine/resources/FileSearcher.cpp
Normal file
95
engines/hpl1/engine/resources/FileSearcher.cpp
Normal file
@@ -0,0 +1,95 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#include "hpl1/engine/resources/FileSearcher.h"
|
||||
#include "hpl1/engine/resources/low_level_resources.h"
|
||||
#include "hpl1/engine/system/String.h"
|
||||
#include "hpl1/engine/system/low_level_system.h"
|
||||
#include "hpl1/hpl1.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cFileSearcher::cFileSearcher(LowLevelResources *apLowLevelResources) {
|
||||
mpLowLevelResources = apLowLevelResources;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cFileSearcher::~cFileSearcher() {
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cFileSearcher::AddDirectory(tString asPath, tString asMask) {
|
||||
tStringList lstFileNames;
|
||||
// Make the path with only "/" and lower case.
|
||||
asPath = cString::ToLowerCase(cString::ReplaceCharTo(asPath, "\\", "/"));
|
||||
|
||||
tStringSetIt it = m_setLoadedDirs.find(asPath);
|
||||
// If the path is not already added, add it!
|
||||
if (it == m_setLoadedDirs.end()) {
|
||||
m_setLoadedDirs.insert(asPath);
|
||||
|
||||
mpLowLevelResources->findFilesInDir(lstFileNames, asPath, asMask);
|
||||
for (const auto &f : lstFileNames) {
|
||||
m_mapFiles.insert(tFilePathMap::value_type(
|
||||
cString::ToLowerCase(f),
|
||||
cString::SetFilePath(f, asPath)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void cFileSearcher::ClearDirectories() {
|
||||
m_mapFiles.clear();
|
||||
m_setLoadedDirs.clear();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
tString cFileSearcher::GetFilePath(tString asName) {
|
||||
tFilePathMapIt it = m_mapFiles.find(cString::ToLowerCase(asName));
|
||||
if (it == m_mapFiles.end())
|
||||
return "";
|
||||
|
||||
return it->second;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
} // namespace hpl
|
||||
76
engines/hpl1/engine/resources/FileSearcher.h
Normal file
76
engines/hpl1/engine/resources/FileSearcher.h
Normal file
@@ -0,0 +1,76 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#ifndef HPL_FILESEARCHER_H
|
||||
#define HPL_FILESEARCHER_H
|
||||
|
||||
#include "hpl1/engine/resources/ResourcesTypes.h"
|
||||
#include "hpl1/engine/system/SystemTypes.h"
|
||||
#include "common/stablemap.h"
|
||||
#include "common/multimap.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class LowLevelResources;
|
||||
|
||||
typedef Common::MultiMap<tString, tString> tFilePathMap;
|
||||
typedef tFilePathMap::iterator tFilePathMapIt;
|
||||
|
||||
class cFileSearcher {
|
||||
public:
|
||||
cFileSearcher(LowLevelResources *apLowLevelResources);
|
||||
~cFileSearcher();
|
||||
|
||||
/**
|
||||
* Adds a directory that will be searched when looking for files.
|
||||
* \param asMask What files that should be searched for, for example: "*.jpeg".
|
||||
* \param asPath The path to the directory.
|
||||
*/
|
||||
void AddDirectory(tString asPath, tString asMask);
|
||||
|
||||
/**
|
||||
* Clears all directories
|
||||
*/
|
||||
void ClearDirectories();
|
||||
|
||||
/**
|
||||
* Gets a file pointer and searches through all added resources.
|
||||
* \param asName Name of the file.
|
||||
* \return Path to the file. "" if file is not found.
|
||||
*/
|
||||
tString GetFilePath(tString asName);
|
||||
|
||||
private:
|
||||
tFilePathMap m_mapFiles;
|
||||
tStringSet m_setLoadedDirs;
|
||||
|
||||
LowLevelResources *mpLowLevelResources;
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_FILESEARCHER_H
|
||||
152
engines/hpl1/engine/resources/FontManager.cpp
Normal file
152
engines/hpl1/engine/resources/FontManager.cpp
Normal file
@@ -0,0 +1,152 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#include "hpl1/engine/resources/FontManager.h"
|
||||
#include "hpl1/engine/graphics/Graphics.h"
|
||||
#include "hpl1/engine/graphics/LowLevelGraphics.h"
|
||||
#include "hpl1/engine/resources/ImageManager.h"
|
||||
#include "hpl1/engine/resources/Resources.h"
|
||||
#include "hpl1/engine/system/String.h"
|
||||
#include "hpl1/engine/system/low_level_system.h"
|
||||
|
||||
#include "hpl1/engine/graphics/font_data.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cFontManager::cFontManager(cGraphics *apGraphics, cGui *apGui, cResources *apResources)
|
||||
: iResourceManager(apResources->GetFileSearcher(), apResources->GetLowLevel(),
|
||||
apResources->GetLowLevelSystem()) {
|
||||
mpGraphics = apGraphics;
|
||||
mpResources = apResources;
|
||||
mpGui = apGui;
|
||||
}
|
||||
|
||||
cFontManager::~cFontManager() {
|
||||
DestroyAll();
|
||||
Log(" Done with fonts\n");
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
FontData *cFontManager::CreateFontData(const tString &asName, int alSize, unsigned short alFirstChar,
|
||||
unsigned short alLastChar) {
|
||||
tString sPath;
|
||||
FontData *pFont;
|
||||
tString asNewName = cString::ToLowerCase(asName);
|
||||
|
||||
BeginLoad(asName);
|
||||
|
||||
// asNewName = cString::SetFileExt(asName,"ttf");
|
||||
|
||||
pFont = static_cast<FontData *>(this->FindLoadedResource(asNewName, sPath));
|
||||
|
||||
if (pFont == NULL && sPath != "") {
|
||||
pFont = mpGraphics->GetLowLevel()->CreateFontData(asNewName);
|
||||
pFont->setUp(mpGraphics->GetDrawer(), mpLowLevelResources, mpGui);
|
||||
|
||||
tString sExt = cString::ToLowerCase(cString::GetFileExt(asName));
|
||||
|
||||
// True Type Font
|
||||
if (sExt == "ttf") {
|
||||
if (pFont->createFromFontFile(sPath, alSize, alFirstChar, alLastChar) == false) {
|
||||
hplDelete(pFont);
|
||||
EndLoad();
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
// Angel code font type
|
||||
else if (sExt == "fnt") {
|
||||
if (pFont->createFromBitmapFile(sPath) == false) {
|
||||
hplDelete(pFont);
|
||||
EndLoad();
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
Error("Font '%s' has an unknown extension!\n", asName.c_str());
|
||||
hplDelete(pFont);
|
||||
EndLoad();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// mpResources->GetImageManager()->FlushAll();
|
||||
AddResource(pFont);
|
||||
}
|
||||
|
||||
if (pFont)
|
||||
pFont->IncUserCount();
|
||||
else
|
||||
Error("Couldn't create font '%s'\n", asNewName.c_str());
|
||||
|
||||
EndLoad();
|
||||
return pFont;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iResourceBase *cFontManager::Create(const tString &asName) {
|
||||
return CreateFontData(asName, 16, 32, 255);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cFontManager::Unload(iResourceBase *apResource) {
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cFontManager::Destroy(iResourceBase *apResource) {
|
||||
apResource->DecUserCount();
|
||||
|
||||
if (apResource->HasUsers() == false) {
|
||||
RemoveResource(apResource);
|
||||
hplDelete(apResource);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PRIVATE METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
} // namespace hpl
|
||||
68
engines/hpl1/engine/resources/FontManager.h
Normal file
68
engines/hpl1/engine/resources/FontManager.h
Normal file
@@ -0,0 +1,68 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#ifndef HPL_FONT_MANAGER_H
|
||||
#define HPL_FONT_MANAGER_H
|
||||
|
||||
#include "hpl1/engine/resources/ResourceManager.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class cGraphics;
|
||||
class cResources;
|
||||
class cGui;
|
||||
class FontData;
|
||||
|
||||
class cFontManager : public iResourceManager {
|
||||
public:
|
||||
cFontManager(cGraphics *apGraphics, cGui *apGui, cResources *apResources);
|
||||
~cFontManager();
|
||||
|
||||
iResourceBase *Create(const tString &asName);
|
||||
/**
|
||||
* Create a new font
|
||||
* \param asName name of the font
|
||||
* \param alSize size the characters are rendered in
|
||||
* \param alFirstChar first ASCII character to be rendered
|
||||
* \param alLastChar last ASCII character to be rendered
|
||||
* \return
|
||||
*/
|
||||
FontData *CreateFontData(const tString &asName, int alSize = 16, unsigned short alFirstChar = 32,
|
||||
unsigned short alLastChar = 255);
|
||||
|
||||
void Destroy(iResourceBase *apResource);
|
||||
void Unload(iResourceBase *apResource);
|
||||
|
||||
private:
|
||||
cGraphics *mpGraphics;
|
||||
cResources *mpResources;
|
||||
cGui *mpGui;
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_FONT_MANAGER_H
|
||||
55
engines/hpl1/engine/resources/FrameBase.h
Normal file
55
engines/hpl1/engine/resources/FrameBase.h
Normal file
@@ -0,0 +1,55 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#ifndef HPL_FRAMEBASE_H
|
||||
#define HPL_FRAMEBASE_H
|
||||
|
||||
#include "hpl1/engine/math/MathTypes.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class iFrameBase {
|
||||
public:
|
||||
iFrameBase() {
|
||||
mlPicCount = 0;
|
||||
}
|
||||
|
||||
void SetPicCount(int alPicCount) { mlPicCount = alPicCount; }
|
||||
void DecPicCount() {
|
||||
if (mlPicCount > 0)
|
||||
mlPicCount--;
|
||||
}
|
||||
int GetPicCount() { return mlPicCount; }
|
||||
bool IsEmpty() { return mlPicCount <= 0; }
|
||||
|
||||
protected:
|
||||
int mlPicCount;
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_FRAMEBASE_H
|
||||
266
engines/hpl1/engine/resources/FrameBitmap.cpp
Normal file
266
engines/hpl1/engine/resources/FrameBitmap.cpp
Normal file
@@ -0,0 +1,266 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#include "hpl1/engine/resources/FrameBitmap.h"
|
||||
#include "hpl1/engine/graphics/Texture.h"
|
||||
#include "hpl1/engine/graphics/bitmap2D.h"
|
||||
#include "hpl1/engine/math/Math.h"
|
||||
#include "hpl1/engine/resources/FrameTexture.h"
|
||||
#include "hpl1/engine/resources/ResourceImage.h"
|
||||
#include "hpl1/engine/system/low_level_system.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cFrameBitmap::cFrameBitmap(Bitmap2D *apBitmap, cFrameTexture *apFrmTex, int alHandle) : iFrameBase() {
|
||||
mpBitmap = apBitmap;
|
||||
mpFrameTexture = apFrmTex;
|
||||
mpBitmap->fillRect(cRect2l(0, 0, 0, 0), cColor(1, 1));
|
||||
mlMinHole = 6;
|
||||
mlHandle = alHandle;
|
||||
mbIsFull = false;
|
||||
mbIsLocked = false;
|
||||
|
||||
// Root node in rect tree
|
||||
mRects.Insert(cFBitmapRect(0, 0, mpBitmap->getWidth(), mpBitmap->getHeight(), -1));
|
||||
}
|
||||
|
||||
cFrameBitmap::~cFrameBitmap() {
|
||||
hplDelete(mpBitmap);
|
||||
mpBitmap = NULL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#define DEBUG_BTREE (false)
|
||||
|
||||
cResourceImage *cFrameBitmap::AddBitmap(Bitmap2D *apSrc) {
|
||||
cResourceImage *pImage = NULL;
|
||||
// source size
|
||||
//+2 because we are gonna have a border to get rid if some antialiasing problems
|
||||
int lSW = apSrc->getWidth() + 2;
|
||||
int lSH = apSrc->getHeight() + 2;
|
||||
|
||||
// destination size
|
||||
// int lDW = mpBitmap->getWidth();
|
||||
// int lDH = mpBitmap->getHeight();
|
||||
|
||||
cVector2l vPos;
|
||||
|
||||
bool bFoundEmptyNode = false;
|
||||
bool bFoundNode = false;
|
||||
// Debug
|
||||
int node = 0;
|
||||
|
||||
if (DEBUG_BTREE)
|
||||
Log("**** Image %d *****\n", mlPicCount);
|
||||
|
||||
// Get the leaves of the tree and search it for a good pos.
|
||||
tRectTreeNodeList lstNodes = mRects.GetLeafList();
|
||||
tRectTreeNodeListIt it;
|
||||
for (it = lstNodes.begin(); it != lstNodes.end(); ++it) {
|
||||
if (DEBUG_BTREE)
|
||||
Log("Checking node %d:\n", node++);
|
||||
tRectTreeNode *TopNode = *it;
|
||||
cFBitmapRect *pData = TopNode->GetData();
|
||||
|
||||
// Check if the space is free
|
||||
if (pData->mlHandle < 0) {
|
||||
if (DEBUG_BTREE)
|
||||
Log("Found free node\n");
|
||||
bFoundEmptyNode = true; // An empty node was found.. bitmap not full yet.
|
||||
|
||||
// Check if the Image fits in the rect
|
||||
cRect2l NewRect = cRect2l(pData->mRect.x, pData->mRect.y, lSW, lSH);
|
||||
if (DEBUG_BTREE)
|
||||
Log("Fit: [%d:%d:%d:%d] in [%d:%d:%d:%d]\n",
|
||||
NewRect.x, NewRect.y, NewRect.w, NewRect.h,
|
||||
pData->mRect.x, pData->mRect.y, pData->mRect.w, pData->mRect.h);
|
||||
|
||||
if (cMath::BoxFit(NewRect, pData->mRect)) {
|
||||
if (DEBUG_BTREE)
|
||||
Log("The node fits!\n");
|
||||
bFoundNode = true;
|
||||
|
||||
// If the bitmap fits perfectly add the node without splitting
|
||||
if (MinimumFit(NewRect, pData->mRect)) {
|
||||
if (DEBUG_BTREE)
|
||||
Log("Minimum fit!\n");
|
||||
pData->mRect = NewRect;
|
||||
pData->mlHandle = 1;
|
||||
}
|
||||
// If there is still space left, make new nodes.
|
||||
else {
|
||||
if (DEBUG_BTREE)
|
||||
Log("Normal fit!\n");
|
||||
// Insert 2 children for the top node (lower and upper part.
|
||||
tRectTreeNode *UpperNode;
|
||||
// Upper
|
||||
UpperNode = mRects.InsertAt(cFBitmapRect(NewRect.x, NewRect.y,
|
||||
pData->mRect.w, NewRect.h, -2),
|
||||
TopNode,
|
||||
eBinTreeNode_Left);
|
||||
|
||||
// Lower
|
||||
mRects.InsertAt(cFBitmapRect(NewRect.x, NewRect.y + NewRect.h,
|
||||
pData->mRect.w, pData->mRect.h - NewRect.h, -3),
|
||||
TopNode,
|
||||
eBinTreeNode_Right);
|
||||
|
||||
// Split the Upper Node into 2 nodes.
|
||||
pData = UpperNode->GetData(); // Get the data for the upper node.
|
||||
// Upper split, this is the new bitmap
|
||||
mRects.InsertAt(cFBitmapRect(NewRect.x, NewRect.y,
|
||||
NewRect.w, NewRect.h, 2),
|
||||
UpperNode,
|
||||
eBinTreeNode_Left);
|
||||
|
||||
// Lower split, this is empty
|
||||
mRects.InsertAt(cFBitmapRect(NewRect.x + NewRect.w, NewRect.y,
|
||||
pData->mRect.w - NewRect.w, NewRect.h, -4),
|
||||
UpperNode,
|
||||
eBinTreeNode_Right);
|
||||
}
|
||||
|
||||
vPos = cVector2l(NewRect.x + 1, NewRect.y + 1); //+1 for the right pos
|
||||
|
||||
// Draw 4 times so we get a nice extra border
|
||||
for (int i = 0; i < 2; i++)
|
||||
for (int j = 0; j < 2; j++) {
|
||||
apSrc->drawToBitmap(*mpBitmap, cVector2l(NewRect.x + i * 2, NewRect.y + j * 2));
|
||||
}
|
||||
// Fix the border a little more:
|
||||
for (int i = -1; i < 2; i++)
|
||||
for (int j = -1; j < 2; j++)
|
||||
if ((i == 0 || j == 0) && (i != j)) {
|
||||
apSrc->drawToBitmap(*mpBitmap, cVector2l(NewRect.x + 1 + i, NewRect.y + 1 + j));
|
||||
}
|
||||
// Draw the final
|
||||
apSrc->drawToBitmap(*mpBitmap, cVector2l(NewRect.x + 1, NewRect.y + 1));
|
||||
|
||||
mlPicCount++;
|
||||
mpFrameTexture->SetPicCount(mlPicCount);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (bFoundNode) {
|
||||
// Create the image resource
|
||||
pImage = hplNew(cResourceImage, (apSrc->getFileName(), mpFrameTexture, this,
|
||||
cRect2l(vPos, cVector2l(lSW - 2, lSH - 2)), //-2 to get the correct size.
|
||||
cVector2l(mpBitmap->getWidth(), mpBitmap->getHeight()),
|
||||
mlHandle));
|
||||
|
||||
if (!bFoundEmptyNode) {
|
||||
mbIsFull = true;
|
||||
}
|
||||
|
||||
mbIsUpdated = true;
|
||||
}
|
||||
|
||||
/// LAST DEBUG ///
|
||||
if (DEBUG_BTREE) {
|
||||
Log("Current Tree begin:\n");
|
||||
tRectTreeNodeList lstNodes2 = mRects.GetNodeList();
|
||||
tRectTreeNodeListIt it2;
|
||||
int node2 = 0;
|
||||
for (it2 = lstNodes2.begin(); it2 != lstNodes2.end(); ++it) {
|
||||
cRect2l Rect = (*it2)->GetData()->mRect;
|
||||
int h = (*it)->GetData()->mlHandle;
|
||||
Log(" %d: [%d:%d:%d:%d]:%d\n", node2, Rect.x, Rect.y, Rect.w, Rect.h, h);
|
||||
node2++;
|
||||
}
|
||||
Log("Current Tree end:\n");
|
||||
Log("-----------------\n");
|
||||
|
||||
Log("Current Leaves begin:\n");
|
||||
lstNodes2 = mRects.GetLeafList();
|
||||
node2 = 0;
|
||||
for (it2 = lstNodes2.begin(); it2 != lstNodes2.end(); ++it) {
|
||||
cRect2l Rect = (*it2)->GetData()->mRect;
|
||||
int h = (*it2)->GetData()->mlHandle;
|
||||
Log(" %d: [%d:%d:%d:%d]: %d\n", node2, Rect.x, Rect.y, Rect.w, Rect.h, h);
|
||||
node2++;
|
||||
}
|
||||
Log("Current Tree end:\n");
|
||||
Log("-----------------\n");
|
||||
}
|
||||
|
||||
return pImage;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cFrameBitmap::MinimumFit(cRect2l aSrc, cRect2l aDest) {
|
||||
if (aDest.w - aSrc.w < mlMinHole && aDest.h - aSrc.h < mlMinHole)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cFrameBitmap::IsUpdated() {
|
||||
return mbIsUpdated;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cFrameBitmap::IsFull() {
|
||||
return mbIsFull;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cFrameBitmap::FlushToTexture() {
|
||||
if (mbIsUpdated) {
|
||||
mpFrameTexture->GetTexture()->CreateFromBitmap(mpBitmap);
|
||||
mpFrameTexture->GetTexture()->SetWrapS(eTextureWrap_ClampToEdge);
|
||||
mpFrameTexture->GetTexture()->SetWrapT(eTextureWrap_ClampToEdge);
|
||||
|
||||
// mpFrameTexture->SetPicCount(mlPicCount);
|
||||
mbIsUpdated = false;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
} // namespace hpl
|
||||
91
engines/hpl1/engine/resources/FrameBitmap.h
Normal file
91
engines/hpl1/engine/resources/FrameBitmap.h
Normal file
@@ -0,0 +1,91 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#ifndef HPL_FRAMEBITMAP_H
|
||||
#define HPL_FRAMEBITMAP_H
|
||||
|
||||
#include "hpl1/engine/math/MathTypes.h"
|
||||
#include "hpl1/engine/resources/FrameBase.h"
|
||||
#include "hpl1/engine/system/BinTree.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class cFrameTexture;
|
||||
class cResourceImage;
|
||||
class Bitmap2D;
|
||||
|
||||
// The frames bitmap + rect class
|
||||
class cFBitmapRect {
|
||||
public:
|
||||
cFBitmapRect() { mlHandle = -1; }
|
||||
cFBitmapRect(int x, int y, int w, int h, int alHandle) {
|
||||
mRect = cRect2l(x, y, w, h);
|
||||
mlHandle = alHandle;
|
||||
}
|
||||
|
||||
cRect2l mRect;
|
||||
int mlHandle;
|
||||
};
|
||||
|
||||
typedef BinTree<cFBitmapRect> tRectTree;
|
||||
typedef BinTreeNode<cFBitmapRect> tRectTreeNode;
|
||||
typedef Common::List<tRectTreeNode *> tRectTreeNodeList;
|
||||
typedef tRectTreeNodeList::iterator tRectTreeNodeListIt;
|
||||
|
||||
class cFrameBitmap : public iFrameBase {
|
||||
public:
|
||||
cFrameBitmap(Bitmap2D *apBitmap, cFrameTexture *apFrmTex, int alHandle);
|
||||
~cFrameBitmap();
|
||||
|
||||
cResourceImage *AddBitmap(Bitmap2D *apSrc);
|
||||
bool MinimumFit(cRect2l aSrc, cRect2l aDest);
|
||||
bool IsFull();
|
||||
bool IsUpdated();
|
||||
|
||||
bool IsLocked() const { return mbIsLocked; }
|
||||
void SetLocked(bool abX) { mbIsLocked = abX; }
|
||||
|
||||
bool FlushToTexture();
|
||||
|
||||
cFrameTexture *GetFrameTexture() { return mpFrameTexture; }
|
||||
|
||||
int GetHandle() const { return mlHandle; }
|
||||
|
||||
private:
|
||||
Bitmap2D *mpBitmap;
|
||||
cFrameTexture *mpFrameTexture;
|
||||
tRectTree mRects;
|
||||
int mlMinHole;
|
||||
int mlHandle;
|
||||
bool mbIsFull;
|
||||
bool mbIsUpdated;
|
||||
bool mbIsLocked;
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_FRAMEBITMAP_H
|
||||
63
engines/hpl1/engine/resources/FrameTexture.cpp
Normal file
63
engines/hpl1/engine/resources/FrameTexture.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#include "hpl1/engine/resources/FrameTexture.h"
|
||||
#include "hpl1/engine/graphics/Texture.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cFrameTexture::cFrameTexture(iTexture *apTex, int alHandle) : iFrameBase() {
|
||||
mpTexture = apTex;
|
||||
mlHandle = alHandle;
|
||||
}
|
||||
|
||||
cFrameTexture::~cFrameTexture() {
|
||||
if (mpTexture)
|
||||
hplDelete(mpTexture);
|
||||
mpTexture = NULL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iTexture *cFrameTexture::GetTexture() {
|
||||
return mpTexture;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
} // namespace hpl
|
||||
52
engines/hpl1/engine/resources/FrameTexture.h
Normal file
52
engines/hpl1/engine/resources/FrameTexture.h
Normal file
@@ -0,0 +1,52 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#ifndef HPL_FRAMETEXTURE_H
|
||||
#define HPL_FRAMETEXTURE_H
|
||||
|
||||
#include "hpl1/engine/resources/FrameBase.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class iTexture;
|
||||
|
||||
class cFrameTexture : public iFrameBase {
|
||||
public:
|
||||
cFrameTexture(iTexture *pTex, int alHandle);
|
||||
~cFrameTexture();
|
||||
|
||||
iTexture *GetTexture();
|
||||
int GetHandle() { return mlHandle; }
|
||||
|
||||
private:
|
||||
iTexture *mpTexture;
|
||||
int mlHandle;
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_FRAMETEXTURE_H
|
||||
119
engines/hpl1/engine/resources/GpuProgramManager.cpp
Normal file
119
engines/hpl1/engine/resources/GpuProgramManager.cpp
Normal file
@@ -0,0 +1,119 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#include "hpl1/engine/resources/GpuProgramManager.h"
|
||||
#include "hpl1/debug.h"
|
||||
#include "hpl1/engine/graphics/GPUProgram.h"
|
||||
#include "hpl1/engine/graphics/LowLevelGraphics.h"
|
||||
#include "hpl1/engine/system/String.h"
|
||||
#include "hpl1/engine/system/low_level_system.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cGpuProgramManager::cGpuProgramManager(cFileSearcher *apFileSearcher, iLowLevelGraphics *apLowLevelGraphics,
|
||||
LowLevelResources *apLowLevelResources, LowLevelSystem *apLowLevelSystem)
|
||||
: iResourceManager(apFileSearcher, apLowLevelResources, apLowLevelSystem) {
|
||||
mpLowLevelGraphics = apLowLevelGraphics;
|
||||
}
|
||||
|
||||
cGpuProgramManager::~cGpuProgramManager() {
|
||||
DestroyAll();
|
||||
|
||||
Log(" Done with Gpu programs\n");
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Since further parameters are needed for the gpu prog this does not work...
|
||||
* For now at least.
|
||||
* \param asName
|
||||
* \return
|
||||
*/
|
||||
iResourceBase *cGpuProgramManager::Create(const tString &asName) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iGpuProgram *cGpuProgramManager::CreateProgram(const tString &vertex, const tString &fragment,
|
||||
eGpuProgramType aType) {
|
||||
if (!mpLowLevelGraphics->GetCaps(eGraphicCaps_GL_GpuPrograms))
|
||||
return nullptr;
|
||||
|
||||
tString sPath;
|
||||
iGpuProgram *pProgram;
|
||||
pProgram = static_cast<iGpuProgram *>(FindLoadedResource(vertex + " " + fragment, sPath));
|
||||
if (pProgram == nullptr) {
|
||||
pProgram = mpLowLevelGraphics->CreateGpuProgram(vertex, fragment);
|
||||
AddResource(pProgram);
|
||||
}
|
||||
|
||||
pProgram->IncUserCount();
|
||||
|
||||
return pProgram;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cGpuProgramManager::Unload(iResourceBase *apResource) {
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cGpuProgramManager::Destroy(iResourceBase *apResource) {
|
||||
apResource->DecUserCount();
|
||||
|
||||
if (apResource->HasUsers() == false) {
|
||||
RemoveResource(apResource);
|
||||
hplDelete(apResource);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PRIVATE METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
} // namespace hpl
|
||||
64
engines/hpl1/engine/resources/GpuProgramManager.h
Normal file
64
engines/hpl1/engine/resources/GpuProgramManager.h
Normal file
@@ -0,0 +1,64 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#ifndef HPL_GPU_PROGRAM_MANAGER_H
|
||||
#define HPL_GPU_PROGRAM_MANAGER_H
|
||||
|
||||
#include "hpl1/engine/resources/ResourceManager.h"
|
||||
|
||||
#include "hpl1/engine/graphics/GPUProgram.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class iLowLevelGraphics;
|
||||
|
||||
class cGpuProgramManager : public iResourceManager {
|
||||
public:
|
||||
cGpuProgramManager(cFileSearcher *apFileSearcher, iLowLevelGraphics *apLowLevelGraphics,
|
||||
LowLevelResources *apLowLevelResources, LowLevelSystem *apLowLevelSystem);
|
||||
~cGpuProgramManager();
|
||||
|
||||
iResourceBase *Create(const tString &asName);
|
||||
/**
|
||||
* Creates a new GPU program
|
||||
* \param asName name of the program
|
||||
* \param asEntry the entry point of the program (usually "main")
|
||||
* \param aType type of the program
|
||||
* \return
|
||||
*/
|
||||
iGpuProgram *CreateProgram(const tString &vertex, const tString &fragment, eGpuProgramType aType = eGpuProgramType_LastEnum);
|
||||
|
||||
void Destroy(iResourceBase *apResource);
|
||||
void Unload(iResourceBase *apResource);
|
||||
|
||||
private:
|
||||
iLowLevelGraphics *mpLowLevelGraphics;
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_GPU_PROGRAM_MANAGER_H
|
||||
132
engines/hpl1/engine/resources/ImageEntityManager.cpp
Normal file
132
engines/hpl1/engine/resources/ImageEntityManager.cpp
Normal file
@@ -0,0 +1,132 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#include "hpl1/engine/resources/ImageEntityManager.h"
|
||||
#include "common/algorithm.h"
|
||||
#include "hpl1/engine/graphics/Graphics.h"
|
||||
#include "hpl1/engine/graphics/ImageEntityData.h"
|
||||
#include "hpl1/engine/graphics/Material.h"
|
||||
#include "hpl1/engine/resources/Resources.h"
|
||||
#include "hpl1/engine/system/String.h"
|
||||
#include "hpl1/engine/system/low_level_system.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cImageEntityManager::cImageEntityManager(cGraphics *apGraphics, cResources *apResources)
|
||||
: iResourceManager(apResources->GetFileSearcher(), apResources->GetLowLevel(),
|
||||
apResources->GetLowLevelSystem()) {
|
||||
mpGraphics = apGraphics;
|
||||
mpResources = apResources;
|
||||
|
||||
mvImageHandle.resize(eMaterialTexture_LastEnum);
|
||||
Common::fill(mvImageHandle.begin(), mvImageHandle.end(), -1);
|
||||
}
|
||||
|
||||
cImageEntityManager::~cImageEntityManager() {
|
||||
DestroyAll();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cImageEntityData *cImageEntityManager::CreateData(const tString &asName) {
|
||||
return static_cast<cImageEntityData *>(Create(asName));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cImageEntityManager::Unload(iResourceBase *apResource) {
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cImageEntityManager::Destroy(iResourceBase *apResource) {
|
||||
apResource->DecUserCount();
|
||||
|
||||
if (apResource->HasUsers() == false) {
|
||||
RemoveResource(apResource);
|
||||
hplDelete(apResource);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PRIVATE METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
} // namespace hpl
|
||||
60
engines/hpl1/engine/resources/ImageEntityManager.h
Normal file
60
engines/hpl1/engine/resources/ImageEntityManager.h
Normal file
@@ -0,0 +1,60 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#ifndef HPL_IMAGE_ENTITY_MANAGER_H
|
||||
#define HPL_IMAGE_ENTITY_MANAGER_H
|
||||
|
||||
#include "hpl1/engine/resources/ResourceManager.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class cGraphics;
|
||||
class cResources;
|
||||
|
||||
class cImageEntityData;
|
||||
|
||||
class cImageEntityManager : public iResourceManager {
|
||||
public:
|
||||
cImageEntityManager(cGraphics *apGraphics, cResources *apResources);
|
||||
~cImageEntityManager();
|
||||
|
||||
iResourceBase *Create(const tString &asName);
|
||||
cImageEntityData *CreateData(const tString &asName);
|
||||
|
||||
void Destroy(iResourceBase *apResource);
|
||||
void Unload(iResourceBase *apResource);
|
||||
|
||||
private:
|
||||
cGraphics *mpGraphics;
|
||||
cResources *mpResources;
|
||||
|
||||
tIntVec mvImageHandle;
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_IMAGE_ENTITY_MANAGER_H
|
||||
359
engines/hpl1/engine/resources/ImageManager.cpp
Normal file
359
engines/hpl1/engine/resources/ImageManager.cpp
Normal file
@@ -0,0 +1,359 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#include "hpl1/engine/resources/ImageManager.h"
|
||||
#include "hpl1/engine/graphics/LowLevelGraphics.h"
|
||||
#include "hpl1/engine/resources/FrameBitmap.h"
|
||||
#include "hpl1/engine/resources/FrameTexture.h"
|
||||
#include "hpl1/engine/resources/ResourceImage.h"
|
||||
#include "hpl1/engine/resources/low_level_resources.h"
|
||||
#include "hpl1/engine/system/String.h"
|
||||
#include "hpl1/engine/system/low_level_system.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cImageManager::cImageManager(cFileSearcher *apFileSearcher, iLowLevelGraphics *apLowLevelGraphics,
|
||||
LowLevelResources *apLowLevelResources, LowLevelSystem *apLowLevelSystem)
|
||||
: iResourceManager(apFileSearcher, apLowLevelResources, apLowLevelSystem) {
|
||||
mpLowLevelGraphics = apLowLevelGraphics;
|
||||
|
||||
mpLowLevelResources->getSupportedImageFormats(mlstFileFormats);
|
||||
|
||||
mvFrameSize = cVector2l(512, 512);
|
||||
mlFrameHandle = 0;
|
||||
}
|
||||
|
||||
cImageManager::~cImageManager() {
|
||||
// DeleteAllBitmapFrames();
|
||||
DestroyAll();
|
||||
|
||||
Log(" Done with images\n");
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iResourceBase *cImageManager::Create(const tString &asName) {
|
||||
return CreateInFrame(asName, -1);
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iResourceBase *cImageManager::CreateInFrame(const tString &asName, int alFrameHandle) {
|
||||
cResourceImage *pImage = NULL;
|
||||
tString sPath;
|
||||
|
||||
BeginLoad(asName);
|
||||
|
||||
pImage = FindImage(asName, sPath);
|
||||
if (!pImage) {
|
||||
if (sPath != "") {
|
||||
Bitmap2D *pBmp;
|
||||
pBmp = mpLowLevelResources->loadBitmap2D(sPath);
|
||||
if (pBmp == NULL) {
|
||||
Error("Imagemanager Couldn't load bitmap '%s'\n", sPath.c_str());
|
||||
EndLoad();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pImage = AddToFrame(pBmp, alFrameHandle);
|
||||
|
||||
hplDelete(pBmp);
|
||||
|
||||
if (pImage == NULL) {
|
||||
Error("Imagemanager couldn't create image '%s'\n", asName.c_str());
|
||||
}
|
||||
|
||||
if (pImage)
|
||||
AddResource(pImage);
|
||||
}
|
||||
} else {
|
||||
// Log("Found '%s' in stock!\n",asName.c_str());
|
||||
}
|
||||
|
||||
if (pImage)
|
||||
pImage->IncUserCount();
|
||||
else
|
||||
Error("Couldn't load image '%s'\n", asName.c_str());
|
||||
|
||||
// Log("Loaded image %s, it has %d users!\n", pImage->GetName().c_str(),pImage->GetUserCount());
|
||||
// Log(" frame has %d pics\n", pImage->GetFrameTexture()->GetPicCount());
|
||||
|
||||
EndLoad();
|
||||
return pImage;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cResourceImage *cImageManager::CreateImage(const tString &asName, int alFrameHandle) {
|
||||
iResourceBase *pRes = CreateInFrame(asName, alFrameHandle);
|
||||
cResourceImage *pImage = static_cast<cResourceImage *>(pRes);
|
||||
|
||||
return pImage;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cResourceImage *cImageManager::CreateFromBitmap(const tString &asName, Bitmap2D *apBmp, int alFrameHandle) {
|
||||
if (apBmp == NULL)
|
||||
return NULL;
|
||||
|
||||
cResourceImage *pImage = AddToFrame(apBmp, alFrameHandle);
|
||||
|
||||
if (pImage) {
|
||||
AddResource(pImage, false);
|
||||
pImage->IncUserCount();
|
||||
}
|
||||
|
||||
return pImage;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cImageManager::Unload(iResourceBase *apResource) {
|
||||
}
|
||||
|
||||
void cImageManager::Destroy(iResourceBase *apResource) {
|
||||
// Lower the user num for the the resource. If it is 0 then lower the
|
||||
// user num for the TextureFrame and delete the resource. If the Texture
|
||||
// frame reaches 0 it is deleted as well.
|
||||
cResourceImage *pImage = static_cast<cResourceImage *>(apResource);
|
||||
cFrameTexture *pFrame = pImage->GetFrameTexture();
|
||||
cFrameBitmap *pBmpFrame = pImage->GetFrameBitmap();
|
||||
|
||||
// pImage->GetFrameBitmap()->FlushToTexture(); Not needed?
|
||||
|
||||
// Log("Users Before: %d\n",pImage->GetUserCount());
|
||||
// Log("Framepics Before: %d\n",pFrame->GetPicCount());
|
||||
|
||||
pImage->DecUserCount(); // dec frame count as well.. is that ok?
|
||||
|
||||
// Log("---\n");
|
||||
// Log("Destroyed Image: '%s' Users: %d\n",pImage->GetName().c_str(),pImage->GetUserCount());
|
||||
// Log("Frame %d has left Pics: %d\n",pFrame,pFrame->GetPicCount());
|
||||
|
||||
if (pImage->HasUsers() == false) {
|
||||
pFrame->DecPicCount(); // Doing it here now instead.
|
||||
pBmpFrame->DecPicCount();
|
||||
RemoveResource(apResource);
|
||||
hplDelete(apResource);
|
||||
|
||||
// Log("deleting image and dec fram to %d images!\n",pFrame->GetPicCount());
|
||||
}
|
||||
|
||||
if (pFrame->IsEmpty()) {
|
||||
// Log(" Deleting frame...");
|
||||
|
||||
// Delete the bitmap frame that has this this frame.
|
||||
for (tFrameBitmapListIt it = mlstBitmapFrames.begin(); it != mlstBitmapFrames.end(); ++it) {
|
||||
cFrameBitmap *pBmpFrame2 = *it;
|
||||
if (pBmpFrame2->GetFrameTexture() == pFrame) {
|
||||
// Log("and bitmap...");
|
||||
hplDelete(pBmpFrame2);
|
||||
mlstBitmapFrames.erase(it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// delete from list
|
||||
m_mapTextureFrames.erase(pFrame->GetHandle());
|
||||
hplDelete(pFrame);
|
||||
// Log(" Deleted frame!\n");
|
||||
}
|
||||
// Log("---\n");
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cImageManager::DeleteAllBitmapFrames() {
|
||||
FlushAll();
|
||||
for (tFrameBitmapListIt it = mlstBitmapFrames.begin(); it != mlstBitmapFrames.end();) {
|
||||
hplDelete(*it);
|
||||
it = mlstBitmapFrames.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
int cImageManager::FlushAll() {
|
||||
// Log("Flushing...");
|
||||
int lNum = 0;
|
||||
for (tFrameBitmapListIt it = mlstBitmapFrames.begin(); it != mlstBitmapFrames.end();) {
|
||||
if ((*it)->FlushToTexture())
|
||||
lNum++;
|
||||
|
||||
if ((*it)->IsFull()) {
|
||||
// Do not delete all, probably this struct needs to be here for easy access :S
|
||||
// hplDelete(*it);
|
||||
// it = mlstBitmapFrames.erase(it);
|
||||
it++;
|
||||
} else {
|
||||
it++;
|
||||
}
|
||||
}
|
||||
|
||||
// Log("Done!\n");
|
||||
|
||||
return lNum;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
int cImageManager::CreateFrame(cVector2l avSize) {
|
||||
cFrameBitmap *pBFrame = CreateBitmapFrame(avSize);
|
||||
|
||||
if (pBFrame == NULL)
|
||||
return -1;
|
||||
|
||||
return pBFrame->GetHandle();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cImageManager::SetFrameLocked(int alHandle, bool abLocked) {
|
||||
tFrameBitmapListIt it = mlstBitmapFrames.begin();
|
||||
while (it != mlstBitmapFrames.end()) {
|
||||
if ((*it)->GetHandle() == alHandle) {
|
||||
(*it)->SetLocked(abLocked);
|
||||
break;
|
||||
}
|
||||
it++;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PRIVATE METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cResourceImage *cImageManager::FindImage(const tString &asName, tString &asFilePath) {
|
||||
cResourceImage *pImage = NULL;
|
||||
|
||||
if (cString::GetFileExt(asName) == "") {
|
||||
for (tStringListIt it = mlstFileFormats.begin(); it != mlstFileFormats.end(); ++it) {
|
||||
tString sNewName = cString::SetFileExt(asName, *it);
|
||||
pImage = static_cast<cResourceImage *>(FindLoadedResource(sNewName, asFilePath));
|
||||
|
||||
if ((pImage == NULL && asFilePath != "") || pImage != NULL)
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
pImage = static_cast<cResourceImage *>(FindLoadedResource(asName, asFilePath));
|
||||
}
|
||||
|
||||
return pImage;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cResourceImage *cImageManager::AddToFrame(Bitmap2D *apBmp, int alFrameHandle) {
|
||||
bool bFound = false;
|
||||
cResourceImage *pImage = NULL;
|
||||
|
||||
if (mlstBitmapFrames.size() == 0) {
|
||||
CreateBitmapFrame(mvFrameSize);
|
||||
}
|
||||
|
||||
if (alFrameHandle < 0) {
|
||||
// Search the frames til one is find that fits the bitmap
|
||||
for (tFrameBitmapListIt it = mlstBitmapFrames.begin(); it != mlstBitmapFrames.end(); it++) {
|
||||
if (!(*it)->IsFull() && !(*it)->IsLocked()) {
|
||||
pImage = (*it)->AddBitmap(apBmp);
|
||||
if (pImage != NULL) {
|
||||
bFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If it fitted in none of the frames, create a new and put it in that.
|
||||
if (!bFound) {
|
||||
// Log("No fit!\n");
|
||||
// not 100% it fits in this one...if so maybe the bitmap size of the frame
|
||||
// should be changed?
|
||||
|
||||
// pImage = CreateBitmapFrame(mvFrameSize)->AddBitmap(apBmp);
|
||||
cFrameBitmap *pFrame = CreateBitmapFrame(mvFrameSize);
|
||||
if (pFrame) {
|
||||
pImage = pFrame->AddBitmap(apBmp);
|
||||
if (pImage == NULL) {
|
||||
Log("No fit in new frame!\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
tFrameBitmapListIt it = mlstBitmapFrames.begin();
|
||||
while (it != mlstBitmapFrames.end()) {
|
||||
if ((*it)->GetHandle() == alFrameHandle) {
|
||||
pImage = (*it)->AddBitmap(apBmp);
|
||||
break;
|
||||
}
|
||||
it++;
|
||||
}
|
||||
if (pImage == NULL)
|
||||
Error("Image didn't fit frame %d!\n", alFrameHandle);
|
||||
}
|
||||
|
||||
return pImage;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cFrameBitmap *cImageManager::CreateBitmapFrame(cVector2l avSize) {
|
||||
iTexture *pTex = mpLowLevelGraphics->CreateTexture(false, eTextureType_Normal, eTextureTarget_2D);
|
||||
cFrameTexture *pTFrame = hplNew(cFrameTexture, (pTex, mlFrameHandle));
|
||||
Bitmap2D *pBmp = mpLowLevelGraphics->CreateBitmap2D(avSize);
|
||||
cFrameBitmap *pBFrame = hplNew(cFrameBitmap, (pBmp, pTFrame, mlFrameHandle));
|
||||
|
||||
mlstBitmapFrames.push_back(pBFrame);
|
||||
|
||||
auto 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;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
} // namespace hpl
|
||||
93
engines/hpl1/engine/resources/ImageManager.h
Normal file
93
engines/hpl1/engine/resources/ImageManager.h
Normal file
@@ -0,0 +1,93 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#ifndef HPL_IMAGEMANAGER_H
|
||||
#define HPL_IMAGEMANAGER_H
|
||||
|
||||
#include "hpl1/engine/math/MathTypes.h"
|
||||
#include "hpl1/engine/resources/ResourceManager.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class cResourceImage;
|
||||
class cFrameTexture;
|
||||
class cFrameBitmap;
|
||||
class iLowLevelGraphics;
|
||||
class Bitmap2D;
|
||||
|
||||
typedef Common::List<cFrameBitmap *> tFrameBitmapList;
|
||||
typedef tFrameBitmapList::iterator tFrameBitmapListIt;
|
||||
|
||||
typedef Common::StableMap<int, cFrameTexture *> tFrameTextureMap;
|
||||
typedef tFrameTextureMap::iterator tFrameTextureMapIt;
|
||||
|
||||
class cImageManager : public iResourceManager {
|
||||
public:
|
||||
cImageManager(cFileSearcher *apFileSearcher, iLowLevelGraphics *apLowLevelGraphics,
|
||||
LowLevelResources *apLowLevelResources, LowLevelSystem *apLowLevelSystem);
|
||||
~cImageManager();
|
||||
|
||||
iResourceBase *Create(const tString &asName);
|
||||
|
||||
void Destroy(iResourceBase *apResource);
|
||||
|
||||
void Unload(iResourceBase *apResource);
|
||||
|
||||
// Image specifc
|
||||
iResourceBase *CreateInFrame(const tString &asName, int alFrameHandle);
|
||||
cResourceImage *CreateImage(const tString &asName, int alFrameHandle = -1);
|
||||
/**
|
||||
* Draws all updated content to textures. THis must be done before a loaded image can be used.
|
||||
* Use this as unoften as possible.
|
||||
* \return Number of bitmaps flushes
|
||||
*/
|
||||
int FlushAll();
|
||||
void DeleteAllBitmapFrames();
|
||||
|
||||
cResourceImage *CreateFromBitmap(const tString &asName, Bitmap2D *apBmp, int alFrameHandle = -1);
|
||||
|
||||
int CreateFrame(cVector2l avSize);
|
||||
void SetFrameLocked(int alHandle, bool abLocked);
|
||||
|
||||
private:
|
||||
iLowLevelGraphics *mpLowLevelGraphics;
|
||||
|
||||
tFrameBitmapList mlstBitmapFrames;
|
||||
tFrameTextureMap m_mapTextureFrames;
|
||||
|
||||
tStringList mlstFileFormats;
|
||||
cVector2l mvFrameSize;
|
||||
int mlFrameHandle;
|
||||
|
||||
cResourceImage *FindImage(const tString &asName, tString &asFilePath);
|
||||
cResourceImage *AddToFrame(Bitmap2D *apBmp, int alFrameHandle);
|
||||
cFrameBitmap *CreateBitmapFrame(cVector2l avSize);
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_RESOURCEMANAGER_H
|
||||
230
engines/hpl1/engine/resources/LanguageFile.cpp
Normal file
230
engines/hpl1/engine/resources/LanguageFile.cpp
Normal file
@@ -0,0 +1,230 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#include "hpl1/engine/resources/LanguageFile.h"
|
||||
#include "hpl1/engine/impl/tinyXML/tinyxml.h"
|
||||
#include "hpl1/engine/resources/FileSearcher.h"
|
||||
#include "hpl1/engine/system/String.h"
|
||||
#include "hpl1/engine/system/low_level_system.h"
|
||||
|
||||
#include "hpl1/engine/resources/FileSearcher.h"
|
||||
#include "hpl1/engine/resources/Resources.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cLanguageFile::cLanguageFile(cResources *apResources) {
|
||||
mpResources = apResources;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cLanguageFile::~cLanguageFile() {
|
||||
STLMapDeleteAll(m_mapCategories);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cLanguageFile::LoadFromFile(const tString asFile) {
|
||||
TiXmlDocument *pDoc = hplNew(TiXmlDocument, (asFile.c_str()));
|
||||
if (pDoc->LoadFile() == false) {
|
||||
hplDelete(pDoc);
|
||||
Error("Couldn't find language file '%s'\n", asFile.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
TiXmlElement *pRootElem = pDoc->FirstChildElement();
|
||||
|
||||
///////////////////////////
|
||||
// Iterate the resources
|
||||
TiXmlElement *pResourceElem = pRootElem->FirstChildElement("RESOURCES");
|
||||
if (pResourceElem) {
|
||||
TiXmlElement *pDirElem = pResourceElem->FirstChildElement("Directory");
|
||||
for (; pDirElem != NULL; pDirElem = pDirElem->NextSiblingElement("Directory")) {
|
||||
tString sPath = pDirElem->Attribute("Path");
|
||||
mpResources->AddResourceDir(sPath);
|
||||
}
|
||||
} else {
|
||||
Warning("No resources element found in '%s'\n", asFile.c_str());
|
||||
}
|
||||
|
||||
///////////////////////////
|
||||
// Iterate the categories
|
||||
TiXmlElement *pCatElem = pRootElem->FirstChildElement("CATEGORY");
|
||||
for (; pCatElem != NULL; pCatElem = pCatElem->NextSiblingElement("CATEGORY")) {
|
||||
cLanguageCategory *pCategory = hplNew(cLanguageCategory, ());
|
||||
tString sCatName = pCatElem->Attribute("Name");
|
||||
|
||||
m_mapCategories.insert(tLanguageCategoryMap::value_type(sCatName, pCategory));
|
||||
|
||||
///////////////////////////
|
||||
// Iterate the entries
|
||||
TiXmlElement *pEntryElem = pCatElem->FirstChildElement("Entry");
|
||||
for (; pEntryElem != NULL; pEntryElem = pEntryElem->NextSiblingElement("Entry")) {
|
||||
cLanguageEntry *pEntry = hplNew(cLanguageEntry, ());
|
||||
tString sEntryName = pEntryElem->Attribute("Name");
|
||||
|
||||
if (pEntryElem->FirstChild() == NULL) {
|
||||
pEntry->mwsText = _W("");
|
||||
} else {
|
||||
TiXmlText *pTextNode = pEntryElem->FirstChild()->ToText();
|
||||
if (pTextNode) {
|
||||
// pEntry->msText = pTextNode->Value();
|
||||
// pEntry->msText = cString::ReplaceStringTo(pEntry->msText,"[br]","\n");
|
||||
|
||||
tString sString = pTextNode->Value();
|
||||
pEntry->mwsText = _W("");
|
||||
|
||||
// if(sCatName == "TEST") Log("String: '%s' %d\n",sString.c_str(),sString.size());
|
||||
|
||||
for (size_t i = 0; i < sString.size(); ++i) {
|
||||
unsigned char c = sString[i];
|
||||
if (c == '[') {
|
||||
bool bFoundCommand = true;
|
||||
tString sCommand = "";
|
||||
int lCount = 1;
|
||||
|
||||
while (sString[i + lCount] != ']' && i + lCount < sString.size() && lCount < 16) {
|
||||
sCommand += sString[i + lCount];
|
||||
lCount++;
|
||||
}
|
||||
|
||||
if (sCommand == "br") {
|
||||
pEntry->mwsText += _W('\n');
|
||||
} else if (sCommand[0] == 'u') {
|
||||
int lNum = cString::ToInt(sCommand.substr(1).c_str(), 0);
|
||||
pEntry->mwsText += (wchar_t)lNum;
|
||||
} else {
|
||||
bFoundCommand = false;
|
||||
}
|
||||
|
||||
// Go forward or add [ to string
|
||||
if (bFoundCommand) {
|
||||
i += lCount;
|
||||
} else {
|
||||
pEntry->mwsText += sString[i];
|
||||
}
|
||||
}
|
||||
// Decode UTF-8!
|
||||
else if (c >= 128) {
|
||||
unsigned char c2 = sString[i + 1];
|
||||
|
||||
int lNum = c & 0x1f; // c AND 0001 1111
|
||||
lNum = lNum << 6;
|
||||
lNum = lNum | (c2 & 0x3f); // c AND 0011 1111
|
||||
|
||||
pEntry->mwsText += (wchar_t)lNum;
|
||||
++i;
|
||||
// Log(" %d: (%x %x) -> %d\n",i,c,c2,(wchar_t)lNum);
|
||||
} else {
|
||||
// if(sCatName == "TEST") Log(" %d: %c | %d\n",i,c,c);
|
||||
pEntry->mwsText += c;
|
||||
// if(sCatName == "TEST") Log(" '%s'\n",cString::To8Char(pEntry->mwsText).c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if(sE == "Motion blur:") Log("After String: '%s'\n",cString::To8Char(pEntry->mwsText).c_str());
|
||||
|
||||
auto ret = pCategory->m_mapEntries.insert(tLanguageEntryMap::value_type(sEntryName, pEntry));
|
||||
if (ret.second == false) {
|
||||
Warning("Language entry '%s' in category '%s' already exists!\n", sEntryName.c_str(), sCatName.c_str());
|
||||
hplDelete(pEntry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
hplDelete(pDoc);
|
||||
|
||||
/*{
|
||||
tString sRawFile = cString::SetFileExt(asFile,"")+"_raw_text.txt";
|
||||
Log("Saving raw text '%s'\n", sRawFile.c_str());
|
||||
FILE *pFile = fopen(sRawFile.c_str(),"w+");
|
||||
if(pFile==NULL) Error("Could not open file: '%s'\n", sRawFile.c_str());
|
||||
|
||||
tLanguageCategoryMapIt CatIt = m_mapCategories.begin();
|
||||
for(; CatIt != m_mapCategories.end(); ++CatIt)
|
||||
{
|
||||
cLanguageCategory *pCategory = CatIt->second;
|
||||
tLanguageEntryMapIt EntryIt = pCategory->m_mapEntries.begin();
|
||||
for(; EntryIt != pCategory->m_mapEntries.end(); ++EntryIt)
|
||||
{
|
||||
cLanguageEntry *pEntry = EntryIt->second;
|
||||
fputs(cString::To8Char(pEntry->mwsText + _W("\n\n")).c_str(), pFile);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fclose(pFile);
|
||||
}*/
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
const tWString &cLanguageFile::Translate(const tString &asCat, const tString &asName) {
|
||||
tLanguageCategoryMapIt CatIt = m_mapCategories.find(asCat);
|
||||
if (CatIt == m_mapCategories.end()) {
|
||||
Warning("Could not find language file category '%s'\n", asCat.c_str());
|
||||
return mwsEmpty;
|
||||
}
|
||||
|
||||
cLanguageCategory *pCategory = CatIt->second;
|
||||
tLanguageEntryMapIt EntryIt = pCategory->m_mapEntries.find(asName);
|
||||
if (EntryIt == pCategory->m_mapEntries.end()) {
|
||||
Warning("Could not find language file entry '%s'\n", asName.c_str());
|
||||
return mwsEmpty;
|
||||
}
|
||||
|
||||
cLanguageEntry *pEntry = EntryIt->second;
|
||||
|
||||
return pEntry->mwsText;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PRIVATE METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
} // namespace hpl
|
||||
82
engines/hpl1/engine/resources/LanguageFile.h
Normal file
82
engines/hpl1/engine/resources/LanguageFile.h
Normal file
@@ -0,0 +1,82 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#ifndef HPL_LANGUAGE_FILE_H
|
||||
#define HPL_LANGUAGE_FILE_H
|
||||
|
||||
#include "hpl1/engine/system/SystemTypes.h"
|
||||
#include "common/stablemap.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class cResources;
|
||||
|
||||
//--------------------------------
|
||||
|
||||
class cLanguageEntry {
|
||||
public:
|
||||
tWString mwsText;
|
||||
};
|
||||
|
||||
typedef Common::StableMap<tString, cLanguageEntry *> tLanguageEntryMap;
|
||||
typedef tLanguageEntryMap::iterator tLanguageEntryMapIt;
|
||||
|
||||
//--------------------------------
|
||||
|
||||
class cLanguageCategory {
|
||||
public:
|
||||
~cLanguageCategory() {
|
||||
STLMapDeleteAll(m_mapEntries);
|
||||
}
|
||||
|
||||
tLanguageEntryMap m_mapEntries;
|
||||
};
|
||||
|
||||
typedef Common::StableMap<tString, cLanguageCategory *> tLanguageCategoryMap;
|
||||
typedef tLanguageCategoryMap::iterator tLanguageCategoryMapIt;
|
||||
|
||||
//--------------------------------
|
||||
|
||||
class cLanguageFile {
|
||||
public:
|
||||
cLanguageFile(cResources *apResources);
|
||||
~cLanguageFile();
|
||||
|
||||
bool LoadFromFile(const tString asFile);
|
||||
|
||||
const tWString &Translate(const tString &asCat, const tString &asName);
|
||||
|
||||
private:
|
||||
tLanguageCategoryMap m_mapCategories;
|
||||
tWString mwsEmpty;
|
||||
|
||||
cResources *mpResources;
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_LANGUAGE_FILE_H
|
||||
415
engines/hpl1/engine/resources/MaterialManager.cpp
Normal file
415
engines/hpl1/engine/resources/MaterialManager.cpp
Normal file
@@ -0,0 +1,415 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#include "hpl1/engine/resources/MaterialManager.h"
|
||||
#include "hpl1/engine/graphics/Graphics.h"
|
||||
#include "hpl1/engine/graphics/Material.h"
|
||||
#include "hpl1/engine/graphics/MaterialHandler.h"
|
||||
#include "hpl1/engine/impl/tinyXML/tinyxml.h"
|
||||
#include "hpl1/engine/resources/Resources.h"
|
||||
#include "hpl1/engine/resources/TextureManager.h"
|
||||
#include "hpl1/engine/system/String.h"
|
||||
#include "hpl1/engine/system/System.h"
|
||||
#include "hpl1/engine/system/low_level_system.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cMaterialManager::cMaterialManager(cGraphics *apGraphics, cResources *apResources)
|
||||
: iResourceManager(apResources->GetFileSearcher(), apResources->GetLowLevel(),
|
||||
apResources->GetLowLevelSystem()) {
|
||||
mpGraphics = apGraphics;
|
||||
mpResources = apResources;
|
||||
|
||||
mlTextureSizeLevel = 0;
|
||||
mTextureFilter = eTextureFilter_Bilinear;
|
||||
mfTextureAnisotropy = 1.0f;
|
||||
|
||||
mlIdCounter = 0;
|
||||
}
|
||||
|
||||
cMaterialManager::~cMaterialManager() {
|
||||
DestroyAll();
|
||||
|
||||
Log(" Done with materials\n");
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iMaterial *cMaterialManager::CreateMaterial(const tString &asName) {
|
||||
tString sPath;
|
||||
iMaterial *pMaterial;
|
||||
tString asNewName;
|
||||
|
||||
BeginLoad(asName);
|
||||
|
||||
asNewName = cString::SetFileExt(asName, "mat");
|
||||
|
||||
pMaterial = static_cast<iMaterial *>(this->FindLoadedResource(asNewName, sPath));
|
||||
|
||||
if (pMaterial == NULL && sPath != "") {
|
||||
pMaterial = LoadFromFile(asNewName, sPath);
|
||||
|
||||
if (pMaterial == NULL) {
|
||||
Error("Couldn't load material '%s'\n", asNewName.c_str());
|
||||
EndLoad();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
AddResource(pMaterial);
|
||||
}
|
||||
|
||||
if (pMaterial)
|
||||
pMaterial->IncUserCount();
|
||||
else
|
||||
Error("Couldn't create material '%s'\n", asNewName.c_str());
|
||||
|
||||
EndLoad();
|
||||
return pMaterial;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iResourceBase *cMaterialManager::Create(const tString &asName) {
|
||||
return CreateMaterial(asName);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cMaterialManager::Update(float afTimeStep) {
|
||||
tResourceHandleMapIt it = m_mapHandleResources.begin();
|
||||
for (; it != m_mapHandleResources.end(); ++it) {
|
||||
iResourceBase *pBase = it->second;
|
||||
iMaterial *pMat = static_cast<iMaterial *>(pBase);
|
||||
|
||||
pMat->Update(afTimeStep);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cMaterialManager::Unload(iResourceBase *apResource) {
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cMaterialManager::Destroy(iResourceBase *apResource) {
|
||||
apResource->DecUserCount();
|
||||
|
||||
if (apResource->HasUsers() == false) {
|
||||
RemoveResource(apResource);
|
||||
hplDelete(apResource);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cMaterialManager::SetTextureFilter(eTextureFilter aFilter) {
|
||||
if (aFilter == mTextureFilter)
|
||||
return;
|
||||
mTextureFilter = aFilter;
|
||||
|
||||
tResourceHandleMapIt it = m_mapHandleResources.begin();
|
||||
for (; it != m_mapHandleResources.end(); ++it) {
|
||||
iMaterial *pMat = static_cast<iMaterial *>(it->second);
|
||||
|
||||
for (int i = 0; i < eMaterialTexture_LastEnum; ++i) {
|
||||
iTexture *pTex = pMat->GetTexture((eMaterialTexture)i);
|
||||
if (pTex)
|
||||
pTex->SetFilter(aFilter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cMaterialManager::SetTextureAnisotropy(float afX) {
|
||||
if (afX < 1.0 || mpGraphics->GetLowLevel()->GetCaps(eGraphicCaps_AnisotropicFiltering) == 0) {
|
||||
return;
|
||||
}
|
||||
if (afX > (float)mpGraphics->GetLowLevel()->GetCaps(eGraphicCaps_MaxAnisotropicFiltering)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mfTextureAnisotropy == afX)
|
||||
return;
|
||||
mfTextureAnisotropy = afX;
|
||||
|
||||
tResourceHandleMapIt it = m_mapHandleResources.begin();
|
||||
for (; it != m_mapHandleResources.end(); ++it) {
|
||||
iMaterial *pMat = static_cast<iMaterial *>(it->second);
|
||||
|
||||
for (int i = 0; i < eMaterialTexture_LastEnum; ++i) {
|
||||
iTexture *pTex = pMat->GetTexture((eMaterialTexture)i);
|
||||
if (pTex)
|
||||
pTex->SetAnisotropyDegree(mfTextureAnisotropy);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
tString cMaterialManager::GetPhysicsMaterialName(const tString &asName) {
|
||||
tString sPath;
|
||||
iMaterial *pMaterial;
|
||||
tString asNewName;
|
||||
|
||||
asNewName = cString::SetFileExt(asName, "mat");
|
||||
|
||||
pMaterial = static_cast<iMaterial *>(this->FindLoadedResource(asNewName, sPath));
|
||||
|
||||
if (pMaterial == NULL && sPath != "") {
|
||||
TiXmlDocument *pDoc = hplNew(TiXmlDocument, (sPath.c_str()));
|
||||
if (!pDoc->LoadFile()) {
|
||||
hplDelete(pDoc);
|
||||
return "";
|
||||
}
|
||||
|
||||
TiXmlElement *pRoot = pDoc->RootElement();
|
||||
|
||||
TiXmlElement *pMain = pRoot->FirstChildElement("Main");
|
||||
if (pMain == NULL) {
|
||||
hplDelete(pDoc);
|
||||
Error("Main child not found in '%s'\n", sPath.c_str());
|
||||
return "";
|
||||
}
|
||||
|
||||
tString sPhysicsName = cString::ToString(pMain->Attribute("PhysicsMaterial"), "Default");
|
||||
|
||||
hplDelete(pDoc);
|
||||
|
||||
return sPhysicsName;
|
||||
}
|
||||
|
||||
if (pMaterial)
|
||||
return pMaterial->GetPhysicsMaterial();
|
||||
else
|
||||
return "";
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PRIVATE METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
iMaterial *cMaterialManager::LoadFromFile(const tString &asName, const tString &asPath) {
|
||||
TiXmlDocument *pDoc = hplNew(TiXmlDocument, (asPath.c_str()));
|
||||
if (!pDoc->LoadFile()) {
|
||||
hplDelete(pDoc);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
TiXmlElement *pRoot = pDoc->RootElement();
|
||||
|
||||
///////////////////////////
|
||||
// Main
|
||||
TiXmlElement *pMain = pRoot->FirstChildElement("Main");
|
||||
if (pMain == NULL) {
|
||||
hplDelete(pDoc);
|
||||
Error("Main child not found.\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char *sType = pMain->Attribute("Type");
|
||||
if (sType == NULL) {
|
||||
hplDelete(pDoc);
|
||||
Error("Type not found.\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool bUseAlpha = cString::ToBool(pMain->Attribute("UseAlpha"), false);
|
||||
bool bDepthTest = cString::ToBool(pMain->Attribute("DepthTest"), true);
|
||||
float fValue = cString::ToFloat(pMain->Attribute("Value"), 1);
|
||||
tString sPhysicsMatName = cString::ToString(pMain->Attribute("PhysicsMaterial"), "Default");
|
||||
|
||||
iMaterial *pMat = mpGraphics->GetMaterialHandler()->Create(asName, sType, eMaterialPicture_Texture);
|
||||
if (pMat == NULL) {
|
||||
hplDelete(pDoc);
|
||||
Error("Invalid material type '%s'\n", sType);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pMat->SetHasAlpha(bUseAlpha);
|
||||
pMat->SetDepthTest(bDepthTest);
|
||||
pMat->SetValue(fValue);
|
||||
pMat->SetPhysicsMaterial(sPhysicsMatName);
|
||||
|
||||
///////////////////////////
|
||||
// Textures
|
||||
TiXmlElement *pTexRoot = pRoot->FirstChildElement("TextureUnits");
|
||||
if (pTexRoot == NULL) {
|
||||
hplDelete(pDoc);
|
||||
Error("TextureUnits child not found.\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
tTextureTypeList lstTexTypes = pMat->GetTextureTypes();
|
||||
tTextureTypeListIt it = lstTexTypes.begin();
|
||||
for (; it != lstTexTypes.end(); it++) {
|
||||
iTexture *pTex = nullptr;
|
||||
|
||||
TiXmlElement *pTexChild = pTexRoot->FirstChildElement(GetTextureString(it->mType).c_str());
|
||||
if (pTexChild == NULL) {
|
||||
/*Error("Texture unit missing!");
|
||||
hplDelete(pMat);
|
||||
return NULL;*/
|
||||
continue;
|
||||
}
|
||||
|
||||
eTextureTarget target = GetTarget(cString::ToString(pTexChild->Attribute("Type"), ""));
|
||||
tString sFile = cString::ToString(pTexChild->Attribute("File"), "");
|
||||
bool bMipMaps = cString::ToBool(pTexChild->Attribute("Mipmaps"), true);
|
||||
bool bCompress = cString::ToBool(pTexChild->Attribute("Compress"), false);
|
||||
eTextureWrap wrap = GetWrap(cString::ToString(pTexChild->Attribute("Wrap"), ""));
|
||||
|
||||
eTextureAnimMode animMode = GetAnimMode(cString::ToString(pTexChild->Attribute("AnimMode"), "None"));
|
||||
float fFrameTime = cString::ToFloat(pTexChild->Attribute("AnimFrameTime"), 1.0f);
|
||||
|
||||
if (sFile == "") {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (animMode != eTextureAnimMode_None) {
|
||||
pTex = mpResources->GetTextureManager()->CreateAnim2D(sFile, bMipMaps, bCompress,
|
||||
eTextureType_Normal,
|
||||
mlTextureSizeLevel);
|
||||
} else {
|
||||
if (target == eTextureTarget_2D) {
|
||||
pTex = mpResources->GetTextureManager()->Create2D(sFile, bMipMaps, bCompress,
|
||||
eTextureType_Normal,
|
||||
mlTextureSizeLevel);
|
||||
} else if (target == eTextureTarget_1D) {
|
||||
pTex = mpResources->GetTextureManager()->Create1D(sFile, bMipMaps, bCompress,
|
||||
eTextureType_Normal,
|
||||
mlTextureSizeLevel);
|
||||
} else if (target == eTextureTarget_CubeMap) {
|
||||
pTex = mpResources->GetTextureManager()->CreateCubeMap(sFile, bMipMaps, bCompress,
|
||||
eTextureType_Normal,
|
||||
mlTextureSizeLevel);
|
||||
}
|
||||
}
|
||||
|
||||
pTex->SetFrameTime(fFrameTime);
|
||||
pTex->SetAnimMode(animMode);
|
||||
|
||||
pTex->SetWrapS(wrap);
|
||||
pTex->SetWrapT(wrap);
|
||||
|
||||
pTex->SetFilter(mTextureFilter);
|
||||
pTex->SetAnisotropyDegree(mfTextureAnisotropy);
|
||||
|
||||
pMat->SetTexture(pTex, it->mType);
|
||||
}
|
||||
|
||||
///////////////////////////
|
||||
// Custom
|
||||
pMat->LoadData(pRoot);
|
||||
|
||||
hplDelete(pDoc);
|
||||
|
||||
pMat->Compile();
|
||||
|
||||
return pMat;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
eTextureTarget cMaterialManager::GetTarget(const tString &asType) {
|
||||
if (cString::ToLowerCase(asType) == "cube")
|
||||
return eTextureTarget_CubeMap;
|
||||
else if (cString::ToLowerCase(asType) == "1D")
|
||||
return eTextureTarget_1D;
|
||||
else if (cString::ToLowerCase(asType) == "2D")
|
||||
return eTextureTarget_2D;
|
||||
else if (cString::ToLowerCase(asType) == "3D")
|
||||
return eTextureTarget_3D;
|
||||
|
||||
return eTextureTarget_2D;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
tString cMaterialManager::GetTextureString(eMaterialTexture aType) {
|
||||
switch (aType) {
|
||||
case eMaterialTexture_Diffuse:
|
||||
return "Diffuse";
|
||||
case eMaterialTexture_Alpha:
|
||||
return "Alpha";
|
||||
case eMaterialTexture_NMap:
|
||||
return "NMap";
|
||||
case eMaterialTexture_Illumination:
|
||||
return "Illumination";
|
||||
case eMaterialTexture_Specular:
|
||||
return "Specular";
|
||||
case eMaterialTexture_CubeMap:
|
||||
return "CubeMap";
|
||||
case eMaterialTexture_Refraction:
|
||||
return "Refraction";
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
eTextureWrap cMaterialManager::GetWrap(const tString &asType) {
|
||||
if (cString::ToLowerCase(asType) == "repeat")
|
||||
return eTextureWrap_Repeat;
|
||||
else if (cString::ToLowerCase(asType) == "clamp")
|
||||
return eTextureWrap_Clamp;
|
||||
else if (cString::ToLowerCase(asType) == "clamptoedge")
|
||||
return eTextureWrap_ClampToEdge;
|
||||
|
||||
return eTextureWrap_Repeat;
|
||||
}
|
||||
|
||||
eTextureAnimMode cMaterialManager::GetAnimMode(const tString &asType) {
|
||||
if (cString::ToLowerCase(asType) == "none")
|
||||
return eTextureAnimMode_None;
|
||||
else if (cString::ToLowerCase(asType) == "loop")
|
||||
return eTextureAnimMode_Loop;
|
||||
else if (cString::ToLowerCase(asType) == "oscillate")
|
||||
return eTextureAnimMode_Oscillate;
|
||||
|
||||
return eTextureAnimMode_None;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
} // namespace hpl
|
||||
89
engines/hpl1/engine/resources/MaterialManager.h
Normal file
89
engines/hpl1/engine/resources/MaterialManager.h
Normal file
@@ -0,0 +1,89 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#ifndef HPL_MATERIAL_MANAGER_H
|
||||
#define HPL_MATERIAL_MANAGER_H
|
||||
|
||||
#include "hpl1/engine/graphics/Material.h"
|
||||
#include "hpl1/engine/graphics/Texture.h"
|
||||
#include "hpl1/engine/resources/ResourceManager.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class cGraphics;
|
||||
class cResources;
|
||||
class iMaterial;
|
||||
|
||||
class cMaterialManager : public iResourceManager {
|
||||
public:
|
||||
cMaterialManager(cGraphics *apGraphics, cResources *apResources);
|
||||
~cMaterialManager();
|
||||
|
||||
iResourceBase *Create(const tString &asName);
|
||||
iMaterial *CreateMaterial(const tString &asName);
|
||||
|
||||
void Update(float afTimeStep);
|
||||
|
||||
void Destroy(iResourceBase *apResource);
|
||||
void Unload(iResourceBase *apResource);
|
||||
|
||||
void SetTextureSizeLevel(unsigned int alLevel) { mlTextureSizeLevel = alLevel; }
|
||||
int GetTextureSizeLevel() { return mlTextureSizeLevel; }
|
||||
|
||||
void SetTextureFilter(eTextureFilter aFilter);
|
||||
eTextureFilter GetTextureFilter() { return mTextureFilter; }
|
||||
|
||||
void SetTextureAnisotropy(float afX);
|
||||
float GetTextureAnisotropy() { return mfTextureAnisotropy; }
|
||||
|
||||
tString GetPhysicsMaterialName(const tString &asName);
|
||||
|
||||
private:
|
||||
iMaterial *LoadFromFile(const tString &asName, const tString &asPath);
|
||||
|
||||
eTextureTarget GetTarget(const tString &asType);
|
||||
tString GetTextureString(eMaterialTexture aType);
|
||||
eTextureWrap GetWrap(const tString &asType);
|
||||
eTextureAnimMode GetAnimMode(const tString &asType);
|
||||
|
||||
unsigned int mlTextureSizeLevel;
|
||||
eTextureFilter mTextureFilter;
|
||||
float mfTextureAnisotropy;
|
||||
|
||||
tStringList mlstFileFormats;
|
||||
|
||||
tStringVec mvCubeSideSuffixes;
|
||||
|
||||
cGraphics *mpGraphics;
|
||||
cResources *mpResources;
|
||||
|
||||
int mlIdCounter;
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_MATERIAL_MANAGER_H
|
||||
95
engines/hpl1/engine/resources/MeshLoader.h
Normal file
95
engines/hpl1/engine/resources/MeshLoader.h
Normal file
@@ -0,0 +1,95 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#ifndef HPL_MESH_LOADER_H
|
||||
#define HPL_MESH_LOADER_H
|
||||
|
||||
#include "hpl1/engine/graphics/GraphicsTypes.h"
|
||||
#include "hpl1/engine/math/MathTypes.h"
|
||||
#include "hpl1/engine/system/SystemTypes.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
typedef tFlag tWorldLoadFlag;
|
||||
|
||||
#define eWorldLoadFlag_NoLights (0x00000001)
|
||||
#define eWorldLoadFlag_NoEntities (0x00000002)
|
||||
#define eWorldLoadFlag_NoGameEntities (0x00000004)
|
||||
|
||||
typedef tFlag tMeshLoadFlag;
|
||||
|
||||
#define eMeshLoadFlag_NoGeometry (0x00000001)
|
||||
|
||||
class cMesh;
|
||||
|
||||
class cResources;
|
||||
class cMaterialManager;
|
||||
class cMeshManager;
|
||||
class cAnimationManager;
|
||||
class cMeshLoaderHandler;
|
||||
class iLowLevelGraphics;
|
||||
class cWorld3D;
|
||||
class cScene;
|
||||
class cAnimation;
|
||||
class cSystem;
|
||||
|
||||
class iMeshLoader {
|
||||
friend class cMeshLoaderHandler;
|
||||
|
||||
public:
|
||||
iMeshLoader(iLowLevelGraphics *apLowLevelGraphics)
|
||||
: mpLowLevelGraphics(apLowLevelGraphics) {}
|
||||
virtual ~iMeshLoader() = default;
|
||||
|
||||
virtual cMesh *LoadMesh(const tString &asFile, tMeshLoadFlag aFlags) = 0;
|
||||
virtual bool SaveMesh(cMesh *apMesh, const tString &asFile) = 0;
|
||||
|
||||
virtual cWorld3D *LoadWorld(const tString &asFile, cScene *apScene, tWorldLoadFlag aFlags) = 0;
|
||||
|
||||
virtual cAnimation *LoadAnimation(const tString &asFile) = 0;
|
||||
|
||||
virtual bool IsSupported(const tString asFileType) = 0;
|
||||
|
||||
virtual void AddSupportedTypes(tStringVec *avFileTypes) = 0;
|
||||
|
||||
static void SetRestricStaticLightToSector(bool abX) { mbRestricStaticLightToSector = abX; }
|
||||
static void SetUseFastMaterial(bool abX) { mbUseFastMaterial = abX; }
|
||||
|
||||
protected:
|
||||
cMaterialManager *mpMaterialManager;
|
||||
cMeshManager *mpMeshManager;
|
||||
cAnimationManager *mpAnimationManager;
|
||||
iLowLevelGraphics *mpLowLevelGraphics;
|
||||
cSystem *mpSystem;
|
||||
|
||||
static bool mbRestricStaticLightToSector;
|
||||
static bool mbUseFastMaterial;
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_MESH_LOADER_H
|
||||
155
engines/hpl1/engine/resources/MeshLoaderHandler.cpp
Normal file
155
engines/hpl1/engine/resources/MeshLoaderHandler.cpp
Normal file
@@ -0,0 +1,155 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#include "hpl1/engine/resources/MeshLoaderHandler.h"
|
||||
|
||||
#include "hpl1/engine/resources/MeshLoader.h"
|
||||
#include "hpl1/engine/resources/Resources.h"
|
||||
#include "hpl1/engine/scene/Scene.h"
|
||||
#include "hpl1/engine/system/String.h"
|
||||
#include "hpl1/engine/system/low_level_system.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
bool iMeshLoader::mbRestricStaticLightToSector = false;
|
||||
bool iMeshLoader::mbUseFastMaterial = false;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cMeshLoaderHandler::cMeshLoaderHandler(cResources *apResources, cScene *apScene) {
|
||||
mpResources = apResources;
|
||||
mpScene = apScene;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cMeshLoaderHandler::~cMeshLoaderHandler() {
|
||||
tMeshLoaderListIt it = mlstLoaders.begin();
|
||||
for (; it != mlstLoaders.end(); it++) {
|
||||
hplDelete(*it);
|
||||
}
|
||||
|
||||
mlstLoaders.clear();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cMesh *cMeshLoaderHandler::LoadMesh(const tString &asFile, tMeshLoadFlag aFlags) {
|
||||
tString sType = cString::ToLowerCase(cString::GetFileExt(asFile));
|
||||
|
||||
tMeshLoaderListIt it = mlstLoaders.begin();
|
||||
for (; it != mlstLoaders.end(); it++) {
|
||||
iMeshLoader *pLoader = *it;
|
||||
|
||||
if (pLoader->IsSupported(sType)) {
|
||||
return pLoader->LoadMesh(asFile, aFlags);
|
||||
}
|
||||
}
|
||||
|
||||
Log("No loader for '%s' found!\n", sType.c_str());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cMeshLoaderHandler::SaveMesh(cMesh *apMesh, const tString &asFile) {
|
||||
tString sType = cString::ToLowerCase(cString::GetFileExt(asFile));
|
||||
|
||||
tMeshLoaderListIt it = mlstLoaders.begin();
|
||||
for (; it != mlstLoaders.end(); it++) {
|
||||
iMeshLoader *pLoader = *it;
|
||||
|
||||
if (pLoader->IsSupported(sType)) {
|
||||
return pLoader->SaveMesh(apMesh, asFile);
|
||||
}
|
||||
}
|
||||
|
||||
Log("No loader for '%s' found!\n", sType.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cWorld3D *cMeshLoaderHandler::LoadWorld(const tString &asFile, tWorldLoadFlag aFlags) {
|
||||
tString sType = cString::ToLowerCase(cString::GetFileExt(asFile));
|
||||
|
||||
tMeshLoaderListIt it = mlstLoaders.begin();
|
||||
for (; it != mlstLoaders.end(); it++) {
|
||||
iMeshLoader *pLoader = *it;
|
||||
|
||||
if (pLoader->IsSupported(sType)) {
|
||||
return pLoader->LoadWorld(asFile, mpScene, aFlags);
|
||||
}
|
||||
}
|
||||
|
||||
Log("No loader for '%s' found!\n", sType.c_str());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cAnimation *cMeshLoaderHandler::LoadAnimation(const tString &asFile) {
|
||||
tString sType = cString::ToLowerCase(cString::GetFileExt(asFile));
|
||||
|
||||
tMeshLoaderListIt it = mlstLoaders.begin();
|
||||
for (; it != mlstLoaders.end(); it++) {
|
||||
iMeshLoader *pLoader = *it;
|
||||
|
||||
if (pLoader->IsSupported(sType)) {
|
||||
return pLoader->LoadAnimation(asFile);
|
||||
}
|
||||
}
|
||||
|
||||
Log("No loader for '%s' found!\n", sType.c_str());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cMeshLoaderHandler::AddLoader(iMeshLoader *apLoader) {
|
||||
mlstLoaders.push_back(apLoader);
|
||||
|
||||
apLoader->mpMaterialManager = mpResources->GetMaterialManager();
|
||||
apLoader->mpMeshManager = mpResources->GetMeshManager();
|
||||
apLoader->mpAnimationManager = mpResources->GetAnimationManager();
|
||||
apLoader->mpSystem = mpScene->GetSystem();
|
||||
|
||||
apLoader->AddSupportedTypes(&mvSupportedTypes);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
} // namespace hpl
|
||||
77
engines/hpl1/engine/resources/MeshLoaderHandler.h
Normal file
77
engines/hpl1/engine/resources/MeshLoaderHandler.h
Normal file
@@ -0,0 +1,77 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#ifndef HPL_MESH_LOADER_HANDLER_H
|
||||
#define HPL_MESH_LOADER_HANDLER_H
|
||||
|
||||
#include "hpl1/engine/graphics/GraphicsTypes.h"
|
||||
#include "hpl1/engine/math/MathTypes.h"
|
||||
#include "hpl1/engine/system/SystemTypes.h"
|
||||
|
||||
#include "common/list.h"
|
||||
#include "hpl1/engine/resources/MeshLoader.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class cMesh;
|
||||
class iMeshLoader;
|
||||
class cResources;
|
||||
class cWorld3D;
|
||||
class cScene;
|
||||
class cAnimation;
|
||||
|
||||
typedef Common::List<iMeshLoader *> tMeshLoaderList;
|
||||
typedef tMeshLoaderList::iterator tMeshLoaderListIt;
|
||||
|
||||
class cMeshLoaderHandler {
|
||||
public:
|
||||
cMeshLoaderHandler(cResources *apResources, cScene *apScene);
|
||||
~cMeshLoaderHandler();
|
||||
|
||||
cMesh *LoadMesh(const tString &asFile, tMeshLoadFlag aFlags);
|
||||
bool SaveMesh(cMesh *apMesh, const tString &asFile);
|
||||
|
||||
cWorld3D *LoadWorld(const tString &asFile, tWorldLoadFlag aFlags);
|
||||
|
||||
cAnimation *LoadAnimation(const tString &asFile);
|
||||
|
||||
void AddLoader(iMeshLoader *apLoader);
|
||||
|
||||
tStringVec *GetSupportedTypes() { return &mvSupportedTypes; }
|
||||
|
||||
private:
|
||||
tStringVec mvSupportedTypes;
|
||||
|
||||
tMeshLoaderList mlstLoaders;
|
||||
|
||||
cResources *mpResources;
|
||||
cScene *mpScene;
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_MESH_LOADER_HANDLER_H
|
||||
148
engines/hpl1/engine/resources/MeshManager.cpp
Normal file
148
engines/hpl1/engine/resources/MeshManager.cpp
Normal file
@@ -0,0 +1,148 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#include "hpl1/engine/resources/MeshManager.h"
|
||||
#include "hpl1/engine/graphics/Mesh.h"
|
||||
#include "hpl1/engine/resources/FileSearcher.h"
|
||||
#include "hpl1/engine/resources/MeshLoaderHandler.h"
|
||||
#include "hpl1/engine/resources/Resources.h"
|
||||
#include "hpl1/engine/system/String.h"
|
||||
#include "hpl1/engine/system/System.h"
|
||||
#include "hpl1/engine/system/low_level_system.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cMeshManager::cMeshManager(cGraphics *apGraphic, cResources *apResources)
|
||||
: iResourceManager(apResources->GetFileSearcher(), apResources->GetLowLevel(),
|
||||
apResources->GetLowLevelSystem()) {
|
||||
mpGraphics = apGraphic;
|
||||
mpResources = apResources;
|
||||
}
|
||||
|
||||
cMeshManager::~cMeshManager() {
|
||||
DestroyAll();
|
||||
|
||||
Log(" Done with meshes\n");
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cMesh *cMeshManager::CreateMesh(const tString &asName) {
|
||||
tString sPath;
|
||||
cMesh *pMesh;
|
||||
tString asNewName;
|
||||
|
||||
BeginLoad(asName);
|
||||
|
||||
asNewName = asName; // cString::SetFileExt(asName,"mesh");
|
||||
|
||||
// If the file is missing an extension, search for an existing file.
|
||||
if (cString::GetFileExt(asNewName) == "") {
|
||||
bool bFound = false;
|
||||
tStringVec *pTypes = mpResources->GetMeshLoaderHandler()->GetSupportedTypes();
|
||||
for (size_t i = 0; i < pTypes->size(); i++) {
|
||||
asNewName = cString::SetFileExt(asNewName, (*pTypes)[i]);
|
||||
tString sPath2 = mpResources->GetFileSearcher()->GetFilePath(asNewName);
|
||||
if (sPath2 != "") {
|
||||
bFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (bFound == false) {
|
||||
Error("Couldn't create mesh '%s'\n", asName.c_str());
|
||||
EndLoad();
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
pMesh = static_cast<cMesh *>(this->FindLoadedResource(asNewName, sPath));
|
||||
|
||||
if (pMesh == NULL && sPath != "") {
|
||||
pMesh = mpResources->GetMeshLoaderHandler()->LoadMesh(sPath, 0);
|
||||
if (pMesh == NULL) {
|
||||
EndLoad();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
AddResource(pMesh);
|
||||
}
|
||||
|
||||
if (pMesh)
|
||||
pMesh->IncUserCount();
|
||||
else
|
||||
Error("Couldn't create mesh '%s'\n", asNewName.c_str());
|
||||
|
||||
EndLoad();
|
||||
return pMesh;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iResourceBase *cMeshManager::Create(const tString &asName) {
|
||||
return CreateMesh(asName);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cMeshManager::Unload(iResourceBase *apResource) {
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cMeshManager::Destroy(iResourceBase *apResource) {
|
||||
apResource->DecUserCount();
|
||||
|
||||
if (apResource->HasUsers() == false) {
|
||||
RemoveResource(apResource);
|
||||
hplDelete(apResource);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PRIVATE METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
} // namespace hpl
|
||||
57
engines/hpl1/engine/resources/MeshManager.h
Normal file
57
engines/hpl1/engine/resources/MeshManager.h
Normal file
@@ -0,0 +1,57 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#ifndef HPL_MESH_MANAGER_H
|
||||
#define HPL_MESH_MANAGER_H
|
||||
|
||||
#include "hpl1/engine/resources/ResourceManager.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class cGraphics;
|
||||
class cResources;
|
||||
class cMesh;
|
||||
|
||||
class cMeshManager : public iResourceManager {
|
||||
public:
|
||||
cMeshManager(cGraphics *apGraphics, cResources *apResources);
|
||||
~cMeshManager();
|
||||
|
||||
iResourceBase *Create(const tString &asName);
|
||||
cMesh *CreateMesh(const tString &asName);
|
||||
|
||||
void Destroy(iResourceBase *apResource);
|
||||
void Unload(iResourceBase *apResource);
|
||||
|
||||
private:
|
||||
cGraphics *mpGraphics;
|
||||
cResources *mpResources;
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_MESH_MANAGER_H
|
||||
202
engines/hpl1/engine/resources/ParticleManager.cpp
Normal file
202
engines/hpl1/engine/resources/ParticleManager.cpp
Normal file
@@ -0,0 +1,202 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#include "hpl1/engine/resources/ParticleManager.h"
|
||||
|
||||
#include "hpl1/engine/graphics/Graphics.h"
|
||||
#include "hpl1/engine/graphics/ParticleSystem3D.h"
|
||||
#include "hpl1/engine/resources/FileSearcher.h"
|
||||
#include "hpl1/engine/resources/Resources.h"
|
||||
#include "hpl1/engine/system/low_level_system.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cParticleManager::cParticleManager(cGraphics *apGraphics, cResources *apResources)
|
||||
: iResourceManager(apResources->GetFileSearcher(), apResources->GetLowLevel(),
|
||||
apResources->GetLowLevelSystem()) {
|
||||
mpGraphics = apGraphics;
|
||||
mpResources = apResources;
|
||||
}
|
||||
|
||||
cParticleManager::~cParticleManager() {
|
||||
tResourceHandleMapIt it = m_mapHandleResources.begin();
|
||||
for (; it != m_mapHandleResources.end(); ++it) {
|
||||
iResourceBase *pResource = it->second;
|
||||
while (pResource->HasUsers())
|
||||
pResource->DecUserCount();
|
||||
}
|
||||
|
||||
DestroyUnused(0);
|
||||
|
||||
Log(" Done with particles\n");
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iResourceBase *cParticleManager::Create(const tString &asName) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iParticleSystem2D *cParticleManager::CreatePS2D(const tString &asName, cVector3f avSize) {
|
||||
/*tParticleSystemDataMapIt it = m_mapData.find(asName);
|
||||
if(it == m_mapData.end()) return NULL;
|
||||
|
||||
iParticleSystemData *pData = it->second;
|
||||
|
||||
//Is name needed?..nahh
|
||||
iParticleSystem* pPart = pData->Create("",avSize);
|
||||
pPart->SetDataName(asName);
|
||||
pPart->SetDataSize(avSize);
|
||||
|
||||
if(pPart->GetType() == eParticleSystemType_2D)
|
||||
return static_cast<iParticleSystem2D*>(pPart);
|
||||
else
|
||||
{
|
||||
hplDelete(pPart);
|
||||
return NULL;
|
||||
}*/
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cParticleSystem3D *cParticleManager::CreatePS3D(const tString &asName, const tString &asType,
|
||||
cVector3f avSize, const cMatrixf &a_mtxTransform) {
|
||||
cParticleSystemData3D *pData = NULL;
|
||||
|
||||
tString sTypeName = cString::SetFileExt(cString::ToLowerCase(asType), "");
|
||||
|
||||
// tParticleSystemData3DMapIt it = m_mapData3D.find(sTypeName);
|
||||
// if(it == m_mapData3D.end())
|
||||
pData = static_cast<cParticleSystemData3D *>(GetByName(sTypeName));
|
||||
if (pData == NULL) {
|
||||
tString sFile = cString::SetFileExt(asType, "ps");
|
||||
|
||||
tString sPath = mpFileSearcher->GetFilePath(sFile);
|
||||
|
||||
if (sPath == "") {
|
||||
Error("Couldn't find particle system file '%s'\n", sFile.c_str());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cParticleSystemData3D *pPSData = hplNew(cParticleSystemData3D, (sTypeName,
|
||||
mpResources, mpGraphics));
|
||||
|
||||
if (pPSData->LoadFromFile(sPath) == false) {
|
||||
Error("Can't load data from particle system file '%s'\n", sTypeName.c_str());
|
||||
hplDelete(pPSData);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
AddData3D(pPSData);
|
||||
|
||||
pData = pPSData;
|
||||
}
|
||||
|
||||
pData->IncUserCount();
|
||||
cParticleSystem3D *pPS = pData->Create(asName, avSize, a_mtxTransform);
|
||||
pPS->SetDataName(asType);
|
||||
pPS->SetDataSize(avSize);
|
||||
pPS->SetParticleManager(this);
|
||||
|
||||
return pPS;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cParticleManager::AddData3D(cParticleSystemData3D *apData) {
|
||||
AddResource(apData);
|
||||
// m.insert(tParticleSystemData3DMap::value_type(cString::ToLowerCase(apData->GetName()),
|
||||
// apData));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cParticleManager::Preload(const tString &asFile) {
|
||||
tString sTypeName = cString::SetFileExt(cString::ToLowerCase(asFile), "");
|
||||
|
||||
// tParticleSystemData3DMapIt it = m_mapData3D.find(sTypeName);
|
||||
// if(it == m_mapData3D.end())
|
||||
cParticleSystemData3D *pData = static_cast<cParticleSystemData3D *>(GetByName(sTypeName));
|
||||
if (pData == NULL) {
|
||||
tString sFile = cString::SetFileExt(asFile, "ps");
|
||||
tString sPath = mpFileSearcher->GetFilePath(sFile);
|
||||
if (sPath == "") {
|
||||
Error("Couldn't find particle system file '%s'\n", sFile.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
cParticleSystemData3D *pPSData = hplNew(cParticleSystemData3D, (sTypeName,
|
||||
mpResources, mpGraphics));
|
||||
|
||||
if (pPSData->LoadFromFile(sPath) == false) {
|
||||
Error("Can't load data from particle system file '%s'\n", sTypeName.c_str());
|
||||
hplDelete(pPSData);
|
||||
return;
|
||||
}
|
||||
|
||||
AddData3D(pPSData);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cParticleManager::Unload(iResourceBase *apResource) {
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cParticleManager::Destroy(iResourceBase *apResource) {
|
||||
if (apResource->HasUsers()) {
|
||||
apResource->DecUserCount();
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PRIVATE METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
} // namespace hpl
|
||||
86
engines/hpl1/engine/resources/ParticleManager.h
Normal file
86
engines/hpl1/engine/resources/ParticleManager.h
Normal file
@@ -0,0 +1,86 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#ifndef HPL_PARTICLE_SYSTEM_MANAGER_H
|
||||
#define HPL_PARTICLE_SYSTEM_MANAGER_H
|
||||
|
||||
#include "hpl1/engine/resources/ResourceManager.h"
|
||||
|
||||
#include "hpl1/engine/math/MathTypes.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class cGraphics;
|
||||
class cResources;
|
||||
class iParticleSystem2D;
|
||||
class cParticleSystem3D;
|
||||
class cParticleSystemData3D;
|
||||
|
||||
//----------------------------------------------------
|
||||
|
||||
typedef Common::StableMap<tString, cParticleSystemData3D *> tParticleSystemData3DMap;
|
||||
typedef tParticleSystemData3DMap::iterator tParticleSystemData3DMapIt;
|
||||
|
||||
//----------------------------------------------------
|
||||
|
||||
class cParticleManager : public iResourceManager {
|
||||
public:
|
||||
cParticleManager(cGraphics *apGraphics, cResources *apResources);
|
||||
~cParticleManager();
|
||||
|
||||
/**
|
||||
* NOT USED! For now that is... there is no need for it since particle systems are not really
|
||||
* resources, yet
|
||||
* \param asName
|
||||
* \return
|
||||
*/
|
||||
iResourceBase *Create(const tString &asName);
|
||||
|
||||
iParticleSystem2D *CreatePS2D(const tString &asName, cVector3f avSize);
|
||||
|
||||
cParticleSystem3D *CreatePS3D(const tString &asName, const tString &asType, cVector3f avSize,
|
||||
const cMatrixf &a_mtxTransform);
|
||||
|
||||
void AddData3D(cParticleSystemData3D *apData);
|
||||
|
||||
void Preload(const tString &asFile);
|
||||
|
||||
void Destroy(iResourceBase *apResource);
|
||||
void Unload(iResourceBase *apResource);
|
||||
|
||||
private:
|
||||
cGraphics *mpGraphics;
|
||||
cResources *mpResources;
|
||||
|
||||
Common::List<cParticleSystem3D *> mlstSystems;
|
||||
|
||||
// tParticleSystemData3DMap m_mapData3D;
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_PARTICLE_SYSTEM_MANAGER_H
|
||||
63
engines/hpl1/engine/resources/ResourceBase.cpp
Normal file
63
engines/hpl1/engine/resources/ResourceBase.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#include "hpl1/engine/resources/ResourceBase.h"
|
||||
|
||||
#include "hpl1/engine/system/low_level_system.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
bool iResourceBase::mbLogCreateAndDelete = false;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
iResourceBase::iResourceBase(tString asName, unsigned long alPrio) {
|
||||
mlTime = 0; //(unsigned long)time(NULL);
|
||||
mlPrio = alPrio;
|
||||
mlHandle = 0;
|
||||
mlUserCount = 0;
|
||||
msName = asName;
|
||||
mbLogDestruction = false;
|
||||
}
|
||||
|
||||
iResourceBase::~iResourceBase() {
|
||||
if (mbLogDestruction && mbLogCreateAndDelete)
|
||||
Log(" Destroyed resource '%s'\n", msName.c_str());
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void iResourceBase::IncUserCount() {
|
||||
mlUserCount++;
|
||||
mlTime = 0; //(unsigned long)time(NULL);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
} // namespace hpl
|
||||
95
engines/hpl1/engine/resources/ResourceBase.h
Normal file
95
engines/hpl1/engine/resources/ResourceBase.h
Normal file
@@ -0,0 +1,95 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#ifndef HPL_RESOURCEBASE_H
|
||||
#define HPL_RESOURCEBASE_H
|
||||
|
||||
#include "hpl1/engine/system/SystemTypes.h"
|
||||
#include "hpl1/engine/system/low_level_system.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class iResourceBase {
|
||||
public:
|
||||
iResourceBase(tString asName, unsigned long alPrio);
|
||||
|
||||
virtual ~iResourceBase();
|
||||
|
||||
/**
|
||||
* virtual bool Reload()=0;
|
||||
* \return true is reload was successful, else false.
|
||||
*/
|
||||
virtual bool reload() = 0;
|
||||
|
||||
/**
|
||||
* Free most the memory, save info to get started again.
|
||||
*/
|
||||
virtual void unload() = 0;
|
||||
|
||||
/**
|
||||
* Free all memory.
|
||||
*/
|
||||
virtual void destroy() = 0;
|
||||
|
||||
tString GetName() { return msName; }
|
||||
unsigned long GetHandle() { return mlHandle; }
|
||||
void SetHandle(unsigned long alHandle) { mlHandle = alHandle; }
|
||||
tString GetFilePath() { return msFilePath; }
|
||||
unsigned long GetTime() { return mlTime; }
|
||||
unsigned long GetPrio() { return mlPrio; }
|
||||
unsigned long GetSize() { return mlSize; }
|
||||
|
||||
void SetLogDestruction(bool abX) { mbLogDestruction = abX; }
|
||||
|
||||
unsigned int GetUserCount() { return mlUserCount; }
|
||||
void IncUserCount();
|
||||
void DecUserCount() {
|
||||
if (mlUserCount > 0)
|
||||
mlUserCount--;
|
||||
}
|
||||
bool HasUsers() { return mlUserCount > 0; }
|
||||
|
||||
static bool GetLogCreateAndDelete() { return mbLogCreateAndDelete; }
|
||||
static void SetLogCreateAndDelete(bool abX) { mbLogCreateAndDelete = abX; }
|
||||
|
||||
protected:
|
||||
static bool mbLogCreateAndDelete;
|
||||
|
||||
unsigned int mlPrio; // dunno if this will be of any use.
|
||||
unsigned long mlTime; // Time for creation.
|
||||
unsigned long mlSize; // for completion. Not used yet.
|
||||
|
||||
unsigned int mlUserCount;
|
||||
unsigned long mlHandle;
|
||||
tString msName;
|
||||
tString msFilePath;
|
||||
bool mbLogDestruction;
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_RESOURCEBASE_H
|
||||
132
engines/hpl1/engine/resources/ResourceImage.cpp
Normal file
132
engines/hpl1/engine/resources/ResourceImage.cpp
Normal file
@@ -0,0 +1,132 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#include "hpl1/engine/resources/ResourceImage.h"
|
||||
#include "hpl1/engine/graphics/Texture.h"
|
||||
#include "hpl1/engine/resources/FrameTexture.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#define kContractSize (0.001f)
|
||||
|
||||
cResourceImage::cResourceImage(tString asName, cFrameTexture *apFrameTex,
|
||||
cFrameBitmap *apFrameBmp, cRect2l aRect,
|
||||
cVector2l avSrcSize, int alHandle) : iResourceBase(asName, 0) {
|
||||
mpFrameTexture = apFrameTex;
|
||||
mpFrameBitmap = apFrameBmp;
|
||||
mRect = aRect;
|
||||
mvSourceSize = avSrcSize;
|
||||
mlHandle = alHandle;
|
||||
|
||||
cVector2f vTexSize = cVector2f((float)mRect.w, (float)mRect.h) /
|
||||
cVector2f((float)mvSourceSize.x, (float)mvSourceSize.y);
|
||||
cVector2f vTexPos = cVector2f((float)mRect.x, (float)mRect.y) /
|
||||
cVector2f((float)mvSourceSize.x, (float)mvSourceSize.y);
|
||||
|
||||
mvVtx.push_back(cVertex(cVector3f(0, 0, 0),
|
||||
cVector3f(vTexPos.x + kContractSize, vTexPos.y + kContractSize, 0), cColor(1)));
|
||||
|
||||
mvVtx.push_back(cVertex(cVector3f((float)mRect.w, 0, 0),
|
||||
cVector3f(vTexPos.x + vTexSize.x - kContractSize, vTexPos.y + kContractSize, 0),
|
||||
cColor(1)));
|
||||
|
||||
mvVtx.push_back(cVertex(cVector3f((float)mRect.w, (float)mRect.h, 0),
|
||||
cVector3f(vTexPos.x + vTexSize.x - kContractSize, vTexPos.y + vTexSize.y - kContractSize, 0),
|
||||
cColor(1)));
|
||||
|
||||
mvVtx.push_back(cVertex(cVector3f(0, (float)mRect.h, 0),
|
||||
cVector3f(vTexPos.x + kContractSize, vTexPos.y + vTexSize.y - kContractSize, 0),
|
||||
cColor(1)));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cResourceImage::~cResourceImage() {
|
||||
mvVtx.clear();
|
||||
// mpFrameTexture->DecPicCount();
|
||||
mpFrameTexture = NULL;
|
||||
mlHandle = -1;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iTexture *cResourceImage::GetTexture() const { return mpFrameTexture->GetTexture(); }
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
tVertexVec cResourceImage::GetVertexVecCopy(const cVector2f &avPos, const cVector2f &avSize) {
|
||||
tVertexVec vTmpVtx = mvVtx;
|
||||
|
||||
if (avSize == cVector2f(-1, -1)) {
|
||||
vTmpVtx[1].pos.x = mvVtx[0].pos.x + mRect.w;
|
||||
vTmpVtx[2].pos.x = mvVtx[0].pos.x + mRect.w;
|
||||
vTmpVtx[2].pos.y = mvVtx[0].pos.y + mRect.h;
|
||||
vTmpVtx[3].pos.y = mvVtx[0].pos.y + mRect.h;
|
||||
} else {
|
||||
vTmpVtx[1].pos.x = mvVtx[0].pos.x + avSize.x;
|
||||
vTmpVtx[2].pos.x = mvVtx[0].pos.x + avSize.x;
|
||||
vTmpVtx[2].pos.y = mvVtx[0].pos.y + avSize.y;
|
||||
vTmpVtx[3].pos.y = mvVtx[0].pos.y + avSize.y;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
vTmpVtx[i].pos += avPos;
|
||||
|
||||
return vTmpVtx;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cResourceImage::reload() {
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cResourceImage::unload() {
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cResourceImage::destroy() {
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
} // namespace hpl
|
||||
91
engines/hpl1/engine/resources/ResourceImage.h
Normal file
91
engines/hpl1/engine/resources/ResourceImage.h
Normal file
@@ -0,0 +1,91 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#ifndef HPL_RESOURCE_IMAGE_H
|
||||
#define HPL_RESOURCE_IMAGE_H
|
||||
|
||||
#include "hpl1/engine/resources/ResourceBase.h"
|
||||
|
||||
#include "common/array.h"
|
||||
#include "hpl1/engine/graphics/GraphicsTypes.h"
|
||||
#include "hpl1/engine/math/MathTypes.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class cFrameTexture;
|
||||
class cFrameBitmap;
|
||||
class iTexture;
|
||||
|
||||
class cResourceImage : public iResourceBase {
|
||||
friend class cImageManager;
|
||||
|
||||
public:
|
||||
cResourceImage(tString asName, cFrameTexture *apFrameTex,
|
||||
cFrameBitmap *apFrameBmp,
|
||||
cRect2l aRect,
|
||||
cVector2l avSrcSize, int alHandle);
|
||||
|
||||
bool reload();
|
||||
void unload();
|
||||
void destroy();
|
||||
|
||||
// Image specific
|
||||
int GetHeight() const { return mRect.h; }
|
||||
int GetWidth() const { return mRect.w; }
|
||||
cVector2l GetSize() const { return cVector2l(mRect.w, mRect.h); }
|
||||
cVector2l GetPosition() const { return cVector2l(mRect.x, mRect.y); }
|
||||
|
||||
int GetSourceWidth() const { return mvSourceSize.x; }
|
||||
int GetSourceHeight() const { return mvSourceSize.y; }
|
||||
|
||||
iTexture *GetTexture() const;
|
||||
|
||||
cFrameTexture *GetFrameTexture() const { return mpFrameTexture; }
|
||||
cFrameBitmap *GetFrameBitmap() const { return mpFrameBitmap; }
|
||||
|
||||
tVertexVec GetVertexVecCopy(const cVector2f &avPos, const cVector2f &avSize);
|
||||
const tVertexVec &GetVertexVec() { return mvVtx; }
|
||||
|
||||
private:
|
||||
~cResourceImage();
|
||||
|
||||
cFrameTexture *mpFrameTexture;
|
||||
cFrameBitmap *mpFrameBitmap;
|
||||
|
||||
cVector2l mvSourceSize;
|
||||
cRect2l mRect;
|
||||
tVertexVec mvVtx;
|
||||
|
||||
int mlHandle;
|
||||
};
|
||||
|
||||
typedef Common::Array<cResourceImage *> tResourceImageVec;
|
||||
typedef tResourceImageVec::iterator tResourceImageVecIt;
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_RESOURCE_IMAGE_H
|
||||
255
engines/hpl1/engine/resources/ResourceManager.cpp
Normal file
255
engines/hpl1/engine/resources/ResourceManager.cpp
Normal file
@@ -0,0 +1,255 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#include "hpl1/engine/resources/ResourceManager.h"
|
||||
#include "hpl1/engine/system/String.h"
|
||||
|
||||
#include "hpl1/engine/resources/FileSearcher.h"
|
||||
#include "hpl1/engine/resources/ResourceBase.h"
|
||||
#include "hpl1/engine/resources/low_level_resources.h"
|
||||
|
||||
#include "hpl1/engine/system/low_level_system.h"
|
||||
|
||||
#include "common/algorithm.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
int iResourceManager::mlTabCount = 0;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iResourceManager::iResourceManager(cFileSearcher *apFileSearcher,
|
||||
LowLevelResources *apLowLevelResources,
|
||||
LowLevelSystem *apLowLevelSystem) {
|
||||
mpFileSearcher = apFileSearcher;
|
||||
mpLowLevelResources = apLowLevelResources;
|
||||
mpLowLevelSystem = apLowLevelSystem;
|
||||
mlHandleCount = 0;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iResourceBase *iResourceManager::GetByName(const tString &asName) {
|
||||
tString sName = cString::ToLowerCase(asName);
|
||||
// Log("Looking for '%s' \n", sName.c_str());
|
||||
|
||||
tResourceNameMapIt it = m_mapNameResources.find(sName);
|
||||
if (it == m_mapNameResources.end())
|
||||
return NULL;
|
||||
|
||||
return it->second;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iResourceBase *iResourceManager::GetByHandle(unsigned long alHandle) {
|
||||
tResourceHandleMapIt it = m_mapHandleResources.find(alHandle);
|
||||
if (it == m_mapHandleResources.end())
|
||||
return NULL;
|
||||
|
||||
return it->second;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cResourceBaseIterator iResourceManager::GetResourceBaseIterator() {
|
||||
return cResourceBaseIterator(&m_mapNameResources);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
/*void iResourceManager::Destroy(iResourceBase* apResource)
|
||||
{
|
||||
apResource->DecUserCount();
|
||||
if(apResource->HasUsers()==false){
|
||||
m_mapHandleResources.erase(apResource->GetHandle());
|
||||
m_mapNameResources.erase(apResource->GetName());
|
||||
hplDelete(apResource);
|
||||
}
|
||||
}*/
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
class cSortResources {
|
||||
public:
|
||||
bool operator()(iResourceBase *apResourceA, iResourceBase *apResourceB) {
|
||||
if (apResourceA->GetUserCount() != apResourceB->GetUserCount()) {
|
||||
return apResourceA->GetUserCount() > apResourceB->GetUserCount();
|
||||
}
|
||||
|
||||
return apResourceA->GetTime() > apResourceB->GetTime();
|
||||
}
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void iResourceManager::DestroyUnused(int alMaxToKeep) {
|
||||
// Log("Start Num Of: %d\n",m_mapHandleResources.size());
|
||||
// Check if there are too many resources.
|
||||
if ((int)m_mapHandleResources.size() <= alMaxToKeep)
|
||||
return;
|
||||
|
||||
// Add resources to a vector
|
||||
Common::Array<iResourceBase *> vResources;
|
||||
vResources.reserve(m_mapHandleResources.size());
|
||||
|
||||
tResourceHandleMapIt it = m_mapHandleResources.begin();
|
||||
for (; it != m_mapHandleResources.end(); ++it) {
|
||||
vResources.push_back(it->second);
|
||||
}
|
||||
|
||||
// Sort the sounds according to num of users and then time.
|
||||
Common::sort(vResources.data(), vResources.data() + vResources.size(), cSortResources());
|
||||
// Log("-------------Num: %d-----------------\n",vResources.size());
|
||||
for (size_t i = alMaxToKeep; i < vResources.size(); ++i) {
|
||||
iResourceBase *pRes = vResources[i];
|
||||
// Log("%s count:%d time:%d\n",pRes->GetName().c_str(),
|
||||
// pRes->GetUserCount(),
|
||||
// pRes->GetTime());
|
||||
|
||||
if (pRes->HasUsers() == false) {
|
||||
RemoveResource(pRes);
|
||||
hplDelete(pRes);
|
||||
}
|
||||
}
|
||||
// Log("--------------------------------------\n");
|
||||
// Log("End Num Of: %d\n",m_mapHandleResources.size());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void iResourceManager::DestroyAll() {
|
||||
tResourceHandleMapIt it = m_mapHandleResources.begin();
|
||||
while (it != m_mapHandleResources.end()) {
|
||||
// Log("Start destroy...");
|
||||
|
||||
iResourceBase *pResource = it->second;
|
||||
|
||||
// Log(" res: : %d ...",pResource->GetName().c_str(),pResource->GetUserCount());
|
||||
|
||||
while (pResource->HasUsers())
|
||||
pResource->DecUserCount();
|
||||
|
||||
Destroy(pResource);
|
||||
|
||||
it = m_mapHandleResources.begin();
|
||||
|
||||
// Log(" Done!\n");
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PROTECTED METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void iResourceManager::BeginLoad(const tString &asFile) {
|
||||
mlTimeStart = GetApplicationTime();
|
||||
|
||||
// Log("Begin resource: %s\n",asFile.c_str());
|
||||
|
||||
mlTabCount++;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void iResourceManager::EndLoad() {
|
||||
mlTabCount--;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iResourceBase *iResourceManager::FindLoadedResource(const tString &asName, tString &asFilePath) {
|
||||
iResourceBase *pResource = GetByName(asName);
|
||||
if (pResource == NULL) {
|
||||
asFilePath = mpFileSearcher->GetFilePath(asName);
|
||||
} else {
|
||||
asFilePath = "";
|
||||
}
|
||||
|
||||
return pResource;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
tString iResourceManager::GetTabs() {
|
||||
tString sTabs = "";
|
||||
for (int i = 0; i < mlTabCount; ++i)
|
||||
sTabs += " ";
|
||||
return sTabs;
|
||||
}
|
||||
|
||||
void iResourceManager::AddResource(iResourceBase *apResource, bool abLog) {
|
||||
apResource->SetHandle(GetHandle());
|
||||
|
||||
tString sName = cString::ToLowerCase(apResource->GetName());
|
||||
|
||||
m_mapHandleResources.insert(tResourceHandleMap::value_type(
|
||||
apResource->GetHandle(), apResource));
|
||||
m_mapNameResources.insert(tResourceNameMap::value_type(
|
||||
sName, apResource));
|
||||
|
||||
if (abLog && iResourceBase::GetLogCreateAndDelete()) {
|
||||
unsigned long lTime = GetApplicationTime() - mlTimeStart;
|
||||
Log("%sLoaded resource %s in %d ms\n", GetTabs().c_str(), apResource->GetName().c_str(), lTime);
|
||||
apResource->SetLogDestruction(true);
|
||||
}
|
||||
|
||||
// Log("End resource: %s\n",apResource->GetName().c_str());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void iResourceManager::RemoveResource(iResourceBase *apResource) {
|
||||
m_mapHandleResources.erase(apResource->GetHandle());
|
||||
m_mapNameResources.erase(cString::ToLowerCase(apResource->GetName()));
|
||||
|
||||
// Log("Removing %s %d %d!\n", apResource->GetName().c_str(),x,y);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
unsigned long iResourceManager::GetHandle() {
|
||||
return mlHandleCount++;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
} // namespace hpl
|
||||
106
engines/hpl1/engine/resources/ResourceManager.h
Normal file
106
engines/hpl1/engine/resources/ResourceManager.h
Normal file
@@ -0,0 +1,106 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#ifndef HPL_RESOURCEMANAGER_H
|
||||
#define HPL_RESOURCEMANAGER_H
|
||||
|
||||
#include "hpl1/engine/system/SystemTypes.h"
|
||||
#include "common/stablemap.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class LowLevelResources;
|
||||
class LowLevelSystem;
|
||||
class cFileSearcher;
|
||||
class iResourceBase;
|
||||
|
||||
typedef Common::StableMap<unsigned long, iResourceBase *> tResourceHandleMap;
|
||||
typedef tResourceHandleMap::iterator tResourceHandleMapIt;
|
||||
|
||||
typedef Common::StableMap<tString, iResourceBase *> tResourceNameMap;
|
||||
typedef tResourceNameMap::iterator tResourceNameMapIt;
|
||||
|
||||
typedef Common::List<iResourceBase *> tResourceBaseList;
|
||||
typedef tResourceBaseList::iterator tResourceBaseListIt;
|
||||
|
||||
typedef cSTLMapIterator<iResourceBase *, tResourceNameMap, tResourceNameMapIt> cResourceBaseIterator;
|
||||
|
||||
class iResourceManager {
|
||||
public:
|
||||
iResourceManager(cFileSearcher *apFileSearcher, LowLevelResources *apLowLevelResources,
|
||||
LowLevelSystem *apLowLevelSystem);
|
||||
virtual ~iResourceManager() {}
|
||||
|
||||
virtual iResourceBase *Create(const tString &asName) = 0;
|
||||
|
||||
iResourceBase *GetByName(const tString &asName);
|
||||
iResourceBase *GetByHandle(unsigned long alHandle);
|
||||
|
||||
cResourceBaseIterator GetResourceBaseIterator();
|
||||
|
||||
void DestroyUnused(int alMaxToKeep);
|
||||
|
||||
virtual void Destroy(iResourceBase *apResource) = 0;
|
||||
virtual void DestroyAll();
|
||||
|
||||
virtual void Unload(iResourceBase *apResource) = 0;
|
||||
|
||||
virtual void Update(float afTimeStep) {}
|
||||
|
||||
protected:
|
||||
unsigned long mlHandleCount;
|
||||
tResourceNameMap m_mapNameResources;
|
||||
tResourceHandleMap m_mapHandleResources;
|
||||
|
||||
cFileSearcher *mpFileSearcher;
|
||||
LowLevelResources *mpLowLevelResources;
|
||||
LowLevelSystem *mpLowLevelSystem;
|
||||
|
||||
void BeginLoad(const tString &asFile);
|
||||
void EndLoad();
|
||||
|
||||
unsigned long mlTimeStart;
|
||||
|
||||
/**
|
||||
* Checks if a resource alllready is in the manager, else searches the resources.
|
||||
* \param &asName Name of the resource.
|
||||
* \param &asFilePath If the file is not in the manager, the path is put here. "" if there is no such file.
|
||||
* \return A pointer to the resource. NULL if not in manager.
|
||||
*/
|
||||
iResourceBase *FindLoadedResource(const tString &asName, tString &asFilePath);
|
||||
void AddResource(iResourceBase *apResource, bool abLog = true);
|
||||
void RemoveResource(iResourceBase *apResource);
|
||||
|
||||
unsigned long GetHandle();
|
||||
|
||||
tString GetTabs();
|
||||
static int mlTabCount;
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_RESOURCEMANAGER_H
|
||||
356
engines/hpl1/engine/resources/Resources.cpp
Normal file
356
engines/hpl1/engine/resources/Resources.cpp
Normal file
@@ -0,0 +1,356 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#include "hpl1/engine/resources/Resources.h"
|
||||
|
||||
#include "hpl1/engine/resources/AnimationManager.h"
|
||||
#include "hpl1/engine/resources/ConfigFile.h"
|
||||
#include "hpl1/engine/resources/FileSearcher.h"
|
||||
#include "hpl1/engine/resources/FontManager.h"
|
||||
#include "hpl1/engine/resources/GpuProgramManager.h"
|
||||
#include "hpl1/engine/resources/ImageEntityManager.h"
|
||||
#include "hpl1/engine/resources/ImageManager.h"
|
||||
#include "hpl1/engine/resources/LanguageFile.h"
|
||||
#include "hpl1/engine/resources/MaterialManager.h"
|
||||
#include "hpl1/engine/resources/MeshLoaderHandler.h"
|
||||
#include "hpl1/engine/resources/MeshManager.h"
|
||||
#include "hpl1/engine/resources/ParticleManager.h"
|
||||
#include "hpl1/engine/resources/ScriptManager.h"
|
||||
#include "hpl1/engine/resources/SoundEntityManager.h"
|
||||
#include "hpl1/engine/resources/SoundManager.h"
|
||||
#include "hpl1/engine/resources/TextureManager.h"
|
||||
#include "hpl1/engine/resources/TileSetManager.h"
|
||||
#include "hpl1/engine/resources/VideoManager.h"
|
||||
#include "hpl1/engine/resources/low_level_resources.h"
|
||||
#include "hpl1/engine/scene/Area2D.h"
|
||||
#include "hpl1/engine/system/System.h"
|
||||
|
||||
#include "hpl1/engine/system/low_level_system.h"
|
||||
|
||||
#include "hpl1/engine/impl/tinyXML/tinyxml.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cResources::cResources(LowLevelResources *apLowLevelResources, iLowLevelGraphics *apLowLevelGraphics)
|
||||
: iUpdateable("Resources") {
|
||||
mpLowLevelResources = apLowLevelResources;
|
||||
mpLowLevelGraphics = apLowLevelGraphics;
|
||||
|
||||
mpFileSearcher = hplNew(cFileSearcher, (mpLowLevelResources));
|
||||
|
||||
mpDefaultEntity3DLoader = NULL;
|
||||
mpDefaultArea3DLoader = NULL;
|
||||
|
||||
mpLanguageFile = NULL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cResources::~cResources() {
|
||||
Log("Exiting Resources Module\n");
|
||||
Log("--------------------------------------------------------\n");
|
||||
|
||||
STLMapDeleteAll(m_mEntity3DLoaders);
|
||||
STLMapDeleteAll(m_mArea3DLoaders);
|
||||
STLMapDeleteAll(m_mMapEntity2DLoaders);
|
||||
STLMapDeleteAll(m_mMapArea2DLoaders);
|
||||
|
||||
hplDelete(mpTileSetManager);
|
||||
hplDelete(mpFontManager);
|
||||
hplDelete(mpScriptManager);
|
||||
hplDelete(mpParticleManager);
|
||||
hplDelete(mpSoundManager);
|
||||
hplDelete(mpImageEntityManager);
|
||||
hplDelete(mpMeshManager);
|
||||
hplDelete(mpMaterialManager);
|
||||
hplDelete(mpGpuProgramManager);
|
||||
hplDelete(mpImageManager);
|
||||
hplDelete(mpTextureManager);
|
||||
hplDelete(mpSoundEntityManager);
|
||||
hplDelete(mpAnimationManager);
|
||||
hplDelete(mpVideoManager);
|
||||
|
||||
Log(" All resources deleted\n");
|
||||
|
||||
hplDelete(mpFileSearcher);
|
||||
hplDelete(mpMeshLoaderHandler);
|
||||
|
||||
if (mpLanguageFile)
|
||||
hplDelete(mpLanguageFile);
|
||||
|
||||
mlstManagers.clear();
|
||||
Log("--------------------------------------------------------\n\n");
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cResources::Init(cGraphics *apGraphics, cSystem *apSystem, cSound *apSound, cScene *apScene,
|
||||
cGui *apGui) {
|
||||
Log("Initializing Resources Module\n");
|
||||
Log("--------------------------------------------------------\n");
|
||||
|
||||
mpLowLevelSystem = apSystem->GetLowLevel();
|
||||
|
||||
Log(" Creating resource managers\n");
|
||||
|
||||
mpImageManager = hplNew(cImageManager, (mpFileSearcher, mpLowLevelGraphics, mpLowLevelResources, mpLowLevelSystem));
|
||||
mlstManagers.push_back(mpImageManager);
|
||||
mpGpuProgramManager = hplNew(cGpuProgramManager, (mpFileSearcher, mpLowLevelGraphics, mpLowLevelResources, mpLowLevelSystem));
|
||||
mlstManagers.push_back(mpGpuProgramManager);
|
||||
mpTileSetManager = hplNew(cTileSetManager, (apGraphics, this));
|
||||
mlstManagers.push_back(mpTileSetManager);
|
||||
mpImageEntityManager = hplNew(cImageEntityManager, (apGraphics, this));
|
||||
mlstManagers.push_back(mpImageEntityManager);
|
||||
mpParticleManager = hplNew(cParticleManager, (apGraphics, this));
|
||||
mlstManagers.push_back(mpParticleManager);
|
||||
mpSoundManager = hplNew(cSoundManager, (apSound, this));
|
||||
mlstManagers.push_back(mpParticleManager);
|
||||
mpFontManager = hplNew(cFontManager, (apGraphics, apGui, this));
|
||||
mlstManagers.push_back(mpFontManager);
|
||||
mpScriptManager = hplNew(cScriptManager, (apSystem, this));
|
||||
mlstManagers.push_back(mpScriptManager);
|
||||
mpTextureManager = hplNew(cTextureManager, (apGraphics, this));
|
||||
mlstManagers.push_back(mpTextureManager);
|
||||
mpMaterialManager = hplNew(cMaterialManager, (apGraphics, this));
|
||||
mlstManagers.push_back(mpMaterialManager);
|
||||
mpMeshManager = hplNew(cMeshManager, (apGraphics, this));
|
||||
mlstManagers.push_back(mpMeshManager);
|
||||
mpSoundEntityManager = hplNew(cSoundEntityManager, (apSound, this));
|
||||
mlstManagers.push_back(mpSoundEntityManager);
|
||||
mpAnimationManager = hplNew(cAnimationManager, (apGraphics, this));
|
||||
mlstManagers.push_back(mpAnimationManager);
|
||||
mpVideoManager = hplNew(cVideoManager, (apGraphics, this));
|
||||
mlstManagers.push_back(mpVideoManager);
|
||||
|
||||
Log(" Misc Creation\n");
|
||||
|
||||
mpMeshLoaderHandler = hplNew(cMeshLoaderHandler, (this, apScene));
|
||||
|
||||
mpLowLevelResources->addMeshLoaders(mpMeshLoaderHandler);
|
||||
mpLowLevelResources->addVideoLoaders(mpVideoManager);
|
||||
|
||||
Log("--------------------------------------------------------\n\n");
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cResources::Update(float afTimeStep) {
|
||||
tResourceManagerListIt it = mlstManagers.begin();
|
||||
for (; it != mlstManagers.end(); ++it) {
|
||||
iResourceManager *pManager = *it;
|
||||
|
||||
pManager->Update(afTimeStep);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cFileSearcher *cResources::GetFileSearcher() {
|
||||
return mpFileSearcher;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* \todo File searcher should check so if the dir is already added and if so return false and not add
|
||||
* \param &asDir
|
||||
* \param &asMask
|
||||
* \return
|
||||
*/
|
||||
bool cResources::AddResourceDir(const tString &asDir, const tString &asMask) {
|
||||
mpFileSearcher->AddDirectory(asDir, asMask);
|
||||
if (iResourceBase::GetLogCreateAndDelete())
|
||||
Log(" Added resource directory '%s'\n", asDir.c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
void cResources::ClearResourceDirs() {
|
||||
mpFileSearcher->ClearDirectories();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cResources::SetLanguageFile(const tString &asFile) {
|
||||
if (mpLanguageFile) {
|
||||
hplDelete(mpLanguageFile);
|
||||
mpLanguageFile = NULL;
|
||||
}
|
||||
|
||||
tString asPath = mpFileSearcher->GetFilePath(asFile);
|
||||
if (asPath == "") {
|
||||
Error("Couldn't load language file '%s'\n", asFile.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
mpLanguageFile = hplNew(cLanguageFile, (this));
|
||||
|
||||
return mpLanguageFile->LoadFromFile(asPath);
|
||||
}
|
||||
|
||||
const tWString &cResources::Translate(const tString &asCat, const tString &asName) {
|
||||
if (mpLanguageFile) {
|
||||
return mpLanguageFile->Translate(asCat, asName);
|
||||
} else {
|
||||
return mwsEmptyString;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cResources::AddEntity2DLoader(iEntity2DLoader *apLoader) {
|
||||
m_mMapEntity2DLoaders.insert(tEntity2DLoaderMap::value_type(apLoader->GetName(), apLoader));
|
||||
}
|
||||
|
||||
iEntity2DLoader *cResources::GetEntity2DLoader(const tString &asName) {
|
||||
tEntity2DLoaderMapIt it = m_mMapEntity2DLoaders.find(asName);
|
||||
if (it == m_mMapEntity2DLoaders.end()) {
|
||||
Warning("No loader for type '%s' found!\n", asName.c_str());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return it->second;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cResources::AddArea2DLoader(iArea2DLoader *apLoader) {
|
||||
m_mMapArea2DLoaders.insert(tArea2DLoaderMap::value_type(apLoader->GetName(), apLoader));
|
||||
}
|
||||
|
||||
iArea2DLoader *cResources::GetArea2DLoader(const tString &asName) {
|
||||
tArea2DLoaderMapIt it = m_mMapArea2DLoaders.find(asName);
|
||||
if (it == m_mMapArea2DLoaders.end()) {
|
||||
Warning("No loader for type '%s' found!\n", asName.c_str());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return it->second;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cResources::AddEntity3DLoader(iEntity3DLoader *apLoader, bool abSetAsDefault) {
|
||||
m_mEntity3DLoaders.insert(tEntity3DLoaderMap::value_type(apLoader->GetName(), apLoader));
|
||||
|
||||
if (abSetAsDefault) {
|
||||
mpDefaultEntity3DLoader = apLoader;
|
||||
}
|
||||
}
|
||||
|
||||
iEntity3DLoader *cResources::GetEntity3DLoader(const tString &asName) {
|
||||
tEntity3DLoaderMapIt it = m_mEntity3DLoaders.find(asName);
|
||||
if (it == m_mEntity3DLoaders.end()) {
|
||||
Warning("No loader for type '%s' found!\n", asName.c_str());
|
||||
|
||||
if (mpDefaultEntity3DLoader) {
|
||||
Log("Using default loader!\n");
|
||||
return mpDefaultEntity3DLoader;
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return it->second;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cResources::AddArea3DLoader(iArea3DLoader *apLoader, bool abSetAsDefault) {
|
||||
m_mArea3DLoaders.insert(tArea3DLoaderMap::value_type(apLoader->GetName(), apLoader));
|
||||
|
||||
if (abSetAsDefault) {
|
||||
mpDefaultArea3DLoader = apLoader;
|
||||
}
|
||||
}
|
||||
|
||||
iArea3DLoader *cResources::GetArea3DLoader(const tString &asName) {
|
||||
tArea3DLoaderMapIt it = m_mArea3DLoaders.find(asName);
|
||||
if (it == m_mArea3DLoaders.end()) {
|
||||
Warning("No loader for area type '%s' found!\n", asName.c_str());
|
||||
|
||||
if (mpDefaultArea3DLoader) {
|
||||
Log("Using default loader!\n");
|
||||
return mpDefaultArea3DLoader;
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return it->second;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
LowLevelResources *cResources::GetLowLevel() {
|
||||
return mpLowLevelResources;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
} // namespace hpl
|
||||
250
engines/hpl1/engine/resources/Resources.h
Normal file
250
engines/hpl1/engine/resources/Resources.h
Normal file
@@ -0,0 +1,250 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#ifndef HPL_RESOURCES_H
|
||||
#define HPL_RESOURCES_H
|
||||
|
||||
#include "hpl1/engine/system/SystemTypes.h"
|
||||
#include "common/stablemap.h"
|
||||
|
||||
#include "hpl1/engine/graphics/GPUProgram.h"
|
||||
|
||||
#include "hpl1/engine/game/Updateable.h"
|
||||
|
||||
class TiXmlElement;
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class cImageEntity;
|
||||
|
||||
class LowLevelResources;
|
||||
class iLowLevelGraphics;
|
||||
class LowLevelSystem;
|
||||
class cSystem;
|
||||
class iResourceManager;
|
||||
class cFileSearcher;
|
||||
class cImageManager;
|
||||
class cGpuProgramManager;
|
||||
class cTileSetManager;
|
||||
class cImageEntityManager;
|
||||
class cParticleManager;
|
||||
class cSoundManager;
|
||||
class cFontManager;
|
||||
class cScriptManager;
|
||||
class cTextureManager;
|
||||
class cMaterialManager;
|
||||
class cSoundEntityManager;
|
||||
class cAnimationManager;
|
||||
class cMeshManager;
|
||||
class cVideoManager;
|
||||
class cConfigFile;
|
||||
class cArea2D;
|
||||
class cSound;
|
||||
class cMeshLoaderHandler;
|
||||
class cScene;
|
||||
class cGraphics;
|
||||
class iRenderable;
|
||||
class cWorld3D;
|
||||
class iEntity3D;
|
||||
class cLanguageFile;
|
||||
class cGui;
|
||||
|
||||
//-------------------------------------------------------
|
||||
|
||||
class iEntity2DLoader {
|
||||
public:
|
||||
iEntity2DLoader(const tString &asName) : msName(asName) {}
|
||||
virtual ~iEntity2DLoader() {}
|
||||
|
||||
const tString &GetName() { return msName; }
|
||||
|
||||
virtual void Load(cImageEntity *apImageEntity) = 0;
|
||||
|
||||
protected:
|
||||
tString msName;
|
||||
};
|
||||
|
||||
typedef Common::StableMap<tString, iEntity2DLoader *> tEntity2DLoaderMap;
|
||||
typedef tEntity2DLoaderMap::iterator tEntity2DLoaderMapIt;
|
||||
|
||||
//-------------------------------------------------------
|
||||
|
||||
class iArea2DLoader {
|
||||
public:
|
||||
iArea2DLoader(const tString &asName) : msName(asName) {}
|
||||
virtual ~iArea2DLoader() {}
|
||||
|
||||
const tString &GetName() { return msName; }
|
||||
|
||||
virtual void Load(cArea2D *apArea) = 0;
|
||||
|
||||
protected:
|
||||
tString msName;
|
||||
};
|
||||
|
||||
typedef Common::StableMap<tString, iArea2DLoader *> tArea2DLoaderMap;
|
||||
typedef tArea2DLoaderMap::iterator tArea2DLoaderMapIt;
|
||||
|
||||
//-------------------------------------------------------
|
||||
|
||||
class iEntity3DLoader {
|
||||
public:
|
||||
iEntity3DLoader(const tString &asName) : msName(asName) {}
|
||||
virtual ~iEntity3DLoader() {}
|
||||
|
||||
const tString &GetName() { return msName; }
|
||||
|
||||
virtual iEntity3D *Load(const tString &asName, TiXmlElement *apRootElem, const cMatrixf &a_mtxTransform,
|
||||
cWorld3D *apWorld, const tString &asFileName, bool abLoadReferences) = 0;
|
||||
|
||||
protected:
|
||||
tString msName;
|
||||
};
|
||||
|
||||
typedef Common::StableMap<tString, iEntity3DLoader *> tEntity3DLoaderMap;
|
||||
typedef tEntity3DLoaderMap::iterator tEntity3DLoaderMapIt;
|
||||
|
||||
//-------------------------------------------------------
|
||||
|
||||
class iArea3DLoader {
|
||||
public:
|
||||
iArea3DLoader(const tString &asName) : msName(asName) {}
|
||||
virtual ~iArea3DLoader() {}
|
||||
|
||||
const tString &GetName() { return msName; }
|
||||
|
||||
virtual iEntity3D *Load(const tString &asName, const cVector3f &avSize, const cMatrixf &a_mtxTransform, cWorld3D *apWorld) = 0;
|
||||
|
||||
protected:
|
||||
tString msName;
|
||||
};
|
||||
|
||||
typedef Common::StableMap<tString, iArea3DLoader *> tArea3DLoaderMap;
|
||||
typedef tArea3DLoaderMap::iterator tArea3DLoaderMapIt;
|
||||
|
||||
//-------------------------------------------------------
|
||||
|
||||
// Should this be made a map so you can do
|
||||
// GetManager(tString) when getting a manager?
|
||||
// This way you would be able to add your own resource types
|
||||
// easily.
|
||||
typedef Common::List<iResourceManager *> tResourceManagerList;
|
||||
typedef tResourceManagerList::iterator tResourceManagerListIt;
|
||||
|
||||
//-------------------------------------------------------
|
||||
|
||||
class cResources : public iUpdateable {
|
||||
public:
|
||||
cResources(LowLevelResources *apLowLevelResources, iLowLevelGraphics *apLowLevelGraphics);
|
||||
virtual ~cResources();
|
||||
|
||||
void Init(cGraphics *apGraphics, cSystem *apSystem, cSound *apSound, cScene *apScene, cGui *apGui);
|
||||
|
||||
void Update(float afTimeStep);
|
||||
|
||||
LowLevelResources *GetLowLevel();
|
||||
cFileSearcher *GetFileSearcher();
|
||||
|
||||
bool AddResourceDir(const tString &asDir, const tString &asMask = "*.*");
|
||||
void ClearResourceDirs();
|
||||
|
||||
bool SetLanguageFile(const tString &asFile);
|
||||
const tWString &Translate(const tString &asCat, const tString &asName);
|
||||
|
||||
void AddEntity2DLoader(iEntity2DLoader *apLoader);
|
||||
iEntity2DLoader *GetEntity2DLoader(const tString &asName);
|
||||
|
||||
void AddEntity3DLoader(iEntity3DLoader *apLoader, bool abSetAsDefault = false);
|
||||
iEntity3DLoader *GetEntity3DLoader(const tString &asName);
|
||||
|
||||
void AddArea3DLoader(iArea3DLoader *apLoader, bool abSetAsDefault = false);
|
||||
iArea3DLoader *GetArea3DLoader(const tString &asName);
|
||||
|
||||
void AddArea2DLoader(iArea2DLoader *apLoader);
|
||||
iArea2DLoader *GetArea2DLoader(const tString &asName);
|
||||
|
||||
bool LoadResourceDirsFile(const tString &asFile);
|
||||
|
||||
cImageManager *GetImageManager() { return mpImageManager; }
|
||||
cGpuProgramManager *GetGpuProgramManager() { return mpGpuProgramManager; }
|
||||
cTileSetManager *GetTileSetManager() { return mpTileSetManager; }
|
||||
cImageEntityManager *GetImageEntityManager() { return mpImageEntityManager; }
|
||||
cParticleManager *GetParticleManager() { return mpParticleManager; }
|
||||
cSoundManager *GetSoundManager() { return mpSoundManager; }
|
||||
cFontManager *GetFontManager() { return mpFontManager; }
|
||||
cScriptManager *GetScriptManager() { return mpScriptManager; }
|
||||
cTextureManager *GetTextureManager() { return mpTextureManager; }
|
||||
cMaterialManager *GetMaterialManager() { return mpMaterialManager; }
|
||||
cMeshManager *GetMeshManager() { return mpMeshManager; }
|
||||
cMeshLoaderHandler *GetMeshLoaderHandler() { return mpMeshLoaderHandler; }
|
||||
cSoundEntityManager *GetSoundEntityManager() { return mpSoundEntityManager; }
|
||||
cAnimationManager *GetAnimationManager() { return mpAnimationManager; }
|
||||
cVideoManager *GetVideoManager() { return mpVideoManager; }
|
||||
|
||||
LowLevelSystem *GetLowLevelSystem() { return mpLowLevelSystem; }
|
||||
|
||||
private:
|
||||
LowLevelResources *mpLowLevelResources;
|
||||
iLowLevelGraphics *mpLowLevelGraphics;
|
||||
LowLevelSystem *mpLowLevelSystem;
|
||||
cFileSearcher *mpFileSearcher;
|
||||
|
||||
tResourceManagerList mlstManagers;
|
||||
cImageManager *mpImageManager;
|
||||
cGpuProgramManager *mpGpuProgramManager;
|
||||
cTileSetManager *mpTileSetManager;
|
||||
cImageEntityManager *mpImageEntityManager;
|
||||
cParticleManager *mpParticleManager;
|
||||
cSoundManager *mpSoundManager;
|
||||
cFontManager *mpFontManager;
|
||||
cScriptManager *mpScriptManager;
|
||||
cTextureManager *mpTextureManager;
|
||||
cMaterialManager *mpMaterialManager;
|
||||
cSoundEntityManager *mpSoundEntityManager;
|
||||
cAnimationManager *mpAnimationManager;
|
||||
cVideoManager *mpVideoManager;
|
||||
|
||||
cLanguageFile *mpLanguageFile;
|
||||
|
||||
cMeshManager *mpMeshManager;
|
||||
cMeshLoaderHandler *mpMeshLoaderHandler;
|
||||
|
||||
tEntity2DLoaderMap m_mMapEntity2DLoaders;
|
||||
tArea2DLoaderMap m_mMapArea2DLoaders;
|
||||
|
||||
tEntity3DLoaderMap m_mEntity3DLoaders;
|
||||
iEntity3DLoader *mpDefaultEntity3DLoader;
|
||||
|
||||
tArea3DLoaderMap m_mArea3DLoaders;
|
||||
iArea3DLoader *mpDefaultArea3DLoader;
|
||||
|
||||
tWString mwsEmptyString;
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_RESOURCES_H
|
||||
38
engines/hpl1/engine/resources/ResourcesTypes.h
Normal file
38
engines/hpl1/engine/resources/ResourcesTypes.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#ifndef HPL_RESOURCES_TYPES_H
|
||||
#define HPL_RESOURCES_TYPES_H
|
||||
|
||||
namespace hpl {
|
||||
|
||||
// change to own file type?
|
||||
// typedef FILE tFile;
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_RESOURCES_TYPES_H
|
||||
127
engines/hpl1/engine/resources/ScriptManager.cpp
Normal file
127
engines/hpl1/engine/resources/ScriptManager.cpp
Normal file
@@ -0,0 +1,127 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#include "hpl1/engine/resources/ScriptManager.h"
|
||||
#include "hpl1/engine/resources/Resources.h"
|
||||
#include "hpl1/engine/system/Script.h"
|
||||
#include "hpl1/engine/system/String.h"
|
||||
#include "hpl1/engine/system/System.h"
|
||||
#include "hpl1/engine/system/low_level_system.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cScriptManager::cScriptManager(cSystem *apSystem, cResources *apResources)
|
||||
: iResourceManager(apResources->GetFileSearcher(), apResources->GetLowLevel(),
|
||||
apResources->GetLowLevelSystem()) {
|
||||
mpSystem = apSystem;
|
||||
mpResources = apResources;
|
||||
}
|
||||
|
||||
cScriptManager::~cScriptManager() {
|
||||
DestroyAll();
|
||||
Log(" Done with scripts\n");
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iScript *cScriptManager::CreateScript(const tString &asName) {
|
||||
tString sPath;
|
||||
iScript *pScript;
|
||||
tString asNewName;
|
||||
|
||||
BeginLoad(asName);
|
||||
|
||||
asNewName = cString::SetFileExt(asName, "hps");
|
||||
|
||||
pScript = static_cast<iScript *>(this->FindLoadedResource(asNewName, sPath));
|
||||
|
||||
if (pScript == NULL && sPath != "") {
|
||||
pScript = mpSystem->GetLowLevel()->createScript(asNewName);
|
||||
|
||||
if (pScript->CreateFromFile(sPath) == false) {
|
||||
hplDelete(pScript);
|
||||
EndLoad();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
AddResource(pScript);
|
||||
}
|
||||
|
||||
if (pScript)
|
||||
pScript->IncUserCount();
|
||||
else
|
||||
Error("Couldn't create script '%s'\n", asNewName.c_str());
|
||||
|
||||
EndLoad();
|
||||
return pScript;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iResourceBase *cScriptManager::Create(const tString &asName) {
|
||||
return CreateScript(asName);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cScriptManager::Unload(iResourceBase *apResource) {
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cScriptManager::Destroy(iResourceBase *apResource) {
|
||||
apResource->DecUserCount();
|
||||
|
||||
if (apResource->HasUsers() == false) {
|
||||
RemoveResource(apResource);
|
||||
hplDelete(apResource);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PRIVATE METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
} // namespace hpl
|
||||
62
engines/hpl1/engine/resources/ScriptManager.h
Normal file
62
engines/hpl1/engine/resources/ScriptManager.h
Normal file
@@ -0,0 +1,62 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#ifndef HPL_SCRIPT_MANAGER_H
|
||||
#define HPL_SCRIPT_MANAGER_H
|
||||
|
||||
#include "hpl1/engine/resources/ResourceManager.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class cSystem;
|
||||
class cResources;
|
||||
class iScript;
|
||||
|
||||
class cScriptManager : public iResourceManager {
|
||||
public:
|
||||
cScriptManager(cSystem *apSystem, cResources *apResources);
|
||||
~cScriptManager();
|
||||
|
||||
iResourceBase *Create(const tString &asName);
|
||||
/**
|
||||
* Create a new script.
|
||||
* \param asName name of the script.
|
||||
* \return
|
||||
*/
|
||||
iScript *CreateScript(const tString &asName);
|
||||
|
||||
void Destroy(iResourceBase *apResource);
|
||||
void Unload(iResourceBase *apResource);
|
||||
|
||||
private:
|
||||
cSystem *mpSystem;
|
||||
cResources *mpResources;
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_SCRIPT_MANAGER_H
|
||||
146
engines/hpl1/engine/resources/SoundEntityManager.cpp
Normal file
146
engines/hpl1/engine/resources/SoundEntityManager.cpp
Normal file
@@ -0,0 +1,146 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#include "hpl1/engine/resources/SoundEntityManager.h"
|
||||
|
||||
#include "hpl1/engine/resources/Resources.h"
|
||||
#include "hpl1/engine/sound/Sound.h"
|
||||
#include "hpl1/engine/sound/SoundChannel.h"
|
||||
#include "hpl1/engine/sound/SoundEntityData.h"
|
||||
#include "hpl1/engine/sound/SoundHandler.h"
|
||||
#include "hpl1/engine/system/String.h"
|
||||
#include "hpl1/engine/system/low_level_system.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cSoundEntityManager::cSoundEntityManager(cSound *apSound, cResources *apResources)
|
||||
: iResourceManager(apResources->GetFileSearcher(), apResources->GetLowLevel(),
|
||||
apResources->GetLowLevelSystem()) {
|
||||
mpSound = apSound;
|
||||
mpResources = apResources;
|
||||
}
|
||||
|
||||
cSoundEntityManager::~cSoundEntityManager() {
|
||||
DestroyAll();
|
||||
|
||||
Log(" Done with sound entities\n");
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cSoundEntityManager::Preload(const tString &asFile) {
|
||||
cSoundEntityData *pData = CreateSoundEntity(asFile);
|
||||
if (pData == NULL) {
|
||||
Warning("Couldn't preload sound '%s'\n", asFile.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
if (pData->GetMainSoundName() != "") {
|
||||
iSoundChannel *pChannel = mpSound->GetSoundHandler()->CreateChannel(pData->GetMainSoundName(), 0);
|
||||
if (pChannel)
|
||||
hplDelete(pChannel);
|
||||
}
|
||||
if (pData->GetStartSoundName() != "") {
|
||||
iSoundChannel *pChannel = mpSound->GetSoundHandler()->CreateChannel(pData->GetStartSoundName(), 0);
|
||||
if (pChannel)
|
||||
hplDelete(pChannel);
|
||||
}
|
||||
if (pData->GetStopSoundName() != "") {
|
||||
iSoundChannel *pChannel = mpSound->GetSoundHandler()->CreateChannel(pData->GetStopSoundName(), 0);
|
||||
if (pChannel)
|
||||
hplDelete(pChannel);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iResourceBase *cSoundEntityManager::Create(const tString &asName) {
|
||||
return CreateSoundEntity(asName);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cSoundEntityManager::Unload(iResourceBase *apResource) {
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cSoundEntityManager::Destroy(iResourceBase *apResource) {
|
||||
apResource->DecUserCount();
|
||||
|
||||
if (apResource->HasUsers() == false) {
|
||||
RemoveResource(apResource);
|
||||
hplDelete(apResource);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
} // namespace hpl
|
||||
59
engines/hpl1/engine/resources/SoundEntityManager.h
Normal file
59
engines/hpl1/engine/resources/SoundEntityManager.h
Normal file
@@ -0,0 +1,59 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#ifndef HPL_SOUND_ENTITY_MANAGER_H
|
||||
#define HPL_SOUND_ENTITY_MANAGER_H
|
||||
|
||||
#include "hpl1/engine/resources/ResourceManager.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class cSound;
|
||||
class cResources;
|
||||
class cSoundEntityData;
|
||||
|
||||
class cSoundEntityManager : public iResourceManager {
|
||||
public:
|
||||
cSoundEntityManager(cSound *apSound, cResources *apResources);
|
||||
~cSoundEntityManager();
|
||||
|
||||
void Preload(const tString &asFile);
|
||||
|
||||
iResourceBase *Create(const tString &asName);
|
||||
cSoundEntityData *CreateSoundEntity(const tString &asName);
|
||||
|
||||
void Destroy(iResourceBase *apResource);
|
||||
void Unload(iResourceBase *apResource);
|
||||
|
||||
private:
|
||||
cSound *mpSound;
|
||||
cResources *mpResources;
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_SOUND_ENTITY_MANAGER_H
|
||||
162
engines/hpl1/engine/resources/SoundManager.cpp
Normal file
162
engines/hpl1/engine/resources/SoundManager.cpp
Normal file
@@ -0,0 +1,162 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#include "hpl1/engine/resources/SoundManager.h"
|
||||
#include "hpl1/engine/resources/Resources.h"
|
||||
#include "hpl1/engine/sound/LowLevelSound.h"
|
||||
#include "hpl1/engine/sound/Sound.h"
|
||||
#include "hpl1/engine/sound/SoundData.h"
|
||||
#include "hpl1/engine/system/String.h"
|
||||
#include "hpl1/engine/system/low_level_system.h"
|
||||
|
||||
#include "hpl1/debug.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cSoundManager::cSoundManager(cSound *apSound, cResources *apResources)
|
||||
: iResourceManager(apResources->GetFileSearcher(), apResources->GetLowLevel(),
|
||||
apResources->GetLowLevelSystem()) {
|
||||
mpSound = apSound;
|
||||
mpResources = apResources;
|
||||
|
||||
mpSound->GetLowLevel()->GetSupportedFormats(mlstFileFormats);
|
||||
}
|
||||
|
||||
cSoundManager::~cSoundManager() {
|
||||
DestroyAll();
|
||||
Log(" Done with sounds\n");
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iSoundData *cSoundManager::CreateSoundData(const tString &asName, bool abStream, bool abLoopStream) {
|
||||
tString sPath;
|
||||
iSoundData *pSound = NULL;
|
||||
|
||||
BeginLoad(asName);
|
||||
|
||||
pSound = FindData(asName, sPath);
|
||||
|
||||
if (pSound == NULL && sPath != "") {
|
||||
pSound = mpSound->GetLowLevel()->LoadSoundData(cString::GetFileName(sPath), sPath, "", abStream,
|
||||
abLoopStream);
|
||||
if (pSound) {
|
||||
AddResource(pSound);
|
||||
pSound->SetSoundManager(mpResources->GetSoundManager());
|
||||
} else {
|
||||
Hpl1::logError(Hpl1::kDebugAudio, "sound data %s could not be loaded\n", asName.c_str());
|
||||
}
|
||||
|
||||
} else {
|
||||
}
|
||||
|
||||
// if(!pSound) Error("Couldn't load sound data '%s'\n",asName.c_str());
|
||||
EndLoad();
|
||||
return pSound;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iResourceBase *cSoundManager::Create(const tString &asName) {
|
||||
return CreateSoundData(asName, false);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cSoundManager::Unload(iResourceBase *apResource) {
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cSoundManager::Destroy(iResourceBase *apResource) {
|
||||
// Log("Destroying %s users: %d\n",apResource->GetName().c_str(),
|
||||
// apResource->GetUserCount());
|
||||
if (apResource->HasUsers()) {
|
||||
apResource->DecUserCount();
|
||||
|
||||
iSoundData *pData = static_cast<iSoundData *>(apResource);
|
||||
if (pData->IsStream() && pData->HasUsers() == false) {
|
||||
RemoveResource(pData);
|
||||
hplDelete(pData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cSoundManager::DestroyAll() {
|
||||
// FIX FIX FIX
|
||||
// Fix what? :P
|
||||
tResourceHandleMapIt it = m_mapHandleResources.begin();
|
||||
while (it != m_mapHandleResources.end()) {
|
||||
iResourceBase *pData = it->second;
|
||||
RemoveResource(pData);
|
||||
hplDelete(pData);
|
||||
|
||||
it = m_mapHandleResources.begin();
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PRIVATE METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iSoundData *cSoundManager::FindData(const tString &asName, tString &asFilePath) {
|
||||
iSoundData *pData = NULL;
|
||||
|
||||
if (cString::GetFileExt(asName) == "") {
|
||||
for (tStringListIt it = mlstFileFormats.begin(); it != mlstFileFormats.end(); ++it) {
|
||||
tString sNewName = cString::SetFileExt(asName, *it);
|
||||
pData = static_cast<iSoundData *>(FindLoadedResource(sNewName, asFilePath));
|
||||
|
||||
if ((pData == NULL && asFilePath != "") || pData != NULL)
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
pData = static_cast<iSoundData *>(FindLoadedResource(asName, asFilePath));
|
||||
}
|
||||
|
||||
return pData;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
} // namespace hpl
|
||||
63
engines/hpl1/engine/resources/SoundManager.h
Normal file
63
engines/hpl1/engine/resources/SoundManager.h
Normal file
@@ -0,0 +1,63 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#ifndef HPL_SOUND_MANAGER_H
|
||||
#define HPL_SOUND_MANAGER_H
|
||||
|
||||
#include "hpl1/engine/resources/ResourceManager.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class cSound;
|
||||
class cResources;
|
||||
class iSoundData;
|
||||
|
||||
class cSoundManager : public iResourceManager {
|
||||
public:
|
||||
cSoundManager(cSound *apSound, cResources *apResources);
|
||||
~cSoundManager();
|
||||
|
||||
iResourceBase *Create(const tString &asName);
|
||||
iSoundData *CreateSoundData(const tString &asName, bool abStream, bool abLoopStream = false);
|
||||
|
||||
void Destroy(iResourceBase *apResource);
|
||||
void Unload(iResourceBase *apResource);
|
||||
|
||||
void DestroyAll();
|
||||
|
||||
private:
|
||||
cSound *mpSound;
|
||||
cResources *mpResources;
|
||||
|
||||
tStringList mlstFileFormats;
|
||||
|
||||
iSoundData *FindData(const tString &asName, tString &asFilePath);
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_SOUND_MANAGER_H
|
||||
442
engines/hpl1/engine/resources/TextureManager.cpp
Normal file
442
engines/hpl1/engine/resources/TextureManager.cpp
Normal file
@@ -0,0 +1,442 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#include "hpl1/engine/resources/TextureManager.h"
|
||||
#include "hpl1/debug.h"
|
||||
#include "hpl1/engine/graphics/Graphics.h"
|
||||
#include "hpl1/engine/graphics/LowLevelGraphics.h"
|
||||
#include "hpl1/engine/graphics/Texture.h"
|
||||
#include "hpl1/engine/graphics/bitmap2D.h"
|
||||
#include "hpl1/engine/resources/FileSearcher.h"
|
||||
#include "hpl1/engine/resources/Resources.h"
|
||||
#include "hpl1/engine/resources/low_level_resources.h"
|
||||
#include "hpl1/engine/system/String.h"
|
||||
#include "hpl1/engine/system/low_level_system.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cTextureManager::cTextureManager(cGraphics *apGraphics, cResources *apResources)
|
||||
: iResourceManager(apResources->GetFileSearcher(), apResources->GetLowLevel(),
|
||||
apResources->GetLowLevelSystem()) {
|
||||
mpGraphics = apGraphics;
|
||||
mpResources = apResources;
|
||||
|
||||
mpLowLevelResources->getSupportedImageFormats(mlstFileFormats);
|
||||
|
||||
mvCubeSideSuffixes.push_back("_pos_x");
|
||||
mvCubeSideSuffixes.push_back("_neg_x");
|
||||
mvCubeSideSuffixes.push_back("_pos_y");
|
||||
mvCubeSideSuffixes.push_back("_neg_y");
|
||||
mvCubeSideSuffixes.push_back("_pos_z");
|
||||
mvCubeSideSuffixes.push_back("_neg_z");
|
||||
}
|
||||
|
||||
cTextureManager::~cTextureManager() {
|
||||
STLMapDeleteAll(m_mapAttenuationTextures);
|
||||
DestroyAll();
|
||||
Log(" Destroyed all textures\n");
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iTexture *cTextureManager::Create1D(const tString &asName, bool abUseMipMaps, bool abCompress,
|
||||
eTextureType aType, unsigned int alTextureSizeLevel) {
|
||||
return CreateFlatTexture(asName, abUseMipMaps, abCompress, aType, eTextureTarget_1D, alTextureSizeLevel);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iTexture *cTextureManager::Create2D(const tString &asName, bool abUseMipMaps, bool abCompress,
|
||||
eTextureType aType, unsigned int alTextureSizeLevel, eTextureTarget aTarget) {
|
||||
return CreateFlatTexture(asName, abUseMipMaps, abCompress, aType, aTarget, alTextureSizeLevel);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iTexture *cTextureManager::CreateAnim2D(const tString &asName, bool abUseMipMaps, bool abCompress,
|
||||
eTextureType aType, unsigned int alTextureSizeLevel) {
|
||||
BeginLoad(asName);
|
||||
|
||||
iTexture *pTexture = static_cast<iTexture *>(GetByName(asName));
|
||||
|
||||
if (pTexture == NULL) {
|
||||
tString sFileExt = cString::GetFileExt(asName);
|
||||
tString sFileName = cString::SetFileExt(cString::GetFileName(asName), "");
|
||||
|
||||
tStringVec mvFileNames;
|
||||
|
||||
tString sTest = sFileName + "01." + sFileExt;
|
||||
int lNum = 2;
|
||||
tStringVec vPaths;
|
||||
|
||||
while (true) {
|
||||
tString sPath = mpFileSearcher->GetFilePath(sTest);
|
||||
|
||||
if (sPath == "") {
|
||||
break;
|
||||
} else {
|
||||
vPaths.push_back(sPath);
|
||||
if (lNum < 10)
|
||||
sTest = sFileName + "0" + cString::ToString(lNum) + "." + sFileExt;
|
||||
else
|
||||
sTest = sFileName + cString::ToString(lNum) + "." + sFileExt;
|
||||
|
||||
++lNum;
|
||||
}
|
||||
}
|
||||
|
||||
if (vPaths.empty()) {
|
||||
Error("No textures found for animation %s\n", asName.c_str());
|
||||
Error("Couldn't texture '%s'\n", asName.c_str());
|
||||
EndLoad();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
tBitmap2DVec vBitmaps;
|
||||
for (size_t i = 0; i < vPaths.size(); ++i) {
|
||||
Bitmap2D *pBmp = mpResources->GetLowLevel()->loadBitmap2D(vPaths[i]);
|
||||
if (pBmp == NULL) {
|
||||
Error("Couldn't load bitmap '%s'!\n", vPaths[i].c_str());
|
||||
|
||||
for (int j = 0; j < (int)vBitmaps.size(); j++)
|
||||
hplDelete(vBitmaps[j]);
|
||||
|
||||
EndLoad();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
vBitmaps.push_back(pBmp);
|
||||
}
|
||||
|
||||
// Create the animated texture
|
||||
pTexture = mpGraphics->GetLowLevel()->CreateTexture(asName, abUseMipMaps, aType,
|
||||
eTextureTarget_2D);
|
||||
|
||||
pTexture->SetSizeLevel(alTextureSizeLevel);
|
||||
|
||||
if (pTexture->CreateAnimFromBitmapVec(&vBitmaps) == false) {
|
||||
Error("Couldn't create animated texture '%s'!\n", asName.c_str());
|
||||
hplDelete(pTexture);
|
||||
for (int j = 0; j < (int)vBitmaps.size(); j++)
|
||||
hplDelete(vBitmaps[j]);
|
||||
EndLoad();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Bitmaps no longer needed.
|
||||
for (int j = 0; j < (int)vBitmaps.size(); j++)
|
||||
hplDelete(vBitmaps[j]);
|
||||
|
||||
AddResource(pTexture);
|
||||
}
|
||||
|
||||
if (pTexture)
|
||||
pTexture->IncUserCount();
|
||||
else
|
||||
Error("Couldn't texture '%s'\n", asName.c_str());
|
||||
|
||||
EndLoad();
|
||||
return pTexture;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iTexture *cTextureManager::CreateCubeMap(const tString &asPathName, bool abUseMipMaps,
|
||||
bool abCompress, eTextureType aType,
|
||||
unsigned int alTextureSizeLevel) {
|
||||
tString sName = cString::SetFileExt(asPathName, "");
|
||||
|
||||
iTexture *pTexture = static_cast<iTexture *>(GetByName(sName));
|
||||
|
||||
BeginLoad(asPathName);
|
||||
|
||||
if (pTexture == NULL) {
|
||||
// See if files for all faces exist
|
||||
tStringVec vPaths;
|
||||
tString sPath = "";
|
||||
for (int i = 0; i < 6; i++) {
|
||||
for (tStringListIt it = mlstFileFormats.begin(); it != mlstFileFormats.end(); ++it) {
|
||||
tString sNewName = sName + mvCubeSideSuffixes[i] + "." + *it;
|
||||
sPath = mpFileSearcher->GetFilePath(sNewName);
|
||||
|
||||
if (sPath != "")
|
||||
break;
|
||||
}
|
||||
|
||||
if (sPath == "") {
|
||||
tString sNewName = sName + mvCubeSideSuffixes[i];
|
||||
Error("Couldn't find %d-face '%s', for cubemap '%s'\n", i, sNewName.c_str(), sName.c_str());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
vPaths.push_back(sPath);
|
||||
}
|
||||
|
||||
// Load bitmaps for all faces
|
||||
tBitmap2DVec vBitmaps;
|
||||
for (int i = 0; i < 6; i++) {
|
||||
Bitmap2D *pBmp = mpResources->GetLowLevel()->loadBitmap2D(vPaths[i]);
|
||||
if (pBmp == NULL) {
|
||||
Error("Couldn't load bitmap '%s'!\n", vPaths[i].c_str());
|
||||
for (int j = 0; j < (int)vBitmaps.size(); j++)
|
||||
hplDelete(vBitmaps[j]);
|
||||
EndLoad();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
vBitmaps.push_back(pBmp);
|
||||
}
|
||||
|
||||
// Create the cubemap
|
||||
pTexture = mpGraphics->GetLowLevel()->CreateTexture(sName, abUseMipMaps, aType,
|
||||
eTextureTarget_CubeMap);
|
||||
pTexture->SetSizeLevel(alTextureSizeLevel);
|
||||
|
||||
if (pTexture->CreateCubeFromBitmapVec(&vBitmaps) == false) {
|
||||
Error("Couldn't create cubemap '%s'!\n", sName.c_str());
|
||||
hplDelete(pTexture);
|
||||
for (int j = 0; j < (int)vBitmaps.size(); j++)
|
||||
hplDelete(vBitmaps[j]);
|
||||
EndLoad();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Bitmaps no longer needed.
|
||||
for (int j = 0; j < (int)vBitmaps.size(); j++)
|
||||
hplDelete(vBitmaps[j]);
|
||||
|
||||
AddResource(pTexture);
|
||||
}
|
||||
|
||||
pTexture->IncUserCount();
|
||||
|
||||
EndLoad();
|
||||
return pTexture;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iResourceBase *cTextureManager::Create(const tString &asName) {
|
||||
return Create2D(asName, true);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cTextureManager::Unload(iResourceBase *apResource) {
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cTextureManager::Destroy(iResourceBase *apResource) {
|
||||
apResource->DecUserCount();
|
||||
|
||||
if (apResource->HasUsers() == false) {
|
||||
RemoveResource(apResource);
|
||||
// Log("Deleting1 '%s'-%d\n",apResource->GetName().c_str() ,apResource);
|
||||
// Log("Deleting2 '%s'-%d\n",apResource->GetName().c_str() ,(iTexture*)apResource);
|
||||
// Log("Deleting1 %d\n",apResource);
|
||||
// Log("Deleting2 %d\n",(iTexture*)apResource);
|
||||
hplDelete(apResource);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cTextureManager::Update(float afTimeStep) {
|
||||
tResourceHandleMapIt it = m_mapHandleResources.begin();
|
||||
for (; it != m_mapHandleResources.end(); ++it) {
|
||||
iResourceBase *pBase = it->second;
|
||||
iTexture *pTexture = static_cast<iTexture *>(pBase);
|
||||
|
||||
pTexture->Update(afTimeStep);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iTexture *cTextureManager::CreateAttenuation(const tString &asFallOffName) {
|
||||
tString sName = cString::ToLowerCase(asFallOffName);
|
||||
tTextureAttenuationMapIt it = m_mapAttenuationTextures.find(sName);
|
||||
if (it != m_mapAttenuationTextures.end())
|
||||
return it->second;
|
||||
|
||||
tString sPath = "";
|
||||
|
||||
if (cString::GetFileExt(asFallOffName) != "") {
|
||||
sPath = mpFileSearcher->GetFilePath(asFallOffName);
|
||||
} else {
|
||||
for (tStringListIt it2 = mlstFileFormats.begin(); it2 != mlstFileFormats.end(); ++it2) {
|
||||
tString sFileName = cString::SetFileExt(asFallOffName, *it2);
|
||||
sPath = mpFileSearcher->GetFilePath(sFileName);
|
||||
if (sPath != "")
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (sPath == "") {
|
||||
Log("Couldn't find falloff map file '%s'\n", asFallOffName.c_str());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Bitmap2D *pBmp = mpResources->GetLowLevel()->loadBitmap2D(sPath);
|
||||
if (pBmp == NULL) {
|
||||
Log("Couldn't load bitmap '%s'\n", asFallOffName.c_str());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int lBmpChannels = pBmp->getNumChannels();
|
||||
int lWidth = pBmp->getWidth();
|
||||
const unsigned char *pPixels = static_cast<const unsigned char *>(pBmp->getRawData());
|
||||
|
||||
iTexture *pTexture = mpGraphics->GetLowLevel()->CreateTexture("Attenuation", false, eTextureType_Normal, eTextureTarget_3D);
|
||||
int lSize = 16;
|
||||
int lAttChannels = 2;
|
||||
|
||||
cVector3f vCentre = ((float)lSize) / 2.0f;
|
||||
float fMaxDist = ((float)lSize) / 2.0f; // radius of sphere
|
||||
|
||||
Common::Array<unsigned char> vAttenMap;
|
||||
vAttenMap.resize(lSize * lSize * lSize * lAttChannels);
|
||||
|
||||
// Log("CREATTING ATTENUTAION MAP\n");
|
||||
for (int z = 0; z < lSize; ++z)
|
||||
for (int y = 0; y < lSize; ++y)
|
||||
for (int x = 0; x < lSize; ++x) {
|
||||
cVector3f vPos((float)x, (float)y, (float)z);
|
||||
vPos = vPos - vCentre;
|
||||
|
||||
float fDist = vPos.Length();
|
||||
if (fDist > fMaxDist)
|
||||
fDist = fMaxDist;
|
||||
float fNormDist = fDist / fMaxDist;
|
||||
|
||||
// unsigned char val = 255 - (unsigned char)(fNormDist * 255.0f);
|
||||
int lTexPos = (int)(fNormDist * (float)lWidth);
|
||||
if (lTexPos >= lWidth)
|
||||
lTexPos = lWidth - 1;
|
||||
unsigned char val = pPixels[lTexPos * lBmpChannels];
|
||||
|
||||
for (int i = 0; i < lAttChannels; ++i) {
|
||||
vAttenMap[z * lSize * lSize * lAttChannels + y * lSize * lAttChannels + x * lAttChannels + i] = val;
|
||||
}
|
||||
}
|
||||
|
||||
pTexture->CreateFromArray(&vAttenMap[0], lAttChannels, cVector3l(16, 16, 16));
|
||||
pTexture->SetWrapS(eTextureWrap_ClampToBorder);
|
||||
pTexture->SetWrapT(eTextureWrap_ClampToBorder);
|
||||
pTexture->SetWrapR(eTextureWrap_ClampToBorder);
|
||||
|
||||
hplDelete(pBmp);
|
||||
|
||||
m_mapAttenuationTextures.insert(tTextureAttenuationMap::value_type(sName, pTexture));
|
||||
|
||||
return pTexture;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PRIVATE METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iTexture *cTextureManager::CreateFlatTexture(const tString &asName, bool abUseMipMaps,
|
||||
bool abCompress, eTextureType aType, eTextureTarget aTarget,
|
||||
unsigned int alTextureSizeLevel) {
|
||||
tString sPath;
|
||||
|
||||
BeginLoad(asName);
|
||||
|
||||
Common::ScopedPtr<iTexture> pTexture(FindTexture2D(asName, sPath));
|
||||
|
||||
if (!pTexture && sPath != "") {
|
||||
// Load the bitmaps
|
||||
Common::ScopedPtr<Bitmap2D> bmp(mpLowLevelResources->loadBitmap2D(sPath));
|
||||
if (!bmp) {
|
||||
Hpl1::logError(Hpl1::kDebugResourceLoading, "Texturemanager Couldn't load bitmap '%s'\n", sPath.c_str());
|
||||
EndLoad();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Create the texture and load from bitmap
|
||||
pTexture.reset(mpGraphics->GetLowLevel()->CreateTexture(asName, abUseMipMaps, aType,
|
||||
aTarget));
|
||||
if (!pTexture) {
|
||||
EndLoad();
|
||||
return nullptr;
|
||||
}
|
||||
pTexture->SetSizeLevel(alTextureSizeLevel);
|
||||
if (!pTexture->CreateFromBitmap(bmp.get())) {
|
||||
EndLoad();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
AddResource(pTexture.get());
|
||||
}
|
||||
|
||||
if (pTexture)
|
||||
pTexture->IncUserCount();
|
||||
else
|
||||
Hpl1::logError(Hpl1::kDebugResourceLoading, "texture '%s' is invalid\n", asName.c_str());
|
||||
|
||||
EndLoad();
|
||||
return pTexture.release();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iTexture *cTextureManager::FindTexture2D(const tString &asName, tString &asFilePath) {
|
||||
iTexture *pTexture = NULL;
|
||||
|
||||
if (cString::GetFileExt(asName) == "") {
|
||||
for (tStringListIt it = mlstFileFormats.begin(); it != mlstFileFormats.end(); ++it) {
|
||||
tString sNewName = cString::SetFileExt(asName, *it);
|
||||
pTexture = static_cast<iTexture *>(FindLoadedResource(sNewName, asFilePath));
|
||||
|
||||
if ((pTexture == NULL && asFilePath != "") || pTexture != NULL)
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
pTexture = static_cast<iTexture *>(FindLoadedResource(asName, asFilePath));
|
||||
}
|
||||
|
||||
return pTexture;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
} // namespace hpl
|
||||
100
engines/hpl1/engine/resources/TextureManager.h
Normal file
100
engines/hpl1/engine/resources/TextureManager.h
Normal file
@@ -0,0 +1,100 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#ifndef HPL_TEXTURE_MANAGER_H
|
||||
#define HPL_TEXTURE_MANAGER_H
|
||||
|
||||
#include "hpl1/engine/graphics/Texture.h"
|
||||
#include "hpl1/engine/resources/ResourceManager.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class cGraphics;
|
||||
class cResources;
|
||||
class iTexture;
|
||||
|
||||
//------------------------------------------------------
|
||||
|
||||
typedef Common::StableMap<tString, iTexture *> tTextureAttenuationMap;
|
||||
typedef Common::StableMap<tString, iTexture *>::iterator tTextureAttenuationMapIt;
|
||||
|
||||
//------------------------------------------------------
|
||||
|
||||
class cTextureManager : public iResourceManager {
|
||||
public:
|
||||
cTextureManager(cGraphics *apGraphics, cResources *apResources);
|
||||
~cTextureManager();
|
||||
|
||||
iResourceBase *Create(const tString &asName);
|
||||
iTexture *Create1D(const tString &asName, bool abUseMipMaps, bool abCompress = false, eTextureType aType = eTextureType_Normal,
|
||||
unsigned int alTextureSizeLevel = 0);
|
||||
|
||||
iTexture *Create2D(const tString &asName, bool abUseMipMaps, bool abCompress = false, eTextureType aType = eTextureType_Normal,
|
||||
unsigned int alTextureSizeLevel = 0, eTextureTarget aTarget = eTextureTarget_2D);
|
||||
|
||||
/**
|
||||
* Creates an animated texture. The name must be [name].[ext]. And then the textures in the animtion must
|
||||
* be named [name]01.[ext], [name]02.[ext], etc
|
||||
* \param asName
|
||||
* \param abUseMipMaps
|
||||
* \param abCompress
|
||||
* \param aType
|
||||
* \return
|
||||
*/
|
||||
iTexture *CreateAnim2D(const tString &asName, bool abUseMipMaps, bool abCompress = false, eTextureType aType = eTextureType_Normal,
|
||||
unsigned int alTextureSizeLevel = 0);
|
||||
|
||||
iTexture *CreateCubeMap(const tString &asName, bool abUseMipMaps, bool abCompress = false, eTextureType aType = eTextureType_Normal,
|
||||
unsigned int alTextureSizeLevel = 0);
|
||||
|
||||
iTexture *CreateAttenuation(const tString &asFallOffName);
|
||||
|
||||
void Destroy(iResourceBase *apResource);
|
||||
void Unload(iResourceBase *apResource);
|
||||
|
||||
void Update(float afTimeStep);
|
||||
|
||||
private:
|
||||
iTexture *CreateFlatTexture(const tString &asName, bool abUseMipMaps,
|
||||
bool abCompress, eTextureType aType, eTextureTarget aTarget,
|
||||
unsigned int alTextureSizeLevel);
|
||||
|
||||
iTexture *FindTexture2D(const tString &asName, tString &asFilePath);
|
||||
|
||||
tTextureAttenuationMap m_mapAttenuationTextures;
|
||||
|
||||
tStringList mlstFileFormats;
|
||||
|
||||
tStringVec mvCubeSideSuffixes;
|
||||
|
||||
cGraphics *mpGraphics;
|
||||
cResources *mpResources;
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_TEXTURE_MANAGER_H
|
||||
126
engines/hpl1/engine/resources/TileSetManager.cpp
Normal file
126
engines/hpl1/engine/resources/TileSetManager.cpp
Normal file
@@ -0,0 +1,126 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#include "hpl1/engine/resources/TileSetManager.h"
|
||||
#include "hpl1/engine/graphics/Graphics.h"
|
||||
#include "hpl1/engine/resources/Resources.h"
|
||||
#include "hpl1/engine/scene/TileSet.h"
|
||||
#include "hpl1/engine/system/String.h"
|
||||
#include "hpl1/engine/system/low_level_system.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cTileSetManager::cTileSetManager(cGraphics *apGraphics, cResources *apResources)
|
||||
: iResourceManager(apResources->GetFileSearcher(), apResources->GetLowLevel(),
|
||||
apResources->GetLowLevelSystem()) {
|
||||
mpGraphics = apGraphics;
|
||||
mpResources = apResources;
|
||||
}
|
||||
|
||||
cTileSetManager::~cTileSetManager() {
|
||||
DestroyAll();
|
||||
Log(" Done with tilesets\n");
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cTileSet *cTileSetManager::CreateTileSet(const tString &asName) {
|
||||
return static_cast<cTileSet *>(Create(asName));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cTileSetManager::Unload(iResourceBase *apResource) {
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cTileSetManager::Destroy(iResourceBase *apResource) {
|
||||
apResource->DecUserCount();
|
||||
|
||||
if (apResource->HasUsers() == false) {
|
||||
RemoveResource(apResource);
|
||||
hplDelete(apResource);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PRIVATE METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
} // namespace hpl
|
||||
57
engines/hpl1/engine/resources/TileSetManager.h
Normal file
57
engines/hpl1/engine/resources/TileSetManager.h
Normal file
@@ -0,0 +1,57 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#ifndef HPL_TILESET_MANAGER_H
|
||||
#define HPL_TILESET_MANAGER_H
|
||||
|
||||
#include "hpl1/engine/resources/ResourceManager.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class cGraphics;
|
||||
class cResources;
|
||||
class cTileSet;
|
||||
|
||||
class cTileSetManager : public iResourceManager {
|
||||
public:
|
||||
cTileSetManager(cGraphics *apGraphics, cResources *apResources);
|
||||
~cTileSetManager();
|
||||
|
||||
iResourceBase *Create(const tString &asName);
|
||||
cTileSet *CreateTileSet(const tString &asName);
|
||||
|
||||
void Destroy(iResourceBase *apResource);
|
||||
void Unload(iResourceBase *apResource);
|
||||
|
||||
private:
|
||||
cGraphics *mpGraphics;
|
||||
cResources *mpResources;
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_TILESET_MANAGER_H
|
||||
158
engines/hpl1/engine/resources/VideoManager.cpp
Normal file
158
engines/hpl1/engine/resources/VideoManager.cpp
Normal file
@@ -0,0 +1,158 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#include "hpl1/engine/resources/VideoManager.h"
|
||||
|
||||
#include "hpl1/engine/graphics/VideoStream.h"
|
||||
#include "hpl1/engine/resources/FileSearcher.h"
|
||||
#include "hpl1/engine/resources/Resources.h"
|
||||
#include "hpl1/engine/system/String.h"
|
||||
#include "hpl1/engine/system/low_level_system.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cVideoManager::cVideoManager(cGraphics *apGraphics, cResources *apResources)
|
||||
: iResourceManager(apResources->GetFileSearcher(), apResources->GetLowLevel(),
|
||||
apResources->GetLowLevelSystem()) {
|
||||
mpGraphics = apGraphics;
|
||||
mpResources = apResources;
|
||||
}
|
||||
|
||||
cVideoManager::~cVideoManager() {
|
||||
STLDeleteAll(mlstVideoLoaders);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iResourceBase *cVideoManager::Create(const tString &asName) {
|
||||
return CreateVideo(asName);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iVideoStream *cVideoManager::CreateVideo(const tString &asName) {
|
||||
BeginLoad(asName);
|
||||
|
||||
tString sPath = mpFileSearcher->GetFilePath(asName);
|
||||
if (sPath == "") {
|
||||
EndLoad();
|
||||
Error("Video file '%s' could not be found!\n", asName.c_str());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
iVideoStreamLoader *pLoader = GetLoader(asName);
|
||||
if (pLoader == NULL) {
|
||||
Error("Could not find a loader for '%s'\n", asName.c_str());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
iVideoStream *pVideo = pLoader->Create(asName);
|
||||
|
||||
if (pVideo->LoadFromFile(sPath) == false) {
|
||||
EndLoad();
|
||||
hplDelete(pVideo);
|
||||
Error("Could not load video '%s'\n", asName.c_str());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
AddResource(pVideo);
|
||||
|
||||
EndLoad();
|
||||
return pVideo;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cVideoManager::AddVideoLoader(iVideoStreamLoader *apLoader) {
|
||||
mlstVideoLoaders.push_back(apLoader);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cVideoManager::Unload(iResourceBase *apResource) {
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cVideoManager::Destroy(iResourceBase *apResource) {
|
||||
if (apResource) {
|
||||
RemoveResource(apResource);
|
||||
hplDelete(apResource);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cVideoManager::Update(float afTimeStep) {
|
||||
tResourceHandleMapIt it = m_mapHandleResources.begin();
|
||||
for (; it != m_mapHandleResources.end(); ++it) {
|
||||
iResourceBase *pBase = it->second;
|
||||
iVideoStream *pVideo = static_cast<iVideoStream *>(pBase);
|
||||
|
||||
pVideo->Update(afTimeStep);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PRIVATE METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iVideoStreamLoader *cVideoManager::GetLoader(const tString &asFileName) {
|
||||
tString sExt = cString::ToLowerCase(cString::GetFileExt(asFileName));
|
||||
|
||||
tVideoStreamLoaderListIt it = mlstVideoLoaders.begin();
|
||||
for (; it != mlstVideoLoaders.end(); ++it) {
|
||||
iVideoStreamLoader *pLoader = *it;
|
||||
|
||||
tStringVec &vExt = pLoader->GetExtensions();
|
||||
for (size_t i = 0; i < vExt.size(); ++i) {
|
||||
if (vExt[i] == sExt) {
|
||||
return pLoader;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
} // namespace hpl
|
||||
79
engines/hpl1/engine/resources/VideoManager.h
Normal file
79
engines/hpl1/engine/resources/VideoManager.h
Normal file
@@ -0,0 +1,79 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#ifndef HPL_VIDEO_MANAGER_H
|
||||
#define HPL_VIDEO_MANAGER_H
|
||||
|
||||
#include "hpl1/engine/resources/ResourceManager.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class cResources;
|
||||
class cGraphics;
|
||||
class iVideoStream;
|
||||
class iVideoStreamLoader;
|
||||
|
||||
//----------------------------------------------------
|
||||
|
||||
typedef Common::List<iVideoStreamLoader *> tVideoStreamLoaderList;
|
||||
typedef tVideoStreamLoaderList::iterator tVideoStreamLoaderListIt;
|
||||
|
||||
//----------------------------------------------------
|
||||
|
||||
typedef Common::List<iVideoStream *> tVideoStreamList;
|
||||
typedef tVideoStreamList::iterator tVideoStreamListIt;
|
||||
|
||||
//----------------------------------------------------
|
||||
|
||||
class cVideoManager : public iResourceManager {
|
||||
public:
|
||||
cVideoManager(cGraphics *apGraphics, cResources *apResources);
|
||||
~cVideoManager();
|
||||
|
||||
iResourceBase *Create(const tString &asName);
|
||||
|
||||
iVideoStream *CreateVideo(const tString &asName);
|
||||
|
||||
void AddVideoLoader(iVideoStreamLoader *apLoader);
|
||||
|
||||
void Destroy(iResourceBase *apResource);
|
||||
void Unload(iResourceBase *apResource);
|
||||
|
||||
void Update(float afTimeStep);
|
||||
|
||||
private:
|
||||
iVideoStreamLoader *GetLoader(const tString &asFileName);
|
||||
|
||||
cGraphics *mpGraphics;
|
||||
cResources *mpResources;
|
||||
|
||||
tVideoStreamLoaderList mlstVideoLoaders;
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_VIDEO_MANAGER_H
|
||||
76
engines/hpl1/engine/resources/low_level_resources.cpp
Normal file
76
engines/hpl1/engine/resources/low_level_resources.cpp
Normal file
@@ -0,0 +1,76 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "hpl1/engine/resources/low_level_resources.h"
|
||||
#include "common/file.h"
|
||||
#include "common/fs.h"
|
||||
#include "hpl1/debug.h"
|
||||
#include "hpl1/engine/graphics/LowLevelGraphics.h"
|
||||
#include "hpl1/engine/impl/MeshLoaderCollada.h"
|
||||
#include "hpl1/engine/impl/MeshLoaderMSH.h"
|
||||
#include "hpl1/engine/resources/MeshLoaderHandler.h"
|
||||
#include "hpl1/engine/resources/VideoManager.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
static tString getImageType(tString filepath) {
|
||||
filepath.toLowercase();
|
||||
size_t pos = filepath.findLastOf(".");
|
||||
if (pos != Common::String::npos)
|
||||
return filepath.substr(pos + 1).c_str();
|
||||
return "";
|
||||
}
|
||||
|
||||
Bitmap2D *LowLevelResources::loadBitmap2D(const tString &filepath) {
|
||||
return new Bitmap2D(filepath, getImageType(filepath), *_lowLevelGraphics->GetPixelFormat());
|
||||
}
|
||||
|
||||
void LowLevelResources::getSupportedImageFormats(tStringList &formats) {
|
||||
formats.push_back("BMP");
|
||||
formats.push_back("GIF");
|
||||
formats.push_back("JPEG");
|
||||
formats.push_back("PNG");
|
||||
formats.push_back("JPG");
|
||||
formats.push_back("TGA");
|
||||
}
|
||||
|
||||
void LowLevelResources::addMeshLoaders(cMeshLoaderHandler *ml) {
|
||||
ml->AddLoader(hplNew(cMeshLoaderMSH, (_lowLevelGraphics)));
|
||||
ml->AddLoader(hplNew(cMeshLoaderCollada, (_lowLevelGraphics)));
|
||||
}
|
||||
|
||||
void LowLevelResources::addVideoLoaders(cVideoManager *vm) {
|
||||
#ifdef INCLUDE_THORA
|
||||
apManager->AddVideoLoader(hplNew(cVideoStreamTheora_Loader, ()));
|
||||
#endif
|
||||
}
|
||||
|
||||
void LowLevelResources::findFilesInDir(tStringList &alstStrings, tString asDir, tString asMask) {
|
||||
Common::Path pattern(asDir + '/' + asMask);
|
||||
Common::ArchiveMemberList ls;
|
||||
if (SearchMan.listMatchingMembers(ls, pattern) == 0)
|
||||
Hpl1::logWarning(Hpl1::kDebugFilePath, "no files matching pattern %s were found", pattern.toString().c_str());
|
||||
|
||||
for (auto &f : ls)
|
||||
alstStrings.push_back(f->getName());
|
||||
}
|
||||
|
||||
} // namespace hpl
|
||||
60
engines/hpl1/engine/resources/low_level_resources.h
Normal file
60
engines/hpl1/engine/resources/low_level_resources.h
Normal file
@@ -0,0 +1,60 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#ifndef HPL_LOWLEVELRESOURCES_H
|
||||
#define HPL_LOWLEVELRESOURCES_H
|
||||
|
||||
#include "hpl1/engine/system/SystemTypes.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class Bitmap2D;
|
||||
class cMeshLoaderHandler;
|
||||
class cVideoManager;
|
||||
class iLowLevelGraphics;
|
||||
|
||||
class LowLevelResources {
|
||||
public:
|
||||
LowLevelResources(iLowLevelGraphics *lowLevelGraphics) : _lowLevelGraphics(lowLevelGraphics) {
|
||||
}
|
||||
|
||||
// Returns a list of files in a directory matching a pattern
|
||||
void findFilesInDir(tStringList &fileList, tString dir, tString pattern);
|
||||
|
||||
void getSupportedImageFormats(tStringList &formats);
|
||||
Bitmap2D *loadBitmap2D(const tString &filepath);
|
||||
|
||||
void addMeshLoaders(cMeshLoaderHandler *ml);
|
||||
void addVideoLoaders(cVideoManager *vm);
|
||||
|
||||
private:
|
||||
iLowLevelGraphics *_lowLevelGraphics;
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_LOWLEVELRESOURCES_H
|
||||
Reference in New Issue
Block a user