HSP : HSP3Dish / onion software 2021(c)

title

HSP3 Dish android (NDK) version programming guide

  1. Android version HSP3Dish overview
  2. Preparing the environment
  3. Platform API installation
  4. HSP3Dish Helper settings
  5. Create a new project
  6. About the library folder
  7. Project build
  8. Sample project
  9. Transfer and execution to the actual machine
  10. Data file preparation
  11. Get system information
  12. Task (activity) call
  13. About the hsp3dish.ini configuration file
  14. About manual setting items
  15. About network communication
  16. Release build
  17. About the HGIMG4 project
  18. About device control
  19. AdMob ad serving
  20. mes, print command
  21. Notes and restrictions for android version
  22. Android version will be updated

Android version HSP3Dish overview

The android version of HSP3Dish is a runtime of HSP3Dish that runs on android OS-equipped models (smartphones, tablets, etc.). It is possible to reproduce the functions supported by HSP3Dish for Windows on android OS. (The android version of HSP3Dish is intended to execute the Windows version of the script, and does not reproduce the HSP3 development system itself on android.)
In this manual, we will explain how to use the android version and points to note.

Currently, in order to build a file that can be executed on android, it is necessary to set the environment for development. There is no cost to build a development environment. All can be prepared for free. These work on Windows and you can check the operation on the connected android device.
The HSP3Dish Helper tool is included to assist you in building with HSP3Dish. This makes it possible to build for android relatively smoothly.

In order to operate on the actual android machine, the following is required.


If you unzip the archive to the recommended folder, you will see something like the above. (Use alphabetic characters only, folder names without spaces)

HSP3 Dish Helper settings

Launch HSP3Dish Helper (hsp3dh.exe) in the HSP installation folder (must be updated with the latest version of the HSP3Dish development set).


On the screen displayed by pressing the "Option" button, set the location of the installed folder such as android development environment (SDK).


If it is installed in the recommended folder, it will have the above settings.
The final "Project" folder setting indicates the starting point of the project folder created when building the app for android. The recommended folder is "c: \\ android".

Platform API installation

First, install the Platform API required for the build. You can start HSP3Dish Helper (hsp3dh.exe) and start it from the "SDK Manager" button on the "Options" tab.


This tool allows you to install the required APIs. (Must be connected to the net)
A checkbox for the API corresponding to each version is displayed in the form of "Android 10 (API 29)". Be sure to check "Android SDK Tools", "Android SDK Platform-tools", "Android SDK Build-tools" (latest Rev.) and "Android 10 (API 29)". (The API version indicates the level of API that can be used in the program, and it has nothing to do with the version of the device to install. Normally, if you install "Android 10 (API 29)", it can be operated on most devices. increase.)
Click the "Install packages ..." button to download and install. "Installed" is added to the installed items.

(If you use it in an environment where you cannot connect to the Internet for some reason, use a place where you can temporarily connect to the Internet. After installation, if you prepare the android development environment (SDK) folder itself, there is no problem with the build. )

* New apps for publishing on Google Play must be registered in android 11 (API30) and AAB (Android App Bundle) formats from August 2021.
Build in AAB format will be supported at an early stage, so β test version Be sure to check for updates .

Create a new project

Launch HSP3Dish Helper (hsp3dh.exe) and press the "android" button at the bottom center to enter android build mode.


The above dialog for creating a new project is displayed. (If it is not a new project, click the "New project" button)
By setting the following items and clicking the "New" button, the folder of the specified project will be created and you will be ready to build for android. When developing an app for android, you must always create one project file for each app. The project folder is created starting from the location set in the setting menu.

About the library folder

When creating a new project, the library folder required for build is created. The library folder is created in the project's base (root) folder, which is set as an option.
The ones created as library folders are as follows.

By starting HSP3Dish Helper (hsp3dh.exe) and pressing the "Update Library" button on the "Options" tab, the contents of the project folder will be overwritten. Please do this when you update or replace the HSP.

The sources in the hsplib36 ~ folder contain the HSP3Dish runtime sources shared by each project. The user can change the source by himself, but please note that the source may be overwritten and updated by updating HSP3Dish helper.

Build project

Launch HSP3Dish Helper (hsp3dh.exe) and press the "android" button at the bottom center to enter android build mode.


The above project build dialog will be displayed. (If it is not a build, press the "Existing project" button)
By building the project, the specified HSP script and data file will be output as a format (apk file) that can be executed by android. In the development of the android application, the final output result is the apk file that summarizes all the programs and data for execution.
The items to be set in the dialog are as follows.

Sample project

