// TMP TMP static void viewportToScissor(const CViewport &vp, CScissor &scissor) { scissor.X = vp.getX(); scissor.Y = vp.getY(); scissor.Width = vp.getWidth(); scissor.Height = vp.getHeight(); }
/** ** Handle scrolling area. ** ** @param state Scroll direction/state. ** @param fast Flag scroll faster. ** ** @todo Support dynamic acceleration of scroll speed. ** @todo If the scroll key is longer pressed the area is scrolled faster. */ void DoScrollArea(int state, bool fast, bool isKeyboard) { CViewport *vp; int stepx; int stepy; static int remx = 0; // FIXME: docu static int remy = 0; // FIXME: docu int speed = isKeyboard ? UI.KeyScrollSpeed : UI.MouseScrollSpeed; if (state == ScrollNone) { return; } vp = UI.SelectedViewport; if (fast) { stepx = (int)(speed * vp->MapWidth / 2 * PixelTileSize.x * FRAMES_PER_SECOND / 4); stepy = (int)(speed * vp->MapHeight / 2 * PixelTileSize.y * FRAMES_PER_SECOND / 4); } else {// dynamic: let these variables increase up to fast.. // FIXME: pixels per second should be configurable stepx = (int)(speed * PixelTileSize.x * FRAMES_PER_SECOND / 4); stepy = (int)(speed * PixelTileSize.y * FRAMES_PER_SECOND / 4); } if ((state & (ScrollLeft | ScrollRight)) && (state & (ScrollLeft | ScrollRight)) != (ScrollLeft | ScrollRight)) { stepx = stepx * 100 * 100 / VideoSyncSpeed / FRAMES_PER_SECOND / (SkipFrames + 1); remx += stepx - (stepx / 100) * 100; stepx /= 100; if (remx > 100) { ++stepx; remx -= 100; } } else { stepx = 0; } if ((state & (ScrollUp | ScrollDown)) && (state & (ScrollUp | ScrollDown)) != (ScrollUp | ScrollDown)) { stepy = stepy * 100 * 100 / VideoSyncSpeed / FRAMES_PER_SECOND / (SkipFrames + 1); remy += stepy - (stepy / 100) * 100; stepy /= 100; if (remy > 100) { ++stepy; remy -= 100; } } else { stepy = 0; } if (state & ScrollUp) { stepy = -stepy; } if (state & ScrollLeft) { stepx = -stepx; } const PixelDiff offset(stepx, stepy); vp->Set(vp->MapPos, vp->Offset + offset); // This recalulates some values HandleMouseMove(CursorScreenPos); }
/* virtual */ PixelPos COrder_Follow::Show(const CViewport &vp, const PixelPos &lastScreenPos) const { PixelPos targetPos; if (this->HasGoal()) { //Wyrmgus start if (this->GetGoal()->MapLayer != CurrentMapLayer) { return lastScreenPos; } //Wyrmgus end targetPos = vp.MapToScreenPixelPos(this->GetGoal()->GetMapPixelPosCenter()); } else { //Wyrmgus start if (this->MapLayer != CurrentMapLayer) { return lastScreenPos; } //Wyrmgus end targetPos = vp.TilePosToScreen_Center(this->goalPos); } //Wyrmgus start // Video.FillCircleClip(ColorGreen, lastScreenPos, 2); // Video.DrawLineClip(ColorGreen, lastScreenPos, targetPos); // Video.FillCircleClip(ColorGreen, targetPos, 3); if (Preference.ShowPathlines) { Video.FillCircleClip(ColorGreen, lastScreenPos, 2); Video.DrawLineClip(ColorGreen, lastScreenPos, targetPos); Video.FillCircleClip(ColorGreen, targetPos, 3); } //Wyrmgus end return targetPos; }
void ParaEngine::CViewportManager::GetPointOnViewport(int& x, int& y, int* pWidth, int* pHeight) { CViewport* pViewPort = GetActiveViewPort(); if (pViewPort) { pViewPort->GetPointOnViewport(x, y, pWidth, pHeight); } }
/** ** Handle scrolling area. ** ** @param state Scroll direction/state. ** @param fast Flag scroll faster. ** ** @todo Support dynamic acceleration of scroll speed. ** @todo If the scroll key is longer pressed the area is scrolled faster. */ void DoScrollArea(int state, bool fast) { CViewport *vp; int stepx; int stepy; static int remx = 0; // FIXME: docu static int remy = 0; // FIXME: docu if (state == ScrollNone) { return; } vp = UI.SelectedViewport; if (fast) { stepx = vp->MapWidth / 2 * TileSizeX * FRAMES_PER_SECOND; stepy = vp->MapHeight / 2 * TileSizeY * FRAMES_PER_SECOND; } else {// dynamic: let these variables increase upto fast.. // FIXME: pixels per second should be configurable stepx = TileSizeX * FRAMES_PER_SECOND; stepy = TileSizeY * FRAMES_PER_SECOND; } if ((state & (ScrollLeft | ScrollRight)) && (state & (ScrollLeft | ScrollRight)) != (ScrollLeft | ScrollRight)) { stepx = stepx * 100 * 100 / VideoSyncSpeed / FRAMES_PER_SECOND / (SkipFrames + 1); remx += stepx - (stepx / 100) * 100; stepx /= 100; if (remx > 100) { ++stepx; remx -= 100; } } else { stepx = 0; } if ((state & (ScrollUp | ScrollDown)) && (state & (ScrollUp | ScrollDown)) != (ScrollUp | ScrollDown)) { stepy = stepy * 100 * 100 / VideoSyncSpeed / FRAMES_PER_SECOND / (SkipFrames + 1); remy += stepy - (stepy / 100) * 100; stepy /= 100; if (remy > 100) { ++stepy; remy -= 100; } } else { stepy = 0; } if (state & ScrollUp) { stepy = -stepy; } if (state & ScrollLeft) { stepx = -stepx; } vp->Set(vp->MapX, vp->MapY, vp->OffsetX + stepx, vp->OffsetY + stepy); // This recalulates some values HandleMouseMove(CursorX, CursorY); }
/** ** Takes coordinates of a pixel in stratagus's window and computes ** the map viewport which contains this pixel. ** ** @param screenPos pixel coordinate with origin at UL corner of screen ** ** @return viewport pointer or null if this pixel is not inside ** any of the viewports. ** ** @note This functions only works with rectangular viewports, when ** we support shaped map window, this must be rewritten. */ CViewport *GetViewport(const PixelPos &screenPos) { for (CViewport *vp = UI.Viewports; vp < UI.Viewports + UI.NumViewports; ++vp) { if (vp->Contains(screenPos)) { return vp; } } return nullptr; }
CViewport* ParaEngine::CViewportManager::GetViewportByPoint(int x, int y) { for (auto iter = m_viewportList.begin(); iter != m_viewportList.end(); iter++) { CViewport* pViewPort = *iter; if (pViewPort) { if (pViewPort->IsPointOnViewport(x, y)) return pViewPort; } } return NULL; }
/* virtual */ PixelPos COrder_Repair::Show(const CViewport &vp, const PixelPos &lastScreenPos) const { PixelPos targetPos; if (this->ReparableTarget != NULL) { targetPos = vp.MapToScreenPixelPos(this->ReparableTarget->GetMapPixelPosCenter()); } else { targetPos = vp.TilePosToScreen_Center(this->goalPos); } Video.FillCircleClip(ColorGreen, lastScreenPos, 2); Video.DrawLineClip(ColorGreen, lastScreenPos, targetPos); Video.FillCircleClip(ColorYellow, targetPos, 3); return targetPos; }
/* virtual */ PixelPos COrder_Board::Show(const CViewport &vp, const PixelPos &lastScreenPos) const { PixelPos targetPos; if (this->HasGoal()) { targetPos = vp.MapToScreenPixelPos(this->GetGoal()->GetMapPixelPosCenter()); } else { targetPos = vp.TilePosToScreen_Center(this->goalPos); } Video.FillCircleClip(ColorGreen, lastScreenPos, 2); Video.DrawLineClip(ColorGreen, lastScreenPos, targetPos); Video.FillCircleClip(ColorGreen, targetPos, 3); return targetPos; }
HRESULT ParaEngine::CViewportManager::Render(double dTimeDelta, int nPipelineOrder) { SortViewport(); for (auto iter = m_viewportSorted.begin(); iter != m_viewportSorted.end(); iter++) { CViewport* pViewPort = *iter; if (pViewPort) { pViewPort->Render(dTimeDelta, nPipelineOrder); } } CreateGetViewPort(1)->SetActive(); return S_OK; }
/* virtual */ PixelPos COrder_Attack::Show(const CViewport &vp, const PixelPos &lastScreenPos) const { PixelPos targetPos; if (this->HasGoal()) { targetPos = vp.MapToScreenPixelPos(this->GetGoal()->GetMapPixelPosCenter()); } else { targetPos = vp.TilePosToScreen_Center(this->goalPos); } Video.FillCircleClip(ColorRed, lastScreenPos, 2); Video.DrawLineClip(ColorRed, lastScreenPos, targetPos); Video.FillCircleClip(IsWeakTargetSelected() ? ColorBlue : ColorRed, targetPos, 3); return targetPos; }
/** ** Draw map area */ void DrawMapArea() { // Draw all of the viewports for (CViewport *vp = UI.Viewports; vp < UI.Viewports + UI.NumViewports; ++vp) { // Center viewport on tracked unit if (vp->Unit) { if (vp->Unit->Destroyed || vp->Unit->CurrentAction() == UnitActionDie) { vp->Unit = NULL; } else { vp->Center(vp->Unit->GetMapPixelPosCenter()); } } vp->Draw(); } }
/** ** Draw missile. */ void Missile::DrawMissile(const CViewport &vp) const { Assert(this->Type); CUnit *sunit = this->SourceUnit; // FIXME: I should copy SourcePlayer for second level missiles. if (sunit && sunit->Player) { #ifdef DYNAMIC_LOAD if (!this->Type->Sprite) { LoadMissileSprite(this->Type); } #endif } const PixelPos screenPixelPos = vp.MapToScreenPixelPos(this->position); switch (this->Type->Class) { case MissileClassHit: CLabel(GetGameFont()).DrawClip(screenPixelPos.x, screenPixelPos.y, this->Damage); break; default: if (Type->G) { this->Type->DrawMissileType(this->SpriteFrame, screenPixelPos); } break; } }
bool GraphicAnimation::isVisible(const CViewport &vp, const CPosition &pos) { // invisible graphics always invisible if (!g) { return false; } PixelSize graphicSize(g->Width, g->Height); PixelDiff margin(PixelTileSize.x - 1, PixelTileSize.y - 1); PixelPos position(pos.x, pos.y); Vec2i minPos = Map.MapPixelPosToTilePos(position); Vec2i maxPos = Map.MapPixelPosToTilePos(position + graphicSize + margin); Map.Clamp(minPos); Map.Clamp(maxPos); if (!vp.AnyMapAreaVisibleInViewport(minPos, maxPos)) { return false; } Vec2i p; for (p.x = minPos.x; p.x <= maxPos.x; ++p.x) { for (p.y = minPos.y; p.y <= maxPos.y; ++p.y) { if (ReplayRevealMap || Map.Field(p)->playerInfo.IsTeamVisible(*ThisPlayer)) { return true; } } } return false; }
virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */) { static bool minimized= false; minimized= !minimized; if(minimized) { CViewport vp; vp.init(0, 0, 0.1f, 0.1f); Scene->setViewport(vp); } else { CViewport vp; vp.initFullScreen(); Scene->setViewport(vp); } }
/* virtual */ PixelPos COrder_Move::Show(const CViewport &vp, const PixelPos &lastScreenPos) const { const PixelPos targetPos = vp.TilePosToScreen_Center(this->goalPos); Video.FillCircleClip(ColorGreen, lastScreenPos, 2); Video.DrawLineClip(ColorGreen, lastScreenPos, targetPos); Video.FillCircleClip(ColorGreen, targetPos, 3); return targetPos; }
/** ** Draw map area */ void DrawMapArea(void) { // Draw all of the viewports for (CViewport *vp = UI.Viewports; vp < UI.Viewports + UI.NumViewports; ++vp) { // Center viewport on tracked unit if (vp->Unit) { if (vp->Unit->Destroyed || vp->Unit->Orders[0]->Action == UnitActionDie) { vp->Unit = NoUnitP; } else { vp->Center(vp->Unit->X, vp->Unit->Y, vp->Unit->IX + TileSizeX / 2, vp->Unit->IY + TileSizeY / 2); } } vp->Draw(); } }
void ParaEngine::CViewportManager::UpdateViewport(int nBackbufferWidth, int nBackbufferHeight) { if (m_nHeight != nBackbufferHeight || m_nWidth != nBackbufferWidth) { m_nWidth = nBackbufferWidth; m_nHeight = nBackbufferHeight; m_viewport.Width = m_nWidth; m_viewport.Height = m_nHeight; UpdateLayout(); for (auto iter = m_viewportList.begin(); iter != m_viewportList.end(); iter++) { CViewport* pViewPort = *iter; if (pViewPort) { pViewPort->OnParentSizeChanged(m_nWidth, m_nHeight); } } } }
/* virtual */ PixelPos COrder_Build::Show(const CViewport &vp, const PixelPos &lastScreenPos) const { PixelPos targetPos = vp.TilePosToScreen_Center(this->goalPos); targetPos.x += (this->GetUnitType().TileWidth - 1) * PixelTileSize.x / 2; targetPos.y += (this->GetUnitType().TileHeight - 1) * PixelTileSize.y / 2; const int w = this->GetUnitType().BoxWidth; const int h = this->GetUnitType().BoxHeight; DrawSelection(ColorGray, targetPos.x - w / 2, targetPos.y - h / 2, targetPos.x + w / 2, targetPos.y + h / 2); Video.FillCircleClip(ColorGreen, lastScreenPos, 2); Video.DrawLineClip(ColorGreen, lastScreenPos, targetPos); Video.FillCircleClip(ColorGreen, targetPos, 3); return targetPos; }
void ParaEngine::CViewportManager::UpdateLayout() { if (GetLayout() == VIEW_LAYOUT_STEREO_LEFT_RIGHT) { int nHalfWidth = (int)(GetWidth() / 2); CViewport* pUIViewportLeft = CreateGetViewPort(0); pUIViewportLeft->SetPosition("_ml", 0, 0, nHalfWidth, 0); CViewport* pMainSceneViewportLeft = CreateGetViewPort(1); pMainSceneViewportLeft->SetPosition("_ml", 0, 0, nHalfWidth, 0); CViewport* pUIViewportRight = CreateGetViewPort(2); pUIViewportRight->SetPosition("_mr", 0, 0, nHalfWidth, 0); CViewport* pMainSceneViewportRight = CreateGetViewPort(3); pMainSceneViewportRight->SetPosition("_mr", 0, 0, nHalfWidth, 0); } }
void initInventoryDisplay () { ConfigFile.setCallback ("InventoryDisplayState", cbUpdateInventoryDisplay); if (ShowDebugInChat) nlinfo("Init Inventory Display (state)=%d", InventoryState); // // Setup the inventory scene // InventoryScene = Driver->createScene(); CViewport v; v.init (0.0f, 0.0f, 1.0f, 1.0f); InventoryScene->setViewport (v); uint32 width, height; Driver->getWindowSize (width, height); ScreenWidth = (float) width; ScreenHeight = (float) height; SelectedTexture = Driver->createTextureFile ("selectedIcon.tga"); // invSelectPS = InventoryScene->createInstance( "invselect.ps" ); // invSelectPS->hide(); }
/** ** Check missile visibility in a given viewport. ** ** @param vp Viewport to be checked. ** @param missile Missile pointer to check if visible. ** ** @return Returns true if visible, false otherwise. */ static int MissileVisibleInViewport(const CViewport &vp, const Missile &missile) { Vec2i boxmin; Vec2i boxmax; GetMissileMapArea(missile, boxmin, boxmax); if (!vp.AnyMapAreaVisibleInViewport(boxmin, boxmax)) { return 0; } Vec2i pos; for (pos.x = boxmin.x; pos.x <= boxmax.x; ++pos.x) { for (pos.y = boxmin.y; pos.y <= boxmax.y; ++pos.y) { if (ReplayRevealMap || Map.Field(pos)->playerInfo.IsTeamVisible(*ThisPlayer)) { return 1; } } } return 0; }
/** ** Show selection marker around a unit. ** ** @param unit Pointer to unit. */ void DrawUnitSelection(const CViewport &vp, const CUnit &unit) { IntColor color; // FIXME: make these colors customizable with scripts. if (Editor.Running && UnitUnderCursor == &unit && Editor.State == EditorSelecting) { color = ColorWhite; } else if (unit.Selected || unit.TeamSelected || (unit.Blink & 1)) { if (unit.Player->Index == PlayerNumNeutral) { color = ColorYellow; } else if ((unit.Selected || (unit.Blink & 1)) && (unit.Player == ThisPlayer || ThisPlayer->IsTeamed(unit))) { color = ColorGreen; } else if (ThisPlayer->IsEnemy(unit)) { color = ColorRed; } else { color = PlayerColors[GameSettings.Presets[unit.Player->Index].PlayerColor][0]; for (int i = 0; i < PlayerMax; ++i) { if (unit.TeamSelected & (1 << i)) { color = PlayerColors[GameSettings.Presets[i].PlayerColor][0]; } } } } else if (CursorBuilding && unit.Type->Building && unit.CurrentAction() != UnitActionDie && (unit.Player == ThisPlayer || ThisPlayer->IsTeamed(unit))) { // If building mark all own buildings color = ColorGray; } else { return; } const CUnitType &type = *unit.Type; const PixelPos screenPos = vp.MapToScreenPixelPos(unit.GetMapPixelPosCenter()); const int x = screenPos.x - type.BoxWidth / 2 - (type.Width - (type.Sprite ? type.Sprite->Width : 0)) / 2; const int y = screenPos.y - type.BoxHeight / 2 - (type.Height - (type.Sprite ? type.Sprite->Height : 0)) / 2; DrawSelection(color, x + type.BoxOffsetX, y + type.BoxOffsetY, x + type.BoxWidth + type.BoxOffsetX, y + type.BoxHeight + type.BoxOffsetY); }
// TMP TMP void tempDumpColPolys() { CPackedWorld *pw = R2::getEditor().getIslandCollision().getPackedIsland(); if (pw) { static CMaterial material; static CMaterial wiredMaterial; static CMaterial texturedMaterial; static CVertexBuffer vb; static bool initDone = false; if (!initDone) { vb.setVertexFormat(CVertexBuffer::PositionFlag); vb.setPreferredMemory(CVertexBuffer::AGPVolatile, false); material.initUnlit(); material.setDoubleSided(true); material.setZFunc(CMaterial::lessequal); wiredMaterial.initUnlit(); wiredMaterial.setDoubleSided(true); wiredMaterial.setZFunc(CMaterial::lessequal); wiredMaterial.setColor(CRGBA(255, 255, 255, 250)); wiredMaterial.texEnvOpAlpha(0, CMaterial::Replace); wiredMaterial.texEnvArg0Alpha(0, CMaterial::Diffuse, CMaterial::SrcAlpha); wiredMaterial.setBlend(true); wiredMaterial.setBlendFunc(CMaterial::srcalpha, CMaterial::invsrcalpha); texturedMaterial.initUnlit(); texturedMaterial.setDoubleSided(true); texturedMaterial.setZFunc(CMaterial::lessequal); initDone = true; } // just add a projected texture R2::getEditor().getIslandCollision().loadEntryPoints(); R2::CScenarioEntryPoints &sep = R2::CScenarioEntryPoints::getInstance(); CVectorD playerPos = UserEntity->pos(); R2::CScenarioEntryPoints::CCompleteIsland *island = sep.getCompleteIslandFromCoords(CVector2f((float) playerPos.x, (float) playerPos.y)); static CSString currIsland; if (island && island->Island != currIsland) { currIsland = island->Island; CTextureFile *newTex = new CTextureFile(currIsland + "_sp.tga"); newTex->setWrapS(ITexture::Clamp); newTex->setWrapT(ITexture::Clamp); texturedMaterial.setTexture(0, newTex); texturedMaterial.texEnvOpRGB(0, CMaterial::Replace); texturedMaterial.texEnvArg0RGB(0, CMaterial::Texture, CMaterial::SrcColor); texturedMaterial.setTexCoordGen(0, true); texturedMaterial.setTexCoordGenMode(0, CMaterial::TexCoordGenObjectSpace); CMatrix mat; CVector scale((float) (island->XMax - island->XMin), (float) (island->YMax - island->YMin), 0.f); scale.x = 1.f / favoid0(scale.x); scale.y = 1.f / favoid0(scale.y); scale.z = 0.f; mat.setScale(scale); mat.setPos(CVector(- island->XMin * scale.x, - island->YMin * scale.y, 0.f)); // CMatrix uvScaleMat; // uint texWidth = (uint) (island->XMax - island->XMin); uint texHeight = (uint) (island->YMax - island->YMin); float UScale = (float) texWidth / raiseToNextPowerOf2(texWidth); float VScale = (float) texHeight / raiseToNextPowerOf2(texHeight); // uvScaleMat.setScale(CVector(UScale, - VScale, 0.f)); uvScaleMat.setPos(CVector(0.f, VScale, 0.f)); // texturedMaterial.enableUserTexMat(0, true); texturedMaterial.setUserTexMat(0, uvScaleMat * mat); } const CFrustum &frust = MainCam.getFrustum(); // IDriver *driver = ((CDriverUser *) Driver)->getDriver(); driver->enableFog(true); const CRGBA clearColor = CRGBA(0, 0, 127, 0); driver->setupFog(frust.Far * 0.8f, frust.Far, clearColor); CViewport vp; vp.init(0.f, 0.f, 1.f, 1.f); driver->setupViewport(vp); CScissor scissor; viewportToScissor(vp, scissor); driver->setupScissor(scissor); // driver->setFrustum(frust.Left, frust.Right, frust.Bottom, frust.Top, frust.Near, frust.Far, frust.Perspective); driver->setupViewMatrix(MainCam.getMatrix().inverted()); driver->setupModelMatrix(CMatrix::Identity); // // const CVector localFrustCorners[8] = { CVector(frust.Left, frust.Near, frust.Top), CVector(frust.Right, frust.Near, frust.Top), CVector(frust.Right, frust.Near, frust.Bottom), CVector(frust.Left, frust.Near, frust.Bottom), CVector(frust.Left * frust.Far / frust.Near, frust.Far, frust.Top * frust.Far / frust.Near), CVector(frust.Right * frust.Far / frust.Near, frust.Far, frust.Top * frust.Far / frust.Near), CVector(frust.Right * frust.Far / frust.Near, frust.Far, frust.Bottom * frust.Far / frust.Near), CVector(frust.Left * frust.Far / frust.Near, frust.Far, frust.Bottom * frust.Far / frust.Near) }; // roughly compute covered zones // /* sint frustZoneMinX = INT_MAX; sint frustZoneMaxX = INT_MIN; sint frustZoneMinY = INT_MAX; sint frustZoneMaxY = INT_MIN; for(uint k = 0; k < sizeofarray(localFrustCorners); ++k) { CVector corner = camMat * localFrustCorners[k]; sint zoneX = (sint) (corner.x / 160.f) - zoneMinX; sint zoneY = (sint) floorf(corner.y / 160.f) - zoneMinY; frustZoneMinX = std::min(frustZoneMinX, zoneX); frustZoneMinY = std::min(frustZoneMinY, zoneY); frustZoneMaxX = std::max(frustZoneMaxX, zoneX); frustZoneMaxY = std::max(frustZoneMaxY, zoneY); } */ const uint TRI_BATCH_SIZE = 10000; // batch size for rendering static std::vector<TPackedZoneBaseSPtr> zones; zones.clear(); pw->getZones(zones); for(uint k = 0; k < zones.size(); ++k) { zones[k]->render(vb, *driver, texturedMaterial, wiredMaterial, MainCam.getMatrix(), TRI_BATCH_SIZE, localFrustCorners); } } }
void ParaEngine::CViewportManager::SetLayout(VIEWPORT_LAYOUT nLayout, CSceneObject* pMainScene, CGUIRoot* pGUIRoot) { if (!pMainScene) pMainScene = CGlobals::GetScene(); if (!pGUIRoot) pGUIRoot = CGlobals::GetGUI(); if (m_nLayout == nLayout && GetViewportCount() != 0) return; // clear layout SetViewportCount(0); m_nLayout = nLayout; if (nLayout == VIEW_LAYOUT_STEREO_LEFT_RIGHT) { int nHalfWidth = (int)(GetWidth() / 2); CViewport* pUIViewportLeft = CreateGetViewPort(0); pUIViewportLeft->SetIdentifier("left_GUI"); pUIViewportLeft->SetGUIRoot(pGUIRoot); pUIViewportLeft->SetPosition("_ml", 0, 0, nHalfWidth, 0); pUIViewportLeft->SetZOrder(100); pUIViewportLeft->SetEyeMode(STEREO_EYE_LEFT); CViewport* pMainSceneViewportLeft = CreateGetViewPort(1); pMainSceneViewportLeft->SetIdentifier("left_scene"); pMainSceneViewportLeft->SetScene(pMainScene); pMainSceneViewportLeft->SetPosition("_ml", 0, 0, nHalfWidth, 0); pMainSceneViewportLeft->SetEyeMode(STEREO_EYE_LEFT); CViewport* pUIViewportRight = CreateGetViewPort(2); pUIViewportRight->SetIdentifier("right_GUI"); pUIViewportRight->SetGUIRoot(pGUIRoot); pUIViewportRight->SetPosition("_mr", 0, 0, nHalfWidth, 0); pUIViewportRight->SetZOrder(101); pUIViewportRight->SetEyeMode(STEREO_EYE_RIGHT); CViewport* pMainSceneViewportRight = CreateGetViewPort(3); pMainSceneViewportRight->SetIdentifier("right_scene"); pMainSceneViewportRight->SetScene(pMainScene); pMainSceneViewportRight->SetPosition("_mr", 0, 0, nHalfWidth, 0); pMainSceneViewportRight->SetZOrder(1); pMainSceneViewportRight->SetEyeMode(STEREO_EYE_RIGHT); SetViewportCount(4); } else if (nLayout == VIEW_LAYOUT_STEREO_RED_BLUE) { CViewport* pUIViewport = CreateGetViewPort(0); pUIViewport->SetIdentifier("GUI"); pUIViewport->SetGUIRoot(pGUIRoot); pUIViewport->SetPosition("_fi", 0, 0, 0, 0); pUIViewport->SetZOrder(100); pUIViewport->SetEyeMode(STEREO_EYE_NORMAL); CViewport* pMainSceneViewportLeft = CreateGetViewPort(1); pMainSceneViewportLeft->SetIdentifier("left_scene"); pMainSceneViewportLeft->SetScene(pMainScene); pMainSceneViewportLeft->SetPosition("_fi", 0, 0, 0, 0); pMainSceneViewportLeft->SetEyeMode(STEREO_EYE_LEFT); pMainSceneViewportLeft->SetRenderTargetName("_LeftViewRT"); // use private render target CViewport* pMainSceneViewportRight = CreateGetViewPort(2); pMainSceneViewportRight->SetIdentifier("right_scene"); pMainSceneViewportRight->SetScene(pMainScene); pMainSceneViewportRight->SetPosition("_fi", 0, 0, 0, 0); pMainSceneViewportRight->SetZOrder(1); pMainSceneViewportRight->SetEyeMode(STEREO_EYE_RIGHT); // final full screen quad CViewport* pFinalViewPort = CreateGetViewPort(3); pFinalViewPort->SetIdentifier("final_composite"); pFinalViewPort->SetPosition("_fi", 0, 0, 0, 0); pFinalViewPort->SetEyeMode(STEREO_EYE_NORMAL); pFinalViewPort->SetZOrder(99); // before GUI pFinalViewPort->SetPipelineOrder(PIPELINE_3D_SCENE); SetViewportCount(4); } else // if (nLayout == VIEW_LAYOUT_DEFAULT) { CViewport* pUIViewport = CreateGetViewPort(0); pUIViewport->SetIdentifier("GUI"); pUIViewport->SetGUIRoot(pGUIRoot); pUIViewport->SetPosition("_fi", 0, 0, 0, 0); pUIViewport->SetZOrder(100); pUIViewport->SetEyeMode(STEREO_EYE_NORMAL); CViewport* pMainSceneViewport = CreateGetViewPort(1); pMainSceneViewport->SetIdentifier("scene"); pMainSceneViewport->SetScene(pMainScene); pMainSceneViewport->SetPosition("_fi", 0, 0, 0, 0); pMainSceneViewport->SetEyeMode(STEREO_EYE_NORMAL); SetViewportCount(2); } }
/** ** Draw unit on map. */ void CUnit::Draw(const CViewport &vp) const { int frame; int state; int constructed; const CConstructionFrame *cframe; const CUnitType *type; if (this->Destroyed || this->Container || this->Type->Revealer) { // Revealers are not drawn return; } bool IsVisible = this->IsVisible(*ThisPlayer); // Those should have been filtered. Check doesn't make sense with ReplayRevealMap Assert(ReplayRevealMap || this->Type->VisibleUnderFog || IsVisible); int player = this->RescuedFrom ? this->RescuedFrom->Index : this->Player->Index; int action = this->CurrentAction(); PixelPos screenPos; if (ReplayRevealMap || IsVisible) { screenPos = vp.MapToScreenPixelPos(this->GetMapPixelPosTopLeft()); type = this->Type; frame = this->Frame; state = (action == UnitActionBuilt) | ((action == UnitActionUpgradeTo) << 1); constructed = this->Constructed; // Reset Type to the type being upgraded to if (action == UnitActionUpgradeTo) { const COrder_UpgradeTo &order = *static_cast<COrder_UpgradeTo *>(this->CurrentOrder()); type = &order.GetUnitType(); } if (this->CurrentAction() == UnitActionBuilt) { COrder_Built &order = *static_cast<COrder_Built *>(this->CurrentOrder()); cframe = &order.GetFrame(); } else { cframe = NULL; } } else { screenPos = vp.TilePosToScreen_TopLeft(this->Seen.tilePos); screenPos.x += this->Seen.IX; screenPos.y += this->Seen.IY; frame = this->Seen.Frame; type = this->Seen.Type; constructed = this->Seen.Constructed; state = this->Seen.State; cframe = this->Seen.CFrame; } #ifdef DYNAMIC_LOAD if (!type->Sprite) { LoadUnitTypeSprite(type); } #endif if (!IsVisible && frame == UnitNotSeen) { DebugPrint("FIXME: Something is wrong, unit %d not seen but drawn time %lu?.\n" _C_ UnitNumber(*this) _C_ GameCycle); return; } if (state == 1 && constructed && cframe) { DrawConstructionShadow(*type, cframe, frame, screenPos); } else { if (action != UnitActionDie) { DrawShadow(*type, frame, screenPos); } } // // Show that the unit is selected // DrawUnitSelection(vp, *this); // // Adjust sprite for Harvesters. // CPlayerColorGraphic *sprite = type->Sprite; if (type->Harvester && this->CurrentResource) { ResourceInfo *resinfo = type->ResInfo[this->CurrentResource]; if (this->ResourcesHeld) { if (resinfo->SpriteWhenLoaded) { sprite = resinfo->SpriteWhenLoaded; } } else { if (resinfo->SpriteWhenEmpty) { sprite = resinfo->SpriteWhenEmpty; } } } // // Now draw! // Buildings under construction/upgrade/ready. // if (state == 1) { if (constructed && cframe) { const PixelPos pos(screenPos + (type->GetPixelSize()) / 2); DrawConstruction(GameSettings.Presets[player].PlayerColor, cframe, *type, frame, pos); } else { DrawUnitType(*type, sprite, GameSettings.Presets[player].PlayerColor, frame, screenPos); } // // Draw the future unit type, if upgrading to it. // } else { DrawUnitType(*type, sprite, GameSettings.Presets[player].PlayerColor, frame, screenPos); } // Unit's extras not fully supported.. need to be decorations themselves. DrawInformations(*this, *type, screenPos); }