Skip to content

Commit

Permalink
- rewritten actors speech engine :
Browse files Browse the repository at this point in the history
  1) there are three types of speech: one acor, multiple actor, non actor
  2) slow speech implemented
  3) uses native engine flags (async,noanimate...) instead of semaphores
- proper timings implemented

svn-id: r16237
  • Loading branch information
ajax16384 committed Dec 21, 2004
1 parent ad0b8f1 commit ea3b0d1
Show file tree
Hide file tree
Showing 14 changed files with 496 additions and 422 deletions.
392 changes: 194 additions & 198 deletions saga/actor.cpp

Large diffs are not rendered by default.

107 changes: 73 additions & 34 deletions saga/actor.h
Expand Up @@ -39,22 +39,46 @@ namespace Saga {

#define ACTOR_ACTIONTIME 80

#define ACTOR_DIALOGUE_LETTERTIME 50
#define ACTOR_DIALOGUE_HEIGHT 100

#define ACTOR_LMULT 4

#define ACTOR_ORIENTATION_COUNT 4

#define ACTOR_SPEECH_STRING_MAX 16
#define ACTOR_SPEECH_ACTORS_MAX 8

#define IS_VALID_ACTOR_INDEX(index) ((index >= 0) && (index < ACTORCOUNT))
#define IS_VALID_ACTOR_ID(id) ((id == 1) || (id >= 0x2000) && (id < (0x2000 | ACTORCOUNT)))
#define ACTOR_ID_TO_INDEX(id) ((((uint16)id) == 1 ) ? 0 : (int)(((uint16)id) & ~0x2000))
#define ACTOR_INDEX_TO_ID(index) ((((int)index) == 0 ) ? 1 : (uint16)(((int)index) | 0x2000))


enum ActorActions {
kActionWait = 0,
kActionWalkToPoint = 1,
kActionWalkToLink = 2,
kActionWalkDir = 3,
kActionSpeak = 4,
kActionAccept = 5,
kActionStoop = 6,
kActionLook = 7,
kActionCycleFrames = 8,
kActionPongFrames = 9,
kActionFreeze = 10,
kActionFall = 11,
kActionClimb = 12
};

enum SpeechFlags {
kSpeakNoAnimate = 1,
kSpeakAsync = 2,
kSpeakSlow = 4
};

enum ACTOR_INTENTS {
INTENT_NONE = 0,
INTENT_PATH = 1,
INTENT_SPEAK = 2
INTENT_PATH = 1
};

enum ACTOR_WALKFLAGS {
Expand Down Expand Up @@ -136,52 +160,34 @@ struct WALKINTENT {
};


struct ACTORDIALOGUE {
int d_playing;
const char *d_string;
uint16 d_voice_rn;
long d_time;
int d_sem_held;
SEMAPHORE *d_sem;
ACTORDIALOGUE() { memset(this, 0, sizeof(*this)); }
};

typedef Common::List<ACTORDIALOGUE> ActorDialogList;


struct ACTORINTENT {
int a_itype;
uint16 a_iflags;
int a_idone;

int si_init;
uint16 si_flags;
int si_last_action;
ActorDialogList si_diaglist; /* Actor dialogue list */

WALKINTENT walkIntent;

ACTORINTENT() {
a_itype = 0;
a_iflags = 0;
a_idone = 0;

si_init = 0;
si_flags = 0;
si_last_action = 0;
}
};

typedef Common::List<ACTORINTENT> ActorIntentList;


struct ActorData {
bool disabled; // Actor disabled in init section
int index; // Actor index
uint16 actorId; // Actor id
int nameIndex; // Actor's index in actor name string list
byte speechColor; // Actor dialogue color
uint16 flags; // Actor flags
uint16 flags; // Actor initial flags


int sceneNumber; // scene of actor
int actorX; // Actor's logical coordinates
int actorY; //
Expand All @@ -191,9 +197,12 @@ struct ActorData {
int screenDepth; //
int screenScale; //

int currentAction;
int facingDirection;
uint16 actorFlags; // dynamic flags
int currentAction; // ActorActions type
int facingDirection; // orientation
int actionDirection;
int actionCycle;
int frameNumber; // current actor frame number

SPRITELIST *spriteList; // Actor's sprite list data
int spriteListResourceId; // Actor's sprite list resource id
Expand Down Expand Up @@ -233,9 +242,6 @@ struct ActorData {
index = 0;
actorId = 0;
nameIndex = 0;
currentAction = 0;
facingDirection = 0;
actionDirection = 0;
speechColor = 0;
frames = NULL;
framesCount = 0;
Expand All @@ -248,6 +254,11 @@ struct ActorData {
actorY = 0;
actorZ = 0;
screenDepth = 0;

actorFlags = 0;
currentAction = 0;
facingDirection = 0;
actionDirection = 0;

idle_time = 0;
orient = 0;
Expand All @@ -270,6 +281,24 @@ struct ACTIONTIMES {
int time;
};

struct SpeechData {
int speechColor;
int outlineColor;
int speechFlags;
const char *strings[ACTOR_SPEECH_STRING_MAX];
int stringsCount;
int slowModeCharIndex;
uint16 actorIds[ACTOR_SPEECH_ACTORS_MAX];
int actorsCount;
int sampleResourceId;
bool playing;
int playingTime;

SpeechData() {
memset(this, 0, sizeof(*this));
}
};

class Actor {
public:
Actor(SagaEngine *vm);
Expand All @@ -284,39 +313,49 @@ class Actor {
int drawActors();
void updateActorsScene(); // calls from scene loading to update Actors info

void AtoS(Point &screenPoint, const Point &actorPoint);
void StoA(Point &actorPoint, const Point &screenPoint);

void move(uint16 actorId, const Point &movePoint);
void moveRelative(uint16 actorId, const Point &movePoint);

void walkTo(uint16 actorId, const Point *walk_pt, uint16 flags, SEMAPHORE *sem);

void speak(uint16 actorId, const char *d_string, uint16 d_voice_rn, SEMAPHORE *sem);

int skipDialogue();

int getSpeechTime(const char *d_string, uint16 d_voice_rn);
void setOrientation(uint16 actorId, int orient);
void setAction(uint16 actorId, int action_n, uint16 action_flags);
void setDefaultAction(uint16 actorId, int action_n, uint16 action_flags);

// speech
void actorSpeech(uint16 actorId, const char **strings, int stringsCount, uint16 sampleResourceId, int speechFlags);
void nonActorSpeech(const char **strings, int stringsCount, int speechFlags);
void simulSpeech(const char *string, uint16 *actorIds, int actorIdsCount, int speechFlags);
void setSpeechColor(int speechColor, int outlineColor) {
_activeSpeech.speechColor = speechColor;
_activeSpeech.outlineColor = outlineColor;
}
void abortAllSpeeches();
void abortSpeech();
bool isSpeaking() {
return _activeSpeech.stringsCount > 0;
}

private:
int handleWalkIntent(ActorData *actor, WALKINTENT *a_walk_int, int *complete_p, int msec);
int handleSpeakIntent(ActorData *actor, ACTORINTENT *a_aintent, int *complete_p, int msec);
int setPathNode(WALKINTENT *walk_int, const Point &src_pt, Point *dst_pt, SEMAPHORE *sem);

ActorData *getActor(uint16 actorId);

bool loadActorResources(ActorData * actor);

void createDrawOrderList();
void handleSpeech(int msec);

SagaEngine *_vm;
RSCFILE_CONTEXT *_actorContext;
ActorOrderList _drawOrderList;
ActorData _actors[ACTORCOUNT];
SpeechData _activeSpeech;
};

} // End of namespace Saga
Expand Down
15 changes: 15 additions & 0 deletions saga/console.cpp
Expand Up @@ -86,6 +86,21 @@ Console::Console(SagaEngine *vm) : Common::Debugger<Console>() {
Console::~Console() {
}

int Console::DebugPrintf(const char *format, ...) {
int count;
va_list argptr;

va_start(argptr, format);

debug(1, format, argptr);
count = Common::Debugger<Console>::DebugPrintf(format);

va_end (argptr);

return count;
}


void Console::preEnter() {
}

Expand Down
2 changes: 2 additions & 0 deletions saga/console.h
Expand Up @@ -35,6 +35,8 @@ class Console : public Common::Debugger<Console> {
Console(SagaEngine *vm);
~Console(void);

int DebugPrintf(const char *format, ...);

protected:
virtual void preEnter();
virtual void postEnter();
Expand Down
4 changes: 2 additions & 2 deletions saga/input.cpp
Expand Up @@ -71,7 +71,7 @@ int SagaEngine::processInput() {

// Actual game keys
case 32: // space
_actor->skipDialogue();
_actor->abortSpeech();
break;
case 19: // pause
case 'p':
Expand All @@ -80,7 +80,7 @@ int SagaEngine::processInput() {
case 27: // Esc
// Skip to next scene skip target
if (!_interface->getMode() == kPanelNone) // FIXME: hack
_script->SThreadAbortAll();
_actor->abortAllSpeeches();
else
_scene->skipScene();
break;
Expand Down
5 changes: 5 additions & 0 deletions saga/resnames.h
Expand Up @@ -104,6 +104,11 @@ namespace Saga {
#define CAVE_VOICE_12 12
#define CAVE_VOICE_13 13

#define SCENE1_VOICE_009 57
//TODO: fill it
#define SCENE1_VOICE_138 186


// MUSIC
#define MUSIC_1 9
#define MUSIC_2 10
Expand Down
2 changes: 1 addition & 1 deletion saga/saga.cpp
Expand Up @@ -248,7 +248,7 @@ int SagaEngine::go() {
}
_actor->direct(msec);
_events->handleEvents(msec);
_script->SThreadExecThreads(msec);
_script->executeThreads(msec);
}
// Per frame processing
_render->drawScene();
Expand Down
9 changes: 8 additions & 1 deletion saga/saga.h
Expand Up @@ -74,15 +74,22 @@ enum ERRORCODE {

enum SAGAGameId {
GID_ITE,
GID_ITECD,
GID_IHNM
};

enum scriptTimings {
kScriptTimeTicksPerSecond = (728L/10L),
};

struct CLICKAREA {
int n_points;
Point *points;
};

inline int ticksToMSec(int tick) {
return tick * 1000 / kScriptTimeTicksPerSecond;
}

class SagaEngine : public Engine {
void errorString(const char *buf_input, char *buf_output);

Expand Down

0 comments on commit ea3b0d1

Please sign in to comment.