void ParticleRenderer::updateEBO()
{
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_eboArray[m_frameId]);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLushort) * getNumActive(), m_particleSystem->getSortedIndices(), GL_DYNAMIC_DRAW);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
    CHECK_GL_ERROR();
}
Example #2
0
void ParticleInitializer::depthSortEfficient(const vec3f& halfVector)
{
    // calculate eye-space z
    for (int32_t i = 0; i < getNumActive(); ++i)
    {
        float z = -dot(halfVector, truncate(m_pos[i]));  // project onto vector
        m_zs[i] = z;
    }

    // sort
    m_sorter.Sort(m_zs, getNumActive());

    const GLuint *sortedIndices32 = m_sorter.GetIndices();
    for (int32_t i = 0; i < getNumActive(); ++i)
    {
        m_sortedIndices16[i] = (GLushort) sortedIndices32[i];
    }
}
void ParticleRenderer::createVBO()
{
    deleteVBO();

    glGenBuffers(1, &m_vbo);
    glBindBuffer(GL_ARRAY_BUFFER, m_vbo);
    glBufferData(GL_ARRAY_BUFFER, 3 * sizeof(float) * getNumActive(), m_particleSystem->getPositions(), GL_STATIC_DRAW);
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    CHECK_GL_ERROR();
}
void ParticleRenderer::createEBOs()
{
    deleteEBOs();

    // to avoid CPU<->GPU sync points when updating DYNAMIC buffers,
    // use an array of buffers and use the least-recently-used one each frame.
    m_eboArray = new GLuint[m_eboCount];
    glGenBuffers(m_eboCount, m_eboArray);

    for (int i = 0; i < m_eboCount; ++i)
    {
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_eboArray[i]);
        glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLushort) * getNumActive(), NULL, GL_DYNAMIC_DRAW);
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
        CHECK_GL_ERROR();
    }
}
Example #5
0
void ParticleInitializer::simulate()
{
    //m_timeCondition.Acquire();
    //m_timeCondition.Wait();
    const float dt = m_elapsedTime;
    //m_timeCondition.Release();

    const vec4f wind(4.7f, 0.0f, 3.1f, 0.0f);
    for (int32_t i = 0; i < getNumActive(); i++)
    {
        m_pos[i] += dt * wind;
        wrapPos(m_width, m_pos[i]);
    }

    //m_timeCondition.Acquire();
    m_elapsedTime -= dt;
    //m_timeCondition.Release();
}
void ParticleRenderer::depthSort(SceneInfo& scene)
{
    m_particleSystem->depthSort(scene.m_halfVector);

    m_batchSize = getNumActive() / (int)m_params.numSlices;
}
Example #7
0
optional<CampaignSetup> CampaignBuilder::prepareCampaign(function<optional<RetiredGames>(CampaignType)> genRetired,
    CampaignType type, string worldName) {
  Vec2 size(17, 9);
  int numBlocked = 0.6 * size.x * size.y;
  Table<Campaign::SiteInfo> terrain = getTerrain(random, size, numBlocked);
  auto retired = genRetired(type);
  View::CampaignMenuState menuState { true, false};
  setCountLimits(options);
  const auto playerRole = getPlayerRole();
  while (1) {
    Campaign campaign(terrain, type, playerRole, worldName);
    if (auto pos = considerStaticPlayerPos(campaign)) {
      campaign.clearSite(*pos);
      setPlayerPos(campaign, *pos, avatarInfo.playerCreature->getMaxViewIdUpgrade());
    }
    placeVillains(campaign, getVillainCounts(type, options), retired, avatarInfo.tribeAlignment);
    while (1) {
      bool updateMap = false;
      campaign.influenceSize = options->getIntValue(OptionId::INFLUENCE_SIZE);
      campaign.refreshInfluencePos();
      CampaignAction action = autoConfirm(type) ? CampaignActionId::CONFIRM
          : view->prepareCampaign({
              campaign,
              (retired && type == CampaignType::FREE_PLAY) ? optional<RetiredGames&>(*retired) : none,
              avatarInfo.playerCreature.get(),
              getPrimaryOptions(),
              getSecondaryOptions(type),
              getSiteChoiceTitle(type),
              getIntroText(),
              getAvailableTypes().transform([](CampaignType t) -> View::CampaignOptions::CampaignTypeInfo {
                  return {t, getCampaignTypeDescription(t)};}),
              getMenuWarning(type)
              }, options, menuState);
      switch (action.getId()) {
        case CampaignActionId::REROLL_MAP:
          terrain = getTerrain(random, size, numBlocked);
          updateMap = true;
          break;
        case CampaignActionId::UPDATE_MAP:
          updateMap = true;
          break;
        case CampaignActionId::CHANGE_TYPE:
          type = action.get<CampaignType>();
          retired = genRetired(type);
          updateMap = true;
          break;
        case CampaignActionId::UPDATE_OPTION:
          switch (action.get<OptionId>()) {
            case OptionId::PLAYER_NAME:
            case OptionId::GENERATE_MANA:
            case OptionId::INFLUENCE_SIZE:
              break;
            default:
              updateMap = true;
              break;
          }
          break;
        case CampaignActionId::CANCEL:
          return none;
        case CampaignActionId::CHOOSE_SITE:
          if (!considerStaticPlayerPos(campaign))
            setPlayerPos(campaign, action.get<Vec2>(), avatarInfo.playerCreature->getMaxViewIdUpgrade());
          break;
        case CampaignActionId::CONFIRM:
          if (!retired || retired->getNumActive() > 0 || playerRole != PlayerRole::KEEPER ||
              retired->getAllGames().empty() ||
              view->yesOrNoPrompt("The imps are going to be sad if you don't add any retired dungeons. Continue?")) {
            string name = avatarInfo.playerCreature->getName().firstOrBare();
            string gameIdentifier = name + "_" + campaign.worldName + getNewIdSuffix();
            string gameDisplayName = name + " of " + campaign.worldName;
            return CampaignSetup{campaign, gameIdentifier, gameDisplayName,
                getIntroMessages(type)};
          }
      }
      if (updateMap)
        break;
    }
  }
}