Skip to content

Commit

Permalink
Merge pull request #665 from nseam/dev-fx-emcc
Browse files Browse the repository at this point in the history
Emscripten refactor
  • Loading branch information
kenorb authored Jun 16, 2023
2 parents 7f16aa1 + 94d2da4 commit e89966d
Show file tree
Hide file tree
Showing 162 changed files with 5,093 additions and 2,396 deletions.
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

0 comments on commit e89966d

Please sign in to comment.