1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-20 13:33:02 +01:00

Merge pull request #11122 from tupaschoal/reduce-c-casts

Reduce c-style cast
This commit is contained in:
Michael Steenbeek
2020-03-28 22:47:14 +01:00
committed by GitHub
22 changed files with 148 additions and 119 deletions

View File

@@ -176,12 +176,12 @@ namespace OpenRCT2::Audio
if (_pan <= 0.5)
{
_volume_l = 1.0;
_volume_r = (float)(1.0 / attenuation);
_volume_r = static_cast<float>(1.0 / attenuation);
}
else
{
_volume_r = 1.0;
_volume_l = (float)(1.0 / attenuation);
_volume_l = static_cast<float>(1.0 / attenuation);
}
}
@@ -260,7 +260,7 @@ namespace OpenRCT2::Audio
size_t readLen = _source->Read(dst, _offset, bytesToRead);
if (readLen > 0)
{
dst = (void*)((uintptr_t)dst + readLen);
dst = reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(dst) + readLen);
bytesToRead -= readLen;
bytesRead += readLen;
_offset += readLen;

View File

@@ -74,7 +74,7 @@ namespace OpenRCT2::Audio
want.samples = 2048;
want.callback = [](void* arg, uint8_t* dst, int32_t length) -> void {
auto mixer = static_cast<AudioMixerImpl*>(arg);
mixer->GetNextAudioChunk(dst, (size_t)length);
mixer->GetNextAudioChunk(dst, static_cast<size_t>(length));
};
want.userdata = this;
@@ -167,7 +167,7 @@ namespace OpenRCT2::Audio
IAudioSource* source = _musicSources[pathId];
if (source == nullptr)
{
const utf8* path = context_get_path_legacy((int32_t)pathId);
const utf8* path = context_get_path_legacy(static_cast<int32_t>(pathId));
source = AudioSource::CreateMemoryFromWAV(path, &_format);
if (source == nullptr)
{
@@ -258,7 +258,7 @@ namespace OpenRCT2::Audio
void MixChannel(ISDLAudioChannel* channel, uint8_t* data, size_t length)
{
int32_t byteRate = _format.GetByteRate();
int32_t numSamples = (int32_t)(length / byteRate);
int32_t numSamples = static_cast<int32_t>(length / byteRate);
double rate = 1;
if (_format.format == AUDIO_S16SYS)
{
@@ -283,8 +283,8 @@ namespace OpenRCT2::Audio
}
// Read raw PCM from channel
int32_t readSamples = (int32_t)(numSamples * rate);
size_t readLength = (size_t)(readSamples / cvt.len_ratio) * byteRate;
int32_t readSamples = static_cast<int32_t>(numSamples * rate);
size_t readLength = static_cast<size_t>(readSamples / cvt.len_ratio) * byteRate;
_channelBuffer.resize(readLength);
size_t bytesRead = channel->Read(_channelBuffer.data(), readLength);
@@ -312,7 +312,7 @@ namespace OpenRCT2::Audio
// Apply effects
if (rate != 1)
{
int32_t inRate = (int32_t)(bufferLen / byteRate);
int32_t inRate = static_cast<int32_t>(bufferLen / byteRate);
int32_t outRate = numSamples;
if (bytesRead != readLength)
{
@@ -320,7 +320,8 @@ namespace OpenRCT2::Audio
outRate = _format.freq * (1 / rate);
}
_effectBuffer.resize(length);
bufferLen = ApplyResample(channel, buffer, (int32_t)(bufferLen / byteRate), numSamples, inRate, outRate);
bufferLen = ApplyResample(
channel, buffer, static_cast<int32_t>(bufferLen / byteRate), numSamples, inRate, outRate);
buffer = _effectBuffer.data();
}
@@ -330,7 +331,8 @@ namespace OpenRCT2::Audio
// Finally mix on to destination buffer
size_t dstLength = std::min(length, bufferLen);
SDL_MixAudioFormat(data, (const uint8_t*)buffer, _format.format, (uint32_t)dstLength, mixVolume);
SDL_MixAudioFormat(
data, static_cast<const uint8_t*>(buffer), _format.format, static_cast<uint32_t>(dstLength), mixVolume);
channel->UpdateOldVolume();
}
@@ -357,7 +359,8 @@ namespace OpenRCT2::Audio
uint32_t inLen = srcSamples;
uint32_t outLen = dstSamples;
speex_resampler_process_interleaved_int(
resampler, (const spx_int16_t*)srcBuffer, &inLen, (spx_int16_t*)_effectBuffer.data(), &outLen);
resampler, static_cast<const spx_int16_t*>(srcBuffer), &inLen,
reinterpret_cast<spx_int16_t*>(_effectBuffer.data()), &outLen);
return outLen * byteRate;
}
@@ -369,10 +372,10 @@ namespace OpenRCT2::Audio
switch (_format.format)
{
case AUDIO_S16SYS:
EffectPanS16(channel, (int16_t*)buffer, (int32_t)(len / sampleSize));
EffectPanS16(channel, static_cast<int16_t*>(buffer), static_cast<int32_t>(len / sampleSize));
break;
case AUDIO_U8:
EffectPanU8(channel, (uint8_t*)buffer, (int32_t)(len / sampleSize));
EffectPanU8(channel, static_cast<uint8_t*>(buffer), static_cast<int32_t>(len / sampleSize));
break;
}
}
@@ -399,28 +402,28 @@ namespace OpenRCT2::Audio
break;
}
int32_t startVolume = (int32_t)(channel->GetOldVolume() * volumeAdjust);
int32_t endVolume = (int32_t)(channel->GetVolume() * volumeAdjust);
int32_t startVolume = static_cast<int32_t>(channel->GetOldVolume() * volumeAdjust);
int32_t endVolume = static_cast<int32_t>(channel->GetVolume() * volumeAdjust);
if (channel->IsStopping())
{
endVolume = 0;
}
int32_t mixVolume = (int32_t)(channel->GetVolume() * volumeAdjust);
int32_t mixVolume = static_cast<int32_t>(channel->GetVolume() * volumeAdjust);
if (startVolume != endVolume)
{
// Set to max since we are adjusting the volume ourselves
mixVolume = MIXER_VOLUME_MAX;
// Fade between volume levels to smooth out sound and minimize clicks from sudden volume changes
int32_t fadeLength = (int32_t)len / _format.BytesPerSample();
int32_t fadeLength = static_cast<int32_t>(len) / _format.BytesPerSample();
switch (_format.format)
{
case AUDIO_S16SYS:
EffectFadeS16((int16_t*)buffer, fadeLength, startVolume, endVolume);
EffectFadeS16(static_cast<int16_t*>(buffer), fadeLength, startVolume, endVolume);
break;
case AUDIO_U8:
EffectFadeU8((uint8_t*)buffer, fadeLength, startVolume, endVolume);
EffectFadeU8(static_cast<uint8_t*>(buffer), fadeLength, startVolume, endVolume);
break;
}
}
@@ -437,8 +440,8 @@ namespace OpenRCT2::Audio
for (int32_t i = 0; i < length * 2; i += 2)
{
data[i] = (int16_t)(data[i] * volumeL);
data[i + 1] = (int16_t)(data[i + 1] * volumeR);
data[i] = static_cast<int16_t>(data[i] * volumeL);
data[i + 1] = static_cast<int16_t>(data[i + 1] * volumeR);
volumeL += d_left;
volumeR += d_right;
}
@@ -453,9 +456,9 @@ namespace OpenRCT2::Audio
for (int32_t i = 0; i < length * 2; i += 2)
{
float t = (float)i / (length * 2);
data[i] = (uint8_t)(data[i] * ((1.0 - t) * oldVolumeL + t * volumeL));
data[i + 1] = (uint8_t)(data[i + 1] * ((1.0 - t) * oldVolumeR + t * volumeR));
float t = static_cast<float>(i) / (length * 2);
data[i] = static_cast<uint8_t>(data[i] * ((1.0 - t) * oldVolumeL + t * volumeL));
data[i + 1] = static_cast<uint8_t>(data[i + 1] * ((1.0 - t) * oldVolumeR + t * volumeR));
}
}
@@ -463,12 +466,12 @@ namespace OpenRCT2::Audio
{
static_assert(SDL_MIX_MAXVOLUME == MIXER_VOLUME_MAX, "Max volume differs between OpenRCT2 and SDL2");
float startvolume_f = (float)startvolume / SDL_MIX_MAXVOLUME;
float endvolume_f = (float)endvolume / SDL_MIX_MAXVOLUME;
float startvolume_f = static_cast<float>(startvolume) / SDL_MIX_MAXVOLUME;
float endvolume_f = static_cast<float>(endvolume) / SDL_MIX_MAXVOLUME;
for (int32_t i = 0; i < length; i++)
{
float t = (float)i / length;
data[i] = (int16_t)(data[i] * ((1 - t) * startvolume_f + t * endvolume_f));
float t = static_cast<float>(i) / length;
data[i] = static_cast<int16_t>(data[i] * ((1 - t) * startvolume_f + t * endvolume_f));
}
}
@@ -476,12 +479,12 @@ namespace OpenRCT2::Audio
{
static_assert(SDL_MIX_MAXVOLUME == MIXER_VOLUME_MAX, "Max volume differs between OpenRCT2 and SDL2");
float startvolume_f = (float)startvolume / SDL_MIX_MAXVOLUME;
float endvolume_f = (float)endvolume / SDL_MIX_MAXVOLUME;
float startvolume_f = static_cast<float>(startvolume) / SDL_MIX_MAXVOLUME;
float endvolume_f = static_cast<float>(endvolume) / SDL_MIX_MAXVOLUME;
for (int32_t i = 0; i < length; i++)
{
float t = (float)i / length;
data[i] = (uint8_t)(data[i] * ((1 - t) * startvolume_f + t * endvolume_f));
float t = static_cast<float>(i) / length;
data[i] = static_cast<uint8_t>(data[i] * ((1 - t) * startvolume_f + t * endvolume_f));
}
}
@@ -494,10 +497,10 @@ namespace OpenRCT2::Audio
{
size_t reqConvertBufferCapacity = len * cvt->len_mult;
_convertBuffer.resize(reqConvertBufferCapacity);
std::copy_n((const uint8_t*)src, len, _convertBuffer.data());
std::copy_n(static_cast<const uint8_t*>(src), len, _convertBuffer.data());
cvt->len = (int32_t)len;
cvt->buf = (uint8_t*)_convertBuffer.data();
cvt->len = static_cast<int32_t>(len);
cvt->buf = static_cast<uint8_t*>(_convertBuffer.data());
if (SDL_ConvertAudio(cvt) >= 0)
{
result = true;

View File

@@ -51,7 +51,7 @@ namespace OpenRCT2::Audio
int64_t currentPosition = SDL_RWtell(_rw);
if (currentPosition != -1)
{
size_t bytesToRead = (size_t)std::min<uint64_t>(len, _dataLength - offset);
size_t bytesToRead = static_cast<size_t>(std::min<uint64_t>(len, _dataLength - offset));
int64_t dataOffset = _dataBegin + offset;
if (currentPosition != dataOffset)
{

View File

@@ -57,12 +57,12 @@ namespace OpenRCT2::Audio
size_t bytesToRead = 0;
if (offset < _length)
{
bytesToRead = (size_t)std::min<uint64_t>(len, _length - offset);
bytesToRead = static_cast<size_t>(std::min<uint64_t>(len, _length - offset));
auto src = GetData();
if (src != nullptr)
{
std::copy_n(src + offset, bytesToRead, (uint8_t*)dst);
std::copy_n(src + offset, bytesToRead, reinterpret_cast<uint8_t*>(dst));
}
}
return bytesToRead;
@@ -164,7 +164,7 @@ namespace OpenRCT2::Audio
auto src = GetData();
auto cvtBuffer = std::vector<uint8_t>(_length * cvt.len_mult);
std::copy_n(src, _length, cvtBuffer.data());
cvt.len = (int32_t)_length;
cvt.len = static_cast<int32_t>(_length);
cvt.buf = cvtBuffer.data();
if (SDL_ConvertAudio(&cvt) >= 0)
{

View File

@@ -24,7 +24,7 @@ static std::vector<uint8_t> ReadToVector(std::istream& stream)
auto size = stream.tellg();
result.resize(size);
stream.seekg(0, std::ios_base::beg);
stream.read((char*)result.data(), size);
stream.read(reinterpret_cast<char*>(result.data()), size);
}
return result;
}
@@ -34,7 +34,7 @@ static std::vector<uint8_t> ReadToVector(std::istream& stream)
static Image ReadBitmap(std::istream& istream, IMAGE_FORMAT format)
{
auto buffer = ReadToVector(istream);
auto sdlStream = SDL_RWFromConstMem(buffer.data(), (int)buffer.size());
auto sdlStream = SDL_RWFromConstMem(buffer.data(), static_cast<int>(buffer.size()));
auto bitmap = SDL_LoadBMP_RW(sdlStream, 1);
if (bitmap != nullptr)
{
@@ -59,7 +59,7 @@ static Image ReadBitmap(std::istream& istream, IMAGE_FORMAT format)
std::fill(image.Pixels.begin(), image.Pixels.end(), 0xFF);
// Copy pixels over
auto src = (const uint8_t*)bitmap->pixels;
auto src = static_cast<const uint8_t*>(bitmap->pixels);
auto dst = image.Pixels.data();
if (numChannels == 4)
{

View File

@@ -33,7 +33,7 @@ namespace OpenRCT2
std::unique_ptr<IDrawingEngine> Create(
DRAWING_ENGINE_TYPE type, const std::shared_ptr<IUiContext>& uiContext) override
{
switch ((int32_t)type)
switch (static_cast<int32_t>(type))
{
case DRAWING_ENGINE_SOFTWARE:
return CreateSoftwareDrawingEngine(uiContext);

View File

@@ -57,7 +57,7 @@ public:
: X8DrawingEngine(uiContext)
, _uiContext(uiContext)
{
_window = (SDL_Window*)_uiContext->GetWindow();
_window = static_cast<SDL_Window*>(_uiContext->GetWindow());
}
~HardwareDisplayDrawingEngine() override
@@ -221,7 +221,8 @@ private:
else
#endif
{
CopyBitsToTexture(_screenTexture, _bits, (int32_t)_width, (int32_t)_height, _paletteHWMapped);
CopyBitsToTexture(
_screenTexture, _bits, static_cast<int32_t>(_width), static_cast<int32_t>(_height), _paletteHWMapped);
}
if (smoothNN)
{
@@ -264,7 +265,7 @@ private:
int32_t padding = pitch - (width * 4);
if (pitch == width * 4)
{
uint32_t* dst = (uint32_t*)pixels;
uint32_t* dst = static_cast<uint32_t*>(pixels);
for (int32_t i = width * height; i > 0; i--)
{
*dst++ = palette[*src++];
@@ -274,26 +275,26 @@ private:
{
if (pitch == (width * 2) + padding)
{
uint16_t* dst = (uint16_t*)pixels;
uint16_t* dst = static_cast<uint16_t*>(pixels);
for (int32_t y = height; y > 0; y--)
{
for (int32_t x = width; x > 0; x--)
{
const uint8_t lower = *(uint8_t*)(&palette[*src++]);
const uint8_t upper = *(uint8_t*)(&palette[*src++]);
const uint8_t lower = *reinterpret_cast<const uint8_t*>(&palette[*src++]);
const uint8_t upper = *reinterpret_cast<const uint8_t*>(&palette[*src++]);
*dst++ = (lower << 8) | upper;
}
dst = (uint16_t*)(((uint8_t*)dst) + padding);
dst = reinterpret_cast<uint16_t*>(reinterpret_cast<uint8_t*>(dst) + padding);
}
}
else if (pitch == width + padding)
{
uint8_t* dst = (uint8_t*)pixels;
uint8_t* dst = static_cast<uint8_t*>(pixels);
for (int32_t y = height; y > 0; y--)
{
for (int32_t x = width; x > 0; x--)
{
*dst++ = *(uint8_t*)(&palette[*src++]);
*dst++ = *reinterpret_cast<const uint8_t*>(&palette[*src++]);
}
dst += padding;
}
@@ -352,13 +353,13 @@ private:
auto timeLeft = GetDirtyVisualTime(x, y);
if (timeLeft > 0)
{
uint8_t alpha = (uint8_t)(timeLeft * 5 / 2);
uint8_t alpha = static_cast<uint8_t>(timeLeft * 5 / 2);
SDL_Rect ddRect;
ddRect.x = (int32_t)(x * _dirtyGrid.BlockWidth * scaleX);
ddRect.y = (int32_t)(y * _dirtyGrid.BlockHeight * scaleY);
ddRect.w = (int32_t)(_dirtyGrid.BlockWidth * scaleX);
ddRect.h = (int32_t)(_dirtyGrid.BlockHeight * scaleY);
ddRect.x = static_cast<int32_t>(x * _dirtyGrid.BlockWidth * scaleX);
ddRect.y = static_cast<int32_t>(y * _dirtyGrid.BlockHeight * scaleY);
ddRect.w = static_cast<int32_t>(_dirtyGrid.BlockWidth * scaleX);
ddRect.h = static_cast<int32_t>(_dirtyGrid.BlockHeight * scaleY);
SDL_SetRenderDrawColor(_sdlRenderer, 255, 255, 255, alpha);
SDL_RenderFillRect(_sdlRenderer, &ddRect);
@@ -369,7 +370,7 @@ private:
void ReadCentrePixel(uint32_t* pixel)
{
SDL_Rect centrePixelRegion = { (int32_t)(_width / 2), (int32_t)(_height / 2), 1, 1 };
SDL_Rect centrePixelRegion = { static_cast<int32_t>(_width / 2), static_cast<int32_t>(_height / 2), 1, 1 };
SDL_RenderReadPixels(_sdlRenderer, &centrePixelRegion, SDL_PIXELFORMAT_RGBA8888, pixel, sizeof(uint32_t));
}

View File

@@ -37,7 +37,7 @@ public:
: X8DrawingEngine(uiContext)
, _uiContext(uiContext)
{
_window = (SDL_Window*)_uiContext->GetWindow();
_window = static_cast<SDL_Window*>(_uiContext->GetWindow());
}
~SoftwareDrawingEngine() override
@@ -113,7 +113,7 @@ private:
}
// Copy pixels from the virtual screen buffer to the surface
std::copy_n(_bits, _surface->pitch * _surface->h, (uint8_t*)_surface->pixels);
std::copy_n(_bits, _surface->pitch * _surface->h, static_cast<uint8_t*>(_surface->pixels));
// Unlock the surface
if (SDL_MUSTLOCK(_surface))

View File

@@ -39,9 +39,11 @@ ApplyPaletteShader::ApplyPaletteShader()
glBufferData(GL_ARRAY_BUFFER, sizeof(VertexData), VertexData, GL_STATIC_DRAW);
glBindVertexArray(_vao);
glVertexAttribPointer(vPosition, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), (void*)offsetof(VDStruct, position));
glVertexAttribPointer(
vTextureCoordinate, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), (void*)offsetof(VDStruct, texturecoordinate));
vPosition, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), reinterpret_cast<void*>(offsetof(VDStruct, position)));
glVertexAttribPointer(
vTextureCoordinate, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct),
reinterpret_cast<void*>(offsetof(VDStruct, texturecoordinate)));
glEnableVertexAttribArray(vPosition);
glEnableVertexAttribArray(vTextureCoordinate);
@@ -72,7 +74,7 @@ void ApplyPaletteShader::SetTexture(GLuint texture)
void ApplyPaletteShader::SetPalette(const vec4* glPalette)
{
glUniform4fv(uPalette, 256, (const GLfloat*)glPalette);
glUniform4fv(uPalette, 256, reinterpret_cast<const GLfloat*>(glPalette));
}
void ApplyPaletteShader::Draw()

View File

@@ -39,9 +39,11 @@ ApplyTransparencyShader::ApplyTransparencyShader()
glBufferData(GL_ARRAY_BUFFER, sizeof(VertexData), VertexData, GL_STATIC_DRAW);
glBindVertexArray(_vao);
glVertexAttribPointer(vPosition, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), (void*)offsetof(VDStruct, position));
glVertexAttribPointer(
vTextureCoordinate, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), (void*)offsetof(VDStruct, texturecoordinate));
vPosition, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), reinterpret_cast<void*>(offsetof(VDStruct, position)));
glVertexAttribPointer(
vTextureCoordinate, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct),
reinterpret_cast<void*>(offsetof(VDStruct, texturecoordinate)));
glEnableVertexAttribArray(vPosition);
glEnableVertexAttribArray(vTextureCoordinate);

View File

@@ -39,16 +39,23 @@ DrawLineShader::DrawLineShader()
glBufferData(GL_ARRAY_BUFFER, sizeof(VertexData), VertexData, GL_STATIC_DRAW);
glBindVertexArray(_vao);
glVertexAttribPointer(vVertMat + 0, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), (void*)offsetof(VDStruct, mat[0]));
glVertexAttribPointer(vVertMat + 1, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), (void*)offsetof(VDStruct, mat[1]));
glVertexAttribPointer(vVertMat + 2, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), (void*)offsetof(VDStruct, mat[2]));
glVertexAttribPointer(vVertMat + 3, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), (void*)offsetof(VDStruct, mat[3]));
glVertexAttribPointer(
vVertMat + 0, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), reinterpret_cast<void*>(offsetof(VDStruct, mat[0])));
glVertexAttribPointer(
vVertMat + 1, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), reinterpret_cast<void*>(offsetof(VDStruct, mat[1])));
glVertexAttribPointer(
vVertMat + 2, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), reinterpret_cast<void*>(offsetof(VDStruct, mat[2])));
glVertexAttribPointer(
vVertMat + 3, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), reinterpret_cast<void*>(offsetof(VDStruct, mat[3])));
glBindBuffer(GL_ARRAY_BUFFER, _vboInstances);
glVertexAttribIPointer(vClip, 4, GL_INT, sizeof(DrawLineCommand), (void*)offsetof(DrawLineCommand, clip));
glVertexAttribIPointer(vBounds, 4, GL_INT, sizeof(DrawLineCommand), (void*)offsetof(DrawLineCommand, bounds));
glVertexAttribIPointer(vColour, 1, GL_UNSIGNED_INT, sizeof(DrawLineCommand), (void*)offsetof(DrawLineCommand, colour));
glVertexAttribIPointer(vDepth, 1, GL_INT, sizeof(DrawLineCommand), (void*)offsetof(DrawLineCommand, depth));
glVertexAttribIPointer(vClip, 4, GL_INT, sizeof(DrawLineCommand), reinterpret_cast<void*>(offsetof(DrawLineCommand, clip)));
glVertexAttribIPointer(
vBounds, 4, GL_INT, sizeof(DrawLineCommand), reinterpret_cast<void*>(offsetof(DrawLineCommand, bounds)));
glVertexAttribIPointer(
vColour, 1, GL_UNSIGNED_INT, sizeof(DrawLineCommand), reinterpret_cast<void*>(offsetof(DrawLineCommand, colour)));
glVertexAttribIPointer(
vDepth, 1, GL_INT, sizeof(DrawLineCommand), reinterpret_cast<void*>(offsetof(DrawLineCommand, depth)));
glEnableVertexAttribArray(vVertMat + 0);
glEnableVertexAttribArray(vVertMat + 1);
@@ -98,7 +105,7 @@ void DrawLineShader::DrawInstances(const LineCommandBatch& instances)
glBindBuffer(GL_ARRAY_BUFFER, _vboInstances);
glBufferData(GL_ARRAY_BUFFER, sizeof(DrawLineCommand) * instances.size(), instances.data(), GL_STREAM_DRAW);
glDrawArraysInstanced(GL_LINES, 0, 2, (GLsizei)instances.size());
glDrawArraysInstanced(GL_LINES, 0, 2, static_cast<GLsizei>(instances.size()));
}
#endif /* DISABLE_OPENGL */

