-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Drag Selection #1603
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
Drag Selection #1603
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
7b74280
renderer: HUD renderer.
heinezen a64c2c9
refactor: Solve weird tab/space mixup.
heinezen 449df59
input: Change entity creation to 'CTRL+LMB'.
heinezen 542ff6b
input: Rename engine controller to game controller.
heinezen ad992b4
input: Event bindings for drag selection box.
heinezen 3e16e5d
gamestate: Drag selection as event.
heinezen 20f8709
input: HUD controller.
heinezen c8657df
assets: Shader for drag select rectangle.
heinezen d2f8538
input: Select with viewport transformation.
heinezen 05b1fba
gamestate: Add 'Selectable' component.
heinezen a532255
gamestate: Assign 'Selectable' component when configured in nyan.
heinezen 16ef5e7
gamestate: Check if an entity is selectable when drag selecting.
heinezen 4247e3c
gamestate: Remove auto-selection on spawning.
heinezen 522bd56
input: Separate method for resetting drag select.
heinezen b6d33a5
renderer: Add drag select in HUD renderer.
heinezen f834b05
presenter: Add HUD renderer.
heinezen 6acc008
input: Default actions for HUD controller.
heinezen 248dba6
input: Allow multiple input actions per event.
heinezen 664475f
input: Forward actions to HuD controller.
heinezen 386eb8c
renderer: Fix drag selection rectable vertices.
heinezen 016d874
renderer: Add missing docstrings.
heinezen f7ce033
renderer: Rename high-level renderers to 'render stage'.
heinezen 7b027b0
renderer: Refactor filenames for render stages.
heinezen 4ad0fb9
input: Reactivate camera actions.
heinezen b408178
doc: Add HudRenderer description to renderer docs.
heinezen 136471d
renderer: Make sure that alpha is 1 for blend results.
heinezen 4ff5e6d
gamestate: Suppress less useful drag select log messages.
heinezen a51d2c3
input: Fix missing std::move.
heinezen 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| #version 330 | ||
|
|
||
| // Color of the drag rectangle | ||
| uniform vec4 in_col; | ||
|
|
||
| layout(location=0) out vec4 out_col; | ||
|
|
||
| void main() { | ||
| out_col = in_col; | ||
| } | ||
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,7 @@ | ||
| #version 330 | ||
|
|
||
| layout(location=0) in vec2 position; | ||
|
|
||
| void main() { | ||
| gl_Position = vec4(position, 0.0, 1.0); | ||
| } |
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 |
|---|---|---|
|
|
@@ -2,5 +2,6 @@ add_sources(libopenage | |
| idle.cpp | ||
| live.cpp | ||
| move.cpp | ||
| selectable.cpp | ||
| turn.cpp | ||
| ) | ||
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,12 @@ | ||
| // Copyright 2023-2023 the openage authors. See copying.md for legal info. | ||
|
|
||
| #include "selectable.h" | ||
|
|
||
|
|
||
| namespace openage::gamestate::component { | ||
|
|
||
| component_t Selectable::get_type() const { | ||
| return component_t::SELECTABLE; | ||
| } | ||
|
|
||
| } // namespace openage::gamestate::component |
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,20 @@ | ||
| // Copyright 2023-2023 the openage authors. See copying.md for legal info. | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <nyan/nyan.h> | ||
|
|
||
| #include "gamestate/component/api_component.h" | ||
| #include "gamestate/component/types.h" | ||
|
|
||
|
|
||
| namespace openage::gamestate::component { | ||
|
|
||
| class Selectable : public APIComponent { | ||
| public: | ||
| using APIComponent::APIComponent; | ||
|
|
||
| component_t get_type() const override; | ||
| }; | ||
|
|
||
| } // namespace openage::gamestate::component |
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 |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ enum class component_t { | |
| IDLE, | ||
| TURN, | ||
| MOVE, | ||
| SELECTABLE, | ||
| LIVE | ||
| }; | ||
|
|
||
|
|
||
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 |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| add_sources(libopenage | ||
| drag_select.cpp | ||
| process_command.cpp | ||
| send_command.cpp | ||
| spawn_entity.cpp | ||
|
|
||
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,100 @@ | ||
| // Copyright 2023-2023 the openage authors. See copying.md for legal info. | ||
|
|
||
| #include "drag_select.h" | ||
|
|
||
| #include <eigen3/Eigen/Dense> | ||
|
|
||
| #include "coord/phys.h" | ||
| #include "coord/pixel.h" | ||
| #include "coord/scene.h" | ||
| #include "curve/discrete.h" | ||
| #include "gamestate/component/internal/ownership.h" | ||
| #include "gamestate/component/internal/position.h" | ||
| #include "gamestate/game_entity.h" | ||
| #include "gamestate/game_state.h" | ||
| #include "gamestate/types.h" | ||
|
|
||
|
|
||
| namespace openage::gamestate::event { | ||
|
|
||
| DragSelectHandler::DragSelectHandler() : | ||
| OnceEventHandler{"game.drag_select"} {} | ||
|
|
||
| void DragSelectHandler::setup_event(const std::shared_ptr<openage::event::Event> & /* event */, | ||
| const std::shared_ptr<openage::event::State> & /* state */) { | ||
| // TODO | ||
| } | ||
|
|
||
| void DragSelectHandler::invoke(openage::event::EventLoop & /* loop */, | ||
| const std::shared_ptr<openage::event::EventEntity> & /* target */, | ||
| const std::shared_ptr<openage::event::State> &state, | ||
| const time::time_t &time, | ||
| const param_map ¶ms) { | ||
| auto gstate = std::dynamic_pointer_cast<openage::gamestate::GameState>(state); | ||
|
|
||
| size_t controlled_id = params.get("controlled", 0); | ||
|
|
||
| Eigen::Matrix4f id_matrix = Eigen::Matrix4f::Identity(); | ||
| Eigen::Matrix4f cam_matrix = params.get("camera_matrix", id_matrix); | ||
| Eigen::Vector2f drag_start = params.get("drag_start", Eigen::Vector2f{0, 0}); | ||
| Eigen::Vector2f drag_end = params.get("drag_end", Eigen::Vector2f{0, 0}); | ||
|
|
||
| // Boundaries of the rectangle | ||
| float top = std::max(drag_start.y(), drag_end.y()); | ||
| float bottom = std::min(drag_start.y(), drag_end.y()); | ||
| float left = std::min(drag_start.x(), drag_end.x()); | ||
| float right = std::max(drag_start.x(), drag_end.x()); | ||
|
|
||
| log::log(SPAM << "Drag select rectangle (NDC):"); | ||
| log::log(SPAM << "\tTop: " << top); | ||
| log::log(SPAM << "\tBottom: " << bottom); | ||
| log::log(SPAM << "\tLeft: " << left); | ||
| log::log(SPAM << "\tRight: " << right); | ||
|
|
||
| std::vector<entity_id_t> selected; | ||
| for (auto &entity : gstate->get_game_entities()) { | ||
heinezen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (not entity.second->has_component(component::component_t::SELECTABLE)) { | ||
| // skip entities that are not selectable | ||
| continue; | ||
| } | ||
|
|
||
| // Check if the entity is owned by the controlled player | ||
| // TODO: Check this using Selectable diplomatic property | ||
| auto owner = std::dynamic_pointer_cast<component::Ownership>( | ||
| entity.second->get_component(component::component_t::OWNERSHIP)); | ||
| if (owner->get_owners().get(time) != controlled_id) { | ||
| // only select entities of the controlled player | ||
| continue; | ||
| } | ||
|
|
||
| // Get the position of the entity in the viewport | ||
| auto pos = std::dynamic_pointer_cast<component::Position>( | ||
| entity.second->get_component(component::component_t::POSITION)); | ||
| auto current_pos = pos->get_positions().get(time); | ||
| auto world_pos = current_pos.to_scene3().to_world_space(); | ||
| Eigen::Vector4f clip_pos = cam_matrix * Eigen::Vector4f{world_pos.x(), world_pos.y(), world_pos.z(), 1}; | ||
TheJJ marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // Check if the entity is in the rectangle | ||
| if (clip_pos.x() > left | ||
| and clip_pos.x() < right | ||
| and clip_pos.y() > bottom | ||
| and clip_pos.y() < top) { | ||
| selected.push_back(entity.first); | ||
| } | ||
| } | ||
|
|
||
| // Select the units | ||
| auto select_cb = params.get("select_cb", | ||
| std::function<void(const std::vector<entity_id_t> ids)>{ | ||
| [](const std::vector<entity_id_t> /* ids */) {}}); | ||
| select_cb(selected); | ||
| } | ||
|
|
||
| time::time_t DragSelectHandler::predict_invoke_time(const std::shared_ptr<openage::event::EventEntity> & /* target */, | ||
| const std::shared_ptr<openage::event::State> & /* state */, | ||
| const time::time_t &at) { | ||
| return at; | ||
| } | ||
|
|
||
|
|
||
| } // namespace openage::gamestate::event | ||
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,46 @@ | ||
| // Copyright 2023-2023 the openage authors. See copying.md for legal info. | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <cstddef> | ||
| #include <memory> | ||
| #include <string> | ||
|
|
||
| #include "event/evententity.h" | ||
| #include "event/eventhandler.h" | ||
|
|
||
|
|
||
| namespace openage { | ||
|
|
||
| namespace event { | ||
| class EventLoop; | ||
| class Event; | ||
| class State; | ||
| } // namespace event | ||
|
|
||
| namespace gamestate::event { | ||
|
|
||
| /** | ||
| * Drag select game entities. | ||
| */ | ||
| class DragSelectHandler : public openage::event::OnceEventHandler { | ||
heinezen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| public: | ||
| DragSelectHandler(); | ||
| ~DragSelectHandler() = default; | ||
|
|
||
| void setup_event(const std::shared_ptr<openage::event::Event> &event, | ||
| const std::shared_ptr<openage::event::State> &state) override; | ||
|
|
||
| void invoke(openage::event::EventLoop &loop, | ||
| const std::shared_ptr<openage::event::EventEntity> &target, | ||
| const std::shared_ptr<openage::event::State> &state, | ||
| const time::time_t &time, | ||
| const param_map ¶ms) override; | ||
|
|
||
| time::time_t predict_invoke_time(const std::shared_ptr<openage::event::EventEntity> &target, | ||
| const std::shared_ptr<openage::event::State> &state, | ||
| const time::time_t &at) override; | ||
| }; | ||
|
|
||
| } // namespace gamestate::event | ||
| } // namespace openage | ||
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
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 |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| add_subdirectory("camera") | ||
| add_subdirectory("game") | ||
| add_subdirectory("hud") |
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 |
|---|---|---|
|
|
@@ -4,4 +4,4 @@ | |
|
|
||
| namespace openage::input::game { | ||
|
|
||
| } // namespace openage::input::engine | ||
| } // namespace openage::input::game | ||
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
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.