Skip to content

Commit

Permalink
Configure rubocop (#6)
Browse files Browse the repository at this point in the history
* Fix string literals

* Add a few more cops

* Fix cops

* Fix action ruby version

* Fix action
  • Loading branch information
ggraca authored Feb 6, 2024
1 parent ac3301f commit ec961a6
Show file tree
Hide file tree
Showing 51 changed files with 113 additions and 104 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/linters.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: linters
on: [pull_request]

jobs:
rubocop:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- run: bundle exec rubocop
7 changes: 7 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,10 @@ require:
AllCops:
TargetRubyVersion: 3.1.2
NewCops: enable
Exclude:
- vendor/bundle/**/*
- "**/*_spec.rb"

# It's common to have one-line methods for component helpers
Layout/EmptyLineBetweenDefs:
AllowAdjacentOneLineDefs: true
2 changes: 0 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,3 @@ path "." do
end

gemspec path: "./belts"

gem "rspec"
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ PLATFORMS

DEPENDENCIES
belts!
rspec
rspec (~> 3.12)
rubocop-rspec (~> 2.11)
standard (~> 1.12)

Expand Down
2 changes: 1 addition & 1 deletion assimp_bindings/lib/assimp/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Node < FFI::Struct
mChildren: NodePointer.ptr,
mNumMeshes: :uint,
mMeshes: :pointer, # TODO
mMetaData: :pointer, # TODO: MetaData.ptr
mMetaData: :pointer # TODO: MetaData.ptr
)
end
end
7 changes: 4 additions & 3 deletions belts/belts.gemspec
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
VERSION ||= File.read(File.expand_path("../.belts-version", __dir__)).strip
version = File.read(File.expand_path("../.belts-version", __dir__)).strip

Gem::Specification.new do |s|
s.name = "belts"
s.version = VERSION
s.version = version
s.summary = "A data-oriented game engine for Ruby."
s.author = "Guilherme Graca"
s.homepage = "https://github.com/ggraca/belts"
Expand All @@ -12,8 +12,9 @@ Gem::Specification.new do |s|
s.executable = "belts"

s.required_ruby_version = ">= 3.1.2"
s.add_dependency "belts_engine", VERSION
s.add_dependency "belts_engine", version
s.add_dependency "thor", "~> 1.2.1"
s.add_development_dependency "standard", "~> 1.12"
s.add_development_dependency "rspec", "~> 3.12"
s.add_development_dependency "rubocop-rspec", "~> 2.11"
end
6 changes: 3 additions & 3 deletions belts_engine/belts_engine.gemspec
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
VERSION ||= File.read(File.expand_path("../.belts-version", __dir__)).strip
version = File.read(File.expand_path("../.belts-version", __dir__)).strip

Gem::Specification.new do |s|
s.name = "belts_engine"
s.version = VERSION
s.version = version
s.summary = "The core functionality of the Belts game engine"
s.author = "Guilherme Graca"
s.homepage = "https://github.com/ggraca/belts"
Expand All @@ -11,5 +11,5 @@ Gem::Specification.new do |s|
s.files = Dir.glob("lib/**/*")

s.required_ruby_version = ">= 3.1.2"
s.add_dependency "belts_support", VERSION
s.add_dependency "belts_support", version
end
2 changes: 1 addition & 1 deletion belts_engine/lib/belts_assets/config/model_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def included(base)
module ClassMethods
def model(key, file)
@@models ||= {}
@@models[key] = { file: Dir["assets/#{file}"].first }
@@models[key] = {file: Dir["assets/#{file}"].first}
end

def models
Expand Down
19 changes: 9 additions & 10 deletions belts_engine/lib/belts_assets/importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ def initialize(key, file_path)
@scene = Assimp.aiImportFile(file_path,
Assimp::Process::Preset::TARGET_REALTIME_MAX_QUALITY |
Assimp::Process::CONVERT_TO_LEFT_HANDED |
Assimp::Process::EMBED_TEXTURES
)
Assimp::Process::EMBED_TEXTURES)

@model = Model.new
@model.id = @global_id = key
Expand All @@ -22,7 +21,7 @@ def initialize(key, file_path)
private

def import_meshes
@scene[:mNumMeshes].times.map do |i|
Array.new(@scene[:mNumMeshes]) do |i|
pointer = Assimp::MeshPointer.new(@scene[:mMeshes].to_ptr + i * Assimp::MeshPointer.size)
import_mesh(pointer[:mesh], i)
end
Expand All @@ -34,7 +33,7 @@ def import_mesh(mesh_data, index)
mesh.name = mesh_data[:mName][:data].to_s
mesh.material_id = fetch_material_id(mesh_data[:mMaterialIndex])

