Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
scilla-core
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
劳工
scilla-core
Commits
d8bc031b
Commit
d8bc031b
authored
Jun 18, 2019
by
rockyl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加makeRandom
removeChild和removeChildAt返回被删除实体
parent
d4bbf423
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
30 additions
and
12 deletions
+30
-12
Entity.ts
src/core/Entity.ts
+7
-3
ObjectPool.ts
src/support/ObjectPool.ts
+8
-8
index.ts
src/support/index.ts
+6
-1
math.ts
src/tools/math.ts
+9
-0
No files found.
src/core/Entity.ts
View file @
d8bc031b
...
@@ -230,7 +230,7 @@ export class Entity extends HashObject {
...
@@ -230,7 +230,7 @@ export class Entity extends HashObject {
removeChild
(
child
:
Entity
)
{
removeChild
(
child
:
Entity
)
{
const
index
=
this
.
getChildIndex
(
child
);
const
index
=
this
.
getChildIndex
(
child
);
if
(
index
>=
0
)
{
if
(
index
>=
0
)
{
this
.
removeChildAt
(
index
);
return
this
.
removeChildAt
(
index
);
}
}
}
}
...
@@ -240,9 +240,13 @@ export class Entity extends HashObject {
...
@@ -240,9 +240,13 @@ export class Entity extends HashObject {
*/
*/
removeChildAt
(
index
:
number
)
{
removeChildAt
(
index
:
number
)
{
const
child
=
this
.
_children
[
index
];
const
child
=
this
.
_children
[
index
];
this
.
_onChildRemoved
(
child
);
this
.
_children
.
splice
(
index
,
1
);
if
(
child
){
this
.
_onChildRemoved
(
child
);
this
.
_children
.
splice
(
index
,
1
);
return
child
;
}
}
}
/**
/**
...
...
src/support/ObjectPool.ts
View file @
d8bc031b
...
@@ -3,12 +3,12 @@
...
@@ -3,12 +3,12 @@
*
*
* 对象池
* 对象池
*/
*/
let
all
=
{};
let
all
=
{};
function
getGroup
(
name
:
string
){
function
getGroup
(
name
:
string
)
{
let
group
=
all
[
name
];
let
group
=
all
[
name
];
if
(
!
group
)
{
if
(
!
group
)
{
throw
new
Error
(
'group '
+
name
+
' not registered.'
);
throw
new
Error
(
'group '
+
name
+
' not registered.'
);
}
}
...
@@ -21,7 +21,7 @@ function getGroup(name: string){
...
@@ -21,7 +21,7 @@ function getGroup(name: string){
* @param newFunc 实例化方法
* @param newFunc 实例化方法
* @param initFunc 初始化方法
* @param initFunc 初始化方法
*/
*/
export
function
register
(
name
:
string
,
newFunc
:
Function
,
initFunc
:
Function
)
{
export
function
register
(
name
:
string
,
newFunc
:
()
=>
any
,
initFunc
:
(
instance
:
any
,
...
params
)
=>
void
)
{
all
[
name
]
=
{
name
,
newFunc
,
initFunc
,
pool
:
[]};
all
[
name
]
=
{
name
,
newFunc
,
initFunc
,
pool
:
[]};
}
}
...
@@ -30,15 +30,15 @@ export function register(name: string, newFunc: Function, initFunc: Function){
...
@@ -30,15 +30,15 @@ export function register(name: string, newFunc: Function, initFunc: Function){
* @param name 池名称
* @param name 池名称
* @param params 参数
* @param params 参数
*/
*/
export
function
get
(
name
:
string
,
...
params
){
export
function
get
(
name
:
string
,
...
params
)
{
let
group
=
getGroup
(
name
);
let
group
=
getGroup
(
name
);
let
{
newFunc
,
initFunc
,
pool
}
=
group
;
let
{
newFunc
,
initFunc
,
pool
}
=
group
;
let
instance
;
let
instance
;
if
(
pool
.
length
==
0
)
{
if
(
pool
.
length
==
0
)
{
instance
=
newFunc
();
instance
=
newFunc
();
}
else
{
}
else
{
instance
=
pool
.
pop
();
instance
=
pool
.
pop
();
}
}
...
@@ -52,7 +52,7 @@ export function get(name: string, ...params){
...
@@ -52,7 +52,7 @@ export function get(name: string, ...params){
* @param name 池名称
* @param name 池名称
* @param instance 实例
* @param instance 实例
*/
*/
export
function
recycle
(
name
:
string
,
instance
){
export
function
recycle
(
name
:
string
,
instance
)
{
let
group
=
getGroup
(
name
);
let
group
=
getGroup
(
name
);
group
.
pool
.
push
(
instance
);
group
.
pool
.
push
(
instance
);
...
...
src/support/index.ts
View file @
d8bc031b
...
@@ -14,4 +14,9 @@ export {default as LocalStorage} from './LocalStorage'
...
@@ -14,4 +14,9 @@ export {default as LocalStorage} from './LocalStorage'
export
{
TextStyle
}
from
'./TextStyle'
export
{
TextStyle
}
from
'./TextStyle'
export
{
default
as
EventEmitter
}
from
'./EventEmitter'
;
export
{
default
as
EventEmitter
}
from
'./EventEmitter'
;
export
{
default
as
dataCenter
}
from
'./DataCenter'
;
export
{
default
as
dataCenter
}
from
'./DataCenter'
;
\ No newline at end of file
import
*
as
ObjectPool
from
'./ObjectPool'
export
{
ObjectPool
};
\ No newline at end of file
src/tools/math.ts
View file @
d8bc031b
...
@@ -61,6 +61,15 @@ export function makeRandomInt(max: number, min: number = 0): number {
...
@@ -61,6 +61,15 @@ export function makeRandomInt(max: number, min: number = 0): number {
return
Math
.
floor
(
Math
.
random
()
*
(
max
-
min
))
+
min
;
return
Math
.
floor
(
Math
.
random
()
*
(
max
-
min
))
+
min
;
}
}
/**
* 随机生成一个数
* @param max
* @param min
*/
export
function
makeRandom
(
max
:
number
,
min
:
number
=
0
):
number
{
return
Math
.
random
()
*
(
max
-
min
)
+
min
;
}
/**
/**
* 打乱一个数组
* 打乱一个数组
* @param arr
* @param arr
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment