mirror of
https://github.com/4ian/GDevelop.git
synced 2025-10-15 10:19:04 +00:00
Compare commits
3 Commits
40c576bc2d
...
experiment
Author | SHA1 | Date | |
---|---|---|---|
![]() |
f21569269c | ||
![]() |
d98e0622c2 | ||
![]() |
a0ffc5fe8d |
@@ -273,8 +273,6 @@ gd::String EventsCodeGenerator::GenerateConditionCode(
|
||||
|
||||
if (instrInfos.codeExtraInformation.HasCustomCodeGenerator()) {
|
||||
context.EnterCustomCondition();
|
||||
conditionCode += GenerateReferenceToUpperScopeBoolean(
|
||||
"conditionTrue", returnBoolean, context);
|
||||
conditionCode += instrInfos.codeExtraInformation.customCodeGenerator(
|
||||
condition, *this, context);
|
||||
maxCustomConditionsDepth =
|
||||
|
@@ -404,6 +404,18 @@ class GD_CORE_API EventsCodeGenerator {
|
||||
return boolName;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Generate the full name for accessing to a boolean variable used for
|
||||
* conditions.
|
||||
*
|
||||
* Default implementation just returns the boolean name passed as argument.
|
||||
*/
|
||||
virtual gd::String GenerateUpperScopeBooleanFullName(
|
||||
const gd::String& boolName,
|
||||
const gd::EventsCodeGenerationContext& context) {
|
||||
return boolName;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Must create a boolean. Its value must be false.
|
||||
*
|
||||
@@ -665,19 +677,6 @@ class GD_CORE_API EventsCodeGenerator {
|
||||
return "!(" + predicat + ")";
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Must create a boolean which is a reference to a boolean declared in
|
||||
* the parent scope.
|
||||
*
|
||||
* The default implementation generates C-style code.
|
||||
*/
|
||||
virtual gd::String GenerateReferenceToUpperScopeBoolean(
|
||||
const gd::String& referenceName,
|
||||
const gd::String& referencedBoolean,
|
||||
gd::EventsCodeGenerationContext& context) {
|
||||
return "bool & " + referenceName + " = " + referencedBoolean + ";\n";
|
||||
}
|
||||
|
||||
virtual gd::String GenerateFreeCondition(
|
||||
const std::vector<gd::String>& arguments,
|
||||
const gd::InstructionMetadata& instrInfos,
|
||||
|
@@ -65,16 +65,11 @@ gd::String EventsCodeGenerator::GenerateEventsListCompleteFunctionCode(
|
||||
gd::String globalObjectLists = allObjectsDeclarationsAndResets.first;
|
||||
gd::String globalObjectListsReset = allObjectsDeclarationsAndResets.second;
|
||||
|
||||
// "Booleans" used by conditions
|
||||
gd::String globalConditionsBooleans =
|
||||
codeGenerator.GenerateAllConditionsBooleanDeclarations();
|
||||
|
||||
gd::String output =
|
||||
// clang-format off
|
||||
codeGenerator.GetCodeNamespace() + " = {};\n" +
|
||||
globalDeclarations +
|
||||
globalObjectLists + "\n" +
|
||||
globalConditionsBooleans + "\n\n" +
|
||||
globalObjectLists + "\n\n" +
|
||||
codeGenerator.GetCustomCodeOutsideMain() + "\n\n" +
|
||||
fullyQualifiedFunctionName + " = function(" +
|
||||
functionArgumentsCode +
|
||||
@@ -639,21 +634,6 @@ EventsCodeGenerator::GenerateAllObjectsDeclarationsAndResets(
|
||||
return std::make_pair(globalObjectLists, globalObjectListsReset);
|
||||
}
|
||||
|
||||
gd::String EventsCodeGenerator::GenerateAllConditionsBooleanDeclarations() {
|
||||
gd::String globalConditionsBooleans;
|
||||
for (unsigned int i = 0; i <= GetMaxCustomConditionsDepth(); ++i) {
|
||||
globalConditionsBooleans += GetCodeNamespaceAccessor() + "conditionTrue_" +
|
||||
gd::String::From(i) + " = {val:false};\n";
|
||||
for (std::size_t j = 0; j <= GetMaxConditionsListsSize(); ++j) {
|
||||
globalConditionsBooleans += GetCodeNamespaceAccessor() + "condition" +
|
||||
gd::String::From(j) + "IsTrue_" +
|
||||
gd::String::From(i) + " = {val:false};\n";
|
||||
}
|
||||
}
|
||||
|
||||
return globalConditionsBooleans;
|
||||
}
|
||||
|
||||
gd::String EventsCodeGenerator::GenerateObjectFunctionCall(
|
||||
gd::String objectListName,
|
||||
const gd::ObjectMetadata& objMetadata,
|
||||
@@ -729,7 +709,7 @@ gd::String EventsCodeGenerator::GenerateFreeCondition(
|
||||
|
||||
// Generate condition code
|
||||
return GenerateBooleanFullName(returnBoolean, context) +
|
||||
".val = " + predicat + ";\n";
|
||||
" = " + predicat + ";\n";
|
||||
}
|
||||
|
||||
gd::String EventsCodeGenerator::GenerateObjectCondition(
|
||||
@@ -761,18 +741,18 @@ gd::String EventsCodeGenerator::GenerateObjectCondition(
|
||||
|
||||
// Generate whole condition code
|
||||
conditionCode +=
|
||||
"for(var i = 0, k = 0, l = " + GetObjectListName(objectName, context) +
|
||||
"for (var i = 0, k = 0, l = " + GetObjectListName(objectName, context) +
|
||||
".length;i<l;++i) {\n";
|
||||
conditionCode += " if ( " + predicat + " ) {\n";
|
||||
conditionCode += " " +
|
||||
GenerateBooleanFullName(returnBoolean, context) +
|
||||
".val = true;\n";
|
||||
" = true;\n";
|
||||
conditionCode += " " + GetObjectListName(objectName, context) +
|
||||
"[k] = " + GetObjectListName(objectName, context) + "[i];\n";
|
||||
conditionCode += " ++k;\n";
|
||||
conditionCode += " }\n";
|
||||
conditionCode += "}\n";
|
||||
conditionCode += GetObjectListName(objectName, context) + ".length = k;";
|
||||
conditionCode += GetObjectListName(objectName, context) + ".length = k;\n";
|
||||
|
||||
return conditionCode;
|
||||
}
|
||||
@@ -816,19 +796,19 @@ gd::String EventsCodeGenerator::GenerateBehaviorCondition(
|
||||
<< "\" (condition: " << instrInfos.GetFullName() << ")." << endl;
|
||||
} else {
|
||||
conditionCode +=
|
||||
"for(var i = 0, k = 0, l = " + GetObjectListName(objectName, context) +
|
||||
"for (var i = 0, k = 0, l = " + GetObjectListName(objectName, context) +
|
||||
".length;i<l;++i) {\n";
|
||||
conditionCode += " if ( " + predicat + " ) {\n";
|
||||
conditionCode += " " +
|
||||
GenerateBooleanFullName(returnBoolean, context) +
|
||||
".val = true;\n";
|
||||
" = true;\n";
|
||||
conditionCode += " " + GetObjectListName(objectName, context) +
|
||||
"[k] = " + GetObjectListName(objectName, context) +
|
||||
"[i];\n";
|
||||
conditionCode += " ++k;\n";
|
||||
conditionCode += " }\n";
|
||||
conditionCode += "}\n";
|
||||
conditionCode += GetObjectListName(objectName, context) + ".length = k;";
|
||||
conditionCode += GetObjectListName(objectName, context) + ".length = k;\n";
|
||||
}
|
||||
|
||||
return conditionCode;
|
||||
@@ -1096,29 +1076,26 @@ gd::String EventsCodeGenerator::GenerateConditionsListCode(
|
||||
gd::EventsCodeGenerationContext& context) {
|
||||
gd::String outputCode;
|
||||
|
||||
for (std::size_t i = 0; i < conditions.size(); ++i)
|
||||
outputCode += GenerateBooleanInitializationToFalse(
|
||||
"condition" + gd::String::From(i) + "IsTrue", context);
|
||||
"isConditionTrue", context);
|
||||
|
||||
for (std::size_t cId = 0; cId < conditions.size(); ++cId) {
|
||||
if (cId != 0)
|
||||
outputCode +=
|
||||
"if ( " +
|
||||
GenerateBooleanFullName(
|
||||
"condition" + gd::String::From(cId - 1) + "IsTrue", context) +
|
||||
".val ) {\n";
|
||||
|
||||
if (cId != 0) {
|
||||
outputCode += "if (" +
|
||||
GenerateBooleanFullName("isConditionTrue", context) +
|
||||
") {\n";
|
||||
}
|
||||
gd::String conditionCode =
|
||||
GenerateConditionCode(conditions[cId],
|
||||
"condition" + gd::String::From(cId) + "IsTrue",
|
||||
"isConditionTrue",
|
||||
context);
|
||||
if (!conditions[cId].GetType().empty()) {
|
||||
outputCode += "{\n";
|
||||
outputCode +=
|
||||
GenerateBooleanFullName("isConditionTrue", context) + " = false;\n";
|
||||
outputCode += conditionCode;
|
||||
outputCode += "}";
|
||||
}
|
||||
}
|
||||
|
||||
// Close nested "if".
|
||||
for (std::size_t cId = 0; cId < conditions.size(); ++cId) {
|
||||
if (cId != 0) outputCode += "}\n";
|
||||
}
|
||||
@@ -1331,29 +1308,27 @@ gd::String EventsCodeGenerator::GenerateGetVariable(
|
||||
return output;
|
||||
}
|
||||
|
||||
gd::String EventsCodeGenerator::GenerateReferenceToUpperScopeBoolean(
|
||||
const gd::String& referenceName,
|
||||
const gd::String& referencedBoolean,
|
||||
gd::EventsCodeGenerationContext& context) {
|
||||
gd::String EventsCodeGenerator::GenerateUpperScopeBooleanFullName(
|
||||
const gd::String& boolName,
|
||||
const gd::EventsCodeGenerationContext& context) {
|
||||
if (context.GetCurrentConditionDepth() <= 0)
|
||||
return "/* Code generation error: the referenced boolean can't exist as "
|
||||
"the context has a condition depth of 0. */";
|
||||
|
||||
return GenerateBooleanFullName(referenceName, context) + " = " +
|
||||
GetCodeNamespaceAccessor() + referencedBoolean + "_" +
|
||||
gd::String::From(context.GetCurrentConditionDepth() - 1) + ";\n";
|
||||
return boolName + "_" +
|
||||
gd::String::From(context.GetCurrentConditionDepth() - 1);
|
||||
}
|
||||
|
||||
gd::String EventsCodeGenerator::GenerateBooleanInitializationToFalse(
|
||||
const gd::String& boolName,
|
||||
const gd::EventsCodeGenerationContext& context) {
|
||||
return GenerateBooleanFullName(boolName, context) + ".val = false;\n";
|
||||
return "let " + GenerateBooleanFullName(boolName, context) + " = false;\n";
|
||||
}
|
||||
|
||||
gd::String EventsCodeGenerator::GenerateBooleanFullName(
|
||||
const gd::String& boolName,
|
||||
const gd::EventsCodeGenerationContext& context) {
|
||||
return GetCodeNamespaceAccessor() + boolName + "_" +
|
||||
return boolName + "_" +
|
||||
gd::String::From(context.GetCurrentConditionDepth());
|
||||
}
|
||||
|
||||
|
@@ -170,6 +170,14 @@ class EventsCodeGenerator : public gd::EventsCodeGenerator {
|
||||
const gd::String& boolName,
|
||||
const gd::EventsCodeGenerationContext& context);
|
||||
|
||||
/**
|
||||
* \brief Generate the full name for accessing to a boolean variable used for
|
||||
* conditions.
|
||||
*/
|
||||
virtual gd::String GenerateUpperScopeBooleanFullName(
|
||||
const gd::String& boolName,
|
||||
const gd::EventsCodeGenerationContext& context);
|
||||
|
||||
/**
|
||||
* \brief Set a boolean to false.
|
||||
*/
|
||||
@@ -315,11 +323,6 @@ class EventsCodeGenerator : public gd::EventsCodeGenerator {
|
||||
return "!(" + predicat + ")";
|
||||
};
|
||||
|
||||
virtual gd::String GenerateReferenceToUpperScopeBoolean(
|
||||
const gd::String& referenceName,
|
||||
const gd::String& referencedBoolean,
|
||||
gd::EventsCodeGenerationContext& context);
|
||||
|
||||
virtual gd::String GenerateObjectsDeclarationCode(
|
||||
gd::EventsCodeGenerationContext& context);
|
||||
|
||||
|
@@ -83,8 +83,8 @@ AdvancedExtension::AdvancedExtension() {
|
||||
"!!eventsFunctionContext.getArgument(" +
|
||||
parameterNameCode + ") : false)";
|
||||
gd::String outputCode =
|
||||
codeGenerator.GenerateBooleanFullName("conditionTrue", context) +
|
||||
".val = " + valueCode + ";\n";
|
||||
codeGenerator.GenerateUpperScopeBooleanFullName("isConditionTrue", context) +
|
||||
" = " + valueCode + ";\n";
|
||||
return outputCode;
|
||||
});
|
||||
|
||||
@@ -141,8 +141,7 @@ AdvancedExtension::AdvancedExtension() {
|
||||
instruction.GetParameter(2).GetPlainString());
|
||||
|
||||
gd::String resultingBoolean =
|
||||
codeGenerator.GenerateBooleanFullName("conditionTrue", context) +
|
||||
".val";
|
||||
codeGenerator.GenerateUpperScopeBooleanFullName("isConditionTrue", context);
|
||||
|
||||
return resultingBoolean + " = ((typeof eventsFunctionContext !== 'undefined' ? "
|
||||
"Number(eventsFunctionContext.getArgument(" +
|
||||
@@ -169,8 +168,7 @@ AdvancedExtension::AdvancedExtension() {
|
||||
instruction.GetParameter(2).GetPlainString());
|
||||
|
||||
gd::String resultingBoolean =
|
||||
codeGenerator.GenerateBooleanFullName("conditionTrue", context) +
|
||||
".val";
|
||||
codeGenerator.GenerateUpperScopeBooleanFullName("isConditionTrue", context);
|
||||
|
||||
return resultingBoolean + " = ((typeof eventsFunctionContext !== 'undefined' ? "
|
||||
"\"\" + eventsFunctionContext.getArgument(" +
|
||||
|
@@ -68,8 +68,7 @@ CommonInstructionsExtension::CommonInstructionsExtension() {
|
||||
instruction.GetParameter(2).GetPlainString());
|
||||
|
||||
gd::String resultingBoolean =
|
||||
codeGenerator.GenerateBooleanFullName("conditionTrue", context) +
|
||||
".val";
|
||||
codeGenerator.GenerateUpperScopeBooleanFullName("isConditionTrue", context);
|
||||
|
||||
return resultingBoolean + " = (" + value1Code + " " + operatorCode +
|
||||
" " + value2Code + ");\n";
|
||||
@@ -99,8 +98,7 @@ CommonInstructionsExtension::CommonInstructionsExtension() {
|
||||
instruction.GetParameter(2).GetPlainString());
|
||||
|
||||
gd::String resultingBoolean =
|
||||
codeGenerator.GenerateBooleanFullName("conditionTrue", context) +
|
||||
".val";
|
||||
codeGenerator.GenerateUpperScopeBooleanFullName("isConditionTrue", context);
|
||||
|
||||
return resultingBoolean + " = (" + value1Code + " " + operatorCode +
|
||||
" " + value2Code + ");\n";
|
||||
@@ -139,11 +137,8 @@ CommonInstructionsExtension::CommonInstructionsExtension() {
|
||||
event.GetConditions().empty()
|
||||
? ""
|
||||
: codeGenerator.GenerateBooleanFullName(
|
||||
"condition" +
|
||||
gd::String::From(event.GetConditions().size() - 1) +
|
||||
"IsTrue",
|
||||
context) +
|
||||
".val";
|
||||
"isConditionTrue",
|
||||
context);
|
||||
|
||||
gd::EventsCodeGenerationContext actionsContext;
|
||||
actionsContext.Reuse(context);
|
||||
@@ -189,6 +184,11 @@ CommonInstructionsExtension::CommonInstructionsExtension() {
|
||||
gd::String conditionsCode;
|
||||
gd::InstructionsList& conditions = instruction.GetSubInstructions();
|
||||
|
||||
// The Or "return" true by setting the upper boolean to true.
|
||||
// So, it needs to be initialized to false.
|
||||
conditionsCode += codeGenerator.GenerateUpperScopeBooleanFullName(
|
||||
"isConditionTrue", parentContext) +
|
||||
" = false;\n";
|
||||
//"OR" condition must declare objects list, but without picking the
|
||||
// objects from the scene. Lists are either empty or come from a
|
||||
// parent event.
|
||||
@@ -203,7 +203,7 @@ CommonInstructionsExtension::CommonInstructionsExtension() {
|
||||
|
||||
gd::String conditionCode = codeGenerator.GenerateConditionCode(
|
||||
conditions[cId],
|
||||
"condition" + gd::String::From(cId) + "IsTrue",
|
||||
"isConditionTrue",
|
||||
context);
|
||||
|
||||
conditionsCode += "{\n";
|
||||
@@ -217,14 +217,14 @@ CommonInstructionsExtension::CommonInstructionsExtension() {
|
||||
// If the condition is true : merge all objects picked in the
|
||||
// final object lists.
|
||||
conditionsCode +=
|
||||
"if( " +
|
||||
"if(" +
|
||||
codeGenerator.GenerateBooleanFullName(
|
||||
"condition" + gd::String::From(cId) + "IsTrue", context) +
|
||||
".val ) {\n";
|
||||
"isConditionTrue", context) +
|
||||
") {\n";
|
||||
conditionsCode += " " +
|
||||
codeGenerator.GenerateBooleanFullName(
|
||||
"conditionTrue", context) +
|
||||
".val = true;\n";
|
||||
codeGenerator.GenerateUpperScopeBooleanFullName(
|
||||
"isConditionTrue", context) +
|
||||
" = true;\n";
|
||||
std::set<gd::String> objectsListsToBeDeclared =
|
||||
context.GetAllObjectsToBeDeclared();
|
||||
for (set<gd::String>::iterator it =
|
||||
@@ -240,8 +240,8 @@ CommonInstructionsExtension::CommonInstructionsExtension() {
|
||||
gd::String::From(parentContext.GetContextDepth()) + "_" +
|
||||
gd::String::From(parentContext.GetCurrentConditionDepth()) +
|
||||
"final";
|
||||
conditionsCode += " for(var j = 0, jLen = " + objList +
|
||||
".length;j<jLen;++j) {\n";
|
||||
conditionsCode += " for (let j = 0, jLen = " + objList +
|
||||
".length; j < jLen ; ++j) {\n";
|
||||
conditionsCode += " if ( " + finalObjList + ".indexOf(" +
|
||||
objList + "[j]) === -1 )\n";
|
||||
conditionsCode += " " + finalObjList + ".push(" +
|
||||
@@ -274,14 +274,12 @@ CommonInstructionsExtension::CommonInstructionsExtension() {
|
||||
gd::String::From(parentContext.GetCurrentConditionDepth()) +
|
||||
"final";
|
||||
codeGenerator.AddGlobalDeclaration(finalObjList + " = [];\n");
|
||||
declarationsCode += finalObjList + ".length = 0;";
|
||||
declarationsCode += finalObjList + ".length = 0;\n";
|
||||
}
|
||||
for (unsigned int i = 0; i < conditions.size(); ++i)
|
||||
declarationsCode +=
|
||||
codeGenerator.GenerateBooleanFullName(
|
||||
"condition" + gd::String::From(i) + "IsTrue",
|
||||
parentContext) +
|
||||
".val = false;\n";
|
||||
declarationsCode += "let " +
|
||||
codeGenerator.GenerateBooleanFullName(
|
||||
"isConditionTrue", parentContext) +
|
||||
" = false;\n";
|
||||
|
||||
// Generate code
|
||||
gd::String code;
|
||||
@@ -318,77 +316,33 @@ CommonInstructionsExtension::CommonInstructionsExtension() {
|
||||
outputCode += codeGenerator.GenerateConditionsListCode(
|
||||
instruction.GetSubInstructions(), parentContext);
|
||||
|
||||
gd::String predicat = "true";
|
||||
for (unsigned int i = 0;
|
||||
i < instruction.GetSubInstructions().size();
|
||||
++i)
|
||||
predicat += " && " +
|
||||
outputCode += codeGenerator.GenerateUpperScopeBooleanFullName(
|
||||
"isConditionTrue", parentContext) +
|
||||
" = " +
|
||||
codeGenerator.GenerateBooleanFullName(
|
||||
"condition" + gd::String::From(i) + "IsTrue",
|
||||
parentContext) +
|
||||
".val";
|
||||
|
||||
outputCode += codeGenerator.GenerateBooleanFullName("conditionTrue",
|
||||
parentContext) +
|
||||
".val = " + predicat + ";\n";
|
||||
"isConditionTrue", parentContext) +
|
||||
";\n";
|
||||
|
||||
return outputCode;
|
||||
});
|
||||
|
||||
GetAllConditions()["BuiltinCommonInstructions::Not"]
|
||||
.codeExtraInformation.SetCustomCodeGenerator(
|
||||
[](gd::Instruction& instruction,
|
||||
gd::EventsCodeGenerator& codeGenerator,
|
||||
gd::EventsCodeGenerationContext& context) {
|
||||
gd::InstructionsList& conditions = instruction.GetSubInstructions();
|
||||
[](gd::Instruction &instruction,
|
||||
gd::EventsCodeGenerator &codeGenerator,
|
||||
gd::EventsCodeGenerationContext &parentContext) {
|
||||
gd::String outputCode;
|
||||
|
||||
for (unsigned int i = 0; i < conditions.size(); ++i) {
|
||||
outputCode +=
|
||||
codeGenerator.GenerateBooleanFullName(
|
||||
"condition" + gd::String::From(i) + "IsTrue", context) +
|
||||
".val = false;\n";
|
||||
}
|
||||
outputCode += codeGenerator.GenerateConditionsListCode(
|
||||
instruction.GetSubInstructions(), parentContext);
|
||||
|
||||
for (unsigned int cId = 0; cId < conditions.size(); ++cId) {
|
||||
if (cId != 0)
|
||||
outputCode +=
|
||||
"if ( !" +
|
||||
codeGenerator.GenerateBooleanFullName(
|
||||
"condition" + gd::String::From(cId - 1) + "IsTrue",
|
||||
context) +
|
||||
".val ) {\n";
|
||||
|
||||
const gd::InstructionMetadata& instrInfos =
|
||||
gd::MetadataProvider::GetConditionMetadata(
|
||||
codeGenerator.GetPlatform(), conditions[cId].GetType());
|
||||
|
||||
gd::String conditionCode = codeGenerator.GenerateConditionCode(
|
||||
conditions[cId],
|
||||
"condition" + gd::String::From(cId) + "IsTrue",
|
||||
context);
|
||||
if (!conditions[cId].GetType().empty()) {
|
||||
outputCode += "{\n";
|
||||
outputCode += conditionCode;
|
||||
outputCode += "}";
|
||||
}
|
||||
}
|
||||
|
||||
for (unsigned int cId = 0; cId < conditions.size(); ++cId) {
|
||||
if (cId != 0) outputCode += "}\n";
|
||||
}
|
||||
|
||||
if (!conditions.empty()) {
|
||||
outputCode += codeGenerator.GenerateBooleanFullName(
|
||||
"conditionTrue", context) +
|
||||
".val = !";
|
||||
outputCode +=
|
||||
codeGenerator.GenerateBooleanFullName(
|
||||
"condition" + gd::String::From(conditions.size() - 1) +
|
||||
"IsTrue",
|
||||
context) +
|
||||
".val;\n";
|
||||
}
|
||||
outputCode += codeGenerator.GenerateUpperScopeBooleanFullName(
|
||||
"isConditionTrue", parentContext) +
|
||||
" = !" +
|
||||
codeGenerator.GenerateBooleanFullName(
|
||||
"isConditionTrue", parentContext) +
|
||||
";\n";
|
||||
;
|
||||
|
||||
return outputCode;
|
||||
});
|
||||
@@ -400,9 +354,9 @@ CommonInstructionsExtension::CommonInstructionsExtension() {
|
||||
gd::EventsCodeGenerationContext& context) {
|
||||
size_t uniqueId = codeGenerator.GenerateSingleUsageUniqueIdFor(
|
||||
instruction.GetOriginalInstruction().lock().get());
|
||||
gd::String outputCode = codeGenerator.GenerateBooleanFullName(
|
||||
"conditionTrue", context) +
|
||||
".val = ";
|
||||
gd::String outputCode = codeGenerator.GenerateUpperScopeBooleanFullName(
|
||||
"isConditionTrue", context) +
|
||||
" = ";
|
||||
gd::String contextObjectName = codeGenerator.HasProjectAndLayout()
|
||||
? "runtimeScene"
|
||||
: "eventsFunctionContext";
|
||||
@@ -440,12 +394,7 @@ CommonInstructionsExtension::CommonInstructionsExtension() {
|
||||
gd::String whileIfPredicat = "true";
|
||||
if (!event.GetWhileConditions().empty())
|
||||
whileIfPredicat =
|
||||
codeGenerator.GenerateBooleanFullName(
|
||||
"condition" +
|
||||
gd::String::From(event.GetWhileConditions().size() - 1) +
|
||||
"IsTrue",
|
||||
context) +
|
||||
".val";
|
||||
codeGenerator.GenerateBooleanFullName("isConditionTrue", context);
|
||||
|
||||
gd::String conditionsCode = codeGenerator.GenerateConditionsListCode(
|
||||
event.GetConditions(), context);
|
||||
@@ -454,20 +403,13 @@ CommonInstructionsExtension::CommonInstructionsExtension() {
|
||||
gd::String ifPredicat = "true";
|
||||
if (!event.GetConditions().empty())
|
||||
ifPredicat =
|
||||
codeGenerator.GenerateBooleanFullName(
|
||||
"condition" +
|
||||
gd::String::From(event.GetConditions().size() - 1) +
|
||||
"IsTrue",
|
||||
context) +
|
||||
".val";
|
||||
codeGenerator.GenerateBooleanFullName("isConditionTrue", context);
|
||||
|
||||
// Write final code
|
||||
gd::String whileBoolean = codeGenerator.GetCodeNamespaceAccessor() +
|
||||
"stopDoWhile" +
|
||||
gd::String::From(context.GetContextDepth());
|
||||
codeGenerator.AddGlobalDeclaration(whileBoolean + " = false;\n");
|
||||
outputCode += whileBoolean + " = false;\n";
|
||||
outputCode += "do {";
|
||||
gd::String whileBoolean =
|
||||
codeGenerator.GenerateBooleanFullName("stopDoWhile", context);
|
||||
outputCode += "let " + whileBoolean + " = false;\n";
|
||||
outputCode += "do {\n";
|
||||
outputCode += codeGenerator.GenerateObjectsDeclarationCode(context);
|
||||
outputCode += whileConditionsStr;
|
||||
outputCode += "if (" + whileIfPredicat + ") {\n";
|
||||
@@ -483,7 +425,7 @@ CommonInstructionsExtension::CommonInstructionsExtension() {
|
||||
outputCode += "}\n";
|
||||
outputCode += "} else " + whileBoolean + " = true; \n";
|
||||
|
||||
outputCode += "} while ( !" + whileBoolean + " );\n";
|
||||
outputCode += "} while (!" + whileBoolean + ");\n";
|
||||
|
||||
return outputCode;
|
||||
});
|
||||
@@ -506,15 +448,10 @@ CommonInstructionsExtension::CommonInstructionsExtension() {
|
||||
event.GetConditions(), context);
|
||||
gd::String actionsCode =
|
||||
codeGenerator.GenerateActionsListCode(event.GetActions(), context);
|
||||
gd::String ifPredicat =
|
||||
event.GetConditions().empty()
|
||||
? "true"
|
||||
: codeGenerator.GenerateBooleanFullName(
|
||||
"condition" +
|
||||
gd::String::From(event.GetConditions().size() - 1) +
|
||||
"IsTrue",
|
||||
context) +
|
||||
".val";
|
||||
gd::String ifPredicat = event.GetConditions().empty()
|
||||
? "true"
|
||||
: codeGenerator.GenerateBooleanFullName(
|
||||
"isConditionTrue", context);
|
||||
|
||||
// Prepare object declaration and sub events
|
||||
gd::String subevents =
|
||||
@@ -679,12 +616,7 @@ CommonInstructionsExtension::CommonInstructionsExtension() {
|
||||
gd::String ifPredicat = "true";
|
||||
if (!event.GetConditions().empty())
|
||||
ifPredicat =
|
||||
codeGenerator.GenerateBooleanFullName(
|
||||
"condition" +
|
||||
gd::String::From(event.GetConditions().size() - 1) +
|
||||
"IsTrue",
|
||||
context) +
|
||||
".val";
|
||||
codeGenerator.GenerateBooleanFullName("isConditionTrue", context);
|
||||
|
||||
// Prepare object declaration and sub events
|
||||
gd::String subevents =
|
||||
@@ -693,16 +625,12 @@ CommonInstructionsExtension::CommonInstructionsExtension() {
|
||||
codeGenerator.GenerateObjectsDeclarationCode(context) + "\n";
|
||||
|
||||
// Write final code
|
||||
gd::String repeatCountVar = codeGenerator.GetCodeNamespaceAccessor() +
|
||||
"repeatCount" +
|
||||
gd::String::From(context.GetContextDepth());
|
||||
codeGenerator.AddGlobalDeclaration(repeatCountVar + " = 0;\n");
|
||||
gd::String repeatIndexVar = codeGenerator.GetCodeNamespaceAccessor() +
|
||||
"repeatIndex" +
|
||||
gd::String::From(context.GetContextDepth());
|
||||
codeGenerator.AddGlobalDeclaration(repeatIndexVar + " = 0;\n");
|
||||
outputCode += repeatCountVar + " = " + repeatCountCode + ";\n";
|
||||
outputCode += "for(" + repeatIndexVar + " = 0;" + repeatIndexVar +
|
||||
gd::String repeatCountVar =
|
||||
"repeatCount" + gd::String::From(context.GetContextDepth());
|
||||
gd::String repeatIndexVar =
|
||||
"repeatIndex" + gd::String::From(context.GetContextDepth());
|
||||
outputCode += "const " + repeatCountVar + " = " + repeatCountCode + ";\n";
|
||||
outputCode += "for (let " + repeatIndexVar + " = 0;" + repeatIndexVar +
|
||||
" < " + repeatCountVar + ";++" + repeatIndexVar + ") {\n";
|
||||
outputCode += objectDeclaration;
|
||||
outputCode += conditionsCode;
|
||||
@@ -752,12 +680,7 @@ CommonInstructionsExtension::CommonInstructionsExtension() {
|
||||
gd::String ifPredicat = "true";
|
||||
if (!event.GetConditions().empty())
|
||||
ifPredicat =
|
||||
codeGenerator.GenerateBooleanFullName(
|
||||
"condition" +
|
||||
gd::String::From(event.GetConditions().size() - 1) +
|
||||
"IsTrue",
|
||||
context) +
|
||||
".val";
|
||||
codeGenerator.GenerateBooleanFullName("isConditionTrue", context);
|
||||
|
||||
// Prepare object declaration and sub events
|
||||
gd::String subevents =
|
||||
@@ -812,11 +735,11 @@ CommonInstructionsExtension::CommonInstructionsExtension() {
|
||||
1) // We write a slighty more simple ( and optimized ) output code
|
||||
// when only one object list is used.
|
||||
outputCode +=
|
||||
"for(" + forEachIndexVar + " = 0;" + forEachIndexVar + " < " +
|
||||
"for (" + forEachIndexVar + " = 0;" + forEachIndexVar + " < " +
|
||||
codeGenerator.GetObjectListName(realObjects[0], parentContext) +
|
||||
".length;++" + forEachIndexVar + ") {\n";
|
||||
else
|
||||
outputCode += "for(" + forEachIndexVar + " = 0;" + forEachIndexVar +
|
||||
outputCode += "for (" + forEachIndexVar + " = 0;" + forEachIndexVar +
|
||||
" < " + forEachTotalCountVar + ";++" + forEachIndexVar +
|
||||
") {\n";
|
||||
|
||||
|
@@ -390,8 +390,7 @@ describe('libGD.js - GDJS Boolean Operator Code Generation integration tests', (
|
||||
[false, true].forEach((a) => {
|
||||
[false, true].forEach((b) => {
|
||||
const result = !(a && b);
|
||||
// TODO Fix the Not condition.
|
||||
it.skip(`can generate a Not: !(${a} && ${b}) is ${result}`, function () {
|
||||
it(`can generate a Not: !(${a} && ${b}) is ${result}`, function () {
|
||||
const runtimeScene =
|
||||
generateAndRunVariableAffectationWithConditions([
|
||||
{
|
||||
@@ -474,8 +473,7 @@ describe('libGD.js - GDJS Boolean Operator Code Generation integration tests', (
|
||||
[false, true].forEach((a) => {
|
||||
[false, true].forEach((b) => {
|
||||
const result = !(a && !b);
|
||||
// TODO Fix the Not condition.
|
||||
it.skip(`can generate a Not of Not: !(${a} && !${b}) is ${result}`, function () {
|
||||
it(`can generate a Not of Not: !(${a} && !${b}) is ${result}`, function () {
|
||||
const runtimeScene =
|
||||
generateAndRunVariableAffectationWithConditions([
|
||||
{
|
||||
@@ -511,8 +509,7 @@ describe('libGD.js - GDJS Boolean Operator Code Generation integration tests', (
|
||||
[false, true].forEach((a) => {
|
||||
[false, true].forEach((b) => {
|
||||
const result = !(!a && b);
|
||||
// TODO Fix the Not condition.
|
||||
it.skip(`can generate a Not of Not: !(!${a} && ${b}) is ${result}`, function () {
|
||||
it(`can generate a Not of Not: !(!${a} && ${b}) is ${result}`, function () {
|
||||
const runtimeScene =
|
||||
generateAndRunVariableAffectationWithConditions([
|
||||
{
|
||||
|
Reference in New Issue
Block a user