113 Commits

Author SHA1 Message Date
Charles Dang
12fa8f2844 Use standard chrono types consistently throughout the codebase
* Functions that return time values now return proper std::chrono::duration units (milliseconds,
  seconds, etc.). This removes the need to do manual unit conversions.
* Simple time-to-execute logging was replaced with `utils::optimer`.
* Most uses of `SDL_GetTicks()` have been replaced with `std::chrono::steady_clock`.
* Uses of events::pump_info::ticks() have been replaced with direct calls to steady_clock::now().
  This made the countdown_clock code significantly simpler. As for the music_tinker, that needs
  to be rethought wholesale.
2024-11-07 11:10:13 -05:00
white-haired-uncle
d74b4061fa
improve tooltip placement on sidebar (#8908) 2024-07-30 17:27:27 -05:00
pentarctagon
970163813d 2024 copyright update 2024-01-20 22:22:23 -06:00
Pentarctagon
c44cc2742e Copyright update.. 2023-04-29 10:48:11 -05:00
Tommy
bd745d244b Upgrade some SDL_Rect to rect 2022-07-31 16:47:26 +12:00
Tommy
143023fec8 Properly update map label tooltip positions 2022-07-29 16:52:44 +12:00
Tommy
bef85a51a4 video: Clarify draw_area() -> game_canvas() in almost all cases
Theoretically the drawing area may change if we are rendering to
texture. However the vast majority of cases wanted the game canvas
size independent of whatever the current render target may be.

A function game_canvas_size() was also added returning a point,
and this was used to simplify things where appropriate.
2022-07-24 22:06:33 +12:00
Tommy
29c82e308a CVideo: Remove CVideo singleton, replacing with "video" interface
The only real change is that in stead of passing around CVideo
pointers and calling things via CVideo::get_singleton().foo()
one simply does not pass around pointers, and calls video::foo().
2022-07-24 22:06:33 +12:00
Tommy
ba24612f73 Remove trailing newlines from multiline log messages 2022-07-20 15:20:57 +12:00
Tommy
1c25ebdfa2 Remove std::endl from log lines, now that it's added automatically 2022-07-20 15:20:57 +12:00
Tommy
06254e5581 Mega draw manager implementation
This has been megasquashed because it was a month-long mess of fixes
and reworks.

In summary:
* objects no-longer draw by hooking a DRAW event. In stead they
  inherit from gui2::top_level_drawable, and implement its interface.
* the game display now renders to an offscreen buffer. This is used
  to implement hardware scrolling, and to redraw after halos, floating
  labels etc. move.
* halos, floating labels, tooltips, and a few more things are now
  drawn on top of the game display, rather than as part of it. This
  allows them to be updated independently without reading pixels
  from the screen.
* surface restorers have been removed. Reading pixels from the screen
  should now be unnecessary excepting two cases: (a) screenshots,
  (b) background blur. Blur is cached, and screenshots are occasional.
* GUI2 widgets no longer keep track of dirty state. They are redrawn
  as necessary. Most places which previously set dirty state now queue
  a redraw in their part of the screen in stead.
* A consequence is that active translucency is enabled across all UI
  elements, and the game display can (and does) continue to animate
  while menus and dialogs are showing.
* performance is drastically increased for basically everything, most
  notably map scrolling, floating text, and halos.
* CPU usage is drastically decreased. With animations disabled it is
  essentially zero while nothing is moving.
* GPU usage is also minimal. The display is only flipped if something
  is drawn.
2022-07-13 13:34:01 +12:00
Tommy
0481a63f56 Replace sdl::rects_overlap with new rect::overlaps 2022-07-02 12:30:58 +12:00
Tommy
103dfc031c Replace sdl::point_in_location with new rect::contains 2022-07-02 12:30:58 +12:00
Tommy
d130622b96 Initial indirect rendering prototype.
Rendering is now done to a separate surface. All routines that previously
wrote directly to the framebuffer now write to this surface. When the screen
is flipped, this surface is copied directly to a streaming texture, which is
then scaled to the window's rendering surface for display.

This has enabled a drawing resolution that differs from display resolution.
It is active and for the most part works. Input events are converted to the
correct scale by SDL, so most input handling routines can be used unchanged,
but one or two are causing problems so there are some bugs. To test this,
change the "pixel_scale" preference. Don't expect a playable game with
any pixel scale other than 1 yet.
2022-04-18 17:25:06 +12:00
Pentarctagon
340023921d
2022 copyright update. 2022-03-06 19:07:13 -06:00
Steve Cotton
a9e534812d Fix iterator-use-after-invalidation in tooltips
It's undefined behavior to access an iterator after calling std::map::erase(),
the correct method is to use the new iterator that erase() returns instead.

(cherry picked from commit b0c59a558af7197d80f3170fb5d26f9e75f11d82)
2021-11-06 07:21:16 +01:00
Pentarctagon
57ce449af8
Re-add attribution to copyright notices.
These are mostly useless and outdated/wrong, but apparently it's probably illegal to remove them.
2021-07-27 20:21:38 -05:00
Pentarctagon
ba75e1af50
Copyright update.
This additionally:
* Makes all copyright notices identical aside from the starting year for Wesnoth-specific source files. Files not included: mariadbpp, lua, spirit po, xbrz, and bcrypt (crypt_blowfish).
* Removes all attribution from the files, since the vast majority of them are outdated or seemingly just outright incorrect. For example, I would guess that Dave is no longer the sole author of the majority of Wesnoth's current code.
2021-07-26 11:38:03 -05:00
Iris Morelle
79c7d09c6a gui1: Revert font measurements for tooltips and in-game text overlays
There's such a thing as too big, surely.
2021-03-19 12:36:52 -03:00
Charles Dang
2470984af3 Prepend 'SDL2/' to all SDL includes
This was needed to get the build working with vcpkg's version of SDL, where all the SDL files are
in their own SDL folder. However, our cmake config also has a note saying it was a deliberate choice
to move our SDL files *out* of their SDL2 folder due to certain distros (FreeBSD is mentioned) not
putting the files in said folder in the first place.
2019-07-22 15:35:55 +11:00
Martin Hrubý (hrubymar10)
674fda85b7 Migrate links to https if available - Fwd c18537edc0678f40a209797d72dfaba3e5e88545
(cherry-picked from commit bc4d22dc72e79c3d6a3364ac896e473afd298246)
2018-10-07 03:23:36 +00:00
Charles Dang
f5effa03f3 Tooltips: increased bg opacity to match GUI2 ones
Makes it easier to read the text too.
2018-03-18 17:01:25 +11:00
Charles Dang
4ba33d464e Cleaned up text rendering-related includes 2018-03-11 21:46:21 +11:00
Charles Dang
16ce2af32e Made display class no longer inherit from filter_context
The only function that display meaningfully implemented was get_disp_context. It did implement
get_tod_man, but only meaningfully in its two derived classes (it returned the result of
resources::tod_manager in display). Additionally, the long-ass comment in the header stated the
display class should *not* inherit from filter_context. Do note that get_disp_context was retained
as a display member function.

Upon further investigation, I found that there were only two places where the display class was
passed to unit_filter. All others passed resources::filter_con. The editor_display class was also
assigned to resources::filter_con in editor::context_manager. So, I removed the second filter_context
argument from unit_filter and initialized it from resources::filter_con in all cases.

unit_filter only used the filter_context to get its display_context and the unit_map within anyway.
When using display::get_disp_context in-game, that would return a game_board object. Using
resources::filter_con in the same context would return the game_state object that owned the
aforementioned game_board, and calling get_disp_context on that game_state would return the board
as well. So we end up in the same place.

To be complete, I also made editor::context_manager inherit from filter_context. It makes much more
sense, since it can nicely implement 2/4 of the fc functions. It also ensures resources::filter_con
is valid in the editor, in case it's needed. I'm not 100% sure it is, but since it was assigned
before (to editor_display), it's very likely.

Another side effect of the above is that get_tod_man is now implemented in a more apropos class
in the editor. Essentially, editor_display (where it was implemented before by reaching into the
context_manager) holds an editor_controller which holds a context_manager (where it's now implemented).
It wasn't even really needed in editor_display and was only called once.

Similarly, get_tod_man has been removed from game_display. Again, it was only present to "properly"
implement the function in display, which only existed because display inherited from filter_context.
And get_tod_man wasn't even needed in display, game_display, or editor_display (save for the one
aforementioned call)!!! AND in game_display, it simply dereferenced a pointer to the *actual* ToD
manager in the game_state class, WHICH IN AND OF ITSELF INHERITS FROM FILTER_CONTEXT!!!

I have removed the tod_manager pointer in game_display and replaced its use with resources::tod_manager,
which in the context of the game (where game_display) would be use, point to the same thing the class
pointer did. I suppose I could have left it, since I'm trying to remove/improve the use of the
resources pointers, but I felt it better to decouple the two classes (game_display and game_state)
slightly, especially since its main purpose for existing (overriding display::get_tod_man) no longer
exists.

Finally, some of the instances where a unit_filter object is created had to be changed to use brace
initialization or else the build failed. @celticminstrel tells me this might be because of some "most
vexing parse" issue.

Some formatting and virtual/override specifiers were also applied/added.

*huffs*
2018-01-29 15:54:01 +11:00
Gregory A Lundberg
b5f76eff79
Bump copyright to 2018 2018-01-19 00:02:20 -06:00
Charles Dang
29ff4bd644 Removed CVideo argument from help functions
Just used the singleton in the main show_help function.
2017-12-05 10:50:11 +11:00
Charles Dang
de1a9724eb Refactored handling of window/renderer size getters
* Removed display::screen_area(), display::w(), and display::h().
* Moved the global screen_area() function into the CVideo class.
* Renamed CVideo::getx() and gety() to get_width() and get_height()
* Made those two functions return the result of screen_area() instead of the other way around.
* Added preliminary support for high-DPI rendering to screen_area()

Note on the last point: When I fixed bug #1772 (aa8f6c7e7 right now but will probably change with rebasing)
I noted that SDL_GetWindowSize and SDL_GetRendererOutputSize returned the same results for me (even with
Window's automatic scaling for non-high-DPI-enabled apps disabled) but that the SDL documentation stated the
former returned screen coordinates and the latter pixels. In that same commit I changed the dimension functions
to use SDL_GetWindowSize. I've now reversed that decision and gone back to using SDL_GetRendererOutputSize so
I can guarantee output in pixels. If use_pixels is false, the code will return coordinates in 96 DPI, so I need
to have pixel measurements for the calculations.

Again, though, I do not know if SDL_GetWindowSize returns a different value that pixel size (which it's said
to do) on macOS or iOS. I'll need to do some testing. It's possible on those platforms I won't need the 96 DPI
measurements, but it's also possible it will be needed on on platforms, since all of our code relies on pixel
measurements.
2017-12-05 10:50:10 +11:00
Charles Dang
9dd497db4a Cleaned up the mess of CVideo references passed around the game initialization process
Essentially, we had CVideo arguments being passed down this chain:
- game_launcher
- free-standing MP initialization functions
- campaign_controller
- playsingle_controller/playmp_controller
- play_controller
- game_display
- display

And likewise down through
- game_launcher
- editor_controller
- editor_display
- display

With only a minimal number of actual calls along the way. :| There were maybe... two remaining?

This removes the CVideo arguments and class members from both chains (except of course, game_launcher.
That's where the "real" CVideo object lives).

The display class now initializes its CVideo reference from the singleton, which is also used in the
very few other places it's needed. I also replaced a check for a null video ptr in show_tooltip()
with a faked() check (see src/tooltips.cpp). That seems to make more sense, since CVideo is never
null now.
2017-11-21 02:30:19 +11:00
Charles Dang
61992429d0 Avoid copy initialization of colors when possible 2017-04-15 21:10:42 +11:00
Charles Dang
0c3260dc05 Finished deploying std::map::emplace (cont. e1a579da51)
Apparently, the last time I did this I only grepped for `insert(std::pair` not `insert(std::make_pair`. Oversight, much?
2017-04-12 07:51:42 +11:00
Celtic Minstrel
b4dc11ce36 Belated 2017 copyright update 2017-03-19 10:05:38 -04:00
Charles Dang
60fc61a9a0 Cleaned up a few SDL includes 2017-03-14 10:56:35 +11:00
Charles Dang
e22c8967ee Cleaned up global.hpp includes 2016-12-17 15:21:04 +11:00
Charles Dang
4b3862493f Convert all usecases of SDL_Color to color_t 2016-11-30 17:59:30 +11:00
Jyrki Vesterinen
5e2af01fba Fix build
This involves splitting standard colors out of font/constants.cpp.
Serialization/string_utils.cpp, that is part of wesnothlib
(compiled into both client and server) uses ellipsis and Unicode minus sign
from font constants, which means that font/constants.cpp must be part of
wesnothlib as well. However, one of standard colors is evaluated by calling
inverse(const SDL_Color&) declared in sdl/utils.hpp. Sdl/utils.cpp has way
too many dependencies to live in wesnothlib.

Hence, standard colors are now in a file of their own:
font/standard_colors.cpp. That file is part of wesnoth (not wesnothlib) and
only available for the client.
2016-10-16 18:34:22 +03:00
Charles Dang
b6ea5106ca Moved marked-up_text.*pp to font/ 2016-10-16 22:54:07 +11:00
Charles Dang
30c1a852d3 Attempt to fix compilation 2016-10-16 22:52:54 +11:00
Celtic Minstrel
db5cf990de Fix use of constexpr 2016-10-16 01:45:05 -04:00
Chris Beck
f82f996347 move font constants to their own compilation unit
avoids including SDL_TTF unnecessarily
2016-10-15 12:38:52 -04:00
Chris Beck
e3417bd954 split gui1 font interface into a font_config and sdl_ttf interface
move all of these into font folder
2016-10-15 05:52:23 -04:00
Charles Dang
ea0a9ff43b Bumped size of GUI1 tooltip text
Was left too small after enabling Lato in GUI1 (52cba5fc639a)
2016-05-18 10:57:42 +11:00
Celtic Minstrel
ca382018b7 BOOST_FOREACH -> range for 2016-04-02 09:38:29 -04:00
Celtic Minstrel
3ac7f8d970 NULL -> nullptr
A few cases of NULL were missed, since changing them led to errors
(Mainly instances where it was passed to a boost::function)
2016-03-31 00:42:38 -04:00
Charles Dang
37d9b102b7 Include SDL files as system headers
This excludes inclusions in SDL_GPU files.
2016-03-20 15:07:16 +11:00
gfgtdf
a953848dda remove display dependency from show_help()
help_button still needs a display& for regierting it in the hotkey code.
2016-01-12 23:17:56 +01:00
Chris Beck
ba51524f6e update copyright to year 2016
using this shell script:

find src -type f -print0 | xargs -0 sed -i "s|Copyright (C) \([[:digit:]]*\)\([ ]*\)-\([ ]*\)2015|Copyright (C) \1\2-\32016|g"
2016-01-02 23:59:31 -05:00
Ignacio R. Morelle
aecdbab096 Pass object by reference
Found by cppcheck.
2015-07-06 23:42:13 -03:00
Chris Beck
ea212b5bc2 move class floating_label from font.cpp to its own file
floating_label is essentially a primitive GUI1 widget, consisting
just of a text label and non-interacting. It's also used for the
map labels displayed in-game iiuc.
2015-03-07 21:22:03 -05:00
Ignacio R. Morelle
57ae45387a New Year copyright update 2015-01-01 19:07:35 -03:00
Fabian Müller
7525c2ed4c Allow removing labels by handle. 2014-12-13 07:31:46 +01:00