Reorganize files

This commit is contained in:
Vasilii Rogin 2023-04-20 02:23:33 +03:00
parent f01a3e3fbc
commit da814a6b76
6 changed files with 136 additions and 68 deletions

View File

@ -4,7 +4,7 @@ set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
set(EXECUTABLE_NAME fallout2-ce)
if (APPLE)
if(APPLE)
if(IOS)
set(CMAKE_OSX_DEPLOYMENT_TARGET "11" CACHE STRING "")
set(CMAKE_OSX_ARCHITECTURES "arm64" CACHE STRING "")
@ -20,7 +20,7 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED YES)
set(CMAKE_CXX_EXTENSIONS NO)
if (ANDROID)
if(ANDROID)
add_library(${EXECUTABLE_NAME} SHARED)
else()
add_executable(${EXECUTABLE_NAME} WIN32 MACOSX_BUNDLE)
@ -271,6 +271,10 @@ target_sources(${EXECUTABLE_NAME} PUBLIC
"src/sfall_lists.h"
"src/sfall_opcodes.cc"
"src/sfall_opcodes.h"
"src/sfall_script_value.cc"
"src/sfall_script_value.h"
"src/sfall_arrays.cc"
"src/sfall_arrays.h"
)
if(IOS)
@ -295,7 +299,7 @@ if(WIN32)
)
endif()
if (WIN32)
if(WIN32)
target_sources(${EXECUTABLE_NAME} PUBLIC
"os/windows/fallout2-ce.ico"
"os/windows/fallout2-ce.rc"
@ -356,7 +360,7 @@ if(APPLE)
"
COMPONENT Runtime)
if (CPACK_BUNDLE_APPLE_CERT_APP)
if(CPACK_BUNDLE_APPLE_CERT_APP)
install(CODE "
execute_process(COMMAND codesign --deep --force --options runtime --sign \"${CPACK_BUNDLE_APPLE_CERT_APP}\" ${CMAKE_BINARY_DIR}/${MACOSX_BUNDLE_BUNDLE_NAME}.app)
"

View File

@ -1,4 +1,7 @@
#include "sfall_arrays.h"
#include "interpreter.h"
#include "sfall_script_value.h"
#include <cstdint>
#include <stdexcept>
#include <unordered_map>
@ -7,67 +10,9 @@
namespace fallout {
using ArrayId = unsigned int;
static ArrayId nextArrayID = 1;
static ArrayId stackArrayId = 1;
class SFallScriptValue : public ProgramValue {
public:
SFallScriptValue()
{
opcode = VALUE_TYPE_INT;
integerValue = 0;
}
SFallScriptValue(int value)
{
opcode = VALUE_TYPE_INT;
integerValue = value;
}
SFallScriptValue(Object* value)
{
opcode = VALUE_TYPE_PTR;
pointerValue = value;
}
SFallScriptValue(ProgramValue& value)
{
// Assuming that pointer is the biggest in size
static_assert(sizeof(decltype(value.floatValue)) <= sizeof(decltype(value.pointerValue)));
static_assert(sizeof(decltype(value.integerValue)) <= sizeof(decltype(value.pointerValue)));
opcode = value.opcode;
pointerValue = value.pointerValue;
}
bool isInt() const
{
return opcode == VALUE_TYPE_INT;
}
bool isFloat() const
{
return opcode == VALUE_TYPE_FLOAT;
}
bool isPointer() const
{
return opcode == VALUE_TYPE_PTR;
}
int asInt() const
{
switch (opcode) {
case VALUE_TYPE_INT:
return integerValue;
case VALUE_TYPE_FLOAT:
return static_cast<int>(floatValue);
default:
return 0;
}
}
};
#define ARRAYFLAG_ASSOC (1) // is map
#define ARRAYFLAG_CONSTVAL (2) // don't update value of key if the key exists in map
#define ARRAYFLAG_RESERVED (4)
#define ARRAY_MAX_STRING (255) // maximum length of string to be stored as array key or value
#define ARRAY_MAX_SIZE (100000) // maximum number of array elements,
@ -100,7 +45,7 @@ ArrayId CreateArray(int len, uint32_t flags)
flags = (flags & ~1); // reset 1 bit
if (len < 0) {
flags |= ARRAYFLAG_ASSOC;
flags |= SFALL_ARRAYFLAG_ASSOC;
throw(std::invalid_argument("Not implemented yet"));
};
@ -171,4 +116,20 @@ ProgramValue GetArray(ArrayId array_id, ProgramValue key)
};
return arr->data[element_index];
}
void SetArray(ArrayId array_id, const SFallScriptValue& key, const SFallScriptValue& val, bool allowUnset)
{
auto arr = get_array_by_id(array_id);
if (arr == nullptr) {
return;
};
if (key.isInt()) {
auto index = key.asInt();
if (index >= 0 && index < arr->size()) {
arr->data[index] = key;
}
}
}
}

