Пример #1
0
void EffectGlow::Render(int x, int y, int w, int h)
{
    if (!effect_glow::enable)
        return;
    if (!init)
        Init();
    if (!isHackActive() || (g_IEngine->IsTakingScreenshot() && clean_screenshots) || g_Settings.bInvalid)
        return;
    CMatRenderContextPtr ptr(GET_RENDER_CONTEXT);

    ptr->ClearColor4ub(0, 0, 0, 255);
    ptr->PushRenderTargetAndViewport(mat_fullframe);
    ptr->ClearBuffers(true, true);
    ptr->OverrideAlphaWriteEnable(true, true);
    ptr->PopRenderTargetAndViewport();
    ptr->ClearStencilBufferRectangle(0, 0, w, h, 0);
    ptr->DepthRange(0.0f, 0.01f);

    SS_First.SetStencilState(ptr);

    drawing = true;
    for (int i = 1; i <= HIGHEST_ENTITY; i++)
    {
        IClientEntity *ent = g_IEntityList->GetClientEntity(i);
        if (ent && !ent->IsDormant() && ShouldRenderGlow(ent))
        {
            ptr->PushRenderTargetAndViewport(mat_fullframe);
            g_IVRenderView->SetColorModulation(GlowColor(ent));
            g_IVModelRender->ForcedMaterialOverride(mat_glow);
            DrawEntity(ent);
            ptr->PopRenderTargetAndViewport();

            g_IVRenderView->SetBlend(0.0f);
            g_IVModelRender->ForcedMaterialOverride(mat_unlit_z);
            DrawEntity(ent);
            g_IVRenderView->SetBlend(1.0f);
        }
    }
    drawing = false;

    SS_Last.SetStencilState(ptr);

    g_IVModelRender->ForcedMaterialOverride(NULL);

    ptr->DepthRange(0.0f, 1.0f);
    ptr->DrawScreenSpaceRectangle(mat_halo, x, y, w, h, 0, 0, w, h, w, h);
    ptr->SetStencilEnable(false);
}
Пример #2
0
/*
 * This could probably use some optimization.  Every time we draw the map,
 * we do n filter operations, then n sort operations.  huuurk.
 * Maybe keep the entity linked list y sorted at all times by reordering
 * whenever a y value changes.  That's only O(n) as opposed to O(nlogn) or
 * whatever unholy growth rate this is.
 *
 * Update: meh.  Sorting doesn't seem to be a bottleneck.
 */