View File

@@ -41,26 +41,39 @@ DrawRectShader::DrawRectShader()
glBindVertexArray(_vao);
glVertexAttribPointer(vVertMat + 0, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), (void*)offsetof(VDStruct, mat[0]));
glVertexAttribPointer(vVertMat + 1, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), (void*)offsetof(VDStruct, mat[1]));
glVertexAttribPointer(vVertMat + 2, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), (void*)offsetof(VDStruct, mat[2]));
glVertexAttribPointer(vVertMat + 3, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), (void*)offsetof(VDStruct, mat[3]));
glVertexAttribPointer(vVertVec, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), (void*)offsetof(VDStruct, vec));
glVertexAttribPointer(
vVertMat + 0, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), reinterpret_cast<void*>(offsetof(VDStruct, mat[0])));
glVertexAttribPointer(
vVertMat + 1, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), reinterpret_cast<void*>(offsetof(VDStruct, mat[1])));
glVertexAttribPointer(
vVertMat + 2, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), reinterpret_cast<void*>(offsetof(VDStruct, mat[2])));
glVertexAttribPointer(
vVertMat + 3, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), reinterpret_cast<void*>(offsetof(VDStruct, mat[3])));
glVertexAttribPointer(vVertVec, 2, GL_FLOAT, GL_FALSE, sizeof(VDStruct), reinterpret_cast<void*>(offsetof(VDStruct, vec)));
glBindBuffer(GL_ARRAY_BUFFER, _vboInstances);
glVertexAttribIPointer(vClip, 4, GL_INT, sizeof(DrawRectCommand), (void*)offsetof(DrawRectCommand, clip));
glVertexAttribIPointer(vClip, 4, GL_INT, sizeof(DrawRectCommand), reinterpret_cast<void*>(offsetof(DrawRectCommand, clip)));
glVertexAttribIPointer(
vTexColourAtlas, 1, GL_INT, sizeof(DrawRectCommand), (void*)offsetof(DrawRectCommand, texColourAtlas));
vTexColourAtlas, 1, GL_INT, sizeof(DrawRectCommand),
reinterpret_cast<void*>(offsetof(DrawRectCommand, texColourAtlas)));
glVertexAttribPointer(
vTexColourBounds, 4, GL_FLOAT, GL_FALSE, sizeof(DrawRectCommand), (void*)offsetof(DrawRectCommand, texColourBounds));
glVertexAttribIPointer(vTexMaskAtlas, 1, GL_INT, sizeof(DrawRectCommand), (void*)offsetof(DrawRectCommand, texMaskAtlas));
vTexColourBounds, 4, GL_FLOAT, GL_FALSE, sizeof(DrawRectCommand),
reinterpret_cast<void*>(offsetof(DrawRectCommand, texColourBounds)));
glVertexAttribIPointer(
vTexMaskAtlas, 1, GL_INT, sizeof(DrawRectCommand), reinterpret_cast<void*>(offsetof(DrawRectCommand, texMaskAtlas)));
glVertexAttribPointer(
vTexMaskBounds, 4, GL_FLOAT, GL_FALSE, sizeof(DrawRectCommand), (void*)offsetof(DrawRectCommand, texMaskBounds));
glVertexAttribIPointer(vPalettes, 3, GL_INT, sizeof(DrawRectCommand), (void*)offsetof(DrawRectCommand, palettes));
glVertexAttribIPointer(vFlags, 1, GL_INT, sizeof(DrawRectCommand), (void*)offsetof(DrawRectCommand, flags));
glVertexAttribIPointer(vColour, 1, GL_UNSIGNED_INT, sizeof(DrawRectCommand), (void*)offsetof(DrawRectCommand, colour));
glVertexAttribIPointer(vBounds, 4, GL_INT, sizeof(DrawRectCommand), (void*)offsetof(DrawRectCommand, bounds));
glVertexAttribIPointer(vDepth, 1, GL_INT, sizeof(DrawRectCommand), (void*)offsetof(DrawRectCommand, depth));
vTexMaskBounds, 4, GL_FLOAT, GL_FALSE, sizeof(DrawRectCommand),
reinterpret_cast<void*>(offsetof(DrawRectCommand, texMaskBounds)));
glVertexAttribIPointer(
vPalettes, 3, GL_INT, sizeof(DrawRectCommand), reinterpret_cast<void*>(offsetof(DrawRectCommand, palettes)));
glVertexAttribIPointer(
vFlags, 1, GL_INT, sizeof(DrawRectCommand), reinterpret_cast<void*>(offsetof(DrawRectCommand, flags)));
glVertexAttribIPointer(
vColour, 1, GL_UNSIGNED_INT, sizeof(DrawRectCommand), reinterpret_cast<void*>(offsetof(DrawRectCommand, colour)));
glVertexAttribIPointer(
vBounds, 4, GL_INT, sizeof(DrawRectCommand), reinterpret_cast<void*>(offsetof(DrawRectCommand, bounds)));
glVertexAttribIPointer(
vDepth, 1, GL_INT, sizeof(DrawRectCommand), reinterpret_cast<void*>(offsetof(DrawRectCommand, depth)));
glEnableVertexAttribArray(vVertMat + 0);
glEnableVertexAttribArray(vVertMat + 1);
@@ -152,7 +165,7 @@ void DrawRectShader::SetInstances(const RectCommandBatch& instances)
glBindBuffer(GL_ARRAY_BUFFER, _vboInstances);
glBufferData(GL_ARRAY_BUFFER, sizeof(DrawRectCommand) * instances.size(), instances.data(), GL_STREAM_DRAW);
_instanceCount = (GLsizei)instances.size();
_instanceCount = static_cast<GLsizei>(instances.size());
}
void DrawRectShader::DrawInstances()

View File

@@ -153,7 +153,7 @@ public:
uint32_t finalPixelOffset = width + pixelOffset;
uint32_t xPixelOffset = pixelOffset;
xPixelOffset += ((uint8_t)(patternX - patternStartXOffset)) % patternXSpace;
xPixelOffset += (static_cast<uint8_t>(patternX - patternStartXOffset)) % patternXSpace;
uint8_t patternPixel = pattern[patternYPos * 2 + 1];
for (; xPixelOffset < finalPixelOffset; xPixelOffset += patternXSpace)
@@ -204,7 +204,7 @@ public:
, _drawingContext(new OpenGLDrawingContext(this))
, _rainDrawer(_drawingContext)
{
_window = (SDL_Window*)_uiContext->GetWindow();
_window = static_cast<SDL_Window*>(_uiContext->GetWindow());
_bitsDPI.DrawingEngine = this;
# ifdef __ENABLE_LIGHTFX__
lightfx_set_available(false);
@@ -839,8 +839,8 @@ void OpenGLDrawingContext::DrawSpriteSolid(uint32_t image, int32_t x, int32_t y,
int32_t drawOffsetX = g1Element->x_offset;
int32_t drawOffsetY = g1Element->y_offset;
int32_t drawWidth = (uint16_t)g1Element->width;
int32_t drawHeight = (uint16_t)g1Element->height;
int32_t drawWidth = static_cast<uint16_t>(g1Element->width);
int32_t drawHeight = static_cast<uint16_t>(g1Element->height);
int32_t left = x + drawOffsetX;
int32_t top = y + drawOffsetY;
@@ -887,8 +887,8 @@ void OpenGLDrawingContext::DrawGlyph(uint32_t image, int32_t x, int32_t y, uint8
int32_t drawOffsetX = g1Element->x_offset;
int32_t drawOffsetY = g1Element->y_offset;
int32_t drawWidth = (uint16_t)g1Element->width;
int32_t drawHeight = (uint16_t)g1Element->height;
int32_t drawWidth = static_cast<uint16_t>(g1Element->width);
int32_t drawHeight = static_cast<uint16_t>(g1Element->height);
int32_t left = x + drawOffsetX;
int32_t top = y + drawOffsetY;
@@ -1003,14 +1003,14 @@ void OpenGLDrawingContext::SetDPI(rct_drawpixelinfo* dpi)
{
rct_drawpixelinfo* screenDPI = _engine->GetDPI();
# ifndef NDEBUG
size_t bitsSize = (size_t)screenDPI->height * (size_t)(screenDPI->width + screenDPI->pitch);
size_t bitsSize = static_cast<size_t>(screenDPI->height) * static_cast<size_t>(screenDPI->width + screenDPI->pitch);
# endif
size_t bitsOffset = (size_t)(dpi->bits - screenDPI->bits);
size_t bitsOffset = static_cast<size_t>(dpi->bits - screenDPI->bits);
assert(bitsOffset < bitsSize);
_clipLeft = (int32_t)(bitsOffset % (screenDPI->width + screenDPI->pitch));
_clipTop = (int32_t)(bitsOffset / (screenDPI->width + screenDPI->pitch));
_clipLeft = static_cast<int32_t>(bitsOffset % (screenDPI->width + screenDPI->pitch));
_clipTop = static_cast<int32_t>(bitsOffset / (screenDPI->width + screenDPI->pitch));
_clipRight = _clipLeft + (dpi->width / dpi->zoom_level);
_clipBottom = _clipTop + (dpi->height / dpi->zoom_level);
_offsetX = _clipLeft - dpi->x;

View File

@@ -72,7 +72,7 @@ OpenGLFramebuffer::~OpenGLFramebuffer()
void OpenGLFramebuffer::Bind() const
{
glBindFramebuffer(GL_FRAMEBUFFER, _id);
glViewport(0, 0, (GLsizei)_width, (GLsizei)_height);
glViewport(0, 0, static_cast<GLsizei>(_width), static_cast<GLsizei>(_height));
}
void OpenGLFramebuffer::BindDraw() const

View File

@@ -29,7 +29,7 @@ OpenGLShader::OpenGLShader(const char* name, GLenum type)
auto sourceCodeStr = sourceCode.c_str();
_id = glCreateShader(type);
glShaderSource(_id, 1, (const GLchar**)&sourceCodeStr, nullptr);
glShaderSource(_id, 1, static_cast<const GLchar**>(&sourceCodeStr), nullptr);
glCompileShader(_id);
GLint status;
@@ -84,7 +84,7 @@ std::string OpenGLShader::ReadSourceCode(const std::string& path)
}
auto fileData = std::string((size_t)fileLength + 1, '\0');
fs.Read((void*)fileData.data(), fileLength);
fs.Read(static_cast<void*>(fileData.data()), fileLength);
return fileData;
}

View File

@@ -86,7 +86,7 @@ BasicTextureInfo TextureCache::GetOrLoadImageTexture(uint32_t image)
// Load new texture.
unique_lock lock(_mutex);
index = (uint32_t)_textureCache.size();
index = static_cast<uint32_t>(_textureCache.size());
AtlasTextureInfo info = LoadImageTexture(image);
@@ -105,7 +105,7 @@ BasicTextureInfo TextureCache::GetOrLoadGlyphTexture(uint32_t image, uint8_t* pa
{
shared_lock lock(_mutex);
std::copy_n(palette, sizeof(glyphId.Palette), (uint8_t*)&glyphId.Palette);
std::copy_n(palette, sizeof(glyphId.Palette), reinterpret_cast<uint8_t*>(&glyphId.Palette));
auto kvp = _glyphTextureMap.find(glyphId);
if (kvp != _glyphTextureMap.end())
@@ -271,7 +271,7 @@ AtlasTextureInfo TextureCache::AllocateImage(int32_t imageWidth, int32_t imageHe
}
// If there is no such atlas, then create a new one
if ((int32_t)_atlases.size() >= _atlasesTextureIndicesLimit)
if (static_cast<int32_t>(_atlases.size()) >= _atlasesTextureIndicesLimit)
{
throw std::runtime_error("more texture atlases required, but device limit reached!");
}

View File

@@ -105,7 +105,7 @@ public:
_freeSlots.resize(_cols * _rows);
for (size_t i = 0; i < _freeSlots.size(); i++)
{
_freeSlots[i] = (GLuint)i;
_freeSlots[i] = static_cast<GLuint>(i);
}
}
@@ -146,7 +146,7 @@ public:
[[nodiscard]] int32_t GetFreeSlots() const
{
return (int32_t)_freeSlots.size();
return static_cast<int32_t>(_freeSlots.size());
}
static int32_t CalculateImageSizeOrder(int32_t actualWidth, int32_t actualHeight)
@@ -158,7 +158,7 @@ public:
actualSize = TEXTURE_CACHE_SMALLEST_SLOT;
}
return (int32_t)ceil(log2f((float)actualSize));
return static_cast<int32_t>(ceil(log2f(static_cast<float>(actualSize))));
}
private:
@@ -178,10 +178,10 @@ private:
[[nodiscard]] vec4 NormalizeCoordinates(const ivec4& coords) const
{
return vec4{
coords.x / (float)_atlasWidth,
coords.y / (float)_atlasHeight,
coords.z / (float)_atlasWidth,
coords.w / (float)_atlasHeight,
coords.x / static_cast<float>(_atlasWidth),
coords.y / static_cast<float>(_atlasHeight),
coords.z / static_cast<float>(_atlasWidth),
coords.w / static_cast<float>(_atlasHeight),
};
}
};