The sample / hsp3dish folder contains sample scripts for using HSP3Dish. Specify the HSP3Dish sample (block3.hsp) of breakout in the source script, You can run the build leaving the data file (dpm) blank.


Transfer and execution to the actual machine

After the project build is completed, you can transfer it to the actual android machine or simulator and check it. (When running on the simulator, start "AVD Manager" from the "Options" tab of HSP3Dish helper, and set and start the simulator to use it.)
Transfer (install) the pre-built apk file by connecting the actual android device via USB and pressing the "Transfer" button while it is recognized by the OS. After that, execute the transferred application from the application list.
The connection settings of the actual android device differ depending on the device model. Please refer to the following sites.

Even if you cannot transfer to the actual machine, you can transfer the apk file generated by the build via the net or USB memory, install it, and check the execution.
You can display the execution log by pressing the "Logcat" button. You can check the error and initialization message from HSP when transferring to the actual machine and executing.

Data file preparation

The data file referenced by the script can be prepared in two ways. One is to copy the files to the assets folder in your project directory. Basically, use this method. The assets folder can contain all the files used for reading, including image files.
However, please note that unlike Windows, the file name is case-sensitive, so you need to write the file name correctly.

The other method is to copy the file to the data folder (generate data.dpm) set in the "Data file (dpm)" item and use it.
* It has been confirmed that the dpm file is not recognized correctly on android9 or later OS. We plan to support it in future versions, but currently it is recommended to use the assets folder instead of the dpm file.
If you want to use data or encryption that you don't want people to see, make sure to use the data folder in data.dpm. However, please note that sound files (wav, mp3, etc.) are not recognized. Also, please note that reading from a file pack by data.dpm has the same restrictions as the HSP packfile specification (file name length is 12 characters or less). Be sure to put the sound files in the assets folder.

Get system information

It is now possible to get the OS version and device name using the sysinfo function. You can get a string like "android 2.3.3" with sysinfo (0). This makes it possible to determine the OS and version currently running in the source.
You can also get the device name with sysinfo (2).

Task (activity) call

Other tasks (activities) can be called by the exec command.

If the second parameter (execution mode) is 0, it depends on the "package name" and "class name". Specifies the task to perform. If you need to unlock the security, describe the class to be started in of "AndroidManifest.xml".

An easier way to do this is to call the app by specifying the URI.

For example, if "http://hsp.tv" is specified for the URI, the default web browser will be opened and displayed as the URL. Start the dialer with "tel: 123456789". There are various other calling methods supported by the OS.

About the hsp3dish.ini configuration file

If there is a setting file "hsp3dish.ini" in the "hsp" folder (folder where HSP scripts are installed) in the project folder, the setting will be reflected at build time.
"Hsp3dish.ini" is a file to refer to the settings such as screen size when executing on Windows. See the HSP3Dish Programming Manual for more information. By writing like "parameter name = setting value", the setting will be reflected when building android.

If you want to adjust the screen scaling automatically, set the auto scaling value like "autoscale = 0". You can scale the drawn screen size appropriately and display it on the current screen.
The details of the automatic scaling value are as follows.

The orientation of portrait (vertical screen) and landscape (horizontal screen) is automatically set according to the specified screen size.
If "hsp3dish.ini" does not exist, or if the settings are not written, no particular changes will be made. If you want to set manually without using the "hsp3dish.ini" file, read the item "About manual setting items".

About manual setting items

By editing the main.cpp source in the jni folder, you can make various settings related to HSP3Dish.
Normally, prepare the setting file "hsp3dish.ini" in the "hsp" folder and configure the settings. This section describes how to modify the source code and set it manually.
Modify the following line in the source code (near 160 lines) that starts with "static void engine_handle_cmd".

Items that start with "//" are commented out and do not work. By default, scaling is not set, so it should look like the above.

First, delete the "//" to enable the hgio_view line. Please set the original screen size (resolution at which the script operates) with hgio_view. The above example shows that the horizontal size is 480 and the vertical size is 320.

If you want to display at the specified magnification, enable the hgio_scale line. With hgio_scale, the original screen size is displayed at the specified magnification. Use this if you want to fix the magnification. In general, we recommend using hgio_autoscale.

If you want the screen scaling to be adjusted automatically, enable the hgio_autoscale line. With hgio_autoscale, the drawn screen size is scaled appropriately and displayed on the current screen.
The numbers in parentheses allow you to specify several scaling methods.

Scaling settings are made at startup. It cannot be changed while the script is running.

Corrects the phenomenon that adjacent pixels are blended when the texture is enlarged. Normally, it is not necessary to specify this option, but please try it when the texture is not displayed correctly due to screen scaling etc.
If the number in parentheses is other than 0, the correction will be ON. If it is 0, the correction will be OFF.

