Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Storing array #90

Open
bayou-brogrammer opened this issue Jul 2, 2022 · 3 comments
Open

Storing array #90

bayou-brogrammer opened this issue Jul 2, 2022 · 3 comments

Comments

@bayou-brogrammer
Copy link

Can't seem to figure out how to store an array of ui8. I have a component for FieldOfView which changes everytime the player moves. The visibleTiles just hold the idx [(y as usize * self.width as usize) + x as usize] to the relative tiles that are currently visible

export const FieldOfView = defineComponent(
  {
    radius: Types.ui8,
    isDirty: Types.ui8,
    visibleTiles: [Types.ui8],
  },
  5,
);

After this definition, I get unknown as the type
CleanShot 2022-07-02 at 14 58 08@2x

Im probably missing something really simple. Or if there is a better way to store visible tiles let me know

@bayou-brogrammer
Copy link
Author

errr so I was dumb. I needed to provide a number for the typed array after looking to the source.
CleanShot 2022-07-02 at 15 07 47@2x

My question is what does that number actually do in terms of size? I printed the components to the console and it shows that visibileTiles is an array allocated to 1000 units.

CleanShot 2022-07-02 at 15 08 54@2x

Is that standard or are we able to control how much allocation to start with? FieldOfView is a very spare component so I doubt it needs 1000

@vegeta897
Copy link
Contributor

You can pass an integer as a second argument into defineComponent to control how large the data arrays are.

The number you use with your typed array definition controls how large the array is for each entity. With a size of 1 it's basically pointless compared to a single ui8 value. If it's meant to index the tiles on your map, then it needs to be as big as the map's total number of tiles.

@NateTheGreatt
Copy link
Owner

My question is what does that number actually do in terms of size? I printed the components to the console and it shows that visibileTiles is an array allocated to 1000 units.
Is that standard or are we able to control how much allocation to start with? FieldOfView is a very spare component so I doubt it needs 1000

This is due to a resizing bug on the current release. it should be fixed on master, pending release soon:tm:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants