Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
b689435
groundwork for vectors in script
marauder2k7 Sep 28, 2025
35cfd4a
more requirements
marauder2k7 Sep 29, 2025
23c3cd8
basic echo works
marauder2k7 Sep 29, 2025
8644863
fixes
marauder2k7 Sep 30, 2025
9aef7fc
backup commit before removal of array
marauder2k7 Sep 30, 2025
529a155
Assignment commit
marauder2k7 Oct 1, 2025
4d8db61
vector type
marauder2k7 Oct 1, 2025
b114126
everything working
marauder2k7 Oct 1, 2025
ff1d41e
nested vectors
marauder2k7 Oct 2, 2025
97fc1d7
cleanup and fixes
marauder2k7 Oct 2, 2025
f76c591
vector unit tests
marauder2k7 Oct 3, 2025
d43ebe8
Update astNodes.cpp
marauder2k7 Oct 3, 2025
63c410d
Update astNodes.cpp
marauder2k7 Oct 3, 2025
a38cd45
return conversion to opcode
marauder2k7 Oct 4, 2025
74805fd
working up to world editor
marauder2k7 Oct 4, 2025
2ac9eb0
fix
marauder2k7 Oct 5, 2025
c6ecb06
dont need to save
marauder2k7 Oct 5, 2025
2864417
Update astNodes.cpp
marauder2k7 Oct 5, 2025
65d8400
return conversion, when index outside vector return default values
marauder2k7 Oct 5, 2025
c87b83a
test union vec
marauder2k7 Oct 5, 2025
de58586
unit tests passing
marauder2k7 Oct 6, 2025
b6cea44
assign op and comments
marauder2k7 Oct 6, 2025
de630b4
Update astNodes.cpp
marauder2k7 Oct 6, 2025
cce7b67
Update ScriptTest.cpp
marauder2k7 Oct 6, 2025
576e9fa
vector now clears
marauder2k7 Oct 7, 2025
4b2f3aa
test with eval
marauder2k7 Oct 7, 2025
ea74dae
moar updated
marauder2k7 Oct 8, 2025
034cbe7
use shared_ptr
marauder2k7 Oct 8, 2025
d6b03c7
Update console.h
marauder2k7 Oct 8, 2025
ad9af5d
Update compiledEval.cpp
marauder2k7 Oct 8, 2025
de18464
idiot moment.....
marauder2k7 Oct 8, 2025
78abacd
Update compiledEval.cpp
marauder2k7 Oct 8, 2025
e7bda7d
Update compiledEval.cpp
marauder2k7 Oct 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions Engine/source/console/console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,28 @@ char* ConsoleValue::convertToBuffer() const
return buffer;
}

char* ConsoleValue::convertVectorToBuffer() const
{
if (!vec || vec->size() == 0)
return (char*)"";

// use FrameAllocator to avoid static overwrite
char* buffer = static_cast<char*>(sConversionAllocator.alloc(4096));
buffer[0] = 0;

for (U32 v = 0; v < vec->size(); v++)
{
const char* elemStr = (*vec)[v].getString();

if (v > 0)
dStrcat(buffer, " ", 4096);

dStrcat(buffer, elemStr, 4096);
}

return buffer;
}

