VideoBuffer pointer correctness
This commit is contained in:
parent
50bfa7cd5e
commit
b26a1b4a88
@ -29,18 +29,6 @@ VideoBuffer::VideoBuffer(pixel const *data, Vec2<int> size, size_t rowStride):
|
||||
std::copy_n(data + rowStride * y, size.X, video.RowIterator(Vec2(0, y)));
|
||||
}
|
||||
|
||||
VideoBuffer::VideoBuffer(int width, int height):
|
||||
VideoBuffer(Vec2(width, height))
|
||||
{}
|
||||
|
||||
VideoBuffer::VideoBuffer(VideoBuffer * old):
|
||||
VideoBuffer(*old)
|
||||
{}
|
||||
|
||||
VideoBuffer::VideoBuffer(pixel const *buffer, int width, int height, int pitch):
|
||||
VideoBuffer(buffer, Vec2(width, height), pitch == 0 ? width : pitch)
|
||||
{}
|
||||
|
||||
void VideoBuffer::Crop(Rect<int> rect)
|
||||
{
|
||||
rect &= Size().OriginRect();
|
||||
|
@ -48,13 +48,6 @@ public:
|
||||
// Automatically choose a size to fit within the given box, keeping aspect ratio
|
||||
void ResizeToFit(Vec2<int> bound, bool resample = false);
|
||||
|
||||
[[deprecated("Use VideoBuffer(VideoBuffer const &)")]]
|
||||
VideoBuffer(VideoBuffer * old);
|
||||
[[deprecated("Use VideoBuffer(pixel const *, Vec2<int>)")]]
|
||||
VideoBuffer(pixel const *buffer, int width, int height, int pitch = 0);
|
||||
[[deprecated("Use VideoBuffer(Vec2<int>)")]]
|
||||
VideoBuffer(int width, int height);
|
||||
|
||||
bool WritePNG(const ByteString &path) const;
|
||||
};
|
||||
|
||||
|
@ -48,6 +48,11 @@ class Renderer: public RasterDrawMethods<Renderer>
|
||||
friend struct RasterDrawMethods<Renderer>;
|
||||
|
||||
public:
|
||||
Vec2<int> Size() const
|
||||
{
|
||||
return video.Size();
|
||||
}
|
||||
|
||||
pixel const *Data() const
|
||||
{
|
||||
return video.data();
|
||||
|
@ -499,11 +499,8 @@ void Renderer::ResetModes()
|
||||
|
||||
VideoBuffer Renderer::DumpFrame()
|
||||
{
|
||||
VideoBuffer newBuffer(XRES, YRES);
|
||||
for(int y = 0; y < YRES; y++)
|
||||
{
|
||||
std::copy(vid+(y*WINDOWW), vid+(y*WINDOWW)+XRES, newBuffer.Data()+(y*XRES));
|
||||
}
|
||||
VideoBuffer newBuffer(RES);
|
||||
newBuffer.BlendImage(video.data(), 0xFF, Size().OriginRect());
|
||||
return newBuffer;
|
||||
}
|
||||
|
||||
|
@ -157,7 +157,7 @@ void ElementSearchActivity::searchTools(String query)
|
||||
else
|
||||
tempButton = new ToolButton(current+viewPosition, ui::Point(30, 18), tool->Name, tool->Identifier, tool->Description);
|
||||
|
||||
tempButton->Appearance.SetTexture(tempTexture.get());
|
||||
tempButton->Appearance.SetTexture(std::move(tempTexture));
|
||||
tempButton->Appearance.BackgroundInactive = tool->Colour.WithAlpha(0xFF);
|
||||
tempButton->SetActionCallback({ [this, tempButton, tool] {
|
||||
if (tempButton->GetSelectionState() >= 0 && tempButton->GetSelectionState() <= 2)
|
||||
|
@ -213,7 +213,7 @@ GameView::GameView():
|
||||
selectPoint2(0, 0),
|
||||
currentMouse(0, 0),
|
||||
mousePosition(0, 0),
|
||||
placeSaveThumb(NULL),
|
||||
placeSaveThumb(nullptr),
|
||||
placeSaveOffset(0, 0)
|
||||
{
|
||||
|
||||
@ -344,8 +344,6 @@ GameView::~GameView()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
delete placeSaveThumb;
|
||||
}
|
||||
|
||||
class GameView::OptionListener: public QuickOptionListener
|
||||
@ -631,7 +629,7 @@ void GameView::NotifyToolListChanged(GameModel * sender)
|
||||
}
|
||||
} });
|
||||
|
||||
tempButton->Appearance.SetTexture(tempTexture.get());
|
||||
tempButton->Appearance.SetTexture(std::move(tempTexture));
|
||||
|
||||
tempButton->Appearance.BackgroundInactive = toolList[i]->Colour.WithAlpha(0xFF);
|
||||
|
||||
@ -1914,7 +1912,6 @@ void GameView::NotifyLogChanged(GameModel * sender, String entry)
|
||||
|
||||
void GameView::NotifyPlaceSaveChanged(GameModel * sender)
|
||||
{
|
||||
delete placeSaveThumb;
|
||||
placeSaveOffset = ui::Point(0, 0);
|
||||
if(sender->GetPlaceSave())
|
||||
{
|
||||
@ -1924,7 +1921,7 @@ void GameView::NotifyPlaceSaveChanged(GameModel * sender)
|
||||
}
|
||||
else
|
||||
{
|
||||
placeSaveThumb = NULL;
|
||||
placeSaveThumb = nullptr;
|
||||
selectMode = SelectNone;
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,11 @@
|
||||
#pragma once
|
||||
#include <ctime>
|
||||
#include <deque>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include "common/String.h"
|
||||
#include "gui/interface/Window.h"
|
||||
#include "simulation/Sample.h"
|
||||
#include <ctime>
|
||||
#include <vector>
|
||||
#include <deque>
|
||||
|
||||
enum DrawMode
|
||||
{
|
||||
@ -116,7 +117,7 @@ private:
|
||||
ui::Point currentMouse;
|
||||
ui::Point mousePosition;
|
||||
|
||||
VideoBuffer * placeSaveThumb;
|
||||
std::unique_ptr<VideoBuffer> placeSaveThumb;
|
||||
ui::Point placeSaveOffset;
|
||||
|
||||
SimulationSample sample;
|
||||
|
@ -5,7 +5,7 @@
|
||||
namespace ui
|
||||
{
|
||||
Appearance::Appearance():
|
||||
texture(NULL),
|
||||
texture(nullptr),
|
||||
|
||||
VerticalAlign(AlignMiddle),
|
||||
HorizontalAlign(AlignCentre),
|
||||
@ -32,23 +32,13 @@ namespace ui
|
||||
icon(NoIcon)
|
||||
{}
|
||||
|
||||
VideoBuffer * Appearance::GetTexture()
|
||||
VideoBuffer const *Appearance::GetTexture()
|
||||
{
|
||||
return texture;
|
||||
return texture.get();
|
||||
}
|
||||
|
||||
void Appearance::SetTexture(VideoBuffer * texture)
|
||||
void Appearance::SetTexture(std::unique_ptr<VideoBuffer> texture)
|
||||
{
|
||||
delete this->texture;
|
||||
if(texture)
|
||||
this->texture = new VideoBuffer(texture);
|
||||
else
|
||||
this->texture = NULL;
|
||||
this->texture = std::move(texture);
|
||||
}
|
||||
|
||||
Appearance::~Appearance()
|
||||
{
|
||||
delete texture;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
#include <memory>
|
||||
#include "Border.h"
|
||||
#include "Colour.h"
|
||||
#include "graphics/Icons.h"
|
||||
@ -9,7 +10,8 @@ namespace ui
|
||||
class Appearance
|
||||
{
|
||||
private:
|
||||
VideoBuffer * texture;
|
||||
std::shared_ptr<VideoBuffer> texture;
|
||||
|
||||
public:
|
||||
enum HorizontalAlignment
|
||||
{
|
||||
@ -46,10 +48,9 @@ namespace ui
|
||||
|
||||
Icon icon;
|
||||
|
||||
VideoBuffer * GetTexture();
|
||||
void SetTexture(VideoBuffer * texture);
|
||||
VideoBuffer const *GetTexture();
|
||||
void SetTexture(std::unique_ptr<VideoBuffer> texture);
|
||||
|
||||
Appearance();
|
||||
~Appearance();
|
||||
};
|
||||
}
|
||||
|
@ -35,7 +35,7 @@
|
||||
|
||||
PreviewView::PreviewView():
|
||||
ui::Window(ui::Point(-1, -1), ui::Point((XRES/2)+210, (YRES/2)+150)),
|
||||
savePreview(NULL),
|
||||
savePreview(nullptr),
|
||||
submitCommentButton(NULL),
|
||||
addCommentBox(NULL),
|
||||
commentWarningLabel(NULL),
|
||||
@ -418,8 +418,7 @@ void PreviewView::OnKeyPress(int key, int scan, bool repeat, bool shift, bool ct
|
||||
void PreviewView::NotifySaveChanged(PreviewModel * sender)
|
||||
{
|
||||
SaveInfo * save = sender->GetSaveInfo();
|
||||
delete savePreview;
|
||||
savePreview = NULL;
|
||||
savePreview = nullptr;
|
||||
if(save)
|
||||
{
|
||||
votesUp = save->votesUp;
|
||||
@ -657,5 +656,4 @@ PreviewView::~PreviewView()
|
||||
RemoveComponent(submitCommentButton);
|
||||
delete submitCommentButton;
|
||||
}
|
||||
delete savePreview;
|
||||
}
|
||||
|
@ -1,8 +1,9 @@
|
||||
#pragma once
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
#include "common/String.h"
|
||||
#include "gui/interface/Window.h"
|
||||
#include <vector>
|
||||
#include <set>
|
||||
|
||||
namespace ui
|
||||
{
|
||||
@ -20,7 +21,7 @@ class PreviewController;
|
||||
class PreviewView: public ui::Window
|
||||
{
|
||||
PreviewController * c;
|
||||
VideoBuffer * savePreview;
|
||||
std::unique_ptr<VideoBuffer> savePreview;
|
||||
ui::Button * openButton;
|
||||
ui::Button * browserOpenButton;
|
||||
ui::Button * favButton;
|
||||
|
@ -20,7 +20,7 @@ void SaveRenderer::Flush(int begin, int end)
|
||||
std::fill(ren->graphicscache + begin, ren->graphicscache + end, gcache_item());
|
||||
}
|
||||
|
||||
VideoBuffer * SaveRenderer::Render(GameSave * save, bool decorations, bool fire, Renderer *renderModeSource)
|
||||
std::unique_ptr<VideoBuffer> SaveRenderer::Render(GameSave * save, bool decorations, bool fire, Renderer *renderModeSource)
|
||||
{
|
||||
std::lock_guard<std::mutex> gx(renderMutex);
|
||||
|
||||
@ -32,10 +32,7 @@ VideoBuffer * SaveRenderer::Render(GameSave * save, bool decorations, bool fire,
|
||||
ren->SetColourMode(renderModeSource->GetColourMode());
|
||||
}
|
||||
|
||||
int width, height;
|
||||
VideoBuffer * tempThumb = NULL;
|
||||
width = save->blockWidth;
|
||||
height = save->blockHeight;
|
||||
std::unique_ptr<VideoBuffer> tempThumb;
|
||||
|
||||
sim->clear_sim();
|
||||
|
||||
@ -43,11 +40,8 @@ VideoBuffer * SaveRenderer::Render(GameSave * save, bool decorations, bool fire,
|
||||
{
|
||||
ren->decorations_enable = true;
|
||||
ren->blackDecorations = !decorations;
|
||||
pixel * pData = NULL;
|
||||
pixel * dst;
|
||||
pixel * src = ren->vid;
|
||||
|
||||
ren->ClearAccumulation();
|
||||
ren->clearScreen();
|
||||
|
||||
if (fire)
|
||||
{
|
||||
@ -64,17 +58,8 @@ VideoBuffer * SaveRenderer::Render(GameSave * save, bool decorations, bool fire,
|
||||
ren->RenderBegin();
|
||||
ren->RenderEnd();
|
||||
|
||||
|
||||
pData = (pixel *)malloc(PIXELSIZE * ((width*CELL)*(height*CELL)));
|
||||
dst = pData;
|
||||
for(int i = 0; i < height*CELL; i++)
|
||||
{
|
||||
memcpy(dst, src, (width*CELL)*PIXELSIZE);
|
||||
dst+=(width*CELL);///PIXELSIZE;
|
||||
src+=WINDOWW;
|
||||
}
|
||||
tempThumb = new VideoBuffer(pData, width*CELL, height*CELL);
|
||||
free(pData);
|
||||
tempThumb = std::make_unique<VideoBuffer>(Vec2(save->blockWidth, save->blockHeight) * CELL);
|
||||
tempThumb->BlendImage(ren->Data(), 0xFF, ren->Size().OriginRect());
|
||||
}
|
||||
|
||||
return tempThumb;
|
||||
|
@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
#include "common/ExplicitSingleton.h"
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include "common/ExplicitSingleton.h"
|
||||
|
||||
class GameSave;
|
||||
class VideoBuffer;
|
||||
@ -14,8 +15,7 @@ class SaveRenderer: public ExplicitSingleton<SaveRenderer> {
|
||||
std::mutex renderMutex;
|
||||
public:
|
||||
SaveRenderer();
|
||||
VideoBuffer * Render(GameSave * save, bool decorations = true, bool fire = true, Renderer *renderModeSource = nullptr);
|
||||
VideoBuffer * Render(unsigned char * saveData, int saveDataSize, bool decorations = true, bool fire = true);
|
||||
std::unique_ptr<VideoBuffer> Render(GameSave * save, bool decorations = true, bool fire = true, Renderer *renderModeSource = nullptr);
|
||||
void Flush(int begin, int end);
|
||||
virtual ~SaveRenderer();
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user