(svn r23357) -Codechange: move AIStorage to ScriptStorage

This commit is contained in:
truebrain 2011-11-29 23:21:04 +00:00
parent c2398c0fe1
commit 99cb93ef6f
12 changed files with 48 additions and 47 deletions

View File

@ -792,6 +792,7 @@
<ClInclude Include="..\src\script\script_info.hpp" /> <ClInclude Include="..\src\script\script_info.hpp" />
<ClCompile Include="..\src\script\script_scanner.cpp" /> <ClCompile Include="..\src\script\script_scanner.cpp" />
<ClInclude Include="..\src\script\script_scanner.hpp" /> <ClInclude Include="..\src\script\script_scanner.hpp" />
<ClInclude Include="..\src\script\script_storage.hpp" />
<ClCompile Include="..\src\script\squirrel.cpp" /> <ClCompile Include="..\src\script\squirrel.cpp" />
<ClInclude Include="..\src\script\squirrel.hpp" /> <ClInclude Include="..\src\script\squirrel.hpp" />
<ClInclude Include="..\src\script\squirrel_class.hpp" /> <ClInclude Include="..\src\script\squirrel_class.hpp" />
@ -851,7 +852,6 @@
<ClInclude Include="..\src\ai\ai_instance.hpp" /> <ClInclude Include="..\src\ai\ai_instance.hpp" />
<ClCompile Include="..\src\ai\ai_scanner.cpp" /> <ClCompile Include="..\src\ai\ai_scanner.cpp" />
<ClInclude Include="..\src\ai\ai_scanner.hpp" /> <ClInclude Include="..\src\ai\ai_scanner.hpp" />
<ClInclude Include="..\src\ai\ai_storage.hpp" />
<ClInclude Include="..\src\ai\api\ai_changelog.hpp" /> <ClInclude Include="..\src\ai\api\ai_changelog.hpp" />
<ClInclude Include="..\src\ai\api\ai_info_docs.hpp" /> <ClInclude Include="..\src\ai\api\ai_info_docs.hpp" />
<ClInclude Include="..\src\script\api\script_accounting.hpp" /> <ClInclude Include="..\src\script\api\script_accounting.hpp" />

View File

@ -1599,6 +1599,9 @@
<ClInclude Include="..\src\script\script_scanner.hpp"> <ClInclude Include="..\src\script\script_scanner.hpp">
<Filter>Script</Filter> <Filter>Script</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\src\script\script_storage.hpp">
<Filter>Script</Filter>
</ClInclude>
<ClCompile Include="..\src\script\squirrel.cpp"> <ClCompile Include="..\src\script\squirrel.cpp">
<Filter>Script</Filter> <Filter>Script</Filter>
</ClCompile> </ClCompile>
@ -1776,9 +1779,6 @@
<ClInclude Include="..\src\ai\ai_scanner.hpp"> <ClInclude Include="..\src\ai\ai_scanner.hpp">
<Filter>AI Core</Filter> <Filter>AI Core</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\src\ai\ai_storage.hpp">
<Filter>AI Core</Filter>
</ClInclude>
<ClInclude Include="..\src\ai\api\ai_changelog.hpp"> <ClInclude Include="..\src\ai\api\ai_changelog.hpp">
<Filter>AI API</Filter> <Filter>AI API</Filter>
</ClInclude> </ClInclude>

View File

@ -2474,6 +2474,10 @@
RelativePath=".\..\src\script\script_scanner.hpp" RelativePath=".\..\src\script\script_scanner.hpp"
> >
</File> </File>
<File
RelativePath=".\..\src\script\script_storage.hpp"
>
</File>
<File <File
RelativePath=".\..\src\script\squirrel.cpp" RelativePath=".\..\src\script\squirrel.cpp"
> >
@ -2722,10 +2726,6 @@
RelativePath=".\..\src\ai\ai_scanner.hpp" RelativePath=".\..\src\ai\ai_scanner.hpp"
> >
</File> </File>
<File
RelativePath=".\..\src\ai\ai_storage.hpp"
>
</File>
</Filter> </Filter>
<Filter <Filter
Name="AI API" Name="AI API"

