AGS 3.0 Final - it's been a long road

Started by Pumaman, Sun 10/06/2007 18:24:35

Previous topic - Next topic

monkey0506

Regarding not being able to use dynamic arrays within a struct...it may be possible to implement them as if they were static members using the workaround I found for simulating static variables. For example, it may be possible (although I haven't downloaded the new beta yet; I will verify after I test it) to do something like this:

Code: ags
// script header
struct MyStruct {
  import static attribute int CharacterStatus[];
  };

// main script

int MyStruct_CharacterStatus[];

function game_start() {
  MyStruct_CharacterStatus = new int[Game.CharacterCount];
  }

int geti_CharacterStatus(this MyStruct*, int index) {
  if ((index < 0) || (index >= Game.CharacterCount)) return SCR_NO_VALUE;
  return MyStruct_CharacterStatus[index];
  }

void seti_CharacterStatus(this MyStruct*, int index, int value) {
  if ((index < 0) || (index >= Game.CharacterCount)) return;
  MyStruct_CharacterStatus[index] = value;
  }


NOTE: Presuming this method does work, it would only be available to simulate static dynamic array members. However you would not be able to access the static array within the script the get/set functions were defined in.

In any case, it's great to hear that we're getting some dynamic memory privileges. Presumably there's no need to delete[] the array? Thanks either way Chris.

SSH

Yeah, can we keep backward compatibility for old modules, please? Or is it simply that the  #defines for AGS_MAX_CHARACTERS won't exist?
12

Reaper

In Beta 5, when i make a new translation, language specific chars like äöüàŸ appear as a ? in the .trs file.

Shane 'ProgZmax' Stevens

1.  I can hear music modules again, yay!

2.  is the 'always run full screen' setting in preferences supposed to work yet, because I have it set but games will still start windowed if their setup file is set to windowed. 


So far Boyd Quest and all the mini-games work perfectly in the new build.  Looks like it's getting close!


Pumaman

QuoteJust because of curiosity, can the size of a dynamic array be defined only once or can it be changed multiple times in-game?

It can't be changed, but you can replace it with a new one. For example:

int myarray[] = new int[20];
...
myarray = new int[30];

By doing so though, the array contents will be lost.

QuoteNo longer possible? Do you mean this won't compile anymore?

Yes. As of beta 3, for example, the AGS_MAX_VIEWS and AGS_MAX_GUIS constants no longer exist. This is because there is no limit, so it doesn't make sense to have these defined (what would they be defined to?)

QuoteRegarding not being able to use dynamic arrays within a struct

I'll try to add proper support for this to a later beta, because I appreciate it would be useful.

QuotePresumably there's no need to delete[] the array?

Nope, the arrays are handled by the garbage collector in the same way as it deals with Strings, DynamicSprites, etc.

QuoteYeah, can we keep backward compatibility for old modules, please? Or is it simply that the  #defines for AGS_MAX_CHARACTERS won't exist?

As I said above, if you can think of a way to maintain backwards compatibility, I'm all ears. But since there is no maximum number of views, what would you suggest AGS_MAX_VIEWS should be defined as?

QuoteIn Beta 5, when i make a new translation, language specific chars like äöüàŸ appear as a ? in the .trs file.

Hmm strange, I'll look into it. Is this a new problem with beta 5, or is it just the first time you've tried it with 2.8 ?

Quote2.  is the 'always run full screen' setting in preferences supposed to work yet, because I have it set but games will still start windowed if their setup file is set to windowed. 

It should work, yes. Bear in mind that if you use F5 to run the game it will always be windowed because the debugger doesn't support full screen, but you can use Ctrl+F5 to run it without the debugger, which should abide by the Preferences setting.

QuoteSo far Boyd Quest and all the mini-games work perfectly in the new build.  Looks like it's getting close!

Glad to hear it! ;)

Scorpiorus

I just gave it a go to properly try and test the new version of AGS.

First of all, thank you Chris for your fabulous work with rewriting the Editor. I can only guess how much time and effort it took to rewrite the whole thing. I really like the new look of the editor and how the interface is now standardized making it very convenient and easy to use -- great work! :)




Ok, I did some testing and found some minor issues (AGS 2.8 beta 5); I hope they haven't been already reported before, sorry if it's so:

1. "Edit room" and "Room script" do not appear on the navigation tree until it's updated

Started a new game and created a new room. The new room node was added to the tree but it had no child nodes: "Edit room" and "Room script". To make them appear I had to enter a description for the new room (another possibility is to add-then-delete yet another room to update the tree).


