Aller au contenu

Photo

[Question] Dynamic Memory?


  • Veuillez vous connecter pour répondre
16 réponses à ce sujet

#1
Gralamin

Gralamin
  • Members
  • 45 messages
Does Dragon Age support dynamic memory? (Either made c style through malloc, or C++ Style through new). It might be useful to have the capability in certain circumstances.

#2
Gralamin

Gralamin
  • Members
  • 45 messages
Found out someone is already working on it. Exciting stuff. http://social.biowar.../8/index/225921

#3
kosmonymous

kosmonymous
  • Members
  • 16 messages
I have a solution for this already working.. I created global saveable variables to module via 2da and then made an utility interface to reserve some portion of those to array that can be handled through that interface. It handles just the basic types so structs must be done by having multiple arrays and keeping the indexes in same order.



If you need it I can send it to you, even though its not extensively tested yet.

#4
Astorax

Astorax
  • Members
  • 324 messages
Make it a project kosmonymous, upload it with the caveat that it isn't thoroughly tested, and BAM, free QA. :D

#5
Quildra

Quildra
  • Members
  • 45 messages
could you forward this to me as well as it seems like I might be able in integrate this in to my summon-able chest mod so i can finally take my inventory from area to area

#6
kosmonymous

kosmonymous
  • Members
  • 16 messages
There you go :) Please continue discussion regarding the functionality of my implementation in project discussions as they will benefit all.



http://social.biowar...ct/825/#details

#7
Quildra

Quildra
  • Members
  • 45 messages
You'll need to make the files public so we can download them. I fell into this pot hole already :(

Its in manage files on the files section :)

#8
Phaenan

Phaenan
  • Members
  • 315 messages
I will have a look at it myself, I was just starting to work on something similar for my own stuff. :o

Modifié par Phaenan, 21 novembre 2009 - 11:58 .


#9
kosmonymous

kosmonymous
  • Members
  • 16 messages
Done, thanks Quildra. Phaenan it is not very complex to do that functionality, but its ridiculously slow work to test and debug the code and hunt all the bugs.

#10
Phaenan

Phaenan
  • Members
  • 315 messages
I hear you. Some love for us debuggers would be great, it's a bit tedious with DisplayFloatyMessage() as only weapon.

Thanks for making the file public. :o

#11
elys

elys
  • Members
  • 458 messages
Here a concept for Dynamic AutoSized Integer Arrays:

The idea is to use a string as an array, storing each integer into its Hexadecimal string representation.

For example:

1 = "00000000"
50 = "00000032"
- 1386702516 = "AD58994C"

so the array [1, 50, -1386702516] would  be stored in our string  as "0000000000000032AD58994C"

Here some code below, I've just typed the code here, I don't know if it works correctly. Remember it's just a theory.

Nor I know what is the internal size limit of DAO's string type.

I also assume the DAO's HexToIntString function to return something like "XXXXXXXX" and not "XXXXh" or whatever but anyway this would just require to adjust the script for it.

You may notice in the code that part of it is like duplicated, and may think I should have make this "often-use" code part into  functions or procedures.
But it is on purpose. If DAO's can indeed handle long strings and so be able to contain big arrays, we might want to spare the process memory and stack by not passing and duplicating these long strings as function parameters.


int GetArrayLength(string sArray)
{
    //Get the Array Length
    int nLen = GetStringLength(sArray);
    if (nLen < 8)
        return 0;
    return nLen / 8;
}   
string SetArrayLength(string sArray, int nNewLen)
{
    // nLen <-- Get the Array Length
    int nLen = GetStringLength(sArray);
    if (nLen < 8)
        nLen = 0;
    else
        nLen = nLen / 8;  
        
     
    //if the new array length is bigger then fill the gap up with "zeroes"
    if (nNewLen > nLen)
    {
      
       //Insert zero values to fill the array up for the new length
       int nCount;
       do
       {
            sArray = InsertString(sArray, "00000000", (nLen + nCount) * 8);
            nCount++;
       }
       while (nCount < nNewLen - nLen);
    }
    //else if smaller return the array truncated
    else
        return SubString(sArray,0, nNewLen * 8);
    
    // return the new array
    return sArray;
}
int GetIntFromArray(string sArray, int nIndex)
{
    // nLen <-- Get the Array Length
    int nLen = GetStringLength(sArray);
    if (nLen < 8)
        nLen = 0;
    else
        nLen = nLen / 8;
        
    //Index ouf of range, return zero
    if (nIndex > nLen - 1)
        return 0; 
    //return Array[Index] value
    return HexStringToInt(SubString(sArray, nIndex*8, 8));
} 
string SetIntInArray(string sArray, int nIndex, int nValue = 0)
{
    // nLen <-- Array Length
    int nLen = GetStringLength(sArray);
    if (nLen < 8)
        nLen = 0;
    else
        nLen = nLen / 8;
        
    // nLenDiff <--- Difference between the current and new array length     
    int nLenDiff = nIndex + 1 - nLen;
    
    // If need to increase the Array Length, fill with zero values.
    if (nLenDiff > 1)
    {
       //Insert zero values to fill the array up to our new value Index
       int nCount;
       do
       {
            sArray = InsertString(sArray, "00000000", (nLen + nCount) * 8);
            nCount++;
       }
       while (nCount < nLenDiff - 1);
      
       
        // Insert the new value and return updated array
        return InsertString(sArray, IntToHexString(nValue) , nIndex *8 ); 
    } 
    
    //else update Array[Index] with new value
    return SubString(sArray, 0, nIndex * 8) + IntToHexString(nValue) + SubString(sArray, (nIndex + 1) * 8, (nLen - 1 - nIndex) * 8);
}


If this works, you can adapt it for Float and String arrays with a little more code.

Modifié par elys, 21 novembre 2009 - 01:41 .


#12
CID-78

CID-78
  • Members
  • 1 124 messages
that is a waste of memory a int is 32bit so it can be represented as 4 character (8bit ASCII). it's just a matter of bit shifting.

#13
kosmonymous

kosmonymous
  • Members
  • 16 messages
Elys, I like your idea :) Then the strings could be saved to 2da and the arrays would be saveable. In those you could also save structs if needed, even though that would make the code lot more complex. My implementation has an true integer for each int you save but end-user-wise it would make no difference. Your concept is limited by string-lenght and mine by variables in the 2da.

#14
kosmonymous

kosmonymous
  • Members
  • 16 messages
CID-78 doing that would make DA:O creators think again should they have provided this kind of functionality via engine :D

#15
elys

elys
  • Members
  • 458 messages

CID-78 wrote...
that is a waste of memory a int is 32bit so it can be represented as 4 character (8bit ASCII). it's just a matter of bit shifting.


I guess DAO strings are unicode strings, and so using widechar, which means each char takes 16 bits of memory.

Using the available IntToChar function (which handles only 8bits), you would still only be able to store each integer-8bits part into a WideChar(16 bits)
So it would still be a waste of memory, just half less.

But that is assuming that DAO string functions only handle string internally by stored length, and not by handling null terminator.
Because else storing Byte as Char directly as you suggest would be very bad. For example 00h stored would mean the string is terminated for DAO while it's not the case.

Modifié par elys, 21 novembre 2009 - 03:20 .


#16
elys

elys
  • Members
  • 458 messages
Well it's time for for a big smile for me.

I just noticed Dragon Age origins natively supports array. For example by declaring:

int[] nArray;

I have not verified if it's only to handle engine-generated arrays returned by engine functions such as GetObjectsInShape, or if you can declare one and assign values to indexes to get it autosized.

Modifié par elys, 23 novembre 2009 - 05:49 .


#17
Phaenan

Phaenan
  • Members
  • 315 messages
Yep, that's pretty much what I do in my code to get (and save) an ersazt of multidirectionnal array. I can't get out of my head the feeling that's not that clean, but I've thought of anything better to have persistent "arrays".