1

Topic: Migrate to SDL2

Hey guys.

I started porting Teeworlds to SDL2. It's currently not released but it's widely-used already (e.g. Valve games on Linux). It fixes many bugs that you can't fix with SDL1.2 on Linux like multimedia keys in fullscreen, fullscreen and screen selection in a multi-monitor environment, hardware cursor and ungrabbing they mouse in fullscreen (which is helpful for multiple monitors).

I have not changed to logic at the moment but changed the build system and replaced deprecated functions with the new counterparts. There still is an issue with input handling (segfault) but other than that I works fine.

The code is only tested on Linux because that's all I have so I'd like if someone can jump in and help me with the Windows and Mac versions.

You can find the code here: https://github.com/swick/teeworlds

2

Re: Migrate to SDL2

Would certainly be nice to have fullscreen work better on a multihead setup. I looked through it and left you some comments.

The only thing I don't like about is that the SDL headers are included in the repo. Should be done differently, especially since SDL2 is not yet released and thus likely to change.

3

Re: Migrate to SDL2

It uses the headers on your system on Linux. I included the header files because then you can ship the SDL2 library on windows and mac without having to install it. It works the same way with SDL1.2 just that I don't have the DLL and lib files, yet.
If they are not needed for windows and mac support I'm fine with removing them again.

4

Re: Migrate to SDL2

Required libraries (SDL and freetype) should imho be downloaded by scripts where necessary. PYthon is available anyway. On OS X the libs can just be installed from macports if building yourself, the binary version we offer ships the libraries anyway (on Windows and OS X at least, for Linux SDL2 would've to be statically linked i guess since most distros don't have it yet).

5 (edited by swick 2013-07-07 22:13:19)

Re: Migrate to SDL2

Okay, I'll remove them for now. edit: on the other hand, this is exactly what Teeworlds does ATM. Not sure anymore.
I also figured out why tw crashes sometimes. The Keycode have changed. In SDL 1.2 they all are somewhat in and the maximum is 332 but in SDL 2.0 the keycodes are the scancodes AND'd with 1<<30 which results in numbers > 1024, which is the buffer size. I'm not sure how to handle this.

6

Re: Migrate to SDL2

Would that mean?
Clipbooooooooooard support <3

Not Luck, Just Magic.

7

Re: Migrate to SDL2

Dune, think so, probably needs extra code though. That should bring RTL support too, right?

swick, yes, that's what Teeworlds does currently, I think it's bad (even if practical) though and should be removed. I think I did remove some of the support for shipped libs with my rewrite of bam.lua.

8 (edited by swick 2013-07-23 21:52:02)

Re: Migrate to SDL2

Clipboard is possible. Don't know what you mean with RTL.

Just poked around a little bit more and I came to the conclusion that the key-handling needs to change. Some stuff is auto-gernerated from SDL1.2 header files which doesn't work anymore so it has do be done by hand.

I'll pull your commits and remove the headers.

edit: Has anyone a good idea how to handle the (key-)input with SDL2?
edit2: I'm off for a week

Found more time to work on it unexpectedly.
The code now uses the scancodes instead of keycodes. This fixes the sagfault but is no good solution.