2. Problem with switching between rooms

If I have two or more rooms on the tree and try to switch to (load) the one with previously expanded parent node by double-clicking on that node, it collapses instead; and if I try double-clicking it again, it then expands and loads/shows the room. It always works ok on first try, if I select a node and press the "Enter" key instead of double-clicking, though.


3. Debugger doesn't break at a breakpoint placed within game_start()

It's really a minor one, but I could not make it break anywhere at game_start.


4. There is no rebuild all rooms option or I just couldn't find it

Would be handy to have it back, as there are situations with updated #defines and "imports" so we don't have to load and save each room one-by-one.


5. There is no "There were compilation errors" message on errors in room scripts

This message textbox appears on errors in global script and script modules but not on those in room scripts.


Dynamic arrays

It's really great to have those supported natively, thanks!

How feasible would it be to add some sort of a "resize" operator to manage dynamic array size without losing the values where possible.

Also, since initially the array pointer is null, would it be feasible to have a way to release it -- say, by doing: "array = null;". May be handy if we have many global arrays and want to be carefull on how much memory is used.
A workaround would be to do "array = new int[1];", of course.

Charity

#86
Dynamic arrays look awesome.  Look forward to the ones that work with structs.

Anyway, I got an error.  I downloaded the new beta to a new folder and opened it just fine.  Loaded a game I was testing in beta 4 with no problems.  Looked briefly at one of my GUIs to see if there were sliders, and then exited without saving.  After that I changed my monitor resolution from 800x600 briefly to 848x480 (which was weird so I switched back) and then to 1024x768, to see how the editor works in a higher resolution (typically use lower resolutions because I have poor eyesight and need to be able to see individual pixels in order to read some fonts and images).  I went to open the editor again and got this message:

An unexpected error occurred.  See below for details.
System.IndexOutOfRangeException: Index was outside the bounds of the array.
at AGS.Editor.SplashScreen..ctor()
at AGS.Editor.Program.RunApplication()

I switched back to 800x600 but still get the error, so I'm not sure what caused it.

Reaper

Quote
Quote
In Beta 5, when i make a new translation, language specific chars like äöüàŸ appear as a ? in the .trs file.
Hmm strange, I'll look into it. Is this a new problem with beta 5, or is it just the first time you've tried it with 2.8 ?

First time i've  tried it with 2.8
in 2.72 the same translation file is ok

Pumaman

QuoteFirst of all, thank you Chris for your fabulous work with rewriting the Editor. I can only guess how much time and effort it took to rewrite the whole thing. I really like the new look of the editor and how the interface is now standardized making it very convenient and easy to use -- great work!

Glad you like it! :)

Quote1. "Edit room" and "Room script" do not appear on the navigation tree until it's updated
2. Problem with switching between rooms
3. Debugger doesn't break at a breakpoint placed within game_start()
4. There is no rebuild all rooms option or I just couldn't find it
5. There is no "There were compilation errors" message on errors in room scripts

Thanks for these, I'll look into them. Number 2 might be a bit of a quirk with the windows treeview control, so I don't know if I'll be able to fix it.

QuoteHow feasible would it be to add some sort of a "resize" operator to manage dynamic array size without losing the values where possible.

Also, since initially the array pointer is null, would it be feasible to have a way to release it -- say, by doing: "array = null;". May be handy if we have many global arrays and want to be carefull on how much memory is used.
A workaround would be to do "array = new int[1];", of course.

Comparing and assigning to null is a good idea, I'll look into it.
Resizing arrays would be ideal, but I can't promise it'll make it into 2.8.

QuoteAn unexpected error occurred.  See below for details.
System.IndexOutOfRangeException: Index was outside the bounds of the array.
at AGS.Editor.SplashScreen..ctor()
at AGS.Editor.Program.RunApplication()

Hmm, has your PC been running for 25 days now without a reboot? I have a feeling you've just stumbled onto a bit of an oversight on my part if that's the case, I'll get it fixed. In the meantime, to stop the error happening you'll need to restart your computer.

QuoteFirst time i've  tried it with 2.8
in 2.72 the same translation file is ok

Ok thanks, I'll look into it.

monkey0506

#89
I didn't mean to imply you won't provide dynamic array struct members (because you should), it simply occurred to me that the workaround I found for attributes may apply for static members until the official solution is provided. ;)

As for a resizing function, the following works, however unless it's possible to pass a dynamic array as a parameter (which I haven't actually tested), the function is specific to one array: TESTED! Passing a dynamic array as a parameter WORKS! :) See below for code.