mesh_data[:mNumVertices].times.map do |i|
Array.new(mesh_data[:mNumVertices]) do |i|
mesh.positions << Assimp::Vector3D.new(mesh_data[:mVertices].to_ptr + i * Assimp::Vector3D.size).values

if !mesh_data[:mNormals].null?
Expand All @@ -52,7 +51,7 @@ def import_mesh(mesh_data, index)
mesh.colors << [1, 0, 0, 1]
end

mesh_data[:mNumFaces].times.map do |i|
Array.new(mesh_data[:mNumFaces]) do |i|
face = Assimp::Face.new(mesh_data[:mFaces] + i * Assimp::Face.size)
mesh.indices << face[:mIndices].to_ptr.read_array_of_uint(face[:mNumIndices])
end
Expand All @@ -63,7 +62,7 @@ def import_mesh(mesh_data, index)
end

def import_materials
@scene[:mNumMaterials].times.map do |i|
Array.new(@scene[:mNumMaterials]) do |i|
pointer = Assimp::MaterialPointer.new(@scene[:mMaterials].to_ptr + i * Assimp::MaterialPointer.size)
import_material(pointer[:material], i)
end
Expand Down Expand Up @@ -113,9 +112,9 @@ def import_nodes(parent_node = nil, cur_node_data = @scene[:mRootNode])
model_node.parent = parent_node

local_ids = cur_node_data[:mMeshes].read_array_of_uint(cur_node_data[:mNumMeshes])
model_node.mesh_ids = local_ids.map {|id| fetch_mesh_id(id) }
model_node.mesh_ids = local_ids.map { |id| fetch_mesh_id(id) }

cur_node_data[:mNumChildren].times.each do |i|
cur_node_data[:mNumChildren].times do |i|
pointer = Assimp::NodePointer.new(cur_node_data[:mChildren].to_ptr + i * Assimp::NodePointer.size)
child_node_data = pointer[:node]

Expand All @@ -126,11 +125,11 @@ def import_nodes(parent_node = nil, cur_node_data = @scene[:mRootNode])
end

def fetch_mesh_id(local_id)
"#{@global_id}_mesh_#{local_id}".to_sym
:"#{@global_id}_mesh_#{local_id}"
end

def fetch_material_id(local_id)
"#{@global_id}_material_#{local_id}".to_sym
:"#{@global_id}_material_#{local_id}"
end
end
end
2 changes: 1 addition & 1 deletion belts_engine/lib/belts_assets/mesh.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def initialize
end

def vertices
@positions.size.times.map do |i|
Array.new(@positions.size) do |i|
[*positions[i], *normals[i], *colors[i]]
end.flatten
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Tools
class AssetManager
class MaterialManager < BaseManager
def add_material(material)
raise 'Material must have an id' if material.id.nil?
raise "Material must have an id" if material.id.nil?
self[material.id] = material
end
end
Expand Down
2 changes: 1 addition & 1 deletion belts_engine/lib/belts_bgfx/input_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def parse_events
event = SDL::Event.new
while SDL.PollEvent(event) != 0
event_type = event[:common][:type]
event_timestamp = event[:common][:timestamp]
_event_timestamp = event[:common][:timestamp]

case event_type
when SDL::KEYDOWN
Expand Down
2 changes: 1 addition & 1 deletion belts_engine/lib/belts_engine.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require "belts_support"
require_relative "./patches"
require_relative "patches"

[:vec2, :vec3, :vec4, :quat, :mat4].each do |struct|
require_relative "./belts_engine/structs/#{struct}"
Expand Down
1 change: 0 additions & 1 deletion belts_engine/lib/belts_engine/application.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
module BeltsEngine

# The application ensures all libraries are loaded before starting the game.
# It can also handle some pre-processing (e.g. compiling assets)
class Application
Expand Down
2 changes: 1 addition & 1 deletion belts_engine/lib/belts_engine/components/camera.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Camera < BeltsSupport::Component
layout(
projection_type: :ulong,
projection_type: :ulong
)

class << self
Expand Down
2 changes: 1 addition & 1 deletion belts_engine/lib/belts_engine/components/light.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Light < BeltsSupport::Component
layout(
light_type: :ulong,
light_type: :ulong
)

class << self
Expand Down
2 changes: 1 addition & 1 deletion belts_engine/lib/belts_engine/components/position.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ class Position < BeltsSupport::Component
include Vec3::Behaviour

def move!(dir)
self.set!(self + dir)
set!(self + dir)
end
end
2 changes: 1 addition & 1 deletion belts_engine/lib/belts_engine/components/render_data.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class RenderData < BeltsSupport::Component
layout(
model: :ulong,
model: :ulong
)

class << self
Expand Down
6 changes: 3 additions & 3 deletions belts_engine/lib/belts_engine/ecs/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def initialize(flecs_query, flecs_world, filters)
name: name,
klass: klass,
size: klass.size,
index: i + 1, # Component indexes start at 1
index: i + 1 # Component indexes start at 1
}
end
end
Expand All @@ -23,12 +23,12 @@ def each_with_components(&block)
components_requested = @components.slice(*params)

