Skip to content

Commit

Permalink
Merge branch 'main' into vite-press-doc
Browse files Browse the repository at this point in the history
  • Loading branch information
robertlong committed May 22, 2023
2 parents 9f9ce91 + 2000267 commit fe40201
Show file tree
Hide file tree
Showing 140 changed files with 8,492 additions and 3,160 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Production CI
on:
push:
branches:
- main
- prod
jobs:
deploy:
runs-on: ubuntu-latest
Expand Down
63 changes: 63 additions & 0 deletions .github/workflows/staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Staging CI
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 16
cache: yarn

- name: Install
run: yarn install

- name: Build
env:
NODE_OPTIONS: --max_old_space_size=4096
VITE_SENTRY_DSN: "https://[email protected]/50"
VITE_SENTRY_ENVIRONMENT: "staging"
VITE_SENTRY_RELEASE: ${{ github.sha }}
run: yarn build

- name: Create Deployment
uses: bobheadxi/deployments@v1
id: deployment
with:
step: start
token: ${{ secrets.GITHUB_TOKEN }}
env: Netlify
ref: ${{ github.event.workflow_run.head_sha }}

- name: Deploy to Netlify
id: netlify
uses: nwtgck/[email protected]
with:
publish-dir: dist
deploy-message: "Staging Deploy from GitHub Actions"
netlify-config-path: ./netlify.toml
github-token: ${{ secrets.GITHUB_TOKEN }}
alias: staging
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
timeout-minutes: 1

