Search Home Members Contacts
About Us
Products
Downloads
Community
Support
Pages: [1]
  Print  
Author Topic: Threading Experience and Collision Problem  (Read 2315 times)
SalatalikTursusu
Community Member
*
Posts: 20


« on: October 09, 2004, 03:11:47 AM »

Hi all,

I have 1 problem and 1 question  ...

First off all while working on collision , i found that collision is not working on maps which are paging enabled ... is it a known problem or do i have to recode my collision function ?

My question is: do anyone have experience with threading in game programming ... i searched on google and gamedev but i couldnt find any usefull example ... I am using C#.Net and thinking on using Thread Pool which may help me to solve problems but first of all i wanted to learn others experiences on threading ...

Currently collision testing stages are slowing down my controls ... thats why i want to move my bullet, collision test and bullet control codes to threads ...

Thanks
Logged
sashelas
Community Member
*
Posts: 227


WWW
« Reply #1 on: October 09, 2004, 03:19:58 PM »

I'm using threading with a C# web server usercontrol I wrote to use with TV3D.  It is rudimentary but is the fourth web server I've done since 1995.

Suspending, monitoring, locking and the handling of deadlocks are kind of tricky, but creating and killing threads are fairly straightforward.

Here is an excerpt to show roughly how I'm using threading in C#. .

using System.Threading;
..
   public class WebServerControl : System.Windows.Forms.UserControl
   {
..
      private Thread th;
      public void StartServer(int iPortNumber, string sPath)
      {
         th = new Thread(new ThreadStart(Listen));
         th.Start();
         th.Name="Server";
..
      public void StopServer()
      {
            Thread.CurrentThread.Abort();
..
      private void Listen()
      {
..
               listenThreadCount++;
               Thread t = new Thread(new ThreadStart(HandleConnection));
               t.IsBackground=true;
               t.Priority=ThreadPriority.BelowNormal;
               t.Start();
               t.Name=listenThreadCount.ToString();
               if (shutdown==true) {t.Abort();}
..

For C# I'm using the following books which have good coverage of threading:
C# Programmers Cookbook - Microsoft
C# Cookbook - O'Reilly
C# Network Programming - Sybex
Programming C# - O'Reilly

I'm fairly new to threading in C# but so far it seems rock solid.  I'm thinking of adding threading to my client to handle requests.

There are alot of poor implementations of pooling out there, Weblogic apps mostly, that could have just taken the overhead hit of creating threads as needed rather than trying to pool.  When a pool gets locked up, often the vendors suggested restarting the service which is horrible in production.

I'd appreciate hearing about tips or tricks you learn in relation to game programming.  Thread pooling has a default max of 25 threads per CPU so it doesn't work well for large scale applications.  If you use it wrong you will see heavy contention.  A server I wrote in 1998, Shambala Server, handled threading and its work queue for threads poorly and as a result it was vulnerable to DoS attacks.  If you are planning on using threads for collisions, you might want to allocate a thread per type of object or a thread per player to keep the count low and avoid contention.
Logged
SalatalikTursusu
Community Member
*
Posts: 20


« Reply #2 on: October 10, 2004, 05:47:49 AM »

i implementended thread pooling (atleast i think so ...) and i see that thread pooling cant help me to solve my problems ... also it cant even process the simple game procedures ...

i tried to use threading but i couldn't implemented it as it has to be ... thats why i am still trying to figure out how to implement threading in my gameloop, user controls, bullet movements and such ...

i am thinking on defining my gameloop as a thread , user controls, bullet movements and collisions will be sub threads in that threaded gameloop ...

any suggestion ?

thanks
Logged
James
Community Member
*
Posts: 883


« Reply #3 on: October 10, 2004, 07:40:37 AM »

We use threading within our game to provide smoother responses and to provide background processing.

Recently we threaded all texture loading for our minimap. Before threading it would lag the game about 150->250ms (1/4 second!) to load in a set of new tiles for the minimap, with our thread we have no glitch at all Smiley

Only certain things can be put in threads, mainly AI, data loading and other processing. You cannot easily perform DirectX or TV3D functions as they are generally unsafe.

So your main thread should handle rendering, user input and conversion of thread data (ie. AI positions) to in-game data (aka. AI 3D mesh positions).

Threads are easy imho, but they are fantastic when u get it right Smiley
Logged

James
[www.DeepVoodooGaming.Com (Ireland)]
SalatalikTursusu
Community Member
*
Posts: 20


« Reply #4 on: October 10, 2004, 12:29:41 PM »

thank you james for your reply ...
i couldnt implemented it with both threading and thread pool ...

can you show me an example on rendering thread or game loop thread ?

thanks
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.3 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks