[Patch] Hardware cursor v1.1 (r27050)

Forum for technical discussions regarding development. If you have a general suggestion, problem or comment, please use one of the other forums.

Moderator: OpenTTD Developers

Post Reply
aberro
Engineer
Engineer
Posts: 64
Joined: 20 May 2013 20:20

[Patch] Hardware cursor v1.1 (r27050)

Post by aberro »

I've made this patch because I'm annoyed by lagging cursor, I like things to be smooth at least on input.
This patch compatible ONLY for Win32, not for SDL!
Currently, all cursors, all blitters and all GUI sizes are supported, so practically you won't see the difference other than cursor will be more responsive. If there is something going wrong and HW cursor cannot be created - default cursor drawing routine will be used.
Algorithm is following: get current cursor SpriteID, get sprite data, decode it, create two GDI bitmaps ('and' and 'xor' masks) and DCs, write decoded pixel data into bitmaps, create HCURSOR from them and set default window's cursor to created cursor. When hardware cursor is successfully created and shown or when current cursor ID and size is same as at the moment when hw cursor was created, stop execution of cursor drawing routine. All created HCURSOR are cached, so when CursorID changed, if it has just same sprite, use cached HCURSOR instead of recreating same one. When CursorID is same, but cursor itself changed (both it's size or sprite data), destroy previously cached cursor, recreate new one and cache it.

Code: Select all

Version history:
v1.0
 - Initial release.
v1.1 
  Fix for cursor disappearance.
  Added check for fully transparent cursor.
  Fixed memory leak. Previously cached cursors are now destroyed properly when cache updated.
  All cursors are now supported: switch removed and cursors cache size increased.
  Minor optimizations, comment lines, so on.
P.S.
I don't care for good practices of coding/patching, for merging this patch into trunk, for copyrights or their violation (yes, you may copy this piece of faeces and say that you've done this), for thanks, for curses, for your opinion, for anything but bugs, so don't even bother me with this. If you found bug, especially critical one, you're welcome.
Attachments
HardwareCursor_r27050.patch
(15.52 KiB) Downloaded 214 times
Last edited by aberro on 11 Nov 2014 11:45, edited 3 times in total.
aberro
Engineer
Engineer
Posts: 64
Joined: 20 May 2013 20:20

Re: [Patch] Hardware cursor v1.0 (r27050)

Post by aberro »

There is some critical bug leading to complete cursor disappearance, so do not download this until it fixed. Found just now after a hour of playing.
aberro
Engineer
Engineer
Posts: 64
Joined: 20 May 2013 20:20

Re: [Patch] Hardware cursor v1.1 (r27050)

Post by aberro »

Should be fixed now. Besides, I removed that huge switch, because it was really useless, any cursor may be and should be successfully converted into HBITMAP, so if some patch adds their own CursorIDs, it will be hardware too.
peter1138
OpenTTD Developer
OpenTTD Developer
Posts: 1732
Joined: 30 Mar 2005 09:43

Re: [Patch] Hardware cursor v1.1 (r27050)

Post by peter1138 »

Besides generating a stupidly large map, where does the standard cursor have a lag issue?
He's like, some kind of OpenTTD developer.
aberro
Engineer
Engineer
Posts: 64
Joined: 20 May 2013 20:20

Re: [Patch] Hardware cursor v1.1 (r27050)

Post by aberro »

On slow machines, or when it's over 9000 trains, or while zooming far away, or when large set of trains|stations|objects sprites from newgrfs are loaded first time, or just sometimes. Anyway, I like 'stupidly large maps' because they are more realistic. Besides, even when it's not a really lag, but low fps (<30), it's maybe not so annoying, but still... Personally, I don't like custom cursors that drawn by game at all, whichever game it is. And in case of OTTD, cursors may be easily made hardware would it upgrade to SDL2.0. So, why not to make them hardware at least for GDI drawing driver?
User avatar
FLHerne
Tycoon
Tycoon
Posts: 1543
Joined: 12 Jul 2011 12:09
Location: St Ives, Cambs, UK

Re: [Patch] Hardware cursor v1.1 (r27050)

Post by FLHerne »

petern wrote:Besides generating a stupidly large map, where does the standard cursor have a lag issue?
I get quite noticeable cursor lag on a fairly-well-filled (many ships, newgrfs!) 512*1024 one. Since I'm a Linux user, I don't know if this patch would be an improvement in my case.
Temporary Permanent signature filling text. Content coming soon delayed indefinitely! Oh, and I have had a screenshot thread.
Linux user (XMonad DWM/KDE, Arch), IRC obsessive and rail enthusiast. No longer building robots; now I ring church bells.
Author of an incredibly boring stickied post about NewGRFs.
aberro
Engineer
Engineer
Posts: 64
Joined: 20 May 2013 20:20

Re: [Patch] Hardware cursor v1.1 (r27050)

Post by aberro »

No, until you're playing windows version of OTTD in wine. I've tried to look for solution in SDL, but OTTD still uses SDL 1.2, which doesn't support hardware cursor acceleration as far as I know and it's not in this patch intentions to upgrade OTTD to SDL 2.0. If OTTD would someday upgrade to SDL 2.0 and I wouldn't forget about this patch, I'll try to add HW cursor to SDL OTTD driver too.
User avatar
prissi
Chief Executive
Chief Executive
Posts: 647
Joined: 15 Nov 2004 19:46
Location: Berlin, Germany
Contact:

Re: [Patch] Hardware cursor v1.1 (r27050)

Post by prissi »

SDL_CreateCursor is also an SDL function since the dawn of time. It depends on the video driver whether this will be an hard- or softcursor.
I like to look at great maps and see how things flow. A little like a finished model railway, but it is evolving and actually never finished. http://www.simutrans.com
aberro
Engineer
Engineer
Posts: 64
Joined: 20 May 2013 20:20

Re: [Patch] Hardware cursor v1.1 (r27050)

Post by aberro »

Ok, I'll check what I can do and if everything will be all right then I'll update the patch.
peter1138
OpenTTD Developer
OpenTTD Developer
Posts: 1732
Joined: 30 Mar 2005 09:43

Re: [Patch] Hardware cursor v1.1 (r27050)

Post by peter1138 »

SDL_CreateCursor only allows black and white cursors. SDL_CreateColorCursor is needed, which is not in SDL 1.2.
He's like, some kind of OpenTTD developer.
aberro
Engineer
Engineer
Posts: 64
Joined: 20 May 2013 20:20

Re: [Patch] Hardware cursor v1.1 (r27050)

Post by aberro »

Well, looks like the task is done before I even get to it.
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 21 guests