Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y cmake clang-format clang-tidy libsdl2-dev protobuf-compiler
sudo apt-get install -y cmake clang-format clang-tidy-20 libsdl2-dev protobuf-compiler

- name: Check Code Formatting
run: |
Expand Down
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.14)
cmake_minimum_required(VERSION 3.25)
project(NeuronIDE CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

enable_testing()
Expand Down
3 changes: 3 additions & 0 deletions cmake/Dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/refs/tags/v1.14.0.zip
SYSTEM
)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
Expand All @@ -15,6 +16,7 @@ FetchContent_Declare(
liblsl
GIT_REPOSITORY https://github.com/sccn/liblsl.git
GIT_TAG v1.16.2
SYSTEM
)
set(LSL_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(liblsl)
Expand All @@ -24,6 +26,7 @@ FetchContent_Declare(
concurrentqueue
GIT_REPOSITORY https://github.com/cameron314/concurrentqueue.git
GIT_TAG v1.0.4
SYSTEM
)
FetchContent_MakeAvailable(concurrentqueue)

Expand Down
2 changes: 1 addition & 1 deletion cmake/StaticAnalysis.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# cmake/StaticAnalysis.cmake

# --- Clang-Tidy Configuration ---
find_program(CLANG_TIDY_EXE NAMES "clang-tidy")
find_program(CLANG_TIDY_EXE NAMES "clang-tidy-20")
if(CLANG_TIDY_EXE)
message(STATUS "clang-tidy found: ${CLANG_TIDY_EXE}")
set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_EXE}")
Expand Down
12 changes: 12 additions & 0 deletions include/data_structures/Context.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef CONTEXT_HPP
#define CONTEXT_HPP

#include <string>
#include <vector>

struct Context {
double timestamp;
std::vector<std::string> markers;
};

#endif // CONTEXT_HPP
11 changes: 11 additions & 0 deletions include/data_structures/EEGData.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef EEGDATA_HPP
#define EEGDATA_HPP

#include <vector>

struct EEGData {
double timestamp;
std::vector<double> channelValues;
};

#endif // EEGDATA_HPP
11 changes: 11 additions & 0 deletions include/data_structures/Marker.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef MARKER_HPP
#define MARKER_HPP

#include <string>

struct Marker {
std::string name;
double timestamp;
};

#endif // MARKER_HPP
3 changes: 2 additions & 1 deletion include/parser/Parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ class Parser {

private:
static std::shared_ptr<SceneObject> buildSceneObject(const NeuronIDE::SceneObject& protoObj);
static std::unique_ptr<Component> buildComponent(const NeuronIDE::Component& protoComp);
static std::unique_ptr<Component> buildComponent(const NeuronIDE::Component& protoComp,
const std::shared_ptr<SceneObject>& owner);
};

#endif // PARSER_HPP
28 changes: 28 additions & 0 deletions include/renderer/Renderer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#ifndef RENDERER_HPP
#define RENDERER_HPP

#include <SDL2/SDL.h>
#include <concurrentqueue.h>

#include <memory>
#include <thread>

class Scene;
struct Marker;

class Renderer {
public:
Renderer() = default;
~Renderer() = default;

void render(const std::stop_token& stoken);

private:
std::unique_ptr<SDL_Window> window;
std::shared_ptr<SDL_Renderer> sdlRenderer;
std::weak_ptr<Scene> currentScene;
std::shared_ptr<moodycamel::ConcurrentQueue<Marker>> markerQueue;
std::jthread renderThread;
};

#endif // RENDERER_HPP
5 changes: 5 additions & 0 deletions include/scene/Scene.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <vector>

class SceneObject;
class SDL_Renderer;
struct Context;

