Skip to content

Commit

Permalink
KOTOR: Add code for testing KotOR animations
Browse files Browse the repository at this point in the history
Highlight a creature with the mouse, and press m to advance this
creature to the next animation. A message showing the name of the
current aniamtion will be printed to stderr. Press n to go back to the
previous animation.

Likewise, highlight a situated object (a placeable or a door) and
press to advance to the next object state.

This only works with objects and creatures that are already
highlightable.
  • Loading branch information
DrMcCoy committed May 10, 2018
1 parent 9973994 commit 863e60b
Show file tree
Hide file tree
Showing 10 changed files with 135 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/engines/kotor/area.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,8 +435,15 @@ void Area::processEventQueue() {
if (e->key.keysym.sym == SDLK_TAB)
highlightAll(true);
} else if (e->type == Events::kEventKeyUp) { // Releasing TAB
if (e->key.keysym.sym == SDLK_TAB)
if (e->key.keysym.sym == SDLK_TAB) {
highlightAll(false);
} else if (e->key.keysym.sym == SDLK_m) {
checkActive();
playNextAnimation();
} else if (e->key.keysym.sym == SDLK_n) {
checkActive();
playPreviousAnimation();
}
}
}

Expand Down Expand Up @@ -494,6 +501,24 @@ void Area::click(int x, int y) {
_module->clickObject(o);
}

void Area::playNextAnimation() {
Common::StackLock lock(_mutex);

if (!_activeObject)
return;

_activeObject->playNextAnimation();
}

void Area::playPreviousAnimation() {
Common::StackLock lock(_mutex);

if (!_activeObject)
return;

_activeObject->playPreviousAnimation();
}

