• 2311d游戏引擎适配ios


    原文
    通过遵循arsd:simpledisplay(v11.0.0之前)上的一些旧代码,Apple的文档和Jacob的这一惊人贡献,
    我已从金属绑定中删除了所有extern(Objective-C)代码,现在,所有Objective-C桥接代码都是使用D的反射生成的.
    因此,给定此例代码:

    import core.attribute : selector;
    extern(Objective-C):
    class MTKView
    {
        //创建要绘画到当前可绘画对象中的渲染传递描述符.
        @selector("currentRenderPassDescriptor")
        MTLRenderPassDescriptor currentRenderPassDescriptor();
    }
    class MTKView2 : MTKView
    {
        //创建要绘画到当前可绘画对象中的渲染传递描述符.
        @selector("currentRenderPassDescriptor2")
        MTLRenderPassDescriptor currentRenderPassDescriptor2();
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14

    现在有:

    mtkview.d
    module mtkview;
    import objc.meta : selector;
    @ObjectiveC final extern(C++):
    class MTKView
    {
        //创建要绘画到当前可绘画对象中的渲染传递描述符.
        @selector("currentRenderPassDescriptor")
        MTLRenderPassDescriptor currentRenderPassDescriptor();
    }
    class MTKView2
    {
        mixin ObjcExtends!(MTKView);
        //创建要绘画到当前可绘画对象中的渲染传递描述符.
        @selector("currentRenderPassDescriptor2")
        MTLRenderPassDescriptor currentRenderPassDescriptor2();
    }
    //metal_gen.d
    module metal_gen;
    import mtkview;
    mixin ObjcLinkModule!(mtkview);
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21

    这是如何从单独编译中获得实际优势的示例,分开编译反射接口代码可带来更好编译速度.

    mixin ObjcLinkModule用来迭代每个@ObjectiveCUDA,为类和接口中定义的每个方法生成实现.(是的,可在其他文件中实现类方法).
    final用来使D避免使用虚表,因为ObjectiveC对象不遵循D约定,因此要取名字空间和指针.这样,甚至可制作出不会出现段错误的如下有效代码:

    import mtkview;
    (cast(MTKView)(new int)).currentRenderPassDescriptor;
    
    • 1
    • 2

    虽然extern(C++)基本上是通过不生成TypeInfo节省一些内存,且可在因段错误需要转换时,避免D动态转换.
    尽管接口代码不像以前那样干净,但对用户来说,唯一改变的是,因为所有类都是最终的,因此不会按其父类隐式转换,而需要显式转换.

    我想,支持iOSM1是合理的.只是在整个引擎中,在更改绑定后,需要修复大约2行代码,因此,前端用户仍会有个好看代码.

    D金属绑定
    未来,提供对HipremeEngineiOS支持,并在MacOS构建选择器上,提供官方LDC支持,这样对普通用户,几乎可在所有平台使用该引擎😃

  • 相关阅读:
    Spring 是怎么解决循环依赖问题的呢?
    Layui弹出层关闭后页面自动刷新的用法以及建议
    网络的基本概念
    一文读懂Llama 2(从原理到实战)
    C# 找出两个Rectangle或是矩形的相互重合与非重合部分?
    ElasticSearch查询
    【IC设计】NoC(Network on Chip)调研
    PHP Cookie
    Redis高频面试题完整版
    哪里有期货开户的正规途径?
  • 原文地址:https://blog.csdn.net/fqbqrr/article/details/134259417