Skip to content

Commit c66716c

Browse files
committed
bak
1 parent 1c1d8f0 commit c66716c

6 files changed

Lines changed: 99 additions & 11 deletions

File tree

bullet/alternatives.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,19 @@ Proprietary:
2121

2222
2D:
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

cpp/functional.cpp

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,39 @@
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+
1217
int 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
}

cpp/map.cpp

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff 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
}

cpp/random.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff 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;

cpp/set.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff 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};

opengl/vulkan.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)