mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2025-01-31 05:37:17 -05:00
Added data manager. Added file/mpq lookup dictionary.
This commit is contained in:
parent
e68eafd5f6
commit
591d90134a
@ -1,17 +1,18 @@
|
||||
set (SOURCES
|
||||
src/main.cpp
|
||||
src/D2DataManager.cpp
|
||||
src/D2Engine.cpp
|
||||
src/Scenes/D2MainMenu.cpp
|
||||
)
|
||||
|
||||
set (HEADERS
|
||||
include/OpenDiablo2.Game/D2DataManager.h
|
||||
include/OpenDiablo2.Game/D2Engine.h
|
||||
include/OpenDiablo2.Game/D2EngineConfig.h
|
||||
include/OpenDiablo2.Game/Scenes/D2Scene.h
|
||||
include/OpenDiablo2.Game/Scenes/D2MainMenu.h
|
||||
)
|
||||
|
||||
|
||||
add_executable(OpenDiablo2.Game ${SOURCES} ${HEADERS})
|
||||
|
||||
target_include_directories(OpenDiablo2.SDL2
|
||||
@ -28,3 +29,7 @@ target_link_libraries(OpenDiablo2.Game
|
||||
stdc++fs
|
||||
spdlog::spdlog
|
||||
)
|
||||
|
||||
set_target_properties(OpenDiablo2.Game PROPERTIES
|
||||
CXX_STANDARD 17
|
||||
)
|
||||
|
@ -0,0 +1,21 @@
|
||||
#ifndef OPENDIABLO2_GAME_D2DATAMANAGER_H
|
||||
#define OPENDIABLO2_GAME_D2DATAMANAGER_H
|
||||
|
||||
#include <memory>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <OpenDiablo2.Game/D2EngineConfig.h>
|
||||
|
||||
namespace OpenDiablo2::Game {
|
||||
|
||||
class D2DataManager {
|
||||
public:
|
||||
typedef std::unique_ptr<D2DataManager> Ptr;
|
||||
D2DataManager(const D2EngineConfig& engineConfig);
|
||||
private:
|
||||
std::map<std::string, std::string> fileEntries;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // OPENDIABLO2_GAME_D2DATAMANAGER_H
|
@ -3,6 +3,7 @@
|
||||
|
||||
#include <stack>
|
||||
#include <memory>
|
||||
#include <OpenDiablo2.Game/D2DataManager.h>
|
||||
#include <OpenDiablo2.System/D2Graphics.h>
|
||||
#include <OpenDiablo2.System/D2Input.h>
|
||||
#include <OpenDiablo2.Game/Scenes/D2Scene.h>
|
||||
@ -20,16 +21,14 @@ public:
|
||||
// Runs the engine
|
||||
void Run();
|
||||
|
||||
OpenDiablo2::Game::D2DataManager::Ptr dataManager;
|
||||
OpenDiablo2::System::D2Graphics::Ptr gfx;
|
||||
OpenDiablo2::System::D2Input::Ptr input;
|
||||
|
||||
private:
|
||||
// Represents the engine configuration
|
||||
const D2EngineConfig config;
|
||||
|
||||
// The graphics subsystem
|
||||
OpenDiablo2::System::D2Graphics::Ptr gfx;
|
||||
|
||||
// The input subsystem
|
||||
OpenDiablo2::System::D2Input::Ptr input;
|
||||
|
||||
// Indicates the system should keep running (if set to true)
|
||||
bool isRunning = true;
|
||||
|
||||
|
59
src/OpenDiablo2.Game/src/D2DataManager.cpp
Normal file
59
src/OpenDiablo2.Game/src/D2DataManager.cpp
Normal file
@ -0,0 +1,59 @@
|
||||
#include <experimental/filesystem>
|
||||
#include <spdlog/spdlog.h>
|
||||
#include <StormLib.h>
|
||||
#include <OpenDiablo2.Game/D2DataManager.h>
|
||||
|
||||
namespace fs = std::experimental::filesystem;
|
||||
|
||||
OpenDiablo2::Game::D2DataManager::D2DataManager(const D2EngineConfig &engineConfig)
|
||||
: fileEntries() {
|
||||
spdlog::info("Loading data files");
|
||||
auto mpqExt = std::string(".mpq");
|
||||
for (auto &p : fs::recursive_directory_iterator(engineConfig.BasePath))
|
||||
{
|
||||
if (p.path().extension() != mpqExt)
|
||||
continue;
|
||||
|
||||
HANDLE hMpq = NULL;
|
||||
HANDLE hListFile = NULL;
|
||||
|
||||
if(!SFileOpenArchive(p.path().c_str(), 0, 0, &hMpq)) {
|
||||
spdlog::error(std::string(" > ").append(p.path().string()).append(" [READ ERROR!]"));
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!SFileOpenFileEx(hMpq, "(listfile)", 0, &hListFile)) {
|
||||
spdlog::error(std::string(" > ").append(p.path().string()).append(" [LIST FILE NOT FOUND!]"));
|
||||
SFileCloseArchive(hMpq);
|
||||
continue;
|
||||
}
|
||||
|
||||
auto listFileContents = std::string();
|
||||
char szBuffer[0x10000];
|
||||
DWORD dwBytes = 1;
|
||||
|
||||
while(dwBytes > 0)
|
||||
{
|
||||
SFileReadFile(hListFile, szBuffer, sizeof(szBuffer), &dwBytes, NULL);
|
||||
if(dwBytes > 0) {
|
||||
listFileContents.append(szBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
std::string delim = "\r\n";
|
||||
auto start = 0U;
|
||||
auto end = listFileContents.find(delim);
|
||||
auto linesFound = 0;
|
||||
while (end != std::string::npos)
|
||||
{
|
||||
linesFound++;
|
||||
fileEntries.emplace(listFileContents.substr(start, end - start), p.path().stem().string());
|
||||
start = end + delim.length();
|
||||
end = listFileContents.find(delim, start);
|
||||
}
|
||||
spdlog::debug(std::string(" > ").append(p.path().string()).append(" [").append(std::to_string(linesFound)).append(" files]"));
|
||||
SFileCloseFile(hListFile);
|
||||
|
||||
SFileCloseArchive(hMpq);
|
||||
}
|
||||
}
|
@ -3,10 +3,11 @@
|
||||
|
||||
|
||||
OpenDiablo2::Game::D2Engine::D2Engine(const D2EngineConfig &config)
|
||||
: config(config) {
|
||||
gfx = std::make_unique<OpenDiablo2::System::D2Graphics>();
|
||||
input = std::make_unique<OpenDiablo2::System::D2Input>();
|
||||
}
|
||||
: config(config)
|
||||
, gfx(std::make_unique<OpenDiablo2::System::D2Graphics>())
|
||||
, input(std::make_unique<OpenDiablo2::System::D2Input>())
|
||||
, dataManager(std::make_unique<OpenDiablo2::Game::D2DataManager>(config))
|
||||
{ }
|
||||
|
||||
void
|
||||
OpenDiablo2::Game::D2Engine::Run() {
|
||||
|
@ -1,25 +1,29 @@
|
||||
project(OpenDiablo2.SDL2 VERSION 0.1 LANGUAGES CXX)
|
||||
|
||||
set (SOURCES
|
||||
src/D2Graphics.cpp
|
||||
src/D2Input.cpp
|
||||
set (SOURCES
|
||||
src/D2Graphics.cpp
|
||||
src/D2Input.cpp
|
||||
)
|
||||
|
||||
set (HEADERS
|
||||
include/OpenDiablo2.System/D2Graphics.h
|
||||
include/OpenDiablo2.System/D2Input.h
|
||||
include/OpenDiablo2.System/D2Graphics.h
|
||||
include/OpenDiablo2.System/D2Input.h
|
||||
)
|
||||
|
||||
add_library(OpenDiablo2.SDL2 SHARED ${SOURCES} ${HEADERS})
|
||||
|
||||
target_include_directories(OpenDiablo2.SDL2
|
||||
PUBLIC
|
||||
include
|
||||
PRIVATE
|
||||
include
|
||||
PUBLIC
|
||||
include
|
||||
PRIVATE
|
||||
include
|
||||
)
|
||||
|
||||
target_link_libraries(OpenDiablo2.SDL2
|
||||
spdlog::spdlog
|
||||
SDL2-static
|
||||
spdlog::spdlog
|
||||
SDL2-static
|
||||
)
|
||||
|
||||
set_target_properties(OpenDiablo2.SDL2 PROPERTIES
|
||||
CXX_STANDARD 17
|
||||
)
|
||||
|
@ -28,6 +28,8 @@ struct SDLRendererDestroyer
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
class D2Graphics
|
||||
{
|
||||
public:
|
||||
|
Loading…
Reference in New Issue
Block a user