2013-07-02 07:06:03 +01:00
|
|
|
#pragma once
|
2013-07-02 08:40:43 +02:00
|
|
|
#ifndef _LOADERDFF_HPP_
|
|
|
|
#define _LOADERDFF_HPP_
|
2013-07-02 07:06:03 +01:00
|
|
|
|
2017-01-04 21:08:21 +00:00
|
|
|
#include <data/Clump.hpp>
|
2016-12-03 20:58:03 +00:00
|
|
|
#include <gl/TextureData.hpp>
|
2016-04-07 01:13:46 +01:00
|
|
|
#include <loaders/RWBinaryStream.hpp>
|
2016-09-09 21:13:21 +01:00
|
|
|
#include <platform/FileHandle.hpp>
|
2016-12-03 20:58:03 +00:00
|
|
|
|
|
|
|
#include <functional>
|
2016-09-09 21:13:21 +01:00
|
|
|
#include <string>
|
2013-07-02 07:06:03 +01:00
|
|
|
|
2016-09-09 21:13:21 +01:00
|
|
|
class DFFLoaderException {
|
|
|
|
std::string _message;
|
2014-08-04 22:21:01 +01:00
|
|
|
|
2016-09-09 21:13:21 +01:00
|
|
|
public:
|
|
|
|
DFFLoaderException(const std::string& message) : _message(message) {
|
|
|
|
}
|
2014-08-04 22:21:01 +01:00
|
|
|
|
2016-09-09 21:13:21 +01:00
|
|
|
const std::string& which() {
|
|
|
|
return _message;
|
|
|
|
}
|
2014-08-04 22:21:01 +01:00
|
|
|
};
|
|
|
|
|
2016-09-09 21:13:21 +01:00
|
|
|
class LoaderDFF {
|
2013-07-02 07:06:03 +01:00
|
|
|
public:
|
2016-12-03 20:58:03 +00:00
|
|
|
using TextureLookupCallback = std::function<TextureData::Handle(
|
|
|
|
const std::string&, const std::string&)>;
|
2017-01-04 21:08:21 +00:00
|
|
|
using GeometryList = std::vector<GeometryPtr>;
|
|
|
|
using FrameList = std::vector<ModelFramePtr>;
|
2016-12-03 20:58:03 +00:00
|
|
|
|
rwlib: Use ClumpPtr instead of Clump*
Should fix these memory leaks:
==22737== 14,598,040 (131,472 direct, 14,466,568 indirect) bytes in 2,739 blocks are definitely lost in loss record 3,124 of 3,126
==22737== at 0x4C2F1CA: operator new(unsigned long) (vg_replace_malloc.c:334)
==22737== by 0x90FE4B: LoaderDFF::loadFromMemory(std::shared_ptr<FileContentsInfo>) (LoaderDFF.cpp:443)
==22737== by 0x7BCC86: GameData::loadModel(unsigned short) (GameData.cpp:474)
==22737== by 0x7DF7BC: GameWorld::createInstance(unsigned short, glm::tvec3<float, (glm::precision)0> const&, glm::tquat<float, (glm::precision)0> const&) (GameWorld.cpp:144)
==22737== by 0x7DF44C: GameWorld::placeItems(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) (GameWorld.cpp:120)
==22737== by 0x758D38: RWGame::newGame() (RWGame.cpp:116)
==22737== by 0x786389: LoadingState::enter() (LoadingState.cpp:9)
==22737== by 0x75DC59: void StateManager::enter<LoadingState, RWGame*, RWGame::RWGame(Logger&, int, char**)::{lambda()#1}>(RWGame*&&, RWGame::RWGame(Logger&, int, char**)::{lambda()#1}&&) (StateManager.hpp:40)
==22737== by 0x758484: RWGame::RWGame(Logger&, int, char**) (RWGame.cpp:81)
==22737== by 0x747815: main (main.cpp:13)
2017-09-13 00:47:22 +02:00
|
|
|
ClumpPtr loadFromMemory(FileHandle file);
|
2016-12-03 20:58:03 +00:00
|
|
|
|
|
|
|
void setTextureLookupCallback(TextureLookupCallback tlc) {
|
|
|
|
texturelookup = tlc;
|
|
|
|
}
|
2017-01-04 21:08:21 +00:00
|
|
|
|
2016-12-03 20:58:03 +00:00
|
|
|
private:
|
|
|
|
TextureLookupCallback texturelookup;
|
2017-01-04 21:08:21 +00:00
|
|
|
|
|
|
|
FrameList readFrameList(const RWBStream& stream);
|
|
|
|
|
|
|
|
GeometryList readGeometryList(const RWBStream& stream);
|
|
|
|
|
|
|
|
GeometryPtr readGeometry(const RWBStream& stream);
|
|
|
|
|
|
|
|
void readMaterialList(GeometryPtr& geom, const RWBStream& stream);
|
|
|
|
|
|
|
|
void readMaterial(GeometryPtr& geom, const RWBStream& stream);
|
|
|
|
|
|
|
|
void readTexture(Geometry::Material& material, const RWBStream& stream);
|
|
|
|
|
|
|
|
void readGeometryExtension(GeometryPtr& geom, const RWBStream& stream);
|
|
|
|
|
|
|
|
void readBinMeshPLG(GeometryPtr& geom, const RWBStream& stream);
|
|
|
|
|
|
|
|
AtomicPtr readAtomic(FrameList& framelist, GeometryList& geometrylist,
|
|
|
|
const RWBStream& stream);
|
2014-06-04 11:53:11 +01:00
|
|
|
};
|
|
|
|
|
2013-07-24 01:44:08 +01:00
|
|
|
#endif
|