From 96ef8ccba3a86bc9bb48c5242fa719e8599d565e Mon Sep 17 00:00:00 2001 From: John Alanbrook Date: Fri, 21 Feb 2025 16:58:36 -0600 Subject: [PATCH] Add camera and debug modules --- .github/workflows/build.yml | 11 +- docs/api/modules/camera.md | 46 ++ docs/api/modules/debug.md | 76 +++ docs/api/modules/imgui.md | 1243 +++++++++++++++++++++++++++++++++++ docs/api/modules/input.md | 20 - docs/api/modules/io.md | 9 +- docs/api/prosperon.md | 68 -- docs/dull/Array.md | 661 +++++++++++++++++++ scripts/modules/camera.js | 26 + scripts/modules/cmd.js | 59 +- scripts/modules/debug.js | 42 ++ scripts/modules/render.js | 2 +- source/jsffi.c | 42 +- 13 files changed, 2145 insertions(+), 160 deletions(-) create mode 100644 docs/api/modules/camera.md create mode 100644 docs/api/modules/debug.md create mode 100644 docs/dull/Array.md create mode 100644 scripts/modules/camera.js create mode 100644 scripts/modules/debug.js diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2e8f6c56..a929dece 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -54,11 +54,20 @@ jobs: - name: Check Out Code uses: actions/checkout@v4 + - name: Cache MSYS2 + uses: actions/cache@v3 + with: + path: C:\msys64 + key: ${{ runner.os }}-msys2-${{ matrix.msystem }}-${{ hashFiles('**/lockfiles', '.github/workflows/*.yml') }} + restore-keys: | + ${{ runner.os }}-msys2-${{ matrix.msystem }}- + - name: Setup MSYS2 uses: msys2/setup-msys2@v2 with: msystem: ${{ matrix.msystem }} update: true + cache: false install: | git zip @@ -155,7 +164,6 @@ jobs: if: ${{ false }} runs-on: ubuntu-latest steps: - # [Deploy-itch steps remain unchanged] - name: Check Out Code uses: actions/checkout@v3 with: @@ -186,7 +194,6 @@ jobs: needs: [package-dist] runs-on: ubuntu-latest steps: - # [Deploy-gitea steps remain unchanged] - name: Check Out Code uses: actions/checkout@v3 with: diff --git a/docs/api/modules/camera.md b/docs/api/modules/camera.md new file mode 100644 index 00000000..741ed994 --- /dev/null +++ b/docs/api/modules/camera.md @@ -0,0 +1,46 @@ +# camera + +### list() function + +Return an array of available camera device IDs. + + + +**Returns**: An array of camera IDs, or undefined if no cameras are available. + + +### open(id) function + +Open a camera device with the given ID. + + + +**id**: The camera ID to open. + + +**Returns**: A camera object on success, or throws an error if the camera cannot be opened. + + +### name(id) function + +Return the name of the camera with the given ID. + + + +**id**: The camera ID to query. + + +**Returns**: A string with the camera's name, or throws an error if the name cannot be retrieved. + + +### position(id) function + +Return the physical position of the camera with the given ID. + + + +**id**: The camera ID to query. + + +**Returns**: A string indicating the camera position ("unknown", "front", or "back"). + diff --git a/docs/api/modules/debug.md b/docs/api/modules/debug.md new file mode 100644 index 00000000..c3017e44 --- /dev/null +++ b/docs/api/modules/debug.md @@ -0,0 +1,76 @@ +# debug + +### stack_depth() function + +Return the current stack depth. + + + +**Returns**: A number representing the stack depth. + + +### build_backtrace() function + +Build and return a backtrace of the current call stack. + + + +**Returns**: An object representing the call stack backtrace. + + +### closure_vars(fn) function + +Return the closure variables for a given function. + + + +**fn**: The function object to inspect. + + +**Returns**: An object containing the closure variables. + + +### local_vars(depth) function + +Return the local variables for a specific stack frame. + + + +**depth**: The stack frame depth to inspect. + + +**Returns**: An object containing the local variables at the specified depth. + + +### fn_info(fn) function + +Return metadata about a given function. + + + +**fn**: The function object to inspect. + + +**Returns**: An object with metadata about the function. + + +### backtrace_fns() function + +Return an array of functions in the current backtrace. + + + +**Returns**: An array of function objects from the call stack. + + +### dump_obj(obj) function + +Return a string representation of a given object. + + + +**obj**: The object to dump. + + +**Returns**: A string describing the object's contents. + diff --git a/docs/api/modules/imgui.md b/docs/api/modules/imgui.md index b00474ac..4d129a85 100644 --- a/docs/api/modules/imgui.md +++ b/docs/api/modules/imgui.md @@ -1 +1,1244 @@ # imgui + +### windowpos() function + +Return the position of the current ImGui window as an ImVec2. + + + +**Returns**: A 2-element array [x, y] representing the top-left corner of the current window in screen coordinates. + + +### plot2pixels(coords) function + +Convert a point from plot coordinates to pixel coordinates in the current ImPlot. + + + +**coords**: A 2-element array [x, y] in plot coordinates. + + +**Returns**: A 2-element array [x, y] in pixel coordinates, mapped from the current ImPlot. + + +### plotpos() function + +Return the top-left corner of the current ImPlot region in screen (pixel) coordinates. + + + +**Returns**: A 2-element array [x, y] representing the position of the current ImPlot in screen coordinates. + + +### plotlimits() function + +Retrieve the current plot’s axis limits (min/max) for both X and Y axes. + + + +**Returns**: An object { x: { min, max }, y: { min, max } } describing the current plot’s visible axis ranges. + + +### setaxes(xAxis, yAxis) function + +Switch the active axes in ImPlot (useful if multiple axes exist). + + + +**xAxis**: The x-axis index (0..2). + +**yAxis**: The y-axis index (0..2). + + +**Returns**: None + + +### setupaxis(axis) function + +Setup the specified axis in the current ImPlot (e.g., for customizing tick labels). + + + +**axis**: The numeric index of the axis (0..2). + + +**Returns**: None + + +### inplot(coords) function + +Check if the given point is within the current ImPlot's visible region. + + + +**coords**: A 2-element array [x, y] in plot coordinates. + + +**Returns**: True if the point is within the visible plot region, otherwise false. + + +### window(title, callback) function + +Create a new ImGui window with the given title and invoke the callback to render inside it. + + + +**title**: The text displayed as the window title. + +**callback**: A function called to render the contents of the window. + + +**Returns**: A boolean indicating if the window is still active (open) after rendering. + + +### menu(label, callback) function + +Create a new menu entry in a menu bar or menu. The callback is invoked to populate the menu if opened. + + + +**label**: The label of the menu (visible in the menubar). + +**callback**: A function called to render menu items when the menu is open. + + +**Returns**: None + + +### sameline(offset) function + +Place the next widget on the same line, optionally specifying a horizontal offset. + + + +**offset**: A float offset from the current cursor position. If omitted, defaults to 0. + + +**Returns**: None + + +### int(label, value) function + +Display an integer input box with a label. + + + +**label**: The label text for the input. + +**value**: The initial integer value. + + +**Returns**: The updated integer value after user edits. + + +### pushid(id) function + +Push an integer ID onto the ImGui ID stack. + + + +**id**: An integer used to differentiate widgets/items with the same label. + + +**Returns**: None + + +### popid() function + +Pop an ID off the ImGui ID stack. + + + +**Returns**: None + + +### slider(label, value, minValue, maxValue) function + +Create a float slider (or multi-float sliders if given an array) within the specified range. + + + +**label**: The slider label text. + +**value**: A single float or an array of floats (e.g., [r,g,b,a]). + +**minValue**: The minimum slider value. + +**maxValue**: The maximum slider value. + + +**Returns**: The updated float or array of floats after user adjustment. + + +### intslider(label, value, minValue, maxValue) function + +Create an integer slider (or multiple integer sliders if given a typed array) in the specified range. + + + +**label**: The slider label text. + +**value**: A single integer or a typed array of integers (for multi-component sliders). + +**minValue**: The minimum integer value. + +**maxValue**: The maximum integer value. + + +**Returns**: The updated integer or array of integers after user adjustment. + + +### menubar(callback) function + +Begin rendering a menubar. The callback is invoked to create menu items. Ends automatically. + + + +**callback**: A function that creates menu items within the menubar. + + +**Returns**: None + + +### mainmenubar(callback) function + +Create the main menu bar at the top of the screen. The callback is invoked for populating it. + + + +**callback**: A function to render items in the main menu bar. + + +**Returns**: None + + +### menuitem(label, shortcut, callback, selected) function + +Create a menu item that can optionally be toggled. If selected, calls the provided callback. + + + +**label**: The text label of the menu item. + +**shortcut**: An optional shortcut text to display (e.g. "Ctrl+S"). + +**callback**: A function called if the user clicks or activates this item. + +**selected**: A boolean indicating whether this menu item is toggled or not. + + +**Returns**: A boolean reflecting the toggled state. + + +### radio(label, active) function + +Create a radio button. + + + +**label**: The text label for the radio button. + +**active**: Whether this radio button is currently selected. + + +**Returns**: True if this radio button is now selected by the user, otherwise false. + + +### image(texture) function + +Render a texture as an image at a default size (100x100). + + + +**texture**: The GPU texture to display. + + +**Returns**: None + + +### imagebutton(label, texture, callback) function + +Create an ImageButton widget which displays a texture; calls the callback when clicked. + + + +**label**: A string identifier (not visually used). + +**texture**: The GPU texture to display on the button. + +**callback**: A function called when the button is clicked. + + +**Returns**: None + + +### textinput(label, text) function + +Show a single-line text input widget. + + + +**label**: The label text next to the input box. + +**text**: The current text. If undefined, the box starts empty. + + +**Returns**: The updated text string after user editing. + + +### textbox(label, text) function + +Show a multi-line text input widget. + + + +**label**: The label text next to the input box. + +**text**: The current multi-line text. If undefined, starts empty. + + +**Returns**: The updated text after user editing. + + +### button(label, callback) function + +Create a button. The callback fires if the user clicks it. + + + +**label**: The text displayed on the button. + +**callback**: The function called on click. + + +**Returns**: None + + +### checkbox(label, checked) function + +Create a checkbox to toggle a boolean value. + + + +**label**: The text label for the checkbox. + +**checked**: The current boolean state. + + +**Returns**: The updated boolean state after user toggle. + + +### text(text) function + +Render a line of text in the ImGui window. + + + +**text**: The string to display. + + +**Returns**: None + + +### plot(title, callback) function + +Begin a new ImPlot region with the specified title. Calls the callback to render plot contents. + + + +**title**: The title (label) of the plot. + +**callback**: A function that sets up and draws within the ImPlot region. + + +**Returns**: None + + +### lineplot(label, data, shaded, lastPoint) function + +Plot a line graph in the current ImPlot. + + + +**label**: The label for the line plot. + +**data**: An array of [x,y] points or a single array of y-values. + +**shaded**: Boolean indicating if the area under the line should be filled. + +**lastPoint**: (Optional) Additional point or frame usage. (Currently partial/placeholder in code.) + + +**Returns**: None + + +### scatterplot(label, data, shaded, lastPoint) function + +Plot a scatter graph in the current ImPlot. + + + +**label**: The label for the scatter plot. + +**data**: An array of [x,y] points or a single array of y-values. + +**shaded**: Typically unused for scatter. + +**lastPoint**: (Optional) Additional param if needed. + + +**Returns**: None + + +### stairplot(label, data, shaded, lastPoint) function + +Plot a stair-step graph in the current ImPlot. + + + +**label**: The label for the stair plot. + +**data**: An array of [x,y] points or a single array of y-values. + +**shaded**: A boolean to fill under the stair-step line. + +**lastPoint**: (Optional) Extended data usage if needed. + + +**Returns**: None + + +### digitalplot(label, data, shaded, lastPoint) function + +Plot a digital (step-like) graph in the current ImPlot. + + + +**label**: The label for the digital plot. + +**data**: An array of [x,y] points or a single array of y-values. + +**shaded**: Typically not used for digital plots. + +**lastPoint**: (Optional) Extended data usage if needed. + + +**Returns**: None + + +### barplot(label, data, width) function + +Plot a bar chart in the current ImPlot. + + + +**label**: The label for the bar series. + +**data**: An array of [x,y] points or just an array of y-values. + +**width**: The width of each bar in plot units. + + +**Returns**: None + + +### textplot(text, coords) function + +Render text at the specified coordinates in plot space. + + + +**text**: The string to render. + +**coords**: A 2-element array [x, y] in plot coordinates. + + +**Returns**: None + + +### histogramplot(label, data) function + +Plot a histogram from the given data array/typed array in the current ImPlot. + + + +**label**: The label for the histogram. + +**data**: A typed array (or numeric array) containing the values to bin/display. + + +**Returns**: None + + +### plotaxes(xLabel, yLabel) function + +Set up labels for the X and Y axes of the current ImPlot. + + + +**xLabel**: The label for the x-axis. + +**yLabel**: The label for the y-axis. + + +**Returns**: None + + +### plotmousepos() function + +Get the mouse cursor’s position in the current plot’s coordinate system. + + + +**Returns**: A 2-element array [x, y] representing the mouse position in plot coordinates. + + +### plothovered() function + +Check if the mouse is hovering over the current ImPlot. + + + +**Returns**: True if the plot area is hovered, otherwise false. + + +### axeslimits(xMin, xMax, yMin, yMax) function + +Set up the visible axis limits in the current ImPlot. + + + +**xMin**: The left (min) bound of the x-axis. + +**xMax**: The right (max) bound of the x-axis. + +**yMin**: The bottom (min) bound of the y-axis. + +**yMax**: The top (max) bound of the y-axis. + + +**Returns**: None + + +### prepend(commandBuffer) function + +Prepare ImGui draw data for rendering, typically called after ImGui::Render(). + + + +**commandBuffer**: The SDL GPU command buffer where draw data will be queued. + + +**Returns**: None + + +### fitaxis(axis) function + +Fit either the x-axis or y-axis to its data range on the next plot frame. + + + +**axis**: 0 for X-axis, 1 for Y-axis. + + +**Returns**: None + + +### columns(count) function + +Switch the layout to use a specified number of columns. + + + +**count**: The number of columns to layout in the current region. + + +**Returns**: None + + +### nextcolumn() function + +Advance to the next column in a multi-column layout. + + + +**Returns**: None + + +### collapsingheader(label) function + +Create a collapsible header. Returns true if it is open (expanded). + + + +**label**: The text label of the header. + + +**Returns**: True if the header is expanded, otherwise false. + + +### tree(label, callback) function + +Create a tree node. If opened, calls the callback for nested content. + + + +**label**: The label for the tree node. + +**callback**: A function called if the node is expanded. + + +**Returns**: None + + +### listbox(label, items, selectedIndex) function + +Create a list box widget to select from a list of strings. + + + +**label**: The label next to the list box. + +**items**: An array of strings to display. + +**selectedIndex**: The currently selected index. + + +**Returns**: The updated selected index after user selection. + + +### axisfmt(axis, callback) function + +Set a custom formatter for a specified y-axis in ImPlot. + + + +**axis**: The y-axis index (0..2) to format. + +**callback**: A function(value) => string that converts axis values to text. + + +**Returns**: None + + +### tabbar(label, callback) function + +Begin a tab bar container. The callback is invoked to create tabs. + + + +**label**: The identifier label of the tab bar. + +**callback**: A function that creates tab items. + + +**Returns**: None + + +### tab(label, callback) function + +Create a tab item. If selected, calls the callback for tab content. + + + +**label**: The name of the tab. + +**callback**: A function to render the tab’s content if active. + + +**Returns**: None + + +### open_popup(label) function + +Open a popup by its identifier. + + + +**label**: The identifier of the popup to open. + + +**Returns**: None + + +### modal(label, callback) function + +Begin a modal popup. The callback is invoked to display contents if the modal is open. + + + +**label**: The identifier of the modal popup. + +**callback**: A function for rendering the modal’s UI if open. + + +**Returns**: None + + +### popup(label, callback) function + +Begin a popup. The callback is invoked if the popup is open. + + + +**label**: The identifier of the popup. + +**callback**: A function for rendering the popup’s UI. + + +**Returns**: None + + +### close_popup() function + +Close the current popup. + + + +**Returns**: None + + +### context(label, callback) function + +Create a popup context menu. The callback is invoked if the menu opens. + + + +**label**: The identifier for the context menu. + +**callback**: A function that renders menu items in the context. + + +**Returns**: None + + +### table(label, columns, callback, sortCallback) function + +Create a table with multiple columns. Optionally enable sorting and pass a sort callback. + + + +**label**: The identifier for the table. + +**columns**: The number of columns. + +**callback**: A function to populate the table (rows/cells). + +**sortCallback**: An optional function(columnIndex, ascending) called if user sorts a column. + + +**Returns**: None + + +### tablenextcolumn() function + +Move to the next column in a table row. + + + +**Returns**: None + + +### tablenextrow() function + +Move to the next row in a table. + + + +**Returns**: None + + +### tableheadersrow() function + +Create a row of headers in the current table (should be called once after column setup). + + + +**Returns**: None + + +### tableangledheadersrow() function + +Create an angled header row (for advanced usage). Typically not used as often. + + + +**Returns**: None + + +### tablesetupcolumn(label) function + +Setup configuration for a single column in the table. + + + +**label**: The label/header text for this column. + + +**Returns**: None + + +### dnd(type, payload, callback) function + +Begin a drag source for custom data payload. + + + +**type**: A string identifier for the drag-drop payload type. + +**payload**: A numeric payload stored in the drag-drop. + +**callback**: (Currently unused) Placeholder if you want to do extra on drag start. + + +**Returns**: None + + +### dndtarget(type, callback) function + +Create a drop target for matching drag-drop payload type. Invokes callback on drop. + + + +**type**: A string identifier for the drag-drop payload type to accept. + +**callback**: A function(payloadNumber) called when a matching payload is dropped. + + +**Returns**: None + + +### color(label, color) function + +Create a color editor (3 or 4 floats). Returns the updated color. + + + +**label**: The label for the color editor. + +**color**: An array [r,g,b] or [r,g,b,a]. + + +**Returns**: Updated color array after user input. + + +### startnode(callback, linkCreatedCallback, nodeHoveredCallback, linkHoveredCallback) function + +Begin a node editor session with ImNodes. The callback defines nodes. +Additional callbacks handle link creation and hover events. + + + +**callback**: A function to define node editor contents (adding nodes, etc). + +**linkCreatedCallback**: A function(startAttr, endAttr) called when a new link is created. + +**nodeHoveredCallback**: A function(nodeId) called when a node is hovered. + +**linkHoveredCallback**: A function(linkId) called when a link is hovered. + + +**Returns**: None + + +### node(nodeId, callback) function + +Begin a node with a unique ID, then call the callback to define its contents. + + + +**nodeId**: A unique integer ID for this node. + +**callback**: A function that populates the node’s UI. + + +**Returns**: None + + +### nodein(attributeId, callback) function + +Create an input attribute in the current node. + + + +**attributeId**: The attribute ID for this input. + +**callback**: A function that defines the UI within the input attribute. + + +**Returns**: None + + +### nodeout(attributeId, callback) function + +Create an output attribute in the current node. + + + +**attributeId**: The attribute ID for this output. + +**callback**: A function that defines the UI within the output attribute. + + +**Returns**: None + + +### nodelink(linkId, startAttributeId, endAttributeId) function + +Link two node attributes by their IDs. + + + +**linkId**: A unique integer ID for this link. + +**startAttributeId**: The attribute ID where the link starts. + +**endAttributeId**: The attribute ID where the link ends. + + +**Returns**: None + + +### nodemini(size) function + +Show a minimap for the current node editor. + + + +**size**: A float controlling the minimap size ratio. + + +**Returns**: None + + +### mousehoveringrect(min, max) function + +Check if the mouse is hovering within the given rectangle. + + + +**min**: A 2-element array [x, y] for the top-left corner. + +**max**: A 2-element array [x, y] for the bottom-right corner. + + +**Returns**: True if the mouse is within that rectangle, otherwise false. + + +### mouseclicked(button) function + +Check if a specific mouse button was clicked (went from up to down) this frame. + + + +**button**: An integer for the mouse button index (0 = left, 1 = right, etc). + + +**Returns**: True if the button was clicked, otherwise false. + + +### mousedown(button) function + +Check if the specified mouse button is currently held down. + + + +**button**: The mouse button index. + + +**Returns**: True if the button is down, otherwise false. + + +### mousereleased(button) function + +Check if the specified mouse button was released this frame. + + + +**button**: The mouse button index. + + +**Returns**: True if the button was released, otherwise false. + + +### mousedragging(button) function + +Check if the mouse is being dragged with the specified button. + + + +**button**: The mouse button index. + + +**Returns**: True if the mouse is dragging, otherwise false. + + +### mousedelta() function + +Get the mouse movement delta (difference) for the current frame. + + + +**Returns**: A 2-element array [dx, dy] representing the mouse movement. + + +### rect(pMin, pMax, color) function + +Draw a rectangle outline in the current window’s draw list. + + + +**pMin**: A 2-element array [x, y] for the top-left corner. + +**pMax**: A 2-element array [x, y] for the bottom-right corner. + +**color**: A 4-element array [r, g, b, a] specifying the outline color. + + +**Returns**: None + + +### rectfilled(pMin, pMax, color) function + +Draw a filled rectangle in the current window’s draw list. + + + +**pMin**: [x, y] for the top-left corner. + +**pMax**: [x, y] for the bottom-right corner. + +**color**: [r, g, b, a] fill color. + + +**Returns**: None + + +### line(p1, p2, color) function + +Draw a line between two points in the current window’s draw list. + + + +**p1**: [x, y] start position. + +**p2**: [x, y] end position. + +**color**: [r, g, b, a] line color. + + +**Returns**: None + + +### bezierquad(p1, p2, p3, color, thickness) function + +Draw a quadratic bezier curve. + + + +**p1**: [x, y] start point. + +**p2**: [x, y] control point. + +**p3**: [x, y] end point. + +**color**: [r, g, b, a] color. + +**thickness**: Line thickness. + + +**Returns**: None + + +### beziercubic(p1, p2, p3, p4, color, thickness) function + +Draw a cubic bezier curve. + + + +**p1**: [x, y] start point. + +**p2**: [x, y] first control point. + +**p3**: [x, y] second control point. + +**p4**: [x, y] end point. + +**color**: [r, g, b, a] color. + +**thickness**: Line thickness. + + +**Returns**: None + + +### point(center, radius, color) function + +Draw a filled circle (point) in the current window’s draw list. + + + +**center**: [x, y] center of the circle. + +**radius**: The radius of the circle. + +**color**: [r, g, b, a] fill color. + + +**Returns**: None + + +### drawtext(text, position, color) function + +Draw text at the given screen position with a specified color. + + + +**text**: The string to draw. + +**position**: [x, y] in screen coordinates. + +**color**: [r, g, b, a] text color. + + +**Returns**: None + + +### cursorscreenpos() function + +Get the current ImGui cursor screen position. + + + +**Returns**: A 2-element array [x, y] in screen coordinates. + + +### setcursorscreenpos(position) function + +Set the ImGui cursor screen position. + + + +**position**: A 2-element array [x, y] in screen coordinates. + + +**Returns**: None + + +### contentregionavail() function + +Return the available space in the current window’s content region. + + + +**Returns**: A 2-element array [width, height] of available space. + + +### dummy(size) function + +Add a dummy item (invisible) of the specified size to the layout. + + + +**size**: A 2-element array [width, height]. + + +**Returns**: None + + +### invisiblebutton(label, size) function + +Create an invisible button that occupies a given size and can catch clicks. + + + +**label**: The identifier for the button. + +**size**: [width, height] specifying the button area. + + +**Returns**: None + + +### width(width) function + +Set the width of the next item in the layout. + + + +**width**: The width (in pixels) for the next item. + + +**Returns**: None + + +### setclipboard(text) function + +Set the system clipboard text. + + + +**text**: The string to put into the clipboard. + + +**Returns**: None + + +### newframe() function + +Start a new ImGui frame. Should be called once per frame before rendering UI elements. + + + +**Returns**: None + + +### endframe(commandBuffer, renderPass) function + +Finalize and render the ImGui draw data to the specified command buffer and render pass. + + + +**commandBuffer**: The SDL GPU command buffer to render into. + +**renderPass**: The SDL GPU render pass used to draw ImGui data. + + +**Returns**: None + + +### wantmouse() function + +Check if ImGui wants to capture the mouse (e.g., if a window or widget needs mouse events). + + + +**Returns**: True if ImGui is capturing the mouse, otherwise false. + + +### wantkeys() function + +Check if ImGui wants to capture the keyboard (e.g., if a text input is active). + + + +**Returns**: True if ImGui is capturing the keyboard, otherwise false. + + +### init(gpuDevice, window) function + +Initialize ImGui with SDL and SDL_gpu, creating the ImGui context and configuring it. + + + +**gpuDevice**: The SDL_GPUDevice object. + +**window**: The SDL_Window object to attach ImGui onto. + + +**Returns**: None + + +### render_menu(render) function + +### prosperon_menu() function diff --git a/docs/api/modules/input.md b/docs/api/modules/input.md index 5bc62d31..f31580f4 100644 --- a/docs/api/modules/input.md +++ b/docs/api/modules/input.md @@ -66,23 +66,3 @@ and booleans for pressed buttons (left, middle, right, x1, x2). **Returns**: Object { x, y, left, middle, right, x1, x2 } - -### mouse object - -### keyboard object - -### print_pawn_kbm(pawn) function - -### procdown() function - -### print_md_kbm(pawn) function - -### has_bind(pawn, bind) function - -### action object - -### tabcomplete(val, list) function - -### do_uncontrol(pawn) function - -### player object diff --git a/docs/api/modules/io.md b/docs/api/modules/io.md index 0b237e16..23cbdb35 100644 --- a/docs/api/modules/io.md +++ b/docs/api/modules/io.md @@ -174,12 +174,17 @@ Return the application's base directory (where the executable is located). **Returns**: A string with the base directory path. -### userdir() function +### prefdir(org, app) function -Return the user's directory, often used for saving data. +Get the user-and-app-specific path where files can be written. +**org**: The name of your organization. + +**app**: The name of your application. + + **Returns**: A string with the user's directory path. diff --git a/docs/api/prosperon.md b/docs/api/prosperon.md index 9cf244a3..f13284c8 100644 --- a/docs/api/prosperon.md +++ b/docs/api/prosperon.md @@ -33,71 +33,3 @@ ### imgui(...args) function ### app(...args) function - -### date string - -### camera object - -### debug boolean - -### semver object - -### title string - -### width number - -### height number - -### size object - -### icon object - -### high_dpi number - -### alpha number - -### fullscreen number - -### sample_count number - -### enable_clipboard boolean - -### enable_dragndrop boolean - -### max_dropped_files number - -### swap_interval number - -### name string - -### identifier string - -### creator string - -### copyright string - -### type string - -### url string - -### postvals object - -### hudcam object - -### appcam object - -### screencolor object - -### window object - -An application window, created via prosperon.engine_start or SDL calls. Freed on GC. - - -### font object - -### gpu object - -A handle for low-level GPU operations via SDL GPU. Freed on GC. - - -### exit() function diff --git a/docs/dull/Array.md b/docs/dull/Array.md new file mode 100644 index 00000000..a7050d4c --- /dev/null +++ b/docs/dull/Array.md @@ -0,0 +1,661 @@ +# Array + +### length number + +### at(index) function + +Return the item at index 'index', supporting negative indices to count from +the end. If 'index' is out of range, returns undefined. + + + +**index**: The index of the element to return (can be negative). + + +**Returns**: The element at the given index, or undefined. + + +### with(index, value) function + +Return a shallow copy of the array, but with the element at 'index' replaced +by 'value'. If 'index' is negative, it counts from the end. Throws if out of range. + + + +**index**: The zero-based index (can be negative) to replace. + +**value**: The new value for the specified position. + + +**Returns**: A new array with the updated element. + + +### concat(items) function + +Return a new array that is the result of concatenating this array with +any additional arrays or values provided. + + + +**items**: One or more arrays or values to concatenate. + + +**Returns**: A new array with the items appended. + + +### every(callback, thisArg) function + +Return true if the provided callback function returns a truthy value for +every element in the array; otherwise false. + + + +**callback**: A function(element, index, array) => boolean. + +**thisArg**: Optional. A value to use as 'this' within the callback. + + +**Returns**: True if all elements pass the test, otherwise false. + + +### some(callback, thisArg) function + +Return true if the provided callback function returns a truthy value for at +least one element in the array; otherwise false. + + + +**callback**: A function(element, index, array) => boolean. + +**thisArg**: Optional. A value to use as 'this' within the callback. + + +**Returns**: True if at least one element passes the test, otherwise false. + + +### forEach(callback, thisArg) function + +Call the provided callback function once for each element in the array. +Does not produce a return value. + + + +**callback**: A function(element, index, array). + +**thisArg**: Optional. A value to use as 'this' within the callback. + + +**Returns**: None + + +### map(callback, thisArg) function + +Create a new array with the results of calling a provided callback function +on every element in this array. + + + +**callback**: A function(element, index, array) => newElement. + +**thisArg**: Optional. A value to use as 'this' within the callback. + + +**Returns**: A new array of transformed elements. + + +### filter(callback, thisArg) function + +Create a new array containing all elements for which the provided callback +function returns a truthy value. + + + +**callback**: A function(element, index, array) => boolean. + +**thisArg**: Optional. A value to use as 'this' within the callback. + + +**Returns**: A new array of elements that passed the test. + + +### reduce(callback, initialValue) function + +Apply a callback function against an accumulator and each element in the +array (from left to right) to reduce it to a single value. + + + +**callback**: A function(accumulator, element, index, array) => newAccumulator. + +**initialValue**: Optional. The initial value for the accumulator. + + +**Returns**: The single resulting value. + + +### reduceRight(callback, initialValue) function + +Similar to reduce(), except it processes elements from right to left. + + + +**callback**: A function(accumulator, element, index, array) => newAccumulator. + +**initialValue**: Optional. The initial value for the accumulator. + + +**Returns**: The single resulting value. + + +### fill(value, start, end) function + +Fill the array with a static value from 'start' index up to (but not including) +'end' index. Modifies the original array. + + + +**value**: The value to fill. + +**start**: The starting index (default 0). + +**end**: The ending index (default array.length). + + +**Returns**: The modified array (with filled values). + + +### find(callback, thisArg) function + +Return the first element in the array that satisfies the provided callback +function. If none is found, return undefined. + + + +**callback**: A function(element, index, array) => boolean. + +**thisArg**: Optional. A value to use as 'this' within the callback. + + +**Returns**: The first matching element, or undefined if not found. + + +### findIndex(callback, thisArg) function + +Return the index of the first element in the array that satisfies the +provided callback function. If none is found, return -1. + + + +**callback**: A function(element, index, array) => boolean. + +**thisArg**: Optional. A value to use as 'this' within the callback. + + +**Returns**: The index of the first matching element, or -1 if not found. + + +### findLast(callback, thisArg) function + +Return the last element in the array that satisfies the provided callback +function, searching from right to left. If none is found, return undefined. + + + +**callback**: A function(element, index, array) => boolean. + +**thisArg**: Optional. A value to use as 'this' within the callback. + + +**Returns**: The last matching element, or undefined if not found. + + +### findLastIndex(callback, thisArg) function + +Return the index of the last element in the array that satisfies the +provided callback function, searching from right to left. If none is found, +return -1. + + + +**callback**: A function(element, index, array) => boolean. + +**thisArg**: Optional. A value to use as 'this' within the callback. + + +**Returns**: The index of the last matching element, or -1 if not found. + + +### indexOf(searchElement, fromIndex) function + +Return the first index at which a given element can be found. If not present, +return -1. + + + +**searchElement**: The item to locate in the array. + +**fromIndex**: The index at which to start searching (default 0). + + +**Returns**: The index of the found element, or -1 if not found. + + +### lastIndexOf(searchElement, fromIndex) function + +Return the last index at which a given element can be found, or -1 if not +present. Searches backward from 'fromIndex'. + + + +**searchElement**: The item to locate in the array. + +**fromIndex**: The index at which to start searching backward (default array.length - 1). + + +**Returns**: The last index of the found element, or -1 if not found. + + +### includes(searchElement, fromIndex) function + +Return a boolean indicating whether the array contains the given element, +comparing elements using the SameValueZero algorithm. + + + +**searchElement**: The value to search for. + +**fromIndex**: The position in the array to start searching (default 0). + + +**Returns**: True if the element is found, otherwise false. + + +### join(separator) function + +Join all elements of the array into a string, separated by 'separator'. + + + +**separator**: The delimiter string to separate elements (default ','). + + +**Returns**: A string of array elements joined by the separator. + + +### toString() function + +Return a string representing the elements of the array, separated by commas. +Overrides Object.prototype.toString. + + + +**Returns**: A comma-separated string of array elements. + + +### toLocaleString() function + +Return a localized string representing the array and its elements, calling +each element's toLocaleString if available. + + + +**Returns**: A locale-sensitive, comma-separated string of array elements. + + +### pop() function + +Remove the last element from the array and return it. This changes the length +of the array. + + + +**Returns**: The removed element, or undefined if the array is empty. + + +### push(items) function + +Append one or more elements to the end of the array and return the new length +of the array. + + + +**items**: One or more items to append. + + +**Returns**: The new length of the array. + + +### shift() function + +Remove the first element from the array and return it. This changes the length +of the array. + + + +**Returns**: The removed element, or undefined if the array is empty. + + +### unshift(items) function + +Insert one or more elements at the start of the array and return the new +length of the array. + + + +**items**: One or more elements to insert at the start. + + +**Returns**: The new length of the array. + + +### reverse() function + +Reverse the elements of the array in place and return the modified array. + + + +**Returns**: The reversed array. + + +### toReversed() function + +Return a shallow copy of the array in reverse order, without modifying the original array. + + + +**Returns**: A new reversed array. + + +### sort(compareFunction) function + +Sort the array in place, returning it. By default, sorts elements as strings in ascending order. An optional compareFunction may be used for custom sorting. + + + +**compareFunction**: A function(a, b) => number, defining sort order. + + +**Returns**: The sorted array. + + +### toSorted(compareFunction) function + +Return a shallow copy of the array, sorted according to the optional compare +function, without modifying the original array. + + + +**compareFunction**: A function(a, b) => number, defining sort order. + + +**Returns**: A new sorted array. + + +### slice(start, end) function + +Return a shallow copy of a portion of the array into a new array object, selected from 'start' to 'end' (end not included). + + + +**start**: The beginning index (0-based). Negative values count from the end. + +**end**: The end index (exclusive). Negative values count from the end. + + +**Returns**: A new array containing the extracted elements. + + +### splice(start, deleteCount, items) function + +Change the contents of the array by removing or replacing existing elements and/or adding new elements in place. Returns an array of removed elements. + + + +**start**: The index at which to start changing the array. + +**deleteCount**: Number of elements to remove. + +**items**: Elements to add in place of the removed elements. + + +**Returns**: An array containing the removed elements (if any). + + +### toSpliced(start, deleteCount, items) function + +Return a shallow copy of the array, with a splice-like operation applied at 'start' removing 'deleteCount' elements and adding 'items'. Does not mutate the original array. + + + +**start**: The index at which to start the splice operation. + +**deleteCount**: Number of elements to remove. + +**items**: Elements to add in place of the removed elements. + + +**Returns**: A new array with the splice applied. + + +### copyWithin(target, start, end) function + +Copy a sequence of array elements within the array, overwriting existing values. This operation is performed in place and returns the modified array. + + + +**target**: The index at which to copy the sequence to. + +**start**: The beginning index of the sequence to copy. + +**end**: The end index (exclusive) of the sequence to copy (default array.length). + + +**Returns**: The modified array. + + +### flatMap(callback, thisArg) function + +Return a new array formed by applying a callback function to each element and then flattening the result by one level. + + + +**callback**: A function(element, index, array) => array or value. + +**thisArg**: Optional. A value to use as 'this' within the callback. + + +**Returns**: A new array with the flattened results. + + +### flat(depth) function + +Return a new array with all sub-array elements concatenated into it recursively up to the specified depth. + + + +**depth**: The maximum depth to flatten (default 1). + + +**Returns**: A new flattened array. + + +### values() function + +Return a new Array Iterator object that contains the values for each index in the array. + + + +**Returns**: An iterator over the array's elements. + + +### keys() function + +Return a new Array Iterator object that contains the keys (indexes) for each index in the array. + + + +**Returns**: An iterator over the array's indices. + + +### entries() function + +Return a new Array Iterator object that contains key/value pairs for each index in the array. Each entry is [index, value]. + + + +**Returns**: An iterator over [index, value] pairs. + + +### add(other) function + +Non-standard. Add corresponding elements of the current array and 'other' element-wise, returning a new array. Behavior depends on data types. + + + +**other**: Another array or scalar to add to each element. + + +**Returns**: A new array with element-wise sum results. + + +### sub(other) function + +Non-standard. Subtract corresponding elements of 'other' from the current array element-wise, returning a new array. Behavior depends on data types. + + + +**other**: Another array or scalar to subtract from each element. + + +**Returns**: A new array with element-wise difference results. + + +### div(other) function + +Non-standard. Divide each element of the current array by the corresponding element of 'other' (or a scalar) element-wise, returning a new array. Behavior depends on data types. + + + +**other**: Another array or scalar for the division. + + +**Returns**: A new array with element-wise division results. + + +### scale() function + +### lerp() function + +### x accessor + +### y accessor + +### xy accessor + +### r accessor + +### g accessor + +### b accessor + +### a accessor + +### rgb accessor + +### rgba accessor + +### filter!(fn) function + +Perform an in-place filter of this array using the provided callback 'fn'. +Any element for which 'fn' returns a falsy value is removed. The array is modified +and then returned. + + + +**fn**: A callback function(element, index, array) => boolean. + + +**Returns**: The filtered (modified) array. + + +### delete(item) function + +Remove the first occurrence of 'item' from the array, if it exists. +Returns undefined. + + + +**item**: The item to remove. + + +**Returns**: undefined + + +### copy() function + +Return a deep copy of this array by applying 'deep_copy' to each element. +The resulting array is entirely new. + + + +**Returns**: A new array that is a deep copy of the original. + + +### equal(b) function + +Check if this array and array 'b' have the same elements in the same order. +If they are of different lengths, return false. Otherwise compare them via JSON. + + + +**b**: Another array to compare against. + + +**Returns**: True if they match, false otherwise. + + +### last() function + +Return the last element of this array. If the array is empty, returns undefined. + + + +**Returns**: The last element of the array, or undefined if empty. + + +### wrapped(x) function + +Return a copy of the array with the first 'x' elements appended to the end. +Does not modify the original array. + + + +**x**: The number of leading elements to re-append. + + +**Returns**: A new array with the leading elements wrapped to the end. + + +### wrap_idx(x) function + +Wrap the integer 'x' around this array's length, ensuring the resulting index +lies within [0, this.length - 1]. + + + +**x**: The index to wrap. + + +**Returns**: A wrapped index within this array's bounds. + + +### mirrored(x) function + +Return a new array that appends a reversed copy (excluding the last element) +of itself to the end. For example, [1,2,3] -> [1,2,3,2,1]. If the array has length +<= 1, a copy of it is returned directly. + + + +**Returns**: A new "mirrored" array. + diff --git a/scripts/modules/camera.js b/scripts/modules/camera.js new file mode 100644 index 00000000..e8311990 --- /dev/null +++ b/scripts/modules/camera.js @@ -0,0 +1,26 @@ +var camera = this + +camera.list[prosperon.DOC] = `Return an array of available camera device IDs. + +:return: An array of camera IDs, or undefined if no cameras are available. +` + +camera.open[prosperon.DOC] = `Open a camera device with the given ID. + +:param id: The camera ID to open. +:return: A camera object on success, or throws an error if the camera cannot be opened. +` + +camera.name[prosperon.DOC] = `Return the name of the camera with the given ID. + +:param id: The camera ID to query. +:return: A string with the camera's name, or throws an error if the name cannot be retrieved. +` + +camera.position[prosperon.DOC] = `Return the physical position of the camera with the given ID. + +:param id: The camera ID to query. +:return: A string indicating the camera position ("unknown", "front", or "back"). +` + +return this; diff --git a/scripts/modules/cmd.js b/scripts/modules/cmd.js index 03c21826..30775b09 100644 --- a/scripts/modules/cmd.js +++ b/scripts/modules/cmd.js @@ -27,46 +27,45 @@ Cmdline.register_order = function (order, fn, doc, usage = "") { Cmdline.register_order( "makedoc", function() { -var doc = use('doc') + var doc = use('doc') -var gs = ['console', 'prosperon', 'actor', 'use'] + var gs = ['console', 'prosperon', 'actor', 'use'] -Object.getOwnPropertyDescriptor(prosperon.c_types.transform, 'pos')[prosperon.DOC] = 'TEST DOC' + Object.getOwnPropertyDescriptor(prosperon.c_types.transform, 'pos')[prosperon.DOC] = 'TEST DOC' -console.log(Object.getOwnPropertyDescriptor(prosperon.c_types.transform,'pos')[prosperon.DOC]) + console.log(Object.getOwnPropertyDescriptor(prosperon.c_types.transform,'pos')[prosperon.DOC]) -for (var g of gs) - io.slurpwrite(`.src/docs/api/${g}.md`, doc.writeDocFile(globalThis[g], g)) + for (var g of gs) + io.slurpwrite(`.src/docs/api/${g}.md`, doc.writeDocFile(globalThis[g], g)) -var coredocs = io.enumerate("scripts/modules", 0) -coredocs = coredocs.filter(x => io.match("**/*.js", x)).map(x => x.name()) + var coredocs = io.enumerate("scripts/modules", 0) + coredocs = coredocs.filter(x => io.match("**/*.js", x)).map(x => x.name()) -var TYPEPATH = '.src/docs/api/types/' -for (var c in prosperon.c_types) { - io.slurpwrite(`${TYPEPATH}${c}.md`, doc.writeDocFile(prosperon.c_types[c], c)) -} + var TYPEPATH = '.src/docs/api/types/' + for (var c in prosperon.c_types) + io.slurpwrite(`${TYPEPATH}${c}.md`, doc.writeDocFile(prosperon.c_types[c], c)) -var APIPATH = '.src/docs/api/modules/' + var APIPATH = '.src/docs/api/modules/' -for (var m of coredocs) { - var u = use(m) - var path = `${APIPATH}${m}.md` - io.slurpwrite(path, doc.writeDocFile(u, m)) -} + for (var m of coredocs) { + var u = use(m) + var path = `${APIPATH}${m}.md` + io.slurpwrite(path, doc.writeDocFile(u, m)) + } -var DULLPATH = '.src/docs/dull/' -var mixins = ['Object', 'String', 'Array', 'Map', 'WeakMap', 'Symbol','Set', 'WeakSet', 'ArrayBuffer', 'Function'] -for (var m of mixins) { - var path = `${DULLPATH}${m}.md` - io.slurpwrite(path, doc.writeDocFile(globalThis[m].prototype, m)) -} + var DULLPATH = '.src/docs/dull/' + var mixins = ['Object', 'String', 'Array', 'Map', 'WeakMap', 'Symbol','Set', 'WeakSet', 'ArrayBuffer', 'Function'] + for (var m of mixins) { + var path = `${DULLPATH}${m}.md` + io.slurpwrite(path, doc.writeDocFile(globalThis[m].prototype, m)) + } -var dullgpath = '.src/docs/dull/globals/' -var globals = ['Object', 'String', 'Array', 'Symbol', 'Number', 'Error','Function', 'Math'] -for (var m of globals) { - var path = `${dullgpath}${m}.md` - io.slurpwrite(path, doc.writeDocFile(globalThis[m], m)) -} + var dullgpath = '.src/docs/dull/globals/' + var globals = ['Object', 'String', 'Array', 'Symbol', 'Number', 'Error','Function', 'Math'] + for (var m of globals) { + var path = `${dullgpath}${m}.md` + io.slurpwrite(path, doc.writeDocFile(globalThis[m], m)) + } "Make documentation." }) diff --git a/scripts/modules/debug.js b/scripts/modules/debug.js new file mode 100644 index 00000000..8823fc1b --- /dev/null +++ b/scripts/modules/debug.js @@ -0,0 +1,42 @@ +var debug = this + +debug.stack_depth[prosperon.DOC] = `Return the current stack depth. + +:return: A number representing the stack depth. +` + +debug.build_backtrace[prosperon.DOC] = `Build and return a backtrace of the current call stack. + +:return: An object representing the call stack backtrace. +` + +debug.closure_vars[prosperon.DOC] = `Return the closure variables for a given function. + +:param fn: The function object to inspect. +:return: An object containing the closure variables. +` + +debug.local_vars[prosperon.DOC] = `Return the local variables for a specific stack frame. + +:param depth: The stack frame depth to inspect. +:return: An object containing the local variables at the specified depth. +` + +debug.fn_info[prosperon.DOC] = `Return metadata about a given function. + +:param fn: The function object to inspect. +:return: An object with metadata about the function. +` + +debug.backtrace_fns[prosperon.DOC] = `Return an array of functions in the current backtrace. + +:return: An array of function objects from the call stack. +` + +debug.dump_obj[prosperon.DOC] = `Return a string representation of a given object. + +:param obj: The object to dump. +:return: A string describing the object's contents. +` + +return this diff --git a/scripts/modules/render.js b/scripts/modules/render.js index 9450b3d6..0d5b73b3 100644 --- a/scripts/modules/render.js +++ b/scripts/modules/render.js @@ -31,7 +31,7 @@ var default_conf = { var config = use('config.js') config.__proto__ = default_conf -prosperon.camera = use('camera').make() +prosperon.camera = use('ext/camera').make() prosperon.camera.size = [config.width,config.height] var base_pipeline = { diff --git a/source/jsffi.c b/source/jsffi.c index 7dcf9bdf..6968b430 100644 --- a/source/jsffi.c +++ b/source/jsffi.c @@ -6387,33 +6387,6 @@ static const JSCFunctionListEntry js_font_funcs[] = { MIST_FUNC_DEF(font, text_size, 3), }; -const char *STRTEST = "TEST STRING"; - -JSC_CCALL(performance_barecall,) -JSC_CCALL(performance_unpack_array, - void *v = js2cpvec2arr(js,argv[0]); - arrfree(v); -) -JSC_CCALL(performance_pack_num, return number2js(js,1.0)) -JSC_CCALL(performance_pack_string, return JS_NewStringLen(js, STRTEST, sizeof(*STRTEST))) -JSC_CCALL(performance_unpack_string, JS_ToCString(js, argv[0])) -JSC_CCALL(performance_call_fn_n, - for (int i = 0; i < js2number(js,argv[1]); i++) { - JSValue r = JS_Call(js, argv[0], JS_UNDEFINED, 0, NULL); - uncaught_exception(js,r); - } - uncaught_exception(js,JS_Call(js,argv[2], JS_UNDEFINED, 0, NULL)); -) - -static const JSCFunctionListEntry js_performance_funcs[] = { - MIST_FUNC_DEF(performance, barecall,0), - MIST_FUNC_DEF(performance, unpack_array, 1), - MIST_FUNC_DEF(performance, pack_num, 0), - MIST_FUNC_DEF(performance, pack_string, 0), - MIST_FUNC_DEF(performance, unpack_string, 1), - MIST_FUNC_DEF(performance, call_fn_n, 3) -}; - JSC_CCALL(geometry_rect_intersection, rect a = js2rect(js,argv[0]); rect b = js2rect(js,argv[1]); @@ -7609,9 +7582,9 @@ MISTUSE(graphics) MISTUSE(util) MISTUSE(video) MISTUSE(event) -#ifndef NEDITOR +MISTUSE(camera) +MISTUSE(debug) JSValue js_imgui_use(JSContext *js); -#endif #define MISTLINE(NAME) (ModuleEntry){#NAME, js_##NAME##_use} @@ -7629,12 +7602,11 @@ void ffi_load(JSContext *js, int argc, char **argv) { arrput(module_registry, MISTLINE(video)); arrput(module_registry, MISTLINE(event)); arrput(module_registry, MISTLINE(soloud)); - arrput(module_registry,MISTLINE(layout)); + arrput(module_registry, MISTLINE(layout)); arrput(module_registry, MISTLINE(miniz)); -#ifndef NEDITOR arrput(module_registry, MISTLINE(imgui)); -#endif - + arrput(module_registry, MISTLINE(camera)); + arrput(module_registry, MISTLINE(debug)); #ifdef TRACY_ENABLE arrput(module_registry, MISTLINE(tracy)); #endif @@ -7668,11 +7640,7 @@ void ffi_load(JSContext *js, int argc, char **argv) { QJSCLASSPREP_NO_FUNCS(SDL_GPUComputePipeline) QJSCLASSPREP_FUNCS(sprite) -// QJSCLASSPREP_FUNCS(SDL_GPUGraphicsPipeline) -// QJSCLASSPREP_FUNCS(SDL_GPUSampler) -// QJSCLASSPREP_FUNCS(SDL_GPUShader) QJSCLASSPREP_FUNCS(SDL_GPUBuffer) -// QJSCLASSPREP_FUNCS(SDL_GPUTransferBuffer) QJSCLASSPREP_FUNCS(PHYSFS_File) QJSCLASSPREP_FUNCS(transform); QJSCLASSPREP_FUNCS(font);