Skip to content

Instantly share code, notes, and snippets.

@nikki93
Created April 9, 2021 03:46
Show Gist options
  • Save nikki93/b77d55944e7f52464f3eeffbc4934877 to your computer and use it in GitHub Desktop.
Save nikki93/b77d55944e7f52464f3eeffbc4934877 to your computer and use it in GitHub Desktop.
nikki@pop-os:~/Development/castle-xyz/castle-client/core
$ ./run.sh release
-- Configuring done
-- Generating done
-- Build files have been written to: /home/nikki/Development/castle-xyz/castle-client/core/build/release
[0/2] Re-checking globbed directories...
[2/2] Linking CXX executable castle-core
time: 1.727592139999615
sum: -1840446080
nikki@pop-os:~/Development/castle-xyz/castle-client/core
$ ./run.sh release
-- Configuring done
-- Generating done
-- Build files have been written to: /home/nikki/Development/castle-xyz/castle-client/core/build/release
[0/2] Re-checking globbed directories...
[2/2] Linking CXX executable castle-core
time: 1.839390456007095
sum: -1840446080
nikki@pop-os:~/Development/castle-xyz/castle-client/core
$
#include "precomp.h"
#include "engine.h"
// Run the main loop, calling `frame` per frame. `frame` should return a
// boolean that is `false` when it wants to quit. Handles both the web and
// desktop cases.
template<typename F>
void loop(F &&frame) {
#ifdef __EMSCRIPTEN__
static auto &sFrame = frame;
emscripten_set_main_loop(
[]() {
sFrame();
},
0, true);
#else
while (frame()) {
}
#endif
}
// Main web and desktop entrypoint
#undef main // SDL does some weird stuff overriding `main` with a macro...
int main() {
Lv lv { 800, 450 };
love::RandomGenerator rng;
auto sum = 0;
auto start = lv.timer.getTime();
{
struct Thing {
struct Stuff {
int i = 0;
float f = 0;
};
std::vector<Stuff> stuffs;
};
for (auto i = 0; i < 1000; ++i) {
std::array<Thing, 2000> things;
for (auto &thing : things) {
for (auto i = 0; i < int(rng.rand() % 8); ++i) {
thing.stuffs.push_back(Thing::Stuff { int(rng.rand() % 200), float(rng.random()) });
}
}
for (auto i = 0; i < 100; ++i) {
for (auto &thing : things) {
for (auto &stuff : thing.stuffs) {
sum += stuff.f * float(stuff.i);
}
}
}
}
}
auto end = lv.timer.getTime();
fmt::print("time: {}\n", end - start);
fmt::print("sum: {}\n", sum);
return 0;
Engine eng;
loop([&]() {
return eng.frame();
});
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment