Fix some more CObject interface issues

* fix mission 1.3
 * fix saving/loading missions
 * fix compile warnings
master
Piotr Dziwinski 2015-07-11 23:41:41 +02:00
parent 03717e11d4
commit fcbbbcb83c
10 changed files with 164 additions and 78 deletions

View File

@ -212,38 +212,50 @@ std::string ModelOutput::VectorToString(const Math::Vector& vector)
std::string ModelOutput::TransparentModeToString(ModelTransparentMode mode)
{
std::string str;
switch (mode)
{
case ModelTransparentMode::None:
return "none";
str = "none";
break;
case ModelTransparentMode::AlphaChannel:
return "alpha";
str = "alpha";
break;
case ModelTransparentMode::MapBlackToAlpha:
return "map_black";
str = "map_black";
break;
case ModelTransparentMode::MapWhiteToAlpha:
return "map_white";
str = "map_white";
break;
}
return str;
}
std::string ModelOutput::SpecialMarkToString(ModelSpecialMark specialMark)
{
std::string str;
switch (specialMark)
{
case ModelSpecialMark::None:
return "none";
str = "none";
break;
case ModelSpecialMark::Part1:
return "part1";
str = "part1";
break;
case ModelSpecialMark::Part2:
return "part2";
str = "part2";
break;
case ModelSpecialMark::Part3:
return "part3";
str = "part3";
break;
}
return str;
}
void ModelOutput::WriteBinaryModel(const CModel& model, std::ostream &stream)

View File

@ -1247,7 +1247,7 @@ void CAutoBase::FreezeCargo(bool freeze)
if ( obj == m_object ) continue; // yourself?
if (IsObjectBeingTransported(obj)) continue;
Math::Vector oPos = obj->GetPosition(0);
Math::Vector oPos = obj->GetPosition();
float dist = Math::DistanceProjected(m_pos, oPos);
if ( dist < 32.0f )
{

View File

@ -6,6 +6,9 @@
CObject::CObject(int id, ObjectType type)
: m_id(id)
, m_type(type)
, m_position(0.0f, 0.0f, 0.0f)
, m_rotation(0.0f, 0.0f, 0.0f)
, m_scale(1.0f, 1.0f, 1.0f)
{
m_implementedInterfaces.fill(false);
}
@ -52,6 +55,21 @@ std::vector<CrashSphere> CObject::GetAllCrashSpheres()
return allCrashSpheres;
}
Math::Vector CObject::GetPosition() const
{
return m_position;
}
Math::Vector CObject::GetRotation() const
{
return m_rotation;
}
Math::Vector CObject::GetScale() const
{
return m_scale;
}
int CObject::GetCrashSphereCount()
{
return m_crashSpheres.size();

View File

@ -85,6 +85,14 @@ public:
return m_implementedInterfaces[static_cast<int>(type)];
}
//! Returns current object's position
virtual Math::Vector GetPosition() const;
using COldObjectInterface::GetPosition;
//! Returns current object's rotation (Euler angles)
virtual Math::Vector GetRotation() const;
//! Returns current object's scale
virtual Math::Vector GetScale() const;
//! Sets crash spheres for object
void SetCrashSpheres(const std::vector<Gfx::ModelCrashSphere>& crashSpheres);
//! Adds a new crash sphere
@ -120,6 +128,9 @@ protected:
const int m_id; //!< unique identifier
ObjectType m_type; //!< object type
ObjectInterfaceTypes m_implementedInterfaces; //!< interfaces that the object implements
Math::Vector m_position;
Math::Vector m_rotation;
Math::Vector m_scale;
std::vector<CrashSphere> m_crashSpheres; //!< crash spheres
Math::Sphere m_cameraCollisionSphere;
};

View File

@ -1274,7 +1274,7 @@ void COldObject::SetPosition(int part, const Math::Vector &pos)
}
}
Math::Vector COldObject::GetPosition(int part)
Math::Vector COldObject::GetPosition(int part) const
{
return m_objectPart[part].position;
}
@ -1292,7 +1292,7 @@ void COldObject::SetAngle(int part, const Math::Vector &angle)
}
}
Math::Vector COldObject::GetAngle(int part)
Math::Vector COldObject::GetAngle(int part) const
{
return m_objectPart[part].angle;
}
@ -1366,7 +1366,7 @@ void COldObject::SetZoom(int part, Math::Vector zoom)
m_objectPart[part].zoom.z != 1.0f );
}
Math::Vector COldObject::GetZoom(int part)
Math::Vector COldObject::GetZoom(int part) const
{
return m_objectPart[part].zoom;
}
@ -3433,3 +3433,19 @@ void COldObject::DeleteDeselList(CObject* pObj)
m_totalDesectList = j;
}
Math::Vector COldObject::GetPosition() const
{
return GetPosition(0);
}
Math::Vector COldObject::GetRotation() const
{
return GetAngle(0);
}
Math::Vector COldObject::GetScale() const
{
return GetZoom(0);
}

