🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Progress Report

Published July 20, 2006
Advertisement
So word is in that the interviews last week are no-goes. One ran into bureaucratic malaise and they're not hiring anyone. The other was a poor fit (what the hell do I know about assembly lines?) and they've two other candidates likely better suited for the job.

On a slightly related note, I spent the past 12 hours banging my head against C# reflection. It might be one of ignorance or design block, but I couldn't get this scenario working:

In the game, most objects have properties which define game values. Changing a property triggers a series of events, starting with a local instance event, triggering 'containing' events up to a master event which triggers whenever an instance of that property changes state. It's common on the server side for all of those 'master' events to have a listener which relays the state change to clients that can see the object in question.

So, the plan was to use C# Attributes. Game visible properties would be tagged with an attribute which houses the network message ID, and the Fog of War level at which the property is visible (For example, a tile's resources suddenly vanish. An empire with a unit in the tile will see that change, an empire which only explored the tile ages ago would not). Reflection could then be used to auto-generate the network message sending and recieving stuff.

So looking up the attributes, easy. Finding the delegate fields representing the events, easy. Generating an object to do the message sending, easy. Identifying the types in the delegate, or setting anything to the delegate fields, or getting the generated object to convert into a delegate? 12 hours of misery.

The closest I got was setting the delegate to a dynamically generated Generic class with an implicit conversion operator. Unfortunately, the generated generic class wouldn't convert nicely (since it's technically a different type than the actual Generic class' operator expects?) despite the fact that I could explicitly assign the class to the Reflected field.

I think that recieving and other Fog stuff can be fully automated, but I've not tried it quite yet. For now I'm going to semi-manually enter the message listeners. The name and fog will still be drawn from Attributes, but I'll need to enter the actual registration for each new property.


For those curious, here's a snippet of what the attribute addition looks like in code:
        [GameProperty("UnitLocation", Knowledge.Level.Seen)]        public Tile Location {            get {                return (tile);            }            set {                if (tile != value) {                    Tile tmp = tile;                    tmp.Remove(this);                    tile = value;                    tile.Add(this);                    LocationChange(this, tmp, tile);                }            }        }


I also did a little bit of testing last night on the event structure and Fog discovery events, which work much better than their previous incarnations. And I ended up reading through a good portion of the C# specs hunting for generics tidbits that might explain why things weren't working. Now I just need to find job opportunities that aren't doing QA work on PoS GPS recievers in semi-trucks...
0 likes 2 comments

Comments

Telastyn
Hrm, that's interesting.

It's pretty much what I was doing, only the final SetValue on the change event was impossible as I couldn't generate the proper delegate (I imagine Com stuff has a fixed generic event?) or get a generated object to convert into the delegate type.

Anyways, thanks for the tip AP, I'll look into that.
July 21, 2006 09:57 AM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement