Jump to content

  • Log In with Google      Sign In   
  • Create Account


Vortez

Member Since 15 Jun 2007
Offline Last Active Jul 14 2014 12:39 PM

Posts I've Made

In Topic: very strange bug (when runing c basic arrays code)

30 June 2014 - 11:22 AM

You know how the stack work, right?

 

http://stackoverflow.com/questions/6219878/stack-overflow-c


In Topic: very strange bug (when runing c basic arrays code)

30 June 2014 - 11:17 AM


100*1000 is 100,000 elements, 6 such arrays make 600,000 elements 4 bytes each, that's 2,400,000 bytes or over 2 MB. That's bigger than default stack size, that's why you get crash. Use new[] operator for those arrays and it'll work just fine.

 

You have your answer right there, stop blaming the compiler for your mistake. Either allocate the array with new(recommended) or increase the stack size. Default stack size is 1 Mb IIRC.


In Topic: Can't clip tiles without crashing

29 June 2014 - 02:34 PM


And to Vortez, I did the index thing, but I don't know how to set it all at once with different coordinates.

 

You dont have to have a vector class to do this, that was just a suggestion, you could roll up a function for this, for example.

void SetTile(TILES *pTile, int x, int y, int TileSize)
{
    pTile->x = x;
    pTile->y = y;
    pTile->w = TileSize;
    pTile->h = TileSize;
}

Calculating the x and y coordinate shouldn't be too difficult. I'll let you figure it out.

 

As for the lua part, i can't help you on that, haven't done that sort of thing yet.


In Topic: How do multyple people write code for one project?

29 June 2014 - 02:27 PM

Use something like github, it will make you're life much easier. Although i cannot give you much advice since i only used it for my personal project, never coded in a team.


In Topic: Can't clip tiles without crashing

29 June 2014 - 10:44 AM

You're repeating yourself a lot in this code, and the readability is not very good, i suggest caching those values into variables or consts.

 

Example:

            tiles_i[(y * tiles_across) + x].x = 16;
            tiles_i[(y * tiles_across) + x].y = 16;
            tiles_i[(y * tiles_across) + x].w = 16;
            tiles_i[(y * tiles_across) + x].h = 16;           
            printf
("%d\n",(y * tiles_across) + x);

 

could be replaced by

            const TileSize = 16;

            ...

            int Index = (y * tiles_across) + x)

            tiles_i(Index).x = TileSize;

            tiles_i(Index).y = TileSize;

            tiles_i(Index).z = TileSize;

            tiles_i(Index).w = TileSize;

 

Even better would be using a vector class, and overload the = operator

 

            tiles[Index] = TileSize; // Set all four values at once

 

Mine look like this. Notice i didn't think about overloading the = operator with a float, but it would take 30 seconds to add one, or i could use the Set() method.


PARTNERS