In the game I'm developing (well, it will be a game, eventually, hopefully), I'm trying to set up a simple way to display dialogue. I created a function called "message", which takes text as a parameter, and adds it (or concaternates, or whatever) to a variable that stores the current message, and then prints the message to the screen. Originally, I used IGUIFont::draw to display the text (I was looking at the 2D Graphics tutorial, and that's what they used there, so I thought it was the standard), and that wanted the text as a stringw, so I made the variables use stringw. Then I wrote some code for wordwrap, which used some of the stringw functions, and had to do some conversion to use the IGUIFont::getDimensions function, which requires a wchar_t*. And... then I found out about the addStaticText function, which had wordwrap built-in, and uses a wchar_t*, as does basically everything else. So I got rid of the wordwrap portion of my code, and set the function to use the addStaticText thing. Moving on, I wrote some code to handle the whole "press ENTER for next page of dialogue" thing, (interpreting a form feed character as a separation between pages, and advancing to the next page if the nextmessage variable is true), and then I ran into, again, some issues with conversion. Very annoying, and I'd rather not have to keep dealing with that, so I'm thinking I'll just use wchar_t* to make life a lot easier. But since this is going to be a long project, I figured I should make sure there isn't some reason why it would be better to use stringw. And also, why IGUIFont::draw uses stringw when basically nothing else does.
The only merit I see to using stringw is that it has those built-in functions for searching and such, which are quite useful, but I could easily write my own functions to do all that.
I've done Google searches, as well as searches on this forum, and have basically found two things: people having trouble converting between stringw and wchar_t*, and people having issues with xml and unicode. Nothing, as far as I can tell, about why I shouldn't just skip the conversion issues and use wchar_t*. So, if someone with more knowledge of Irrlicht and C++ and programming and computer science could explain things a little, it would be very much appreciated.
P.S. For what it matters, my game is supposed to be multi-platiform. I'm designing it on Ubuntu 12.10, and once I solve the stupid DLL errors in Windows 8, I'll be working on it on that, too. Might end up going for Android as well, since I have an Android tablet. And it's a single-player adventure game, in English only.
P.P.S. I didn't include code because I figured it didn't matter too much, but if you want/need it, I'll post it.
Stringw versus wchar_t*
Re: Stringw versus wchar_t*
I guess I dont understand the question. It is remarkably simple to convert between wchar and char types using the stringc and stringw classes.
stringc(wtext); //converts wchar_t* to char*
stringw(ctext); //converts char* to wchar_t*
I use this in my logging functions since I use MFC and it requires wchar* text for window labels and whatnot.
I prefer to use stringc in my main program and use stringw(myStringc).c_str(); whenever I need to convert to wchar*
stringc(wtext); //converts wchar_t* to char*
stringw(ctext); //converts char* to wchar_t*
I use this in my logging functions since I use MFC and it requires wchar* text for window labels and whatnot.
I prefer to use stringc in my main program and use stringw(myStringc).c_str(); whenever I need to convert to wchar*
Re: Stringw versus wchar_t*
Huh. Thought I'd made it clear, but I guess I never actually explicitly stated the question. Oops.
The question was whether there was any reason to use stringw (aka irr::core::string<wchar_t>) instead of just using wchar_t*. What's the benefit of stringw as opposed to wchar_t*? Because it really just seems like a hassle to store things in stringw and have to convert to wchar_t* whenever you want to display it. Seems like a waste of time and code.
The question was whether there was any reason to use stringw (aka irr::core::string<wchar_t>) instead of just using wchar_t*. What's the benefit of stringw as opposed to wchar_t*? Because it really just seems like a hassle to store things in stringw and have to convert to wchar_t* whenever you want to display it. Seems like a waste of time and code.
Re: Stringw versus wchar_t*
It's the difference between a C++ type and a C type. stringw lets you do string += something_else.
Re: Stringw versus wchar_t*
The main advantage is that stringw handles the memory for you.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm