Skip to content

Commit

Permalink
LRS improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
gmoromisato committed Jul 2, 2015
1 parent 3726e73 commit da5962a
Show file tree
Hide file tree
Showing 6 changed files with 186 additions and 84 deletions.
131 changes: 131 additions & 0 deletions Transcendence/CLRSDisplay.cpp
@@ -0,0 +1,131 @@
// CLRSDisplay.cpp
//
// CLRSDisplay class
// Copyright (c) 2015 by Kronosaur Productions, LLC. All Rights Reserved.

#include "PreComp.h"
#include "Transcendence.h"

void CLRSDisplay::CleanUp (void)

// CleanUp
//
// Clean up from a session

{
m_pPlayer = NULL;
}

ALERROR CLRSDisplay::Init (CPlayerShipController *pPlayer, const RECT &rcRect)

// Init
//
// Initialize the display

{
// Initialize

int cxWidth = RectWidth(rcRect);
int cyHeight = RectHeight(rcRect);
m_pPlayer = pPlayer;
m_rcRect = rcRect;
m_iDiameter = Min(cxWidth, cyHeight);

// Create a buffer

if (!m_Buffer.Create(cxWidth, cyHeight, CG32bitImage::alpha8))
return ERR_FAIL;

// Create a circular mask for the LRS

if (!m_Mask.Create(cxWidth, cyHeight, 0xff))
return ERR_FAIL;

CGDraw::Circle(m_Mask, (m_iDiameter / 2), (m_iDiameter / 2), (m_iDiameter / 2), 0x00);

// Done

return NOERROR;
}

void CLRSDisplay::Paint (CG32bitImage &Dest)

// Paint
//
// Paints the display

{
Dest.Blt(0,
0,
RectWidth(m_rcRect),
RectHeight(m_rcRect),
200,
m_Buffer,
m_rcRect.left,
m_rcRect.top);
}

void CLRSDisplay::Update (void)

// Update
//
// Updates the display

