Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 59 60 [61] 62 63 ... 91

Author Topic: Programming Help Thread (For Dummies)  (Read 100640 times)

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: Programming Help Thread (For Dummies)
« Reply #900 on: November 08, 2012, 07:17:11 am »

I check "if int n is zero", and if it is I return.
I cannot push_back zeros, and I don't need to: it's for my map-based lookup system.

The problem is that if I put the implementation in the cpp, the compiler complains that the default value was redefined. error C2572: 'assign_to_vector' : redefinition of default parameter for all eight parameters. Microsoft documentation asserts that I need to put the implementation with the definition for functions with default parameters. ;_;
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #901 on: November 08, 2012, 08:35:22 am »

See http://stackoverflow.com/questions/4989483/where-to-put-default-parameter-value-in-c
Default-values in either location is okay, not in both. Preferably the definition.
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

Araph

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #902 on: November 08, 2012, 08:22:06 pm »

Figured out what was wrong with the PHP script! Turns out I accidentally used '+' instead of '.' here:

Code: [Select]
$file = fopen("polls/" . $_GET['option'] + ".txt", "r+");
Logged

thobal

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #903 on: November 14, 2012, 03:19:49 pm »

For some reason I'm getting garbage values at certain places. Typically the same place, but if I change the planetZdimension value, they shift around.

But they are always around terrainMap[planetZdimension][0]
  • where x is between 2 and 5(inclusive). Basically, these three or four values are returning garbage and I dont know why. It's not an issue yet, and I can set them manually, but I'm just wondering why the loop doesnt set them.
Code: [Select]
   
const int planetXdimension = 96;
const int planetYdimension = 64;
const int planetZdimension = 18;

for (int i = 0; i < NUMBER_OF_PLANETS; i++)
    {
        context.planetMaps[i] =  new PlanetMaps ;

        for (int z = 0; z < planetZdimension; z++)
        {
        context.planetMaps[i]->fillEmpty(z);
        }

       
    }
That is running in the main loop, then there is this:
Code: [Select]
void PlanetMaps::fillDirt(int z)
{
   // for (int z = 0; z < 4; z++)
   // {
        for (int y = 0; y < planetYdimension - 1 ; y++)
        {
            for (int x = 0; x < planetXdimension - 1 ; x++)
            {
                terrainMap[z][y][x] = DIRT;
            }
        }
  //  }
}
Logged
Signature goes here.

Levi

  • Bay Watcher
  • Is a fish.
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #904 on: November 14, 2012, 03:41:29 pm »

I don't think you need the -1 on the planetXdimension and planetYdimension for loops(unless you've made your array sizes planetXdimension - 1).  That'll cut it off an element early I think.  Not sure if that is specifically causing the error though.
Logged
Avid Gamer | Goldfish Enthusiast | Canadian | Professional Layabout

Normandy

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #905 on: November 14, 2012, 03:46:06 pm »

Can you provide additional code? It's hard to tell what's going on from such a small snippet. Especially where you allocate memory for planetMaps and terrainMap.

Although from your current code there seem to be a couple bugs. When you mention "terrainMap[planetZdimension][0]", is your first dimension, terrainMap[] is initialized as a length planetZdimension+1 (or higher) array? During your for loops, you loop up to less than planetYdimension-1, meaning that if terrainMap[z][] is a planetYdimension length array, the last element at index planetYdimension-1 is never initialized (since the loop terminates when it reaches this value). A similar error occurs in the x dimension. Is this intentional?
Logged

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #906 on: November 14, 2012, 05:12:21 pm »

Did you initialise all the arrays?
That means initialising 96 arrays, each containing 64 arrays of size 18.
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

thobal

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #907 on: November 14, 2012, 05:55:06 pm »

The -1 is just so I can see where the level ends. Also, I posted the wrong code snippet and firefox ate my reply. I'm just gonna upload the whole damn folder. I'm not sure why I'm so worried about this. Also, to answer Normany's question: What do you mean, allocate memory? Here is my main function:

