فهرست منبع

More fixes for newly added tutorials

Michael Alexsander Silva Dias 6 سال پیش
والد
کامیت
f426de1612
3فایلهای تغییر یافته به همراه76 افزوده شده و 84 حذف شده
  1. 63 69
      tutorials/content/procedural_geometry.rst
  2. 3 3
      tutorials/optimization/using_servers.rst
  3. 10 12
      tutorials/threads/using_multiple_threads.rst

+ 63 - 69
tutorials/content/procedural_geometry.rst

@@ -1,7 +1,7 @@
 .. _doc_procedural_geometry:
 
 Procedural geometry generation
-===============================
+==============================
 
 Users often ask how to generate geometry from easily code. This is not very complicated, but it's not obvious.
 Godot provides a few classes entirely dedicated to make it this easy. Still, the best tool for the job depends
@@ -10,7 +10,7 @@ entirely on the use case.
 SurfaceTool
 -----------
 
-This is the most common helper. :ref:`SurfaceTool<class_SurfaceTool>` is a class you can instantiate to generate :ref:`Meshes<class_Mesh>`, specifically *Mesh Surfaces*. 
+This is the most common helper. :ref:`SurfaceTool<class_SurfaceTool>` is a class you can instantiate to generate :ref:`Meshes<class_Mesh>`, specifically *Mesh Surfaces*.
 
 It has a similar API to OpenGL 1.x, and it's meant for static content. This means, the mesh is generated once and then used.
 
@@ -20,34 +20,33 @@ Here is a simple example of how to use it to add a single triangle.
  .. code-tab:: gdscript GDScript
 
     var st = SurfaceTool.new()
-    
+
     st.begin(Mesh.PRIMITIVE_TRIANGLE)
 
-    # Prepares attributes for add_vertex
-    st.add_normal( Vector3(0,0,1) )
-    st.add_uv( Vector2(0,0) )
-    # Call last for each vertex, adds the above attributes
-    st.add_vertex( Vector3(-1,-1,0) ) 
+    # Prepare attributes for add_vertex.
+    st.add_normal(Vector3(0, 0, 1))
+    st.add_uv(Vector2(0, 0))
+    # Call last for each vertex, adds the above attributes.
+    st.add_vertex(Vector3(-1, -1, 0))
 
-    st.add_normal( Vector3(0,0,1) )
-    st.add_uv( Vector2(0,1) )
-    st.add_vertex( Vector3(-1,1,0) ) 
+    st.add_normal(Vector3(0, 0, 1))
+    st.add_uv(Vector2(0, 1))
+    st.add_vertex(Vector3(-1, 1, 0))
 
-    st.add_normal( Vector3(0,0,1) )
-    st.add_uv( Vector2(1,1) )
-    st.add_vertex( Vector3(1,1,0) ) 
+    st.add_normal(Vector3(0, 0, 1))
+    st.add_uv(Vector2(1, 1))
+    st.add_vertex(Vector3(1, 1, 0))
 
-    # Create indices, indices are optional
+    # Create indices, indices are optional.
     st.index()
 
-    # Commit to a mesh
-
+    # Commit to a mesh.
     var mesh = st.commit()
 
 Just explore the APIs and the possibilities.
 
 ImmediateGeometry
------------------    
+-----------------
 
 Unlike *SurfaceTool*, :ref:`ImmediateGeometry<class_ImmediateGeometry>` is an actual node. It's similar in the "OpenGL 1.x" style API,
 but it's actually designed to create content on the fly and modify it every frame efficiently.
@@ -61,31 +60,28 @@ It's used similar to *SurfaceTool*.
 
     extends ImmediateGeometry
 
-
     void _process(delta):
-
-        # Clean up before drawing
-
+        # Clean up before drawing.
         clear()
 
-        # Begin draw
+        # Begin draw.
         begin(Mesh.PRIMITIVE_TRIANGLE)
