-
Notifications
You must be signed in to change notification settings - Fork 84
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
add ComboBlade and associated wrappers #668
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not bad, needs some cleaning up, but I don't see anything wrong with it. :)
8f2a33a
to
200a0b4
Compare
Thanks for the feedback, I made some updates based on your comments. |
blades/combo_blade.h
Outdated
return real_style_->NoOnOff(); | ||
} | ||
|
||
virtual bool Charging() { return real_style_->Charging();} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add space after ;
blades/combo_blade.h
Outdated
} | ||
|
||
int num_leds() const override { | ||
int result = blade1_num_leds_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this would be shorter and easier to read:
return blade1_num_leds + blade2->num_leds();
blades/combo_blade.h
Outdated
} | ||
|
||
BladeStyle* UnSetStyle() override { | ||
if (dummy_style_) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you call blade_ / blade2_->UnsetStyle() here then dummy_style will never have a null style (when used), and we can drop the if() statements in that class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moving these into a single object resolves this, thanks!
blades/combo_blade.h
Outdated
blade2_(blade2) | ||
{ | ||
blade_ = blade1; | ||
dummy_style_ = new ComboBladeStyleWrapper(this, blade1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ProffieOS code avoids using 'new' as much as possible to avoid memory fragmentation.
Just make "dummy_style" a ComboBladeStyleWrapper instead of a ComboBladeStyleWrapper*.
blades/combo_blade.h
Outdated
|
||
void setRealStyle(BladeStyle* style){real_style_ = style;} | ||
|
||
BladeStyle* GetRealStyle(){return real_style_;} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs 3 more more spaces, should be:
BladeStyle* GetRealStyle() { return real_style_; }
(same comment applies in other places as well.)
d1638f4
to
c30ae69
Compare
|
||
BladeStyle* UnSetStyle() override { | ||
BladeStyle* result = real_style_; | ||
real_style_ = nullptr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should also call blade_ / blade2_ -> UnSetStyle() here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure why, but it actually seems like I get a crash due to a null pointer somewhere when I tried this, willing to explore more if you think this idea is still worth pursuing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you have a config file that crashes (and instructions for how to make it crash if needed) I can run it with a debugger to see exactly where the crash occurs.
blades/combo_blade.h
Outdated
bool Charging() override { return real_style_->Charging(); } | ||
|
||
bool IsHandled(HandledFeature effect) override { | ||
if (real_style_) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
once UnsetStyle is called properly below, real_style_ will never be null here.
c30ae69
to
3e227c1
Compare
{ | ||
blade_ = blade1; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a destructor that deletes the blade2_cache_
|
||
BladeStyle* UnSetStyle() override { | ||
BladeStyle* result = real_style_; | ||
real_style_ = nullptr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you have a config file that crashes (and instructions for how to make it crash if needed) I can run it with a debugger to see exactly where the crash occurs.
Here is the combo blade code that I came up with. I admit that my current test case of combining the two crystal chamber LEDs is about as simple as it gets, but it seems to work pretty nicely for my use case.
The ComboBladeWrapper is used to send out calls to the the actual blades controlling real hardware. The style on the actual blades is set to a ComboBladeStyleWrapper, which forwards the calls for the on to the actual style code, but running against the original ComboBladeWrapper. This allows the ComboBladeWrapper to dispatch the led control calls on to the actual blade hardware while simulating a single blade with the length of both blades put together.
Also see discussion on crucible