class Scene {
private:
Expand All @@ -19,6 +21,9 @@ class Scene {

const std::string& getExperimentName() const { return experimentName; }
const std::vector<std::shared_ptr<SceneObject>>& getObjects() const { return objects; }

void update(const Context& ctx);
void render(SDL_Renderer* renderer);
};

#endif // SCENE_HPP
7 changes: 6 additions & 1 deletion include/scene/SceneObject.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <vector>

class Component;
class SDL_Renderer;
struct Context;

class SceneObject {
public:
Expand All @@ -21,9 +23,12 @@ class SceneObject {

SceneObject(std::string n, bool visible = true);

void setTransform(Transform t);
void setTransform(const Transform& transform);

void addComponent(std::unique_ptr<Component> comp);

void update(const Context& ctx);
void render(SDL_Renderer* renderer);
};

#endif // SCENEOBJECT_HPP
13 changes: 7 additions & 6 deletions include/scene/components/BlinkComponent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#define BLINKCOMPONENT_HPP

#include <iostream>
#include <memory>

#include "Component.hpp"

Expand All @@ -12,13 +11,15 @@ class Component;

class BlinkComponent : public Component {
public:
BlinkComponent(double freq) : blinkFrequencyHz(freq) {
std::cout << " + [BlinkComponent] Utworzono z czestotliwoscia: " << blinkFrequencyHz
<< "Hz\n";
}
BlinkComponent(std::shared_ptr<SceneObject> owner, double freq)
: Component(owner), blinkFrequencyHz(freq) {}
void setFrequency(double freq);

static std::unique_ptr<Component> createBlinker(const NeuronIDE::Component& protoComp);
void update(const Context& context) override;
void render(SDL_Renderer* renderer) override;

static std::unique_ptr<Component> createBlinker(const NeuronIDE::Component& protoComp,
const std::shared_ptr<SceneObject>& owner);

private:
double blinkFrequencyHz = 0.0;
Expand Down
15 changes: 14 additions & 1 deletion include/scene/components/Component.hpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
#ifndef COMPONENT_HPP
#define COMPONENT_HPP

#include <memory>

class SceneObject;
class SDL_Renderer;
struct Context;

class Component {
public:
Component() = default;
Component() = delete;
Component(std::shared_ptr<SceneObject> owner) : owner(owner) {}
virtual ~Component() = default;

Component(const Component&) = default;
Component(Component&&) = default;
Component& operator=(const Component&) = default;
Component& operator=(Component&&) = default;

virtual void update(const Context& context) = 0;
virtual void render(SDL_Renderer* renderer) = 0;

protected:
std::weak_ptr<SceneObject> owner;
};

#endif // COMPONENT_HPP
7 changes: 5 additions & 2 deletions include/scene/components/ComponentRegistry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ class Component;
namespace NeuronIDE {
class Component;
}
class SceneObject;

using ComponentCreatorFunc = std::function<std::unique_ptr<Component>(const NeuronIDE::Component&)>;
using ComponentCreatorFunc = std::function<std::unique_ptr<Component>(
const NeuronIDE::Component&, const std::shared_ptr<SceneObject>&)>;

class ComponentRegistry {
public:
Expand All @@ -27,7 +29,8 @@ class ComponentRegistry {

void registerCreator(int typeId, ComponentCreatorFunc creator);

std::unique_ptr<Component> build(const NeuronIDE::Component& protoComp);
std::unique_ptr<Component> build(const NeuronIDE::Component& protoComp,
const std::shared_ptr<SceneObject>& owner);

private:
ComponentRegistry() = default;
Expand Down
30 changes: 11 additions & 19 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,27 +1,19 @@
protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS ${CMAKE_CURRENT_SOURCE_DIR}/../protoFiles/neuronide.proto)

add_library(runtime_core OBJECT
Runtime.cpp
parser/Parser.cpp
scene/components/ComponentRegistry.cpp
scene/components/BlinkComponent.cpp
scene/SceneObject.cpp
${PROTO_SRCS}
${PROTO_HDRS}
)
add_library(neuronide_proto STATIC ${PROTO_SRCS} ${PROTO_HDRS})
set_target_properties(neuronide_proto PROPERTIES CXX_CLANG_TIDY "")
target_include_directories(neuronide_proto SYSTEM PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
target_link_libraries(neuronide_proto PUBLIC protobuf::libprotobuf)

target_include_directories(runtime_core SYSTEM PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/../include
${CMAKE_CURRENT_BINARY_DIR}
${SDL2_INCLUDE_DIRS}
)
add_subdirectory(scene)
add_subdirectory(parser)
add_subdirectory(renderer)

target_link_libraries(runtime_core PUBLIC
lsl
concurrentqueue
protobuf::libprotobuf
${SDL2_LIBRARIES}
add_library(runtime_core STATIC
Runtime.cpp
)
target_include_directories(runtime_core PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../include)
target_link_libraries(runtime_core PUBLIC scene parser renderer)

add_executable(NeuronIDE main.cpp)
target_link_libraries(NeuronIDE PRIVATE runtime_core)
7 changes: 7 additions & 0 deletions src/parser/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
add_library(parser OBJECT
Parser.cpp
)

target_include_directories(parser PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../include/parser)

target_link_libraries(parser PUBLIC scene)
7 changes: 4 additions & 3 deletions src/parser/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ std::shared_ptr<SceneObject> Parser::buildSceneObject(const NeuronIDE::SceneObje
}
seenComponentTypes.insert(typeId);

auto comp = buildComponent(protoComp);
auto comp = buildComponent(protoComp, obj);
if (comp) {
obj->addComponent(std::move(comp));
}
Expand All @@ -61,6 +61,7 @@ std::shared_ptr<SceneObject> Parser::buildSceneObject(const NeuronIDE::SceneObje
return obj;
}

std::unique_ptr<Component> Parser::buildComponent(const NeuronIDE::Component& protoComp) {
return ComponentRegistry::instance().build(protoComp);
std::unique_ptr<Component> Parser::buildComponent(const NeuronIDE::Component& protoComp,
const std::shared_ptr<SceneObject>& owner) {
return ComponentRegistry::instance().build(protoComp, owner);
}
15 changes: 15 additions & 0 deletions src/renderer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
add_library(renderer OBJECT
Renderer.cpp
)

target_include_directories(renderer PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/../../include/renderer
${SDL2_INCLUDE_DIRS}
)

target_link_libraries(renderer PUBLIC
scene
lsl
concurrentqueue
${SDL2_LIBRARIES}
)
45 changes: 45 additions & 0 deletions src/renderer/Renderer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include "renderer/Renderer.hpp"

#include "data_structures/Context.hpp"
#include "data_structures/Marker.hpp"
#include "lsl_cpp.h"
#include "scene/Scene.hpp"

void Renderer::render(const std::stop_token& stoken) {
std::vector<std::string> currentFrameMarkers;
auto lastTime = std::chrono::high_resolution_clock::now();

while (!stoken.stop_requested()) {
auto currentTime = std::chrono::high_resolution_clock::now();
double deltaTime = std::chrono::duration<double>(currentTime - lastTime).count();
lastTime = currentTime;

currentFrameMarkers.clear();
Context ctx{deltaTime, currentFrameMarkers};

SDL_Event event;
while (SDL_PollEvent(&event) == 1) {
if (event.type == SDL_QUIT) {
return;
}
}

if (auto scene = currentScene.lock()) {
scene->update(ctx);
}

SDL_RenderClear(sdlRenderer.get());

if (auto scene = currentScene.lock()) {
scene->render(sdlRenderer.get());
}

SDL_RenderPresent(sdlRenderer.get());

double exactTime = lsl::local_clock();

for (const auto& markerName : currentFrameMarkers) {
markerQueue->enqueue(Marker{markerName, exactTime});
}
}
}
Loading
Loading