aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorPaul Gilbert2018-10-20 14:39:34 -0700
committerPaul Gilbert2018-12-08 19:05:59 -0800
commitcf5259d3bc279fd73b4ae8bad2d7b04b8ff7265e (patch)
tree64fda763ed78280bed548891e3e2894d288560e2 /engines
parent65091b25c13be1c5cb319d91fe4ad773ae6fcad0 (diff)
downloadscummvm-rg350-cf5259d3bc279fd73b4ae8bad2d7b04b8ff7265e.tar.gz
scummvm-rg350-cf5259d3bc279fd73b4ae8bad2d7b04b8ff7265e.tar.bz2
scummvm-rg350-cf5259d3bc279fd73b4ae8bad2d7b04b8ff7265e.zip
GLK: Adding stream open/closing
Diffstat (limited to 'engines')
-rw-r--r--engines/gargoyle/gargoyle.cpp6
-rw-r--r--engines/gargoyle/gargoyle.h7
-rw-r--r--engines/gargoyle/glk.cpp10
-rw-r--r--engines/gargoyle/module.mk2
-rw-r--r--engines/gargoyle/streams.cpp (renamed from engines/gargoyle/stream.cpp)34
-rw-r--r--engines/gargoyle/streams.h (renamed from engines/gargoyle/stream.h)53
-rw-r--r--engines/gargoyle/windows.cpp11
-rw-r--r--engines/gargoyle/windows.h18
8 files changed, 89 insertions, 52 deletions
diff --git a/engines/gargoyle/gargoyle.cpp b/engines/gargoyle/gargoyle.cpp
index 986a40ab78..a481ae9624 100644
--- a/engines/gargoyle/gargoyle.cpp
+++ b/engines/gargoyle/gargoyle.cpp
@@ -30,7 +30,7 @@
#include "graphics/thumbnail.h"
#include "gargoyle/gargoyle.h"
#include "gargoyle/events.h"
-#include "gargoyle/stream.h"
+#include "gargoyle/streams.h"
#include "gargoyle/windows.h"
namespace Gargoyle {
@@ -57,8 +57,8 @@ void GargoyleEngine::initialize() {
initGraphics(640, 480, false);
_screen = new Graphics::Screen();
_events = new Events();
- _streams = new Streams();
- _windows = new Windows(_screen);
+ _streams = new Streams(this);
+ _windows = new Windows(this, _screen);
}
Common::Error GargoyleEngine::run() {
diff --git a/engines/gargoyle/gargoyle.h b/engines/gargoyle/gargoyle.h
index bd977137b4..e7d5df2ae4 100644
--- a/engines/gargoyle/gargoyle.h
+++ b/engines/gargoyle/gargoyle.h
@@ -73,10 +73,7 @@ private:
void initialize();
protected:
const GargoyleGameDescription *_gameDescription;
- Events *_events;
Graphics::Screen *_screen;
- Streams *_streams;
- Windows *_windows;
Common::RandomSource _random;
int _loadSaveSlot;
@@ -93,6 +90,10 @@ protected:
*/
virtual void runGame(Common::SeekableReadStream *gameFile) = 0;
public:
+ Events *_events;
+ Streams *_streams;
+ Windows *_windows;
+public:
GargoyleEngine(OSystem *syst, const GargoyleGameDescription *gameDesc);
virtual ~GargoyleEngine();
diff --git a/engines/gargoyle/glk.cpp b/engines/gargoyle/glk.cpp
index 22d02f5237..b49fb63e66 100644
--- a/engines/gargoyle/glk.cpp
+++ b/engines/gargoyle/glk.cpp
@@ -22,7 +22,7 @@
#include "gargoyle/glk.h"
#include "gargoyle/events.h"
-#include "gargoyle/stream.h"
+#include "gargoyle/streams.h"
#include "gargoyle/windows.h"
namespace Gargoyle {
@@ -136,7 +136,7 @@ strid_t Glk::glk_window_get_echo_stream(winid_t win) {
}
void Glk::glk_set_window(winid_t win) {
- _windows->setCurrent(win ? win->_stream : nullptr);
+ _streams->setCurrent(win ? win->_stream : nullptr);
}
strid_t Glk::glk_stream_open_file(frefid_t fileref, FileMode fmode,
@@ -374,15 +374,15 @@ glui32 Glk::glk_buffer_to_title_case_uni(glui32 *buf, glui32 len,
}
void Glk::glk_put_char_uni(glui32 ch) {
- glk_put_char_stream_uni(_windows->getCurrent(), ch);
+ glk_put_char_stream_uni(_streams->getCurrent(), ch);
}
void Glk::glk_put_string_uni(glui32 *s) {
- glk_put_buffer_stream_uni(_windows->getCurrent(), s, strlen_uni(s));
+ glk_put_buffer_stream_uni(_streams->getCurrent(), s, strlen_uni(s));
}
void Glk::glk_put_buffer_uni(glui32 *buf, glui32 len) {
- glk_put_buffer_stream_uni(_windows->getCurrent(), buf, len);
+ glk_put_buffer_stream_uni(_streams->getCurrent(), buf, len);
}
void Glk::glk_put_char_stream_uni(strid_t str, glui32 ch) {
diff --git a/engines/gargoyle/module.mk b/engines/gargoyle/module.mk
index 5acba6a7a4..05b7f5ff3a 100644
--- a/engines/gargoyle/module.mk
+++ b/engines/gargoyle/module.mk
@@ -6,7 +6,7 @@ MODULE_OBJS := \
gargoyle.o \
glk.o \
picture.o \
- stream.o \
+ streams.o \
windows.o \
scott/detection.o \
scott/scott.o
diff --git a/engines/gargoyle/stream.cpp b/engines/gargoyle/streams.cpp
index c447646638..62e43e3908 100644
--- a/engines/gargoyle/stream.cpp
+++ b/engines/gargoyle/streams.cpp
@@ -20,14 +20,18 @@
*
*/
-#include "gargoyle/stream.h"
+#include "gargoyle/streams.h"
#include "gargoyle/windows.h"
namespace Gargoyle {
-Stream::Stream(bool readable, bool writable, uint32 rock, bool unicode) :
- _readable(readable), _writable(writable), _readCount(0), _writeCount(0),
- _prev(nullptr), _next(nullptr), _rock(0) {
+Stream::Stream(Streams *streams, bool readable, bool writable, uint32 rock, bool unicode) :
+ _streams(streams), _readable(readable), _writable(writable), _readCount(0),
+ _writeCount(0), _prev(nullptr), _next(nullptr), _rock(0) {
+}
+
+Stream::~Stream() {
+ _streams->removeStream(this);
}
Stream *Stream::getNext(uint32 *rock) const {
@@ -45,12 +49,19 @@ void Stream::fillResult(StreamResult *result) {
}
void Stream::close(StreamResult *result) {
+ // Get the read/write totals
fillResult(result);
+ // Remove the stream
+ delete this;
}
/*--------------------------------------------------------------------------*/
+void WindowStream::close(StreamResult *result) {
+ warning("cannot close window stream");
+}
+
void WindowStream::writeChar(unsigned char ch) {
}
@@ -61,8 +72,8 @@ void WindowStream::writeCharUni(uint32 ch) {
/*--------------------------------------------------------------------------*/
-MemoryStream::MemoryStream(void *buf, size_t buflen, FileMode mode, uint32 rock, bool unicode) :
- Stream(mode != filemode_Write, mode != filemode_Read, rock, unicode),
+MemoryStream::MemoryStream(Streams *streams, void *buf, size_t buflen, FileMode mode, uint32 rock, bool unicode) :
+ Stream(streams, mode != filemode_Write, mode != filemode_Read, rock, unicode),
_buf(buf), _buflen(buflen), _bufptr(buf) {
assert(_buf && _buflen);
assert(mode == filemode_Read || mode == filemode_Write || mode == filemode_ReadWrite);
@@ -88,7 +99,8 @@ void MemoryStream::writeCharUni(uint32 ch) {
/*--------------------------------------------------------------------------*/
-Streams::Streams() : _streamList(nullptr) {}
+Streams::Streams(GargoyleEngine *engine) : _engine(engine), _streamList(nullptr), _currentStream(nullptr) {
+}
Streams::~Streams() {
while (_streamList)
@@ -96,13 +108,13 @@ Streams::~Streams() {
}
WindowStream *Streams::addWindowStream(Window *window) {
- WindowStream *stream = new WindowStream(window);
+ WindowStream *stream = new WindowStream(this, window);
addStream(stream);
return stream;
}
MemoryStream *Streams::addMemoryStream(void *buf, size_t buflen, FileMode mode, uint32 rock, bool unicode) {
- MemoryStream *stream = new MemoryStream(buf, buflen, mode, rock, unicode);
+ MemoryStream *stream = new MemoryStream(this, buf, buflen, mode, rock, unicode);
addStream(stream);
return stream;
}
@@ -114,7 +126,7 @@ void Streams::addStream(Stream *stream) {
stream->_next->_prev = stream;
}
-void Streams::deleteStream(Stream *stream) {
+void Streams::removeStream(Stream *stream) {
Stream *prev = stream->_prev;
Stream *next = stream->_next;
@@ -124,8 +136,6 @@ void Streams::deleteStream(Stream *stream) {
_streamList = next;
if (next)
next->_prev = prev;
-
- delete stream;
}
Stream *Streams::getFirst(uint32 *rock) {
diff --git a/engines/gargoyle/stream.h b/engines/gargoyle/streams.h
index 4effee33ff..db21d58867 100644
--- a/engines/gargoyle/stream.h
+++ b/engines/gargoyle/streams.h
@@ -20,15 +20,17 @@
*
*/
-#ifndef GARGOYLE_STREAM_H
-#define GARGOYLE_STREAM_H
+#ifndef GARGOYLE_STREAMS_H
+#define GARGOYLE_STREAMS_H
#include "common/scummsys.h"
#include "gargoyle/glk_types.h"
namespace Gargoyle {
+class GargoyleEngine;
class Window;
+class Streams;
struct StreamResult {
uint32 _readCount;
@@ -40,6 +42,7 @@ struct StreamResult {
*/
class Stream {
public:
+ Streams *_streams;
Stream *_prev;
Stream *_next;
uint32 _rock;
@@ -51,12 +54,12 @@ public:
/**
* Constructor
*/
- Stream(bool readable, bool writable, uint32 rock, bool unicode);
+ Stream(Streams *streams, bool readable, bool writable, uint32 rock, bool unicode);
/**
* Destructor
*/
- virtual ~Stream() {}
+ virtual ~Stream();
/**
* Get the next stream
@@ -74,9 +77,9 @@ public:
void fillResult(StreamResult *result);
/**
- * Close the stream
+ * Close and delete the stream
*/
- virtual void close(StreamResult *result = nullptr);
+ void close(StreamResult *result = nullptr);
/**
* Write a character
@@ -100,8 +103,13 @@ public:
/**
* Constructor
*/
- WindowStream(Window *window, uint32 rock = 0, bool unicode = true) :
- Stream(true, false, rock, unicode), _window(window) {}
+ WindowStream(Streams *streams, Window *window, uint32 rock = 0, bool unicode = true) :
+ Stream(streams, true, false, rock, unicode), _window(window) {}
+
+ /**
+ * Close the stream
+ */
+ virtual void close(StreamResult *result = nullptr);
/**
* Write a character
@@ -128,7 +136,7 @@ public:
/**
* Constructor
*/
- MemoryStream(void *buf, size_t buflen, FileMode mode, uint32 rock = 0, bool unicode = true);
+ MemoryStream(Streams *streams, void *buf, size_t buflen, FileMode mode, uint32 rock = 0, bool unicode = true);
/**
* Write a character
@@ -145,18 +153,26 @@ public:
* Streams manager
*/
class Streams {
+ friend class Stream;
private:
+ GargoyleEngine *_engine;
Stream *_streamList;
+ Stream *_currentStream;
private:
/**
* Adds a created stream to the list
*/
void addStream(Stream *stream);
+
+ /**
+ * Remove a stream
+ */
+ void removeStream(Stream *stream);
public:
/**
* Constructor
*/
- Streams();
+ Streams(GargoyleEngine *engine);
/**
* Destructor
@@ -176,12 +192,27 @@ public:
/**
* Delete a stream
*/
- void deleteStream(Stream *stream);
+ void deleteStream(Stream *stream) {
+ delete stream;
+ }
/**
* Start an Iteration through streams
*/
Stream *getFirst(uint32 *rock);
+
+ /**
+ * Set the current output stream
+ */
+ void setCurrent(Stream *stream) {
+ assert(stream->_writable);
+ _currentStream = stream;
+ }
+
+ /**
+ * Gets the current output stream
+ */
+ Stream *getCurrent() const { return _currentStream; }
};
diff --git a/engines/gargoyle/windows.cpp b/engines/gargoyle/windows.cpp
index 0abc8a8797..2c8680b45d 100644
--- a/engines/gargoyle/windows.cpp
+++ b/engines/gargoyle/windows.cpp
@@ -21,7 +21,8 @@
*/
#include "gargoyle/windows.h"
-#include "gargoyle/stream.h"
+#include "gargoyle/gargoyle.h"
+#include "gargoyle/streams.h"
#include "common/algorithm.h"
#include "common/textconsole.h"
@@ -88,9 +89,10 @@ WindowStyle G_STYLES[style_NUMSTYLES] = {
/*--------------------------------------------------------------------------*/
-Windows::Windows(Graphics::Screen *screen) : _screen(screen), _forceRedraw(true), _moreFocus(false),
+Windows::Windows(GargoyleEngine *engine, Graphics::Screen *screen) :
+ _engine(engine), _screen(screen), _forceRedraw(true), _moreFocus(false),
_windowList(nullptr), _rootWin(nullptr), _focusWin(nullptr), _mask(nullptr),
- _claimSelect(0), _currentStr(nullptr) {
+ _claimSelect(0) {
_imageW = _screen->w;
_imageH = _screen->h;
_cellW = _cellH = 8;
@@ -305,7 +307,8 @@ Window::Window(Windows *windows, glui32 rock) : _magicnum(MAGIC_WINDOW_NUM),
Common::fill(&fgcolor[0], &fgcolor[3], 3);
disprock.num = 0;
- _stream = new WindowStream(this, rock);
+ Streams &streams = *windows->_engine->_streams;
+ _stream = streams.addWindowStream(this);
}
/*--------------------------------------------------------------------------*/
diff --git a/engines/gargoyle/windows.h b/engines/gargoyle/windows.h
index fdb29bb7b1..95f1ed48e1 100644
--- a/engines/gargoyle/windows.h
+++ b/engines/gargoyle/windows.h
@@ -29,10 +29,11 @@
#include "graphics/screen.h"
#include "gargoyle/glk_types.h"
#include "gargoyle/picture.h"
-#include "gargoyle/stream.h"
+#include "gargoyle/streams.h"
namespace Gargoyle {
+class GargoyleEngine;
class Window;
class PairWindow;
struct WindowMask;
@@ -45,7 +46,9 @@ struct WindowMask;
* Main windows manager
*/
class Windows {
+ friend class Window;
private:
+ GargoyleEngine *_engine;
Graphics::Screen *_screen;
Window * _windowList; ///< List of all windows
Window *_rootWin; ///< The topmost window
@@ -54,7 +57,6 @@ private:
bool _moreFocus;
bool _claimSelect;
WindowMask *_mask;
- Stream *_currentStr;
private:
/**
* Create a new window
@@ -98,7 +100,7 @@ public:
/**
* Constructor
*/
- Windows(Graphics::Screen *screen);
+ Windows(GargoyleEngine *engine, Graphics::Screen *screen);
/**
* Open a new window
@@ -114,16 +116,6 @@ public:
void clearSelection();
/**
- * Set the current output stream
- */
- void setCurrent(Stream *stream) { _currentStr = stream; }
-
- /**
- * Gets the current output stream
- */
- Stream *getCurrent() const { return _currentStr; }
-
- /**
* Repaint an area of the windows
*/
void repaint(const Common::Rect &box);