-
Notifications
You must be signed in to change notification settings - Fork 0
feat: parser implementation and structure refactor #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
c6f082f
feat: parser implementation and scene structure
WojtussToKox ce21d4b
feat: add lsl and sdl dependencies
MichalSzandar 4041748
feat: parser implementation and scene structure
WojtussToKox 27ffe0a
fix: comment code that uses classes that do not exist yet
MichalSzandar 99f07da
refactor: reorganize project structure and standarized code
WojtussToKox 666fc82
fix: format code
MichalSzandar 3040e93
fix: install protobuf on CI
MichalSzandar e99be07
refactor: replace switch case in Parser::buildComponent with Componen…
MichalSzandar 3602b3c
fix: format code
MichalSzandar 7efae6b
refactor: move SceneObject functions implementation to seperate .cpp …
MichalSzandar fea6138
fix: format code
MichalSzandar 706a9f4
refactor: throw error if component creator function has already been …
MichalSzandar b14e23b
feat: create macro for registering components
MichalSzandar 5254dc2
fix: format code
MichalSzandar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| #ifndef PARSER_HPP | ||
| #define PARSER_HPP | ||
|
|
||
| #include <iostream> | ||
| #include <memory> | ||
| #include <string> | ||
|
|
||
| class Scene; | ||
| class SceneObject; | ||
| class Component; | ||
|
|
||
| namespace NeuronIDE { | ||
| class SceneObject; | ||
| class Component; | ||
| } // namespace NeuronIDE | ||
|
|
||
| class Parser { | ||
| public: | ||
| Parser() = default; | ||
|
|
||
| std::shared_ptr<Scene> parse(const std::string& filePath); | ||
|
|
||
| private: | ||
| static std::shared_ptr<SceneObject> buildSceneObject(const NeuronIDE::SceneObject& protoObj); | ||
| static std::unique_ptr<Component> buildComponent(const NeuronIDE::Component& protoComp); | ||
| }; | ||
|
|
||
| #endif // PARSER_HPP |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| #ifndef SCENE_HPP | ||
| #define SCENE_HPP | ||
|
|
||
| #include <memory> | ||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| class SceneObject; | ||
|
|
||
| class Scene { | ||
| private: | ||
| std::string experimentName; | ||
| std::vector<std::shared_ptr<SceneObject>> objects; | ||
|
|
||
| public: | ||
| void setExperimentName(const std::string& name) { experimentName = name; } | ||
|
|
||
| void addObject(std::shared_ptr<SceneObject> obj) { objects.push_back(std::move(obj)); } | ||
|
|
||
| const std::string& getExperimentName() const { return experimentName; } | ||
| const std::vector<std::shared_ptr<SceneObject>>& getObjects() const { return objects; } | ||
| }; | ||
|
|
||
| #endif // SCENE_HPP |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| #ifndef SCENEOBJECT_HPP | ||
| #define SCENEOBJECT_HPP | ||
|
|
||
| #include <iostream> | ||
| #include <memory> | ||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| class Component; | ||
|
|
||
| class SceneObject { | ||
| public: | ||
| std::string name; | ||
| bool isVisible = true; | ||
|
|
||
| struct Transform { | ||
| double posX = 0, posY = 0, width = 0, height = 0, rotation = 0; | ||
| } transform; | ||
|
|
||
| std::vector<std::unique_ptr<Component>> components; | ||
|
|
||
| SceneObject(std::string n, bool visible = true); | ||
|
|
||
| void setTransform(Transform t); | ||
|
|
||
| void addComponent(std::unique_ptr<Component> comp); | ||
| }; | ||
|
|
||
| #endif // SCENEOBJECT_HPP |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| #ifndef BLINKCOMPONENT_HPP | ||
| #define BLINKCOMPONENT_HPP | ||
|
|
||
| #include <iostream> | ||
| #include <memory> | ||
|
|
||
| #include "Component.hpp" | ||
|
|
||
| namespace NeuronIDE { | ||
| class Component; | ||
| } | ||
|
|
||
| class BlinkComponent : public Component { | ||
| public: | ||
| BlinkComponent(double freq) : blinkFrequencyHz(freq) { | ||
| std::cout << " + [BlinkComponent] Utworzono z czestotliwoscia: " << blinkFrequencyHz | ||
| << "Hz\n"; | ||
| } | ||
| void setFrequency(double freq); | ||
|
|
||
| static std::unique_ptr<Component> createBlinker(const NeuronIDE::Component& protoComp); | ||
|
|
||
| private: | ||
| double blinkFrequencyHz = 0.0; | ||
| }; | ||
|
|
||
| #endif // BLINKCOMPONENT_HPP |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| #ifndef COMPONENT_HPP | ||
| #define COMPONENT_HPP | ||
|
|
||
| class Component { | ||
| public: | ||
| Component() = default; | ||
| virtual ~Component() = default; | ||
|
|
||
| Component(const Component&) = default; | ||
| Component(Component&&) = default; | ||
| Component& operator=(const Component&) = default; | ||
| Component& operator=(Component&&) = default; | ||
| }; | ||
|
|
||
| #endif // COMPONENT_HPP |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| #ifndef COMPONENTREGISTRY_HPP | ||
| #define COMPONENTREGISTRY_HPP | ||
|
|
||
| #include <functional> | ||
| #include <memory> | ||
| #include <unordered_map> | ||
|
|
||
| class Component; | ||
| namespace NeuronIDE { | ||
| class Component; | ||
| } | ||
|
|
||
| using ComponentCreatorFunc = std::function<std::unique_ptr<Component>(const NeuronIDE::Component&)>; | ||
|
|
||
| class ComponentRegistry { | ||
| public: | ||
| ComponentRegistry(const ComponentRegistry&) = delete; | ||
| ComponentRegistry& operator=(const ComponentRegistry&) = delete; | ||
|
|
||
| ComponentRegistry(ComponentRegistry&&) = delete; | ||
| ComponentRegistry& operator=(ComponentRegistry&&) = delete; | ||
|
|
||
| static ComponentRegistry& instance() { | ||
| static ComponentRegistry instance; | ||
| return instance; | ||
| } | ||
|
|
||
| void registerCreator(int typeId, ComponentCreatorFunc creator); | ||
|
|
||
| std::unique_ptr<Component> build(const NeuronIDE::Component& protoComp); | ||
|
|
||
| private: | ||
| ComponentRegistry() = default; | ||
|
|
||
| std::unordered_map<int, ComponentCreatorFunc> creators; | ||
| }; | ||
|
|
||
| #define COMPONENT_REGISTRATION_CONCAT_IMPL(x, y) x##y | ||
| #define COMPONENT_REGISTRATION_CONCAT(x, y) COMPONENT_REGISTRATION_CONCAT_IMPL(x, y) | ||
|
|
||
| #define REGISTER_COMPONENT(typeId, creatorFunc) \ | ||
| namespace { \ | ||
| struct COMPONENT_REGISTRATION_CONCAT(ComponentRegistrar_, __LINE__) { \ | ||
| COMPONENT_REGISTRATION_CONCAT(ComponentRegistrar_, __LINE__)() { \ | ||
| ComponentRegistry::instance().registerCreator(static_cast<int>(typeId), creatorFunc); \ | ||
| } \ | ||
| }; \ | ||
| static COMPONENT_REGISTRATION_CONCAT(ComponentRegistrar_, __LINE__) \ | ||
| COMPONENT_REGISTRATION_CONCAT(global_registrar_, __LINE__); \ | ||
| } | ||
|
|
||
| #endif // COMPONENTREGISTRY_HPP |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| syntax = "proto3"; | ||
|
|
||
| package NeuronIDE; | ||
|
|
||
| message SpriteRenderer { | ||
| string texture_path = 1; | ||
| string img_path = 2; | ||
| } | ||
|
|
||
| message TextRenderer { | ||
| string text = 1; | ||
| string font_path = 2; | ||
| uint32 font_size = 3; | ||
| } | ||
|
|
||
| message BlinkComponent { | ||
| double blink_frequency_hz = 1; | ||
| } | ||
|
|
||
| message ScriptComponent { | ||
| string script_path = 1; | ||
| } | ||
|
|
||
| message Transform { | ||
| double x = 1; | ||
| double y = 2; | ||
| double width = 3; | ||
| double height = 4; | ||
| double rotation = 5; | ||
| } | ||
|
|
||
| message Component { | ||
| oneof component_type { | ||
| SpriteRenderer renderer = 1; | ||
| TextRenderer text = 2; | ||
| BlinkComponent blinker = 3; | ||
| ScriptComponent script = 4; | ||
| } | ||
| } | ||
|
|
||
| message SceneObject { | ||
| string name = 1; | ||
| bool is_visible = 2; | ||
| Transform transform = 3; | ||
| repeated Component components = 4; | ||
| } | ||
|
|
||
| message Scene { | ||
| string project_name = 1; | ||
| repeated SceneObject scene_objects = 2; | ||
| } | ||
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| project_name: "Moj Pierwszy Eksperyment" | ||
|
|
||
| scene_objects { | ||
| name: "Gracz" | ||
| is_visible: true | ||
|
|
||
| transform { | ||
| x: 100.0 | ||
| y: 200.0 | ||
| width: 64.0 | ||
| height: 64.0 | ||
| rotation: 0.0 | ||
| } | ||
|
|
||
| components { | ||
| blinker { | ||
| blink_frequency_hz: 1.5 | ||
| } | ||
| } | ||
| } | ||
|
|
||
| scene_objects { | ||
| name: "Napis Powitalny" | ||
| is_visible: true | ||
|
|
||
| transform { | ||
| x: 400.0 | ||
| y: 50.0 | ||
| width: 300.0 | ||
| height: 100.0 | ||
| rotation: 0.0 | ||
| } | ||
|
|
||
| components { | ||
| blinker { | ||
| blink_frequency_hz: 5 | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,27 @@ | ||
| add_library(runtime_core Runtime.cpp) | ||
| target_include_directories(runtime_core PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../include) | ||
| protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS ${CMAKE_CURRENT_SOURCE_DIR}/../protoFiles/neuronide.proto) | ||
|
|
||
| target_link_libraries(runtime_core PUBLIC | ||
| 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} | ||
| ) | ||
|
|
||
| target_include_directories(runtime_core SYSTEM PUBLIC | ||
| ${CMAKE_CURRENT_SOURCE_DIR}/../include | ||
| ${CMAKE_CURRENT_BINARY_DIR} | ||
| ${SDL2_INCLUDE_DIRS} | ||
| ) | ||
|
|
||
| target_link_libraries(runtime_core PUBLIC | ||
| lsl | ||
| concurrentqueue | ||
| protobuf::libprotobuf | ||
| ${SDL2_LIBRARIES} | ||
| ) | ||
| target_include_directories(runtime_core PUBLIC ${SDL2_INCLUDE_DIRS}) | ||
|
|
||
| add_executable(NeuronIDE main.cpp) | ||
| target_link_libraries(NeuronIDE PRIVATE runtime_core) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,4 @@ | ||
| #include <Runtime.hpp> | ||
| #include <iostream> | ||
|
|
||
| int main(int argc, char* argv[]) { | ||
| Runtime::start(); | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.