Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var SCR = {};
- SCR.con_current = 0;
- SCR.centerstring = [];
- SCR.centertime_off = 0.0;
- SCR.CenterPrint = function(str)
- {
- SCR.centerstring = str.split('\n');
- SCR.centertime_off = SCR.centertime.value;
- SCR.centertime_start = CL.state.time;
- }
- SCR.DrawCenterString = function()
- {
- SCR.centertime_off -= Host.frametime;
- if (((SCR.centertime_off <= 0.0) && (CL.state.intermission === 0)) || (Key.dest.dest !== Key.dest.game))
- return;
- var y;
- if (SCR.centerstring.length <= 4)
- y = Math.floor(VID.height * 0.35);
- else
- y = 48;
- var i;
- if (CL.state.intermission)
- {
- var remaining = Math.floor(SCR.printspeed.value * (CL.state.time - SCR.centertime_start));
- var str, x, j;
- for (i = 0; i < SCR.centerstring.length; ++i)
- {
- str = SCR.centerstring[i];
- x = (VID.width - (str.length << 3)) >> 1;
- for (j = 0; j < str.length; ++j)
- {
- Draw.Character(x, y, str.charCodeAt(j));
- if ((remaining--) === 0)
- return;
- x += 8;
- }
- y += 8;
- }
- return;
- }
- for (i = 0; i < SCR.centerstring.length; ++i)
- {
- Draw.String((VID.width - (SCR.centerstring[i].length << 3)) >> 1, y, SCR.centerstring[i]);
- y += 8;
- }
- };
- SCR.CalcFov = function(fov_y, width, height)
- {
- if ((fov_y < 1.0) || (fov_y > 179.0))
- Sys.Error('Bad fov: ' + fov_y);
- return Math.atan(width / (height / Math.tan(fov_y * 0.82 * Math.PI / 360.0))) * 360.0 / Math.PI;
- };
- SCR.CalcRefdef = function()
- {
- SCR.recalc_refdef = false;
- if (SCR.viewsize.value < 30)
- Cvar.Set('viewsize', '30');
- else if (SCR.viewsize.value > 120)
- Cvar.Set('viewsize', '120');
- var size, full;
- if (CL.state.intermission !== 0)
- {
- full = true;
- size = 1.0;
- Sbar.lines = 0;
- }
- else
- {
- size = SCR.viewsize.value;
- if (size >= 120.0)
- Sbar.lines = 0;
- else if (size >= 110.0)
- Sbar.lines = 24;
- else
- Sbar.lines = 48;
- if (size >= 100.0)
- {
- full = true;
- size = 100.0;
- }
- size *= 0.01;
- }
- var vrect = R.refdef.vrect;
- vrect.width = Math.floor(VID.width * size);
- if (vrect.width < 96)
- {
- size = 96.0 / vrect.width;
- vrect.width = 96;
- }
- vrect.height = Math.floor(VID.height * size);
- if (vrect.height > (VID.height - Sbar.lines))
- vrect.height = VID.height - Sbar.lines;
- vrect.x = (VID.width - vrect.width) >> 1;
- if (full === true)
- vrect.y = 0;
- else
- vrect.y = (VID.height - Sbar.lines - vrect.height) >> 1;
- if (SCR.fov.value < 10)
- Cvar.Set('fov', '10');
- else if (SCR.fov.value > 170)
- Cvar.Set('fov', '170');
- R.refdef.fov_x = SCR.CalcFov(SCR.fov.value, vrect.width, vrect.height);
- R.refdef.fov_y = SCR.fov.value * 0.82;
- R.warpwidth = vrect.width;
- R.warpheight = vrect.height;
- if (R.warpwidth > 2048)
- R.warpwidth = 2048;
- if (R.warpheight > 2048)
- R.warpheight = 2048;
- if ((R.oldwarpwidth !== R.warpwidth) || (R.oldwarpheight !== R.warpheight))
- {
- R.oldwarpwidth = R.warpwidth;
- R.oldwarpheight = R.warpheight;
- GL.Bind(0, R.warptexture);
- gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, R.warpwidth, R.warpheight, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
- gl.bindRenderbuffer(gl.RENDERBUFFER, R.warprenderbuffer);
- gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT16, R.warpwidth, R.warpheight);
- gl.bindRenderbuffer(gl.RENDERBUFFER, null);
- }
- };
- SCR.SizeUp_f = function()
- {
- Cvar.SetValue('viewsize', SCR.viewsize.value + 10);
- SCR.recalc_refdef = true;
- };
- SCR.SizeDown_f = function()
- {
- Cvar.SetValue('viewsize', SCR.viewsize.value - 10);
- SCR.recalc_refdef = true;
- };
- SCR.Init = function()
- {
- SCR.fov = Cvar.RegisterVariable('fov', '90');
- SCR.viewsize = Cvar.RegisterVariable('viewsize', '100', true);
- SCR.conspeed = Cvar.RegisterVariable('scr_conspeed', '300');
- SCR.showpause = Cvar.RegisterVariable('showpause', '1');
- SCR.centertime = Cvar.RegisterVariable('scr_centertime', '2');
- SCR.printspeed = Cvar.RegisterVariable('scr_printspeed', '8');
- Cmd.AddCommand('screenshot', SCR.ScreenShot_f);
- Cmd.AddCommand('sizeup', SCR.SizeUp_f);
- Cmd.AddCommand('sizedown', SCR.SizeDown_f);
- SCR.pause = Draw.CachePic('pause');
- SCR.loading = document.getElementById('loading');
- SCR.loading.src = Draw.PicToDataURL(Draw.CachePic('loading'));
- };
- SCR.DrawPause = function()
- {
- if ((SCR.showpause.value === 0) || (CL.state.paused !== true))
- return;
- Draw.Pic((VID.width - SCR.pause.width) >> 1, (VID.height - 48 - SCR.pause.height) >> 1, SCR.pause);
- };
- SCR.SetUpToDrawConsole = function()
- {
- Con.forcedup = (CL.state.worldmodel == null) || (CL.cls.signon !== 4);
- if (Con.forcedup === true)
- {
- SCR.con_current = 200;
- return;
- }
- var conlines;
- if (Key.dest.dest === Key.dest.console)
- conlines = 100;
- else
- conlines = 0;
- if (conlines < SCR.con_current)
- {
- SCR.con_current -= SCR.conspeed.value * Host.frametime;
- if (conlines > SCR.con_current)
- SCR.con_current = conlines;
- }
- else if (conlines > SCR.con_current)
- {
- SCR.con_current += SCR.conspeed.value * Host.frametime;
- if (conlines < SCR.con_current)
- SCR.con_current = conlines;
- }
- };
- SCR.DrawConsole = function()
- {
- if (SCR.con_current > 0)
- {
- Con.DrawConsole(SCR.con_current);
- return;
- }
- if ((Key.dest.dest === Key.dest.game) || (Key.dest.dest === Key.dest.message))
- Con.DrawNotify();
- };
- SCR.ScreenShot_f = function()
- {
- SCR.screenshot = true;
- };
- SCR.BeginLoadingPlaque = function()
- {
- var html = document.getElementsByTagName('html')[0];
- var width = (html.clientWidth <= 320) ? 320 : html.clientWidth;
- var height = (html.clientHeight <= 200) ? 200 : html.clientHeight;
- SCR.loading.style.left = ((width - SCR.loading.width) >> 1) + 'px';
- SCR.loading.style.top = ((height - 48 - SCR.loading.height) >> 1) + 'px';
- SCR.loading.style.display = 'inline-block';
- };
- SCR.EndLoadingPlaque = function()
- {
- SCR.loading.style.display = 'none';
- };
- SCR.UpdateScreen = function()
- {
- var html = document.getElementsByTagName('html')[0];
- var width = (html.clientWidth <= 320) ? 320 : html.clientWidth;
- var height = (html.clientHeight <= 200) ? 200 : html.clientHeight;
- if ((VID.width != width) || (VID.height != height))
- {
- VID.width = width;
- VID.height = height;
- VID.mainwindow.width = width;
- VID.mainwindow.height = height;
- SCR.recalc_refdef = true;
- }
- if (SCR.oldfov !== SCR.fov.value)
- {
- SCR.oldfov = SCR.fov.value;
- SCR.recalc_refdef = true;
- }
- if (SCR.oldscreensize !== SCR.viewsize.value)
- {
- SCR.oldscreensize = SCR.viewsize.value;
- SCR.recalc_refdef = true;
- }
- if (SCR.recalc_refdef === true)
- SCR.CalcRefdef();
- SCR.SetUpToDrawConsole();
- V.RenderView();
- GL.Set2D();
- if (R.dowarp === true)
- R.WarpScreen();
- if ((CL.state.intermission === 1) && (Key.dest.dest === Key.dest.game))
- Sbar.IntermissionOverlay();
- else if ((CL.state.intermission === 2) && (Key.dest.dest === Key.dest.game))
- {
- Sbar.FinaleOverlay();
- SCR.DrawCenterString();
- }
- else if ((CL.state.intermission === 3) && (Key.dest.dest === Key.dest.game))
- SCR.DrawCenterString();
- else
- {
- if (V.crosshair.value !== 0)
- {
- Draw.Character(R.refdef.vrect.x + (R.refdef.vrect.width >> 1) + V.crossx.value,
- R.refdef.vrect.y + (R.refdef.vrect.height >> 1) + V.crossy.value, 43);
- }
- SCR.DrawPause();
- SCR.DrawCenterString();
- Sbar.Draw();
- SCR.DrawConsole();
- M.Draw();
- }
- R.PolyBlend();
- gl.disable(gl.BLEND);
- if (SCR.screenshot === true)
- {
- SCR.screenshot = false;
- gl.finish();
- open(VID.mainwindow.toDataURL('image/jpeg'));
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment