75 lines
1.8 KiB
C
75 lines
1.8 KiB
C
#pragma once
|
|
|
|
// ============================================================================
|
|
// block_executor.h - 积木执行引擎
|
|
// ============================================================================
|
|
|
|
#include "block_workspace.h"
|
|
|
|
#define MAX_VARIABLES 256
|
|
#define MAX_CALL_STACK 32
|
|
#define MAX_EXEC_STACK 1024
|
|
|
|
// 变量
|
|
typedef struct {
|
|
char name[64];
|
|
SlotValue value;
|
|
int used;
|
|
} Variable;
|
|
|
|
// 调用帧
|
|
typedef struct {
|
|
Block* block;
|
|
Block* return_block;
|
|
} CallFrame;
|
|
|
|
// 执行状态
|
|
typedef enum {
|
|
EXEC_IDLE = 0,
|
|
EXEC_RUNNING,
|
|
EXEC_WAITING,
|
|
EXEC_PAUSED,
|
|
EXEC_ERROR
|
|
} ExecState;
|
|
|
|
// 执行器
|
|
typedef struct BlockExecutor {
|
|
BlockWorkspace* workspace;
|
|
ExecState state;
|
|
|
|
Variable variables[MAX_VARIABLES];
|
|
int variable_count;
|
|
|
|
CallFrame call_stack[MAX_CALL_STACK];
|
|
int call_stack_top;
|
|
|
|
Block* current_block;
|
|
double wait_timer;
|
|
|
|
int breakpoint_enabled;
|
|
Block* breakpoint_block;
|
|
} BlockExecutor;
|
|
|
|
// 初始化/销毁
|
|
BlockExecutor* executor_create(BlockWorkspace* ws);
|
|
void executor_destroy(BlockExecutor* exec);
|
|
|
|
// 控制
|
|
void executor_start(BlockExecutor* exec);
|
|
void executor_stop(BlockExecutor* exec);
|
|
void executor_pause(BlockExecutor* exec);
|
|
void executor_resume(BlockExecutor* exec);
|
|
void executor_step(BlockExecutor* exec);
|
|
|
|
// 更新 (每帧调用)
|
|
void executor_update(BlockExecutor* exec, double delta_time);
|
|
|
|
// 变量操作
|
|
void executor_set_variable(BlockExecutor* exec, const char* name, SlotValue value);
|
|
SlotValue executor_get_variable(BlockExecutor* exec, const char* name);
|
|
void executor_create_variable(BlockExecutor* exec, const char* name);
|
|
|
|
// 日志回调
|
|
typedef void (*LogCallback)(const char* msg, int level);
|
|
void executor_set_log_callback(LogCallback cb);
|