Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 21 22 [23] 24 25 ... 91

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

alway

  • Bay Watcher
  • 🏳️‍⚧️
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #330 on: November 23, 2011, 04:35:04 pm »

Yeah, your sort function is hardwired for 20 elements and you are giving it arrays with size 5. The memory allocation probably* puts arrays 1, 2, and 3 next to one another and sort(array1) simply treats those 3 arrays as a single array and sorts it as such, while sort(array2) takes the values in memory for array 2, array3, and whatever random noise is stored in the 5 positions after the end of array3 as a size 20 array, thus giving you 15 of your numbers and 5 random values from memory. My guess would be your error came from a brainfart involving the size of the array in bites (20) being confused for the size of the array in elements (5).

*memory allocation will usually allocate this way iirc, since they are being created one after the other in code, though automated code optimization or a memory shortage in a specific block of memory allocated to the program may cause them to be stored elsewhere.
« Last Edit: November 23, 2011, 04:41:52 pm by alway »
Logged

MaximumZero

  • Bay Watcher
  • Stare into the abyss.
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #331 on: November 23, 2011, 04:37:35 pm »

The form definition is just a class. The Form in the application is just an object. Add a public member to the form definition of form 2 and set it from form 1.

No matter how many times I read this, I still can't make heads or tails of it. Care to elaborate, oh Zen Master?
Logged
  
Holy crap, why did I not start watching One Punch Man earlier? This is the best thing.
probably figured an autobiography wouldn't be interesting

Darvi

  • Bay Watcher
  • <Cript> Darvi is my wifi.
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #332 on: November 23, 2011, 04:49:16 pm »

Yeah, your sort function is hardwired for 20 elements and you are giving it arrays with size 5.
Yeah I just figured that out. I simply copied the function from a previous file and didn't even bother to check  :x
Logged

DrKillPatient

  • Bay Watcher
  • The yak falls infinitely
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #333 on: November 23, 2011, 05:07:05 pm »

I'm trying to make a basic system for graphical tiles, similar to DF in the way of having (changeable) ASCII tilesets printed out to the screen. I'd like to use a fairly common portable library such as OpenGL or SDL. Does anyone here know of a decent tutorial for such a thing?
Logged
"Frankly, if you're hanging out with people who tell you to use v.begin() instead of &v[0], you need to rethink your social circle."
    Scott Meyers, Effective STL

I've written bash scripts to make using DF easier under Linux!

Gatleos

  • Bay Watcher
  • Mournhold... City of Light... City of MAGIC!
    • View Profile
    • Someone Sig This
Re: Programming Help Thread (For Dummies)
« Reply #334 on: November 23, 2011, 06:09:06 pm »

I'm trying to make a basic system for graphical tiles, similar to DF in the way of having (changeable) ASCII tilesets printed out to the screen. I'd like to use a fairly common portable library such as OpenGL or SDL. Does anyone here know of a decent tutorial for such a thing?
Well, libtcod is made with SDL and just as portable. If you want to make it by scratch, on the other hand:

In my experience, it's dead simple to make a graphics engine to draw ASCII tiles from a bitmap. Everything you need is in SDL's basic blitting functions. The tough part is the colors. In SDL, there's really no "clean" way to tint a surface before drawing it. Every method I could find was either way too slow or way too memory-heavy. So, OpenGL is really the way to go if you want a quick way to draw colored ASCII tiles.
Logged
Think of it like Sim City, except with rival mayors that seek to destroy your citizens by arming legions of homeless people and sending them to attack you.
Quote from: Moonshadow101
it would be funny to see babies spontaneously combust
Gat HQ (Sigtext)
++U+U++ // ,.,.@UUUUUUUU

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #335 on: November 23, 2011, 06:24:01 pm »

Yeah, your sort function is hardwired for 20 elements and you are giving it arrays with size 5.
Yeah I just figured that out. I simply copied the function from a previous file and didn't even bother to check  :x
Any reason you can't just use a built-in sorting function? Because right now you're using bubble sort, which is kind of the slowest sorting algorithm you're ever going to see (It's O(n2) with a high prefactor. The only reason you ever see it is for didactic reasons)
Logged

