Help me with C++ for my game


#323

Note: I wrote almost all of this last week, and I still didn’t upload your version to my Arduboy to confirm that everything works the same

You’ve explained the const thing very well.

I’m assuming one thing, a constant member functions cannot use a non constant member variable to calculate its stuff and return a value? Meaning, based on the the same arguments, a constant member function needs to do the exact same thing everytime?

In simpler terms, does it need to be a pure function?
Other question… is a member function considered pure if it uses non constant member variables to come up with its return value/what it does?

I think a reason people might not like having multiple files is because they don’t know how to name their files properly/decide which things to put where? (although… you still have that problem if you keep everything in one file - what to put where)

Or they’re a front-end web dev and they’re used to having long files?

I’m trying to implement slope tiles on my platformer (in the GameMaker version first, and I don’t it I’ll add it to the Arduboy version). It’s kind of breaking my brain trying to implement it. I don’t need help with that yet, I have the right resources, just still trying to implement it.

Stuff from today…

Hey @Pharap I just wanted to wish you merry Christmas, happy holidays, vacations, whatever it is you do at the end of December and whether you do anything at all, that you have a wonderful time doing it.

Thanks again for all the help from these past two months. A few people helped but you really did a ton. I was hesitant to buy the Arduboy when I did it but if I knew there was gonna be this “Pharap” feature I would have bought it instantly.

This part probably should have been a private message but I don’t know how to do that here, so it’ll have to be public. I’m moving this week so I’ll be back in a week or two

By the way I’ll make a UWP (Universal Windows Platform) version of my platformer, and it will be playable on Xbox One.


(Pharap) #324

Precisely, const-qualified functions can’t call non-const-qualified functions.

In fact, when you’re in a const-qualified function,
the this pointer is no longer T *, it’s const T *.

Not necessarily. It depends on why there are two different versions of the function.

That said, I can’t think of a good reason for there to be a const-qualified function and a non-const-qualified function apart from wanting to return a const-reference and a non-const-reference depending on whether the object is const.

So in 99% cases, yes they should be the same.

No, they don’t have to be ‘pure’.

Technically they are allowed to modify their arguments*,
and techically all (non-static) member functions have state (the implicit this**).

* I recommend against modifying arguments in 90% of cases because I think reassigning arguments makes the code harder to follow. (There are exceptions to this of course.)

** If a function doesn’t make use of any of the object’s state (i.e. it doesn’t use this, implicitly or explicitly) then it’s often worth considering whether it should be a static member function, or even a free function.

For the duration of a const-qualified functions, all member variables are effectively const (because this is const)*.

If a const-qualified function doesn’t modify any state or any of its arguments then arguably it could be classed as ‘pure’, but it depends whether you count the implicit this as an argument or not.

From a language point of view, it’s not an argument.
From an implementation point of view, it is usually implemented as a function argument.

But remember, even if you class the object’s state as an argument, you still have to get the exact same return value for the same set of arguments.

So ultimately it depends on your outlook.

* That’s actually a bit of a lie. There’s one case where they aren’t, but that case is a very dangerous edge case that I don’t like teaching people about because it’s one of the few parts of the non-C parts of C++ I consider to be an outright mistake and I can count on one hand the number of times I’ve seen it used in production code.

Usually you just name it after the most important thing that lives in it.

Most of the time I’m a one-class-per-file (or one-struct-per-file, or one-enum-class-per-file) kind of person, so I find that pretty easy.
(Where did I put GameplayState? In GameplayState.h of course.)

It gets a bit more difficult when I’ve got a file that has multiple free functions, but really I ought to put those in a namespace and name the file after the namespace.

If I have a lot of related classes I’ll make a file that includes all of them and then include that file.
(And often I’ll put them all inside a folder with the same name as that file, and then have an outer file that includes the file that includes all the other files.)

Do any front-end web developers actually read and write pure HTML anymore?

I got the impression most used HTML generators and provided page layouts in some kind of template language (like Mustache) or server-side language (like PHP).

(If I ever make a website I always write the HTML myself, but I almost never make websites.)

That’s something I’ve never actually implemented.

I like the look of this solution:

It needs floating point (or fixed point) calculations, but the equation itself looks quite simple and the diagram makes is relatively easy to understand.


The thought is much appreciated and the same to you.

(Truthfully I’m a bit of a grinch though.)

As far as I’m aware nobody says ‘happy holidays’ in Britain.
It’s an American (and aparently Canadian) thing.

It doesn’t seem that long.

Don’t say it too loudly or everyone will want one. :P

Fair enough.

