dxrubynd 1.4.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,392 @@
1
+ #include "ruby/version.h"
2
+ #include "ruby/encoding.h"
3
+ #include <stdlib.h>
4
+ #include <mmsystem.h>
5
+ #include <tchar.h>
6
+ #include <d3d9.h>
7
+ #include <d3dx9.h>
8
+ #include <memory.h>
9
+ #include <math.h>
10
+ #include <d3d9types.h>
11
+ #include <WINNLS32.H>
12
+ //#include <dshow.h>
13
+
14
+ #include "version.h"
15
+
16
+ /* Ruby1.8�̌Â��ق��Ή� */
17
+ #ifndef RSTRING_PTR
18
+ # define RSTRING_PTR(s) (RSTRING(s)->ptr)
19
+ #endif
20
+ #ifndef RSTRING_LEN
21
+ # define RSTRING_LEN(s) (RSTRING(s)->len)
22
+ #endif
23
+
24
+ #ifndef RARRAY_PTR
25
+ # define RARRAY_PTR(s) (RARRAY(s)->ptr)
26
+ #endif
27
+ #ifndef RARRAY_LEN
28
+ # define RARRAY_LEN(s) (RARRAY(s)->len)
29
+ #endif
30
+
31
+ #ifndef RARRAY_AREF
32
+ # define RARRAY_AREF(a, i) (RARRAY_PTR(a)[i])
33
+ #endif
34
+
35
+ #ifndef RARRAY_ASET
36
+ # define RARRAY_ASET(a, i, v) (RARRAY_PTR(a)[i] = v)
37
+ #endif
38
+
39
+ #ifndef RARRAY_PTR_USE_START
40
+ # define RARRAY_PTR_USE_START(a) /* */
41
+ #endif
42
+
43
+ #ifndef RARRAY_PTR_USE_END
44
+ # define RARRAY_PTR_USE_END(a) /* */
45
+ #endif
46
+
47
+ #ifndef RARRAY_PTR_USE
48
+ # define RARRAY_PTR_USE(ary, ptr_name, expr) do { \
49
+ expr; \
50
+ } while (0)
51
+ #endif
52
+
53
+ #ifndef OBJ_WRITE
54
+ # define OBJ_WRITE(obj, slot, data) *slot=data;
55
+ #endif
56
+
57
+ #ifdef RUBY_VERSION_MAJOR
58
+ # if !(RUBY_VERSION_MAJOR == 1 || RUBY_API_VERSION_MAJOR == 1 || (RUBY_API_VERSION_MAJOR == 2 && RUBY_API_VERSION_MINOR == 0))
59
+ # define DXRUBY_USE_TYPEDDATA
60
+ # endif
61
+ #endif
62
+
63
+ #ifdef DXRUBY_USE_TYPEDDATA
64
+ # define DXRUBY_CHECK_TYPE( a, b ) \
65
+ if( !RB_TYPE_P(b, T_DATA) || RTYPEDDATA_TYPE(b) != &a##_data_type) {\
66
+ rb_raise(rb_eTypeError, "wrong argument type %s (expected DXRuby::"#a")", rb_obj_classname( b ));}
67
+ # define DXRUBY_CHECK_IMAGE( a ) \
68
+ if( !RB_TYPE_P(a, T_DATA) || (RTYPEDDATA_TYPE(a) != &Image_data_type && RTYPEDDATA_TYPE(a) != &RenderTarget_data_type) ) {\
69
+ rb_raise(rb_eTypeError, "wrong argument type %s (expected DXRuby::Image or DXRuby::RenderTarget)", rb_obj_classname( a ));}
70
+ # define DXRUBY_GET_STRUCT( c, v ) ((struct DXRuby##c *)RTYPEDDATA_DATA( v ))
71
+ # define DXRUBY_CHECK( a, b ) ( RB_TYPE_P(b, T_DATA) && RTYPEDDATA_TYPE(b) == &a##_data_type )
72
+ #else
73
+ # define DXRUBY_CHECK_TYPE( a, b ) \
74
+ {if( TYPE( b ) != T_DATA || RDATA( b )->dfree != (RUBY_DATA_FUNC)a##_release )\
75
+ rb_raise(rb_eTypeError, "wrong argument type %s (expected DXRuby::"#a")", rb_obj_classname( b ));}
76
+ # define DXRUBY_CHECK_IMAGE( a ) \
77
+ {if( TYPE( a ) != T_DATA || (RDATA( a )->dfree != (RUBY_DATA_FUNC)Image_release && RDATA( a )->dfree != (RUBY_DATA_FUNC)RenderTarget_release) )\
78
+ rb_raise(rb_eTypeError, "wrong argument type %s (expected DXRuby::Image or DXRuby::RenderTarget)", rb_obj_classname( a ));}
79
+ # define DXRUBY_GET_STRUCT( c, v ) ((struct DXRuby##c *)DATA_PTR( v ))
80
+ # define DXRUBY_CHECK( a, b ) ( TYPE( b ) == T_DATA && RDATA( b )->dfree == (RUBY_DATA_FUNC)a##_release )
81
+ #endif
82
+
83
+ #define DXRUBY_CHECK_DISPOSE( a, b ) {if( a->b == NULL ) { rb_raise( eDXRubyError, "disposed object" );}}
84
+ #define NUM2FLOAT( x ) ((float)( FIXNUM_P(x) ? FIX2INT(x) : NUM2DBL(x) ))
85
+ #define RELEASE( x ) if( x ) { if(FAILED(x->lpVtbl->Release( x )))rb_raise(eDXRubyError,"release error"); x = NULL; }
86
+ #define DXRUBY_RETRY_START {retry_flag = FALSE;do {
87
+ #define DXRUBY_RETRY_END if( FAILED( hr ) && !retry_flag ){rb_gc_start();retry_flag = TRUE;}else{retry_flag = FALSE;}} while( retry_flag );}
88
+
89
+ #define FORMAT_JPEG D3DXIFF_JPG
90
+ #define FORMAT_JPG D3DXIFF_JPG
91
+ #define FORMAT_PNG D3DXIFF_PNG
92
+ #define FORMAT_BMP D3DXIFF_BMP
93
+ #define FORMAT_DDS D3DXIFF_DDS
94
+
95
+ #define IME_BUF_SIZE 1024
96
+ #define IME_VK_BUF_SIZE 1024
97
+
98
+ struct DXRubyWindowInfo {
99
+ int x; /* �����W */
100
+ int y; /* �����W */
101
+ int width; /* �� */
102
+ int height; /* ���� */
103
+ int windowed; /* �E�B���h�E���[�h����true */
104
+ int created; /* �E�B���h�E���쐬������true */
105
+ float scale; /* �E�B���h�E�̃T�C�Y�{�� */
106
+ // int RefreshRate; /* ���t���b�V�����[�g */
107
+ int enablemouse; /* �}�E�X��\�����邩�ǂ��� */
108
+ int mousewheelpos; /* �}�E�X�z�C�[���̈ʒu */
109
+ int fps; /* fps */
110
+ int fpscheck; /* ���݂�fps */
111
+ int frameskip; /* �R�}��������t���O */
112
+ HANDLE hIcon; /* �E�B���h�E�A�C�R���n���h�� */
113
+ int input_updated; /* ���͍X�V������1 */
114
+ int requestclose; /* �E�B���h�E���‚���ꂽ��1 */
115
+ VALUE render_target; /* �X�N���[�������_�[�^�[�Q�b�g */
116
+ VALUE before_call; /* ���t���[�������ōŏ��ɌĂ΂�� */
117
+ VALUE after_call; /* ���t���[�������ōŌ�ɌĂ΂�� */
118
+ VALUE image_array; /* DrawFontEx�ɂ�鎩������Image�u���� */
119
+ int active; /* �Q�[�������p */
120
+ LPD3DXEFFECT pD3DXEffectCircleShader; /* �~�`��pShader */
121
+ LPD3DXEFFECT pD3DXEffectCircleFillShader; /* �h��‚Ԃ��~�`��pShader */
122
+ };
123
+
124
+ /* �s�N�`���z�� */
125
+ static struct DXRubyPictureList {
126
+ float z; /* �s�N�`����Z���W */
127
+ struct DXRubyPicture *picture; /* �s�N�`���\���̂ւ̃|�C���^ */
128
+ };
129
+
130
+ /* �e�N�X�`���f�[�^ */
131
+ struct DXRubyTexture {
132
+ LPDIRECT3DTEXTURE9 pD3DTexture; /* �s�N�`���Ɏg���e�N�X�`�� */
133
+ float width;
134
+ float height;
135
+ int refcount;
136
+ };
137
+
138
+ /* RenderTarget�I�u�W�F�N�g�̒��g */
139
+ struct DXRubyRenderTarget {
140
+ struct DXRubyTexture *texture;
141
+ int x; /* x�n�_�ʒu */
142
+ int y; /* y�n�_�ʒu */
143
+ int width; /* �C���[�W�̕� */
144
+ int height;/* �C���[�W�̍��� */
145
+ // int lockcount; /* ���b�N�J�E���g �����܂�Image�Ƌ��� */
146
+ IDirect3DSurface9 *surface;
147
+
148
+ int PictureCount; /* �s�N�`���̓o�^�� */
149
+ int PictureAllocateCount; /* �s�N�`���o�^�̃������m�ې� */
150
+ int PictureSize; /* �s�N�`���f�[�^�̎g�p�ς݃T�C�Y */
151
+ int PictureAllocateSize; /* �s�N�`���f�[�^�̃������m�ۃT�C�Y */
152
+ char *PictureStruct;
153
+
154
+ struct DXRubyPictureList *PictureList;
155
+
156
+ int minfilter; /* �k���t�B���^ */
157
+ int magfilter; /* �g��t�B���^ */
158
+
159
+ int a; /* �w�i�N���A�F ������ */
160
+ int r; /* �w�i�N���A�F �Ԑ��� */
161
+ int g; /* �w�i�N���A�F �ΐ��� */
162
+ int b; /* �w�i�N���A�F ���� */
163
+
164
+ #ifdef DXRUBY15
165
+ VALUE vregenerate_proc;
166
+ #endif
167
+
168
+ int PictureDecideCount; /* �s�N�`���̓o�^�m�萔 */
169
+ int PictureDecideSize; /* �s�N�`���f�[�^�̓o�^�m��T�C�Y */
170
+ int clearflag; /* 1�t���[��1��̃N���A��������������ǂ��� */
171
+
172
+ int ox; /* �r���[�ϊ��␳x */
173
+ int oy; /* �r���[�ϊ��␳y */
174
+ };
175
+
176
+ struct DXRubyPicture_drawLine {
177
+ void (*func)(void*);
178
+ VALUE value;
179
+ unsigned char blendflag; /* ������(000)�A���Z����1(100)�A���Z����2(101)�A���Z����1(110)�A���Z����2(111)�̃t���O */
180
+ unsigned char alpha; /* �A���t�@�i�����j�l */
181
+ char reserve1; /* �\��3 */
182
+ char reserve2; /* �\��4 */
183
+ int x1;
184
+ int y1;
185
+ int x2;
186
+ int y2;
187
+ float z;
188
+ int col;
189
+ };
190
+
191
+ struct DXRubyPicture_drawCircle {
192
+ void (*func)(void*);
193
+ VALUE value;
194
+ unsigned char blendflag; /* ������(000)�A���Z����1(100)�A���Z����2(101)�A���Z����1(110)�A���Z����2(111)�̃t���O */
195
+ unsigned char alpha; /* �A���t�@�i�����j�l */
196
+ char reserve1; /* �\��3 */
197
+ char reserve2; /* �\��4 */
198
+ int x;
199
+ int y;
200
+ int r;
201
+ float z;
202
+ int col;
203
+ };
204
+
205
+ struct DXRubyPicture_draw {
206
+ void (*func)(void*);
207
+ VALUE value;
208
+ unsigned char blendflag; /* ������(000)�A���Z����1(100)�A���Z����2(101)�A���Z����1(110)�A���Z����2(111)�̃t���O */
209
+ unsigned char alpha; /* �A���t�@�i�����j�l */
210
+ char reserve1; /* �\��3 */
211
+ char reserve2; /* �\��4 */
212
+ int x;
213
+ int y;
214
+ float z;
215
+ };
216
+
217
+ struct DXRubyPicture_drawEx {
218
+ void (*func)(void*);
219
+ VALUE value;
220
+ unsigned char blendflag; /* ������(000)�A���Z����1(100)�A���Z����2(101)�A���Z����1(110)�A���Z����2(111)�̃t���O */
221
+ unsigned char alpha; /* �A���t�@�i�����j�l */
222
+ char reserve1; /* �\��3 */
223
+ char reserve2; /* �\��4 */
224
+ int x;
225
+ int y;
226
+ float z;
227
+ float scalex;
228
+ float scaley;
229
+ float centerx;
230
+ float centery;
231
+ float angle;
232
+ };
233
+
234
+ struct DXRubyPicture_drawFont {
235
+ void (*func)(void*);
236
+ VALUE value;
237
+ unsigned char blendflag; /* ������(000)�A���Z����1(100)�A���Z����2(101)�A���Z����1(110)�A���Z����2(111)�̃t���O */
238
+ unsigned char alpha; /* �A���t�@�i�����j�l */
239
+ char reserve1; /* �\��3 */
240
+ char reserve2; /* �\��4 */
241
+ int x;
242
+ int y;
243
+ int z;
244
+ float scalex;
245
+ float scaley;
246
+ float centerx;
247
+ float centery;
248
+ float angle;
249
+ int color; /* �t�H���g�̐F */
250
+ };
251
+
252
+ struct DXRubyPicture_drawMorph {
253
+ void (*func)(void*);
254
+ VALUE value;
255
+ unsigned char blendflag; /* ������(000)�A���Z����1(100)�A���Z����2(101)�A���Z����1(110)�A���Z����2(111)�̃t���O */
256
+ unsigned char alpha; /* �A���t�@�i�����j�l */
257
+ char reserve1; /* �\��3 */
258
+ char reserve2; /* �\��4 */
259
+ float x1;
260
+ float y1;
261
+ float x2;
262
+ float y2;
263
+ float x3;
264
+ float y3;
265
+ float x4;
266
+ float y4;
267
+ float z;
268
+ int dividex;
269
+ int dividey;
270
+ char colorflag, r, g, b;
271
+ };
272
+
273
+ struct DXRubyPicture_drawTile {
274
+ void (*func)(void*);
275
+ VALUE value;
276
+ unsigned char blendflag; /* ������(000)�A���Z����1(100)�A���Z����2(101)�A���Z����1(110)�A���Z����2(111)�̃t���O */
277
+ unsigned char alpha; /* �A���t�@�i�����j�l */
278
+ char reserve1; /* �\��3 */
279
+ char reserve2; /* �\��4 */
280
+ int basex;
281
+ int basey;
282
+ int sizex;
283
+ int sizey;
284
+ int startx;
285
+ int starty;
286
+ float z;
287
+ };
288
+
289
+ /* ShaderCore */
290
+ struct DXRubyShaderCore {
291
+ LPD3DXEFFECT pD3DXEffect;
292
+ VALUE vtype; /* �������ƌ^�̃Z�b�g */
293
+ };
294
+
295
+ /* Shader */
296
+ struct DXRubyShader {
297
+ VALUE vcore;
298
+ VALUE vparam; /* �������ƒ��g�̃Z�b�g*/
299
+ VALUE vname;
300
+ };
301
+
302
+
303
+ #ifdef DXRUBY_EXTERN
304
+ extern HINSTANCE g_hInstance; /* �A�v���P�[�V�����C���X�^���X */
305
+ extern HANDLE g_hWnd; /* �E�B���h�E�n���h�� */
306
+ extern int g_iRefAll; /* �C���^�[�t�F�[�X�̎Q�ƃJ�E���g */
307
+
308
+ extern LPDIRECT3D9 g_pD3D; /* Direct3D�C���^�[�t�F�C�X */
309
+ extern LPDIRECT3DDEVICE9 g_pD3DDevice; /* Direct3DDevice�C���^�[�t�F�C�X */
310
+ extern D3DPRESENT_PARAMETERS g_D3DPP; /* D3DDevice�̐ݒ� */
311
+ extern LPD3DXSPRITE g_pD3DXSprite; /* D3DXSprite */
312
+ extern struct DXRubyLostList {
313
+ void **pointer;
314
+ int allocate_size;
315
+ int count;
316
+ } g_RenderTargetList, g_ShaderCoreList;
317
+ extern int g_sync; /* �����������[�h = 1 */
318
+ extern int retry_flag;
319
+ extern BYTE g_byMouseState_L_buf;
320
+ extern BYTE g_byMouseState_M_buf;
321
+ extern BYTE g_byMouseState_R_buf;
322
+
323
+ /* �G���R�[�f�B���O��� */
324
+ extern rb_encoding *g_enc_sys;
325
+ extern rb_encoding *g_enc_utf16;
326
+ extern rb_encoding *g_enc_utf8;
327
+
328
+ extern struct DXRubyWindowInfo g_WindowInfo;
329
+ extern char sys_encode[256];
330
+
331
+ extern VALUE mDXRuby; /* DXRuby���W���[�� */
332
+ extern VALUE eDXRubyError; /* ��O */
333
+ extern VALUE mWindow; /* �E�B���h�E���W���[�� */
334
+ extern VALUE cRenderTarget; /* �����_�[�^�[�Q�b�g�N���X */
335
+ extern VALUE cShaderCore; /* �V�F�[�_�R�A�N���X */
336
+ extern VALUE cShader; /* �V�F�[�_�N���X */
337
+
338
+ /* �V���{�� */
339
+ extern VALUE symbol_blend;
340
+ extern VALUE symbol_angle;
341
+ extern VALUE symbol_alpha;
342
+ extern VALUE symbol_scalex;
343
+ extern VALUE symbol_scale_x;
344
+ extern VALUE symbol_scaley;
345
+ extern VALUE symbol_scale_y;
346
+ extern VALUE symbol_centerx;
347
+ extern VALUE symbol_center_x;
348
+ extern VALUE symbol_centery;
349
+ extern VALUE symbol_center_y;
350
+ extern VALUE symbol_z;
351
+ extern VALUE symbol_color;
352
+ extern VALUE symbol_add;
353
+ extern VALUE symbol_add2;
354
+ extern VALUE symbol_sub;
355
+ extern VALUE symbol_sub2;
356
+ extern VALUE symbol_none;
357
+ extern VALUE symbol_offset_sync;
358
+ extern VALUE symbol_dividex;
359
+ extern VALUE symbol_dividey;
360
+ extern VALUE symbol_edge;
361
+ extern VALUE symbol_edge_color;
362
+ extern VALUE symbol_edge_width;
363
+ extern VALUE symbol_edge_level;
364
+ extern VALUE symbol_shadow;
365
+ extern VALUE symbol_shadow_color;
366
+ extern VALUE symbol_shadow_x;
367
+ extern VALUE symbol_shadow_y;
368
+ extern VALUE symbol_shadow_edge;
369
+ extern VALUE symbol_shader;
370
+ extern VALUE symbol_int;
371
+ extern VALUE symbol_float;
372
+ extern VALUE symbol_texture;
373
+ extern VALUE symbol_technique;
374
+ extern VALUE symbol_discard;
375
+ extern VALUE symbol_aa;
376
+ extern VALUE symbol_call;
377
+
378
+ extern int MainThreadError;
379
+ #endif
380
+
381
+ void *RenderTarget_AllocPictureList( struct DXRubyRenderTarget *rt, int size );
382
+ void RenderTarget_draw_func( struct DXRubyPicture_draw *picture );
383
+ void RenderTarget_drawShader_func( struct DXRubyPicture_draw *picture );
384
+ void RenderTarget_drawEx_func( struct DXRubyPicture_drawEx *picture );
385
+ void RenderTarget_release( struct DXRubyRenderTarget* rt );
386
+ void ShaderCore_release( struct DXRubyShaderCore *core );
387
+ void Shader_release( struct DXRubyShader *shader );
388
+ VALUE RenderTarget_update( VALUE self );
389
+ //int Window_drawShader_func_foreach_lock( VALUE key, VALUE value, VALUE obj );
390
+
391
+ VALUE hash_lookup(VALUE hash, VALUE key);
392
+
@@ -0,0 +1,29 @@
1
+ require "mkmf"
2
+
3
+ SYSTEM_LIBRARIES = [
4
+ "dxguid",
5
+ "d3d9",
6
+ ["d3dx9_40", "d3dx9"],
7
+ "dinput8",
8
+ "dsound",
9
+ "gdi32",
10
+ "ole32",
11
+ "user32",
12
+ "kernel32",
13
+ "comdlg32",
14
+ "winmm",
15
+ "uuid",
16
+ "imm32",
17
+ ]
18
+
19
+ SYSTEM_LIBRARIES.each do |libs|
20
+ [*libs].any? {|lib| have_library(lib) }
21
+ end
22
+
23
+ #�w�b�_�t�@�C������Ă܂��񂪒��ׂ�̖ʓ|��(^-^;
24
+
25
+ have_header("d3dx9.h")
26
+ have_header("dinput.h")
27
+ have_func("rb_enc_str_new")
28
+
29
+ create_makefile("dxruby")