Files
itgmania212121/src/WheelNotifyIcon.cpp
T
sukibabyandteejusb eb35a9b9af Switch from Float to Integer Time Values
- Use fast data types where possible so the compiler can optimize for speed based on platform
    - for example, 128 bits might be fastest on ARM
    - good future-proofing

- Refactor GetTimeSinceStart() to be a bit faster
    - multiplication is much faster than division

- Implement a RageTimer method to get the seconds value as a plain int, for the places which cast the seconds value to an int

- Changing from GetTimeSinceStartFast() to GetTimeSinceStart() where accuracy is important

- Changing from GetTimeSinceStart() to GetUsecsSinceStart() for timestamp diffs

- Adjust RageThreads to accomodate an unsigned timestamp value
   - a constant for the maximum value of `uint_fast64_t` replaces `-1` to accommodate the change from signed to unsigned for the `locked_at` variable
   - i have separate constants for `std::numeric_limits<std::uint_fast64_t>::max()` and `static_cast<std::uint_fast64_t>(-1)`, so the reader understands -1 represents an error code, though they evaluate to the same value, so i could remove one of the two

- Add two methods to calculate the MMSSMsMs / MMSSMsMsMs time value from usecs directly instead of inferring it from a seconds value, in RageUtil

- Use a similar counter/modulo based method for WheelNotifyIcon, similar to what i did for text_glow in NoteField in 2eeee03

- Make `g_iStartTime` static const for safety

Rename two timer functions:
GetUsecsSinceStart -> GetTimeSinceStartMicroseconds
GetMicrosecondsSinceStart -> GetSystemTimeAsMicroseconds

Remove std prefix from uint_fast64_t
2024-09-22 01:27:45 -07:00

122 lines
4.1 KiB
C++

#include "global.h"
#include "WheelNotifyIcon.h"
#include "RageUtil.h"
#include "GameConstantsAndTypes.h"
#include "MusicWheel.h"
#include "WheelNotifyIcon.h"
#include "RageTimer.h"
#include "ThemeManager.h"
#include <cmath>
/* todo: replace this entire thing with a set of AutoActors and a Scroller.
* In reality, everything except the Beginner/Training icon can be replicated
* in Lua (in stock StepMania 4), so I'm not sure if we even need this... -aj
*/
static ThemeMetric<bool> SHOW_TRAINING ("WheelNotifyIcon","ShowTraining");
static ThemeMetric<bool> BLINK_BEST_ICON ("WheelNotifyIcon","BlinkPlayersBest");
static ThemeMetric<int> NUM_ICONS_TO_SHOW ("WheelNotifyIcon","NumIconsToShow");
WheelNotifyIcon::WheelNotifyIcon()
{
// Load( THEME->GetPathG("MusicWheelItem","WheelNotifyIcon") );
Load( THEME->GetPathG("WheelNotifyIcon","icons 4x2") );
StopAnimating();
}
void WheelNotifyIcon::SetFlags( Flags flags )
{
m_vIconsToShow.clear();
// push onto vector in highest to lowest priority
switch( flags.iPlayersBestNumber )
{
case 1: m_vIconsToShow.push_back( best1 ); break;
case 2: m_vIconsToShow.push_back( best2 ); break;
case 3: m_vIconsToShow.push_back( best3 ); break;
}
if( flags.bEdits )
m_vIconsToShow.push_back( edits );
switch( flags.iStagesForSong )
{
case 1: break;
case 2: m_vIconsToShow.push_back( long_ver ); break;
case 3: m_vIconsToShow.push_back( marathon ); break;
default: FAIL_M( ssprintf("flags.iStagesForSong = %d", flags.iStagesForSong) );
}
if( flags.bHasBeginnerOr1Meter && (bool)SHOW_TRAINING )
m_vIconsToShow.push_back( training );
// If BLINK_BEST_ICON, make player's best icon blink if it's the only icon.
if( m_vIconsToShow.size() == 1 && BLINK_BEST_ICON )
{
if( m_vIconsToShow[0] >= best1 && m_vIconsToShow[0] <= best3 )
m_vIconsToShow.push_back( empty );
}
const unsigned int newSize = std::min<unsigned int>(m_vIconsToShow.size(), static_cast<unsigned int>(NUM_ICONS_TO_SHOW));
m_vIconsToShow.resize(newSize);
// Broadcast Set message so items can react. (futures) -aj
//Message msg("Set");
//this->HandleMessage( msg );
/* Make sure the right icon is selected, since we might be drawn before
* we get another update. */
Update(0);
}
bool WheelNotifyIcon::EarlyAbortDraw() const
{
if( m_vIconsToShow.empty() )
return true;
return Sprite::EarlyAbortDraw();
}
void WheelNotifyIcon::Update( float fDeltaTime )
{
if( m_vIconsToShow.size() > 0 )
{
/* We should probably end up parsing the vector and then dynamically
* insert flag icons based on "priority". Easy to do, hopefully
- Midiman */
static std::uint_fast32_t updateCounter = 0;
updateCounter++;
const int index = updateCounter % m_vIconsToShow.size();
Sprite::SetState(m_vIconsToShow[index]);
}
Sprite::Update( fDeltaTime );
}
/*
* (c) 2001-2004 Chris Danford
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, and/or sell copies of the Software, and to permit persons to
* whom the Software is furnished to do so, provided that the above
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/