Exemplo n.º 1
0
int WebPEncode(const WebPConfig* config, WebPPicture* pic) {
  int ok = 0;

  if (pic == NULL)
    return 0;
  WebPEncodingSetError(pic, VP8_ENC_OK);  // all ok so far
  if (config == NULL)  // bad params
    return WebPEncodingSetError(pic, VP8_ENC_ERROR_NULL_PARAMETER);
  if (!WebPValidateConfig(config))
    return WebPEncodingSetError(pic, VP8_ENC_ERROR_INVALID_CONFIGURATION);
  if (pic->width <= 0 || pic->height <= 0)
    return WebPEncodingSetError(pic, VP8_ENC_ERROR_BAD_DIMENSION);
  if (pic->width > WEBP_MAX_DIMENSION || pic->height > WEBP_MAX_DIMENSION)
    return WebPEncodingSetError(pic, VP8_ENC_ERROR_BAD_DIMENSION);

  if (pic->stats != NULL) memset(pic->stats, 0, sizeof(*pic->stats));

  if (!config->lossless) {
    VP8Encoder* enc = NULL;
    if (pic->y == NULL || pic->u == NULL || pic->v == NULL) {
      // Make sure we have YUVA samples.
      if (!WebPPictureARGBToYUVA(pic, WEBP_YUV420)) return 0;
    }

    enc = InitVP8Encoder(config, pic);
    if (enc == NULL) return 0;  // pic->error is already set.
    // Note: each of the tasks below account for 20% in the progress report.
    ok = VP8EncAnalyze(enc);

    // Analysis is done, proceed to actual coding.
    ok = ok && VP8EncStartAlpha(enc);   // possibly done in parallel
    if (!enc->use_tokens_) {
      ok = VP8EncLoop(enc);
    } else {
      ok = VP8EncTokenLoop(enc);
    }
    ok = ok && VP8EncFinishAlpha(enc);
#ifdef WEBP_EXPERIMENTAL_FEATURES
    ok = ok && VP8EncFinishLayer(enc);
#endif

    ok = ok && VP8EncWrite(enc);
    StoreStats(enc);
    if (!ok) {
      VP8EncFreeBitWriters(enc);
    }
    ok &= DeleteVP8Encoder(enc);  // must always be called, even if !ok
  } else {
    // Make sure we have ARGB samples.
    if (pic->argb == NULL && !WebPPictureYUVAToARGB(pic)) {
      return 0;
    }

    ok = VP8LEncodeImage(config, pic);  // Sets pic->error in case of problem.
  }

  return ok;
}
void EngineStatePlayerStats::InitPlayer()
{
  PoolGameState::PlayerInfo* pInfo = 
    GetEngine()->GetGameState()->GetPlayerInfo(m_currentPlayer);
  Assert(pInfo);

  std::string charname = pInfo->m_name;
 
  m_pChar = new CharacterGameObject;
  Character* pChar = CharacterManager::Instance()->GetCharacter(charname);
  Assert(pChar);
  m_pChar->AddMesh(pChar);

  std::string playername = "player ";
  playername += ToString(m_currentPlayer + 1); // make it one-based
  playername += " -  "; 
  playername += charname;
  m_pComp = TextFactory::Instance()->Create(playername); 

  // For each stat in player info, set the guage.
  int sz = m_nameGuages.size();
  Assert((int)pInfo->m_stats.size() == sz);

  // Have any stats changed since last time ?
  // If so, play a wav
  // TODO play a happy or sad wav depending on movement - but this is hard,
  // because some stats could go up, and others down. Best if the wav is
  // neutral, just to indicate a change.
  bool hasChanged = false;
  // Compare old values with current values, where old values exist.
  
  std::vector<float> oldStats = GetStats(m_currentPlayer);
  for (int i = 0; i < sz; i++)
  {
    float newval = pInfo->m_stats[i];

    Assert((int)oldStats.size() >= i);
    if ((int)oldStats.size() == i)
    {
      oldStats.push_back(newval);
    }

    float oldval = oldStats[i];
    if (oldval != newval)
    {
      hasChanged = true;
      break;
    }
  }
  StoreStats(m_currentPlayer, oldStats);

  if (hasChanged)
  {
    std::string wav = GetEngine()->GetConfigValue("stat_change_wav");
    GetEngine()->PlayWav(wav);
  }
}
void EngineStatePlayerStats::Red(bool down)
{
  if (!down)
  {
    return;
  }

  // If changing state do nothing
  if (GetEngine()->IsFading())
  {
    return;
  }

  // So transitions work for all players.
  m_time = 0;
  // Store the new stats for this player.
  PoolGameState::PlayerInfo* pInfo = 
    GetEngine()->GetGameState()->GetPlayerInfo(m_currentPlayer);
  Assert(pInfo);
  StoreStats(m_currentPlayer, pInfo->m_stats);

  // Show next player's stats
  ++m_currentPlayer;
  int numPlayers = GetEngine()->GetGameState()->GetNumberOfPlayers();
  Assert(m_currentPlayer <= numPlayers);
  if (m_currentPlayer == numPlayers)
  {
    // Final player has been displayed. Go to next state.
    Finished();
    // Restore current player so we can fade out if required.
    --m_currentPlayer;
  }
  else
  {
    InitPlayer();
    // TODO sound effect
  }
  
}
Exemplo n.º 4
0
int WebPEncode(const WebPConfig* const config, WebPPicture* const pic) {
  VP8Encoder* enc;
  int ok;

  if (pic == NULL)
    return 0;
  WebPEncodingSetError(pic, VP8_ENC_OK);  // all ok so far
  if (config == NULL)  // bad params
    return WebPEncodingSetError(pic, VP8_ENC_ERROR_NULL_PARAMETER);
  if (!WebPValidateConfig(config))
    return WebPEncodingSetError(pic, VP8_ENC_ERROR_INVALID_CONFIGURATION);
  if (pic->width <= 0 || pic->height <= 0)
    return WebPEncodingSetError(pic, VP8_ENC_ERROR_BAD_DIMENSION);
  if (pic->y == NULL || pic->u == NULL || pic->v == NULL)
    return WebPEncodingSetError(pic, VP8_ENC_ERROR_NULL_PARAMETER);
  if (pic->width > WEBP_MAX_DIMENSION || pic->height > WEBP_MAX_DIMENSION)
    return WebPEncodingSetError(pic, VP8_ENC_ERROR_BAD_DIMENSION);

  enc = InitEncoder(config, pic);
  if (enc == NULL) return 0;  // pic->error is already set.
  // Note: each of the tasks below account for 20% in the progress report.
  ok = VP8EncAnalyze(enc)
    && VP8StatLoop(enc)
    && VP8EncLoop(enc)
    && VP8EncFinishAlpha(enc)
#ifdef WEBP_EXPERIMENTAL_FEATURES
    && VP8EncFinishLayer(enc)
#endif
    && VP8EncWrite(enc);
  StoreStats(enc);
  if (!ok) {
    VP8EncFreeBitWriters(enc);
  }
  DeleteEncoder(enc);

  return ok;
}
Exemplo n.º 5
0
int WebPEncode(const WebPConfig* config, WebPPicture* pic) {
  int ok = 0;

  if (pic == NULL)
    return 0;
  WebPEncodingSetError(pic, VP8_ENC_OK);  // all ok so far
  if (config == NULL)  // bad params
    return WebPEncodingSetError(pic, VP8_ENC_ERROR_NULL_PARAMETER);
  if (!WebPValidateConfig(config))
    return WebPEncodingSetError(pic, VP8_ENC_ERROR_INVALID_CONFIGURATION);
  if (pic->width <= 0 || pic->height <= 0)
    return WebPEncodingSetError(pic, VP8_ENC_ERROR_BAD_DIMENSION);
  if (pic->width > WEBP_MAX_DIMENSION || pic->height > WEBP_MAX_DIMENSION)
    return WebPEncodingSetError(pic, VP8_ENC_ERROR_BAD_DIMENSION);

  if (pic->stats != NULL) memset(pic->stats, 0, sizeof(*pic->stats));

  if (!config->lossless) {
    VP8Encoder* enc = NULL;
    if (pic->y == NULL || pic->u == NULL || pic->v == NULL) {
      // Make sure we have YUVA samples.
      float dithering = 0.f;
      if (config->preprocessing & 2) {
        const float x = config->quality / 100.f;
        const float x2 = x * x;
        // slowly decreasing from max dithering at low quality (q->0)
        // to 0.5 dithering amplitude at high quality (q->100)
        dithering = 1.0f + (0.5f - 1.0f) * x2 * x2;
      }
      if (!WebPPictureARGBToYUVADithered(pic, WEBP_YUV420, dithering)) {
        return 0;
      }
    }

    enc = InitVP8Encoder(config, pic);
    if (enc == NULL) return 0;  // pic->error is already set.
    // Note: each of the tasks below account for 20% in the progress report.
    ok = VP8EncAnalyze(enc);

    // Analysis is done, proceed to actual coding.
    ok = ok && VP8EncStartAlpha(enc);   // possibly done in parallel
    if (!enc->use_tokens_) {
      ok = ok && VP8EncLoop(enc);
    } else {
      ok = ok && VP8EncTokenLoop(enc);
    }
    ok = ok && VP8EncFinishAlpha(enc);

    ok = ok && VP8EncWrite(enc);
    StoreStats(enc);
    if (!ok) {
      VP8EncFreeBitWriters(enc);
    }
    ok &= DeleteVP8Encoder(enc);  // must always be called, even if !ok
  } else {
    // Make sure we have ARGB samples.
    if (pic->argb == NULL && !WebPPictureYUVAToARGB(pic)) {
      return 0;
    }

    ok = VP8LEncodeImage(config, pic);  // Sets pic->error in case of problem.
  }

  return ok;
}