Recently I spent some time in Orxonox, when I noticed something strange:
Only that, for some reason, one healthbar is blurred and the other is not.
Ok well, but what's up with that other thing over here:
Is that... a giant healthbar?
That must be one moth**fu**ing healthy portal!
But wait... aren't portals supposed to be things? Like... objects? Without health?
So let's check the code:
So uhm... apparently every WorldEntity is now a Pawn and can be safely converted with a C-style-cast?
Well, nope.
So I fixed it with an orxonox_cast (which is basically the same like a dynamic_cast):
And now portals look correctly (without a healthbar):
What do we learn from that? Never use C-style-casts!
(I already knew that!)
By the way, did you know that portals will also teleport your laser beams (and other projectiles)? It's pretty cool:
What's that weird blurry thing on the left? Apparently it's supposed to be a health bar, just like the one on the right.How not to use casts [an ironical comment]
Moderator: PPS-Leaders
How not to use casts [an ironical comment]
Fabian 'x3n' Landau, Orxonox developer
Re: How not to use casts [an ironical comment]
Nice bugfix! I think a guy played around with these enemy health bars a year ago during PPS. Obviously we should have kept one more eye on him.....
Re: How not to use casts [an ironical comment]
I'm currently looking more into modern C++ coding styles and I've got to say: Too many developers (not just random PPS students) write "C code with classes".
You might want to call old style C++ "C code with classes" but in the days of C++11 we should definitely start looking into more safe and clever ways of coding. A C-style cast is definitely no longer a safe and clever thing to do. Also simple things like C-style code is not necessarily faster than "complicated" C++ constructs, just because it's simple.
Instead there is often zero to almost no overhead when using new STL or even boost constructs to have more higher level code. Sometimes it's even faster than anything you could write yourself. Also the chance of writing something buggy is a lot smaller.
I would suggest we look into modern style C++ and start using it ourselves and thus be a good example for the students. Orxonox might very well be the first and only real coding experience for these students and it's our responsibility to give them the best learning experience as possible.
I've got some starting links you might want to look at:
https://www.youtube.com/watch?v=xnqTKD8uD64
https://isocpp.org/blog/category/articles-books
http://herbsutter.com/elements-of-modern-c-style/
http://herbsutter.com/2013/06/13/gotw-9 ... ways-auto/
http://channel9.msdn.com/Events/GoingNa ... pp11-Style
Anyway. Good find and nice fix, Fabian!
You might want to call old style C++ "C code with classes" but in the days of C++11 we should definitely start looking into more safe and clever ways of coding. A C-style cast is definitely no longer a safe and clever thing to do. Also simple things like C-style code is not necessarily faster than "complicated" C++ constructs, just because it's simple.
Instead there is often zero to almost no overhead when using new STL or even boost constructs to have more higher level code. Sometimes it's even faster than anything you could write yourself. Also the chance of writing something buggy is a lot smaller.
I would suggest we look into modern style C++ and start using it ourselves and thus be a good example for the students. Orxonox might very well be the first and only real coding experience for these students and it's our responsibility to give them the best learning experience as possible.
I've got some starting links you might want to look at:
https://www.youtube.com/watch?v=xnqTKD8uD64
https://isocpp.org/blog/category/articles-books
http://herbsutter.com/elements-of-modern-c-style/
http://herbsutter.com/2013/06/13/gotw-9 ... ways-auto/
http://channel9.msdn.com/Events/GoingNa ... pp11-Style
Anyway. Good find and nice fix, Fabian!
"I'm Commander Shepard and this is my favorite forum on the internet."
Who is online
Users browsing this forum: No registered users and 1 guest