Skip to content

Commit

Permalink
3DTest: Fixes warning: OnInit function is useless for scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
kenorb committed Sep 11, 2021
1 parent 6d9a92e commit fdf4087
Show file tree
Hide file tree
Showing 23 changed files with 78 additions and 84 deletions.
18 changes: 9 additions & 9 deletions 3D/Chart3D.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ class Chart3D : public Dynamic {
// Shaders.
Ref<Shader> shader_vs;
Ref<Shader> shader_ps;

Chart3DType* current_renderer;

Instances<Chart3D> instances;

public:
Expand All @@ -96,21 +96,21 @@ class Chart3D : public Dynamic {
initialized = false;
Interface::AddListener(chart3d_interface_listener, &this);
}

void OnInterfaceEvent(InterfaceEvent& _event) {
if (GetCurrentRenderer() == NULL) {
return;
}

Device* _gfx = GetCurrentRenderer().GetDevice();

_gfx.DrawText(10, 10, "Event!");
}

Shader* GetShaderVS() { return shader_vs.Ptr(); }

Shader* GetShaderPS() { return shader_ps.Ptr(); }

Chart3DType* GetCurrentRenderer() {
return current_renderer;
}
Expand Down Expand Up @@ -139,7 +139,7 @@ class Chart3D : public Dynamic {
return NULL;
}
}

current_renderer = renderers[type].Ptr();

return renderers[type].Ptr();
Expand Down Expand Up @@ -209,4 +209,4 @@ class Chart3D : public Dynamic {

_type_renderer.Render(_device);
}
};
};
14 changes: 7 additions & 7 deletions 3D/Chart3DCandles.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ class Chart3DCandles : public Chart3DType {
cube1.Ptr().GetTSR().translation.x = chart3d.GetBarPositionX(_shift);
cube1.Ptr().GetTSR().translation.y = chart3d.GetPriceScale(_ohlc.GetMinOC()) + _height / 2;
cube1.Ptr().GetTSR().scale.y = _height;

//Print(cube1.Ptr().GetTSR().translation.y);

cube1.Ptr().GetMaterial().SetColor(higher ? 0x22FF11 : 0xFF1122);
_device.Render(cube1.Ptr());

Expand All @@ -78,25 +78,25 @@ class Chart3DCandles : public Chart3DType {
cube2.Ptr().GetMaterial().SetColor(higher ? 0x22FF11 : 0xFF1122);
_device.Render(cube2.Ptr());
}

int _digits = (int)MarketInfo(Symbol(), MODE_DIGITS);
float _pip_pow = (float)MathPow(10, _digits);
float _pip_size = 1.0f / (float)MathPow(10, _digits);
float _pip_size_m1 = 1.0f / (float)MathPow(10, _digits - 1);
float _start = float(int(chart3d.GetMinBarsPrice() * _pip_pow) * _pip_size);
float _end = float(int(chart3d.GetMaxBarsPrice() * _pip_pow) * _pip_size);

// Rendering price lines.
for (double _s = _start; _s < _end + _pip_size_m1; _s += _pip_size * 10) {
float _y = chart3d.GetPriceScale((float)_s);

cube3.Ptr().GetTSR().translation.y = _y;
cube3.Ptr().GetTSR().scale.x = 200.0f;

_device.DrawText(5, _y, StringFormat("%." + IntegerToString(_digits) + "f", _s), 0x90FFFFFF, TA_LEFT | TA_VCENTER, GFX_DRAW_TEXT_FLAG_2D_COORD_X);

cube3.Ptr().GetMaterial().SetColor(0x333333);
_device.Render(cube3.Ptr());
}
}
};
};
4 changes: 2 additions & 2 deletions 3D/Chart3DType.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Chart3DType : public Dynamic {
* Constructor.
*/
Chart3DType(Chart3D* _chart3d, Device* _device) : chart3d(_chart3d), device(_device) {}

Device* GetDevice() {
return device;
}
Expand All @@ -53,4 +53,4 @@ class Chart3DType : public Dynamic {
* Renders chart.
*/
virtual void Render(Device* _device) {}
};
};
2 changes: 1 addition & 1 deletion 3D/Cube.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,4 @@ class Cube : public Mesh<T> {
SetShaderVS(_device.VertexShader(ShaderCubeSourceVS, T::Layout));
SetShaderPS(_device.PixelShader(ShaderCubeSourcePS));
}
};
};
6 changes: 3 additions & 3 deletions 3D/Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,19 +272,19 @@ class Device : public Dynamic {
_viewport.height = frontend.Ptr().Height();
_viewport.minz = -10000.0f;
_viewport.maxz = 10000.0f;

DXVector3 _vec3_in(_x, _y, 0.0f);
DXVector3 _vec3_out;
DXVec3Project(_vec3_out, _vec3_in, _viewport, GetProjectionMatrix(), GetViewMatrix(), GetWorldMatrix());

if ((_flags & GFX_DRAW_TEXT_FLAG_2D_COORD_X) == GFX_DRAW_TEXT_FLAG_2D_COORD_X) {
_vec3_out.x = _x;
}

if ((_flags & GFX_DRAW_TEXT_FLAG_2D_COORD_Y) == GFX_DRAW_TEXT_FLAG_2D_COORD_Y) {
_vec3_out.y = _y;
}

frontend.Ptr().DrawText(_vec3_out.x, _vec3_out.y, _text, _color, _align);
}