It will be easier to provide a general function when we can have dynamic arrays within structs. And then Chris will implement it :P.

It's possible to pass a dynamic array as a function parameter (hooray!), however, as far as I can tell there's no way to get the size of the array (thanks Chris ;)), so I'll store that in a variable:

Code: ags
int arr[];
int arrSize = 0;

import int[] resize_arr(int iarr[], int currSize, int newSize, int defaultValue=0);

int[] resize_arr(int iarr[], int currSize, int newSize, int defaultValue) {
  // currSize is just a placeholder for a proper get_array_size function
  // if (iarr == null) return null; // can't currently check if array is null
  if ((currSize < 0) || (newSize < 0)) {
    // arr = null; // can't currently set array to null
    //return null;
    return new int[1]; // placeholder
    }
  int new_arr[] = new int[newSize];
  int i = 0;
  while ((currSize) && (i < currSize) && (i < newSize)) {
    new_arr[i] = iarr[i];
    i++;
    }
  while (i < newSize) {
    new_arr[i] = defaultValue;
    i++;
    }
  return new_arr;
  }

function game_start() {
  arr = resize_arr(arr, arrSize, arrSize + 10, 73);
  arrSize += 10;
  }


This function will resize the array to the specified size, then return the modified array. If the array is grown the new values will be filled with the defaultValue.

[EDIT:]

Apparently although it appeared to work, the function wasn't really working the way I thought it was, which may have yielded some unexpected results. Scorpiorus was right; you'll need to return the modified array.

Regarding getting the size of an array, this is definitely stored internally somewhere, because dynamic arrays still have proper bounds checking. This wouldn't be possible unless the size was stored. Now it's simply a matter of providing a reasonable means for the user to access this value.

Snarky

Quote from: Pumaman on Wed 18/07/2007 18:53:13
Yes. As of beta 3, for example, the AGS_MAX_VIEWS and AGS_MAX_GUIS constants no longer exist. This is because there is no limit, so it doesn't make sense to have these defined (what would they be defined to?)

As I said above, if you can think of a way to maintain backwards compatibility, I'm all ears. But since there is no maximum number of views, what would you suggest AGS_MAX_VIEWS should be defined as?

Well, if you're asking for suggestions, how about keeping the same value it used to be defined to? That would maintain backwards compatibility, would it not?

Alynn

Chris, would it be possible to have those MAX_VALUE  become complile time static variables. Something like if you have 10 views AGS_MAX_VIEWS is now 10, and can be used in array declarations and the like.

Since things like characters, views, and the like cannot be made dynamically, this shouldn't pose any code issues (other than difficulty).

Maintains backward compatability, and adds new functionality.

Gilbert

A problem will be, if you make these compile time variables, you'll need to recompile all rooms which may take reference to these values whenever you have add say a view, etc. to your game.

DavidCB

#93
Hi,
I found this error when I compile my game in AGS 2.8 Beta 5:

Error: prepare_script: error -18...

...when I try to modify the code I got this message:

---------------------------
Adventure Game Studio
---------------------------
An unexpected error occurred. Please note down the following information and contact CJ.



System.IndexOutOfRangeException: àndice fuera de los límites de la matriz.

   en AGS.Editor.AutoComplete.SkipWhitespace(FastString& script)

   en AGS.Editor.AutoComplete.GetNextWord(FastString& script)

   en AGS.Editor.AutoComplete.GetLocalVariableDeclarationsFromScriptExtract(String scriptToParse)

   en AGS.Editor.ScintillaWrapper.GetListOfLocalVariablesForCurrentPosition()

   en AGS.Editor.ScintillaWrapper.ParsePreviousExpression(Int32 startAtPos, String& charactersAfterDot, Boolean& staticAccess, Boolean& isThis)

   en AGS.Editor.ScintillaWrapper.ShowStructMemberAutoComplete()

   en AGS.Editor.ScintillaWrapper.ShowAutoCompleteIfAppropriate(Int32 minimumLength)

   en AGS.Editor.ScintillaWrapper.OnUpdateUI(Object sender, EventArgs e)

   en Scintilla.ScintillaControl.DispatchScintillaEvent(SCNotification notification)

   en Scintilla.ScintillaControl.WndProc(Message& m)

   en System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)

   en System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)

   en System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
---------------------------

then I don't type any key without get this message.

Excuse my English.

SSH

