Skip to content

Commit 1693d86

Browse files
committed
Integrate GDevelop.js (emscripten bindings of Core/Extensions to JS) inside the repository
1 parent ccc29ef commit 1693d86

28 files changed

+15014
-21
lines changed

.clang_complete

+5-9
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,13 @@
66
-DMACOS
77
-DRELEASE
88
-D_FILE_OFFSET_BITS=64
9-
-DwxDEBUG_LEVEL=0
109
-D_WCHAR_H_CPLUSPLUS_98_CONFORMANCE_
1110
-Wno-potentially-evaluated-expression
1211
-std=gnu++11
13-
-I/usr/local/Cellar/wxmac/3.0.2/include/wx-3.0
1412
-DNDEBUG
1513
-fPIC
16-
-I/Users/florian/Projects/F/GD/ExtLibs/SFML/include
17-
-I/Users/florian/Projects/F/GD/Core
18-
-I/usr/local/Cellar/wxmac/3.0.2/lib/wx/include/osx_cocoa-unicode-3.0
19-
-I/usr/local/Cellar/wxmac/3.0.2/include/wx-3.0
20-
-I/Users/florian/Projects/F/GD/GDCpp/.
21-
-I/Users/florian/Projects/F/GD/GDJS/.
22-
-F/Users/florian/Projects/F/GD/ExtLibs/SFML/extlibs/libs-osx/Frameworks
14+
-I./ExtLibs/SFML/include
15+
-I./Core
16+
-I./GDCpp/.
17+
-I./GDJS/.
18+
-F./ExtLibs/SFML/extlibs/libs-osx/Frameworks

.gitignore

-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
/Binaries/Releases/**/*.tar.lzma
1919
/Binaries/Releases/**/*.zip
2020
/Binaries/Releases/**/*.deb
21-
/GDevelop.js
2221
*.depend
2322
*.layout
2423
*.xgdwe
@@ -37,7 +36,6 @@
3736
/Binaries/Output/Release_Linux/**
3837
/Binaries/Output/Debug_Darwin/**
3938
/Binaries/Output/Release_Darwin/**
40-
/Binaries/Output/Frameworks/
4139
!/Binaries/Output/Release_Linux/StartGDevelop.sh
4240
!/Binaries/Output/Release_Linux/CppPlatform/
4341
/Binaries/**/MinGW32

.travis.yml

+35-10
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,20 @@ env:
1717
- GCC_VERSION="4.8"
1818

1919
addons:
20+
artifacts:
21+
s3_region: "us-east-1"
22+
paths:
23+
- Binaries/Output/libGD.js/Release
2024
apt:
2125
sources:
2226
- ubuntu-toolchain-r-test
2327
packages:
24-
#Build dependencies:
25-
- cmake
28+
# Build dependencies:
29+
# (Cmake 3+ is required by Emscripten)
30+
- cmake3
2631
- p7zip-full
2732
- g++-4.8
28-
#SFML dependencies:
33+
# SFML dependencies:
2934
- libopenal-dev
3035
- libjpeg-dev
3136
- libglew-dev
@@ -35,11 +40,14 @@ addons:
3540
- libglu1-mesa-dev
3641
- libfreetype6-dev
3742

38-
#Activate X Virtual Framebuffer to allow tests to
39-
#use SFML.
4043
before_install:
44+
#Activate X Virtual Framebuffer to allow tests to
45+
#use SFML.
4146
- "export DISPLAY=:99.0"
4247
- "sh -e /etc/init.d/xvfb start"
48+
# This workaround is required to avoid libstdc++ errors (Emscripten requires a recent version of libstdc++)
49+
- wget -q -O libstdc++6 http://security.ubuntu.com/ubuntu/pool/main/g/gcc-5/libstdc++6_5.4.0-6ubuntu1~16.04.10_amd64.deb
50+
- sudo dpkg --force-all -i libstdc++6
4351

4452
install:
4553
#Install newIDE tests dependencies
@@ -50,28 +58,45 @@ install:
5058
- cd ../..
5159
#Get the correct version of gcc/g++
5260
- if [ "$CXX" = "g++" ]; then export CXX="g++-${GCC_VERSION}" CC="gcc-${GCC_VERSION}"; fi
53-
#Compile the tests only
61+
#Compile the tests only for GDCore and GDCpp
5462
- mkdir .build-tests
5563
- cd .build-tests
5664
- cmake -DBUILD_GDJS=FALSE -DBUILD_TESTS=TRUE -DCMAKE_CXX_COMPILER=$(which $CXX) -DCMAKE_C_COMPILER=$(which $CC) ..
5765
- make -j 4
5866
- cd ..
67+
# Install Emscripten (for GDevelop.js)
68+
- git clone https://github.com/juj/emsdk.git
69+
- cd emsdk
70+
- ./emsdk install sdk-1.37.37-64bit
71+
- ./emsdk activate sdk-1.37.37-64bit
72+
- source ./emsdk_env.sh
73+
- cd ..
74+
# Install GDevelop.js dependencies
75+
- cd GDevelop.js
76+
- npm install -g grunt-cli
77+
- npm install
78+
- npm run build
79+
- cd ..
5980

6081
script:
61-
#GDCore and GDCpp game engine tests:
82+
# GDCore and GDCpp game engine tests:
6283
- cd .build-tests
6384
- Core/GDCore_tests
6485
- GDCpp/GDCpp_tests
6586
- Extensions/PathfindingBehavior/PathfindingBehavior_Runtime_tests
6687
- Extensions/LinkedObjects/LinkedObjects_Runtime_tests
6788
- cd ..
68-
#newIDE tests:
89+
# GDevelop.js tests
90+
- cd GDevelop.js
91+
- npm test
92+
- cd ..
93+
# newIDE tests:
6994
- cd newIDE/app
7095
- npm test
7196
- npm run flow
7297
- npm run check-format
7398
- cd ../..
74-
#GDJS game engine tests, disabled on Travis CI because ChromeHeadless can't be started.
75-
#See them running on Semaphore-CI instead: https://semaphoreci.com/4ian/gd
99+
# GDJS game engine tests, disabled on Travis CI because ChromeHeadless can't be started.
100+
# See them running on Semaphore-CI instead: https://semaphoreci.com/4ian/gd
76101
# - cd GDJS/tests && npm test
77102
# - cd ../..

GDevelop.js/.gitignore

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/node_modules
2+
Bindings/parser.out
3+
Bindings/WebIDLGrammar.pkl
4+
Bindings/glue.cpp
5+
Bindings/glue.js
6+
parser.out
7+
WebIDLGrammar.pkl
8+
.cpp.old
9+
examples/demo-generated-code.js
10+
examples/demo-generated-game.json
11+
**/.DS_Store

