mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-20 05:07:51 -06:00
Memory optimization and code cleanup. Don't keep deserialized paths
This commit is contained in:
parent
52fb02f29d
commit
1697cb24a6
11 changed files with 99 additions and 71 deletions
|
@ -13,15 +13,24 @@ has 'flow_spacing' => (is => 'rw');
|
|||
# see EXTR_ROLE_* constants in ExtrusionPath.pm
|
||||
has 'role' => (is => 'rw', required => 1);
|
||||
|
||||
sub BUILD {
|
||||
my $self = shift;
|
||||
bless $self->polygon, 'Slic3r::Polygon';
|
||||
$self->polygon($self->polygon->serialize);
|
||||
}
|
||||
use constant PACK_FMT => 'fca*';
|
||||
|
||||
sub deserialize {
|
||||
# class or object method
|
||||
sub pack {
|
||||
my $self = shift;
|
||||
$self->polygon($self->polygon->deserialize);
|
||||
my %args = @_;
|
||||
|
||||
if (ref $self) {
|
||||
%args = map { $_ => $self->$_ } qw(flow_spacing role polygon);
|
||||
}
|
||||
|
||||
my $o = \ pack PACK_FMT,
|
||||
$args{flow_spacing} || -1,
|
||||
$args{role} // (die "Missing mandatory attribute 'role'"), #/
|
||||
$args{polygon}->serialize;
|
||||
|
||||
bless $o, 'Slic3r::ExtrusionLoop::Packed';
|
||||
return $o;
|
||||
}
|
||||
|
||||
sub shortest_path {
|
||||
|
@ -33,8 +42,6 @@ sub split_at_index {
|
|||
my $self = shift;
|
||||
my ($index) = @_;
|
||||
|
||||
$self->deserialize;
|
||||
|
||||
my @new_points = ();
|
||||
push @new_points, @{$self->polygon}[$index .. $#{$self->polygon}];
|
||||
push @new_points, @{$self->polygon}[0 .. $index];
|
||||
|
@ -52,8 +59,6 @@ sub split_at {
|
|||
|
||||
$point = Slic3r::Point->new($point);
|
||||
|
||||
$self->deserialize;
|
||||
|
||||
# find index of point
|
||||
my $i = -1;
|
||||
for (my $n = 0; $n <= $#{$self->polygon}; $n++) {
|
||||
|
@ -86,4 +91,18 @@ sub points {
|
|||
return $self->polygon;
|
||||
}
|
||||
|
||||
package Slic3r::ExtrusionLoop::Packed;
|
||||
sub unpack {
|
||||
my $self = shift;
|
||||
|
||||
my ($flow_spacing, $role, $polygon_s)
|
||||
= unpack Slic3r::ExtrusionLoop::PACK_FMT, $$self;
|
||||
|
||||
return Slic3r::ExtrusionLoop->new(
|
||||
flow_spacing => ($flow_spacing == -1) ? undef : $flow_spacing,
|
||||
role => $role,
|
||||
polygon => Slic3r::Polygon->deserialize($polygon_s),
|
||||
);
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue