Request designation rescan in auto-growing burrows.

This improves performance of burrowed miners digging 1-wide tunnels.
develop
Alexander Gavrilov 2012-05-12 20:54:26 +04:00
parent 60bb486aba
commit c6b52067bd
5 changed files with 44 additions and 10 deletions

@ -1066,7 +1066,7 @@ Events:
Emitted when a burrow might have been renamed either through Emitted when a burrow might have been renamed either through
the game UI, or ``renameBurrow()``. the game UI, or ``renameBurrow()``.
* ``onDigComplete.foo = function(job_type,pos,old_tiletype,new_tiletype)`` * ``onDigComplete.foo = function(job_type,pos,old_tiletype,new_tiletype,worker)``
Emitted when a tile might have been dug out. Only tracked if the Emitted when a tile might have been dug out. Only tracked if the
auto-growing burrows feature is enabled. auto-growing burrows feature is enabled.

@ -1245,7 +1245,7 @@ module file is still necessary for <tt class="docutils literal">require</tt> to
<p>Emitted when a burrow might have been renamed either through <p>Emitted when a burrow might have been renamed either through
the game UI, or <tt class="docutils literal">renameBurrow()</tt>.</p> the game UI, or <tt class="docutils literal">renameBurrow()</tt>.</p>
</li> </li>
<li><p class="first"><tt class="docutils literal">onDigComplete.foo = function(job_type,pos,old_tiletype,new_tiletype)</tt></p> <li><p class="first"><tt class="docutils literal">onDigComplete.foo = function(job_type,pos,old_tiletype,new_tiletype,worker)</tt></p>
<p>Emitted when a tile might have been dug out. Only tracked if the <p>Emitted when a tile might have been dug out. Only tracked if the
auto-growing burrows feature is enabled.</p> auto-growing burrows feature is enabled.</p>
</li> </li>

@ -143,6 +143,23 @@ INSTANTIATE_WRAPPERS(4, (OSTREAM_ARG,A1,A2,A3,A4), (out,vA1,vA2,vA3,vA4),
INSTANTIATE_RETURN_TYPE((A1,A2,A3,A4,A5)) INSTANTIATE_RETURN_TYPE((A1,A2,A3,A4,A5))
INSTANTIATE_WRAPPERS(5, (A1,A2,A3,A4,A5), (vA1,vA2,vA3,vA4,vA5), INSTANTIATE_WRAPPERS(5, (A1,A2,A3,A4,A5), (vA1,vA2,vA3,vA4,vA5),
LOAD_ARG(A1); LOAD_ARG(A2); LOAD_ARG(A3); LOAD_ARG(A4); LOAD_ARG(A5);) LOAD_ARG(A1); LOAD_ARG(A2); LOAD_ARG(A3); LOAD_ARG(A4); LOAD_ARG(A5);)
INSTANTIATE_WRAPPERS(5, (OSTREAM_ARG,A1,A2,A3,A4,A5), (out,vA1,vA2,vA3,vA4,vA5),
LOAD_OSTREAM(out); LOAD_ARG(A1); LOAD_ARG(A2);
LOAD_ARG(A3); LOAD_ARG(A4); LOAD_ARG(A5);)
#undef FW_TARGS
#define FW_TARGS class A1, class A2, class A3, class A4, class A5, class A6
INSTANTIATE_RETURN_TYPE((A1,A2,A3,A4,A5,A6))
INSTANTIATE_WRAPPERS(6, (A1,A2,A3,A4,A5,A6), (vA1,vA2,vA3,vA4,vA5,vA6),
LOAD_ARG(A1); LOAD_ARG(A2); LOAD_ARG(A3);
LOAD_ARG(A4); LOAD_ARG(A5); LOAD_ARG(A6);)
INSTANTIATE_WRAPPERS(6, (OSTREAM_ARG,A1,A2,A3,A4,A5,A6), (out,vA1,vA2,vA3,vA4,vA5,vA6),
LOAD_OSTREAM(out); LOAD_ARG(A1); LOAD_ARG(A2); LOAD_ARG(A3);
LOAD_ARG(A4); LOAD_ARG(A5); LOAD_ARG(A6);)
#undef FW_TARGS
#define FW_TARGS class A1, class A2, class A3, class A4, class A5, class A6, class A7
INSTANTIATE_RETURN_TYPE((A1,A2,A3,A4,A5,A6,A7))
#undef FW_TARGS #undef FW_TARGS
#undef FW_TARGSC #undef FW_TARGSC

@ -424,3 +424,17 @@ namespace DFHack {namespace Lua {
name##_event.invoke(out, 4); \ name##_event.invoke(out, 4); \
} \ } \
} }
#define DEFINE_LUA_EVENT_5(name, handler, arg_type1, arg_type2, arg_type3, arg_type4, arg_type5) \
static DFHack::Lua::Notification name##_event(df::wrap_function(handler, true)); \
void name(color_ostream &out, arg_type1 arg1, arg_type2 arg2, arg_type3 arg3, arg_type4 arg4, arg_type5 arg5) { \
handler(out, arg1, arg2, arg3, arg4, arg5); \
if (auto state = name##_event.get_state()) { \
DFHack::Lua::Push(state, arg1); \
DFHack::Lua::Push(state, arg2); \
DFHack::Lua::Push(state, arg3); \
DFHack::Lua::Push(state, arg4); \
DFHack::Lua::Push(state, arg5); \
name##_event.invoke(out, 5); \
} \
}