View File

@ -126,9 +126,9 @@ public:
Math::Vector GetTilt() override;
void SetPosition(int part, const Math::Vector &pos) override;
Math::Vector GetPosition(int part) override;
Math::Vector GetPosition(int part) const override;
void SetAngle(int part, const Math::Vector &angle) override;
Math::Vector GetAngle(int part) override;
Math::Vector GetAngle(int part) const override;
void SetAngleY(int part, float angle) override;
void SetAngleX(int part, float angle) override;
void SetAngleZ(int part, float angle) override;
@ -137,7 +137,7 @@ public:
float GetAngleZ(int part) override;
void SetZoom(int part, float zoom) override;
void SetZoom(int part, Math::Vector zoom) override;
Math::Vector GetZoom(int part) override;
Math::Vector GetZoom(int part) const override;
void SetZoomX(int part, float zoom) override;
float GetZoomX(int part) override;
void SetZoomY(int part, float zoom) override;
@ -310,6 +310,10 @@ public:
void SetInfoReturn(float value) override;
float GetInfoReturn() override;
Math::Vector GetPosition() const override;
Math::Vector GetRotation() const override;
Math::Vector GetScale() const override;
protected:
bool EventFrame(const Event &event);
void VirusFrame(float rTime);

View File

@ -163,7 +163,7 @@ void COldObjectInterface::SetPosition(int part, const Math::Vector &pos)
throw std::logic_error("SetPosition: not implemented!");
}
Math::Vector COldObjectInterface::GetPosition(int part)
Math::Vector COldObjectInterface::GetPosition(int part) const
{
throw std::logic_error("GetPosition: not implemented!");
}
@ -173,7 +173,7 @@ void COldObjectInterface::SetAngle(int part, const Math::Vector &angle)
throw std::logic_error("SetAngle: not implemented!");
}
Math::Vector COldObjectInterface::GetAngle(int part)
Math::Vector COldObjectInterface::GetAngle(int part) const
{
throw std::logic_error("GetAngle: not implemented!");
}
@ -218,7 +218,7 @@ void COldObjectInterface::SetZoom(int part, Math::Vector zoom)
throw std::logic_error("SetZoom: not implemented!");
}
Math::Vector COldObjectInterface::GetZoom(int part)
Math::Vector COldObjectInterface::GetZoom(int part) const
{
throw std::logic_error("GetZoom: not implemented!");
}
@ -646,7 +646,9 @@ void COldObjectInterface::SetExploding(bool bExplo)
bool COldObjectInterface::IsExploding()
{
throw std::logic_error("IsExploding: not implemented!");
// TODO: temporary hack
return false;
//throw std::logic_error("IsExploding: not implemented!");
}
void COldObjectInterface::SetLock(bool bLock)
@ -663,12 +665,16 @@ bool COldObjectInterface::GetLock()
void COldObjectInterface::SetSpaceshipCargo(bool bCargo)
{
throw std::logic_error("SetSpaceshipCargo: not implemented!");
// TODO: temporary hack
return;
//throw std::logic_error("SetSpaceshipCargo: not implemented!");
}
bool COldObjectInterface::IsSpaceshipCargo()
{
throw std::logic_error("IsSpaceshipCargo: not implemented!");
// TODO: temporary hack
return false;
//throw std::logic_error("IsSpaceshipCargo: not implemented!");
}
void COldObjectInterface::SetBurn(bool bBurn)
@ -678,7 +684,9 @@ void COldObjectInterface::SetBurn(bool bBurn)
bool COldObjectInterface::GetBurn()
{
throw std::logic_error("GetBurn: not implemented!");
// TODO: temporary hack
return false;
//throw std::logic_error("GetBurn: not implemented!");
}
void COldObjectInterface::SetDead(bool bDead)

View File

