Skip to content

Commit

Permalink
C++ compatibility fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
nseam committed Oct 10, 2024
1 parent 101a3da commit b327268
Show file tree
Hide file tree
Showing 13 changed files with 169 additions and 119 deletions.
8 changes: 7 additions & 1 deletion Indicators/Tick/Indi_TickMt.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ class Indi_TickMt : public IndicatorTick<Indi_TickMtParams, double, ItemsHistory

#endif

#ifdef __MQL4__
// In MQL4 or MQL5 (if there's no history returned by CopyTicksRange) we
// try to create and return OHLC ticks by calling iOpen/iHigh/iLow/iClose
// for each bar in history. Candle indicator will form candles from those
Expand Down Expand Up @@ -201,6 +202,11 @@ class Indi_TickMt : public IndicatorTick<Indi_TickMtParams, double, ItemsHistory
_out_ticks[_tick_idx++] = _tick_c;
}

#endif

#ifndef __MQL__
// @fixit In C++ we currently don't have a system to retrieve historic OHLCs from MT servers.
#endif
return ArraySize(_out_ticks) != 0;
}

Expand Down Expand Up @@ -265,6 +271,6 @@ class Indi_TickMt : public IndicatorTick<Indi_TickMtParams, double, ItemsHistory
// Appending tick into the history.
AppendEntry(_entry);

return _ask != WRONG_VALUE && _bid != WRONG_VALUE;
return _ask != (double)WRONG_VALUE && _bid != (double)WRONG_VALUE;
}
};
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CFLAGS := -Wall -Wextra -std=c++17 -w # Compiler flags
EMCC_CFLAGS := $(CFLAGS) --bind -s ASSERTIONS=1 -s ERROR_ON_UNDEFINED_SYMBOLS=0 -s EXIT_RUNTIME=0 -s EXPORTED_FUNCTIONS="[]" -s WASM=1 -s MODULARIZE=1 -s NO_EXIT_RUNTIME=1
MAKEFILES := $(wildcard **/tests/Makefile) # $(wildcard **/**/tests/Makefile)
MAKEFILES := $(wildcard **/tests/Makefile) $(wildcard **/**/tests/Makefile)

# Check if the system is Linux
UNAME_S := $(shell uname -s)
Expand Down
49 changes: 27 additions & 22 deletions Platform/Chart3D/Chart3D.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,27 @@
#pragma once
#endif

#include "../Chart/Bar.struct.h"
#include "../../Indicator/IndicatorData.h"
#include "../../Indicators/Price/Indi_MA.h"
#include "../../Storage/Instances.h"
#include "../../Refs.mqh"
#include "../../Serializer/SerializerConverter.h"
#include "../../Serializer/SerializerJson.h"
#include "Chart3DCandles.h"
#include "Chart3DType.h"
#include "Cube.h"
#include "Device.h"
#include "Interface.h"

#ifdef __MQL5__
// Resource variables.
#resource "Shaders/chart3d_vs.hlsl" as string Chart3DShaderSourceVS;
#resource "Shaders/chart3d_ps.hlsl" as string Chart3DShaderSourcePS;
#endif
// We currently only support MQL.
#ifdef __MQL__

#include "../../Indicator/IndicatorData.h"
#include "../../Indicators/Price/Indi_MA.h"
#include "../../Refs.mqh"
#include "../../Serializer/SerializerConverter.h"
#include "../../Serializer/SerializerJson.h"
#include "../../Storage/Instances.h"
#include "../Chart/Bar.struct.h"
#include "Chart3DCandles.h"
#include "Chart3DType.h"
#include "Cube.h"
#include "Device.h"
#include "Interface.h"

#ifdef __MQL5__
// Resource variables.
#resource "Shaders/chart3d_vs.hlsl" as string Chart3DShaderSourceVS;
#resource "Shaders/chart3d_ps.hlsl" as string Chart3DShaderSourcePS;
#endif

typedef BarOHLC (*Chart3DPriceFetcher)(ENUM_TIMEFRAMES, int);

Expand Down Expand Up @@ -100,9 +103,9 @@ class Chart3D : public Dynamic {
offset.z = 25.0f;
initialized = false;
source = _source;
#ifdef __MQL5__
#ifdef __MQL5__
Interface::AddListener(chart3d_interface_listener, &this);
#endif
#endif
}

