Skip to content

Commit

Permalink
Fixes #3324 by providing native M1 libraries to JOGL and JBullet
Browse files Browse the repository at this point in the history
Simplifies drastically the "GLAnimatorControl" hierarchy and removes the
legacy SWT GLCanvas to focus on NEWT Windows
  • Loading branch information
across committed Mar 19, 2022
1 parent 2bcdbce commit 03f4a03
Show file tree
Hide file tree
Showing 27 changed files with 399 additions and 916 deletions.
50 changes: 32 additions & 18 deletions msi.gama.core/src/msi/gama/runtime/PlatformHelper.java
@@ -1,12 +1,12 @@
/*******************************************************************************************************
*
* PlatformHelper.java, in msi.gama.core, is part of the source code of the
* GAMA modeling and simulation platform (v.1.8.2).
* PlatformHelper.java, in msi.gama.core, is part of the source code of the GAMA modeling and simulation platform
* (v.1.8.2).
*
* (c) 2007-2022 UMI 209 UMMISCO IRD/SU & Partners (IRIT, MIAT, TLU, CTU)
*
* Visit https://github.com/gama-platform/gama for license information and contacts.
*
*
********************************************************************************************************/
/*******************************************************************************
* Copyright (c) 2007-2008 SAS Institute Inc., ILOG S.A. All rights reserved. This program and the accompanying
Expand All @@ -29,13 +29,15 @@ public class PlatformHelper {
private static String platformString = Platform.getOS();

/** The is windows. */
private static boolean isWindows = "win32".equals(platformString);
private static boolean isWindows = "win32".equals(PlatformHelper.platformString);

/** The is mac. */
private static boolean isMac = "macosx".equals(platformString);
private static boolean isMac = "macosx".equals(PlatformHelper.platformString);

/** The is linux. */
private static boolean isLinux = "linux".equals(platformString);
private static boolean isLinux = "linux".equals(PlatformHelper.platformString);

private static boolean isARM = Platform.ARCH_AARCH64.equals(Platform.getOSArch());

/** The is developer. */
private static volatile Boolean isDeveloper;
Expand All @@ -50,33 +52,39 @@ private PlatformHelper() {}
*
* @return true, if is windows
*/
public static boolean isWindows() { return isWindows; }
public static boolean isWindows() {
return PlatformHelper.isWindows;
}

/**
* Checks if is linux.
*
* @return true, if is linux
*/
public static boolean isLinux() { return isLinux; }
public static boolean isLinux() {
return PlatformHelper.isLinux;
}

/**
* Checks if is mac.
*
* @return true, if is mac
*/
public static boolean isMac() { return isMac; }
public static boolean isMac() {
return PlatformHelper.isMac;
}