const char* ConsoleValue::getConsoleData() const
{
return Con::getData(type, dataPtr, 0, enumTable);
Expand Down
95 changes: 89 additions & 6 deletions Engine/source/console/console.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@
#ifndef _REFBASE_H_
#include "core/util/refBase.h"
#endif
#ifndef __RESOURCE_H__
#include "core/resource.h"
#endif
#include <stdarg.h>

#include "core/util/str.h"
#include "core/util/journal/journaledSignal.h"
#include "core/stringTable.h"
Expand Down Expand Up @@ -120,12 +122,13 @@ typedef const char *StringTableEntry;

enum ConsoleValueType
{
cvNULL = -5,
cvNULL = -6,
cvVector = -5,
cvInteger = -4,
cvFloat = -3,
cvString = -2,
cvSTEntry = -1,
cvConsoleValueType = 0
cvConsoleValueType = 0,
};

class ConsoleValue
Expand All @@ -151,22 +154,29 @@ class ConsoleValue

S32 type;
U32 bufferLen;

std::shared_ptr<Vector<ConsoleValue>> vec;
static DataChunker sConversionAllocator;

char* convertToBuffer() const;
char* convertVectorToBuffer() const;

const char* getConsoleData() const;

TORQUE_FORCEINLINE void cleanupData()
{
if (type <= cvString && bufferLen > 0)
if (type <= ConsoleValueType::cvString && bufferLen > 0)
{
dFree(s);
bufferLen = 0;
}

s = const_cast<char*>(StringTable->EmptyString());

if (type == ConsoleValueType::cvVector)
{
vec.reset();
}

type = ConsoleValueType::cvNULL;
}
ConsoleValue()
Expand Down Expand Up @@ -199,6 +209,9 @@ class ConsoleValue
case cvString:
setString(ref.s);
break;
case cvVector:
setVector(ref.vec); // copy-by-reference, no ownership
break;
default:
setConsoleData(ref.type, ref.dataPtr, ref.enumTable);
break;
Expand All @@ -212,6 +225,9 @@ class ConsoleValue
case cvNULL:
std::cout << "Ref already cleared!";
break;
case cvVector:
setVector(ref.vec);
break;
case cvInteger:
setInt(ref.i);
break;
Expand Down Expand Up @@ -251,6 +267,8 @@ class ConsoleValue
return s == StringTable->EmptyString() ? 0.0f : dAtof(s);
if (type == ConsoleValueType::cvString)
return dStrcmp(s, "") == 0 ? 0.0f : dAtof(s);
if (type == ConsoleValueType::cvVector)
return vec->size();
return dAtof(getConsoleData());
}

Expand All @@ -264,16 +282,79 @@ class ConsoleValue
return s == StringTable->EmptyString() ? 0 : dAtoi(s);
if (type == ConsoleValueType::cvString)
return dStrcmp(s, "") == 0 ? 0 : dAtoi(s);

if (type == ConsoleValueType::cvVector)
return vec->size();
return dAtoi(getConsoleData());
}

TORQUE_FORCEINLINE void setVector(std::shared_ptr<Vector<ConsoleValue>> v)
{
cleanupData();
type = ConsoleValueType::cvVector;
vec = v;
}

TORQUE_FORCEINLINE std::shared_ptr<Vector<ConsoleValue>> getVector() const
{
if (type == cvVector)
return vec;

// Handle string or string table entry as a space-delimited vector
if (isNumberType() || isStringType())
{
if (type == cvString || type == cvSTEntry)
{
if (s == StringTable->EmptyString())
return NULL;
}

std::shared_ptr<Vector<ConsoleValue>> temp = std::make_shared<Vector<ConsoleValue>>();
if (isNumberType())
{
ConsoleValue elem;
if (type == cvFloat)
elem.setFloat(f);
else if (type == cvInteger)
elem.setInt(i);

temp->push_back(elem);
return temp;
}

if (type == cvString || type == cvSTEntry)
{
if (s == StringTable->EmptyString())
return NULL;

const char* str = s ? s : "";

char* buffer = dStrdup(str);
char* tok = dStrtok(buffer, " \t\r\n");

while (tok)
{
ConsoleValue elem;
elem.setString(tok);
temp->push_back(elem);
tok = dStrtok(NULL, " \t\r\n");
}

dFree(buffer);
return temp;
}
}

return NULL;
}

TORQUE_FORCEINLINE const char* getString() const
{
if (isStringType())
return s;
if (isNumberType())
return convertToBuffer();
if ((type == cvVector))
return convertVectorToBuffer();
return getConsoleData();
}

Expand All @@ -292,6 +373,8 @@ class ConsoleValue
return s == StringTable->EmptyString() ? false : dAtob(s);
if (type == ConsoleValueType::cvString)
return dStrcmp(s, "") == 0 ? false : dAtob(s);
if (type == ConsoleValueType::cvVector)
return vec->size() > 0;
return dAtob(getConsoleData());
}

Expand Down
27 changes: 27 additions & 0 deletions Engine/source/console/consoleInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,11 @@ class Dictionary
return value.getString();
}

inline std::shared_ptr<Vector<ConsoleValue>> getVectorValue()
{
return value.getVector();
}

