X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=cl_main.c;h=9a651dbb0859387ab22a84b6dfe9e66f3f8dc0d4;hb=d3e2f7e92ec8883147b70a7bc0971a7b4561d3d5;hp=32c7d61a87df8ebae69b4de4eaa8bb29566946da;hpb=cbb6c7c5b3dadfa4bf3bf06285722a69e4f93f51;p=xonotic%2Fdarkplaces.git diff --git a/cl_main.c b/cl_main.c index 32c7d61a..9a651dbb 100644 --- a/cl_main.c +++ b/cl_main.c @@ -66,6 +66,8 @@ cvar_t cl_beams_lightatend = {CVAR_SAVE, "cl_beams_lightatend", "0","make a ligh cvar_t cl_noplayershadow = {CVAR_SAVE, "cl_noplayershadow", "0","hide player shadow"}; +cvar_t qport = {0, "qport", "0", "identification key for playing on qw servers (allows you to maintain a connection to a quakeworld server even if your port changes)"}; + cvar_t cl_prydoncursor = {0, "cl_prydoncursor", "0", "enables a mouse pointer which is able to click on entities in the world, useful for point and click mods, see PRYDON_CLIENTCURSOR extension in dpextensions.qc"}; cvar_t cl_deathnoviewmodel = {0, "cl_deathnoviewmodel", "1", "hides gun model when dead"}; @@ -90,6 +92,8 @@ int cl_max_dlights; int cl_max_lightstyle; int cl_max_brushmodel_entities; int cl_activedlights; +int cl_activeeffects; +int cl_activebeams; entity_t *cl_entities; entity_t *cl_csqcentities; //[515]: csqc @@ -122,6 +126,7 @@ CL_ClearState void CL_ClearState(void) { int i; + entity_t *ent; if (cl_entities) Mem_Free(cl_entities);cl_entities = NULL; if (cl_csqcentities) Mem_Free(cl_csqcentities);cl_csqcentities = NULL; //[515]: csqc @@ -136,6 +141,7 @@ void CL_ClearState(void) if (cl_brushmodel_entities) Mem_Free(cl_brushmodel_entities);cl_brushmodel_entities = NULL; if (cl.entitydatabase) EntityFrame_FreeDatabase(cl.entitydatabase);cl.entitydatabase = NULL; if (cl.entitydatabase4) EntityFrame4_FreeDatabase(cl.entitydatabase4);cl.entitydatabase4 = NULL; + if (cl.entitydatabaseqw) EntityFrameQW_FreeDatabase(cl.entitydatabaseqw);cl.entitydatabaseqw = NULL; if (cl.scores) Mem_Free(cl.scores);cl.scores = NULL; if (!sv.active) @@ -143,6 +149,9 @@ void CL_ClearState(void) // wipe the entire cl structure memset (&cl, 0, sizeof(cl)); + + S_StopAllSounds(); + // reset the view zoom interpolation cl.mviewzoom[0] = cl.mviewzoom[1] = 1; @@ -163,6 +172,8 @@ void CL_ClearState(void) cl_max_lightstyle = MAX_LIGHTSTYLES; cl_max_brushmodel_entities = MAX_EDICTS; cl_activedlights = 0; + cl_activeeffects = 0; + cl_activebeams = 0; cl_entities = (entity_t *)Mem_Alloc(cl_mempool, cl_max_entities * sizeof(entity_t)); cl_csqcentities = (entity_t *)Mem_Alloc(cl_mempool, cl_max_csqcentities * sizeof(entity_t)); //[515]: csqc @@ -211,6 +222,27 @@ void CL_ClearState(void) VectorSet(cl_playercrouchmaxs, 16, 16, 24); } + // disable until we get textures for it + R_ResetSkyBox(); + + ent = &cl_entities[0]; + // entire entity array was cleared, so just fill in a few fields + ent->state_current.active = true; + ent->render.model = cl.worldmodel = NULL; // no world model yet + ent->render.scale = 1; // some of the renderer still relies on scale + ent->render.alpha = 1; + ent->render.colormap = -1; // no special coloring + ent->render.flags = RENDER_SHADOW | RENDER_LIGHT; + Matrix4x4_CreateFromQuakeEntity(&ent->render.matrix, 0, 0, 0, 0, 0, 0, 1); + Matrix4x4_Invert_Simple(&ent->render.inversematrix, &ent->render.matrix); + CL_BoundingBoxForEntity(&ent->render); + + // noclip is turned off at start + noclip_anglehack = false; + + // mark all frames invalid for delta + memset(cl.qw_deltasequence, -1, sizeof(cl.qw_deltasequence)); + CL_Screen_NewMap(); CL_Particles_Clear(); CL_CGVM_Clear(); @@ -305,16 +337,25 @@ void CL_Disconnect(void) if (cls.demorecording) CL_Stop_f(); - // send clc_disconnect 3 times to improve chances of server receiving - // it (but it still fails sometimes) - Con_DPrint("Sending clc_disconnect\n"); + // send disconnect message 3 times to improve chances of server + // receiving it (but it still fails sometimes) memset(&buf, 0, sizeof(buf)); buf.data = bufdata; buf.maxsize = sizeof(bufdata); - MSG_WriteByte(&buf, clc_disconnect); - NetConn_SendUnreliableMessage(cls.netcon, &buf); - NetConn_SendUnreliableMessage(cls.netcon, &buf); - NetConn_SendUnreliableMessage(cls.netcon, &buf); + if (cls.protocol == PROTOCOL_QUAKEWORLD) + { + Con_DPrint("Sending drop command\n"); + MSG_WriteByte(&buf, qw_clc_stringcmd); + MSG_WriteString(&buf, "drop"); + } + else + { + Con_DPrint("Sending clc_disconnect\n"); + MSG_WriteByte(&buf, clc_disconnect); + } + NetConn_SendUnreliableMessage(cls.netcon, &buf, cls.protocol); + NetConn_SendUnreliableMessage(cls.netcon, &buf, cls.protocol); + NetConn_SendUnreliableMessage(cls.netcon, &buf, cls.protocol); NetConn_Close(cls.netcon); cls.netcon = NULL; } @@ -353,6 +394,9 @@ void CL_EstablishConnection(const char *host) // stop demo loop in case this fails CL_Disconnect(); + // make sure the client ports are open before attempting to connect + NetConn_UpdateSockets(); + // run a network frame //NetConn_ClientFrame();SV_VM_Begin();NetConn_ServerFrame();SV_VM_End(); @@ -536,6 +580,7 @@ void CL_Effect(vec3_t org, int modelindex, int startframe, int framecount, float e->frame = 0; e->frame1time = cl.time; e->frame2time = cl.time; + cl_activeeffects = max(cl_activeeffects, i + 1); break; } } @@ -669,6 +714,61 @@ void CL_UpdateLights(void) } } +void CL_AddQWCTFFlagModel(entity_t *player, int skin) +{ + float f; + entity_t *flag; + matrix4x4_t flagmatrix; + + // this code taken from QuakeWorld + f = 14; + if (player->render.frame2 >= 29 && player->render.frame2 <= 40) + { + if (player->render.frame2 >= 29 && player->render.frame2 <= 34) + { //axpain + if (player->render.frame2 == 29) f = f + 2; + else if (player->render.frame2 == 30) f = f + 8; + else if (player->render.frame2 == 31) f = f + 12; + else if (player->render.frame2 == 32) f = f + 11; + else if (player->render.frame2 == 33) f = f + 10; + else if (player->render.frame2 == 34) f = f + 4; + } + else if (player->render.frame2 >= 35 && player->render.frame2 <= 40) + { // pain + if (player->render.frame2 == 35) f = f + 2; + else if (player->render.frame2 == 36) f = f + 10; + else if (player->render.frame2 == 37) f = f + 10; + else if (player->render.frame2 == 38) f = f + 8; + else if (player->render.frame2 == 39) f = f + 4; + else if (player->render.frame2 == 40) f = f + 2; + } + } + else if (player->render.frame2 >= 103 && player->render.frame2 <= 118) + { + if (player->render.frame2 >= 103 && player->render.frame2 <= 104) f = f + 6; //nailattack + else if (player->render.frame2 >= 105 && player->render.frame2 <= 106) f = f + 6; //light + else if (player->render.frame2 >= 107 && player->render.frame2 <= 112) f = f + 7; //rocketattack + else if (player->render.frame2 >= 112 && player->render.frame2 <= 118) f = f + 7; //shotattack + } + // end of code taken from QuakeWorld + + flag = CL_NewTempEntity(); + if (!flag) + return; + + flag->render.model = cl.model_precache[cl.qw_modelindex_flag]; + flag->render.skinnum = skin; + flag->render.colormap = -1; // no special coloring + flag->render.alpha = 1; + VectorSet(flag->render.colormod, 1, 1, 1); + // attach the flag to the player matrix + Matrix4x4_CreateFromQuakeEntity(&flagmatrix, -f, -22, 0, 0, 0, -45, 1); + Matrix4x4_Concat(&flag->render.matrix, &player->render.matrix, &flagmatrix); + Matrix4x4_Invert_Simple(&flag->render.inversematrix, &flag->render.matrix); + R_LerpAnimation(&flag->render); + CL_BoundingBoxForEntity(&flag->render); +} + #define MAXVIEWMODELS 32 entity_t *viewmodels[MAXVIEWMODELS]; int numviewmodels; @@ -714,14 +814,14 @@ void CL_LinkNetworkEntity(entity_t *e) e->render.colormap = e->state_current.colormap; cb = (e->render.colormap & 0xF) << 4;cb += (cb >= 128 && cb < 224) ? 4 : 12; cbcolor = (unsigned char *) (&palette_complete[cb]); - e->render.colormap_pantscolor[0] = cbcolor[0] * (1.0f / 255.0f) * e->render.colormod[0]; - e->render.colormap_pantscolor[1] = cbcolor[1] * (1.0f / 255.0f) * e->render.colormod[1]; - e->render.colormap_pantscolor[2] = cbcolor[2] * (1.0f / 255.0f) * e->render.colormod[2]; + e->render.colormap_pantscolor[0] = cbcolor[0] * (1.0f / 255.0f); + e->render.colormap_pantscolor[1] = cbcolor[1] * (1.0f / 255.0f); + e->render.colormap_pantscolor[2] = cbcolor[2] * (1.0f / 255.0f); cb = (e->render.colormap & 0xF0);cb += (cb >= 128 && cb < 224) ? 4 : 12; cbcolor = (unsigned char *) (&palette_complete[cb]); - e->render.colormap_shirtcolor[0] = cbcolor[0] * (1.0f / 255.0f) * e->render.colormod[0]; - e->render.colormap_shirtcolor[1] = cbcolor[1] * (1.0f / 255.0f) * e->render.colormod[1]; - e->render.colormap_shirtcolor[2] = cbcolor[2] * (1.0f / 255.0f) * e->render.colormod[2]; + e->render.colormap_shirtcolor[0] = cbcolor[0] * (1.0f / 255.0f); + e->render.colormap_shirtcolor[1] = cbcolor[1] * (1.0f / 255.0f); + e->render.colormap_shirtcolor[2] = cbcolor[2] * (1.0f / 255.0f); } else if (e->state_current.colormap && cl.scores != NULL) { @@ -730,14 +830,14 @@ void CL_LinkNetworkEntity(entity_t *e) e->render.colormap = cl.scores[e->state_current.colormap - 1].colors; // color it cb = (e->render.colormap & 0xF) << 4;cb += (cb >= 128 && cb < 224) ? 4 : 12; cbcolor = (unsigned char *) (&palette_complete[cb]); - e->render.colormap_pantscolor[0] = cbcolor[0] * (1.0f / 255.0f) * e->render.colormod[0]; - e->render.colormap_pantscolor[1] = cbcolor[1] * (1.0f / 255.0f) * e->render.colormod[1]; - e->render.colormap_pantscolor[2] = cbcolor[2] * (1.0f / 255.0f) * e->render.colormod[2]; + e->render.colormap_pantscolor[0] = cbcolor[0] * (1.0f / 255.0f); + e->render.colormap_pantscolor[1] = cbcolor[1] * (1.0f / 255.0f); + e->render.colormap_pantscolor[2] = cbcolor[2] * (1.0f / 255.0f); cb = (e->render.colormap & 0xF0);cb += (cb >= 128 && cb < 224) ? 4 : 12; cbcolor = (unsigned char *) (&palette_complete[cb]); - e->render.colormap_shirtcolor[0] = cbcolor[0] * (1.0f / 255.0f) * e->render.colormod[0]; - e->render.colormap_shirtcolor[1] = cbcolor[1] * (1.0f / 255.0f) * e->render.colormod[1]; - e->render.colormap_shirtcolor[2] = cbcolor[2] * (1.0f / 255.0f) * e->render.colormod[2]; + e->render.colormap_shirtcolor[0] = cbcolor[0] * (1.0f / 255.0f); + e->render.colormap_shirtcolor[1] = cbcolor[1] * (1.0f / 255.0f); + e->render.colormap_shirtcolor[2] = cbcolor[2] * (1.0f / 255.0f); } else { @@ -989,6 +1089,11 @@ void CL_LinkNetworkEntity(entity_t *e) dlightcolor[1] += 0.7f; dlightcolor[2] += 0.3f; } + if (e->render.effects & (EF_FLAG1QW | EF_FLAG2QW)) + { + // these are only set on player entities + CL_AddQWCTFFlagModel(e, (e->render.effects & EF_FLAG2QW) != 0); + } } // muzzleflash fades over time, and is offset a bit if (e->persistent.muzzleflash > 0) @@ -1113,7 +1218,7 @@ void CL_LinkNetworkEntity(entity_t *e) // hide player shadow during intermission or nehahra movie if (!(e->render.effects & EF_NOSHADOW) && !(e->render.flags & (RENDER_VIEWMODEL | RENDER_TRANSPARENT)) - && (!(e->render.flags & RENDER_EXTERIORMODEL) || (!cl.intermission && cl.protocol != PROTOCOL_NEHAHRAMOVIE && !cl_noplayershadow.integer))) + && (!(e->render.flags & RENDER_EXTERIORMODEL) || (!cl.intermission && cls.protocol != PROTOCOL_NEHAHRAMOVIE && !cl_noplayershadow.integer))) e->render.flags |= RENDER_SHADOW; // as soon as player is known we can call V_CalcRefDef if (!csqc_loaded) @@ -1278,7 +1383,7 @@ static void CL_RelinkEffects(void) entity_t *ent; float frame; - for (i = 0, e = cl_effects;i < cl_max_effects;i++, e++) + for (i = 0, e = cl_effects;i < cl_activeeffects;i++, e++) { if (e->active) { @@ -1287,6 +1392,8 @@ static void CL_RelinkEffects(void) if (intframe < 0 || intframe >= e->endframe) { memset(e, 0, sizeof(*e)); + while (cl_activeeffects > 0 && !cl_effects[cl_activeeffects - 1].active) + cl_activeeffects--; continue; } @@ -1340,10 +1447,17 @@ void CL_RelinkBeams(void) float forward; matrix4x4_t tempmatrix; - for (i = 0, b = cl_beams;i < cl_max_beams;i++, b++) + while (cl_activebeams > 0 && !cl_beams[cl_activebeams - 1].model) + cl_activeeffects--; + for (i = 0, b = cl_beams;i < cl_activebeams;i++, b++) { - if (!b->model || b->endtime < cl.time) + if (!b->model) + continue; + if (b->endtime < cl.time) + { + b->model = NULL; continue; + } // if coming from the player, update the start position //if (b->entity == cl.viewentity) @@ -1416,6 +1530,34 @@ void CL_RelinkBeams(void) } } +static void CL_RelinkQWNails(void) +{ + int i; + vec_t *v; + entity_t *ent; + + for (i = 0;i < cl.qw_num_nails;i++) + { + v = cl.qw_nails[i]; + + // if we're drawing effects, get a new temp entity + // (NewTempEntity adds it to the render entities list for us) + if (!(ent = CL_NewTempEntity())) + continue; + + // normal stuff + ent->render.model = cl.model_precache[cl.qw_modelindex_spike]; + ent->render.colormap = -1; // no special coloring + ent->render.alpha = 1; + VectorSet(ent->render.colormod, 1, 1, 1); + + Matrix4x4_CreateFromQuakeEntity(&ent->render.matrix, v[0], v[1], v[2], v[3], v[4], v[5], 1); + Matrix4x4_Invert_Simple(&ent->render.inversematrix, &ent->render.matrix); + R_LerpAnimation(&ent->render); + CL_BoundingBoxForEntity(&ent->render); + } +} + void CL_LerpPlayer(float frac) { int i; @@ -1462,6 +1604,7 @@ void CSQC_RelinkAllEntities (int drawmask) CL_RelinkStaticEntities(); CL_RelinkBeams(); CL_RelinkEffects(); + CL_RelinkQWNails(); } } @@ -1477,6 +1620,7 @@ extern void CL_ClientMovement_Replay(); int CL_ReadFromServer(void) { CL_ReadDemoMessage(); + CL_SendMove(); r_refdef.time = cl.time; r_refdef.extraupdate = !r_speeds.integer; @@ -1509,6 +1653,7 @@ int CL_ReadFromServer(void) CL_RelinkStaticEntities(); CL_RelinkBeams(); CL_RelinkEffects(); + CL_RelinkQWNails(); } else csqc_frame = true; @@ -1525,28 +1670,6 @@ int CL_ReadFromServer(void) return 0; } -/* -================= -CL_SendCmd -================= -*/ -void CL_UpdatePrydonCursor(void); -void CL_SendCmd(void) -{ - // send the reliable message (forwarded commands) if there is one - if (cls.netcon && cls.netcon->message.cursize && NetConn_CanSendMessage(cls.netcon)) - { - if (developer.integer) - { - Con_Print("CL_SendCmd: sending reliable message:\n"); - SZ_HexDumpToConsole(&cls.netcon->message); - } - if (NetConn_SendReliableMessage(cls.netcon, &cls.netcon->message) == -1) - Host_Error("CL_WriteToServer: lost server connection"); - SZ_Clear(&cls.netcon->message); - } -} - // LordHavoc: pausedemo command static void CL_PauseDemo_f (void) { @@ -1695,6 +1818,10 @@ void CL_Init (void) Cvar_RegisterVariable(&cl_deathnoviewmodel); + // for QW connections + Cvar_RegisterVariable(&qport); + Cvar_SetValueQuick(&qport, (rand() * RAND_MAX + rand()) & 0xffff); + Cmd_AddCommand("timerefresh", CL_TimeRefresh_f, "turn quickly and print rendering statistcs"); CL_Parse_Init();