mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-04-20 03:45:26 +00:00
Console Refactor
This commit is contained in:
parent
626de074cc
commit
89b0c7f73b
89 changed files with 1883 additions and 1553 deletions
|
|
@ -38,12 +38,12 @@
|
|||
#ifndef _DATACHUNKER_H_
|
||||
#include "core/dataChunker.h"
|
||||
#endif
|
||||
#include "module.h"
|
||||
|
||||
/// @ingroup console_system Console System
|
||||
/// @{
|
||||
|
||||
|
||||
class ExprEvalState;
|
||||
struct FunctionDecl;
|
||||
class CodeBlock;
|
||||
class AbstractClassRep;
|
||||
|
|
@ -125,7 +125,7 @@ public:
|
|||
ConsoleFunctionHeader* mHeader;
|
||||
|
||||
/// The compiled script code if this is a script function.
|
||||
CodeBlock* mCode;
|
||||
Con::Module* mModule;
|
||||
|
||||
/// The offset in the compiled script code at which this function begins.
|
||||
U32 mFunctionOffset;
|
||||
|
|
@ -150,7 +150,7 @@ public:
|
|||
void clear();
|
||||
|
||||
///
|
||||
ConsoleValue execute(S32 argc, ConsoleValue* argv, ExprEvalState* state);
|
||||
ConsoleValue execute(S32 argc, ConsoleValue* argv, SimObject* thisObj);
|
||||
|
||||
/// Return a one-line documentation text string for the function.
|
||||
String getBriefDescription(String* outRemainingDocText = NULL) const;
|
||||
|
|
@ -181,7 +181,7 @@ public:
|
|||
Namespace();
|
||||
~Namespace();
|
||||
|
||||
void addFunction(StringTableEntry name, CodeBlock* cb, U32 functionOffset, const char* usage = NULL, U32 lineNumber = 0);
|
||||
void addFunction(StringTableEntry name, Con::Module* cb, U32 functionOffset, const char* usage = NULL, U32 lineNumber = 0);
|
||||
void addCommand(StringTableEntry name, StringCallback, const char *usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL);
|
||||
void addCommand(StringTableEntry name, IntCallback, const char *usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL);
|
||||
void addCommand(StringTableEntry name, FloatCallback, const char *usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL);
|
||||
|
|
@ -475,11 +475,10 @@ public:
|
|||
|
||||
HashTableData* hashTable;
|
||||
HashTableData ownHashTable;
|
||||
ExprEvalState *exprState;
|
||||
|
||||
StringTableEntry scopeName;
|
||||
Namespace *scopeNamespace;
|
||||
CodeBlock *code;
|
||||
Con::Module *module;
|
||||
U32 ip;
|
||||
|
||||
Dictionary();
|
||||
|
|
@ -487,7 +486,7 @@ public:
|
|||
|
||||
Entry *lookup(StringTableEntry name);
|
||||
Entry *add(StringTableEntry name);
|
||||
void setState(ExprEvalState *state, Dictionary* ref = NULL);
|
||||
void setState(Dictionary* ref = NULL);
|
||||
void remove(Entry *);
|
||||
void reset();
|
||||
|
||||
|
|
@ -547,126 +546,35 @@ struct ConsoleValueFrame
|
|||
}
|
||||
};
|
||||
|
||||
class ExprEvalState
|
||||
{
|
||||
public:
|
||||
/// @name Expression Evaluation
|
||||
/// @{
|
||||
|
||||
///
|
||||
SimObject *thisObject;
|
||||
Dictionary::Entry *currentVariable;
|
||||
Dictionary::Entry *copyVariable;
|
||||
bool traceOn;
|
||||
|
||||
U32 mStackDepth;
|
||||
bool mShouldReset; ///< Designates if the value stack should be reset
|
||||
bool mResetLocked; ///< mShouldReset will be set at the end
|
||||
|
||||
ExprEvalState();
|
||||
~ExprEvalState();
|
||||
|
||||
/// @}
|
||||
|
||||
/// @name Stack Management
|
||||
/// @{
|
||||
|
||||
/// The stack of callframes. The extra redirection is necessary since Dictionary holds
|
||||
/// an interior pointer that will become invalid when the object changes address.
|
||||
Vector< Dictionary* > stack;
|
||||
|
||||
S32 getTopOfStack() { return (S32)mStackDepth; }
|
||||
|
||||
Vector< ConsoleValueFrame > localStack;
|
||||
ConsoleValueFrame* currentRegisterArray; // contains array at to top of localStack
|
||||
|
||||
///
|
||||
Dictionary globalVars;
|
||||
|
||||
void setCurVarName(StringTableEntry name);
|
||||
void setCurVarNameCreate(StringTableEntry name);
|
||||
|
||||
S32 getIntVariable();
|
||||
F64 getFloatVariable();
|
||||
const char *getStringVariable();
|
||||
void setIntVariable(S32 val);
|
||||
void setFloatVariable(F64 val);
|
||||
void setStringVariable(const char *str);
|
||||
|
||||
TORQUE_FORCEINLINE S32 getLocalIntVariable(S32 reg)
|
||||
{
|
||||
return currentRegisterArray->values[reg].getInt();
|
||||
}
|
||||
|
||||
TORQUE_FORCEINLINE F64 getLocalFloatVariable(S32 reg)
|
||||
{
|
||||
return currentRegisterArray->values[reg].getFloat();
|
||||
}
|
||||
|
||||
TORQUE_FORCEINLINE const char* getLocalStringVariable(S32 reg)
|
||||
{
|
||||
return currentRegisterArray->values[reg].getString();
|
||||
}
|
||||
|
||||
TORQUE_FORCEINLINE void setLocalIntVariable(S32 reg, S64 val)
|
||||
{
|
||||
currentRegisterArray->values[reg].setInt(val);
|
||||
}
|
||||
|
||||
TORQUE_FORCEINLINE void setLocalFloatVariable(S32 reg, F64 val)
|
||||
{
|
||||
currentRegisterArray->values[reg].setFloat(val);
|
||||
}
|
||||
|
||||
TORQUE_FORCEINLINE void setLocalStringVariable(S32 reg, const char* val, S32 len)
|
||||
{
|
||||
currentRegisterArray->values[reg].setString(val, len);
|
||||
}
|
||||
|
||||
TORQUE_FORCEINLINE void setLocalStringTableEntryVariable(S32 reg, StringTableEntry val)
|
||||
{
|
||||
currentRegisterArray->values[reg].setStringTableEntry(val);
|
||||
}
|
||||
|
||||
TORQUE_FORCEINLINE void moveConsoleValue(S32 reg, ConsoleValue val)
|
||||
{
|
||||
currentRegisterArray->values[reg] = std::move(val);
|
||||
}
|
||||
|
||||
void pushFrame(StringTableEntry frameName, Namespace *ns, S32 regCount);
|
||||
void popFrame();
|
||||
|
||||
/// Puts a reference to an existing stack frame
|
||||
/// on the top of the stack.
|
||||
void pushFrameRef(S32 stackIndex);
|
||||
|
||||
void pushDebugFrame(S32 stackIndex);
|
||||
|
||||
U32 getStackDepth() const
|
||||
{
|
||||
return mStackDepth;
|
||||
}
|
||||
|
||||
Dictionary& getCurrentFrame()
|
||||
{
|
||||
return *(stack[mStackDepth - 1]);
|
||||
}
|
||||
|
||||
Dictionary& getFrameAt(S32 depth)
|
||||
{
|
||||
return *(stack[depth]);
|
||||
}
|
||||
|
||||
/// @}
|
||||
|
||||
/// Run integrity checks for debugging.
|
||||
void validate();
|
||||
};
|
||||
|
||||
namespace Con
|
||||
{
|
||||
/// The current $instantGroup setting.
|
||||
extern String gInstantGroup;
|
||||
|
||||
/// Global variable storage
|
||||
inline Dictionary gGlobalVars;
|
||||
|
||||
typedef Dictionary ConsoleFrame;
|
||||
typedef Vector<ConsoleFrame*> ConsoleStack;
|
||||
|
||||
inline ConsoleStack gFrameStack;
|
||||
|
||||
inline ConsoleStack getFrameStack() { return gFrameStack; }
|
||||
inline void pushStackFrame(ConsoleFrame* frame) { gFrameStack.push_back(frame); }
|
||||
inline ConsoleFrame* popStackFrame() { ConsoleFrame* last = gFrameStack.last(); gFrameStack.pop_back(); return last; }
|
||||
inline ConsoleFrame* getCurrentStackFrame() { return getFrameStack().empty() ? NULL : gFrameStack.last(); }
|
||||
inline ConsoleFrame* getStackFrame(S32 idx) { return gFrameStack[idx]; }
|
||||
|
||||
inline Vector<Con::Module*> gScriptModules;
|
||||
|
||||
inline Vector<Con::Module*> getAllScriptModules() { return gScriptModules; }
|
||||
Con::Module* findScriptModuleForFile(const char* fileName);
|
||||
// Convenience functions for getting the execution context
|
||||
inline const char* getCurrentScriptModulePath() { return getCurrentStackFrame() && getCurrentStackFrame()->module ? getCurrentStackFrame()->module->getPath() : NULL; }
|
||||
inline const char* getCurrentScriptModuleName() { return getCurrentStackFrame() && getCurrentStackFrame()->module ? getCurrentStackFrame()->module->getName() : NULL; }
|
||||
inline Con::Module* getCurrentScriptModule() { return getCurrentStackFrame() ? getCurrentStackFrame()->module : NULL; }
|
||||
|
||||
inline bool gTraceOn;
|
||||
}
|
||||
|
||||
/// @}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue