Skip to content

Commit

Permalink
[Sapien] Move d3d line draw into h2codez
Browse files Browse the repository at this point in the history
  • Loading branch information
num0005 committed Oct 7, 2018
1 parent 9607f5c commit 74d4375
Showing 1 changed file with 35 additions and 6 deletions.
41 changes: 35 additions & 6 deletions H2Codez/H2Sapien/RenderDebug.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "RenderDebug.h"
#include <d3d9.h>
#include "..\Common\H2EKCommon.h"
#include "..\util\Patches.h"
#include "..\Tags\ScenarioStructureBSP.h"
Expand All @@ -10,20 +11,48 @@ scenario_structure_bsp_block *get_sbsp()
return *reinterpret_cast<scenario_structure_bsp_block **>(0xA9CA74);
}

IDirect3DDevice9Ex *get_global_d3d_device()
{
return *reinterpret_cast<IDirect3DDevice9Ex **>(0xFE6B34);
}

struct s_debug_vertex
{
real_point3d point;
D3DCOLOR colour;
};
CHECK_STRUCT_SIZE(s_debug_vertex, 0x10);

inline D3DCOLOR halo_colour_to_d3d_colour(const colour_rgba *colour)
{
auto halo_to_hex = [](float num) -> int { return int(num * 255); };

return D3DCOLOR_ARGB(halo_to_hex(colour->alpha), halo_to_hex(colour->red), halo_to_hex(colour->green), halo_to_hex(colour->blue));
}

void draw_debug_line(real_point3d *v0, real_point3d *v1,
const colour_rgba *start_colour = nullptr,
const colour_rgba *end_colour = nullptr)
{
const static colour_rgba black;

const static colour_rgba white;
if (!start_colour)
{
start_colour = &black;
start_colour = &white;
}

typedef void __cdecl draw_debug_line(real_point3d *v0, real_point3d *v1, const colour_rgba *start_colour, const colour_rgba *end_colour);
auto draw_debug_line_impl = reinterpret_cast<draw_debug_line*>(0x715AF0);
draw_debug_line_impl(v0, v1, start_colour, end_colour);
if (!end_colour)
{
end_colour = start_colour;
}

s_debug_vertex line_info[2];
line_info[0].point = *v0;
line_info[0].colour = halo_colour_to_d3d_colour(start_colour);
line_info[1].point = *v1;
line_info[1].colour = halo_colour_to_d3d_colour(end_colour);


LOG_CHECK(get_global_d3d_device()->DrawPrimitiveUP(D3DPT_LINELIST, 1, line_info, sizeof(s_debug_vertex)) == NOERROR);
}

const colour_rgba pathfinding_debug_colour_default( 1.0f, 0.0f, 1.0f, 1.0f );
Expand Down

0 comments on commit 74d4375

Please sign in to comment.