- name: Update deployment status
uses: bobheadxi/deployments@v1
if: always()
with:
step: finish
override: false
token: ${{ secrets.GITHUB_TOKEN }}
status: ${{ job.status }}
env: ${{ steps.deployment.outputs.env }}
deployment_id: ${{ steps.deployment.outputs.deployment_id }}
env_url: ${{ steps.netlify.outputs.deploy-url }}
12 changes: 5 additions & 7 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@
"defaultHomeServer": "thirdroom.io",
"homeserverList": ["thirdroom.io", "matrix.org"],
"onboardingVersion": 1,
"bugReportEndpointUrl": "https://element.io/bugreports/submit",
"repositoryRoomIdOrAlias": "#repository-room:thirdroom.io",
"oidc": {
"clientConfigs": {
"https://id.thirdroom.io/realms/thirdroom/": {
"client_id": "thirdroom",
"uris": ["http://localhost:3000", "https://thirdroom.io"],
"guestKeycloakIdpHint": "guest"
}
"staticOidcClients": {
"https://id.thirdroom.io/realms/thirdroom/": {
"client_id": "thirdroom",
"guestKeycloakIdpHint": "guest"
}
}
}
42 changes: 42 additions & 0 deletions examples/ecs-basic/js/ecs-basic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const Spinner = world.findComponentStoreByName("Spinner");

const spinnerQuery = world.createQuery([Spinner]);

function setRotationAxis(quat, axis, angle) {
// Ensure the axis is a unit vector
let xAxis = axis[0];
let yAxis = axis[1];
let zAxis = axis[2];

let len = xAxis * xAxis + yAxis * yAxis + zAxis * zAxis;

if (len > 0) {
len = 1 / Math.sqrt(len);
}

xAxis = axis[0] * len;
yAxis = axis[1] * len;
zAxis = axis[2] * len;

// Calculate the sin and cos values for half of the angle
let halfAngle = angle / 2;
let sinHalfAngle = Math.sin(halfAngle);
let cosHalfAngle = Math.cos(halfAngle);

// Compute the quaternion components
quat.x = xAxis * sinHalfAngle;
quat.y = yAxis * sinHalfAngle;
quat.z = zAxis * sinHalfAngle;
quat.w = cosHalfAngle;
}

function SpinnerSystem(time) {
for (const node of spinnerQuery) {
const spinner = node.getComponent(Spinner);
setRotationAxis(node.rotation, spinner.axis, time * spinner.speed);
}
}

world.onupdate = (dt, time) => {
SpinnerSystem(time);
};
Binary file modified examples/network/c/build/networked-example.wasm
Binary file not shown.
10 changes: 6 additions & 4 deletions examples/network/c/src/networked-example.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <stdbool.h>
#include <string.h>
#include "../../../../src/engine/scripting/emscripten/src/websg.h"
#include "../../../../src/engine/scripting/emscripten/src/websg-network.h"
#include "../../../../src/engine/scripting/emscripten/src/websg-networking.h"

node_id_t material_button;
node_id_t room1_switch;
Expand All @@ -23,6 +23,8 @@ bool material_button_state = true;
bool room1_switch_state = true;
bool room2_switch_state = true;

network_listener_id_t network_listener;

int PACKET_BYTES = 3;
bool entered = false;

Expand Down Expand Up @@ -67,12 +69,12 @@ export void websg_load() {

export void websg_enter() {
entered = true;
websg_network_listen();
network_listener = websg_network_listen();
}

export void websg_update(float_t dt) {
// consume net packets
while (entered && websg_network_receive(inbound_network_packet, PACKET_BYTES) > 0) {
while (entered && websg_network_listener_receive(network_listener, inbound_network_packet, PACKET_BYTES) > 0) {
// material_button
material_button_state = inbound_network_packet[0];
websg_material_set_base_color_texture(left_cube_material, material_button_state ? planks_texture : bricks_texture);
Expand Down Expand Up @@ -113,6 +115,6 @@ export void websg_update(float_t dt) {
outbound_network_packet[1] = room1_switch_state ? 1 : 0;
outbound_network_packet[2] = room2_switch_state ? 1 : 0;

websg_network_broadcast(outbound_network_packet, PACKET_BYTES);
websg_network_broadcast(outbound_network_packet, PACKET_BYTES, 1, 1);
}
}
18 changes: 10 additions & 8 deletions examples/physics/js/physics-example.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
let boxNode3;

world.onenter = () => {
const scene = world.environment;

Expand Down Expand Up @@ -33,9 +31,10 @@ world.onenter = () => {
collider: world.createCollider({ type: "box", size: [1, 1, 1] }),
});
boxNode2.addPhysicsBody({ type: WebSG.PhysicsBodyType.Kinematic });
boxNode2.addInteractable();
scene.addNode(boxNode2);

boxNode3 = world.createNode({
const boxNode3 = world.createNode({
translation: [-2, 2, 0],
mesh: world.createBoxMesh({
size: [1, 1, 1],
Expand All @@ -49,11 +48,14 @@ world.onenter = () => {
collider: world.createCollider({ type: "box", size: [1, 1, 1] }),
});
boxNode3.addPhysicsBody({ type: WebSG.PhysicsBodyType.Kinematic });
scene.addNode(boxNode3);
};
boxNode3.addInteractable({ type: WebSG.InteractableType.Interactable });

const translation = new Float32Array([-2, 2, 0]);
scene.addNode(boxNode3);

world.onupdate = (dt, elapsed) => {
if (boxNode3) boxNode3.translation[1] = Math.sin(elapsed) * 1 + 2;
world.onupdate = (dt, elapsed) => {
boxNode3.translation[1] = Math.sin(elapsed) * 1 + 2;
if (boxNode3.interactable.pressed) {
boxNode3.startOrbit();
}
};
};
150 changes: 150 additions & 0 deletions examples/platformer/js/platformer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
const Player = world.findComponentStoreByName("Player");
const Mover = world.findComponentStoreByName("Mover");
const Spinner = world.findComponentStoreByName("Spinner");
const Coin = world.findComponentStoreByName("Coin");
const ExtraLife = world.findComponentStoreByName("ExtraLife");
const Obstacle = world.findComponentStoreByName("Obstacle");
const Conveyer = world.findComponentStoreByName("Conveyer");
const Checkpoint = world.findComponentStoreByName("Checkpoint");
const Goal = world.findComponentStoreByName("Goal");

const moverQuery = world.createQuery([Mover]);
const spinnerQuery = world.createQuery([Spinner]);
const coinQuery = world.createQuery([Coin]);
const extraLifeQuery = world.createQuery([ExtraLife]);
const obstacleQuery = world.createQuery([Obstacle]);
const conveyerQuery = world.createQuery([Conveyer]);
const checkpointQuery = world.createQuery([Checkpoint]);
const goalQuery = world.createQuery([Goal]);

function MoverSystem(time) {
for (const node of moverQuery) {
node.position.lerp(node.startPosition, node.endPosition, time / node.duration);
}
}

function SpinnerSystem(time) {
for (const node of spinnerQuery) {
const spinner = node.getComponent(Spinner);
node.rotation.setRotationAxis(spinner.axis, time * spinner.speed);
}
}

function CoinSystem() {
for (const node of coinQuery) {
for (const collision of node.physicsBody.getCollisions()) {
const coin = node.getComponent(Coin);
const player = collision.node.getComponent(Player);

if (!coin.taken && player) {
node.audioEmitter.play();
node.visible = false;
coin.taken = true;
player.coins++;
}
}
}
}

function ExtraLifeSystem() {
for (const node of extraLifeQuery) {
for (const collision of node.physicsBody.getCollisions()) {
const extraLife = node.getComponent(ExtraLife);
const player = collision.node.getComponent(Player);

if (!extraLife.taken && player) {
node.audioEmitter.play();
node.visible = false;
extraLife.taken = true;
player.lives++;
}
}
}
}

function ObstacleSystem() {
for (const node of obstacleQuery) {
for (const collision of node.physicsBody.getCollisions()) {
const player = collision.node.getComponent(Player);

if (player) {
node.audioEmitter.play();
player.translation = player.lastSpawnPoint.translation;
player.rotation = player.lastSpawnPoint.rotation;
player.lives--;

if (player.lives == 0) {
// TODO: Game Over Screen
}
}
}
}
}

let conveyerMaterial;
const conveyerSpeed = 1;

function ConveyerSystem() {
for (const node of conveyerQuery) {
for (const collision of node.physicsBody.getCollisions()) {
const player = collision.node.getComponent(Player);

if (player) {
}
}
}

conveyerMaterial.baseColorTextureOffset.y += conveyerSpeed * dt;
}

function ScrollingMaterialSystem(dt) {
for (const material of scrollingMaterialQuery) {
}
}

function CheckpointSystem() {
for (const node of checkPointQuery) {
for (const collision of node.physicsBody.getCollisions()) {
const player = collision.node.getComponent(Player);

if (player) {
node.audioEmitter.play();
player.lastSpawnPoint = node;
}
}
}
}

function GoalSystem() {
for (const node of goalQuery) {
for (const collision of node.physicsBody.getCollisions()) {
const player = collision.node.getComponent(Player);

if (player) {
node.audioEmitter.play();

// TODO: Show Game Win Screen
}
}
}
}

world.onload = () => {
conveyerMaterial = world.findMaterialByName("ConveyerMaterial");
};

world.onenter = (playerRig) => {
playerRig.addComponent(Player);
};

world.onupdate = (dt, time) => {
MoverSystem(time);
SpinnerSystem(time);
ConveyerSystem();
ScrollingMaterialSystem(dt);
CoinSystem();
ExtraLifeSystem();
ObstacleSystem();
CheckpointSystem();
GoalSystem();
};
Loading

0 comments on commit fe40201

Please sign in to comment.