Page MenuHomePhabricator

No OneTemporary

diff --git a/layout/menu.xml b/layout/menu.xml
index f419097..a5bd801 100644
--- a/layout/menu.xml
+++ b/layout/menu.xml
@@ -1,317 +1,329 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<Menus>
<Menu id="firsttime" title="Welcome to @progtitle@!
&lt;div style='font-size:17pt'>Please choose some initial settings:&lt;/div>">
<Item type="list" call="init_key" text="Keyset">
<Option value="-1" text="Don't Touch!" />
<Option value="0" text="Home row" /> <!--(ASDF for left and JKL; for right)-->
<Option value="1" text="WASD/Arrows" />
</Item>
<Item type="list" call="init_color" text="Initial Color">
<Option value="0" text="0xff0000Red" />
<Option value="1" text="0xff8800Orange" />
<Option value="2" text="0xffff00Yellow" />
<Option value="3" text="0x00ff00Green" />
<Option value="4" text="0x00ffffCyan" />
<Option value="5" text="0x0000ffBlue" />
<Option value="6" text="0xff00ffViolet" />
</Item>
<Item type="str" var="player.name" text="Name"/>
<Item type="exitmenu" text="Let's go!"/>
</Menu>
<Menu id="main" title="@progtitle@ Alpha">
<Item type="submenu" onenter="game" text="Play"/>
<Item type="submenu" onenter="player" text="Customize Player"/>
<Item type="submenu" onenter="input" text="Configure Input"/>
<Item type="submenu" onenter="system" text="Configure 3DCycles"/>
<Item type="submenu" onenter="about" text="About"/>
<!-- <Item type="submenu" onenter="egg" text="&lt;- Go Back"/> -->
<!-- alt: <Item type="text" text="" /> <!- - no exit game function, escape will do nothing -->
<Item type="js" onenter="menu('quit')" text="Quit"/>
</Menu>
<!-- General game configuration -->
<Menu id="game" title="Play Game">
<Item type="js" onenter="playGame()" style="display:inline-block;" text="Locally"/>
<Item type="submenu" onenter="game_setup" style="font-size:16pt;" text="(config)"/>
<Item type="submenu" onenter="network" text="Network"/>
<Item type="exitmenu" text="&lt;- Go Back"/>
</Menu>
<Menu id="network" title="Network Game">
<Item type="str" var="CONNECT_HOST" text="Host" />
<Item type="num" range="1024,49151" var="CONNECT_PORT" text="Port" />
<Item type="list" var="CONNECT_SSL" text="SSL">
<Option value="false" text="No" /> <Option value="true" text="Yes" />
</Item>
<Item type="js" onenter="connectToGame()" text="Connect"/>
<Item type="exitmenu" text="&lt;- Go Back"/>
+ </Menu>
+ <Menu id="connect" title="Connecting...">
+ <Item type="text" text="" from="con:last" style="font-size:14pt;text-align:left;padding:10px;color:grey" />
+ <Item type="leave" text="&lt;- Cancel"/>
+ </Menu>
+ <Menu id="connectfail" title="Connection Failure">
+ <Item type="text" text="" from="con:last" style="font-size:11pt;text-align:left;padding:10px" />
+ <Item type="leave" text="&lt;- Okay"/>
+ </Menu>
+ <Menu id="connectterm" title="Connection Terminated">
+ <Item type="text" text="" from="con:last" style="font-size:11pt;text-align:left;padding:10px" />
+ <Item type="leave" text="&lt;- Okay"/>
</Menu>
<Menu id="game_setup" title="Local Game Config" if="not engine.network">
<Item type="submenu" onenter="presets" text="Load Preset..."/>
<Item type="num" range="0,Infinity" var="TEAMS_MIN" text="Min Teams (# of Humans+AIs)" />
<Item type="list" var="GAME_TYPE" text="When the round finishes">
<Option value="0" text="Keep the round going" />
<Option value="1" text="End the round" />
</Item>
<Item type="list" var="FINISH_TYPE" text="When only AIs remain">
<Option value="1" text="Have AIs win" />
<Option value="2" text="Fast finish" />
<Option value="3" text="Find winner (alpha)" />
</Item>
<Item type="num" range="-20,15" var="SIZE_FACTOR" text="Arena Size" />
<Item type="num" range="0,Infinity" var="CYCLE_SPEED" text="Cycle Speed" />
<Item type="num" range="0,Infinity" var="CYCLE_RUBBER" text="Cycle Rubber" />
<Item type="exitmenu" text="&lt;- Go Back"/>
</Menu>
<!--<Menu id="presets" title="Load Preset">
<Item type="js" onenter="preset('classic');menu('exitmenu');menu('exitmenu')" text="Classic"/>
<Item type="js" onenter="preset('df');menu('menu:loading')" text="Dogfight"/>
<Item type="js" onenter="preset('hr');menu('menu:loading')" text="High Rubber"/>
<Item type="js" onenter="preset('ft');menu('menu:loading')" text="Fast Track"/>
<Item type="js" onenter="preset('fort');menu('menu:loading')" text="Fortress"/>
<Item type="js" onenter="preset('racing');menu('menu:loading')" text="Racing"/>
<Item type="js" onenter="preset('zonetest');menu('exitmenu');menu('exitmenu')" text="Zone test"/>
<Item type="exitmenu" text="Cancel"/>
</Menu>-->
<Menu id="presets" title="Load Preset">
<Item type="js" style="font-size:14pt" onenter="preset('classic');menu('exitmenu');menu('exitmenu')"
text="Classic" title="Default low rubber settings in Armagetron"/>
<Item type="js" style="font-size:14pt" onenter="menu('menu:loading');preset('df')"
text="Loose Dogfight" title="Obey loose dogfight rules or go elsewhere!"/>
<Item type="js" style="font-size:14pt" onenter="menu('menu:loading');preset('hr')"
text="0x0000ff-=}0xffffffID0x0000ff&lt; 0xffff00T0x00ff00I0xffff00L0x00ff00T 0x0000ffHigh Rubber0x00ff00" title="No camping!"/>
<Item type="js" style="font-size:14pt" onenter="menu('menu:loading');preset('ft')"
text="0xc0c000&gt;&gt;&gt; 0xff0000F0xff1c1cA0xff3838S0xff5555T0xff7171T0xff8d8dR0xffaaaaA0xffc6c6C0xffe2e2K 0xc0c000&lt;&lt;&lt;" title="Gotta go fast! Very fast!"/>
<Item type="js" style="font-size:14pt" onenter="menu('menu:loading');preset('fort')"
text="Fortress" title="Take the enemy's base, try not to let them take yours."/>
<Item type="js" style="font-size:14pt" onenter="menu('menu:loading');preset('ctf')"
text="Capture the Flag" title="Take the enemy's flag, try not to let them take yours."/>
<Item type="js" style="font-size:14pt" onenter="menu('menu:loading');preset('styball')"
text="Styball (Soccer / Hockey)" title="Push the ball into the enemy's base, but don't let them push it into yours!"/>
<Item type="js" style="font-size:14pt" onenter="menu('menu:loading');preset('racing')"
text="0x66cc66Adventures of 0x00cc00TRON 0xffffff>> Advanced Racing &lt;&lt;" title="First to the finish line wins!"/>
<Item type="js" style="font-size:14pt" onenter="menu('menu:loading');preset('snake')"
text="0x66ccffSnake Survival" title="How long can you get your trail?"/>
<Item type="js" style="font-size:14pt" onenter="preset('zonetest');menu('exitmenu');menu('exitmenu')"
text="Zone test" title="Zones! Zones! Zones! Zones everywhere!"/>
<Item type="exitmenu" text="Cancel" title="Never mind, none of these look interesting..."/>
</Menu>
<Menu id="loading" title="Loading...">
<Item type="text" text="" from="con:last" style="font-size:14pt;text-align:left;padding:10px;color:grey" />
</Menu>
<!-- Player configuration -->
<Menu id="player" title="Player Setup">
<Item type="str" var="player.name" text="Name"/>
<Item type="submenu" onenter="macro" text="Instant Chats"/>
<Item type="color" var="player.cycleColor" text="Cycle Color" />
<Item type="color" var="player.tailColor" text="Tail Color" />
<!--<Item type="num" range="0,5" var="player.engineType" text="Engine Type" />-->
<Item type="list" var="player.spectating" text="Spectator Mode">
<Option value="false" text="Off" /> <Option value="true" text="On" />
</Item>
<Item type="js" onenter="exportUsrSets()" text="Export player settings" />
<Item type="js" onenter="importSets()" text="Import settings" />
<Item type="exitmenu" text="&lt;- Go Back"/>
</Menu>
<Menu id="macro" title="Instant Chats">
<!--<Foreach var="instantchats" as="n">
<Item type="str" var="instantchats.$(n).text" text="Chat"/>
<Item type="keys" var="instantchats.$(n).input" text="Input" />
<Item type="text" text="&amp;nbsp;" />
</Foreach>-->
<Item type="str" var="instantchats.0.text" text="Chat"/>
<Item type="keys" var="instantchats.0.input" text="Input" />
<Item type="text" text="&amp;nbsp;" />
<Item type="str" var="instantchats.1.text" text="Chat"/>
<Item type="keys" var="instantchats.1.input" text="Input" />
<Item type="text" text="&amp;nbsp;" />
<Item type="str" var="instantchats.2.text" text="Chat"/>
<Item type="keys" var="instantchats.2.input" text="Input" />
<Item type="text" text="&amp;nbsp;" />
<Item type="str" var="instantchats.3.text" text="Chat"/>
<Item type="keys" var="instantchats.3.input" text="Input" />
<Item type="text" text="&amp;nbsp;" />
<Item type="js" onenter="" text="Add instant chat (future)" />
<Item type="exitmenu" text="&lt;- Go Back"/>
</Menu>
<Menu id="input" title="Configure Input">
<Item type="submenu" onenter="input_conf" text="Player Control"/>
<Item type="submenu" onenter="global_input_conf" text="Global Input"/>
<Item type="exitmenu" text="&lt;- Go Back"/>
</Menu>
<Menu id="input_conf" title="Player Input">
<Item type="keys" var="left" text="Turn left" />
<Item type="keys" var="right" text="Turn right" />
<!--<Item type="keys" var="north" text="Turn North" />
<Item type="keys" var="south" text="Turn South" />
<Item type="keys" var="east" text="Turn East" />
<Item type="keys" var="west" text="Turn West" />-->
<Item type="keys" var="boost" text="Boost" />
<Item type="keys" var="toggleboost" text="Toggle Boost" />
<Item type="keys" var="brake" text="Brake" />
<Item type="keys" var="togglebrake" text="Toggle Brake" />
<Item type="keys" var="jump" text="Jump" />
<Item type="keys" var="chat" text="Chat" />
<Item type="keys" var="camera" text="Switch View" />
<Item type="keys" var="look_left" text="Look Left" />
<Item type="keys" var="look_right" text="Look Right" />
<Item type="keys" var="look_forward" text="Look Forward" />
<Item type="keys" var="look_back" text="Look Back" />
<Item type="exitmenu" text="&lt;- Go Back"/>
</Menu>
<!-- Configuration -->
<Menu id="system" title="System Setup">
<Item type="submenu" onenter="screen" text="Configure Display"/>
<Item type="submenu" onenter="display" text="Configure Visuals"/>
<Item type="submenu" onenter="sound" text="Configure the Sound"/>
<Item type="submenu" onenter="other" text="Misc Settings"/>
<Item type="exitmenu" text="&lt;- Go Back"/>
</Menu>
<Menu id="screen" title="Screen Mode">
<Item type="list" call="settings.FULLSCREEN" text="Fullscreen (F11)" title="It's recommended that you use F11 instead of this fullscreen option. It is, however, left in for mobile touchscreen devices.">
<Option value="false" text="Off" /> <Option value="true" text="On" />
</Item>
<Item type="list" var="REDRAW_MODE" text="VSync" title="Synchronize framerate with vertical refresh rate\nThe vertical refresh rate is basically the frames per second your monitor displays. Turning this on would make it depend on browser redraw calls, effectively capping your FPS at the refresh rate. Turning it off would continously draw the frames but throws away additional frames that your monitor doesn't display. Depending on game loop configuration, this can provide minimal advantage.">
<Option value="1" text="Off" /> <Option value="0" text="On" />
</Item>
<Item type="num" range="1,Infinity" var="MAX_TARGET_FPS" text="Max Target FPS" />
<Item type="exitmenu" text="&lt;- Go Back"/>
</Menu>
<Menu id="display" title="Visual Settings">
<Item type="submenu" onenter="detail" text="Detail Settings"/>
<Item type="submenu" onenter="visual_prefs" text="Other Preferences"/>
<Item type="exitmenu" text="&lt;- Go Back"/>
</Menu>
<Menu id="detail" title="Detail Settings">
<Item type="list" call="aamenurender" text="Menu Background Rendering" title="How the background is rendered. Default: Image">
<Option value="img" text="Image" />
<Option value="css" text="CSS" />
<Option value="css_rot" text="CSS+Rotation" />
</Item>
<Item type="exitmenu" text="&lt;- Go Back"/>
</Menu>
<Menu id="visual_prefs" title="Preferences">
<Item type="list" var="HIGH_RIM" text="High Rims">
<Option value="false" text="Off" /> <Option value="true" text="On" />
</Item>
<Item type="list" var="EXPLOSION" text="Explosions">
<Option value="false" text="Off" /> <Option value="true" text="On" />
</Item>
<Item type="list" var="engine.view" from="engine.views" text="Current Camera" />
<Item type="exitmenu" text="&lt;- Go Back"/>
</Menu>
<Menu id="sound" title="Sound Configuration">
<Item type="list" var="player.engineType" text="Sound set">
<Option value="5" text="ArmagetronAd" />
<Option value="3" text="Tr2n Origins" />
<Option value="4" text="glTron" />
</Item>
<Item type="exitmenu" text="&lt;- Go Back"/>
</Menu>
<Menu id="other" title="Misc Configuration">
<Item type="submenu" onenter="display_tweaks" text="Tweaks"/>
<Item type="submenu" onenter="global_input_conf" text="Global Keys"/>
<Item type="exitmenu" text="&lt;- Go Back"/>
</Menu>
<Menu id="display_tweaks" title="Game Tweaks">
<Item type="list" var="GAME_LOOP" text="Run game loop">
<Option value="0" text="Outside render cycle" />
<Option value="2" text="Outside+during render cycle" title="possibily reduces fps?" />
<Option value="0.5" text="Outside render cycle + cycle movement in render" title="may reduce visible jumps, the default" />
<Option value="1" text="During render cycle" title="may reduce jumps but increase lag"/>
</Item>
<Item type="exitmenu" text="&lt;- Go Back"/>
</Menu>
<Menu id="global_input_conf" title="Input Configuration">
<Item type="keys" var="scroll_up" text="Scroll Up" />
<Item type="keys" var="scroll_down" text="Scroll Down" />
<Item type="keys" var="scroll_end" text="Scroll to End" />
<Item type="keys" var="score" text="Toggle Scoreboard" />
<Item type="keys" var="esc" text="In-game Menu" />
<Item type="exitmenu" text="&lt;- Go Back"/>
</Menu>
<Menu id="about" title="About">
<Item type="text" style="font-size:15pt" text="0xff8800Title: 0xRESETT@progtitle@" />
<Item type="text" style="font-size:15pt" text="Draws heavy inspiration from the excellent lightcycle game Armagetron Advanced." />
<Item type="text" style="font-size:15pt" text="0xff8800Version: 0xRESETTv1.0-beta6" />
<Item type="text" style="font-size:15pt" text="This is a development version. It's a heavy work in progress. Anything could change at any time, and there may be a lot of bugs." />
<Item type="submenu" onenter="about_dev" text="Credits"/>
<Item type="submenu" onenter="license" text="Legal Stuff"/>
<!--<Item type="text" text="0xff7f00Official Website: 0xRESETTN/A" />-->
<Item type="exitmenu" text="&lt;- Go Back"/>
</Menu>
<Menu id="about_dev" title="Credits">
<Item type="text" style="font-size:15pt" text="0xff8800Project Admin: 0xRESETTNelg" />
<Item type="text" style="font-size:15pt" text="0xff8800Developers: 0xRESETTNelg, Durf" />
<Item type="text" style="font-size:15pt" text="0xff8800Collision Detection: 0xRESETTDurf, softSurfer" />
<Item type="text" style="font-size:15pt" text="0xff8800ArmagetronAd Font: 0xRESETTLucifer, Fabrice Holbe" />
<Item type="text" style="font-size:15pt" text="0xRESETTDefault Theme:" />
<Item type="text" style="font-size:15pt" text="0xff8800Wall Textures: 0xRESETTBrian Hilmers" />
<Item type="text" style="font-size:15pt" text="0xff8800Textures: 0xRESETTthe Armagetron Advanced development team" />
<Item type="text" style="font-size:15pt" text="0xff8800ArmagetronAd Cycles: 0xRESETTZ-Man(?)" />
<!--<Item type="text" style="font-size:15pt" text="0xff8800Testing: 0xRESETTdukevin, light, jericho, zoom" />-->
<Item type="exitmenu" text="&lt;- Go Back"/>
</Menu>
<Menu id="license" title="Legal Stuff">
<Item type="text" style="font-size:15pt" text="3DCycles - A lightcycle game. &lt;br>
Copyright (C) 2019 Glen Harpring &lt;br> &lt;br>
This program is free software; you can redistribute it and/or &lt;br>
modify it under the terms of the GNU General Public License &lt;br>
as published by the Free Software Foundation; either version 2 &lt;br>
of the License, or (at your option) any later version. &lt;br>
&lt;br>
This program is distributed in the hope that it will be useful, &lt;br>
but WITHOUT ANY WARRANTY; without even the implied warranty of &lt;br>
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the &lt;br>
GNU General Public License for more details. &lt;br>
&lt;br>
You should have received a copy of the GNU General Public License &lt;br>
along with this program; if not, write to the Free Software &lt;br>
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA." />
<Item type="exitmenu" text="&lt;- Go Back"/>
</Menu>
<Menu id="pause" title="Paused" exitmenu="pauseMenuToggle()">
<Item type="submenu" onenter="game_setup" text="Local Game Setup"/>
<Item type="submenu" onenter="team" text="Change Teams"/>
<Item type="submenu" onenter="player" text="Customize Player"/>
<Item type="submenu" onenter="input" text="Configure Input"/>
<Item type="submenu" onenter="system" text="Configure 3DCycles"/>
<Item type="submenu" onenter="about" text="About"/>
<Item type="leave" text="Leave Grid"/>
<Item type="exitmenu" text="Return to Game"/>
</Menu>
<Menu id="team" title="Change Teams">
<!-- script to dynamically generate items-->
<Item type="list" var="player.spectating" text="Spectator Mode" onenter="KILL_ALL">
<Option value="false" text="Off" /> <Option value="true" text="On" />
</Item>
<Item type="exitmenu" text="&lt;- Go Back"/>
</Menu>
<Menu id="vote" title="Vote" exitmenu="menu('exitmenu');vote(voteopt)"> <!--Future implementation?-->
<Item type="list" call="function(in){voteopt = in; return '';}" text="Vote">
<Option value="no" text=" No &gt;" />
<Option value="" text="&lt; Ignore &gt;" />
<Option value="yes" text="&lt; Yes " />
</Item>
<Item type="exitmenu" text="Submit"/>
</Menu>
<Menu id="highscores" title="0x000000Highscores">
<Item type="text" text="0xff0000»0x808080Swag´0xRESETT: INF points" />
<Item type="text" text="0x0088ff|0xRESETTNelg0xRESETT: 10 points" />
<Item type="text" text="0x00ff00Z-Man0xRESETT: 1 points" />
<Item type="exitmenu" text="&lt;- Go Back"/>
</Menu>
<Menu id="preset_loaded" title="Preset Loaded">
<Item type="js" onenter="playGame()" text="Play"/>
<Item type="submenu" onenter="input_conf" text="Set Controls"/>
<Item type="exitmenu" text="Back to main menu"/>
</Menu>
</Menus>
diff --git a/scripts/network.js b/scripts/network.js
index 2087c5f..0783e98 100644
--- a/scripts/network.js
+++ b/scripts/network.js
@@ -1,354 +1,353 @@
/*
* 3DCycles - A lightcycle game.
* Copyright (C) 2019 Glen Harpring
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
function connectTo(host,port)
{
- hideMenu(); engine.inputState = "game";
+ engine.playGame = false; engine.inputState = "game";
try
{
var connection = new WebSocket('ws'+(settings.CONNECT_SSL?'s':'')+'://'+host+':'+port);
connection.onmessage = connectionHandler;
connection.onerror = function(e)
{
console.log(e); var msg;
+ disconnectFromGame();menu("leave");showMenu();
+ menu("menu:connectfail");
if(engine.network)
{
engine.console.print(msg="An error occurred with the connection.");
}
else
{
engine.console.print(msg="Couldn't connect to server. Please ensure that you have the right host and port.");
}
- disconnectFromGame();menu("leave");showMenu();
- menu("menu:");
- document.getElementById('menu').innerHTML = "<h1>Connection Error</h1><div style='text-align:left;font-size:11pt'>"+msg+"</div>";
}
connection.onclose = function(e)
{
console.log(e); var msg;
if(engine.network)
{
+ disconnectFromGame();menu("leave");showMenu();
+ menu("menu:connectterm");
engine.console.print(msg="Our connection with the server has been terminated.");
msg += " ";
if(e.reason == "") engine.console.print(msg+="No reason given.\n"); else engine.console.print(msg+="Reason: "+e.reason+"\n");
- disconnectFromGame();menu("leave");showMenu();
- menu("menu:");
- document.getElementById('menu').innerHTML = "<h1>Connection Terminated</h1><div style='text-align:left;font-size:11pt'>"+msg+"</div>";
}
}
return connection;
}
catch(e)
{
engine.console.print(e+"\n");
disconnectFromGame();menu("leave");showMenu();
menu("menu:");
document.getElementById('menu').innerHTML = "<h1>An error occurred</h1><div style='text-align:left;font-size:11pt'>"+e+"</div>";
}
}
function doNetSlide(cycle,timestep=1)
{
if(isNaN(cycle.position.x) || isNaN(cycle.position.y))
{
cycle.position.x = cycle.newPos.x;
cycle.position.y = cycle.newPos.y;
delete cycle.newPos;
}
else
{
timestep *= settings.CYCLE_SMOOTH_TIME;
if(timestep > 1) timestep = 1;
cycle.lastpos.x = (cycle.position.x += (cycle.newPos.x-cycle.position.x)*timestep);
cycle.lastpos.y = (cycle.position.y += (cycle.newPos.y-cycle.position.y)*timestep);
cycle.resetCurrWallSegment();
if(cycle.position.x == cycle.newPos.x && cycle.position.y == cycle.newPos.y) delete cycle.newPos;
}
}
function connectionHandler(e)
{
//console.log(e);
var msg = JSON.parse(e.data);
switch(msg.type)
{
case "ping": engine.connection.send((JSON.stringify({type:"pong"}))); break;
case "timeSync":
if(msg.data)
{
engine.gtime = msg.data;
engine.connection.send(JSON.stringify({type:"timeSync",data:engine.gtime}));
}
engine.connection.timeSync = false;
break;
case "version":
engine.connection.send(JSON.stringify({type:"version",data:0.7}));
break;
case "endRound": if(inround()) endRound(); break;
case "newRound":
if(!engine.playGame) playGame();
else if(!inround()) newRound();
break;
case "setting":
console.log(e);
netcfg(msg.setting,""+msg.data);
break;
case "con":
engine.console.print(msg.data);
break;
case "cen":
centerMessage(msg.data.msg,msg.data.time);
break;
case "syncdata":
console.log(msg.gtime);
engine.connection.send(JSON.stringify({type:"player",data:settings.player}));
if(typeof(msg.netid) != "undefined")
{
engine.activePlayer = msg.netid||0; //we got id
engine.network = true;
if(!engine.scene) init();
//endRound();
}
//engine.totalPauseTime += (msg.gtime||0)-engine.gtime;
if(msg.gtime !== undefined) engine.gtime = msg.gtime;
break;
case "leave":
if(engine.players[msg.data])
{
if(msg.data == engine.activePlayer)
{
console.warn("Player being deleted is ours.");
}
if(msg.data == engine.viewTarget)
{
changeViewTarget(1);
}
if(engine.players[msg.data].alive) engine.players[msg.data].kill();
engine.players.splice(msg.data,1);
updateScoreBoard();
}
else
{
console.warn("Left player doesn't seem to exist.");
}
break;
case "playerdata":
console.log(msg.data);
for(var i=msg.data.length;i--;) if(typeof(msg.data[i]) != "undefined")
{
var data = msg.data[i];
if(!engine.players[data.netid])
{
var cycleinfo;
data.ai = false; // AIs should be exclusively handled by the server. Maybe a different solution in the future?
engine.players[data.netid] = new Player(cycleinfo={
x:data.x||0, y:data.y||0, z:data.z||0, dir:data.dir||0, ai:data.ai||false,
name:data.name||"1",
cycleColor:data.cycleColor, tailColor:data.tailColor,
engineType:data.engineType||settings.player.engineType,
team: engine.teams[data.team]||new Team({name:(data.alive?data.name:"")}),
});
console.log(data);
engine.players[data.netid].spawn(cycleinfo,false);
audioMixing(engine.players[data.netid]);
}
else
{
engine.players[data.netid].name = data.name;
engine.players[data.netid].cycleColor = data.cycleColor;
engine.players[data.netid].tailColor = data.tailColor;
}
}
break;
case "griddata":
if(!engine.playGame) playGame();
//console.log(msg.data);
//engine.gtime = (performance.now()/settings.TIME_FACTOR)-engine.timeStart-engine.totalPauseTime-4000;
if(msg.gtime > engine.gtime)
{
//engine.gtime = msg.gtime;
//console.log("S: ",msg.gtime-engine.gtime);
if(!engine.connection.timeSync)
{
engine.connection.timeSync = true;
engine.connection.send(JSON.stringify({type:"timeSync",data:engine.gtime}));
}
}
var delta = engine.gtime-(msg.gtime);
var timestep = delta/1000;
//var delta = timestep*1000;
for(var i=msg.data.length;i--;)
if(typeof(msg.data[i]) != "undefined")
{
var data = msg.data[i];
var cycle = engine.players[data.netid];
if(cycle.alive != data.alive)
{
if(cycle.alive == true) cycle.killAt(data.position[0],data.position[1],data.position[2]);
else cycle.spawn({x:data.position[0],y:data.position[1],z:data.position[2]},(!!data.spawntime));
delete cycle.newPos;
}
cycle.speed = data.speed; cycle.rubber = data.rubber;
if(cycle.alive)
{
var olddir = cycle.rotation.z, newdir = deg2rad(data.direction||0);
if(!data.wall && normalizeRad(olddir) == normalizeRad(newdir) && isFinite(data.position[0]) && isFinite(data.position[1])) //slide to position
{
if(!cycle.newPos) cycle.newPos = new THREE.Vector2(cycle.position.x,cycle.position.y);
cycle.newPos.x = data.position[0]; cycle.newPos.y = data.position[1];
if(!cycle.handleNetTurn)
{
doNetSlide(cycle,Infinity);
cycle.handleNetTurn = true;
}
}
else if(cycle.handleNetTurn) //jump straight to the position, we're doing a turn
{ //also, don't handle updates until our last turn has been sent by the server
cycle.lastpos.x = cycle.position.x = data.position[0]||0;
cycle.lastpos.y = cycle.position.y = data.position[1]||0;
delete cycle.newPos;
cycle.gameTime = Math.max(0,msg.gtime);
if(settings.DEBUG_NETWORK_TURN_WAIT) cycle.lastTurnTime = 0;
//HACK to avoid cycle sticking to wall on a turn
{
var fakeTS = 0.01/cycle.speed;
var move2d = Math.cos(cycle.model.rotation.y)*(cycle.speed*fakeTS), dir = cdir(cycle.rotation.z);
cycle.lastpos.x = (cycle.position.x += move2d*dir[0]);
cycle.lastpos.y = (cycle.position.y += move2d*dir[1]);
cycle.gameTime += fakeTS;
}
}
if(data.wall) { cycle.walls.map = data.wall; cycle.resetWall(false); }
cycle.lastpos.z = cycle.position.z = data.position[2]||0;
if(cycle.haswall)
{
if(rad2deg(olddir) == rad2deg(newdir))
{
cycle.walls.map[cycle.walls.map.length-1] = [cycle.position.x,cycle.position.y];
}
else
{
cycle.rotation.z = newdir;
var wallmod = cycle.walls.children[cycle.walls.children.length-1];
cycle.newWallSegment();
}
}
else
{
cycle.rotation.z = newdir;
}
}
//if(isFinite(timestep)) cycle.update(timestep);
}
if(!engine.lastPingTime) engine.players[engine.activePlayer].ping = parseInt(delta);
updateScoreBoard(); //console.log(timestep);
break;
case "scoredata":
for(var i=msg.data.length;i--;)
if(typeof(msg.data[i]) != "undefined")
{
var data = msg.data[i];
var cycle = engine.players[data.netid];
cycle.chatting = data.chatting||false;
cycle.ping = data.ping||0;
cycle.score = data.score||0;
engine.lastPingTime = performance.now();
}
updateScoreBoard();
break;
case "team":
engine.teams.splice(0);
for(var i=msg.data.length-1;i>=0;--i) if(msg.data[i])
{
engine.teams[msg.data[i].id] = new Team(msg.data[i]);
}
break;
case "zone":
for(var i=msg.data.length-1;i>=0;--i) if(msg.data[i])
{
var zone = msg.data[i];
if(zone.destroyed)
{
if(engine.zones[zone.id])
{
engine.zones[zone.id].destroy();
}
}
else if(engine.zones.children[zone.id])
{
var myZone = engine.zones.children[zone.id];
if(zone.x!==undefined) {myZone.position.x = zone.x; myZone.position.y = zone.y; myZone.position.z = zone.z;}
if(zone.xdir!==undefined) {myZone.cfg.xdir = zone.xdir; myZone.cfg.ydir = zone.ydir;}
if(zone.bounce!== undefined)myZone.cfg.bounce = zone.bounce;
myZone.cfg.netObject = true;
}
else
{
try
{
var s = new Zone(zone).spawn();
//we don't need to process the zone ourselves (as that will all be handled by the server), however we should still know the type for our chatbot.
s.netObject = true;
}
catch(e)
{
engine.console.print("0xff7f7fAn error occurred when syncing zones. You may be missing some important elements of the game.\n");
console.error(e);
}
}
}
break;
}
}
function connectToGame()
{
if(!engine.connection)
{
engine.connection = connectTo(settings.CONNECT_HOST,settings.CONNECT_PORT)
document.getElementById("progtitle").innerHTML = tStringify("@progtitleshort@ &bull; Connecting to "+settings.CONNECT_HOST+":"+settings.CONNECT_PORT);
+ menu("menu:connect");
}
}
function disconnectFromGame()
{
if(engine.connection && engine.connection.close) engine.connection.close();
engine.connection = engine.network = false;
engine.viewTarget = engine.activePlayer = 0;
for(var i=netChanged.length-1;i>=0;--i)
{
chsetting(netChanged[i][0],netChanged[i][1],true);
}
netChanged = [];
}

File Metadata

Mime Type
text/x-diff
Expires
Mon, Jun 23, 9:14 PM (3 d, 23 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
10843

Event Timeline