X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=sv_main.c;h=59da2be28ad1fa1485a1892741c9b30e1c965919;hb=f9605292b17719532eac0b3c7ccd6341b671d684;hp=4514e973742fc27af451e5f0ef2f99f3acb20694;hpb=9ba80c169d244d56e90f437c512f827953cc1208;p=xonotic%2Fdarkplaces.git diff --git a/sv_main.c b/sv_main.c index 4514e973..59da2be2 100644 --- a/sv_main.c +++ b/sv_main.c @@ -46,6 +46,7 @@ void SV_Init (void) extern cvar_t sv_accelerate; extern cvar_t sv_idealpitchscale; extern cvar_t sv_aim; + extern cvar_t sv_predict; Cvar_RegisterVariable (&sv_maxvelocity); Cvar_RegisterVariable (&sv_gravity); @@ -57,6 +58,7 @@ void SV_Init (void) Cvar_RegisterVariable (&sv_idealpitchscale); Cvar_RegisterVariable (&sv_aim); Cvar_RegisterVariable (&sv_nostep); + Cvar_RegisterVariable (&sv_predict); for (i=0 ; i MAX_DATAGRAM-16) return; MSG_WriteByte (&sv.datagram, svc_particle); - MSG_WriteCoord (&sv.datagram, org[0]); - MSG_WriteCoord (&sv.datagram, org[1]); - MSG_WriteCoord (&sv.datagram, org[2]); + MSG_WriteFloatCoord (&sv.datagram, org[0]); + MSG_WriteFloatCoord (&sv.datagram, org[1]); + MSG_WriteFloatCoord (&sv.datagram, org[2]); for (i=0 ; i<3 ; i++) { v = dir[i]*16; @@ -100,6 +102,41 @@ void SV_StartParticle (vec3_t org, vec3_t dir, int color, int count) MSG_WriteByte (&sv.datagram, color); } +/* +================== +SV_StartEffect + +Make sure the event gets sent to all clients +================== +*/ +void SV_StartEffect (vec3_t org, int modelindex, int startframe, int framecount, int framerate) +{ + if (sv.datagram.cursize > MAX_DATAGRAM-18) + return; + if (modelindex >= 256) + { + MSG_WriteByte (&sv.datagram, svc_effect2); + MSG_WriteFloatCoord (&sv.datagram, org[0]); + MSG_WriteFloatCoord (&sv.datagram, org[1]); + MSG_WriteFloatCoord (&sv.datagram, org[2]); + MSG_WriteShort (&sv.datagram, modelindex); + MSG_WriteByte (&sv.datagram, startframe); + MSG_WriteByte (&sv.datagram, framecount); + MSG_WriteByte (&sv.datagram, framerate); + } + else + { + MSG_WriteByte (&sv.datagram, svc_effect); + MSG_WriteFloatCoord (&sv.datagram, org[0]); + MSG_WriteFloatCoord (&sv.datagram, org[1]); + MSG_WriteFloatCoord (&sv.datagram, org[2]); + MSG_WriteByte (&sv.datagram, modelindex); + MSG_WriteByte (&sv.datagram, startframe); + MSG_WriteByte (&sv.datagram, framecount); + MSG_WriteByte (&sv.datagram, framerate); + } +} + /* ================== SV_StartSound @@ -108,7 +145,7 @@ Each entity can have eight independant sound sources, like voice, weapon, feet, etc. Channel 0 is an auto-allocate channel, the others override anything -allready running on that entity/channel pair. +already running on that entity/channel pair. An attenuation of 0 will play full volume everywhere in the level. Larger attenuations will drop off. (max 4 attenuation) @@ -157,17 +194,23 @@ void SV_StartSound (edict_t *entity, int channel, char *sample, int volume, if (attenuation != DEFAULT_SOUND_PACKET_ATTENUATION) field_mask |= SND_ATTENUATION; -// directed messages go only to the entity the are targeted on - MSG_WriteByte (&sv.datagram, svc_sound); +// directed messages go only to the entity they are targeted on + if (sound_num >= 256) + MSG_WriteByte (&sv.datagram, svc_sound2); + else + MSG_WriteByte (&sv.datagram, svc_sound); MSG_WriteByte (&sv.datagram, field_mask); if (field_mask & SND_VOLUME) MSG_WriteByte (&sv.datagram, volume); if (field_mask & SND_ATTENUATION) MSG_WriteByte (&sv.datagram, attenuation*64); MSG_WriteShort (&sv.datagram, channel); - MSG_WriteByte (&sv.datagram, sound_num); + if (sound_num >= 256) + MSG_WriteShort (&sv.datagram, sound_num); + else + MSG_WriteByte (&sv.datagram, sound_num); for (i=0 ; i<3 ; i++) - MSG_WriteCoord (&sv.datagram, entity->v.origin[i]+0.5*(entity->v.mins[i]+entity->v.maxs[i])); + MSG_WriteFloatCoord (&sv.datagram, entity->v.origin[i]+0.5*(entity->v.mins[i]+entity->v.maxs[i])); } /* @@ -192,11 +235,11 @@ void SV_SendServerinfo (client_t *client) char message[2048]; MSG_WriteByte (&client->message, svc_print); - sprintf (message, "%c\nDARKPLACES VERSION %4.2f SERVER (%i CRC)", 2, VERSION, pr_crc); + sprintf (message, "%c\nDARKPLACES VERSION %4.2f BUILD %i SERVER (%i CRC)", 2, VERSION, buildnumber, pr_crc); MSG_WriteString (&client->message,message); MSG_WriteByte (&client->message, svc_serverinfo); - MSG_WriteLong (&client->message, PROTOCOL_VERSION); + MSG_WriteLong (&client->message, DPPROTOCOL_VERSION); MSG_WriteByte (&client->message, svs.maxclients); if (!coop.value && deathmatch.value) @@ -278,7 +321,7 @@ void SV_ConnectClient (int clientnum) else { // call the progs to get default spawn parms for the new client - PR_ExecuteProgram (pr_global_struct->SetNewParms); + PR_ExecuteProgram (pr_global_struct->SetNewParms, "QC function SetNewParms is missing"); for (i=0 ; ispawn_parms[i] = (&pr_global_struct->parm1)[i]; } @@ -440,6 +483,8 @@ void SV_WriteEntitiesToClient (client_t *client, edict_t *clent, sizebuf_t *msg) MSG_WriteFloat(msg, org[2]); } */ + MSG_WriteByte(msg, svc_entitiesbegin); + MSG_WriteShort(msg, 1); clentnum = EDICT_TO_PROG(clent); // LordHavoc: for comparison purposes // send over all entities (except the client) that touch the pvs @@ -543,9 +588,9 @@ void SV_WriteEntitiesToClient (client_t *client, edict_t *clent, sizebuf_t *msg) // send an update bits = 0; - dodelta = FALSE; + dodelta = false; if ((int)ent->v.effects & EF_DELTA) - dodelta = cl.time < client->nextfullupdate[e]; // every half second a full update is forced + dodelta = realtime < client->nextfullupdate[e]; // every half second a full update is forced if (dodelta) { @@ -554,7 +599,7 @@ void SV_WriteEntitiesToClient (client_t *client, edict_t *clent, sizebuf_t *msg) } else { - client->nextfullupdate[e] = cl.time + 0.5; + client->nextfullupdate[e] = realtime + 0.5; baseline = &ent->baseline; } @@ -598,7 +643,7 @@ void SV_WriteEntitiesToClient (client_t *client, edict_t *clent, sizebuf_t *msg) angles[0] = angles[0] * movelerp + ent->stepoldangles[0]; angles[1] = angles[1] * movelerp + ent->stepoldangles[1]; angles[2] = angles[2] * movelerp + ent->stepoldangles[2]; - VectorMA(origin, host_client->ping, ent->v.velocity, origin); + VectorMA(origin, host_client->latency, ent->v.velocity, origin); } else // copy as they are { @@ -617,17 +662,20 @@ void SV_WriteEntitiesToClient (client_t *client, edict_t *clent, sizebuf_t *msg) } // LordHavoc: old stuff, but rewritten to have more exact tolerances - if ((int)(origin[0]*8.0) != (int)(baseline->origin[0]*8.0)) bits |= U_ORIGIN1; - if ((int)(origin[1]*8.0) != (int)(baseline->origin[1]*8.0)) bits |= U_ORIGIN2; - if ((int)(origin[2]*8.0) != (int)(baseline->origin[2]*8.0)) bits |= U_ORIGIN3; +// if ((int)(origin[0]*8.0) != (int)(baseline->origin[0]*8.0)) bits |= U_ORIGIN1; +// if ((int)(origin[1]*8.0) != (int)(baseline->origin[1]*8.0)) bits |= U_ORIGIN2; +// if ((int)(origin[2]*8.0) != (int)(baseline->origin[2]*8.0)) bits |= U_ORIGIN3; + if (origin[0] != baseline->origin[0]) bits |= U_ORIGIN1; + if (origin[1] != baseline->origin[1]) bits |= U_ORIGIN2; + if (origin[2] != baseline->origin[2]) bits |= U_ORIGIN3; if ((int)(angles[0]*(256.0/360.0)) != (int)(baseline->angles[0]*(256.0/360.0))) bits |= U_ANGLE1; if ((int)(angles[1]*(256.0/360.0)) != (int)(baseline->angles[1]*(256.0/360.0))) bits |= U_ANGLE2; if ((int)(angles[2]*(256.0/360.0)) != (int)(baseline->angles[2]*(256.0/360.0))) bits |= U_ANGLE3; - if (baseline->colormap != (int) ent->v.colormap) bits |= U_COLORMAP; - if (baseline->skin != (int) ent->v.skin) bits |= U_SKIN; + if (baseline->colormap != (byte) ent->v.colormap) bits |= U_COLORMAP; + if (baseline->skin != (byte) ent->v.skin) bits |= U_SKIN; if ((baseline->frame & 0x00FF) != ((int) ent->v.frame & 0x00FF)) bits |= U_FRAME; if ((baseline->effects & 0x00FF) != ((int) ent->v.effects & 0x00FF)) bits |= U_EFFECTS; - if (baseline->modelindex != (int) ent->v.modelindex) bits |= U_MODEL; + if (baseline->modelindex != (byte) ent->v.modelindex) bits |= U_MODEL; // LordHavoc: new stuff if (baseline->alpha != alpha) bits |= U_ALPHA; @@ -637,6 +685,7 @@ void SV_WriteEntitiesToClient (client_t *client, edict_t *clent, sizebuf_t *msg) if (baseline->glowcolor != glowcolor) bits |= U_GLOWCOLOR; if (baseline->colormod != colormod) bits |= U_COLORMOD; if (((int) baseline->frame & 0xFF00) != ((int) ent->v.frame & 0xFF00)) bits |= U_FRAME2; + if (((int) baseline->frame & 0xFF00) != ((int) ent->v.modelindex & 0xFF00)) bits |= U_MODEL2; // update delta baseline VectorCopy(ent->v.origin, ent->deltabaseline.origin); @@ -680,11 +729,11 @@ void SV_WriteEntitiesToClient (client_t *client, edict_t *clent, sizebuf_t *msg) if (bits & U_COLORMAP) MSG_WriteByte (msg, ent->v.colormap); if (bits & U_SKIN) MSG_WriteByte (msg, ent->v.skin); if (bits & U_EFFECTS) MSG_WriteByte (msg, ent->v.effects); - if (bits & U_ORIGIN1) MSG_WriteCoord (msg, origin[0]); + if (bits & U_ORIGIN1) MSG_WriteFloatCoord (msg, origin[0]); if (bits & U_ANGLE1) MSG_WriteAngle(msg, angles[0]); - if (bits & U_ORIGIN2) MSG_WriteCoord (msg, origin[1]); + if (bits & U_ORIGIN2) MSG_WriteFloatCoord (msg, origin[1]); if (bits & U_ANGLE2) MSG_WriteAngle(msg, angles[1]); - if (bits & U_ORIGIN3) MSG_WriteCoord (msg, origin[2]); + if (bits & U_ORIGIN3) MSG_WriteFloatCoord (msg, origin[2]); if (bits & U_ANGLE3) MSG_WriteAngle(msg, angles[2]); // LordHavoc: new stuff @@ -695,7 +744,11 @@ void SV_WriteEntitiesToClient (client_t *client, edict_t *clent, sizebuf_t *msg) if (bits & U_GLOWCOLOR) MSG_WriteByte(msg, glowcolor); if (bits & U_COLORMOD) MSG_WriteByte(msg, colormod); if (bits & U_FRAME2) MSG_WriteByte(msg, (int)ent->v.frame >> 8); + if (bits & U_MODEL2) MSG_WriteByte(msg, (int)ent->v.modelindex >> 8); } + + MSG_WriteByte(msg, svc_entitiesend); + MSG_WriteShort(msg, MAX_EDICTS); } /* @@ -730,6 +783,7 @@ void SV_WriteClientdataToMessage (edict_t *ent, sizebuf_t *msg) edict_t *other; int items; eval_t *val; + vec3_t punchvector; // // send a damage message @@ -741,7 +795,7 @@ void SV_WriteClientdataToMessage (edict_t *ent, sizebuf_t *msg) MSG_WriteByte (msg, ent->v.dmg_save); MSG_WriteByte (msg, ent->v.dmg_take); for (i=0 ; i<3 ; i++) - MSG_WriteCoord (msg, other->v.origin[i] + 0.5*(other->v.mins[i] + other->v.maxs[i])); + MSG_WriteFloatCoord (msg, other->v.origin[i] + 0.5*(other->v.mins[i] + other->v.maxs[i])); ent->v.dmg_take = 0; ent->v.dmg_save = 0; @@ -786,10 +840,17 @@ void SV_WriteClientdataToMessage (edict_t *ent, sizebuf_t *msg) if ( ent->v.waterlevel >= 2) bits |= SU_INWATER; + // dpprotocol + VectorClear(punchvector); + if ((val = GETEDICTFIELDVALUE(ent, eval_punchvector))) + VectorCopy(val->vector, punchvector); + for (i=0 ; i<3 ; i++) { if (ent->v.punchangle[i]) bits |= (SU_PUNCH1<v.velocity[i]) bits |= (SU_VELOCITY1<v.weapon) bits |= SU_WEAPON; + if (bits >= 65536) + bits |= SU_EXTEND1; + if (bits >= 16777216) + bits |= SU_EXTEND2; + // send the data MSG_WriteByte (msg, svc_clientdata); MSG_WriteShort (msg, bits); + if (bits & SU_EXTEND1) + MSG_WriteByte(msg, bits >> 16); + if (bits & SU_EXTEND2) + MSG_WriteByte(msg, bits >> 24); if (bits & SU_VIEWHEIGHT) MSG_WriteChar (msg, ent->v.view_ofs[2]); @@ -817,7 +887,9 @@ void SV_WriteClientdataToMessage (edict_t *ent, sizebuf_t *msg) for (i=0 ; i<3 ; i++) { if (bits & (SU_PUNCH1<v.punchangle[i]); + MSG_WritePreciseAngle(msg, ent->v.punchangle[i]); // dpprotocol + if (bits & (SU_PUNCHVEC1<v.velocity[i]/16); } @@ -1015,8 +1087,7 @@ void SV_SendClientMessages (void) SV_DropClient (false); // went to another level else { - if (NET_SendMessage (host_client->netconnection - , &host_client->message) == -1) + if (NET_SendMessage (host_client->netconnection, &host_client->message) == -1) SV_DropClient (true); // if the message couldn't send, kick off SZ_Clear (&host_client->message); host_client->last_message = realtime; @@ -1117,7 +1188,7 @@ void SV_CreateBaseline (void) MSG_WriteByte (&sv.signon, svent->baseline.skin); for (i=0 ; i<3 ; i++) { - MSG_WriteCoord(&sv.signon, svent->baseline.origin[i]); + MSG_WriteFloatCoord(&sv.signon, svent->baseline.origin[i]); MSG_WriteAngle(&sv.signon, svent->baseline.angles[i]); } } @@ -1170,7 +1241,7 @@ void SV_SaveSpawnparms (void) // call the progs to get default spawn parms for the new client pr_global_struct->self = EDICT_TO_PROG(host_client->edict); - PR_ExecuteProgram (pr_global_struct->SetChangeParms); + PR_ExecuteProgram (pr_global_struct->SetChangeParms, "QC function SetChangeParms is missing"); for (j=0 ; jspawn_parms[j] = (&pr_global_struct->parm1)[j]; } @@ -1323,7 +1394,7 @@ void SV_SpawnServer (char *server) sv.state = ss_active; // run two frames to allow everything to settle - host_frametime = 0.1; + sv.frametime = pr_global_struct->frametime = host_frametime = 0.1; SV_Physics (); SV_Physics ();