Quick little tweak to make the build speed up while a build is running.

master
Zed A. Shaw 1 day ago
parent 94c9cd75a8
commit d1c2352237
  1. 4
      assets/shaders/build_status.frag
  2. 106
      coro.hpp
  3. 14
      gui.cpp
  4. 2
      gui.hpp

@ -5,7 +5,7 @@ uniform sampler2D source;
uniform float u_mouse;
uniform float value = 0.2;
uniform bool is_error = false;
uniform int line_length = 100;
uniform int speedup = 1;
float random (in vec2 st) {
return fract(sin(dot(st.xy,
@ -49,7 +49,7 @@ void main() {
vec2 st = gl_FragCoord.xy/u_resolution.xy * 3.0;
vec3 color = vec3(0.0);
float speed = u_time;
float speed = u_time * speedup;
float value = 0.8;
vec3 base_tone = is_error ? vec3(1.0, 0.5, 0.5) : vec3(0.5, 1.0, 0.5);

@ -1,106 +0,0 @@
#pragma once
#include <concepts>
#include <coroutine>
#include <exception>
#include <assert.h>
enum TaskStates {
STARTED, AWAIT, YIELD,
EXCEPTION, RETURN,
RETURN_VOID, DEAD
};
template<typename T>
struct Task {
struct promise_type;
using handle_type = std::coroutine_handle<promise_type>;
struct promise_type {
T value_;
std::exception_ptr exception_;
TaskStates state_{STARTED};
Task get_return_object() {
return Task(handle_type::from_promise(*this));
}
std::suspend_always initial_suspend() {
state_ = AWAIT;
return {};
}
std::suspend_always final_suspend() noexcept {
return {};
}
void unhandled_exception() {
state_ = EXCEPTION;
exception_ = std::current_exception();
}
template<std::convertible_to<T> From> // C++20 concept
void return_value(From &&from) {
state_ = RETURN;
value_ = std::forward<From>(from);
}
template<std::convertible_to<T> From> // C++20 concept
std::suspend_always yield_value(From &&from) {
state_ = YIELD;
value_ = std::forward<From>(from);
return {};
}
void return_void() {
state_ = RETURN_VOID;
}
};
handle_type h_;
Task() {
}
Task(handle_type h) : h_(h) {
}
Task(const Task &t) : h_(t.h_) {
}
void destroy() {
// this should make it safe to clal repeatedly
if(h_.promise().state_ != DEAD) {
h_.destroy();
h_.promise().state_ = DEAD;
}
}
T operator()() {
assert(!h_.done());
call();
return std::move(h_.promise().value_);
}
bool done() {
return h_.done();
}
TaskStates state() {
return h_.promise().state_;
}
private:
void call() {
h_();
if (h_.promise().exception_) {
std::rethrow_exception(h_.promise().exception_);
}
}
};
struct Pass : std::suspend_always {
};

@ -78,6 +78,7 @@ void GUI::main_loop() {
void GUI::build_success() {
$hit_error = false;
configure_status_shader(1, $hit_error);
$gui.show_sprite("face", "build_success");
sound::stop("building");
sound::play("build_success");
@ -86,6 +87,7 @@ void GUI::build_success() {
void GUI::build_failed(bool play_sound, const string &command) {
$hit_error = true;
configure_status_shader(1, $hit_error);
$gui.show_sprite("face", "build_failed");
sound::stop("building");
@ -96,9 +98,13 @@ void GUI::build_failed(bool play_sound, const string &command) {
output(fmt::format("!!! BUILD FAILED. Your command correct? '{}'", command));
}
void GUI::configure_status_shader(size_t line_length, bool is_error) {
void GUI::configure_status_shader(int speedup, bool is_error) {
auto& effect = $gui.get<guecs::Effect>($log);
effect.$shader->setUniform("line_length", (int)line_length);
if(speedup > 0) {
effect.$shader->setUniform("speedup", speedup);
}
if(!$hit_error && is_error) {
$hit_error = is_error;
}
@ -108,7 +114,7 @@ void GUI::configure_status_shader(size_t line_length, bool is_error) {
}
void GUI::update_status(GameEngine &game, size_t line_length, bool is_error) {
configure_status_shader(line_length, is_error);
configure_status_shader(line_length * 0, is_error);
$status = fmt::format(L"HP {}\nRounds {}\nStreaks {}\nDeaths {}",
game.hit_points, game.rounds,
@ -119,6 +125,7 @@ void GUI::update_status(GameEngine &game, size_t line_length, bool is_error) {
}
void GUI::you_died() {
configure_status_shader(0, $hit_error);
$gui.show_sprite("face", "you_died");
sound::stop("building");
sound::play("you_died");
@ -128,6 +135,7 @@ void GUI::you_died() {
void GUI::building() {
$hit_error = false;
configure_status_shader(20, $hit_error);
$gui.show_sprite("face", "building");
output("############# START ############");
output(">>>> Will it Build?");

@ -24,7 +24,7 @@ class GUI {
void output(const string msg);
void update_status(GameEngine &game, size_t line_length, bool is_error);
void configure_status_shader(size_t line_length, bool is_error);
void configure_status_shader(int speedup, bool is_error);
void startup();
bool is_open() { return $window.isOpen(); }

Loading…
Cancel
Save