sfml.js 0.0.1-preview.38 → 0.0.1-preview.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -4
- package/binding.gyp +34 -0
- package/lib/color.js +5 -2
- package/lib/image.js +17 -4
- package/lib/keyboard.js +3 -1
- package/lib/rect.js +28 -8
- package/lib/render_window.js +3 -1
- package/lib/vector2.js +26 -12
- package/lib/vertex.js +4 -2
- package/lib/video_mode.js +14 -4
- package/package.json +8 -3
- package/src/color.cc +4 -6
- package/src/drawable/package_plugin-inl.h +4 -3
- package/src/drawable/rectangle_shape.cc +3 -2
- package/src/drawable/shape.cc +3 -1
- package/src/drawable/vertex_array.cc +3 -3
- package/src/font.cc +6 -4
- package/src/image.cc +4 -5
- package/src/image.h +1 -1
- package/src/mouse.cc +2 -1
- package/src/plugins/transformable_plugin-inl.h +2 -2
- package/src/rect-inl.h +12 -8
- package/src/rect.h +1 -1
- package/src/render_window.cc +4 -3
- package/src/resizable_buffer.h +18 -2
- package/src/texture.cc +2 -2
- package/src/utils-inl.h +2 -2
- package/src/vector2-inl.h +13 -13
- package/src/vector2.h +3 -3
- package/src/vertex.cc +66 -28
- package/src/vertex.h +2 -2
- package/third_party/sfml/platform/win64/bin/openal32.dll +0 -0
- package/third_party/sfml/platform/win64/bin/sfml-audio-2.dll +0 -0
- package/third_party/sfml/platform/win64/bin/sfml-graphics-2.dll +0 -0
- package/third_party/sfml/platform/win64/bin/sfml-network-2.dll +0 -0
- package/third_party/sfml/platform/win64/bin/sfml-system-2.dll +0 -0
- package/third_party/sfml/platform/win64/bin/sfml-window-2.dll +0 -0
- package/third_party/sfml/platform/win64/lib/flac.lib +0 -0
- package/third_party/sfml/platform/win64/lib/freetype.lib +0 -0
- package/third_party/sfml/platform/win64/lib/ogg.lib +0 -0
- package/third_party/sfml/platform/win64/lib/openal32.lib +0 -0
- package/third_party/sfml/platform/win64/lib/sfml-audio.lib +0 -0
- package/third_party/sfml/platform/win64/lib/sfml-graphics.lib +0 -0
- package/third_party/sfml/platform/win64/lib/sfml-main.lib +0 -0
- package/third_party/sfml/platform/win64/lib/sfml-network.lib +0 -0
- package/third_party/sfml/platform/win64/lib/sfml-system.lib +0 -0
- package/third_party/sfml/platform/win64/lib/sfml-window.lib +0 -0
- package/third_party/sfml/platform/win64/lib/vorbis.lib +0 -0
- package/third_party/sfml/platform/win64/lib/vorbisenc.lib +0 -0
- package/third_party/sfml/platform/win64/lib/vorbisfile.lib +0 -0
- package/tools/keycode.js +31 -20
- package/tools/mouse_button.js +52 -35
- package/tools/symlinks.js +15 -0
package/src/rect-inl.h
CHANGED
|
@@ -10,12 +10,11 @@ namespace rect {
|
|
|
10
10
|
#define TEMPLATE_INNER T, NAN_T, V8_T
|
|
11
11
|
|
|
12
12
|
template <typename T, typename NAN_T, class V8_T>
|
|
13
|
-
v8::MaybeLocal<v8::
|
|
13
|
+
v8::MaybeLocal<v8::Value> Rect<TEMPLATE_INNER>::NewRealInstance(
|
|
14
14
|
v8::Isolate* isolate, size_t argc, v8::Local<v8::Value>* argv) {
|
|
15
15
|
v8::Local<v8::Function> cons = real_constructor.Get(isolate);
|
|
16
16
|
|
|
17
|
-
v8::MaybeLocal<v8::
|
|
18
|
-
cons->NewInstance(isolate->GetCurrentContext(), argc, argv);
|
|
17
|
+
v8::MaybeLocal<v8::Value> maybe_ret = Nan::Call(cons, cons, argc, argv);
|
|
19
18
|
return maybe_ret;
|
|
20
19
|
}
|
|
21
20
|
|
|
@@ -82,9 +81,14 @@ NAN_METHOD(Rect<TEMPLATE_INNER>::Intersects) {
|
|
|
82
81
|
Nan::ObjectWrap::Unwrap<Rect<T, NAN_T, V8_T>>(info[0].As<v8::Object>());
|
|
83
82
|
|
|
84
83
|
v8::Local<v8::Function> cons = real_constructor.Get(info.GetIsolate());
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
84
|
+
Nan::TryCatch try_catch;
|
|
85
|
+
v8::MaybeLocal<v8::Value> maybe_ret = Nan::Call(cons, cons, 0, nullptr);
|
|
86
|
+
if (maybe_ret.IsEmpty()) {
|
|
87
|
+
try_catch.ReThrow();
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
v8::Local<v8::Object> ret = maybe_ret.ToLocalChecked().As<v8::Object>();
|
|
88
92
|
Rect<T, NAN_T, V8_T>* ret_rect =
|
|
89
93
|
Nan::ObjectWrap::Unwrap<Rect<T, NAN_T, V8_T>>(ret);
|
|
90
94
|
|
|
@@ -100,7 +104,7 @@ NAN_METHOD(Rect<TEMPLATE_INNER>::Intersects) {
|
|
|
100
104
|
template <typename T, typename NAN_T, class V8_T> \
|
|
101
105
|
NAN_METHOD(Rect<TEMPLATE_INNER>::name##Getter) { \
|
|
102
106
|
Rect<T, NAN_T, V8_T>* rect = \
|
|
103
|
-
Nan::ObjectWrap::Unwrap<Rect<T, NAN_T, V8_T>>(info.
|
|
107
|
+
Nan::ObjectWrap::Unwrap<Rect<T, NAN_T, V8_T>>(info.This()); \
|
|
104
108
|
v8::Local<V8_T> ret = \
|
|
105
109
|
Nan::New<V8_T>(static_cast<NAN_T>(rect->_rect.lowercase)); \
|
|
106
110
|
info.GetReturnValue().Set(ret); \
|
|
@@ -115,7 +119,7 @@ NAN_METHOD(Rect<TEMPLATE_INNER>::Intersects) {
|
|
|
115
119
|
\
|
|
116
120
|
NAN_T val = maybe_value.ToLocalChecked()->Value(); \
|
|
117
121
|
Rect<T, NAN_T, V8_T>* rect = \
|
|
118
|
-
Nan::ObjectWrap::Unwrap<Rect<T, NAN_T, V8_T>>(info.
|
|
122
|
+
Nan::ObjectWrap::Unwrap<Rect<T, NAN_T, V8_T>>(info.This()); \
|
|
119
123
|
rect->_rect.lowercase = static_cast<T>(val); \
|
|
120
124
|
}
|
|
121
125
|
|
package/src/rect.h
CHANGED
|
@@ -53,7 +53,7 @@ class Rect : public Nan::ObjectWrap {
|
|
|
53
53
|
Nan::SetMethod(func, "setRealConstructor", SetRealConstructor);
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
static v8::MaybeLocal<v8::
|
|
56
|
+
static v8::MaybeLocal<v8::Value> NewRealInstance(
|
|
57
57
|
v8::Isolate* isolate,
|
|
58
58
|
size_t argc = 0,
|
|
59
59
|
v8::Local<v8::Value>* argv = nullptr);
|
package/src/render_window.cc
CHANGED
|
@@ -16,6 +16,7 @@ using v8::Local;
|
|
|
16
16
|
using v8::MaybeLocal;
|
|
17
17
|
using v8::Object;
|
|
18
18
|
using v8::String;
|
|
19
|
+
using v8::Value;
|
|
19
20
|
|
|
20
21
|
Nan::Persistent<Function> constructor;
|
|
21
22
|
|
|
@@ -126,14 +127,14 @@ NAN_METHOD(RenderWindow::Capture) {
|
|
|
126
127
|
sf::Image img = window->_window->capture();
|
|
127
128
|
|
|
128
129
|
Nan::TryCatch try_catch;
|
|
129
|
-
MaybeLocal<
|
|
130
|
+
MaybeLocal<Value> maybe_img =
|
|
130
131
|
image::Image::NewRealInstance(info.GetIsolate());
|
|
131
132
|
if (maybe_img.IsEmpty()) {
|
|
132
133
|
try_catch.ReThrow();
|
|
133
134
|
return;
|
|
134
135
|
}
|
|
135
136
|
|
|
136
|
-
Local<Object> img_obj = maybe_img.ToLocalChecked();
|
|
137
|
+
Local<Object> img_obj = maybe_img.ToLocalChecked().As<Object>();
|
|
137
138
|
image::Image* node_sfml_img = Nan::ObjectWrap::Unwrap<image::Image>(img_obj);
|
|
138
139
|
node_sfml_img->SetInnerImage(img);
|
|
139
140
|
|
|
@@ -190,7 +191,7 @@ NAN_METHOD(RenderWindow::GetSize) {
|
|
|
190
191
|
sf::Vector2u vec = window->_window->getSize();
|
|
191
192
|
|
|
192
193
|
Nan::TryCatch try_catch;
|
|
193
|
-
MaybeLocal<
|
|
194
|
+
MaybeLocal<Value> maybe_vec =
|
|
194
195
|
vector2::Vector2U::NewRealInstance(info.GetIsolate(), vec);
|
|
195
196
|
if (maybe_vec.IsEmpty()) {
|
|
196
197
|
try_catch.ReThrow();
|
package/src/resizable_buffer.h
CHANGED
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
#define SRC_RESIZABLE_BUFFER_H_
|
|
3
3
|
|
|
4
4
|
#include <stdio.h>
|
|
5
|
+
|
|
6
|
+
#ifndef _WIN32
|
|
7
|
+
#include <string.h>
|
|
5
8
|
#include <unistd.h>
|
|
9
|
+
#endif
|
|
6
10
|
|
|
7
11
|
namespace node_sfml {
|
|
8
12
|
|
|
@@ -19,8 +23,13 @@ class ResizableBuffer {
|
|
|
19
23
|
inline ResizableBuffer()
|
|
20
24
|
: _buff(nullptr),
|
|
21
25
|
_length(0),
|
|
22
|
-
_byte_length(0)
|
|
23
|
-
|
|
26
|
+
_byte_length(0)
|
|
27
|
+
#ifndef _WIN32
|
|
28
|
+
,
|
|
29
|
+
_page_size(getpagesize())
|
|
30
|
+
#endif
|
|
31
|
+
{
|
|
32
|
+
}
|
|
24
33
|
|
|
25
34
|
explicit inline ResizableBuffer(size_t length) : ResizableBuffer() {
|
|
26
35
|
this->Realloc(length);
|
|
@@ -44,12 +53,16 @@ class ResizableBuffer {
|
|
|
44
53
|
_byte_length = _length * sizeof(T);
|
|
45
54
|
if (!_length) return;
|
|
46
55
|
|
|
56
|
+
#ifndef _WIN32
|
|
47
57
|
if (_byte_length >= _page_size) {
|
|
48
58
|
posix_memalign(
|
|
49
59
|
reinterpret_cast<void**>(&_buff), _page_size, _byte_length);
|
|
50
60
|
} else {
|
|
51
61
|
_buff = static_cast<T*>(valloc(_byte_length));
|
|
52
62
|
}
|
|
63
|
+
#else
|
|
64
|
+
_buff = static_cast<T*>(malloc(_byte_length));
|
|
65
|
+
#endif
|
|
53
66
|
|
|
54
67
|
memset(_buff, 0, _byte_length);
|
|
55
68
|
}
|
|
@@ -80,7 +93,10 @@ class ResizableBuffer {
|
|
|
80
93
|
T* _buff;
|
|
81
94
|
size_t _length;
|
|
82
95
|
size_t _byte_length;
|
|
96
|
+
|
|
97
|
+
#ifndef _WIN32
|
|
83
98
|
size_t _page_size;
|
|
99
|
+
#endif
|
|
84
100
|
};
|
|
85
101
|
|
|
86
102
|
} // namespace node_sfml
|
package/src/texture.cc
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#include "texture.h"
|
|
2
2
|
#include "image.h"
|
|
3
3
|
#include "rect.h"
|
|
4
|
-
#include "vector2.h"
|
|
4
|
+
#include "vector2-inl.h"
|
|
5
5
|
#include "workers/load_from_file_worker.h"
|
|
6
6
|
|
|
7
7
|
namespace node_sfml {
|
|
@@ -141,7 +141,7 @@ NAN_METHOD(Texture::GetSize) {
|
|
|
141
141
|
sf::Vector2u size = texture->_texture.getSize();
|
|
142
142
|
|
|
143
143
|
Nan::TryCatch try_catch;
|
|
144
|
-
MaybeLocal<
|
|
144
|
+
MaybeLocal<Value> size_obj =
|
|
145
145
|
vector2::Vector2<sf::Uint32, sf::Uint32, v8::Uint32>::NewRealInstance(
|
|
146
146
|
info.GetIsolate(), size);
|
|
147
147
|
if (size_obj.IsEmpty()) {
|
package/src/utils-inl.h
CHANGED
|
@@ -34,11 +34,11 @@ inline void V8StringToSFString(v8::Isolate* isolate,
|
|
|
34
34
|
return;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
ResizableBuffer<char> utf8_string(string_utf8_length);
|
|
37
|
+
ResizableBuffer<char> utf8_string(string_utf8_length + 1);
|
|
38
38
|
int wrote = v8_string->WriteUtf8(isolate, *utf8_string);
|
|
39
39
|
|
|
40
40
|
// TODO(XadillaX): Real length?
|
|
41
|
-
ResizableBuffer<wchar_t> wstr(wrote << 1);
|
|
41
|
+
ResizableBuffer<wchar_t> wstr((wrote << 1) + 1);
|
|
42
42
|
sf::Utf<8>::toWide(*utf8_string, *utf8_string + wrote, *wstr);
|
|
43
43
|
sf_string = sf::String(*wstr);
|
|
44
44
|
}
|
package/src/vector2-inl.h
CHANGED
|
@@ -13,7 +13,7 @@ NAN_METHOD(Subtract) {
|
|
|
13
13
|
T* right = Nan::ObjectWrap::Unwrap<T>(info[1].As<v8::Object>());
|
|
14
14
|
|
|
15
15
|
Nan::TryCatch try_catch;
|
|
16
|
-
v8::MaybeLocal<v8::
|
|
16
|
+
v8::MaybeLocal<v8::Value> ret =
|
|
17
17
|
T::NewRealInstance(info.GetIsolate(), left->vector2() - right->vector2());
|
|
18
18
|
if (ret.IsEmpty()) {
|
|
19
19
|
try_catch.ReThrow();
|
|
@@ -29,7 +29,7 @@ NAN_METHOD(Add) {
|
|
|
29
29
|
T* right = Nan::ObjectWrap::Unwrap<T>(info[1].As<v8::Object>());
|
|
30
30
|
|
|
31
31
|
Nan::TryCatch try_catch;
|
|
32
|
-
v8::MaybeLocal<v8::
|
|
32
|
+
v8::MaybeLocal<v8::Value> ret =
|
|
33
33
|
T::NewRealInstance(info.GetIsolate(), left->vector2() + right->vector2());
|
|
34
34
|
if (ret.IsEmpty()) {
|
|
35
35
|
try_catch.ReThrow();
|
|
@@ -45,7 +45,7 @@ NAN_METHOD(Multiply) {
|
|
|
45
45
|
T right = static_cast<T>(Nan::To<NAN_T>(info[1]).FromJust());
|
|
46
46
|
|
|
47
47
|
Nan::TryCatch try_catch;
|
|
48
|
-
v8::MaybeLocal<v8::
|
|
48
|
+
v8::MaybeLocal<v8::Value> ret =
|
|
49
49
|
Self::NewRealInstance(info.GetIsolate(), left->vector2() * right);
|
|
50
50
|
if (ret.IsEmpty()) {
|
|
51
51
|
try_catch.ReThrow();
|
|
@@ -61,7 +61,7 @@ NAN_METHOD(Div) {
|
|
|
61
61
|
T right = static_cast<T>(Nan::To<NAN_T>(info[1]).FromJust());
|
|
62
62
|
|
|
63
63
|
Nan::TryCatch try_catch;
|
|
64
|
-
v8::MaybeLocal<v8::
|
|
64
|
+
v8::MaybeLocal<v8::Value> ret =
|
|
65
65
|
Self::NewRealInstance(info.GetIsolate(), left->vector2() / right);
|
|
66
66
|
if (ret.IsEmpty()) {
|
|
67
67
|
try_catch.ReThrow();
|
|
@@ -88,27 +88,27 @@ NAN_METHOD(NotEquals) {
|
|
|
88
88
|
#define TEMPLATE_INNER T, NAN_T, V8_T
|
|
89
89
|
|
|
90
90
|
template <typename T, typename NAN_T, class V8_T>
|
|
91
|
-
v8::MaybeLocal<v8::
|
|
91
|
+
v8::MaybeLocal<v8::Value> Vector2<TEMPLATE_INNER>::NewRealInstance(
|
|
92
92
|
v8::Isolate* isolate, size_t argc, v8::Local<v8::Value>* argv) {
|
|
93
93
|
v8::Local<v8::Function> cons = real_constructor.Get(isolate);
|
|
94
94
|
if (cons.IsEmpty()) {
|
|
95
95
|
Nan::ThrowError("`real_constructor` is not set.");
|
|
96
|
-
return v8::MaybeLocal<v8::
|
|
96
|
+
return v8::MaybeLocal<v8::Value>();
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
v8::MaybeLocal<v8::
|
|
100
|
-
|
|
99
|
+
v8::MaybeLocal<v8::Value> maybe_ret = Nan::Call(cons, cons, argc, argv);
|
|
100
|
+
cons->NewInstance(isolate->GetCurrentContext(), argc, argv);
|
|
101
101
|
return maybe_ret;
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
template <typename T, typename NAN_T, class V8_T>
|
|
105
|
-
v8::MaybeLocal<v8::
|
|
105
|
+
v8::MaybeLocal<v8::Value> Vector2<TEMPLATE_INNER>::NewRealInstance(
|
|
106
106
|
v8::Isolate* isolate, const sf::Vector2<T>& src) {
|
|
107
|
-
v8::MaybeLocal<v8::
|
|
107
|
+
v8::MaybeLocal<v8::Value> maybe =
|
|
108
108
|
Vector2<TEMPLATE_INNER>::NewRealInstance(isolate);
|
|
109
109
|
if (maybe.IsEmpty()) return maybe;
|
|
110
110
|
|
|
111
|
-
v8::Local<v8::Object> vec = maybe.ToLocalChecked();
|
|
111
|
+
v8::Local<v8::Object> vec = maybe.ToLocalChecked().As<v8::Object>();
|
|
112
112
|
Vector2<TEMPLATE_INNER>* vec_wrapper =
|
|
113
113
|
Nan::ObjectWrap::Unwrap<Vector2<TEMPLATE_INNER>>(vec);
|
|
114
114
|
sf::Vector2<T>& v = vec_wrapper->vector2();
|
|
@@ -150,7 +150,7 @@ NAN_METHOD(Vector2<TEMPLATE_INNER>::New) {
|
|
|
150
150
|
template <typename T, typename NAN_T, class V8_T> \
|
|
151
151
|
NAN_METHOD(Vector2<TEMPLATE_INNER>::name##Getter) { \
|
|
152
152
|
Vector2<T, NAN_T, V8_T>* vec = \
|
|
153
|
-
Nan::ObjectWrap::Unwrap<Vector2<T, NAN_T, V8_T>>(info.
|
|
153
|
+
Nan::ObjectWrap::Unwrap<Vector2<T, NAN_T, V8_T>>(info.This()); \
|
|
154
154
|
v8::Local<V8_T> ret = \
|
|
155
155
|
Nan::New<V8_T>(static_cast<NAN_T>(vec->vector2().lowercase)); \
|
|
156
156
|
info.GetReturnValue().Set(ret); \
|
|
@@ -165,7 +165,7 @@ NAN_METHOD(Vector2<TEMPLATE_INNER>::New) {
|
|
|
165
165
|
\
|
|
166
166
|
NAN_T val = maybe_value.ToLocalChecked()->Value(); \
|
|
167
167
|
Vector2<T, NAN_T, V8_T>* vec = \
|
|
168
|
-
Nan::ObjectWrap::Unwrap<Vector2<T, NAN_T, V8_T>>(info.
|
|
168
|
+
Nan::ObjectWrap::Unwrap<Vector2<T, NAN_T, V8_T>>(info.This()); \
|
|
169
169
|
vec->vector2().lowercase = static_cast<T>(val); \
|
|
170
170
|
}
|
|
171
171
|
|
package/src/vector2.h
CHANGED
|
@@ -74,12 +74,12 @@ class Vector2 : public Nan::ObjectWrap {
|
|
|
74
74
|
Nan::SetMethod(func, "notEquals", NotEquals<Self>);
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
static v8::MaybeLocal<v8::
|
|
77
|
+
static v8::MaybeLocal<v8::Value> NewRealInstance(
|
|
78
78
|
v8::Isolate* isolate,
|
|
79
79
|
size_t argc = 0,
|
|
80
80
|
v8::Local<v8::Value>* argv = nullptr);
|
|
81
|
-
static v8::MaybeLocal<v8::
|
|
82
|
-
|
|
81
|
+
static v8::MaybeLocal<v8::Value> NewRealInstance(v8::Isolate* isolate,
|
|
82
|
+
const sf::Vector2<T>& src);
|
|
83
83
|
|
|
84
84
|
protected:
|
|
85
85
|
static NAN_METHOD(New);
|
package/src/vertex.cc
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
namespace node_sfml {
|
|
6
6
|
namespace vertex {
|
|
7
7
|
|
|
8
|
+
using v8::BigInt;
|
|
8
9
|
using v8::Function;
|
|
9
10
|
using v8::FunctionTemplate;
|
|
10
11
|
using v8::Isolate;
|
|
@@ -44,24 +45,23 @@ NAN_MODULE_INIT(Vertex::Init) {
|
|
|
44
45
|
Nan::Set(target, name, func);
|
|
45
46
|
}
|
|
46
47
|
|
|
47
|
-
MaybeLocal<
|
|
48
|
-
|
|
48
|
+
MaybeLocal<Value> Vertex::NewRealInstance(v8::Isolate* isolate,
|
|
49
|
+
const sf::Vertex& vertex) {
|
|
49
50
|
Nan::HandleScope scope;
|
|
50
51
|
|
|
51
52
|
v8::Local<v8::Function> cons = real_constructor.Get(isolate);
|
|
52
53
|
if (cons.IsEmpty()) {
|
|
53
54
|
Nan::ThrowError("`real_constructor` is not set.");
|
|
54
|
-
return v8::MaybeLocal<v8::
|
|
55
|
+
return v8::MaybeLocal<v8::Value>();
|
|
55
56
|
}
|
|
56
57
|
|
|
57
|
-
sf::
|
|
58
|
+
sf::Uint64 temp = reinterpret_cast<sf::Uint64>(&vertex);
|
|
58
59
|
Local<Value> argv[] = {
|
|
59
60
|
Nan::New(vertex::Vertex::new_from_pointer_magic_number),
|
|
60
|
-
|
|
61
|
+
BigInt::NewFromUnsigned(isolate, temp),
|
|
61
62
|
};
|
|
62
63
|
|
|
63
|
-
v8::MaybeLocal<v8::
|
|
64
|
-
cons->NewInstance(isolate->GetCurrentContext(), 2, argv);
|
|
64
|
+
v8::MaybeLocal<v8::Value> maybe_ret = Nan::Call(cons, cons, 2, argv);
|
|
65
65
|
return maybe_ret;
|
|
66
66
|
}
|
|
67
67
|
|
|
@@ -69,7 +69,8 @@ NAN_METHOD(Vertex::New) {
|
|
|
69
69
|
if (info[0]->IsNumber()) {
|
|
70
70
|
sf::Int32 magic_number = Nan::To<sf::Int32>(info[0]).FromJust();
|
|
71
71
|
if (magic_number == new_from_pointer_magic_number) {
|
|
72
|
-
|
|
72
|
+
Local<BigInt> big_int = info[1].As<BigInt>();
|
|
73
|
+
sf::Uint64 ptr = big_int->Uint64Value();
|
|
73
74
|
sf::Vertex* vertex = reinterpret_cast<sf::Vertex*>(ptr);
|
|
74
75
|
Vertex* ret = new Vertex(vertex);
|
|
75
76
|
ret->Wrap(info.This());
|
|
@@ -97,7 +98,7 @@ NAN_METHOD(Vertex::SyncFromJS) {
|
|
|
97
98
|
|
|
98
99
|
#define V(name, lowercase, snake_case, unwrap_type, inner_func) \
|
|
99
100
|
NAN_METHOD(Vertex::name##Getter) { \
|
|
100
|
-
Vertex* vertex = Nan::ObjectWrap::Unwrap<Vertex>(info.
|
|
101
|
+
Vertex* vertex = Nan::ObjectWrap::Unwrap<Vertex>(info.This()); \
|
|
101
102
|
info.GetReturnValue().Set(Nan::New<Object>(vertex->_##lowercase##_wrap)); \
|
|
102
103
|
vertex->_vtx->snake_case = *vertex->_##lowercase; \
|
|
103
104
|
} \
|
|
@@ -106,7 +107,7 @@ NAN_METHOD(Vertex::SyncFromJS) {
|
|
|
106
107
|
Local<Object> obj = info[0].As<Object>(); \
|
|
107
108
|
unwrap_type* obj_unwrapped = Nan::ObjectWrap::Unwrap<unwrap_type>(obj); \
|
|
108
109
|
\
|
|
109
|
-
Vertex* vertex = Nan::ObjectWrap::Unwrap<Vertex>(info.
|
|
110
|
+
Vertex* vertex = Nan::ObjectWrap::Unwrap<Vertex>(info.This()); \
|
|
110
111
|
vertex->_##lowercase = &obj_unwrapped->inner_func(); \
|
|
111
112
|
vertex->_##lowercase##_wrap.Reset(obj); \
|
|
112
113
|
vertex->SyncFromJS(k##name); \
|
|
@@ -119,21 +120,40 @@ Vertex::Vertex(sf::Vertex* src) {
|
|
|
119
120
|
_vtx =
|
|
120
121
|
std::make_unique<sf::Vertex>(src->position, src->color, src->texCoords);
|
|
121
122
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
123
|
+
MaybeLocal<Value> maybe_temp;
|
|
124
|
+
Local<Object> temp;
|
|
125
|
+
|
|
126
|
+
Nan::TryCatch try_catch;
|
|
127
|
+
maybe_temp =
|
|
128
|
+
vector2::Vector2F::NewRealInstance(Isolate::GetCurrent(), _vtx->position);
|
|
129
|
+
if (maybe_temp.IsEmpty()) {
|
|
130
|
+
try_catch.ReThrow();
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
temp = maybe_temp.ToLocalChecked().As<Object>();
|
|
125
135
|
_position_wrap.Reset(temp);
|
|
126
136
|
_position = &Nan::ObjectWrap::Unwrap<vector2::Vector2F>(temp)->vector2();
|
|
127
137
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
138
|
+
MaybeLocal<Object> maybe_color = color::Color::NewRealColorInstance(
|
|
139
|
+
Isolate::GetCurrent(), _vtx->color.toInteger());
|
|
140
|
+
if (maybe_color.IsEmpty()) {
|
|
141
|
+
try_catch.ReThrow();
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
temp = maybe_color.ToLocalChecked();
|
|
131
146
|
_color_wrap.Reset(temp);
|
|
132
147
|
_color = &Nan::ObjectWrap::Unwrap<color::Color>(temp)->color();
|
|
133
148
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
149
|
+
maybe_temp = vector2::Vector2F::NewRealInstance(Isolate::GetCurrent(),
|
|
150
|
+
_vtx->texCoords);
|
|
151
|
+
if (maybe_temp.IsEmpty()) {
|
|
152
|
+
try_catch.ReThrow();
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
temp = maybe_temp.ToLocalChecked().As<Object>();
|
|
137
157
|
_tex_coords_wrap.Reset(temp);
|
|
138
158
|
_tex_coords = &Nan::ObjectWrap::Unwrap<vector2::Vector2F>(temp)->vector2();
|
|
139
159
|
}
|
|
@@ -171,21 +191,39 @@ Vertex::Vertex(Local<Value> position,
|
|
|
171
191
|
}
|
|
172
192
|
}
|
|
173
193
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
194
|
+
Nan::TryCatch try_catch;
|
|
195
|
+
MaybeLocal<Value> maybe_temp;
|
|
196
|
+
Local<Object> temp;
|
|
197
|
+
maybe_temp =
|
|
198
|
+
vector2::Vector2F::NewRealInstance(Isolate::GetCurrent(), _vtx->position);
|
|
199
|
+
if (maybe_temp.IsEmpty()) {
|
|
200
|
+
try_catch.ReThrow();
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
temp = maybe_temp.ToLocalChecked().As<Object>();
|
|
177
205
|
_position_wrap.Reset(temp);
|
|
178
206
|
_position = &Nan::ObjectWrap::Unwrap<vector2::Vector2F>(temp)->vector2();
|
|
179
207
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
208
|
+
MaybeLocal<Object> maybe_color = color::Color::NewRealColorInstance(
|
|
209
|
+
Isolate::GetCurrent(), _vtx->color.toInteger());
|
|
210
|
+
if (maybe_color.IsEmpty()) {
|
|
211
|
+
try_catch.ReThrow();
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
temp = maybe_color.ToLocalChecked().As<Object>();
|
|
183
216
|
_color_wrap.Reset(temp);
|
|
184
217
|
_color = &Nan::ObjectWrap::Unwrap<color::Color>(temp)->color();
|
|
185
218
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
219
|
+
maybe_temp = vector2::Vector2F::NewRealInstance(Isolate::GetCurrent(),
|
|
220
|
+
_vtx->texCoords);
|
|
221
|
+
if (maybe_temp.IsEmpty()) {
|
|
222
|
+
try_catch.ReThrow();
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
temp = maybe_temp.ToLocalChecked().As<Object>();
|
|
189
227
|
_tex_coords_wrap.Reset(temp);
|
|
190
228
|
_tex_coords = &Nan::ObjectWrap::Unwrap<vector2::Vector2F>(temp)->vector2();
|
|
191
229
|
}
|
package/src/vertex.h
CHANGED
|
@@ -25,8 +25,8 @@ class Vertex : public Nan::ObjectWrap {
|
|
|
25
25
|
kAll,
|
|
26
26
|
};
|
|
27
27
|
|
|
28
|
-
static v8::MaybeLocal<v8::
|
|
29
|
-
|
|
28
|
+
static v8::MaybeLocal<v8::Value> NewRealInstance(v8::Isolate* isolate,
|
|
29
|
+
const sf::Vertex& vertex);
|
|
30
30
|
|
|
31
31
|
public:
|
|
32
32
|
static NAN_MODULE_INIT(Init);
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/tools/keycode.js
CHANGED
|
@@ -4,21 +4,26 @@ const cp = require('child_process');
|
|
|
4
4
|
const fs = require('fs');
|
|
5
5
|
const path = require('path');
|
|
6
6
|
|
|
7
|
-
const keyboardHpp = fs.readFileSync(
|
|
7
|
+
const keyboardHpp = fs.readFileSync(
|
|
8
|
+
path.join(__dirname, '../third_party/sfml/include/SFML/Window/Keyboard.hpp'));
|
|
8
9
|
|
|
9
10
|
let current = 0;
|
|
10
|
-
const extracted = /enum Key\W+{([\w\W]*)KeyCount
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
11
|
+
const extracted = /enum Key\W+{([\w\W]*)KeyCount,/
|
|
12
|
+
.exec(keyboardHpp)[1]
|
|
13
|
+
.trim()
|
|
14
|
+
.split('\n')
|
|
15
|
+
.map(line => {
|
|
16
|
+
line = line.trim().replace(/,\W*\/\/\/.+/, '');
|
|
17
|
+
|
|
18
|
+
const arr = line.split('=').map(c => c.trim());
|
|
19
|
+
if (arr.length >= 2) {
|
|
20
|
+
current = parseInt(arr[1]);
|
|
21
|
+
} else {
|
|
22
|
+
current++;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return [ arr[0], current ];
|
|
26
|
+
});
|
|
22
27
|
|
|
23
28
|
const str = `#include <map>
|
|
24
29
|
#include <string>
|
|
@@ -30,10 +35,12 @@ std::map<int, std::string> keycode_itoa;
|
|
|
30
35
|
std::map<std::string, int> keycode_atoi;
|
|
31
36
|
|
|
32
37
|
void InitKeyCode() {
|
|
33
|
-
${extracted
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
38
|
+
${extracted
|
|
39
|
+
.map(([ key, code ]) => {
|
|
40
|
+
return `keycode_itoa[${code}] = "${key}";
|
|
41
|
+
keycode_atoi["${key}"] = ${code};`;
|
|
42
|
+
})
|
|
43
|
+
.join('')}
|
|
37
44
|
}
|
|
38
45
|
|
|
39
46
|
} // namespace node_sfml
|
|
@@ -42,8 +49,12 @@ void InitKeyCode() {
|
|
|
42
49
|
|
|
43
50
|
fs.writeFileSync(path.join(__dirname, '../src/gen/keycode.cc'), str);
|
|
44
51
|
|
|
45
|
-
|
|
46
|
-
path.join(__dirname, 'clang_format.js'),
|
|
47
|
-
|
|
52
|
+
if (process.platform !== 'win32') {
|
|
53
|
+
cp.execFileSync(path.join(__dirname, 'clang_format.js'), [
|
|
54
|
+
'-style=file',
|
|
55
|
+
'-i',
|
|
56
|
+
path.join(__dirname, '../src/gen/keycode.cc'),
|
|
57
|
+
]);
|
|
58
|
+
}
|
|
48
59
|
|
|
49
60
|
console.log('./src/gen/keyboard.cc generated.');
|