Browse Source

Formatting fixes to new tutorials

Rémi Verschelde 6 years ago
parent
commit
e40f3da2d5

+ 16 - 19
tutorials/math/beziers_and_curves.rst

@@ -1,11 +1,8 @@
 .. _doc_beziers_and_curves:
 
-Beziers, Curves and Paths
+Beziers, curves and paths
 =========================
 
-Introduction
-~~~~~~~~~~~~
-
 Bezier curves are a mathematical approximation to natural shapes. Their goal is to represent a curve with
 as little information as possible, and with a high level of flexibility.
 
@@ -34,7 +31,7 @@ To draw the curve between them, just interpolate the two segments that form betw
         var q0 = p0.linear_interpolate(p1, t)
         var q1 = p1.linear_interpolate(p2, t)
 
-This will reduce the points from 3 to 2. Do the same process with *q0* and *q1* to obtain a single point *r*.
+This will reduce the points from 3 to 2. Do the same process with ``q0`` and ``q1`` to obtain a single point ``r``.
 
 .. tabs::
  .. code-tab:: gdscript GDScript
@@ -42,7 +39,7 @@ This will reduce the points from 3 to 2. Do the same process with *q0* and *q1*
         var r = q0.linear_interpolate(q1, t)
         return r
 
-Finally, this point fill follow the curve when t goes from 0 to 1. This type of curve is called *Quadratic Bezier*.
+Finally, this point fill follow the curve when ``t`` goes from 0 to 1. This type of curve is called *Quadratic Bezier*.
 
 .. image:: img/bezier_quadratic_points2.gif
 
@@ -55,12 +52,12 @@ Let's add one more point and make it four.
 
 .. image:: img/bezier_cubic_points.png
 
-Then let's modify the function to take four points as an input, *p0, p1, p2* and *p3*:
+Then let's modify the function to take four points as an input, ``p0``, ``p1``, ``p2`` and ``p3``:
 
 .. tabs::
  .. code-tab:: gdscript GDScript
 
-    func _cubic_bezier(p0 : Vector2,p1 : Vector2,p2 : Vector2,p3 : Vector2 ,t : float):
+    func _cubic_bezier(p0: Vector2, p1: Vector2, p2: Vector2, p3: Vector2, t: float):
 
 Interpolate then into three points:
 
@@ -93,17 +90,17 @@ The result will be a smooth curve interpolating between all four points:
 
 *(Image credit: Wikipedia)*
 
-.. note:: For 3D, it's exactly the same, just change Vector2 into Vector3.
+.. note:: For 3D, it's exactly the same, just change ``Vector2`` to ``Vector3``.
 
 Control point form
 ------------------
 
-Now, let's take these points and change the way we understand them. Instead of having p0, p1, p2 and p3, we will store them as:
+Now, let's take these points and change the way we understand them. Instead of having ``p0``, ``p1``, ``p2`` and ``p3``, we will store them as:
 
-* **POINT0** = **P0**: Is the first point, the source
-* **CONTROL0** = **P1** - **P0**: Is a relative vector for the first control point
-* **CONTROL1** = **P3** - **P2**: Is a relative vector for the second control point
-* **POINT1** = **P3**: Is the second point, the destination
+* ``POINT0 = P0``: Is the first point, the source
+* ``CONTROL0 = P1 - P0``: Is a relative vector for the first control point
+* ``CONTROL1 = P3 - P2``: Is a relative vector for the second control point
+* ``POINT1 = P3``: Is the second point, the destination
 
 This way, we have two points and two control points (which are relative vectors to the respective points). If visualized, they will look a lot more familiar:
 
@@ -125,7 +122,7 @@ Using them, however, may not be completely obvious, so following is a descriptio
 Evaluating
 ----------
 
-Just evaluating them may be an option, but in most cases it's not very useful. The big drawback with Bezier curves is that if you traverse them at constant speed, from *t=0* to *t=1*, the actual interpolation will *not* move at constant speed. The speed is also an interpolation between the distances between points p0, p1, p2 and p3 and there is not a mathematically simple way to traverse the curve at constant speed.
+Just evaluating them may be an option, but in most cases it's not very useful. The big drawback with Bezier curves is that if you traverse them at constant speed, from ``t = 0`` to ``t = 1``, the actual interpolation will *not* move at constant speed. The speed is also an interpolation between the distances between points ``p0``, ``p1``, ``p2`` and ``p3`` and there is not a mathematically simple way to traverse the curve at constant speed.
 
 Let's do a simple example with the following pseudocode:
 
@@ -141,23 +138,23 @@ Let's do a simple example with the following pseudocode:
 
 .. image:: img/bezier_interpolation_speed.gif
 
-As you can see, the speed (in pixels per second) of the circle varies, even though *t* is increased at constant speed. This makes beziers difficult to use for anything practical out of the box.
+As you can see, the speed (in pixels per second) of the circle varies, even though ``t`` is increased at constant speed. This makes beziers difficult to use for anything practical out of the box.
 
 Drawing
 -------
 
 Drawing beziers (or objects based on the curve) is a very common use case, but it's also not easy. For pretty much any case, Bezier curves need to be converted to some sort of segments. This is normally difficult, however, without creating a very high amount of them.
 
-The reason is that some sections of a curve (specifically, corners) may requiere considerable amounts of points, while other sections may not:
+The reason is that some sections of a curve (specifically, corners) may require considerable amounts of points, while other sections may not:
 
 .. image:: img/bezier_point_amount.png
 
-Additionally, if both control points were 0,0 (remember they are relative vectors), the Bezier curve would just be a straight line (so drawing a high amount of points would be wasteful).
+Additionally, if both control points were ``0, 0`` (remember they are relative vectors), the Bezier curve would just be a straight line (so drawing a high amount of points would be wasteful).
 
 Before drawing Bezier curves, *tesselation* is required. This is often done with a recursive or divide and conquer function that splits the curve until the curvature amount becomes less than a certain threshold.
 
 The *Curve* classes provide this via the
-:ref:`Curve2D.tessellate()<class_Curve2D_method_tessellate>` function (which receives optional *stages* of recursion and angle *tolerance* arguments). This way, drawing something based on a curve is easier.
+:ref:`Curve2D.tessellate() <class_Curve2D_method_tessellate>` function (which receives optional ``stages`` of recursion and angle ``tolerance`` arguments). This way, drawing something based on a curve is easier.
 
 Traversal
 ---------

+ 11 - 14
tutorials/math/interpolation.rst

@@ -3,21 +3,18 @@
 Interpolation
 =============
 
-Introduction
-~~~~~~~~~~~~
-
 Interpolation is a very basic operation in graphics programming. It's good to become familiar with it in order to expand your horizons as a graphics developer.
 
-The basic idea is that you want to transition from A to B. A value *t*, represents the states in-between.
+The basic idea is that you want to transition from A to B. A value ``t``, represents the states in-between.
 
-As an example if *t* is 0, then the state is A. If *t* is 1, then the state is B. Anything in-between is an *interpolation*.
+As an example if ``t`` is 0, then the state is A. If ``t`` is 1, then the state is B. Anything in-between is an *interpolation*.
 
 Between two real (floating point) numbers, a simple interpolation is usually described as:
 
 .. tabs::
  .. code-tab:: gdscript GDScript
 
-    interpolation = A * (t-1) + B * t
+    interpolation = A * (1 - t) + B * t
 
 And often simplified to:
 
@@ -28,17 +25,17 @@ And often simplified to:
 
 which is exactly the same.
 
-The name of this type of interpolation, which transforms a value into another at *constant speed* is *"Linear"*. So, when you hear about *Linear Interpolation*, you know they are referring to this simple formula.
+The name of this type of interpolation, which transforms a value into another at *constant speed* is *"linear"*. So, when you hear about *Linear Interpolation*, you know they are referring to this simple formula.
 
 There are other types of interpolations, which will not be covered here. A recommended read afterwards is the :ref:`Bezier <doc_beziers_and_curves>` page.
 
-Vector Interpolation
+Vector interpolation
 --------------------
 
-Vector types (Vector2 and Vector3) can also be interpolated, they come with handy functions to do it
-:ref:`Vector2.linear_interpolate()<class_Vector2_method_linear_interpolate>` and :ref:`Vector3.linear_interpolate()<class_Vector3_method_linear_interpolate>`.
+Vector types (:ref:`Vector2 <class_Vector2>` and :ref:`Vector3 <class_Vector3>`) can also be interpolated, they come with handy functions to do it
+:ref:`Vector2.linear_interpolate() <class_Vector2_method_linear_interpolate>` and :ref:`Vector3.linear_interpolate() <class_Vector3_method_linear_interpolate>`.
 
-For cubic interpolation, there are also :ref:`Vector2.cubic_interpolate()<class_Vector2_method_linear_interpolate>` and :ref:`Vector3.cubic_interpolate()<class_Vector3_method_linear_interpolate>`, which do a :ref:`Bezier <doc_beziers_and_curves>` style interpolation.
+For cubic interpolation, there are also :ref:`Vector2.cubic_interpolate() <class_Vector2_method_linear_interpolate>` and :ref:`Vector3.cubic_interpolate() <class_Vector3_method_linear_interpolate>`, which do a :ref:`Bezier <doc_beziers_and_curves>` style interpolation.
 
 Here is simple pseudo-code for going from point A to B using interpolation:
 
@@ -58,7 +55,7 @@ Transform interpolation
 -----------------------
 
 It is also possible to interpolate whole transforms (make sure they have either uniform scale or, at least, the same non-uniform scale).
-For this, the function :ref:`Transform.interpolate_with()<class_Transform_method_interpolate_with>` can be used.
+For this, the function :ref:`Transform.interpolate_with() <class_Transform_method_interpolate_with>` can be used.
 
 Here is an example of transforming a monkey from Position1 to Position2:
 
@@ -71,7 +68,7 @@ Using the following pseudocode:
 
     var t = 0.0
 
-    func _process(delta):
+    func _physics_process(delta):
         t += delta
 
         $Monkey.transform = $Position1.transform.interpolate_with($Position2.transform, t)
@@ -81,7 +78,7 @@ And again, it will produce the following motion:
 .. image:: img/interpolation_monkey.gif
 
 
-Smoothing Motion
+Smoothing motion
 ----------------
 
 Interpolation can be used to smooth movement, rotation, etc. Here is an example of a circle following the mouse using smoothed motion:

+ 7 - 7
tutorials/optimization/using_multimesh.rst

@@ -7,7 +7,7 @@ For large amount of instances (in the thousands), that need to be constantly pro
 (and certain amount of control needs to be retained),
 :ref:`using servers directly <doc_using_servers>` is the recommended optimization.
 
-When the amount of objects reach the  hundreds of thousands or millions,
+When the amount of objects reach the hundreds of thousands or millions,
 none of these approaches are efficient anymore. Still, depending on the requirements, there
 is one more optimization possible.
 
@@ -16,7 +16,7 @@ MultiMeshes
 
 A :ref:`MultiMesh<class_MultiMesh>` is a single draw primitive that can draw up to millions
 of objects in one go. It's extremely efficient because it uses the GPU hardware to do this
-(In OpenGL ES 2.0, it's less efficient because there is no hardware support for it, though).
+(in OpenGL ES 2.0, it's less efficient because there is no hardware support for it, though).
 
 The only drawback is that there is no *screen* or *frustum* culling possible for individual instances.
 This means, that millions of objects will be *always* or *never* drawn, depending on the visibility
@@ -27,8 +27,8 @@ If the objects are simple enough (just a couple of vertices), this is generally
 as most modern GPUs are optimized for this use case. A workaround is to create several MultiMeshes
 for different areas of the world.
 
-It is also possible to execute some logic inside the vertex shader (using the INSTANCE_ID or
-INSTANCE_CUSTOM built-in constants). For an example of animating thousands of objects in a MultiMesh,
+It is also possible to execute some logic inside the vertex shader (using the ``INSTANCE_ID`` or
+``INSTANCE_CUSTOM`` built-in constants). For an example of animating thousands of objects in a MultiMesh,
 see the :ref:`Animating thousands of fish <doc_animating_thousands_of_fish>` tutorial. Information
 to the shader can be provided via textures (there are floating point :ref:`Image<class_Image>` formats
 which are ideal for this).
@@ -40,11 +40,11 @@ function). This way, the array can be created with multiple threads, then set in
 high cache efficiency.
 
 Finally, it's not required to have all MultiMesh instances visible. The amount of visible ones can be
-controlled with the *MultiMesh.visible_instance_count* property. The typical workflow is to allocate
-the maximum amount of instances that will be used,
+controlled with the :ref:`MultiMesh.visible_instance_count <class_MultiMesh_property_visible_instance_count>`
+property. The typical workflow is to allocate the maximum amount of instances that will be used,
 then change the amount visible depending on how many are currently needed.
 
-Multimesh Example
+Multimesh example
 -----------------
 
 Here is an example of using a MultiMesh from code (using GDScript). Other languages may be more

+ 5 - 4
tutorials/optimization/using_servers.rst

@@ -30,7 +30,8 @@ One of the most interesting design decisions for Godot, is the fact that the who
 *optional*. While it is not currently possible to compile it out, it can be completely bypassed.
 
 At the core, Godot uses the concept of Servers. They are very low level APIs to control
-rendering, physics, sound, etc. The scene system is built on top of them and uses them directly. The most common servers are:
+rendering, physics, sound, etc. The scene system is built on top of them and uses them directly.
+The most common servers are:
 
 * :ref:`VisualServer <class_VisualServer>`: handles everything related to graphics.
 * :ref:`PhysicsServer <class_PhysicsServer>`: handles everything related to 3D physics.
@@ -68,7 +69,7 @@ For nodes, there are many functions available:
   allows creating 3D objects directly with the server API and using them.
 * For 2D, the :ref:`World2D <class_World2D>` resource (obtainable in the :ref:`Viewport <class_Viewport>`
   and :ref:`CanvasItem <class_CanvasItem>` nodes)
-  nodes) contains functions to get the *VisualServer Canvas*, and the *Physics2DServer Space*. This
+  contains functions to get the *VisualServer Canvas*, and the *Physics2DServer Space*. This
   allows creating 2D objects directly with the server API and using them.
 * The :ref:`VisualInstance<class_VisualInstance>` class, allows getting the scenario *instance* and
   *instance base* via the :ref:`VisualInstance.get_instance() <class_VisualInstance_method_get_instance>`