I’m trying to take a break from programming for a week or two anyway,
but I’m not doing a very good job so far.

Go onto a person’s profile and press the ‘message’ button.

(Alternatively if you click on someone’s name on one of their comments you get a box with the same button, but doing it that way starts the message with a reference to the comment. You can delete the comment reference, but it takes longer.)

I haven’t bought any new consoles since I got my dekstop.
Steam has converted me. :P


Just to confuse you, I hope you enjoy Boxing Day :P.


#325

Sounds like this would make it easier to change a single file and do a pull request specifically for it?

I was gonna ask about how to handle related classes

I’m not that knowledgable in that field, but people use Bootstraps or their own setup with just what they need (Bootstrap or not). With CSS files being kept seperately, as long as you use the same structure everywhere, there’s only one file you need to change to modify the looks and layout of your website

I figured out how to make it work for a 45 degrees slope (not on the Arduboy), it’s not finished yet. I did it seperately to test it better and debug it faster, now what I’ve got is collision with the cursor - if the cursor is in the slope, the slope turns green. Here’s the GML (GameMaker Language) code:

var _result = 0;
var _color = c_red;
var _x0 = x;
var _y0 = y;
var _x1 = x + TILE_WIDTH-1;
var _y1 = y + TILE_HEIGHT-1;

var _in_tile_x = (_x0 <= mouse_x && mouse_x <= _x1);
var _in_tile_y = (_y0 <= mouse_y && mouse_y <= _y1);
var _in_tile = (_in_tile_x && _in_tile_y);

var _local_x = mouse_x - _x0;
var _local_y = mouse_y - _y0;
var _top = _y1 - _y0 - (_local_x - floor(_local_x / TILE_WIDTH) * TILE_WIDTH);
if (_local_y >= _top) && (_in_tile) {
	_color = c_green;
	_result = 1;
}

if keyboard_check_pressed(vk_enter) {
	show_message("localY: " + string(_local_y) + "\ntop: " + string(_top));
}

draw_self();
draw_set_color(_color);
draw_triangle(bbox_left-1, bbox_bottom, bbox_right, bbox_top-1, bbox_right, bbox_bottom, false);
draw_set_color(c_white);

draw_text(x-16, y-16, _local_x % 8);
draw_text(x-8, y-16, _top % 8);
draw_text(x, y-16, _result);
draw_text(x+8, y-16, _local_y);

draw_set_color(c_blue);
draw_rectangle(mouse_x, mouse_y, mouse_x, mouse_y, false);
draw_set_color(c_white);

Thanks!

They were productive months with few headaches. I get actual headaches if I focus hard on something and can’t figure it out after a while. You have literally saved me a ton of headaches

I know what Boxing Day is! You couldn’t confuse me. Your evil plan did not work.

Where I’m from we only say “Joyeux Noel”, but we do say “Joyeuses fêtes”, that last one is when you’re talking about Christmas + vacation time (no school/no work) and new year’s


(Pharap) #326

Good point, that’s also true.

If you had one massive file then pull requests would always affect just a small part of the same file.

I wouldn’t be surprised if even the CSS is machine generated these days.

The problem is then how to resolve that collision.

I get a bit stressed sometimes if I’m doing something difficult,
but the more I learn the less difficult things I encounter.

Usually the most difficult thing I end up doing is library design or making sense of certain people’s code.
Occaisionally I’ll pick a very difficult project.

Often if I can’t figure something out I usually just write a few notes and let it simmer for a few days while I’m doing other things and I’ll often have a sudden epiphany when I get back to it later.

I find I concentrate a lot better when it’s quiet, but I rarely get quiet.

Often the end result is worth the frustration though.

I’m sure we used to have an ornament that said that.
(As well as one that said ‘feliz navidad’.)

Do they celebrate it in Canada?

Bambozled again.

‘En vacances’. (Merci M. Poirot.)

In Britain we don’t say ‘vacation’, we say ‘holiday’.
(“I’m going on holiday.”, “Holiday time” “Enjoy your Holiday(s).”)

We say that even if people aren’t actually leaving the country or it’s just taking paid time off and there isn’t an actual holiday as such.


#327

I’ve been bamboozled by my Xbox One. I keep playing, it’s addictive (I’m in love with Halo 5’s “Forge”).
I’d like to finish what I started so I’ll be coming back this week. My Arduboy platformer was almost finished, it’d be great to finally release it this month.


(Pharap) #328

I decided to take a programming break from late December onwards so I could finally take some time to play some games (mainly Driftmoon on Steam).
I’ve already started breaking my break though.