Commit 03e434d4 authored by Ralph Alexander Bariz's avatar Ralph Alexander Bariz 💬
Browse files

Merge branch 'ralph/0000000' into 'master'

0000000 fixes

See merge request !24
parents 67664430 f309d343
Pipeline #2028 waiting for manual action with stage
......@@ -239,7 +239,7 @@ protected:
long off_x = 0, off_y = 0;
u_char* pixel_buffer = nullptr;
void set_size(u_int x, u_int y) {
void set_size(const u_int x, const u_int y) {
std::unique_lock lk(this->mtx);
if(this->pixel_buffer) {
delete[] this->pixel_buffer;
......@@ -257,7 +257,7 @@ protected:
}
}
void set_off(long x, long y) {
void set_off(const long x, const long y) {
std::unique_lock lk(this->mtx);
this->off_x = x;
this->off_y = y;
......@@ -288,7 +288,6 @@ public:
y = v.first.y-this->off_y;
if(x >= 0 && y >= 0 && x < this->size_x && y < this->size_y) {
//auto* px = &this->pixel_buffer[(this->size_x*4*y)+(x*4)];
auto* px = this->pixel_buffer + y*this->size_x*4 + x*4;
px[0] = v.second ? 255 : 0;
px[1] = v.second ? 255 : 0;
......@@ -312,19 +311,16 @@ void GolController::tick_update(GolController& ctrl, GolView* view) {
auto r = ctrl.space->take<GolCell<>>(a.id, ctrl.space, a.id, ctrl.view->observation);
switch(a.t) {
case gol_action_type::toggle:
if(!ctrl.running) {
if(!ctrl.running)
ctrl.branch_sys->act(GolCell<>::tick_toggle, r, &ctrl.iter);
}
break;
case gol_action_type::set:
if(!ctrl.running) {
if(!ctrl.running)
ctrl.branch_sys->act(GolCell<>::tick_set, r, &ctrl.iter, true);
}
break;
case gol_action_type::unset:
if(!ctrl.running) {
if(!ctrl.running)
ctrl.branch_sys->act(GolCell<>::tick_set, r, &ctrl.iter, false);
}
break;
}
}
......
......@@ -244,7 +244,7 @@ void MainWin::tick_init(MainWin* mw) {
void MainWin::tick_update(MainWin* mw) {
if(!mw->closed) {
cc::act_fwd(GolController::tick_update, mw->view.controller, dynamic_cast<GolView*>(&mw->view));
cc::act(GolController::tick_update, mw->view.controller, dynamic_cast<GolView*>(&mw->view));
cc::act_synced(cy::delay_ms(UI_UPDATE_DELAY), tick_update, mw);
}
}
......
......@@ -204,7 +204,7 @@ void GolHost::tick_init(std::shared_ptr<GolHost> h) {
void GolHost::tick_update(std::shared_ptr<GolHost> h) {
if(!h->closed) {
cc::act_fwd(GolController::tick_update, h->view->controller, dynamic_cast<GolView*>(h->view));
cc::act(GolController::tick_update, h->view->controller, dynamic_cast<GolView*>(h->view));
cc::act_synced(cy::delay_ms(UI_UPDATE_DELAY), tick_update, h);
}
}
......
......@@ -9,13 +9,11 @@ ApplicationWindow
visible: true
width: 640
height: 480
title: qsTr("Game of Life")
title: qsTr("Brane")
readonly property bool inPortrait: window.width < window.height
property double fps;
property double ops;
signal speedChanged(real speed)
signal playButtonClicked(bool checked)
signal templateDropped(string name, real mouse_x, real mouxe_y)
header: ToolBar {
RowLayout {
......@@ -29,117 +27,13 @@ ApplicationWindow
}
}
Label {
//text: "Game of Life"
//text: "Brane"
elide: Label.ElideRight
horizontalAlignment: Qt.AlignHCenter
verticalAlignment: Qt.AlignVCenter
Layout.fillWidth: true
}
Text { text: window.fps }
ToolButton {
checkable: true
icon.name: "media-seek-forward"
onClicked: checked ? speedMenu.open() : speedMenu.close()
Menu {
id: speedMenu
y: parent.height
Slider {
id: speedSlider
from: 0
value: 0
to: 500
stepSize: 10
onMoved: {
window.speedChanged(speedSlider.value)
}
}
}
}
}
}
Drawer {
id: drawer
objectName: "drawer"
y: header.height
width: 200
height: parent.height - header.height
modal: inPortrait
interactive: inPortrait
position: inPortrait ? 0 : 1
visible: !inPortrait
ListView {
id: templates
objectName: "templates"
anchors.fill: parent
model: {}
property string dragName: ""
delegate: Item {
id: item
width: templates.width
height: 25
required property string modelData
Rectangle {
id: rect
width: templates.width
height: 25
z: mouseArea.drag.active || mouseArea.pressed ? 2 : 1
property point beginDrag
Drag.active: mouseArea.drag.active
Text {
id: text
anchors.centerIn: parent
text: parent.parent.modelData
}
MouseArea {
id: mouseArea
anchors.fill: parent
drag.target: parent
onPressed: {
parent.beginDrag = Qt.point(parent.x, parent.y);
templates.dragName = text.text;
}
onReleased: {
parent.Drag.drop();
backAnimX.from = parent.x;
backAnimX.to = parent.beginDrag.x;
backAnimY.from = parent.y;
backAnimY.to = parent.beginDrag.y;
backAnim.start()
}
ParallelAnimation {
id: backAnim
SpringAnimation { id: backAnimX; target: rect; property: "x"; duration: 500; spring: 2; damping: 0.2 }
SpringAnimation { id: backAnimY; target: rect; property: "y"; duration: 500; spring: 2; damping: 0.2 }
}
}
states: [
State {
when: rect.Drag.active
PropertyChanges {
target: rect
opacity: 0.3
}
}
]
}
}
Text { text: window.ops }
}
}
......
......@@ -75,8 +75,10 @@ namespace causal {
}
if(!r) {
r = cc::aspect<T>::make_certain(id, this->shared_from_this(), std::forward<Args>(args)...);
r = cc::aspect<T>::make(id, this->shared_from_this(), std::forward<Args>(args)...);
this->aspects[id] = r.get_ptr()->as_untyped();
cc::opener o(r);
r.create();
}
return r;
......
......@@ -43,11 +43,12 @@ namespace causal {
r = m.ptr->template as_typed<T>();
m.ptr->leave(this);
} else {
if constexpr(certain)
r = cc::aspect<T>::make_certain(id, this->shared_from_this(), std::forward<Args>(args)...);
else
r = cc::aspect<T>::make(id, this->shared_from_this(), std::forward<Args>(args)...);
r = cc::aspect<T>::make(id, this->shared_from_this(), std::forward<Args>(args)...);
this->aspects[id].ptr = r.get_ptr()->as_untyped();
if constexpr(certain) {
cc::opener o(r);
r.create();
}
}
return r;
}
......
......@@ -146,30 +146,21 @@ namespace causal {
return this;
}
template<typename Fn>
void apply(Fn f) const {
template<typename Fn, typename... Args>
void apply(Fn f, Args&&... args) const {
if(this->borrow_key && !this->const_borrowed) {
cc::static_for_each(*this, [&]<size_t I, typename A>(A a) {
using FT = typename std::remove_pointer_t<A>::data_type;
f.template operator()<I, FT>(a ? a->get_or_create(this->borrow_key) : nullptr);
if(a) {
FT* ptr = a->get_or_create(this->borrow_key);
f.template operator()<I, FT>(ptr, std::forward<Args>(args)...);
}
return true;
});
} else
throw attempt_to_retreive_unborrowed_facet_element();
}
template<typename Fn, typename... Args>
void apply_aspects(Fn f, Args&&... args) const {
if(!this->focus_key && !this->borrow_key)
cc::static_for_each(*this, [&]<size_t I, typename A>(A a) {
using AT = typename std::remove_pointer_t<A>;
f.template operator()<I, AT>(a, std::forward<Args>(args)...);
return true;
});
else
throw attempt_to_edit_active_facet();
}
template<typename Fn, typename... Args>
void apply_certain(Fn f, Args&&... args) const {
if(this->borrow_key && !this->const_borrowed) {
......@@ -186,6 +177,18 @@ namespace causal {
throw attempt_to_retreive_unborrowed_facet_element();
}
template<typename Fn, typename... Args>
void apply_aspects(Fn f, Args&&... args) const {
if(!this->focus_key && !this->borrow_key)
cc::static_for_each(*this, [&]<size_t I, typename A>(A a) {
using AT = typename std::remove_pointer_t<A>;
f.template operator()<I, AT>(a, std::forward<Args>(args)...);
return true;
});
else
throw attempt_to_edit_active_facet();
}
size_t size() const noexcept {
return std::tuple_size<container_type>::value;
}
......
......@@ -24,17 +24,25 @@ namespace causal {
MSGPACK_DEFINE(loose, oscillators)
virtual void apply(const facet_type& os) {
int64_t ref_point = 0;
os.template apply_certain([]<size_t I, typename AT>(AT* o, int64_t& rp) {
rp += o->elongation;
}, ref_point);
ref_point = ref_point / os.size();
os.template apply_certain([]<size_t I, typename AT>(AT* o, Bond* t, const int64_t& rp) {
int64_t d = rp - o->elongation;
o->velocity += d / (t->loose*o->inertia);
}, this, ref_point);
virtual bool apply(const facet_type& os) {
int64_t ref_elongation = 0, ref_velocity = 0;
os.template apply([]<size_t I, typename AT>(AT* o, int64_t& re, int64_t& rv) {
re += o->elongation;
rv += o->velocity;
}, ref_elongation, ref_velocity);
ref_elongation /= os.size();
ref_velocity /= os.size();
bool applied = false;
os.template apply([]<size_t I, typename AT>(AT* o, Bond<O...>* t, const int64_t& re, const int64_t& rv, bool& applied) {
if(!o->fixed && re != o->elongation) {
int64_t f = re - o->elongation;
o->velocity += f / (t->loose*o->inertia);
applied = true;
}
}, this, ref_elongation, ref_velocity, applied);
return applied;
}
};
......@@ -52,10 +60,12 @@ namespace causal {
// actual elongation
int64_t elongation = 0;
MSGPACK_DEFINE(inertia, velocity, elongation, bonds)
bool fixed = false;
MSGPACK_DEFINE(inertia, velocity, elongation, fixed, bonds)
virtual void push(int64_t e) {
this->velocity = e;
this->velocity += e;
}
virtual void apply() {
......
......@@ -53,12 +53,11 @@ struct Spring final : cs::Bond<Pendulum, Pendulum> {
struct Pendulum final : cs::Oscillator<Spring> {
std::string name;
static void tick_push(Pendulum& p, int64_t& e);
static void tick_apply(Pendulum& p);
};
void Spring::tick_pre_apply(Spring& s) {
cc::act_fwd_synced(cy::united(s.unifier), s.oscillators.expand(tick_apply, s));
cc::act_synced(cy::united(s.unifier), s.oscillators.expand(tick_apply, s));
}
void Spring::tick_apply(cf::edges<Pendulum, Pendulum>& ps, Spring& s) {
......@@ -97,16 +96,11 @@ void Spring::tick_apply(cf::edges<Pendulum, Pendulum>& ps, Spring& s) {
if(s.hit_cnt < WAIT_FOR_HITS) {
s.apply_cnt++;
s.prev = ps.get<0>().velocity;
cc::act_fwd(Pendulum::tick_apply, ps.get<0>());
cc::act_fwd(Pendulum::tick_apply, ps.get<1>());
cc::act(Pendulum::tick_apply, ps.get<0>());
cc::act(Pendulum::tick_apply, ps.get<1>());
}
}
void Pendulum::tick_push(Pendulum& p, int64_t& e) {
p.push(e);
cc::act_fwd(tick_apply, p);
}
void Pendulum::tick_apply(Pendulum& p) {
p.apply();
cc::act(p.bonds.explode(Spring::tick_pre_apply));
......@@ -155,7 +149,7 @@ TEST(causal_system_oscillator, osciallation) {
(*rs_1).oscillators = cf::edges(rp1_1.get(), rp1_2.get());
}
b->act_fwd(Spring::tick_pre_apply, rs_1);
b->act(Spring::tick_pre_apply, rs_1);
bool done = false;
for(tick_cnt_1 = 0; tick_cnt_1 < MAX_TICKS; tick_cnt_1++) {
......@@ -180,7 +174,7 @@ TEST(causal_system_oscillator, osciallation) {
(*rs_2).oscillators = cf::edges(rp2_1, rp2_2);
}
b->act_fwd(Spring::tick_pre_apply, rs_2);
b->act(Spring::tick_pre_apply, rs_2);
bool done = false;
for(tick_cnt_2 = 0; tick_cnt_2 < MAX_TICKS; tick_cnt_2++) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment