本文整理汇总了C++中Stopwatch::startMs方法的典型用法代码示例。如果您正苦于以下问题:C++ Stopwatch::startMs方法的具体用法?C++ Stopwatch::startMs怎么用?C++ Stopwatch::startMs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stopwatch
的用法示例。
在下文中一共展示了Stopwatch::startMs方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
TEST(keyboard_UT, KeyboardHandlerCallback)
{
{
if ( SDL_Init ( SDL_INIT_VIDEO ) < 0 )
{
std::cerr << "SDL_Init ( .. ) failed: " << SDL_GetError( ) <<std::endl;
exit( -1 );
}
SDL_Window * window = SDL_CreateWindow( "SDL2 OpenGL"
, SDL_WINDOWPOS_CENTERED
, SDL_WINDOWPOS_CENTERED
, 1920 / 2
, 1080 / 2
, SDL_WINDOW_OPENGL | SDL_WINDOW_BORDERLESS |
SDL_WINDOW_SHOWN | SDL_WINDOW_INPUT_GRABBED |
SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_MOUSE_FOCUS );
SDL_GLContext context = SDL_GL_CreateContext( window );
SDL_GL_SetSwapInterval( 1 );
//SDL_MaximizeWindow( window );
SDL_RaiseWindow( window );
SDL_SetWindowGrab( window, SDL_TRUE );
event quit;
OnKeyboardEventCallback onKeyboardCharacter = [&] ( KeyboardEvent const & xEvent )
{
std::cout << "[ Key " << ( xEvent.getKeyUp( ) ? "up " : "down " ) << ": "
<< std::hex << xEvent.getScanCode( ) << "]" << std::endl;
if ( xEvent.getScanCode( ) == SDL_SCANCODE_Q )
{
std::cerr << "Q pressed. Exiting.. " << std::endl;
quit.set( );
}
};
Keyboard kb;
kb.registerCallback( onKeyboardCharacter );
kb.listen( );
double accum = 0.0;
while ( !quit.isSet( ) )
{
Stopwatch t;
t.startMs( );
SDL_PumpEvents( );
SDL_GL_SwapWindow( window );
if ( ( accum += t.stop( ) ) > 3000.0 )
{
std::cerr << "Timeout reached. Exiting.." << std::endl;
break;
}
}
kb.stopListening( );
SDL_DestroyWindow(window);
SDL_Quit( );
}
}
示例2: f
TEST(mouse_UT, MouseHandlerCallback)
{
{
if ( SDL_Init ( SDL_INIT_VIDEO ) < 0 )
{
std::cerr << "SDL_Init ( .. ) failed: " << SDL_GetError( ) <<std::endl;
exit( -1 );
}
SDL_Window * window = SDL_CreateWindow( "SDL2 OpenGL"
, SDL_WINDOWPOS_CENTERED
, SDL_WINDOWPOS_CENTERED
, 1920/2
, 1080/2
, SDL_WINDOW_OPENGL | SDL_WINDOW_BORDERLESS |
SDL_WINDOW_SHOWN | SDL_WINDOW_INPUT_GRABBED |
SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_MOUSE_FOCUS );
SDL_GLContext context = SDL_GL_CreateContext( window );
SDL_GL_SetSwapInterval( 1 );
SDL_RaiseWindow( window );
SDL_SetWindowGrab( window, SDL_TRUE );
event quit;
OnMouseEventCallback onMouseCharacter = [&] ( MouseEventInfo const & xEvent )
{
std::ios::fmtflags const f( std::cout.flags( ) );
std::cout << "[ Mouse: "
<< xEvent.x
<< ", "
<< xEvent.y
<< " "
<< std::hex
<< xEvent.state;
std::cout.flags( f );
auto resolveClickStateName = []( eClickState const xState )->const char *
{
switch ( xState )
{
case eClickState_Up:
return "Up";
case eClickState_Down:
return "Down";
case eClickState_Continue:
return "Continue";
case eClickState_None:
return "None";
default:
return "Invalid";
}
};
std::cout
<< "left: " << ( resolveClickStateName( xEvent.leftState ) ) << " "
<< "middle: " << ( resolveClickStateName( xEvent.middleState ) ) << " "
<< "right: " << ( resolveClickStateName( xEvent.rightState ) ) << " "
<< ( xEvent.wheelHasMovedUp( ) ? ", wheel up " : "" )
<< ( xEvent.wheelHasMovedDown( ) ? ", wheel down " : "" )
<< " ]"
<< std::endl;
if ( xEvent.leftState == eClickState_Continue &&
xEvent.middleState == eClickState_Continue &&
xEvent.rightState == eClickState_Continue )
{
std::cout << "All three buttons pressed. Exiting.." << std::endl;
quit.set( );
}
};
Mouse kb;
kb.registerCallback(onMouseCharacter);
kb.listen( );
double accum = 0.0;
Stopwatch t;
while ( !quit.isSet( ) )
{
t.startMs( );
SDL_PumpEvents( );
//.........这里部分代码省略.........
示例3: if
Keyboard( double const xDebounceTicks = 18000000.0 )
: mM( )
, mQuit( )
, mCallbacks( )
, mInitialized( false )
, mKeyboardListener( [ & ] ( int64_t const xSleepIntervalNs ) -> uint32_t
{
bool pressedLastTime[ SDL_NUM_SCANCODES ];
for ( uint16_t ii = 0; ii < SDL_NUM_SCANCODES; ++ii )
{
pressedLastTime [ ii ] = false;
}
double continueDebounceAccum = 0.0;
Stopwatch t;
while ( !mQuit.isSet( ) )
{
if ( xSleepIntervalNs > 0 )
{
sleep::ns( xSleepIntervalNs );
}
const Uint8 * state = SDL_GetKeyboardState( NULL );
for ( uint16_t ii = 0; ii < SDL_NUM_SCANCODES; ++ii )
{
eKeyState keyState = eKeyState_None;
auto runCallbacks = [&]()
{
mM.run([&]( )
{
for ( auto callback : mCallbacks )
{
callback( KeyboardEvent( keyState, ii, state ) );
}
});
};
if ( state[ ii ] && !pressedLastTime[ ii ] )
{
keyState = eKeyState_Down;
t.startMs( );
}
else if ( state[ ii ] && pressedLastTime[ ii ] )
{
continueDebounceAccum += t.stop( );
if ( continueDebounceAccum > mDebounceTicks )
{
keyState = eKeyState_Continue;
continueDebounceAccum = 0;
t.startMs( );
}
}
else if ( !state[ ii ] && pressedLastTime[ ii ] )
{
keyState = eKeyState_Up;
}
if ( keyState != eKeyState_None )
{
runCallbacks( );
}
pressedLastTime[ ii ] = state[ ii ];
}
}
})
, mDebounceTicks( xDebounceTicks )
{
SISULOG( "In Keyboard Ctor" );
}