Skip to content

Commit

Permalink
Progress on making things modular
Browse files Browse the repository at this point in the history
  • Loading branch information
ishland committed Mar 5, 2022
1 parent 2cfe711 commit aae7b2a
Show file tree
Hide file tree
Showing 148 changed files with 826 additions and 2,687 deletions.
224 changes: 136 additions & 88 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
plugins {
id 'java-library'
id 'fabric-loom' version '0.11-SNAPSHOT'
id 'io.github.juuxel.loom-quiltflower' version '1.6.0'
id 'maven-publish'
id 'com.github.johnrengelman.shadow' version '7.1.0'
id 'fabric-loom' version '0.11-SNAPSHOT' apply false
id 'io.github.juuxel.loom-quiltflower' version '1.6.0' apply false
id "me.champeau.jmh" version "0.6.6"
}

@SuppressWarnings('unused')
static def moduleDependencies(project, List<String> depNames) {
project.dependencies {
depNames.each {
api project.dependencies.project(path: ":$it", configuration: 'namedElements')
}
}
}

allprojects {
archivesBaseName = "${project.archives_base_name}-mc${project.minecraft_version}"
archivesBaseName = "${project.name}-mc${project.minecraft_version}"
group = project.maven_group
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
version = project.mod_version + "." + getVersionSuffix()

repositories {
maven { url 'https://jitpack.io' }
}

if (plugins.hasPlugin("fabric-loom")) {
loom {
shareRemapCaches = true
}
}
afterEvaluate {
if (plugins.hasPlugin("fabric-loom")) {
migrateMappings.configure {
Expand All @@ -32,102 +30,156 @@ allprojects {
}
}

afterEvaluate {
logger.lifecycle("Version String: ${version}")
}
configure (allprojects - project(":tests")) {
if (project != rootProject && project.parent != rootProject) return

loom {
accessWidenerPath = file("src/main/resources/c2me.accesswidener")
}
apply plugin: 'fabric-loom'
apply plugin: 'io.github.juuxel.loom-quiltflower'
apply plugin: 'java-library'
apply plugin: 'maven-publish'

configurations {
api.extendsFrom includeApi
implementation.extendsFrom shadowImpl
runtimeOnly.extendsFrom shadowRuntime
}
sourceSets {
devlaunch {
compileClasspath += main.compileClasspath
runtimeClasspath += main.runtimeClasspath
}
}

dependencies {
//to change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
api "net.fabricmc:yarn:${project.yarn_mappings}:v2" // loom bug?
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"

includeApi project(":libs")
include project(":libs")
shadowImpl "com.ibm.async:asyncutil:${async_util_version}"
shadowImpl "com.electronwill.night-config:toml:${night_config_version}"
shadowImpl "org.threadly:threadly:${threadly_version}"
repositories {
maven { url 'https://jitpack.io' }
}

afterEvaluate {
project(":compatibility").subprojects.each {
shadowRuntime(it) {
transitive false
dependencies {
//to change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"

implementation "com.ibm.async:asyncutil:${async_util_version}"
implementation "com.electronwill.night-config:toml:${night_config_version}"
implementation "org.threadly:threadly:${threadly_version}"
}

loom {
def awFile = file("src/main/resources/${project.name}.accesswidener")
if (awFile.isFile()) {
project.logger.lifecycle("Adding " + awFile)
accessWidenerPath = awFile
}

runs {
devlaunchClient {
client()
ideConfigGenerated project.rootProject == project
name = "DevLaunch Client"
source sourceSets.devlaunch
}
devlaunchServer {
server()
ideConfigGenerated project.rootProject == project
name = "DevLaunch Server"
source sourceSets.devlaunch
}
}
}

// PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs.
// You may need to force-disable transitiveness on them.
processResources {
inputs.property "version", project.version

// jmh
afterEvaluate {
jmh project.sourceSets.main.compileClasspath
filesMatching("fabric.mod.json") {
expand "version": project.version
}
}
}

processResources {
inputs.property "version", project.version
jar {
from rootProject.file("LICENSE")
}

filesMatching("fabric.mod.json") {
expand "version": project.version
java {
withSourcesJar()
}

// ensure that the encoding is set to UTF-8, no matter what the system default is
// this fixes some edge cases with special characters not displaying correctly
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}

// reproducible
tasks.withType(AbstractArchiveTask) {
preserveFileTimestamps = false
reproducibleFileOrder = true
}
}

// ensure that the encoding is set to UTF-8, no matter what the system default is
// this fixes some edge cases with special characters not displaying correctly
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
// configure the maven publication
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}

// select the repositories you want to publish to
repositories {
// uncomment to publish to the local maven
// mavenLocal()
}
}
}

jar {
from "LICENSE"
subprojects {
afterEvaluate {
genSourcesWithFernFlower.enabled = false
genSourcesWithQuiltflower.enabled = false
genSourcesWithCfr.enabled = false
unpickJar.enabled = false
}
}

shadowJar {
archiveClassifier = "all-dev"
configurations = [ project.configurations.shadowImpl, project.configurations.shadowRuntime ]
from "LICENSE"
afterEvaluate {
logger.lifecycle("Version String: ${version}")
}

//noinspection UnnecessaryQualifiedReference
task("remapShadowJar", type: net.fabricmc.loom.task.RemapJarTask, dependsOn: shadowJar) {
input = shadowJar.archiveFile
archiveFileName = shadowJar.archiveFileName.get().replaceAll("-dev\\.jar\$", ".jar")
addNestedDependencies = true
project(":libs").afterEvaluate {
dependsOn(project(":libs").assemble)
dependencies {
// includeApi project(":libs")
// include project(":libs")
include implementation("com.ibm.async:asyncutil:${async_util_version}")
include implementation("com.electronwill.night-config:toml:${night_config_version}")
include implementation("org.threadly:threadly:${threadly_version}")

// PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs.
// You may need to force-disable transitiveness on them.

// jmh
afterEvaluate {
jmh project.sourceSets.main.compileClasspath
}
}

assemble.dependsOn(remapShadowJar)

// configure the maven publication
publishing {
publications {
mavenJava(MavenPublication) {
// add all the jars that should be included when publishing to maven
artifact(remapJar) {
builtBy remapJar
}
loom {
runs {
server {
inherit devlaunchServer
}
client {
inherit devlaunchClient
}
}
}

// select the repositories you want to publish to
repositories {
// uncomment to publish to the local maven
// mavenLocal()
subprojects.forEach { remapJar.dependsOn("${it.path}:remapJar") }

dependencies {
afterEvaluate {
(subprojects - project(":tests")).forEach {
if (it.parent != rootProject) return

api project(path: ":${it.name}", configuration: "namedElements")
include project("${it.name}:")

devlaunchImplementation project("${it.name}:").sourceSets.devlaunch.output
}
}
}

Expand All @@ -154,10 +206,6 @@ String getVersionSuffix() {
return split[split.length - 2] + suffix
}

shadowJar {
// minimize()
}

jmh {
// includes = ['some regular expression'] // include pattern (regular expression) for benchmarks to be executed
// excludes = ['some regular expression'] // exclude pattern (regular expression) for benchmarks to be executed
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.ishland.c2me.base;

import com.ishland.c2me.base.common.config.ConfigSystem;
import io.netty.util.internal.PlatformDependent;
import net.fabricmc.api.EnvType;
import net.fabricmc.loader.api.FabricLoader;

public class ModuleEntryPoint {

private static final boolean enabled = true;

public static final long globalExecutorParallelism = new ConfigSystem.ConfigAccessor()
.key("globalExecutorParallelism")
.comment("Configures the parallelism of global executor")
.getLong(getDefaultGlobalExecutorParallelism(), getDefaultGlobalExecutorParallelism(), ConfigSystem.LongChecks.THREAD_COUNT);

private static int getDefaultGlobalExecutorParallelism() {
return Math.max(1, Math.min(getDefaultParallelismCPU(), getDefaultParallelismHeap()));
}

private static int getDefaultParallelismCPU() {
if (PlatformDependent.isWindows()) {
return Math.max(1, (int) (Runtime.getRuntime().availableProcessors() / 1.6 - 2)) + defaultParallelismEnvTypeOffset();
} else {
return Math.max(1, (int) (Runtime.getRuntime().availableProcessors() / 1.2 - 2)) + defaultParallelismEnvTypeOffset();
}
}

private static int defaultParallelismEnvTypeOffset() {
return isClientSide() ? -2 : 0;
}

private static boolean isClientSide() {
return FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT;
}

private static int getDefaultParallelismHeap() {
if (PlatformDependent.isJ9Jvm()) {
return (int) ((memoryInGiB() + (isClientSide() ? -0.6 : -0.2)) / 0.5) + defaultParallelismEnvTypeOffset();
} else {
return (int) ((memoryInGiB() + (isClientSide() ? -1.8 : -0.6)) / 1.4) + defaultParallelismEnvTypeOffset();
}
}

private static double memoryInGiB() {
return Runtime.getRuntime().maxMemory() / 1024.0 / 1024.0 / 1024.0;
}


}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.ishland.c2me.common;
package com.ishland.c2me.base.common;

import com.ishland.c2me.common.config.C2MEConfig;
import com.ishland.c2me.common.util.C2MEForkJoinWorkerThreadFactory;
import com.ishland.c2me.base.ModuleEntryPoint;
import com.ishland.c2me.base.common.util.C2MEForkJoinWorkerThreadFactory;

import java.util.concurrent.Executor;
import java.util.concurrent.ForkJoinPool;
Expand All @@ -10,7 +10,7 @@ public class GlobalExecutors {

private static final C2MEForkJoinWorkerThreadFactory factory = new C2MEForkJoinWorkerThreadFactory("c2me", "C2ME worker #%d", Thread.NORM_PRIORITY - 1);
public static final ForkJoinPool executor = new ForkJoinPool(
C2MEConfig.globalExecutorParallelism,
(int) ModuleEntryPoint.globalExecutorParallelism,
factory,
null,
true
Expand Down
Loading

0 comments on commit aae7b2a

Please sign in to comment.