code cleanup
This commit is contained in:
parent
e706c69c75
commit
f5ff55898d
@ -1686,6 +1686,7 @@ Styling support for html-defined menus
|
||||
Dynamic html-defined menus support button elements that call a client hook when clicked
|
||||
Dynamic menu navigation between windows
|
||||
Starting formatting npc intro page
|
||||
Code cleanup
|
||||
|
||||
|
||||
|
||||
|
||||
@ -91,6 +91,9 @@ public class HtmlParser {
|
||||
}
|
||||
}
|
||||
} break;
|
||||
case "script": {
|
||||
LoggerInterface.loggerUI.WARNING("Script tag not implemented yet");
|
||||
} break;
|
||||
case "style":
|
||||
//silently ignore
|
||||
break;
|
||||
|
||||
@ -2,6 +2,7 @@ package electrosphere.engine.assetmanager.queue;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.lwjgl.BufferUtils;
|
||||
|
||||
@ -72,6 +73,11 @@ public class QueuedTexture implements QueuedAsset<Texture> {
|
||||
*/
|
||||
boolean suppliedPath = false;
|
||||
|
||||
/**
|
||||
* The runnable to invoke to actually load the model
|
||||
*/
|
||||
Consumer<Texture> loadFunc;
|
||||
|
||||
/**
|
||||
* Creates the queued texture object
|
||||
* @param buffer The data to buffer
|
||||
@ -147,6 +153,16 @@ public class QueuedTexture implements QueuedAsset<Texture> {
|
||||
return rVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the queued texture object
|
||||
* @param image the image to load to gpu
|
||||
*/
|
||||
public static QueuedTexture createFromImage(BufferedImage bufferedImage, Consumer<Texture> loadFunc){
|
||||
QueuedTexture rVal = QueuedTexture.createFromImage(bufferedImage);
|
||||
rVal.loadFunc = loadFunc;
|
||||
return rVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the queued texture object
|
||||
* @param path The path to register this texture to
|
||||
@ -170,6 +186,9 @@ public class QueuedTexture implements QueuedAsset<Texture> {
|
||||
texture = new Texture(Globals.renderingEngine.getOpenGLState(), data, buffer);
|
||||
} break;
|
||||
}
|
||||
if(this.loadFunc != null){
|
||||
this.loadFunc.accept(texture);
|
||||
}
|
||||
hasLoaded = true;
|
||||
}
|
||||
|
||||
|
||||
@ -764,6 +764,7 @@ public class AttachUtils {
|
||||
* @param parentEntity
|
||||
* @return The list of entities that are attached to this parent entity, or null if undefined
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static List<Entity> getChildrenList(Entity parentEntity){
|
||||
return (List<Entity>)parentEntity.getData(EntityDataStrings.ATTACH_CHILDREN_LIST);
|
||||
}
|
||||
|
||||
@ -538,6 +538,7 @@ public class ClientAttackTree implements BehaviorTree {
|
||||
* @param attackType the attack type
|
||||
* @return The moveset if it exists
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<AttackMove> getMoveset(String attackType){
|
||||
return (List<AttackMove>)parent.getData(attackType);
|
||||
}
|
||||
|
||||
@ -634,6 +634,7 @@ public class ServerAttackTree implements BehaviorTree {
|
||||
* @param attackType the attack type
|
||||
* @return The moveset if it exists
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<AttackMove> getMoveset(String attackType){
|
||||
return (List<AttackMove>)parent.getData(attackType);
|
||||
}
|
||||
|
||||
@ -53,6 +53,7 @@ public class ClientEquipState implements BehaviorTree {
|
||||
* @param equipPoints the list of available points
|
||||
*/
|
||||
private ClientEquipState(Entity parent, Object ... params){
|
||||
@SuppressWarnings("unchecked")
|
||||
List<EquipPoint> equipPoints = (List<EquipPoint>)params[0];
|
||||
this.parent = parent;
|
||||
for(EquipPoint point : equipPoints){
|
||||
|
||||
@ -60,6 +60,7 @@ public class ServerEquipState implements BehaviorTree {
|
||||
Map<String,Entity> equipMap = new HashMap<String,Entity>();
|
||||
|
||||
public ServerEquipState(Entity parent, Object ... params){
|
||||
@SuppressWarnings("unchecked")
|
||||
List<EquipPoint> equipPoints = (List<EquipPoint>)params[0];
|
||||
this.parent = parent;
|
||||
for(EquipPoint point : equipPoints){
|
||||
|
||||
@ -3,7 +3,6 @@ package electrosphere.entity.state.rotator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.joml.Quaterniond;
|
||||
import org.joml.Quaternionf;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
@ -58,16 +57,16 @@ public class RotatorTree implements BehaviorTree{
|
||||
|
||||
public void applyRotatorNode(RotatorHierarchyNode node){
|
||||
//apply
|
||||
String nodeBoneName = node.getBone();
|
||||
Quaterniond currentRotation = entityActor.getBoneRotation(nodeBoneName);
|
||||
// String nodeBoneName = node.getBone();
|
||||
// Quaterniond currentRotation = entityActor.getBoneRotation(nodeBoneName);
|
||||
for(RotatorConstraint constraint : node.getRotatorContraints()){
|
||||
float allowedMarginPitch = constraint.getAllowedMarginPitch();
|
||||
float allowedMarginYaw = constraint.getAllowedMarginYaw();
|
||||
// float allowedMarginPitch = constraint.getAllowedMarginPitch();
|
||||
// float allowedMarginYaw = constraint.getAllowedMarginYaw();
|
||||
boolean followsBone = constraint.getFollowsBone();
|
||||
boolean followsView = constraint.getFollowsView();
|
||||
if(followsBone){
|
||||
String parentBone = constraint.getParentBone();
|
||||
Quaterniond parentBoneRotation = entityActor.getBoneRotation(parentBone);
|
||||
// String parentBone = constraint.getParentBone();
|
||||
// Quaterniond parentBoneRotation = entityActor.getBoneRotation(parentBone);
|
||||
// currentRotation.
|
||||
}
|
||||
if(followsView){
|
||||
|
||||
@ -3,7 +3,6 @@ package electrosphere.entity.state.rotator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.joml.Quaterniond;
|
||||
import org.joml.Quaternionf;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
@ -58,16 +57,16 @@ public class ServerRotatorTree implements BehaviorTree{
|
||||
|
||||
public void applyRotatorNode(RotatorHierarchyNode node){
|
||||
//apply
|
||||
String nodeBoneName = node.getBone();
|
||||
Quaterniond currentRotation = entityPoseActor.getBoneRotation(nodeBoneName);
|
||||
// String nodeBoneName = node.getBone();
|
||||
// Quaterniond currentRotation = entityPoseActor.getBoneRotation(nodeBoneName);
|
||||
for(RotatorConstraint constraint : node.getRotatorContraints()){
|
||||
float allowedMarginPitch = constraint.getAllowedMarginPitch();
|
||||
float allowedMarginYaw = constraint.getAllowedMarginYaw();
|
||||
// float allowedMarginPitch = constraint.getAllowedMarginPitch();
|
||||
// float allowedMarginYaw = constraint.getAllowedMarginYaw();
|
||||
boolean followsBone = constraint.getFollowsBone();
|
||||
boolean followsView = constraint.getFollowsView();
|
||||
if(followsBone){
|
||||
String parentBone = constraint.getParentBone();
|
||||
Quaterniond parentBoneRotation = entityPoseActor.getBoneRotation(parentBone);
|
||||
// String parentBone = constraint.getParentBone();
|
||||
// Quaterniond parentBoneRotation = entityPoseActor.getBoneRotation(parentBone);
|
||||
// currentRotation.
|
||||
}
|
||||
if(followsView){
|
||||
|
||||
@ -451,6 +451,7 @@ public class ItemUtils {
|
||||
return item.containsKey(EntityDataStrings.ITEM_EQUIP_WHITELIST);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static List<EquipWhitelist> getEquipWhitelist(Entity item){
|
||||
return (List<EquipWhitelist>)item.getData(EntityDataStrings.ITEM_EQUIP_WHITELIST);
|
||||
}
|
||||
|
||||
@ -20,6 +20,7 @@ public class LoreProtocol implements ClientProtocolTemplate<LoreMessage> {
|
||||
switch(message.getMessageSubtype()){
|
||||
case RESPONSERACES:
|
||||
//we get back the race list as a json array, deserialize, and push into type loader
|
||||
@SuppressWarnings("unchecked")
|
||||
List<String> playableRaces = new Gson().fromJson(message.getdata(), List.class);
|
||||
Globals.gameConfigCurrent.getCreatureTypeLoader().loadPlayableRaces(playableRaces);
|
||||
break;
|
||||
|
||||
@ -77,99 +77,6 @@ public class Texture {
|
||||
Globals.renderingEngine.checkError();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
/**
|
||||
* Creates an in engine texture object from a java bufferedimage object
|
||||
* @param bufferedImage The java bufferedimage object
|
||||
*/
|
||||
public Texture(OpenGLState openGlState, BufferedImage bufferedImage){
|
||||
this.texturePointer = GL40.glGenTextures();
|
||||
Globals.renderingEngine.checkError();
|
||||
//bind the new texture
|
||||
openGlState.glBindTexture(GL_TEXTURE_2D, texturePointer);
|
||||
//how are we gonna wrap the texture??
|
||||
this.setWrap(openGlState, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT);
|
||||
this.setWrap(openGlState, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT);
|
||||
//set the border color to black
|
||||
this.setBorderColor(openGlState, new float[]{ 0.0f, 0.0f, 0.0f, 1.0f });
|
||||
//set magnification and minification operation sampling strategies
|
||||
this.setMinFilter(openGlState, GL_LINEAR);
|
||||
this.setMagFilter(openGlState, GL_LINEAR);
|
||||
//load the image here
|
||||
ByteBuffer data;
|
||||
width = 1;
|
||||
height = 1;
|
||||
BufferedImage image_data = bufferedImage;
|
||||
if (
|
||||
image_data.getType() == BufferedImage.TYPE_3BYTE_BGR ||
|
||||
image_data.getType() == BufferedImage.TYPE_INT_RGB
|
||||
){
|
||||
hasTransparency = false;
|
||||
} else if(
|
||||
image_data.getType() == BufferedImage.TYPE_4BYTE_ABGR ||
|
||||
image_data.getType() == BufferedImage.TYPE_INT_ARGB
|
||||
){
|
||||
hasTransparency = true;
|
||||
}
|
||||
width = image_data.getWidth();
|
||||
height = image_data.getHeight();
|
||||
if(hasTransparency){
|
||||
data = BufferUtils.createByteBuffer(width * height * 4);
|
||||
} else {
|
||||
data = BufferUtils.createByteBuffer(width * height * 3);
|
||||
}
|
||||
for(int y = height - 1; y > -1; y--){
|
||||
for(int x = 0; x < width; x++){
|
||||
int color = image_data.getRGB(x, y);
|
||||
|
||||
// data.put((byte)temp.getRed());
|
||||
// data.put((byte)temp.getGreen());
|
||||
// data.put((byte)temp.getBlue());
|
||||
if(hasTransparency){
|
||||
int blue = color & 0xff;
|
||||
int green = (color & 0xff00) >> 8;
|
||||
int red = (color & 0xff0000) >> 16;
|
||||
int alpha = (color & 0xff000000) >>> 24;
|
||||
data.put((byte)red);
|
||||
data.put((byte)green);
|
||||
data.put((byte)blue);
|
||||
data.put((byte)alpha);
|
||||
} else {
|
||||
int blue = color & 0xff;
|
||||
int green = (color & 0xff00) >> 8;
|
||||
int red = (color & 0xff0000) >> 16;
|
||||
data.put((byte)red);
|
||||
data.put((byte)green);
|
||||
data.put((byte)blue);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(data.position() > 0){
|
||||
data.flip();
|
||||
}
|
||||
//call if width != height so opengl figures out how to unpack it properly
|
||||
if(width != height){
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
}
|
||||
//buffer the texture information
|
||||
if(hasTransparency){
|
||||
this.pixelFormat = GL_RGBA;
|
||||
this.datatype = GL_UNSIGNED_BYTE;
|
||||
this.glTexImage2D(openGlState, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data);
|
||||
} else {
|
||||
this.pixelFormat = GL_RGB;
|
||||
this.datatype = GL_UNSIGNED_BYTE;
|
||||
this.glTexImage2D(openGlState, width, height, GL_RGB, GL_UNSIGNED_BYTE, data);
|
||||
}
|
||||
glGenerateMipmap(GL_TEXTURE_2D);
|
||||
//check build status
|
||||
String errorMessage = RenderingEngine.getErrorInEnglish(Globals.renderingEngine.getError());
|
||||
if(errorMessage != null){
|
||||
LoggerInterface.loggerRenderer.ERROR(new IllegalStateException("Texture Constructor[from bufferedimage]: " + errorMessage));
|
||||
}
|
||||
openGlState.glBindTexture(GL_TEXTURE_2D, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an in engine texture object from a java bufferedimage object
|
||||
* @param bufferedImage The java bufferedimage object
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
package electrosphere.renderer.ui.font;
|
||||
|
||||
import electrosphere.engine.Globals;
|
||||
import electrosphere.engine.assetmanager.queue.QueuedTexture;
|
||||
import electrosphere.logger.LoggerInterface;
|
||||
import electrosphere.renderer.OpenGLState;
|
||||
import electrosphere.renderer.model.Material;
|
||||
@ -184,8 +186,9 @@ public class FontUtils {
|
||||
|
||||
//create material with new font image
|
||||
Material uiMat = new Material();
|
||||
Texture texture = new Texture(openGLState, image);
|
||||
uiMat.setTexturePointer(texture.getTexturePointer());
|
||||
Globals.assetManager.queuedAsset(QueuedTexture.createFromImage(image, (Texture tex) -> {
|
||||
uiMat.setTexturePointer(tex.getTexturePointer());
|
||||
}));
|
||||
|
||||
|
||||
//construct final font object and return
|
||||
|
||||
@ -23,24 +23,44 @@ import electrosphere.util.FileUtils;
|
||||
*/
|
||||
public class ScriptContext {
|
||||
|
||||
//the default namespaces for
|
||||
public static String SCRIPT_NAMESPACE_ENGINE = "engine"; //namespace for the engine functions exposed to the script engine
|
||||
public static String SCRIPT_NAMESPACE_SCRIPT = "script"; //namespace for the core typescript functionsw
|
||||
public static String SCRIPT_NAMESPACE_SCENE = "scene"; //namespace for the current scene
|
||||
/**
|
||||
* namespace for the engine functions exposed to the script engine
|
||||
*/
|
||||
public static final String SCRIPT_NAMESPACE_ENGINE = "engine";
|
||||
|
||||
//the graal context
|
||||
/**
|
||||
* namespace for the core typescript functions
|
||||
*/
|
||||
public static final String SCRIPT_NAMESPACE_SCRIPT = "script";
|
||||
|
||||
/**
|
||||
* namespace for the current scene
|
||||
*/
|
||||
public static final String SCRIPT_NAMESPACE_SCENE = "scene";
|
||||
|
||||
/**
|
||||
* the graal context
|
||||
*/
|
||||
Context context;
|
||||
|
||||
//used to build source objects
|
||||
/**
|
||||
* used to build source objects
|
||||
*/
|
||||
Builder builder;
|
||||
|
||||
//the javascript object that stores values
|
||||
/**
|
||||
* the javascript object that stores values
|
||||
*/
|
||||
Value topLevelValue;
|
||||
|
||||
//the object that contains all host values accessible to javascript land
|
||||
/**
|
||||
* the object that contains all host values accessible to javascript land
|
||||
*/
|
||||
Value hostObject;
|
||||
|
||||
//the engine object
|
||||
/**
|
||||
* the engine object
|
||||
*/
|
||||
Value engineObject;
|
||||
|
||||
/**
|
||||
@ -148,7 +168,7 @@ public class ScriptContext {
|
||||
* Loads a script from disk
|
||||
* @param path The path to the script file
|
||||
*/
|
||||
void loadDependency(String path){
|
||||
private void loadDependency(String path){
|
||||
String content;
|
||||
Source source = null;
|
||||
try {
|
||||
@ -357,7 +377,7 @@ public class ScriptContext {
|
||||
* @param filePath The filepath of the module
|
||||
*/
|
||||
public void requireModule(String filePath){
|
||||
invokeFunction("require", filePath);
|
||||
this.invokeFunction("require", filePath);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -53,7 +53,9 @@ public class ScriptEngine extends SignalServiceImpl {
|
||||
*/
|
||||
public static final int GLOBAL_SCENE = -1;
|
||||
|
||||
//the map of script filepaths to parsed, in-memory scripts
|
||||
/**
|
||||
* the map of script filepaths to parsed, in-memory scripts
|
||||
*/
|
||||
Map<String,Source> sourceMap;
|
||||
|
||||
/**
|
||||
@ -81,7 +83,9 @@ public class ScriptEngine extends SignalServiceImpl {
|
||||
*/
|
||||
boolean initialized = false;
|
||||
|
||||
//The files that are loaded on init to bootstrap the script engine
|
||||
/**
|
||||
* The files that are loaded on init to bootstrap the script engine
|
||||
*/
|
||||
public static final String[] filesToLoadOnInit = new String[]{
|
||||
//polyfills
|
||||
"Scripts/compiler/require_polyfill.js",
|
||||
@ -102,8 +106,10 @@ public class ScriptEngine extends SignalServiceImpl {
|
||||
"/Scripts/compiler/host_access.ts",
|
||||
};
|
||||
|
||||
//The classes that will be provided to the scripting engine
|
||||
//https://stackoverflow.com/a/65942034
|
||||
/**
|
||||
* The classes that will be provided to the scripting engine
|
||||
* https://stackoverflow.com/a/65942034
|
||||
*/
|
||||
public static final Object[][] staticClasses = new Object[][]{
|
||||
{"mathUtils",SpatialMathUtils.class},
|
||||
{"simulation",Main.class},
|
||||
@ -116,7 +122,9 @@ public class ScriptEngine extends SignalServiceImpl {
|
||||
{"areaUtils",ScriptClientAreaUtils.class},
|
||||
};
|
||||
|
||||
//singletons from the host that are provided to the javascript context
|
||||
/**
|
||||
* singletons from the host that are provided to the javascript context
|
||||
*/
|
||||
public static final Object[][] hostSingletops = new Object[][]{
|
||||
{"timekeeper",Globals.timekeeper},
|
||||
{"currentPlayer",Globals.clientPlayer},
|
||||
|
||||
@ -48,7 +48,7 @@ public class FluidDiskMap {
|
||||
public void init(String saveName){
|
||||
LoggerInterface.loggerEngine.DEBUG("INIT CHUNK MAP " + saveName);
|
||||
if(FileUtils.getSaveFile(saveName, "chunk.map").exists()){
|
||||
worldPosFileMap = FileUtils.loadObjectFromSavePath(saveName, "fluid.map", Map.class);
|
||||
worldPosFileMap = FileUtils.loadObjectFromSavePath(saveName, "fluid.map", FluidDiskMap.class).worldPosFileMap;
|
||||
LoggerInterface.loggerEngine.DEBUG("POS FILE MAP: " + worldPosFileMap.keySet());
|
||||
} else {
|
||||
worldPosFileMap = new HashMap<String,String>();
|
||||
@ -59,7 +59,7 @@ public class FluidDiskMap {
|
||||
* Saves the disk map to disk
|
||||
*/
|
||||
public void save(){
|
||||
FileUtils.serializeObjectToSavePath(Globals.currentSave.getName(), "fluid.map", worldPosFileMap);
|
||||
FileUtils.serializeObjectToSavePath(Globals.currentSave.getName(), "fluid.map", this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
Reference in New Issue
Block a user