1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-04 13:42:55 +01:00

Remove most of remaining memory functions from libopenrct2ui

This commit is contained in:
Ted John
2018-01-21 11:14:46 +00:00
parent 131286f758
commit cebe13984f
11 changed files with 29 additions and 42 deletions

View File

@@ -23,7 +23,6 @@
#include <openrct2/Context.h>
#include <openrct2/core/Guard.hpp>
#include <openrct2/core/Math.hpp>
#include <openrct2/core/Memory.hpp>
#include <openrct2/core/Util.hpp>
#include <openrct2/audio/audio.h>
#include <openrct2/audio/AudioChannel.h>

View File

@@ -19,7 +19,6 @@
#include <openrct2/common.h>
#include <SDL.h>
#include <openrct2/core/Math.hpp>
#include <openrct2/core/Memory.hpp>
#include <openrct2/audio/AudioMixer.h>
#include <openrct2/audio/AudioSource.h>
#include "AudioContext.h"

View File

@@ -16,33 +16,29 @@
#ifndef DISABLE_OPENGL
#include <algorithm>
#include <cmath>
#include <unordered_map>
#include <SDL.h>
#include <openrct2/config/Config.h>
#include <openrct2/core/Console.hpp>
#include <openrct2/core/Math.hpp>
#include <openrct2/core/Memory.hpp>
#include <openrct2/drawing/Drawing.h>
#include <openrct2/drawing/IDrawingContext.h>
#include <openrct2/drawing/IDrawingEngine.h>
#include <openrct2/drawing/LightFX.h>
#include <openrct2/drawing/Rain.h>
#include <openrct2/interface/Screenshot.h>
#include <openrct2/ui/UiContext.h>
#include <openrct2-ui/interface/Window.h>
#include <openrct2/Intro.h>
#include <openrct2/drawing/Drawing.h>
#include <openrct2/drawing/LightFX.h>
#include <openrct2-ui/interface/Window.h>
#include <openrct2/ui/UiContext.h>
#include "../DrawingEngines.h"
#include "GLSLTypes.h"
#include "OpenGLAPI.h"
#include "OpenGLFramebuffer.h"
#include "ApplyPaletteShader.h"
#include "DrawCommands.h"
#include "DrawLineShader.h"
#include "DrawRectShader.h"
#include "GLSLTypes.h"
#include "OpenGLAPI.h"
#include "OpenGLFramebuffer.h"
#include "SwapFramebuffer.h"
#include "TextureCache.h"
#include "TransparencyDepth.h"
@@ -346,27 +342,27 @@ private:
uint8 * newBits = new uint8[newBitsSize];
if (_bits == nullptr)
{
Memory::Set(newBits, 0, newBitsSize);
std::fill_n(newBits, newBitsSize, 0);
}
else
{
if (_pitch == pitch)
{
Memory::Copy(newBits, _bits, Math::Min(_bitsSize, newBitsSize));
std::copy_n(_bits, std::min(_bitsSize, newBitsSize), newBits);
}
else
{
uint8 * src = _bits;
uint8 * dst = newBits;
uint32 minWidth = Math::Min(_width, width);
uint32 minHeight = Math::Min(_height, height);
uint32 minWidth = std::min(_width, width);
uint32 minHeight = std::min(_height, height);
for (uint32 y = 0; y < minHeight; y++)
{
Memory::Copy(dst, src, minWidth);
std::copy_n(src, minWidth, dst);
if (pitch - minWidth > 0)
{
Memory::Set(dst + minWidth, 0, pitch - minWidth);
std::fill_n(dst + minWidth, pitch - minWidth, 0);
}
src += _pitch;
dst += pitch;
@@ -716,8 +712,8 @@ void OpenGLDrawingContext::DrawSpriteRawMasked(sint32 x, sint32 y, uint32 maskIm
sint32 drawOffsetX = g1ElementMask->x_offset;
sint32 drawOffsetY = g1ElementMask->y_offset;
sint32 drawWidth = Math::Min(g1ElementMask->width, g1ElementColour->width);
sint32 drawHeight = Math::Min(g1ElementMask->height, g1ElementColour->height);
sint32 drawWidth = std::min(g1ElementMask->width, g1ElementColour->width);
sint32 drawHeight = std::min(g1ElementMask->height, g1ElementColour->height);
sint32 left = x + drawOffsetX;
sint32 top = y + drawOffsetY;

View File

@@ -16,9 +16,10 @@
#ifndef DISABLE_OPENGL
#include <algorithm>
#include <memory>
#include <openrct2/common.h>
#include <SDL_video.h>
#include <openrct2/core/Memory.hpp>
#include "OpenGLFramebuffer.h"
constexpr GLuint BACKBUFFER_ID = 0;
@@ -94,21 +95,20 @@ void OpenGLFramebuffer::GetPixels(rct_drawpixelinfo &dpi) const
{
assert(dpi.width == _width && dpi.height == _height);
uint8 * pixels = Memory::Allocate<uint8>(_width * _height);
auto pixels = std::make_unique<uint8[]>(_width * _height);
glBindTexture(GL_TEXTURE_2D, _texture);
glPixelStorei(GL_PACK_ALIGNMENT, 1);
glGetTexImage(GL_TEXTURE_2D, 0, GL_RED_INTEGER, GL_UNSIGNED_BYTE, pixels);
glGetTexImage(GL_TEXTURE_2D, 0, GL_RED_INTEGER, GL_UNSIGNED_BYTE, pixels.get());
// Flip pixels vertically on copy
uint8 * src = pixels + ((_height - 1) * _width);
uint8 * src = pixels.get() + ((_height - 1) * _width);
uint8 * dst = dpi.bits;
for (sint32 y = 0; y < _height; y++)
{
Memory::Copy(dst, src, _width);
std::copy_n(src, _width, dst);
src -= _width;
dst += dpi.width + dpi.pitch;
}
Memory::Free(pixels);
}
void OpenGLFramebuffer::SwapColourBuffer(OpenGLFramebuffer &other)

View File

@@ -16,12 +16,11 @@
#ifndef DISABLE_OPENGL
#include <vector>
#include <algorithm>
#include <stdexcept>
#include <openrct2/core/Memory.hpp>
#include "TextureCache.h"
#include <vector>
#include <openrct2/drawing/Drawing.h>
#include "TextureCache.h"
constexpr uint32 UNUSED_INDEX = 0xFFFFFFFF;
@@ -95,7 +94,7 @@ BasicTextureInfo TextureCache::GetOrLoadGlyphTexture(uint32 image, uint8 * palet
{
GlyphId glyphId;
glyphId.Image = image;
Memory::Copy<void>(&glyphId.Palette, palette, sizeof(glyphId.Palette));
std::copy_n((uint8 *)&glyphId.Palette, sizeof(glyphId.Palette), palette);
auto kvp = _glyphTextureMap.find(glyphId);
if (kvp != _glyphTextureMap.end())
@@ -290,8 +289,8 @@ void TextureCache::FreeTextures()
rct_drawpixelinfo TextureCache::CreateDPI(sint32 width, sint32 height)
{
size_t numPixels = width * height;
uint8 * pixels8 = Memory::Allocate<uint8>(numPixels);
Memory::Set(pixels8, 0, numPixels);
auto pixels8 = new uint8[numPixels];
std::fill_n(pixels8, numPixels, 0);
rct_drawpixelinfo dpi;
dpi.bits = pixels8;
@@ -306,7 +305,7 @@ rct_drawpixelinfo TextureCache::CreateDPI(sint32 width, sint32 height)
void TextureCache::DeleteDPI(rct_drawpixelinfo dpi)
{
Memory::Free(dpi.bits);
delete dpi.bits;
}
GLuint TextureCache::GetAtlasesTexture()

View File

@@ -19,7 +19,6 @@
#include <openrct2/core/Console.hpp>
#include <openrct2/core/File.h>
#include <openrct2/core/FileStream.hpp>
#include <openrct2/core/Memory.hpp>
#include <openrct2/core/Path.hpp>
#include <openrct2/core/String.hpp>
#include <openrct2/PlatformEnvironment.h>

View File

@@ -21,7 +21,6 @@
#include <openrct2/object/ObjectManager.h>
#include <openrct2/ride/TrackDesignRepository.h>
#include <openrct2/core/Math.hpp>
#include <openrct2/core/Memory.hpp>
#include <openrct2-ui/windows/Window.h>
#include <openrct2/audio/audio.h>

View File

@@ -21,7 +21,6 @@
#include <openrct2/Context.h>
#include <openrct2/core/Math.hpp>
#include <openrct2/core/Util.hpp>
#include <openrct2/core/Memory.hpp>
#include <openrct2/Game.h>
#include <openrct2/Input.h>
#include <openrct2/localisation/Localisation.h>

View File

@@ -16,7 +16,6 @@
#include <string>
#include <vector>
#include <openrct2/core/Memory.hpp>
#include <openrct2/localisation/Localisation.h>
#include <openrct2/object/ObjectManager.h>
#include <openrct2/platform/platform.h>

View File

@@ -17,7 +17,6 @@
#include <vector>
#include <openrct2/audio/audio.h>
#include <openrct2/config/Config.h>
#include <openrct2/core/Memory.hpp>
#include <openrct2/interface/themes.h>
#include <openrct2/localisation/Date.h>
#include <openrct2/localisation/Localisation.h>

View File

@@ -18,7 +18,6 @@
#include <openrct2/audio/audio.h>
#include <openrct2/Context.h>
#include <openrct2/core/Math.hpp>
#include <openrct2/core/Memory.hpp>
#include <openrct2/core/String.hpp>
#include <openrct2/drawing/IDrawingEngine.h>
#include <openrct2/Editor.h>