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 dont 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. definately get everything checked out by a doctor.
also, im not saying to push thru something that could be damaging. dont take my advise and push thru pain if that pain is a torn ligament or something. if its just pain that they cant do anything for is what i was talking about. hard to put it all in words, but ive 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