Language: 
To browser these website, it's necessary to store cookies on your computer.
The cookies contain no personal information, they are required for program control.
  the storage of cookies while browsing this website, on Login and Register.

Author Topic:  why we use unsigned?  (Read 136 times)

0 Members and 1 Guest are viewing this topic.

Dolfo

« on: 04, January 2025, 22:51:54 »
if we don't need negativ values, we often use unsigned types. This will "double" the range we can use.

But mainly all code, we merge sint with uint in logics.

At that moment we merge this, we destroy the advantage of uint double range.

We using unchecked type casts to sint, we producing overflows, we decreasing the allowed range with extended math.

For example nrof is uint32, this would allow 0 und 4.294.967.295 , what sounds cool.

But then we calc the weight, what is sint32 (-2147483648 to 2147483647) with nrof * weight, we kill this advantage.

So there is no need to use uint32 for nrof to allow "more" range, if we break it with math later.

An item with nrof 4.294.967.295 will break our code. An item with 2.147.483.647 needs only weight above 2 and also breaks our code.

uint types can make sense if we use smaller uint types like uint8, uint 16 and the math behind is in bigger ranges like sint32.

but using uint32 when our math is in sint 32 makes only problems.
« Last Edit: 05, January 2025, 15:52:27 by Dolfo »
Don't believe the shit, you hear in mainstream. Believe your own body. Your body is speaking always the true to you. But you need to understand your body. Hear to your body, not to your ego. And when body is calling to you: "Hey something is wrong!" find the reason(s) for that. Man in White don't go for that, they don't want to heal you. They want earn money and sell you medicine, you should take rest of your life. You are not the patient, you are their customer. Never forget this!

michtoen

« Reply #1 on: 09, January 2025, 17:03:22 »
Ok, it is a bit since i looked in the code but here is one reaon.

Mainly, if you have counters or ref. counters there exists no negative value. It would be a bug (and yes ,there are reasons to allow it for example in multi threaded code, but lets hold it simple).

And you are right, at some point for some math it makes no sense to have both worlds, signed and not sigend. But if you think about it - it will break at high ranges always in some way or another. Trust me with that :)

The goal must be something else - a system which use much more sane numbers. We should never come near that problem at all. Because if we solve this - other appear.

In the end it is a kind of entropy problem - and entropy always win.

Some of the ideas of that code started in the early 90s. Even as i designed the base of alot stuff it was just 2000-2002. It was partly trying things out but also partly "how it was done - and hey that would be cool".

WoW really did it right here - its inventory system is simple, unrealistic and somewhat boring - but it works. Easy to implement.

Our system with number of objects and related that to maps & objects and the inventory was much a "whats possible" and "how that will work".

As open source game it is possible to do.
vita est proelium

Tags:
 

Related Topics

  Subject / Started by Replies Last post
3 Replies
837 Views
Last post 18, March 2006, 16:16:09
by smacky
20 Replies
12594 Views
Last post 14, June 2007, 11:52:23
by smacky
4 Replies
843 Views
Last post 29, January 2008, 16:11:49
by wawoolard
17 Replies
1902 Views
Last post 11, September 2008, 21:09:18
by smacky
1 Replies
876 Views
Last post 30, July 2010, 17:09:38
by Anich