ランダム関数の修正
守矢諏訪子 <suwako@076.moe>、2026-06-26 05:13
コミット 726e4bf6bfb24cec05f077e09c7f32fe01ef2b81
・親 a28100b
・ファイルを見る
7個のファイル、+44 -9
| @@ -153,6 +153,7 @@ | ||
| 153 | 153 | void SetContextMinorVersion(int minor); |
| 154 | 154 | void SetOpenGLProfile(int profile); |
| 155 | 155 | void SetForwardCompatibility(bool fc); |
| 156 | + void SetMaximized(bool fc); | |
| 156 | 157 | |
| 157 | 158 | void CreateWindowHints(); |
| 158 | 159 | void PollEvents(); |
| @@ -175,6 +176,7 @@ | ||
| 175 | 176 | int m_Minor = 0; |
| 176 | 177 | int m_Profile = 0; |
| 177 | 178 | bool m_ForwardCompat = false; |
| 179 | + bool m_IsMaximized = false; | |
| 178 | 180 | }; // class Instance |
| 179 | 181 | |
| 180 | 182 | class Window { |
| @@ -189,6 +191,7 @@ | ||
| 189 | 191 | void SwapBuffers(); |
| 190 | 192 | |
| 191 | 193 | void GetSize(int *w, int *h); |
| 194 | + void Maximize(); | |
| 192 | 195 | void SetClipboardString(string str); |
| 193 | 196 | string GetClipboardString(); |
| 194 | 197 | void MakeContextCurrent(); |
| @@ -38,6 +38,7 @@ | ||
| 38 | 38 | #include <util/types.hh> |
| 39 | 39 | |
| 40 | 40 | namespace util::rand { |
| 41 | + void Seed(u32 seed); | |
| 41 | 42 | i32 GetRandom(i32 min, i32 max); |
| 42 | 43 | } // namespace util::rand |
| 43 | 44 |
変更
main.cc
| @@ -40,6 +40,7 @@ | ||
| 40 | 40 | #include <util/vector.hh> |
| 41 | 41 | #include <util/sqlite.hh> |
| 42 | 42 | #include <util/structs.hh> |
| 43 | +#include <util/random.hh> | |
| 43 | 44 | #include <shader/shader.hh> |
| 44 | 45 | #include <shader/buffers.hh> |
| 45 | 46 | #include <database/setup.hh> |
| @@ -57,6 +58,7 @@ | ||
| 57 | 58 | #include <backends/imgui_impl_opengl3.h> |
| 58 | 59 | |
| 59 | 60 | #include <sol.hpp> |
| 61 | +#include <chrono> | |
| 60 | 62 | |
| 61 | 63 | constexpr int windowWidth = 1280; |
| 62 | 64 | constexpr int windowHeight = 720; |
| @@ -70,7 +72,11 @@ | ||
| 70 | 72 | glfw.SetContextMinorVersion(6); |
| 71 | 73 | glfw.SetOpenGLProfile(glfwpp::Attributes::OpenGLCore); |
| 72 | 74 | glfw.SetForwardCompatibility(true); |
| 75 | + glfw.SetMaximized(true); | |
| 73 | 76 | glfw.CreateWindowHints(); |
| 77 | + | |
| 78 | + u32 seed = static_cast<u32>(std::chrono::high_resolution_clock::now().time_since_epoch().count()); | |
| 79 | + util::rand::Seed(seed); | |
| 74 | 80 | |
| 75 | 81 | // ウィンドウを作成 |
| 76 | 82 | string winName = sofname + " " + version::full; |
| @@ -40,7 +40,7 @@ | ||
| 40 | 40 | if (!glfw.isAbout) return; |
| 41 | 41 | |
| 42 | 42 | ImGuiWindowFlags flags = 0; |
| 43 | - ImGui::SetNextWindowSize({800, 600}, ImGuiCond_FirstUseEver); | |
| 43 | + ImGui::SetNextWindowSize({400, 300}, ImGuiCond_Appearing); | |
| 44 | 44 | ImGui::Begin("Shader Playgroundについて", &glfw.isAbout, flags); |
| 45 | 45 | string name = "Shader Playground " + glfw.version; |
| 46 | 46 | string copyright = "© 2026 - 076スタジオ合同会社"; |
| @@ -98,7 +98,7 @@ | ||
| 98 | 98 | dock_right = ImGui::DockBuilderSplitNode( |
| 99 | 99 | dock_main, |
| 100 | 100 | ImGuiDir_Right, |
| 101 | - 0.45f, | |
| 101 | + 0.35f, | |
| 102 | 102 | nullptr, |
| 103 | 103 | &dock_main |
| 104 | 104 | ); |
| @@ -71,11 +71,16 @@ | ||
| 71 | 71 | m_ForwardCompat = fc; |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | + void Instance::SetMaximized(bool fc) { | |
| 75 | + m_IsMaximized = fc; | |
| 76 | + } | |
| 77 | + | |
| 74 | 78 | void Instance::CreateWindowHints() { |
| 75 | 79 | glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, m_Major); |
| 76 | 80 | glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, m_Minor); |
| 77 | 81 | glfwWindowHint(GLFW_OPENGL_PROFILE, m_Profile); |
| 78 | 82 | glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, m_ForwardCompat); |
| 83 | + glfwWindowHint(GLFW_MAXIMIZED, m_IsMaximized); | |
| 79 | 84 | } |
| 80 | 85 | |
| 81 | 86 | void Instance::PollEvents() { |
| @@ -159,6 +164,10 @@ | ||
| 159 | 164 | |
| 160 | 165 | void Window::GetSize(int *w, int *h) { |
| 161 | 166 | glfwGetWindowSize(m_Window, w, h); |
| 167 | + } | |
| 168 | + | |
| 169 | + void Window::Maximize() { | |
| 170 | + glfwMaximizeWindow(m_Window); | |
| 162 | 171 | } |
| 163 | 172 | |
| 164 | 173 | void Window::SetClipboardString(string str) { |
| @@ -34,15 +34,17 @@ | ||
| 34 | 34 | */ |
| 35 | 35 | #include <util/random.hh> |
| 36 | 36 | #include <cmath> |
| 37 | +#include <chrono> | |
| 37 | 38 | |
| 38 | 39 | namespace util::rand { |
| 39 | 40 | u32 randState[4]; |
| 40 | - static inline u32 randLeftRot(const u32 x, i32 k) { | |
| 41 | + | |
| 42 | + static inline u32 leftRot(const u32 x, i32 k) { | |
| 41 | 43 | return (x << k) | (x >> (32 - k)); |
| 42 | 44 | } |
| 43 | 45 | |
| 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; | |
| 46 | 48 | const u32 t = randState[1] << 9; |
| 47 | 49 | |
| 48 | 50 | randState[2] ^= randState[0]; |
| @@ -51,15 +53,29 @@ | ||
| 51 | 53 | randState[0] ^= randState[3]; |
| 52 | 54 | |
| 53 | 55 | randState[2] ^= t; |
| 54 | - randState[3] = randLeftRot(randState[3], 11); | |
| 56 | + randState[3] = leftRot(randState[3], 11); | |
| 55 | 57 | |
| 56 | 58 | return res; |
| 57 | 59 | } |
| 58 | 60 | |
| 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); | |
| 61 | 64 | } |
| 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 | + } | |
| 62 | 72 | |
| 73 | + ////////////////////// | |
| 74 | + | |
| 75 | + void Seed(u32 seed) { | |
| 76 | + for (int i = 0; i < 4; i++) randState[i] = splitmix32(seed); | |
| 77 | + } | |
| 78 | + | |
| 63 | 79 | i32 GetRandom(i32 min, i32 max) { |
| 64 | 80 | if (min > max) { |
| 65 | 81 | i32 tmp = max; |
| @@ -67,6 +83,6 @@ | ||
| 67 | 83 | min = tmp; |
| 68 | 84 | } |
| 69 | 85 | |
| 70 | - return randGetValue(min, max); | |
| 86 | + return getValue(min, max); | |
| 71 | 87 | } |
| 72 | 88 | } // namespace util::rand |