什么配置文件格式允许包含其他文件和继承设置?
我正在编写一个基于 C++ 的多人游戏。
我需要一种灵活的文件格式来存储有关游戏角色的信息。
游戏角色通常不会共享相同的属性,或者使用基本格式
例如:
一种允许我做这样的事情的格式:
#include "standardsettings.config"
//include other files which this file
//then changes
FastSpaceship:
Speed: 10 //pixels/sec
Rotation: 5 //deg/sec
MotherShip : FastSpaceship //inherits all the settings of the Spaceship ship
ShieldRecharge: 4
WeaponA [ power:10,
range:20,
style:fireball]
SlowMotherShip : MotherShip //inherits all the settings of the monther ship
Speed: 4 // override speed
我一直在寻找一种可以完成所有这些操作或类似的预先存在的格式,但没有运气。 除非必须,否则我不想重新发明轮子,所以我想知道是否有人知道支持这些功能的任何好的配置文件格式
I'm writing a Multiplayer C++ based game.
I need a flexible file format to store information about the game charactors.
The game charactors will often not share the same attributes, or use a basew
For example:
A format that would allow me to do something like this:
#include "standardsettings.config"
//include other files which this file
//then changes
FastSpaceship:
Speed: 10 //pixels/sec
Rotation: 5 //deg/sec
MotherShip : FastSpaceship //inherits all the settings of the Spaceship ship
ShieldRecharge: 4
WeaponA [ power:10,
range:20,
style:fireball]
SlowMotherShip : MotherShip //inherits all the settings of the monther ship
Speed: 4 // override speed
I've been searching for a pre-existing format that does all this, or is similar, but with no luck. I'm keen not to reinvent the wheel unless I have to, so i was wondering if anyone knows any good configuration file formats that support these features
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
经过大量搜索后,我找到了一个非常好的解决方案,使用 Lua
我发现 Lua 最初是设计为配置的文件语言,但后来演变成一种完整的编程语言。
示例
util.lua
globalsettings.lua
myspaceship.lua
使用 Lua 中的打印功能也可以轻松测试设置是否正确。 语法并不像我想要的那么好,但它非常接近我想要的,我不介意多写一点。
使用此处的代码 http://windrealm.com /tutorials/reading-a-lua-configuration-file-from-c.php 我可以将设置读入我的 C++ 程序
After alot of searching i've found a pretty good solution using Lua
Lua I found out was originally designed as a configuration file language, but then evolved into a complete programming language.
Example
util.lua
globalsettings.lua
myspaceship.lua
Using the print function in Lua its also easy to test the settings if they are correct. Syntax isn't quite as nice as I would like it, but its so close to what I want, i'm not gonna mind writing out a bit more.
The using the code here http://windrealm.com/tutorials/reading-a-lua-configuration-file-from-c.php I can read the settings into my C++ program
您可能想查看某种基于框架的表示,因为看起来这正是你说的是。 该维基百科页面链接到一些现有的实现,您可能可以使用这些实现,或者创建您自己的实现。
You might want to check out some sort of frame-based representation, since it seems that's exactly what you're talking about. That wikipedia page links to a few existing implementations that maybe you could use, or create your own.
YAML? 它就像没有逗号和引号的 JSON。
YAML? It's like JSON without the commas and quotes.
JSON 是最简单的文件格式,具有成熟的库,您可以解释它来执行您想要的任何操作。
JSON is about the simplest file format around, has mature libraries, and you can interpret it to do anything you want.