-    
-        # Prepares attributes for add_vertex
-        set_normal( Vector3(0,0,1) )
-        set_uv( Vector2(0,0) )
-        # Call last for each vertex, adds the above attributes
-        add_vertex( Vector3(-1,-1,0) ) 
-    
-        set_normal( Vector3(0,0,1) )
-        set_uv( Vector2(0,1) )
-        add_vertex( Vector3(-1,1,0) ) 
-    
-        set_normal( Vector3(0,0,1) )
-        set_uv( Vector2(1,1) )
-        add_vertex( Vector3(1,1,0) ) 
-    
-        # End drawing
+
+        # Prepare attributes for add_vertex.
+        set_normal( Vector3(0, 0, 1))
+        set_uv(Vector2(0, 0))
+        # Call last for each vertex, adds the above attributes.
+        add_vertex(Vector3(-1, -1, 0))
+
+        set_normal(Vector3(0, 0, 1))
+        set_uv(Vector2(0, 1))
+        add_vertex(Vector3(-1, 1, 0))
+
+        set_normal(Vector3(0, 0, 1))
+        set_uv(Vector2(1, 1))
+        add_vertex(Vector3(1, 1, 0))
+
+        # End drawing.
         end()
 
 Arrays
@@ -101,50 +97,48 @@ Similar code as before, but draw a square using indices:
  .. code-tab:: gdscript GDScript
 
     var arrays = []
-    arrays.resize(Mesh::ARRAY_MAX)
+    arrays.resize(Mesh.ARRAY_MAX)
 
     var normal_array = []
     var uv_array = []
     var vertex_array = []
     var index_array = []
 
-    normal_array.resize(4)    
-    uv_array.resize(4)    
-    vertex_array.resize(4)    
-    index_array.resize(6)    
+    normal_array.resize(4)
+    uv_array.resize(4)
+    vertex_array.resize(4)
+    index_array.resize(6)
 
-    normal_array[0]=Vector3(0,0,1)
-    uv_array[0]=Vector2(0,0)
-    vertex_array[0]=Vector3(-1,-1)
+    normal_array[0] = Vector3(0, 0, 1)
+    uv_array[0] = Vector2(0, 0)
+    vertex_array[0] = Vector3(-1, -1)
 
-    normal_array[1]=Vector3(0,0,1)
-    uv_array[1]=Vector2(0,1)
-    vertex_array[1]=Vector3(-1, 1)
+    normal_array[1] = Vector3(0, 0, 1)
+    uv_array[1] = Vector2(0,1)
+    vertex_array[1] = Vector3(-1, 1)
 
-    normal_array[2]=Vector3(0,0,1)
-    uv_array[2]=Vector2(1,1)
-    vertex_array[2]=Vector3( 1, 1)
+    normal_array[2] = Vector3(0, 0, 1)
+    uv_array[2] = Vector2(1, 1)
+    vertex_array[2] = Vector3(1, 1)
 
-    normal_array[3]=Vector3(0,0,1)
-    uv_array[3]=Vector2(1,0)
-    vertex_array[3]=Vector3( 1, -1)
+    normal_array[3] = Vector3(0, 0, 1)
+    uv_array[3] = Vector2(1, 0)
+    vertex_array[3] = Vector3(1, -1)
 
-    # indices are optional in Godot, but if they exist they are used
-    index_array[0]=0
-    index_array[1]=1
-    index_array[2]=2
+    # Indices are optional in Godot, but if they exist they are used.
+    index_array[0] = 0
+    index_array[1] = 1
+    index_array[2] = 2
 
-    index_array[3]=2
-    index_array[4]=3
-    index_array[5]=0
+    index_array[3] = 2
+    index_array[4] = 3
+    index_array[5] = 0
 
-    arrays[Mesh.ARRAY_VERTEX]=vertex_array
-    arrays[Mesh.ARRAY_NORMAL]=normal_array
-    arrays[Mesh.ARRAY_TEX_UV]=uv_array
-    arrays[Mesh.ARRAY_INDEX]=index_array
+    arrays[Mesh.ARRAY_VERTEX] = vertex_array
+    arrays[Mesh.ARRAY_NORMAL] = normal_array
+    arrays[Mesh.ARRAY_TEX_UV] = uv_array
+    arrays[Mesh.ARRAY_INDEX] = index_array
 
     var mesh = ArrayMesh.new()
 
     mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES,arrays)
