GLK: Adding stream open/closing

This commit is contained in:
Paul Gilbert
2018-12-08 19:05:59 -08:00
committed by Paul Gilbert
parent 65091b25c1
commit cf5259d3bc
8 changed files with 89 additions and 52 deletions
+3 -3
View File
@@ -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() {
+4 -3
View File
@@ -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;
@@ -92,6 +89,10 @@ protected:
* Main game loop for the individual interpreters
*/
virtual void runGame(Common::SeekableReadStream *gameFile) = 0;
public:
Events *_events;
Streams *_streams;
Windows *_windows;
public:
GargoyleEngine(OSystem *syst, const GargoyleGameDescription *gameDesc);
virtual ~GargoyleEngine();
+5 -5
View File
@@ -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) {
+1 -1
View File
@@ -6,7 +6,7 @@ MODULE_OBJS := \
gargoyle.o \
glk.o \
picture.o \
stream.o \
streams.o \
windows.o \
scott/detection.o \
scott/scott.o
@@ -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) {
@@ -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; }
};
+7 -4
View File
@@ -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);
}
/*--------------------------------------------------------------------------*/
+5 -13
View File
@@ -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
@@ -113,16 +115,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
*/