1
0
Fork 0
mirror of https://github.com/gwm17/Specter.git synced 2024-11-22 18:28:52 -05:00

Modified Application to allow for setting of the runtime path programatically. This helps avoid copying assets to the binary directory by setting the runtime path to SpecProject.

This commit is contained in:
Gordon McCann 2022-07-09 09:22:11 -04:00
parent 6753678e69
commit 830aef4f9f
5 changed files with 36 additions and 11 deletions

View File

@ -46,4 +46,5 @@ endif()
set_target_properties(SpecProject PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${SPECTER_BINARY_DIR})
add_custom_command(TARGET SpecProject POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/Assets ${SPECTER_BINARY_DIR}/Assets)
#No longer needed, but maybe come back if I don't like the programatic solution
#add_custom_command(TARGET SpecProject POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/Assets ${SPECTER_BINARY_DIR}/Assets)

View File

@ -7,13 +7,14 @@
#include "Specter.h"
#include "SPSAnalysisStage.h"
#include "SPSInputLayer.h"
#include <filesystem>
//User application class. Pushes user analysis stages.
class SPSApp : public Specter::Application
{
public:
SPSApp() :
Specter::Application()
SPSApp(const Specter::ApplicationArgs& args) :
Specter::Application(args)
{
PushLayer(new Specter::SPSInputLayer());
//PushLayer(new Navigator::TestServerLayer());
@ -22,7 +23,7 @@ public:
};
//Define the creation function to make our user application
Specter::Application* Specter::CreateApplication() { return new SPSApp(); }
Specter::Application* Specter::CreateApplication(const ApplicationArgs& args) { return new SPSApp(args); }
//Make sure to initialize log BEFORE creating application.
int main(int argc, const char** argv)
@ -30,8 +31,15 @@ int main(int argc, const char** argv)
Specter::Logger::Init();
SPEC_TRACE("Logger Initialized!");
Specter::ApplicationArgs args;
args.name = "SPS Specter";
if (std::filesystem::current_path().string().find("SpecProject") != std::string::npos)
args.runtimePath = ""; //Dont modify runtime path, already points to SpecProject
else
args.runtimePath = "../SpecProject"; //Assume we're attempting to run from bin dir? Technically would also work for any new subproject made by same method as SpecProject
SPEC_PROFILE_BEGIN_SESSION("Startup", "navprofile_startup.json");
auto app = Specter::CreateApplication();
auto app = Specter::CreateApplication(args);
SPEC_PROFILE_END_SESSION();
SPEC_PROFILE_BEGIN_SESSION("Runtime", "navprofile_runtime.json");

View File

@ -18,14 +18,20 @@ namespace Specter {
Application* Application::s_instance = nullptr;
Application::Application() :
m_runFlag(true)
Application::Application(const ApplicationArgs& args) :
m_args(args), m_runFlag(true)
{
SPEC_PROFILE_FUNCTION();
s_instance = this;
m_window = std::unique_ptr<Window>(Window::Create());
//Set the runtime path so that we can find our assets
if(!m_args.runtimePath.empty())
std::filesystem::current_path(m_args.runtimePath);
SPEC_INFO("Runtime Directory: {0}", std::filesystem::current_path().string());
m_window = std::unique_ptr<Window>(Window::Create({m_args.name, 1280, 720}));
m_window->SetEventCallback(BIND_EVENT_FUNCTION(Application::OnEvent)); //Allow window to pass events back
m_physicsLayer = new PhysicsLayer();

View File

@ -24,10 +24,16 @@
namespace Specter {
struct ApplicationArgs
{
std::string name = "";
std::string runtimePath = "";
};
class Application
{
public:
Application();
Application(const ApplicationArgs& args);
virtual ~Application();
void Run();
@ -42,9 +48,13 @@ namespace Specter {
inline Window& GetWindow() { return *m_window; }
inline const ApplicationArgs& GetArgs() { return m_args; }
private:
bool OnWindowCloseEvent(WindowCloseEvent& event);
ApplicationArgs m_args;
LayerStack m_stack;
std::unique_ptr<Window> m_window;
ImGuiLayer* m_imgui_layer;
@ -62,7 +72,7 @@ namespace Specter {
This function is left to be defined by the user. In principle we don't need to do this, as the Specter library doesn't handle creation of the application,
but I like it and might be useful for changing to a system with a pre-defined entry point.
*/
Application* CreateApplication();
Application* CreateApplication(const ApplicationArgs& args);
}
#endif

View File

@ -1,6 +1,6 @@
/*
SpectrumSerializer.h
SpectrumSerializer class providing method to write/read spectra (histograms and cuts) to/from a .nav file. These are formated text files.
SpectrumSerializer class providing method to write/read spectra (histograms and cuts) to/from a .spec file. These are formated text files.
Note that by virtue of the way that cuts work, they are written first.
A couple of notes: