// spellforge_native.cpp — 见头文件说明。
#include "spellforge_native.h"

#include <godot_cpp/core/class_db.hpp>

using namespace godot;

void SpellforgeNative::_bind_methods() {
	ClassDB::bind_method(D_METHOD("multiply", "a", "b"), &SpellforgeNative::multiply);
	ClassDB::bind_method(D_METHOD("native_info"), &SpellforgeNative::native_info);
	ClassDB::bind_method(D_METHOD("scale_inplace", "data", "factor"), &SpellforgeNative::scale_inplace);
}

SpellforgeNative::SpellforgeNative() {}
SpellforgeNative::~SpellforgeNative() {}

double SpellforgeNative::multiply(double a, double b) const {
	return a * b;
}

String SpellforgeNative::native_info() const {
	return String("Spellforge C++ GDExtension OK — built against Godot 4.7.1 API");
}

PackedFloat32Array SpellforgeNative::scale_inplace(PackedFloat32Array data, float factor) const {
	// 边界纪律（ADR-L1）：热循环全程在 C++ 内完成，仅在边界批量进出 PackedArray。
	// ptrw() 拿到原生连续内存指针，内循环零 GodotObject 调用。
	const int n = data.size();
	float *w = data.ptrw();
	for (int i = 0; i < n; i++) {
		w[i] *= factor;
	}
	return data;
}
