mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-19 19:39:41 +00:00
Cleaned up superflous functions in BSA archive. Started working on input system.
This commit is contained in:
parent
86b78b18f4
commit
d5228c6f5f
9 changed files with 145 additions and 69 deletions
|
@ -48,8 +48,7 @@ public:
|
|||
void load() {}
|
||||
void unload() {}
|
||||
|
||||
// Open a file in the archive.
|
||||
DataStreamPtr open(const String& filename) const
|
||||
DataStreamPtr open(const String& filename, bool recursive = true) const
|
||||
{
|
||||
// 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
|
||||
|
@ -64,6 +63,10 @@ public:
|
|||
return DataStreamPtr(new Mangle2OgreStream(strm));
|
||||
}
|
||||
|
||||
// Check if the file exists.
|
||||
bool exists(const String& filename) { return arc.exists(filename.c_str()); }
|
||||
time_t getModifiedTime(const String&) { return 0; }
|
||||
|
||||
// This is never called as far as I can see.
|
||||
StringVectorPtr list(bool recursive = true, bool dirs = false)
|
||||
{
|
||||
|
@ -71,6 +74,7 @@ public:
|
|||
StringVectorPtr ptr = StringVectorPtr(new StringVector());
|
||||
return ptr;
|
||||
}
|
||||
|
||||
// Also never called.
|
||||
FileInfoListPtr listFileInfo(bool recursive = true, bool dirs = false)
|
||||
{
|
||||
|
@ -79,8 +83,6 @@ public:
|
|||
return ptr;
|
||||
}
|
||||
|
||||
time_t getModifiedTime(const String&) { return 0; }
|
||||
|
||||
// After load() is called, find("*") is called once. It doesn't seem
|
||||
// to matter that we return an empty list, exists() gets called on
|
||||
// the correct files anyway.
|
||||
|
@ -104,11 +106,6 @@ public:
|
|||
FileInfoListPtr findFileInfo(const String& pattern, bool recursive = true,
|
||||
bool dirs = false)
|
||||
{
|
||||
/*
|
||||
std::cout << "findFileInfo(" << pattern << ", " << recursive
|
||||
<< ", " << dirs << ")\n";
|
||||
*/
|
||||
|
||||
FileInfoListPtr ptr = FileInfoListPtr(new FileInfoList());
|
||||
|
||||
// Check if the file exists (only works for single files - wild
|
||||
|
@ -128,66 +125,6 @@ public:
|
|||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
// Check if the file exists.
|
||||
bool exists(const String& filename) { return arc.exists(filename.c_str()); }
|
||||
|
||||
// Fill out all types of virtual members from Ogre framework
|
||||
StringVectorPtr list(bool recursive = true)
|
||||
{
|
||||
StringVectorPtr ptr = StringVectorPtr(new StringVector());
|
||||
return ptr;
|
||||
}
|
||||
|
||||
StringVectorPtr find(const String& pattern, bool recursive = true)
|
||||
{
|
||||
StringVectorPtr ptr = StringVectorPtr(new StringVector());
|
||||
return ptr;
|
||||
}
|
||||
|
||||
FileInfoListPtr listFileInfo(bool recursive = true)
|
||||
{
|
||||
FileInfoListPtr ptr = FileInfoListPtr(new FileInfoList());
|
||||
return ptr;
|
||||
}
|
||||
|
||||
FileInfoListPtr findFileInfo(const String& pattern, bool recursive = true)
|
||||
{
|
||||
FileInfoListPtr ptr = FileInfoListPtr(new FileInfoList());
|
||||
|
||||
// Check if the file exists (only works for single files - wild
|
||||
// cards and recursive search isn't implemented.)
|
||||
if(exists(pattern)) {
|
||||
FileInfo fi;
|
||||
fi.archive = this;
|
||||
fi.filename = pattern;
|
||||
// It apparently doesn't matter that we return bogus
|
||||
// information
|
||||
fi.path = "";
|
||||
fi.compressedSize = fi.uncompressedSize = 0;
|
||||
|
||||
ptr->push_back(fi);
|
||||
}
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
DataStreamPtr open(const String& filename, bool recursive = true) const
|
||||
{
|
||||
// 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));
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
// An archive factory for BSA archives
|
||||
|
|
|
@ -12,6 +12,10 @@
|
|||
loading code. Cutting down dependencies also help on the general
|
||||
maintainability.
|
||||
|
||||
TODO FIXME: Cleanup. The RecLists store pointers to new'd objects,
|
||||
but these are never deleted anywhere. Right now this data is
|
||||
persistant through the application lifetime so it doesn't matter,
|
||||
but fix it later.
|
||||
*/
|
||||
|
||||
#include "esm/records.hpp"
|
||||
|
|
|
@ -11,6 +11,7 @@ namespace Render
|
|||
rendering objects from the given cell into the given rendering
|
||||
scene.
|
||||
|
||||
TODO FIXME: Doesn't do full cleanup yet.
|
||||
*/
|
||||
class CellRender
|
||||
{
|
||||
|
|
2
input/tests/.gitignore
vendored
Normal file
2
input/tests/.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
*_test
|
||||
|
9
input/tests/Makefile
Normal file
9
input/tests/Makefile
Normal file
|
@ -0,0 +1,9 @@
|
|||
GCC=g++
|
||||
|
||||
all: funcbind_test
|
||||
|
||||
funcbind_test: funcbind_test.cpp
|
||||
$(GCC) $^ -o $@
|
||||
|
||||
clean:
|
||||
rm *_test
|
84
input/tests/funcbind_test.cpp
Normal file
84
input/tests/funcbind_test.cpp
Normal file
|
@ -0,0 +1,84 @@
|
|||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <boost/function.hpp>
|
||||
#include <assert.h>
|
||||
|
||||
typedef boost::function<void()> Action;
|
||||
|
||||
struct FuncBind
|
||||
{
|
||||
std::string name;
|
||||
Action action;
|
||||
};
|
||||
|
||||
class Binder
|
||||
{
|
||||
std::vector<FuncBind> bindings;
|
||||
|
||||
public:
|
||||
/**
|
||||
Initialize the struct by telling it how many functions you have
|
||||
to bind. The largest index you intend to use should be number-1.
|
||||
*/
|
||||
Binder(int number) : bindings(number) {}
|
||||
|
||||
void bind(int index, Action action, const std::string &name="")
|
||||
{
|
||||
assert(index >= 0 && index < bindings.size());
|
||||
FuncBind &fb = bindings[index];
|
||||
fb.action = action;
|
||||
fb.name = name;
|
||||
}
|
||||
|
||||
void unbind(int index)
|
||||
{
|
||||
assert(index >= 0 && index < bindings.size());
|
||||
FuncBind &fb = bindings[index];
|
||||
fb = FuncBind();
|
||||
}
|
||||
|
||||
void call(int index)
|
||||
{
|
||||
assert(index >= 0 && index < bindings.size());
|
||||
FuncBind &fb = bindings[index];
|
||||
if(fb.action)
|
||||
{
|
||||
cout << "Calling '" << fb.name << "'\n";
|
||||
fb.action();
|
||||
}
|
||||
else
|
||||
cout << "No function\n";
|
||||
}
|
||||
};
|
||||
|
||||
void f1()
|
||||
{
|
||||
cout << "In f1()\n";
|
||||
}
|
||||
|
||||
void f2()
|
||||
{
|
||||
cout << "In f2()\n";
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
cout << "This will test the function binding system\n";
|
||||
|
||||
Binder bnd(5);
|
||||
|
||||
bnd.bind(0, &f1, "This is action 1");
|
||||
bnd.bind(1, &f2);
|
||||
bnd.bind(2, &f1, "This is action 3");
|
||||
|
||||
for(int i=0; i<5; i++)
|
||||
{
|
||||
cout << "\nCalling " << i << endl;
|
||||
bnd.call(i);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
19
input/tests/output/funcbind_test.out
Normal file
19
input/tests/output/funcbind_test.out
Normal file
|
@ -0,0 +1,19 @@
|
|||
This will test the function binding system
|
||||
|
||||
Calling 0
|
||||
Calling 'This is action 1'
|
||||
In f1()
|
||||
|
||||
Calling 1
|
||||
Calling ''
|
||||
In f2()
|
||||
|
||||
Calling 2
|
||||
Calling 'This is action 3'
|
||||
In f1()
|
||||
|
||||
Calling 3
|
||||
No function
|
||||
|
||||
Calling 4
|
||||
No function
|
18
input/tests/test.sh
Executable file
18
input/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
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
function run()
|
||||
{
|
||||
echo
|
||||
echo "$1/tests/:"
|
||||
cd "$1/tests/"
|
||||
./test.sh
|
||||
|
@ -9,6 +10,7 @@ function run()
|
|||
}
|
||||
|
||||
run tools
|
||||
run input
|
||||
run bsa
|
||||
run nif
|
||||
run nifogre
|
||||
|
|
Loading…
Reference in a new issue