Skip to content

Commit

Permalink
TITANIC: Code for starfield mode setup & photo code
Browse files Browse the repository at this point in the history
  • Loading branch information
dreammaster committed Mar 3, 2017
1 parent 415bd56 commit 297cb6b
Show file tree
Hide file tree
Showing 10 changed files with 172 additions and 31 deletions.
2 changes: 1 addition & 1 deletion engines/titanic/core/game_object.h
Expand Up @@ -44,7 +44,7 @@ enum Found { FOUND_NONE = 0, FOUND_GLOBAL = 1, FOUND_ROOM = 2, FOUND_PET = 3, FO
enum RoomFlagsComparison { RFC_LOCATION = 1, RFC_CLASS_ELEVATOR = 2, RFC_TITANIA = 3 };
enum StarControlAction {
STAR_SHOW = 0, STAR_HIDE, STAR_2, STAR_RESET_POS, STAR_4, STAR_5, STAR_6, STAR_7,
STAR_8, STAR_9, STAR_10, STAR_11, STAR_12, STAR_13, STAR_SET_REFERENCE, STAR_FADE_IN,
STAR_8, STAR_TOGGLE_MODE, STAR_10, STAR_11, STAR_12, STAR_13, STAR_SET_REFERENCE, STAR_FADE_IN,
STAR_FADE_OUT, STAR_17, STAR_18, STAR_19
};

Expand Down
2 changes: 1 addition & 1 deletion engines/titanic/game/nav_helmet.cpp
Expand Up @@ -106,7 +106,7 @@ bool CNavHelmet::PETHelmetOnOffMsg(CPETHelmetOnOffMsg *msg) {

bool CNavHelmet::PETPhotoOnOffMsg(CPETPhotoOnOffMsg *msg) {
if (_flag)
starFn(STAR_9);
starFn(STAR_TOGGLE_MODE);

return true;
}
Expand Down
15 changes: 9 additions & 6 deletions engines/titanic/star_control/star_control.cpp
Expand Up @@ -110,8 +110,11 @@ bool CStarControl::MouseMoveMsg(CMouseMoveMsg *msg) {
}

bool CStarControl::KeyCharMsg(CKeyCharMsg *msg) {
if (_visible)
_view.KeyCharMsg(msg->_key);
if (_visible) {
CErrorCode errorCode;
_view.KeyCharMsg(msg->_key, &errorCode);
return errorCode.get();
}

return false;
}
Expand All @@ -138,7 +141,7 @@ void CStarControl::newFrame() {
int val1 = _starField.get88();
int val2 = 0;

if (!_starField.get3()) {
if (_starField.getMode() == MODE_STARFIELD) {
val2 = _starField.get5();
if ((val1 + 2) == _starField.get7Count())
val2 = 0;
Expand Down Expand Up @@ -205,8 +208,8 @@ void CStarControl::doAction(StarControlAction action) {
_view.fn9();
break;

case STAR_9:
_view.fn10();
case STAR_TOGGLE_MODE:
_view.toggleMode();
break;

case STAR_10:
Expand All @@ -226,7 +229,7 @@ void CStarControl::doAction(StarControlAction action) {
break;

case STAR_SET_REFERENCE: {
_view.fn15();
_view.setHasReference();
CPetControl *pet = getPetControl();
if (pet)
pet->starsSetReference();
Expand Down
4 changes: 4 additions & 0 deletions engines/titanic/star_control/star_control_sub8.cpp
Expand Up @@ -22,6 +22,7 @@

#include "titanic/star_control/star_control_sub8.h"
#include "titanic/star_control/star_control_sub7.h"
#include "titanic/star_control/star_control_sub12.h"
#include "titanic/star_control/star_field.h"

namespace Titanic {
Expand All @@ -47,5 +48,8 @@ void CStarControlSub8::selectStar(int index, CVideoSurface *surface,
// TODO
}

void CStarControlSub8::fn1(CStarField *starField, CSurfaceArea *surfaceArea, CStarControlSub12 *sub12) {
// TODO
}

} // End of namespace Titanic
4 changes: 4 additions & 0 deletions engines/titanic/star_control/star_control_sub8.h
Expand Up @@ -23,13 +23,15 @@
#ifndef TITANIC_STAR_CONTROL_SUB8_H
#define TITANIC_STAR_CONTROL_SUB8_H

#include "titanic/star_control/surface_area.h"
#include "titanic/support/simple_file.h"
#include "titanic/support/video_surface.h"

namespace Titanic {

class CStarField;
class CStarControlSub7;
class CStarControlSub12;

class CStarControlSub8 {
struct StructEntry {
Expand Down Expand Up @@ -64,6 +66,8 @@ class CStarControlSub8 {

void selectStar(int starNum, CVideoSurface *surface, CStarField *starField,
CStarControlSub7 *sub7);

void fn1(CStarField *starField, CSurfaceArea *surfaceArea, CStarControlSub12 *sub12);
};

} // End of namespace Titanic
Expand Down
23 changes: 14 additions & 9 deletions engines/titanic/star_control/star_field.cpp
Expand Up @@ -25,16 +25,16 @@

namespace Titanic {

CStarField::CStarField() : _val1(0), _val2(0), _val3(0), _val4(true),
_val5(0), _isSolved(false) {
CStarField::CStarField() : _val1(0), _val2(0), _mode(MODE_STARFIELD),
_val4(true), _val5(0), _isSolved(false) {
}

void CStarField::load(SimpleFile *file) {
_sub7.load(file);
_sub8.load(file);
_val1 = file->readNumber();
_val2 = file->readNumber();
_val3 = file->readNumber();
_mode = (StarMode)file->readNumber();
_val4 = file->readNumber();
_isSolved = file->readNumber();
}
Expand All @@ -44,7 +44,7 @@ void CStarField::save(SimpleFile *file, int indent) {
_sub8.save(file, indent);
file->writeNumberLine(_val1, indent);
file->writeNumberLine(_val2, indent);
file->writeNumberLine(_val3, indent);
file->writeNumberLine(_mode, indent);
file->writeNumberLine(_val4, indent);
file->writeNumberLine(_isSolved, indent);
}
Expand Down Expand Up @@ -93,12 +93,12 @@ void CStarField::set54(int val) {
_sub5.set4(val);
}

int CStarField::get3() const {
return _val3;
StarMode CStarField::getMode() const {
return _mode;
}

void CStarField::set3(int val) {
_val3 = val;
void CStarField::setMode(StarMode mode) {
_mode = mode;
}

void CStarField::toggle4() {
Expand Down Expand Up @@ -131,9 +131,14 @@ void CStarField::fn1(CErrorCode *errorCode) {
_sub5.proc3(errorCode);
}

void CStarField::fn6(CVideoSurface *surface, CStarControlSub12 *sub12) {
CSurfaceArea surfaceArea(surface);

}

bool CStarField::mouseButtonDown(CVideoSurface *surface, CStarControlSub12 *sub12,
int flags, const Common::Point &pt) {
if (!_val3) {
if (_mode == MODE_STARFIELD) {
CSurfaceArea surfaceArea(surface);
return selectStar(&surfaceArea, sub12, 0, pt);
} else {
Expand Down
18 changes: 15 additions & 3 deletions engines/titanic/star_control/star_field.h
Expand Up @@ -32,6 +32,8 @@

namespace Titanic {

enum StarMode { MODE_STARFIELD = 0, MODE_PHOTO = 1 };

class CStarField : public CStarControlSub2 {
private:
CStarControlSub7 _sub7;
Expand All @@ -41,7 +43,7 @@ class CStarField : public CStarControlSub2 {
CStarControlSub5 _sub5;
int _val1;
int _val2;
int _val3;
StarMode _mode;
bool _val4;
int _val5;
bool _isSolved;
Expand Down Expand Up @@ -71,8 +73,17 @@ class CStarField : public CStarControlSub2 {
void set2(int val);
int get54() const;
void set54(int val);
int get3() const;
void set3(int val);

/**
* Gets the current display mode
*/
StarMode getMode() const;

/**
* Sets the display mode
*/
void setMode(StarMode mode);

void toggle4();
bool set4(bool val);
int get88() const;
Expand All @@ -93,6 +104,7 @@ class CStarField : public CStarControlSub2 {
}

void fn1(CErrorCode *errorCode);
void fn6(CVideoSurface *surface, CStarControlSub12 *sub12);

/**
* Called when the starfield is clicked
Expand Down
104 changes: 96 additions & 8 deletions engines/titanic/star_control/star_view.cpp
Expand Up @@ -25,6 +25,7 @@
#include "titanic/star_control/star_control.h"
#include "titanic/star_control/star_field.h"
#include "titanic/core/game_object.h"
#include "titanic/titanic.h"

namespace Titanic {

Expand Down Expand Up @@ -67,7 +68,10 @@ void CStarView::setup(CScreenManager *screenManager, CStarField *starField, CSta
}

void CStarView::reset() {
// TODO
if (!_field118) {
CStarControlSub12 sub12(&_sub13);
fn18(&sub12);
}
}

void CStarView::draw(CScreenManager *screenManager) {
Expand Down Expand Up @@ -139,9 +143,22 @@ bool CStarView::MouseMoveMsg(int unused, const Point &pt) {
return false;
}

CErrorCode CStarView::KeyCharMsg(int key) {
// TODO
return CErrorCode();
bool CStarView::KeyCharMsg(int key, CErrorCode *errorCode) {
CStarControlSub6 sub6;
// int v = _starField ? _starField->get88() : -1;

switch (key) {
case Common::KEYCODE_TAB:
if (_starField) {
toggleMode();
return true;
}
break;

// TODO: More switch cases
}

return false;
}

bool CStarView::canSetStarDestination() const {
Expand Down Expand Up @@ -197,8 +214,10 @@ void CStarView::fn9() {
// TODO
}

void CStarView::fn10() {
// TODO
void CStarView::toggleMode() {
_showingPhoto = !_showingPhoto;
if (_starField)
_starField->setMode(_showingPhoto ? MODE_PHOTO : MODE_STARFIELD);
}

void CStarView::fn11() {
Expand All @@ -217,8 +236,18 @@ void CStarView::fn14() {
// TODO
}

void CStarView::fn15() {
// TODO
void CStarView::setHasReference() {
FVector v1, v2;
randomizeVectors(&v1, &v2);

_sub13.setPosition(v1);
_sub13.fn11(v2);
_field218 = 0;
_sub13.fn13(1, 0);
_sub13.fn13(0, 0);
_field118 = 1;
reset();
_field218 = 1;
}

void CStarView::fn16() {
Expand All @@ -229,5 +258,64 @@ void CStarView::fn17() {
// TODO
}

void CStarView::fn18(CStarControlSub12 *sub12) {
if (_starField) {
if (!_videoSurface2) {
CScreenManager *scrManager = CScreenManager::setCurrent();
if (scrManager)
resizeSurface(scrManager, 600, 340, &_videoSurface2);
}

if (_videoSurface2) {
int oldVal = _starField->get54();
_starField->set4(false);

_videoSurface2->clear();
_videoSurface2->lock();
_starField->render(_videoSurface2, sub12);
_videoSurface2->unlock();

_starField->set54(oldVal);
_starField->fn6(_videoSurface2, sub12);
}
}
}

void CStarView::randomizeVectors(FVector *v1, FVector *v2) {
v1->_x = g_vm->getRandomFloat() * -4096.0 - 3072.0;
v1->_y = g_vm->getRandomFloat() * -4096.0 - 3072.0;
v1->_z = g_vm->getRandomFloat() * -4096.0 - 3072.0;

double vx = g_vm->getRandomFloat() * 8192.0;
double vy = g_vm->getRandomFloat() * 1024.0;
vx -= v1->_x;
vy -= v1->_y;

v2->_x = vx;
v2->_y = vy;
v2->_z = -v1->_z;
v2->fn3();
}

void CStarView::resizeSurface(CScreenManager *scrManager, int width, int height,
CVideoSurface **surface) {
if (!surface)
// Surface pointer must be provided
return;
if (*surface) {
// If there's an existing surface of the correct size, re-use it
if ((*surface)->getWidth() == width && (*surface)->getHeight() == height)
return;

// Delete the old surface
delete *surface;
*surface = nullptr;
}

CVideoSurface *newSurface = scrManager->createSurface(width, height);
if (newSurface)
*surface = newSurface;
}


} // End of namespace Titanic

0 comments on commit 297cb6b

Please sign in to comment.