File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -21,9 +21,19 @@ Proprietary:
2121
22222D:
2323
24- - Box2D
2524- < http://brm.io/matter-js/ > JavaScript on browser
2625
26+ ## Box2D
27+
28+ AngryBirds used Box2D physics engine which does not require even attribution, and never gave anything back to its creator (Blizzard employee):
29+
30+ - < http://www.geek.com/games/box2d-creator-asks-rovio-for-angry-birds-credit-at-gdc-1321779/ >
31+ - < http://www.neogaf.com/forum/showthread.php?t=472319 >
32+ - impressive chain and watch demos with RUBE (closed source) editor < https://www.youtube.com/watch?v=WqLR4dFn1qE >
33+ - destructible terrain as in Worms:
34+ - https://www.youtube.com/watch?v=Qkh8PMwOgQ4
35+ - gas internal combustion engine!!! < https://www.youtube.com/watch?v=8kZRpouZ3OQ >
36+
2737## Fluids
2838
2939- https://github.com/rchoetzlein/fluids3
Original file line number Diff line number Diff line change 99
1010#include " common.hpp"
1111
12+ int overload (int i){ return i + 1 ; }
13+ int overload (int i, int j){ return i + j; }
14+
15+ int default_ (int i, int j = 1 ){ return i + j; }
16+
1217int main () {
18+ // # function
19+ {
20+ // Disambiguate overload.
21+ // http://stackoverflow.com/questions/12500411/setting-a-stdfunction-variable-to-refer-to-the-stdsin-function
22+ {
23+ std::function<int (int )> f = (int (*)(int ))&overload;
24+ assert (f (1 ) == 2 );
25+ std::function<int (int , int )> g = (int (*)(int , int ))&overload;
26+ assert (g (1 , 2 ) == 3 );
27+ }
28+
29+ // Default vaues without bind.
30+ // TODO possible?
31+ {
32+ // Fails. j seems to contain trash.
33+ // std::function<int(int)> f = (int(*)(int))&default_;
34+ // assert(f(1) == 2);
35+
36+ // Lambda workaround.
37+ std::function<int (int )> f = [](int i){ return default_ (i); };
38+ assert (f (1 ) == 2 );
39+
40+ std::function<int (int , int )> g = (int (*)(int , int ))&default_;
41+ assert (g (1 , 2 ) == 3 );
42+ }
43+ }
44+
1345 /*
1446 # bind2nd
1547
@@ -31,9 +63,7 @@ int main() {
3163 */
3264 }
3365
34- /*
35- # plus
36- */
66+ // # plus
3767 {
3868 assert (std::plus<int >()(1 , 2 ) == 3 );
3969 }
Original file line number Diff line number Diff line change @@ -121,13 +121,33 @@ int main() {
121121 {1 , " one" },
122122 };
123123
124-
125124 auto found = m.find (0 );
126125 assert (found != m.end ());
127126 assert (found->second == " zero" );
128127
129128 assert (m.find (2 ) == m.end ());
130129 assert (m.size () == 2 );
130+
131+ /*
132+ Get default provided value if key not present
133+
134+ TODO: any less verbose way than finding and check != end? Like:
135+
136+ m.get(key, default)
137+
138+ I know I can define a helper, but come on...
139+ */
140+ {
141+ std::map<int ,int > m{};
142+ int default_ = 42 ;
143+ int result;
144+ auto f = m.find (1 );
145+ if (f == m.end ()) {
146+ result = default_;
147+ } else {
148+ result = f->second ;
149+ }
150+ }
131151 }
132152
133153 /*
@@ -225,4 +245,34 @@ int main() {
225245 assert ((m == std::map<int ,std::string>{{1 , " one" }}));
226246 }
227247 }
248+
249+ // # Range switch case.
250+ // http://stackoverflow.com/questions/9432226/how-do-i-select-a-range-of-values-in-a-switch-statement/42331563#42331563
251+ #if 0
252+ {
253+ for (auto i = -1; i < 8; ++i) {
254+ std::cout << i << std::endl;
255+ std::map<int,std::function<void()>> m;
256+ m.emplace(0, [](){
257+ std::cout << "too small" << std::endl;
258+ });
259+ m.emplace(2, [](){
260+ std::cout << "zero" << std::endl;
261+ });
262+ m.emplace(5, [](){
263+ std::cout << "two" << std::endl;
264+ });
265+ m.emplace(7, [](){
266+ std::cout << "five" << std::endl;
267+ });
268+ auto it = m.upper_bound(i);
269+ if (it == m.end()) {
270+ std::cout << "too large" << std::endl;
271+ } else {
272+ it->second();
273+ }
274+ std::cout << std::endl;
275+ }
276+ }
277+ #endif
228278}
Original file line number Diff line number Diff line change @@ -9,8 +9,9 @@ int main() {
99 http://stackoverflow.com/questions/322938/recommended-way-to-initialize-srand/13004555#13004555
1010 */
1111 {
12- std::random_device r;
13- std::mt19937 prng (r ());
12+ std::random_device dev;
13+ unsigned int seed = dev ();
14+ std::mt19937 prng (seed);
1415 std::uniform_int_distribution<> dist (1 , 10 );
1516 for (unsigned int i = 0 ; i < 10 ; ++i) {
1617 // std::cout << dist(prng) << std::endl;
Original file line number Diff line number Diff line change @@ -81,8 +81,6 @@ int main() {
8181 /*
8282 # insert
8383
84- Like for std::vector, insert makes copies.
85-
8684 Return is a pair conatining:
8785
8886 - if the item was not present, an iterator to the item inserted and true
@@ -177,8 +175,6 @@ int main() {
177175 Else, returns `map::end()`
178176
179177 find is `log n` time since the container is ordered.
180-
181- log n time complexity since always sorted
182178 */
183179 {
184180 std::set<int > s = {0 , 1 , 2 };
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ TODO software implementations: <https://www.quora.com/unanswered/Is-there-a-Vulk
1717- < https://github.com/SaschaWillems/Vulkan >
1818- < https://github.com/LunarG/VulkanSamples >
1919- < https://github.com/Overv/VulkanTutorial >
20+ - < https://gist.githubusercontent.com/sheredom/523f02bbad2ae397d7ed255f3f3b5a7f/raw/7c33ee6136ae1f7c03741ba7ad6e02e8de9f9802/VkComputeSample > Codeplay employee writes SPIR-V shader by hand! :-) The absolute minimal example?
2021
2122## Hardware support
2223
You can’t perform that action at this time.
0 commit comments