Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 16 additions & 6 deletions src/vm_builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,8 @@ static const BuiltinVarEntry BUILTIN_VAR_TABLE[] = {
{ "depth", BUILTIN_VAR_DEPTH },
{ "direction", BUILTIN_VAR_DIRECTION },
{ "event_data", BUILTIN_VAR_EVENT_DATA },
{ "event_number", BUILTIN_VAR_EVENT_NUMBER },
{ "event_type", BUILTIN_VAR_EVENT_TYPE },
{ "false", BUILTIN_VAR_FALSE },
{ "fps", BUILTIN_VAR_FPS },
{ "fps_real", BUILTIN_VAR_FPS_REAL },
Expand Down Expand Up @@ -921,6 +923,10 @@ RValue VMBuiltins_getVariable(VMContext* ctx, Instance* inst, int16_t builtinVar
return RValue_makeBool(inst->timelineLoop);

// Room properties
case BUILTIN_VAR_EVENT_TYPE:
return RValue_makeReal((GMLReal) ctx->currentEventType);
case BUILTIN_VAR_EVENT_NUMBER:
return RValue_makeReal((GMLReal) ctx->currentEventSubtype);
case BUILTIN_VAR_ROOM:
return RValue_makeReal((GMLReal) runner->currentRoomIndex);
case BUILTIN_VAR_ROOM_FIRST:
Expand Down Expand Up @@ -7092,7 +7098,8 @@ static bool resolveFunctionRef(VMContext* ctx, RValue funcRef, int32_t* outCodeI
return *outCodeIndex >= 0 || *outBuiltin != nullptr;
}
#endif
if (funcRef.type != RVALUE_INT32 && funcRef.type != RVALUE_INT64 && funcRef.type != RVALUE_REAL) return false;
if (funcRef.type != RVALUE_INT32 && funcRef.type != RVALUE_INT64 && funcRef.type != RVALUE_REAL &&
!(funcRef.type == RVALUE_ASSETREF && funcRef.assetRefType == ASSET_TYPE_SCRIPT)) return false;
int32_t rawArg = RValue_toInt32(funcRef);
if (rawArg >= 0 && ctx->dataWin->func.functionCount > (uint32_t) rawArg) {
const char* funcName = ctx->dataWin->func.functions[rawArg].name;
Expand Down Expand Up @@ -15694,24 +15701,28 @@ static RValue builtin_layer_destroy(VMContext* ctx, RValue* args, MAYBE_UNUSED i

static RValue builtin_layer_script_begin(VMContext* ctx, RValue* args, MAYBE_UNUSED int32_t argCount) {
int32_t layerId = resolveLayerIdArg(ctx->runner, args[0]);
int32_t scriptIndex = RValue_toInt32(args[1]);
int32_t codeIndex;
BuiltinFunc builtin;
resolveFunctionRef(ctx, args[1], &codeIndex, &builtin);

RuntimeLayer* runtimeLayer = Runner_findRuntimeLayerById(ctx->runner, layerId);
if (runtimeLayer == nullptr) return RValue_makeUndefined();

runtimeLayer->beginScript = scriptIndex;
runtimeLayer->beginScript = codeIndex;

return RValue_makeUndefined();
}

static RValue builtin_layer_script_end(VMContext* ctx, RValue* args, MAYBE_UNUSED int32_t argCount) {
int32_t layerId = resolveLayerIdArg(ctx->runner, args[0]);
int32_t scriptIndex = RValue_toInt32(args[1]);
int32_t codeIndex;
BuiltinFunc builtin;
resolveFunctionRef(ctx, args[1], &codeIndex, &builtin);

RuntimeLayer* runtimeLayer = Runner_findRuntimeLayerById(ctx->runner, layerId);
if (runtimeLayer == nullptr) return RValue_makeUndefined();

runtimeLayer->endScript = scriptIndex;
runtimeLayer->endScript = codeIndex;

return RValue_makeUndefined();
}
Expand Down Expand Up @@ -23042,7 +23053,6 @@ static RValue builtin_physics_raycast(VMContext* ctx, RValue* args, int32_t coun
void VMBuiltins_registerAll(VMContext* ctx) {
requireMessage(!ctx->registeredBuiltinFunctions, "Attempting to register all VMBuiltins, but it was already registered!");
ctx->registeredBuiltinFunctions = true;

// Physics
#define PHYSICS_FUNCTION(name, scope, minimum, returnsReal) VM_registerBuiltin(ctx, #name, builtin_##name);
PHYSICS_FUNCTIONS(PHYSICS_FUNCTION)
Expand Down
2 changes: 2 additions & 0 deletions src/vm_builtins.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ typedef enum {
BUILTIN_VAR_FPS_REAL,
BUILTIN_VAR_DEBUG_MODE,
BUILTIN_VAR_DELTA_TIME,
BUILTIN_VAR_EVENT_TYPE,
BUILTIN_VAR_EVENT_NUMBER,

// Legacy GMS 1.x globals
BUILTIN_VAR_SCORE,
Expand Down
Loading