Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Poll

What programming topic would you want the next challenge to be about?  (It might be a good opportunity to focus on a subject you're not familiar with or to reinforce knowledge on one that you already know)

Control Flow
- 2 (2.2%)
Arrays, Strings, Pointers, and References
- 8 (9%)
Functions
- 4 (4.5%)
Basic object-oriented programming
- 30 (33.7%)
A bit more advanced OOP (Composition, Operator overloading, Inheritance, Virtual Functions)
- 18 (20.2%)
Templates
- 8 (9%)
Other (Explain)
- 4 (4.5%)
Working with files?  (Streams)
- 15 (16.9%)

Total Members Voted: 89


Pages: 1 ... 73 74 [75] 76 77 78

Author Topic: Programming Challenges & Resources (#bay12prog) Initiative  (Read 97531 times)

lordnincompoop

  • Bay Watcher
  • Allusionist
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #1110 on: April 14, 2011, 05:10:16 pm »

I think so, I mean what does it have in there? Should just be a bunch of .c and .h files.

The source, a bunch of readmes, python files, sample exes, .lib files, docs, makefiles, and more.
Logged

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #1111 on: April 14, 2011, 05:42:50 pm »

.DLL's as well if you're on windows or .SUO if you're on linux (that's the right extension, no?). That's also what most wrappers need (if they use the C code you'll need a C compiler in addition to the compiler/interpreter of your language)
Logged

Biag

  • Bay Watcher
  • Huzzah!
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #1112 on: April 14, 2011, 05:50:32 pm »

Ok, well hi to all of you.

-snip-

Thanks all. If you can help, I'd be epichappy.

Do you mean a game engine, or a graphics engine? For graphics, I'd recommend C++ using OpenGL. It's industry standard! :D
Logged

lordnincompoop

  • Bay Watcher
  • Allusionist
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #1113 on: April 14, 2011, 06:27:58 pm »

Ok, well hi to all of you.

-snip-

Thanks all. If you can help, I'd be epichappy.

Do you mean a game engine, or a graphics engine? For graphics, I'd recommend C++ using OpenGL. It's industry standard! :D

I highly advise you against coding a game with just C++ and OpenGL. You will die, especially when alone and with no useful programming experience. There's Allegro and a bunch of other libraries, so go look them up.

Java is perfectly fine, don't see why it would be impossible to code a game in that language. Both Wurm and Minecraft are made (successfully, I might add) in Java, and I doubt you'll make anything much more demanding than that. There's the LWJGL and a bunch of stuff for Java too.

The Unreal Development Kit is completely free for non-commercial use, no catches at all. For commercial use, you'll have to pay them a cut for the first several thousand copies your game sells, I think.
Logged

qwertyuiopas

  • Bay Watcher
  • Photoshop is for elves who cannot use MSPaint.
    • View Profile
    • uristqwerty.ca, my current (barren) site.
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #1114 on: April 14, 2011, 08:30:14 pm »

Spoiler: Code is in C (click to show/hide)
In mkcanvas, how do turn c.data into a two dimensional array. I've tried some silly mallocs and the above but it doesn't work. It segfaults when trying to access c.data[0][0].red.

Never mind this, the guys at ##c tell me it isn't really possible.

The segfault is because both the canvas and the RGB array are allocated on the stack, so disappear as soon as the function returns. Any use of them after they go out of scope will have unexpected results, and is most certainly a bug.

To make a two dimensional array? Make a one dimensional array of pointers to one dimensional arrays.

In C, the easiest way to get good results would be a function that constructs and allocates the structure, or returns NULL if it fails.

(Warning: Barely tested, and only theoretically bug-free)
(Almost certainly needs to be modified to use the same brace style and indentation as the rest of the code, and the iterator declarations might need to be moved too. If they do, then keep the row = 0 and col = 0 in the for loops, otherwise it won't work (specifically, only the first row and last column would be initialized if the col loop didn't have col = 0, and having the row = 0 is just for consistency))

Code: [Select]
canvas* newCanvas(int width, int height, RGB initialColour)
{
    if(width <= 0 || height <= 0)
      return NULL;

    canvas *c = malloc(sizeof(canvas));
    if(c == NULL)
      return NULL;

    c->width = width;
    c->height = height;
    c->data = malloc(sizeof(RGB*) * height);
    if(c->data == NULL)
    {
        free(c);
        return NULL;
    }

    for(int row = 0; row < height; row++)
    {
        c->data[row] = malloc(sizeof(RGB) * width);
        if(c->data[row] == NULL)
        {
            while(row--)
              free(c->data[row]);

            free(c->data);
            free(c);
            return NULL;
        }

        for(int col = 0; col < width; col++)
          c->data[row][col] = initialColour;
    }

    return c;
}


Edit: A one-dimensional array where you manually convert [x][y] into [(y*width) + x] would also work.
« Last Edit: April 14, 2011, 08:33:05 pm by qwertyuiopas »
Logged
Eh?
Eh!

Shades

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #1115 on: April 15, 2011, 02:36:11 am »

and it's 3D and... well. I've got no engines or anything which are totally free source which might work.

Try something like Ogre3D which is free but just a rendering engine or maybe Torque 3D which is $99 for a license.
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