it = Flecs.ecs_query_iter(@flecs_world, @flecs_query)
while(Flecs.ecs_query_next(it))
while Flecs.ecs_query_next(it)
components = components_requested.values.map do |component|
component.merge(pointer: Flecs.ecs_field_w_size(it, component[:size], component[:index]))
end

it[:count].times.each do |i|
it[:count].times do |i|
fields = {}

if entity_requested
Expand Down
2 changes: 1 addition & 1 deletion belts_engine/lib/belts_engine/structs/quat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def included(base)

[:x, :y, :z, :w].each_with_index do |key, index|
base.define_method(key) { self[:values][index] }
base.define_method("#{key}=") { |value| self[:values][index] = value }
base.define_method(:"#{key}=") { |value| self[:values][index] = value }
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion belts_engine/lib/belts_engine/structs/vec2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def included(base)

[:x, :y].each_with_index do |key, index|
base.define_method(key) { self[:values][index] }
base.define_method("#{key}=") { |value| self[:values][index] = value }
base.define_method(:"#{key}=") { |value| self[:values][index] = value }
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion belts_engine/lib/belts_engine/structs/vec3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def included(base)

[:x, :y, :z].each_with_index do |key, index|
base.define_method(key) { self[:values][index] }
base.define_method("#{key}=") { |value| self[:values][index] = value }
base.define_method(:"#{key}=") { |value| self[:values][index] = value }
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion belts_engine/lib/belts_engine/structs/vec4.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def included(base)

[:x, :y, :z, :w].each_with_index do |key, index|
base.define_method(key) { self[:values][index] }
base.define_method("#{key}=") { |value| self[:values][index] = value }
base.define_method(:"#{key}=") { |value| self[:values][index] = value }
end
end
end
Expand Down
19 changes: 5 additions & 14 deletions belts_engine/lib/belts_engine/system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ def initialize(game)
end

# Runs once before the first update
def start; end
def start
end

# Runs once per frame
def update; end
def update
end

def progress(ctx = nil)
return update if @started
Expand All @@ -29,19 +31,8 @@ def progress(ctx = nil)

def register_tool_shortcuts
@game.tools.each do |key, value|
instance_variable_set("@#{key}", value)
instance_variable_set(:"@#{key}", value)
end
end

def debug(db = true)
return yield unless db
RubyProf.start

yield
result = RubyProf.stop
printer = RubyProf::FlatPrinter.new(result)
printer.print(STDOUT)
exit
end
end
end
2 changes: 1 addition & 1 deletion belts_engine/lib/belts_engine/tools/ecs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def init_phases
on_validate: Flecs.EcsOnValidate,
post_update: Flecs.EcsPostUpdate,
pre_store: Flecs.EcsPreStore,
on_store: Flecs.EcsOnStore,
on_store: Flecs.EcsOnStore
)
end

Expand Down
4 changes: 2 additions & 2 deletions belts_support/belts_support.gemspec
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
VERSION ||= File.read(File.expand_path("../.belts-version", __dir__)).strip
version = File.read(File.expand_path("../.belts-version", __dir__)).strip

Gem::Specification.new do |s|
s.name = "belts_support"
s.version = VERSION
s.version = version
s.summary = "Common tools for the Belts game engine"
s.author = "Guilherme Graca"
s.homepage = "https://github.com/ggraca/belts"
Expand Down
6 changes: 4 additions & 2 deletions belts_support/lib/belts_support/extension.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
module BeltsSupport
module Extension
# Handle application installation (loading libraries, mixins, etc.)
def install; end
def install
end

# Handle game initialization (registering tools, loading assets, etc.)
def init(game); end
def init(game)
end
end
end
2 changes: 1 addition & 1 deletion flecs_bindings/lib/flecs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ module Flecs
:EcsOnValidate,
:EcsPostUpdate,
:EcsPreStore,
:EcsOnStore,
:EcsOnStore
].each do |name|
attach_variable name, :ecs_entity_t
end
Expand Down
2 changes: 1 addition & 1 deletion flecs_bindings/lib/flecs/component_desc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class ComponentDesc < FFI::Struct
layout(
_canary: :int32,
entity: :ecs_entity_t,
type: TypeInfo.by_value,
type: TypeInfo.by_value
)
end
end
2 changes: 1 addition & 1 deletion flecs_bindings/lib/flecs/filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Filter < FFI::Struct
entity: :ecs_entity_t,
iterable: Iterable.by_value,
dtor: :ecs_poly_dtor_t,
world: :ecs_world_tp,
world: :ecs_world_tp
)
end
end
Loading

0 comments on commit ec961a6

Please sign in to comment.