어떤 구성 파일 형식이 다른 파일의 포함과 설정 상속을 허용합니까?

StackOverflow https://stackoverflow.com/questions/1228545

문제

멀티 플레이어 C ++ 기반 게임을 작성하고 있습니다.

게임 charactors에 대한 정보를 저장하려면 유연한 파일 형식이 필요합니다.

게임 charactors는 종종 동일한 속성을 공유하지 않거나 Basew를 사용합니다.

예를 들어:

다음과 같은 일을 할 수있는 형식 :

#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

나는이 모든 일을하거나 비슷하지만 운이없는 기존 형식을 찾고 있습니다. 나는 필요하지 않으면 바퀴를 재발 명하지 않기 때문에 이러한 기능을 지원하는 좋은 구성 파일 형식을 알고 있는지 궁금합니다.

도움이 되었습니까?

해결책 4

많은 검색 후에는 꽤 좋은 솔루션을 찾았습니다. 루아

LUA는 원래 구성 파일 언어로 설계되었지만 완전한 프로그래밍 언어로 발전했습니다.

예시

util.lua

-- helper function needed for inheritance
function inherit(t)            -- return a deep copy (incudes all subtables) of the table t
  local new = {}             -- create a new table
  local i, v = next(t, nil)  -- i is an index of t, v = t[i]
  while i do
    if type(v)=="table" then v=inherit(v) end -- deep copy
    new[i] = v
    i, v = next(t, i)        -- get next index
  end
  return new
end

Globalsettings.lua

require "util"
SpaceShip = {
    speed = 1,
    rotation =1
}

MySpaceship.lua

require "globalsettings"  -- include file

FastSpaceship = inherits(SpaceShip)
FastSpaceship.Speed = 10
FastSpaceship.Rotation = 5

MotherShip = inherits(FastSpaceship)
MotherShip.ShieldRecharge = 4
ShieldRecharge.WeaponA = {
        Power = 10,
        Range = 20,
        Style = "fireball"

SlowMotherShip = inherits(MotherShip)
SlowMotherShip.Speed = 4

LUA의 인쇄 기능을 사용하면 설정이 올바른 경우 쉽게 테스트 할 수 있습니다. 구문은 내가 원하는만큼 좋지는 않지만, 내가 원하는 것과 너무 가까워서 조금 더 글을 쓰지 않을 것입니다.

여기에 코드 사용 http://windrealm.com/tutorials/reading-a-lua-configuration-file-from-c.php C ++ 프로그램의 설정을 읽을 수 있습니다.

다른 팁

JSON은 가장 간단한 파일 형식에 관한 것이며, 성숙한 라이브러리가 있으며, 원하는 모든 것을 수행하도록 해석 할 수 있습니다.

{
    "FastSpaceship" : {
        "Speed" : 10,
        "Rotation" : 5 
    },
    "MotherShip" : {
        "Inherits" : "FastSpaceship",
        "ShieldRecharge" : 4,
        "WeaponA": {
            "Power": 10,
            "Range": 20,
            "style": "fireball"
        }
    },
    "SlowMotherShip": {
        "Inherits": "MotherShip",
        "Speed": 4 
    } 
}

? 쉼표와 따옴표가없는 JSON과 같습니다.

당신은 어떤 종류의 것을 확인하고 싶을 수도 있습니다 프레임 기반 표현은 정확히 당신이 말하는 것 같습니다. 해당 Wikipedia 페이지는 사용할 수있는 몇 가지 기존 구현으로 연결되거나 직접 만들 수 있습니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top