Add FreeArray

This commit is contained in:
Vasilii Rogin 2023-04-20 02:46:24 +03:00
parent a93c7fba9e
commit 4662314839
6 changed files with 34 additions and 7 deletions

View File

@ -32,6 +32,7 @@
#include "scripts.h"
#include "selfrun.h"
#include "settings.h"
#include "sfall_arrays.h"
#include "sfall_config.h"
#include "svga.h"
#include "text_font.h"
@ -40,7 +41,6 @@
#include "window_manager_private.h"
#include "word_wrap.h"
#include "worldmap.h"
namespace fallout {
#define DEATH_WINDOW_WIDTH 640
@ -375,6 +375,8 @@ static void mainLoop()
renderPresent();
sharedFpsLimiter.throttle();
DeleteAllTempArrays();
}
scriptsDisable();

View File

@ -131,4 +131,17 @@ void SetArray(ArrayId array_id, const SFallScriptValue& key, const SFallScriptVa
}
}
void FreeArray(ArrayId array_id)
{
// TODO: remove from saved_arrays
arrays.erase(array_id);
}
void DeleteAllTempArrays()
{
for (auto it = temporaryArrays.begin(); it != temporaryArrays.end(); ++it) {
FreeArray(*it);
}
temporaryArrays.clear();
}
}

View File

@ -20,6 +20,7 @@ ProgramValue GetArrayKey(ArrayId array_id, int index);
int LenArray(ArrayId array_id);
ProgramValue GetArray(ArrayId array_id, const SFallScriptValue& key);
void SetArray(ArrayId array_id, const SFallScriptValue& key, const SFallScriptValue& val, bool allowUnset);
void FreeArray(ArrayId array_id);
void DeleteAllTempArrays();
}
#endif /* SFALL_ARRAYS */

View File

@ -304,9 +304,7 @@ static void opCreateArray(Program* program)
{
auto flags = programStackPopInteger(program);
auto len = programStackPopInteger(program);
auto array_id = CreateArray(len, flags);
programStackPushInteger(program, array_id);
}
@ -315,9 +313,7 @@ static void opTempArray(Program* program)
{
auto flags = programStackPopInteger(program);
auto len = programStackPopInteger(program);
auto array_id = CreateTempArray(len, flags);
programStackPushInteger(program, array_id);
}
@ -330,6 +326,13 @@ static void opGetArray(Program* program)
programStackPushValue(program, value);
}
// free_array
static void opFreeArray(Program* program)
{
auto arrayId = programStackPopInteger(program);
FreeArray(arrayId);
}
// len_array
static void opLenArray(Program* program)
{
@ -346,7 +349,7 @@ static void opPartyMemberList(Program* program)
for (int i = 0; i < LenArray(array_id); i++) {
SetArray(array_id, SFallScriptValue { i }, SFallScriptValue { objects[i] }, false);
}
programStackPushInteger(program, 100);
programStackPushInteger(program, array_id);
}
// round
@ -393,6 +396,7 @@ void sfallOpcodesInit()
interpreterRegisterOpcode(0x8221, opGetScreenHeight);
interpreterRegisterOpcode(0x822D, opCreateArray);
interpreterRegisterOpcode(0x822F, opGetArray);
interpreterRegisterOpcode(0x8230, opFreeArray);
interpreterRegisterOpcode(0x8231, opLenArray);
interpreterRegisterOpcode(0x8233, opTempArray);
interpreterRegisterOpcode(0x8237, opParseInt);

View File

@ -27,6 +27,11 @@ SFallScriptValue::SFallScriptValue(ProgramValue& value)
// TODO: If type is string then copy string
}
SFallScriptValue::~SFallScriptValue()
{
// TODO: If type is string then free it
}
bool SFallScriptValue::isInt() const
{
return opcode == VALUE_TYPE_INT;

View File

@ -16,6 +16,8 @@ public:
bool isFloat() const;
bool isPointer() const;
int asInt() const;
~SFallScriptValue();
};
}