Use forward declaration in libscript
This commit is contained in:
parent
ad6df32c97
commit
e9bbc08ec3
21 changed files with 247 additions and 122 deletions
|
@ -389,10 +389,13 @@ target_precompile_headers(libgui PRIVATE src/engine/pch.h)
|
|||
set(SCRIPT_HEADERS
|
||||
src/engine/script/enginetype.h
|
||||
src/engine/script/execution.h
|
||||
src/engine/script/executioncontext.h
|
||||
src/engine/script/executionstate.h
|
||||
src/engine/script/instrutil.h
|
||||
src/engine/script/ncsreader.h
|
||||
src/engine/script/program.h
|
||||
src/engine/script/routine.h
|
||||
src/engine/script/routineprovider.h
|
||||
src/engine/script/services.h
|
||||
src/engine/script/scripts.h
|
||||
src/engine/script/types.h
|
||||
|
|
|
@ -17,12 +17,16 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "../../script/types.h"
|
||||
|
||||
#include "action.h"
|
||||
|
||||
namespace reone {
|
||||
|
||||
namespace script {
|
||||
|
||||
struct ExecutionContext;
|
||||
|
||||
}
|
||||
|
||||
namespace game {
|
||||
|
||||
class CommandAction : public Action {
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "../common/guardutil.h"
|
||||
#include "../scene/types.h"
|
||||
#include "../script/execution.h"
|
||||
#include "../script/executioncontext.h"
|
||||
|
||||
#include "action/usefeat.h"
|
||||
#include "action/useskill.h"
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
|
||||
#include "routines.h"
|
||||
|
||||
#include "../../script/executioncontext.h"
|
||||
|
||||
#include "../enginetype/effect.h"
|
||||
#include "../enginetype/event.h"
|
||||
#include "../enginetype/location.h"
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "../../common/collectionutil.h"
|
||||
#include "../../resource/types.h"
|
||||
#include "../../script/routine.h"
|
||||
#include "../../script/routineprovider.h"
|
||||
#include "../../script/types.h"
|
||||
#include "../../script/variable.h"
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include "../../common/log.h"
|
||||
#include "../../common/random.h"
|
||||
#include "../../resource/strings.h"
|
||||
#include "../../script/executioncontext.h"
|
||||
|
||||
#include "../game.h"
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include "routines.h"
|
||||
|
||||
#include "../../common/log.h"
|
||||
#include "../../script/executioncontext.h"
|
||||
|
||||
#include "../enginetype/event.h"
|
||||
#include "../game.h"
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include "runner.h"
|
||||
|
||||
#include "../../script/execution.h"
|
||||
#include "../../script/executioncontext.h"
|
||||
|
||||
#include "../game.h"
|
||||
|
||||
|
|
|
@ -17,10 +17,15 @@
|
|||
|
||||
#include "execution.h"
|
||||
|
||||
#include "../common/guardutil.h"
|
||||
#include "../common/log.h"
|
||||
|
||||
#include "executioncontext.h"
|
||||
#include "instrutil.h"
|
||||
#include "program.h"
|
||||
#include "routine.h"
|
||||
#include "routineprovider.h"
|
||||
#include "variable.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace std::placeholders;
|
||||
|
@ -31,7 +36,9 @@ namespace script {
|
|||
|
||||
static constexpr int kStartInstructionOffset = 13;
|
||||
|
||||
ScriptExecution::ScriptExecution(const shared_ptr<ScriptProgram> &program, unique_ptr<ExecutionContext> context) : _context(move(context)), _program(program) {
|
||||
ScriptExecution::ScriptExecution(shared_ptr<ScriptProgram> program, unique_ptr<ExecutionContext> context) : _context(move(context)), _program(program) {
|
||||
ensureNotNull(program, "program");
|
||||
|
||||
static unordered_map<ByteCode, function<void(ScriptExecution *, const Instruction &)>> handlers {
|
||||
{ ByteCode::CopyDownSP, &ScriptExecution::executeCopyDownSP },
|
||||
{ ByteCode::Reserve, &ScriptExecution::executeReserve },
|
||||
|
|
|
@ -17,17 +17,22 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "program.h"
|
||||
#include "executionstate.h"
|
||||
#include "types.h"
|
||||
#include "variable.h"
|
||||
|
||||
namespace reone {
|
||||
|
||||
namespace script {
|
||||
|
||||
struct ExecutionContext;
|
||||
struct Instruction;
|
||||
struct Variable;
|
||||
|
||||
class ScriptProgram;
|
||||
|
||||
class ScriptExecution : boost::noncopyable {
|
||||
public:
|
||||
ScriptExecution(const std::shared_ptr<ScriptProgram> &program, std::unique_ptr<ExecutionContext> context);
|
||||
ScriptExecution(std::shared_ptr<ScriptProgram> program, std::unique_ptr<ExecutionContext> context);
|
||||
|
||||
int run();
|
||||
|
||||
|
|
41
src/engine/script/executioncontext.h
Normal file
41
src/engine/script/executioncontext.h
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Copyright (c) 2020-2021 The reone project contributors
|
||||
*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "types.h"
|
||||
|
||||
namespace reone {
|
||||
|
||||
namespace script {
|
||||
|
||||
struct ExecutionState;
|
||||
|
||||
class IRoutineProvider;
|
||||
|
||||
struct ExecutionContext {
|
||||
IRoutineProvider *routines { nullptr };
|
||||
std::shared_ptr<ExecutionState> savedState;
|
||||
uint32_t callerId { kObjectInvalid };
|
||||
uint32_t triggererId { kObjectInvalid };
|
||||
int userDefinedEventNumber { -1 };
|
||||
int scriptVar { -1 };
|
||||
};
|
||||
|
||||
} // namespace script
|
||||
|
||||
} // namespae reone
|
37
src/engine/script/executionstate.h
Normal file
37
src/engine/script/executionstate.h
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Copyright (c) 2020-2021 The reone project contributors
|
||||
*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace reone {
|
||||
|
||||
namespace script {
|
||||
|
||||
struct Variable;
|
||||
|
||||
class ScriptProgram;
|
||||
|
||||
struct ExecutionState {
|
||||
std::shared_ptr<ScriptProgram> program;
|
||||
std::vector<Variable> globals;
|
||||
std::vector<Variable> locals;
|
||||
uint32_t insOffset { 0 };
|
||||
};
|
||||
|
||||
} // namespace script
|
||||
|
||||
} // namespae reone
|
|
@ -19,6 +19,8 @@
|
|||
|
||||
#include "../common/log.h"
|
||||
|
||||
#include "program.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace reone {
|
||||
|
|
|
@ -19,12 +19,12 @@
|
|||
|
||||
#include "../resource/format/binreader.h"
|
||||
|
||||
#include "program.h"
|
||||
|
||||
namespace reone {
|
||||
|
||||
namespace script {
|
||||
|
||||
class ScriptProgram;
|
||||
|
||||
/**
|
||||
* Parses compiled script program.
|
||||
*
|
||||
|
|
|
@ -17,85 +17,12 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "types.h"
|
||||
|
||||
namespace reone {
|
||||
|
||||
namespace script {
|
||||
|
||||
enum class ByteCode {
|
||||
CopyDownSP = 0x01,
|
||||
Reserve = 0x02,
|
||||
CopyTopSP = 0x03,
|
||||
PushConstant = 0x04,
|
||||
CallRoutine = 0x05,
|
||||
LogicalAnd = 0x06,
|
||||
LogicalOr = 0x07,
|
||||
InclusiveBitwiseOr = 0x08,
|
||||
ExclusiveBitwiseOr = 0x09,
|
||||
BitwiseAnd = 0x0a,
|
||||
Equal = 0x0b,
|
||||
NotEqual = 0x0c,
|
||||
GreaterThanOrEqual = 0x0d,
|
||||
GreaterThan = 0x0e,
|
||||
LessThan = 0x0f,
|
||||
LessThanOrEqual = 0x10,
|
||||
ShiftLeft = 0x11,
|
||||
ShiftRight = 0x12,
|
||||
UnsignedShiftRight = 0x13,
|
||||
Add = 0x14,
|
||||
Subtract = 0x15,
|
||||
Multiply = 0x16,
|
||||
Divide = 0x17,
|
||||
Mod = 0x18,
|
||||
Negate = 0x19,
|
||||
OnesComplement = 0x1a,
|
||||
AdjustSP = 0x1b,
|
||||
Jump = 0x1d,
|
||||
JumpToSubroutine = 0x1e,
|
||||
JumpIfZero = 0x1f,
|
||||
Return = 0x20,
|
||||
Destruct = 0x21,
|
||||
LogicalNot = 0x22,
|
||||
DecRelToSP = 0x23,
|
||||
IncRelToSP = 0x24,
|
||||
JumpIfNonZero = 0x25,
|
||||
CopyDownBP = 0x26,
|
||||
CopyTopBP = 0x27,
|
||||
DecRelToBP = 0x28,
|
||||
IncRelToBP = 0x29,
|
||||
SaveBP = 0x2a,
|
||||
RestoreBP = 0x2b,
|
||||
StoreState = 0x2c,
|
||||
Noop = 0x2d,
|
||||
Invalid = 0xff
|
||||
};
|
||||
|
||||
enum class InstructionType {
|
||||
None = 0,
|
||||
One = 0x01,
|
||||
Int = 0x03,
|
||||
Float = 0x04,
|
||||
String = 0x05,
|
||||
Object = 0x06,
|
||||
Effect = 0x10,
|
||||
Event = 0x11,
|
||||
Location = 0x12,
|
||||
Talent = 0x13,
|
||||
IntInt = 0x20,
|
||||
FloatFloat = 0x21,
|
||||
ObjectObject = 0x22,
|
||||
StringString = 0x23,
|
||||
StructStruct = 0x24,
|
||||
IntFloat = 0x25,
|
||||
FloatInt = 0x26,
|
||||
EffectEffect = 0x30,
|
||||
EventEvent = 0x31,
|
||||
LocationLocation = 0x32,
|
||||
TalentTalent = 0x33,
|
||||
VectorVector = 0x3a,
|
||||
VectorFloat = 0x3b,
|
||||
FloatVector = 0x3c
|
||||
};
|
||||
|
||||
class NcsReader;
|
||||
|
||||
struct Instruction {
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
|
||||
#include "../common/log.h"
|
||||
|
||||
#include "variable.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace reone {
|
||||
|
|
|
@ -17,12 +17,15 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "variable.h"
|
||||
#include "types.h"
|
||||
|
||||
namespace reone {
|
||||
|
||||
namespace script {
|
||||
|
||||
struct ExecutionContext;
|
||||
struct Variable;
|
||||
|
||||
class Routine {
|
||||
public:
|
||||
Routine() = default;
|
||||
|
|
36
src/engine/script/routineprovider.h
Normal file
36
src/engine/script/routineprovider.h
Normal file
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Copyright (c) 2020-2021 The reone project contributors
|
||||
*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace reone {
|
||||
|
||||
namespace script {
|
||||
|
||||
class Routine;
|
||||
|
||||
class IRoutineProvider {
|
||||
public:
|
||||
virtual ~IRoutineProvider() {
|
||||
}
|
||||
|
||||
virtual const Routine &get(int index) = 0;
|
||||
};
|
||||
|
||||
} // namespace script
|
||||
|
||||
} // namespae reone
|
|
@ -24,33 +24,95 @@ namespace script {
|
|||
constexpr uint32_t kObjectSelf = 0;
|
||||
constexpr uint32_t kObjectInvalid = 1;
|
||||
|
||||
struct Variable;
|
||||
|
||||
class ScriptProgram;
|
||||
class Routine;
|
||||
|
||||
struct ExecutionState {
|
||||
std::shared_ptr<ScriptProgram> program;
|
||||
std::vector<Variable> globals;
|
||||
std::vector<Variable> locals;
|
||||
uint32_t insOffset { 0 };
|
||||
enum class ByteCode {
|
||||
CopyDownSP = 0x01,
|
||||
Reserve = 0x02,
|
||||
CopyTopSP = 0x03,
|
||||
PushConstant = 0x04,
|
||||
CallRoutine = 0x05,
|
||||
LogicalAnd = 0x06,
|
||||
LogicalOr = 0x07,
|
||||
InclusiveBitwiseOr = 0x08,
|
||||
ExclusiveBitwiseOr = 0x09,
|
||||
BitwiseAnd = 0x0a,
|
||||
Equal = 0x0b,
|
||||
NotEqual = 0x0c,
|
||||
GreaterThanOrEqual = 0x0d,
|
||||
GreaterThan = 0x0e,
|
||||
LessThan = 0x0f,
|
||||
LessThanOrEqual = 0x10,
|
||||
ShiftLeft = 0x11,
|
||||
ShiftRight = 0x12,
|
||||
UnsignedShiftRight = 0x13,
|
||||
Add = 0x14,
|
||||
Subtract = 0x15,
|
||||
Multiply = 0x16,
|
||||
Divide = 0x17,
|
||||
Mod = 0x18,
|
||||
Negate = 0x19,
|
||||
OnesComplement = 0x1a,
|
||||
AdjustSP = 0x1b,
|
||||
Jump = 0x1d,
|
||||
JumpToSubroutine = 0x1e,
|
||||
JumpIfZero = 0x1f,
|
||||
Return = 0x20,
|
||||
Destruct = 0x21,
|
||||
LogicalNot = 0x22,
|
||||
DecRelToSP = 0x23,
|
||||
IncRelToSP = 0x24,
|
||||
JumpIfNonZero = 0x25,
|
||||
CopyDownBP = 0x26,
|
||||
CopyTopBP = 0x27,
|
||||
DecRelToBP = 0x28,
|
||||
IncRelToBP = 0x29,
|
||||
SaveBP = 0x2a,
|
||||
RestoreBP = 0x2b,
|
||||
StoreState = 0x2c,
|
||||
Noop = 0x2d,
|
||||
Invalid = 0xff
|
||||
};
|
||||
|
||||
class IRoutineProvider {
|
||||
public:
|
||||
virtual ~IRoutineProvider() {
|
||||
}
|
||||
|
||||
virtual const Routine &get(int index) = 0;
|
||||
enum class InstructionType {
|
||||
None = 0,
|
||||
One = 0x01,
|
||||
Int = 0x03,
|
||||
Float = 0x04,
|
||||
String = 0x05,
|
||||
Object = 0x06,
|
||||
Effect = 0x10,
|
||||
Event = 0x11,
|
||||
Location = 0x12,
|
||||
Talent = 0x13,
|
||||
IntInt = 0x20,
|
||||
FloatFloat = 0x21,
|
||||
ObjectObject = 0x22,
|
||||
StringString = 0x23,
|
||||
StructStruct = 0x24,
|
||||
IntFloat = 0x25,
|
||||
FloatInt = 0x26,
|
||||
EffectEffect = 0x30,
|
||||
EventEvent = 0x31,
|
||||
LocationLocation = 0x32,
|
||||
TalentTalent = 0x33,
|
||||
VectorVector = 0x3a,
|
||||
VectorFloat = 0x3b,
|
||||
FloatVector = 0x3c
|
||||
};
|
||||
|
||||
struct ExecutionContext {
|
||||
IRoutineProvider *routines { nullptr };
|
||||
std::shared_ptr<ExecutionState> savedState;
|
||||
uint32_t callerId { kObjectInvalid };
|
||||
uint32_t triggererId { kObjectInvalid };
|
||||
int userDefinedEventNumber { -1 };
|
||||
int scriptVar { -1 };
|
||||
enum class VariableType {
|
||||
Void,
|
||||
Int,
|
||||
Float,
|
||||
String,
|
||||
Vector,
|
||||
Object,
|
||||
Effect,
|
||||
Event,
|
||||
Location,
|
||||
Talent,
|
||||
Action,
|
||||
|
||||
NotImplemented // used to return default values from placeholder routines
|
||||
};
|
||||
|
||||
} // namespace script
|
||||
|
|
|
@ -23,21 +23,7 @@ namespace reone {
|
|||
|
||||
namespace script {
|
||||
|
||||
enum class VariableType {
|
||||
Void,
|
||||
Int,
|
||||
Float,
|
||||
String,
|
||||
Vector,
|
||||
Object,
|
||||
Effect,
|
||||
Event,
|
||||
Location,
|
||||
Talent,
|
||||
Action,
|
||||
|
||||
NotImplemented // used to return default values from placeholder routines
|
||||
};
|
||||
struct ExecutionContext;
|
||||
|
||||
class EngineType;
|
||||
class ScriptObject;
|
||||
|
|
|
@ -22,6 +22,9 @@
|
|||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include "../../engine/script/execution.h"
|
||||
#include "../../engine/script/executioncontext.h"
|
||||
#include "../../engine/script/program.h"
|
||||
#include "../../engine/script/variable.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
|
Loading…
Reference in a new issue