LiteRGSS 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +7 -0
  2. data/ext/LiteRGSS/Bitmap.cpp +316 -0
  3. data/ext/LiteRGSS/Bitmap.h +24 -0
  4. data/ext/LiteRGSS/BlendMode.cpp +202 -0
  5. data/ext/LiteRGSS/BlendMode.h +20 -0
  6. data/ext/LiteRGSS/CBitmap_Element.cpp +50 -0
  7. data/ext/LiteRGSS/CBitmap_Element.h +17 -0
  8. data/ext/LiteRGSS/CDrawable_Element.cpp +38 -0
  9. data/ext/LiteRGSS/CDrawable_Element.h +30 -0
  10. data/ext/LiteRGSS/CRect_Element.h +15 -0
  11. data/ext/LiteRGSS/CShaderSprite_Element.cpp +17 -0
  12. data/ext/LiteRGSS/CShaderSprite_Element.h +17 -0
  13. data/ext/LiteRGSS/CSprite_Element.cpp +15 -0
  14. data/ext/LiteRGSS/CSprite_Element.h +36 -0
  15. data/ext/LiteRGSS/CText_Element.cpp +12 -0
  16. data/ext/LiteRGSS/CText_Element.h +29 -0
  17. data/ext/LiteRGSS/CTone_Element.h +17 -0
  18. data/ext/LiteRGSS/CViewport_Element.cpp +224 -0
  19. data/ext/LiteRGSS/CViewport_Element.h +57 -0
  20. data/ext/LiteRGSS/Color.cpp +200 -0
  21. data/ext/LiteRGSS/Color.h +22 -0
  22. data/ext/LiteRGSS/Fonts.cpp +126 -0
  23. data/ext/LiteRGSS/Fonts.h +20 -0
  24. data/ext/LiteRGSS/Graphics.cpp +314 -0
  25. data/ext/LiteRGSS/Graphics.h +31 -0
  26. data/ext/LiteRGSS/Graphics.local.cpp +365 -0
  27. data/ext/LiteRGSS/Graphics.local.h +37 -0
  28. data/ext/LiteRGSS/Image.cpp +460 -0
  29. data/ext/LiteRGSS/Image.h +32 -0
  30. data/ext/LiteRGSS/Input.cpp +664 -0
  31. data/ext/LiteRGSS/Input.h +38 -0
  32. data/ext/LiteRGSS/LiteRGSS.cpp +34 -0
  33. data/ext/LiteRGSS/LiteRGSS.h +113 -0
  34. data/ext/LiteRGSS/Rect.cpp +324 -0
  35. data/ext/LiteRGSS/Rect.h +24 -0
  36. data/ext/LiteRGSS/Shader.cpp +279 -0
  37. data/ext/LiteRGSS/Shader.h +13 -0
  38. data/ext/LiteRGSS/ShaderSprite.cpp +78 -0
  39. data/ext/LiteRGSS/ShaderSprite.h +8 -0
  40. data/ext/LiteRGSS/Sprite.cpp +495 -0
  41. data/ext/LiteRGSS/Sprite.h +43 -0
  42. data/ext/LiteRGSS/Table.cpp +228 -0
  43. data/ext/LiteRGSS/Table.h +29 -0
  44. data/ext/LiteRGSS/Table32.cpp +228 -0
  45. data/ext/LiteRGSS/Table32.h +29 -0
  46. data/ext/LiteRGSS/Text.cpp +574 -0
  47. data/ext/LiteRGSS/Text.h +52 -0
  48. data/ext/LiteRGSS/Texture.hpp +735 -0
  49. data/ext/LiteRGSS/Tone.cpp +228 -0
  50. data/ext/LiteRGSS/Tone.h +22 -0
  51. data/ext/LiteRGSS/Viewport.cpp +491 -0
  52. data/ext/LiteRGSS/Viewport.h +33 -0
  53. data/ext/LiteRGSS/Yuki.cpp +29 -0
  54. data/ext/LiteRGSS/Yuki.h +8 -0
  55. data/ext/LiteRGSS/Yuki_Gif.cpp +218 -0
  56. data/ext/LiteRGSS/Yuki_Gif.h +25 -0
  57. data/ext/LiteRGSS/extconf.rb +8 -0
  58. data/ext/LiteRGSS/libnsgif.c +1169 -0
  59. data/ext/LiteRGSS/libnsgif.h +183 -0
  60. data/ext/LiteRGSS/libnsgif.hpp +184 -0
  61. data/ext/LiteRGSS/lodepng.cpp +6245 -0
  62. data/ext/LiteRGSS/lodepng.h +1769 -0
  63. data/ext/LiteRGSS/lzw.c +377 -0
  64. data/ext/LiteRGSS/lzw.h +105 -0
  65. data/ext/LiteRGSS/sf_Text2.cpp +690 -0
  66. data/ext/LiteRGSS/sf_Text2.hpp +549 -0
  67. data/ext/LiteRGSS/utils/log.h +21 -0
  68. metadata +112 -0
@@ -0,0 +1,43 @@
1
+ #ifndef L_SPRITE_HEADER
2
+ #define L_SPRITE_HEADER
3
+ #include "Graphics.h"
4
+
5
+ VALUE rb_Sprite_Initialize(int argc, VALUE* argv, VALUE self);
6
+ VALUE rb_Sprite_Copy(VALUE self);
7
+ VALUE rb_Sprite_Dispose(VALUE self);
8
+ VALUE rb_Sprite_Disposed(VALUE self);
9
+ VALUE rb_Sprite_setBitmap(VALUE self, VALUE bitmap);
10
+ VALUE rb_Sprite_getBitmap(VALUE self);
11
+ VALUE rb_Sprite_setX(VALUE self, VALUE val);
12
+ VALUE rb_Sprite_getX(VALUE self);
13
+ VALUE rb_Sprite_setY(VALUE self, VALUE val);
14
+ VALUE rb_Sprite_getY(VALUE self);
15
+ VALUE rb_Sprite_setZ(VALUE self, VALUE val);
16
+ VALUE rb_Sprite_getZ(VALUE self);
17
+ VALUE rb_Sprite_setOX(VALUE self, VALUE val);
18
+ VALUE rb_Sprite_getOX(VALUE self);
19
+ VALUE rb_Sprite_setOY(VALUE self, VALUE val);
20
+ VALUE rb_Sprite_getOY(VALUE self);
21
+ VALUE rb_Sprite_setVisible(VALUE self, VALUE val);
22
+ VALUE rb_Sprite_getVisible(VALUE self);
23
+ VALUE rb_Sprite_setAngle(VALUE self, VALUE val);
24
+ VALUE rb_Sprite_getAngle(VALUE self);
25
+ VALUE rb_Sprite_setZoomX(VALUE self, VALUE val);
26
+ VALUE rb_Sprite_getZoomX(VALUE self);
27
+ VALUE rb_Sprite_setZoomY(VALUE self, VALUE val);
28
+ VALUE rb_Sprite_getZoomY(VALUE self);
29
+ VALUE rb_Sprite_setPosition(VALUE self, VALUE x, VALUE y);
30
+ VALUE rb_Sprite_setOrigin(VALUE self, VALUE x, VALUE y);
31
+ VALUE rb_Sprite_setZoom(VALUE self, VALUE zoom);
32
+ VALUE rb_Sprite_setOpacity(VALUE self, VALUE val);
33
+ VALUE rb_Sprite_getOpacity(VALUE self);
34
+ VALUE rb_Sprite_getRect(VALUE self);
35
+ VALUE rb_Sprite_setRect(VALUE self, VALUE val);
36
+ VALUE rb_Sprite_DisposeFromViewport(VALUE self);
37
+ VALUE rb_Sprite_Viewport(VALUE self);
38
+ VALUE rb_Sprite_Index(VALUE self);
39
+ VALUE rb_Sprite_getMirror(VALUE self);
40
+ VALUE rb_Sprite_setMirror(VALUE self, VALUE val);
41
+ VALUE rb_Sprite_width(VALUE self);
42
+ VALUE rb_Sprite_height(VALUE self);
43
+ #endif
@@ -0,0 +1,228 @@
1
+ #include "LiteRGSS.h"
2
+
3
+ VALUE rb_cTable = Qnil;
4
+
5
+ #define GET_TABLE rb_Table_Struct* table; \
6
+ Data_Get_Struct(self, rb_Table_Struct, table); \
7
+ if(table == nullptr) \
8
+ return Qnil;
9
+
10
+ void rb_Table_Free(void* data)
11
+ {
12
+ rb_Table_Struct* table = reinterpret_cast<rb_Table_Struct*>(data);
13
+ if(table != nullptr)
14
+ {
15
+ //std::cout << "TH : " << table->heap << std::endl;
16
+ if(table->heap != nullptr)
17
+ delete[] table->heap;
18
+ table->heap = nullptr;
19
+ delete table;
20
+ }
21
+ }
22
+
23
+ VALUE rb_Table_Alloc(VALUE klass)
24
+ {
25
+ rb_Table_Struct* table = new rb_Table_Struct();
26
+ table->heap = nullptr;
27
+ table->header.dim = 0;
28
+ table->header.data_size = 0;
29
+ return Data_Wrap_Struct(klass, NULL, rb_Table_Free, table);
30
+ }
31
+
32
+ void Init_Table()
33
+ {
34
+ rb_cTable = rb_define_class("Table", rb_cObject);
35
+ rb_define_alloc_func(rb_cTable, rb_Table_Alloc);
36
+ rb_define_method(rb_cTable, "initialize", _rbf rb_Table_initialize, -1);
37
+ rb_define_method(rb_cTable, "[]", _rbf rb_Table_get, -1);
38
+ rb_define_method(rb_cTable, "[]=", _rbf rb_Table_set, -1);
39
+ rb_define_method(rb_cTable, "xsize", _rbf rb_Table_xSize, 0);
40
+ rb_define_method(rb_cTable, "ysize", _rbf rb_Table_ySize, 0);
41
+ rb_define_method(rb_cTable, "zsize", _rbf rb_Table_zSize, 0);
42
+ rb_define_method(rb_cTable, "dim", _rbf rb_Table_dim, 0);
43
+ rb_define_method(rb_cTable, "resize", _rbf rb_Table_resize, -1);
44
+ rb_define_method(rb_cTable, "fill", _rbf rb_Table_Fill, 1);
45
+
46
+ rb_define_method(rb_cTable, "_dump", _rbf rb_Table_Save, 1);
47
+ rb_define_singleton_method(rb_cTable, "_load", _rbf rb_Table_Load, 1);
48
+ }
49
+
50
+
51
+ VALUE rb_Table_initialize(int argc, VALUE* argv, VALUE self)
52
+ {
53
+ GET_TABLE
54
+ switch(argc)
55
+ {
56
+ case 1:
57
+ table->header.xsize = rb_num2ulong(argv[0]);
58
+ table->header.ysize = 1;
59
+ table->header.zsize = 1;
60
+ break;
61
+ case 2:
62
+ table->header.xsize = rb_num2ulong(argv[0]);
63
+ table->header.ysize = rb_num2ulong(argv[1]);
64
+ table->header.zsize = 1;
65
+ break;
66
+ case 3:
67
+ table->header.xsize = rb_num2ulong(argv[0]);
68
+ table->header.ysize = rb_num2ulong(argv[1]);
69
+ table->header.zsize = rb_num2ulong(argv[2]);
70
+ break;
71
+ default:
72
+ rb_raise(rb_eRGSSError, "Table can be 1D, 2D or 3D but nothing else, requested dimension : %dD", argc);
73
+ return Qnil;
74
+ }
75
+ if(table->header.xsize == 0)
76
+ table->header.xsize = 1;
77
+ if(table->header.ysize == 0)
78
+ table->header.ysize = 1;
79
+ if(table->header.zsize == 0)
80
+ table->header.zsize = 1;
81
+ table->header.dim = argc;
82
+ table->header.data_size = table->header.xsize * table->header.ysize * table->header.zsize;
83
+ table->heap = new short[table->header.data_size];
84
+ return self;
85
+ }
86
+
87
+ VALUE rb_Table_get(int argc, VALUE* argv, VALUE self)
88
+ {
89
+ GET_TABLE
90
+ VALUE rx, ry, rz;
91
+ unsigned long x, y, z;
92
+ rb_scan_args(argc, argv, "12", &rx, &ry, &rz);
93
+ x = rb_num2ulong(rx);
94
+ y = NIL_P(ry) ? 0 : rb_num2ulong(ry);
95
+ z = NIL_P(rz) ? 0 : rb_num2ulong(rz);
96
+ if(x >= table->header.xsize || y >= table->header.ysize || z >= table->header.zsize)
97
+ return Qnil;
98
+ return rb_int2inum(table->heap[x + (y * table->header.xsize) + (z * table->header.xsize * table->header.ysize)]);
99
+ }
100
+
101
+ VALUE rb_Table_set(int argc, VALUE* argv, VALUE self)
102
+ {
103
+ GET_TABLE
104
+ VALUE rx, ry, rz, rv;
105
+ unsigned long x, y, z;
106
+ short v;
107
+ rb_scan_args(argc, argv, "22", &rx, &ry, &rz, &rv);
108
+ x = rb_num2ulong(rx);
109
+ if(NIL_P(rz))
110
+ {
111
+ v = RB_NUM2SHORT(ry);
112
+ z = y = 0;
113
+ }
114
+ else if(NIL_P(rv))
115
+ {
116
+ v = RB_NUM2SHORT(rz);
117
+ y = rb_num2ulong(ry);
118
+ z = 0;
119
+ }
120
+ else
121
+ {
122
+ y = rb_num2ulong(ry);
123
+ z = rb_num2ulong(rz);
124
+ v = RB_NUM2SHORT(rv);
125
+ }
126
+ if(x >= table->header.xsize || y >= table->header.ysize || z >= table->header.zsize)
127
+ return Qnil;
128
+ table->heap[x + (y * table->header.xsize) + (z * table->header.xsize * table->header.ysize)] = v;
129
+ return self;
130
+ }
131
+
132
+ VALUE rb_Table_xSize(VALUE self)
133
+ {
134
+ GET_TABLE
135
+ return rb_uint2inum(table->header.xsize);
136
+ }
137
+
138
+ VALUE rb_Table_ySize(VALUE self)
139
+ {
140
+ GET_TABLE
141
+ return rb_uint2inum(table->header.ysize);
142
+ }
143
+
144
+ VALUE rb_Table_zSize(VALUE self)
145
+ {
146
+ GET_TABLE
147
+ return rb_uint2inum(table->header.zsize);
148
+ }
149
+
150
+ VALUE rb_Table_dim(VALUE self)
151
+ {
152
+ GET_TABLE
153
+ return rb_uint2inum(table->header.dim);
154
+ }
155
+
156
+ void table_copy(short* dheap, short* sheap, unsigned long dxsize, unsigned long dysize,
157
+ unsigned long dzsize, unsigned long sxsize, unsigned long sysize, unsigned long szsize)
158
+ {
159
+ unsigned long xsize, ysize, zsize, soy, soz, doy, doz, x, y, z;
160
+ xsize = dxsize < sxsize ? dxsize : sxsize;
161
+ ysize = dysize < sysize ? dysize : sysize;
162
+ zsize = dzsize < szsize ? dzsize : szsize;
163
+ for(z = 0; z < zsize; z++)
164
+ {
165
+ doz = z * dxsize * dysize;
166
+ soz = z * sxsize * sysize; // optimisable => del soz, repl soz par soy
167
+ for(y = 0; y < ysize; y++)
168
+ {
169
+ doy = doz + (y * dxsize);
170
+ soy = soz + (y * sxsize); // optimisable => add after for{} soy += sxsize;
171
+ for(x = 0; x < xsize; x++)
172
+ {
173
+ dheap[doy++] = sheap[soy++];
174
+ }
175
+ }
176
+ }
177
+ }
178
+
179
+ VALUE rb_Table_resize(int argc, VALUE* argv, VALUE self)
180
+ {
181
+ GET_TABLE
182
+ auto table2 = *table;
183
+ rb_Table_initialize(argc, argv, self);
184
+ // Copying data
185
+ table_copy(table->heap, table2.heap,
186
+ table->header.xsize, table->header.ysize, table->header.zsize,
187
+ table2.header.xsize, table2.header.ysize, table2.header.zsize);
188
+ // Freeing heap
189
+ delete[] table2.heap;
190
+ return self;
191
+ }
192
+
193
+
194
+ VALUE rb_Table_Load(VALUE self, VALUE str)
195
+ {
196
+ rb_check_type(str, T_STRING);
197
+ rb_Table_Struct* table = reinterpret_cast<rb_Table_Struct*>(RSTRING_PTR(str));
198
+ VALUE arr[3];
199
+ arr[0] = RB_UINT2NUM(table->header.xsize);
200
+ arr[1] = RB_UINT2NUM(table->header.ysize);
201
+ arr[2] = RB_UINT2NUM(table->header.zsize);
202
+ table->header.dim = normalize_long(table->header.dim, 1, 3);
203
+ VALUE rtable = rb_class_new_instance(table->header.dim, arr, self);
204
+ Data_Get_Struct(rtable, rb_Table_Struct, table);
205
+ memcpy(table->heap, RSTRING_PTR(str) + sizeof(rb_Table_Struct_Header), table->header.data_size * sizeof(short));
206
+ return rtable;
207
+ }
208
+
209
+ VALUE rb_Table_Save(VALUE self, VALUE limit)
210
+ {
211
+ GET_TABLE
212
+ VALUE str1 = rb_str_new(reinterpret_cast<char*>(&table->header), sizeof(rb_Table_Struct_Header));
213
+ VALUE str2 = rb_str_new(reinterpret_cast<char*>(table->heap), table->header.data_size * sizeof(short));
214
+ return rb_str_concat(str1, str2);
215
+ }
216
+
217
+ VALUE rb_Table_Fill(VALUE self, VALUE val)
218
+ {
219
+ GET_TABLE
220
+ short v = RB_NUM2SHORT(val);
221
+ unsigned long sz = table->header.data_size;
222
+ short* data = table->heap;
223
+ for(unsigned long i = 0;i < sz;i++)
224
+ {
225
+ data[i] = v;
226
+ }
227
+ return self;
228
+ }
@@ -0,0 +1,29 @@
1
+ #ifndef L_TABLE_HEADER
2
+ #define L_TABLE_HEADER
3
+
4
+ struct rb_Table_Struct_Header {
5
+ unsigned int dim;
6
+ unsigned int xsize;
7
+ unsigned int ysize;
8
+ unsigned int zsize;
9
+ unsigned int data_size;
10
+ };
11
+
12
+ struct rb_Table_Struct {
13
+ rb_Table_Struct_Header header;
14
+ short* heap;
15
+ };
16
+
17
+ VALUE rb_Table_initialize(int argc, VALUE* argv, VALUE self);
18
+ VALUE rb_Table_get(int argc, VALUE* argv, VALUE self);
19
+ VALUE rb_Table_set(int argc, VALUE* argv, VALUE self);
20
+ VALUE rb_Table_xSize(VALUE self);
21
+ VALUE rb_Table_ySize(VALUE self);
22
+ VALUE rb_Table_zSize(VALUE self);
23
+ VALUE rb_Table_dim(VALUE self);
24
+ VALUE rb_Table_resize(int argc, VALUE* argv, VALUE self);
25
+ VALUE rb_Table_Load(VALUE self, VALUE str);
26
+ VALUE rb_Table_Save(VALUE self, VALUE limit);
27
+ VALUE rb_Table_Fill(VALUE self, VALUE val);
28
+
29
+ #endif
@@ -0,0 +1,228 @@
1
+ #include "LiteRGSS.h"
2
+
3
+ VALUE rb_cTable32 = Qnil;
4
+
5
+ #define GET_TABLE rb_Table32_Struct* table; \
6
+ Data_Get_Struct(self, rb_Table32_Struct, table); \
7
+ if(table == nullptr) \
8
+ return Qnil;
9
+
10
+ void rb_Table32_Free(void* data)
11
+ {
12
+ rb_Table32_Struct* table = reinterpret_cast<rb_Table32_Struct*>(data);
13
+ if(table != nullptr)
14
+ {
15
+ //std::cout << "TH : " << table->heap << std::endl;
16
+ if(table->heap != nullptr)
17
+ delete[] table->heap;
18
+ table->heap = nullptr;
19
+ delete table;
20
+ }
21
+ }
22
+
23
+ VALUE rb_Table32_Alloc(VALUE klass)
24
+ {
25
+ rb_Table32_Struct* table = new rb_Table32_Struct();
26
+ table->heap = nullptr;
27
+ table->header.dim = 0;
28
+ table->header.data_size = 0;
29
+ return Data_Wrap_Struct(klass, NULL, rb_Table32_Free, table);
30
+ }
31
+
32
+ void Init_Table32()
33
+ {
34
+ rb_cTable32 = rb_define_class("Table32", rb_cObject);
35
+ rb_define_alloc_func(rb_cTable32, rb_Table32_Alloc);
36
+ rb_define_method(rb_cTable32, "initialize", _rbf rb_Table32_initialize, -1);
37
+ rb_define_method(rb_cTable32, "[]", _rbf rb_Table32_get, -1);
38
+ rb_define_method(rb_cTable32, "[]=", _rbf rb_Table32_set, -1);
39
+ rb_define_method(rb_cTable32, "xsize", _rbf rb_Table32_xSize, 0);
40
+ rb_define_method(rb_cTable32, "ysize", _rbf rb_Table32_ySize, 0);
41
+ rb_define_method(rb_cTable32, "zsize", _rbf rb_Table32_zSize, 0);
42
+ rb_define_method(rb_cTable32, "dim", _rbf rb_Table32_dim, 0);
43
+ rb_define_method(rb_cTable32, "resize", _rbf rb_Table32_resize, -1);
44
+ rb_define_method(rb_cTable32, "fill", _rbf rb_Table32_Fill, 1);
45
+
46
+ rb_define_method(rb_cTable32, "_dump", _rbf rb_Table32_Save, 1);
47
+ rb_define_singleton_method(rb_cTable32, "_load", _rbf rb_Table32_Load, 1);
48
+ }
49
+
50
+
51
+ VALUE rb_Table32_initialize(int argc, VALUE* argv, VALUE self)
52
+ {
53
+ GET_TABLE
54
+ switch(argc)
55
+ {
56
+ case 1:
57
+ table->header.xsize = rb_num2ulong(argv[0]);
58
+ table->header.ysize = 1;
59
+ table->header.zsize = 1;
60
+ break;
61
+ case 2:
62
+ table->header.xsize = rb_num2ulong(argv[0]);
63
+ table->header.ysize = rb_num2ulong(argv[1]);
64
+ table->header.zsize = 1;
65
+ break;
66
+ case 3:
67
+ table->header.xsize = rb_num2ulong(argv[0]);
68
+ table->header.ysize = rb_num2ulong(argv[1]);
69
+ table->header.zsize = rb_num2ulong(argv[2]);
70
+ break;
71
+ default:
72
+ rb_raise(rb_eRGSSError, "Table32 can be 1D, 2D or 3D but nothing else, requested dimension : %dD", argc);
73
+ return Qnil;
74
+ }
75
+ if(table->header.xsize == 0)
76
+ table->header.xsize = 1;
77
+ if(table->header.ysize == 0)
78
+ table->header.ysize = 1;
79
+ if(table->header.zsize == 0)
80
+ table->header.zsize = 1;
81
+ table->header.dim = argc;
82
+ table->header.data_size = table->header.xsize * table->header.ysize * table->header.zsize;
83
+ table->heap = new long[table->header.data_size];
84
+ return self;
85
+ }
86
+
87
+ VALUE rb_Table32_get(int argc, VALUE* argv, VALUE self)
88
+ {
89
+ GET_TABLE
90
+ VALUE rx, ry, rz;
91
+ unsigned long x, y, z;
92
+ rb_scan_args(argc, argv, "12", &rx, &ry, &rz);
93
+ x = rb_num2ulong(rx);
94
+ y = NIL_P(ry) ? 0 : rb_num2ulong(ry);
95
+ z = NIL_P(rz) ? 0 : rb_num2ulong(rz);
96
+ if(x >= table->header.xsize || y >= table->header.ysize || z >= table->header.zsize)
97
+ return Qnil;
98
+ return rb_int2inum(table->heap[x + (y * table->header.xsize) + (z * table->header.xsize * table->header.ysize)]);
99
+ }
100
+
101
+ VALUE rb_Table32_set(int argc, VALUE* argv, VALUE self)
102
+ {
103
+ GET_TABLE
104
+ VALUE rx, ry, rz, rv;
105
+ unsigned long x, y, z;
106
+ long v;
107
+ rb_scan_args(argc, argv, "22", &rx, &ry, &rz, &rv);
108
+ x = rb_num2ulong(rx);
109
+ if(NIL_P(rz))
110
+ {
111
+ v = RB_NUM2LONG(ry);
112
+ z = y = 0;
113
+ }
114
+ else if(NIL_P(rv))
115
+ {
116
+ v = RB_NUM2LONG(rz);
117
+ y = rb_num2ulong(ry);
118
+ z = 0;
119
+ }
120
+ else
121
+ {
122
+ y = rb_num2ulong(ry);
123
+ z = rb_num2ulong(rz);
124
+ v = RB_NUM2LONG(rv);
125
+ }
126
+ if(x >= table->header.xsize || y >= table->header.ysize || z >= table->header.zsize)
127
+ return Qnil;
128
+ table->heap[x + (y * table->header.xsize) + (z * table->header.xsize * table->header.ysize)] = v;
129
+ return self;
130
+ }
131
+
132
+ VALUE rb_Table32_xSize(VALUE self)
133
+ {
134
+ GET_TABLE
135
+ return rb_uint2inum(table->header.xsize);
136
+ }
137
+
138
+ VALUE rb_Table32_ySize(VALUE self)
139
+ {
140
+ GET_TABLE
141
+ return rb_uint2inum(table->header.ysize);
142
+ }
143
+
144
+ VALUE rb_Table32_zSize(VALUE self)
145
+ {
146
+ GET_TABLE
147
+ return rb_uint2inum(table->header.zsize);
148
+ }
149
+
150
+ VALUE rb_Table32_dim(VALUE self)
151
+ {
152
+ GET_TABLE
153
+ return rb_uint2inum(table->header.dim);
154
+ }
155
+
156
+ void table_copy(long* dheap, long* sheap, unsigned long dxsize, unsigned long dysize,
157
+ unsigned long dzsize, unsigned long sxsize, unsigned long sysize, unsigned long szsize)
158
+ {
159
+ unsigned long xsize, ysize, zsize, soy, soz, doy, doz, x, y, z;
160
+ xsize = dxsize < sxsize ? dxsize : sxsize;
161
+ ysize = dysize < sysize ? dysize : sysize;
162
+ zsize = dzsize < szsize ? dzsize : szsize;
163
+ for(z = 0; z < zsize; z++)
164
+ {
165
+ doz = z * dxsize * dysize;
166
+ soz = z * sxsize * sysize; // optimisable => del soz, repl soz par soy
167
+ for(y = 0; y < ysize; y++)
168
+ {
169
+ doy = doz + (y * dxsize);
170
+ soy = soz + (y * sxsize); // optimisable => add after for{} soy += sxsize;
171
+ for(x = 0; x < xsize; x++)
172
+ {
173
+ dheap[doy++] = sheap[soy++];
174
+ }
175
+ }
176
+ }
177
+ }
178
+
179
+ VALUE rb_Table32_resize(int argc, VALUE* argv, VALUE self)
180
+ {
181
+ GET_TABLE
182
+ auto table2 = *table;
183
+ rb_Table32_initialize(argc, argv, self);
184
+ // Copying data
185
+ table_copy(table->heap, table2.heap,
186
+ table->header.xsize, table->header.ysize, table->header.zsize,
187
+ table2.header.xsize, table2.header.ysize, table2.header.zsize);
188
+ // Freeing heap
189
+ delete[] table2.heap;
190
+ return self;
191
+ }
192
+
193
+
194
+ VALUE rb_Table32_Load(VALUE self, VALUE str)
195
+ {
196
+ rb_check_type(str, T_STRING);
197
+ rb_Table32_Struct* table = reinterpret_cast<rb_Table32_Struct*>(RSTRING_PTR(str));
198
+ VALUE arr[3];
199
+ arr[0] = RB_UINT2NUM(table->header.xsize);
200
+ arr[1] = RB_UINT2NUM(table->header.ysize);
201
+ arr[2] = RB_UINT2NUM(table->header.zsize);
202
+ table->header.dim = normalize_long(table->header.dim, 1, 3);
203
+ VALUE rtable = rb_class_new_instance(table->header.dim, arr, self);
204
+ Data_Get_Struct(rtable, rb_Table32_Struct, table);
205
+ memcpy(table->heap, RSTRING_PTR(str) + sizeof(rb_Table32_Struct_Header), table->header.data_size * sizeof(long));
206
+ return rtable;
207
+ }
208
+
209
+ VALUE rb_Table32_Save(VALUE self, VALUE limit)
210
+ {
211
+ GET_TABLE
212
+ VALUE str1 = rb_str_new(reinterpret_cast<char*>(&table->header), sizeof(rb_Table32_Struct_Header));
213
+ VALUE str2 = rb_str_new(reinterpret_cast<char*>(table->heap), table->header.data_size * sizeof(long));
214
+ return rb_str_concat(str1, str2);
215
+ }
216
+
217
+ VALUE rb_Table32_Fill(VALUE self, VALUE val)
218
+ {
219
+ GET_TABLE
220
+ long v = RB_NUM2LONG(val);
221
+ unsigned long sz = table->header.data_size;
222
+ long* data = table->heap;
223
+ for(unsigned long i = 0;i < sz;i++)
224
+ {
225
+ data[i] = v;
226
+ }
227
+ return self;
228
+ }