Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 139 140 [141] 142 143 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 906584 times)

armeggedonCounselor

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2100 on: March 30, 2012, 01:27:40 pm »

Or do something else for a bit. That worked with an earlier problem I had.

Basically, I forgot that when calling a function, you don't have to include the variable type.

There was much facepalming when I figured out what I was doing wrong.
Logged
Quote from: Stargrasper
It's an incredibly useful technique that will crash the computer if you aren't careful with it.
That really describes any programming.

Stargrasper

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2101 on: April 02, 2012, 10:18:18 am »

Anyone else here been around long enough to have used HyperCard?  What'd you think of it?  What'd you think of HyperTalk?
Logged

DJ

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2102 on: April 02, 2012, 10:44:56 am »

What's the standard way to display a background image in a game with a scrolling background?

I'm using SDL, and when I was learning it from a tutorial it told me to only update the part of the background where a sprite was last frame, in order to speed things up. The tutorial was using a static background, though. But I need the camera to scroll over the background as the player moves (ie background is bigger than screen area). And there's my problem - there doesn't seem to be a way to directly display just a part of the background image.

The only thing I can think of is reblitting the whole screen area every time the camera moves even one pixel, which is to say virtually every frame. I'm guessing this would be awfully slow. And yes, I know that premature optimization is a bad thing, but I just got this ugly feeling that I'm missing something super obvious here.
Logged
Urist, President has immigrated to your fortress!
Urist, President mandates the Dwarven Bill of Rights.

Cue magma.
Ah, the Magma Carta...

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2103 on: April 02, 2012, 10:51:36 am »

You're going to have to reblit the entire background every time the camera moves any way, there's no way around that. This is because blitting is just copying an image from video memory to the screen. What you want to avoid is loading the image into memory every time you move the camera as that is costly. SDL has options for only blitting a part of an image though. IIRC BlitSurface enables you to specify a source rectangle which indicates what part of the surface to blit, but this may depend on the language you're using.
Logged

malloc

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2104 on: April 02, 2012, 11:00:17 am »

The only thing I can think of is reblitting the whole screen area every time the camera moves even one pixel, which is to say virtually every frame. I'm guessing this would be awfully slow. And yes, I know that premature optimization is a bad thing, but I just got this ugly feeling that I'm missing something super obvious here.

That is pretty much the way to go. Slow? It's not too bad actually.

If you run into performance problems, it has something to do with the fact that software blitting everything to screen is generally slow. But honestly I don't think you should worry to much about hitting a bottleneck. If you do, you will probably have to which to a hardware accelerated alternative like OpenGL or DirectX, they will not have any sort of performance hit from just blitting sprites, unless you are blitting like a million of them.
Logged

DJ

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2105 on: April 02, 2012, 11:04:33 am »

That's what I was planning to do. Good to know I'm not doing it in a horrendously suboptimal way. I haven't actually run into any performance problems yet, but then again I only got the sprite class done so far and just tested things with one instance of it.

And yeah, I load all the graphics into a bitmap library class at startup, sprites and backgrounds just reference these images.
Logged
Urist, President has immigrated to your fortress!
Urist, President mandates the Dwarven Bill of Rights.

Cue magma.
Ah, the Magma Carta...

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2106 on: April 02, 2012, 11:34:51 am »

The only thing I can think of is reblitting the whole screen area every time the camera moves even one pixel, which is to say virtually every frame. I'm guessing this would be awfully slow. And yes, I know that premature optimization is a bad thing, but I just got this ugly feeling that I'm missing something super obvious here.

That is pretty much the way to go. Slow? It's not too bad actually.

If you run into performance problems, it has something to do with the fact that software blitting everything to screen is generally slow. But honestly I don't think you should worry to much about hitting a bottleneck. If you do, you will probably have to which to a hardware accelerated alternative like OpenGL or DirectX, they will not have any sort of performance hit from just blitting sprites, unless you are blitting like a million of them.
SDL can do hardware acceleration on many setups if you're in full screen mode IIRC.
Logged

dizzyelk

  • Bay Watcher
  • Likes kittens for their delicious roasts.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2107 on: April 03, 2012, 03:22:12 pm »

Right, so I'm trying to learn me some SDL by writing a simple RL. I'm using SDL (duh) and C++. I know C++, not an expert, but good enough. However, I'm having this weird error in one of my functions. The code is the same as with my character movement code, which works perfectly, however in this particular function it reads my keypresses twice. I fixed it by putting a SDL_WaitEvent() call at the end, but this now means that you have to hit 'Q' twice to exit. Without the SDL_WaitEvent() it'll skip 2 tiles when you hit space fr the next tile, and move 2 squares in whatever direction I press. I can't figure out what the problem is, because, as I understand it, an event is only created when a key is pressed (and, indeed, that is what happens with my movement code). Can anyone shed some light on this for me? Code after the spoiler.

