procedurally generated block item types

This commit is contained in:
austin 2025-01-24 17:34:49 -05:00
parent 0961b42e26
commit c2523b21bf
12 changed files with 134 additions and 13 deletions

View File

@ -1304,6 +1304,7 @@ Disable client fluid draw cell loading gate
Properly differentiate local/world bone attach point calculation
Floating origin implementation for collision engine
Improve initial asset loading performance
PoseModel creation for basic shape types

View File

@ -165,7 +165,7 @@ public class ClientFluidManager {
lock.lock();
for(FluidChunkGenQueueItem queueItem : fluidChunkGenerationQueue){
Model fluidModel = FluidChunkModelGeneration.generateFluidModel(queueItem.getData());
Globals.assetManager.registerModelToSpecificString(fluidModel, queueItem.getPromisedHash());
Globals.assetManager.registerModelWithPath(fluidModel, queueItem.getPromisedHash());
}
fluidChunkGenerationQueue.clear();
lock.unlock();

View File

@ -353,7 +353,7 @@ public class ClientTerrainManager {
lock.acquireUninterruptibly();
for(TerrainChunkGenQueueItem queueItem : terrainChunkGenerationQueue){
Model terrainModel = TransvoxelModelGeneration.generateTerrainModel(queueItem.getData(), queueItem.getAtlas());
Globals.assetManager.registerModelToSpecificString(terrainModel, queueItem.getPromisedHash());
Globals.assetManager.registerModelWithPath(terrainModel, queueItem.getPromisedHash());
if(queueItem.notifyTarget != null){
queueItem.notifyTarget.alertToGeneration();
}

View File

@ -83,6 +83,7 @@ import electrosphere.server.datacell.EntityDataCellMapper;
import electrosphere.server.datacell.RealmManager;
import electrosphere.server.db.DatabaseController;
import electrosphere.server.pathfinding.NavMeshManager;
import electrosphere.server.poseactor.PoseModel;
import electrosphere.server.saves.Save;
import electrosphere.server.simulation.MacroSimulation;
import electrosphere.server.simulation.MicroSimulation;
@ -642,9 +643,9 @@ public class Globals {
//create font manager
fontManager = new FontManager();
fontManager.loadFonts();
assetManager.registerModelToSpecificString(RenderUtils.createBitmapCharacter(), AssetDataStrings.BITMAP_CHARACTER_MODEL);
assetManager.registerModelWithPath(RenderUtils.createBitmapCharacter(), AssetDataStrings.BITMAP_CHARACTER_MODEL);
//particle billboard model
assetManager.registerModelToSpecificString(RenderUtils.createParticleModel(), AssetDataStrings.MODEL_PARTICLE);
assetManager.registerModelWithPath(RenderUtils.createParticleModel(), AssetDataStrings.MODEL_PARTICLE);
//initialize required windows
WindowUtils.initBaseWindows();
//init default shaderProgram
@ -655,9 +656,9 @@ public class Globals {
//init fluid shader program
FluidChunkModelGeneration.fluidChunkShaderProgram = VisualShader.loadSpecificShader("/Shaders/entities/fluid2/fluid2.vs", "/Shaders/entities/fluid2/fluid2.fs");
//init models
assetManager.registerModelToSpecificString(RenderUtils.createUnitsphere(), AssetDataStrings.UNITSPHERE);
assetManager.registerModelToSpecificString(RenderUtils.createUnitCylinder(), AssetDataStrings.UNITCYLINDER);
assetManager.registerModelToSpecificString(RenderUtils.createUnitCube(), AssetDataStrings.UNITCUBE);
assetManager.registerModelWithPath(RenderUtils.createUnitsphere(), AssetDataStrings.UNITSPHERE);
assetManager.registerModelWithPath(RenderUtils.createUnitCylinder(), AssetDataStrings.UNITCYLINDER);
assetManager.registerModelWithPath(RenderUtils.createUnitCube(), AssetDataStrings.UNITCUBE);
assetManager.addModelPathToQueue("Models/basic/geometry/SmallCube.fbx");
assetManager.addModelPathToQueue("Models/basic/geometry/unitcapsule.glb");
assetManager.addModelPathToQueue("Models/basic/geometry/unitplane.fbx");
@ -666,6 +667,13 @@ public class Globals {
assetManager.addShaderToQueue("Shaders/core/plane/plane.vs", "Shaders/core/plane/plane.fs");
solidPlaneModelID = assetManager.registerModel(RenderUtils.createInWindowPanel("Shaders/ui/plainBox/plainBox.vs", "Shaders/ui/plainBox/plainBox.fs"));
//init pose models for basic shapes
PoseModel emptyPoseModel = PoseModel.createEmpty();
assetManager.registerPoseModelWithPath(emptyPoseModel, AssetDataStrings.POSE_EMPTY);
assetManager.registerPoseModelWithPath(emptyPoseModel, AssetDataStrings.UNITSPHERE);
assetManager.registerPoseModelWithPath(emptyPoseModel, AssetDataStrings.UNITCYLINDER);
assetManager.registerPoseModelWithPath(emptyPoseModel, AssetDataStrings.UNITCUBE);
//image panel
ImagePanel.imagePanelModelPath = assetManager.registerModel(RenderUtils.createPlaneModel("Shaders/core/imagepanel/imagepanel.vs", "Shaders/core/imagepanel/imagepanel.fs"));

View File

@ -23,6 +23,7 @@ public class AssetDataStrings {
public static final String UNITCUBE = "unitCube";
public static final String MODEL_PARTICLE = "particleModel";
public static final String TEXTURE_PARTICLE = "particleTexture";
public static final String POSE_EMPTY = "poseEmpty";
/**
* UI textures

View File

@ -264,10 +264,6 @@ public class AssetManager {
public void registerModelWithPath(Model m, String path){
modelsLoadedIntoMemory.put(path, m);
}
public void registerModelToSpecificString(Model m, String s){
modelsLoadedIntoMemory.put(s,m);
}
public void deregisterModelPath(String path){
modelsLoadedIntoMemory.remove(path);
@ -341,6 +337,16 @@ public class AssetManager {
}
return rVal;
}
/**
* Registers a (presumably generated in code) pose model to a given path in the asset manager
* Used particularly if you have a specific path you want to relate to a specific pose model (eg basic shapes)
* @param m The pose model to register
* @param path The path to register the pose model to
*/
public void registerPoseModelWithPath(PoseModel m, String path){
poseModelsLoadedIntoMemory.put(path, m);
}

View File

@ -102,8 +102,9 @@ public class Config {
config.biomeMap = BiomeTypeMap.loadBiomeFile("Data/game/biomes.json");
config.samplerDefinitions = SamplerFile.readSamplerDefinitionFiles("Data/game/voxel");
//create furniture items
//create procedural item types
ItemDataMap.loadSpawnItems(config.itemMap, config.objectTypeLoader);
ItemDataMap.generateBlockItems(config.itemMap, config.blockData);
//validate
ConfigValidator.valdiate(config);

View File

@ -2,8 +2,12 @@ package electrosphere.game.data.item;
import java.util.Arrays;
import electrosphere.engine.assetmanager.AssetDataStrings;
import electrosphere.game.data.block.BlockType;
import electrosphere.game.data.common.CommonEntityType;
import electrosphere.game.data.common.item.SpawnItemDescription;
import electrosphere.game.data.graphics.GraphicsTemplate;
import electrosphere.game.data.graphics.NonproceduralModel;
/**
* Data on a given item
@ -84,7 +88,7 @@ public class Item extends CommonEntityType {
if(description.getGraphicsTemplate() != null){
rVal.setGraphicsTemplate(description.getGraphicsTemplate());
} else {
throw new Error("Need to implement handling for when no graphics template is providedd!");
throw new Error("Need to implement handling for when no graphics template is provided!");
}
@ -100,6 +104,42 @@ public class Item extends CommonEntityType {
return rVal;
}
/**
* Creates item data from a block type
* @param description The block type
* @return The item data
*/
public static Item createBlockItem(BlockType blockType){
Item rVal = new Item();
rVal.setId(blockType.getName());
if(blockType.getTexture() != null){
rVal.iconPath = blockType.getTexture();
} else {
rVal.iconPath = Item.DEFAULT_ITEM_ICON_PATH;
}
NonproceduralModel modelData = new NonproceduralModel();
modelData.setPath(AssetDataStrings.UNITCUBE);
GraphicsTemplate blockItemGraphicsTemplate = new GraphicsTemplate();
blockItemGraphicsTemplate.setModel(modelData);
rVal.setGraphicsTemplate(blockItemGraphicsTemplate);
//set usage
ItemUsage usage = new ItemUsage();
usage.setBlockId(blockType.getId());
rVal.setSecondaryUsage(usage);
//attach common tokens
rVal.setTokens(Arrays.asList(DEFAULT_TOKENS));
return rVal;
}
/**
* the idle animation for the item
* @return

View File

@ -9,6 +9,8 @@ import java.util.Set;
import electrosphere.entity.Entity;
import electrosphere.entity.types.item.ItemUtils;
import electrosphere.game.data.block.BlockData;
import electrosphere.game.data.block.BlockType;
import electrosphere.game.data.common.CommonEntityMap;
import electrosphere.game.data.common.CommonEntityType;
import electrosphere.util.FileUtils;
@ -130,4 +132,17 @@ public class ItemDataMap {
}
}
/**
* Loads all block types as items
* @param itemDataMap The item data map
* @param blockData The data on all block types
*/
public static void generateBlockItems(ItemDataMap itemDataMap, BlockData blockData){
for(BlockType blockType : blockData.getTypes()){
Item spawnItem = Item.createBlockItem(blockType);
//create spawn items
itemDataMap.putType(spawnItem.getId(), spawnItem);
}
}
}

View File

@ -10,6 +10,11 @@ public class ItemUsage {
*/
String spawnEntityId;
/**
* If defined, this item will place the block type on use
*/
Integer blockId;
/**
* Gets the spawn entity id of the item usage
* @return The spawn entity id
@ -26,6 +31,24 @@ public class ItemUsage {
this.spawnEntityId = spawnEntityId;
}
/**
* Gets the block type id of the item usage
* @return The block type id
*/
public Integer getBlockId() {
return blockId;
}
/**
* Sets the block type id of the item usage
* @param spawnEntityId The block type id
*/
public void setBlockId(Integer blockId) {
this.blockId = blockId;
}
}

View File

@ -13,6 +13,7 @@ import electrosphere.game.data.creature.type.CreatureData;
import electrosphere.game.data.creature.type.block.BlockVariant;
import electrosphere.game.data.item.Item;
import electrosphere.game.data.item.ItemUsage;
import electrosphere.logger.LoggerInterface;
import electrosphere.net.parser.net.message.InventoryMessage;
import electrosphere.net.server.ServerConnectionHandler;
import electrosphere.server.datacell.Realm;
@ -86,6 +87,10 @@ public class PlayerActions {
Vector3d spawnPos = new Vector3d(message.getviewTargetX(),message.getviewTargetY(),message.getviewTargetZ());
CommonEntityUtils.serverSpawnBasicObject(playerRealm, spawnPos, secondaryUsage.getSpawnEntityId());
}
if(secondaryUsage.getBlockId() != null){
Vector3d spawnPos = new Vector3d(message.getviewTargetX(),message.getviewTargetY(),message.getviewTargetZ());
LoggerInterface.loggerEngine.WARNING("Spawn block type " + secondaryUsage.getBlockId() + " at " + spawnPos);
}
}

View File

@ -40,6 +40,12 @@ public class PoseModel {
Map<String, Animation> animMap;
/**
* Private constructor for static creation methods
*/
private PoseModel(){
}
/**
* Constructor
* @param path Path on disk to this posemodel
@ -104,6 +110,21 @@ public class PoseModel {
}
}
/**
* Constructor
* @param path Path on disk to this posemodel
* @param scene The AI Scene parsed from the file on disk
*/
public static PoseModel createEmpty(){
PoseModel rVal = new PoseModel();
rVal.bones = new ArrayList<Bone>();
rVal.boneMap = new HashMap<String, Bone>();
rVal.nodeMap = new HashMap<String, AnimNode>();
rVal.animations = new ArrayList<Animation>();
rVal.animMap = new HashMap<String, Animation>();
return rVal;
}
/**
* Applies an animation to a certain set of bones