-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
testnative: fix when building with -DSDL_LIBC=OFF #10062
Conversation
9880713
to
61a58a8
Compare
See my comments on pr #10063
I know I'm deviating from std::rand() by returning a Uint32. I did update the docs to say it returns 32 random bits (instead of a number) and suggest using SDL_rand_n(). Here are the pros/cons:
There's an open question on the PR about if SDL_rand_n() should use Sint32 even though negative numbers don't quite work right. |
SDL_rand_n() should probably take and return Sint32, but document that the valid range of n is [0...SDL_MAX_SINT32], otherwise you'll run into problems mixing SDL_rand_n() with signed arithmetic. |
We should probably have SDL_RAND_MAX, for consistency. :) |
Will do. |
I agree that SDL_rand() should return 32-bits, so we have the full 32-bits of values for _float(), etc... actually, float can't represent the full range of 32-bit values, maybe using 31 bits would be fine? |
What if we rename SDL_rand() to SDL_rand_bits(), and make SDL_rand() take an n parameter so nobody can accidentally use it like std::rand? And forget SDL_RAND_MAX because you manually provide the max to rand. Edit: I really like the rand_bits() idea. But maybe we can keep the std::rand() interface for SDL_rand(). |
Maybe we don't expose the rand() interface at all? We just have rand_n and rand_float? |
Yeah. If we're not going to implement std::rand() with all its warts, we probably shouldn't mimic its interface. |
Just submitted #10064 Deleted SDL_rand() to force users onto the correct functions. |
Yes! I just tried your pr and testnative behaves fine. ( |
61a58a8
to
d1a4cf9
Compare
d1a4cf9
to
349235d
Compare
SDL_rand
returns unsigned integers,so
SDL_rand() % (MAX_SPEED * 2 + 1)) - MAX_SPEED
(MAX_SPEED = 1) can result in2**32-1
.I also included a bonus fix for
testnative.c
that failed to link on Windows when built with-DSDL_LIBC=OFF
.Including
build_config/SDL_build_config.h
directly was simpler then copying thetestevdev
workaround to includeSDL_internal.h
.Description
Existing Issue(s)