PRIVATE: more code

This commit is contained in:
neuromancer 2021-01-08 22:42:34 -03:00 committed by Eugene Sandulenko
parent 536fcd5605
commit f5c4e7e6cb
6 changed files with 199 additions and 31 deletions

View file

@ -78,7 +78,7 @@ void loadSetting(Common::String *name)
progp = prog;
for (Inst *pc_ = progp; pc_-progp < 100; pc_++) {
/*for (Inst *pc_ = progp; pc_-progp < 100; pc_++) {
if (_functions.contains((void *) *pc_))
debug("%p: %s", (void*) pc_, _functions.getVal((void*) *pc_)->c_str());
else if ( (Inst *) *pc_ >= progp && (Inst *) *pc_ <= (progp + NPROG))
@ -87,8 +87,7 @@ void loadSetting(Common::String *name)
debugN("%p:", (void*) pc_);
showSymbol((Symbol *) *pc_);
}
}
}*/
}

View file

@ -14,8 +14,26 @@ void ChgMode(ArgArray args) {
g_private->_mode = args[0].u.val;
Common::String *s = new Common::String(args[1].u.str);
g_private->_nextSetting = s;
if (g_private->_mode == 0) {
g_private->_origin->x = 0;
g_private->_origin->y = 0;
}
else if (g_private->_mode == 1) {
g_private->_origin->x = 63;
g_private->_origin->y = 48;
}
else
assert(0);
}
void VSPicture(ArgArray args) {
// assert types
debug("VSPicture(%s)", args[0].u.str);
g_private->_nextVS = new Common::String(args[0].u.str);
}
void Goto(ArgArray args) { // should be goto, but this is a reserved word
// assert types
debug("goto(%s)", args[0].u.str);
@ -29,6 +47,15 @@ void Quit(ArgArray args) {
}
void RestartGame(ArgArray args) {
// assert types
debug("WARNING: RestartGame is not implemented");
}
void DossierAdd(ArgArray args) {
// assert types
debug("WARNING: DossierAdd is not implemented");
}
void SetFlag(ArgArray args) {
// assert types
@ -39,16 +66,23 @@ void SetFlag(ArgArray args) {
void Exit(ArgArray args) {
// assert types
assert(args[2].type == RECT || args[2].type == NAME);
debug("Exit(%s, %s, %s)", args[0].u.str, args[1].u.sym->name->c_str(), "RECT");
debug("Exit(..)"); //, args[0].u.str, args[1].u.sym->name->c_str(), "RECT");
ExitInfo *e = (ExitInfo*) malloc(sizeof(ExitInfo));
e->nextSetting = new Common::String(args[0].u.str);
e->cursor = args[1].u.sym->name;
if (args[0].type == NUM && args[0].u.val == 0)
e->nextSetting = NULL;
else
e->nextSetting = new Common::String(args[0].u.str);
if (args[1].type == NUM && args[1].u.val == 0)
e->cursor = NULL;
else
e->cursor = args[1].u.sym->name;
e->rect = args[2].u.rect;
g_private->_exits.push_front(*e);
}
void SetModifiedFlag(ArgArray args) {
// assert types
debug("SetModifiedFlag(%d)", args[0].u.val);
@ -71,10 +105,19 @@ void Sound(ArgArray args) {
void Transition(ArgArray args) {
// assert types
debug("Transition(%s, %s)", args[0].u.str, args[1].u.str);
g_private->_nextMovie = new Common::String(args[0].u.str);
//g_private->_nextMovie = new Common::String(args[0].u.str);
g_private->_nextSetting = new Common::String(args[1].u.str);
}
void Movie(ArgArray args) {
// assert types
debug("Movie(%s, %s)", args[0].u.str, args[1].u.str);
if (strcmp(args[0].u.str, "\"\"") != 0)
g_private->_nextMovie = new Common::String(args[0].u.str);
g_private->_nextSetting = new Common::String(args[1].u.str);
}
void CRect(ArgArray args) {
// assert types
@ -113,6 +156,36 @@ void Bitmap(ArgArray args) {
g_private->loadImage(*s, x, y);
}
void Mask(ArgArray args, bool drawn) {
assert(args.size() == 3 || args.size() == 5);
int x = 0;
int y = 0;
char *f = args[0].u.str;
char *e = args[1].u.str;
Common::String *c = args[2].u.sym->name;
if (args.size() == 5) {
x = args[3].u.val;
y = args[4].u.val;
}
debug("Mask(%s, %s, %s, %d, %d)", f, e, c->c_str(), x, y);
const Common::String *s = new Common::String(f);
//if (drawed)
// g_private->loadImage(*s, x, y);
MaskInfo *m = (MaskInfo*) malloc(sizeof(MaskInfo));
m->surf = g_private->loadMask(*s, x, y, drawn);
m->nextSetting = new Common::String(e);
m->cursor = c;
m->point = new Common::Point(x,y);
g_private->_masks.push_front(*m);
}
void Timer(ArgArray args) {
debug("Timer(%d, %s, %s)", args[0].u.val, args[1].u.str, args[2].u.str);
g_system->delayMillis(100 * args[0].u.val);
@ -138,12 +211,22 @@ void execFunction(char *name, ArgArray args) {
else if (strcmp(name, "Bitmap") == 0) {
Bitmap(args);
}
else if (strcmp(name, "Mask") == 0) {
Mask(args, false);
}
else if (strcmp(name, "MaskDrawn") == 0) {
Mask(args, true);
}
else if (strcmp(name, "Timer") == 0) {
Timer(args);
}
else if (strcmp(name, "Transition") == 0) {
Transition(args);
}
else if (strcmp(name, "Movie") == 0) {
Movie(args);
}
else if (strcmp(name, "SetModifiedFlag") == 0) {
SetModifiedFlag(args);
}
@ -156,9 +239,18 @@ void execFunction(char *name, ArgArray args) {
else if (strcmp(name, "LoadGame") == 0) {
;
}
else if (strcmp(name, "DossierAdd") == 0) {
DossierAdd(args);
}
else if (strcmp(name, "VSPicture") == 0) {
VSPicture(args);
}
else if (strcmp(name, "CRect") == 0) {
CRect(args);
}
else if (strcmp(name, "RestartGame") == 0) {
RestartGame(args);
}
else {
debug("I don't know how to exec %s", name);
assert(0);

View file

@ -29,6 +29,7 @@ goto return GOTOTOK;
RECT return RECT;
FALSE return FALSETOK;
TRUE return TRUETOK;
NULL return NULLTOK;
Random return RANDOMTOK;
[A-Za-z_][A-Za-z_0-9]* yylval.s = strdup(yytext); return NAME;
[\-]?[0-9]+ yylval.sym = Private::addconstant(NUM, atoi(yytext), NULL); return NUM;

View file

@ -46,7 +46,7 @@ int yywrap()
%token<s> NAME
%token<sym> STRING NUM
%type <inst> body if startp cond end expr statements statement fcall value
%token LTE GTE NEQ EQ FALSETOK TRUETOK IFTOK ELSETOK RECT GOTOTOK DEBUGTOK DEFINETOK SETTINGTOK RANDOMTOK
%token LTE GTE NEQ EQ FALSETOK TRUETOK NULLTOK IFTOK ELSETOK RECT GOTOTOK DEBUGTOK DEFINETOK SETTINGTOK RANDOMTOK
%type<narg> params
%%
@ -136,7 +136,8 @@ params: /* nothing */ { $$ = 0; }
| fcall { $$ = 1; }
;
value: FALSETOK { code2(Private::constpush, (Private::Inst) Private::addconstant(NUM, 0, NULL)); }
value: NULLTOK { code2(Private::constpush, (Private::Inst) Private::addconstant(NUM, 0, NULL)); }
| FALSETOK { code2(Private::constpush, (Private::Inst) Private::addconstant(NUM, 0, NULL)); }
| TRUETOK { code2(Private::constpush, (Private::Inst) Private::addconstant(NUM, 1, NULL)); }
| NUM { code2(Private::constpush, (Private::Inst)$NUM); }
| STRING { code2(Private::strpush, (Private::Inst)$STRING); }

View file

@ -106,15 +106,17 @@ Common::Error PrivateEngine::run() {
_screenH = 480;
//_pixelFormat = Graphics::PixelFormat::createFormatCLUT8();
_pixelFormat = Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0);
_transparentColor = _pixelFormat.RGBToColor(0,255,0);
initGraphics(_screenW, _screenH, &_pixelFormat);
CursorMan.replaceCursor(MOUSECURSOR_SCI, 11, 16, 0, 0, 0);
CursorMan.replaceCursorPalette(cursorPalette, 0, 3);
_origin = new Common::Point(0, 0);
_image = new Image::BitmapDecoder();
_compositeSurface = new Graphics::ManagedSurface();
_compositeSurface->create(_screenW, _screenH, _pixelFormat);
_compositeSurface->setTransparentColor(0x00ff00);
_compositeSurface->setTransparentColor(_transparentColor);
// You could use backend transactions directly as an alternative,
// but it isn't recommended, until you want to handle the error values
@ -162,12 +164,17 @@ Common::Error PrivateEngine::run() {
// Events
switch (event.type) {
case Common::EVENT_QUIT:
case Common::EVENT_RETURN_TO_LAUNCHER:
break;
case Common::EVENT_QUIT:
case Common::EVENT_RETURN_TO_LAUNCHER:
break;
case Common::EVENT_LBUTTONDOWN:
selectExit(mousePos);
case Common::EVENT_LBUTTONDOWN:
selectMask(mousePos);
selectExit(mousePos);
break;
default:
{}
}
@ -198,6 +205,7 @@ Common::Error PrivateEngine::run() {
if (_nextSetting != NULL) {
debug("Executing %s", _nextSetting->c_str());
_exits.clear();
_masks.clear();
loadSetting(_nextSetting);
_nextSetting = NULL;
CursorMan.showMouse(false);
@ -215,26 +223,54 @@ Common::Error PrivateEngine::run() {
}
void PrivateEngine::selectExit(Common::Point mousePos) {
//debug("Mousepos %d %d", mousePos.x, mousePos.y);
Common::String *ns = NULL;
int rs = 1 << 31;
int rs = 100000000;
int cs = 0;
for (ExitList::const_iterator it = _exits.begin(); it != _exits.end(); ++it) {
const ExitInfo e = *it;
cs = e.rect->width()*e.rect->height();
ExitInfo e;
for (ExitList::iterator it = _exits.begin(); it != _exits.end(); ++it) {
e = *it;
cs = e.rect->width()*e.rect->height();
//debug("Testing exit %s %d", e.nextSetting->c_str(), cs);
if (e.rect->contains(mousePos)) {
debug("Exit %s %d", e.nextSetting->c_str(), cs);
if (cs < rs) {
//debug("Inside! %d %d", cs, rs);
if (cs < rs && e.nextSetting != NULL) { // TODO: check this
debug("Found Exit %s %d", e.nextSetting->c_str(), cs);
rs = cs;
ns = e.nextSetting;
}
}
}
if (cs > 0)
if (ns != NULL) {
debug("Exit selected %s", ns->c_str());
_nextSetting = ns;
}
}
void PrivateEngine::selectMask(Common::Point mousePos) {
//debug("Mousepos %d %d", mousePos.x, mousePos.y);
Common::String *ns = NULL;
MaskInfo m;
for (MaskList::iterator it = _masks.begin(); it != _masks.end(); ++it) {
m = *it;
debug("Testing mask %s", m.nextSetting->c_str());
if ( *((uint32*) m.surf->getBasePtr(mousePos.x, mousePos.y)) != _transparentColor) {
debug("Inside!");
if (m.nextSetting != NULL) { // TODO: check this
debug("Found Mask %s", m.nextSetting->c_str());
ns = m.nextSetting;
break;
}
}
}
if (ns != NULL) {
debug("Mask selected %s", ns->c_str());
_nextSetting = ns;
}
}
bool PrivateEngine::hasFeature(EngineFeature f) const {
return
@ -295,7 +331,7 @@ void PrivateEngine::playSound(const Common::String &name) {
}
void PrivateEngine::playVideo(const Common::String &name) {
debugC(1, kPrivateDebugExample, "%s : %s", __FUNCTION__, name.c_str());
debug("%s : %s", __FUNCTION__, name.c_str());
Common::File *file = new Common::File();
Common::String path = convertPath(name);
@ -326,10 +362,32 @@ void PrivateEngine::loadImage(const Common::String &name, int x, int y) {
//for (int i = 0; i < 30; i=i+3)
// debug("%x %x %x", *(_image->getPalette()+i), *(_image->getPalette()+i+1), *(_image->getPalette()+i+2));
_compositeSurface->transBlitFrom(*_image->getSurface()->convertTo(_pixelFormat, _image->getPalette()), Common::Point(x,y), _pixelFormat.RGBToColor(0,255,0));
_compositeSurface->transBlitFrom(*_image->getSurface()->convertTo(_pixelFormat, _image->getPalette()), Common::Point(x,y), _transparentColor);
drawScreen();
}
Graphics::ManagedSurface *PrivateEngine::loadMask(const Common::String &name, int x, int y, bool drawn) {
debugC(1, kPrivateDebugExample, "%s : %s", __FUNCTION__, name.c_str());
Common::File file;
Common::String path = convertPath(name);
if (!file.open(path))
error("unable to load mask %s", path.c_str());
_image->loadStream(file);
Graphics::ManagedSurface *surf = new Graphics::ManagedSurface();
surf->create(_screenW, _screenH, _pixelFormat);
surf->transBlitFrom(*_image->getSurface()->convertTo(_pixelFormat, _image->getPalette()), Common::Point(x,y));
if (drawn) {
_compositeSurface->transBlitFrom(surf->rawSurface(), Common::Point(x,y), _transparentColor);
drawScreen();
}
return surf;
}
void PrivateEngine::drawScreen() {
if (_videoDecoder ? _videoDecoder->needsUpdate() : false || _compositeSurface) {
@ -342,7 +400,8 @@ void PrivateEngine::drawScreen() {
Graphics::Surface *frame = new Graphics::Surface;
frame->create(_screenW, _screenH, _pixelFormat);
frame->copyFrom(*_videoDecoder->decodeNextFrame());
surface->transBlitFrom(*frame->convertTo(_pixelFormat, _videoDecoder->getPalette()));
const Common::Point o(_origin->x, _origin->y);
surface->transBlitFrom(*frame->convertTo(_pixelFormat, _videoDecoder->getPalette()), o);
}
int w = surface->w; //CLIP<int>(surface->w, 0, _screenW);

View file

@ -41,8 +41,15 @@ typedef struct ExitInfo {
Common::String *cursor;
} ExitInfo;
typedef Common::List<ExitInfo> ExitList;
typedef struct MaskInfo {
Graphics::ManagedSurface *surf;
Common::String *nextSetting;
Common::Point *point;
Common::String *cursor;
} MaskInfo;
typedef Common::List<ExitInfo> ExitList;
typedef Common::List<MaskInfo> MaskList;
class PrivateEngine : public Engine {
private:
@ -64,6 +71,7 @@ public:
//Mohawk::InstallerArchive _installerArchive;
Common::Error run() override;
void selectMask(Common::Point);
void selectExit(Common::Point);
bool hasFeature(EngineFeature f) const override;
bool canLoadGameStateCurrently() override { return true; }
@ -77,15 +85,23 @@ public:
void playVideo(const Common::String &name);
void stopSound();
void loadImage(const Common::String &name, int x, int y);
void loadImage(const Common::String &, int, int);
Graphics::ManagedSurface *loadMask(const Common::String &, int, int, bool);
uint32 _transparentColor;
void drawScreen();
// global state
Common::Point *_origin;
Common::String *_nextSetting;
int _mode;
Common::String *_nextVS;
int _mode;
bool _modified;
Common::String *_nextMovie;
ExitList _exits;
MaskList _masks;
};
extern PrivateEngine *g_private;