void OnInterfaceEvent(InterfaceEvent& _event) {
Expand Down Expand Up @@ -222,10 +225,12 @@ class Chart3D : public Dynamic {
BarOHLC _ohlc;
// BarOHLC _ohlc = price_fetcher(PERIOD_CURRENT, 0); // @fixme: 'price_fetcher' - internal error #%d

#ifdef __debug__
#ifdef __debug__
Print(SerializerConverter::FromObject(_ohlc).ToString<SerializerJson>());
#endif
#endif

_type_renderer.Render(_device);
}
};

#endif
39 changes: 22 additions & 17 deletions Platform/Chart3D/Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,23 @@
*/

#ifndef __MQL__
// Allows the preprocessor to include a header file when it is needed.
#pragma once
// Allows the preprocessor to include a header file when it is needed.
#pragma once
#endif

#include "../../Refs.mqh"
#include "../../Util.h"
#include "Frontend.h"
#include "IndexBuffer.h"
#include "Material.h"
#include "Math.h"
#include "Mesh.h"
#include "Shader.h"
#include "ShaderVertexLayout.struct.h"
#include "VertexBuffer.h"
// We currently only support MQL.
#ifdef __MQL__

#include "../../Refs.mqh"
#include "../../Util.h"
#include "Frontend.h"
#include "IndexBuffer.h"
#include "Material.h"
#include "Math.h"
#include "Mesh.h"
#include "Shader.h"
#include "ShaderVertexLayout.struct.h"
#include "VertexBuffer.h"

enum GFX_DRAW_TEXT_FLAGS { GFX_DRAW_TEXT_FLAG_NONE, GFX_DRAW_TEXT_FLAG_2D_COORD_X, GFX_DRAW_TEXT_FLAG_2D_COORD_Y };

