void PoolAllocator::clear() { u8 adjustment = GetAdjustment(this->m_MemoryFirstAddress, this->OBJECT_ALIGNMENT); size_t numObjects = (size_t)floor((this->m_MemorySize - adjustment) / this->OBJECT_SIZE); union { void* asVoidPtr; uptr asUptr; }; asVoidPtr = (void*)this->m_MemoryFirstAddress; // align start address asUptr += adjustment; this->freeList = (void**)asVoidPtr; void** p = this->freeList; for (int i = 0; i < (numObjects - 1); ++i) { *p = (void*)((uptr)p + this->OBJECT_SIZE); p = (void**)*p; } *p = nullptr; }
void Scale::HandleMouseButtonEvent( sf::Mouse::Button button, bool press, int x, int y ) { if( button != sf::Mouse::Left ) { return; } if( m_drag_offset ) { m_drag_offset.reset(); m_dragging = false; } if( !GetAllocation().contains( static_cast<float>( x ), static_cast<float>( y ) ) ) { return; } if( press ) { if( !GetSliderRect().contains( static_cast<float>( x ) - GetAllocation().left, static_cast<float>( y ) - GetAllocation().top ) ) { Adjustment::Ptr adjustment( GetAdjustment() ); auto minor_step = adjustment->GetMinorStep(); auto range = adjustment->GetUpper() - adjustment->GetLower(); auto steps = range / minor_step; auto needed_steps = 0.f; auto trough_position = 0.f; auto trough_length = 0.f; if( GetOrientation() == Orientation::HORIZONTAL ) { trough_position = static_cast<float>( x ) - ( GetAllocation().left + GetSliderRect().width / 2.f ); trough_length = GetAllocation().width - GetSliderRect().width; } if( GetOrientation() == Orientation::VERTICAL ) { trough_position = static_cast<float>( y ) - ( GetAllocation().top + GetSliderRect().height / 2.f ); trough_length = GetAllocation().height - GetSliderRect().height; } trough_position = std::min( trough_position, trough_length ); auto trough_ratio = trough_position / trough_length; for( ; needed_steps < steps; needed_steps += 1.f ) { if( ( 1.f / steps ) * needed_steps > trough_ratio ) { break; } } needed_steps = std::max( needed_steps - 1.f, 0.f ); adjustment->SetValue( needed_steps * minor_step ); } m_dragging = true; m_drag_offset.reset( new sf::Vector2f( static_cast<float>( x ) - ( GetAllocation().left + GetSliderRect().left + GetSliderRect().width / 2.f ), static_cast<float>( y ) - ( GetAllocation().top + GetSliderRect().top + GetSliderRect().height / 2.f ) ) ); } }
// recalculation of the delta value for the reference clock INT64 SynchCorrection::GetCorrectedTimeDelta(INT64 time, REFERENCE_TIME rtAHwTime, REFERENCE_TIME rtRCTime) { double deltaTime = 0; { CAutoLock lock(&m_csDeltaLock); deltaTime = time * GetAdjustment() * GetBias() + m_dDeltaError; m_dDeltaError = deltaTime - floor(deltaTime); } return (INT64) deltaTime; }
void Scrollbar::HandleMouseMoveEvent( int x, int y ) { if( !m_dragging || ( x == std::numeric_limits<int>::min() ) || ( y == std::numeric_limits<int>::min() ) ) { return; } Adjustment::Ptr adjustment( GetAdjustment() ); auto slider_rect = GetSliderRect(); auto value_range = std::max( adjustment->GetUpper() - adjustment->GetLower() - adjustment->GetPageSize(), adjustment->GetMinorStep() / 2.f ); auto steps = value_range / adjustment->GetMinorStep(); if( GetOrientation() == Orientation::HORIZONTAL ) { auto stepper_length = GetAllocation().height; auto slider_center_x = slider_rect.left + slider_rect.width / 2.0f; auto step_distance = ( GetAllocation().width - 2.f * stepper_length ) / steps; auto delta = ( static_cast<float>( x ) - (slider_center_x + m_slider_click_offset) ); while( delta < (-step_distance / 2) ) { adjustment->Decrement(); delta += step_distance; } while( delta > (step_distance / 2) ) { adjustment->Increment(); delta -= step_distance; } } else { auto stepper_length = GetAllocation().width; auto slider_center_y = slider_rect.top + slider_rect.height / 2.0f; auto step_distance = (GetAllocation().height - 2.f * stepper_length) / steps; auto delta = static_cast<float>( y ) - (slider_center_y + m_slider_click_offset); while( delta < (-step_distance / 2) ) { adjustment->Decrement(); delta += step_distance; } while( delta > (step_distance / 2) ) { adjustment->Increment(); delta -= step_distance; } } }
const sf::FloatRect Scale::GetSliderRect() const { auto slider_length = Context::Get().GetEngine().GetProperty<float>( "SliderLength", shared_from_this() ); auto slider_width = (GetOrientation() == Orientation::HORIZONTAL) ? GetAllocation().height : GetAllocation().width; auto adjustment = GetAdjustment(); auto current_value = adjustment->GetValue(); auto value_range = adjustment->GetUpper() - adjustment->GetLower() - adjustment->GetPageSize(); if( GetOrientation() == Orientation::HORIZONTAL ) { auto slider_x = (GetAllocation().width - slider_length) * (current_value - adjustment->GetLower()) / value_range; auto slider_y = (GetAllocation().height - slider_width) / 2.f; return sf::FloatRect( slider_x, slider_y, slider_length, slider_width ); } auto slider_x = (GetAllocation().width - slider_width) / 2.f; auto slider_y = (GetAllocation().height - slider_length) * (1 - ((current_value - adjustment->GetLower()) / value_range)); return sf::FloatRect( slider_x, slider_y, slider_width, slider_length ); }
const sf::FloatRect Scrollbar::GetSliderRect() const { float mimimum_slider_length( Context::Get().GetEngine().GetProperty<float>( "SliderMinimumLength", shared_from_this() ) ); Adjustment::Ptr adjustment( GetAdjustment() ); auto current_value = adjustment->GetValue(); auto value_range = std::max( adjustment->GetUpper() - adjustment->GetLower() - adjustment->GetPageSize(), .0f ); auto pages = value_range / adjustment->GetPageSize() + 1.f; if( GetOrientation() == Orientation::HORIZONTAL ) { auto stepper_length = GetAllocation().height; auto trough_length = GetAllocation().width - 2.f * stepper_length; auto slider_length = std::max( mimimum_slider_length, trough_length / pages ); if( adjustment->GetPageSize() == .0f ) { slider_length = mimimum_slider_length; } auto slider_x = stepper_length + ( trough_length - slider_length ) * ( current_value - adjustment->GetLower() ) / value_range; auto slider_y = 0.f; if( value_range == .0f ) { slider_x = stepper_length; } return sf::FloatRect( slider_x, slider_y, slider_length, GetAllocation().height ); } auto stepper_length = GetAllocation().width; auto trough_length = GetAllocation().height - 2.f * stepper_length; auto slider_length = std::max( mimimum_slider_length, trough_length / pages ); if( adjustment->GetPageSize() == .0f ) { slider_length = mimimum_slider_length; } auto slider_x = 0.f; auto slider_y = stepper_length + ( trough_length - slider_length ) * ( current_value - adjustment->GetLower() ) / value_range; if( value_range == .0f ) { slider_y = stepper_length; } return sf::FloatRect( slider_x, slider_y, GetAllocation().width, slider_length ); }
void* StackAllocator::allocate(size_t memSize, u8 alignment) { assert(memSize > 0 && "allocate called with memSize = 0."); union { void* asVoidPtr; uptr asUptr; AllocMetaInfo* asMeta; }; asVoidPtr = (void*)this->m_MemoryFirstAddress; // current address asUptr += this->m_MemoryUsed; u8 adjustment = GetAdjustment(asVoidPtr, alignment, sizeof(AllocMetaInfo)); // check if there is enough memory available if (this->m_MemoryUsed + memSize + adjustment > this->m_MemorySize) { // not enough memory return nullptr; } // store alignment in allocation meta info asMeta->adjustment = adjustment; // determine aligned memory address asUptr += adjustment; // update book keeping this->m_MemoryUsed += memSize + adjustment; this->m_MemoryAllocations++; // return aligned memory address return asVoidPtr; }
Bool_T Postsolver::ReadActions( FILE *fp ) { //-------------------------------------------------------------------------- // Initialize the object as an empty object. Set up the read data buffer, // work variables etc. Set up the lexical analysis module. // FreeMemory(); Lexer::SetInputStream( "action file", fp ); ResetErrorCount(); MaxErrCount( 20 ); Int_T ReducedCols = 0; //-------------------------------------------------------------------------- // Read the first line. // if( !Lexer::GetKeyword( "PRESOLVER" ) || !Lexer::GetSpace() || !Lexer::GetKeyword( "REPORT" ) ) { Error( "Title line incorrect or missing." ); goto error; } if( !Lexer::GetNewline() ) { Error( "Extra input after the title line ignored." ); Lexer::GetNewline( True ); } //-------------------------------------------------------------------------- // Read the ROWS section and create the row exclusion array. Then read the // COLUMNS section and do the same. // if( /* !GetRowsSection() || */ !GetColumnsSection() ) goto error; assert( n >= 0 ); { for( Int_T j = 0; j < n; j++ ) if( ExcludeCols[j] ) ReducedCols++; } //-------------------------------------------------------------------------- // Read the actions in loop. Then read the "ENDATA" and finish processing. // while( GetAction( ReducedCols ) || GetAdjustment() ) ; if( ReducedCols > 0 ) { Error( "Some postsolve actions missing." ); goto error; } if( !Lexer::GetKeyword( "ENDATA" ) ) { Error( "ENDATA expected." ); goto error; } if( ErrorCount() > 0 ) goto error; return True; error: FreeMemory(); return False; }
void Scrollbar::HandleMouseButtonEvent( sf::Mouse::Button button, bool press, int x, int y ) { if( button != sf::Mouse::Left ) { return; } if( press ) { auto slider_rect = GetSliderRect(); slider_rect.left += GetAllocation().left; slider_rect.top += GetAllocation().top; if( slider_rect.contains( static_cast<float>( x ), static_cast<float>( y ) ) ) { m_dragging = true; if( GetOrientation() == Orientation::HORIZONTAL ) { auto slider_mid = slider_rect.left + slider_rect.width / 2.f; m_slider_click_offset = static_cast<float>( x ) + GetAllocation().left - slider_mid; } else { auto slider_mid = slider_rect.top + slider_rect.height / 2.f; m_slider_click_offset = static_cast<float>( y ) + GetAllocation().top - slider_mid; } return; } if( GetOrientation() == Orientation::HORIZONTAL ) { auto stepper_length = GetAllocation().height; sf::FloatRect decrease_stepper_rect( GetAllocation().left, GetAllocation().top, stepper_length, GetAllocation().height ); sf::FloatRect increase_stepper_rect( GetAllocation().left + GetAllocation().width - stepper_length, GetAllocation().top, stepper_length, GetAllocation().height ); if( decrease_stepper_rect.contains( static_cast<float>( x ), static_cast<float>( y ) ) ) { m_decrease_pressed = true; GetAdjustment()->Decrement(); m_elapsed_time = 0.f; m_repeat_wait = true; Invalidate(); return; } if( increase_stepper_rect.contains( static_cast<float>( x ), static_cast<float>( y ) ) ) { m_increase_pressed = true; GetAdjustment()->Increment(); m_elapsed_time = 0.f; m_repeat_wait = true; Invalidate(); return; } } else { auto stepper_length = GetAllocation().width; sf::FloatRect decrease_stepper_rect( GetAllocation().left, GetAllocation().top, GetAllocation().width, stepper_length ); sf::FloatRect increase_stepper_rect( GetAllocation().left, GetAllocation().top + GetAllocation().height - stepper_length, GetAllocation().width, stepper_length ); if( decrease_stepper_rect.contains( static_cast<float>( x ), static_cast<float>( y ) ) ) { m_decrease_pressed = true; GetAdjustment()->Decrement(); m_elapsed_time = 0.f; m_repeat_wait = true; Invalidate(); return; } if( increase_stepper_rect.contains( static_cast<float>( x ), static_cast<float>( y ) ) ) { m_increase_pressed = true; GetAdjustment()->Increment(); m_elapsed_time = 0.f; m_repeat_wait = true; Invalidate(); return; } } auto slider_center_x = slider_rect.left + slider_rect.width / 2.f; auto slider_center_y = slider_rect.top + slider_rect.height / 2.f; if( GetOrientation() == Orientation::HORIZONTAL ) { if( GetAllocation().contains( static_cast<float>( x ), static_cast<float>( y ) ) ) { if( static_cast<float>( x ) < slider_center_x ) { m_page_decreasing = x; GetAdjustment()->DecrementPage(); m_elapsed_time = 0.f; m_repeat_wait = true; Invalidate(); return; } else { m_page_increasing = x; GetAdjustment()->IncrementPage(); m_elapsed_time = 0.f; m_repeat_wait = true; Invalidate(); return; } } } else { if( GetAllocation().contains( static_cast<float>( x ), static_cast<float>( y ) ) ) { if( static_cast<float>( y ) < slider_center_y ) { m_page_decreasing = y; GetAdjustment()->DecrementPage(); m_elapsed_time = 0.f; m_repeat_wait = true; Invalidate(); return; } else { m_page_increasing = y; GetAdjustment()->IncrementPage(); m_elapsed_time = 0.f; m_repeat_wait = true; Invalidate(); return; } } } } else { m_dragging = false; m_decrease_pressed = false; m_increase_pressed = false; m_page_decreasing = 0; m_page_increasing = 0; m_slider_click_offset = 0.f; Invalidate(); return; } }
void Scrollbar::HandleUpdate( float seconds ) { auto stepper_speed = Context::Get().GetEngine().GetProperty<float>( "StepperSpeed", shared_from_this() ); m_elapsed_time += seconds; if( m_elapsed_time < (1.f / stepper_speed) ) { return; } if( m_repeat_wait ) { auto stepper_repeat_delay = Context::Get().GetEngine().GetProperty<sf::Uint32>( "StepperRepeatDelay", shared_from_this() ); if( m_elapsed_time < (static_cast<float>( stepper_repeat_delay ) / 1000.f) ) { return; } m_repeat_wait = false; } m_elapsed_time = 0.f; // Increment / Decrement value while one of the steppers is pressed if( m_decrease_pressed ) { GetAdjustment()->Decrement(); Invalidate(); return; } else if( m_increase_pressed ) { GetAdjustment()->Increment(); Invalidate(); return; } auto slider_rect = GetSliderRect(); slider_rect.left += GetAllocation().left; slider_rect.top += GetAllocation().top; // Increment / Decrement page while mouse is pressed on the trough if( m_page_decreasing ) { GetAdjustment()->DecrementPage(); if( GetOrientation() == Orientation::HORIZONTAL ) { if( slider_rect.left + slider_rect.width < static_cast<float>( m_page_decreasing ) ) { m_page_decreasing = 0; } } else { if( slider_rect.top + slider_rect.height < static_cast<float>( m_page_decreasing ) ) { m_page_decreasing = 0; } } Invalidate(); return; } else if( m_page_increasing ) { GetAdjustment()->IncrementPage(); if( GetOrientation() == Orientation::HORIZONTAL ) { if( slider_rect.left + slider_rect.width > static_cast<float>( m_page_increasing ) ) { m_page_increasing = 0; } } else { if( slider_rect.top + slider_rect.height > static_cast<float>( m_page_increasing ) ) { m_page_increasing = 0; } } Invalidate(); return; } }