@ -112,9 +112,9 @@ public:
virtual Math::Vector GetTilt();
virtual void SetPosition(int part, const Math::Vector &pos);
virtual Math::Vector GetPosition(int part);
virtual Math::Vector GetPosition(int part) const;
virtual void SetAngle(int part, const Math::Vector &angle);
virtual Math::Vector GetAngle(int part);
virtual Math::Vector GetAngle(int part) const;
virtual void SetAngleY(int part, float angle);
virtual void SetAngleX(int part, float angle);
virtual void SetAngleZ(int part, float angle);
@ -123,7 +123,7 @@ public:
virtual float GetAngleZ(int part);
virtual void SetZoom(int part, float zoom);
virtual void SetZoom(int part, Math::Vector zoom);
virtual Math::Vector GetZoom(int part);
virtual Math::Vector GetZoom(int part) const;
virtual void SetZoomX(int part, float zoom);
virtual float GetZoomX(int part);
virtual void SetZoomY(int part, float zoom);

View File

@ -2546,9 +2546,12 @@ void CRobotMain::AbortMovie()
{
for (CObject* obj : m_objMan->GetAllObjects())
{
CAuto* automat = obj->GetAuto();
if (automat != 0)
automat->Abort();
if (obj->Implements(ObjectInterfaceType::Old))
{
CAuto* automat = obj->GetAuto();
if (automat != 0)
automat->Abort();
}
}
m_app->SetMouseMode(MOUSE_ENGINE);
@ -4831,38 +4834,42 @@ void CRobotMain::IOWriteObject(CLevelParserLine* line, CObject* obj)
line->AddParam("type", CLevelParserParamUPtr{new CLevelParserParam(obj->GetType())});
line->AddParam("id", CLevelParserParamUPtr{new CLevelParserParam(obj->GetID())});
line->AddParam("pos", CLevelParserParamUPtr{new CLevelParserParam(obj->GetPosition(0)/g_unit)});
line->AddParam("angle", CLevelParserParamUPtr{new CLevelParserParam(obj->GetAngle(0)/(Math::PI/180.0f))});
line->AddParam("zoom", CLevelParserParamUPtr{new CLevelParserParam(obj->GetZoom(0))});
line->AddParam("pos", CLevelParserParamUPtr{new CLevelParserParam(obj->GetPosition()/g_unit)});
line->AddParam("angle", CLevelParserParamUPtr{new CLevelParserParam(obj->GetRotation() * Math::RAD_TO_DEG)});
line->AddParam("zoom", CLevelParserParamUPtr{new CLevelParserParam(obj->GetScale())});
Math::Vector pos;
for (int i = 1; i < OBJECTMAXPART; i++)
if (obj->Implements(ObjectInterfaceType::Old))
{
if (obj->GetObjectRank(i) == -1) continue;
pos = obj->GetPosition(i);
if (pos.x != 0.0f || pos.y != 0.0f || pos.z != 0.0f)
Math::Vector pos;
for (int i = 1; i < OBJECTMAXPART; i++)
{
pos /= g_unit;
line->AddParam("p" + boost::lexical_cast<std::string>(i), CLevelParserParamUPtr{new CLevelParserParam(pos)});
if (obj->GetObjectRank(i) == -1) continue;
pos = obj->GetPosition(i);
if (pos.x != 0.0f || pos.y != 0.0f || pos.z != 0.0f)
{
pos /= g_unit;
line->AddParam("p" + boost::lexical_cast<std::string>(i), CLevelParserParamUPtr{new CLevelParserParam(pos)});
}
pos = obj->GetAngle(i);
if (pos.x != 0.0f || pos.y != 0.0f || pos.z != 0.0f)
{
pos /= (Math::PI/180.0f);
line->AddParam("a" + boost::lexical_cast<std::string>(i), CLevelParserParamUPtr{new CLevelParserParam(pos)});
}
pos = obj->GetZoom(i);
if (pos.x != 1.0f || pos.y != 1.0f || pos.z != 1.0f)
{
line->AddParam("z" + boost::lexical_cast<std::string>(i), CLevelParserParamUPtr{new CLevelParserParam(pos)});
}
}
pos = obj->GetAngle(i);
if (pos.x != 0.0f || pos.y != 0.0f || pos.z != 0.0f)
{
pos /= (Math::PI/180.0f);
line->AddParam("a" + boost::lexical_cast<std::string>(i), CLevelParserParamUPtr{new CLevelParserParam(pos)});
}
pos = obj->GetZoom(i);
if (pos.x != 1.0f || pos.y != 1.0f || pos.z != 1.0f)
{
line->AddParam("z" + boost::lexical_cast<std::string>(i), CLevelParserParamUPtr{new CLevelParserParam(pos)});
}
line->AddParam("trainer", CLevelParserParamUPtr{new CLevelParserParam(obj->GetTrainer())});
line->AddParam("option", CLevelParserParamUPtr{new CLevelParserParam(obj->GetOption())});
}
line->AddParam("trainer", CLevelParserParamUPtr{new CLevelParserParam(obj->GetTrainer())});
line->AddParam("option", CLevelParserParamUPtr{new CLevelParserParam(obj->GetOption())});
if (obj == m_infoObject)
line->AddParam("select", CLevelParserParamUPtr{new CLevelParserParam(1)});
@ -5036,33 +5043,37 @@ CObject* CRobotMain::IOReadObject(CLevelParserLine *line, const char* filename,
int option = line->GetParam("option")->AsInt(0);
CObject* obj = m_objMan->CreateObject(pos, dir.y, type, 0.0f, 1.0f, 0.0f, trainer, toy, option, id);
obj->SetDefRank(objRank);
obj->SetPosition(0, pos);
obj->SetAngle(0, dir);
if (zoom.x != 0.0f || zoom.y != 0.0f || zoom.z != 0.0f)
obj->SetZoom(0, zoom);
for (int i = 1; i < OBJECTMAXPART; i++)
if (obj->Implements(ObjectInterfaceType::Old))
{
if (obj->GetObjectRank(i) == -1) continue;
obj->SetDefRank(objRank);
obj->SetPosition(0, pos);
obj->SetAngle(0, dir);
pos = line->GetParam(std::string("p")+boost::lexical_cast<std::string>(i))->AsPoint(Math::Vector());
if (pos.x != 0.0f || pos.y != 0.0f || pos.z != 0.0f)
{
obj->SetPosition(i, pos*g_unit);
}
dir = line->GetParam(std::string("a")+boost::lexical_cast<std::string>(i))->AsPoint(Math::Vector());
if (dir.x != 0.0f || dir.y != 0.0f || dir.z != 0.0f)
{
obj->SetAngle(i, dir*(Math::PI/180.0f));
}
zoom = line->GetParam(std::string("z")+boost::lexical_cast<std::string>(i))->AsPoint(Math::Vector());
if (zoom.x != 0.0f || zoom.y != 0.0f || zoom.z != 0.0f)
obj->SetZoom(0, zoom);
for (int i = 1; i < OBJECTMAXPART; i++)
{
obj->SetZoom(i, zoom);
if (obj->GetObjectRank(i) == -1) continue;
pos = line->GetParam(std::string("p")+boost::lexical_cast<std::string>(i))->AsPoint(Math::Vector());
if (pos.x != 0.0f || pos.y != 0.0f || pos.z != 0.0f)
{
obj->SetPosition(i, pos*g_unit);
}
dir = line->GetParam(std::string("a")+boost::lexical_cast<std::string>(i))->AsPoint(Math::Vector());
if (dir.x != 0.0f || dir.y != 0.0f || dir.z != 0.0f)
{
obj->SetAngle(i, dir*(Math::PI/180.0f));
}
zoom = line->GetParam(std::string("z")+boost::lexical_cast<std::string>(i))->AsPoint(Math::Vector());
if (zoom.x != 0.0f || zoom.y != 0.0f || zoom.z != 0.0f)
{
obj->SetZoom(i, zoom);
}
}
}
@ -5173,10 +5184,13 @@ CObject* CRobotMain::IOReadScene(const char *filename, const char *filecbot)
{
if (IsObjectBeingTransported(obj)) continue;
objRank = obj->GetDefRank();
if (objRank == -1) continue;
if (obj->Implements(ObjectInterfaceType::Programmable))
{
objRank = obj->GetDefRank();
if (objRank == -1) continue;
LoadFileScript(obj, filename, objRank, nbError);
LoadFileScript(obj, filename, objRank, nbError);
}
}
}
while (nbError > 0 && nbError != lastError);

View File

@ -48,6 +48,9 @@ CStaticObject::CStaticObject(int id,
const Gfx::CModelMesh* mesh = model.GetMesh("main");
assert(mesh != nullptr);
m_position = position;
m_rotation.y = angleY;
Math::Matrix worldMatrix = ComputeWorldMatrix(position, angleY);
m_meshHandle = m_engine->AddStaticMesh(key, mesh, worldMatrix);