« first day (346 days earlier)      last day (2490 days later) » 

7:11 AM
I have collision in my game. Its one function that checks all the objects that have Collider and checks if they overlap. Anyway, I think the system of how it works is not really important for my question. The question is, can I call that function (for collision) in function calculate_next_physical_frame? (here is example of what I mean): ideone.com/FEyupX I am doing it, and everything seems to be smooth. But I am asking this to make sure it is a good way to do it.
 
Ven
7:57 AM
how else would you do it?
 
8:21 AM
@Ven That is what I am asking. Is there any better way or is this way ok?
 
Ven
8:41 AM
@MuhamedCicak you need to calculate physics every time something moves
 
@Ven It is really hard to keep track of every object. As I understood, by your logic I would need to check if any object moved, and then calculate physics? What is problem with the current logic? In the ideone link I pasted there is function in that code called calculate_next_physical_frame. I call collision checking in that function. Is that bad? If so, why is it?
 
Ven
@MuhamedCicak I don't think there's anything wrong with it
 
@Ven So, why did you say that I would need to check physics when something moves? Maybe I understood wrongly.
 
Ven
I just meant it generally, not as something you need to improve.
 
@Ven Oh okay, so I guess my current version of collision checking is not that bad :) ?
 
Ven
8:58 AM
'think so
 
 
2 hours later…
10:46 AM
Hi, another question here. I know it is trivial to make function like this: int foo(int x, int y, int z) which checks whether x is between y and z. But I would like to use std libraries function if it has one (that does this). So is there any func like this?
 
nwp
@MuhamedCicak "checks whether" sounds like it should have a return type of bool and not int.
you can check here but I don't think there is that specific function
 
int isInScope(int num, int start, int end) {
return (num >= start && num <= end)s;
}
I did this, i did not find specific function either
I usually do not use bool
I use int for it. 0 for false and 1 for true
 
nwp
why?
 
I do not know. I guess its habit from C.
But C had bool as well. Right?
When I learned C from K&R he never used bool so I did not either
 
nwp
@MuhamedCicak no
 
10:57 AM
Oh so it has no. Thats why he did not use bool :)
 
nwp
@MuhamedCicak you should either stick with C or try to shake off C habits when using C++
 
@nwp There is theory that people say learning C is disadvantage for learning C++ (i do not know if you think so) but I do not think like that. Now I am learning C++ and I will definetely shake off C habits. But it helped me a lot in learning C++ (because I know C) and it still does.
 
nwp
Apparently they added it in C99 with a header, so one could argue that C does have bool.
 
@nwp Yeah I remembered it from DOOM's source code. In Carmack's code there was bool. And it is all in C.
 
nwp
I think most C-people just do #define bool char #define true 1 #define false 0.
 
11:01 AM
So if I am going to use bool, shall I change this: bool isInScope(int num, int start, int end) {
return (num >= start && num <= end);
} to this: bool isInScope(int num, int start, int end) {
if (num >= start && num <= end) {
return true;
}
return false;
}
Sorry i do not know how to format code in chat
comments
I hope you can see the code properly
 
nwp
When you paste multiple lines you can click the fixed font button. Or press ctrl+K.
@MuhamedCicak no, the first version is much shorter and clearer. I would even remove the parenthesis.
 
@nwp Yeah, I always put them (parathesis) for safety (I do not know order exactly). So yeah, I will remove them.
 
nwp
It might make sense to do return (num >= start) && (num <= end); if you want to be explicit about operator precedences.
 
Yeah, I guess I will do like that.
 
nwp
You could do return std::clamp(num, start, end) == num; but I think it is worse.
 
Ven
11:11 AM
lol
needs more TMP
 
@nwp I've just read it (the clamp function). Why do you think its worse to use it?
 
nwp
@MuhamedCicak Because it is more complicated.
not clamp in general, but to implement isInScope
 
Yeah. It is actually.
@nwp Oh by the way, did you make any engines or games in C++? You helped me yesterday a lot about my game.
 
nwp
I did mess around making an ECS. It is not actually good though.
I need to find a good way to remove components from entities. I just don't know how to do it without the overhead that I currently have.
 
Im actually reading what ECS is. Have a short desc :D?
Oh, actually I am making that right now.
I have components which can be attached to objects
 
nwp
11:24 AM
You have entities that have an ID and you can put components into them. You have components that have some data such as struct Speed{int speed;}; without logic. And then you have systems that loop over all entities that have certain components, for example a position, direction and speed and then modify them. It is common to structure games that way.
It is quite tricky to figure out where to put the components that you attach to entities so that it is not overly restrictive and fast.
 
Yeah, that looks familiar. I have been doing games in Unity earlier (not proffesional, all this is learning-purpose) and saw how they have these components and thought that I can make similar system from scratch in c++. I have components like collider, texture etc.
 
it's easy to make a ECS but very hard to make it a usable ECS
 
@nwp So you said you were doing ECS. Did you finish it? By "finish" I mean as much as you wanted.
@ratchetfreak Almost everything is like that :D Not just ECS
 
nwp
@MuhamedCicak I put it on hold until C++17 so I could express things without the ridiculous template code that I wrote. I think I'm mostly interested in trying all the new cool features and not really in making a game.
unfortunately even though C++17 is out my tools are still too far behind to effectively use it
 
I'm trying to "cout" a .png file from my program, however the png has a null terminator "\0" and my cout stops there, how can I output the whole bytestream?
 
11:33 AM
@nwp Lol. I firstly should learn C++11
 
nwp
@SergioBasurco use one of the ways to pass the size instead of pretending that the .png is a C string
 
@SergioBasurco don't use the streams for binary data...
You are likely also having a problem with '\n' in the data
 
nwp
@SergioBasurco Why does it matter? It is garbage data either way.
 
What should I use instead? What I want to achieve is:
myprog.exe > file.png
 
nwp
@SergioBasurco does that work with cat?
 
11:38 AM
@nwp Not sure what you mean. My program is creating the png file, so there's nothing for cat to open, besides I'm on windows
 
cout.write(data.data(), data.size());
 
@nwp I am learning C++11 from BS's book "The C++ Programming Language 4th Edition". But I am really in love with making games. So I accept that as practice, but the problem is, I do too much practice and leave theory behind (the book). Even though I can learn C++ theory by making games, I guess it is always better to learn theory from book.
 
@ratchetfreak What should I use instead of streams? Does it apply for outputing as myprog.exe > file.png?
 
nwp
@SergioBasurco I think the equivalent is echo, so you could try echo some.png > some2.png and see if some2.png survives. I fear that cmd.exe opens stuff in text mode and breaks non-printable characters and makes the whole thing impossible.
 
@nwp the equivalent of cat in windows is type
 
nwp
11:47 AM
right, echo would just print "some.png"
 
Alright, in any case I'm not opening any png, i'm creating it from my application. cout.write seems to work but writes some extra bytes and the file cannot be opened. Thanks though!
 
@SergioBasurco that'll be each "\n" being converted to "\r\n"
 
@ratchetfreak Yup that's it, can it be prevented?
 
5
Q: Is there way to set stdout to binary mode?

CppMonsterIs there way to set stdout to binary mode? In which mode is stdout without any operations, from my debugging issues I assume that it is in text mode, is it true? I tried function: freopen(NULL,"wb",stdout) but my program is crashes when I'm doing it.

 
@ratchetfreak cheers mate, that did it
 
12:24 PM
If I use if statement like this: if((case1 || case2) && (case3 || case4)) { do something}
what would this mean?
in which cases will this enter
in do something
 
12:37 PM
@MuhamedCicak Assume, that `a = (case1 || case2)`, and `b = (case3 || case4)`.
Then we have `if(a && b) { do something}`.
... Markdown formatting for codeblocks is not working here?
 
