mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-15 18:39:51 +00:00
Tested and fixed BSA archive loader for Ogre, added test script
This commit is contained in:
parent
1779dc1f7c
commit
310e3a8038
@ -30,7 +30,12 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <OgreArchive.h>
|
#include <OgreArchive.h>
|
||||||
|
#include <OgreArchiveFactory.h>
|
||||||
#include "bsa_file.h"
|
#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
|
/// An OGRE Archive wrapping a BSAFile archive
|
||||||
class BSAArchive : public Archive
|
class BSAArchive : public Archive
|
||||||
@ -51,8 +56,17 @@ public:
|
|||||||
// Open a file in the archive.
|
// Open a file in the archive.
|
||||||
DataStreamPtr open(const String& filename) const
|
DataStreamPtr open(const String& filename) const
|
||||||
{
|
{
|
||||||
// Open the file, and wrap it into an Ogre::DataStream.
|
// Get a non-const reference to arc. This is a hack and it's all
|
||||||
return DataStreamPtr(new MangleDataStream(getFile(filename.c_str()));
|
// 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.
|
// This is never called as far as I can see.
|
||||||
@ -128,8 +142,6 @@ public:
|
|||||||
class BSAArchiveFactory : public ArchiveFactory
|
class BSAArchiveFactory : public ArchiveFactory
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~BSAArchiveFactory() {}
|
|
||||||
|
|
||||||
const String& getType() const
|
const String& getType() const
|
||||||
{
|
{
|
||||||
static String name = "BSA";
|
static String name = "BSA";
|
||||||
|
@ -1,10 +1,16 @@
|
|||||||
GCC=g++
|
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
|
bsa_file_test: bsa_file_test.cpp ../bsa_file.cpp
|
||||||
$(GCC) $^ -o $@
|
$(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
|
bsatool: bsatool.cpp ../bsa_file.cpp bsatool_cmd.c
|
||||||
$(GCC) $^ -o $@
|
$(GCC) $^ -o $@
|
||||||
|
|
||||||
|
38
bsa/tests/ogre_archive_test.cpp
Normal file
38
bsa/tests/ogre_archive_test.cpp
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
#include <Ogre.h>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
}
|
17
bsa/tests/output/bsa_file_test.out
Normal file
17
bsa/tests/output/bsa_file_test.out
Normal file
@ -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.
|
2
bsa/tests/output/ogre_archive_test.out
Normal file
2
bsa/tests/output/ogre_archive_test.out
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
Opening file: textures\tx_natural_cavern_wall13.dds
|
||||||
|
Size: 43808
|
18
bsa/tests/test.sh
Executable file
18
bsa/tests/test.sh
Executable file
@ -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
|
Loading…
x
Reference in New Issue
Block a user