Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

 

 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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...