Skip to content
This repository has been archived by the owner on Aug 18, 2024. It is now read-only.

Commit

Permalink
non-3d-page-load-optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
HexaField committed Aug 17, 2024
1 parent 2ab6196 commit f72a1af
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
21 changes: 11 additions & 10 deletions src/old examples/matchmaking.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,18 @@ import { Engine } from '@etherealengine/ecs/src/Engine'
import { MatchmakingTicketAssignment, OpenMatchTicket } from '@etherealengine/matchmaking/src/interfaces'
import { matchTicketAssignmentPath } from '@etherealengine/matchmaking/src/match-ticket-assignment.schema'
import { matchTicketPath } from '@etherealengine/matchmaking/src/match-ticket.schema'
import { API } from '@etherealengine/common'

const gameModes = ['ctf', 'tournament']

async function findCurrentTicketData() {
const { data } = await Engine.instance.api.service(matchUserPath).find()
const { data } = await API.instance.service(matchUserPath).find()
if (data.length) {
const matchUser = data[0]
const ticket = await Engine.instance.api.service(matchTicketPath).get(matchUser.ticketId)
const ticket = await API.instance.service(matchTicketPath).get(matchUser.ticketId)
if (!ticket) {
// ticket is outdated - delete match-user row
await Engine.instance.api.service(matchUserPath).remove(matchUser.id)
await API.instance.service(matchUserPath).remove(matchUser.id)
} else {
const gamemode = ticket.search_fields.tags[0]
return { id: ticket.id, gamemode }
Expand Down Expand Up @@ -84,15 +85,15 @@ const Page = () => {
setIsUpdating(true)
let serverTicket: OpenMatchTicket
try {
serverTicket = await Engine.instance.api.service(matchTicketPath).create({ gamemode })
serverTicket = await API.instance.service(matchTicketPath).create({ gamemode })
} catch (e) {
const matchUser = (await Engine.instance.api.service(matchUserPath).find()).data[0]
serverTicket = await Engine.instance.api.service(matchTicketPath).get(matchUser.ticketId)
const matchUser = (await API.instance.service(matchUserPath).find()).data[0]
serverTicket = await API.instance.service(matchTicketPath).get(matchUser.ticketId)
if (!serverTicket) {
// cleanup
await Engine.instance.api.service(matchUserPath).remove(matchUser.id)
await API.instance.service(matchUserPath).remove(matchUser.id)
// create new
serverTicket = await Engine.instance.api.service(matchTicketPath).create({ gamemode })
serverTicket = await API.instance.service(matchTicketPath).create({ gamemode })
}
}

Expand All @@ -114,14 +115,14 @@ const Page = () => {
if (!ticketId) {
return
}
await Engine.instance.api.service(matchTicketPath).remove(ticketId)
await API.instance.service(matchTicketPath).remove(ticketId)
setTicketData(undefined)
// setStatus('')
}

function getAssignment(ticketId: string): Promise<MatchmakingTicketAssignment> {
return (
Engine.instance.api.service(matchTicketAssignmentPath).get(ticketId) as Promise<MatchmakingTicketAssignment>
API.instance.service(matchTicketAssignmentPath).get(ticketId) as Promise<MatchmakingTicketAssignment>
).then((assignment) => {
console.log('assignment', ticketId, assignment)
return assignment
Expand Down
7 changes: 4 additions & 3 deletions src/old examples/matchmaking2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Engine } from '@etherealengine/ecs/src/Engine'
import { OpenMatchTicketAssignment } from '@etherealengine/matchmaking/src/interfaces'
import { matchTicketAssignmentPath } from '@etherealengine/matchmaking/src/match-ticket-assignment.schema'
import { matchTicketPath } from '@etherealengine/matchmaking/src/match-ticket.schema'
import { API } from '@etherealengine/common'

const Page = () => {
const [renderTrigger, updRenderTrigger] = useState<object>()
Expand All @@ -23,10 +24,10 @@ const Page = () => {
async function newTicket() {
let ticket
try {
ticket = await Engine.instance.api.service(matchTicketPath).create({ gamemode: 'mode.demo' })
ticket = await API.instance.service(matchTicketPath).create({ gamemode: 'mode.demo' })
} catch (e) {
alert('You already searching for game')
const matchUser = (await Engine.instance.api.service(matchUserPath).find()).data[0]
const matchUser = (await API.instance.service(matchUserPath).find()).data[0]
console.log('matchUser', matchUser)
ticket = { id: matchUser.ticketId }
}
Expand All @@ -49,7 +50,7 @@ const Page = () => {

function getAssignment(ticketId: string): Promise<OpenMatchTicketAssignment> {
return (
Engine.instance.api.service(matchTicketAssignmentPath).get(ticketId) as Promise<OpenMatchTicketAssignment>
API.instance.service(matchTicketAssignmentPath).get(ticketId) as Promise<OpenMatchTicketAssignment>
).then((assignment) => {
console.log('assignment', ticketId, assignment)
connections.current[ticketId] = assignment.connection
Expand Down

0 comments on commit f72a1af

Please sign in to comment.