HEngine
  • 引擎编译
  • 未来工作
  • 使用文档
    • 代码规范
    • Shader规范
    • config 配置
  • Python脚本系统
    • 技术分析
    • 使用api
  • Cpp脚本系统
    • 技术分析
  • 技术文档 & 心得体会
    • 数学
      • 坐标系、UV与深度范围
      • 行主序 与 列主序
    • 路径管理
    • 构建系统
    • 自定义资源格式
    • UI
      • undo/redo
      • 分辨率处理
    • ECS 系统
    • 插件系统
    • 数学库
    • Ref Counted
    • 音频
    • ChatGPT
    • Mesh、Vertex 等组织关系
    • 编辑器热更新方案
    • Profile
    • NLP
    • RenderDoc
    • CodeGen与反射系统
    • 安装包
    • 物理引擎
      • PhysX集成
      • Bullet集成
    • 动画
  • 图形后端
    • 坐标系差异
    • Feature差异
    • RHI 封装
    • Shader与Constant Buffer
    • DX12
    • Vulkan
    • Render Graph
    • 渲染整体架构
  • 图形Feature
    • 毛发
    • 鼠标拾取
    • 实例化渲染
  • Shader
    • Shader 交叉编译
    • Shader Toy
    • Shader 热更新
    • PBR
  • 打包
    • 打包
  • Bug 记录 & 解决过程
    • 闪退记录汇总
    • 导入图片显示混乱
    • D3D下glfw+imgui失效
  • 其他资料
    • 总结集合
Powered by GitBook
On this page
  1. Cpp脚本系统

技术分析

为了兼顾游戏运行效率,增加一套cpp的脚本系统。

class CameraController : public ScriptableEntity
{
public:
    void OnCreate()
    {
        auto& translation = GetComponent<TransformComponent>().Translation;
        translation.x = rand() % 10 - 5.0f;
    }

    void OnDestroy()
    {
    }

    void OnUpdate(Timestep ts)
    {
        auto& translation = GetComponent<TransformComponent>().Translation;
        float speed = 5.0f;

        if (Input::IsKeyPressed(KeyCode::A))
            translation.x -= speed * ts;
        if (Input::IsKeyPressed(KeyCode::D))
            translation.x += speed * ts;
        if (Input::IsKeyPressed(KeyCode::W))
            translation.y += speed * ts;
        if (Input::IsKeyPressed(KeyCode::S))
            translation.y -= speed * ts;
    }
};

mCameraEntity.AddComponent<NativeScriptComponent>().Bind<CameraController>();
mSecondCamera.AddComponent<NativeScriptComponent>().Bind<CameraController>();

后续可以考虑使用反射的方式,把cpp脚本拖过去,自动Bind好对应的方法。

Previous使用apiNext数学

Last updated 2 years ago