void setIntValue(U32 val)
{
if (mIsConstant)
Expand Down Expand Up @@ -406,6 +411,28 @@ class Dictionary
if (notify)
notify->trigger();
}

void setVectorValue(std::shared_ptr<Vector<ConsoleValue>> val)
{
if (mIsConstant)
{
Con::errorf("Cannot assign value to constant '%s'.", name);
return;
}

if (value.isConsoleType())
{
Con::setData(value.type, value.dataPtr, 0, 1, NULL, value.enumTable); // null for now
}
else
{
value.setVector(val);
}

// Fire off the notification if we have one.
if (notify)
notify->trigger();
}
};

struct HashTableData
Expand Down
13 changes: 13 additions & 0 deletions Engine/source/console/torquescript/CMDgram.y
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,19 @@ expr
{ $$ = (ExprNode*)VarNode::alloc( $1.lineNumber, $1.value, NULL); }
| VAR '[' aidx_expr ']'
{ $$ = (ExprNode*)VarNode::alloc( $1.lineNumber, $1.value, $3 ); }
| expr '[' expr ']'
{ $$ = VectorIndexNode::alloc($1->dbgLineNumber, $1, $3); }
| '[' expr_list_decl ']'
{
Vector<ExprNode*> elems;
if ($2) {
// expr_list already chains ExprNodes using append(),
// so walk and collect them
for (ExprNode* e = $2; e; e = (ExprNode*)e->getNext())
elems.push_back(e);
}
$$ = VectorExprNode::alloc(@1.first_line, elems);
}
;
/*
| rwDEFINE '(' var_list_decl ')' '{' statement_list '}'
Expand Down
29 changes: 28 additions & 1 deletion Engine/source/console/torquescript/ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ enum TypeReq
TypeReqNone,
TypeReqUInt,
TypeReqFloat,
TypeReqString
TypeReqString,
TypeReqVector
};

enum ExprNodeName
Expand Down Expand Up @@ -134,6 +135,32 @@ struct ExprNode : StmtNode
virtual ExprNodeName getExprNodeNameEnum() const { return NameExprNode; }
};

struct VectorExprNode : ExprNode
{
Vector<ExprNode*> elements; ///< Elements of the vector literal

static VectorExprNode* alloc(S32 lineNumber, const Vector<ExprNode*>& elements);

U32 compile(CodeStream& codeStream, U32 ip, TypeReq type) override;
TypeReq getPreferredType() override { return TypeReqVector; }
DBG_STMT_TYPE(VectorExprNode);
};

struct VectorIndexNode : ExprNode
{
ExprNode* base;
ExprNode* index;

static VectorIndexNode* alloc(S32 lineNumber, ExprNode* b, ExprNode* i);

U32 compile(CodeStream& codeStream, U32 ip, TypeReq type) override;
TypeReq getPreferredType() override { return TypeReqNone; }
DBG_STMT_TYPE(VectorIndexNode);

ExprNode* getBase() const { return base; }
ExprNode* getIndex() const { return index; }
};

struct ReturnStmtNode : StmtNode
{
ExprNode* expr;
Expand Down
21 changes: 21 additions & 0 deletions Engine/source/console/torquescript/astAlloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,27 @@ using namespace Compiler;

//------------------------------------------------------------

VectorExprNode* VectorExprNode::alloc(S32 lineNumber, const Vector<ExprNode*>& elements)
{
VectorExprNode* ret = (VectorExprNode*)consoleAlloc(sizeof(VectorExprNode));
constructInPlace(ret);
ret->dbgLineNumber = lineNumber;
ret->optimizedNode = NULL;
ret->elements = elements;
return ret;
}

VectorIndexNode* VectorIndexNode::alloc(S32 lineNumber, ExprNode* b, ExprNode* i)
{
VectorIndexNode* ret = (VectorIndexNode*)consoleAlloc(sizeof(VectorIndexNode));
constructInPlace(ret);
ret->dbgLineNumber = lineNumber;
ret->optimizedNode = NULL;
ret->base = b;
ret->index = i;
return ret;
}

BreakStmtNode* BreakStmtNode::alloc(S32 lineNumber)
{
BreakStmtNode* ret = (BreakStmtNode*)consoleAlloc(sizeof(BreakStmtNode));
Expand Down
Loading
Loading