XML与YAML和对于2D RPG的JSON [英] XML vs YAML vs JSON for a 2D RPG

查看:177
本文介绍了XML与YAML和对于2D RPG的JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法弄清楚是否对C ++ 2D RPG使用XML,YAML或JSON。



以下是我的想法:




  • 简单地保存不仅仅是播放器数据,而是环境数据,如对象(x,y)坐标;加载时间;日期;图形配置等。


  • 我需要一些灵活,易于使用, li>



这是最好的选择?我有JavaScript的JavaScript,但不是C ++的经验。



编辑


$老实说,如果一个文本文件似乎像这样的东西最简单和最有效的解决方案(特别是如果我可以写它到二进制),那么我都耳朵。



编辑2



也可以随意提供其他建议。



如果你不需要分层存储,那么平面表格文件比其他任何东西都容易处理。所有你需要做的是读取磁盘上的行,并在选项卡上拆分。



如果你正在查看更多的键/值对类型存储),则 INI文件可能是合理的。这种格式有很多的灵活性,虽然推理它可能不太方便,当你敲击它。



如果你需要分层,JSON可能会更简单。有很多种语言的JSON库,听起来你已经熟悉了。





sqlite 可能是另一个选项。在SQL中有龙,但是在sqlite周围有一个不错的C ++包装,它可以是可管理的。主要好处是ACID,在我看来。



YAML规格看起来有点长,所以我可以猜测它有更多的厨房水槽。只是略过libyaml文档,API看起来有点像我过去使用的SAX接口。我没有后天的知识,但我会保持开始使用它没有一个很好的理由。



XML吸引人处理,不选择



无论您选择哪一个,编写尽可能少的代码就可以管理它。你真的想写你的引擎将使用的类。然后担心序列化它们。如果你让你的序列化影响你的类设计,你可能会后悔。 :)


I can't figure out whether or not to use XML, YAML, or JSON for a C++ 2D RPG.

Here are my thoughts:

  • I need something which is simple to save not just player data, but environment data, such as object (x, y) coordinates; load times; dates; graphics configurations, etc.

  • I need something flexible, easy to use, and definitely light weight, but powerful to handle the above.

Which is the best choice? I have experience with JSON in JavaScript, but not C++. Are there any good references for parsing JSON in C++ if this is the route to go?

Edit

Honestly, if a text file seems like the simplest and most effective solution for something like this (especially if I can just write it to binary), then I'm all ears.

Edit 2

Feel free to provide other suggestions as well.

解决方案

I would use the simplest thing that satisfies your requirements.

If you don't need hierarchical storage, then flat tabular files are so much easier to deal with than anything else. All you have to do is read lines off disk and split on tab.

If you are looking at more of key/value pair type storage (as opposed to lists of things), then INI files can be reasonable. This format has a lot of flexibility, though reasoning about it can less approachable when you extort it.

If you need hierarchical, it's possible that JSON would be simpler. There are JSON libraries in wide range of languages, and it sounds like you already familiar.

What's the best C++ JSON parser?

sqlite may be another option. There be dragons in SQL, but with a nice C++ wrapper around sqlite, it can be manageable. The primary benefit would be ACID, in my opinion.

The YAML spec looks somewhat lengthy, so I can guess that it has more kitchen sinks. Just skimming the libyaml docs, the API looks somewhat like SAX interfaces that I've used in the past. I have no a posteriori knowledge of it, but I would be reticent to start using it without a good reason.

XML sucks to deal with, don't opt in to it.

Regardless of which one you choose, write as little code as you can managing it. You really want to write the classes your engine will use first. Then worry about serializing them. If you let your serialization influence your class design, you'll probably regret it. :)

这篇关于XML与YAML和对于2D RPG的JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