Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 .. _cds2014_cpp: | |
| 2 | |
| 3 ################################## | |
| 4 A Saga of Fire and Water - Codelab | |
| 5 ################################## | |
| 6 | |
| 7 Introduction | |
| 8 ------------ | |
| 9 | |
| 10 .. include:: cpp_summary.inc | |
| 11 | |
| 12 .. include:: ../nacldev/setup_app.inc | |
| 13 | |
| 14 Get the Code! | |
| 15 ------------- | |
| 16 | |
| 17 Rather than start from nothing, for this codelab we've provided | |
| 18 you with a zip file containing a starting point. | |
| 19 | |
| 20 Download the codelab:: | |
| 21 | |
| 22 curl http://nacltools.storage.googleapis.com/cds2014/cds2014_cpp.zip -O | |
| 23 | |
| 24 Unzip it:: | |
| 25 | |
| 26 unzip cds2014_cpp.zip | |
| 27 | |
| 28 Go into the codelab directory:: | |
| 29 | |
| 30 cd cds2014_cpp | |
| 31 | |
| 32 Create a new local git repo:: | |
| 33 | |
| 34 git init | |
| 35 | |
| 36 Add everything:: | |
| 37 | |
| 38 git add . | |
| 39 | |
| 40 Commit it:: | |
| 41 | |
| 42 git commit -am "initial" | |
| 43 | |
| 44 While working, you can see what you've changed by running:: | |
| 45 | |
| 46 git diff | |
| 47 | |
| 48 | |
| 49 Fire is cool, let's burn some stuff... | |
| 50 -------------------------------------- | |
| 51 | |
| 52 Indulging your inner child, lets make some virtual fire! | |
| 53 Use the following shockingly intuitive incantation:: | |
| 54 | |
| 55 make fire | |
| 56 | |
| 57 You should now see a small popup window, smoldering away. | |
| 58 If you click, you can make more fire! | |
| 59 I think that's pretty cool, but then I selected | |
| 60 the institution of higher learning I attended based | |
| 61 on the integral role fire played in its campus life. | |
| 62 | |
| 63 Water | |
| 64 ----- | |
| 65 | |
| 66 Remarkably, not everyone enjoys the primal illusion of fire. | |
| 67 | |
| 68 Your task in this codelab is to transform the rising fire | |
| 69 effect you see before you, into a beautiful, tranquil waterfall. | |
| 70 This will require digging into some C++ code. | |
| 71 | |
| 72 Before you begin, you'll want to copy our fire program to a new name, | |
| 73 since you might decide later that you like fire better, I know I do:: | |
| 74 | |
| 75 cp fire.cc water.cc | |
| 76 | |
| 77 For this codelab, you'll only need to change `water.cc`. | |
| 78 | |
| 79 The task of turning fire into water involves two key challenges: | |
| 80 | |
| 81 * Alter the red-yellow palette of fire into a blue-green one. | |
| 82 * Reverse upward rising flame into downward falling water. | |
| 83 * Seed the waterfall from the top instead of the bottom. | |
| 84 | |
| 85 At this point you'll want to open up `water.cc` in the editor you | |
| 86 picked earlier. | |
| 87 | |
| 88 I see a red door and I want it painted... blue | |
| 89 ============================================== | |
| 90 | |
| 91 While PPAPI's 2D graphics API uses multi-component RGB pixels, | |
| 92 our flame effect is actually monochrome. A single intensity | |
| 93 value is used in the flame simulation. This is then converted | |
| 94 to color based on a multi-color gradient. | |
| 95 To alter the color-scheme, locate this palette, and exchange | |
| 96 the red component for blue. | |
| 97 | |
| 98 Hint: Focus your energies on the CreatePalette function. | |
| 99 | |
| 100 You can test you changes at any time with:: | |
| 101 | |
| 102 make water | |
| 103 | |
| 104 What goes up... | |
| 105 =============== | |
| 106 | |
| 107 Now there's the small matter of gravity. | |
| 108 While smoke, and well flame, rises, we want our water to go down. | |
| 109 | |
| 110 The simulation of fire loops over each pixel, | |
| 111 bottom row to top row, | |
| 112 diffusing "fire stuff" behind the sweep. | |
| 113 You'll want to reverse this. | |
| 114 Note the simulation buffer is stored in |row_major| from bottom to top. | |
| 115 Accesses of + width and - width are used to reach rows above and below | |
| 116 the current line. | |
| 117 | |
| 118 .. |row_major| raw:: html | |
| 119 | |
| 120 <a href="http://en.wikipedia.org/wiki/Row-major_order" | |
| 121 target="_blank">Row-major order</a> | |
| 122 | |
| 123 Hint: You'll need to change the y loop direction in the UpdateFlames function. | |
| 124 | |
| 125 Up high, down low | |
| 126 ================= | |
| 127 | |
| 128 While you can now use the mouse to inject a trickle of water. | |
| 129 The small line of blue at the bottom isn't much of a waterfall. | |
| 130 Move it to the top to complete the effect. | |
| 131 | |
| 132 Hint: You'll want to change the area that the UpdateCoals function mutates. | |
| 133 | |
| 134 | |
| 135 What you've learned | |
| 136 ------------------- | |
| 137 | |
| 138 In addition to learning a new appreciation for fire, you've also made water... | |
| 139 And while dusting off your C/C++ image manipulation skills, | |
| 140 you've discovered how easy it is to modify, build, | |
| 141 and run a NaCl application that uses PPAPI. | |
| 142 | |
| 143 2D graphics is fun, but now you're ready to check out the wealth of | |
| 144 other | |
| 145 `PPAPI interfaces available | |
| 146 <http://src.chromium.org/viewvc/chrome/trunk/src/ppapi/cpp/>`_. | |
|
binji
2014/11/14 19:19:17
point to docs instead of source control?
bradn
2014/11/14 23:55:35
Done.
| |
| 147 | |
| 148 While our in-browser environment is rapidly evolving | |
| 149 to become a complete development solution, | |
| 150 for the broadest range of development options, check out the | |
| 151 `NaCl SDK | |
| 152 <https://developer.chrome.com/native-client/sdk/download>`_. | |
| 153 | |
| 154 For questions, concerns, and help contact us at | |
| 155 `native-client-discuss@googlegroups.com | |
| 156 <https://groups.google.com/forum/#!forum/native-client-discuss>`_. | |
| 157 | |
| 158 I hope this codelab has lit a fire in you to go out there, | |
| 159 and bring an awesome C/C++ application to NaCl or PNaCl today! | |
| 160 | |
| 161 | |
| 162 .. include:: ../nacldev/cleanup_app.inc | |
| OLD | NEW |