Last active
November 10, 2017 00:24
-
-
Save csmr/87eae0fa218efba43f9fc661b270ceb4 to your computer and use it in GitHub Desktop.
An improved yet simple solution to render view by msec intervals
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def run argh | |
# require 'pry'; binding.pry | |
p_dbg "- run #{argh} #{Thread.current.to_s} - #{@debug_frame.to_s}", self | |
state_int = argh | |
while state_int == 1 | |
@debug_frame += 1 | |
ui_handle_input | |
ui_refresh(0) | |
read_pipes | |
end | |
end # run loop | |
def ui_refresh(ui) | |
drawing_bool = true | |
ui_render_view | |
@refresh_frame += 1 | |
drawing_bool = false | |
end | |
def ui_render_view | |
if @refresh_frame%240 == 0 | |
p_dbg "refresh frame #{@refresh_frame}, run frame #{@debug_frame} - Type 1 to send msg to engine, 2 to msg stateserver, Q to exit." | |
end | |
# STDOUT.write (@refresh_frame%24).to_s.rjust(3, "0") + "\r" | |
end | |
def ui_handle_input | |
@in_str = read_line_nonblocking( STDIN, @refreshdelay_secs ) | |
if @in_str == "\t" || @in_str.nil? | |
@in_str = nil | |
return | |
end | |
p_dbg "UI got input #{@in_str}", self | |
case @in_str | |
when "Q", "\u0003" | |
ui_message_engine "Q" | |
ui_message_stateserver "Q" | |
exit | |
when "1" | |
ui_message_engine "1" | |
when "2" | |
ui_message_engine "2" | |
else | |
# bye! | |
end | |
@in_str = nil | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment