Commit graph

592 commits

Author SHA1 Message Date
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
Rikard Falkeborn
557bbf36ea Make some functions static in display.{cpp,hpp} 2017-12-22 19:48:45 +02: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
e8655af1b4 Display: one (hopefully) significant optimization and one minor one
Copying the blit_helper objects when adding them to the drawing buffer was expensive since
blit_helper contains a vector of surfaces. We definitely want to copy that as little as
possible.

Also used std::move when fetching fog/shroud images. This function apparently has little
overhead, but still nice to not make copies here.

Also made get_terrain_images return void (this is just minor cleanup, not an optimization).
No need for it to return a reference to a class member.
2017-11-27 16:41:05 +11:00
Jyrki Vesterinen
4d0c46164e Miscellaneous optimizations in display::get_terrain_images()
* The vector of surfaces is now a class member variable instead of a local
variable. This saves a memory allocation every time the function is called
- which is worth it in this case, as the function is a major performance
bottleneck.

* The surfaces are now being moved instead of copied where possible. Turns
out that freeing a SDL surface is fairly expensive in performance-critical
code.

* Pointers to ToDs are now cached, reducing the number of calls to
get_time_of_day() from 37 to 7.

In a stress-test in Aetheryn's Mod at 50 % zoom, the FPS I was getting on
my PC (Intel Core i5-4430) increased from 16 to 23.
2017-11-26 20:07:34 +02:00
Charles Dang
3da9077312 CVideo/Display: cleaned up/slightly refactored a few things
* display::w() and display::h() now simply forward to CVideo::getx() and gety() instead of querying
  the underlying window object. This is a slight semantic change, since now these functions return
  screen coordinates instead of pixels, but that's probably what we want in the long term anyway.
* sdl:🪟:get_flags() now returns the proper uint32_t instead of int
* Added a dedicated CVideo::window_has_flags function since testing window flags was the most common
  use of the underlying sdl window outside the class.
* Made CVideo::set_window_mode private. This is an implementation detail and shouldn't be public.
* Removed BPP argument from CVideo::make_test_fake. It's never passed anything other than 32, and
  we're long past the time when we care about window BPP.
* Removed sdl/window.hpp include from video.hpp. This was mostly only there to allow other area of
  the code to call get_window()->get_flags() (and for display.hpp). There's no real reason for it to
  be there anymore and was just making any modification to the sdl window header take ages.
2017-11-21 14:20:14 +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
galegosimpatico
d98d7aa80c Fix visual bug in the announces system.
Follow up 'ceba081542a4'. It is nice to remove the previously
announced message when announces are being delivered very quickly, but
maybe movement feedback announces should be exempt of that. Before
this rev, Whenever an 'Enemy unit sighted' message was being ordered
coupled with a subsequent 'press $HOTKEY to keep moving', the 'Enemy
unit sighted' message was getting discarded.

src/actions/move.cpp: Movement feedback is important, do not remove
previous messaging when announcing.

src/display.cpp: Do not remove previously announced label when so
requested.

src/display.hpp: Add a `struct` device meant to pass optional
arguments to `void announce(const std::string&, const color_t&, ...)`
instead of primitive typed optional arguments (one, `int`, was being
in use, I would have needed to add a second one, `bool`, but when
trying to do that, the `bool` value would be received by the function
as the `int` argument when not providing an explicit value for the
`int` argument (see `src/actions/move.cpp`). Given C++11, for optional
arguments, does not (to the extent of my understanding) allow
specifying the argument name on the calling place, I was forced into
adding this struct in order to jail all primitive typed optional
arguments.

src/synced_commands.cpp: Adapt to new public API in `class display`.
2017-10-27 19:39:26 +11:00
Rikard Falkeborn
a8f6df50e8 Add const to member functions 2017-10-26 21:09:47 +03:00
Alexander van Gessel
f86a4a7764 Display actual FPS (#1958)
That is, not calculated FPS, but the actual number of frames rendered during the previous second.
2017-09-11 08:38:22 +03:00
Jyrki Vesterinen
3692cfa86b Redraw invalidated hexes once, not twice
This halves the CPU usage cost of animations, which is useful especially in
water-heavy scenarios such as Dead Water.

I was worried about the possibility of regressions, but I didn't find any
in my playtesting: moved and killed units disappear from their hexes like
they should.
2017-09-04 23:46:33 +03:00
Jyrki Vesterinen
670bcf71a3 Address a bunch of Coverity Scan warnings 2017-09-01 23:24:04 +03:00
gfgtdf
22a2d6f380 save current gui location in savegames (#1886) 2017-08-08 15:43:18 +02:00
Celtic Minstrel
b4990801ef Fixed some issues with the resolution list (fixes #1772)
Awhile back I added some code to remove any resolutions from the list that exceeded the current DPI.
I seem to have misunderstood some of the functionality.

First, off, GetCurrentDisplayMode doesn't seem to return current resolution. From my tests, it seems
to return a "maximum maximized size" of some sort equal to GetUsableDisplayBounds - 1 (see below):

* Render output size: 800, 600
* Display mode size: 1536, 864
* Window size: 800, 600
* Display Bounds: x: 0, y: 0, w: 1537, h: 865
* Usable display bounds: x: 0, y: 0, w: 1537, h: 865

The actual
window size, which @celticminstrel informs me is what we should be measuring here, is actually returned
by either GetWindowSize or GetRenderOutputSize. According to SDL, the latter should return pixel size
and the former screen coordinates. In my tests, though, the results are the same. This might be different
on macOS or iOS. Either way, I've changed current_resolution(), getx(), and gety() to use the results of
GetWindowSize().

Additionally, it seems I don't need to multiply any display modes by the DPI scale factor if I check the
sizes against the aforementioned "max maximized area" w/h. For that I use GetDisplayBounds however...
though again, I'm not sure that's the best way to do this. It does seem to work correctly to fix the
aforementioned bug, anyway. I'll need to figure out more about the handling of DPI on Windows vs macOS
or iOS. There's an implication that the measurements some of these functions return is different.
2017-07-23 16:38:46 -04:00
Jyrki Vesterinen
4e4d7b5277 Rewrite the FPS cap implementation
The FPS cap, originally implemented in 2007, is very poorly done. It
doesn't take frame time variance into account, and is therefore almost
guaranteed to cause missed frames all the time. It doesn't increase timer
granularity on Windows, which causes SDL_Delay() to often take much longer
than intended. And it's hardcoded for 50 FPS, which fits poorly with 60 Hz
displays.

This new implementation fixes all those issues.

My experience is that the game feels much, much smoother with the new
implementation, perfectly competitive with 1.12. In my opinion, performance
is now at an acceptable level for a stable release.
2017-07-22 15:48:46 +03:00
Charles Dang
762db98da1 Moved clear_screen to CVideo and made use of it instead of calling sdl:🪟:fill directly
Should fix nullptr access violations in the tests.
2017-05-27 11:42:14 +11:00
Charles Dang
5e6e8eab6f Made energy_bar_rects static in unit_drawer file (superior version of 1ff1b7fdd)
I reverted the aforementioned commit after being informed it would be inferior, performance-wise.
However, this should solve that as the map is no longer constantly recreated.

This also addresses some issues I had with the original commit where I had to make some member
functions non-const.
2017-05-17 22:40:35 +11:00
Charles Dang
4479682469 Convert uses of create_rect to aggregate initialization when possible
This only includes cases where this can be done without triggering warnings about narrowing conversion.
Also includes cleanups of sdl/rect.hpp includes.
2017-05-17 21:16:57 +11:00
Charles Dang
2101353d36 Convert include guards to the shorter #pragma once
Turns out I mistook @celticminstrel's opinion that we should use include guards over pragma (737916e).
Since all major compilers support `#pragma once`, there's no reason not to use it.

For future mergability reasons, this excludes src/spirit_po and src/xBRZ. It also excludes src/boost-patched.
2017-05-09 19:41:37 +11:00
Charles Dang
d4529dfc1e Removed ThemeWML border image keys
These were rendered unnecessary by 781276709d, which changed border rendering to use the terrain engine.
This also removes display::draw_border, which used the keys.
2017-04-25 19:49:08 +11:00
Celtic Minstrel
b9a35fa870 Allow changing theme while in a game 2017-04-24 11:01:10 -04:00
Charles Dang
4c0422d491 Allow manual override of ToD color used in display::update_tod 2017-04-24 17:25:22 +11:00
Charles Dang
30340aaedb Display: removed dummy drawing layer
Not exactly sure what it meant by "sizing the vector" - the enum isn't a vector, or used in a vector. It doesn't
seem to have been relevant to max_layer_group either, since that was calculated with a -2 offset to ignore it.

Likely it had to do with the loop in drawing_buffer_key ctor, which was designed to find the group (which is
drawing_layer an enum member) "under" (ie, that contained) the specified layer. Having a dummy buffer meant the
precondition of layer < max layer (ie, the buffer) layer was always true, meaning the index was always decremented
at least once.
2017-04-21 05:31:51 +11:00
Charles Dang
ac9ad01be8 Use std::array where array size is needed, when appropriate 2017-04-21 03:41:18 +11:00
Rikard Falkeborn
343eb9ab1b Add const to some functions 2017-04-17 16:51:30 +11:00
Celtic Minstrel
b4dc11ce36 Belated 2017 copyright update 2017-03-19 10:05:38 -04:00
Charles Dang
daefe8e63b Don't reset zoom level every time a game is loaded (FR #25592)
Note this doesn't apply across app sessions, but it's an improvement.
2017-03-19 05:15:25 +11:00
Charles Dang
6c994a5a73 Properly validate and set index when calling set_zoom with value
This fixes an issue where the zoom index wasn't properly reset when set_default_zoom was set. It also ensures
this function will only work with the set zoom levels.
2017-03-14 12:53:16 +11:00
Charles Dang
64ebefbffa Removed 'sunset' command. Deals with bug #25460
Not really useful, this was. Better debug aids, we need.
2017-03-09 17:23:13 +11:00
Charles Dang
d10c4e7a0b Revert "Made the unit_drawer own its bar rect map instead of keeping it in the display singleton"
This reverts commit 1ff1b7fdd8. I've been informed this is inferior, performance-wise.
2017-03-08 19:18:14 +11:00
Charles Dang
1ff1b7fdd8 Made the unit_drawer own its bar rect map instead of keeping it in the display singleton 2017-03-08 19:00:19 +11:00
Charles Dang
9f43913ee1 Implement specific zoom levels instead of constant +/-4 (FR #24469) 2017-03-07 23:09:16 +11:00
Charles Dang
c912f7e7e7 Removed zoom slider code
This slider hasn't worked in ages, and we're planning to remove it anyway.

The slider "groove" image remains since it's hard drawn in the background image file.
2017-03-07 21:05:25 +11:00
Charles Dang
44f8d2e539 Convert a few more things to use color_t 2016-12-03 23:27:32 +11:00
Celtic Minstrel
d0bb55159d Restore tod_color struct
Since it represents a colour delta rather than an absolute colour, the
color_t struct is not a sufficient substitute.

This partially reverts commit 0adeea43e0.

The formatting changes from that commit were not reverted, nor was
including colour in time-of-day equality. The unused tod_color::operator*=
was not restored, either.
2016-11-30 11:12:40 -05:00
Charles Dang
4b3862493f Convert all usecases of SDL_Color to color_t 2016-11-30 17:59:30 +11:00
Charles Dang
0adeea43e0 Replaced uses of the tod_color struct with color_t 2016-11-30 15:41:18 +11:00
Charles Dang
a60433356d Refactored out display::rgb, red, blue, green, and blend_rgb 2016-11-30 14:46:22 +11:00
Charles Dang
6465750cdf Avoid including team.hpp in diaplay.hpp 2016-11-30 12:56:32 +11:00
Celtic Minstrel
5392e306b9 Misc renaming of types to drop t- prefix 2016-11-09 01:13:17 -05:00
Celtic Minstrel
b6d862713f Misc class renaming to remove t- prefix 2016-11-09 01:13:17 -05:00
Charles Dang
dc477afb7a Removed empty sdl/image.*pp files
These used to contain code related to SDL_GPU, but were emptied in e497761d4e when that library was removed.
2016-11-07 13:05:03 +11:00
Charles Dang
8c92a9ee8e Formatting cleanup: moved const qualifiers before type names 2016-10-31 01:04:18 +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
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
ln-zookeeper
5d347bb61b Added a "Draw Number of Bitmaps" option to the editor
This is similar to "Draw Hex Coordinates" and "Draw Terrain Codes", and displays the number of terrain graphics surfaces draw for each hex. It is useful for spotting mistakes such as overlay images having non-transparent pixels in adjacent hexes where they shouldn't, or for comparing the efficiency of different kinds of terrain graphics rules.
2016-10-05 18:20:19 +03:00
Andreas Löf
e497761d4e Remove SDL_GPU #idfefs and library
Commands run:
find . -type f -name "*.hpp" | xargs coan source --replace --no-transients -U"SDL_GPU"
find . -type f -name "*.cpp" | xargs coan source --replace --no-transients -U"SDL_GPU"

This was followed by grepping and a bit of manual editing to remove
defunct TODO items and the empty sdl/gpu.hpp file.
2016-10-03 23:54:02 +13:00
gfgtdf
92cd7fee25 show the debug command notification longer
as requested in http://gna.org/bugs/index.php?18693
2016-08-08 17:35:52 +02:00
Charles Dang
05092ba2f6 Refactor most boost pointer related stuff to use their stdlib counterparts
This constitutes drop-in replacements for:

* boost::shared_ptr
* boost::scoped_ptr
* boost::weak_ptr
* boost::enable_shared_from_this
* boost::static_pointer_cast
* boost::dynamic_pointer_cast

This excludes boost::intrusive_ptr, except for stray includes. Refactoring that is more complicated.
2016-07-25 09:28:42 +11:00