Module: Draco

Defined in:
lib/draco.rb,
lib/draco/benchmark.rb

Overview

Public: The Draco ECS library.

Defined Under Namespace

Modules: Benchmark Classes: Component, Entity, NotAComponentError, Set, System, World

Constant Summary collapse

VERSION =

Public: The version of the library. Draco uses semver to version releases.

"0.6.1"

Class Method Summary collapse

Class Method Details

.camelize(string) ⇒ Object

Internal: Converts an underscored string into a camel case string.

Examples

camlize("camel_case")
# => "CamelCase"

Returns a string.



947
948
949
950
951
952
953
954
955
956
957
958
959
960
# File 'lib/draco.rb', line 947

def self.camelize(string) # rubocop:disable Metrics/MethodLength
  modifier = -32

  string.to_s.bytes.map do |byte|
    if byte == 95
      modifier = -32
      nil
    else
      char = (byte + modifier).chr
      modifier = 0
      char
    end
  end.compact.join
end

.Tag(name) ⇒ Object

Public: Creates a new empty component at runtime. If the given Class already exists, it reuses the existing Class.

name - The symbol or string name of the component. It can be either camelcase or underscored.

Returns a Class with superclass of Draco::Component.



391
392
393
394
395
396
397
398
# File 'lib/draco.rb', line 391

def self.Tag(name) # rubocop:disable Naming/MethodName
  klass_name = camelize(name)

  return Object.const_get(klass_name) if Object.const_defined?(klass_name)

  klass = Class.new(Component)
  Object.const_set(klass_name, klass)
end

.underscore(string) ⇒ Object

Internal: Converts a camel cased string to an underscored string.

Examples

underscore("CamelCase")
# => "camel_case"

Returns a String.



928
929
930
931
932
933
934
935
936
937
# File 'lib/draco.rb', line 928

def self.underscore(string)
  string.to_s.split("::").last.bytes.map.with_index do |byte, i|
    if byte > 64 && byte < 97
      downcased = byte + 32
      i.zero? ? downcased.chr : "_#{downcased.chr}"
    else
      byte.chr
    end
  end.join
end