View File

@ -0,0 +1,25 @@
#ifndef SFALL_ARRAYS
#define SFALL_ARRAYS
#include "interpreter.h"
#include "object.h"
#include "sfall_script_value.h"
#include <cstdint>
namespace fallout {
#define SFALL_ARRAYFLAG_ASSOC (1) // is map
#define SFALL_ARRAYFLAG_CONSTVAL (2) // don't update value of key if the key exists in map
#define SFALL_ARRAYFLAG_RESERVED (4)
using ArrayId = unsigned int;
ArrayId CreateArray(int len, uint32_t flags);
ArrayId CreateTempArray(int len, uint32_t flags);
ProgramValue GetArrayKey(ArrayId array_id, int index);
int LenArray(ArrayId array_id);
ProgramValue GetArray(ArrayId array_id, ProgramValue key);
void SetArray(ArrayId array_id, const SFallScriptValue& key, const SFallScriptValue& val, bool allowUnset);
}
#endif /* SFALL_ARRAYS */

View File

@ -11,9 +11,10 @@
#include "mouse.h"
#include "object.h"
#include "party_member.h"
#include "sfall_arrays.cc"
#include "sfall_arrays.h"
#include "sfall_global_vars.h"
#include "sfall_lists.h"
#include "sfall_script_value.h"
#include "stat.h"
#include "svga.h"
#include <string.h>
@ -341,10 +342,9 @@ static void opPartyMemberList(Program* program)
{
auto includeHidden = programStackPopInteger(program);
auto objects = get_all_party_members_objects(includeHidden);
auto array_id = CreateTempArray(objects.size(), ARRAYFLAG_RESERVED);
auto arr = get_array_by_id(array_id);
for (int i = 0; i < arr->size(); i++) {
arr->data[i] = SFallScriptValue { objects[i] };
auto array_id = CreateTempArray(objects.size(), SFALL_ARRAYFLAG_RESERVED);
for (int i = 0; i < LenArray(array_id); i++) {
SetArray(array_id, SFallScriptValue { i }, SFallScriptValue { objects[i] }, false);
}
programStackPushInteger(program, 100);
}

55
src/sfall_script_value.cc Normal file
View File

@ -0,0 +1,55 @@
#include "sfall_script_value.h"
namespace fallout {
SFallScriptValue::SFallScriptValue()
{
opcode = VALUE_TYPE_INT;
integerValue = 0;
}
SFallScriptValue::SFallScriptValue(int value)
{
opcode = VALUE_TYPE_INT;
integerValue = value;
};
SFallScriptValue::SFallScriptValue(Object* value)
{
opcode = VALUE_TYPE_PTR;
pointerValue = value;
};
SFallScriptValue::SFallScriptValue(ProgramValue& value)
{
// Assuming that pointer is the biggest in size
static_assert(sizeof(decltype(value.floatValue)) <= sizeof(decltype(value.pointerValue)));
static_assert(sizeof(decltype(value.integerValue)) <= sizeof(decltype(value.pointerValue)));
opcode = value.opcode;
pointerValue = value.pointerValue;
// TODO: If type is string then copy string
}
bool SFallScriptValue::isInt() const
{
return opcode == VALUE_TYPE_INT;
}
bool SFallScriptValue::isFloat() const
{
return opcode == VALUE_TYPE_FLOAT;
}
bool SFallScriptValue::isPointer() const
{
return opcode == VALUE_TYPE_PTR;
}
int SFallScriptValue::asInt() const
{
switch (opcode) {
case VALUE_TYPE_INT:
return integerValue;
case VALUE_TYPE_FLOAT:
return static_cast<int>(floatValue);
default:
return 0;
}
}
}

23
src/sfall_script_value.h Normal file
View File

@ -0,0 +1,23 @@
#ifndef SFALL_SCRIPT_VALUE
#define SFALL_SCRIPT_VALUE
#include "interpreter.h"
#include "object.h"
namespace fallout {
class SFallScriptValue : public ProgramValue {
public:
SFallScriptValue();
SFallScriptValue(int value);
SFallScriptValue(Object* value);
SFallScriptValue(ProgramValue& value);
bool isInt() const;
bool isFloat() const;
bool isPointer() const;
int asInt() const;
};
}
#endif /* SFALL_SCRIPT_VALUE */