-
-

+ 3 - 3
tutorials/optimization/using_servers.rst

@@ -143,9 +143,9 @@ The 3D APIs are different than the 2D ones, so the instantiation API must be use
         VisualServer.instance_set_transform(instance, xform)
 
 Creating a 2D RigidBody and moving a sprite with it
-----------------------------------------------------
+---------------------------------------------------
 
-This creates a :ref:`RigidBody2D <class_RigidBody2D>` using the :ref:`Physics2DServer <Physics2DServer>` API,
+This creates a :ref:`RigidBody2D <class_RigidBody2D>` using the :ref:`Physics2DServer <class_Physics2DServer>` API,
 and moves a :ref:`CanvasItem <class_CanvasItem>` when the body moves.
 
 .. tabs::
@@ -174,7 +174,7 @@ and moves a :ref:`CanvasItem <class_CanvasItem>` when the body moves.
         Physics2DServer.body_set_force_integration_callback(body, self, "_body_moved", 0)
 
 The 3D version should be very similar, as 2D and 3D physics servers are identical (using
-:ref:`RigidBody <RigidBody>` and :ref:`PhysicsServer <PhysicsServer>` respectively).
+:ref:`RigidBody <class_RigidBody>` and :ref:`PhysicsServer <class_PhysicsServer>` respectively).
 
 Getting data from the servers
 -----------------------------

+ 10 - 12
tutorials/threads/using_multiple_threads.rst

@@ -20,17 +20,15 @@ Creating a thread is very simple, just use the following code:
 .. tabs::
  .. code-tab:: gdscript GDScript
 
-    var thread = null
+    var thread
 
     # The thread will start here.
     func _ready():
-
         thread = Thread.new()
         thread.start(self, "_thread_function", "Wafflecopter")
 
     # Run here and exit.
     func _thread_function(userdata):
-
         print("I'm a thread! Userdata is: ", userdata)
 
     # Thread must be disposed (or "joined"), for portability.
@@ -60,8 +58,8 @@ Here is an example of using a Mutex:
  .. code-tab:: gdscript GDScript
 
     var counter = 0
-    var mutex = null
-    var thread = null
+    var mutex
+    var thread
 
     # The thread will start here.
     func _ready():
@@ -69,7 +67,7 @@ Here is an example of using a Mutex:
         thread = Thread.new()
         thread.start(self, "_thread_function")
         
-        # Increase value, protect it with a Mutex.
+        # Increase value, protect it with Mutex.
         mutex.lock()
         counter += 1
         mutex.unlock()
@@ -99,9 +97,9 @@ The main thread, instead, uses :ref:`Semaphore.post()<class_Semaphore_method_pos
  .. code-tab:: gdscript GDScript
 
     var counter = 0
-    var mutex = null
-    var semaphore = null
-    var thread = null
+    var mutex
+    var semaphore
+    var thread
     var exit_thread = false
 
     # The thread will start here.
@@ -114,14 +112,14 @@ The main thread, instead, uses :ref:`Semaphore.post()<class_Semaphore_method_pos
         thread.start(self, "_thread_function")
 
     func _thread_function(userdata):
-        while (true):
+        while true:
             semaphore.wait() # Wait until posted.
 
             mutex.lock()
             var should_exit = exit_thread # Protect with Mutex.
             mutex.unlock()
 
-            if (should_exit):
+            if should_exit:
                 break
 
             mutex.lock()
@@ -133,7 +131,7 @@ The main thread, instead, uses :ref:`Semaphore.post()<class_Semaphore_method_pos
 
     func get_counter():
         mutex.lock()
-        # copy counter, protect with mutex.
+        # Copy counter, protect with Mutex.
         var counter_value = counter
         mutex.unlock()
         return counter_value