njin
Engine 2D gọn nhẹ để tự tay làm game theo ý mình. Vibe coding cũng ổn luôn
Loading...
Searching...
No Matches
njin_spatial_batch.h
1#pragma once
2#include "_types.h"
3#include <span>
4#include <utility>
5#include <vector>
6
7namespace njin {
8
11
20 i32 cols = 0;
21 i32 rows = 0;
25 i32 count() const;
29 i32 cell_at(vec2 p) const;
30};
31
45
52bool batch_cell_visible(const batch_grid2d &grid, const batch_view2d &view, i32 cell);
53
62bool batch_cell_detailed(const batch_grid2d &grid, const batch_view2d &view, i32 cell, f32 radius);
63
66using instance_range = std::pair<u32, u32>;
67
83std::vector<instance_range> batch_instance_ranges(std::span<const u32> offsets,
84 std::span<const u8> wanted, std::span<const instance_range> excluded = {});
85
87
88} // namespace njin
bool batch_cell_detailed(const batch_grid2d &grid, const batch_view2d &view, i32 cell, f32 radius)
Ô cell có ở gần không: khoảng cách từ view.focus đến hình chữ nhật của ô nhỏ hơn radius.
std::vector< instance_range > batch_instance_ranges(std::span< const u32 > offsets, std::span< const u8 > wanted, std::span< const instance_range > excluded={})
Các đoạn instance cần vẽ, từ những ô được chọn.
bool batch_cell_visible(const batch_grid2d &grid, const batch_view2d &view, i32 cell)
Ô cell có lọt vào vùng nhìn không: hình chữ nhật của ô, nới thêm overhang, có chạm hình chữ nhật lo .
std::pair< u32, u32 > instance_range
Một đoạn instance [first, second) trong bộ đệm: vẽ bằng draw_instanced3d(ctx, mesh,...
Definition njin_spatial_batch.h:66
std::int32_t i32
Số nguyên có dấu 32 bit.
Definition _types.h:14
float f32
Số thực 32 bit.
Definition _types.h:28
Lưới chia mặt đất thành ô, để nhóm instance theo ô chứa tâm của chúng.
Definition njin_spatial_batch.h:17
i32 count() const
Số ô, cols * rows.
vec2 cell_size
Kích thước một ô theo hai trục, lớn hơn 0.
Definition njin_spatial_batch.h:19
i32 cell_at(vec2 p) const
Ô chứa điểm p: hàng * cols + cột.
i32 rows
Số hàng (theo trục thứ hai).
Definition njin_spatial_batch.h:21
i32 cols
Số cột (theo trục thứ nhất).
Definition njin_spatial_batch.h:20
vec2 origin
Góc nhỏ nhất (x, y nhỏ nhất) của ô 0.
Definition njin_spatial_batch.h:18
Phần mặt phẳng một camera thấy, do game dựng từ camera của mình mỗi frame.
Definition njin_spatial_batch.h:37
vec2 hi
Góc lớn nhất; không nhỏ hơn lo ở trục nào.
Definition njin_spatial_batch.h:39
f32 overhang
Vật nhô ra khỏi ô chứa tâm nó xa nhất bao nhiêu (bán kính lớn nhất của instance).
Definition njin_spatial_batch.h:43
vec2 focus
Điểm đo khoảng cách cho batch_cell_detailed(), thường là vị trí camera.
Definition njin_spatial_batch.h:40
vec2 lo
Góc nhỏ nhất của hình chữ nhật nhìn thấy.
Definition njin_spatial_batch.h:38
Vị trí một ô trong lưới. Có thể âm.
Definition _tilemap.h:43
Vector 2 chiều. Dùng cho vị trí, kích thước, độ dời.
Definition _types.h:39