Update to 12.0-beta1

This commit is contained in:
dP
2021-08-15 14:57:29 +03:00
parent ac7d3eba75
commit 9df4f2c4fc
666 changed files with 61302 additions and 20466 deletions

View File

@@ -41,7 +41,7 @@ bool _right_button_down; ///< Is right mouse button pressed?
bool _right_button_clicked; ///< Is right mouse button clicked?
DrawPixelInfo _screen;
bool _screen_disable_anim = false; ///< Disable palette animation (important for 32bpp-anim blitter during giant screenshot)
bool _exit_game;
std::atomic<bool> _exit_game;
GameMode _game_mode;
SwitchMode _switch_mode; ///< The next mainloop command.
PauseMode _pause_mode;
@@ -51,6 +51,8 @@ static byte _stringwidth_table[FS_END][224]; ///< Cache containing width of ofte
DrawPixelInfo *_cur_dpi;
byte _colour_gradient[COLOUR_END][8];
static std::recursive_mutex _palette_mutex; ///< To coordinate access to _cur_palette.
static void GfxMainBlitterViewport(const Sprite *sprite, int x, int y, BlitterMode mode, const SubSprite *sub = nullptr, SpriteID sprite_id = SPR_CURSOR_MOUSE);
static void GfxMainBlitter(const Sprite *sprite, int x, int y, BlitterMode mode, const SubSprite *sub = nullptr, SpriteID sprite_id = SPR_CURSOR_MOUSE, ZoomLevel zoom = ZOOM_LVL_NORMAL);
@@ -656,6 +658,28 @@ int DrawString(int left, int right, int top, const char *str, TextColour colour,
return DrawLayoutLine(*layout.front(), top, left, right, align, underline, true);
}
/**
* Draw string, possibly truncated to make it fit in its allocated space
*
* @param left The left most position to draw on.
* @param right The right most position to draw on.
* @param top The top most position to draw on.
* @param str String to draw.
* @param colour Colour used for drawing the string, for details see _string_colourmap in
* table/palettes.h or docs/ottd-colourtext-palette.png or the enum TextColour in gfx_type.h
* @param align The alignment of the string when drawing left-to-right. In the
* case a right-to-left language is chosen this is inverted so it
* will be drawn in the right direction.
* @param underline Whether to underline what has been drawn or not.
* @param fontsize The size of the initial characters.
* @return In case of left or center alignment the right most pixel we have drawn to.
* In case of right alignment the left most pixel we have drawn to.
*/
int DrawString(int left, int right, int top, const std::string &str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
{
return DrawString(left, right, top, str.c_str(), colour, align, underline, fontsize);
}
/**
* Draw string, possibly truncated to make it fit in its allocated space
*
@@ -806,6 +830,28 @@ int DrawStringMultiLine(int left, int right, int top, int bottom, const char *st
return ((align & SA_VERT_MASK) == SA_BOTTOM) ? first_line : last_line;
}
/**
* Draw string, possibly over multiple lines.
*
* @param left The left most position to draw on.
* @param right The right most position to draw on.
* @param top The top most position to draw on.
* @param bottom The bottom most position to draw on.
* @param str String to draw.
* @param colour Colour used for drawing the string, for details see _string_colourmap in
* table/palettes.h or docs/ottd-colourtext-palette.png or the enum TextColour in gfx_type.h
* @param align The horizontal and vertical alignment of the string.
* @param underline Whether to underline all strings
* @param fontsize The size of the initial characters.
*
* @return If \a align is #SA_BOTTOM, the top to where we have written, else the bottom to where we have written.
*/
int DrawStringMultiLine(int left, int right, int top, int bottom, const std::string &str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
{
return DrawStringMultiLine(left, right, top, bottom, str.c_str(), colour, align, underline, fontsize);
}
/**
* Draw string, possibly over multiple lines.
*
@@ -845,6 +891,21 @@ Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
return layout.GetBounds();
}
/**
* Return the string dimension in pixels. The height and width are returned
* in a single Dimension value. TINYFONT, BIGFONT modifiers are only
* supported as the first character of the string. The returned dimensions
* are therefore a rough estimation correct for all the current strings
* but not every possible combination
* @param str string to calculate pixel-width
* @param start_fontsize Fontsize to start the text with
* @return string width and height in pixels
*/
Dimension GetStringBoundingBox(const std::string &str, FontSize start_fontsize)
{
return GetStringBoundingBox(str.c_str(), start_fontsize);
}
/**
* Get bounding box of a string. Uses parameters set by #SetDParam if needed.
* Has the same restrictions as #GetStringBoundingBox(const char *str, FontSize start_fontsize).
@@ -891,15 +952,17 @@ const char *GetCharAtPosition(const char *str, int x, FontSize start_fontsize)
/**
* Draw single character horizontally centered around (x,y)
* @param c Character (glyph) to draw
* @param x X position to draw character
* @param y Y position to draw character
* @param r Rectangle to draw character within
* @param colour Colour to use, for details see _string_colourmap in
* table/palettes.h or docs/ottd-colourtext-palette.png or the enum TextColour in gfx_type.h
*/
void DrawCharCentered(WChar c, int x, int y, TextColour colour)
void DrawCharCentered(WChar c, const Rect &r, TextColour colour)
{
SetColourRemap(colour);
GfxMainBlitter(GetGlyph(FS_NORMAL, c), x - GetCharacterWidth(FS_NORMAL, c) / 2, y, BM_COLOUR_REMAP);
GfxMainBlitter(GetGlyph(FS_NORMAL, c),
CenterBounds(r.left, r.right, GetCharacterWidth(FS_NORMAL, c)),
CenterBounds(r.top, r.bottom, FONT_HEIGHT_NORMAL),
BM_COLOUR_REMAP);
}
/**
@@ -1136,15 +1199,44 @@ void DoPaletteAnimations();
void GfxInitPalettes()
{
std::lock_guard<std::recursive_mutex> lock(_palette_mutex);
memcpy(&_cur_palette, &_palette, sizeof(_cur_palette));
DoPaletteAnimations();
}
/**
* Copy the current palette if the palette was updated.
* Used by video-driver to get a current up-to-date version of the palette,
* to avoid two threads accessing the same piece of memory (with a good chance
* one is already updating the palette while the other is drawing based on it).
* @param local_palette The location to copy the palette to.
* @param force_copy Whether to ignore if there is an update for the palette.
* @return True iff a copy was done.
*/
bool CopyPalette(Palette &local_palette, bool force_copy)
{
std::lock_guard<std::recursive_mutex> lock(_palette_mutex);
if (!force_copy && _cur_palette.count_dirty == 0) return false;
local_palette = _cur_palette;
_cur_palette.count_dirty = 0;
if (force_copy) {
local_palette.first_dirty = 0;
local_palette.count_dirty = 256;
}
return true;
}
#define EXTR(p, q) (((uint16)(palette_animation_counter * (p)) * (q)) >> 16)
#define EXTR2(p, q) (((uint16)(~palette_animation_counter * (p)) * (q)) >> 16)
void DoPaletteAnimations()
{
std::lock_guard<std::recursive_mutex> lock(_palette_mutex);
/* Animation counter for the palette animation. */
static int palette_animation_counter = 0;
palette_animation_counter += 8;
@@ -1283,7 +1375,7 @@ void LoadStringWidthTable(bool monospace)
}
}
ReInitAllWindows();
ReInitAllWindows(false);
}
/**
@@ -1854,7 +1946,7 @@ bool ToggleFullScreen(bool fs)
{
bool result = VideoDriver::GetInstance()->ToggleFullscreen(fs);
if (_fullscreen != fs && _resolutions.empty()) {
DEBUG(driver, 0, "Could not find a suitable fullscreen resolution");
Debug(driver, 0, "Could not find a suitable fullscreen resolution");
}
return result;
}