Skip to content

Commit

Permalink
replace all instances of Scoped{Ptr,Array} with unique_ptr
Browse files Browse the repository at this point in the history
Includes a few very minor use cleanups too:

- *foo.Get() is simpler as just *foo
- foo.Get()[idx] is simpler as just foo[idx]
- NULL -> nullptr
- Valid() doesn't have a direct counterpart in unique_ptr; just
  use the pointer in a bool context (it has an explicit conversion
  to bool)
  • Loading branch information
johnbartholomew committed Oct 30, 2013
1 parent 780edb3 commit 6b6b9c6
Show file tree
Hide file tree
Showing 75 changed files with 317 additions and 349 deletions.
2 changes: 1 addition & 1 deletion src/DeathView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ DeathView::DeathView(): View()
Pi::renderer->GetNearFarRange(znear, zfar);

const float fovY = Pi::config->Float("FOVVertical");
m_cam.Reset(new Camera(Graphics::GetScreenWidth(), Graphics::GetScreenHeight(), fovY, znear, zfar));
m_cam.reset(new Camera(Graphics::GetScreenWidth(), Graphics::GetScreenHeight(), fovY, znear, zfar));
}

DeathView::~DeathView() {}
Expand Down
2 changes: 1 addition & 1 deletion src/DeathView.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class DeathView : public View {
virtual void OnSwitchTo();

private:
ScopedPtr<Camera> m_cam;
std::unique_ptr<Camera> m_cam;
float m_cameraDist;
};

Expand Down
2 changes: 1 addition & 1 deletion src/FaceVideoLink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ FaceVideoLink::FaceVideoLink(float w, float h, Uint32 flags, Uint32 seed,

m_characterInfo = new CharacterInfoText(w * 0.8f, h * 0.15f, charname, title);

m_quad.Reset(new Gui::TexturedQuad(Graphics::TextureBuilder(faceim, Graphics::LINEAR_CLAMP, true, true).CreateTexture(Gui::Screen::GetRenderer())));
m_quad.reset(new Gui::TexturedQuad(Graphics::TextureBuilder(faceim, Graphics::LINEAR_CLAMP, true, true).CreateTexture(Gui::Screen::GetRenderer())));
}

FaceVideoLink::~FaceVideoLink() {
Expand Down
2 changes: 1 addition & 1 deletion src/FaceVideoLink.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class FaceVideoLink : public VideoLink {
Uint32 m_seed;

Uint32 m_created;
ScopedPtr<Gui::TexturedQuad> m_quad;
std::unique_ptr<Gui::TexturedQuad> m_quad;
Gui::ToolTip *m_message;
CharacterInfoText *m_characterInfo;
};
Expand Down
44 changes: 22 additions & 22 deletions src/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ Game::Game(const SystemPath &path) :
m_requestedTimeAccel(TIMEACCEL_1X),
m_forceTimeAccel(false)
{
m_space.Reset(new Space(this, path));
m_space.reset(new Space(this, path));
SpaceStation *station = static_cast<SpaceStation*>(m_space->FindBodyForPath(&path));
assert(station);

m_player.Reset(new Player("kanara"));
m_player.reset(new Player("kanara"));

m_space->AddBody(m_player.Get());
m_space->AddBody(m_player.get());

m_player->SetFrame(station->GetFrame());
m_player->SetDockedWith(station, 0);
Expand All @@ -60,13 +60,13 @@ Game::Game(const SystemPath &path, const vector3d &pos) :
m_requestedTimeAccel(TIMEACCEL_1X),
m_forceTimeAccel(false)
{
m_space.Reset(new Space(this, path));
m_space.reset(new Space(this, path));
Body *b = m_space->FindBodyForPath(&path);
assert(b);

m_player.Reset(new Player("kanara"));
m_player.reset(new Player("kanara"));

m_space->AddBody(m_player.Get());
m_space->AddBody(m_player.get());

m_player->SetFrame(b->GetFrame());

Expand Down Expand Up @@ -98,9 +98,9 @@ Game::~Game()
// is owned by the space, and the game part that holds all the player
// attributes and whatever else

m_space->RemoveBody(m_player.Get());
m_space.Reset();
m_player.Reset();
m_space->RemoveBody(m_player.get());
m_space.reset();
m_player.reset();
}

Game::Game(Serializer::Reader &rd) :
Expand All @@ -124,13 +124,13 @@ Game::Game(Serializer::Reader &rd) :

// space, all the bodies and things
section = rd.RdSection("Space");
m_space.Reset(new Space(this, section));
m_space.reset(new Space(this, section));


// game state and space transition state
section = rd.RdSection("Game");

m_player.Reset(static_cast<Player*>(m_space->GetBodyByIndex(section.Int32())));
m_player.reset(static_cast<Player*>(m_space->GetBodyByIndex(section.Int32())));

// hyperspace clouds being brought over from the previous system
Uint32 nclouds = section.Int32();
Expand Down Expand Up @@ -184,12 +184,12 @@ void Game::Serialize(Serializer::Writer &wr)
// game state and space transition state
section = Serializer::Writer();

section.Int32(m_space->GetIndexForBody(m_player.Get()));
section.Int32(m_space->GetIndexForBody(m_player.get()));

// hyperspace clouds being brought over from the previous system
section.Int32(m_hyperspaceClouds.size());
for (std::list<HyperspaceCloud*>::const_iterator i = m_hyperspaceClouds.begin(); i != m_hyperspaceClouds.end(); ++i)
(*i)->Serialize(section, m_space.Get());
(*i)->Serialize(section, m_space.get());

section.Double(m_time);
section.Int32(Uint32(m_state));
Expand Down Expand Up @@ -295,7 +295,7 @@ bool Game::UpdateTimeAccel()
else if (!m_forceTimeAccel) {
// check we aren't too near to objects for timeaccel //
for (Space::BodyIterator i = m_space->BodiesBegin(); i != m_space->BodiesEnd(); ++i) {
if ((*i) == m_player) continue;
if ((*i) == m_player.get()) continue;
if ((*i)->IsType(Object::HYPERSPACECLOUD)) continue;

vector3d toBody = m_player->GetPosition() - (*i)->GetPositionRelTo(m_player->GetFrame());
Expand Down Expand Up @@ -396,14 +396,14 @@ void Game::SwitchToHyperspace()
printf(SIZET_FMT " clouds brought over\n", m_hyperspaceClouds.size());

// remove the player from space
m_space->RemoveBody(m_player.Get());
m_space->RemoveBody(m_player.get());

// create hyperspace :)
m_space.Reset(new Space(this));
m_space.reset(new Space(this));

// put the player in it
m_player->SetFrame(m_space->GetRootFrame());
m_space->AddBody(m_player.Get());
m_space->AddBody(m_player.get());

// put player at the origin. kind of unnecessary since it won't be moving
// but at least it gives some consistency
Expand All @@ -425,15 +425,15 @@ void Game::SwitchToHyperspace()
void Game::SwitchToNormalSpace()
{
// remove the player from hyperspace
m_space->RemoveBody(m_player.Get());
m_space->RemoveBody(m_player.get());

// create a new space for the system
const SystemPath &dest = m_player->GetHyperspaceDest();
m_space.Reset(new Space(this, dest));
m_space.reset(new Space(this, dest));

// put the player in it
m_player->SetFrame(m_space->GetRootFrame());
m_space->AddBody(m_player.Get());
m_space->AddBody(m_player.get());

// place it
m_player->SetPosition(m_space->GetHyperspaceExitPoint(m_hyperspaceSource));
Expand Down Expand Up @@ -601,7 +601,7 @@ void Game::CreateViews()

// XXX views expect Pi::game and Pi::player to exist
Pi::game = this;
Pi::player = m_player.Get();
Pi::player = m_player.get();

Pi::cpan = new ShipCpanel(Pi::renderer);
Pi::sectorView = new SectorView();
Expand Down Expand Up @@ -636,7 +636,7 @@ void Game::LoadViews(Serializer::Reader &rd)

// XXX views expect Pi::game and Pi::player to exist
Pi::game = this;
Pi::player = m_player.Get();
Pi::player = m_player.get();

Serializer::Reader section = rd.RdSection("ShipCpanel");
Pi::cpan = new ShipCpanel(section, Pi::renderer);
Expand Down
8 changes: 4 additions & 4 deletions src/Game.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ class Game {
bool IsNormalSpace() const { return m_state == STATE_NORMAL; }
bool IsHyperspace() const { return m_state == STATE_HYPERSPACE; }

Space *GetSpace() const { return m_space.Get(); }
Space *GetSpace() const { return m_space.get(); }
double GetTime() const { return m_time; }
Player *GetPlayer() const { return m_player.Get(); }
Player *GetPlayer() const { return m_player.get(); }

// physics step
void TimeStep(float step);
Expand Down Expand Up @@ -90,10 +90,10 @@ class Game {
void SwitchToHyperspace();
void SwitchToNormalSpace();

ScopedPtr<Space> m_space;
std::unique_ptr<Space> m_space;
double m_time;

ScopedPtr<Player> m_player;
std::unique_ptr<Player> m_player;

enum State {
STATE_NORMAL,
Expand Down
62 changes: 31 additions & 31 deletions src/GeoPatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ GeoPatch::GeoPatch(const RefCountedPtr<GeoPatchContext> &ctx_, GeoSphere *gs,
const vector3d &v0_, const vector3d &v1_, const vector3d &v2_, const vector3d &v3_,
const int depth, const GeoPatchID &ID_)
: ctx(ctx_), v0(v0_), v1(v1_), v2(v2_), v3(v3_),
heights(NULL), normals(NULL), colors(NULL),
m_vbo(0), parent(NULL), geosphere(gs),
heights(nullptr), normals(nullptr), colors(nullptr),
m_vbo(0), parent(nullptr), geosphere(gs),
m_depth(depth), mPatchID(ID_),
mHasJobRequest(false)
{
Expand Down Expand Up @@ -60,11 +60,11 @@ GeoPatch::~GeoPatch() {
if (edgeFriend[i]) edgeFriend[i]->NotifyEdgeFriendDeleted(this);
}
for (int i=0; i<NUM_KIDS; i++) {
kids[i].Reset();
kids[i].reset();
}
heights.Reset();
normals.Reset();
colors.Reset();
heights.reset();
normals.reset();
colors.reset();
glDeleteBuffersARB(1, &m_vbo);
}

Expand All @@ -75,9 +75,9 @@ void GeoPatch::_UpdateVBOs() {
glBindBufferARB(GL_ARRAY_BUFFER, m_vbo);
glBufferDataARB(GL_ARRAY_BUFFER, sizeof(GeoPatchContext::VBOVertex)*ctx->NUMVERTICES(), 0, GL_DYNAMIC_DRAW);
double xfrac=0.0, yfrac=0.0;
double *pHts = heights.Get();
const vector3f *pNorm = &normals[0];
const Color3ub *pColr = &colors[0];
double *pHts = heights.get();
const vector3f *pNorm = normals.get();
const Color3ub *pColr = colors.get();
GeoPatchContext::VBOVertex *pData = ctx->vbotemp;
for (int y=0; y<ctx->edgeLen; y++) {
xfrac = 0.0;
Expand Down Expand Up @@ -115,7 +115,7 @@ void GeoPatch::_UpdateVBOs() {
void GeoPatch::Render(Graphics::Renderer *renderer, const vector3d &campos, const matrix4x4d &modelView, const Graphics::Frustum &frustum) {
if (kids[0]) {
for (int i=0; i<NUM_KIDS; i++) kids[i]->Render(renderer, campos, modelView, frustum);
} else if (heights.Valid()) {
} else if (heights) {
_UpdateVBOs();

if (!frustum.TestPoint(clipCentroid, clipRadius))
Expand Down Expand Up @@ -144,7 +144,7 @@ void GeoPatch::LODUpdate(const vector3d &campos) {
return;

bool canSplit = true;
bool canMerge = kids[0].Valid();
bool canMerge = bool(kids[0]);

// always split at first level
if (parent) {
Expand Down Expand Up @@ -184,15 +184,15 @@ void GeoPatch::LODUpdate(const vector3d &campos) {
}
if( canMerge ) {
for (int i=0; i<NUM_KIDS; i++) {
kids[i].Reset();
kids[i].reset();
}
}
}
}

void GeoPatch::RequestSinglePatch()
{
if( !heights.Valid() ) {
if( !heights ) {
assert(!mHasJobRequest);
mHasJobRequest = true;
SSingleSplitRequest *ssrd = new SSingleSplitRequest(v0, v1, v2, v3, centroid.Normalized(), m_depth,
Expand All @@ -217,41 +217,41 @@ void GeoPatch::ReceiveHeightmaps(SQuadSplitResult *psr)
const int nD = m_depth+1;
for (int i=0; i<NUM_KIDS; i++)
{
assert(!kids[i].Valid());
assert(!kids[i]);
const SQuadSplitResult::SSplitResultData& data = psr->data(i);
assert(i==data.patchID.GetPatchIdx(nD));
assert(0==data.patchID.GetPatchIdx(nD+1));
kids[i].Reset(new GeoPatch(ctx, geosphere,
kids[i].reset(new GeoPatch(ctx, geosphere,
data.v0, data.v1, data.v2, data.v3,
nD, data.patchID));
}

// hm.. edges. Not right to pass this
// edgeFriend...
kids[0]->edgeFriend[0] = GetEdgeFriendForKid(0, 0);
kids[0]->edgeFriend[1] = kids[1].Get();
kids[0]->edgeFriend[2] = kids[3].Get();
kids[0]->edgeFriend[1] = kids[1].get();
kids[0]->edgeFriend[2] = kids[3].get();
kids[0]->edgeFriend[3] = GetEdgeFriendForKid(0, 3);
kids[1]->edgeFriend[0] = GetEdgeFriendForKid(1, 0);
kids[1]->edgeFriend[1] = GetEdgeFriendForKid(1, 1);
kids[1]->edgeFriend[2] = kids[2].Get();
kids[1]->edgeFriend[3] = kids[0].Get();
kids[2]->edgeFriend[0] = kids[1].Get();
kids[1]->edgeFriend[2] = kids[2].get();
kids[1]->edgeFriend[3] = kids[0].get();
kids[2]->edgeFriend[0] = kids[1].get();
kids[2]->edgeFriend[1] = GetEdgeFriendForKid(2, 1);
kids[2]->edgeFriend[2] = GetEdgeFriendForKid(2, 2);
kids[2]->edgeFriend[3] = kids[3].Get();
kids[3]->edgeFriend[0] = kids[0].Get();
kids[3]->edgeFriend[1] = kids[2].Get();
kids[2]->edgeFriend[3] = kids[3].get();
kids[3]->edgeFriend[0] = kids[0].get();
kids[3]->edgeFriend[1] = kids[2].get();
kids[3]->edgeFriend[2] = GetEdgeFriendForKid(3, 2);
kids[3]->edgeFriend[3] = GetEdgeFriendForKid(3, 3);
kids[0]->parent = kids[1]->parent = kids[2]->parent = kids[3]->parent = this;

for (int i=0; i<NUM_KIDS; i++)
{
const SQuadSplitResult::SSplitResultData& data = psr->data(i);
kids[i]->heights.Reset(data.heights);
kids[i]->normals.Reset(data.normals);
kids[i]->colors.Reset(data.colors);
kids[i]->heights.reset(data.heights);
kids[i]->normals.reset(data.normals);
kids[i]->colors.reset(data.colors);
}
for (int i=0; i<NUM_EDGES; i++) { if(edgeFriend[i]) edgeFriend[i]->NotifyEdgeFriendSplit(this); }
for (int i=0; i<NUM_KIDS; i++) {
Expand All @@ -263,14 +263,14 @@ void GeoPatch::ReceiveHeightmaps(SQuadSplitResult *psr)

void GeoPatch::ReceiveHeightmap(const SSingleSplitResult *psr)
{
assert(NULL==parent);
assert(NULL!=psr);
assert(nullptr == parent);
assert(nullptr != psr);
assert(mHasJobRequest);
{
const SSingleSplitResult::SSplitResultData& data = psr->data();
heights.Reset(data.heights);
normals.Reset(data.normals);
colors.Reset(data.colors);
heights.reset(data.heights);
normals.reset(data.normals);
colors.reset(data.colors);
}
mHasJobRequest = false;
}
Loading

0 comments on commit 6b6b9c6

Please sign in to comment.