nwp
12:49 PM
It does, you just used ` instead of '
 
nwp
Interesting. Might be worth reporting on meta unless it already has.
 
 
3 hours later…
3:52 PM
@nwp Markdown is disabled on multiline messages /cc @Toreno96
chat being shitty and like
 
 
1 hour later…
5:21 PM
how can i see if a char * contains ".txt" in the end, if it isnt '/0' terminated?
 
@jeyejow do you know the length?
 
user1804599
@jeyejow Why are you using char* is this 1970
 
user1804599
Also you need either a terminator or a length.
 
user1804599
Otherwise you can't find the end.
 
@Mgetz no, it's a argv[x]
 
user1804599
5:24 PM
Strings in argv are all NUL-terminated.
 
@jeyejow as in from the main function?
those are null terminated
 
@Mgetz they are? so i can use strlen ?
 
@jeyejow you can, but you can also just strstr
 
user1804599
No, use std::string.
 
or better yet use std::string
or std::string_view
 
user1804599
5:27 PM
Put std::vector<std::string> argv_vector(argv, argv + argc); at the top of main.
 
user1804599
Then use that instead of argc and argv.
 
i just need to get the lenght of the char *, its because i need to make a for cycle to see if it ends in ".txt"
 
17 messages moved from Lounge<C++>
 
@rightfold, i dont know how to work with vectors
 
user1804599
And then you have an std::string and you can use boost::algorithm::ends_with.
 
5:28 PM
about time to learn then :)
 
user784668
@rightfold That's just boost::ends_with.
 
@rightfold but i dont know how to work with vectors :p
 
user784668
@jeyejow then learn
 
@Mgetz ill try that then! thanks
 
5:29 PM
4 messages moved from Lounge<C++>
 
@milleniumbug i self taught me c++ so you can guess i dont know much ahaha, ill search for vectors and tr to learn them
 
@jeyejow Self-taught does not imply ignorance. I taught myself C++ too, but I think I know quite a bit...
 
@jeyejow I would highly suggest you read bjarne's book on C++, you'll thank yourself later
 
@JerryCoffin :p
@Mgetz ill check it out! appreciated!
 
 
2 hours later…
7:16 PM
hey guys, one question, if i have a char *, (lets call it A), and A contains some chars inside, how can i add more chars to the current ones? For example if A was "abcde" and i wanted to add "fgh" to it, so the result would be "abcdefgh", how can i do it?
 
this would be trivial with std::string
 
i need it to stay as char *
 
no you don't
a.c_str() gets you a null-terminated string you can pass to function that expects a const char*
 
ohhhh
ad what goes inside it?
the a.c_str()
a is a string and i put inside it the variable i have has char * ?
 
void garbage_function(const char*);

int main()
{
    std::string a = "abcde";
    a += "fgh";
    garbage_function(a.c_str());
}
 
7:21 PM
ok, i will try that, thanks!
@milleniumbug one more question, if i have a string like this "abcedfg\hijk", how can i cut it from the end till it reaches the '\' caracterand i end up with something like this "abcdefg\" ? I was thinking converting the string to an array and a for cicle to go thru the array and you can imagine the rest, but is there a better solution for my problem?
maybe there is alreaddy something that does what i want
 
nwp
@jeyejow You can look at what std::string has to offer. Particularly resize seems a good fit for the task.
 
@nwp thanks! ill check it out
 
basically .find together with .substr
 
@milleniumbug the problem is, what if i hav multiple '\' in my string?
and i want the last one only
for example
"abc\def\ghi\jk" <- original string
"abc\def\ghi\" <- new string
 
ok, .find does only work in forward, but there's .find_last_of
that one only works for single characters, which is fine with you since you're operating on \
 
7:36 PM
@milleniumbug nice, the example i found of .find_last_of suits perfectly, thanks again ahah!
 
nwp
there is also rfind
 
hah, silly names
no wonder I've missed it
 
@nwp that would work if i knew the values, but they are user input
all i know it that its a path\filename.somthing
and i wanted to know ho to get the path without the file so i could check the existence of the path
 
and this is relevant how
 
its relenvat because with what @nwp sed, i couldnt apply it to my problem
 
nwp
7:40 PM
str.rfind('\');
returns the position of the last '\' in str
 
oh
 
it doesn't matter whether your variable has a literal assigned or it's read from the console
it's a variable
 
LOL i was thinking about using the letter of the file name inset of the '\', fail
i gtg, brb after dinner
 
 
1 hour later…
9:00 PM
Gud evening
I'm going to ask a Q about impilicit conversion in constructors.
 
hello @iksemyonov :D
 
9:42 PM
i have a question, i need to add an include to my project, but it says it cant find the library
so i downloaded it, but i dont know what folder to drag it
im using Visual Studio 2017, and i havent found anny information about were it is
does anny one know were is the folder i need to drop my header file?
i thinki found how to do it
 
@iksemyonov don't ask to ask, just ask
@jeyejow follow the instructions given to you by the lib's author
 
@milleniumbug stackoverflow.com/questions/6769760/… this helpedme, i mean at least i was able to use the library
the instructions were outdated
aff ok, todday was a productive day, i did manny updates to my project :P good night everyone!
 
10:06 PM
When writing a C-wrapper to a C++ library is new/delete the only way to safely manage dynamic memory from the C++ side, since std::unique_ptr is scoped and std::shared_ptr may have unreliable semantics across a language+process boundary?
 
you need to convert to "raw types" at boundaries, yes
note: boundaries
 
@milleniumbug ah thanks so much for the confirmation, what a huge relief! Thought I had completely missed something when I've been working in C++11 mindset for so long
 
making such wrappers is either quite easy or hellishly difficult depending on complexity of the library, number of interaction points, and on how portable you want to be
throwing across foreign language frames may sometimes work, but of course it's safer to assume it doesn't, but it adds work
and also there are issues with libraries that are using different runtimes
^ you don't want to support this (different runtimes)
because such code can't safely assume the library and the library user uses the same malloc implementation, for example
 
yeah, I making sure not to throw any exceptions from the C++ side
 

« first day (346 days earlier)      last day (2490 days later) »