diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..293de45 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +**/.git +**/.DS_Store +**/node_modules diff --git a/Dockerfile.client b/Dockerfile.client new file mode 100644 index 0000000..9b49798 --- /dev/null +++ b/Dockerfile.client @@ -0,0 +1,20 @@ +# build +FROM node:18-alpine as build + +COPY . /app +WORKDIR /app/client + +RUN npm install --save-dev +RUN npm run build + + +# serve via nginx +FROM nginx:latest + +RUN rm /etc/nginx/conf.d/default.conf +COPY nginx.conf /etc/nginx/conf.d/ + +COPY --from=build /app/client/dist /usr/share/nginx/html + +EXPOSE 80 +CMD ["nginx", "-g", "daemon off;"] diff --git a/Dockerfile.server b/Dockerfile.server new file mode 100644 index 0000000..3db00ea --- /dev/null +++ b/Dockerfile.server @@ -0,0 +1,9 @@ +FROM oven/bun + +COPY . /app + +WORKDIR /app/server + +RUN bun install + +CMD bun run /app/server/src/main.ts diff --git a/client/index.html b/client/index.html index 892a3af..332fdf0 100644 --- a/client/index.html +++ b/client/index.html @@ -10,7 +10,7 @@
diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..e3f8865 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,25 @@ +version: '3' + +services: + client: + build: + dockerfile: Dockerfile.client + networks: + - webapp + ports: + - 1337:80 + restart: always + container_name: jumpstorm-client + hostname: client + + server: + build: + dockerfile: Dockerfile.server + networks: + - webapp + restart: always + container_name: jumpstorm-server + +networks: + webapp: + driver: bridge diff --git a/engine/entities/Player.ts b/engine/entities/Player.ts index 02dd14e..abe3bb5 100644 --- a/engine/entities/Player.ts +++ b/engine/entities/Player.ts @@ -92,7 +92,7 @@ export class Player extends Entity { const distance = Math.sqrt( Math.pow(center.y - myCenter.y, 2) + Math.pow(center.x - myCenter.x, 2) ); - const clientServerPredictionCenterThreshold = 30; + const clientServerPredictionCenterThreshold = 20; if (distance < clientServerPredictionCenterThreshold) center = myCenter; [ diff --git a/engine/structures/Grid.ts b/engine/structures/Grid.ts index 5f0e053..06bdf4e 100644 --- a/engine/structures/Grid.ts +++ b/engine/structures/Grid.ts @@ -67,9 +67,6 @@ export class Grid implements RefreshingCollisionFinderBehavior { const yBoxes = Math.ceil( this.gridDimension.height / this.cellDimension.height ); - const xBoxes = Math.ceil( - this.gridDimension.width / this.cellDimension.width - ); const translated: Coord2D = { y: center.y - this.topLeft.y, diff --git a/engine/systems/NetworkUpdate.ts b/engine/systems/NetworkUpdate.ts index 524ebf4..02fbd9f 100644 --- a/engine/systems/NetworkUpdate.ts +++ b/engine/systems/NetworkUpdate.ts @@ -32,7 +32,7 @@ export class NetworkUpdate extends System { this.messageProcessor = messageProcessor; this.entityUpdateInfo = new Map(); - this.nextPublishInterval = 0; + this.nextPublishInterval = this.getNextUpdateInterval(); } public update(dt: number, game: Game) { diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..6aac36f --- /dev/null +++ b/nginx.conf @@ -0,0 +1,19 @@ +server { + listen 80; + + location / { + root /usr/share/nginx/html/; + index index.html; + try_files $uri $uri/ /index.html; + } + + location /api { + proxy_pass http://server:8080; + + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $host; + } +}