void Area::highlightAll(bool enabled) {
if (_highlightAll == enabled)
return;
Expand Down
2 changes: 2 additions & 0 deletions src/engines/kotor/area.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ class Area : public KotOR::Object, public Events::Notifyable {
void highlightAll(bool enabled);

void click(int x, int y);
void playNextAnimation();
void playPreviousAnimation();


friend class Console;
Expand Down
40 changes: 40 additions & 0 deletions src/engines/kotor/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,17 @@ namespace KotOR {
Creature::Creature(const Aurora::GFF3Struct &creature) : Object(kObjectTypeCreature) {
init();
load(creature);

if (_model)
_modelStates = _model->getStates();

_currentModelState = _modelStates.end();
}

Creature::Creature() : Object(kObjectTypeCreature) {
init();

_currentModelState = _modelStates.end();
}

Creature::~Creature() {
Expand Down Expand Up @@ -414,6 +421,39 @@ Common::ScopedPtr<Graphics::Aurora::Model> &Creature::getModel() {
return _model;
}

void Creature::playNextAnimation() {
if (!_model)
return;

if (_currentModelState == _modelStates.end())
_currentModelState = _modelStates.begin();

if (_currentModelState == _modelStates.end())
return;

warning("Playing animation \"%s\" on model \"%s\" (\"%s\")", _currentModelState->c_str(),
_model->getName().c_str(), _tag.c_str());

_model->playAnimation(*_currentModelState, true, -1);

++_currentModelState;
}

void Creature::playPreviousAnimation() {
if (!_model || _modelStates.empty())
return;

--_currentModelState;

warning("Playing animation \"%s\" on model \"%s\" (\"%s\")", _currentModelState->c_str(),
_model->getName().c_str(), _tag.c_str());

_model->playAnimation(*_currentModelState, true, -1);

if (_currentModelState == _modelStates.begin())
_currentModelState = _modelStates.end();
}

} // End of namespace KotOR

} // End of namespace Engines
6 changes: 6 additions & 0 deletions src/engines/kotor/creature.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ class Creature : public Object {

Common::ScopedPtr<Graphics::Aurora::Model> &getModel();

void playNextAnimation();
void playPreviousAnimation();

private:
/** Parts of a creature's body. */
struct PartModels {
Expand Down Expand Up @@ -121,6 +124,9 @@ class Creature : public Object {

Common::ScopedPtr<Graphics::Aurora::Model> _model; ///< The creature's model.

std::list<Common::UString> _modelStates;
std::list<Common::UString>::const_iterator _currentModelState;


void init();

Expand Down
5 changes: 5 additions & 0 deletions src/engines/kotor/door.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ Door::Door(Module &module, const Aurora::GFF3Struct &door) : Situated(kObjectTyp
_linkedToFlag(kLinkedToNothing), _linkedToType(kObjectTypeAll) {

load(door);

if (_model)
_modelStates = _model->getStates();

_currentModelState = _modelStates.end();
}

Door::~Door() {
Expand Down
6 changes: 6 additions & 0 deletions src/engines/kotor/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ void Object::playSound(const Common::UString &sound, bool pitchVariance) {
_sound = ::Engines::playSound(sound, Sound::kSoundTypeVoice, false, 1.0f, pitchVariance);
}

void Object::playNextAnimation() {
}

void Object::playPreviousAnimation() {
}

} // End of namespace KotOR

} // End of namespace Engines
3 changes: 3 additions & 0 deletions src/engines/kotor/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ class Object : public Aurora::NWScript::Object, public KotOR::ScriptContainer {
/** Play an object sound. */
void playSound(const Common::UString &sound, bool pitchVariance = false);

virtual void playNextAnimation();
virtual void playPreviousAnimation();

protected:
ObjectType _type; ///< The object's type.

Expand Down
5 changes: 5 additions & 0 deletions src/engines/kotor/placeable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ Placeable::Placeable(const Aurora::GFF3Struct &placeable) : Situated(kObjectType
_state(kStateDefault), _hasInventory(false) {

load(placeable);

if (_model)
_modelStates = _model->getStates();

_currentModelState = _modelStates.end();
}

Placeable::~Placeable() {
Expand Down
34 changes: 34 additions & 0 deletions src/engines/kotor/situated.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Situated::Situated(ObjectType type) : Object(type), _appearanceID(Aurora::kField
_soundAppType(Aurora::kFieldIDInvalid), _locked(false),
_lastOpenedBy(0), _lastClosedBy(0), _lastUsedBy(0) {

_currentModelState = _modelStates.end();
}

Situated::~Situated() {
Expand Down Expand Up @@ -206,6 +207,39 @@ void Situated::loadSounds() {
_soundLocked = twoda.getRow(_soundAppType).getString("Locked");
}

void Situated::playNextAnimation() {
if (!_model)
return;

if (_currentModelState == _modelStates.end())
_currentModelState = _modelStates.begin();

if (_currentModelState == _modelStates.end())
return;

warning("Setting state \"%s\" on model \"%s\" (\"%s\")", _currentModelState->c_str(),
_model->getName().c_str(), _tag.c_str());

_model->setState(*_currentModelState);

++_currentModelState;
}

void Situated::playPreviousAnimation() {
if (!_model || _modelStates.empty())
return;

--_currentModelState;

warning("Setting state \"%s\" on model \"%s\" (\"%s\")", _currentModelState->c_str(),
_model->getName().c_str(), _tag.c_str());

_model->setState(*_currentModelState);

if (_currentModelState == _modelStates.begin())
_currentModelState = _modelStates.end();
}

} // End of namespace KotOR

} // End of namespace Engines
8 changes: 8 additions & 0 deletions src/engines/kotor/situated.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ class Situated : public Object {
/** Set the situated object's orientation. */
void setOrientation(float x, float y, float z, float angle);

// Object/Cursor interactions

void playNextAnimation();
void playPreviousAnimation();

protected:
Common::UString _modelName; ///< The model's resource name.

Expand All @@ -88,6 +93,9 @@ class Situated : public Object {

Common::ScopedPtr<Graphics::Aurora::Model> _model; ///< The situated object's model.

std::list<Common::UString> _modelStates;
std::list<Common::UString>::const_iterator _currentModelState;


Situated(ObjectType type);

Expand Down

0 comments on commit 863e60b

Please sign in to comment.