Author: oracle
Date: Wed Jul 9 01:33:50 2008
New Revision: 27866
URL: http://svn.gna.org/viewcvs/wesnoth?rev=27866&view=rev
Log:
More clean up. The ai_manager is now completing its resource
lifecycle. If an AI returns true from its "reap" method,
the manager will destroy the instance. This allows the AI
to clean up before the manager destoys the AI instance.
Modified:
trunk/src/ai.cpp
Modified: trunk/src/ai.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/ai.cpp?rev=27866&r1=27865&r2=27866&view=diff
==============================================================================
--- trunk/src/ai.cpp (original)
+++ trunk/src/ai.cpp Wed Jul 9 01:33:50 2008
@@ -22,6 +22,7 @@
#include "ai2.hpp"
#include "ai_dfool.hpp"
#ifdef HAVE_PYTHON
+//#include "python_ai.hpp"
#include "ai_python.hpp"
#endif
#include "actions.hpp"
@@ -222,6 +223,8 @@
else if(name == "python_ai")
#ifdef HAVE_PYTHON
return new python_ai(info);
+// else if(name == "newpy_ai")
+// return new pythonai::PythonAI( info ) ;
#else
{
LOG_STREAM(err, ai) << "No Python AI support available in this
Wesnoth build!\n";
@@ -2351,14 +2354,21 @@
// Request each AI to clean up. The number of AIs which performed some type of
-// clean up is returned. For now, only the python_ai should return a non-zero
value.
+// clean up is returned.
int ai_manager::reap_ais()
{
int counter = 0 ;
for( AINameMap::iterator itor = ais.begin() ; itor != ais.end() ; ++itor )
{
+ // Request the AI clean up after it self. If it does not which to
+ // be purged, it must return false. If it returns true, the AI
+ // is deleted from the AI map.
if( itor->second->manager_reap_ai() )
- ++counter ;
+ {
+ // Delete the AI from the managed map
+ ais.erase( itor ) ;
+ ++counter ;
+ }
}
return counter ;
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits