Moving CBotLogicExpr class in its own header and source files.
parent
4cd7a7a031
commit
8ee0b7df56
|
@ -727,25 +727,6 @@ public:
|
||||||
void RestoreState(CBotStack* &pj, bool bMain) override;
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CBotLogicExpr : public CBotInstr
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
CBotInstr* m_condition; // test to evaluate
|
|
||||||
CBotInstr* m_op1; // left element
|
|
||||||
CBotInstr* m_op2; // right element
|
|
||||||
friend class CBotTwoOpExpr;
|
|
||||||
|
|
||||||
public:
|
|
||||||
CBotLogicExpr();
|
|
||||||
~CBotLogicExpr();
|
|
||||||
// static
|
|
||||||
// CBotInstr* Compile(CBotToken* &p, CBotCStack* pStack);
|
|
||||||
bool Execute(CBotStack* &pStack) override;
|
|
||||||
void RestoreState(CBotStack* &pj, bool bMain) override;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// all operations with two operands
|
// all operations with two operands
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,92 @@
|
||||||
|
/*
|
||||||
|
* This file is part of the Colobot: Gold Edition source code
|
||||||
|
* Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Modules inlcude
|
||||||
|
#include "CBotLogicExpr.h"
|
||||||
|
|
||||||
|
// Local include
|
||||||
|
|
||||||
|
// Global include
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
CBotLogicExpr::CBotLogicExpr()
|
||||||
|
{
|
||||||
|
m_condition =
|
||||||
|
m_op1 =
|
||||||
|
m_op2 = nullptr; // nullptr to be able to delete without other
|
||||||
|
name = "CBotLogicExpr"; // debug
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
CBotLogicExpr::~CBotLogicExpr()
|
||||||
|
{
|
||||||
|
delete m_condition;
|
||||||
|
delete m_op1;
|
||||||
|
delete m_op2;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
bool CBotLogicExpr::Execute(CBotStack* &pStack)
|
||||||
|
{
|
||||||
|
CBotStack* pStk1 = pStack->AddStack(this); // adds an item to the stack
|
||||||
|
// or return in case of recovery
|
||||||
|
// if ( pStk1 == EOX ) return true;
|
||||||
|
|
||||||
|
if ( pStk1->GetState() == 0 )
|
||||||
|
{
|
||||||
|
if ( !m_condition->Execute(pStk1) ) return false;
|
||||||
|
if (!pStk1->SetState(1)) return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( pStk1->GetVal() == true )
|
||||||
|
{
|
||||||
|
if ( !m_op1->Execute(pStk1) ) return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ( !m_op2->Execute(pStk1) ) return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return pStack->Return(pStk1); // transmits the result
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
void CBotLogicExpr::RestoreState(CBotStack* &pStack, bool bMain)
|
||||||
|
{
|
||||||
|
if ( !bMain ) return;
|
||||||
|
|
||||||
|
CBotStack* pStk1 = pStack->RestoreStack(this); // adds an item to the stack
|
||||||
|
if ( pStk1 == nullptr ) return;
|
||||||
|
|
||||||
|
if ( pStk1->GetState() == 0 )
|
||||||
|
{
|
||||||
|
m_condition->RestoreState(pStk1, bMain);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( pStk1->GetVal() == true )
|
||||||
|
{
|
||||||
|
m_op1->RestoreState(pStk1, bMain);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_op2->RestoreState(pStk1, bMain);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,70 @@
|
||||||
|
/*
|
||||||
|
* This file is part of the Colobot: Gold Edition source code
|
||||||
|
* Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam
|
||||||
|
* 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
|
||||||
|
|
||||||
|
// Modules inlcude
|
||||||
|
#include "CBot.h"
|
||||||
|
|
||||||
|
// Local include
|
||||||
|
|
||||||
|
// Global include
|
||||||
|
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief The CBotLogicExpr class
|
||||||
|
*/
|
||||||
|
class CBotLogicExpr : public CBotInstr
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief CBotLogicExpr
|
||||||
|
*/
|
||||||
|
CBotLogicExpr();
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief ~CBotLogicExpr
|
||||||
|
*/
|
||||||
|
~CBotLogicExpr();
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Execute
|
||||||
|
* \param pStack
|
||||||
|
* \return
|
||||||
|
*/
|
||||||
|
bool Execute(CBotStack* &pStack) override;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief RestoreState
|
||||||
|
* \param pj
|
||||||
|
* \param bMain
|
||||||
|
*/
|
||||||
|
void RestoreState(CBotStack* &pj, bool bMain) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
//! Test to evaluate
|
||||||
|
CBotInstr* m_condition;
|
||||||
|
//! Left element
|
||||||
|
CBotInstr* m_op1;
|
||||||
|
//! Right element
|
||||||
|
CBotInstr* m_op2;
|
||||||
|
friend class CBotTwoOpExpr;
|
||||||
|
};
|
|
@ -24,6 +24,7 @@
|
||||||
#include "CBot.h"
|
#include "CBot.h"
|
||||||
|
|
||||||
#include "CBotInstr/CBotParExpr.h"
|
#include "CBotInstr/CBotParExpr.h"
|
||||||
|
#include "CBotInstr/CBotLogicExpr.h"
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
|
@ -50,22 +51,6 @@ CBotTwoOpExpr::~CBotTwoOpExpr()
|
||||||
delete m_rightop;
|
delete m_rightop;
|
||||||
}
|
}
|
||||||
|
|
||||||
CBotLogicExpr::CBotLogicExpr()
|
|
||||||
{
|
|
||||||
m_condition =
|
|
||||||
m_op1 =
|
|
||||||
m_op2 = nullptr; // nullptr to be able to delete without other
|
|
||||||
name = "CBotLogicExpr"; // debug
|
|
||||||
}
|
|
||||||
|
|
||||||
CBotLogicExpr::~CBotLogicExpr()
|
|
||||||
{
|
|
||||||
delete m_condition;
|
|
||||||
delete m_op1;
|
|
||||||
delete m_op2;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// type of operands accepted by operations
|
// type of operands accepted by operations
|
||||||
#define ENTIER ((1<<CBotTypByte)|(1<<CBotTypShort)|(1<<CBotTypChar)|(1<<CBotTypInt)|(1<<CBotTypLong))
|
#define ENTIER ((1<<CBotTypByte)|(1<<CBotTypShort)|(1<<CBotTypChar)|(1<<CBotTypInt)|(1<<CBotTypLong))
|
||||||
#define FLOTANT ((1<<CBotTypFloat)|(1<<CBotTypDouble))
|
#define FLOTANT ((1<<CBotTypFloat)|(1<<CBotTypDouble))
|
||||||
|
@ -517,54 +502,6 @@ void CBotTwoOpExpr::RestoreState(CBotStack* &pStack, bool bMain)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool CBotLogicExpr::Execute(CBotStack* &pStack)
|
|
||||||
{
|
|
||||||
CBotStack* pStk1 = pStack->AddStack(this); // adds an item to the stack
|
|
||||||
// or return in case of recovery
|
|
||||||
// if ( pStk1 == EOX ) return true;
|
|
||||||
|
|
||||||
if ( pStk1->GetState() == 0 )
|
|
||||||
{
|
|
||||||
if ( !m_condition->Execute(pStk1) ) return false;
|
|
||||||
if (!pStk1->SetState(1)) return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( pStk1->GetVal() == true )
|
|
||||||
{
|
|
||||||
if ( !m_op1->Execute(pStk1) ) return false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if ( !m_op2->Execute(pStk1) ) return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return pStack->Return(pStk1); // transmits the result
|
|
||||||
}
|
|
||||||
|
|
||||||
void CBotLogicExpr::RestoreState(CBotStack* &pStack, bool bMain)
|
|
||||||
{
|
|
||||||
if ( !bMain ) return;
|
|
||||||
|
|
||||||
CBotStack* pStk1 = pStack->RestoreStack(this); // adds an item to the stack
|
|
||||||
if ( pStk1 == nullptr ) return;
|
|
||||||
|
|
||||||
if ( pStk1->GetState() == 0 )
|
|
||||||
{
|
|
||||||
m_condition->RestoreState(pStk1, bMain);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( pStk1->GetVal() == true )
|
|
||||||
{
|
|
||||||
m_op1->RestoreState(pStk1, bMain);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_op2->RestoreState(pStk1, bMain);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
void t()
|
void t()
|
||||||
{
|
{
|
||||||
|
|
|
@ -36,6 +36,7 @@ set(SOURCES
|
||||||
CBotInstr/CBotExprUnaire.cpp
|
CBotInstr/CBotExprUnaire.cpp
|
||||||
CBotInstr/CBotParExpr.cpp
|
CBotInstr/CBotParExpr.cpp
|
||||||
CBotInstr/CBotBoolExpr.cpp
|
CBotInstr/CBotBoolExpr.cpp
|
||||||
|
CBotInstr/CBotLogicExpr.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
# Includes
|
# Includes
|
||||||
|
|
Loading…
Reference in New Issue