Consolidate some constants into actual enumerations/namespaces.

- Certain parts of the code referred to int literals, when they should use named constants instead
- Different classes had enumerations for the same quantities; this is now fixed
- Basically, TIAConstants and FrameBufferConstants now contain all constants, and their relationship is clearly indicated (previously it wasn't as clear)
This commit is contained in:
Stephen Anthony 2019-03-10 15:19:30 -02:30
parent 9a8e5a3a33
commit d09b6329c9
12 changed files with 59 additions and 53 deletions

View File

@ -75,8 +75,8 @@ bool FrameBuffer::initialize()
query_h = s.h; query_h = s.h;
} }
// Various parts of the codebase assume a minimum screen size // Various parts of the codebase assume a minimum screen size
myDesktopSize.w = std::max(query_w, uInt32(kFBMinW)); myDesktopSize.w = std::max(query_w, FBMinimum::Width);
myDesktopSize.h = std::max(query_h, uInt32(kFBMinH)); myDesktopSize.h = std::max(query_h, FBMinimum::Height);
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Create fonts to draw text // Create fonts to draw text
@ -88,7 +88,8 @@ bool FrameBuffer::initialize()
// We can probably add ifdefs to take care of corner cases, // We can probably add ifdefs to take care of corner cases,
// but that means we've failed to abstract it enough ... // but that means we've failed to abstract it enough ...
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
bool smallScreen = myDesktopSize.w < kFBMinW || myDesktopSize.h < kFBMinH; bool smallScreen = myDesktopSize.w < FBMinimum::Width ||
myDesktopSize.h < FBMinimum::Height;
// This font is used in a variety of situations when a really small // This font is used in a variety of situations when a really small
// font is needed; we let the specific widget/dialog decide when to // font is needed; we let the specific widget/dialog decide when to
@ -120,8 +121,9 @@ bool FrameBuffer::initialize()
myLauncherFont = make_unique<GUI::Font>(GUI::stellaDesc); myLauncherFont = make_unique<GUI::Font>(GUI::stellaDesc);
// Determine possible TIA windowed zoom levels // Determine possible TIA windowed zoom levels
uInt32 maxZoom = maxWindowSizeForScreen(uInt32(kTIAMinW), uInt32(kTIAMinH), uInt32 maxZoom = maxWindowSizeForScreen(
myDesktopSize.w, myDesktopSize.h); TIAConstants::viewableWidth, TIAConstants::viewableHeight,
myDesktopSize.w, myDesktopSize.h);
// Figure our the smallest zoom level we can use // Figure our the smallest zoom level we can use
uInt32 firstZoom = smallScreen ? 1 : 2; uInt32 firstZoom = smallScreen ? 1 : 2;
@ -186,7 +188,7 @@ FBInitStatus FrameBuffer::createDisplay(const string& title,
// we're running on a 'large' system, and the window size requirements // we're running on a 'large' system, and the window size requirements
// can be relaxed // can be relaxed
// Otherwise, we treat the system as if WINDOWED_SUPPORT is not defined // Otherwise, we treat the system as if WINDOWED_SUPPORT is not defined
if(myDesktopSize.w < kFBMinW && myDesktopSize.h < kFBMinH && if(myDesktopSize.w < FBMinimum::Width && myDesktopSize.h < FBMinimum::Height &&
(myDesktopSize.w < width || myDesktopSize.h < height)) (myDesktopSize.w < width || myDesktopSize.h < height))
return FBInitStatus::FailTooLarge; return FBInitStatus::FailTooLarge;
@ -254,7 +256,7 @@ FBInitStatus FrameBuffer::createDisplay(const string& title,
} }
if(!myMsg.surface) if(!myMsg.surface)
myMsg.surface = allocateSurface(kFBMinW, font().getFontHeight()+10); myMsg.surface = allocateSurface(FBMinimum::Width, font().getFontHeight()+10);
// Print initial usage message, but only print it later if the status has changed // Print initial usage message, but only print it later if the status has changed
if(myInitializedCount == 1) if(myInitializedCount == 1)
@ -837,7 +839,7 @@ void FrameBuffer::setAvailableVidModes(uInt32 baseWidth, uInt32 baseHeight)
// Figure our the smallest zoom level we can use // Figure our the smallest zoom level we can use
uInt32 firstZoom = 2; uInt32 firstZoom = 2;
if(myDesktopSize.w < kFBMinW || myDesktopSize.h < kFBMinH) if(myDesktopSize.w < FBMinimum::Width || myDesktopSize.h < FBMinimum::Height)
firstZoom = 1; firstZoom = 1;
for(uInt32 zoom = firstZoom; zoom <= maxZoom; ++zoom) for(uInt32 zoom = firstZoom; zoom <= maxZoom; ++zoom)
{ {
@ -924,8 +926,8 @@ VideoMode::VideoMode(uInt32 iw, uInt32 ih, uInt32 sw, uInt32 sh,
zoom(z), zoom(z),
description(desc) description(desc)
{ {
sw = std::max(sw, uInt32(FrameBuffer::kTIAMinW)); sw = std::max(sw, TIAConstants::viewableWidth);
sh = std::max(sh, uInt32(FrameBuffer::kTIAMinH)); sh = std::max(sh, TIAConstants::viewableHeight);
iw = std::min(iw, sw); iw = std::min(iw, sw);
ih = std::min(ih, sh); ih = std::min(ih, sh);
int ix = (sw - iw) >> 1; int ix = (sw - iw) >> 1;

View File

@ -83,11 +83,6 @@ class VideoMode
class FrameBuffer class FrameBuffer
{ {
public: public:
enum {
kTIAMinW = 320u, kTIAMinH = TIAConstants::viewableHeight,
kFBMinW = 640u, kFBMinH = 480u
};
/** /**
Creates a new Frame Buffer Creates a new Frame Buffer
*/ */

View File

@ -18,8 +18,15 @@
#ifndef FRAMEBUFFER_CONSTANTS_HXX #ifndef FRAMEBUFFER_CONSTANTS_HXX
#define FRAMEBUFFER_CONSTANTS_HXX #define FRAMEBUFFER_CONSTANTS_HXX
#include "TIAConstants.hxx"
#include "bspf.hxx" #include "bspf.hxx"
// Minimum size for a framebuffer window
namespace FBMinimum {
static constexpr uInt32 Width = TIAConstants::viewableWidth * 2;
static constexpr uInt32 Height = TIAConstants::viewableHeight * 2;
}
// Return values for initialization of framebuffer window // Return values for initialization of framebuffer window
enum class FBInitStatus { enum class FBInitStatus {
Success, Success,

View File

@ -23,7 +23,7 @@
#include "OSystem.hxx" #include "OSystem.hxx"
#include "Console.hxx" #include "Console.hxx"
#include "TIA.hxx" #include "TIA.hxx"
#include "PNGLibrary.hxx" #include "PNGLibrary.hxx"
#include "TIASurface.hxx" #include "TIASurface.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -42,19 +42,22 @@ TIASurface::TIASurface(OSystem& system)
myNTSCFilter.loadConfig(myOSystem.settings()); myNTSCFilter.loadConfig(myOSystem.settings());
// Create a surface for the TIA image and scanlines; we'll need them eventually // Create a surface for the TIA image and scanlines; we'll need them eventually
myTiaSurface = myFB.allocateSurface(AtariNTSC::outWidth(kTIAW), kTIAH); myTiaSurface = myFB.allocateSurface(AtariNTSC::outWidth(TIAConstants::frameBufferWidth),
TIAConstants::frameBufferHeight);
// Generate scanline data, and a pre-defined scanline surface // Generate scanline data, and a pre-defined scanline surface
uInt32 scanData[kScanH]; constexpr uInt32 scanHeight = TIAConstants::frameBufferHeight * 2;
for(int i = 0; i < kScanH; i+=2) uInt32 scanData[scanHeight];
for(uInt32 i = 0; i < scanHeight; i += 2)
{ {
scanData[i] = 0x00000000; scanData[i] = 0x00000000;
scanData[i+1] = 0xff000000; scanData[i+1] = 0xff000000;
} }
mySLineSurface = myFB.allocateSurface(1, kScanH, scanData); mySLineSurface = myFB.allocateSurface(1, scanHeight, scanData);
// Base TIA surface for use in taking snapshots in 1x mode // Base TIA surface for use in taking snapshots in 1x mode
myBaseTiaSurface = myFB.allocateSurface(kTIAW*2, kTIAH); myBaseTiaSurface = myFB.allocateSurface(TIAConstants::frameBufferWidth*2,
TIAConstants::frameBufferHeight);
memset(myRGBFramebuffer, 0, sizeof(myRGBFramebuffer)); memset(myRGBFramebuffer, 0, sizeof(myRGBFramebuffer));
@ -278,8 +281,8 @@ void TIASurface::enableNTSC(bool enable)
myFilter = Filter(enable ? uInt8(myFilter) | 0x10 : uInt8(myFilter) & 0x01); myFilter = Filter(enable ? uInt8(myFilter) | 0x10 : uInt8(myFilter) & 0x01);
// Normal vs NTSC mode uses different source widths // Normal vs NTSC mode uses different source widths
myTiaSurface->setSrcSize(enable ? myTiaSurface->setSrcSize(enable ? AtariNTSC::outWidth(TIAConstants::frameBufferWidth)
AtariNTSC::outWidth(kTIAW) : uInt32(kTIAW), myTIA->height()); : TIAConstants::frameBufferWidth, myTIA->height());
FBSurface::Attributes& tia_attr = myTiaSurface->attributes(); FBSurface::Attributes& tia_attr = myTiaSurface->attributes();
tia_attr.smoothing = myOSystem.settings().getBool("tia.inter"); tia_attr.smoothing = myOSystem.settings().getBool("tia.inter");

View File

@ -185,20 +185,16 @@ class TIASurface
}; };
Filter myFilter; Filter myFilter;
enum {
kTIAW = 160,
kTIAH = TIAConstants::frameBufferHeight,
kScanH = kTIAH*2
};
// NTSC object to use in TIA rendering mode // NTSC object to use in TIA rendering mode
NTSCFilter myNTSCFilter; NTSCFilter myNTSCFilter;
///////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////
// Phosphor mode items (aka reduced flicker on 30Hz screens) // Phosphor mode items (aka reduced flicker on 30Hz screens)
// RGB frame buffer // RGB frame buffer
uInt32 myRGBFramebuffer[AtariNTSC::outWidth(kTIAW) * kTIAH]; uInt32 myRGBFramebuffer[AtariNTSC::outWidth(TIAConstants::frameBufferWidth) *
uInt32 myPrevRGBFramebuffer[AtariNTSC::outWidth(kTIAW) * kTIAH]; TIAConstants::frameBufferHeight];
uInt32 myPrevRGBFramebuffer[AtariNTSC::outWidth(TIAConstants::frameBufferWidth) *
TIAConstants::frameBufferHeight];
// Use phosphor effect // Use phosphor effect
bool myUsePhosphor; bool myUsePhosphor;

View File

@ -22,10 +22,12 @@
namespace TIAConstants { namespace TIAConstants {
constexpr uInt32 frameBufferHeight = 320; static constexpr uInt32 frameBufferWidth = 160;
constexpr uInt32 maxYStart = 64; static constexpr uInt32 frameBufferHeight = 320;
constexpr uInt32 viewableHeight = 240; static constexpr uInt32 maxYStart = 64; // TODO - this may be removed
constexpr uInt32 initialGarbageFrames = 10; static constexpr uInt32 viewableWidth = 320;
static constexpr uInt32 viewableHeight = 240;
static constexpr uInt32 initialGarbageFrames = 10;
static constexpr uInt16 static constexpr uInt16
H_PIXEL = 160, H_CYCLES = 76, CYCLE_CLOCKS = 3, H_PIXEL = 160, H_CYCLES = 76, CYCLE_CLOCKS = 3,

View File

@ -814,7 +814,7 @@ bool Dialog::getDynamicBounds(uInt32& w, uInt32& h) const
{ {
const GUI::Rect& r = instance().frameBuffer().imageRect(); const GUI::Rect& r = instance().frameBuffer().imageRect();
if(r.width() <= FrameBuffer::kFBMinW || r.height() <= FrameBuffer::kFBMinH) if(r.width() <= FBMinimum::Width || r.height() <= FBMinimum::Height)
{ {
w = r.width(); w = r.width();
h = r.height(); h = r.height();

View File

@ -35,13 +35,12 @@ Launcher::Launcher(OSystem& osystem)
// The launcher dialog is resizable, within certain bounds // The launcher dialog is resizable, within certain bounds
// We check those bounds now // We check those bounds now
myWidth = std::max(myWidth, uInt32(FrameBuffer::kFBMinW)); myWidth = std::max(myWidth, FBMinimum::Width);
myHeight = std::max(myHeight, uInt32(FrameBuffer::kFBMinH)); myHeight = std::max(myHeight, FBMinimum::Height);
myWidth = std::min(myWidth, uInt32(d.w)); myWidth = std::min(myWidth, uInt32(d.w));
myHeight = std::min(myHeight, uInt32(d.h)); myHeight = std::min(myHeight, uInt32(d.h));
myOSystem.settings().setValue("launcherres", myOSystem.settings().setValue("launcherres", GUI::Size(myWidth, myHeight));
GUI::Size(myWidth, myHeight));
myBaseDialog = new LauncherDialog(myOSystem, *this, 0, 0, myWidth, myHeight); myBaseDialog = new LauncherDialog(myOSystem, *this, 0, 0, myWidth, myHeight);
} }

View File

@ -16,7 +16,7 @@
//============================================================================ //============================================================================
#include "Dialog.hxx" #include "Dialog.hxx"
#include "FrameBuffer.hxx" #include "FrameBufferConstants.hxx"
#include "OptionsDialog.hxx" #include "OptionsDialog.hxx"
#include "bspf.hxx" #include "bspf.hxx"
#include "Menu.hxx" #include "Menu.hxx"
@ -26,5 +26,5 @@ Menu::Menu(OSystem& osystem)
: DialogContainer(osystem) : DialogContainer(osystem)
{ {
myBaseDialog = new OptionsDialog(myOSystem, *this, nullptr, myBaseDialog = new OptionsDialog(myOSystem, *this, nullptr,
FrameBuffer::kFBMinW, FrameBuffer::kFBMinH, OptionsDialog::emulator); FBMinimum::Width, FBMinimum::Height, OptionsDialog::emulator);
} }

View File

@ -35,8 +35,9 @@ RomInfoWidget::RomInfoWidget(GuiObject* boss, const GUI::Font& font,
: Widget(boss, font, x, y, w, h), : Widget(boss, font, x, y, w, h),
mySurfaceIsValid(false), mySurfaceIsValid(false),
myHaveProperties(false), myHaveProperties(false),
myAvail(w > 400 ? GUI::Size(640, TIAConstants::viewableHeight*2) : myAvail(w > 400 ?
GUI::Size(320, TIAConstants::viewableHeight)) GUI::Size(TIAConstants::viewableWidth*2, TIAConstants::viewableHeight*2) :
GUI::Size(TIAConstants::viewableWidth, TIAConstants::viewableHeight))
{ {
_flags = WIDGET_ENABLED; _flags = WIDGET_ENABLED;
_bgcolor = kDlgColor; _bgcolor = kDlgColor;
@ -84,7 +85,8 @@ void RomInfoWidget::parseProperties(const FilesystemNode& node)
// only draw certain parts of it // only draw certain parts of it
if(mySurface == nullptr) if(mySurface == nullptr)
{ {
mySurface = instance().frameBuffer().allocateSurface(320*2, TIAConstants::viewableHeight*2); mySurface = instance().frameBuffer().allocateSurface(
TIAConstants::viewableWidth*2, TIAConstants::viewableHeight*2);
mySurface->attributes().smoothing = true; mySurface->attributes().smoothing = true;
mySurface->applyAttributes(); mySurface->applyAttributes();

View File

@ -16,14 +16,14 @@
//============================================================================ //============================================================================
#include "Dialog.hxx" #include "Dialog.hxx"
#include "FrameBuffer.hxx" #include "FrameBufferConstants.hxx"
#include "TimeMachineDialog.hxx" #include "TimeMachineDialog.hxx"
#include "TimeMachine.hxx" #include "TimeMachine.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
TimeMachine::TimeMachine(OSystem& osystem) TimeMachine::TimeMachine(OSystem& osystem)
: DialogContainer(osystem), : DialogContainer(osystem),
myWidth(FrameBuffer::kFBMinW) myWidth(FBMinimum::Width)
{ {
myBaseDialog = new TimeMachineDialog(myOSystem, *this, myWidth); myBaseDialog = new TimeMachineDialog(myOSystem, *this, myWidth);
} }

View File

@ -133,21 +133,21 @@ UIDialog::UIDialog(OSystem& osystem, DialogContainer& parent,
// Launcher width and height // Launcher width and height
myLauncherWidthSlider = new SliderWidget(myTab, font, xpos, ypos, "Launcher width ", myLauncherWidthSlider = new SliderWidget(myTab, font, xpos, ypos, "Launcher width ",
lwidth, kLauncherSize, 6 * fontWidth, "px"); lwidth, kLauncherSize, 6 * fontWidth, "px");
myLauncherWidthSlider->setMinValue(FrameBuffer::kFBMinW); myLauncherWidthSlider->setMinValue(FBMinimum::Width);
myLauncherWidthSlider->setMaxValue(ds.w); myLauncherWidthSlider->setMaxValue(ds.w);
myLauncherWidthSlider->setStepValue(10); myLauncherWidthSlider->setStepValue(10);
// one tickmark every ~100 pixel // one tickmark every ~100 pixel
myLauncherWidthSlider->setTickmarkInterval((ds.w - FrameBuffer::kFBMinW + 50) / 100); myLauncherWidthSlider->setTickmarkInterval((ds.w - FBMinimum::Width + 50) / 100);
wid.push_back(myLauncherWidthSlider); wid.push_back(myLauncherWidthSlider);
ypos += lineHeight + V_GAP; ypos += lineHeight + V_GAP;
myLauncherHeightSlider = new SliderWidget(myTab, font, xpos, ypos, "Launcher height ", myLauncherHeightSlider = new SliderWidget(myTab, font, xpos, ypos, "Launcher height ",
lwidth, kLauncherSize, 6 * fontWidth, "px"); lwidth, kLauncherSize, 6 * fontWidth, "px");
myLauncherHeightSlider->setMinValue(FrameBuffer::kFBMinH); myLauncherHeightSlider->setMinValue(FBMinimum::Height);
myLauncherHeightSlider->setMaxValue(ds.h); myLauncherHeightSlider->setMaxValue(ds.h);
myLauncherHeightSlider->setStepValue(10); myLauncherHeightSlider->setStepValue(10);
// one tickmark every ~100 pixel // one tickmark every ~100 pixel
myLauncherHeightSlider->setTickmarkInterval((ds.h - FrameBuffer::kFBMinH + 50) / 100); myLauncherHeightSlider->setTickmarkInterval((ds.h - FBMinimum::Height + 50) / 100);
wid.push_back(myLauncherHeightSlider); wid.push_back(myLauncherHeightSlider);
ypos += lineHeight + V_GAP; ypos += lineHeight + V_GAP;
@ -237,8 +237,8 @@ void UIDialog::loadConfig()
const GUI::Size& ls = settings.getSize("launcherres"); const GUI::Size& ls = settings.getSize("launcherres");
uInt32 w = ls.w, h = ls.h; uInt32 w = ls.w, h = ls.h;
w = std::max(w, uInt32(FrameBuffer::kFBMinW)); w = std::max(w, FBMinimum::Width);
h = std::max(h, uInt32(FrameBuffer::kFBMinH)); h = std::max(h, FBMinimum::Height);
w = std::min(w, instance().frameBuffer().desktopSize().w); w = std::min(w, instance().frameBuffer().desktopSize().w);
h = std::min(h, instance().frameBuffer().desktopSize().h); h = std::min(h, instance().frameBuffer().desktopSize().h);