Fixes several minor initialization issues that were causing problems with deletion/management of components and entities.

Also makes the ThirdPersonPlayer game object editor selectable again by removing an erroneously set field.
This commit is contained in:
Areloch 2016-05-31 12:51:23 -05:00
parent bbf7865a77
commit 2464b620ba
7 changed files with 46 additions and 9 deletions

View file

@ -149,6 +149,8 @@ bool AnimationComponent::onAdd()
void AnimationComponent::onRemove() void AnimationComponent::onRemove()
{ {
Parent::onRemove(); Parent::onRemove();
mOwnerRenderInst = NULL;
} }
void AnimationComponent::onComponentAdd() void AnimationComponent::onComponentAdd()
@ -387,7 +389,7 @@ S32 AnimationComponent::getThreadSequenceID(S32 slot)
void AnimationComponent::updateThread(Thread& st) void AnimationComponent::updateThread(Thread& st)
{ {
if (!mOwnerShapeInstance) if (!mOwnerRenderInst)
return; return;
switch (st.state) switch (st.state)
@ -628,7 +630,7 @@ void AnimationComponent::startSequenceSound(Thread& thread)
void AnimationComponent::advanceThreads(F32 dt) void AnimationComponent::advanceThreads(F32 dt)
{ {
if (!mOwnerShapeInstance) if (!mOwnerRenderInst)
return; return;
for (U32 i = 0; i < MaxScriptThreads; i++) for (U32 i = 0; i < MaxScriptThreads; i++)

View file

@ -92,6 +92,32 @@ void CameraOrbiterComponent::onComponentRemove()
Parent::onComponentRemove(); Parent::onComponentRemove();
} }
void CameraOrbiterComponent::componentAddedToOwner(Component *comp)
{
if (comp->getId() == getId())
return;
//test if this is a shape component!
CameraComponent *camComponent = dynamic_cast<CameraComponent*>(comp);
if (camComponent)
{
mCamera = camComponent;
}
}
void CameraOrbiterComponent::componentRemovedFromOwner(Component *comp)
{
if (comp->getId() == getId()) //?????????
return;
//test if this is a shape component!
CameraComponent *camComponent = dynamic_cast<CameraComponent*>(comp);
if (camComponent)
{
mCamera = NULL;
}
}
U32 CameraOrbiterComponent::packUpdate(NetConnection *con, U32 mask, BitStream *stream) U32 CameraOrbiterComponent::packUpdate(NetConnection *con, U32 mask, BitStream *stream)
{ {
U32 retMask = Parent::packUpdate(con, mask, stream); U32 retMask = Parent::packUpdate(con, mask, stream);

View file

@ -62,6 +62,9 @@ public:
virtual void onComponentAdd(); virtual void onComponentAdd();
virtual void onComponentRemove(); virtual void onComponentRemove();
virtual void componentAddedToOwner(Component *comp);
virtual void componentRemovedFromOwner(Component *comp);
virtual U32 packUpdate(NetConnection *con, U32 mask, BitStream *stream); virtual U32 packUpdate(NetConnection *con, U32 mask, BitStream *stream);
virtual void unpackUpdate(NetConnection *con, BitStream *stream); virtual void unpackUpdate(NetConnection *con, BitStream *stream);

View file

@ -69,6 +69,8 @@ PlayerControllerComponent::PlayerControllerComponent() : Component()
mFriction = 0.3f; mFriction = 0.3f;
mElasticity = 0.4f; mElasticity = 0.4f;
mMaxVelocity = 3000.f; mMaxVelocity = 3000.f;
mVelocity = VectorF::Zero;
mContactTimer = 0;
mSticky = false; mSticky = false;
mFalling = false; mFalling = false;
@ -88,7 +90,7 @@ PlayerControllerComponent::PlayerControllerComponent() : Component()
mDescription = getDescriptionText("A general-purpose physics player controller."); mDescription = getDescriptionText("A general-purpose physics player controller.");
mNetFlags.set(Ghostable | ScopeAlways); //mNetFlags.set(Ghostable | ScopeAlways);
mMass = 9.0f; // from ShapeBase mMass = 9.0f; // from ShapeBase
mDrag = 1.0f; // from ShapeBase mDrag = 1.0f; // from ShapeBase

View file

@ -53,6 +53,7 @@ MeshComponent::MeshComponent() : Component()
{ {
mShapeName = StringTable->insert(""); mShapeName = StringTable->insert("");
mShapeAsset = StringTable->insert(""); mShapeAsset = StringTable->insert("");
mShapeInstance = NULL;
mChangingMaterials.clear(); mChangingMaterials.clear();

View file

@ -405,8 +405,9 @@ U32 Entity::packUpdate(NetConnection *con, U32 mask, BitStream *stream)
//mathWrite( *stream, getScale() ); //mathWrite( *stream, getScale() );
//stream->writeAffineTransform(mObjToWorld); //stream->writeAffineTransform(mObjToWorld);
//mathWrite(*stream, getPosition()); //mathWrite(*stream, getPosition());
mathWrite(*stream, mPos); //mathWrite(*stream, mPos);
stream->writeCompressedPoint(mPos);
mathWrite(*stream, getRotation()); mathWrite(*stream, getRotation());
mDelta.move.pack(stream); mDelta.move.pack(stream);
@ -500,7 +501,8 @@ void Entity::unpackUpdate(NetConnection *con, BitStream *stream)
Point3F pos; Point3F pos;
mathRead(*stream, &pos); stream->readCompressedPoint(&pos);
//mathRead(*stream, &pos);
RotationF rot; RotationF rot;
@ -893,8 +895,10 @@ void Entity::setMountRotation(EulerF rotOffset)
void Entity::getCameraTransform(F32* pos, MatrixF* mat) void Entity::getCameraTransform(F32* pos, MatrixF* mat)
{ {
Vector<CameraInterface*> updaters = getComponents<CameraInterface>(); Vector<CameraInterface*> updaters = getComponents<CameraInterface>();
for (Vector<CameraInterface*>::iterator it = updaters.begin(); it != updaters.end(); it++) { for (Vector<CameraInterface*>::iterator it = updaters.begin(); it != updaters.end(); it++)
if ((*it)->getCameraTransform(pos, mat)) { {
if ((*it)->getCameraTransform(pos, mat))
{
return; return;
} }
} }
@ -1210,7 +1214,7 @@ void Entity::removeObject(SimObject* object)
bool Entity::addComponent(Component *comp) bool Entity::addComponent(Component *comp)
{ {
if (comp == NULL || !comp->isProperlyAdded()) if (comp == NULL)
return false; return false;
//double-check were not re-adding anything //double-check were not re-adding anything

View file

@ -1,6 +1,5 @@
<Entity <Entity
scale="1 1 1" scale="1 1 1"
isSelectionEnabled="false"
class="ThirdPersonPlayerObject" class="ThirdPersonPlayerObject"
canSave="true" canSave="true"
canSaveDynamicFields="true" canSaveDynamicFields="true"