Things which need to get fixed:
FIXED: 1. Support nationalized keyboards for keybindings (keycodes instead of scancodes; old method doesn't work anymore)
FIXED: 2. Input doesn't work anymore (this is not the same as keybindings)
FIXED: 3. it looks like the scrollwheel misbehaves in-game, doesn't look like it's a problem of input, though

Any help is appreciated!

edit: last push for a week! It's already usable.

edit: Fixed all problems I found. Code is up!
I still need testers for Mac and Windows!

edit: Finally got the hardware cursor to work (https://github.com/swick/teeworlds/tree/hardwarecursor)
Required more changes to the mouse handling code than expected, but seems to work fine now.

I already made changes to support multiple monitors and you can even choose the screen from the GUI.

I'm also going to merge all sdl2 specific branches into sdl2all so you can test everything new.

------------------

Have been hard at work to bring you new features.

* support for multiple screens
* GUI to select the screen and appropriate resolutions
* moving mouse cursor freely in and out of the window
* Hardware Cursor
* clipboard support (copy and paste via ctrl+c and ctrl+v)

The code is known to work on Linux and Windows. Still need testers for Mac and someone who does a code review.

You can find the code on GitHub: https://github.com/swick/teeworlds/
* master is the port to SDL 2.0 without new features
* sdl2all contains all new features
* other branches contain what they are named after

-----------
Known Bugs:
* crosshairs lags in windowed mode
* fullscreen in non-native resolutions is buggy (wrong stretching, not rendered areas)

9

Re: Migrate to SDL2

Soon I'll get Windows 8 Computer, and if I have a good time, I will test it.

I'm a god.

10

Re: Migrate to SDL2

If you could post binaries, Im sure you would have more testers...

C++/Java my life ^^
If you like dislike button click it
NOW!

11

Re: Migrate to SDL2

PhOen!X':  thanks dude! I appreciate it.
kittyPL: I can only provide binaries for amd64 (and maybe i386) linux because I don't own a copy of windows or mac.

It would be great if anyone who gets this running on windows or mac could upload the binaries!

I'm currently in touch with the SDL devs because of a few bugs in SDL 2.0 itself. As there is something new I'll report it here.

12

Re: Migrate to SDL2

I can build/test it after including SDL2 in our repos (https://bugzilla.redhat.com/show_bug.cgi?id=989752)

13

Re: Migrate to SDL2

Where can I download the appropiate version of SDL2?

14

Re: Migrate to SDL2

@heinrich5991: Look here: http://www.libsdl.org/hg.php

I will try to compile and test the stuff on Mac OS X if I find the time.

15

Re: Migrate to SDL2

sounds good

Antoine de Saint Exupéry: It seems that perfection is reached not when there is nothing left to add, but when there is nothing left to take away.
Besides -  I am the gfx guy!

16

Re: Migrate to SDL2

I like SFML written in C++ and very easy to use tongue

17

Re: Migrate to SDL2

Let's roll!
http://repos.fedorapeople.org/repos/ign … rlds-sdl2/

18

Re: Migrate to SDL2

Awesome, guys.

Anyone interested in forking my repo, add everything necessary to build it on windows and/or mac and then send me a pull request?

19

Re: Migrate to SDL2

for windows you just have to delete in backend_sdl.cpp

 #include <unistd.h> 

and change in sdl2.lua

 settings.link.libs:Add("SDLmain") 

to

 settings.link.libs:Add("SDL2main") 

(and adding the lib files ofc )

20

Re: Migrate to SDL2

Thanks. Done. I hope everything is alright because I can't test it.

21 (edited by ghost 2013-08-02 15:31:20)

Re: Migrate to SDL2

I got it to work on Mac OS X, too (really easy..) and I'll make a pull request right now. However, I think there should be some more work, I don't think we still need platform dependent code to handle opengl contexts (we can use sdl's opengl contexts) now etc. Would be nice if somebody could look into that.

EDIT: It's very nice to see, that with sdl2, minimizing teeworlds works on Mac OS X just fine smile

22 (edited by swick 2013-08-04 04:10:44)

Re: Migrate to SDL2

Thanks guys. I've merged support for Windows and Mac.
I'd like to have binaries for linux, win, mac for i386 and amd64. Anyone?

For testing:
* linux amd64
* Mac OS X i386 + amd64 (thanks ghost)
* ...

23 (edited by ghost 2013-08-06 11:28:39)

Re: Migrate to SDL2

Mac OS X i386 + amd64 (standalone): http://ghost.crabdance.com/assets/downl … ll-osx.dmg

EDIT: The cursor does not work correctly ingame on Mac OS X. It does not move at all. It moves for a very short duration, if you open one of the "terminals" in tw (f1, f2). Does it work correctly on other OS'es? This seems to be related to hardware cursor, because I'ts ok on your master branch.

However, the mouse is buggy there, too. If inp_grab is enabled, it's buggy ingame and If i start the game, I need to open one of the terminals once in order to make the mouse work (before that, the tw curser is in the upper right corner and I can see the Mac OS X cursor moving, if I move the mouse.

24

Re: Migrate to SDL2

ghost wrote:

EDIT: The curser does not work correctly ingame on Mac OS X. It does not move at all. It moves for a very short duration, if you open one of the "terminals" in tw (f1, f2). Does it work correctly on other OS'es?

On Fedora works fine.

25

Re: Migrate to SDL2

Does it work if you set inp_hw_cursor to 0?