ランダム関数の修正

守矢諏訪子 <suwako@076.moe>、2026-06-26 05:13
コミット 726e4bf6bfb24cec05f077e09c7f32fe01ef2b81 ・親 a28100b ・ファイルを見る

7個のファイル、+44 -9

@@ -153,6 +153,7 @@
153153 void SetContextMinorVersion(int minor);
154154 void SetOpenGLProfile(int profile);
155155 void SetForwardCompatibility(bool fc);
156+ void SetMaximized(bool fc);
156157
157158 void CreateWindowHints();
158159 void PollEvents();
@@ -175,6 +176,7 @@
175176 int m_Minor = 0;
176177 int m_Profile = 0;
177178 bool m_ForwardCompat = false;
179+ bool m_IsMaximized = false;
178180 }; // class Instance
179181
180182 class Window {
@@ -189,6 +191,7 @@
189191 void SwapBuffers();
190192
191193 void GetSize(int *w, int *h);
194+ void Maximize();
192195 void SetClipboardString(string str);
193196 string GetClipboardString();
194197 void MakeContextCurrent();
@@ -38,6 +38,7 @@
3838 #include <util/types.hh>
3939
4040 namespace util::rand {
41+ void Seed(u32 seed);
4142 i32 GetRandom(i32 min, i32 max);
4243 } // namespace util::rand
4344
変更 main.cc
@@ -40,6 +40,7 @@
4040 #include <util/vector.hh>
4141 #include <util/sqlite.hh>
4242 #include <util/structs.hh>
43+#include <util/random.hh>
4344 #include <shader/shader.hh>
4445 #include <shader/buffers.hh>
4546 #include <database/setup.hh>
@@ -57,6 +58,7 @@
5758 #include <backends/imgui_impl_opengl3.h>
5859
5960 #include <sol.hpp>
61+#include <chrono>
6062
6163 constexpr int windowWidth = 1280;
6264 constexpr int windowHeight = 720;
@@ -70,7 +72,11 @@
7072 glfw.SetContextMinorVersion(6);
7173 glfw.SetOpenGLProfile(glfwpp::Attributes::OpenGLCore);
7274 glfw.SetForwardCompatibility(true);
75+ glfw.SetMaximized(true);
7376 glfw.CreateWindowHints();
77+
78+ u32 seed = static_cast<u32>(std::chrono::high_resolution_clock::now().time_since_epoch().count());
79+ util::rand::Seed(seed);
7480
7581 // ウィンドウを作成
7682 string winName = sofname + " " + version::full;
@@ -40,7 +40,7 @@
4040 if (!glfw.isAbout) return;
4141
4242 ImGuiWindowFlags flags = 0;
43- ImGui::SetNextWindowSize({800, 600}, ImGuiCond_FirstUseEver);
43+ ImGui::SetNextWindowSize({400, 300}, ImGuiCond_Appearing);
4444 ImGui::Begin("Shader Playgroundについて", &glfw.isAbout, flags);
4545 string name = "Shader Playground " + glfw.version;
4646 string copyright = "© 2026 - 076スタジオ合同会社";
@@ -98,7 +98,7 @@
9898 dock_right = ImGui::DockBuilderSplitNode(
9999 dock_main,
100100 ImGuiDir_Right,
101- 0.45f,
101+ 0.35f,
102102 nullptr,
103103 &dock_main
104104 );
@@ -71,11 +71,16 @@
7171 m_ForwardCompat = fc;
7272 }
7373
74+ void Instance::SetMaximized(bool fc) {
75+ m_IsMaximized = fc;
76+ }
77+
7478 void Instance::CreateWindowHints() {
7579 glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, m_Major);
7680 glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, m_Minor);
7781 glfwWindowHint(GLFW_OPENGL_PROFILE, m_Profile);
7882 glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, m_ForwardCompat);
83+ glfwWindowHint(GLFW_MAXIMIZED, m_IsMaximized);
7984 }
8085
8186 void Instance::PollEvents() {
@@ -159,6 +164,10 @@
159164
160165 void Window::GetSize(int *w, int *h) {
161166 glfwGetWindowSize(m_Window, w, h);
167+ }
168+
169+ void Window::Maximize() {
170+ glfwMaximizeWindow(m_Window);
162171 }
163172
164173 void Window::SetClipboardString(string str) {
@@ -34,15 +34,17 @@
3434 */
3535 #include <util/random.hh>
3636 #include <cmath>
37+#include <chrono>
3738
3839 namespace util::rand {
3940 u32 randState[4];
40- static inline u32 randLeftRot(const u32 x, i32 k) {
41+
42+ static inline u32 leftRot(const u32 x, i32 k) {
4143 return (x << k) | (x >> (32 - k));
4244 }
4345
44- u32 randXoshiro128() {
45- const u32 res = randLeftRot(randState[1] * 5, 7) * 9;
46+ u32 xoshiro128() {
47+ const u32 res = leftRot(randState[1] * 5, 7) * 9;
4648 const u32 t = randState[1] << 9;
4749
4850 randState[2] ^= randState[0];
@@ -51,15 +53,29 @@
5153 randState[0] ^= randState[3];
5254
5355 randState[2] ^= t;
54- randState[3] = randLeftRot(randState[3], 11);
56+ randState[3] = leftRot(randState[3], 11);
5557
5658 return res;
5759 }
5860
59- i32 randGetValue(i32 min, i32 max) {
60- return randXoshiro128() % (abs(max - min) + 1) + min;
61+ i32 getValue(i32 min, i32 max) {
62+ u32 range = static_cast<u32>(max - min + 1);
63+ return min + (xoshiro128() % range);
6164 }
65+
66+ static u32 splitmix32(u32 &x) {
67+ u32 z = (x += 0x9e3779b9);
68+ z = (z ^ (z >> 16)) * 0x85ebca6b;
69+ z = (z ^ (z >> 13)) * 0xc2b2ae35;
70+ return z ^ (z >> 16);
71+ }
6272
73+ //////////////////////
74+
75+ void Seed(u32 seed) {
76+ for (int i = 0; i < 4; i++) randState[i] = splitmix32(seed);
77+ }
78+
6379 i32 GetRandom(i32 min, i32 max) {
6480 if (min > max) {
6581 i32 tmp = max;
@@ -67,6 +83,6 @@
6783 min = tmp;
6884 }
6985
70- return randGetValue(min, max);
86+ return getValue(min, max);
7187 }
7288 } // namespace util::rand