Made better code formatting
This commit is contained in:
189
src/modules/.clang-format
Normal file
189
src/modules/.clang-format
Normal file
@@ -0,0 +1,189 @@
|
|||||||
|
# Commented out parameters are those with the same value as base LLVM style.
|
||||||
|
# We can uncomment them if we want to change their value, or enforce the
|
||||||
|
# chosen value in case the base style changes (last sync: Clang 13.0).
|
||||||
|
---
|
||||||
|
### General config, applies to all languages ###
|
||||||
|
BasedOnStyle: LLVM
|
||||||
|
AccessModifierOffset: -4
|
||||||
|
AlignAfterOpenBracket: DontAlign
|
||||||
|
# AlignArrayOfStructures: None
|
||||||
|
# AlignConsecutiveMacros: None
|
||||||
|
# AlignConsecutiveAssignments: None
|
||||||
|
# AlignConsecutiveBitFields: None
|
||||||
|
# AlignConsecutiveDeclarations: None
|
||||||
|
# AlignEscapedNewlines: Right
|
||||||
|
AlignOperands: DontAlign
|
||||||
|
AlignTrailingComments: false
|
||||||
|
# AllowAllArgumentsOnNextLine: true
|
||||||
|
# AllowAllConstructorInitializersOnNextLine: true
|
||||||
|
AllowAllParametersOfDeclarationOnNextLine: false
|
||||||
|
# AllowShortEnumsOnASingleLine: true
|
||||||
|
# AllowShortBlocksOnASingleLine: Never
|
||||||
|
# AllowShortCaseLabelsOnASingleLine: false
|
||||||
|
# AllowShortFunctionsOnASingleLine: All
|
||||||
|
# AllowShortLambdasOnASingleLine: All
|
||||||
|
# AllowShortIfStatementsOnASingleLine: Never
|
||||||
|
# AllowShortLoopsOnASingleLine: false
|
||||||
|
# AlwaysBreakAfterDefinitionReturnType: None
|
||||||
|
# AlwaysBreakAfterReturnType: None
|
||||||
|
# AlwaysBreakBeforeMultilineStrings: false
|
||||||
|
# AlwaysBreakTemplateDeclarations: MultiLine
|
||||||
|
# AttributeMacros:
|
||||||
|
# - __capability
|
||||||
|
# BinPackArguments: true
|
||||||
|
# BinPackParameters: true
|
||||||
|
BraceWrapping:
|
||||||
|
# AfterCaseLabel: false
|
||||||
|
AfterClass: false
|
||||||
|
AfterControlStatement: Never
|
||||||
|
AfterEnum: false
|
||||||
|
AfterFunction: true
|
||||||
|
AfterNamespace: false
|
||||||
|
# AfterObjCDeclaration: false
|
||||||
|
# AfterStruct: false
|
||||||
|
# AfterUnion: false
|
||||||
|
# AfterExternBlock: false
|
||||||
|
# BeforeCatch: false
|
||||||
|
# BeforeElse: false
|
||||||
|
# BeforeLambdaBody: false
|
||||||
|
# BeforeWhile: false
|
||||||
|
# IndentBraces: false
|
||||||
|
# SplitEmptyFunction: true
|
||||||
|
# SplitEmptyRecord: true
|
||||||
|
# SplitEmptyNamespace: true
|
||||||
|
# BreakBeforeBinaryOperators: None
|
||||||
|
# BreakBeforeConceptDeclarations: true
|
||||||
|
BreakBeforeBraces: Custom
|
||||||
|
# BreakBeforeInheritanceComma: false
|
||||||
|
# BreakInheritanceList: BeforeColon
|
||||||
|
# BreakBeforeTernaryOperators: true
|
||||||
|
# BreakConstructorInitializersBeforeComma: false
|
||||||
|
BreakConstructorInitializers: AfterColon
|
||||||
|
# BreakStringLiterals: true
|
||||||
|
ColumnLimit: 0
|
||||||
|
# CommentPragmas: '^ IWYU pragma:'
|
||||||
|
# CompactNamespaces: false
|
||||||
|
ConstructorInitializerAllOnOneLineOrOnePerLine: true
|
||||||
|
ConstructorInitializerIndentWidth: 8
|
||||||
|
ContinuationIndentWidth: 8
|
||||||
|
Cpp11BracedListStyle: false
|
||||||
|
# DeriveLineEnding: true
|
||||||
|
# DerivePointerAlignment: false
|
||||||
|
# DisableFormat: false
|
||||||
|
# EmptyLineAfterAccessModifier: Never
|
||||||
|
# EmptyLineBeforeAccessModifier: LogicalBlock
|
||||||
|
# ExperimentalAutoDetectBinPacking: false
|
||||||
|
# FixNamespaceComments: true
|
||||||
|
# ForEachMacros:
|
||||||
|
# - foreach
|
||||||
|
# - Q_FOREACH
|
||||||
|
# - BOOST_FOREACH
|
||||||
|
# IfMacros:
|
||||||
|
# - KJ_IF_MAYBE
|
||||||
|
# IncludeBlocks: Preserve
|
||||||
|
IncludeCategories:
|
||||||
|
- Regex: '".*"'
|
||||||
|
Priority: 1
|
||||||
|
- Regex: '^<.*\.h>'
|
||||||
|
Priority: 2
|
||||||
|
- Regex: '^<.*'
|
||||||
|
Priority: 3
|
||||||
|
# IncludeIsMainRegex: '(Test)?$'
|
||||||
|
# IncludeIsMainSourceRegex: ''
|
||||||
|
# IndentAccessModifiers: false
|
||||||
|
IndentCaseLabels: true
|
||||||
|
# IndentCaseBlocks: false
|
||||||
|
# IndentGotoLabels: true
|
||||||
|
# IndentPPDirectives: None
|
||||||
|
# IndentExternBlock: AfterExternBlock
|
||||||
|
# IndentRequires: false
|
||||||
|
IndentWidth: 8
|
||||||
|
# IndentWrappedFunctionNames: false
|
||||||
|
# InsertTrailingCommas: None
|
||||||
|
# JavaScriptQuotes: Leave
|
||||||
|
# JavaScriptWrapImports: true
|
||||||
|
KeepEmptyLinesAtTheStartOfBlocks: false
|
||||||
|
# LambdaBodyIndentation: Signature
|
||||||
|
# MacroBlockBegin: ''
|
||||||
|
# MacroBlockEnd: ''
|
||||||
|
# MaxEmptyLinesToKeep: 1
|
||||||
|
# NamespaceIndentation: None
|
||||||
|
# PenaltyBreakAssignment: 2
|
||||||
|
# PenaltyBreakBeforeFirstCallParameter: 19
|
||||||
|
# PenaltyBreakComment: 300
|
||||||
|
# PenaltyBreakFirstLessLess: 120
|
||||||
|
# PenaltyBreakString: 1000
|
||||||
|
# PenaltyBreakTemplateDeclaration: 10
|
||||||
|
# PenaltyExcessCharacter: 1000000
|
||||||
|
# PenaltyReturnTypeOnItsOwnLine: 60
|
||||||
|
# PenaltyIndentedWhitespace: 0
|
||||||
|
# PointerAlignment: Right
|
||||||
|
# PPIndentWidth: -1
|
||||||
|
# ReferenceAlignment: Pointer
|
||||||
|
# ReflowComments: true
|
||||||
|
# ShortNamespaceLines: 1
|
||||||
|
# SortIncludes: CaseSensitive
|
||||||
|
# SortJavaStaticImport: Before
|
||||||
|
# SortUsingDeclarations: true
|
||||||
|
# SpaceAfterCStyleCast: false
|
||||||
|
# SpaceAfterLogicalNot: false
|
||||||
|
# SpaceAfterTemplateKeyword: true
|
||||||
|
# SpaceBeforeAssignmentOperators: true
|
||||||
|
# SpaceBeforeCaseColon: false
|
||||||
|
# SpaceBeforeCpp11BracedList: false
|
||||||
|
# SpaceBeforeCtorInitializerColon: true
|
||||||
|
# SpaceBeforeInheritanceColon: true
|
||||||
|
# SpaceBeforeParens: ControlStatements
|
||||||
|
# SpaceAroundPointerQualifiers: Default
|
||||||
|
# SpaceBeforeRangeBasedForLoopColon: true
|
||||||
|
# SpaceInEmptyParentheses: false
|
||||||
|
# SpacesBeforeTrailingComments: 1
|
||||||
|
# SpaceInEmptyBlock: false
|
||||||
|
# SpaceInEmptyParentheses: false
|
||||||
|
# SpacesBeforeTrailingComments: 1
|
||||||
|
# SpacesInAngles: Never
|
||||||
|
# SpacesInContainerLiterals: true
|
||||||
|
# SpacesInConditionalStatement: false
|
||||||
|
# SpacesInContainerLiterals: true
|
||||||
|
# SpacesInCStyleCastParentheses: false
|
||||||
|
## Godot TODO: We'll want to use a min of 1, but we need to see how to fix
|
||||||
|
## our comment capitalization at the same time.
|
||||||
|
SpacesInLineCommentPrefix:
|
||||||
|
Minimum: 0
|
||||||
|
Maximum: -1
|
||||||
|
# SpacesInParentheses: false
|
||||||
|
# SpacesInSquareBrackets: false
|
||||||
|
# SpaceBeforeSquareBrackets: false
|
||||||
|
# BitFieldColonSpacing: Both
|
||||||
|
# StatementAttributeLikeMacros:
|
||||||
|
# - Q_EMIT
|
||||||
|
# StatementMacros:
|
||||||
|
# - Q_UNUSED
|
||||||
|
# - QT_REQUIRE_VERSION
|
||||||
|
TabWidth: 8
|
||||||
|
# UseCRLF: false
|
||||||
|
UseTab: Always
|
||||||
|
# WhitespaceSensitiveMacros:
|
||||||
|
# - STRINGIZE
|
||||||
|
# - PP_STRINGIZE
|
||||||
|
# - BOOST_PP_STRINGIZE
|
||||||
|
# - NS_SWIFT_NAME
|
||||||
|
# - CF_SWIFT_NAME
|
||||||
|
---
|
||||||
|
### C++ specific config ###
|
||||||
|
Language: Cpp
|
||||||
|
Standard: c++14
|
||||||
|
---
|
||||||
|
### ObjC specific config ###
|
||||||
|
Language: ObjC
|
||||||
|
# ObjCBinPackProtocolList: Auto
|
||||||
|
ObjCBlockIndentWidth: 4
|
||||||
|
# ObjCBreakBeforeNestedBlockParam: true
|
||||||
|
# ObjCSpaceAfterProperty: false
|
||||||
|
# ObjCSpaceBeforeProtocolList: true
|
||||||
|
---
|
||||||
|
### Java specific config ###
|
||||||
|
Language: Java
|
||||||
|
# BreakAfterJavaFieldAnnotations: false
|
||||||
|
JavaImportGroups: ['org.godotengine', 'android', 'androidx', 'com.android', 'com.google', 'java', 'javax']
|
||||||
|
...
|
||||||
@@ -36,7 +36,7 @@ void _get_property_list(List<PropertyInfo> *p_list) const;
|
|||||||
void _notification(int p_what);
|
void _notification(int p_what);
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
#endif
|
#endif
|
||||||
}
|
} //namespace ECS
|
||||||
void ECS::play(struct ECS::AnimationPlayerData *player,
|
void ECS::play(struct ECS::AnimationPlayerData *player,
|
||||||
const StringName &p_name,
|
const StringName &p_name,
|
||||||
float p_custom_blend, float p_custom_scale,
|
float p_custom_blend, float p_custom_scale,
|
||||||
@@ -732,6 +732,10 @@ static void ECS::_animation_process_data(struct ECS::AnimationPlayerData *player
|
|||||||
{
|
{
|
||||||
float delta = p_delta * player->speed_scale * cd.speed_scale;
|
float delta = p_delta * player->speed_scale * cd.speed_scale;
|
||||||
float next_pos = cd.pos + delta;
|
float next_pos = cd.pos + delta;
|
||||||
|
if (cd.from->animation.is_null()) {
|
||||||
|
ERR_PRINT("bad animation");
|
||||||
|
return;
|
||||||
|
}
|
||||||
float len = cd.from->animation->get_length();
|
float len = cd.from->animation->get_length();
|
||||||
bool loop = cd.from->animation->has_loop();
|
bool loop = cd.from->animation->has_loop();
|
||||||
if (!loop) {
|
if (!loop) {
|
||||||
@@ -773,6 +777,10 @@ static void ECS::_animation_process2(struct ECS::AnimationPlayerData *player,
|
|||||||
ECS::Playback &c = player->playback;
|
ECS::Playback &c = player->playback;
|
||||||
player->accum_pass++;
|
player->accum_pass++;
|
||||||
|
|
||||||
|
if (c.current.from->animation.is_null()) {
|
||||||
|
ERR_PRINT("bad animation2");
|
||||||
|
return;
|
||||||
|
}
|
||||||
_animation_process_data(player, c.current,
|
_animation_process_data(player, c.current,
|
||||||
p_delta, 1.0f,
|
p_delta, 1.0f,
|
||||||
c.seeked && p_delta != 0, p_started);
|
c.seeked && p_delta != 0, p_started);
|
||||||
@@ -782,6 +790,14 @@ static void ECS::_animation_process2(struct ECS::AnimationPlayerData *player,
|
|||||||
for (List<Blend>::Element *E = c.blend.back(); E; E = prev) {
|
for (List<Blend>::Element *E = c.blend.back(); E; E = prev) {
|
||||||
Blend &b = E->get();
|
Blend &b = E->get();
|
||||||
float blend = b.blend_left / b.blend_time;
|
float blend = b.blend_left / b.blend_time;
|
||||||
|
if (b.data.from->animation.is_null()) {
|
||||||
|
ERR_PRINT("bad animation3");
|
||||||
|
b.blend_left -= Math::absf(player->speed_scale * p_delta);
|
||||||
|
prev = E->prev();
|
||||||
|
if (b.blend_left < 0)
|
||||||
|
c.blend.erase(E);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
_animation_process_data(player, b.data, p_delta, blend, false, false);
|
_animation_process_data(player, b.data, p_delta, blend, false, false);
|
||||||
b.blend_left -= Math::absf(player->speed_scale * p_delta);
|
b.blend_left -= Math::absf(player->speed_scale * p_delta);
|
||||||
prev = E->prev();
|
prev = E->prev();
|
||||||
@@ -872,7 +888,8 @@ static void ECS::_animation_process(struct ECS::AnimationPlayerData *player, flo
|
|||||||
} else
|
} else
|
||||||
_set_process(player, false);
|
_set_process(player, false);
|
||||||
}
|
}
|
||||||
void ECS::_stop_playing_caches(struct ECS::AnimationPlayerData *player) {
|
void ECS::_stop_playing_caches(struct ECS::AnimationPlayerData *player)
|
||||||
|
{
|
||||||
#if 0
|
#if 0
|
||||||
for (Set<TrackNodeCache *>::Element *E = player->playing_caches.front(); E; E = E->next()) {
|
for (Set<TrackNodeCache *>::Element *E = player->playing_caches.front(); E; E = E->next()) {
|
||||||
if (E->get()->node && E->get()->audio_playing) {
|
if (E->get()->node && E->get()->audio_playing) {
|
||||||
@@ -916,6 +933,8 @@ Error ECS::add_animation(struct ECS::AnimationPlayerData *player,
|
|||||||
const StringName &p_name, const Ref<Animation> &p_animation)
|
const StringName &p_name, const Ref<Animation> &p_animation)
|
||||||
{
|
{
|
||||||
ERR_FAIL_COND_V(p_animation.is_null(), ERR_INVALID_PARAMETER);
|
ERR_FAIL_COND_V(p_animation.is_null(), ERR_INVALID_PARAMETER);
|
||||||
|
print_line("animation name: " + p_name);
|
||||||
|
print_line("animation length: " + itos(p_animation->get_length()));
|
||||||
|
|
||||||
if (player->animation_set.has(p_name)) {
|
if (player->animation_set.has(p_name)) {
|
||||||
_unref_anim(player, player->animation_set[p_name].animation);
|
_unref_anim(player, player->animation_set[p_name].animation);
|
||||||
|
|||||||
@@ -82,7 +82,9 @@ struct TrackNodeCache {
|
|||||||
audio_playing(false),
|
audio_playing(false),
|
||||||
audio_start(0.0),
|
audio_start(0.0),
|
||||||
audio_len(0.0),
|
audio_len(0.0),
|
||||||
animation_playing(false) {}
|
animation_playing(false)
|
||||||
|
{
|
||||||
|
}
|
||||||
};
|
};
|
||||||
struct AnimationData {
|
struct AnimationData {
|
||||||
String name;
|
String name;
|
||||||
@@ -95,7 +97,8 @@ struct PlaybackData {
|
|||||||
float pos;
|
float pos;
|
||||||
float speed_scale;
|
float speed_scale;
|
||||||
|
|
||||||
PlaybackData() {
|
PlaybackData()
|
||||||
|
{
|
||||||
pos = 0;
|
pos = 0;
|
||||||
speed_scale = 1.0;
|
speed_scale = 1.0;
|
||||||
from = nullptr;
|
from = nullptr;
|
||||||
@@ -105,7 +108,8 @@ struct Blend {
|
|||||||
PlaybackData data;
|
PlaybackData data;
|
||||||
float blend_time;
|
float blend_time;
|
||||||
float blend_left;
|
float blend_left;
|
||||||
Blend() {
|
Blend()
|
||||||
|
{
|
||||||
blend_left = 0.0f;
|
blend_left = 0.0f;
|
||||||
blend_time = 0.0f;
|
blend_time = 0.0f;
|
||||||
}
|
}
|
||||||
@@ -247,5 +251,5 @@ NodePath get_root(struct AnimationPlayerData *player);
|
|||||||
void clear_caches(struct AnimationPlayerData *player);
|
void clear_caches(struct AnimationPlayerData *player);
|
||||||
void get_argument_options(struct AnimationPlayerData *player,
|
void get_argument_options(struct AnimationPlayerData *player,
|
||||||
const StringName &p_function, int p_idx, List<String> *r_options);
|
const StringName &p_function, int p_idx, List<String> *r_options);
|
||||||
}
|
} //namespace ECS
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,21 +1,21 @@
|
|||||||
#include <cassert>
|
#include "character.h"
|
||||||
#include <flecs.h>
|
#include "animation_system.h"
|
||||||
#include <core/rid.h>
|
#include "skeleton-prep.h"
|
||||||
#include <scene/3d/collision_shape.h>
|
|
||||||
#include <core/engine.h>
|
#include <core/engine.h>
|
||||||
|
#include <core/rid.h>
|
||||||
#include <core/variant_parser.h>
|
#include <core/variant_parser.h>
|
||||||
|
#include <flecs.h>
|
||||||
|
#include <scene/3d/collision_shape.h>
|
||||||
#include <scene/3d/mesh_instance.h>
|
#include <scene/3d/mesh_instance.h>
|
||||||
#include <scene/resources/shape.h>
|
|
||||||
#include <scene/resources/packed_scene.h>
|
|
||||||
#include <servers/physics_server.h>
|
|
||||||
#include <servers/visual_server.h>
|
|
||||||
#include <scene/resources/animation.h>
|
|
||||||
#include <scene/resources/skin.h>
|
|
||||||
#include <scene/animation/animation_player.h>
|
#include <scene/animation/animation_player.h>
|
||||||
#include <scene/main/viewport.h>
|
#include <scene/main/viewport.h>
|
||||||
#include "character.h"
|
#include <scene/resources/animation.h>
|
||||||
#include "skeleton-prep.h"
|
#include <scene/resources/packed_scene.h>
|
||||||
#include "animation_system.h"
|
#include <scene/resources/shape.h>
|
||||||
|
#include <scene/resources/skin.h>
|
||||||
|
#include <servers/physics_server.h>
|
||||||
|
#include <servers/visual_server.h>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
namespace ECS {
|
namespace ECS {
|
||||||
Skeleton::Skeleton()
|
Skeleton::Skeleton()
|
||||||
@@ -28,7 +28,7 @@ namespace ECS {
|
|||||||
Skeleton::~Skeleton()
|
Skeleton::~Skeleton()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
} //namespace ECS
|
||||||
|
|
||||||
ECS::RigidBody::RigidBody(RID rid, enum type type)
|
ECS::RigidBody::RigidBody(RID rid, enum type type)
|
||||||
{
|
{
|
||||||
@@ -90,12 +90,24 @@ int Character::create_character(int id)
|
|||||||
root.emplace<Transform>();
|
root.emplace<Transform>();
|
||||||
root.emplace<ECS::RigidBody>(body, ECS::RigidBody::TYPE_KINEMATIC);
|
root.emplace<ECS::RigidBody>(body, ECS::RigidBody::TYPE_KINEMATIC);
|
||||||
root.emplace<ECS::Skeleton>();
|
root.emplace<ECS::Skeleton>();
|
||||||
|
root.emplace<ECS::AnimationPlayerData>();
|
||||||
|
List<StringName> anim_list;
|
||||||
|
scene_data[id].animations.get_key_list(&anim_list);
|
||||||
|
List<StringName>::Element *e = anim_list.front();
|
||||||
|
ECS::AnimationPlayerData *player = root.get_mut<ECS::AnimationPlayerData>();
|
||||||
|
while (e) {
|
||||||
|
ECS::add_animation(player, e->get(),
|
||||||
|
scene_data[id].animations[e->get()]);
|
||||||
|
flecs::log::trace("added animation %s", String(e->get()).ascii().get_data());
|
||||||
|
e = e->next();
|
||||||
|
}
|
||||||
|
root.modified<ECS::AnimationPlayerData>();
|
||||||
root.emplace<ECS::AnimationTree>();
|
root.emplace<ECS::AnimationTree>();
|
||||||
root.add<ECS::Dirty>();
|
root.add<ECS::Dirty>();
|
||||||
ECS::MetaData *md = root.get_mut<ECS::MetaData>();
|
ECS::MetaData *md = root.get_mut<ECS::MetaData>();
|
||||||
md->type_index = id;
|
md->type_index = id;
|
||||||
root.modified<ECS::MetaData>();
|
|
||||||
|
|
||||||
|
root.modified<ECS::MetaData>();
|
||||||
print_line("body created for root");
|
print_line("body created for root");
|
||||||
for (i = 0; i < scene_data[id].shapes.size(); i++) {
|
for (i = 0; i < scene_data[id].shapes.size(); i++) {
|
||||||
ecs.entity()
|
ecs.entity()
|
||||||
@@ -221,7 +233,7 @@ void Character::set_scene(int id, const Ref<PackedScene> &scene)
|
|||||||
while (e) {
|
while (e) {
|
||||||
StringName anim_name = e->get();
|
StringName anim_name = e->get();
|
||||||
Ref<Animation> animation = anim->get_animation(anim_name);
|
Ref<Animation> animation = anim->get_animation(anim_name);
|
||||||
scene_data[id].animations.push_back(animation);
|
scene_data[id].animations[anim_name] = animation;
|
||||||
e = e->next();
|
e = e->next();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -267,8 +279,7 @@ void Character::_bind_methods()
|
|||||||
void Character::init_bone()
|
void Character::init_bone()
|
||||||
{
|
{
|
||||||
ecs.component<ECS::BoneComponent>()
|
ecs.component<ECS::BoneComponent>()
|
||||||
.on_add([](flecs::entity e, ECS::BoneComponent &s)
|
.on_add([](flecs::entity e, ECS::BoneComponent &s) {
|
||||||
{
|
|
||||||
// flecs::log::trace("added bonecomponent %s", e.name().c_str());
|
// flecs::log::trace("added bonecomponent %s", e.name().c_str());
|
||||||
flecs::entity parent = e.parent();
|
flecs::entity parent = e.parent();
|
||||||
parent.add<ECS::Dirty>();
|
parent.add<ECS::Dirty>();
|
||||||
@@ -279,8 +290,7 @@ void Character::init_bone()
|
|||||||
parent.remove<ECS::Skinned>();
|
parent.remove<ECS::Skinned>();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.on_set([](flecs::entity e, ECS::BoneComponent &s)
|
.on_set([](flecs::entity e, ECS::BoneComponent &s) {
|
||||||
{
|
|
||||||
flecs::entity parent = e.parent();
|
flecs::entity parent = e.parent();
|
||||||
ECS::Skeleton *skel = parent.get_mut<ECS::Skeleton>();
|
ECS::Skeleton *skel = parent.get_mut<ECS::Skeleton>();
|
||||||
if (s.index >= skel->bone_count) {
|
if (s.index >= skel->bone_count) {
|
||||||
@@ -301,12 +311,10 @@ void Character::init_bone()
|
|||||||
parent.add<ECS::Dirty>();
|
parent.add<ECS::Dirty>();
|
||||||
});
|
});
|
||||||
ecs.component<ECS::BonePose>()
|
ecs.component<ECS::BonePose>()
|
||||||
.on_add([](flecs::entity e, ECS::BonePose &s)
|
.on_add([](flecs::entity e, ECS::BonePose &s) {
|
||||||
{
|
|
||||||
// flecs::log::trace("added bonepose %s", e.name().c_str());
|
// flecs::log::trace("added bonepose %s", e.name().c_str());
|
||||||
})
|
})
|
||||||
.on_set([](flecs::entity e, ECS::BonePose &s)
|
.on_set([](flecs::entity e, ECS::BonePose &s) {
|
||||||
{
|
|
||||||
#if 0
|
#if 0
|
||||||
const Transform &xform = s.pose;
|
const Transform &xform = s.pose;
|
||||||
String out;
|
String out;
|
||||||
@@ -317,11 +325,12 @@ void Character::init_bone()
|
|||||||
e.add<ECS::Dirty>();
|
e.add<ECS::Dirty>();
|
||||||
});
|
});
|
||||||
ecs.system<ECS::BonePose, ECS::Dirty>()
|
ecs.system<ECS::BonePose, ECS::Dirty>()
|
||||||
.with<ECS::Skeleton>().parent()
|
.with<ECS::Skeleton>()
|
||||||
.with<ECS::Bound>().parent()
|
.parent()
|
||||||
|
.with<ECS::Bound>()
|
||||||
|
.parent()
|
||||||
.kind(flecs::OnUpdate)
|
.kind(flecs::OnUpdate)
|
||||||
.each([this](flecs::entity e, ECS::BonePose &s, const ECS::Dirty &d)
|
.each([this](flecs::entity e, ECS::BonePose &s, const ECS::Dirty &d) {
|
||||||
{
|
|
||||||
flecs::entity parent = e.parent();
|
flecs::entity parent = e.parent();
|
||||||
/* Don't update unbound skeleton */
|
/* Don't update unbound skeleton */
|
||||||
if (!parent.has<ECS::Bound>()) {
|
if (!parent.has<ECS::Bound>()) {
|
||||||
@@ -342,11 +351,15 @@ void Character::init_bone()
|
|||||||
}
|
}
|
||||||
void Character::animation_system_init()
|
void Character::animation_system_init()
|
||||||
{
|
{
|
||||||
ecs.component<ECS::AnimationPlayerData>();
|
ecs.component<ECS::AnimationPlayerData>()
|
||||||
|
.on_set([](flecs::entity e, ECS::AnimationPlayerData &s) {
|
||||||
|
flecs::log::trace("created animation player");
|
||||||
|
});
|
||||||
ecs.system<ECS::AnimationPlayerData>("UpdateAnimation")
|
ecs.system<ECS::AnimationPlayerData>("UpdateAnimation")
|
||||||
.kind(flecs::OnUpdate)
|
.kind(flecs::OnUpdate)
|
||||||
.each([](flecs::entity e, ECS::AnimationPlayerData &player)
|
.each([](flecs::entity e, ECS::AnimationPlayerData &player) {
|
||||||
{
|
if (!player.playing)
|
||||||
|
ECS::play(&player, "stand1-loop");
|
||||||
ECS::advance(&player, SceneTree::get_singleton()->get_physics_process_time());
|
ECS::advance(&player, SceneTree::get_singleton()->get_physics_process_time());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -358,20 +371,17 @@ void Character::initialize()
|
|||||||
ecs.import <skeleton_prep>();
|
ecs.import <skeleton_prep>();
|
||||||
init_skeleton();
|
init_skeleton();
|
||||||
ecs.component<ECS::MetaData>()
|
ecs.component<ECS::MetaData>()
|
||||||
.on_add([](flecs::entity e, ECS::MetaData &s)
|
.on_add([](flecs::entity e, ECS::MetaData &s) {
|
||||||
{
|
|
||||||
flecs::log::trace("added metadata %s", e.name().c_str());
|
flecs::log::trace("added metadata %s", e.name().c_str());
|
||||||
});
|
});
|
||||||
init_bone();
|
init_bone();
|
||||||
init_slot();
|
init_slot();
|
||||||
ecs.component<ECS::AnimationTree>()
|
ecs.component<ECS::AnimationTree>()
|
||||||
.on_add([](flecs::entity e, ECS::AnimationTree &s)
|
.on_add([](flecs::entity e, ECS::AnimationTree &s) {
|
||||||
{
|
|
||||||
flecs::log::trace("animationtree slot %s", e.name().c_str());
|
flecs::log::trace("animationtree slot %s", e.name().c_str());
|
||||||
});
|
});
|
||||||
ecs.component<ECS::RigidBody>()
|
ecs.component<ECS::RigidBody>()
|
||||||
.on_add([](flecs::entity e, ECS::RigidBody &s)
|
.on_add([](flecs::entity e, ECS::RigidBody &s) {
|
||||||
{
|
|
||||||
flecs::log::trace("added rigidbody %s", e.name().c_str());
|
flecs::log::trace("added rigidbody %s", e.name().c_str());
|
||||||
});
|
});
|
||||||
const String path = "res://characters/";
|
const String path = "res://characters/";
|
||||||
@@ -385,8 +395,7 @@ void Character::initialize()
|
|||||||
ecs.system<ECS::Skeleton>("UpdateBone")
|
ecs.system<ECS::Skeleton>("UpdateBone")
|
||||||
.with<ECS::Bound>()
|
.with<ECS::Bound>()
|
||||||
.kind(flecs::OnUpdate)
|
.kind(flecs::OnUpdate)
|
||||||
.each([](flecs::entity e, ECS::Skeleton &sk)
|
.each([](flecs::entity e, ECS::Skeleton &sk) {
|
||||||
{
|
|
||||||
flecs::entity root = e.lookup("Root");
|
flecs::entity root = e.lookup("Root");
|
||||||
if (!root.is_valid() || !root.is_alive())
|
if (!root.is_valid() || !root.is_alive())
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -57,7 +57,8 @@ namespace ECS {
|
|||||||
};
|
};
|
||||||
struct AnimationTree {
|
struct AnimationTree {
|
||||||
void *root;
|
void *root;
|
||||||
AnimationTree(): root(nullptr)
|
AnimationTree() :
|
||||||
|
root(nullptr)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
~AnimationTree()
|
~AnimationTree()
|
||||||
@@ -100,7 +101,7 @@ namespace ECS {
|
|||||||
CShape(RID body, const Transform &offset, Ref<Shape> shape);
|
CShape(RID body, const Transform &offset, Ref<Shape> shape);
|
||||||
~CShape();
|
~CShape();
|
||||||
};
|
};
|
||||||
}
|
} //namespace ECS
|
||||||
|
|
||||||
class Character : public Object {
|
class Character : public Object {
|
||||||
GDCLASS(Character, Object)
|
GDCLASS(Character, Object)
|
||||||
@@ -113,6 +114,7 @@ public:
|
|||||||
void set_scene(int id, const Ref<PackedScene> &scene);
|
void set_scene(int id, const Ref<PackedScene> &scene);
|
||||||
Ref<PackedScene> get_scene(int id) const;
|
Ref<PackedScene> get_scene(int id) const;
|
||||||
Character();
|
Character();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
flecs::world ecs;
|
flecs::world ecs;
|
||||||
struct shape_data {
|
struct shape_data {
|
||||||
@@ -134,7 +136,7 @@ protected:
|
|||||||
Ref<PackedScene> scene;
|
Ref<PackedScene> scene;
|
||||||
Vector<struct shape_data> shapes;
|
Vector<struct shape_data> shapes;
|
||||||
Vector<struct mesh_data> meshes;
|
Vector<struct mesh_data> meshes;
|
||||||
Vector<Ref<Animation> > animations;
|
HashMap<StringName, Ref<Animation>> animations;
|
||||||
Vector<struct bone_data> bones;
|
Vector<struct bone_data> bones;
|
||||||
Set<SkinReference *> skin_bindings;
|
Set<SkinReference *> skin_bindings;
|
||||||
} scene_data[2];
|
} scene_data[2];
|
||||||
|
|||||||
@@ -1,26 +1,24 @@
|
|||||||
|
|
||||||
#include <cassert>
|
#include "character.h"
|
||||||
#include <flecs.h>
|
|
||||||
#include <servers/visual_server.h>
|
|
||||||
#include <scene/main/scene_tree.h>
|
|
||||||
#include <core/reference.h>
|
#include <core/reference.h>
|
||||||
|
#include <core/variant_parser.h>
|
||||||
|
#include <flecs.h>
|
||||||
|
#include <scene/main/scene_tree.h>
|
||||||
#include <scene/main/viewport.h>
|
#include <scene/main/viewport.h>
|
||||||
#include <scene/resources/skin.h>
|
#include <scene/resources/skin.h>
|
||||||
#include <core/variant_parser.h>
|
#include <servers/visual_server.h>
|
||||||
#include "character.h"
|
#include <cassert>
|
||||||
|
|
||||||
void Character::init_skeleton()
|
void Character::init_skeleton()
|
||||||
{
|
{
|
||||||
VisualServer *vs = VS::get_singleton();
|
VisualServer *vs = VS::get_singleton();
|
||||||
ecs.component<ECS::Skeleton>()
|
ecs.component<ECS::Skeleton>()
|
||||||
.on_add([](flecs::entity e, ECS::Skeleton &s)
|
.on_add([](flecs::entity e, ECS::Skeleton &s) {
|
||||||
{
|
|
||||||
// flecs::log::trace("added skeleton %s", e.name().c_str());
|
// flecs::log::trace("added skeleton %s", e.name().c_str());
|
||||||
if (e.has<ECS::SkeletonOrderPrepared>())
|
if (e.has<ECS::SkeletonOrderPrepared>())
|
||||||
e.remove<ECS::SkeletonOrderPrepared>();
|
e.remove<ECS::SkeletonOrderPrepared>();
|
||||||
})
|
})
|
||||||
.on_set([](flecs::entity e, ECS::Skeleton &s)
|
.on_set([](flecs::entity e, ECS::Skeleton &s) {
|
||||||
{
|
|
||||||
// flecs::log::trace("on set: set skeleton %s", e.name().c_str());
|
// flecs::log::trace("on set: set skeleton %s", e.name().c_str());
|
||||||
// s.process_order_dirty = true;
|
// s.process_order_dirty = true;
|
||||||
e.add<ECS::Dirty>();
|
e.add<ECS::Dirty>();
|
||||||
@@ -28,8 +26,7 @@ void Character::init_skeleton()
|
|||||||
ecs.system<ECS::Skeleton>("CreateSkeleton")
|
ecs.system<ECS::Skeleton>("CreateSkeleton")
|
||||||
.without<ECS::Bound>()
|
.without<ECS::Bound>()
|
||||||
.kind(flecs::PreUpdate)
|
.kind(flecs::PreUpdate)
|
||||||
.each([vs](flecs::entity e, ECS::Skeleton &skel)
|
.each([vs](flecs::entity e, ECS::Skeleton &skel) {
|
||||||
{
|
|
||||||
if (!skel.skeleton.is_valid()) {
|
if (!skel.skeleton.is_valid()) {
|
||||||
skel.skeleton = vs->skeleton_create();
|
skel.skeleton = vs->skeleton_create();
|
||||||
flecs::log::trace("created skeleton");
|
flecs::log::trace("created skeleton");
|
||||||
@@ -39,8 +36,7 @@ void Character::init_skeleton()
|
|||||||
.with<ECS::Dirty>()
|
.with<ECS::Dirty>()
|
||||||
.without<ECS::SkeletonOrderPrepared>()
|
.without<ECS::SkeletonOrderPrepared>()
|
||||||
.kind(flecs::PreUpdate)
|
.kind(flecs::PreUpdate)
|
||||||
.each([](flecs::entity e, ECS::Skeleton &sk)
|
.each([](flecs::entity e, ECS::Skeleton &sk) {
|
||||||
{
|
|
||||||
if (sk.process_order_dirty) {
|
if (sk.process_order_dirty) {
|
||||||
flecs::log::trace("skeletons: %d dirty: sorting bones", sk.bone_count);
|
flecs::log::trace("skeletons: %d dirty: sorting bones", sk.bone_count);
|
||||||
int i;
|
int i;
|
||||||
@@ -88,8 +84,7 @@ void Character::init_skeleton()
|
|||||||
.with<ECS::SkeletonOrderPrepared>()
|
.with<ECS::SkeletonOrderPrepared>()
|
||||||
.without<ECS::SkeletonTransformReady>()
|
.without<ECS::SkeletonTransformReady>()
|
||||||
.kind(flecs::OnUpdate)
|
.kind(flecs::OnUpdate)
|
||||||
.each([](flecs::entity e, ECS::Skeleton &sk)
|
.each([](flecs::entity e, ECS::Skeleton &sk) {
|
||||||
{
|
|
||||||
int i;
|
int i;
|
||||||
VisualServer *vs = VS::get_singleton();
|
VisualServer *vs = VS::get_singleton();
|
||||||
// flecs::log::trace("skeletons: %d dirty: update try", sk.bone_count);
|
// flecs::log::trace("skeletons: %d dirty: update try", sk.bone_count);
|
||||||
|
|||||||
@@ -1,23 +1,21 @@
|
|||||||
#include <cassert>
|
#include "character.h"
|
||||||
#include <flecs.h>
|
|
||||||
#include <servers/visual_server.h>
|
|
||||||
#include <scene/main/scene_tree.h>
|
|
||||||
#include <core/reference.h>
|
#include <core/reference.h>
|
||||||
|
#include <flecs.h>
|
||||||
|
#include <scene/main/scene_tree.h>
|
||||||
#include <scene/main/viewport.h>
|
#include <scene/main/viewport.h>
|
||||||
#include <scene/resources/skin.h>
|
#include <scene/resources/skin.h>
|
||||||
#include "character.h"
|
#include <servers/visual_server.h>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
void Character::init_slot()
|
void Character::init_slot()
|
||||||
{
|
{
|
||||||
SceneTree *st = SceneTree::get_singleton();
|
SceneTree *st = SceneTree::get_singleton();
|
||||||
VisualServer *vs = VS::get_singleton();
|
VisualServer *vs = VS::get_singleton();
|
||||||
ecs.component<ECS::CharacterSlot>()
|
ecs.component<ECS::CharacterSlot>()
|
||||||
.on_add([](flecs::entity e, ECS::CharacterSlot &s)
|
.on_add([](flecs::entity e, ECS::CharacterSlot &s) {
|
||||||
{
|
|
||||||
flecs::log::trace("added slot %s", e.name().c_str());
|
flecs::log::trace("added slot %s", e.name().c_str());
|
||||||
})
|
})
|
||||||
.on_remove([vs](flecs::entity e, ECS::CharacterSlot &s)
|
.on_remove([vs](flecs::entity e, ECS::CharacterSlot &s) {
|
||||||
{
|
|
||||||
if (s.instance.is_valid()) {
|
if (s.instance.is_valid()) {
|
||||||
vs->instance_set_scenario(s.instance, RID());
|
vs->instance_set_scenario(s.instance, RID());
|
||||||
vs->instance_attach_skeleton(s.instance, RID());
|
vs->instance_attach_skeleton(s.instance, RID());
|
||||||
@@ -28,18 +26,17 @@ void Character::init_slot()
|
|||||||
}
|
}
|
||||||
// flecs::log::trace("removed slot %s", e.name().c_str());
|
// flecs::log::trace("removed slot %s", e.name().c_str());
|
||||||
})
|
})
|
||||||
.on_set([st](flecs::entity e, ECS::CharacterSlot &s)
|
.on_set([st](flecs::entity e, ECS::CharacterSlot &s) {
|
||||||
{
|
|
||||||
// flecs::log::trace("set slot %s", e.name().c_str());
|
// flecs::log::trace("set slot %s", e.name().c_str());
|
||||||
if (s.mesh.is_null() || !s.mesh.is_valid())
|
if (s.mesh.is_null() || !s.mesh.is_valid())
|
||||||
flecs::log::err("invalid mesh %s", e.name().c_str());
|
flecs::log::err("invalid mesh %s", e.name().c_str());
|
||||||
});
|
});
|
||||||
ecs.system<ECS::CharacterSlot>("UpdateSlot")
|
ecs.system<ECS::CharacterSlot>("UpdateSlot")
|
||||||
.without<ECS::Bound>()
|
.without<ECS::Bound>()
|
||||||
.with<ECS::Skeleton>().parent()
|
.with<ECS::Skeleton>()
|
||||||
|
.parent()
|
||||||
.kind(flecs::PreUpdate)
|
.kind(flecs::PreUpdate)
|
||||||
.each([vs, st](flecs::entity e, ECS::CharacterSlot &slot)
|
.each([vs, st](flecs::entity e, ECS::CharacterSlot &slot) {
|
||||||
{
|
|
||||||
assert(e.parent().has<ECS::Skeleton>());
|
assert(e.parent().has<ECS::Skeleton>());
|
||||||
if (!slot.instance.is_valid()) {
|
if (!slot.instance.is_valid()) {
|
||||||
slot.name = e.name().c_str();
|
slot.name = e.name().c_str();
|
||||||
@@ -52,11 +49,11 @@ void Character::init_slot()
|
|||||||
});
|
});
|
||||||
ecs.system<ECS::CharacterSlot>("AttachToSkeleton")
|
ecs.system<ECS::CharacterSlot>("AttachToSkeleton")
|
||||||
.without<ECS::Bound>()
|
.without<ECS::Bound>()
|
||||||
.with<ECS::Skeleton>().parent()
|
.with<ECS::Skeleton>()
|
||||||
|
.parent()
|
||||||
.with<ECS::Skinned>()
|
.with<ECS::Skinned>()
|
||||||
.kind(flecs::PreUpdate)
|
.kind(flecs::PreUpdate)
|
||||||
.each([vs, st](flecs::entity e, ECS::CharacterSlot &slot)
|
.each([vs, st](flecs::entity e, ECS::CharacterSlot &slot) {
|
||||||
{
|
|
||||||
flecs::entity parent = e.parent();
|
flecs::entity parent = e.parent();
|
||||||
assert(parent.has<ECS::Skeleton>());
|
assert(parent.has<ECS::Skeleton>());
|
||||||
assert(!e.has<ECS::Bound>());
|
assert(!e.has<ECS::Bound>());
|
||||||
@@ -79,12 +76,12 @@ void Character::init_slot()
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
ecs.system<ECS::CharacterSlot>("BindSlotsToSkeleton")
|
ecs.system<ECS::CharacterSlot>("BindSlotsToSkeleton")
|
||||||
.with<ECS::Skeleton>().parent()
|
.with<ECS::Skeleton>()
|
||||||
|
.parent()
|
||||||
.without<ECS::Bound>()
|
.without<ECS::Bound>()
|
||||||
.without<ECS::Skinned>()
|
.without<ECS::Skinned>()
|
||||||
.kind(flecs::PreUpdate)
|
.kind(flecs::PreUpdate)
|
||||||
.each([vs](flecs::entity e, ECS::CharacterSlot &slot)
|
.each([vs](flecs::entity e, ECS::CharacterSlot &slot) {
|
||||||
{
|
|
||||||
flecs::entity parent = e.parent();
|
flecs::entity parent = e.parent();
|
||||||
int i;
|
int i;
|
||||||
assert(!e.has<ECS::Bound>());
|
assert(!e.has<ECS::Bound>());
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#include <core/engine.h>
|
|
||||||
#include "character.h"
|
|
||||||
#include "register_types.h"
|
#include "register_types.h"
|
||||||
|
#include "character.h"
|
||||||
|
#include <core/engine.h>
|
||||||
|
|
||||||
void register_character_types()
|
void register_character_types()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user