common2: add namespace and reformat everything with space over tabs.

This makes it "possible" to use other editors (than emacs).

Signed-off-by: Andrea Odetti <mariofutire@gmail.com>
This commit is contained in:
Andrea Odetti 2021-02-25 16:04:50 +00:00
parent 9366956c49
commit 3b917e93be
27 changed files with 623 additions and 542 deletions

View file

@ -60,6 +60,9 @@ namespace
} }
namespace common2
{
CommonFrame::CommonFrame() CommonFrame::CommonFrame()
: myResourcePath(getResourcePath()) : myResourcePath(getResourcePath())
{ {
@ -114,3 +117,5 @@ std::string CommonFrame::getBitmapFilename(const std::string & resource)
return resource; return resource;
} }
}

View file

@ -4,6 +4,9 @@
#include <vector> #include <vector>
#include <string> #include <string>
namespace common2
{
class CommonFrame : public LinuxFrame class CommonFrame : public LinuxFrame
{ {
public: public:
@ -19,3 +22,5 @@ protected:
const std::string myResourcePath; const std::string myResourcePath;
std::vector<BYTE> myResource; std::vector<BYTE> myResource;
}; };
}

View file

@ -39,7 +39,7 @@ namespace
return std::string(homeDir); return std::string(homeDir);
} }
class Configuration : public PTreeRegistry class Configuration : public common2::PTreeRegistry
{ {
public: public:
Configuration(const std::string & filename, const bool saveOnExit); Configuration(const std::string & filename, const bool saveOnExit);
@ -84,6 +84,9 @@ namespace
} }
namespace common2
{
std::string GetConfigFile(const std::string & filename) std::string GetConfigFile(const std::string & filename)
{ {
const std::string dir = getHomeDir() + "/.applewin"; const std::string dir = getHomeDir() + "/.applewin";
@ -123,3 +126,5 @@ void InitializeFileRegistry(const EmulatorOptions & options)
Registry::instance = config; Registry::instance = config;
} }
}

View file

@ -2,7 +2,12 @@
#include <string> #include <string>
namespace common2
{
struct EmulatorOptions; struct EmulatorOptions;
std::string GetConfigFile(const std::string & filename); std::string GetConfigFile(const std::string & filename);
void InitializeFileRegistry(const EmulatorOptions & options); void InitializeFileRegistry(const EmulatorOptions & options);
}

View file

@ -19,7 +19,7 @@ namespace po = boost::program_options;
namespace namespace
{ {
void parseGeometry(const std::string & s, Geometry & geometry) void parseGeometry(const std::string & s, common2::Geometry & geometry)
{ {
std::smatch m; std::smatch m;
if (std::regex_match(s, m, std::regex("^(\\d+)x(\\d+)(\\+(\\d+)\\+(\\d+))?$"))) if (std::regex_match(s, m, std::regex("^(\\d+)x(\\d+)(\\+(\\d+)\\+(\\d+))?$")))
@ -42,6 +42,9 @@ namespace
} }
namespace common2
{
bool getEmulatorOptions(int argc, const char * argv [], const std::string & edition, EmulatorOptions & options) bool getEmulatorOptions(int argc, const char * argv [], const std::string & edition, EmulatorOptions & options)
{ {
const std::string name = "Apple Emulator for " + edition + " (based on AppleWin " + getVersion() + ")"; const std::string name = "Apple Emulator for " + edition + " (based on AppleWin " + getVersion() + ")";
@ -213,3 +216,5 @@ void applyOptions(const EmulatorOptions & options)
Paddle::setSquaring(options.paddleSquaring); Paddle::setSquaring(options.paddleSquaring);
} }
}

View file

@ -3,6 +3,8 @@
#include <string> #include <string>
#include <vector> #include <vector>
namespace common2
{
struct Geometry struct Geometry
{ {
@ -55,3 +57,5 @@ struct EmulatorOptions
bool getEmulatorOptions(int argc, const char * argv [], const std::string & edition, EmulatorOptions & options); bool getEmulatorOptions(int argc, const char * argv [], const std::string & edition, EmulatorOptions & options);
void applyOptions(const EmulatorOptions & options); void applyOptions(const EmulatorOptions & options);
}

View file

@ -16,6 +16,9 @@ namespace
} }
namespace common2
{
bool PTreeRegistry::KeyQtEncodedLess::operator()(const std::string & lhs, const std::string & rhs) const bool PTreeRegistry::KeyQtEncodedLess::operator()(const std::string & lhs, const std::string & rhs) const
{ {
const std::string key1 = decodeKey(lhs); const std::string key1 = decodeKey(lhs);
@ -62,3 +65,5 @@ void PTreeRegistry::putValue(const std::string & section, const std::string & ke
const std::string path = section + "." + key; const std::string path = section + "." + key;
myINI.put(path, value); myINI.put(path, value);
} }
}

View file

@ -4,6 +4,8 @@
#include <boost/property_tree/ptree.hpp> #include <boost/property_tree/ptree.hpp>
#include <string> #include <string>
namespace common2
{
class PTreeRegistry : public Registry class PTreeRegistry : public Registry
{ {
@ -34,3 +36,5 @@ public:
protected: protected:
ini_t myINI; ini_t myINI;
}; };
}

View file

@ -4,6 +4,9 @@
#include "CPU.h" #include "CPU.h"
#include "Core.h" #include "Core.h"
namespace common2
{
Speed::Speed(const bool fixedSpeed) Speed::Speed(const bool fixedSpeed)
: myFixedSpeed(fixedSpeed) : myFixedSpeed(fixedSpeed)
{ {
@ -47,3 +50,5 @@ size_t Speed::getCyclesTillNext(const size_t microseconds) const
} }
} }
} }
}

View file

@ -2,6 +2,9 @@
#include <chrono> #include <chrono>
namespace common2
{
class Speed class Speed
{ {
public: public:
@ -19,3 +22,5 @@ private:
std::chrono::time_point<std::chrono::steady_clock> myStartTime; std::chrono::time_point<std::chrono::steady_clock> myStartTime;
uint64_t myStartCycles; uint64_t myStartCycles;
}; };
}

View file

@ -4,6 +4,9 @@
#include <cmath> #include <cmath>
#include <iomanip> #include <iomanip>
namespace common2
{
Timer::Timer() Timer::Timer()
: mySum(0) : mySum(0)
, mySum2(0) , mySum2(0)
@ -46,3 +49,5 @@ std::ostream& operator<<(std::ostream& os, const Timer & timer)
os << ", n = " << std::setw(6) << timer.myN; os << ", n = " << std::setw(6) << timer.myN;
return os; return os;
} }
}

View file

@ -1,6 +1,9 @@
#include <chrono> #include <chrono>
#include <iosfwd> #include <iosfwd>
namespace common2
{
class Timer class Timer
{ {
public: public:
@ -22,3 +25,5 @@ private:
}; };
std::ostream& operator<<(std::ostream& os, const Timer & timer); std::ostream& operator<<(std::ostream& os, const Timer & timer);
}

View file

@ -30,6 +30,9 @@
#include <libgen.h> #include <libgen.h>
#include <unistd.h> #include <unistd.h>
namespace common2
{
void setSnapshotFilename(const std::string & filename, const bool load) void setSnapshotFilename(const std::string & filename, const bool load)
{ {
// same logic as qapple // same logic as qapple
@ -109,3 +112,5 @@ Initialisation::~Initialisation()
LogDone(); LogDone();
RiffFinishWriteFile(); RiffFinishWriteFile();
} }
}

View file

@ -2,6 +2,9 @@
#include <string> #include <string>
namespace common2
{
void setSnapshotFilename(const std::string & filename, const bool load); void setSnapshotFilename(const std::string & filename, const bool load);
class Initialisation class Initialisation
@ -10,3 +13,5 @@ public:
Initialisation(); Initialisation();
~Initialisation(); ~Initialisation();
}; };
}

View file

@ -58,7 +58,7 @@ Game::Game(const std::shared_ptr<RetroFrame> & frame)
LogInit(); LogInit();
InitialiseRetroRegistry(); InitialiseRetroRegistry();
myInit.reset(new Initialisation); myInit.reset(new common2::Initialisation);
switch (ourInputDevices[0]) switch (ourInputDevices[0])
{ {
@ -286,6 +286,6 @@ bool Game::loadGame(const std::string & path)
bool Game::loadSnapshot(const std::string & path) bool Game::loadSnapshot(const std::string & path)
{ {
setSnapshotFilename(path, true); common2::setSnapshotFilename(path, true);
return true; return true;
} }

View file

@ -6,8 +6,12 @@
#include <string> #include <string>
#include <vector> #include <vector>
class RetroFrame; namespace common2
{
class Initialisation; class Initialisation;
}
class RetroFrame;
class Game class Game
{ {
@ -33,11 +37,11 @@ public:
private: private:
const std::shared_ptr<RetroFrame> myFrame; const std::shared_ptr<RetroFrame> myFrame;
Speed mySpeed; // fixed speed common2::Speed mySpeed; // fixed speed
std::vector<int> myButtonStates; std::vector<int> myButtonStates;
std::shared_ptr<Initialisation> myInit; std::shared_ptr<common2::Initialisation> myInit;
bool checkButtonPressed(unsigned id); bool checkButtonPressed(unsigned id);
void keyboardEmulation(); void keyboardEmulation();

View file

@ -5,7 +5,7 @@
#include <memory> #include <memory>
#include <vector> #include <vector>
class RetroFrame : public CommonFrame class RetroFrame : public common2::CommonFrame
{ {
public: public:
RetroFrame(); RetroFrame();

View file

@ -132,7 +132,7 @@ void SetupRetroVariables()
void InitialiseRetroRegistry() void InitialiseRetroRegistry()
{ {
const auto registry = std::make_shared<PTreeRegistry>(); const auto registry = std::make_shared<common2::PTreeRegistry>();
for (const Variable & variable : ourVariables) for (const Variable & variable : ourVariables)
{ {

View file

@ -27,7 +27,7 @@
namespace namespace
{ {
bool ContinueExecution(const EmulatorOptions & options, const std::shared_ptr<NFrame> & frame) bool ContinueExecution(const common2::EmulatorOptions & options, const std::shared_ptr<NFrame> & frame)
{ {
const auto start = std::chrono::steady_clock::now(); const auto start = std::chrono::steady_clock::now();
@ -130,7 +130,7 @@ namespace
} }
} }
void EnterMessageLoop(const EmulatorOptions & options, const std::shared_ptr<NFrame> & frame) void EnterMessageLoop(const common2::EmulatorOptions & options, const std::shared_ptr<NFrame> & frame)
{ {
LogFileTimeUntilFirstKeyReadReset(); LogFileTimeUntilFirstKeyReadReset();
while (ContinueExecution(options, frame)) while (ContinueExecution(options, frame))
@ -140,7 +140,7 @@ namespace
int run_ncurses(int argc, const char * argv []) int run_ncurses(int argc, const char * argv [])
{ {
EmulatorOptions options; common2::EmulatorOptions options;
options.memclear = g_nMemoryClearType; options.memclear = g_nMemoryClearType;
const bool run = getEmulatorOptions(argc, argv, "ncurses", options); const bool run = getEmulatorOptions(argc, argv, "ncurses", options);
@ -161,7 +161,7 @@ namespace
g_nMemoryClearType = options.memclear; g_nMemoryClearType = options.memclear;
Initialisation init; common2::Initialisation init;
SetCtrlCHandler(options.headless); SetCtrlCHandler(options.headless);
applyOptions(options); applyOptions(options);

View file

@ -10,7 +10,7 @@ class ASCIIArt;
class EvDevPaddle; class EvDevPaddle;
struct NCurses; struct NCurses;
class NFrame : public CommonFrame class NFrame : public common2::CommonFrame
{ {
public: public:
NFrame(const std::string & paddleDevice); NFrame(const std::string & paddleDevice);

View file

@ -35,7 +35,7 @@ namespace
} }
SDLImGuiFrame::SDLImGuiFrame(const EmulatorOptions & options) SDLImGuiFrame::SDLImGuiFrame(const common2::EmulatorOptions & options)
: SDLFrame(options) : SDLFrame(options)
{ {
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, 0); SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, 0);
@ -49,7 +49,7 @@ SDLImGuiFrame::SDLImGuiFrame(const EmulatorOptions & options)
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
const SDL_WindowFlags windowFlags = (SDL_WindowFlags)(SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE); const SDL_WindowFlags windowFlags = (SDL_WindowFlags)(SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
const Geometry & geometry = options.geometry; const common2::Geometry & geometry = options.geometry;
myWindow.reset(SDL_CreateWindow(g_pAppTitle.c_str(), geometry.x, geometry.y, geometry.width, geometry.height, windowFlags), SDL_DestroyWindow); myWindow.reset(SDL_CreateWindow(g_pAppTitle.c_str(), geometry.x, geometry.y, geometry.width, geometry.height, windowFlags), SDL_DestroyWindow);
if (!myWindow) if (!myWindow)
@ -81,7 +81,7 @@ SDLImGuiFrame::SDLImGuiFrame(const EmulatorOptions & options)
ImGui::CreateContext(); ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO(); ImGuiIO& io = ImGui::GetIO();
mySettings.iniFileLocation = GetConfigFile("imgui.ini"); mySettings.iniFileLocation = common2::GetConfigFile("imgui.ini");
if (mySettings.iniFileLocation.empty()) if (mySettings.iniFileLocation.empty())
{ {
io.IniFilename = nullptr; io.IniFilename = nullptr;

View file

@ -3,12 +3,15 @@
#include "frontends/sdl/sdlframe.h" #include "frontends/sdl/sdlframe.h"
#include "frontends/sdl/imgui/gles.h" #include "frontends/sdl/imgui/gles.h"
namespace common2
{
class EmulatorOptions; class EmulatorOptions;
}
class SDLImGuiFrame : public SDLFrame class SDLImGuiFrame : public SDLFrame
{ {
public: public:
SDLImGuiFrame(const EmulatorOptions & options); SDLImGuiFrame(const common2::EmulatorOptions & options);
~SDLImGuiFrame() override; ~SDLImGuiFrame() override;

View file

@ -53,7 +53,7 @@ namespace
return current.refresh_rate; return current.refresh_rate;
} }
void execute(Speed speed, const size_t next) void execute(common2::Speed speed, const size_t next)
{ {
if (g_nAppMode == MODE_RUNNING) if (g_nAppMode == MODE_RUNNING)
{ {
@ -73,9 +73,9 @@ namespace
struct Data struct Data
{ {
Speed * speed; common2::Speed * speed;
SDL_mutex * mutex; SDL_mutex * mutex;
Timer * timer; common2::Timer * timer;
}; };
Uint32 emulator_callback(Uint32 interval, void *param) Uint32 emulator_callback(Uint32 interval, void *param)
@ -97,7 +97,7 @@ void run_sdl(int argc, const char * argv [])
{ {
std::cerr << std::fixed << std::setprecision(2); std::cerr << std::fixed << std::setprecision(2);
EmulatorOptions options; common2::EmulatorOptions options;
Video & video = GetVideo(); Video & video = GetVideo();
const int sw = video.GetFrameBufferBorderlessWidth(); const int sw = video.GetFrameBufferBorderlessWidth();
@ -146,7 +146,7 @@ void run_sdl(int argc, const char * argv [])
g_nMemoryClearType = options.memclear; g_nMemoryClearType = options.memclear;
Initialisation init; common2::Initialisation init;
applyOptions(options); applyOptions(options);
const int fps = getRefreshRate(); const int fps = getRefreshRate();
@ -177,17 +177,17 @@ void run_sdl(int argc, const char * argv [])
} }
else else
{ {
Timer global; common2::Timer global;
Timer updateTextureTimer; common2::Timer updateTextureTimer;
Timer refreshScreenTimer; common2::Timer refreshScreenTimer;
Timer cpuTimer; common2::Timer cpuTimer;
Timer eventTimer; common2::Timer eventTimer;
Timer frameTimer; common2::Timer frameTimer;
const std::string globalTag = ". ."; const std::string globalTag = ". .";
std::string updateTextureTimerTag, refreshScreenTimerTag, cpuTimerTag, eventTimerTag; std::string updateTextureTimerTag, refreshScreenTimerTag, cpuTimerTag, eventTimerTag;
Speed speed(options.fixedSpeed); common2::Speed speed(options.fixedSpeed);
if (options.multiThreaded) if (options.multiThreaded)
{ {

View file

@ -8,10 +8,10 @@
#include <iostream> #include <iostream>
SDLRendererFrame::SDLRendererFrame(const EmulatorOptions & options) SDLRendererFrame::SDLRendererFrame(const common2::EmulatorOptions & options)
: SDLFrame(options) : SDLFrame(options)
{ {
const Geometry & geometry = options.geometry; const common2::Geometry & geometry = options.geometry;
myWindow.reset(SDL_CreateWindow(g_pAppTitle.c_str(), geometry.x, geometry.y, geometry.width, geometry.height, SDL_WINDOW_RESIZABLE), SDL_DestroyWindow); myWindow.reset(SDL_CreateWindow(g_pAppTitle.c_str(), geometry.x, geometry.y, geometry.width, geometry.height, SDL_WINDOW_RESIZABLE), SDL_DestroyWindow);
if (!myWindow) if (!myWindow)

View file

@ -2,12 +2,15 @@
#include "frontends/sdl/sdlframe.h" #include "frontends/sdl/sdlframe.h"
namespace common2
{
class EmulatorOptions; class EmulatorOptions;
}
class SDLRendererFrame : public SDLFrame class SDLRendererFrame : public SDLFrame
{ {
public: public:
SDLRendererFrame(const EmulatorOptions & options); SDLRendererFrame(const common2::EmulatorOptions & options);
void UpdateTexture() override; void UpdateTexture() override;
void RenderPresent() override; void RenderPresent() override;

View file

@ -112,7 +112,7 @@ namespace
} }
SDLFrame::SDLFrame(const EmulatorOptions & options) SDLFrame::SDLFrame(const common2::EmulatorOptions & options)
: myForceCapsLock(true) : myForceCapsLock(true)
, myMultiplier(1) , myMultiplier(1)
, myFullscreen(false) , myFullscreen(false)

View file

@ -4,12 +4,15 @@
#include "frontends/common2/speed.h" #include "frontends/common2/speed.h"
#include <SDL.h> #include <SDL.h>
namespace common2
{
struct EmulatorOptions; struct EmulatorOptions;
}
class SDLFrame : public CommonFrame class SDLFrame : public common2::CommonFrame
{ {
public: public:
SDLFrame(const EmulatorOptions & options); SDLFrame(const common2::EmulatorOptions & options);
void VideoPresentScreen() override; void VideoPresentScreen() override;
void FrameRefreshStatus(int drawflags) override; void FrameRefreshStatus(int drawflags) override;
@ -38,5 +41,5 @@ protected:
int myMultiplier; int myMultiplier;
bool myFullscreen; bool myFullscreen;
Speed mySpeed; common2::Speed mySpeed;
}; };