CPTerminal
Output terminal interface.
This is game engine view on the underlying terminal. CosPlay comes built-in with two implementations for this interface:
- org.cosplay.impl.jlineterm.CPJLineTerminal native JLine-based implementation that works with any OS command line terminal application supporting ANSI escape sequences are a standard for in-band signaling to control cursor location, color, font styling, and other options. For running games in xterm, iTerm, any VTE-based terminal, Windows Terminal, etc. this is the implementation to use.
- org.cosplay.impl.emuterm.CPEmuTerminal GUI-based terminal emulator. It behaves in exactly the same manner as native ANSI-based terminal. It takes no advantage of raster graphics in drawing or color rendering. It also adheres to the FPS capping by the game engine. Terminal emulator is an ideal tool during the game development as you can quickly iterate, start and stop games right from IDEs without any need for the external builds.
When initializing CosPlay game engine using one of the CPEngine.init methods you are passing a boolean parameter which indicates whether to use native or a GUI-based terminal emulator. This way the game engine automatically knows which of the two built-in implementations to use and you don't need to specify these classes anywhere else. For the most use cases this is all that is needed.
Note that there's an easy way to check whether or not your game is running in the native terminal. Execute the following code somewhere in your game engine initialization routine:
val isInNativeTerm = System.console() != null
and pass the appropriate flag into one of the CPEngine.init methods. This way your game will automatically choose the appropriate terminal implementation based on what environment it is running on.
Custom Terminal Implementation
You may decide to provide your own terminal implementation, for example, targeting iOS, Android or WebGL output. Here are the steps to do it:
- Create a class that implements this trait.
- This class should have at least one public constructor that takes one parameter of type CPGameInfo.
- This class should be instantiable through standard reflection from Scala code.
- Set system property
COSPLAY_TERM_CLASSNAME=x.y.z.MyTerm
, wherex.y.z.MyTerm
is a fully qualified name of the class you developed. Make sure to set this system property before calling one of the CPEngine.init methods. - Initialize the game engine as usual. Setting
COSPLAY_TERM_CLASSNAME
system property will override the default terminal selection.
Attributes
- See also
-
org.cosplay.impl.jlineterm.CPJLineTerminal
org.cosplay.impl.emuterm.CPEmuTerminal
- Source
- CPTerminal.scala
- Graph
-
- Supertypes
-
class Objecttrait Matchableclass Any