YAML > XML

Random irrelevance that just didn't fit into other forums. Talk about anything.

Moderator: Talkative People

K-Bal
ES Beta Backer
ES Beta Backer
Posts: 701
Joined: Sun Mar 15, 2009 3:21 pm
Location: Germany, Aachen
Contact:

YAML > XML

Post by K-Bal »

Anyone who wants to use XML should consider a short look at YAML with libyaml-cpp. It's extremely easy to use (from my game):
rats.yaml wrote: -
name: "Small Rat"
model: "hueteotl"
texture: "rat.png"
scale: 2.0
maxhealth: 15.0
maxmana: 0.0
maxvelocity: 20.0
-
name: "Big Rat"
model: "hueteotl"
texture: "rat.png"
scale: 3.0
maxhealth: 25.0
maxmana: 0.0
maxvelocity: 20.0
Factory method:

Code: Select all

KMEntity* EntityFactory::CreateEnemy(const std::string& script, const std::string& type, const ggut::Vector2f& pos)
{
	//TODO: KMEnemy
	KMEntity* temp = new KMEntity();

	std::ifstream fin(script.c_str());
	YAML::Parser parser(fin);

	YAML::Node doc;
	parser.GetNextDocument(doc);

	try
	{
		for(std::size_t num = 0; num < doc.size(); ++num)
		{
			if(doc[num]["name"] == type)
			{
				temp->SetName(type);
				temp->SetMaxHealth(doc[num]["maxhealth"]);
				temp->SetHealth(doc[num]["maxhealth"]);
				temp->SetMaxMana(doc[num]["maxmana"]);
				temp->SetMana(doc[num]["maxmana"]);
				temp->SetModel(doc[num]["model"]);
				temp->SetPosition(pos);
				temp->SetScale(doc[num]["scale"]);
				temp->SetMaxVelocity(doc[num]["maxvelocity"]);
			}
		}
	}
	catch( ... )
	{
		std::cerr << "Failed to load Enemy from YAML file!" << std::endl;
	}

	return temp;
}
Use:

Code: Select all

myRat = myEntityFactory.CreateEnemy("entities/rats.yaml", "Small Rat", Vector2f(150, 150));
Just wanted to share this. I just discovered it one hour ago ;)
XianForce
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 767
Joined: Wed Oct 29, 2008 8:36 pm

Re: YAML > XML

Post by XianForce »

Wow... That looks pretty legit =D. I'll have to take a look at it =p.
User avatar
M_D_K
Chaos Rift Demigod
Chaos Rift Demigod
Posts: 1087
Joined: Tue Oct 28, 2008 10:33 am
Favorite Gaming Platforms: PC
Programming Language of Choice: C/++
Location: UK

Re: YAML > XML

Post by M_D_K »

That's pretty awesome, I'll be checking that out later.
Gyro Sheen wrote:you pour their inventory onto my life
IRC wrote: <sparda> The routine had a stack overflow, sorry.
<sparda> Apparently the stack was full of shit.
DaveB
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 24
Joined: Sat Nov 21, 2009 1:57 pm

Re: YAML > XML

Post by DaveB »

Yeah I think I will diffidently use this, looks really clean and easy to use
User avatar
thejahooli
Chaos Rift Junior
Chaos Rift Junior
Posts: 265
Joined: Fri Feb 20, 2009 7:45 pm
Location: London, England

Re: YAML > XML

Post by thejahooli »

Do you know any tutorials or documentation on using it as there seems to be little on it.
I'll make your software hardware.
User avatar
LeonBlade
Chaos Rift Demigod
Chaos Rift Demigod
Posts: 1314
Joined: Thu Jan 22, 2009 12:22 am
Current Project: Trying to make my first engine in C++ using OGL
Favorite Gaming Platforms: PS3
Programming Language of Choice: C++
Location: Blossvale, NY

Re: YAML > XML

Post by LeonBlade »

How would I use this for my maps ;)
There's no place like ~/
pritam
Chaos Rift Demigod
Chaos Rift Demigod
Posts: 991
Joined: Thu Nov 13, 2008 3:16 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Amiga, PSOne, NDS
Programming Language of Choice: C++
Location: Sweden

Re: YAML > XML

Post by pritam »

This looks very nice and clean, unlike how bloated XML can get.
mattheweston
Chaos Rift Junior
Chaos Rift Junior
Posts: 200
Joined: Mon Feb 22, 2010 12:32 am
Current Project: Breakout clone, Unnamed 2D RPG
Favorite Gaming Platforms: PC, XBOX360
Programming Language of Choice: C#
Location: San Antonio,Texas
Contact:

Re: YAML > XML

Post by mattheweston »

I took a week long course on Adobe Flex and they were saying this is what will eventually replace XML due to various reasons.
Image
K-Bal
ES Beta Backer
ES Beta Backer
Posts: 701
Joined: Sun Mar 15, 2009 3:21 pm
Location: Germany, Aachen
Contact:

Re: YAML > XML

Post by K-Bal »

mattheweston wrote:I took a week long course on Adobe Flex and they were saying this is what will eventually replace XML due to various reasons.
It will replace XML if we (the developers) use it and spread the word ;)
User avatar
thejahooli
Chaos Rift Junior
Chaos Rift Junior
Posts: 265
Joined: Fri Feb 20, 2009 7:45 pm
Location: London, England

Re: YAML > XML

Post by thejahooli »

Sorry for being a noob, but could you please explain the set-up as I am not very experienced with command prompt, which is how they explain it.
I'll make your software hardware.
User avatar
GroundUpEngine
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 835
Joined: Sun Nov 08, 2009 2:01 pm
Current Project: mixture
Favorite Gaming Platforms: PC
Programming Language of Choice: C++
Location: UK

Re: YAML > XML

Post by GroundUpEngine »

Same here.. I epic fail at working with & setting up new libraries, I tryed to implement it before but gave up straight away lol. But I really want to use yaml properly! :)
K-Bal
ES Beta Backer
ES Beta Backer
Posts: 701
Joined: Sun Mar 15, 2009 3:21 pm
Location: Germany, Aachen
Contact:

Re: YAML > XML

Post by K-Bal »

What exactly is your problem? What do you need the cmd prompt for?
User avatar
thejahooli
Chaos Rift Junior
Chaos Rift Junior
Posts: 265
Joined: Fri Feb 20, 2009 7:45 pm
Location: London, England

Re: YAML > XML

Post by thejahooli »

I realised after downloading it that it was just a usual library set-up. I was just a bit thrown off by the How To Build section of the website.
I'll make your software hardware.
User avatar
LeonBlade
Chaos Rift Demigod
Chaos Rift Demigod
Posts: 1314
Joined: Thu Jan 22, 2009 12:22 am
Current Project: Trying to make my first engine in C++ using OGL
Favorite Gaming Platforms: PS3
Programming Language of Choice: C++
Location: Blossvale, NY

Re: YAML > XML

Post by LeonBlade »

Hmm... I don't see how I could use this for a map structure, doesn't seem... efficient enough?
Should I just do tile by tile?
There's no place like ~/
Post Reply