-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9791bec
commit f820dcc
Showing
18 changed files
with
1,568 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
root = true | ||
|
||
[*] | ||
end_of_line = lf | ||
insert_final_newline = true | ||
charset = utf-8 | ||
indent_style = space | ||
indent_size = 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* -text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.vagrant/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# -*- mode: ruby -*- | ||
# vi: set ft=ruby : | ||
|
||
Vagrant.configure(2) do |config| | ||
config.vm.box = 'CatPlusPlus/Debian' | ||
config.vm.box_version = '~> 1.0.1' | ||
|
||
config.vm.network 'forwarded_port', guest: 80, host: 8000 | ||
config.vm.network 'forwarded_port', guest: 443, host: 8443 | ||
|
||
config.vm.provider 'virtualbox' do |vb| | ||
vb.cpus = 2 | ||
vb.memory = '1024' | ||
end | ||
|
||
config.vm.provision 'shell', path: 'bin/provision' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/bin/bash | ||
set -e | ||
export DEBIAN_FRONTEND=noninteractive | ||
export PAGER=cat | ||
|
||
apt-get update -y | ||
apt-get -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" install -y -V \ | ||
clang-3.8 clang-format-3.8 clang-tidy-3.8 \ | ||
libwebsocketpp-dev libboost-all-dev libicu-dev \ | ||
ninja-build | ||
|
||
cat > /etc/nginx/sites-available/default <<EOF | ||
server { | ||
include snippets/listen-default.conf; | ||
server_name _; | ||
sendfile off; | ||
root /vagrant/client; | ||
index index.html; | ||
location /ws/ { | ||
proxy_http_version 1.1; | ||
proxy_set_header Host \$http_host; | ||
proxy_set_header X-Real-IP \$remote_addr; | ||
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for; | ||
proxy_set_header X-Forwarded-Proto \$scheme; | ||
proxy_set_header X-Forwarded-Host \$http_host; | ||
proxy_set_header Upgrade \$http_upgrade; | ||
proxy_set_header Connection "upgrade"; | ||
proxy_pass http://localhost:8080; | ||
} | ||
location / { | ||
try_files \$uri \$uri/ =404; | ||
} | ||
} | ||
EOF | ||
|
||
systemctl reload nginx | ||
systemctl stop [email protected] || : | ||
systemctl disable [email protected] || : | ||
systemctl stop redis-server || : | ||
systemctl disable redis-server || : | ||
|
||
cd $(mktemp -d) | ||
git clone https://github.com/brson/multirust.git --depth 1 --recursive | ||
cd multirust | ||
|
||
git submodule update --init | ||
This comment has been minimized.
Sorry, something went wrong. |
||
sh ./build.sh | ||
sh ./install.sh | ||
su - vagrant -c 'multirust update stable && multirust default stable' 2>/dev/null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules/ | ||
bower_components/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
body { | ||
min-height: 100%; | ||
} | ||
|
||
#game-canvas { | ||
margin: 25px auto; | ||
border: 1px solid black; | ||
display: block; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
(function() { | ||
'use strict'; | ||
|
||
// | ||
// Evil global state | ||
// | ||
|
||
// TODO player-related state | ||
|
||
var canvas = null; | ||
var socket = null; | ||
var address = null; | ||
var lastTime = null; | ||
var keyboard = null; | ||
|
||
// | ||
// Input handling | ||
// | ||
|
||
var INPUT_MOVE_UP = 0; | ||
var INPUT_MOVE_DOWN = 1; | ||
var INPUT_MOVE_LEFT = 2; | ||
var INPUT_MOVE_RIGHT = 3; | ||
var INPUT_FIRE = 4; | ||
|
||
var onKeyInput = function(input) { | ||
}; | ||
|
||
var onMouseInput = function(input, x, y) { | ||
}; | ||
|
||
var bindInput = function() { | ||
keyboard = new window.keypress.Listener(); | ||
}; | ||
|
||
var unbindInput = function() { | ||
keyboard.reset(); | ||
keyboard = null; | ||
}; | ||
|
||
// | ||
// Game logic | ||
// | ||
|
||
var setupGame = function() { | ||
// TODO | ||
bindInput(); | ||
}; | ||
|
||
var stopGame = function() { | ||
// TODO | ||
unbindInput(); | ||
}; | ||
|
||
var update = function(timeDelta) { | ||
// TODO | ||
}; | ||
|
||
// | ||
// Rendering | ||
// | ||
|
||
var draw = function(context, width, height, timeDelta) { | ||
// TODO drawing | ||
}; | ||
|
||
var frame = function(time) { | ||
if (lastTime === null) { | ||
lastTime = time; | ||
} | ||
|
||
var delta = time - lastTime; | ||
lastTime = time; | ||
|
||
update(delta); | ||
|
||
var context = canvas.getContext('2d'); | ||
context.save(); | ||
context.clearRect(0, 0, canvas.width, canvas.height); | ||
draw(context, canvas.width, canvas.height, delta); | ||
context.restore(); | ||
|
||
window.requestAnimationFrame(frame); | ||
}; | ||
|
||
// | ||
// Networking | ||
// | ||
|
||
var handleMessage = function(msg) { | ||
// TODO do stuff~ | ||
}; | ||
|
||
var sendMessage = function(msg) { | ||
msg = JSON.stringify(msg); | ||
socket.send(msg); | ||
}; | ||
|
||
var connect = function() { | ||
console.log('Trying to connect to ' + address); | ||
|
||
socket = new WebSocket(address); | ||
|
||
socket.onopen = function() { | ||
console.log('Connected to ' + address); | ||
setupGame(); | ||
}; | ||
|
||
socket.onmessage = function(e) { | ||
var message = JSON.parse(e.data); | ||
handleMessage(msg); | ||
}; | ||
|
||
socket.onerror = socket.onclose = function() { | ||
console.log('Disconnected from ' + address); | ||
// TODO automatic reconnection | ||
stopGame(); | ||
}; | ||
}; | ||
|
||
var disconnect = function() { | ||
if (socket !== null) { | ||
console.log('Disconnecting from ' + address); | ||
socket.close(); | ||
socket = null; | ||
} | ||
}; | ||
|
||
// | ||
// DOM events | ||
// | ||
|
||
var onConnectClick = function(e) { | ||
disconnect(); | ||
|
||
address = document.getElementById('server-address').value; | ||
connect(); | ||
|
||
e.stopPropagation(); | ||
}; | ||
|
||
var onDisconnectClick = function(e) { | ||
disconnect(); | ||
e.stopPropagation(); | ||
}; | ||
|
||
var onDOMReady = function() { | ||
console.log('onDOMReady'); | ||
canvas = document.getElementById('game-canvas'); | ||
|
||
document.getElementById('connect').addEventListener('click', onConnectClick); | ||
document.getElementById('disconnect').addEventListener('click', onDisconnectClick); | ||
|
||
// TODO maybe figure out godo way to fill available viewport | ||
|
||
window.requestAnimationFrame(frame); | ||
}; | ||
|
||
document.addEventListener('DOMContentLoaded', onDOMReady); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Tatsoryk Client</title> | ||
|
||
<link rel="stylesheet" href="game.css"> | ||
<script src="vendor/keypress.js"></script> | ||
<script src="game.js"></script> | ||
</head> | ||
<body> | ||
<div id="control-panel"> | ||
<input id="server-address" value="ws://localhost:8000/ws"> | ||
<input id="connect" type="button" value="Connect"> | ||
<input id="disconnect" type="button" value="Disconnect"> | ||
</div> | ||
|
||
<canvas id="game-canvas" width="1280" height="720"></canvas> | ||
</body> | ||
</html> |
Oops, something went wrong.
Isn't this already covered by L46?
Edit: it is.