<commit_before>//=============================================================================
// ■ ruby_connection.cpp
//-----------------------------------------------------------------------------
//   包装每一个导出到Ruby中的函数，也负责一些Ruby扩展所需的杂务。
//=============================================================================

#include "global.hpp"

typedef void (*freefunc_t)(void*);

GLfloat vertices[] = {
	0.0f, 0.0f, 0.0f,
	435.0f, 0.0f, 0.0f,
	435.0f, 270.0f, 0.0f
};

namespace RubyWrapper {
	VALUE load_pic(VALUE self, VALUE path) {
		Check_Type(path, T_STRING);
		char* a = RSTRING_PTR(path);
		return Qnil;//RSTRING(load_img(a));
	}

	struct ptr_data {
		void *ptr;
		long size;
		freefunc_t free;
		VALUE wrap[2];
	};

	VALUE gdrawable_visible_set(VALUE val, VALUE cdata) {
		return Qnil;
	}

	static void rb_data_mark(void *ptr) {
		struct ptr_data *data = ptr;
		if (data->wrap[0])
			rb_gc_mark(data->wrap[0]);
		if (data->wrap[1])
			rb_gc_mark(data->wrap[1]);
	}

	static void rb_data_free(void *ptr) {
		struct ptr_data *data = ptr;
		if (data->ptr && data->free)
			(*(data->free))(data->ptr);
		xfree(ptr);
	}

	static size_t rb_data_memsize(const void *ptr) {
		const struct ptr_data *data = ptr;
		return sizeof(*data) + data->size;
	}

	rb_data_type_t gdrawable_data_type = {
		"Drawable_C_Data",
		{rb_data_mark, rb_data_free, rb_data_memsize},
	};

	VALUE gdrawable_visible_get(VALUE val, VALUE cdata) {
	/*	rb_data_type_t gdrawable_data_type = {
			"Drawable_C_Data",
			{
				0, 0,
			},
			0, (void*) node, RUBY_TYPED_FREE_IMMEDIATELY,
		};*/
		struct ptr_data *data;
		(RCN*) TypedData_Get_Struct(cdata, ptr_data, &gdrawable_data_type, data);
		RCN* node = (RCN*) data->ptr;
		return Qnil;//(VALUE) node->visible;
	}

	VALUE gdrawable_bind_obj(VALUE self) {

		RCN* node = (RCN*) malloc(sizeof(RCN));
		node->n = self;
		node->visible = true;
		node->prev = render_chain;
		if (node->prev == NULL)
			render_chain = node;
		else
			node->prev->next = node;
		node->next = NULL;
		node->gd = GDrawable::create();
		node->gd->vertices = (GLfloat*) malloc(sizeof(vertices));
		memcpy(node->gd->vertices, vertices, sizeof(vertices));
		node->gd->size_of_VBO = sizeof(vertices);
		GDrawable::update(node->gd);

		return TypedData_Wrap_Struct(rb_cData, &gdrawable_data_type, node);
	}

	VALUE init_engine(VALUE self, VALUE w, VALUE h) {
		Check_Type(w, T_FIXNUM);
		Check_Type(h, T_FIXNUM);
		::init_engine(FIX2INT(w), FIX2INT(h));
		return Qnil;
	}

	VALUE main_draw_loop() {
		::main_draw_loop();
		return Qnil;
	}

	VALUE main_get_frame_count() {
		return LONG2FIX(VMDE->frame_count);
	}

	VALUE main_get_fps() {
		return INT2FIX(VMDE->fps);
	}

	VALUE main_matrix2D() {
		::matrix2D();
		return Qtrue;
	}

	VALUE main_set_brightness(VALUE self, VALUE b) {
		Check_Type(b, T_FLOAT);<commit_msg>VISIBLE可以get了<commit_after>//=============================================================================
// ■ ruby_connection.cpp
//-----------------------------------------------------------------------------
//   包装每一个导出到Ruby中的函数，也负责一些Ruby扩展所需的杂务。
//=============================================================================

#include "global.hpp"

typedef void (*freefunc_t)(void*);

GLfloat vertices[] = {
	0.0f, 0.0f, 0.0f,
	435.0f, 0.0f, 0.0f,
	435.0f, 270.0f, 0.0f
};

namespace RubyWrapper {
	VALUE load_pic(VALUE self, VALUE path) {
		Check_Type(path, T_STRING);
		char* a = RSTRING_PTR(path);
		return Qnil;//RSTRING(load_img(a));
	}

	struct ptr_data {
		void *ptr;
		long size;
		freefunc_t free;
		VALUE wrap[2];
	};

	VALUE gdrawable_visible_set(VALUE val, VALUE cdata) {
		return Qnil;
	}

	static void rb_data_mark(void *ptr) {
		struct ptr_data *data = ptr;
		if (data->wrap[0])
			rb_gc_mark(data->wrap[0]);
		if (data->wrap[1])
			rb_gc_mark(data->wrap[1]);
	}

	static void rb_data_free(void *ptr) {
		struct ptr_data *data = ptr;
		if (data->ptr && data->free)
			(*(data->free))(data->ptr);
		xfree(ptr);
	}

	static size_t rb_data_memsize(const void *ptr) {
		const struct ptr_data *data = ptr;
		return sizeof(*data) + data->size;
	}

	rb_data_type_t gdrawable_data_type = {
		"Drawable_C_Data",
		{rb_data_mark, rb_data_free, rb_data_memsize},
	};

	VALUE gdrawable_visible_get(VALUE val, VALUE cdata) {
		struct ptr_data *data;
		(RCN*) TypedData_Get_Struct(cdata, ptr_data, &gdrawable_data_type, data);
		RCN* node = (RCN*) data->ptr;

		log("%d", node);
		return node->visible ? Qtrue : Qfalse;
	}

	VALUE gdrawable_bind_obj(VALUE self) {

		RCN* node = (RCN*) malloc(sizeof(RCN));
		node->n = self;
		node->visible = true;
		node->prev = render_chain;
		if (node->prev == NULL)
			render_chain = node;
		else
			node->prev->next = node;
		node->next = NULL;
		node->gd = GDrawable::create();
		node->gd->vertices = (GLfloat*) malloc(sizeof(vertices));
		memcpy(node->gd->vertices, vertices, sizeof(vertices));
		node->gd->size_of_VBO = sizeof(vertices);
		GDrawable::update(node->gd);

		struct ptr_data* data;
		VALUE v = TypedData_Make_Struct(rb_cData, struct ptr_data, &gdrawable_data_type, data);
		data->ptr = node;
		data->free = free;
		data->size = sizeof(RCN);

		return v;
	}

	VALUE init_engine(VALUE self, VALUE w, VALUE h) {
		Check_Type(w, T_FIXNUM);
		Check_Type(h, T_FIXNUM);
		::init_engine(FIX2INT(w), FIX2INT(h));
		return Qnil;
	}

	VALUE main_draw_loop() {
		::main_draw_loop();
		return Qnil;
	}

	VALUE main_get_frame_count() {
		return LONG2FIX(VMDE->frame_count);
	}

	VALUE main_get_fps() {
		return INT2FIX(VMDE->fps);
	}

	VALUE main_matrix2D() {
		::matrix2D();
		return Qtrue;
	}

	VALUE main_set_brightness(VALUE self, VALUE b) {
		Check_Type(b, T_FLOAT);
{'fraction_non_alphanumeric': 0.2259897035327534, 'fraction_numerical': 0.012959346706905734, 'mean_word_length': 3.8694900605012963, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 62, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4591525', 'n_tokens_mistral': 2392, 'n_tokens_neox': 2178, 'n_words': 415}