Skip to content

Commit 7d86739

Browse files
committed
Fixed Lua bindings not returning NULL pointer members in C++ classes properly, added a Lua-accessible vector multiply method to Matrix4, added an option to disable animations in a specific skeleton bone, fixed SceneLabel saving in entity editor broken in previous commit, minor 3d physics bugfixes, fixed bounding box calculation bug in Mesh introduced by recent mesh changes
1 parent d50a95e commit 7d86739

File tree

8 files changed

+46
-13
lines changed

8 files changed

+46
-13
lines changed

Bindings/Scripts/create_lua_library/create_lua_library.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def mkdir_p(path): # Same effect as mkdir -p, create dir and all necessary paren
1616
else: raise
1717

1818
def template_returnPtrLookupArray(prefix, className, ptr):
19-
out = ""
19+
out = "%sif %s == nil then return nil end\n" % (prefix, ptr)
2020
out += "%sfor i=1,count(%s) do\n" % (prefix, ptr)
2121
out += "%s\tlocal __c = _G[%s](\"__skip_ptr__\")\n" % (prefix, className.replace("*", ""))
2222
out += "%s\t__c.__ptr = %s[i]\n" % (prefix, ptr)
@@ -27,7 +27,7 @@ def template_returnPtrLookupArray(prefix, className, ptr):
2727

