10 cm( inst, this,
"Sectors_Loader" ),
13 load_range( load_range ),
14 sector_size( sector_size ),
15 current_begin( 0, 0 ),
25 void Sectors_Loader::Load(
iv::int2 block )
28 this->sectors->
Load( &this->
cm, block );
31 void Sectors_Loader::Unload(
iv::int2 block )
34 this->sectors->
Unload( &this->
cm, block );
40 auto center_position = this->position->
Get();
42 int2 current_begin = this->current_begin;
43 int2 current_end = this->current_end;
44 int2 target_begin =
sig_div(
int2( center_position -
float2( this->load_range, this->load_range ) ), this->sector_size );
45 int2 target_end =
sig_div(
int2( center_position +
float2( this->load_range, this->load_range ) ), this->sector_size );
47 int max_begin_x = std::max( current_begin.x, target_begin.x );
48 int min_end_x = std::min( current_end.x, target_end.x );
52 for(
int x = current_begin.x; x < std::min( current_end.x, target_begin.x ); x++ )
53 for(
int y = current_begin.y; y < current_end.y; y++ )
54 this->Unload(
int2( x, y ) );
57 for(
int x = std::max( target_end.x, current_begin.x ); x < current_end.x; x++ )
58 for(
int y = current_begin.y; y < current_end.y; y++ )
59 this->Unload(
int2( x, y ) );
62 for(
int y = current_begin.y; y < std::min( current_end.y, target_begin.y ); y++ )
63 for(
int x = max_begin_x; x < min_end_x; x++ )
64 this->Unload(
int2( x, y ) );
67 for(
int y = std::max( target_end.y, current_begin.y ); y < current_end.y; y++ )
68 for(
int x = max_begin_x; x < min_end_x; x++ )
69 this->Unload(
int2( x, y ) );
73 for(
int x = target_begin.x; x < std::min( target_end.x, current_begin.x ); x++ )
74 for(
int y = target_begin.y; y < target_end.y; y++ )
75 this->Load(
int2( x, y ) );
78 for(
int x = std::max( current_end.x, target_begin.x ); x < target_end.x; x++ )
79 for(
int y = target_begin.y; y < target_end.y; y++ )
80 this->Load(
int2( x, y ) );
83 for(
int y = target_begin.y; y < std::min( target_end.y, current_begin.y ); y++ )
84 for(
int x = max_begin_x; x < min_end_x; x++ )
85 this->Load(
int2( x, y ) );
88 for(
int y = std::max( current_end.y, target_begin.y ); y < target_end.y; y++ )
89 for(
int x = max_begin_x; x < min_end_x; x++ )
90 this->Load(
int2( x, y ) );
93 this->current_begin = target_begin;
94 this->current_end = target_end;