Skip to content

Commit

Permalink
KOTOR2: Port satellite camera implementation from K1
Browse files Browse the repository at this point in the history
  • Loading branch information
vkremianskii committed May 13, 2018
1 parent c554226 commit 145895d
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 19 deletions.
18 changes: 12 additions & 6 deletions src/engines/kotor2/console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,21 @@ Console::Console(KotOR2Engine &engine) :
::Engines::Console(engine, Graphics::Aurora::kSystemFontMono, 13),
_engine(&engine), _maxSizeMusic(0) {

registerCommand("exitmodule" , boost::bind(&Console::cmdExitModule , this, _1),
registerCommand("exitmodule" , boost::bind(&Console::cmdExitModule , this, _1),
"Usage: exitmodule\nExit the module, returning to the main menu");
registerCommand("listmodules", boost::bind(&Console::cmdListModules, this, _1),
registerCommand("listmodules", boost::bind(&Console::cmdListModules , this, _1),
"Usage: listmodules\nList all modules");
registerCommand("loadmodule" , boost::bind(&Console::cmdLoadModule , this, _1),
registerCommand("loadmodule" , boost::bind(&Console::cmdLoadModule , this, _1),
"Usage: loadmodule <module>\nLoad and enter the specified module");
registerCommand("listmusic" , boost::bind(&Console::cmdListMusic , this, _1),
registerCommand("listmusic" , boost::bind(&Console::cmdListMusic , this, _1),
"Usage: listmusic\nList all available music resources");
registerCommand("stopmusic" , boost::bind(&Console::cmdStopMusic , this, _1),
registerCommand("stopmusic" , boost::bind(&Console::cmdStopMusic , this, _1),
"Usage: stopmusic\nStop the currently playing music resource");
registerCommand("playmusic" , boost::bind(&Console::cmdPlayMusic , this, _1),
registerCommand("playmusic" , boost::bind(&Console::cmdPlayMusic , this, _1),
"Usage: playmusic [<music>]\nPlay the specified music resource. "
"If none was specified, play the default area music.");
registerCommand("tfc" , boost::bind(&Console::cmdToggleFreeCam, this, _1),
"Usage: tfc\nToggle free roam camera mode");
}

Console::~Console() {
Expand Down Expand Up @@ -141,6 +143,10 @@ void Console::cmdPlayMusic(const CommandLine &cl) {
_engine->getGame().playMusic(cl.args);
}

void Console::cmdToggleFreeCam(const CommandLine &UNUSED(cl)) {
_engine->getGame().getModule().toggleFreeRoamCamera();
}

} // End of namespace KotOR2

} // End of namespace Engines
13 changes: 7 additions & 6 deletions src/engines/kotor2/console.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,13 @@ class Console : public ::Engines::Console {
void updateMusic();

// The commands
void cmdExitModule (const CommandLine &cl);
void cmdListModules(const CommandLine &cl);
void cmdLoadModule (const CommandLine &cl);
void cmdListMusic (const CommandLine &cl);
void cmdStopMusic (const CommandLine &cl);
void cmdPlayMusic (const CommandLine &cl);
void cmdExitModule (const CommandLine &cl);
void cmdListModules (const CommandLine &cl);
void cmdLoadModule (const CommandLine &cl);
void cmdListMusic (const CommandLine &cl);
void cmdStopMusic (const CommandLine &cl);
void cmdPlayMusic (const CommandLine &cl);
void cmdToggleFreeCam(const CommandLine &cl);
};

} // End of namespace KotOR2
Expand Down
37 changes: 30 additions & 7 deletions src/engines/kotor2/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "src/aurora/gff3file.h"

#include "src/graphics/camera.h"
#include "src/graphics/graphics.h"

#include "src/graphics/aurora/textureman.h"

Expand All @@ -46,6 +47,7 @@
#include "src/engines/aurora/resources.h"
#include "src/engines/aurora/console.h"
#include "src/engines/aurora/freeroamcamera.h"
#include "src/engines/aurora/satellitecamera.h"

#include "src/engines/kotor2/module.h"
#include "src/engines/kotor2/area.h"
Expand All @@ -62,7 +64,8 @@ bool Module::Action::operator<(const Action &s) const {

Module::Module(::Engines::Console &console) : Object(kObjectTypeModule),
_console(&console), _hasModule(false), _running(false),
_currentTexturePack(-1), _exit(false), _entryLocationType(kObjectTypeAll) {
_currentTexturePack(-1), _exit(false), _entryLocationType(kObjectTypeAll),
_freeCamEnabled(false) {
loadTexturePack();
}

Expand Down Expand Up @@ -313,9 +316,10 @@ void Module::enter() {
}

// Roughly head position
CameraMan.setPosition(entryX, entryY, entryZ + 1.8f);
CameraMan.setOrientation(90.0f, 0.0f, entryAngle);
CameraMan.update();
SatelliteCam.setTarget(entryX, entryY, entryZ + 1.8f);
SatelliteCam.setDistance(3.2f);
SatelliteCam.setPitch(83);
SatelliteCam.update(0);

enterArea();

Expand Down Expand Up @@ -403,8 +407,18 @@ void Module::processEventQueue() {
if (!isRunning())
return;

uint32 now = SDL_GetTicks();
_frameTime = (now - _prevTimestamp) / 1000.f;
_prevTimestamp = now;

handleEvents();
handleActions();

if (!_freeCamEnabled) {
GfxMan.lockFrame();
SatelliteCam.update(_frameTime);
GfxMan.unlockFrame();
}
}

void Module::handleEvents() {
Expand All @@ -430,16 +444,21 @@ void Module::handleEvents() {
}

// Camera
if (!_console->isVisible())
if (FreeRoamCam.handleCameraInput(*event))
if (!_console->isVisible()) {
if (_freeCamEnabled) {
if (FreeRoamCam.handleCameraInput(*event))
continue;
} else if (SatelliteCam.handleCameraInput(*event))
continue;
}

_area->addEvent(*event);
}

_eventQueue.clear();

CameraMan.update();
if (_freeCamEnabled)
CameraMan.update();

_area->processEventQueue();
}
Expand Down Expand Up @@ -557,6 +576,10 @@ Common::UString Module::getName(const Common::UString &module) {
return "";
}

void Module::toggleFreeRoamCamera() {
_freeCamEnabled = !_freeCamEnabled;
}

} // End of namespace KotOR2

} // End of namespace Engines
6 changes: 6 additions & 0 deletions src/engines/kotor2/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ class Module : public KotOR2::Object, public KotOR2::ObjectContainer {
void processEventQueue();
// '---

void toggleFreeRoamCamera();

private:
enum ActionType {
kActionNone = 0,
Expand Down Expand Up @@ -179,6 +181,10 @@ class Module : public KotOR2::Object, public KotOR2::ObjectContainer {
EventQueue _eventQueue;
ActionQueue _delayedActions;

bool _freeCamEnabled;
uint32 _prevTimestamp;
float _frameTime;


// .--- Unloading
/** Unload the whole shebang.
Expand Down

0 comments on commit 145895d

Please sign in to comment.