Skip to content

Commit

Permalink
Editor: begin implementing scene view. LLVM 14 test
Browse files Browse the repository at this point in the history
  • Loading branch information
geneotech committed Jul 16, 2022
1 parent e760901 commit e9729cf
Show file tree
Hide file tree
Showing 16 changed files with 211 additions and 21 deletions.
2 changes: 1 addition & 1 deletion appveyor.yml
Expand Up @@ -20,7 +20,7 @@ install:
- set PATH=C:\projects\deps\ninja;%PATH%
- ninja --version

- appveyor DownloadFile https://github.com/llvm/llvm-project/releases/download/llvmorg-13.0.1/LLVM-13.0.1-win64.exe -FileName llvm-installer.exe
- appveyor DownloadFile https://github.com/llvm/llvm-project/releases/download/llvmorg-14.0.6/LLVM-14.0.6-win64.exe -FileName llvm-installer.exe
- START /WAIT llvm-installer.exe /S /D=C:\"Program Files\LLVM"

notifications:
Expand Down
4 changes: 2 additions & 2 deletions cmake/linux_actions/install_llvm.sh
@@ -1,4 +1,4 @@
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo add-apt-repository -y "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-13 main"
sudo add-apt-repository -y "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-14 main"
sudo apt-get -q update
sudo apt-get -y install clang-13 lld-13 libc++-13-dev libc++abi-13-dev
sudo apt-get -y install clang-14 lld-14 libc++-14-dev libc++abi-14-dev
3 changes: 1 addition & 2 deletions cmake/version_file_generator/CMakeLists.txt
Expand Up @@ -50,7 +50,7 @@ if(MSVC)
"${CMAKE_CXX_FLAGS} /Ob2 /Oi /O2 /permissive- /std:c++latest"
)
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++1z")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++20")
endif()

if (CLANG AND NOT MSVC)
Expand Down Expand Up @@ -80,7 +80,6 @@ endif()

add_executable(version_file_generator
"version_file_generator.cpp"
"../../src/augs/misc/time_utils.cpp"
)

if (MSVC)
Expand Down
1 change: 0 additions & 1 deletion cmake/version_file_generator/version_file_generator.cpp
Expand Up @@ -9,7 +9,6 @@ using namespace std::chrono;
#include "augs/window_framework/exec.h"
#include "augs/filesystem/file.h"
#include "augs/string/typesafe_sprintf.h"
#include "augs/misc/time_utils.h"
#include "augs/string/string_templates.h"

