1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-22 22:34:33 +01:00

Fix indentation and code style in various files

This commit is contained in:
Alexander Overvoorde
2016-07-27 16:31:25 +02:00
parent 96be7bd861
commit 3842728f38
5 changed files with 75 additions and 41 deletions

View File

@@ -899,15 +899,18 @@ void OpenGLDrawingContext::DrawGlyph(uint32 image, sint32 x, sint32 y, uint8 * p
_commandBuffers.images.push_back(command);
}
void OpenGLDrawingContext::FlushCommandBuffers() {
void OpenGLDrawingContext::FlushCommandBuffers()
{
FlushRectangles();
FlushLines();
FlushImages();
}
void OpenGLDrawingContext::FlushRectangles() {
for (const auto& command : _commandBuffers.rectangles) {
void OpenGLDrawingContext::FlushRectangles()
{
for (const auto& command : _commandBuffers.rectangles)
{
_fillRectShader->Use();
_fillRectShader->SetFlags(command.flags);
_fillRectShader->SetSourceFramebuffer(command.sourceFramebuffer);
@@ -921,7 +924,8 @@ void OpenGLDrawingContext::FlushRectangles() {
}
void OpenGLDrawingContext::FlushLines() {
for (const auto& command : _commandBuffers.lines) {
for (const auto& command : _commandBuffers.lines)
{
_drawLineShader->Use();
_drawLineShader->SetColour(command.colour);
_drawLineShader->SetClip(command.clip[0], command.clip[1], command.clip[2], command.clip[3]);
@@ -931,7 +935,8 @@ void OpenGLDrawingContext::FlushLines() {
_commandBuffers.lines.clear();
}
void OpenGLDrawingContext::FlushImages() {
void OpenGLDrawingContext::FlushImages()
{
if (_commandBuffers.images.size() == 0) return;
OpenGLAPI::SetTexture(0, GL_TEXTURE_2D_ARRAY, _textureCache->GetAtlasesTexture());
@@ -939,7 +944,8 @@ void OpenGLDrawingContext::FlushImages() {
std::vector<DrawImageInstance> instances;
instances.reserve(_commandBuffers.images.size());
for (const auto& command : _commandBuffers.images) {
for (const auto& command : _commandBuffers.images)
{
DrawImageInstance instance;
instance.clip = {command.clip[0], command.clip[1], command.clip[2], command.clip[3]};

View File

@@ -82,8 +82,10 @@ CachedTextureInfo TextureCache::GetOrLoadGlyphTexture(uint32 image, uint8 * pale
return cacheInfo;
}
void TextureCache::CreateAtlasesTexture() {
if (!_atlasesTextureInitialised) {
void TextureCache::CreateAtlasesTexture()
{
if (!_atlasesTextureInitialised)
{
// Determine width and height to use for texture atlases
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &_atlasesTextureDimensions);
if (_atlasesTextureDimensions > TEXTURE_CACHE_MAX_ATLAS_SIZE) {
@@ -106,13 +108,14 @@ void TextureCache::CreateAtlasesTexture() {
}
}
void TextureCache::EnlargeAtlasesTexture(GLuint newEntries) {
void TextureCache::EnlargeAtlasesTexture(GLuint newEntries)
{
CreateAtlasesTexture();
GLuint newIndices = _atlasesTextureIndices + newEntries;
// Retrieve current array data
std::vector<char> oldPixels(_atlasesTextureDimensions * _atlasesTextureDimensions * _atlasesTextureIndices);
auto oldPixels = std::vector<char>(_atlasesTextureDimensions * _atlasesTextureDimensions * _atlasesTextureIndices);
glGetTexImage(GL_TEXTURE_2D_ARRAY, 0, GL_RED_INTEGER, GL_UNSIGNED_BYTE, oldPixels.data());
// Reallocate array
@@ -168,18 +171,22 @@ void * TextureCache::GetImageAsARGB(uint32 image, uint32 tertiaryColour, uint32
return pixels32;
}
CachedTextureInfo TextureCache::AllocateImage(int imageWidth, int imageHeight) {
CachedTextureInfo TextureCache::AllocateImage(int imageWidth, int imageHeight)
{
CreateAtlasesTexture();
// Find an atlas that fits this image
for (Atlas& atlas : _atlases) {
if (atlas.GetFreeSlots() > 0 && atlas.IsImageSuitable(imageWidth, imageHeight)) {
for (Atlas& atlas : _atlases)
{
if (atlas.GetFreeSlots() > 0 && atlas.IsImageSuitable(imageWidth, imageHeight))
{
return atlas.Allocate(imageWidth, imageHeight);
}
}
// If there is no such atlas, then create a new one
if ((int) _atlases.size() >= _atlasesTextureIndicesLimit) {
if ((int) _atlases.size() >= _atlasesTextureIndicesLimit)
{
throw std::runtime_error("more texture atlases required, but device limit reached!");
}
@@ -187,7 +194,7 @@ CachedTextureInfo TextureCache::AllocateImage(int imageWidth, int imageHeight) {
int atlasSize = (int) powf(2, (float) Atlas::CalculateImageSizeOrder(imageWidth, imageHeight));
#ifdef DEBUG
printf("new texture atlas #%d (size %d) allocated\n", atlasIndex, atlasSize);
log_verbose("new texture atlas #%d (size %d) allocated\n", atlasIndex, atlasSize);
#endif
_atlases.push_back(std::move(Atlas(atlasIndex, atlasSize)));
@@ -296,7 +303,8 @@ void TextureCache::DeleteDPI(rct_drawpixelinfo* dpi)
delete dpi;
}
GLuint TextureCache::GetAtlasesTexture() {
GLuint TextureCache::GetAtlasesTexture()
{
return _atlasesTexture;
}

View File

@@ -16,9 +16,9 @@
#pragma once
#include <algorithm>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <SDL_pixels.h>
#include "../../../common.h"
#include "OpenGLAPI.h"
@@ -62,7 +62,8 @@ constexpr int TEXTURE_CACHE_MAX_ATLAS_SIZE = 2048;
constexpr int TEXTURE_CACHE_SMALLEST_SLOT = 32;
// Location of an image (texture atlas index, slot and normalized coordinates)
struct CachedTextureInfo {
struct CachedTextureInfo
{
GLuint index;
GLuint slot;
vec4i bounds;
@@ -72,7 +73,8 @@ struct CachedTextureInfo {
// Represents a texture atlas that images of a given maximum size can be allocated from
// Atlases are all stored in the same 2D texture array, occupying the specified index
// Slots in atlases are always squares.
class Atlas {
class Atlas
{
private:
GLuint _index;
int _imageSize;
@@ -82,12 +84,14 @@ private:
int _cols, _rows;
public:
Atlas(GLuint index, int imageSize) {
Atlas(GLuint index, int imageSize)
{
_index = index;
_imageSize = imageSize;
}
void Initialise(int atlasWidth, int atlasHeight) {
void Initialise(int atlasWidth, int atlasHeight)
{
_atlasWidth = atlasWidth;
_atlasHeight = atlasHeight;
@@ -95,12 +99,14 @@ public:
_rows = _atlasHeight / _imageSize;
_freeSlots.resize(_cols * _rows);
for (size_t i = 0; i < _freeSlots.size(); i++) {
for (size_t i = 0; i < _freeSlots.size(); i++)
{
_freeSlots[i] = i;
}
}
CachedTextureInfo Allocate(int actualWidth, int actualHeight) {
CachedTextureInfo Allocate(int actualWidth, int actualHeight)
{
assert(_freeSlots.size() > 0);
GLuint slot = _freeSlots.back();
@@ -108,10 +114,17 @@ public:
auto bounds = GetSlotCoordinates(slot, actualWidth, actualHeight);
return {_index, slot, bounds, NormalizeCoordinates(bounds)};
return
{
_index,
slot,
bounds,
NormalizeCoordinates(bounds)
};
}
void Free(const CachedTextureInfo& info) {
void Free(const CachedTextureInfo& info)
{
assert(_index == info.index);
_freeSlots.push_back(info.slot);
@@ -119,18 +132,21 @@ public:
// Checks if specified image would be tightly packed in this atlas
// by checking if it is within the right power of 2 range
bool IsImageSuitable(int actualWidth, int actualHeight) const {
bool IsImageSuitable(int actualWidth, int actualHeight) const
{
int imageOrder = CalculateImageSizeOrder(actualWidth, actualHeight);
int atlasOrder = (int) log2(_imageSize);
return imageOrder == atlasOrder;
}
int GetFreeSlots() const {
int GetFreeSlots() const
{
return (int) _freeSlots.size();
}
static int CalculateImageSizeOrder(int actualWidth, int actualHeight) {
static int CalculateImageSizeOrder(int actualWidth, int actualHeight)
{
int actualSize = std::max(actualWidth, actualHeight);
if (actualSize < TEXTURE_CACHE_SMALLEST_SLOT) {
@@ -141,11 +157,13 @@ public:
}
private:
vec4i GetSlotCoordinates(GLuint slot, int actualWidth, int actualHeight) const {
vec4i GetSlotCoordinates(GLuint slot, int actualWidth, int actualHeight) const
{
int row = slot / _cols;
int col = slot % _cols;
return vec4i{
return vec4i
{
_imageSize * col,
_imageSize * row,
_imageSize * col + actualWidth,
@@ -153,8 +171,10 @@ private:
};
}
vec4f NormalizeCoordinates(const vec4i& coords) const {
return vec4f{
vec4f NormalizeCoordinates(const vec4i& coords) const
{
return vec4f
{
coords.x / (float) _atlasWidth,
coords.y / (float) _atlasHeight,
coords.z / (float) _atlasWidth,

View File

@@ -307,16 +307,16 @@ static int _frames;
static void rct2_measure_fps()
{
_frames++;
_frames++;
time_t currentTime = time(NULL);
time_t currentTime = time(NULL);
if (currentTime != _lastSecond) {
_currentFPS = _frames;
_frames = 0;
}
if (currentTime != _lastSecond) {
_currentFPS = _frames;
_frames = 0;
}
_lastSecond = currentTime;
_lastSecond = currentTime;
}
static void rct2_draw_fps(rct_drawpixelinfo *dpi)
@@ -333,7 +333,7 @@ static void rct2_draw_fps(rct_drawpixelinfo *dpi)
ch = utf8_write_codepoint(ch, FORMAT_MEDIUMFONT);
ch = utf8_write_codepoint(ch, FORMAT_OUTLINE);
ch = utf8_write_codepoint(ch, FORMAT_WHITE);
sprintf(ch, "%d", _currentFPS);
// Draw Text

View File

@@ -587,7 +587,7 @@ static void window_options_mouseup(rct_window *w, int widgetIndex)
switch (widgetIndex) {
case WIDX_UNCAP_FPS_CHECKBOX:
gConfigGeneral.uncap_fps ^= 1;
drawing_engine_set_fps_uncapped(gConfigGeneral.uncap_fps);
drawing_engine_set_fps_uncapped(gConfigGeneral.uncap_fps);
config_save_default();
window_invalidate(w);
break;