Darvi

  • Bay Watcher
  • <Cript> Darvi is my wifi.
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #336 on: November 23, 2011, 06:52:07 pm »

Was part of the problem. So  yeah, didactic reasons.
Logged

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #337 on: November 23, 2011, 06:53:28 pm »

Tell them to teach you something useful then (insertion sort maybe?) :P
Logged

Darvi

  • Bay Watcher
  • <Cript> Darvi is my wifi.
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #338 on: November 23, 2011, 06:53:49 pm »

Quicksort.
Logged

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #339 on: November 23, 2011, 06:56:10 pm »

For a 20 element array? Well, if the alternative is bubble sort it makes sense...
Logged

alfie275

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #340 on: November 23, 2011, 06:57:14 pm »

If you're doing tiles in opengl you might want to just use textured quads.
Logged
I do LP of videogames!
See here:
http://www.youtube.com/user/MrAlfie275

DrKillPatient

  • Bay Watcher
  • The yak falls infinitely
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #341 on: November 23, 2011, 10:25:00 pm »

If you're doing tiles in opengl you might want to just use textured quads.

I'm not at all familiar with OpenGL-- is that essentially creating a row of squares along the screen (each the size of one tile on the tileset bitmap) and retexturing them as needed?
Logged
"Frankly, if you're hanging out with people who tell you to use v.begin() instead of &v[0], you need to rethink your social circle."
    Scott Meyers, Effective STL

I've written bash scripts to make using DF easier under Linux!

Shades

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #342 on: November 24, 2011, 05:18:44 am »

Quicksort.

Dual-pivot Quicksort, that extra ~20% efficiency over those huge 20 element lists might save you whole cycles :)
Logged
Its like playing god with sentient legos. - They Got Leader
[Dwarf Fortress] plays like a dizzyingly complex hybrid of Dungeon Keeper and The Sims, if all your little people were manic-depressive alcoholics. - tv tropes
You don't use science to show that you're right, you use science to become right. - xkcd

Darvi

  • Bay Watcher
  • <Cript> Darvi is my wifi.
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #343 on: November 24, 2011, 06:54:19 am »

Boggosort is best sort.

And now I have to PM scriver that typo.
Logged

malloc

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #344 on: November 25, 2011, 07:19:54 am »

If you're doing tiles in opengl you might want to just use textured quads.

I'm not at all familiar with OpenGL-- is that essentially creating a row of squares along the screen (each the size of one tile on the tileset bitmap) and retexturing them as needed?
Yes pretty much, but:
Each tile only need a texture coordinate to where relative in the texture where the tile is located.
Texture swapping is one of the biggest bottlenecks in graphics rendering, which is why you will want to try to do it as rarely as possible.

This is pretty much what I did in my openGL games:
Code: [Select]
//Usually I render everything to a framebuffer, but it is not really necessary.
...
for(int i = 0; i < screen_width/tile_width ; ++i){
    for(n = 0; n < screen_height/tile_height ; ++n){
        glBegin(GL_QUADS);
        glTexCoord2f(map.tiles[i,n].xOffset[0],map.tiles[i,n].yOffset[0]);
        glVertex3f(i*tile_width,n*tile_width,0);
        glTexCoord2f(map.tiles[i,n].xOffset[1],map.tiles[i,n].yOffset[1]);
        glVertex3f(i*tile_width+tile_width,n*tile_width,0);
        glTexCoord2f(map.tiles[i,n].xOffset[2],map.tiles[i,n].yOffset[2]);
        glVertex3f(i*tile_width+tile_width,n*tile_width+tile_height,0);
        glTexCoord2f(map.tiles[i,n].xOffset[3],map.tiles[i,n].yOffset[3]);
        glVertex3f(i*tile_width,n*tile_width+tile_height,0);
        glEnd();
    }
}

« Last Edit: November 25, 2011, 07:21:32 am by malloc »
Logged
Pages: 1 ... 21 22 [23] 24 25 ... 91