@ -153,10 +153,10 @@ static int next_job_id_save = 0;
static std::map<int,DigJob> diggers; static std::map<int,DigJob> diggers;
static void handle_dig_complete(color_ostream &out, df::job_type job, df::coord pos, static void handle_dig_complete(color_ostream &out, df::job_type job, df::coord pos,
df::tiletype old_tile, df::tiletype new_tile); df::tiletype old_tile, df::tiletype new_tile, df::unit *worker);
DEFINE_LUA_EVENT_4(onDigComplete, handle_dig_complete, DEFINE_LUA_EVENT_5(onDigComplete, handle_dig_complete,
df::job_type, df::coord, df::tiletype, df::tiletype); df::job_type, df::coord, df::tiletype, df::tiletype, df::unit*);
static void detect_digging(color_ostream &out) static void detect_digging(color_ostream &out)
{ {
@ -179,10 +179,7 @@ static void detect_digging(color_ostream &out)
if (new_tile != it->second.old_tile) if (new_tile != it->second.old_tile)
{ {
onDigComplete(out, it->second.job, pos, it->second.old_tile, new_tile); onDigComplete(out, it->second.job, pos, it->second.old_tile, new_tile, worker);
//if (worker && !worker->job.current_job)
// worker->counters.think_counter = worker->counters.job_counter = 0;
} }
} }
@ -370,7 +367,7 @@ static void add_walls_to_burrows(color_ostream &out, std::vector<df::burrow*> &b
} }
static void handle_dig_complete(color_ostream &out, df::job_type job, df::coord pos, static void handle_dig_complete(color_ostream &out, df::job_type job, df::coord pos,
df::tiletype old_tile, df::tiletype new_tile) df::tiletype old_tile, df::tiletype new_tile, df::unit *worker)
{ {
if (!isWalkable(new_tile)) if (!isWalkable(new_tile))
return; return;
@ -390,9 +387,11 @@ static void handle_dig_complete(color_ostream &out, df::job_type job, df::coord
return; return;
MapExtras::MapCache mc; MapExtras::MapCache mc;
bool changed = false;
if (!isWalkable(old_tile)) if (!isWalkable(old_tile))
{ {
changed = true;
add_walls_to_burrows(out, to_grow, mc, pos+df::coord(-1,-1,0), pos+df::coord(1,1,0)); add_walls_to_burrows(out, to_grow, mc, pos+df::coord(-1,-1,0), pos+df::coord(1,1,0));
if (isWalkableUp(new_tile)) if (isWalkableUp(new_tile))
@ -407,6 +406,7 @@ static void handle_dig_complete(color_ostream &out, df::job_type job, df::coord
if (LowPassable(new_tile) && !LowPassable(old_tile)) if (LowPassable(new_tile) && !LowPassable(old_tile))
{ {
changed = true;
add_to_burrows(to_grow, pos-df::coord(0,0,1)); add_to_burrows(to_grow, pos-df::coord(0,0,1));
if (tileShape(new_tile) == tiletype_shape::RAMP_TOP) if (tileShape(new_tile) == tiletype_shape::RAMP_TOP)
@ -415,6 +415,9 @@ static void handle_dig_complete(color_ostream &out, df::job_type job, df::coord
pos+df::coord(-1,-1,-1), pos+df::coord(1,1,-1)); pos+df::coord(-1,-1,-1), pos+df::coord(1,1,-1));
} }
} }
if (changed && worker && !worker->job.current_job)
Job::checkDesignationsNow();
} }
static void renameBurrow(color_ostream &out, df::burrow *burrow, std::string name) static void renameBurrow(color_ostream &out, df::burrow *burrow, std::string name)