From 310e3a8038188dd0bb1bee31fa63ec42e4ed0ed0 Mon Sep 17 00:00:00 2001 From: Nicolay Korslund Date: Sat, 2 Jan 2010 14:04:31 +0100 Subject: [PATCH] Tested and fixed BSA archive loader for Ogre, added test script --- bsa/bsa_archive.cpp | 20 +++++++++++--- bsa/tests/Makefile | 8 +++++- bsa/tests/ogre_archive_test.cpp | 38 ++++++++++++++++++++++++++ bsa/tests/output/bsa_file_test.out | 17 ++++++++++++ bsa/tests/output/ogre_archive_test.out | 2 ++ bsa/tests/test.sh | 18 ++++++++++++ 6 files changed, 98 insertions(+), 5 deletions(-) create mode 100644 bsa/tests/ogre_archive_test.cpp create mode 100644 bsa/tests/output/bsa_file_test.out create mode 100644 bsa/tests/output/ogre_archive_test.out create mode 100755 bsa/tests/test.sh diff --git a/bsa/bsa_archive.cpp b/bsa/bsa_archive.cpp index 34c2bd85b..2b04177d0 100644 --- a/bsa/bsa_archive.cpp +++ b/bsa/bsa_archive.cpp @@ -30,7 +30,12 @@ */ #include +#include #include "bsa_file.h" +#include "../mangle/stream/clients/ogre_datastream.h" + +using namespace Ogre; +using namespace Mangle::Stream; /// An OGRE Archive wrapping a BSAFile archive class BSAArchive : public Archive @@ -51,8 +56,17 @@ public: // Open a file in the archive. DataStreamPtr open(const String& filename) const { - // Open the file, and wrap it into an Ogre::DataStream. - return DataStreamPtr(new MangleDataStream(getFile(filename.c_str())); + // Get a non-const reference to arc. This is a hack and it's all + // OGRE's fault. You should NOT expect an open() command not to + // have any side effects on the archive, and hence this function + // should not have been declared const in the first place. + BSAFile *narc = (BSAFile*)&arc; + + // Open the file + StreamPtr strm = narc->getFile(filename.c_str()); + + // Wrap it into an Ogre::DataStream. + return DataStreamPtr(new Mangle2OgreStream(strm)); } // This is never called as far as I can see. @@ -128,8 +142,6 @@ public: class BSAArchiveFactory : public ArchiveFactory { public: - virtual ~BSAArchiveFactory() {} - const String& getType() const { static String name = "BSA"; diff --git a/bsa/tests/Makefile b/bsa/tests/Makefile index 6e1db734f..483f0c336 100644 --- a/bsa/tests/Makefile +++ b/bsa/tests/Makefile @@ -1,10 +1,16 @@ GCC=g++ -all: bsa_file_test bsatool +all: bsa_file_test bsatool ogre_archive_test + +I_OGRE=$(shell pkg-config --cflags OGRE) +L_OGRE=$(shell pkg-config --libs OGRE) bsa_file_test: bsa_file_test.cpp ../bsa_file.cpp $(GCC) $^ -o $@ +ogre_archive_test: ogre_archive_test.cpp ../bsa_file.cpp + $(GCC) $^ -o $@ $(I_OGRE) $(L_OGRE) + bsatool: bsatool.cpp ../bsa_file.cpp bsatool_cmd.c $(GCC) $^ -o $@ diff --git a/bsa/tests/ogre_archive_test.cpp b/bsa/tests/ogre_archive_test.cpp new file mode 100644 index 000000000..09db3accc --- /dev/null +++ b/bsa/tests/ogre_archive_test.cpp @@ -0,0 +1,38 @@ +#include +#include + +// This is a test of the BSA archive handler for OGRE. + +#include "../bsa_archive.cpp" + +using namespace Ogre; +using namespace std; + +int main() +{ + // Disable Ogre logging + new LogManager; + Log *log = LogManager::getSingleton().createLog(""); + log->setDebugOutputEnabled(false); + + // Set up Root + Root *root = new Root("","",""); + + // Add the archive manager + ArchiveManager::getSingleton().addArchiveFactory( new BSAArchiveFactory ); + + // Add Morrowind.bsa + ResourceGroupManager::getSingleton(). + addResourceLocation("../../data/Morrowind.bsa", "BSA", "General"); + + // Pick a sample file + String tex = "textures\\tx_natural_cavern_wall13.dds"; + cout << "Opening file: " << tex << endl; + + // Get it from the resource system + DataStreamPtr data = ResourceGroupManager::getSingleton().openResource(tex, "General"); + + cout << "Size: " << data->size() << endl; + + return 0; +} diff --git a/bsa/tests/output/bsa_file_test.out b/bsa/tests/output/bsa_file_test.out new file mode 100644 index 000000000..31b73c794 --- /dev/null +++ b/bsa/tests/output/bsa_file_test.out @@ -0,0 +1,17 @@ +Reading Morrowind.bsa +First 10 files in archive: + meshes\m\probe_journeyman_01.nif (6276 bytes @126646784) + textures\menu_rightbuttonup_top.dds (256 bytes @218533676) + textures\menu_rightbuttonup_right.dds (256 bytes @218533420) + textures\menu_rightbuttonup_left.dds (256 bytes @218533164) + textures\menu_rightbuttondown_top.dds (256 bytes @218531820) + meshes\b\b_n_redguard_f_skins.nif (41766 bytes @17810510) + meshes\b\b_n_redguard_m_skins.nif (41950 bytes @18103839) + meshes\b\b_n_redguard_f_wrist.nif (2355 bytes @17858864) + meshes\b\b_n_redguard_m_foot.nif (4141 bytes @17862813) + meshes\b\b_n_redguard_m_knee.nif (2085 bytes @18098833) +Does file 'meshes\r\xnetch_betty.nif' exist? + Yes. + 53714 bytes +Does file 'humdrum' exist? + No. diff --git a/bsa/tests/output/ogre_archive_test.out b/bsa/tests/output/ogre_archive_test.out new file mode 100644 index 000000000..748e4b1e7 --- /dev/null +++ b/bsa/tests/output/ogre_archive_test.out @@ -0,0 +1,2 @@ +Opening file: textures\tx_natural_cavern_wall13.dds +Size: 43808 diff --git a/bsa/tests/test.sh b/bsa/tests/test.sh new file mode 100755 index 000000000..b1ca6f1a6 --- /dev/null +++ b/bsa/tests/test.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +make || exit + +mkdir -p output + +PROGS=*_test + +for a in $PROGS; do + if [ -f "output/$a.out" ]; then + echo "Running $a:" + $a | diff output/$a.out - + else + echo "Creating $a.out" + $a > "output/$a.out" + git add "output/$a.out" + fi +done