Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emscripten refactor #665

Merged
merged 45 commits into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
5287625
WIP. Writing stubs/most important methods' implementations for Emscri…
nseam Nov 17, 2022
d393683
WIP. Added missing C++ methods regarding String printing/manipulation…
nseam Nov 30, 2022
e36c9c9
WIP. Trying to run emscripten-generated code in the browser.
nseam Dec 1, 2022
42409e3
WIP. Trying to make smart pointers to work in JS.
nseam Dec 15, 2022
da13c54
WIP. Making Account and Exchange classes to work via Emscripten. Also…
nseam Dec 21, 2022
ff982e3
WIP. End up with include loop.
nseam Jan 9, 2023
36993ce
WIP. Fixing Emscripten compilation errors.
nseam Jan 12, 2023
efa69da
WIP. Fixing Emscripten compilation errors.
nseam Jan 14, 2023
db0b8a0
WIP. Making code C++/Emscripten-compatible.
nseam Jan 19, 2023
f4c5d18
WIP. Code is now compiling for a FX31337-wasm's tests/js/TestRunner.js
nseam Jan 20, 2023
c09b514
IndicatorsTest now compiles in MT5. Need to check other tests.
nseam Jan 26, 2023
88108ce
WIP. Fixing MT5 tests.
nseam Jan 27, 2023
17cd38a
Fixed C++ and MQL5 errors for tests in /tests folder.
nseam Feb 2, 2023
a30a476
WIP. Trying to make tests to run on MT4.
nseam Feb 7, 2023
720ec62
WIP. Should fix tests in MT4 and MT5.
nseam Feb 8, 2023
032e8e7
WIP. Should fix errors in MT4, MT5 & C++ for TaskRunner.
nseam Feb 9, 2023
11b6ce5
Added missing includes.
nseam Feb 16, 2023
f78b9fd
Addes required flags for emcc and gcc.
nseam Feb 16, 2023
a13a079
Made tests to continue even if one of them fails.
nseam Feb 17, 2023
2a5f72c
Added ToString() override to Indicator class, so IndicatorsTest will …
nseam Feb 17, 2023
a36e135
WIP. Making FX's Indicator.cpp's to compile.
nseam Feb 17, 2023
ba94fa8
Sets job max-parallel to 4 as per API limits
kenorb Feb 21, 2023
ccade19
WIP. Using Indi_TickProvider to provide tick for Candle indicator and…
nseam Feb 23, 2023
ee07184
Merge branch 'dev-fx-emcc' of https://github.com/nseam/EA31337-classe…
nseam Feb 23, 2023
16ebdc4
Fixing MQL4 errors.
nseam Feb 24, 2023
65b8f29
WIP. Fixing MT4 errors.
nseam Feb 25, 2023
478b640
WIP. Testing RSI over IndicatorTfDummy over Indi_TickProvider. Now we…
nseam Mar 1, 2023
30d6f7f
WIP. Testing RSI over IndicatorTfDummy over Indi_TickProvider. RSI re…
nseam Mar 2, 2023
db3442d
Fixes recent syntax errors for C++.
nseam Mar 8, 2023
93a46bb
Little changes for array #defines.
nseam Apr 7, 2023
42de20c
WIP. Making a Tester class and exporting IndicatorTfDummy and RSI ind…
nseam Apr 20, 2023
3bc9a57
src/IndicatorTest.cpp
nseam Apr 28, 2023
050cee4
Empty commit to run tests.
nseam May 24, 2023
2d7e339
Fixes Indi_RSI #elif error. Also, added PERIOD_TF_IRREGULAR enum valu…
nseam May 24, 2023
930cda4
Fixes tests using Platform::FetchDefaultCandleIndicator() as method n…
nseam May 24, 2023
df4bb44
Tiny internal changes. Part of testing emcc API.
nseam Jun 1, 2023
b3a7f4a
Fixes warning "too many arguments for function-like macro 'RUNTIME_ER…
nseam Jun 5, 2023
69220b5
Should fix problem with MA expecting additional bar, despite it has a…
nseam Jun 8, 2023
03bcdf3
Little changes required by emcc support.
nseam Jun 8, 2023
4faba09
Merge branch 'v3.004-dev' into dev-fx-emcc
nseam Jun 13, 2023
d53d07a
Should fix problems with DrawIndicatorTest as Platform::AddWithDefaul…
nseam Jun 15, 2023
f31618f
Merge branch 'dev-fx-emcc' of https://github.com/nseam/EA31337-classe…
nseam Jun 15, 2023
b246c9d
Fixing CompileTest
nseam Jun 15, 2023
78d8634
Fixes problem with not preserving TF passed to Candle indicators.
nseam Jun 15, 2023
94d2da4
Fixes ZigZag and ZigZagColor value validation.
nseam Jun 16, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .github/workflows/compile-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ jobs:
with:
compiler: gcc-latest
- name: Compile ${{ matrix.file }} via emcc
run: emcc "${{ matrix.file }}"
if: always()
run: >
emcc -s WASM=1 -s ENVIRONMENT=node -s EXIT_RUNTIME=0 -s NO_EXIT_RUNTIME=1 -s ASSERTIONS=1 -Wall -s
MODULARIZE=1 -s ERROR_ON_UNDEFINED_SYMBOLS=0 --bind -s EXPORTED_FUNCTIONS="[]" -g -std=c++17
"${{ matrix.file }}"
- name: Compile ${{ matrix.file }} via g++
run: g++ -c "${{ matrix.file }}"
if: always()
run: g++ -g -std=c++17 -c "${{ matrix.file }}"
6 changes: 6 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ jobs:
- SummaryReportTest
- TickerTest
- TradeTest
max-parallel: 4
steps:
- uses: actions/download-artifact@v2
with:
Expand All @@ -86,6 +87,7 @@ jobs:
MtVersion: 4.0.0.1349
TestExpert: ${{ matrix.test }}
RunOnError: show_logs 200
if: always()
timeout-minutes: 10

