Skip to content
This repository has been archived by the owner on Sep 14, 2019. It is now read-only.

Commit

Permalink
Merge pull request #99 from Milerius/dev
Browse files Browse the repository at this point in the history
add animation system
  • Loading branch information
Milerius authored Aug 5, 2018
2 parents 821ce2d + b5ab7e6 commit b3945b2
Show file tree
Hide file tree
Showing 21 changed files with 481 additions and 68 deletions.
Binary file added bin/assets/textures/game_scene/bheet_arrival.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions cmake/shiva-sfml-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ find_package(shiva CONFIG REQUIRED)
include("${CMAKE_CURRENT_LIST_DIR}/shiva-shiva-system-sfml-resources-targets.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/shiva-shiva-system-sfml-graphics-targets.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/shiva-shiva-system-sfml-inputs-targets.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/shiva-sfml-common-targets.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/shiva-shiva-system-sfml-animation-targets.cmake")

macro(import_plugins plugin_name)
if(CMAKE_BUILD_TYPE MATCHES Debug)
Expand Down Expand Up @@ -35,4 +37,6 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${SAVE_OUTPUT_DIRECTORY}")
check_required_components("shiva-system-sfml-resources")
check_required_components("shiva-system-sfml-graphics")
check_required_components("shiva-system-sfml-input")
check_required_components("sfml-common")
check_required_components("shiva-system-sfml-animation")

