Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
ViewportCulling.h
Go to the documentation of this file.
1/**
2 * @file ViewportCulling.h
3 * @brief Viewport culling helpers for the VS graph canvas (Phase 7).
4 * @author Olympe Engine
5 * @date 2026-03-10
6 *
7 * @details
8 * Provides static utility methods for determining whether a node rectangle
9 * overlaps the current viewport (with an optional margin). Call
10 * FilterVisibleNodes() to get a list of node IDs that should be rendered.
11 *
12 * No state, no singletons — pure functions operating on plain data.
13 *
14 * C++14 compliant — no std::optional, structured bindings, std::filesystem.
15 */
16
17#pragma once
18
19#include <vector>
20#include <utility>
21
22namespace Olympe {
23
24// ============================================================================
25// Supporting types
26// ============================================================================
27
28/**
29 * @struct ViewRect
30 * @brief An axis-aligned rectangle used to describe the viewport or a node bounds.
31 */
32struct ViewRect {
33 float x; ///< Left edge
34 float y; ///< Top edge
35 float w; ///< Width
36 float h; ///< Height
37};
38
39// ============================================================================
40// ViewportCulling
41// ============================================================================
42
43/**
44 * @class ViewportCulling
45 * @brief Static helpers for AABB-based viewport culling.
46 *
47 * Typical usage:
48 * @code
49 * ViewRect vp = { scrollX, scrollY, windowW, windowH };
50 * auto visible = ViewportCulling::FilterVisibleNodes(nodeRects, vp);
51 * for (int id : visible) RenderNode(id);
52 * @endcode
53 */
55public:
56
57 /**
58 * @brief Tests whether a single node rectangle overlaps the viewport.
59 *
60 * @param nodeX Node left edge in graph space.
61 * @param nodeY Node top edge in graph space.
62 * @param nodeW Node width.
63 * @param nodeH Node height.
64 * @param viewport Current visible rectangle in graph space.
65 * @param margin Extra padding applied to the viewport before testing.
66 * @return true if the node is at least partially visible.
67 */
68 static bool IsNodeVisible(float nodeX, float nodeY,
69 float nodeW, float nodeH,
70 const ViewRect& viewport,
71 float margin = 50.0f);
72
73 /**
74 * @brief Filters a list of (id, rect) pairs and returns only the visible IDs.
75 *
76 * @param nodeRects List of (nodeId, ViewRect) pairs.
77 * @param viewport Current visible rectangle in graph space.
78 * @param margin Extra padding applied to the viewport before testing.
79 * @return IDs of visible nodes.
80 */
81 static std::vector<int> FilterVisibleNodes(
82 const std::vector<std::pair<int, ViewRect>>& nodeRects,
83 const ViewRect& viewport,
84 float margin = 50.0f);
85};
86
87} // namespace Olympe
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
Static helpers for AABB-based viewport culling.
static std::vector< int > FilterVisibleNodes(const std::vector< std::pair< int, ViewRect > > &nodeRects, const ViewRect &viewport, float margin=50.0f)
Filters a list of (id, rect) pairs and returns only the visible IDs.
static bool IsNodeVisible(float nodeX, float nodeY, float nodeW, float nodeH, const ViewRect &viewport, float margin=50.0f)
Tests whether a single node rectangle overlaps the viewport.
< Provides AssetID and INVALID_ASSET_ID
An axis-aligned rectangle used to describe the viewport or a node bounds.
float x
Left edge.
float y
Top edge.