Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More ergonomic way of creating draw callbacks #346

Open
Ruin0x11 opened this issue May 5, 2021 · 0 comments
Open

More ergonomic way of creating draw callbacks #346

Ruin0x11 opened this issue May 5, 2021 · 0 comments
Labels
design Concerns the architecture of the engine modding Concerns new modding features beyond the scope of porting vanilla's codebase.

Comments

@Ruin0x11
Copy link
Owner

Ruin0x11 commented May 5, 2021

The draw callback system can be error-prone if misused, because you have to call coroutine.yield (Draw.yield) manually inside the callback closure you submit.

local cb = function(draw_x, draw_y)
   local t = UiTheme.load()
   local frames = 0.0
   while true do
      t.base.void:draw(0, 0, Draw.get_width(), Draw.get_height())
      local _, _, _, dt = Draw.yield(config.base.general_wait)
      frames = frames + dt
      if frames > 10.0 then
         break
      end
   end
end

Draw.start_draw_callback(cb)

A cleaner interface might help.

local cb = {}

function cb:init()
   self.t = UiTheme.load()
   self.frames = 0.0
end

function cb:draw(draw_x, draw_y)
   self.t.base.void:draw(0, 0, Draw.get_width(), Draw.get_height())
end

function cb:update(dt)
   self.frames = self.frames + dt
   if self.frames > 10.0
      return true
   end

   return false, config.base.general_wait
end

Draw.start_draw_callback(cb)

The :update() function would return the continue/stop result and the amount of delta time to wait for. The scheduling and execution would be handled behind the scenes.

This would also make it easier to program and instantiate new classes that implement the draw callback interface instead of needing to allocate a new closure every time.

@Ruin0x11 Ruin0x11 added design Concerns the architecture of the engine modding Concerns new modding features beyond the scope of porting vanilla's codebase. labels May 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design Concerns the architecture of the engine modding Concerns new modding features beyond the scope of porting vanilla's codebase.
Projects
None yet
Development

No branches or pull requests

1 participant