Don't take over console in TEXT mode.

develop
Petr Mrázek 2011-08-01 03:31:52 +02:00
parent a36d8b0619
commit 331ada8f91
12 changed files with 138 additions and 45 deletions

@ -806,6 +806,7 @@
<Address name="interface" description="Pointer to the global interfacest object (gview symbol on Linux)."/>
<Address name="current_menu_state" description="A numeric value that describes the state of the current GUI element (switching between menus will change this)."/>
<Address name="hotkeys" description="Address where the array of hotkeys starts." />
<Address name="init" description="Address with the init.txt structure." />
</Group>
<Group name="Maps" description="Offsets used by the Maps module.">
<Address name="map_data" description="Pointer to the start of the map structure."/>
@ -3055,6 +3056,7 @@
<Address name="hotkeys" value="0x93f740c" />
<Address name="interface" value="0x8C3E900" />
<Address name="current_menu_state" value="0x93F756C" />
<Address name="init" value="0x959C2A0" />
</Group>
<Group name="Creatures">
Maybe, possibly.

@ -601,7 +601,7 @@ Console::Console():std::ostream(0), std::ios(0)
d = 0;
inited = false;
// we can't create the mutex at this time. the SDL functions aren't hooked yet.
wlock = 0;
wlock = new mutex();
}
Console::~Console()
{
@ -613,12 +613,18 @@ Console::~Console()
delete d;
}
bool Console::init(void)
bool Console::init(bool sharing)
{
if(sharing)
{
inited = false;
return false;
}
freopen("stdout.log", "w", stdout);
freopen("stderr.log", "w", stderr);
d = new Private();
// make our own weird streams so our IO isn't redirected
d->dfout_C = fopen("/dev/tty", "w");
wlock = new mutex();
rdbuf(d);
std::cin.tie(this);
clear();
@ -628,6 +634,8 @@ bool Console::init(void)
bool Console::shutdown(void)
{
if(!d)
return true;
lock_guard <mutex> g(*wlock);
if(d->rawmode)
d->disable_raw();

@ -387,11 +387,24 @@ bool Core::Init()
{
if(started)
return true;
// init the console. This must be always the first step!
con.init();
// find out what we are...
vif = new DFHack::VersionInfoFactory("Memory.xml");
p = new DFHack::Process(vif);
vinfo = p->getDescriptor();
// init the console.
Gui * g = getGui();
if(g->init)
{
if(g->init->graphics.flags.is_set(GRAPHICS_TEXT))
{
con.init(true);
}
else con.init(false);
}
else con.init(false);
if (!p->isIdentified())
{
con.printerr("Couldn't identify this version of DF.\n");
@ -400,7 +413,7 @@ bool Core::Init()
p = NULL;
return false;
}
vinfo = p->getDescriptor();
// create mutex for syncing with interactive tasks
StackMutex = new mutex();
AccessMutex = new mutex();
@ -472,6 +485,8 @@ void Core::Resume()
// should always be from simulation thread!
int Core::Update()
{
if(!started)
Init();
if(errorstate)
return -1;

@ -108,8 +108,6 @@ DFhackCExport int SDL_PollEvent(SDL::Event* event)
static int (*_SDL_Init)(uint32_t flags) = 0;
DFhackCExport int SDL_Init(uint32_t flags)
{
freopen("stdout.log", "w", stdout);
freopen("stderr.log", "w", stderr);
// find real functions
_SDL_Init = (int (*)( uint32_t )) dlsym(RTLD_NEXT, "SDL_Init");
_SDL_Quit = (void (*)( void )) dlsym(RTLD_NEXT, "SDL_Quit");
@ -126,8 +124,10 @@ DFhackCExport int SDL_Init(uint32_t flags)
fprintf(stderr,"dfhack: something went horribly wrong\n");
exit(1);
}
/*
DFHack::Core & c = DFHack::Core::getInstance();
c.Init();
*/
int ret = _SDL_Init(flags);
return ret;
}

@ -596,8 +596,6 @@ DFhackCExport int SDL_Init(uint32_t flags)
{
if(!inited)
FirstCall();
DFHack::Core & c = DFHack::Core::getInstance();
c.Init();
return _SDL_Init(flags);
}

@ -185,7 +185,7 @@ bool Process::setPermisions(const t_memrange & range,const t_memrange &trgrange)
int protect=0;
if(trgrange.read)protect|=PROT_READ;
if(trgrange.write)protect|=PROT_WRITE;
if(trgrange.execute)protect|=PROT_EXECUTE;
if(trgrange.execute)protect|=PROT_EXEC;
result=mprotect((void *)range.start, range.end-range.start,protect);
return result==0;

@ -31,6 +31,7 @@ distribution.
//#include <ostream>
namespace DFHack
{
template <typename T = int>
class BitArray
{
public:
@ -49,7 +50,7 @@ namespace DFHack
if(bits)
memset(bits, 0, size);
}
void set (uint32_t index, bool value = true)
void set (T index, bool value = true)
{
if(!value)
{
@ -63,7 +64,7 @@ namespace DFHack
bits[byte] |= bit;
}
}
void clear (uint32_t index)
void clear (T index)
{
uint32_t byte = index / 8;
if(byte < size)
@ -72,7 +73,7 @@ namespace DFHack
bits[byte] &= ~bit;
}
}
void toggle (uint32_t index)
void toggle (T index)
{
uint32_t byte = index / 8;
if(byte < size)
@ -81,7 +82,7 @@ namespace DFHack
bits[byte] ^= bit;
}
}
bool is_set (uint32_t index)
bool is_set (T index)
{
uint32_t byte = index / 8;
if(byte < size)
@ -115,17 +116,12 @@ namespace DFHack
memcpy(bits, &data, size);
return true;
}
friend std::ostream& operator<< (std::ostream &out, BitArray &ba);
//private:
uint8_t * bits;
uint32_t size;
};
inline std::ostream& operator<< (std::ostream &out, BitArray &ba)
friend std::ostream& operator<< (std::ostream &out, BitArray <T> &ba)
{
std::stringstream sstr;
for (int i = 0; i < ba.size * 8; i++)
{
if(ba.is_set(i))
if(ba.is_set((T)i))
sstr << "1 ";
else
sstr << "0 ";
@ -133,4 +129,8 @@ namespace DFHack
out << sstr.str();
return out;
}
//private:
uint8_t * bits;
uint32_t size;
};
}

