public void Init(Client tclient, ClientCVar cvar) { if (Context != null) { Context.Dispose(); } TheClient = tclient; CVars = cvar; Context = new AudioContext(AudioContext.DefaultDevice, 0, 0, false, true); Context.MakeCurrent(); try { if (Microphone != null) { Microphone.StopEcho(); } Microphone = new MicrophoneHandler(this); } catch (Exception ex) { SysConsole.Output("Loading microphone handling", ex); } if (Effects != null) { foreach (SoundEffect sfx in Effects.Values) { sfx.Internal = -2; } } Effects = new Dictionary<string, SoundEffect>(); PlayingNow = new List<ActiveSound>(); Noise = LoadSound(new DataStream(Convert.FromBase64String(NoiseDefault.NoiseB64)), "noise"); }
/// <summary> /// Start up and run the server. /// </summary> public void StartUp(string args) { Files.Init(); SysConsole.Output(OutputType.INIT, "Launching as new client, this is " + (this == Central ? "" : "NOT ") + "the Central client."); SysConsole.Output(OutputType.INIT, "Loading command system..."); Commands = new ClientCommands(); Commands.Init(new ClientOutputter(this), this); SysConsole.Output(OutputType.INIT, "Loading CVar system..."); CVars = new ClientCVar(); CVars.Init(this, Commands.Output); SysConsole.Output(OutputType.INIT, "Loading default settings..."); if (Files.Exists("clientdefaultsettings.cfg")) { string contents = Files.ReadText("clientdefaultsettings.cfg"); Commands.ExecuteCommands(contents); } Commands.ExecuteCommands(args); SysConsole.Output(OutputType.INIT, "Generating window..."); Window = new GameWindow(CVars.r_width.ValueI, CVars.r_height.ValueI, new GraphicsMode(24, 24, 0, 0), Program.GameName + " v" + Program.GameVersion, GameWindowFlags.Default, DisplayDevice.Default, 4, 3, GraphicsContextFlags.ForwardCompatible); Window.Location = new Point(0, 0); Window.WindowState = CVars.r_fullscreen.ValueB ? WindowState.Fullscreen : WindowState.Normal; Window.Load += new EventHandler<EventArgs>(Window_Load); Window.RenderFrame += new EventHandler<FrameEventArgs>(Window_RenderFrame); Window.Mouse.Move += new EventHandler<MouseMoveEventArgs>(MouseHandler.Window_MouseMove); Window.KeyDown += new EventHandler<KeyboardKeyEventArgs>(KeyHandler.PrimaryGameWindow_KeyDown); Window.KeyPress += new EventHandler<KeyPressEventArgs>(KeyHandler.PrimaryGameWindow_KeyPress); Window.KeyUp += new EventHandler<KeyboardKeyEventArgs>(KeyHandler.PrimaryGameWindow_KeyUp); Window.Mouse.WheelChanged += new EventHandler<MouseWheelEventArgs>(KeyHandler.Mouse_Wheel); Window.Mouse.ButtonDown += new EventHandler<MouseButtonEventArgs>(KeyHandler.Mouse_ButtonDown); Window.Mouse.ButtonUp += new EventHandler<MouseButtonEventArgs>(KeyHandler.Mouse_ButtonUp); Window.Resize += Window_Resize; Window.Closed += Window_Closed; onVsyncChanged(CVars.r_vsync, null); Window.Run(1, CVars.r_maxfps.ValueD); }
public void Generate(Client tclient, ClientCVar cvars, TextureEngine eng) { TheClient = tclient; if (Anims != null) { for (int i = 0; i < Anims.Count; i++) { Anims[i].Destroy(); } } if (TextureID > -1) { GL.DeleteTexture(TextureID); GL.DeleteTexture(NormalTextureID); GL.DeleteTexture(HelpTextureID); } Anims = new List<AnimatedTexture>(); TEngine = eng; TextureID = GL.GenTexture(); TWidth = cvars.r_blocktexturewidth.ValueI; GL.BindTexture(TextureTarget.Texture2DArray, TextureID); GL.TexStorage3D(TextureTarget3d.Texture2DArray, 1, SizedInternalFormat.Rgba8, TWidth, TWidth, MaterialHelpers.Textures.Length); GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureMinFilter, (int)(cvars.r_blocktexturelinear.ValueB ? TextureMinFilter.Linear: TextureMinFilter.Nearest)); GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureMagFilter, (int)(cvars.r_blocktexturelinear.ValueB ? TextureMagFilter.Linear : TextureMagFilter.Nearest)); GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge); GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge); HelpTextureID = GL.GenTexture(); GL.BindTexture(TextureTarget.Texture2DArray, HelpTextureID); GL.TexStorage3D(TextureTarget3d.Texture2DArray, 1, SizedInternalFormat.Rgba8, TWidth, TWidth, MaterialHelpers.Textures.Length); GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear); GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge); GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge); NormalTextureID = GL.GenTexture(); GL.BindTexture(TextureTarget.Texture2DArray, NormalTextureID); GL.TexStorage3D(TextureTarget3d.Texture2DArray, 1, SizedInternalFormat.Rgba8, TWidth, TWidth, MaterialHelpers.Textures.Length); GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear); GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge); GL.TexParameter(TextureTarget.Texture2DArray, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge); // TODO: Use normal.a! List<MaterialTextureInfo> texs = new List<MaterialTextureInfo>(MaterialHelpers.Textures.Length); IntTexs = new string[MaterialHelpers.Textures.Length]; //float time = 0; for (int ia = 0; ia < MaterialHelpers.Textures.Length; ia++) { int i = ia; // TODO: Make this saner, and don't allow entering a game until it's done maybe? //TheClient.Schedule.ScheduleSyncTask(() => { MaterialTextureInfo tex = new MaterialTextureInfo(); tex.Mat = (Material)i; string[] refrornot = MaterialHelpers.Textures[i].SplitFast('@'); if (refrornot.Length > 1) { string[] rorn = refrornot[1].SplitFast('%'); if (rorn.Length > 1) { tex.RefrRate = Utilities.StringToFloat(rorn[1]); } tex.RefractTextures = rorn[0].SplitFast(','); } string[] glowornot = refrornot[0].SplitFast('!'); if (glowornot.Length > 1) { tex.GlowingTextures = glowornot[1].SplitFast(','); } string[] reflornot = glowornot[0].SplitFast('*'); if (reflornot.Length > 1) { tex.ReflectTextures = reflornot[1].SplitFast(','); } string[] specularornot = reflornot[0].SplitFast('&'); if (specularornot.Length > 1) { tex.SpecularTextures = specularornot[1].SplitFast(','); } string[] normalornot = specularornot[0].SplitFast('$'); GL.BindTexture(TextureTarget.Texture2DArray, NormalTextureID); if (normalornot.Length > 1) { string[] rorn = normalornot[1].SplitFast('%'); if (rorn.Length > 1) { tex.NormRate = Utilities.StringToFloat(rorn[1]); } tex.NormalTextures = rorn[0].SplitFast(','); SetTexture((int)tex.Mat, tex.NormalTextures[0]); if (tex.NormalTextures.Length > 1) { SetAnimated((int)tex.Mat, tex.NormRate, tex.NormalTextures, NormalTextureID); } } else { SetTexture((int)tex.Mat, "normal_def"); } string[] rateornot = normalornot[0].SplitFast('%'); if (rateornot.Length > 1) { tex.Rate = Utilities.StringToFloat(rateornot[1]); } tex.Textures = rateornot[0].SplitFast(','); GL.BindTexture(TextureTarget.Texture2DArray, TextureID); SetTexture((int)tex.Mat, tex.Textures[0]); if (tex.Textures.Length > 1) { SetAnimated((int)tex.Mat, tex.Rate, tex.Textures, TextureID); } texs.Add(tex); IntTexs[(int)tex.Mat] = tex.Textures[0]; }//, i * LoadRate); //time = i * 0.1f; } for (int ia = 0; ia < texs.Count; ia++) { int i = ia; //TheClient.Schedule.ScheduleSyncTask(() => { GL.BindTexture(TextureTarget.Texture2DArray, HelpTextureID); Bitmap combo = GetCombo(texs[i], 0); TEngine.LockBitmapToTexture(combo, (int)texs[i].Mat); if ((texs[i].SpecularTextures != null) && (texs[i].ReflectTextures != null) && (texs[i].RefractTextures != null) && (texs[i].GlowingTextures != null) && texs[i].SpecularTextures.Length > 1) { Bitmap[] bmps = new Bitmap[texs[i].SpecularTextures.Length]; bmps[0] = combo; for (int x = 1; x < bmps.Length; x++) { bmps[x] = GetCombo(texs[i], x); } SetAnimated((int)texs[i].Mat, texs[i].RefrRate, bmps, HelpTextureID); for (int x = 1; x < bmps.Length; x++) { bmps[x].Dispose(); } } combo.Dispose(); }//, time + i * LoadRate); } GL.BindTexture(TextureTarget.Texture2DArray, 0); GL.BindTexture(TextureTarget.Texture2DArray, 0); }