Expand Down Expand Up @@ -165,10 +168,10 @@ class Device : public Dynamic {
VertexBuffer* _buff = CreateVertexBuffer();
// Unfortunately we can't make this method virtual.
if (dynamic_cast<MTDXVertexBuffer*>(_buff) != NULL) {
// MT5's DirectX.
#ifdef __debug__
// MT5's DirectX.
#ifdef __debug__
Print("Filling vertex buffer via MTDXVertexBuffer");
#endif
#endif
((MTDXVertexBuffer*)_buff).Fill<T>(data);
} else {
Alert("Unsupported vertex buffer device target");
Expand Down Expand Up @@ -196,9 +199,9 @@ class Device : public Dynamic {
*/
template <typename T>
void Render(Mesh<T>* _mesh, Shader* _vs = NULL, Shader* _ps = NULL) {
#ifdef __debug__
#ifdef __debug__
Print("Rendering mesh");
#endif
#endif
VertexBuffer* _vertices;
IndexBuffer* _indices;
_mesh.GetBuffers(&this, _vertices, _indices);
Expand Down Expand Up @@ -321,3 +324,5 @@ class Device : public Dynamic {
*/
virtual void ClearBuffer(ENUM_CLEAR_BUFFER_TYPE _type, unsigned int _color) = NULL;
};

#endif
39 changes: 22 additions & 17 deletions Platform/Chart3D/Devices/MTDX/MTDXDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,29 @@
*/

#ifndef __MQL__
// Allows the preprocessor to include a header file when it is needed.
#pragma once
// Allows the preprocessor to include a header file when it is needed.
#pragma once
#endif

#include "../../Device.h"
// We currently only support MQL.
#ifdef __MQL__

#include "../../Device.h"

class MTDXDevice : public Device {
public:
/**
* Initializes graphics device.
*/
bool Init(Frontend* _frontend) {
#ifdef __debug__
#ifdef __debug__
Print("MTDXDevice: DXContextCreate: width = ", _frontend.Width(), ", height = ", _frontend.Height());
#endif
#endif
context = DXContextCreate(_frontend.Width(), _frontend.Height());
#ifdef __debug__
#ifdef __debug__
Print("LastError: ", GetLastError());
Print("MTDXDevice: context = ", context);
#endif
#endif
_frontend.Init();
return true;
}
Expand Down Expand Up @@ -87,14 +90,14 @@ class MTDXDevice : public Device {
_dx_color.z = 1.0f / 255.0f * ((_color & 0x000000FF) >> 0);
_dx_color.w = 1.0f / 255.0f * ((_color & 0xFF000000) >> 24);
DXContextClearColors(context, _dx_color);
#ifdef __debug__
#ifdef __debug__
Print("DXContextClearColors: LastError: ", GetLastError());
#endif
#endif
} else if (_type == CLEAR_BUFFER_TYPE_DEPTH) {
DXContextClearDepth(context);
#ifdef __debug__
#ifdef __debug__
Print("DXContextClearDepth: LastError: ", GetLastError());
#endif
#endif
}
}

Expand Down Expand Up @@ -140,19 +143,21 @@ class MTDXDevice : public Device {
_vertices.Select();
if (_indices == NULL) {
if (!DXDraw(context)) {
#ifdef __debug__
#ifdef __debug__
Print("Can't draw!");
#endif
#endif
}
#ifdef __debug__
#ifdef __debug__
Print("DXDraw: LastError: ", GetLastError());
#endif
#endif
} else {
_indices.Select();
DXDrawIndexed(context);
#ifdef __debug__
#ifdef __debug__
Print("DXDrawIndexed: LastError: ", GetLastError());
#endif
#endif
}
}
};

#endif
11 changes: 8 additions & 3 deletions Platform/Chart3D/Face.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@
*/

#ifndef __MQL__
// Allows the preprocessor to include a header file when it is needed.
#pragma once
// Allows the preprocessor to include a header file when it is needed.
#pragma once
#endif

#include "Math.h"
// We currently only support MQL.
#ifdef __MQL__

#include "Math.h"

// Face flags.
enum ENUM_FACE_FLAGS { FACE_FLAGS_NONE, FACE_FLAGS_TRIANGLE, FACE_FLAGS_QUAD };
Expand Down Expand Up @@ -99,3 +102,5 @@ struct Face {
}
}
};

#endif
16 changes: 8 additions & 8 deletions Platform/Chart3D/Frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
*/

#ifndef __MQL__
// Allows the preprocessor to include a header file when it is needed.
#pragma once
// Allows the preprocessor to include a header file when it is needed.
#pragma once
#endif

#include "../../Refs.mqh"
Expand Down Expand Up @@ -61,32 +61,32 @@ class Frontend : public Dynamic {
/**
* Initializes canvas.
*/
virtual bool Init() = NULL;
virtual bool Init() = 0;

/**
* Deinitializes canvas.
*/
virtual bool Deinit() = NULL;
virtual bool Deinit() = 0;

/**
* Executed before render starts.
*/
virtual void RenderBegin(int context) = NULL;
virtual void RenderBegin(int context) = 0;

/**
* Executed after render ends.
*/
virtual void RenderEnd(int context) = NULL;
virtual void RenderEnd(int context) = 0;

/**
* Returns canvas' width.
*/
virtual int Width() = NULL;
virtual int Width() = 0;

/**
* Returns canvas' height.
*/
virtual int Height() = NULL;
virtual int Height() = 0;

/**
* Enqueues text to be drawn directly into the pixel buffer. Queue will be processed in the Device::End() method.
Expand Down
10 changes: 5 additions & 5 deletions Platform/Chart3D/IndexBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
*/

#ifndef __MQL__
// Allows the preprocessor to include a header file when it is needed.
#pragma once
// Allows the preprocessor to include a header file when it is needed.
#pragma once
#endif

#include "../../Refs.mqh"
Expand All @@ -54,15 +54,15 @@ class IndexBuffer : public Dynamic {
/**
* Creates index buffer.
*/
virtual bool Create(VOID_DATA(_data)) = NULL;
virtual bool Create(VOID_DATA(_data)) = 0;

/**
* Fills index buffer with indices.
*/
virtual void Fill(ARRAY_REF(unsigned int, _indices)) = NULL;
virtual void Fill(ARRAY_REF(unsigned int, _indices)) = 0;

/**
* Activates index buffer for rendering.
*/
virtual void Select() = NULL;
virtual void Select() = 0;
};
Loading

0 comments on commit b327268

Please sign in to comment.