bethesirius / ChosunTruck

Euro Truck Simulator 2 autonomous driving solution
732 stars 104 forks source link

Trying to get Input working #7

Closed zappybiby closed 7 years ago

zappybiby commented 7 years ago

Main changes: Creating a framework to get input working in Windows. Formatted the solution. Fixed the freezing issue that was preventing https://github.com/bethesirius/ChosunTruck/commit/a052ca5c8de5dbec7f7856a4861fed243558926c from working.

Current Status: Pauses after the first "go straight" command, then after a couple of seconds it finds lines and adjusts accordingly. Line detection does freeze at some moments, and it seems to always want to go left when it should be going straight.

Fixed Problems: Freezing: Turns out that I had to change "unsigned char" to "uchar" (as is needed for CV_8U matrix in OpenCV 3.0). This fixed the memory leak that was causing program to freeze.

Input: KEYEVENTF_SCANCODE isn't actually defined, I'm switching to KEYEVENTF_UNICODE (Although this still doesn't work in ETS2). I originally used SCANCODE to make SendInput use hardware scan codes. Since SendInput works at a lower level than WM_KEYDOWN and keybd_event, my intention was to get input to work with programs like ETS2 that don't work with virtual key inputs. In my current build, Spy++ does not register any messages being sent to the Prism3d window. Although keybd_event was not working originally, it is possible that it may work now. Read more here

Current issues: Input: Unfortunately, input isn't working. Prism3d uses DirectInput (which is actually a wrapper for RawInput) so we will need to adapt code to this. Read more here

Debug: Also worth nothing that Debug build is failing to run with error

"Assertion failed (src.checkVector(2, CV_32F) == 4 && dst.checkVector(2, CV_32F) ==
4) in cv::Mat cv::GetPerspectiveTransform ..."

This error doesn't seem to affect the Release build. This error is usually caused by the Mat being of an invalid type. However since we are using hwnd2mat, it is hard to identify where we are giving the Mat it's type.

zappybiby commented 7 years ago

I apologize for making this large pull request. I do not know how to break this up.

If you want, you can fork from https://github.com/bethesirius/ChosunTruck/commit/a052ca5c8de5dbec7f7856a4861fed243558926c and make the changes noted here https://github.com/bethesirius/ChosunTruck/pull/7/commits/501083326c7ff1587f5365bc4550337735653b6d to basically come to the point I am at. This avoids the excessive formatting.

Note: I have no idea what I'm doing and have no prior coding experience. I couldn't even make a "Hello World" in C++ if you asked me right now. Merge with caution!