Page 1 of 1

Understanding POL source

Posted: Tue Oct 27, 2015 11:27 am
by bodom
Hey,

I am still trying to understand POL source code. I have found this:

Code: Select all

   bool NPC::send_event( Bscript::BObjectImp* event )
	{
	  if (ex != NULL)
	  {
		if (ex->os_module->signal_event( event ))
		  return true;
	  }
	  Bscript::BObject bo( event );
	  return false;
	}
Basically, if the NPC has an AI (ex != NULL) the event is sent to the script and true is returned. If not, false is returned but what "Bscript::BObject bo( event )" does?

Re: Understanding POL source

Posted: Fri Oct 30, 2015 11:41 pm
by Turley
Not really sure, since I didn't looked into calling code.
It looks like that the event parameter is an owing pointer, thus the function needs to transfer the ownership or destroy the pointer. Otherwise it would result in a memory leak.
The creation of the bobject is just for that purpose destroying the pointer, if you look at the deconstructor you should see a delete.

Re: Understanding POL source

Posted: Sat Oct 31, 2015 1:03 pm
by bodom
Thank you for your answer!

It sounds complicated to me, but I think I've understood it :D

Code: Select all

BObject::~BObject()
	{}
Anyway, BObject's deconstructor seems to be empty.

That's weird, because I am trying to debug a trace that leads me exactly there.