More moving of stuff into classes

svn-id: r11025
This commit is contained in:
Torbjörn Andersson 2003-11-01 16:55:20 +00:00
parent 078091e7f4
commit 94edf540ef
12 changed files with 373 additions and 461 deletions

View File

@ -44,19 +44,13 @@
namespace Sword2 {
// stores resource id of wav to use as lead-out from smacker
static uint32 smackerLeadOut = 0;
int32 Animate(int32 *params, uint8 reverse_flag);
int32 Mega_table_animate(int32 *params, uint8 reverse_flag);
int32 Logic::fnAnim(int32 *params) {
// params: 0 pointer to object's logic structure
// 1 pointer to object's graphic structure
// 2 resource id of animation file
// 0 means normal forward anim
return Animate(params, 0);
return animate(params, false);
}
int32 Logic::fnReverseAnim(int32 *params) {
@ -65,7 +59,7 @@ int32 Logic::fnReverseAnim(int32 *params) {
// 2 resource id of animation file
// 1 means reverse anim
return Animate(params, 1);
return animate(params, true);
}
int32 Logic::fnMegaTableAnim(int32 *params) {
@ -75,7 +69,7 @@ int32 Logic::fnMegaTableAnim(int32 *params) {
// 3 pointer to animation table
// 0 means normal forward anim
return Mega_table_animate(params, 0);
return megaTableAnimate(params, false);
}
int32 Logic::fnReverseMegaTableAnim(int32 *params) {
@ -85,10 +79,10 @@ int32 Logic::fnReverseMegaTableAnim(int32 *params) {
// 3 pointer to animation table
// 1 means reverse anim
return Mega_table_animate(params, 1);
return megaTableAnimate(params, true);
}
int32 Animate(int32 *params, uint8 reverse_flag) {
int32 Logic::animate(int32 *params, bool reverse) {
// params: 0 pointer to object's logic structure
// 1 pointer to object's graphic structure
// 2 resource id of animation file
@ -153,7 +147,7 @@ int32 Animate(int32 *params, uint8 reverse_flag) {
#ifdef _SWORD2_DEBUG
// check that we haven't been passed a zero resource number
if (res == 0)
error("Animate: %s (id %d) passed zero anim resource", FetchObjectName(ID), ID);
error("animate: %s (id %d) passed zero anim resource", FetchObjectName(ID), ID);
#endif
// open anim file
@ -163,7 +157,7 @@ int32 Animate(int32 *params, uint8 reverse_flag) {
// check this this resource is actually an animation file!
head = (_standardHeader *) anim_file;
if (head->fileType != ANIMATION_FILE)
error("Animate: %s (%d) is not an anim!", FetchObjectName(res), res);
error("animate: %s (%d) is not an anim!", FetchObjectName(res), res);
#endif
// point to anim header
@ -172,14 +166,14 @@ int32 Animate(int32 *params, uint8 reverse_flag) {
/* #ifdef _SWORD2_DEBUG
// check there's at least one frame
if (anim_head->noAnimFrames == 0)
error("Animate: %s (%d) has zero frame count!", FetchObjectName(res), res);
error("animate: %s (%d) has zero frame count!", FetchObjectName(res), res);
#endif */
// now running an anim, looping back to this 'FN' call again
ob_logic->looping = 1;
ob_graphic->anim_resource = res;
if (reverse_flag)
if (reverse)
ob_graphic->anim_pc = anim_head->noAnimFrames - 1;
else
ob_graphic->anim_pc = 0;
@ -199,7 +193,7 @@ int32 Animate(int32 *params, uint8 reverse_flag) {
anim_file = res_man.open(ob_graphic->anim_resource);
anim_head = FetchAnimHeader(anim_file);
if (reverse_flag)
if (reverse)
ob_graphic->anim_pc--;
else
ob_graphic->anim_pc++;
@ -207,7 +201,7 @@ int32 Animate(int32 *params, uint8 reverse_flag) {
// check for end of anim
if (reverse_flag) {
if (reverse) {
if (ob_graphic->anim_pc == 0)
ob_logic->looping = 0;
} else {
@ -222,7 +216,7 @@ int32 Animate(int32 *params, uint8 reverse_flag) {
return ob_logic->looping ? IR_REPEAT : IR_STOP;
}
int32 Mega_table_animate(int32 *params, uint8 reverse_flag) {
int32 Logic::megaTableAnimate(int32 *params, bool reverse) {
// params: 0 pointer to object's logic structure
// 1 pointer to object's graphic structure
// 2 pointer to object's mega structure
@ -253,8 +247,8 @@ int32 Mega_table_animate(int32 *params, uint8 reverse_flag) {
// pars[2] only needed setting at the start of the anim
// call Animate() with these params
return Animate(pars, reverse_flag);
// call animate() with these params
return animate(pars, reverse);
}
int32 Logic::fnSetFrame(int32 *params) {
@ -462,66 +456,45 @@ int32 Logic::fnUnshadedSprite(int32 *params) {
// _wavHeader *speech;
// } _movieTextObject;
// FOR TEXT LINES IN SEQUENCE PLAYER
#define MAX_SEQUENCE_TEXT_LINES 15
typedef struct {
uint32 textNumber;
uint16 startFrame;
uint16 endFrame;
mem *text_mem;
uint32 speechBufferSize;
uint16 *speech_mem;
} _sequenceTextInfo;
// keeps count of number of text lines to disaply during the sequence
static uint32 sequenceTextLines = 0;
static _sequenceTextInfo sequence_text_list[MAX_SEQUENCE_TEXT_LINES];
int32 Logic::fnAddSequenceText(int32 *params) {
// params: 0 text number
// 1 frame number to start the text displaying
// 2 frame number to stop the text dispalying
// params: 0 text number
// 1 frame number to start the text displaying
// 2 frame number to stop the text dispalying
#ifdef _SWORD2_DEBUG
if (sequenceTextLines == MAX_SEQUENCE_TEXT_LINES)
error("fnAddSequenceText ran out of lines");
#endif
assert(_sequenceTextLines < MAX_SEQUENCE_TEXT_LINES);
sequence_text_list[sequenceTextLines].textNumber = params[0];
sequence_text_list[sequenceTextLines].startFrame = params[1];
sequence_text_list[sequenceTextLines].endFrame = (uint16) params[2];
sequenceTextLines++;
_sequenceTextList[_sequenceTextLines].textNumber = params[0];
_sequenceTextList[_sequenceTextLines].startFrame = params[1];
_sequenceTextList[_sequenceTextLines].endFrame = (uint16) params[2];
_sequenceTextLines++;
// continue script
return IR_CONT;
}
void CreateSequenceSpeech(_movieTextObject *sequenceText[]) {
void Logic::createSequenceSpeech(_movieTextObject *sequenceText[]) {
uint32 line;
_frameHeader *frame;
uint32 local_text;
uint32 text_res;
uint8 *text;
uint32 wavId; // ie. offical text number (actor text number)
uint8 speechRunning;
bool speechRunning;
char speechFile[256];
// for each sequence text line that's been logged
for (line = 0; line < sequenceTextLines; line++) {
for (line = 0; line < _sequenceTextLines; line++) {
// allocate this structure
sequenceText[line] = new _movieTextObject;
sequenceText[line]->startFrame = sequence_text_list[line].startFrame;
sequenceText[line]->endFrame = sequence_text_list[line].endFrame;
sequenceText[line]->startFrame = _sequenceTextList[line].startFrame;
sequenceText[line]->endFrame = _sequenceTextList[line].endFrame;
// pull out the text line to get the official text number
// (for wav id)
text_res = sequence_text_list[line].textNumber / SIZE;
local_text = sequence_text_list[line].textNumber & 0xffff;
text_res = _sequenceTextList[line].textNumber / SIZE;
local_text = _sequenceTextList[line].textNumber & 0xffff;
// open text resource & get the line
text = FetchTextLine(res_man.open(text_res), local_text);
@ -536,8 +509,8 @@ void CreateSequenceSpeech(_movieTextObject *sequenceText[]) {
// is it to be speech or subtitles or both?
// assume speech is not running until know otherwise
speechRunning = 0;
sequence_text_list[line].speech_mem = NULL;
speechRunning = false;
_sequenceTextList[line].speech_mem = NULL;
sequenceText[line]->speech = NULL;
if (!g_sound->isSpeechMute()) {
@ -556,10 +529,10 @@ void CreateSequenceSpeech(_movieTextObject *sequenceText[]) {
else
strcpy(speechFile, "speech.clu");
sequence_text_list[line].speechBufferSize = g_sound->preFetchCompSpeech((char *) speechFile, wavId, &sequence_text_list[line].speech_mem);
if (sequence_text_list[line].speechBufferSize) {
_sequenceTextList[line].speechBufferSize = g_sound->preFetchCompSpeech((char *) speechFile, wavId, &_sequenceTextList[line].speech_mem);
if (_sequenceTextList[line].speechBufferSize) {
// ok, we've got speech!
speechRunning = 1;
speechRunning = true;
}
}
@ -578,33 +551,33 @@ void CreateSequenceSpeech(_movieTextObject *sequenceText[]) {
// When rendering text over a sequence we need a
// different colour for the border.
sequence_text_list[line].text_mem = fontRenderer.makeTextSprite(text + 2, 600, 255, g_sword2->_speechFontId, 1);
_sequenceTextList[line].text_mem = fontRenderer.makeTextSprite(text + 2, 600, 255, g_sword2->_speechFontId, 1);
// ok to close the text resource now
res_man.close(text_res);
} else {
sequence_text_list[line].text_mem = NULL;
_sequenceTextList[line].text_mem = NULL;
sequenceText[line]->textSprite = NULL;
}
}
// for drivers: NULL-terminate the array of pointers to
// _movieTextObject's
sequenceText[sequenceTextLines] = NULL;
sequenceText[_sequenceTextLines] = NULL;
// now lock all the memory blocks containing text sprites & speech
// samples and set up the pointers to them, etc, for the drivers
for (line = 0; line < sequenceTextLines; line++) {
for (line = 0; line < _sequenceTextLines; line++) {
// if we've made a text sprite for this line...
if (sequence_text_list[line].text_mem) {
memory.lockMemory(sequence_text_list[line].text_mem);
if (_sequenceTextList[line].text_mem) {
memory.lockMemory(_sequenceTextList[line].text_mem);
// now fill out the _spriteInfo structure in the
// _movieTextObjectStructure
frame = (_frameHeader *) sequence_text_list[line].text_mem->ad;
frame = (_frameHeader *) _sequenceTextList[line].text_mem->ad;
sequenceText[line]->textSprite = new _spriteInfo;
@ -614,39 +587,39 @@ void CreateSequenceSpeech(_movieTextObject *sequenceText[]) {
sequenceText[line]->textSprite->w = frame->width;
sequenceText[line]->textSprite->h = frame->height;
sequenceText[line]->textSprite->type = RDSPR_DISPLAYALIGN | RDSPR_NOCOMPRESSION;
sequenceText[line]->textSprite->data = sequence_text_list[line].text_mem->ad + sizeof(_frameHeader);
sequenceText[line]->textSprite->data = _sequenceTextList[line].text_mem->ad + sizeof(_frameHeader);
}
// if we've loaded a speech sample for this line...
if (sequence_text_list[line].speech_mem) {
if (_sequenceTextList[line].speech_mem) {
// for drivers: set up pointer to decompressed wav in
// memory
sequenceText[line]->speechBufferSize = sequence_text_list[line].speechBufferSize;
sequenceText[line]->speech = sequence_text_list[line].speech_mem;
sequenceText[line]->speechBufferSize = _sequenceTextList[line].speechBufferSize;
sequenceText[line]->speech = _sequenceTextList[line].speech_mem;
}
}
}
void ClearSequenceSpeech(_movieTextObject *textSprites[]) {
void Logic::clearSequenceSpeech(_movieTextObject *sequenceText[]) {
uint32 line;
for (line = 0; line < sequenceTextLines; line++) {
for (line = 0; line < _sequenceTextLines; line++) {
// free up the memory used by this _movieTextObject
delete textSprites[line];
delete sequenceText[line];
// free up the mem block containing this text sprite
if (sequence_text_list[line].text_mem)
memory.freeMemory(sequence_text_list[line].text_mem);
if (_sequenceTextList[line].text_mem)
memory.freeMemory(_sequenceTextList[line].text_mem);
// free up the mem block containing this speech sample
if (sequence_text_list[line].speech_mem)
free(sequence_text_list[line].speech_mem);
if (_sequenceTextList[line].speech_mem)
free(_sequenceTextList[line].speech_mem);
}
// IMPORTANT! Reset the line count ready for the next sequence!
sequenceTextLines = 0;
_sequenceTextLines = 0;
}
int32 Logic::fnSmackerLeadIn(int32 *params) {
@ -686,7 +659,7 @@ int32 Logic::fnSmackerLeadOut(int32 *params) {
// params: 0 id of lead-out music
// ready for use in fnPlaySequence
smackerLeadOut = params[0];
_smackerLeadOut = params[0];
// continue script
return IR_CONT;
@ -727,16 +700,16 @@ int32 Logic::fnPlaySequence(int32 *params) {
// now create the text sprites, if any
if (sequenceTextLines)
CreateSequenceSpeech(sequenceSpeechArray);
if (_sequenceTextLines)
createSequenceSpeech(sequenceSpeechArray);
// open the lead-out music resource, if there is one
if (smackerLeadOut) {
leadOut = res_man.open(smackerLeadOut);
if (_smackerLeadOut) {
leadOut = res_man.open(_smackerLeadOut);
#ifdef _SWORD2_DEBUG
header = (_standardHeader *)leadOut;
header = (_standardHeader *) leadOut;
if (header->fileType != WAV_FILE)
error("fnSmackerLeadOut() given invalid resource");
#endif
@ -754,7 +727,7 @@ int32 Logic::fnPlaySequence(int32 *params) {
MoviePlayer player;
if (sequenceTextLines && !(g_sword2->_features & GF_DEMO))
if (_sequenceTextLines && !(g_sword2->_features & GF_DEMO))
rv = player.play(filename, sequenceSpeechArray, leadOut);
else
rv = player.play(filename, NULL, leadOut);
@ -764,9 +737,9 @@ int32 Logic::fnPlaySequence(int32 *params) {
// close the lead-out music resource
if (smackerLeadOut) {
res_man.close(smackerLeadOut);
smackerLeadOut = 0;
if (_smackerLeadOut) {
res_man.close(_smackerLeadOut);
_smackerLeadOut = 0;
}
// check the error return-value
@ -775,8 +748,8 @@ int32 Logic::fnPlaySequence(int32 *params) {
// now clear the text sprites, if any
if (sequenceTextLines)
ClearSequenceSpeech(sequenceSpeechArray);
if (_sequenceTextLines)
clearSequenceSpeech(sequenceSpeechArray);
// now clear the screen in case the Sequence was quitted (using ESC)
// rather than fading down to black

View File

@ -38,85 +38,17 @@
namespace Sword2 {
// ---------------------------------------------------------------------------
buildit bgp0_list[MAX_bgp0_sprites];
buildit bgp1_list[MAX_bgp1_sprites];
buildit back_list[MAX_back_sprites];
buildit sort_list[MAX_sort_sprites];
buildit fore_list[MAX_fore_sprites];
buildit fgp0_list[MAX_fgp0_sprites];
buildit fgp1_list[MAX_fgp1_sprites];
// holds the order of the sort list
// i.e the list stays static and we sort this
uint16 sort_order[MAX_sort_sprites];
uint32 cur_bgp0;
uint32 cur_bgp1;
uint32 cur_back;
uint32 cur_sort;
uint32 cur_fore;
uint32 cur_fgp0;
uint32 cur_fgp1;
uint32 largest_layer_area = 0; // should be reset to zero at start of each screen change
uint32 largest_sprite_area = 0; // - " -
char largest_layer_info[128] = { "largest layer: none registered" };
char largest_sprite_info[128] = { "largest sprite: none registered" };
// ---------------------------------------------------------------------------
// last palette used - so that we can restore the correct one after a pause
// (which dims the screen) and it's not always the main screen palette that we
// want, eg. during the eclipse
// This flag gets set in Start_new_palette() and SetFullPalette()
uint32 lastPaletteRes = 0;
// ---------------------------------------------------------------------------
// 'frames per second' counting stuff
uint32 fps = 0;
uint32 cycleTime = 0;
uint32 frameCount = 0;
// So I know if the control Panel can be activated - CJR 1-5-97
extern uint32 mouse_status;
// ---------------------------------------------------------------------------
// function prototypes not needed externally
void Start_new_palette(void);
void Register_frame(int32 *params, buildit *build_unit);
void Process_layer(uint32 layer_number);
void Sort_the_sort_list(void);
void Send_back_par0_frames(void);
void Send_back_par1_frames(void);
void Send_back_frames(void);
void Send_sort_frames(void);
void Send_fore_frames(void);
void Send_fore_par0_frames(void);
void Send_fore_par1_frames(void);
// ---------------------------------------------------------------------------
//
// PC Build_display
//
// ---------------------------------------------------------------------------
void Build_display(void) {
void Sword2Engine::buildDisplay(void) {
uint8 *file;
_multiScreenHeader *screenLayerTable;
if (this_screen.new_palette) {
// start the layer palette fading up
Start_new_palette();
startNewPalette();
largest_layer_area = 0; // should be reset to zero at start of each screen change
largest_sprite_area = 0; // - " -
// should be reset to zero at start of each screen change
_largestLayerArea = 0;
_largestSpriteArea = 0;
}
// there is a valid screen to run
@ -148,7 +80,7 @@ void Build_display(void) {
// release the screen resource before cacheing
// the sprites
res_man.close(this_screen.background_layer_id);
Send_back_par0_frames();
sendBackPar0Frames();
} else {
// release the screen resource
res_man.close(this_screen.background_layer_id);
@ -165,7 +97,7 @@ void Build_display(void) {
// release the screen resource before cacheing
// the sprites
res_man.close(this_screen.background_layer_id);
Send_back_par1_frames();
sendBackPar1Frames();
} else {
// release the screen resource
res_man.close(this_screen.background_layer_id);
@ -181,10 +113,10 @@ void Build_display(void) {
// sprites & layers
Send_back_frames(); // background sprites
Sort_the_sort_list();
Send_sort_frames(); // sorted sprites & layers
Send_fore_frames(); // foreground sprites
sendBackFrames(); // background sprites
sortTheSortList();
sendSortFrames(); // sorted sprites & layers
sendForeFrames(); // foreground sprites
// first foreground parallax + related anims
@ -197,7 +129,7 @@ void Build_display(void) {
// release the screen resource before cacheing
// the sprites
res_man.close(this_screen.background_layer_id);
Send_fore_par0_frames();
sendForePar0Frames();
} else {
// release the screen resource
res_man.close(this_screen.background_layer_id);
@ -214,7 +146,7 @@ void Build_display(void) {
// release the screen resource before cacheing
// the sprites
res_man.close(this_screen.background_layer_id);
Send_fore_par1_frames();
sendForePar1Frames();
} else {
// release the screen resource
res_man.close(this_screen.background_layer_id);
@ -240,12 +172,12 @@ void Build_display(void) {
// update our fps reading
frameCount++;
if (SVM_timeGetTime() > cycleTime) {
fps = frameCount;
debug(2, "FPS: %d", fps);
frameCount = 0;
cycleTime = SVM_timeGetTime() + 1000;
_frameCount++;
if (SVM_timeGetTime() > _cycleTime) {
_fps = _frameCount;
debug(2, "FPS: %d", _fps);
_frameCount = 0;
_cycleTime = SVM_timeGetTime() + 1000;
}
// Check if we've got time to render the screen again
@ -261,12 +193,11 @@ void Build_display(void) {
}
}
// ---------------------------------------------------------------------------
//
// Fades down and displays a message on the screen for time seconds
//
void DisplayMsg(uint8 *text, int time) {
void Sword2Engine::displayMsg(uint8 *text, int time) {
mem *text_spr;
_frameHeader *frame;
_spriteInfo spriteInfo;
@ -336,16 +267,13 @@ void DisplayMsg(uint8 *text, int time) {
g_display->setPalette(0, 256, (uint8 *) oldPal, RDPAL_FADE);
}
// ---------------------------------------------------------------------------
//
// Fades message down and removes it, fading up again afterwards
//
void RemoveMsg(void) {
void Sword2Engine::removeMsg(void) {
g_display->fadeDown();
g_display->waitForFade();
g_display->clearScene();
// g_display->fadeUp();
@ -355,71 +283,71 @@ void RemoveMsg(void) {
// this routine to clean up!
}
void Send_back_par0_frames(void) {
void Sword2Engine::sendBackPar0Frames(void) {
// could be none at all - theoretically at least
for (uint i = 0; i < cur_bgp0; i++) {
for (uint i = 0; i < _curBgp0; i++) {
// frame attached to 1st background parallax
Process_image(&bgp0_list[i]);
processImage(&_bgp0List[i]);
}
}
void Send_back_par1_frames(void) {
void Sword2Engine::sendBackPar1Frames(void) {
// could be none at all - theoretically at least
for (uint i = 0; i < cur_bgp1; i++) {
for (uint i = 0; i < _curBgp1; i++) {
// frame attached to 2nd background parallax
Process_image(&bgp1_list[i]);
processImage(&_bgp1List[i]);
}
}
void Send_back_frames(void) {
void Sword2Engine::sendBackFrames(void) {
// could be none at all - theoretically at least
for (uint i = 0; i < cur_back; i++) {
Process_image(&back_list[i]);
for (uint i = 0; i < _curBack; i++) {
processImage(&_backList[i]);
}
}
void Send_sort_frames(void) {
void Sword2Engine::sendSortFrames(void) {
// send the sort frames for printing - layers, shrinkers & normal flat
// sprites
// could be none at all - theoretically at least
for (uint i = 0; i < cur_sort; i++) {
if (sort_list[sort_order[i]].layer_number) {
for (uint i = 0; i < _curSort; i++) {
if (_sortList[_sortOrder[i]].layer_number) {
// its a layer - minus 1 for true layer number
// we need to know from the buildit because the layers
// will have been sorted in random order
Process_layer(sort_list[sort_order[i]].layer_number - 1);
processLayer(_sortList[_sortOrder[i]].layer_number - 1);
} else {
// sprite
Process_image(&sort_list[sort_order[i]]);
processImage(&_sortList[_sortOrder[i]]);
}
}
}
void Send_fore_frames(void) {
void Sword2Engine::sendForeFrames(void) {
// could be none at all - theoretically at least
for (uint i = 0; i < cur_fore; i++) {
Process_image(&fore_list[i]);
for (uint i = 0; i < _curFore; i++) {
processImage(&_foreList[i]);
}
}
void Send_fore_par0_frames(void) {
void Sword2Engine::sendForePar0Frames(void) {
// could be none at all - theoretically at least
for (uint i = 0; i < cur_fgp0; i++) {
for (uint i = 0; i < _curFgp0; i++) {
// frame attached to 1st foreground parallax
Process_image(&fgp0_list[i]);
processImage(&_fgp0List[i]);
}
}
void Send_fore_par1_frames(void) {
void Sword2Engine::sendForePar1Frames(void) {
// could be none at all - theoretically at least
for (uint i = 0; i < cur_fgp1; i++) {
for (uint i = 0; i < _curFgp1; i++) {
// frame attached to 2nd foreground parallax
Process_image(&fgp1_list[i]);
processImage(&_fgp1List[i]);
}
}
void Process_layer(uint32 layer_number) {
void Sword2Engine::processLayer(uint32 layer_number) {
uint8 *file;
_layerHeader *layer_head;
_spriteInfo spriteInfo;
@ -445,22 +373,18 @@ void Process_layer(uint32 layer_number) {
spriteInfo.data = file + sizeof(_standardHeader) + layer_head->offset;
spriteInfo.colourTable = 0;
//------------------------------------------
// check for largest layer for debug info
current_layer_area = layer_head->width * layer_head->height;
if (current_layer_area > largest_layer_area) {
largest_layer_area = current_layer_area;
sprintf(largest_layer_info,
if (current_layer_area > _largestLayerArea) {
_largestLayerArea = current_layer_area;
sprintf(_largestLayerInfo,
"largest layer: %s layer(%d) is %dx%d",
FetchObjectName(this_screen.background_layer_id),
layer_number, layer_head->width, layer_head->height);
}
//------------------------------------------
rv = g_display->drawSprite(&spriteInfo);
if (rv)
error("Driver Error %.8x in Process_layer(%d)", rv, layer_number);
@ -468,7 +392,7 @@ void Process_layer(uint32 layer_number) {
res_man.close(this_screen.background_layer_id);
}
void Process_image(buildit *build_unit) {
void Sword2Engine::processImage(buildit *build_unit) {
uint8 *file, *colTablePtr = NULL;
_animHeader *anim_head;
_frameHeader *frame_head;
@ -529,7 +453,7 @@ void Process_image(buildit *build_unit) {
// if we want this frame to be affected by the shading mask,
// add the status bit
if (build_unit->shadingFlag == 1)
if (build_unit->shadingFlag)
spriteType |= RDSPR_SHADOW;
spriteInfo.x = build_unit->x;
@ -545,14 +469,13 @@ void Process_image(buildit *build_unit) {
spriteInfo.data = (uint8 *) (frame_head + 1);
spriteInfo.colourTable = colTablePtr;
//------------------------------------------
// check for largest layer for debug info
current_sprite_area = frame_head->width * frame_head->height;
if (current_sprite_area > largest_sprite_area) {
largest_sprite_area = current_sprite_area;
sprintf(largest_sprite_info,
if (current_sprite_area > _largestSpriteArea) {
_largestSpriteArea = current_sprite_area;
sprintf(_largestSpriteInfo,
"largest sprite: %s frame(%d) is %dx%d",
FetchObjectName(build_unit->anim_resource),
build_unit->anim_pc,
@ -560,7 +483,6 @@ void Process_image(buildit *build_unit) {
frame_head->height);
}
#ifdef _SWORD2_DEBUG
if (SYSTEM_TESTING_ANIMS) { // see anims.cpp
// bring the anim into the visible screen
// but leave extra pixel at edge for box
@ -582,7 +504,6 @@ void Process_image(buildit *build_unit) {
rect_x2 = spriteInfo.x + spriteInfo.scaledWidth;
rect_y2 = spriteInfo.y + spriteInfo.scaledHeight;
}
#endif
// #ifdef _SWORD2_DEBUG
// if (frame_head->width <= 1) {
@ -592,7 +513,7 @@ void Process_image(buildit *build_unit) {
rv = g_display->drawSprite(&spriteInfo);
if (rv)
error("Driver Error %.8x with sprite %s (%d) in Process_image",
error("Driver Error %.8x with sprite %s (%d) in processImage",
rv, FetchObjectName(build_unit->anim_resource),
build_unit->anim_resource);
@ -600,45 +521,45 @@ void Process_image(buildit *build_unit) {
res_man.close(build_unit->anim_resource);
}
void Reset_render_lists(void) {
void Sword2Engine::resetRenderLists(void) {
// reset the sort lists - do this before a logic loop
// takes into account the fact that the start of the list is pre-built
// with the special sortable layers
cur_bgp0 = 0;
cur_bgp1 = 0;
cur_back = 0;
_curBgp0 = 0;
_curBgp1 = 0;
_curBack = 0;
// beginning of sort list is setup with the special sort layers
cur_sort = this_screen.number_of_layers;
cur_fore = 0;
cur_fgp0 = 0;
cur_fgp1 = 0;
_curSort = this_screen.number_of_layers;
_curFore = 0;
_curFgp0 = 0;
_curFgp1 = 0;
if (cur_sort) {
if (_curSort) {
// there are some layers - so rebuild the sort order
// positioning
for (uint i = 0; i < cur_sort; i++)
sort_order[i] = i; //rebuild the order list
for (uint i = 0; i < _curSort; i++)
_sortOrder[i] = i; //rebuild the order list
}
}
void Sort_the_sort_list(void) {
//sort the list
void Sword2Engine::sortTheSortList(void) {
// sort the list
//cannot bubble sort 0 or 1 items!
if (cur_sort <= 1)
// cannot bubble sort 0 or 1 items!
if (_curSort <= 1)
return;
for (uint i = 0; i < cur_sort - 1; i++) {
for (uint j = 0; j < cur_sort - 1; j++) {
if (sort_list[sort_order[j]].sort_y > sort_list[sort_order[j + 1]].sort_y) {
SWAP(sort_order[j], sort_order[j + 1]);
for (uint i = 0; i < _curSort - 1; i++) {
for (uint j = 0; j < _curSort - 1; j++) {
if (_sortList[_sortOrder[j]].sort_y > _sortList[_sortOrder[j + 1]].sort_y) {
SWAP(_sortOrder[j], _sortOrder[j + 1]);
}
}
}
}
void Register_frame(int32 *params, buildit *build_unit) {
void Sword2Engine::registerFrame(int32 *params, buildit *build_unit) {
// params: 0 pointer to mouse structure or NULL for no write to mouse
// list (non-zero means write sprite-shape to mouse list)
// 1 pointer to graphic structure
@ -653,15 +574,11 @@ void Register_frame(int32 *params, buildit *build_unit) {
_cdtEntry *cdt_entry;
int scale = 0;
//-------------------------------------------
// open animation file & set up the necessary pointers
ob_graph = (Object_graphic *) params[1];
#ifdef _SWORD2_DEBUG
if (ob_graph->anim_resource == 0)
error("ERROR: %s(%d) has no anim resource in Register_frame", FetchObjectName(ID), ID);
#endif
assert(ob_graph->anim_resource);
file = res_man.open(ob_graph->anim_resource);
@ -669,7 +586,6 @@ void Register_frame(int32 *params, buildit *build_unit) {
cdt_entry = FetchCdtEntry(file, ob_graph->anim_pc);
frame_head = FetchFrameHeader(file, ob_graph->anim_pc);
#ifdef _SWORD2_DEBUG
// update player graphic details for on-screen debug info
if (ID == CUR_PLAYER_ID) {
playerGraphic.type = ob_graph->type;
@ -678,25 +594,22 @@ void Register_frame(int32 *params, buildit *build_unit) {
playerGraphic.anim_pc = ob_graph->anim_pc + 1;
player_graphic_no_frames = anim_head->noAnimFrames;
}
#endif
//-------------------------------------------
// fill in the buildit structure for this frame
//retrieve the resource
// retrieve the resource
build_unit->anim_resource = ob_graph->anim_resource;
//retrieve the frame
// retrieve the frame
build_unit->anim_pc = ob_graph->anim_pc;
//not a layer
// not a layer
build_unit->layer_number = 0;
// Affected by shading mask?
if (ob_graph->type & SHADED_SPRITE)
build_unit->shadingFlag = 1;
build_unit->shadingFlag = true;
else
build_unit->shadingFlag = 0;
build_unit->shadingFlag = false;
//-------------------------------------------
// check if this frame has offsets ie. this is a scalable mega frame
if (cdt_entry->frameType & FRAME_OFFSET) {
@ -746,10 +659,7 @@ void Register_frame(int32 *params, buildit *build_unit) {
// only if 'pointer' isn't NULL
if (ob_mouse->pointer) {
#ifdef _SWORD2_DEBUG
if (cur_mouse == TOTAL_mouse_list)
error("ERROR: mouse_list full");
#endif
assert(cur_mouse < TOTAL_mouse_list);
mouse_list[cur_mouse].x1 = build_unit->x;
mouse_list[cur_mouse].y1 = build_unit->y;
@ -792,73 +702,49 @@ int32 Logic::fnRegisterFrame(int32 *params) {
// 1 pointer to graphic structure
// 2 pointer to mega structure or NULL if not a mega
return g_sword2->registerFrame(params);
}
int32 Sword2Engine::registerFrame(int32 *params) {
Object_graphic *ob_graph = (Object_graphic *) params[1];
// check low word for sprite type
switch (ob_graph->type & 0x0000ffff) {
case BGP0_SPRITE:
#ifdef _SWORD2_DEBUG
if (cur_bgp0 == MAX_bgp0_sprites)
error("ERROR: bgp0_list full in fnRegisterFrame");
#endif
Register_frame(params, &bgp0_list[cur_bgp0]);
cur_bgp0++;
assert(_curBgp0 < MAX_bgp0_sprites);
registerFrame(params, &_bgp0List[_curBgp0]);
_curBgp0++;
break;
case BGP1_SPRITE:
#ifdef _SWORD2_DEBUG
if (cur_bgp1 == MAX_bgp1_sprites)
error("ERROR: bgp1_list full in fnRegisterFrame");
#endif
Register_frame(params, &bgp1_list[cur_bgp1]);
cur_bgp1++;
assert(_curBgp1 < MAX_bgp1_sprites);
registerFrame(params, &_bgp1List[_curBgp1]);
_curBgp1++;
break;
case BACK_SPRITE:
#ifdef _SWORD2_DEBUG
if (cur_back == MAX_back_sprites)
error("ERROR: back_list full in fnRegisterFrame");
#endif
Register_frame(params, &back_list[cur_back]);
cur_back++;
assert(_curBack < MAX_back_sprites);
registerFrame(params, &_backList[_curBack]);
_curBack++;
break;
case SORT_SPRITE:
#ifdef _SWORD2_DEBUG
if (cur_sort == MAX_sort_sprites)
error("ERROR: sort_list full in fnRegisterFrame");
#endif
sort_order[cur_sort] = cur_sort;
Register_frame(params, &sort_list[cur_sort]);
cur_sort++;
assert(_curSort < MAX_sort_sprites);
_sortOrder[_curSort] = _curSort;
registerFrame(params, &_sortList[_curSort]);
_curSort++;
break;
case FORE_SPRITE:
#ifdef _SWORD2_DEBUG
if (cur_fore == MAX_fore_sprites)
error("ERROR: fore_list full in fnRegisterFrame");
#endif
Register_frame(params, &fore_list[cur_fore]);
cur_fore++;
assert(_curFore < MAX_fore_sprites);
registerFrame(params, &_foreList[_curFore]);
_curFore++;
break;
case FGP0_SPRITE:
#ifdef _SWORD2_DEBUG
if (cur_fgp0 == MAX_fgp0_sprites)
error("ERROR: fgp0_list full in fnRegisterFrame");
#endif
Register_frame(params, &fgp0_list[cur_fgp0]);
cur_fgp0++;
assert(_curFgp0 < MAX_fgp0_sprites);
registerFrame(params, &_fgp0List[_curFgp0]);
_curFgp0++;
break;
case FGP1_SPRITE:
#ifdef _SWORD2_DEBUG
if (cur_fgp1 == MAX_fgp1_sprites)
error("ERROR: fgp1_list full in fnRegisterFrame");
#endif
Register_frame(params, &fgp1_list[cur_fgp1]);
cur_fgp1++;
assert(_curFgp1 < MAX_fgp1_sprites);
registerFrame(params, &_fgp1List[_curFgp1]);
_curFgp1++;
break;
default:
// NO_SPRITE no registering!
@ -868,8 +754,8 @@ int32 Logic::fnRegisterFrame(int32 *params) {
return IR_CONT;
}
void Start_new_palette(void) {
//start layer palette fading up
void Sword2Engine::startNewPalette(void) {
// start layer palette fading up
uint8 *screenFile;
@ -885,7 +771,7 @@ void Start_new_palette(void) {
g_display->setPalette(0, 256, FetchPalette(screenFile), RDPAL_FADE);
// indicating that it's a screen palette
lastPaletteRes = 0;
_lastPaletteRes = 0;
// close screen file
res_man.close(this_screen.background_layer_id);
@ -942,35 +828,18 @@ int32 Logic::fnFadeUp(int32 *params) {
return IR_CONT;
}
// ---------------------------------------------------------------------------
// typedef struct {
// uint8 red;
// uint8 green;
// uint8 blue;
// uint8 alpha;
// } _palEntry;
// ---------------------------------------------------------------------------
// typedef struct {
// // first colour number in this palette (0..255)
// uint8 firstEntry;
// // number of Entries-1 (0..255) to be taken as (1..256)
// uint8 noEntries;
// } _paletteHeader;
int32 Logic::fnSetPalette(int32 *params) {
// params: 0 resource number of palette file, or 0 if it's to be
// the palette from the current screen
SetFullPalette(params[0]);
g_sword2->setFullPalette(params[0]);
return IR_CONT;
}
void SetFullPalette(int32 palRes) {
void Sword2Engine::setFullPalette(int32 palRes) {
uint8 *file;
_standardHeader *head;
//----------------------------------
// fudge for hut interior
// - unpausing should restore last palette as normal (could be screen
// palette or 'dark_palette_13')
@ -983,7 +852,7 @@ void SetFullPalette(int32 palRes) {
if (palRes == -1) {
// restore whatever palette was last set (screen
// palette or 'dark_palette_13')
palRes = lastPaletteRes;
palRes = _lastPaletteRes;
}
} else {
// check if we're just restoring the current screen palette
@ -996,20 +865,16 @@ void SetFullPalette(int32 palRes) {
palRes = 0;
}
if (palRes == 0 && lastPaletteRes)
palRes = lastPaletteRes;
if (palRes == 0 && _lastPaletteRes)
palRes = _lastPaletteRes;
}
//----------------------------------
// non-zero: set palette to this separate palette file
if (palRes) {
// open the palette file
head = (_standardHeader *) res_man.open(palRes);
#ifdef _SWORD2_DEBUG
if (head->fileType != PALETTE_FILE)
error("fnSetPalette() called with invalid resource!");
#endif
assert(head->fileType == PALETTE_FILE);
file = (uint8 *) (head + 1);
@ -1029,7 +894,7 @@ void SetFullPalette(int32 palRes) {
if (palRes != CONTROL_PANEL_PALETTE) { // (James 03sep97)
// indicating that it's a separate palette resource
lastPaletteRes = palRes;
_lastPaletteRes = palRes;
}
// close palette file
@ -1044,12 +909,12 @@ void SetFullPalette(int32 palRes) {
g_display->setPalette(0, 256, FetchPalette(file), RDPAL_INSTANT);
// indicating that it's a screen palette
lastPaletteRes = 0;
_lastPaletteRes = 0;
// close screen file
res_man.close(this_screen.background_layer_id);
} else
error("fnSetPalette(0) called, but no current screen available!");
error("setFullPalette(0) called, but no current screen available!");
}
}
@ -1061,11 +926,9 @@ int32 Logic::fnRestoreGame(int32 *params) {
int32 Logic::fnChangeShadows(int32 *params) {
// params: none
uint32 rv;
// if last screen was using a shading mask (see below)
if (this_screen.mask_flag) {
rv = g_display->closeLightMask();
uint32 rv = g_display->closeLightMask();
if (rv)
error("Driver Error %.8x [%s line %u]", rv);

View File

@ -20,82 +20,15 @@
#ifndef _BUILD_DISPLAY
#define _BUILD_DISPLAY
#include "sword2/driver/driver96.h"
#define MAX_bgp0_sprites 6
#define MAX_bgp1_sprites 6
#define MAX_back_sprites 30
#define MAX_sort_sprites 30
#define MAX_fore_sprites 30
#define MAX_fgp0_sprites 6
#define MAX_fgp1_sprites 6
namespace Sword2 {
// structure filled out by each object to register its graphic printing
// requrements
typedef struct {
int16 x;
int16 y;
uint16 scaled_width;
uint16 scaled_height;
int16 sort_y;
uint32 anim_resource;
uint16 anim_pc;
// denotes a scaling sprite at print time - and holds the scaling
// value for the shrink routine
uint16 scale;
// non zero means this item is a layer - retrieve from background
// layer and send to special renderer
uint16 layer_number;
// non zero means we want this frame to be affected by the shading mask
uint8 shadingFlag;
// if none zero the shrinker should write coordinates to this
// mouse_list number
// uint32 write_mouse_list;
} buildit;
// declared externally so that debug.cpp can display these in the info
#define MAX_bgp0_sprites 6
#define MAX_bgp1_sprites 6
#define MAX_back_sprites 30
#define MAX_sort_sprites 30
#define MAX_fore_sprites 30
#define MAX_fgp0_sprites 6
#define MAX_fgp1_sprites 6
// declared externally so that debug.cpp can display these in the info
extern uint32 cur_bgp0;
extern uint32 cur_bgp1;
extern uint32 cur_back;
extern uint32 cur_sort;
extern uint32 cur_fore;
extern uint32 cur_fgp0;
extern uint32 cur_fgp1;
extern char largest_layer_info[128];
extern char largest_sprite_info[128];
// the only build list needed externally - by layers.cpp - for adding layers
// to sort list
extern buildit sort_list[];
// function prototypes needed externally
void Reset_render_lists(void);
void Build_display(void);
void Process_image(buildit *build_unit);
void DisplayMsg( uint8 *text, int time );
void RemoveMsg(void);
void SetFullPalette(int32 palRes);
// needed by debug.cpp for displaying as part of top-screen info
extern uint32 fps;
} // End of namespace Sword2
#endif

View File

@ -323,7 +323,7 @@ private:
public:
Dialog() : _numWidgets(0), _finish(false), _result(0) {
SetFullPalette(CONTROL_PANEL_PALETTE);
g_sword2->setFullPalette(CONTROL_PANEL_PALETTE);
}
virtual ~Dialog() {
@ -1293,7 +1293,7 @@ public:
// Reset the graphic 'buildit' list before a
// new logic list (see fnRegisterFrame)
Reset_render_lists();
g_sword2->resetRenderLists();
// Reset the mouse hot-spot list (see
// fnRegisterMouse and fnRegisterFrame)
@ -1310,7 +1310,7 @@ public:
void SaveLoadDialog::saveLoadError(char* text) {
// Print a message on screen. Second parameter is duration.
DisplayMsg((uint8 *) text, 0);
g_sword2->displayMsg((uint8 *) text, 0);
// Wait for ESC or mouse click
while (1) {
@ -1334,7 +1334,7 @@ void SaveLoadDialog::saveLoadError(char* text) {
}
// Remove the message.
RemoveMsg();
g_sword2->removeMsg();
}
Gui::Gui() : _baseSlot(0) {
@ -1469,7 +1469,7 @@ void Gui::restartControl(void) {
// reset the graphic 'buildit' list before a new logic list
// (see fnRegisterFrame)
Reset_render_lists();
g_sword2->resetRenderLists();
// reset the mouse hot-spot list (see fnRegisterMouse and
// fnRegisterFrame)

View File

@ -21,7 +21,6 @@
#include "sword2/driver/driver96.h"
#include "sword2/sword2.h"
#include "sword2/debug.h"
#include "sword2/build_display.h" // for 'fps'
#include "sword2/console.h"
#include "sword2/defs.h"
#include "sword2/events.h" // for CountEvents()
@ -33,7 +32,7 @@
#include "sword2/resman.h"
#include "sword2/router.h" // for plotWalkGrid()
#include "sword2/speech.h" // for 'officialTextNumber' and
// 'speechScriptWaiting'
// 'speechScriptWaiting'
namespace Sword2 {
@ -263,7 +262,7 @@ void Build_debug_text(void) {
// frames-per-second counter
sprintf(buf, "fps %d", fps);
sprintf(buf, "fps %d", g_sword2->_fps);
Make_debug_text_block(buf, 440, 0);
// location number
@ -283,32 +282,32 @@ void Build_debug_text(void) {
// sprite list usage
sprintf(buf, "bgp0: %d/%d", cur_bgp0, MAX_bgp0_sprites);
sprintf(buf, "bgp0: %d/%d", g_sword2->_curBgp0, MAX_bgp0_sprites);
Make_debug_text_block(buf, 560, 0);
sprintf(buf, "bgp1: %d/%d", cur_bgp1, MAX_bgp1_sprites);
sprintf(buf, "bgp1: %d/%d", g_sword2->_curBgp1, MAX_bgp1_sprites);
Make_debug_text_block(buf, 560, 15);
sprintf(buf, "back: %d/%d", cur_back, MAX_back_sprites);
sprintf(buf, "back: %d/%d", g_sword2->_curBack, MAX_back_sprites);
Make_debug_text_block(buf, 560, 30);
sprintf(buf, "sort: %d/%d", cur_sort, MAX_sort_sprites);
sprintf(buf, "sort: %d/%d", g_sword2->_curSort, MAX_sort_sprites);
Make_debug_text_block(buf, 560, 45);
sprintf(buf, "fore: %d/%d", cur_fore, MAX_fore_sprites);
sprintf(buf, "fore: %d/%d", g_sword2->_curFore, MAX_fore_sprites);
Make_debug_text_block(buf, 560, 60);
sprintf(buf, "fgp0: %d/%d", cur_fgp0, MAX_fgp0_sprites);
sprintf(buf, "fgp0: %d/%d", g_sword2->_curFgp0, MAX_fgp0_sprites);
Make_debug_text_block(buf, 560, 75);
sprintf(buf, "fgp1: %d/%d", cur_fgp1, MAX_fgp1_sprites);
sprintf(buf, "fgp1: %d/%d", g_sword2->_curFgp1, MAX_fgp1_sprites);
Make_debug_text_block(buf, 560, 90);
// largest layer & sprite
// NB. Strings already constructed in Build_display.cpp
Make_debug_text_block(largest_layer_info, 0, 60);
Make_debug_text_block(largest_sprite_info, 0, 75);
Make_debug_text_block(g_sword2->_largestLayerInfo, 0, 60);
Make_debug_text_block(g_sword2->_largestSpriteInfo, 0, 75);
// "waiting for person" indicator - set form fnTheyDo and
// fnTheyDoWeWait

View File

@ -338,9 +338,9 @@ int32 Logic::fnDisplayMsg(int32 *params) {
// +2 to skip the encoded text number in the first 2 chars; 3 is
// duration in seconds
DisplayMsg(FetchTextLine(res_man.open(text_res), local_text) + 2, 3);
g_sword2->displayMsg(FetchTextLine(res_man.open(text_res), local_text) + 2, 3);
res_man.close(text_res);
RemoveMsg();
g_sword2->removeMsg();
return IR_CONT;
}
@ -445,7 +445,7 @@ int32 Logic::fnPlayCredits(int32 *params) {
g_display->setPalette(0, 256, oldPal, RDPAL_FADE);
g_display->fadeUp();
g_display->updateDisplay();
Build_display();
g_sword2->buildDisplay();
g_display->waitForFade();
g_sound->muteFx(false);

View File

@ -49,6 +49,10 @@ int32 Logic::fnInitBackground(int32 *params) {
// params: 0 res id of normal background layer - cannot be 0
// 1 1 yes 0 no for a new palette
return g_sword2->initBackground(params[0], params[1]);
}
int32 Sword2Engine::initBackground(int32 res, int32 new_palette) {
_multiScreenHeader *screenLayerTable;
_screenHeader *screen_head;
_layerHeader *layer;
@ -56,15 +60,15 @@ int32 Logic::fnInitBackground(int32 *params) {
uint8 *file;
uint32 rv;
debug(5, "CHANGED TO LOCATION \"%s\"", FetchObjectName(*params));
debug(5, "CHANGED TO LOCATION \"%s\"", FetchObjectName(res));
// stop all fx & clears the queue
Clear_fx_queue();
#ifdef _SWORD2_DEBUG
debug(5, "fnInitBackground(%d)", params[0]);
debug(5, "fnInitBackground(%d)", res);
if (!params[0]) {
if (!res) {
error("ERROR: fnInitBackground cannot have 0 for background layer id!");
}
#endif
@ -85,8 +89,8 @@ int32 Logic::fnInitBackground(int32 *params) {
if (this_screen.background_layer_id)
g_display->closeBackgroundLayer();
this_screen.background_layer_id = params[0]; // set the res id
this_screen.new_palette = params[1]; // yes or no - palette is taken from layer file
this_screen.background_layer_id = res;
this_screen.new_palette = new_palette;
// ok, now read the resource and pull out all the normal sort layer
// info/and set them up at the beginning of the sort list - why do it
@ -116,9 +120,9 @@ int32 Logic::fnInitBackground(int32 *params) {
// need this for sorting - but leave the rest blank,
// we'll take from the header at print time
sort_list[i].sort_y = layer->y + layer->height;
g_sword2->_sortList[i].sort_y = layer->y + layer->height;
// signifies a layer
sort_list[i].layer_number = i + 1;
g_sword2->_sortList[i].layer_number = i + 1;
debug(5, "init layer %d", i);
}

View File

@ -22,8 +22,8 @@
#ifndef _LOGIC
#define _LOGIC
// #include "sword2/defs.h"
#include "sword2/header.h"
#include "sword2/driver/driver96.h"
namespace Sword2 {
@ -32,6 +32,8 @@ namespace Sword2 {
// This must allow for the largest number of objects in a screen
#define OBJECT_KILL_LIST_SIZE 50
#define MAX_SEQUENCE_TEXT_LINES 15
class Logic {
private:
// Point to the global variable data
@ -69,8 +71,34 @@ private:
void setupOpcodes(void);
void processKillList(void);
// Stores resource id of the wav to use as lead-out from smacker
uint32 _smackerLeadOut;
int32 animate(int32 *params, bool reverse);
int32 megaTableAnimate(int32 *params, bool reverse);
// keeps count of number of text lines to disaply during the sequence
uint32 _sequenceTextLines;
// FOR TEXT LINES IN SEQUENCE PLAYER
struct _sequenceTextInfo {
uint32 textNumber;
uint16 startFrame;
uint16 endFrame;
mem *text_mem;
uint32 speechBufferSize;
uint16 *speech_mem;
};
_sequenceTextInfo _sequenceTextList[MAX_SEQUENCE_TEXT_LINES];
void createSequenceSpeech(_movieTextObject *sequenceText[]);
void clearSequenceSpeech(_movieTextObject *sequenceText[]);
public:
Logic() : _globals(NULL), _kills(0), _debugFlag(false) {
Logic() : _globals(NULL), _kills(0), _debugFlag(false),
_smackerLeadOut(0), _sequenceTextLines(0) {
setupOpcodes();
}
@ -197,7 +225,7 @@ public:
int32 fnRefreshInventory(int32 *params);
int32 fnChangeShadows(int32 *params);
//do one cycle of the current session
// do one cycle of the current session
int processSession(void);
// cause the logic loop to terminate and drop out

View File

@ -282,7 +282,7 @@ void System_menu_mouse(void) {
// '0' means put back game screen
// palette; see Build_display.cpp
SetFullPalette(0);
g_sword2->setFullPalette(0);
// stop the engine fading in the
// restored screens palette

View File

@ -1285,7 +1285,7 @@ void ResourceManager::getCd(int cd) {
g_logic.fnStopMusic(NULL);
textRes = res_man.open(2283);
DisplayMsg(FetchTextLine(textRes, 5 + cd) + 2, 0);
g_sword2->displayMsg(FetchTextLine(textRes, 5 + cd) + 2, 0);
text_spr = fontRenderer.makeTextSprite(FetchTextLine(textRes, 5 + cd) + 2, 640, 187, g_sword2->_speechFontId);
frame = (_frameHeader*) text_spr->ad;
@ -1338,7 +1338,7 @@ void ResourceManager::getCd(int cd) {
} while (!done);
memory.freeMemory(text_spr);
RemoveMsg();
g_sword2->removeMsg();
}
} // End of namespace Sword2

View File

@ -140,6 +140,18 @@ Sword2Engine::Sword2Engine(GameDetector *detector, OSystem *syst)
_newgui = g_gui;
_debugger = new Debugger(this);
_lastPaletteRes = 0;
_largestLayerArea = 0;
_largestSpriteArea = 0;
strcpy(_largestLayerInfo, "largest layer: none registered");
strcpy(_largestSpriteInfo, "largest sprite: none registered");
_fps = 0;
_cycleTime = 0;
_frameCount = 0;
}
Sword2Engine::~Sword2Engine() {
@ -247,7 +259,7 @@ int32 GameCycle(void) {
do {
// reset the graphic 'buildit' list before a new
// logic list (see fnRegisterFrame)
Reset_render_lists();
g_sword2->resetRenderLists();
// reset the mouse hot-spot list (see fnRegisterMouse
// and fnRegisterFrame)
@ -402,10 +414,10 @@ void Sword2Engine::go() {
// display once every 4 game-cycles
if (console_status || renderSkip == 0 || (gameCycle % 4) == 0)
Build_display(); // create and flip the screen
g_sword2->buildDisplay(); // create and flip the screen
#else
// create and flip the screen
Build_display();
g_sword2->buildDisplay();
#endif
}
@ -529,7 +541,7 @@ void UnpauseGame(void) {
UnpauseAllSound();
// put back game screen palette; see Build_display.cpp
SetFullPalette(0xffffffff);
g_sword2->setFullPalette(0xffffffff);
// If graphics level at max, turn up again
if (graphics_level_fudged) {

View File

@ -25,6 +25,7 @@
#include "common/map.h"
#include "common/rect.h"
#include "common/str.h"
#include "sword2/build_display.h"
#include "sword2/console.h"
#include "sword2/driver/d_sound.h"
#include "sword2/driver/d_draw.h"
@ -63,6 +64,68 @@ private:
uint32 _bootParam;
int32 _saveSlot;
// structure filled out by each object to register its graphic printing
// requrements
struct buildit {
int16 x;
int16 y;
uint16 scaled_width;
uint16 scaled_height;
int16 sort_y;
uint32 anim_resource;
uint16 anim_pc;
// Denotes a scaling sprite at print time - and holds the
// scaling value for the shrink routine
uint16 scale;
// Non-zero means this item is a layer - retrieve from
// background layer and send to special renderer
uint16 layer_number;
// True means we want this frame to be affected by the shading
// mask
bool shadingFlag;
};
buildit _bgp0List[MAX_bgp0_sprites];
buildit _bgp1List[MAX_bgp1_sprites];
buildit _backList[MAX_back_sprites];
buildit _sortList[MAX_sort_sprites];
buildit _foreList[MAX_fore_sprites];
buildit _fgp0List[MAX_fgp0_sprites];
buildit _fgp1List[MAX_fgp1_sprites];
// Holds the order of the sort list, i.e. the list stays static and we
// sort this array.
uint16 _sortOrder[MAX_sort_sprites];
// Last palette used - so that we can restore the correct one after a
// pause (which dims the screen) and it's not always the main screen
// palette that we want, eg. during the eclipse
// This flag gets set in startNewPalette() and setFullPalette()
uint32 _lastPaletteRes;
void sendBackPar0Frames(void);
void sendBackPar1Frames(void);
void sendBackFrames(void);
void sendSortFrames(void);
void sendForeFrames(void);
void sendForePar0Frames(void);
void sendForePar1Frames(void);
void sortTheSortList(void);
void startNewPalette(void);
void processLayer(uint32 layer_number);
public:
Sword2Engine(GameDetector *detector, OSystem *syst);
~Sword2Engine();
@ -86,6 +149,43 @@ public:
uint32 _controlsFontId;
uint32 _redFontId;
void resetRenderLists(void);
void buildDisplay(void);
void processImage(buildit *build_unit);
void displayMsg(uint8 *text, int time);
void removeMsg(void);
void setFullPalette(int32 palRes);
int32 registerFrame(int32 *params);
void registerFrame(int32 *params, buildit *build_unit);
// The debugger wants to access these
uint32 _curBgp0;
uint32 _curBgp1;
uint32 _curBack;
uint32 _curSort;
uint32 _curFore;
uint32 _curFgp0;
uint32 _curFgp1;
// So I know if the control panel can be activated
int32 _mouseStatus;
// Debugging stuff
uint32 _largestLayerArea;
uint32 _largestSpriteArea;
char _largestLayerInfo[128];
char _largestSpriteInfo[128];
// 'frames per second' counting stuff
uint32 _fps;
uint32 _cycleTime;
uint32 _frameCount;
int32 initBackground(int32 res, int32 new_palette);
void errorString(const char *buf_input, char *buf_output);
void initialiseFontResourceFlags(void);
void initialiseFontResourceFlags(uint8 language);