Diablo® III

How to Implement: Commas

Hey Guys,

i just found a great tutorial on how to implement commas for Diablo 3 (in C++).
We should all let the Devs know how to do it, so it can be done fast!

http://pi7.eu/blog/139
its only a few lines of code:
void addCommaToNumberString( char* numberString, int &length )
{
int readPos = length - 1;
length += readPos / 3;
int writePos= length - 1;

while( readPos > 2 )
{
numberString[ writePos - 0 ] = numberString[ readPos - 0 ];
numberString[ writePos - 1 ] = numberString[ readPos - 1 ];
numberString[ writePos - 2 ] = numberString[ readPos - 2 ];
numberString[ writePos - 3 ] = ',';

readPos -= 3;
writePos -= 4;
}
}


happy greetings,
Surir
Reply Quote
No comment, please add comments or else dev would be clueless. They've been trying to do this for years with no success.
Reply Quote
Rofl
Reply Quote
You should check length first:

if (length > 0) {
...
}

Also, what about asian regions? Now you have to pass in the regional expectation, so your prototype changes a bit:
void addCommaToNumberString( char* numberString, int &length, enum region);

Or to avoid over engineering, just use the operating system region locales for handling presentation. Something a little smarter then this hooplah. http://www.globalyzer.com/gzserver/help/i18ntopics/cpplocales.html
Reply Quote
@GodOfDiablo: i removed the comments from the code posted, because it would not fit in the code-box ;)

@semiXform: well you could add a lot of standart stuff to this function, i think it is showing the core of this complex algorithm, wich is even optimized for Performance (ASM could be even faster)
Adding Commas is not for noobs!
Reply Quote
Currency formatting should take into account locale. Some use commas, some don't.

Also, in C++...

int value = 1978879;
std::cout.imbue(std::locale(""));
std::cout << value << std::endl;

Just look up and specify the appropriate locale, as defined in the system, and you'll have the thousands separator the person is used to.
Reply Quote
Stop trolling TC.

First they have to put the issue on the table and discuss it, then they have to approve it. Then they have to tell the devs to learn how to implement the change, they have to make it and test internally.

And finally they have to prepare the 1 month PTR to see if any adjustments are required.

Give them their time Jesus, people are so entitled and impatient these days.


We're talking about comma's... Not adding another boss into the game. This should be a quick fix like in a phone app game...
Edited by Lolly#1416 on 8/5/2013 11:56 AM PDT
Reply Quote
Stop trolling TC.

First they have to put the issue on the table and discuss it, then they have to approve it. Then they have to tell the devs to learn how to implement the change, they have to make it and test internally.

And finally they have to prepare the 1 month PTR to see if any adjustments are required.

Give them their time Jesus, people are so entitled and impatient these days.


:D

but you forgot the Iterative process!
Reply Quote
08/05/2013 06:41 AMPosted by Surir
numberString[ writePos - 0 ]


If the numberString is not preallocated to be big enough for the commas to be added this will fail with a buffer overflow.
Reply Quote
Yep this is one of those things, similar to adding an "appear offline" mode, that the freaking intern could add while he/she is on their lunch break.
Reply Quote
It has to FIRST check if there already commas and if it is the EU, Azian or the US realm.

In Eurasia the use of dots is more status quo. If you use 2 or more commas in big numbers it suggests you are unfamiliar with history. A stereotype that generally works well with English speaking people.

ISO dictates dots, so there you have it.

A good work around would be to have spaces between the numbers. That way Americans can understand it, British people can understand it and it wont look silly to the rest of the world?

Easy as cake, yes?
Reply Quote
Sticky requested

:-D
Reply Quote
"Commas are something we've been talking a lot about around the water cooler lately, and a lot of the devs have been really excited about the addition of commas into the game. A lot of ideas about commas have been tossed around some of our discussions lately.

We've had several discussions about commas, but nothing is planned for implementation as of yet, since we must still internally playtest them before coming up with any concrete decisions.

We really like the idea of commas, but find that there is some conflict with our vision of the game and how things will be progressing currently. It is a work in progress to try and integrate commas into the game and trying to determine how that will affect the metagame overall.

We are planning on having a working internal 'Commas Build' that we can test out as soon as November, but nothing is set in stone quite yet."
Reply Quote
They have coding issues. They also have management issues and decisions seems to be made by people that don't play the game. Look at raising the GAH gold cap from 2B. As stated, the effort to make that happen is too much to worry about right now. Well I can agree as long as they tell us its screwed up too much, but their not telling us its their fault. Only that its too hard.

As programmers, its difficult to say something is too hard, because its not, its usually just too time consuming. That only happens when the wrong decisions are made from the beginning.

Rather then admit failure, they admit incompetence.
Reply Quote
They have coding issues. They also have management issues and decisions seems to be made by people that don't play the game. Look at raising the GAH gold cap from 2B. As stated, the effort to make that happen is too much to worry about right now. Well I can agree as long as they tell us its screwed up too much, but their not telling us its their fault. Only that its too hard.

As programmers, its difficult to say something is too hard, because its not, its usually just too time consuming. That only happens when the wrong decisions are made from the beginning.

Rather then admit failure, they admit incompetence.


Let me be the first to tell you it doesn't work like that.

The game was already sold,

the game was already a success.

Now it is really time to have the code finished mr microsoft.
Reply Quote
@whoopadeedoo: haha, nice, didn't see it ;)
@marsovac: check the blog ;)
Reply Quote

Please report any Code of Conduct violations, including:

Threats of violence. We take these seriously and will alert the proper authorities.

Posts containing personal information about other players. This includes physical addresses, e-mail addresses, phone numbers, and inappropriate photos and/or videos.

Harassing or discriminatory language. This will not be tolerated.

Forums Code of Conduct

Report Post # written by

Reason
Explain (256 characters max)
Submit Cancel

Reported!

[Close]