try your best to stay mentally strong. Hopefully your pain is something that can be fixed. There are a lot of great success stories with knee surgeries, but a lot of times, its never the same again.
Im in the same boat. I tore my knee up racing motocross. I blew my knee out twice. The second time, I tore my acl and mcl. I hyperextended the knee and broke my knee cap. The miniscus was pushed completely out from the impact. The trauma to the joint was so bad, my knee pretty much just shut down. I don't really have any cartilage left in it. I had 7 surgeries on it by the time I was your age. Since then, there is nothing they can do. It needs replaced, and they wont do that at my age (24).
If you worry about how broke down you will be at 40, you start to forget your still young. If you work at it and have the confidence in yourself, over time you can mentally block a lot of the pain out and still enjoy your hobby. Its hard, but a strong healthy attitude is very important. Definitely get everything checked out by a doctor.
Also, im not saying to push thru something that could be damaging. Don't take my advise and push thru pain if that pain is a torn ligament or something. If its just pain that they can't do anything for is what I was talking about. Hard to put it all in words, but I've dealt with a lot of pain in my life, so if you need any advise or anything on living with pain, feel free to message me