int main(int argc, char** argv) {
Expand Down
25 changes: 25 additions & 0 deletions docs/pages/todo/brainstorm_now.md
Expand Up @@ -6,6 +6,31 @@ permalink: brainstorm_now
summary: That which we are brainstorming at the moment.
---

- First let's convert the project to cosmos so we can see what's happening
- Co z oficjalnymi?
- Okej, ostatecznie nie bedziemy mieli funkcji ktora tworzy oficjalne bezposrednio w intercosmie
- Tylko jedynie wypelnia ten resource pool bezposrednio w reprezentacji ktora potrzebujesz


# Creating the viewed cosmos from the project state

- When drag and dropping on scene, we could either
- Preview the pasted entity live by refreshing the cosmos constantly
- This is cleaner and is better UX
- But less performant?
- And how do we determine the layer?
- This could be a continuous create node command that only changes the position and target layer/index
- just like widgets are continuous
- It's only first posted however once the mouse is over the scene
- and would have to be deleted if we go back
- we'll later worry about recovering the inspector state
- it wil properly show the target layer position too
- we'll need to scroll to it though
- Or just show a ghost that approximates the position


# Stuff

- One-click could select it, double-click toggle collapse?

- Eye would indeed be better on the left, to not mix it with the object icons
Expand Down
140 changes: 137 additions & 3 deletions src/application/setups/editor/editor_setup.cpp
Expand Up @@ -31,6 +31,8 @@

#include "augs/templates/history.hpp"

#include "game/cosmos/create_entity.hpp"

editor_setup::editor_setup(const augs::path_type& project_path) : paths(project_path) {
LOG("Loading editor project at: %x", project_path);
project = editor_project_readwrite::read_project_json(paths.project_json);
Expand Down Expand Up @@ -58,7 +60,7 @@ bool editor_setup::handle_input_before_imgui(
using namespace augs::event;

if (in.e.msg == message::ldoubleclick) {
double_click_happened = true;
handle_doubleclick_in_layers_gui = true;
}

if (in.e.msg == message::activate) {
Expand Down Expand Up @@ -278,8 +280,16 @@ editor_paths_changed_report editor_setup::rebuild_pathed_resources() {
file.associated_resource.set<resource_type>(moved_id, false);
}
else {
const auto it = pool.allocate(editor_pathed_resource(path_in_project, new_resource_hash, file.last_write_time));
const auto new_id = it.key;
const auto [new_id, new_resource] = pool.allocate(editor_pathed_resource(path_in_project, new_resource_hash, file.last_write_time));

if constexpr(std::is_same_v<editor_sprite_resource, resource_type>) {
try {
new_resource.editable.size = augs::image::get_size(full_path);
}
catch (...) {
new_resource.editable.size.set(32, 32);
}
}

file.associated_resource.set<resource_type>(new_id, false);
}
Expand Down Expand Up @@ -518,6 +528,130 @@ std::string editor_setup::get_name(inspected_variant v) const {
return std::visit(get_object_name, v);
}

void editor_setup::rebuild_scene() {
scene.clear();

const auto mutable_access = cosmos_common_significant_access();

/* Create resources */

auto resource_pool_handler = [&]<typename P>(const P& pool, const bool is_official) {
using resource_type = typename P::value_type;

auto& viewables = scene.viewables;

for (const auto& resource : pool) {
if constexpr(std::is_same_v<editor_sprite_resource, resource_type>) {
auto create_in = [&]<typename entity_type>(entity_type) {
auto& flavour_pool = scene.world.get_flavours<static_decoration>(mutable_access);
auto& definitions = viewables.image_definitions;

const auto [new_image_id, new_definition] = definitions.allocate();

{
new_definition.source_image.path = resource.external_file.path_in_project;
new_definition.source_image.is_official = is_official;

auto& meta = new_definition.meta;
(void)meta;
}

const auto [new_raw_flavour_id, new_flavour] = flavour_pool.allocate();
const auto new_flavour_id = typed_entity_flavour_id<entity_type>(new_raw_flavour_id);

const auto& editable = resource.editable;

{
auto& render = new_flavour.template get<invariants::render>();
render.layer = render_layer::GROUND;
}

{
auto& sprite = new_flavour.template get<invariants::sprite>();
sprite.set(new_image_id, editable.size, editable.color);
}

/* Cache for quick and easy mapping */

resource.scene_image_id = new_image_id;
resource.scene_flavour_id = new_flavour_id;
};

// for now the only supported one
create_in(static_decoration());
}
else if constexpr(std::is_same_v<editor_sound_resource, resource_type>) {

}
else if constexpr(std::is_same_v<editor_light_resource, resource_type>) {

}
else {
//static_assert(always_false_v<P>, "Non-exhaustive if constexpr");
}
}
};

project.resources .for_each([&](const auto& pool) { resource_pool_handler(pool, false); } );
official_resources.for_each([&](const auto& pool) { resource_pool_handler(pool, true); } );

/* Create nodes */

auto total_order = sorting_order_type(0);

for (const auto layer_id : reverse(project.layers.order)) {
auto layer = find_layer(layer_id);
ensure(layer != nullptr);

if (!layer->visible) {
continue;
}

auto node_handler = [&]<typename node_type>(node_type& typed_node, const auto id) {
(void)id;

if (!typed_node.visible) {
return;
}

const auto resource = find_resource(typed_node.resource_id);

if (resource == nullptr) {
return;
}

auto entity_pre_constructor = [&]<typename H>(const H&, auto& agg) {
// using entity_type = typename H::used_entity_type;

if (auto sorting_order = agg.template find<components::sorting_order>()) {
sorting_order->order = total_order;
}
};

auto entity_post_constructor = [&](auto&&...) {

};

if constexpr(std::is_same_v<editor_sprite_node, node_type>) {

cosmic::create_entity(
scene.world,
resource->scene_flavour_id,
entity_pre_constructor,
entity_post_constructor
);
}
else {
//static_assert(always_false_v<P>, "Non-exhaustive if constexpr");
}
};

for (const auto node_id : reverse(layer->hierarchy.nodes)) {
on_node(node_id, node_handler);
}
}
}

template struct edit_resource_command<editor_sprite_resource>;
template struct edit_resource_command<editor_sound_resource>;
template struct edit_resource_command<editor_light_resource>;
Expand Down
4 changes: 3 additions & 1 deletion src/application/setups/editor/editor_setup.h
Expand Up @@ -198,7 +198,9 @@ class editor_setup : public default_setup_settings {
void undo();
void redo();

bool double_click_happened = false;
bool handle_doubleclick_in_layers_gui = false;

void rebuild_scene();

/*********************************************************/
/*************** DEFAULT SETUP BOILERPLATE ***************/
Expand Down
11 changes: 6 additions & 5 deletions src/application/setups/editor/gui/editor_filesystem_gui.cpp
Expand Up @@ -22,13 +22,14 @@ void editor_filesystem_gui::perform(const editor_project_files_input in) {

}();

if (!payload_still_exists) {
const bool mouse_over_scene = !mouse_over_any_window();
if (const bool mouse_over_scene = !mouse_over_any_window()) {
LOG("Dropped %x on scene", dragged_resource->name);
}
else {

if (mouse_over_scene) {
LOG("Dropped %x on scene", dragged_resource->name);
}
}

if (!payload_still_exists) {
dragged_resource = nullptr;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/application/setups/editor/gui/editor_layers_gui.cpp
Expand Up @@ -18,8 +18,8 @@ void editor_layers_gui::perform(const editor_layers_input in) {

(void)in;

const bool has_double_click = in.setup.double_click_happened;
in.setup.double_click_happened = false;
const bool has_double_click = in.setup.handle_doubleclick_in_layers_gui;
in.setup.handle_doubleclick_in_layers_gui = false;

auto window = make_scoped_window();

Expand Down
11 changes: 11 additions & 0 deletions src/application/setups/editor/resources/editor_sprite_resource.h
Expand Up @@ -4,10 +4,13 @@

#include "augs/math/vec2.h"
#include "augs/drawing/sprite.h"
#include "game/assets/ids/asset_ids.h"
#include "game/cosmos/entity_flavour_id.h"

struct editor_sprite_resource_editable {
// GEN INTROSPECTOR struct editor_sprite_resource_editable
rgba color = white;
vec2i size = vec2i::zero;
bool tile_excess_size = false;
// END GEN INTROSPECTOR
};
Expand All @@ -18,8 +21,16 @@ struct editor_sprite_resource {

editor_pathed_resource external_file;
editor_sprite_resource_editable editable;

/* Cache */

ad_hoc_entry_id thumbnail_id = static_cast<ad_hoc_entry_id>(-1);

/* Only for quick mapping */

mutable assets::image_id scene_image_id;
mutable entity_flavour_id scene_flavour_id;

editor_sprite_resource(const editor_pathed_resource& f) : external_file(f) {}

decltype(auto) get_display_name() const {
Expand Down
4 changes: 3 additions & 1 deletion src/augs/misc/time_utils.cpp
Expand Up @@ -33,11 +33,12 @@ augs::date_time::date_time(
{
}

#if 1
#if defined(__clang__) && defined(PLATFORM_UNIX)
augs::date_time::date_time(
const augs::file_time_type& tp
) :
date_time(augs::file_time_type::clock::to_time_t(tp))
date_time(std::chrono::time_point_cast<std::chrono::system_clock::duration>(std::chrono::file_clock::to_sys(tp)))
{
}
#else
Expand All @@ -57,6 +58,7 @@ augs::date_time::date_time(
t = filetime_to_timet(ft);
}
#endif
#endif

std::string augs::date_time::format_time_point_utc(const std::chrono::system_clock::time_point& tp) {
std::ostringstream o;
Expand Down
2 changes: 2 additions & 0 deletions src/game/cosmos/cosmos_common_significant_access.h
Expand Up @@ -36,5 +36,7 @@ class cosmos_common_significant_access {
template <class id_type>
friend struct duplicate_asset_command;

friend class editor_setup;

cosmos_common_significant_access() {}
};
18 changes: 18 additions & 0 deletions src/game/cosmos/entity_solvable.h
Expand Up @@ -52,6 +52,24 @@ struct entity_solvable : entity_solvable_meta {
return std::get<C>(component_state);
}

template <class C>
C* find() {
if constexpr(has<C>()) {
return std::addressof(std::get<C>(component_state));
}

return nullptr;
}

template <class C>
const C* find() const {
if constexpr(has<C>()) {
return std::addressof(std::get<C>(component_state));
}

return nullptr;
}

template <class F>
void for_each(F&& callback) {
for_each_through_std_get(component_state, std::forward<F>(callback));
Expand Down
1 change: 0 additions & 1 deletion src/test_scenes/ingredients/guns.cpp
@@ -1,4 +1,3 @@
#include "test_scenes/create_test_scene_entity.h"
#include "game/cosmos/cosmos.h"
#include "game/components/gun_component.h"
#include "game/components/item_component.h"
Expand Down
1 change: 0 additions & 1 deletion src/view/viewables/image_definition.h
Expand Up @@ -9,7 +9,6 @@

#include "view/viewables/image_meta.h"

#include "view/asset_location_context.h"
#include "view/viewables/regeneration/neon_maps.h"
#include "view/maybe_official_path_types.h"
#include "view/viewables/asset_definition_view.h"
Expand Down
1 change: 0 additions & 1 deletion src/view/viewables/streaming/viewables_streaming.h
Expand Up @@ -8,7 +8,6 @@
#include "augs/graphics/renderer.h"
#include "view/viewables/streaming/viewables_streaming_profiler.h"
#include "view/viewables/all_viewables_defs.h"
#include "view/viewables/image_cache.h"
#include "view/viewables/loaded_sounds_map.h"

#include "view/viewables/atlas_distributions.h"
Expand Down

0 comments on commit e9729cf

Please sign in to comment.