From b327268913cb7e96e1eca3c8b982f59341853f5a Mon Sep 17 00:00:00 2001 From: Adrian Kierzkowski Date: Thu, 10 Oct 2024 19:20:09 +0200 Subject: [PATCH] C++ compatibility fixes. --- Indicators/Tick/Indi_TickMt.h | 8 ++- Makefile | 2 +- Platform/Chart3D/Chart3D.h | 49 ++++++++++-------- Platform/Chart3D/Device.h | 39 ++++++++------ Platform/Chart3D/Devices/MTDX/MTDXDevice.h | 39 ++++++++------ Platform/Chart3D/Face.h | 11 ++-- Platform/Chart3D/Frontend.h | 16 +++--- Platform/Chart3D/IndexBuffer.h | 10 ++-- Platform/Chart3D/Math.h | 60 ++++++++++++---------- Platform/Chart3D/Shader.h | 17 +++--- Platform/Chart3D/TSR.h | 11 ++-- Platform/Chart3D/Vertex.h | 11 ++-- Std.h | 15 +++--- 13 files changed, 169 insertions(+), 119 deletions(-) diff --git a/Indicators/Tick/Indi_TickMt.h b/Indicators/Tick/Indi_TickMt.h index c2dcf44c8..89269bc5a 100644 --- a/Indicators/Tick/Indi_TickMt.h +++ b/Indicators/Tick/Indi_TickMt.h @@ -165,6 +165,7 @@ class Indi_TickMt : public IndicatorTick()); -#endif + #endif _type_renderer.Render(_device); } }; + +#endif diff --git a/Platform/Chart3D/Device.h b/Platform/Chart3D/Device.h index 741561a51..85ceefe12 100644 --- a/Platform/Chart3D/Device.h +++ b/Platform/Chart3D/Device.h @@ -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 }; @@ -165,10 +168,10 @@ class Device : public Dynamic { VertexBuffer* _buff = CreateVertexBuffer(); // Unfortunately we can't make this method virtual. if (dynamic_cast(_buff) != NULL) { -// MT5's DirectX. -#ifdef __debug__ + // MT5's DirectX. + #ifdef __debug__ Print("Filling vertex buffer via MTDXVertexBuffer"); -#endif + #endif ((MTDXVertexBuffer*)_buff).Fill(data); } else { Alert("Unsupported vertex buffer device target"); @@ -196,9 +199,9 @@ class Device : public Dynamic { */ template void Render(Mesh* _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); @@ -321,3 +324,5 @@ class Device : public Dynamic { */ virtual void ClearBuffer(ENUM_CLEAR_BUFFER_TYPE _type, unsigned int _color) = NULL; }; + +#endif diff --git a/Platform/Chart3D/Devices/MTDX/MTDXDevice.h b/Platform/Chart3D/Devices/MTDX/MTDXDevice.h index aa82926c8..82a505d2b 100644 --- a/Platform/Chart3D/Devices/MTDX/MTDXDevice.h +++ b/Platform/Chart3D/Devices/MTDX/MTDXDevice.h @@ -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 "../../Device.h" +// We currently only support MQL. +#ifdef __MQL__ + + #include "../../Device.h" class MTDXDevice : public Device { public: @@ -38,14 +41,14 @@ class MTDXDevice : public Device { * 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; } @@ -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 } } @@ -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 diff --git a/Platform/Chart3D/Face.h b/Platform/Chart3D/Face.h index 59f394b26..4969db0d2 100644 --- a/Platform/Chart3D/Face.h +++ b/Platform/Chart3D/Face.h @@ -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 }; @@ -99,3 +102,5 @@ struct Face { } } }; + +#endif diff --git a/Platform/Chart3D/Frontend.h b/Platform/Chart3D/Frontend.h index a5bc188eb..d681b1552 100644 --- a/Platform/Chart3D/Frontend.h +++ b/Platform/Chart3D/Frontend.h @@ -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" @@ -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. diff --git a/Platform/Chart3D/IndexBuffer.h b/Platform/Chart3D/IndexBuffer.h index 7392f7731..3eb7f7395 100644 --- a/Platform/Chart3D/IndexBuffer.h +++ b/Platform/Chart3D/IndexBuffer.h @@ -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" @@ -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; }; diff --git a/Platform/Chart3D/Math.h b/Platform/Chart3D/Math.h index 25cd12e1d..69a0e3947 100644 --- a/Platform/Chart3D/Math.h +++ b/Platform/Chart3D/Math.h @@ -4,34 +4,38 @@ //| https://www.mql5.com | //+------------------------------------------------------------------+ #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 #ifdef __MQL__ -#property copyright "Copyright 2019,MetaQuotes Software Corp." -#property link "https://www.mql5.com" + #property copyright "Copyright 2019,MetaQuotes Software Corp." + #property link "https://www.mql5.com" #endif + +// We currently only support MQL. +#ifdef __MQL__ + //+------------------------------------------------------------------+ -//| DirectX Math Routines | -//+------------------------------------------------------------------+ -//| Ported from C++ code of ReactOS, written by David Adam | -//| and Tony Wasserka | -//| | -//| https://doxygen.reactos.org/de/d57/ | -//| dll_2directx_2wine_2d3dx9__36_2math_8c_source.html | -//| | -//| Copyright (C) 2007 David Adam | -//| Copyright (C) 2007 Tony Wasserka | -//+------------------------------------------------------------------+ -#define DX_PI 3.1415926535897932384626f -#define DX_PI_DIV2 1.5707963267948966192313f -#define DX_PI_DIV3 1.0471975511965977461542f -#define DX_PI_DIV4 0.7853981633974483096156f -#define DX_PI_DIV6 0.5235987755982988730771f -#define DX_PI_MUL2 6.2831853071795864769253f -#define DXSH_MINORDER 2 -#define DXSH_MAXORDER 6 + //| DirectX Math Routines | + //+------------------------------------------------------------------+ + //| Ported from C++ code of ReactOS, written by David Adam | + //| and Tony Wasserka | + //| | + //| https://doxygen.reactos.org/de/d57/ | + //| dll_2directx_2wine_2d3dx9__36_2math_8c_source.html | + //| | + //| Copyright (C) 2007 David Adam | + //| Copyright (C) 2007 Tony Wasserka | + //+------------------------------------------------------------------+ + #define DX_PI 3.1415926535897932384626f + #define DX_PI_DIV2 1.5707963267948966192313f + #define DX_PI_DIV3 1.0471975511965977461542f + #define DX_PI_DIV4 0.7853981633974483096156f + #define DX_PI_DIV6 0.5235987755982988730771f + #define DX_PI_MUL2 6.2831853071795864769253f + #define DXSH_MINORDER 2 + #define DXSH_MAXORDER 6 //+------------------------------------------------------------------+ //| Preliminary declarations | //+------------------------------------------------------------------+ @@ -1442,7 +1446,7 @@ void DXMatrixAffineTransformation2D(DXMatrix &out, float scaling, const DXVector out.m[3][0] += translation.x; out.m[3][1] += translation.y; } -#define D3DERR_INVALIDCALL -2005530516 + #define D3DERR_INVALIDCALL -2005530516 //#define S_OK 0; //+------------------------------------------------------------------+ //| Breaks down a general 3D transformation _matrix into its scalar, | @@ -3150,7 +3154,7 @@ void DXSHRotate(float &out[], int order, const DXMatrix &_matrix, const float &i return; } -#ifdef __MQL5__ + #ifdef __MQL5__ if ((float)fabs(_matrix.m[2][2]) != 1.0f) { sinb = (float)sqrt(1.0f - _matrix.m[2][2] * _matrix.m[2][2]); alpha = (float)atan2(_matrix.m[2][1] / sinb, _matrix.m[2][0] / sinb); @@ -3161,12 +3165,12 @@ void DXSHRotate(float &out[], int order, const DXMatrix &_matrix, const float &i beta = 0.0f; gamma = 0.0f; } -#else + #else alpha = 0.0f; beta = 0.0f; gamma = 0.0f; sinb = 0.0f; -#endif + #endif //--- DXSHRotateZ(temp, order, gamma, in); @@ -3230,3 +3234,5 @@ float DXScalarLerp(const float val1, const float val2, float s) { return ((1 - s //+---------------------------------------------------------------------+ float DXScalarBiasScale(const float val, const float bias, const float scale) { return ((val + bias) * scale); } //+------------------------------------------------------------------+ + +#endif diff --git a/Platform/Chart3D/Shader.h b/Platform/Chart3D/Shader.h index 8bfc3de25..6b5d9cfca 100644 --- a/Platform/Chart3D/Shader.h +++ b/Platform/Chart3D/Shader.h @@ -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 "../../Refs.mqh" +// We currently only support MQL. +#ifdef __MQL__ + + #include "../../Refs.mqh" // Shader type. enum ENUM_SHADER_TYPE { @@ -85,10 +88,10 @@ class Shader : public Dynamic { void SetCBuffer(const X& data) { // Unfortunately we can't make this method virtual. if (dynamic_cast(&this) != NULL) { -// MT5's DirectX. -#ifdef __debug__ + // MT5's DirectX. + #ifdef __debug__ Print("Setting CBuffer data for MT5"); -#endif + #endif ((MTDXShader*)&this).SetCBuffer(data); } else { Alert("Unsupported cbuffer device target"); @@ -100,3 +103,5 @@ class Shader : public Dynamic { */ virtual void Select() = NULL; }; + +#endif diff --git a/Platform/Chart3D/TSR.h b/Platform/Chart3D/TSR.h index 4ed42dd48..e239a8ed5 100644 --- a/Platform/Chart3D/TSR.h +++ b/Platform/Chart3D/TSR.h @@ -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" class TSR { public: @@ -65,3 +68,5 @@ class TSR { return _mtx_result; } }; + +#endif diff --git a/Platform/Chart3D/Vertex.h b/Platform/Chart3D/Vertex.h index 65e9248b0..1922a8e62 100644 --- a/Platform/Chart3D/Vertex.h +++ b/Platform/Chart3D/Vertex.h @@ -21,11 +21,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 "../../Refs.mqh" +// We currently only support MQL. +#ifdef __MQL__ + + #include "../../Refs.mqh" /** * Generic vertex to be used by meshes. @@ -56,3 +59,5 @@ const ShaderVertexLayout Vertex::Layout[3] = { {"POSITION", 0, GFX_VAR_TYPE_FLOAT, 3, false, sizeof(Vertex), 0}, {"NORMAL", 0, GFX_VAR_TYPE_FLOAT, 3, false, sizeof(Vertex), sizeof(float) * 3}, {"COLOR", 0, GFX_VAR_TYPE_FLOAT, 4, false, sizeof(Vertex), sizeof(float) * 6}}; + +#endif diff --git a/Std.h b/Std.h index 789ec31eb..c4a5d6ce1 100644 --- a/Std.h +++ b/Std.h @@ -387,15 +387,19 @@ class InvalidEnumValue { #endif static const T value() { - return (T)INT_MAX; +#ifdef __MQL__ + return (T)NULL; +#else + return std::numeric_limits::max(); +#endif } }; #ifndef __MQL__ struct _WRONG_VALUE { template - operator T() { - return (T)-1; + operator T() const { + return std::numeric_limits::max(); } } WRONG_VALUE; @@ -405,10 +409,9 @@ const string _empty_string = ""; // Converter of NULL_VALUE into expected type. e.g., "int x = NULL_VALUE" will end up with "x = 0". struct _NULL_VALUE { template - explicit operator T() const { - return (T)0; + operator T() const { + return std::numeric_limits::max(); } - } NULL_VALUE; /**