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();
|
||||||
@@ -821,13 +837,13 @@ static void ECS::_animation_update_transforms(struct ECS::AnimationPlayerData *p
|
|||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
case SP_NODE2D_POS:
|
case SP_NODE2D_POS:
|
||||||
// static_cast<Node2D *>(pa->object)->set_position(pa->value_accum);
|
// static_cast<Node2D *>(pa->object)->set_position(pa->value_accum);
|
||||||
break;
|
break;
|
||||||
case SP_NODE2D_ROT:
|
case SP_NODE2D_ROT:
|
||||||
// static_cast<Node2D *>(pa->object)->set_rotation(Math::deg2rad((double)pa->value_accum));
|
// static_cast<Node2D *>(pa->object)->set_rotation(Math::deg2rad((double)pa->value_accum));
|
||||||
break;
|
break;
|
||||||
case SP_NODE2D_SCALE:
|
case SP_NODE2D_SCALE:
|
||||||
// static_cast<Node2D *>(pa->object)->set_scale(pa->value_accum);
|
// static_cast<Node2D *>(pa->object)->set_scale(pa->value_accum);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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,34 +1,34 @@
|
|||||||
#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()
|
||||||
{
|
{
|
||||||
bone_count = 0;
|
bone_count = 0;
|
||||||
skeleton = RID();
|
skeleton = RID();
|
||||||
dirty = true;
|
dirty = true;
|
||||||
process_order_dirty = true;
|
process_order_dirty = true;
|
||||||
}
|
|
||||||
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()
|
||||||
@@ -108,7 +120,7 @@ int Character::create_character(int id)
|
|||||||
ecs.entity(scene_data[id].bones[i].name.ascii().get_data())
|
ecs.entity(scene_data[id].bones[i].name.ascii().get_data())
|
||||||
.child_of(root)
|
.child_of(root)
|
||||||
.emplace<ECS::BoneComponent>(index, parent_index, rest)
|
.emplace<ECS::BoneComponent>(index, parent_index, rest)
|
||||||
.set<ECS::BonePose>({index, Transform()});
|
.set<ECS::BonePose>({ index, Transform() });
|
||||||
}
|
}
|
||||||
for (i = 0; i < scene_data[id].meshes.size(); i++) {
|
for (i = 0; i < scene_data[id].meshes.size(); i++) {
|
||||||
// flecs::log::trace("creating slot -");
|
// flecs::log::trace("creating slot -");
|
||||||
@@ -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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -234,7 +246,7 @@ void Character::set_scene(int id, const Ref<PackedScene> &scene)
|
|||||||
scene_data[id].bones.write[i].index = i;
|
scene_data[id].bones.write[i].index = i;
|
||||||
scene_data[id].bones.write[i].parent = skel->get_bone_parent(i);
|
scene_data[id].bones.write[i].parent = skel->get_bone_parent(i);
|
||||||
scene_data[id].bones.write[i].rest = skel->get_bone_rest(i);
|
scene_data[id].bones.write[i].rest = skel->get_bone_rest(i);
|
||||||
// print_line("added bone: " + scene_data[id].bones.write[i].name + " " + itos(i));
|
// print_line("added bone: " + scene_data[id].bones.write[i].name + " " + itos(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (i = 0; i < tmp->get_child_count(); i++)
|
for (i = 0; i < tmp->get_child_count(); i++)
|
||||||
@@ -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());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -355,23 +368,20 @@ void Character::initialize()
|
|||||||
Error err;
|
Error err;
|
||||||
flecs::log::set_level(0);
|
flecs::log::set_level(0);
|
||||||
SceneTree *st = SceneTree::get_singleton();
|
SceneTree *st = SceneTree::get_singleton();
|
||||||
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;
|
||||||
@@ -394,7 +403,7 @@ void Character::initialize()
|
|||||||
return;
|
return;
|
||||||
float delta = SceneTree::get_singleton()->get_physics_process_time();
|
float delta = SceneTree::get_singleton()->get_physics_process_time();
|
||||||
struct ECS::BonePose *bp = root.get_mut<ECS::BonePose>();
|
struct ECS::BonePose *bp = root.get_mut<ECS::BonePose>();
|
||||||
// bp->pose.basis = bp->pose.basis.rotated(Vector3(0, 1, 0), 0.016f);
|
// bp->pose.basis = bp->pose.basis.rotated(Vector3(0, 1, 0), 0.016f);
|
||||||
bp->pose.origin += Vector3(0.2f * delta, 0.0f, 0.0f);
|
bp->pose.origin += Vector3(0.2f * delta, 0.0f, 0.0f);
|
||||||
root.modified<ECS::BonePose>();
|
root.modified<ECS::BonePose>();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ class Animation;
|
|||||||
class Skin;
|
class Skin;
|
||||||
class SkinReference;
|
class SkinReference;
|
||||||
namespace ECS {
|
namespace ECS {
|
||||||
struct Skeleton {
|
struct Skeleton {
|
||||||
bool dirty;
|
bool dirty;
|
||||||
RID skeleton;
|
RID skeleton;
|
||||||
Ref<Skin> skin;
|
Ref<Skin> skin;
|
||||||
@@ -36,35 +36,36 @@ namespace ECS {
|
|||||||
Vector<struct bone_data> bones;
|
Vector<struct bone_data> bones;
|
||||||
Skeleton();
|
Skeleton();
|
||||||
~Skeleton();
|
~Skeleton();
|
||||||
};
|
};
|
||||||
struct Bound {};
|
struct Bound {};
|
||||||
struct Skinned {};
|
struct Skinned {};
|
||||||
struct Dirty {};
|
struct Dirty {};
|
||||||
struct SkeletonOrderPrepared {};
|
struct SkeletonOrderPrepared {};
|
||||||
struct SkeletonTransformReady {};
|
struct SkeletonTransformReady {};
|
||||||
struct MetaData {
|
struct MetaData {
|
||||||
int type_index;
|
int type_index;
|
||||||
};
|
};
|
||||||
struct BoneComponent {
|
struct BoneComponent {
|
||||||
flecs::entity_t skeleton;
|
flecs::entity_t skeleton;
|
||||||
int index, parent_index;
|
int index, parent_index;
|
||||||
Transform rest, pose;
|
Transform rest, pose;
|
||||||
BoneComponent(int index, int parent_index, const Transform &rest);
|
BoneComponent(int index, int parent_index, const Transform &rest);
|
||||||
};
|
};
|
||||||
struct BonePose {
|
struct BonePose {
|
||||||
int index;
|
int index;
|
||||||
Transform pose;
|
Transform pose;
|
||||||
};
|
};
|
||||||
struct AnimationTree {
|
struct AnimationTree {
|
||||||
void *root;
|
void *root;
|
||||||
AnimationTree(): root(nullptr)
|
AnimationTree() :
|
||||||
|
root(nullptr)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
~AnimationTree()
|
~AnimationTree()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
struct CharacterSlot {
|
struct CharacterSlot {
|
||||||
String name;
|
String name;
|
||||||
RID instance;
|
RID instance;
|
||||||
RID skeleton;
|
RID skeleton;
|
||||||
@@ -79,8 +80,8 @@ namespace ECS {
|
|||||||
CharacterSlot &operator=(CharacterSlot &&obj);
|
CharacterSlot &operator=(CharacterSlot &&obj);
|
||||||
~CharacterSlot();
|
~CharacterSlot();
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
struct RigidBody {
|
struct RigidBody {
|
||||||
enum type {
|
enum type {
|
||||||
TYPE_NONE = 0,
|
TYPE_NONE = 0,
|
||||||
TYPE_STATIC = 1,
|
TYPE_STATIC = 1,
|
||||||
@@ -93,18 +94,18 @@ namespace ECS {
|
|||||||
enum type type;
|
enum type type;
|
||||||
RigidBody(RID rid, enum type type);
|
RigidBody(RID rid, enum type type);
|
||||||
~RigidBody();
|
~RigidBody();
|
||||||
};
|
};
|
||||||
struct CShape {
|
struct CShape {
|
||||||
Transform offset;
|
Transform offset;
|
||||||
Ref<Shape> shape;
|
Ref<Shape> shape;
|
||||||
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)
|
||||||
public:
|
public:
|
||||||
int create_character(int type_id);
|
int create_character(int type_id);
|
||||||
void destroy_character(int id);
|
void destroy_character(int id);
|
||||||
static Character *singleton;
|
static Character *singleton;
|
||||||
@@ -113,7 +114,8 @@ 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 {
|
||||||
Ref<Shape> shape;
|
Ref<Shape> shape;
|
||||||
@@ -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,35 +1,32 @@
|
|||||||
|
|
||||||
#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>();
|
||||||
});
|
});
|
||||||
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,14 +84,13 @@ 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);
|
||||||
if (sk.process_order_dirty)
|
if (sk.process_order_dirty)
|
||||||
return;
|
return;
|
||||||
// flecs::log::trace("skeletons: %d dirty: update", sk.bone_count);
|
// flecs::log::trace("skeletons: %d dirty: update", sk.bone_count);
|
||||||
struct ECS::Skeleton::bone_data *bonesptr = sk.bones.ptrw();
|
struct ECS::Skeleton::bone_data *bonesptr = sk.bones.ptrw();
|
||||||
int len = sk.bones.size();
|
int len = sk.bones.size();
|
||||||
const int *order = sk.process_order.ptr();
|
const int *order = sk.process_order.ptr();
|
||||||
@@ -146,7 +141,7 @@ void Character::init_skeleton()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// flecs::log::trace("transform should be ready");
|
// flecs::log::trace("transform should be ready");
|
||||||
e.add<ECS::SkeletonTransformReady>();
|
e.add<ECS::SkeletonTransformReady>();
|
||||||
assert(sk.skin_bone_indices_ptrs);
|
assert(sk.skin_bone_indices_ptrs);
|
||||||
uint32_t bind_count = sk.skin->get_bind_count();
|
uint32_t bind_count = sk.skin->get_bind_count();
|
||||||
|
|||||||
@@ -1,45 +1,42 @@
|
|||||||
#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());
|
||||||
vs->instance_set_base(s.instance, RID());
|
vs->instance_set_base(s.instance, RID());
|
||||||
vs->free(s.instance);
|
vs->free(s.instance);
|
||||||
s.instance = RID();
|
s.instance = RID();
|
||||||
// print_line("mesh instance slot removed " + s.name);
|
// print_line("mesh instance slot removed " + s.name);
|
||||||
}
|
}
|
||||||
// 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();
|
||||||
@@ -47,23 +44,23 @@ void Character::init_slot()
|
|||||||
slot.instance = vs->instance_create();
|
slot.instance = vs->instance_create();
|
||||||
vs->instance_set_scenario(slot.instance, scenario);
|
vs->instance_set_scenario(slot.instance, scenario);
|
||||||
vs->instance_set_base(slot.instance, slot.mesh->get_rid());
|
vs->instance_set_base(slot.instance, slot.mesh->get_rid());
|
||||||
// flecs::log::trace("created instance for %s", e.name().c_str());
|
// flecs::log::trace("created instance for %s", e.name().c_str());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
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>());
|
||||||
assert(slot.instance.is_valid());
|
assert(slot.instance.is_valid());
|
||||||
const ECS::Skeleton *skel = parent.get<ECS::Skeleton>();
|
const ECS::Skeleton *skel = parent.get<ECS::Skeleton>();
|
||||||
assert(skel->skeleton.is_valid());
|
assert(skel->skeleton.is_valid());
|
||||||
// flecs::log::trace("binding slot for %s", e.name().c_str());
|
// flecs::log::trace("binding slot for %s", e.name().c_str());
|
||||||
if (skel->skeleton.is_valid())
|
if (skel->skeleton.is_valid())
|
||||||
slot.skeleton = skel->skeleton;
|
slot.skeleton = skel->skeleton;
|
||||||
if (slot.skin.is_null() && !skel->skin.is_null())
|
if (slot.skin.is_null() && !skel->skin.is_null())
|
||||||
@@ -75,16 +72,16 @@ void Character::init_slot()
|
|||||||
slot.bound = true;
|
slot.bound = true;
|
||||||
e.add<ECS::Bound>();
|
e.add<ECS::Bound>();
|
||||||
parent.add<ECS::Bound>();
|
parent.add<ECS::Bound>();
|
||||||
// flecs::log::trace("bound slot for %s", e.name().c_str());
|
// flecs::log::trace("bound slot for %s", e.name().c_str());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
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>());
|
||||||
@@ -93,11 +90,11 @@ void Character::init_slot()
|
|||||||
if (skel->skin.is_null() && slot.skin_internal.is_null()) {
|
if (skel->skin.is_null() && slot.skin_internal.is_null()) {
|
||||||
const struct ECS::Skeleton::bone_data *bonesptr = skel->bones.ptr();
|
const struct ECS::Skeleton::bone_data *bonesptr = skel->bones.ptr();
|
||||||
const int *order = skel->process_order.ptr();
|
const int *order = skel->process_order.ptr();
|
||||||
// flecs::log::trace("binding slot for %s", e.name().c_str());
|
// flecs::log::trace("binding slot for %s", e.name().c_str());
|
||||||
slot.skin_internal.instance();
|
slot.skin_internal.instance();
|
||||||
slot.skin_internal->set_bind_count(skel->bones.size());
|
slot.skin_internal->set_bind_count(skel->bones.size());
|
||||||
int len = skel->bones.size();
|
int len = skel->bones.size();
|
||||||
// flecs::log::trace("creating skin for %s", e.name().c_str());
|
// flecs::log::trace("creating skin for %s", e.name().c_str());
|
||||||
for (i = 0; i < len; i++) {
|
for (i = 0; i < len; i++) {
|
||||||
const struct ECS::Skeleton::bone_data &b = bonesptr[order[i]];
|
const struct ECS::Skeleton::bone_data &b = bonesptr[order[i]];
|
||||||
if (b.parent >= 0)
|
if (b.parent >= 0)
|
||||||
@@ -110,7 +107,7 @@ void Character::init_slot()
|
|||||||
slot.skin_internal->set_bind_pose(i, slot.skin_internal->get_bind_pose(i).affine_inverse());
|
slot.skin_internal->set_bind_pose(i, slot.skin_internal->get_bind_pose(i).affine_inverse());
|
||||||
}
|
}
|
||||||
skel->skin = slot.skin_internal;
|
skel->skin = slot.skin_internal;
|
||||||
// flecs::log::trace("created skin for %s: %d", e.name().c_str(), len);
|
// flecs::log::trace("created skin for %s: %d", e.name().c_str(), len);
|
||||||
assert(skel->skeleton.is_valid());
|
assert(skel->skeleton.is_valid());
|
||||||
skel->skin = slot.skin_internal;
|
skel->skin = slot.skin_internal;
|
||||||
uint32_t bind_count = skel->skin->get_bind_count();
|
uint32_t bind_count = skel->skin->get_bind_count();
|
||||||
|
|||||||
@@ -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