mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-22 18:26:12 +08:00
[cpp] Fixed memory allocations at runtime.
This commit is contained in:
parent
906c0b4b60
commit
bceee601ad
@ -97,7 +97,7 @@ namespace Spine {
|
|||||||
Vector<float> _lengths;
|
Vector<float> _lengths;
|
||||||
Vector<float> _segments;
|
Vector<float> _segments;
|
||||||
|
|
||||||
Vector<float> computeWorldPositions(PathAttachment& path, int spacesCount, bool tangents, bool percentPosition, bool percentSpacing);
|
Vector<float>& computeWorldPositions(PathAttachment& path, int spacesCount, bool tangents, bool percentPosition, bool percentSpacing);
|
||||||
|
|
||||||
static void addBeforePosition(float p, Vector<float>& temp, int i, Vector<float>& output, int o);
|
static void addBeforePosition(float p, Vector<float>& temp, int i, Vector<float>& output, int o);
|
||||||
|
|
||||||
|
|||||||
@ -52,7 +52,10 @@ public:
|
|||||||
int _slotIndex;
|
int _slotIndex;
|
||||||
String _name;
|
String _name;
|
||||||
|
|
||||||
explicit AttachmentKey(int slotIndex = 0, const String &name = "");
|
explicit AttachmentKey(int slotIndex = 0, const String &name = 0);
|
||||||
|
|
||||||
|
// Used in Skin::getAttachment to avoid allocation of temporary string
|
||||||
|
explicit AttachmentKey(int slotIndex, const char* name);
|
||||||
|
|
||||||
AttachmentKey(const AttachmentKey &other) {
|
AttachmentKey(const AttachmentKey &other) {
|
||||||
this->_slotIndex = other._slotIndex;
|
this->_slotIndex = other._slotIndex;
|
||||||
@ -60,6 +63,14 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool operator==(const AttachmentKey &other) const;
|
bool operator==(const AttachmentKey &other) const;
|
||||||
|
|
||||||
|
int getSlotIndex() {
|
||||||
|
return _slotIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
String& getName() {
|
||||||
|
return _name;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct HashAttachmentKey : public SpineObject {
|
struct HashAttachmentKey : public SpineObject {
|
||||||
|
|||||||
@ -100,13 +100,18 @@ public:
|
|||||||
|
|
||||||
if (!chars) {
|
if (!chars) {
|
||||||
_length = 0;
|
_length = 0;
|
||||||
_buffer = 0;
|
_buffer = NULL;
|
||||||
} else {
|
} else {
|
||||||
_length = strlen(chars);
|
_length = strlen(chars);
|
||||||
_buffer = (char *) chars;
|
_buffer = (char *) chars;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void unown() {
|
||||||
|
_length = 0;
|
||||||
|
_buffer = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
String &operator=(const String &other) {
|
String &operator=(const String &other) {
|
||||||
if (this == &other) return *this;
|
if (this == &other) return *this;
|
||||||
if (_buffer) {
|
if (_buffer) {
|
||||||
|
|||||||
@ -676,7 +676,7 @@ void AnimationState::applyRotateTimeline(RotateTimeline *rotateTimeline, Skeleto
|
|||||||
}
|
}
|
||||||
|
|
||||||
Bone *bone = skeleton._bones[rotateTimeline->_boneIndex];
|
Bone *bone = skeleton._bones[rotateTimeline->_boneIndex];
|
||||||
Vector<float> frames = rotateTimeline->_frames;
|
Vector<float>& frames = rotateTimeline->_frames;
|
||||||
if (time < frames[0]) {
|
if (time < frames[0]) {
|
||||||
if (pose == MixPose_Setup) {
|
if (pose == MixPose_Setup) {
|
||||||
bone->_rotation = bone->_data._rotation;
|
bone->_rotation = bone->_data._rotation;
|
||||||
|
|||||||
@ -125,7 +125,7 @@ void PathConstraint::update() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector<float> positions = computeWorldPositions(*attachment, spacesCount, tangents,
|
Vector<float>& positions = computeWorldPositions(*attachment, spacesCount, tangents,
|
||||||
data.getPositionMode() == PositionMode_Percent,
|
data.getPositionMode() == PositionMode_Percent,
|
||||||
spacingMode == SpacingMode_Percent);
|
spacingMode == SpacingMode_Percent);
|
||||||
float boneX = positions[0];
|
float boneX = positions[0];
|
||||||
@ -254,7 +254,7 @@ PathConstraintData &PathConstraint::getData() {
|
|||||||
return _data;
|
return _data;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector<float>
|
Vector<float>&
|
||||||
PathConstraint::computeWorldPositions(PathAttachment &path, int spacesCount, bool tangents, bool percentPosition,
|
PathConstraint::computeWorldPositions(PathAttachment &path, int spacesCount, bool tangents, bool percentPosition,
|
||||||
bool percentSpacing) {
|
bool percentSpacing) {
|
||||||
Slot &target = *_target;
|
Slot &target = *_target;
|
||||||
|
|||||||
@ -39,6 +39,11 @@
|
|||||||
|
|
||||||
using namespace Spine;
|
using namespace Spine;
|
||||||
|
|
||||||
|
Skin::AttachmentKey::AttachmentKey(int slotIndex, const char* name) :
|
||||||
|
_slotIndex(slotIndex),
|
||||||
|
_name(name, true) {
|
||||||
|
}
|
||||||
|
|
||||||
Skin::AttachmentKey::AttachmentKey(int slotIndex, const String &name) :
|
Skin::AttachmentKey::AttachmentKey(int slotIndex, const String &name) :
|
||||||
_slotIndex(slotIndex),
|
_slotIndex(slotIndex),
|
||||||
_name(name) {
|
_name(name) {
|
||||||
@ -71,10 +76,13 @@ void Skin::addAttachment(int slotIndex, const String &name, Attachment *attachme
|
|||||||
}
|
}
|
||||||
|
|
||||||
Attachment *Skin::getAttachment(int slotIndex, const String &name) {
|
Attachment *Skin::getAttachment(int slotIndex, const String &name) {
|
||||||
AttachmentKey key(slotIndex, name);
|
AttachmentKey key(slotIndex, name.buffer());
|
||||||
if (_attachments.containsKey(key)) {
|
if (_attachments.containsKey(key)) {
|
||||||
return _attachments[key];
|
Attachment *attachment = _attachments[key];
|
||||||
|
key.getName().unown();
|
||||||
|
return attachment;
|
||||||
} else {
|
} else {
|
||||||
|
key.getName().unown();
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user