Jump to content
  • Advertisement
Sign in to follow this  
  • entries
    45
  • comments
    48
  • views
    51922

Metadata, Reflection or Self-describing Data

Sign in to follow this  
hplus0603

281 views

I'm a big fan of self-describing data. Some people call it reflection, some people call it metadata -- the end result is the same. A program should be able to examine the data structures within itself, and make decisions based on that examination.

The object/component/property system I wrote a while back, turned out to only need a few additional functions to be fully self-describing.

Why is this interesting, you might ask? Well, I'm glad you asked! This lets me implement level saving (as used from a level editor) using reflection on the objects and properties in the world. Traverse the world/object/component/property hierarchy, and write out a Lua script that re-creates that world. Instant level format. Ta-da!

Yes, this trick has been used before, but I still like it. And you'd be surprised how many APIs in the 'real world' I've run across that aren't actually self-describing. Just remember: If you can get from "here" to "there," you really ought to be able to get back again!

So, what was the thing I had to add? Turned out, a property didn't know which container it belonged to. It really shouldn't, because properties are separate from containers, but containers are property collections, so I added an accessor to get the collection from the property. Then, I had to punch through the name of the container as a member on the property collection, and I'm done. (An alternative would be to implement query-interface, but I've stayed away from that for now.)

Just thought I'd share.
Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!