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_ctx.h
1#pragma once
2#include "_mod.h"
3#include "_random.h"
4#include "_types.h"
5#include <entt/entity/registry.hpp>
6#include <entt/signal/dispatcher.hpp>
7#include <initializer_list>
8#include <span>
9
10namespace njin {
11// Opaque: created with create (njin.h), only accessed through the
12// functions below.
13struct context;
14
17
24entt::registry &world(context &ctx);
25
31entt::dispatcher &events(context &ctx);
32
41void ecs_register(context &ctx, sys_phase phase, sys_fnc fnc, const char *name = nullptr);
42
51void ecs_register(context &ctx, sys_phase phase, const sys_desc &desc);
52
58void mod_register(context &ctx, const mod_desc &desc);
59
70void mod_register(context &ctx, std::initializer_list<mod_desc> mods);
71
77void mod_register(context &ctx, std::span<const mod_desc> mods);
79
82
90f32 delta(const context &ctx);
91
96f32 delta_real(const context &ctx);
97
104void time_set_scale(context &ctx, f32 scale);
105
109f32 time_scale(const context &ctx);
110
118void time_set_paused(context &ctx, bool paused);
119
123bool time_paused(const context &ctx);
124
128f32 fixed_delta(const context &ctx);
129
136f32 fixed_alpha(const context &ctx);
137
141f32 elapsed(const context &ctx);
143
146
153rng &random(context &ctx);
155} // namespace njin
void ecs_register(context &ctx, sys_phase phase, sys_fnc fnc, const char *name=nullptr)
Thêm một system vào lịch chạy của một phase.
void mod_register(context &ctx, const mod_desc &desc)
Chạy setup của module và đưa các system của nó vào lịch chạy.
entt::dispatcher & events(context &ctx)
Trả về dispatcher của EnTT để gửi và nhận event giữa các system.
sys_phase
Các phase của một frame, chạy theo đúng thứ tự khai báo.
Definition _mod.h:31
void(*)(context &ctx) sys_fnc
Một system là một hàm thường nhận context của engine.
Definition _mod.h:15
entt::registry & world(context &ctx)
Trả về registry của EnTT chứa mọi entity và component của game.
rng & random(context &ctx)
Bộ sinh số ngẫu nhiên dùng chung của engine.
f32 fixed_delta(const context &ctx)
Độ dài một nhịp của phase_fixed_update, bằng 1 / config::fixed_hz.
f32 delta_real(const context &ctx)
Thời gian thật của frame trước, không bị tốc độ thời gian hay tạm dừng ảnh hưởng.
f32 time_scale(const context &ctx)
Tốc độ thời gian hiện tại.
f32 fixed_alpha(const context &ctx)
Phần nhịp cố định còn dư sau phase_fixed_update của frame này, từ 0 đến 1.
void time_set_scale(context &ctx, f32 scale)
Đặt tốc độ thời gian của game.
void time_set_paused(context &ctx, bool paused)
Tạm dừng hoặc chạy tiếp thời gian của game.
bool time_paused(const context &ctx)
Game có đang tạm dừng không.
f32 delta(const context &ctx)
Thời gian của frame trước, tính bằng giây, đã nhân với tốc độ thời gian.
f32 elapsed(const context &ctx)
Thời gian đã trôi qua kể từ lúc mở cửa sổ, tính bằng giây.
float f32
Số thực 32 bit.
Definition _types.h:28
Mô tả một module: một nhóm system có tên.
Definition _mod.h:67
Bộ sinh số ngẫu nhiên PCG32: nhanh, chất lượng tốt, và lặp lại được: cùng hạt giống thì cùng dãy số.
Definition _random.h:13
Mô tả một system kèm ràng buộc thứ tự, dùng với ecs_register().
Definition _mod.h:47