1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
#pragma once
#include "inode.h"
#include "imapexporter.h"
#include "imapformat.h"
#include "imap.h"
#include "igame.h"
#include "../infofile/InfoFileExporter.h"
#include "EventRateLimiter.h"
#include <sigc++/signal.h>
namespace map
{
/**
* Walker class which passes the visited scene nodes to the
* attached MapExporter class, for writing it to the given
* string output stream. The exporter is using a IMapWriter class
* to dispatch various calls like beginWriteEntity(),
* beginMap(), endWriteBrush() during scene traversal etc.
*
* If the progress dialog is enabled (i.e. nodeCount > 0 in constructor)
* a gtkutil::OperationAbortedException& might be thrown during traversal,
* the calling code needs to be able to handle that.
*/
class MapExporter :
public IMapExporter,
public scene::NodeVisitor
{
private:
// For writing nodes to the stream
IMapWriter& _writer;
// The stream we're writing to
std::ostream& _mapStream;
// Optional info file exporter (is NULL if no info file should be written)
InfoFileExporterPtr _infoFileExporter;
// The root node of the subgraph to be exported
scene::IMapRootNodePtr _root;
// Event rate limiter for the progress dialog
EventRateLimiter _dialogEventLimiter;
// The total number, used for progress measurement
std::size_t _totalNodeCount;
std::size_t _curNodeCount;
// Counters which will be passed to the InfoFileExporter
std::size_t _entityNum;
std::size_t _primitiveNum;
bool _sendProgressMessages;
public:
// The constructor prepares the scene and the output stream
MapExporter(IMapWriter& writer, const scene::IMapRootNodePtr& root,
std::ostream& mapStream, std::size_t nodeCount = 0);
// Additional constructor allowed to write to the auxiliary .darkradiant file
MapExporter(IMapWriter& writer, const scene::IMapRootNodePtr& root,
std::ostream& mapStream, std::ostream& auxStream, std::size_t nodeCount = 0);
// Cleans up the scene on destruction
~MapExporter();
// Entry point for traversing the given root node using the given traversal function
void exportMap(const scene::INodePtr& root, const GraphTraversalFunc& traverse) override;
// NodeVisitor implementation, is called by the traversal func passed to MapResource
bool pre(const scene::INodePtr& node) override;
void post(const scene::INodePtr& node) override;
// Send FileProgress messages through the MessageBus while exporting
void enableProgressMessages();
// Don't send any progress messages through the MessageBus while exporting
void disableProgressMessages();
private:
// Common code shared by the constructors
void construct();
void onNodeProgress();
// Is called before exporting the scene to prepare func_* groups.
void prepareScene();
// Called after all the writing has been performed, cleans up func_* groups
void finishScene();
void recalculateBrushWindings();
};
typedef std::shared_ptr<MapExporter> MapExporterPtr;
} // namespace
|