Detatch client logic from opengl/openal calls
This commit is contained in:
parent
b167062585
commit
2fd8e77a2a
@ -30,7 +30,7 @@ public class ControlCallback implements GLFWKeyCallbackI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* !!!WARNING!!!, will silently fail if
|
* !!!WARNING!!!, will silently fail if opengl elementsn ot defined or keycode is outside of key value array size or is not in main rendering thread
|
||||||
* @param keycode
|
* @param keycode
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -1167,14 +1167,14 @@ public class ControlHandler {
|
|||||||
public void runHandlers(List<Control> controls){
|
public void runHandlers(List<Control> controls){
|
||||||
|
|
||||||
//construct mouse event
|
//construct mouse event
|
||||||
glfwGetCursorPos(Globals.window, mouse_X_Buffer, mouse_Y_Buffer);
|
|
||||||
xpos = mouse_X_Buffer[0];
|
//Fills the buffer
|
||||||
ypos = mouse_Y_Buffer[0];
|
getMousePositionInBuffer();
|
||||||
float xoffset = (float) (xpos - mouse_lastX);
|
float xoffset = (float) (xpos - mouse_lastX);
|
||||||
float yoffset = (float) (mouse_lastY - ypos);
|
float yoffset = (float) (mouse_lastY - ypos);
|
||||||
mouse_lastX = (float) xpos;
|
mouse_lastX = (float) xpos;
|
||||||
mouse_lastY = (float) ypos;
|
mouse_lastY = (float) ypos;
|
||||||
MouseEvent currentMouseEvent = new MouseEvent((int)xpos,(int)ypos,(int)mouse_lastX,(int)mouse_lastY,(int)xoffset,(int)yoffset,Globals.mouseCallback.getButton(GLFW_MOUSE_BUTTON_1),Globals.mouseCallback.getButton(GLFW_MOUSE_BUTTON_2));
|
MouseEvent currentMouseEvent = new MouseEvent((int)xpos,(int)ypos,(int)mouse_lastX,(int)mouse_lastY,(int)xoffset,(int)yoffset,getButton1Raw(),getButton2Raw());
|
||||||
boolean mouseMoveEvent = xoffset != 0 || yoffset != 0;
|
boolean mouseMoveEvent = xoffset != 0 || yoffset != 0;
|
||||||
|
|
||||||
|
|
||||||
@ -1238,6 +1238,31 @@ public class ControlHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void getMousePositionInBuffer(){
|
||||||
|
//only if not headless, gather position
|
||||||
|
if(!Globals.HEADLESS){
|
||||||
|
glfwGetCursorPos(Globals.window, mouse_X_Buffer, mouse_Y_Buffer);
|
||||||
|
xpos = mouse_X_Buffer[0];
|
||||||
|
ypos = mouse_Y_Buffer[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean getButton1Raw(){
|
||||||
|
if(Globals.HEADLESS){
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return Globals.mouseCallback.getButton(GLFW_MOUSE_BUTTON_1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean getButton2Raw(){
|
||||||
|
if(Globals.HEADLESS){
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return Globals.mouseCallback.getButton(GLFW_MOUSE_BUTTON_2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Control getControl(String controlName){
|
public Control getControl(String controlName){
|
||||||
return controls.get(controlName);
|
return controls.get(controlName);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,7 +23,7 @@ public class MouseCallback extends GLFWMouseButtonCallback {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* !!!WARNING!!!, will silently fail if
|
* !!!WARNING!!!, will silently fail if opengl elementsn ot defined or keycode is outside of key value array size or is not in main rendering thread
|
||||||
* @param keycode
|
* @param keycode
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -113,8 +113,8 @@ public class Globals {
|
|||||||
//
|
//
|
||||||
public static ControlHandler controlHandler;
|
public static ControlHandler controlHandler;
|
||||||
public static boolean updateCamera = true;
|
public static boolean updateCamera = true;
|
||||||
public static ControlCallback controlCallback;
|
public static ControlCallback controlCallback = new ControlCallback();
|
||||||
public static MouseCallback mouseCallback;
|
public static MouseCallback mouseCallback = new MouseCallback();
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|||||||
@ -264,11 +264,11 @@ public class Main {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if(Globals.RUN_CLIENT){
|
if(Globals.RUN_CLIENT && !Globals.HEADLESS){
|
||||||
Globals.renderingEngine.drawScreen();
|
Globals.renderingEngine.drawScreen();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Globals.ENGINE_SHUTDOWN_FLAG || (Globals.RUN_CLIENT && glfwWindowShouldClose(Globals.window))){
|
if(Globals.ENGINE_SHUTDOWN_FLAG || (!Globals.HEADLESS && Globals.RUN_CLIENT && glfwWindowShouldClose(Globals.window))){
|
||||||
running = false;
|
running = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -289,7 +289,7 @@ public class Main {
|
|||||||
// S H U T D O W N
|
// S H U T D O W N
|
||||||
//
|
//
|
||||||
//Terminate the program.
|
//Terminate the program.
|
||||||
if(Globals.RUN_CLIENT){
|
if(!Globals.HEADLESS && Globals.RUN_CLIENT){
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
}
|
}
|
||||||
//used to signal threads to stop
|
//used to signal threads to stop
|
||||||
@ -299,7 +299,7 @@ public class Main {
|
|||||||
Globals.serverThread.interrupt();
|
Globals.serverThread.interrupt();
|
||||||
}
|
}
|
||||||
//shut down audio engine
|
//shut down audio engine
|
||||||
if(Globals.RUN_CLIENT){
|
if(!Globals.HEADLESS && Globals.RUN_CLIENT){
|
||||||
Globals.audioEngine.shutdown();
|
Globals.audioEngine.shutdown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -113,8 +113,11 @@ public class Mesh {
|
|||||||
//
|
//
|
||||||
// VAO
|
// VAO
|
||||||
//
|
//
|
||||||
|
//Check for headless to not call gl functions when not running with gpu
|
||||||
|
if(!Globals.HEADLESS){
|
||||||
rVal.vertexArrayObject = glGenVertexArrays();
|
rVal.vertexArrayObject = glGenVertexArrays();
|
||||||
glBindVertexArray(rVal.vertexArrayObject);
|
glBindVertexArray(rVal.vertexArrayObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -370,7 +373,7 @@ public class Mesh {
|
|||||||
boneIndexDataBuffer.flip();
|
boneIndexDataBuffer.flip();
|
||||||
boneWeightDataBuffer.flip();
|
boneWeightDataBuffer.flip();
|
||||||
|
|
||||||
|
if(!Globals.HEADLESS){
|
||||||
rVal.boneWeightBuffer = glGenBuffers();
|
rVal.boneWeightBuffer = glGenBuffers();
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, rVal.boneWeightBuffer);
|
glBindBuffer(GL_ARRAY_BUFFER, rVal.boneWeightBuffer);
|
||||||
GL15.glBufferData(GL_ARRAY_BUFFER, boneWeightDataBuffer, GL_STATIC_DRAW);
|
GL15.glBufferData(GL_ARRAY_BUFFER, boneWeightDataBuffer, GL_STATIC_DRAW);
|
||||||
@ -383,6 +386,7 @@ public class Mesh {
|
|||||||
GL15.glBufferData(GL_ARRAY_BUFFER, boneIndexDataBuffer, GL_STATIC_DRAW);
|
GL15.glBufferData(GL_ARRAY_BUFFER, boneIndexDataBuffer, GL_STATIC_DRAW);
|
||||||
glVertexAttribPointer(3, 4, GL_FLOAT, false, 0, 0);
|
glVertexAttribPointer(3, 4, GL_FLOAT, false, 0, 0);
|
||||||
glEnableVertexAttribArray(3);
|
glEnableVertexAttribArray(3);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
rVal.hasBones = false;
|
rVal.hasBones = false;
|
||||||
}
|
}
|
||||||
@ -397,8 +401,9 @@ public class Mesh {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if(!Globals.HEADLESS){
|
||||||
rVal.shader = ShaderProgram.smart_assemble_shader(has_bones, apply_lighting);
|
rVal.shader = ShaderProgram.smart_assemble_shader(has_bones, apply_lighting);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -414,8 +419,9 @@ public class Mesh {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if(!Globals.HEADLESS){
|
||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -435,59 +441,73 @@ public class Mesh {
|
|||||||
|
|
||||||
|
|
||||||
public void buffer_vertices(FloatBuffer verticies, int vertexDimension){
|
public void buffer_vertices(FloatBuffer verticies, int vertexDimension){
|
||||||
|
if(!Globals.HEADLESS){
|
||||||
vertexBuffer = glGenBuffers();
|
vertexBuffer = glGenBuffers();
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
|
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
|
||||||
GL15.glBufferData(GL_ARRAY_BUFFER, verticies, GL_STATIC_DRAW);
|
GL15.glBufferData(GL_ARRAY_BUFFER, verticies, GL_STATIC_DRAW);
|
||||||
glVertexAttribPointer(0, vertexDimension, GL_FLOAT, false, 0, 0);
|
glVertexAttribPointer(0, vertexDimension, GL_FLOAT, false, 0, 0);
|
||||||
glEnableVertexAttribArray(0);
|
glEnableVertexAttribArray(0);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void buffer_normals(FloatBuffer normals, int normalDimension){
|
public void buffer_normals(FloatBuffer normals, int normalDimension){
|
||||||
|
if(!Globals.HEADLESS){
|
||||||
normalBuffer = glGenBuffers();
|
normalBuffer = glGenBuffers();
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, normalBuffer);
|
glBindBuffer(GL_ARRAY_BUFFER, normalBuffer);
|
||||||
GL15.glBufferData(GL_ARRAY_BUFFER, normals, GL_STATIC_DRAW);
|
GL15.glBufferData(GL_ARRAY_BUFFER, normals, GL_STATIC_DRAW);
|
||||||
glVertexAttribPointer(1, normalDimension, GL_FLOAT, false, 0, 0);
|
glVertexAttribPointer(1, normalDimension, GL_FLOAT, false, 0, 0);
|
||||||
glEnableVertexAttribArray(1);
|
glEnableVertexAttribArray(1);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void buffer_faces(IntBuffer faces){
|
public void buffer_faces(IntBuffer faces){
|
||||||
|
if(!Globals.HEADLESS){
|
||||||
elementArrayBuffer = glGenBuffers();
|
elementArrayBuffer = glGenBuffers();
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, elementArrayBuffer);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, elementArrayBuffer);
|
||||||
GL15.glBufferData(GL_ELEMENT_ARRAY_BUFFER, faces, GL_STATIC_DRAW);
|
GL15.glBufferData(GL_ELEMENT_ARRAY_BUFFER, faces, GL_STATIC_DRAW);
|
||||||
elementCount = faces.capacity();
|
elementCount = faces.capacity();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void buffer_texture_coords(FloatBuffer coords, int textureDimension){
|
public void buffer_texture_coords(FloatBuffer coords, int textureDimension){
|
||||||
|
if(!Globals.HEADLESS){
|
||||||
textureCoordBuffer = glGenBuffers();
|
textureCoordBuffer = glGenBuffers();
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, textureCoordBuffer);
|
glBindBuffer(GL_ARRAY_BUFFER, textureCoordBuffer);
|
||||||
GL15.glBufferData(GL_ARRAY_BUFFER, coords, GL_STATIC_DRAW);
|
GL15.glBufferData(GL_ARRAY_BUFFER, coords, GL_STATIC_DRAW);
|
||||||
glVertexAttribPointer(4, textureDimension, GL_FLOAT, false, 0, 0);
|
glVertexAttribPointer(4, textureDimension, GL_FLOAT, false, 0, 0);
|
||||||
glEnableVertexAttribArray(4);
|
glEnableVertexAttribArray(4);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void bufferCustomFloatAttribArray(FloatBuffer buffer, int bufferDimension, int attribIndex){
|
public void bufferCustomFloatAttribArray(FloatBuffer buffer, int bufferDimension, int attribIndex){
|
||||||
|
if(!Globals.HEADLESS){
|
||||||
int customBuffer = glGenBuffers();
|
int customBuffer = glGenBuffers();
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, customBuffer);
|
glBindBuffer(GL_ARRAY_BUFFER, customBuffer);
|
||||||
GL15.glBufferData(GL_ARRAY_BUFFER, buffer, GL_STATIC_DRAW);
|
GL15.glBufferData(GL_ARRAY_BUFFER, buffer, GL_STATIC_DRAW);
|
||||||
glVertexAttribPointer(attribIndex, bufferDimension, GL_FLOAT, false, 0, 0);
|
glVertexAttribPointer(attribIndex, bufferDimension, GL_FLOAT, false, 0, 0);
|
||||||
glEnableVertexAttribArray(attribIndex);
|
glEnableVertexAttribArray(attribIndex);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void bufferCustomIntAttribArray(IntBuffer buffer, int bufferDimension, int attribIndex){
|
public void bufferCustomIntAttribArray(IntBuffer buffer, int bufferDimension, int attribIndex){
|
||||||
|
if(!Globals.HEADLESS){
|
||||||
int customBuffer = glGenBuffers();
|
int customBuffer = glGenBuffers();
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, customBuffer);
|
glBindBuffer(GL_ARRAY_BUFFER, customBuffer);
|
||||||
GL15.glBufferData(GL_ARRAY_BUFFER, buffer, GL_STATIC_DRAW);
|
GL15.glBufferData(GL_ARRAY_BUFFER, buffer, GL_STATIC_DRAW);
|
||||||
glVertexAttribPointer(attribIndex, bufferDimension, GL_INT, false, 0, 0);
|
glVertexAttribPointer(attribIndex, bufferDimension, GL_INT, false, 0, 0);
|
||||||
glEnableVertexAttribArray(attribIndex);
|
glEnableVertexAttribArray(attribIndex);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void bufferCustomUIntAttribArray(IntBuffer buffer, int bufferDimension, int attribIndex){
|
public void bufferCustomUIntAttribArray(IntBuffer buffer, int bufferDimension, int attribIndex){
|
||||||
|
if(!Globals.HEADLESS){
|
||||||
int customBuffer = glGenBuffers();
|
int customBuffer = glGenBuffers();
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, customBuffer);
|
glBindBuffer(GL_ARRAY_BUFFER, customBuffer);
|
||||||
GL15.glBufferData(GL_ARRAY_BUFFER, buffer, GL_STATIC_DRAW);
|
GL15.glBufferData(GL_ARRAY_BUFFER, buffer, GL_STATIC_DRAW);
|
||||||
glVertexAttribPointer(attribIndex, bufferDimension, GL_UNSIGNED_INT, false, 0, 0);
|
glVertexAttribPointer(attribIndex, bufferDimension, GL_UNSIGNED_INT, false, 0, 0);
|
||||||
glEnableVertexAttribArray(attribIndex);
|
glEnableVertexAttribArray(attribIndex);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void setTextureMask(ActorTextureMask textureMask){
|
public void setTextureMask(ActorTextureMask textureMask){
|
||||||
this.textureMask = textureMask;
|
this.textureMask = textureMask;
|
||||||
|
|||||||
@ -231,12 +231,13 @@ public class RenderingEngine {
|
|||||||
Globals.WINDOW_WIDTH = bufferWidth;
|
Globals.WINDOW_WIDTH = bufferWidth;
|
||||||
Globals.WINDOW_HEIGHT = bufferHeight;
|
Globals.WINDOW_HEIGHT = bufferHeight;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Attack controls callbacks
|
||||||
|
//
|
||||||
//set key callback
|
//set key callback
|
||||||
Globals.controlCallback = new ControlCallback();
|
|
||||||
GLFW.glfwSetKeyCallback(Globals.window, Globals.controlCallback);
|
GLFW.glfwSetKeyCallback(Globals.window, Globals.controlCallback);
|
||||||
|
|
||||||
//set mouse callback
|
//set mouse callback
|
||||||
Globals.mouseCallback = new MouseCallback();
|
|
||||||
GLFW.glfwSetMouseButtonCallback(Globals.window, Globals.mouseCallback);
|
GLFW.glfwSetMouseButtonCallback(Globals.window, Globals.mouseCallback);
|
||||||
|
|
||||||
//get title bar dimensions
|
//get title bar dimensions
|
||||||
|
|||||||
@ -5,6 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
package electrosphere.renderer.texture;
|
package electrosphere.renderer.texture;
|
||||||
|
|
||||||
|
import electrosphere.engine.Globals;
|
||||||
import electrosphere.engine.Main;
|
import electrosphere.engine.Main;
|
||||||
import electrosphere.util.FileUtils;
|
import electrosphere.util.FileUtils;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
@ -42,6 +43,7 @@ public class Texture {
|
|||||||
|
|
||||||
public Texture(String path){
|
public Texture(String path){
|
||||||
this.path = path;
|
this.path = path;
|
||||||
|
if(!Globals.HEADLESS){
|
||||||
//generate the texture object on gpu
|
//generate the texture object on gpu
|
||||||
texturePointer = glGenTextures();
|
texturePointer = glGenTextures();
|
||||||
//bind the new texture
|
//bind the new texture
|
||||||
@ -128,7 +130,8 @@ public class Texture {
|
|||||||
}
|
}
|
||||||
glGenerateMipmap(GL_TEXTURE_2D);
|
glGenerateMipmap(GL_TEXTURE_2D);
|
||||||
//OPTIONAL free the original image data now that it's on the gpu
|
//OPTIONAL free the original image data now that it's on the gpu
|
||||||
System.gc();
|
// System.gc();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void bind(){
|
public void bind(){
|
||||||
|
|||||||
@ -15,7 +15,7 @@ public class SpawningCreaturesTest {
|
|||||||
@Before
|
@Before
|
||||||
public void initEngine(){
|
public void initEngine(){
|
||||||
System.out.println("[Test] Spawn many creatures");
|
System.out.println("[Test] Spawn many creatures");
|
||||||
Globals.RUN_CLIENT = false;
|
Globals.RUN_CLIENT = true;
|
||||||
Globals.RUN_SERVER = true;
|
Globals.RUN_SERVER = true;
|
||||||
Globals.HEADLESS = true;
|
Globals.HEADLESS = true;
|
||||||
NetUtils.setPort(0);
|
NetUtils.setPort(0);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user