OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4PlayerInfoConflicts.cpp File Reference
#include "C4Include.h"
#include "control/C4PlayerInfo.h"
#include "control/C4Teams.h"
#include "lib/StdColors.h"
#include "lib/C4Random.h"
Include dependency graph for C4PlayerInfoConflicts.cpp:

Go to the source code of this file.

Classes

class  C4PlayerInfoListAttributeConflictResolver
 

Functions

DWORD GenerateRandomPlayerColor (int32_t iTry)
 
bool IsColorConflict (DWORD dwClr1, DWORD dwClr2)
 

Variables

const int32_t C4MaxPlayerColorChangeTries = 100
 
const int32_t C4MaxPlayerNameChangeTries = 100
 

Function Documentation

DWORD GenerateRandomPlayerColor ( int32_t  iTry)

Definition at line 32 of file C4PlayerInfoConflicts.cpp.

References C4RGB, and UnsyncedRandom().

Referenced by C4Team::RecheckColor().

33 {
34  // generate a random one biased towards max channel luminance
35  // (for greater color difference and less gray-ish colors)
36  return C4RGB(std::min<int>(UnsyncedRandom(302), 256), std::min<int>(UnsyncedRandom(302), 256), std::min<int>(UnsyncedRandom(302), 256));
37 }
uint32_t UnsyncedRandom()
Definition: C4Random.cpp:58
#define C4RGB(r, g, b)
Definition: StdColors.h:26

Here is the call graph for this function:

Here is the caller graph for this function:

bool IsColorConflict ( DWORD  dwClr1,
DWORD  dwClr2 
)

Definition at line 39 of file C4PlayerInfoConflicts.cpp.

References RGB2rgb(), rgb2xyY(), and xy2upvp().

Referenced by C4Team::RecheckColor().

40 {
41  // NEW COLOR CONFLICT METHOD: u'v'-distance
42  int R1 = 0xff & (dwClr1 >> 16);
43  int G1 = 0xff & (dwClr1 >> 8);
44  int B1 = 0xff & (dwClr1 );
45  int R2 = 0xff & (dwClr2 >> 16);
46  int G2 = 0xff & (dwClr2 >> 8);
47  int B2 = 0xff & (dwClr2 );
48  double r1=0,g1=0,b1=0,r2=0,g2=0,b2=0,x1=0,y1=0,Y1=0,x2=0,y2=0,Y2=0,u1=0,v1=0,u2=0,v2=0;
49  RGB2rgb(R1, G1, B1, &r1, &g1, &b1);
50  RGB2rgb(R2, G2, B2, &r2, &g2, &b2);
51  rgb2xyY(r1, g1, b1, &x1, &y1, &Y1);
52  rgb2xyY(r2, g2, b2, &x2, &y2, &Y2);
53  xy2upvp(x1, y1, &u1, &v1);
54  xy2upvp(x2, y2, &u2, &v2);
55  double Y = (Y1+Y2)/2.0;
56  double clrdiff = sqrt((u2-u1)*(u2-u1) + (v2-v1)*(v2-v1)) * Y*Y * 150;
57  double lumdiff = (Abs<double>(Y2-Y1) / std::max<double>(Y*Y*5, 0.5)) / 0.10;
58  return clrdiff + lumdiff < 1.0;
59 }
bool xy2upvp(double x, double y, double *pu, double *pv)
Definition: StdColors.h:164
bool rgb2xyY(double r, double g, double b, double *px, double *py, double *pY)
Definition: StdColors.h:146
bool RGB2rgb(int R, int G, int B, double *pr, double *pg, double *pb, double gamma=2.2)
Definition: StdColors.h:173

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

const int32_t C4MaxPlayerColorChangeTries = 100

Definition at line 27 of file C4PlayerInfoConflicts.cpp.

const int32_t C4MaxPlayerNameChangeTries = 100

Definition at line 28 of file C4PlayerInfoConflicts.cpp.