PDA

View Full Version : Overriding PhysicsObject::on_collision_begin/end not working



vdell
03-23-2014, 04:20 PM
I've been learning Clanlib for a while now and with the help of the examples I've managed to get as far as getting physics working. Now i've bumped into a problem with overriding PhysicsObject::on_collision_begin/end. I have a base class for all game objects (showing only relevant parts):



class LevelObjectBase : public clan::PhysicsObject
{
public:
virtual void on_collision_begin(clan::Body &b);
virtual void on_collision_end(clan::Body &b);
virtual bool should_collide_with(clan::Body &b);
protected:
clan::Body m_body;
clan::Fixture m_fixture;

};


And other object derive from the above class like



class BlockObject : public DestroyableObject, public clan::PolygonShape
{
public:
BlockObject(clan::Canvas *canvas, clan::Sprite *sprite, unsigned int health,
clan::PhysicsContext &pc, const std::string &name = "block");
};

why::BlockObject::BlockObject(clan::Canvas *canvas, clan::Sprite *sprite, unsigned int health,
clan::PhysicsContext &pc, const std::string &name) :
DestroyableObject(canvas, sprite, health, name), clan::PolygonShape(pc)
{
using namespace clan;
set_as_box((float)get_width()/2, (float)get_height()/2);

BodyDescription bd(pc);
bd.set_type(BodyType::body_static);

m_body = Body(pc, bd);

FixtureDescription fd(pc);
fd.set_density(1.0f);
fd.set_shape(*this);
m_fixture = Fixture(pc, m_body, fd);
}

The game loop simply calls PhysicsWorld::step() after I'm done drawing. The objects are moving as they are supposed to and collisions also work as expected. However, the overridden functions are not being called when collision happens. I checked the Roadgeddon example and I didn't see anything that has been done differently (at least anything directly related to collisions).

Am I missing something?

P.S. Any chance that the documentation will updated with a bit more details? There isn't much explanations on what to do/when to do/what not do etc. The examples help but it's still extra work if everything needs to be searched from the examples.

TIA

rombust
03-24-2014, 08:36 AM
P.S. Any chance that the documentation will updated with a bit more details? There isn't much explanations on what to do/when to do/what not do etc. The examples help but it's still extra work if everything needs to be searched from the examples.

No, there is little chance.

Unfortunately the state is this:
To create documentation, you need to be proficient at programming with ClanLib
When proficient, you no longer require documentation.
It is boring to create documentation.

You are welcome to submit documentation patches via github.

With reference to your question. I think you are on your own with that one.

ClanLib is modular, developers only use and specialise in specific components of ClanLib.
For example, I only use clanCore, clanDisplay and clanGL.

I don't know anyone that currently uses clanPhysics2D.
Maybe I'll be proved wrong :)

vdell
03-24-2014, 11:02 AM
No, there is little chance.

Unfortunately the state is this:
To create documentation, you need to be proficient at programming with ClanLib
When proficient, you no longer require documentation.
It is boring to create documentation.

You are welcome to submit documentation patches via github.


I'm kind of baffled that someone would think so little about documentation and the importance of it. Sure, after one masters the usage of a library, there's less use for the docs but how can one master it without documentation? By looking at the source? With proper documentation the learning process would be a lot quicker and that would undoubtedly attract more users and developers to ClanLib (which I'm guessing is the idea when a library is released to the public but maybe I'm wrong). As an example, if you compare the documentation of ClanLib (http://www.clanlib.org/documentation/3.0/) to the documentation of the Boost libraries (http://www.boost.org/doc/libs/1_55_0/), which one seems more professional? I understand that Boost is maybe not the best example, because it has a lot more developers, but its docs are pretty good.



With reference to your question. I think you are on your own with that one.


I guess I have to cross my fingers and hope for the best ...

vdell
03-24-2014, 11:58 AM
Solution: Call m_body.set_data(this) from the derived class.



void clan::Body::set_data ( PhysicsObject * data )
Set the physics object object that is going to process collision events.

rombust
03-24-2014, 01:35 PM
I'm kind of baffled that someone would think so little about documentation and the importance of it.....


My comment is through experience of using ClanLib since around year 2000.

Nobody is denying that ClanLib documentation is extremely limited, and it really does need improving.

Before around year 2000, ClanLib documentation was a lot better. There were numerous tutorials explaining how to do things. A book even exists with a chapter dedicated to ClanLib. Back then, the code base was tiny.

Since then, 3 developers (including myself) have written a lot of documentation, and spent a lot of personal time doing it. As you can tell, we have only just scratched the surface.
We no longer have any free time to write documentation, with family and work taking priority. In our limited free time, we prefer to code as a hobby, not writing documentation.

ClanLib is unique in itself. There is no “management”. You have just as much say in it, as I do. We discuss things on IRC if breaking changes are beneficial.

We never tell anyone “you should do this”, else there is usually a rude response. Basically saying “If you don't like it, fix it, and post a patch on github”.

Why other libraries have better documentation? Well, it's the type of library. ClanLib isn't cool to develop. People love using it, just not developing for it.

Have a look at this thread http://www.rtsoft.com/forums/showthread.php?11861-commercial-orientation-of-ClanLib ... it covers about all of it!

rombust
03-24-2014, 01:39 PM
For interest, about 3 years ago, we had a wiki for editing docs. Nobody used it. ... Except spammers
So last year we moved the documentation to ClanLib\Documentation in the source code.

Seltzer
03-27-2014, 04:24 PM
For interest, about 3 years ago, we had a wiki for editing docs. Nobody used it. ... Except spammers
So last year we moved the documentation to ClanLib\Documentation in the source code.

That's a shame, although it does streamline big doc patches. It might be a good idea to add documentation guidelines to the code guidelines file to ensure future patches begin trending towards better code transparency. Something that strongly encourages a "document as you go" approach. It's really not as time consuming as everyone thinks, and it would make the engine much more approachable. :)

