Don't use globals

develop
Japa 2018-01-26 08:19:41 +05:30
parent ef451a2f2d
commit e3d95daf45
4 changed files with 15 additions and 7 deletions

@ -1 +1 @@
Subproject commit 618db6349ece5827d371a60b0fac1066b1d7989b Subproject commit 9afe7c9538f1bfa104c5eff54b0945eee32a76cc

@ -1,4 +1,6 @@
#include "item_reader.h" #include "item_reader.h"
#include "Core.h"
#include "VersionInfo.h"
#include "df/art_image.h" #include "df/art_image.h"
#include "df/art_image_chunk.h" #include "df/art_image_chunk.h"
@ -104,9 +106,9 @@ void CopyImage(const df::art_image * image, ArtImage * netImage)
void CopyImage(df::art_image_ref imageRef, ArtImage * netImage) void CopyImage(df::art_image_ref imageRef, ArtImage * netImage)
{ {
if (df::global::getArtImage) GET_IMAGE getImage = reinterpret_cast<GET_IMAGE>(Core::getInstance().vinfo->getAddress("rfr_get_art_image"));
if (getImage)
{ {
df::art_image * (__thiscall *getImage)(df::world*, df::art_image_ref *, int *) = (df::art_image * (__thiscall*)(df::world*, df::art_image_ref *, int *))df::global::getArtImage;
int subid = -1; int subid = -1;
CopyImage(getImage(world, &imageRef, &subid), netImage); CopyImage(getImage(world, &imageRef, &subid), netImage);
} }

@ -11,6 +11,9 @@ namespace df
{ {
struct item; struct item;
struct map_block; struct map_block;
struct art_image;
struct art_image_ref;
struct world;
} }
namespace MapExtras namespace MapExtras
@ -22,4 +25,6 @@ DFHack::command_result GetItemList(DFHack::color_ostream &stream, const DFHack::
void CopyItem(RemoteFortressReader::Item * NetItem, df::item * DfItem); void CopyItem(RemoteFortressReader::Item * NetItem, df::item * DfItem);
void ConvertDFColorDescriptor(int16_t index, RemoteFortressReader::ColorDefinition * out); void ConvertDFColorDescriptor(int16_t index, RemoteFortressReader::ColorDefinition * out);
typedef df::art_image * (__thiscall *GET_IMAGE)(df::world*, df::art_image_ref *, int *);
#endif // !ITEM_READER_H #endif // !ITEM_READER_H

@ -17,6 +17,7 @@
#include "SDL_events.h" #include "SDL_events.h"
#include "SDL_keyboard.h" #include "SDL_keyboard.h"
#include "TileTypes.h" #include "TileTypes.h"
#include "VersionInfo.h"
#if DF_VERSION_INT > 34011 #if DF_VERSION_INT > 34011
#include "DFHackVersion.h" #include "DFHackVersion.h"
#endif #endif
@ -191,9 +192,9 @@ command_result generate_image(color_ostream &out, vector <string> & parameters)
imageRef.site_id = -1; imageRef.site_id = -1;
imageRef.subid = -1; imageRef.subid = -1;
if (df::global::getArtImage) GET_IMAGE getImage = reinterpret_cast<GET_IMAGE>(Core::getInstance().vinfo->getAddress("rfr_get_art_image"));
if (getImage)
{ {
df::art_image * (__thiscall *getImage)(df::world*,df::art_image_ref *, int *) = (df::art_image * (__thiscall*)(df::world*, df::art_image_ref *, int *))df::global::getArtImage;
int subid = -1; int subid = -1;
auto image = getImage(world,&imageRef, &subid); auto image = getImage(world,&imageRef, &subid);
out.print("Id: %d, subid: %d\n", image->id, image->subid); out.print("Id: %d, subid: %d\n", image->id, image->subid);