View File

@@ -199,7 +199,7 @@ static void window_changelog_scrollpaint(rct_window* w, rct_drawpixelinfo* dpi,
if (y + lineHeight < dpi->y || y >= dpi->y + dpi->height)
continue;
gfx_draw_string(dpi, (char*)line, w->colours[0], x, y);
gfx_draw_string(dpi, static_cast<const char*>(line), w->colours[0], x, y);
}
}

View File

@@ -1147,7 +1147,7 @@ static void window_editor_object_selection_scrollpaint(rct_window* w, rct_drawpi
if (*listItem.flags & (OBJECT_SELECTION_FLAG_IN_USE | OBJECT_SELECTION_FLAG_ALWAYS_REQUIRED))
colour2 |= COLOUR_FLAG_INSET;
gfx_draw_string(dpi, (char*)CheckBoxMarkString, colour2, x, y);
gfx_draw_string(dpi, static_cast<const char*>(CheckBoxMarkString), colour2, x, y);
}
x = gScreenFlags & SCREEN_FLAGS_TRACK_MANAGER ? 0 : 15;

View File

@@ -1175,7 +1175,7 @@ static void window_editor_objective_options_rides_scrollpaint(rct_window* w, rct
{
gCurrentFontSpriteBase = stringId == STR_WINDOW_COLOUR_2_STRINGID ? FONT_SPRITE_BASE_MEDIUM_EXTRA_DARK
: FONT_SPRITE_BASE_MEDIUM_DARK;
gfx_draw_string(dpi, (char*)CheckBoxMarkString, w->colours[1] & 0x7F, 2, y);
gfx_draw_string(dpi, static_cast<const char*>(CheckBoxMarkString), w->colours[1] & 0x7F, 2, y);
}
// Ride name

View File

@@ -756,7 +756,7 @@ static void window_multiplayer_groups_mouseup(rct_window* w, rct_widgetindex wid
case WIDX_RENAME_GROUP:;
int32_t groupIndex = network_get_group_index(_selectedGroup);
const utf8* groupName = network_get_group_name(groupIndex);
window_text_input_raw_open(w, widgetIndex, STR_GROUP_NAME, STR_ENTER_NEW_NAME_FOR_THIS_GROUP, (utf8*)groupName, 32);
window_text_input_raw_open(w, widgetIndex, STR_GROUP_NAME, STR_ENTER_NEW_NAME_FOR_THIS_GROUP, groupName, 32);
break;
}
}

View File

@@ -921,7 +921,8 @@ void window_themes_scrollpaint(rct_window* w, rct_drawpixelinfo* dpi, int32_t sc
{
gCurrentFontSpriteBase = FONT_SPRITE_BASE_MEDIUM_DARK;
gfx_draw_string(
dpi, (char*)CheckBoxMarkString, w->colours[1] & 0x7F, _button_offset_x + 12 * j, y + _check_offset_y);
dpi, static_cast<const char*>(CheckBoxMarkString), w->colours[1] & 0x7F, _button_offset_x + 12 * j,
y + _check_offset_y);
}
}
}