Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
Kayak UI 0.11
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Microhacks
Bevy Forks
Kayak UI 0.11
Commits
658f0ebc
Unverified
Commit
658f0ebc
authored
2 years ago
by
John
Committed by
GitHub
2 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #253 from StarArawn/dashmap
Use dashmap more
parents
33cda10b
5975bc3c
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/context.rs
+194
-240
194 additions, 240 deletions
src/context.rs
src/widget_context.rs
+39
-56
39 additions, 56 deletions
src/widget_context.rs
with
233 additions
and
296 deletions
src/context.rs
+
194
−
240
View file @
658f0ebc
This diff is collapsed.
Click to expand it.
src/widget_context.rs
+
39
−
56
View file @
658f0ebc
use
std
::
sync
::{
Arc
,
RwLock
};
use
bevy
::{
prelude
::{
BuildChildren
,
Commands
,
Component
,
Entity
,
Resource
},
utils
::
HashMap
,
};
use
bevy
::
prelude
::{
BuildChildren
,
Commands
,
Component
,
Entity
,
Resource
};
use
dashmap
::
DashMap
;
use
morphorm
::
Hierarchy
;
use
crate
::{
...
...
@@ -23,15 +21,15 @@ pub struct KayakWidgetContext {
new_tree
:
Arc
<
RwLock
<
Tree
>>
,
context_entities
:
ContextEntities
,
layout_cache
:
Arc
<
RwLock
<
LayoutCache
>>
,
pub
(
crate
)
index
:
Arc
<
RwLock
<
H
ashMap
<
Entity
,
usize
>
>>
,
pub
(
crate
)
index
:
D
ashMap
<
Entity
,
usize
>
,
widget_state
:
WidgetState
,
pub
(
crate
)
order_tree
:
Arc
<
RwLock
<
Tree
>>
,
pub
camera_entity
:
Option
<
Entity
>
,
// Unique id's store entity id's related to a key rather than the child tree.
// This lets users get a unique entity. The first Entity is the parent widget.
// The 2nd hashmap is a list of keys and their entities.
unique_ids
:
Arc
<
RwLock
<
H
ashMap
<
Entity
,
H
ashMap
<
String
,
Entity
>>
>>
,
unique_ids_parents
:
Arc
<
RwLock
<
H
ashMap
<
Entity
,
Entity
>
>>
,
unique_ids
:
D
ashMap
<
Entity
,
D
ashMap
<
String
,
Entity
>>
,
unique_ids_parents
:
D
ashMap
<
Entity
,
Entity
>
,
}
impl
KayakWidgetContext
{
...
...
@@ -41,10 +39,10 @@ impl KayakWidgetContext {
layout_cache
:
Arc
<
RwLock
<
LayoutCache
>>
,
widget_state
:
WidgetState
,
order_tree
:
Arc
<
RwLock
<
Tree
>>
,
index
:
Arc
<
RwLock
<
H
ashMap
<
Entity
,
usize
>
>>
,
index
:
D
ashMap
<
Entity
,
usize
>
,
camera_entity
:
Option
<
Entity
>
,
unique_ids
:
Arc
<
RwLock
<
H
ashMap
<
Entity
,
H
ashMap
<
String
,
Entity
>>
>>
,
unique_ids_parents
:
Arc
<
RwLock
<
H
ashMap
<
Entity
,
Entity
>
>>
,
unique_ids
:
D
ashMap
<
Entity
,
D
ashMap
<
String
,
Entity
>>
,
unique_ids_parents
:
D
ashMap
<
Entity
,
Entity
>
,
)
->
Self
{
Self
{
old_tree
,
...
...
@@ -152,19 +150,15 @@ impl KayakWidgetContext {
}
fn
get_and_add_index
(
&
self
,
parent
:
Entity
)
->
usize
{
if
let
Ok
(
mut
hash_map
)
=
self
.index
.try_write
()
{
if
hash_map
.contains_key
(
&
parent
)
{
let
index
=
hash_map
.get_mut
(
&
parent
)
.unwrap
();
let
current_index
=
*
index
;
*
index
+=
1
;
return
current_index
;
}
else
{
hash_map
.insert
(
parent
,
1
);
return
0
;
}
if
self
.index
.contains_key
(
&
parent
)
{
let
mut
index
=
self
.index
.get_mut
(
&
parent
)
.unwrap
();
let
current_index
=
*
index
;
*
index
.value_mut
()
+=
1
;
current_index
}
else
{
self
.index
.insert
(
parent
,
1
);
0
}
0
}
/// Creates or grabs the existing state entity
...
...
@@ -206,27 +200,22 @@ impl KayakWidgetContext {
let
mut
entity
=
None
;
if
let
Some
(
parent_entity
)
=
parent_id
{
if
let
Some
(
key
)
=
key
.map
(|
key
|
key
.to_string
())
{
if
let
Ok
(
unique_ids
)
=
self
.unique_ids
.try_read
()
{
if
let
Some
(
key_hashmap
)
=
unique_ids
.get
(
&
parent_entity
)
{
entity
=
key_hashmap
.get
(
&
key
)
.cloned
();
if
let
Some
(
child
)
=
entity
{
if
let
Some
(
mut
entity_commands
)
=
commands
.get_entity
(
child
)
{
entity_commands
.despawn
();
}
entity
=
Some
(
commands
.get_or_spawn
(
child
)
.set_parent
(
parent_entity
)
.id
());
log
::
trace!
(
"Reusing keyed widget entity {:?} with parent: {:?}!"
,
child
.index
(),
parent_id
.unwrap
()
.index
()
);
if
let
Some
(
key_hashmap
)
=
self
.unique_ids
.get
(
&
parent_entity
)
{
entity
=
key_hashmap
.get
(
&
key
)
.map
(|
v
|
*
v
.value
());
if
let
Some
(
child
)
=
entity
{
if
let
Some
(
mut
entity_commands
)
=
commands
.get_entity
(
child
)
{
entity_commands
.despawn
();
}
}
else
{
log
::
trace!
(
"couldn't find key entity on parent!"
);
entity
=
Some
(
commands
.get_or_spawn
(
child
)
.set_parent
(
parent_entity
)
.id
());
log
::
trace!
(
"Reusing keyed widget entity {:?} with parent: {:?}!"
,
child
.index
(),
parent_id
.unwrap
()
.index
()
);
}
}
else
{
panic
!
(
"
C
ouldn't
get unique id lock
!"
);
log
::
trace
!
(
"
c
ouldn't
find key entity on parent
!"
);
}
}
else
{
let
children
=
self
.get_children_ordered
(
parent_entity
);
...
...
@@ -262,22 +251,16 @@ impl KayakWidgetContext {
commands
.entity
(
entity
.unwrap
())
.set_parent
(
parent_entity
);
if
let
Some
(
key
)
=
key
.map
(|
key
|
key
.to_string
())
{
if
let
Ok
(
mut
unique_ids
)
=
self
.unique_ids
.try_write
()
{
if
let
Some
(
key_hashmap
)
=
unique_ids
.get_mut
(
&
parent_entity
)
{
key_hashmap
.insert
(
key
,
entity
.unwrap
());
if
let
Ok
(
mut
unique_ids_parents
)
=
self
.unique_ids_parents
.try_write
()
{
unique_ids_parents
.insert
(
entity
.unwrap
(),
parent_entity
);
}
}
else
{
let
mut
key_hashmap
=
HashMap
::
new
();
key_hashmap
.insert
(
key
,
entity
.unwrap
());
unique_ids
.insert
(
parent_entity
,
key_hashmap
);
if
let
Ok
(
mut
unique_ids_parents
)
=
self
.unique_ids_parents
.try_write
()
{
unique_ids_parents
.insert
(
entity
.unwrap
(),
parent_entity
);
}
}
if
let
Some
(
key_hashmap
)
=
self
.unique_ids
.get_mut
(
&
parent_entity
)
{
key_hashmap
.insert
(
key
,
entity
.unwrap
());
self
.unique_ids_parents
.insert
(
entity
.unwrap
(),
parent_entity
);
}
else
{
let
key_hashmap
=
DashMap
::
new
();
key_hashmap
.insert
(
key
,
entity
.unwrap
());
self
.unique_ids
.insert
(
parent_entity
,
key_hashmap
);
self
.unique_ids_parents
.insert
(
entity
.unwrap
(),
parent_entity
);
}
}
else
{
// We need to add it to the ordered tree
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment