Skip to content

Commit 203165f

Browse files
committed
feat(ECS模式): begin
1 parent 7d4ce93 commit 203165f

File tree

5 files changed

+456
-460
lines changed

5 files changed

+456
-460
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
这里与之前一样,我们将一个GameObject的数据保存在一个state中,然后用一个索引与其关联。具体就是:
3+
gameObject其实就是一个number类型的id值,
4+
gameObjectState保存了一个GameObject的数据
5+
gameObject与gameObjectState一一关联,这个关联体现在前者是WorldState->gameObjects这个Hash Map的Key,后者是它的Value
6+
7+
<!-- World封装了操作GameObject和组件的API -->
8+
9+
10+
11+
12+
组件与GameObject一样,我们将它的数据保存在一个state中,只是不需要索引。所以一个组件就等于一个组件state
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
我们将一个英雄的数据保存在一个state中,然后用一个索引与其关联。具体就是:
2+
normalHero、superHero其实就是一个number类型的id值
3+
normalHeroState、superHeroState分别保存了一个普通英雄、一个超级英雄的数据(比如position、velocity)
4+
normalHero与normalHeroState一一关联,这个关联体现在前者是WorldState->normalHeroes这个Hash Map的Key,后者是它的Value
5+
同理,superHero与superHeroState关联
6+

ECS模式代码/story_before/src/NormalHero.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { state as normalHeroState, hero as normalHero } from "./NormalHeroStateT
33
import { state as worldState } from "./WorldStateType";
44
import { getNormalHeroState, setNormalHeroState } from "./WorldUtils";
55

6+
// create函数负责创建一个普通英雄,该英雄的数据保存在一个normalHeroState中,并生成一个全局唯一的索引id与其关联
67
export let create = (): [normalHeroState, normalHero] => {
78
let normalHeroState: normalHeroState = {
89
position: [0, 0, 0],
@@ -17,6 +18,7 @@ export let create = (): [normalHeroState, normalHero] => {
1718
]
1819
}
1920

21+
//这里只是给出了伪代码用于演示而已,实际的update函数应该会根据该普通英雄的层级关系和本地坐标来更新他的模型矩阵
2022
export let update = (normalHeroState: normalHeroState): normalHeroState => {
2123
console.log("更新NormalHero")
2224

doc/第四轮.org

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
* TODO 更新代码库,给出索引、how to run
77

8+
** TODO update README
9+
810
** TODO give where has code, uml and how to run code and run result for each example
911

1012
TODO give how to run rescript code(pipeline pattern should mention it!)

0 commit comments

Comments
 (0)