Skip to content

Commit

Permalink
Faster time estimate for multimaterial
Browse files Browse the repository at this point in the history
  • Loading branch information
enricoturri1966 committed Jul 20, 2018
1 parent 4b8e10a commit 95bd2bb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 30 deletions.
38 changes: 12 additions & 26 deletions xs/src/libslic3r/GCodeTimeEstimator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ namespace Slic3r {
}

GCodeTimeEstimator::Block::Block()
: st_synchronized(false)
{
}

Expand Down Expand Up @@ -202,7 +201,7 @@ namespace Slic3r {
if (start_from_beginning)
{
_reset_time();
_set_blocks_st_synchronize(false);
_last_st_synchronized_block_id = -1;
}
_calculate_time();

Expand Down Expand Up @@ -614,6 +613,8 @@ namespace Slic3r {

reset_g1_line_id();
_g1_line_ids.clear();

_last_st_synchronized_block_id = -1;
}

void GCodeTimeEstimator::_reset_time()
Expand All @@ -626,14 +627,6 @@ namespace Slic3r {
_blocks.clear();
}

void GCodeTimeEstimator::_set_blocks_st_synchronize(bool state)
{
for (Block& block : _blocks)
{
block.st_synchronized = state;
}
}

void GCodeTimeEstimator::_calculate_time()
{
_forward_pass();
Expand All @@ -642,10 +635,9 @@ namespace Slic3r {

_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)
continue;
Block& block = _blocks[i];

#if ENABLE_MOVE_STATS
float block_time = 0.0f;
Expand All @@ -668,6 +660,8 @@ namespace Slic3r {
block.elapsed_time = _time;
#endif // ENABLE_MOVE_STATS
}

_last_st_synchronized_block_id = _blocks.size() - 1;
}

void GCodeTimeEstimator::_process_gcode_line(GCodeReader&, const GCodeReader::GCodeLine& line)
Expand Down Expand Up @@ -1210,18 +1204,14 @@ namespace Slic3r {
void GCodeTimeEstimator::_simulate_st_synchronize()
{
_calculate_time();
_set_blocks_st_synchronize(true);
}

void GCodeTimeEstimator::_forward_pass()
{
if (_blocks.size() > 1)
{
for (unsigned int i = 0; i < (unsigned int)_blocks.size() - 1; ++i)
{
if (_blocks[i].st_synchronized || _blocks[i + 1].st_synchronized)
continue;

for (int i = _last_st_synchronized_block_id + 1; i < (int)_blocks.size() - 1; ++i)
{
_planner_forward_pass_kernel(_blocks[i], _blocks[i + 1]);
}
}
Expand All @@ -1231,11 +1221,8 @@ namespace Slic3r {
{
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]);
}
}
Expand Down Expand Up @@ -1286,10 +1273,9 @@ namespace Slic3r {
Block* curr = 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)
continue;
Block& b = _blocks[i];

curr = next;
next = &b;
Expand Down
6 changes: 2 additions & 4 deletions xs/src/libslic3r/GCodeTimeEstimator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,6 @@ namespace Slic3r {
Trapezoid trapezoid;
float elapsed_time;

bool st_synchronized;

Block();

// Returns the length of the move covered by this block, in mm
Expand Down Expand Up @@ -211,6 +209,8 @@ namespace Slic3r {
BlocksList _blocks;
// Map between g1 line id and blocks id, used to speed up export of remaining times
G1LineIdToBlockIdMap _g1_line_ids;
// Index of the last block already st_synchronized
int _last_st_synchronized_block_id;
float _time; // s

#if ENABLE_MOVE_STATS
Expand Down Expand Up @@ -323,8 +323,6 @@ namespace Slic3r {
void _reset_time();
void _reset_blocks();

void _set_blocks_st_synchronize(bool state);

// Calculates the time estimate
void _calculate_time();

Expand Down

0 comments on commit 95bd2bb

Please sign in to comment.