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 ... 9 10 [11] 12 13 ... 78

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

alway

  • Bay Watcher
  • 🏳️‍⚧️
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #150 on: June 12, 2010, 12:52:25 pm »

Yep, and that's what I will be putting in to correct it. AdjustWindowRect(rectangle of wanted size of display, window style, t/f of whether there are menus);
Now if only I could stop hitting f7 every time I want to save changes made on the forums...

Edit: Good lord, it seems AdjustWindowRect is borked somehow. Or at the very least doesn't like WS_OVERLAPPEDWINDOW style. Luckily, I managed to come across a solution to do it manually like so:
Code: [Select]
void SetClientSize(HWND handle, int x, int y)
{
RECT r;

GetClientRect(handle, &r);

x -= r.right;
y -= r.bottom;

GetWindowRect(handle, &r);

x += (r.right - r.left);
y += (r.bottom - r.top);

SetWindowPos(handle, NULL, 0, 0, x, y, SWP_NOMOVE);
}
« Last Edit: June 12, 2010, 01:34:14 pm by alway »
Logged

ILikePie

  • Bay Watcher
  • Call me Ron
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #151 on: June 13, 2010, 07:24:18 am »

I've come across the 'make' tool in many different places. I was wondering what exactly does this tool do? The GCC manual does a terrible job of explaining it. I'm guessing it takes some make file and compiles your program for you, but that's not something you can't do with a simple batch or bash script. Do you guys have a rather simple explanation as to what it does?
Logged

Normandy

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #152 on: June 13, 2010, 09:05:29 am »

It's basically a script designed specifically for compilation purposes; it automatically detects objects that need to be recompiled and will recompile them for you, without recompiling code that has not changed since the last compile. You can also put shell commands into it to automate certain things, such as say, compressing your program for distribution.

It also has some nifty features like setting variables from the command line, all of which make compiling easier.

I'm not particularly familiar with it, but that is my experience with it so far.
Logged

ILikePie

  • Bay Watcher
  • Call me Ron
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #153 on: June 13, 2010, 10:35:44 am »

Oh, thanks. Guess I'll be using that from now on then.

I've got another error now, this one really has me stumped. I have this for loop, and the program ignores everything after it. Any prints don't show up on the console, and the functions don't seem to run. The compiler does compile it, but when running the program any succeeding (succeeding the for loop) commands or functions don't run.

Pastebin link
Spoiler: ...and forum code (click to show/hide)

ignore wvlib.h and the Wave function, they are just some stuff I have; they don't seem to be causing the error. What am I doing wrong?

Apologies if this is an obvious mistake, I've just started using with C.

