« first day (656 days earlier)      last day (2201 days later) » 

12:00 AM
so I take I also have to remake my container from
std::map<int, std::map<int, std::function<std::shared_ptr<icNode>(void)>>>
to
std::map<int, std::map<int, std::function<std::shared_ptr<icNode>(std::string,std::string)>>>
?
 
That's what I was saying you could do, yeah
 
I see, I though I could just have an overload somehow,
humh
humh
very interesting
Thanks, I think I have an idea how to deal with it. I guess I could register 2 vectors with 2 different sets of arguments
 
Allow me to interrupt with a furtive question about complexity of the function vector.insert(ptr,newval,newval+offset), does the container delays all the values from ptr ahead to the end, or is there some kind of chained list struct inside ?
 
I do kind of question std::map<int, std::map<int, ...>> though; it makes me wonder whether it'd be better as std::map<std::pair<int, int>, ...> (and you might prefer std::unordered_map to std::map)
 
 
1 hour later…
1:33 AM
Do you guys think a self-answered question asking why if(x == (1 || 3)) does not work would be good? I found some questions about comparing a variable to multiple values, but none of them explain why the expression does not work. I think a question like this would be helpful since we can direct beginners making this mistake to the question instead of explaining it every time. I'm kind of afraid that people will consider this to be too basic.
 
1:45 AM
Its too basic, and I would close it as a typographic mistake
Possibly close it as a dupe to the one you linked
 
2:09 AM
Hi! So I'm trying to implement a depth first search according to the question I asked, here: https://stackoverflow.com/questions/50067721/modifying-a-depth-first-search-algorithm-using-an-adjacency-matrix-to-search-for

and this is my code: https://pastebin.com/d5srh4ry
And that is the graph of my adjacency matrix.
When I try and go from node 6 to 3, for example I get a response of (1, 2, 2)
 
protip, use boost
 
Can't use boost, assignment to implement DFS ourselves.
Anyways, the path keeps returning incorrectly, and I'm not exactly sure where in my implementation i am making a mistake.
Wait... I just realized something actually.....
Yeah nevermind, still have no idea.
 
 
8 hours later…
10:05 AM
hey
 
10:16 AM
anyone know what the * does here?
virtual Inherited* clone() const {
      return new Inherited(*this)
}
 
nwp
10:57 AM
@Jurassic The first one means that clone returns a pointer to an Inherited and the second one dereferences this.
 
@Jurassic return value is a pointer of Inherited...this dynamic constructed object on heap is instantiated by copyconstructor with actual instance (*this) as parameter.
 
complicated stuff
i still cant think this through
 
nwp
There is some context missing here. clone is a member function of some class. this is a pointer to an object of that class. Inherited most likely has a constructor that takes a reference to that class, but not a constructor that takes a pointer to that class.
 
@Jurassic the virtual method returns a pointer of an object from type Inherited, which is initalized with actual instance of these type (where this method is part of).
@nwp but it is dereferenced *this....so you the constructor of Inherited gets a reference as parameter....just a copyconstruction.
 
 
2 hours later…
1:11 PM
reinterpret_cast<std::vector<dyn_object>::iterator&>(params[1]); is this UB?
casting an int to a reference?
 
nwp
It's UB whenever you access something by the wrong type, except for char.
 
1:37 PM
casting an int to std::vector<int>* is also UB, right?
How do I answer a person who says the code works with it and is not willing to change?
 
nwp
@Yashas I believe the cast itself is not technically UB. Dereferencing the pointer most likely is.
 
auto ptr = reinterpret_cast<list_t*>(params[1]);
ptr->push_back(Factory(amx, params[Indices]...));
 
nwp
@Yashas You say that it's shitty code that is difficult to follow and can break any moment. If they don't see a problem with that try to isolate yourself from that code so you can't get blamed when it eventually breaks.
If you are on not-windows you can use sanitizers to make the code crash and proof that it is obviously not working.
@Yashas It depends on what params[1] is. Assuming someone did params[1] = reinterpret_cast<int>(new std::vector<int>); and you are on 32 bit it would still be shitty, but not technically UB.
There is a chance I'm missing something and it actually is UB.
The most compelling argument I can think of is that when you need to store a std::vector<int>* you should store it as a std::vector<int>* and not as an int.
 
It has to be passed to an external program.
The address is being used to identify the vector inside the host program.
 
nwp
1:52 PM
On systems with a proper OS programs run on different areas of memory. That means the pointer you get cannot be dereferenced, you get a crash instead.
You need some ReadProcessMemory trickery or whatever it was called.
 
