Faster time estimate for multimaterial

This commit is contained in:
Enrico Turri 2018-07-20 15:54:11 +02:00
parent 4b8e10a05c
commit 95bd2bb8f9
2 changed files with 14 additions and 30 deletions

View file

@ -79,7 +79,6 @@ namespace Slic3r {
} }
GCodeTimeEstimator::Block::Block() GCodeTimeEstimator::Block::Block()
: st_synchronized(false)
{ {
} }
@ -202,7 +201,7 @@ namespace Slic3r {
if (start_from_beginning) if (start_from_beginning)
{ {
_reset_time(); _reset_time();
_set_blocks_st_synchronize(false); _last_st_synchronized_block_id = -1;
} }
_calculate_time(); _calculate_time();
@ -614,6 +613,8 @@ namespace Slic3r {
reset_g1_line_id(); reset_g1_line_id();
_g1_line_ids.clear(); _g1_line_ids.clear();
_last_st_synchronized_block_id = -1;
} }
void GCodeTimeEstimator::_reset_time() void GCodeTimeEstimator::_reset_time()
@ -626,14 +627,6 @@ namespace Slic3r {
_blocks.clear(); _blocks.clear();
} }
void GCodeTimeEstimator::_set_blocks_st_synchronize(bool state)
{
for (Block& block : _blocks)
{
block.st_synchronized = state;
}
}
void GCodeTimeEstimator::_calculate_time() void GCodeTimeEstimator::_calculate_time()
{ {
_forward_pass(); _forward_pass();
@ -642,10 +635,9 @@ namespace Slic3r {
_time += get_additional_time(); _time += get_additional_time();
for (Block& block : _blocks) for (int i = _last_st_synchronized_block_id + 1; i < (int)_blocks.size(); ++i)
{ {
if (block.st_synchronized) Block& block = _blocks[i];
continue;
#if ENABLE_MOVE_STATS #if ENABLE_MOVE_STATS
float block_time = 0.0f; float block_time = 0.0f;
@ -668,6 +660,8 @@ namespace Slic3r {
block.elapsed_time = _time; block.elapsed_time = _time;
#endif // ENABLE_MOVE_STATS #endif // ENABLE_MOVE_STATS
} }
_last_st_synchronized_block_id = _blocks.size() - 1;
} }
void GCodeTimeEstimator::_process_gcode_line(GCodeReader&, const GCodeReader::GCodeLine& line) void GCodeTimeEstimator::_process_gcode_line(GCodeReader&, const GCodeReader::GCodeLine& line)
@ -1210,18 +1204,14 @@ namespace Slic3r {
void GCodeTimeEstimator::_simulate_st_synchronize() void GCodeTimeEstimator::_simulate_st_synchronize()
{ {
_calculate_time(); _calculate_time();
_set_blocks_st_synchronize(true);
} }
void GCodeTimeEstimator::_forward_pass() void GCodeTimeEstimator::_forward_pass()
{ {
if (_blocks.size() > 1) if (_blocks.size() > 1)
{ {
for (unsigned int i = 0; i < (unsigned int)_blocks.size() - 1; ++i) for (int i = _last_st_synchronized_block_id + 1; i < (int)_blocks.size() - 1; ++i)
{ {
if (_blocks[i].st_synchronized || _blocks[i + 1].st_synchronized)
continue;
_planner_forward_pass_kernel(_blocks[i], _blocks[i + 1]); _planner_forward_pass_kernel(_blocks[i], _blocks[i + 1]);
} }
} }
@ -1231,11 +1221,8 @@ namespace Slic3r {
{ {
if (_blocks.size() > 1) if (_blocks.size() > 1)
{ {
for (int i = (int)_blocks.size() - 1; i >= 1; --i) for (int i = (int)_blocks.size() - 1; i >= _last_st_synchronized_block_id + 2; --i)
{ {
if (_blocks[i - 1].st_synchronized || _blocks[i].st_synchronized)
continue;
_planner_reverse_pass_kernel(_blocks[i - 1], _blocks[i]); _planner_reverse_pass_kernel(_blocks[i - 1], _blocks[i]);
} }
} }
@ -1286,10 +1273,9 @@ namespace Slic3r {
Block* curr = nullptr; Block* curr = nullptr;
Block* next = nullptr; Block* next = nullptr;
for (Block& b : _blocks) for (int i = _last_st_synchronized_block_id + 1; i < (int)_blocks.size(); ++i)
{ {
if (b.st_synchronized) Block& b = _blocks[i];
continue;
curr = next; curr = next;
next = &b; next = &b;

View file

@ -144,8 +144,6 @@ namespace Slic3r {
Trapezoid trapezoid; Trapezoid trapezoid;
float elapsed_time; float elapsed_time;
bool st_synchronized;
Block(); Block();
// Returns the length of the move covered by this block, in mm // Returns the length of the move covered by this block, in mm
@ -211,6 +209,8 @@ namespace Slic3r {
BlocksList _blocks; BlocksList _blocks;
// Map between g1 line id and blocks id, used to speed up export of remaining times // Map between g1 line id and blocks id, used to speed up export of remaining times
G1LineIdToBlockIdMap _g1_line_ids; G1LineIdToBlockIdMap _g1_line_ids;
// Index of the last block already st_synchronized
int _last_st_synchronized_block_id;
float _time; // s float _time; // s
#if ENABLE_MOVE_STATS #if ENABLE_MOVE_STATS
@ -323,8 +323,6 @@ namespace Slic3r {
void _reset_time(); void _reset_time();
void _reset_blocks(); void _reset_blocks();
void _set_blocks_st_synchronize(bool state);
// Calculates the time estimate // Calculates the time estimate
void _calculate_time(); void _calculate_time();