{
bool bNewEnemies;
int cxWidth = RectWidth(m_rcRect);
int cyHeight = RectHeight(m_rcRect);

if (m_pBackground)
CGDraw::BltTiled(m_Buffer, 0, 0, cxWidth, cyHeight, *m_pBackground);
else
m_Buffer.Fill(m_rgbBackground);

// If we're not blind, paint the LRS

if (m_pPlayer == NULL
|| !m_pPlayer->GetShip()->IsLRSBlind())
{
RECT rcView;
rcView.left = 0;
rcView.top = 0;
rcView.right = cxWidth;
rcView.bottom = cyHeight;

Metric rKlicksPerPixel = g_LRSRange * 2 / RectWidth(rcView);
g_pUniverse->PaintPOVLRS(m_Buffer, rcView, rKlicksPerPixel, 0, &bNewEnemies);

// Notify player of enemies

if (bNewEnemies)
m_pPlayer->OnEnemyShipsDetected();
}

// If we're blind, paint snow

else
{
if (m_pSnow)
CGDraw::BltTiled(m_Buffer, 0, 0, cxWidth, cyHeight, *m_pSnow);

int iCount = mathRandom(1, 8);
for (int i = 0; i < iCount; i++)
{
m_Buffer.Fill(0, mathRandom(0, cyHeight),
cxWidth,
mathRandom(1, 20),
CG32bitPixel(108, 252, 128));
}
}

// Mask out the border

m_Buffer.SetMask(0,
0,
cxWidth,
cyHeight,
m_Mask,
CG32bitPixel::Null(),
0,
0);
}
4 changes: 2 additions & 2 deletions Transcendence/CTranscendenceWnd.cpp
Expand Up @@ -31,7 +31,6 @@ int g_cyScreen = 0;
CTranscendenceWnd::CTranscendenceWnd (HWND hWnd, CTranscendenceController *pTC) : m_hWnd(hWnd),
m_pTC(pTC),
m_State(gsNone),
m_pLargeHUD(NULL),
m_pCurrentScreen(NULL),
m_bShowingMap(false),
m_bDebugConsole(false),
Expand Down Expand Up @@ -353,7 +352,7 @@ void CTranscendenceWnd::Animate (CG32bitImage &TheScreen, CGameSession *pSession
::OffsetRect(&rcRect, -m_rcMainScreen.left, -m_rcMainScreen.top);
m_pCurrentScreen->Invalidate(rcRect);

rcRect = m_rcLRS;
rcRect = m_LRSDisplay.GetRect();
::OffsetRect(&rcRect, -m_rcMainScreen.left, -m_rcMainScreen.top);
m_pCurrentScreen->Invalidate(rcRect);

Expand Down Expand Up @@ -520,6 +519,7 @@ void CTranscendenceWnd::CleanUpPlayerShip (void)
{
DEBUG_TRY

m_LRSDisplay.CleanUp();
m_ReactorDisplay.CleanUp();
m_DeviceDisplay.CleanUp();
m_TargetDisplay.CleanUp();
Expand Down
96 changes: 18 additions & 78 deletions Transcendence/GameScreen.cpp
Expand Up @@ -66,10 +66,6 @@
#define SO_BETA_FORMATION CONSTLIT("Beta formation")
#define SO_GAMMA_FORMATION CONSTLIT("Gamma formation")

const int LRS_UPDATE_DELAY = 5;
const int g_LRSWidth = 200;
const int g_LRSHeight = 200;

const int g_WeaponStatusWidth = 350;
const int g_WeaponStatusHeight = 32;

Expand All @@ -82,6 +78,11 @@ const int g_iPlanetaryScale = 1;

const int MAP_ZOOM_SPEED = 16;

const int LRS_UPDATE_DELAY = 5;
const int MIN_LRS_SIZE = 200;
const int LRS_SCALE = 27;
const CG32bitPixel RGB_LRS_BACKGROUND = CG32bitPixel(17, 21, 26);

void CTranscendenceWnd::Autopilot (bool bTurnOn)

// Autopilot
Expand Down Expand Up @@ -424,26 +425,23 @@ ALERROR CTranscendenceWnd::InitDisplays (void)

m_bTransparencyEffects = true;

// Create a bitmap for the LRS

if (!m_LRS.Create(g_LRSWidth, g_LRSHeight, CG32bitImage::alpha8))
return ERR_FAIL;

//m_rcLRS.left = m_rcScreen.left;
m_rcLRS.left = m_rcScreen.right - g_LRSWidth;
//m_rcLRS.top = g_cyScreen - g_LRSHeight;
m_rcLRS.top = 0;
m_rcLRS.right = m_rcLRS.left + g_LRSWidth;
m_rcLRS.bottom = m_rcLRS.top + g_LRSHeight;

// Find some bitmaps that we need. NOTE: We lock the images because we
// don't dispose of them.
//
// LATER: These should be obtained form the player ship.

m_pLargeHUD = g_pUniverse->GetLibraryBitmap(g_LRSImageUNID, CDesignCollection::FLAG_IMAGE_LOCK);
m_pSRSSnow = g_pUniverse->GetLibraryBitmap(g_SRSSnowImageUNID, CDesignCollection::FLAG_IMAGE_LOCK);
m_pLRSBorder = g_pUniverse->GetLibraryBitmap(g_LRSBorderUNID, CDesignCollection::FLAG_IMAGE_LOCK);

// Create LRS

int iLRSDiameter = Max(MIN_LRS_SIZE, LRS_SCALE * RectHeight(m_rcScreen) / 100);
rcRect.left = m_rcScreen.right - iLRSDiameter;
rcRect.top = 0;
rcRect.right = rcRect.left + iLRSDiameter;
rcRect.bottom = rcRect.top + iLRSDiameter;
m_LRSDisplay.Init(GetPlayer(), rcRect);
m_LRSDisplay.SetSnowImage(m_pSRSSnow);
m_LRSDisplay.SetBackgroundColor(RGB_LRS_BACKGROUND);

// Create the message display

Expand Down Expand Up @@ -543,69 +541,11 @@ void CTranscendenceWnd::PaintLRS (void)
// Update the LRS every 10 ticks

if ((m_iTick % LRS_UPDATE_DELAY) == 0)
{
bool bNewEnemies;

m_LRS.Blt(0, 0, g_LRSWidth, g_LRSHeight, *m_pLargeHUD, 0, 0);

// If we're not blind, paint the LRS

if (GetPlayer() == NULL
|| !GetPlayer()->GetShip()->IsLRSBlind())
{
RECT rcView;
rcView.left = 0;
rcView.top = 0;
rcView.right = g_LRSWidth;
rcView.bottom = g_LRSHeight;

Metric rKlicksPerPixel = g_LRSRange * 2 / RectWidth(rcView);
g_pUniverse->PaintPOVLRS(m_LRS, rcView, rKlicksPerPixel, 0, &bNewEnemies);

// Notify player of enemies

if (bNewEnemies)
GetPlayer()->OnEnemyShipsDetected();
}

// If we're blind, paint snow

else
{
PaintSnow(m_LRS, 0, 0, g_LRSWidth, g_LRSHeight);

int iCount = mathRandom(1, 8);
for (int i = 0; i < iCount; i++)
{
m_LRS.Fill(0, mathRandom(0, g_LRSHeight),
g_LRSWidth,
mathRandom(1, 20),
CG32bitPixel(108, 252, 128));
}
}

// Mask out the border

m_LRS.SetMask(0,
0,
g_LRSWidth,
g_LRSHeight,
*m_pLRSBorder,
CG32bitPixel::Null(),
0,
0);
}
m_LRSDisplay.Update();

// Blt the LRS

g_pHI->GetScreen().Blt(0,
0,
RectWidth(m_rcLRS),
RectHeight(m_rcLRS),
200,
m_LRS,
m_rcLRS.left,
m_rcLRS.top);
m_LRSDisplay.Paint(g_pHI->GetScreen());

DEBUG_CATCH
}
Expand Down
35 changes: 31 additions & 4 deletions Transcendence/Transcendence.h
Expand Up @@ -925,6 +925,36 @@ class CPlayerDisplay
const SFontTable *m_pFonts;
};

