Originally Posted by
Apoc
The code was originally a Sequential, then I added some stuff that required it to be Explicit.
Understood.
And yes, the two Vector3 structs are awesome alternatives. But some people don't like having the extra dependency.
People are crazy and insist on re-inventing the wheel. Re-invent to understand, re-invent because you will do a better job. Re-invent just because? That's (mostly) crazy talk.
Also, me and the .NET Marshaler have a hate-hate relationship. I don't trust it to 'assume' things.
And that I can understand too. When it screws up, it screws up royally! The simple cases, such as three floats, is usually pretty safe though.
Browsing your code did cause me to go back and re-examine the assumptions about my own object enumeration though. We do it almost the same way.
The main difference is that I don't pulse my objects. I keep a TimeSpan and enumerate again if the last time the object list was enumerated is greater than the desired TimeSpan, in this case 30 millseconds.
My Enumerate went from about 50 lines to the code below. I was over-complicating my tests in the dictionary for valid objects. Making sure the object type was valid, the memory address had not changed, etc.
Code:
private void EnumerateVisibleObjects()
{
Dictionary<GameGUID, WowObject> newObjectCache = new Dictionary<GameGUID, WowObject>();
ObjectMemoryAddresses objectMemory = new ObjectMemoryAddresses(m_gameClient);
foreach (uint memoryAddress in objectMemory)
{
GameGUID clientGUID = GetGUID(memoryAddress);
Descriptor.WoWObjectType clientObjectType = GetType(memoryAddress);
WowObject obj = null;
try
{
obj = m_objectCache[clientGUID];
obj.BaseAddress = memoryAddress;
}
catch
{
obj = GetGameObject(memoryAddress);
}
if (obj != null)
{
newObjectCache.Add(clientGUID, obj);
}
}
m_objectCache = newObjectCache;
m_lastEnumerationTime = DateTime.Now;
}