Skip to content

Commit

Permalink
Merge pull request #133 from Lyzev/131-bug-opening-up-schizoid-clickg…
Browse files Browse the repository at this point in the history
…ui-crashes-the-game-when-using-liquidbounce-with-schizoid-1

did take way too long, sry
  • Loading branch information
Lyzev authored Jun 8, 2024
2 parents 6d07759 + f2587fc commit 7847679
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 27 deletions.
38 changes: 16 additions & 22 deletions src/main/kotlin/dev/lyzev/api/opengl/shader/Shaders.kt
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ object ShaderParticle : ShaderCompute("Particle", 64, 1, 1) {
}
}

object ShaderRandom : ShaderVertexFragment("Random")

object ShaderMovingAveragesBox : ShaderCompute("MovingAveragesBox", 32, 1, 1) {

private val horizontal = Matrix2f(1f, 0f, 0f, 1f)
Expand Down Expand Up @@ -231,12 +233,17 @@ object ShaderGameOfLife : ShaderCompute("GameOfLife", 32, 1, 1) {
private lateinit var after: WrappedFramebuffer

private var initTime = System.currentTimeMillis()
var queueGenPixels = true
var deltaTime = 1000 / 10
var size = 3
var b = "3"
var s = "23"
var s = "236"

override fun draw() {
if (queueGenPixels) {
generateRandomPixels()
queueGenPixels = false
}
if (System.currentTimeMillis() - initTime > deltaTime) {
initTime = System.currentTimeMillis()
after.clear()
Expand Down Expand Up @@ -274,27 +281,13 @@ object ShaderGameOfLife : ShaderCompute("GameOfLife", 32, 1, 1) {
ShaderTint.unbind()
}

fun generateRandomPixels() {
val width = before.textureWidth
val height = before.textureHeight
val pixels = MemoryUtil.memAlloc(width * height * 4)
for (i in 0 until width * height) {
if (Math.random() < .7) {
pixels.put(0)
pixels.put(0)
pixels.put(0)
pixels.put(0.toByte())
} else {
pixels.put(255.toByte())
pixels.put(255.toByte())
pixels.put(255.toByte())
pixels.put(255.toByte())
}
}
pixels.flip()
before.beginRead()
GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA8, width, height, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, pixels)
MemoryUtil.memFree(pixels)
private fun generateRandomPixels() {
before.clear()
before.beginWrite(true)
ShaderRandom.bind()
ShaderRandom["Time"] = System.nanoTime() / 1000000000f
drawFullScreen()
ShaderRandom.unbind()
}

override fun delete() {
Expand All @@ -307,6 +300,7 @@ object ShaderGameOfLife : ShaderCompute("GameOfLife", 32, 1, 1) {
super.init()
before = WrappedFramebuffer(size, linear = false)
after = WrappedFramebuffer(size, linear = false)
queueGenPixels = true
}

override fun preprocess(source: String) = processIncludes(source).format(myGroupSizeX, myGroupSizeY, myGroupSizeZ, b.toCharArray().joinToString(", "), s.toCharArray().joinToString(", "))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ object ImGuiScreenFeature : ImGuiScreen("Feature Screen"), EventListener {
}
if (it == "Game of Life") {
ShaderGameOfLife.init()
ShaderGameOfLife.generateRandomPixels()
} else {
ShaderGameOfLife.delete()
}
Expand Down Expand Up @@ -94,12 +93,11 @@ object ImGuiScreenFeature : ImGuiScreen("Feature Screen"), EventListener {
) {
ShaderGameOfLife.size = it
ShaderGameOfLife.reload()
ShaderGameOfLife.generateRandomPixels()
}
val gameOfLifeRulestring by text(
"Game of Life Rulestring",
"The rulestring of the game of life.",
"B3/S23",
"B3/S236",
true,
Regex("B[0-8]+/S[0-8]+"),
hide = ::background neq "Game of Life"
Expand All @@ -108,7 +106,6 @@ object ImGuiScreenFeature : ImGuiScreen("Feature Screen"), EventListener {
ShaderGameOfLife.b = rulestring.substringAfter("B").substringBefore("/")
ShaderGameOfLife.s = rulestring.substringAfter("S")
ShaderGameOfLife.reload()
ShaderGameOfLife.generateRandomPixels()
}

private val texturesMario = Array(3) {
Expand Down Expand Up @@ -144,7 +141,7 @@ object ImGuiScreenFeature : ImGuiScreen("Feature Screen"), EventListener {
val configManager = ImGuiRenderableConfigManager()

override fun onDisplayed() {
ShaderGameOfLife.generateRandomPixels()
ShaderGameOfLife.queueGenPixels = true
}

override fun renderInGameBackground(context: DrawContext) =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright (c) 2023. Schizoid
* All rights reserved.
*/

#version 330

in vec2 uv;
out vec4 color;

uniform float Time;

#include "Noise.glsl"

void main() {
if (rand(uv * (4500 + 2500 * rand(vec2(Time)))) < .7) {
color = vec4(0);
} else {
color = vec4(1);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright (c) 2023. Schizoid
* All rights reserved.
*/

#version 330

in vec2 position;
out vec2 uv;

void main() {
gl_Position = vec4(position, 0, 1);
uv = position * .5 + .5;
}

0 comments on commit 7847679

Please sign in to comment.