Fix issue where clipping in world space not transformed

main
Cameron Murphy Reikes 2 years ago
parent 41f963ad98
commit 0d07dc9f73

@ -150,5 +150,5 @@
} }
@level level0: @level level0:
{ {
filepath: "new_level.json", filepath: "newsmalllevel.json",
} }

@ -96,14 +96,14 @@
"rotation":0, "rotation":0,
"visible":true, "visible":true,
"width":32, "width":32,
"x":46.4621212121228, "x":173.128787878789,
"y":115.727272727277 "y":107.06060606061
}, },
{ {
"class":"", "class":"",
"height":32, "height":32,
"id":17, "id":17,
"name":"OldMan", "name":"TheBlacksmith",
"properties":[ "properties":[
{ {
"name":"standing", "name":"standing",
@ -115,23 +115,6 @@
"width":32, "width":32,
"x":240, "x":240,
"y":106 "y":106
},
{
"class":"",
"height":32,
"id":18,
"name":"OldMan",
"properties":[
{
"name":"standing",
"type":"string",
"value":"STANDING_JOINED"
}],
"rotation":0,
"visible":true,
"width":32,
"x":236,
"y":472
}], }],
"opacity":1, "opacity":1,
"type":"objectgroup", "type":"objectgroup",

@ -26,17 +26,6 @@
"id":2, "id":2,
"name":"objects", "name":"objects",
"objects":[ "objects":[
{
"class":"",
"height":31.604938271605,
"id":1,
"name":"MERCHANT",
"rotation":0,
"visible":true,
"width":29.9415204678363,
"x":167,
"y":81.5
},
{ {
"class":"", "class":"",
"height":31.6049, "height":31.6049,
@ -47,6 +36,23 @@
"width":29.9415, "width":29.9415,
"x":68.02925, "x":68.02925,
"y":88.19755 "y":88.19755
},
{
"class":"",
"height":32,
"id":3,
"name":"TheBlacksmith",
"properties":[
{
"name":"held_items",
"type":"string",
"value":"{.data = {ITEM_Chalice}, .cur_index = 1}"
}],
"rotation":0,
"visible":true,
"width":32,
"x":165.353383458647,
"y":104.300751879699
}], }],
"opacity":1, "opacity":1,
"type":"objectgroup", "type":"objectgroup",
@ -74,7 +80,7 @@
"y":0 "y":0
}], }],
"nextlayerid":4, "nextlayerid":4,
"nextobjectid":3, "nextobjectid":4,
"orientation":"orthogonal", "orientation":"orthogonal",
"renderorder":"right-down", "renderorder":"right-down",
"tiledversion":"1.9.2", "tiledversion":"1.9.2",

@ -9,6 +9,8 @@
// you can't do &(some func, variable) to get the variable's address in C. Sad! // you can't do &(some func, variable) to get the variable's address in C. Sad!
#define GET_TABLE_PTR(table, index) (assert(index < ARRLEN(table) && index >= 0), &table[index]) #define GET_TABLE_PTR(table, index) (assert(index < ARRLEN(table) && index >= 0), &table[index])
#define RANGE_ITER(from, to) for(int i = from; i < to; i++)
// null terminator always built into buffers so can read properly from data // null terminator always built into buffers so can read properly from data
#define BUFF_VALID(buff_ptr) assert((buff_ptr)->cur_index <= ARRLEN((buff_ptr)->data)) #define BUFF_VALID(buff_ptr) assert((buff_ptr)->cur_index <= ARRLEN((buff_ptr)->data))
#define BUFF(type, max_size) struct { int cur_index; type data[max_size]; char null_terminator; } #define BUFF(type, max_size) struct { int cur_index; type data[max_size]; char null_terminator; }

