You know the "Hashtable(Of Type)" class used by the VBContentManager?
There's actually a generic Dictionary class in the .NET framework that serves the same purpose.
The Dictionary class provides two type predicates, one for the key and one for the value, whereas my Hashtable class simply presumes the key to be of type String. We could do away with the Hashtable(Of Type) class all together, and simply start using Dictionaries.
The other thing I started messing with is the generic Stack class. My current ScreenManager class keeps track of Screen order via some rather sloppy and unnecessary list manipulation. But all of that can be done away with and replaced with a Stack(Of Screen).
Stacks are a very convenient way to maintain Screen order within a ScreenManager, because there is a natural synchronization between the inherent nature of Stacks and the way we display Screens.
At the beginning of the program, push Screen1 onto the Stack. When you transition away from that Screen1 to Screen47, pop the Stack (removing Screen1) and push Screen47 onto the Stack. If you want to display Screen2 over Screen47, simply push Screen2 onto the Stack. Now Screen2 is above Screen47, which is exactly what we wanted to display. When Screen2 is finished, pop it off the Stack, and Screen47 resumes the top position. It's a very convenient way to maintain the order of Screens, and I will employ this technique in the Screen tutorial.
3/7/08
Uninventing some wheels - Stacks & Dictionaries
by
emachine74
@
12:37 PM
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment