I’ve been working on a number of things after Adlib. One area I took a look at was multiplayer gaming and Project Darkstar. I’ll save my comments about that project for another post but in the meantime I thought I would share a little library I wrote while exploring Darkstar. In a nutshell it is something like properties, for those of you who know C#, for Java. In fact, it’s a library which lets you define property objects in place of traditional getter/setter methods. In addition to saving you from writing tons of boilerplate code for accessors and mutators it also provides some nifty features which I’ll go into below. Anyway, I hope you’ll check it out, I’ve named the library “Props”.
How about a problem statement:
Writing getters and setters in Java is verbose and a waste of time.
And a solution:
Create an object which encapsulates the getter/setter
And for bonus points:
Keep things type-safe at compile time and throw in some extra goodies such as change tracking and runtime constraints
So why do you want something like Props? Well, I wrote the library because I wanted to create a delta-based protocol for a multiplayer Asteroids game. That means instead of sending the entire state of the game to the clients, the server would calculate what had changed since its last update and only send the changes. Nifty, but tracking those changes was going to be a total pain! To work around this I wrote the Props library which allows you to track an object’s state in a data-driven manner. Check out the ComplexExample included with the source to see how that might work.
Don’t you know, the Props’ library does more than reduce the amount of code you write and track changes. It actually allows you to do some cool things with Constraints. A constraint is a little bit of logic which acts as a gatekeeper between a new value and your property. Every time you try to set a property it has to pass all the assigned constraints.
Let’s say you’re working with a property such as rotation. Normally, a field such as this can only be between zero and two pi but there’s nothing about a float which ensures that’s the case. Using a constraint you sleep at night knowing that your rotation is always within pre-defined limits.
Now, I could go on to tell you about DataBindings and the exciting world of change tracking. Or I could spin a yarn about how awesome it is to have a data driven model. However I’ll spare you the ink. Go check out the Props library and tell me what you think!
Hello, my name is Alex Schearer. I grew up in New York and currently live in Seattle.
2 Comments
Tried taking a look at the source code, for some reason I get a weird error when trying to unzip the file.
but maybe it’s just vista..
Thanks Eddie, I will try it on Vista later tonight, it appears to work fine on Windows 7 though. If other people are seeing the problem please let me know so I can fix it.