Guild icon
DDraceNetwork
Development / developer
Development discussion. Logged to https://ddnet.tw/irclogs/ Connected with DDNet's IRC channel, Matrix room and GitHub repositories — IRC: #ddnet on Quakenet | Matrix: #ddnet-developer:matrix.org GitHub: https://github.com/ddnet
Between 2020-05-26 00:00:00Z and 2020-05-27 00:00:00Z
Avatar
@Learath2 shall I make the teleporters "biased" again so that the reimplementation is easier?
08:33
I'd be in favor of it
Avatar
Reimplementation?
08:35
Also how were the teleporters biased?
Avatar
if you have a number between 0 and 2**31-1 (edited)
08:36
and take that modulo say 3
08:36
then it does not divide cleanly
08:37
2**31-1 = 1, 2**31-2 = 0 mod 3
Avatar
Ah at even 52 teleporters the bias is incredibly small
Avatar
so we have these rests one more time
Avatar
It only starts to get significant at around 2^30
Avatar
we have 0: 715827883 1: 715827883 2: 715827882
Avatar
2^21*
Avatar
see that bias?
08:38
it's incredible
Avatar
At 2^31 some numbers will happen twice as many as others btw
Avatar
yes
08:38
we don't have 2**31 teleporters in maps
Avatar
It does indeed get large when you have bigger buckets
Avatar
I doubt we have maps with more than 1000 out teleporters
Avatar
Anyways if we are staying biased maybe we can do (rand() * range) >> 32
08:40
(I also agree we should stay biased, we just dont ever have ranges that get any significant bias)
08:41
Or just a modulo, not like it's on a performance critical path
08:42
(Not like there are even paths performance critical enough in tw for this to matter)
Avatar
I'll take the modulo, I think
08:43
that's the obvious thing that people can easily implement in all programming languages
08:44
it also obviously generates stuff in 0..n-1
Avatar
I made a lot of pretty histograms and at our ranges you really arent getting any significant bias at all
09:01
@Learath2 ^ my current proposal
Avatar
@heinrich5991 hm the init no longer looks equivalent, is it?
09:50
oh, it is, cute
09:51
The last call to RandomBits can also be changed to a step in the LCG instead
Avatar
@Learath2 I reverted it to the version I had from wikipedia
Avatar
It's a trivial constant cost, I guess it's fine as is
10:12
Should we also find a way to get the teleporter prediction now that we have a prng?
Avatar
not in this PR IMO
10:12
I just used glibc's because that is what we use on all the servers. Based on https://www.mscs.dal.ca/~selinger/random/. Behavior change: The PRNG is actually seeded now.
Avatar
Oh, btw I think you want a lock on this prng
Avatar
I think we're single-threaded
Avatar
Are we sure to stay that way?
Avatar
planning for unknowns just bloats the code
Avatar
Hm, now that I think about it, it'd be a horrible idea to use this prng out of the main thread
Avatar
yes. you can also just instantiate another one
Avatar
We can patch in something like numpy's SeedSequence later if we want semi related prngs
10:15
as in the stream of numbers isn't related but we can derive the other prng from this ones seed
10:15
Anyway, I think this is good to merge
10:18
What should we do with our types btw?
10:18
I also think that having to include system.h just for types is 😦
Avatar
perhaps a different header just for types would be good?
Avatar
If server is full we spam server with connect attempts, this way we are getting "Too many connections in a short time" in return. Why would not we request server status before doing reconnect ? We could request its status till we get something not like N/N
Avatar
is there a way i can properly mask events with 128 players? i assume the current int64_t mask doesnt work for 128 players
Avatar
simple way out: use the gcc extension __uint128
20:18
harder way out: refactor the mask code to work with arbitrary N
Avatar
so i need to replace all the int64_t's to __uint128?
Avatar
yes. only works on 64bit architectures though, but I guess your server has one of these
20:30
#if !defined(_MSC_VER) || _MSC_VER >= 1600 #include <stdint.h> #else typedef __int32 int32_t; typedef unsigned __int32 uint32_t; typedef __int64 int64_t; typedef unsigned __int64 uint64_t; #endif
20:30
@heinrich5991 i need to add the __uint128 there too, right?
20:31
currently its the int64_t, is there a signed uint128?
Avatar
no need, but you could do typedef __uint128 uint128 if you wanted to
20:31
or typedef __int128 int128
Avatar
whats the difference between int128 and uint128?
Avatar
__int128 is signd and __uint128 is unsigned
Avatar
so i would go with int128, i thinkl
20:33
but there is no uint64_t?
20:33
its defined as a normal int64 with the unsigned prefix
Avatar
ah, that code snippet is about msvs anyway
20:34
you don't need to add it there
20:34
I don't know if MSVS even supports int128
20:34
/uint128
Avatar
i hope so, i am working with it
Avatar
I only looked for gcc
Avatar
well, i do get it suggested
20:34
so i think it works
Avatar
int8, int16, int32, int64 Sized integer int n, where n is the size, in bits, of the integer variable. int8, int16, int32 and int64 are Microsoft-specific keywords. Not all types are available on all architectures. (int128 is not supported.)
20:36
what do i do about it?
Avatar
build your own int128, or extend the mask code to work with arbitrary N
Avatar
how do i build a data type?
Avatar
you can build a class that consists of two u64s and implements the needed operatiosn
Avatar
__m128 should work, as it says on the internet
20:39
mh, no it doesnt
Avatar
mh i wrote 256player support once and added a mask for it https://github.com/Jupeyy/teeworlds-fng2-mod/blob/teeworlds_0.6/src/game/server/gamecontext.h just replace long long with int64_t but it doesnt really support the operator's a normal int datatype would
FNG mod for teeworlds, that advances the original FNG idea by golden spikes and other features - Jupeyy/teeworlds-fng2-mod
20:47
but its not too hard to write smth like that
Avatar
wouldnt i be able to use this but as a m_aMask[2] with 2 times int64_t?
Avatar
MSVC doesn't do 128bit integers, not even emulated ones
21:02
yay garbage compilers
21:04
Since you only need to use it as a mask, just use two 64 bit integers and address the correct half for a given index
21:04
It's only "fun" when you need arithmetic operations
Avatar
windows poggers
Avatar
boost multiprecision comes with overengineered overbloated version of a 128bit integer if that's what you need
Avatar
if you change the iterators yes fokko
Avatar
I think stl comes with bitset since forever
Avatar
the < 4
Avatar
or there is std::vector<bool> which is oddly enough a bitset because someone had too much to drink before they made it to the standards committee meeting
21:11
or I think there is some internal winapi voodoo that enables operations on 128bit integers
21:12
Uses two nice DWORD64s
21:13
makes for very clean and pleasant code, as is expected of proprietary code from the 80s
Avatar
if it comes hard on hard, you can also just waste 128bytes xd
Avatar
now don't do that, please
21:17
Oh shove two ULARGE_INTEGERs in a struct now that would be truly horrendous
21:18
Actually put that struct in a union, with an OctuplePart
Avatar
I mean implementing an emulated int128 isn't that hard
Avatar
People should follow standards. Microsoft is the standard. And the circle is complete. – Bruce Zenone May 7 '14 at 21:45
21:22
This attitude is how MSVC has managed to stay relevant for so long
21:22
No Bruce, Microsoft isn't the standard, they are an implementation vendor
Avatar
clang implemented the microsoft standard
Avatar
I'll bet it has something to do with some fat paychecks or some developers on loan
21:30
Microsoft hasn't dished out anything sane in the last decade
21:30
except for maybe their implementation of the C++ STL
21:33
@heinrich5991 what did clang adopt anyway? the msvc extensions?
Avatar
it is binary compatible and header compatible with msvs
21:33
including command line arguments etc.
Avatar
Oh that probably explains why I'm missing a PRIx64
Avatar
it can even generate pdbs
21:34
which they had to reverse engineer
Avatar
Are you sure they reverse engineered it?
Avatar
I think they did and then microsoft said: why didn't you ask us for docs
Avatar
I think microsoft has been pretty open for a while now about their shitty proprietary formats
Avatar
and then they published some half-working code, but still very valuable for RE
Avatar
One day I hope all these companies will stop maintaining their own binary formats
21:41
ELF is flexible enough, or heck I'll even take Mach-O or PE, as long as I don't have to keep 3 of them in mind
Avatar
@Deleted User
22:44
QuadroMask(long long mask) { memset(m_Mask, mask, sizeof(m_Mask)); }
22:44
i do have int64_t m_Mask[2]; now, so what to pass here?
22:44
why does this take a long long mask, and not a QuadroMask
Avatar
nothing, i just did that constructor to set all bits to 1, if required
22:45
u can overload the constructor
22:45
and have multiple
Avatar
what do you mean
Avatar
just change the source to your purpose
Avatar
but i dont really know what all is needed
Avatar
QuadroMask(const QuadroMask& OtherMask) { memcpy(this, &OtherMask, sizeof(OtherMask); } (edited)
22:46
sry
22:46
memcopy
22:46
it
22:47
i dunno what u need xD
Avatar
i am not sure either, because i dont completely understand ur system
22:47
i need to adapt this to fit in the ddnet like teammasking
Avatar
it just overloads common operators u use with bitflags
22:48
like if((Mask | OtherMask)) { //mask is set }
22:49
if you really want it as mighty as a datatype, you should use templates and/or overload the operators with specific datatypes
22:50
i cannot explain what operator overloading does in 2 setences xD
Avatar
just imagine it like that, you can build your datatype u want
22:50
e.g. a int is nothing else than a datatype that overloads the operators
22:51
bool operator==(const int& otherint) { SOME ASSEMBLER } (edited)
22:51
u can imagine it like that
22:51
and you can do the same in c++
22:52
for teeworlds you most probably just need & don't u?
22:53
if Flag & (1 << 63) is set, then id 63 exists
22:53
i think
Avatar
ok
22:54
bool IsSet(size_t BitIndex) const { size_t IndexOfBit = BitIndex / (sizeof(int64_t) * 8); size_t BitInIndex = BitIndex % (sizeof(int64_t) * 8); return (operator[](IndexOfBit) & (((int64_t)1) << BitInIndex)) != 0; }
22:54
so that function would replace what u want todo
22:55
instead of & u just call the function on the bitflag
22:55
if you prefer a & operator you need to overload & operator
Avatar
int64_t operator & (const Mask128& Mask) { return (m_Mask[0] & Mask[0]) | (m_Mask[1] & Mask[1]); }
Avatar
(you can avoid the expensive div and mod)
Avatar
you mean this?
Avatar
for that u need to create an own flag
22:56
also possible to use
22:56
i am lost i think
22:56
too high level for me
Avatar
you need to understand what datatypes are about i think
Avatar
yes, that is what happens if you don't plan things 😄
Avatar
its just some bytes in memory
22:57
@Learath2 how can i avoid it btw 😄
22:57
bit shifting?
Avatar
Well a branch is cheaper
Avatar
puhh yeah probably xD
Avatar
@Deleted User so how would this work with the larger mask? Mask |= 1LL << i;
Avatar
i dunno what the compiler is able todo
22:59
to optimize*
Avatar
I think a smart enough compiler would optimize that
Avatar
@fokkonaut you can e.g. overload a global operator << and add a datatype that reresents another datatype for i e.g. struct SShiftOffset { size_t i; }; then QuadroMask& operator<<(const int& ValueToShift, const SShiftOffset& B) { //if you just accept 1 as valuetoshift anyway QuadroMask m; m.SetBit(B.i); } and call it by 1 << SShiftOffset(Offset)
23:02
something like that
23:02
or just create a mask and call SetBit
23:02
there are infinite ways todo it
Avatar
yep optimizes to a branch
Avatar
interesting 😄
Avatar
@Deleted User uhm, yea so the masking needs to wait :( xd
23:03
im too dumb for this
Avatar
yeah sry
Avatar
make tutorials on assembler to understand that anything is just memory
23:04
its really noit easy to get away from the feeling from datatypes to hardware close things
Avatar
oh even better no branch no nothing
Avatar
have you tried to search for an bitfield implentation in c++?
Avatar
std::bitset
Avatar
maybe someone did it with good implementation already
23:05
ah nice
23:05
that makes it ez xD
Avatar
Oh duh sizeof(int64_t) * 8 is a power of 2
23:06
You can use a shift to do the division
Avatar
yeah 😄
Avatar
power of modern optimizing compilers
Avatar
but yeah fokko, std::bitset is what u want
23:07
even in c++ std what do u want more
Avatar
@Deleted User how the hell did you managed to do single-line-code syntax for multiline code using `
Avatar
23:13
u mean this?
23:13
shift + enter
Avatar
...though
Avatar
u need to do 3 times ` at end and beginning
Avatar
@fokkonaut ye, normally, but he's cheating
23:14
seems Discord trolls itself with it, because it doesn't show that as a code while typing, but does convert after sending
Avatar
i dunno the chat code styles for discord xD
23:15
easiest would be /code xD
Avatar
(╯°□°)╯︵ ┻━┻
23:15
lol
23:16
¯\_(ツ)_/¯
23:16
||||
23:16
sorry
Avatar
` for single line -- code ``` for multi line
Avatar
ah
23:16
i am missing color
Avatar
also, with the multiline you can set language syntax, for colors
Avatar
even steam supports it better xD
23:16
steam chat
Avatar
@Deleted User on pc there is color sometimes
23:17
only for some languages tho
Avatar
body { background-color: #0080FF; }
Avatar
ui
Avatar
nice
Avatar
not for c++ tho
Avatar
@Deleted User ```<language> some code ```
Avatar
<c++> int i(void);
Avatar
don't put it in <>
Avatar
oh xd
23:18
c++ int i(void);
Avatar
c++ void test(int a, int b) { return; }
23:19
ez
Avatar
but typing ` on a german keyboard sucks anyway xD
23:25
./code would be best xd
Avatar
hm I couldn't find a variant of isset that's optimized well on all major compilers
23:42
return __shiftright128(m_Data[0], m_Data[1], idx) & 1; works great for msvc
23:45
(even better then gcc and clangs emulated 128 bit ints)
Avatar
okay not perfect but std::bitset<128> is mediocre across all relevant compilers
Exported 244 message(s)