The Old Republic and both Knights of the Old Republic are set long before the movies, but how do they mesh with each other? I thought TOR would be after both KOTOR games, but the opening cinematics make it sound like it's all about the reemergence of the Sith after having been in hiding for so long (but making a huge army/fleet?)
According to the Star Wars wikia, Knights of the Old Republic takes place in 3,956 BBY (Before the Battle for Yavin - aka the finale of Episode IV: A New Hope) which is 303 years before the BTC (Treaty of Coruscant).
The Treaty of Coruscant heralds the start of the "Cold War Era", during which The Old Republic is set.
So KOTOR takes place about 300 years before TOR.
Do note that the Opening Cinematic in the game is set in the "Past". For instance, the Jedi that gets away, Satele Shan, is now one of the premier leaders of the Jedi Order, not simply an apprentice as she is in the cinematic.
The faction specific cinematics are also set in the "Past", though they reference events at the end of the Sith-Republic war, rather than the beginning of it, specifically The Sacking of Coruscant and The Battle of Alderaan.
The exact date within TOR is unknown, though it is estimated to be about 20 ATC (After Treaty of Coruscant)
The complete in-universe explanation of how the plotlines fit together is given in the Revan tie-in novel. (Note that despite being the third published in the The Old Republic tie-in novel series, none of the books have anything to do with the others, and indeed Revan takes place chronologically first.)
It ties together the emergence of Revan's Sith to not only the Sith of The Old Republic's Cold War era, but also the Sith of the original Tales of the Jedi comics (Naga Sadow, Ludo Kreshh, Marka Ragnos, et al.). It resolves several outstanding questions from the game, both about Revan's past and the future of Revan and the Exile. Highly recommended.
Slightly-spoilery outline of the main thrust of the book:
In short, some time after the end of KOTOR (and as alluded to in KOTOR2) Revan is prompted by recurring dreams to head off into the Unknown Regions in search of the true Sith. With the help of the Exile, he finds them, and recovers his memories.
More-spoilery summary of the revealed info:
After the Great Hyperspace War of 5000 BBY, as told in the Tales of the Jedi comics, an individual emerged to lead the remainder of the Sith into hiding. That individual became the Sith Emperor and acquired immortality, so that indeed this is the same Emperor as in The Old Republic. Revan and Malak encountered him in the Unknown Regions, and he dominated their minds, turning them to the dark side; he sent them out against the Republic as a test of their defenses, thus explaining the Jedi Civil War of the Knights of the Old Republic game.
And finally, a spoiler of the end of the novel, tying it all together:
Revan, upon recovering these memories, returns with the Jedi Exile (from KOTOR2) to confront the Sith Emperor. He and the Exile are defeated in the ensuing conflict; the Exile is killed, while Revan is held captive by the Emperor. Revan is kept in some kind of suspended animation state while the Emperor pries into his mind, but vows to not only stay strong and not reveal information about the Republic, but also to enhance the Emperor's naturally cautious tendencies, thus delaying the Sith Invasion long enough for his children to grow up in a galaxy without war. This delaying action is presumably what led to the 300-year gap between the events of KOTOR / Revan and those of The Old Republic. Revan's eventual fate, however, is unknown, and likely to be a significant plot point in The Old Republic.