コード例 #1
0
	// フレーム更新。
	void UpdateFrame()
	{
		_flags.reset(FRAME_SKIP);
//		if (_frameRateController.GetElapsedTime() > _frameRateController.GetFrameTime() * 2)
//		{
//			// TODO: あまりにもお粗末な処理…ちゃんと考える。
//			_flags.set(FRAME_SKIP);
//		}

		Draw();
		
		_frameRateController.ChangeFrame();
	}
コード例 #2
0
void testFlags() {
	log(LOG_DEBUG, "AWL: testing Flags...");
	Flags flags;
	log(LOG_DEBUG, "AWL: testing Flags 0...");
	flags.resize( 0 );
	GBASSERT( flags.getNumFlags() == 0 );
	GBASSERT( flags.getNumSet() == 0 );
	GBASSERT( flags.getLowestSet() == flags.NoMin );
	GBASSERT( flags.getHighestSet() == flags.NoMax );
	log(LOG_DEBUG, "AWL: testing Flags 1...");
	flags.resize( 1 );
	GBASSERT( flags.getNumFlags() == 1 );
	GBASSERT( ! flags.getFlag( 0 ) );
	GBASSERT( flags.getNumSet() == 0 );
	GBASSERT( flags.getLowestSet() == flags.NoMin );
	GBASSERT( flags.getHighestSet() == flags.NoMax );
	log(LOG_DEBUG, "AWL: testing Flags 2...");
	flags.setFlag( 0, true );
	GBASSERT( flags.getFlag( 0 ) );
	GBASSERT( flags.getLowestSet() == flags.getHighestSet() );
	GBASSERT( flags.getLowestSet() == 0 );
	GBASSERT( flags.getNumSet() == 1 );
	GBASSERT( flags.getHighestSet() >= flags.getLowestSet() );
	log(LOG_DEBUG, "AWL: testing Flags 3...");
	flags.setFlag( 0, false );
	GBASSERT( ! flags.getFlag( 0 ) );
	GBASSERT( flags.getLowestSet() == flags.NoMin );
	GBASSERT( flags.getHighestSet() == flags.NoMax );
	GBASSERT( flags.getNumSet() == 0 );
	log(LOG_DEBUG, "AWL: testing Flags 4...");
	flags.setFlag( 0, true );
	flags.resize( 5 );
	flags.setFlag( 1, true );
	GBASSERT( flags.getNumFlags() == 5 );
	GBASSERT( flags.getFlag(0) );
	GBASSERT( flags.getFlag(1) );
	GBASSERT( flags.getLowestSet() == 0 );
	GBASSERT( flags.getHighestSet() == 1 );
	GBASSERT( flags.getNumSet() == 2 );
	GBASSERT( flags.getHighestSet() >= flags.getLowestSet() );
	log(LOG_DEBUG, "AWL: testing Flags 5...");
	flags.setFlag( 3, true );
	GBASSERT( flags.getFlag( 3 ) );
	GBASSERT( flags.getLowestSet() == 0 );
	GBASSERT( flags.getHighestSet() == 3 );
	GBASSERT( flags.getNumSet() == 3 );
	GBASSERT( flags.getHighestSet() >= flags.getLowestSet() );
	log(LOG_DEBUG, "AWL: testing Flags 6...");
	flags.setFlag( 0, false );
	GBASSERT( ! flags.getFlag( 0 ) );
	GBASSERT( flags.getLowestSet() == 1 );
	GBASSERT( flags.getHighestSet() == 3 );
	GBASSERT( flags.getNumSet() == 2 );
	GBASSERT( flags.getHighestSet() >= flags.getLowestSet() );
	log(LOG_DEBUG, "AWL: testing Flags 7...");
	flags.setFlag( 0, true );
	flags.setFlag( 2, true );
	GBASSERT( flags.getFlag( 0 ) );
	GBASSERT( flags.getFlag( 2 ) );
	GBASSERT( flags.getLowestSet() == 0 );
	GBASSERT( flags.getHighestSet() == 3 );
	GBASSERT( flags.getNumSet() == 4 );
	GBASSERT( flags.getHighestSet() >= flags.getLowestSet() );
	log(LOG_DEBUG, "AWL: testing Flags 8...");
	flags.setFlag( 2, false );
	GBASSERT( ! flags.getFlag( 2 ) );
	GBASSERT( flags.getFlag( 0 ) );
	GBASSERT( flags.getLowestSet() == 0 );
	GBASSERT( flags.getHighestSet() == 3 );
	GBASSERT( flags.getNumSet() == 3 );
	GBASSERT( flags.getHighestSet() >= flags.getLowestSet() );
	log(LOG_DEBUG, "AWL: testing Flags 9...");
	flags.setFlag( 2, 5 );
	flags.setFlag( 3, false );
	GBASSERT( flags.getFlag( 0 ) );
	GBASSERT( 5 == flags.getFlag( 2 ) );
	GBASSERT( ! flags.getFlag( 3 ) );
	GBASSERT( flags.getLowestSet() == 0 );
	GBASSERT( flags.getHighestSet() == 2 );
	GBASSERT( flags.getNumSet() == 3 );
	GBASSERT( flags.getHighestSet() >= flags.getLowestSet() );
	log(LOG_DEBUG, "AWL: testing Flags 10...");
	flags.reset();
	GBASSERT( flags.getNumFlags() == 5 );
	for ( int32_t i = 0; i < flags.getNumFlags(); i++ ) {
		GBASSERT( ! flags.getFlag( i ) );
	}
	GBASSERT( flags.getLowestSet() == flags.NoMin );
	GBASSERT( flags.getHighestSet() == flags.NoMax );
	GBASSERT( flags.getNumSet() == 0 );
	log(LOG_DEBUG, "AWL: Testing Flags 11...");
	flags.setFlag( 0, true );
	flags.setFlag( 2, 0x33 );
	flags.setFlag( 4, true );
	GBASSERT( flags.getFlag( 0 ) );
	GBASSERT( ! flags.getFlag( 1 ) );
	GBASSERT( 0x33 == flags.getFlag( 2 ) );
	GBASSERT( ! flags.getFlag( 3 ) );
	GBASSERT( flags.getFlag( 4 ) );
	GBASSERT( flags.getLowestSet() == 0 );
	GBASSERT( flags.getHighestSet() == 4 );
	GBASSERT( flags.getNumSet() == 3 );
	GBASSERT( flags.getHighestSet() >= flags.getLowestSet() );
	log(LOG_DEBUG, "AWL: Testing Flags 12...");
	flags.resize( 3 );
	GBASSERT( flags.getNumFlags() == 3 );
	GBASSERT( flags.getHighestSet() == 2 );
	GBASSERT( flags.getLowestSet() == 0 );
	GBASSERT( flags.getNumSet() == 2 );
	GBASSERT( flags.getHighestSet() >= flags.getLowestSet() );
	log(LOG_DEBUG, "AWL: Testing Flags 13...");
	flags.resize( 1 );
	GBASSERT( flags.getNumFlags() == 1 );
	GBASSERT( flags.getHighestSet() == 0 );
	GBASSERT( flags.getLowestSet() == 0 );
	GBASSERT( flags.getNumSet() == 1 );
	GBASSERT( flags.getHighestSet() >= flags.getLowestSet() );
	log(LOG_DEBUG, "AWL: Testing Flags 14...");
	flags.reset();
	GBASSERT( flags.getNumSet() == 0 );
	GBASSERT( flags.getNumFlags() == 1 );
	GBASSERT( flags.getLowestSet() == flags.NoMin );
	GBASSERT( flags.getHighestSet() == flags.NoMax );
	for ( int32_t i = 0; i < flags.getNumFlags(); i++ ) {
		GBASSERT( ! flags.getFlag( i ) );
	}	
	const int32_t TESTCASESIZE = 100000;
	if ( ! flags.resize( TESTCASESIZE ) ) {
		log(LOG_DEBUG, "AWL: Cannot allocate memory to test Flags!");
		return;
	}
	GBASSERT( flags.getNumSet() == 0 );
	GBASSERT( flags.getNumFlags() == TESTCASESIZE );
	GBASSERT( flags.getLowestSet() == flags.NoMin );
	GBASSERT( flags.getHighestSet() == flags.NoMax );
	//flags.dumpFlags();
	for ( int32_t i = 0; i < flags.getNumFlags(); i++ ) {
		GBASSERT( ! flags.getFlag( i ) );
	}
	log(LOG_DEBUG, "AWL: Testing Flags 15 (test case size:%"INT32")...", 
	    TESTCASESIZE);
	Timer timer;
	timer.start();
	int32_t cnt = 0;
	int32_t ls = flags.NoMin;
	int32_t hs = flags.NoMax;
	for ( int32_t i = 0; i < TESTCASESIZE; i++ ) {
		int32_t j = random() % TESTCASESIZE;
		char r = random() % 2;
		if ( 0 == r ) {
			r = random() % 256;
			if (r == 0) r = -1;
			char wasSet = flags.getFlag( j );
			if ( ! wasSet ) cnt++;
			flags.setFlag( j, r );
			GBASSERT( flags.getFlag( j ) == r );
			//log(LOG_DEBUG, "AWL: set j:%"INT32" wasSet:%d set:%"INT32", cnt:%"INT32"", 
			//    j, wasSet, flags.getNumSet(), cnt);
			GBASSERT( flags.getNumSet() == cnt );
			GBASSERT( flags.getNumFlags() == TESTCASESIZE );
			if ( hs < j ) {
				GBASSERT( flags.getHighestSet() == j );
				hs = j;
			}
			if ( ls > j ) {
				GBASSERT( flags.getLowestSet() == j );
				ls = j;
			}
			GBASSERT( flags.getHighestSet() >= flags.getLowestSet() );
		}
		else {
			char wasSet = flags.getFlag( j );
			if ( wasSet ) cnt--;
			flags.setFlag( j, false );
			if ( ls == j ) {
				GBASSERT( flags.getLowestSet() == flags.NoMin ||
					     flags.getLowestSet() > j );
				ls = flags.getLowestSet();
			}
			if ( hs == j ) {
				GBASSERT( flags.getHighestSet() == flags.NoMax ||
					     flags.getHighestSet() < j );
				hs = flags.getHighestSet();
			}
			//log(LOG_DEBUG, "AWL: unset j:%"INT32" wasSet:%d set:%"INT32", cnt:%"INT32"", 
			//    j, wasSet, flags.getNumSet(), cnt);
			GBASSERT( ! flags.getFlag( j ) );
			GBASSERT( flags.getNumSet() == cnt );
			GBASSERT( flags.getNumFlags() == TESTCASESIZE );
			if ( cnt > 0 )
				GBASSERT( flags.getHighestSet() >= flags.getLowestSet() );
			else {
				ls = flags.NoMin;
				hs = flags.NoMax;
			}
			GBASSERT( flags.getLowestSet() == ls );
			GBASSERT( flags.getHighestSet() == hs );
		}
	}
	flags.reset();
	GBASSERT( flags.getNumFlags() == TESTCASESIZE );
	GBASSERT( flags.getHighestSet() == flags.NoMax );
	GBASSERT( flags.getLowestSet() == flags.NoMin );
	GBASSERT( flags.getNumSet() == 0 );
	for ( int32_t i = 0; i < flags.getNumFlags(); i++ ) {
		GBASSERT( ! flags.getFlag( i ) );
	}
	timer.stop();
	log("AWL: Flags %"INT32" tests took %lld ms", TESTCASESIZE, timer.getSpan());
	log(LOG_DEBUG, "AWL: Flags tests passed. :)");
}