RandomSync Class Reference

#include <randomsync.h>

List of all members.

Public Member Functions

 RandomSync ()
void Init ()
bool GetBool ()
double GetDouble ()
double GetDouble (double max)
double GetDouble (double min, double max)
long GetLong (long min, long max)
Point2i GetPoint (const Rectanglei &rect)
Point2i GetPoint (const Point2i &pt)
void AddToTable (double nbr)

Private Member Functions

double GetRand ()
void GenerateTable ()

Private Attributes

std::list< double > rnd_table


Detailed Description

Definition at line 28 of file randomsync.h.


Constructor & Destructor Documentation

RandomSync::RandomSync (  ) 

Definition at line 34 of file randomsync.cpp.

00034                       {
00035 }


Member Function Documentation

void RandomSync::AddToTable ( double  nbr  ) 

Definition at line 58 of file randomsync.cpp.

00059 {
00060   rnd_table.push_back(nbr);
00061 }

Here is the caller graph for this function:

void RandomSync::GenerateTable (  )  [private]

Definition at line 50 of file randomsync.cpp.

00051 {
00052   //Add a random number to the table, send it over network if needed
00053   double nbr = rand();
00054   AddToTable(nbr);
00055   if(network.IsServer()) ActionHandler::GetInstance()->NewAction(new Action(Action::ACTION_SEND_RANDOM,nbr));
00056 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool RandomSync::GetBool (  ) 

Definition at line 79 of file randomsync.cpp.

00079                         {
00080   int moitie = RAND_MAX/2;
00081   return (GetRand() <= moitie);
00082 }

Here is the call graph for this function:

Here is the caller graph for this function:

double RandomSync::GetDouble ( double  min,
double  max 
)

Definition at line 91 of file randomsync.cpp.

00091                                                   {
00092         return min + GetDouble(max - min);
00093 }

Here is the call graph for this function:

double RandomSync::GetDouble ( double  max  ) 

Definition at line 95 of file randomsync.cpp.

00095                                       {
00096         return max * GetDouble();
00097 }

Here is the call graph for this function:

double RandomSync::GetDouble (  ) 

Get a random number between 0.0 and 1.0

Returns:
A number between 0.0 and 1.0

Definition at line 104 of file randomsync.cpp.

00104                             {
00105         return 1.0*GetRand()/(RAND_MAX + 1.0);
00106 }

Here is the call graph for this function:

Here is the caller graph for this function:

long RandomSync::GetLong ( long  min,
long  max 
)

Génère un nombre entier aléatoire compris dans [min;max]

Definition at line 87 of file randomsync.cpp.

00087                                           {
00088         return min + (long)GetDouble(max - min + 1);
00089 }

Here is the call graph for this function:

Here is the caller graph for this function:

Point2i RandomSync::GetPoint ( const Point2i pt  ) 

Definition at line 122 of file randomsync.cpp.

00122                                              {
00123         return Point2i( GetLong(0, pt.x - 1), GetLong(0, pt.y - 1) );
00124 }

Here is the call graph for this function:

Point2i RandomSync::GetPoint ( const Rectanglei rect  ) 

Return a random point in the given rectangle.

Parameters:
rect The rectangle in which the returned point will be.
Returns:
a random point.

Definition at line 114 of file randomsync.cpp.

00114                                                   {
00115         Point2i topPoint = rect.GetPosition();
00116         Point2i bottomPoint = rect.GetBottomRightPoint();
00117 
00118         return Point2i( GetLong(topPoint.x, bottomPoint.x),
00119                         GetLong(topPoint.y, bottomPoint.y) );
00120 }

Here is the call graph for this function:

Here is the caller graph for this function:

double RandomSync::GetRand (  )  [private]

Definition at line 63 of file randomsync.cpp.

00064 {
00065   if(network.IsServer() || network.IsLocal()) GenerateTable();
00066 
00067   // If the table is empty freeze until the server have sent something
00068   while(rnd_table.size() == 0)
00069   {
00070     SDL_Delay(100);
00071     ActionHandler::GetInstance()->ExecActions();
00072   }
00073 
00074   double nbr = rnd_table.front();
00075   rnd_table.pop_front();
00076   return nbr;
00077 }

Here is the call graph for this function:

Here is the caller graph for this function:

void RandomSync::Init (  ) 

Definition at line 37 of file randomsync.cpp.

00037                      {
00038   //If we are a client on the network, we don't generate any random number
00039   if(network.IsClient()) return;
00040 
00041   srand( time(NULL) );
00042 
00043   rnd_table.clear();
00044 
00045   //Fill the pregenerated tables:
00046   for(uint i=0; i < table_size; i++)
00047     GenerateTable();
00048 }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

std::list<double> RandomSync::rnd_table [private]

Definition at line 30 of file randomsync.h.


The documentation for this class was generated from the following files:
Generated on Mon Jan 1 14:13:14 2007 for Wormux by  doxygen 1.4.7