@@ -136,10 +137,10 @@ The 3D APIs are different than the 2D ones, so the instantiation API must be use
         # Add a mesh to it.
         # Remember, keep the reference.
         var mesh = load("res://mymesh.obj")
-        VisualServer.instance_set_base(instance,mesh)
+        VisualServer.instance_set_base(instance, mesh)
         # Move the mesh around.
         var xform = Transform(Basis(), Vector3(20, 100, 0))
-        VisualServer.instance_set_transform(instance,xform)
+        VisualServer.instance_set_transform(instance, xform)
 
 Creating a 2D RigidBody and moving a sprite with it
 ----------------------------------------------------

+ 0 - 4
tutorials/threads/thread_safe_apis.rst

@@ -49,8 +49,6 @@ you are doing and you are sure that a single resource is not being used or
 set in multiple ones. Otherwise, you are safer just using the servers API
 (which is fully thread-safe) directly and not touching scene or resources.
 
-
-
 GDScript arrays, dictionaries
 -----------------------------
 
@@ -60,5 +58,3 @@ Resources
 ---------
 
 Modifying a unique resource from multiple threads is not supported, but loading them on threads or handling a reference is perfectly supported. Scenes, textures, meshes, etc. Can be loaded and manipulated on threads, then added to the active scene in the main thread.
-
-

+ 48 - 46
tutorials/threads/using_multiple_threads.rst

@@ -8,12 +8,12 @@ Threads
 
 Threads allow simultaneous execution of code. It allows off-loading work from the main thread.
 
-Godot supports threads and provides many handy functions to use them. 
+Godot supports threads and provides many handy functions to use them.
 
 .. note:: If using other languages (C#, C++), it may be easier to use the threading classes they support.
 
 Creating a Thread
-------------------
+-----------------
 
 Creating a thread is very simple, just use the following code:
 
@@ -22,33 +22,39 @@ Creating a thread is very simple, just use the following code:
 
     var thread = null
 
-    # The thread will start here
+    # The thread will start here.
     func _ready():
 
         thread = Thread.new()
-        thread.start(self,"_thread_function","Wafflecopter")
+        thread.start(self, "_thread_function", "Wafflecopter")
 
-    # Run here and exit
+    # Run here and exit.
     func _thread_function(userdata):
 
-        print("I'm a thread! Userdata is: ",userdata)
+        print("I'm a thread! Userdata is: ", userdata)
 
-    # Thread must be disposed (or "Joined"), for portability
+    # Thread must be disposed (or "joined"), for portability.
     func _exit_tree():
         thread.wait_to_finish()
 
-
 Your function will, then, run in a separate thread until it returns.
-Even if the function has returned already, the thread must collect it, so call :ref:`Thread.wait_to_finish()<class_Thread_method_wait_to_finish>`, which will wait until the thread is done (if not done yet), then properly dispose of it.
+Even if the function has returned already, the thread must collect it, so call
+:ref:`Thread.wait_to_finish()<class_Thread_method_wait_to_finish>`, which will wait until the
+thread is done (if not done yet), then properly dispose of it.
 
 Mutexes
 -------
 
-Accessing objects or data from multiple threads is not always supported (if you do it, it will cause unexpected behaviors or crashes). Read the :ref:`Thread Safe APIs<doc_thread_safe_apis>` to understand which engine APIs support multiple thread access.
+Accessing objects or data from multiple threads is not always supported (if you do it, it will
+cause unexpected behaviors or crashes). Read the :ref:`Thread safe APIs<doc_thread_safe_apis>`
+to understand which engine APIs support multiple thread access.
 
-When processing your own data or calling your own functions, as a rule, try to avoid accessing the same data directly from different threads. You may run into synchronization problems, as the data is not allways updated between CPU cores when modified. Always use a :ref:`Mutex<class_Mutex>` when accessing a piece of data from different threads.
+When processing your own data or calling your own functions, as a rule, try to avoid accessing
+the same data directly from different threads. You may run into synchronization problems, as the
+data is not always updated between CPU cores when modified.
+Always use a :ref:`Mutex<class_Mutex>` when accessing a piece of data from different threads.
 
-Here is an example of using a mutex:
+Here is an example of using a Mutex:
 
 .. tabs::
  .. code-tab:: gdscript GDScript
@@ -57,33 +63,35 @@ Here is an example of using a mutex:
     var mutex = null
     var thread = null
 
-    # The thread will start here
+    # The thread will start here.
     func _ready():
         mutex = Mutex.new()
         thread = Thread.new()
-        thread.start(self,"_thread_function")
+        thread.start(self, "_thread_function")
         
-        #increase value, protect it with mutex
+        # Increase value, protect it with a Mutex.
         mutex.lock()
-        counter+=1
+        counter += 1
         mutex.unlock()
 
-    # Increment the value from the thread, too
+    # Increment the value from the thread, too.
     func _thread_function(userdata):
         mutex.lock()
-        counter+=1
+        counter += 1
         mutex.unlock()
 
-    # Thread must be disposed (or "Joined"), for portability
+    # Thread must be disposed (or "joined"), for portability.
     func _exit_tree():
         thread.wait_to_finish()
-        print("Counter is: ",counter) # Should be 2
+        print("Counter is: ", counter) # Should be 2.
 
 Semaphores
------------
+----------
 
-Sometimes you want your thread to work *"On Demand"*. In other words, tell it when to work and let it suspend when it isn't doing anything.
-For this *:ref:`Semaphores<class_Semaphore>`* are used. The function :ref:`Semaphore.wait()<class_Semaphore_method_wait>` is used in the thread to suspend it until some data arrives.
+Sometimes you want your thread to work *"on demand"*. In other words, tell it when to work
+and let it suspend when it isn't doing anything.
+For this :ref:`Semaphores<class_Semaphore>` are used. The function :ref:`Semaphore.wait()<class_Semaphore_method_wait>`
+is used in the thread to suspend it until some data arrives.
 
 The main thread, instead, uses :ref:`Semaphore.post()<class_Semaphore_method_post>` to signal that data is ready to be processed:
 
@@ -96,58 +104,52 @@ The main thread, instead, uses :ref:`Semaphore.post()<class_Semaphore_method_pos
     var thread = null
     var exit_thread = false
 
-    # The thread will start here
+    # The thread will start here.
     func _ready():
         mutex = Mutex.new()
         semaphore = Semaphore.new()
-        exit_thread=false
+        exit_thread = false
 
         thread = Thread.new()
-        thread.start(self,"_thread_function")
-        
+        thread.start(self, "_thread_function")
 
     func _thread_function(userdata):
-
-        while(true):
-            semaphore.wait() # wait until posted
+        while (true):
+            semaphore.wait() # Wait until posted.
 
             mutex.lock()
-            var should_exit = exit_thread # protect with mutex
+            var should_exit = exit_thread # Protect with Mutex.
             mutex.unlock()
 
             if (should_exit):
                 break
 
             mutex.lock()
-            counter+=1 # increment counter, protect with mutex
+            counter += 1 # Increment counter, protect with Mutex.
             mutex.unlock()
 
     func increment_counter():
-        semaphore.post() # Make the thread process 
+        semaphore.post() # Make the thread process.
 
     func get_counter():
         mutex.lock()
-        # copy counter, protect with mutex
-        var counter_value = counter 
+        # copy counter, protect with mutex.
+        var counter_value = counter
         mutex.unlock()
         return counter_value
 
-
-    # Thread must be disposed (or "Joined"), for portability
+    # Thread must be disposed (or "joined"), for portability.
     func _exit_tree():
-        # Set exit condition to true       
+        # Set exit condition to true.
         mutex.lock()
-        exit_thread = true # protect with mutex
+        exit_thread = true # Protect with Mutex.
         mutex.unlock()
 
-        # unblock by posting
+        # Unblock by posting.
         semaphore.post()
 
-        # wait until it exits
+        # Wait until it exits.
         thread.wait_to_finish()
 
-        # Print the counter
-        print("Counter is: ",counter)
-
-
-
+        # Print the counter.
+        print("Counter is: ", counter)