4 changes: 2 additions & 2 deletions examples/sfml/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
if (SHIVA_USE_SFML_AS_RENDERER)
add_executable(sfml-example sfml-example.cpp sfml-example.hpp)
add_dependencies(sfml-example shiva::shiva-system-sfml-graphics shiva::shiva-system-sfml-inputs shiva::shiva-system-sfml-resources)
add_dependencies(sfml-example shiva::shiva-system-sfml-graphics shiva::shiva-system-sfml-inputs shiva::shiva-system-sfml-resources shiva::shiva-system-sfml-animation)
target_link_libraries(sfml-example shiva::shiva)
set_target_properties(sfml-example
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/bin"
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/bin"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/bin"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/bin"
LIBRARY_OUTPUT_DIRECTORY_DEBUG "${CMAKE_SOURCE_DIR}/bin"
Expand Down
13 changes: 10 additions & 3 deletions examples/sfml/game_scene.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,16 @@ function leave()
end

function on_after_load_resources(evt)
local id, sprite = shiva.entity_registry:create_game_object_with_sprite()
sprite:set_texture(shiva.resource_registry:get_texture("game_scene/toto"), false)
entities[#entities + 1] = id
--local id, sprite = shiva.entity_registry:create_game_object_with_sprite()
--sprite:set_texture(shiva.resource_registry:get_texture("game_scene/toto"), false)
--entities[#entities + 1] = id
--shiva.entity_registry:add_layer_1_component(id)

--local id = shiva.anim:create_game_object_with_animated_sprite(anim_status.playing,
-- 0.12, true, 1, 1, 1, 9, "game_scene/mage_idle_dir_1")

local id = shiva.anim:create_game_object_with_animated_sprite(anim_status.playing,
0.09, true, 1, 12, 7, 80, "game_scene/bheet_arrival")
shiva.entity_registry:add_layer_1_component(id)
end

Expand Down
2 changes: 2 additions & 0 deletions examples/sfml/sfml-example.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ namespace shiva::examples::sfml
auto render_system = system_manager_.get_system_by_name("render_system", shiva::ecs::system_type::post_update);
auto input_system = system_manager_.get_system_by_name("input_system", shiva::ecs::system_type::pre_update);
auto resources_system = system_manager_.get_system_by_name("resources_system", shiva::ecs::system_type::pre_update);
auto animation_system = system_manager_.get_system_by_name("animation_system", shiva::ecs::system_type::logic_update);
resources_system->set_user_data(&lua_system.get_state());
animation_system->set_user_data(&lua_system.get_state());
input_system->set_user_data(render_system->get_user_data());
lua_system.load_all_scripted_systems();
}
Expand Down
4 changes: 3 additions & 1 deletion modules/ecs/shiva/ecs/components/all.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <shiva/meta/list.hpp>
#include <shiva/ecs/components/layer.hpp>
#include <shiva/ecs/components/drawable.hpp>
#include <shiva/ecs/components/animation.hpp>

namespace shiva::ecs
{
Expand All @@ -18,5 +19,6 @@ namespace shiva::ecs
layer_6,
layer_7,
layer_8,
drawable>;
drawable,
animation>;
}
33 changes: 33 additions & 0 deletions modules/ecs/shiva/ecs/components/animation.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// Created by roman Sztergbaum on 05/08/2018.
//

#pragma once

#include <memory>
#include <shiva/reflection/reflection.hpp>

namespace shiva::ecs
{
struct animation
{
template <typename Animation>
animation(Animation ptr) noexcept : animation_(ptr)
{
}

reflect_class(animation)

static constexpr auto reflected_functions() noexcept
{
return meta::makeMap();
}

static constexpr auto reflected_members() noexcept
{
return meta::makeMap();
}

std::shared_ptr<void> animation_{nullptr};
};
}
1 change: 1 addition & 0 deletions modules/lua/CMakeSources.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ set(MODULE_PUBLIC_HEADERS
"${MODULE_PATH}/lua.hpp"
"${MODULE_PATH}/lua_system.hpp"
"${MODULE_PATH}/lua_scripted_system.hpp"
"${MODULE_PATH}/lua_helpers.hpp"
)

set(MODULE_PRIVATE_HEADERS
Expand Down
39 changes: 39 additions & 0 deletions modules/lua/shiva/lua/lua_helpers.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// Created by roman Sztergbaum on 05/08/2018.
//

#pragma once

#include <array>
#if defined(fmt)
#undef fmt
#include <sol/state.hpp>
#else
#include <sol/state.hpp>
#endif
#include <shiva/spdlog/spdlog.hpp>

namespace shiva::lua
{
template <typename T>
void register_type(sol::state& state, shiva::logging::logger logger) noexcept
{
const auto table = std::tuple_cat(
std::make_tuple(T::class_name()),
T::reflected_functions(),
T::reflected_members());

try {
std::apply(
[&state](auto &&...params) {
state.new_usertype<T>(std::forward<decltype(params)>(params)...);
}, table);
}
catch (const std::exception &error) {
logger->error("error: {}", error.what());
return;
}

logger->info("successfully registering type: {}", T::class_name());
}
}
31 changes: 5 additions & 26 deletions modules/lua/shiva/lua/lua_system.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <shiva/ecs/system.hpp>
#include <shiva/event/add_base_system.hpp>
#include <shiva/input/input.hpp>
#include <shiva/lua/lua_helpers.hpp>
#include "lua_scripted_system.hpp"

namespace sol
Expand Down Expand Up @@ -123,31 +124,9 @@ namespace shiva::scripting
disable();
}

template <typename T>
void register_type() noexcept
{
const auto table = std::tuple_cat(
std::make_tuple(T::class_name()),
T::reflected_functions(),
T::reflected_members());

try {
std::apply(
[this](auto &&...params) {
this->state_->new_usertype<T>(std::forward<decltype(params)>(params)...);
}, table);
}
catch (const std::exception &error) {
log_->error("error: {}", error.what());
return;
}

log_->info("successfully registering type: {}", T::class_name());
}

void register_entity_registry() noexcept
{
register_type<shiva::entt::entity_registry>();
shiva::lua::register_type<shiva::entt::entity_registry>(*state_, log_);
using comp_type = shiva::entt::entity_registry::component_type;
(*state_)[entity_registry_.class_name()]["for_each_runtime"] = [](shiva::entt::entity_registry &self,
std::vector<comp_type> array,
Expand Down Expand Up @@ -190,20 +169,20 @@ namespace shiva::scripting
template <typename ...Types>
void register_types_list(meta::type_list<Types...>) noexcept
{
(register_type<Types>(), ...);
(shiva::lua::register_type<Types>(*state_, log_), ...);
}

template <typename ... Types>
void register_components(meta::type_list<Types...>)
{
(register_type<Types>(), ...);
(shiva::lua::register_type<Types>(*state_, log_), ...);
(register_component<Types>(), ...);
}

template<typename ... Types>
void register_events(meta::type_list<Types...>)
{
(register_type<Types>(), ...);
(shiva::lua::register_type<Types>(*state_, log_), ...);
(register_event<Types>(), ...);
}

Expand Down
7 changes: 7 additions & 0 deletions modules/sfml/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@ endmacro()

if (SHIVA_USE_SFML_AS_RENDERER)
find_package(SFML CONFIG REQUIRED system window graphics audio)

include(shiva/sfml/common/CMakeSources.cmake)
CREATE_MODULE(shiva::sfml-common "${MODULE_SOURCES}" ${MODULE_PATH})
target_link_libraries(sfml-common INTERFACE sfml-graphics)
AUTO_TARGETS_PLUGINS_INSTALL(sfml-common shiva-sfml)

mini_module(resources "sfml-graphics;sfml-audio;shiva::lua")
mini_module(animation "sfml-graphics;sfml-common;shiva::lua")
mini_module(graphics sfml-graphics)
mini_module(inputs sfml-graphics)
PREPARE_MODULE_INSTALLATION(shiva-sfml)
Expand Down
19 changes: 19 additions & 0 deletions modules/sfml/shiva/sfml/animation/CMakeSources.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
set(MODULE_PATH
${CMAKE_CURRENT_SOURCE_DIR}/shiva/sfml/animation)


set(MODULE_PUBLIC_SOURCES
"${MODULE_PATH}/system-sfml-animation.cpp"
)

set(MODULE_PUBLIC_HEADERS
"${MODULE_PATH}/system-sfml-animation.hpp"
)

set(MODULE_PRIVATE_HEADERS
"")

set(MODULE_SOURCES
${MODULE_PUBLIC_SOURCES}
${MODULE_PUBLIC_HEADERS}
${MODULE_PRIVATE_HEADERS})
Loading

0 comments on commit b3945b2

Please sign in to comment.