/**
* Checks if is developer.
*
* @return true, if is developer
*/
public static boolean isDeveloper() { // NO_UCD (unused code)
if (isDeveloper == null) {
isDeveloper = Platform.getInstallLocation() == null
if (PlatformHelper.isDeveloper == null) {
PlatformHelper.isDeveloper = Platform.getInstallLocation() == null
|| Platform.getInstallLocation().getURL().getPath().contains("org.eclipse.pde.core");
}
return isDeveloper;
return PlatformHelper.isDeveloper;
}

/**
Expand All @@ -95,21 +103,27 @@ public static boolean isDeveloper() { // NO_UCD (unused code)
* @return the int
*/
static int parseVersion(final String version) {
if (version == null) return 0;
if (version == null) { return 0; }
int major = 0, minor = 0, micro = 0;
final int length = version.length();
final var length = version.length();
int index = 0, start = 0;
while (index < length && Character.isDigit(version.charAt(index))) { index++; }
while (index < length && Character.isDigit(version.charAt(index))) {
index++;
}
try {
if (start < length) { major = Integer.parseInt(version.substring(start, index)); }
} catch (final NumberFormatException e) {}
start = ++index;
while (index < length && Character.isDigit(version.charAt(index))) { index++; }
while (index < length && Character.isDigit(version.charAt(index))) {
index++;
}
try {
if (start < length) { minor = Integer.parseInt(version.substring(start, index)); }
} catch (final NumberFormatException e) {}
start = ++index;
while (index < length && Character.isDigit(version.charAt(index))) { index++; }
while (index < length && Character.isDigit(version.charAt(index))) {
index++;
}
try {
if (start < length) { micro = Integer.parseInt(version.substring(start, index)); }
} catch (final NumberFormatException e) {}
Expand All @@ -129,7 +143,7 @@ public static int javaVersion(final int major, final int minor, final int micro)
}

public static boolean isARM() {
return Platform.ARCH_AARCH64.equals(Platform.getOSArch());
return PlatformHelper.isARM;
}

}
2 changes: 1 addition & 1 deletion simtools.gaml.extensions.physics/.classpath
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry exported="true" kind="lib" path="lib/Libbulletjme-11.0.0.jar" sourcepath="lib/Libbulletjme-11.0.0-sources.jar"/>
<classpathentry exported="true" kind="lib" path="lib/Libbulletjme-14.1.0.jar" sourcepath="lib/Libbulletjme-14.1.0-sources.jar"/>
<classpathentry exported="true" kind="lib" path="lib/native/"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
<attributes>
Expand Down
2 changes: 1 addition & 1 deletion simtools.gaml.extensions.physics/META-INF/MANIFEST.MF
Expand Up @@ -8,7 +8,7 @@ Require-Bundle: msi.gama.core,
org.eclipse.osgi
Bundle-ClassPath: .,
lib/native/,
lib/Libbulletjme-11.0.0.jar
lib/Libbulletjme-14.1.0.jar
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-17
Automatic-Module-Name: simtools.gaml.extensions.physics
Expand Down
2 changes: 1 addition & 1 deletion simtools.gaml.extensions.physics/build.properties
Expand Up @@ -6,7 +6,7 @@ bin.includes = META-INF/,\
plugin.xml,\
models/,\
lib/native/,\
lib/Libbulletjme-11.0.0.jar
lib/Libbulletjme-14.1.0.jar
bin.excludes = lib/Libbulletjme-11.0.0-sources.jar,\
external_src/jbullet-1.0.1-sources.jar
jre.compilation.profile = JavaSE-11
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Expand Up @@ -38,13 +38,15 @@ public class NativeLoader {
public static final String NATIVE_LIBRARY_LOCATION = "/lib/native/";

/** The Constant MAC_NATIVE_LIBRARY_NAME. */
public static final String MAC_NATIVE_LIBRARY_NAME = "libbulletjme.dylib";
public static final String MAC_NATIVE_LIBRARY_NAME = "MacOSX64ReleaseDp_libbulletjme.dylib";

public static final String MAC_ARM_NATIVE_LIBRARY_NAME = "MacOSX_ARM64ReleaseDp_libbulletjme.dylib";

/** The Constant WIN_NATIVE_LIBRARY_NAME. */
public static final String WIN_NATIVE_LIBRARY_NAME = "bulletjme.dll";
public static final String WIN_NATIVE_LIBRARY_NAME = "Windows64ReleaseDp_bulletjme.dll";

/** The Constant LIN_NATIVE_LIBRARY_NAME. */
public static final String LIN_NATIVE_LIBRARY_NAME = "libbulletjme.so";
public static final String LIN_NATIVE_LIBRARY_NAME = "Linux64ReleaseDp_libbulletjme.so";

/** The Load native library. */
public static boolean LoadNativeLibrary() {
Expand All @@ -66,6 +68,9 @@ public static boolean LoadNativeLibrary() {
case MacOSX64:
name = MAC_NATIVE_LIBRARY_NAME;
break;
case MacOSX_ARM64:
name = MAC_ARM_NATIVE_LIBRARY_NAME;
break;
default:
throw new RuntimeException("Platform " + platform + " is not supported");
}
Expand Down
Expand Up @@ -164,7 +164,9 @@ public PhysicalSimulationAgent(final IPopulation<? extends IAgent> s, final int
public Object primRegister(final IScope scope) {
IList<IAgent> agents = scope.getListArg(BODIES);
if (agents == null) return null;
for (IAgent agent : agents) { registerAgent(scope, agent); }
for (IAgent agent : agents) {
registerAgent(scope, agent);
}
return agents;
}

Expand Down Expand Up @@ -208,7 +210,9 @@ public void updateAgent(final IScope scope, final IAgent agent) {
* @return the terrain
*/
@getter (IPhysicalConstants.TERRAIN)
public IField getTerrain() { return terrain; }
public IField getTerrain() {
return terrain;
}

/**
* Sets the terrain.
Expand All @@ -217,7 +221,9 @@ public void updateAgent(final IScope scope, final IAgent agent) {
* the new terrain
*/
@setter (IPhysicalConstants.TERRAIN)
public void setTerrain(final IField t) { terrain = t; }
public void setTerrain(final IField t) {
terrain = t;
}

/**
* Gets the ccd.
Expand Down Expand Up @@ -406,10 +412,12 @@ protected void registerMicropopulation(final IScope scope, final ISpecies specie

@Override
public boolean doStep(final IScope scope) {
super.doStep(scope);
final Double timeStep = getTimeStep(scope);
getGateway().doStep(timeStep, maxSubSteps);
return true;
if (super.doStep(scope)) {
final Double timeStep = getTimeStep(scope);
getGateway().doStep(timeStep, maxSubSteps);
return true;
}
return false;
}

/**
Expand Down Expand Up @@ -457,18 +465,31 @@ public void notifyAgentAdded(final IScope scope, final IPopulation<? extends IAg
@Override
public void notifyAgentsAdded(final IScope scope, final IPopulation<? extends IAgent> pop,
final Collection<? extends IAgent> agents) {
if (automatedRegistration) { for (IAgent a : agents) { registerAgent(scope, a); } }
if (scope.interrupted()) return;

if (automatedRegistration) {
for (IAgent a : agents) {
registerAgent(scope, a);
}
}
}

@Override
public void notifyAgentsRemoved(final IScope scope, final IPopulation<? extends IAgent> pop,
final Collection<? extends IAgent> agents) {
for (IAgent a : agents) { unregisterAgent(scope, a); }
if (scope.interrupted()) return;

for (IAgent a : agents) {
unregisterAgent(scope, a);
}
}

@Override
public void notifyPopulationCleared(final IScope scope, final IPopulation<? extends IAgent> pop) {
for (IAgent a : pop) { unregisterAgent(scope, a); }
if (scope.interrupted()) return;
for (IAgent a : pop) {
unregisterAgent(scope, a);
}

}

Expand Down
@@ -1,7 +1,7 @@
/*******************************************************************************************************
*
* NativeBulletPhysicalWorld.java, in simtools.gaml.extensions.physics, is part of the source code of the
* GAMA modeling and simulation platform (v.1.8.2).
* NativeBulletPhysicalWorld.java, in simtools.gaml.extensions.physics, is part of the source code of the GAMA modeling
* and simulation platform (v.1.8.2).
*
* (c) 2007-2022 UMI 209 UMMISCO IRD/SU & Partners (IRIT, MIAT, TLU, CTU)
*
Expand Down Expand Up @@ -32,7 +32,8 @@ public class NativeBulletPhysicalWorld extends AbstractPhysicalWorld<PhysicsSpac
/**
* Instantiates a new native bullet physical world.
*
* @param physicalSimulationAgent the physical simulation agent
* @param physicalSimulationAgent
* the physical simulation agent
*/
public NativeBulletPhysicalWorld(final PhysicalSimulationAgent physicalSimulationAgent) {
super(physicalSimulationAgent);
Expand All @@ -52,6 +53,7 @@ protected IShapeConverter<CollisionShape, Vector3f> createShapeConverter() {
@Override
public PhysicsSpace createWorld() {
world = new PhysicsSpace(PhysicsSpace.BroadphaseType.DBVT);
// TODO Adopt the new API
world.addCollisionListener(contactListener);
setGravity(simulation.getGravity(simulation.getScope()));
setCCD(simulation.getCCD(simulation.getScope()));
Expand Down Expand Up @@ -91,6 +93,7 @@ public void setGravity(final GamaPoint g) {
public void dispose() {
if (world == null) return;
world.getRigidBodyList().forEach(world::removeCollisionObject);
world.freeUnusedObjects();
world = null;
}

Expand Down
Expand Up @@ -115,6 +115,6 @@ private static boolean get(final String name, final boolean def) {
* GLCanvas. Advantages are multiple (smaller memory footprint, immediate opening and resizing, etc.), and only a
* few glitches remain (esp. on macOS). True by defautl
*/
public static final boolean USE_NATIVE_OPENGL_WINDOW = get("use_native_opengl_window", true);
// public static final boolean USE_NATIVE_OPENGL_WINDOW = get("use_native_opengl_window", true);

}
Expand Up @@ -143,7 +143,7 @@ public void setCanvas(final GamaGLCanvas canvas) {

@Override
public void init(final GLAutoDrawable drawable) {
if (!FLAGS.USE_NATIVE_OPENGL_WINDOW) { WorkbenchHelper.asyncRun(() -> canvas.setVisible(visible)); }
// if (!FLAGS.USE_NATIVE_OPENGL_WINDOW) { WorkbenchHelper.asyncRun(() -> canvas.setVisible(visible)); }
openGL.setGL2(drawable.getGL().getGL2());
cameraHelper.initialize();
openGL.initializeGLStates(data.getBackgroundColor());
Expand Down
Expand Up @@ -439,8 +439,8 @@ public final void mouseMove(final org.eclipse.swt.events.MouseEvent e) {
* @return the int
*/
private int autoScaleUp(final int nb) {
if (FLAGS.USE_NATIVE_OPENGL_WINDOW) return nb;
return DPIHelper.autoScaleUp(nb);
return nb;
// return DPIHelper.autoScaleUp(nb);
}

@Override
Expand Down

0 comments on commit 03f4a03

Please sign in to comment.