it's not touched in the host program
it's just used as an identifier
 
nwp
So whenever someone passes a wrong identifier the program crashes?
 
yes
 
nwp
And that is not considered a problem?
 
I already voiced it but he said it would crash and left it there :|
This is the code if you are interested in looking at
 
nwp
1:56 PM
Well, if crashing on incorrect input is considered acceptable I guess it's fine.
 
Good day!
 
nwp
Doesn't work on 64 bit though because pointers will have 64 bits and ints only 32 so you can't fit a pointer into an int.
 
Quick question: I've got a map<string, int> currently and on a certain condition, i'd like to update the string part, however, it doesn't seem to like this (any ideas why? - I could make a whole new pair and remove the current one but that doesnt feel too efficient):
item.first = "Ammunition (" + to_string(player.ammo) + ")";
Unless it's obvious from the code to someone, the error message is "no operator "=" matches these operands"
 
nwp
You have to do the remove+insert. You can't just change it in-place because that could change the order which breaks the tree that std::map uses.
 
Alright!
But get this then: Why does it work when I change the int-part later on if so?
Or, atleast it doesnt give me an error
 
nwp
2:08 PM
Because the tree is ordered by the key, not the value.
 
oh
oh..
that's..
 
nwp
Also if you have C++17 look at extract.
 
god dammit. Alright, thanks!
 
3:03 PM
Is there a better way to do this: auto intrf_iter = std::find_if(IScriptList.begin(), IScriptList.end(), [](const IScript& intrf) { return intrf.empty(); });
I have a std::vector of objects. There's a member variable in the object. I need to find the object in the std::vector which has a particular value in that member variable.
 
nwp
Looks good to me. What's bothering you about it?
 
I was wondering if there was a better way to search.
That lambda function is so small.
What about overloading bool conversion operator and looking for the first one which evaluates to false? Even with this I don't know how to find the correct object.
 
nwp
If you do have that one of these should make the lambda unnecessary.
But it seems fine to me. The lambda is obvious and understandable.
Implicit conversions not so much.
 
I need an iterator to the empty object.
Hmm, I don't know why my opinions change so fast but I think the lambda is good.
if (IScriptList.size() == static_cast<int>(std::numeric_limits<ScriptKey_t>::max()) + 1)is there a nicer way to do it?
The number of objects is limited by the number of non-zero id numbers ScriptKey_t can store. I need to check if the maximum has been hit.
I get a warning. I have to cast somewhere. And size() could also turn out to be zero.
 
nwp
3:19 PM
Why +1 and not -1?
The right side evaluates to 256, right?
 
127?
 
nwp
std::numeric_limits<uint_8>::max() should be 255
 
ScriptKey_t is int8_t
 
nwp
Ah, oh.
 
overflow is undefined behavior, right?
 
nwp
3:22 PM
I still don't understand the +1.
 
is it ok to assume that (unsigned int)0 - 1 is never going to equal 128?
 
AH HA! I got most of my depth first search work properly.
 
nwp
@Yashas Basically for signed numbers yes, for unsigned no.
 
@nwp The ScriptKey_t is allowed to take [0, 127] => |[0, 127]| = 128. size() would have 128 when all the keys have been used.
 
nwp
You said non-zero ids, so I assumed [1, 127] and wondered what happens for negative numbers.
@Annabelle good job
 
3:25 PM
@nwp Oh my. I meant non-negative ids. My bad. Sorry.
 
I am running into one problem tho. It seems to be adding an extra set into the path.
For example this is my mostly working code: pastebin.com/L4eCB6vU
For example: if I call it on callDFS(3, 6);
Then I get a path of 3 1 2 5 6 6 5 2 1
Instead of 3 1 2 5 6
Not sure why
 
You could pass the visited (and path too) array as a reference instead of a pointer.
vector<bool>* visited => vector<bool>& visited
 
The visited array seems fine though? That wouldn't change the error at all.
 
@Annabelle It's fine but I thought it would nicer to deal with references than pointers. Pointers tend to be error-prone and hamper readability.
You could use a 2D array for the adjacency matrix.
 
I might change it up later then. However I'd like to fix the main issue first.
I'm already using a vector for that.
 
3:32 PM
You could use std::vector<std::vector<int>>. This would allow you to use this syntax: adjMatrix[w][src]
 
That doesn't solve any problem, not to be rude. It's just a design difference.
 
nwp
Don't underestimate clear design. It tends to make solving problems easier.
 
I don't get the logic. Why is every reachable node being pushed into path?
@Annabelle For every node in the path, simpleDFS pushes the node onto the path vector at line 20. After that simpleDFS returns, the previous simpleDFS will add it back again (because of line 25).
You have to remove line 20.
The simpleDFS call which will find the destination will push the destination node onto path and returns. As it returns (and has found the destination node), you have to push the nodes which helped reach the destination node (which line 25 correctly does) and at the end you have to push source into the path.
 
3:54 PM
Hmm removing line 20 gives me an output of: 6 6 5 2 1
When it should be 6 5 2 1 3
So slightly better I think.
Also putting a path->push_back(src); at the very end (right before the final return)
Does not do anything
 
4:23 PM
From cppreference - overload resolution
Either way, the argument list for the purpose of overload resolution consists of a single argument which is the initializer expression, which will be compared against the first argument of the constructor or against the implicit object argument of the conversion function.

Am I correct that argument here is compared against the parameter? Or is the arg vs arg terminology correct?
 
 
4 hours later…
8:30 PM
a
 
 
2 hours later…
10:37 PM
Good evening!
So I doubt anyone is up at this time, but whatever, I'll shoot anyways.
I currently got two classes, EnemyActions and PlayerActions, and it's a bit conflicting. PlayerActions needs to include EnemyActions to know where the enemies are, and EnemyActions needs to include PlayerActions to know where the player is. Which, in it's turn, results in getting "too many include files depth = 1024" or something along those lines.
Googling around, it seems i'm missing #pragma once in my header files, which I've added (nonetheless, I had #ifndef .. #define .. #endif before), but this seems to result in the header files not recognizing the classes coming in as parameters
So I'm really stuck between a rock and a hard place here. Any ideas?
 
nwp
Sounds like you have cyclic includes.
 
If that's exactly what it sounds like, then yeah, I guess so
 
nwp
How about you merge PlayerAction and EnemyAction into a single Action that doesn't need to know who the player and who the enemy is?
 
I could, and I'd want to, but the way I made it from the start doesn't allow me to do that unless I spend the next few weeks refactoring everything to support it
I could have a single Action file with two different classes I guess, if that changes anything?
For the time being anyways
Prior to this I had a third file, GameCharacter, which allowed me to bypass this error, so if nothing else I can go back to that.
Primarily I wanted to try to make it look better
 
nwp
There is a chance my crystal ball is defective and it's not actually cyclic includes, but if it is correct you need to break the cycle and say for example that PlayerAction.h may not include EnemyAction.h. That creates the problem that PlayerAction can no longer refer to EnemyAction because the type is not known. And you fix that with forward declarations.
 
10:45 PM
That is a possibility, i assume
You know, all things considered, I'm starting to wonder if all this effort is worth it, if we take into context that i could just re-introduce that third file
 
nwp
Sounds like you have lost sight of your design a bit and should think about what classes are responsible for what and what they need to refer to and do some refactoring.
 
Yeah, i realised that earlier tonight and this is my first attempt at it. But I probably need to get to sketching up a "blueprint" on how i want things to work
 
nwp
You can only do the simple thing that fixes the immediate issue for so long before you collapse under technical dept.
 
They're all duct-tape solutions pretty much, yeah
 
nwp
A blueprint sounds like a good idea.
 
10:54 PM
Ah, working towards GitHub is lovely. Just have to run a command if i want to revert back to the latest commit and everything works again.
But yeahno, cheers for the help once again!
 
11:11 PM
I feel like the correct solution to the problem of writing a game is to use of the many tried and tested game engines.
 
Well, for what it's worth, I am using SDL
 
11:45 PM
Is it possible that a breadth first search returns no path, when a depth first search returns a path given an adjacency matrix?
 
1 message moved from Lounge<C++>
@Annabelle No. A path is a path. BF/DF just determines the order in which nodes/paths are visited.
The graph representation should be immaterial.
Did you make sure the graph is correctly interpreted (directedness, e.g.)
 
Hmm okay. I think then I might be having some sort of error somewhere... need to test it then.
// Our implementation of Breadth-First Search.
// Takes in source, destination nodes and 2 vectors of visited/path.
void Network::BFS(int src, int dest, vector<bool>& visited, vector<int>& path) {
	// The Queue is the core for the BFS.
	queue<int> Queue;
	// Mark current node as visited.
	visited[src] = true;
	Queue.push(src);
	// While queue is not empty.
	while (!Queue.empty()) {
		// Add node to path.
		// Check if we have found the destination yet or not, if we have we do one last push to path and we're done!
I have this as my breadth first search, yet it is failing to find a path.
Is there anything I did wrong in it?
 
Have you tried debugging it
 

« first day (656 days earlier)      last day (2201 days later) »