Commit graph

33042 commits

Author SHA1 Message Date
Charles Dang
3376ef04e3 Another large batch of progress, primarily in game_display
This is primarily focused on getting various areas of the game display drawing, such as footstep images
and the terrain defense indicators.

To facilitate the last, I've refactored draw_text_in_hex to utilize floating labels instead of drawing
to hex directly with surfaces. This probably isn't the most optimal solution, since labels are continuously
created and destroyed, but since their text is usually short and cached in the rendered text cache it
does for now.

Also includes some cleanup of deprecated functions in display, and slight reordering of drawing order of
certain elements.
2018-03-19 01:29:34 +11:00
Charles Dang
92d51b866d Added RAII helper struct to manage a floating label's lifetime 2018-03-19 01:29:32 +11:00
Charles Dang
07844f471b Comment out an unused parameter
Not sure if we'll need this again (perhaps to delay draws mid-action) so I'm not removing it yet.
2018-03-19 01:29:31 +11:00
Charles Dang
f8e71f4d9a Display: avoid unnecessarily (potentially) creating millions of temp vectors
I've moved the terrain hex drawing code directly into draw_visible_hexes instead of relying on get_terrain_images
to return a vector of all the necessary images for each visible hex and then drawing them. Instead, we now draw
each hex's images immediately without any intermediary container.

With the old method, after about 10 to 15 seconds of drawing we had already allocated (and destroyed) almost 180,000
temporary vectors (a new one was created for each hex, twice per draw cycle). It's obvious how quickly that would add
up over a normal play session, and though in this case the performance hit for creating each vector was probably tiny,
creating them likely would have added up.
2018-03-19 01:29:30 +11:00
Charles Dang
e9a8813b67 Floating Labels: use new pango_text functionality for generating text outline 2018-03-19 01:29:29 +11:00
Charles Dang
9add86d745 Avoid temporary object when creating new textures from disk 2018-03-19 01:29:28 +11:00
Charles Dang
2f2adc6899 Some updates to the texture wrapper class
* Made reset() a public function
* Added an assign() function
* Don't try to destroy null textures
* Updated doc comments

I left assign() as just taking an SDL_Texture ptr since having it take a texture ref would be
functionally equivalent to operator=.
2018-03-19 01:29:27 +11:00
Charles Dang
8bb6f193a9 Font/Pango Text: add extra stroke to text outline to compensate for alpha weirdness
Also added the outline to the hash.
2018-03-19 01:29:24 +11:00
Charles Dang
1fd9a16a86 GUI2/Canvas: handle text alpha as a render-time op
This reduces the number of times the text itself needs to be rendered, especially for areas like the
story viewer where the only difference is alpha.
2018-03-19 01:26:20 +11:00
Charles Dang
3bf6768685 Floating Label: header formatting updates 2018-03-19 01:26:19 +11:00
Charles Dang
8647ff63c0 Added a texture cache for pango_text render output 2018-03-19 01:26:18 +11:00
Charles Dang
a0f8ad67a5 GUI2/Canvas: don't skip drawing if canvas texture is null 2018-03-19 01:26:16 +11:00
Charles Dang
9d90539fc7 Display: re-enable fps counter with :fps 2018-03-19 01:26:15 +11:00
Charles Dang
78bcd85d9f Display: cleaned up a bunch of now-unused/unnecessary members and functions 2018-03-19 01:26:14 +11:00
Charles Dang
cdb43343b4 Marked sdl_handler::draw overrides as final 2018-03-19 01:26:12 +11:00
Charles Dang
dadb31aadf Display: header formatting and doc updates
Appropriate functions were also marked deprecated.
2018-03-19 01:26:11 +11:00
Charles Dang
e422261518 Removed external calls to display::redraw_everything() 2018-03-19 01:26:10 +11:00
Charles Dang
35a9dc6084 Video: don't render null textures 2018-03-19 01:26:09 +11:00
Charles Dang
345fa27565 Display: work on refactoring the main drawing system
Previously, every visible hex was iterated over and every element in that hex draw. This was inefficient
for two reasons: First, it meant the performance footprint for many operations like unit drawing was O(n²),
since the list of elements had to be checked for every single hex. Second, it meant the renderer had to
switch active textures many more times than necessary.

