static void VID_SW_FreeBuffers() { D_FlushCaches(); free(vid_surfcache); free(d_pzbuffer); }
/* ===================== CL_ClearState ===================== */ void CL_ClearState (void) { int i; S_StopAllSounds (true); Con_DPrintf ("Clearing memory\n"); D_FlushCaches (); Mod_ClearAll (); if (host_hunklevel) // FIXME: check this... Hunk_FreeToLowMark (host_hunklevel); CL_ClearTEnts (); // wipe the entire cl structure memset (&cl, 0, sizeof(cl)); SZ_Clear (&cls.netchan.message); // clear other arrays memset (cl_efrags, 0, sizeof(cl_efrags)); memset (cl_dlights, 0, sizeof(cl_dlights)); memset (cl_lightstyle, 0, sizeof(cl_lightstyle)); // // allocate the efrags and chain together into a free list // cl.free_efrags = cl_efrags; for (i=0 ; i<MAX_EFRAGS-1 ; i++) cl.free_efrags[i].entnext = &cl.free_efrags[i+1]; cl.free_efrags[i].entnext = NULL; }
/* =============== R_CheckVariables =============== */ void R_CheckVariables (void) { static float oldbright; if (r_fullbright.value != oldbright) { oldbright = r_fullbright.value; D_FlushCaches (); // so all lighting changes } }
/* ================ Host_ClearMemory This clears all the memory used by both the client and server, but does not reinitialize anything. ================ */ void Host_ClearMemory (void) { Con_DPrintf ("Clearing memory\n"); D_FlushCaches (); Mod_ClearAll (); /* host_hunklevel MUST be set at this point */ Hunk_FreeToLowMark (host_hunklevel); cls.signon = 0; memset (&sv, 0, sizeof(sv)); memset (&cl, 0, sizeof(cl)); }
/* =============== R_CheckVariables =============== */ static void R_CheckVariables(void) { // FIXME - do it right (cvar callback) static float oldbright; if (r_fullbright.value != oldbright) { oldbright = r_fullbright.value; D_FlushCaches(); // so all lighting changes } }
/* ================ Host_ClearMemory This clears all the memory used by both the client and server, but does not reinitialize anything. ================ */ void Host_ClearMemory (void) { Con_DPrintf ("Clearing memory\n"); D_FlushCaches (); Mod_ClearAll (); /* host_hunklevel MUST be set at this point */ Hunk_FreeToLowMark (host_hunklevel); cls.signon = 0; if (sv.edicts) free(sv.edicts); // ericw -- sv.edicts switched to use malloc() memset (&sv, 0, sizeof(sv)); memset (&cl, 0, sizeof(cl)); }
//Free hunk memory up to host_hunklevel //Can only be called when changing levels! void Host_ClearMemory (void) { // FIXME, move to CL_ClearState D_FlushCaches (); // FIXME, move to CL_ClearState Mod_ClearAll (); CM_InvalidateMap (); // any data previously allocated on hunk is no longer valid Hunk_FreeToLowMark (host_hunklevel); }
/* =============== Host_ClearMemory Free hunk memory up to host_hunklevel Can only be called when changing levels! =============== */ void Host_ClearMemory () { // FIXME, move to CL_ClearState if (!dedicated) D_FlushCaches (); // FIXME, move to CL_ClearState #ifndef SERVERONLY if (!dedicated) Mod_ClearAll (); #endif CM_InvalidateMap (); // any data previously allocated on hunk is no longer valid Hunk_FreeToLowMark (host_hunklevel); }
/* @@@@@@@@@@@@@@@@@@@@@ R_BeginRegistration Specifies the model that will be used as the world @@@@@@@@@@@@@@@@@@@@@ */ void R_BeginRegistration (char *model) { char fullname[MAX_QPATH]; cvar_t *flushmap; registration_sequence++; r_oldviewcluster = -1; // force markleafs Com_sprintf (fullname, sizeof(fullname), "maps/%s.bsp", model); D_FlushCaches (); // explicitly free the old map if different // this guarantees that mod_known[0] is the world map flushmap = ri.Cvar_Get ("flushmap", "0", 0); if ( strcmp(mod_known[0].name, fullname) || flushmap->value) Mod_Free (&mod_known[0]); r_worldmodel = R_RegisterModel (fullname); R_NewMap (); }
/* ================ VID_AllocBuffers ================ */ static qboolean VID_AllocBuffers (int width, int height) { int tsize, tbuffersize; tbuffersize = width * height * sizeof (*d_pzbuffer); tsize = D_SurfaceCacheForRes (width, height); tbuffersize += tsize; // see if there's enough memory, allowing for the normal mode 0x13 pixel, // z, and surface buffers //if ((host_parms->memsize - tbuffersize + SURFCACHE_SIZE_AT_320X200 + // 0x10000 * 3) < MINIMUM_MEMORY) // Pa3PyX: using hopefully better estimation now // if total memory < needed surface cache + (minimum operational memory // less surface cache for 320x200 and typical hunk state after init) if (host_parms->memsize < tbuffersize + 0x180000 + 0xC00000) { Con_SafePrintf ("Not enough memory for video mode\n"); return false; // not enough memory for mode } vid_surfcachesize = tsize; if (d_pzbuffer) { D_FlushCaches (); Hunk_FreeToHighMark (VID_highhunkmark); d_pzbuffer = NULL; } VID_highhunkmark = Hunk_HighMark (); d_pzbuffer = (short *) Hunk_HighAllocName (tbuffersize, "video"); vid_surfcache = (byte *)d_pzbuffer + width * height * sizeof (*d_pzbuffer); return true; }
/* @@@@@@@@@@@@@@@@@@@@@ R_BeginRegistration Specifies the model that will be used as the world @@@@@@@@@@@@@@@@@@@@@ */ void R_BeginRegistration(const char *model) { char fullname[MAX_QPATH]; bsp_t *bsp; qerror_t ret; int i; registration_sequence++; r_oldviewcluster = -1; // force markleafs D_FlushCaches(); Q_concat(fullname, sizeof(fullname), "maps/", model, ".bsp", NULL); ret = BSP_Load(fullname, &bsp); if (!bsp) { Com_Error(ERR_DROP, "%s: couldn't load %s: %s", __func__, fullname, Q_ErrorString(ret)); } if (bsp == r_worldmodel) { for (i = 0; i < bsp->numtexinfo; i++) { bsp->texinfo[i].image->registration_sequence = registration_sequence; } bsp->refcount--; return; } BSP_Free(r_worldmodel); r_worldmodel = bsp; ProcessTexinfo(bsp); ProcessFaces(bsp); // TODO R_NewMap(); }
/* =============== R_SetupFrame =============== */ void R_SetupFrame (void) { int i; vrect_t vrect; if (r_fullbright->modified) { r_fullbright->modified = false; D_FlushCaches (); // so all lighting changes } r_framecount++; // build the transformation matrix for the given view angles VectorCopy (r_refdef.vieworg, modelorg); VectorCopy (r_refdef.vieworg, r_origin); AngleVectors (r_refdef.viewangles, vpn, vright, vup); // current viewleaf if ( !( r_newrefdef.rdflags & RDF_NOWORLDMODEL ) ) { r_viewleaf = Mod_PointInLeaf (r_origin, r_worldmodel); r_viewcluster = r_viewleaf->cluster; } if (sw_waterwarp->value && (r_newrefdef.rdflags & RDF_UNDERWATER) ) r_dowarp = true; else r_dowarp = false; if (r_dowarp) { // warp into off screen buffer vrect.x = 0; vrect.y = 0; vrect.width = r_newrefdef.width < WARP_WIDTH ? r_newrefdef.width : WARP_WIDTH; vrect.height = r_newrefdef.height < WARP_HEIGHT ? r_newrefdef.height : WARP_HEIGHT; d_viewbuffer = r_warpbuffer; r_screenwidth = WARP_WIDTH; } else { vrect.x = r_newrefdef.x; vrect.y = r_newrefdef.y; vrect.width = r_newrefdef.width; vrect.height = r_newrefdef.height; d_viewbuffer = (void *)vid.buffer; r_screenwidth = vid.rowbytes; } R_ViewChanged (&vrect); // start off with just the four screen edge clip planes R_TransformFrustum (); R_SetUpFrustumIndexes (); // save base values VectorCopy (vpn, base_vpn); VectorCopy (vright, base_vright); VectorCopy (vup, base_vup); // clear frame counts c_faceclip = 0; d_spanpixcount = 0; r_polycount = 0; r_drawnpolycount = 0; r_wholepolycount = 0; r_amodels_drawn = 0; r_outofsurfaces = 0; r_outofedges = 0; // d_setup d_roverwrapped = false; d_initial_rover = sc_rover; d_minmip = sw_mipcap->value; if (d_minmip > 3) d_minmip = 3; else if (d_minmip < 0) d_minmip = 0; for (i=0 ; i<(NUM_MIPS-1) ; i++) d_scalemip[i] = basemip[i] * sw_mipscale->value; d_aflatcolor = 0; }
/* =============== R_SetupFrame =============== */ void R_SetupFrame(void) { int i; vrect_t vrect; if (r_fullbright->modified) { r_fullbright->modified = qfalse; D_FlushCaches(); // so all lighting changes } r_framecount++; // build the transformation matrix for the given view angles VectorCopy(r_newrefdef.vieworg, modelorg); VectorCopy(r_newrefdef.vieworg, r_origin); AngleVectors(r_newrefdef.viewangles, vpn, vright, vup); // current viewleaf if (!(r_newrefdef.rdflags & RDF_NOWORLDMODEL)) { r_viewleaf = BSP_PointLeaf(r_worldmodel->nodes, r_origin); r_viewcluster = r_viewleaf->cluster; } if (sw_waterwarp->integer && (r_newrefdef.rdflags & RDF_UNDERWATER)) r_dowarp = qtrue; else r_dowarp = qfalse; if (r_dowarp) { // warp into off screen buffer vrect.x = 0; vrect.y = 0; vrect.width = r_newrefdef.width < WARP_WIDTH ? r_newrefdef.width : WARP_WIDTH; vrect.height = r_newrefdef.height < WARP_HEIGHT ? r_newrefdef.height : WARP_HEIGHT; d_viewbuffer = r_warpbuffer; d_screenrowbytes = WARP_WIDTH * VID_BYTES; } else { vrect.x = r_newrefdef.x; vrect.y = r_newrefdef.y; vrect.width = r_newrefdef.width; vrect.height = r_newrefdef.height; d_viewbuffer = (void *)vid.buffer; d_screenrowbytes = vid.rowbytes; } R_ViewChanged(&vrect); // start off with just the four screen edge clip planes R_TransformFrustum(); R_SetUpFrustumIndexes(); // save base values VectorCopy(vpn, base_vpn); VectorCopy(vright, base_vright); VectorCopy(vup, base_vup); // clear frame counts c_faceclip = 0; r_polycount = 0; r_drawnpolycount = 0; r_wholepolycount = 0; r_amodels_drawn = 0; r_outofsurfaces = 0; r_outofedges = 0; // d_setup for (i = 0; i < vid.height; i++) { d_spantable[i] = d_viewbuffer + i * d_screenrowbytes; d_zspantable[i] = d_pzbuffer + i * d_zwidth; } // clear Z-buffer and color-buffers if we're doing the gallery if (r_newrefdef.rdflags & RDF_NOWORLDMODEL) { memset(d_pzbuffer, 0xff, vid.width * vid.height * sizeof(d_pzbuffer[0])); #if 0 R_DrawFill8(r_newrefdef.x, r_newrefdef.y, r_newrefdef.width, r_newrefdef.height, /*(int)sw_clearcolor->value & 0xff*/0); #endif } d_minmip = Cvar_ClampInteger(sw_mipcap, 0, NUM_MIPS - 1); for (i = 0; i < (NUM_MIPS - 1); i++) d_scalemip[i] = basemip[i] * sw_mipscale->value; }