Spoiler (click to show/hide)
Logged
Dwarf Fortress - Bringing out the evil in people since 2006.
Somehow, that fills me more with dread than anticipation.  It's like being told that someone's exhuming your favorite grandparent and they're going to try to make her into a cyborg stripper.

Stargrasper

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2108 on: April 03, 2012, 03:43:32 pm »

Sounds like it's just reading so fast, it's reading keystrokes twice.  Try setting SDL_EnableKeyRepeat(int delay, int interval).  The api says setting delay to zero (0) will disable repeat entirely.

EDIT: It might also help to look for key release instead of key press.
« Last Edit: April 03, 2012, 03:45:31 pm by Stargrasper »
Logged

Nadaka

  • Bay Watcher
    • View Profile
    • http://www.nadaka.us
Re: if self.isCoder(): post() #Programming Thread
« Reply #2109 on: April 03, 2012, 04:22:19 pm »

I caught myself saying a moment ago while working on my work project: "This is such a hacked solution. I almost hope it doesn't work."

jasper reports are not your friend.
Logged
Take me out to the black, tell them I ain't comin' back...
I don't care cause I'm still free, you can't take the sky from me...

I turned myself into a monster, to fight against the monsters of the world.

dizzyelk

  • Bay Watcher
  • Likes kittens for their delicious roasts.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2110 on: April 03, 2012, 04:45:57 pm »

Sounds like it's just reading so fast, it's reading keystrokes twice.  Try setting SDL_EnableKeyRepeat(int delay, int interval).  The api says setting delay to zero (0) will disable repeat entirely.

EDIT: It might also help to look for key release instead of key press.
I tried looking for the key release before, and also tried adding a SDL_Wait() (or whatever the syntax actually is) but they didn't help, the first acted the same, the second just made me wait between the 2 motions... looking up the SDL_EnableKeyRepeat() now...

EDIT: Nope, didn't help, its still doing it.
« Last Edit: April 03, 2012, 04:49:12 pm by dizzyelk »
Logged
Dwarf Fortress - Bringing out the evil in people since 2006.
Somehow, that fills me more with dread than anticipation.  It's like being told that someone's exhuming your favorite grandparent and they're going to try to make her into a cyborg stripper.

RedWarrior0

  • Bay Watcher
  • she/her
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2111 on: April 05, 2012, 10:08:12 pm »

Is anyone here particularly talented in brainfuck? It looks interesting, but the name describes it very well.
Logged

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2112 on: April 05, 2012, 10:11:44 pm »

Is anyone here particularly talented in brainfuck? It looks interesting, but the name describes it very well.

I know how the language works, but I haven't spent a whole lot of time programming in it. The most I've done is writing a C++ interpreter.

Good reference: http://esolangs.org/wiki/Brainfuck

Aqizzar

  • Bay Watcher
  • There is no 'U'.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2113 on: April 05, 2012, 10:15:40 pm »

I had the mother of all facepalms today, debugging code with my boss.  I couldn't figure out why a page-to-print was producing growing margins with every page.  I looked that code over backwards and forwards, and then he hits a search one time, and I see the issue.

Code: [Select]
point.X = margin += colX_1;
                ^^^^ wut

Why the fuck does that even compile?  You can't set two variables in one statement, that's impossible.
Logged
And here is where my beef pops up like a looming awkward boner.
Please amplify your relaxed states.
Quote from: PTTG??
The ancients built these quote pyramids to forever store vast quantities of rage.

Nadaka

  • Bay Watcher
    • View Profile
    • http://www.nadaka.us
Re: if self.isCoder(): post() #Programming Thread
« Reply #2114 on: April 05, 2012, 10:24:04 pm »

I had the mother of all facepalms today, debugging code with my boss.  I couldn't figure out why a page-to-print was producing growing margins with every page.  I looked that code over backwards and forwards, and then he hits a search one time, and I see the issue.

Code: [Select]
point.X = margin += colX_1;
                ^^^^ wut

Why the fuck does that even compile?  You can't set two variables in one statement, that's impossible.

Depending on the language you can. the assignment operator is basically just another function, one that can return a value. In c, c++ and java it returns the value being set so you can do things like this:

a = b = c = d = 0;

instead of:

a = 0;
b = 0;
c = 0;
d = 0;
Logged
Take me out to the black, tell them I ain't comin' back...
I don't care cause I'm still free, you can't take the sky from me...

I turned myself into a monster, to fight against the monsters of the world.
Pages: 1 ... 139 140 [141] 142 143 ... 796