class CLRSDisplay
{
public:
CLRSDisplay (void) :
m_rgbBackground(CG32bitPixel(0, 0, 0)),
m_pBackground(NULL),
m_pSnow(NULL)
{ }

void CleanUp (void);
inline const RECT &GetRect (void) { return m_rcRect; }
ALERROR Init (CPlayerShipController *pPlayer, const RECT &rcRect);
void Paint (CG32bitImage &Dest);
inline void SetBackgroundColor (CG32bitPixel rgbColor) { m_rgbBackground = rgbColor; }
inline void SetBackgroundImage (const CG32bitImage *pImage) { m_pBackground = pImage; }
inline void SetSnowImage (const CG32bitImage *pSnow) { m_pSnow = pSnow; }
void Update (void);

private:
CPlayerShipController *m_pPlayer;

RECT m_rcRect;
int m_iDiameter; // Diameter of scanner in pixels
CG32bitImage m_Buffer;
CG8bitImage m_Mask;
CG32bitPixel m_rgbBackground;
const CG32bitImage *m_pBackground;
const CG32bitImage *m_pSnow;
};

class CReactorDisplay
{
public:
Expand Down Expand Up @@ -1337,14 +1367,11 @@ class CTranscendenceWnd : public CUniverse::IHost, public IAniCommand
RECT m_rcWindow; // Rect of main window in screen coordinates
RECT m_rcWindowScreen; // Rect of screen within window

CG32bitImage m_LRS; // Long-range scan
RECT m_rcLRS; // Rect on screen where LRS goes
CG32bitImage *m_pLargeHUD; // Background LRS image
CG32bitImage *m_pSRSSnow; // SRS snow image
CG32bitImage *m_pLRSBorder; // LRS border

CArmorDisplay m_ArmorDisplay; // Armor display object
CDeviceCounterDisplay m_DeviceDisplay; // Device counter display
CLRSDisplay m_LRSDisplay; // LRS display
CMessageDisplay m_MessageDisplay; // Message display object
CReactorDisplay m_ReactorDisplay; // Reactor status display object
CTargetDisplay m_TargetDisplay; // Targeting computer display
Expand Down
1 change: 1 addition & 0 deletions Transcendence/Transcendence.vcxproj
Expand Up @@ -311,6 +311,7 @@
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<ClCompile Include="CLoadGameWithSignInTask.cpp" />
<ClCompile Include="CLRSDisplay.cpp" />
<ClCompile Include="CodeChainExtensions.cpp">
<Optimization Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Disabled</Optimization>
<Optimization Condition="'$(Configuration)|$(Platform)'=='SteamDebug|Win32'">Disabled</Optimization>
Expand Down
3 changes: 3 additions & 0 deletions Transcendence/Transcendence.vcxproj.filters
Expand Up @@ -236,6 +236,9 @@
<ClCompile Include="CHighScoreDisplay.cpp">
<Filter>Source Files\Intro Session</Filter>
</ClCompile>
<ClCompile Include="CLRSDisplay.cpp">
<Filter>Source Files\Displays</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="BackgroundTasks.h">
Expand Down

0 comments on commit da5962a

Please sign in to comment.