Scripts-MQL4:
Expand Down Expand Up @@ -113,6 +115,7 @@ jobs:
- TerminalTest
- TimerTest
- ValueStorageTest
max-parallel: 4
steps:
- uses: actions/download-artifact@v2
with:
Expand All @@ -121,6 +124,7 @@ jobs:
uses: fx31337/mql-tester-action@master
with:
Script: ${{ matrix.test }}
if: always()
timeout-minutes: 10

Scripts-MQL4-Ignore:
Expand All @@ -146,6 +150,7 @@ jobs:
with:
Script: ${{ matrix.test }}
RunOnFail: "exit 0"
if: always()
timeout-minutes: 10

Trade-Tests-MQL4:
Expand All @@ -167,4 +172,5 @@ jobs:
uses: fx31337/mql-tester-action@master
with:
Script: ${{ matrix.test }}
if: always()
timeout-minutes: 10
1 change: 1 addition & 0 deletions 3D/Chart3DCandles.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* 3D chart candles renderer.
*/

#include "../Chart.define.h"
#include "Chart3DType.h"
#include "Cube.h"
#include "Device.h"
Expand Down
4 changes: 2 additions & 2 deletions 3D/Cube.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ class Cube : public Mesh<T> {
* Initializes graphics device-related things.
*/
virtual void Initialize(Device* _device) {
SetShaderVS(_device.VertexShader(ShaderCubeSourceVS, T::Layout));
SetShaderPS(_device.PixelShader(ShaderCubeSourcePS));
SetShaderVS(_device.CreateVertexShader(ShaderCubeSourceVS, T::Layout));
SetShaderPS(_device.CreatePixelShader(ShaderCubeSourcePS));
}
#endif
};
29 changes: 17 additions & 12 deletions 3D/Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,20 +138,25 @@ class Device : public Dynamic {
/**
* Creates vertex shader to be used by current graphics device.
*/
virtual Shader* VertexShader(string _source_code, const ShaderVertexLayout& _layout[],
string _entry_point = "main") = NULL;
virtual Shader* CreateVertexShader(string _source_code, const ShaderVertexLayout& _layout[],
string _entry_point = "main") = NULL;

/**
* Creates pixel shader to be used by current graphics device.
*/
virtual Shader* PixelShader(string _source_code, string _entry_point = "main") = NULL;
virtual Shader* CreatePixelShader(string _source_code, string _entry_point = "main") = 0;

/**
* Creates vertex buffer to be used by current graphics device.
*/
virtual VertexBuffer* CreateVertexBuffer() = 0;

/**
* Creates vertex buffer to be used by current graphics device.
*/
template <typename T>
VertexBuffer* VertexBuffer(T& data[]) {
VertexBuffer* _buff = VertexBuffer();
VertexBuffer* CreateVertexBuffer(T& data[]) {
VertexBuffer* _buff = CreateVertexBuffer();
// Unfortunately we can't make this method virtual.
if (dynamic_cast<MTDXVertexBuffer*>(_buff) != NULL) {
// MT5's DirectX.
Expand All @@ -165,15 +170,10 @@ class Device : public Dynamic {
return _buff;
}

/**
* Creates vertex buffer to be used by current graphics device.
*/
virtual VertexBuffer* VertexBuffer() = NULL;

/**
* Creates index buffer to be used by current graphics device.
*/
virtual IndexBuffer* IndexBuffer(unsigned int& _indices[]) = NULL;
virtual IndexBuffer* CreateIndexBuffer(unsigned int& _indices[]) = 0;

/**
* Renders vertex buffer with optional point indices.
Expand All @@ -183,7 +183,7 @@ class Device : public Dynamic {
/**
* Renders vertex buffer with optional point indices.
*/
virtual void RenderBuffers(VertexBuffer* _vertices, IndexBuffer* _indices = NULL) = NULL;
virtual void RenderBuffers(VertexBuffer* _vertices, IndexBuffer* _indices = NULL) = 0;

/**
* Renders given mesh.
Expand Down Expand Up @@ -233,6 +233,11 @@ class Device : public Dynamic {
int Height() { return frontend.Ptr().Height(); }

void SetCameraOrtho3D(float _pos_x = 0.0f, float _pos_y = 0.0f, float _pos_z = 0.0f) {
if (Width() <= 0 || Height() <= 0) {
Print("Cannot set 2D camera as width or height of the viewport is zero!");
DebugBreak();
return;
}
DXMatrixOrthoLH(mtx_projection, 1.0f * _pos_z, 1.0f / Width() * Height() * _pos_z, -10000, 10000);
}

Expand Down
14 changes: 5 additions & 9 deletions 3D/Devices/MTDX/MTDXDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,11 @@ class MTDXDevice : public Device {
}
}

/**
* Creates index buffer to be used by current graphics device.
*/
IndexBuffer* IndexBuffer() { return NULL; }

/**
* Creates vertex shader to be used by current graphics device.
*/
virtual Shader* VertexShader(string _source_code, const ShaderVertexLayout& _layout[], string _entry_point = "main") {
Shader* CreateVertexShader(string _source_code, const ShaderVertexLayout& _layout[],
string _entry_point = "main") override {
MTDXShader* _shader = new MTDXShader(&this);
_shader.Create(SHADER_TYPE_VS, _source_code, _entry_point);
_shader.SetDataLayout(_layout);
Expand All @@ -111,7 +107,7 @@ class MTDXDevice : public Device {
/**
* Creates pixel shader to be used by current graphics device.
*/
virtual Shader* PixelShader(string _source_code, string _entry_point = "main") {
Shader* CreatePixelShader(string _source_code, string _entry_point = "main") override {
MTDXShader* _shader = new MTDXShader(&this);
_shader.Create(SHADER_TYPE_PS, _source_code, _entry_point);
return _shader;
Expand All @@ -120,12 +116,12 @@ class MTDXDevice : public Device {
/**
* Creates vertex buffer to be used by current graphics device.
*/
VertexBuffer* VertexBuffer() { return new MTDXVertexBuffer(&this); }
VertexBuffer* CreateVertexBuffer() override { return new MTDXVertexBuffer(&this); }

/**
* Creates index buffer to be used by current graphics device.
*/
virtual IndexBuffer* IndexBuffer(unsigned int& _indices[]) {
IndexBuffer* CreateIndexBuffer(unsigned int& _indices[]) override {
IndexBuffer* _buffer = new MTDXIndexBuffer(&this);
_buffer.Fill(_indices);
return _buffer;
Expand Down
9 changes: 7 additions & 2 deletions 3D/Mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,13 @@ struct PointEntry {
T point;
long key;

// Default constructor.
PointEntry() {}

// Copy constructor.
PointEntry(const PointEntry<T>& r) : point(r.point), key(r.key) {}

// Constructor.
PointEntry(const T& _point) {
point = _point;
key = MakeKey(_point.Position.x, _point.Position.y, _point.Position.z);
Expand Down Expand Up @@ -249,8 +254,8 @@ class Mesh : public Dynamic {
Print("Indices: ", _s_indices);
#endif

vbuff = _vbuff = _device.VertexBuffer<T>(_vertices);
ibuff = _ibuff = _device.IndexBuffer(_indices);
vbuff = _vbuff = _device.CreateVertexBuffer<T>(_vertices);
ibuff = _ibuff = _device.CreateIndexBuffer(_indices);
return true;
}
};
17 changes: 12 additions & 5 deletions 3D/Vertex.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,18 @@ struct Vertex {
DXVector3 Normal;
DXColor Color;

Vertex() {
Color.r = 1.0f;
Color.g = 1.0f;
Color.b = 1.0f;
Color.a = 1.0f;
// Default constructor.
Vertex(float r = 1, float g = 1, float b = 1, float a = 1) {
Color.r = r;
Color.g = g;
Color.b = b;
Color.a = a;
}

Vertex(const Vertex &r) {
Position = r.Position;
Normal = r.Normal;
Color = r.Color;
}

static const ShaderVertexLayout Layout[3];
Expand Down
17 changes: 16 additions & 1 deletion Account/Account.struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#ifndef __MQL__
// Allows the preprocessor to include a header file when it is needed.
#pragma once
#include "../Serializer.enum.h"
#include "../Serializer/Serializer.enum.h"
#endif

// Forward class declaration.
Expand All @@ -48,6 +48,21 @@ struct AccountEntry {
double margin_used;
double margin_free;
double margin_avail;

// Default constructor.
AccountEntry() {}

// Constructor.
AccountEntry(const AccountEntry& r)
: dtime(r.dtime),
balance(r.balance),
credit(r.credit),
equity(r.equity),
profit(r.profit),
margin_used(r.margin_used),
margin_free(r.margin_free),
margin_avail(r.margin_avail) {}

// Serializers.
void SerializeStub(int _n1 = 1, int _n2 = 1, int _n3 = 1, int _n4 = 1, int _n5 = 1) {}
SerializerNodeType Serialize(Serializer& _s) {
Expand Down
3 changes: 2 additions & 1 deletion Account/AccountBase.struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@
#ifndef __MQL__
// Allows the preprocessor to include a header file when it is needed.
#pragma once
#include "../Serializer.enum.h"
#include "../Serializer/Serializer.enum.h"
#endif

// Forward class declaration.
class Serializer;

// Includes.
#include "../Serializer/Serializer.h"
#include "../Std.h"
#include "../Terminal.define.h"

// Struct for account entries.
Expand Down
12 changes: 7 additions & 5 deletions Account/AccountMt.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class AccountMt;
#include "../Orders.mqh"
#include "../Serializer/Serializer.h"
#include "../SymbolInfo.mqh"
#include "../Task/TaskCondition.enum.h"
#include "../Trade.struct.h"
#include "Account.define.h"
#include "Account.enum.h"
Expand Down Expand Up @@ -283,7 +284,7 @@ class AccountMt {
return ::AccountFreeMarginMode();
#else
// @todo: Not implemented yet.
return NULL;
return NULL_VALUE;
#endif
}
static double GetAccountFreeMarginMode() { return AccountMt::AccountFreeMarginMode(); }
Expand Down Expand Up @@ -469,7 +470,7 @@ class AccountMt {
*/
bool IsFreeMargin(ENUM_ORDER_TYPE _cmd, double size_of_lot, string _symbol = NULL) {
bool _res = true;
double margin = AccountFreeMarginCheck(_symbol, _cmd, size_of_lot);
// double margin = AccountFreeMarginCheck(_symbol, _cmd, size_of_lot);
if (GetLastError() == 134 /* NOT_ENOUGH_MONEY */) _res = false;
return (_res);
}
Expand Down Expand Up @@ -617,9 +618,10 @@ class AccountMt {
return StringFormat(
"Type: %s, Server/Company/Name: %s/%s/%s, Currency: %s, Balance: %g, Credit: %g, Equity: %g, Profit: %g, "
"Margin Used/Free/Avail: %g(%.1f%%)/%g/%g, Orders limit: %g: Leverage: 1:%d, StopOut Level: %d (Mode: %d)",
GetType(), GetServerName(), GetCompanyName(), GetAccountName(), GetCurrency(), GetBalance(), GetCredit(),
GetEquity(), GetProfit(), GetMarginUsed(), GetMarginUsedInPct(), GetMarginFree(), GetMarginAvail(),
GetLimitOrders(), GetLeverage(), GetStopoutLevel(), GetStopoutMode());
C_STR(GetType()), C_STR(GetServerName()), C_STR(GetCompanyName()), C_STR(GetAccountName()),
C_STR(GetCurrency()), GetBalance(), GetCredit(), GetEquity(), GetProfit(), GetMarginUsed(),
GetMarginUsedInPct(), GetMarginFree(), GetMarginAvail(), GetLimitOrders(), GetLeverage(), GetStopoutLevel(),
GetStopoutMode());
}

/**
Expand Down
Loading