From d422c6bdabab66338fef28f08d6d7bf4fdb62af7 Mon Sep 17 00:00:00 2001 From: jaysunxiao Date: Wed, 18 May 2022 21:08:42 +0800 Subject: [PATCH] doc --- README.md | 4 +- doc/demo01_hello/3.node.md | 2 +- doc/demo01_hello/5.node2d.md | 2 +- doc/demo05_scene_node/scene_node.md | 41 +++++- gdProtocol/ProtocolManager.gd | 12 +- gdProtocol/buffer/ByteBuffer.gd | 202 ++++++++++++++-------------- gdProtocol/packet/ComplexObject.gd | 3 +- gdProtocol/packet/NormalObject.gd | 3 +- gdProtocol/packet/ObjectA.gd | 3 +- gdProtocol/packet/ObjectB.gd | 3 +- gdProtocol/packet/SimpleObject.gd | 3 +- gdTest/GdProtocolTest.gd | 1 + 12 files changed, 158 insertions(+), 121 deletions(-) diff --git a/README.md b/README.md index b9f93b9..d570f42 100644 --- a/README.md +++ b/README.md @@ -12,4 +12,6 @@ ### 4.安装和HelloWorld -- 建议再看看底61集的视频,学会调整运行时候的屏幕位置,避免运行时候屏幕位置出现问题 +- 建议再看看底61集的视频,黑白控制台是否隐藏,学会调整运行时候的屏幕位置,避免运行时候屏幕位置出现问题 + +- fix:纠正P25说的深度优先遍历顺序,绘制节点的顺序应该是广度优先遍历 diff --git a/doc/demo01_hello/3.node.md b/doc/demo01_hello/3.node.md index 68a5827..564e231 100644 --- a/doc/demo01_hello/3.node.md +++ b/doc/demo01_hello/3.node.md @@ -56,7 +56,7 @@ CTRL + Z ,撤销上一步操作 - 在2D画面中,两个对象如果重叠,谁显示在上面呢? - 按照节点的顺序 -- 在数据结构上的专业术语叫树的深度优先遍历,深度优先遍历的顺序就是最后显示的顺序 +- 在数据结构上的专业术语叫树的广度优先遍历,广度优先遍历的顺序就是最后显示的顺序 ![Image text](../demo05_scene_node/image/节点.png) ![Image text](../demo05_scene_node/image/节点渲染顺序.png) diff --git a/doc/demo01_hello/5.node2d.md b/doc/demo01_hello/5.node2d.md index f685ba5..e298042 100644 --- a/doc/demo01_hello/5.node2d.md +++ b/doc/demo01_hello/5.node2d.md @@ -62,7 +62,7 @@ func _process(delta): - Canvas是画布的意思,所以CanvasItem代表了就是可以被绘制节点,可以设置可视化界面和材质的颜色 - 所有的2D节点和GUI节点都继承于CanvasItem节点 -- CanvasItem是按树的树的深度优先遍历顺序绘制的 +- CanvasItem是按树的树的广度优先遍历顺序绘制的 - 可以通过设置CanvasItem的Show Behind Parent来改变最终渲染到屏幕上的画面顺序 ``` diff --git a/doc/demo05_scene_node/scene_node.md b/doc/demo05_scene_node/scene_node.md index f714aae..c445c78 100644 --- a/doc/demo05_scene_node/scene_node.md +++ b/doc/demo05_scene_node/scene_node.md @@ -18,6 +18,7 @@ - 图片像素 + ![Image text](image/pixel.jpg) @@ -45,11 +46,10 @@ # 3. 垂直同步 -- Vsync,垂直同步 + +- Vsync,垂直同步又称场同步(Vertical Hold) ``` -垂直同步又称场同步(Vertical Hold),从CRT显示器的显示原理来看,单个像素组成了水平扫描线,水平扫描线在垂直方向的堆积形成了完整的画面。 -显示器的刷新率受显卡DAC控制,显卡DAC完成一帧的扫描后就会产生一个垂直同步信号。 我们平时所说的打开垂直同步指的是将该信号送入显卡3D图形处理部分,从而让显卡在生成3D图形时受垂直同步信号的制约。 当我们选择"等待垂直同步信号"(即打开垂直同步)时,显卡绘制3D图形前会等待垂直同步信号, @@ -66,6 +66,33 @@ ![Image text](image/window03.jpg) + +- CRT显示器学名为“阴极射线显像管”,是一种使用阴极射线管(Cathode Ray Tube)的显示器。 + +``` +屏幕上的图形图像是由一个个因电子束击打而发光的荧光点组成 + +电子枪从屏幕的左上角的第一行(行的多少根据显示器当时的分辨率所决定,比如800X600分辨率下,电子枪就要扫描600行)开始,从左至右逐行扫描, +第一行扫描完后再从第二行的最左端开始至第二行的最右端,一直到扫描完整个屏幕后再从屏幕的左上角开始,这时就完成了一次对屏幕的刷新,周而复始。 + +从CRT显示器的显示原理来看,单个像素组成了水平扫描线,水平扫描线在垂直方向的堆积形成了完整的画面。 +显示器的刷新率受显卡DAC控制,显卡DAC完成一帧的扫描后就会产生一个垂直同步信号。 +``` + +- 液晶显示器借助于薄膜晶体管驱动的有源矩阵液晶显示器,它主要是以电流刺激液晶分子产生点、线、面配合背部灯管构成画面。 + +``` + +在电场的作用下,利用液晶分子的排列方向发生变化,使外光源透光率改变(调制),完成电一光变换, +再利用R、G、B三基色信号的不同激励,通过红、绿、蓝三基色滤光膜,完成时域和空间域的彩色重显。 + +LCD的刷新率与CRT不同,因为LCD和CRT的显像方式不同,CRT是靠不断刷新画面来使显示器显示图像的,而LCD只要改变发光颗粒就能使显示器中的画面动起来 +正是由于LCD与CRT显像方式不同,LCD显示器本身不会出现屏幕闪烁的现象 + +打开垂直同步可以使得画面平滑、稳定。 +关闭垂直同步,则可以明显提高帧数,获得更快的速度,代价就是牺牲稳定性,显卡持续高负荷运转势必发热,进而影响计算速度。 +``` + # 4. 屏幕坐标 ![Image text](image/坐标系.png) @@ -112,20 +139,22 @@ func positionTest(): pass ``` -# 4. 场景和节点 +# 6. 深度遍历显示节点 ![Image text](image/场景.png) ![Image text](image/节点.png) ![Image text](image/节点渲染顺序.png) -![Image text](image/节点的顺序.png) - 一个游戏可以包含多个场景,但是一个场景中必须有一个根节点,一个根节点可以包含多个不重名的子节点(unity的子节点可以同名),不同名更加符合习惯,为godot点赞。 -# 5. 基本组件 +- fix:纠正P25说的深度优先遍历顺序,绘制节点的顺序应该是广度优先遍历 + +# 7. Image类的使用 - CanvasItem节点,CanvasItem -> Node -> Object - Canvas是画布的意思,所以CanvasItem代表了就是可以被绘制节点,可以设置可视化界面和材质的颜色 - 所有的2D节点和GUI节点都继承于CanvasItem节点 + ![Image text](image/节点的顺序.png) ![Image text](./image/component1.png) diff --git a/gdProtocol/ProtocolManager.gd b/gdProtocol/ProtocolManager.gd index 0e08f01..b2aab51 100644 --- a/gdProtocol/ProtocolManager.gd +++ b/gdProtocol/ProtocolManager.gd @@ -10,8 +10,8 @@ static func getProtocol(protocolId: int): return protocols[protocolId] static func newInstance(protocolId: int): - var protocol = protocols[protocolId] - return protocol.new() + var protocol = protocols[protocolId] + return protocol.new() static func write(buffer, packet): var protocolId: int = packet.PROTOCOL_ID @@ -20,10 +20,10 @@ static func write(buffer, packet): protocol.write(buffer, packet) static func read(buffer): - var protocolId = buffer.readShort(); - var protocol = protocols[protocolId] - var packet = protocol.read(buffer); - return packet; + var protocolId = buffer.readShort(); + var protocol = protocols[protocolId] + var packet = protocol.read(buffer); + return packet; static func initProtocol(): protocols[100] = ComplexObject diff --git a/gdProtocol/buffer/ByteBuffer.gd b/gdProtocol/buffer/ByteBuffer.gd index 8186a2a..f66cbfc 100644 --- a/gdProtocol/buffer/ByteBuffer.gd +++ b/gdProtocol/buffer/ByteBuffer.gd @@ -258,12 +258,12 @@ func readPacket(protocolId): func newInstance(protocolId: int): return ProtocolManager.newInstance(protocolId) -func writeBooleanArray(value): - if (value == null): +func writeBooleanArray(array): + if (array == null): writeInt(0) else: - writeInt(value.size()); - for element in value: + writeInt(array.size()); + for element in array: writeBool(element) func readBooleanArray(): @@ -274,12 +274,12 @@ func readBooleanArray(): array.append(readBool()) return array -func writeByteArray(value): - if (value == null): +func writeByteArray(array): + if (array == null): writeInt(0) else: - writeInt(value.size()); - for element in value: + writeInt(array.size()); + for element in array: writeByte(element) func readByteArray(): @@ -290,12 +290,12 @@ func readByteArray(): array.append(readByte()) return array -func writeShortArray(value): - if (value == null): +func writeShortArray(array): + if (array == null): writeInt(0) else: - writeInt(value.size()); - for element in value: + writeInt(array.size()); + for element in array: writeShort(element) func readShortArray(): @@ -306,12 +306,12 @@ func readShortArray(): array.append(readShort()) return array -func writeIntArray(value): - if (value == null): +func writeIntArray(array): + if (array == null): writeInt(0) else: - writeInt(value.size()); - for element in value: + writeInt(array.size()); + for element in array: writeInt(element) func readIntArray(): @@ -322,12 +322,12 @@ func readIntArray(): array.append(readInt()) return array -func writeLongArray(value): - if (value == null): +func writeLongArray(array): + if (array == null): writeInt(0) else: - writeInt(value.size()); - for element in value: + writeInt(array.size()); + for element in array: writeLong(element) func readLongArray(): @@ -338,12 +338,12 @@ func readLongArray(): array.append(readLong()) return array -func writeFloatArray(value): - if (value == null): +func writeFloatArray(array): + if (array == null): writeInt(0) else: - writeInt(value.size()); - for element in value: + writeInt(array.size()); + for element in array: writeFloat(element) func readFloatArray(): @@ -354,12 +354,12 @@ func readFloatArray(): array.append(readFloat()) return array -func writeDoubleArray(value): - if (value == null): +func writeDoubleArray(array): + if (array == null): writeInt(0) else: - writeInt(value.size()); - for element in value: + writeInt(array.size()); + for element in array: writeDouble(element) func readDoubleArray(): @@ -370,12 +370,12 @@ func readDoubleArray(): array.append(readDouble()) return array -func writeCharArray(value): - if (value == null): +func writeCharArray(array): + if (array == null): writeInt(0) else: - writeInt(value.size()); - for element in value: + writeInt(array.size()); + for element in array: writeChar(element) func readCharArray(): @@ -386,12 +386,12 @@ func readCharArray(): array.append(readChar()) return array -func writeStringArray(value): - if (value == null): +func writeStringArray(array): + if (array == null): writeInt(0) else: - writeInt(value.size()); - for element in value: + writeInt(array.size()); + for element in array: writeString(element) func readStringArray(): @@ -403,13 +403,13 @@ func readStringArray(): return array -func writePacketArray(value, protocolId): - if (value == null): +func writePacketArray(array, protocolId): + if (array == null): writeInt(0) else: var protocolRegistration = ProtocolManager.getProtocol(protocolId) - writeInt(value.size()); - for element in value: + writeInt(array.size()); + for element in array: protocolRegistration.write(self, element) func readPacketArray(protocolId): @@ -421,14 +421,14 @@ func readPacketArray(protocolId): array.append(protocolRegistration.read(self)) return array -func writeIntIntMap(value): - if (value == null): +func writeIntIntMap(map): + if (map == null): writeInt(0) else: - writeInt(value.size()) - for key in value: + writeInt(map.size()) + for key in map: writeInt(key) - writeInt(value[key]) + writeInt(map[key]) func readIntIntMap(): var map = {} @@ -440,14 +440,14 @@ func readIntIntMap(): map[key] = value return map -func writeIntLongMap(value): - if (value == null): +func writeIntLongMap(map): + if (map == null): writeInt(0) else: - writeInt(value.size()) - for key in value: - writeInt(key) - writeLong(value[key]) + writeInt(map.size()) + for key in map: + writeInt(map) + writeLong(map[key]) func readIntLongMap(): var map = {} @@ -459,14 +459,14 @@ func readIntLongMap(): map[key] = value return map -func writeIntStringMap(value): - if (value == null): +func writeIntStringMap(map): + if (map == null): writeInt(0) else: - writeInt(value.size()) - for key in value: + writeInt(map.size()) + for key in map: writeInt(key) - writeString(value[key]) + writeString(map[key]) func readIntStringMap(): var map = {} @@ -479,15 +479,15 @@ func readIntStringMap(): return map -func writeIntPacketMap(value, protocolId): - if (value == null): +func writeIntPacketMap(map, protocolId): + if (map == null): writeInt(0) else: var protocolRegistration = ProtocolManager.getProtocol(protocolId) - writeInt(value.size()) - for key in value: + writeInt(map.size()) + for key in map: writeInt(key) - protocolRegistration.write(self, value[key]) + protocolRegistration.write(self, map[key]) func readIntPacketMap(protocolId): var map = {} @@ -501,14 +501,14 @@ func readIntPacketMap(protocolId): return map -func writeLongIntMap(value): - if (value == null): +func writeLongIntMap(map): + if (map == null): writeInt(0) else: - writeInt(value.size()) - for key in value: + writeInt(map.size()) + for key in map: writeLong(key) - writeInt(value[key]) + writeInt(map[key]) func readLongIntMap(): var map = {} @@ -520,14 +520,14 @@ func readLongIntMap(): map[key] = value return map -func writeLongLongMap(value): - if (value == null): +func writeLongLongMap(map): + if (map == null): writeInt(0) else: - writeInt(value.size()) - for key in value: + writeInt(map.size()) + for key in map: writeLong(key) - writeLong(value[key]) + writeLong(map[key]) func readLongLongMap(): var map = {} @@ -539,14 +539,14 @@ func readLongLongMap(): map[key] = value return map -func writeLongStringMap(value): - if (value == null): +func writeLongStringMap(map): + if (map == null): writeInt(0) else: - writeInt(value.size()) - for key in value: + writeInt(map.size()) + for key in map: writeLong(key) - writeString(value[key]) + writeString(map[key]) func readLongStringMap(): var map = {} @@ -559,15 +559,15 @@ func readLongStringMap(): return map -func writeLongPacketMap(value, protocolId): - if (value == null): +func writeLongPacketMap(map, protocolId): + if (map == null): writeInt(0) else: var protocolRegistration = ProtocolManager.getProtocol(protocolId) - writeInt(value.size()) - for key in value: + writeInt(map.size()) + for key in map: writeLong(key) - protocolRegistration.write(self, value[key]) + protocolRegistration.write(self, map[key]) func readLongPacketMap(protocolId): var map = {} @@ -581,14 +581,14 @@ func readLongPacketMap(protocolId): return map -func writeStringIntMap(value): - if (value == null): +func writeStringIntMap(map): + if (map == null): writeInt(0) else: - writeInt(value.size()) - for key in value: + writeInt(map.size()) + for key in map: writeString(key) - writeInt(value[key]) + writeInt(map[key]) func readStringIntMap(): var map = {} @@ -600,14 +600,14 @@ func readStringIntMap(): map[key] = value return map -func writeStringLongMap(value): - if (value == null): +func writeStringLongMap(map): + if (map == null): writeInt(0) else: - writeInt(value.size()) - for key in value: + writeInt(map.size()) + for key in map: writeString(key) - writeLong(value[key]) + writeLong(map[key]) func readStringLongMap(): var map = {} @@ -619,14 +619,14 @@ func readStringLongMap(): map[key] = value return map -func writeStringStringMap(value): - if (value == null): +func writeStringStringMap(map): + if (map == null): writeInt(0) else: - writeInt(value.size()) - for key in value: + writeInt(map.size()) + for key in map: writeString(key) - writeString(value[key]) + writeString(map[key]) func readStringStringMap(): var map = {} @@ -639,15 +639,15 @@ func readStringStringMap(): return map -func writeStringPacketMap(value, protocolId): - if (value == null): +func writeStringPacketMap(map, protocolId): + if (map == null): writeInt(0) else: var protocolRegistration = ProtocolManager.getProtocol(protocolId) - writeInt(value.size()) - for key in value: + writeInt(map.size()) + for key in map: writeString(key) - protocolRegistration.write(self, value[key]) + protocolRegistration.write(self, map[key]) func readStringPacketMap(protocolId): var map = {} diff --git a/gdProtocol/packet/ComplexObject.gd b/gdProtocol/packet/ComplexObject.gd index c9b7318..ca35096 100644 --- a/gdProtocol/packet/ComplexObject.gd +++ b/gdProtocol/packet/ComplexObject.gd @@ -3,6 +3,7 @@ # # @author jaysunxiao # @version 3.0 + # byte类型,最简单的整形 var a # byte # byte的包装类型 @@ -206,7 +207,7 @@ static func write(buffer, packet): static func read(buffer): if (!buffer.readBool()): return null - var packet = buffer.newInstance(100) + var packet = buffer.newInstance(PROTOCOL_ID) var result19 = buffer.readByte() packet.a = result19 var result20 = buffer.readByte() diff --git a/gdProtocol/packet/NormalObject.gd b/gdProtocol/packet/NormalObject.gd index 7f7b424..a9f4126 100644 --- a/gdProtocol/packet/NormalObject.gd +++ b/gdProtocol/packet/NormalObject.gd @@ -1,5 +1,6 @@ # @author jaysunxiao # @version 3.0 + var a # byte var aaa # byte[] var b # short @@ -47,7 +48,7 @@ static func write(buffer, packet): static func read(buffer): if (!buffer.readBool()): return null - var packet = buffer.newInstance(101) + var packet = buffer.newInstance(PROTOCOL_ID) var result0 = buffer.readByte() packet.a = result0 var array1 = buffer.readByteArray() diff --git a/gdProtocol/packet/ObjectA.gd b/gdProtocol/packet/ObjectA.gd index c2e7fd0..c70ca38 100644 --- a/gdProtocol/packet/ObjectA.gd +++ b/gdProtocol/packet/ObjectA.gd @@ -1,5 +1,6 @@ # @author jaysunxiao # @version 3.0 + var a # int var m # java.util.Map var objectB # com.zfoo.protocol.packet.ObjectB @@ -17,7 +18,7 @@ static func write(buffer, packet): static func read(buffer): if (!buffer.readBool()): return null - var packet = buffer.newInstance(102) + var packet = buffer.newInstance(PROTOCOL_ID) var result0 = buffer.readInt() packet.a = result0 var map1 = buffer.readIntStringMap() diff --git a/gdProtocol/packet/ObjectB.gd b/gdProtocol/packet/ObjectB.gd index 73598a4..136edc0 100644 --- a/gdProtocol/packet/ObjectB.gd +++ b/gdProtocol/packet/ObjectB.gd @@ -1,5 +1,6 @@ # @author jaysunxiao # @version 3.0 + var flag # boolean const PROTOCOL_ID = 103 @@ -13,7 +14,7 @@ static func write(buffer, packet): static func read(buffer): if (!buffer.readBool()): return null - var packet = buffer.newInstance(103) + var packet = buffer.newInstance(PROTOCOL_ID) var result0 = buffer.readBool() packet.flag = result0 return packet diff --git a/gdProtocol/packet/SimpleObject.gd b/gdProtocol/packet/SimpleObject.gd index 255afec..6ca8f5e 100644 --- a/gdProtocol/packet/SimpleObject.gd +++ b/gdProtocol/packet/SimpleObject.gd @@ -1,5 +1,6 @@ # @author jaysunxiao # @version 3.0 + var c # int var g # boolean @@ -15,7 +16,7 @@ static func write(buffer, packet): static func read(buffer): if (!buffer.readBool()): return null - var packet = buffer.newInstance(104) + var packet = buffer.newInstance(PROTOCOL_ID) var result0 = buffer.readInt() packet.c = result0 var result1 = buffer.readBool() diff --git a/gdTest/GdProtocolTest.gd b/gdTest/GdProtocolTest.gd index 789b634..44bcaf8 100644 --- a/gdTest/GdProtocolTest.gd +++ b/gdTest/GdProtocolTest.gd @@ -92,6 +92,7 @@ func test(): var newByteBuffer = ByteBuffer.new() ProtocolManager.write(newByteBuffer, packet); + print(newByteBuffer.getWriteOffset()) var newPacket = ProtocolManager.read(newByteBuffer); print(newPacket)