2015-11-14 11:56:16 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the Colobot: Gold Edition source code
|
2020-07-07 08:19:36 +00:00
|
|
|
* Copyright (C) 2001-2020, Daniel Roux, EPSITEC SA & TerranovaTeam
|
2015-11-14 11:56:16 +00:00
|
|
|
* http://epsitec.ch; http://colobot.info; http://github.com/colobot
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see http://gnu.org/licenses
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2015-11-23 20:59:56 +00:00
|
|
|
#include "CBot/CBotDefines.h"
|
|
|
|
#include "CBot/CBotTypResult.h"
|
2015-12-26 13:19:24 +00:00
|
|
|
#include "CBot/CBotEnums.h"
|
|
|
|
#include "CBot/CBotVar/CBotVar.h"
|
2015-11-22 16:38:16 +00:00
|
|
|
|
2015-11-22 16:54:40 +00:00
|
|
|
#include <cstdio>
|
2015-12-20 15:19:10 +00:00
|
|
|
#include <string>
|
2015-12-26 13:19:24 +00:00
|
|
|
|
|
|
|
namespace CBot
|
|
|
|
{
|
2015-11-14 11:56:16 +00:00
|
|
|
|
2015-11-22 15:42:51 +00:00
|
|
|
class CBotInstr;
|
2015-12-24 10:57:34 +00:00
|
|
|
class CBotExternalCall;
|
2015-11-22 16:54:40 +00:00
|
|
|
class CBotVar;
|
|
|
|
class CBotProgram;
|
|
|
|
class CBotToken;
|
2015-11-14 11:56:16 +00:00
|
|
|
|
2015-12-24 13:39:38 +00:00
|
|
|
/**
|
|
|
|
* \brief The execution stack
|
2015-12-25 19:47:30 +00:00
|
|
|
*
|
|
|
|
* \nosubgrouping
|
2015-11-14 11:56:16 +00:00
|
|
|
*/
|
|
|
|
class CBotStack
|
|
|
|
{
|
|
|
|
public:
|
2015-12-25 21:03:23 +00:00
|
|
|
/**
|
|
|
|
* \brief Block type this stack represents. This determines local variable visibility (you can only see up to top FUNCTION stack)
|
|
|
|
*/
|
|
|
|
enum class BlockVisibilityType : unsigned short
|
|
|
|
{
|
|
|
|
INSTRUCTION = 0, //!< Instruction (default)
|
|
|
|
BLOCK = 1, //!< Code block between { ... }
|
|
|
|
FUNCTION = 2 //!< Function - variable visibility limit
|
|
|
|
};
|
|
|
|
|
2015-12-31 15:10:47 +00:00
|
|
|
enum class IsFunction : unsigned short { NO = 0, YES = 1, EXTERNAL_CALL = 2 };
|
2015-12-25 19:47:30 +00:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//! \name Stack memory management
|
|
|
|
//@{
|
2015-12-19 20:20:41 +00:00
|
|
|
|
2015-11-14 11:56:16 +00:00
|
|
|
/**
|
2015-12-25 18:48:31 +00:00
|
|
|
* \brief Allocate the stack
|
2015-11-14 11:56:16 +00:00
|
|
|
* \return pointer to created stack
|
|
|
|
*/
|
2015-12-24 13:39:38 +00:00
|
|
|
static CBotStack* AllocateStack();
|
2015-11-14 11:56:16 +00:00
|
|
|
|
2015-12-25 18:48:31 +00:00
|
|
|
/** \brief Remove the current stack */
|
2015-11-14 11:56:16 +00:00
|
|
|
void Delete();
|
|
|
|
|
2015-12-24 13:39:38 +00:00
|
|
|
CBotStack() = delete;
|
|
|
|
~CBotStack() = delete;
|
2015-11-14 11:56:16 +00:00
|
|
|
|
|
|
|
/**
|
2015-12-24 13:39:38 +00:00
|
|
|
* \brief Check for stack overflow and set error status as needed
|
|
|
|
* \return true on stack overflow
|
2015-11-14 11:56:16 +00:00
|
|
|
*/
|
|
|
|
bool StackOver();
|
|
|
|
|
2015-12-25 19:47:30 +00:00
|
|
|
//@}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
/** \name Error management
|
|
|
|
*/
|
|
|
|
//@{
|
|
|
|
|
2015-11-14 11:56:16 +00:00
|
|
|
/**
|
2015-12-24 13:39:38 +00:00
|
|
|
* \brief Get last error
|
|
|
|
* \param[out] start Starting position in code of the error
|
|
|
|
* \param[out] end Ending position in code of the error
|
|
|
|
* \return Error number
|
2015-11-14 11:56:16 +00:00
|
|
|
*/
|
2021-06-12 02:48:50 +00:00
|
|
|
CBotError GetError(int& start, int& end);
|
2015-11-14 11:56:16 +00:00
|
|
|
|
|
|
|
/**
|
2015-12-24 13:39:38 +00:00
|
|
|
* \brief Get last error
|
|
|
|
* \return Error number
|
|
|
|
* \see GetError(int&, int&) for error position in code
|
2015-11-14 11:56:16 +00:00
|
|
|
*/
|
2021-06-12 02:48:50 +00:00
|
|
|
CBotError GetError();
|
2015-12-25 19:47:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Check if there was an error
|
2016-03-30 11:40:26 +00:00
|
|
|
* \return false if an error occurred
|
2015-12-25 19:47:30 +00:00
|
|
|
* \see GetError()
|
|
|
|
*/
|
2021-06-12 02:48:50 +00:00
|
|
|
bool IsOk();
|
2015-12-25 19:47:30 +00:00
|
|
|
|
2015-12-25 21:03:23 +00:00
|
|
|
/**
|
|
|
|
* \brief Set execution error unless it's already set unless you are trying to reset it
|
|
|
|
*
|
|
|
|
* \param n Error to set
|
|
|
|
* \param token Token to take error position from
|
|
|
|
* \see ResetError() to force set error
|
|
|
|
*/
|
|
|
|
void SetError(CBotError n, CBotToken* token = nullptr);
|
|
|
|
/**
|
|
|
|
* \brief Set error position to position of given token
|
|
|
|
*
|
|
|
|
* \param token Token to take error position from
|
|
|
|
*/
|
|
|
|
void SetPosError(CBotToken* token);
|
|
|
|
/**
|
|
|
|
* \brief Set execution error even if it is already set
|
|
|
|
*
|
|
|
|
* \see SetError() to set error only if it is not set already
|
|
|
|
*/
|
|
|
|
void ResetError(CBotError n, int start, int end);
|
|
|
|
/**
|
|
|
|
* \todo Document
|
|
|
|
*
|
|
|
|
* WARNING! Changes error to -val ...
|
|
|
|
*/
|
|
|
|
void SetBreak(int val, const std::string& name);
|
|
|
|
|
2015-12-25 19:47:30 +00:00
|
|
|
//@}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
2015-11-14 11:56:16 +00:00
|
|
|
|
|
|
|
/**
|
2015-12-25 21:03:23 +00:00
|
|
|
* \brief Reset the stack for execution resume - resets the error and timer
|
2015-11-14 11:56:16 +00:00
|
|
|
*/
|
2015-12-24 13:39:38 +00:00
|
|
|
void Reset();
|
2015-11-14 11:56:16 +00:00
|
|
|
|
2015-12-25 19:47:30 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//! \name Local variables
|
|
|
|
//@{
|
|
|
|
|
2015-11-14 11:56:16 +00:00
|
|
|
/**
|
2015-12-25 18:48:31 +00:00
|
|
|
* \brief Adds a local variable
|
|
|
|
* \param var Variable to be added
|
2015-11-14 11:56:16 +00:00
|
|
|
*/
|
2015-12-25 18:48:31 +00:00
|
|
|
void AddVar(CBotVar* var);
|
2015-11-14 11:56:16 +00:00
|
|
|
|
|
|
|
/**
|
2015-12-25 18:48:31 +00:00
|
|
|
* \brief Fetch a variable by its token
|
|
|
|
* \param pToken Token upon which search is performed
|
2015-12-31 15:54:13 +00:00
|
|
|
* \param bUpdate true to automatically call update function for classes, see CBotClass::SetUpdateFunc()
|
2015-12-25 18:48:31 +00:00
|
|
|
* \return Found variable, nullptr if not found
|
2015-11-14 11:56:16 +00:00
|
|
|
*/
|
2015-12-24 13:39:38 +00:00
|
|
|
CBotVar* FindVar(CBotToken*& pToken, bool bUpdate);
|
2015-11-14 11:56:16 +00:00
|
|
|
|
|
|
|
/**
|
2015-12-25 18:48:31 +00:00
|
|
|
* \copydoc FindVar(CBotToken*&, bool)
|
2015-11-14 11:56:16 +00:00
|
|
|
*/
|
2015-12-24 13:39:38 +00:00
|
|
|
CBotVar* FindVar(CBotToken& pToken, bool bUpdate);
|
2015-11-14 11:56:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Fetch variable by its name
|
2015-12-25 18:48:31 +00:00
|
|
|
* \param name Name of variable to find
|
|
|
|
* \return Found variable, nullptr if not found
|
2015-11-14 11:56:16 +00:00
|
|
|
*/
|
2015-12-20 15:19:10 +00:00
|
|
|
CBotVar* FindVar(const std::string& name);
|
2015-11-14 11:56:16 +00:00
|
|
|
|
|
|
|
/**
|
2015-12-25 18:48:31 +00:00
|
|
|
* \brief Fetch a variable on the stack according to its unique identifier
|
|
|
|
*
|
|
|
|
* This is faster than comparing names
|
|
|
|
*
|
|
|
|
* \param ident Unique identifier of a variable
|
2015-12-31 15:54:13 +00:00
|
|
|
* \param bUpdate true to automatically call update function for classes, see CBotClass::SetUpdateFunc()
|
2015-12-25 18:48:31 +00:00
|
|
|
* \return Found variable, nullptr if not found
|
2015-11-14 11:56:16 +00:00
|
|
|
*/
|
2015-12-24 13:39:38 +00:00
|
|
|
CBotVar* FindVar(long ident, bool bUpdate);
|
2015-11-14 11:56:16 +00:00
|
|
|
|
|
|
|
/**
|
2015-12-25 18:48:31 +00:00
|
|
|
* \brief Find variable by its token and returns a copy of it
|
|
|
|
*
|
|
|
|
* \param pToken Token upon which search is performed
|
2015-12-31 15:54:13 +00:00
|
|
|
* \param bUpdate true to automatically call update function for classes, see CBotClass::SetUpdateFunc()
|
2015-11-14 11:56:16 +00:00
|
|
|
* \return Found variable, nullptr if not found
|
|
|
|
*/
|
2015-12-25 18:48:31 +00:00
|
|
|
CBotVar* CopyVar(CBotToken& pToken, bool bUpdate = false);
|
2015-11-14 11:56:16 +00:00
|
|
|
|
2015-12-25 19:47:30 +00:00
|
|
|
//@}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
/** \name Child stacks
|
|
|
|
*
|
|
|
|
* When you enter a new code block or instruction, child stack is created
|
|
|
|
* for managing everything that happens inside that block / instruction.
|
|
|
|
*/
|
|
|
|
//@{
|
2015-11-14 11:56:16 +00:00
|
|
|
|
2015-12-25 19:47:30 +00:00
|
|
|
/**
|
|
|
|
* \brief Creates or gets the primary child stack
|
|
|
|
*
|
|
|
|
* If the stack already exists, it is returned.
|
|
|
|
* Otherwise, a new stack is created.
|
|
|
|
*
|
|
|
|
* \todo Document params
|
|
|
|
* \returns New stack element
|
|
|
|
*/
|
2015-12-25 21:03:23 +00:00
|
|
|
CBotStack* AddStack(CBotInstr* instr = nullptr, BlockVisibilityType bBlock = BlockVisibilityType::INSTRUCTION);
|
2015-12-25 19:47:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Creates or gets the secondary child stack
|
|
|
|
* \todo What is it used for?
|
|
|
|
*
|
|
|
|
* If the stack already exists, it is returned.
|
|
|
|
* Otherwise, a new stack is created.
|
|
|
|
*
|
|
|
|
* \see AddStack()
|
|
|
|
* \return New stack element
|
|
|
|
*/
|
2015-12-25 21:03:23 +00:00
|
|
|
CBotStack* AddStack2(BlockVisibilityType bBlock = BlockVisibilityType::INSTRUCTION);
|
2015-12-25 19:47:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Adds special EOX stack marker
|
|
|
|
*
|
|
|
|
* \todo What is this thing?
|
|
|
|
* Used by external calls
|
|
|
|
*
|
|
|
|
* \todo Document params & return
|
|
|
|
*/
|
2015-12-31 16:59:48 +00:00
|
|
|
CBotStack* AddStackExternalCall(CBotExternalCall* instr = nullptr,
|
|
|
|
BlockVisibilityType bBlock = BlockVisibilityType::INSTRUCTION);
|
2015-12-25 19:47:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Restore CBotInstr pointer after loading stack from file
|
|
|
|
* \todo Check what this does exactly
|
|
|
|
*/
|
2015-11-14 11:56:16 +00:00
|
|
|
CBotStack* RestoreStack(CBotInstr* instr = nullptr);
|
2015-12-25 19:47:30 +00:00
|
|
|
/**
|
|
|
|
* \brief Restores CBotExternalCall in the EOX marker after loading stack from file
|
|
|
|
* \todo Check what this does exactly
|
|
|
|
*/
|
2015-12-24 10:57:34 +00:00
|
|
|
CBotStack* RestoreStackEOX(CBotExternalCall* instr = nullptr);
|
2015-11-14 11:56:16 +00:00
|
|
|
|
2015-12-25 19:47:30 +00:00
|
|
|
/**
|
|
|
|
* \brief Return to this point - copy the result from given stack, and destroy all child stacks from here
|
|
|
|
*
|
|
|
|
* \todo Better description
|
|
|
|
*
|
|
|
|
* \param pFils Stack to copy result from
|
|
|
|
* \return IsOk()
|
|
|
|
*/
|
|
|
|
bool Return(CBotStack* pFils);
|
|
|
|
/**
|
|
|
|
* \brief Like Return() but doesn't destroy the stacks
|
|
|
|
*
|
|
|
|
* \param pFils Stack to copy result from
|
|
|
|
* \return IsOk()
|
|
|
|
*/
|
|
|
|
bool ReturnKeep(CBotStack* pFils);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \todo Document
|
2015-12-25 21:03:23 +00:00
|
|
|
*
|
2015-12-25 19:47:30 +00:00
|
|
|
* in case of eventual break
|
|
|
|
*/
|
2016-01-15 18:59:03 +00:00
|
|
|
bool BreakReturn(CBotStack* pfils, const std::string& name = "");
|
2015-12-25 19:47:30 +00:00
|
|
|
/**
|
|
|
|
* \todo Document
|
2015-12-25 21:03:23 +00:00
|
|
|
*
|
2015-12-25 19:47:30 +00:00
|
|
|
* or "continue"
|
|
|
|
*/
|
2015-12-20 15:19:10 +00:00
|
|
|
bool IfContinue(int state, const std::string& name);
|
2015-11-14 11:56:16 +00:00
|
|
|
|
2015-12-25 19:47:30 +00:00
|
|
|
//@}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
/** \name Preserving execution status
|
|
|
|
*
|
|
|
|
* A "state" is a number that determines how much of CBotInstr::Execute() has been already executed.
|
|
|
|
* When CBotInstr::Execute() is called, it continues execution from the point it finished at.
|
|
|
|
* See various CBotInstr::Execute() implementations for details.
|
|
|
|
*
|
2015-12-25 21:03:23 +00:00
|
|
|
* Each state change causes one tick on the execution timer
|
2015-12-25 19:47:30 +00:00
|
|
|
*/
|
|
|
|
//@{
|
2015-11-14 11:56:16 +00:00
|
|
|
|
2015-12-25 21:03:23 +00:00
|
|
|
/**
|
|
|
|
* \brief Set execution state
|
|
|
|
* \param n New state
|
|
|
|
* \param lim Required amount of "ticks" on the timer required to allow to continue execution. By default allows a little overflow (up to 10 ticks)
|
|
|
|
* \return false if timer requests interruption (timer <= limit)
|
|
|
|
*/
|
|
|
|
bool SetState(int n, int lim = -10);
|
|
|
|
/**
|
|
|
|
* \brief Return current execution state
|
|
|
|
*
|
|
|
|
* Used when resuming execution
|
|
|
|
*
|
|
|
|
* \return Execution state set before interruption by SetState() and IncState()
|
|
|
|
*/
|
|
|
|
int GetState() { return m_state; }
|
|
|
|
/**
|
|
|
|
* \brief Increase the execution state by one
|
|
|
|
* \param lim Required amount of "ticks" on the timer required to allow to continue execution. By default allows a little overflow (up to 10 ticks)
|
|
|
|
* \return false if timer requests interruption (timer <= limit)
|
|
|
|
*/
|
|
|
|
bool IncState(int lim = -10);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Check if we are in step by step execution mode
|
|
|
|
* \return true if step by step, false otherwise
|
|
|
|
*/
|
|
|
|
bool IfStep();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Resumes execution of interrupted external call
|
|
|
|
* \return true if external call finished, false if interrupted again
|
|
|
|
*/
|
2015-11-14 11:56:16 +00:00
|
|
|
bool Execute();
|
|
|
|
|
2015-12-25 19:47:30 +00:00
|
|
|
//@}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
2015-12-25 21:03:23 +00:00
|
|
|
//! \name Result variable
|
2015-12-25 19:47:30 +00:00
|
|
|
//@{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Set the result variable
|
|
|
|
* \todo CBotStack takes over the ownership - use std::unique_ptr here
|
|
|
|
* \param var Result variable to set
|
|
|
|
*/
|
|
|
|
void SetVar(CBotVar* var);
|
|
|
|
/**
|
|
|
|
* \brief Set the result variable to copy of given variable
|
|
|
|
* \param var Variable to copy as result
|
|
|
|
*/
|
2015-12-25 21:03:23 +00:00
|
|
|
void SetCopyVar(CBotVar* var);
|
2015-12-25 19:47:30 +00:00
|
|
|
/**
|
|
|
|
* \brief Return result variable
|
|
|
|
* \return Variable set with SetVar() or SetCopyVar()
|
|
|
|
*/
|
2015-11-14 11:56:16 +00:00
|
|
|
CBotVar* GetVar();
|
2015-12-25 21:03:23 +00:00
|
|
|
|
2015-12-25 19:47:30 +00:00
|
|
|
/**
|
|
|
|
* \todo Document
|
2015-12-25 21:03:23 +00:00
|
|
|
*
|
2021-06-12 02:48:50 +00:00
|
|
|
* Copies the result value from m_data->retvar (m_var at a moment of SetBreak(3)) to this stack result
|
2015-12-25 19:47:30 +00:00
|
|
|
*/
|
2015-11-14 11:56:16 +00:00
|
|
|
bool GetRetVar(bool bRet);
|
2015-12-25 21:03:23 +00:00
|
|
|
|
2015-12-25 19:47:30 +00:00
|
|
|
/**
|
|
|
|
* \brief Return the result variable as int
|
|
|
|
* \deprecated Please use GetVar()->GetValInt() instead
|
|
|
|
* \todo Remove
|
|
|
|
* \return GetVar()->GetValInt(), or 0 if GetVar() == nullptr
|
|
|
|
*/
|
2015-11-14 11:56:16 +00:00
|
|
|
long GetVal();
|
|
|
|
|
2015-12-25 19:47:30 +00:00
|
|
|
//@}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2015-12-25 21:03:23 +00:00
|
|
|
/**
|
|
|
|
* \brief Set program this stack level is in. Additionally marks this block as function block.
|
|
|
|
* Note: for public functions different stack levels might be in different programs
|
|
|
|
* \todo Refactor this two-in-one thing
|
|
|
|
* \param p CBotProgram we are currently in
|
|
|
|
*/
|
2015-12-24 13:39:38 +00:00
|
|
|
void SetProgram(CBotProgram* p);
|
2015-12-25 21:03:23 +00:00
|
|
|
/**
|
|
|
|
* \brief Get program we are currently in
|
|
|
|
* \param bFirst if true, get the main CBotProgram instance (the one that has the main function)
|
|
|
|
*/
|
|
|
|
CBotProgram* GetProgram(bool bFirst = false);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Set user pointer for external calls
|
|
|
|
*
|
|
|
|
* Execution calls only - see CBotExternalCallList::SetUserPtr() for compilation calls
|
|
|
|
*
|
|
|
|
* \param user User pointer to set
|
|
|
|
*/
|
2015-12-24 13:39:38 +00:00
|
|
|
void SetUserPtr(void* user);
|
2015-12-25 21:03:23 +00:00
|
|
|
/**
|
|
|
|
* \brief Get user pointer for external calls
|
|
|
|
* \returns User pointer for external execution calls
|
|
|
|
* \see SetUserPtr()
|
|
|
|
*/
|
2015-12-24 13:39:38 +00:00
|
|
|
void* GetUserPtr();
|
2015-11-14 11:56:16 +00:00
|
|
|
|
2015-12-25 21:03:23 +00:00
|
|
|
/**
|
|
|
|
* \brief Get the block type this stack represents - instruction, code block or function
|
|
|
|
* \see BlockVisibilityType enum
|
|
|
|
*/
|
|
|
|
BlockVisibilityType GetBlock();
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//! \name Function calls
|
|
|
|
//@{
|
2015-11-14 11:56:16 +00:00
|
|
|
|
2015-12-25 21:03:23 +00:00
|
|
|
/**
|
|
|
|
* \brief Execute a function call, either external or user-defined
|
|
|
|
* \param[in, out] nIdent Unique function identifier, if not found will be updated
|
|
|
|
* \param token Function name token
|
|
|
|
* \param ppVar Array of function arguments
|
|
|
|
* \param rettype Expected return type
|
|
|
|
*/
|
|
|
|
bool ExecuteCall(long& nIdent, CBotToken* token, CBotVar** ppVar, const CBotTypResult& rettype);
|
|
|
|
/**
|
|
|
|
* \brief Restore a function call after the program state has been restored from a file
|
|
|
|
* \param[in, out] nIdent Unique function identifier, if not found will be updated
|
|
|
|
* \param token Function name token
|
|
|
|
* \param ppVar Array of function arguments
|
|
|
|
*/
|
2015-11-14 11:56:16 +00:00
|
|
|
void RestoreCall(long& nIdent, CBotToken* token, CBotVar** ppVar);
|
|
|
|
|
2015-12-25 21:03:23 +00:00
|
|
|
//@}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//! \name Write to file
|
|
|
|
//@{
|
|
|
|
|
2019-04-11 08:13:13 +00:00
|
|
|
bool SaveState(std::ostream &ostr);
|
|
|
|
bool RestoreState(std::istream &istr, CBotStack* &pStack);
|
2015-11-14 11:56:16 +00:00
|
|
|
|
2015-12-25 21:03:23 +00:00
|
|
|
//@}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Set the maximum number of "timer ticks" (parts of instructions) to execute
|
|
|
|
*
|
|
|
|
* This setting gets applied on next call to Reset()
|
|
|
|
*
|
|
|
|
* \todo Full documentation of the timer
|
|
|
|
*/
|
2021-06-12 02:48:50 +00:00
|
|
|
void SetTimer(int n);
|
2015-12-31 16:59:48 +00:00
|
|
|
/**
|
|
|
|
* \brief Get the current configured maximum number of "timer ticks" (parts of instructions) to execute
|
|
|
|
*/
|
2021-06-12 02:48:50 +00:00
|
|
|
int GetTimer();
|
2015-11-14 11:56:16 +00:00
|
|
|
|
2015-12-25 21:03:23 +00:00
|
|
|
/**
|
|
|
|
* \brief Get current position in the program
|
|
|
|
* \param[out] functionName Current function name, nullptr if not found
|
|
|
|
* \param[out] start Start position of currently executed token
|
|
|
|
* \param[out] end End position of currently executed token
|
|
|
|
*/
|
|
|
|
void GetRunPos(std::string& functionName, int& start, int& end);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Get local variables at the given stack level
|
|
|
|
* \param[out] functionName Name of instruction being executed at this level
|
|
|
|
* \param level 0 for current level, -1, -2, -3 etc. for next levels
|
|
|
|
*/
|
|
|
|
CBotVar* GetStackVars(std::string& functionName, int level);
|
2015-11-14 11:56:16 +00:00
|
|
|
|
2015-12-31 16:59:48 +00:00
|
|
|
bool IsCallFinished();
|
|
|
|
|
2015-11-14 11:56:16 +00:00
|
|
|
private:
|
|
|
|
CBotStack* m_next;
|
|
|
|
CBotStack* m_next2;
|
|
|
|
CBotStack* m_prev;
|
|
|
|
|
2015-12-31 16:59:48 +00:00
|
|
|
int m_state;
|
|
|
|
int m_step;
|
2021-06-12 02:48:50 +00:00
|
|
|
|
|
|
|
struct Data;
|
|
|
|
|
|
|
|
CBotStack::Data* m_data;
|
2015-11-14 11:56:16 +00:00
|
|
|
|
|
|
|
CBotVar* m_var; // result of the operations
|
|
|
|
CBotVar* m_listVar; // variables declared at this level
|
|
|
|
|
2015-12-31 16:59:48 +00:00
|
|
|
BlockVisibilityType m_block; // is part of a block (variables are local to this block)
|
2015-11-14 11:56:16 +00:00
|
|
|
bool m_bOver; // stack limits?
|
2015-12-31 16:59:48 +00:00
|
|
|
//! CBotProgram instance the execution is in in this stack level
|
|
|
|
CBotProgram* m_prog;
|
|
|
|
|
|
|
|
//! The corresponding instruction
|
|
|
|
CBotInstr* m_instr;
|
|
|
|
//! If this stack level holds a function call
|
|
|
|
IsFunction m_func;
|
|
|
|
//! Extern call on this level (only if m_func == IsFunction::EXTERNAL_CALL)
|
|
|
|
CBotExternalCall* m_call;
|
|
|
|
|
|
|
|
bool m_callFinished;
|
2015-11-14 11:56:16 +00:00
|
|
|
};
|
2015-12-26 13:19:24 +00:00
|
|
|
|
|
|
|
} // namespace CBot
|