About Store Forum Documentation Contact



Post Reply 
FixedArray and setNumZero
Author Message
Houge Offline
Member

Post: #1
FixedArray and setNumZero
Hi!

I know that FixedArray doesn't support adding or removing elements, but is it possible to add something like "setNumZero" to its constructor?
When FixedArray is created of simple types (like Int) there's garbage after creation, and I'd like to be able to have zeroes by default without a need to go through each element and set it o 0.

Thanks!
12-05-2020 08:32 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #2
RE: FixedArray and setNumZero
This can't be done because elements are already allocated/constructed as:
TYPE _data_org[NUM];

setNumZero in other classes:
1. allocates memory
2. zeroes memory
3. calls constructor

But because FixedArray is TYPE _data_org[NUM] then constructor is already called.

What you could do is make a custom class, something like this

Code:
class FixedArrayZero : FixedArray<.., ..>
{
   FixedArrayZero() {REPAO(T)=0;}
}
12-06-2020 08:36 AM
Find all posts by this user Quote this message in a reply
Houge Offline
Member

Post: #3
RE: FixedArray and setNumZero
Ah, got it. Yes, I will probably do that. Thank you!
12-06-2020 06:20 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Houge Offline
Member

Post: #4
RE: FixedArray and setNumZero
OK, I actually can't do that because of the forward declaration.

Code:
private:
   TYPE _data_org, *_data;
this in FixedArray needs to know the exact size of the member but due to forward declaration it doesn't and I get the following error:

Code:
error C2079: 'EE::FixedArray<TYPE,5>::_data_org' uses undefined struct '_customClass'
message : see reference to class template instantiation 'EE::FixedArray<TYPE,5>' being compiled
message : see reference to class template instantiation 'FixedArrayZero<_customClass,5>' being compiled

But it works fine with FixedArray.
I guess I'll have to have FixedArray as a private member of my own class.
(This post was last modified: 12-07-2020 06:10 AM by Houge.)
12-07-2020 06:05 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #5
RE: FixedArray and setNumZero
What exactly is the problem?
Code:
<TYPE, int NUM> class FixedArrayZero : FixedArray<TYPE, NUM>
{
   FixedArrayZero()
   {
      REPAO(T)=0;
   }
}
FixedArrayZero<int, 5> test;
12-07-2020 06:49 AM
Find all posts by this user Quote this message in a reply
Houge Offline
Member

Post: #6
RE: FixedArray and setNumZero
I get the error in my project but I can't reproduce it in "hello world" project to send it to you, and I don't understand why. I do exactly as you say and get two different results in two projects.

The error doesn't happen with simple types, only with custom structs/classes.

UPD: OK I made it. But I think the bug is in different place. Here's the full app:
Code:
/******************************************************************************/
<TYPE, int NUM> class FixedArrayZero : FixedArray<TYPE, NUM>
{
   FixedArrayZero()
   {
      REPAO(T)=0;
   }
}

struct _saProgressColorScheme
{                  
    Color colorOne,
          colorTwo;
    
    _saProgressColorScheme &operator=(C Int   &value) {    colorOne = colorTwo = Color(value);    return T;    }
}
struct _saProgressColorSchemeSet
{
    FixedArrayZero<_saProgressColorScheme, 6> hpStyle;
    FixedArrayZero<_saProgressColorScheme, 6> mpStyle;
}

/******************************************************************************/
void InitPre() { EE_INIT();   }
bool Init()    { return true; }
void Shut()    {}
bool Update()  { return Kb.bp(KB_ESC) ? false : true;}
void Draw()    {}
/******************************************************************************/

Funny thing: error happens only with struct name "_saProgressColorScheme". If I use other struct names, error disappears.

What is going on here?

UPD2:
When I export project with an error to Visual Studio, even if I rename the class it does no difference, error still exists. And vice versa, if I export a project with different class name, I can change it in Visual Studio to whatever, it still compiles without problems.
(This post was last modified: 12-08-2020 03:28 AM by Houge.)
12-08-2020 02:53 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #7
RE: FixedArray and setNumZero
Hi and sorry for taking so long, that was not a trivial problem.
I was able to fix it, please update the source from GitHub.
04-09-2021 04:13 PM
Find all posts by this user Quote this message in a reply
Houge Offline
Member

Post: #8
RE: FixedArray and setNumZero
Thanks a lot!
04-15-2021 05:26 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Post Reply