Expand Down
2 changes: 1 addition & 1 deletion 3D/Devices/MTDX/MTDXDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,4 @@ class MTDXDevice : public Device {
#endif
}
}
};
};
2 changes: 1 addition & 1 deletion 3D/Devices/MTDX/MTDXIndexBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ class MTDXIndexBuffer : public IndexBuffer {
Print("Select: LastError: ", GetLastError());
#endif
}
};
};
2 changes: 1 addition & 1 deletion 3D/Devices/MTDX/MTDXShader.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,4 @@ class MTDXShader : public Shader {
DXInputSet(cbuffer_mvp_handle, mvp_buffer);
DXShaderSet(GetDevice().Context(), handle);
}
};
};
2 changes: 1 addition & 1 deletion 3D/Devices/MTDX/MTDXVertexBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,4 @@ class MTDXVertexBuffer : public VertexBuffer {
Print("Select: LastError: ", GetLastError());
#endif
}
};
};
2 changes: 1 addition & 1 deletion 3D/Face.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,4 @@ struct Face {
points[i].Normal = _normal;
}
}
};
};
6 changes: 3 additions & 3 deletions 3D/Frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ struct DrawTextQueueItem {
*/
class Frontend : public Dynamic {
protected:

DrawTextQueueItem draw_text_queue[];

public:
Expand Down Expand Up @@ -96,7 +96,7 @@ class Frontend : public Dynamic {
_item.align = _align;
Util::ArrayPush(draw_text_queue, _item);
}

void ProcessDrawText() {
for (int i = 0; i < ArraySize(draw_text_queue); ++i) {
DrawTextQueueItem _item = draw_text_queue[i];
Expand All @@ -111,4 +111,4 @@ class Frontend : public Dynamic {
* Draws text directly into the pixel buffer. Should be executed after all 3d drawing.
*/
virtual void DrawTextNow(int _x, int _y, string _text, unsigned int _color = 0xFFFFFFFF, unsigned int _align = 0) {}
};
};
6 changes: 3 additions & 3 deletions 3D/Frontends/MT5Frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class MT5Frontend : public Frontend {
* Returns canvas' height.
*/
virtual int Height() { return (int)ChartGetInteger(0, CHART_HEIGHT_IN_PIXELS); }

/**
* Draws text directly into the pixel buffer. Should be executed after all 3d drawing.
*/
Expand All @@ -164,10 +164,10 @@ class MT5Frontend : public Frontend {
#ifdef __debug__
Print("TextSetFont: LastError = ", GetLastError());
#endif

TextOut(_text, _x, _y, _align, image, Width(), Height(), _color, COLOR_FORMAT_ARGB_NORMALIZE);
#ifdef __debug__
Print("TextOut: LastError = ", GetLastError());
#endif
}
};
};
2 changes: 1 addition & 1 deletion 3D/IndexBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,4 @@ class IndexBuffer : public Dynamic {
* Activates index buffer for rendering.
*/
virtual void Select() = NULL;
};
};
30 changes: 15 additions & 15 deletions 3D/Interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,35 +26,35 @@
*/

#include "../Util.h"

enum ENUM_INTERFACE_EVENT {
INTERFACE_EVENT_NONE,
INTERFACE_EVENT_MOUSE_MOVE,
INTERFACE_EVENT_MOUSE_DOWN,
INTERFACE_EVENT_MOUSE_UP
};

struct InterfaceEvent {
ENUM_INTERFACE_EVENT type;
struct EventMouse {
int x;
int y;
datetime dt;
};

union EventData {
EventMouse mouse;
} data;
};


void OnChartEvent(const int id, const long& lparam, const double& dparam, const string& sparam) {
datetime _dt;
double _mp;
int _window = 0;
InterfaceEvent _event;


if (id == CHART_EVENT_MOUSE_MOVE) {
Interface::mouse_pos_x = (int)lparam;
Interface::mouse_pos_y = (int)dparam;
Expand All @@ -63,56 +63,56 @@ void OnChartEvent(const int id, const long& lparam, const double& dparam, const
_event.data.mouse.x = Interface::mouse_pos_x;
_event.data.mouse.y = Interface::mouse_pos_y;
Interface::FireEvent(_event);
}
}
}

typedef void (*InterfaceListener)(InterfaceEvent&, void*);

class Interface
{
public:

struct Installation
{
InterfaceListener listener;
void* target;
};

static Installation installations[];

static bool mouse_was_down;
static int mouse_pos_x;
static int mouse_pos_y;
static bool initialized;

static void AddListener(InterfaceListener _listener, void* _target) {
if (!initialized) {
ChartSetInteger(0, CHART_EVENT_MOUSE_MOVE, true);
ChartRedraw();
initialized = true;
}

for (int i = 0; i < ArraySize(installations); ++i) {
if (installations[i].listener == _listener) {
// Listener already added.
return;
}
}

Installation _installation;
_installation.listener = _listener;
_installation.target = _target;

Util::ArrayPush(installations, _installation);
}

static void FireEvent(InterfaceEvent& _event) {
for (int i = 0; i < ArraySize(installations); ++i) {
Installation _installation = installations[i];
_installation.listener(_event, _installation.target);
}
}

static int GetMouseX() {
return mouse_pos_x;
}
Expand Down
2 changes: 1 addition & 1 deletion 3D/Mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,4 +253,4 @@ class Mesh : public Dynamic {
ibuff = _ibuff = _device.IndexBuffer(_indices);
return true;
}
};
};
2 changes: 1 addition & 1 deletion 3D/Shader.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,4 @@ class Shader : public Dynamic {
* Selectes shader to be used by graphics device for rendering.
*/
virtual void Select() = NULL;
};
};
2 changes: 1 addition & 1 deletion 3D/Shaders/cube_vs.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ OUTPUT main(INPUT input) {
output.color = input.color * mat_color;

return output;
}
}
2 changes: 1 addition & 1 deletion 3D/TSR.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ class TSR {

return _mtx_result;
}
};
};
2 changes: 1 addition & 1 deletion 3D/VertexBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ class VertexBuffer : public Dynamic {
Device* GetDevice() { return device.Ptr(); }

virtual void Select() = NULL;
};
};
2 changes: 1 addition & 1 deletion Instances.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ class Instances {
};

template<typename T>
T* Instances::instances[];
T* Instances::instances[];
Loading

0 comments on commit fdf4087

Please sign in to comment.