Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
GitCode
Cataclysm DDA
提交
aeea2e4d
C
Cataclysm DDA
项目概览
GitCode
/
Cataclysm DDA
通知
5
Star
6383
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
Cataclysm DDA
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
aeea2e4d
编写于
1月 13, 2022
作者:
D
David Seguin
提交者:
Eric Pierce
1月 14, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use display cache to boost performance
Also modifies the test to refresh the cache.
上级
17e14970
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
61 addition
and
3 deletion
+61
-3
src/display.cpp
src/display.cpp
+20
-2
src/display.h
src/display.h
+30
-0
tests/widget_test.cpp
tests/widget_test.cpp
+11
-1
未找到文件。
src/display.cpp
浏览文件 @
aeea2e4d
...
...
@@ -35,6 +35,15 @@ static const flag_id json_flag_THERMOMETER( "THERMOMETER" );
static
const
itype_id
fuel_type_muscle
(
"muscle"
);
// Cache for the overmap widget string
static
disp_overmap_cache
disp_om_cache
;
disp_overmap_cache
::
disp_overmap_cache
()
{
_center
=
overmap
::
invalid_tripoint
;
_mission
=
overmap
::
invalid_tripoint
;
}
// Get remotely controlled vehicle, or vehicle character is inside of
vehicle
*
display
::
vehicle_driven
(
const
Character
&
u
)
{
...
...
@@ -1232,14 +1241,19 @@ std::string display::colorized_overmap_text( const avatar &u, const int width, c
map
&
here
=
get_map
();
// Map is roughly centered around this point
const
point_abs_omt
center_xy
=
u
.
global_omt_location
().
xy
();
const
tripoint_abs_omt
&
center_xyz
=
u
.
global_omt_location
();
const
tripoint_abs_omt
&
mission_xyz
=
u
.
get_active_mission_target
();
// Retrieve cached string instead of constantly rebuilding it
if
(
disp_om_cache
.
is_valid_for
(
center_xyz
,
mission_xyz
)
)
{
return
disp_om_cache
.
get_val
();
}
// Scan each row of overmap tiles
for
(
int
row
=
-
(
height
/
2
);
row
<=
height
-
(
height
/
2
)
-
1
;
row
++
)
{
// Scan across the width of the row
for
(
int
col
=
-
(
width
/
2
);
col
<=
width
-
(
width
/
2
)
-
1
;
col
++
)
{
// Get colorized symbol for this point
const
tripoint_abs_omt
omt
(
center_xy
+
point
(
col
,
row
),
here
.
get_abs_sub
().
z
);
const
tripoint_abs_omt
omt
(
center_xy
z
.
xy
()
+
point
(
col
,
row
),
here
.
get_abs_sub
().
z
);
std
::
pair
<
std
::
string
,
nc_color
>
sym_color
=
display
::
overmap_tile_symbol_color
(
u
,
omt
);
// Highlight player character location in the center
...
...
@@ -1250,6 +1264,10 @@ std::string display::colorized_overmap_text( const avatar &u, const int width, c
}
overmap_text
+=
"
\n
"
;
}
// Rebuild the cache so we can reuse it if nothing changes
disp_om_cache
.
rebuild
(
center_xyz
,
mission_xyz
,
overmap_text
);
return
overmap_text
;
}
...
...
src/display.h
浏览文件 @
aeea2e4d
...
...
@@ -9,6 +9,36 @@
class
avatar
;
class
Character
;
struct
disp_overmap_cache
{
private:
tripoint_abs_omt
_center
;
tripoint_abs_omt
_mission
;
std
::
string
_om_wgt_str
;
public:
disp_overmap_cache
();
// Returns true if the stored overmap string can be used with the given
// center (player) position and mission target.
bool
is_valid_for
(
const
tripoint_abs_omt
&
center
,
const
tripoint_abs_omt
&
mission
)
const
{
return
_center
==
center
&&
_mission
==
mission
;
}
// Rebuild the cache using the validation parameters "center" and "mission"
// and store the associated widget string.
void
rebuild
(
const
tripoint_abs_omt
&
center
,
const
tripoint_abs_omt
&
mission
,
const
std
::
string
&
om_wgt_str
)
{
_center
=
center
;
_mission
=
mission
;
_om_wgt_str
=
om_wgt_str
;
}
// Retreive the cached widget string
const
std
::
string
&
get_val
()
const
{
return
_om_wgt_str
;
}
};
// The display namespace contains UI string output and colorization functions
// Some return plain strings or translations, some return a (string, color) pair,
// and some return a string with colorization tags embedded.
...
...
tests/widget_test.cpp
浏览文件 @
aeea2e4d
...
...
@@ -4,8 +4,10 @@
#include "player_helpers.h"
#include "map.h"
#include "map_helpers.h"
#include "mission.h"
#include "monster.h"
#include "morale.h"
#include "overmap.h"
#include "overmapbuffer.h"
#include "options_helpers.h"
#include "weather.h"
...
...
@@ -952,11 +954,12 @@ TEST_CASE( "widgets showing weather conditions", "[widget][weather]" )
// Fill a 3x3 overmap area around the avatar with a given overmap terrain
static
void
fill_overmap_area
(
const
avatar
&
ava
,
const
oter_id
&
oter
)
{
const
tripoint_abs_omt
ava_pos
(
ms_to_omt_copy
(
get_map
().
getabs
(
ava
.
pos
()
)
)
);
const
tripoint_abs_omt
&
ava_pos
=
ava
.
global_omt_location
(
);
for
(
int
x
=
-
1
;
x
<=
1
;
++
x
)
{
for
(
int
y
=
-
1
;
y
<=
1
;
++
y
)
{
const
tripoint
offset
(
x
,
y
,
0
);
overmap_buffer
.
ter_set
(
ava_pos
+
offset
,
oter
);
overmap_buffer
.
set_seen
(
ava_pos
+
offset
,
true
);
}
}
}
...
...
@@ -965,8 +968,12 @@ TEST_CASE( "multi-line overmap text widget", "[widget][overmap]" )
{
widget
overmap_w
=
widget_test_overmap_3x3_text
.
obj
();
avatar
&
ava
=
get_avatar
();
mission
msn
;
// Use mission target to invalidate the om cache
msn
.
set_target
(
ava
.
global_omt_location
()
+
tripoint
(
5
,
0
,
0
)
);
clear_avatar
();
clear_map
();
ava
.
on_mission_assignment
(
msn
);
SECTION
(
"field"
)
{
const
std
::
string
brown_dot
=
"<color_c_brown>.</color>"
;
...
...
@@ -978,6 +985,7 @@ TEST_CASE( "multi-line overmap text widget", "[widget][overmap]" )
};
fill_overmap_area
(
ava
,
oter_id
(
"field"
)
);
msn
.
set_target
(
msn
.
get_target
()
+
tripoint
(
1
,
0
,
0
)
);
CHECK
(
overmap_w
.
layout
(
ava
)
==
join
(
field_3x3
,
""
)
);
}
...
...
@@ -991,6 +999,7 @@ TEST_CASE( "multi-line overmap text widget", "[widget][overmap]" )
};
fill_overmap_area
(
ava
,
oter_id
(
"forest"
)
);
msn
.
set_target
(
msn
.
get_target
()
+
tripoint
(
2
,
0
,
0
)
);
CHECK
(
overmap_w
.
layout
(
ava
)
==
join
(
forest_3x3
,
""
)
);
}
...
...
@@ -1004,6 +1013,7 @@ TEST_CASE( "multi-line overmap text widget", "[widget][overmap]" )
};
fill_overmap_area
(
ava
,
oter_id
(
"central_lab"
)
);
msn
.
set_target
(
msn
.
get_target
()
+
tripoint
(
3
,
0
,
0
)
);
CHECK
(
overmap_w
.
layout
(
ava
)
==
join
(
lab_3x3
,
""
)
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录