(I'm compiling with the minGW gcc binary if it matters.)
« Last Edit: June 13, 2010, 10:55:49 am by ILikePie »
Logged

alway

  • Bay Watcher
  • 🏳️‍⚧️
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #154 on: June 13, 2010, 11:11:49 am »

Have you tried printing the value of 't' during the loop? That could let you know whether it is stuck in the loop. If t stops being displayed at some point, you know it at least gets through the loop all right.
Logged

ILikePie

  • Bay Watcher
  • Call me Ron
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #155 on: June 13, 2010, 11:23:02 am »

Found the problem, my malloc was wrong. It should be:
buffer = (float*) malloc(Channels * (Bits / 8) * Samples * sizeof(float));

instead of:
buffer = (float*) malloc(Channels * (Bits / 8) * Samples);

Now to find out how to write pointer arrays to files.
« Last Edit: June 13, 2010, 11:24:35 am by ILikePie »
Logged

eerr

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #156 on: June 13, 2010, 04:55:57 pm »

one file or many files?
Logged

alway

  • Bay Watcher
  • 🏳️‍⚧️
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #157 on: June 13, 2010, 10:19:42 pm »

Gah... It seems my sprite code is not as bugfree as I had hoped. Or more specificly, the position code is acting up. The positions are scaling to weird values. From what I can figure out, it seems the position is related to:
1. The position itself; the odd scaling is directly proportional to the position values given
2. The size scalar being applied to the image; this too is directly proportional to the position values given. An image scaled to .1, .1 will have a position which is 1/10 that of the original size.
3. size/shape of the original image; can't figure out how this one relates to it, other than it does

Well that was easier than I thought... Turns out some of the code I had was unneccesary, and after removing that and compensating the position code for the scaling done to the texture things are now in order! (I hope)
« Last Edit: June 13, 2010, 10:32:24 pm by alway »
Logged

ILikePie

  • Bay Watcher
  • Call me Ron
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #158 on: June 14, 2010, 05:32:08 am »

one file or many files?
One file, I might just end up using
Code: [Select]
for (i = 0; i < 88199; i++)
        fwrite(&buffer[i], sizeof(buffer), 1, Wave);
Though it messes up my file and overwrites quite a bit of crap.
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 #159 on: June 14, 2010, 09:39:00 pm »

Here is an interesting challenge:

In C, or C++ without cheating by using existing libraries that do this, implement a string type that will automatically resize itself (in C, have it use functions, in C++, you may optionally add operator overloading) to hold whatever is added to it. It does not nessecarily have to be completely perfect, but being able to abstract the memory management is the key point.

Most importatly, no cheating. Using anything other than standard libraries(not literally just stdlib.h, but the overall small collection of libraries that are included with every compiler), or using the C++ string type(or other similar easy solutions), is not allowed.
Logged
Eh?
Eh!

eerr

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #160 on: June 15, 2010, 12:11:25 pm »

Make allows a very large number of files to be compiled and recompiled, in an organized fashion.
You don't really need it to do much, but if you need to compile multiple files, make will allow you to link them fairly easily.

one file or many files?
One file, I might just end up using
Code: [Select]
for (i = 0; i < 88199; i++)
        fwrite(&buffer[i], sizeof(buffer), 1, Wave);
Though it messes up my file and overwrites quite a bit of crap.
edit: ahhh, I should have caught myself. Need to pay more attention.
« Last Edit: June 16, 2010, 12:59:22 am by eerr »
Logged

Normandy

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #161 on: June 15, 2010, 01:07:21 pm »

eerr, That's an array of floats. You don't need a \0 at the end.

You see, your problem is that you're using fwrite wrong. You either do this:
fwrite(buffer, sizeof(float), 88199, Wave);
or this:
for (i = 0; i < 88199; ++i) fwrite(buffer + i, sizeof(float), 1, Wave);
(I'm not actually sure if it's buffer + i or buffer + i * sizeof(float), I haven't done C in a while.)

Do the former, since it's more idiomatic. Make sure you understand the functions you use: http://www.cplusplus.com/reference/clibrary/cstdio/fwrite/

Also, are you sure that .wav formats use floating point values? Just checking, I don't know myself personally.
Logged

timmeh

  • Bay Watcher
    • View Profile
    • My Portfolio
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #162 on: June 19, 2010, 03:38:41 pm »

Okay, I've been screwing around with C# for a little while now, made a few console apps as well as a simple forms based alarm program that launches a list of files when triggered.  I've gotten fairly comfortable with the event and object oriented design, and put together a simple state-based game engine that makes fairly heavy use of events, function delegates and interfaces; then put together a simple game that basically just consisted of trying to click on the right bubbles.  Not a particularly impressive feat, but it was good experience.  I want to use the state-based engine for a more interesting project, but I had a few questions first.

1.  With any major commercial game, the ability to change the screen resolution is a must.  However, I'd planned on using the positions of game objects directly to draw them, which would obviously cause problems if the screen changed size.  My current plan is just to draw to a buffer with the default size, and just stretch the buffer to fit if the screen is a different size.  Is there a better way to handle this?
2.  I've grown reasonably comfortable with SDL-NET for graphics, but the support/documentation is a bit lacking, the wiki is full of broken links, and it's making me wonder if I've inadvertently chosen an outdated library.  What would be the best was to handle 2D graphics in C#, in an object oriented, managed code way?

Any other input would be much appreciated as well, if I've missed asking a question I should have.
« Last Edit: June 19, 2010, 04:12:07 pm by timmeh »
Logged
On the Wall is a Masterfully engraved carving of Urist McHardcastle and Goblins. Urist McHardcastle is surrounded by the Goblins. The Golbins are stamping on Urist McHardcastle. Urist McHardcaste is laughing at the Goblins. The carving related to the prolonged and bloody death of Urist McHardcastle in the Fall of 1659, the Winter of 1659, and the Spring of 1660. On the engraving is an image of Cheese.

Blacken

  • Bay Watcher
  • Orange Polar Bear
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #163 on: June 19, 2010, 05:01:34 pm »

1. Make the viewport bigger. Use offsets and anchoring/docking to keep important control areas consistent, while increasing the size of the viewable features for your game (i.e., in a tile engine, show more tiles). You should be drawing with 2D quads or worldspace sprites anyway, so this should be easy.

2. I'd use OpenTK. I used to use SDL.NET for a lot of stuff, and its interface is pretty good, but it's clunky. OpenTK exposes OpenGL cleanly (i.e., better than Tao), but isn't really "object-oriented." For graphics stuff, where you want fairly direct control, even I have no problem with mostly discarding OO for this. You can build your own abstraction on top easily anyway.
« Last Edit: June 19, 2010, 05:03:58 pm by Blacken »
Logged
"There's vermin fish, which fisherdwarves catch, and animal fish, which catch fisherdwarves." - Flame11235

alway

  • Bay Watcher
  • 🏳️‍⚧️
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #164 on: June 19, 2010, 08:44:38 pm »

Just came across a weird bug in my direct input code. In both my book and a sample tutorial from the documentation in VC++ '08 it says to use the following when checking for a keypress.
Code: [Select]
bool DirectInput::keyDown(char key)
{
    return (mKeyboardState[key] & 0x80) !=0;
}
This then gives me a compiler warning (c4309, variable truncation) for large DIK values (for example, DIK_LEFT = 0xCD = 205), and for said values it will not give correct readings on whether the key is pressed. Reading the book a bit more about it said the 'key' variable is basicly just an index, so I used an unsigned int key rather than the char key, and it worked just fine.
So my questions are thus:
1. Why use char rather than an unsigned int for this?
2. What would cause this error?
3. And most importantly, will anything explode at a later date for using an unsigned int rather than char?
Logged
Pages: 1 ... 9 10 [11] 12 13 ... 78