AGS 3.6.0 WIP (Alpha 21) - SDL2-based engine + Unicode support

Started by Crimson Wizard, Thu 25/03/2021 02:28:54

Previous topic - Next topic

Crimson Wizard

Quote from: Stranga on Fri 18/02/2022 06:57:35if I save at night and load it's day (or background frame resorts to default which I think is 0). Basically, it's not saving room background frames (Not sure if this is affecting other frame animations, haven't tested it with views yet)

Looks like a bug.

Stranga

Thanks for the update and fix CW  :-D

I also found this, not sure if it's a bug either but when running custom dialog options via scripting I get these errors:
Spoiler


[close]

the first one is in Turkish, which just seems to show some displacement of the letters and the other two are Russian which doesn't show up at all, I've tried a few different fonts with Russian but still, the same result.
The rest of the GUI and regular text seems to work fine :)

Crimson Wizard

Quote from: Stranga on Wed 02/03/2022 06:09:01
I also found this, not sure if it's a bug either but when running custom dialog options via scripting I get these errors:

I cannot answer this question without knowing more details - what script you have, which fonts you have, and so on.

Stranga

Quote from: Crimson Wizard on Wed 02/03/2022 08:20:01
I cannot answer this question without knowing more details - what script you have, which fonts you have, and so on.

My apologies, here's the script:
Spoiler
Code: ags

// new module script

//int dlg_opt_color = ;
int dlg_opt_acolor = 30719;
int dlg_opt_ncolor = 65535;
int DlgCursorPos = 1;

import int  KeyUp[2];
import int  KeyDown[2];
import int  KeyLeft[2];
import int  KeyRight[2];
import int  KeyAction[2];
import int  KeyBack;
import int  KeyMenu;
import int  KeySprint[2];

import bool CanPress;

function repeatedly_execute() 
{
  btnDialogCursor.Visible = false;
  btnOptionsBox.Visible = false;
}

function dialog_options_get_dimensions(DialogOptionsRenderingInfo *info)
{
  // Create a 200x200 dialog options area at (50,100)
  info.X = 30;
  info.Y = 50;//50
  info.Width = 256;
  info.Height = 256;
  info.ActiveOptionID = 1; // set to first option
}

function dialog_options_render(DialogOptionsRenderingInfo *info)
{
  //info.Surface.Clear(dlg_opt_color);
  int i = 1,  ypos = 24,  xpos = 0;
  // Render all the options that are enabled
  while (i <= info.DialogToRender.OptionCount)
  {
    if (info.DialogToRender.GetOptionState(i) == eOptionOn)
    { 
      if (info.ActiveOptionID == i){
        
          btnDialogCursor.SetPosition(6, ypos+42); //Cursor Position 
          btnDialogCursor.Animate(5, 0, 5, eRepeat);
      }
       else
       
        info.Surface.DrawingColor = dlg_opt_ncolor;
        info.Surface.DrawStringWrapped(5, ypos, info.Width - 10, 
        eFontfntDefault, eAlignLeft, info.DialogToRender.GetOptionText(i));
        ypos += GetTextHeight(info.DialogToRender.GetOptionText(i), eFontfntAll, info.Width - 10);   
    }
    aMenuSelector.Play();
    i++;
  }
}

function dialog_options_key_press(DialogOptionsRenderingInfo *info, eKeyCode keycode) 
{
  switch (keycode)
  {
  case KeyUp[0]:
  case KeyUp[1]:
    // check all options upwards until found an active one
    for (int next_opt = info.ActiveOptionID - 1; next_opt >= 1; next_opt--)
    {
      if (info.DialogToRender.GetOptionState(next_opt) == eOptionOn)
      {
        info.ActiveOptionID = next_opt;
        break;
      }
    }
  break;
  case KeyDown[0]:
  case KeyDown[1]:
    // check all options downwards until found an active one
    for (int next_opt = info.ActiveOptionID + 1; next_opt <= info.DialogToRender.OptionCount; next_opt++)
    {
      if (info.DialogToRender.GetOptionState(next_opt) == eOptionOn)
      {
        info.ActiveOptionID = next_opt;
        break;
      }
    }
  break;
  }
  
if(CanPress)
  {
    switch(keycode)
    {
      case KeyAction[0]:
      case KeyAction[1]:
        btnDialogCursor.Visible = false;
        btnOptionsBox.Visible = false;
        btnPopUp.Visible = false;
        btnPopTalk.Visible = false;
        info.RunActiveOption();
      break;
    }
  }
}

function dialog_options_repexec(DialogOptionsRenderingInfo *info)
{
    btnOptionsBox.Visible = true;
    btnDialogCursor.Visible = true;
}
[close]

Here's the font I am using too: https://opengameart.org/content/lanapixel-localization-friendly-pixel-font
The game is keyboard-only based so I used the custom choice scripting found in the manual. I also use this same font with other languages too and it works fine with them.

Crimson Wizard

Quote from: Stranga on Wed 02/03/2022 23:33:18
Here's the font I am using too: https://opengameart.org/content/lanapixel-localization-friendly-pixel-font
The game is keyboard-only based so I used the custom choice scripting found in the manual. I also use this same font with other languages too and it works fine with them.

I will make some tests, but something I noticed in the script:
- calling GetTextHeight you use eFontfntAll, but
- calling DrawStringWrapped you use eFontfntDefault.

What's the difference between these fonts, could you double check that this is correct?

Stranga

That was the problem! Thanks, CW! I can't believe I missed that  :-[ Everything works fine now  :-D

Edit: the difference was that "Default" was the AGS font I was using during the development "All" was the one that contained the customer symbols and such for different languages

Crimson Wizard

#186
Updated to Alpha 19
(use download links in the first post)

New changes:

Editor:
- Finally, full Unicode support right in the Editor. Script, game properties and so on, support any human language. Note that you have to use proper Unicode fonts for this to work correctly.
To upgrade your game to unicode mode, goto General Settings and check the "Text format" option. Changing it will convert game files and resave the project. If you had only basic latin text - nothing should change; this is mostly done in case you had other languages in your game. After we update templates, unicode mode should be default for all the new projects.
ANSI mode is still supported, mostly in case you're upgrading an old game and wish to stick to old fonts.
- Upgraded script editor to Scintilla 3.21.1 and ScintillaNET 3.6.3. This was done for easier unicode support. I don't think anything has changed feature-wise, but keep an eye for regressions.
- Added Android build target support (requires "Android component" installed).
More info on building for Android is here: https://www.adventuregamestudio.co.uk/forums/index.php?topic=59772.0
- Removed game Cursors hard limit (was 20), fwiw.
- Fixed few editor panes were not opening correct help topics in F1.

Engine:
- Added "--clear-cache-on-room-change" command-line arg (and similar config option).
- Fixed OGV Theora videos positioned incorrectly if they have certain sizes or aspect ratios.


I think we're now done with major features in this version. In order to move to Beta stage, we only need to update game templates, because they are still upgraded from 3.5.1, and some options are set to backward compatible values at start.

eri0o

The web component is now in too (as part of the installer), so it's not necessary to link it separately in the main page anymore.

I think during beta we will also be writing the missing manual pages, updating script API changes in documentation.

Crimson Wizard

Unfortunately found two bugs in Alpha 19:
- When converting text format (in General Settings) all your scripts should be closed, otherwise the editor may crash;
- In script editor deleting multiple lines at once (with selection) may cause crash.

Both are fixed in this temp build:
https://cirrus-ci.com/task/6570224085368832

I will be releasing a proper update too soon.

Crimson Wizard

#189
Updated to Alpha 20
(use download links in the first post)

Had to make new update soon, to fix couple of problems found since the last update.

New changes:

Editor:
- Fixed crash when changing game encoding if any script window is open (since 3.6.0.18).
- Fixed script editor "random" errors when deleting multiline selection (regression in 3.6.0.18).

Compiler:
- Support hexadecimal number literals (32-bit max). May be used anywhere where regular decimal numbers are used.
Code: ags

int a = 0xFFFFFF00;
int b = 0x01234567;
int c = 0xabcdefab; // both capital and small x and a-f letters are supported
int d = 16 + 0x10; // means 16 + 16


