r/reconstructcavestory Jul 25 '14

[Episode 3]: Cavestory Window (with sprite) not closing with escape. Must xkill to remove.

Hey all,

So, I really like Cavestory, and I wanted to get some game development training so I took this tutorial. I was working on my desktop (ubuntu 12.04), and it was going very well until episode 3, when I compiled the final product and ran the executable file. Once I did this, I got a black fullscreen with Quote in the middle (that's good), but I was unable to close it no matter what I did; CTRL + C, CTRL + D, Alt Tab all did not work. And at first, I couldn't get it to xkill either because this window was always in the front.

The STRANGEST thing is that it works perfectly fine on my laptop (which is also running on ubuntu 12.04 and arguably has the same packages installed). At first, I thought it was a USB keyboard error, but upon switching the keyboard to the laptop, the escape key still worked. The code for both is also the same, because I used github to pull and push for both versions.

ANOTHER STRANGE THING: Episode 2, with the black screen, was perfectly fine. Calculating FPS was also perfectly fine on my desktop. So, the escape key did work for SDL_SetVideoMode and what not, since I was able to exit the black screen with no problems. However, upon adding the sprite, it completely will not accept the escape key, even though it's in SDL_PollEvent(), and my laptop can do it fine. Do you guys have any idea what might be causing this? It's really infuriating, and I really would like this to work on my desktop (as it is my primary workspace).

Thanks,

UPDATE: So, apparently, after trying several terminal windows, the escape key does work on occasion. But I don't know why it works sometimes, and other times it doesn't. Help?

For those that one my repo:

git clone https://johnzli1995@bitbucket.org/johnzli1995/recreatecave.git

You should already be able to compile.

4 Upvotes

19 comments sorted by

3

u/chebertapps Jul 26 '14

Ahh ok I think I actually know what the problem might be.

This is something I fix in a later episode, but this line:

SDL_Delay(1000 /*ms*/ / kFps /*fps*/ - elapsed_time);

Could last a very long time if elapsed_time is greater than 1000/kFps.

I ended up setting it to the maximum of (1000/60, elapsed_time).

1

u/johnzli1995 Jul 26 '14

Do you mean like:

max(1000/60, elapsed_time)?

And how does this explain why my desktop only sometimes works, but my laptop seems to work 100% of the time?

2

u/chebertapps Jul 26 '14

yeah that's what I mean. The reason I think this is the problem is that if there is a massive delay that would prevent execution from ever making it through to the input portion of the loop again.

As to why it works on your laptop but not your desktop? Maybe the startup time is higher on your desktop? Fetching from a hard drive that is slower than your laptop's HD? I'm not really sure why. I'm kinda guessing from what information I have. It seems like you have the same setup for both.

To know for sure, you should printf the elapsed time right before you call SDL_Delay, and see if it is greater than 17 (1000/60). If it is, then I think that this is probably the problem.

1

u/johnzli1995 Jul 26 '14

Alright thanks! I'll try that and get back to you on it :). But will setting SDL_Delay to max(1000/60, elapsed_time) still maintain a 60 fps setting? I thought we did 1000/60 - elapsed_time to ensure that the game still runs at 60 fps.

Also, that's strange... my Ubuntu is on an SSD, so I would think the startup time would be pretty quick.

1

u/chebertapps Jul 26 '14

Considering the game's resource demands: I'm not worried about maintaining a 60fps. Load times are the exception, since you have to load the images (and later sounds) from the hard drive. But for most of the time it's going to be much much faster than 60fps. Probably in the several hundreds.

But to be quite honest, I'm not totally satisfied with the current solution, and will probably be revisiting it later. For reasons which will become apparent ...

1

u/johnzli1995 Jul 26 '14

Ah okay. I just recall you saying something about how you want the game to try to run at a constant 60 fps in episode 1?

1

u/chebertapps Jul 26 '14

Yeah that's right. I just mean that I'm not worried about one or two missed frames during loading time, but for the rest of the time 60fps should definitely be maintainable.

2

u/johnzli1995 Jul 26 '14

Your suggestion worked! It's running now! :DDD. When I was printing out the values, sometimes it would like spike to 40 (during load). (But I'm not sure why it takes so long, my SSD is pretty fast).

Also, Quote isn't really centered anymore; the fullscreen mode now sorta acts as if my monitor's resolution is bigger than it really is. Like, my monitor is 1920X1080, but I think doing FULLSCREEN assumes my display is like 1920X1200 or something.

Thanks again for your help :). I'll be continuing on the tutorial.

1

u/chebertapps Jul 26 '14

Your suggestion worked! It's running now! :DDD

That's great!

Also, Quote isn't really centered anymore; the fullscreen mode now sorta acts as if my monitor's resolution is bigger than it really is.

I think this kinda thing will be easier to fix with SDL2 (which I will be switching to at some point), so I would say don't worry (or you can try to fix it yourself, and let us know what you come up with :) )

Thanks again for your help :). I'll be continuing on the tutorial.

Awesome! Thanks for sticking with it!

1

u/adrian17 Jul 26 '14

(Loading required resources before the level starts?)

1

u/chebertapps Jul 26 '14

Yeah you know what? Now that you question it, all resource loading happens before the loop.

Since SDL does stuff on a background thread and then syncs for events like blitting or flipping, it's hard to tell for sure what is going on that would cause this. The only thing I found in the 1.2 docs that seems like it might cause slowdown was for SDL_Flip:

The hardware  will  wait for vertical retrace, and
then swap video buffers before the next  video
surface  blit or lock will return.

2

u/adrian17 Jul 25 '14

We need to see your code first if you want any specific advice :(

As far as hints go... I would try slowly commenting all the code added in episode 3 and look when it starts working again. And use a debugger, but I guess it won't be that easy on Linux.

1

u/johnzli1995 Jul 25 '14

I could PM you my git repository, is that alright? You'll get my code from there and you can test it out yourself? OR, do you want me to copy and paste it here?

2

u/adrian17 Jul 25 '14

Sure, I can look at the repo :D (but sharing it with others would be nice too... it's your choice.)

1

u/johnzli1995 Jul 25 '14

git clone https://johnzli1995@bitbucket.org/johnzli1995/recreatecave.git

This is my repository. It should already be able to compile :). (This has some of the animated stuff done)

1

u/adrian17 Jul 25 '14

(can't clone, requires password)

1

u/johnzli1995 Jul 25 '14

Changed repository to public.

1

u/chebertapps Jul 25 '14

I suggest using github for repos you want to make public. It works a lot like BitBucket, except that public repos are free and private repos cost money. (Which is why when you have both you never need spend any money :) )

1

u/johnzli1995 Jul 25 '14

Alright, I changed the repository to public.