• Create Account

### #ActualRiztro

Posted 23 December 2012 - 04:46 PM

I think you are assigning a pointer (that is an array) of arrays to a pointer. Notice the different types it says you are converting between?

error: cannot convert ‘uint8 (*)[4096] {aka unsigned char (*)[4096]}’ to ‘uint8* {aka unsigned char*}’ in assignment

From uint8*[] to uint8*.
Or, in another sense*, from uint8[][] to uint8[].

*Not technically accurate, but for illustrative purposes. [] is not identical to *, even if [] can convert to *.

It'd be easiest to just have it as a one-dimensional array that you treat like a 2D array:

m_Tile = new uint8[MAP_WIDTH * MAP_HEIGHT];

m_Tile[(y * MAP_WIDTH) + x] = blah;

But why not use a one-dimensional std::vector so the memory is managed for you?

std::vector<uint8> m_Tiles(MAP_WIDTH * MAP_HEIGHT);

uint8 myClass::GetTile(unsigned x, unsigned y)
{
return this->m_Tiles[(y * MAP_WIDTH) + x];
}

Ohhh okay thankyou!! It compiles! And I just want to use dynamic memory because it is a bit quicker when I access it every draw call.

But now I have run into another problem, I wrote a program that generates tile IDs in the range of 0 to 1, but it is generating way more than I want. Can anyone tell me why? Here is my function:

//Little program to generate test map with only 0 and 1 tile

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <fstream>

using namespace std;

int main()
{
ofstream file;
file.open("default.vmf", ios::trunc);
for (int j = 0; j < 4096; j++)
{
for (int i = 0; i < 4906; i++)
{
file << rand()%2;
}
file << '\n';
}
file.close();
return 0;
}

So the file size should be (4096*4096) + 4096 == 16781312 right? Because I am filling up all the tiles and adding \n at the end of every 4096 tiles. But then after my program runs, the file is 20099072 bytes large. I don't understand what is happening here :/

EDIT: Just saw the problem.. I made a typo, 4906 instead of 4096

### #2Riztro

Posted 23 December 2012 - 04:43 PM

I think you are assigning a pointer (that is an array) of arrays to a pointer. Notice the different types it says you are converting between?

error: cannot convert ‘uint8 (*)[4096] {aka unsigned char (*)[4096]}’ to ‘uint8* {aka unsigned char*}’ in assignment

From uint8*[] to uint8*.
Or, in another sense*, from uint8[][] to uint8[].

*Not technically accurate, but for illustrative purposes. [] is not identical to *, even if [] can convert to *.

It'd be easiest to just have it as a one-dimensional array that you treat like a 2D array:

m_Tile = new uint8[MAP_WIDTH * MAP_HEIGHT];

m_Tile[(y * MAP_WIDTH) + x] = blah;

But why not use a one-dimensional std::vector so the memory is managed for you?

std::vector<uint8> m_Tiles(MAP_WIDTH * MAP_HEIGHT);

uint8 myClass::GetTile(unsigned x, unsigned y)
{
return this->m_Tiles[(y * MAP_WIDTH) + x];
}

Ohhh okay thankyou!! It compiles! And I just want to use dynamic memory because it is a bit quicker when I access it every draw call.

But now I have run into another problem, I wrote a program that generates tile IDs in the range of 0 to 1, but it is generating way more than I want. Can anyone tell me why? Here is my function:

//Little program to generate test map with only 0 and 1 tile

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <fstream>

using namespace std;

int main()
{
ofstream file;
file.open("default.vmf", ios::trunc);
for (int j = 0; j < 4096; j++)
{
for (int i = 0; i < 4906; i++)
{
file << rand()%2;
}
file << '\n';
}
file.close();
return 0;
}

So the file size should be (4096*4096) + 4096 == 16781312 right? Because I am filling up all the tiles and adding \n at the end of every 4096 tiles. But then after my program runs, the file is 20099072 bytes large. I don't understand what is happening here :/

### #1Riztro

Posted 23 December 2012 - 04:42 PM

I think you are assigning a pointer (that is an array) of arrays to a pointer. Notice the different types it says you are converting between?

error: cannot convert ‘uint8 (*)[4096] {aka unsigned char (*)[4096]}’ to ‘uint8* {aka unsigned char*}’ in assignment

From uint8*[] to uint8*.
Or, in another sense*, from uint8[][] to uint8[].

*Not technically accurate, but for illustrative purposes. [] is not identical to *, even if [] can convert to *.

It'd be easiest to just have it as a one-dimensional array that you treat like a 2D array:

m_Tile = new uint8[MAP_WIDTH * MAP_HEIGHT];

m_Tile[(y * MAP_WIDTH) + x] = blah;

But why not use a one-dimensional std::vector so the memory is managed for you?

std::vector<uint8> m_Tiles(MAP_WIDTH * MAP_HEIGHT);

uint8 myClass::GetTile(unsigned x, unsigned y)
{
return this->m_Tiles[(y * MAP_WIDTH) + x];
}

Ohhh okay thankyou!! It compiles! And I just want to use dynamic memory because it is a bit quicker when I access it every draw call.

But now I have run into another problem, I wrote a program that generates tile IDs in the range of 0 to 1, but it is generating way more than I want. Can anyone tell me why? Here is my function:

//Little program to generate test map with only 0 and 1 tile

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <fstream>

using namespace std;

int main()
{
ofstream file;
file.open("default.vmf", ios::trunc);
for (int j = 0; j < 4096; j++)
{
for (int i = 0; i < 4906; i++)
{
file << rand()%2;
}
file << '\n';
}
file.close();
return 0;
}

So the file size should be (4096*4096) + 4096 right? Because I am filling up all the tiles and adding \n at the end of every 4096 tiles. But then after my program runs, the file is 20099072 bytes large. I don't understand what is happening here :/

PARTNERS