Code: [Select]
int main(int argc, char** argv)
{
    int resolutionSizeX = 1080;
    int resolutionSizeY = 960;

    DisplayerOutputer display;
    PlayerViewSettings player;


    IrrlichtDevice * device =
        createDevice(EDT_OPENGL, dimension2d<u32>(resolutionSizeX, resolutionSizeY), 16,
        false, false, false, 0);



    SAppContext context;
    context.playerView = &player;
    context.device = device;

    loadPngs(context);

    for (int i = 0; i < NUMBER_OF_PLANETS; i++)
    {
        context.planetMaps[i] =  new PlanetMaps ;

        for (int i2 = 0; i2 < planetZdimension; i2++)
        {
        context.planetMaps[i]->fillEmpty(i2);
        }

        printf("\nPLanet #"); printf("%p", context.planetMaps[i]);
    }




    context.planetMaps[0]->fillDirt(6);
    context.planetMaps[0]->fillDirt(0);



    SetupGraphics( context );

    MyEventReceiver receiver(context);
    device->setEventReceiver(&receiver);


    IVideoDriver* driver = device->getVideoDriver();




    while(device->run())
    {

        driver->beginScene(true, true, SColor(0,200,200,200));

        display.drawGraphics(context);


        driver->endScene();
    }

    device->drop();

    return EXIT_SUCCESS;

So far as allocating memory goes, that's all I know. I'll post the PlanetMaps class next:

Code: [Select]
const int planetXdimension = 96;
const int planetYdimension = 64;
const int planetZdimension = 16;

enum TerrainTypes {EMPTY = 'n',
                    DIRT,
                    ROCK,
                    ORE};

enum TerrainAspect {LEVEL, SLOPE_NORTH, SLOPE_SOUTH, SLOPE_EAST, SLOPE_WEST,
                        SLOPE_NW, SLOPE_NE, SLOPE_SW, SLOPE_SE};
Code: [Select]
struct PlanetMaps
{


   

    TerrainTypes terrainMap [planetZdimension][planetYdimension][planetXdimension];



    int planetX;
    int planetY;







    void fillDirt(int);
    void fillEmpty(int);
    void drawTestLine(int);
    void drawTestArrow();

};
Code: [Select]
void PlanetMaps::drawTestArrow()
{

 drawTestLine(5);
 for (int i = 1; i < 10; i++)
    {
        terrainMap[1][0][i] = DIRT;
    }
}
Code: [Select]
void PlanetMaps::fillDirt(int z)
{

        for (int y = 0; y < planetYdimension - 1 ; y++)
        {
            for (int x = 0; x < planetXdimension - 1 ; x++)
            {
                terrainMap[z][y][x] = DIRT;
            }
        }

}
Code: [Select]
void PlanetMaps::fillEmpty(int z)
{
{
        for (int y = 0; y < planetYdimension ; y++)
        {
            for (int x = 0; x < planetXdimension ; x++)
            {
                terrainMap[z][y][x] = EMPTY;
            }
        }

}
Code: [Select]
void PlanetMaps::drawTestLine(int line)
{
    for (int i = 0; i < 16; i++)
    {
        terrainMap[1][i][line] = DIRT;
    }
}


Also, PlanetMaps.planetX and PlanetMaps.planetY are irrlevant. Having some trouble with rapidshare so you cant get the whole source. I'll post a pic later if my error wasnt obvious.

Oh, and the context struct:

Code: [Select]
struct SAppContext
{
    IrrlichtDevice *device;
    IGUIFont* font;

    PlanetMaps *planetMaps[NUMBER_OF_PLANETS];
    PlayerViewSettings *playerView;

    video::ITexture *emptyBlock;
    video::ITexture *dirtBlock;
    video::ITexture *testBlock;
};
« Last Edit: November 14, 2012, 05:56:57 pm by thobal »
Logged
Signature goes here.

RulerOfNothing

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #908 on: November 14, 2012, 06:48:20 pm »

When you say you are getting garbage values at some places, are there any places which are more common than others? What kind of garbage values are you getting (i.e. are they all the same or random)?
Logged

thobal

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #909 on: November 14, 2012, 07:22:08 pm »

They are only on the top level
here is the printf readout of the variable values:
Code: [Select]
printf("\n%i", context.planetMaps[0]->terrainMap[16][0][0]);
    printf("\n%i", context.planetMaps[0]->terrainMap[16][0][1]);
    printf("\n%i", context.planetMaps[0]->terrainMap[16][0][2]);
    printf("\n%i", context.planetMaps[0]->terrainMap[16][0][3]);
    printf("\n%i", context.planetMaps[0]->terrainMap[16][0][4]);
    printf("\n%i", context.planetMaps[0]->terrainMap[16][0][5]);
    printf("\n%i", context.planetMaps[0]->terrainMap[16][0][6]);




0
0
-1073561598
17301766
110
110
110

Here is the display, there should be all boxes on the top level, not three missing.
Spoiler (click to show/hide)



Logged
Signature goes here.

RulerOfNothing

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #910 on: November 14, 2012, 09:14:32 pm »

Code: [Select]
printf("\n%i", context.planetMaps[0]->terrainMap[16][0][0]);
    printf("\n%i", context.planetMaps[0]->terrainMap[16][0][1]);
    printf("\n%i", context.planetMaps[0]->terrainMap[16][0][2]);
    printf("\n%i", context.planetMaps[0]->terrainMap[16][0][3]);
    printf("\n%i", context.planetMaps[0]->terrainMap[16][0][4]);
    printf("\n%i", context.planetMaps[0]->terrainMap[16][0][5]);
    printf("\n%i", context.planetMaps[0]->terrainMap[16][0][6]);

Here is the display, there should be all boxes on the top level, not three missing.
Spoiler (click to show/hide)
Firstly, there are actually 4 boxes missing, secondly your map should only go up to z=15 (since arrays in C++ are zero based).
Logged

thobal

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #911 on: November 14, 2012, 11:03:33 pm »

Still doesnt explain why they arent showing up right.
Logged
Signature goes here.

Normandy

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #912 on: November 14, 2012, 11:08:42 pm »

By allocating memory I meant where the size of the array is initialized. But yeah, RulerOfNothing is right, terrainMap[16] points to garbage data since it's outside the bounds of your array. I suspect the blocks might not be showing since when you attempt to render the block on the screen, your renderer can't make sense of the input value and so it doesn't render anything.
Logged

olemars

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #913 on: November 15, 2012, 11:03:14 am »

You're indexing out of bounds, so the first four values are actually planetX and planetY of context.planetMaps[0] plus some padding or metadata, while the last three are the first data values of context.planetMaps[1].

Still doesnt explain why they arent showing up right.

I'm a bit confused by what's showing up at all. The code indicates that z layer 0 and 6 are DIRT blocks while the rest are EMPTY and hidden, so what is the top layer?
Logged

thobal

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #914 on: November 15, 2012, 06:08:00 pm »

Empty cubes are drawn on the active layer in place of nothing. It's so you cant quickly see which layer you have selected when you're in the sky. It's a placeholder, more or less.

Edit: I dug through the input code and it turns out I had an off by one error in there. I think my subconcious just wouldnt let me accept that it could be something so simple.
« Last Edit: November 15, 2012, 08:55:16 pm by thobal »
Logged
Signature goes here.
Pages: 1 ... 59 60 [61] 62 63 ... 91