Before the advent of radar, gunnery depended on visual observation. As others have noted this was either by optical range finders mounted high in the ship or spotter aircraft. Depending on atmospheric conditions, the limit of direct observation was around 12 miles. Naval fire control was, and is, an extremely complex problem. Two excellent works on the subject are In Defence of Naval Supremacy by John T. Sumida (arguably THE expert on the subject, especially in the British navy) and Naval Firepower by Norman Friedman. Friedman, in his lavishly illustrated work, exams the development of naval fire control in the U.S. Navy during the Dreadnought era.