View File

@ -2471,6 +2471,10 @@
RelativePath=".\..\src\script\script_scanner.hpp" RelativePath=".\..\src\script\script_scanner.hpp"
> >
</File> </File>
<File
RelativePath=".\..\src\script\script_storage.hpp"
>
</File>
<File <File
RelativePath=".\..\src\script\squirrel.cpp" RelativePath=".\..\src\script\squirrel.cpp"
> >
@ -2719,10 +2723,6 @@
RelativePath=".\..\src\ai\ai_scanner.hpp" RelativePath=".\..\src\ai\ai_scanner.hpp"
> >
</File> </File>
<File
RelativePath=".\..\src\ai\ai_storage.hpp"
>
</File>
</Filter> </Filter>
<Filter <Filter
Name="AI API" Name="AI API"

View File

@ -557,6 +557,7 @@ script/script_info.cpp
script/script_info.hpp script/script_info.hpp
script/script_scanner.cpp script/script_scanner.cpp
script/script_scanner.hpp script/script_scanner.hpp
script/script_storage.hpp
script/squirrel.cpp script/squirrel.cpp
script/squirrel.hpp script/squirrel.hpp
script/squirrel_class.hpp script/squirrel_class.hpp
@ -622,7 +623,6 @@ ai/ai_instance.cpp
ai/ai_instance.hpp ai/ai_instance.hpp
ai/ai_scanner.cpp ai/ai_scanner.cpp
ai/ai_scanner.hpp ai/ai_scanner.hpp
ai/ai_storage.hpp
# AI API # AI API
ai/api/ai_changelog.hpp ai/api/ai_changelog.hpp

View File

@ -17,10 +17,11 @@
#include "../script/squirrel_class.hpp" #include "../script/squirrel_class.hpp"
#include "ai_config.hpp" #include "ai_config.hpp"
#include "ai_storage.hpp"
#include "ai_instance.hpp"
#include "ai_gui.hpp" #include "ai_gui.hpp"
#include "../script/script_storage.hpp"
#include "ai_instance.hpp"
/* Convert all AI related classes to Squirrel data. /* Convert all AI related classes to Squirrel data.
* Note: this line is a marker in squirrel_export.sh. Do not change! */ * Note: this line is a marker in squirrel_export.sh. Do not change! */
#include "api/ai_accounting.hpp.sq" #include "api/ai_accounting.hpp.sq"
@ -82,7 +83,7 @@ static const int MAX_SL_OPS = 100000;
/** The maximum number of operations for initial start of an AI. */ /** The maximum number of operations for initial start of an AI. */
static const int MAX_CONSTRUCTOR_OPS = 100000; static const int MAX_CONSTRUCTOR_OPS = 100000;
AIStorage::~AIStorage() ScriptStorage::~ScriptStorage()
{ {
/* Free our pointers */ /* Free our pointers */
if (event_data != NULL) ScriptEventController::FreeEventPointer(); if (event_data != NULL) ScriptEventController::FreeEventPointer();
@ -111,7 +112,7 @@ AIInstance::AIInstance() :
suspend(0), suspend(0),
callback(NULL) callback(NULL)
{ {
this->storage = new AIStorage(); this->storage = new ScriptStorage();
this->engine = new Squirrel("AI"); this->engine = new Squirrel("AI");
this->engine->SetPrintFunction(&PrintFunc); this->engine->SetPrintFunction(&PrintFunc);
} }
@ -428,7 +429,7 @@ void AIInstance::CollectGarbage() const
instance->engine->InsertResult(ScriptObject::GetNewGroupID()); instance->engine->InsertResult(ScriptObject::GetNewGroupID());
} }
AIStorage *AIInstance::GetStorage() ScriptStorage *AIInstance::GetStorage()
{ {
return this->storage; return this->storage;
} }

View File

@ -111,7 +111,7 @@ public:
/** /**
* Get the storage of this AI. * Get the storage of this AI.
*/ */
class AIStorage *GetStorage(); class ScriptStorage *GetStorage();
/** /**
* Get the log pointer of this AI. * Get the log pointer of this AI.
@ -202,15 +202,15 @@ public:
private: private:
class ScriptController *controller; ///< The AI main class. class ScriptController *controller; ///< The AI main class.
class AIStorage *storage; ///< Some global information for each running AI. class ScriptStorage *storage; ///< Some global information for each running AI.
class Squirrel *engine; ///< A wrapper around the squirrel vm. class Squirrel *engine; ///< A wrapper around the squirrel vm.
SQObject *instance; ///< Squirrel-pointer to the AI main class. SQObject *instance; ///< Squirrel-pointer to the AI main class.
bool is_started; ///< Is the AIs constructor executed? bool is_started; ///< Is the AIs constructor executed?
bool is_dead; ///< True if the AI has been stopped. bool is_dead; ///< True if the AI has been stopped.
bool is_save_data_on_stack; ///< Is the save data still on the squirrel stack? bool is_save_data_on_stack; ///< Is the save data still on the squirrel stack?
int suspend; ///< The amount of ticks to suspend this AI before it's allowed to continue. int suspend; ///< The amount of ticks to suspend this AI before it's allowed to continue.
AISuspendCallbackProc *callback; ///< Callback that should be called in the next tick the AI runs. AISuspendCallbackProc *callback; ///< Callback that should be called in the next tick the AI runs.
/** /**
* Register all API functions to the VM. * Register all API functions to the VM.

View File

@ -23,7 +23,7 @@
*/ */
class ScriptExecMode : public ScriptObject { class ScriptExecMode : public ScriptObject {
private: private:
AIModeProc *last_mode; ///< The previous mode we were in. ScriptModeProc *last_mode; ///< The previous mode we were in.
ScriptObject *last_instance; ///< The previous instace of the mode. ScriptObject *last_instance; ///< The previous instace of the mode.
protected: protected:

View File

@ -15,7 +15,7 @@
#include "../../network/network.h" #include "../../network/network.h"
#include "../../tunnelbridge.h" #include "../../tunnelbridge.h"
#include "../../ai/ai_storage.hpp" #include "../script_storage.hpp"
#include "../../ai/ai_instance.hpp" #include "../../ai/ai_instance.hpp"
#include "script_error.hpp" #include "script_error.hpp"
@ -23,7 +23,7 @@
* Get the storage associated with the current AIInstance. * Get the storage associated with the current AIInstance.
* @return The storage. * @return The storage.
*/ */
static AIStorage *GetStorage() static ScriptStorage *GetStorage()
{ {
return ScriptObject::GetActiveInstance()->GetStorage(); return ScriptObject::GetActiveInstance()->GetStorage();
} }
@ -60,13 +60,13 @@ ScriptObject::ActiveInstance::~ActiveInstance()
return GetStorage()->delay; return GetStorage()->delay;
} }
/* static */ void ScriptObject::SetDoCommandMode(AIModeProc *proc, ScriptObject *instance) /* static */ void ScriptObject::SetDoCommandMode(ScriptModeProc *proc, ScriptObject *instance)
{ {
GetStorage()->mode = proc; GetStorage()->mode = proc;
GetStorage()->mode_instance = instance; GetStorage()->mode_instance = instance;
} }
/* static */ AIModeProc *ScriptObject::GetDoCommandMode() /* static */ ScriptModeProc *ScriptObject::GetDoCommandMode()
{ {
return GetStorage()->mode; return GetStorage()->mode;
} }

View File

