Skip to content
This repository has been archived by the owner on Mar 8, 2024. It is now read-only.

Commit

Permalink
Drop AfxSdlApp friendship with main()
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaffeine committed Apr 24, 2023
1 parent 5790d1a commit 574298f
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 40 deletions.
24 changes: 12 additions & 12 deletions src/libdev/afx/AfxSdlApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@

#include <SDL.h>

AfxSdlApp::AfxSdlApp(int argc, char* argv[])
{
AfxInvokeArgs args;
// start from second arg
for (int i = 1; i < argc; ++i)
{
args.push_back(argv[i]);
}

setArgs(args);
}

void AfxSdlApp::finish()
{
// Make multiple finish calls benign.
Expand All @@ -36,18 +48,6 @@ void AfxSdlApp::testPrint(const char*) const
{
}

void AfxSdlApp::initialise(int argc, char* argv[])
{
AfxInvokeArgs args;
// start from second arg
for (int i = 1; i < argc; ++i)
{
args.push_back(argv[i]);
}

setArgs(args);
}

bool AfxSdlApp::OSStartup()
{
initLogger();
Expand Down
9 changes: 3 additions & 6 deletions src/libdev/afx/AfxSdlApp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class AfxSdlApp : public AfxApp
{
public:
AfxSdlApp() = default;
AfxSdlApp(int argc, char* argv[]);

~AfxSdlApp() override = default;

Expand All @@ -19,12 +19,12 @@ class AfxSdlApp : public AfxApp

void testPrint(const char*) const override;

void setLoggingEnabled(bool enabled);

protected:
bool OSStartup() override;
void OSShutdown() override;

void setLoggingEnabled(bool enabled);

private:
// These are called only by this class from the run method.
// The default implementations call the client and OS specific
Expand All @@ -39,9 +39,6 @@ class AfxSdlApp : public AfxApp
void dispatchKeybrdEvent(SDL_Event*, bool);
void dispatchCharEvent(SDL_Event*);
void dispatchTouchEvent(SDL_Event*, bool);
void initialise(int argc, char* argv[]);

friend int main(int, char*[]);

bool finishing_ { false };
bool finished_ { false };
Expand Down
4 changes: 2 additions & 2 deletions src/libdev/afx/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ void AfxApp::setAppName(const std::string& name)
appName_ = name;
}

void AfxApp::setAppVersion(const std::string& version)
void AfxApp::setVersion(const std::string& version)
{
version_ = version;
}

void AfxApp::setAppBuildVersion(const std::string& buildVersion)
void AfxApp::setBuildVersion(const std::string& buildVersion)
{
buildVersion_ = buildVersion;
}
9 changes: 5 additions & 4 deletions src/libdev/afx/app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,13 @@ class AfxApp

// AfxApplications can provide a name. This is useful for window titles.
const std::string& name() const;
void setAppName(const std::string& name);

const std::string& version() const;
void setVersion(const std::string& version);

const std::string& buildVersion() const;
void setBuildVersion(const std::string& buildVersion);

// Get the arguments that were supplied at program invocation.
// This does *not* include the program name as the first element
Expand Down Expand Up @@ -78,10 +83,6 @@ class AfxApp
// just for the sake of consistency.
virtual void updateDisplay() = 0;

void setAppName(const std::string& name);
void setAppVersion(const std::string& version);
void setAppBuildVersion(const std::string& buildVersion);

ExitStatus exitStatus() const;
void exitStatus(ExitStatus);

Expand Down
8 changes: 3 additions & 5 deletions src/projects/machines/machines_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@

int main(int argc, char* argv[])
{
SDLApp app;
SDLApp app(argc, argv);
app.setAppName("Machines");
app.setAppVersion(machinesVersion());
app.setAppBuildVersion(machinesBuildVersion());
app.setVersion(machinesVersion());
app.setBuildVersion(machinesBuildVersion());
app.setLoggingEnabled(true);

try
{
app.initialise(argc, argv);

auto const runResult = app.run();

return runResult;
Expand Down
5 changes: 3 additions & 2 deletions src/projects/machines/sdlapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ void debugTiming(const char* text, bool startTiming)
}
}

SDLApp::SDLApp()
: winWidth_(400)
SDLApp::SDLApp(int argc, char* argv[])
: AfxSdlApp(argc, argv)
, winWidth_(400)
, winHeight_(300)
, pDisplay_(nullptr)
, pRoot_(nullptr)
Expand Down
2 changes: 1 addition & 1 deletion src/projects/machines/sdlapp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class MachGuiStartupScreens;
class SDLApp : public AfxSdlApp
{
public:
SDLApp();
SDLApp(int argc, char* argv[]);
~SDLApp() override;

enum StartedFromLobby
Expand Down
8 changes: 3 additions & 5 deletions src/projects/planeted/planeted_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@

int main(int argc, char* argv[])
{
SDLApp app;
SDLApp app(argc, argv);
app.setAppName("Machines Planet Editor");
app.setAppVersion("v0.00.01");
app.setAppBuildVersion(machinesBuildVersion());
app.setVersion("v0.00.01");
app.setBuildVersion(machinesBuildVersion());

try
{
app.initialise(argc, argv);

auto const runResult = app.run();

return runResult;
Expand Down
5 changes: 3 additions & 2 deletions src/projects/planeted/sdlapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,9 @@ void debugTiming(const char* text, bool startTiming)
}
}

SDLApp::SDLApp()
: winWidth_(400)
SDLApp::SDLApp(int argc, char* argv[])
: AfxSdlApp(argc, argv)
, winWidth_(400)
, winHeight_(300)
, pPlanet_(nullptr)
, pDisplay_(nullptr)
Expand Down
2 changes: 1 addition & 1 deletion src/projects/planeted/sdlapp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class EnvPlanetEnvironment;
class SDLApp : public AfxSdlApp
{
public:
SDLApp();
SDLApp(int argc, char* argv[]);
~SDLApp() override;

private:
Expand Down

0 comments on commit 574298f

Please sign in to comment.