Modify the sharing method of node changeFlag (#3746)

This commit is contained in:
GengineJS
2021-07-21 00:12:23 +08:00
committed by GitHub
parent 7a3cfdeab2
commit 274bb09165
4 changed files with 10 additions and 53 deletions
@@ -127,50 +127,6 @@ static bool js_scene_Model_setInstancedAttrBlock(se::State& s) // NOLINT(readabi
}
SE_BIND_FUNC(js_scene_Model_setInstancedAttrBlock) // NOLINT(readability-identifier-naming)
static bool js_scene_Node_initWithData(se::State& s) // NOLINT(readability-identifier-naming)
{
auto* cobj = static_cast<cc::scene::Node*>(s.nativeThisObject());
CC_UNUSED bool ok = true;
const auto& args = s.args();
size_t argc = args.size();
do {
if (argc == 1) {
SE_PRECONDITION2(args[0].isObject() && args[0].toObject()->isTypedArray(), false, "js_scene_Node_initWithData: expected Typed Array!");
uint8_t* data{nullptr};
size_t dataBytes = 0;
args[0].toObject()->getTypedArrayData(&data, &dataBytes);
cobj->initWithData(data);
return true;
}
} while (false);
SE_REPORT_ERROR("wrong number of arguments: %d", (int)argc);
return false;
}
SE_BIND_FUNC(js_scene_Node_initWithData) // NOLINT(readability-identifier-naming)
static bool js_scene_Pass_initWithData(se::State& s) // NOLINT(readability-identifier-naming)
{
auto* cobj = static_cast<cc::scene::Pass*>(s.nativeThisObject());
CC_UNUSED bool ok = true;
const auto& args = s.args();
size_t argc = args.size();
do {
if (argc == 1) {
SE_PRECONDITION2(args[0].isObject() && args[0].toObject()->isTypedArray(), false, "js_scene_Pass_initWithData: expected Typed Array!");
uint8_t* data{nullptr};
size_t dataBytes = 0;
args[0].toObject()->getTypedArrayData(&data, &dataBytes);
cobj->initWithData(data);
return true;
}
} while (false);
SE_REPORT_ERROR("wrong number of arguments: %d", (int)argc);
return false;
}
SE_BIND_FUNC(js_scene_Pass_initWithData) // NOLINT(readability-identifier-naming)
static bool js_scene_SubModel_setSubMeshBuffers(se::State& s) // NOLINT(readability-identifier-naming)
{
auto* cobj = static_cast<cc::scene::SubModel*>(s.nativeThisObject());
@@ -235,8 +191,6 @@ bool register_all_scene_manual(se::Object* obj) // NOLINT(readability-identifier
}
__jsb_cc_scene_Model_proto->defineFunction("setInstancedAttrBlock", _SE(js_scene_Model_setInstancedAttrBlock));
__jsb_cc_scene_Node_proto->defineFunction("initWithData", _SE(js_scene_Node_initWithData));
__jsb_cc_scene_Pass_proto->defineFunction("initWithData", _SE(js_scene_Pass_initWithData));
__jsb_cc_scene_SubModel_proto->defineFunction("setSubMeshBuffers", _SE(js_scene_SubModel_setSubMeshBuffers));
__jsb_cc_scene_Pass_proto->defineFunction("setRootBufferAndBlock", _SE(js_scene_Pass_setRootBufferAndBlock));
+3 -1
View File
@@ -100,8 +100,10 @@ void Node::updateWorldRTMatrix() {
Mat4::fromRT(_nodeLayout->worldRotation, _nodeLayout->worldPosition, &_rtMat);
}
void Node::initWithData(uint8_t *data) {
void Node::initWithData(uint8_t *data, uint8_t *flagChunk, uint32_t offset) {
_nodeLayout = reinterpret_cast<NodeLayout *>(data);
_flagChunk = flagChunk;
_flagOffest = offset;
}
} // namespace scene
+5 -4
View File
@@ -38,7 +38,6 @@ namespace scene {
// This struct defines the memory layout shared between JS and C++.
struct NodeLayout {
uint32_t dirtyFlag{0};
uint32_t flagsChanged{0};
uint32_t layer{0};
cc::Vec3 worldScale;
cc::Vec3 worldPosition;
@@ -58,7 +57,7 @@ public:
Node &operator=(const Node &) = delete;
Node &operator=(Node &&) = delete;
void initWithData(uint8_t *data);
void initWithData(uint8_t *, uint8_t *, uint32_t);
void updateWorldTransform();
void updateWorldRTMatrix();
@@ -66,7 +65,7 @@ public:
_parent = parent;
}
inline void setFlagsChanged(uint32_t value) { _nodeLayout->flagsChanged = value; }
inline void setFlagsChanged(uint32_t value) { *(reinterpret_cast<uint32_t *>(_flagChunk) + _flagOffest) = value; }
inline void setDirtyFlag(uint32_t value) { _nodeLayout->dirtyFlag = value; }
inline void setLayer(uint32_t layer) { _nodeLayout->layer = layer; }
inline void setWorldMatrix(const Mat4 &matrix) { _nodeLayout->worldMatrix.set(matrix); }
@@ -82,7 +81,7 @@ public:
inline void setLocalScale(const Vec3 &scale) { _nodeLayout->localScale.set(scale); }
inline Node * getParent() const { return _parent; }
inline uint32_t getFlagsChanged() const { return _nodeLayout->flagsChanged; }
inline uint32_t getFlagsChanged() const { return *(reinterpret_cast<uint32_t *>(_flagChunk) + _flagOffest); }
inline uint32_t getLayer() const { return _nodeLayout->layer; }
inline uint32_t getDirtyFlag() const { return _nodeLayout->dirtyFlag; }
inline const Vec3 & getPosition() const { return _nodeLayout->localPosition; }
@@ -99,6 +98,8 @@ private:
NodeLayout *_nodeLayout{nullptr};
Node * _parent{nullptr};
Mat4 _rtMat;
uint8_t * _flagChunk{nullptr};
uint32_t _flagOffest{0};
};
} // namespace scene
+2 -2
View File
@@ -43,11 +43,11 @@ classes = Light Node DirectionalLight SpotLight SphereLight Model SubModel Pass
skip = Model::[setInstancedAttrBlock getType getLocalBuffer getModelBounds getWorldBounds],
SubModel::[getDescriptorSet getInputAssembler getSubMesh setSubMeshBuffers],
Light::[getColor getColorTemperatureRGB getNode getType getUseColorTemperature],
Node::[getFlagsChanged getLayer getWorldMatrix getWorldPosition getWorldRotation getWorldScale initWithData setFlagsChanged setDirtyFlag setLayer setWorldMatrix setWorldPosition setWorldRotation setWorldScale setLocalPosition setLocalRotation setLocalScale getNodeLayout getWorldRT updateWorldTransform updateWorldRTMatrix getDirtyFlag getPosition getScale getRotation getParent],
Node::[getFlagsChanged getLayer getWorldMatrix getWorldPosition getWorldRotation getWorldScale setFlagsChanged setDirtyFlag setLayer setWorldMatrix setWorldPosition setWorldRotation setWorldScale setLocalPosition setLocalRotation setLocalScale getNodeLayout getWorldRT updateWorldTransform updateWorldRTMatrix getDirtyFlag getPosition getScale getRotation getParent],
DirectionalLight::[getDirection getIlluminance],
SpotLight::[getAABB getAngle getAspect getSpotAngle getDirection getFrustum getIlluminance getNeedUpdate getRange getPosition getSize],
SphereLight::[getAABB getIlluminance getPosition getRange getSize],
Pass::[initWithData setRootBufferAndBlock],
Pass::[setRootBufferAndBlock],
AABB::[getBoundary aabbAabb aabbFrustum aabbPlan merge transform transformExtentM4 setCenter getCenter setHalfExtents getHalfExtents set fromPoints],
SkinningModel::[updateTransform updateUBOs uploadJointData updateWorldMatrix],
Frustum::[update type],