Skip to content

Commit

Permalink
Add more skeletons.
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCatPlusPlus committed Mar 26, 2016
1 parent 9791bec commit f820dcc
Show file tree
Hide file tree
Showing 18 changed files with 1,568 additions and 1 deletion.
8 changes: 8 additions & 0 deletions .editorconfig
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
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* -text
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.vagrant/
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,18 @@
A Lounge<Discord> gaem project that gets completed.

The loungescussion and circlejerk about The Game is [here](https://forum.loungecpp.net/topic/21/tatsoryk-a-lounge-discord-gaem-project-that-gets-completed) [regulars only].

## Using Vagrant

1. Install [VirtualBox](https://www.virtualbox.org/wiki/Downloads) 5.0.14 or newer.
1. Install [Vagrant](https://www.vagrantup.com/downloads.html) 1.8 or newer
1. Run `vagrant up` to set everything up. This needs 1GB free RAM, and will download around 1-2GB (the image + project dependencies).
1. Run `vagrant ssh`. `/vagrant` folder corresponds to the project root.

You should be able to just run builds without installing anything extra. Also, nginx is listening on port 8000 and 8443 (TLS).
WebSocket is exposed as `ws://localhost:8000/ws/` (the server itself should be listening on port 8080). Static files are all
served from `/vagrant/client`.

For Rust there is multirust and newest stable Rust installed.

For C++ side of things there is Clang 3.8, ninja, libwebsocketpp, Boost 1.58 and ICU should Unicode support be needed.
17 changes: 17 additions & 0 deletions Vagrantfile
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
52 changes: 52 additions & 0 deletions bin/provision
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.

Copy link
@nabijaczleweli

nabijaczleweli Apr 8, 2016

Member

Isn't this already covered by L46?

Edit: it is.

sh ./build.sh
sh ./install.sh
su - vagrant -c 'multirust update stable && multirust default stable' 2>/dev/null
2 changes: 2 additions & 0 deletions client/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
bower_components/
9 changes: 9 additions & 0 deletions client/game.css
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;
}
160 changes: 160 additions & 0 deletions client/game.js
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);
})();
20 changes: 20 additions & 0 deletions client/index.html
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>
Loading

0 comments on commit f820dcc

Please sign in to comment.