Skip to content

Commit

Permalink
GRAPHICS: Replace ScopedPtr/ScopedArray with std::unique_ptr
Browse files Browse the repository at this point in the history
  • Loading branch information
DrMcCoy committed Aug 11, 2020
1 parent 79340f7 commit ae325f3
Show file tree
Hide file tree
Showing 38 changed files with 120 additions and 100 deletions.
5 changes: 3 additions & 2 deletions src/graphics/aurora/abcfont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
* An ABC/SBM font, as used by Jade Empire.
*/

#include "src/common/scopedptr.h"
#include <memory>

#include "src/common/ustring.h"
#include "src/common/error.h"
#include "src/common/readstream.h"
Expand Down Expand Up @@ -127,7 +128,7 @@ void ABCFont::renderUnbind() const {
}

void ABCFont::load(const Common::UString &name) {
Common::ScopedPtr<Common::SeekableReadStream> abc(ResMan.getResource(name, ::Aurora::kFileTypeABC));
std::unique_ptr<Common::SeekableReadStream> abc(ResMan.getResource(name, ::Aurora::kFileTypeABC));
if (!abc)
throw Common::Exception("No such font \"%s\"", name.c_str());

Expand Down
13 changes: 7 additions & 6 deletions src/graphics/aurora/cursor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
* A cursor as used in the Aurora engines.
*/

#include "src/common/scopedptr.h"
#include <memory>

#include "src/common/util.h"
#include "src/common/error.h"
#include "src/common/readstream.h"
Expand Down Expand Up @@ -82,23 +83,23 @@ void Cursor::render() {
void Cursor::load() {
::Aurora::FileType type;

Common::ScopedPtr<Common::SeekableReadStream>
std::unique_ptr<Common::SeekableReadStream>
img(ResMan.getResource(::Aurora::kResourceCursor, _name, &type));
if (!img)
throw Common::Exception("No such cursor resource \"%s\"", _name.c_str());

_hotspotX = 0;
_hotspotY = 0;

Common::ScopedPtr<ImageDecoder> image;
std::unique_ptr<ImageDecoder> image;

// Loading the different image formats
if (type == ::Aurora::kFileTypeTGA)
image.reset(new TGA(*img));
image = std::make_unique<TGA>(*img);
else if (type == ::Aurora::kFileTypeDDS)
image.reset(new DDS(*img));
image = std::make_unique<DDS>(*img);
else if (type == ::Aurora::kFileTypeCUR) {
Common::ScopedPtr<WinIconImage> cursor(new WinIconImage(*img));
std::unique_ptr<WinIconImage> cursor = std::make_unique<WinIconImage>(*img);

if (_hotspotX < 0)
_hotspotX = cursor->getHotspotX();
Expand Down
5 changes: 3 additions & 2 deletions src/graphics/aurora/cursorman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
* The Aurora cursor manager.
*/

#include "src/common/scopedptr.h"
#include <memory>

#include "src/common/util.h"
#include "src/common/error.h"

Expand Down Expand Up @@ -85,7 +86,7 @@ bool CursorManager::add(const Common::UString &name, const Common::UString &grou
std::lock_guard<std::recursive_mutex> lock(_mutex);

try {
Common::ScopedPtr<Cursor> cursor(new Cursor(name, hotspotX, hotspotY));
std::unique_ptr<Cursor> cursor = std::make_unique<Cursor>(name, hotspotX, hotspotY);

CursorMap::iterator g = _cursors.find(group);
if (g == _cursors.end()) {
Expand Down
4 changes: 2 additions & 2 deletions src/graphics/aurora/fonthandle.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
#define GRAPHICS_AURORA_FONTHANDLE_H

#include <map>
#include <memory>

#include "src/common/types.h"
#include "src/common/scopedptr.h"
#include "src/common/ptrmap.h"
#include "src/common/ustring.h"

Expand All @@ -40,7 +40,7 @@ namespace Aurora {

/** A managed font, storing how often it's referenced. */
struct ManagedFont {
Common::ScopedPtr<Font> font;
std::unique_ptr<Font> font;
uint32 referenceCount;

ManagedFont(Font *f);
Expand Down
5 changes: 3 additions & 2 deletions src/graphics/aurora/fontman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
* The Aurora font manager.
*/

#include "src/common/scopedptr.h"
#include <memory>

#include "src/common/error.h"
#include "src/common/systemfonts.h"

Expand Down Expand Up @@ -79,7 +80,7 @@ bool FontManager::hasFont(const Common::UString &name, int height) {
FontHandle FontManager::add(Font *font, const Common::UString &name) {
std::lock_guard<std::recursive_mutex> lock(_mutex);

Common::ScopedPtr<ManagedFont> managedFont(new ManagedFont(font));
std::unique_ptr<ManagedFont> managedFont = std::make_unique<ManagedFont>(font);

std::pair<FontMap::iterator, bool> result = _fonts.insert(std::make_pair(name, managedFont.get()));
if (!result.second)
Expand Down
7 changes: 4 additions & 3 deletions src/graphics/aurora/nftrfont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
#include <cassert>
#include <cstring>

#include "src/common/scopedptr.h"
#include <memory>

#include "src/common/util.h"
#include "src/common/maths.h"
#include "src/common/ustring.h"
Expand Down Expand Up @@ -91,7 +92,7 @@ NFTRFont::NFTRFont(Common::SeekableReadStream *nftr, bool invertPalette) :

assert(nftr);

Common::ScopedPtr<Common::SeekableSubReadStreamEndian> nftrEndian(open(nftr));
std::unique_ptr<Common::SeekableSubReadStreamEndian> nftrEndian(open(nftr));

load(*nftrEndian);
}
Expand All @@ -103,7 +104,7 @@ NFTRFont::NFTRFont(const Common::UString &name, bool invertPalette) :
if (!nftr)
throw Common::Exception("No such font \"%s\"", name.c_str());

Common::ScopedPtr<Common::SeekableSubReadStreamEndian> nftrEndian(open(nftr));
std::unique_ptr<Common::SeekableSubReadStreamEndian> nftrEndian(open(nftr));

load(*nftrEndian);
}
Expand Down
8 changes: 4 additions & 4 deletions src/graphics/aurora/pltfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ void PLTFile::load(Common::SeekableReadStream &plt) {

size_t size = width * height;

_dataImage.reset(new uint8[size]);
_dataLayers.reset(new uint8[size]);
_dataImage = std::make_unique<uint8[]>(size);
_dataLayers = std::make_unique<uint8[]>(size);

uint8 *image = _dataImage.get();
uint8 *layer = _dataLayers.get();
Expand Down Expand Up @@ -181,7 +181,7 @@ ImageDecoder *PLTFile::getLayerPalette(uint32 layer, uint8 row) {
assert(layer < kLayerMAX);

// TODO: We may want to cache these somehow...
Common::ScopedPtr<ImageDecoder> palette(loadImage(kPalettes[layer]));
std::unique_ptr<ImageDecoder> palette(loadImage(kPalettes[layer]));

if (palette->getFormat() != kPixelFormatBGRA)
throw Common::Exception("Invalid format (%d)", palette->getFormat());
Expand All @@ -203,7 +203,7 @@ ImageDecoder *PLTFile::getLayerPalette(uint32 layer, uint8 row) {
void PLTFile::getColorRows(byte rows[4 * 256 * kLayerMAX], const uint8 colors[kLayerMAX]) {
for (size_t i = 0; i < kLayerMAX; i++, rows += 4 * 256) {
try {
Common::ScopedPtr<ImageDecoder> palette(getLayerPalette(i, colors[i]));
std::unique_ptr<ImageDecoder> palette(getLayerPalette(i, colors[i]));

// The images have their origin at the bottom left, so we flip the color row
const uint8 row = palette->getMipMap(0).height - 1 - colors[i];
Expand Down
6 changes: 3 additions & 3 deletions src/graphics/aurora/pltfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#ifndef GRAPHICS_AURORA_PLTFILE_H
#define GRAPHICS_AURORA_PLTFILE_H

#include "src/common/scopedptr.h"
#include <memory>

#include "src/aurora/aurorafile.h"

Expand Down Expand Up @@ -69,8 +69,8 @@ class PLTFile : public ::Aurora::AuroraFile, public Texture {

Surface *_surface;

Common::ScopedArray<uint8> _dataImage;
Common::ScopedArray<uint8> _dataLayers;
std::unique_ptr<uint8[]> _dataImage;
std::unique_ptr<uint8[]> _dataLayers;

uint8 _colors[kLayerMAX];

Expand Down
7 changes: 4 additions & 3 deletions src/graphics/aurora/texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
#ifndef GRAPHICS_AURORA_TEXTURE_H
#define GRAPHICS_AURORA_TEXTURE_H

#include "src/common/scopedptr.h"
#include <memory>

#include "src/common/ustring.h"

#include "src/graphics/types.h"
Expand Down Expand Up @@ -86,8 +87,8 @@ class Texture : public Graphics::Texture {
Common::UString _name; ///< The name of the texture's image's file.
::Aurora::FileType _type; ///< The type of the texture's image's file.

Common::ScopedPtr<ImageDecoder> _image; ///< The actual image.
Common::ScopedPtr<TXI> _txi; ///< The TXI.
std::unique_ptr<ImageDecoder> _image; ///< The actual image.
std::unique_ptr<TXI> _txi; ///< The TXI.

uint32 _width;
uint32 _height;
Expand Down
5 changes: 3 additions & 2 deletions src/graphics/aurora/textureman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
* The Aurora texture manager.
*/

#include "src/common/scopedptr.h"
#include <memory>

#include "src/common/util.h"
#include "src/common/error.h"
#include "src/common/uuid.h"
Expand Down Expand Up @@ -134,7 +135,7 @@ TextureHandle TextureManager::add(Texture *texture, Common::UString name) {
if (name.empty())
name = Common::generateIDRandomString();

Common::ScopedPtr<ManagedTexture> managedTexture(new ManagedTexture(texture));
std::unique_ptr<ManagedTexture> managedTexture = std::make_unique<ManagedTexture>(texture);

std::pair<TextureMap::iterator, bool> result = _textures.insert(std::make_pair(name, managedTexture.get()));
if (!result.second)
Expand Down
4 changes: 2 additions & 2 deletions src/graphics/aurora/ttffont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ TTFFont::~TTFFont() {
}

void TTFFont::load(Common::SeekableReadStream *ttf, int height) {
Common::ScopedPtr<Common::SeekableReadStream> ttfStream(ttf);
std::unique_ptr<Common::SeekableReadStream> ttfStream(ttf);

_ttf.reset(new TTFRenderer(*ttfStream, height));
_ttf = std::make_unique<TTFRenderer>(*ttfStream, height);

_height = _ttf->getHeight();
if (_height > kPageHeight)
Expand Down
4 changes: 2 additions & 2 deletions src/graphics/aurora/ttffont.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@

#include <vector>
#include <map>
#include <memory>

#include "src/common/types.h"
#include "src/common/scopedptr.h"
#include "src/common/ptrvector.h"

#include "src/graphics/font.h"
Expand Down Expand Up @@ -103,7 +103,7 @@ class TTFFont : public Graphics::Font {
};


Common::ScopedPtr<TTFRenderer> _ttf;
std::unique_ptr<TTFRenderer> _ttf;

Common::PtrVector<Page> _pages;
std::map<uint32, Char> _chars;
Expand Down
2 changes: 1 addition & 1 deletion src/graphics/fpscounter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace Graphics {
FPSCounter::FPSCounter(size_t secs) : _seconds(secs) {
assert(_seconds > 0);

_frames.reset(new uint32[_seconds]);
_frames = std::make_unique<uint32[]>(_seconds);

reset();
}
Expand Down
5 changes: 3 additions & 2 deletions src/graphics/fpscounter.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
#ifndef GRAPHICS_FPSCOUNTER_H
#define GRAPHICS_FPSCOUNTER_H

#include <memory>

#include "src/common/types.h"
#include "src/common/scopedptr.h"

namespace Graphics {

Expand Down Expand Up @@ -56,7 +57,7 @@ class FPSCounter {

uint32 _fps; ///< The current FPS value.

Common::ScopedArray<uint32> _frames; ///< All frame counters.
std::unique_ptr<uint32[]> _frames; ///< All frame counters.

void calculateFPS(); ///< Calculate the average FPS value.
};
Expand Down
2 changes: 1 addition & 1 deletion src/graphics/graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ GraphicsManager::GraphicsManager() : Events::Notifyable() {
_guiWidth = 800;
_guiHeight = 600;

_fpsCounter.reset(new FPSCounter(3));
_fpsCounter = std::make_unique<FPSCounter>(3);

_frameLock.store(0);

Expand Down
4 changes: 2 additions & 2 deletions src/graphics/graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
#include <vector>
#include <list>
#include <atomic>
#include <memory>

#include "external/glm/mat4x4.hpp"

#include "src/common/types.h"
#include "src/common/scopedptr.h"
#include "src/common/singleton.h"
#include "src/common/ustring.h"
#include "src/common/mutex.h"
Expand Down Expand Up @@ -216,7 +216,7 @@ class GraphicsManager : public Common::Singleton<GraphicsManager>, public Events
int _guiHeight;
int _guiWidth;

Common::ScopedPtr<FPSCounter> _fpsCounter; ///< Counts the current frames per seconds value.
std::unique_ptr<FPSCounter> _fpsCounter; ///< Counts the current frames per seconds value.

uint32 _lastSampled; ///< Timestamp used to advance animations.

Expand Down
2 changes: 1 addition & 1 deletion src/graphics/images/cbgt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ void CBGT::createImage(uint32 width, uint32 height) {
_mipMaps.back()->height = height;
_mipMaps.back()->size = width * height * 4;

_mipMaps.back()->data.reset(new byte[_mipMaps.back()->size]);
_mipMaps.back()->data = std::make_unique<byte[]>(_mipMaps.back()->size);
std::memset(_mipMaps.back()->data.get(), 0, _mipMaps.back()->size);
}

Expand Down
11 changes: 6 additions & 5 deletions src/graphics/images/dds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
* DDS texture (DirectDraw Surface or BioWare's own format) loading).
*/

#include "src/common/scopedptr.h"
#include <memory>

#include "src/common/util.h"
#include "src/common/error.h"
#include "src/common/readstream.h"
Expand Down Expand Up @@ -121,7 +122,7 @@ void DDS::readStandardHeader(Common::SeekableReadStream &dds, DataType &dataType

_mipMaps.reserve(mipMapCount);
for (uint32 i = 0; i < mipMapCount; i++) {
MipMap *mipMap = new MipMap(this);
std::unique_ptr<MipMap> mipMap = std::make_unique<MipMap>();

mipMap->width = MAX<uint32>(width , 1);
mipMap->height = MAX<uint32>(height, 1);
Expand All @@ -131,7 +132,7 @@ void DDS::readStandardHeader(Common::SeekableReadStream &dds, DataType &dataType
width >>= 1;
height >>= 1;

_mipMaps.push_back(mipMap);
_mipMaps.push_back(mipMap.release());
}

}
Expand Down Expand Up @@ -187,7 +188,7 @@ void DDS::readBioWareHeader(Common::SeekableReadStream &dds, DataType &dataType)

// Detect how many mip maps are in the DDS
do {
Common::ScopedPtr<MipMap> mipMap(new MipMap(this));
std::unique_ptr<MipMap> mipMap = std::make_unique<MipMap>(this);

mipMap->width = MAX<uint32>(width, 1);
mipMap->height = MAX<uint32>(height, 1);
Expand Down Expand Up @@ -216,7 +217,7 @@ void DDS::setSize(MipMap &mipMap) {

void DDS::readData(Common::SeekableReadStream &dds, DataType dataType) {
for (MipMaps::iterator mipMap = _mipMaps.begin(); mipMap != _mipMaps.end(); ++mipMap) {
(*mipMap)->data.reset(new byte[(*mipMap)->size]);
(*mipMap)->data = std::make_unique<byte[]>((*mipMap)->size);

if (dataType == kDataType4444) {

Expand Down

0 comments on commit ae325f3

Please sign in to comment.