Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
GEM
remote: https://rubygems.org/
specs:
action_text-trix (2.1.16)
action_text-trix (2.1.17)
railties
actioncable (8.1.2)
actionpack (= 8.1.2)
Expand Down Expand Up @@ -115,7 +115,7 @@ GEM
delayed_job_active_record (4.1.11)
activerecord (>= 3.0, < 9.0)
delayed_job (>= 3.0, < 5)
devise (5.0.2)
devise (5.0.3)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 7.0)
Expand Down Expand Up @@ -196,7 +196,7 @@ GEM
prism (>= 1.3.0)
rdoc (>= 4.0.0)
reline (>= 0.4.2)
json (2.19.1)
json (2.19.2)
jsonapi-renderer (0.2.2)
jwt (3.1.2)
base64
Expand All @@ -218,7 +218,7 @@ GEM
activesupport (>= 4)
railties (>= 4)
request_store (~> 1.0)
loofah (2.25.0)
loofah (2.25.1)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
mail (2.9.0)
Expand Down Expand Up @@ -360,14 +360,14 @@ GEM
rspec-mocks (3.13.8)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-rails (8.0.3)
rspec-rails (8.0.4)
actionpack (>= 7.2)
activesupport (>= 7.2)
railties (>= 7.2)
rspec-core (~> 3.13)
rspec-expectations (~> 3.13)
rspec-mocks (~> 3.13)
rspec-support (~> 3.13)
rspec-core (>= 3.13.0, < 5.0.0)
rspec-expectations (>= 3.13.0, < 5.0.0)
rspec-mocks (>= 3.13.0, < 5.0.0)
rspec-support (>= 3.13.0, < 5.0.0)
rspec-support (3.13.7)
rspec_junit_formatter (0.6.0)
rspec-core (>= 2, < 4, != 2.12.0)
Expand Down Expand Up @@ -409,7 +409,7 @@ GEM
useragent (0.16.11)
warden (1.2.9)
rack (>= 2.0.9)
webmock (3.26.1)
webmock (3.26.2)
addressable (>= 2.8.0)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)
Expand Down
52 changes: 26 additions & 26 deletions bun.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions config/initializers/mutations.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require Rails.root.join("app/lib/mutations/hstore_filter")

MUTATIONS_DEFAULTS = Mutations::DefaultErrorMessageCreator::MESSAGES

# I don't like the errors that mutations provides for :before and :after,
Expand Down
24 changes: 23 additions & 1 deletion frontend/three_d_garden/__tests__/fps_probe_test.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import React from "react";
import { render } from "@testing-library/react";
import * as threeFiber from "@react-three/fiber";
import { countSceneObjects, FPSProbe } from "../fps_probe";
import { countSceneObjects, FPSProbe, REPORT_EVERY_N } from "../fps_probe";

