Initial commit
This commit is contained in:
1
engines/hpl1/POTFILES
Normal file
1
engines/hpl1/POTFILES
Normal file
@@ -0,0 +1 @@
|
||||
engines/hpl1/metaengine.cpp
|
||||
48
engines/hpl1/algorithms.h
Normal file
48
engines/hpl1/algorithms.h
Normal file
@@ -0,0 +1,48 @@
|
||||
/* 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef HPL1_ALGORITHMS
|
||||
#define HPL1_ALGORITHMS
|
||||
|
||||
#include "common/array.h"
|
||||
|
||||
namespace Hpl1 {
|
||||
|
||||
template<typename T, typename V>
|
||||
void resizeAndFill(Common::Array<T> &container, const typename Common::Array<T>::size_type newSize, const V &value) {
|
||||
const auto oldSize = container.size();
|
||||
container.resize(newSize);
|
||||
for (auto i = oldSize; i < newSize; ++i)
|
||||
container[i] = value;
|
||||
}
|
||||
|
||||
template<typename RandomIt, typename Pred>
|
||||
RandomIt removeIf(RandomIt begin, RandomIt end, Pred pred) {
|
||||
for (auto i = begin; i != end; ++i) {
|
||||
if (!pred(*i))
|
||||
*begin++ = *i;
|
||||
}
|
||||
return begin;
|
||||
}
|
||||
|
||||
} // namespace Hpl1
|
||||
|
||||
#endif // HPL1_ALGORITHMS
|
||||
3
engines/hpl1/configure.engine
Normal file
3
engines/hpl1/configure.engine
Normal file
@@ -0,0 +1,3 @@
|
||||
# This file is included from the main "configure" script
|
||||
# add_engine [name] [desc] [build-by-default] [subengines] [base games] [deps] [components]
|
||||
add_engine hpl1 "Hpl1" yes "" "" "16bit 3d highres jpeg gif png opengl_game_shaders" "tinygl"
|
||||
3
engines/hpl1/credits.pl
Normal file
3
engines/hpl1/credits.pl
Normal file
@@ -0,0 +1,3 @@
|
||||
begin_section("Hpl1");
|
||||
add_person("Emanuele Grisenti", "grisenti", "");
|
||||
end_section();
|
||||
68
engines/hpl1/debug.h
Normal file
68
engines/hpl1/debug.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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef HPL1_DEBUG_H
|
||||
#define HPL1_DEBUG_H
|
||||
|
||||
#include "common/debug.h"
|
||||
#include "common/textconsole.h"
|
||||
|
||||
#define HPL1_UNIMPLEMENTED(fnName) error("call to unimplemented function " #fnName)
|
||||
|
||||
namespace Hpl1 {
|
||||
|
||||
enum DebugChannels {
|
||||
kDebugGraphics = 1,
|
||||
kDebugResourceLoading,
|
||||
kDebugFilePath,
|
||||
kDebugOpenGL,
|
||||
kDebugRenderer,
|
||||
kDebugAudio,
|
||||
kDebugSaves,
|
||||
kDebugTextures,
|
||||
kDebugScripts,
|
||||
kDebugShaders,
|
||||
};
|
||||
|
||||
enum DebugLevels {
|
||||
kDebugLevelError = 1,
|
||||
kDebugLevelWarning = 2,
|
||||
kDebugLevelLog = 3
|
||||
};
|
||||
|
||||
template<typename... Args>
|
||||
void logError(uint32 channels, const char *fmt, Args... args) {
|
||||
debugCN(kDebugLevelError, channels, fmt, args...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void logWarning(uint32 channels, const char *fmt, Args... args) {
|
||||
debugCN(kDebugLevelWarning, channels, fmt, args...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void logInfo(uint32 channels, const char *fmt, Args... args) {
|
||||
debugCN(kDebugLevelLog, channels, fmt, args...);
|
||||
}
|
||||
|
||||
} // namespace Hpl1
|
||||
|
||||
#endif
|
||||
50
engines/hpl1/detection.cpp
Normal file
50
engines/hpl1/detection.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
/* 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/detection.h"
|
||||
#include "base/plugins.h"
|
||||
#include "common/config-manager.h"
|
||||
#include "common/file.h"
|
||||
#include "common/md5.h"
|
||||
#include "common/str-array.h"
|
||||
#include "common/util.h"
|
||||
#include "hpl1/debug.h"
|
||||
#include "hpl1/detection_tables.h"
|
||||
|
||||
const DebugChannelDef Hpl1MetaEngineDetection::debugFlagList[] = {
|
||||
{Hpl1::kDebugGraphics, "Graphics", "Graphics debug channel"},
|
||||
{Hpl1::kDebugResourceLoading, "ResourceLoading", "Resource loading debug channel"},
|
||||
{Hpl1::kDebugFilePath, "FilePath", "File path debug channel"},
|
||||
{Hpl1::kDebugOpenGL, "OpenGL", "OpenGL debug channel"},
|
||||
{Hpl1::kDebugRenderer, "Renderer", "Rederer debug channel"},
|
||||
{Hpl1::kDebugAudio, "Audio", "Audio debug channel"},
|
||||
{Hpl1::kDebugSaves, "Saves", "Channel for debugging game saving and loading"},
|
||||
{Hpl1::kDebugTextures, "Textures", "Texture debug channel"},
|
||||
{Hpl1::kDebugScripts, "Scripts", "Scripts debug channel"},
|
||||
{Hpl1::kDebugShaders, "Shaders", "Shaders debug channel"},
|
||||
DEBUG_CHANNEL_END};
|
||||
|
||||
Hpl1MetaEngineDetection::Hpl1MetaEngineDetection() : AdvancedMetaEngineDetection(Hpl1::GAME_DESCRIPTIONS,
|
||||
Hpl1::GAME_NAMES) {
|
||||
_flags = kADFlagMatchFullPaths;
|
||||
}
|
||||
|
||||
REGISTER_PLUGIN_STATIC(HPL1_DETECTION, PLUGIN_TYPE_ENGINE_DETECTION, Hpl1MetaEngineDetection);
|
||||
59
engines/hpl1/detection.h
Normal file
59
engines/hpl1/detection.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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef HPL1_DETECTION_H
|
||||
#define HPL1_DETECTION_H
|
||||
|
||||
#include "engines/advancedDetector.h"
|
||||
|
||||
namespace Hpl1 {
|
||||
|
||||
extern const PlainGameDescriptor GAME_NAMES[];
|
||||
|
||||
extern const ADGameDescription GAME_DESCRIPTIONS[];
|
||||
|
||||
} // namespace Hpl1
|
||||
|
||||
class Hpl1MetaEngineDetection : public AdvancedMetaEngineDetection<ADGameDescription> {
|
||||
static const DebugChannelDef debugFlagList[];
|
||||
|
||||
public:
|
||||
Hpl1MetaEngineDetection();
|
||||
~Hpl1MetaEngineDetection() override {}
|
||||
|
||||
const char *getName() const override {
|
||||
return "hpl1";
|
||||
}
|
||||
|
||||
const char *getEngineName() const override {
|
||||
return "HPL1";
|
||||
}
|
||||
|
||||
const char *getOriginalCopyright() const override {
|
||||
return "HPL1 (C) Frictional Games AB";
|
||||
}
|
||||
|
||||
const DebugChannelDef *getDebugChannels() const override {
|
||||
return debugFlagList;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
202
engines/hpl1/detection_tables.h
Normal file
202
engines/hpl1/detection_tables.h
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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Hpl1 {
|
||||
|
||||
const PlainGameDescriptor GAME_NAMES[] = {
|
||||
{"penumbraoverture", "Penumbra: Overture"},
|
||||
{"penumbrablackplague", "Penumbra: Black Plague"},
|
||||
{0, 0}
|
||||
};
|
||||
|
||||
const ADGameDescription GAME_DESCRIPTIONS[] = {
|
||||
|
||||
// Penumbra: Overture (Humble Indie Bundle #1 Release)
|
||||
{
|
||||
"penumbraoverture",
|
||||
nullptr,
|
||||
AD_ENTRY1s("Penumbra.exe", "43c33c142b18268c9e98d4c5a6d911b7", 2727936),
|
||||
Common::Language::EN_ANY,
|
||||
Common::Platform::kPlatformWindows,
|
||||
ADGF_NO_FLAGS,
|
||||
GUIO0()
|
||||
},
|
||||
|
||||
// Penumbra: Overture (GOG v1.0)
|
||||
{
|
||||
"penumbraoverture",
|
||||
nullptr,
|
||||
AD_ENTRY1s("Penumbra.exe", "f840b972ee889200ba501ee3a465317e", 2744320),
|
||||
Common::Language::EN_ANY,
|
||||
Common::Platform::kPlatformWindows,
|
||||
ADGF_NO_FLAGS,
|
||||
GUIO0()
|
||||
},
|
||||
|
||||
// Penumbra: Overture (GOG v1.1.1 - Mac Intel only)
|
||||
{
|
||||
"penumbraoverture",
|
||||
nullptr,
|
||||
AD_ENTRY1s("Penumbra.app/Contents/MacOS/Penumbra", "e893ccac7b311ab1559890837aa131b0", 8234848),
|
||||
Common::Language::EN_ANY,
|
||||
Common::Platform::kPlatformMacintosh,
|
||||
ADGF_NO_FLAGS,
|
||||
GUIO0()
|
||||
},
|
||||
|
||||
// Penumbra: Overture (Steam v1.1.1 - Mac Intel only)
|
||||
{
|
||||
"penumbraoverture",
|
||||
nullptr,
|
||||
AD_ENTRY1s("Penumbra.app/Contents/MacOS/Penumbra", "18d91c220e3461f2f7cf257009068416", 8468352),
|
||||
Common::Language::EN_ANY,
|
||||
Common::Platform::kPlatformMacintosh,
|
||||
ADGF_NO_FLAGS,
|
||||
GUIO0()
|
||||
},
|
||||
|
||||
// Penumbra: Overture (v1.0.3 - Mac PPC + Intel)
|
||||
{
|
||||
"penumbraoverture",
|
||||
nullptr,
|
||||
AD_ENTRY1s("Penumbra.app/Contents/MacOS/Penumbra", "1fcca1c15ac595c84c49c01692b90c0d", 17446384),
|
||||
Common::Language::EN_ANY,
|
||||
Common::Platform::kPlatformMacintosh,
|
||||
ADGF_NO_FLAGS,
|
||||
GUIO0()
|
||||
},
|
||||
|
||||
// Penumbra: Overture (v1.0 - Mac demo)
|
||||
{
|
||||
"penumbraoverture",
|
||||
nullptr,
|
||||
AD_ENTRY1s("PenumbraDemo.app/Contents/MacOS/PenumbraDemo", "656342216967baaaa80eb413d5c93b29", 16203948),
|
||||
Common::Language::EN_ANY,
|
||||
Common::Platform::kPlatformMacintosh,
|
||||
ADGF_DEMO,
|
||||
GUIO0()
|
||||
},
|
||||
|
||||
// Penumbra: Overture (v1.0.3 - Mac demo)
|
||||
{
|
||||
"penumbraoverture",
|
||||
nullptr,
|
||||
AD_ENTRY1s("PenumbraDemo.app/Contents/MacOS/PenumbraDemo", "c898d408859f80d260dbe0bd312c3acf", 17402172),
|
||||
Common::Language::EN_ANY,
|
||||
Common::Platform::kPlatformMacintosh,
|
||||
ADGF_DEMO,
|
||||
GUIO0()
|
||||
},
|
||||
|
||||
// Penumbra: Overture (The Penumbra Collection)
|
||||
// TRAC #14674
|
||||
{
|
||||
"penumbraoverture",
|
||||
nullptr,
|
||||
AD_ENTRY1s("Penumbra.exe", "202990aa064ae67a675e2b187384036a", 2736128),
|
||||
Common::Language::EN_ANY,
|
||||
Common::kPlatformWindows,
|
||||
ADGF_NO_FLAGS,
|
||||
GUIO0()
|
||||
},
|
||||
|
||||
// Penumbra: Overture (Steam - Windows)
|
||||
{
|
||||
"penumbraoverture",
|
||||
nullptr,
|
||||
AD_ENTRY1s("Penumbra.exe", "384e33ddc55f51debca07b6538087e75", 3104768),
|
||||
Common::Language::EN_ANY,
|
||||
Common::kPlatformWindows,
|
||||
ADGF_NO_FLAGS,
|
||||
GUIO0()
|
||||
},
|
||||
|
||||
// Penumbra: Overture (Steam - Linux)
|
||||
{
|
||||
"penumbraoverture",
|
||||
nullptr,
|
||||
AD_ENTRY1s("penumbra.bin", "41950a7597b7d9976f77a73a43e8871d", 6301460),
|
||||
Common::Language::EN_ANY,
|
||||
Common::kPlatformLinux,
|
||||
ADGF_NO_FLAGS,
|
||||
GUIO0()
|
||||
},
|
||||
|
||||
// Penumbra: Im Halbschatten (Episode Eins) - German
|
||||
// TRAC #16279
|
||||
{
|
||||
"penumbraoverture",
|
||||
nullptr,
|
||||
AD_ENTRY1s("Penumbra.exe", "7b216d6bfdf2dc8f2a1371ee3565bb6f", 2363392),
|
||||
Common::Language::DE_DEU,
|
||||
Common::kPlatformWindows,
|
||||
ADGF_NO_FLAGS,
|
||||
GUIO0()
|
||||
},
|
||||
|
||||
// Penumbra: Black Plague (GOG v1.0)
|
||||
{
|
||||
"penumbrablackplague",
|
||||
nullptr,
|
||||
AD_ENTRY1s("Penumbra.exe", "a066f7284e063ac3e5d7409102b7a497", 2985984),
|
||||
Common::Language::EN_ANY,
|
||||
Common::kPlatformWindows,
|
||||
ADGF_UNSUPPORTED,
|
||||
GUIO0()
|
||||
},
|
||||
|
||||
// Penumbra: Black Plague (Mac Steam v1.1.1)
|
||||
{
|
||||
"penumbrablackplague",
|
||||
nullptr,
|
||||
AD_ENTRY1s("BlackPlague.app/Contents/MacOS/BlackPlague", "e3ddadc4809ab9853079c0db50f3e032", 9090512),
|
||||
Common::Language::EN_ANY,
|
||||
Common::Platform::kPlatformMacintosh,
|
||||
ADGF_UNSUPPORTED,
|
||||
GUIO0()
|
||||
},
|
||||
|
||||
// Penumbra: Black Plague (Mac GOG v1.1.1)
|
||||
{
|
||||
"penumbrablackplague",
|
||||
nullptr,
|
||||
AD_ENTRY1s("BlackPlague.app/Contents/MacOS/BlackPlague", "867ea67dd189ad4c191e0a9664d2f065", 8856992),
|
||||
Common::Language::EN_ANY,
|
||||
Common::Platform::kPlatformMacintosh,
|
||||
ADGF_UNSUPPORTED,
|
||||
GUIO0()
|
||||
},
|
||||
|
||||
// Penumbra: Black Plague (CD)
|
||||
{
|
||||
"penumbrablackplague",
|
||||
nullptr,
|
||||
AD_ENTRY1s("Penumbra.exe", "be48f62ecd16975e31083989129eafd3", 8159232),
|
||||
Common::Language::EN_ANY,
|
||||
Common::kPlatformWindows,
|
||||
ADGF_UNSUPPORTED,
|
||||
GUIO0()
|
||||
},
|
||||
|
||||
AD_TABLE_END_MARKER
|
||||
};
|
||||
|
||||
} // namespace Hpl1
|
||||
74
engines/hpl1/engine/ai/AI.cpp
Normal file
74
engines/hpl1/engine/ai/AI.cpp
Normal file
@@ -0,0 +1,74 @@
|
||||
/* 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/ai/AI.h"
|
||||
|
||||
#include "hpl1/engine/ai/AINodeGenerator.h"
|
||||
#include "hpl1/engine/system/MemoryManager.h"
|
||||
#include "hpl1/engine/system/low_level_system.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cAI::cAI() : iUpdateable("HPL_AI") {
|
||||
mpAINodeGenerator = hplNew(cAINodeGenerator, ());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cAI::~cAI() {
|
||||
hplDelete(mpAINodeGenerator);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cAI::Reset() {
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cAI::Update(float afTimeStep) {
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cAI::Init() {
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
} // namespace hpl
|
||||
58
engines/hpl1/engine/ai/AI.h
Normal file
58
engines/hpl1/engine/ai/AI.h
Normal file
@@ -0,0 +1,58 @@
|
||||
/* 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_AI_H
|
||||
#define HPL_AI_H
|
||||
|
||||
#include "hpl1/engine/game/GameTypes.h"
|
||||
#include "hpl1/engine/system/SystemTypes.h"
|
||||
|
||||
#include "hpl1/engine/game/Updateable.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class cAINodeGenerator;
|
||||
|
||||
class cAI : public iUpdateable {
|
||||
public:
|
||||
cAI();
|
||||
~cAI();
|
||||
|
||||
void Reset();
|
||||
void Update(float afTimeStep);
|
||||
|
||||
void Init();
|
||||
|
||||
cAINodeGenerator *GetNodeGenerator() { return mpAINodeGenerator; }
|
||||
|
||||
private:
|
||||
cAINodeGenerator *mpAINodeGenerator;
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_AI_H
|
||||
619
engines/hpl1/engine/ai/AINodeContainer.cpp
Normal file
619
engines/hpl1/engine/ai/AINodeContainer.cpp
Normal file
@@ -0,0 +1,619 @@
|
||||
/* 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/ai/AINodeContainer.h"
|
||||
|
||||
#include "hpl1/engine/physics/PhysicsBody.h"
|
||||
#include "hpl1/engine/scene/World3D.h"
|
||||
#include "hpl1/engine/system/String.h"
|
||||
#include "hpl1/engine/system/low_level_system.h"
|
||||
|
||||
#include "hpl1/engine/math/Math.h"
|
||||
|
||||
#include "hpl1/engine/impl/tinyXML/tinyxml.h"
|
||||
|
||||
#include "common/algorithm.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// AI NODE
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cAINode::cAINode() {
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cAINode::~cAINode() {
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cAINode::AddEdge(cAINode *pNode) {
|
||||
cAINodeEdge Edge;
|
||||
|
||||
Edge.mpNode = pNode;
|
||||
Edge.mfDistance = cMath::Vector3Dist(mvPosition, pNode->mvPosition);
|
||||
Edge.mfSqrDistance = cMath::Vector3DistSqr(mvPosition, pNode->mvPosition);
|
||||
|
||||
mvEdges.push_back(Edge);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// RAY INTERSECT
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cAINodeRayCallback::Reset() {
|
||||
mbIntersected = false;
|
||||
mpCallback = NULL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cAINodeRayCallback::Intersected() {
|
||||
return mbIntersected;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cAINodeRayCallback::BeforeIntersect(iPhysicsBody *pBody) {
|
||||
if (pBody->GetCollideCharacter() == false)
|
||||
return false;
|
||||
|
||||
if ((mFlags & eAIFreePathFlag_SkipStatic) && pBody->GetMass() == 0)
|
||||
return false;
|
||||
|
||||
if ((mFlags & eAIFreePathFlag_SkipDynamic) &&
|
||||
(pBody->GetMass() > 0 || pBody->IsCharacter()))
|
||||
return false;
|
||||
|
||||
if ((mFlags & eAIFreePathFlag_SkipVolatile) && pBody->IsVolatile())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cAINodeRayCallback::OnIntersect(iPhysicsBody *pBody, cPhysicsRayParams *apParams) {
|
||||
if (mpCallback) {
|
||||
if (mpCallback->Intersects(pBody, apParams)) {
|
||||
mbIntersected = true;
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
mbIntersected = true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cAINodeIterator::cAINodeIterator(cAINodeContainer *apContainer, const cVector3f &avPos, float afRadius) {
|
||||
mpContainer = apContainer;
|
||||
mvPosition = avPos;
|
||||
mfRadius = afRadius;
|
||||
|
||||
// Calculate local position
|
||||
cVector2f vLocalPos(mvPosition.x, mvPosition.z);
|
||||
vLocalPos -= mpContainer->mvMinGridPos;
|
||||
|
||||
cVector2f vLocalStart = vLocalPos - cVector2f(afRadius);
|
||||
cVector2f vLocalEnd = vLocalPos + cVector2f(afRadius);
|
||||
|
||||
mvStartGridPos = mpContainer->GetGridPosFromLocal(vLocalStart);
|
||||
mvEndGridPos = mpContainer->GetGridPosFromLocal(vLocalEnd);
|
||||
mvGridPos = mvStartGridPos;
|
||||
|
||||
mpNodeList = &mpContainer->GetGrid(mvGridPos)->mlstNodes;
|
||||
while (mpNodeList->empty()) {
|
||||
if (IncGridPos()) {
|
||||
mpNodeList = &mpContainer->GetGrid(mvGridPos)->mlstNodes;
|
||||
} else {
|
||||
mpNodeList = NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (mpNodeList) {
|
||||
mNodeIt = mpNodeList->begin();
|
||||
}
|
||||
|
||||
// Log("--------------------------------------\n");
|
||||
// Log("Iterating (%d %d) -> (%d %d)\n", mvStartGridPos.x,mvStartGridPos.y,
|
||||
// mvEndGridPos.x,mvEndGridPos.y);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cAINodeIterator::HasNext() {
|
||||
if (mpNodeList == NULL || mpNodeList->empty())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cAINode *cAINodeIterator::Next() {
|
||||
cAINode *pNode = *mNodeIt;
|
||||
|
||||
++mNodeIt;
|
||||
if (mNodeIt == mpNodeList->end()) {
|
||||
if (IncGridPos()) {
|
||||
mpNodeList = &mpContainer->GetGrid(mvGridPos)->mlstNodes;
|
||||
while (mpNodeList->empty()) {
|
||||
if (IncGridPos()) {
|
||||
mpNodeList = &mpContainer->GetGrid(mvGridPos)->mlstNodes;
|
||||
} else {
|
||||
mpNodeList = NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
mpNodeList = NULL;
|
||||
}
|
||||
|
||||
if (mpNodeList)
|
||||
mNodeIt = mpNodeList->begin();
|
||||
}
|
||||
|
||||
return pNode;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cAINodeIterator::IncGridPos() {
|
||||
mvGridPos.x++;
|
||||
if (mvGridPos.x > mvEndGridPos.x) {
|
||||
mvGridPos.x = mvStartGridPos.x;
|
||||
mvGridPos.y++;
|
||||
if (mvGridPos.y > mvEndGridPos.y) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cAINodeContainer::cAINodeContainer(const tString &asName, const tString &asNodeName,
|
||||
cWorld3D *apWorld, const cVector3f &avCollideSize) {
|
||||
mpWorld = apWorld;
|
||||
mvSize = avCollideSize;
|
||||
msName = asName;
|
||||
msNodeName = asNodeName;
|
||||
|
||||
mpRayCallback = hplNew(cAINodeRayCallback, ());
|
||||
|
||||
mlMaxNodeEnds = 5;
|
||||
mlMinNodeEnds = 2;
|
||||
mfMaxEndDistance = 3.0f;
|
||||
mfMaxHeight = 0.1f;
|
||||
|
||||
mlNodesPerGrid = 6;
|
||||
|
||||
mbNodeIsAtCenter = true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cAINodeContainer::~cAINodeContainer() {
|
||||
hplDelete(mpRayCallback);
|
||||
|
||||
STLDeleteAll(mvNodes);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cAINodeContainer::ReserveSpace(size_t alReserveSpace) {
|
||||
mvNodes.reserve(alReserveSpace);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cAINodeContainer::AddNode(const tString &asName, const cVector3f &avPosition, void *apUserData) {
|
||||
cAINode *pNode = hplNew(cAINode, ());
|
||||
pNode->msName = asName;
|
||||
pNode->mvPosition = avPosition;
|
||||
pNode->mpUserData = apUserData;
|
||||
|
||||
mvNodes.push_back(pNode);
|
||||
m_mapNodes.insert(tAINodeMap::value_type(asName, pNode));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
int cAINodeContainer::GetNodeNum() const {
|
||||
return (int)mvNodes.size();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cAINode *cAINodeContainer::GetNodeFromName(const tString &asName) {
|
||||
tAINodeMapIt it = m_mapNodes.find(asName);
|
||||
if (it == m_mapNodes.end()) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return it->second;
|
||||
|
||||
// return (cAINode*)STLFindByName(mvNodes,asName);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
class cSortEndNodes {
|
||||
public:
|
||||
bool operator()(const cAINodeEdge &aEndA, const cAINodeEdge &aEndB) {
|
||||
return aEndA.mfDistance < aEndB.mfDistance;
|
||||
}
|
||||
};
|
||||
|
||||
void cAINodeContainer::Compile() {
|
||||
BuildNodeGridMap();
|
||||
|
||||
tAINodeVecIt CurrentNodeIt = mvNodes.begin();
|
||||
for (; CurrentNodeIt != mvNodes.end(); ++CurrentNodeIt) {
|
||||
cAINode *pNode = *CurrentNodeIt;
|
||||
|
||||
////////////////////////////////////////
|
||||
// Add the ends that are connected to the node.
|
||||
/*Log("Node %s checks: ",pNode->GetName().c_str());
|
||||
tAINodeVecIt EndNodeIt = mvNodes.begin();
|
||||
for(; EndNodeIt != mvNodes.end(); ++EndNodeIt)
|
||||
{
|
||||
cAINode *pEndNode = *EndNodeIt;
|
||||
|
||||
if(pEndNode == pNode) continue;
|
||||
float fDist = cMath::Vector3Dist(pNode->mvPosition, pEndNode->mvPosition);
|
||||
if(fDist > mfMaxEndDistance*2) continue;
|
||||
Log("'%s'(%f) ",pEndNode->GetName().c_str(),fDist);
|
||||
|
||||
float fHeight = fabs(pNode->mvPosition.y - pEndNode->mvPosition.y);
|
||||
|
||||
if( fHeight <= mfMaxHeight &&
|
||||
FreePath(pNode->mvPosition, pEndNode->mvPosition,-1,eAIFreePathFlag_SkipDynamic))
|
||||
{
|
||||
pNode->AddEdge(pEndNode);
|
||||
Log("Added!");
|
||||
}
|
||||
Log(", ");
|
||||
}
|
||||
Log("\n");*/
|
||||
// Log("Node %s checks: ",pNode->GetName().c_str());
|
||||
cAINodeIterator nodeIt = GetNodeIterator(pNode->mvPosition, mfMaxEndDistance * 1.5f);
|
||||
while (nodeIt.HasNext()) {
|
||||
cAINode *pEndNode = nodeIt.Next();
|
||||
|
||||
if (pEndNode == pNode)
|
||||
continue;
|
||||
float fDist = cMath::Vector3Dist(pNode->mvPosition, pEndNode->mvPosition);
|
||||
if (fDist > mfMaxEndDistance * 2)
|
||||
continue;
|
||||
// Log("'%s'(%f) ",pEndNode->GetName().c_str(),fDist);
|
||||
|
||||
float fHeight = fabs(pNode->mvPosition.y - pEndNode->mvPosition.y);
|
||||
|
||||
tAIFreePathFlag flag = eAIFreePathFlag_SkipDynamic | eAIFreePathFlag_SkipVolatile;
|
||||
if (fHeight <= mfMaxHeight &&
|
||||
FreePath(pNode->mvPosition, pEndNode->mvPosition, -1, flag)) {
|
||||
pNode->AddEdge(pEndNode);
|
||||
// Log("Added!");
|
||||
}
|
||||
// Log(", ");
|
||||
}
|
||||
// Log("\n");
|
||||
|
||||
///////////////////////////////////////
|
||||
// Sort nodes and remove unwanted ones.
|
||||
|
||||
Common::sort(pNode->mvEdges.data(), pNode->mvEdges.data() + pNode->mvEdges.size(), cSortEndNodes());
|
||||
|
||||
// Resize if to too large
|
||||
if (mlMaxNodeEnds > 0 && (int)pNode->mvEdges.size() > mlMaxNodeEnds) {
|
||||
pNode->mvEdges.resize(mlMaxNodeEnds);
|
||||
}
|
||||
|
||||
// Remove ends to far, but skip if min nodes is not met
|
||||
for (size_t i = 0; i < pNode->mvEdges.size(); ++i) {
|
||||
if (pNode->mvEdges[i].mfDistance > mfMaxEndDistance && (int)i >= mlMinNodeEnds) {
|
||||
pNode->mvEdges.resize(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Log(" Final edge count: %d\n",pNode->mvEdges.size());
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cAINodeContainer::BuildNodeGridMap() {
|
||||
bool bLog = false;
|
||||
|
||||
if (bLog)
|
||||
Log("Nodes: %d\n", mvNodes.size());
|
||||
|
||||
////////////////////////////////////
|
||||
// Calculate min and max
|
||||
cVector2f vMin(mvNodes[0]->GetPosition().x, mvNodes[0]->GetPosition().z);
|
||||
cVector2f vMax(mvNodes[0]->GetPosition().x, mvNodes[0]->GetPosition().z);
|
||||
|
||||
for (size_t i = 1; i < mvNodes.size(); ++i) {
|
||||
cAINode *pNode = mvNodes[i];
|
||||
|
||||
if (vMin.x > pNode->GetPosition().x)
|
||||
vMin.x = pNode->GetPosition().x;
|
||||
if (vMin.y > pNode->GetPosition().z)
|
||||
vMin.y = pNode->GetPosition().z;
|
||||
|
||||
if (vMax.x < pNode->GetPosition().x)
|
||||
vMax.x = pNode->GetPosition().x;
|
||||
if (vMax.y < pNode->GetPosition().z)
|
||||
vMax.y = pNode->GetPosition().z;
|
||||
}
|
||||
|
||||
mvMinGridPos = vMin;
|
||||
mvMaxGridPos = vMax;
|
||||
|
||||
////////////////////////////////////
|
||||
// Determine size of grids
|
||||
int lGridNum = (int)(sqrt((float)mvNodes.size() / (float)mlNodesPerGrid) + 0.5f) + 1;
|
||||
|
||||
if (bLog)
|
||||
Log("Grid Num: %d\n", lGridNum);
|
||||
|
||||
mvGridMapSize.x = lGridNum;
|
||||
mvGridMapSize.y = lGridNum;
|
||||
|
||||
//+1 to fix so that nodes on the border has a grid)
|
||||
mvGrids.resize((lGridNum + 1) * (lGridNum + 1));
|
||||
|
||||
mvGridSize = (mvMaxGridPos - mvMinGridPos);
|
||||
mvGridSize.x /= (float)mvGridMapSize.x;
|
||||
mvGridSize.y /= (float)mvGridMapSize.y;
|
||||
|
||||
if (bLog)
|
||||
Log("GridSize: %f : %f\n", mvGridSize.x, mvGridSize.y);
|
||||
if (bLog)
|
||||
Log("MinPos: %s\n", mvMinGridPos.ToString().c_str());
|
||||
if (bLog)
|
||||
Log("MaxPos: %s\n", mvMaxGridPos.ToString().c_str());
|
||||
|
||||
////////////////////////////////////
|
||||
// Add nodes to grid
|
||||
for (size_t i = 0; i < mvNodes.size(); ++i) {
|
||||
cAINode *pNode = mvNodes[i];
|
||||
|
||||
cVector2f vLocalPos(pNode->GetPosition().x, pNode->GetPosition().z);
|
||||
vLocalPos -= mvMinGridPos;
|
||||
|
||||
cVector2l vGridPos(0);
|
||||
// Have checks so we are sure there is no division by zero.
|
||||
if (mvGridSize.x > 0)
|
||||
vGridPos.x = (int)(vLocalPos.x / mvGridSize.x);
|
||||
if (mvGridSize.y > 0)
|
||||
vGridPos.y = (int)(vLocalPos.y / mvGridSize.y);
|
||||
|
||||
if (false)
|
||||
Log("Adding node %d, world: (%s) local (%s), at %d : %d\n", i,
|
||||
pNode->GetPosition().ToString().c_str(),
|
||||
vLocalPos.ToString().c_str(),
|
||||
vGridPos.x, vGridPos.y);
|
||||
|
||||
mvGrids[vGridPos.y * (mvGridMapSize.x + 1) + vGridPos.x].mlstNodes.push_back(pNode);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cAINodeIterator cAINodeContainer::GetNodeIterator(const cVector3f &avPosition, float afRadius) {
|
||||
return cAINodeIterator(this, avPosition, afRadius);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
static const cVector2f gvPosAdds[] = {cVector2f(0, 0),
|
||||
cVector2f(1, 0),
|
||||
cVector2f(-1, 0),
|
||||
cVector2f(0, 1),
|
||||
cVector2f(0, -1)};
|
||||
|
||||
bool cAINodeContainer::FreePath(const cVector3f &avStart, const cVector3f &avEnd, int alRayNum,
|
||||
tAIFreePathFlag aFlags, iAIFreePathCallback *apCallback) {
|
||||
iPhysicsWorld *pPhysicsWorld = mpWorld->GetPhysicsWorld();
|
||||
if (pPhysicsWorld == NULL)
|
||||
return true;
|
||||
|
||||
if (alRayNum < 0 || alRayNum > 5)
|
||||
alRayNum = 5;
|
||||
|
||||
/////////////////////////////
|
||||
// Calculate the right vector
|
||||
const cVector3f vForward = cMath::Vector3Normalize(avEnd - avStart);
|
||||
const cVector3f vUp = cVector3f(0, 1.0f, 0);
|
||||
const cVector3f vRight = cMath::Vector3Cross(vForward, vUp);
|
||||
|
||||
// Get the center
|
||||
const cVector3f vStartCenter = mbNodeIsAtCenter ? avStart : avStart + cVector3f(0, mvSize.y / 2, 0);
|
||||
const cVector3f vEndCenter = mbNodeIsAtCenter ? avEnd : avEnd + cVector3f(0, mvSize.y / 2, 0);
|
||||
|
||||
// Get the half with and height. Make them a little smaller so that player can slide over funk on floor.
|
||||
const float fHalfWidth = mvSize.x * 0.4f;
|
||||
const float fHalfHeight = mvSize.y * 0.4f;
|
||||
|
||||
// Setup ray callback
|
||||
mpRayCallback->SetFlags(aFlags);
|
||||
|
||||
// Iterate through all the rays.
|
||||
for (int i = 0; i < alRayNum; ++i) {
|
||||
cVector3f vAdd = vRight * (gvPosAdds[i].x * fHalfWidth) + vUp * (gvPosAdds[i].y * fHalfHeight);
|
||||
cVector3f vStart = vStartCenter + vAdd;
|
||||
cVector3f vEnd = vEndCenter + vAdd;
|
||||
|
||||
mpRayCallback->Reset();
|
||||
mpRayCallback->mpCallback = apCallback;
|
||||
|
||||
pPhysicsWorld->CastRay(mpRayCallback, vStart, vEnd, false, false, false, true);
|
||||
|
||||
if (mpRayCallback->Intersected())
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cAINodeContainer::SaveToFile(const tString &asFile) {
|
||||
TiXmlDocument *pXmlDoc = hplNew(TiXmlDocument, (asFile.c_str()));
|
||||
|
||||
TiXmlElement *pRootElem = static_cast<TiXmlElement *>(pXmlDoc->InsertEndChild(TiXmlElement("AINodes")));
|
||||
|
||||
for (size_t i = 0; i < mvNodes.size(); ++i) {
|
||||
cAINode *pNode = mvNodes[i];
|
||||
TiXmlElement *pNodeElem = static_cast<TiXmlElement *>(pRootElem->InsertEndChild(TiXmlElement("Node")));
|
||||
|
||||
pNodeElem->SetAttribute("Name", pNode->GetName().c_str());
|
||||
|
||||
for (int edge = 0; edge < pNode->GetEdgeNum(); ++edge) {
|
||||
cAINodeEdge *pEdge = pNode->GetEdge(edge);
|
||||
TiXmlElement *pEdgeElem = static_cast<TiXmlElement *>(pNodeElem->InsertEndChild(TiXmlElement("Edge")));
|
||||
|
||||
pEdgeElem->SetAttribute("Node", pEdge->mpNode->GetName().c_str());
|
||||
tString sDistance = cString::ToString(pEdge->mfDistance);
|
||||
pEdgeElem->SetAttribute("Distance", sDistance.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
if (pXmlDoc->SaveFile() == false) {
|
||||
Error("Couldn't save XML file %s\n", asFile.c_str());
|
||||
}
|
||||
hplDelete(pXmlDoc);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cAINodeContainer::LoadFromFile(const tString &asFile) {
|
||||
BuildNodeGridMap();
|
||||
|
||||
TiXmlDocument *pXmlDoc = hplNew(TiXmlDocument, (asFile.c_str()));
|
||||
if (pXmlDoc->LoadFile() == false) {
|
||||
Warning("Couldn't open XML file %s\n", asFile.c_str());
|
||||
hplDelete(pXmlDoc);
|
||||
return;
|
||||
}
|
||||
|
||||
TiXmlElement *pRootElem = pXmlDoc->RootElement();
|
||||
|
||||
TiXmlElement *pNodeElem = pRootElem->FirstChildElement("Node");
|
||||
for (; pNodeElem != NULL; pNodeElem = pNodeElem->NextSiblingElement("Node")) {
|
||||
tString sName = cString::ToString(pNodeElem->Attribute("Name"), "");
|
||||
|
||||
cAINode *pNode = GetNodeFromName(sName);
|
||||
|
||||
TiXmlElement *pEdgeElem = pNodeElem->FirstChildElement("Edge");
|
||||
for (; pEdgeElem != NULL; pEdgeElem = pEdgeElem->NextSiblingElement("Edge")) {
|
||||
tString sNodeName = cString::ToString(pEdgeElem->Attribute("Node"), "");
|
||||
cAINode *pEdgeNode = GetNodeFromName(sNodeName);
|
||||
|
||||
cAINodeEdge Edge;
|
||||
Edge.mpNode = pEdgeNode;
|
||||
Edge.mfDistance = cString::ToFloat(pEdgeElem->Attribute("Distance"), 0);
|
||||
Edge.mfSqrDistance = Edge.mfDistance * Edge.mfDistance;
|
||||
|
||||
pNode->mvEdges.push_back(Edge);
|
||||
}
|
||||
}
|
||||
|
||||
hplDelete(pXmlDoc);
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PRIVATE METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cVector2l cAINodeContainer::GetGridPosFromLocal(const cVector2f &avLocalPos) {
|
||||
cVector2l vGridPos;
|
||||
vGridPos.x = (int)(avLocalPos.x / mvGridSize.x);
|
||||
vGridPos.y = (int)(avLocalPos.y / mvGridSize.y);
|
||||
|
||||
if (vGridPos.x < 0)
|
||||
vGridPos.x = 0;
|
||||
if (vGridPos.y < 0)
|
||||
vGridPos.y = 0;
|
||||
if (vGridPos.x > mvGridMapSize.x)
|
||||
vGridPos.x = mvGridMapSize.x;
|
||||
if (vGridPos.y > mvGridMapSize.y)
|
||||
vGridPos.y = mvGridMapSize.y;
|
||||
|
||||
return vGridPos;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cAIGridNode *cAINodeContainer::GetGrid(const cVector2l &avPos) {
|
||||
int lIndex = avPos.y * (mvGridMapSize.x + 1) + avPos.x;
|
||||
// Log(" index: %d Max: %d\n",lIndex,(int)mvGrids.size());
|
||||
|
||||
return &mvGrids[lIndex];
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
} // namespace hpl
|
||||
303
engines/hpl1/engine/ai/AINodeContainer.h
Normal file
303
engines/hpl1/engine/ai/AINodeContainer.h
Normal file
@@ -0,0 +1,303 @@
|
||||
/* 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_AI_NODE_CONTAINER_H
|
||||
#define HPL_AI_NODE_CONTAINER_H
|
||||
|
||||
#include "hpl1/engine/math/MathTypes.h"
|
||||
#include "hpl1/engine/system/SystemTypes.h"
|
||||
|
||||
#include "common/array.h"
|
||||
#include "common/list.h"
|
||||
#include "hpl1/engine/physics/PhysicsWorld.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class cWorld3D;
|
||||
|
||||
//--------------------------------
|
||||
|
||||
typedef tFlag tAIFreePathFlag;
|
||||
|
||||
#define eAIFreePathFlag_SkipStatic (0x00000001)
|
||||
#define eAIFreePathFlag_SkipDynamic (0x00000002)
|
||||
#define eAIFreePathFlag_SkipVolatile (0x00000004)
|
||||
|
||||
//--------------------------------
|
||||
class cAINode;
|
||||
|
||||
class cAINodeEdge {
|
||||
public:
|
||||
float mfDistance;
|
||||
float mfSqrDistance;
|
||||
cAINode *mpNode;
|
||||
};
|
||||
|
||||
typedef Common::Array<cAINodeEdge> tAINodeEdgeVec;
|
||||
typedef tAINodeEdgeVec::iterator tAINodeEdgeVecIt;
|
||||
|
||||
//--------------------------------
|
||||
|
||||
class cAINode {
|
||||
friend class cAINodeContainer;
|
||||
|
||||
public:
|
||||
cAINode();
|
||||
~cAINode();
|
||||
|
||||
void AddEdge(cAINode *pNode);
|
||||
|
||||
int GetEdgeNum() const { return (int)mvEdges.size(); }
|
||||
inline cAINodeEdge *GetEdge(int alIdx) { return &mvEdges[alIdx]; }
|
||||
|
||||
const cVector3f &GetPosition() { return mvPosition; }
|
||||
|
||||
const tString &GetName() { return msName; }
|
||||
|
||||
private:
|
||||
tString msName;
|
||||
cVector3f mvPosition;
|
||||
void *mpUserData;
|
||||
|
||||
tAINodeEdgeVec mvEdges;
|
||||
};
|
||||
|
||||
typedef Common::Array<cAINode *> tAINodeVec;
|
||||
typedef tAINodeVec::iterator tAINodeVecIt;
|
||||
|
||||
typedef Common::List<cAINode *> tAINodeList;
|
||||
typedef tAINodeList::iterator tAINodeListIt;
|
||||
|
||||
typedef Common::StableMap<tString, cAINode *> tAINodeMap;
|
||||
typedef tAINodeMap::iterator tAINodeMapIt;
|
||||
|
||||
//--------------------------------
|
||||
|
||||
class iAIFreePathCallback {
|
||||
public:
|
||||
virtual ~iAIFreePathCallback() = default;
|
||||
virtual bool Intersects(iPhysicsBody *pBody, cPhysicsRayParams *apParams) = 0;
|
||||
};
|
||||
|
||||
//--------------------------------
|
||||
|
||||
class cAINodeRayCallback : public iPhysicsRayCallback {
|
||||
public:
|
||||
void Reset();
|
||||
void SetFlags(tAIFreePathFlag aFlags) { mFlags = aFlags; }
|
||||
|
||||
bool BeforeIntersect(iPhysicsBody *pBody);
|
||||
bool OnIntersect(iPhysicsBody *pBody, cPhysicsRayParams *apParams);
|
||||
|
||||
bool Intersected();
|
||||
|
||||
iAIFreePathCallback *mpCallback;
|
||||
|
||||
private:
|
||||
bool mbIntersected;
|
||||
tAIFreePathFlag mFlags;
|
||||
};
|
||||
|
||||
//--------------------------------
|
||||
|
||||
class cAIGridNode {
|
||||
public:
|
||||
tAINodeList mlstNodes;
|
||||
};
|
||||
|
||||
//--------------------------------
|
||||
class cAINodeContainer;
|
||||
|
||||
class cAINodeIterator {
|
||||
public:
|
||||
cAINodeIterator(cAINodeContainer *apContainer, const cVector3f &avPos, float afRadius);
|
||||
|
||||
bool HasNext();
|
||||
cAINode *Next();
|
||||
|
||||
private:
|
||||
bool IncGridPos();
|
||||
|
||||
cAINodeContainer *mpContainer;
|
||||
cVector3f mvPosition;
|
||||
float mfRadius;
|
||||
cVector2l mvStartGridPos;
|
||||
cVector2l mvEndGridPos;
|
||||
cVector2l mvGridPos;
|
||||
|
||||
tAINodeList *mpNodeList;
|
||||
tAINodeListIt mNodeIt;
|
||||
};
|
||||
|
||||
//--------------------------------
|
||||
|
||||
class cAINodeContainer {
|
||||
friend class cAINodeIterator;
|
||||
|
||||
public:
|
||||
cAINodeContainer(const tString &asName, const tString &asNodeName,
|
||||
cWorld3D *apWorld, const cVector3f &avCollideSize);
|
||||
~cAINodeContainer();
|
||||
|
||||
const tString &GetNodeName() { return msNodeName; }
|
||||
const tString &GetName() { return msName; }
|
||||
|
||||
const cVector3f &GetCollideSize() { return mvSize; }
|
||||
|
||||
/**
|
||||
* Reserves spaces for nodes.
|
||||
* \param alReserveSpace Number of nodes to reserve space for.
|
||||
*/
|
||||
void ReserveSpace(size_t alReserveSpace);
|
||||
|
||||
/**
|
||||
* Adds a new node to the container.
|
||||
* \param &asName Name of the node
|
||||
* \param &avPosition Position of the node.
|
||||
* \param *apUserData Data supplied by user.
|
||||
*/
|
||||
void AddNode(const tString &asName, const cVector3f &avPosition, void *apUserData = NULL);
|
||||
|
||||
/**
|
||||
* Get the number of nodes.
|
||||
*/
|
||||
int GetNodeNum() const;
|
||||
|
||||
/**
|
||||
* Get a node.
|
||||
* \param alIdx index of node.
|
||||
*/
|
||||
inline cAINode *GetNode(int alIdx) { return mvNodes[alIdx]; }
|
||||
|
||||
/**
|
||||
* Gets a node based on the name.
|
||||
* \param &asName Name of the node.
|
||||
*/
|
||||
cAINode *GetNodeFromName(const tString &asName);
|
||||
|
||||
/**
|
||||
* Compile the added nodes.
|
||||
*/
|
||||
void Compile();
|
||||
|
||||
/**
|
||||
* Build a grid map for nodes. (Used internally mostly)
|
||||
*/
|
||||
void BuildNodeGridMap();
|
||||
|
||||
/**
|
||||
* Returns a node iterator. Note that the radius is not checked, some nodes may lie outside.
|
||||
* \param &avPosition
|
||||
* \param afRadius
|
||||
* \return
|
||||
*/
|
||||
cAINodeIterator GetNodeIterator(const cVector3f &avPosition, float afRadius);
|
||||
|
||||
/**
|
||||
* Checks for a free path using the containers collide size.
|
||||
* \param &avStart
|
||||
* \param &avEnd
|
||||
* \param alRayNum The max number of rays cast, -1 = maximum
|
||||
* \param alFlags Set Flags for the ray casting.
|
||||
* \param apCallback Check for every body and overrides alFlags.
|
||||
* \return
|
||||
*/
|
||||
bool FreePath(const cVector3f &avStart, const cVector3f &avEnd, int alRayNum = -1,
|
||||
tAIFreePathFlag aFlags = 0, iAIFreePathCallback *apCallback = NULL);
|
||||
|
||||
/**
|
||||
* Sets the max number of end node added to a node.
|
||||
* \param alX The max number, -1 = unlimited
|
||||
*/
|
||||
void SetMaxEdges(int alX) { mlMaxNodeEnds = alX; }
|
||||
|
||||
/**
|
||||
* Sets the min number of end node added to a node. This overrides max distance when needed.
|
||||
*/
|
||||
void SetMinEdges(int alX) { mlMinNodeEnds = alX; }
|
||||
|
||||
/**
|
||||
* Sets the max distance for an end node.
|
||||
* \param afX
|
||||
*/
|
||||
void SetMaxEdgeDistance(float afX) { mfMaxEndDistance = afX; }
|
||||
|
||||
float GetMaxEdgeDistance() const { return mfMaxEndDistance; }
|
||||
|
||||
void SetMaxHeight(float afX) { mfMaxHeight = afX; }
|
||||
float GetMaxHeight() const { return mfMaxHeight; }
|
||||
|
||||
/**
|
||||
* When calculating if there is a free path between two nodes. Is the node position the center of the collider.
|
||||
* If not the position is the feet position.
|
||||
*/
|
||||
void SetNodeIsAtCenter(bool abX) { mbNodeIsAtCenter = abX; }
|
||||
bool GetNodeIsAtCenter() { return mbNodeIsAtCenter; }
|
||||
|
||||
/**
|
||||
* Saves all the node connections to file.
|
||||
*/
|
||||
void SaveToFile(const tString &asFile);
|
||||
/**
|
||||
* Loads all node connections from file. Only to be done after all nodes are loaded.
|
||||
*/
|
||||
void LoadFromFile(const tString &asFile);
|
||||
|
||||
private:
|
||||
cVector2l GetGridPosFromLocal(const cVector2f &avLocalPos);
|
||||
cAIGridNode *GetGrid(const cVector2l &avPos);
|
||||
|
||||
tString msName;
|
||||
tString msNodeName;
|
||||
|
||||
cWorld3D *mpWorld;
|
||||
cVector3f mvSize;
|
||||
|
||||
cAINodeRayCallback *mpRayCallback;
|
||||
tAINodeVec mvNodes;
|
||||
tAINodeMap m_mapNodes;
|
||||
|
||||
bool mbNodeIsAtCenter;
|
||||
|
||||
cVector2l mvGridMapSize;
|
||||
cVector2f mvGridSize;
|
||||
cVector2f mvMinGridPos;
|
||||
cVector2f mvMaxGridPos;
|
||||
int mlNodesPerGrid;
|
||||
|
||||
Common::Array<cAIGridNode> mvGrids;
|
||||
|
||||
// properties
|
||||
int mlMaxNodeEnds;
|
||||
int mlMinNodeEnds;
|
||||
float mfMaxEndDistance;
|
||||
float mfMaxHeight;
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_AI_NODE_CONTAINER_H
|
||||
342
engines/hpl1/engine/ai/AINodeGenerator.cpp
Normal file
342
engines/hpl1/engine/ai/AINodeGenerator.cpp
Normal file
@@ -0,0 +1,342 @@
|
||||
/* 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/ai/AINodeGenerator.h"
|
||||
|
||||
#include "hpl1/engine/scene/World3D.h"
|
||||
|
||||
#include "hpl1/engine/system/String.h"
|
||||
#include "hpl1/engine/system/System.h"
|
||||
#include "hpl1/engine/system/low_level_system.h"
|
||||
|
||||
#include "hpl1/engine/resources/FileSearcher.h"
|
||||
#include "hpl1/engine/resources/Resources.h"
|
||||
|
||||
#include "hpl1/engine/physics/PhysicsBody.h"
|
||||
#include "hpl1/engine/physics/PhysicsWorld.h"
|
||||
|
||||
#include "hpl1/engine/impl/tinyXML/tinyxml.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PARAMS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cAINodeGeneratorParams::cAINodeGeneratorParams() {
|
||||
msNodeType = "node";
|
||||
|
||||
mfHeightFromGround = 0.1f;
|
||||
mfMinWallDist = 0.4f;
|
||||
|
||||
mvMinPos = cVector3f(-10000, -10000, -10000);
|
||||
mvMaxPos = cVector3f(10000, 10000, 10000);
|
||||
|
||||
mfGridSize = 0.4f;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cCollideRayCallback::OnIntersect(iPhysicsBody *pBody, cPhysicsRayParams *apParams) {
|
||||
if (pBody->GetMass() != 0)
|
||||
return true;
|
||||
|
||||
mbIntersected = true;
|
||||
mvPos = apParams->mvPoint;
|
||||
mfDist = apParams->mfDist;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
unsigned generatorInstances = 0;
|
||||
|
||||
cAINodeGenerator::cAINodeGenerator() {
|
||||
++generatorInstances;
|
||||
assert(generatorInstances == 1);
|
||||
}
|
||||
|
||||
cAINodeGenerator::~cAINodeGenerator() {
|
||||
--generatorInstances;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
// static cCollideRayCallback gCollideRayCallback;
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cAINodeGenerator::Generate(cWorld3D *apWorld, cAINodeGeneratorParams *apParams) {
|
||||
mpWorld = apWorld;
|
||||
mpParams = apParams;
|
||||
|
||||
iPhysicsWorld *pPhysicsWorld = apWorld->GetPhysicsWorld();
|
||||
|
||||
// bool mbLoadFromFile = false;
|
||||
|
||||
/*cSystem *pSystem = */ apWorld->GetSystem();
|
||||
cResources *pResources = apWorld->GetResources();
|
||||
cFileSearcher *pFileSearcher = pResources->GetFileSearcher();
|
||||
|
||||
mpNodeList = apWorld->GetAINodeList(mpParams->msNodeType);
|
||||
|
||||
if (mpWorld->GetFileName() != "") {
|
||||
tString sPath = pFileSearcher->GetFilePath(mpWorld->GetFileName());
|
||||
tWString sSaveFile = cString::To16Char(cString::SetFileExt(sPath, "ainodes"));
|
||||
|
||||
if (sPath != "" && FileExists(sSaveFile)) {
|
||||
cDate mapDate = FileModifiedDate(cString::To16Char(sPath));
|
||||
cDate saveDate = FileModifiedDate(sSaveFile);
|
||||
|
||||
// If the save file is newer than the map load from it.
|
||||
if (saveDate > mapDate) {
|
||||
LoadFromFile();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////
|
||||
// Get the size of the world
|
||||
cPhysicsBodyIterator it = pPhysicsWorld->GetBodyIterator();
|
||||
cVector3f vWorldMax(-100000, -100000, -100000);
|
||||
cVector3f vWorldMin(100000, 100000, 100000);
|
||||
|
||||
while (it.HasNext()) {
|
||||
iPhysicsBody *pBody = it.Next();
|
||||
|
||||
cVector3f vMin = pBody->GetBV()->GetMin();
|
||||
cVector3f vMax = pBody->GetBV()->GetMax();
|
||||
|
||||
// X
|
||||
if (vWorldMin.x > vMin.x)
|
||||
vWorldMin.x = vMin.x;
|
||||
if (vWorldMax.x < vMax.x)
|
||||
vWorldMax.x = vMax.x;
|
||||
|
||||
// Y
|
||||
if (vWorldMin.y > vMin.y)
|
||||
vWorldMin.y = vMin.y;
|
||||
if (vWorldMax.y < vMax.y)
|
||||
vWorldMax.y = vMax.y;
|
||||
|
||||
// Z
|
||||
if (vWorldMin.z > vMin.z)
|
||||
vWorldMin.z = vMin.z;
|
||||
if (vWorldMax.z < vMax.z)
|
||||
vWorldMax.z = vMax.z;
|
||||
}
|
||||
|
||||
// Make the world small according to grid size.
|
||||
vWorldMin.x += mpParams->mfGridSize;
|
||||
vWorldMin.z += mpParams->mfGridSize;
|
||||
vWorldMax.x -= mpParams->mfGridSize;
|
||||
vWorldMax.z -= mpParams->mfGridSize;
|
||||
|
||||
/////////////////////////////////////////
|
||||
// Check against the user set min and max
|
||||
if (vWorldMin.x < mpParams->mvMinPos.x)
|
||||
vWorldMin.x = mpParams->mvMinPos.x;
|
||||
if (vWorldMax.x > mpParams->mvMaxPos.x)
|
||||
vWorldMax.x = mpParams->mvMaxPos.x;
|
||||
|
||||
if (vWorldMin.y < mpParams->mvMinPos.y)
|
||||
vWorldMin.y = mpParams->mvMinPos.y;
|
||||
if (vWorldMax.y > mpParams->mvMaxPos.y)
|
||||
vWorldMax.y = mpParams->mvMaxPos.y;
|
||||
|
||||
if (vWorldMin.z < mpParams->mvMinPos.z)
|
||||
vWorldMin.z = mpParams->mvMinPos.z;
|
||||
if (vWorldMax.z > mpParams->mvMaxPos.z)
|
||||
vWorldMax.z = mpParams->mvMaxPos.z;
|
||||
|
||||
/////////////////////////////////////////
|
||||
// Place the nodes in the world
|
||||
cVector3f vPos(vWorldMin.x, 0, vWorldMin.z);
|
||||
|
||||
while (vPos.z <= vWorldMax.z) {
|
||||
cVector3f vStart(vPos.x, vWorldMax.y, vPos.z);
|
||||
cVector3f vEnd(vPos.x, vWorldMin.y, vPos.z);
|
||||
|
||||
pPhysicsWorld->CastRay(this, vStart, vEnd, false, false, true);
|
||||
|
||||
// Log("Pos: %s Min: %s Max: %s\n",vPos.ToString().c_str(),
|
||||
// vWorldMin.ToString().c_str(),
|
||||
// vWorldMax.ToString().c_str());
|
||||
|
||||
vPos.x += apParams->mfGridSize;
|
||||
if (vPos.x > vWorldMax.x) {
|
||||
vPos.x = vWorldMin.x;
|
||||
vPos.z += apParams->mfGridSize;
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////
|
||||
// Check so that the nodes are not too close to walls
|
||||
cVector3f vEnds[4] = {cVector3f(mpParams->mfMinWallDist, 0, 0),
|
||||
cVector3f(-mpParams->mfMinWallDist, 0, 0),
|
||||
cVector3f(0, 0, mpParams->mfMinWallDist),
|
||||
cVector3f(0, 0, -mpParams->mfMinWallDist)};
|
||||
|
||||
cVector3f vPushBackDirs[4] = {cVector3f(-1, 0, 0),
|
||||
cVector3f(1, 0, 0),
|
||||
cVector3f(0, 0, -1),
|
||||
cVector3f(0, 0, 1)};
|
||||
|
||||
tTempAiNodeListIt nodeIt = mpNodeList->begin();
|
||||
for (; nodeIt != mpNodeList->end(); ++nodeIt) {
|
||||
cTempAiNode &Node = *nodeIt;
|
||||
|
||||
// Check if there are any walls close by.
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
_rayCallback.mbIntersected = false;
|
||||
pPhysicsWorld->CastRay(&_rayCallback, Node.mvPos, Node.mvPos + vEnds[i], true, false, true);
|
||||
|
||||
if (_rayCallback.mbIntersected) {
|
||||
// Log("Walldistance %f : Add: (%s) Push (%s) Min: %f\n",gCollideRayCallback.mfDist,
|
||||
// vEnds[i].ToString().c_str(),
|
||||
// vPushBackDirs[i].ToString().c_str(),
|
||||
// mpParams->mfMinWallDist);
|
||||
if (_rayCallback.mfDist < mpParams->mfMinWallDist) {
|
||||
Node.mvPos += vPushBackDirs[i] * (mpParams->mfMinWallDist - _rayCallback.mfDist);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////
|
||||
// Save to file
|
||||
|
||||
SaveToFile();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PRIVATE
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cAINodeGenerator::OnIntersect(iPhysicsBody *pBody, cPhysicsRayParams *apParams) {
|
||||
if (pBody->GetMass() != 0)
|
||||
return true;
|
||||
|
||||
/*iPhysicsWorld *pPhysicsWorld = */ mpWorld->GetPhysicsWorld();
|
||||
|
||||
cVector3f vPosition = apParams->mvPoint + cVector3f(0, mpParams->mfHeightFromGround, 0);
|
||||
|
||||
mpNodeList->push_back(cTempAiNode(vPosition, ""));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cAINodeGenerator::SaveToFile() {
|
||||
if (mpWorld->GetFileName() == "")
|
||||
return;
|
||||
|
||||
/*cSystem *pSystem = */ mpWorld->GetSystem();
|
||||
cResources *pResources = mpWorld->GetResources();
|
||||
cFileSearcher *pFileSearcher = pResources->GetFileSearcher();
|
||||
|
||||
tString sMapPath = pFileSearcher->GetFilePath(mpWorld->GetFileName());
|
||||
tString sSaveFile = cString::SetFileExt(sMapPath, "ainodes");
|
||||
|
||||
TiXmlDocument *pXmlDoc = hplNew(TiXmlDocument, (sSaveFile.c_str()));
|
||||
|
||||
TiXmlElement *pRootElem = static_cast<TiXmlElement *>(pXmlDoc->InsertEndChild(TiXmlElement("AiNodes")));
|
||||
|
||||
tTempAiNodeListIt nodeIt = mpNodeList->begin();
|
||||
for (; nodeIt != mpNodeList->end(); ++nodeIt) {
|
||||
cTempAiNode &Node = *nodeIt;
|
||||
TiXmlElement *pNodeElem = static_cast<TiXmlElement *>(pRootElem->InsertEndChild(TiXmlElement("Node")));
|
||||
|
||||
tString sPos = cString::ToString(Node.mvPos.x) + " " +
|
||||
cString::ToString(Node.mvPos.y) + " " +
|
||||
cString::ToString(Node.mvPos.z);
|
||||
pNodeElem->SetAttribute("Pos", sPos.c_str());
|
||||
pNodeElem->SetAttribute("Name", Node.msName.c_str());
|
||||
}
|
||||
|
||||
if (pXmlDoc->SaveFile() == false) {
|
||||
Error("Couldn't save XML file %s\n", sSaveFile.c_str());
|
||||
}
|
||||
hplDelete(pXmlDoc);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cAINodeGenerator::LoadFromFile() {
|
||||
if (mpWorld->GetFileName() == "")
|
||||
return;
|
||||
|
||||
/*cSystem *pSystem = */ mpWorld->GetSystem();
|
||||
cResources *pResources = mpWorld->GetResources();
|
||||
cFileSearcher *pFileSearcher = pResources->GetFileSearcher();
|
||||
|
||||
tString sMapPath = pFileSearcher->GetFilePath(mpWorld->GetFileName());
|
||||
tString sSaveFile = cString::SetFileExt(sMapPath, "ainodes");
|
||||
|
||||
TiXmlDocument *pXmlDoc = hplNew(TiXmlDocument, (sSaveFile.c_str()));
|
||||
if (pXmlDoc->LoadFile() == false) {
|
||||
Warning("Couldn't open XML file %s\n", sSaveFile.c_str());
|
||||
hplDelete(pXmlDoc);
|
||||
return;
|
||||
}
|
||||
|
||||
TiXmlElement *pRootElem = pXmlDoc->RootElement();
|
||||
|
||||
TiXmlElement *pNodeElem = pRootElem->FirstChildElement("Node");
|
||||
for (; pNodeElem != NULL; pNodeElem = pNodeElem->NextSiblingElement("Node")) {
|
||||
cVector3f vPos = cString::ToVector3f(pNodeElem->Attribute("Pos"), 0);
|
||||
tString sName = cString::ToString(pNodeElem->Attribute("Name"), "");
|
||||
|
||||
mpNodeList->push_back(cTempAiNode(vPos, sName));
|
||||
}
|
||||
|
||||
hplDelete(pXmlDoc);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
} // namespace hpl
|
||||
91
engines/hpl1/engine/ai/AINodeGenerator.h
Normal file
91
engines/hpl1/engine/ai/AINodeGenerator.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_AI_NODE_GENERATOR_H
|
||||
#define HPL_AI_NODE_GENERATOR_H
|
||||
|
||||
#include "hpl1/engine/game/GameTypes.h"
|
||||
#include "hpl1/engine/system/SystemTypes.h"
|
||||
|
||||
#include "hpl1/engine/physics/PhysicsWorld.h"
|
||||
#include "hpl1/engine/scene/World3D.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class cWorld3D;
|
||||
|
||||
class cCollideRayCallback : public iPhysicsRayCallback {
|
||||
public:
|
||||
virtual ~cCollideRayCallback() {}
|
||||
bool OnIntersect(iPhysicsBody *pBody, cPhysicsRayParams *apParams);
|
||||
|
||||
bool mbIntersected;
|
||||
cVector3f mvPos;
|
||||
float mfDist;
|
||||
};
|
||||
|
||||
//-------------------------------
|
||||
|
||||
class cAINodeGeneratorParams {
|
||||
public:
|
||||
cAINodeGeneratorParams();
|
||||
|
||||
tString msNodeType;
|
||||
|
||||
float mfHeightFromGround;
|
||||
float mfMinWallDist;
|
||||
|
||||
cVector3f mvMinPos;
|
||||
cVector3f mvMaxPos;
|
||||
|
||||
float mfGridSize;
|
||||
};
|
||||
|
||||
//-------------------------------
|
||||
|
||||
class cAINodeGenerator : public iPhysicsRayCallback {
|
||||
public:
|
||||
cAINodeGenerator();
|
||||
virtual ~cAINodeGenerator();
|
||||
|
||||
void Generate(cWorld3D *apWorld, cAINodeGeneratorParams *apParams);
|
||||
|
||||
private:
|
||||
bool OnIntersect(iPhysicsBody *pBody, cPhysicsRayParams *apParams);
|
||||
|
||||
void SaveToFile();
|
||||
void LoadFromFile();
|
||||
|
||||
cAINodeGeneratorParams *mpParams;
|
||||
cWorld3D *mpWorld;
|
||||
tTempAiNodeList *mpNodeList;
|
||||
cCollideRayCallback _rayCallback;
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_AI_NODE_GENERATOR_H
|
||||
323
engines/hpl1/engine/ai/AStar.cpp
Normal file
323
engines/hpl1/engine/ai/AStar.cpp
Normal file
@@ -0,0 +1,323 @@
|
||||
/* 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/ai/AStar.h"
|
||||
|
||||
#include "hpl1/engine/ai/AINodeContainer.h"
|
||||
|
||||
#include "hpl1/engine/math/Math.h"
|
||||
|
||||
#include "hpl1/engine/system/low_level_system.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// NODE
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cAStarNode::cAStarNode(cAINode *apAINode) {
|
||||
mpParent = NULL;
|
||||
mpAINode = apAINode;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cAStarNodeCompare::operator()(cAStarNode *apNodeA, cAStarNode *apNodeB) const {
|
||||
return apNodeA->mpAINode < apNodeB->mpAINode;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cAStarHandler::cAStarHandler(cAINodeContainer *apContainer) {
|
||||
mlMaxIterations = -1;
|
||||
|
||||
mpContainer = apContainer;
|
||||
|
||||
mpCallback = NULL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cAStarHandler::~cAStarHandler() {
|
||||
STLDeleteAll(m_setClosedList);
|
||||
STLDeleteAll(m_setOpenList);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cAStarHandler::GetPath(const cVector3f &avStart, const cVector3f &avGoal, tAINodeList *apNodeList) {
|
||||
/////////////////////////////////////////////////
|
||||
// check if there is free path from start to goal
|
||||
if (mpContainer->FreePath(avStart, avGoal, 3)) {
|
||||
mpGoalNode = NULL;
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Reset all variables
|
||||
// These should just be cleared and pools used instead.
|
||||
STLDeleteAll(m_setClosedList);
|
||||
STLDeleteAll(m_setOpenList);
|
||||
m_setGoalNodes.clear();
|
||||
mpGoalNode = NULL;
|
||||
|
||||
// Set goal position
|
||||
mvGoal = avGoal;
|
||||
|
||||
float fMaxHeight = mpContainer->GetMaxHeight() * 1.5f;
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Find nodes reachable from the start and goal position (use double 2*2 distance)
|
||||
float fMaxDist = mpContainer->GetMaxEdgeDistance() * 2; // float fMaxDist = mpContainer->GetMaxEdgeDistance()*mpContainer->GetMaxEdgeDistance()*4;
|
||||
|
||||
/////////////////////
|
||||
// Check with Start
|
||||
// Log(" Get Start\n");
|
||||
cAINodeIterator startNodeIt = mpContainer->GetNodeIterator(avStart, fMaxDist);
|
||||
while (startNodeIt.HasNext()) {
|
||||
cAINode *pAINode = startNodeIt.Next();
|
||||
// Log("Check node: %s\n",pAINode->GetName().c_str());
|
||||
|
||||
float fHeight = fabs(avStart.y - pAINode->GetPosition().y);
|
||||
float fDist = cMath::Vector3Dist(avStart, pAINode->GetPosition()); // float fDist = cMath::Vector3DistSqr(avStart,pAINode->GetPosition());
|
||||
if (fDist < fMaxDist && fHeight <= fMaxHeight) {
|
||||
// Check if path is clear
|
||||
if (mpContainer->FreePath(avStart, pAINode->GetPosition(), -1,
|
||||
eAIFreePathFlag_SkipDynamic)) {
|
||||
AddOpenNode(pAINode, NULL, fDist);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Log(" Found start\n");
|
||||
|
||||
////////////////////////////////
|
||||
// Check with Goal
|
||||
// Log(" Get Goal\n");
|
||||
cAINodeIterator goalNodeIt = mpContainer->GetNodeIterator(avGoal, fMaxDist);
|
||||
while (goalNodeIt.HasNext()) {
|
||||
cAINode *pAINode = goalNodeIt.Next();
|
||||
// Log("Check node: %s\n",pAINode->GetName().c_str());
|
||||
|
||||
float fHeight = fabs(avGoal.y - pAINode->GetPosition().y);
|
||||
float fDist = cMath::Vector3Dist(avGoal, pAINode->GetPosition()); // fDist = cMath::Vector3DistSqr(avGoal,pAINode->GetPosition());
|
||||
if (fDist < fMaxDist && fHeight <= fMaxHeight) {
|
||||
// Check if path is clear
|
||||
if (mpContainer->FreePath(avGoal, pAINode->GetPosition(), 3)) {
|
||||
m_setGoalNodes.insert(pAINode);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Log(" Found goal\n");
|
||||
|
||||
/*for(int i=0; i<mpContainer->GetNodeNum(); ++i)
|
||||
{
|
||||
cAINode *pAINode = mpContainer->GetNode(i);
|
||||
|
||||
////////////////////////////////
|
||||
//Check with Start
|
||||
float fHeight = fabs(avStart.y - pAINode->GetPosition().y);
|
||||
float fDist = cMath::Vector3Dist(avStart,pAINode->GetPosition());
|
||||
//float fDist = cMath::Vector3DistSqr(avStart,pAINode->GetPosition());
|
||||
if(fDist < fMaxDist && fHeight <= fMaxHeight)
|
||||
{
|
||||
//Check if path is clear
|
||||
if(mpContainer->FreePath(avStart,pAINode->GetPosition(),-1))
|
||||
{
|
||||
AddOpenNode(pAINode,NULL,fDist);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
//Check with Goal
|
||||
fHeight = fabs(avGoal.y - pAINode->GetPosition().y);
|
||||
fDist = cMath::Vector3Dist(avGoal,pAINode->GetPosition());
|
||||
//fDist = cMath::Vector3DistSqr(avGoal,pAINode->GetPosition());
|
||||
if(fDist < fMaxDist && fHeight <= fMaxHeight)
|
||||
{
|
||||
//Check if path is clear
|
||||
if(mpContainer->FreePath(avGoal,pAINode->GetPosition(),3))
|
||||
{
|
||||
m_setGoalNodes.insert(pAINode);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Iterate the algorithm
|
||||
IterateAlgorithm();
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// Check if goal was found, if so build path.
|
||||
if (mpGoalNode) {
|
||||
if (apNodeList) {
|
||||
cAStarNode *pParentNode = mpGoalNode;
|
||||
while (pParentNode != NULL) {
|
||||
apNodeList->push_back(pParentNode->mpAINode);
|
||||
pParentNode = pParentNode->mpParent;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PRIVATE METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cAStarHandler::IterateAlgorithm() {
|
||||
int lIterationCount = 0;
|
||||
while (m_setOpenList.empty() == false && (mlMaxIterations < 0 || lIterationCount < mlMaxIterations)) {
|
||||
cAStarNode *pNode = GetBestNode();
|
||||
cAINode *pAINode = pNode->mpAINode;
|
||||
|
||||
//////////////////////
|
||||
// Check if current node can reach goal
|
||||
if (IsGoalNode(pAINode)) {
|
||||
mpGoalNode = pNode;
|
||||
break;
|
||||
}
|
||||
|
||||
/////////////////////
|
||||
// Add nodes connected to current
|
||||
int lEdgeCount = pAINode->GetEdgeNum();
|
||||
for (int i = 0; i < lEdgeCount; ++i) {
|
||||
cAINodeEdge *pEdge = pAINode->GetEdge(i);
|
||||
|
||||
if (mpCallback == NULL || mpCallback->CanAddNode(pAINode, pEdge->mpNode)) {
|
||||
AddOpenNode(pEdge->mpNode, pNode, pNode->mfDistance + pEdge->mfDistance);
|
||||
// AddOpenNode(pEdge->mpNode, pNode, pNode->mfDistance + pEdge->mfSqrDistance);
|
||||
}
|
||||
}
|
||||
|
||||
++lIterationCount;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cAStarHandler::AddOpenNode(cAINode *apAINode, cAStarNode *apParent, float afDistance) {
|
||||
// TODO: free path check with dynamic objects here.
|
||||
|
||||
// TODO: Some pooling here would be good.
|
||||
cAStarNode *pNode = hplNew(cAStarNode, (apAINode));
|
||||
|
||||
// Check if it is in closed list.
|
||||
tAStarNodeSetIt it = m_setClosedList.find(pNode);
|
||||
if (it != m_setClosedList.end()) {
|
||||
hplDelete(pNode);
|
||||
return;
|
||||
}
|
||||
|
||||
// Add it if it wasn't already inserted
|
||||
const auto test = m_setOpenList.find(pNode);
|
||||
if (test != m_setOpenList.end()) {
|
||||
hplDelete(pNode);
|
||||
return;
|
||||
}
|
||||
m_setOpenList.insert(pNode);
|
||||
|
||||
pNode->mfDistance = afDistance;
|
||||
pNode->mfCost = Cost(afDistance, apAINode, apParent) + Heuristic(pNode->mpAINode->GetPosition(), mvGoal);
|
||||
pNode->mpParent = apParent;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cAStarNode *cAStarHandler::GetBestNode() {
|
||||
tAStarNodeSetIt it = m_setOpenList.begin();
|
||||
tAStarNodeSetIt bestIt = it;
|
||||
cAStarNode *pBestNode = *it;
|
||||
++it;
|
||||
|
||||
// Iterate open list and find the best node.
|
||||
for (; it != m_setOpenList.end(); ++it) {
|
||||
cAStarNode *pNode = *it;
|
||||
if (pBestNode->mfCost > pNode->mfCost) {
|
||||
pBestNode = pNode;
|
||||
bestIt = it;
|
||||
}
|
||||
}
|
||||
|
||||
// Remove node from open
|
||||
m_setOpenList.erase(bestIt);
|
||||
|
||||
// Add to closed list
|
||||
m_setClosedList.insert(pBestNode);
|
||||
|
||||
return pBestNode;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
float cAStarHandler::Cost(float afDistance, cAINode *apAINode, cAStarNode *apParent) {
|
||||
if (apParent) {
|
||||
float fHeight = (1 + fabs(apAINode->GetPosition().y - apParent->mpAINode->GetPosition().y));
|
||||
return afDistance * fHeight;
|
||||
} else
|
||||
return afDistance;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
float cAStarHandler::Heuristic(const cVector3f &avStart, const cVector3f &avGoal) {
|
||||
// return cMath::Vector3DistSqr(avStart, avGoal);
|
||||
return cMath::Vector3Dist(avStart, avGoal);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cAStarHandler::IsGoalNode(cAINode *apAINode) {
|
||||
tAINodeSetIt it = m_setGoalNodes.find(apAINode);
|
||||
if (it == m_setGoalNodes.end())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
} // namespace hpl
|
||||
128
engines/hpl1/engine/ai/AStar.h
Normal file
128
engines/hpl1/engine/ai/AStar.h
Normal file
@@ -0,0 +1,128 @@
|
||||
/* 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_A_STAR_H
|
||||
#define HPL_A_STAR_H
|
||||
|
||||
#include "common/list.h"
|
||||
#include "hpl1/engine/game/GameTypes.h"
|
||||
#include "hpl1/engine/math/MathTypes.h"
|
||||
#include "hpl1/engine/system/SystemTypes.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class cAINodeContainer;
|
||||
class cAINode;
|
||||
|
||||
//--------------------------------------
|
||||
|
||||
typedef Hpl1::Std::set<cAINode *> tAINodeSet;
|
||||
typedef tAINodeSet::iterator tAINodeSetIt;
|
||||
|
||||
//--------------------------------------
|
||||
|
||||
typedef Common::List<cAINode *> tAINodeList;
|
||||
typedef tAINodeList::iterator tAINodeListIt;
|
||||
|
||||
//--------------------------------------
|
||||
|
||||
class cAStarNode {
|
||||
public:
|
||||
cAStarNode(cAINode *apAINode);
|
||||
|
||||
float mfCost;
|
||||
float mfDistance;
|
||||
|
||||
cAStarNode *mpParent;
|
||||
cAINode *mpAINode;
|
||||
};
|
||||
|
||||
class cAStarNodeCompare {
|
||||
public:
|
||||
bool operator()(cAStarNode *apNodeA, cAStarNode *apNodeB) const;
|
||||
};
|
||||
|
||||
typedef Hpl1::Std::set<cAStarNode *, cAStarNodeCompare> tAStarNodeSet;
|
||||
typedef tAStarNodeSet::iterator tAStarNodeSetIt;
|
||||
|
||||
//--------------------------------------
|
||||
class cAStarHandler;
|
||||
|
||||
class iAStarCallback {
|
||||
public:
|
||||
virtual ~iAStarCallback() {}
|
||||
|
||||
virtual bool CanAddNode(cAINode *apParentNode, cAINode *apChildNode) = 0;
|
||||
};
|
||||
|
||||
//--------------------------------------
|
||||
|
||||
class cAStarHandler {
|
||||
public:
|
||||
cAStarHandler(cAINodeContainer *apContainer);
|
||||
~cAStarHandler();
|
||||
|
||||
bool GetPath(const cVector3f &avStart, const cVector3f &avGoal, tAINodeList *apNodeList);
|
||||
|
||||
/**
|
||||
* Set max number of times the algorithm is iterated.
|
||||
* \param alX -1 = until OpenList is empty
|
||||
*/
|
||||
void SetMaxIterations(int alX) { mlMaxIterations = alX; }
|
||||
|
||||
void SetCallback(iAStarCallback *apCallback) { mpCallback = apCallback; }
|
||||
|
||||
private:
|
||||
void IterateAlgorithm();
|
||||
|
||||
void AddOpenNode(cAINode *apAINode, cAStarNode *apParent, float afDistance);
|
||||
|
||||
cAStarNode *GetBestNode();
|
||||
|
||||
float Cost(float afDistance, cAINode *apAINode, cAStarNode *apParent);
|
||||
float Heuristic(const cVector3f &avStart, const cVector3f &avGoal);
|
||||
|
||||
bool IsGoalNode(cAINode *apAINode);
|
||||
|
||||
cVector3f mvGoal;
|
||||
|
||||
cAStarNode *mpGoalNode;
|
||||
tAINodeSet m_setGoalNodes;
|
||||
|
||||
cAINodeContainer *mpContainer;
|
||||
|
||||
int mlMaxIterations;
|
||||
|
||||
iAStarCallback *mpCallback;
|
||||
|
||||
tAStarNodeSet m_setOpenList;
|
||||
tAStarNodeSet m_setClosedList;
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_A_STAR_H
|
||||
143
engines/hpl1/engine/ai/StateMachine.cpp
Normal file
143
engines/hpl1/engine/ai/StateMachine.cpp
Normal file
@@ -0,0 +1,143 @@
|
||||
/* 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/ai/StateMachine.h"
|
||||
|
||||
#include "hpl1/engine/system/low_level_system.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// STATE
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iAIState::iAIState() {
|
||||
mfTimeCount = 0;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void iAIState::Sleep(float afTime) {
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void iAIState::Update(float afTime) {
|
||||
// Update according to the time step
|
||||
mfTimeCount += afTime;
|
||||
while (mfTimeCount >= mfUpdateStep) {
|
||||
OnUpdate(mfUpdateStep);
|
||||
mfTimeCount -= mfUpdateStep;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cStateMachine::cStateMachine() {
|
||||
mbActive = true;
|
||||
|
||||
mpCurrentState = NULL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cStateMachine::~cStateMachine() {
|
||||
STLMapDeleteAll(m_mapStates);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cStateMachine::Update(float afTime) {
|
||||
if (mbActive == false || mpCurrentState == NULL)
|
||||
return;
|
||||
|
||||
mpCurrentState->Update(afTime);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cStateMachine::AddState(iAIState *apState, const tString &asName, int alId, float afUpdateStep) {
|
||||
apState->SetStateMachine(this);
|
||||
apState->mlId = alId;
|
||||
apState->msName = asName;
|
||||
apState->mfUpdateStep = afUpdateStep;
|
||||
|
||||
if (m_mapStates.empty())
|
||||
mpCurrentState = apState;
|
||||
|
||||
m_mapStates.insert(tAIStateMap::value_type(alId, apState));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cStateMachine::ChangeState(int alId) {
|
||||
if (alId == mpCurrentState->GetId())
|
||||
return;
|
||||
|
||||
iAIState *pState = GetState(alId);
|
||||
if (pState == NULL) {
|
||||
Warning("State %d does not exist!\n", alId);
|
||||
return;
|
||||
}
|
||||
|
||||
mpCurrentState->OnLeaveState(pState->GetId());
|
||||
pState->OnEnterState(mpCurrentState == NULL ? -1 : mpCurrentState->GetId());
|
||||
|
||||
mpCurrentState = pState;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iAIState *cStateMachine::GetState(int alId) {
|
||||
tAIStateMapIt it = m_mapStates.find(alId);
|
||||
if (it == m_mapStates.end())
|
||||
return NULL;
|
||||
|
||||
return it->second;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iAIState *cStateMachine::CurrentState() {
|
||||
return mpCurrentState;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
} // namespace hpl
|
||||
108
engines/hpl1/engine/ai/StateMachine.h
Normal file
108
engines/hpl1/engine/ai/StateMachine.h
Normal file
@@ -0,0 +1,108 @@
|
||||
/* 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_STATE_MACHINE_H
|
||||
#define HPL_STATE_MACHINE_H
|
||||
|
||||
#include "hpl1/engine/game/GameTypes.h"
|
||||
#include "hpl1/engine/system/SystemTypes.h"
|
||||
|
||||
#include "common/stablemap.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//-----------------------------------------
|
||||
class cStateMachine;
|
||||
|
||||
class iAIState {
|
||||
friend class cStateMachine;
|
||||
|
||||
public:
|
||||
iAIState();
|
||||
virtual ~iAIState() {}
|
||||
|
||||
virtual void OnUpdate(float afTime) = 0;
|
||||
|
||||
virtual void OnEnterState(int alLastState) = 0;
|
||||
virtual void OnLeaveState(int alNextState) = 0;
|
||||
|
||||
int GetId() { return mlId; }
|
||||
const tString &GetName() { return msName; }
|
||||
float GetUpdateStep() { return mfUpdateStep; }
|
||||
|
||||
void Sleep(float afTime);
|
||||
|
||||
protected:
|
||||
int mlId;
|
||||
tString msName;
|
||||
float mfUpdateStep;
|
||||
cStateMachine *mpStateMachine;
|
||||
|
||||
private:
|
||||
void Update(float afTime);
|
||||
void SetStateMachine(cStateMachine *apStateMachine) { mpStateMachine = apStateMachine; }
|
||||
|
||||
float mfTimeCount;
|
||||
};
|
||||
|
||||
typedef Common::StableMap<int, iAIState *> tAIStateMap;
|
||||
typedef tAIStateMap::iterator tAIStateMapIt;
|
||||
|
||||
//-----------------------------------------
|
||||
|
||||
class cStateMachine {
|
||||
public:
|
||||
cStateMachine();
|
||||
virtual ~cStateMachine();
|
||||
|
||||
void Update(float afTime);
|
||||
|
||||
/**
|
||||
* Adds a new state to the state machine. The state machine will destroy them when deleted.
|
||||
*/
|
||||
void AddState(iAIState *apState, const tString &asName, int alId, float afUpdateStep);
|
||||
|
||||
void ChangeState(int alId);
|
||||
|
||||
void SetActive(bool abX) { mbActive = abX; }
|
||||
bool IsActive() { return mbActive; }
|
||||
|
||||
iAIState *GetState(int alId);
|
||||
|
||||
iAIState *CurrentState();
|
||||
|
||||
private:
|
||||
bool mbActive;
|
||||
|
||||
tAIStateMap m_mapStates;
|
||||
|
||||
iAIState *mpCurrentState;
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_STATE_MACHINE_H
|
||||
247
engines/hpl1/engine/engine.h
Normal file
247
engines/hpl1/engine/engine.h
Normal file
@@ -0,0 +1,247 @@
|
||||
/* 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef HPL1_ENGINE_H
|
||||
#define HPL1_ENGINE_H
|
||||
|
||||
#include "hpl1/engine/ai/AI.h"
|
||||
#include "hpl1/engine/ai/AINodeContainer.h"
|
||||
#include "hpl1/engine/ai/AINodeGenerator.h"
|
||||
#include "hpl1/engine/ai/AStar.h"
|
||||
#include "hpl1/engine/ai/StateMachine.h"
|
||||
#include "hpl1/engine/game/Game.h"
|
||||
#include "hpl1/engine/game/GameTypes.h"
|
||||
#include "hpl1/engine/game/SaveGame.h"
|
||||
#include "hpl1/engine/game/ScriptFuncs.h"
|
||||
#include "hpl1/engine/game/Updateable.h"
|
||||
#include "hpl1/engine/game/Updater.h"
|
||||
#include "hpl1/engine/game/low_level_game_setup.h"
|
||||
#include "hpl1/engine/graphics/Animation.h"
|
||||
#include "hpl1/engine/graphics/AnimationTrack.h"
|
||||
#include "hpl1/engine/graphics/BackgroundImage.h"
|
||||
#include "hpl1/engine/graphics/Beam.h"
|
||||
#include "hpl1/engine/graphics/BillBoard.h"
|
||||
#include "hpl1/engine/graphics/Bone.h"
|
||||
#include "hpl1/engine/graphics/BoneState.h"
|
||||
#include "hpl1/engine/graphics/Color.h"
|
||||
#include "hpl1/engine/graphics/GPUProgram.h"
|
||||
#include "hpl1/engine/graphics/GfxObject.h"
|
||||
#include "hpl1/engine/graphics/Graphics.h"
|
||||
#include "hpl1/engine/graphics/GraphicsDrawer.h"
|
||||
#include "hpl1/engine/graphics/GraphicsTypes.h"
|
||||
#include "hpl1/engine/graphics/ImageEntityData.h"
|
||||
#include "hpl1/engine/graphics/LowLevelGraphics.h"
|
||||
#include "hpl1/engine/graphics/LowLevelPicture.h"
|
||||
#include "hpl1/engine/graphics/Material.h"
|
||||
#include "hpl1/engine/graphics/MaterialHandler.h"
|
||||
#include "hpl1/engine/graphics/Material_Additive.h"
|
||||
#include "hpl1/engine/graphics/Material_Alpha.h"
|
||||
#include "hpl1/engine/graphics/Material_BaseLight.h"
|
||||
#include "hpl1/engine/graphics/Material_Bump.h"
|
||||
#include "hpl1/engine/graphics/Material_BumpColorSpec.h"
|
||||
#include "hpl1/engine/graphics/Material_BumpSpec.h"
|
||||
#include "hpl1/engine/graphics/Material_BumpSpec2D.h"
|
||||
#include "hpl1/engine/graphics/Material_Diffuse.h"
|
||||
#include "hpl1/engine/graphics/Material_Diffuse2D.h"
|
||||
#include "hpl1/engine/graphics/Material_DiffuseAdditive2D.h"
|
||||
#include "hpl1/engine/graphics/Material_DiffuseAlpha2D.h"
|
||||
#include "hpl1/engine/graphics/Material_DiffuseSpec.h"
|
||||
#include "hpl1/engine/graphics/Material_EnvMap_Reflect.h"
|
||||
#include "hpl1/engine/graphics/Material_Fallback01_BaseLight.h"
|
||||
#include "hpl1/engine/graphics/Material_Fallback02_BaseLight.h"
|
||||
#include "hpl1/engine/graphics/Material_Flat.h"
|
||||
#include "hpl1/engine/graphics/Material_FontNormal.h"
|
||||
#include "hpl1/engine/graphics/Material_Modulative.h"
|
||||
#include "hpl1/engine/graphics/Material_ModulativeX2.h"
|
||||
#include "hpl1/engine/graphics/Material_Smoke2D.h"
|
||||
#include "hpl1/engine/graphics/Material_Water.h"
|
||||
#include "hpl1/engine/graphics/Mesh.h"
|
||||
#include "hpl1/engine/graphics/Mesh2d.h"
|
||||
#include "hpl1/engine/graphics/MeshCreator.h"
|
||||
#include "hpl1/engine/graphics/OcclusionQuery.h"
|
||||
#include "hpl1/engine/graphics/ParticleEmitter.h"
|
||||
#include "hpl1/engine/graphics/ParticleEmitter2D.h"
|
||||
#include "hpl1/engine/graphics/ParticleEmitter3D.h"
|
||||
#include "hpl1/engine/graphics/ParticleEmitter3D_UserData.h"
|
||||
#include "hpl1/engine/graphics/ParticleSystem3D.h"
|
||||
#include "hpl1/engine/graphics/RenderList.h"
|
||||
#include "hpl1/engine/graphics/RenderObject2D.h"
|
||||
#include "hpl1/engine/graphics/RenderState.h"
|
||||
#include "hpl1/engine/graphics/Renderable.h"
|
||||
#include "hpl1/engine/graphics/Renderer2D.h"
|
||||
#include "hpl1/engine/graphics/Renderer3D.h"
|
||||
#include "hpl1/engine/graphics/RendererPostEffects.h"
|
||||
#include "hpl1/engine/graphics/Skeleton.h"
|
||||
#include "hpl1/engine/graphics/SubMesh.h"
|
||||
#include "hpl1/engine/graphics/Texture.h"
|
||||
#include "hpl1/engine/graphics/VertexBuffer.h"
|
||||
#include "hpl1/engine/graphics/VideoStream.h"
|
||||
#include "hpl1/engine/graphics/bitmap2D.h"
|
||||
#include "hpl1/engine/graphics/font_data.h"
|
||||
#include "hpl1/engine/gui/Gui.h"
|
||||
#include "hpl1/engine/gui/GuiGfxElement.h"
|
||||
#include "hpl1/engine/gui/GuiMaterial.h"
|
||||
#include "hpl1/engine/gui/GuiMaterialBasicTypes.h"
|
||||
#include "hpl1/engine/gui/GuiPopUp.h"
|
||||
#include "hpl1/engine/gui/GuiPopUpMessageBox.h"
|
||||
#include "hpl1/engine/gui/GuiSet.h"
|
||||
#include "hpl1/engine/gui/GuiSkin.h"
|
||||
#include "hpl1/engine/gui/GuiTypes.h"
|
||||
#include "hpl1/engine/gui/Widget.h"
|
||||
#include "hpl1/engine/gui/WidgetBaseClasses.h"
|
||||
#include "hpl1/engine/gui/WidgetButton.h"
|
||||
#include "hpl1/engine/gui/WidgetCheckBox.h"
|
||||
#include "hpl1/engine/gui/WidgetComboBox.h"
|
||||
#include "hpl1/engine/gui/WidgetFrame.h"
|
||||
#include "hpl1/engine/gui/WidgetImage.h"
|
||||
#include "hpl1/engine/gui/WidgetLabel.h"
|
||||
#include "hpl1/engine/gui/WidgetListBox.h"
|
||||
#include "hpl1/engine/gui/WidgetSlider.h"
|
||||
#include "hpl1/engine/gui/WidgetTextBox.h"
|
||||
#include "hpl1/engine/gui/WidgetWindow.h"
|
||||
#include "hpl1/engine/impl/tinyXML/tinyxml.h"
|
||||
#include "hpl1/engine/input/Action.h"
|
||||
#include "hpl1/engine/input/ActionKeyboard.h"
|
||||
#include "hpl1/engine/input/ActionMouseButton.h"
|
||||
#include "hpl1/engine/input/Input.h"
|
||||
#include "hpl1/engine/input/InputDevice.h"
|
||||
#include "hpl1/engine/input/InputTypes.h"
|
||||
#include "hpl1/engine/input/Keyboard.h"
|
||||
#include "hpl1/engine/input/LowLevelInput.h"
|
||||
#include "hpl1/engine/input/Mouse.h"
|
||||
#include "hpl1/engine/math/BoundingVolume.h"
|
||||
#include "hpl1/engine/math/Frustum.h"
|
||||
#include "hpl1/engine/math/Math.h"
|
||||
#include "hpl1/engine/math/MathTypes.h"
|
||||
#include "hpl1/engine/math/MeshTypes.h"
|
||||
#include "hpl1/engine/math/PidController.h"
|
||||
#include "hpl1/engine/math/Quaternion.h"
|
||||
#include "hpl1/engine/math/Spring.h"
|
||||
#include "hpl1/engine/math/Vector2.h"
|
||||
#include "hpl1/engine/math/Vector3.h"
|
||||
#include "hpl1/engine/math/hplMatrix.h"
|
||||
#include "hpl1/engine/physics/Body2D.h"
|
||||
#include "hpl1/engine/physics/CharacterBody.h"
|
||||
#include "hpl1/engine/physics/CollideData.h"
|
||||
#include "hpl1/engine/physics/CollideData2D.h"
|
||||
#include "hpl1/engine/physics/CollideShape.h"
|
||||
#include "hpl1/engine/physics/Collider2D.h"
|
||||
#include "hpl1/engine/physics/LowLevelPhysics.h"
|
||||
#include "hpl1/engine/physics/Physics.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/PhysicsMaterial.h"
|
||||
#include "hpl1/engine/physics/PhysicsWorld.h"
|
||||
#include "hpl1/engine/physics/SurfaceData.h"
|
||||
#include "hpl1/engine/resources/AnimationManager.h"
|
||||
#include "hpl1/engine/resources/ConfigFile.h"
|
||||
#include "hpl1/engine/resources/EntityLoader_Object.h"
|
||||
#include "hpl1/engine/resources/FileSearcher.h"
|
||||
#include "hpl1/engine/resources/FontManager.h"
|
||||
#include "hpl1/engine/resources/FrameBase.h"
|
||||
#include "hpl1/engine/resources/FrameBitmap.h"
|
||||
#include "hpl1/engine/resources/FrameTexture.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/MeshLoader.h"
|
||||
#include "hpl1/engine/resources/MeshLoaderHandler.h"
|
||||
#include "hpl1/engine/resources/MeshManager.h"
|
||||
#include "hpl1/engine/resources/ParticleManager.h"
|
||||
#include "hpl1/engine/resources/ResourceBase.h"
|
||||
#include "hpl1/engine/resources/ResourceImage.h"
|
||||
#include "hpl1/engine/resources/ResourceManager.h"
|
||||
#include "hpl1/engine/resources/Resources.h"
|
||||
#include "hpl1/engine/resources/ResourcesTypes.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/AnimationState.h"
|
||||
#include "hpl1/engine/scene/Area2D.h"
|
||||
#include "hpl1/engine/scene/Camera.h"
|
||||
#include "hpl1/engine/scene/Camera2D.h"
|
||||
#include "hpl1/engine/scene/Camera3D.h"
|
||||
#include "hpl1/engine/scene/ColliderEntity.h"
|
||||
#include "hpl1/engine/scene/Entity.h"
|
||||
#include "hpl1/engine/scene/Entity2D.h"
|
||||
#include "hpl1/engine/scene/Entity3D.h"
|
||||
#include "hpl1/engine/scene/GridMap2D.h"
|
||||
#include "hpl1/engine/scene/ImageEntity.h"
|
||||
#include "hpl1/engine/scene/Light.h"
|
||||
#include "hpl1/engine/scene/Light2D.h"
|
||||
#include "hpl1/engine/scene/Light2DPoint.h"
|
||||
#include "hpl1/engine/scene/Light3D.h"
|
||||
#include "hpl1/engine/scene/Light3DPoint.h"
|
||||
#include "hpl1/engine/scene/Light3DSpot.h"
|
||||
#include "hpl1/engine/scene/MeshEntity.h"
|
||||
#include "hpl1/engine/scene/MultiImageEntity.h"
|
||||
#include "hpl1/engine/scene/Node.h"
|
||||
#include "hpl1/engine/scene/Node2D.h"
|
||||
#include "hpl1/engine/scene/Node3D.h"
|
||||
#include "hpl1/engine/scene/NodeState.h"
|
||||
#include "hpl1/engine/scene/PortalContainer.h"
|
||||
#include "hpl1/engine/scene/RenderableContainer.h"
|
||||
#include "hpl1/engine/scene/Scene.h"
|
||||
#include "hpl1/engine/scene/SectorVisibility.h"
|
||||
#include "hpl1/engine/scene/SoundEntity.h"
|
||||
#include "hpl1/engine/scene/SoundSource.h"
|
||||
#include "hpl1/engine/scene/SubMeshEntity.h"
|
||||
#include "hpl1/engine/scene/Tile.h"
|
||||
#include "hpl1/engine/scene/TileData.h"
|
||||
#include "hpl1/engine/scene/TileLayer.h"
|
||||
#include "hpl1/engine/scene/TileMap.h"
|
||||
#include "hpl1/engine/scene/TileMapIt.h"
|
||||
#include "hpl1/engine/scene/TileMapLineIt.h"
|
||||
#include "hpl1/engine/scene/TileMapRectIt.h"
|
||||
#include "hpl1/engine/scene/TileSet.h"
|
||||
#include "hpl1/engine/scene/World2D.h"
|
||||
#include "hpl1/engine/scene/World3D.h"
|
||||
#include "hpl1/engine/sound/LowLevelSound.h"
|
||||
#include "hpl1/engine/sound/MusicHandler.h"
|
||||
#include "hpl1/engine/sound/Sound.h"
|
||||
#include "hpl1/engine/sound/SoundChannel.h"
|
||||
#include "hpl1/engine/sound/SoundData.h"
|
||||
#include "hpl1/engine/sound/SoundEntityData.h"
|
||||
#include "hpl1/engine/sound/SoundEnvironment.h"
|
||||
#include "hpl1/engine/sound/SoundHandler.h"
|
||||
#include "hpl1/engine/system/BinTree.h"
|
||||
#include "hpl1/engine/system/Container.h"
|
||||
#include "hpl1/engine/system/LogicTimer.h"
|
||||
#include "hpl1/engine/system/MemoryManager.h"
|
||||
#include "hpl1/engine/system/Script.h"
|
||||
#include "hpl1/engine/system/SerializeClass.h"
|
||||
#include "hpl1/engine/system/String.h"
|
||||
#include "hpl1/engine/system/System.h"
|
||||
#include "hpl1/engine/system/SystemTypes.h"
|
||||
#include "hpl1/engine/system/low_level_system.h"
|
||||
|
||||
#endif
|
||||
500
engines/hpl1/engine/game/Game.cpp
Normal file
500
engines/hpl1/engine/game/Game.cpp
Normal file
@@ -0,0 +1,500 @@
|
||||
/* 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/game/Game.h"
|
||||
|
||||
#include "hpl1/engine/game/ScriptFuncs.h"
|
||||
#include "hpl1/engine/game/Updater.h"
|
||||
#include "hpl1/engine/graphics/Graphics.h"
|
||||
#include "hpl1/engine/graphics/LowLevelGraphics.h"
|
||||
#include "hpl1/engine/graphics/Renderer3D.h"
|
||||
#include "hpl1/engine/input/Input.h"
|
||||
#include "hpl1/engine/input/Mouse.h"
|
||||
#include "hpl1/engine/resources/Resources.h"
|
||||
#include "hpl1/engine/system/LogicTimer.h"
|
||||
#include "hpl1/engine/system/String.h"
|
||||
#include "hpl1/engine/system/System.h"
|
||||
|
||||
#include "hpl1/engine/gui/Gui.h"
|
||||
|
||||
#include "hpl1/engine/game/low_level_game_setup.h"
|
||||
#include "hpl1/engine/system/low_level_system.h"
|
||||
|
||||
#include "common/events.h"
|
||||
#include "hpl1/hpl1.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// FPS COUNTER
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
cFPSCounter::cFPSCounter(LowLevelSystem *apLowLevelSystem) {
|
||||
mfFPS = 60;
|
||||
|
||||
mlFramecounter = 0;
|
||||
mfFrametimestart = 0;
|
||||
mfFrametime = 0;
|
||||
|
||||
mfUpdateRate = 1;
|
||||
|
||||
mpLowLevelSystem = apLowLevelSystem;
|
||||
|
||||
mfFrametimestart = ((float)GetApplicationTime()) / 1000.0f;
|
||||
}
|
||||
|
||||
void cFPSCounter::AddFrame() {
|
||||
mlFramecounter++;
|
||||
|
||||
mfFrametime = (((float)GetApplicationTime()) / 1000.0f) - mfFrametimestart;
|
||||
|
||||
// update the timer
|
||||
if (mfFrametime >= mfUpdateRate) {
|
||||
mfFPS = ((float)mlFramecounter) / mfFrametime;
|
||||
mlFramecounter = 0;
|
||||
mfFrametimestart = ((float)GetApplicationTime()) / 1000.0f;
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// SETUP VAR CONTAINER
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cSetupVarContainer::cSetupVarContainer() {
|
||||
msBlank = "";
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cSetupVarContainer::AddString(const tString &asName, const tString &asValue) {
|
||||
Common::StableMap<tString, tString>::value_type val(asName, asValue);
|
||||
m_mapVars.insert(val);
|
||||
}
|
||||
|
||||
void cSetupVarContainer::AddInt(const tString &asName, int alValue) {
|
||||
AddString(asName, cString::ToString(alValue));
|
||||
}
|
||||
void cSetupVarContainer::AddFloat(const tString &asName, float afValue) {
|
||||
AddString(asName, cString::ToString(afValue));
|
||||
}
|
||||
void cSetupVarContainer::AddBool(const tString &asName, bool abValue) {
|
||||
AddString(asName, abValue ? "true" : "false");
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
const tString &cSetupVarContainer::GetString(const tString &asName) {
|
||||
Common::StableMap<tString, tString>::iterator it = m_mapVars.find(asName);
|
||||
if (it == m_mapVars.end())
|
||||
return msBlank;
|
||||
else
|
||||
return it->second;
|
||||
}
|
||||
|
||||
float cSetupVarContainer::GetFloat(const tString &asName, float afDefault) {
|
||||
const tString &sVal = GetString(asName);
|
||||
if (sVal == "")
|
||||
return afDefault;
|
||||
else
|
||||
return cString::ToFloat(sVal.c_str(), afDefault);
|
||||
}
|
||||
int cSetupVarContainer::GetInt(const tString &asName, int alDefault) {
|
||||
const tString &sVal = GetString(asName);
|
||||
if (sVal == "")
|
||||
return alDefault;
|
||||
else
|
||||
return cString::ToInt(sVal.c_str(), alDefault);
|
||||
}
|
||||
bool cSetupVarContainer::GetBool(const tString &asName, bool abDefault) {
|
||||
const tString &sVal = GetString(asName);
|
||||
if (sVal == "")
|
||||
return abDefault;
|
||||
else
|
||||
return cString::ToBool(sVal.c_str(), abDefault);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cGame::cGame(LowLevelGameSetup *apGameSetup, cSetupVarContainer &aVars) {
|
||||
GameInit(apGameSetup, aVars);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cGame::cGame(LowLevelGameSetup *apGameSetup, int alWidth, int alHeight, int alBpp, bool abFullscreen,
|
||||
unsigned int alUpdateRate, int alMultisampling) {
|
||||
cSetupVarContainer Vars;
|
||||
Vars.AddInt("ScreenWidth", alWidth);
|
||||
Vars.AddInt("ScreenHeight", alHeight);
|
||||
Vars.AddInt("ScreenBpp", alBpp);
|
||||
Vars.AddBool("Fullscreen", abFullscreen);
|
||||
Vars.AddInt("Multisampling", alMultisampling);
|
||||
Vars.AddInt("LogicUpdateRate", alUpdateRate);
|
||||
GameInit(apGameSetup, Vars);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cGame::GameInit(LowLevelGameSetup *apGameSetup, cSetupVarContainer &aVars) {
|
||||
mpGameSetup = apGameSetup;
|
||||
|
||||
Log("Creating Engine Modules\n");
|
||||
Log("--------------------------------------------------------\n");
|
||||
|
||||
// Create the modules that game connects to and init them!
|
||||
Log(" Creating graphics module\n");
|
||||
mpGraphics = mpGameSetup->createGraphics();
|
||||
|
||||
Log(" Creating system module\n");
|
||||
mpSystem = mpGameSetup->createSystem();
|
||||
|
||||
Log(" Creating resource module\n");
|
||||
mpResources = mpGameSetup->createResources(mpGraphics);
|
||||
|
||||
Log(" Creating input module\n");
|
||||
mpInput = mpGameSetup->createInput(mpGraphics);
|
||||
|
||||
Log(" Creating sound module\n");
|
||||
mpSound = mpGameSetup->createSound();
|
||||
|
||||
Log(" Creating physics module\n");
|
||||
mpPhysics = mpGameSetup->createPhysics();
|
||||
|
||||
Log(" Creating ai module\n");
|
||||
mpAI = mpGameSetup->createAi();
|
||||
|
||||
Log(" Creating gui module\n");
|
||||
mpGui = hplNew(cGui, ());
|
||||
|
||||
Log(" Creating scene module\n");
|
||||
mpScene = mpGameSetup->createScene(mpGraphics, mpResources, mpSound, mpPhysics, mpSystem, mpAI);
|
||||
|
||||
Log("--------------------------------------------------------\n\n");
|
||||
|
||||
// Init the resources
|
||||
mpResources->Init(mpGraphics, mpSystem, mpSound, mpScene, mpGui);
|
||||
|
||||
// Init the graphics
|
||||
mpGraphics->Init(aVars.GetInt("ScreenWidth", 800),
|
||||
aVars.GetInt("ScreenHeight", 600),
|
||||
aVars.GetInt("ScreenBpp", 32),
|
||||
aVars.GetBool("Fullscreen", false),
|
||||
aVars.GetInt("Multisampling", 0),
|
||||
aVars.GetString("WindowCaption"),
|
||||
mpResources);
|
||||
|
||||
// Init Sound
|
||||
mpSound->Init(mpResources, aVars.GetBool("UseSoundHardware", true),
|
||||
aVars.GetBool("ForceGeneric", false),
|
||||
aVars.GetBool("UseEnvironmentalAudio", false),
|
||||
aVars.GetInt("MaxSoundChannels", 32),
|
||||
aVars.GetInt("StreamUpdateFreq", 10),
|
||||
aVars.GetBool("UseSoundThreading", true),
|
||||
aVars.GetBool("UseVoiceManagement", true),
|
||||
aVars.GetInt("MaxMonoChannelsHint", 0),
|
||||
aVars.GetInt("MaxStereoChannelsHint", 0),
|
||||
aVars.GetInt("StreamBufferSize", 4096),
|
||||
aVars.GetInt("StreamBufferCount", 8),
|
||||
aVars.GetBool("LowLevelSoundLogging", false),
|
||||
aVars.GetString("DeviceName"));
|
||||
|
||||
// Init physics
|
||||
mpPhysics->Init(mpResources);
|
||||
|
||||
// Init AI
|
||||
mpAI->Init();
|
||||
|
||||
// Init Gui
|
||||
mpGui->Init(mpResources, mpGraphics, mpSound, mpScene);
|
||||
|
||||
Log("Initializing Game Module\n");
|
||||
Log("--------------------------------------------------------\n");
|
||||
// Create the updatehandler
|
||||
Log(" Adding engine updates\n");
|
||||
mpUpdater = hplNew(cUpdater, (mpSystem->GetLowLevel()));
|
||||
|
||||
// Add some loaded modules to the updater
|
||||
mpUpdater->AddGlobalUpdate(mpInput);
|
||||
mpUpdater->AddGlobalUpdate(mpPhysics);
|
||||
mpUpdater->AddGlobalUpdate(mpScene);
|
||||
mpUpdater->AddGlobalUpdate(mpSound);
|
||||
mpUpdater->AddGlobalUpdate(mpAI);
|
||||
mpUpdater->AddGlobalUpdate(mpGui);
|
||||
mpUpdater->AddGlobalUpdate(mpResources);
|
||||
|
||||
// Setup the "default" updater container
|
||||
mpUpdater->AddContainer("Default");
|
||||
mpUpdater->SetContainer("Default");
|
||||
|
||||
// Create the logic timer.
|
||||
mpLogicTimer = mpSystem->CreateLogicTimer(aVars.GetInt("LogicUpdateRate", 800));
|
||||
|
||||
// Init some standard script funcs
|
||||
Log(" Initializing script functions\n");
|
||||
cScriptFuncs::Init(mpGraphics, mpResources, mpSystem, mpInput, mpScene, mpSound, this);
|
||||
|
||||
// Since game is not done:
|
||||
mbGameIsDone = false;
|
||||
|
||||
mfUpdateTime = 0;
|
||||
mfGameTime = 0;
|
||||
|
||||
mbLimitFPS = true;
|
||||
|
||||
mpFPSCounter = hplNew(cFPSCounter, (mpSystem->GetLowLevel()));
|
||||
Log("--------------------------------------------------------\n\n");
|
||||
|
||||
Log("User Initialization\n");
|
||||
Log("--------------------------------------------------------\n");
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cGame::~cGame() {
|
||||
Log("--------------------------------------------------------\n\n");
|
||||
|
||||
hplDelete(mpLogicTimer);
|
||||
hplDelete(mpFPSCounter);
|
||||
|
||||
hplDelete(mpUpdater);
|
||||
|
||||
hplDelete(mpGui);
|
||||
hplDelete(mpScene);
|
||||
hplDelete(mpInput);
|
||||
hplDelete(mpSound);
|
||||
hplDelete(mpGraphics);
|
||||
hplDelete(mpResources);
|
||||
hplDelete(mpPhysics);
|
||||
hplDelete(mpAI);
|
||||
hplDelete(mpSystem);
|
||||
|
||||
Log(" Deleting game setup provided by user\n");
|
||||
hplDelete(mpGameSetup);
|
||||
|
||||
Log("HPL Exit was successful!\n");
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHOD
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
int glClearUpdateCheck = 0;
|
||||
void cGame::Run() {
|
||||
double fNumOfTimes = 0;
|
||||
double fMediumTime = 0;
|
||||
|
||||
mpUpdater->OnStart();
|
||||
|
||||
mpLogicTimer->Reset();
|
||||
|
||||
// Loop the game... fix the var...
|
||||
unsigned long lTempTime = GetApplicationTime();
|
||||
|
||||
mfFrameTime = 0;
|
||||
unsigned long lTempFrameTime = GetApplicationTime();
|
||||
|
||||
bool mbIsUpdated = true;
|
||||
|
||||
while (!mbGameIsDone && !g_engine->shouldQuit()) {
|
||||
//////////////////////////
|
||||
// Update logic.
|
||||
while (mpLogicTimer->WantUpdate() && !mbGameIsDone) {
|
||||
unsigned int lUpdateTime = GetApplicationTime();
|
||||
|
||||
mpUpdater->Update(GetStepSize());
|
||||
|
||||
unsigned int lDeltaTime = GetApplicationTime() - lUpdateTime;
|
||||
mfUpdateTime = (float)(lDeltaTime) / 1000.0f;
|
||||
|
||||
mbIsUpdated = true;
|
||||
|
||||
glClearUpdateCheck++;
|
||||
|
||||
mfGameTime += GetStepSize();
|
||||
}
|
||||
mpLogicTimer->EndUpdateLoop();
|
||||
|
||||
// If not making a single rendering is better to use gpu and
|
||||
// cpu at the same time and make query checks etc after logic update.
|
||||
// If any delete has occurred in the update this might crash. so skip it for now.
|
||||
/*if(mbRenderOnce==false) {
|
||||
mpGraphics->GetRenderer3D()->FetchOcclusionQueries();
|
||||
mpUpdater->OnPostBufferSwap();
|
||||
}*/
|
||||
|
||||
// Draw graphics!
|
||||
if (mbIsUpdated)
|
||||
mpScene->UpdateRenderList(mfFrameTime);
|
||||
if (mbLimitFPS == false || mbIsUpdated) {
|
||||
mbIsUpdated = false;
|
||||
|
||||
// Get the the from the last frame.
|
||||
mfFrameTime = ((float)(GetApplicationTime() - lTempFrameTime)) / 1000;
|
||||
lTempFrameTime = GetApplicationTime();
|
||||
|
||||
// Draw this frame
|
||||
// unsigned long lFTime = GetApplicationTime();
|
||||
mpUpdater->OnDraw();
|
||||
mpScene->Render(mpUpdater, mfFrameTime);
|
||||
|
||||
// Update fps counter.
|
||||
mpFPSCounter->AddFrame();
|
||||
|
||||
// Update the screen.
|
||||
mpGraphics->GetLowLevel()->SwapBuffers();
|
||||
mpGraphics->GetRenderer3D()->FetchOcclusionQueries();
|
||||
mpUpdater->OnPostBufferSwap();
|
||||
|
||||
fNumOfTimes++;
|
||||
}
|
||||
}
|
||||
Log("--------------------------------------------------------\n\n");
|
||||
|
||||
Log("Statistics\n");
|
||||
Log("--------------------------------------------------------\n");
|
||||
|
||||
unsigned long lTime = GetApplicationTime() - lTempTime;
|
||||
fMediumTime = fNumOfTimes / (((double)lTime) / 1000);
|
||||
|
||||
Log(" Medium framerate: %f\n", fMediumTime);
|
||||
Log("--------------------------------------------------------\n\n");
|
||||
|
||||
Log("User Exit\n");
|
||||
Log("--------------------------------------------------------\n");
|
||||
|
||||
mpUpdater->OnExit();
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cGame::Exit() {
|
||||
mbGameIsDone = true;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cGame::ResetLogicTimer() {
|
||||
mpLogicTimer->Reset();
|
||||
}
|
||||
|
||||
void cGame::SetUpdatesPerSec(int alUpdatesPerSec) {
|
||||
mpLogicTimer->SetUpdatesPerSec(alUpdatesPerSec);
|
||||
}
|
||||
|
||||
int cGame::GetUpdatesPerSec() {
|
||||
return mpLogicTimer->GetUpdatesPerSec();
|
||||
}
|
||||
|
||||
float cGame::GetStepSize() {
|
||||
return mpLogicTimer->GetStepSize();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cScene *cGame::GetScene() {
|
||||
return mpScene;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cResources *cGame::GetResources() {
|
||||
return mpResources;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cGraphics *cGame::GetGraphics() {
|
||||
return mpGraphics;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cSystem *cGame::GetSystem() {
|
||||
return mpSystem;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cInput *cGame::GetInput() {
|
||||
return mpInput;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cSound *cGame::GetSound() {
|
||||
return mpSound;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cPhysics *cGame::GetPhysics() {
|
||||
return mpPhysics;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cAI *cGame::GetAI() {
|
||||
return mpAI;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cGui *cGame::GetGui() {
|
||||
return mpGui;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cUpdater *cGame::GetUpdater() {
|
||||
return mpUpdater;
|
||||
}
|
||||
|
||||
float cGame::GetFPS() {
|
||||
return mpFPSCounter->mfFPS;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cGame::SetFPSUpdateRate(float afSec) {
|
||||
mpFPSCounter->mfUpdateRate = afSec;
|
||||
}
|
||||
float cGame::GetFPSUpdateRate() {
|
||||
return mpFPSCounter->mfUpdateRate;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
} // namespace hpl
|
||||
221
engines/hpl1/engine/game/Game.h
Normal file
221
engines/hpl1/engine/game/Game.h
Normal file
@@ -0,0 +1,221 @@
|
||||
/* 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_GAME_H
|
||||
#define HPL_GAME_H
|
||||
|
||||
#include "hpl1/engine/system/SystemTypes.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class cUpdater;
|
||||
class LowLevelGameSetup;
|
||||
class LowLevelSystem;
|
||||
class cLogicTimer;
|
||||
|
||||
class cSystem;
|
||||
class cInput;
|
||||
class cResources;
|
||||
class cGraphics;
|
||||
class cScene;
|
||||
class cSound;
|
||||
class cPhysics;
|
||||
class cAI;
|
||||
class cGui;
|
||||
|
||||
class cFPSCounter {
|
||||
public:
|
||||
cFPSCounter(LowLevelSystem *apLowLevelSystem);
|
||||
|
||||
void AddFrame();
|
||||
|
||||
float mfFPS;
|
||||
float mfUpdateRate;
|
||||
|
||||
private:
|
||||
LowLevelSystem *mpLowLevelSystem;
|
||||
int mlFramecounter;
|
||||
float mfFrametimestart;
|
||||
float mfFrametime;
|
||||
};
|
||||
|
||||
//---------------------------------------------------
|
||||
|
||||
class cSetupVarContainer {
|
||||
public:
|
||||
cSetupVarContainer();
|
||||
|
||||
void AddString(const tString &asName, const tString &asValue);
|
||||
|
||||
void AddInt(const tString &asName, int alValue);
|
||||
void AddFloat(const tString &asName, float afValue);
|
||||
void AddBool(const tString &asName, bool abValue);
|
||||
|
||||
const tString &GetString(const tString &asName);
|
||||
|
||||
float GetFloat(const tString &asName, float afDefault);
|
||||
int GetInt(const tString &asName, int alDefault);
|
||||
bool GetBool(const tString &asName, bool abDefault);
|
||||
|
||||
private:
|
||||
Common::StableMap<tString, tString> m_mapVars;
|
||||
tString msBlank;
|
||||
};
|
||||
|
||||
//---------------------------------------------------
|
||||
|
||||
class cGame {
|
||||
public:
|
||||
cGame(LowLevelGameSetup *apGameSetup, cSetupVarContainer &aVars);
|
||||
cGame(LowLevelGameSetup *apGameSetup, int alWidth, int alHeight, int alBpp, bool abFullscreen,
|
||||
unsigned int alUpdateRate = 60, int alMultisampling = 0);
|
||||
~cGame();
|
||||
|
||||
private:
|
||||
void GameInit(LowLevelGameSetup *apGameSetup, cSetupVarContainer &aVars);
|
||||
|
||||
public:
|
||||
/**
|
||||
* Starts the game loop. To make stuff run they must be added as updatables..
|
||||
*/
|
||||
void Run();
|
||||
/**
|
||||
* Exists the game.
|
||||
* \todo is this a good way to do it? Should game be global. If so, make a singleton.
|
||||
*/
|
||||
void Exit();
|
||||
|
||||
/**
|
||||
*
|
||||
* \return A pointer to Scene
|
||||
*/
|
||||
cScene *GetScene();
|
||||
/**
|
||||
*
|
||||
* \return A pointer to Resources
|
||||
*/
|
||||
cResources *GetResources();
|
||||
|
||||
/**
|
||||
*
|
||||
* \return A pointer to the Updater
|
||||
*/
|
||||
cUpdater *GetUpdater();
|
||||
|
||||
/**
|
||||
*
|
||||
* \return A pointer to the System
|
||||
*/
|
||||
cSystem *GetSystem();
|
||||
|
||||
/**
|
||||
*
|
||||
* \return A pointer to the Input
|
||||
*/
|
||||
cInput *GetInput();
|
||||
|
||||
/**
|
||||
*
|
||||
* \return A pointer to the Graphics
|
||||
*/
|
||||
cGraphics *GetGraphics();
|
||||
/**
|
||||
*
|
||||
* \return A pointer to the Sound
|
||||
*/
|
||||
cSound *GetSound();
|
||||
/**
|
||||
*
|
||||
* \return A pointer to the Physics
|
||||
*/
|
||||
cPhysics *GetPhysics();
|
||||
|
||||
/**
|
||||
*
|
||||
* \return A pointer to the AI
|
||||
*/
|
||||
cAI *GetAI();
|
||||
|
||||
/**
|
||||
*
|
||||
* \return A pointer to the Gui
|
||||
*/
|
||||
cGui *GetGui();
|
||||
|
||||
void ResetLogicTimer();
|
||||
void SetUpdatesPerSec(int alUpdatesPerSec);
|
||||
int GetUpdatesPerSec();
|
||||
float GetStepSize();
|
||||
|
||||
cLogicTimer *GetLogicTimer() { return mpLogicTimer; }
|
||||
|
||||
float GetFPS();
|
||||
|
||||
void SetFPSUpdateRate(float afSec);
|
||||
float GetFPSUpdateRate();
|
||||
|
||||
float GetFrameTime() { return mfFrameTime; }
|
||||
|
||||
float GetUpdateTime() { return mfUpdateTime; }
|
||||
|
||||
double GetGameTime() { return mfGameTime; }
|
||||
|
||||
void SetLimitFPS(bool abX) { mbLimitFPS = abX; }
|
||||
bool GetLimitFPS() { return mbLimitFPS; }
|
||||
|
||||
private:
|
||||
bool mbGameIsDone;
|
||||
|
||||
float mfFrameTime;
|
||||
|
||||
float mfUpdateTime;
|
||||
|
||||
double mfGameTime;
|
||||
|
||||
LowLevelGameSetup *mpGameSetup;
|
||||
cUpdater *mpUpdater;
|
||||
cLogicTimer *mpLogicTimer;
|
||||
|
||||
cFPSCounter *mpFPSCounter;
|
||||
|
||||
bool mbLimitFPS;
|
||||
|
||||
// Modules that Game connnect to:
|
||||
cResources *mpResources;
|
||||
cSystem *mpSystem;
|
||||
cInput *mpInput;
|
||||
cGraphics *mpGraphics;
|
||||
cScene *mpScene;
|
||||
cSound *mpSound;
|
||||
cPhysics *mpPhysics;
|
||||
cAI *mpAI;
|
||||
cGui *mpGui;
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_GAME_H
|
||||
57
engines/hpl1/engine/game/GameTypes.cpp
Normal file
57
engines/hpl1/engine/game/GameTypes.cpp
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.
|
||||
*/
|
||||
|
||||
#include "hpl1/engine/game/GameTypes.h"
|
||||
|
||||
#include "hpl1/engine/system/low_level_system.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cScriptVar::cScriptVar() {
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// SERIALIZE
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
kBeginSerializeBase(cScriptVar)
|
||||
kSerializeVar(msName, eSerializeType_String)
|
||||
kSerializeVar(mlVal, eSerializeType_Int32)
|
||||
kEndSerialize()
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
} // namespace hpl
|
||||
48
engines/hpl1/engine/game/GameTypes.h
Normal file
48
engines/hpl1/engine/game/GameTypes.h
Normal file
@@ -0,0 +1,48 @@
|
||||
/* 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_GAME_TYPES_H
|
||||
#define HPL_GAME_TYPES_H
|
||||
|
||||
#include "hpl1/engine/system/SerializeClass.h"
|
||||
#include "common/stablemap.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class cScriptVar : public iSerializable {
|
||||
kSerializableClassInit(cScriptVar) public : cScriptVar();
|
||||
|
||||
tString msName;
|
||||
int mlVal;
|
||||
};
|
||||
|
||||
typedef Common::StableMap<tString, cScriptVar> tScriptVarMap;
|
||||
typedef tScriptVarMap::iterator tScriptVarMapIt;
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_GAME_TYPES_H
|
||||
201
engines/hpl1/engine/game/SaveGame.cpp
Normal file
201
engines/hpl1/engine/game/SaveGame.cpp
Normal file
@@ -0,0 +1,201 @@
|
||||
/* 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/game/SaveGame.h"
|
||||
|
||||
#include "hpl1/engine/system/low_level_system.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// SAVE GAME DATA
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
// Serialize iSaveGame
|
||||
kBeginSerializeBaseVirtual(iSaveData)
|
||||
kSerializeVar(mlSaveDataId, eSerializeType_Int32)
|
||||
kEndSerialize()
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// SAVE GAME OBJECT
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int iSaveObject::_mlGlobalIdCount = 0;
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
iSaveObject::iSaveObject() {
|
||||
mlSaveObjectId = _mlGlobalIdCount++;
|
||||
if (_mlGlobalIdCount < 0)
|
||||
_mlGlobalIdCount = 0;
|
||||
|
||||
mbIsSaved = true;
|
||||
}
|
||||
|
||||
iSaveObject::~iSaveObject() {
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
void iSaveObject::SaveToSaveData(iSaveData *apSaveData) {
|
||||
apSaveData->mlSaveDataId = mlSaveObjectId;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
void iSaveObject::LoadFromSaveData(iSaveData *apSaveData) {
|
||||
mlSaveObjectId = apSaveData->mlSaveDataId;
|
||||
mpSaveData = apSaveData;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
void iSaveObject::SaveDataSetup(cSaveObjectHandler *apSaveObjectHandler, cGame *apGame) {
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// SAVE GAME CONTAINER
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
cSaveObjectHandler::cSaveObjectHandler() {
|
||||
}
|
||||
|
||||
cSaveObjectHandler::~cSaveObjectHandler() {
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
void cSaveObjectHandler::Add(iSaveObject *pObject) {
|
||||
m_mapSaveObjects.insert(tSaveObjectMap::value_type(pObject->GetSaveObjectId(), pObject));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
iSaveObject *cSaveObjectHandler::Get(int alId) {
|
||||
tSaveObjectMapIt it = m_mapSaveObjects.find(alId);
|
||||
if (it == m_mapSaveObjects.end()) {
|
||||
Warning("Couldn't find save object with id %d\n", alId);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return it->second;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
cSaveObjectIterator cSaveObjectHandler::GetIterator() {
|
||||
return cSaveObjectIterator(&m_mapSaveObjects);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
void cSaveObjectHandler::SetUpAll(cGame *apGame) {
|
||||
int lMaxId = 0;
|
||||
|
||||
tSaveObjectMapIt it = m_mapSaveObjects.begin();
|
||||
for (; it != m_mapSaveObjects.end(); ++it) {
|
||||
iSaveObject *pObject = it->second;
|
||||
|
||||
if (pObject->GetSaveObjectId() > lMaxId)
|
||||
lMaxId = pObject->GetSaveObjectId();
|
||||
|
||||
pObject->SaveDataSetup(this, apGame);
|
||||
}
|
||||
|
||||
iSaveObject::_mlGlobalIdCount = lMaxId;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
void cSaveObjectHandler::Clear() {
|
||||
m_mapSaveObjects.clear();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
size_t cSaveObjectHandler::Size() {
|
||||
return m_mapSaveObjects.size();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// SAVE DATA CONTAINER
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
cSaveDataHandler::cSaveDataHandler() {
|
||||
}
|
||||
|
||||
cSaveDataHandler::~cSaveDataHandler() {
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
void cSaveDataHandler::Add(iSaveData *pData) {
|
||||
m_mapSaveData.insert(tSaveDataMap::value_type(pData->GetSaveCreatePrio(), pData));
|
||||
}
|
||||
|
||||
cSaveDataIterator cSaveDataHandler::GetIterator() {
|
||||
return cSaveDataIterator(&m_mapSaveData);
|
||||
}
|
||||
|
||||
void cSaveDataHandler::Clear() {
|
||||
m_mapSaveData.clear();
|
||||
}
|
||||
|
||||
size_t cSaveDataHandler::Size() {
|
||||
return m_mapSaveData.size();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
void cSaveDataHandler::AddVoidPtr(void **apPtr) {
|
||||
iSaveData **pDataPtr = (iSaveData **)apPtr;
|
||||
Add(*pDataPtr);
|
||||
}
|
||||
void cSaveDataHandler::AddVoidClass(void *apClass) {
|
||||
iSaveData *pData = (iSaveData *)(apClass);
|
||||
Add(pData);
|
||||
}
|
||||
|
||||
iContainerIterator *cSaveDataHandler::CreateIteratorPtr() {
|
||||
return hplNew(cSaveDataIterator, (&m_mapSaveData));
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
} // namespace hpl
|
||||
239
engines/hpl1/engine/game/SaveGame.h
Normal file
239
engines/hpl1/engine/game/SaveGame.h
Normal file
@@ -0,0 +1,239 @@
|
||||
/* 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_SAVE_GAME_H
|
||||
#define HPL_SAVE_GAME_H
|
||||
|
||||
#include "hpl1/engine/system/SerializeClass.h"
|
||||
#include "hpl1/engine/system/SystemTypes.h"
|
||||
#include "common/stablemap.h"
|
||||
#include "common/multimap.h"
|
||||
|
||||
class TiXmlElement;
|
||||
|
||||
#define kSaveData_LoadFromBegin(aClass) \
|
||||
super::LoadFromSaveData(apSaveData); \
|
||||
cSaveData_##aClass *pData = static_cast<cSaveData_##aClass *>(apSaveData); \
|
||||
assert(pData != nullptr);
|
||||
|
||||
#define kSaveData_SaveToBegin(aClass) \
|
||||
super::SaveToSaveData(apSaveData); \
|
||||
cSaveData_##aClass *pData = static_cast<cSaveData_##aClass *>(apSaveData); \
|
||||
assert(pData != nullptr);
|
||||
|
||||
#define kSaveData_SetupBegin(aClass) \
|
||||
super::SaveDataSetup(apSaveObjectHandler, apGame); \
|
||||
cSaveData_##aClass *pData = static_cast<cSaveData_##aClass *>(mpSaveData); \
|
||||
assert(pData != nullptr);
|
||||
|
||||
#define kSaveData_BaseClass(aClass) class cSaveData_##aClass : public iSaveData
|
||||
#define kSaveData_ChildClass(aParent, aChild) class cSaveData_##aChild : public cSaveData_##aParent
|
||||
|
||||
#define kSaveData_ClassInit(aClass) kSerializableClassInit(cSaveData_##aClass)
|
||||
|
||||
//////////////////////////////////////////////
|
||||
// Helpers to copy data.
|
||||
#define kSaveData_SaveTo(aVar) pData->aVar = aVar;
|
||||
#define kSaveData_LoadFrom(aVar) aVar = pData->aVar;
|
||||
|
||||
#define kSaveData_SaveObject(aObject, aId) \
|
||||
if (aObject) \
|
||||
pData->aId = aObject->GetSaveObjectId(); \
|
||||
else \
|
||||
pData->aId = -1;
|
||||
|
||||
// Only used in setup:
|
||||
#define kSaveData_LoadObject(aObject, aId, aClass) \
|
||||
if (pData->aId == -1) \
|
||||
aObject = NULL; \
|
||||
else { \
|
||||
aObject = static_cast<aClass>(apSaveObjectHandler->Get(pData->aId)); \
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////
|
||||
// Helpers to copy containers with SaveDataId
|
||||
#define kSaveData_SaveIdList(aSrcList, aSrcIt, aDestList) \
|
||||
pData->aDestList.Clear(); \
|
||||
for (aSrcIt it = aSrcList.begin(); it != aSrcList.end(); ++it) { \
|
||||
pData->aDestList.Add((*it)->GetSaveObjectId()); \
|
||||
}
|
||||
|
||||
// Only used in setup:
|
||||
#define kSaveData_LoadIdList(aSrcList, aDestList, aClass) \
|
||||
{ \
|
||||
cContainerListIterator<int> it = pData->aDestList.GetIterator(); \
|
||||
aSrcList.clear(); \
|
||||
while (it.HasNext()) { \
|
||||
int lId = it.Next(); \
|
||||
iSaveObject *pObject = apSaveObjectHandler->Get(lId); \
|
||||
if (pObject == NULL) { \
|
||||
continue; \
|
||||
} \
|
||||
aSrcList.push_back(static_cast<aClass>(pObject)); \
|
||||
} \
|
||||
}
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//--------------------------------------------------------
|
||||
|
||||
class cSaveObjectHandler;
|
||||
class iSaveObject;
|
||||
class cGame;
|
||||
|
||||
/**
|
||||
* This is data that is created by a SaveObject and the data can be loaded into the object.
|
||||
*/
|
||||
class iSaveData : public iSerializable {
|
||||
kSerializableClassInit(iSaveData) public : int mlSaveDataId;
|
||||
|
||||
/**
|
||||
* Creates the SaveObject using previously saved objects and the data in this class.
|
||||
*/
|
||||
virtual iSaveObject *CreateSaveObject(cSaveObjectHandler *apSaveObjectHandler, cGame *apGame) = 0;
|
||||
|
||||
/**
|
||||
* The lower number the earlier it will be created.
|
||||
*/
|
||||
virtual int GetSaveCreatePrio() = 0;
|
||||
};
|
||||
|
||||
//--------------------------------------------------------
|
||||
|
||||
/**
|
||||
* This is class is inherited by object that are to be saved.
|
||||
*/
|
||||
class iSaveObject {
|
||||
friend class cSaveObjectHandler;
|
||||
|
||||
public:
|
||||
iSaveObject();
|
||||
virtual ~iSaveObject();
|
||||
|
||||
/**
|
||||
* Get a unique id for this object.
|
||||
*/
|
||||
int GetSaveObjectId() { return mlSaveObjectId; }
|
||||
|
||||
/**
|
||||
* Save it's data to a SaveData
|
||||
*/
|
||||
virtual void SaveToSaveData(iSaveData *apSaveData);
|
||||
/**
|
||||
* Load it's data from a SaveData
|
||||
*/
|
||||
virtual void LoadFromSaveData(iSaveData *apSaveData);
|
||||
|
||||
/**
|
||||
* Creates the SaveData that this class uses.
|
||||
*/
|
||||
virtual iSaveData *CreateSaveData() = 0;
|
||||
|
||||
/**
|
||||
* After all objects have been created, this function is called to enable setup.
|
||||
*/
|
||||
virtual void SaveDataSetup(cSaveObjectHandler *apSaveObjectHandler, cGame *apGame);
|
||||
|
||||
void SetIsSaved(bool abX) { mbIsSaved = abX; }
|
||||
bool IsSaved() { return mbIsSaved; }
|
||||
|
||||
protected:
|
||||
iSaveData *mpSaveData;
|
||||
|
||||
private:
|
||||
int mlSaveObjectId;
|
||||
bool mbIsSaved;
|
||||
static int _mlGlobalIdCount;
|
||||
};
|
||||
|
||||
//---------------------------------------------------------
|
||||
|
||||
typedef Common::MultiMap<int, iSaveObject *> tSaveObjectMap;
|
||||
typedef tSaveObjectMap::iterator tSaveObjectMapIt;
|
||||
|
||||
typedef cSTLMapIterator<iSaveObject *, tSaveObjectMap, tSaveObjectMapIt> cSaveObjectIterator;
|
||||
|
||||
/**
|
||||
* This store all the SaveObjects created at load time.
|
||||
*/
|
||||
class cSaveObjectHandler {
|
||||
public:
|
||||
cSaveObjectHandler();
|
||||
~cSaveObjectHandler();
|
||||
|
||||
public:
|
||||
void Add(iSaveObject *pObject);
|
||||
|
||||
iSaveObject *Get(int alId);
|
||||
|
||||
cSaveObjectIterator GetIterator();
|
||||
|
||||
void SetUpAll(cGame *apGame);
|
||||
|
||||
void Clear();
|
||||
size_t Size();
|
||||
|
||||
private:
|
||||
tSaveObjectMap m_mapSaveObjects;
|
||||
};
|
||||
|
||||
//---------------------------------------------------------
|
||||
|
||||
typedef Common::MultiMap<int, iSaveData *> tSaveDataMap;
|
||||
typedef tSaveDataMap::iterator tSaveDataMapIt;
|
||||
|
||||
typedef cSTLMapIterator<iSaveData *, tSaveDataMap, tSaveDataMapIt> cSaveDataIterator;
|
||||
|
||||
/**
|
||||
* Used to keep track of save data.
|
||||
*/
|
||||
class cSaveDataHandler : public iContainer {
|
||||
public:
|
||||
cSaveDataHandler();
|
||||
~cSaveDataHandler();
|
||||
|
||||
void Add(iSaveData *pData);
|
||||
|
||||
cSaveDataIterator GetIterator();
|
||||
|
||||
void Clear();
|
||||
size_t Size();
|
||||
|
||||
private:
|
||||
void AddVoidPtr(void **apPtr);
|
||||
void AddVoidClass(void *apClass);
|
||||
|
||||
iContainerIterator *CreateIteratorPtr();
|
||||
|
||||
tSaveDataMap m_mapSaveData;
|
||||
};
|
||||
|
||||
//---------------------------------------------------------
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_SAVE_GAME_H
|
||||
1458
engines/hpl1/engine/game/ScriptFuncs.cpp
Normal file
1458
engines/hpl1/engine/game/ScriptFuncs.cpp
Normal file
File diff suppressed because it is too large
Load Diff
75
engines/hpl1/engine/game/ScriptFuncs.h
Normal file
75
engines/hpl1/engine/game/ScriptFuncs.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_SCRIPT_FUNCS_H
|
||||
#define HPL_SCRIPT_FUNCS_H
|
||||
|
||||
#include "hpl1/engine/physics/PhysicsJoint.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class cGraphics;
|
||||
class cResources;
|
||||
class cSystem;
|
||||
class cSound;
|
||||
class cScene;
|
||||
class cInput;
|
||||
class cGame;
|
||||
|
||||
//---------------------------------------
|
||||
|
||||
class cScriptJointCallback : public iPhysicsJointCallback {
|
||||
public:
|
||||
cScriptJointCallback(cScene *apScene);
|
||||
|
||||
void OnMinLimit(iPhysicsJoint *apJoint);
|
||||
void OnMaxLimit(iPhysicsJoint *apJoint);
|
||||
|
||||
bool IsScript() { return true; }
|
||||
|
||||
tString msMaxFunc;
|
||||
tString msMinFunc;
|
||||
|
||||
cScene *mpScene;
|
||||
};
|
||||
|
||||
//---------------------------------------
|
||||
|
||||
class cScriptFuncs {
|
||||
public:
|
||||
static void Init(cGraphics *apGraphics,
|
||||
cResources *apResources,
|
||||
cSystem *apSystem,
|
||||
cInput *apInput,
|
||||
cScene *apScene,
|
||||
cSound *apSound,
|
||||
cGame *apGame);
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_SCRIPT_FUNCS_H
|
||||
63
engines/hpl1/engine/game/Updateable.h
Normal file
63
engines/hpl1/engine/game/Updateable.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_UPDATEABLE_H
|
||||
#define HPL_UPDATEABLE_H
|
||||
|
||||
#include "hpl1/engine/system/SystemTypes.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class iUpdateable {
|
||||
public:
|
||||
iUpdateable(const tString &asName) : msName(asName) {}
|
||||
virtual ~iUpdateable() {}
|
||||
|
||||
virtual void OnDraw() {}
|
||||
|
||||
virtual void OnPostSceneDraw() {}
|
||||
|
||||
virtual void OnPostGUIDraw() {}
|
||||
|
||||
virtual void OnPostBufferSwap() {}
|
||||
|
||||
virtual void OnStart() {}
|
||||
|
||||
virtual void Update(float afTimeStep) {}
|
||||
|
||||
virtual void OnExit() {}
|
||||
|
||||
virtual void Reset() {}
|
||||
|
||||
const tString &GetName() { return msName; }
|
||||
|
||||
private:
|
||||
tString msName;
|
||||
};
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_UPDATEABLE_H
|
||||
267
engines/hpl1/engine/game/Updater.cpp
Normal file
267
engines/hpl1/engine/game/Updater.cpp
Normal file
@@ -0,0 +1,267 @@
|
||||
/* 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/game/Updater.h"
|
||||
|
||||
#include "hpl1/engine/game/Updateable.h"
|
||||
#include "hpl1/engine/system/low_level_system.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cUpdater::cUpdater(LowLevelSystem *apLowLevelSystem) {
|
||||
mpCurrentUpdates = NULL;
|
||||
|
||||
mpLowLevelSystem = apLowLevelSystem;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cUpdater::~cUpdater() {
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHOD
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cUpdater::OnDraw() {
|
||||
for (tUpdateableListIt it = mlstGlobalUpdateableList.begin(); it != mlstGlobalUpdateableList.end(); ++it) {
|
||||
(*it)->OnDraw();
|
||||
}
|
||||
|
||||
if (mpCurrentUpdates) {
|
||||
for (tUpdateableListIt it = mpCurrentUpdates->begin(); it != mpCurrentUpdates->end(); ++it) {
|
||||
(*it)->OnDraw();
|
||||
}
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cUpdater::OnPostSceneDraw() {
|
||||
for (tUpdateableListIt it = mlstGlobalUpdateableList.begin(); it != mlstGlobalUpdateableList.end(); ++it) {
|
||||
(*it)->OnPostSceneDraw();
|
||||
}
|
||||
|
||||
if (mpCurrentUpdates) {
|
||||
for (tUpdateableListIt it = mpCurrentUpdates->begin(); it != mpCurrentUpdates->end(); ++it) {
|
||||
(*it)->OnPostSceneDraw();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void cUpdater::OnPostGUIDraw() {
|
||||
for (tUpdateableListIt it = mlstGlobalUpdateableList.begin(); it != mlstGlobalUpdateableList.end(); ++it) {
|
||||
(*it)->OnPostGUIDraw();
|
||||
}
|
||||
|
||||
if (mpCurrentUpdates) {
|
||||
for (tUpdateableListIt it = mpCurrentUpdates->begin(); it != mpCurrentUpdates->end(); ++it) {
|
||||
(*it)->OnPostGUIDraw();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cUpdater::OnPostBufferSwap() {
|
||||
for (tUpdateableListIt it = mlstGlobalUpdateableList.begin(); it != mlstGlobalUpdateableList.end(); ++it) {
|
||||
(*it)->OnPostBufferSwap();
|
||||
}
|
||||
|
||||
if (mpCurrentUpdates) {
|
||||
for (tUpdateableListIt it = mpCurrentUpdates->begin(); it != mpCurrentUpdates->end(); ++it) {
|
||||
(*it)->OnPostBufferSwap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cUpdater::OnStart() {
|
||||
for (tUpdateableListIt it = mlstGlobalUpdateableList.begin(); it != mlstGlobalUpdateableList.end(); ++it) {
|
||||
(*it)->OnStart();
|
||||
}
|
||||
|
||||
tUpdateContainerMapIt ContIt = m_mapUpdateContainer.begin();
|
||||
while (ContIt != m_mapUpdateContainer.end()) {
|
||||
tUpdateableListIt UpIt = ContIt->second.begin();
|
||||
while (UpIt != ContIt->second.end()) {
|
||||
(*UpIt)->OnStart();
|
||||
UpIt++;
|
||||
}
|
||||
|
||||
ContIt++;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cUpdater::Reset() {
|
||||
for (tUpdateableListIt it = mlstGlobalUpdateableList.begin(); it != mlstGlobalUpdateableList.end(); ++it) {
|
||||
(*it)->Reset();
|
||||
}
|
||||
|
||||
tUpdateContainerMapIt ContIt = m_mapUpdateContainer.begin();
|
||||
while (ContIt != m_mapUpdateContainer.end()) {
|
||||
|
||||
tUpdateableList *pUpdates = &ContIt->second;
|
||||
tUpdateableListIt UpIt = pUpdates->begin();
|
||||
while (UpIt != pUpdates->end()) {
|
||||
iUpdateable *pUpdate = *UpIt;
|
||||
|
||||
pUpdate->Reset();
|
||||
|
||||
++UpIt;
|
||||
}
|
||||
|
||||
++ContIt;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cUpdater::OnExit() {
|
||||
for (tUpdateableListIt it = mlstGlobalUpdateableList.begin(); it != mlstGlobalUpdateableList.end(); ++it) {
|
||||
// Log(" Exiting %s\n",(*it)->GetName().c_str());
|
||||
(*it)->OnExit();
|
||||
}
|
||||
|
||||
tUpdateContainerMapIt ContIt = m_mapUpdateContainer.begin();
|
||||
while (ContIt != m_mapUpdateContainer.end()) {
|
||||
tUpdateableListIt UpIt = ContIt->second.begin();
|
||||
while (UpIt != ContIt->second.end()) {
|
||||
// Log(" Exiting %s\n",(*UpIt)->GetName().c_str());
|
||||
(*UpIt)->OnExit();
|
||||
UpIt++;
|
||||
}
|
||||
|
||||
ContIt++;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cUpdater::Update(float afTimeStep) {
|
||||
for (tUpdateableListIt it = mlstGlobalUpdateableList.begin(); it != mlstGlobalUpdateableList.end(); ++it) {
|
||||
START_TIMING_EX((*it)->GetName().c_str(), game)
|
||||
(*it)->Update(afTimeStep);
|
||||
STOP_TIMING(game)
|
||||
}
|
||||
|
||||
if (mpCurrentUpdates) {
|
||||
tUpdateableList *pList = mpCurrentUpdates;
|
||||
for (tUpdateableListIt it = pList->begin(); it != pList->end(); ++it) {
|
||||
START_TIMING_EX((*it)->GetName().c_str(), game)
|
||||
(*it)->Update(afTimeStep);
|
||||
STOP_TIMING(game)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cUpdater::SetContainer(tString asContainer) {
|
||||
tUpdateContainerMapIt it = m_mapUpdateContainer.find(asContainer);
|
||||
if (it == m_mapUpdateContainer.end())
|
||||
return false;
|
||||
|
||||
msCurrentUpdates = asContainer;
|
||||
if (msCurrentUpdates == "Default") {
|
||||
SetUpdateLogActive(true);
|
||||
} else {
|
||||
SetUpdateLogActive(false);
|
||||
}
|
||||
|
||||
mpCurrentUpdates = &it->second;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
tString cUpdater::GetCurrentContainerName() {
|
||||
if (mpCurrentUpdates == NULL)
|
||||
return "";
|
||||
|
||||
return msCurrentUpdates;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cUpdater::AddContainer(tString asName) {
|
||||
// Create the value for the map with key and Updateable
|
||||
tUpdateContainerMap::value_type val = tUpdateContainerMap::value_type(
|
||||
asName, tUpdateableList());
|
||||
// Add it to the map
|
||||
m_mapUpdateContainer.insert(val);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cUpdater::AddUpdate(tString asContainer, iUpdateable *apUpdate) {
|
||||
if (apUpdate == NULL) {
|
||||
Error("Couldn't add NULL updatable!");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Search the map for the container name
|
||||
tUpdateContainerMapIt it = m_mapUpdateContainer.find(asContainer);
|
||||
if (it == m_mapUpdateContainer.end())
|
||||
return false;
|
||||
|
||||
// Add the updatable
|
||||
it->second.push_back(apUpdate);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cUpdater::AddGlobalUpdate(iUpdateable *apUpdate) {
|
||||
mlstGlobalUpdateableList.push_back(apUpdate);
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PRIVATE METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
} // namespace hpl
|
||||
110
engines/hpl1/engine/game/Updater.h
Normal file
110
engines/hpl1/engine/game/Updater.h
Normal file
@@ -0,0 +1,110 @@
|
||||
/* 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_UPDATER_H
|
||||
#define HPL_UPDATER_H
|
||||
|
||||
#include "common/list.h"
|
||||
#include "hpl1/engine/system/SystemTypes.h"
|
||||
#include "common/stablemap.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class iUpdateable;
|
||||
class LowLevelSystem;
|
||||
|
||||
typedef Common::List<iUpdateable *> tUpdateableList;
|
||||
typedef tUpdateableList::iterator tUpdateableListIt;
|
||||
|
||||
typedef Common::StableMap<tString, tUpdateableList> tUpdateContainerMap;
|
||||
typedef tUpdateContainerMap::iterator tUpdateContainerMapIt;
|
||||
|
||||
class cUpdater {
|
||||
public:
|
||||
cUpdater(LowLevelSystem *apLowLevelSystem);
|
||||
~cUpdater();
|
||||
|
||||
void Reset();
|
||||
|
||||
void OnDraw();
|
||||
void OnPostSceneDraw();
|
||||
void OnPostGUIDraw();
|
||||
void OnPostBufferSwap();
|
||||
|
||||
void OnStart();
|
||||
|
||||
void Update(float afTimeStep);
|
||||
|
||||
void OnExit();
|
||||
|
||||
/**
|
||||
* Sets the active update container to be used.
|
||||
* \param asContainer Name of the contianer
|
||||
* \return
|
||||
*/
|
||||
bool SetContainer(tString asContainer);
|
||||
|
||||
/**
|
||||
* Gets the name of the current container in use.
|
||||
* \return name of current container.
|
||||
*/
|
||||
tString GetCurrentContainerName();
|
||||
/**
|
||||
* Adds a new container
|
||||
* \todo change name to state instead of container?
|
||||
* \param asName Name for the new container.
|
||||
* \return
|
||||
*/
|
||||
bool AddContainer(tString asName);
|
||||
/**
|
||||
* Adds a new update in a container.
|
||||
* \param asContainer Container name
|
||||
* \param apUpdate pointer to the class that will be updated
|
||||
* \return
|
||||
*/
|
||||
bool AddUpdate(tString asContainer, iUpdateable *apUpdate);
|
||||
/**
|
||||
* Adds a global update that runs no matter what container is set
|
||||
* \param apUpdate
|
||||
* \return
|
||||
*/
|
||||
bool AddGlobalUpdate(iUpdateable *apUpdate);
|
||||
|
||||
private:
|
||||
tString msCurrentUpdates;
|
||||
|
||||
tUpdateContainerMap m_mapUpdateContainer;
|
||||
|
||||
LowLevelSystem *mpLowLevelSystem;
|
||||
|
||||
tUpdateableList *mpCurrentUpdates;
|
||||
tUpdateableList mlstGlobalUpdateableList;
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_UPDATER_H
|
||||
105
engines/hpl1/engine/game/low_level_game_setup.cpp
Normal file
105
engines/hpl1/engine/game/low_level_game_setup.cpp
Normal file
@@ -0,0 +1,105 @@
|
||||
/* 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/game/low_level_game_setup.h"
|
||||
#include "hpl1/engine/impl/LowLevelGraphicsSDL.h"
|
||||
#include "hpl1/engine/impl/LowLevelPhysicsNewton.h"
|
||||
#include "hpl1/engine/impl/LowLevelSoundOpenAL.h"
|
||||
#include "hpl1/engine/impl/low_level_graphics_tgl.h"
|
||||
#include "hpl1/engine/input/LowLevelInput.h"
|
||||
#include "hpl1/engine/resources/low_level_resources.h"
|
||||
#include "hpl1/engine/system/low_level_system.h"
|
||||
#include "hpl1/graphics.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
static iLowLevelGraphics *createLowLevelGfx() {
|
||||
#ifdef HPL1_USE_OPENGL
|
||||
if (Hpl1::useOpenGL())
|
||||
return hplNew(cLowLevelGraphicsSDL, ());
|
||||
#endif
|
||||
#ifdef USE_TINYGL
|
||||
return hplNew(LowLevelGraphicsTGL, ());
|
||||
#else
|
||||
error("Can't find a valid renderer: TinyGL is not supported");
|
||||
#endif
|
||||
}
|
||||
|
||||
LowLevelGameSetup::LowLevelGameSetup() {
|
||||
_lowLevelSystem = hplNew(LowLevelSystem, ());
|
||||
_lowLevelGraphics = createLowLevelGfx();
|
||||
_lowLevelInput = hplNew(LowLevelInput, (_lowLevelGraphics));
|
||||
_lowLevelResources = hplNew(LowLevelResources, (_lowLevelGraphics));
|
||||
_lowLevelSound = hplNew(cLowLevelSoundOpenAL, ());
|
||||
_lowLevelPhysics = hplNew(cLowLevelPhysicsNewton, ());
|
||||
}
|
||||
|
||||
LowLevelGameSetup::~LowLevelGameSetup() {
|
||||
Log("Deleting lowlevel stuff.\n");
|
||||
|
||||
Log("Physics\n");
|
||||
hplDelete(_lowLevelPhysics);
|
||||
Log("Sound\n");
|
||||
hplDelete(_lowLevelSound);
|
||||
Log("Input\n");
|
||||
hplDelete(_lowLevelInput);
|
||||
Log("Resources\n");
|
||||
hplDelete(_lowLevelResources);
|
||||
Log("System\n");
|
||||
hplDelete(_lowLevelSystem);
|
||||
Log("Graphics\n");
|
||||
hplDelete(_lowLevelGraphics);
|
||||
}
|
||||
|
||||
cScene *LowLevelGameSetup::createScene(cGraphics *graphics, cResources *resources, cSound *sound,
|
||||
cPhysics *physics, cSystem *system, cAI *ai) {
|
||||
return hplNew(cScene, (graphics, resources, sound, physics, system, ai));
|
||||
}
|
||||
|
||||
cResources *LowLevelGameSetup::createResources(cGraphics *graphics) {
|
||||
return hplNew(cResources, (_lowLevelResources, _lowLevelGraphics));
|
||||
}
|
||||
|
||||
cInput *LowLevelGameSetup::createInput(cGraphics *graphics) {
|
||||
return hplNew(cInput, (_lowLevelInput));
|
||||
}
|
||||
|
||||
cSystem *LowLevelGameSetup::createSystem() {
|
||||
return hplNew(cSystem, (_lowLevelSystem));
|
||||
}
|
||||
|
||||
cGraphics *LowLevelGameSetup::createGraphics() {
|
||||
return hplNew(cGraphics, (_lowLevelGraphics, _lowLevelResources));
|
||||
}
|
||||
|
||||
cSound *LowLevelGameSetup::createSound() {
|
||||
return hplNew(cSound, (_lowLevelSound));
|
||||
}
|
||||
|
||||
cPhysics *LowLevelGameSetup::createPhysics() {
|
||||
return hplNew(cPhysics, (_lowLevelPhysics));
|
||||
}
|
||||
|
||||
cAI *LowLevelGameSetup::createAi() {
|
||||
return hplNew(cAI, ());
|
||||
}
|
||||
|
||||
} // namespace hpl
|
||||
68
engines/hpl1/engine/game/low_level_game_setup.h
Normal file
68
engines/hpl1/engine/game/low_level_game_setup.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_LOWLEVELGAMESETUP_H
|
||||
#define HPL_LOWLEVELGAMESETUP_H
|
||||
|
||||
#include "hpl1/engine/ai/AI.h"
|
||||
#include "hpl1/engine/graphics/Graphics.h"
|
||||
#include "hpl1/engine/input/Input.h"
|
||||
#include "hpl1/engine/physics/Physics.h"
|
||||
#include "hpl1/engine/resources/Resources.h"
|
||||
#include "hpl1/engine/scene/Scene.h"
|
||||
#include "hpl1/engine/sound/Sound.h"
|
||||
#include "hpl1/engine/system/System.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class LowLevelGameSetup {
|
||||
public:
|
||||
LowLevelGameSetup();
|
||||
~LowLevelGameSetup();
|
||||
|
||||
cInput *createInput(cGraphics *graphics);
|
||||
cSystem *createSystem();
|
||||
cGraphics *createGraphics();
|
||||
cResources *createResources(cGraphics *graphics);
|
||||
cScene *createScene(cGraphics *graphics, cResources *resources, cSound *sound,
|
||||
cPhysics *physics, cSystem *system, cAI *ai);
|
||||
cSound *createSound();
|
||||
cPhysics *createPhysics();
|
||||
cAI *createAi();
|
||||
|
||||
private:
|
||||
LowLevelSystem *_lowLevelSystem;
|
||||
iLowLevelGraphics *_lowLevelGraphics;
|
||||
LowLevelInput *_lowLevelInput;
|
||||
LowLevelResources *_lowLevelResources;
|
||||
iLowLevelSound *_lowLevelSound;
|
||||
iLowLevelPhysics *_lowLevelPhysics;
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_LOWLEVELGAMESETUP_H
|
||||
119
engines/hpl1/engine/graphics/Animation.cpp
Normal file
119
engines/hpl1/engine/graphics/Animation.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/graphics/Animation.h"
|
||||
|
||||
#include "hpl1/engine/graphics/AnimationTrack.h"
|
||||
#include "hpl1/engine/math/Math.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cAnimation::cAnimation(const tString &asName, const tString &asFile) : iResourceBase(asName, 0) {
|
||||
msAnimName = "";
|
||||
msFileName = asFile;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cAnimation::~cAnimation() {
|
||||
STLDeleteAll(mvTracks);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
float cAnimation::GetLength() {
|
||||
return mfLength;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cAnimation::SetLength(float afTime) {
|
||||
mfLength = afTime;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cAnimationTrack *cAnimation::CreateTrack(const tString &asName, tAnimTransformFlag aFlags) {
|
||||
cAnimationTrack *pTrack = hplNew(cAnimationTrack, (asName, aFlags, this));
|
||||
|
||||
mvTracks.push_back(pTrack);
|
||||
|
||||
return pTrack;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cAnimationTrack *cAnimation::GetTrack(int alIndex) {
|
||||
return mvTracks[alIndex];
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cAnimationTrack *cAnimation::GetTrackByName(const tString &asName) {
|
||||
for (size_t i = 0; i < mvTracks.size(); ++i) {
|
||||
if (asName == tString(mvTracks[i]->GetName())) {
|
||||
return mvTracks[i];
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cAnimation::ResizeTracks(int alNum) {
|
||||
mvTracks.reserve(alNum);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
int cAnimation::GetTrackNum() {
|
||||
return (int)mvTracks.size();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PRIVATE METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
} // namespace hpl
|
||||
79
engines/hpl1/engine/graphics/Animation.h
Normal file
79
engines/hpl1/engine/graphics/Animation.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_ANIMATION_H
|
||||
#define HPL_ANIMATION_H
|
||||
|
||||
#include "common/array.h"
|
||||
#include "hpl1/engine/graphics/GraphicsTypes.h"
|
||||
#include "hpl1/engine/math/MathTypes.h"
|
||||
#include "hpl1/engine/resources/ResourceBase.h"
|
||||
#include "hpl1/engine/system/SystemTypes.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class cAnimationTrack;
|
||||
|
||||
typedef Common::Array<cAnimationTrack *> tAnimationTrackVec;
|
||||
typedef tAnimationTrackVec::iterator tAnimationTrackVecIt;
|
||||
|
||||
class cAnimation : public iResourceBase {
|
||||
public:
|
||||
cAnimation(const tString &asName, const tString &asFile);
|
||||
~cAnimation();
|
||||
|
||||
float GetLength();
|
||||
void SetLength(float afTime);
|
||||
|
||||
cAnimationTrack *CreateTrack(const tString &asName, tAnimTransformFlag aFlags);
|
||||
cAnimationTrack *GetTrack(int alIndex);
|
||||
cAnimationTrack *GetTrackByName(const tString &asName);
|
||||
void ResizeTracks(int alNum);
|
||||
int GetTrackNum();
|
||||
|
||||
const char *GetAnimationName() { return msAnimName.c_str(); }
|
||||
void SetAnimationName(const tString &asName) { msAnimName = asName; }
|
||||
|
||||
tString &GetFileName() { return msFileName; }
|
||||
|
||||
// Resources implementation
|
||||
bool reload() { return false; }
|
||||
void unload() {}
|
||||
void destroy() {}
|
||||
|
||||
private:
|
||||
tString msAnimName;
|
||||
tString msFileName;
|
||||
|
||||
float mfLength;
|
||||
|
||||
tAnimationTrackVec mvTracks;
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_ANIMATION_H
|
||||
207
engines/hpl1/engine/graphics/AnimationTrack.cpp
Normal file
207
engines/hpl1/engine/graphics/AnimationTrack.cpp
Normal file
@@ -0,0 +1,207 @@
|
||||
/* 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/graphics/AnimationTrack.h"
|
||||
|
||||
#include "hpl1/engine/graphics/Animation.h"
|
||||
#include "hpl1/engine/math/Math.h"
|
||||
#include "hpl1/engine/scene/Node3D.h"
|
||||
#include "hpl1/engine/system/low_level_system.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cAnimationTrack::cAnimationTrack(const tString &asName, tAnimTransformFlag aTransformFlags,
|
||||
cAnimation *apParent) {
|
||||
msName = asName;
|
||||
mTransformFlags = aTransformFlags;
|
||||
mpParent = apParent;
|
||||
|
||||
mfMaxFrameTime = 0;
|
||||
|
||||
mlNodeIdx = -1;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cAnimationTrack::~cAnimationTrack() {
|
||||
STLDeleteAll(mvKeyFrames);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cAnimationTrack::ResizeKeyFrames(int alSize) {
|
||||
mvKeyFrames.reserve(alSize);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cKeyFrame *cAnimationTrack::CreateKeyFrame(float afTime) {
|
||||
cKeyFrame *pFrame = hplNew(cKeyFrame, ());
|
||||
pFrame->time = afTime;
|
||||
|
||||
// Check so that this is the first
|
||||
if (afTime > mfMaxFrameTime || mvKeyFrames.empty()) {
|
||||
mvKeyFrames.push_back(pFrame);
|
||||
mfMaxFrameTime = afTime;
|
||||
} else {
|
||||
tKeyFramePtrVecIt it = mvKeyFrames.begin();
|
||||
for (; it != mvKeyFrames.end(); it++) {
|
||||
if (afTime < (*it)->time) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
mvKeyFrames.insert(it, pFrame);
|
||||
}
|
||||
|
||||
return pFrame;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cAnimationTrack::ApplyToNode(cNode3D *apNode, float afTime, float afWeight) {
|
||||
cKeyFrame Frame = GetInterpolatedKeyFrame(afTime);
|
||||
|
||||
// Scale
|
||||
// Skip this for now...
|
||||
/*cVector3f vOne(1,1,1);
|
||||
cVector3f vScale = (Frame.scale - vOne)*afWeight + vOne;
|
||||
apNode->AddScale(vScale);*/
|
||||
|
||||
// Rotation
|
||||
cQuaternion qRot = cMath::QuaternionSlerp(afWeight, cQuaternion::Identity, Frame.rotation, true);
|
||||
apNode->AddRotation(qRot);
|
||||
|
||||
// Translation
|
||||
cVector3f vTrans = Frame.trans * afWeight;
|
||||
apNode->AddTranslation(vTrans);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cKeyFrame cAnimationTrack::GetInterpolatedKeyFrame(float afTime) {
|
||||
cKeyFrame ResultKeyFrame;
|
||||
ResultKeyFrame.time = afTime;
|
||||
|
||||
cKeyFrame *pKeyFrameA = NULL;
|
||||
cKeyFrame *pKeyFrameB = NULL;
|
||||
|
||||
float fT = GetKeyFramesAtTime(afTime, &pKeyFrameA, &pKeyFrameB);
|
||||
|
||||
if (fT == 0.0f) {
|
||||
ResultKeyFrame.rotation = pKeyFrameA->rotation;
|
||||
ResultKeyFrame.scale = pKeyFrameA->scale;
|
||||
ResultKeyFrame.trans = pKeyFrameA->trans;
|
||||
} else {
|
||||
// Do a linear interpolation
|
||||
// This should include spline stuff later on.
|
||||
|
||||
ResultKeyFrame.rotation = cMath::QuaternionSlerp(fT, pKeyFrameA->rotation,
|
||||
pKeyFrameB->rotation, true);
|
||||
|
||||
ResultKeyFrame.scale = pKeyFrameA->scale * (1 - fT) + pKeyFrameB->scale * fT;
|
||||
ResultKeyFrame.trans = pKeyFrameA->trans * (1 - fT) + pKeyFrameB->trans * fT;
|
||||
}
|
||||
|
||||
return ResultKeyFrame;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
float cAnimationTrack::GetKeyFramesAtTime(float afTime, cKeyFrame **apKeyFrameA, cKeyFrame **apKeyFrameB) {
|
||||
float fTotalAnimLength = mpParent->GetLength();
|
||||
|
||||
// Wrap time
|
||||
// Not sure it is a good idea to clamp the length.
|
||||
// But wrapping screws loop mode up.
|
||||
// Wrap(..., totalLength + kEpislon), migh work though.
|
||||
afTime = cMath::Clamp(afTime, 0, fTotalAnimLength);
|
||||
|
||||
// If longer than max time return last frame and first
|
||||
if (afTime >= mfMaxFrameTime) {
|
||||
*apKeyFrameA = mvKeyFrames[mvKeyFrames.size() - 1];
|
||||
*apKeyFrameB = mvKeyFrames[0];
|
||||
|
||||
// Get T between end to start again. (the last frame doesn't mean the anim is over.
|
||||
// In that case wrap to the first frame).
|
||||
// float fDeltaT = fTotalAnimLength - (*apKeyFrameA)->time;
|
||||
|
||||
// If animation time is >= max time might as well just return the last frame.
|
||||
// Not sure if this is good for some looping anims, in that case check the code.
|
||||
return 0.0f; //(afTime - (*apKeyFrameA)->time) / fDeltaT;
|
||||
}
|
||||
|
||||
// Get the number of frames
|
||||
const int lSize = (int)mvKeyFrames.size();
|
||||
|
||||
// Find the second frame.
|
||||
int lIdxB = -1;
|
||||
for (int i = 0; i < lSize; i++) {
|
||||
if (afTime <= mvKeyFrames[i]->time) {
|
||||
lIdxB = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// If first frame was found, the lowest time is not 0.
|
||||
// If so return the first frame only.
|
||||
if (lIdxB == 0) {
|
||||
*apKeyFrameA = mvKeyFrames[0];
|
||||
*apKeyFrameB = mvKeyFrames[0];
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
// Get the frames
|
||||
*apKeyFrameA = mvKeyFrames[lIdxB - 1];
|
||||
*apKeyFrameB = mvKeyFrames[lIdxB];
|
||||
|
||||
float fDeltaT = (*apKeyFrameB)->time - (*apKeyFrameA)->time;
|
||||
|
||||
return (afTime - (*apKeyFrameA)->time) / fDeltaT;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PRIVATE METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
} // namespace hpl
|
||||
102
engines/hpl1/engine/graphics/AnimationTrack.h
Normal file
102
engines/hpl1/engine/graphics/AnimationTrack.h
Normal file
@@ -0,0 +1,102 @@
|
||||
/* 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_TRACK_H
|
||||
#define HPL_ANIMATION_TRACK_H
|
||||
|
||||
#include "hpl1/engine/graphics/GraphicsTypes.h"
|
||||
#include "hpl1/engine/math/MathTypes.h"
|
||||
#include "hpl1/engine/system/SystemTypes.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class cAnimation;
|
||||
class cNode3D;
|
||||
|
||||
class cAnimationTrack {
|
||||
public:
|
||||
cAnimationTrack(const tString &asName, tAnimTransformFlag aTransformFlags, cAnimation *apParent);
|
||||
~cAnimationTrack();
|
||||
|
||||
void ResizeKeyFrames(int alSize);
|
||||
|
||||
/**
|
||||
* Creates a new key frame. These should be added in sequential order.
|
||||
* \param afTime the time for the key frame.
|
||||
*/
|
||||
cKeyFrame *CreateKeyFrame(float afTime);
|
||||
|
||||
inline cKeyFrame *GetKeyFrame(int alIndex) { return mvKeyFrames[alIndex]; }
|
||||
inline int GetKeyFrameNum() { return (int)mvKeyFrames.size(); }
|
||||
|
||||
inline tAnimTransformFlag GetTransformFlags() { return mTransformFlags; }
|
||||
|
||||
/**
|
||||
* Apply the animation to a node. The method uses Node->AddXXX() so Update matrix must be called
|
||||
* for the transformation to be applied.
|
||||
* \param apNode The node with it's base pose
|
||||
* \param afTime The time at which to apply the animation
|
||||
* \param afWeight The weight of the animation, a value from 0 to 1.
|
||||
*/
|
||||
void ApplyToNode(cNode3D *apNode, float afTime, float afWeight);
|
||||
|
||||
/**
|
||||
* Get a KeyFrame that contains an interpolated value.
|
||||
* \param afTime The time from wihcih to create the keyframe.
|
||||
*/
|
||||
cKeyFrame GetInterpolatedKeyFrame(float afTime);
|
||||
|
||||
/**
|
||||
* Gets key frames between for a specific time.
|
||||
* \param afTime The time
|
||||
* \param &apKeyFrameA The frame that is equal to or before time
|
||||
* \param &apKeyFrameB The frame that is after time.
|
||||
* \return Weight of the different frames. 0 = 100% A, 1 = 100% B 0.5 = 50% A and 50% B
|
||||
*/
|
||||
float GetKeyFramesAtTime(float afTime, cKeyFrame **apKeyFrameA, cKeyFrame **apKeyFrameB);
|
||||
|
||||
const char *GetName() { return msName.c_str(); }
|
||||
|
||||
void SetNodeIndex(int alIndex) { mlNodeIdx = alIndex; }
|
||||
int GetNodeIndex() { return mlNodeIdx; }
|
||||
|
||||
private:
|
||||
tString msName;
|
||||
|
||||
int mlNodeIdx;
|
||||
|
||||
tKeyFramePtrVec mvKeyFrames;
|
||||
tAnimTransformFlag mTransformFlags;
|
||||
|
||||
float mfMaxFrameTime;
|
||||
|
||||
cAnimation *mpParent;
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_ANIMATION_TRACK_H
|
||||
175
engines/hpl1/engine/graphics/BackgroundImage.cpp
Normal file
175
engines/hpl1/engine/graphics/BackgroundImage.cpp
Normal file
@@ -0,0 +1,175 @@
|
||||
/* 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/graphics/BackgroundImage.h"
|
||||
#include "hpl1/engine/math/Math.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cBackgroundImage::cBackgroundImage(iMaterial *apMat, const cVector3f &avPos, bool abTile,
|
||||
const cVector2f &avSize, const cVector2f &avPosPercent, const cVector2f &avVel) {
|
||||
mpMaterial = apMat;
|
||||
|
||||
mvPos = avPos;
|
||||
mbTile = abTile;
|
||||
mvSize = avSize;
|
||||
mvPosPercent = avPosPercent;
|
||||
mvVel = avVel;
|
||||
|
||||
mvVtx = apMat->GetImage(eMaterialTexture_Diffuse)->GetVertexVecCopy(0, mvSize);
|
||||
for (int i = 0; i < (int)mvVtx.size(); i++) {
|
||||
mvVtx[i].pos.z = mvPos.z;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cBackgroundImage::~cBackgroundImage() {
|
||||
hplDelete(mpMaterial);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cBackgroundImage::Draw(const cRect2f &aCollideRect, iLowLevelGraphics *apLowLevelGraphics) {
|
||||
tVector3fList lstPositions;
|
||||
cVector3f vScreenPos(aCollideRect.x * mvPosPercent.x - mvPos.x,
|
||||
aCollideRect.y * mvPosPercent.y, mvPos.z - mvPos.y);
|
||||
|
||||
// Calculate at what positions(s) the background is to be drawn.
|
||||
if (mbTile) {
|
||||
// The number of images needed.
|
||||
cVector2l vNum;
|
||||
vNum.x = (int)(aCollideRect.w / mvSize.x) + 1;
|
||||
vNum.y = (int)(aCollideRect.h / mvSize.y) + 1;
|
||||
|
||||
cVector2f vStartPos;
|
||||
if (vScreenPos.x >= 0)
|
||||
vStartPos.x = mvSize.x - cMath::Modulus(vScreenPos.x, mvSize.x);
|
||||
else
|
||||
vStartPos.x = cMath::Modulus(vScreenPos.x, mvSize.x);
|
||||
|
||||
if (vScreenPos.y >= 0)
|
||||
vStartPos.y = mvSize.y - cMath::Modulus(vScreenPos.y, mvSize.y);
|
||||
else
|
||||
vStartPos.y = cMath::Modulus(vScreenPos.y, mvSize.y);
|
||||
|
||||
// Log("Screen: %f : %f\n",vScreenPos.x, vScreenPos.y);
|
||||
// Log("Start: %f : %f\n",vStartPos.x, vStartPos.y);
|
||||
// Log("Pos: %f : %f\n",mvPos.x, mvPos.y);
|
||||
|
||||
if (vStartPos.x > 0) {
|
||||
vStartPos.x -= mvSize.x;
|
||||
vNum.x++;
|
||||
}
|
||||
if (vStartPos.y > 0) {
|
||||
vStartPos.y -= mvSize.y;
|
||||
vNum.y++;
|
||||
}
|
||||
|
||||
for (int x = 0; x < vNum.x; x++)
|
||||
for (int y = 0; y < vNum.y; y++) {
|
||||
lstPositions.push_back(cVector3f(vStartPos.x + mvSize.x * x,
|
||||
vStartPos.y + mvSize.y * y, vScreenPos.z));
|
||||
}
|
||||
} else {
|
||||
cRect2f Rect(vScreenPos.x, vScreenPos.y, mvSize.x, mvSize.y);
|
||||
|
||||
if (cMath::BoxCollision(aCollideRect, Rect)) {
|
||||
lstPositions.push_back(vScreenPos);
|
||||
}
|
||||
}
|
||||
|
||||
// Draw the images
|
||||
mpMaterial->StartRendering(eMaterialRenderType_Diffuse, NULL, NULL);
|
||||
|
||||
int lIdxAdd = 0;
|
||||
|
||||
tVector3fListIt it = lstPositions.begin();
|
||||
for (; it != lstPositions.end(); it++) {
|
||||
mvVtx[0].pos.x = it->x;
|
||||
mvVtx[0].pos.y = it->y;
|
||||
apLowLevelGraphics->AddVertexToBatch(mvVtx[0]);
|
||||
|
||||
mvVtx[1].pos.x = it->x + mvSize.x;
|
||||
mvVtx[1].pos.y = it->y;
|
||||
apLowLevelGraphics->AddVertexToBatch(mvVtx[1]);
|
||||
|
||||
mvVtx[2].pos.x = it->x + mvSize.x;
|
||||
mvVtx[2].pos.y = it->y + mvSize.y;
|
||||
apLowLevelGraphics->AddVertexToBatch(mvVtx[2]);
|
||||
|
||||
mvVtx[3].pos.x = it->x;
|
||||
mvVtx[3].pos.y = it->y + mvSize.y;
|
||||
apLowLevelGraphics->AddVertexToBatch(mvVtx[3]);
|
||||
|
||||
apLowLevelGraphics->AddIndexToBatch(lIdxAdd + 0);
|
||||
apLowLevelGraphics->AddIndexToBatch(lIdxAdd + 1);
|
||||
apLowLevelGraphics->AddIndexToBatch(lIdxAdd + 2);
|
||||
apLowLevelGraphics->AddIndexToBatch(lIdxAdd + 3);
|
||||
|
||||
/*apLowLevelGraphics->AddIndexToBatch(lIdxAdd + 2);
|
||||
apLowLevelGraphics->AddIndexToBatch(lIdxAdd + 3);
|
||||
apLowLevelGraphics->AddIndexToBatch(lIdxAdd + 0);*/
|
||||
|
||||
lIdxAdd += 4;
|
||||
}
|
||||
|
||||
do {
|
||||
apLowLevelGraphics->FlushQuadBatch(mpMaterial->GetBatchFlags(eMaterialRenderType_Diffuse), false);
|
||||
} while (mpMaterial->NextPass(eMaterialRenderType_Diffuse));
|
||||
|
||||
apLowLevelGraphics->ClearBatch();
|
||||
|
||||
mpMaterial->EndRendering(eMaterialRenderType_Diffuse);
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cBackgroundImage::Update() {
|
||||
mvPos += mvVel;
|
||||
|
||||
if (mbTile) {
|
||||
if (mvPos.x >= mvSize.x)
|
||||
mvPos.x = mvPos.x - mvSize.x;
|
||||
if (mvPos.y >= mvSize.y)
|
||||
mvPos.y = mvPos.y - mvSize.y;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
} // namespace hpl
|
||||
65
engines/hpl1/engine/graphics/BackgroundImage.h
Normal file
65
engines/hpl1/engine/graphics/BackgroundImage.h
Normal file
@@ -0,0 +1,65 @@
|
||||
/* 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_BACKGROUND_IMAGE_H
|
||||
#define HPL_BACKGROUND_IMAGE_H
|
||||
|
||||
#include "hpl1/engine/graphics/GraphicsTypes.h"
|
||||
#include "hpl1/engine/graphics/Material.h"
|
||||
#include "hpl1/engine/math/MathTypes.h"
|
||||
#include "common/stablemap.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class cBackgroundImage {
|
||||
public:
|
||||
cBackgroundImage(iMaterial *apMat, const cVector3f &avPos, bool abTile,
|
||||
const cVector2f &avSize, const cVector2f &avPosPercent, const cVector2f &avVel);
|
||||
~cBackgroundImage();
|
||||
|
||||
void Draw(const cRect2f &aCollideRect, iLowLevelGraphics *apLowLevelGraphics);
|
||||
|
||||
void Update();
|
||||
|
||||
private:
|
||||
iMaterial *mpMaterial;
|
||||
|
||||
tVertexVec mvVtx;
|
||||
|
||||
cVector3f mvPos;
|
||||
bool mbTile;
|
||||
cVector2f mvSize;
|
||||
cVector2f mvPosPercent;
|
||||
cVector2f mvVel;
|
||||
};
|
||||
|
||||
typedef Common::StableMap<float, cBackgroundImage *> tBackgroundImageMap;
|
||||
typedef tBackgroundImageMap::iterator tBackgroundImageMapIt;
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_BACKGROUND_IMAGE_H
|
||||
465
engines/hpl1/engine/graphics/Beam.cpp
Normal file
465
engines/hpl1/engine/graphics/Beam.cpp
Normal file
@@ -0,0 +1,465 @@
|
||||
/* 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/graphics/Beam.h"
|
||||
|
||||
#include "hpl1/engine/impl/tinyXML/tinyxml.h"
|
||||
|
||||
#include "hpl1/engine/graphics/Graphics.h"
|
||||
#include "hpl1/engine/graphics/LowLevelGraphics.h"
|
||||
#include "hpl1/engine/graphics/Material.h"
|
||||
#include "hpl1/engine/graphics/VertexBuffer.h"
|
||||
#include "hpl1/engine/math/Math.h"
|
||||
#include "hpl1/engine/resources/FileSearcher.h"
|
||||
#include "hpl1/engine/resources/MaterialManager.h"
|
||||
#include "hpl1/engine/resources/Resources.h"
|
||||
#include "hpl1/engine/scene/Camera3D.h"
|
||||
#include "hpl1/engine/scene/Scene.h"
|
||||
#include "hpl1/engine/scene/World3D.h"
|
||||
|
||||
#include "hpl1/engine/game/Game.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cBeam::cBeam(const tString asName, cResources *apResources, cGraphics *apGraphics) : iRenderable(asName) {
|
||||
mpMaterialManager = apResources->GetMaterialManager();
|
||||
mpFileSearcher = apResources->GetFileSearcher();
|
||||
mpLowLevelGraphics = apGraphics->GetLowLevel();
|
||||
|
||||
msFileName = "";
|
||||
|
||||
mvSize = 1;
|
||||
|
||||
mbTileHeight = true;
|
||||
|
||||
mColor = cColor(1, 1, 1, 1);
|
||||
|
||||
mpMaterial = NULL;
|
||||
|
||||
mlLastRenderCount = -1;
|
||||
|
||||
mpVtxBuffer = mpLowLevelGraphics->CreateVertexBuffer(
|
||||
eVertexFlag_Position | eVertexFlag_Color0 | eVertexFlag_Texture0 |
|
||||
eVertexFlag_Normal,
|
||||
eVertexBufferDrawType_Tri, eVertexBufferUsageType_Dynamic, 4, 6);
|
||||
|
||||
cVector3f vCoords[4] = {cVector3f((mvSize.x / 2), -(mvSize.y / 2), 0),
|
||||
cVector3f(-(mvSize.x / 2), -(mvSize.y / 2), 0),
|
||||
cVector3f(-(mvSize.x / 2), (mvSize.y / 2), 0),
|
||||
cVector3f((mvSize.x / 2), (mvSize.y / 2), 0)};
|
||||
|
||||
cVector3f vTexCoords[4] = {cVector3f(1, 1, 0), // Bottom left
|
||||
cVector3f(-1, 1, 0), // Bottom right
|
||||
cVector3f(-1, -1, 0), // Top left
|
||||
cVector3f(1, -1, 0)}; // Top right
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
mpVtxBuffer->AddVertex(eVertexFlag_Position, vCoords[i]);
|
||||
mpVtxBuffer->AddColor(eVertexFlag_Color0, cColor(1, 1, 1, 1));
|
||||
mpVtxBuffer->AddVertex(eVertexFlag_Texture0, (vTexCoords[i] + cVector2f(1, 1)) / 2);
|
||||
mpVtxBuffer->AddVertex(eVertexFlag_Normal, cVector3f(0, 0, 1));
|
||||
}
|
||||
|
||||
for (int i = 0; i < 3; i++)
|
||||
mpVtxBuffer->AddIndex(i);
|
||||
for (int i = 2; i < 5; i++)
|
||||
mpVtxBuffer->AddIndex(i == 4 ? 0 : i);
|
||||
|
||||
mpVtxBuffer->Compile(eVertexCompileFlag_CreateTangents);
|
||||
|
||||
mpEnd = hplNew(cBeamEnd, (asName + "_end", this));
|
||||
mpEnd->AddCallback(&mEndCallback);
|
||||
|
||||
// Some temp setup
|
||||
mBoundingVolume.SetSize(cVector3f(mvSize.x, mvSize.y, mvSize.x));
|
||||
|
||||
mbApplyTransformToBV = false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cBeam::~cBeam() {
|
||||
hplDelete(mpEnd);
|
||||
if (mpMaterial)
|
||||
mpMaterialManager->Destroy(mpMaterial);
|
||||
if (mpVtxBuffer)
|
||||
hplDelete(mpVtxBuffer);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cBeam::SetSize(const cVector2f &avSize) {
|
||||
mvSize = avSize;
|
||||
mBoundingVolume.SetSize(cVector3f(mvSize.x, mvSize.y, mvSize.x));
|
||||
|
||||
SetTransformUpdated();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cBeam::SetTileHeight(bool abX) {
|
||||
if (mbTileHeight == abX)
|
||||
return;
|
||||
|
||||
mbTileHeight = abX;
|
||||
|
||||
SetTransformUpdated();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cBeam::SetMultiplyAlphaWithColor(bool abX) {
|
||||
if (mbMultiplyAlphaWithColor == abX)
|
||||
return;
|
||||
|
||||
mbMultiplyAlphaWithColor = abX;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cBeam::SetColor(const cColor &aColor) {
|
||||
if (mColor == aColor)
|
||||
return;
|
||||
|
||||
mColor = aColor;
|
||||
|
||||
float *pColors = mpVtxBuffer->GetArray(eVertexFlag_Color0);
|
||||
|
||||
// Change "lower colors"
|
||||
if (mbMultiplyAlphaWithColor) {
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
pColors[0] = mColor.r * mColor.a;
|
||||
pColors[1] = mColor.g * mColor.a;
|
||||
pColors[2] = mColor.b * mColor.a;
|
||||
pColors[3] = mColor.a;
|
||||
pColors += 4;
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
pColors[0] = mColor.r;
|
||||
pColors[1] = mColor.g;
|
||||
pColors[2] = mColor.b;
|
||||
pColors[3] = mColor.a;
|
||||
pColors += 4;
|
||||
}
|
||||
}
|
||||
mpVtxBuffer->UpdateData(eVertexFlag_Color0, false);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cBeam::SetMaterial(iMaterial *apMaterial) {
|
||||
mpMaterial = apMaterial;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cBoundingVolume *cBeam::GetBoundingVolume() {
|
||||
if (mbUpdateBoundingVolume) {
|
||||
cVector3f vMax = GetWorldPosition();
|
||||
cVector3f vMin = vMax;
|
||||
cVector3f vEnd = mpEnd->GetWorldPosition();
|
||||
|
||||
if (vMax.x < vEnd.x)
|
||||
vMax.x = vEnd.x;
|
||||
if (vMax.y < vEnd.y)
|
||||
vMax.y = vEnd.y;
|
||||
if (vMax.z < vEnd.z)
|
||||
vMax.z = vEnd.z;
|
||||
|
||||
if (vMin.x > vEnd.x)
|
||||
vMin.x = vEnd.x;
|
||||
if (vMin.y > vEnd.y)
|
||||
vMin.y = vEnd.y;
|
||||
if (vMin.z > vEnd.z)
|
||||
vMin.z = vEnd.z;
|
||||
|
||||
vMin -= cVector3f(mvSize.x);
|
||||
vMax += cVector3f(mvSize.x);
|
||||
|
||||
mBoundingVolume.SetLocalMinMax(vMin, vMax);
|
||||
|
||||
mbUpdateBoundingVolume = false;
|
||||
}
|
||||
|
||||
return &mBoundingVolume;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cBeam::UpdateGraphics(cCamera3D *apCamera, float afFrameTime, cRenderList *apRenderList) {
|
||||
if (mlStartTransformCount == GetTransformUpdateCount() &&
|
||||
mlEndTransformCount == GetTransformUpdateCount()) {
|
||||
return;
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
// Get Axis
|
||||
mvAxis = mpEnd->GetWorldPosition() - GetWorldPosition();
|
||||
|
||||
mvMidPosition = GetWorldPosition() + mvAxis * 0.5f;
|
||||
float fDist = mvAxis.Length();
|
||||
|
||||
mvAxis.Normalise();
|
||||
|
||||
////////////////////////////////
|
||||
// Update vertex buffer
|
||||
cVector2f vBeamSize = cVector2f(mvSize.x, fDist);
|
||||
|
||||
float *pPos = mpVtxBuffer->GetArray(eVertexFlag_Position);
|
||||
float *pTex = mpVtxBuffer->GetArray(eVertexFlag_Texture0);
|
||||
|
||||
cVector3f vCoords[4] = {cVector3f((vBeamSize.x / 2), -(vBeamSize.y / 2), 0),
|
||||
cVector3f(-(vBeamSize.x / 2), -(vBeamSize.y / 2), 0),
|
||||
cVector3f(-(vBeamSize.x / 2), (vBeamSize.y / 2), 0),
|
||||
cVector3f((vBeamSize.x / 2), (vBeamSize.y / 2), 0)};
|
||||
|
||||
cVector3f vTexCoords[4];
|
||||
if (mbTileHeight) {
|
||||
vTexCoords[0] = cVector3f(1, 1, 0); // Bottom left
|
||||
vTexCoords[1] = cVector3f(0, 1, 0); // Bottom right
|
||||
vTexCoords[2] = cVector3f(0, -fDist / mvSize.y, 0); // Top left
|
||||
vTexCoords[3] = cVector3f(1, -fDist / mvSize.y, 0); // Top right
|
||||
} else {
|
||||
vTexCoords[0] = cVector3f(1, 1, 0); // Bottom left
|
||||
vTexCoords[1] = cVector3f(0, 1, 0); // Bottom right
|
||||
vTexCoords[2] = cVector3f(0, 0, 0); // Top left
|
||||
vTexCoords[3] = cVector3f(1, 0, 0); // Top right
|
||||
}
|
||||
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
pPos[0] = vCoords[i].x;
|
||||
pPos[1] = vCoords[i].y;
|
||||
pPos[2] = vCoords[i].z;
|
||||
pPos += 4;
|
||||
|
||||
pTex[0] = vTexCoords[i].x;
|
||||
pTex[1] = vTexCoords[i].y;
|
||||
pTex += 3;
|
||||
}
|
||||
|
||||
mpVtxBuffer->UpdateData(eVertexFlag_Position | eVertexFlag_Texture0, false);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cMatrixf *cBeam::GetModelMatrix(cCamera3D *apCamera) {
|
||||
if (apCamera == NULL)
|
||||
return &GetWorldMatrix();
|
||||
|
||||
m_mtxTempTransform = GetWorldMatrix();
|
||||
cVector3f vForward, vRight, vUp;
|
||||
|
||||
cVector3f vCameraForward = apCamera->GetPosition() - GetWorldPosition();
|
||||
vCameraForward.Normalise();
|
||||
|
||||
vUp = mvAxis; // cMath::MatrixMul(GetWorldMatrix().GetRotation(),mvAxis);
|
||||
// vUp.Normalise();
|
||||
|
||||
if (vUp == vForward) {
|
||||
vRight = cMath::Vector3Cross(vUp, vCameraForward);
|
||||
Warning("Beam Right vector is not correct! Contact programmer!\n");
|
||||
} else
|
||||
vRight = cMath::Vector3Cross(vUp, vCameraForward);
|
||||
|
||||
vRight.Normalise();
|
||||
vForward = cMath::Vector3Cross(vRight, vUp);
|
||||
|
||||
// Set right vector
|
||||
m_mtxTempTransform.m[0][0] = vRight.x;
|
||||
m_mtxTempTransform.m[1][0] = vRight.y;
|
||||
m_mtxTempTransform.m[2][0] = vRight.z;
|
||||
|
||||
// Set up vector
|
||||
m_mtxTempTransform.m[0][1] = vUp.x;
|
||||
m_mtxTempTransform.m[1][1] = vUp.y;
|
||||
m_mtxTempTransform.m[2][1] = vUp.z;
|
||||
|
||||
// Set forward vector
|
||||
m_mtxTempTransform.m[0][2] = vForward.x;
|
||||
m_mtxTempTransform.m[1][2] = vForward.y;
|
||||
m_mtxTempTransform.m[2][2] = vForward.z;
|
||||
|
||||
m_mtxTempTransform.SetTranslation(mvMidPosition);
|
||||
|
||||
return &m_mtxTempTransform;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
int cBeam::GetMatrixUpdateCount() {
|
||||
return GetTransformUpdateCount();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cBeam::LoadXMLProperties(const tString asFile) {
|
||||
msFileName = asFile;
|
||||
|
||||
tString sNewFile = cString::SetFileExt(asFile, "beam");
|
||||
tString sPath = mpFileSearcher->GetFilePath(sNewFile);
|
||||
if (sPath != "") {
|
||||
TiXmlDocument *pDoc = hplNew(TiXmlDocument, (sPath.c_str()));
|
||||
if (pDoc->LoadFile()) {
|
||||
TiXmlElement *pRootElem = pDoc->RootElement();
|
||||
|
||||
TiXmlElement *pMainElem = pRootElem->FirstChildElement("MAIN");
|
||||
if (pMainElem != NULL) {
|
||||
tString sMaterial = cString::ToString(pMainElem->Attribute("Material"), "");
|
||||
cVector2f vSize = cString::ToVector2f(pMainElem->Attribute("Size"), 1);
|
||||
|
||||
bool bTileHeight = cString::ToBool(pMainElem->Attribute("TileHeight"), true);
|
||||
bool bMultiplyAlphaWithColor = cString::ToBool(pMainElem->Attribute("MultiplyAlphaWithColor"), false);
|
||||
|
||||
cColor StartColor = cString::ToColor(pMainElem->Attribute("StartColor"), cColor(1, 1));
|
||||
cColor EndColor = cString::ToColor(pMainElem->Attribute("EndColor"), cColor(1, 1));
|
||||
|
||||
SetSize(vSize);
|
||||
SetTileHeight(bTileHeight);
|
||||
SetMultiplyAlphaWithColor(bMultiplyAlphaWithColor);
|
||||
SetColor(StartColor);
|
||||
mpEnd->SetColor(EndColor);
|
||||
|
||||
/////////////////
|
||||
// Load material
|
||||
iMaterial *pMat = mpMaterialManager->CreateMaterial(sMaterial);
|
||||
if (pMat) {
|
||||
SetMaterial(pMat);
|
||||
} else {
|
||||
Error("Couldn't load material '%s' in Beam file '%s'",
|
||||
sMaterial.c_str(), sNewFile.c_str());
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
Error("Cannot find main element in %s\n", sNewFile.c_str());
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
Error("Couldn't load file '%s'\n", sNewFile.c_str());
|
||||
}
|
||||
hplDelete(pDoc);
|
||||
} else {
|
||||
Error("Couldn't find file '%s'\n", sNewFile.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cBeam::IsVisible() {
|
||||
if (mColor.r <= 0 && mColor.g <= 0 && mColor.b <= 0)
|
||||
return false;
|
||||
|
||||
return IsRendered();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// BEAM END TRANSFORM UPDATE CALLBACK
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cBeamEnd_UpdateCallback::OnTransformUpdate(iEntity3D *apEntity) {
|
||||
cBeamEnd *pEnd = static_cast<cBeamEnd *>(apEntity);
|
||||
|
||||
pEnd->mpBeam->SetTransformUpdated(true);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// BEAM END
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cBeamEnd::SetColor(const cColor &aColor) {
|
||||
if (mColor == aColor)
|
||||
return;
|
||||
|
||||
mColor = aColor;
|
||||
|
||||
float *pColors = mpBeam->mpVtxBuffer->GetArray(eVertexFlag_Color0);
|
||||
|
||||
// Change "upper colors"
|
||||
pColors += 4 * 2;
|
||||
if (mpBeam->mbMultiplyAlphaWithColor) {
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
pColors[0] = mColor.r * mColor.a;
|
||||
pColors[1] = mColor.g * mColor.a;
|
||||
pColors[2] = mColor.b * mColor.a;
|
||||
pColors[3] = mColor.a;
|
||||
pColors += 4;
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
pColors[0] = mColor.r;
|
||||
pColors[1] = mColor.g;
|
||||
pColors[2] = mColor.b;
|
||||
pColors[3] = mColor.a;
|
||||
pColors += 4;
|
||||
}
|
||||
}
|
||||
|
||||
mpBeam->mpVtxBuffer->UpdateData(eVertexFlag_Color0, false);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PRIVATE METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// SAVE OBJECT STUFF
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
} // namespace hpl
|
||||
172
engines/hpl1/engine/graphics/Beam.h
Normal file
172
engines/hpl1/engine/graphics/Beam.h
Normal file
@@ -0,0 +1,172 @@
|
||||
/* 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_BEAM_H
|
||||
#define HPL_BEAM_H
|
||||
|
||||
#include "RenderList.h"
|
||||
#include "hpl1/engine/graphics/GraphicsTypes.h"
|
||||
#include "hpl1/engine/graphics/Renderable.h"
|
||||
#include "hpl1/engine/math/MathTypes.h"
|
||||
#include "hpl1/engine/scene/Entity3D.h"
|
||||
#include "hpl1/engine/system/SystemTypes.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class cMaterialManager;
|
||||
class cResources;
|
||||
class cGraphics;
|
||||
class cFileSearcher;
|
||||
class iLowLevelGraphics;
|
||||
class iMaterial;
|
||||
class iVertexBuffer;
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
class cBeam;
|
||||
class cBeamEnd : public iEntity3D {
|
||||
friend class cBeam;
|
||||
friend class cBeamEnd_UpdateCallback;
|
||||
|
||||
public:
|
||||
cBeamEnd(const tString asName, cBeam *apBeam) : iEntity3D(asName),
|
||||
mColor(1, 1), mpBeam(apBeam) {}
|
||||
|
||||
void SetColor(const cColor &aColor);
|
||||
const cColor &GetColor() { return mColor; }
|
||||
|
||||
/////////////////////////////////
|
||||
// Entity implementation
|
||||
tString GetEntityType() { return "BeamEnd"; }
|
||||
|
||||
private:
|
||||
cColor mColor;
|
||||
cBeam *mpBeam;
|
||||
};
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
class cBeamEnd_UpdateCallback : public iEntityCallback {
|
||||
public:
|
||||
void OnTransformUpdate(iEntity3D *apEntity);
|
||||
};
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
class cBeam : public iRenderable {
|
||||
typedef iRenderable super;
|
||||
friend class cBeamEnd;
|
||||
|
||||
public:
|
||||
cBeam(const tString asName, cResources *apResources, cGraphics *apGraphics);
|
||||
~cBeam();
|
||||
|
||||
void SetMaterial(iMaterial *apMaterial);
|
||||
|
||||
const tString &GetFileName() { return msFileName; }
|
||||
|
||||
/**
|
||||
* Set the size. X= the thickness of the line, width of texture used. Y = the length that one texture height takes.
|
||||
* \param avSize
|
||||
*/
|
||||
void SetSize(const cVector2f &avSize);
|
||||
cVector2f GetSize() { return mvSize; }
|
||||
|
||||
void SetColor(const cColor &aColor);
|
||||
const cColor &GetColor() { return mColor; }
|
||||
|
||||
void SetTileHeight(bool abX);
|
||||
bool GetTileHeight() { return mbTileHeight; }
|
||||
|
||||
void SetMultiplyAlphaWithColor(bool abX);
|
||||
bool GetMultiplyAlphaWithColor() { return mbMultiplyAlphaWithColor; }
|
||||
|
||||
cBeamEnd *GetEnd() { return mpEnd; }
|
||||
|
||||
bool LoadXMLProperties(const tString asFile);
|
||||
|
||||
cVector3f GetAxis() { return mvAxis; }
|
||||
cVector3f GetMidPosition() { return mvMidPosition; }
|
||||
|
||||
/////////////////////////////////
|
||||
// Entity implementation
|
||||
tString GetEntityType() { return "Beam"; }
|
||||
|
||||
bool IsVisible();
|
||||
void SetVisible(bool abVisible) { SetRendered(abVisible); }
|
||||
|
||||
// Renderable implementations
|
||||
iMaterial *GetMaterial() { return mpMaterial; }
|
||||
iVertexBuffer *GetVertexBuffer() { return mpVtxBuffer; }
|
||||
|
||||
void UpdateGraphics(cCamera3D *apCamera, float afFrameTime, cRenderList *apRenderList);
|
||||
|
||||
bool IsShadowCaster() { return false; }
|
||||
|
||||
cBoundingVolume *GetBoundingVolume();
|
||||
|
||||
cMatrixf *GetModelMatrix(cCamera3D *apCamera);
|
||||
|
||||
int GetMatrixUpdateCount();
|
||||
|
||||
eRenderableType GetRenderType() { return eRenderableType_ParticleSystem; }
|
||||
|
||||
private:
|
||||
cMaterialManager *mpMaterialManager;
|
||||
cFileSearcher *mpFileSearcher;
|
||||
iLowLevelGraphics *mpLowLevelGraphics;
|
||||
|
||||
iMaterial *mpMaterial;
|
||||
iVertexBuffer *mpVtxBuffer;
|
||||
|
||||
cBeamEnd *mpEnd;
|
||||
|
||||
tString msFileName;
|
||||
|
||||
int mlStartTransformCount;
|
||||
int mlEndTransformCount;
|
||||
|
||||
cMatrixf m_mtxTempTransform;
|
||||
|
||||
int mlLastRenderCount;
|
||||
|
||||
cBeamEnd_UpdateCallback mEndCallback;
|
||||
|
||||
cVector2f mvSize;
|
||||
|
||||
cVector3f mvAxis;
|
||||
cVector3f mvMidPosition;
|
||||
|
||||
bool mbTileHeight;
|
||||
bool mbMultiplyAlphaWithColor;
|
||||
|
||||
cColor mColor;
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_BEAM_H
|
||||
610
engines/hpl1/engine/graphics/BillBoard.cpp
Normal file
610
engines/hpl1/engine/graphics/BillBoard.cpp
Normal file
@@ -0,0 +1,610 @@
|
||||
/* 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/graphics/BillBoard.h"
|
||||
|
||||
#include "hpl1/engine/impl/tinyXML/tinyxml.h"
|
||||
|
||||
#include "hpl1/engine/graphics/Graphics.h"
|
||||
#include "hpl1/engine/graphics/LowLevelGraphics.h"
|
||||
#include "hpl1/engine/graphics/Material.h"
|
||||
#include "hpl1/engine/graphics/MeshCreator.h"
|
||||
#include "hpl1/engine/graphics/VertexBuffer.h"
|
||||
#include "hpl1/engine/math/Math.h"
|
||||
#include "hpl1/engine/resources/FileSearcher.h"
|
||||
#include "hpl1/engine/resources/MaterialManager.h"
|
||||
#include "hpl1/engine/resources/Resources.h"
|
||||
#include "hpl1/engine/scene/Camera3D.h"
|
||||
#include "hpl1/engine/scene/Scene.h"
|
||||
#include "hpl1/engine/scene/World3D.h"
|
||||
|
||||
#include "hpl1/engine/game/Game.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cBillboard::cBillboard(const tString asName, const cVector2f &avSize, cResources *apResources,
|
||||
cGraphics *apGraphics) : iRenderable(asName) {
|
||||
mpMaterialManager = apResources->GetMaterialManager();
|
||||
mpFileSearcher = apResources->GetFileSearcher();
|
||||
mpLowLevelGraphics = apGraphics->GetLowLevel();
|
||||
mpMeshCreator = apGraphics->GetMeshCreator();
|
||||
|
||||
mpHaloSourceBuffer = mpMeshCreator->CreateBoxVertexBuffer(1);
|
||||
|
||||
mvSize = avSize;
|
||||
mvAxis = cVector3f(0, 1, 0);
|
||||
|
||||
mColor = cColor(1, 1, 1, 1);
|
||||
mfForwardOffset = 0;
|
||||
mfHaloAlpha = 1.0f;
|
||||
|
||||
mType = eBillboardType_Point;
|
||||
|
||||
mpMaterial = NULL;
|
||||
|
||||
mlLastRenderCount = -1;
|
||||
|
||||
mpVtxBuffer = mpLowLevelGraphics->CreateVertexBuffer(
|
||||
eVertexFlag_Position | eVertexFlag_Color0 | eVertexFlag_Texture0 |
|
||||
eVertexFlag_Normal,
|
||||
eVertexBufferDrawType_Tri, eVertexBufferUsageType_Dynamic, 4, 6);
|
||||
|
||||
cVector3f vCoords[4] = {cVector3f((mvSize.x / 2), -(mvSize.y / 2), 0),
|
||||
cVector3f(-(mvSize.x / 2), -(mvSize.y / 2), 0),
|
||||
cVector3f(-(mvSize.x / 2), (mvSize.y / 2), 0),
|
||||
cVector3f((mvSize.x / 2), (mvSize.y / 2), 0)};
|
||||
|
||||
cVector3f vTexCoords[4] = {cVector3f(1, -1, 0),
|
||||
cVector3f(-1, -1, 0),
|
||||
cVector3f(-1, 1, 0),
|
||||
cVector3f(1, 1, 0)};
|
||||
for (int i = 0; i < 4; i++) {
|
||||
mpVtxBuffer->AddVertex(eVertexFlag_Position, vCoords[i]);
|
||||
mpVtxBuffer->AddColor(eVertexFlag_Color0, cColor(1, 1, 1, 1));
|
||||
mpVtxBuffer->AddVertex(eVertexFlag_Texture0, (vTexCoords[i] + cVector2f(1, 1)) / 2);
|
||||
mpVtxBuffer->AddVertex(eVertexFlag_Normal, cVector3f(0, 0, 1));
|
||||
}
|
||||
|
||||
for (int i = 0; i < 3; i++)
|
||||
mpVtxBuffer->AddIndex(i);
|
||||
for (int i = 2; i < 5; i++)
|
||||
mpVtxBuffer->AddIndex(i == 4 ? 0 : i);
|
||||
|
||||
mpVtxBuffer->Compile(eVertexCompileFlag_CreateTangents);
|
||||
|
||||
mbIsHalo = false;
|
||||
mbHaloSourceIsParent = false;
|
||||
mvHaloSourceSize = 1;
|
||||
|
||||
mBoundingVolume.SetSize(cVector3f(mvSize.x, mvSize.y, mvSize.x));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cBillboard::~cBillboard() {
|
||||
if (mpMaterial)
|
||||
mpMaterialManager->Destroy(mpMaterial);
|
||||
if (mpVtxBuffer)
|
||||
hplDelete(mpVtxBuffer);
|
||||
if (mpHaloSourceBuffer)
|
||||
hplDelete(mpHaloSourceBuffer);
|
||||
|
||||
if (mQueryObject.mpQuery)
|
||||
mpLowLevelGraphics->DestroyOcclusionQuery(mQueryObject.mpQuery);
|
||||
if (mMaxQueryObject.mpQuery)
|
||||
mpLowLevelGraphics->DestroyOcclusionQuery(mMaxQueryObject.mpQuery);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cBillboard::SetSize(const cVector2f &avSize) {
|
||||
mvSize = avSize;
|
||||
mBoundingVolume.SetSize(cVector3f(mvSize.x, mvSize.y, mvSize.x));
|
||||
|
||||
float *pPos = mpVtxBuffer->GetArray(eVertexFlag_Position);
|
||||
|
||||
cVector3f vCoords[4] = {cVector3f((mvSize.x / 2), -(mvSize.y / 2), 0),
|
||||
cVector3f(-(mvSize.x / 2), -(mvSize.y / 2), 0),
|
||||
cVector3f(-(mvSize.x / 2), (mvSize.y / 2), 0),
|
||||
cVector3f((mvSize.x / 2), (mvSize.y / 2), 0)};
|
||||
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
pPos[0] = vCoords[i].x;
|
||||
pPos[1] = vCoords[i].y;
|
||||
pPos[2] = vCoords[i].z;
|
||||
pPos += 4;
|
||||
}
|
||||
|
||||
mpVtxBuffer->UpdateData(eVertexFlag_Position, false);
|
||||
|
||||
if (mType == eBillboardType_Axis)
|
||||
SetAxis(mvAxis);
|
||||
|
||||
SetTransformUpdated();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cBillboard::SetType(eBillboardType aType) {
|
||||
mType = aType;
|
||||
|
||||
SetAxis(mvAxis);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cBillboard::SetAxis(const cVector3f &avAxis) {
|
||||
mvAxis = avAxis;
|
||||
mvAxis.Normalise();
|
||||
|
||||
// This is a quick fix so the bounding box is correct for non up-pointing axises
|
||||
if (mType == eBillboardType_Axis && mvAxis != cVector3f(0, 1, 0)) {
|
||||
float fMax = mvSize.x;
|
||||
if (fMax < mvSize.y)
|
||||
fMax = mvSize.y;
|
||||
|
||||
fMax *= kSqrt2f;
|
||||
|
||||
mBoundingVolume.SetSize(fMax);
|
||||
|
||||
SetTransformUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cBillboard::SetColor(const cColor &aColor) {
|
||||
if (mColor == aColor)
|
||||
return;
|
||||
|
||||
mColor = aColor;
|
||||
|
||||
float *pColors = mpVtxBuffer->GetArray(eVertexFlag_Color0);
|
||||
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
pColors[0] = mColor.r * mfHaloAlpha;
|
||||
pColors[1] = mColor.g * mfHaloAlpha;
|
||||
pColors[2] = mColor.b * mfHaloAlpha;
|
||||
pColors[3] = mColor.a * mfHaloAlpha;
|
||||
pColors += 4;
|
||||
}
|
||||
|
||||
mpVtxBuffer->UpdateData(eVertexFlag_Color0, false);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cBillboard::SetHaloAlpha(float afX) {
|
||||
if (mfHaloAlpha == afX) {
|
||||
return;
|
||||
}
|
||||
|
||||
mfHaloAlpha = afX;
|
||||
|
||||
float *pColors = mpVtxBuffer->GetArray(eVertexFlag_Color0);
|
||||
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
pColors[0] = mColor.r * mfHaloAlpha;
|
||||
pColors[1] = mColor.g * mfHaloAlpha;
|
||||
pColors[2] = mColor.b * mfHaloAlpha;
|
||||
pColors[3] = mColor.a * mfHaloAlpha;
|
||||
pColors += 4;
|
||||
}
|
||||
|
||||
mpVtxBuffer->UpdateData(eVertexFlag_Color0, false);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cBillboard::SetForwardOffset(float afOffset) {
|
||||
mfForwardOffset = afOffset;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cBillboard::SetMaterial(iMaterial *apMaterial) {
|
||||
mpMaterial = apMaterial;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cBoundingVolume *cBillboard::GetBoundingVolume() {
|
||||
return &mBoundingVolume;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cBillboard::UpdateGraphics(cCamera3D *apCamera, float afFrameTime, cRenderList *apRenderList) {
|
||||
if (mbIsHalo == false)
|
||||
return;
|
||||
|
||||
////////////////////////
|
||||
// Set the alpha
|
||||
float fAlpha = 0;
|
||||
|
||||
if (mlLastRenderCount == apRenderList->GetLastRenderCount()) {
|
||||
if (mMaxQueryObject.mpQuery->GetSampleCount() > 0) {
|
||||
fAlpha = (float)mQueryObject.mpQuery->GetSampleCount() /
|
||||
(float)mMaxQueryObject.mpQuery->GetSampleCount();
|
||||
}
|
||||
}
|
||||
SetHaloAlpha(fAlpha);
|
||||
mlLastRenderCount = apRenderList->GetRenderCount();
|
||||
|
||||
////////////////////////
|
||||
// Add the queries
|
||||
if (mbHaloSourceIsParent) {
|
||||
iRenderable *pParent = static_cast<iRenderable *>(GetEntityParent());
|
||||
if (pParent == NULL) {
|
||||
Error("Billboard %s has no parent!\n", msName.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
iVertexBuffer *pVtxBuffer = pParent->GetVertexBuffer();
|
||||
if (pVtxBuffer == NULL) {
|
||||
Error("Billboard '%s' parent '%s' as NULL vertex buffer!\n", msName.c_str(),
|
||||
pParent->GetName().c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
mQueryObject.mpMatrix = pParent->GetModelMatrix(apCamera);
|
||||
mQueryObject.mpVtxBuffer = pVtxBuffer;
|
||||
|
||||
mMaxQueryObject.mpMatrix = pParent->GetModelMatrix(apCamera);
|
||||
mMaxQueryObject.mpVtxBuffer = pVtxBuffer;
|
||||
} else {
|
||||
mQueryObject.mpMatrix = &GetWorldMatrix();
|
||||
mQueryObject.mpVtxBuffer = mpHaloSourceBuffer;
|
||||
|
||||
mMaxQueryObject.mpMatrix = &GetWorldMatrix();
|
||||
mMaxQueryObject.mpVtxBuffer = mpHaloSourceBuffer;
|
||||
}
|
||||
|
||||
mQueryObject.mbDepthTest = true;
|
||||
mMaxQueryObject.mbDepthTest = false;
|
||||
|
||||
apRenderList->AddOcclusionQuery(&mQueryObject);
|
||||
apRenderList->AddOcclusionQuery(&mMaxQueryObject);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cMatrixf *cBillboard::GetModelMatrix(cCamera3D *apCamera) {
|
||||
if (apCamera == NULL)
|
||||
return &GetWorldMatrix();
|
||||
|
||||
m_mtxTempTransform = GetWorldMatrix();
|
||||
cVector3f vForward, vRight, vUp;
|
||||
|
||||
cVector3f vCameraForward = apCamera->GetPosition() - GetWorldPosition();
|
||||
vCameraForward.Normalise();
|
||||
|
||||
if (mType == eBillboardType_Point) {
|
||||
vForward = vCameraForward;
|
||||
vRight = cMath::Vector3Cross(apCamera->GetViewMatrix().GetUp(), vForward);
|
||||
vUp = cMath::Vector3Cross(vForward, vRight);
|
||||
} else if (mType == eBillboardType_Axis) {
|
||||
vUp = cMath::MatrixMul(GetWorldMatrix().GetRotation(), mvAxis);
|
||||
vUp.Normalise();
|
||||
|
||||
if (vUp == vForward) {
|
||||
vRight = cMath::Vector3Cross(vUp, vCameraForward);
|
||||
Warning("Billboard Right vector is not correct! Contact programmer!\n");
|
||||
} else
|
||||
vRight = cMath::Vector3Cross(vUp, vCameraForward);
|
||||
|
||||
vRight.Normalise();
|
||||
vForward = cMath::Vector3Cross(vRight, vUp);
|
||||
|
||||
// vForward.Normalise();
|
||||
// vUp.Normalise();
|
||||
}
|
||||
|
||||
if (mfForwardOffset != 0) {
|
||||
cVector3f vPos = m_mtxTempTransform.GetTranslation();
|
||||
vPos += vCameraForward * mfForwardOffset;
|
||||
m_mtxTempTransform.SetTranslation(vPos);
|
||||
}
|
||||
|
||||
// Set right vector
|
||||
m_mtxTempTransform.m[0][0] = vRight.x;
|
||||
m_mtxTempTransform.m[1][0] = vRight.y;
|
||||
m_mtxTempTransform.m[2][0] = vRight.z;
|
||||
|
||||
// Set up vector
|
||||
m_mtxTempTransform.m[0][1] = vUp.x;
|
||||
m_mtxTempTransform.m[1][1] = vUp.y;
|
||||
m_mtxTempTransform.m[2][1] = vUp.z;
|
||||
|
||||
// Set forward vector
|
||||
m_mtxTempTransform.m[0][2] = vForward.x;
|
||||
m_mtxTempTransform.m[1][2] = vForward.y;
|
||||
m_mtxTempTransform.m[2][2] = vForward.z;
|
||||
|
||||
return &m_mtxTempTransform;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
int cBillboard::GetMatrixUpdateCount() {
|
||||
return GetTransformUpdateCount();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cBillboard::LoadXMLProperties(const tString asFile) {
|
||||
tString sNewFile = cString::SetFileExt(asFile, "bnt");
|
||||
tString sPath = mpFileSearcher->GetFilePath(sNewFile);
|
||||
if (sPath != "") {
|
||||
TiXmlDocument *pDoc = hplNew(TiXmlDocument, (sPath.c_str()));
|
||||
if (pDoc->LoadFile()) {
|
||||
TiXmlElement *pRootElem = pDoc->RootElement();
|
||||
|
||||
TiXmlElement *pMainElem = pRootElem->FirstChildElement("MAIN");
|
||||
if (pMainElem != NULL) {
|
||||
mType = ToType(pMainElem->Attribute("Type"));
|
||||
tString sMaterial = cString::ToString(pMainElem->Attribute("Material"), "");
|
||||
bool bUsesOffset = cString::ToBool(pMainElem->Attribute("UseOffset"), false);
|
||||
if (bUsesOffset == false)
|
||||
mfForwardOffset = 0;
|
||||
|
||||
/////////////////
|
||||
// Halo stuff
|
||||
bool bIsHalo = cString::ToBool(pMainElem->Attribute("IsHalo"), false);
|
||||
SetIsHalo(bIsHalo);
|
||||
|
||||
if (bIsHalo) {
|
||||
bool bHaloSourceIsParent = cString::ToBool(pMainElem->Attribute("HaloSourceIsParent"), false);
|
||||
SetHaloSourceIsParent(bHaloSourceIsParent);
|
||||
|
||||
if (bHaloSourceIsParent == false) {
|
||||
tString sSizeVec = cString::ToString(pMainElem->Attribute("HaloSourceSize"), "1 1 1");
|
||||
tFloatVec vSizeValues;
|
||||
cString::GetFloatVec(sSizeVec, vSizeValues, NULL);
|
||||
SetHaloSourceSize(cVector3f(vSizeValues[0], vSizeValues[1], vSizeValues[2]));
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////
|
||||
// Load material
|
||||
iMaterial *pMat = mpMaterialManager->CreateMaterial(sMaterial);
|
||||
if (pMat) {
|
||||
SetMaterial(pMat);
|
||||
} else {
|
||||
Error("Couldn't load material '%s' in billboard file '%s'",
|
||||
sMaterial.c_str(), sNewFile.c_str());
|
||||
}
|
||||
} else {
|
||||
Error("Cannot find main element in %s\n", sNewFile.c_str());
|
||||
}
|
||||
} else {
|
||||
Error("Couldn't load file '%s'\n", sNewFile.c_str());
|
||||
}
|
||||
hplDelete(pDoc);
|
||||
} else {
|
||||
Error("Couldn't find file '%s'\n", sNewFile.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cBillboard::IsVisible() {
|
||||
if (mColor.r <= 0 && mColor.g <= 0 && mColor.b <= 0)
|
||||
return false;
|
||||
|
||||
return IsRendered();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cBillboard::SetIsHalo(bool abX) {
|
||||
mbIsHalo = abX;
|
||||
|
||||
if (mbIsHalo) {
|
||||
mQueryObject.mpQuery = mpLowLevelGraphics->CreateOcclusionQuery();
|
||||
mMaxQueryObject.mpQuery = mpLowLevelGraphics->CreateOcclusionQuery();
|
||||
|
||||
mfHaloAlpha = 1; // THis is to make sure that the new alpha is set to the mesh.
|
||||
SetHaloAlpha(0);
|
||||
} else if (mQueryObject.mpQuery) {
|
||||
mpLowLevelGraphics->DestroyOcclusionQuery(mQueryObject.mpQuery);
|
||||
mpLowLevelGraphics->DestroyOcclusionQuery(mMaxQueryObject.mpQuery);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cBillboard::SetHaloSourceSize(const cVector3f &avSize) {
|
||||
mvHaloSourceSize = avSize;
|
||||
|
||||
UpdateSourceBufferSize();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cBillboard::SetHaloSourceIsParent(bool abX) {
|
||||
mbHaloSourceIsParent = abX;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PRIVATE METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
eBillboardType cBillboard::ToType(const char *apString) {
|
||||
if (apString == NULL)
|
||||
return eBillboardType_Point;
|
||||
|
||||
tString sType = cString::ToLowerCase(apString);
|
||||
|
||||
if (sType == "point")
|
||||
return eBillboardType_Point;
|
||||
else if (sType == "axis")
|
||||
return eBillboardType_Axis;
|
||||
|
||||
Warning("Invalid billboard type '%s'\n", apString);
|
||||
|
||||
return eBillboardType_Point;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cBillboard::UpdateSourceBufferSize() {
|
||||
int lNum = mpHaloSourceBuffer->GetVertexNum();
|
||||
float *pPositions = mpHaloSourceBuffer->GetArray(eVertexFlag_Position);
|
||||
|
||||
for (int i = 0; i < lNum; ++i) {
|
||||
// X
|
||||
if (pPositions[0] < 0)
|
||||
pPositions[0] = -mvHaloSourceSize.x * 0.5f;
|
||||
else
|
||||
pPositions[0] = mvHaloSourceSize.x * 0.5f;
|
||||
// Y
|
||||
if (pPositions[1] < 0)
|
||||
pPositions[1] = -mvHaloSourceSize.y * 0.5f;
|
||||
else
|
||||
pPositions[1] = mvHaloSourceSize.y * 0.5f;
|
||||
// Z
|
||||
if (pPositions[2] < 0)
|
||||
pPositions[2] = -mvHaloSourceSize.z * 0.5f;
|
||||
else
|
||||
pPositions[2] = mvHaloSourceSize.z * 0.5f;
|
||||
|
||||
pPositions += 4;
|
||||
}
|
||||
|
||||
mpHaloSourceBuffer->UpdateData(eVertexFlag_Position, false);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// SAVE OBJECT STUFF
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
kBeginSerialize(cSaveData_cBillboard, cSaveData_iRenderable)
|
||||
kSerializeVar(msMaterial, eSerializeType_String)
|
||||
|
||||
kSerializeVar(mType, eSerializeType_Int32)
|
||||
kSerializeVar(mvSize, eSerializeType_Vector3f)
|
||||
kSerializeVar(mvAxis, eSerializeType_Vector3f)
|
||||
kSerializeVar(mfForwardOffset, eSerializeType_Float32)
|
||||
kSerializeVar(mColor, eSerializeType_Color)
|
||||
kSerializeVar(mfHaloAlpha, eSerializeType_Float32)
|
||||
|
||||
kSerializeVar(mbIsHalo, eSerializeType_Bool)
|
||||
kSerializeVar(mvHaloSourceSize, eSerializeType_Vector3f)
|
||||
kSerializeVar(mbHaloSourceIsParent, eSerializeType_Bool)
|
||||
kEndSerialize()
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iSaveObject *cSaveData_cBillboard::CreateSaveObject(cSaveObjectHandler *apSaveObjectHandler, cGame *apGame) {
|
||||
cWorld3D *pWorld = apGame->GetScene()->GetWorld3D();
|
||||
|
||||
cBillboard *pBill = pWorld->CreateBillboard(msName, mvSize, msMaterial);
|
||||
|
||||
return pBill;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
int cSaveData_cBillboard::GetSaveCreatePrio() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iSaveData *cBillboard::CreateSaveData() {
|
||||
return hplNew(cSaveData_cBillboard, ());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cBillboard::SaveToSaveData(iSaveData *apSaveData) {
|
||||
kSaveData_SaveToBegin(cBillboard);
|
||||
|
||||
pData->msMaterial = mpMaterial == NULL ? "" : mpMaterial->GetName();
|
||||
|
||||
kSaveData_SaveTo(mType);
|
||||
kSaveData_SaveTo(mvSize);
|
||||
kSaveData_SaveTo(mvAxis);
|
||||
kSaveData_SaveTo(mfForwardOffset);
|
||||
kSaveData_SaveTo(mColor);
|
||||
kSaveData_SaveTo(mfHaloAlpha);
|
||||
|
||||
kSaveData_SaveTo(mbIsHalo);
|
||||
kSaveData_SaveTo(mvHaloSourceSize);
|
||||
kSaveData_SaveTo(mbHaloSourceIsParent);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cBillboard::LoadFromSaveData(iSaveData *apSaveData) {
|
||||
kSaveData_LoadFromBegin(cBillboard);
|
||||
|
||||
mType = (eBillboardType)pData->mType;
|
||||
kSaveData_LoadFrom(mvSize);
|
||||
kSaveData_LoadFrom(mvAxis);
|
||||
kSaveData_LoadFrom(mfForwardOffset);
|
||||
kSaveData_LoadFrom(mColor);
|
||||
kSaveData_LoadFrom(mfHaloAlpha);
|
||||
|
||||
SetIsHalo(pData->mbIsHalo);
|
||||
SetHaloSourceSize(pData->mvHaloSourceSize);
|
||||
SetHaloSourceIsParent(pData->mbHaloSourceIsParent);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cBillboard::SaveDataSetup(cSaveObjectHandler *apSaveObjectHandler, cGame *apGame) {
|
||||
kSaveData_SetupBegin(cBillboard);
|
||||
|
||||
if (mbIsHalo) {
|
||||
// Log("Setting up halo billboard '%s'\n",msName.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
} // namespace hpl
|
||||
187
engines/hpl1/engine/graphics/BillBoard.h
Normal file
187
engines/hpl1/engine/graphics/BillBoard.h
Normal file
@@ -0,0 +1,187 @@
|
||||
/* 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_BILLBOARD_H
|
||||
#define HPL_BILLBOARD_H
|
||||
|
||||
#include "RenderList.h"
|
||||
#include "hpl1/engine/graphics/GraphicsTypes.h"
|
||||
#include "hpl1/engine/graphics/Renderable.h"
|
||||
#include "hpl1/engine/math/MathTypes.h"
|
||||
#include "hpl1/engine/scene/Entity3D.h"
|
||||
#include "hpl1/engine/system/SystemTypes.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
enum eBillboardType {
|
||||
eBillboardType_Point,
|
||||
eBillboardType_Axis,
|
||||
eBillboardType_LastEnum
|
||||
};
|
||||
|
||||
class cMaterialManager;
|
||||
class cResources;
|
||||
class cGraphics;
|
||||
class cMeshCreator;
|
||||
class cFileSearcher;
|
||||
class iLowLevelGraphics;
|
||||
class iMaterial;
|
||||
class iVertexBuffer;
|
||||
class iOcclusionQuery;
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
kSaveData_ChildClass(iRenderable, cBillboard) {
|
||||
kSaveData_ClassInit(cBillboard) public : tString msMaterial;
|
||||
|
||||
int mType;
|
||||
cVector2f mvSize;
|
||||
cVector3f mvAxis;
|
||||
float mfForwardOffset;
|
||||
cColor mColor;
|
||||
float mfHaloAlpha;
|
||||
|
||||
bool mbIsHalo;
|
||||
cVector3f mvHaloSourceSize;
|
||||
bool mbHaloSourceIsParent;
|
||||
|
||||
virtual iSaveObject *CreateSaveObject(cSaveObjectHandler * apSaveObjectHandler, cGame * apGame);
|
||||
virtual int GetSaveCreatePrio();
|
||||
};
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
class cBillboard : public iRenderable {
|
||||
typedef iRenderable super;
|
||||
|
||||
public:
|
||||
cBillboard(const tString asName, const cVector2f &avSize, cResources *apResources,
|
||||
cGraphics *apGraphics);
|
||||
~cBillboard();
|
||||
|
||||
void SetMaterial(iMaterial *apMaterial);
|
||||
|
||||
void SetSize(const cVector2f &avSize);
|
||||
cVector2f GetSize() { return mvSize; }
|
||||
|
||||
void SetType(eBillboardType aType);
|
||||
eBillboardType GetType() { return mType; }
|
||||
|
||||
void SetAxis(const cVector3f &avAxis);
|
||||
cVector3f GetAxis() { return mvAxis; }
|
||||
|
||||
void SetForwardOffset(float afOffset);
|
||||
float GetForwardOffset() { return mfForwardOffset; }
|
||||
|
||||
void SetColor(const cColor &aColor);
|
||||
const cColor &GetColor() { return mColor; }
|
||||
|
||||
void SetHaloAlpha(float afX);
|
||||
float GetHaloAlpha() { return mfHaloAlpha; }
|
||||
|
||||
void LoadXMLProperties(const tString asFile);
|
||||
|
||||
/////////////////////////////////
|
||||
// Halo stuff
|
||||
void SetIsHalo(bool abX);
|
||||
bool IsHalo() { return mbIsHalo; }
|
||||
|
||||
void SetHaloSourceSize(const cVector3f &avSize);
|
||||
cVector3f GetHaloSourceSize() { return mvHaloSourceSize; }
|
||||
|
||||
void SetHaloSourceIsParent(bool abX);
|
||||
bool GetHaloSourceIsParent() { return mbHaloSourceIsParent; }
|
||||
|
||||
iOcclusionQuery *GetQuery() { return mQueryObject.mpQuery; }
|
||||
iOcclusionQuery *GetMaxQuery() { return mMaxQueryObject.mpQuery; }
|
||||
|
||||
/////////////////////////////////
|
||||
// Entity implementation
|
||||
tString GetEntityType() { return "Billboard"; }
|
||||
|
||||
bool IsVisible();
|
||||
void SetVisible(bool abVisible) { SetRendered(abVisible); }
|
||||
|
||||
// Renderable implementations
|
||||
iMaterial *GetMaterial() { return mpMaterial; }
|
||||
iVertexBuffer *GetVertexBuffer() { return mpVtxBuffer; }
|
||||
|
||||
void UpdateGraphics(cCamera3D *apCamera, float afFrameTime, cRenderList *apRenderList);
|
||||
|
||||
bool IsShadowCaster() { return false; }
|
||||
|
||||
cBoundingVolume *GetBoundingVolume();
|
||||
|
||||
cMatrixf *GetModelMatrix(cCamera3D *apCamera);
|
||||
|
||||
int GetMatrixUpdateCount();
|
||||
|
||||
eRenderableType GetRenderType() { return eRenderableType_ParticleSystem; }
|
||||
|
||||
// SaveObject implementation
|
||||
virtual iSaveData *CreateSaveData();
|
||||
virtual void SaveToSaveData(iSaveData *apSaveData);
|
||||
virtual void LoadFromSaveData(iSaveData *apSaveData);
|
||||
virtual void SaveDataSetup(cSaveObjectHandler *apSaveObjectHandler, cGame *apGame);
|
||||
|
||||
private:
|
||||
eBillboardType ToType(const char *apString);
|
||||
|
||||
void UpdateSourceBufferSize();
|
||||
|
||||
cMaterialManager *mpMaterialManager;
|
||||
cFileSearcher *mpFileSearcher;
|
||||
iLowLevelGraphics *mpLowLevelGraphics;
|
||||
cMeshCreator *mpMeshCreator;
|
||||
|
||||
iMaterial *mpMaterial;
|
||||
iVertexBuffer *mpVtxBuffer;
|
||||
|
||||
iVertexBuffer *mpHaloSourceBuffer;
|
||||
|
||||
cMatrixf m_mtxTempTransform;
|
||||
|
||||
eBillboardType mType;
|
||||
cVector2f mvSize;
|
||||
cVector3f mvAxis;
|
||||
|
||||
int mlLastRenderCount;
|
||||
|
||||
bool mbIsHalo;
|
||||
cVector3f mvHaloSourceSize;
|
||||
bool mbHaloSourceIsParent;
|
||||
cOcclusionQueryObject mQueryObject;
|
||||
cOcclusionQueryObject mMaxQueryObject;
|
||||
|
||||
float mfForwardOffset;
|
||||
cColor mColor;
|
||||
float mfHaloAlpha;
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_BILLBOARD_H
|
||||
162
engines/hpl1/engine/graphics/Bone.cpp
Normal file
162
engines/hpl1/engine/graphics/Bone.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/graphics/Bone.h"
|
||||
|
||||
#include "hpl1/engine/graphics/Skeleton.h"
|
||||
#include "hpl1/engine/math/Math.h"
|
||||
|
||||
#include "hpl1/engine/system/low_level_system.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cBone::cBone(const tString &asName, cSkeleton *apSkeleton) {
|
||||
msName = asName;
|
||||
mpSkeleton = apSkeleton;
|
||||
mpParent = NULL;
|
||||
|
||||
mbNeedsUpdate = true;
|
||||
|
||||
mlValue = 0;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cBone::~cBone() {
|
||||
STLDeleteAll(mlstChildren);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cBone *cBone::CreateChildBone(const tString &asName) {
|
||||
cBone *pBone = hplNew(cBone, (asName, mpSkeleton));
|
||||
pBone->mpParent = this;
|
||||
|
||||
mlstChildren.push_back(pBone);
|
||||
mpSkeleton->AddBone(pBone);
|
||||
|
||||
return pBone;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cBone::SetTransform(const cMatrixf &a_mtxTransform) {
|
||||
m_mtxTransform = a_mtxTransform;
|
||||
|
||||
NeedsUpdate();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
const cMatrixf &cBone::GetLocalTransform() {
|
||||
return m_mtxTransform;
|
||||
}
|
||||
|
||||
const cMatrixf &cBone::GetWorldTransform() {
|
||||
UpdateMatrix();
|
||||
|
||||
return m_mtxWorldTransform;
|
||||
}
|
||||
|
||||
const cMatrixf &cBone::GetInvWorldTransform() {
|
||||
UpdateMatrix();
|
||||
|
||||
return m_mtxInvWorldTransform;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cBone::Detach() {
|
||||
if (mpParent == NULL)
|
||||
return;
|
||||
|
||||
tBoneListIt it = mpParent->mlstChildren.begin();
|
||||
for (; it != mpParent->mlstChildren.end(); it++) {
|
||||
if (*it == this) {
|
||||
mpParent->mlstChildren.erase(it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
mpSkeleton->RemoveBone(this);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cBoneIterator cBone::GetChildIterator() {
|
||||
return cBoneIterator(&mlstChildren);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cBone::UpdateMatrix() {
|
||||
if (mbNeedsUpdate == false)
|
||||
return;
|
||||
|
||||
if (mpParent == NULL) {
|
||||
m_mtxWorldTransform = m_mtxTransform;
|
||||
} else {
|
||||
m_mtxWorldTransform = cMath::MatrixMul(mpParent->GetWorldTransform(), m_mtxTransform);
|
||||
}
|
||||
|
||||
m_mtxInvWorldTransform = cMath::MatrixInverse(m_mtxWorldTransform);
|
||||
|
||||
mbNeedsUpdate = false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PRIVATE METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cBone::NeedsUpdate() {
|
||||
mbNeedsUpdate = true;
|
||||
|
||||
tBoneListIt it = mlstChildren.begin();
|
||||
for (; it != mlstChildren.end(); it++) {
|
||||
cBone *pBone = *it;
|
||||
|
||||
pBone->NeedsUpdate();
|
||||
}
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
} // namespace hpl
|
||||
97
engines/hpl1/engine/graphics/Bone.h
Normal file
97
engines/hpl1/engine/graphics/Bone.h
Normal file
@@ -0,0 +1,97 @@
|
||||
/* 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_BONE_H
|
||||
#define HPL_BONE_H
|
||||
|
||||
#include "common/list.h"
|
||||
#include "hpl1/engine/graphics/GraphicsTypes.h"
|
||||
#include "hpl1/engine/math/MathTypes.h"
|
||||
#include "hpl1/engine/system/SystemTypes.h"
|
||||
#include "common/stablemap.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class cSkeleton;
|
||||
class cBone;
|
||||
|
||||
typedef Common::List<cBone *> tBoneList;
|
||||
typedef tBoneList::iterator tBoneListIt;
|
||||
|
||||
typedef cSTLIterator<cBone *, tBoneList, tBoneListIt> cBoneIterator;
|
||||
|
||||
class cBone {
|
||||
friend class cSkeleton;
|
||||
|
||||
public:
|
||||
cBone(const tString &asName, cSkeleton *apSkeleton);
|
||||
~cBone();
|
||||
|
||||
cBone *CreateChildBone(const tString &asName);
|
||||
|
||||
void SetTransform(const cMatrixf &a_mtxTransform);
|
||||
const cMatrixf &GetLocalTransform();
|
||||
const cMatrixf &GetWorldTransform();
|
||||
const cMatrixf &GetInvWorldTransform();
|
||||
|
||||
const tString &GetName() { return msName; }
|
||||
|
||||
cBoneIterator GetChildIterator();
|
||||
|
||||
void Detach();
|
||||
|
||||
cBone *GetParent() { return mpParent; }
|
||||
|
||||
// Needed for some loading stuff..
|
||||
int GetValue() { return mlValue; }
|
||||
void SetValue(int alVal) { mlValue = alVal; }
|
||||
|
||||
private:
|
||||
void NeedsUpdate();
|
||||
|
||||
void UpdateMatrix();
|
||||
|
||||
tString msName;
|
||||
|
||||
cMatrixf m_mtxTransform;
|
||||
|
||||
cMatrixf m_mtxWorldTransform;
|
||||
cMatrixf m_mtxInvWorldTransform;
|
||||
|
||||
cBone *mpParent;
|
||||
tBoneList mlstChildren;
|
||||
|
||||
cSkeleton *mpSkeleton;
|
||||
|
||||
bool mbNeedsUpdate;
|
||||
|
||||
int mlValue;
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_BONE_H
|
||||
98
engines/hpl1/engine/graphics/BoneState.cpp
Normal file
98
engines/hpl1/engine/graphics/BoneState.cpp
Normal file
@@ -0,0 +1,98 @@
|
||||
/* 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/graphics/BoneState.h"
|
||||
|
||||
#include "hpl1/engine/physics/PhysicsBody.h"
|
||||
|
||||
#include "hpl1/engine/math/Math.h"
|
||||
|
||||
#include "hpl1/engine/system/low_level_system.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cBoneState::cBoneState(const tString &asName, bool abAutoDeleteChildren) : cNode3D(asName, abAutoDeleteChildren) {
|
||||
mpBody = NULL;
|
||||
mpColliderBody = NULL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cBoneState::SetBody(iPhysicsBody *apBody) {
|
||||
mpBody = apBody;
|
||||
}
|
||||
iPhysicsBody *cBoneState::GetBody() {
|
||||
return mpBody;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cBoneState::SetColliderBody(iPhysicsBody *apBody) {
|
||||
mpColliderBody = apBody;
|
||||
}
|
||||
iPhysicsBody *cBoneState::GetColliderBody() {
|
||||
return mpColliderBody;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cBoneState::SetBodyMatrix(const cMatrixf &a_mtxBody) {
|
||||
m_mtxBody = a_mtxBody;
|
||||
m_mtxInvBody = cMath::MatrixInverse(m_mtxBody);
|
||||
}
|
||||
|
||||
const cMatrixf &cBoneState::GetBodyMatrix() {
|
||||
return m_mtxBody;
|
||||
}
|
||||
|
||||
const cMatrixf &cBoneState::GetInvBodyMatrix() {
|
||||
return m_mtxInvBody;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PRIVATE METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
} // namespace hpl
|
||||
61
engines/hpl1/engine/graphics/BoneState.h
Normal file
61
engines/hpl1/engine/graphics/BoneState.h
Normal file
@@ -0,0 +1,61 @@
|
||||
/* 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_BONE_STATE_H
|
||||
#define HPL_BONE_STATE_H
|
||||
|
||||
#include "hpl1/engine/scene/Node3D.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class iPhysicsBody;
|
||||
|
||||
class cBoneState : public cNode3D {
|
||||
public:
|
||||
cBoneState(const tString &asName, bool abAutoDeleteChildren);
|
||||
|
||||
void SetBody(iPhysicsBody *apBody);
|
||||
iPhysicsBody *GetBody();
|
||||
|
||||
void SetColliderBody(iPhysicsBody *apBody);
|
||||
iPhysicsBody *GetColliderBody();
|
||||
|
||||
void SetBodyMatrix(const cMatrixf &a_mtxBody);
|
||||
const cMatrixf &GetBodyMatrix();
|
||||
const cMatrixf &GetInvBodyMatrix();
|
||||
|
||||
private:
|
||||
iPhysicsBody *mpBody;
|
||||
cMatrixf m_mtxBody;
|
||||
cMatrixf m_mtxInvBody;
|
||||
|
||||
iPhysicsBody *mpColliderBody;
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_BONE_STATE_H
|
||||
178
engines/hpl1/engine/graphics/Color.cpp
Normal file
178
engines/hpl1/engine/graphics/Color.cpp
Normal file
@@ -0,0 +1,178 @@
|
||||
/* 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/graphics/Color.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cColor::cColor(float afR, float afG, float afB, float afA) {
|
||||
r = afR;
|
||||
g = afG;
|
||||
b = afB;
|
||||
a = afA;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cColor::cColor(float afR, float afG, float afB) {
|
||||
r = afR;
|
||||
g = afG;
|
||||
b = afB;
|
||||
a = 1;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cColor::cColor() {
|
||||
r = 0;
|
||||
g = 0;
|
||||
b = 0;
|
||||
a = 1;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cColor::cColor(float afVal) {
|
||||
r = afVal;
|
||||
g = afVal;
|
||||
b = afVal;
|
||||
a = 1;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cColor::cColor(float afVal, float afA) {
|
||||
r = afVal;
|
||||
g = afVal;
|
||||
b = afVal;
|
||||
a = afA;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cColor::FromVec(float *apV) {
|
||||
r = apV[0];
|
||||
g = apV[1];
|
||||
b = apV[2];
|
||||
a = apV[3];
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cColor cColor::operator*(float afVal) const {
|
||||
cColor col;
|
||||
col.r = r * afVal;
|
||||
col.g = g * afVal;
|
||||
col.b = b * afVal;
|
||||
col.a = a * afVal;
|
||||
return col;
|
||||
}
|
||||
|
||||
cColor cColor::operator/(float afVal) const {
|
||||
cColor col;
|
||||
col.r = r / afVal;
|
||||
col.g = g / afVal;
|
||||
col.b = b / afVal;
|
||||
col.a = a / afVal;
|
||||
return col;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cColor cColor::operator+(const cColor &aCol) const {
|
||||
return cColor(
|
||||
r + aCol.r,
|
||||
g + aCol.g,
|
||||
b + aCol.b,
|
||||
a + aCol.a);
|
||||
}
|
||||
|
||||
cColor cColor::operator-(const cColor &aCol) const {
|
||||
return cColor(
|
||||
r - aCol.r,
|
||||
g - aCol.g,
|
||||
b - aCol.b,
|
||||
a - aCol.a);
|
||||
}
|
||||
|
||||
cColor cColor::operator*(const cColor &aCol) const {
|
||||
return cColor(
|
||||
r * aCol.r,
|
||||
g * aCol.g,
|
||||
b * aCol.b,
|
||||
a * aCol.a);
|
||||
}
|
||||
|
||||
cColor cColor::operator/(const cColor &aCol) const {
|
||||
return cColor(
|
||||
r / aCol.r,
|
||||
g / aCol.g,
|
||||
b / aCol.b,
|
||||
a / aCol.a);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cColor::operator==(cColor aCol) const {
|
||||
if (r == aCol.r && g == aCol.g && b == aCol.b && a == aCol.a)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
tString cColor::ToString() const {
|
||||
char buf[512];
|
||||
snprintf(buf, 512, "%f : %f : %f : %f", r, g, b, a);
|
||||
tString str = buf;
|
||||
return str;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
tString cColor::ToFileString() const {
|
||||
char buf[512];
|
||||
snprintf(buf, 512, "%g %g %g %g", r, g, b, a);
|
||||
tString str = buf;
|
||||
return str;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
} // namespace hpl
|
||||
72
engines/hpl1/engine/graphics/Color.h
Normal file
72
engines/hpl1/engine/graphics/Color.h
Normal file
@@ -0,0 +1,72 @@
|
||||
/* 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_COLOR_H
|
||||
#define HPL_COLOR_H
|
||||
|
||||
#include "common/array.h"
|
||||
#include "common/list.h"
|
||||
#include "hpl1/engine/system/SystemTypes.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class cColor {
|
||||
public:
|
||||
float r, g, b, a;
|
||||
|
||||
cColor(float afR, float afG, float afB, float afA);
|
||||
cColor(float afR, float afG, float afB);
|
||||
cColor();
|
||||
cColor(float afVal);
|
||||
cColor(float afVal, float afA);
|
||||
|
||||
cColor operator*(float afVal) const;
|
||||
cColor operator/(float afVal) const;
|
||||
|
||||
cColor operator+(const cColor &aCol) const;
|
||||
cColor operator-(const cColor &aCol) const;
|
||||
cColor operator*(const cColor &aCol) const;
|
||||
cColor operator/(const cColor &aCol) const;
|
||||
|
||||
bool operator==(cColor aCol) const;
|
||||
|
||||
tString ToString() const;
|
||||
|
||||
tString ToFileString() const;
|
||||
|
||||
void FromVec(float *apV);
|
||||
};
|
||||
|
||||
typedef Common::List<cColor> tColorList;
|
||||
typedef tColorList::iterator tColorListIt;
|
||||
|
||||
typedef Common::Array<cColor> tColorVec;
|
||||
typedef tColorVec::iterator tColorVecIt;
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_COLOR_H
|
||||
50
engines/hpl1/engine/graphics/GPUProgram.cpp
Normal file
50
engines/hpl1/engine/graphics/GPUProgram.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
/* 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/graphics/GPUProgram.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
bool iGpuProgram::mbDebugInfo = false;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
} // namespace hpl
|
||||
109
engines/hpl1/engine/graphics/GPUProgram.h
Normal file
109
engines/hpl1/engine/graphics/GPUProgram.h
Normal file
@@ -0,0 +1,109 @@
|
||||
/* 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_H
|
||||
#define HPL_GPU_PROGRAM_H
|
||||
|
||||
#include "hpl1/engine/graphics/GraphicsTypes.h"
|
||||
#include "hpl1/engine/math/MathTypes.h"
|
||||
#include "hpl1/engine/resources/ResourceBase.h"
|
||||
#include "hpl1/engine/system/SystemTypes.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class iTexture;
|
||||
|
||||
enum eGpuProgramType {
|
||||
eGpuProgramType_Vertex,
|
||||
eGpuProgramType_Fragment,
|
||||
eGpuProgramType_LastEnum
|
||||
};
|
||||
|
||||
enum eGpuProgramMatrix {
|
||||
eGpuProgramMatrix_View,
|
||||
eGpuProgramMatrix_Projection,
|
||||
eGpuProgramMatrix_Texture,
|
||||
eGpuProgramMatrix_ViewProjection,
|
||||
eGpuProgramMatrix_LastEnum
|
||||
};
|
||||
|
||||
enum eGpuProgramMatrixOp {
|
||||
eGpuProgramMatrixOp_Identity,
|
||||
eGpuProgramMatrixOp_Inverse,
|
||||
eGpuProgramMatrixOp_Transpose,
|
||||
eGpuProgramMatrixOp_InverseTranspose,
|
||||
eGpuProgramMatrixOp_LastEnum
|
||||
};
|
||||
|
||||
class iGpuProgram : public iResourceBase {
|
||||
public:
|
||||
iGpuProgram(const tString &asName) : iResourceBase(asName, 0) {
|
||||
}
|
||||
virtual ~iGpuProgram() {}
|
||||
|
||||
static void SetLogDebugInformation(bool abX) { mbDebugInfo = abX; }
|
||||
|
||||
/**
|
||||
* Bind the program to the GPU
|
||||
*/
|
||||
virtual void Bind() = 0;
|
||||
/**
|
||||
* Unbind the program to the GPU
|
||||
*/
|
||||
virtual void UnBind() = 0;
|
||||
|
||||
virtual bool SetFloat(const tString &asName, float afX) = 0;
|
||||
|
||||
bool SetVec2f(const tString &asName, const cVector2f avVec) {
|
||||
return SetVec2f(asName, avVec.x, avVec.y);
|
||||
}
|
||||
virtual bool SetVec2f(const tString &asName, float afX, float afY) = 0;
|
||||
|
||||
bool SetVec3f(const tString &asName, const cVector3f &avVec) {
|
||||
return SetVec3f(asName, avVec.x, avVec.y, avVec.z);
|
||||
}
|
||||
bool SetColor3f(const tString &asName, const cColor &aCol) {
|
||||
return SetVec3f(asName, aCol.r, aCol.g, aCol.b);
|
||||
}
|
||||
virtual bool SetVec3f(const tString &asName, float afX, float afY, float afZ) = 0;
|
||||
|
||||
bool SetColor4f(const tString &asName, const cColor &aCol) {
|
||||
return SetVec4f(asName, aCol.r, aCol.g, aCol.b, aCol.a);
|
||||
}
|
||||
virtual bool SetVec4f(const tString &asName, float afX, float afY, float afZ, float afW) = 0;
|
||||
|
||||
virtual bool SetMatrixf(const tString &asName, const cMatrixf &mMtx) = 0;
|
||||
virtual bool SetMatrixf(const tString &asName, eGpuProgramMatrix mType,
|
||||
eGpuProgramMatrixOp mOp) = 0;
|
||||
|
||||
protected:
|
||||
static bool mbDebugInfo;
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_GPU_PROGRAM_H
|
||||
73
engines/hpl1/engine/graphics/GfxObject.cpp
Normal file
73
engines/hpl1/engine/graphics/GfxObject.cpp
Normal file
@@ -0,0 +1,73 @@
|
||||
/* 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/graphics/GfxObject.h"
|
||||
|
||||
#include "hpl1/engine/graphics/Material.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cGfxObject::cGfxObject(iMaterial *apMat, const tString &asFile, bool abIsImage) {
|
||||
mpMat = apMat;
|
||||
|
||||
msSourceFile = asFile;
|
||||
|
||||
mbIsImage = abIsImage;
|
||||
|
||||
if (mbIsImage) {
|
||||
mvVtx = apMat->GetImage(eMaterialTexture_Diffuse)->GetVertexVecCopy(0, -1);
|
||||
} else {
|
||||
mvVtx.push_back(cVertex(cVector3f(0, 0, 0), cVector2f(0, 0), cColor(1, 1)));
|
||||
mvVtx.push_back(cVertex(cVector3f(1, 0, 0), cVector2f(1, 0), cColor(1, 1)));
|
||||
mvVtx.push_back(cVertex(cVector3f(1, 1, 0), cVector2f(1, 1), cColor(1, 1)));
|
||||
mvVtx.push_back(cVertex(cVector3f(0, 1, 0), cVector2f(0, 1), cColor(1, 1)));
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cGfxObject::~cGfxObject() {
|
||||
hplDelete(mpMat);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
} // namespace hpl
|
||||
65
engines/hpl1/engine/graphics/GfxObject.h
Normal file
65
engines/hpl1/engine/graphics/GfxObject.h
Normal file
@@ -0,0 +1,65 @@
|
||||
/* 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_GFX_OBJECT_H
|
||||
#define HPL_GFX_OBJECT_H
|
||||
|
||||
#include "common/array.h"
|
||||
#include "hpl1/engine/graphics/GraphicsTypes.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class iMaterial;
|
||||
|
||||
class cGfxObject {
|
||||
public:
|
||||
cGfxObject(iMaterial *apMat, const tString &asFile, bool abIsImage);
|
||||
~cGfxObject();
|
||||
|
||||
iMaterial *GetMaterial() const { return mpMat; }
|
||||
cVertex *GetVtxPtr(int alNum) { return &mvVtx[alNum]; }
|
||||
tVertexVec *GetVertexVec() { return &mvVtx; }
|
||||
|
||||
const tString &GetSourceFile() { return msSourceFile; }
|
||||
|
||||
bool IsImage() { return mbIsImage; }
|
||||
|
||||
private:
|
||||
tVertexVec mvVtx;
|
||||
iMaterial *mpMat;
|
||||
// float mfZ;
|
||||
bool mbIsImage;
|
||||
|
||||
tString msSourceFile;
|
||||
};
|
||||
|
||||
typedef Common::Array<cGfxObject> tGfxObjectVec;
|
||||
typedef tGfxObjectVec::iterator tGfxObjectVecIt;
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_GFX_OBJECT_H
|
||||
186
engines/hpl1/engine/graphics/Graphics.cpp
Normal file
186
engines/hpl1/engine/graphics/Graphics.cpp
Normal file
@@ -0,0 +1,186 @@
|
||||
/* 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/graphics/Graphics.h"
|
||||
|
||||
#include "hpl1/engine/game/Updateable.h"
|
||||
#include "hpl1/engine/graphics/GraphicsDrawer.h"
|
||||
#include "hpl1/engine/graphics/LowLevelGraphics.h"
|
||||
#include "hpl1/engine/graphics/MaterialHandler.h"
|
||||
#include "hpl1/engine/graphics/MeshCreator.h"
|
||||
#include "hpl1/engine/graphics/RenderList.h"
|
||||
#include "hpl1/engine/graphics/Renderer2D.h"
|
||||
#include "hpl1/engine/graphics/Renderer3D.h"
|
||||
#include "hpl1/engine/graphics/RendererPostEffects.h"
|
||||
#include "hpl1/engine/resources/Resources.h"
|
||||
#include "hpl1/engine/resources/low_level_resources.h"
|
||||
#include "hpl1/engine/system/low_level_system.h"
|
||||
|
||||
// 2D Materials
|
||||
#include "hpl1/engine/graphics/Material_BumpSpec2D.h"
|
||||
#include "hpl1/engine/graphics/Material_Diffuse2D.h"
|
||||
#include "hpl1/engine/graphics/Material_DiffuseAdditive2D.h"
|
||||
#include "hpl1/engine/graphics/Material_DiffuseAlpha2D.h"
|
||||
#include "hpl1/engine/graphics/Material_FontNormal.h"
|
||||
#include "hpl1/engine/graphics/Material_Smoke2D.h"
|
||||
|
||||
// 3D Materials
|
||||
#include "hpl1/engine/graphics/Material_Additive.h"
|
||||
#include "hpl1/engine/graphics/Material_Alpha.h"
|
||||
#include "hpl1/engine/graphics/Material_Bump.h"
|
||||
#include "hpl1/engine/graphics/Material_BumpColorSpec.h"
|
||||
#include "hpl1/engine/graphics/Material_BumpSpec.h"
|
||||
#include "hpl1/engine/graphics/Material_Diffuse.h"
|
||||
#include "hpl1/engine/graphics/Material_DiffuseSpec.h"
|
||||
#include "hpl1/engine/graphics/Material_EnvMap_Reflect.h"
|
||||
#include "hpl1/engine/graphics/Material_Flat.h"
|
||||
#include "hpl1/engine/graphics/Material_Modulative.h"
|
||||
#include "hpl1/engine/graphics/Material_ModulativeX2.h"
|
||||
#include "hpl1/engine/graphics/Material_Water.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cGraphics::cGraphics(iLowLevelGraphics *apLowLevelGraphics, LowLevelResources *apLowLevelResources) {
|
||||
mpLowLevelGraphics = apLowLevelGraphics;
|
||||
mpLowLevelResources = apLowLevelResources;
|
||||
|
||||
mpDrawer = NULL;
|
||||
mpMeshCreator = NULL;
|
||||
mpMaterialHandler = NULL;
|
||||
mpRenderer2D = NULL;
|
||||
mpRenderer3D = NULL;
|
||||
mpRendererPostEffects = NULL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cGraphics::~cGraphics() {
|
||||
Log("Exiting Graphics Module\n");
|
||||
Log("--------------------------------------------------------\n");
|
||||
|
||||
hplDelete(mpRenderer2D);
|
||||
hplDelete(mpRenderer3D);
|
||||
hplDelete(mpRendererPostEffects);
|
||||
hplDelete(mpDrawer);
|
||||
hplDelete(mpMeshCreator);
|
||||
hplDelete(mpMaterialHandler);
|
||||
hplDelete(mpRenderList);
|
||||
|
||||
Log("--------------------------------------------------------\n\n");
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cGraphics::Init(int alWidth, int alHeight, int alBpp, int abFullscreen,
|
||||
int alMultisampling, const tString &asWindowCaption,
|
||||
cResources *apResources) {
|
||||
Log("Initializing Graphics Module\n");
|
||||
Log("--------------------------------------------------------\n");
|
||||
|
||||
// Setup the graphic directories:
|
||||
apResources->AddResourceDir("core/programs");
|
||||
apResources->AddResourceDir("core/textures");
|
||||
|
||||
Log(" Init low level graphics\n");
|
||||
mpLowLevelGraphics->Init(alWidth, alHeight, alBpp, abFullscreen, alMultisampling, asWindowCaption);
|
||||
|
||||
Log(" Creating graphic systems\n");
|
||||
mpMaterialHandler = hplNew(cMaterialHandler, (this, apResources));
|
||||
mpDrawer = hplNew(cGraphicsDrawer, (mpLowLevelGraphics, mpMaterialHandler, apResources));
|
||||
mpRenderer2D = hplNew(cRenderer2D, (mpLowLevelGraphics, apResources, mpDrawer));
|
||||
mpRenderList = hplNew(cRenderList, (this));
|
||||
mpMeshCreator = hplNew(cMeshCreator, (mpLowLevelGraphics, apResources));
|
||||
mpRenderer3D = hplNew(cRenderer3D, (mpLowLevelGraphics, apResources, mpMeshCreator, mpRenderList));
|
||||
mpRendererPostEffects = hplNew(cRendererPostEffects, (mpLowLevelGraphics, apResources, mpRenderList,
|
||||
mpRenderer3D));
|
||||
mpRenderer3D->SetPostEffects(mpRendererPostEffects);
|
||||
|
||||
// Add all the materials.
|
||||
// 2D
|
||||
Log(" Adding engine materials\n");
|
||||
mpMaterialHandler->Add(hplNew(cMaterialType_BumpSpec2D, ()));
|
||||
mpMaterialHandler->Add(hplNew(cMaterialType_DiffuseAdditive2D, ()));
|
||||
mpMaterialHandler->Add(hplNew(cMaterialType_DiffuseAlpha2D, ()));
|
||||
mpMaterialHandler->Add(hplNew(cMaterialType_Diffuse2D, ()));
|
||||
mpMaterialHandler->Add(hplNew(cMaterialType_Smoke2D, ()));
|
||||
mpMaterialHandler->Add(hplNew(cMaterialType_FontNormal, ()));
|
||||
|
||||
// 3D
|
||||
mpMaterialHandler->Add(hplNew(cMaterialType_Diffuse, ()));
|
||||
mpMaterialHandler->Add(hplNew(cMaterialType_Bump, ()));
|
||||
mpMaterialHandler->Add(hplNew(cMaterialType_DiffuseSpec, ()));
|
||||
mpMaterialHandler->Add(hplNew(cMaterialType_BumpSpec, ()));
|
||||
mpMaterialHandler->Add(hplNew(cMaterialType_BumpColorSpec, ()));
|
||||
|
||||
mpMaterialHandler->Add(hplNew(cMaterialType_Additive, ()));
|
||||
mpMaterialHandler->Add(hplNew(cMaterialType_Alpha, ()));
|
||||
mpMaterialHandler->Add(hplNew(cMaterialType_Flat, ()));
|
||||
mpMaterialHandler->Add(hplNew(cMaterialType_Modulative, ()));
|
||||
mpMaterialHandler->Add(hplNew(cMaterialType_ModulativeX2, ()));
|
||||
|
||||
mpMaterialHandler->Add(hplNew(cMaterialType_EnvMap_Reflect, ()));
|
||||
|
||||
mpMaterialHandler->Add(hplNew(cMaterialType_Water, ()));
|
||||
|
||||
Log("--------------------------------------------------------\n\n");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iLowLevelGraphics *cGraphics::GetLowLevel() {
|
||||
return mpLowLevelGraphics;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cGraphicsDrawer *cGraphics::GetDrawer() {
|
||||
return mpDrawer;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cRenderer2D *cGraphics::GetRenderer2D() {
|
||||
return mpRenderer2D;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
} // namespace hpl
|
||||
86
engines/hpl1/engine/graphics/Graphics.h
Normal file
86
engines/hpl1/engine/graphics/Graphics.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_GRAPHICS_H
|
||||
#define HPL_GRAPHICS_H
|
||||
|
||||
#include "hpl1/engine/system/SystemTypes.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class cResources;
|
||||
class cRenderer2D;
|
||||
class cRenderer3D;
|
||||
class cRendererPostEffects;
|
||||
class cRenderList;
|
||||
class cGraphicsDrawer;
|
||||
class LowLevelResources;
|
||||
class iLowLevelGraphics;
|
||||
class cMeshCreator;
|
||||
class cMaterialHandler;
|
||||
|
||||
class cGraphics {
|
||||
public:
|
||||
cGraphics(iLowLevelGraphics *apLowLevelGraphics, LowLevelResources *apLowLevelResources);
|
||||
~cGraphics();
|
||||
|
||||
bool Init(int alWidth, int alHeight, int alBpp, int abFullscreen, int alMultisampling,
|
||||
const tString &asWindowCaption, cResources *apResources);
|
||||
|
||||
/**
|
||||
* Get low level graphics routines
|
||||
* \return pointer to the low level class
|
||||
*/
|
||||
iLowLevelGraphics *GetLowLevel();
|
||||
|
||||
/**
|
||||
* Get the drawer
|
||||
* \return
|
||||
*/
|
||||
cGraphicsDrawer *GetDrawer();
|
||||
|
||||
cRenderer2D *GetRenderer2D();
|
||||
cRenderer3D *GetRenderer3D() { return mpRenderer3D; }
|
||||
cRendererPostEffects *GetRendererPostEffects() { return mpRendererPostEffects; }
|
||||
cMeshCreator *GetMeshCreator() { return mpMeshCreator; }
|
||||
cMaterialHandler *GetMaterialHandler() { return mpMaterialHandler; }
|
||||
|
||||
private:
|
||||
iLowLevelGraphics *mpLowLevelGraphics;
|
||||
LowLevelResources *mpLowLevelResources;
|
||||
cGraphicsDrawer *mpDrawer;
|
||||
cMeshCreator *mpMeshCreator;
|
||||
cMaterialHandler *mpMaterialHandler;
|
||||
cRenderer2D *mpRenderer2D;
|
||||
cRenderer3D *mpRenderer3D;
|
||||
cRendererPostEffects *mpRendererPostEffects;
|
||||
cRenderList *mpRenderList;
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_GRAPHICS_H
|
||||
422
engines/hpl1/engine/graphics/GraphicsDrawer.cpp
Normal file
422
engines/hpl1/engine/graphics/GraphicsDrawer.cpp
Normal file
@@ -0,0 +1,422 @@
|
||||
/* 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/graphics/GraphicsDrawer.h"
|
||||
|
||||
#include "hpl1/engine/graphics/GfxObject.h"
|
||||
#include "hpl1/engine/graphics/LowLevelGraphics.h"
|
||||
#include "hpl1/engine/graphics/Material.h"
|
||||
#include "hpl1/engine/graphics/MaterialHandler.h"
|
||||
#include "hpl1/engine/resources/FrameBitmap.h"
|
||||
#include "hpl1/engine/resources/ResourceImage.h"
|
||||
#include "hpl1/engine/resources/TextureManager.h"
|
||||
#include "hpl1/engine/system/low_level_system.h"
|
||||
|
||||
#include "hpl1/engine/math/Math.h"
|
||||
|
||||
#include "hpl1/engine/resources/ImageManager.h"
|
||||
#include "hpl1/engine/resources/Resources.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cGraphicsDrawer::cGraphicsDrawer(iLowLevelGraphics *apLowLevelGraphics, cMaterialHandler *apMaterialHandler,
|
||||
cResources *apResources) {
|
||||
mpLowLevelGraphics = apLowLevelGraphics;
|
||||
mpMaterialHandler = apMaterialHandler;
|
||||
mpResources = apResources;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cGraphicsDrawer::~cGraphicsDrawer() {
|
||||
ClearBackgrounds();
|
||||
|
||||
STLDeleteAll(mlstGfxObjects);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iMaterial *cGfxBufferObject::GetMaterial() const {
|
||||
return mpObject->GetMaterial();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cGfxBufferCompare::operator()(const cGfxBufferObject &aObjectA, const cGfxBufferObject &aObjectB) const {
|
||||
if (aObjectA.GetZ() != aObjectB.GetZ()) {
|
||||
return aObjectA.GetZ() < aObjectB.GetZ();
|
||||
} else if (aObjectA.GetMaterial()->GetTexture(eMaterialTexture_Diffuse) !=
|
||||
aObjectB.GetMaterial()->GetTexture(eMaterialTexture_Diffuse)) {
|
||||
return aObjectA.GetMaterial()->GetTexture(eMaterialTexture_Diffuse) >
|
||||
aObjectB.GetMaterial()->GetTexture(eMaterialTexture_Diffuse);
|
||||
} else if (aObjectA.GetMaterial()->GetType(eMaterialRenderType_Diffuse) !=
|
||||
aObjectB.GetMaterial()->GetType(eMaterialRenderType_Diffuse)) {
|
||||
return aObjectA.GetMaterial()->GetType(eMaterialRenderType_Diffuse) >
|
||||
aObjectB.GetMaterial()->GetType(eMaterialRenderType_Diffuse);
|
||||
} else {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
static void FlushImage(cGfxObject *apObject) {
|
||||
if (apObject->IsImage()) {
|
||||
cResourceImage *pImage = apObject->GetMaterial()->GetImage(eMaterialTexture_Diffuse);
|
||||
pImage->GetFrameBitmap()->FlushToTexture();
|
||||
}
|
||||
}
|
||||
|
||||
void cGraphicsDrawer::DrawGfxObject(cGfxObject *apObject, const cVector3f &avPos,
|
||||
const cVector2f &avSize, const cColor &aColor,
|
||||
bool abFlipH, bool abFlipV, float afAngle) {
|
||||
FlushImage(apObject);
|
||||
|
||||
cGfxBufferObject BuffObj;
|
||||
BuffObj.mpObject = apObject;
|
||||
BuffObj.mvTransform = avPos;
|
||||
BuffObj.mvSize = avSize;
|
||||
BuffObj.mColor = aColor;
|
||||
BuffObj.mbFlipH = abFlipH;
|
||||
BuffObj.mbFlipV = abFlipV;
|
||||
BuffObj.mfAngle = afAngle;
|
||||
|
||||
BuffObj.mbIsColorAndSize = true;
|
||||
|
||||
m_setGfxBuffer.insert(BuffObj);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cGraphicsDrawer::DrawGfxObject(cGfxObject *apObject, const cVector3f &avPos) {
|
||||
FlushImage(apObject);
|
||||
|
||||
cGfxBufferObject BuffObj;
|
||||
BuffObj.mpObject = apObject;
|
||||
BuffObj.mvTransform = avPos;
|
||||
BuffObj.mbIsColorAndSize = false;
|
||||
|
||||
m_setGfxBuffer.insert(BuffObj);
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cGraphicsDrawer::DrawAll() {
|
||||
// Set all states
|
||||
mpLowLevelGraphics->SetDepthTestActive(false);
|
||||
mpLowLevelGraphics->SetIdentityMatrix(eMatrix_ModelView);
|
||||
|
||||
mpLowLevelGraphics->SetOrthoProjection(mpLowLevelGraphics->GetVirtualSize(), -1000, 1000);
|
||||
|
||||
int lIdxAdd = 0;
|
||||
iMaterial *pPrevMat = NULL;
|
||||
iMaterial *pMat = NULL;
|
||||
const cGfxBufferObject *pObj = NULL;
|
||||
tGfxBufferSetIt ObjectIt = m_setGfxBuffer.begin();
|
||||
|
||||
if (ObjectIt != m_setGfxBuffer.end())
|
||||
pMat = ObjectIt->GetMaterial();
|
||||
|
||||
while (ObjectIt != m_setGfxBuffer.end()) {
|
||||
if (pMat->StartRendering(eMaterialRenderType_Diffuse, NULL, NULL) == false) {
|
||||
ObjectIt++;
|
||||
if (ObjectIt != m_setGfxBuffer.end())
|
||||
pMat = ObjectIt->GetMaterial();
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
do {
|
||||
pObj = &(*ObjectIt);
|
||||
if (pObj->mbIsColorAndSize) {
|
||||
cVector3f vPos[4];
|
||||
float fW = pObj->mvSize.x * 0.5f;
|
||||
float fH = pObj->mvSize.y * 0.5f;
|
||||
cMatrixf mtxTrans = cMath::MatrixTranslate(pObj->mvTransform + cVector3f(fW, fH, 0));
|
||||
vPos[0] = cVector3f(-fW, -fH, 0);
|
||||
vPos[1] = cVector3f(fW, -fH, 0);
|
||||
vPos[2] = cVector3f(fW, fH, 0);
|
||||
vPos[3] = cVector3f(-fW, fH, 0);
|
||||
|
||||
if (pObj->mfAngle != 0) {
|
||||
cMatrixf mtxRot = cMath::MatrixRotateZ(pObj->mfAngle);
|
||||
vPos[0] = cMath::MatrixMul(mtxRot, vPos[0]);
|
||||
vPos[1] = cMath::MatrixMul(mtxRot, vPos[1]);
|
||||
vPos[2] = cMath::MatrixMul(mtxRot, vPos[2]);
|
||||
vPos[3] = cMath::MatrixMul(mtxRot, vPos[3]);
|
||||
}
|
||||
|
||||
vPos[0] = cMath::MatrixMul(mtxTrans, vPos[0]);
|
||||
vPos[1] = cMath::MatrixMul(mtxTrans, vPos[1]);
|
||||
vPos[2] = cMath::MatrixMul(mtxTrans, vPos[2]);
|
||||
vPos[3] = cMath::MatrixMul(mtxTrans, vPos[3]);
|
||||
|
||||
if (pObj->mbFlipH) {
|
||||
mpLowLevelGraphics->AddVertexToBatch_Size2D(pObj->mpObject->GetVtxPtr(0),
|
||||
&vPos[0],
|
||||
&pObj->mColor,
|
||||
0, 0);
|
||||
mpLowLevelGraphics->AddVertexToBatch_Size2D(pObj->mpObject->GetVtxPtr(1),
|
||||
&vPos[1],
|
||||
&pObj->mColor,
|
||||
0, 0);
|
||||
mpLowLevelGraphics->AddVertexToBatch_Size2D(pObj->mpObject->GetVtxPtr(2),
|
||||
&vPos[2],
|
||||
&pObj->mColor,
|
||||
0, 0);
|
||||
mpLowLevelGraphics->AddVertexToBatch_Size2D(pObj->mpObject->GetVtxPtr(3),
|
||||
&vPos[3],
|
||||
&pObj->mColor,
|
||||
pObj->mvSize.x, pObj->mvSize.y);
|
||||
} else {
|
||||
mpLowLevelGraphics->AddVertexToBatch_Size2D(pObj->mpObject->GetVtxPtr(0),
|
||||
&vPos[0],
|
||||
&pObj->mColor,
|
||||
0, 0);
|
||||
mpLowLevelGraphics->AddVertexToBatch_Size2D(pObj->mpObject->GetVtxPtr(1),
|
||||
&vPos[1],
|
||||
&pObj->mColor,
|
||||
0, 0);
|
||||
mpLowLevelGraphics->AddVertexToBatch_Size2D(pObj->mpObject->GetVtxPtr(2),
|
||||
&vPos[2],
|
||||
&pObj->mColor,
|
||||
0, 0);
|
||||
mpLowLevelGraphics->AddVertexToBatch_Size2D(pObj->mpObject->GetVtxPtr(3),
|
||||
&vPos[3],
|
||||
&pObj->mColor,
|
||||
0, 0);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
mpLowLevelGraphics->AddIndexToBatch(lIdxAdd + i);
|
||||
} else {
|
||||
for (int i = 0; i < (int)pObj->mpObject->GetVertexVec()->size(); i++) {
|
||||
mpLowLevelGraphics->AddVertexToBatch(pObj->mpObject->GetVtxPtr(i),
|
||||
&pObj->mvTransform);
|
||||
mpLowLevelGraphics->AddIndexToBatch(lIdxAdd + i);
|
||||
}
|
||||
}
|
||||
lIdxAdd += (int)pObj->mpObject->GetVertexVec()->size();
|
||||
|
||||
pPrevMat = pMat;
|
||||
ObjectIt++;
|
||||
|
||||
if (ObjectIt == m_setGfxBuffer.end()) {
|
||||
pMat = NULL;
|
||||
break;
|
||||
} else {
|
||||
pMat = ObjectIt->GetMaterial();
|
||||
}
|
||||
} while (pMat->GetType(eMaterialRenderType_Diffuse) ==
|
||||
pPrevMat->GetType(eMaterialRenderType_Diffuse) &&
|
||||
pMat->GetTexture(eMaterialTexture_Diffuse) ==
|
||||
pPrevMat->GetTexture(eMaterialTexture_Diffuse));
|
||||
|
||||
lIdxAdd = 0;
|
||||
|
||||
do {
|
||||
mpLowLevelGraphics->FlushQuadBatch(pPrevMat->GetBatchFlags(eMaterialRenderType_Diffuse), false);
|
||||
} while (pPrevMat->NextPass(eMaterialRenderType_Diffuse));
|
||||
|
||||
mpLowLevelGraphics->ClearBatch();
|
||||
|
||||
pPrevMat->EndRendering(eMaterialRenderType_Diffuse);
|
||||
}
|
||||
|
||||
// Clear the buffer of objects.
|
||||
m_setGfxBuffer.clear();
|
||||
|
||||
// Reset all states
|
||||
mpLowLevelGraphics->SetDepthTestActive(true);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cGfxObject *cGraphicsDrawer::CreateGfxObject(const tString &asFileName, const tString &asMaterialName,
|
||||
bool abAddToList) {
|
||||
cResourceImage *pImage = mpResources->GetImageManager()->CreateImage(asFileName);
|
||||
if (pImage == NULL) {
|
||||
error("Couldn't load image '%s'", asFileName.c_str());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
iMaterial *pMat = mpMaterialHandler->Create(asMaterialName, eMaterialPicture_Image);
|
||||
if (pMat == NULL) {
|
||||
error("Couldn't create material '%s'", asMaterialName.c_str());
|
||||
return NULL;
|
||||
}
|
||||
// mpResources->GetImageManager()->FlushAll();
|
||||
|
||||
pMat->SetImage(pImage, eMaterialTexture_Diffuse);
|
||||
|
||||
cGfxObject *pObject = hplNew(cGfxObject, (pMat, asFileName, true));
|
||||
|
||||
if (abAddToList)
|
||||
mlstGfxObjects.push_back(pObject);
|
||||
|
||||
return pObject;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cGfxObject *cGraphicsDrawer::CreateGfxObject(Bitmap2D *apBmp, const tString &asMaterialName,
|
||||
bool abAddToList) {
|
||||
cResourceImage *pImage = mpResources->GetImageManager()->CreateFromBitmap("", apBmp);
|
||||
if (pImage == NULL) {
|
||||
error("Couldn't create image");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
iMaterial *pMat = mpMaterialHandler->Create(asMaterialName, eMaterialPicture_Image);
|
||||
if (pMat == NULL) {
|
||||
error("Couldn't create material '%s'", asMaterialName.c_str());
|
||||
return NULL;
|
||||
}
|
||||
// mpResources->GetImageManager()->FlushAll();
|
||||
|
||||
pMat->SetImage(pImage, eMaterialTexture_Diffuse);
|
||||
|
||||
cGfxObject *pObject = hplNew(cGfxObject, (pMat, "", true));
|
||||
|
||||
if (abAddToList)
|
||||
mlstGfxObjects.push_back(pObject);
|
||||
|
||||
return pObject;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cGfxObject *cGraphicsDrawer::CreateGfxObjectFromTexture(const tString &asFileName, const tString &asMaterialName,
|
||||
bool abAddToList) {
|
||||
iTexture *pTex = mpResources->GetTextureManager()->Create2D(asFileName, false);
|
||||
if (pTex == NULL) {
|
||||
error("Couldn't create texture '%s'", asFileName.c_str());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
iMaterial *pMat = mpMaterialHandler->Create(asMaterialName, eMaterialPicture_Texture);
|
||||
if (pMat == NULL) {
|
||||
error("Couldn't create material '%s'", asMaterialName.c_str());
|
||||
return NULL;
|
||||
}
|
||||
// mpResources->GetImageManager()->FlushAll();
|
||||
|
||||
pMat->SetTexture(pTex, eMaterialTexture_Diffuse);
|
||||
|
||||
cGfxObject *pObject = hplNew(cGfxObject, (pMat, asFileName, false));
|
||||
|
||||
if (abAddToList)
|
||||
mlstGfxObjects.push_back(pObject);
|
||||
|
||||
return pObject;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cGraphicsDrawer::DestroyGfxObject(cGfxObject *apObject) {
|
||||
STLFindAndDelete(mlstGfxObjects, apObject);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cBackgroundImage *cGraphicsDrawer::AddBackgroundImage(const tString &asFileName,
|
||||
const tString &asMaterialName,
|
||||
const cVector3f &avPos,
|
||||
bool abTile, const cVector2f &avSize, const cVector2f &avPosPercent, const cVector2f &avVel) {
|
||||
cResourceImage *pImage = mpResources->GetImageManager()->CreateImage(asFileName);
|
||||
if (pImage == NULL) {
|
||||
error("Couldn't load image '%s'", asFileName.c_str());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
iMaterial *pMat = mpMaterialHandler->Create(asMaterialName, eMaterialPicture_Image);
|
||||
if (pMat == NULL) {
|
||||
error("Couldn't create material '%s'", asMaterialName.c_str());
|
||||
return NULL;
|
||||
}
|
||||
// mpResources->GetImageManager()->FlushAll();
|
||||
|
||||
pMat->SetImage(pImage, eMaterialTexture_Diffuse);
|
||||
|
||||
cBackgroundImage *pBG = hplNew(cBackgroundImage, (pMat, avPos, abTile, avSize, avPosPercent, avVel));
|
||||
|
||||
m_mapBackgroundImages.insert(tBackgroundImageMap::value_type(avPos.z, pBG));
|
||||
|
||||
return pBG;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cGraphicsDrawer::UpdateBackgrounds() {
|
||||
tBackgroundImageMapIt it = m_mapBackgroundImages.begin();
|
||||
for (; it != m_mapBackgroundImages.end(); it++) {
|
||||
it->second->Update();
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cGraphicsDrawer::DrawBackgrounds(const cRect2f &aCollideRect) {
|
||||
mpLowLevelGraphics->SetIdentityMatrix(eMatrix_ModelView);
|
||||
mpLowLevelGraphics->SetDepthTestActive(true);
|
||||
mpLowLevelGraphics->SetDepthWriteActive(false);
|
||||
mpLowLevelGraphics->SetAlphaTestFunc(eAlphaTestFunc_Greater, 0.1f);
|
||||
mpLowLevelGraphics->SetDepthTestFunc(eDepthTestFunc_LessOrEqual);
|
||||
|
||||
tBackgroundImageMapIt it = m_mapBackgroundImages.begin();
|
||||
for (; it != m_mapBackgroundImages.end(); it++) {
|
||||
it->second->Draw(aCollideRect, mpLowLevelGraphics);
|
||||
}
|
||||
|
||||
mpLowLevelGraphics->SetAlphaTestFunc(eAlphaTestFunc_Greater, 0.05f);
|
||||
mpLowLevelGraphics->SetDepthWriteActive(true);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cGraphicsDrawer::ClearBackgrounds() {
|
||||
tBackgroundImageMapIt it = m_mapBackgroundImages.begin();
|
||||
for (; it != m_mapBackgroundImages.end(); it++) {
|
||||
hplDelete(it->second);
|
||||
}
|
||||
m_mapBackgroundImages.clear();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
} // namespace hpl
|
||||
156
engines/hpl1/engine/graphics/GraphicsDrawer.h
Normal file
156
engines/hpl1/engine/graphics/GraphicsDrawer.h
Normal file
@@ -0,0 +1,156 @@
|
||||
/* 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_GRAPHICSDRAWER_H
|
||||
#define HPL_GRAPHICSDRAWER_H
|
||||
|
||||
#include "common/array.h"
|
||||
#include "common/list.h"
|
||||
#include "hpl1/engine/graphics/BackgroundImage.h"
|
||||
#include "hpl1/engine/graphics/GraphicsTypes.h"
|
||||
#include "hpl1/std/multiset.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class iLowLevelGraphics;
|
||||
class cResourceImage;
|
||||
class cGfxObject;
|
||||
class cMaterialHandler;
|
||||
class iMaterial;
|
||||
|
||||
class cGfxBufferObject {
|
||||
public:
|
||||
cGfxObject *mpObject;
|
||||
cVector3f mvTransform;
|
||||
|
||||
bool mbIsColorAndSize;
|
||||
cColor mColor;
|
||||
cVector2f mvSize;
|
||||
bool mbFlipH = false;
|
||||
bool mbFlipV = false;
|
||||
float mfAngle = 0;
|
||||
|
||||
iMaterial *GetMaterial() const;
|
||||
float GetZ() const { return mvTransform.z; }
|
||||
};
|
||||
|
||||
typedef Common::Array<cGfxObject> tGfxObjectVec;
|
||||
typedef tGfxObjectVec::iterator tGfxObjectVecIt;
|
||||
|
||||
class cGfxBufferCompare {
|
||||
public:
|
||||
bool operator()(const cGfxBufferObject &aObjectA, const cGfxBufferObject &aObjectB) const;
|
||||
};
|
||||
|
||||
typedef Hpl1::Std::multiset<cGfxBufferObject, cGfxBufferCompare> tGfxBufferSet;
|
||||
typedef tGfxBufferSet::iterator tGfxBufferSetIt;
|
||||
|
||||
class cResources;
|
||||
|
||||
typedef Common::List<cGfxObject *> tGfxObjectList;
|
||||
typedef tGfxObjectList::iterator tGfxObjectListIt;
|
||||
|
||||
class cGraphicsDrawer {
|
||||
public:
|
||||
cGraphicsDrawer(iLowLevelGraphics *apLowLevelGraphics, cMaterialHandler *apMaterialHandler,
|
||||
cResources *apResources);
|
||||
~cGraphicsDrawer();
|
||||
|
||||
/**
|
||||
* Draw Gfx object during next DrawAll call.
|
||||
* \param apObject
|
||||
* \param avPos
|
||||
*/
|
||||
void DrawGfxObject(cGfxObject *apObject, const cVector3f &avPos);
|
||||
|
||||
/**
|
||||
* Draw Gfx object during next DrawAll call.
|
||||
* \param apObject
|
||||
* \param avPos
|
||||
* \param avSize Size of object
|
||||
* \param aColor color to use
|
||||
* \param abFlipH Flip image horisontally
|
||||
* \param abFlipV Flip image verically
|
||||
*/
|
||||
void DrawGfxObject(cGfxObject *apObject, const cVector3f &avPos,
|
||||
const cVector2f &avSize, const cColor &aColor,
|
||||
bool abFlipH = false, bool abFlipV = false, float afAngle = 0);
|
||||
|
||||
/**
|
||||
* Draw all gfx obejcts, Called after world is rendered by cScene.
|
||||
*/
|
||||
void DrawAll();
|
||||
|
||||
/**
|
||||
* Create Gfx object from file
|
||||
* \param &asFileName Filename of image
|
||||
* \param &asMaterialName material to use
|
||||
* \param abAddToList if the engine should delete object at exit, this means DestroyGfxObject must be used. Should almost always be true.
|
||||
* \return
|
||||
*/
|
||||
cGfxObject *CreateGfxObject(const tString &asFileName, const tString &asMaterialName,
|
||||
bool abAddToList = true);
|
||||
/**
|
||||
* Create gfx object from Bitmap
|
||||
* \param *apBmp bitmap
|
||||
* \param &asMaterialName material to use
|
||||
* \param abAddToList if the engine should delete object at exit, this means DestroyGfxObject must be used. Should almost always be true.
|
||||
* \return
|
||||
*/
|
||||
cGfxObject *CreateGfxObject(Bitmap2D *apBmp, const tString &asMaterialName,
|
||||
bool abAddToList = true);
|
||||
|
||||
cGfxObject *CreateGfxObjectFromTexture(const tString &asFileName, const tString &asMaterialName,
|
||||
bool abAddToList = true);
|
||||
/**
|
||||
* Destroys a gfx object.
|
||||
*/
|
||||
void DestroyGfxObject(cGfxObject *apObject);
|
||||
|
||||
cBackgroundImage *AddBackgroundImage(const tString &asFileName, const tString &asMaterialName,
|
||||
const cVector3f &avPos, bool abTile,
|
||||
const cVector2f &avSize, const cVector2f &avPosPercent, const cVector2f &avVel);
|
||||
|
||||
void UpdateBackgrounds();
|
||||
void DrawBackgrounds(const cRect2f &aCollideRect);
|
||||
void ClearBackgrounds();
|
||||
|
||||
private:
|
||||
iLowLevelGraphics *mpLowLevelGraphics;
|
||||
cMaterialHandler *mpMaterialHandler;
|
||||
cResources *mpResources;
|
||||
|
||||
tGfxBufferSet m_setGfxBuffer;
|
||||
|
||||
tGfxObjectList mlstGfxObjects;
|
||||
|
||||
tBackgroundImageMap m_mapBackgroundImages;
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_GRAPHICSDRAWER_H
|
||||
165
engines/hpl1/engine/graphics/GraphicsTypes.h
Normal file
165
engines/hpl1/engine/graphics/GraphicsTypes.h
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.
|
||||
*/
|
||||
|
||||
#ifndef HPL_GRAPHICSTYPES_H
|
||||
#define HPL_GRAPHICSTYPES_H
|
||||
|
||||
#include "common/array.h"
|
||||
#include "common/list.h"
|
||||
#include "hpl1/engine/graphics/Color.h"
|
||||
#include "hpl1/engine/math/MathTypes.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
#define MAX_TEXTUREUNITS (8)
|
||||
#define MAX_NUM_OF_LIGHTS (30)
|
||||
|
||||
enum eMatrix {
|
||||
eMatrix_ModelView,
|
||||
eMatrix_Projection,
|
||||
eMatrix_Texture,
|
||||
eMatrix_LastEnum
|
||||
};
|
||||
|
||||
enum eTileRotation {
|
||||
eTileRotation_0,
|
||||
eTileRotation_90,
|
||||
eTileRotation_180,
|
||||
eTileRotation_270,
|
||||
eTileRotation_LastEnum
|
||||
};
|
||||
|
||||
enum ePrimitiveType {
|
||||
ePrimitiveType_Tri,
|
||||
ePrimitiveType_Quad,
|
||||
ePrimitiveType_LastEnum
|
||||
};
|
||||
|
||||
typedef tFlag tAnimTransformFlag;
|
||||
|
||||
#define eAnimTransformFlag_Translate (0x00000001)
|
||||
#define eAnimTransformFlag_Scale (0x00000002)
|
||||
#define eAnimTransformFlag_Rotate (0x00000004)
|
||||
|
||||
#define klNumOfAnimTransformFlags (3)
|
||||
|
||||
const tAnimTransformFlag kvAnimTransformFlags[] = {eAnimTransformFlag_Translate,
|
||||
eAnimTransformFlag_Scale, eAnimTransformFlag_Rotate};
|
||||
|
||||
//-----------------------------------------
|
||||
|
||||
enum eColorDataFormat {
|
||||
eColorDataFormat_RGB,
|
||||
eColorDataFormat_RGBA,
|
||||
eColorDataFormat_ALPHA,
|
||||
eColorDataFormat_BGR,
|
||||
eColorDataFormat_BGRA,
|
||||
eColorDataFormat_LastEnum
|
||||
};
|
||||
|
||||
//---------------------------------------
|
||||
|
||||
enum eFontAlign {
|
||||
eFontAlign_Left,
|
||||
eFontAlign_Right,
|
||||
eFontAlign_Center,
|
||||
eFontAlign_LastEnum
|
||||
};
|
||||
|
||||
//---------------------------------------
|
||||
|
||||
class cKeyFrame {
|
||||
public:
|
||||
cVector3f trans;
|
||||
cVector3f scale;
|
||||
cQuaternion rotation;
|
||||
float time;
|
||||
};
|
||||
|
||||
typedef Common::Array<cKeyFrame *> tKeyFramePtrVec;
|
||||
typedef tKeyFramePtrVec::iterator tKeyFramePtrVecIt;
|
||||
|
||||
typedef Common::Array<cKeyFrame> tKeyFrameVec;
|
||||
typedef tKeyFrameVec::iterator tKeyFrameVecIt;
|
||||
|
||||
//---------------------------------------
|
||||
|
||||
enum eAnimationEventType {
|
||||
eAnimationEventType_PlaySound,
|
||||
eAnimationEventType_LastEnum
|
||||
};
|
||||
|
||||
//---------------------------------------
|
||||
|
||||
class cVertexBonePair {
|
||||
public:
|
||||
cVertexBonePair(unsigned int aVtx, unsigned int aBone, float aW) {
|
||||
vtxIdx = aVtx;
|
||||
boneIdx = aBone;
|
||||
weight = aW;
|
||||
}
|
||||
cVertexBonePair() {}
|
||||
|
||||
unsigned int vtxIdx;
|
||||
unsigned int boneIdx;
|
||||
float weight;
|
||||
};
|
||||
|
||||
typedef Common::Array<cVertexBonePair> tVertexBonePairVec;
|
||||
typedef tVertexBonePairVec::iterator tVertexBonePairVecIt;
|
||||
|
||||
//---------------------------------------
|
||||
|
||||
class cVertex {
|
||||
public:
|
||||
cVertex() : pos(0), tex(0), col(0) {}
|
||||
cVertex(const cVector3f &avPos, const cVector3f &avTex, const cColor &aCol) {
|
||||
pos = avPos;
|
||||
tex = avTex;
|
||||
col = aCol;
|
||||
}
|
||||
|
||||
cVertex(const cVector3f &avPos, const cColor &aCol) {
|
||||
pos = avPos;
|
||||
col = aCol;
|
||||
}
|
||||
|
||||
cVector3f pos;
|
||||
cVector3f tex;
|
||||
cVector3f tan;
|
||||
cVector3f norm;
|
||||
cColor col;
|
||||
};
|
||||
|
||||
typedef Common::List<cVertex> tVertexList;
|
||||
typedef tVertexList::iterator tVertexListIt;
|
||||
|
||||
typedef Common::Array<cVertex> tVertexVec;
|
||||
typedef tVertexVec::iterator tVertexVecIt;
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_GRAPHICSTYPES_H
|
||||
292
engines/hpl1/engine/graphics/ImageEntityData.cpp
Normal file
292
engines/hpl1/engine/graphics/ImageEntityData.cpp
Normal file
@@ -0,0 +1,292 @@
|
||||
/* 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/graphics/ImageEntityData.h"
|
||||
#include "hpl1/engine/graphics/Graphics.h"
|
||||
#include "hpl1/engine/graphics/Material.h"
|
||||
#include "hpl1/engine/graphics/MaterialHandler.h"
|
||||
#include "hpl1/engine/graphics/Mesh2d.h"
|
||||
#include "hpl1/engine/graphics/MeshCreator.h"
|
||||
#include "hpl1/engine/impl/tinyXML/tinyxml.h"
|
||||
#include "hpl1/engine/resources/Resources.h"
|
||||
#include "hpl1/engine/scene/ImageEntity.h"
|
||||
#include "hpl1/engine/scene/TileSet.h"
|
||||
#include "hpl1/engine/system/low_level_system.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cImageEntityData::cImageEntityData(tString asName, cGraphics *apGraphics, cResources *apResources)
|
||||
: iResourceBase(asName, 0) {
|
||||
mpResources = apResources;
|
||||
mpGraphics = apGraphics;
|
||||
|
||||
mlFrameNum = 0;
|
||||
|
||||
mbCastShadows = false;
|
||||
mbCollidable = false;
|
||||
mbLit = true;
|
||||
|
||||
mpMesh = NULL;
|
||||
mpCollideMesh = NULL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cImageEntityData::~cImageEntityData() {
|
||||
for (int i = 0; i < (int)mvImageFrames.size(); i++) {
|
||||
hplDelete(mvImageFrames[i].mpMaterial);
|
||||
}
|
||||
|
||||
hplDelete(mpMesh);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cImageAnimation *cImageEntityData::GetAnimationByName(const tString &asName) {
|
||||
tImageAnimationMapIt it = m_mapAnimations.find(asName);
|
||||
if (it == m_mapAnimations.end())
|
||||
return NULL;
|
||||
|
||||
return &it->second;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cImageAnimation *cImageEntityData::GetAnimationByHandle(int alHandle) {
|
||||
tImageAnimationMapIt it = m_mapAnimations.begin();
|
||||
|
||||
while (it != m_mapAnimations.end()) {
|
||||
if (it->second.mlHandle == alHandle)
|
||||
return &it->second;
|
||||
it++;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cImageEntityData::CreateFromFile(const tString &asFile, tIntVec &avImageHandle) {
|
||||
bool bGotAnim = false;
|
||||
TiXmlDocument *pDoc = hplNew(TiXmlDocument, (asFile.c_str()));
|
||||
if (!pDoc->LoadFile()) {
|
||||
error("Couldn't load tileset '%s'", asFile.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
TiXmlElement *RootElem = pDoc->RootElement();
|
||||
|
||||
// Temp test::
|
||||
Common::fill(avImageHandle.begin(), avImageHandle.end(), -1);
|
||||
|
||||
///////// MAIN ///////////////
|
||||
TiXmlElement *MainElem = RootElem->FirstChildElement("MAIN");
|
||||
|
||||
msDataName = cString::ToString(MainElem->Attribute("Name"), "");
|
||||
msType = cString::ToString(MainElem->Attribute("Type"), "");
|
||||
msSubType = cString::ToString(MainElem->Attribute("Subtype"), "");
|
||||
|
||||
///////// IMAGE ///////////////
|
||||
TiXmlElement *ImageElem = RootElem->FirstChildElement("IMAGE");
|
||||
|
||||
tString sImageName = cString::ToString(ImageElem->Attribute("Name"), "");
|
||||
tString sDirectory = cString::ToString(ImageElem->Attribute("Dir"), "");
|
||||
tString sMaterial = cString::ToString(ImageElem->Attribute("Material"), "");
|
||||
tString sMesh = cString::ToString(ImageElem->Attribute("Mesh"), "");
|
||||
|
||||
mvImageSize.x = cString::ToFloat(ImageElem->Attribute("Width"), 512) + 2.0f;
|
||||
mvImageSize.y = cString::ToFloat(ImageElem->Attribute("Height"), 512) + 2.0f;
|
||||
|
||||
///////// PROPERTIES ///////////////
|
||||
TiXmlElement *PropElem = RootElem->FirstChildElement("PROPERTIES");
|
||||
|
||||
mbCastShadows = cString::ToBool(PropElem->Attribute("CastShadows"), false);
|
||||
mbCollidable = cString::ToBool(PropElem->Attribute("Collidable"), false);
|
||||
mbCollides = cString::ToBool(PropElem->Attribute("Collides"), false);
|
||||
mbLit = cString::ToBool(PropElem->Attribute("Lit"), true);
|
||||
tString sCollideMesh = cString::ToString(PropElem->Attribute("CollideMesh"), "square");
|
||||
|
||||
///////// ANIMATIONS ///////////////
|
||||
TiXmlElement *AnimationElem = RootElem->FirstChildElement("ANIMATIONS");
|
||||
|
||||
if (AnimationElem != NULL) {
|
||||
mlFrameNum = cString::ToInt(AnimationElem->Attribute("Frames"), 1);
|
||||
|
||||
TiXmlElement *AnimChildElem = AnimationElem->FirstChildElement();
|
||||
|
||||
int lCount = 0;
|
||||
while (AnimChildElem) {
|
||||
cImageAnimation Anim;
|
||||
Anim.msName = cString::ToString(AnimChildElem->Attribute("Name"), "");
|
||||
Anim.mfSpeed = cString::ToFloat(AnimChildElem->Attribute("Speed"), 1);
|
||||
Anim.mbCollidable = cString::ToBool(AnimChildElem->Attribute("Collidable"), false);
|
||||
Anim.msSound = cString::ToString(AnimChildElem->Attribute("Sound"), "");
|
||||
Anim.mlHandle = lCount;
|
||||
|
||||
tString sData = cString::ToString(AnimChildElem->Attribute("Data"), "");
|
||||
cString::GetIntVec(sData, Anim.mvFrameNums);
|
||||
|
||||
m_mapAnimations.insert(tImageAnimationMap::value_type(Anim.msName, Anim));
|
||||
|
||||
AnimChildElem = AnimChildElem->NextSiblingElement();
|
||||
lCount++;
|
||||
}
|
||||
|
||||
bGotAnim = true;
|
||||
} else {
|
||||
mlFrameNum = 1;
|
||||
bGotAnim = false;
|
||||
}
|
||||
|
||||
///////// LOADING /////////////////
|
||||
|
||||
mpResources->AddResourceDir(sDirectory);
|
||||
|
||||
// Create the mesh for drawing
|
||||
mpMesh = mpGraphics->GetMeshCreator()->Create2D(sMesh, 2);
|
||||
if (mpMesh == NULL) {
|
||||
Error("Error creating mesh for '%s'!\n", msName.c_str());
|
||||
return false;
|
||||
}
|
||||
mpMesh->CreateVertexVec();
|
||||
mvIdxVec = *mpMesh->GetIndexVec();
|
||||
|
||||
// Create the mesh used for collision
|
||||
mpCollideMesh = mpGraphics->GetMeshCreator()->Create2D(sCollideMesh, 2);
|
||||
if (mpCollideMesh == NULL) {
|
||||
Error("Error creating collide mesh '%s' for '%s'!\n", sCollideMesh.c_str(), msName.c_str());
|
||||
return false;
|
||||
}
|
||||
mpCollideMesh->CreateVertexVec();
|
||||
|
||||
// Determine frame size, there should be some minum size and it should also see to that it
|
||||
// can contain all frames for the animations.
|
||||
double x = ceil(log((double)((float)mlFrameNum) * mvImageSize.x) / log(2.0f));
|
||||
double y = ceil(log((double)mvImageSize.y) / log(2.0f));
|
||||
|
||||
if (x > kMaxImageEntityFrameWidth) {
|
||||
y += x - kMaxTileFrameWidth;
|
||||
x = kMaxTileFrameWidth;
|
||||
}
|
||||
|
||||
mvFrameSize = cVector2l((int)pow(2.0, x), (int)pow(2.0, y));
|
||||
|
||||
// Loop through all animation frames.
|
||||
for (int i = 0; i < mlFrameNum; i++) {
|
||||
// Get the material
|
||||
iMaterial *pMaterial = mpGraphics->GetMaterialHandler()->Create(sMaterial, eMaterialPicture_Image);
|
||||
if (pMaterial == NULL) {
|
||||
Error("Error creating material '%s' for '%s'!\n", sMaterial.c_str(), msName.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get the textures for the material
|
||||
tTextureTypeList lstTypes = pMaterial->GetTextureTypes();
|
||||
for (tTextureTypeListIt it = lstTypes.begin(); it != lstTypes.end(); it++) {
|
||||
if (avImageHandle[it->mType] == -1) {
|
||||
avImageHandle[it->mType] = mpResources->GetImageManager()->CreateFrame(mvFrameSize);
|
||||
}
|
||||
|
||||
tString sFile;
|
||||
if (bGotAnim) {
|
||||
int lNum = i + 1;
|
||||
|
||||
sFile = sImageName;
|
||||
if (lNum < 10)
|
||||
sFile += "0";
|
||||
sFile += Common::String::format("%d", lNum).c_str();
|
||||
} else {
|
||||
sFile = sImageName;
|
||||
}
|
||||
|
||||
cResourceImage *pImage = mpResources->GetImageManager()->CreateImage(
|
||||
sFile + it->msSuffix,
|
||||
avImageHandle[it->mType]);
|
||||
if (pImage == NULL) {
|
||||
error("Can't load texture '%s%s'", sFile.c_str(), it->msSuffix.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
pMaterial->SetImage(pImage, it->mType);
|
||||
}
|
||||
|
||||
pMaterial->Compile();
|
||||
|
||||
cImageFrame ImageFrame;
|
||||
|
||||
ImageFrame.mpMaterial = pMaterial;
|
||||
cRect2f ImageRect = pMaterial->GetTextureOffset(eMaterialTexture_Diffuse);
|
||||
ImageFrame.mvVtx = *mpMesh->GetVertexVec(ImageRect, 2, eTileRotation_0);
|
||||
|
||||
mvImageFrames.push_back(ImageFrame);
|
||||
}
|
||||
|
||||
///////// CLEAN UP ///////////////
|
||||
|
||||
hplDelete(pDoc);
|
||||
|
||||
mpResources->GetImageManager()->FlushAll();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cImageFrame *cImageEntityData::GetImageFrame(int alFrame) {
|
||||
if (alFrame < 0 || alFrame >= (int)mvImageFrames.size())
|
||||
return NULL;
|
||||
|
||||
return &mvImageFrames[alFrame];
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PRIVATE METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cImageEntityData::GetFrameNum(TiXmlElement *apElement) {
|
||||
mlFrameNum = 1;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
} // namespace hpl
|
||||
130
engines/hpl1/engine/graphics/ImageEntityData.h
Normal file
130
engines/hpl1/engine/graphics/ImageEntityData.h
Normal file
@@ -0,0 +1,130 @@
|
||||
/* 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_DATA_H
|
||||
#define HPL_IMAGE_ENTITY_DATA_H
|
||||
|
||||
#include "hpl1/engine/graphics/GraphicsTypes.h"
|
||||
#include "hpl1/engine/math/MathTypes.h"
|
||||
#include "hpl1/engine/resources/ResourceBase.h"
|
||||
#include "hpl1/engine/system/SystemTypes.h"
|
||||
#include "common/stablemap.h"
|
||||
|
||||
class TiXmlElement;
|
||||
|
||||
namespace hpl {
|
||||
|
||||
#define kMaxImageEntityFrameWidth (1024)
|
||||
|
||||
class cResources;
|
||||
class cGraphics;
|
||||
class iMaterial;
|
||||
class cMesh2D;
|
||||
|
||||
class cImageFrame {
|
||||
public:
|
||||
iMaterial *mpMaterial;
|
||||
tVertexVec mvVtx;
|
||||
};
|
||||
|
||||
typedef Common::Array<cImageFrame> tImageFrameVec;
|
||||
typedef tImageFrameVec::iterator tImageFrameVecIt;
|
||||
|
||||
class cImageAnimation {
|
||||
public:
|
||||
tString msName;
|
||||
int mlHandle;
|
||||
float mfSpeed;
|
||||
tIntVec mvFrameNums;
|
||||
bool mbCollidable;
|
||||
tString msSound;
|
||||
};
|
||||
|
||||
typedef Common::StableMap<tString, cImageAnimation> tImageAnimationMap;
|
||||
typedef tImageAnimationMap::iterator tImageAnimationMapIt;
|
||||
|
||||
class cImageEntityData : public iResourceBase {
|
||||
public:
|
||||
cImageEntityData(tString asName, cGraphics *apGraphics, cResources *apResources);
|
||||
~cImageEntityData();
|
||||
|
||||
// resource stuff:
|
||||
bool reload() { return false; }
|
||||
void unload() {}
|
||||
void destroy() {}
|
||||
|
||||
bool CreateFromFile(const tString &asFile, tIntVec &avImageHandle);
|
||||
|
||||
cImageFrame *GetImageFrame(int alFrame);
|
||||
tUIntVec *GetIndexVec() { return &mvIdxVec; }
|
||||
|
||||
int GetFrameNum() { return mlFrameNum; }
|
||||
cImageAnimation *GetAnimationByName(const tString &asName);
|
||||
cImageAnimation *GetAnimationByHandle(int alHandle);
|
||||
int GetAnimationNum() { return (int)m_mapAnimations.size(); }
|
||||
tImageAnimationMap *GetAnimationMap() { return &m_mapAnimations; }
|
||||
|
||||
const tString &GetType() { return msType; }
|
||||
const tString &GetSubType() { return msSubType; }
|
||||
const tString &GetDataName() { return msDataName; }
|
||||
|
||||
cVector2f GetImageSize() { return mvImageSize; }
|
||||
|
||||
cMesh2D *GetCollideMesh() { return mpCollideMesh; }
|
||||
|
||||
bool IsCollidable() { return mbCollidable; }
|
||||
bool GetCollides() { return mbCollides; }
|
||||
bool GetCastShadows() { return mbCastShadows; }
|
||||
|
||||
private:
|
||||
int mlFrameNum;
|
||||
cResources *mpResources;
|
||||
cGraphics *mpGraphics;
|
||||
cVector2l mvFrameSize;
|
||||
cMesh2D *mpMesh;
|
||||
cMesh2D *mpCollideMesh;
|
||||
tUIntVec mvIdxVec;
|
||||
cVector2f mvImageSize;
|
||||
|
||||
tString msDataName;
|
||||
tString msType;
|
||||
tString msSubType;
|
||||
|
||||
bool mbCastShadows;
|
||||
bool mbCollidable;
|
||||
bool mbCollides;
|
||||
bool mbLit;
|
||||
|
||||
tImageFrameVec mvImageFrames;
|
||||
tImageAnimationMap m_mapAnimations;
|
||||
|
||||
void GetFrameNum(TiXmlElement *apElement);
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_IMAGE_ENTITY_DATA_H
|
||||
426
engines/hpl1/engine/graphics/LowLevelGraphics.h
Normal file
426
engines/hpl1/engine/graphics/LowLevelGraphics.h
Normal file
@@ -0,0 +1,426 @@
|
||||
/* 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_LOWLEVELGRAPHICS_H
|
||||
#define HPL_LOWLEVELGRAPHICS_H
|
||||
|
||||
#include "hpl1/engine/graphics/GPUProgram.h"
|
||||
#include "hpl1/engine/graphics/GraphicsTypes.h"
|
||||
#include "hpl1/engine/graphics/Texture.h"
|
||||
#include "hpl1/engine/graphics/VertexBuffer.h"
|
||||
#include "hpl1/engine/graphics/bitmap2D.h"
|
||||
#include "hpl1/engine/math/MathTypes.h"
|
||||
#include "hpl1/engine/system/SystemTypes.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
enum eBlendFunc {
|
||||
eBlendFunc_Zero,
|
||||
eBlendFunc_One,
|
||||
eBlendFunc_SrcColor,
|
||||
eBlendFunc_OneMinusSrcColor,
|
||||
eBlendFunc_DestColor,
|
||||
eBlendFunc_OneMinusDestColor,
|
||||
eBlendFunc_SrcAlpha,
|
||||
eBlendFunc_OneMinusSrcAlpha,
|
||||
eBlendFunc_DestAlpha,
|
||||
eBlendFunc_OneMinusDestAlpha,
|
||||
eBlendFunc_SrcAlphaSaturate,
|
||||
eBlendFunc_LastEnum
|
||||
};
|
||||
|
||||
enum eTextureParam {
|
||||
eTextureParam_ColorFunc,
|
||||
eTextureParam_AlphaFunc,
|
||||
eTextureParam_ColorSource0,
|
||||
eTextureParam_ColorSource1,
|
||||
eTextureParam_ColorSource2,
|
||||
eTextureParam_AlphaSource0,
|
||||
eTextureParam_AlphaSource1,
|
||||
eTextureParam_AlphaSource2,
|
||||
eTextureParam_ColorOp0,
|
||||
eTextureParam_ColorOp1,
|
||||
eTextureParam_ColorOp2,
|
||||
eTextureParam_AlphaOp0,
|
||||
eTextureParam_AlphaOp1,
|
||||
eTextureParam_AlphaOp2,
|
||||
eTextureParam_ColorScale,
|
||||
eTextureParam_AlphaScale,
|
||||
eTextureParam_LastEnum
|
||||
};
|
||||
|
||||
enum eTextureOp {
|
||||
eTextureOp_Color,
|
||||
eTextureOp_OneMinusColor,
|
||||
eTextureOp_Alpha,
|
||||
eTextureOp_OneMinusAlpha,
|
||||
eTextureOp_LasEnum
|
||||
};
|
||||
|
||||
enum eTextureSource {
|
||||
eTextureSource_Texture,
|
||||
eTextureSource_Constant,
|
||||
eTextureSource_Primary,
|
||||
eTextureSource_Previous,
|
||||
eTextureSource_LastEnum
|
||||
};
|
||||
|
||||
enum eTextureFunc {
|
||||
eTextureFunc_Modulate,
|
||||
eTextureFunc_Replace,
|
||||
eTextureFunc_Add,
|
||||
eTextureFunc_Subtract,
|
||||
eTextureFunc_AddSigned,
|
||||
eTextureFunc_Interpolate,
|
||||
eTextureFunc_Dot3RGB,
|
||||
eTextureFunc_Dot3RGBA,
|
||||
eTextureFunc_LastEnum
|
||||
};
|
||||
|
||||
enum eStencilFunc {
|
||||
eStencilFunc_Never,
|
||||
eStencilFunc_Less,
|
||||
eStencilFunc_LessOrEqual,
|
||||
eStencilFunc_Greater,
|
||||
eStencilFunc_GreaterOrEqual,
|
||||
eStencilFunc_Equal,
|
||||
eStencilFunc_NotEqual,
|
||||
eStencilFunc_Always,
|
||||
eStencilFunc_LastEnum
|
||||
};
|
||||
|
||||
enum eStencilFace {
|
||||
eStencilFace_Front,
|
||||
eStencilFace_Back,
|
||||
eStencilFace_LastEnum,
|
||||
};
|
||||
|
||||
enum eDepthTestFunc {
|
||||
eDepthTestFunc_Never,
|
||||
eDepthTestFunc_Less,
|
||||
eDepthTestFunc_LessOrEqual,
|
||||
eDepthTestFunc_Greater,
|
||||
eDepthTestFunc_GreaterOrEqual,
|
||||
eDepthTestFunc_Equal,
|
||||
eDepthTestFunc_NotEqual,
|
||||
eDepthTestFunc_Always,
|
||||
eDepthTestFunc_LastEnum
|
||||
};
|
||||
|
||||
enum eAlphaTestFunc {
|
||||
eAlphaTestFunc_Never,
|
||||
eAlphaTestFunc_Less,
|
||||
eAlphaTestFunc_LessOrEqual,
|
||||
eAlphaTestFunc_Greater,
|
||||
eAlphaTestFunc_GreaterOrEqual,
|
||||
eAlphaTestFunc_Equal,
|
||||
eAlphaTestFunc_NotEqual,
|
||||
eAlphaTestFunc_Always,
|
||||
eAlphaTestFunc_LastEnum
|
||||
};
|
||||
|
||||
enum eStencilOp {
|
||||
eStencilOp_Keep,
|
||||
eStencilOp_Zero,
|
||||
eStencilOp_Replace,
|
||||
eStencilOp_Increment,
|
||||
eStencilOp_Decrement,
|
||||
eStencilOp_Invert,
|
||||
eStencilOp_IncrementWrap,
|
||||
eStencilOp_DecrementWrap,
|
||||
eStencilOp_LastEnum
|
||||
};
|
||||
|
||||
enum eCullMode {
|
||||
eCullMode_Clockwise,
|
||||
eCullMode_CounterClockwise,
|
||||
eCullMode_LastEnum
|
||||
};
|
||||
|
||||
enum eGraphicCaps {
|
||||
eGraphicCaps_TextureTargetRectangle,
|
||||
eGraphicCaps_VertexBufferObject,
|
||||
eGraphicCaps_TwoSideStencil,
|
||||
|
||||
eGraphicCaps_MaxTextureImageUnits,
|
||||
eGraphicCaps_MaxTextureCoordUnits,
|
||||
|
||||
eGraphicCaps_AnisotropicFiltering,
|
||||
eGraphicCaps_MaxAnisotropicFiltering,
|
||||
|
||||
eGraphicCaps_Multisampling,
|
||||
|
||||
eGraphicCaps_GL_GpuPrograms,
|
||||
eGraphicCaps_GL_NVRegisterCombiners,
|
||||
eGraphicCaps_GL_NVRegisterCombiners_MaxStages,
|
||||
eGraphicCaps_GL_BlendFunctionSeparate,
|
||||
eGraphicCaps_GL_MultiTexture,
|
||||
|
||||
eGraphicCaps_LastEnum
|
||||
};
|
||||
|
||||
typedef tFlag tVtxBatchFlag;
|
||||
|
||||
#define eVtxBatchFlag_Normal (0x00000001)
|
||||
#define eVtxBatchFlag_Position (0x00000002)
|
||||
#define eVtxBatchFlag_Color0 (0x00000004)
|
||||
#define eVtxBatchFlag_Texture0 (0x00000008)
|
||||
#define eVtxBatchFlag_Texture1 (0x00000010)
|
||||
#define eVtxBatchFlag_Texture2 (0x00000020)
|
||||
|
||||
#define kMaxClipPlanes (6)
|
||||
|
||||
class FontData;
|
||||
class iOcclusionQuery;
|
||||
|
||||
class iLowLevelGraphics {
|
||||
public:
|
||||
virtual ~iLowLevelGraphics() {}
|
||||
/**
|
||||
* Sets the video mode. Must only be called ONCE!
|
||||
* \param alWidth
|
||||
* \param alHeight
|
||||
* \param alBpp
|
||||
* \param abFullscreen
|
||||
* \param alMultiSampling The amount of multisamplimg, 0 = off.
|
||||
* \return
|
||||
*/
|
||||
virtual bool Init(int alWidth, int alHeight, int alBpp, int abFullscreen, int alMultisampling,
|
||||
const tString &asWindowCaption) = 0;
|
||||
|
||||
/**
|
||||
* Get the capabilities of the graphics. Th return value depends on the capability
|
||||
* \param aType
|
||||
* \return
|
||||
*/
|
||||
virtual int GetCaps(eGraphicCaps aType) const = 0;
|
||||
/**
|
||||
* Show the cursor or not. Default is false
|
||||
* \param aX
|
||||
*/
|
||||
virtual void ShowCursor(bool abX) = 0;
|
||||
|
||||
virtual int GetMultisampling() = 0;
|
||||
/**
|
||||
* Get Size of screen
|
||||
* \return
|
||||
*/
|
||||
virtual cVector2f GetScreenSize() = 0;
|
||||
virtual cVector2f GetVirtualSize() = 0;
|
||||
/**
|
||||
* Sets the virtual screen size. Default is 0-1
|
||||
* \param avSize
|
||||
*/
|
||||
virtual void SetVirtualSize(cVector2f avSize) = 0;
|
||||
|
||||
virtual void SetMultisamplingActive(bool abX) = 0;
|
||||
|
||||
virtual void SetGammaCorrection(float afX) = 0;
|
||||
virtual float GetGammaCorrection() = 0;
|
||||
|
||||
virtual void SetClipPlane(int alIdx, const cPlanef &aPlane) = 0;
|
||||
virtual cPlanef GetClipPlane(int alIdx, const cPlanef &aPlane) = 0;
|
||||
virtual void SetClipPlaneActive(int alIdx, bool abX) = 0;
|
||||
|
||||
virtual Bitmap2D *CreateBitmap2D(const cVector2l &avSize) = 0;
|
||||
virtual FontData *CreateFontData(const tString &asName) = 0;
|
||||
|
||||
virtual iTexture *CreateTexture(bool abUseMipMaps, eTextureType aType, eTextureTarget aTarget) = 0;
|
||||
virtual iTexture *CreateTexture(const tString &asName, bool abUseMipMaps, eTextureType aType, eTextureTarget aTarget) = 0;
|
||||
virtual iTexture *CreateTexture(Bitmap2D *apBmp, bool abUseMipMaps, eTextureType aType,
|
||||
eTextureTarget aTarget) = 0;
|
||||
virtual iTexture *CreateTexture(const cVector2l &avSize, int alBpp, cColor aFillCol,
|
||||
bool abUseMipMaps, eTextureType aType, eTextureTarget aTarget) = 0;
|
||||
|
||||
virtual Graphics::PixelFormat *GetPixelFormat() = 0;
|
||||
|
||||
virtual iGpuProgram *CreateGpuProgram(const tString &vertex, const tString &fragment) = 0;
|
||||
|
||||
// TODO: Kinda quick and diry, better to have a screen to Bitmap.
|
||||
// and then a save as in the Bitmap.
|
||||
virtual void SaveScreenToBMP(const tString &asFile) = 0;
|
||||
|
||||
/////////// MATRIX METHODS //////////////////////////
|
||||
|
||||
virtual void PushMatrix(eMatrix aMtxType) = 0;
|
||||
virtual void PopMatrix(eMatrix aMtxType) = 0;
|
||||
virtual void SetIdentityMatrix(eMatrix aMtxType) = 0;
|
||||
|
||||
virtual void SetMatrix(eMatrix aMtxType, const cMatrixf &a_mtxA) = 0;
|
||||
|
||||
virtual void TranslateMatrix(eMatrix aMtxType, const cVector3f &avPos) = 0;
|
||||
virtual void RotateMatrix(eMatrix aMtxType, const cVector3f &avRot) = 0;
|
||||
virtual void ScaleMatrix(eMatrix aMtxType, const cVector3f &avScale) = 0;
|
||||
|
||||
virtual void SetOrthoProjection(const cVector2f &avSize, float afMin, float afMax) = 0;
|
||||
|
||||
/////////// DRAWING METHODS /////////////////////////
|
||||
|
||||
// OCCLUSION
|
||||
virtual iOcclusionQuery *CreateOcclusionQuery() = 0;
|
||||
virtual void DestroyOcclusionQuery(iOcclusionQuery *apQuery) = 0;
|
||||
|
||||
// CLEARING THE FRAMEBUFFER
|
||||
virtual void ClearScreen() = 0;
|
||||
|
||||
virtual void SetClearColor(const cColor &aCol) = 0;
|
||||
virtual void SetClearDepth(float afDepth) = 0;
|
||||
virtual void SetClearStencil(int alVal) = 0;
|
||||
|
||||
virtual void SetClearColorActive(bool abX) = 0;
|
||||
virtual void SetClearDepthActive(bool abX) = 0;
|
||||
virtual void SetClearStencilActive(bool abX) = 0;
|
||||
|
||||
virtual void SetColorWriteActive(bool abR, bool abG, bool abB, bool abA) = 0;
|
||||
virtual void SetDepthWriteActive(bool abX) = 0;
|
||||
|
||||
virtual void SetCullActive(bool abX) = 0;
|
||||
virtual void SetCullMode(eCullMode aMode) = 0;
|
||||
|
||||
// DEPTH
|
||||
virtual void SetDepthTestActive(bool abX) = 0;
|
||||
virtual void SetDepthTestFunc(eDepthTestFunc aFunc) = 0;
|
||||
|
||||
// ALPHA
|
||||
virtual void SetAlphaTestActive(bool abX) = 0;
|
||||
virtual void SetAlphaTestFunc(eAlphaTestFunc aFunc, float afRef) = 0;
|
||||
|
||||
// STENCIL
|
||||
virtual void SetStencilActive(bool abX) = 0;
|
||||
/*virtual void SetStencilTwoSideActive(bool abX)=0;
|
||||
virtual void SetStencilFace(eStencilFace aFace)=0;
|
||||
virtual void SetStencilFunc(eStencilFunc aFunc,int alRef, unsigned int aMask)=0;
|
||||
virtual void SetStencilOp(eStencilOp aFailOp,eStencilOp aZFailOp,eStencilOp aZPassOp)=0;*/
|
||||
virtual void SetStencil(eStencilFunc aFunc, int alRef, unsigned int aMask,
|
||||
eStencilOp aFailOp, eStencilOp aZFailOp, eStencilOp aZPassOp) = 0;
|
||||
virtual void SetStencilTwoSide(eStencilFunc aFrontFunc, eStencilFunc aBackFunc,
|
||||
int alRef, unsigned int aMask,
|
||||
eStencilOp aFrontFailOp, eStencilOp aFrontZFailOp, eStencilOp aFrontZPassOp,
|
||||
eStencilOp aBackFailOp, eStencilOp aBackZFailOp, eStencilOp aBackZPassOp) = 0;
|
||||
virtual void SetStencilTwoSide(bool abX) = 0;
|
||||
|
||||
// SCISSOR
|
||||
virtual void SetScissorActive(bool abX) = 0;
|
||||
virtual void SetScissorRect(const cRect2l &aRect) = 0;
|
||||
|
||||
// TEXTURE
|
||||
virtual void SetTexture(unsigned int alUnit, iTexture *apTex) = 0;
|
||||
virtual void SetActiveTextureUnit(unsigned int alUnit) = 0;
|
||||
virtual void SetTextureEnv(eTextureParam aParam, int alVal) = 0;
|
||||
virtual void SetTextureConstantColor(const cColor &aColor) = 0;
|
||||
|
||||
// COLOR
|
||||
virtual void SetColor(const cColor &aColor) = 0;
|
||||
|
||||
// BLENDING
|
||||
virtual void SetBlendActive(bool abX) = 0;
|
||||
virtual void SetBlendFunc(eBlendFunc aSrcFactor, eBlendFunc aDestFactor) = 0;
|
||||
virtual void SetBlendFuncSeparate(eBlendFunc aSrcFactorColor, eBlendFunc aDestFactorColor,
|
||||
eBlendFunc aSrcFactorAlpha, eBlendFunc aDestFactorAlpha) = 0;
|
||||
|
||||
// POLYGONS
|
||||
virtual iVertexBuffer *CreateVertexBuffer(tVertexFlag aFlags, eVertexBufferDrawType aDrawType,
|
||||
eVertexBufferUsageType aUsageType,
|
||||
int alReserveVtxSize = 0, int alReserveIdxSize = 0) = 0;
|
||||
|
||||
virtual void DrawRect(const cVector2f &avPos, const cVector2f &avSize, float afZ) = 0;
|
||||
|
||||
virtual void DrawTri(const tVertexVec &avVtx) = 0;
|
||||
virtual void DrawTri(const cVertex *avVtx) = 0;
|
||||
|
||||
virtual void DrawQuad(const tVertexVec &avVtx) = 0;
|
||||
virtual void DrawQuad(const tVertexVec &avVtx, const cColor aCol) = 0;
|
||||
virtual void DrawQuad(const tVertexVec &avVtx, const float afZ) = 0;
|
||||
virtual void DrawQuad(const tVertexVec &avVtx, const float afZ, const cColor &aCol) = 0;
|
||||
virtual void DrawQuadMultiTex(const tVertexVec &avVtx, const tVector3fVec &avExtraUvs) = 0;
|
||||
|
||||
// VERTEX BATCHER
|
||||
virtual void AddVertexToBatch(const cVertex &apVtx) = 0;
|
||||
virtual void AddVertexToBatch(const cVertex *apVtx, const cVector3f *avTransform) = 0;
|
||||
virtual void AddVertexToBatch(const cVertex *apVtx, const cMatrixf *aMtx) = 0;
|
||||
|
||||
virtual void AddVertexToBatch_Size2D(const cVertex *apVtx, const cVector3f *avTransform,
|
||||
const cColor *apCol, const float &mfW, const float &mfH) = 0;
|
||||
|
||||
virtual void AddVertexToBatch_Raw(const cVector3f &avPos, const cColor &aColor,
|
||||
const cVector3f &avTex) = 0;
|
||||
|
||||
virtual void AddIndexToBatch(int alIndex) = 0;
|
||||
|
||||
virtual void AddTexCoordToBatch(unsigned int alUnit, const cVector3f *apCoord) = 0;
|
||||
virtual void SetBatchTextureUnitActive(unsigned int alUnit, bool abActive) = 0;
|
||||
|
||||
// Add more ways to add Vertex to the batch?
|
||||
// Index array, vtxArray, etc perhaps?
|
||||
|
||||
virtual void FlushTriBatch(tVtxBatchFlag aTypeFlags, bool abAutoClear = true) = 0;
|
||||
virtual void FlushQuadBatch(tVtxBatchFlag aTypeFlags, bool abAutoClear = true) = 0;
|
||||
virtual void ClearBatch() = 0;
|
||||
|
||||
// some primitive:
|
||||
virtual void DrawLine(const cVector3f &avBegin, const cVector3f &avEnd, cColor aCol) = 0;
|
||||
virtual void DrawBoxMaxMin(const cVector3f &avMax, const cVector3f &avMin, cColor aCol) = 0;
|
||||
virtual void DrawSphere(const cVector3f &avPos, float afRadius, cColor aCol) = 0;
|
||||
|
||||
virtual void DrawLine2D(const cVector2f &avBegin, const cVector2f &avEnd, float afZ, cColor aCol) = 0;
|
||||
virtual void DrawLineRect2D(const cRect2f &aRect, float afZ, cColor aCol) = 0;
|
||||
virtual void DrawLineCircle2D(const cVector2f &avCenter, float afRadius, float afZ, cColor aCol) = 0;
|
||||
|
||||
virtual void DrawFilledRect2D(const cRect2f &aRect, float afZ, cColor aCol) = 0;
|
||||
// GENERAL
|
||||
/**
|
||||
* All further drawing operations are rendered to this texture.
|
||||
* \param pTex Texture to render to. NULL = screen (frame buffer)
|
||||
*/
|
||||
virtual void SetRenderTarget(iTexture *pTex) = 0;
|
||||
/**
|
||||
* Check if the render target uses a z buffer when drawing.
|
||||
* \return
|
||||
*/
|
||||
virtual bool RenderTargetHasZBuffer() = 0;
|
||||
/**
|
||||
* Makes sure the render target is drawn to the target.
|
||||
* Not useful for all implementations.
|
||||
*/
|
||||
virtual void FlushRenderTarget() = 0;
|
||||
|
||||
/**
|
||||
* Copies the current frame buffer to a texture.
|
||||
* \param apTex The texture the framebuffer is copied to.
|
||||
* \param &avPos The Screenpositon
|
||||
* \param &avSize The size of the screen.
|
||||
* \param &avTexOffset The position on the texture.
|
||||
*/
|
||||
virtual void CopyContextToTexure(iTexture *apTex, const cVector2l &avPos,
|
||||
const cVector2l &avSize, const cVector2l &avTexOffset = 0) = 0;
|
||||
virtual void FlushRendering() = 0;
|
||||
virtual void SwapBuffers() = 0;
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_LOWLEVELGRAPHICS_H
|
||||
66
engines/hpl1/engine/graphics/LowLevelPicture.h
Normal file
66
engines/hpl1/engine/graphics/LowLevelPicture.h
Normal file
@@ -0,0 +1,66 @@
|
||||
/* 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_LOWLEVEL_PICTURE_H
|
||||
#define HPL_LOWLEVEL_PICTURE_H
|
||||
|
||||
#include "common/system.h"
|
||||
#include "hpl1/engine/system/String.h"
|
||||
#include "hpl1/engine/system/SystemTypes.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class LowLevelPicture {
|
||||
public:
|
||||
LowLevelPicture(const tString &type) : _type(type) {}
|
||||
virtual ~LowLevelPicture() = default;
|
||||
|
||||
tString getType() { return _type; }
|
||||
|
||||
uint32 getHeight() const { return _height; }
|
||||
uint32 getWidth() const { return _width; }
|
||||
|
||||
virtual uint32 getBpp() const = 0;
|
||||
|
||||
virtual bool hasAlpha() = 0;
|
||||
|
||||
void setPath(const tString &path) { _path = path; }
|
||||
tString getPath() { return _path; }
|
||||
tString getFileName() const { return cString::GetFileName(_path); }
|
||||
|
||||
protected:
|
||||
uint32 _height;
|
||||
uint32 _width;
|
||||
|
||||
private:
|
||||
tString _type;
|
||||
tString _path;
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_LOWLEVEL_PICTURE_H
|
||||
159
engines/hpl1/engine/graphics/Material.cpp
Normal file
159
engines/hpl1/engine/graphics/Material.cpp
Normal file
@@ -0,0 +1,159 @@
|
||||
/* 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/graphics/Material.h"
|
||||
#include "hpl1/engine/graphics/GPUProgram.h"
|
||||
#include "hpl1/engine/graphics/Renderer2D.h"
|
||||
#include "hpl1/engine/graphics/Renderer3D.h"
|
||||
#include "hpl1/engine/resources/GpuProgramManager.h"
|
||||
#include "hpl1/engine/resources/ImageManager.h"
|
||||
#include "hpl1/engine/resources/TextureManager.h"
|
||||
#include "hpl1/engine/scene/Camera.h"
|
||||
#include "hpl1/engine/system/String.h"
|
||||
#include "hpl1/engine/system/low_level_system.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
eMaterialQuality iMaterial::mQuality = eMaterialQuality_High;
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iMaterial::iMaterial(const tString &asName, iLowLevelGraphics *apLowLevelGraphics,
|
||||
cImageManager *apImageManager, cTextureManager *apTextureManager,
|
||||
cRenderer2D *apRenderer, cGpuProgramManager *apProgramManager,
|
||||
eMaterialPicture aPicture, cRenderer3D *apRenderer3D)
|
||||
: iResourceBase(asName, 0) {
|
||||
if (aPicture == eMaterialPicture_Image) {
|
||||
mvImage.resize(eMaterialTexture_LastEnum);
|
||||
Common::fill(mvImage.begin(), mvImage.end(), nullptr);
|
||||
} else {
|
||||
mvTexture.resize(eMaterialTexture_LastEnum);
|
||||
Common::fill(mvTexture.begin(), mvTexture.end(), nullptr);
|
||||
}
|
||||
|
||||
mType = eMaterialType_Null;
|
||||
mPicture = aPicture;
|
||||
|
||||
mpLowLevelGraphics = apLowLevelGraphics;
|
||||
mpImageManager = apImageManager;
|
||||
mpTextureManager = apTextureManager;
|
||||
mpRenderer = apRenderer;
|
||||
mpRenderer3D = apRenderer3D;
|
||||
mpRenderSettings = mpRenderer3D->GetRenderSettings();
|
||||
mpProgramManager = apProgramManager;
|
||||
|
||||
mbUsesLights = false;
|
||||
mbIsTransperant = false;
|
||||
mbIsGlowing = false;
|
||||
mbHasAlpha = false;
|
||||
mbDepthTest = true;
|
||||
mfValue = 1;
|
||||
|
||||
for (int i = 0; i < 2; i++)
|
||||
for (int j = 0; j < kMaxProgramNum; j++)
|
||||
mpProgram[i][j] = NULL;
|
||||
|
||||
mlPassCount = 0;
|
||||
|
||||
mlId = -1;
|
||||
}
|
||||
|
||||
iMaterial::~iMaterial() {
|
||||
int i;
|
||||
|
||||
for (i = 0; i < (int)mvImage.size(); i++) {
|
||||
if (mvImage[i])
|
||||
mpImageManager->Destroy(mvImage[i]);
|
||||
}
|
||||
for (i = 0; i < (int)mvTexture.size(); i++) {
|
||||
if (mvTexture[i])
|
||||
mpTextureManager->Destroy(mvTexture[i]);
|
||||
}
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
for (int j = 0; j < kMaxProgramNum; j++) {
|
||||
if (mpProgram[i][j])
|
||||
mpProgramManager->Destroy(mpProgram[i][j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
/*void iMaterial::Destroy()
|
||||
{
|
||||
|
||||
}*/
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iTexture *iMaterial::GetTexture(eMaterialTexture aType) {
|
||||
if (mPicture == eMaterialPicture_Image) {
|
||||
if (mvImage[aType] == NULL) {
|
||||
Log("2: %d\n", aType);
|
||||
return NULL;
|
||||
}
|
||||
return mvImage[aType]->GetTexture();
|
||||
} else {
|
||||
return mvTexture[aType];
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cRect2f iMaterial::GetTextureOffset(eMaterialTexture aType) {
|
||||
cRect2f SizeRect;
|
||||
|
||||
if (mPicture == eMaterialPicture_Image) {
|
||||
tVertexVec VtxVec = mvImage[aType]->GetVertexVecCopy(0, 0);
|
||||
|
||||
SizeRect.x = VtxVec[0].tex.x;
|
||||
SizeRect.y = VtxVec[0].tex.y;
|
||||
SizeRect.w = VtxVec[2].tex.x - VtxVec[0].tex.x;
|
||||
SizeRect.h = VtxVec[2].tex.y - VtxVec[0].tex.y;
|
||||
} else {
|
||||
SizeRect.x = 0;
|
||||
SizeRect.y = 0;
|
||||
SizeRect.w = 1; //(float) mvTexture[aType]->GetWidth();
|
||||
SizeRect.h = 1; //(float) mvTexture[aType]->GetHeight();
|
||||
}
|
||||
|
||||
return SizeRect;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
} // namespace hpl
|
||||
405
engines/hpl1/engine/graphics/Material.h
Normal file
405
engines/hpl1/engine/graphics/Material.h
Normal file
@@ -0,0 +1,405 @@
|
||||
/* 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_H
|
||||
#define HPL_MATERIAL_H
|
||||
|
||||
#include "common/array.h"
|
||||
#include "common/list.h"
|
||||
#include "hpl1/engine/graphics/GPUProgram.h"
|
||||
#include "hpl1/engine/graphics/LowLevelGraphics.h"
|
||||
#include "hpl1/engine/graphics/Texture.h"
|
||||
#include "hpl1/engine/resources/ResourceBase.h"
|
||||
#include "hpl1/engine/resources/ResourceImage.h"
|
||||
#include "hpl1/engine/system/SystemTypes.h"
|
||||
|
||||
class TiXmlElement;
|
||||
|
||||
namespace hpl {
|
||||
|
||||
#define kMaxProgramNum (5)
|
||||
|
||||
enum eMaterialQuality {
|
||||
eMaterialQuality_VeryLow = 0,
|
||||
eMaterialQuality_Low = 1,
|
||||
eMaterialQuality_Medium = 2,
|
||||
eMaterialQuality_High = 3,
|
||||
eMaterialQuality_VeryHigh = 4,
|
||||
eMaterialQuality_LastEnum = 5
|
||||
};
|
||||
|
||||
enum eMaterialTexture {
|
||||
eMaterialTexture_Diffuse,
|
||||
eMaterialTexture_NMap,
|
||||
eMaterialTexture_Specular,
|
||||
eMaterialTexture_Alpha,
|
||||
eMaterialTexture_Illumination,
|
||||
eMaterialTexture_CubeMap,
|
||||
eMaterialTexture_Refraction,
|
||||
eMaterialTexture_LastEnum
|
||||
};
|
||||
|
||||
enum eMaterialType {
|
||||
eMaterialType_Null,
|
||||
|
||||
eMaterialType_Diffuse,
|
||||
eMaterialType_DiffuseAlpha,
|
||||
eMaterialType_DiffuseAdditive,
|
||||
eMaterialType_DiffuseNMap,
|
||||
eMaterialType_DiffuseSpecular,
|
||||
eMaterialType_BumpSpec,
|
||||
eMaterialType_Smoke,
|
||||
|
||||
eMaterialType_FontNormal,
|
||||
|
||||
eMaterialType_LastEnum
|
||||
};
|
||||
|
||||
enum eMaterialPicture {
|
||||
eMaterialPicture_Image,
|
||||
eMaterialPicture_Texture,
|
||||
eMaterialPicture_LastEnum
|
||||
};
|
||||
|
||||
enum eMaterialRenderType {
|
||||
eMaterialRenderType_Z,
|
||||
eMaterialRenderType_Light,
|
||||
eMaterialRenderType_Diffuse,
|
||||
eMaterialRenderType_LastEnum
|
||||
};
|
||||
|
||||
enum eMaterialBlendMode {
|
||||
eMaterialBlendMode_None,
|
||||
eMaterialBlendMode_Add,
|
||||
eMaterialBlendMode_Mul,
|
||||
eMaterialBlendMode_MulX2,
|
||||
eMaterialBlendMode_Replace,
|
||||
eMaterialBlendMode_Alpha,
|
||||
eMaterialBlendMode_DestAlphaAdd,
|
||||
eMaterialBlendMode_LastEnum
|
||||
};
|
||||
|
||||
enum eMaterialAlphaMode {
|
||||
eMaterialAlphaMode_Solid,
|
||||
eMaterialAlphaMode_Trans,
|
||||
eMaterialAlphaMode_LastEnum,
|
||||
};
|
||||
|
||||
//! Determines what color channels are going to be affected
|
||||
enum eMaterialChannelMode {
|
||||
eMaterialChannelMode_RGBA,
|
||||
eMaterialChannelMode_RGB,
|
||||
eMaterialChannelMode_A,
|
||||
eMaterialChannelMode_Z,
|
||||
eMaterialChannelMode_LastEnum,
|
||||
};
|
||||
|
||||
//---------------------------------------------------
|
||||
|
||||
class cRenderer2D;
|
||||
class cRenderer3D;
|
||||
class cRenderSettings;
|
||||
class cTextureManager;
|
||||
class cImageManager;
|
||||
class cGpuProgramManager;
|
||||
class iLight;
|
||||
class iCamera;
|
||||
class iLight3D;
|
||||
|
||||
//---------------------------------------------------
|
||||
|
||||
class iGLStateProgram : public iGpuProgram {
|
||||
public:
|
||||
iGLStateProgram(tString asName)
|
||||
: iGpuProgram(asName) {
|
||||
mbSetUpDone = false;
|
||||
}
|
||||
virtual ~iGLStateProgram() {}
|
||||
|
||||
void SetUp(iLowLevelGraphics *apLowLevelGraphics) {
|
||||
if (mbSetUpDone == false) {
|
||||
mpLowGfx = apLowLevelGraphics;
|
||||
mbSetUpDone = true;
|
||||
InitData();
|
||||
}
|
||||
}
|
||||
|
||||
virtual void Bind() = 0;
|
||||
virtual void UnBind() = 0;
|
||||
|
||||
bool CreateFromFile(const tString &asFile, const tString &asEntry) { return false; }
|
||||
bool SetFloat(const tString &asName, float afX) { return false; }
|
||||
|
||||
bool SetVec2f(const tString &asName, float afX, float afY) { return false; }
|
||||
bool SetVec3f(const tString &asName, float afX, float afY, float afZ) { return false; }
|
||||
bool SetVec4f(const tString &asName, float afX, float afY, float afZ, float afW) { return false; }
|
||||
bool SetMatrixf(const tString &asName, const cMatrixf &mMtx) { return false; }
|
||||
bool SetMatrixf(const tString &asName, eGpuProgramMatrix mType, eGpuProgramMatrixOp mOp) { return false; }
|
||||
bool SetTexture(const tString &asName, iTexture *apTexture, bool abAutoDisable = true) { return false; }
|
||||
bool SetTextureToUnit(int alUnit, iTexture *apTexture) { return false; }
|
||||
|
||||
eGpuProgramType GetType() { return eGpuProgramType_LastEnum; }
|
||||
|
||||
bool reload() { return false; }
|
||||
void unload() {}
|
||||
void destroy() {}
|
||||
|
||||
protected:
|
||||
iLowLevelGraphics *mpLowGfx;
|
||||
|
||||
bool mbSetUpDone;
|
||||
|
||||
virtual void InitData() = 0;
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------
|
||||
|
||||
class iMaterialProgramSetup {
|
||||
public:
|
||||
virtual ~iMaterialProgramSetup() = default;
|
||||
virtual void Setup(iGpuProgram *apProgram, cRenderSettings *apRenderSettings) = 0;
|
||||
virtual void SetupMatrix(cMatrixf *apModelMatrix, cRenderSettings *apRenderSettings) {}
|
||||
};
|
||||
|
||||
//---------------------------------------------------
|
||||
|
||||
class cTextureType {
|
||||
public:
|
||||
cTextureType(tString asSuffix, eMaterialTexture aType) : msSuffix(asSuffix), mType(aType) {}
|
||||
|
||||
tString msSuffix;
|
||||
eMaterialTexture mType;
|
||||
};
|
||||
|
||||
typedef Common::List<cTextureType> tTextureTypeList;
|
||||
typedef tTextureTypeList::iterator tTextureTypeListIt;
|
||||
|
||||
//---------------------------------------------------
|
||||
|
||||
class iMaterial : public iResourceBase {
|
||||
public:
|
||||
iMaterial(const tString &asName, iLowLevelGraphics *apLowLevelGraphics,
|
||||
cImageManager *apImageManager, cTextureManager *apTextureManager,
|
||||
cRenderer2D *apRenderer, cGpuProgramManager *apProgramManager,
|
||||
eMaterialPicture aPicture, cRenderer3D *apRenderer3D);
|
||||
virtual ~iMaterial();
|
||||
|
||||
// resources stuff.
|
||||
bool reload() { return false; }
|
||||
void unload() {}
|
||||
void destroy() {}
|
||||
|
||||
virtual void Compile() = 0;
|
||||
|
||||
virtual void Update(float afTimeStep) {}
|
||||
|
||||
// The new render system stuff
|
||||
virtual iGpuProgram *getGpuProgram(const eMaterialRenderType aType, const int alPass, iLight3D *apLight) { return nullptr; }
|
||||
virtual iMaterialProgramSetup *getGpuProgramSetup(const eMaterialRenderType aType, const int alPass, iLight3D *apLight) { return nullptr; };
|
||||
|
||||
virtual iGpuProgram *GetVertexProgram(eMaterialRenderType aType, int alPass, iLight3D *apLight) { return NULL; }
|
||||
virtual bool VertexProgramUsesLight(eMaterialRenderType aType, int alPass, iLight3D *apLight) { return false; }
|
||||
virtual bool VertexProgramUsesEye(eMaterialRenderType aType, int alPass, iLight3D *apLight) { return false; }
|
||||
virtual iMaterialProgramSetup *GetVertexProgramSetup(eMaterialRenderType aType, int alPass, iLight3D *apLight) { return NULL; }
|
||||
|
||||
virtual iGpuProgram *GetFragmentProgram(eMaterialRenderType aType, int alPass, iLight3D *apLight) { return NULL; }
|
||||
virtual iMaterialProgramSetup *GetFragmentProgramSetup(eMaterialRenderType aType, int alPass, iLight3D *apLight) { return NULL; }
|
||||
|
||||
virtual eMaterialAlphaMode GetAlphaMode(eMaterialRenderType aType, int alPass, iLight3D *apLight) { return eMaterialAlphaMode_Solid; }
|
||||
virtual eMaterialBlendMode GetBlendMode(eMaterialRenderType aType, int alPass, iLight3D *apLight) { return eMaterialBlendMode_Replace; }
|
||||
virtual eMaterialChannelMode GetChannelMode(eMaterialRenderType aType, int alPass, iLight3D *apLight) { return eMaterialChannelMode_RGBA; }
|
||||
|
||||
virtual iTexture *GetTexture(int alUnit, eMaterialRenderType aType, int alPass, iLight3D *apLight) { return NULL; }
|
||||
virtual eMaterialBlendMode GetTextureBlend(int alUnit, eMaterialRenderType aType, int alPass, iLight3D *apLight) { return eMaterialBlendMode_None; }
|
||||
|
||||
virtual int GetNumOfPasses(eMaterialRenderType aType, iLight3D *apLight) { return 0; }
|
||||
|
||||
virtual bool UsesType(eMaterialRenderType aType) { return false; }
|
||||
|
||||
bool HasAlpha() { return mbHasAlpha; }
|
||||
void SetHasAlpha(bool abX) { mbHasAlpha = abX; }
|
||||
|
||||
bool GetDepthTest() { return mbDepthTest; }
|
||||
void SetDepthTest(bool abX) { mbDepthTest = abX; }
|
||||
|
||||
float GetValue() { return mfValue; }
|
||||
void SetValue(float afX) { mfValue = afX; }
|
||||
|
||||
virtual bool LoadData(TiXmlElement *apRootElem) { return true; }
|
||||
|
||||
/**
|
||||
* Here the set up should be done like setting texture units, blend mode, etc
|
||||
* \param mType
|
||||
* \param apCam
|
||||
* \param *pLight
|
||||
* \return
|
||||
*/
|
||||
virtual bool StartRendering(eMaterialRenderType aType, iCamera *apCam, iLight *pLight) = 0;
|
||||
/**
|
||||
* Here all stuff should be set back to normal, like unbinding gpu programs
|
||||
* \param mType
|
||||
*/
|
||||
virtual void EndRendering(eMaterialRenderType mType) = 0;
|
||||
/**
|
||||
* Return the data types needed for rendering.
|
||||
* \param mType
|
||||
* \return
|
||||
*/
|
||||
virtual tVtxBatchFlag GetBatchFlags(eMaterialRenderType mType) = 0;
|
||||
|
||||
/**
|
||||
* Set new states and return true for another pass
|
||||
* \param mType
|
||||
* \return
|
||||
*/
|
||||
virtual bool NextPass(eMaterialRenderType mType) = 0;
|
||||
/**
|
||||
* return true if the program has multple passes
|
||||
* \param mType
|
||||
* \return
|
||||
*/
|
||||
virtual bool HasMultiplePasses(eMaterialRenderType mType) = 0;
|
||||
|
||||
/**
|
||||
* Get type
|
||||
* \param mType
|
||||
* \return
|
||||
*/
|
||||
virtual eMaterialType GetType(eMaterialRenderType mType) = 0;
|
||||
virtual void EditVertexes(eMaterialRenderType mType, iCamera *apCam, iLight *pLight,
|
||||
tVertexVec *apVtxVec, cVector3f *apTransform, unsigned int alIndexAdd) = 0;
|
||||
|
||||
iTexture *GetTexture(eMaterialTexture aType);
|
||||
cRect2f GetTextureOffset(eMaterialTexture aType);
|
||||
|
||||
void SetTexture(iTexture *apTex, eMaterialTexture aType) { mvTexture[aType] = apTex; }
|
||||
void SetImage(cResourceImage *apImg, eMaterialTexture aType) {
|
||||
mvImage[aType] = apImg;
|
||||
}
|
||||
cResourceImage *GetImage(eMaterialTexture aType) { return mvImage[aType]; }
|
||||
|
||||
void SetProgram(iGpuProgram *apProgram, eGpuProgramType aType, unsigned int alNum) {
|
||||
mpProgram[aType][alNum] = apProgram;
|
||||
}
|
||||
iGpuProgram *GetProgram(eGpuProgramType aType, unsigned int alNum) {
|
||||
return mpProgram[aType][alNum];
|
||||
}
|
||||
|
||||
/**
|
||||
* return true if the material is transparent
|
||||
* \return
|
||||
*/
|
||||
virtual bool IsTransperant() { return mbIsTransperant; }
|
||||
virtual bool IsGlowing() { return mbIsGlowing; }
|
||||
/**
|
||||
* return true if the material has a light pass
|
||||
* \return
|
||||
*/
|
||||
virtual bool UsesLights() { return mbUsesLights; }
|
||||
|
||||
virtual tTextureTypeList GetTextureTypes() {
|
||||
tTextureTypeList vTypes;
|
||||
vTypes.push_back(cTextureType("", eMaterialTexture_Diffuse));
|
||||
return vTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* The type of the material
|
||||
* \param alId
|
||||
*/
|
||||
void SetId(int alId) { mlId = alId; }
|
||||
int GetId() { return mlId; }
|
||||
|
||||
virtual iGpuProgram *getRefractionProgram() { return nullptr; }
|
||||
|
||||
virtual bool GetRefractionUsesDiffuse() { return false; }
|
||||
virtual eMaterialTexture GetRefractionDiffuseTexture() { return eMaterialTexture_Diffuse; }
|
||||
|
||||
virtual bool GetRefractionUsesEye() { return false; }
|
||||
virtual bool GetRefractionUsesTime() { return false; }
|
||||
virtual bool GetRefractionSkipsStandardTrans() { return false; }
|
||||
|
||||
const tString &GetPhysicsMaterial() { return msPhysicsMaterial; }
|
||||
void SetPhysicsMaterial(const tString &asName) { msPhysicsMaterial = asName; }
|
||||
|
||||
static void SetQuality(eMaterialQuality aQuality) { mQuality = aQuality; }
|
||||
static eMaterialQuality GetQuality() { return mQuality; }
|
||||
|
||||
protected:
|
||||
iLowLevelGraphics *mpLowLevelGraphics;
|
||||
cImageManager *mpImageManager;
|
||||
cTextureManager *mpTextureManager;
|
||||
cRenderer2D *mpRenderer;
|
||||
cRenderer3D *mpRenderer3D;
|
||||
cRenderSettings *mpRenderSettings;
|
||||
cGpuProgramManager *mpProgramManager;
|
||||
|
||||
static eMaterialQuality mQuality;
|
||||
|
||||
bool mbIsTransperant;
|
||||
bool mbIsGlowing;
|
||||
bool mbUsesLights;
|
||||
bool mbHasAlpha;
|
||||
bool mbDepthTest;
|
||||
float mfValue;
|
||||
|
||||
int mlId;
|
||||
|
||||
tString msPhysicsMaterial;
|
||||
|
||||
tTextureVec mvTexture;
|
||||
tResourceImageVec mvImage;
|
||||
|
||||
eMaterialType mType;
|
||||
eMaterialPicture mPicture;
|
||||
|
||||
iGpuProgram *mpProgram[2][kMaxProgramNum];
|
||||
|
||||
int mlPassCount;
|
||||
|
||||
// void Destroy();
|
||||
};
|
||||
|
||||
typedef Common::Array<iMaterial *> tMaterialVec;
|
||||
typedef tMaterialVec::iterator tMaterialVecIt;
|
||||
|
||||
class iMaterialType {
|
||||
public:
|
||||
virtual ~iMaterialType() = default;
|
||||
virtual bool IsCorrect(tString asName) = 0;
|
||||
virtual iMaterial *Create(const tString &asName, iLowLevelGraphics *apLowLevelGraphics,
|
||||
cImageManager *apImageManager, cTextureManager *apTextureManager,
|
||||
cRenderer2D *apRenderer, cGpuProgramManager *apProgramManager,
|
||||
eMaterialPicture aPicture, cRenderer3D *apRenderer3D) = 0;
|
||||
};
|
||||
|
||||
typedef Common::List<iMaterialType *> tMaterialTypeList;
|
||||
typedef tMaterialTypeList::iterator tMaterialTypeListIt;
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_MATERIAL_H
|
||||
108
engines/hpl1/engine/graphics/MaterialHandler.cpp
Normal file
108
engines/hpl1/engine/graphics/MaterialHandler.cpp
Normal file
@@ -0,0 +1,108 @@
|
||||
/* 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/graphics/MaterialHandler.h"
|
||||
#include "hpl1/engine/graphics/Graphics.h"
|
||||
#include "hpl1/engine/resources/ResourceImage.h"
|
||||
#include "hpl1/engine/resources/Resources.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cMaterialHandler::cMaterialHandler(cGraphics *apGraphics, cResources *apResources) {
|
||||
mpGraphics = apGraphics;
|
||||
mpResources = apResources;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cMaterialHandler::~cMaterialHandler() {
|
||||
tMaterialTypeListIt it = mlstMatTypes.begin();
|
||||
for (; it != mlstMatTypes.end(); it++) {
|
||||
hplDelete(*it);
|
||||
}
|
||||
|
||||
mlstMatTypes.clear();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cMaterialHandler::Add(iMaterialType *apTypedata) {
|
||||
mlstMatTypes.push_back(apTypedata);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
iMaterial *cMaterialHandler::Create(tString asMatName, eMaterialPicture mPicType) {
|
||||
return Create("", asMatName, mPicType);
|
||||
}
|
||||
|
||||
iMaterial *cMaterialHandler::Create(const tString &asName, tString asMatName, eMaterialPicture mPicType) {
|
||||
iMaterial *pMat = NULL;
|
||||
// cResourceImage *pImage = NULL;
|
||||
unsigned int lIdCount = 1;
|
||||
|
||||
for (tMaterialTypeListIt it = mlstMatTypes.begin(); it != mlstMatTypes.end(); it++) {
|
||||
if ((*it)->IsCorrect(asMatName)) {
|
||||
pMat = (*it)->Create(asName, mpGraphics->GetLowLevel(), mpResources->GetImageManager(),
|
||||
mpResources->GetTextureManager(),
|
||||
mpGraphics->GetRenderer2D(), mpResources->GetGpuProgramManager(),
|
||||
mPicType, mpGraphics->GetRenderer3D());
|
||||
|
||||
// Set an id to the material for easier rendering later on.
|
||||
pMat->SetId(lIdCount);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
lIdCount++;
|
||||
}
|
||||
|
||||
return pMat;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PRIVATE METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
} // namespace hpl
|
||||
66
engines/hpl1/engine/graphics/MaterialHandler.h
Normal file
66
engines/hpl1/engine/graphics/MaterialHandler.h
Normal file
@@ -0,0 +1,66 @@
|
||||
/* 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_MATERIALHANDLER_H
|
||||
#define HPL_MATERIALHANDLER_H
|
||||
|
||||
#include "hpl1/engine/graphics/Material.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class cGraphics;
|
||||
class cResources;
|
||||
|
||||
class cMaterialHandler {
|
||||
public:
|
||||
cMaterialHandler(cGraphics *apGraphics, cResources *apResources);
|
||||
~cMaterialHandler();
|
||||
|
||||
/**
|
||||
* Add a new type of material
|
||||
* \param apTypedata
|
||||
*/
|
||||
void Add(iMaterialType *apTypedata);
|
||||
/**
|
||||
* Create a new material
|
||||
* \param asMatName
|
||||
* \param mPicType
|
||||
* \return
|
||||
*/
|
||||
iMaterial *Create(tString asMatName, eMaterialPicture mPicType);
|
||||
|
||||
iMaterial *Create(const tString &asName, tString asMatName, eMaterialPicture mPicType);
|
||||
|
||||
private:
|
||||
tMaterialTypeList mlstMatTypes;
|
||||
cResources *mpResources;
|
||||
cGraphics *mpGraphics;
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_MATERIALHANDLER_H
|
||||
162
engines/hpl1/engine/graphics/Material_Additive.cpp
Normal file
162
engines/hpl1/engine/graphics/Material_Additive.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/graphics/Material_Additive.h"
|
||||
#include "hpl1/engine/graphics/GPUProgram.h"
|
||||
#include "hpl1/engine/graphics/Renderer2D.h"
|
||||
#include "hpl1/engine/graphics/Renderer3D.h"
|
||||
#include "hpl1/engine/math/Math.h"
|
||||
#include "hpl1/engine/resources/GpuProgramManager.h"
|
||||
#include "hpl1/engine/resources/TextureManager.h"
|
||||
#include "hpl1/engine/scene/Camera.h"
|
||||
#include "hpl1/engine/scene/Light.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// VERTEX PRORGAM SETUP
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
class cFogProgramSetup : public iMaterialProgramSetup {
|
||||
public:
|
||||
void Setup(iGpuProgram *apProgram, cRenderSettings *apRenderSettings) {
|
||||
// apProgram->SetColor3f("fogColor",apRenderSettings->mFogColor);
|
||||
apProgram->SetFloat("fogStart", apRenderSettings->mfFogStart);
|
||||
apProgram->SetFloat("fogEnd", apRenderSettings->mfFogEnd);
|
||||
}
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cMaterial_Additive::cMaterial_Additive(const tString &asName, iLowLevelGraphics *apLowLevelGraphics,
|
||||
cImageManager *apImageManager, cTextureManager *apTextureManager,
|
||||
cRenderer2D *apRenderer, cGpuProgramManager *apProgramManager,
|
||||
eMaterialPicture aPicture, cRenderer3D *apRenderer3D)
|
||||
: iMaterial(asName, apLowLevelGraphics, apImageManager, apTextureManager, apRenderer, apProgramManager,
|
||||
aPicture, apRenderer3D) {
|
||||
mbIsTransperant = true;
|
||||
mbIsGlowing = false;
|
||||
mbUsesLights = false;
|
||||
|
||||
_fogShader = mpProgramManager->CreateProgram("hpl1_Fog_Trans", "hpl1_Fog_Trans_Alpha");
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cMaterial_Additive::~cMaterial_Additive() {
|
||||
if (_fogShader)
|
||||
mpProgramManager->Destroy(_fogShader);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iGpuProgram *cMaterial_Additive::getGpuProgram(const eMaterialRenderType aType, const int alPass, iLight3D *apLight) {
|
||||
if (mpRenderSettings->mbFogActive)
|
||||
return _fogShader;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
iMaterialProgramSetup *cMaterial_Additive::getGpuProgramSetup(const eMaterialRenderType aType, const int alPass, iLight3D *apLight) {
|
||||
static cFogProgramSetup fogProgramSetup;
|
||||
if (mpRenderSettings->mbFogActive)
|
||||
return &fogProgramSetup;
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool cMaterial_Additive::VertexProgramUsesLight(eMaterialRenderType aType, int alPass, iLight3D *apLight) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool cMaterial_Additive::VertexProgramUsesEye(eMaterialRenderType aType, int alPass, iLight3D *apLight) {
|
||||
return false;
|
||||
}
|
||||
|
||||
eMaterialAlphaMode cMaterial_Additive::GetAlphaMode(eMaterialRenderType aType, int alPass, iLight3D *apLight) {
|
||||
return eMaterialAlphaMode_Solid;
|
||||
}
|
||||
|
||||
eMaterialBlendMode cMaterial_Additive::GetBlendMode(eMaterialRenderType aType, int alPass, iLight3D *apLight) {
|
||||
return eMaterialBlendMode_Add;
|
||||
}
|
||||
|
||||
eMaterialChannelMode cMaterial_Additive::GetChannelMode(eMaterialRenderType aType, int alPass, iLight3D *apLight) {
|
||||
return eMaterialChannelMode_RGBA;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iTexture *cMaterial_Additive::GetTexture(int alUnit, eMaterialRenderType aType, int alPass, iLight3D *apLight) {
|
||||
if (alUnit == 0)
|
||||
return mvTexture[eMaterialTexture_Diffuse];
|
||||
|
||||
if (alUnit == 1 && mpRenderSettings->mbFogActive) {
|
||||
return mpRenderer3D->GetFogAddTexture();
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
eMaterialBlendMode cMaterial_Additive::GetTextureBlend(int alUnit, eMaterialRenderType aType, int alPass, iLight3D *apLight) {
|
||||
return eMaterialBlendMode_Mul;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cMaterial_Additive::UsesType(eMaterialRenderType aType) {
|
||||
if (aType == eMaterialRenderType_Diffuse)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
tTextureTypeList cMaterial_Additive::GetTextureTypes() {
|
||||
tTextureTypeList vTypes;
|
||||
vTypes.push_back(cTextureType("", eMaterialTexture_Diffuse));
|
||||
vTypes.push_back(cTextureType("_ref", eMaterialTexture_Refraction));
|
||||
vTypes.push_back(cTextureType("_spec", eMaterialTexture_Specular));
|
||||
|
||||
return vTypes;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
} // namespace hpl
|
||||
98
engines/hpl1/engine/graphics/Material_Additive.h
Normal file
98
engines/hpl1/engine/graphics/Material_Additive.h
Normal file
@@ -0,0 +1,98 @@
|
||||
/* 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_ADDITIVE_H
|
||||
#define HPL_MATERIAL_ADDITIVE_H
|
||||
|
||||
#include "hpl1/engine/graphics/GPUProgram.h"
|
||||
#include "hpl1/engine/graphics/Material.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class cMaterial_Additive : public iMaterial {
|
||||
public:
|
||||
cMaterial_Additive(const tString &asName, iLowLevelGraphics *apLowLevelGraphics,
|
||||
cImageManager *apImageManager, cTextureManager *apTextureManager,
|
||||
cRenderer2D *apRenderer, cGpuProgramManager *apProgramManager,
|
||||
eMaterialPicture aPicture, cRenderer3D *apRenderer3D);
|
||||
|
||||
virtual ~cMaterial_Additive();
|
||||
|
||||
tTextureTypeList GetTextureTypes();
|
||||
|
||||
bool UsesType(eMaterialRenderType aType);
|
||||
|
||||
iGpuProgram *getGpuProgram(const eMaterialRenderType aType, const int alPass, iLight3D *apLight);
|
||||
iMaterialProgramSetup *getGpuProgramSetup(const eMaterialRenderType aType, const int alPass, iLight3D *apLight);
|
||||
|
||||
bool VertexProgramUsesLight(eMaterialRenderType aType, int alPass, iLight3D *apLight);
|
||||
bool VertexProgramUsesEye(eMaterialRenderType aType, int alPass, iLight3D *apLight);
|
||||
|
||||
eMaterialAlphaMode GetAlphaMode(eMaterialRenderType aType, int alPass, iLight3D *apLight);
|
||||
eMaterialBlendMode GetBlendMode(eMaterialRenderType aType, int alPass, iLight3D *apLight);
|
||||
eMaterialChannelMode GetChannelMode(eMaterialRenderType aType, int alPass, iLight3D *apLight);
|
||||
|
||||
iTexture *GetTexture(int alUnit, eMaterialRenderType aType, int alPass, iLight3D *apLight);
|
||||
eMaterialBlendMode GetTextureBlend(int alUnit, eMaterialRenderType aType, int alPass, iLight3D *apLight);
|
||||
|
||||
int GetNumOfPasses(eMaterialRenderType aType, iLight3D *apLight) { return 1; }
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// Old and worthless stuff, only used by 2D renderer
|
||||
void Compile() {}
|
||||
bool StartRendering(eMaterialRenderType aType, iCamera *apCam, iLight *pLight) { return false; }
|
||||
void EndRendering(eMaterialRenderType aType) {}
|
||||
tVtxBatchFlag GetBatchFlags(eMaterialRenderType aType) { return 0; }
|
||||
bool NextPass(eMaterialRenderType aType) { return false; }
|
||||
bool HasMultiplePasses(eMaterialRenderType aType) { return false; }
|
||||
eMaterialType GetType(eMaterialRenderType aType) { return eMaterialType_Diffuse; }
|
||||
void EditVertexes(eMaterialRenderType aType, iCamera *apCam, iLight *pLight,
|
||||
tVertexVec *apVtxVec, cVector3f *apTransform, unsigned int alIndexAdd) {}
|
||||
|
||||
private:
|
||||
iGpuProgram *_fogShader;
|
||||
};
|
||||
|
||||
class cMaterialType_Additive : public iMaterialType {
|
||||
public:
|
||||
bool IsCorrect(tString asName) {
|
||||
return cString::ToLowerCase(asName) == "additive";
|
||||
}
|
||||
|
||||
iMaterial *Create(const tString &asName, iLowLevelGraphics *apLowLevelGraphics,
|
||||
cImageManager *apImageManager, cTextureManager *apTextureManager,
|
||||
cRenderer2D *apRenderer, cGpuProgramManager *apProgramManager,
|
||||
eMaterialPicture aPicture, cRenderer3D *apRenderer3D) {
|
||||
return hplNew(cMaterial_Additive, (asName, apLowLevelGraphics,
|
||||
apImageManager, apTextureManager, apRenderer,
|
||||
apProgramManager, aPicture, apRenderer3D));
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_MATERIAL_ADDITIVE_H
|
||||
158
engines/hpl1/engine/graphics/Material_Alpha.cpp
Normal file
158
engines/hpl1/engine/graphics/Material_Alpha.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/graphics/Material_Alpha.h"
|
||||
#include "hpl1/engine/graphics/GPUProgram.h"
|
||||
#include "hpl1/engine/graphics/Renderer2D.h"
|
||||
#include "hpl1/engine/graphics/Renderer3D.h"
|
||||
#include "hpl1/engine/math/Math.h"
|
||||
#include "hpl1/engine/resources/GpuProgramManager.h"
|
||||
#include "hpl1/engine/resources/TextureManager.h"
|
||||
#include "hpl1/engine/scene/Camera.h"
|
||||
#include "hpl1/engine/scene/Light.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// VERTEX PRORGAM SETUP
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
class cFogProgramSetup : public iMaterialProgramSetup {
|
||||
public:
|
||||
void Setup(iGpuProgram *apProgram, cRenderSettings *apRenderSettings) {
|
||||
apProgram->SetFloat("fogStart", apRenderSettings->mfFogStart);
|
||||
apProgram->SetFloat("fogEnd", apRenderSettings->mfFogEnd);
|
||||
}
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cMaterial_Alpha::cMaterial_Alpha(const tString &asName, iLowLevelGraphics *apLowLevelGraphics,
|
||||
cImageManager *apImageManager, cTextureManager *apTextureManager,
|
||||
cRenderer2D *apRenderer, cGpuProgramManager *apProgramManager,
|
||||
eMaterialPicture aPicture, cRenderer3D *apRenderer3D)
|
||||
: iMaterial(asName, apLowLevelGraphics, apImageManager, apTextureManager, apRenderer, apProgramManager,
|
||||
aPicture, apRenderer3D) {
|
||||
mbIsTransperant = true;
|
||||
mbIsGlowing = false;
|
||||
mbUsesLights = false;
|
||||
|
||||
_fogShader = mpProgramManager->CreateProgram("hpl1_Fog_Trans", "hpl1_Fog_Trans_Alpha");
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cMaterial_Alpha::~cMaterial_Alpha() {
|
||||
if (_fogShader)
|
||||
mpProgramManager->Destroy(_fogShader);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iGpuProgram *cMaterial_Alpha::getGpuProgram(eMaterialRenderType aType, int alPass, iLight3D *apLight) {
|
||||
if (mpRenderSettings->mbFogActive)
|
||||
return _fogShader;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
iMaterialProgramSetup *cMaterial_Alpha::getGpuProgramSetup(const eMaterialRenderType aType, const int alPass, iLight3D *apLight) {
|
||||
static cFogProgramSetup fogProgramSetup;
|
||||
if (mpRenderSettings->mbFogActive)
|
||||
return &fogProgramSetup;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool cMaterial_Alpha::VertexProgramUsesLight(eMaterialRenderType aType, int alPass, iLight3D *apLight) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool cMaterial_Alpha::VertexProgramUsesEye(eMaterialRenderType aType, int alPass, iLight3D *apLight) {
|
||||
return false;
|
||||
}
|
||||
|
||||
eMaterialAlphaMode cMaterial_Alpha::GetAlphaMode(eMaterialRenderType aType, int alPass, iLight3D *apLight) {
|
||||
return eMaterialAlphaMode_Solid;
|
||||
}
|
||||
|
||||
eMaterialBlendMode cMaterial_Alpha::GetBlendMode(eMaterialRenderType aType, int alPass, iLight3D *apLight) {
|
||||
return eMaterialBlendMode_Alpha;
|
||||
}
|
||||
|
||||
eMaterialChannelMode cMaterial_Alpha::GetChannelMode(eMaterialRenderType aType, int alPass, iLight3D *apLight) {
|
||||
return eMaterialChannelMode_RGBA;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iTexture *cMaterial_Alpha::GetTexture(int alUnit, eMaterialRenderType aType, int alPass, iLight3D *apLight) {
|
||||
if (alUnit == 0)
|
||||
return mvTexture[eMaterialTexture_Diffuse];
|
||||
|
||||
if (alUnit == 1 && mpRenderSettings->mbFogActive) {
|
||||
return mpRenderer3D->GetFogAlphaTexture();
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
eMaterialBlendMode cMaterial_Alpha::GetTextureBlend(int alUnit, eMaterialRenderType aType, int alPass, iLight3D *apLight) {
|
||||
return eMaterialBlendMode_Mul;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cMaterial_Alpha::UsesType(eMaterialRenderType aType) {
|
||||
if (aType == eMaterialRenderType_Diffuse)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
tTextureTypeList cMaterial_Alpha::GetTextureTypes() {
|
||||
tTextureTypeList vTypes;
|
||||
vTypes.push_back(cTextureType("", eMaterialTexture_Diffuse));
|
||||
vTypes.push_back(cTextureType("_ref", eMaterialTexture_Refraction));
|
||||
vTypes.push_back(cTextureType("_spec", eMaterialTexture_Specular));
|
||||
|
||||
return vTypes;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
} // namespace hpl
|
||||
98
engines/hpl1/engine/graphics/Material_Alpha.h
Normal file
98
engines/hpl1/engine/graphics/Material_Alpha.h
Normal file
@@ -0,0 +1,98 @@
|
||||
/* 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_ALPHA_H
|
||||
#define HPL_MATERIAL_ALPHA_H
|
||||
|
||||
#include "hpl1/engine/graphics/GPUProgram.h"
|
||||
#include "hpl1/engine/graphics/Material.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class cMaterial_Alpha : public iMaterial {
|
||||
public:
|
||||
cMaterial_Alpha(const tString &asName, iLowLevelGraphics *apLowLevelGraphics,
|
||||
cImageManager *apImageManager, cTextureManager *apTextureManager,
|
||||
cRenderer2D *apRenderer, cGpuProgramManager *apProgramManager,
|
||||
eMaterialPicture aPicture, cRenderer3D *apRenderer3D);
|
||||
|
||||
virtual ~cMaterial_Alpha();
|
||||
|
||||
tTextureTypeList GetTextureTypes();
|
||||
|
||||
bool UsesType(eMaterialRenderType aType);
|
||||
|
||||
iGpuProgram *getGpuProgram(const eMaterialRenderType aType, const int alPass, iLight3D *apLight);
|
||||
iMaterialProgramSetup *getGpuProgramSetup(const eMaterialRenderType aType, const int alPass, iLight3D *apLight);
|
||||
|
||||
bool VertexProgramUsesLight(eMaterialRenderType aType, int alPass, iLight3D *apLight);
|
||||
bool VertexProgramUsesEye(eMaterialRenderType aType, int alPass, iLight3D *apLight);
|
||||
|
||||
eMaterialAlphaMode GetAlphaMode(eMaterialRenderType aType, int alPass, iLight3D *apLight);
|
||||
eMaterialBlendMode GetBlendMode(eMaterialRenderType aType, int alPass, iLight3D *apLight);
|
||||
eMaterialChannelMode GetChannelMode(eMaterialRenderType aType, int alPass, iLight3D *apLight);
|
||||
|
||||
iTexture *GetTexture(int alUnit, eMaterialRenderType aType, int alPass, iLight3D *apLight);
|
||||
eMaterialBlendMode GetTextureBlend(int alUnit, eMaterialRenderType aType, int alPass, iLight3D *apLight);
|
||||
|
||||
int GetNumOfPasses(eMaterialRenderType aType, iLight3D *apLight) { return 1; }
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// Old and worthless stuff, only used by 2D renderer
|
||||
void Compile() {}
|
||||
bool StartRendering(eMaterialRenderType aType, iCamera *apCam, iLight *pLight) { return false; }
|
||||
void EndRendering(eMaterialRenderType aType) {}
|
||||
tVtxBatchFlag GetBatchFlags(eMaterialRenderType aType) { return 0; }
|
||||
bool NextPass(eMaterialRenderType aType) { return false; }
|
||||
bool HasMultiplePasses(eMaterialRenderType aType) { return false; }
|
||||
eMaterialType GetType(eMaterialRenderType aType) { return eMaterialType_Diffuse; }
|
||||
void EditVertexes(eMaterialRenderType aType, iCamera *apCam, iLight *pLight,
|
||||
tVertexVec *apVtxVec, cVector3f *apTransform, unsigned int alIndexAdd) {}
|
||||
|
||||
private:
|
||||
iGpuProgram *_fogShader;
|
||||
};
|
||||
|
||||
class cMaterialType_Alpha : public iMaterialType {
|
||||
public:
|
||||
bool IsCorrect(tString asName) {
|
||||
return cString::ToLowerCase(asName) == "alpha";
|
||||
}
|
||||
|
||||
iMaterial *Create(const tString &asName, iLowLevelGraphics *apLowLevelGraphics,
|
||||
cImageManager *apImageManager, cTextureManager *apTextureManager,
|
||||
cRenderer2D *apRenderer, cGpuProgramManager *apProgramManager,
|
||||
eMaterialPicture aPicture, cRenderer3D *apRenderer3D) {
|
||||
return hplNew(cMaterial_Alpha, (asName, apLowLevelGraphics,
|
||||
apImageManager, apTextureManager, apRenderer,
|
||||
apProgramManager, aPicture, apRenderer3D));
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_MATERIAL_ALPHA_H
|
||||
394
engines/hpl1/engine/graphics/Material_BaseLight.cpp
Normal file
394
engines/hpl1/engine/graphics/Material_BaseLight.cpp
Normal file
@@ -0,0 +1,394 @@
|
||||
/* 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/graphics/Material_BaseLight.h"
|
||||
#include "common/algorithm.h"
|
||||
#include "hpl1/engine/graphics/GPUProgram.h"
|
||||
#include "hpl1/engine/graphics/Renderer2D.h"
|
||||
#include "hpl1/engine/graphics/Renderer3D.h"
|
||||
#include "hpl1/engine/math/Math.h"
|
||||
#include "hpl1/engine/resources/GpuProgramManager.h"
|
||||
#include "hpl1/engine/resources/TextureManager.h"
|
||||
#include "hpl1/engine/scene/Camera.h"
|
||||
#include "hpl1/engine/scene/Light.h"
|
||||
#include "hpl1/engine/scene/Light3DSpot.h"
|
||||
#include "hpl1/engine/scene/PortalContainer.h"
|
||||
#include "hpl1/engine/system/String.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// FRAGMENT PRORGAM SETUP
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cAmbProgramSetup::Setup(iGpuProgram *apProgram, cRenderSettings *apRenderSettings) {
|
||||
if (apRenderSettings->mpSector)
|
||||
apProgram->SetColor3f("ambientColor", apRenderSettings->mAmbientColor * apRenderSettings->mpSector->GetAmbientColor());
|
||||
else
|
||||
apProgram->SetColor3f("ambientColor", apRenderSettings->mAmbientColor);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iMaterial_BaseLight::iMaterial_BaseLight(const tString &asLightVertexProgram,
|
||||
const tString &asLightFragmentProgram,
|
||||
const tString &asName, iLowLevelGraphics *apLowLevelGraphics,
|
||||
cImageManager *apImageManager, cTextureManager *apTextureManager,
|
||||
cRenderer2D *apRenderer, cGpuProgramManager *apProgramManager,
|
||||
eMaterialPicture aPicture, cRenderer3D *apRenderer3D)
|
||||
: iMaterial(asName, apLowLevelGraphics, apImageManager, apTextureManager, apRenderer, apProgramManager,
|
||||
aPicture, apRenderer3D) {
|
||||
mbIsTransperant = false;
|
||||
mbIsGlowing = false;
|
||||
mbUsesLights = true;
|
||||
mbUseColorSpecular = false;
|
||||
|
||||
Common::fill(_shaders, _shaders + eBaseLightProgram_LastEnum, nullptr);
|
||||
|
||||
///////////////////////////////////////////
|
||||
// Load the light pass vertex program
|
||||
// Point
|
||||
_shaders[eBaseLightProgram_Point1] = mpProgramManager->CreateProgram(asLightVertexProgram, asLightFragmentProgram);
|
||||
|
||||
////////////////////////////////////////
|
||||
// Get names for other light programs
|
||||
tString sSpotVtxProgram = asLightVertexProgram + "_Spot";
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// Check if there is enough texture units for 1 pass spot
|
||||
if (mpLowLevelGraphics->GetCaps(eGraphicCaps_MaxTextureImageUnits) > 4) {
|
||||
mbUsesTwoPassSpot = false;
|
||||
tString sSpotFragProgram = asLightFragmentProgram + "_Spot";
|
||||
_shaders[eBaseLightProgram_Spot1] = mpProgramManager->CreateProgram(sSpotVtxProgram, sSpotFragProgram);
|
||||
} else {
|
||||
mbUsesTwoPassSpot = true;
|
||||
tString sSpotFragProgram1 = "Diffuse_Light_Spot_pass1"; // cString::Sub(asLightFragmentProgram,0, (int)asLightFragmentProgram.size() - 5) +
|
||||
// "Spot_fp_pass1.cg";
|
||||
tString sSpotFragProgram2 = asLightFragmentProgram + "_Spot_pass2";
|
||||
_shaders[eBaseLightProgram_Spot1] = mpProgramManager->CreateProgram(sSpotVtxProgram, sSpotFragProgram1);
|
||||
_shaders[eBaseLightProgram_Spot2] = mpProgramManager->CreateProgram(sSpotVtxProgram, sSpotFragProgram2);
|
||||
}
|
||||
|
||||
_diffuseShader = mpProgramManager->CreateProgram("hpl1_Diffuse_Color", "hpl1_Diffuse_Color");
|
||||
_ambientShader = mpProgramManager->CreateProgram("hpl1_Diffuse_Color", "hpl1_Ambient_Color");
|
||||
|
||||
///////////////////////////////////////////
|
||||
// Normalization map
|
||||
mpNormalizationMap = mpTextureManager->CreateCubeMap("Normalization", false);
|
||||
mpNormalizationMap->SetWrapS(eTextureWrap_ClampToEdge);
|
||||
mpNormalizationMap->SetWrapT(eTextureWrap_ClampToEdge);
|
||||
|
||||
///////////////////////////////////////////
|
||||
// Negative rejection
|
||||
mpSpotNegativeRejectMap = mpTextureManager->Create1D("core_spot_negative_reject", false);
|
||||
if (mpSpotNegativeRejectMap) {
|
||||
mpSpotNegativeRejectMap->SetWrapS(eTextureWrap_ClampToEdge);
|
||||
mpSpotNegativeRejectMap->SetWrapT(eTextureWrap_ClampToEdge);
|
||||
}
|
||||
|
||||
mbUseSpecular = false;
|
||||
mbUseNormalMap = false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iMaterial_BaseLight::~iMaterial_BaseLight() {
|
||||
if (mpNormalizationMap)
|
||||
mpTextureManager->Destroy(mpNormalizationMap);
|
||||
if (mpSpotNegativeRejectMap)
|
||||
mpTextureManager->Destroy(mpSpotNegativeRejectMap);
|
||||
|
||||
for (int i = 0; i < eBaseLightProgram_LastEnum; ++i) {
|
||||
if (_shaders[i])
|
||||
mpProgramManager->Destroy(_shaders[i]);
|
||||
}
|
||||
|
||||
if (_diffuseShader)
|
||||
mpProgramManager->Destroy(_diffuseShader);
|
||||
if (_ambientShader)
|
||||
mpProgramManager->Destroy(_ambientShader);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iGpuProgram *iMaterial_BaseLight::getGpuProgram(const eMaterialRenderType aType, const int alPass, iLight3D *apLight) {
|
||||
if (aType == eMaterialRenderType_Light) {
|
||||
eBaseLightProgram program;
|
||||
if (apLight->GetLightType() == eLight3DType_Spot && mbUsesTwoPassSpot) {
|
||||
if (alPass == 0)
|
||||
program = eBaseLightProgram_Spot1;
|
||||
else
|
||||
program = eBaseLightProgram_Spot2;
|
||||
} else {
|
||||
if (apLight->GetLightType() == eLight3DType_Point)
|
||||
program = eBaseLightProgram_Point1;
|
||||
else if (apLight->GetLightType() == eLight3DType_Spot)
|
||||
program = eBaseLightProgram_Spot1;
|
||||
else {
|
||||
assert(false);
|
||||
program = static_cast<eBaseLightProgram>(0);
|
||||
}
|
||||
}
|
||||
return _shaders[program];
|
||||
} else if (aType == eMaterialRenderType_Diffuse) {
|
||||
return _diffuseShader;
|
||||
} else if (aType == eMaterialRenderType_Z) {
|
||||
return _ambientShader;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
iMaterialProgramSetup *iMaterial_BaseLight::getGpuProgramSetup(const eMaterialRenderType aType, const int alPass, iLight3D *apLight) {
|
||||
static cAmbProgramSetup ambProgramSetup;
|
||||
if (aType == eMaterialRenderType_Z)
|
||||
return &ambProgramSetup;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
|
||||
bool iMaterial_BaseLight::VertexProgramUsesLight(eMaterialRenderType aType, int alPass, iLight3D *apLight) {
|
||||
if (aType == eMaterialRenderType_Light)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
|
||||
bool iMaterial_BaseLight::VertexProgramUsesEye(eMaterialRenderType aType, int alPass, iLight3D *apLight) {
|
||||
if (aType == eMaterialRenderType_Light && mbUseSpecular)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
|
||||
eMaterialAlphaMode iMaterial_BaseLight::GetAlphaMode(eMaterialRenderType aType, int alPass, iLight3D *apLight) {
|
||||
if (aType == eMaterialRenderType_Z && mbHasAlpha)
|
||||
return eMaterialAlphaMode_Trans;
|
||||
|
||||
return eMaterialAlphaMode_Solid;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
|
||||
eMaterialBlendMode iMaterial_BaseLight::GetBlendMode(eMaterialRenderType aType, int alPass, iLight3D *apLight) {
|
||||
//////////////////////////////
|
||||
// Spot two pass
|
||||
if (aType == eMaterialRenderType_Light && apLight->GetLightType() == eLight3DType_Spot && mbUsesTwoPassSpot) {
|
||||
if (alPass == 0)
|
||||
return eMaterialBlendMode_Replace;
|
||||
else if (alPass == 1)
|
||||
return eMaterialBlendMode_DestAlphaAdd;
|
||||
}
|
||||
|
||||
//////////////////////////////
|
||||
// Other
|
||||
if (aType == eMaterialRenderType_Z)
|
||||
return eMaterialBlendMode_Replace;
|
||||
|
||||
return eMaterialBlendMode_Add;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
|
||||
eMaterialChannelMode iMaterial_BaseLight::GetChannelMode(eMaterialRenderType aType, int alPass, iLight3D *apLight) {
|
||||
////////////////////////////
|
||||
// Spot two pass:
|
||||
if (aType == eMaterialRenderType_Light && apLight->GetLightType() == eLight3DType_Spot && mbUsesTwoPassSpot) {
|
||||
if (alPass == 0)
|
||||
return eMaterialChannelMode_A;
|
||||
}
|
||||
//////////////////////////////
|
||||
// Other
|
||||
else if (aType == eMaterialRenderType_Z) {
|
||||
// return eMaterialChannelMode_Z;
|
||||
return eMaterialChannelMode_RGBA;
|
||||
}
|
||||
|
||||
return eMaterialChannelMode_RGBA;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iTexture *iMaterial_BaseLight::GetTexture(int alUnit, eMaterialRenderType aType, int alPass, iLight3D *apLight) {
|
||||
if (aType == eMaterialRenderType_Z) {
|
||||
// if(alUnit==0 && mbHasAlpha) return mvTexture[eMaterialTexture_Diffuse];
|
||||
if (alUnit == 0)
|
||||
return mvTexture[eMaterialTexture_Diffuse];
|
||||
return NULL;
|
||||
} else if (aType == eMaterialRenderType_Diffuse) {
|
||||
if (alUnit == 0)
|
||||
return mvTexture[eMaterialTexture_Illumination];
|
||||
return NULL;
|
||||
} else if (aType == eMaterialRenderType_Light) {
|
||||
//////////////////////////////////////////////
|
||||
// Two Pass Spot LIght
|
||||
if (mbUsesTwoPassSpot && apLight->GetLightType() == eLight3DType_Spot) {
|
||||
if (alPass == 0) {
|
||||
switch (alUnit) {
|
||||
// Falloff map
|
||||
case 0:
|
||||
return apLight->GetFalloffMap();
|
||||
|
||||
// Negative rejection:
|
||||
case 1:
|
||||
return mpSpotNegativeRejectMap;
|
||||
}
|
||||
} else {
|
||||
switch (alUnit) {
|
||||
// Diffuse texture
|
||||
case 0:
|
||||
return mvTexture[eMaterialTexture_Diffuse];
|
||||
|
||||
// Normalmap
|
||||
case 1:
|
||||
if (mbUseNormalMap)
|
||||
return mvTexture[eMaterialTexture_NMap];
|
||||
break;
|
||||
|
||||
// Normalization map
|
||||
case 2:
|
||||
return mpNormalizationMap;
|
||||
break;
|
||||
|
||||
// Spotlight texture
|
||||
case 3: {
|
||||
cLight3DSpot *pSpotLight = static_cast<cLight3DSpot *>(apLight);
|
||||
return pSpotLight->GetTexture();
|
||||
} break;
|
||||
}
|
||||
}
|
||||
}
|
||||
//////////////////////////////////////////////
|
||||
// All Other Lighting
|
||||
else {
|
||||
switch (alUnit) {
|
||||
// Diffuse texture
|
||||
case 0:
|
||||
return mvTexture[eMaterialTexture_Diffuse];
|
||||
|
||||
// Normalmap
|
||||
case 1:
|
||||
if (mbUseNormalMap)
|
||||
return mvTexture[eMaterialTexture_NMap];
|
||||
break;
|
||||
|
||||
// Normalization map
|
||||
case 2:
|
||||
return mpNormalizationMap;
|
||||
break;
|
||||
|
||||
// Falloff map
|
||||
case 3:
|
||||
return apLight->GetFalloffMap();
|
||||
|
||||
// Spotlight texture
|
||||
case 4:
|
||||
if (apLight->GetLightType() == eLight3DType_Spot) {
|
||||
cLight3DSpot *pSpotLight = static_cast<cLight3DSpot *>(apLight);
|
||||
return pSpotLight->GetTexture();
|
||||
};
|
||||
break;
|
||||
// Negative rejection
|
||||
case 5:
|
||||
if (apLight->GetLightType() == eLight3DType_Spot) {
|
||||
return mpSpotNegativeRejectMap;
|
||||
}
|
||||
break;
|
||||
// Color specular
|
||||
case 6:
|
||||
if (mbUseColorSpecular) {
|
||||
return mvTexture[eMaterialTexture_Specular];
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
eMaterialBlendMode iMaterial_BaseLight::GetTextureBlend(int alUnit, eMaterialRenderType aType, int alPass, iLight3D *apLight) {
|
||||
return eMaterialBlendMode_None;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
int iMaterial_BaseLight::GetNumOfPasses(eMaterialRenderType aType, iLight3D *apLight) {
|
||||
if (aType == eMaterialRenderType_Light && apLight->GetLightType() == eLight3DType_Spot && mbUsesTwoPassSpot) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool iMaterial_BaseLight::UsesType(eMaterialRenderType aType) {
|
||||
if (aType == eMaterialRenderType_Diffuse) {
|
||||
if (mvTexture[eMaterialTexture_Illumination])
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
tTextureTypeList iMaterial_BaseLight::GetTextureTypes() {
|
||||
tTextureTypeList vTypes;
|
||||
vTypes.push_back(cTextureType("", eMaterialTexture_Diffuse));
|
||||
if (mbUseNormalMap)
|
||||
vTypes.push_back(cTextureType("_bump", eMaterialTexture_NMap));
|
||||
|
||||
if (mbUseColorSpecular)
|
||||
vTypes.push_back(cTextureType("_spec", eMaterialTexture_Specular));
|
||||
|
||||
vTypes.push_back(cTextureType("_illum", eMaterialTexture_Illumination));
|
||||
|
||||
return vTypes;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
} // namespace hpl
|
||||
114
engines/hpl1/engine/graphics/Material_BaseLight.h
Normal file
114
engines/hpl1/engine/graphics/Material_BaseLight.h
Normal file
@@ -0,0 +1,114 @@
|
||||
/* 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_BASE_LIGHT_H
|
||||
#define HPL_MATERIAL_BASE_LIGHT_H
|
||||
|
||||
#include "hpl1/engine/graphics/GPUProgram.h"
|
||||
#include "hpl1/engine/graphics/Material.h"
|
||||
#include "hpl1/engine/scene/Light3D.h"
|
||||
|
||||
enum eBaseLightProgram {
|
||||
eBaseLightProgram_Point1 = 0,
|
||||
eBaseLightProgram_Point2 = 1,
|
||||
eBaseLightProgram_Point3 = 2,
|
||||
eBaseLightProgram_Spot1 = 3,
|
||||
eBaseLightProgram_Spot2 = 4,
|
||||
eBaseLightProgram_Spot3 = 5,
|
||||
eBaseLightProgram_LastEnum = 6
|
||||
};
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class cAmbProgramSetup : public iMaterialProgramSetup {
|
||||
public:
|
||||
void Setup(iGpuProgram *apProgram, cRenderSettings *apRenderSettings);
|
||||
};
|
||||
|
||||
class iMaterial_BaseLight : public iMaterial {
|
||||
public:
|
||||
iMaterial_BaseLight(const tString &asLightVertexProgram,
|
||||
const tString &asLightFragmentProgram,
|
||||
|
||||
const tString &asName, iLowLevelGraphics *apLowLevelGraphics,
|
||||
cImageManager *apImageManager, cTextureManager *apTextureManager,
|
||||
cRenderer2D *apRenderer, cGpuProgramManager *apProgramManager,
|
||||
eMaterialPicture aPicture, cRenderer3D *apRenderer3D);
|
||||
|
||||
virtual ~iMaterial_BaseLight();
|
||||
|
||||
tTextureTypeList GetTextureTypes();
|
||||
|
||||
bool UsesType(eMaterialRenderType aType);
|
||||
|
||||
iGpuProgram *getGpuProgram(const eMaterialRenderType aType, const int alPass, iLight3D *apLight);
|
||||
iMaterialProgramSetup *getGpuProgramSetup(const eMaterialRenderType aType, const int alPass, iLight3D *apLight);
|
||||
|
||||
bool VertexProgramUsesLight(eMaterialRenderType aType, int alPass, iLight3D *apLight);
|
||||
bool VertexProgramUsesEye(eMaterialRenderType aType, int alPass, iLight3D *apLight);
|
||||
|
||||
eMaterialAlphaMode GetAlphaMode(eMaterialRenderType aType, int alPass, iLight3D *apLight);
|
||||
eMaterialBlendMode GetBlendMode(eMaterialRenderType aType, int alPass, iLight3D *apLight);
|
||||
eMaterialChannelMode GetChannelMode(eMaterialRenderType aType, int alPass, iLight3D *apLight);
|
||||
|
||||
iTexture *GetTexture(int alUnit, eMaterialRenderType aType, int alPass, iLight3D *apLight);
|
||||
eMaterialBlendMode GetTextureBlend(int alUnit, eMaterialRenderType aType, int alPass, iLight3D *apLight);
|
||||
|
||||
int GetNumOfPasses(eMaterialRenderType aType, iLight3D *apLight);
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// Old and worthless stuff, only used by 2D renderer
|
||||
void Compile() {}
|
||||
bool StartRendering(eMaterialRenderType aType, iCamera *apCam, iLight *pLight) { return false; }
|
||||
void EndRendering(eMaterialRenderType aType) {}
|
||||
tVtxBatchFlag GetBatchFlags(eMaterialRenderType aType) { return 0; }
|
||||
bool NextPass(eMaterialRenderType aType) { return false; }
|
||||
bool HasMultiplePasses(eMaterialRenderType aType) { return false; }
|
||||
eMaterialType GetType(eMaterialRenderType aType) { return eMaterialType_Diffuse; }
|
||||
void EditVertexes(eMaterialRenderType aType, iCamera *apCam, iLight *pLight,
|
||||
tVertexVec *apVtxVec, cVector3f *apTransform, unsigned int alIndexAdd) {}
|
||||
|
||||
protected:
|
||||
iTexture *mpNormalizationMap;
|
||||
iTexture *mpSpotNegativeRejectMap;
|
||||
|
||||
bool mbUsesTwoPassSpot;
|
||||
|
||||
// properties to set
|
||||
bool mbUseSpecular;
|
||||
bool mbUseNormalMap;
|
||||
bool mbUseColorSpecular;
|
||||
|
||||
iGpuProgram *_diffuseShader;
|
||||
iGpuProgram *_ambientShader;
|
||||
|
||||
iGpuProgram *_shaders[eBaseLightProgram_LastEnum];
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_MATERIAL_BASE_LIGHT_H
|
||||
99
engines/hpl1/engine/graphics/Material_Bump.cpp
Normal file
99
engines/hpl1/engine/graphics/Material_Bump.cpp
Normal file
@@ -0,0 +1,99 @@
|
||||
/* 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/graphics/Material_Bump.h"
|
||||
|
||||
#include "hpl1/engine/graphics/Material_Alpha.h"
|
||||
#include "hpl1/engine/graphics/Material_Fallback01_BaseLight.h"
|
||||
#include "hpl1/engine/graphics/Material_Fallback02_BaseLight.h"
|
||||
#include "hpl1/engine/graphics/Material_Flat.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cMaterial_Bump::cMaterial_Bump(const tString &asName, iLowLevelGraphics *apLowLevelGraphics,
|
||||
cImageManager *apImageManager, cTextureManager *apTextureManager,
|
||||
cRenderer2D *apRenderer, cGpuProgramManager *apProgramManager,
|
||||
eMaterialPicture aPicture, cRenderer3D *apRenderer3D)
|
||||
: iMaterial_BaseLight("hpl1_Diffuse_Light",
|
||||
"hpl1_Bump_Light",
|
||||
asName, apLowLevelGraphics, apImageManager, apTextureManager, apRenderer, apProgramManager,
|
||||
aPicture, apRenderer3D) {
|
||||
mbUseSpecular = false;
|
||||
mbUseNormalMap = true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cMaterial_Bump::~cMaterial_Bump() {
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iMaterial *cMaterialType_Bump::Create(const tString &asName, iLowLevelGraphics *apLowLevelGraphics,
|
||||
cImageManager *apImageManager, cTextureManager *apTextureManager,
|
||||
cRenderer2D *apRenderer, cGpuProgramManager *apProgramManager,
|
||||
eMaterialPicture aPicture, cRenderer3D *apRenderer3D) {
|
||||
|
||||
if (!apLowLevelGraphics->GetCaps(eGraphicCaps_GL_GpuPrograms) || iMaterial::GetQuality() == eMaterialQuality_VeryLow) {
|
||||
return hplNew(cMaterial_Flat, (asName, apLowLevelGraphics,
|
||||
apImageManager, apTextureManager, apRenderer,
|
||||
apProgramManager, aPicture, apRenderer3D));
|
||||
}
|
||||
if (iMaterial::GetQuality() >= eMaterialQuality_High) {
|
||||
return hplNew(cMaterial_Bump, (asName, apLowLevelGraphics,
|
||||
apImageManager, apTextureManager, apRenderer,
|
||||
apProgramManager, aPicture, apRenderer3D));
|
||||
} else if (apLowLevelGraphics->GetCaps(eGraphicCaps_MaxTextureImageUnits) >= 3 &&
|
||||
iMaterial::GetQuality() >= eMaterialQuality_Medium) {
|
||||
return hplNew(cMaterial_Fallback01_Bump, (asName, apLowLevelGraphics,
|
||||
apImageManager, apTextureManager, apRenderer,
|
||||
apProgramManager, aPicture, apRenderer3D));
|
||||
} else if (iMaterial::GetQuality() >= eMaterialQuality_Low) {
|
||||
return hplNew(cMaterial_Fallback02_Diffuse, (asName, apLowLevelGraphics,
|
||||
apImageManager, apTextureManager, apRenderer,
|
||||
apProgramManager, aPicture, apRenderer3D));
|
||||
} else {
|
||||
return hplNew(cMaterial_Flat, (asName, apLowLevelGraphics,
|
||||
apImageManager, apTextureManager, apRenderer,
|
||||
apProgramManager, aPicture, apRenderer3D));
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
} // namespace hpl
|
||||
60
engines/hpl1/engine/graphics/Material_Bump.h
Normal file
60
engines/hpl1/engine/graphics/Material_Bump.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_MATERIAL_BUMP_H
|
||||
#define HPL_MATERIAL_BUMP_H
|
||||
|
||||
#include "hpl1/engine/graphics/Material_BaseLight.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class cMaterial_Bump : public iMaterial_BaseLight {
|
||||
public:
|
||||
cMaterial_Bump(const tString &asName, iLowLevelGraphics *apLowLevelGraphics,
|
||||
cImageManager *apImageManager, cTextureManager *apTextureManager,
|
||||
cRenderer2D *apRenderer, cGpuProgramManager *apProgramManager,
|
||||
eMaterialPicture aPicture, cRenderer3D *apRenderer3D);
|
||||
~cMaterial_Bump();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
class cMaterialType_Bump : public iMaterialType {
|
||||
public:
|
||||
bool IsCorrect(tString asName) {
|
||||
return cString::ToLowerCase(asName) == "bump";
|
||||
}
|
||||
|
||||
iMaterial *Create(const tString &asName, iLowLevelGraphics *apLowLevelGraphics,
|
||||
cImageManager *apImageManager, cTextureManager *apTextureManager,
|
||||
cRenderer2D *apRenderer, cGpuProgramManager *apProgramManager,
|
||||
eMaterialPicture aPicture, cRenderer3D *apRenderer3D);
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_MATERIAL_BUMPE_H
|
||||
107
engines/hpl1/engine/graphics/Material_BumpColorSpec.cpp
Normal file
107
engines/hpl1/engine/graphics/Material_BumpColorSpec.cpp
Normal file
@@ -0,0 +1,107 @@
|
||||
/* 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/graphics/Material_BumpColorSpec.h"
|
||||
|
||||
#include "hpl1/engine/graphics/Material_Alpha.h"
|
||||
#include "hpl1/engine/graphics/Material_Bump.h"
|
||||
#include "hpl1/engine/graphics/Material_Fallback01_BaseLight.h"
|
||||
#include "hpl1/engine/graphics/Material_Fallback02_BaseLight.h"
|
||||
#include "hpl1/engine/graphics/Material_Flat.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cMaterial_BumpColorSpec::cMaterial_BumpColorSpec(const tString &asName, iLowLevelGraphics *apLowLevelGraphics,
|
||||
cImageManager *apImageManager, cTextureManager *apTextureManager,
|
||||
cRenderer2D *apRenderer, cGpuProgramManager *apProgramManager,
|
||||
eMaterialPicture aPicture, cRenderer3D *apRenderer3D)
|
||||
: iMaterial_BaseLight("hpl1_DiffuseSpec_Light",
|
||||
"hpl1_BumpColorSpec_Light",
|
||||
asName, apLowLevelGraphics, apImageManager, apTextureManager, apRenderer, apProgramManager,
|
||||
aPicture, apRenderer3D) {
|
||||
mbUseSpecular = true;
|
||||
mbUseNormalMap = true;
|
||||
mbUseColorSpecular = true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cMaterial_BumpColorSpec::~cMaterial_BumpColorSpec() {
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iMaterial *cMaterialType_BumpColorSpec::Create(const tString &asName, iLowLevelGraphics *apLowLevelGraphics,
|
||||
cImageManager *apImageManager, cTextureManager *apTextureManager,
|
||||
cRenderer2D *apRenderer, cGpuProgramManager *apProgramManager,
|
||||
eMaterialPicture aPicture, cRenderer3D *apRenderer3D) {
|
||||
|
||||
if (!apLowLevelGraphics->GetCaps(eGraphicCaps_GL_GpuPrograms) || iMaterial::GetQuality() == eMaterialQuality_VeryLow) {
|
||||
return hplNew(cMaterial_Flat, (asName, apLowLevelGraphics,
|
||||
apImageManager, apTextureManager, apRenderer,
|
||||
apProgramManager, aPicture, apRenderer3D));
|
||||
}
|
||||
if (iMaterial::GetQuality() >= eMaterialQuality_High) {
|
||||
if (apLowLevelGraphics->GetCaps(eGraphicCaps_MaxTextureImageUnits) >= 7) {
|
||||
return hplNew(cMaterial_BumpColorSpec, (asName, apLowLevelGraphics,
|
||||
apImageManager, apTextureManager, apRenderer,
|
||||
apProgramManager, aPicture, apRenderer3D));
|
||||
} else {
|
||||
return hplNew(cMaterial_Bump, (asName, apLowLevelGraphics,
|
||||
apImageManager, apTextureManager, apRenderer,
|
||||
apProgramManager, aPicture, apRenderer3D));
|
||||
}
|
||||
} else if (apLowLevelGraphics->GetCaps(eGraphicCaps_MaxTextureImageUnits) >= 3 &&
|
||||
iMaterial::GetQuality() >= eMaterialQuality_Medium) {
|
||||
return hplNew(cMaterial_Fallback01_Bump, (asName, apLowLevelGraphics,
|
||||
apImageManager, apTextureManager, apRenderer,
|
||||
apProgramManager, aPicture, apRenderer3D));
|
||||
} else if (iMaterial::GetQuality() >= eMaterialQuality_Low) {
|
||||
return hplNew(cMaterial_Fallback02_Diffuse, (asName, apLowLevelGraphics,
|
||||
apImageManager, apTextureManager, apRenderer,
|
||||
apProgramManager, aPicture, apRenderer3D));
|
||||
} else {
|
||||
return hplNew(cMaterial_Flat, (asName, apLowLevelGraphics,
|
||||
apImageManager, apTextureManager, apRenderer,
|
||||
apProgramManager, aPicture, apRenderer3D));
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
} // namespace hpl
|
||||
60
engines/hpl1/engine/graphics/Material_BumpColorSpec.h
Normal file
60
engines/hpl1/engine/graphics/Material_BumpColorSpec.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_MATERIAL_BUMP_COLOR_SPEC_H
|
||||
#define HPL_MATERIAL_BUMP_COLOR_SPEC_H
|
||||
|
||||
#include "hpl1/engine/graphics/Material_BaseLight.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class cMaterial_BumpColorSpec : public iMaterial_BaseLight {
|
||||
public:
|
||||
cMaterial_BumpColorSpec(const tString &asName, iLowLevelGraphics *apLowLevelGraphics,
|
||||
cImageManager *apImageManager, cTextureManager *apTextureManager,
|
||||
cRenderer2D *apRenderer, cGpuProgramManager *apProgramManager,
|
||||
eMaterialPicture aPicture, cRenderer3D *apRenderer3D);
|
||||
~cMaterial_BumpColorSpec();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
class cMaterialType_BumpColorSpec : public iMaterialType {
|
||||
public:
|
||||
bool IsCorrect(tString asName) {
|
||||
return cString::ToLowerCase(asName) == "bumpcolorspecular";
|
||||
}
|
||||
|
||||
iMaterial *Create(const tString &asName, iLowLevelGraphics *apLowLevelGraphics,
|
||||
cImageManager *apImageManager, cTextureManager *apTextureManager,
|
||||
cRenderer2D *apRenderer, cGpuProgramManager *apProgramManager,
|
||||
eMaterialPicture aPicture, cRenderer3D *apRenderer3D);
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_MATERIAL_BUMP_COLOR_SPEC_H
|
||||
99
engines/hpl1/engine/graphics/Material_BumpSpec.cpp
Normal file
99
engines/hpl1/engine/graphics/Material_BumpSpec.cpp
Normal file
@@ -0,0 +1,99 @@
|
||||
/* 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/graphics/Material_BumpSpec.h"
|
||||
|
||||
#include "hpl1/engine/graphics/Material_Alpha.h"
|
||||
#include "hpl1/engine/graphics/Material_Fallback01_BaseLight.h"
|
||||
#include "hpl1/engine/graphics/Material_Fallback02_BaseLight.h"
|
||||
#include "hpl1/engine/graphics/Material_Flat.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cMaterial_BumpSpec::cMaterial_BumpSpec(const tString &asName, iLowLevelGraphics *apLowLevelGraphics,
|
||||
cImageManager *apImageManager, cTextureManager *apTextureManager,
|
||||
cRenderer2D *apRenderer, cGpuProgramManager *apProgramManager,
|
||||
eMaterialPicture aPicture, cRenderer3D *apRenderer3D)
|
||||
: iMaterial_BaseLight("hpl1_DiffuseSpec_Light",
|
||||
"hpl1_BumpSpec_Light",
|
||||
asName, apLowLevelGraphics, apImageManager, apTextureManager, apRenderer, apProgramManager,
|
||||
aPicture, apRenderer3D) {
|
||||
mbUseSpecular = true;
|
||||
mbUseNormalMap = true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cMaterial_BumpSpec::~cMaterial_BumpSpec() {
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iMaterial *cMaterialType_BumpSpec::Create(const tString &asName, iLowLevelGraphics *apLowLevelGraphics,
|
||||
cImageManager *apImageManager, cTextureManager *apTextureManager,
|
||||
cRenderer2D *apRenderer, cGpuProgramManager *apProgramManager,
|
||||
eMaterialPicture aPicture, cRenderer3D *apRenderer3D) {
|
||||
|
||||
if (!apLowLevelGraphics->GetCaps(eGraphicCaps_GL_GpuPrograms) || iMaterial::GetQuality() == eMaterialQuality_VeryLow) {
|
||||
return hplNew(cMaterial_Flat, (asName, apLowLevelGraphics,
|
||||
apImageManager, apTextureManager, apRenderer,
|
||||
apProgramManager, aPicture, apRenderer3D));
|
||||
}
|
||||
if (iMaterial::GetQuality() >= eMaterialQuality_High) {
|
||||
return hplNew(cMaterial_BumpSpec, (asName, apLowLevelGraphics,
|
||||
apImageManager, apTextureManager, apRenderer,
|
||||
apProgramManager, aPicture, apRenderer3D));
|
||||
} else if (apLowLevelGraphics->GetCaps(eGraphicCaps_MaxTextureImageUnits) >= 3 &&
|
||||
iMaterial::GetQuality() >= eMaterialQuality_Medium) {
|
||||
return hplNew(cMaterial_Fallback01_Bump, (asName, apLowLevelGraphics,
|
||||
apImageManager, apTextureManager, apRenderer,
|
||||
apProgramManager, aPicture, apRenderer3D));
|
||||
} else if (iMaterial::GetQuality() >= eMaterialQuality_Low) {
|
||||
return hplNew(cMaterial_Fallback02_Diffuse, (asName, apLowLevelGraphics,
|
||||
apImageManager, apTextureManager, apRenderer,
|
||||
apProgramManager, aPicture, apRenderer3D));
|
||||
} else {
|
||||
return hplNew(cMaterial_Flat, (asName, apLowLevelGraphics,
|
||||
apImageManager, apTextureManager, apRenderer,
|
||||
apProgramManager, aPicture, apRenderer3D));
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
} // namespace hpl
|
||||
60
engines/hpl1/engine/graphics/Material_BumpSpec.h
Normal file
60
engines/hpl1/engine/graphics/Material_BumpSpec.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_MATERIAL_BUMP_SPEC_H
|
||||
#define HPL_MATERIAL_BUMP_SPEC_H
|
||||
|
||||
#include "hpl1/engine/graphics/Material_BaseLight.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class cMaterial_BumpSpec : public iMaterial_BaseLight {
|
||||
public:
|
||||
cMaterial_BumpSpec(const tString &asName, iLowLevelGraphics *apLowLevelGraphics,
|
||||
cImageManager *apImageManager, cTextureManager *apTextureManager,
|
||||
cRenderer2D *apRenderer, cGpuProgramManager *apProgramManager,
|
||||
eMaterialPicture aPicture, cRenderer3D *apRenderer3D);
|
||||
~cMaterial_BumpSpec();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
class cMaterialType_BumpSpec : public iMaterialType {
|
||||
public:
|
||||
bool IsCorrect(tString asName) {
|
||||
return cString::ToLowerCase(asName) == "bumpspecular";
|
||||
}
|
||||
|
||||
iMaterial *Create(const tString &asName, iLowLevelGraphics *apLowLevelGraphics,
|
||||
cImageManager *apImageManager, cTextureManager *apTextureManager,
|
||||
cRenderer2D *apRenderer, cGpuProgramManager *apProgramManager,
|
||||
eMaterialPicture aPicture, cRenderer3D *apRenderer3D);
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_MATERIAL_BUMP_SPEC_H
|
||||
191
engines/hpl1/engine/graphics/Material_BumpSpec2D.cpp
Normal file
191
engines/hpl1/engine/graphics/Material_BumpSpec2D.cpp
Normal file
@@ -0,0 +1,191 @@
|
||||
/* 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/graphics/Material_BumpSpec2D.h"
|
||||
#include "hpl1/engine/graphics/GPUProgram.h"
|
||||
#include "hpl1/engine/graphics/Renderer2D.h"
|
||||
#include "hpl1/engine/resources/GpuProgramManager.h"
|
||||
#include "hpl1/engine/scene/Camera.h"
|
||||
#include "hpl1/engine/scene/Light.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cMaterial_BumpSpec2D::cMaterial_BumpSpec2D(const tString &asName, iLowLevelGraphics *apLowLevelGraphics,
|
||||
cImageManager *apImageManager, cTextureManager *apTextureManager,
|
||||
cRenderer2D *apRenderer, cGpuProgramManager *apProgramManager,
|
||||
eMaterialPicture aPicture, cRenderer3D *apRenderer3D)
|
||||
: iMaterial(asName, apLowLevelGraphics, apImageManager, apTextureManager, apRenderer, apProgramManager,
|
||||
aPicture, apRenderer3D) {
|
||||
mbIsTransperant = false;
|
||||
mbIsGlowing = false;
|
||||
mbUsesLights = true;
|
||||
mbHasSpecular = true;
|
||||
mType = eMaterialType_BumpSpec;
|
||||
|
||||
_shader = mpProgramManager->CreateProgram("hpl1_BumpSpec2D_Light", "hpl1_BumpSpec2D_Light");
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cMaterial_BumpSpec2D::~cMaterial_BumpSpec2D() {
|
||||
if (_shader)
|
||||
mpProgramManager->Destroy(_shader);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cMaterial_BumpSpec2D::Compile() {
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cMaterial_BumpSpec2D::StartRendering(eMaterialRenderType aType, iCamera *apCam, iLight *apLight) {
|
||||
if (aType == eMaterialRenderType_Z) {
|
||||
mpLowLevelGraphics->SetBlendActive(false);
|
||||
mpLowLevelGraphics->SetTexture(0, GetTexture(eMaterialTexture_Diffuse));
|
||||
mpLowLevelGraphics->SetTextureEnv(eTextureParam_AlphaFunc, eTextureFunc_Replace);
|
||||
mpLowLevelGraphics->SetAlphaTestActive(true);
|
||||
mpLowLevelGraphics->SetAlphaTestFunc(eAlphaTestFunc_GreaterOrEqual, 0.6f);
|
||||
} else if (aType == eMaterialRenderType_Light) {
|
||||
cVector3f vLightPos = apLight->GetLightPosition();
|
||||
|
||||
cVector3f vEyePos;
|
||||
if (apCam != nullptr) {
|
||||
vEyePos = apCam->GetEyePosition();
|
||||
}
|
||||
|
||||
mpLowLevelGraphics->SetBlendActive(true);
|
||||
mpLowLevelGraphics->SetBlendFunc(eBlendFunc_One, eBlendFunc_One);
|
||||
|
||||
mpLowLevelGraphics->SetTexture(0, GetTexture(eMaterialTexture_NMap));
|
||||
mpLowLevelGraphics->SetTexture(1, mpRenderer->GetLightMap(0));
|
||||
|
||||
_shader->SetMatrixf("worldViewProj",
|
||||
eGpuProgramMatrix_ViewProjection,
|
||||
eGpuProgramMatrixOp_Identity);
|
||||
|
||||
_shader->SetVec3f("LightPos", vLightPos.x, vLightPos.y, vLightPos.z);
|
||||
|
||||
_shader->SetVec3f("EyePos", vEyePos.x, vEyePos.y, vEyePos.z);
|
||||
|
||||
_shader->SetFloat("LightRadius", apLight->GetFarAttenuation());
|
||||
_shader->SetVec4f("LightColor", apLight->GetDiffuseColor().r,
|
||||
apLight->GetDiffuseColor().g, apLight->GetDiffuseColor().b,
|
||||
apLight->GetDiffuseColor().a);
|
||||
_shader->Bind();
|
||||
} else if (aType == eMaterialRenderType_Diffuse) {
|
||||
mpLowLevelGraphics->SetBlendActive(true);
|
||||
mpLowLevelGraphics->SetBlendFunc(eBlendFunc_DestColor, eBlendFunc_DestAlpha);
|
||||
mpLowLevelGraphics->SetTexture(0, GetTexture(eMaterialTexture_Diffuse));
|
||||
mpLowLevelGraphics->SetTextureEnv(eTextureParam_ColorFunc, eTextureFunc_Add);
|
||||
mpLowLevelGraphics->SetTextureEnv(eTextureParam_ColorOp1, eTextureOp_OneMinusAlpha);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cMaterial_BumpSpec2D::EndRendering(eMaterialRenderType aType) {
|
||||
if (aType == eMaterialRenderType_Z) {
|
||||
mpLowLevelGraphics->SetAlphaTestActive(false);
|
||||
mpLowLevelGraphics->SetTexture(0, NULL);
|
||||
mpLowLevelGraphics->SetTextureEnv(eTextureParam_AlphaFunc, eTextureFunc_Modulate);
|
||||
}
|
||||
if (aType == eMaterialRenderType_Light) {
|
||||
mpLowLevelGraphics->SetTexture(0, NULL);
|
||||
mpLowLevelGraphics->SetTexture(1, NULL);
|
||||
|
||||
_shader->UnBind();
|
||||
} else if (aType == eMaterialRenderType_Diffuse) {
|
||||
mpLowLevelGraphics->SetTexture(0, NULL);
|
||||
mpLowLevelGraphics->SetBlendActive(false);
|
||||
mpLowLevelGraphics->SetTextureEnv(eTextureParam_ColorFunc, eTextureFunc_Modulate);
|
||||
mpLowLevelGraphics->SetTextureEnv(eTextureParam_ColorOp1, eTextureOp_Color);
|
||||
}
|
||||
|
||||
mlPassCount = 0;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
tVtxBatchFlag cMaterial_BumpSpec2D::GetBatchFlags(eMaterialRenderType aType) {
|
||||
if (aType == eMaterialRenderType_Light) {
|
||||
return eVtxBatchFlag_Position | eVtxBatchFlag_Texture0 |
|
||||
eVtxBatchFlag_Normal | eVtxBatchFlag_Color0;
|
||||
}
|
||||
|
||||
return eVtxBatchFlag_Position | eVtxBatchFlag_Texture0 | eVtxBatchFlag_Color0;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cMaterial_BumpSpec2D::NextPass(eMaterialRenderType aType) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cMaterial_BumpSpec2D::HasMultiplePasses(eMaterialRenderType aType) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
eMaterialType cMaterial_BumpSpec2D::GetType(eMaterialRenderType aType) {
|
||||
if (aType == eMaterialRenderType_Z)
|
||||
return eMaterialType_DiffuseAlpha;
|
||||
return mType;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cMaterial_BumpSpec2D::EditVertexes(eMaterialRenderType aType, iCamera *apCam, iLight *pLight,
|
||||
tVertexVec *apVtxVec, cVector3f *apTransform, unsigned int alIndexAdd) {
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
tTextureTypeList cMaterial_BumpSpec2D::GetTextureTypes() {
|
||||
tTextureTypeList lstTypes;
|
||||
lstTypes.push_back(cTextureType("", eMaterialTexture_Diffuse));
|
||||
lstTypes.push_back(cTextureType("_bump", eMaterialTexture_NMap));
|
||||
return lstTypes;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
} // namespace hpl
|
||||
80
engines/hpl1/engine/graphics/Material_BumpSpec2D.h
Normal file
80
engines/hpl1/engine/graphics/Material_BumpSpec2D.h
Normal file
@@ -0,0 +1,80 @@
|
||||
/* 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_BUMP_SPEC2D_H
|
||||
#define HPL_MATERIAL_BUMP_SPEC2D_H
|
||||
|
||||
#include "hpl1/engine/graphics/GPUProgram.h"
|
||||
#include "hpl1/engine/graphics/Material.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class cMaterial_BumpSpec2D : public iMaterial {
|
||||
public:
|
||||
cMaterial_BumpSpec2D(const tString &asName, iLowLevelGraphics *apLowLevelGraphics,
|
||||
cImageManager *apImageManager, cTextureManager *apTextureManager,
|
||||
cRenderer2D *apRenderer, cGpuProgramManager *apProgramManager,
|
||||
eMaterialPicture aPicture, cRenderer3D *apRenderer3D);
|
||||
~cMaterial_BumpSpec2D();
|
||||
|
||||
void Compile();
|
||||
bool StartRendering(eMaterialRenderType aType, iCamera *apCam, iLight *apLight);
|
||||
void EndRendering(eMaterialRenderType aType);
|
||||
tVtxBatchFlag GetBatchFlags(eMaterialRenderType aType);
|
||||
bool NextPass(eMaterialRenderType aType);
|
||||
bool HasMultiplePasses(eMaterialRenderType aType);
|
||||
|
||||
tTextureTypeList GetTextureTypes();
|
||||
|
||||
eMaterialType GetType(eMaterialRenderType aType);
|
||||
void EditVertexes(eMaterialRenderType aType, iCamera *apCam, iLight *pLight,
|
||||
tVertexVec *apVtxVec, cVector3f *apTransform, unsigned int alIndexAdd);
|
||||
|
||||
private:
|
||||
iGpuProgram *_shader;
|
||||
bool mbHasSpecular;
|
||||
};
|
||||
|
||||
class cMaterialType_BumpSpec2D : public iMaterialType {
|
||||
public:
|
||||
bool IsCorrect(tString asName) {
|
||||
return cString::ToLowerCase(asName) == "bumpspec2d";
|
||||
}
|
||||
|
||||
iMaterial *Create(const tString &asName, iLowLevelGraphics *apLowLevelGraphics,
|
||||
cImageManager *apImageManager, cTextureManager *apTextureManager,
|
||||
cRenderer2D *apRenderer, cGpuProgramManager *apProgramManager,
|
||||
eMaterialPicture aPicture, cRenderer3D *apRenderer3D) {
|
||||
return hplNew(cMaterial_BumpSpec2D, (asName, apLowLevelGraphics,
|
||||
apImageManager, apTextureManager, apRenderer,
|
||||
apProgramManager, aPicture, apRenderer3D));
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_MATERIAL_BUMP_SPEC2D_H
|
||||
102
engines/hpl1/engine/graphics/Material_Diffuse.cpp
Normal file
102
engines/hpl1/engine/graphics/Material_Diffuse.cpp
Normal file
@@ -0,0 +1,102 @@
|
||||
/* 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/graphics/Material_Diffuse.h"
|
||||
|
||||
#include "hpl1/engine/graphics/Material_Fallback01_BaseLight.h"
|
||||
#include "hpl1/engine/graphics/Material_Fallback02_BaseLight.h"
|
||||
#include "hpl1/engine/graphics/Material_Flat.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cMaterial_Diffuse::cMaterial_Diffuse(const tString &asName, iLowLevelGraphics *apLowLevelGraphics,
|
||||
cImageManager *apImageManager, cTextureManager *apTextureManager,
|
||||
cRenderer2D *apRenderer, cGpuProgramManager *apProgramManager,
|
||||
eMaterialPicture aPicture, cRenderer3D *apRenderer3D)
|
||||
: iMaterial_BaseLight("hpl1_Diffuse_Light",
|
||||
"hpl1_Diffuse_Light",
|
||||
asName, apLowLevelGraphics, apImageManager, apTextureManager, apRenderer, apProgramManager,
|
||||
aPicture, apRenderer3D) {
|
||||
mbUseSpecular = false;
|
||||
mbUseNormalMap = false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cMaterial_Diffuse::~cMaterial_Diffuse() {
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
cMaterialType_Diffuse::cMaterialType_Diffuse() {
|
||||
mlTechLevel = 0;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iMaterial *cMaterialType_Diffuse::Create(const tString &asName, iLowLevelGraphics *apLowLevelGraphics,
|
||||
cImageManager *apImageManager, cTextureManager *apTextureManager,
|
||||
cRenderer2D *apRenderer, cGpuProgramManager *apProgramManager,
|
||||
eMaterialPicture aPicture, cRenderer3D *apRenderer3D) {
|
||||
|
||||
if (!apLowLevelGraphics->GetCaps(eGraphicCaps_GL_GpuPrograms) || iMaterial::GetQuality() == eMaterialQuality_VeryLow) {
|
||||
return hplNew(cMaterial_Flat, (asName, apLowLevelGraphics,
|
||||
apImageManager, apTextureManager, apRenderer,
|
||||
apProgramManager, aPicture, apRenderer3D));
|
||||
}
|
||||
if (iMaterial::GetQuality() >= eMaterialQuality_High) {
|
||||
return hplNew(cMaterial_Diffuse, (asName, apLowLevelGraphics,
|
||||
apImageManager, apTextureManager, apRenderer,
|
||||
apProgramManager, aPicture, apRenderer3D));
|
||||
} else if (apLowLevelGraphics->GetCaps(eGraphicCaps_MaxTextureImageUnits) >= 3 &&
|
||||
iMaterial::GetQuality() >= eMaterialQuality_Medium) {
|
||||
return hplNew(cMaterial_Fallback01_Diffuse, (asName, apLowLevelGraphics,
|
||||
apImageManager, apTextureManager, apRenderer,
|
||||
apProgramManager, aPicture, apRenderer3D));
|
||||
} else if (iMaterial::GetQuality() >= eMaterialQuality_Low) {
|
||||
return hplNew(cMaterial_Fallback02_Diffuse, (asName, apLowLevelGraphics,
|
||||
apImageManager, apTextureManager, apRenderer,
|
||||
apProgramManager, aPicture, apRenderer3D));
|
||||
} else {
|
||||
return hplNew(cMaterial_Flat, (asName, apLowLevelGraphics,
|
||||
apImageManager, apTextureManager, apRenderer,
|
||||
apProgramManager, aPicture, apRenderer3D));
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
} // namespace hpl
|
||||
65
engines/hpl1/engine/graphics/Material_Diffuse.h
Normal file
65
engines/hpl1/engine/graphics/Material_Diffuse.h
Normal file
@@ -0,0 +1,65 @@
|
||||
/* 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_DIFFUSE_H
|
||||
#define HPL_MATERIAL_DIFFUSE_H
|
||||
|
||||
#include "hpl1/engine/graphics/Material_BaseLight.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class cMaterial_Diffuse : public iMaterial_BaseLight {
|
||||
public:
|
||||
cMaterial_Diffuse(const tString &asName, iLowLevelGraphics *apLowLevelGraphics,
|
||||
cImageManager *apImageManager, cTextureManager *apTextureManager,
|
||||
cRenderer2D *apRenderer, cGpuProgramManager *apProgramManager,
|
||||
eMaterialPicture aPicture, cRenderer3D *apRenderer3D);
|
||||
~cMaterial_Diffuse();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
class cMaterialType_Diffuse : public iMaterialType {
|
||||
public:
|
||||
cMaterialType_Diffuse();
|
||||
|
||||
bool IsCorrect(tString asName) {
|
||||
return cString::ToLowerCase(asName) == "diffuse";
|
||||
}
|
||||
|
||||
iMaterial *Create(const tString &asName, iLowLevelGraphics *apLowLevelGraphics,
|
||||
cImageManager *apImageManager, cTextureManager *apTextureManager,
|
||||
cRenderer2D *apRenderer, cGpuProgramManager *apProgramManager,
|
||||
eMaterialPicture aPicture, cRenderer3D *apRenderer3D);
|
||||
|
||||
private:
|
||||
int mlTechLevel;
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_MATERIAL_DIFFUSE_H
|
||||
135
engines/hpl1/engine/graphics/Material_Diffuse2D.cpp
Normal file
135
engines/hpl1/engine/graphics/Material_Diffuse2D.cpp
Normal file
@@ -0,0 +1,135 @@
|
||||
/* 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/graphics/Material_Diffuse2D.h"
|
||||
#include "hpl1/engine/graphics/Renderer2D.h"
|
||||
#include "hpl1/engine/scene/Camera.h"
|
||||
#include "hpl1/engine/scene/Light.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cMaterial_Diffuse2D::cMaterial_Diffuse2D(const tString &asName, iLowLevelGraphics *apLowLevelGraphics,
|
||||
cImageManager *apImageManager, cTextureManager *apTextureManager,
|
||||
cRenderer2D *apRenderer, cGpuProgramManager *apProgramManager,
|
||||
eMaterialPicture aPicture, cRenderer3D *apRenderer3D)
|
||||
: iMaterial(asName, apLowLevelGraphics, apImageManager, apTextureManager, apRenderer, apProgramManager,
|
||||
aPicture, apRenderer3D) {
|
||||
mbIsTransperant = false;
|
||||
mbIsGlowing = false;
|
||||
|
||||
mType = eMaterialType_Diffuse;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cMaterial_Diffuse2D::~cMaterial_Diffuse2D() {
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cMaterial_Diffuse2D::Compile() {
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cMaterial_Diffuse2D::StartRendering(eMaterialRenderType aType, iCamera *apCam, iLight *pLight) {
|
||||
if (aType == eMaterialRenderType_Z) {
|
||||
mpLowLevelGraphics->SetBlendActive(false);
|
||||
mpLowLevelGraphics->SetTexture(0, GetTexture(eMaterialTexture_Diffuse));
|
||||
mpLowLevelGraphics->SetTextureEnv(eTextureParam_AlphaFunc, eTextureFunc_Replace);
|
||||
mpLowLevelGraphics->SetAlphaTestActive(true);
|
||||
mpLowLevelGraphics->SetAlphaTestFunc(eAlphaTestFunc_GreaterOrEqual, 0.6f);
|
||||
} else if (aType == eMaterialRenderType_Light) {
|
||||
return false;
|
||||
} else if (aType == eMaterialRenderType_Diffuse) {
|
||||
mpLowLevelGraphics->SetBlendActive(true);
|
||||
mpLowLevelGraphics->SetBlendFunc(eBlendFunc_One, eBlendFunc_Zero);
|
||||
|
||||
mpLowLevelGraphics->SetTexture(0, GetTexture(eMaterialTexture_Diffuse));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cMaterial_Diffuse2D::EndRendering(eMaterialRenderType aType) {
|
||||
if (aType == eMaterialRenderType_Z) {
|
||||
mpLowLevelGraphics->SetAlphaTestActive(false);
|
||||
mpLowLevelGraphics->SetTexture(0, NULL);
|
||||
mpLowLevelGraphics->SetTextureEnv(eTextureParam_AlphaFunc, eTextureFunc_Modulate);
|
||||
}
|
||||
if (aType == eMaterialRenderType_Diffuse) {
|
||||
mpLowLevelGraphics->SetBlendActive(false);
|
||||
mpLowLevelGraphics->SetTexture(0, NULL);
|
||||
} else if (aType == eMaterialRenderType_Light) {
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
tVtxBatchFlag cMaterial_Diffuse2D::GetBatchFlags(eMaterialRenderType aType) {
|
||||
return eVtxBatchFlag_Position | eVtxBatchFlag_Texture0 | eVtxBatchFlag_Color0;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cMaterial_Diffuse2D::NextPass(eMaterialRenderType aType) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cMaterial_Diffuse2D::HasMultiplePasses(eMaterialRenderType aType) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
eMaterialType cMaterial_Diffuse2D::GetType(eMaterialRenderType aType) {
|
||||
if (aType == eMaterialRenderType_Z)
|
||||
return eMaterialType_DiffuseAlpha;
|
||||
return mType;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cMaterial_Diffuse2D::EditVertexes(eMaterialRenderType aType, iCamera *apCam, iLight *pLight,
|
||||
tVertexVec *apVtxVec, cVector3f *apTransform, unsigned int alIndexAdd) {
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
} // namespace hpl
|
||||
75
engines/hpl1/engine/graphics/Material_Diffuse2D.h
Normal file
75
engines/hpl1/engine/graphics/Material_Diffuse2D.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_MATERIAL_DIFFUSE2D_H
|
||||
#define HPL_MATERIAL_DIFFUSE2D_H
|
||||
|
||||
#include "hpl1/engine/graphics/Material.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class cMaterial_Diffuse2D : public iMaterial {
|
||||
public:
|
||||
cMaterial_Diffuse2D(const tString &asName, iLowLevelGraphics *apLowLevelGraphics,
|
||||
cImageManager *apImageManager, cTextureManager *apTextureManager,
|
||||
cRenderer2D *apRenderer, cGpuProgramManager *apProgramManager,
|
||||
eMaterialPicture aPicture, cRenderer3D *apRenderer3D);
|
||||
~cMaterial_Diffuse2D();
|
||||
|
||||
void Compile();
|
||||
bool StartRendering(eMaterialRenderType aType, iCamera *apCam, iLight *pLight);
|
||||
void EndRendering(eMaterialRenderType aType);
|
||||
tVtxBatchFlag GetBatchFlags(eMaterialRenderType aType);
|
||||
bool NextPass(eMaterialRenderType aType);
|
||||
bool HasMultiplePasses(eMaterialRenderType aType);
|
||||
|
||||
eMaterialType GetType(eMaterialRenderType aType);
|
||||
void EditVertexes(eMaterialRenderType aType, iCamera *apCam, iLight *pLight,
|
||||
tVertexVec *apVtxVec, cVector3f *apTransform, unsigned int alIndexAdd);
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
class cMaterialType_Diffuse2D : public iMaterialType {
|
||||
public:
|
||||
bool IsCorrect(tString asName) {
|
||||
return cString::ToLowerCase(asName) == "diff2d";
|
||||
}
|
||||
|
||||
iMaterial *Create(const tString &asName, iLowLevelGraphics *apLowLevelGraphics,
|
||||
cImageManager *apImageManager, cTextureManager *apTextureManager,
|
||||
cRenderer2D *apRenderer, cGpuProgramManager *apProgramManager,
|
||||
eMaterialPicture aPicture, cRenderer3D *apRenderer3D) {
|
||||
return hplNew(cMaterial_Diffuse2D, (asName, apLowLevelGraphics,
|
||||
apImageManager, apTextureManager, apRenderer,
|
||||
apProgramManager, aPicture, apRenderer3D));
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_MATERIAL_DIFFUSE2D_H
|
||||
134
engines/hpl1/engine/graphics/Material_DiffuseAdditive2D.cpp
Normal file
134
engines/hpl1/engine/graphics/Material_DiffuseAdditive2D.cpp
Normal file
@@ -0,0 +1,134 @@
|
||||
/* 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/graphics/Material_DiffuseAdditive2D.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cMaterial_DiffuseAdditive2D::cMaterial_DiffuseAdditive2D(const tString &asName, iLowLevelGraphics *apLowLevelGraphics,
|
||||
cImageManager *apImageManager, cTextureManager *apTextureManager,
|
||||
cRenderer2D *apRenderer, cGpuProgramManager *apProgramManager,
|
||||
eMaterialPicture aPicture, cRenderer3D *apRenderer3D)
|
||||
: iMaterial(asName, apLowLevelGraphics, apImageManager, apTextureManager, apRenderer, apProgramManager,
|
||||
aPicture, apRenderer3D) {
|
||||
mbIsTransperant = true;
|
||||
mbIsGlowing = true;
|
||||
mType = eMaterialType_DiffuseAdditive;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cMaterial_DiffuseAdditive2D::~cMaterial_DiffuseAdditive2D() {
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cMaterial_DiffuseAdditive2D::Compile() {
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cMaterial_DiffuseAdditive2D::StartRendering(eMaterialRenderType aType, iCamera *apCam, iLight *pLight) {
|
||||
if (aType == eMaterialRenderType_Diffuse) {
|
||||
mpLowLevelGraphics->SetBlendActive(true);
|
||||
mpLowLevelGraphics->SetBlendFunc(eBlendFunc_SrcAlpha, eBlendFunc_One);
|
||||
|
||||
mpLowLevelGraphics->SetActiveTextureUnit(0);
|
||||
// mpLowLevelGraphics->SetTextureEnv(eTextureParam_ColorOp1,eTextureOp_Alpha);
|
||||
mpLowLevelGraphics->SetTextureEnv(eTextureParam_ColorFunc, eTextureFunc_Modulate);
|
||||
|
||||
mpLowLevelGraphics->SetTexture(0, GetTexture(eMaterialTexture_Diffuse));
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cMaterial_DiffuseAdditive2D::EndRendering(eMaterialRenderType aType) {
|
||||
if (aType == eMaterialRenderType_Diffuse) {
|
||||
mpLowLevelGraphics->SetTexture(0, NULL);
|
||||
mpLowLevelGraphics->SetActiveTextureUnit(0);
|
||||
mpLowLevelGraphics->SetTextureEnv(eTextureParam_ColorOp1, eTextureOp_Color);
|
||||
mpLowLevelGraphics->SetTextureEnv(eTextureParam_ColorFunc, eTextureFunc_Modulate);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
tVtxBatchFlag cMaterial_DiffuseAdditive2D::GetBatchFlags(eMaterialRenderType aType) {
|
||||
return eVtxBatchFlag_Position | eVtxBatchFlag_Texture0 | eVtxBatchFlag_Color0;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cMaterial_DiffuseAdditive2D::NextPass(eMaterialRenderType aType) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cMaterial_DiffuseAdditive2D::HasMultiplePasses(eMaterialRenderType aType) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
eMaterialType cMaterial_DiffuseAdditive2D::GetType(eMaterialRenderType aType) {
|
||||
return mType;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cMaterial_DiffuseAdditive2D::UsesType(eMaterialRenderType aType) {
|
||||
if (aType == eMaterialRenderType_Diffuse)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cMaterial_DiffuseAdditive2D::EditVertexes(eMaterialRenderType aType, iCamera *apCam, iLight *pLight,
|
||||
tVertexVec *apVtxVec, cVector3f *apTransform, unsigned int alIndexAdd) {
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
} // namespace hpl
|
||||
79
engines/hpl1/engine/graphics/Material_DiffuseAdditive2D.h
Normal file
79
engines/hpl1/engine/graphics/Material_DiffuseAdditive2D.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_MATERIAL_DIFFUSE_ADDITIVE2D_H
|
||||
#define HPL_MATERIAL_DIFFUSE_ADDITIVE2D_H
|
||||
|
||||
#include "hpl1/engine/graphics/Material.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class cMaterial_DiffuseAdditive2D : public iMaterial {
|
||||
public:
|
||||
cMaterial_DiffuseAdditive2D(const tString &asName, iLowLevelGraphics *apLowLevelGraphics,
|
||||
cImageManager *apImageManager, cTextureManager *apTextureManager,
|
||||
cRenderer2D *apRenderer, cGpuProgramManager *apProgramManager,
|
||||
eMaterialPicture aPicture, cRenderer3D *apRenderer3D);
|
||||
~cMaterial_DiffuseAdditive2D();
|
||||
|
||||
void Compile();
|
||||
bool StartRendering(eMaterialRenderType mType, iCamera *apCam, iLight *pLight);
|
||||
void EndRendering(eMaterialRenderType mType);
|
||||
tVtxBatchFlag GetBatchFlags(eMaterialRenderType mType);
|
||||
bool NextPass(eMaterialRenderType mType);
|
||||
bool HasMultiplePasses(eMaterialRenderType mType);
|
||||
|
||||
bool UsesType(eMaterialRenderType aType);
|
||||
|
||||
eMaterialType GetType(eMaterialRenderType mType);
|
||||
void EditVertexes(eMaterialRenderType mType, iCamera *apCam, iLight *pLight,
|
||||
tVertexVec *apVtxVec, cVector3f *apTransform, unsigned int alIndexAdd);
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
class cMaterialType_DiffuseAdditive2D : public iMaterialType {
|
||||
public:
|
||||
bool IsCorrect(tString asName) {
|
||||
if (cString::ToLowerCase(asName) == "diffadditive2d")
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
iMaterial *Create(const tString &asName, iLowLevelGraphics *apLowLevelGraphics,
|
||||
cImageManager *apImageManager, cTextureManager *apTextureManager,
|
||||
cRenderer2D *apRenderer, cGpuProgramManager *apProgramManager,
|
||||
eMaterialPicture aPicture, cRenderer3D *apRenderer3D) {
|
||||
return hplNew(cMaterial_DiffuseAdditive2D, (asName, apLowLevelGraphics,
|
||||
apImageManager, apTextureManager, apRenderer,
|
||||
apProgramManager, aPicture, apRenderer3D));
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_MATERIAL_DIFFUSE_ADDITIVE_H
|
||||
121
engines/hpl1/engine/graphics/Material_DiffuseAlpha2D.cpp
Normal file
121
engines/hpl1/engine/graphics/Material_DiffuseAlpha2D.cpp
Normal file
@@ -0,0 +1,121 @@
|
||||
/* 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/graphics/Material_DiffuseAlpha2D.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cMaterial_DiffuseAlpha2D::cMaterial_DiffuseAlpha2D(const tString &asName, iLowLevelGraphics *apLowLevelGraphics,
|
||||
cImageManager *apImageManager, cTextureManager *apTextureManager,
|
||||
cRenderer2D *apRenderer, cGpuProgramManager *apProgramManager,
|
||||
eMaterialPicture aPicture, cRenderer3D *apRenderer3D)
|
||||
: iMaterial(asName, apLowLevelGraphics, apImageManager, apTextureManager, apRenderer, apProgramManager,
|
||||
aPicture, apRenderer3D) {
|
||||
mbIsTransperant = true;
|
||||
mbIsGlowing = true; // Set to false later on
|
||||
mType = eMaterialType_DiffuseAlpha;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cMaterial_DiffuseAlpha2D::~cMaterial_DiffuseAlpha2D() {
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cMaterial_DiffuseAlpha2D::Compile() {
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cMaterial_DiffuseAlpha2D::StartRendering(eMaterialRenderType aType, iCamera *apCam, iLight *pLight) {
|
||||
if (aType == eMaterialRenderType_Diffuse) {
|
||||
mpLowLevelGraphics->SetBlendActive(true);
|
||||
mpLowLevelGraphics->SetBlendFunc(eBlendFunc_SrcAlpha, eBlendFunc_OneMinusSrcAlpha);
|
||||
|
||||
mpLowLevelGraphics->SetTexture(0, GetTexture(eMaterialTexture_Diffuse));
|
||||
// mpLowLevelGraphics->SetTextureParam(eTextureParam_ColorOp1,eTextureOp_Alpha);
|
||||
// mpLowLevelGraphics->SetTextureParam(eTextureParam_ColorFunc, eTextureFunc_Modulate);
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cMaterial_DiffuseAlpha2D::EndRendering(eMaterialRenderType aType) {
|
||||
if (aType == eMaterialRenderType_Diffuse) {
|
||||
// mpLowLevelGraphics->SetTextureParam(eTextureParam_ColorOp1,eTextureOp_Color);
|
||||
// mpLowLevelGraphics->SetTextureParam(eTextureParam_ColorFunc, eTextureFunc_Modulate);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
tVtxBatchFlag cMaterial_DiffuseAlpha2D::GetBatchFlags(eMaterialRenderType aType) {
|
||||
return eVtxBatchFlag_Position | eVtxBatchFlag_Texture0 | eVtxBatchFlag_Color0;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cMaterial_DiffuseAlpha2D::NextPass(eMaterialRenderType aType) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cMaterial_DiffuseAlpha2D::HasMultiplePasses(eMaterialRenderType aType) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
eMaterialType cMaterial_DiffuseAlpha2D::GetType(eMaterialRenderType aType) {
|
||||
return mType;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cMaterial_DiffuseAlpha2D::EditVertexes(eMaterialRenderType aType, iCamera *apCam, iLight *pLight,
|
||||
tVertexVec *apVtxVec, cVector3f *apTransform, unsigned int alIndexAdd) {
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
} // namespace hpl
|
||||
75
engines/hpl1/engine/graphics/Material_DiffuseAlpha2D.h
Normal file
75
engines/hpl1/engine/graphics/Material_DiffuseAlpha2D.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_MATERIAL_DIFFUSE_ALPHA2D_H
|
||||
#define HPL_MATERIAL_DIFFUSE_ALPHA2D_H
|
||||
|
||||
#include "hpl1/engine/graphics/Material.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class cMaterial_DiffuseAlpha2D : public iMaterial {
|
||||
public:
|
||||
cMaterial_DiffuseAlpha2D(const tString &asName, iLowLevelGraphics *apLowLevelGraphics,
|
||||
cImageManager *apImageManager, cTextureManager *apTextureManager,
|
||||
cRenderer2D *apRenderer, cGpuProgramManager *apProgramManager,
|
||||
eMaterialPicture aPicture, cRenderer3D *apRenderer3D);
|
||||
~cMaterial_DiffuseAlpha2D();
|
||||
|
||||
void Compile();
|
||||
bool StartRendering(eMaterialRenderType mType, iCamera *apCam, iLight *pLight);
|
||||
void EndRendering(eMaterialRenderType mType);
|
||||
tVtxBatchFlag GetBatchFlags(eMaterialRenderType mType);
|
||||
bool NextPass(eMaterialRenderType mType);
|
||||
bool HasMultiplePasses(eMaterialRenderType mType);
|
||||
|
||||
eMaterialType GetType(eMaterialRenderType mType);
|
||||
void EditVertexes(eMaterialRenderType mType, iCamera *apCam, iLight *pLight,
|
||||
tVertexVec *apVtxVec, cVector3f *apTransform, unsigned int alIndexAdd);
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
class cMaterialType_DiffuseAlpha2D : public iMaterialType {
|
||||
public:
|
||||
bool IsCorrect(tString asName) {
|
||||
return cString::ToLowerCase(asName) == "diffalpha2d";
|
||||
}
|
||||
|
||||
iMaterial *Create(const tString &asName, iLowLevelGraphics *apLowLevelGraphics,
|
||||
cImageManager *apImageManager, cTextureManager *apTextureManager,
|
||||
cRenderer2D *apRenderer, cGpuProgramManager *apProgramManager,
|
||||
eMaterialPicture aPicture, cRenderer3D *apRenderer3D) {
|
||||
return hplNew(cMaterial_DiffuseAlpha2D, (asName, apLowLevelGraphics,
|
||||
apImageManager, apTextureManager, apRenderer,
|
||||
apProgramManager, aPicture, apRenderer3D));
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_MATERIAL_DIFFUSE_ALPHA2D_H
|
||||
98
engines/hpl1/engine/graphics/Material_DiffuseSpec.cpp
Normal file
98
engines/hpl1/engine/graphics/Material_DiffuseSpec.cpp
Normal file
@@ -0,0 +1,98 @@
|
||||
/* 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/graphics/Material_DiffuseSpec.h"
|
||||
|
||||
#include "hpl1/engine/graphics/Material_Fallback01_BaseLight.h"
|
||||
#include "hpl1/engine/graphics/Material_Fallback02_BaseLight.h"
|
||||
#include "hpl1/engine/graphics/Material_Flat.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cMaterial_DiffuseSpec::cMaterial_DiffuseSpec(const tString &asName, iLowLevelGraphics *apLowLevelGraphics,
|
||||
cImageManager *apImageManager, cTextureManager *apTextureManager,
|
||||
cRenderer2D *apRenderer, cGpuProgramManager *apProgramManager,
|
||||
eMaterialPicture aPicture, cRenderer3D *apRenderer3D)
|
||||
: iMaterial_BaseLight("hpl1_DiffuseSpec_Light",
|
||||
"hpl1_DiffuseSpec_Light",
|
||||
asName, apLowLevelGraphics, apImageManager, apTextureManager, apRenderer, apProgramManager,
|
||||
aPicture, apRenderer3D) {
|
||||
mbUseSpecular = true;
|
||||
mbUseNormalMap = false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cMaterial_DiffuseSpec::~cMaterial_DiffuseSpec() {
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iMaterial *cMaterialType_DiffuseSpec::Create(const tString &asName, iLowLevelGraphics *apLowLevelGraphics,
|
||||
cImageManager *apImageManager, cTextureManager *apTextureManager,
|
||||
cRenderer2D *apRenderer, cGpuProgramManager *apProgramManager,
|
||||
eMaterialPicture aPicture, cRenderer3D *apRenderer3D) {
|
||||
|
||||
if (!apLowLevelGraphics->GetCaps(eGraphicCaps_GL_GpuPrograms) || iMaterial::GetQuality() == eMaterialQuality_VeryLow) {
|
||||
return hplNew(cMaterial_Flat, (asName, apLowLevelGraphics,
|
||||
apImageManager, apTextureManager, apRenderer,
|
||||
apProgramManager, aPicture, apRenderer3D));
|
||||
}
|
||||
if (iMaterial::GetQuality() >= eMaterialQuality_High) {
|
||||
return hplNew(cMaterial_DiffuseSpec, (asName, apLowLevelGraphics,
|
||||
apImageManager, apTextureManager, apRenderer,
|
||||
apProgramManager, aPicture, apRenderer3D));
|
||||
} else if (apLowLevelGraphics->GetCaps(eGraphicCaps_MaxTextureImageUnits) >= 3 &&
|
||||
iMaterial::GetQuality() >= eMaterialQuality_Medium) {
|
||||
return hplNew(cMaterial_Fallback01_Diffuse, (asName, apLowLevelGraphics,
|
||||
apImageManager, apTextureManager, apRenderer,
|
||||
apProgramManager, aPicture, apRenderer3D));
|
||||
} else if (iMaterial::GetQuality() >= eMaterialQuality_Low) {
|
||||
return hplNew(cMaterial_Fallback02_Diffuse, (asName, apLowLevelGraphics,
|
||||
apImageManager, apTextureManager, apRenderer,
|
||||
apProgramManager, aPicture, apRenderer3D));
|
||||
} else {
|
||||
return hplNew(cMaterial_Flat, (asName, apLowLevelGraphics,
|
||||
apImageManager, apTextureManager, apRenderer,
|
||||
apProgramManager, aPicture, apRenderer3D));
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
} // namespace hpl
|
||||
60
engines/hpl1/engine/graphics/Material_DiffuseSpec.h
Normal file
60
engines/hpl1/engine/graphics/Material_DiffuseSpec.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_MATERIAL_DIFFUSE_SPEC_H
|
||||
#define HPL_MATERIAL_DIFFUSE_SPEC_H
|
||||
|
||||
#include "hpl1/engine/graphics/Material_BaseLight.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class cMaterial_DiffuseSpec : public iMaterial_BaseLight {
|
||||
public:
|
||||
cMaterial_DiffuseSpec(const tString &asName, iLowLevelGraphics *apLowLevelGraphics,
|
||||
cImageManager *apImageManager, cTextureManager *apTextureManager,
|
||||
cRenderer2D *apRenderer, cGpuProgramManager *apProgramManager,
|
||||
eMaterialPicture aPicture, cRenderer3D *apRenderer3D);
|
||||
~cMaterial_DiffuseSpec();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
class cMaterialType_DiffuseSpec : public iMaterialType {
|
||||
public:
|
||||
bool IsCorrect(tString asName) {
|
||||
return cString::ToLowerCase(asName) == "diffusespecular";
|
||||
}
|
||||
|
||||
iMaterial *Create(const tString &asName, iLowLevelGraphics *apLowLevelGraphics,
|
||||
cImageManager *apImageManager, cTextureManager *apTextureManager,
|
||||
cRenderer2D *apRenderer, cGpuProgramManager *apProgramManager,
|
||||
eMaterialPicture aPicture, cRenderer3D *apRenderer3D);
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_MATERIAL_DIFFUSE_SPEC_H
|
||||
175
engines/hpl1/engine/graphics/Material_EnvMap_Reflect.cpp
Normal file
175
engines/hpl1/engine/graphics/Material_EnvMap_Reflect.cpp
Normal file
@@ -0,0 +1,175 @@
|
||||
/* 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/graphics/Material_EnvMap_Reflect.h"
|
||||
#include "hpl1/engine/graphics/GPUProgram.h"
|
||||
#include "hpl1/engine/graphics/Renderer2D.h"
|
||||
#include "hpl1/engine/graphics/Renderer3D.h"
|
||||
#include "hpl1/engine/math/Math.h"
|
||||
#include "hpl1/engine/resources/GpuProgramManager.h"
|
||||
#include "hpl1/engine/resources/TextureManager.h"
|
||||
#include "hpl1/engine/scene/Camera.h"
|
||||
#include "hpl1/engine/scene/Camera3D.h"
|
||||
#include "hpl1/engine/scene/Light.h"
|
||||
#include "hpl1/engine/system/low_level_system.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// MATERIAL SETUP
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cEnvMapReflect_SetUp::Setup(iGpuProgram *apProgram, cRenderSettings *apRenderSettings) {
|
||||
apProgram->SetVec3f("eyeWorldPos", apRenderSettings->mpCamera->GetPosition());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cEnvMapReflect_SetUp::SetupMatrix(cMatrixf *apModelMatrix, cRenderSettings *apRenderSettings) {
|
||||
// Put here so it is updated with every matrix, just as well...
|
||||
if (apModelMatrix)
|
||||
apRenderSettings->gpuProgram->SetMatrixf("objectWorldMatrix", *apModelMatrix);
|
||||
else {
|
||||
apRenderSettings->gpuProgram->SetMatrixf("objectWorldMatrix", cMatrixf::Identity);
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cMaterial_EnvMap_Reflect::cMaterial_EnvMap_Reflect(const tString &asName, iLowLevelGraphics *apLowLevelGraphics,
|
||||
cImageManager *apImageManager, cTextureManager *apTextureManager,
|
||||
cRenderer2D *apRenderer, cGpuProgramManager *apProgramManager,
|
||||
eMaterialPicture aPicture, cRenderer3D *apRenderer3D)
|
||||
: iMaterial(asName, apLowLevelGraphics, apImageManager, apTextureManager, apRenderer, apProgramManager,
|
||||
aPicture, apRenderer3D) {
|
||||
mbIsTransperant = false;
|
||||
mbIsGlowing = false;
|
||||
mbUsesLights = false;
|
||||
|
||||
_diffuseProgram = mpProgramManager->CreateProgram("hpl1_Diffuse_Color", "hpl1_Diffuse_Color");
|
||||
_diffuseReflectProgram = mpProgramManager->CreateProgram("hpl1_Diffuse_EnvMap_Reflect", "hpl1_Diffuse_EnvMap_Reflect");
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cMaterial_EnvMap_Reflect::~cMaterial_EnvMap_Reflect() {
|
||||
if (_diffuseProgram)
|
||||
mpProgramManager->Destroy(_diffuseProgram);
|
||||
if (_diffuseReflectProgram)
|
||||
mpProgramManager->Destroy(_diffuseReflectProgram);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iGpuProgram *cMaterial_EnvMap_Reflect::getGpuProgram(const eMaterialRenderType aType, const int alPass, iLight3D *apLight) {
|
||||
if (aType == eMaterialRenderType_Z)
|
||||
return _diffuseProgram;
|
||||
return _diffuseReflectProgram;
|
||||
}
|
||||
|
||||
iMaterialProgramSetup *cMaterial_EnvMap_Reflect::getGpuProgramSetup(const eMaterialRenderType aType, const int alPass, iLight3D *apLight) {
|
||||
static cEnvMapReflect_SetUp envMaterialSetup;
|
||||
if (aType == eMaterialRenderType_Diffuse)
|
||||
return &envMaterialSetup;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool cMaterial_EnvMap_Reflect::VertexProgramUsesLight(eMaterialRenderType aType, int alPass, iLight3D *apLight) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool cMaterial_EnvMap_Reflect::VertexProgramUsesEye(eMaterialRenderType aType, int alPass, iLight3D *apLight) {
|
||||
return false;
|
||||
}
|
||||
|
||||
eMaterialAlphaMode cMaterial_EnvMap_Reflect::GetAlphaMode(eMaterialRenderType aType, int alPass, iLight3D *apLight) {
|
||||
return eMaterialAlphaMode_Solid;
|
||||
}
|
||||
|
||||
eMaterialBlendMode cMaterial_EnvMap_Reflect::GetBlendMode(eMaterialRenderType aType, int alPass, iLight3D *apLight) {
|
||||
if (aType == eMaterialRenderType_Z)
|
||||
return eMaterialBlendMode_None;
|
||||
|
||||
return eMaterialBlendMode_Replace;
|
||||
}
|
||||
|
||||
eMaterialChannelMode cMaterial_EnvMap_Reflect::GetChannelMode(eMaterialRenderType aType, int alPass, iLight3D *apLight) {
|
||||
if (aType == eMaterialRenderType_Z)
|
||||
return eMaterialChannelMode_Z;
|
||||
return eMaterialChannelMode_RGBA;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iTexture *cMaterial_EnvMap_Reflect::GetTexture(int alUnit, eMaterialRenderType aType, int alPass, iLight3D *apLight) {
|
||||
if (aType == eMaterialRenderType_Z)
|
||||
return NULL;
|
||||
|
||||
if (alUnit == 0)
|
||||
return mvTexture[eMaterialTexture_Diffuse];
|
||||
if (alUnit == 1)
|
||||
return mvTexture[eMaterialTexture_CubeMap];
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
eMaterialBlendMode cMaterial_EnvMap_Reflect::GetTextureBlend(int alUnit, eMaterialRenderType aType, int alPass, iLight3D *apLight) {
|
||||
return eMaterialBlendMode_Mul;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cMaterial_EnvMap_Reflect::UsesType(eMaterialRenderType aType) {
|
||||
if (aType == eMaterialRenderType_Diffuse || aType == eMaterialRenderType_Z)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
tTextureTypeList cMaterial_EnvMap_Reflect::GetTextureTypes() {
|
||||
tTextureTypeList vTypes;
|
||||
vTypes.push_back(cTextureType("", eMaterialTexture_Diffuse));
|
||||
vTypes.push_back(cTextureType("cube", eMaterialTexture_CubeMap));
|
||||
|
||||
return vTypes;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
} // namespace hpl
|
||||
108
engines/hpl1/engine/graphics/Material_EnvMap_Reflect.h
Normal file
108
engines/hpl1/engine/graphics/Material_EnvMap_Reflect.h
Normal file
@@ -0,0 +1,108 @@
|
||||
/* 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_ENVMAP_REFLECT_H
|
||||
#define HPL_MATERIAL_ENVMAP_REFLECT_H
|
||||
|
||||
#include "hpl1/engine/graphics/Material.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//----------------------------------------------------
|
||||
|
||||
class cEnvMapReflect_SetUp : public iMaterialProgramSetup {
|
||||
public:
|
||||
void Setup(iGpuProgram *apProgram, cRenderSettings *apRenderSettings);
|
||||
void SetupMatrix(cMatrixf *apModelMatrix, cRenderSettings *apRenderSettings);
|
||||
};
|
||||
|
||||
//----------------------------------------------------
|
||||
|
||||
class cMaterial_EnvMap_Reflect : public iMaterial {
|
||||
public:
|
||||
cMaterial_EnvMap_Reflect(const tString &asName, iLowLevelGraphics *apLowLevelGraphics,
|
||||
cImageManager *apImageManager, cTextureManager *apTextureManager,
|
||||
cRenderer2D *apRenderer, cGpuProgramManager *apProgramManager,
|
||||
eMaterialPicture aPicture, cRenderer3D *apRenderer3D);
|
||||
|
||||
virtual ~cMaterial_EnvMap_Reflect();
|
||||
|
||||
tTextureTypeList GetTextureTypes();
|
||||
|
||||
bool UsesType(eMaterialRenderType aType);
|
||||
|
||||
iGpuProgram *getGpuProgram(const eMaterialRenderType aType, const int alPass, iLight3D *apLight);
|
||||
iMaterialProgramSetup *getGpuProgramSetup(const eMaterialRenderType aType, const int alPass, iLight3D *apLight);
|
||||
|
||||
bool VertexProgramUsesLight(eMaterialRenderType aType, int alPass, iLight3D *apLight);
|
||||
bool VertexProgramUsesEye(eMaterialRenderType aType, int alPass, iLight3D *apLight);
|
||||
|
||||
eMaterialAlphaMode GetAlphaMode(eMaterialRenderType aType, int alPass, iLight3D *apLight);
|
||||
eMaterialBlendMode GetBlendMode(eMaterialRenderType aType, int alPass, iLight3D *apLight);
|
||||
eMaterialChannelMode GetChannelMode(eMaterialRenderType aType, int alPass, iLight3D *apLight);
|
||||
|
||||
iTexture *GetTexture(int alUnit, eMaterialRenderType aType, int alPass, iLight3D *apLight);
|
||||
eMaterialBlendMode GetTextureBlend(int alUnit, eMaterialRenderType aType, int alPass, iLight3D *apLight);
|
||||
|
||||
int GetNumOfPasses(eMaterialRenderType aType, iLight3D *apLight) { return 1; }
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// Old and worthless stuff, only used by 2D renderer
|
||||
void Compile() {}
|
||||
bool StartRendering(eMaterialRenderType aType, iCamera *apCam, iLight *pLight) { return false; }
|
||||
void EndRendering(eMaterialRenderType aType) {}
|
||||
tVtxBatchFlag GetBatchFlags(eMaterialRenderType aType) { return 0; }
|
||||
bool NextPass(eMaterialRenderType aType) { return false; }
|
||||
bool HasMultiplePasses(eMaterialRenderType aType) { return false; }
|
||||
eMaterialType GetType(eMaterialRenderType aType) { return eMaterialType_Diffuse; }
|
||||
void EditVertexes(eMaterialRenderType aType, iCamera *apCam, iLight *pLight,
|
||||
tVertexVec *apVtxVec, cVector3f *apTransform, unsigned int alIndexAdd) {}
|
||||
|
||||
private:
|
||||
iGpuProgram *_diffuseProgram;
|
||||
iGpuProgram *_diffuseReflectProgram;
|
||||
};
|
||||
|
||||
class cMaterialType_EnvMap_Reflect : public iMaterialType {
|
||||
public:
|
||||
bool IsCorrect(tString asName) {
|
||||
return cString::ToLowerCase(asName) == "environmentmapreflect";
|
||||
}
|
||||
|
||||
iMaterial *Create(const tString &asName, iLowLevelGraphics *apLowLevelGraphics,
|
||||
cImageManager *apImageManager, cTextureManager *apTextureManager,
|
||||
cRenderer2D *apRenderer, cGpuProgramManager *apProgramManager,
|
||||
eMaterialPicture aPicture, cRenderer3D *apRenderer3D) {
|
||||
return hplNew(cMaterial_EnvMap_Reflect, (asName, apLowLevelGraphics,
|
||||
apImageManager, apTextureManager, apRenderer,
|
||||
apProgramManager, aPicture, apRenderer3D));
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_MATERIAL_ENVMAP_REFLECT_H
|
||||
305
engines/hpl1/engine/graphics/Material_Fallback01_BaseLight.cpp
Normal file
305
engines/hpl1/engine/graphics/Material_Fallback01_BaseLight.cpp
Normal file
@@ -0,0 +1,305 @@
|
||||
/* 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/graphics/Material_Fallback01_BaseLight.h"
|
||||
#include "common/algorithm.h"
|
||||
#include "hpl1/engine/graphics/GPUProgram.h"
|
||||
#include "hpl1/engine/graphics/Renderer2D.h"
|
||||
#include "hpl1/engine/graphics/Renderer3D.h"
|
||||
#include "hpl1/engine/math/Math.h"
|
||||
#include "hpl1/engine/resources/GpuProgramManager.h"
|
||||
#include "hpl1/engine/resources/TextureManager.h"
|
||||
#include "hpl1/engine/scene/Camera.h"
|
||||
#include "hpl1/engine/scene/Light.h"
|
||||
#include "hpl1/engine/scene/Light3DSpot.h"
|
||||
#include "hpl1/engine/scene/PortalContainer.h"
|
||||
#include "hpl1/engine/system/String.h"
|
||||
|
||||
//#include <GL/GLee.h>
|
||||
|
||||
namespace hpl {
|
||||
|
||||
iMaterial_Fallback01_BaseLight::iMaterial_Fallback01_BaseLight(
|
||||
bool abNormalMap, bool abSpecular,
|
||||
const tString &asName, iLowLevelGraphics *apLowLevelGraphics,
|
||||
cImageManager *apImageManager, cTextureManager *apTextureManager,
|
||||
cRenderer2D *apRenderer, cGpuProgramManager *apProgramManager,
|
||||
eMaterialPicture aPicture, cRenderer3D *apRenderer3D)
|
||||
: iMaterial(asName, apLowLevelGraphics, apImageManager, apTextureManager, apRenderer, apProgramManager,
|
||||
aPicture, apRenderer3D) {
|
||||
|
||||
Common::fill(_programs, _programs + eBaseLightProgram_LastEnum, nullptr);
|
||||
|
||||
mbUseNormalMap = abNormalMap;
|
||||
mbUseSpecular = abSpecular;
|
||||
|
||||
mbIsTransperant = false;
|
||||
mbIsGlowing = false;
|
||||
mbUsesLights = true;
|
||||
|
||||
const char *firstPassFragment = "";
|
||||
if (abNormalMap)
|
||||
firstPassFragment = "hpl1_Fallback01_Bump_Light";
|
||||
else
|
||||
firstPassFragment = "hpl1_Fallback01_Diffuse_Light_p1";
|
||||
|
||||
_programs[eBaseLightProgram_Point1] = mpProgramManager->CreateProgram("hpl1_Fallback01_Diffuse_Light_p1", firstPassFragment);
|
||||
_programs[eBaseLightProgram_Point2] = mpProgramManager->CreateProgram("hpl1_Fallback01_Diffuse_Light_p2", "hpl1_Fallback01_Diffuse_Light_p2");
|
||||
_programs[eBaseLightProgram_Spot1] = mpProgramManager->CreateProgram("hpl1_Fallback01_Diffuse_Light_p1", firstPassFragment);
|
||||
_programs[eBaseLightProgram_Spot2] = mpProgramManager->CreateProgram("hpl1_Fallback01_Diffuse_Light_Spot_p2", "hpl1_Fallback01_Diffuse_Light_Spot");
|
||||
|
||||
_diffuseShader = mpProgramManager->CreateProgram("hpl1_Diffuse_Color", "hpl1_Diffuse_Color");
|
||||
_ambientShader = mpProgramManager->CreateProgram("hpl1_Diffuse_Color", "hpl1_Ambient_Color");
|
||||
|
||||
mpNormalizationMap = mpTextureManager->CreateCubeMap("Normalization", false);
|
||||
mpNormalizationMap->SetWrapS(eTextureWrap_ClampToEdge);
|
||||
mpNormalizationMap->SetWrapT(eTextureWrap_ClampToEdge);
|
||||
|
||||
mpSpotNegativeRejectMap = mpTextureManager->Create1D("core_spot_negative_reject", false);
|
||||
if (mpSpotNegativeRejectMap) {
|
||||
mpSpotNegativeRejectMap->SetWrapS(eTextureWrap_ClampToEdge);
|
||||
mpSpotNegativeRejectMap->SetWrapT(eTextureWrap_ClampToEdge);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iMaterial_Fallback01_BaseLight::~iMaterial_Fallback01_BaseLight() {
|
||||
if (mpNormalizationMap)
|
||||
mpTextureManager->Destroy(mpNormalizationMap);
|
||||
if (mpSpotNegativeRejectMap)
|
||||
mpTextureManager->Destroy(mpSpotNegativeRejectMap);
|
||||
|
||||
for (int i = 0; i < eBaseLightProgram_LastEnum; i++) {
|
||||
if (_programs[i])
|
||||
mpProgramManager->Destroy(_programs[i]);
|
||||
}
|
||||
if (_diffuseShader)
|
||||
mpProgramManager->Destroy(_diffuseShader);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iGpuProgram *iMaterial_Fallback01_BaseLight::getGpuProgram(const eMaterialRenderType aType, const int alPass, iLight3D *apLight) {
|
||||
eBaseLightProgram program = eBaseLightProgram_Point1;
|
||||
if (apLight) {
|
||||
if (apLight->GetLightType() == eLight3DType_Point)
|
||||
program = eBaseLightProgram_Point1;
|
||||
else if (apLight->GetLightType() == eLight3DType_Spot)
|
||||
program = eBaseLightProgram_Spot1;
|
||||
}
|
||||
|
||||
if (aType == eMaterialRenderType_Light) {
|
||||
return _programs[program + alPass];
|
||||
}
|
||||
if (aType == eMaterialRenderType_Z)
|
||||
return _ambientShader;
|
||||
if (aType == eMaterialRenderType_Diffuse)
|
||||
return _diffuseShader;
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
iMaterialProgramSetup *iMaterial_Fallback01_BaseLight::getGpuProgramSetup(const eMaterialRenderType aType, const int alPass, iLight3D *apLight) {
|
||||
static cAmbProgramSetup ambProgramSetup;
|
||||
if (aType == eMaterialRenderType_Z)
|
||||
return &ambProgramSetup;
|
||||
return nullptr;
|
||||
}
|
||||
//------------------------------------------------------------------------------------
|
||||
|
||||
bool iMaterial_Fallback01_BaseLight::VertexProgramUsesLight(eMaterialRenderType aType, int alPass, iLight3D *apLight) {
|
||||
if (aType == eMaterialRenderType_Light) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
|
||||
bool iMaterial_Fallback01_BaseLight::VertexProgramUsesEye(eMaterialRenderType aType, int alPass, iLight3D *apLight) {
|
||||
if (aType == eMaterialRenderType_Light && mbUseSpecular)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
|
||||
eMaterialAlphaMode iMaterial_Fallback01_BaseLight::GetAlphaMode(eMaterialRenderType aType, int alPass, iLight3D *apLight) {
|
||||
if (aType == eMaterialRenderType_Z && mbHasAlpha)
|
||||
return eMaterialAlphaMode_Trans;
|
||||
|
||||
return eMaterialAlphaMode_Solid;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
|
||||
eMaterialBlendMode iMaterial_Fallback01_BaseLight::GetBlendMode(eMaterialRenderType aType, int alPass, iLight3D *apLight) {
|
||||
//////////////////////////////
|
||||
// Light
|
||||
if (aType == eMaterialRenderType_Light) {
|
||||
if (alPass == 0)
|
||||
return eMaterialBlendMode_Replace;
|
||||
else if (alPass == 1)
|
||||
return eMaterialBlendMode_DestAlphaAdd;
|
||||
}
|
||||
//////////////////////////////
|
||||
// Z
|
||||
else if (aType == eMaterialRenderType_Z)
|
||||
return eMaterialBlendMode_Replace;
|
||||
|
||||
//////////////////////////////
|
||||
// Other
|
||||
return eMaterialBlendMode_Add;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
|
||||
eMaterialChannelMode iMaterial_Fallback01_BaseLight::GetChannelMode(eMaterialRenderType aType, int alPass, iLight3D *apLight) {
|
||||
////////////////////////////
|
||||
// Spot two pass:
|
||||
if (aType == eMaterialRenderType_Light) {
|
||||
if (alPass == 0)
|
||||
return eMaterialChannelMode_A;
|
||||
}
|
||||
//////////////////////////////
|
||||
// Other
|
||||
else if (aType == eMaterialRenderType_Z) {
|
||||
// return eMaterialChannelMode_Z;
|
||||
return eMaterialChannelMode_RGBA;
|
||||
}
|
||||
|
||||
return eMaterialChannelMode_RGBA;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iTexture *iMaterial_Fallback01_BaseLight::GetTexture(int alUnit, eMaterialRenderType aType, int alPass, iLight3D *apLight) {
|
||||
////////////////////////////////////////
|
||||
// Z
|
||||
if (aType == eMaterialRenderType_Z) {
|
||||
// if(alUnit==0 && mbHasAlpha) return mvTexture[eMaterialTexture_Diffuse];
|
||||
if (alUnit == 0)
|
||||
return mvTexture[eMaterialTexture_Diffuse];
|
||||
return NULL;
|
||||
}
|
||||
////////////////////////////////////////
|
||||
// Diffuse
|
||||
else if (aType == eMaterialRenderType_Diffuse) {
|
||||
if (alUnit == 0)
|
||||
return mvTexture[eMaterialTexture_Illumination];
|
||||
return NULL;
|
||||
}
|
||||
////////////////////////////////////////
|
||||
// Light
|
||||
else if (aType == eMaterialRenderType_Light) {
|
||||
if (alPass == 0) {
|
||||
switch (alUnit) {
|
||||
case 0:
|
||||
return mpNormalizationMap;
|
||||
case 1:
|
||||
if (mbUseNormalMap)
|
||||
return mvTexture[eMaterialTexture_NMap];
|
||||
break;
|
||||
case 2: {
|
||||
if (apLight->GetTempTexture(0) == NULL) {
|
||||
iTexture *pTex = apLight->GetFalloffMap();
|
||||
apLight->SetTempTexture(0, mpTextureManager->CreateAttenuation(pTex->GetName()));
|
||||
}
|
||||
return apLight->GetTempTexture(0);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
switch (alUnit) {
|
||||
case 0:
|
||||
return mvTexture[eMaterialTexture_Diffuse];
|
||||
case 1:
|
||||
if (apLight->GetLightType() == eLight3DType_Spot) {
|
||||
cLight3DSpot *pSpotLight = static_cast<cLight3DSpot *>(apLight);
|
||||
return pSpotLight->GetTexture();
|
||||
};
|
||||
break;
|
||||
case 2:
|
||||
if (apLight->GetLightType() == eLight3DType_Spot) {
|
||||
return mpSpotNegativeRejectMap;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
eMaterialBlendMode iMaterial_Fallback01_BaseLight::GetTextureBlend(int alUnit, eMaterialRenderType aType, int alPass, iLight3D *apLight) {
|
||||
return eMaterialBlendMode_None;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
int iMaterial_Fallback01_BaseLight::GetNumOfPasses(eMaterialRenderType aType, iLight3D *apLight) {
|
||||
if (aType == eMaterialRenderType_Light)
|
||||
return 2;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool iMaterial_Fallback01_BaseLight::UsesType(eMaterialRenderType aType) {
|
||||
if (aType == eMaterialRenderType_Diffuse) {
|
||||
if (mvTexture[eMaterialTexture_Illumination])
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
tTextureTypeList iMaterial_Fallback01_BaseLight::GetTextureTypes() {
|
||||
tTextureTypeList vTypes;
|
||||
vTypes.push_back(cTextureType("", eMaterialTexture_Diffuse));
|
||||
if (mbUseNormalMap) {
|
||||
vTypes.push_back(cTextureType("_bump", eMaterialTexture_NMap));
|
||||
}
|
||||
|
||||
vTypes.push_back(cTextureType("_illum", eMaterialTexture_Illumination));
|
||||
|
||||
return vTypes;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
} // namespace hpl
|
||||
135
engines/hpl1/engine/graphics/Material_Fallback01_BaseLight.h
Normal file
135
engines/hpl1/engine/graphics/Material_Fallback01_BaseLight.h
Normal file
@@ -0,0 +1,135 @@
|
||||
/* 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_FALLBACK01_BASE_LIGHT_H
|
||||
#define HPL_MATERIAL_FALLBACK01_BASE_LIGHT_H
|
||||
|
||||
#include "hpl1/engine/graphics/GPUProgram.h"
|
||||
#include "hpl1/engine/graphics/Material.h"
|
||||
#include "hpl1/engine/scene/Light3D.h"
|
||||
|
||||
#include "hpl1/engine/graphics/Material_BaseLight.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//---------------------------------------------------------------
|
||||
|
||||
class iMaterial_Fallback01_BaseLight : public iMaterial {
|
||||
public:
|
||||
iMaterial_Fallback01_BaseLight(bool abNormalMap, bool abSpecular,
|
||||
const tString &asName, iLowLevelGraphics *apLowLevelGraphics,
|
||||
cImageManager *apImageManager, cTextureManager *apTextureManager,
|
||||
cRenderer2D *apRenderer, cGpuProgramManager *apProgramManager,
|
||||
eMaterialPicture aPicture, cRenderer3D *apRenderer3D);
|
||||
|
||||
virtual ~iMaterial_Fallback01_BaseLight();
|
||||
|
||||
tTextureTypeList GetTextureTypes();
|
||||
|
||||
bool UsesType(eMaterialRenderType aType);
|
||||
|
||||
iGpuProgram *getGpuProgram(const eMaterialRenderType aType, const int alPass, iLight3D *apLight);
|
||||
iMaterialProgramSetup *getGpuProgramSetup(const eMaterialRenderType aType, const int alPass, iLight3D *apLight);
|
||||
|
||||
bool VertexProgramUsesLight(eMaterialRenderType aType, int alPass, iLight3D *apLight);
|
||||
bool VertexProgramUsesEye(eMaterialRenderType aType, int alPass, iLight3D *apLight);
|
||||
|
||||
eMaterialAlphaMode GetAlphaMode(eMaterialRenderType aType, int alPass, iLight3D *apLight);
|
||||
eMaterialBlendMode GetBlendMode(eMaterialRenderType aType, int alPass, iLight3D *apLight);
|
||||
eMaterialChannelMode GetChannelMode(eMaterialRenderType aType, int alPass, iLight3D *apLight);
|
||||
|
||||
iTexture *GetTexture(int alUnit, eMaterialRenderType aType, int alPass, iLight3D *apLight);
|
||||
eMaterialBlendMode GetTextureBlend(int alUnit, eMaterialRenderType aType, int alPass, iLight3D *apLight);
|
||||
|
||||
int GetNumOfPasses(eMaterialRenderType aType, iLight3D *apLight);
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// Old and worthless stuff, only used by 2D renderer
|
||||
void Compile() {}
|
||||
bool StartRendering(eMaterialRenderType aType, iCamera *apCam, iLight *pLight) { return false; }
|
||||
void EndRendering(eMaterialRenderType aType) {}
|
||||
tVtxBatchFlag GetBatchFlags(eMaterialRenderType aType) { return 0; }
|
||||
bool NextPass(eMaterialRenderType aType) { return false; }
|
||||
bool HasMultiplePasses(eMaterialRenderType aType) { return false; }
|
||||
eMaterialType GetType(eMaterialRenderType aType) { return eMaterialType_Diffuse; }
|
||||
void EditVertexes(eMaterialRenderType aType, iCamera *apCam, iLight *pLight,
|
||||
tVertexVec *apVtxVec, cVector3f *apTransform, unsigned int alIndexAdd) {}
|
||||
|
||||
protected:
|
||||
iTexture *mpNormalizationMap;
|
||||
iTexture *mpSpotNegativeRejectMap;
|
||||
|
||||
// properties to set
|
||||
bool mbUseSpecular;
|
||||
bool mbUseNormalMap;
|
||||
|
||||
bool mbUsesTwoPassSpot;
|
||||
|
||||
iTexture *mpAttenuationMap;
|
||||
|
||||
iGpuProgram *_programs[eBaseLightProgram_LastEnum];
|
||||
iGpuProgram *_diffuseShader;
|
||||
iGpuProgram *_ambientShader;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////
|
||||
// Diffuse
|
||||
///////////////////////////////////////////
|
||||
|
||||
class cMaterial_Fallback01_Diffuse : public iMaterial_Fallback01_BaseLight {
|
||||
public:
|
||||
cMaterial_Fallback01_Diffuse(const tString &asName, iLowLevelGraphics *apLowLevelGraphics,
|
||||
cImageManager *apImageManager, cTextureManager *apTextureManager,
|
||||
cRenderer2D *apRenderer, cGpuProgramManager *apProgramManager,
|
||||
eMaterialPicture aPicture, cRenderer3D *apRenderer3D)
|
||||
: iMaterial_Fallback01_BaseLight(false, false,
|
||||
asName, apLowLevelGraphics, apImageManager, apTextureManager, apRenderer, apProgramManager,
|
||||
aPicture, apRenderer3D) {
|
||||
}
|
||||
};
|
||||
|
||||
///////////////////////////////////////////
|
||||
// Bump
|
||||
///////////////////////////////////////////
|
||||
|
||||
class cMaterial_Fallback01_Bump : public iMaterial_Fallback01_BaseLight {
|
||||
public:
|
||||
cMaterial_Fallback01_Bump(const tString &asName, iLowLevelGraphics *apLowLevelGraphics,
|
||||
cImageManager *apImageManager, cTextureManager *apTextureManager,
|
||||
cRenderer2D *apRenderer, cGpuProgramManager *apProgramManager,
|
||||
eMaterialPicture aPicture, cRenderer3D *apRenderer3D)
|
||||
: iMaterial_Fallback01_BaseLight(true, false,
|
||||
asName, apLowLevelGraphics, apImageManager, apTextureManager, apRenderer, apProgramManager,
|
||||
aPicture, apRenderer3D) {
|
||||
}
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_MATERIAL_FALLBACK01_BASE_LIGHT_H
|
||||
310
engines/hpl1/engine/graphics/Material_Fallback02_BaseLight.cpp
Normal file
310
engines/hpl1/engine/graphics/Material_Fallback02_BaseLight.cpp
Normal file
@@ -0,0 +1,310 @@
|
||||
/* 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/graphics/Material_Fallback02_BaseLight.h"
|
||||
#include "common/algorithm.h"
|
||||
#include "hpl1/engine/graphics/GPUProgram.h"
|
||||
#include "hpl1/engine/graphics/Material_BaseLight.h"
|
||||
#include "hpl1/engine/graphics/Renderer2D.h"
|
||||
#include "hpl1/engine/math/Math.h"
|
||||
#include "hpl1/engine/resources/GpuProgramManager.h"
|
||||
#include "hpl1/engine/resources/TextureManager.h"
|
||||
#include "hpl1/engine/scene/Camera.h"
|
||||
#include "hpl1/engine/scene/Light.h"
|
||||
#include "hpl1/engine/scene/Light3DSpot.h"
|
||||
#include "hpl1/engine/system/String.h"
|
||||
#include "hpl1/engine/system/low_level_system.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
iMaterial_Fallback02_BaseLight::iMaterial_Fallback02_BaseLight(
|
||||
const tString &asName, iLowLevelGraphics *apLowLevelGraphics,
|
||||
cImageManager *apImageManager, cTextureManager *apTextureManager,
|
||||
cRenderer2D *apRenderer, cGpuProgramManager *apProgramManager,
|
||||
eMaterialPicture aPicture, cRenderer3D *apRenderer3D)
|
||||
: iMaterial(asName, apLowLevelGraphics, apImageManager, apTextureManager, apRenderer, apProgramManager,
|
||||
aPicture, apRenderer3D) {
|
||||
|
||||
mbIsTransperant = false;
|
||||
mbIsGlowing = false;
|
||||
mbUsesLights = true;
|
||||
|
||||
Common::fill(_gpuPrograms, _gpuPrograms + eBaseLightProgram_LastEnum, nullptr);
|
||||
|
||||
_gpuPrograms[eBaseLightProgram_Point1] = mpProgramManager->CreateProgram("hpl1_Fallback02_Diffuse_Light_p1", "hpl1_Fallback02_Diffuse_Light_p1");
|
||||
// the second pass is the same as the second pass of fallback01
|
||||
_gpuPrograms[eBaseLightProgram_Point2] = mpProgramManager->CreateProgram("hpl1_Fallback02_Diffuse_Light_p2", "hpl1_Fallback01_Diffuse_Light_p2");
|
||||
_gpuPrograms[eBaseLightProgram_Spot1] = mpProgramManager->CreateProgram("hpl1_Fallback02_Diffuse_Light_p1", "hpl1_Fallback02_Diffuse_Light_p1");
|
||||
_gpuPrograms[eBaseLightProgram_Spot2] = mpProgramManager->CreateProgram("hpl1_Fallback02_Diffuse_Light_Spot_p2", "hpl1_Fallback02_Diffuse_Light_Spot_p2");
|
||||
_gpuPrograms[eBaseLightProgram_Spot3] = mpProgramManager->CreateProgram("hpl1_Fallback02_Diffuse_Light_Spot_p3", "hpl1_Fallback02_Diffuse_Light_Spot_p3");
|
||||
|
||||
_diffuseGpuProgram = mpProgramManager->CreateProgram("hpl1_Diffuse_Color", "hpl1_Diffuse_Color");
|
||||
_ambientGpuProgram = mpProgramManager->CreateProgram("hpl1_Diffuse_Color", "hpl1_Ambient_Color");
|
||||
|
||||
mpNormalizationMap = mpTextureManager->CreateCubeMap("Normalization", false);
|
||||
mpNormalizationMap->SetWrapS(eTextureWrap_ClampToEdge);
|
||||
mpNormalizationMap->SetWrapT(eTextureWrap_ClampToEdge);
|
||||
|
||||
mpSpotNegativeRejectMap = mpTextureManager->Create1D("core_spot_negative_reject", false);
|
||||
if (mpSpotNegativeRejectMap) {
|
||||
mpSpotNegativeRejectMap->SetWrapS(eTextureWrap_ClampToEdge);
|
||||
mpSpotNegativeRejectMap->SetWrapT(eTextureWrap_ClampToEdge);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iMaterial_Fallback02_BaseLight::~iMaterial_Fallback02_BaseLight() {
|
||||
if (mpNormalizationMap)
|
||||
mpTextureManager->Destroy(mpNormalizationMap);
|
||||
if (mpSpotNegativeRejectMap)
|
||||
mpTextureManager->Destroy(mpSpotNegativeRejectMap);
|
||||
|
||||
for (int i = 0; i < eBaseLightProgram_LastEnum; i++) {
|
||||
if (_gpuPrograms[i])
|
||||
mpProgramManager->Destroy(_gpuPrograms[i]);
|
||||
}
|
||||
if (_diffuseGpuProgram)
|
||||
mpProgramManager->Destroy(_diffuseGpuProgram);
|
||||
if (_ambientGpuProgram)
|
||||
mpProgramManager->Destroy(_ambientGpuProgram);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iGpuProgram *iMaterial_Fallback02_BaseLight::getGpuProgram(const eMaterialRenderType aType, const int alPass, iLight3D *apLight) {
|
||||
eBaseLightProgram program = eBaseLightProgram_Point1;
|
||||
if (apLight) {
|
||||
if (apLight->GetLightType() == eLight3DType_Point)
|
||||
program = eBaseLightProgram_Point1;
|
||||
else if (apLight->GetLightType() == eLight3DType_Spot)
|
||||
program = eBaseLightProgram_Spot1;
|
||||
}
|
||||
|
||||
if (aType == eMaterialRenderType_Light)
|
||||
return _gpuPrograms[program + alPass];
|
||||
if (aType == eMaterialRenderType_Z)
|
||||
return _ambientGpuProgram;
|
||||
if (aType == eMaterialRenderType_Diffuse)
|
||||
return _diffuseGpuProgram;
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
iMaterialProgramSetup *iMaterial_Fallback02_BaseLight::getGpuProgramSetup(const eMaterialRenderType aType, const int alPass, iLight3D *apLight) {
|
||||
static cAmbProgramSetup ambProgramSetup;
|
||||
if (aType == eMaterialRenderType_Z)
|
||||
return &ambProgramSetup;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
|
||||
bool iMaterial_Fallback02_BaseLight::VertexProgramUsesLight(eMaterialRenderType aType, int alPass, iLight3D *apLight) {
|
||||
if (aType == eMaterialRenderType_Light) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
|
||||
bool iMaterial_Fallback02_BaseLight::VertexProgramUsesEye(eMaterialRenderType aType, int alPass, iLight3D *apLight) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
|
||||
eMaterialAlphaMode iMaterial_Fallback02_BaseLight::GetAlphaMode(eMaterialRenderType aType, int alPass, iLight3D *apLight) {
|
||||
if (aType == eMaterialRenderType_Z && mbHasAlpha)
|
||||
return eMaterialAlphaMode_Trans;
|
||||
|
||||
return eMaterialAlphaMode_Solid;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
|
||||
eMaterialBlendMode iMaterial_Fallback02_BaseLight::GetBlendMode(eMaterialRenderType aType, int alPass, iLight3D *apLight) {
|
||||
//////////////////////////////
|
||||
// Light
|
||||
if (aType == eMaterialRenderType_Light) {
|
||||
if (apLight->GetLightType() == eLight3DType_Point) {
|
||||
if (alPass == 0)
|
||||
return eMaterialBlendMode_Replace;
|
||||
else if (alPass == 1)
|
||||
return eMaterialBlendMode_DestAlphaAdd;
|
||||
} else {
|
||||
switch (alPass) {
|
||||
case 0:
|
||||
return eMaterialBlendMode_Replace;
|
||||
case 1:
|
||||
return eMaterialBlendMode_Mul;
|
||||
case 2:
|
||||
return eMaterialBlendMode_DestAlphaAdd;
|
||||
}
|
||||
}
|
||||
}
|
||||
//////////////////////////////
|
||||
// Z
|
||||
else if (aType == eMaterialRenderType_Z)
|
||||
return eMaterialBlendMode_Replace;
|
||||
|
||||
//////////////////////////////
|
||||
// Other
|
||||
return eMaterialBlendMode_Add;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
|
||||
eMaterialChannelMode iMaterial_Fallback02_BaseLight::GetChannelMode(eMaterialRenderType aType, int alPass, iLight3D *apLight) {
|
||||
////////////////////////////
|
||||
// Light
|
||||
if (aType == eMaterialRenderType_Light) {
|
||||
if (apLight->GetLightType() == eLight3DType_Point) {
|
||||
if (alPass == 0)
|
||||
return eMaterialChannelMode_A;
|
||||
} else {
|
||||
if (alPass == 0 || alPass == 1)
|
||||
return eMaterialChannelMode_A;
|
||||
}
|
||||
}
|
||||
//////////////////////////////
|
||||
// Other
|
||||
else if (aType == eMaterialRenderType_Z) {
|
||||
// return eMaterialChannelMode_Z;
|
||||
return eMaterialChannelMode_RGBA;
|
||||
}
|
||||
|
||||
return eMaterialChannelMode_RGBA;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iTexture *iMaterial_Fallback02_BaseLight::GetTexture(int alUnit, eMaterialRenderType aType, int alPass, iLight3D *apLight) {
|
||||
////////////////////////////////////////
|
||||
// Z
|
||||
if (aType == eMaterialRenderType_Z) {
|
||||
// if(alUnit==0 && mbHasAlpha) return mvTexture[eMaterialTexture_Diffuse];
|
||||
if (alUnit == 0)
|
||||
return mvTexture[eMaterialTexture_Diffuse];
|
||||
return NULL;
|
||||
}
|
||||
////////////////////////////////////////
|
||||
// Diffuse
|
||||
else if (aType == eMaterialRenderType_Diffuse) {
|
||||
if (alUnit == 0)
|
||||
return mvTexture[eMaterialTexture_Illumination];
|
||||
return NULL;
|
||||
}
|
||||
////////////////////////////////////////
|
||||
// Light
|
||||
else if (aType == eMaterialRenderType_Light) {
|
||||
if (alPass == 0) {
|
||||
switch (alUnit) {
|
||||
case 0:
|
||||
return mpNormalizationMap;
|
||||
case 1: {
|
||||
if (apLight->GetTempTexture(0) == NULL) {
|
||||
iTexture *pTex = apLight->GetFalloffMap();
|
||||
apLight->SetTempTexture(0, mpTextureManager->CreateAttenuation(pTex->GetName()));
|
||||
}
|
||||
return apLight->GetTempTexture(0);
|
||||
}
|
||||
}
|
||||
} else if (alPass == 1) {
|
||||
if (apLight->GetLightType() == eLight3DType_Point) {
|
||||
if (alUnit == 0)
|
||||
return mvTexture[eMaterialTexture_Diffuse];
|
||||
} else {
|
||||
if (alUnit == 0)
|
||||
return mpSpotNegativeRejectMap;
|
||||
}
|
||||
} else if (alPass == 2) {
|
||||
switch (alUnit) {
|
||||
case 0:
|
||||
return mvTexture[eMaterialTexture_Diffuse];
|
||||
case 1:
|
||||
if (apLight->GetLightType() == eLight3DType_Spot) {
|
||||
cLight3DSpot *pSpotLight = static_cast<cLight3DSpot *>(apLight);
|
||||
return pSpotLight->GetTexture();
|
||||
};
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
eMaterialBlendMode iMaterial_Fallback02_BaseLight::GetTextureBlend(int alUnit, eMaterialRenderType aType, int alPass, iLight3D *apLight) {
|
||||
return eMaterialBlendMode_None;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
int iMaterial_Fallback02_BaseLight::GetNumOfPasses(eMaterialRenderType aType, iLight3D *apLight) {
|
||||
if (aType == eMaterialRenderType_Light) {
|
||||
if (apLight->GetLightType() == eLight3DType_Point)
|
||||
return 2;
|
||||
else
|
||||
return 3;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool iMaterial_Fallback02_BaseLight::UsesType(eMaterialRenderType aType) {
|
||||
if (aType == eMaterialRenderType_Diffuse) {
|
||||
if (mvTexture[eMaterialTexture_Illumination])
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
tTextureTypeList iMaterial_Fallback02_BaseLight::GetTextureTypes() {
|
||||
tTextureTypeList vTypes;
|
||||
vTypes.push_back(cTextureType("", eMaterialTexture_Diffuse));
|
||||
vTypes.push_back(cTextureType("_illum", eMaterialTexture_Illumination));
|
||||
|
||||
return vTypes;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
} // namespace hpl
|
||||
114
engines/hpl1/engine/graphics/Material_Fallback02_BaseLight.h
Normal file
114
engines/hpl1/engine/graphics/Material_Fallback02_BaseLight.h
Normal file
@@ -0,0 +1,114 @@
|
||||
/* 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_FALLBACK02_BASE_LIGHT_H
|
||||
#define HPL_MATERIAL_FALLBACK02_BASE_LIGHT_H
|
||||
|
||||
#include "hpl1/engine/graphics/Material.h"
|
||||
#include "hpl1/engine/scene/Light3D.h"
|
||||
|
||||
#include "hpl1/engine/graphics/Material_BaseLight.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//---------------------------------------------------------------
|
||||
|
||||
class iMaterial_Fallback02_BaseLight : public iMaterial {
|
||||
public:
|
||||
iMaterial_Fallback02_BaseLight(
|
||||
const tString &asName, iLowLevelGraphics *apLowLevelGraphics,
|
||||
cImageManager *apImageManager, cTextureManager *apTextureManager,
|
||||
cRenderer2D *apRenderer, cGpuProgramManager *apProgramManager,
|
||||
eMaterialPicture aPicture, cRenderer3D *apRenderer3D);
|
||||
|
||||
virtual ~iMaterial_Fallback02_BaseLight();
|
||||
|
||||
tTextureTypeList GetTextureTypes();
|
||||
|
||||
bool UsesType(eMaterialRenderType aType);
|
||||
|
||||
iGpuProgram *getGpuProgram(const eMaterialRenderType aType, const int alPass, iLight3D *apLight);
|
||||
iMaterialProgramSetup *getGpuProgramSetup(const eMaterialRenderType aType, const int alPass, iLight3D *apLight);
|
||||
|
||||
bool VertexProgramUsesLight(eMaterialRenderType aType, int alPass, iLight3D *apLight);
|
||||
bool VertexProgramUsesEye(eMaterialRenderType aType, int alPass, iLight3D *apLight);
|
||||
|
||||
eMaterialAlphaMode GetAlphaMode(eMaterialRenderType aType, int alPass, iLight3D *apLight);
|
||||
eMaterialBlendMode GetBlendMode(eMaterialRenderType aType, int alPass, iLight3D *apLight);
|
||||
eMaterialChannelMode GetChannelMode(eMaterialRenderType aType, int alPass, iLight3D *apLight);
|
||||
|
||||
iTexture *GetTexture(int alUnit, eMaterialRenderType aType, int alPass, iLight3D *apLight);
|
||||
eMaterialBlendMode GetTextureBlend(int alUnit, eMaterialRenderType aType, int alPass, iLight3D *apLight);
|
||||
|
||||
int GetNumOfPasses(eMaterialRenderType aType, iLight3D *apLight);
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// Old and worthless stuff, only used by 2D renderer
|
||||
void Compile() {}
|
||||
bool StartRendering(eMaterialRenderType aType, iCamera *apCam, iLight *pLight) { return false; }
|
||||
void EndRendering(eMaterialRenderType aType) {}
|
||||
tVtxBatchFlag GetBatchFlags(eMaterialRenderType aType) { return 0; }
|
||||
bool NextPass(eMaterialRenderType aType) { return false; }
|
||||
bool HasMultiplePasses(eMaterialRenderType aType) { return false; }
|
||||
eMaterialType GetType(eMaterialRenderType aType) { return eMaterialType_Diffuse; }
|
||||
void EditVertexes(eMaterialRenderType aType, iCamera *apCam, iLight *pLight,
|
||||
tVertexVec *apVtxVec, cVector3f *apTransform, unsigned int alIndexAdd) {}
|
||||
|
||||
protected:
|
||||
iTexture *mpNormalizationMap;
|
||||
iTexture *mpSpotNegativeRejectMap;
|
||||
|
||||
iTexture *mpAttenuationMap;
|
||||
|
||||
iGpuProgram *_gpuPrograms[eBaseLightProgram_LastEnum];
|
||||
iGpuProgram *_diffuseGpuProgram;
|
||||
iGpuProgram *_ambientGpuProgram;
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------
|
||||
|
||||
///////////////////////////////////////////
|
||||
// Diffuse
|
||||
///////////////////////////////////////////
|
||||
|
||||
class cMaterial_Fallback02_Diffuse : public iMaterial_Fallback02_BaseLight {
|
||||
public:
|
||||
cMaterial_Fallback02_Diffuse(const tString &asName, iLowLevelGraphics *apLowLevelGraphics,
|
||||
cImageManager *apImageManager, cTextureManager *apTextureManager,
|
||||
cRenderer2D *apRenderer, cGpuProgramManager *apProgramManager,
|
||||
eMaterialPicture aPicture, cRenderer3D *apRenderer3D)
|
||||
: iMaterial_Fallback02_BaseLight(
|
||||
asName, apLowLevelGraphics, apImageManager, apTextureManager, apRenderer, apProgramManager,
|
||||
aPicture, apRenderer3D) {
|
||||
}
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_MATERIAL_FALLBACK02_BASE_LIGHT_H
|
||||
149
engines/hpl1/engine/graphics/Material_Flat.cpp
Normal file
149
engines/hpl1/engine/graphics/Material_Flat.cpp
Normal file
@@ -0,0 +1,149 @@
|
||||
/* 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/graphics/Material_Flat.h"
|
||||
#include "hpl1/engine/graphics/GPUProgram.h"
|
||||
#include "hpl1/engine/graphics/Renderer2D.h"
|
||||
#include "hpl1/engine/math/Math.h"
|
||||
#include "hpl1/engine/resources/GpuProgramManager.h"
|
||||
#include "hpl1/engine/resources/TextureManager.h"
|
||||
#include "hpl1/engine/scene/Camera.h"
|
||||
#include "hpl1/engine/scene/Light.h"
|
||||
#include "hpl1/engine/system/low_level_system.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cMaterial_Flat::cMaterial_Flat(const tString &asName, iLowLevelGraphics *apLowLevelGraphics,
|
||||
cImageManager *apImageManager, cTextureManager *apTextureManager,
|
||||
cRenderer2D *apRenderer, cGpuProgramManager *apProgramManager,
|
||||
eMaterialPicture aPicture, cRenderer3D *apRenderer3D)
|
||||
: iMaterial(asName, apLowLevelGraphics, apImageManager, apTextureManager, apRenderer, apProgramManager,
|
||||
aPicture, apRenderer3D) {
|
||||
mbIsTransperant = false;
|
||||
mbIsGlowing = false;
|
||||
mbUsesLights = false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cMaterial_Flat::~cMaterial_Flat() {
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cMaterial_Flat::VertexProgramUsesLight(eMaterialRenderType aType, int alPass, iLight3D *apLight) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool cMaterial_Flat::VertexProgramUsesEye(eMaterialRenderType aType, int alPass, iLight3D *apLight) {
|
||||
return false;
|
||||
}
|
||||
|
||||
eMaterialAlphaMode cMaterial_Flat::GetAlphaMode(eMaterialRenderType aType, int alPass, iLight3D *apLight) {
|
||||
if (aType == eMaterialRenderType_Z && mbHasAlpha)
|
||||
return eMaterialAlphaMode_Trans;
|
||||
|
||||
return eMaterialAlphaMode_Solid;
|
||||
}
|
||||
|
||||
eMaterialBlendMode cMaterial_Flat::GetBlendMode(eMaterialRenderType aType, int alPass, iLight3D *apLight) {
|
||||
if (aType == eMaterialRenderType_Z)
|
||||
return eMaterialBlendMode_None;
|
||||
|
||||
if (alPass == 1)
|
||||
return eMaterialBlendMode_Add;
|
||||
else
|
||||
return eMaterialBlendMode_Replace;
|
||||
}
|
||||
|
||||
eMaterialChannelMode cMaterial_Flat::GetChannelMode(eMaterialRenderType aType, int alPass, iLight3D *apLight) {
|
||||
if (aType == eMaterialRenderType_Z)
|
||||
return eMaterialChannelMode_Z;
|
||||
return eMaterialChannelMode_RGBA;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iTexture *cMaterial_Flat::GetTexture(int alUnit, eMaterialRenderType aType, int alPass, iLight3D *apLight) {
|
||||
if (aType == eMaterialRenderType_Z) {
|
||||
if (alUnit == 0 && mbHasAlpha)
|
||||
return mvTexture[eMaterialTexture_Diffuse];
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (alUnit == 0) {
|
||||
if (alPass == 0)
|
||||
return mvTexture[eMaterialTexture_Diffuse];
|
||||
else
|
||||
return mvTexture[eMaterialTexture_Illumination];
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
eMaterialBlendMode cMaterial_Flat::GetTextureBlend(int alUnit, eMaterialRenderType aType, int alPass, iLight3D *apLight) {
|
||||
return eMaterialBlendMode_Mul;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cMaterial_Flat::UsesType(eMaterialRenderType aType) {
|
||||
if (aType == eMaterialRenderType_Diffuse || aType == eMaterialRenderType_Z)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
int cMaterial_Flat::GetNumOfPasses(eMaterialRenderType aType, iLight3D *apLight) {
|
||||
if (mvTexture[eMaterialTexture_Illumination])
|
||||
return 2;
|
||||
return 1;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
tTextureTypeList cMaterial_Flat::GetTextureTypes() {
|
||||
tTextureTypeList vTypes;
|
||||
vTypes.push_back(cTextureType("", eMaterialTexture_Diffuse));
|
||||
vTypes.push_back(cTextureType("", eMaterialTexture_Illumination));
|
||||
|
||||
return vTypes;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
} // namespace hpl
|
||||
92
engines/hpl1/engine/graphics/Material_Flat.h
Normal file
92
engines/hpl1/engine/graphics/Material_Flat.h
Normal file
@@ -0,0 +1,92 @@
|
||||
/* 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_FLAT_H
|
||||
#define HPL_MATERIAL_FLAT_H
|
||||
|
||||
#include "hpl1/engine/graphics/GPUProgram.h"
|
||||
#include "hpl1/engine/graphics/Material.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class cMaterial_Flat : public iMaterial {
|
||||
public:
|
||||
cMaterial_Flat(const tString &asName, iLowLevelGraphics *apLowLevelGraphics,
|
||||
cImageManager *apImageManager, cTextureManager *apTextureManager,
|
||||
cRenderer2D *apRenderer, cGpuProgramManager *apProgramManager,
|
||||
eMaterialPicture aPicture, cRenderer3D *apRenderer3D);
|
||||
|
||||
virtual ~cMaterial_Flat();
|
||||
|
||||
tTextureTypeList GetTextureTypes();
|
||||
|
||||
bool UsesType(eMaterialRenderType aType);
|
||||
|
||||
bool VertexProgramUsesLight(eMaterialRenderType aType, int alPass, iLight3D *apLight);
|
||||
bool VertexProgramUsesEye(eMaterialRenderType aType, int alPass, iLight3D *apLight);
|
||||
|
||||
eMaterialAlphaMode GetAlphaMode(eMaterialRenderType aType, int alPass, iLight3D *apLight);
|
||||
eMaterialBlendMode GetBlendMode(eMaterialRenderType aType, int alPass, iLight3D *apLight);
|
||||
eMaterialChannelMode GetChannelMode(eMaterialRenderType aType, int alPass, iLight3D *apLight);
|
||||
|
||||
iTexture *GetTexture(int alUnit, eMaterialRenderType aType, int alPass, iLight3D *apLight);
|
||||
eMaterialBlendMode GetTextureBlend(int alUnit, eMaterialRenderType aType, int alPass, iLight3D *apLight);
|
||||
|
||||
int GetNumOfPasses(eMaterialRenderType aType, iLight3D *apLight);
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// Old and worthless stuff, only used by 2D renderer
|
||||
void Compile() {}
|
||||
bool StartRendering(eMaterialRenderType aType, iCamera *apCam, iLight *pLight) { return false; }
|
||||
void EndRendering(eMaterialRenderType aType) {}
|
||||
tVtxBatchFlag GetBatchFlags(eMaterialRenderType aType) { return 0; }
|
||||
bool NextPass(eMaterialRenderType aType) { return false; }
|
||||
bool HasMultiplePasses(eMaterialRenderType aType) { return false; }
|
||||
eMaterialType GetType(eMaterialRenderType aType) { return eMaterialType_Diffuse; }
|
||||
void EditVertexes(eMaterialRenderType aType, iCamera *apCam, iLight *pLight,
|
||||
tVertexVec *apVtxVec, cVector3f *apTransform, unsigned int alIndexAdd) {}
|
||||
};
|
||||
|
||||
class cMaterialType_Flat : public iMaterialType {
|
||||
public:
|
||||
bool IsCorrect(tString asName) {
|
||||
return cString::ToLowerCase(asName) == "flat";
|
||||
}
|
||||
|
||||
iMaterial *Create(const tString &asName, iLowLevelGraphics *apLowLevelGraphics,
|
||||
cImageManager *apImageManager, cTextureManager *apTextureManager,
|
||||
cRenderer2D *apRenderer, cGpuProgramManager *apProgramManager,
|
||||
eMaterialPicture aPicture, cRenderer3D *apRenderer3D) {
|
||||
return hplNew(cMaterial_Flat, (asName, apLowLevelGraphics,
|
||||
apImageManager, apTextureManager, apRenderer,
|
||||
apProgramManager, aPicture, apRenderer3D));
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_MATERIAL_FLAT_H
|
||||
118
engines/hpl1/engine/graphics/Material_FontNormal.cpp
Normal file
118
engines/hpl1/engine/graphics/Material_FontNormal.cpp
Normal file
@@ -0,0 +1,118 @@
|
||||
/* 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/graphics/Material_FontNormal.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cMaterial_FontNormal::cMaterial_FontNormal(const tString &asName, iLowLevelGraphics *apLowLevelGraphics,
|
||||
cImageManager *apImageManager, cTextureManager *apTextureManager,
|
||||
cRenderer2D *apRenderer, cGpuProgramManager *apProgramManager,
|
||||
eMaterialPicture aPicture, cRenderer3D *apRenderer3D)
|
||||
: iMaterial(asName, apLowLevelGraphics, apImageManager, apTextureManager, apRenderer, apProgramManager,
|
||||
aPicture, apRenderer3D) {
|
||||
mbIsTransperant = true;
|
||||
mbIsGlowing = true;
|
||||
mType = eMaterialType_FontNormal;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cMaterial_FontNormal::~cMaterial_FontNormal() {
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cMaterial_FontNormal::Compile() {
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cMaterial_FontNormal::StartRendering(eMaterialRenderType aType, iCamera *apCam, iLight *pLight) {
|
||||
if (aType == eMaterialRenderType_Diffuse) {
|
||||
mpLowLevelGraphics->SetBlendActive(true);
|
||||
mpLowLevelGraphics->SetBlendFunc(eBlendFunc_SrcAlpha, eBlendFunc_OneMinusSrcAlpha);
|
||||
|
||||
mpLowLevelGraphics->SetTexture(0, GetTexture(eMaterialTexture_Diffuse));
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cMaterial_FontNormal::EndRendering(eMaterialRenderType aType) {
|
||||
if (aType == eMaterialRenderType_Diffuse) {
|
||||
// mpLowLevelGraphics->SetTextureParam(eTextureParam_AlphaSource0,eTextureSource_Texture);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
tVtxBatchFlag cMaterial_FontNormal::GetBatchFlags(eMaterialRenderType aType) {
|
||||
return eVtxBatchFlag_Position | eVtxBatchFlag_Texture0 | eVtxBatchFlag_Color0;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cMaterial_FontNormal::NextPass(eMaterialRenderType aType) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cMaterial_FontNormal::HasMultiplePasses(eMaterialRenderType aType) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
eMaterialType cMaterial_FontNormal::GetType(eMaterialRenderType aType) {
|
||||
return mType;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cMaterial_FontNormal::EditVertexes(eMaterialRenderType aType, iCamera *apCam, iLight *pLight,
|
||||
tVertexVec *apVtxVec, cVector3f *apTransform, unsigned int alIndexAdd) {
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
} // namespace hpl
|
||||
75
engines/hpl1/engine/graphics/Material_FontNormal.h
Normal file
75
engines/hpl1/engine/graphics/Material_FontNormal.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_MATERIAL_FONTNORMAL_H
|
||||
#define HPL_MATERIAL_FONTNORMAL_H
|
||||
|
||||
#include "hpl1/engine/graphics/Material.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class cMaterial_FontNormal : public iMaterial {
|
||||
public:
|
||||
cMaterial_FontNormal(const tString &asName, iLowLevelGraphics *apLowLevelGraphics,
|
||||
cImageManager *apImageManager, cTextureManager *apTextureManager,
|
||||
cRenderer2D *apRenderer, cGpuProgramManager *apProgramManager,
|
||||
eMaterialPicture aPicture, cRenderer3D *apRenderer3D);
|
||||
~cMaterial_FontNormal();
|
||||
|
||||
void Compile();
|
||||
bool StartRendering(eMaterialRenderType aType, iCamera *apCam, iLight *pLight);
|
||||
void EndRendering(eMaterialRenderType aType);
|
||||
tVtxBatchFlag GetBatchFlags(eMaterialRenderType aType);
|
||||
bool NextPass(eMaterialRenderType aType);
|
||||
bool HasMultiplePasses(eMaterialRenderType aType);
|
||||
|
||||
eMaterialType GetType(eMaterialRenderType aType);
|
||||
void EditVertexes(eMaterialRenderType aType, iCamera *apCam, iLight *pLight,
|
||||
tVertexVec *apVtxVec, cVector3f *apTransform, unsigned int alIndexAdd);
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
class cMaterialType_FontNormal : public iMaterialType {
|
||||
public:
|
||||
bool IsCorrect(tString asName) {
|
||||
return cString::ToLowerCase(asName) == "fontnormal";
|
||||
}
|
||||
|
||||
iMaterial *Create(const tString &asName, iLowLevelGraphics *apLowLevelGraphics,
|
||||
cImageManager *apImageManager, cTextureManager *apTextureManager,
|
||||
cRenderer2D *apRenderer, cGpuProgramManager *apProgramManager,
|
||||
eMaterialPicture aPicture, cRenderer3D *apRenderer3D) {
|
||||
return hplNew(cMaterial_FontNormal, (asName, apLowLevelGraphics,
|
||||
apImageManager, apTextureManager, apRenderer,
|
||||
apProgramManager, aPicture, apRenderer3D));
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_MATERIAL_FONTNORMAL_H
|
||||
163
engines/hpl1/engine/graphics/Material_Modulative.cpp
Normal file
163
engines/hpl1/engine/graphics/Material_Modulative.cpp
Normal file
@@ -0,0 +1,163 @@
|
||||
/* 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/graphics/Material_Modulative.h"
|
||||
#include "hpl1/engine/graphics/GPUProgram.h"
|
||||
#include "hpl1/engine/graphics/Renderer2D.h"
|
||||
#include "hpl1/engine/graphics/Renderer3D.h"
|
||||
#include "hpl1/engine/math/Math.h"
|
||||
#include "hpl1/engine/resources/GpuProgramManager.h"
|
||||
#include "hpl1/engine/resources/TextureManager.h"
|
||||
#include "hpl1/engine/scene/Camera.h"
|
||||
#include "hpl1/engine/scene/Light.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// VERTEX PRORGAM SETUP
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
class cFogProgramSetup : public iMaterialProgramSetup {
|
||||
public:
|
||||
void Setup(iGpuProgram *apProgram, cRenderSettings *apRenderSettings) {
|
||||
apProgram->SetFloat("fogStart", apRenderSettings->mfFogStart);
|
||||
apProgram->SetFloat("fogEnd", apRenderSettings->mfFogEnd);
|
||||
}
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cMaterial_Modulative::cMaterial_Modulative(const tString &asName, iLowLevelGraphics *apLowLevelGraphics,
|
||||
cImageManager *apImageManager, cTextureManager *apTextureManager,
|
||||
cRenderer2D *apRenderer, cGpuProgramManager *apProgramManager,
|
||||
eMaterialPicture aPicture, cRenderer3D *apRenderer3D)
|
||||
: iMaterial(asName, apLowLevelGraphics, apImageManager, apTextureManager, apRenderer, apProgramManager,
|
||||
aPicture, apRenderer3D) {
|
||||
mbIsTransperant = true;
|
||||
mbIsGlowing = false;
|
||||
mbUsesLights = false;
|
||||
|
||||
_fogShader = mpProgramManager->CreateProgram("hpl1_Fog_Trans", "hpl1_Fog_Trans_Mod");
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cMaterial_Modulative::~cMaterial_Modulative() {
|
||||
if (_fogShader)
|
||||
mpProgramManager->Destroy(_fogShader);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iGpuProgram *cMaterial_Modulative::getGpuProgram(const eMaterialRenderType aType, const int alPass, iLight3D *apLight) {
|
||||
if (mpRenderSettings->mbFogActive)
|
||||
return _fogShader;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
iMaterialProgramSetup *cMaterial_Modulative::getGpuProgramSetup(const eMaterialRenderType aType, const int alPass, iLight3D *apLight) {
|
||||
static cFogProgramSetup gFogProgramSetup;
|
||||
if (mpRenderSettings->mbFogActive)
|
||||
return &gFogProgramSetup;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool cMaterial_Modulative::VertexProgramUsesLight(eMaterialRenderType aType, int alPass, iLight3D *apLight) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool cMaterial_Modulative::VertexProgramUsesEye(eMaterialRenderType aType, int alPass, iLight3D *apLight) {
|
||||
return false;
|
||||
}
|
||||
|
||||
eMaterialAlphaMode cMaterial_Modulative::GetAlphaMode(eMaterialRenderType aType, int alPass, iLight3D *apLight) {
|
||||
return eMaterialAlphaMode_Solid;
|
||||
}
|
||||
|
||||
eMaterialBlendMode cMaterial_Modulative::GetBlendMode(eMaterialRenderType aType, int alPass, iLight3D *apLight) {
|
||||
return eMaterialBlendMode_Mul;
|
||||
}
|
||||
|
||||
eMaterialChannelMode cMaterial_Modulative::GetChannelMode(eMaterialRenderType aType, int alPass, iLight3D *apLight) {
|
||||
return eMaterialChannelMode_RGBA;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iTexture *cMaterial_Modulative::GetTexture(int alUnit, eMaterialRenderType aType, int alPass, iLight3D *apLight) {
|
||||
if (mpRenderSettings->mbFogActive) {
|
||||
if (alUnit == 0)
|
||||
return mvTexture[eMaterialTexture_Diffuse];
|
||||
else if (alUnit == 1)
|
||||
return mpRenderer3D->GetFogAddTexture();
|
||||
} else {
|
||||
if (alUnit == 0)
|
||||
return mvTexture[eMaterialTexture_Diffuse];
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
eMaterialBlendMode cMaterial_Modulative::GetTextureBlend(int alUnit, eMaterialRenderType aType, int alPass, iLight3D *apLight) {
|
||||
return eMaterialBlendMode_Mul;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cMaterial_Modulative::UsesType(eMaterialRenderType aType) {
|
||||
if (aType == eMaterialRenderType_Diffuse)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
tTextureTypeList cMaterial_Modulative::GetTextureTypes() {
|
||||
tTextureTypeList vTypes;
|
||||
vTypes.push_back(cTextureType("", eMaterialTexture_Diffuse));
|
||||
vTypes.push_back(cTextureType("_ref", eMaterialTexture_Refraction));
|
||||
vTypes.push_back(cTextureType("_spec", eMaterialTexture_Specular));
|
||||
|
||||
return vTypes;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
} // namespace hpl
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user