void Engine::RenderEntities(uint layerIndex) {
    CDEBUG("renderentities");
    std::vector<Entity*>     drawlist;
    const Point res = video->GetResolution();
    const Map::Layer* layer = map.GetLayer(layerIndex);

    int xw = (xwin * layer->parallax.mulx / layer->parallax.divx) - layer->x;
    int yw = (ywin * layer->parallax.muly / layer->parallax.divy) - layer->y;

    // first, get a list of entities onscreen
    uint width, height;
    for (EntityList::iterator i = entities.begin(); i != entities.end(); i++) {
        Entity* e = *i;
        const Sprite* sprite = e->sprite;

        if (e->layerIndex != layerIndex)    continue;   // wrong layer
        if (!sprite)                        continue;   // no sprite? @_x

        width = sprite->Width();
        height = sprite->Height();

        // get the coodinates at which the sprite would be drawn
        int x = e->x - sprite->nHotx + layer->x - xw;
        int y = e->y - sprite->nHoty + layer->y - yw;

        if (x + width > 0 && y + height > 0 &&
            x < res.x     && y < res.y      &&
            e->isVisible
        ) {
            drawlist.push_back(e);                                                          // the entity is onscreen, tag it.
        }
    }

    if (!drawlist.empty()) {
        // Sort them by y value. (see the CompareEntity functor above)
        std::sort(drawlist.begin(), drawlist.end(), CompareEntities());

        video->SetBlendMode(Video::Normal);
        for (std::vector<Entity*>::iterator j = drawlist.begin(); j != drawlist.end(); j++) {
#if 0
            const Entity* e = *j;
            const Sprite* s = e->sprite;
            int x = e->x - xwin - s->nHotx + layer->x;
            int y = e->y - ywin - s->nHoty + layer->y;

            DrawEntity(e, x, y);
#else
            RenderEntity(*j);
#endif
        }
    }
}
// ----------------------------------------------------------------------------
void vHavokChainConstraintChainRenderer::OnRender()
{
  // Check prerequisites: entity, render context, visibility collector
  if (!m_spChainEntity)
    return;
  VisRenderContextPtr spContext = Vision::Contexts.GetCurrentContext();
  if (!spContext)
    return;
  IVisVisibilityCollectorPtr spVisCollector = spContext->GetVisibilityCollector();
  if (!spVisCollector)
    return;
  VisFrustum_cl const* pFrustum = spVisCollector->GetBaseFrustum();

  // Make entity visible for drawing
  m_spChainEntity->SetVisibleBitmask(VIS_ENTITY_VISIBLE);

  // For each chain link: move the entity bounding box accordingly,
  // check visibility, and then draw the entity there if visible.
  for (unsigned int i = 0; i < m_pConstraintChain->GetNumLinks(); ++i)
  {
    hkvMat3 mRot;
    hkvVec3 vTrans;
    m_pConstraintChain->GetLinkTransform(i, mRot, vTrans);
    m_spChainEntity->SetRotationMatrix(mRot);
    m_spChainEntity->SetPosition(vTrans);
    m_spChainEntity->UpdateVisBoundingBox();

    hkvAlignedBBox const& bBox = *m_spChainEntity->GetCurrentVisBoundingBoxPtr();
    if ((!pFrustum) || pFrustum->Overlaps(bBox))
    {
      DrawEntity(VPT_PrimaryOpaquePass);
      DrawEntity(VPT_SecondaryOpaquePass);
      DrawEntity(VPT_TransparentPass);
    }
  }

  // Hide entity for regular rendering
  m_spChainEntity->SetVisibleBitmask(VIS_ENTITY_INVISIBLE);
}
Пример #4
0
void Engine::DrawEntity(const Entity* ent) {
    const Sprite* const s = ent->sprite;
    const Map::Layer* const layer = map.GetLayer(ent->layerIndex);

    int xw = (xwin * layer->parallax.mulx / layer->parallax.divx) - layer->x;
    int yw = (ywin * layer->parallax.muly / layer->parallax.divy) - layer->y;

    int x = ent->x - xw - s->nHotx + layer->x;
    int y = ent->y - yw - s->nHoty + layer->y;

    uint frameIndex = (ent->specFrame != -1) ? ent->specFrame : ent->curFrame;

    DrawEntity(ent, x, y, frameIndex);
}
Пример #5
0
    /*!
    * @brief Draws everything that is in the entities list with a sprite component
    * @param dt the time per frame use if needed
    */
    void GLGraphics::Update(float dt)    // Update every frame 
    {
      CameraPtr camera = ENGINE->GetActiveSpace()->GetCamera()->GET_COMPONENT(Camera);
      // clear the buffers to begin a new frame.
      //newFrame();
      // The new frame operation is now handled by the Engine::Update(float) function.

      // Enable alpha blending for opacity.
      glEnable(GL_BLEND);
      glBlendFunc(GL_SRC_ALPHA, GL_ONE);
      
      for (auto &it : _entities)
      {
        DrawEntity(it, camera);
      }
      
    }
