Updates swift generated monster sample file (#6616)

Updates swift generated monster sample file
Adds frozen attribute
This commit is contained in:
mustiikhalil
2021-05-06 07:55:03 +03:00
committed by GitHub
parent a4bb8f0c2e
commit 8a582883ac
5 changed files with 28 additions and 22 deletions

View File

@@ -4,7 +4,7 @@
import FlatBuffers import FlatBuffers
public enum MyGame_Sample_Color: Int8, Enum { public enum MyGame_Sample_Color: Int8, Enum {
public typealias T = Int8 public typealias T = Int8
public static var byteSize: Int { return MemoryLayout<Int8>.size } public static var byteSize: Int { return MemoryLayout<Int8>.size }
public var value: Int8 { return self.rawValue } public var value: Int8 { return self.rawValue }
@@ -17,7 +17,7 @@ public enum MyGame_Sample_Color: Int8, Enum {
public static var min: MyGame_Sample_Color { return .red } public static var min: MyGame_Sample_Color { return .red }
} }
public enum MyGame_Sample_Equipment: UInt8, Enum { public enum MyGame_Sample_Equipment: UInt8, Enum {
public typealias T = UInt8 public typealias T = UInt8
public static var byteSize: Int { return MemoryLayout<UInt8>.size } public static var byteSize: Int { return MemoryLayout<UInt8>.size }
public var value: UInt8 { return self.rawValue } public var value: UInt8 { return self.rawValue }
@@ -113,7 +113,7 @@ public struct MyGame_Sample_Monster: FlatBufferObject {
public var weaponsCount: Int32 { let o = _accessor.offset(VTOFFSET.weapons.v); return o == 0 ? 0 : _accessor.vector(count: o) } public var weaponsCount: Int32 { let o = _accessor.offset(VTOFFSET.weapons.v); return o == 0 ? 0 : _accessor.vector(count: o) }
public func weapons(at index: Int32) -> MyGame_Sample_Weapon? { let o = _accessor.offset(VTOFFSET.weapons.v); return o == 0 ? nil : MyGame_Sample_Weapon(_accessor.bb, o: _accessor.indirect(_accessor.vector(at: o) + index * 4)) } public func weapons(at index: Int32) -> MyGame_Sample_Weapon? { let o = _accessor.offset(VTOFFSET.weapons.v); return o == 0 ? nil : MyGame_Sample_Weapon(_accessor.bb, o: _accessor.indirect(_accessor.vector(at: o) + index * 4)) }
public var equippedType: MyGame_Sample_Equipment { let o = _accessor.offset(VTOFFSET.equippedType.v); return o == 0 ? .none_ : MyGame_Sample_Equipment(rawValue: _accessor.readBuffer(of: UInt8.self, at: o)) ?? .none_ } public var equippedType: MyGame_Sample_Equipment { let o = _accessor.offset(VTOFFSET.equippedType.v); return o == 0 ? .none_ : MyGame_Sample_Equipment(rawValue: _accessor.readBuffer(of: UInt8.self, at: o)) ?? .none_ }
public func equipped<T: FlatBufferObject>(type: T.Type) -> T? { let o = _accessor.offset(VTOFFSET.equipped.v); return o == 0 ? nil : _accessor.union(o) } public func equipped<T: FlatbuffersInitializable>(type: T.Type) -> T? { let o = _accessor.offset(VTOFFSET.equipped.v); return o == 0 ? nil : _accessor.union(o) }
public var pathCount: Int32 { let o = _accessor.offset(VTOFFSET.path.v); return o == 0 ? 0 : _accessor.vector(count: o) } public var pathCount: Int32 { let o = _accessor.offset(VTOFFSET.path.v); return o == 0 ? 0 : _accessor.vector(count: o) }
public func path(at index: Int32) -> MyGame_Sample_Vec3? { let o = _accessor.offset(VTOFFSET.path.v); return o == 0 ? nil : _accessor.directRead(of: MyGame_Sample_Vec3.self, offset: _accessor.vector(at: o) + index * 12) } public func path(at index: Int32) -> MyGame_Sample_Vec3? { let o = _accessor.offset(VTOFFSET.path.v); return o == 0 ? nil : _accessor.directRead(of: MyGame_Sample_Vec3.self, offset: _accessor.vector(at: o) + index * 12) }
public func mutablePath(at index: Int32) -> MyGame_Sample_Vec3_Mutable? { let o = _accessor.offset(VTOFFSET.path.v); return o == 0 ? nil : MyGame_Sample_Vec3_Mutable(_accessor.bb, o: _accessor.vector(at: o) + index * 12) } public func mutablePath(at index: Int32) -> MyGame_Sample_Vec3_Mutable? { let o = _accessor.offset(VTOFFSET.path.v); return o == 0 ? nil : MyGame_Sample_Vec3_Mutable(_accessor.bb, o: _accessor.vector(at: o) + index * 12) }
@@ -121,30 +121,30 @@ public struct MyGame_Sample_Monster: FlatBufferObject {
public static func add(pos: MyGame_Sample_Vec3?, _ fbb: inout FlatBufferBuilder) { guard let pos = pos else { return }; fbb.create(struct: pos, position: VTOFFSET.pos.p) } public static func add(pos: MyGame_Sample_Vec3?, _ fbb: inout FlatBufferBuilder) { guard let pos = pos else { return }; fbb.create(struct: pos, position: VTOFFSET.pos.p) }
public static func add(mana: Int16, _ fbb: inout FlatBufferBuilder) { fbb.add(element: mana, def: 150, at: VTOFFSET.mana.p) } public static func add(mana: Int16, _ fbb: inout FlatBufferBuilder) { fbb.add(element: mana, def: 150, at: VTOFFSET.mana.p) }
public static func add(hp: Int16, _ fbb: inout FlatBufferBuilder) { fbb.add(element: hp, def: 100, at: VTOFFSET.hp.p) } public static func add(hp: Int16, _ fbb: inout FlatBufferBuilder) { fbb.add(element: hp, def: 100, at: VTOFFSET.hp.p) }
public static func add(name: Offset<String>, _ fbb: inout FlatBufferBuilder) { fbb.add(offset: name, at: VTOFFSET.name.p) } public static func add(name: Offset, _ fbb: inout FlatBufferBuilder) { fbb.add(offset: name, at: VTOFFSET.name.p) }
public static func addVectorOf(inventory: Offset<UOffset>, _ fbb: inout FlatBufferBuilder) { fbb.add(offset: inventory, at: VTOFFSET.inventory.p) } public static func addVectorOf(inventory: Offset, _ fbb: inout FlatBufferBuilder) { fbb.add(offset: inventory, at: VTOFFSET.inventory.p) }
public static func add(color: MyGame_Sample_Color, _ fbb: inout FlatBufferBuilder) { fbb.add(element: color.rawValue, def: 2, at: VTOFFSET.color.p) } public static func add(color: MyGame_Sample_Color, _ fbb: inout FlatBufferBuilder) { fbb.add(element: color.rawValue, def: 2, at: VTOFFSET.color.p) }
public static func addVectorOf(weapons: Offset<UOffset>, _ fbb: inout FlatBufferBuilder) { fbb.add(offset: weapons, at: VTOFFSET.weapons.p) } public static func addVectorOf(weapons: Offset, _ fbb: inout FlatBufferBuilder) { fbb.add(offset: weapons, at: VTOFFSET.weapons.p) }
public static func add(equippedType: MyGame_Sample_Equipment, _ fbb: inout FlatBufferBuilder) { fbb.add(element: equippedType.rawValue, def: 0, at: VTOFFSET.equippedType.p) } public static func add(equippedType: MyGame_Sample_Equipment, _ fbb: inout FlatBufferBuilder) { fbb.add(element: equippedType.rawValue, def: 0, at: VTOFFSET.equippedType.p) }
public static func add(equipped: Offset<UOffset>, _ fbb: inout FlatBufferBuilder) { fbb.add(offset: equipped, at: VTOFFSET.equipped.p) } public static func add(equipped: Offset, _ fbb: inout FlatBufferBuilder) { fbb.add(offset: equipped, at: VTOFFSET.equipped.p) }
public static func addVectorOf(path: Offset<UOffset>, _ fbb: inout FlatBufferBuilder) { fbb.add(offset: path, at: VTOFFSET.path.p) } public static func addVectorOf(path: Offset, _ fbb: inout FlatBufferBuilder) { fbb.add(offset: path, at: VTOFFSET.path.p) }
public static func startVectorOfPath(_ size: Int, in builder: inout FlatBufferBuilder) { public static func startVectorOfPath(_ size: Int, in builder: inout FlatBufferBuilder) {
builder.startVector(size * MemoryLayout<MyGame_Sample_Vec3>.size, elementSize: MemoryLayout<MyGame_Sample_Vec3>.alignment) builder.startVector(size * MemoryLayout<MyGame_Sample_Vec3>.size, elementSize: MemoryLayout<MyGame_Sample_Vec3>.alignment)
} }
public static func endMonster(_ fbb: inout FlatBufferBuilder, start: UOffset) -> Offset<UOffset> { let end = Offset<UOffset>(offset: fbb.endTable(at: start)); return end } public static func endMonster(_ fbb: inout FlatBufferBuilder, start: UOffset) -> Offset { let end = Offset(offset: fbb.endTable(at: start)); return end }
public static func createMonster( public static func createMonster(
_ fbb: inout FlatBufferBuilder, _ fbb: inout FlatBufferBuilder,
pos: MyGame_Sample_Vec3? = nil, pos: MyGame_Sample_Vec3? = nil,
mana: Int16 = 150, mana: Int16 = 150,
hp: Int16 = 100, hp: Int16 = 100,
nameOffset name: Offset<String> = Offset(), nameOffset name: Offset = Offset(),
inventoryVectorOffset inventory: Offset<UOffset> = Offset(), inventoryVectorOffset inventory: Offset = Offset(),
color: MyGame_Sample_Color = .blue, color: MyGame_Sample_Color = .blue,
weaponsVectorOffset weapons: Offset<UOffset> = Offset(), weaponsVectorOffset weapons: Offset = Offset(),
equippedType: MyGame_Sample_Equipment = .none_, equippedType: MyGame_Sample_Equipment = .none_,
equippedOffset equipped: Offset<UOffset> = Offset(), equippedOffset equipped: Offset = Offset(),
pathVectorOffset path: Offset<UOffset> = Offset() pathVectorOffset path: Offset = Offset()
) -> Offset<UOffset> { ) -> Offset {
let __start = MyGame_Sample_Monster.startMonster(&fbb) let __start = MyGame_Sample_Monster.startMonster(&fbb)
MyGame_Sample_Monster.add(pos: pos, &fbb) MyGame_Sample_Monster.add(pos: pos, &fbb)
MyGame_Sample_Monster.add(mana: mana, &fbb) MyGame_Sample_Monster.add(mana: mana, &fbb)
@@ -183,14 +183,14 @@ public struct MyGame_Sample_Weapon: FlatBufferObject {
public var damage: Int16 { let o = _accessor.offset(VTOFFSET.damage.v); return o == 0 ? 0 : _accessor.readBuffer(of: Int16.self, at: o) } public var damage: Int16 { let o = _accessor.offset(VTOFFSET.damage.v); return o == 0 ? 0 : _accessor.readBuffer(of: Int16.self, at: o) }
@discardableResult public func mutate(damage: Int16) -> Bool {let o = _accessor.offset(VTOFFSET.damage.v); return _accessor.mutate(damage, index: o) } @discardableResult public func mutate(damage: Int16) -> Bool {let o = _accessor.offset(VTOFFSET.damage.v); return _accessor.mutate(damage, index: o) }
public static func startWeapon(_ fbb: inout FlatBufferBuilder) -> UOffset { fbb.startTable(with: 2) } public static func startWeapon(_ fbb: inout FlatBufferBuilder) -> UOffset { fbb.startTable(with: 2) }
public static func add(name: Offset<String>, _ fbb: inout FlatBufferBuilder) { fbb.add(offset: name, at: VTOFFSET.name.p) } public static func add(name: Offset, _ fbb: inout FlatBufferBuilder) { fbb.add(offset: name, at: VTOFFSET.name.p) }
public static func add(damage: Int16, _ fbb: inout FlatBufferBuilder) { fbb.add(element: damage, def: 0, at: VTOFFSET.damage.p) } public static func add(damage: Int16, _ fbb: inout FlatBufferBuilder) { fbb.add(element: damage, def: 0, at: VTOFFSET.damage.p) }
public static func endWeapon(_ fbb: inout FlatBufferBuilder, start: UOffset) -> Offset<UOffset> { let end = Offset<UOffset>(offset: fbb.endTable(at: start)); return end } public static func endWeapon(_ fbb: inout FlatBufferBuilder, start: UOffset) -> Offset { let end = Offset(offset: fbb.endTable(at: start)); return end }
public static func createWeapon( public static func createWeapon(
_ fbb: inout FlatBufferBuilder, _ fbb: inout FlatBufferBuilder,
nameOffset name: Offset<String> = Offset(), nameOffset name: Offset = Offset(),
damage: Int16 = 0 damage: Int16 = 0
) -> Offset<UOffset> { ) -> Offset {
let __start = MyGame_Sample_Weapon.startWeapon(&fbb) let __start = MyGame_Sample_Weapon.startWeapon(&fbb)
MyGame_Sample_Weapon.add(name: name, &fbb) MyGame_Sample_Weapon.add(name: name, &fbb)
MyGame_Sample_Weapon.add(damage: damage, &fbb) MyGame_Sample_Weapon.add(damage: damage, &fbb)

View File

@@ -16,6 +16,7 @@
import Foundation import Foundation
@frozen
public struct ByteBuffer { public struct ByteBuffer {
/// Storage is a container that would hold the memory pointer to solve the issue of /// Storage is a container that would hold the memory pointer to solve the issue of
@@ -29,12 +30,14 @@ public struct ByteBuffer {
/// Capacity of UInt8 the buffer can hold /// Capacity of UInt8 the buffer can hold
var capacity: Int var capacity: Int
@usableFromInline
init(count: Int, alignment: Int) { init(count: Int, alignment: Int) {
memory = UnsafeMutableRawPointer.allocate(byteCount: count, alignment: alignment) memory = UnsafeMutableRawPointer.allocate(byteCount: count, alignment: alignment)
capacity = count capacity = count
unowned = false unowned = false
} }
@usableFromInline
init(memory: UnsafeMutableRawPointer, capacity: Int, unowned: Bool) { init(memory: UnsafeMutableRawPointer, capacity: Int, unowned: Bool) {
self.memory = memory self.memory = memory
self.capacity = capacity self.capacity = capacity
@@ -47,6 +50,7 @@ public struct ByteBuffer {
} }
} }
@usableFromInline
func copy(from ptr: UnsafeRawPointer, count: Int) { func copy(from ptr: UnsafeRawPointer, count: Int) {
assert( assert(
!unowned, !unowned,
@@ -54,6 +58,7 @@ public struct ByteBuffer {
memory.copyMemory(from: ptr, byteCount: count) memory.copyMemory(from: ptr, byteCount: count)
} }
@usableFromInline
func initialize(for size: Int) { func initialize(for size: Int) {
assert( assert(
!unowned, !unowned,

View File

@@ -16,6 +16,7 @@
import Foundation import Foundation
@frozen
public struct FlatBufferBuilder { public struct FlatBufferBuilder {
/// Storage for the Vtables used in the buffer are stored in here, so they would be written later in EndTable /// Storage for the Vtables used in the buffer are stored in here, so they would be written later in EndTable
@@ -532,6 +533,7 @@ extension FlatBufferBuilder: CustomDebugStringConvertible {
var addedElements: Int { capacity - (numOfFields &* size) } var addedElements: Int { capacity - (numOfFields &* size) }
/// Creates the memory to store the buffer in /// Creates the memory to store the buffer in
@usableFromInline
init() { init() {
memory = UnsafeMutableRawBufferPointer.allocate(byteCount: 0, alignment: 0) memory = UnsafeMutableRawBufferPointer.allocate(byteCount: 0, alignment: 0)
} }

View File

@@ -16,6 +16,7 @@
import Foundation import Foundation
@frozen
public struct Struct { public struct Struct {
public private(set) var bb: ByteBuffer public private(set) var bb: ByteBuffer
public private(set) var postion: Int32 public private(set) var postion: Int32

View File

@@ -16,6 +16,7 @@
import Foundation import Foundation
@frozen
public struct Table { public struct Table {
public private(set) var bb: ByteBuffer public private(set) var bb: ByteBuffer
public private(set) var postion: Int32 public private(set) var postion: Int32
@@ -113,9 +114,6 @@ public struct Table {
o += postion o += postion
return o + bb.read(def: Int32.self, position: Int(o)) + 4 return o + bb.read(def: Int32.self, position: Int(o)) + 4
} }
}
extension Table {
static public func indirect(_ o: Int32, _ fbb: ByteBuffer) -> Int32 { o + fbb.read( static public func indirect(_ o: Int32, _ fbb: ByteBuffer) -> Int32 { o + fbb.read(
def: Int32.self, def: Int32.self,