Commit graph

158 commits

Author SHA1 Message Date
Jyrki Vesterinen
695c8eebe8 Integrate GLEW to the Visual Studio project
I also removed USE_GL_RENDERING (OpenGL rendering is now used
unconditionally), moved initialization of gl::context out of the
constructor, and added some light logging about OpenGL (so that, in the
future with hardware-specific issues, we have a way to know which hardware
is affected).

This commit breaks build with anything except Visual Studio due to
requiring OpenGL and GLEW but not linking to them.
2018-09-27 19:56:22 +03:00
Martin Hrubý (hrubymar10)
bc4d22dc72 Migrate links to https if available - Fwd c18537edc0 2018-07-16 19:07:08 +11:00
Charles Dang
66dc67140f CVideo: removed "help string" interface
These will be handled by GUI2 tooltips once we get the editor all converted to
the new UI system.
2018-04-14 20:25:36 +11:00
Charles Dang
b08fa98260 Removed CVideo::blit_surface
Used to be a surface drawing helper for blitting on the framebuffer surface.
I made it work with accelerated rendering by forwarding it to render_copy,
but we don't need it anymore. All but one of its usecases have been removed.
2018-03-26 14:15:38 +11:00
Charles Dang
85dcef7fa0 Removed remaining references to window framebuffer surface 2018-03-24 10:31:04 +11:00
Jyrki Vesterinen
e70a9c769d Fix size of fake screen
Unit tests (WML and C++ alike) require that the fake screen has nonzero
size. Thus, we again report a nonzero screen size with a fake screen.

Unfortunately, this didn't fix the unit test I was testing
(test_end_turn). The problem is that the null theme is returning that
the game area has zero size; however, I haven't found any differences
between 1.13 and master that would explain why the problem occurs in
master but not 1.13. I'll need to debug 1.13 separately later on...
2018-03-20 20:54:29 +02:00
Charles Dang
625135eb0d Rename events::pump to events::run_event_loop
To make its purpose clearer.
2018-03-20 11:26:54 +11:00
Charles Dang
123dd952c0 Made CVideo::render_screen private
It's not supposed to be called outside events::pump.
2018-03-20 10:33:58 +11:00
Charles Dang
b2d3da4a1e Removed non-functional video2::draw_layering class
Will possibly re-implement this in a different way.
2018-03-20 04:47:40 +11:00
Charles Dang
cbf34d2db3 Video: we don't need to record the refresh rate anymore
Once we get OpenGL rendering all set up, double buffering will limit the frame rate for us.
2018-03-19 01:42:17 +11:00
Charles Dang
46eea05a67 Refactor and cleanup of the drawing dispatch system
Previously, drawing was handled with custom DRAW and DRAW_ALL events which individual event handlers
managed. DRAW was used for only-as-needed draws, and DRAW_ALL for drawing everything. As we've switched
to accelerated rendering, we've switched to the latter model all the time; everything is always drawn.

Both DRAW and DRAW_ALL events aren't needed anymore and have been removed. Instead, we simply call each
handler's draw() function directly from events::pump. The two main cases that handled draw events - the
display class and GUI2 - just forwarded the event handler calls to their respective draw() functions anyway.

Awhile back to unconditionally send draw events to the event queue constantly every 20 ms. However, to prevent
draw calls from becoming backed up, the queue already had code to remove all but 1 draw event from the queue
anyway, so the actual rate of drawing was still reliant on the rate at which events::pump was called. Therefor
this commit should result in no change at the rate the screen is drawn.
2018-03-19 01:22:26 +11:00
Charles Dang
8a82d43855 Some initial code (disabled for now) for setting up an OGL context
In the interests of getting this all done faster, I've decided to postpone work on the OGL implementation for now
and focus on the SDL_Renderer version. This contains some basic code (include-guarded) for setting up an OGL context
for the main SDL window.
2018-03-19 01:22:01 +11:00
Charles Dang
66f2d3f49c Video: removed unused arguments from make_test_fake 2018-03-19 01:21:03 +11:00
Charles Dang
e205e42d44 Video: (almost) completely removed framebuffer surface
Again, useless since there's no more window surface with accelerated rendering.
getSurface() remains since it's still used in quite a lot of places. Will removed ASAP.
2018-03-19 01:21:01 +11:00
Charles Dang
6fbc2491ea Video: expand render_copy to take flip arguments
Still needs to handle rotation.
2018-03-19 01:16:24 +11:00
Charles Dang
d2087a14c4 Initial refactor for main-screen accelerated rendering 2018-03-19 01:16:01 +11:00
Charles Dang
56a793c086 Added SDL_Texture wrapper class and some utility functions 2018-03-19 01:13:47 +11:00
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 3a301db7d4
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