About network communication

It is possible to perform network communication using commands such as httpload and httpinfo on android. However, in android8.0 or later, due to the OS specifications, only https access (encrypted communication) is allowed. http access is basically prohibited.
For example, if you want to access "http://www.onionsoft.net", go to "https://www.onionsoft.net" By changing it, communication becomes possible. (Please think that access to an unspecified http server is basically impossible)
Access via https is possible depending on the specifications on the server side. There are things you can't do. In that case, add the "network_security_config.xml" file It is possible to communicate by allowing http access only to a specific URL (domain).
You can register the domain of http communication destination for each project. First, create a new "network_security_config.xml" file and under the project folder Place it in res / xml. Here, please describe the following contents.

In the above example, "www.onionsoft.net" is specified as an accessible domain. Describe the required domain here. You can configure multiple domains if you wish.

Next, edit "AndroidManifest.xml" in the project folder and add the "& lt; application ~" line. Please rewrite as follows.

With the above, http access is possible only for the registered domain.
Since it is an auxiliary method to the last, it is desirable to access https as much as possible. Please remember.

Release build

You can generate a signed apk file by doing a release build from HSP3Dish Helper. This makes it possible to register the created application on Google Play (Android Market). The general procedure for publishing is as follows.

* After 2019/08/01, API28 (android9) is required for SDK for apps registered on Google Play. Please note that the application to be released and built must be built by installing the SDK of API 28 or later.

I will explain step by step.

About the HGIMG4 project

Basically, you can use HGIM G4 script with the same specifications as the Windows version.


The HGIMG4 project takes a very long time to build for the first time. Also, because it uses the OpenGL / ES2 function, it may not work or may be slow depending on the environment and model of the android terminal.
In HGIMG4, files such as res folder and shader are always required at startup. From the "res folder" in the "sample / hgimg4" folder of HSP, to the HGIMG4 project folder for android Copy it under "assets". (The folder structure is "assets / res / ...")
The minimum required files are as follows.

		res/font.gpb
Shader files in the res / shaders folder
	

Please note that the following functions are not supported. It will be supported in a future version.

About device control

It is possible to access Android device-specific functions with commands such as devcontrol.

devcontrol "control command", parameter 1, parameter 2, parameter 3
	

Perform device control in the above format. On Android devices, the control command specified as a character string recognizes the following. (The control command string must match exactly, including case.)
Note that an error does not occur even if you write a control command that is not recognized.

Control command content
	-------------------------------------------
vibrate Vibrate operation (parameter 1)
AdMob Displaying ads with AdMob
	

for example,

		devcontrol "vibrate",400
	

Instructs the device to perform a vibrate operation.
The length of vibration (in milliseconds) can be changed by changing the value of the parameter.

You can also get system information with the devinfo command.

devinfo variable name, "information name"
	

Perform device control in the above format. On Android devices, the control command specified as a character string recognizes the following. (The control command string must match exactly, including case.)
Note that an error does not occur even if you write a control command that is not recognized.

Information name Contents
	-------------------------------------------
name Terminal type name (terminal name can be obtained by sysinfo (2))
locale Locale information
	

for example,

		devinfo a,"locale"
	

Assigns the information of Loril to the variable a.

AdMob ad serving

About mes, print command

HSP3Dish supports character string drawing of mes and print instructions using the built-in font. (HGIM G4 is not applicable because it draws with font data)
The font name specified by the font command is ignored and the font size is reflected. Also, the font style only supports standard (0) and bold (1).
Since the process of acquiring fonts on android is a heavy burden on the system, the content (texture) once drawn is cached on the HSP3Dish side to speed up the process. Normally, you should be able to use it without being aware of this mechanism.
If you want to control the cache function, describe the setting with the setreq command. (It does not affect Windows and iOS versions)

setreq SYSREQ_MESCACHE_MAX, 64; Specifies the maximum number of cache registrations
The internal operation of the cache is that if there is a character string with exactly the same content as the message once displayed, The previous data will be reused and displayed. However, the cache that was not displayed for 8 frames will be discarded.
The maximum number of caches that can be retained is 64 by default. The cache setting range is 0 to 128 as a guide, and even if the value is large, it does not necessarily mean that the speed will be increased. Please understand that message display is a costly process for the purpose of suppressing a noticeable slowdown.
If the maximum number of cache registrations is set to 0, the cache will not speed up.

Notes and restrictions for android version

Android version will be updated

The following features will be added with higher priority in order from the top.

The version upgrade will be announced on the HSP official site HSPTV !, so please check back from time to time.

ONION software