Server + Newton

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Re: Server + Newton

Postby KingSnail » Tue Nov 23, 2010 10:32 pm

I have 2.26 and I found the class dThread
but how do I use it?
Do you have a small example?
Working on an MMORPG powered by Newton Dynamics.
User avatar
KingSnail
 
Posts: 112
Joined: Sat Jan 02, 2010 9:55 pm

Re: Server + Newton

Postby Julio Jerez » Wed Nov 24, 2010 10:36 am

first you link the dScene library to your project, then you create a class like this

Code: Select all
class dSimulationThread: public dThread
{
   public:
   dSimulationThread();
   ~dSimulationThread();

   virtual unsigned RunMyTask ();
   bool m_asycronousUpdate;
   dFloat m_physicsTime;
};


then you place you newton update in function RunMyTask prototype like this:

Code: Select all
unsigned dSimulationThread::RunMyTask ()
{
   if (m_asycronousUpdate) {
      DemoEntityManager& me = *((DemoEntityManager*)this);
      me.UpdatePhysics();
   }
   return 1;
}


// in your world class call asycronous from the physic thread
void DemoEntityManager::UpdatePhysics()
{
   if (m_world) {
      dFloat timestepInSecunds = 1.0f / MAX_PHYSICS_FPS;
      unsigned64 timestepMicrosecunds = unsigned64 (timestepInSecunds * 1000000.0f);

      unsigned64 currentTime = m_timer.GetTimeInMicrosenconds ();
      unsigned64 nextTime = currentTime - m_microsecunds;
      int loops = 0;
      while ((nextTime >= timestepMicrosecunds) && (loops < MAX_PHYSICS_LOOPS)) {
         loops ++;

         // run the newton update function
         if (!m_reEntrantUpdate) {
            m_reEntrantUpdate = true;
            if (m_physicsUpdate && m_world) {
               NewtonUpdate (m_world, timestepInSecunds);
            }
            m_reEntrantUpdate = false;
         }

         nextTime -= timestepMicrosecunds;
         m_microsecunds += timestepMicrosecunds;
      }

      if (loops) {
         m_physicsTime = dFloat (m_timer.GetTimeInMicrosenconds () - currentTime) / 1000000.0f;
      }

      if (loops >= MAX_PHYSICS_LOOPS) {
         m_microsecunds = currentTime;
      }
   }
}



this examply is taken from the SDK demo, and it runs the p[hsyics in a sperate threa at a fix rate, with no lag and not time wated in CP when eh trea is idle.
basically if yo uhave a multicore system it will runteh phsicns is a full core giveing it a comple time step.
as oppose to upadtion form teh main thread when the physic will have only a teh time left by teh rest of the system.

the dTread will be you biggest bang fo rthe Buck at using the CPU resources.
No only for physics but also for other Game task like AI, or even your animation.

for example you can place your animation system in a separate subclass of dThread and run it at a fix step,
when the time expired you can just the update of what you have, and next time continue when you left.
since it is for multiplayer the client will see the frame with the provius animation key frame.
but they will be not network lag since the server will only do what is can and the rest will automatically be the same as it was in previus frame.

say you asign the Animation Thread 8 limisecunds, for animaion update.
you make a circla list with all you players,

when teh thread ger it turn it stat advacin teh animation startioon with playe one and whil te h8 millisesecudn have no expired, it contionus with the next player.
say in could update 10 player out of teh 35.

at the time is save the play counet indicator and teh tres idle fo eth rest of the timestep. (this is the reck to make is mo lag)
now you trasmit teh upadte frames to teh clients.

in the next animation tunr teh thread continue updating players bu this stime the anbace by twice the time step, scine those players lost one animation update.
as you continue doing that each time updating the animation by the number of frames the system takes to go a full over all player.
in the client side the interpolation should do the rest. It is Is like an autmatic animation LOD system.
basically the system will automatically adapt to the speed of the line, by decimation the animating.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Server + Newton

Postby Carli » Wed Jan 05, 2011 7:20 am

KingSnail wrote:The server sends snapshots every 100ms of all people in a certain area around a player
the client interpolates the positions.

[...]

I had this (from the demo) before and it was too laggy above 35 players


Did you measure your traffic ammount and your CPU load?
Maybe your bottleneck is elsewhere.
Carli
 
Posts: 245
Joined: Fri Oct 02, 2009 5:28 am

Re: Server + Newton

Postby PJani » Wed Jan 05, 2011 11:01 am

I didnt read whole thread, but what do you use? TCP, UDP? How big packets do you send, recive?

If you use TCP you will need to set TCP_NODELAY flag, because TCP uses Nagle algorithm, which waits until buffer is not full enought.
If you use UDP did you consider you are loosing packets, or meybe over throttling and over filling buffer?

Were clients run on one computer or meybe on 35 real machines?

Are clients running newton too, for smooting things near you?

100ms can be VERY laggy... try to send more often if you can. i would try to send more often for very close objects...
| i7-5930k@4.2Ghz, EVGA 980Ti FTW, 32GB RAM@3000 |
| Dell XPS 13 9370, i7-8550U, 16GB RAM |
| Ogre 1.7.4 | VC++ 9 | custom OgreNewt, Newton 300 |
| C/C++, C# |
User avatar
PJani
 
Posts: 448
Joined: Mon Feb 02, 2009 7:18 pm
Location: Slovenia

Re: Server + Newton

Postby JernejL » Thu Jan 06, 2011 3:50 am

100ms can work well, i know mods which can deal with smooth sync up to 200ms with heavy packet loss, with good interpolation and extrapolation algorythms this is not a big issue.
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1587
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: Server + Newton

Postby KingSnail » Fri Jan 07, 2011 6:12 pm

Hey, didnt post in here for a while,
I am using RakNet which handles all the small network details (Thank god :D)
I am using c++0x threads instead of newton ones because the newton ones were a bit of a pain to setup.
But now it works asynchonously (and also 8 newton threads) so thanks for suggestion there.

I am sending packets every 50ms for now
I am also implementing EPIC template code from guy in gamedev forums as interpolation/extrapolation code
which is getting decent results so far.
Working on an MMORPG powered by Newton Dynamics.
User avatar
KingSnail
 
Posts: 112
Joined: Sat Jan 02, 2010 9:55 pm

Previous

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 2 guests