Skip to content

Commit

Permalink
Started overhauling and making a new loading pipeline that is way mor…
Browse files Browse the repository at this point in the history
…e clean.
  • Loading branch information
Hilligans committed Feb 24, 2024
1 parent e0b0e6c commit e6571d1
Show file tree
Hide file tree
Showing 44 changed files with 1,154 additions and 123 deletions.
44 changes: 28 additions & 16 deletions src/main/java/dev/hilligans/ourcraft/ClientMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
import dev.hilligans.ourcraft.client.rendering.graphics.api.IGraphicsEngine;
import dev.hilligans.ourcraft.client.rendering.newrenderer.TextureAtlas;
import dev.hilligans.ourcraft.data.other.BoundingBox;
import dev.hilligans.ourcraft.mod.handler.pipeline.standard.StandardPipeline;
import dev.hilligans.ourcraft.util.ArgumentContainer;
import dev.hilligans.ourcraft.util.Side;
import org.joml.Intersectionf;
import org.joml.Math;
import org.joml.Vector2f;

import java.io.IOException;
import java.util.function.Consumer;

public class ClientMain {

Expand All @@ -29,8 +31,31 @@ public static void main(String[] args) throws IOException {
GameInstance gameInstance = Ourcraft.GAME_INSTANCE;
gameInstance.handleArgs(args);
gameInstance.side = Side.CLIENT;
gameInstance.loadContent();
gameInstance.THREAD_PROVIDER.map();
gameInstance.POST_CORE_HOOKS.add(gameInstance1 -> new Thread(() -> {

gameInstance1.THREAD_PROVIDER.map();

Client client = new Client(gameInstance1, argumentContainer);
//Client client1 = new Client(gameInstance, argumentContainer);
String graphicsEngine = argumentContainer.getString("--graphicsEngine", null);
if(graphicsEngine != null) {
System.out.println(graphicsEngine);
client.setGraphicsEngine(gameInstance1.GRAPHICS_ENGINES.get(graphicsEngine));
// client1.setGraphicsEngine(gameInstance.GRAPHICS_ENGINES.get(graphicsEngine));
}
//client1.setupClient();
client.startClient();


gameInstance1.THREAD_PROVIDER.EXECUTOR.shutdownNow();
if(argumentContainer.getBoolean("--integratedServer", false)) {
ServerMain.getServer().stop();
}
System.exit(0);

}).start());


Thread serverThread = null;
if(argumentContainer.getBoolean("--integratedServer", false)) {
Expand All @@ -44,22 +69,9 @@ public static void main(String[] args) throws IOException {
}
}

Client client = new Client(gameInstance, argumentContainer);
Client client1 = new Client(gameInstance, argumentContainer);
String graphicsEngine = argumentContainer.getString("--graphicsEngine", null);
if(graphicsEngine != null) {
System.out.println(graphicsEngine);
client.setGraphicsEngine(gameInstance.GRAPHICS_ENGINES.get(graphicsEngine));
client1.setGraphicsEngine(gameInstance.GRAPHICS_ENGINES.get(graphicsEngine));
}
client1.setupClient();
client.startClient();
StandardPipeline.get(gameInstance).build();


gameInstance.THREAD_PROVIDER.EXECUTOR.shutdownNow();
if(argumentContainer.getBoolean("--integratedServer", false)) {
ServerMain.getServer().stop();
}
System.exit(0);
//gameInstance.loadContent();
}
}
10 changes: 10 additions & 0 deletions src/main/java/dev/hilligans/ourcraft/GameInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Consumer;

public class GameInstance {

public final ArrayList<Consumer<GameInstance>> POST_CORE_HOOKS = new ArrayList<>();
public final EventBus EVENT_BUS = new EventBus();
public final ModLoader MOD_LOADER = new ModLoader(this);
public final Logger LOGGER = new Logger("", "");
Expand All @@ -72,6 +74,8 @@ public class GameInstance {

public final int gameInstanceUniversalID;

public boolean built = false;

public final ToolLevelList MATERIAL_LIST = new ToolLevelList();

public GameInstance() {
Expand Down Expand Up @@ -116,6 +120,12 @@ public void loadContent() {
REBUILDING.set(false);
}

public void runPostCoreHooks() {
for(Consumer<GameInstance> consumer : POST_CORE_HOOKS) {
consumer.accept(this);
}
}

public void build(IGraphicsEngine<?,?,?> graphicsEngine, GraphicsContext graphicsContext) {
for(Registry<?> registry : REGISTRIES.ELEMENTS) {
for(Object o : registry.ELEMENTS) {
Expand Down
74 changes: 66 additions & 8 deletions src/main/java/dev/hilligans/ourcraft/Ourcraft.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
package dev.hilligans.ourcraft;

import dev.hilligans.ourcraft.biome.Biome;
import dev.hilligans.ourcraft.biome.Biomes;
import dev.hilligans.ourcraft.block.Block;
import dev.hilligans.ourcraft.client.audio.SoundBuffer;
import dev.hilligans.ourcraft.client.audio.Sounds;
import dev.hilligans.ourcraft.client.ChatWindow;
import dev.hilligans.ourcraft.client.Client;
import dev.hilligans.ourcraft.client.input.InputHandlerProvider;
import dev.hilligans.ourcraft.client.input.handler.providers.ControllerHandlerProvider;
import dev.hilligans.ourcraft.client.input.handler.providers.KeyPressHandlerProvider;
import dev.hilligans.ourcraft.client.input.handler.providers.MouseHandlerProvider;
import dev.hilligans.ourcraft.client.input.Input;
import dev.hilligans.ourcraft.client.input.RepeatingInput;
import dev.hilligans.ourcraft.client.input.handlers.MouseHandler;
import dev.hilligans.ourcraft.client.rendering.Texture;
import dev.hilligans.ourcraft.client.rendering.graphics.api.IGraphicsEngine;
import dev.hilligans.ourcraft.client.rendering.graphics.api.ILayoutEngine;
import dev.hilligans.ourcraft.client.rendering.graphics.fixedfunctiongl.FixedFunctionGLEngine;
import dev.hilligans.ourcraft.client.rendering.graphics.implementations.WorldCamera;
import dev.hilligans.ourcraft.client.rendering.graphics.nuklear.NuklearLayoutEngine;
Expand All @@ -20,21 +26,35 @@
import dev.hilligans.ourcraft.client.rendering.ScreenBuilder;
import dev.hilligans.ourcraft.client.rendering.screens.*;
import dev.hilligans.ourcraft.client.rendering.Textures;
import dev.hilligans.ourcraft.command.CommandHandler;
import dev.hilligans.ourcraft.data.descriptors.Tag;
import dev.hilligans.ourcraft.data.primitives.Tuple;
import dev.hilligans.ourcraft.item.Items;
import dev.hilligans.ourcraft.item.data.ToolLevel;
import dev.hilligans.ourcraft.mod.handler.ModClass;
import dev.hilligans.ourcraft.mod.handler.content.CoreExtensionView;
import dev.hilligans.ourcraft.mod.handler.content.ModContent;
import dev.hilligans.ourcraft.mod.handler.Identifier;
import dev.hilligans.ourcraft.mod.handler.content.RegistryView;
import dev.hilligans.ourcraft.network.Protocol;
import dev.hilligans.ourcraft.network.Protocols;
import dev.hilligans.ourcraft.recipe.IRecipe;
import dev.hilligans.ourcraft.recipe.helper.RecipeView;
import dev.hilligans.ourcraft.resource.loaders.ResourceLoader;
import dev.hilligans.ourcraft.resource.loaders.StringLoader;
import dev.hilligans.ourcraft.resource.registry.loaders.JsonRegistryLoader;
import dev.hilligans.ourcraft.resource.loaders.ImageLoader;
import dev.hilligans.ourcraft.resource.loaders.JsonLoader;
import dev.hilligans.ourcraft.resource.ResourceManager;
import dev.hilligans.ourcraft.resource.registry.loaders.RegistryLoader;
import dev.hilligans.ourcraft.schematic.LitematicaSchematicLoader;
import dev.hilligans.ourcraft.settings.Setting;
import dev.hilligans.ourcraft.util.ArgumentContainer;
import dev.hilligans.ourcraft.util.NamedThreadFactory;
import at.favre.lib.crypto.bcrypt.BCrypt;
import dev.hilligans.ourcraft.util.Side;
import dev.hilligans.ourcraft.util.registry.IRegistryElement;
import dev.hilligans.ourcraft.util.registry.Registry;
import dev.hilligans.ourcraft.world.Feature;
import dev.hilligans.ourcraft.world.newworldsystem.ChainedBlockChunkStream;
import dev.hilligans.ourcraft.world.newworldsystem.ChunkStream;
import dev.hilligans.ourcraft.block.Blocks;
Expand All @@ -47,13 +67,10 @@
import java.io.File;
import java.nio.DoubleBuffer;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.function.BiConsumer;

import static org.lwjgl.glfw.GLFW.*;

public class Ourcraft {
public class Ourcraft extends ModClass {

public static final GameInstance GAME_INSTANCE = new GameInstance();
public static final ArgumentContainer getArgumentContainer() {
Expand Down Expand Up @@ -81,7 +98,48 @@ public static File getFile(String path) {
return new File(Ourcraft.path + "/" + path);
}

public static void registerCoreExtensions(CoreExtensionView view) {

@Override
public String getModID() {
return "ourcraft";
}

@Override
public void registerRegistries(RegistryView view) {
Tuple<Class<? extends IRegistryElement>, String>[] elements = new Tuple[]{
new Tuple(Block.class, "block"),
new Tuple(Items.class, "item"),
new Tuple(Biome.class, "biome"),
new Tuple(Tag.class, "tag"),
new Tuple(IRecipe.class, "recipe"),
new Tuple(RecipeView.class, "recipe_view"),
new Tuple(IGraphicsEngine.class, "graphics_engine"),
new Tuple(CommandHandler.class, "command"),
new Tuple(Protocol.class, "protocol"),
new Tuple(Setting.class, "setting"),
new Tuple(ResourceLoader.class, "resource_loader"),
new Tuple(SoundBuffer.class, "sound"),
new Tuple(ToolLevel.class, "tool_level"),
new Tuple(RegistryLoader.class, "registry_loader"),
new Tuple(ScreenBuilder.class, "screen"),
new Tuple(Feature.class, "feature"),
new Tuple(RenderTarget.class, "render_target"),
new Tuple(RenderPipeline.class, "render_pipeline"),
new Tuple(RenderTaskSource.class, "render_task"),
new Tuple(Input.class, "key_bind"),
new Tuple(VertexFormat.class, "vertex_format"),
new Tuple(InputHandlerProvider.class, "input"),
new Tuple(Texture.class, "texture"),
new Tuple(ShaderSource.class, "shader"),
new Tuple(ILayoutEngine.class, "layout_engine")
};

for(Tuple<Class<? extends IRegistryElement>, String> element : elements) {
view.registerRegistry(() -> new Registry<>(view.getGameInstance(), element.getTypeA(), element.getTypeB()));
}
}

public void registerCoreExtensions(CoreExtensionView view) {
view.registerRegistryLoader(new JsonRegistryLoader(new Identifier("tool_tiers", "ourcraft"), "Data/ToolTiers.json", (modContent1, jsonObject, string) -> {
JSONArray elements = jsonObject.getJSONArray("material");
ToolLevel[] levels = new ToolLevel[elements.length()];
Expand Down Expand Up @@ -177,9 +235,9 @@ public static void registerCoreExtensions(CoreExtensionView view) {

public static void registerDefaultContent(ModContent modContent) {
//temporarily
registerCoreExtensions(modContent.getCoreView());
//registerCoreExtensions(modContent.getCoreView());

chainedChunkStream.assignModContent(modContent);
chainedChunkStream.assignOwner(modContent);
modContent.registerResourceLoader(new JsonLoader(), new ImageLoader(), new StringLoader());
modContent.registerResourceLoader(new LitematicaSchematicLoader());

Expand Down
8 changes: 7 additions & 1 deletion src/main/java/dev/hilligans/ourcraft/biome/Biome.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import dev.hilligans.ourcraft.GameInstance;
import dev.hilligans.ourcraft.block.Block;
import dev.hilligans.ourcraft.block.Blocks;
import dev.hilligans.ourcraft.mod.handler.content.ModContainer;
import dev.hilligans.ourcraft.mod.handler.content.ModContent;
import dev.hilligans.ourcraft.util.registry.IRegistryElement;
import dev.hilligans.ourcraft.world.builders.WorldBuilder;
Expand All @@ -15,7 +16,7 @@ public class Biome implements IRegistryElement {

public String name;
public int terrainHeight = 10;
public ModContent source;
public ModContainer source;

public Vector3i terrainHeights = new Vector3i(0,5,5);

Expand Down Expand Up @@ -68,6 +69,11 @@ public Biome setParams(float temp, float humidity, float noise, float rand, floa
public void load(GameInstance gameInstance) {
}

@Override
public void assignOwner(ModContainer owner) {
this.source = owner;
}

@Override
public String getResourceName() {
return name;
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/dev/hilligans/ourcraft/block/Block.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ public Block setBlockDrop(Block blockDrop) {
return this;
}



public void setModContent(ModContent modContent) {
this.modId = modContent.getModID();
this.modContent = modContent;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package dev.hilligans.ourcraft.client.input;

import dev.hilligans.ourcraft.client.rendering.graphics.api.IInputProvider;
import dev.hilligans.ourcraft.mod.handler.content.ModContainer;
import dev.hilligans.ourcraft.mod.handler.content.ModContent;
import dev.hilligans.ourcraft.util.registry.IRegistryElement;

public abstract class InputHandlerProvider implements IRegistryElement {

public String name;
public ModContent modContent;
public ModContainer owner;

public InputHandlerProvider(String name) {
this.name = name;
Expand All @@ -16,8 +17,8 @@ public InputHandlerProvider(String name) {
public abstract IInputProvider getProvider(String engineName, String windowingName);

@Override
public void assignModContent(ModContent modContent) {
this.modContent = modContent;
public void assignOwner(ModContainer modContent) {
this.owner = modContent;
}

@Override
Expand All @@ -27,7 +28,7 @@ public String getResourceName() {

@Override
public String getResourceOwner() {
return modContent.getModID();
return owner.getModID();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import dev.hilligans.ourcraft.client.rendering.graphics.RenderWindow;
import dev.hilligans.ourcraft.GameInstance;
import dev.hilligans.ourcraft.client.rendering.graphics.api.GraphicsContext;
import dev.hilligans.ourcraft.mod.handler.content.ModContainer;
import dev.hilligans.ourcraft.mod.handler.content.ModContent;
import dev.hilligans.ourcraft.util.registry.IRegistryElement;
import org.json.JSONArray;
Expand All @@ -16,7 +17,7 @@ public class ScreenBuilder implements IRegistryElement {

public ArrayList<TextureElement> textures = new ArrayList<>();
public String name;
public ModContent modContent;
public ModContainer owner;

public ScreenBuilder(String name, JSONObject jsonObject) {
this.name = name;
Expand All @@ -31,10 +32,10 @@ public ScreenBuilder(String name, JSONObject jsonObject) {
}

@Override
public void assignModContent(ModContent modContent) {
this.modContent = modContent;
public void assignOwner(ModContainer owner) {
this.owner = owner;
for(TextureElement textureElement : textures) {
modContent.registerTexture(textureElement.texture);
owner.registerTexture(textureElement.texture);
}
}

Expand Down Expand Up @@ -83,7 +84,7 @@ public String getResourceName() {

@Override
public String getResourceOwner() {
return modContent.getModID();
return owner.getModID();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import dev.hilligans.ourcraft.client.rendering.graphics.ShaderSource;
import dev.hilligans.ourcraft.client.rendering.newrenderer.Image;
import dev.hilligans.ourcraft.GameInstance;
import dev.hilligans.ourcraft.mod.handler.content.ModContainer;
import dev.hilligans.ourcraft.mod.handler.content.ModContent;
import dev.hilligans.ourcraft.resource.ResourceLocation;
import dev.hilligans.ourcraft.util.UniqueResource;
Expand All @@ -19,7 +20,7 @@
public class Texture implements IRegistryElement, IGraphicsElement {

public String path;
public ModContent source;
public ModContainer source;

public long textureId = -1;
public ShaderSource shaderSource;
Expand Down Expand Up @@ -129,8 +130,8 @@ public String getResourceType() {
return "texture";
}
@Override
public void assignModContent(ModContent modContent) {
this.source = modContent;
public void assignOwner(ModContainer source) {
this.source = source;
}

@Override
Expand Down
Loading

0 comments on commit e6571d1

Please sign in to comment.