Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/phisn/rocket-game
Browse files Browse the repository at this point in the history
  • Loading branch information
phisn committed May 13, 2024
2 parents b105f29 + 839c405 commit 46eb517
Show file tree
Hide file tree
Showing 18 changed files with 2,810 additions and 3,234 deletions.
Binary file added best.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions best.txt

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions packages/server/.dev.vars

This file was deleted.

1 change: 1 addition & 0 deletions packages/server/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.env
.wrangler
.dev.vars
3 changes: 2 additions & 1 deletion packages/server/src/api/leaderboard/validate-replay.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import RAPIER from "@dimforge/rapier2d"
import { TRPCError } from "@trpc/server"
import { and, count, eq, lt } from "drizzle-orm"
import { DrizzleD1Database } from "drizzle-orm/d1"
Expand Down Expand Up @@ -135,7 +136,7 @@ function serverValidateReplay(worldname: string, gamemode: string, replayBuffer:
const replayModel = ReplayModel.decode(replayBuffer)
const worldModel = WorldModel.decode(Buffer.from(world.model, "base64"))

const stats = validateReplay(replayModel, worldModel, gamemode)
const stats = validateReplay(RAPIER, replayModel, worldModel, gamemode)

if (!stats) {
console.log("replay is invalid")
Expand Down
6 changes: 0 additions & 6 deletions packages/server/src/api/user/user-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,28 +72,22 @@ export const userRouter = router({
)
.query(async ({ input: { code }, ctx: { oauth, env, db } }) => {
try {
console.error(1)
const { access_token } = await oauth.validateAuthorizationCode(code, {
credentials: env.AUTH_GOOGLE_CLIENT_SECRET,
authenticateWith: "request_body",
})
console.error(2)

const userInfoRequest = await fetch(
`https://www.googleapis.com/oauth2/v1/userinfo?access_token=${access_token}`,
)

console.error(3)

if (!userInfoRequest.ok) {
throw new TRPCError({
code: "BAD_REQUEST",
message: "Failed to fetch user info",
})
}

console.error(4)

const userInfo = z
.object({
email: z.string(),
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/framework/trpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const createContext =
"https://accounts.google.com/o/oauth2/auth",
"https://accounts.google.com/o/oauth2/token",
{
redirectURI: env.CLIENT_URL,
redirectURI: env.CLIENT_URL.split(",").at(-1),
},
),
env,
Expand Down
1 change: 1 addition & 0 deletions packages/server/wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ port = 3002

[vars]
CLIENT_URL = "https://new.rocketgame.app,https://rust-game.rocket-game.pages.dev,https://polyburn.com"
API_URL="https://api.polyburn.com"

[[d1_databases]]
migrations_dir = "drizzle"
Expand Down
58 changes: 14 additions & 44 deletions packages/web-game/src/game/modules/module-input/module-input.ts
Original file line number Diff line number Diff line change
@@ -1,59 +1,19 @@
import { RuntimeSystemContext } from "runtime/src/core/runtime-system-stack"
import { ExtendedRuntime } from "../../runtime-extension/new-extended-runtime"
import { Keyboard } from "./keyboard"
import { Mouse } from "./mouse"

const CHARCODE_ONE = "1".charCodeAt(0)
const CHARCODE_NINE = "9".charCodeAt(0)

function base64ToBytes(base64: string) {
return Uint8Array.from(atob(base64), c => c.charCodeAt(0))
}

const input = [
4, 3, 5, 5, 5, 5, 4, 5, 4, 4, 5, 5, 4, 4, 4, 5, 4, 4, 5, 4, 5, 4, 5, 4, 0, 4, 5, 4, 5, 4, 5, 4,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 5, 2, 2, 4, 4, 2, 2, 5, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 1, 0, 4, 4, 5, 5, 5, 5, 5, 4, 5, 4, 4, 4, 4, 5, 4, 4, 5, 4, 5, 4, 5, 4, 5, 5, 4, 5, 4,
5, 5, 4, 5, 5, 4, 5, 5, 5, 5, 5, 5, 5, 5, 4, 5, 2, 2, 2, 2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5, 5,
4, 5, 4, 5, 4, 4, 5, 4, 4, 4, 5, 4, 5, 4, 5, 5, 4, 5, 4, 3, 5, 5, 5, 4, 5, 5, 5, 5, 5, 4, 5, 5,
5, 5, 4, 5, 0, 2, 4, 2, 4, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 4, 5, 0, 4, 4, 5, 5,
5, 5, 5, 4, 4, 5, 4, 4, 5, 4, 4, 4, 4, 5, 5, 4, 5, 5, 5, 4, 5, 4, 5, 5, 4, 5, 4, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 4, 2, 2, 4, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 4, 4, 5, 5,
5, 5, 4, 5, 4, 5, 4, 5, 4, 4, 4, 4, 5, 4, 5, 4, 5, 5, 4, 5, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 4, 5, 2, 2, 4, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 4, 4, 5, 5,
5, 5, 5, 4, 4, 4, 5, 4, 4, 5, 4, 4, 5, 4, 5, 5, 4, 5, 4, 5, 4, 5, 5, 5, 4, 5, 4, 5, 5, 5, 5, 4,
]

export class ModuleInput {
private keyboard: Keyboard
private mouse: Mouse

private rotationSpeed = [0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2.0, 2.5, 3.0]
private rotationSpeedIndex = 2

private precomputed: RuntimeSystemContext[]
private iter = -1
// private precomputed: RuntimeSystemContext[]
// private iter = -1

constructor(runtime: ExtendedRuntime) {
this.keyboard = new Keyboard()
Expand All @@ -65,20 +25,30 @@ export class ModuleInput {
this.onKeyboardDown = this.onKeyboardDown.bind(this)
window.addEventListener("keydown", this.onKeyboardDown)

/*
this.precomputed = []
let rotation = 0
for (let i = 0; i < input.length; ++i) {
const thrust = input[i] >= 3
const previousRotation = rotation
if (input[i] === 1 || input[i] === 4) {
rotation += 0.1
} else if (input[i] === 2 || input[i] === 5) {
rotation -= 0.1
}
this.precomputed.push({ rotation, thrust })
const limit = 4
for (let j = 0; j < limit; ++j) {
this.precomputed.push({
rotation: previousRotation + ((rotation - previousRotation) * (j + 1)) / limit,
thrust,
})
}
}
*/
}

dispose() {
Expand All @@ -104,7 +74,7 @@ export class ModuleInput {
}

onFixedUpdate() {
++this.iter
// ++this.iter
}

onKeyboardDown(event: KeyboardEvent) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { BufferGeometry, Loader, LoadingManager, Shape, ShapePath, Vector2 } from "three"

export interface SVGResultPaths extends ShapePath {
userData?: Record<string, any> | undefined
}

export interface SVGResult {
paths: SVGResultPaths[]
xml: XMLDocument
}

export interface StrokeStyle {
strokeColor: string
strokeWidth: number
strokeLineJoin: string
strokeLineCap: string
strokeMiterLimit: number
}

export class SVGLoader extends Loader<SVGResult> {
constructor(manager?: LoadingManager)

defaultDPI: number
defaultUnit: string

parse(text: string): SVGResult

static getStrokeStyle(
width?: number,
color?: string,
lineJoin?: string,
lineCap?: string,
miterLimit?: number,
): StrokeStyle

/**
* Generates a stroke with some witdh around the given path.
* @remarks The path can be open or closed (last point equals to first point)
* @param points Array of Vector2D (the path). Minimum 2 points.
* @param style Object with SVG properties as returned by SVGLoader.getStrokeStyle(), or SVGLoader.parse() in the path.userData.style object
* @param arcDivisions Arc divisions for round joins and endcaps. (Optional)
* @param minDistance Points closer to this distance will be merged. (Optional)
* @returns BufferGeometry with stroke triangles (In plane z = 0). UV coordinates are generated ('u' along path. 'v' across it, from left to right)
*/
static pointsToStroke(
points: Vector2[],
style: StrokeStyle,
arcDivisions?: number,
minDistance?: number,
): BufferGeometry

static pointsToStrokeWithBuffers(
points: Vector2[],
style: StrokeStyle,
arcDivisions?: number,
minDistance?: number,
vertices?: number[],
normals?: number[],
uvs?: number[],
vertexOffset?: number,
): number

static createShapes(shapePath: ShapePath): Shape[]
}
Loading

0 comments on commit 46eb517

Please sign in to comment.