Use tile buffers!

develop
Petr Mrázek 2012-03-05 02:24:02 +01:00
parent a45fc82743
commit f83db86258
3 changed files with 20 additions and 21 deletions

@ -679,7 +679,7 @@ bool Core::Init()
HotkeyCond = new condition_variable(); HotkeyCond = new condition_variable();
thread * HK = new thread(fHKthread, (void *) temp); thread * HK = new thread(fHKthread, (void *) temp);
screen_window = new Windows::top_level_window(); screen_window = new Windows::top_level_window();
screen_window->addChild(new Windows::dfhack_dummy(0,0)); screen_window->addChild(new Windows::dfhack_dummy(5,10));
started = true; started = true;
cerr << "DFHack is running.\n"; cerr << "DFHack is running.\n";
return true; return true;

@ -23,6 +23,7 @@ distribution.
*/ */
#pragma once #pragma once
#include "Export.h"
#include <cstddef> #include <cstddef>
namespace DFHack namespace DFHack
@ -67,14 +68,6 @@ namespace Windows
class df_window; class df_window;
struct df_tilebuf struct df_tilebuf
{ {
df_tilebuf(unsigned int width, unsigned int height):width(width),height(height)
{
data = new df_screentile[width*height];
}
~df_tilebuf()
{
delete data;
}
df_screentile * data; df_screentile * data;
unsigned int width; unsigned int width;
unsigned int height; unsigned int height;
@ -193,7 +186,7 @@ namespace Windows
virtual painter * lock(); virtual painter * lock();
bool unlock (painter * painter); bool unlock (painter * painter);
virtual bool addChild(df_window *); virtual bool addChild(df_window *);
virtual df_screentile * getBuffer() = 0; virtual df_tilebuf getBuffer() = 0;
public: public:
df_screentile* buffer; df_screentile* buffer;
unsigned int width; unsigned int width;
@ -215,7 +208,7 @@ namespace Windows
virtual bool move (int left_, int top_, unsigned int width_, unsigned int height_); virtual bool move (int left_, int top_, unsigned int width_, unsigned int height_);
virtual void paint (); virtual void paint ();
virtual painter * lock(); virtual painter * lock();
virtual df_screentile * getBuffer(); virtual df_tilebuf getBuffer();
}; };
class DFHACK_EXPORT buffered_window : public df_window class DFHACK_EXPORT buffered_window : public df_window
{ {
@ -230,24 +223,26 @@ namespace Windows
} }
virtual void blit_to_parent () virtual void blit_to_parent ()
{ {
df_screentile * parbuf = parent->getBuffer(); df_tilebuf par = parent->getBuffer();
int parent_width = parent->width;
int parent_height = parent->height;
for(int xi = 0; xi < width; xi++) for(int xi = 0; xi < width; xi++)
{ {
for(int yi = 0; yi < height; yi++) for(int yi = 0; yi < height; yi++)
{ {
int parx = left + xi; int parx = left + xi;
int pary = top + yi; int pary = top + yi;
if(pary >= parent_height) continue; if(pary >= par.height) continue;
if(parx >= parent_width) continue; if(parx >= par.width) continue;
parbuf[parx * parent_height + pary] = buffer[xi * height + yi]; par.data[parx * par.height + pary] = buffer[xi * height + yi];
} }
} }
} }
virtual df_screentile* getBuffer() virtual df_tilebuf getBuffer()
{ {
return buffer; df_tilebuf buf;
buf.data = buffer;
buf.width = width;
buf.height = height;
return buf;
}; };
}; };
class DFHACK_EXPORT dfhack_dummy : public buffered_window class DFHACK_EXPORT dfhack_dummy : public buffered_window

@ -108,7 +108,11 @@ void Windows::top_level_window::paint ()
} }
}; };
Windows::df_screentile * Windows::top_level_window::getBuffer() Windows::df_tilebuf Windows::top_level_window::getBuffer()
{ {
return getScreenBuffer(); df_tilebuf buf;
buf.data = getScreenBuffer();
buf.height = df::global::gps->dimy;
buf.width = df::global::gps->dimx;
return buf;
} }