My new system involved drawing every element of a specific type at once - ie, all background terrains at
once, all units, all items, etc. This reduces lookup time from O(n²) to O(n) and results in a noticeable
performance increase. It also reduces the number of times the renderer needs to switch active textures,
since bulk draws such as the map grid overlay are now done all at once while that specific texture is
active.

There are still some layering issues and missing elements that need to be sorted, especially in game_display.
2018-03-19 01:26:07 +11:00
Charles Dang
0d69cbad69 SDL/Texture: made info struct take a texture ptr directly
Will allow me to construct one directly from a pointer if I don't have a wrapper object.
2018-03-19 01:26:06 +11:00
Charles Dang
2cddf5e2c5 Fixed some bad drawing offsets and sizes when zoomed in
This fixes HP/XP bar size (wasn't scaled to zoom) and placement, as well as crown/orb and main sprite placement.
2018-03-19 01:26:05 +11:00
Charles Dang
a86ac0675f Display: removed old drawing code and external draw calls 2018-03-19 01:23:09 +11:00
Charles Dang
9850e47720 Removed animation invalidation code
This no longer actually does anything now that location invalidation is removed. If you follow the code
animation_component::invalidate called unit_animation::invalidate which was responsible for generating
the overlaped_hex_ set. Previously, this is what locations were invalidated. Now it didn't do anything.
2018-03-19 01:23:07 +11:00
Charles Dang
c5be598cd0 Display: removed all the invalidated locations code
This removes all the code related to invalidating locations, any functions used to set, modify, or propagate
location invalidation, and several functions that no longer serve any purpose anymore since their only purpose
was to handle invalidated locations.
2018-03-19 01:23:06 +11:00
Charles Dang
ffc064eca2 SDL/Window: throw exception if render-to-texture is not enabled
NOTE: for some reason, if I remove the `SDL_RENDERER_TARGETTEXTURE` flag from sdl::window's ctor
render_flags argument, this assertion still doesn't throw. Not sure if that means by GPU supports
it by default, or what.
2018-03-19 01:22:31 +11:00
Charles Dang
48d61611f8 Fixed halos drawing over fog and shroud (fixes #1406) 2018-03-19 01:22:29 +11:00
Charles Dang
d23d1ea338 Renamed drawing_buffer to drawing_queue
Also renamed drawing_queue::drawing_layer to just 'layer'.
2018-03-19 01:22:28 +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
b746829692 Improved console output on IPF fail
Yes, I know the duplicate code should be consolidated.
2018-03-19 01:22:24 +11:00
Charles Dang
085bd42974 Display: restrict render clip rect setter to map drawing scope only
This prevents tooltips from being cut off.
2018-03-19 01:22:23 +11:00
Charles Dang
f25a404f37 Refactored floating_label implementation
* Store label as a texture instead of creating a texture from a surface every draw cycle
* Restored expired label removal and alpha fadeout (was accidentally removed earlier in my refactoring)
* Use alpha field of bg_color member for background color
* Draw tooltip backgrounds procedurally instead of with surfaces and part of the label texture itself.
  See included comment for small caveat.
2018-03-19 01:22:21 +11:00
Charles Dang
2c9d9efb1d Floating Label: formatting update 2018-03-19 01:22:20 +11:00
Charles Dang
ed27b67f1e Port floating textbox/command console to GUI2
The old floating textbox was extremely entwined with the controller_base, play_controller, and menu_handler
classes. controller_base::have_keyboard_focus essentially controlled whether some events were executed based
on whether the floating textbox was open or not. Additionally, those events weren't even reached if a UI dialog
was open at all.

The new design features a singleton console class that can be called from anywhere, not just the game. I've also
decoupled the execution object from play_controller. The relevant functions in menu_handler are now passed to
the console as callbacks.

To work around map events such as clicking not being available if the console was open, I removed the exclusionary
is-in-dialog check from controller_base::handle_event and instead exit early out certain types of events using
controller_base::have_keyboard_focus. As mentioned in the accompanying comment, this isn't the best solution, but
it will do for now.

The new console also isn't fully feature-comparable with the old GUI1 one. The following are still missing:
* The checkbox, for use when sending messages.
* Tab completion.
* A crash occurs when existing the app if a game was exited with the console open.

I'm leaving the old floating_textbox code around for now for reference.
2018-03-19 01:22:18 +11:00
Charles Dang
770664d1f3 Added a getter for a static pango_text object
The reason I added this was so I can refactor some temporary pango_text objects out of the display class.
styled_widget doesn't use this for reasons explained in the comment.
2018-03-19 01:22:16 +11:00
Charles Dang
2dca404a63 Split texture caches into linear and NN scaled versions
With textures, you can't change render scale quality once they've been created. To rectify this, I've
made the texture caches a map of caches, sorted by scale quality. This should result in no performance
overhead, since an image is simply added to the appropriate quality cache on creation instead of in
a single cache. If a different version of a texture is needed it will be loaded later.

By default, load_texture will return images using nearest neighbor scaling. GUI2 always fetches images
using linear scaling. This is consistent with the old software rendering method. Plus, we don't have
any way (as of now) to specify the render quality on a per-image basis.
2018-03-19 01:22:14 +11:00
Charles Dang
6c04ae29b9 GUI2/Window: removed empty undraw() function
This was emptied earlier in my refactor when window unrendering was removed. I simply hadn't
removed the function yet.
2018-03-19 01:22:13 +11:00
Charles Dang
3154ab419f Restored alpha handling of unit frames
Still need to figure out the blending effects or submerge alpha.
2018-03-19 01:22:12 +11:00
Charles Dang
c406a2067f Refactored halo code to bring it in line with new drawing methods
This basically rips out all the unrendering and invalidation code. Neither is needed anymore.
Instead, we can have a simple, clean, "just draw the managed halos" interface.

Note there's an issue unrelated to this where halos aren't removed when a unit is killed with
the debug kill menu command.
2018-03-19 01:22:10 +11:00
Charles Dang
f7de368551 Added some inline wrappers for SDL_SetTexture* functions 2018-03-19 01:22:09 +11:00
Charles Dang
ca44435550 SDL/Window: removed pixel format member and promoted renderer info wholly to class member
The pixel format member was really rather useless, since SDL_RenderInfo returns an array of supported
formats and only the first one was being saved.
2018-03-19 01:22:08 +11:00
Charles Dang
855345291b GUI2: removed some unnecessary calls to canvas::set_is_dirty
The one in Outro was unnecessary since set_variable already calls set_is_dirty.
The one in the Story Viewer was there to deal with some background redraw issues which no longer appear
with the new drawing methods.
2018-03-19 01:22:06 +11:00
Charles Dang
c8f36d2758 GUI2/Canvas: set clip rect when tiling images
This fixes an issue where images could be tiled outside their desired size area.
2018-03-19 01:22:04 +11:00
Charles Dang
af861f7292 Allowed IPFs to work again when using the texture cache
See create_texture_from_sub_file doc comment for more info.
2018-03-19 01:22:03 +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
61dcb43ee6 GUI2/Canvas: refactor surface use out of image rendering
The only real reason to keep using a surface was in order to have resize mode manipulations. I've now added
texture-only handling methods (the tiling one was borrowed from display.cpp's draw_background function).
2018-03-19 01:21:12 +11:00
Charles Dang
01d78cbb7f Trim ToD images to hex 2018-03-19 01:21:11 +11:00
Charles Dang
1cb496d966 Extended implementation of the texture cache
Instead of always loading a surface at the same time, textures are now loaded directly from disk if applicable.
Instead, surfaces are only loaded if applicable to apply some effect that cannot as of now be done with texture
manipulation since we dont have shader support yet.

In that vein, I've also added two new texture caches, one for masked-to-hex images and one for ToD colored images.
2018-03-19 01:21:10 +11:00
Charles Dang
250bb0b3af GUI2/Canvas: fixed mirrored images being flipped on the wrong axis. 2018-03-19 01:21:08 +11:00
Charles Dang
d748cbcd23 Units: fixed bad HP/XP bars fill rect offset 2018-03-19 01:21:07 +11:00
Charles Dang
37bcade3a1 Removed most call to raise_draw_event
These don't seem necessary anymore since draw handling happens per-frame and doesn't rely
on calling derived class's draw() member.
2018-03-19 01:21:06 +11:00