2828
# Note we expect className to be a valid string
2929
def template_returnPtrLookup(prefix, className, ptr):
30-
out = ""
30+
out = "%sif %s == nil then return nil end\n" % (prefix, ptr)
3131
out += "%slocal __c = _G[%s](\"__skip_ptr__\")\n" % (prefix, className.replace("*", ""))
3232
out += "%s__c.__ptr = %s\n" % (prefix, ptr)
3333
out += "%sreturn __c\n" % (prefix)
@@ -319,8 +319,12 @@ def createLUABindings(inputPath, prefix, mainInclude, libSmallName, libName, api
319319
wrappersHeaderOut += "\t%s(L, inst->%s%s);\n" % (outfunc, pp["name"], retFunc)
320320
else:
321321
if pp["type"].find("*") != -1:
322-
wrappersHeaderOut += "\tPolyBase **userdataPtr = (PolyBase**)lua_newuserdata(L, sizeof(PolyBase*));\n"
323-
wrappersHeaderOut += "\t*userdataPtr = (PolyBase*)inst->%s%s;\n" % (pp["name"], retFunc)
322+
wrappersHeaderOut += "\tif(!inst->%s%s) {\n" % (pp["name"], retFunc)
323+
wrappersHeaderOut += "\t\tlua_pushnil(L);\n"
324+
wrappersHeaderOut += "\t} else {\n"
325+
wrappersHeaderOut += "\t\tPolyBase **userdataPtr = (PolyBase**)lua_newuserdata(L, sizeof(PolyBase*));\n"
326+
wrappersHeaderOut += "\t\t*userdataPtr = (PolyBase*)inst->%s%s;\n" % (pp["name"], retFunc)
327+
wrappersHeaderOut += "\t}\n"
324328
else:
325329
wrappersHeaderOut += "\tPolyBase **userdataPtr = (PolyBase**)lua_newuserdata(L, sizeof(PolyBase*));\n"
326330
wrappersHeaderOut += "\t*userdataPtr = (PolyBase*)&inst->%s%s;\n" % (pp["name"], retFunc)
@@ -731,7 +735,6 @@ def createLUABindings(inputPath, prefix, mainInclude, libSmallName, libName, api
731735
if basicType == True: # Yes, a primitive
732736
luaClassBindingOut += "\treturn retVal\n"
733737
else: # Yes, a pointer was returned
734-
luaClassBindingOut += "\tif retVal == nil then return nil end\n"
735738
if vectorReturn == True:
736739
className = vectorReturnClass.replace("*", "")
737740
luaClassBindingOut += template_returnPtrLookupArray("\t",template_quote(className),"retVal")

Core/Contents/Include/PolyBone.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ namespace Polycode {
156156
Vector3 baseScale;
157157
Vector3 basePosition;
158158

159+
bool disableAnimation;
160+
159161
protected:
160162
Bone* parentBone;
161163
std::vector<Bone*> childBones;

Core/Contents/Include/PolyMatrix4.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,16 @@ namespace Polycode {
129129
n*m[3][0], n*m[3][1], n*m[3][2], n*m[3][3]);
130130
}
131131

132+
inline Vector3 multVector( const Vector3 &v2 ) const
133+
{
134+
return Vector3(v2.x*m[0][0] + v2.y*m[1][0] + v2.z*m[2][0] + m[3][0],
135+
v2.x*m[0][1] + v2.y*m[1][1] + v2.z*m[2][1] + m[3][1],
136+
v2.x*m[0][2] + v2.y*m[1][2] + v2.z*m[2][2] + m[3][2]);
137+
}
138+
132139
inline Vector3 operator * ( const Vector3 &v2 ) const
133140
{
134-
return Vector3(v2.x*m[0][0] + v2.y*m[1][0] + v2.z*m[2][0] + m[3][0],
135-
v2.x*m[0][1] + v2.y*m[1][1] + v2.z*m[2][1] + m[3][1],
136-
v2.x*m[0][2] + v2.y*m[1][2] + v2.z*m[2][2] + m[3][2]);
141+
return multVector(v2);
137142
}
138143

139144
inline Number* operator [] ( int row ) { return m[row];}

Core/Contents/Source/PolyBone.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Bone::Bone(const String& boneName) : Entity() {
3333
this->boneName = boneName;
3434
parentBone = NULL;
3535
boneMatrix.identity();
36+
disableAnimation = false;
3637
}
3738

3839
Bone::~Bone() {

Core/Contents/Source/PolyMesh.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -657,8 +657,8 @@ Vector3 Mesh::calculateBBox() {
657657

658658
for(int i=0; i < vertexPositionArray.data.size()-2; i += 3) {
659659
retVec.x = max(retVec.x,(Number)fabs(vertexPositionArray.data[i]));
660-
retVec.y = max(retVec.y,(Number)fabs(vertexPositionArray.data[i]+1));
661-
retVec.z = max(retVec.z,(Number)fabs(vertexPositionArray.data[i]+2));
660+
retVec.y = max(retVec.y,(Number)fabs(vertexPositionArray.data[i+1]));
661+
retVec.z = max(retVec.z,(Number)fabs(vertexPositionArray.data[i+2]));
662662
}
663663

664664
if(retVec.x == 0.0) {

Core/Contents/Source/PolySkeleton.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,11 @@ SkeletonAnimation *Skeleton::getAnimation(const String& name) const {
118118
void Skeleton::Update() {
119119

120120
for(int i=0; i < bones.size(); i++) {
121-
bones[i]->setRotationByQuaternion(bones[i]->baseRotation);
122-
bones[i]->setPosition(bones[i]->basePosition);
123-
bones[i]->setScale(bones[i]->baseScale);
121+
if(!bones[i]->disableAnimation) {
122+
bones[i]->setRotationByQuaternion(bones[i]->baseRotation);
123+
bones[i]->setPosition(bones[i]->basePosition);
124+
bones[i]->setScale(bones[i]->baseScale);
125+
}
124126
}
125127

126128
if(baseAnimation) {
@@ -440,6 +442,9 @@ void BoneTrack::Update(Number elapsed) {
440442
boneQuat = quatCurve->interpolate(time/length, true);
441443
}
442444

445+
if(targetBone->disableAnimation) {
446+
return;
447+
}
443448

444449
Quaternion rotationQuat = targetBone->getRotationQuat();
445450
rotationQuat = Quaternion::Slerp(weight, rotationQuat, boneQuat, true);

IDE/Contents/Source/PolycodeEntityEditor.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2254,6 +2254,19 @@ void PolycodeEntityEditor::saveEntityToObjectEntry(Entity *entity, ObjectEntry *
22542254

22552255
}
22562256

2257+
if(dynamic_cast<SceneLabel*>(entity)) {
2258+
SceneLabel *label = (SceneLabel*) entity;
2259+
2260+
if(!(*(entry))["type"])
2261+
entry->addChild("type", "SceneLabel");
2262+
ObjectEntry *labelEntry = entry->addChild("SceneLabel");
2263+
labelEntry->addChild("text", label->getText());
2264+
labelEntry->addChild("font", label->getLabel()->getFont()->getFontName());
2265+
labelEntry->addChild("size", (Number)label->getLabel()->getSize());
2266+
labelEntry->addChild("actualHeight", label->getLabelActualHeight());
2267+
labelEntry->addChild("aaMode", (int)label->getLabel()->getAntialiasMode());
2268+
}
2269+
22572270
if(dynamic_cast<SceneLight*>(entity)) {
22582271
SceneLight *light = (SceneLight*) entity;
22592272
if(!(*(entry))["type"]) {

Modules/Contents/3DPhysics/Source/PolyPhysicsScene.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ using namespace Polycode;
3535

3636
PhysicsSceneEvent::PhysicsSceneEvent() : Event () {
3737
eventType = "PhysicsSceneEvent";
38+
collisionEntityA = NULL;
39+
collisionEntityB = NULL;
40+
entityA = NULL;
41+
entityB = NULL;
3842
}
3943

4044
PhysicsSceneEvent::~PhysicsSceneEvent() {

0 commit comments

Comments
 (0)