Пример #6
0
void Engine::RenderEntity(const Entity* ent) {
    if (ent->renderScript.get() == 0) {
        DrawEntity(ent);
    } else {
        const Sprite* const s = ent->sprite;
        const Map::Layer* const layer = map.GetLayer(ent->layerIndex);

        int xw = (xwin * layer->parallax.mulx / layer->parallax.divx) - layer->x;
        int yw = (ywin * layer->parallax.muly / layer->parallax.divy) - layer->y;

        int x = ent->x - xw - s->nHotx + layer->x;
        int y = ent->y - yw - s->nHoty + layer->y;

        uint frameIndex = (ent->specFrame != -1) ? ent->specFrame : ent->curFrame;

        script.ExecObject(ent->renderScript, ent, x, y, frameIndex);
    }
}
ERR TestControllerLoop()
{
    while(flags & CONTINUE)
    {
        //AddForce(ship->physics_object, 0.0, 10.0, ship->physics_object->cog_x, ship->physics_object->cog_y);        

        SDL_Event event;
        while(SDL_PollEvent(&event) != 0)
        {
            if(event.type == SDL_QUIT)
                 flags ^= CONTINUE;
            else if(event.type == SDL_KEYDOWN && event.key.repeat == 0)
                switch(event.key.keysym.sym)
                {
                case SDLK_UP: 
                    flames->sprite->data[CURRENT_LOOP] ^= 1;
                    flags ^= ENGINE;
                    break;
                case SDLK_DOWN:
                    ship->y_speed = 0.0;
                    ship->x_speed = 0.0;
                    break;
                case SDLK_LEFT: ship->a_speed   = -5.0; break;
                case SDLK_RIGHT: ship->a_speed  = 5.0; break;
                case SDLK_r :
                    yoshi->center_x = 220;
                    yoshi->center_y = 120;
                    yoshi->x_speed = 0;
                    yoshi->y_speed = 0;
                    ship->center_x = 520;
                    ship->center_y = 120;
                    ship->x_speed = 0;
                    ship->y_speed = 0;
                case SDLK_SPACE:
                    tmp = CopyEntity(bolt);
                    tmp->center_x = ship->center_x;
                    tmp->center_y = ship->center_y;
                    tmp->angle = ship->angle;
                    tmp->x_speed = RotateOffsetX(0.0, -10.0, ship->angle);
                    tmp->y_speed = RotateOffsetY(0.0, -10.0, ship->angle);
                    InsertValue(tmp, bolts, 0);
                    break;
                }
            else if(event.type == SDL_KEYUP)
                switch(event.key.keysym.sym)
                {
                case SDLK_UP:
                    flames->sprite->data[CURRENT_LOOP] ^= 1;
                    flags ^= ENGINE;
                    break;
                case SDLK_DOWN: break;
                case SDLK_LEFT: ship->a_speed   = 0.0; break;
                case SDLK_RIGHT: ship->a_speed  = 0.0; break;
                case SDLK_SPACE: 
                    break;
                }
        }

        if(flags & UPDATE)
        {
            if(flags & ENGINE)
                AddForce(ship->physics_object, RotateOffsetX(0.0, -20.0, ship->angle), RotateOffsetY(0.0, -20.0, ship->angle),
                        ship->physics_object->cog_x, ship->physics_object->cog_y);

            if(CheckCollision(ship->collision_object, yoshi->collision_object) != 0)
            {
                printf("BOOM\n");
                //flags ^= CONTINUE;
                AddForce(ship->physics_object, yoshi->x_speed * yoshi->physics_object->mass, yoshi->y_speed * yoshi->physics_object->mass,
                        ship->physics_object->cog_x, ship->physics_object->cog_y);
                AddForce(yoshi->physics_object, ship->x_speed * ship->physics_object->mass, ship->y_speed * ship->physics_object->mass,
                        yoshi->physics_object->cog_x, yoshi->physics_object->cog_y);
            }
            Element* el = bolts->start;
            Entity* tmp = NULL;
            int i = 0;
            while(el != NULL)
            {
                tmp = (Entity*)el->value;
                //if(CheckCollision(ship->collision_object, tmp->collision_object) != 0)
                //{
                //    printf("BOOM\n");
                //    flags ^= CONTINUE;
                //}
                if(CheckCollision(yoshi->collision_object, tmp->collision_object) != 0)
                {
                    AddForce(yoshi->physics_object, RotateOffsetX(0.0, -10.0, tmp->angle), RotateOffsetY(0.0, -10.0, tmp->angle),
                            yoshi->physics_object->cog_x, yoshi->physics_object->cog_y);
                    yoshi->sprite->zoom -= 0.5;
                    if(yoshi->sprite->zoom < 0.5)
                        yoshi->sprite->zoom = 0.5;
                    FreeEntity(tmp);
                    FreeElement(bolts, i);
                }
                i++;
                el = el->next;
            }

            UpdateEntity(ship);

            flames->angle = ship->angle;
            flames->center_x = ship->center_x + RotateOffsetX(0.0, ship->sprite->h * ship->sprite->zoom, ship->angle);
            flames->center_y = ship->center_y + RotateOffsetY(0.0, ship->sprite->h * ship->sprite->zoom, ship->angle);
            UpdateEntity(flames);

            UpdateEntity(yoshi);
            yoshi->sprite->zoom      += 0.01;
            yoshi->physics_object->mass = yoshi->sprite->zoom * 100;
            if(yoshi->physics_object->mass < 1)
                yoshi->physics_object->mass = 1;
            yoshi->collision_object->radius = 32*yoshi->sprite->zoom;
            if(yoshi->collision_object->radius < 1)
                yoshi->collision_object->radius = 1;

            for(i = 0; i < bolts->size; i++)
            {
                Entity* tmp = (Entity*)GetValue(bolts, i);
                if(tmp->center_x < -15 || tmp->center_y < -15 || tmp->center_x > 1000 || tmp->center_y > 500)
                {
                    FreeEntity(tmp);
                    FreeElement(bolts, i);
                }
                else
                    UpdateEntity(tmp);
            }
        }

        if(flags & DRAW)
        {
            ClearPMap(visual_debug);
            DrawEntity(ship);
            DrawEntityDebugInfo(visual_debug, ship);
            DrawEntity(flames);
            DrawEntity(yoshi);
            DrawEntityDebugInfo(visual_debug, yoshi);
            int i;
            for(i = 0; i < bolts->size; i++)
            {
                Entity* tmp = (Entity*)GetValue(bolts, i);
                DrawEntity(tmp);
                DrawEntityDebugInfo(visual_debug, tmp);
            }
            DrawPixelMap(visual_debug);
            Render();
        }
    }
    return ExitTestController();
}
Пример #8
0
void Draw()
{
    if (!radar_enabled)
        return;
    if (!g_IEngine->IsInGame())
        return;
    if (CE_BAD(LOCAL_E))
        return;
    int x, y;
    rgba_t outlineclr;
    std::vector<CachedEntity *> enemies{};
    CachedEntity *ent;

    x              = (int) radar_x;
    y              = (int) radar_y;
    int radar_size = *size;
    int half_size  = radar_size / 2;

    outlineclr = GUIColor();

    draw::Rectangle(x, y, radar_size, radar_size, colors::Transparent(colors::black, 0.4f));
    draw::RectangleOutlined(x, y, radar_size, radar_size, outlineclr, 0.5f);

    if (enemies_over_teammates)
        enemies.clear();
    std::vector<CachedEntity *> sentries;
    for (int i = 1; i < HIGHEST_ENTITY; i++)
    {
        ent = ENTITY(i);
        if (CE_BAD(ent))
            continue;
        if (!ent->m_bAlivePlayer())
            continue;
        if (i == g_IEngine->GetLocalPlayer())
            continue;
        if (!show_teammates && ent->m_Type() == ENTITY_PLAYER && !ent->m_bEnemy())
            continue;
        if (ent->m_iClassID() == CL_CLASS(CObjectSentrygun))
            sentries.push_back(ent);
        else if (!enemies_over_teammates || !show_teammates || ent->m_Type() != ENTITY_PLAYER)
            DrawEntity(x, y, ent);
        else if (ent->m_bEnemy())
            enemies.push_back(ent);
        else
            DrawEntity(x, y, ent);
    }
    if (enemies_over_teammates && show_teammates)
        for (auto enemy : enemies)
            DrawEntity(x, y, enemy);
    for (auto Sentry : sentries)
        DrawEntity(x, y, Sentry);
    if (CE_GOOD(LOCAL_E))
    {
        DrawEntity(x, y, LOCAL_E);
        const auto &wtr = WorldToRadar(g_pLocalPlayer->v_Origin.x, g_pLocalPlayer->v_Origin.y);
        if (!use_icons)
            draw::RectangleOutlined(x + wtr.first, y + wtr.second, int(icon_size), int(icon_size), GUIColor(), 0.5f);
    }

    draw::Line(x + half_size, y + half_size / 2, 0, half_size, colors::Transparent(GUIColor(), 0.4f), 0.5f);
    draw::Line(x + half_size / 2, y + half_size, half_size, 0, colors::Transparent(GUIColor(), 0.4f), 0.5f);
}