From 075f7024a0a5959ef6841f8143d7485ac194b0b7 Mon Sep 17 00:00:00 2001 From: Soldy <4786022+Soldy@users.noreply.github.com> Date: Mon, 25 May 2020 12:00:00 +0100 Subject: [PATCH 1/9] audio context Signed-off-by: Soldy <4786022+Soldy@users.noreply.github.com> --- Client/WebQuake/SC.js | 394 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 394 insertions(+) create mode 100644 Client/WebQuake/SC.js diff --git a/Client/WebQuake/SC.js b/Client/WebQuake/SC.js new file mode 100644 index 0000000..4cf05ad --- /dev/null +++ b/Client/WebQuake/SC.js @@ -0,0 +1,394 @@ + +const sClass = function(){ + this.Init=function(){ + init(); + }; + this.PrecacheSound = function(name){ + if (this.nosound !== 0) + return name; + if (this.precache === 0) + return name; + return precacheSound(name); + }; + this.LoadSound = function(source){ + if (this.nosound.value !== 0) + return; + return loadSound(source); + }; + this.SounList = function(){ + for(let i in sfxs) + Con.Print( + sizeGet(i) + ' : ' + i + '\n' + ); + Con.Print( + 'Total resident: ' + + total + + '\n' + ); + }; + this.StartSound = function(entnum, entchannel, sfx, origin, vol, attenuation){ + startSound(entnum, entchannel, sfx, origin, vol, attenuation); + } + this.StartAmbient = function(name){ + return startAmbient(name); + } + this.listAmbient = function(){ + let out = []; + for(let i in ambient_channels) + out.push(i); + return out; + } + this.LocalSound = function(sound){ + startSound( + CL.state.viewentity, + 1, + sound, + Vec.origin, + 1.0, + 1.0 + ); + }; + this.StopAllSounds = function(){ + stopAllSounds(); + } + this.StopSound = function(etnum, etchannel){ + stopSound(etnum, etchannel); + } + this.Play = function(){ + + } + this.PlayVol = function(){ + + } + this.StaticSound = async function(sfx, origin, vol, attenuation){ + await startSound( + "static", + staticSerial, + sfx, + origin, + vol, + attenuation + ); + channels["static"].sub[staticSerial].sx.loop = true; + staticSerial++; + if(staticSerial >10) // 11 static channels + staticSerial = 0; + + } + this.UpdateDynamicSounds = function(){ + for (let i of activeChannels){ //ia:string + if(Host.realtime >= channels[ + activeChannels[i].entnum + ].sub[ + activeChannels[i].entchannel + ].end + ){ + activeChannels.splice(i, 1); + continue; + } + spatialize( + activeChannels[i].entnum, + activeChannels[i].entchannel + ); + channelVolume( + activeChannels[i].entnum, + activeChannels[i].entchannel + ); + } + } + this.UpdateAmbientSounds = function(){} + this.UpdateStaticSounds = function(){} + this.Update = function(origin, forward, right, up){ + listener_origin = origin; + listener_forward = forward; + listener_right = right; + listener_up = up; + if (volume.value < 0.0) + Cvar.SetValue('volume', 0.0); + else if (volume.value > 1.0) + Cvar.SetValue('volume', 1.0); + } + this.Spatialize = function(ch){} + this.size = 0; + this.bgmvolume = 0; + this.volume = 0; + this.ambient_level = 0.3; + this.ambient_fade = 100; + this.precache = 1; + this.nosound = 0; + this.static_channels = []; + this.known_sfx = []; + this.started = false; + let staticSerial = 0; + let activeChannels = []; + let channels = {}; + let ambient_channels = {}; + let listener_origin = [0.0, 0.0, 0.0]; + let listener_forward = [0.0, 0.0, 0.0]; + let listener_right = [0.0, 0.0, 0.0]; + let listener_up = [0.0, 0.0, 0.0]; + let sfxs = {}; + let audioCTX; + let init = async function(){ + Con.Print('\nSound Initialization\n'); + Cmd.AddCommand('play', S.Play); + Cmd.AddCommand('playvol', S.PlayVol); + Cmd.AddCommand('stopsound', S.StopAllSounds); + Cmd.AddCommand('soundlist', S.SoundList); + this.nosound = Cvar.RegisterVariable( + 'nosound', + (COM.CheckParm( + '-nosound' + ) != null) ? '1' : '0' + ); + this.volume = Cvar.RegisterVariable( + 'volume', + '0.7', + true + ); + this.precache = Cvar.RegisterVariable( + 'precache', + '1' + ); + this.bgmvolume = Cvar.RegisterVariable( + 'bgmvolume', + '1', + true + ); + this.ambient_level = Cvar.RegisterVariable( + 'ambient_level', + '0.3' + ); + this.ambient_fade = Cvar.RegisterVariable( + 'ambient_fade', + '100' + ); + this.started = true; + audioCTX = new (window.AudioContext || window.webkitAudioContext)({ + latencyHint: 'interactive', + sampleRate: 44100, + }); + let ambient_sfx = ['water1', 'wind2']; + for (let i of ambient_sfx) + startAmbient('ambience/' + i + '.wav'); + + } + let upldate = function(){ + + } + let spatialize = function(en, ec){ + if(en === CL.state.viewentity){ + channels[en].sub[ec].volLeft = channels[en].sub[ec].vol; + channels[en].sub[ec].volRight = channels[en].sub[ec].vol; + return ; + } + let source = [ + channels[en].sub[ec].origin[0] - listener_origin[0], + channels[en].sub[ec].origin[1] - listener_origin[1], + channels[en].sub[ec].origin[2] - listener_origin[2] + ]; + let dist = Math.sqrt(source[0] * source[0] + source[1] * source[1] + source[2] * source[2]); + + if (dist !== 0.0){ + source[0] /= dist; + source[1] /= dist; + source[2] /= dist; + } + dist *= (channels[en].sub[ec].mult*0.4); + var dot = listener_right[0] * source[0] + + listener_right[1] * source[1] + + listener_right[2] * source[2]; + channels[en].sub[ec].volRight = channels[en].sub[ec].vol * (1.0 - dist) * (1.0 + dot); + if (channels[en].sub[ec].volRight < 0.0) + channels[en].sub[ec].volRight = 0.0; + if (channels[en].sub[ec].volRight > 1.0) + channels[en].sub[ec].volRight = 1.0; + channels[en].sub[ec].volLeft = channels[en].sub[ec].vol * (1.0 - dist) * (1.0 - dot); + if (channels[en].sub[ec].volLeft < 0.0) + channels[en].sub[ec].volLeft = 0.0; + if (channels[en].sub[ec].volLeft > 1.0) + channels[en].sub[ec].volLeft = 1.0; + } + let channelVolume = function(en,ec){ + channels[en].sub[ec].g1.gain.value = + channels[en].sub[ec].volLeft * volume.value; + channels[en].sub[ec].g2.gain.value = + channels[en].sub[ec].volRight * volume.value; + } + let startSound = async function(entnum, entchannel, sfx, origin, vol, attenuation){ + pickChannel(entnum, entchannel); + await loadSound(sfx); + channels[entnum].sub[entchannel].vol = vol; + channels[entnum].sub[entchannel].mult = attenuation * 0.001; + spatialize(entnum, entchannel); + if ( + (channels[entnum].sub[entchannel].volLeft === 0.0)&& + (channels[entnum].sub[entchannel].volRight === 0.0) + ) + return; + + if(channels[entnum].sub[entchannel].activeChannels === false){ + channels[entnum].sub[entchannel].activeChannels = parseInt(activeChannels.length); + activeChannels.push({ + entnum, + entchannel + }); + } + channels[entnum].sub[entchannel].sx.buffer = sfxs[sfx].cache; +// channels[entnum].sub[entchannel].sx.connect(audioCTX.destination); + channels[entnum].sub[entchannel].end = Host.realtime + sfxs[sfx].cache.length; + channels[entnum].sub[entchannel].sx.connect( + channels[entnum].sub[entchannel].m1 + ); + channels[entnum].sub[entchannel].sx.connect( + channels[entnum].sub[entchannel].m1, 0, 1 + ); + channels[entnum].sub[entchannel].m1.connect( + channels[entnum].sub[entchannel].sp + ); + channels[entnum].sub[entchannel].sp.connect( + channels[entnum].sub[entchannel].g1 + ); + channels[entnum].sub[entchannel].sp.connect( + channels[entnum].sub[entchannel].g2 + ); + channels[entnum].sub[entchannel].g1.connect( + channels[entnum].sub[entchannel].m2, 0, 0 + ); + channels[entnum].sub[entchannel].g2.connect( + channels[entnum].sub[entchannel].m2, 0, 1 + ); + channels[entnum].sub[entchannel].m2.connect( + audioCTX.destination + ); + channelVolume(entnum,entchannel); + return channels[entnum].sub[entchannel].sx.start(); + } + let startAmbient = async (sfx)=>{ + try{ + ambient_channels[sfx].stop(); + }catch(e){}; + loadSound(sfx); + ambient_channels[sfx] = audioCTX.createBufferSource(); + ambient_channels[sfx].loop = true ; + ambient_channels[sfx].connect(audioCTX.destination); + setTimeout(function(){ + try{ + console.info(sfx); + ambient_channels[sfx].buffer = sfxs[sfx].cache; + ambient_channels[sfx].start(); + }catch(e){ + console.error(e); + } + },2000); + } + let startAmbientAll = function(){ + for (let i in ambient_channels) + startAmbient(i); + } + let precacheSound = function(name){ + if(typeof sfxs[name] === "undefined") + sfxs[name] = {name: name}; + loadSound(name); + return name; + } + let loadSound = async function(name){ + if (sfxs[name] == null) + sfxs[name] = { + name : name, + cache : null + }; + if (sfxs[name].cache != null) + return true; + let sc = {}; + let data = COM.LoadFile('sound/' + name); + if (data == null){ + Con.Print( + 'Couldn\'t load sound/' + + name + + '\n' + ); + return; + } + (await (async function(dataout, name){ + audioCTX.decodeAudioData( + data, + function(buffer){ + sfxs[name].cache = buffer; + }, + (e) => { reject(e); } + ); + })(data,name)); + return true; + }; + let sizeGet = function(name){ + if(sfxs[name].cache== null) + return ''; + let size = sfxs.cache.size.toString(); + if (sfxs.cache.loopstart != null) + size = 'L' + size; + return size.padStart(6, ' '); + }; + let pickChannel = function(entnum,entchannel){ + if(channels[entnum] == null) + newChannel(entnum); + if(channels[entnum].sub[entchannel] != null) + stopSound(entnum, entchannel); + return channels[entnum].sub[entchannel]= + emptyChannel(); + + }; + let emptyChannel = function(){ + return { + vol : 1, + volLeft : 1, + volRight : 1, + origin : [0,0,0], + mult : 0.0001, + end : null, + sx : audioCTX.createBufferSource(), + m1 : audioCTX.createChannelMerger(2), + m2 : audioCTX.createChannelMerger(2), + sp : audioCTX.createChannelSplitter(2), + g1 : audioCTX.createGain(), + g2 : audioCTX.createGain() + } + } + let newChannel = function(entnum, sub){ + if((1 > sub)||(typeof sub === "undefined")) + sub = 2; + channels[entnum] = { + sub:[] + }; + }; + let stopAllSounds = function(){ + for(let iOne in channels) + for(let iTwo in channels[iOne].sub) + stopSound(iOne,iTwo); + for(let iOne in ambient_channels) + stopSoundAmbient(iOne); + } + let stopSoundAmbient = function(sfx){ + if(ambient_channels[sfx] == null) + return ; + try{ + ambient_channels[sfx].stop(); + ambient_channels[sfx]=null; + }catch(e){ + + } + } + let stopSound = function(entnum, entchannel){ + if(channels[entnum].sub[entchannel].sx == null) + return ; + try{ + channels[entnum].sub[entchannel].sx.stop(); + channels[entnum].sub[entchannel].sx=null; + }catch(e){ + + } + } + +}; + +const S = new sClass(); From 177d7f92ffa66a13e506d4e3bc32b512c015acdc Mon Sep 17 00:00:00 2001 From: Soldy <4786022+Soldy@users.noreply.github.com> Date: Wed, 12 May 2021 09:49:31 +0100 Subject: [PATCH 2/9] move server.js to the main Signed-off-by: Soldy <4786022+Soldy@users.noreply.github.com> --- Server/WebQDS.js | 31 ------------------------------- server.js | 31 +++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 31 deletions(-) delete mode 100644 Server/WebQDS.js create mode 100644 server.js diff --git a/Server/WebQDS.js b/Server/WebQDS.js deleted file mode 100644 index 128907a..0000000 --- a/Server/WebQDS.js +++ /dev/null @@ -1,31 +0,0 @@ -Node = { - dgram: require('dgram'), - fs: require('fs'), - http: require('http'), - os: require('os'), - url: require('url'), - websocket: require('websocket') -}; -require('./WebQDS/Cmd.js'); -require('./WebQDS/COM.js'); -require('./WebQDS/Console.js'); -require('./WebQDS/CRC.js'); -require('./WebQDS/Cvar.js'); -require('./WebQDS/Def.js'); -require('./WebQDS/ED.js'); -require('./WebQDS/Host.js'); -require('./WebQDS/Mod.js'); -require('./WebQDS/MSG.js'); -require('./WebQDS/NET.js'); -require('./WebQDS/NET_Datagram.js'); -require('./WebQDS/NET_WEBS.js'); -require('./WebQDS/PF.js'); -require('./WebQDS/PR.js'); -require('./WebQDS/Protocol.js'); -require('./WebQDS/Q.js'); -require('./WebQDS/SV.js'); -require('./WebQDS/Sys.js'); -require('./WebQDS/SZ.js'); -require('./WebQDS/V.js'); -require('./WebQDS/Vec.js'); -Sys.main(); \ No newline at end of file diff --git a/server.js b/server.js new file mode 100644 index 0000000..0bf4bef --- /dev/null +++ b/server.js @@ -0,0 +1,31 @@ +Node = { + dgram: require('dgram'), + fs: require('fs'), + http: require('http'), + os: require('os'), + url: require('url'), + websocket: require('websocket') +}; +require('./Server/WebQDS/Cmd.js'); +require('./Server/WebQDS/COM.js'); +require('./Server/WebQDS/Console.js'); +require('./Server/WebQDS/CRC.js'); +require('./Server/WebQDS/Cvar.js'); +require('./Server/WebQDS/Def.js'); +require('./Server/WebQDS/ED.js'); +require('./Server/WebQDS/Host.js'); +require('./Server/WebQDS/Mod.js'); +require('./Server/WebQDS/MSG.js'); +require('./Server/WebQDS/NET.js'); +require('./Server/WebQDS/NET_Datagram.js'); +require('./Server/WebQDS/NET_WEBS.js'); +require('./Server/WebQDS/PF.js'); +require('./Server/WebQDS/PR.js'); +require('./Server/WebQDS/Protocol.js'); +require('./Server/WebQDS/Q.js'); +require('./Server/WebQDS/SV.js'); +require('./Server/WebQDS/Sys.js'); +require('./Server/WebQDS/SZ.js'); +require('./Server/WebQDS/V.js'); +require('./Server/WebQDS/Vec.js'); +Sys.main(); From 00bb86b6fe1a1810fbd447587c9b913563e53df0 Mon Sep 17 00:00:00 2001 From: Soldy <4786022+Soldy@users.noreply.github.com> Date: Wed, 12 May 2021 09:56:07 +0100 Subject: [PATCH 3/9] Protocol.js duplication remove Signed-off-by: Soldy <4786022+Soldy@users.noreply.github.com> --- Server/WebQDS/Protocol.js | 101 -------------------------------------- server.js | 2 +- 2 files changed, 1 insertion(+), 102 deletions(-) delete mode 100644 Server/WebQDS/Protocol.js diff --git a/Server/WebQDS/Protocol.js b/Server/WebQDS/Protocol.js deleted file mode 100644 index 6fdb40a..0000000 --- a/Server/WebQDS/Protocol.js +++ /dev/null @@ -1,101 +0,0 @@ -Protocol = {}; - -Protocol.version = 15; - -Protocol.u = { - morebits: 1, - origin1: 1 << 1, - origin2: 1 << 2, - origin3: 1 << 3, - angle2: 1 << 4, - nolerp: 1 << 5, - frame: 1 << 6, - signal: 1 << 7, - - angle1: 1 << 8, - angle3: 1 << 9, - model: 1 << 10, - colormap: 1 << 11, - skin: 1 << 12, - effects: 1 << 13, - longentity: 1 << 14 -}; - -Protocol.su = { - viewheight: 1, - idealpitch: 1 << 1, - punch1: 1 << 2, - punch2: 1 << 3, - punch3: 1 << 4, - velocity1: 1 << 5, - velocity2: 1 << 6, - velocity3: 1 << 7, - items: 1 << 9, - onground: 1 << 10, - inwater: 1 << 11, - weaponframe: 1 << 12, - armor: 1 << 13, - weapon: 1 << 14 -}; - -Protocol.default_viewheight = 22; - -Protocol.svc = { - nop: 1, - disconnect: 2, - updatestat: 3, - version: 4, - setview: 5, - sound: 6, - time: 7, - print: 8, - stufftext: 9, - setangle: 10, - serverinfo: 11, - lightstyle: 12, - updatename: 13, - updatefrags: 14, - clientdata: 15, - stopsound: 16, - updatecolors: 17, - particle: 18, - damage: 19, - spawnstatic: 20, - spawnbaseline: 22, - temp_entity: 23, - setpause: 24, - signonnum: 25, - centerprint: 26, - killedmonster: 27, - foundsecret: 28, - spawnstaticsound: 29, - intermission: 30, - finale: 31, - cdtrack: 32, - sellscreen: 33, - cutscene: 34 -}; - -Protocol.clc = { - nop: 1, - disconnect: 2, - move: 3, - stringcmd: 4 -}; - -Protocol.te = { - spike: 0, - superspike: 1, - gunshot: 2, - explosion: 3, - tarexplosion: 4, - lightning1: 5, - lightning2: 6, - wizspike: 7, - knightspike: 8, - lightning3: 9, - lavasplash: 10, - teleport: 11, - explosion2: 12, - beam: 13 -}; \ No newline at end of file diff --git a/server.js b/server.js index 0bf4bef..47eef63 100644 --- a/server.js +++ b/server.js @@ -21,7 +21,7 @@ require('./Server/WebQDS/NET_Datagram.js'); require('./Server/WebQDS/NET_WEBS.js'); require('./Server/WebQDS/PF.js'); require('./Server/WebQDS/PR.js'); -require('./Server/WebQDS/Protocol.js'); +require('./Client/WebQuake//Protocol.js'); require('./Server/WebQDS/Q.js'); require('./Server/WebQDS/SV.js'); require('./Server/WebQDS/Sys.js'); From 6ff1e6468eda158c5fe6b6d36adfb66938f10d17 Mon Sep 17 00:00:00 2001 From: Soldy <4786022+Soldy@users.noreply.github.com> Date: Wed, 12 May 2021 10:21:46 +0100 Subject: [PATCH 4/9] duplication remove Signed-off-by: Soldy <4786022+Soldy@users.noreply.github.com> --- Server/WebQDS/CRC.js | 45 ----- Server/WebQDS/Cvar.js | 85 --------- Server/WebQDS/Def.js | 82 --------- Server/WebQDS/ED.js | 393 ------------------------------------------ server.js | 10 +- 5 files changed, 5 insertions(+), 610 deletions(-) delete mode 100644 Server/WebQDS/CRC.js delete mode 100644 Server/WebQDS/Cvar.js delete mode 100644 Server/WebQDS/Def.js delete mode 100644 Server/WebQDS/ED.js diff --git a/Server/WebQDS/CRC.js b/Server/WebQDS/CRC.js deleted file mode 100644 index a3ddfb1..0000000 --- a/Server/WebQDS/CRC.js +++ /dev/null @@ -1,45 +0,0 @@ -CRC = {}; - -CRC.table = [ - 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, - 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef, - 0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6, - 0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de, - 0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485, - 0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d, - 0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4, - 0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc, - 0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823, - 0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b, - 0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12, - 0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a, - 0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41, - 0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49, - 0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70, - 0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78, - 0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f, - 0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067, - 0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e, - 0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256, - 0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d, - 0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405, - 0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c, - 0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634, - 0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab, - 0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3, - 0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a, - 0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92, - 0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9, - 0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1, - 0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8, - 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0 -]; - -CRC.Block = function(start) -{ - var crcvalue = 0xffff; - var i; - for (i = 0; i < start.length; ++i) - crcvalue = ((crcvalue << 8) & 0xffff) ^ CRC.table[(crcvalue >> 8) ^ start[i]]; - return crcvalue; -}; \ No newline at end of file diff --git a/Server/WebQDS/Cvar.js b/Server/WebQDS/Cvar.js deleted file mode 100644 index 422810d..0000000 --- a/Server/WebQDS/Cvar.js +++ /dev/null @@ -1,85 +0,0 @@ -Cvar = {}; - -Cvar.vars = []; - -Cvar.FindVar = function(name) -{ - var i; - for (i = 0; i < Cvar.vars.length; ++i) - { - if (Cvar.vars[i].name === name) - return Cvar.vars[i]; - } -}; - -Cvar.Set = function(name, value) -{ - var i, v, changed; - for (i = 0; i < Cvar.vars.length; ++i) - { - v = Cvar.vars[i]; - if (v.name !== name) - continue; - if (v.string !== value) - changed = true; - v.string = value; - v.value = Q.atof(value); - if ((v.server === true) && (changed === true) && (SV.server.active === true)) - Host.BroadcastPrint('"' + v.name + '" changed to "' + v.string + '"\n'); - return; - } - Con.Print('Cvar.Set: variable ' + name + ' not found\n'); -}; - -Cvar.SetValue = function(name, value) -{ - Cvar.Set(name, value.toFixed(6)); -}; - -Cvar.RegisterVariable = function(name, value, archive, server) -{ - var i; - for (i = 0; i < Cvar.vars.length; ++i) - { - if (Cvar.vars[i].name === name) - { - Con.Print('Can\'t register variable ' + name + ', allready defined\n'); - return; - } - } - Cvar.vars[Cvar.vars.length] = - { - name: name, - string: value, - archive: archive, - server: server, - value: Q.atof(value) - }; - return Cvar.vars[Cvar.vars.length - 1]; -}; - -Cvar.Command = function() -{ - var v = Cvar.FindVar(Cmd.argv[0]); - if (v == null) - return; - if (Cmd.argv.length <= 1) - { - Con.Print('"' + v.name + '" is "' + v.string + '"\n'); - return true; - } - Cvar.Set(v.name, Cmd.argv[1]); - return true; -}; - -Cvar.WriteVariables = function() -{ - var f = [], i, v; - for (i = 0; i < Cvar.vars.length; ++i) - { - v = Cvar.vars[i]; - if (v.archive === true) - f[f.length] = v.name + ' "' + v.string + '"\n'; - } - return f.join(''); -}; \ No newline at end of file diff --git a/Server/WebQDS/Def.js b/Server/WebQDS/Def.js deleted file mode 100644 index f9c7139..0000000 --- a/Server/WebQDS/Def.js +++ /dev/null @@ -1,82 +0,0 @@ -Def = {}; - -Def.timedate = 'Exe: 10:13:04 Dec 8 2013\n'; - -Def.max_edicts = 600; - -Def.stat = { - health: 0, - frags: 1, - weapon: 2, - ammo: 3, - armor: 4, - weaponframe: 5, - shells: 6, - nails: 7, - rockets: 8, - cells: 9, - activeweapon: 10, - totalsecrets: 11, - totalmonsters: 12, - secrets: 13, - monsters: 14 -}; - -Def.it = { - shotgun: 1, - super_shotgun: 2, - nailgun: 4, - super_nailgun: 8, - grenade_launcher: 16, - rocket_launcher: 32, - lightning: 64, - super_lightning: 128, - shells: 256, - nails: 512, - rockets: 1024, - cells: 2048, - axe: 4096, - armor1: 8192, - armor2: 16384, - armor3: 32768, - superhealth: 65536, - key1: 131072, - key2: 262144, - invisibility: 524288, - invulnerability: 1048576, - suit: 2097152, - quad: 4194304 -}; - -Def.rit = { - shells: 128, - nails: 256, - rockets: 512, - cells: 1024, - axe: 2048, - lava_nailgun: 4096, - lava_super_nailgun: 8192, - multi_grenade: 16384, - multi_rocket: 32768, - plasma_gun: 65536, - armor1: 8388608, - armor2: 16777216, - armor3: 33554432, - lava_nails: 67108864, - plasma_ammo: 134217728, - multi_rockets: 268435456, - shield: 536870912, - antigrav: 1073741824, - superhealth: 2147483648 -}; - -Def.hit = { - proximity_gun_bit: 16, - mjolnir_bit: 7, - laser_cannon_bit: 23, - proximity_gun: 65536, - mjolnir: 128, - laser_cannon: 8388608, - wetsuit: 33554432, - empathy_shields: 67108864 -}; \ No newline at end of file diff --git a/Server/WebQDS/ED.js b/Server/WebQDS/ED.js deleted file mode 100644 index 79352ac..0000000 --- a/Server/WebQDS/ED.js +++ /dev/null @@ -1,393 +0,0 @@ -ED = {}; - -ED.ClearEdict = function(e) -{ - var i; - for (i = 0; i < PR.entityfields; ++i) - e.v_int[i] = 0; - e.free = false; -}; - -ED.Alloc = function() -{ - var i, e; - for (i = SV.svs.maxclients + 1; i < SV.server.num_edicts; ++i) - { - e = SV.server.edicts[i]; - if ((e.free === true) && ((e.freetime < 2.0) || ((SV.server.time - e.freetime) > 0.5))) - { - ED.ClearEdict(e); - return e; - } - } - if (i === Def.max_edicts) - Sys.Error('ED.Alloc: no free edicts'); - e = SV.server.edicts[SV.server.num_edicts++]; - ED.ClearEdict(e); - return e; -}; - -ED.Free = function(ed) -{ - SV.UnlinkEdict(ed); - ed.free = true; - ed.v_int[PR.entvars.model] = 0; - ed.v_float[PR.entvars.takedamage] = 0.0; - ed.v_float[PR.entvars.modelindex] = 0.0; - ed.v_float[PR.entvars.colormap] = 0.0; - ed.v_float[PR.entvars.skin] = 0.0; - ed.v_float[PR.entvars.frame] = 0.0; - ED.SetVector(ed, PR.entvars.origin, Vec.origin); - ED.SetVector(ed, PR.entvars.angles, Vec.origin); - ed.v_float[PR.entvars.nextthink] = -1.0; - ed.v_float[PR.entvars.solid] = 0.0; - ed.freetime = SV.server.time; -}; - -ED.GlobalAtOfs = function(ofs) -{ - var i, def; - for (i = 0; i < PR.globaldefs.length; ++i) - { - def = PR.globaldefs[i]; - if (def.ofs === ofs) - return def; - } -}; - -ED.FieldAtOfs = function(ofs) -{ - var i, def; - for (i = 0; i < PR.fielddefs.length; ++i) - { - def = PR.fielddefs[i]; - if (def.ofs === ofs) - return def; - } -}; - -ED.FindField = function(name) -{ - var def, i; - for (i = 0; i < PR.fielddefs.length; ++i) - { - def = PR.fielddefs[i]; - if (PR.GetString(def.name) === name) - return def; - } -}; - -ED.FindGlobal = function(name) -{ - var def, i; - for (i = 0; i < PR.globaldefs.length; ++i) - { - def = PR.globaldefs[i]; - if (PR.GetString(def.name) === name) - return def; - } -}; - -ED.FindFunction = function(name) -{ - var i; - for (i = 0; i < PR.functions.length; ++i) - { - if (PR.GetString(PR.functions[i].name) === name) - return i; - } -}; - -ED.Print = function(ed) -{ - if (ed.free === true) - { - Con.Print('FREE\n'); - return; - } - Con.Print('\nEDICT ' + ed.num + ':\n'); - var i, d, name, v, l; - for (i = 1; i < PR.fielddefs.length; ++i) - { - d = PR.fielddefs[i]; - name = PR.GetString(d.name); - if (name.charCodeAt(name.length - 2) === 95) - continue; - v = d.ofs; - if (ed.v_int[v] === 0) - { - if ((d.type & 0x7fff) === 3) - { - if ((ed.v_int[v + 1] === 0) && (ed.v_int[v + 2] === 0)) - continue; - } - else - continue; - } - for (; name.length <= 14; ) - name += ' '; - Con.Print(name + PR.ValueString(d.type, ed.v, v) + '\n'); - } -}; - -ED.PrintEdicts = function() -{ - if (SV.server.active !== true) - return; - Con.Print(SV.server.num_edicts + ' entities\n'); - var i; - for (i = 0; i < SV.server.num_edicts; ++i) - ED.Print(SV.server.edicts[i]); -}; - -ED.PrintEdict_f = function() -{ - if (SV.server.active !== true) - return; - var i = Q.atoi(Cmd.argv[1]); - if ((i >= 0) && (i < SV.server.num_edicts)) - ED.Print(SV.server.edicts[i]); -}; - -ED.Count = function() -{ - if (SV.server.active !== true) - return; - var i, ent, active = 0, models = 0, solid = 0, step = 0; - for (i = 0; i < SV.server.num_edicts; ++i) - { - ent = SV.server.edicts[i]; - if (ent.free === true) - continue; - ++active; - if (ent.v_float[PR.entvars.solid] !== 0.0) - ++solid; - if (ent.v_int[PR.entvars.model] !== 0) - ++models; - if (ent.v_float[PR.entvars.movetype] === SV.movetype.step) - ++step; - } - var num_edicts = SV.server.num_edicts; - Con.Print('num_edicts:' + (num_edicts <= 9 ? ' ' : (num_edicts <= 99 ? ' ' : '')) + num_edicts + '\n'); - Con.Print('active :' + (active <= 9 ? ' ' : (active <= 99 ? ' ' : '')) + active + '\n'); - Con.Print('view :' + (models <= 9 ? ' ' : (models <= 99 ? ' ' : '')) + models + '\n'); - Con.Print('touch :' + (solid <= 9 ? ' ' : (solid <= 99 ? ' ' : '')) + solid + '\n'); - Con.Print('step :' + (step <= 9 ? ' ' : (step <= 99 ? ' ' : '')) + step + '\n'); -}; - -ED.ParseGlobals = function(data) -{ - var keyname, key; - for (;;) - { - data = COM.Parse(data); - if (COM.token.charCodeAt(0) === 125) - return; - if (data == null) - Sys.Error('ED.ParseGlobals: EOF without closing brace'); - keyname = COM.token; - data = COM.Parse(data); - if (data == null) - Sys.Error('ED.ParseGlobals: EOF without closing brace'); - if (COM.token.charCodeAt(0) === 125) - Sys.Error('ED.ParseGlobals: closing brace without data'); - key = ED.FindGlobal(keyname); - if (key == null) - { - Con.Print('\'' + keyname + '\' is not a global\n'); - continue; - } - if (ED.ParseEpair(PR.globals, key, COM.token) !== true) - Host.Error('ED.ParseGlobals: parse error'); - } -}; - -ED.NewString = function(string) -{ - var newstring = [], i, c; - for (i = 0; i < string.length; ++i) - { - c = string.charCodeAt(i); - if ((c === 92) && (i < (string.length - 1))) - { - ++i; - newstring[newstring.length] = (string.charCodeAt(i) === 110) ? '\n' : '\\'; - } - else - newstring[newstring.length] = String.fromCharCode(c); - } - return PR.NewString(newstring.join(''), string.length + 1); -}; - -ED.ParseEpair = function(base, key, s) -{ - var d_float = new Float32Array(base); - var d_int = new Int32Array(base); - var d, v; - switch (key.type & 0x7fff) - { - case PR.etype.ev_string: - d_int[key.ofs] = ED.NewString(s); - return true; - case PR.etype.ev_float: - d_float[key.ofs] = Q.atof(s); - return true; - case PR.etype.ev_vector: - v = s.split(' '); - d_float[key.ofs] = Q.atof(v[0]); - d_float[key.ofs + 1] = Q.atof(v[1]); - d_float[key.ofs + 2] = Q.atof(v[2]); - return true; - case PR.etype.ev_entity: - d_int[key.ofs] = Q.atoi(s); - return true; - case PR.etype.ev_field: - d = ED.FindField(s); - if (d == null) - { - Con.Print('Can\'t find field ' + s + '\n'); - return; - } - d_int[key.ofs] = d.ofs; - return true; - case PR.etype.ev_function: - d = ED.FindFunction(s); - if (d == null) - { - Con.Print('Can\'t find function ' + s + '\n'); - return; - } - d_int[key.ofs] = d; - } - return true; -}; - -ED.ParseEdict = function(data, ent) -{ - var i, init, anglehack, keyname, n, key; - if (ent !== SV.server.edicts[0]) - { - for (i = 0; i < PR.entityfields; ++i) - ent.v_int[i] = 0; - } - for (;;) - { - data = COM.Parse(data); - if (COM.token.charCodeAt(0) === 125) - break; - if (data == null) - Sys.Error('ED.ParseEdict: EOF without closing brace'); - if (COM.token === 'angle') - { - COM.token = 'angles'; - anglehack = true; - } - else - { - anglehack = false; - if (COM.token === 'light') - COM.token = 'light_lev'; - } - for (n = COM.token.length; n > 0; --n) - { - if (COM.token.charCodeAt(n - 1) !== 32) - break; - } - keyname = COM.token.substring(0, n); - data = COM.Parse(data); - if (data == null) - Sys.Error('ED.ParseEdict: EOF without closing brace'); - if (COM.token.charCodeAt(0) === 125) - Sys.Error('ED.ParseEdict: closing brace without data'); - init = true; - if (keyname.charCodeAt(0) === 95) - continue; - key = ED.FindField(keyname); - if (key == null) - { - Con.Print('\'' + keyname + '\' is not a field\n'); - continue; - } - if (anglehack == true) - COM.token = '0 ' + COM.token + ' 0'; - if (ED.ParseEpair(ent.v, key, COM.token) !== true) - Host.Error('ED.ParseEdict: parse error'); - } - if (init !== true) - ent.free = true; - return data; -}; - -ED.LoadFromFile = function(data) -{ - var ent, spawnflags, inhibit = 0, func; - PR.globals_float[PR.globalvars.time] = SV.server.time; - - for (;;) - { - data = COM.Parse(data); - if (data == null) - break; - if (COM.token.charCodeAt(0) !== 123) - Sys.Error('ED.LoadFromFile: found ' + COM.token + ' when expecting {'); - - if (ent == null) - ent = SV.server.edicts[0]; - else - ent = ED.Alloc(); - data = ED.ParseEdict(data, ent); - - spawnflags = ent.v_float[PR.entvars.spawnflags] >> 0; - if (Host.deathmatch.value !== 0) - { - if ((spawnflags & 2048) !== 0) - { - ED.Free(ent); - ++inhibit; - continue; - } - } - else if (((Host.current_skill === 0) && ((spawnflags & 256) !== 0)) - || ((Host.current_skill === 1) && ((spawnflags & 512) !== 0)) - || ((Host.current_skill >= 2) && ((spawnflags & 1024) !== 0))) - { - ED.Free(ent); - ++inhibit; - continue; - } - - if (ent.v_int[PR.entvars.classname] === 0) - { - Con.Print('No classname for:\n'); - ED.Print(ent); - ED.Free(ent); - continue; - } - - func = ED.FindFunction(PR.GetString(ent.v_int[PR.entvars.classname])); - if (func == null) - { - Con.Print('No spawn function for:\n'); - ED.Print(ent); - ED.Free(ent); - continue; - } - - PR.globals_int[PR.globalvars.self] = ent.num; - PR.ExecuteProgram(func); - } - - Con.DPrint(inhibit + ' entities inhibited\n'); -}; - -ED.Vector = function(e, o) -{ - return [e.v_float[o], e.v_float[o + 1], e.v_float[o + 2]]; -}; - -ED.SetVector = function(e, o, v) -{ - e.v_float[o] = v[0]; - e.v_float[o + 1] = v[1]; - e.v_float[o + 2] = v[2]; -}; \ No newline at end of file diff --git a/server.js b/server.js index 47eef63..1aa0b46 100644 --- a/server.js +++ b/server.js @@ -9,10 +9,10 @@ Node = { require('./Server/WebQDS/Cmd.js'); require('./Server/WebQDS/COM.js'); require('./Server/WebQDS/Console.js'); -require('./Server/WebQDS/CRC.js'); -require('./Server/WebQDS/Cvar.js'); -require('./Server/WebQDS/Def.js'); -require('./Server/WebQDS/ED.js'); +require('./Client/WebQuake/CRC.js'); +require('./Client/WebQuake/Cvar.js'); +require('./Client/WebQuake/Def.js'); +require('./Client/WebQuake/ED.js'); require('./Server/WebQDS/Host.js'); require('./Server/WebQDS/Mod.js'); require('./Server/WebQDS/MSG.js'); @@ -21,7 +21,7 @@ require('./Server/WebQDS/NET_Datagram.js'); require('./Server/WebQDS/NET_WEBS.js'); require('./Server/WebQDS/PF.js'); require('./Server/WebQDS/PR.js'); -require('./Client/WebQuake//Protocol.js'); +require('./Client/WebQuake/Protocol.js'); require('./Server/WebQDS/Q.js'); require('./Server/WebQDS/SV.js'); require('./Server/WebQDS/Sys.js'); From 32fb17deaa81a93c6bd63464415f40245b315442 Mon Sep 17 00:00:00 2001 From: Soldy <4786022+Soldy@users.noreply.github.com> Date: Thu, 13 May 2021 22:10:37 +0100 Subject: [PATCH 5/9] implement S.play function Signed-off-by: Soldy <4786022+Soldy@users.noreply.github.com> --- Client/WebQuake/SC.js | 107 +++++++++++++++++++++++++++--------------- 1 file changed, 69 insertions(+), 38 deletions(-) diff --git a/Client/WebQuake/SC.js b/Client/WebQuake/SC.js index 4cf05ad..4e81951 100644 --- a/Client/WebQuake/SC.js +++ b/Client/WebQuake/SC.js @@ -1,19 +1,19 @@ const sClass = function(){ this.Init=function(){ - init(); + _init(); }; this.PrecacheSound = function(name){ if (this.nosound !== 0) return name; if (this.precache === 0) return name; - return precacheSound(name); + return _precacheSound(name); }; this.LoadSound = function(source){ if (this.nosound.value !== 0) return; - return loadSound(source); + return _loadSound(source); }; this.SounList = function(){ for(let i in sfxs) @@ -27,7 +27,7 @@ const sClass = function(){ ); }; this.StartSound = function(entnum, entchannel, sfx, origin, vol, attenuation){ - startSound(entnum, entchannel, sfx, origin, vol, attenuation); + _startSound(entnum, entchannel, sfx, origin, vol, attenuation); } this.StartAmbient = function(name){ return startAmbient(name); @@ -39,7 +39,7 @@ const sClass = function(){ return out; } this.LocalSound = function(sound){ - startSound( + _startSound( CL.state.viewentity, 1, sound, @@ -53,15 +53,9 @@ const sClass = function(){ } this.StopSound = function(etnum, etchannel){ stopSound(etnum, etchannel); - } - this.Play = function(){ - - } - this.PlayVol = function(){ - } this.StaticSound = async function(sfx, origin, vol, attenuation){ - await startSound( + await _startSound( "static", staticSerial, sfx, @@ -86,11 +80,11 @@ const sClass = function(){ activeChannels.splice(i, 1); continue; } - spatialize( + _spatialize( activeChannels[i].entnum, activeChannels[i].entchannel ); - channelVolume( + _channelVolume( activeChannels[i].entnum, activeChannels[i].entchannel ); @@ -108,7 +102,6 @@ const sClass = function(){ else if (volume.value > 1.0) Cvar.SetValue('volume', 1.0); } - this.Spatialize = function(ch){} this.size = 0; this.bgmvolume = 0; this.volume = 0; @@ -116,7 +109,6 @@ const sClass = function(){ this.ambient_fade = 100; this.precache = 1; this.nosound = 0; - this.static_channels = []; this.known_sfx = []; this.started = false; let staticSerial = 0; @@ -129,10 +121,10 @@ const sClass = function(){ let listener_up = [0.0, 0.0, 0.0]; let sfxs = {}; let audioCTX; - let init = async function(){ + const _init = async function(){ Con.Print('\nSound Initialization\n'); - Cmd.AddCommand('play', S.Play); - Cmd.AddCommand('playvol', S.PlayVol); + Cmd.AddCommand('play', _playCommand); + Cmd.AddCommand('playvol', _playCommand); Cmd.AddCommand('stopsound', S.StopAllSounds); Cmd.AddCommand('soundlist', S.SoundList); this.nosound = Cvar.RegisterVariable( @@ -173,10 +165,7 @@ const sClass = function(){ startAmbient('ambience/' + i + '.wav'); } - let upldate = function(){ - - } - let spatialize = function(en, ec){ + const _spatialize = function(en, ec){ if(en === CL.state.viewentity){ channels[en].sub[ec].volLeft = channels[en].sub[ec].vol; channels[en].sub[ec].volRight = channels[en].sub[ec].vol; @@ -195,7 +184,7 @@ const sClass = function(){ source[2] /= dist; } dist *= (channels[en].sub[ec].mult*0.4); - var dot = listener_right[0] * source[0] + const dot = listener_right[0] * source[0] + listener_right[1] * source[1] + listener_right[2] * source[2]; channels[en].sub[ec].volRight = channels[en].sub[ec].vol * (1.0 - dist) * (1.0 + dot); @@ -209,18 +198,59 @@ const sClass = function(){ if (channels[en].sub[ec].volLeft > 1.0) channels[en].sub[ec].volLeft = 1.0; } - let channelVolume = function(en,ec){ + const _channelVolume = function(en,ec){ channels[en].sub[ec].g1.gain.value = channels[en].sub[ec].volLeft * volume.value; channels[en].sub[ec].g2.gain.value = channels[en].sub[ec].volRight * volume.value; } - let startSound = async function(entnum, entchannel, sfx, origin, vol, attenuation){ + const _playCommand = function(){ + const [command, ...list] = Cmd.argv; + if (this.nosound.value !== 0) + return; + if (command === 'playVol') + return _playVol(list); + _play(list); + } + const _play = function(list){ + let sfx; + for (let i of list){ + sfx = _precacheSound(COM.DefaultExtension(i, '.wav')); + if(sfx != null) + _startSound( + CL.state.viewentity, + 0, + sfx, + listener_originm + 1.0, + 1.0 + ); + } + + } + const _playVol = function(list){ + let sfx; + for (let i = 0; i < list; i+=2){ + sfx = _precacheSound(COM.DefaultExtension(list[i], '.wav')); + if(sfx != null) + _startSound( + CL.state.viewentity, + 0, + sfx, + listener_originm + Q.atof( + list[i+1], + ), + 1.0 + ); + } + } + const _startSound = async function(entnum, entchannel, sfx, origin, vol, attenuation){ pickChannel(entnum, entchannel); - await loadSound(sfx); + await _loadSound(sfx); channels[entnum].sub[entchannel].vol = vol; channels[entnum].sub[entchannel].mult = attenuation * 0.001; - spatialize(entnum, entchannel); + _spatialize(entnum, entchannel); if ( (channels[entnum].sub[entchannel].volLeft === 0.0)&& (channels[entnum].sub[entchannel].volRight === 0.0) @@ -235,7 +265,6 @@ const sClass = function(){ }); } channels[entnum].sub[entchannel].sx.buffer = sfxs[sfx].cache; -// channels[entnum].sub[entchannel].sx.connect(audioCTX.destination); channels[entnum].sub[entchannel].end = Host.realtime + sfxs[sfx].cache.length; channels[entnum].sub[entchannel].sx.connect( channels[entnum].sub[entchannel].m1 @@ -261,38 +290,40 @@ const sClass = function(){ channels[entnum].sub[entchannel].m2.connect( audioCTX.destination ); - channelVolume(entnum,entchannel); + _channelVolume(entnum,entchannel); return channels[entnum].sub[entchannel].sx.start(); } let startAmbient = async (sfx)=>{ try{ ambient_channels[sfx].stop(); - }catch(e){}; - loadSound(sfx); + }catch(e){ + console.error(e); + }; + _loadSound(sfx); ambient_channels[sfx] = audioCTX.createBufferSource(); ambient_channels[sfx].loop = true ; ambient_channels[sfx].connect(audioCTX.destination); setTimeout(function(){ try{ console.info(sfx); - ambient_channels[sfx].buffer = sfxs[sfx].cache; - ambient_channels[sfx].start(); + ambient_channels[sfx].buffer = sfxs[sfx].cache; + ambient_channels[sfx].start(); }catch(e){ console.error(e); } },2000); } - let startAmbientAll = function(){ + const _startAmbientAll = function(){ for (let i in ambient_channels) startAmbient(i); } - let precacheSound = function(name){ + const _precacheSound = function(name){ if(typeof sfxs[name] === "undefined") sfxs[name] = {name: name}; - loadSound(name); + _loadSound(name); return name; } - let loadSound = async function(name){ + const _loadSound = async function(name){ if (sfxs[name] == null) sfxs[name] = { name : name, From f6f58429094050b1b74bff007fb4522664e96ecd Mon Sep 17 00:00:00 2001 From: Soldy <4786022+Soldy@users.noreply.github.com> Date: Thu, 13 May 2021 23:20:40 +0100 Subject: [PATCH 6/9] duplication Signed-off-by: Soldy <4786022+Soldy@users.noreply.github.com> --- Server/WebQDS/Sys.js | 49 -------------------------------------------- server.js | 14 ++++++------- 2 files changed, 7 insertions(+), 56 deletions(-) delete mode 100644 Server/WebQDS/Sys.js diff --git a/Server/WebQDS/Sys.js b/Server/WebQDS/Sys.js deleted file mode 100644 index 389f030..0000000 --- a/Server/WebQDS/Sys.js +++ /dev/null @@ -1,49 +0,0 @@ -Sys = {}; - -Sys.Quit = function() -{ - process.exit(0); -}; - -Sys.Print = function(text) -{ - process.stdout.write(text); -}; - -Sys.Error = function(text) -{ - console.log(text); - throw new Error(text); -}; - -Sys.FloatTime = function() -{ - var time = process.hrtime(Sys.oldtime); - return time[0] + (time[1] / 1000000000.0); -}; - -Sys.cmd = ''; -Sys.ConsoleInput = function() -{ - var text = Sys.cmd; - if (text.length === 0) - return; - Sys.cmd = ''; - return text; -}; - -Sys.main = function() -{ - COM.InitArgv(process.argv.slice(1)); - Sys.oldtime = process.hrtime(); - Sys.Print('Host.Init\n'); - Host.Init(); - process.stdin.resume(); - process.stdin.on('data', Sys.StdinOnData); - process.nextTick(Host.Frame); -}; - -Sys.StdinOnData = function(data) -{ - Sys.cmd += Q.memstr(data); -}; \ No newline at end of file diff --git a/server.js b/server.js index 1aa0b46..a844add 100644 --- a/server.js +++ b/server.js @@ -1,10 +1,10 @@ Node = { - dgram: require('dgram'), - fs: require('fs'), - http: require('http'), - os: require('os'), - url: require('url'), - websocket: require('websocket') + fs: require('fs'), + os: require('os'), + url: require('url'), + http: require('http'), + dgram: require('dgram'), + websocket: require('websocket') }; require('./Server/WebQDS/Cmd.js'); require('./Server/WebQDS/COM.js'); @@ -25,7 +25,7 @@ require('./Client/WebQuake/Protocol.js'); require('./Server/WebQDS/Q.js'); require('./Server/WebQDS/SV.js'); require('./Server/WebQDS/Sys.js'); -require('./Server/WebQDS/SZ.js'); +require('./Client/WebQuake/SZ.js'); require('./Server/WebQDS/V.js'); require('./Server/WebQDS/Vec.js'); Sys.main(); From 427b3852b194970a8dd45fb0316e56735f6ef44f Mon Sep 17 00:00:00 2001 From: Soldy <4786022+Soldy@users.noreply.github.com> Date: Sun, 13 Jun 2021 22:18:50 +0100 Subject: [PATCH 7/9] add class sys Signed-off-by: Soldy <4786022+Soldy@users.noreply.github.com> --- Server/WebQDS/Sys.js | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Server/WebQDS/Sys.js diff --git a/Server/WebQDS/Sys.js b/Server/WebQDS/Sys.js new file mode 100644 index 0000000..e4a3d31 --- /dev/null +++ b/Server/WebQDS/Sys.js @@ -0,0 +1,37 @@ +const sysClass = function(){ + this.Quit = function(){ + process.exit(0); + }; + this.Print = function(text) { + process.stdout.write(text); + }; + this.Error = function(text) { + throw new Error(text); + }; + this.FloatTime = function() { + let time = process.hrtime(oldtime); + return time[0] + (time[1] / 1000000000.0); + }; + this.ConsoleInput = function(){ + if (cmd.length === 0) + return; + const text = cmd.toString(); + cmd = ''; + return text; + }; + this.main = function() { + COM.InitArgv(process.argv.slice(1)); + oldtime = process.hrtime(); + Sys.Print('Host.Init\n'); + Host.Init(); + process.stdin.resume(); + process.stdin.on('data', Sys.StdinOnData); + process.nextTick(Host.Frame); + }; + this.StdinOnData = function(data){ + cmd += Q.memstr(data); + }; + let cmd = ''; + let oldtime = process.hrtime(); +} +const Sys = new sysClass(); From 1682e219876bc7b4168e60731b93bc274f334f67 Mon Sep 17 00:00:00 2001 From: Soldy <4786022+Soldy@users.noreply.github.com> Date: Fri, 1 Oct 2021 22:00:22 +0100 Subject: [PATCH 8/9] remove old audio Signed-off-by: Soldy <4786022+Soldy@users.noreply.github.com> --- Client/WebQuake/S.js | 825 ------------------------------------------- Client/index.htm | 6 +- 2 files changed, 4 insertions(+), 827 deletions(-) delete mode 100644 Client/WebQuake/S.js diff --git a/Client/WebQuake/S.js b/Client/WebQuake/S.js deleted file mode 100644 index 9fc30d3..0000000 --- a/Client/WebQuake/S.js +++ /dev/null @@ -1,825 +0,0 @@ -S = {}; - -S.channels = []; -S.static_channels = []; -S.ambient_channels = []; - -S.listener_origin = [0.0, 0.0, 0.0]; -S.listener_forward = [0.0, 0.0, 0.0]; -S.listener_right = [0.0, 0.0, 0.0]; -S.listener_up = [0.0, 0.0, 0.0]; - -S.known_sfx = []; - -S.Init = function() -{ - Con.Print('\nSound Initialization\n'); - Cmd.AddCommand('play', S.Play); - Cmd.AddCommand('playvol', S.PlayVol); - Cmd.AddCommand('stopsound', S.StopAllSounds); - Cmd.AddCommand('soundlist', S.SoundList); - S.nosound = Cvar.RegisterVariable('nosound', (COM.CheckParm('-nosound') != null) ? '1' : '0'); - S.volume = Cvar.RegisterVariable('volume', '0.7', true); - S.precache = Cvar.RegisterVariable('precache', '1'); - S.bgmvolume = Cvar.RegisterVariable('bgmvolume', '1', true); - S.ambient_level = Cvar.RegisterVariable('ambient_level', '0.3'); - S.ambient_fade = Cvar.RegisterVariable('ambient_fade', '100'); - - S.started = true; - - // createBuffer is broken, disable Web Audio for now. - /* if (window.AudioContext != null)) - S.context = new AudioContext(); - else if (window.webkitAudioContext != null) - S.context = new webkitAudioContext(); */ - - var i, ambient_sfx = ['water1', 'wind2'], ch, nodes; - for (i = 0; i < ambient_sfx.length; ++i) - { - ch = {sfx: S.PrecacheSound('ambience/' + ambient_sfx[i] + '.wav'), end: 0.0, master_vol: 0.0}; - S.ambient_channels[i] = ch; - if (S.LoadSound(ch.sfx) !== true) - continue; - if (ch.sfx.cache.loopstart == null) - { - Con.Print('Sound ambience/' + ch.sfx.name + '.wav not looped\n'); - continue; - } - if (S.context != null) - { - nodes = { - source: S.context.createBufferSource(), - gain: S.context.createGainNode() - }; - ch.nodes = nodes; - nodes.source.buffer = ch.sfx.cache.data; - nodes.source.loop = true; - nodes.source.loopStart = ch.sfx.cache.loopstart; - nodes.source.loopEnd = nodes.source.buffer.length; - nodes.source.connect(nodes.gain); - nodes.gain.connect(S.context.destination); - } - else - ch.audio = ch.sfx.cache.data.cloneNode(); - } - - Con.sfx_talk = S.PrecacheSound('misc/talk.wav'); -}; - -S.NoteOff = function(node) -{ - if ((node.playbackState === 1) || (node.playbackState === 2)) - { - try { node.noteOff(0.0); } catch (e) {} - } -} - -S.NoteOn = function(node) -{ - if ((node.playbackState === 0) || (node.playbackState === 3)) - { - try { node.noteOn(0.0); } catch (e) {} - } -} - -S.PrecacheSound = function(name) -{ - if (S.nosound.value !== 0) - return; - var i, sfx; - for (i = 0; i < S.known_sfx.length; ++i) - { - if (S.known_sfx[i].name === name) - { - sfx = S.known_sfx[i]; - break; - } - } - if (i === S.known_sfx.length) - { - S.known_sfx[i] = {name: name}; - sfx = S.known_sfx[i]; - } - if (S.precache.value !== 0) - S.LoadSound(sfx); - return sfx; -}; - -S.PickChannel = function(entnum, entchannel) -{ - var i, channel; - - if (entchannel !== 0) - { - for (i = 0; i < S.channels.length; ++i) - { - channel = S.channels[i]; - if (channel == null) - continue; - if ((channel.entnum === entnum) && ((channel.entchannel === entchannel) || (entchannel === -1))) - { - channel.sfx = null; - if (channel.nodes != null) - { - S.NoteOff(channel.nodes.source); - channel.nodes = null; - } - else if (channel.audio != null) - { - channel.audio.pause(); - channel.audio = null; - } - break; - } - } - } - - if ((entchannel === 0) || (i === S.channels.length)) - { - for (i = 0; i < S.channels.length; ++i) - { - channel = S.channels[i]; - if (channel == null) - break; - if (channel.sfx == null) - break; - } - } - - if (i === S.channels.length) - { - S.channels[i] = {end: 0.0}; - return S.channels[i]; - } - return channel; -}; - -S.Spatialize = function(ch) -{ - if (ch.entnum === CL.state.viewentity) - { - ch.leftvol = ch.master_vol; - ch.rightvol = ch.master_vol; - return; - } - - var source = [ - ch.origin[0] - S.listener_origin[0], - ch.origin[1] - S.listener_origin[1], - ch.origin[2] - S.listener_origin[2] - ]; - var dist = Math.sqrt(source[0] * source[0] + source[1] * source[1] + source[2] * source[2]); - if (dist !== 0.0) - { - source[0] /= dist; - source[1] /= dist; - source[2] /= dist; - } - dist *= ch.dist_mult; - var dot = S.listener_right[0] * source[0] - + S.listener_right[1] * source[1] - + S.listener_right[2] * source[2]; - - ch.rightvol = ch.master_vol * (1.0 - dist) * (1.0 + dot); - if (ch.rightvol < 0.0) - ch.rightvol = 0.0; - ch.leftvol = ch.master_vol * (1.0 - dist) * (1.0 - dot); - if (ch.leftvol < 0.0) - ch.leftvol = 0.0; -}; - -S.StartSound = function(entnum, entchannel, sfx, origin, vol, attenuation) -{ - if ((S.nosound.value !== 0) || (sfx == null)) - return; - - var target_chan = S.PickChannel(entnum, entchannel); - target_chan.origin = [origin[0], origin[1], origin[2]]; - target_chan.dist_mult = attenuation * 0.001; - target_chan.master_vol = vol; - target_chan.entnum = entnum; - target_chan.entchannel = entchannel; - S.Spatialize(target_chan); - if ((target_chan.leftvol === 0.0) && (target_chan.rightvol === 0.0)) - return; - - if (S.LoadSound(sfx) !== true) - { - target_chan.sfx = null; - return; - } - - target_chan.sfx = sfx; - target_chan.pos = 0.0; - target_chan.end = Host.realtime + sfx.cache.length; - var volume; - if (S.context != null) - { - var nodes = { - source: S.context.createBufferSource(), - merger1: S.context.createChannelMerger(2), - splitter: S.context.createChannelSplitter(2), - gain0: S.context.createGainNode(), - gain1: S.context.createGainNode(), - merger2: S.context.createChannelMerger(2) - }; - target_chan.nodes = nodes; - nodes.source.buffer = sfx.cache.data; - if (sfx.cache.loopstart != null) - { - nodes.source.loop = true; - nodes.source.loopStart = sfx.cache.loopstart; - nodes.source.loopEnd = nodes.source.buffer.length; - } - nodes.source.connect(nodes.merger1); - nodes.source.connect(nodes.merger1, 0, 1); - nodes.merger1.connect(nodes.splitter); - nodes.splitter.connect(nodes.gain0, 0); - nodes.splitter.connect(nodes.gain1, 1); - volume = target_chan.leftvol; - if (volume > 1.0) - volume = 1.0; - nodes.gain0.gain.value = volume * S.volume.value; - nodes.gain0.connect(nodes.merger2, 0, 0); - volume = target_chan.rightvol; - if (volume > 1.0) - volume = 1.0; - nodes.gain1.gain.value = volume * S.volume.value; - nodes.gain1.connect(nodes.merger2, 0, 1); - nodes.merger2.connect(S.context.destination); - var i, check, skip; - for (i = 0; i < S.channels.length; ++i) - { - check = S.channels[i]; - if (check === target_chan) - continue; - if ((check.sfx !== sfx) || (check.pos !== 0.0)) - continue; - skip = Math.random() * 0.1; - if (skip >= sfx.cache.length) - { - S.NoteOn(nodes.source); - break; - } - target_chan.pos += skip; - target_chan.end -= skip; - nodes.source.noteGrainOn(0.0, skip, nodes.source.buffer.length - skip); - break; - } - S.NoteOn(nodes.source); - } - else - { - target_chan.audio = sfx.cache.data.cloneNode(); - volume = (target_chan.leftvol + target_chan.rightvol) * 0.5; - if (volume > 1.0) - volume = 1.0; - target_chan.audio.volume = volume * S.volume.value; - target_chan.audio.play(); - } -}; - -S.StopSound = function(entnum, entchannel) -{ - if (S.nosound.value !== 0) - return; - var i, ch; - for (i = 0; i < S.channels.length; ++i) - { - ch = S.channels[i]; - if (ch == null) - continue; - if ((ch.entnum === entnum) && (ch.entchannel === entchannel)) - { - ch.end = 0.0; - ch.sfx = null; - if (ch.nodes != null) - { - S.NoteOff(ch.nodes.source); - ch.nodes = null; - } - else if (ch.audio != null) - { - ch.audio.pause(); - ch.audio = null; - } - return; - } - } -}; - -S.StopAllSounds = function() -{ - if (S.nosound.value !== 0) - return; - - var i, ch; - - for (i = 0; i < S.ambient_channels.length; ++i) - { - ch = S.ambient_channels[i]; - ch.master_vol = 0.0; - if (ch.nodes != null) - S.NoteOff(ch.nodes.source); - else if (ch.audio != null) - ch.audio.pause(); - } - - for (i = 0; i < S.channels.length; ++i) - { - ch = S.channels[i]; - if (ch == null) - continue; - if (ch.nodes != null) - S.NoteOff(ch.nodes.source); - else if (ch.audio != null) - ch.audio.pause(); - } - S.channels = []; - - if (S.context != null) - { - for (i = 0; i < S.static_channels.length; ++i) - S.NoteOff(S.static_channels[i].nodes.source); - } - else - { - for (i = 0; i < S.static_channels.length; ++i) - S.static_channels[i].audio.pause(); - } - S.static_channels = []; -}; - -S.StaticSound = function(sfx, origin, vol, attenuation) -{ - if ((S.nosound.value !== 0) || (sfx == null)) - return; - if (S.LoadSound(sfx) !== true) - return; - if (sfx.cache.loopstart == null) - { - Con.Print('Sound ' + sfx.name + ' not looped\n'); - return; - } - var ss = { - sfx: sfx, - origin: [origin[0], origin[1], origin[2]], - master_vol: vol, - dist_mult: attenuation * 0.000015625, - end: Host.realtime + sfx.cache.length - }; - S.static_channels[S.static_channels.length] = ss; - if (S.context != null) - { - var nodes = { - source: S.context.createBufferSource(), - merger1: S.context.createChannelMerger(2), - splitter: S.context.createChannelSplitter(2), - gain0: S.context.createGainNode(), - gain1: S.context.createGainNode(), - merger2: S.context.createChannelMerger(2) - }; - ss.nodes = nodes; - nodes.source.buffer = sfx.cache.data; - nodes.source.loop = true; - nodes.source.loopStart = sfx.cache.loopstart; - nodes.source.loopEnd = nodes.source.buffer.length; - nodes.source.connect(nodes.merger1); - nodes.source.connect(nodes.merger1, 0, 1); - nodes.merger1.connect(nodes.splitter); - nodes.splitter.connect(nodes.gain0, 0); - nodes.splitter.connect(nodes.gain1, 1); - nodes.gain0.connect(nodes.merger2, 0, 0); - nodes.gain1.connect(nodes.merger2, 0, 1); - nodes.merger2.connect(S.context.destination); - } - else - { - ss.audio = sfx.cache.data.cloneNode(); - ss.audio.pause(); - } -}; - -S.SoundList = function() -{ - var total = 0, i, sfx, sc, size; - for (i = 0; i < S.known_sfx.length; ++i) - { - sfx = S.known_sfx[i]; - sc = sfx.cache; - if (sc == null) - continue; - size = sc.size.toString(); - total += sc.size; - for (; size.length <= 5; ) - size = ' ' + size; - if (sc.loopstart != null) - size = 'L' + size; - else - size = ' ' + size; - Con.Print(size + ' : ' + sfx.name + '\n'); - } - Con.Print('Total resident: ' + total + '\n'); -}; - -S.LocalSound = function(sound) -{ - S.StartSound(CL.state.viewentity, -1, sound, Vec.origin, 1.0, 1.0); -}; - -S.UpdateAmbientSounds = function() -{ - if (CL.state.worldmodel == null) - return; - - var i, ch, vol, sc; - - var l = Mod.PointInLeaf(S.listener_origin, CL.state.worldmodel); - if ((l == null) || (S.ambient_level.value === 0)) - { - for (i = 0; i < S.ambient_channels.length; ++i) - { - ch = S.ambient_channels[i]; - ch.master_vol = 0.0; - if (ch.nodes != null) - { - S.NoteOff(ch.nodes.source); - } - else if (ch.audio != null) - { - if (ch.audio.paused !== true) - ch.audio.pause(); - } - } - return; - } - - for (i = 0; i < S.ambient_channels.length; ++i) - { - ch = S.ambient_channels[i]; - if ((ch.nodes == null) && (ch.audio == null)) - continue; - vol = S.ambient_level.value * l.ambient_level[i]; - if (vol < 8.0) - vol = 0.0; - vol /= 255.0; - if (ch.master_vol < vol) - { - ch.master_vol += (Host.frametime * S.ambient_fade.value) / 255.0; - if (ch.master_vol > vol) - ch.master_vol = vol; - } - else if (ch.master_vol > vol) - { - ch.master_vol -= (Host.frametime * S.ambient_fade.value) / 255.0; - if (ch.master_vol < vol) - ch.master_vol = vol; - } - - if (ch.master_vol === 0.0) - { - if (S.context != null) - { - S.NoteOff(ch.nodes.source); - } - else - { - if (ch.audio.paused !== true) - ch.audio.pause(); - } - continue; - } - if (ch.master_vol > 1.0) - ch.master_vol = 1.0; - if (S.context != null) - { - ch.nodes.gain.gain.value = ch.master_vol * S.volume.value; - S.NoteOn(ch.nodes.source); - } - else - { - ch.audio.volume = ch.master_vol * S.volume.value; - sc = ch.sfx.cache; - if (ch.audio.paused === true) - { - ch.audio.play(); - ch.end = Host.realtime + sc.length; - continue; - } - if (Host.realtime >= ch.end) - { - try - { - ch.audio.currentTime = sc.loopstart; - } - catch (e) - { - ch.end = Host.realtime; - continue; - } - ch.end = Host.realtime + sc.length - sc.loopstart; - } - } - } -}; - -S.UpdateDynamicSounds = function() -{ - var i, ch, sc, volume; - for (i = 0; i < S.channels.length; ++i) - { - ch = S.channels[i]; - if (ch == null) - continue; - if (ch.sfx == null) - continue; - if (Host.realtime >= ch.end) - { - sc = ch.sfx.cache; - if (sc.loopstart != null) - { - if (S.context == null) - { - try - { - ch.audio.currentTime = sc.loopstart; - } - catch (e) - { - ch.end = Host.realtime; - continue; - } - } - ch.end = Host.realtime + sc.length - sc.loopstart; - } - else - { - ch.sfx = null; - ch.nodes = null; - ch.audio = null; - continue; - } - } - S.Spatialize(ch); - if (S.context != null) - { - if (ch.leftvol > 1.0) - ch.leftvol = 1.0; - if (ch.rightvol > 1.0) - ch.rightvol = 1.0; - ch.nodes.gain0.gain.volume = ch.leftvol * S.volume.value; - ch.nodes.gain1.gain.volume = ch.rightvol * S.volume.value; - } - else - { - volume = (ch.leftvol + ch.rightvol) * 0.5; - if (volume > 1.0) - volume = 1.0; - ch.audio.volume = volume * S.volume.value; - } - } -}; - -S.UpdateStaticSounds = function() -{ - var i, j, ch, ch2, sfx, sc, volume; - - for (i = 0; i < S.static_channels.length; ++i) - S.Spatialize(S.static_channels[i]); - - for (i = 0; i < S.static_channels.length; ++i) - { - ch = S.static_channels[i]; - if ((ch.leftvol === 0.0) && (ch.rightvol === 0.0)) - continue; - sfx = ch.sfx; - for (j = i + 1; j < S.static_channels.length; ++j) - { - ch2 = S.static_channels[j]; - if (sfx === ch2.sfx) - { - ch.leftvol += ch2.leftvol; - ch.rightvol += ch2.rightvol; - ch2.leftvol = 0.0; - ch2.rightvol = 0.0; - } - } - } - - if (S.context != null) - { - for (i = 0; i < S.static_channels.length; ++i) - { - ch = S.static_channels[i]; - if ((ch.leftvol === 0.0) && (ch.rightvol === 0.0)) - { - S.NoteOff(ch.nodes.source); - continue; - } - if (ch.leftvol > 1.0) - ch.leftvol = 1.0; - if (ch.rightvol > 1.0) - ch.rightvol = 1.0; - ch.nodes.gain0.gain.value = ch.leftvol * S.volume.value; - ch.nodes.gain1.gain.value = ch.rightvol * S.volume.value; - S.NoteOn(ch.nodes.source); - } - } - else - { - for (i = 0; i < S.static_channels.length; ++i) - { - ch = S.static_channels[i]; - volume = (ch.leftvol + ch.rightvol) * 0.5; - if (volume > 1.0) - volume = 1.0; - if (volume === 0.0) - { - if (ch.audio.paused !== true) - ch.audio.pause(); - continue; - } - ch.audio.volume = volume * S.volume.value; - sc = ch.sfx.cache; - if (ch.audio.paused === true) - { - ch.audio.play(); - ch.end = Host.realtime + sc.length; - continue; - } - if (Host.realtime >= ch.end) - { - try - { - ch.audio.currentTime = sc.loopstart; - } - catch (e) - { - ch.end = Host.realtime; - continue; - } - } - } - } -}; - -S.Update = function(origin, forward, right, up) -{ - if (S.nosound.value !== 0) - return; - - S.listener_origin[0] = origin[0]; - S.listener_origin[1] = origin[1]; - S.listener_origin[2] = origin[2]; - S.listener_forward[0] = forward[0]; - S.listener_forward[1] = forward[1]; - S.listener_forward[2] = forward[2]; - S.listener_right[0] = right[0]; - S.listener_right[1] = right[1]; - S.listener_right[2] = right[2]; - S.listener_up[0] = up[0]; - S.listener_up[1] = up[1]; - S.listener_up[2] = up[2]; - - if (S.volume.value < 0.0) - Cvar.SetValue('volume', 0.0); - else if (S.volume.value > 1.0) - Cvar.SetValue('volume', 1.0); - - S.UpdateAmbientSounds(); - S.UpdateDynamicSounds(); - S.UpdateStaticSounds(); -}; - -S.Play = function() -{ - if (S.nosound.value !== 0) - return; - var i, sfx; - for (i = 1; i < Cmd.argv.length; ++i) - { - sfx = S.PrecacheSound(COM.DefaultExtension(Cmd.argv[i], '.wav')); - if (sfx != null) - S.StartSound(CL.state.viewentity, 0, sfx, S.listener_origin, 1.0, 1.0); - } -}; - -S.PlayVol = function() -{ - if (S.nosound.value !== 0) - return; - var i, sfx; - for (i = 1; i < Cmd.argv.length; i += 2) - { - sfx = S.PrecacheSound(COM.DefaultExtension(Cmd.argv[i], '.wav')); - if (sfx != null) - S.StartSound(CL.state.viewentity, 0, sfx, S.listener_origin, Q.atof(Cmd.argv[i + 1]), 1.0); - } -}; - -S.LoadSound = function(s) -{ - if (S.nosound.value !== 0) - return; - if (s.cache != null) - return true; - - var sc = {}; - - var data = COM.LoadFile('sound/' + s.name); - if (data == null) - { - Con.Print('Couldn\'t load sound/' + s.name + '\n'); - return; - } - - var view = new DataView(data); - if ((view.getUint32(0, true) !== 0x46464952) || (view.getUint32(8, true) !== 0x45564157)) - { - Con.Print('Missing RIFF/WAVE chunks\n'); - return; - } - var p, fmt, dataofs, datalen, cue, loopstart, samples; - for (p = 12; p < data.byteLength; ) - { - switch (view.getUint32(p, true)) - { - case 0x20746d66: // fmt - if (view.getInt16(p + 8, true) !== 1) - { - Con.Print('Microsoft PCM format only\n'); - return; - } - fmt = { - channels: view.getUint16(p + 10, true), - samplesPerSec: view.getUint32(p + 12, true), - avgBytesPerSec: view.getUint32(p + 16, true), - blockAlign: view.getUint16(p + 20, true), - bitsPerSample: view.getUint16(p + 22, true) - }; - break; - case 0x61746164: // data - dataofs = p + 8; - datalen = view.getUint32(p + 4, true); - break; - case 0x20657563: // cue - cue = true; - loopstart = view.getUint32(p + 32, true); - break; - case 0x5453494c: // LIST - if (cue !== true) - break; - cue = false; - if (view.getUint32(p + 28, true) === 0x6b72616d) - samples = loopstart + view.getUint32(p + 24, true); - break; - } - p += view.getUint32(p + 4, true) + 8; - if ((p & 1) !== 0) - ++p; - } - - if (fmt == null) - { - Con.Print('Missing fmt chunk\n'); - return; - } - if (dataofs == null) - { - Con.Print('Missing data chunk\n'); - return; - } - if (loopstart != null) - sc.loopstart = loopstart * fmt.blockAlign / fmt.samplesPerSec; - if (samples != null) - sc.length = samples / fmt.samplesPerSec; - else - sc.length = datalen / fmt.avgBytesPerSec; - - sc.size = datalen + 44; - if ((sc.size & 1) !== 0) - ++sc.size; - var out = new ArrayBuffer(sc.size); - view = new DataView(out); - view.setUint32(0, 0x46464952, true); // RIFF - view.setUint32(4, sc.size - 8, true); - view.setUint32(8, 0x45564157, true); // WAVE - view.setUint32(12, 0x20746d66, true); // fmt - view.setUint32(16, 16, true); - view.setUint16(20, 1, true); - view.setUint16(22, fmt.channels, true); - view.setUint32(24, fmt.samplesPerSec, true); - view.setUint32(28, fmt.avgBytesPerSec, true); - view.setUint16(32, fmt.blockAlign, true); - view.setUint16(34, fmt.bitsPerSample, true); - view.setUint32(36, 0x61746164, true); // data - view.setUint32(40, datalen, true); - (new Uint8Array(out, 44, datalen)).set(new Uint8Array(data, dataofs, datalen)); - if (S.context != null) - sc.data = S.context.createBuffer(out, true); - else - sc.data = new Audio('data:audio/wav;base64,' + Q.btoa(new Uint8Array(out))); - - s.cache = sc; - return true; -}; diff --git a/Client/index.htm b/Client/index.htm index 9524602..ebc89da 100644 --- a/Client/index.htm +++ b/Client/index.htm @@ -123,7 +123,7 @@ - + @@ -524,4 +524,6 @@ } - \ No newline at end of file + + + From 9d6fab2456effac2204c643c26b0140be62cd7b4 Mon Sep 17 00:00:00 2001 From: Soldy <4786022+Soldy@users.noreply.github.com> Date: Thu, 19 May 2022 21:15:07 +0100 Subject: [PATCH 9/9] just for fun change to oo Signed-off-by: Soldy <4786022+Soldy@users.noreply.github.com> --- libs/agent_server_con.js | 10 +++++++++ libs/agent_server_host.js | 10 +++++++++ libs/agent_server_sys.js | 10 +++++++++ {Server/WebQDS => libs/server}/COM.js | 0 {Server/WebQDS => libs/server}/Host.js | 0 {Server/WebQDS => libs/server}/Sys.js | 0 package.json | 30 ++++++++++++++++++++++++++ 7 files changed, 60 insertions(+) create mode 100644 libs/agent_server_con.js create mode 100644 libs/agent_server_host.js create mode 100644 libs/agent_server_sys.js rename {Server/WebQDS => libs/server}/COM.js (100%) rename {Server/WebQDS => libs/server}/Host.js (100%) rename {Server/WebQDS => libs/server}/Sys.js (100%) create mode 100644 package.json diff --git a/libs/agent_server_con.js b/libs/agent_server_con.js new file mode 100644 index 0000000..ec5e805 --- /dev/null +++ b/libs/agent_server_con.js @@ -0,0 +1,10 @@ +'use strict'; +const $universe = global.theUn1v3rse.controls.interface(); + +if(!$universe.baseCheck('Con')){ + const $con = new (require('./server/Con.js')).base(); + $universe.baseAdd('Con', $con); +} + +exports.base = $universe.baseGet('Con'); + diff --git a/libs/agent_server_host.js b/libs/agent_server_host.js new file mode 100644 index 0000000..6def6c4 --- /dev/null +++ b/libs/agent_server_host.js @@ -0,0 +1,10 @@ +'use strict'; +const $universe = global.theUn1v3rse.controls.interface(); + +if(!$universe.baseCheck('Host')){ + const $host = new (require('./server/Host.js')).base(); + $universe.baseAdd('Host', $host); +} + +exports.base = $universe.baseGet('Host'); + diff --git a/libs/agent_server_sys.js b/libs/agent_server_sys.js new file mode 100644 index 0000000..af7730d --- /dev/null +++ b/libs/agent_server_sys.js @@ -0,0 +1,10 @@ +'use strict'; +const $universe = global.theUn1v3rse.controls.interface(); + +if(!$universe.baseCheck('Sys')){ + const $sys = new (require('./server/Sys.js')).base(); + $universe.baseAdd('Sys', $sys); +} + +exports.base = $universe.baseGet('Sys'); + diff --git a/Server/WebQDS/COM.js b/libs/server/COM.js similarity index 100% rename from Server/WebQDS/COM.js rename to libs/server/COM.js diff --git a/Server/WebQDS/Host.js b/libs/server/Host.js similarity index 100% rename from Server/WebQDS/Host.js rename to libs/server/Host.js diff --git a/Server/WebQDS/Sys.js b/libs/server/Sys.js similarity index 100% rename from Server/WebQDS/Sys.js rename to libs/server/Sys.js diff --git a/package.json b/package.json new file mode 100644 index 0000000..61f1ea0 --- /dev/null +++ b/package.json @@ -0,0 +1,30 @@ +{ + "name": "rock-quake", + "version": "0.0.1", + "description": "web quake", + "main": "index.js", + "scripts": { + "test": "node test.js" + }, + "repository": { + "type": "git", + "url": "https://github.com/Soldy/WebQuake.git" + }, + "keywords": [], + "author": "Soldy <4786022+Soldy@users.noreply.github.com>", + "license": "GPLv3", + "bugs": { + "url": "https://github.com/Soldy/WebQuake/issues" + }, + "homepage": "https://github.com/Soldy/WebQuake#readme", + "devDependencies": { + "cheapest-sleep": "^0.99.0-alpha0", + "eslint": "^7.32.0", + "nanoTest": "^0.9.9-beta31" + }, + "dependencies": { + "interactiveConsole": "^0.0.7-alpha0", + "websocket": "^1.0.34" + + } +}