diff options
| author | Xavier Del Campo Romero <xavi92@disroot.org> | 2025-12-19 00:01:17 +0100 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi92@disroot.org> | 2025-12-22 12:47:40 +0100 |
| commit | c736e13c7dd04bfa6c0580a4db3d6501dc28eed1 (patch) | |
| tree | 04d1b490f710b0ed956e8f43d620ed6f846b8cf2 | |
| parent | e2f9ee3f8cd319e952e4f5d5ec466f0ea9e6e77f (diff) | |
| download | globalops-irrlicht.tar.gz | |
Irrlichtirrlicht
| -rw-r--r-- | CMakeLists.txt | 23 | ||||
| -rw-r--r-- | cmake/FindIrrlicht.cmake | 44 | ||||
| -rw-r--r-- | src/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | src/irrlicht/CMakeLists.txt | 9 | ||||
| -rw-r--r-- | src/irrlicht/DTXImage.cpp | 116 | ||||
| -rw-r--r-- | src/irrlicht/DTXImage.h | 44 | ||||
| -rw-r--r-- | src/irrlicht/DTXImageLoader.cpp | 18 | ||||
| -rw-r--r-- | src/irrlicht/DTXImageLoader.h | 13 | ||||
| -rw-r--r-- | src/irrlicht/RezArchive.cpp | 44 | ||||
| -rw-r--r-- | src/irrlicht/RezArchive.h | 24 | ||||
| -rw-r--r-- | src/irrlicht/RezFileList.cpp | 143 | ||||
| -rw-r--r-- | src/irrlicht/RezFileList.h | 35 | ||||
| -rw-r--r-- | src/irrlicht/RezLoader.cpp | 56 | ||||
| -rw-r--r-- | src/irrlicht/RezLoader.h | 19 | ||||
| -rw-r--r-- | src/irrlicht/RezReadFile.cpp | 33 | ||||
| -rw-r--r-- | src/irrlicht/RezReadFile.h | 23 | ||||
| -rw-r--r-- | src/main.cpp | 108 | ||||
| -rw-r--r-- | src/rez/rez.cpp | 51 | ||||
| -rw-r--r-- | src/rez/rez.h | 3 |
19 files changed, 718 insertions, 89 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 90292e5..98eb087 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,24 +7,21 @@ set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_FULL_LIBDIR} ${CMAKE_INSTALL_PREFIX}/${SD_LIBDIR}/lib ) +find_package(Irrlicht REQUIRED) find_package(OpenGL REQUIRED) -find_package(OpenSceneGraph REQUIRED) -find_package(osgViewer REQUIRED) -include(SetupOSGTargets) add_executable(${PROJECT_NAME}) add_subdirectory(src) -target_compile_options(${PROJECT_NAME} PRIVATE -pedantic -Wall -Og) + +if(CMAKE_BUILD_TYPE STREQUAL "Debug") + target_compile_options(${PROJECT_NAME} PRIVATE -Og) +else() + target_compile_options(${PROJECT_NAME} PRIVATE -O3) +endif() + +target_compile_options(${PROJECT_NAME} PRIVATE -pedantic -Wall) target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17) set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 17 CXX_EXTENSIONS OFF ) -target_link_libraries(${PROJECT_NAME} PRIVATE - OpenGL::GL - OpenSceneGraph::Core - OpenSceneGraph::Viewer - OpenThreads::OpenThreads -) - -# https://stackoverflow.com/questions/53461465/cannot-find-shared-libraries-even-rpath-is-set-correctly -target_link_options(${PROJECT_NAME} PRIVATE -Wl,--disable-new-dtags) +target_link_libraries(${PROJECT_NAME} PRIVATE Irrlicht OpenGL::GL) diff --git a/cmake/FindIrrlicht.cmake b/cmake/FindIrrlicht.cmake new file mode 100644 index 0000000..0d2533f --- /dev/null +++ b/cmake/FindIrrlicht.cmake @@ -0,0 +1,44 @@ +mark_as_advanced(IRRLICHT_LIBRARY IRRLICHT_INCLUDE_DIR) +find_library(IRRLICHT_LIBRARY NAMES libirrlicht Irrlicht) +find_path(IRRLICHT_INCLUDE_DIR NAMES irrlicht.h PATH_SUFFIXES irrlicht) + +# Major version +file(STRINGS ${IRRLICHT_INCLUDE_DIR}/IrrCompileConfig.h + irrlicht_MAJOR_VERSION_LINE REGEX + "^#define[ \t]+IRRLICHT_VERSION_MAJOR[ \t]+[0-9]+$") +string(REGEX REPLACE + "^#define[ \t]+IRRLICHT_VERSION_MAJOR[ \t]+([0-9]+)$" + "\\1" irrlicht_VERSION_MAJOR "${irrlicht_MAJOR_VERSION_LINE}") + +# Minor version +file(STRINGS ${IRRLICHT_INCLUDE_DIR}/IrrCompileConfig.h + irrlicht_MINOR_VERSION_LINE REGEX + "^#define[ \t]+IRRLICHT_VERSION_MINOR[ \t]+[0-9]+$") +string(REGEX REPLACE + "^#define[ \t]+IRRLICHT_VERSION_MINOR[ \t]+([0-9]+)$" + "\\1" irrlicht_VERSION_MINOR "${irrlicht_MINOR_VERSION_LINE}") + +# Patch version (revision) +file(STRINGS ${IRRLICHT_INCLUDE_DIR}/IrrCompileConfig.h + irrlicht_REVISION_VERSION_LINE REGEX + "^#define[ \t]+IRRLICHT_VERSION_REVISION[ \t]+[0-9]+$") +string(REGEX REPLACE + "^#define[ \t]+IRRLICHT_VERSION_REVISION[ \t]+([0-9]+)$" + "\\1" irrlicht_VERSION_REVISION "${irrlicht_REVISION_VERSION_LINE}") + +set(Irrlicht_VERSION_STRING + ${irrlicht_VERSION_MAJOR}.${irrlicht_VERSION_MINOR}.${irrlicht_VERSION_REVISION}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Irrlicht + VERSION_VAR Irrlicht_VERSION_STRING + REQUIRED_VARS IRRLICHT_LIBRARY IRRLICHT_INCLUDE_DIR) + +if(Irrlicht_FOUND) + if(NOT TARGET Irrlicht) + add_library(Irrlicht UNKNOWN IMPORTED) + set_target_properties(Irrlicht PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${IRRLICHT_INCLUDE_DIR}" + IMPORTED_LOCATION "${IRRLICHT_LIBRARY}") + endif() +endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e8e3894..54f7542 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,4 +1,5 @@ target_sources(${PROJECT_NAME} PRIVATE main.cpp) add_subdirectory(abc) add_subdirectory(dtx) +add_subdirectory(irrlicht) add_subdirectory(rez) diff --git a/src/irrlicht/CMakeLists.txt b/src/irrlicht/CMakeLists.txt new file mode 100644 index 0000000..8c0c33e --- /dev/null +++ b/src/irrlicht/CMakeLists.txt @@ -0,0 +1,9 @@ +target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_LIST_DIR}) +target_sources(${PROJECT_NAME} PRIVATE + DTXImage.cpp + DTXImageLoader.cpp + RezArchive.cpp + RezFileList.cpp + RezLoader.cpp + RezReadFile.cpp +) diff --git a/src/irrlicht/DTXImage.cpp b/src/irrlicht/DTXImage.cpp new file mode 100644 index 0000000..b6e6cdc --- /dev/null +++ b/src/irrlicht/DTXImage.cpp @@ -0,0 +1,116 @@ +#include <DTXImage.h> +#include <irrlicht.h> + +void *DTXImage::lock() +{ + return nullptr; +} + +void DTXImage::unlock() +{ +} + +const irr::core::dimension2d<irr::u32> &DTXImage::getDimension() const +{ + static const irr::core::dimension2d<irr::u32> d; + + return d; +} + +irr::u32 DTXImage::getBitsPerPixel() const +{ + return 0; +} + +irr::u32 DTXImage::getBytesPerPixel() const +{ + return 0; +} + +irr::u32 DTXImage::getImageDataSizeInBytes() const +{ + return 0; +} + +irr::u32 DTXImage::getImageDataSizeInPixels() const +{ + return 0; +} + +irr::video::SColor DTXImage::getPixel(irr::u32 x, irr::u32 y) const +{ + return irr::video::SColor(); +} + +void DTXImage::setPixel(irr::u32 x, irr::u32 y, const irr::video::SColor &color, + bool blend) +{ +} + +irr::video::ECOLOR_FORMAT DTXImage::getColorFormat() const +{ + return irr::video::ECOLOR_FORMAT::ECF_UNKNOWN; +} + +irr::u32 DTXImage::getRedMask() const +{ + return 0; +} + +irr::u32 DTXImage::getGreenMask() const +{ + return 0; +} + +irr::u32 DTXImage::getBlueMask() const +{ + return 0; +} + +irr::u32 DTXImage::getAlphaMask() const +{ + return 0; +} + +irr::u32 DTXImage::getPitch() const +{ + return 0; +} + +void DTXImage::copyToScaling(void *target, irr::u32 width, irr::u32 height, + irr::video::ECOLOR_FORMAT format, + irr::u32 pitch) +{ +} + +void DTXImage::copyToScaling(IImage *target) +{ +} + +void DTXImage::copyTo(IImage *target, const irr::core::position2d<irr::s32> &) +{ +} + +void DTXImage::copyTo(IImage *target, + const irr::core::position2d<irr::s32> &pos, + const irr::core::rect<irr::s32> &sourceRect, + const irr::core::rect<irr::s32> *clipRect) +{ +} + +void DTXImage::copyToWithAlpha(IImage* target, + const irr::core::position2d<irr::s32> &pos, + const irr::core::rect<irr::s32> &sourceRect, + const irr::video::SColor &color, + const irr::core::rect<irr::s32>* clipRect) +{ +} + +void DTXImage::copyToScalingBoxFilter(IImage* target, irr::s32 bias, + bool blend) +{ +} + +void DTXImage::fill(const irr::video::SColor &color) +{ +} diff --git a/src/irrlicht/DTXImage.h b/src/irrlicht/DTXImage.h new file mode 100644 index 0000000..a4912d3 --- /dev/null +++ b/src/irrlicht/DTXImage.h @@ -0,0 +1,44 @@ +#ifndef DTXIMAGE_H +#define DTXIMAGE_H + +#include <irrlicht.h> + +class DTXImage : public irr::video::IImage +{ + void *lock(); + void unlock(); + const irr::core::dimension2d<irr::u32> &getDimension() const; + irr::u32 getBitsPerPixel() const; + irr::u32 getBytesPerPixel() const; + irr::u32 getImageDataSizeInBytes() const; + irr::u32 getImageDataSizeInPixels() const; + irr::video::SColor getPixel(irr::u32 x, irr::u32 y) const; + void setPixel(irr::u32 x, irr::u32 y, const irr::video::SColor &color, + bool blend = false); + irr::video::ECOLOR_FORMAT getColorFormat() const; + irr::u32 getRedMask() const; + irr::u32 getGreenMask() const; + irr::u32 getBlueMask() const; + irr::u32 getAlphaMask() const; + irr::u32 getPitch() const; + void copyToScaling(void *target, irr::u32 width, irr::u32 height, + irr::video::ECOLOR_FORMAT format = irr::video::ECF_A8R8G8B8, + irr::u32 pitch = 0); + void copyToScaling(IImage *target); + void copyTo(IImage *target, + const irr::core::position2d<irr::s32> + &pos=irr::core::position2d<irr::s32>(0, 0)); + void copyTo(IImage *target, const irr::core::position2d<irr::s32> &pos, + const irr::core::rect<irr::s32> &sourceRect, + const irr::core::rect<irr::s32> *clipRect = nullptr); + void copyToWithAlpha(IImage* target, + const irr::core::position2d<irr::s32> &pos, + const irr::core::rect<irr::s32> &sourceRect, + const irr::video::SColor &color, + const irr::core::rect<irr::s32>* clipRect = 0); + void copyToScalingBoxFilter(IImage* target, irr::s32 bias = 0, + bool blend = false); + void fill(const irr::video::SColor &color); +}; + +#endif diff --git a/src/irrlicht/DTXImageLoader.cpp b/src/irrlicht/DTXImageLoader.cpp new file mode 100644 index 0000000..965cca7 --- /dev/null +++ b/src/irrlicht/DTXImageLoader.cpp @@ -0,0 +1,18 @@ +#include <DTXImageLoader.h> +#include <DTXImage.h> + +bool DTXImageLoader::isALoadableFileExtension(const irr::io::path &filename) + const +{ + return irr::core::hasFileExtension(filename, ".dtx"); +} + +bool DTXImageLoader::isALoadableFileFormat(irr::io::IReadFile *file) const +{ + return false; +} + +irr::video::IImage *DTXImageLoader::loadImage(irr::io::IReadFile *file) const +{ + return new DTXImage; +} diff --git a/src/irrlicht/DTXImageLoader.h b/src/irrlicht/DTXImageLoader.h new file mode 100644 index 0000000..7cd9a7e --- /dev/null +++ b/src/irrlicht/DTXImageLoader.h @@ -0,0 +1,13 @@ +#ifndef DTXIMAGELOADER_H +#define DTXIMAGELOADER_H + +#include <irrlicht.h> + +class DTXImageLoader : public irr::video::IImageLoader +{ + bool isALoadableFileExtension(const irr::io::path &filename) const; + bool isALoadableFileFormat(irr::io::IReadFile *file) const; + irr::video::IImage *loadImage(irr::io::IReadFile *file) const; +}; + +#endif diff --git a/src/irrlicht/RezArchive.cpp b/src/irrlicht/RezArchive.cpp new file mode 100644 index 0000000..8b9ff05 --- /dev/null +++ b/src/irrlicht/RezArchive.cpp @@ -0,0 +1,44 @@ +#include <RezArchive.h> +#include <RezReadFile.h> +#include <rez.h> +#include <memory> + +irr::io::IReadFile *RezArchive::createAndOpenFile(const irr::io::path &filename) +{ + std::unique_ptr<rez::file> f = rez.open(filename.c_str()); + + if (!f) + return nullptr; + + return new RezReadFile(std::move(f), filename); +} + +irr::io::IReadFile *RezArchive::createAndOpenFile(irr::u32 index) +{ + return nullptr; +} + +const irr::io::IFileList *RezArchive::getFileList() const +{ + return filelist.get(); +} + +irr::io::E_FILE_ARCHIVE_TYPE RezArchive::getType() const +{ + return static_cast<irr::io::E_FILE_ARCHIVE_TYPE> + (MAKE_IRR_ID('r', 'e', 'z', 0)); +} + +int RezArchive::parse() +{ + if (rez.parse()) + return -1; + + filelist = std::make_unique<RezFileList>(rez); + return 0; +} + +RezArchive::RezArchive(const irr::io::path &filename) : + rez(filename.c_str()) +{ +} diff --git a/src/irrlicht/RezArchive.h b/src/irrlicht/RezArchive.h new file mode 100644 index 0000000..442d80b --- /dev/null +++ b/src/irrlicht/RezArchive.h @@ -0,0 +1,24 @@ +#ifndef REZARCHIVE_H +#define REZARCHIVE_H + +#include <rez.h> +#include <RezFileList.h> +#include <irrlicht.h> +#include <memory> + +class RezArchive : public irr::io::IFileArchive +{ +public: + RezArchive(const irr::io::path &filename); + int parse(); + virtual irr::io::IReadFile *createAndOpenFile(const irr::io::path &filename); + virtual irr::io::IReadFile *createAndOpenFile(irr::u32 index); + virtual const irr::io::IFileList *getFileList() const; + virtual irr::io::E_FILE_ARCHIVE_TYPE getType() const; + +protected: + std::unique_ptr<RezFileList> filelist; + rez::ball rez; +}; + +#endif diff --git a/src/irrlicht/RezFileList.cpp b/src/irrlicht/RezFileList.cpp new file mode 100644 index 0000000..1932b85 --- /dev/null +++ b/src/irrlicht/RezFileList.cpp @@ -0,0 +1,143 @@ +#include <RezFileList.h> +#include <rez/dir.h> +#include <rez.h> +#include <iostream> + +static const irr::io::path s; + +irr::u32 RezFileList::getFileCount(const rez::dir &dir) const +{ + irr::u32 ret = 0; + + for (const auto &d : dir.entries()) + { + const auto &entry = d.second; + + if (std::holds_alternative<rez::dir>(entry)) + ret += getFileCount(std::get<rez::dir>(entry)); + else if (std::holds_alternative<rez::resource>(entry)) + ret++; + } + + return ret; +} + +irr::u32 RezFileList::getFileCount() const +{ + return getFileCount(rez.root()); +} + +const irr::io::path &RezFileList::getFileName(irr::u32 index) const +{ + return s; +} + +const irr::io::path &RezFileList::getFullFileName(irr::u32 index) const +{ + return s; +} + +irr::u32 RezFileList::getFileSize(irr::u32 index) const +{ + return 0; +} + +irr::u32 RezFileList::getFileOffset(irr::u32 index) const +{ + return 0; +} + +irr::u32 RezFileList::getID(irr::u32 index) const +{ + return 0; +} + +bool RezFileList::isDirectory(irr::u32 index) const +{ + if (index >= entries.size()) + return false; + + return std::holds_alternative<rez::dir>(*entries.at(index)); +} + +int RezFileList::findFile(const irr::io::path &filename, bool isFolder, + const rez::dir::direntry *entry) const +{ + if (std::holds_alternative<rez::resource>(*entry)) + { + const auto &resource = std::get<rez::resource>(*entry); + + if (resource.name() == filename.c_str()) + { + if (isFolder) + { + std::cerr << filename.c_str() << " expected to be a " + "directory, but is a file\n"; + return -1; + } + else + return 1; + } + } + else if (std::holds_alternative<rez::dir>(*entry) && isFolder) + { + const auto &dir = std::get<rez::dir>(*entry); + + if (dir.name() == filename.c_str()) + { + if (!isFolder) + { + std::cerr << filename.c_str() << " expected to be a " + "file, but is a directory\n"; + return -1; + } + else + return 1; + } + } + + return 0; +} + +irr::s32 RezFileList::findFile(const irr::io::path &filename, bool isFolder) + const +{ + for (irr::u32 i = 0; i < entries.size(); i++) + { + auto entry = entries.at(i); + int n = findFile(filename, isFolder, entry); + + if (n < 0) + return -1; + else if (n) + return i; + } + + const rez::dir::direntry *entry = rez.access(filename.c_str()); + + if (!entry || findFile(filename, isFolder, entry) <= 0) + return -1; + + entries.push_back(entry); + return entries.size() - 1; +} + +const irr::io::path &RezFileList::getPath() const +{ + return s; +} + +irr::u32 RezFileList::addItem(const irr::io::path &fullPath, irr::u32 offset, + irr::u32 size, bool isDirectory, irr::u32 id) +{ + return 0; +} + +void RezFileList::sort() +{ +} + +RezFileList::RezFileList(const rez::ball &rez) : + rez(rez) +{ +} diff --git a/src/irrlicht/RezFileList.h b/src/irrlicht/RezFileList.h new file mode 100644 index 0000000..a5ce077 --- /dev/null +++ b/src/irrlicht/RezFileList.h @@ -0,0 +1,35 @@ +#ifndef REZFILELIST_H +#define REZFILELIST_H + +#include <rez.h> +#include <irrlicht.h> +#include <vector> + +class RezFileList : public irr::io::IFileList +{ +public: + RezFileList(const rez::ball &rez); + virtual irr::u32 getFileCount() const; + virtual const irr::io::path &getFileName(irr::u32 index) const; + virtual const irr::io::path &getFullFileName(irr::u32 index) const; + virtual irr::u32 getFileSize(irr::u32 index) const; + virtual irr::u32 getFileOffset(irr::u32 index) const; + virtual irr::u32 getID(irr::u32 index) const; + virtual bool isDirectory(irr::u32 index) const; + virtual irr::s32 findFile(const irr::io::path &filename, bool isFolder) const; + virtual const irr::io::path &getPath() const; + virtual irr::u32 addItem(const irr::io::path& fullPath, irr::u32 offset, + irr::u32 size, bool isDirectory, irr::u32 id); + virtual void sort(); + +protected: + const rez::ball &rez; + +private: + irr::u32 getFileCount(const rez::dir &dir) const; + int findFile(const irr::io::path &filename, bool isFolder, + const rez::dir::direntry *entry) const; + mutable std::vector<const rez::dir::direntry *> entries; +}; + +#endif diff --git a/src/irrlicht/RezLoader.cpp b/src/irrlicht/RezLoader.cpp new file mode 100644 index 0000000..118a96d --- /dev/null +++ b/src/irrlicht/RezLoader.cpp @@ -0,0 +1,56 @@ +#include <RezLoader.h> +#include <RezArchive.h> +#include <rez.h> +#include <irrlicht.h> +#include <cstring> + +bool RezLoader::isALoadableFileFormat(const irr::io::path &filename) const +{ + return irr::core::hasFileExtension(filename, "rez"); +} + +bool RezLoader::isALoadableFileFormat(irr::io::IReadFile *file) const +{ + char buf[sizeof rez::ball::title], *p = buf; + size_t rem = sizeof buf; + + while (rem) + { + irr::s32 n = file->read(p, rem); + + if (n < 0) + return false; + + p += n; + rem -= n; + } + + return !strcmp(buf, rez::ball::title); +} + +bool RezLoader::isALoadableFileFormat(irr::io::E_FILE_ARCHIVE_TYPE fileType) const +{ + return fileType == static_cast<irr::io::E_FILE_ARCHIVE_TYPE> + (MAKE_IRR_ID('r', 'e', 'z', 0)); +} + +irr::io::IFileArchive *RezLoader::createArchive(const irr::io::path &filename, + bool ignoreCase, bool ignorePaths) const +{ + RezArchive *archive = new RezArchive(filename); + + if (archive->parse()) + { + delete archive; + return nullptr; + } + + return archive; +} + +irr::io::IFileArchive *RezLoader::createArchive(irr::io::IReadFile *file, + bool ignoreCase, bool ignorePaths) const +{ + // TODO: how to do that? + return nullptr; +} diff --git a/src/irrlicht/RezLoader.h b/src/irrlicht/RezLoader.h new file mode 100644 index 0000000..85a614d --- /dev/null +++ b/src/irrlicht/RezLoader.h @@ -0,0 +1,19 @@ +#ifndef REZLOADER_H +#define REZLOADER_H + +#include <irrlicht.h> + +class RezLoader : public irr::io::IArchiveLoader +{ +public: + virtual bool isALoadableFileFormat(const irr::io::path &filename) const; + virtual bool isALoadableFileFormat(irr::io::IReadFile *file) const; + virtual bool isALoadableFileFormat(irr::io::E_FILE_ARCHIVE_TYPE fileType) + const; + virtual irr::io::IFileArchive *createArchive(const irr::io::path &filename, + bool ignoreCase, bool ignorePaths) const; + virtual irr::io::IFileArchive *createArchive(irr::io::IReadFile *file, + bool ignoreCase, bool ignorePaths) const; +}; + +#endif diff --git a/src/irrlicht/RezReadFile.cpp b/src/irrlicht/RezReadFile.cpp new file mode 100644 index 0000000..ebeeebd --- /dev/null +++ b/src/irrlicht/RezReadFile.cpp @@ -0,0 +1,33 @@ +#include <RezReadFile.h> + +irr::s32 RezReadFile::read(void *buffer, irr::u32 sizeToRead) +{ + return f->read(buffer, sizeToRead); +} + +bool RezReadFile::seek(long finalPos, bool relativeMovement) +{ + return false; +} + +long RezReadFile::getSize() const +{ + return -1; +} + +long RezReadFile::getPos() const +{ + return f->tell(); +} + +const irr::io::path &RezReadFile::getFileName() const +{ + return filename; +} + +RezReadFile::RezReadFile(std::unique_ptr<rez::file> f, + const irr::io::path &filename) : + f(std::move(f)), + filename(filename) +{ +} diff --git a/src/irrlicht/RezReadFile.h b/src/irrlicht/RezReadFile.h new file mode 100644 index 0000000..892c396 --- /dev/null +++ b/src/irrlicht/RezReadFile.h @@ -0,0 +1,23 @@ +#ifndef REZREADFILE_H +#define REZREADFILE_H + +#include <rez/file.h> +#include <irrlicht.h> +#include <memory> + +class RezReadFile : public irr::io::IReadFile +{ +public: + RezReadFile(std::unique_ptr<rez::file> f, const irr::io::path &filename); + virtual irr::s32 read(void *buffer, irr::u32 sizeToRead); + virtual bool seek(long finalPos, bool relativeMovement); + virtual long getSize() const; + virtual long getPos() const; + virtual const irr::io::path &getFileName() const; + +private: + std::unique_ptr<rez::file> f; + irr::io::path filename; +}; + +#endif diff --git a/src/main.cpp b/src/main.cpp index 382cc93..bd4c243 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,71 +1,75 @@ -#define SDL_MAIN_HANDLED - -#include <abc.h> -#include <dtx.h> -#include <rez.h> -#include <GL/gl.h> -#include <osg/GLExtensions> -#include <osg/State> -#include <osgViewer/GraphicsWindow> -#include <osgViewer/Viewer> -#include <osgViewer/ViewerEventHandlers> +#include <RezLoader.h> +#include <irrlicht.h> #include <cstdlib> -#include <cstdio> #include <iostream> int main(int argc, char *argv[]) { - std::unique_ptr<rez::file> f, abcf; - rez::ball b("globalops.rez"); - abc abc; - dtx dtx; - osgViewer::Viewer viewer; - osg::Camera *cam; - osg::GraphicsContext *gfx; - osg::State *state; - osg::GLExtensions *ext; - osgViewer::GraphicsWindow *gfxw; + int ret = EXIT_FAILURE; + irr::IrrlichtDevice *device = irr::createDevice(irr::video::EDT_OPENGL); + irr::io::IFileSystem *fs; + irr::io::IFileArchive *archive; + irr::io::IReadFile *f = nullptr; + RezLoader rezloader; - viewer.setUpViewInWindow(0, 0, 640, 480); - viewer.realize(); - cam = viewer.getCamera(); - gfx = cam->getGraphicsContext(); - gfxw = dynamic_cast<osgViewer::GraphicsWindow *>(gfx); + if (!device) + { + std::cerr << "irr::createDevice failed\n"; + goto end; + } - if (!gfxw) + device->setWindowCaption(L"GlobalOps"); + archive = rezloader.createArchive("globalops.rez", true, false); + + if (!archive) { - std::cerr << "Failed to cast osgViewe::GraphicContext to " - "osgViewer::GraphicsWindow\n"; - return EXIT_FAILURE; + std::cerr << "Could not open globalops.rez\n"; + goto end; } - gfxw->setWindowName("GlobalOps"); - state = gfx->getState(); - state->initializeExtensionProcs(); - ext = osg::GLExtensions::Get(state->getContextID(), true); + fs = device->getFileSystem(); + fs->addFileArchive(archive); + fs->addArchiveLoader(&rezloader); + f = fs->createAndOpenFile("interface/blueprints/antarctica_tacmap.dtx"); + + if (!f) + goto end; +#if 0 + if (b.parse() + || !(f = b.open("interface/blueprints/antarctica_tacmap.dtx")) + || dtx.parse(*f) + || !(f = b.open("models/grenades/v_frag.abc")) + || abc.parse(*f)) + goto end; +#endif - if (!ext) + while (device->run()) { - std::cerr << "osg::GLExtensions::Get failed\n"; - return EXIT_FAILURE; + irr::video::IVideoDriver *driver = device->getVideoDriver(); + irr::scene::ISceneManager *smgr = device->getSceneManager(); + irr::gui::IGUIEnvironment *guienv = device->getGUIEnvironment(); + + driver->beginScene(); + smgr->drawAll(); + guienv->drawAll(); + driver->endScene(); } - else if (!ext->isCompressedTexImage2DSupported()) + + ret = EXIT_SUCCESS; + +end: + + if (f && !f->drop()) { - std::cerr << "OpenGL extension glCompressedTextImage2D not supported\n"; - return EXIT_FAILURE; + std::cerr << "irr::IReadFile::drop failed\n"; + ret = EXIT_FAILURE; } - else if (!ext->isTextureCompressionS3TCSupported) + + if (device && !device->drop()) { - std::cerr << "OpenGL extension GL_EXT_texture_compression_s3tc " - "not supported\n"; - return EXIT_FAILURE; + std::cerr << "irr::IrrlichtDevice::drop failed\n"; + ret = EXIT_FAILURE; } - else if (b.parse() - || !(f = b.open("interface/blueprints/antarctica_tacmap.dtx")) - || dtx.parse(*f) - || !(f = b.open("models/grenades/v_frag.abc")) - || abc.parse(*f)) - return EXIT_FAILURE; - return viewer.run(); + return ret; } diff --git a/src/rez/rez.cpp b/src/rez/rez.cpp index 2351c05..b8c22ce 100644 --- a/src/rez/rez.cpp +++ b/src/rez/rez.cpp @@ -18,12 +18,17 @@ std::string rez::ball::toupper(const std::string &s) const return ret; } -std::unique_ptr<rez::file> rez::ball::open(const char *path) +const rez::dir &rez::ball::root() const +{ + return root_dir; +} + +const rez::dir::direntry *rez::ball::access(const char *path) const { std::istringstream stream(path); std::string token; const rez::dir *dir = &root_dir; - const rez::resource *resource = nullptr; + const rez::dir::direntry *de = nullptr; while (std::getline(stream, token, '/')) { @@ -34,38 +39,41 @@ std::unique_ptr<rez::file> rez::ball::open(const char *path) if (it == map.end()) return nullptr; - const rez::dir::direntry &de = it->second; + de = &it->second; - if (std::holds_alternative<rez::dir>(de)) - dir = &std::get<rez::dir>(de); - else if (std::holds_alternative<rez::resource>(de)) - { + if (std::holds_alternative<rez::dir>(*de)) + dir = &std::get<rez::dir>(*de); + else if (std::holds_alternative<rez::resource>(*de)) dir = nullptr; - resource = &std::get<rez::resource>(de); - } } - if (dir) + return de; +} + +std::unique_ptr<rez::file> rez::ball::open(const char *path) +{ + const rez::dir::direntry *entry = access(path); + + if (!entry) { - std::cerr << path << " is a directory\n"; + std::cerr << io.path() << ": could not find " << path << '\n'; return nullptr; } - else if (!resource) + else if (std::holds_alternative<rez::dir>(*entry)) { - std::cerr << io.path() << ": could not find " << path << '\n'; + std::cerr << path << " is a directory\n"; return nullptr; } - return std::make_unique<rez::file>(*resource, io); + return std::make_unique<rez::file>(std::get<rez::resource>(*entry), io); } +const char rez::ball::title[127] = + "\r\nRezMgr Version 1 Copyright (C) 1995 MONOLITH INC. " + "\r\nLithTech Resource File \r\n"; + int rez::ball::parse() { - static const char title[63] = - "\r\nRezMgr Version 1 Copyright (C) 1995 MONOLITH INC. ", - subtitle[65] = - "\r\nLithTech Resource File \r\n"; - if (io.open()) return -1; else if (io.check(title)) @@ -73,11 +81,6 @@ int rez::ball::parse() std::cerr << path << ": wrong title\n"; return -1; } - else if (io.check(subtitle)) - { - std::cerr << path << ": wrong subtitle\n"; - return -1; - } else if (io.check(0x1a)) { std::cerr << path << ": wrong EOF\n"; diff --git a/src/rez/rez.h b/src/rez/rez.h index 5bbe206..6998d2b 100644 --- a/src/rez/rez.h +++ b/src/rez/rez.h @@ -15,7 +15,10 @@ class ball public: ball(const char *path); int parse(); + const rez::dir::direntry *access(const char *path) const; std::unique_ptr<rez::file> open(const char *path); + const rez::dir &root() const; + static const char title[127]; private: std::string toupper(const std::string &s) const; |
