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

Improve headless handling #131

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions dist/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -263,13 +263,22 @@ input:hover,input:active {
}

#headless-notification {
display: none;
display: grid;
place-content: center;
position: fixed;
color: white;
top: 1rem;
width: 100%;
font-size: 200px;
left: 0;
top: 0;
padding-left: 10px;
animation: blink infinite alternate 0.5s;
transition: visibility 0.5s, opacity 0.5s;
}
#headless-notification.hide {
opacity: 0;
visibility: collapse;
}
@keyframes blink {
from { color: hsl(0, 0%, 80%); }
to { color: hsl(0, 0%, 40%); }
}

#minimize {
Expand Down
2 changes: 1 addition & 1 deletion dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ <h2>Statistics</h2>
<button class="headless" title="Toggle rendering. Hotkey: H"><i class="fa fa-eye-slash"></i></button>
<button class='pause-button' title="Play/Pause. Hotkey: Spacebar"><i class="fa fa-pause"></i></button>
</div>
<div id="headless-notification">
<div id="headless-notification" class="hide">
<i class="fa fa-eye-slash" ></i>
</div>
<div id='maximize-hot-control' class='hot-controls'>
Expand Down
37 changes: 5 additions & 32 deletions src/Controllers/ControlPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ class ControlPanel {
this.env_controller.setControlPanel(this);
this.editor_controller.setControlPanel(this);
this.stats_panel = new StatsPanel(this.engine.env);
this.headless_opacity = 1;
this.opacity_change_rate = -0.8;
this.paused=false;
this.setHyperparamDefaults();
}
Expand Down Expand Up @@ -132,15 +130,10 @@ class ControlPanel {
}.bind(this));

$('.headless').click(function() {
$('.headless').find("i").toggleClass("fa fa-eye");
$('.headless').find("i").toggleClass("fa fa-eye-slash");
if (WorldConfig.headless){
$('#headless-notification').css('display', 'none');
this.engine.env.renderFull();
}
else {
$('#headless-notification').css('display', 'block');
}
$('.headless').find("i").toggleClass("fa-eye fa-eye-slash");
$('#headless-notification').toggleClass('hide');
if (WorldConfig.headless) this.engine.env.renderFull();

WorldConfig.headless = !WorldConfig.headless;
}.bind(this));
}
Expand Down Expand Up @@ -477,30 +470,10 @@ class ControlPanel {
this.fps = this.engine.fps;
}

updateHeadlessIcon(delta_time) {
if (!this.engine.running)
return;
const min_opacity = 0.4;
var op = this.headless_opacity + (this.opacity_change_rate*delta_time/1000);
if (op <= min_opacity){
op=min_opacity;
this.opacity_change_rate = -this.opacity_change_rate;
}
else if (op >= 1){
op=1;
this.opacity_change_rate = -this.opacity_change_rate;
}
this.headless_opacity = op;
$('#headless-notification').css('opacity',(op*100)+'%');
}

update(delta_time) {
update() {
$('#fps-actual').text("Actual FPS: " + Math.floor(this.engine.actual_fps));
$('#reset-count').text("Auto reset count: " + this.engine.env.reset_count);
this.stats_panel.updateDetails();
if (WorldConfig.headless)
this.updateHeadlessIcon(delta_time);

}

}
Expand Down