-
Notifications
You must be signed in to change notification settings - Fork 0
Configure Your Simulation Project
This page provides step-by-step instructions for setting up a minimal OIS project.
To get started, create a new directory for your project and navigate into it:
mkdir my-simulation-project
cd my-simulation-projectNext, initialize a new Gradle project:
gradle init --type java-libraryOpen the build.gradle file generated in the project root directory and add the following configuration to apply the OIS simulation plugin:
plugins {
id 'org.ois.simulation' version '1.0-SNAPSHOT'
}Next, you need to modify the settings.gradle file to specify where to find the OIS simulation plugin since it is not publicly available. Open the settings.gradle file and add the following configuration:
pluginManagement {
repositories {
mavenLocal()
}
}This configuration tells Gradle to look for plugins in your local Maven repository.
In a simulation, there are various phases or "states" (e.g., menus, gameplay, pause screens) that can occur. The IState interface allows you to define how these states behave when they are entered, updated, or exited, among other lifecycle methods.
The core methods in the IState interface include:
-
enter: Invoked when entering the state. -
exit: Invoked when exiting the state. -
pause: Pauses the state. -
resume: Resumes the state after a pause. -
resize: Handles resizing the state (e.g., when the window changes size). -
render: Handles drawing the state. -
update: Updates the state logic. -
dispose: Releases resources when the state is no longer needed.
create a class that implements the IState interface. Each method in the interface must be implemented, even if some methods are left empty
package org.mypackage;
import org.ois.core.state.IState;
public class MyState implements IState {
@Override
public void enter(Object... parameters) {
// Logic when entering the state.
// Optional: Handle any parameters passed to this state.
}
@Override
public void exit() {
// Logic when exiting the state.
}
@Override
public void pause() {
// Logic when the application is paused at the state.
}
@Override
public void resume() {
// Logic when the application is resume at the state.
}
@Override
public void resize(int width, int height) {
// Logic to handle state resizing.
}
@Override
public void render() {
// Logic to render the state (e.g., drawing elements on screen).
}
@Override
public boolean update(float dt) {
// Update the state logic (e.g., physics, game events).
// Return true to keep the state active, or false to exit the state.
return true;
}
@Override
public void dispose() {
// Clean up resources when the state is no longer needed.
}
}Create a directory named simulation in your project root directory, this directory will hold all of your project configurations and assets.
The simulation.ois file is a JSON configuration file used to define the settings for your simulation.
This file allows you to specify the title, initial state, available states, target platforms, and screen dimensions for the simulation.
A file named simulation.ois
-
title(Optional): The title of your simulation, which may be displayed in the window title bar or launcher, depending on the platform. -
states: A map of all of the project implementations ofIStatemapped to a unique key to identify them. -
initialState: Specifies the state in which the simulation should start. This must correspond to one of the states defined in the states section. -
runner(Optional): Defines the simulation runner configurations such as the intended platform for the simulation and its screen dimensions.-
platforms: An array of platforms on which the simulation can run. If no platforms are specified, the simulation will run on all available platforms by default. -
screenWidth: The width of the simulation screen. A value of0means the screen will dynamically fill the available space (this is the default behavior). -
screenHeight: The height of the simulation screen. A value of0means the screen will dynamically fill the available space (this is the default behavior).
-
Here is the structure of a typical simulation.ois file:
{
"title": "My Simulation Title"
"initialState": "MyState",
"states": {
"MyState": "org.mypackage.MyState"
},
"runner": {
"platforms": [ "Html", "Desktop", "Android" ],
"screenWidth": 0,
"screenHeight": 0
}
}Minimal Configurations
The minimal required fields in the simulation.ois file are initialState and states. These fields define the starting point and the available states for your simulation. The other fields are optional, and if not provided, default values will be used.
{
"initialState": "MyState",
"states": {
"MyState": "org.mypackage.MyState"
}
}To use assets in your simulation you need to place them inside the assets directory.
The OIS infrastructure will know to include them with the simulation.
For HTML supported project that needs to use Reflection.
You can specify the package that will be reflected inside (Optional) reflection.ois JSON configuration file.
[
"org.mypackage.ClassToReflect",
"org.mypackage.OtherClassToReflect"
]After making these changes, your project structure should look like this:
my-simulation-project/
βββ build.gradle
βββ settings.gradle
βββ simulation
β βββ assets
β βββ simulation.ois
βββ src
βββ main
βββ java
βββ org
βββ mypackage
βββ MyState.javaContinue to Running and Debugging the Simulation
Β© 2024