Either way, it's just a suggestion.

vdell
03-27-2014, 04:58 PM
No, there is little chance.

Unfortunately the state is this:
To create documentation, you need to be proficient at programming with ClanLib
When proficient, you no longer require documentation.
It is boring to create documentation.


Hmm, weird. I wrote a pretty long post about the topic and the system said it will be checked by moderators before being posted, but it's still not visible. Well, long story short: IMHO, when a library is released to the public it should be a top priority to take care of the documentation, as that will undoubtedly help in adopting the lib to a project and thus create a bigger and more active community. A developer calling documentation "boring" is kinda scary from a library users' point of view...

Seltzer
03-27-2014, 05:15 PM
Hmm, weird. I wrote a pretty long post about the topic and the system said it will be checked by moderators before being posted, but it's still not visible. Well, long story short: IMHO, when a library is released to the public it should be a top priority to take care of the documentation, as that will undoubtedly help in adopting the lib to a project and thus create a bigger and more active community. A developer calling documentation "boring" is kinda scary from a library users' point of view...

Don't sell them short. The code base is clean and seems to be well designed, and they do their best to keep patching it and answering questions. That's a lot more than some other engines offer. They've got a great little operation set up here, they just need to embrace common documentation practices rather than turning it into a chore, which isn't the easiest thing to do at the drop of a hat.

rombust
03-27-2014, 05:28 PM
Hmm, weird. I wrote a pretty long post about the topic and the system said it will be checked by moderators before being posted, but it's still not visible.

Strange. Also, it said my post was also moderated :) .Might be okay now ;)

- - - Updated - - -


A developer calling documentation "boring" is kinda scary from a library users' point of view...

Yes, and it's wrong I admit that.

In my opinion, with hindsight, many years ago, maybe ClanLib should have had a policy "submitting a patch with added features will not accepted without corresponding documentation".

Difficult to know. Pro's and Con's either way.

Seltzer
03-27-2014, 05:37 PM
Yes, and it's wrong I admit that.

In my opinion, with hindsight, many years ago, maybe ClanLib should have had a policy "submitting a patch with added features will not accepted without corresponding documentation".

Difficult to know. Pro's and Con's either way.

Nothing stopping you guys from adding a standard now. Especially if you want the development community to grow. Subsequent updates/patches, regardless of features added could require corresponding documentation that meets certain standards. Eventually, desire to release a new version will overpower laziness.

A little extra effort now will make development/growth easier for both developers and users. :)

vdell
03-28-2014, 07:59 AM
Don't sell them short. The code base is clean and seems to be well designed, and they do their best to keep patching it and answering questions. That's a lot more than some other engines offer. They've got a great little operation set up here, they just need to embrace common documentation practices rather than turning it into a chore, which isn't the easiest thing to do at the drop of a hat.

Yeah, no objections on that. The library has been easy to use, even for a game developer newbie like me, and the examples help a lot. However, in the case where examples are unable to help it's the documentation and the community that are the next place to look for answers. The way I view it is that the examples are only a supplement for the documentation. Anyway, I'm pretty sure I've made my point clear and hopefully it will have an impact on the future development.

:hat: