Skip to content

Commit 980518c

Browse files
v0.4.9: Consolidated imports, documentation audit, and bug fixes
1 parent 867bc27 commit 980518c

18 files changed

Lines changed: 606 additions & 40 deletions

p3deditor/Blueprint.pde

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
/**
2+
* Blueprint.pde - Visual Logic Container
3+
*
4+
* Version: v0.4.9
5+
* Responsibilities:
6+
* - Manages a graph of VLB nodes and connections for an entity or level.
7+
* - Implements the transpilation engine that converts visual nodes into PDES
8+
* assembly script.
9+
* - Handles event-specific PDES generation (OnStart, OnUpdate, etc.).
10+
* - Manages node spatial organization (Offset/Zoom).
11+
*/
112
class Blueprint {
213
Object owner; // Can be Entity or SceneManager
314
ArrayList<VLBNode> nodes = new ArrayList<VLBNode>();
@@ -47,6 +58,15 @@ class Blueprint {
4758
dst.connectedTo = src;
4859
}
4960

61+
/**
62+
* generatePDES() - Transpilation Hub
63+
*
64+
* [ALGORITHM] VLB to PDES Conversion
65+
* This is the heart of the Visual Logic System. It traverses the node graph
66+
* starting from 'Event: OnStart' and recursively emits PDES commands.
67+
* It ensures that data-dependency nodes (Math, GetPos) are emitted BEFORE
68+
* the flow nodes (Log, SetPos) that consume them.
69+
*/
5070
String generatePDES() {
5171
VLBNode startNode = null;
5272
for (VLBNode n : nodes) if (n.title.equals("Event: OnStart")) { startNode = n; break; }
@@ -108,7 +128,15 @@ class Blueprint {
108128
}
109129
}
110130

111-
// v1.4: Recursively emit commands for data-only nodes that have no flow pins
131+
/**
132+
* [ALGORITHM] emitDataDeps() - Recursive Dependency Emission
133+
*
134+
* For a given flow node, this function finds all connected input data pins,
135+
* traces them back to their source nodes (e.g., an 'Add' node), and recursively
136+
* emits the script commands needed to calculate those values.
137+
* Results are stored in temporary variables ($add_12, $pos_x_5) for the
138+
* consumer to use.
139+
*/
112140
void emitDataDeps(VLBNode n, StringBuilder sb, HashSet<Integer> visited) {
113141
if (n == null || visited.contains(n.id)) return;
114142
// Only process data-producing nodes (no flow input)
@@ -171,6 +199,16 @@ class Blueprint {
171199
}
172200
}
173201

202+
/**
203+
* [ALGORITHM] traverseNode() - Control Flow Generation
204+
*
205+
* Performs a linear traversal of the flow-carrying nodes in the graph.
206+
* 1. Assigns a PDES label (:node_ID) to the current segment.
207+
* 2. Calls emitDataDeps to prepare all necessary input variables.
208+
* 3. Maps the visual node type to its corresponding PDES command (tp, spawn, echo, etc.).
209+
* 4. Follows the output flow pin to the next node in the chain.
210+
* 5. Special Case: Branch nodes emit 'if/else/goto' logic instead of linear fallthrough.
211+
*/
174212
void traverseNode(VLBNode n, StringBuilder sb, HashSet<Integer> visited) {
175213
if (n == null) return;
176214
visited.add(n.id);
@@ -362,6 +400,15 @@ class Blueprint {
362400
}
363401
}
364402

403+
/**
404+
* resolveData() - Pin Value Binding
405+
*
406+
* [ALGORITHM] Variable Reference Mapping
407+
* Determines what string should represent a pin's value in the final script.
408+
* - If disconnected: Returns the pin's literal value (10.0, "Hello").
409+
* - If connected: Returns a variable reference ($res_ID, $pos_x_ID) that
410+
* points to the pre-emitted calculation result of the source node.
411+
*/
365412
String resolveData(VLBPin p) {
366413
if (p == null) return "0";
367414
// v1.1: Follow connected data pins to their source

p3deditor/BlueprintEditor.pde

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
/**
2+
* BlueprintEditor.pde - Visual Logic Workspace
3+
*
4+
* Version: v0.4.9
5+
* Responsibilities:
6+
* - Provides an interactive 'Node Graph' canvas for visual programming.
7+
* - Handles infinite panning, zooming, and grid rendering.
8+
* - Manages node lifecycle: spawning, dragging, connecting, and deletion.
9+
* - Implements the 'Compile' bridge to the PDES Scripting system.
10+
* - Supports 'Hot-Reload' of logic during engine play sessions.
11+
*/
112
class BlueprintEditor {
213
Blueprint activeBlueprint = null;
314
boolean visible = false;
@@ -30,7 +41,7 @@ class BlueprintEditor {
3041
float menuScrollY = 0; // v1.2: Menu scroll offset
3142

3243
// v1.0: Categorized Node Menu
33-
String[] menuCategories = { "Action ", "Logic ", "Math ", "Data ", "Event ", "Value " };
44+
String[] menuCategories = { "�Action �, "�Logic �, "�Math �, "�Data �, "�Event �, "�Value � };
3445
String[][] menuItems = {
3546
{ "Action: Wait", "Action: Log", "Action: Print", "Action: Set Position", "Action: Spawn Entity", "Action: Set Visibility", "Action: Light Settings", "Action: Set Background", "Action: Camera Teleport", "Action: Get Visibility" },
3647
{ "Logic: Branch", "Logic: Compare", "Logic: Counter", "Logic: AND", "Logic: OR", "Logic: NOT" },
@@ -74,6 +85,16 @@ class BlueprintEditor {
7485
return null;
7586
}
7687

88+
/**
89+
* render() - Blueprint Canvas Pass
90+
*
91+
* [ALGORITHM] Layer-based UI Composition
92+
* Draws the visual graph in clear depth stages:
93+
* 1. Background Grid (infinite parallax).
94+
* 2. Bezier Connections (wire layer).
95+
* 3. VLB Nodes (interactive blocks).
96+
* 4. Overlays (Compiling status, Menu, Headers).
97+
*/
7798
void render() {
7899
if (!visible || activeBlueprint == null) return;
79100

@@ -153,7 +174,7 @@ class BlueprintEditor {
153174
float pulse = sin((millis() - compileFlashTime) * 0.005f) * 0.3f + 0.7f;
154175
fill(lerpColor(color(45, 140, 45), color(80, 255, 80), pulse));
155176
rect(runX, 10, 100, 25, 4);
156-
fill(255); textSize(11); textAlign(CENTER, CENTER); text("Compiled!", runX + 50, 22);
177+
fill(255); textSize(11); textAlign(CENTER, CENTER); text("�Compiled!", runX + 50, 22);
157178
} else {
158179
if (mouseX > runX && mouseX < runX + 100 && mouseY > 10 && mouseY < 35) fill(60, 180, 60); else fill(45, 70, 45);
159180
rect(runX, 10, 100, 25, 4);
@@ -349,7 +370,15 @@ class BlueprintEditor {
349370
bezier(x1, y1, x1 + ctrlOffset, y1, x2 - ctrlOffset, y2, x2, y2);
350371
}
351372

352-
// === MOUSE PRESSED ===
373+
/**
374+
* handleMousePressed() / Dragged() / Released()
375+
*
376+
* [ALGORITHM] Graph Interaction Workflow
377+
* - Left-Click: Node selection or Pin drag start (wiring).
378+
* - Box Select: Dragging on empty space to group-select nodes.
379+
* - Right-Drag: Viewport panning.
380+
* - Context Menu: Right-click on empty space to spawn nodes.
381+
*/
353382
void handleMousePressed() {
354383
if (!visible || activeBlueprint == null) return;
355384

@@ -450,7 +479,7 @@ class BlueprintEditor {
450479
if (cwx > n.x && cwx < n.x + n.w && cwy > n.y && cwy < n.y + n.h) {
451480
// v1.4: If clicking an already-selected node, keep multi-selection for group drag
452481
if (n.selected) {
453-
// Already selected just set as drag target, don't clear others
482+
// Already selected �just set as drag target, don't clear others
454483
draggingNode = n;
455484
} else {
456485
if (!p3deditor.this.keyPressed || (p3deditor.this.key != 17 && p3deditor.this.keyCode != p3deditor.this.CONTROL)) {
@@ -661,17 +690,24 @@ class BlueprintEditor {
661690
editingPinText = "";
662691
}
663692

664-
// v1.7: Sync Expression Pins based on variables in the "Expression" pin
693+
/**
694+
* [ALGORITHM] syncExpressionPins() - Dynamic Reflection
695+
*
696+
* This critical algorithm parses a mathematical expression string (e.g. "sin(val) * 10")
697+
* and automatically generates input pins for every undefined variable ("val")
698+
* found in the string. It preserves existing connections during the sync,
699+
* enabling seamless 'Expressive Programming'.
700+
*/
665701
void syncExpressionPins(VLBNode n) {
666702
VLBPin exprPin = n.findPin("Expression", true);
667703
if (exprPin == null) return;
668704

669705
String expr = exprPin.sVal;
670-
java.util.HashSet<String> vars = new java.util.HashSet<String>();
671-
java.util.regex.Matcher m = java.util.regex.Pattern.compile("[a-zA-Z_][a-zA-Z0-9_]*").matcher(expr);
706+
HashSet<String> vars = new HashSet<String>();
707+
Matcher m = Pattern.compile("[a-zA-Z_][a-zA-Z0-9_]*").matcher(expr);
672708

673709
// Reserved words to ignore (functions and constants)
674-
java.util.List<String> reserved = java.util.Arrays.asList(
710+
List<String> reserved = Arrays.asList(
675711
"sin", "cos", "tan", "sqrt", "abs", "rand", "min", "max", "PI", "E", "time", "dt"
676712
);
677713

p3deditor/Command.pde

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,27 @@
1-
import java.util.Stack;
1+
/**
2+
* Command.pde - Undo/Redo System Implementation
3+
*
4+
* Version: v0.4.9
5+
* Responsibilities:
6+
* - Implements the 'Command' design pattern to capture user actions as objects.
7+
* - Manages the Undo and Redo stacks via UndoManager.
8+
* - Provides specific command implementations for transforms, hierarchy changes,
9+
* and property edits.
10+
*/
211

312
abstract class Command {
413
abstract void execute();
514
abstract void undo();
615
}
716

17+
/**
18+
* UndoManager - Stack Manager
19+
*
20+
* [ALGORITHM] Dual-Stack Undo/Redo
21+
* Maintains two stacks: 'undoStack' for past actions and 'redoStack' for
22+
* undone actions. When a new command is pushed, the redoStack is cleared
23+
* to ensure linear history.
24+
*/
825
class UndoManager {
926
Stack<Command> undoStack = new Stack<Command>();
1027
Stack<Command> redoStack = new Stack<Command>();

p3deditor/CommandInterpreter.pde

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
import java.util.Map;
2-
import java.util.HashMap;
3-
1+
/**
2+
* CommandInterpreter.pde - PDES Vocabulary & Dispatcher
3+
*
4+
* Version: v0.4.9
5+
* Responsibilities:
6+
* - Defines the execution logic for all text-based engine commands.
7+
* - Handles alias expansion and recursive command resolution.
8+
* - Implements argument parsing with support for quoted strings.
9+
* - Bridges high-level script intent to low-level engine state changes.
10+
*/
411
class CommandInterpreter {
512
SceneManager scene;
613
String lastResult = "";
@@ -17,6 +24,15 @@ class CommandInterpreter {
1724
this.scriptManager = sm;
1825
}
1926

27+
/**
28+
* execute() - Command Dispatcher
29+
*
30+
* [ALGORITHM] Command Resolution Pipe
31+
* 1. Splits semicolon-separated commands for batch execution.
32+
* 2. Tokenizes the command string into parts.
33+
* 3. Resolves aliases recursively (up to MAX_RECURSION).
34+
* 4. Dispatches the command to its implementation block (if, move, tp, etc.).
35+
*/
2036
String execute(String cmdLine) {
2137
if (cmdLine == null || cmdLine.trim().isEmpty()) return "";
2238

@@ -386,6 +402,14 @@ class CommandInterpreter {
386402
return "SUCCESS: Executed " + count + " instructions from " + filename;
387403
}
388404

405+
/**
406+
* parseArgs() - Tokenizer
407+
*
408+
* [ALGORITHM] Quote-Aware Splitting
409+
* Splits a command line into space-separated tokens while treating text
410+
* within quotes (e.g. "My Entity Name") as a single argument. This is
411+
* critical for handling object names with spaces.
412+
*/
389413
ArrayList<String> parseArgs(String line) {
390414
ArrayList<String> args = new ArrayList<String>();
391415
boolean inQuotes = false;

p3deditor/DebugConsole.pde

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
import java.io.*;
2-
import java.util.*;
3-
1+
/**
2+
* DebugConsole.pde - Engine Diagnostic Terminal
3+
*
4+
* Version: v0.4.9
5+
* Responsibilities:
6+
* - Provides a 'Quake-style' dropdown terminal for direct command entry.
7+
* - Manages session-based logging with persistence to disk (.log files).
8+
* - Implements input history (Up/Down) and multi-line message rendering.
9+
* - Serves as the primary feedback loop for PDES script execution.
10+
*/
411
class LogEntry {
512
String message;
613
int type; // 0:Info, 1:Success, 2:Warn, 3:Error
@@ -51,6 +58,15 @@ class DebugConsole {
5158
}
5259
}
5360

61+
/**
62+
* addLog() - Message Dispatcher
63+
*
64+
* [ALGORITHM] Multi-line Log Ingestion
65+
* High-level messages (like help text or batch results) containing newlines
66+
* are automatically decomposed into individual `LogEntry` objects to
67+
* maintain consistent line spacing in the terminal UI.
68+
* Also mirrors all logs to the persistent session file.
69+
*/
5470
void addLog(String msg, int type) {
5571
if (msg == null) return;
5672

@@ -74,6 +90,14 @@ class DebugConsole {
7490
}
7591
}
7692

93+
/**
94+
* render() - Terminal HUD Pass
95+
*
96+
* [ALGORITHM] Clipped Text Rendering
97+
* Draws a semi-transparent 'Glass' overlay over the viewport.
98+
* Uses `clip()` to ensure text overflow doesn't bleed into the main 3D
99+
* viewport while allowing for vertical scroll offsets.
100+
*/
77101
void render() {
78102
if (!active) return;
79103

@@ -121,6 +145,14 @@ class DebugConsole {
121145
p3deditor.this.popStyle();
122146
}
123147

148+
/**
149+
* handleKey() - Command Ingestion
150+
*
151+
* [ALGORITHM] Buffered Input & History
152+
* Accumulates keystrokes into `currentInput`. On ENTER, it pushes the
153+
* buffer to the `CommandInterpreter`, clears the buffer, and records
154+
* the command in the persistent session history for Up/Down retrieval.
155+
*/
124156
void handleKey(char key, int keyCode) {
125157
if (key == '`') {
126158
active = !active;

p3deditor/EditorCamera.pde

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/**
2+
* EditorCamera.pde - Dual-Mode Viewport Controller
3+
*
4+
* Version: v0.4.9
5+
* Responsibilities:
6+
* - Manages 3D viewport navigation (Fly Mode and Orbit Mode).
7+
* - Derives World-Space basis vectors (Forward/Right/Up) from Euler angles.
8+
* - Handles 'Fly Mode' using Robot-based cursor locking and WASD movement.
9+
* - Handles 'Orbit Mode' using pivot-based rotation, panning, and zooming.
10+
*/
111
class EditorCamera {
212
PVector pos = new PVector(0, -100, 400);
313
PVector target = new PVector(0, 0, 0);
@@ -24,7 +34,15 @@ class EditorCamera {
2434
updatePosFromTarget();
2535
}
2636

27-
// Mathematical derivation of View space basis vectors mapped to World space
37+
/**
38+
* getForward() / getRight() / getUp()
39+
*
40+
* [ALGORITHM] View Space Basis Derivation
41+
* Uses spherical coordinates (Pitch/Yaw) to derive the Forward vector.
42+
* The Right vector is the cross product of Up(0,1,0) and Forward.
43+
* The local Up vector is the cross product of Right and Forward,
44+
* ensuring an orthonormal basis for the camera's view matrix.
45+
*/
2846
PVector getForward() {
2947
return new PVector(cos(rotX)*sin(rotY), -sin(rotX), -cos(rotX)*cos(rotY));
3048
}
@@ -51,7 +69,15 @@ class EditorCamera {
5169
target = PVector.add(pos, PVector.mult(getForward(), orbitDistance));
5270
}
5371

54-
// Called every frame
72+
/**
73+
* update() - Every Frame Logic
74+
*
75+
* [ALGORITHM] Fly Mode & Cursor Lock
76+
* If Right-Click is held (and Alt is NOT held), the system:
77+
* 1. Hides the system cursor and locks it to the center of the screen using Java Robot.
78+
* 2. Accumulates mouse delta into rotation (Pitch/Yaw).
79+
* 3. Processes WASDQE keys for translation relative to the camera's orientation.
80+
*/
5581
void update(boolean[] keyStates) {
5682
if (isRightDragging && !isAltDown) { // Fly mode WASD movement and Cursor Lock
5783

@@ -112,6 +138,15 @@ class EditorCamera {
112138
if (mouseButton == RIGHT) isRightDragging = true;
113139
}
114140

141+
/**
142+
* handleMouseDragged() - Interaction Routing
143+
*
144+
* [ALGORITHM] Orbit Mode logic
145+
* If Alt is held:
146+
* - Left Mouse: Orbit (rotate camera around 'target' point).
147+
* - Center Mouse: Pan (move both 'pos' and 'target' on the camera plane).
148+
* - Right Mouse: Zoom (adjust 'orbitDistance').
149+
*/
115150
void handleMouseDragged(boolean isAltDown) {
116151
float dx = mouseX - lastMouseX;
117152
float dy = mouseY - lastMouseY;

0 commit comments

Comments
 (0)