@ -727,6 +727,7 @@ void reset_level()
} }
update_player_from_entities(); update_player_from_entities();
#ifdef DEVTOOLS
if(false) if(false)
{ {
BUFF_APPEND(&player->held_items, ITEM_WhiteSquare); BUFF_APPEND(&player->held_items, ITEM_WhiteSquare);
@ -738,11 +739,13 @@ void reset_level()
{ {
if (it->npc_kind == NPC_TheBlacksmith) if (it->npc_kind == NPC_TheBlacksmith)
{ {
//BUFF_APPEND(&it->remembered_perceptions, ((Perception) { .type = PlayerDialog, .player_dialog = SENTENCE_CONST("Testing dialog") })); //RANGE_ITER(0, 20)
//BUFF_APPEND(&it->remembered_perceptions, ((Perception) { .type = PlayerDialog, .player_dialog = SENTENCE_CONST("Testing dialog") }));
//BUFF_APPEND(&it->held_items, ITEM_Chalice); //BUFF_APPEND(&it->held_items, ITEM_Chalice);
} }
} }
#endif
} }
@ -1438,6 +1441,13 @@ void draw_quad(DrawParams d)
points[i] = world_to_screen(points[i]); points[i] = world_to_screen(points[i]);
} }
} }
if (d.do_clipping && d.world_space)
{
d.clip_to.upper_left = world_to_screen(d.clip_to.upper_left);
d.clip_to.lower_right = world_to_screen(d.clip_to.lower_right);
}
// we've aplied the world space transform // we've aplied the world space transform
d.world_space = false; d.world_space = false;
@ -2002,6 +2012,7 @@ typedef struct
Color *colors; Color *colors;
float text_scale; float text_scale;
AABB clip_to; AABB clip_to;
bool do_clipping;
bool screen_space; bool screen_space;
} WrappedTextParams; } WrappedTextParams;
@ -2024,7 +2035,7 @@ float draw_wrapped_text(WrappedTextParams p)
memset(line_to_draw, 0, MAX_SENTENCE_LENGTH); memset(line_to_draw, 0, MAX_SENTENCE_LENGTH);
memcpy(line_to_draw, sentence_to_draw, chars_from_sentence); memcpy(line_to_draw, sentence_to_draw, chars_from_sentence);
line_bounds = draw_text((TextParams) { !p.screen_space, true, line_to_draw, cursor, BLACK, p.text_scale, p.clip_to }); line_bounds = draw_text((TextParams) { !p.screen_space, true, line_to_draw, cursor, BLACK, p.text_scale, p.clip_to, .do_clipping = p.do_clipping});
if (line_bounds.lower_right.X > p.at_point.X + p.max_width) if (line_bounds.lower_right.X > p.at_point.X + p.max_width)
{ {
// too big // too big
@ -2041,7 +2052,7 @@ float draw_wrapped_text(WrappedTextParams p)
//float line_height = line_bounds.upper_left.Y - line_bounds.lower_right.Y; //float line_height = line_bounds.upper_left.Y - line_bounds.lower_right.Y;
float line_height = font_line_advance * p.text_scale; float line_height = font_line_advance * p.text_scale;
AABB drawn_bounds = draw_text((TextParams) { !p.screen_space, p.dry_run, line_to_draw, AddV2(cursor, V2(0.0f, -line_height)), BLACK, p.text_scale, p.clip_to, colors_to_draw }); AABB drawn_bounds = draw_text((TextParams) { !p.screen_space, p.dry_run, line_to_draw, AddV2(cursor, V2(0.0f, -line_height)), BLACK, p.text_scale, p.clip_to, colors_to_draw, .do_clipping = p.do_clipping});
if (!p.dry_run) dbgrect(drawn_bounds); if (!p.dry_run) dbgrect(drawn_bounds);
// caught a random infinite loop in the debugger, this will stop it // caught a random infinite loop in the debugger, this will stop it
@ -2153,12 +2164,15 @@ Dialog produce_dialog(Entity *talking_to, bool character_names)
return to_return; return to_return;
} }
Vec2 mouse_pos = { 0 }; // in screen space
void draw_dialog_panel(Entity *talking_to, float alpha) void draw_dialog_panel(Entity *talking_to, float alpha)
{ {
float panel_width = 250.0f; float panel_width = 250.0f;
float panel_height = 150.0f; float panel_height = 150.0f;
float panel_vert_offset = 30.0f; float panel_vert_offset = 30.0f;
AABB dialog_panel = (AABB) { AABB dialog_panel = (AABB) {
.upper_left = AddV2(talking_to->pos, V2(-panel_width / 2.0f, panel_vert_offset + panel_height)), .upper_left = AddV2(talking_to->pos, V2(-panel_width / 2.0f, panel_vert_offset + panel_height)),
.lower_right = AddV2(talking_to->pos, V2(panel_width / 2.0f, panel_vert_offset)), .lower_right = AddV2(talking_to->pos, V2(panel_width / 2.0f, panel_vert_offset)),
@ -2224,9 +2238,9 @@ void draw_dialog_panel(Entity *talking_to, float alpha)
} }
colors[char_i] = blendalpha(colors[char_i], alpha); colors[char_i] = blendalpha(colors[char_i], alpha);
} }
float measured_line_height = draw_wrapped_text((WrappedTextParams) { true, V2(dialog_panel.upper_left.X, new_line_height), dialog_panel.lower_right.X - dialog_panel.upper_left.X, it->s.data, colors, 0.5f, dialog_panel }); float measured_line_height = draw_wrapped_text((WrappedTextParams) { true, V2(dialog_panel.upper_left.X, new_line_height), dialog_panel.lower_right.X - dialog_panel.upper_left.X, it->s.data, colors, 0.5f, .clip_to = dialog_panel, .do_clipping = true});
new_line_height += (new_line_height - measured_line_height); new_line_height += (new_line_height - measured_line_height);
draw_wrapped_text((WrappedTextParams) { false, V2(dialog_panel.upper_left.X, new_line_height), dialog_panel.lower_right.X - dialog_panel.upper_left.X, it->s.data, colors, 0.5f, dialog_panel }); draw_wrapped_text((WrappedTextParams) { false, V2(dialog_panel.upper_left.X, new_line_height), dialog_panel.lower_right.X - dialog_panel.upper_left.X, it->s.data, colors, 0.5f, dialog_panel, .do_clipping = true });
free(colors); free(colors);
} }
@ -2244,7 +2258,6 @@ double elapsed_time = 0.0;
double unwarped_elapsed_time = 0.0; double unwarped_elapsed_time = 0.0;
double last_frame_processing_time = 0.0; double last_frame_processing_time = 0.0;
uint64_t last_frame_time; uint64_t last_frame_time;
Vec2 mouse_pos = { 0 }; // in screen space
typedef struct typedef struct
{ {
@ -3795,9 +3808,9 @@ void frame(void)
} }
colors[char_i] = blendalpha(colors[char_i], alpha); colors[char_i] = blendalpha(colors[char_i], alpha);
} }
float measured_line_height = draw_wrapped_text((WrappedTextParams) { true, V2(dialog_text_aabb.upper_left.X, new_line_height), dialog_text_aabb.lower_right.X - dialog_text_aabb.upper_left.X, it->s.data, colors, dialog_text_scale, dialog_text_aabb, .screen_space = true }); float measured_line_height = draw_wrapped_text((WrappedTextParams) { true, V2(dialog_text_aabb.upper_left.X, new_line_height), dialog_text_aabb.lower_right.X - dialog_text_aabb.upper_left.X, it->s.data, colors, dialog_text_scale, dialog_text_aabb, .screen_space = true, .do_clipping = true});
new_line_height += (new_line_height - measured_line_height); new_line_height += (new_line_height - measured_line_height);
draw_wrapped_text((WrappedTextParams) { false, V2(dialog_text_aabb.upper_left.X, new_line_height), dialog_text_aabb.lower_right.X - dialog_text_aabb.upper_left.X, it->s.data, colors, dialog_text_scale, dialog_text_aabb, .screen_space = true }); draw_wrapped_text((WrappedTextParams) { false, V2(dialog_text_aabb.upper_left.X, new_line_height), dialog_text_aabb.lower_right.X - dialog_text_aabb.upper_left.X, it->s.data, colors, dialog_text_scale, dialog_text_aabb, .screen_space = true, .do_clipping = true});
free(colors); free(colors);
} }
@ -4011,8 +4024,9 @@ void frame(void)
PROFILE_SCOPE("flush rendering") PROFILE_SCOPE("flush rendering")
{ {
ARR_ITER(RenderingQueue, rendering_queues) ARR_ITER_I(RenderingQueue, rendering_queues, i)
{ {
Layer layer = (Layer)i;
RenderingQueue *rendering_queue = it; RenderingQueue *rendering_queue = it;
qsort(&rendering_queue->data[0], rendering_queue->cur_index, sizeof(rendering_queue->data[0]), rendering_compare); qsort(&rendering_queue->data[0], rendering_queue->cur_index, sizeof(rendering_queue->data[0]), rendering_compare);
@ -4021,6 +4035,7 @@ void frame(void)
DrawParams d = *it; DrawParams d = *it;
PROFILE_SCOPE("Draw quad") PROFILE_SCOPE("Draw quad")
{ {
assert(!d.world_space); // world space already applied when queued for drawing
Vec2 *points = d.quad.points; Vec2 *points = d.quad.points;
quad_fs_params_t params = { 0 }; quad_fs_params_t params = { 0 };
params.tint[0] = d.tint.R; params.tint[0] = d.tint.R;
@ -4030,11 +4045,6 @@ void frame(void)
params.alpha_clip_threshold = d.alpha_clip_threshold; params.alpha_clip_threshold = d.alpha_clip_threshold;
if (d.do_clipping) if (d.do_clipping)
{ {
if (d.world_space)
{
d.clip_to.upper_left = world_to_screen(d.clip_to.upper_left);
d.clip_to.lower_right = world_to_screen(d.clip_to.lower_right);
}
Vec2 aabb_clip_ul = into_clip_space(d.clip_to.upper_left); Vec2 aabb_clip_ul = into_clip_space(d.clip_to.upper_left);
Vec2 aabb_clip_lr = into_clip_space(d.clip_to.lower_right); Vec2 aabb_clip_lr = into_clip_space(d.clip_to.lower_right);
params.clip_ul[0] = aabb_clip_ul.x; params.clip_ul[0] = aabb_clip_ul.x;

@ -241,6 +241,8 @@ typedef struct Entity
bool in_conversation_mode; bool in_conversation_mode;
Vec2 to_throw_direction; Vec2 to_throw_direction;
BUFF(Vec2, 8) position_history; // so npcs can follow behind the player
CharacterState state; CharacterState state;
EntityRef talking_to; EntityRef talking_to;
bool is_rolling; // can only roll in idle or walk states bool is_rolling; // can only roll in idle or walk states

Loading…
Cancel
Save