Stringtable
Stringtable
I got another question, this time about xml. I wrote a simple stringtable which can read words out of a xml file so that I can change names, add new names to anything, use different languages and don't have many strings. Everything works but I think if my game is bigger and I need eg 5000 names It'll load very long because I make a new xml reader and delete that reader every time. Is there a way to let the reader stop reading and start reading? Will it lag or is deleting and adding very fast? If it's neccessary I can post the source code.
Just use dynamic arrays (core::array for example)Sir_Hans wrote:It works now but I have to give the number of strings in the array in the source code. Is there a way to read a constant number out of the xml file that I can use it for the size of the array?
Software documentation is like sex. If it's good you want more. If it's bad it's better than nothing.
Sir_Hans wrote:I need wchar_t but I don't know how to convert core::array.
Code: Select all
core::array<core::stringw> theStringList;
theStringList.push_back(L"Satz 1");
theStringList.push_back(L"Satz 2");
theStringList.push_back(L"Satz 3");it's because Irrlicht doesn't support umlauts at all, even if you use another lib that supports umlauts (e.g. tinyXML) you won't be able to use them in Irrlicht (e.g. with static text boxes)...Sir_Hans wrote:I got another problem, I can't use umlauts in the xml file. I looked for that in google but I couldn't find an answer which works.
but IIRC there is a guy who made a new string and font class for UTF-8...
while(!asleep) sheep++;
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
IrrExtensions:

http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
realy ???hybrid wrote:Of course umlauts and other non-ascii characters are supported. You just need to find a matching locale
I never got umlauts to work !!!
if I try something like this:
Code: Select all
font->draw(L"äöüßÄÖÜ", recti(10, 10, 200, 20), SColor(255, 255,255,255));
// or
IGUIButton* btn = guienv->addButton(recti(10, 10, 100, 100), 0, 0, L"äöü");if I do something like this:main.cpp|24|converting to execution character set: Illegal byte sequence
Code: Select all
font->draw(stringw("ÄÄÄÄ").c_str(),recti(10,10,200,20), SColor(255, 255,255,255));and of course I get the error again with this:
Code: Select all
font->draw(stringw(L"ÄÄÄÄ").c_str(),recti(10,10,200,20), SColor(255, 255,255,255));but not if I set the text inside the code (again the error occures)...
but what exactly do you mean by find a matching locale !?!?!
while(!asleep) sheep++;
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
IrrExtensions:

http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Hm, could be it depends on the compiler if it allows umlauts in source-code. But loading them from xml should usually work.
In case you haven't seen it already, there's also 2 different string-table implementations on my homepage: http://www.michaelzeilfelder.de/irrlich ... tringTable
They both use tinyXML, but that's mainly because I knew that more back then I wrote those. The simple implementation doesn't care about encoding and keeps only simple strings. The complexer implementation does load utf-8 files and converts them to a corresponding wide-char format (utf-16 on Windows and utf-32 on Linux). It also supports parameters.
In case you haven't seen it already, there's also 2 different string-table implementations on my homepage: http://www.michaelzeilfelder.de/irrlich ... tringTable
They both use tinyXML, but that's mainly because I knew that more back then I wrote those. The simple implementation doesn't care about encoding and keeps only simple strings. The complexer implementation does load utf-8 files and converts them to a corresponding wide-char format (utf-16 on Windows and utf-32 on Linux). It also supports parameters.
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
well, I must admit that I didn't try the xml reader/writer from Irrlicht, I'm also using tinyXML and there I had never problems with umlauts...
the error I get is always with wchar_t (L"äöü") not with normal strings ("äöü"), but all text functions from Irrlicht are used to use wchar_t...
if I use Irrlicht functions that use normal char strings (like pathes) I can use umlauts, only with text I can't use them...
the error I get is always with wchar_t (L"äöü") not with normal strings ("äöü"), but all text functions from Irrlicht are used to use wchar_t...
if I use Irrlicht functions that use normal char strings (like pathes) I can use umlauts, only with text I can't use them...
while(!asleep) sheep++;
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
IrrExtensions:

http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
I can write umlauts on buttons but I cannot get the umlauts from the xml file.
What's wrong? (it's made very easy)
CStringTableReader.cpp
xml:
Thanks for all the replies. I hope anyone can help me.
@CuteAlien: I didn't see them but the code seems more difficult than mine. I couldn't find any code for a stringtable but I wanted one because it is very easy andI saw it in AoE3 which was made with c++ so I knew that it's possible and tried it myself.
What's wrong? (it's made very easy)
CStringTableReader.cpp
Code: Select all
#include "../header/CStringTableReader.h"
CStringTableReader::CStringTableReader(s32 g_language) {
language = g_language;
switch (language)
{
case 1:
stringreader = createIrrXMLReader("data/stringtable_de.xml");
break;
case 2:
stringreader = createIrrXMLReader("data/stringtable_en.xml");
break;
default:
stringreader = createIrrXMLReader("data/stringtable_en.xml");
break;
}
if(stringreader && stringreader->read()){
while(stringreader && stringreader->read()){
if (!strcmp("string", stringreader->getNodeName()))
{
numbers = stringreader->getAttributeValueAsInt("numbers");
}
for(int i = 0; i <= numbers; i++)
{
if (i == stringreader->getAttributeValueAsInt("id")){
strings[i] = stringw (stringreader->getNodeData()).c_str();
}
}
}}
delete stringreader;
}
stringw CStringTableReader::ReadId(int id)
{
return strings[id];
}
xml:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<string numbers="5"/>
<stringtable>
<name id="1">Schnellstart</name>
<name id="2">Mehrspieler</name>
<name id="3">Optionen</name>
<name id="4">Beenden</name>
<name id="5">Zurück</name>
</stringtable>
Thanks for all the replies. I hope anyone can help me.
@CuteAlien: I didn't see them but the code seems more difficult than mine. I couldn't find any code for a stringtable but I wanted one because it is very easy andI saw it in AoE3 which was made with c++ so I knew that it's possible and tried it myself.
Like the other times just for knowing: Is it so easy that I should do it myself or is it so hard that I need a long code for that or what's wrong with my code?
Is there a if way? I just need the thing that the reader gets for the umlaut then I could try:
for (i = 0; i<30 ;i++){
if (!strcmp(strings[id], "the letter that the reader gets for the umlaut")){
strings[id] = L"the specific umlaut like ü"
}}
Please ask if any information are missing.
PS: Sorry for doublepost but if I don't do that the thread isn't marked.
Is there a if way? I just need the thing that the reader gets for the umlaut then I could try:
for (i = 0; i<30 ;i++){
if (!strcmp(strings[id], "the letter that the reader gets for the umlaut")){
strings[id] = L"the specific umlaut like ü"
}}
Please ask if any information are missing.
PS: Sorry for doublepost but if I don't do that the thread isn't marked.