From ec66db9c08f342d5f6923c54632211eba3a1d46b Mon Sep 17 00:00:00 2001 From: austin Date: Tue, 6 Dec 2022 20:01:53 -0500 Subject: [PATCH] ui debug tools,macos settings,javascript engine --- assets/Config/settings.json | 6 +- assets/Scripts/test.js | 1 + assets/Shaders/plane/plane.vs | 5 +- assets/Shaders/smoke1/smoke1.fs | 351 ++++++++++++++++++ assets/Shaders/smoke1/smoke1.vs | 47 +++ .../debug/{ => windowBorder}/windowBound.fs | 0 .../debug/{ => windowBorder}/windowBound.vs | 2 +- .../windowContentBorder/windowContentBound.fs | 18 + .../windowContentBorder/windowContentBound.vs | 26 ++ assets/Shaders/ui/window/window.fs | 14 + assets/Shaders/ui/window/window.vs | 30 ++ .../Shaders/ui/windowContent/windowContent.fs | 14 + .../Shaders/ui/windowContent/windowContent.vs | 30 ++ pom.xml | 29 ++ .../controls/ControlHandler.java | 153 ++++++-- .../electrosphere/engine/LoadingThread.java | 11 +- .../assetmanager/AssetLoadingThread.java | 42 +++ .../entity/state/gravity/GravityTree.java | 16 +- .../game/config/UserSettings.java | 19 + src/main/java/electrosphere/main/Globals.java | 8 +- src/main/java/electrosphere/main/Main.java | 57 +-- .../electrosphere/menu/MenuGenerators.java | 36 +- .../menu/MenuGeneratorsDebug.java | 89 +++++ .../electrosphere/menu/WindowStrings.java | 1 + .../renderer/RenderingEngine.java | 95 ++++- .../electrosphere/renderer/ShaderProgram.java | 1 + .../renderer/debug/DebugRendering.java | 73 +++- .../renderer/ui/WidgetUtils.java | 15 +- .../electrosphere/renderer/ui/Window.java | 8 +- .../renderer/ui/elements/ActorPanel.java | 34 +- .../renderer/ui/elements/Button.java | 14 + .../renderer/ui/elements/Div.java | 18 +- .../renderer/ui/elements/Label.java | 2 +- .../renderer/ui/elements/Slider.java | 12 +- .../electrosphere/script/ScriptEngine.java | 60 +++ 35 files changed, 1162 insertions(+), 175 deletions(-) create mode 100644 assets/Scripts/test.js create mode 100644 assets/Shaders/smoke1/smoke1.fs create mode 100644 assets/Shaders/smoke1/smoke1.vs rename assets/Shaders/ui/debug/{ => windowBorder}/windowBound.fs (100%) rename assets/Shaders/ui/debug/{ => windowBorder}/windowBound.vs (83%) create mode 100644 assets/Shaders/ui/debug/windowContentBorder/windowContentBound.fs create mode 100644 assets/Shaders/ui/debug/windowContentBorder/windowContentBound.vs create mode 100644 assets/Shaders/ui/window/window.fs create mode 100644 assets/Shaders/ui/window/window.vs create mode 100644 assets/Shaders/ui/windowContent/windowContent.fs create mode 100644 assets/Shaders/ui/windowContent/windowContent.vs create mode 100644 src/main/java/electrosphere/engine/assetmanager/AssetLoadingThread.java create mode 100644 src/main/java/electrosphere/menu/MenuGeneratorsDebug.java create mode 100644 src/main/java/electrosphere/script/ScriptEngine.java diff --git a/assets/Config/settings.json b/assets/Config/settings.json index 7dab4193..dc3e6d34 100644 --- a/assets/Config/settings.json +++ b/assets/Config/settings.json @@ -11,9 +11,13 @@ "graphicsPerformanceLODChunkRadius" : 3, "graphicsPerformanceEnableVSync" : false, - "graphicsPerformanceDrawShadows" : true, + "graphicsPerformanceDrawShadows" : false, + "graphicsPerformanceOIT" : true, "graphicsViewRange" : 20000.0, + "renderResolutionX": 1280, + "renderResolutionY": 800, + "graphicsDebugDrawCollisionSpheres" : false, "graphicsDebugDrawPhysicsObjects" : false, "graphicsDebugDrawMovementVectors" : false, diff --git a/assets/Scripts/test.js b/assets/Scripts/test.js new file mode 100644 index 00000000..d8ec2468 --- /dev/null +++ b/assets/Scripts/test.js @@ -0,0 +1 @@ +console.log("test") \ No newline at end of file diff --git a/assets/Shaders/plane/plane.vs b/assets/Shaders/plane/plane.vs index f007cbe4..6b421834 100644 --- a/assets/Shaders/plane/plane.vs +++ b/assets/Shaders/plane/plane.vs @@ -12,14 +12,15 @@ uniform vec3 tDimension; void main(){ vec2 finalPos = vec2( ((aPos.x + 1)/2 * mDimension.x + mPosition.x) * 2 - 1, - -((((aPos.y + 1)/2) * mDimension.y + mPosition.y) * 2 - 1) + ((((aPos.y + 1)/2) * mDimension.y + (1 - mDimension.y) - mPosition.y) * 2 - 1) + // ((((aPos.y + 1)/2) * mDimension.y + mPosition.y) * 2 - 1) // aPos.y * mDimension.y + (mPosition.y) + (1 - mDimension.y) ); gl_Position = vec4(finalPos.x, finalPos.y, 0.0, 1.0); vec2 finalTex = vec2( aTexCoords.x * tDimension.x + tPosition.x, - aTexCoords.y * tDimension.y + tPosition.y + 1 - (aTexCoords.y * tDimension.y + tPosition.y) ); // vec2 finalTex = aTexCoords; // vec2 finalTex = vec2( diff --git a/assets/Shaders/smoke1/smoke1.fs b/assets/Shaders/smoke1/smoke1.fs new file mode 100644 index 00000000..64e6f106 --- /dev/null +++ b/assets/Shaders/smoke1/smoke1.fs @@ -0,0 +1,351 @@ +/* +MIT License + +Copyright (c) 2022 railgunSR + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ +/* +THIS MAKES USE OF OPENSIMPLEX2, A NOISE ALGORITHM CREATED BY THE FINE FOLKS +OVER AT https://github.com/KdotJPG/OpenSimplex2 +PLEASE GIVE THEM SOME LOVE. + +IT ALSO MAKES USE OF FUNCTIONS FROM THE_FORCE, A SHADER IDE +https://github.com/shawnlawson/The_Force + +*/ + +//version +#version 330 core + +//output +// out vec4 fragColor; + +layout (location = 0) out vec4 accum; +layout (location = 1) out float reveal; + +//input +in vec3 FragPos; +in vec3 Normal; +in vec2 TexCoord; +in vec4 projCoord; +in vec4 modelCoord; + +//uniforms +uniform float time; + +//layout uniforms +uniform sampler2D shadowMap; +uniform sampler2D volumeDepthFrontface; +uniform sampler2D volumeDepthBackface; + +//function declarations +vec4 openSimplex2_Conventional(vec3 X); +vec4 openSimplex2_ImproveXY(vec3 X); +float flameTex(float x, float y); +float getNoise(float scale, float timeScale); +float voronoi(vec2 point); +vec3 voronoi(vec3 x); +float linearCenterAroundPoint(float inputPt, float centerpoint, float falloff); + +/* +Main method +*/ +void main(){ + + float timeS = time * 0.003; + + // Normalized pixel coordinates (from 0 to 1) + vec3 projCoordNorm = projCoord.xyz / projCoord.w / 2.0 + 0.5; + //make vec2 + vec2 finalProd = projCoordNorm.xy; + //grab depth values + float closeDepth = texture(volumeDepthFrontface, finalProd.xy).r; + float farDepth = texture(volumeDepthBackface, finalProd.xy).r; + //distance between the two + float volume = min(abs(farDepth - closeDepth),1); + + + //based on distance of model coords from center + float dist = length(modelCoord.xyz); + + + //noise + // float noiseInX = modelCoord.x * 7.0; + // float noiseInZ = FragPos.y * 7.0 - timeS; + // float noiseInY = modelCoord.y * 7.0; + // float noise = openSimplex2_ImproveXY(vec3(noiseInX,noiseInY,noiseInZ)).x; + float noise = (getNoise(7.0,1.5 * timeS) + getNoise(10.0,1.5 * (timeS + 0.1)) + getNoise(14.0,1.5 * (timeS + 0.2)) + getNoise(20.0,3.0 * timeS)) / 4.0; + // float noise = getNoise(10.0,1.5); + // float noise = getNoise(14.0,2.0); + + float vertical = -modelCoord.z; + + float amountOfFire = volume * 50.0 + vertical * 2.0 + noise * 0.1;// + dist * 0.1; //should be a function of volume + noise + dist from center + + // if(amountOfFire < 0.1){ + // discard; + // } + + amountOfFire = amountOfFire * 2.0; + + float red = 0.1984; + float green = 0.6464; + float blue = 0.7366; + float alpha = volume * 7.0; + + volume = volume * 3; + + float foamFallout = max(1 - (volume * 7),0); + float lightWaterVal = max(1 - (volume * 3),0); + float darkWaterVal = linearCenterAroundPoint(volume,0.5,0.5); + float blackWaterVal = max((volume * 3) - 2,0); + + red = 0.1984 * lightWaterVal + darkWaterVal * 0.0000 + blackWaterVal * 0.0000; + green = 0.6464 * lightWaterVal + darkWaterVal * 0.1370 + blackWaterVal * 0.0980; + blue = 0.7366 * lightWaterVal + darkWaterVal * 0.3140 + blackWaterVal * 0.2200; + + if(dot(Normal,vec3(0,1,0)) > 0.5){ + float foamVal = voronoi(vec3(modelCoord.x * 8,modelCoord.z * 8,timeS)).x; + // foamVal = foamVal * foamVal * min(1 - volume * 10,0); + foamVal = foamVal * foamVal; + red = red + foamVal;// * foamFallout; + blue = blue + foamVal;// * foamFallout; + green = green + foamVal;// * foamFallout; + alpha = alpha + foamVal;// * foamFallout; + // // float foamVal = openSimplex2_ImproveXY(vec3(modelCoord.x * 5.0,modelCoord.z * 5.0,timeS)).x; + // // if(foamVal > 0.4 && foamVal < 0.7){ + // // foamVal = 1.0 - foamVal * foamVal; + // // red = foamVal + red; + // // green = foamVal + green; + // // blue = foamVal + blue; + // // alpha = foamVal + alpha; + // // } + } + + // alpha = 0.5; + + // float red = volume * 10.0; + // float green = volume * 10.0; + // float blue = volume * 10.0; + // float alpha = 1.0; + + vec4 noiseVal = openSimplex2_Conventional(vec3( + projCoordNorm.x * 20, + projCoordNorm.y * 20, + projCoordNorm.z * 20 + timeS * 3)); + + vec4 color = vec4( + noiseVal.x, + noiseVal.y, + noiseVal.z, + alpha * volume + ); + + + // weight function + float weight = clamp(pow(min(1.0, color.a * 10.0) + 0.01, 3.0) * 1e8 * pow(1.0 - gl_FragCoord.z * 0.9, 3.0), 1e-2, 3e3); + + // store pixel color accumulation + accum = vec4(color.rgb,1); + + // store pixel revealage threshold + reveal = volume; + // reveal = 1.0; + + // if(val < 0.3){ + // discard; + // } + + // Output to screen + // fragColor = color; +} + + +float getNoise(float scale, float time){ + float noiseInX = modelCoord.x * scale; + float noiseInZ = FragPos.y * scale - time; + float noiseInY = modelCoord.y * scale; + float noise = openSimplex2_ImproveXY(vec3(noiseInX,noiseInY,noiseInZ)).x; + return noise; +} + + +//////////////// K.jpg's Re-oriented 4-Point BCC Noise (OpenSimplex2) //////////////// +////////////////////// Output: vec4(dF/dx, dF/dy, dF/dz, value) ////////////////////// + +// Inspired by Stefan Gustavson's noise +vec4 permute(vec4 t) { + return t * (t * 34.0 + 133.0); +} + +// Gradient set is a normalized expanded rhombic dodecahedron +vec3 grad(float hash) { + + // Random vertex of a cube, +/- 1 each + vec3 cube = mod(floor(hash / vec3(1.0, 2.0, 4.0)), 2.0) * 2.0 - 1.0; + + // Random edge of the three edges connected to that vertex + // Also a cuboctahedral vertex + // And corresponds to the face of its dual, the rhombic dodecahedron + vec3 cuboct = cube; + cuboct[int(hash / 16.0)] = 0.0; + + // In a funky way, pick one of the four points on the rhombic face + float type = mod(floor(hash / 8.0), 2.0); + vec3 rhomb = (1.0 - type) * cube + type * (cuboct + cross(cube, cuboct)); + + // Expand it so that the new edges are the same length + // as the existing ones + vec3 grad = cuboct * 1.22474487139 + rhomb; + + // To make all gradients the same length, we only need to shorten the + // second type of vector. We also put in the whole noise scale constant. + // The compiler should reduce it into the existing floats. I think. + grad *= (1.0 - 0.042942436724648037 * type) * 32.80201376986577; + + return grad; +} + +// BCC lattice split up into 2 cube lattices +vec4 openSimplex2Base(vec3 X) { + + // First half-lattice, closest edge + vec3 v1 = round(X); + vec3 d1 = X - v1; + vec3 score1 = abs(d1); + vec3 dir1 = step(max(score1.yzx, score1.zxy), score1); + vec3 v2 = v1 + dir1 * sign(d1); + vec3 d2 = X - v2; + + // Second half-lattice, closest edge + vec3 X2 = X + 144.5; + vec3 v3 = round(X2); + vec3 d3 = X2 - v3; + vec3 score2 = abs(d3); + vec3 dir2 = step(max(score2.yzx, score2.zxy), score2); + vec3 v4 = v3 + dir2 * sign(d3); + vec3 d4 = X2 - v4; + + // Gradient hashes for the four points, two from each half-lattice + vec4 hashes = permute(mod(vec4(v1.x, v2.x, v3.x, v4.x), 289.0)); + hashes = permute(mod(hashes + vec4(v1.y, v2.y, v3.y, v4.y), 289.0)); + hashes = mod(permute(mod(hashes + vec4(v1.z, v2.z, v3.z, v4.z), 289.0)), 48.0); + + // Gradient extrapolations & kernel function + vec4 a = max(0.5 - vec4(dot(d1, d1), dot(d2, d2), dot(d3, d3), dot(d4, d4)), 0.0); + vec4 aa = a * a; vec4 aaaa = aa * aa; + vec3 g1 = grad(hashes.x); vec3 g2 = grad(hashes.y); + vec3 g3 = grad(hashes.z); vec3 g4 = grad(hashes.w); + vec4 extrapolations = vec4(dot(d1, g1), dot(d2, g2), dot(d3, g3), dot(d4, g4)); + + // Derivatives of the noise + vec3 derivative = -8.0 * mat4x3(d1, d2, d3, d4) * (aa * a * extrapolations) + + mat4x3(g1, g2, g3, g4) * aaaa; + + // Return it all as a vec4 + return vec4(derivative, dot(aaaa, extrapolations)); +} + +// Use this if you don't want Z to look different from X and Y +vec4 openSimplex2_Conventional(vec3 X) { + + // Rotate around the main diagonal. Not a skew transform. + vec4 result = openSimplex2Base(dot(X, vec3(2.0/3.0)) - X); + return vec4(dot(result.xyz, vec3(2.0/3.0)) - result.xyz, result.w); +} + +// Use this if you want to show X and Y in a plane, then use Z for time, vertical, etc. +vec4 openSimplex2_ImproveXY(vec3 X) { + + // Rotate so Z points down the main diagonal. Not a skew transform. + mat3 orthonormalMap = mat3( + 0.788675134594813, -0.211324865405187, -0.577350269189626, + -0.211324865405187, 0.788675134594813, -0.577350269189626, + 0.577350269189626, 0.577350269189626, 0.577350269189626); + + vec4 result = openSimplex2Base(orthonormalMap * X); + return vec4(result.xyz * orthonormalMap, result.w); +} + +const mat2 myt = mat2(.12121212,.13131313,-.13131313,.12121212); +const vec2 mys = vec2(1e4, 1e6); +vec2 rhash(vec2 uv) { + uv *= myt; + uv *= mys; + return fract(fract(uv/mys)*uv); +} + +vec3 hash( vec3 p ){ + return fract(sin(vec3( dot(p,vec3(1.0,57.0,113.0)), + dot(p,vec3(57.0,113.0,1.0)), + dot(p,vec3(113.0,1.0,57.0))))*43758.5453); + +} + +float voronoi(vec2 point){ + vec2 p = floor( point ); + vec2 f = fract( point ); + float res = 0.0; + for( int j=-1; j<=1; j++ ) { + for( int i=-1; i<=1; i++ ) { + vec2 b = vec2( i, j ); + vec2 r = vec2( b ) - f + rhash( p + b); + res += 1./pow(dot(r,r),8.); + } + } + return pow(1./res, 0.0625); +} + +vec3 voronoi(vec3 x) { + vec3 p = floor( x ); + vec3 f = fract( x ); + + float id = 0.0; + vec2 res = vec2( 100.0 ); + for( int k=-1; k<=1; k++ ) { + for( int j=-1; j<=1; j++ ) { + for( int i=-1; i<=1; i++ ) { + vec3 b = vec3( float(i), float(j), float(k) ); + vec3 r = vec3( b ) - f + hash( p + b ); + float d = dot( r, r ); + + if( d < res.x ) { + id = dot( p+b, vec3(1.0,57.0,113.0 ) ); + res = vec2( d, res.x ); + } + else if( d < res.y ) { + res.y = d; + } + } + } + } + + return vec3( sqrt( res ), abs(id) ); +} + +//////////////////////////////// End noise code //////////////////////////////// + + +float linearCenterAroundPoint(float inputPt, float centerpoint, float falloff){ + return max(((-abs(inputPt - centerpoint)) + centerpoint)*falloff,0); +} + + + diff --git a/assets/Shaders/smoke1/smoke1.vs b/assets/Shaders/smoke1/smoke1.vs new file mode 100644 index 00000000..6c1856f1 --- /dev/null +++ b/assets/Shaders/smoke1/smoke1.vs @@ -0,0 +1,47 @@ +//Vertex Shader +#version 330 core + + + +//input buffers +layout (location = 0) in vec3 aPos; +layout (location = 1) in vec3 aNormal; +layout (location = 4) in vec2 aTex; + + +//coordinate space transformation matrices +uniform mat4 model; +uniform mat4 view; +uniform mat4 projection; +uniform float time; + + + +//output buffers +out vec3 FragPos; +out vec3 Normal; +out vec2 TexCoord; +out vec4 projCoord; +out vec4 modelCoord; + + + +void main() { + //normalize posiiton and normal + vec4 FinalVertex = vec4(aPos, 1.0); + vec4 FinalNormal = vec4(aNormal, 1.0); + + + //push frag, normal, and texture positions to fragment shader + FragPos = vec3(model * FinalVertex); + Normal = mat3(transpose(inverse(model))) * aNormal; + TexCoord = aTex; + projCoord = projection * view * model * FinalVertex; + modelCoord = FinalVertex; + + //set final position with opengl space + vec4 outVec = projection * view * model * FinalVertex; + // outVec.z = outVec.z - 0.1f; + // outVec.z = -0.9; + gl_Position = outVec; +} diff --git a/assets/Shaders/ui/debug/windowBound.fs b/assets/Shaders/ui/debug/windowBorder/windowBound.fs similarity index 100% rename from assets/Shaders/ui/debug/windowBound.fs rename to assets/Shaders/ui/debug/windowBorder/windowBound.fs diff --git a/assets/Shaders/ui/debug/windowBound.vs b/assets/Shaders/ui/debug/windowBorder/windowBound.vs similarity index 83% rename from assets/Shaders/ui/debug/windowBound.vs rename to assets/Shaders/ui/debug/windowBorder/windowBound.vs index 4faf3431..d17784fb 100644 --- a/assets/Shaders/ui/debug/windowBound.vs +++ b/assets/Shaders/ui/debug/windowBorder/windowBound.vs @@ -11,7 +11,7 @@ void main(){ //0,0 vec2 finalPos = vec2( ((((aPos.x + 1)/2) * mDimension.x + mPosition.x) * 2 - 1), - ((((aPos.y + 1)/2) * mDimension.y + mPosition.y) * 2 - 1) + ((((aPos.y + 1)/2) * mDimension.y + (1 - mDimension.y) - mPosition.y) * 2 - 1) // aPos.y * mDimension.y + (mPosition.y) + (1 - mDimension.y) ); gl_Position = vec4(finalPos.x, finalPos.y, 0.0, 1.0); diff --git a/assets/Shaders/ui/debug/windowContentBorder/windowContentBound.fs b/assets/Shaders/ui/debug/windowContentBorder/windowContentBound.fs new file mode 100644 index 00000000..4d190635 --- /dev/null +++ b/assets/Shaders/ui/debug/windowContentBorder/windowContentBound.fs @@ -0,0 +1,18 @@ +#version 330 core + +//threshold on borders of window where to actually draw outline +#define threshold 0.01 + +out vec4 FragColor; + +uniform vec3 color; + +in vec2 texCoord; + +void main(){ + if(abs(texCoord.x) > 1.0-threshold || abs(texCoord.y) > 1.0-threshold || abs(texCoord.x) < threshold || abs(texCoord.y) < threshold){ + FragColor = vec4(color,1.0); + } else { + FragColor = vec4(0.0); + } +} \ No newline at end of file diff --git a/assets/Shaders/ui/debug/windowContentBorder/windowContentBound.vs b/assets/Shaders/ui/debug/windowContentBorder/windowContentBound.vs new file mode 100644 index 00000000..1ee10b65 --- /dev/null +++ b/assets/Shaders/ui/debug/windowContentBorder/windowContentBound.vs @@ -0,0 +1,26 @@ +#version 330 core +layout (location = 0) in vec3 aPos; +layout (location = 4) in vec2 aTexCoords; + +out vec2 texCoord; + +uniform vec3 mPosition; +uniform vec3 mDimension; +uniform vec3 tPosition; +uniform vec3 tDimension; + +void main(){ + vec2 finalPos = vec2( + ((aPos.x + 1)/2 * mDimension.x + mPosition.x) * 2 - 1, + ((((aPos.y + 1)/2) * mDimension.y + mPosition.y) * 2 - 1) + // aPos.y * mDimension.y + (mPosition.y) + (1 - mDimension.y) + ); + gl_Position = vec4(finalPos.x, finalPos.y, 0.0, 1.0); + + // vec2 finalTex = aTexCoords; + // vec2 finalTex = vec2( + // aTexCoords.x + 0.7, + // aTexCoords.y + // ); + texCoord = aTexCoords; +} diff --git a/assets/Shaders/ui/window/window.fs b/assets/Shaders/ui/window/window.fs new file mode 100644 index 00000000..21c738d3 --- /dev/null +++ b/assets/Shaders/ui/window/window.fs @@ -0,0 +1,14 @@ +#version 330 core +out vec4 FragColor; + +in vec2 TexCoords; + +uniform sampler2D screenTexture; + +void main(){ + vec4 textureColor = texture(screenTexture, TexCoords); + if(textureColor.a < 0.1){ + discard; + } + FragColor = textureColor; +} \ No newline at end of file diff --git a/assets/Shaders/ui/window/window.vs b/assets/Shaders/ui/window/window.vs new file mode 100644 index 00000000..1cb02aba --- /dev/null +++ b/assets/Shaders/ui/window/window.vs @@ -0,0 +1,30 @@ +#version 330 core +layout (location = 0) in vec3 aPos; +layout (location = 4) in vec2 aTexCoords; + +out vec2 TexCoords; + +uniform vec3 mPosition; +uniform vec3 mDimension; +uniform vec3 tPosition; +uniform vec3 tDimension; + +void main(){ + vec2 finalPos = vec2( + ((aPos.x + 1)/2 * mDimension.x + mPosition.x) * 2 - 1, + ((((aPos.y + 1)/2) * mDimension.y + (1 - mDimension.y) - mPosition.y) * 2 - 1) + // aPos.y * mDimension.y + (mPosition.y) + (1 - mDimension.y) + ); + gl_Position = vec4(finalPos.x, finalPos.y, 0.0, 1.0); + + vec2 finalTex = vec2( + aTexCoords.x * tDimension.x + tPosition.x, + 1 - (aTexCoords.y * tDimension.y + tPosition.y) + ); + // vec2 finalTex = aTexCoords; + // vec2 finalTex = vec2( + // aTexCoords.x + 0.7, + // aTexCoords.y + // ); + TexCoords = finalTex; +} diff --git a/assets/Shaders/ui/windowContent/windowContent.fs b/assets/Shaders/ui/windowContent/windowContent.fs new file mode 100644 index 00000000..21c738d3 --- /dev/null +++ b/assets/Shaders/ui/windowContent/windowContent.fs @@ -0,0 +1,14 @@ +#version 330 core +out vec4 FragColor; + +in vec2 TexCoords; + +uniform sampler2D screenTexture; + +void main(){ + vec4 textureColor = texture(screenTexture, TexCoords); + if(textureColor.a < 0.1){ + discard; + } + FragColor = textureColor; +} \ No newline at end of file diff --git a/assets/Shaders/ui/windowContent/windowContent.vs b/assets/Shaders/ui/windowContent/windowContent.vs new file mode 100644 index 00000000..ab9fbf9d --- /dev/null +++ b/assets/Shaders/ui/windowContent/windowContent.vs @@ -0,0 +1,30 @@ +#version 330 core +layout (location = 0) in vec3 aPos; +layout (location = 4) in vec2 aTexCoords; + +out vec2 TexCoords; + +uniform vec3 mPosition; +uniform vec3 mDimension; +uniform vec3 tPosition; +uniform vec3 tDimension; + +void main(){ + vec2 finalPos = vec2( + ((aPos.x + 1)/2 * mDimension.x + mPosition.x) * 2 - 1, + ((((aPos.y + 1)/2) * mDimension.y + mPosition.y) * 2 - 1) + // aPos.y * mDimension.y + (mPosition.y) + (1 - mDimension.y) + ); + gl_Position = vec4(finalPos.x, finalPos.y, 0.0, 1.0); + + vec2 finalTex = vec2( + aTexCoords.x * tDimension.x + tPosition.x, + 1 - (aTexCoords.y * tDimension.y + tPosition.y) + ); + // vec2 finalTex = aTexCoords; + // vec2 finalTex = vec2( + // aTexCoords.x + 0.7, + // aTexCoords.y + // ); + TexCoords = finalTex; +} diff --git a/pom.xml b/pom.xml index ac347d79..800f02c8 100644 --- a/pom.xml +++ b/pom.xml @@ -152,12 +152,41 @@ 3.36.0.3 + + junit junit 4.12 + + + + + + org.graalvm.js + js + 22.1.0.1 + + + + org.graalvm.js + js-scriptengine + 22.1.0.1 + + + + + + + com.code-disaster.steamworks4j + steamworks4j + 1.9.0 + + + + diff --git a/src/main/java/electrosphere/controls/ControlHandler.java b/src/main/java/electrosphere/controls/ControlHandler.java index 0535f159..4717cda2 100644 --- a/src/main/java/electrosphere/controls/ControlHandler.java +++ b/src/main/java/electrosphere/controls/ControlHandler.java @@ -1,36 +1,66 @@ package electrosphere.controls; -import electrosphere.audio.AudioUtils; -import electrosphere.controls.Control.ControlMethod; -import electrosphere.controls.Control.ControlType; -import electrosphere.entity.Entity; -import electrosphere.entity.EntityDataStrings; -import electrosphere.entity.types.creature.CreatureUtils; -import electrosphere.entity.state.AttackTree; -import electrosphere.entity.state.equip.EquipState; -import electrosphere.entity.state.inventory.InventoryUtils; -import electrosphere.entity.state.inventory.UnrelationalInventoryState; -import electrosphere.entity.state.ironsight.IronSightTree; -import electrosphere.entity.state.movement.GroundMovementTree; -import electrosphere.entity.state.movement.JumpTree; -import electrosphere.entity.state.movement.GroundMovementTree.MovementRelativeFacing; -import electrosphere.entity.state.movement.GroundMovementTree.MovementTreeState; -import electrosphere.entity.state.movement.SprintTree; -import electrosphere.entity.types.camera.CameraEntityUtils; -import electrosphere.game.client.targeting.crosshair.Crosshair; -import electrosphere.logger.LoggerInterface; -import electrosphere.main.Globals; -import electrosphere.main.Main; -import electrosphere.menu.WindowStrings; -import electrosphere.menu.WindowUtils; -import electrosphere.menu.MenuGenerators; -import electrosphere.menu.MenuGeneratorsInventory; -import electrosphere.renderer.ui.Window; -import electrosphere.renderer.ui.events.ClickEvent; -import electrosphere.renderer.ui.events.KeyboardEvent; -import electrosphere.renderer.ui.events.MenuEvent; -import electrosphere.renderer.ui.events.MouseEvent; -import electrosphere.renderer.ui.events.MenuEvent.MenuEventType; +import static org.lwjgl.glfw.GLFW.GLFW_CURSOR; +import static org.lwjgl.glfw.GLFW.GLFW_CURSOR_DISABLED; +import static org.lwjgl.glfw.GLFW.GLFW_CURSOR_NORMAL; +import static org.lwjgl.glfw.GLFW.GLFW_KEY_0; +import static org.lwjgl.glfw.GLFW.GLFW_KEY_1; +import static org.lwjgl.glfw.GLFW.GLFW_KEY_2; +import static org.lwjgl.glfw.GLFW.GLFW_KEY_3; +import static org.lwjgl.glfw.GLFW.GLFW_KEY_4; +import static org.lwjgl.glfw.GLFW.GLFW_KEY_5; +import static org.lwjgl.glfw.GLFW.GLFW_KEY_6; +import static org.lwjgl.glfw.GLFW.GLFW_KEY_7; +import static org.lwjgl.glfw.GLFW.GLFW_KEY_8; +import static org.lwjgl.glfw.GLFW.GLFW_KEY_9; +import static org.lwjgl.glfw.GLFW.GLFW_KEY_A; +import static org.lwjgl.glfw.GLFW.GLFW_KEY_B; +import static org.lwjgl.glfw.GLFW.GLFW_KEY_BACKSPACE; +import static org.lwjgl.glfw.GLFW.GLFW_KEY_C; +import static org.lwjgl.glfw.GLFW.GLFW_KEY_CAPS_LOCK; +import static org.lwjgl.glfw.GLFW.GLFW_KEY_D; +import static org.lwjgl.glfw.GLFW.GLFW_KEY_DOWN; +import static org.lwjgl.glfw.GLFW.GLFW_KEY_E; +import static org.lwjgl.glfw.GLFW.GLFW_KEY_ENTER; +import static org.lwjgl.glfw.GLFW.GLFW_KEY_ESCAPE; +import static org.lwjgl.glfw.GLFW.GLFW_KEY_F; +import static org.lwjgl.glfw.GLFW.GLFW_KEY_F24; +import static org.lwjgl.glfw.GLFW.GLFW_KEY_G; +import static org.lwjgl.glfw.GLFW.GLFW_KEY_H; +import static org.lwjgl.glfw.GLFW.GLFW_KEY_I; +import static org.lwjgl.glfw.GLFW.GLFW_KEY_J; +import static org.lwjgl.glfw.GLFW.GLFW_KEY_K; +import static org.lwjgl.glfw.GLFW.GLFW_KEY_L; +import static org.lwjgl.glfw.GLFW.GLFW_KEY_LEFT; +import static org.lwjgl.glfw.GLFW.GLFW_KEY_LEFT_CONTROL; +import static org.lwjgl.glfw.GLFW.GLFW_KEY_LEFT_SHIFT; +import static org.lwjgl.glfw.GLFW.GLFW_KEY_M; +import static org.lwjgl.glfw.GLFW.GLFW_KEY_N; +import static org.lwjgl.glfw.GLFW.GLFW_KEY_O; +import static org.lwjgl.glfw.GLFW.GLFW_KEY_P; +import static org.lwjgl.glfw.GLFW.GLFW_KEY_PERIOD; +import static org.lwjgl.glfw.GLFW.GLFW_KEY_Q; +import static org.lwjgl.glfw.GLFW.GLFW_KEY_R; +import static org.lwjgl.glfw.GLFW.GLFW_KEY_RIGHT; +import static org.lwjgl.glfw.GLFW.GLFW_KEY_S; +import static org.lwjgl.glfw.GLFW.GLFW_KEY_SLASH; +import static org.lwjgl.glfw.GLFW.GLFW_KEY_SPACE; +import static org.lwjgl.glfw.GLFW.GLFW_KEY_T; +import static org.lwjgl.glfw.GLFW.GLFW_KEY_U; +import static org.lwjgl.glfw.GLFW.GLFW_KEY_UP; +import static org.lwjgl.glfw.GLFW.GLFW_KEY_V; +import static org.lwjgl.glfw.GLFW.GLFW_KEY_W; +import static org.lwjgl.glfw.GLFW.GLFW_KEY_X; +import static org.lwjgl.glfw.GLFW.GLFW_KEY_Y; +import static org.lwjgl.glfw.GLFW.GLFW_KEY_Z; +import static org.lwjgl.glfw.GLFW.GLFW_MOUSE_BUTTON_1; +import static org.lwjgl.glfw.GLFW.GLFW_MOUSE_BUTTON_2; +import static org.lwjgl.glfw.GLFW.GLFW_MOUSE_BUTTON_LEFT; +import static org.lwjgl.glfw.GLFW.GLFW_MOUSE_BUTTON_RIGHT; +import static org.lwjgl.glfw.GLFW.glfwGetCursorPos; +import static org.lwjgl.glfw.GLFW.glfwMakeContextCurrent; +import static org.lwjgl.glfw.GLFW.glfwMaximizeWindow; +import static org.lwjgl.glfw.GLFW.glfwSetInputMode; import java.util.HashMap; import java.util.LinkedList; @@ -41,9 +71,37 @@ import org.joml.Vector3d; import org.joml.Vector3f; import org.lwjgl.glfw.GLFW; -import static org.lwjgl.glfw.GLFW.*; -import static org.lwjgl.glfw.GLFW.glfwGetCursorPos; -import static org.lwjgl.glfw.GLFW.glfwSetInputMode; +import electrosphere.audio.AudioUtils; +import electrosphere.controls.Control.ControlMethod; +import electrosphere.controls.Control.ControlType; +import electrosphere.entity.Entity; +import electrosphere.entity.state.AttackTree; +import electrosphere.entity.state.equip.EquipState; +import electrosphere.entity.state.inventory.InventoryUtils; +import electrosphere.entity.state.inventory.UnrelationalInventoryState; +import electrosphere.entity.state.ironsight.IronSightTree; +import electrosphere.entity.state.movement.GroundMovementTree; +import electrosphere.entity.state.movement.GroundMovementTree.MovementRelativeFacing; +import electrosphere.entity.state.movement.GroundMovementTree.MovementTreeState; +import electrosphere.entity.state.movement.JumpTree; +import electrosphere.entity.state.movement.SprintTree; +import electrosphere.entity.types.camera.CameraEntityUtils; +import electrosphere.entity.types.creature.CreatureUtils; +import electrosphere.game.client.targeting.crosshair.Crosshair; +import electrosphere.logger.LoggerInterface; +import electrosphere.main.Globals; +import electrosphere.main.Main; +import electrosphere.menu.MenuGenerators; +import electrosphere.menu.MenuGeneratorsDebug; +import electrosphere.menu.MenuGeneratorsInventory; +import electrosphere.menu.WindowStrings; +import electrosphere.menu.WindowUtils; +import electrosphere.renderer.ui.Window; +import electrosphere.renderer.ui.events.ClickEvent; +import electrosphere.renderer.ui.events.KeyboardEvent; +import electrosphere.renderer.ui.events.MenuEvent; +import electrosphere.renderer.ui.events.MenuEvent.MenuEventType; +import electrosphere.renderer.ui.events.MouseEvent; /** * @@ -126,6 +184,7 @@ public class ControlHandler { public static final String INPUT_CODE_INVENTORY_ITEM_DRAG = "inventoryDrag"; public static final String DEBUG_FRAMESTEP = "framestep"; + public static final String DEBUG_OPEN_DEBUG_MENU = "openDebugMenu"; public static enum ControlsState { @@ -164,6 +223,7 @@ public class ControlHandler { List menuNavigationControlList = new LinkedList(); List typingControlList = new LinkedList(); List inventoryControlList = new LinkedList(); + List alwaysOnDebugControlList = new LinkedList(); ControlHandler(){ controls = new HashMap(); @@ -277,6 +337,7 @@ public class ControlHandler { Debug controls */ handler.addControl(DATA_STRING_INPUT_CODE_DEBUG_SPAWN_ITEM, new Control(ControlType.KEY,GLFW_KEY_Q)); + handler.addControl(DEBUG_OPEN_DEBUG_MENU, new Control(ControlType.KEY, GLFW_KEY_O)); /* return @@ -295,6 +356,7 @@ public class ControlHandler { case MAIN_GAME: runHandlers(mainGameControlList); runHandlers(mainGameDebugControlList); + runHandlers(alwaysOnDebugControlList); break; @@ -309,20 +371,24 @@ public class ControlHandler { Typing.. */ runHandlers(typingControlList); + runHandlers(alwaysOnDebugControlList); break; case IN_GAME_MAIN_MENU: runHandlers(menuNavigationControlList); runHandlers(typingControlList); + runHandlers(alwaysOnDebugControlList); // pollMenuNavigationControls(); break; case INVENTORY: runHandlers(inventoryControlList); runHandlers(menuNavigationControlList); + runHandlers(alwaysOnDebugControlList); break; case NO_INPUT: + runHandlers(alwaysOnDebugControlList); break; } @@ -335,6 +401,7 @@ public class ControlHandler { setMenuNavigationControls(); setTypingControls(); setInventoryControls(); + setAlwaysOnDebugControls(); } void setMainGameControls(){ @@ -803,6 +870,24 @@ public class ControlHandler { }}); // RenderingEngine.incrementOutputFramebuffer(); } + + void setAlwaysOnDebugControls(){ + alwaysOnDebugControlList.add(controls.get(DEBUG_OPEN_DEBUG_MENU)); + controls.get(DEBUG_OPEN_DEBUG_MENU).setOnPress(new ControlMethod(){public void execute(){ + System.out.println("open debug menu"); + // Window mainMenuWindow = new Window(0, 0, Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT); + Window mainMenuInGame = MenuGeneratorsDebug.createTopLevelDebugMenu(); + // mainMenuWindow.addChild(mainMenuInGame); + Globals.elementManager.registerWindow(WindowStrings.WINDOW_DEBUG, mainMenuInGame); + WindowUtils.recursiveSetVisible(Globals.elementManager.getWindow(WindowStrings.WINDOW_DEBUG), true); + Globals.elementManager.focusFirstElement(); + Globals.controlHandler.setHandlerState(ControlsState.IN_GAME_MAIN_MENU); + Globals.controlHandler.showMouse(); + //play sound effect + AudioUtils.playAudio("/Audio/openMenu.ogg"); + }}); + controls.get(DEBUG_OPEN_DEBUG_MENU).setRepeatTimeout(0.5f * Main.targetFrameRate); + } void setMenuNavigationControls(){ menuNavigationControlList.add(controls.get(DATA_STRING_INPUT_CODE_MENU_NAVIGATE_FORWARD)); diff --git a/src/main/java/electrosphere/engine/LoadingThread.java b/src/main/java/electrosphere/engine/LoadingThread.java index ed8c9d54..a31775b5 100644 --- a/src/main/java/electrosphere/engine/LoadingThread.java +++ b/src/main/java/electrosphere/engine/LoadingThread.java @@ -14,6 +14,7 @@ import org.joml.Vector3f; import electrosphere.auth.AuthenticationManager; import electrosphere.controls.ControlHandler; import electrosphere.entity.Entity; +import electrosphere.entity.EntityDataStrings; import electrosphere.entity.EntityUtils; import electrosphere.entity.state.movement.ApplyRotationTree; import electrosphere.entity.types.camera.CameraEntityUtils; @@ -26,7 +27,6 @@ import electrosphere.game.client.targeting.crosshair.Crosshair; import electrosphere.game.client.terrain.manager.ClientTerrainManager; import electrosphere.game.collision.CommonWorldData; import electrosphere.game.data.creature.type.CreatureType; -import electrosphere.game.data.creature.type.visualattribute.AttributeVariant; import electrosphere.game.data.creature.type.visualattribute.VisualAttribute; import electrosphere.game.server.datacell.DataCellManager; import electrosphere.game.server.saves.SaveUtils; @@ -44,12 +44,10 @@ import electrosphere.menu.WindowStrings; import electrosphere.menu.WindowUtils; import electrosphere.net.NetUtils; import electrosphere.net.client.ClientNetworking; -import electrosphere.net.parser.net.message.CharacterMessage; import electrosphere.net.server.Server; import electrosphere.net.server.player.Player; import electrosphere.renderer.ui.Window; import electrosphere.util.FileUtils; -import electrosphere.util.Utilities; /** * @@ -761,6 +759,13 @@ public class LoadingThread extends Thread { // myCube.putData(EntityDataStrings.DRAW_TRANSPARENT_PASS, true); // EntityUtils.getPosition(myCube).set(3,1,3); + //work on smoke shader + Entity myCube = EntityUtils.spawnDrawableEntity("Models/unitcube.fbx"); + EntityUtils.getActor(myCube).maskShader("Cube", "Shaders/smoke1/smoke1.vs", "Shaders/smoke1/smoke1.fs"); + Globals.assetManager.addShaderToQueue("Shaders/smoke1/smoke1.vs", "Shaders/smoke1/smoke1.fs"); + myCube.putData(EntityDataStrings.DRAW_TRANSPARENT_PASS, true); + EntityUtils.getPosition(myCube).set(3,1,3); + // Globals.entityManager.registerBehaviorTree(new BehaviorTree() { // int i = 0; // public void simulate(){ diff --git a/src/main/java/electrosphere/engine/assetmanager/AssetLoadingThread.java b/src/main/java/electrosphere/engine/assetmanager/AssetLoadingThread.java new file mode 100644 index 00000000..4da7404d --- /dev/null +++ b/src/main/java/electrosphere/engine/assetmanager/AssetLoadingThread.java @@ -0,0 +1,42 @@ +package electrosphere.engine.assetmanager; + +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.CopyOnWriteArrayList; +import java.util.concurrent.Semaphore; + +public class AssetLoadingThread implements Runnable { + + List pathQueueList = new CopyOnWriteArrayList(); + + Map pathContentMap = new ConcurrentHashMap(); + + Semaphore pathTransitionLock = new Semaphore(1); + + @Override + public void run() { + boolean running = true; + + while(running){ + + } + } + + public boolean containsPath(String path){ + return pathContentMap.containsKey(path); + } + + public String getContent(String path){ + return pathContentMap.get(path); + } + + public void queuePath(String path){ + pathTransitionLock.acquireUninterruptibly(); + if(!pathContentMap.containsKey(path) && !pathQueueList.contains(path)){ + pathQueueList.add(path); + } + pathTransitionLock.release(); + } + +} diff --git a/src/main/java/electrosphere/entity/state/gravity/GravityTree.java b/src/main/java/electrosphere/entity/state/gravity/GravityTree.java index e381d1d2..b239ac4f 100644 --- a/src/main/java/electrosphere/entity/state/gravity/GravityTree.java +++ b/src/main/java/electrosphere/entity/state/gravity/GravityTree.java @@ -1,5 +1,12 @@ package electrosphere.entity.state.gravity; +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; + +import org.joml.Quaternionf; +import org.joml.Vector3d; +import org.joml.Vector3f; + import electrosphere.collision.dispatch.CollisionObject; import electrosphere.entity.Entity; import electrosphere.entity.EntityUtils; @@ -7,18 +14,9 @@ import electrosphere.entity.state.collidable.CollidableTree; import electrosphere.entity.state.collidable.Impulse; import electrosphere.entity.state.movement.FallTree; import electrosphere.entity.state.movement.JumpTree; -import electrosphere.entity.types.creature.CreatureUtils; -import electrosphere.game.collision.PhysicsUtils; import electrosphere.game.collision.collidable.Collidable; import electrosphere.main.Globals; import electrosphere.net.parser.net.message.EntityMessage; -import electrosphere.renderer.actor.Actor; - -import java.util.List; -import java.util.concurrent.CopyOnWriteArrayList; -import org.joml.Quaternionf; -import org.joml.Vector3d; -import org.joml.Vector3f; /** * diff --git a/src/main/java/electrosphere/game/config/UserSettings.java b/src/main/java/electrosphere/game/config/UserSettings.java index 13781e6e..76fc0bcd 100644 --- a/src/main/java/electrosphere/game/config/UserSettings.java +++ b/src/main/java/electrosphere/game/config/UserSettings.java @@ -35,6 +35,10 @@ public class UserSettings { int graphicsPerformanceLODChunkRadius; boolean graphicsPerformanceEnableVSync; boolean graphicsPerformanceDrawShadows; + boolean graphicsPerformanceOIT; + //resolution + int renderResolutionX; + int renderResolutionY; //debug boolean graphicsDebugDrawCollisionSpheres; boolean graphicsDebugDrawPhysicsObjects; @@ -105,6 +109,18 @@ public class UserSettings { public boolean displayFullscreen(){ return displayFullscreen; } + + public int getRenderResolutionX(){ + return renderResolutionX; + } + + public int getRenderResolutionY(){ + return renderResolutionY; + } + + public boolean getGraphicsPerformanceOIT(){ + return graphicsPerformanceOIT; + } public void setGraphicsDebugDrawCollisionSpheres(boolean draw){ @@ -162,6 +178,9 @@ public class UserSettings { rVal.graphicsFOV = 90.0f; rVal.graphicsPerformanceDrawShadows = true; rVal.graphicsPerformanceEnableVSync = true; + rVal.graphicsPerformanceOIT = true; + rVal.renderResolutionX = 1920; + rVal.renderResolutionY = 1080; return rVal; } diff --git a/src/main/java/electrosphere/main/Globals.java b/src/main/java/electrosphere/main/Globals.java index 9f2ef5a3..ea21caf9 100644 --- a/src/main/java/electrosphere/main/Globals.java +++ b/src/main/java/electrosphere/main/Globals.java @@ -404,6 +404,7 @@ public class Globals { assetManager.addModelPathToQueue("Models/unitplane.fbx"); assetManager.addModelPathToQueue("Models/unitcube.fbx"); imagePlaneModelID = assetManager.registerModel(RenderUtils.createPlaneModel("Shaders/plane/plane.vs", "Shaders/plane/plane.fs")); + assetManager.addShaderToQueue("Shaders/plane/plane.vs", null, "Shaders/plane/plane.fs"); solidPlaneModelID = assetManager.registerModel(RenderUtils.createInWindowPanel("Shaders/ui/plainBox/plainBox.vs", "Shaders/ui/plainBox/plainBox.fs")); //image panel @@ -420,9 +421,12 @@ public class Globals { // //in game ui stuff // elementManager.registerWindow(WindowStrings.WINDOW_MENU_MAIN,WidgetUtils.createInGameMainMenuButton()); - Globals.assetManager.addShaderToQueue("Shaders/ui/debug/windowBound.vs", "Shaders/ui/debug/windowBound.fs"); - + //window content shader + assetManager.addShaderToQueue("Shaders/ui/windowContent/windowContent.vs", null, "Shaders/ui/windowContent/windowContent.fs"); + //debug shaders + assetManager.addShaderToQueue("Shaders/ui/debug/windowBorder/windowBound.vs", null, "Shaders/ui/debug/windowBorder/windowBound.fs"); + assetManager.addShaderToQueue("Shaders/ui/debug/windowContentBorder/windowContentBound.vs", null, "Shaders/ui/debug/windowContentBorder/windowContentBound.fs"); //as these assets are required for the renderer to work, we go ahead and //load them into memory now. The loading time penalty is worth it I think. diff --git a/src/main/java/electrosphere/main/Main.java b/src/main/java/electrosphere/main/Main.java index ad6d13ad..9a221190 100644 --- a/src/main/java/electrosphere/main/Main.java +++ b/src/main/java/electrosphere/main/Main.java @@ -1,64 +1,19 @@ package electrosphere.main; -import com.google.gson.Gson; +import static org.lwjgl.glfw.GLFW.glfwGetTime; +import static org.lwjgl.glfw.GLFW.glfwTerminate; +import static org.lwjgl.glfw.GLFW.glfwWindowShouldClose; + +import java.util.concurrent.TimeUnit; + import electrosphere.audio.AudioEngine; -import electrosphere.audio.AudioSource; -import electrosphere.audio.AudioUtils; -import electrosphere.auth.AuthenticationManager; import electrosphere.controls.ControlHandler; -import electrosphere.entity.types.creature.CreatureUtils; -import electrosphere.renderer.Material; -import electrosphere.renderer.Model; -import electrosphere.renderer.RenderUtils; -import electrosphere.entity.Entity; -import electrosphere.entity.EntityUtils; -import electrosphere.entity.state.movement.GroundMovementTree; -import electrosphere.entity.types.hitbox.HitboxUtils; -import electrosphere.entity.types.item.ItemUtils; -import electrosphere.entity.types.attach.AttachUtils; -import electrosphere.entity.types.camera.CameraEntityUtils; import electrosphere.engine.LoadingThread; import electrosphere.engine.cli.CLIParser; import electrosphere.game.client.ClientFunctions; -import electrosphere.game.client.targeting.crosshair.Crosshair; import electrosphere.game.config.UserSettings; -import electrosphere.game.data.creature.type.Animation; -import electrosphere.game.server.saves.SaveUtils; -import electrosphere.game.server.terrain.manager.ServerTerrainManager; -import electrosphere.game.server.world.MacroData; -import electrosphere.game.server.world.ServerWorldData; -import electrosphere.game.simulation.MacroSimulation; -import electrosphere.game.simulation.MicroSimulation; import electrosphere.logger.LoggerInterface; import electrosphere.renderer.RenderingEngine; -import electrosphere.util.FileUtils; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.Random; -import java.util.concurrent.TimeUnit; -import org.joml.Matrix4f; -import org.joml.Quaterniond; -import org.joml.Quaternionf; -import org.joml.Vector3f; -import org.lwjgl.glfw.*; -import static org.lwjgl.glfw.GLFW.*; -import electrosphere.util.ModelLoader; -import electrosphere.util.worldviewer.TerrainViewer; -import electrosphere.util.Utilities; -import java.io.File; -import java.io.IOException; -import java.nio.charset.Charset; -import java.nio.file.Files; -import java.nio.file.StandardOpenOption; -import java.security.Provider; -import java.security.Security; -import java.util.Scanner; -import java.util.logging.Level; -import java.util.logging.Logger; - -import javax.crypto.Cipher; - -import org.joml.Vector3d; diff --git a/src/main/java/electrosphere/menu/MenuGenerators.java b/src/main/java/electrosphere/menu/MenuGenerators.java index d438e8b8..7dab49f8 100644 --- a/src/main/java/electrosphere/menu/MenuGenerators.java +++ b/src/main/java/electrosphere/menu/MenuGenerators.java @@ -1,19 +1,17 @@ package electrosphere.menu; +import java.util.List; + +import org.joml.Vector3f; + import electrosphere.auth.AuthenticationManager; import electrosphere.controls.ControlHandler.ControlsState; import electrosphere.engine.LoadingThread; import electrosphere.entity.Entity; import electrosphere.entity.EntityDataStrings; import electrosphere.entity.EntityUtils; -import electrosphere.entity.state.equip.EquipState; -import electrosphere.entity.state.gravity.GravityUtils; -import electrosphere.entity.state.gravity.GravityTree.GravityTreeState; -import electrosphere.entity.state.inventory.InventoryUtils; -import electrosphere.entity.state.inventory.RelationalInventoryState; -import electrosphere.entity.state.inventory.UnrelationalInventoryState; +import electrosphere.entity.types.camera.CameraEntityUtils; import electrosphere.entity.types.creature.CreatureUtils; -import electrosphere.entity.types.item.ItemUtils; import electrosphere.game.data.creature.type.CreatureType; import electrosphere.game.data.creature.type.visualattribute.VisualAttribute; import electrosphere.game.server.saves.SaveUtils; @@ -24,17 +22,13 @@ import electrosphere.renderer.Model; import electrosphere.renderer.RenderingEngine; import electrosphere.renderer.actor.Actor; import electrosphere.renderer.actor.ActorStaticMorph; +import electrosphere.renderer.actor.ActorUtils; import electrosphere.renderer.ui.ClickableElement; -import electrosphere.renderer.ui.DrawableElement; import electrosphere.renderer.ui.Element; -import electrosphere.renderer.ui.FocusableElement; -import electrosphere.renderer.ui.WidgetUtils; -import electrosphere.renderer.ui.Window; -import electrosphere.renderer.ui.ClickableElement.ClickEventCallback; -import electrosphere.renderer.ui.DraggableElement.DragEventCallback; -import electrosphere.renderer.ui.FocusableElement.FocusEventCallback; import electrosphere.renderer.ui.NavigableElement.NavigationEventCallback; import electrosphere.renderer.ui.ValueElement.ValueChangeEventCallback; +import electrosphere.renderer.ui.Window; +import electrosphere.renderer.ui.elements.ActorPanel; import electrosphere.renderer.ui.elements.Button; import electrosphere.renderer.ui.elements.Div; import electrosphere.renderer.ui.elements.ImagePanel; @@ -43,18 +37,10 @@ import electrosphere.renderer.ui.elements.ScrollableContainer; import electrosphere.renderer.ui.elements.Slider; import electrosphere.renderer.ui.elements.TextInput; import electrosphere.renderer.ui.events.ClickEvent; -import electrosphere.renderer.ui.events.DragEvent; -import electrosphere.renderer.ui.events.FocusEvent; import electrosphere.renderer.ui.events.NavigationEvent; import electrosphere.renderer.ui.events.ValueChangeEvent; import electrosphere.renderer.ui.form.FormElement; -import java.util.List; - -import javax.management.relation.Relation; - -import org.joml.Vector3f; - /** * * @author amaterasu @@ -464,6 +450,12 @@ public class MenuGenerators { Slider slider = new Slider(0, 0, 500, 100, new Vector3f(0.1f,0.1f,0.1f), new Vector3f(1,0,0)); rVal.addChild(slider); + ActorPanel actorPanel = new ActorPanel(500, 100, 500, 500, ActorUtils.createActorFromModelPath("Models/deer1.fbx")); + if(Globals.playerCamera == null){ + Globals.playerCamera = CameraEntityUtils.spawnBasicCameraEntity(new Vector3f(0,0,0), new Vector3f(-1,0,0)); + } + rVal.addChild(actorPanel); + // slider = new Slider(0, 100, 500, 100, new Vector3f(0.1f,0.1f,0.1f), new Vector3f(1,0,0)); // rVal.addChild(slider); diff --git a/src/main/java/electrosphere/menu/MenuGeneratorsDebug.java b/src/main/java/electrosphere/menu/MenuGeneratorsDebug.java new file mode 100644 index 00000000..3d8be8c4 --- /dev/null +++ b/src/main/java/electrosphere/menu/MenuGeneratorsDebug.java @@ -0,0 +1,89 @@ +package electrosphere.menu; + +import java.util.LinkedList; +import java.util.List; + +import electrosphere.main.Globals; +import electrosphere.renderer.debug.DebugRendering; +import electrosphere.renderer.ui.ClickableElement; +import electrosphere.renderer.ui.ContainerElement; +import electrosphere.renderer.ui.Element; +import electrosphere.renderer.ui.WidgetUtils; +import electrosphere.renderer.ui.Window; +import electrosphere.renderer.ui.elements.Label; +import electrosphere.renderer.ui.elements.ScrollableContainer; +import electrosphere.renderer.ui.events.ClickEvent; + +/** + * + * @author amaterasu + */ +public class MenuGeneratorsDebug { + + static final int X_OFFSET = 1000; + + public static Window createTopLevelDebugMenu(){ + Window rVal = new Window(X_OFFSET,100,800,800); + + //label (title) + Label titleLabel = new Label(100,50,1.0f); + titleLabel.setText("DEBUG"); + rVal.addChild(titleLabel); + + //show ui tree + rVal.addChild(WidgetUtils.createLabelButton("Lst UI Elements",100,150,1.0f,new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){ + WindowUtils.replaceWindowContents(WindowStrings.WINDOW_DEBUG, MenuGeneratorsDebug.createListUIElements()); + return false; + }})); + + //show ui tree + rVal.addChild(WidgetUtils.createLabelButton("Debug UI",100,250,1.0f,new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){ + WindowUtils.replaceWindowContents(WindowStrings.WINDOW_DEBUG, MenuGeneratorsDebug.createDebugUIMenu()); + return false; + }})); + + + + return rVal; + } + + public static Element createDebugUIMenu(){ + ScrollableContainer rVal = new ScrollableContainer(0, 0, 800, 800); + rVal.addChild(WidgetUtils.createLabelButton("Toggle UI Outline",100,150,1.0f,new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){ + DebugRendering.toggleOutlineMask(); + return false; + }})); + return rVal; + } + + public static Element createListUIElements(){ + ScrollableContainer rVal = new ScrollableContainer(0, 0, 800, 800); + int verticalOffset = 0; + int horizontalOffset = 0; + List elementsToAdd = new LinkedList(); + for(Element window : Globals.elementManager.getWindowList()){ + verticalOffset = verticalOffset + recursivelyAppendElementTree(elementsToAdd, verticalOffset, horizontalOffset, rVal); + } + for(Element toAdd : elementsToAdd){ + rVal.addChild(toAdd); + } + return rVal; + } + + static int recursivelyAppendElementTree(List toAddList, int verticalOffset, int horizontalOffset, Element child){ + Label currentWindowLabel = new Label(100 + horizontalOffset * 25,100 + verticalOffset * 50,0.5f); + currentWindowLabel.setText(child.toString()); + toAddList.add(currentWindowLabel); + if(child instanceof ContainerElement){ + int cummulativeOffset = 1; + ContainerElement childCast = (ContainerElement) child; + for(Element childOfChild : childCast.getChildren()){ + cummulativeOffset = cummulativeOffset + recursivelyAppendElementTree(toAddList, verticalOffset + cummulativeOffset, horizontalOffset + 1, childOfChild); + } + return cummulativeOffset; + } else { + return verticalOffset + 1; + } + } + +} diff --git a/src/main/java/electrosphere/menu/WindowStrings.java b/src/main/java/electrosphere/menu/WindowStrings.java index 8078ccaf..2f65f126 100644 --- a/src/main/java/electrosphere/menu/WindowStrings.java +++ b/src/main/java/electrosphere/menu/WindowStrings.java @@ -10,5 +10,6 @@ public class WindowStrings { public static final String WINDDOW_ITEM_DROP = "itemDrop"; public static final String WINDOW_ITEM_DRAG_CONTAINER = "itemDragContainer"; public static final String WINDOW_CHARACTER = "windowCharacter"; + public static final String WINDOW_DEBUG = "windowDebug"; } diff --git a/src/main/java/electrosphere/renderer/RenderingEngine.java b/src/main/java/electrosphere/renderer/RenderingEngine.java index ff024dd1..143105eb 100644 --- a/src/main/java/electrosphere/renderer/RenderingEngine.java +++ b/src/main/java/electrosphere/renderer/RenderingEngine.java @@ -269,9 +269,9 @@ public class RenderingEngine { // screenTextureShaders = ShaderProgram.loadSpecificShader("/Shaders/screentexture/drawDepthBuffer/drawDepthBuffer.vs", "/Shaders/screentexture/drawDepthBuffer/drawDepthBuffer.fs"); //generate framebuffers - screenTextureColor = FramebufferUtils.generateScreenTextureColor(Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT); - screenTextureDepth = FramebufferUtils.generateScreenTextureDepth(Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT); - screenFramebuffer = FramebufferUtils.generateScreenTextureFramebuffer(Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT, screenTextureColor, screenTextureDepth); + screenTextureColor = FramebufferUtils.generateScreenTextureColor(Globals.userSettings.getRenderResolutionX(), Globals.userSettings.getRenderResolutionY()); + screenTextureDepth = FramebufferUtils.generateScreenTextureDepth(Globals.userSettings.getRenderResolutionX(), Globals.userSettings.getRenderResolutionY()); + screenFramebuffer = FramebufferUtils.generateScreenTextureFramebuffer(Globals.userSettings.getRenderResolutionX(), Globals.userSettings.getRenderResolutionY(), screenTextureColor, screenTextureDepth); glBindFramebuffer(GL_FRAMEBUFFER, GL_DEFAULT_FRAMEBUFFER); glBindRenderbuffer(GL_RENDERBUFFER, GL_DEFAULT_RENDERBUFFER); @@ -293,10 +293,10 @@ public class RenderingEngine { //create volume depth framebuffer/shader for volumetric rendering // volumeDepthShaderProgram = ShaderProgram.loadSpecificShader("/Shaders/volumeBuffer/volumetric.vs", "/Shaders/volumeBuffer/volumetric.fs"); - volumeDepthBackfaceTexture = FramebufferUtils.generateDepthBufferTexture(Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT); - volumeDepthBackfaceFramebuffer = FramebufferUtils.generateDepthBuffer(Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT, volumeDepthBackfaceTexture); - volumeDepthFrontfaceTexture = FramebufferUtils.generateDepthBufferTexture(Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT); - volumeDepthFrontfaceFramebuffer = FramebufferUtils.generateDepthBuffer(Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT, volumeDepthFrontfaceTexture); + volumeDepthBackfaceTexture = FramebufferUtils.generateDepthBufferTexture(Globals.userSettings.getRenderResolutionX(), Globals.userSettings.getRenderResolutionY()); + volumeDepthBackfaceFramebuffer = FramebufferUtils.generateDepthBuffer(Globals.userSettings.getRenderResolutionX(), Globals.userSettings.getRenderResolutionY(), volumeDepthBackfaceTexture); + volumeDepthFrontfaceTexture = FramebufferUtils.generateDepthBufferTexture(Globals.userSettings.getRenderResolutionX(), Globals.userSettings.getRenderResolutionY()); + volumeDepthFrontfaceFramebuffer = FramebufferUtils.generateDepthBuffer(Globals.userSettings.getRenderResolutionX(), Globals.userSettings.getRenderResolutionY(), volumeDepthFrontfaceTexture); // //Game normals @@ -306,19 +306,19 @@ public class RenderingEngine { static Framebuffer gameImageNormalsFramebuffer; static ShaderProgram renderNormalsShader; */ - gameImageNormalsTexture = FramebufferUtils.generateScreenTextureColor(Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT); - Texture gameImageNormalsDepthTexture = FramebufferUtils.generateScreenTextureDepth(Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT); - gameImageNormalsFramebuffer = FramebufferUtils.generateScreenTextureFramebuffer(Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT, gameImageNormalsTexture, gameImageNormalsDepthTexture); + gameImageNormalsTexture = FramebufferUtils.generateScreenTextureColor(Globals.userSettings.getRenderResolutionX(), Globals.userSettings.getRenderResolutionY()); + Texture gameImageNormalsDepthTexture = FramebufferUtils.generateScreenTextureDepth(Globals.userSettings.getRenderResolutionX(), Globals.userSettings.getRenderResolutionY()); + gameImageNormalsFramebuffer = FramebufferUtils.generateScreenTextureFramebuffer(Globals.userSettings.getRenderResolutionX(), Globals.userSettings.getRenderResolutionY(), gameImageNormalsTexture, gameImageNormalsDepthTexture); renderNormalsShader = ShaderProgram.loadSpecificShader("Shaders/anime/renderNormals.vs", "Shaders/anime/renderNormals.fs"); // //Transparency framebuffers // transparencyAccumulatorClear = new float[]{0.0f, 0.0f, 0.0f, 0.0f}; - transparencyAccumulatorTexture = FramebufferUtils.generateOITAccumulatorTexture(Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT); + transparencyAccumulatorTexture = FramebufferUtils.generateOITAccumulatorTexture(Globals.userSettings.getRenderResolutionX(), Globals.userSettings.getRenderResolutionY()); transparencyRevealageClear = new float[]{1.0f, 0.0f, 0.0f, 0.0f}; - transparencyRevealageTexture = FramebufferUtils.generateOITRevealageTexture(Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT); - transparencyBuffer = FramebufferUtils.generateOITFramebuffer(Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT, transparencyAccumulatorTexture, transparencyRevealageTexture, screenTextureDepth); + transparencyRevealageTexture = FramebufferUtils.generateOITRevealageTexture(Globals.userSettings.getRenderResolutionX(), Globals.userSettings.getRenderResolutionY()); + transparencyBuffer = FramebufferUtils.generateOITFramebuffer(Globals.userSettings.getRenderResolutionX(), Globals.userSettings.getRenderResolutionY(), transparencyAccumulatorTexture, transparencyRevealageTexture, screenTextureDepth); oitCompositeProgram = ShaderProgram.loadSpecificShader("Shaders/oit/composite.vs", "Shaders/oit/composite.fs"); //projection matrices @@ -332,8 +332,8 @@ public class RenderingEngine { static Framebuffer normalsOutlineFrambuffer; static ShaderProgram normalsOutlineShader; */ - normalsOutlineTexture = FramebufferUtils.generateScreenTextureColorAlpha(Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT); - normalsOutlineFrambuffer = FramebufferUtils.generateScreenTextureFramebuffer(Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT, normalsOutlineTexture); + normalsOutlineTexture = FramebufferUtils.generateScreenTextureColorAlpha(Globals.userSettings.getRenderResolutionX(), Globals.userSettings.getRenderResolutionY()); + normalsOutlineFrambuffer = FramebufferUtils.generateScreenTextureFramebuffer(Globals.userSettings.getRenderResolutionX(), Globals.userSettings.getRenderResolutionY(), normalsOutlineTexture); // normalsOutlineShader = ShaderProgram.loadSpecificShader("Shaders/anime/outlineNormals.vs", "Shaders/anime/outlineNormals.fs"); Globals.assetManager.addShaderToQueue("Shaders/anime/outlineNormals.vs", "Shaders/anime/outlineNormals.fs"); @@ -445,7 +445,11 @@ public class RenderingEngine { Render content to the game framebuffer */ if(Globals.RENDER_FLAG_RENDER_SCREEN_FRAMEBUFFER_CONTENT){ - renderGameContent(); + if(Globals.userSettings.getGraphicsPerformanceOIT()){ + renderGameContent(); + } else { + renderGameContentNoOIT(); + } renderDebugContent(); renderNormalsForOutline(); applyKernelsAndPostprocessing(); @@ -493,7 +497,7 @@ public class RenderingEngine { Render boundaries of ui elements */ if(Globals.RENDER_FLAG_RENDER_UI_BOUNDS){ - DebugRendering.drawUIBoundsPolygon(); + DebugRendering.drawUIBoundsWireframe(); } @@ -591,7 +595,7 @@ public class RenderingEngine { glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); glDepthMask(true); - glViewport(0, 0, Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT); + glViewport(0, 0, Globals.userSettings.getRenderResolutionX(), Globals.userSettings.getRenderResolutionY()); /// /// R E N D E R I N G S T U F F @@ -676,6 +680,57 @@ public class RenderingEngine { // glBindVertexArray(0); } + static void renderGameContentNoOIT(){ + + Matrix4f modelTransformMatrix = new Matrix4f(); + + //bind screen fbo + screenFramebuffer.bind(); + glEnable(GL_DEPTH_TEST); + glDepthFunc(GL_LESS); + glDepthMask(true); + glViewport(0, 0, Globals.userSettings.getRenderResolutionX(), Globals.userSettings.getRenderResolutionY()); + + glEnable(GL_BLEND); + glBlendFunci(0, GL_ONE, GL_ONE); + glBlendFunci(1, GL_ZERO, GL_ONE_MINUS_SRC_COLOR); + glBlendEquation(GL_FUNC_ADD); + + /// + /// R E N D E R I N G S T U F F + /// + //Sets the background color. + glClearColor(0.0f, 0.0f, 0.0f, 0.0f); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + + // + // D R A W A L L E N T I T I E S + // + Vector3f cameraPos = CameraEntityUtils.getCameraCenter(Globals.playerCamera); + modelTransformMatrix = new Matrix4f(); + for(Entity currentEntity : Globals.entityManager.getDrawable()){ + Vector3d position = EntityUtils.getPosition(currentEntity); + if( + (boolean)currentEntity.getData(EntityDataStrings.DATA_STRING_DRAW) && + drawPoint(cameraPos,new Vector3f((float)position.x,(float)position.y,(float)position.z)) + ){ + //fetch actor + Actor currentActor = EntityUtils.getActor(currentEntity); + //calculate camera-modified vector3f + Vector3f cameraModifiedPosition = new Vector3f((float)position.x,(float)position.y,(float)position.z).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)); + //calculate and apply model transform + modelTransformMatrix.identity(); + modelTransformMatrix.translate(cameraModifiedPosition); + modelTransformMatrix.rotate(EntityUtils.getRotation(currentEntity)); + modelTransformMatrix.scale(EntityUtils.getScale(currentEntity)); + currentActor.applyModelMatrix(modelTransformMatrix); + //draw + currentActor.draw(true); + } + } + } + static void renderDebugContent(){ //bind screen fbo @@ -683,7 +738,7 @@ public class RenderingEngine { glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); glDepthMask(true); - glViewport(0, 0, Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT); + glViewport(0, 0, Globals.userSettings.getRenderResolutionX(), Globals.userSettings.getRenderResolutionY()); /// /// R E N D E R I N G S T U F F @@ -856,7 +911,7 @@ public class RenderingEngine { glDepthFunc(GL_LESS); glDepthMask(true); - glViewport(0, 0, Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT); + glViewport(0, 0, Globals.userSettings.getRenderResolutionX(), Globals.userSettings.getRenderResolutionY()); /// /// R E N D E R I N G S T U F F diff --git a/src/main/java/electrosphere/renderer/ShaderProgram.java b/src/main/java/electrosphere/renderer/ShaderProgram.java index 832cfc94..6c57da00 100644 --- a/src/main/java/electrosphere/renderer/ShaderProgram.java +++ b/src/main/java/electrosphere/renderer/ShaderProgram.java @@ -469,6 +469,7 @@ public class ShaderProgram { success = glGetProgrami(rVal.shaderProgram, GL_LINK_STATUS); if (success != GL_TRUE) { LoggerInterface.loggerRenderer.ERROR(glGetProgramInfoLog(rVal.shaderProgram), new RuntimeException(glGetProgramInfoLog(rVal.shaderProgram))); + LoggerInterface.loggerRenderer.WARNING("Shader sources: " + vertexPath + " " + fragmentPath); return Globals.defaultMeshShader; // throw new RuntimeException(glGetProgramInfoLog(rVal.shaderProgram)); } diff --git a/src/main/java/electrosphere/renderer/debug/DebugRendering.java b/src/main/java/electrosphere/renderer/debug/DebugRendering.java index 3c45e52f..5d114b92 100644 --- a/src/main/java/electrosphere/renderer/debug/DebugRendering.java +++ b/src/main/java/electrosphere/renderer/debug/DebugRendering.java @@ -21,8 +21,17 @@ import electrosphere.renderer.ui.elements.ImagePanel; public class DebugRendering { + + public static boolean RENDER_DEBUG_OUTLINE_WINDOW = true; + public static boolean RENDER_DEBUG_OUTLINE_DIV = false; + public static boolean RENDER_DEBUG_OUTLINE_BUTTON = false; + public static boolean RENDER_DEBUG_OUTLINE_LABEL = false; + public static boolean RENDER_DEBUG_OUTLINE_ACTOR_PANEL = false; + public static boolean RENDER_DEBUG_OUTLINE_SLIDER = false; + + static int outlineMaskPosition = 0; - public static void drawUIBoundsPolygon(){ + public static void drawUIBoundsWireframe(){ glDisable(GL_DEPTH_TEST); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); for(Element currentElement : Globals.elementManager.getWindowList()){ @@ -40,14 +49,39 @@ public class DebugRendering { } static ShaderProgram windowDrawDebugProgram = null; + static ShaderProgram elementDrawDebugProgram = null; static Model planeModel = null; public static void drawUIBounds(int parentFramebufferPointer, Vector3f boxPosition, Vector3f boxDimensions, Vector3f color){ + if(Globals.RENDER_FLAG_RENDER_UI_BOUNDS){ + if(planeModel == null){ + planeModel = Globals.assetManager.fetchModel(Globals.imagePlaneModelID); + } + if(elementDrawDebugProgram == null){ + elementDrawDebugProgram = Globals.assetManager.fetchShader("Shaders/ui/debug/windowContentBorder/windowContentBound.vs", null, "Shaders/ui/debug/windowContentBorder/windowContentBound.fs"); + } + if(elementDrawDebugProgram != null && planeModel != null){ + Globals.renderingEngine.bindFramebuffer(parentFramebufferPointer); + Globals.renderingEngine.setActiveShader(elementDrawDebugProgram); + planeModel.pushUniformToMesh("plane", "mPosition", boxPosition); + planeModel.pushUniformToMesh("plane", "mDimension", boxDimensions); + planeModel.pushUniformToMesh("plane", "color", color); + // planeModel.drawUI(); + // if(Globals.assetManager.fetchShader("Shaders/plane/plane.vs", null, "Shaders/plane/plane.fs") != null){ + // Globals.renderingEngine.setActiveShader(Globals.assetManager.fetchShader("Shaders/plane/plane.vs", null, "Shaders/plane/plane.fs")); + // } + //drawUI sets shader so overriding window bound shader + planeModel.draw(false, false, true, false, false, false, false); + } + } + } + + public static void drawUIBoundsWindow(int parentFramebufferPointer, Vector3f boxPosition, Vector3f boxDimensions, Vector3f color){ if(Globals.RENDER_FLAG_RENDER_UI_BOUNDS){ if(planeModel == null){ planeModel = Globals.assetManager.fetchModel(Globals.imagePlaneModelID); } if(windowDrawDebugProgram == null){ - windowDrawDebugProgram = Globals.assetManager.fetchShader("Shaders/ui/debug/windowBound.vs", null, "Shaders/ui/debug/windowBound.fs"); + windowDrawDebugProgram = Globals.assetManager.fetchShader("Shaders/ui/debug/windowBorder/windowBound.vs", null, "Shaders/ui/debug/windowBorder/windowBound.fs"); } if(windowDrawDebugProgram != null && planeModel != null){ Globals.renderingEngine.bindFramebuffer(parentFramebufferPointer); @@ -56,6 +90,9 @@ public class DebugRendering { planeModel.pushUniformToMesh("plane", "mDimension", boxDimensions); planeModel.pushUniformToMesh("plane", "color", color); // planeModel.drawUI(); + // if(Globals.assetManager.fetchShader("Shaders/plane/plane.vs", null, "Shaders/plane/plane.fs") != null){ + // Globals.renderingEngine.setActiveShader(Globals.assetManager.fetchShader("Shaders/plane/plane.vs", null, "Shaders/plane/plane.fs")); + // } //drawUI sets shader so overriding window bound shader planeModel.draw(false, false, true, false, false, false, false); } @@ -100,4 +137,36 @@ public class DebugRendering { } } + + public static void toggleOutlineMask(){ + outlineMaskPosition = outlineMaskPosition + 1; + RENDER_DEBUG_OUTLINE_WINDOW = false; + RENDER_DEBUG_OUTLINE_DIV = false; + RENDER_DEBUG_OUTLINE_BUTTON = false; + RENDER_DEBUG_OUTLINE_LABEL = false; + RENDER_DEBUG_OUTLINE_ACTOR_PANEL = false; + switch(outlineMaskPosition){ + case 1: + RENDER_DEBUG_OUTLINE_DIV = true; + break; + case 2: + RENDER_DEBUG_OUTLINE_LABEL = true; + break; + case 3: + RENDER_DEBUG_OUTLINE_BUTTON = true; + break; + case 4: + RENDER_DEBUG_OUTLINE_ACTOR_PANEL = true; + break; + case 5: + RENDER_DEBUG_OUTLINE_SLIDER = true; + break; + default: + case 0: + outlineMaskPosition = 0; + RENDER_DEBUG_OUTLINE_WINDOW = true; + break; + } + } + } diff --git a/src/main/java/electrosphere/renderer/ui/WidgetUtils.java b/src/main/java/electrosphere/renderer/ui/WidgetUtils.java index 46b91767..97605524 100644 --- a/src/main/java/electrosphere/renderer/ui/WidgetUtils.java +++ b/src/main/java/electrosphere/renderer/ui/WidgetUtils.java @@ -2,12 +2,8 @@ package electrosphere.renderer.ui; import electrosphere.controls.ControlHandler; import electrosphere.main.Globals; -import electrosphere.renderer.ui.elements.ImagePanel; +import electrosphere.renderer.ui.elements.Button; import electrosphere.renderer.ui.elements.Label; -import electrosphere.renderer.ui.elements.TextInput; -import electrosphere.renderer.ui.font.FontUtils; -import electrosphere.renderer.ui.font.bitmapchar.BitmapCharacter; -import electrosphere.renderer.ui.layout.LayoutSchemeListScrollable; /** * @@ -151,6 +147,15 @@ public class WidgetUtils { // Globals.widgetManager.registerWidget(rVal); return rVal; } + + public static Button createLabelButton(String label, int posX, int posY, float fontSize, ClickableElement.ClickEventCallback callback){ + Button rVal = new Button(); + Label buttonLabel = new Label(posX,posY,fontSize); + buttonLabel.setText(label); + rVal.addChild(buttonLabel); + rVal.setOnClick(callback); + return rVal; + } } diff --git a/src/main/java/electrosphere/renderer/ui/Window.java b/src/main/java/electrosphere/renderer/ui/Window.java index b559b8d1..15210757 100644 --- a/src/main/java/electrosphere/renderer/ui/Window.java +++ b/src/main/java/electrosphere/renderer/ui/Window.java @@ -46,10 +46,10 @@ public class Window implements DrawableElement, ContainerElement, NavigableEleme // widgetBuffer = FramebufferUtils.generateScreensizeTextureFramebuffer(); customMat.setTexturePointer(widgetBuffer.getTexturePointer()); // customMat.setTexturePointer(Globals.assetManager.fetchTexture("Textures/Testing1.png").getTexturePointer()); - float ndcX = (float)positionX/Globals.WINDOW_WIDTH; - float ndcY = (float)positionY/Globals.WINDOW_HEIGHT; float ndcWidth = (float)width/Globals.WINDOW_WIDTH; float ndcHeight = (float)height/Globals.WINDOW_HEIGHT; + float ndcX = (float)positionX/Globals.WINDOW_WIDTH; + float ndcY = (float)positionY/Globals.WINDOW_HEIGHT; this.width = width; this.height = height; boxPosition = new Vector3f(ndcX,ndcY,0); @@ -88,8 +88,8 @@ public class Window implements DrawableElement, ContainerElement, NavigableEleme LoggerInterface.loggerRenderer.ERROR("Window unable to find plane model!!", new Exception()); } - if(Globals.RENDER_FLAG_RENDER_UI_BOUNDS){ - DebugRendering.drawUIBounds(parentFramebufferPointer, boxPosition, boxDimensions, windowDrawDebugColor); + if(Globals.RENDER_FLAG_RENDER_UI_BOUNDS && DebugRendering.RENDER_DEBUG_OUTLINE_WINDOW){ + DebugRendering.drawUIBoundsWindow(parentFramebufferPointer, boxPosition, boxDimensions, windowDrawDebugColor); } } diff --git a/src/main/java/electrosphere/renderer/ui/elements/ActorPanel.java b/src/main/java/electrosphere/renderer/ui/elements/ActorPanel.java index 7da4ee46..6723a9c4 100644 --- a/src/main/java/electrosphere/renderer/ui/elements/ActorPanel.java +++ b/src/main/java/electrosphere/renderer/ui/elements/ActorPanel.java @@ -1,37 +1,37 @@ package electrosphere.renderer.ui.elements; -import org.joml.Matrix4f; -import org.joml.Quaternionf; -import org.joml.Vector3f; -import static org.lwjgl.opengl.GL11.GL_DEPTH_TEST; -import static org.lwjgl.opengl.GL11.GL_LESS; import static org.lwjgl.opengl.GL11.GL_COLOR_BUFFER_BIT; import static org.lwjgl.opengl.GL11.GL_DEPTH_BUFFER_BIT; -import static org.lwjgl.opengl.GL11.glDepthFunc; -import static org.lwjgl.opengl.GL11.glDepthMask; +import static org.lwjgl.opengl.GL11.GL_DEPTH_TEST; +import static org.lwjgl.opengl.GL11.GL_LESS; import static org.lwjgl.opengl.GL11.glClear; import static org.lwjgl.opengl.GL11.glClearColor; -import static org.lwjgl.opengl.GL11.glEnable; +import static org.lwjgl.opengl.GL11.glDepthFunc; +import static org.lwjgl.opengl.GL11.glDepthMask; import static org.lwjgl.opengl.GL11.glDisable; +import static org.lwjgl.opengl.GL11.glEnable; import static org.lwjgl.opengl.GL11.glViewport; import static org.lwjgl.opengl.GL30.GL_FRAMEBUFFER; import static org.lwjgl.opengl.GL30.glBindFramebuffer; +import org.joml.Matrix4f; +import org.joml.Quaternionf; +import org.joml.Vector3f; + import electrosphere.logger.LoggerInterface; import electrosphere.main.Globals; -import electrosphere.main.Main; import electrosphere.renderer.Material; import electrosphere.renderer.Model; import electrosphere.renderer.RenderingEngine; import electrosphere.renderer.actor.Actor; +import electrosphere.renderer.debug.DebugRendering; import electrosphere.renderer.framebuffer.Framebuffer; import electrosphere.renderer.framebuffer.FramebufferUtils; -import electrosphere.renderer.texture.Texture; import electrosphere.renderer.ui.DraggableElement; import electrosphere.renderer.ui.DrawableElement; import electrosphere.renderer.ui.events.DragEvent; -import electrosphere.renderer.ui.events.Event; import electrosphere.renderer.ui.events.DragEvent.DragEventType; +import electrosphere.renderer.ui.events.Event; public class ActorPanel implements DrawableElement, DraggableElement { @@ -54,6 +54,8 @@ public class ActorPanel implements DrawableElement, DraggableElement { DragEventCallback onDragStart; DragEventCallback onDrag; DragEventCallback onDragRelease; + + static final Vector3f windowDrawDebugColor = new Vector3f(0.0f,0.0f,1.0f); public ActorPanel(int x, int y, int width, int height, Actor actor){ elementBuffer = FramebufferUtils.generateTextureFramebuffer(width, height); @@ -115,18 +117,24 @@ public class ActorPanel implements DrawableElement, DraggableElement { Vector3f boxPosition = new Vector3f(ndcX,ndcY,0); Vector3f boxDimensions = new Vector3f(ndcWidth,ndcHeight,0); + + Globals.renderingEngine.setActiveShader(Globals.assetManager.fetchShader("Shaders/ui/windowContent/windowContent.vs", null, "Shaders/ui/windowContent/windowContent.fs")); - Model planeModel = Globals.assetManager.fetchModel(ImagePanel.imagePanelModelPath); + Model planeModel = Globals.assetManager.fetchModel(Globals.imagePlaneModelID); if(planeModel != null){ planeModel.pushUniformToMesh("plane", "mPosition", boxPosition); planeModel.pushUniformToMesh("plane", "mDimension", boxDimensions); planeModel.pushUniformToMesh("plane", "tPosition", texPosition); planeModel.pushUniformToMesh("plane", "tDimension", texScale); planeModel.meshes.get(0).setMaterial(customMat); - planeModel.drawUI(); + planeModel.draw(false, false, true, true, false, false, false); } else { LoggerInterface.loggerRenderer.ERROR("Actor Panel unable to find plane model!!", new Exception()); } + + if(Globals.RENDER_FLAG_RENDER_UI_BOUNDS && DebugRendering.RENDER_DEBUG_OUTLINE_ACTOR_PANEL){ + DebugRendering.drawUIBounds(parentFramebufferPointer, boxPosition, boxDimensions, windowDrawDebugColor); + } } public int width = 1; diff --git a/src/main/java/electrosphere/renderer/ui/elements/Button.java b/src/main/java/electrosphere/renderer/ui/elements/Button.java index d3c9c7de..ffaaafe4 100644 --- a/src/main/java/electrosphere/renderer/ui/elements/Button.java +++ b/src/main/java/electrosphere/renderer/ui/elements/Button.java @@ -5,6 +5,8 @@ import java.util.List; import org.joml.Vector3f; +import electrosphere.main.Globals; +import electrosphere.renderer.debug.DebugRendering; import electrosphere.renderer.ui.ClickableElement; import electrosphere.renderer.ui.ContainerElement; import electrosphere.renderer.ui.DrawableElement; @@ -35,6 +37,8 @@ public class Button implements DrawableElement, FocusableElement, ContainerEleme FocusEventCallback onLoseFocusCallback; ClickEventCallback clickCallback; + static final Vector3f windowDrawDebugColor = new Vector3f(1.0f,1.0f,1.0f); + public int getWidth() { if(width == -1){ int minX = -1; @@ -207,6 +211,16 @@ public class Button implements DrawableElement, FocusableElement, ContainerEleme drawableChild.draw(parentFramebufferPointer,parentWidth,parentHeight); } } + + if(Globals.RENDER_FLAG_RENDER_UI_BOUNDS && DebugRendering.RENDER_DEBUG_OUTLINE_BUTTON){ + float ndcX = (float)positionX/parentWidth; + float ndcY = (float)positionY/parentHeight; + float ndcWidth = (float)getWidth()/parentWidth; + float ndcHeight = (float)getHeight()/parentHeight; + Vector3f boxPosition = new Vector3f(ndcX,ndcY,0); + Vector3f boxDimensions = new Vector3f(ndcWidth,ndcHeight,0); + DebugRendering.drawUIBounds(parentFramebufferPointer, boxPosition, boxDimensions, windowDrawDebugColor); + } } @Override diff --git a/src/main/java/electrosphere/renderer/ui/elements/Div.java b/src/main/java/electrosphere/renderer/ui/elements/Div.java index 39ce54d2..e6efb942 100644 --- a/src/main/java/electrosphere/renderer/ui/elements/Div.java +++ b/src/main/java/electrosphere/renderer/ui/elements/Div.java @@ -3,6 +3,10 @@ package electrosphere.renderer.ui.elements; import java.util.LinkedList; import java.util.List; +import org.joml.Vector3f; + +import electrosphere.main.Globals; +import electrosphere.renderer.debug.DebugRendering; import electrosphere.renderer.ui.ClickableElement; import electrosphere.renderer.ui.ContainerElement; import electrosphere.renderer.ui.DraggableElement; @@ -12,10 +16,10 @@ import electrosphere.renderer.ui.FocusableElement; import electrosphere.renderer.ui.NavigableElement; import electrosphere.renderer.ui.events.ClickEvent; import electrosphere.renderer.ui.events.DragEvent; +import electrosphere.renderer.ui.events.DragEvent.DragEventType; import electrosphere.renderer.ui.events.Event; import electrosphere.renderer.ui.events.FocusEvent; import electrosphere.renderer.ui.events.NavigationEvent; -import electrosphere.renderer.ui.events.DragEvent.DragEventType; public class Div implements ClickableElement,ContainerElement,DraggableElement,FocusableElement,DrawableElement,NavigableElement { @@ -41,6 +45,8 @@ public class Div implements ClickableElement,ContainerElement,DraggableElement,F public boolean visible = false; + static final Vector3f windowDrawDebugColor = new Vector3f(1.0f,1.0f,1.0f); + @Override public int getWidth() { if(width == -1){ @@ -335,6 +341,16 @@ public class Div implements ClickableElement,ContainerElement,DraggableElement,F drawableChild.draw(parentFramebufferPointer,parentWidth,parentHeight); } } + + if(Globals.RENDER_FLAG_RENDER_UI_BOUNDS && DebugRendering.RENDER_DEBUG_OUTLINE_DIV){ + float ndcX = (float)positionX/parentWidth; + float ndcY = (float)positionY/parentHeight; + float ndcWidth = (float)getWidth()/parentWidth; + float ndcHeight = (float)getHeight()/parentHeight; + Vector3f boxPosition = new Vector3f(ndcX,ndcY,0); + Vector3f boxDimensions = new Vector3f(ndcWidth,ndcHeight,0); + DebugRendering.drawUIBounds(parentFramebufferPointer, boxPosition, boxDimensions, windowDrawDebugColor); + } } @Override diff --git a/src/main/java/electrosphere/renderer/ui/elements/Label.java b/src/main/java/electrosphere/renderer/ui/elements/Label.java index c5391436..3ea71a2a 100644 --- a/src/main/java/electrosphere/renderer/ui/elements/Label.java +++ b/src/main/java/electrosphere/renderer/ui/elements/Label.java @@ -86,7 +86,7 @@ public class Label implements DrawableElement { child.draw(parentFramebufferPointer, parentWidth, parentHeight); } - if(Globals.RENDER_FLAG_RENDER_UI_BOUNDS){ + if(Globals.RENDER_FLAG_RENDER_UI_BOUNDS && DebugRendering.RENDER_DEBUG_OUTLINE_LABEL){ float ndcX = (float)positionX/parentWidth; float ndcY = (float)positionY/parentHeight; float ndcWidth = (float)getWidth()/parentWidth; diff --git a/src/main/java/electrosphere/renderer/ui/elements/Slider.java b/src/main/java/electrosphere/renderer/ui/elements/Slider.java index 9554b18d..412c86c8 100644 --- a/src/main/java/electrosphere/renderer/ui/elements/Slider.java +++ b/src/main/java/electrosphere/renderer/ui/elements/Slider.java @@ -5,22 +5,20 @@ import org.joml.Vector3f; import electrosphere.logger.LoggerInterface; import electrosphere.main.Globals; import electrosphere.renderer.Model; +import electrosphere.renderer.debug.DebugRendering; import electrosphere.renderer.ui.ClickableElement; import electrosphere.renderer.ui.DraggableElement; import electrosphere.renderer.ui.DrawableElement; import electrosphere.renderer.ui.FocusableElement; -import electrosphere.renderer.ui.KeyEventElement; import electrosphere.renderer.ui.MenuEventElement; import electrosphere.renderer.ui.ValueElement; import electrosphere.renderer.ui.events.ClickEvent; import electrosphere.renderer.ui.events.DragEvent; +import electrosphere.renderer.ui.events.DragEvent.DragEventType; import electrosphere.renderer.ui.events.Event; import electrosphere.renderer.ui.events.FocusEvent; -import electrosphere.renderer.ui.events.KeyboardEvent; import electrosphere.renderer.ui.events.MenuEvent; -import electrosphere.renderer.ui.events.MouseEvent; import electrosphere.renderer.ui.events.ValueChangeEvent; -import electrosphere.renderer.ui.events.DragEvent.DragEventType; public class Slider implements ClickableElement, DraggableElement, FocusableElement, DrawableElement, MenuEventElement, ValueElement { @@ -56,6 +54,8 @@ public class Slider implements ClickableElement, DraggableElement, FocusableElem static final int idealMargin = 5; //5 pixels margin ideally + static final Vector3f windowDrawDebugColor = new Vector3f(1.0f,1.0f,1.0f); + public Slider(int positionX, int positionY, int width, int height, Vector3f colorBackground, Vector3f colorForeground){ @@ -119,6 +119,10 @@ public class Slider implements ClickableElement, DraggableElement, FocusableElem } else { LoggerInterface.loggerRenderer.ERROR("Window unable to find plane model!!", new Exception()); } + if(Globals.RENDER_FLAG_RENDER_UI_BOUNDS && DebugRendering.RENDER_DEBUG_OUTLINE_SLIDER){ + boxDimensions.x = (float)((width - marginX * 2) * 1.0f)/parentWidth; + DebugRendering.drawUIBounds(parentFramebufferPointer, boxPosition, boxDimensions, windowDrawDebugColor); + } } diff --git a/src/main/java/electrosphere/script/ScriptEngine.java b/src/main/java/electrosphere/script/ScriptEngine.java new file mode 100644 index 00000000..09c67a6e --- /dev/null +++ b/src/main/java/electrosphere/script/ScriptEngine.java @@ -0,0 +1,60 @@ +package electrosphere.script; + +import java.io.File; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import org.graalvm.polyglot.Context; +import org.graalvm.polyglot.Source; +import org.graalvm.polyglot.Value; + +import electrosphere.util.FileUtils; + +public class ScriptEngine { + + Context context; + + Map sourceMap; + + public void init(){ + //init datastructures + sourceMap = new HashMap(); + //create context + context = Context.create("js"); + //read scripts into source map + readScriptsDirectory("/Scripts", FileUtils.getAssetFile("/Scripts")); + //create bindings + try { + String content = FileUtils.getAssetFileAsString("/Scripts/test.js"); + Source source = Source.create("js", content); + context.eval(source); + System.out.println("Evaluated"); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + void createBindings(){ + Value jsBindings = context.getBindings("js"); + jsBindings.putMember("name", "somescript"); + } + + void readScriptsDirectory(String path, File directory){ + if(directory.exists() && directory.isDirectory()){ + File[] children = directory.listFiles(); + for(File childFile : children){ + String qualifiedName = path + "/" + childFile.getName(); + if(childFile.isDirectory()){ + readScriptsDirectory(qualifiedName,childFile); + } else { + //add to source map + String content = FileUtils.readFileToString(childFile); + sourceMap.put(qualifiedName,Source.create("js",content)); + } + } + } + } + +}