Skip to content

Commit 4b8ee66

Browse files
author
LocalIdentity
committed
Type casting fixes
1 parent 154ded4 commit 4b8ee66

File tree

3 files changed

+21
-24
lines changed

3 files changed

+21
-24
lines changed

engine/render/r_font.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -160,20 +160,20 @@ int r_font_c::StringWidthInternal(f_fontHeight_s* fh, std::u32string_view str, i
160160
else if (ch >= (unsigned)fh->numGlyph) {
161161
auto tofu = BuildTofuString(ch);
162162
for (auto cp : tofu) {
163-
width += (float)measureCodepoint(tofuFont.fh, cp);
163+
width += measureCodepoint(tofuFont.fh, cp);
164164
width = std::ceil(width);
165165
}
166166
++idx;
167167
}
168168
else if (ch == U'\t') {
169169
auto& glyph = fh->Glyph(' ');
170170
int spWidth = glyph.width + glyph.spLeft + glyph.spRight;
171-
width += (float)(spWidth << 2) * scale;
171+
width += spWidth * 4 * scale;
172172
width = std::ceil(width);
173173
++idx;
174174
}
175175
else {
176-
width += (float)measureCodepoint(fh, ch) * scale;
176+
width += measureCodepoint(fh, ch) * scale;
177177
width = std::ceil(width);
178178
++idx;
179179
}
@@ -191,7 +191,7 @@ int r_font_c::StringWidth(int height, std::u32string_view str)
191191
auto lineEnd = std::find(I, str.end(), U'\n');
192192
if (I != lineEnd) {
193193
std::u32string_view line(&*I, std::distance(I, lineEnd));
194-
int lw = (int)StringWidthInternal(fh, line, height, scale);
194+
int lw = StringWidthInternal(fh, line, height, scale);
195195
max = (std::max)(max, lw);
196196
}
197197
if (lineEnd == str.end()) {
@@ -224,7 +224,7 @@ size_t r_font_c::StringCursorInternal(f_fontHeight_s* fh, std::u32string_view st
224224
else if (*I >= (unsigned)fh->numGlyph) {
225225
auto tofu = BuildTofuString(*I);
226226
for (auto cp : tofu) {
227-
x += (float)measureCodepoint(tofuFont.fh, cp);
227+
x += measureCodepoint(tofuFont.fh, cp);
228228
x = std::ceil(x);
229229
if (curX <= x) {
230230
return std::distance(str.begin(), I);
@@ -234,8 +234,8 @@ size_t r_font_c::StringCursorInternal(f_fontHeight_s* fh, std::u32string_view st
234234
}
235235
else if (*I == U'\t') {
236236
auto& glyph = fh->Glyph(' ');
237-
float fullWidth = (float)(glyph.width + glyph.spLeft + glyph.spRight) * 4.0f * scale;
238-
float halfWidth = std::ceil(fullWidth * 0.5f);
237+
float fullWidth = (glyph.width + glyph.spLeft + glyph.spRight) * 4.0f * scale;
238+
float halfWidth = std::ceil(fullWidth / 2.0f);
239239
x += halfWidth;
240240
x = std::ceil(x);
241241
if (curX <= x) {
@@ -249,7 +249,7 @@ size_t r_font_c::StringCursorInternal(f_fontHeight_s* fh, std::u32string_view st
249249
++I;
250250
}
251251
else {
252-
x += (float)measureCodepoint(fh, *I) * scale;
252+
x += measureCodepoint(fh, *I) * scale;
253253
x = std::ceil(x);
254254
if (curX <= x) {
255255
break;
@@ -348,7 +348,7 @@ void r_font_c::DrawTextLine(scp_t pos, int align, int height, col4_t col, std::u
348348
float y = std::floor(pos[Y]);
349349
if (align != F_LEFT) {
350350
// Calculate the real width of the string
351-
float width = (float)StringWidthInternal(fh, str, height, scale);
351+
float width = StringWidthInternal(fh, str, height, scale);
352352
switch (align) {
353353
case F_CENTRE:
354354
x = floor((renderer->VirtualScreenWidth() - width) / 2.0f + pos[X]);

engine/render/r_main.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1864,17 +1864,14 @@ int r_renderer_c::VirtualScreenHeight() {
18641864
float r_renderer_c::VirtualScreenScaleFactor() {
18651865
if (apiDpiAware) {
18661866
if (dpiScaleOverridePercent > 0) {
1867-
return (float)dpiScaleOverridePercent / 100.0f;
1867+
return dpiScaleOverridePercent / 100.0f;
18681868
}
18691869
return sys->video->vid.dpiScale;
18701870
}
18711871
return 1.0f;
18721872
}
18731873

18741874
void r_renderer_c::SetDpiScaleOverridePercent(int percent) {
1875-
if (percent < 0) {
1876-
percent = 0;
1877-
}
18781875
dpiScaleOverridePercent = percent;
18791876
}
18801877

ui_api.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,8 +1069,8 @@ static int l_DrawString(lua_State* L)
10691069
static const char* alignMap[6] = { "LEFT", "CENTER", "RIGHT", "CENTER_X", "RIGHT_X", NULL };
10701070
static const char* fontMap[4] = { "FIXED", "VAR", "VAR BOLD", NULL };
10711071
const float dpiScale = ui->renderer->VirtualScreenScaleFactor();
1072-
const float left = (float)lua_tonumber(L, 1) * dpiScale;
1073-
const float top = (float)lua_tonumber(L, 2) * dpiScale;
1072+
const float left = lua_tonumber(L, 1) * dpiScale;
1073+
const float top = lua_tonumber(L, 2) * dpiScale;
10741074
const int scaledHeight = (int)std::lround((double)lua_tointeger(L, 4) * (double)dpiScale);
10751075
ui->renderer->DrawString(
10761076
left,
@@ -1095,8 +1095,8 @@ static int l_DrawStringWidth(lua_State* L)
10951095
ui->LAssert(L, lua_isstring(L, 3), "DrawStringWidth() argument 3: expected string, got %s", luaL_typename(L, 3));
10961096
static const char* fontMap[4] = { "FIXED", "VAR", "VAR BOLD", NULL };
10971097
const float dpiScale = ui->renderer->VirtualScreenScaleFactor();
1098-
const double logicalHeight = lua_tonumber(L, 1);
1099-
const int scaledHeight = (int)std::lround(logicalHeight * dpiScale);
1098+
const lua_Number logicalHeight = lua_tonumber(L, 1);
1099+
int scaledHeight = (int)std::lround(logicalHeight * dpiScale);
11001100
double const physicalWidth = (double)ui->renderer->DrawStringWidth(
11011101
scaledHeight,
11021102
luaL_checkoption(L, 2, "FIXED", fontMap),
@@ -1118,9 +1118,9 @@ static int l_DrawStringCursorIndex(lua_State* L)
11181118
ui->LAssert(L, lua_isnumber(L, 4), "DrawStringCursorIndex() argument 4: expected number, got %s", luaL_typename(L, 4));
11191119
ui->LAssert(L, lua_isnumber(L, 5), "DrawStringCursorIndex() argument 5: expected number, got %s", luaL_typename(L, 5));
11201120
static const char* fontMap[4] = { "FIXED", "VAR", "VAR BOLD", NULL };
1121-
const double logicalHeight = lua_tonumber(L, 1);
1122-
const double logicalCursorX = lua_tonumber(L, 4);
1123-
const double logicalCursorY = lua_tonumber(L, 5);
1121+
const lua_Number logicalHeight = lua_tonumber(L, 1);
1122+
const lua_Number logicalCursorX = lua_tonumber(L, 4);
1123+
const lua_Number logicalCursorY = lua_tonumber(L, 5);
11241124
const int scaledHeight = (int)std::lround(logicalHeight * dpiScale);
11251125
const int scaledCursorX = (int)std::lround(logicalCursorX * dpiScale);
11261126
const int scaledCursorY = (int)std::lround(logicalCursorY * dpiScale);
@@ -1431,8 +1431,8 @@ static int l_GetCursorPos(lua_State* L)
14311431
{
14321432
ui_main_c* ui = GetUIPtr(L);
14331433
const float dpiScale = ui->renderer->VirtualScreenScaleFactor();
1434-
lua_pushinteger(L, (lua_Integer)std::lround((double)ui->renderer->VirtualMap(ui->cursorX) / (double)dpiScale));
1435-
lua_pushinteger(L, (lua_Integer)std::lround((double)ui->renderer->VirtualMap(ui->cursorY) / (double)dpiScale));
1434+
lua_pushinteger(L, (lua_Integer)std::lround(ui->renderer->VirtualMap(ui->cursorX) / dpiScale));
1435+
lua_pushinteger(L, (lua_Integer)std::lround(ui->renderer->VirtualMap(ui->cursorY) / dpiScale));
14361436
return 2;
14371437
}
14381438

@@ -1444,8 +1444,8 @@ static int l_SetCursorPos(lua_State* L)
14441444
ui->LAssert(L, n >= 2, "Usage: SetCursorPos(x, y)");
14451445
ui->LAssert(L, lua_isnumber(L, 1), "SetCursorPos() argument 1: expected number, got %s", luaL_typename(L, 1));
14461446
ui->LAssert(L, lua_isnumber(L, 2), "SetCursorPos() argument 2: expected number, got %s", luaL_typename(L, 2));
1447-
const int scaledX = (int)std::lround((double)lua_tointeger(L, 1) * (double)dpiScale);
1448-
const int scaledY = (int)std::lround((double)lua_tointeger(L, 2) * (double)dpiScale);
1447+
const int scaledX = (int)std::lround(lua_tonumber(L, 1) * dpiScale);
1448+
const int scaledY = (int)std::lround(lua_tonumber(L, 2) * dpiScale);
14491449
int x = ui->renderer->VirtualUnmap(scaledX);
14501450
int y = ui->renderer->VirtualUnmap(scaledY);
14511451
ui->sys->video->SetRelativeCursor(x, y);

0 commit comments

Comments
 (0)