Skip to content

Commit

Permalink
library: separate renderminimap functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Adamcake committed Dec 1, 2024
1 parent 0ac8aad commit 1599096
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 8 deletions.
16 changes: 14 additions & 2 deletions src/library/doc.texi
Original file line number Diff line number Diff line change
Expand Up @@ -2477,7 +2477,19 @@ and @ref{objects-minimaprender2d}.

@eventobjectwarning{}

@node renderminimap-xywh
@node renderminimap-sourcexywh
@subsection xywh

Returns the x, y, width and height of the section of the minimap image
being drawn, in pixels.

@example lua
@verbatim
local x, y, width, height = event:targetxywh()
@end verbatim
@end example

@node renderminimap-targetxywh
@subsection xywh

Returns the x, y, width and height of where the minimap is being drawn
Expand All @@ -2486,7 +2498,7 @@ top-left pixel of the inner area of the window.

@example lua
@verbatim
local x, y, width, height = event:xywh()
local x, y, width, height = event:targetxywh()
@end verbatim
@end example

Expand Down
19 changes: 16 additions & 3 deletions src/library/gl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1392,12 +1392,25 @@ void _bolt_gl_onDrawElements(GLenum mode, GLsizei count, GLenum type, const void
const uint8_t is_minimap2d_target = tex_target && tex_target->is_minimap_tex_small;

if (tex->is_minimap_tex_small && count == 6) {
const struct GLAttrBinding* binding = &attributes[c->bound_program->loc_aVertexPosition2D];
const struct GLAttrBinding* position = &attributes[c->bound_program->loc_aVertexPosition2D];
const struct GLAttrBinding* uv = &attributes[c->bound_program->loc_aTextureUV];
int32_t xy0[2];
int32_t xy2[2];
if (!_bolt_get_attr_binding_int(c, binding, 0, 2, xy0)) return;
if (!_bolt_get_attr_binding_int(c, binding, 2, 2, xy2)) return;
float uv0[2];
float uv2[2];
if (!_bolt_get_attr_binding_int(c, position, 0, 2, xy0)) return;
if (!_bolt_get_attr_binding_int(c, position, 2, 2, xy2)) return;
_bolt_get_attr_binding(c, uv, 0, 2, uv0);
_bolt_get_attr_binding(c, uv, 2, 2, uv2);
const int16_t x1 = (int16_t)roundf(uv0[0] * tex->width);
const int16_t x2 = (int16_t)roundf(uv2[0] * tex->width);
const int16_t y1 = (int16_t)roundf(uv2[1] * tex->height);
const int16_t y2 = (int16_t)roundf(uv0[1] * tex->height);
const struct RenderMinimapEvent event = {
.source_x = x1,
.source_y = y1,
.source_w = x2 - x1,
.source_h = y2 - y1,
.target_x = (int16_t)xy0[0],
.target_y = (int16_t)(roundf(2.0 / projection_matrix[5]) - xy0[1]),
.target_w = (uint16_t)(xy2[0] - xy0[0]),
Expand Down
4 changes: 4 additions & 0 deletions src/library/plugin/plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,10 @@ struct MinimapTerrainEvent {
};

struct RenderMinimapEvent {
int16_t source_x;
int16_t source_y;
uint16_t source_w;
uint16_t source_h;
int16_t target_x;
int16_t target_y;
uint16_t target_w;
Expand Down
16 changes: 13 additions & 3 deletions src/library/plugin/plugin_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -785,8 +785,17 @@ static int api_minimapterrain_position(lua_State* state) {
return 2;
}

static int api_renderminimap_xywh(lua_State* state) {
const struct RenderMinimapEvent* render = require_self_userdata(state, "xywh");
static int api_renderminimap_sourcexywh(lua_State* state) {
const struct RenderMinimapEvent* render = require_self_userdata(state, "sourcexywh");
lua_pushinteger(state, render->source_x);
lua_pushinteger(state, render->source_y);
lua_pushinteger(state, render->source_w);
lua_pushinteger(state, render->source_h);
return 4;
}

static int api_renderminimap_targetxywh(lua_State* state) {
const struct RenderMinimapEvent* render = require_self_userdata(state, "targetxywh");
lua_pushinteger(state, render->target_x);
lua_pushinteger(state, render->target_y);
lua_pushinteger(state, render->target_w);
Expand Down Expand Up @@ -1648,7 +1657,8 @@ static struct ApiFuncTemplate minimapterrain_functions[] = {
};

static struct ApiFuncTemplate renderminimap_functions[] = {
BOLTFUNC(xywh, renderminimap),
BOLTFUNC(sourcexywh, renderminimap),
BOLTFUNC(targetxywh, renderminimap),
};

static struct ApiFuncTemplate point_functions[] = {
Expand Down

0 comments on commit 1599096

Please sign in to comment.