Napivo1972
Regular
- Joined
- Aug 31, 2004
- Messages
- 85
I screwed up majorly when writing my program.... never envisioned I would need threading while updating...
But having like 2000 objects needing Updating, collision detection and AI, no computer can handle this on a single thread.
In essence my program implements a GameObject that is iUpdatable, iDrawable and contains an iSprite.
iUpdateble only contains one function
Update();
iDrawable only contains one function
iSpriteInfo[] GetSprites() //I just do this as I have other classes derived from iDrawable Like CompositeSprite and Spriteanimation
and then we have iSpriteInfo
As you can imagine I don't have time for lock conditions while updating and as these objects are accessed by 3 threads (in fact there are hundred or so for hitttesting alone) I have decided to implement BaseReadWriteLock as most data is only changed during updating.
I say most as there is one expensive calculation I don't do during updating. that is Calculating the bounding box and Matrix, Those are calculated on a as needed basis.
And then I run into a major problem. Most of the time it is clear when I need a read lock or when I need a write lock but when I need to go and update my bounding rectangle (which is only done the first time I need it when certain parameters have changed) every thing goes wrong. The RecalcBounding rectangle gets called by every thread blocking my entire application and taking like forever to unblock.
Am I just too stupid?
Anyone have a book recommendation about in-dept threading?
I am really stuck as this is only the beginning I need at least 10 000 objects to update, hit test and AI every 60th of a second
Any help appreciated
Napivo
But having like 2000 objects needing Updating, collision detection and AI, no computer can handle this on a single thread.
In essence my program implements a GameObject that is iUpdatable, iDrawable and contains an iSprite.
iUpdateble only contains one function
Update();
iDrawable only contains one function
iSpriteInfo[] GetSprites() //I just do this as I have other classes derived from iDrawable Like CompositeSprite and Spriteanimation
and then we have iSpriteInfo
Code:
public interface iSpriteInfo
{
float X { get; set; }
float Y { get; set; }
float Angle { get; set; }
Vector2 Origin { get; set; }
float Scale { get; set; }
float Depth { get; set; }
Color Color { get; set; }
Boolean Visible { get; set; }
Rectangle SourceRectangle { get; set; }
Rectangle DestinationRectangle { get; set; }
Rectangle BoundingRectangle { get; }
Matrix Matrix { get; }
SpriteSheet SpriteSheet { get; set; }
int SpriteSheetNum { get;}
Color[] TextureData { get; set; }
Vector2 GetVector2 { get; }
Vector3 GetVector3 { get; }
}
As you can imagine I don't have time for lock conditions while updating and as these objects are accessed by 3 threads (in fact there are hundred or so for hitttesting alone) I have decided to implement BaseReadWriteLock as most data is only changed during updating.
I say most as there is one expensive calculation I don't do during updating. that is Calculating the bounding box and Matrix, Those are calculated on a as needed basis.
And then I run into a major problem. Most of the time it is clear when I need a read lock or when I need a write lock but when I need to go and update my bounding rectangle (which is only done the first time I need it when certain parameters have changed) every thing goes wrong. The RecalcBounding rectangle gets called by every thread blocking my entire application and taking like forever to unblock.
Am I just too stupid?
Anyone have a book recommendation about in-dept threading?
I am really stuck as this is only the beginning I need at least 10 000 objects to update, hit test and AI every 60th of a second
Any help appreciated
Napivo