Engine:
- Removed limit of simultaneous Button animations (was 15).
- Removed limit of Character followers (was 30) (was not demanded, but because why not).

Full list of changes is available here:
https://github.com/adventuregamestudio/ags/blob/master/Changes.txt

Crimson Wizard

#190
Updated to Alpha 21
(use download links in the first post)

We are working to complete the unicode support in this version, and also fixing some issues found since the last update.
We still have to prepare updated game templates, imho this is the last thing remaining before announcing 3.6.0 Beta.

New changes:

Editor:
- Added "Use old keyboard handling" option to the General Settings (Backwards compatibility section), which lets select between classic key press handling and new one meant for easier unicode chars support in scripts. See below for more information on this new mode.
- Select script editor's font in the editor's Preferences.
- Fixed some editor's panes do not update previews on property changes (regression since 3.6.0.19).

Compiler:
- Support for the unicode character literals.

Script API:
- Expanded on_key_press callback, now supports two parameters: key code and key modifier flags.
- In the new key handling mode on_key_press is called for each actual key press; e.g. combinations like Ctrl+Z will result in two on_key_press calls, one with eKeyCtrlLeft and second with eKeyZ.
- Implemented new on_text_input(int ch) callback which is called when the engine receives a printable character. This callback is essential for handling unicode chars in script.
- Similarily, expanded dialog_options_key_press with the third mod argument, and implemented dialog_options_text_input callback for receiving unicode chars during the custom dialog options state.
- Added eKeyMod enum for key modifiers constants.
- String.AppendChar, ReplaceChar and Chars[] property are now working with the unicode characters.
- String.Format("%c") specifier will now be able to print unicode characters.

Engine:
- Update engine's sound config to match new SDL2 backend, allow to choose specific sound driver.
- Allow to choose output graphics driver for software mode in config.
- Fixed engine was handling buffered key presses one at a game frame, could cause delayed reaction to the key input (regression in 3.6.0).
- Fixed engine switching to ASCII mode when changing to default translation, even if the game is compiled in unicode mode.

Winsetup:
- Updated sound config, removing obsolete settings.

Full list of changes is available here:
https://github.com/adventuregamestudio/ags/blob/master/Changes.txt
Description of the current engine config:
https://github.com/adventuregamestudio/ags/blob/master/OPTIONS.md




In regards to the key input changes. There are two things.

1. Regardless of the handling mode (see below), the on_key_press function now supports the second parameter: key modifiers. It stores current key modifiers (ctrl, shift, alt, etc) as bit flags. The reason for introducing this parameter is that because the key presses are buffered between game frames, using IsKeyPressed does not always correspond to each handled key. Having an actual "mod" parameter ensures that you can know which modifiers were on when this particular key was pressed.

NOTE: the "int mod" is an optional parameter, and may be omited from the function. It will work correctly even with 1 parameter (eKeyCode).

The list of key mods:
Code: ags

enum eKeyMod
{
  eKeyModShiftLeft,
  eKeyModShiftRight,
  eKeyModShift,        // this means: any shift
  eKeyModCtrlLeft,
  eKeyModCtrlRight,
  eKeyModCtrl,         // this means: any control
  eKeyModAltLeft,
  eKeyModAltRight,
  eKeyModAlt,           // this means: any alt
  eKeyModNum,        // numlock
  eKeyModCaps         // capslock
};


These are not normal enums, but bit fields, which means that you should not use regular comparison with them (like "if (mod == eKeyModCtrl)"), but bit field check instead: "if (mod & eKeyModCtrl)".
Code: ags

function on_key_press(eKeyCode key, int mod) {
    if (key == eKeyQ && (mod & eKeyModCtrl)) { // this tests for ctrl + Q
    }
    if (key == eKeyF1 && (mod & eKeyModAlt)) { // this tests for alt + F1
    }
    if (mod & eKeyModNum) { // this tests if num lock was on when this key is pressed
    }
}


2. The new key handling mode, it's enabled by setting "Use old keyboard handling" in Backwards compatibility (General Settings) to false (this will be the new game default after we update game templates).

What is the difference between old mode and new mode?

Old mode is a backward compatible input handling mode, where
* lone mod keys (Ctrl, Alt, Shift) are not passed further into the engine nor script;
* key + mod combos are merged into one key code for the on_key_press callback: e.g. eKeyCodeCtrlA key codes;
* on_text_input script callback is NOT called.

New mode is:
* all keys are passed into the engine and on_key_press script callback as-is, one by one; e.g. if you press Ctrl + Z, then you get two on_key_press calls, one for Ctrl and another for Z argument..
* on_text_input script callback receives printable characters, which may be used to handle unicode chars typed by the player correctly.

There's a new compiler macro "NEW_KEYINPUT_API" which may be tested using #ifdef and #ifndef to know which mode is set when the game is run. This is mostly useful to the script module writers.

Examples of new mode script
Code: ags

function on_key_press(eKeyCode k, int mod) {
    if (k == eKeyV && (mod & eKeyModCtrl)) {
         // player pressed Ctrl+V, paste the copied text into your custom text control
    }
    if (k == eKeyAlt) {
         // player pressed either Alt
    }
}

function on_text_input(int ch) {
    // player pressed some keys, which formed a printable character
    // this may be either ASCII char, or Unicode char, depending on the game mode
    lblTextField.Text = lblTextField.Text.AppendChar(ch);
}

Andrea1992

Hi, I tried the latest alpha and in some rooms I get this error, I tried to isolate the room functions and interactions, but makes no differnce.
Any guidance on how to debug it? thanks

eri0o

@Andrea1992, You mean you only get these errors in some rooms, but not others?

Trying to narrow down where it could be the problem in AGS, some questions:

  • Do these rooms have multiple background frames and the other don't?
  • Do they use walkbehinds in some special way?
  • Is there any character that is just in the rooms that have this error but not in the others?

Other than this I would ask, if possible, if you could share the room .crm file - a dm is fine.

Andrea1992

Yes, I only get these errors in some rooms.
There aren't multiple background frames in these rooms (Most of the other rooms have multiple backgrounds though, but they're working fine)
There aren't walk behinds.
The room setting "ShowPlayerCharacter" is set to False for these rooms. They are close ups to show details of some objects and some have animations.

The error happens as soon as I change to these rooms.
Here you can download the .crm files of a couples of rooms with the error.
https://ln5.sync.com/dl/fe4035540/b4fwh9cr-a6khtsp6-5cz5e5dg-7ek279rh

Thanks!

Crimson Wizard

@Andrea1992, "Program pointer +204" indicates a stage during loading the room, when engine prepares walkable areas and walk-behinds.
Unfortunately, checking these rooms alone, and importing them into another game, does not reproduce the problem.

Do you remember what was the previous version of AGS you were using where you did not have such errors?
Is it acceptable for you to PM a full compiled game for a test?

Andrea1992

I made the game with AGS 3.5.0.24
I have PM a link to the game.
Thanks.

Crimson Wizard

@Andrea1992, it appears to be some older bug which I could not fix correctly. It happens when you move from the room with several backgrounds to room with less backgrounds.
Here's the build that should have this fixed:
https://cirrus-ci.com/task/5214597316608000

Andrea1992

Thanks Crimson, the build fixed the problem. So, when you update to alpha 22 or beta,  will the fix be included? or will I have to use a different ags build?

Also, the game freezes sometimes. There is a cutscene in one of the rooms with fewer backgrounds and when I tried to escape it, it freezes the game completely. (This is when you talk to the girl outside the house)


Crimson Wizard

Quote from: Andrea1992 on Thu 17/03/2022 00:44:39
Also, the game freezes sometimes. There is a cutscene in one of the rooms with fewer backgrounds and when I tried to escape it, it freezes the game completely. (This is when you talk to the girl outside the house)

Could you tell the number of the room and what do i have to do to reproduce the problem? I never played your game before.

Andrea1992

Room 5,
To get there, from the bedroom (initial room) go outside using the door, then talk to the girl that arrives (only character in that room). This sends you to the room 5, where the cutscene esc problem occurs,
thanks

SMF spam blocked by CleanTalk