Skip to content

Commit

Permalink
Merge pull request #251 from candirugame/ci-docker-cache-deps
Browse files Browse the repository at this point in the history
Ci docker cache deps
  • Loading branch information
IsaacThoman authored Jan 28, 2025
2 parents 7651d78 + d6702a1 commit 0cb52fa
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 42 deletions.
35 changes: 22 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
FROM denoland/deno:2.1.2
LABEL authors="Candiru <[email protected]>"
# Build stage
FROM denoland/deno:2.1.2 AS builder
WORKDIR /app

# Copy all source files
COPY . .

# Cache dependencies
RUN deno cache --import-map=import_map.json main.ts

# Build the application
RUN deno task build

# Set working directory
# Runtime stage
FROM denoland/deno:2.1.2
WORKDIR /app

# Install curl
# Install curl for runtime
USER root
RUN apt-get update && apt-get install -y curl

# Copy the project files
COPY . .
# Copy ALL source files and build artifacts
COPY --from=builder /app/ ./

# Copy the Deno cache
COPY --from=builder /deno-dir/ /deno-dir/

# Ensure the deno user has ownership of the necessary files and directories
# Set permissions
RUN chown -R deno:deno /app

# Switch back to deno user
USER deno

# Expose the port
EXPOSE 3000

# Run the task
CMD ["task", "start"]
CMD ["task", "startnobuild"]
5 changes: 4 additions & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
{
"nodeModulesDir": "auto",
"tasks": {
"dev": "deno run -A --node-modules-dir npm:vite",
"build": "deno run -A --node-modules-dir npm:vite build",
"cache": "deno cache --import-map=import_map.json main.ts",
"preview": "deno run -A --node-modules-dir npm:vite preview",
"serve": "deno run --allow-net --allow-read jsr:@std/http@1/file-server dist/",
"start": "deno task build && deno run --allow-read --allow-env --allow-net --allow-write main.ts"
"start": "deno task build && deno run --allow-read --allow-env --allow-net --allow-write main.ts",
"startnobuild": "deno run --allow-read --allow-env --allow-net --allow-write main.ts"
},
"compilerOptions": {
"lib": ["ES2020", "DOM", "DOM.Iterable", "deno.ns"]
Expand Down
8 changes: 8 additions & 0 deletions import_map.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"imports": {
"@deno/vite-plugin": "npm:@deno/vite-plugin@^1.0.0",
"@oak/oak": "jsr:@oak/oak@^17.1.3",
"@std/http": "jsr:@std/http@^1.0.10",
"vite": "npm:vite@^5.4.8"
}
}
10 changes: 5 additions & 5 deletions src/client/core/AssetManager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';
import { GLTF, GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';
import { DRACOLoader } from 'three/examples/jsm/loaders/DRACOLoader.js';
import * as THREE from 'three';

Expand Down Expand Up @@ -31,11 +31,11 @@ export class AssetManager {
private cloneWithNewMaterials(scene: THREE.Group): THREE.Group {
const clonedScene = scene.clone();

clonedScene.traverse((node) => {
clonedScene.traverse((node: THREE.Object3D) => {
if ((node as THREE.Mesh).isMesh) {
const mesh = node as THREE.Mesh;
if (Array.isArray(mesh.material)) {
mesh.material = mesh.material.map((mat) => mat.clone());
mesh.material = mesh.material.map((mat: THREE.Material) => mat.clone());
} else {
mesh.material = mesh.material.clone();
}
Expand All @@ -60,7 +60,7 @@ export class AssetManager {
this.assets.set(url, { scene: new THREE.Group(), isLoaded: false, callbacks: [callback] });
this.gltfLoader.load(
url,
(gltf) => {
(gltf: GLTF) => {
const assetEntry = this.assets.get(url)!;
assetEntry.scene = gltf.scene;
assetEntry.isLoaded = true;
Expand All @@ -72,7 +72,7 @@ export class AssetManager {
assetEntry.callbacks = [];
},
undefined,
(error) => {
(error: Error) => {
console.error(`Error loading asset ${url}:`, error);
},
);
Expand Down
14 changes: 7 additions & 7 deletions src/client/core/RemotePlayerRenderer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as THREE from 'three';
import { Networking } from './Networking.ts';
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';
import { GLTF, GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';
import { DRACOLoader } from 'three/examples/jsm/loaders/DRACOLoader.js';
import { acceleratedRaycast, computeBoundsTree, disposeBoundsTree } from 'three-mesh-bvh';
import { Player, PlayerData } from '../../shared/Player.ts';
Expand Down Expand Up @@ -74,7 +74,7 @@ export class RemotePlayerRenderer {
this.possumMesh = undefined;
this.loader.load(
'models/simplified_possum.glb',
(gltf) => {
(gltf: GLTF) => {
console.time('Computing possum BVH');
(<THREE.Mesh> gltf.scene.children[0]).geometry.computeBoundsTree();
console.timeEnd('Computing possum BVH');
Expand Down Expand Up @@ -412,7 +412,7 @@ export class RemotePlayerRenderer {
const wallIntersects = this.raycaster.intersectObjects([RemotePlayerRenderer.map]);
this.raycaster.firstHitOnly = false;

const filteredIntersects = playerIntersects.filter((playerIntersect) => {
const filteredIntersects = playerIntersects.filter((playerIntersect: THREE.Intersection) => {
for (const wallIntersect of wallIntersects) {
if (wallIntersect.distance < playerIntersect.distance) {
return false;
Expand All @@ -424,7 +424,7 @@ export class RemotePlayerRenderer {
return true;
});

return filteredIntersects.map((intersect) => intersect.object);
return filteredIntersects.map((intersect: THREE.Intersection) => intersect.object);
}

public getPlayerSpheresInCrosshairWithWalls(): THREE.Object3D[] {
Expand All @@ -437,7 +437,7 @@ export class RemotePlayerRenderer {
const wallIntersects = this.raycaster.intersectObjects([RemotePlayerRenderer.map]);
this.raycaster.firstHitOnly = false;

const filteredIntersects = playerIntersects.filter((playerIntersect) => {
const filteredIntersects = playerIntersects.filter((playerIntersect: THREE.Intersection) => {
for (const wallIntersect of wallIntersects) {
if (wallIntersect.distance < playerIntersect.distance) {
return false;
Expand All @@ -446,7 +446,7 @@ export class RemotePlayerRenderer {
return true;
});

return filteredIntersects.map((intersect) => intersect.object);
return filteredIntersects.map((intersect: THREE.Intersection) => intersect.object);
}

public getShotVectorsToPlayersWithOffset(
Expand All @@ -467,7 +467,7 @@ export class RemotePlayerRenderer {
this.raycaster.firstHitOnly = false;

// Filter player intersections based on wall intersections
const filteredPlayerIntersects = playerIntersects.filter((playerIntersect) => {
const filteredPlayerIntersects = playerIntersects.filter((playerIntersect: THREE.Intersection) => {
for (const wallIntersect of wallIntersects) {
if (wallIntersect.distance < playerIntersect.distance) {
return false; // A wall is blocking the player
Expand Down
4 changes: 2 additions & 2 deletions src/client/items/BananaGun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ export class BananaGun extends ItemBase {
AssetManager.getInstance().loadAsset('models/simplified_banana_1.glb', (scene) => {
this.object = scene;
if (this.itemType === ItemType.InventoryItem) {
this.object.traverse((child) => {
this.object.traverse((child: THREE.Object3D) => {
if ((child as THREE.Mesh).isMesh) {
child.renderOrder = 999;
const mesh = child as THREE.Mesh;
if (Array.isArray(mesh.material)) {
mesh.material.forEach((mat) => mat.depthTest = false);
mesh.material.forEach((mat: THREE.Material) => mat.depthTest = false);
} else {
mesh.material.depthTest = false;
}
Expand Down
4 changes: 2 additions & 2 deletions src/client/items/FishGun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ export class FishGun extends ItemBase {
AssetManager.getInstance().loadAsset('models/simplified_fish.glb', (scene) => {
this.object = scene;
if (this.itemType === ItemType.InventoryItem) {
this.object.traverse((child) => {
this.object.traverse((child: THREE.Object3D) => {
if ((child as THREE.Mesh).isMesh) {
child.renderOrder = 999;
const mesh = child as THREE.Mesh;
if (Array.isArray(mesh.material)) {
mesh.material.forEach((mat) => mat.depthTest = false);
mesh.material.forEach((mat: THREE.Material) => mat.depthTest = false);
} else {
mesh.material.depthTest = false;
}
Expand Down
4 changes: 2 additions & 2 deletions src/client/items/FlagItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ export class FlagItem extends ItemBase {
AssetManager.getInstance().loadAsset('models/simplified_pizza.glb', (scene) => {
this.object = scene;
if (this.itemType === ItemType.InventoryItem) {
this.object.traverse((child) => {
this.object.traverse((child: THREE.Object3D) => {
if ((child as THREE.Mesh).isMesh) {
child.renderOrder = 999;
const mesh = child as THREE.Mesh;
if (Array.isArray(mesh.material)) {
mesh.material.forEach((mat) => mat.depthTest = false);
mesh.material.forEach((mat: THREE.Material) => mat.depthTest = false);
} else {
mesh.material.depthTest = false;
}
Expand Down
4 changes: 2 additions & 2 deletions src/client/items/ItemBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ export class ItemBase {
this.inventoryMenuObject = this.object.clone();

if (this.itemType === ItemType.InventoryItem) {
this.object.traverse((child) => {
this.object.traverse((child: THREE.Object3D) => {
if ((child as THREE.Mesh).isMesh) {
child.renderOrder = 999;
const applyDepthTest = (material: THREE.Material | THREE.Material[]) => {
const applyDepthTest = (material: THREE.Material | THREE.Material[]): void => {
if (Array.isArray(material)) {
material.forEach((mat) => applyDepthTest(mat)); // Recursively handle array elements
} else {
Expand Down
6 changes: 3 additions & 3 deletions src/client/items/Pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ export class Pipe extends ItemBase {

public override init() {
AssetManager.getInstance().loadAsset('models/simplified_rusty_pipe.glb', (scene) => {
this.object = scene;
this.object = scene; //
if (this.itemType === ItemType.InventoryItem) {
this.object.traverse((child) => {
this.object.traverse((child: THREE.Object3D) => {
if ((child as THREE.Mesh).isMesh) {
child.renderOrder = 999;
const mesh = child as THREE.Mesh;
if (Array.isArray(mesh.material)) {
mesh.material.forEach((mat) => mat.depthTest = false);
mesh.material.forEach((mat: THREE.Material) => mat.depthTest = false);
} else {
mesh.material.depthTest = false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/client/ui/DirectionIndicator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class DirectionIndicator extends IndicatorBase {
this.loadModel('models/arrow.glb')
.then((model) => {
this.directionObject = model;
this.directionObject.traverse((child) => {
this.directionObject.traverse((child: THREE.Object3D) => {
if ((child as THREE.Mesh).isMesh) {
(child as THREE.Mesh).renderOrder = 999;
this.applyDepthTestToMesh(child as THREE.Mesh);
Expand Down
2 changes: 1 addition & 1 deletion src/client/ui/HealthIndicator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class HealthIndicator extends IndicatorBase {
this.loadModel('models/simplified_possum.glb')
.then((model) => {
this.possumObject = model;
this.possumObject.traverse((child) => {
this.possumObject.traverse((child: THREE.Object3D) => {
if ((child as THREE.Mesh).isMesh) {
(child as THREE.Mesh).renderOrder = 999;
this.applyDepthTest(child as THREE.Mesh);
Expand Down
6 changes: 3 additions & 3 deletions src/client/ui/IndicatorBase.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as THREE from 'three';
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';
import { GLTF, GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';
import { DRACOLoader } from 'three/examples/jsm/loaders/DRACOLoader.js';
import { Player } from '../../shared/Player.ts';
import { Networking } from '../core/Networking.ts';
Expand Down Expand Up @@ -87,9 +87,9 @@ export abstract class IndicatorBase {
return new Promise((resolve, reject) => {
loader.load(
modelPath,
(gltf) => {
(gltf: GLTF) => {
const object = gltf.scene;
object.traverse((child) => {
object.traverse((child: THREE.Object3D) => {
if ((child as THREE.Mesh).isMesh) {
(child as THREE.Mesh).renderOrder = 999;
this.applyDepthTest(child as THREE.Mesh);
Expand Down

0 comments on commit 0cb52fa

Please sign in to comment.