simplify Graphic module. update structures.

it appears that all this added complexity including an extra pointer dereference was to avoid including the vector header.
develop
Ben Lubar 2020-03-08 00:12:48 -06:00
parent c4e9c8d29c
commit ffb3c29cfc
No known key found for this signature in database
GPG Key ID: 92939677AB59EDA4
3 changed files with 11 additions and 31 deletions

@ -33,6 +33,7 @@ distribution.
#include <stdint.h>
#include "Export.h"
#include "Module.h"
#include <vector>
namespace DFHack
{
@ -71,8 +72,6 @@ namespace DFHack
class DFHACK_EXPORT Graphic : public Module
{
public:
Graphic();
~Graphic();
bool Finish()
{
return true;
@ -82,8 +81,7 @@ namespace DFHack
DFTileSurface* Call(int x, int y);
private:
struct Private;
Private *d;
std::vector<DFTileSurface* (*)(int, int)> funcs;
};
}

@ -47,40 +47,22 @@ std::unique_ptr<Module> DFHack::createGraphic()
return dts::make_unique<Graphic>();
}
struct Graphic::Private
{
bool Started;
vector<DFTileSurface* (*)(int,int)> funcs;
};
Graphic::Graphic()
{
d = new Private;
d->Started = true;
}
Graphic::~Graphic()
{
delete d;
}
bool Graphic::Register(DFTileSurface* (*func)(int,int))
{
d->funcs.push_back(func);
funcs.push_back(func);
return true;
}
bool Graphic::Unregister(DFTileSurface* (*func)(int,int))
{
if ( d->funcs.empty() ) return false;
if ( funcs.empty() ) return false;
vector<DFTileSurface* (*)(int,int)>::iterator it = d->funcs.begin();
while ( it != d->funcs.end() )
vector<DFTileSurface* (*)(int,int)>::iterator it = funcs.begin();
while ( it != funcs.end() )
{
if ( *it == func )
{
d->funcs.erase(it);
funcs.erase(it);
return true;
}
it++;
@ -92,12 +74,12 @@ bool Graphic::Unregister(DFTileSurface* (*func)(int,int))
// This will return first DFTileSurface it can get (or NULL if theres none)
DFTileSurface* Graphic::Call(int x, int y)
{
if ( d->funcs.empty() ) return NULL;
if ( funcs.empty() ) return NULL;
DFTileSurface* temp = NULL;
vector<DFTileSurface* (*)(int,int)>::iterator it = d->funcs.begin();
while ( it != d->funcs.end() )
vector<DFTileSurface* (*)(int,int)>::iterator it = funcs.begin();
while ( it != funcs.end() )
{
temp = (*it)(x,y);
if ( temp != NULL )

@ -1 +1 @@
Subproject commit 8038cc692370471aa1151f81cdc621ac310f30e2
Subproject commit b3016446e60f69d43a9f41e7b2ba4331df14b5e6