Stringtable

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Sir_Hans
Posts: 143
Joined: Sun Dec 06, 2009 2:23 pm
Location: Germany

Stringtable

Post by Sir_Hans »

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.
Sylence
Posts: 725
Joined: Sat Mar 03, 2007 9:01 pm
Location: Germany
Contact:

Post by Sylence »

You read the whole file when you want to get one string?
If I got this right that way is BAD.

Parse the file one time and store the strings in memory and access the saved values from then on.
Software documentation is like sex. If it's good you want more. If it's bad it's better than nothing.
Sir_Hans
Posts: 143
Joined: Sun Dec 06, 2009 2:23 pm
Location: Germany

Post by Sir_Hans »

Parse the strings into an array and return the array? hmmm... didn't think about. Thanks, I'll try that. :)


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?
Nox
Posts: 304
Joined: Wed Jan 14, 2009 6:23 pm

Post by Nox »

Why dont you use a (hash)table for the lookups?
Sylence
Posts: 725
Joined: Sat Mar 03, 2007 9:01 pm
Location: Germany
Contact:

Post by Sylence »

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?
Just use dynamic arrays (core::array for example)
Software documentation is like sex. If it's good you want more. If it's bad it's better than nothing.
Sir_Hans
Posts: 143
Joined: Sun Dec 06, 2009 2:23 pm
Location: Germany

Post by Sir_Hans »

The array has now a size of 10000 but only the first 5 strings are used for testing. I need wchar_t but I don't know how to convert core::array.

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.
Nox
Posts: 304
Joined: Wed Jan 14, 2009 6:23 pm

Post by Nox »

Uhhh....are you used to containerclasses? If not I would recommend you to read some stuff about them.

The "umlaut problem" is that you use a acsii encoding afaik. If you want more letters with a xml you can i.e. use UTF-8 encoding.
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

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");
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.
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)... :cry:
but IIRC there is a guy who made a new string and font class for UTF-8... ;)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Of course umlauts and other non-ascii characters are supported. You just need to find a matching locale :roll:
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

hybrid wrote:Of course umlauts and other non-ascii characters are supported. You just need to find a matching locale :roll:
realy ??? :shock:
I never got umlauts to work !!! :cry:
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"äöü");
I always get an error like:
main.cpp|24|converting to execution character set: Illegal byte sequence
if I do something like this:

Code: Select all

font->draw(stringw("ÄÄÄÄ").c_str(),recti(10,10,200,20), SColor(255, 255,255,255));
I get no error message, but the text will not be drawn...
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));
strange is that I can enter umlauts into an edit box !!! :shock:
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:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
CuteAlien
Admin
Posts: 9933
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

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.
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
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

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... :shock:
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Sir_Hans
Posts: 143
Joined: Sun Dec 06, 2009 2:23 pm
Location: Germany

Post by Sir_Hans »

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

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.
Sir_Hans
Posts: 143
Joined: Sun Dec 06, 2009 2:23 pm
Location: Germany

Post by Sir_Hans »

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.
Post Reply