Added my prediction codee

This commit is contained in:
Marco Cawthorne 2017-03-04 21:08:59 +01:00
parent 0cf6080b5e
commit ec41057c4e
14 changed files with 120 additions and 56 deletions

4
Source/Client/Defs.h Normal file → Executable file
View file

@ -81,6 +81,10 @@ vector vCameraPos;
vector vCameraAngle;
float fCameraTime;
vector vPlayerOrigin;
vector vPlayerOriginOld;
vector vPlayerVelocity;
void View_PlayAnimation( int iSequence );
// This actually belongs in Builtins.h since its an undocumented global

4
Source/Client/Draw.c Normal file → Executable file
View file

@ -154,8 +154,8 @@ void CSQC_UpdateView( float fWinWidth, float fWinHeight, float fGameFocus ) {
setproperty( VF_ORIGIN, vCameraPos) ;
setproperty( VF_ANGLES, vCameraAngle );
} else {
//setproperty( VF_ORIGIN, ePlayerEnt.origin + [ 0, 0, getstatf( STAT_VIEWHEIGHT ) ] );
//setproperty( VF_ANGLES, input_angles );
setproperty( VF_ORIGIN, vPlayerOrigin + [ 0, 0, getstatf( STAT_VIEWHEIGHT ) ] );
setproperty( VF_ANGLES, view_angles );
View_DrawViewModel();
}

34
Source/Client/Entities.c Normal file → Executable file
View file

@ -26,37 +26,37 @@ CSQC_Ent_Update
Called whenever an entity is sent manually via .SendFlags and so on
=================
*/
void CSQC_Ent_Update( float fIsNew ) {
void CSQC_Ent_Update( float flIsNew ) {
float fEntType = readbyte();
/*if( fEntType == ENT_PLAYER ) {
if ( self.entnum == player_localentnum ) {
ePlayerEnt = self;
}
if ( fIsNew == TRUE ) {
self.predraw = CSQC_PlayerUpdate;
//self.drawmask = MASK_ENGINE;
if( fEntType == ENT_PLAYER ) {
if ( flIsNew == TRUE ) {
self.classname = "player";
self.solid = SOLID_SLIDEBOX;
self.predraw = Player_PreDraw;
self.drawmask = MASK_ENGINE;
}
float fFlags = readbyte();
self.modelindex = readbyte();
self.origin_x = readcoord();
self.origin_y = readcoord();
self.origin_z = readcoord();
self.angles_x = readcoord();
self.angles_y = readcoord();
self.angles_z = readcoord();
self.modelindex = readbyte();
self.velocity_x = readshort();
self.velocity_y = readshort();
self.velocity_z = readshort();
self.flags = readfloat();
if ( fFlags & PLAYER_SENDFLAG_INGAME ) {
self.velocity_x = readcoord();
self.velocity_y = readcoord();
self.velocity_z = readcoord();
self.flags = readfloat();
if ( self.flags & FL_CROUCHING ) {
setsize( self, VEC_CHULL_MIN, VEC_CHULL_MAX );
} else {
setsize( self, VEC_HULL_MIN, VEC_HULL_MAX );
}
setorigin( self, self.origin );
} else */if ( fEntType == ENT_AMBIENTSOUND ) {
} else if ( fEntType == ENT_AMBIENTSOUND ) {
self.origin_x = readcoord();
self.origin_y = readcoord();
self.origin_z = readcoord();

View file

@ -26,11 +26,6 @@ Comparable to worldspawn in SSQC in that it's mostly used for precaches
=================
*/
void CSQC_Init(float apilevel, string enginename, float engineversion) {
//static float PlayerFrame( float fIsNew ) {
// self.basebone = 40;
// return TRUE;
//}
precache_model( HUD_NUMFILE );
precache_model( "sprites/muzzleflash1.spr" );
@ -66,11 +61,7 @@ void CSQC_Init(float apilevel, string enginename, float engineversion) {
for ( int i = 0; i < ( CS_WEAPON_COUNT - 1 ); i++ ) {
precache_model( sViewModels[ i ] );
}
//for( int i = 1; i < 9; i++ ) {
// deltalisten( sCSPlayers[ i ], PlayerFrame, 0);
//}
PARTICLE_SPARK = particleeffectnum( "part_spark" );
PARTICLE_PIECES_BLACK = particleeffectnum( "part_pieces_black" );
PARTICLE_SMOKE_GREY = particleeffectnum( "part_smoke_grey" );

70
Source/Client/Player.c Executable file
View file

@ -0,0 +1,70 @@
/*
OpenCS Project
Copyright (C) 2016, 2017 Marco "eukara" Hladik
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
float Player_PreDraw( void ) {
if ( self.entnum == player_localentnum ) {
self.movetype = MOVETYPE_WALK;
// Prepare rollback
vector vOldOrigin = self.origin;
vector vOldVelocity = self.velocity;
float fOldPMoveFlags = self.pmove_flags;
// Apply physics for every single input-frame that has not yet been
// acknowledged by the server (servercommandframe = last acknowledged frame)
for ( int i = servercommandframe + 1; i <= clientcommandframe; i++ ) {
getinputstate( i );
runstandardplayerphysics( self );
}
// Smooth stair stepping, this has to be done manually!
vPlayerOriginOld = vPlayerOrigin;
if ( ( self.flags & FL_ONGROUND ) && ( self.origin_z - vPlayerOriginOld_z > 0 ) ) {
vPlayerOriginOld_z += frametime * 150;
if ( vPlayerOriginOld_z > self.origin_z ) {
vPlayerOriginOld_z = self.origin_z;
}
if ( self.origin_z - vPlayerOriginOld_z > 18 ) {
vPlayerOriginOld_z = self.origin_z - 18;
}
vPlayerOrigin_z += vPlayerOriginOld_z - self.origin_z;
} else {
vPlayerOriginOld_z = self.origin_z;
}
vPlayerOrigin = [ self.origin_x, self.origin_y, vPlayerOriginOld_z ];
vPlayerVelocity = self.velocity;
addentity( self );
// Time to roll back
self.origin = vOldOrigin;
setorigin( self, self.origin );
self.velocity = vOldVelocity;
self.pmove_flags = fOldPMoveFlags;
self.movetype = MOVETYPE_NONE;
// Set renderflag for mirrors!
self.renderflags = RF_EXTERNALMODEL;
} else {
addentity( self );
}
return PREDRAW_NEXT;
}

2
Source/Client/View.c Normal file → Executable file
View file

@ -74,7 +74,7 @@ float View_CalcBob( void ) {
fCycle = MATH_PI + MATH_PI * ( fCycle - autocvar_cl_bobup )/( 1.0 - autocvar_cl_bobup );
}
vVelocity = pmove_vel; //ePlayerEnt.velocity;
vVelocity = vPlayerVelocity;
vVelocity_z = 0;
fBob = sqrt( vVelocity_x * vVelocity_x + vVelocity_y * vVelocity_y ) * autocvar_cl_bob;

View file

@ -45,6 +45,7 @@ Defs.h
../Server/AmbientSound.c
Player.c
View.c
VGUIObjects.c
VGUISpectator.c

5
Source/Globals.h Normal file → Executable file
View file

@ -18,6 +18,11 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#define VEC_HULL_MIN '-16 -16 -36'
#define VEC_HULL_MAX '16 16 36'
#define VEC_CHULL_MIN '-16 -16 -18'
#define VEC_CHULL_MAX '16 16 18'
#define PLAYER_SENDFLAG_UPDATE 1
#define PLAYER_SENDFLAG_INGAME 2

10
Source/Server/Client.c Normal file → Executable file
View file

@ -104,7 +104,7 @@ void PutClientInServer( void ) {
Spawn_MakeSpectator();
Spawn_ObserverCam();
//self.SendEntity = Player_SendEntity;
self.SendEntity = Player_SendEntity;
// Because we don't want to reset these when we die
Money_AddMoney( self, autocvar_mp_startmoney );
@ -133,14 +133,6 @@ void SV_RunClientCommand( void ) {
input_impulse = 0;
}
if ( self.team && self.health > 0 ) {
self.SendFlags |= PLAYER_SENDFLAG_INGAME;
} else {
self.SendFlags |= PLAYER_SENDFLAG_UPDATE;
}
Footsteps_Update();
runstandardplayerphysics( self );
}

8
Source/Server/Defs.h Normal file → Executable file
View file

@ -18,12 +18,9 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#define VEC_HULL_MIN '-16 -16 -36'
#define VEC_HULL_MAX '16 16 36'
#define VEC_PLAYER_VIEWPOS '0 0 20'
#define VEC_CHULL_MIN '-16 -16 -18'
#define VEC_CHULL_MAX '16 16 18'
#define VEC_PLAYER_VIEWPOS '0 0 20'
#define VEC_PLAYER_CVIEWPOS '0 0 12'
// Server cvars
@ -153,6 +150,7 @@ void Input_Handle( void );
void Animation_PlayerTop( float fFrame );
void Animation_PlayerTopTemp( float fFrame, float fTime );
void Footsteps_Update( void );
// WIP
string __fullspawndata;

25
Source/Server/Player.c Normal file → Executable file
View file

@ -18,25 +18,25 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*float Player_SendEntity( entity ePEnt, float fChanged ) {
float Player_SendEntity( entity ePEnt, float fChanged ) {
if ( self.health <= 0 && ePEnt != self ) {
return FALSE;
}
WriteByte( MSG_ENTITY, ENT_PLAYER );
WriteByte( MSG_ENTITY, fChanged );
WriteByte( MSG_ENTITY, self.modelindex );
WriteCoord( MSG_ENTITY, self.origin_x );
WriteCoord( MSG_ENTITY, self.origin_y );
WriteCoord( MSG_ENTITY, self.origin_z );
WriteCoord( MSG_ENTITY, self.angles_x );
WriteCoord( MSG_ENTITY, self.angles_y );
WriteCoord( MSG_ENTITY, self.angles_z );
WriteByte( MSG_ENTITY, self.modelindex );
if ( fChanged & PLAYER_SENDFLAG_INGAME ) {
WriteCoord( MSG_ENTITY, self.velocity_x );
WriteCoord( MSG_ENTITY, self.velocity_y );
WriteCoord( MSG_ENTITY, self.velocity_z );
WriteFloat( MSG_ENTITY, self.flags );
}
WriteShort( MSG_ENTITY, self.velocity_x );
WriteShort( MSG_ENTITY, self.velocity_y );
WriteShort( MSG_ENTITY, self.velocity_z );
WriteFloat( MSG_ENTITY, self.flags );
return TRUE;
}*/
}
string sPainSounds[5] = {
"player/pl_pain2.wav",
@ -297,6 +297,7 @@ Run after physics
*/
void PlayerPostThink( void ) {
Animation_PlayerUpdate();
Footsteps_Update();
if ( ( self.flags & FL_ONGROUND ) && ( self.health > 0 ) && ( self.fFallVelocity > 100 )) {
if ( self.fFallVelocity > 580 ) {
@ -306,4 +307,6 @@ void PlayerPostThink( void ) {
}
self.fFallVelocity = 0;
}
self.SendFlags = 1;
}

2
Source/Server/progs.src Normal file → Executable file
View file

@ -1,6 +1,6 @@
#pragma target fte
#pragma progs_dat "../../opencs/progs.dat"
#pragma progs_dat "../../freecs/progs.dat"
#includelist
../Builtins.h

Binary file not shown.

Binary file not shown.