/* * call-seq: initialize * @overload initialize(pointer, *args) * @param [AbstractMemory] pointer * @param [Array] args * @return [self] */ static VALUE struct_initialize(int argc, VALUE* argv, VALUE self) { Struct* s; VALUE rbPointer = Qnil, rest = Qnil, klass = CLASS_OF(self); int nargs; Data_Get_Struct(self, Struct, s); nargs = rb_scan_args(argc, argv, "01*", &rbPointer, &rest); /* Call up into ruby code to adjust the layout */ if (nargs > 1) { s->rbLayout = rb_funcall2(CLASS_OF(self), id_layout, (int) RARRAY_LEN(rest), RARRAY_PTR(rest)); } else { s->rbLayout = struct_class_layout(klass); } if (!rb_obj_is_kind_of(s->rbLayout, rbffi_StructLayoutClass)) { rb_raise(rb_eRuntimeError, "Invalid Struct layout"); } Data_Get_Struct(s->rbLayout, StructLayout, s->layout); if (rbPointer != Qnil) { s->pointer = MEMORY(rbPointer); s->rbPointer = rbPointer; } else { struct_malloc(s); } return self; }
blend_group_t* blend_group_new(unsigned int key) { struct_malloc(blend_group_t, self); self->tgs = kh_init(hmsp); self->num = 0; self->key = key; return self; }
tex_group_t* tex_group_new(const texture_t* tex, const font_t* font) { struct_malloc(tex_group_t, self); self->tex = tex; self->font = font; self->sgs = kh_init(hmsp); self->num = 0; return self; }
shader_group_t* shader_group_new(const shader_t* program, const vertex_buffer_t* buff, const char* name, int z, struct tex_group_t* tg, struct blend_group_t* bg) { struct_malloc(shader_group_t, self); self->program = program; self->name = sen_strdup(name); self->buff = vertex_buffer_new(vertex_buffer_format(buff)); self->num = 0; self->z = z; self->tg = tg; self->bg = bg; return self; }
static Struct* struct_validate(VALUE self) { Struct* s; Data_Get_Struct(self, Struct, s); if (struct_layout(self) == NULL) { rb_raise(rb_eRuntimeError, "struct layout == null"); } if (s->pointer == NULL) { struct_malloc(s); } return s; }
sprite_t* sen_sprite_new(const char* name, const char* texture_name) { // _logfi("+sprite %s, texture=%s", (name ? name : "autoName"), texture_name); struct_malloc(sprite_t, self); sen_node_init(self, name, 0); self->tex = sen_textures_get(texture_name); sen_assert(self->tex); self->program = sen_shaders_get("sprite"); sen_assert(self->program); self->quad = vertex_buffer_new("a_pos:4f,a_tex_coords:2f,a_color:4f"); //update_quad(self); update_buffer(self); ((node_t*)self)->vt = &sprite_interface; return self; }