摄像机系统,和子对象绑定

This commit is contained in:
ArchZer0
2026-08-17 16:15:05 +08:00
parent 63d97f058a
commit 7b7756f0fe
20 changed files with 744 additions and 132 deletions
+24 -1
View File
@@ -8,6 +8,8 @@
#include <vector>
#include <boundard.hpp>
#include <camera.hpp>
#include <sprite_actor.hpp>
namespace boundard {
namespace {
@@ -24,9 +26,21 @@ std::shared_ptr<Actor> create_actor(const ActorConfig& actor_config, Game& game,
mesh->set_color(actor_config.mesh.color);
mesh->texture = actor_config.mesh.texture;
auto actor = std::make_shared<Actor>(actor_config.name, game, mesh);
std::shared_ptr<Actor> actor;
if (actor_config.type == "camera") {
actor = std::make_shared<Camera>(actor_config.name, game);
} else {
actor = std::make_shared<SpriteActor>(actor_config.name, game, mesh);
}
actor->set_position(actor_config.position);
actor->set_facing(actor_config.facing);
if (auto* camera = dynamic_cast<Camera*>(actor.get())) {
camera->set_zoom(actor_config.zoom);
}
for (const ActorConfig& child_config : actor_config.children) {
actor->add_child(create_actor(child_config, game, behaviors));
}
if (!actor_config.init_function.empty()) {
auto handler = behaviors.init(actor_config.init_function);
@@ -55,10 +69,18 @@ std::shared_ptr<Scene> build_scene(const SceneConfig& scene, Game& game,
BehaviorRegistry& behaviors) {
auto runtime_scene = std::make_shared<Scene>(scene.name);
if (scene.grid_background) {
auto grid = std::make_shared<SpriteActor>("__grid", game,
std::make_shared<Mesh>(Mesh::grid()));
grid->mesh()->set_color({0.20F, 0.28F, 0.36F, 0.75F});
runtime_scene->add_actor(std::move(grid));
}
for (const ActorConfig& actor_config : scene.actors) {
auto actor = create_actor(actor_config, game, behaviors);
runtime_scene->add_actor(std::move(actor));
}
runtime_scene->set_default_camera(scene.default_camera);
return runtime_scene;
}
@@ -143,6 +165,7 @@ int run_engine(int argc, char** argv, const char* default_config_path) {
scene->initialize();
game.set_current_scene(scene);
render_loop.set_actors(scene->actors());
render_loop.set_camera(scene->primary_camera());
};
if (active_scene != nullptr) {