Quote from: Gilbot V7000a on Thu 19/07/2007 06:18:56
A problem will be, if you make these compile time variables, you'll need to recompile all rooms which may take reference to these values whenever you have add say a view, etc. to your game.

Perhaps there could be an option ion the editor for compatibility: 1: No compatibility, 2: Set to values used in 2.72, which will break if you exceed the old limits 3: Static compile-time constants that forces a recompile of all rooms each time you build.
12

Scorpiorus

#95
AGS Editor GUI

Ah, I forgot to mention two things in my previous post:

Would it be practical for the Editor to remember which pane is currently selected to show (Properties or Events) in Edit Room (until a new room is loaded)? It's just I was adding several room event functions in a row and each time I pressed "..." and then double-clicked Edit Room to go back, it showed the Properties pane when I'd prefer the Events as I was working with them.

And also, if I double-click, say, Edit Room and a pane is shown and I then click Edit Room again, the pane vanishes and I need to click somewhere else then double-click Edit Room again to get it back.


Dynamic arrays

Yeah, some way to get the current size of a dynamic array would be really useful, especially for resizing arrays manually, for the time being.

I guess all these "get_size/sizeof (meaning get_item_count)", "resize" things need to be operators in order to properly handle arrays no matter what type of they are?


As for resizing an array manually, the following example demonstrates the idea:

Code: ags

int[] create_from_array_of_int( int a[], int old_size, int new_size )
{
    int new_a[] = new int[new_size];
    
    int i;
    if (new_size > old_size) i = old_size - 1;
    else                     i = new_size - 1;
    
    while (i >= 0)
    {
        new_a[i] = a[i];
        i--;
    }
  
    return new_a;
}


What I'd like to point out is that to "resize" an array it is necessary to return the newly generated array and then to catch it with a pointer:

Code: ags

...
int array[] = new int[100];

// resize "array"
array = create_from_array_of_int( array, 100, 200 ); // 200 is new size
...


I deliberately named it "create_from..." instead of "resize", as that is what actually is taking place here. Similar to Strings (eg: String.Append).


Edit: removed "if (new_size == old_size) return a;" as it may be confusing for semantic of the "create_from" style function. Thanks monkey_05_06!

monkey0506

#96
Code: ags
if (new_size == old_size) return a;


Will actually return the address of the old array, meaning that modifying the "copy" will modify the original.

Code: ags
int a[] = new int[5];
int i = 0;
while (i < 5) {
  a[i] = i + 10;
  i++;
  }
int b[] = a;
b[0] += 5; // a[0] (and b[0]) are BOTH now 15


Just a thought...will dynamic arrays open up the way to multidimensional arrays as well? Understandable if it doesn't, but you know what they say, "You never know if you don't ask." :)

[EDIT:]

Apparently I don't know what I'm talking about either. :=

Monsieur OUXX

#97
dynamic arrays

Two questions :




1. Monkey (or maybe scorporius?) previously wrote that one has to return a modified array, or else the values in the array will be wrong.

Will the values in the array be wrong :
a) Only if the int[] got reassigned (using the new keyword) within the function?
(which would be normal, since an int[] is probably equivalent internally to an int* - so it is impossible to resize an array within a function that cannot  have an int** as parameter)

b) Even if there was no new within the function ?




2. Is there any sort of limitation concerning the size of an exported int[]?

Until now, there was an error message if the sum of all exported data in a module was bigger than a fixed limit. But now, this sum could only be caluculated at runtime... So will the game crash at runtime if an exported array gets too big?
 

Scorpiorus

Quote from: Monsieur OUXX on Sun 22/07/2007 19:49:441. Monkey (or maybe scorporius?) previously wrote that one has to return a modified array, or else the values in the array will be wrong.

Well, if it's just about changing array element values then you do not necessary have to return an array, since an array is passed into a function by a pointer value (int *).

There is a different situation with the "new" operator, as it actually returns a new address of the created array, which you must somehow assign to a global array pointer if it's for resizing manually. So you have to return the new address then of course (since it's the only way to pass it back to the calling script).

Quote2. Is there any sort of limitation concerning the size of an exported int[]?

By exporting an array you just export a 4-byte pointer; so if there is some sort of a limit to how much you can export, then it's not about the size of an array but the number of array pointers being exported.

Sadistyk

Hi. I just downloaded AGS 2.8 beta 5 and I have a problem: when I run the game, the game runs windowed instead of full screen. It only runs in full screen if I first go to the game setup and then I hit the 'Save and Run' button.

By the way, excellent job with AGS 2.8 :)

SMF spam blocked by CleanTalk