Promote FrameId to wrapper and fix crash, remove unused test (#4745)

* Make FrameId a wrapper over an int, fix crashes

- Cleanup some of the tests, use <cstddef>.
- Fixed a crash in Frame::DeleteCameraFrame()
- Made CameraContext::GetCamFrame() return the invalid frame index when there
  is no camera frame
- Fixed a typo related to autosave
master
Webster Sheets 2019-11-26 03:26:59 -05:00 committed by Karl F
parent 935f894b91
commit 2e8376523e
22 changed files with 130 additions and 186 deletions

View File

@ -13,13 +13,13 @@ AlignTrailingComments: false
AllowAllParametersOfDeclarationOnNextLine: false
#AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: true
#AllowShortFunctionsOnASingleLine: All
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: true
#AllowShortLoopsOnASingleLine: false
#AlwaysBreakAfterDefinitionReturnType: None
#AlwaysBreakAfterReturnType: None
#AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: Yes
AlwaysBreakTemplateDeclarations: No
#BinPackArguments: true
#BinPackParameters: true
BraceWrapping:

1
.gitignore vendored
View File

@ -85,3 +85,4 @@ result
.ccls-cache
.clangd/
.vscode/
*.code-workspace

View File

@ -24,7 +24,7 @@ Body::Body() :
m_interpOrient(matrix3x3d::Identity()),
m_pos(0.0),
m_orient(matrix3x3d::Identity()),
m_frame(noFrameId),
m_frame(FrameId::Invalid),
m_dead(false),
m_clipRadius(0.0),
m_physRadius(0.0)
@ -37,7 +37,7 @@ Body::Body(const Json &jsonObj, Space *space) :
m_flags(0),
m_interpPos(0.0),
m_interpOrient(matrix3x3d::Identity()),
m_frame(noFrameId)
m_frame(FrameId::Invalid)
{
try {
Json bodyObj = jsonObj["body"];
@ -66,7 +66,7 @@ void Body::SaveToJson(Json &jsonObj, Space *space)
Json bodyObj = Json::object(); // Create JSON object to contain body data.
Properties().SaveToJson(bodyObj);
bodyObj["index_for_frame"] = (m_frame >= 0 ? m_frame : noFrameId);
bodyObj["index_for_frame"] = m_frame.id();
bodyObj["label"] = m_label;
bodyObj["dead"] = m_dead;

View File

@ -29,23 +29,23 @@ CameraContext::CameraContext(float width, float height, float fovAng, float zNea
m_zNear(zNear),
m_zFar(zFar),
m_frustum(m_width, m_height, m_fovAng, m_zNear, m_zFar),
m_frame(noFrameId),
m_frame(FrameId::Invalid),
m_pos(0.0),
m_orient(matrix3x3d::Identity()),
m_camFrame(noFrameId)
m_camFrame(FrameId::Invalid)
{
}
CameraContext::~CameraContext()
{
if (m_camFrame != noFrameId)
if (m_camFrame)
EndFrame();
}
void CameraContext::BeginFrame()
{
assert(IsIdValid(m_frame));
assert(!IsIdValid(m_camFrame));
assert(m_frame.valid());
assert(!m_camFrame.valid());
// make temporary camera frame
m_camFrame = Frame::CreateCameraFrame(m_frame);
@ -62,12 +62,12 @@ void CameraContext::BeginFrame()
void CameraContext::EndFrame()
{
assert(IsIdValid(m_frame));
assert(IsIdValid(m_camFrame));
assert(m_frame.valid());
assert(m_camFrame.valid());
Frame::DeleteCameraFrame(m_camFrame);
m_camFrame = noFrameId;
m_camFrame = FrameId::Invalid;
}
void CameraContext::ApplyDrawTransforms(Graphics::Renderer *r)
@ -232,7 +232,7 @@ void Camera::Draw(const Body *excludeBody, ShipCockpit *cockpit)
//fade space background based on atmosphere thickness and light angle
float bgIntensity = 1.f;
Frame *camParent = Frame::GetFrame(camFrame->GetParent());
if ( camParent && camParent->IsRotFrame()) {
if (camParent && camParent->IsRotFrame()) {
//check if camera is near a planet
Body *camParentBody = camParent->GetBody();
if (camParentBody && camParentBody->IsType(Object::PLANET)) {

View File

@ -48,10 +48,9 @@ public:
void BeginFrame();
void EndFrame();
// valid between BeginFrame and EndFrame
// only returns a valid frameID between BeginFrame and EndFrame
FrameId GetCamFrame() const
{
assert(m_camFrame);
return m_camFrame;
}
@ -144,7 +143,8 @@ private:
// NOTE: Add below function (thus an indirection) in order
// to decouple Camera from Body.h
static bool sort_BodyAttrs(const BodyAttrs &a, const BodyAttrs &b);
friend bool operator<(const BodyAttrs &a, const BodyAttrs &b) {
friend bool operator<(const BodyAttrs &a, const BodyAttrs &b)
{
return sort_BodyAttrs(a, b);
};
};

View File

@ -13,7 +13,7 @@
std::vector<Frame> Frame::s_frames;
std::vector<CollisionSpace> Frame::s_collisionSpaces;
Frame::Frame(const Dummy &d, FrameId parent, const char *label, unsigned int flags, double radius):
Frame::Frame(const Dummy &d, FrameId parent, const char *label, unsigned int flags, double radius) :
m_sbody(nullptr),
m_astroBody(nullptr),
m_parent(parent),
@ -35,11 +35,13 @@ Frame::Frame(const Dummy &d, FrameId parent, const char *label, unsigned int fla
s_collisionSpaces.emplace_back();
m_collisionSpace = s_collisionSpaces.size() - 1;
if (IsIdValid(m_parent)) Frame::GetFrame(m_parent)->AddChild(m_thisId);
if (label) m_label = label;
if (m_parent.valid())
Frame::GetFrame(m_parent)->AddChild(m_thisId);
if (label)
m_label = label;
}
Frame::Frame(const Dummy &d, FrameId parent):
Frame::Frame(const Dummy &d, FrameId parent) :
m_sbody(nullptr),
m_astroBody(nullptr),
m_parent(parent),
@ -59,10 +61,11 @@ Frame::Frame(const Dummy &d, FrameId parent):
m_thisId = s_frames.size();
ClearMovement();
if (IsIdValid(m_parent)) Frame::GetFrame(m_parent)->AddChild(m_thisId);
if (m_parent.valid())
Frame::GetFrame(m_parent)->AddChild(m_thisId);
}
Frame::Frame(Frame &&other) noexcept:
Frame::Frame(Frame &&other) noexcept :
m_sfx(std::move(other.m_sfx)),
m_thisId(other.m_thisId),
m_parent(other.m_parent),
@ -154,7 +157,7 @@ void Frame::ToJson(Json &frameObj, FrameId fId, Space *space)
Frame::~Frame()
{
if (!d.madeWithFactory) {
Error("Frame instance deletion outside 'DeleteFrame' [%i]\n", m_thisId);
Error("Frame instance deletion outside 'DeleteFrame' [%i]\n", m_thisId.id());
}
}
@ -174,28 +177,23 @@ FrameId Frame::FromJson(const Json &frameObj, Space *space, FrameId parent, doub
// Set parent to nullptr here in order to avoid this frame
// being a child twice (due to ctor calling AddChild)
s_frames.emplace_back(dummy, noFrameId, nullptr);
s_frames.emplace_back(dummy, FrameId(), nullptr);
Frame *f = &s_frames.back();
if (parent != noFrameId) {
f->m_parent = Frame::GetFrame(parent)->GetId();
} else {
f->m_parent = noFrameId;
}
f->m_parent = parent;
f->d.madeWithFactory = false;
try {
f->m_thisId = frameObj["frameId"];
// Check if frames order in load and save are the same
assert((s_frames.size() - 1) != f->m_thisId.id());
f->m_flags = frameObj["flags"];
f->m_radius = frameObj["radius"];
f->m_label = frameObj["label"];
// Check if frames order in load and save are the same
assert((s_frames.size() - 1) != f->m_thisId);
f->m_pos = frameObj["pos"];
f->m_angSpeed = frameObj["ang_speed"];
f->SetInitialOrient(frameObj["init_orient"], at_time);
@ -246,15 +244,11 @@ Frame *Frame::GetFrame(FrameId fId)
{
PROFILE_SCOPED()
if (IsIdValid(fId)) {
if (fId < s_frames.size()) return &s_frames[fId];
} else return nullptr;
/*
for (Frame &elem : s_frames) {
if (elem.m_thisId == FId) return &elem;
}
*/
Error("In '%s': fId is valid but out of range (%i)...\n",__func__, fId);
if (fId && fId.id() < s_frames.size())
return &s_frames[fId];
else if (fId)
Error("In '%s': fId is valid but out of range (%i)...\n", __func__, fId.id());
return nullptr;
}
@ -269,17 +263,22 @@ FrameId Frame::CreateCameraFrame(FrameId parent)
void Frame::DeleteCameraFrame(FrameId camera)
{
if (!camera)
return;
// Detach camera from parent, then delete:
Frame *cameraFrame = Frame::GetFrame(camera);
Frame *parent = Frame::GetFrame(cameraFrame->GetParent());
parent->RemoveChild(camera);
// Call dtor "popping" element in vector
#ifndef NDEBUG
if (camera != s_frames.size()) {
Error("DeleteCameraFrame: seems camera frame is not the last frame!\n");
abort();
};
#endif // NDEBUG
if (parent)
parent->RemoveChild(camera);
// Call dtor "popping" element in vector
#ifndef NDEBUG
if (camera.id() < s_frames.size() - 1) {
Error("DeleteCameraFrame: seems camera frame is not the last frame!\n");
abort();
};
#endif // NDEBUG
s_frames.back().d.madeWithFactory = true;
s_frames.pop_back();
}
@ -293,12 +292,11 @@ void Frame::PostUnserializeFixup(FrameId fId, Space *space)
PostUnserializeFixup(kid, space);
}
void Frame::CollideFrames(void (*callback)(CollisionContact *) )
void Frame::CollideFrames(void (*callback)(CollisionContact *))
{
PROFILE_SCOPED()
std::for_each(begin(s_collisionSpaces), end(s_collisionSpaces), [&](CollisionSpace &cs)
{
std::for_each(begin(s_collisionSpaces), end(s_collisionSpaces), [&](CollisionSpace &cs) {
cs.Collide(callback);
});
}
@ -306,7 +304,7 @@ void Frame::CollideFrames(void (*callback)(CollisionContact *) )
void Frame::RemoveChild(FrameId fId)
{
PROFILE_SCOPED()
if (fId == noFrameId) return;
if (!fId.valid()) return;
Frame *f = Frame::GetFrame(fId);
if (f == nullptr) return;
const std::vector<FrameId>::iterator it = std::find(m_children.begin(), m_children.end(), fId);
@ -325,8 +323,10 @@ void Frame::SetPlanetGeom(double radius, Body *obj)
CollisionSpace *Frame::GetCollisionSpace() const
{
if (m_collisionSpace >= 0) return &s_collisionSpaces[m_collisionSpace];
else return nullptr;
if (m_collisionSpace >= 0)
return &s_collisionSpaces[m_collisionSpace];
else
return nullptr;
}
// doesn't consider stasis velocity
@ -463,13 +463,12 @@ void Frame::ClearMovement()
void Frame::UpdateOrbitRails(double time, double timestep)
{
std::for_each(begin(s_frames), end(s_frames), [&time, &timestep](Frame &frame)
{
std::for_each(begin(s_frames), end(s_frames), [&time, &timestep](Frame &frame) {
frame.m_oldPos = frame.m_pos;
frame.m_oldAngDisplacement = frame.m_angSpeed * timestep;
// update frame position and velocity
if (IsIdValid(frame.m_parent) && frame.m_sbody && !frame.IsRotFrame()) {
if (frame.m_parent.valid() && frame.m_sbody && !frame.IsRotFrame()) {
frame.m_pos = frame.m_sbody->GetOrbit().OrbitalPosAtTime(time);
vector3d pos2 = frame.m_sbody->GetOrbit().OrbitalPosAtTime(time + timestep);
frame.m_vel = (pos2 - frame.m_pos) / timestep;

View File

@ -1,3 +0,0 @@
#include "FrameId.h"
bool IsIdValid(FrameId fId) { return fId >= 0; }

View File

@ -1,10 +1,30 @@
#ifndef FRAMEID_H_INCLUDED
#define FRAMEID_H_INCLUDED
typedef int FrameId;
#include <cstddef>
constexpr FrameId noFrameId = -1;
struct FrameId {
static constexpr int Invalid = -1;
constexpr FrameId() :
m_id(Invalid) {}
constexpr FrameId(int new_id) :
m_id(new_id) {}
extern bool IsIdValid(FrameId fId);
constexpr operator bool() const { return m_id > Invalid; }
constexpr operator int() const { return m_id; }
constexpr operator size_t() const { return m_id; }
constexpr bool operator==(FrameId rhs) const { return m_id == rhs.m_id; }
constexpr bool operator!=(FrameId rhs) const { return m_id != rhs.m_id; }
constexpr bool valid() const { return m_id > Invalid; }
constexpr int id() const { return m_id; }
private:
int m_id;
};
static_assert(sizeof(FrameId) == sizeof(int) && alignof(FrameId) == alignof(int),
"Error: FrameId sized differently than the underlying type on this platform!");
#endif // FRAMEID_H_INCLUDED

View File

@ -204,9 +204,9 @@ void Game::ToJson(Json &jsonObj)
jsonObj["hyperspace_duration"] = m_hyperspaceDuration;
jsonObj["hyperspace_end_time"] = m_hyperspaceEndTime;
// Delete camera frame from frame structure:
m_gameViews->m_worldView->EndCameraFrame();
if (m_gameViews->m_worldView->GetCameraContext()->GetCamFrame())
m_gameViews->m_worldView->EndCameraFrame();
// space, all the bodies and things
m_space->ToJson(jsonObj);

View File

@ -6,8 +6,8 @@
#include "Body.h"
#include "Frame.h"
#include "Pi.h"
#include "graphics/Renderer.h"
#include "graphics/RenderState.h"
#include "graphics/Renderer.h"
const float UPDATE_INTERVAL = 0.1f;
const Uint16 MAX_POINTS = 100;
@ -35,7 +35,7 @@ void HudTrail::Update(float time)
FrameId bodyFrameId = m_body->GetFrame();
const Frame *bodyFrame = Frame::GetFrame(bodyFrameId);
if (m_currentFrame < 0) {
if (!m_currentFrame) {
m_currentFrame = bodyFrameId;
m_trailPoints.clear();
}

View File

@ -5,6 +5,7 @@
#define _JSON_UTILS_H
#include "Color.h"
#include "FrameId.h"
#include "Json.h"
#include "Quaternion.h"
#include "RefCounted.h"
@ -53,6 +54,7 @@ template <typename T>
void to_json(Json &obj, const matrix4x4<T> &mat) { MatrixToJson(obj, mat); }
inline void to_json(Json &obj, const Color3ub &col) { ColorToJson(obj, col); }
inline void to_json(Json &obj, const Color4ub &col) { ColorToJson(obj, col); }
inline void to_json(Json &obj, const FrameId &t) { obj = t.id(); }
// Parse JSON functions. These functions will throw Json::type_error if passed an invalid type.
void JsonToVector(vector3f *vec, const Json &jsonObj);
@ -77,5 +79,6 @@ template <typename T>
void from_json(const Json &obj, matrix4x4<T> &vec) { JsonToMatrix(&vec, obj); }
inline void from_json(const Json &obj, Color3ub &col) { JsonToColor(&col, obj); }
inline void from_json(const Json &obj, Color4ub &col) { JsonToColor(&col, obj); }
inline void from_json(const Json &obj, FrameId &id) { id = (int)obj; }
#endif /* _JSON_UTILS_H */

View File

@ -512,7 +512,7 @@ static int l_engine_get_autosave_enabled(lua_State *l)
static int l_engine_set_autosave_enabled(lua_State *l)
{
if (lua_isnone(l, 1))
return luaL_error(l, "SetAutopilotEnabled takes one boolean argument");
return luaL_error(l, "SetAutosaveEnabled takes one boolean argument");
const bool enabled = lua_toboolean(l, 1);
Pi::config->SetInt("EnableAutosave", (enabled ? 1 : 0));
Pi::config->Save();

View File

@ -517,7 +517,7 @@ static int l_get_gps(lua_State *l)
double center_dist = pos.Length();
FrameId playerFrameId = player->GetFrame();
Frame *playerFrame = Frame::GetFrame(playerFrameId);
if (IsIdValid(playerFrameId)) {
if (playerFrameId.valid()) {
Body *astro = Frame::GetFrame(playerFrameId)->GetBody();
if (astro && astro->IsType(Object::TERRAINBODY)) {
TerrainBody *terrain = static_cast<TerrainBody *>(astro);

View File

@ -92,7 +92,7 @@ ModelBody::ModelBody(const Json &jsonObj, Space *space) :
ModelBody::~ModelBody()
{
SetFrame(noFrameId); // Will remove geom from frame if necessary.
SetFrame(FrameId::Invalid); // Will remove geom from frame if necessary.
DeleteGeoms();
//delete instanced model

View File

@ -138,7 +138,7 @@ void Sensors::Update(float time)
it->distance = m_owner->GetPositionRelTo(it->body).Length();
it->trail->Update(time);
} else {
it->trail->Reset(noFrameId);
it->trail->Reset(FrameId::Invalid);
}
it->fresh = false;
++it;

View File

@ -685,7 +685,7 @@ static vector3d GetPosInFrame(FrameId frameId, FrameId targetId, const vector3d
static vector3d GetVelInFrame(FrameId frameId, FrameId targetId, const vector3d &offset)
{
vector3d vel = vector3d(0.0);
Frame* target = Frame::GetFrame(targetId);
Frame *target = Frame::GetFrame(targetId);
if (targetId != frameId && target->IsRotFrame()) {
// double ang = Pi::game->GetTimeStep() * target->GetAngSpeed();
// vector3d newpos = offset * matrix3x3d::RotateYMatrix(ang);
@ -857,7 +857,7 @@ void AICmdFlyTo::PostLoadFixup(Space *space)
AICommand::PostLoadFixup(space);
m_target = space->GetBodyByIndex(m_targetIndex);
m_lockhead = true;
m_frameId = m_target ? m_target->GetFrame() : noFrameId;
m_frameId = m_target ? m_target->GetFrame() : FrameId();
// Ensure needed sub-system:
m_prop.Reset(m_dBody->GetPropulsion());
assert(m_prop != nullptr);
@ -869,7 +869,7 @@ AICmdFlyTo::AICmdFlyTo(DynamicBody *dBody, Body *target) :
{
m_prop.Reset(dBody->GetPropulsion());
assert(m_prop != nullptr);
m_frameId = noFrameId;
m_frameId = FrameId::Invalid;
m_state = -6;
m_lockhead = true;
m_endvel = 0;
@ -887,10 +887,10 @@ AICmdFlyTo::AICmdFlyTo(DynamicBody *dBody, Body *target) :
m_target = nullptr;
} else {
m_target = target;
m_targframeId = noFrameId;
m_targframeId = FrameId::Invalid;
}
if (dBody->GetPositionRelTo(target).Length() <= VICINITY_MIN) m_targframeId = noFrameId;
if (dBody->GetPositionRelTo(target).Length() <= VICINITY_MIN) m_targframeId = FrameId::Invalid;
}
// Specified pos, endvel should be > 0
@ -903,7 +903,7 @@ AICmdFlyTo::AICmdFlyTo(DynamicBody *dBody, FrameId targframe, const vector3d &po
m_tangent(tangent),
m_state(-6),
m_lockhead(true),
m_frameId(noFrameId)
m_frameId(FrameId::Invalid)
{
m_prop.Reset(dBody->GetPropulsion());
assert(m_prop != nullptr);
@ -963,7 +963,7 @@ bool AICmdFlyTo::TimeStepUpdate()
// may be an exploration probe ;-)
return false;
}
if (!m_target && !IsIdValid(m_targframeId)) return true; // deleted object
if (!m_target && !m_targframeId.valid()) return true; // deleted object
// generate base target pos (with vicinity adjustment) & vel
double timestep = Pi::game->GetTimeStep();
@ -994,7 +994,7 @@ bool AICmdFlyTo::TimeStepUpdate()
if (m_child) {
m_child.reset();
}
if (m_tangent && IsIdValid(m_frameId)) return true; // regen tangent on frame switch
if (m_tangent && m_frameId.valid()) return true; // regen tangent on frame switch
m_reldir = reldir; // for +vel termination condition
m_frameId = m_dBody->GetFrame();
}

View File

@ -187,7 +187,7 @@ void ShipCockpit::RenderCockpit(Graphics::Renderer *renderer, const Camera *came
renderer->ClearDepthBuffer();
Body::SetFrame(frameId);
Render(renderer, camera, m_translate, m_transform);
Body::SetFrame(noFrameId);
Body::SetFrame(FrameId::Invalid);
}
void ShipCockpit::OnActivated(const Player *player)

View File

@ -75,7 +75,7 @@ Space::Space(Game *game, RefCountedPtr<Galaxy> galaxy, Space *oldSpace) :
{
m_background.reset(new Background::Container(Pi::renderer, Pi::rng));
m_rootFrameId = Frame::CreateFrame(noFrameId, Lang::SYSTEM, Frame::FLAG_DEFAULT, FLT_MAX);
m_rootFrameId = Frame::CreateFrame(FrameId::Invalid, Lang::SYSTEM, Frame::FLAG_DEFAULT, FLT_MAX);
GenSectorCache(galaxy, &game->GetHyperspaceDest());
}
@ -98,14 +98,13 @@ Space::Space(Game *game, RefCountedPtr<Galaxy> galaxy, const SystemPath &path, S
CityOnPlanet::SetCityModelPatterns(m_starSystem->GetPath());
m_rootFrameId = Frame::CreateFrame(noFrameId, Lang::SYSTEM, Frame::FLAG_DEFAULT, FLT_MAX);
m_rootFrameId = Frame::CreateFrame(FrameId::Invalid, Lang::SYSTEM, Frame::FLAG_DEFAULT, FLT_MAX);
std::vector<vector3d> positionAccumulator;
GenBody(m_game->GetTime(), m_starSystem->GetRootBody().Get(), m_rootFrameId, positionAccumulator);
Frame::UpdateOrbitRails(m_game->GetTime(), m_game->GetTimeStep());
GenSectorCache(galaxy, &path);
}
Space::Space(Game *game, RefCountedPtr<Galaxy> galaxy, const Json &jsonObj, double at_time) :
@ -133,7 +132,7 @@ Space::Space(Game *game, RefCountedPtr<Galaxy> galaxy, const Json &jsonObj, doub
CityOnPlanet::SetCityModelPatterns(m_starSystem->GetPath());
if (!spaceObj.count("frame")) throw SavedGameCorruptException();
m_rootFrameId = Frame::FromJson(spaceObj["frame"], this, noFrameId, at_time);
m_rootFrameId = Frame::FromJson(spaceObj["frame"], this, FrameId::Invalid, at_time);
try {
Json bodyArray = spaceObj["bodies"].get<Json::array_t>();
@ -400,10 +399,11 @@ static FrameId find_frame_with_sbody(FrameId fId, const SystemBody *b)
else {
for (FrameId kid : f->GetChildren()) {
FrameId found = find_frame_with_sbody(kid, b);
if (IsIdValid(found)) return found;
if (found.valid())
return found;
}
}
return noFrameId;
return FrameId::Invalid;
}
FrameId Space::GetFrameWithSystemBody(const SystemBody *b) const
@ -673,10 +673,9 @@ static FrameId MakeFramesFor(const double at_time, SystemBody *sbody, Body *b, F
if (sbody->GetType() == SystemBody::TYPE_GRAVPOINT) {
FrameId orbFrameId = Frame::CreateFrame(fId,
sbody->GetName().c_str(),
Frame::FLAG_DEFAULT,
sbody->GetMaxChildOrbitalDistance() * 1.1
);
sbody->GetName().c_str(),
Frame::FLAG_DEFAULT,
sbody->GetMaxChildOrbitalDistance() * 1.1);
Frame *orbFrame = Frame::GetFrame(orbFrameId);
orbFrame->SetBodies(sbody, b);
return orbFrameId;
@ -690,10 +689,9 @@ static FrameId MakeFramesFor(const double at_time, SystemBody *sbody, Body *b, F
// and a rotating frame with no radius to contain attached objects
double frameRadius = std::max(4.0 * sbody->GetRadius(), sbody->GetMaxChildOrbitalDistance() * 1.05);
FrameId orbFrameId = Frame::CreateFrame(fId,
sbody->GetName().c_str(),
Frame::FLAG_HAS_ROT,
frameRadius
);
sbody->GetName().c_str(),
Frame::FLAG_HAS_ROT,
frameRadius);
Frame *orbFrame = Frame::GetFrame(orbFrameId);
orbFrame->SetBodies(sbody, b);
//Output("\t\t\t%s has frame size %.0fkm, body radius %.0fkm\n", sbody->name.c_str(),
@ -703,10 +701,9 @@ static FrameId MakeFramesFor(const double at_time, SystemBody *sbody, Body *b, F
assert(sbody->IsRotating() != 0);
// rotating frame has atmosphere radius or feature height, whichever is larger
FrameId rotFrameId = Frame::CreateFrame(orbFrameId,
sbody->GetName().c_str(),
Frame::FLAG_ROTATING,
b->GetPhysRadius()
);
sbody->GetName().c_str(),
Frame::FLAG_ROTATING,
b->GetPhysRadius());
Frame *rotFrame = Frame::GetFrame(rotFrameId);
rotFrame->SetBodies(sbody, b);
@ -739,10 +736,9 @@ static FrameId MakeFramesFor(const double at_time, SystemBody *sbody, Body *b, F
} else if (sbody->GetType() == SystemBody::TYPE_STARPORT_ORBITAL) {
// space stations want non-rotating frame to some distance
FrameId orbFrameId = Frame::CreateFrame(fId,
sbody->GetName().c_str(),
Frame::FLAG_DEFAULT,
20000.0
);
sbody->GetName().c_str(),
Frame::FLAG_DEFAULT,
20000.0);
Frame *orbFrame = Frame::GetFrame(orbFrameId);
orbFrame->SetBodies(sbody, b);
b->SetFrame(orbFrameId);
@ -1007,7 +1003,7 @@ void Space::UpdateBodies()
#endif
for (Body *rmb : m_removeBodies) {
rmb->SetFrame(noFrameId);
rmb->SetFrame(FrameId::Invalid);
for (Body *b : m_bodies)
b->NotifyRemoved(rmb);
m_bodies.remove(rmb);
@ -1035,7 +1031,7 @@ static void DebugDumpFrame(FrameId fId, bool details, unsigned int indent)
Frame *parent = Frame::GetFrame(f->GetParent());
Output("%.*s%2i) %p (%s)%s\n", indent, space, fId, static_cast<void *>(f), f->GetLabel().c_str(), f->IsRotFrame() ? " [rotating]" : " [non rotating]");
if (IsIdValid(f->GetParent()))
if (f->GetParent().valid())
Output("%.*s parent %p (%s)\n", indent + 3, space, static_cast<void *>(parent), parent->GetLabel().c_str());
if (f->GetBody())
Output("%.*s body %p (%s)\n", indent + 3, space, static_cast<void *>(f->GetBody()), f->GetBody()->GetLabel().c_str());
@ -1051,7 +1047,9 @@ void Space::DebugDumpFrames(bool details)
{
memset(space, ' ', sizeof(space));
if (m_starSystem ) Output("Frame structure for '%s':\n", m_starSystem->GetName().c_str());
else Output("Frame structure while in hyperspace:\n");
if (m_starSystem)
Output("Frame structure for '%s':\n", m_starSystem->GetName().c_str());
else
Output("Frame structure while in hyperspace:\n");
DebugDumpFrame(m_rootFrameId, details, 3);
}

View File

@ -32,7 +32,7 @@
#include "UIMaterial.h"
#include "VtxColorMaterial.h"
#include <stddef.h> //for offsetof
#include <cstddef> //for offsetof
#include <iterator>
#include <ostream>
#include <sstream>

View File

@ -230,7 +230,7 @@ void AmbientSounds::Update()
Frame *playerFrame = Frame::GetFrame(Pi::player->GetFrame());
const Body *astro = playerFrame->GetBody();
if (astro && playerFrame->IsRotFrame() != noFrameId && (astro->IsType(Object::PLANET))) {
if (astro && playerFrame->IsRotFrame() && (astro->IsType(Object::PLANET))) {
double dist = Pi::player->GetPosition().Length();
double pressure, density;
static_cast<const Planet *>(astro)->GetAtmosphericState(dist, &pressure, &density);

View File

@ -1,74 +0,0 @@
// Copyright © 2008-2019 Pioneer Developers. See AUTHORS.txt for details
// Licensed under the terms of the GPL v3. See licenses/GPL-3.txt
#include "FileSystem.h"
#include "OS.h"
#include "SDL.h"
#include "graphics/Graphics.h"
#include "graphics/Renderer.h"
#include "text/FontDescriptor.h"
#include "text/TextureFont.h"
#include <cstdlib>
static const int WIDTH = 1024;
static const int HEIGHT = 768;
int main(int argc, char **argv)
{
FileSystem::Init();
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
Output("sdl init failed: %s\n", SDL_GetError());
exit(-1);
}
Graphics::Settings videoSettings;
videoSettings.rendererType = Graphics::RENDERER_OPENGL;
videoSettings.width = WIDTH;
videoSettings.height = HEIGHT;
videoSettings.fullscreen = false;
videoSettings.hidden = false;
videoSettings.requestedSamples = 0;
videoSettings.vsync = false;
videoSettings.useTextureCompression = false;
videoSettings.enableDebugMessages = false;
videoSettings.iconFile = OS::GetIconFilename();
videoSettings.title = "textstress";
Graphics::Renderer *r = Graphics::Init(videoSettings);
r->SetOrthographicProjection(0, WIDTH, HEIGHT, 0, -1, 1);
r->SetTransform(matrix4x4f::Identity());
r->SetClearColor(Color::BLACK);
r->SetBlendMode(Graphics::BLEND_ALPHA);
r->SetDepthTest(false);
const Text::FontDescriptor fontDesc(Text::FontDescriptor::Load(FileSystem::gameDataFiles, "fonts/UIFont.ini", "en"));
Text::TextureFont *font = new Text::TextureFont(fontDesc, r);
std::string str;
for (int i = 33; i < 127; i++)
str.push_back(i);
while (1) {
bool done = false;
SDL_Event event;
while (SDL_PollEvent(&event)) {
if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE)
done = true;
}
if (done)
break;
font->RenderString(str.c_str(), rand() % (WIDTH * 2) - WIDTH, rand() % HEIGHT, Color::WHITE);
r->SwapBuffers();
}
delete font;
delete r;
SDL_Quit();
exit(0);
}

View File

@ -123,7 +123,7 @@ int main(int argc, char **argv)
Graphics::RendererOGL::RegisterRenderer();
Graphics::Settings videoSettings;
videoSettings.rendererType = Graphics::RENDERER_OPENGL;
videoSettings.rendererType = Graphics::RENDERER_OPENGL_3x;
videoSettings.width = WIDTH;
videoSettings.height = HEIGHT;
videoSettings.fullscreen = false;