Ejemplo n.º 1
0
void MainMenuState::doUpdate(sf::Time dt, sf::RenderTarget &target)
{
    float scale = 1.f + 0.05f * std::sin(getTimeSinceStart().asSeconds());
    m_logoSprite.setScale(sf::Vector2f(scale, scale));

    m_playerSprite.update(dt.asSeconds());

    //Move the ground
    m_groundSprite.setPosition(sf::Vector2f(
        m_groundSprite.getPosition().x - dt.asSeconds() * 200,
        m_groundSprite.getPosition().y
    ));
    while(m_groundSprite.getPosition().x <= -128.f)
    {
        m_groundSprite.setPosition(sf::Vector2f(
            m_groundSprite.getPosition().x + 128.f,
            m_groundSprite.getPosition().y
        ));
    }

    //Move the player to the mouse if it is dragged
    if(m_draggingPlayer)
    {
        //TODO: Forbid the user to put the player sprite under the ground
        sf::Vector2f playerDestination =
            target.mapPixelToCoords(sf::Mouse::getPosition(dynamic_cast<sf::RenderWindow&>(target))) - m_offsetToPlayer;
        m_playerSprite.setPosition(
            playerDestination.x, std::min(playerDestination.y, 370.f)
        );
    }
    else //Move the player sprite back to its position after a drag
    {
        //Drag down the player when not dragged by the mouse
        if(m_playerSprite.getPosition().y < 370.f)
        {
            m_playerSprite.setPosition(
                m_playerSprite.getPosition().x, m_playerSprite.getPosition().y + 400 * dt.asSeconds()
            );
        }
        else if(m_playerSprite.getPosition().y > 370.f)
        {
            m_playerSprite.setPosition(
                sf::Vector2f(m_playerSprite.getPosition().x, 370.f)
            );
        }
    }

    //Reset the animation to "default" when he's on the floor
    if(m_playerSprite.getPosition().y >= 370.f && m_playerSprite.getCurrentAnimation() != "default")
    {
        m_playerSprite.setCurrentAnimation("default");
    }
    else if(m_playerSprite.getPosition().y < 370.f && m_playerSprite.getCurrentAnimation() != "jump")
    {
        m_playerSprite.setCurrentAnimation("jump");
    }
}
Ejemplo n.º 2
0
void LevelLoadingState::render(sf::RenderTarget& target)
{
    target.clear(sf::Color(0, 0, 0));

    if(!m_errored)
        m_loadingText.setColor(sf::Color(255, 255, 255, 127.f + 127.f * std::sin(getTimeSinceStart().asSeconds() * 10.f)));
    else
        m_loadingText.setColor(sf::Color(255, 80, 80, 255));

    m_loadingStatusMutex.lock();
    m_loadingStatusText.setString(m_loadingStatusString);
    m_loadingStatusMutex.unlock();

    //Text positioning
    m_loadingText.setPosition(sf::Vector2f(512.f - m_loadingText.getLocalBounds().width/2.f, 384.f - m_loadingText.getLocalBounds().height/2.f));
    m_loadingStatusText.setPosition(sf::Vector2f(512.f - m_loadingStatusText.getLocalBounds().width/2.f, m_loadingText.getPosition().y + m_loadingText.getLocalBounds().top + m_loadingText.getLocalBounds().height + 32.f));

    target.draw(m_loadingText);
    target.draw(m_loadingStatusText);
}
Ejemplo n.º 3
0
void LLViewerStatsRecorder::writeToLog( F32 interval )
{
	size_t data_size = 0;
	F64 delta_time = LLTimer::getTotalSeconds() - mLastSnapshotTime;
	S32 total_objects = mObjectCacheHitCount + mObjectCacheMissCrcCount + mObjectCacheMissFullCount + mObjectFullUpdates + mObjectTerseUpdates + mObjectCacheMissRequests + mObjectCacheMissResponses + mObjectCacheUpdateDupes + mObjectCacheUpdateChanges + mObjectCacheUpdateAdds + mObjectCacheUpdateReplacements + mObjectUpdateFailures;

	if ( delta_time < interval || total_objects == 0) return;

	mLastSnapshotTime = LLTimer::getTotalSeconds();
	LL_DEBUGS() << "ILX: " 
		<< mObjectCacheHitCount << " hits, " 
		<< mObjectCacheMissFullCount << " full misses, "
		<< mObjectCacheMissCrcCount << " crc misses, "
		<< mObjectFullUpdates << " full updates, "
		<< mObjectTerseUpdates << " terse updates, "
		<< mObjectCacheMissRequests << " cache miss requests, "
		<< mObjectCacheMissResponses << " cache miss responses, "
		<< mObjectCacheUpdateDupes << " cache update dupes, "
		<< mObjectCacheUpdateChanges << " cache update changes, "
		<< mObjectCacheUpdateAdds << " cache update adds, "
		<< mObjectCacheUpdateReplacements << " cache update replacements, "
		<< mObjectUpdateFailures << " update failures"
		<< LL_ENDL;

	if (mObjectCacheFile == NULL)
	{
		mStartTime = LLTimer::getTotalSeconds();
		mObjectCacheFile = LLFile::fopen(STATS_FILE_NAME, "wb");
		if (mObjectCacheFile)
		{	// Write column headers
			std::ostringstream data_msg;
			data_msg << "EventTime(ms)\t"
				<< "Cache Hits\t"
				<< "Cache Full Misses\t"
				<< "Cache Crc Misses\t"
				<< "Full Updates\t"
				<< "Terse Updates\t"
				<< "Cache Miss Requests\t"
				<< "Cache Miss Responses\t"
				<< "Cache Update Dupes\t"
				<< "Cache Update Changes\t"
				<< "Cache Update Adds\t"
				<< "Cache Update Replacements\t"
				<< "Update Failures\t"
				<< "Cache Hits bps\t"
				<< "Cache Full Misses bps\t"
				<< "Cache Crc Misses bps\t"
				<< "Full Updates bps\t"
				<< "Terse Updates bps\t"
				<< "Cache Miss Responses bps\t"
				<< "Texture Fetch bps\t"
				<< "\n";

			data_size = data_msg.str().size();
			if (fwrite(data_msg.str().c_str(), 1, data_size, mObjectCacheFile ) != data_size)
			{
				LL_WARNS() << "failed to write full headers to " << STATS_FILE_NAME << LL_ENDL;
			}
		}
		else
		{
			//LL_WARNS() << "Couldn't open " << STATS_FILE_NAME << " for logging." << LL_ENDL;
			return;
		}
	}

	std::ostringstream data_msg;

	data_msg << getTimeSinceStart()
		<< "\t " << mObjectCacheHitCount
		<< "\t" << mObjectCacheMissFullCount
		<< "\t" << mObjectCacheMissCrcCount
		<< "\t" << mObjectFullUpdates
		<< "\t" << mObjectTerseUpdates
		<< "\t" << mObjectCacheMissRequests
		<< "\t" << mObjectCacheMissResponses
		<< "\t" << mObjectCacheUpdateDupes
		<< "\t" << mObjectCacheUpdateChanges
		<< "\t" << mObjectCacheUpdateAdds
		<< "\t" << mObjectCacheUpdateReplacements
		<< "\t" << mObjectUpdateFailures
		<< "\t" << (mObjectCacheHitSize * 8 / delta_time)
		<< "\t" << (mObjectCacheMissFullSize * 8 / delta_time)
		<< "\t" << (mObjectCacheMissCrcSize * 8 / delta_time)
		<< "\t" << (mObjectFullUpdatesSize * 8 / delta_time)
		<< "\t" << (mObjectTerseUpdatesSize * 8 / delta_time)
		<< "\t" << (mObjectCacheMissResponsesSize * 8 / delta_time)
		<< "\t" << (mTextureFetchSize * 8 / delta_time)
		<< "\n";

	data_size = data_msg.str().size();
	if ( data_size != fwrite(data_msg.str().c_str(), 1, data_size, mObjectCacheFile ))
	{
				LL_WARNS() << "Unable to write complete column data to " << STATS_FILE_NAME << LL_ENDL;
	}

	clearStats();
}
Ejemplo n.º 4
0
int main(int argc, char *argv[]) try
{
   setPath(argv[0]);
   
   bool shaders = true;
   
   // load tune if argument is given
   for (int i=1; i<argc; ++i)
   {
      const std::string arg = argv[i];
      if (arg == "--no-shaders")
         shaders = false;
      else
         loadTune(arg);
   }

   class InitAndQuit
   {
      public:
         InitAndQuit(bool shadersOn)
         {
            if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER) != 0)
            {
               std::ostringstream error;
               error << "Failed on SDL_Init: " << SDL_GetError() << "\n";
               throw std::runtime_error(error.str());
            }
            graphics::setupGraphics(shadersOn);
            SDL_WM_SetCaption("Sousaphone Hero", "Sousaphone Hero");
            if(Mix_OpenAudio(AUDIO_RATE, AUDIO_FORMAT, AUDIO_CHANNELS, AUDIO_BUFFERS) != 0)
            {
               SDL_Quit();
               std::ostringstream error;
               error << "Failed on Mix_OpenAudio: " << Mix_GetError() << "\n";
               throw std::runtime_error(error.str());
            }

            std::srand(time(NULL));

            Mix_ChannelFinished(doChangedNotes); // set callback function

            startTiming();
         }

         ~InitAndQuit()
         {
            graphics::cleanupGraphics();
            Mix_CloseAudio();
            SDL_Quit();
         }
   } iandq(shaders);

   // load all the notes (to load them)
   getNoteA(); getNoteB(); getNoteC(); getNoteD(); getNoteE(); getNoteF(); getNoteG();

   const bool demoMode = false;

   double lastNoteFraction = 0;

   int channel = -1;

   bool tuneStarted = false;

   try
   {
      while(1)
      {
         const double currentNoteFraction = noteFraction();
         if (currentNoteFraction < lastNoteFraction) // i.e. we have wrapped round a note
         {
            incrementTune();
            if (demoMode)
            {
               const char current = getCurrentNote();
               if (current != NO_NOTE_CHARACTER)
               {
                  if (channel != -1)
                     Mix_HaltChannel(channel);

                  channel = Mix_PlayChannelTimed(-1, getNote(current).get(), -1, NOTE_DURATION);
               }
            }
         }
         lastNoteFraction = currentNoteFraction;

         if ((getTimeSinceStart() > graphics::ZOOM_OUT_LENGTH*1000.0) && !tuneStarted)
         {
            startTune();
            tuneStarted = true;
         }

         //SDL_Delay(100);

         doIOLoop();
         playAppropriateNote();
         graphics::draw(currentNoteFraction);
         graphics::updateScreen();
         score::doEveryLoop();
      }
   }
   catch(QuitSignal&)
   {} // do nothing

   return 0;
} catch (std::exception& error)
{
   std::cout << error.what();
   return 1;
}
void LLViewerStatsRecorder::writeToLog( F32 interval )
{
	F64 delta_time = LLTimer::getTotalSeconds() - mLastSnapshotTime;
	S32 total_objects = mObjectCacheHitCount + mObjectCacheMissCrcCount + mObjectCacheMissFullCount + mObjectFullUpdates + mObjectTerseUpdates + mObjectCacheMissRequests + mObjectCacheMissResponses + mObjectCacheUpdateDupes + mObjectCacheUpdateChanges + mObjectCacheUpdateAdds + mObjectCacheUpdateReplacements + mObjectUpdateFailures;

	if ( delta_time < interval || total_objects == 0) return;

	mLastSnapshotTime = LLTimer::getTotalSeconds();
	lldebugs << "ILX: " 
		<< mObjectCacheHitCount << " hits, " 
		<< mObjectCacheMissFullCount << " full misses, "
		<< mObjectCacheMissCrcCount << " crc misses, "
		<< mObjectFullUpdates << " full updates, "
		<< mObjectTerseUpdates << " terse updates, "
		<< mObjectCacheMissRequests << " cache miss requests, "
		<< mObjectCacheMissResponses << " cache miss responses, "
		<< mObjectCacheUpdateDupes << " cache update dupes, "
		<< mObjectCacheUpdateChanges << " cache update changes, "
		<< mObjectCacheUpdateAdds << " cache update adds, "
		<< mObjectCacheUpdateReplacements << " cache update replacements, "
		<< mObjectUpdateFailures << " update failures"
		<< llendl;

	if (mObjectCacheFile == NULL)
	{
		mStartTime = LLTimer::getTotalSeconds();
		mObjectCacheFile = LLFile::fopen(STATS_FILE_NAME, "wb");
		if (mObjectCacheFile)
		{	// Write column headers
			std::ostringstream data_msg;
			data_msg << "EventTime(ms)\t"
				<< "Cache Hits\t"
				<< "Cache Full Misses\t"
				<< "Cache Crc Misses\t"
				<< "Full Updates\t"
				<< "Terse Updates\t"
				<< "Cache Miss Requests\t"
				<< "Cache Miss Responses\t"
				<< "Cache Update Dupes\t"
				<< "Cache Update Changes\t"
				<< "Cache Update Adds\t"
				<< "Cache Update Replacements\t"
				<< "Update Failures\t"
				<< "Cache Hits bps\t"
				<< "Cache Full Misses bps\t"
				<< "Cache Crc Misses bps\t"
				<< "Full Updates bps\t"
				<< "Terse Updates bps\t"
				<< "Cache Miss Responses bps\t"
				<< "Texture Fetch bps\t"
				<< "\n";

			// <FS:ND> Make GCC happy about return value of fwrite not used

			// fwrite(data_msg.str().c_str(), 1, data_msg.str().size(), mObjectCacheFile );

			size_t nWritten = fwrite(data_msg.str().c_str(), 1, data_msg.str().size(), mObjectCacheFile );
			if( nWritten != data_msg.str().size() )
			{
				llwarns << "Write truncated, tried to write " << data_msg.str().size() << " written " << nWritten << llendl;
			}

			// </FS:ND>
		}
		else
		{
			llwarns << "Couldn't open " << STATS_FILE_NAME << " for logging." << llendl;
			return;
		}
	}

	std::ostringstream data_msg;

	data_msg << getTimeSinceStart()
		<< "\t " << mObjectCacheHitCount
		<< "\t" << mObjectCacheMissFullCount
		<< "\t" << mObjectCacheMissCrcCount
		<< "\t" << mObjectFullUpdates
		<< "\t" << mObjectTerseUpdates
		<< "\t" << mObjectCacheMissRequests
		<< "\t" << mObjectCacheMissResponses
		<< "\t" << mObjectCacheUpdateDupes
		<< "\t" << mObjectCacheUpdateChanges
		<< "\t" << mObjectCacheUpdateAdds
		<< "\t" << mObjectCacheUpdateReplacements
		<< "\t" << mObjectUpdateFailures
		<< "\t" << (mObjectCacheHitSize * 8 / delta_time)
		<< "\t" << (mObjectCacheMissFullSize * 8 / delta_time)
		<< "\t" << (mObjectCacheMissCrcSize * 8 / delta_time)
		<< "\t" << (mObjectFullUpdatesSize * 8 / delta_time)
		<< "\t" << (mObjectTerseUpdatesSize * 8 / delta_time)
		<< "\t" << (mObjectCacheMissResponsesSize * 8 / delta_time)
		<< "\t" << (mTextureFetchSize * 8 / delta_time)
		<< "\n";

	// <FS:ND> Make GCC happy about return value of fwrite not used

	// fwrite(data_msg.str().c_str(), 1, data_msg.str().size(), mObjectCacheFile );

	size_t nWritten = fwrite(data_msg.str().c_str(), 1, data_msg.str().size(), mObjectCacheFile );
	if( nWritten != data_msg.str().size() )
	{
		llwarns << "Write truncated, tried to write " << data_msg.str().size() << " written " << nWritten << llendl;
	}

	// </FS:ND>

	clearStats();
}