@ -26,7 +26,7 @@ typedef void (AISuspendCallbackProc)(class AIInstance *instance);
/** /**
* The callback function for Mode-classes. * The callback function for Mode-classes.
*/ */
typedef bool (AIModeProc)(); typedef bool (ScriptModeProc)();
/** /**
* Uper-parent object of all API classes. You should never use this class in * Uper-parent object of all API classes. You should never use this class in
@ -122,12 +122,12 @@ protected:
/** /**
* Set the current mode of your AI to this proc. * Set the current mode of your AI to this proc.
*/ */
static void SetDoCommandMode(AIModeProc *proc, ScriptObject *instance); static void SetDoCommandMode(ScriptModeProc *proc, ScriptObject *instance);
/** /**
* Get the current mode your AI is currently under. * Get the current mode your AI is currently under.
*/ */
static AIModeProc *GetDoCommandMode(); static ScriptModeProc *GetDoCommandMode();
/** /**
* Get the instance of the current mode your AI is currently under. * Get the instance of the current mode your AI is currently under.

View File

@ -25,7 +25,7 @@
*/ */
class ScriptTestMode : public ScriptObject { class ScriptTestMode : public ScriptObject {
private: private:
AIModeProc *last_mode; ///< The previous mode we were in. ScriptModeProc *last_mode; ///< The previous mode we were in.
ScriptObject *last_instance; ///< The previous instace of the mode. ScriptObject *last_instance; ///< The previous instace of the mode.
protected: protected:

View File

@ -7,10 +7,10 @@
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>. * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
*/ */
/** @file ai_storage.hpp Defines AIStorage and includes all files required for it. */ /** @file script_storage.hpp Defines ScriptStorage and includes all files required for it. */
#ifndef AI_STORAGE_HPP #ifndef SCRIPT_STORAGE_HPP
#define AI_STORAGE_HPP #define SCRIPT_STORAGE_HPP
#include "../signs_func.h" #include "../signs_func.h"
#include "../vehicle_func.h" #include "../vehicle_func.h"
@ -23,21 +23,21 @@
/** /**
* The callback function for Mode-classes. * The callback function for Mode-classes.
*/ */
typedef bool (AIModeProc)(); typedef bool (ScriptModeProc)();
/** /**
* The storage for each AI. It keeps track of important information. * The storage for each script. It keeps track of important information.
*/ */
class AIStorage { class ScriptStorage {
friend class ScriptObject; friend class ScriptObject;
private: private:
AIModeProc *mode; ///< The current build mode we are int. ScriptModeProc *mode; ///< The current build mode we are int.
class ScriptObject *mode_instance; ///< The instance belonging to the current build mode. class ScriptObject *mode_instance; ///< The instance belonging to the current build mode.
uint delay; ///< The ticks of delay each DoCommand has. uint delay; ///< The ticks of delay each DoCommand has.
bool allow_do_command; ///< Is the usage of DoCommands restricted? bool allow_do_command; ///< Is the usage of DoCommands restricted?
CommandCost costs; ///< The costs the AI is tracking. CommandCost costs; ///< The costs the script is tracking.
Money last_cost; ///< The last cost of the command. Money last_cost; ///< The last cost of the command.
uint last_error; ///< The last error of the command. uint last_error; ///< The last error of the command.
bool last_command_res; ///< The last result of the command. bool last_command_res; ///< The last result of the command.
@ -56,7 +56,7 @@ private:
void *log_data; ///< Pointer to the log data storage. void *log_data; ///< Pointer to the log data storage.
public: public:
AIStorage() : ScriptStorage() :
mode (NULL), mode (NULL),
mode_instance (NULL), mode_instance (NULL),
delay (1), delay (1),
@ -76,7 +76,7 @@ public:
log_data (NULL) log_data (NULL)
{ } { }
~AIStorage(); ~ScriptStorage();
}; };
#endif /* AI_STORAGE_HPP */ #endif /* SCRIPT_STORAGE_HPP */