So... After having some issues with player / zombie lag, which happened to be totally fixed, it happened due to players being downloading files from the same server - patcher, which is weird since I have this connection:
But whatever, I moved the patcher to a seperate server. I now have been looking at the WZ_GameServer source code and soon I found a major performance flaw. I expected the performance to be balanced between all the functions existent in the code, but I stumbled into something. Disabling some paths of the source apparently made the game use 0% of the CPU, or very close to that, with 5 people there testing. Even though it is not properly broken, I mean chat works, you can move, you can kill each other (bugged though).
I found out that the object updating method is draining all the CPU power, not sure if it is a flaw in the way it is coded or anything else but thought I could share this with you so we can fix it together.
Please post any advances in this, remember you probably wouldn't know of this and think it was all OK if I didn't inform you all so inform all the community aswell in return.
Function: BOOL GameObject::Update()
Image as a proof of what I'm saying:
So yea, if anyone's interested this is all Zombies' AI.
Of course there isn't that much to be fixed but small optimizations can still be done.
Commenting Zombie's updating function out freezes CPU usage at 0% unless between time to time when it reaches 10% for 3 seconds (not sure what is it).
The function (method) you need to look for is BOOL obj_Zombie::Update()
But whatever, I moved the patcher to a seperate server. I now have been looking at the WZ_GameServer source code and soon I found a major performance flaw. I expected the performance to be balanced between all the functions existent in the code, but I stumbled into something. Disabling some paths of the source apparently made the game use 0% of the CPU, or very close to that, with 5 people there testing. Even though it is not properly broken, I mean chat works, you can move, you can kill each other (bugged though).
I found out that the object updating method is draining all the CPU power, not sure if it is a flaw in the way it is coded or anything else but thought I could share this with you so we can fix it together.
Please post any advances in this, remember you probably wouldn't know of this and think it was all OK if I didn't inform you all so inform all the community aswell in return.
Function: BOOL GameObject::Update()
Code:
BOOL GameObject::Update()
{
// NOTE : IsSleeping perfomance is slow when scaled to 1000 objects,
// that's why we use perma sleep flag ( most of these objects always sleep )
if(
!( ObjFlags & OBJFLAG_ForceSleep )
&&
PhysicsObject
&&
(!PhysicsObject->IsSleeping() || FirstUpdate) )
{
if(FirstUpdate != 0)
--FirstUpdate;
// physics object is not sleeping, so let's update our position to match physics, and update transform
r3dVector physPos = PhysicsObject->GetPosition();
// sometimes physics returns QNAN position, not sure why
if( r3d_float_isFinite(physPos.x) && r3d_float_isFinite(physPos.y) && r3d_float_isFinite(physPos.z) )
{
if( ( vPos - physPos ).LengthSq() > 32 * FLT_EPSILON )
ShadowExDirty = true ;
vPos = physPos;
D3DXMATRIX mat = PhysicsObject->GetRotation();
mat.m[3][0] = 0.0f; mat.m[3][1] = 0.0f; mat.m[3][2] = 0.0f; mat.m[3][3] = 1.0f;
r3dVector rot;
MatrixGetYawPitchRoll ( mat, rot.x, rot.y, rot.z );
NormalizeYPR ( rot );
rot.x = R3D_RAD2DEG ( rot.x ); rot.y = R3D_RAD2DEG ( rot.y ); rot.z = R3D_RAD2DEG ( rot.z );
if(!vRot.AlmostEqual(rot, 0.01f)) // do not change rotation if it didn't change
{
vRot = rot;
ShadowExDirty = true ;
}
Velocity = PhysicsObject->GetVelocity();
UpdateTransform();
}
}
return TRUE;
}
Image as a proof of what I'm saying:
So yea, if anyone's interested this is all Zombies' AI.
Of course there isn't that much to be fixed but small optimizations can still be done.
Commenting Zombie's updating function out freezes CPU usage at 0% unless between time to time when it reaches 10% for 3 seconds (not sure what is it).
The function (method) you need to look for is BOOL obj_Zombie::Update()