mirror of
https://github.com/gwm17/Specter.git
synced 2024-11-22 18:28:52 -05:00
Beginning addition of physics event building/analysis pipeline. Separate thread with event builder, start user customizable data analysis
This commit is contained in:
parent
7001ef21a4
commit
e723416fcc
|
@ -1,6 +1,7 @@
|
||||||
#include "Navigator.h"
|
#include "Navigator.h"
|
||||||
|
|
||||||
Navigator::Application* Navigator::CreateApplication() { return new Application(); }
|
Navigator::Application* Navigator::CreateApplication() { return new Application(); }
|
||||||
|
Navigator::PhysicsEventBuilder* Navigator::CreatePhysicsEventBuilder() { return new PhysicsEventBuilder(); }
|
||||||
|
|
||||||
int main(int argc, const char** argv)
|
int main(int argc, const char** argv)
|
||||||
{
|
{
|
||||||
|
@ -9,7 +10,6 @@ int main(int argc, const char** argv)
|
||||||
|
|
||||||
auto app = Navigator::CreateApplication();
|
auto app = Navigator::CreateApplication();
|
||||||
|
|
||||||
NAV_TRACE("Navigator Application Created!");
|
|
||||||
app->Run();
|
app->Run();
|
||||||
|
|
||||||
delete app;
|
delete app;
|
||||||
|
|
|
@ -14,19 +14,39 @@ namespace Navigator {
|
||||||
m_window = std::unique_ptr<Window>(Window::Create());
|
m_window = std::unique_ptr<Window>(Window::Create());
|
||||||
m_window->SetEventCallback(BIND_EVENT_FUNCTION(Application::OnEvent));
|
m_window->SetEventCallback(BIND_EVENT_FUNCTION(Application::OnEvent));
|
||||||
|
|
||||||
|
CreatePhysicsEventBuilder();
|
||||||
|
|
||||||
PushLayer(new Layer());
|
PushLayer(new Layer());
|
||||||
|
|
||||||
m_imgui_layer = new ImGuiLayer();
|
m_imgui_layer = new ImGuiLayer();
|
||||||
PushOverlay(m_imgui_layer);
|
PushOverlay(m_imgui_layer);
|
||||||
}
|
}
|
||||||
|
|
||||||
Application::~Application() {}
|
Application::~Application()
|
||||||
|
{
|
||||||
|
if(PhysicsEventBuilder::Get().IsRunning())
|
||||||
|
{
|
||||||
|
NAV_INFO("Detaching PhysicsEventBuilder at shutdown");
|
||||||
|
PhysicsEventBuilder::Get().DetachDataSource();
|
||||||
|
DestroyPhysThread();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Application::DestroyPhysThread()
|
||||||
|
{
|
||||||
|
if(m_physThread != nullptr && m_physThread->joinable())
|
||||||
|
m_physThread->join();
|
||||||
|
|
||||||
|
if(m_physThread != nullptr)
|
||||||
|
delete m_physThread;
|
||||||
|
}
|
||||||
|
|
||||||
void Application::OnEvent(Event& event)
|
void Application::OnEvent(Event& event)
|
||||||
{
|
{
|
||||||
EventDispatcher dispatch(event);
|
EventDispatcher dispatch(event);
|
||||||
dispatch.Dispatch<WindowCloseEvent>(BIND_EVENT_FUNCTION(Application::OnWindowCloseEvent));
|
dispatch.Dispatch<WindowCloseEvent>(BIND_EVENT_FUNCTION(Application::OnWindowCloseEvent));
|
||||||
|
dispatch.Dispatch<PhysicsStartEvent>(BIND_EVENT_FUNCTION(Application::OnPhysicsStartEvent));
|
||||||
|
dispatch.Dispatch<PhysicsStopEvent>(BIND_EVENT_FUNCTION(Application::OnPhysicsStopEvent));
|
||||||
for(auto iter = m_stack.end(); iter != m_stack.begin(); )
|
for(auto iter = m_stack.end(); iter != m_stack.begin(); )
|
||||||
{
|
{
|
||||||
(*(--iter))->OnEvent(event);
|
(*(--iter))->OnEvent(event);
|
||||||
|
@ -42,6 +62,28 @@ namespace Navigator {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Application::OnPhysicsStartEvent(PhysicsStartEvent& event)
|
||||||
|
{
|
||||||
|
if(PhysicsEventBuilder::Get().IsRunning())
|
||||||
|
{
|
||||||
|
PhysicsEventBuilder::Get().DetachDataSource();
|
||||||
|
NAV_INFO("Stopping the event builder...");
|
||||||
|
DestroyPhysThread();
|
||||||
|
}
|
||||||
|
PhysicsEventBuilder::Get().AttachDataSource();
|
||||||
|
NAV_INFO("Starting the event builder...");
|
||||||
|
m_physThread = new std::thread(&PhysicsEventBuilder::Run, std::ref(PhysicsEventBuilder::Get()));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Application::OnPhysicsStopEvent(PhysicsStopEvent& event)
|
||||||
|
{
|
||||||
|
PhysicsEventBuilder::Get().DetachDataSource();
|
||||||
|
NAV_INFO("Stopping the event builder...");
|
||||||
|
DestroyPhysThread();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void Application::PushLayer(Layer* layer)
|
void Application::PushLayer(Layer* layer)
|
||||||
{
|
{
|
||||||
m_stack.PushLayer(layer);
|
m_stack.PushLayer(layer);
|
||||||
|
@ -56,6 +98,8 @@ namespace Navigator {
|
||||||
|
|
||||||
void Application::Run()
|
void Application::Run()
|
||||||
{
|
{
|
||||||
|
PhysicsStartEvent junk;
|
||||||
|
OnEvent(junk);
|
||||||
while(m_runFlag)
|
while(m_runFlag)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
|
@ -4,10 +4,13 @@
|
||||||
#include "Navigator/NavCore.h"
|
#include "Navigator/NavCore.h"
|
||||||
#include "Events/Event.h"
|
#include "Events/Event.h"
|
||||||
#include "Navigator/Events/AppEvent.h"
|
#include "Navigator/Events/AppEvent.h"
|
||||||
|
#include "Navigator/Events/PhysicsEvent.h"
|
||||||
#include "Navigator/LayerStack.h"
|
#include "Navigator/LayerStack.h"
|
||||||
#include "Navigator/Layer.h"
|
#include "Navigator/Layer.h"
|
||||||
#include "Navigator/Window.h"
|
#include "Navigator/Window.h"
|
||||||
#include "Navigator/ImGui/ImGuiLayer.h"
|
#include "Navigator/ImGui/ImGuiLayer.h"
|
||||||
|
#include "Navigator/Physics/PhysicsEventBuilder.h"
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
namespace Navigator {
|
namespace Navigator {
|
||||||
|
|
||||||
|
@ -29,6 +32,12 @@ namespace Navigator {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool OnWindowCloseEvent(WindowCloseEvent& event);
|
bool OnWindowCloseEvent(WindowCloseEvent& event);
|
||||||
|
bool OnPhysicsStartEvent(PhysicsStartEvent& event);
|
||||||
|
bool OnPhysicsStopEvent(PhysicsStopEvent& event);
|
||||||
|
|
||||||
|
void DestroyPhysThread();
|
||||||
|
|
||||||
|
std::thread* m_physThread;
|
||||||
|
|
||||||
LayerStack m_stack;
|
LayerStack m_stack;
|
||||||
std::unique_ptr<Window> m_window;
|
std::unique_ptr<Window> m_window;
|
||||||
|
|
|
@ -1,19 +0,0 @@
|
||||||
#ifndef COMPASS_HIT_H
|
|
||||||
#define COMPASS_HIT_H
|
|
||||||
|
|
||||||
namespace Navigator {
|
|
||||||
|
|
||||||
struct CompassHit
|
|
||||||
{
|
|
||||||
uint16_t board = 400;
|
|
||||||
uint16_t channel = 400;
|
|
||||||
uint64_t timestamp = 0;
|
|
||||||
uint16_t lgate = 0;
|
|
||||||
uint16_t sgate = 0;
|
|
||||||
uint32_t flags = 0;
|
|
||||||
uint32_t Ns = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -11,7 +11,8 @@ namespace Navigator {
|
||||||
WindowClose, WindowResize, WindowFocus, WindowLostFocus, WindowMoved,
|
WindowClose, WindowResize, WindowFocus, WindowLostFocus, WindowMoved,
|
||||||
KeyPressed, KeyReleased, KeyTyped,
|
KeyPressed, KeyReleased, KeyTyped,
|
||||||
MouseButtonPressed, MouseButtonReleased, MouseScrolled, MouseMoved,
|
MouseButtonPressed, MouseButtonReleased, MouseScrolled, MouseMoved,
|
||||||
AppUpdate
|
AppUpdate,
|
||||||
|
PhysicsStart, PhysicsStop
|
||||||
};
|
};
|
||||||
|
|
||||||
enum EventCategory
|
enum EventCategory
|
||||||
|
@ -21,7 +22,8 @@ namespace Navigator {
|
||||||
EventCategoryInput=BIT(1),
|
EventCategoryInput=BIT(1),
|
||||||
EventCategoryKey=BIT(2),
|
EventCategoryKey=BIT(2),
|
||||||
EventCategoryMouse=BIT(3),
|
EventCategoryMouse=BIT(3),
|
||||||
EventCategoryWindow=BIT(4)
|
EventCategoryWindow=BIT(4),
|
||||||
|
EventCategoryPhysics=BIT(5),
|
||||||
};
|
};
|
||||||
|
|
||||||
//Some function generation automation to reduce code written for all events
|
//Some function generation automation to reduce code written for all events
|
||||||
|
|
38
Navigator/src/Navigator/Events/PhysicsEvent.h
Normal file
38
Navigator/src/Navigator/Events/PhysicsEvent.h
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
#ifndef PHYSICS_EVENT_H
|
||||||
|
#define PHYSICS_EVENT_H
|
||||||
|
|
||||||
|
#include "Event.h"
|
||||||
|
|
||||||
|
namespace Navigator {
|
||||||
|
|
||||||
|
class PhysicsStartEvent : public Event
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
PhysicsStartEvent() {}
|
||||||
|
|
||||||
|
std::string ToString() const override
|
||||||
|
{
|
||||||
|
return "Starting PhysicsEventBuilder";
|
||||||
|
}
|
||||||
|
|
||||||
|
EVENT_CATEGORY_SETUP(EventCategoryPhysics);
|
||||||
|
EVENT_TYPE_SETUP(PhysicsStart);
|
||||||
|
};
|
||||||
|
|
||||||
|
class PhysicsStopEvent : public Event
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
PhysicsStopEvent() {}
|
||||||
|
|
||||||
|
std::string ToString() const override
|
||||||
|
{
|
||||||
|
return "Stopping PhysicsEventBuilder";
|
||||||
|
}
|
||||||
|
|
||||||
|
EVENT_CATEGORY_SETUP(EventCategoryPhysics);
|
||||||
|
EVENT_TYPE_SETUP(PhysicsStop);
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
12
Navigator/src/Navigator/Physics/AnalysisStage.cpp
Normal file
12
Navigator/src/Navigator/Physics/AnalysisStage.cpp
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
#include "AnalysisStage.h"
|
||||||
|
|
||||||
|
namespace Navigator {
|
||||||
|
|
||||||
|
AnalysisStage::AnalysisStage(const std::string& name) :
|
||||||
|
m_name(name)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
AnalysisStage::~AnalysisStage() {}
|
||||||
|
|
||||||
|
}
|
27
Navigator/src/Navigator/Physics/AnalysisStage.h
Normal file
27
Navigator/src/Navigator/Physics/AnalysisStage.h
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
#ifndef ANALYSIS_STAGE_H
|
||||||
|
#define ANALYSIS_STAGE_H
|
||||||
|
|
||||||
|
#include "CompassHit.h"
|
||||||
|
|
||||||
|
namespace Navigator {
|
||||||
|
|
||||||
|
class AnalysisStage
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
using RawPhysicsEvent = std::vector<CompassHit>;
|
||||||
|
|
||||||
|
AnalysisStage(const std::string& name="AnalysisStage");
|
||||||
|
virtual ~AnalysisStage();
|
||||||
|
|
||||||
|
virtual void AnalyzeRawPhysicsEvent(const RawPhysicsEvent& event) {};
|
||||||
|
|
||||||
|
void AttachParameterMap() {};
|
||||||
|
|
||||||
|
inline std::string GetName() { return m_name; }
|
||||||
|
private:
|
||||||
|
std::string m_name;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
19
Navigator/src/Navigator/Physics/CompassHit.h
Normal file
19
Navigator/src/Navigator/Physics/CompassHit.h
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
#ifndef COMPASS_HIT_H
|
||||||
|
#define COMPASS_HIT_H
|
||||||
|
|
||||||
|
namespace Navigator {
|
||||||
|
|
||||||
|
struct CompassHit
|
||||||
|
{
|
||||||
|
uint16_t board = 0;
|
||||||
|
uint16_t channel = 0;
|
||||||
|
uint64_t timestamp = 0;
|
||||||
|
uint16_t lgate = 0;
|
||||||
|
uint16_t sgate = 0;
|
||||||
|
uint32_t flags = 0;
|
||||||
|
uint32_t Ns = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
70
Navigator/src/Navigator/Physics/PhysicsEventBuilder.cpp
Normal file
70
Navigator/src/Navigator/Physics/PhysicsEventBuilder.cpp
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
#include "PhysicsEventBuilder.h"
|
||||||
|
|
||||||
|
//temp
|
||||||
|
#include "CompassHit.h"
|
||||||
|
|
||||||
|
namespace Navigator {
|
||||||
|
|
||||||
|
PhysicsEventBuilder* PhysicsEventBuilder::s_instance = nullptr;
|
||||||
|
|
||||||
|
PhysicsEventBuilder::PhysicsEventBuilder() :
|
||||||
|
m_runFlag(false)
|
||||||
|
{
|
||||||
|
if(s_instance != nullptr)
|
||||||
|
{
|
||||||
|
NAV_ERROR("Trying to create a second PhysicsEventBuilder, this is not allowed!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
s_instance = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
PhysicsEventBuilder::~PhysicsEventBuilder() {}
|
||||||
|
|
||||||
|
void PhysicsEventBuilder::AttachDataSource()
|
||||||
|
{
|
||||||
|
m_runFlag = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PhysicsEventBuilder::DetachDataSource()
|
||||||
|
{
|
||||||
|
m_runFlag = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PhysicsEventBuilder::PushLayer(Layer* layer)
|
||||||
|
{
|
||||||
|
m_physStack.PushLayer(layer);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PhysicsEventBuilder::PushOverlay(Layer* layer)
|
||||||
|
{
|
||||||
|
m_physStack.PushOverlay(layer);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PhysicsEventBuilder::Run()
|
||||||
|
{
|
||||||
|
if(!m_runFlag)
|
||||||
|
NAV_WARN("Trying to Run PhysicsEventBuilder without a Data Source, nothing will happen!");
|
||||||
|
|
||||||
|
//temp
|
||||||
|
CompassHit hit;
|
||||||
|
m_rawSort.SetCoincidenceWindow(2);
|
||||||
|
while(m_runFlag)
|
||||||
|
{
|
||||||
|
//NAV_INFO("Doing a physics");
|
||||||
|
hit.timestamp++;
|
||||||
|
if(m_rawSort.IsHitInWindow(hit))
|
||||||
|
{
|
||||||
|
NAV_INFO("Adding hit to event...");
|
||||||
|
m_rawSort.AddHit(hit);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NAV_INFO("Obtaining built event...");
|
||||||
|
auto event = m_rawSort.GetRawPhysicsEvent();
|
||||||
|
NAV_INFO("Built event size: {0}", event.size());
|
||||||
|
m_rawSort.ClearRawPhysicsEvent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
43
Navigator/src/Navigator/Physics/PhysicsEventBuilder.h
Normal file
43
Navigator/src/Navigator/Physics/PhysicsEventBuilder.h
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
#ifndef PHYSICS_EVENT_BUILDER_H
|
||||||
|
#define PHYSICS_EVENT_BUILDER_H
|
||||||
|
|
||||||
|
#include "Navigator/NavCore.h"
|
||||||
|
#include "Navigator/LayerStack.h"
|
||||||
|
#include "Navigator/Layer.h"
|
||||||
|
#include "PhysicsHitSort.h"
|
||||||
|
#include <mutex>
|
||||||
|
#include <atomic>
|
||||||
|
|
||||||
|
namespace Navigator {
|
||||||
|
|
||||||
|
class PhysicsEventBuilder
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
PhysicsEventBuilder();
|
||||||
|
virtual ~PhysicsEventBuilder();
|
||||||
|
|
||||||
|
void Run();
|
||||||
|
|
||||||
|
void AttachDataSource();
|
||||||
|
void DetachDataSource();
|
||||||
|
|
||||||
|
void SetCoincidenceWindow(uint64_t window) { m_rawSort.SetCoincidenceWindow(window); }
|
||||||
|
void PushLayer(Layer* layer);
|
||||||
|
void PushOverlay(Layer* layer);
|
||||||
|
bool IsRunning() { return m_runFlag; }
|
||||||
|
|
||||||
|
inline static PhysicsEventBuilder& Get() { return *s_instance; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
LayerStack m_physStack;
|
||||||
|
std::atomic<bool> m_runFlag; //ensures defined read/write across threads
|
||||||
|
static PhysicsEventBuilder* s_instance;
|
||||||
|
PhysicsHitSort m_rawSort;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
PhysicsEventBuilder* CreatePhysicsEventBuilder();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
31
Navigator/src/Navigator/Physics/PhysicsHitSort.cpp
Normal file
31
Navigator/src/Navigator/Physics/PhysicsHitSort.cpp
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
#include "PhysicsHitSort.h"
|
||||||
|
|
||||||
|
namespace Navigator {
|
||||||
|
|
||||||
|
PhysicsHitSort::PhysicsHitSort(uint64_t window) :
|
||||||
|
m_coincidenceWindow(window), m_startTime(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
PhysicsHitSort::~PhysicsHitSort() {}
|
||||||
|
|
||||||
|
|
||||||
|
bool PhysicsHitSort::IsHitInWindow(const CompassHit& hit)
|
||||||
|
{
|
||||||
|
if(m_startTime == 0)
|
||||||
|
return true;
|
||||||
|
else if( (hit.timestamp - m_startTime) < m_coincidenceWindow)
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PhysicsHitSort::AddHit(const CompassHit& hit)
|
||||||
|
{
|
||||||
|
if(m_event.size() == 0)
|
||||||
|
m_startTime = hit.timestamp;
|
||||||
|
|
||||||
|
m_event.emplace_back(hit);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
32
Navigator/src/Navigator/Physics/PhysicsHitSort.h
Normal file
32
Navigator/src/Navigator/Physics/PhysicsHitSort.h
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
#ifndef PHYSICS_HIT_SORT_H
|
||||||
|
#define PHYSICS_HIT_SORT_H
|
||||||
|
|
||||||
|
#include "CompassHit.h"
|
||||||
|
|
||||||
|
namespace Navigator {
|
||||||
|
|
||||||
|
class PhysicsHitSort
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
using RawPhysicsEvent = std::vector<CompassHit>;
|
||||||
|
|
||||||
|
PhysicsHitSort(uint64_t window=1500000);
|
||||||
|
~PhysicsHitSort();
|
||||||
|
|
||||||
|
bool IsHitInWindow(const CompassHit& hit);
|
||||||
|
void AddHit(const CompassHit& hit);
|
||||||
|
|
||||||
|
inline void ClearRawPhysicsEvent() { m_event.clear(); }
|
||||||
|
inline RawPhysicsEvent GetRawPhysicsEvent() { m_startTime = 0; return m_event; }
|
||||||
|
|
||||||
|
inline void SetCoincidenceWindow(uint64_t window) { m_coincidenceWindow = window; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
RawPhysicsEvent m_event;
|
||||||
|
uint64_t m_coincidenceWindow;
|
||||||
|
uint64_t m_startTime;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
2
Navigator/vendor/imgui
vendored
2
Navigator/vendor/imgui
vendored
|
@ -1 +1 @@
|
||||||
Subproject commit c274a0000f7712ff816d7429efca57eaaf8f680e
|
Subproject commit 3ddac4d367b1862687cc6bf5bccc69db07196a9c
|
10
premake5.lua
10
premake5.lua
|
@ -78,8 +78,10 @@ project "Navigator"
|
||||||
"GLU",
|
"GLU",
|
||||||
"glut",
|
"glut",
|
||||||
"X11",
|
"X11",
|
||||||
"dl",
|
"dl"
|
||||||
"pthread"
|
}
|
||||||
|
linkoptions {
|
||||||
|
"-pthread"
|
||||||
}
|
}
|
||||||
filter "system:macosx"
|
filter "system:macosx"
|
||||||
defines "NAV_APPLE"
|
defines "NAV_APPLE"
|
||||||
|
@ -89,7 +91,9 @@ project "Navigator"
|
||||||
"glut",
|
"glut",
|
||||||
"X11",
|
"X11",
|
||||||
"dl",
|
"dl",
|
||||||
"pthread"
|
}
|
||||||
|
linkoptions{
|
||||||
|
"-pthread"
|
||||||
}
|
}
|
||||||
|
|
||||||
filter "configurations:Debug"
|
filter "configurations:Debug"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user