describe("FPSProbe", () => {
let useFrameSpy: jest.SpyInstance;
let useThreeSpy: jest.SpyInstance;

beforeEach(() => {
window.logStore = undefined;
useFrameSpy = jest.spyOn(threeFiber, "useFrame")
.mockImplementation(jest.fn());
useThreeSpy = jest.spyOn(threeFiber, "useThree")
Expand Down Expand Up @@ -92,6 +93,27 @@ describe("FPSProbe", () => {
nowSpy.mockRestore();
});

it("logs an fps report every nth probe", () => {
let t = 0;
const nowSpy = jest.spyOn(performance, "now").mockImplementation(() => {
t += 2000;
return t;
});
window.logStore = { log: jest.fn() };
render(<FPSProbe />);
const frameHandler = useFrameSpy.mock.calls[0][0] as () => void;
for (let i = 0; i < 100; i++) {
frameHandler();
frameHandler();
}
expect(window.logStore.log).toHaveBeenCalledWith(
"3D Garden FPS",
{ average: 1, best: 1, total: REPORT_EVERY_N, worst: 1 },
"info",
);
nowSpy.mockRestore();
});

it("counts scene objects", () => {
const objects = [
{ isMesh: true, type: "Mesh", name: "soil" },
Expand Down
57 changes: 28 additions & 29 deletions frontend/three_d_garden/bot/components/bounds.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import React from "react";
import { Config } from "../../config";
import { Line } from "@react-three/drei";
import { Group } from "../../components";
import { Box, Edges } from "@react-three/drei";
import { Group, MeshBasicMaterial } from "../../components";
import {
threeSpace,
zero as zeroFunc,
extents as extentsFunc,
zZero as zZeroFunc,
zDir as zDirFunc,
} from "../../helpers";
import { DistanceIndicator } from "../../elements";
import { BackSide } from "three";

export interface BoundsProps {
config: Config;
Expand All @@ -19,33 +18,33 @@ export const Bounds = (props: BoundsProps) => {
const {
bedLengthOuter, bedWidthOuter, x, y, z,
zAxisLength, columnLength, beamLength, bounds,
bedXOffset, bedYOffset,
bedXOffset, bedYOffset, botSizeX, botSizeY, botSizeZ,
} = props.config;
const zZero = zZeroFunc(props.config);
const zDir = zDirFunc(props.config);
const zero = zeroFunc(props.config);
const extents = extentsFunc(props.config);
const zDip = (x: number, y: number): [number, number, number][] => [
[x, y, extents.z],
[x, y, zero.z],
[x, y, extents.z],
];
return <Group name={"bounds-and-distances"}>
<Line name={"bounds"}
<Box name={"bounds"}
visible={bounds}
color={"white"}
points={[
[zero.x, zero.y, zero.z],
[zero.x, extents.y, zero.z],
[extents.x, extents.y, zero.z],
[extents.x, zero.y, zero.z],
[zero.x, zero.y, zero.z],
...zDip(zero.x, zero.y),
...zDip(zero.x, extents.y),
...zDip(extents.x, extents.y),
...zDip(extents.x, zero.y),
[zero.x, zero.y, extents.z],
]} />
position={[
zero.x + botSizeX / 2,
zero.y + botSizeY / 2,
zero.z - botSizeZ / 2,
]}
args={[
botSizeX,
botSizeY,
botSizeZ,
]}>
<MeshBasicMaterial
side={BackSide}
depthWrite={false}
transparent={true}
opacity={0} />
<Edges
lineWidth={1.1}
color={"white"}
threshold={1} />
</Box>
<Group visible={props.config.zDimension}>
<DistanceIndicator
start={{
Expand All @@ -56,7 +55,7 @@ export const Bounds = (props: BoundsProps) => {
end={{
x: threeSpace(0, bedLengthOuter),
y: threeSpace(bedWidthOuter, bedWidthOuter),
z: zZero - z + zAxisLength,
z: zero.z - z + zAxisLength,
}} />
</Group>
<Group visible={props.config.distanceIndicator == "beamLength"}>
Expand Down Expand Up @@ -90,12 +89,12 @@ export const Bounds = (props: BoundsProps) => {
start={{
x: threeSpace(x + 100, bedLengthOuter) + bedXOffset,
y: threeSpace(y, bedWidthOuter) + bedYOffset,
z: zZero - zDir * z,
z: zero.z - zDir * z,
}}
end={{
x: threeSpace(x + 100, bedLengthOuter) + bedXOffset,
y: threeSpace(y, bedWidthOuter) + bedYOffset,
z: zZero - zDir * z + zAxisLength,
z: zero.z - zDir * z + zAxisLength,
}} />
</Group>
</Group>;
Expand Down
17 changes: 17 additions & 0 deletions frontend/three_d_garden/fps_probe.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,13 @@ const formatTopCounts = (
return entries.map(([key, value]) => `${key}: ${value}`).join(", ");
};

export const REPORT_EVERY_N = 60;

export const FPSProbe = () => {
const frameCount = React.useRef(0);
const lastTime = React.useRef<number | undefined>(undefined);
const reportCount = React.useRef(0);
const samples = React.useRef<number[]>([]);
const { gl, scene } = useThree();

React.useEffect(() => {
Expand All @@ -77,6 +81,7 @@ export const FPSProbe = () => {
if (now - lastTime.current >= 1000) {
const elapsed = (now - lastTime.current) / 1000;
const fps = frameCount.current / elapsed;
samples.current.push(fps);
const { calls, triangles, points, lines } = gl.info.render;
const { geometries, textures } = gl.info.memory;
const sceneCounts = countSceneObjects(scene as Scene);
Expand All @@ -103,6 +108,18 @@ export const FPSProbe = () => {
.map(([key, value]) => `${key}: ${value}`)
.join("\n");
console.log(linesToLog);
reportCount.current += 1;
const doReport = !(reportCount.current % REPORT_EVERY_N);
const average = Math.round(samples.current
.reduce((sum, sample) => sum + sample, 0) / samples.current.length);
const report = {
best: Math.round(Math.max(...samples.current)),
worst: Math.round(Math.min(...samples.current)),
average,
total: samples.current.length,
};
doReport && window.logStore?.log("3D Garden FPS", report, "info");
console.log(report);
frameCount.current = 0;
lastTime.current = now;
}
Expand Down
17 changes: 11 additions & 6 deletions lib/tasks/api.rake
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,17 @@ namespace :api do
src = "node_modules/monaco-editor/min/vs"
dst = "public/assets/monaco"
lua_src = "node_modules/monaco-editor/esm/vs"
lua = "basic-languages/lua"
sh "mkdir -p public/assets/"
sh "cp -r #{src} #{dst}"
sh "rm -rf #{dst}/*language*"
sh "mkdir #{dst}/basic-languages"
sh "cp -r #{lua_src}/#{lua} #{dst}/#{lua}"
sh "mkdir -p public/assets/monaco"
sh "cp -r #{src}/assets #{dst}"
sh "cp -r #{src}/editor #{dst}"
sh "cp -r #{src}/basic-languages #{dst}"
sh "cp -r #{src}/loader.js #{dst}"
sh "cp -r #{src}/workers-*.js #{dst}"
sh "cp -r #{src}/monaco.contribution-*.js #{dst}"
sh "cp -r #{src}/editor.api-*.js #{dst}"
sh "cp -r #{src}/nls.messages-loader.js #{dst}"
sh "cp -r #{src}/lua-*.js #{dst}"
sh "cp -r #{lua_src}/basic-languages/lua #{dst}/basic-languages"
end

desc "Serve javascript assets (via Bun bundler)."
Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
"mqtt": "mqtt/dist/mqtt.esm.js"
},
"dependencies": {
"@blueprintjs/core": "6.9.1",
"@blueprintjs/select": "6.1.3",
"@blueprintjs/core": "6.10.0",
"@blueprintjs/select": "6.1.4",
"@monaco-editor/react": "4.7.0",
"@react-spring/three": "10.0.3",
"@react-three/drei": "10.7.7",
Expand All @@ -61,7 +61,7 @@
"farmbot": "15.9.3",
"fengari": "0.1.5",
"fengari-web": "0.1.4",
"i18next": "25.8.17",
"i18next": "25.8.18",
"lodash": "4.17.23",
"markdown-it": "14.1.1",
"markdown-it-emoji": "3.0.0",
Expand All @@ -80,7 +80,7 @@
"redux": "5.0.1",
"redux-immutable-state-invariant": "2.1.0",
"redux-thunk": "3.1.0",
"rollbar": "3.0.0",
"rollbar": "3.1.0",
"suncalc": "1.9.0",
"takeme": "0.12.0",
"three": "0.183.2",
Expand All @@ -89,7 +89,7 @@
},
"devDependencies": {
"@eslint/js": "10.0.1",
"@happy-dom/global-registrator": "20.8.3",
"@happy-dom/global-registrator": "20.8.4",
"@react-three/eslint-plugin": "0.1.2",
"@testing-library/dom": "10.4.1",
"@testing-library/jest-dom": "6.9.1",
Expand All @@ -99,9 +99,9 @@
"@types/jest": "30.0.0",
"@types/readable-stream": "4.0.23",
"@types/suncalc": "1.9.2",
"@typescript-eslint/eslint-plugin": "8.57.0",
"@typescript-eslint/parser": "8.57.0",
"happy-dom": "20.8.3",
"@typescript-eslint/eslint-plugin": "8.57.1",
"@typescript-eslint/parser": "8.57.1",
"happy-dom": "20.8.4",
"eslint": "10.0.3",
"eslint-plugin-eslint-comments": "3.2.0",
"eslint-plugin-import": "2.32.0",
Expand Down
Loading