@ -64,7 +64,7 @@ namespace DFHack
///dtor, NOT thread-safe
~Console();
/// initialize the console. NOT thread-safe
bool init( void );
bool init( bool sharing );
/// shutdown the console. NOT thread-safe
bool shutdown( void );

@ -29,6 +29,7 @@ distribution.
#include "dfhack/Export.h"
#include "dfhack/Module.h"
#include "dfhack/Virtual.h"
#include "dfhack/BitArray.h"
#include <string>
/**
@ -40,6 +41,7 @@ namespace DFHack
{
class DFContextShared;
/**
* A GUI screen
* \ingroup grp_gui
*/
struct t_viewscreen : public t_virtual
@ -50,6 +52,7 @@ namespace DFHack
char unk2; // state?
};
/**
* Interface - wrapper for the GUI
* \ingroup grp_gui
*/
struct t_interface
@ -59,7 +62,52 @@ namespace DFHack
unsigned int flags; // ?
// more crud this way ...
};
enum graphics_flag
{
GRAPHICS_ENABLED = 0,
GRAPHICS_BLACKSPACE = 1,
GRAPHICS_PARTIAL_PRINT = 2,
GRAPHICS_TEXT = 11,
GRAPHICS_FIXED_SIZE = 13
};
enum media_flag
{
MEDIA_NO_SOUND,
MEDIA_NO_INTRO,
MEDIA_COMPRESS_WORLDS,
};
/**
* The init structure - basically DF settings
* \ingroup grp_gui
*/
struct t_init
{
struct
{
BitArray <graphics_flag> flags;
enum
{
WINDOWED_YES,
WINDOWED_NO,
WINDOWED_PROMPT
} windowed;
// screen size in tiles
int grid_x;
int grid_y;
// in pixels ?
int fullscreen_x;
int fullscreen_y;
int window_x;
int window_y;
char partial_print;
} graphics;
struct
{
BitArray <media_flag> flags;
int32_t volume;
} media;
// much more stuff follows
};
#define NUM_HOTKEYS 16
/**
* The hotkey structure
@ -125,6 +173,11 @@ namespace DFHack
*/
hotkey_array * hotkeys;
/*
* Game settings
*/
t_init * init;
/*
* Window size in tiles
*/

@ -461,11 +461,18 @@ namespace DFHack
unsigned int liquid_1 : 1;
unsigned int liquid_2 : 1;
/// rest of the flags is completely unknown
unsigned int unk_2: 28;
// there's a possibility that this flags field is shorter than 32 bits
// FIXME: yes, it's a crazy dynamically sized array of flags. DERP.
unsigned int unk_2: 4;
};
enum e_block_flags
{
/// designated for jobs (digging and stuff like that)
BLOCK_DESIGNATED,
/// possibly related to the designated flag
BLOCK_UNKN1,
/// two flags required for liquid flow.
BLOCK_LIQUIDFLOW_1,
BLOCK_LIQUIDFLOW_2,
};
/**
* map block flags wrapper
* \ingroup grp_maps
@ -535,7 +542,7 @@ namespace DFHack
// one of the vector is the 'effects' vector. another should be item id/index vector
struct df_block
{
BitArray flags;
BitArray <e_block_flags> flags;
// how to handle this virtual mess?
std::vector <t_virtual *> block_events;
// no idea what these are

@ -83,6 +83,16 @@ Gui::Gui()
hotkeys = 0;
};
// Setting up init
try
{
init = (t_init *) OG_Gui->getAddress("init");
}
catch(Error::All &)
{
init = 0;
};
// Setting up menu state
try
{

@ -339,7 +339,7 @@ bool Maps::ReadDirtyBit(uint32_t x, uint32_t y, uint32_t z, bool &dirtybit)
df_block * block = getBlock(x,y,z);
if (block)
{
dirtybit = block->flags.is_set(1);
dirtybit = block->flags.is_set(BLOCK_DESIGNATED);
return true;
}
return false;
@ -351,7 +351,7 @@ bool Maps::WriteDirtyBit(uint32_t x, uint32_t y, uint32_t z, bool dirtybit)
df_block * block = getBlock(x,y,z);
if (block)
{
block->flags.set(1,dirtybit);
block->flags.set(BLOCK_DESIGNATED,dirtybit);
return true;
}
return false;