141 Commits

Author SHA1 Message Date
Matthias Krüger
a2168d2e24 codespell fixes to /src 2018-02-08 21:54:09 +11:00
Gregory A Lundberg
b5f76eff79
Bump copyright to 2018 2018-01-19 00:02:20 -06: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
a21697fef3 Cleaned up various areas of code related to setting window resolution
* Added a point ctor that takes an SDL_Point.
* Added a toggle_fullscreen function to CVideo.
* Change all management of resolution data to use point instead of std::pair<int, int>. This
  shortens the code considerably.
* Cleaned up preferences_dialog::set_resolution_list
* Made CVideo::set_resolution return a bool indicating whether resolution was changed.
* Swapped which of the two set_resolution overloads contains the main implementation.
* Moved the events::raise_resize_event() call when setting resolution to the CVideo function
  where it should have always been (instead of the prefs dialog callback). This is a pretty
  essential component and having it localized in one place meant any other area of the code
  that might have called set_resolution wouldn't have it.
2017-11-27 05:53:23 +11: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
edb07f0cd4 CVideo: formatting and doc update
Also renamed a few functions to use snake case or be a little more descriptive.
2017-11-21 13:22:37 +11:00
Rikard Falkeborn
11edc7afe5 Mark member functions const 2017-08-20 08:50:07 +11:00
Gregory A Lundberg
e5d678b69f Correct documentation comments for pedantic clang
It appears clang 4.0 now checks documenation comments
2017-07-25 12:12:09 -05: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
09c77256fa Fixup 3a301db7d46f
A pair of ints mean non-whole scale factors won't be properly considered.
2017-06-03 00:49:37 +11:00
Charles Dang
3a301db7d4 CVideo: added getter for current DPI scale factor 2017-06-03 00:35:09 +11: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
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
Rikard Falkeborn
94e73a7ccc Add const to some more 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
7d83d0616a Removed CVideo::modeChanged() (unused) 2016-12-11 00:09:24 +11:00
Charles Dang
ec8ff1ac91 CVideo: general cleanup 2016-12-07 01:44:08 +11:00
Charles Dang
5f3a0bb69f CVideo: refactored out custom SDL window state flags
The function CVideo::window_state was the same as sdl:🪟:get_flags, except it handled
the custom state flags. The only slight semantic change is formally, the SDL_APPACTIVE encompassed
SDL_WINDOW_SHOWN && !SDL_WINDOW_MINIMIZED; however, it's very unlikely the former flag would be ever
set if the latter were as well.
2016-12-07 00:59:40 +11:00
Charles Dang
bf86912371 CVideo: removed update_rect functions
These have been functionally useless, since none of their code was ever executed. Since this hasn't caused
any problems this far, I'm removing them.
2016-12-07 00:41:11 +11:00
Charles Dang
0c18c9cb20 CVideo: removed get_screen_surface in favor of getSurface
They do the same thing, and the latter was more widely used.
2016-12-07 00:27:10 +11:00
Charles Dang
f11fa0652a Delete copy and move constructors instead of inheriting from boost::noncopyable 2016-11-30 09:20:02 +11:00
Celtic Minstrel
c09125096b Rename GUI2 widget classes to drop t- prefix 2016-11-09 01:27:30 -05:00
Celtic Minstrel
e0614251c4 Rename exception classes to avoid t- prefix 2016-11-09 01:13:17 -05: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
Jyrki Vesterinen
87cee41680 Fix build with MSVC
Microsoft's linker doesn't tolerate when a type is declared as a class
but forward declared as a struct.
2016-09-24 11:48:44 +03:00
Charles Dang
1fb26d9e1c Convert remaining SDL1.2 defines to their SDL2 counterparts and dropped compat layer 2016-09-15 15:55:09 +11:00
Celtic Minstrel
e6b8681de8 Boost type traits / enable_if -> <type_traits> 2016-07-25 01:31:43 -04: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
Andreas Löf
aa58d83b45 Use RAII instead of lock->unlock directly. 2016-07-16 11:25:01 +12:00
Andreas Löf
d55e884280 Hacky fix for the flickering when a screen is fully redrawn.
The fix supresses the call to flip() while a full redrawn
is performed. The flip calls are instead deferred to
then next draw-cycle.
2016-07-15 23:29:45 +12: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
02993cbaeb Removed empty resize_lock struct and resize_monitor class
Once again, SDL1.2 functionality that does nothing in SDL2.
2016-03-14 02:07:29 +11:00
Charles Dang
c37e9c4a7f Removed display_format_alpha() function
This function's contents were SDL1.2 only, and in SDL2 only return NULL. This
resulted in create_optimized_surface() always returning the passed surface and
get_surface_portion() to potentially return NULL erroneously (if optimize_format
was true, which doesn't seem to be the case anywhere).

However, there haven't been any discernible bugs that resulted from either of these
behaviors, so it should be investigates whether create_optimized_surface() is still
necessary, since it's been operating for a while now simply returning its passed
surface.
2016-03-13 23:45:02 +11:00
Charles Dang
4435b25523 Remove calls to empty update_whole_screen() function
The function's contents were SDL1.2 only, and it now does nothing in
SDL2.
2016-03-13 22:17:36 +11:00
Andreas Löf
358bd1235f Remove SDL1.2 code
This removes all legacy SDL1.2 code. It was done by invoking:
coan source --replace --no-transients -D"SDL_VERSION_ATLEAST(X, Y, Z)"=1 <file>
on each file.
2016-03-13 11:34:34 +13:00
Andreas Löf
b308df8c7e Make sure bigmap isn't overdrawn by in-game UI
The storyscreen would trigger a full redraw-cycle partially through
displaying bigmap. Due to the implementation of the storyscreen, this
would cause it to have the background overdrawn and never updated. The
fix implemented here is to remove layered-drawing functionality from
the storyscreen and trigger a full redraw manually at the end of the
story screen functionality.
2016-03-05 17:15:40 +13:00
Andreas Löf
bdac437efc Fix compilation with SDL1
This fixes two compilation errors when compiling against SDL1. At
least one was brought over from master.
2016-02-28 13:21:36 +13:00
Andreas Löf
b8f18919dd Merge remote-tracking branch 'origin/master' into guifixes
Conflicts:
	src/events.cpp
	src/hotkey/command_executor.hpp
	src/video.cpp

Resolved manually.
2016-02-21 23:00:14 +13:00
Charles Dang
6626bbce22 Add flag to get_available_resolutions() to include current resolution 2016-02-06 20:19:46 +11:00
Andreas Löf
a5f8d62a75 Add initial support for GUI layering
This introduces a subclass of events::sdl_handler that keeps track of
all instantiated classes. When a new instance is created it's pushed
onto a list of all tracked instances. When an instance is destroyed,
all known instances are sent a resize event (under SDL2) to mark them
as dirty. After that there's a DRAW_ALL event pushed onto the event
queue to cause a redraw. There's currently no logic in place to ensure
that there's only one DRAW_ALL event in the event queue at any given
time, but it should be harmless as long as no components are marked as
dirty.
2016-01-30 15:11:20 +13:00
Charles Dang
4afd415143 Decoupled delay() from display class and moved it to a static CVideo function 2016-01-12 10:55:55 +11:00
gfgtdf
93091519bd make CVideo a singleton
half of CVideo's member variables were already static members (in anon
namespaces) so it was never possibel to have more than one of this
class. Making this class a singelton allows us to move all these
variables into the CVideo class.
2016-01-12 00:17:26 +01:00
Andreas Löf
5f5a334fba Make window events a separate handler for sdl_events
This adds a new function to sdl_handler, handle_window_event that is called for all window events. It is propogated to all event contexts instead of just the current one.
events::raise_draw_all_event (and a volatile variant) are added, that also sends draw events to all event contexts in reverse order so that the draw-stack can be redrawn bottom-up.
2016-01-11 18:59:33 +13: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
Charles Dang
68a7259265 Marked a variable as SDL1.2 only 2016-01-03 05:47:42 +11:00
Charles Dang
3c5e6cbdb6 More progress on refactoring window handling under SDL2
General changes in this commit:
* Split window initialization out of setMode and into its own function
* Remove local flags for window state and instead get them directly from the
  window itself.
* Improve handling of distinct window change cases in setMode.
* Refactored and cleaned up several functions.
2016-01-03 04:55:41 +11:00
Charles Dang
8732d8179c Added and deployed getter method for current window resolution 2016-01-01 18:29:54 +11:00
Charles Dang
6272190ec5 Restrict CVideo::modePossible to SDL1 only
It's only called from SDL1 functions anyway
2016-01-01 18:29:51 +11:00
Andreas Löf
544b61534c Fix bug #24209 and add a global event scope
This adds a global event scope that an sdl_handler can register to in
order to receive all current events, regardless of the current
scope. Care should be taken to not be registerd in a local event
context and the global context at the same time as it will lead to the
event handler potentially being invoked twice.

This also adds the workaround needed for #24209 in the new event
handler in the video class.
2016-01-01 17:56:59 +13:00
Charles Dang
ccc2433979 Move relevant functions from preferences to display class
This affects window setter functions such as set_fullscreen() and set_resolution()
2015-12-31 14:00:54 +11:00