EmperorJon

  • Bay Watcher
  • Still waiting...
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #1116 on: April 15, 2011, 11:40:01 am »

Thanks for the help, will take a look around. Maybe try Java, I don't know, it's just I need a graphics engine or preferably a game engine to get me started. I'm going to be making a huge textured world then applying a grid over it for certain grid snap functions and so each tile can have values and such without it looking too 'blocky' (Minecraft. :P)
Logged
I think it's the way towns develop now. In the beginning, people move into a town. Then they start producing tables, which results in more and more tables. Soon tables represent a significant portion of the population, they start lobbying for new laws and regulations, putting people to greater and greater disadvantage...
Link for full quote. 'tis mighty funny.

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #1117 on: April 15, 2011, 12:15:28 pm »

Java doesn't have any 3D capabilities by itself though, so I doubt it's going to help you in that regard.
Logged

EmperorJon

  • Bay Watcher
  • Still waiting...
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #1118 on: April 15, 2011, 12:33:52 pm »

Yeah, I was looking at OpenGL /or part of LWJGL.
Logged
I think it's the way towns develop now. In the beginning, people move into a town. Then they start producing tables, which results in more and more tables. Soon tables represent a significant portion of the population, they start lobbying for new laws and regulations, putting people to greater and greater disadvantage...
Link for full quote. 'tis mighty funny.

ILikePie

  • Bay Watcher
  • Call me Ron
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #1119 on: April 16, 2011, 04:58:46 am »

I remember doing this correctly once, and I think this is the syntax.
When I try to write a whole struct to a file, I get two extra bytes right after the first entry:
Code: [Select]
void write_bitmap (canvas c, FILE *f)
{
     BITMAPINFOHEADER h = mkheader(c);
     fwrite(&h, sizeof(BITMAPINFOHEADER), 1, f);
}

...

$ hexdump -cV file
00000000  42 4d 00 00 66 00 00 00  00 00 00 00 36 00 00 00  |BM..f.......6...|
00000010  28 00 00 00 04 00 00 00  04 00 00 00 01 00 18 00  |(...............|
00000020  00 00 00 00 30 00 00 00  00 02 00 00 00 02 00 00  |....0...........|
00000030  00 00 00 00 00 00 00 00                           |........|
00000038
Those two 00s after 42 4d aren't supposed to be there, and when writing individual parts of the struct, they aren't:
Code: [Select]
void write_bitmap (canvas c, FILE *f)
{
       BITMAPINFOHEADER h = mkheader(c);
       fwrite(&h.magic, sizeof(uint16_t), 1, f);
       fwrite(&h.size,  sizeof(uint32_t), 1, f);
}

...

$ hexdump -vC file
00000000  42 4d 66 00 00 00                                 |BMf...|
00000006

Have I missed anything?

Spoiler: the struct (click to show/hide)
« Last Edit: April 16, 2011, 05:02:22 am by ILikePie »
Logged

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #1120 on: April 16, 2011, 05:35:42 am »

What does it say when you try to access the memory directly?
C might be "padding" your values in your struct, they're not guaranteed to be consecutive. Especially since you use multiple types in one struct.

http://en.wikipedia.org/wiki/Data_structure_alignment

On second thought, I'm pretty sure it's doing that, since you're probably working on a 32-bit system.
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))

EmperorJon

  • Bay Watcher
  • Still waiting...
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #1121 on: April 16, 2011, 07:14:10 am »

Hmm, I'm considering using C++ now... Harder to learn, but more efficient, may be more useful, and MSVisualC++ will be helpful (and free... ;) )...

OpenGL compat. with C++ programs anyone? I think it is...
Logged
I think it's the way towns develop now. In the beginning, people move into a town. Then they start producing tables, which results in more and more tables. Soon tables represent a significant portion of the population, they start lobbying for new laws and regulations, putting people to greater and greater disadvantage...
Link for full quote. 'tis mighty funny.

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #1122 on: April 16, 2011, 08:44:52 am »

Sure it is, but the again, plain C code is C++ compatible, so most C libraries will work under C++
Logged

ILikePie

  • Bay Watcher
  • Call me Ron
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #1123 on: April 16, 2011, 09:40:06 am »

What does it say when you try to access the memory directly?
C might be "padding" your values in your struct, they're not guaranteed to be consecutive. Especially since you use multiple types in one struct.
So you're saying the only way to prevent this "padding," is to write the members one by one?
e, Wikipedia says I can use a #pragma directive to mess with padding. Seems to work fine, but it's hardly portable (The gcc manual says it comes from MSs compiler or something).
« Last Edit: April 16, 2011, 09:49:08 am by ILikePie »
Logged

TolyK

  • Bay Watcher
  • Nowan Ilfideme
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #1124 on: April 16, 2011, 04:00:12 pm »

Sure it is, but the again, plain C code is C++ compatible, so most C libraries will work under C++
not exactly. C++ has stricter type checking, so not 100% copy-and-pase (from personal experience  :-X)
Logged
My Mafia Stats
just do whatevery tolyK and blame it as a bastard mod
Shakerag: Who are you personally suspicious of?
At this point?  TolyK.
Pages: 1 ... 73 74 [75] 76 77 78