GDevelop.js/.prettierrc

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"singleQuote": true,
3+
"trailingComma": "es5"
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#include "BehaviorJsImplementation.h"
2+
#include <GDCore/IDE/Dialogs/PropertyDescriptor.h>
3+
#include <GDCore/Project/Behavior.h>
4+
#include <GDCore/Project/Project.h>
5+
#include <GDCore/Serialization/Serializer.h>
6+
#include <GDCore/Serialization/SerializerElement.h>
7+
#include <emscripten.h>
8+
#include <map>
9+
10+
using namespace gd;
11+
12+
BehaviorJsImplementation* BehaviorJsImplementation::Clone() const {
13+
BehaviorJsImplementation* clone = new BehaviorJsImplementation(*this);
14+
15+
// Copy the references to the JS implementations of the functions (because we
16+
// want an object cloned from C++ to retain the functions implemented in JS).
17+
EM_ASM_INT(
18+
{
19+
var clone =
20+
Module['wrapPointer']($0, Module['BehaviorJsImplementation']);
21+
var self =
22+
Module['wrapPointer']($1, Module['BehaviorJsImplementation']);
23+
24+
clone['getProperties'] = self['getProperties'];
25+
clone['updateProperty'] = self['updateProperty'];
26+
},
27+
(int)clone,
28+
(int)this);
29+
30+
return clone;
31+
}
32+
std::map<gd::String, gd::PropertyDescriptor>
33+
BehaviorJsImplementation::GetProperties(gd::Project&) const {
34+
std::map<gd::String, gd::PropertyDescriptor>* jsCreatedProperties = nullptr;
35+
std::map<gd::String, gd::PropertyDescriptor> copiedProperties;
36+
37+
jsCreatedProperties = (std::map<gd::String, gd::PropertyDescriptor>*)EM_ASM_INT(
38+
{
39+
var self = Module['getCache'](Module['BehaviorJsImplementation'])[$0];
40+
if (!self.hasOwnProperty('getProperties'))
41+
throw 'getProperties is not defined on a BehaviorJsImplementation.';
42+
43+
var objectContent = JSON.parse(Pointer_stringify($1));
44+
var newProperties = self['getProperties'](objectContent);
45+
if (!newProperties)
46+
throw 'getProperties returned nothing in a gd::BehaviorJsImplementation.';
47+
48+
return getPointer(newProperties);
49+
},
50+
(int)this,
51+
jsonContent.c_str());
52+
53+
copiedProperties = *jsCreatedProperties;
54+
delete jsCreatedProperties;
55+
return copiedProperties;
56+
}
57+
bool BehaviorJsImplementation::UpdateProperty(const gd::String& arg0,
58+
const gd::String& arg1,
59+
Project&) {
60+
jsonContent = (const char*)EM_ASM_INT(
61+
{
62+
var self = Module['getCache'](Module['BehaviorJsImplementation'])[$0];
63+
if (!self.hasOwnProperty('updateProperty'))
64+
throw 'updateProperty is not defined on a BehaviorJsImplementation.';
65+
var objectContent = JSON.parse(Pointer_stringify($1));
66+
self['updateProperty'](
67+
objectContent, Pointer_stringify($2), Pointer_stringify($3));
68+
return ensureString(JSON.stringify(objectContent));
69+
},
70+
(int)this,
71+
jsonContent.c_str(),
72+
arg0.c_str(),
73+
arg1.c_str());
74+
75+
return true;
76+
}
77+
78+
void BehaviorJsImplementation::SerializeTo(SerializerElement& arg0) const {
79+
arg0.AddChild("content") = gd::Serializer::FromJSON(jsonContent);
80+
}
81+
void BehaviorJsImplementation::UnserializeFrom(const SerializerElement& arg1) {
82+
jsonContent = gd::Serializer::ToJSON(arg1.GetChild("content"));
83+
}
84+
85+
void BehaviorJsImplementation::__destroy__() { // Useless?
86+
EM_ASM_INT(
87+
{
88+
var self = Module['getCache'](Module['BehaviorJsImplementation'])[$0];
89+
if (!self.hasOwnProperty('__destroy__'))
90+
throw 'a JSImplementation must implement all functions, you forgot BehaviorJsImplementation::__destroy__.';
91+
self['__destroy__']();
92+
},
93+
(int)this);
94+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include <GDCore/IDE/Dialogs/PropertyDescriptor.h>
2+
#include <GDCore/Project/Behavior.h>
3+
#include <GDCore/Project/Project.h>
4+
#include <GDCore/Serialization/Serializer.h>
5+
#include <GDCore/Serialization/SerializerElement.h>
6+
#include <emscripten.h>
7+
8+
using namespace gd;
9+
10+
/**
11+
* \brief A gd::Behavior that stores its content in JSON and forward the properties related
12+
* functions to Javascript with Emscripten.
13+
*/
14+
class BehaviorJsImplementation : public Behavior {
15+
public:
16+
BehaviorJsImplementation() : Behavior(), jsonContent("{}") {}
17+
virtual BehaviorJsImplementation* Clone() const override;
18+
19+
virtual std::map<gd::String, gd::PropertyDescriptor> GetProperties(
20+
gd::Project& project) const override;
21+
virtual bool UpdateProperty(const gd::String& name,
22+
const gd::String& value,
23+
gd::Project& project) override;
24+
25+
void __destroy__();
26+
27+
virtual void SerializeTo(SerializerElement& arg0) const override;
28+
virtual void UnserializeFrom(const SerializerElement& arg1) override;
29+
30+
const gd::String& GetRawJSONContent() const { return jsonContent; };
31+
BehaviorJsImplementation& SetRawJSONContent(const gd::String& newContent) {
32+
jsonContent = newContent;
33+
return *this;
34+
};
35+
36+
private:
37+
gd::String jsonContent;
38+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#include "BehaviorSharedDataJsImplementation.h"
2+
#include <GDCore/IDE/Dialogs/PropertyDescriptor.h>
3+
#include <GDCore/Project/Behavior.h>
4+
#include <GDCore/Project/Project.h>
5+
#include <GDCore/Serialization/Serializer.h>
6+
#include <GDCore/Serialization/SerializerElement.h>
7+
#include <emscripten.h>
8+
#include <map>
9+
10+
using namespace gd;
11+
12+
std::shared_ptr<gd::BehaviorsSharedData>
13+
BehaviorSharedDataJsImplementation::Clone() const {
14+
BehaviorSharedDataJsImplementation* clone =
15+
new BehaviorSharedDataJsImplementation(*this);
16+
17+
// Copy the references to the JS implementations of the functions (because we
18+
// want an object cloned from C++ to retain the functions implemented in JS).
19+
EM_ASM_INT(
20+
{
21+
var clone = Module['wrapPointer'](
22+
$0, Module['BehaviorSharedDataJsImplementation']);
23+
var self = Module['wrapPointer'](
24+
$1, Module['BehaviorSharedDataJsImplementation']);
25+
26+
clone['getProperties'] = self['getProperties'];
27+
clone['updateProperty'] = self['updateProperty'];
28+
},
29+
(int)clone,
30+
(int)this);
31+
32+
return std::shared_ptr<gd::BehaviorsSharedData>(clone);
33+
}
34+
std::map<gd::String, gd::PropertyDescriptor>
35+
BehaviorSharedDataJsImplementation::GetProperties(gd::Project&) const {
36+
std::map<gd::String, gd::PropertyDescriptor>* jsCreatedProperties = nullptr;
37+
std::map<gd::String, gd::PropertyDescriptor> copiedProperties;
38+
39+
jsCreatedProperties = (std::map<gd::String, gd::PropertyDescriptor>*)EM_ASM_INT(
40+
{
41+
var self = Module['getCache'](
42+
Module['BehaviorSharedDataJsImplementation'])[$0];
43+
if (!self.hasOwnProperty('getProperties'))
44+
throw 'getProperties is not defined on a BehaviorSharedDataJsImplementation.';
45+
46+
var objectContent = JSON.parse(Pointer_stringify($1));
47+
var newProperties = self['getProperties'](objectContent);
48+
if (!newProperties)
49+
throw 'getProperties returned nothing in a gd::BehaviorSharedDataJsImplementation.';
50+
51+
return getPointer(newProperties);
52+
},
53+
(int)this,
54+
jsonContent.c_str());
55+
56+
copiedProperties = *jsCreatedProperties;
57+
delete jsCreatedProperties;
58+
return copiedProperties;
59+
}
60+
bool BehaviorSharedDataJsImplementation::UpdateProperty(const gd::String& arg0,
61+
const gd::String& arg1,
62+
Project&) {
63+
jsonContent = (const char*)EM_ASM_INT(
64+
{
65+
var self = Module['getCache'](
66+
Module['BehaviorSharedDataJsImplementation'])[$0];
67+
if (!self.hasOwnProperty('updateProperty'))
68+
throw 'updateProperty is not defined on a BehaviorSharedDataJsImplementation.';
69+
var objectContent = JSON.parse(Pointer_stringify($1));
70+
self['updateProperty'](
71+
objectContent, Pointer_stringify($2), Pointer_stringify($3));
72+
return ensureString(JSON.stringify(objectContent));
73+
},
74+
(int)this,
75+
jsonContent.c_str(),
76+
arg0.c_str(),
77+
arg1.c_str());
78+
79+
return true;
80+
}
81+
82+
void BehaviorSharedDataJsImplementation::SerializeTo(
83+
SerializerElement& arg0) const {
84+
arg0.AddChild("content") = gd::Serializer::FromJSON(jsonContent);
85+
}
86+
void BehaviorSharedDataJsImplementation::UnserializeFrom(
87+
const SerializerElement& arg1) {
88+
jsonContent = gd::Serializer::ToJSON(arg1.GetChild("content"));
89+
}
90+
91+
void BehaviorSharedDataJsImplementation::__destroy__() { // Useless?
92+
EM_ASM_INT(
93+
{
94+
var self = Module['getCache'](
95+
Module['BehaviorSharedDataJsImplementation'])[$0];
96+
if (!self.hasOwnProperty('__destroy__'))
97+
throw 'a JSImplementation must implement all functions, you forgot BehaviorSharedDataJsImplementation::__destroy__.';
98+
self['__destroy__']();
99+
},
100+
(int)this);
101+
}

0 commit comments

Comments
 (0)