diff options
76 files changed, 4232 insertions, 3269 deletions
diff --git a/backends/keymapper/hardware-key.h b/backends/keymapper/hardware-key.h index 8c46ee6358..9fd8d1981a 100644 --- a/backends/keymapper/hardware-key.h +++ b/backends/keymapper/hardware-key.h @@ -31,14 +31,12 @@ namespace Common { -#define HWKEY_ID_SIZE (30) - /** * Describes an available hardware key */ struct HardwareKey { /** unique id used for saving/loading to config */ - char hwKeyId[HWKEY_ID_SIZE]; + String id; /** Human readable description */ String description; @@ -49,11 +47,8 @@ struct HardwareKey { */ KeyState key; - HardwareKey(const char *i, KeyState ky = KeyState(), String desc = "") - : key(ky), description(desc) { - assert(i); - Common::strlcpy(hwKeyId, i, HWKEY_ID_SIZE); - } + HardwareKey(String i, KeyState ky = KeyState(), String desc = "") + : id(i), key(ky), description(desc) { } }; /** @@ -108,11 +103,11 @@ public: _keys.push_back(key); } - const HardwareKey *findHardwareKey(const char *id) const { + const HardwareKey *findHardwareKey(String id) const { List<const HardwareKey *>::const_iterator it; for (it = _keys.begin(); it != _keys.end(); it++) { - if (strncmp((*it)->hwKeyId, id, HWKEY_ID_SIZE) == 0) + if ((*it)->id == id) return (*it); } return 0; @@ -175,8 +170,8 @@ private: List<const HardwareKey *>::iterator it; for (it = _keys.begin(); it != _keys.end(); it++) { - if (strncmp((*it)->hwKeyId, key->hwKeyId, HWKEY_ID_SIZE) == 0) - error("Error adding HardwareKey '%s' - id of %s already in use!", key->description.c_str(), key->hwKeyId); + if ((*it)->id == key->id) + error("Error adding HardwareKey '%s' - id of %s already in use!", key->description.c_str(), key->id.c_str()); else if ((*it)->key == key->key) error("Error adding HardwareKey '%s' - key already in use!", key->description.c_str()); } diff --git a/backends/keymapper/keymap.cpp b/backends/keymapper/keymap.cpp index 5bee1a246d..3913fd149e 100644 --- a/backends/keymapper/keymap.cpp +++ b/backends/keymapper/keymap.cpp @@ -185,12 +185,10 @@ void Keymap::saveMappings() { actIdLen = (actIdLen > ACTION_ID_SIZE) ? ACTION_ID_SIZE : actIdLen; String actId((*it)->id, (*it)->id + actIdLen); - char hwId[HWKEY_ID_SIZE+1]; - - memset(hwId, 0, HWKEY_ID_SIZE+1); + String hwId = ""; if ((*it)->getMappedKey()) { - memcpy(hwId, (*it)->getMappedKey()->hwKeyId, HWKEY_ID_SIZE); + hwId = (*it)->getMappedKey()->id; } _configDomain->setVal(prefix + actId, hwId); } diff --git a/backends/keymapper/keymapper.cpp b/backends/keymapper/keymapper.cpp index aafdd604a2..189f862469 100644 --- a/backends/keymapper/keymapper.cpp +++ b/backends/keymapper/keymapper.cpp @@ -119,7 +119,7 @@ void Keymapper::cleanupGameKeymaps() { // the game specific (=deleted) ones. Stack<MapRecord> newStack; - for (int i = 0; i < _activeMaps.size(); i++) { + for (Stack<MapRecord>::size_type i = 0; i < _activeMaps.size(); i++) { if (_activeMaps[i].global) newStack.push(_activeMaps[i]); } diff --git a/backends/platform/iphone/iphone_common.h b/backends/platform/iphone/iphone_common.h index 5a46a6dde6..4dd9407064 100644 --- a/backends/platform/iphone/iphone_common.h +++ b/backends/platform/iphone/iphone_common.h @@ -23,6 +23,8 @@ #ifndef BACKENDS_PLATFORM_IPHONE_IPHONE_COMMON_H #define BACKENDS_PLATFORM_IPHONE_IPHONE_COMMON_H +#include "graphics/surface.h" + enum InputEvent { kInputMouseDown, kInputMouseUp, @@ -55,21 +57,39 @@ enum GraphicsModes { kGraphicsModeNone = 1 }; +struct VideoContext { + VideoContext() : screenWidth(), screenHeight(), overlayVisible(false), + overlayWidth(), overlayHeight(), mouseX(), mouseY(), + mouseHotspotX(), mouseHotspotY(), mouseWidth(), mouseHeight(), + mouseIsVisible(), graphicsMode(kGraphicsModeLinear), shakeOffsetY() { + } + + // Game screen state + uint screenWidth, screenHeight; + Graphics::Surface screenTexture; + + // Overlay state + bool overlayVisible; + uint overlayWidth, overlayHeight; + Graphics::Surface overlayTexture; + + // Mouse cursor state + uint mouseX, mouseY; + int mouseHotspotX, mouseHotspotY; + uint mouseWidth, mouseHeight; + bool mouseIsVisible; + Graphics::Surface mouseTexture; + + // Misc state + GraphicsModes graphicsMode; + int shakeOffsetY; +}; + // On the ObjC side -void iPhone_setGraphicsMode(GraphicsModes mode); -void iPhone_updateScreen(int mouseX, int mouseY); -void iPhone_updateScreenRect(unsigned short *screen, int x1, int y1, int x2, int y2); -void iPhone_updateOverlayRect(unsigned short *screen, int x1, int y1, int x2, int y2); -void iPhone_initSurface(int width, int height); -void iPhone_setShakeOffset(int offset); +void iPhone_updateScreen(); bool iPhone_fetchEvent(int *outEvent, int *outX, int *outY); const char *iPhone_getDocumentsDir(); bool iPhone_isHighResDevice(); -int iPhone_getScreenHeight(); -int iPhone_getScreenWidth(); -void iPhone_enableOverlay(int state); -void iPhone_showCursor(int state); -void iPhone_setMouseCursor(unsigned short *buffer, int width, int height, int hotspotX, int hotspotY); uint getSizeNextPOT(uint size); diff --git a/backends/platform/iphone/iphone_main.mm b/backends/platform/iphone/iphone_main.mm index 1559ef8a6e..20406e6342 100644 --- a/backends/platform/iphone/iphone_main.mm +++ b/backends/platform/iphone/iphone_main.mm @@ -20,6 +20,9 @@ * */ +// Disable symbol overrides so that we can use system headers. +#define FORBIDDEN_SYMBOL_ALLOW_ALL + #include <UIKit/UIKit.h> #include <Foundation/NSThread.h> diff --git a/backends/platform/iphone/iphone_video.h b/backends/platform/iphone/iphone_video.h index 43a643ab4a..168f9a4244 100644 --- a/backends/platform/iphone/iphone_video.h +++ b/backends/platform/iphone/iphone_video.h @@ -32,9 +32,11 @@ #include <OpenGLES/ES1/glext.h> #include "iphone_keyboard.h" +#include "iphone_common.h" @interface iPhoneView : UIView { - void *_screenSurface; + VideoContext _videoContext; + NSMutableArray *_events; SoftKeyboard *_keyboardView; @@ -47,18 +49,31 @@ UIDeviceOrientation _orientation; + GLint _renderBufferWidth; + GLint _renderBufferHeight; + GLfloat _gameScreenVertCoords[4 * 2]; GLfloat _gameScreenTexCoords[4 * 2]; + CGRect _gameScreenRect; GLfloat _overlayVertCoords[4 * 2]; GLfloat _overlayTexCoords[4 * 2]; + CGRect _overlayRect; + + GLfloat _mouseVertCoords[4 * 2]; + GLfloat _mouseTexCoords[4 * 2]; + GLint _mouseHotspotX, _mouseHotspotY; + GLint _mouseWidth, _mouseHeight; + GLfloat _mouseScaleX, _mouseScaleY; + + int _scaledShakeOffsetY; } - (id)initWithFrame:(struct CGRect)frame; -- (void)drawRect:(CGRect)frame; +- (VideoContext *)getVideoContext; -- (void *)getSurface; +- (void)drawRect:(CGRect)frame; - (void)initSurface; - (void)setViewTransformation; @@ -71,6 +86,8 @@ - (void)updateMouseSurface; - (void)clearColorBuffer; +- (void)notifyMouseMove; +- (void)updateMouseCursorScaling; - (void)updateMouseCursor; - (id)getEvent; @@ -83,4 +100,6 @@ @end +extern iPhoneView *g_iPhoneViewInstance; + #endif diff --git a/backends/platform/iphone/iphone_video.mm b/backends/platform/iphone/iphone_video.mm index 86365cbefe..3aa76681ab 100644 --- a/backends/platform/iphone/iphone_video.mm +++ b/backends/platform/iphone/iphone_video.mm @@ -20,49 +20,22 @@ * */ +// Disable symbol overrides so that we can use system headers. +#define FORBIDDEN_SYMBOL_ALLOW_ALL + #include "iphone_video.h" -#include "iphone_common.h" -static iPhoneView *sharedInstance = nil; -static GraphicsModes _graphicsMode = kGraphicsModeLinear; -static int _width = 0; -static int _height = 0; +#include "graphics/colormasks.h" + +iPhoneView *g_iPhoneViewInstance = nil; static int _fullWidth; static int _fullHeight; -static CGRect _gameScreenRect; - -static char *_gameScreenTextureBuffer = 0; -static int _gameScreenTextureWidth = 0; -static int _gameScreenTextureHeight = 0; - -static char *_overlayTexBuffer = 0; -static int _overlayTexWidth = 0; -static int _overlayTexHeight = 0; -static int _overlayWidth = 0; -static int _overlayHeight = 0; -static CGRect _overlayRect; static int _needsScreenUpdate = 0; -static int _overlayIsEnabled = 0; static UITouch *_firstTouch = NULL; static UITouch *_secondTouch = NULL; -static unsigned short *_mouseCursor = NULL; -static int _mouseCursorHeight = 0; -static int _mouseCursorWidth = 0; -static int _mouseCursorHotspotX = 0; -static int _mouseCursorHotspotY = 0; -static int _mouseX = 0; -static int _mouseY = 0; -static int _mouseCursorEnabled = 0; - -static GLint _renderBufferWidth; -static GLint _renderBufferHeight; - -static int _shakeOffsetY; -static int _scaledShakeOffsetY; - #if 0 static long lastTick = 0; static int frames = 0; @@ -83,83 +56,20 @@ int printOglError(const char *file, int line) { return retCode; } -void iPhone_setGraphicsMode(GraphicsModes mode) { - _graphicsMode = mode; - - [sharedInstance performSelectorOnMainThread:@selector(setGraphicsMode) withObject:nil waitUntilDone: YES]; -} - -void iPhone_showCursor(int state) { - _mouseCursorEnabled = state; -} - -void iPhone_setMouseCursor(unsigned short *buffer, int width, int height, int hotspotX, int hotspotY) { - _mouseCursor = buffer; - - _mouseCursorWidth = width; - _mouseCursorHeight = height; - - _mouseCursorHotspotX = hotspotX; - _mouseCursorHotspotY = hotspotY; - - [sharedInstance performSelectorOnMainThread:@selector(updateMouseCursor) withObject:nil waitUntilDone: YES]; -} - -void iPhone_enableOverlay(int state) { - _overlayIsEnabled = state; - - [sharedInstance performSelectorOnMainThread:@selector(clearColorBuffer) withObject:nil waitUntilDone: YES]; -} - -int iPhone_getScreenHeight() { - return _overlayHeight; -} - -int iPhone_getScreenWidth() { - return _overlayWidth; -} - bool iPhone_isHighResDevice() { return _fullHeight > 480; } -void iPhone_updateScreen(int mouseX, int mouseY) { +void iPhone_updateScreen() { //printf("Mouse: (%i, %i)\n", mouseX, mouseY); - - _mouseX = mouseX; - _mouseY = mouseY; - if (!_needsScreenUpdate) { _needsScreenUpdate = 1; - [sharedInstance performSelectorOnMainThread:@selector(updateSurface) withObject:nil waitUntilDone: NO]; + [g_iPhoneViewInstance performSelectorOnMainThread:@selector(updateSurface) withObject:nil waitUntilDone: NO]; } } -void iPhone_updateScreenRect(unsigned short *screen, int x1, int y1, int x2, int y2) { - for (int y = y1; y < y2; ++y) - memcpy(&_gameScreenTextureBuffer[(y * _gameScreenTextureWidth + x1) * 2], &screen[y * _width + x1], (x2 - x1) * 2); -} - -void iPhone_updateOverlayRect(unsigned short *screen, int x1, int y1, int x2, int y2) { - //printf("Overlaywidth: %u, fullwidth %u\n", _overlayWidth, _fullWidth); - for (int y = y1; y < y2; ++y) - memcpy(&_overlayTexBuffer[(y * _overlayTexWidth + x1) * 2], &screen[y * _overlayWidth + x1], (x2 - x1) * 2); -} - -void iPhone_initSurface(int width, int height) { - _width = width; - _height = height; - _shakeOffsetY = 0; - [sharedInstance performSelectorOnMainThread:@selector(initSurface) withObject:nil waitUntilDone: YES]; -} - -void iPhone_setShakeOffset(int offset) { - _shakeOffsetY = offset; - [sharedInstance performSelectorOnMainThread:@selector(setViewTransformation) withObject:nil waitUntilDone: YES]; -} - bool iPhone_fetchEvent(int *outEvent, int *outX, int *outY) { - id event = [sharedInstance getEvent]; + id event = [g_iPhoneViewInstance getEvent]; if (event == nil) { return false; } @@ -196,92 +106,16 @@ const char *iPhone_getDocumentsDir() { return [documentsDirectory UTF8String]; } -/** - * Converts portrait mode coordinates into rotated mode coordinates. - */ -static bool convertToRotatedCoords(UIDeviceOrientation orientation, CGPoint point, CGPoint *result) { - switch (orientation) { - case UIDeviceOrientationLandscapeLeft: - result->x = point.y; - result->y = _renderBufferWidth - point.x; - return true; - - case UIDeviceOrientationLandscapeRight: - result->x = _renderBufferHeight - point.y; - result->y = point.x; - return true; - - case UIDeviceOrientationPortrait: - result->x = point.x; - result->y = point.y; - return true; - - default: - return false; - } -} - -static bool getMouseCoords(UIDeviceOrientation orientation, CGPoint point, int *x, int *y) { - if (!convertToRotatedCoords(orientation, point, &point)) - return false; - - CGRect *area; - int width, height, offsetY; - if (_overlayIsEnabled) { - area = &_overlayRect; - width = _overlayWidth; - height = _overlayHeight; - offsetY = _shakeOffsetY; - } else { - area = &_gameScreenRect; - width = _width; - height = _height; - offsetY = _scaledShakeOffsetY; - } - - point.x = (point.x - CGRectGetMinX(*area)) / CGRectGetWidth(*area); - point.y = (point.y - CGRectGetMinY(*area)) / CGRectGetHeight(*area); - - *x = (int)(point.x * width); - // offsetY describes the translation of the screen in the upward direction, - // thus we need to add it here. - *y = (int)(point.y * height + offsetY); - - // Clip coordinates - if (*x < 0 || *x > CGRectGetWidth(*area) || *y < 0 || *y > CGRectGetHeight(*area)) - return false; - - return true; -} - -static void setFilterModeForTexture(GLuint tex, GraphicsModes mode) { - if (!tex) - return; - - glBindTexture(GL_TEXTURE_2D, tex); printOpenGLError(); - - GLint filter = GL_LINEAR; - - switch (mode) { - case kGraphicsModeLinear: - filter = GL_LINEAR; - break; - - case kGraphicsModeNone: - filter = GL_NEAREST; - break; - } - - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter); printOpenGLError(); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter); printOpenGLError(); -} - @implementation iPhoneView + (Class)layerClass { return [CAEAGLLayer class]; } +- (VideoContext *)getVideoContext { + return &_videoContext; +} + - (void)createContext { CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer; @@ -317,20 +151,18 @@ static void setFilterModeForTexture(GLuint tex, GraphicsModes mode) { return; } - _overlayHeight = _renderBufferWidth; - _overlayWidth = _renderBufferHeight; - _overlayTexWidth = getSizeNextPOT(_overlayHeight); - _overlayTexHeight = getSizeNextPOT(_overlayWidth); + _videoContext.overlayHeight = _renderBufferWidth; + _videoContext.overlayWidth = _renderBufferHeight; + uint overlayTextureWidth = getSizeNextPOT(_videoContext.overlayHeight); + uint overlayTextureHeight = getSizeNextPOT(_videoContext.overlayWidth); // Since the overlay size won't change the whole run, we can // precalculate the texture coordinates for the overlay texture here // and just use it later on. - _overlayTexCoords[2] = _overlayTexCoords[6] = _overlayWidth / (GLfloat)_overlayTexWidth; - _overlayTexCoords[5] = _overlayTexCoords[7] = _overlayHeight / (GLfloat)_overlayTexHeight; + _overlayTexCoords[2] = _overlayTexCoords[6] = _videoContext.overlayWidth / (GLfloat)overlayTextureWidth; + _overlayTexCoords[5] = _overlayTexCoords[7] = _videoContext.overlayHeight / (GLfloat)overlayTextureHeight; - int textureSize = _overlayTexWidth * _overlayTexHeight * 2; - _overlayTexBuffer = (char *)malloc(textureSize); - memset(_overlayTexBuffer, 0, textureSize); + _videoContext.overlayTexture.create(overlayTextureWidth, overlayTextureHeight, Graphics::createPixelFormat<5551>()); glViewport(0, 0, _renderBufferWidth, _renderBufferHeight); printOpenGLError(); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); printOpenGLError(); @@ -356,13 +188,15 @@ static void setFilterModeForTexture(GLuint tex, GraphicsModes mode) { _fullWidth = (int)frame.size.width; _fullHeight = (int)frame.size.height; - sharedInstance = self; + g_iPhoneViewInstance = self; _keyboardView = nil; _screenTexture = 0; _overlayTexture = 0; _mouseCursorTexture = 0; + _scaledShakeOffsetY = 0; + _gameScreenVertCoords[0] = _gameScreenVertCoords[1] = _gameScreenVertCoords[2] = _gameScreenVertCoords[3] = _gameScreenVertCoords[4] = _gameScreenVertCoords[5] = @@ -383,6 +217,16 @@ static void setFilterModeForTexture(GLuint tex, GraphicsModes mode) { _overlayTexCoords[4] = _overlayTexCoords[5] = _overlayTexCoords[6] = _overlayTexCoords[7] = 0; + _mouseVertCoords[0] = _mouseVertCoords[1] = + _mouseVertCoords[2] = _mouseVertCoords[3] = + _mouseVertCoords[4] = _mouseVertCoords[5] = + _mouseVertCoords[6] = _mouseVertCoords[7] = 0; + + _mouseTexCoords[0] = _mouseTexCoords[1] = + _mouseTexCoords[2] = _mouseTexCoords[3] = + _mouseTexCoords[4] = _mouseTexCoords[5] = + _mouseTexCoords[6] = _mouseTexCoords[7] = 0; + // Initialize the OpenGL ES context [self createContext]; @@ -396,12 +240,9 @@ static void setFilterModeForTexture(GLuint tex, GraphicsModes mode) { [_keyboardView dealloc]; } - free(_gameScreenTextureBuffer); - free(_overlayTexBuffer); -} - -- (void *)getSurface { - return _screenSurface; + _videoContext.screenTexture.free(); + _videoContext.overlayTexture.free(); + _videoContext.mouseTexture.free(); } - (void)drawRect:(CGRect)frame { @@ -419,10 +260,32 @@ static void setFilterModeForTexture(GLuint tex, GraphicsModes mode) { #endif } +- (void)setFilterModeForTexture:(GLuint)tex { + if (!tex) + return; + + glBindTexture(GL_TEXTURE_2D, tex); printOpenGLError(); + + GLint filter = GL_LINEAR; + + switch (_videoContext.graphicsMode) { + case kGraphicsModeLinear: + filter = GL_LINEAR; + break; + + case kGraphicsModeNone: + filter = GL_NEAREST; + break; + } + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter); printOpenGLError(); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter); printOpenGLError(); +} + - (void)setGraphicsMode { - setFilterModeForTexture(_screenTexture, _graphicsMode); - setFilterModeForTexture(_overlayTexture, _graphicsMode); - setFilterModeForTexture(_mouseCursorTexture, _graphicsMode); + [self setFilterModeForTexture:_screenTexture]; + [self setFilterModeForTexture:_overlayTexture]; + [self setFilterModeForTexture:_mouseCursorTexture]; } - (void)updateSurface { @@ -435,10 +298,10 @@ static void setFilterModeForTexture(GLuint tex, GraphicsModes mode) { [self updateMainSurface]; - if (_overlayIsEnabled) + if (_videoContext.overlayVisible) [self updateOverlaySurface]; - if (_mouseCursorEnabled) + if (_videoContext.mouseIsVisible) [self updateMouseSurface]; glBindRenderbufferOES(GL_RENDERBUFFER_OES, _viewRenderbuffer); printOpenGLError(); @@ -446,17 +309,70 @@ static void setFilterModeForTexture(GLuint tex, GraphicsModes mode) { } +- (void)notifyMouseMove { + const GLint mouseX = (GLint)(_videoContext.mouseX * _mouseScaleX) - _mouseHotspotX; + const GLint mouseY = (GLint)(_videoContext.mouseY * _mouseScaleY) - _mouseHotspotY; + + _mouseVertCoords[0] = _mouseVertCoords[4] = mouseX; + _mouseVertCoords[1] = _mouseVertCoords[3] = mouseY; + _mouseVertCoords[2] = _mouseVertCoords[6] = mouseX + _mouseWidth; + _mouseVertCoords[5] = _mouseVertCoords[7] = mouseY + _mouseHeight; +} + +- (void)updateMouseCursorScaling { + CGRect *rect; + int maxWidth, maxHeight; + + if (!_videoContext.overlayVisible) { + rect = &_gameScreenRect; + maxWidth = _videoContext.screenWidth; + maxHeight = _videoContext.screenHeight; + } else { + rect = &_overlayRect; + maxWidth = _videoContext.overlayWidth; + maxHeight = _videoContext.overlayHeight; + } + + if (!maxWidth || !maxHeight) { + printf("WARNING: updateMouseCursorScaling called when screen was not ready (%d)!\n", _videoContext.overlayVisible); + return; + } + + _mouseScaleX = CGRectGetWidth(*rect) / (GLfloat)maxWidth; + _mouseScaleY = CGRectGetHeight(*rect) / (GLfloat)maxHeight; + + _mouseWidth = (GLint)(_videoContext.mouseWidth * _mouseScaleX); + _mouseHeight = (GLint)(_videoContext.mouseHeight * _mouseScaleY); + + _mouseHotspotX = (GLint)(_videoContext.mouseHotspotX * _mouseScaleX); + _mouseHotspotY = (GLint)(_videoContext.mouseHotspotY * _mouseScaleY); + + // We subtract the screen offset to the hotspot here to simplify the + // screen offset handling in the mouse code. Note the subtraction here + // makes sure that the offset actually gets added to the mouse position, + // since the hotspot offset is substracted from the position. + _mouseHotspotX -= (GLint)CGRectGetMinX(*rect); + _mouseHotspotY -= (GLint)CGRectGetMinY(*rect); + + // FIXME: For now we also adapt the mouse position here. In reality we + // would be better off to also adjust the event position when switching + // from overlay to game screen or vica versa. + [self notifyMouseMove]; +} + - (void)updateMouseCursor { if (_mouseCursorTexture == 0) { glGenTextures(1, &_mouseCursorTexture); printOpenGLError(); - setFilterModeForTexture(_mouseCursorTexture, _graphicsMode); + [self setFilterModeForTexture:_mouseCursorTexture]; } - glBindTexture(GL_TEXTURE_2D, _mouseCursorTexture); printOpenGLError(); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getSizeNextPOT(_mouseCursorWidth), getSizeNextPOT(_mouseCursorHeight), 0, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, _mouseCursor); printOpenGLError(); + [self updateMouseCursorScaling]; + + _mouseTexCoords[2] = _mouseTexCoords[6] = _videoContext.mouseWidth / (GLfloat)_videoContext.mouseTexture.w; + _mouseTexCoords[5] = _mouseTexCoords[7] = _videoContext.mouseHeight / (GLfloat)_videoContext.mouseTexture.h; - free(_mouseCursor); - _mouseCursor = NULL; + glBindTexture(GL_TEXTURE_2D, _mouseCursorTexture); printOpenGLError(); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, _videoContext.mouseTexture.w, _videoContext.mouseTexture.h, 0, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, _videoContext.mouseTexture.pixels); printOpenGLError(); } - (void)updateMainSurface { @@ -468,7 +384,7 @@ static void setFilterModeForTexture(GLuint tex, GraphicsModes mode) { // Unfortunately we have to update the whole texture every frame, since glTexSubImage2D is actually slower in all cases // due to the iPhone internals having to convert the whole texture back from its internal format when used. // In the future we could use several tiled textures instead. - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, _gameScreenTextureWidth, _gameScreenTextureHeight, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, _gameScreenTextureBuffer); printOpenGLError(); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, _videoContext.screenTexture.w, _videoContext.screenTexture.h, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, _videoContext.screenTexture.pixels); printOpenGLError(); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); printOpenGLError(); } @@ -477,147 +393,81 @@ static void setFilterModeForTexture(GLuint tex, GraphicsModes mode) { glTexCoordPointer(2, GL_FLOAT, 0, _overlayTexCoords); printOpenGLError(); glBindTexture(GL_TEXTURE_2D, _overlayTexture); printOpenGLError(); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, _overlayTexWidth, _overlayTexHeight, 0, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, _overlayTexBuffer); printOpenGLError(); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, _videoContext.overlayTexture.w, _videoContext.overlayTexture.h, 0, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, _videoContext.overlayTexture.pixels); printOpenGLError(); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); printOpenGLError(); } - (void)updateMouseSurface { - int width = _mouseCursorWidth; - int height = _mouseCursorHeight; - - int mouseX = _mouseX; - int mouseY = _mouseY; - - int hotspotX = _mouseCursorHotspotX; - int hotspotY = _mouseCursorHotspotY; - - CGRect *rect; - int maxWidth, maxHeight; - - if (!_overlayIsEnabled) { - rect = &_gameScreenRect; - maxWidth = _width; - maxHeight = _height; - } else { - rect = &_overlayRect; - maxWidth = _overlayWidth; - maxHeight = _overlayHeight; - } - - const GLfloat scaleX = CGRectGetWidth(*rect) / (GLfloat)maxWidth; - const GLfloat scaleY = CGRectGetHeight(*rect) / (GLfloat)maxHeight; - - mouseX = (int)(mouseX * scaleX); - mouseY = (int)(mouseY * scaleY); - hotspotX = (int)(hotspotX * scaleX); - hotspotY = (int)(hotspotY * scaleY); - width = (int)(width * scaleX); - height = (int)(height * scaleY); - - mouseX -= hotspotX; - mouseY -= hotspotY; - - mouseX += (int)CGRectGetMinX(*rect); - mouseY += (int)CGRectGetMinY(*rect); - - GLfloat vertices[] = { - // Top left - mouseX , mouseY, - // Top right - mouseX + width, mouseY, - // Bottom left - mouseX , mouseY + height, - // Bottom right - mouseX + width, mouseY + height - }; - - //printf("Cursor: width %u height %u\n", _mouseCursorWidth, _mouseCursorHeight); - - float texWidth = _mouseCursorWidth / (float)getSizeNextPOT(_mouseCursorWidth); - float texHeight = _mouseCursorHeight / (float)getSizeNextPOT(_mouseCursorHeight); - - const GLfloat texCoords[] = { - // Top left - 0 , 0, - // Top right - texWidth, 0, - // Bottom left - 0 , texHeight, - // Bottom right - texWidth, texHeight - }; - - glVertexPointer(2, GL_FLOAT, 0, vertices); printOpenGLError(); - glTexCoordPointer(2, GL_FLOAT, 0, texCoords); printOpenGLError(); + glVertexPointer(2, GL_FLOAT, 0, _mouseVertCoords); printOpenGLError(); + glTexCoordPointer(2, GL_FLOAT, 0, _mouseTexCoords); printOpenGLError(); glBindTexture(GL_TEXTURE_2D, _mouseCursorTexture); printOpenGLError(); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); printOpenGLError(); } -- (void)initSurface { - _gameScreenTextureWidth = getSizeNextPOT(_width); - _gameScreenTextureHeight = getSizeNextPOT(_height); - - _gameScreenTexCoords[2] = _gameScreenTexCoords[6] = _width / (GLfloat)_gameScreenTextureWidth; - _gameScreenTexCoords[5] = _gameScreenTexCoords[7] = _height / (GLfloat)_gameScreenTextureHeight; - - _orientation = [[UIDevice currentDevice] orientation]; - - switch (_orientation) { - case UIDeviceOrientationLandscapeLeft: - case UIDeviceOrientationLandscapeRight: - case UIDeviceOrientationPortrait: - break; - - default: - _orientation = UIDeviceOrientationPortrait; - } - - //printf("Window: (%d, %d), Surface: (%d, %d), Texture(%d, %d)\n", _fullWidth, _fullHeight, _width, _height, _gameScreenTextureWidth, _gameScreenTextureHeight); +- (void)setUpOrientation:(UIDeviceOrientation)orientation width:(int *)width height:(int *)height { + _orientation = orientation; glMatrixMode(GL_PROJECTION); glLoadIdentity(); - int screenWidth, screenHeight; - - // Set the origin (0,0) depending on the rotation mode. - if (_orientation == UIDeviceOrientationLandscapeRight) { + // We always force the origin (0,0) to be in the upper left corner. + switch (_orientation) { + case UIDeviceOrientationLandscapeRight: glRotatef( 90, 0, 0, 1); printOpenGLError(); glOrthof(0, _renderBufferHeight, _renderBufferWidth, 0, 0, 1); printOpenGLError(); - screenWidth = _renderBufferHeight; - screenHeight = _renderBufferWidth; - } else if (_orientation == UIDeviceOrientationLandscapeLeft) { + *width = _renderBufferHeight; + *height = _renderBufferWidth; + break; + + case UIDeviceOrientationLandscapeLeft: glRotatef(-90, 0, 0, 1); printOpenGLError(); glOrthof(0, _renderBufferHeight, _renderBufferWidth, 0, 0, 1); printOpenGLError(); - screenWidth = _renderBufferHeight; - screenHeight = _renderBufferWidth; - } else if (_orientation == UIDeviceOrientationPortrait) { + *width = _renderBufferHeight; + *height = _renderBufferWidth; + break; + + case UIDeviceOrientationPortrait: + default: + // We must force the portrait orientation here, since we might not know + // the real orientation. + _orientation = UIDeviceOrientationPortrait; + glOrthof(0, _renderBufferWidth, _renderBufferHeight, 0, 0, 1); printOpenGLError(); - screenWidth = _renderBufferWidth; - screenHeight = _renderBufferHeight; + *width = _renderBufferWidth; + *height = _renderBufferHeight; + break; } +} + +- (void)initSurface { + uint screenTexWidth = getSizeNextPOT(_videoContext.screenWidth); + uint screenTexHeight = getSizeNextPOT(_videoContext.screenHeight); + + _gameScreenTexCoords[2] = _gameScreenTexCoords[6] = _videoContext.screenWidth / (GLfloat)screenTexWidth; + _gameScreenTexCoords[5] = _gameScreenTexCoords[7] = _videoContext.screenHeight / (GLfloat)screenTexHeight; + + int screenWidth, screenHeight; + [self setUpOrientation:[[UIDevice currentDevice] orientation] width:&screenWidth height:&screenHeight]; if (_screenTexture > 0) { glDeleteTextures(1, &_screenTexture); printOpenGLError(); } glGenTextures(1, &_screenTexture); printOpenGLError(); - setFilterModeForTexture(_screenTexture, _graphicsMode); + [self setFilterModeForTexture:_screenTexture]; if (_overlayTexture > 0) { glDeleteTextures(1, &_overlayTexture); printOpenGLError(); } glGenTextures(1, &_overlayTexture); printOpenGLError(); - setFilterModeForTexture(_overlayTexture, _graphicsMode); + [self setFilterModeForTexture:_overlayTexture]; - free(_gameScreenTextureBuffer); - int textureSize = _gameScreenTextureWidth * _gameScreenTextureHeight * 2; - _gameScreenTextureBuffer = (char *)malloc(textureSize); - memset(_gameScreenTextureBuffer, 0, textureSize); + _videoContext.screenTexture.create(screenTexWidth, screenTexHeight, Graphics::createPixelFormat<565>()); glBindRenderbufferOES(GL_RENDERBUFFER_OES, _viewRenderbuffer); printOpenGLError(); @@ -631,7 +481,7 @@ static void setFilterModeForTexture(GLuint tex, GraphicsModes mode) { float overlayPortraitRatio; if (_orientation == UIDeviceOrientationLandscapeLeft || _orientation == UIDeviceOrientationLandscapeRight) { - GLfloat gameScreenRatio = (GLfloat)_width / (GLfloat)_height; + GLfloat gameScreenRatio = (GLfloat)_videoContext.screenWidth / (GLfloat)_videoContext.screenHeight; GLfloat screenRatio = (GLfloat)screenWidth / (GLfloat)screenHeight; // These are the width/height according to the portrait layout! @@ -660,7 +510,7 @@ static void setFilterModeForTexture(GLuint tex, GraphicsModes mode) { _gameScreenRect = CGRectMake(xOffset, yOffset, rectWidth, rectHeight); overlayPortraitRatio = 1.0f; } else { - float ratio = (float)_height / (float)_width; + float ratio = (float)_videoContext.screenHeight / (float)_videoContext.screenWidth; int height = (int)(screenWidth * ratio); //printf("Making rect (%u, %u)\n", screenWidth, height); _gameScreenRect = CGRectMake(0, 0, screenWidth, height); @@ -674,7 +524,7 @@ static void setFilterModeForTexture(GLuint tex, GraphicsModes mode) { [self addSubview:[_keyboardView inputView]]; [self addSubview: _keyboardView]; [[_keyboardView inputView] becomeFirstResponder]; - overlayPortraitRatio = (_overlayHeight * ratio) / _overlayWidth; + overlayPortraitRatio = (_videoContext.overlayHeight * ratio) / _videoContext.overlayWidth; } _overlayRect = CGRectMake(0, 0, screenWidth, screenHeight * overlayPortraitRatio); @@ -688,6 +538,7 @@ static void setFilterModeForTexture(GLuint tex, GraphicsModes mode) { _overlayVertCoords[5] = _overlayVertCoords[7] = CGRectGetMaxY(_overlayRect); [self setViewTransformation]; + [self updateMouseCursorScaling]; } - (void)setViewTransformation { @@ -698,7 +549,7 @@ static void setFilterModeForTexture(GLuint tex, GraphicsModes mode) { // Scale the shake offset according to the overlay size. We need this to // adjust the overlay mouse click coordinates when an offset is set. - _scaledShakeOffsetY = (int)(_shakeOffsetY / (GLfloat)_height * CGRectGetHeight(_overlayRect)); + _scaledShakeOffsetY = (int)(_videoContext.shakeOffsetY / (GLfloat)_videoContext.screenHeight * CGRectGetHeight(_overlayRect)); // Apply the shakeing to the output screen. glTranslatef(0, -_scaledShakeOffsetY, 0); @@ -732,6 +583,64 @@ static void setFilterModeForTexture(GLuint tex, GraphicsModes mode) { [_events addObject: event]; } +/** + * Converts portrait mode coordinates into rotated mode coordinates. + */ +- (bool)convertToRotatedCoords:(CGPoint)point result:(CGPoint *)result { + switch (_orientation) { + case UIDeviceOrientationLandscapeLeft: + result->x = point.y; + result->y = _renderBufferWidth - point.x; + return true; + + case UIDeviceOrientationLandscapeRight: + result->x = _renderBufferHeight - point.y; + result->y = point.x; + return true; + + case UIDeviceOrientationPortrait: + result->x = point.x; + result->y = point.y; + return true; + + default: + return false; + } +} + +- (bool)getMouseCoords:(CGPoint)point eventX:(int *)x eventY:(int *)y { + if (![self convertToRotatedCoords:point result:&point]) + return false; + + CGRect *area; + int width, height, offsetY; + if (_videoContext.overlayVisible) { + area = &_overlayRect; + width = _videoContext.overlayWidth; + height = _videoContext.overlayHeight; + offsetY = _scaledShakeOffsetY; + } else { + area = &_gameScreenRect; + width = _videoContext.screenWidth; + height = _videoContext.screenHeight; + offsetY = _videoContext.shakeOffsetY; + } + + point.x = (point.x - CGRectGetMinX(*area)) / CGRectGetWidth(*area); + point.y = (point.y - CGRectGetMinY(*area)) / CGRectGetHeight(*area); + + *x = (int)(point.x * width); + // offsetY describes the translation of the screen in the upward direction, + // thus we need to add it here. + *y = (int)(point.y * height + offsetY); + + // Clip coordinates + if (*x < 0 || *x > width || *y < 0 || *y > height) + return false; + + return true; +} + - (void)deviceOrientationChanged:(UIDeviceOrientation)orientation { switch (orientation) { case UIDeviceOrientationLandscapeLeft: @@ -762,7 +671,7 @@ static void setFilterModeForTexture(GLuint tex, GraphicsModes mode) { case 1: { UITouch *touch = [touches anyObject]; CGPoint point = [touch locationInView:self]; - if (!getMouseCoords(_orientation, point, &x, &y)) + if (![self getMouseCoords:point eventX:&x eventY:&y]) return; _firstTouch = touch; @@ -780,7 +689,7 @@ static void setFilterModeForTexture(GLuint tex, GraphicsModes mode) { case 2: { UITouch *touch = [touches anyObject]; CGPoint point = [touch locationInView:self]; - if (!getMouseCoords(_orientation, point, &x, &y)) + if (![self getMouseCoords:point eventX:&x eventY:&y]) return; _secondTouch = touch; @@ -804,7 +713,7 @@ static void setFilterModeForTexture(GLuint tex, GraphicsModes mode) { for (UITouch *touch in touches) { if (touch == _firstTouch) { CGPoint point = [touch locationInView:self]; - if (!getMouseCoords(_orientation, point, &x, &y)) + if (![self getMouseCoords:point eventX:&x eventY:&y]) return; [self addEvent: @@ -817,7 +726,7 @@ static void setFilterModeForTexture(GLuint tex, GraphicsModes mode) { ]; } else if (touch == _secondTouch) { CGPoint point = [touch locationInView:self]; - if (!getMouseCoords(_orientation, point, &x, &y)) + if (![self getMouseCoords:point eventX:&x eventY:&y]) return; [self addEvent: @@ -840,7 +749,7 @@ static void setFilterModeForTexture(GLuint tex, GraphicsModes mode) { case 1: { UITouch *touch = [[allTouches allObjects] objectAtIndex:0]; CGPoint point = [touch locationInView:self]; - if (!getMouseCoords(_orientation, point, &x, &y)) + if (![self getMouseCoords:point eventX:&x eventY:&y]) return; [self addEvent: @@ -857,7 +766,7 @@ static void setFilterModeForTexture(GLuint tex, GraphicsModes mode) { case 2: { UITouch *touch = [[allTouches allObjects] objectAtIndex:1]; CGPoint point = [touch locationInView:self]; - if (!getMouseCoords(_orientation, point, &x, &y)) + if (![self getMouseCoords:point eventX:&x eventY:&y]) return; [self addEvent: diff --git a/backends/platform/iphone/osys_events.cpp b/backends/platform/iphone/osys_events.cpp index c167da35e6..85efbda208 100644 --- a/backends/platform/iphone/osys_events.cpp +++ b/backends/platform/iphone/osys_events.cpp @@ -122,8 +122,8 @@ bool OSystem_IPHONE::handleEvent_mouseDown(Common::Event &event, int x, int y) { if (_mouseClickAndDragEnabled) { event.type = Common::EVENT_LBUTTONDOWN; - event.mouse.x = _mouseX; - event.mouse.y = _mouseY; + event.mouse.x = _videoContext->mouseX; + event.mouse.y = _videoContext->mouseY; return true; } else { _lastMouseDown = getMillis(); @@ -140,17 +140,17 @@ bool OSystem_IPHONE::handleEvent_mouseUp(Common::Event &event, int x, int y) { return false; } else if (_mouseClickAndDragEnabled) { event.type = Common::EVENT_LBUTTONUP; - event.mouse.x = _mouseX; - event.mouse.y = _mouseY; + event.mouse.x = _videoContext->mouseX; + event.mouse.y = _videoContext->mouseY; } else { if (getMillis() - _lastMouseDown < 250) { event.type = Common::EVENT_LBUTTONDOWN; - event.mouse.x = _mouseX; - event.mouse.y = _mouseY; + event.mouse.x = _videoContext->mouseX; + event.mouse.y = _videoContext->mouseY; _queuedInputEvent.type = Common::EVENT_LBUTTONUP; - _queuedInputEvent.mouse.x = _mouseX; - _queuedInputEvent.mouse.y = _mouseY; + _queuedInputEvent.mouse.x = _videoContext->mouseX; + _queuedInputEvent.mouse.y = _videoContext->mouseY; _lastMouseTap = getMillis(); _queuedEventTime = _lastMouseTap + kQueuedInputEventDelay; } else @@ -167,12 +167,12 @@ bool OSystem_IPHONE::handleEvent_secondMouseDown(Common::Event &event, int x, in if (_mouseClickAndDragEnabled) { event.type = Common::EVENT_LBUTTONUP; - event.mouse.x = _mouseX; - event.mouse.y = _mouseY; + event.mouse.x = _videoContext->mouseX; + event.mouse.y = _videoContext->mouseY; _queuedInputEvent.type = Common::EVENT_RBUTTONDOWN; - _queuedInputEvent.mouse.x = _mouseX; - _queuedInputEvent.mouse.y = _mouseY; + _queuedInputEvent.mouse.x = _videoContext->mouseX; + _queuedInputEvent.mouse.y = _videoContext->mouseY; } else return false; @@ -184,7 +184,7 @@ bool OSystem_IPHONE::handleEvent_secondMouseUp(Common::Event &event, int x, int if (curTime - _lastSecondaryDown < 400) { //printf("Right tap!\n"); - if (curTime - _lastSecondaryTap < 400 && !_overlayVisible) { + if (curTime - _lastSecondaryTap < 400 && !_videoContext->overlayVisible) { //printf("Right escape!\n"); event.type = Common::EVENT_KEYDOWN; _queuedInputEvent.type = Common::EVENT_KEYUP; @@ -197,11 +197,11 @@ bool OSystem_IPHONE::handleEvent_secondMouseUp(Common::Event &event, int x, int } else if (!_mouseClickAndDragEnabled) { //printf("Rightclick!\n"); event.type = Common::EVENT_RBUTTONDOWN; - event.mouse.x = _mouseX; - event.mouse.y = _mouseY; + event.mouse.x = _videoContext->mouseX; + event.mouse.y = _videoContext->mouseY; _queuedInputEvent.type = Common::EVENT_RBUTTONUP; - _queuedInputEvent.mouse.x = _mouseX; - _queuedInputEvent.mouse.y = _mouseY; + _queuedInputEvent.mouse.x = _videoContext->mouseX; + _queuedInputEvent.mouse.y = _videoContext->mouseY; _lastSecondaryTap = curTime; _queuedEventTime = curTime + kQueuedInputEventDelay; } else { @@ -211,8 +211,8 @@ bool OSystem_IPHONE::handleEvent_secondMouseUp(Common::Event &event, int x, int } if (_mouseClickAndDragEnabled) { event.type = Common::EVENT_RBUTTONUP; - event.mouse.x = _mouseX; - event.mouse.y = _mouseY; + event.mouse.x = _videoContext->mouseX; + event.mouse.y = _videoContext->mouseY; } return true; @@ -234,11 +234,11 @@ bool OSystem_IPHONE::handleEvent_mouseDragged(Common::Event &event, int x, int y _lastPadX = x; _lastPadY = y; - mouseNewPosX = (int)(_mouseX - deltaX / 0.5f); - mouseNewPosY = (int)(_mouseY - deltaY / 0.5f); + mouseNewPosX = (int)(_videoContext->mouseX - deltaX / 0.5f); + mouseNewPosY = (int)(_videoContext->mouseY - deltaY / 0.5f); - int widthCap = _overlayVisible ? _overlayWidth : _screenWidth; - int heightCap = _overlayVisible ? _overlayHeight : _screenHeight; + int widthCap = _videoContext->overlayVisible ? _videoContext->overlayWidth : _videoContext->screenWidth; + int heightCap = _videoContext->overlayVisible ? _videoContext->overlayHeight : _videoContext->screenHeight; if (mouseNewPosX < 0) mouseNewPosX = 0; @@ -350,10 +350,10 @@ void OSystem_IPHONE::handleEvent_orientationChanged(int orientation) { if (_screenOrientation != newOrientation) { _screenOrientation = newOrientation; - iPhone_initSurface(_screenWidth, _screenHeight); + updateOutputSurface(); dirtyFullScreen(); - if (_overlayVisible) + if (_videoContext->overlayVisible) dirtyFullOverlayScreen(); updateScreen(); } diff --git a/backends/platform/iphone/osys_main.cpp b/backends/platform/iphone/osys_main.cpp index 2bdc09c9ce..dabf73bf58 100644 --- a/backends/platform/iphone/osys_main.cpp +++ b/backends/platform/iphone/osys_main.cpp @@ -56,17 +56,16 @@ void *OSystem_IPHONE::s_soundParam = NULL; OSystem_IPHONE::OSystem_IPHONE() : _mixer(NULL), _gameScreenRaw(NULL), - _overlayVisible(false), _gameScreenConverted(NULL), - _mouseHeight(0), _mouseWidth(0), _mouseBuf(NULL), _lastMouseTap(0), _queuedEventTime(0), + _mouseBuf(NULL), _lastMouseTap(0), _queuedEventTime(0), _mouseNeedTextureUpdate(false), _secondaryTapped(false), _lastSecondaryTap(0), _screenOrientation(kScreenOrientationFlippedLandscape), _mouseClickAndDragEnabled(false), _gestureStartX(-1), _gestureStartY(-1), _fullScreenIsDirty(false), _fullScreenOverlayIsDirty(false), _mouseDirty(false), _timeSuspended(0), _lastDragPosX(-1), _lastDragPosY(-1), _screenChangeCount(0), - _overlayHeight(0), _overlayWidth(0), _overlayBuffer(0), _mouseCursorPaletteEnabled(false), - _currentGraphicsMode(kGraphicsModeLinear) { + _mouseCursorPaletteEnabled(false) { _queuedInputEvent.type = Common::EVENT_INVALID; _touchpadModeEnabled = !iPhone_isHighResDevice(); _fsFactory = new POSIXFilesystemFactory(); + initVideoContext(); } OSystem_IPHONE::~OSystem_IPHONE() { @@ -74,7 +73,6 @@ OSystem_IPHONE::~OSystem_IPHONE() { delete _mixer; free(_gameScreenRaw); - free(_gameScreenConverted); } int OSystem_IPHONE::timerHandler(int t) { diff --git a/backends/platform/iphone/osys_main.h b/backends/platform/iphone/osys_main.h index e4b3d358d5..180d3e9d06 100644 --- a/backends/platform/iphone/osys_main.h +++ b/backends/platform/iphone/osys_main.h @@ -59,37 +59,25 @@ protected: static SoundProc s_soundCallback; static void *s_soundParam; - int _currentGraphicsMode; - Audio::MixerImpl *_mixer; + VideoContext *_videoContext; + Graphics::Surface _framebuffer; byte *_gameScreenRaw; - OverlayColor *_overlayBuffer; - uint16 _overlayHeight; - uint16 _overlayWidth; - - uint16 *_gameScreenConverted; // For use with the game texture uint16 _gamePalette[256]; // For use with the mouse texture uint16 _gamePaletteRGBA5551[256]; - bool _overlayVisible; - uint16 _screenWidth; - uint16 _screenHeight; struct timeval _startTime; uint32 _timeSuspended; - bool _mouseVisible; bool _mouseCursorPaletteEnabled; uint16 _mouseCursorPalette[256]; byte *_mouseBuf; byte _mouseKeyColor; - uint _mouseWidth, _mouseHeight; - uint _mouseX, _mouseY; - int _mouseHotspotX, _mouseHotspotY; bool _mouseDirty; bool _mouseNeedTextureUpdate; long _lastMouseDown; @@ -192,13 +180,14 @@ public: virtual void logMessage(LogMessageType::Type type, const char *message); protected: + void initVideoContext(); + void updateOutputSurface(); + void internUpdateScreen(); void dirtyFullScreen(); void dirtyFullOverlayScreen(); void suspendLoop(); void drawDirtyRect(const Common::Rect &dirtyRect); - void drawDirtyOverlayRect(const Common::Rect &dirtyRect); - void updateHardwareSurfaceForRect(const Common::Rect &updatedRect); void updateMouseTexture(); static void AQBufferCallback(void *in, AudioQueueRef inQ, AudioQueueBufferRef outQB); static int timerHandler(int t); diff --git a/backends/platform/iphone/osys_video.cpp b/backends/platform/iphone/osys_video.mm index e26c360c82..31db4c70e7 100644 --- a/backends/platform/iphone/osys_video.cpp +++ b/backends/platform/iphone/osys_video.mm @@ -25,11 +25,16 @@ #include "osys_main.h" +#include "iphone_video.h" + +void OSystem_IPHONE::initVideoContext() { + _videoContext = [g_iPhoneViewInstance getVideoContext]; +} + const OSystem::GraphicsMode *OSystem_IPHONE::getSupportedGraphicsModes() const { return s_supportedGraphicsModes; } - int OSystem_IPHONE::getDefaultGraphicsMode() const { return kGraphicsModeLinear; } @@ -38,8 +43,8 @@ bool OSystem_IPHONE::setGraphicsMode(int mode) { switch (mode) { case kGraphicsModeNone: case kGraphicsModeLinear: - _currentGraphicsMode = mode; - iPhone_setGraphicsMode((GraphicsModes)mode); + _videoContext->graphicsMode = (GraphicsModes)mode; + [g_iPhoneViewInstance performSelectorOnMainThread:@selector(setGraphicsMode) withObject:nil waitUntilDone: YES]; return true; default: @@ -48,55 +53,44 @@ bool OSystem_IPHONE::setGraphicsMode(int mode) { } int OSystem_IPHONE::getGraphicsMode() const { - return _currentGraphicsMode; + return _videoContext->graphicsMode; } void OSystem_IPHONE::initSize(uint width, uint height, const Graphics::PixelFormat *format) { //printf("initSize(%i, %i)\n", width, height); - _screenWidth = width; - _screenHeight = height; + _videoContext->screenWidth = width; + _videoContext->screenHeight = height; + _videoContext->shakeOffsetY = 0; free(_gameScreenRaw); _gameScreenRaw = (byte *)malloc(width * height); bzero(_gameScreenRaw, width * height); - //free(_overlayBuffer); + updateOutputSurface(); - int fullSize = _screenWidth * _screenHeight * sizeof(OverlayColor); - //_overlayBuffer = (OverlayColor *)malloc(fullSize); clearOverlay(); - free(_gameScreenConverted); - - _gameScreenConverted = (uint16 *)malloc(fullSize); - bzero(_gameScreenConverted, fullSize); - - iPhone_initSurface(width, height); - - if (_overlayBuffer == NULL) { - _overlayHeight = iPhone_getScreenHeight(); - _overlayWidth = iPhone_getScreenWidth(); - - printf("Overlay: (%u x %u)\n", _overlayWidth, _overlayHeight); - _overlayBuffer = new OverlayColor[_overlayHeight * _overlayWidth]; - } - _fullScreenIsDirty = false; dirtyFullScreen(); - _mouseVisible = false; + _videoContext->mouseIsVisible = false; _mouseCursorPaletteEnabled = false; _screenChangeCount++; + updateScreen(); } +void OSystem_IPHONE::updateOutputSurface() { + [g_iPhoneViewInstance performSelectorOnMainThread:@selector(initSurface) withObject:nil waitUntilDone: YES]; +} + int16 OSystem_IPHONE::getHeight() { - return _screenHeight; + return _videoContext->screenHeight; } int16 OSystem_IPHONE::getWidth() { - return _screenWidth; + return _videoContext->screenWidth; } void OSystem_IPHONE::setPalette(const byte *colors, uint start, uint num) { @@ -137,12 +131,12 @@ void OSystem_IPHONE::copyRectToScreen(const byte *buf, int pitch, int x, int y, y = 0; } - if (w > _screenWidth - x) { - w = _screenWidth - x; + if (w > (int)_videoContext->screenWidth - x) { + w = _videoContext->screenWidth - x; } - if (h > _screenHeight - y) { - h = _screenHeight - y; + if (h > (int)_videoContext->screenHeight - y) { + h = _videoContext->screenHeight - y; } if (w <= 0 || h <= 0) @@ -153,14 +147,14 @@ void OSystem_IPHONE::copyRectToScreen(const byte *buf, int pitch, int x, int y, } - byte *dst = _gameScreenRaw + y * _screenWidth + x; - if (_screenWidth == pitch && pitch == w) + byte *dst = _gameScreenRaw + y * _videoContext->screenWidth + x; + if ((int)_videoContext->screenWidth == pitch && pitch == w) memcpy(dst, buf, h * w); else { do { memcpy(dst, buf, w); buf += pitch; - dst += _screenWidth; + dst += _videoContext->screenWidth; } while (--h); } } @@ -176,7 +170,7 @@ void OSystem_IPHONE::updateScreen() { _fullScreenIsDirty = false; _fullScreenOverlayIsDirty = false; - iPhone_updateScreen(_mouseX, _mouseY); + iPhone_updateScreen(); } void OSystem_IPHONE::internUpdateScreen() { @@ -190,16 +184,19 @@ void OSystem_IPHONE::internUpdateScreen() { //printf("Drawing: (%i, %i) -> (%i, %i)\n", dirtyRect.left, dirtyRect.top, dirtyRect.right, dirtyRect.bottom); drawDirtyRect(dirtyRect); - updateHardwareSurfaceForRect(dirtyRect); + // TODO: Implement dirty rect code + //updateHardwareSurfaceForRect(dirtyRect); } - if (_overlayVisible) { - while (_dirtyOverlayRects.size()) { + if (_videoContext->overlayVisible) { + // TODO: Implement dirty rect code + _dirtyOverlayRects.clear(); + /*while (_dirtyOverlayRects.size()) { Common::Rect dirtyRect = _dirtyOverlayRects.remove_at(_dirtyOverlayRects.size() - 1); //printf("Drawing: (%i, %i) -> (%i, %i)\n", dirtyRect.left, dirtyRect.top, dirtyRect.right, dirtyRect.bottom); drawDirtyOverlayRect(dirtyRect); - } + }*/ } } @@ -207,32 +204,25 @@ void OSystem_IPHONE::drawDirtyRect(const Common::Rect &dirtyRect) { int h = dirtyRect.bottom - dirtyRect.top; int w = dirtyRect.right - dirtyRect.left; - byte *src = &_gameScreenRaw[dirtyRect.top * _screenWidth + dirtyRect.left]; - uint16 *dst = &_gameScreenConverted[dirtyRect.top * _screenWidth + dirtyRect.left]; + byte *src = &_gameScreenRaw[dirtyRect.top * _videoContext->screenWidth + dirtyRect.left]; + byte *dstRaw = (byte *)_videoContext->screenTexture.getBasePtr(dirtyRect.left, dirtyRect.top); for (int y = h; y > 0; y--) { + uint16 *dst = (uint16 *)dstRaw; for (int x = w; x > 0; x--) *dst++ = _gamePalette[*src++]; - dst += _screenWidth - w; - src += _screenWidth - w; + dstRaw += _videoContext->screenTexture.pitch; + src += _videoContext->screenWidth - w; } } -void OSystem_IPHONE::drawDirtyOverlayRect(const Common::Rect &dirtyRect) { - iPhone_updateOverlayRect(_overlayBuffer, dirtyRect.left, dirtyRect.top, dirtyRect.right, dirtyRect.bottom); -} - -void OSystem_IPHONE::updateHardwareSurfaceForRect(const Common::Rect &updatedRect) { - iPhone_updateScreenRect(_gameScreenConverted, updatedRect.left, updatedRect.top, updatedRect.right, updatedRect.bottom); -} - Graphics::Surface *OSystem_IPHONE::lockScreen() { //printf("lockScreen()\n"); _framebuffer.pixels = _gameScreenRaw; - _framebuffer.w = _screenWidth; - _framebuffer.h = _screenHeight; - _framebuffer.pitch = _screenWidth; + _framebuffer.w = _videoContext->screenWidth; + _framebuffer.h = _videoContext->screenHeight; + _framebuffer.pitch = _videoContext->screenWidth; _framebuffer.format = Graphics::PixelFormat::createFormatCLUT8(); return &_framebuffer; @@ -245,41 +235,44 @@ void OSystem_IPHONE::unlockScreen() { void OSystem_IPHONE::setShakePos(int shakeOffset) { //printf("setShakePos(%i)\n", shakeOffset); - iPhone_setShakeOffset(shakeOffset); + _videoContext->shakeOffsetY = shakeOffset; + [g_iPhoneViewInstance performSelectorOnMainThread:@selector(setViewTransformation) withObject:nil waitUntilDone: YES]; // HACK: We use this to force a redraw. _mouseDirty = true; } void OSystem_IPHONE::showOverlay() { //printf("showOverlay()\n"); - _overlayVisible = true; + _videoContext->overlayVisible = true; dirtyFullOverlayScreen(); updateScreen(); - iPhone_enableOverlay(true); + [g_iPhoneViewInstance performSelectorOnMainThread:@selector(updateMouseCursorScaling) withObject:nil waitUntilDone: YES]; + [g_iPhoneViewInstance performSelectorOnMainThread:@selector(clearColorBuffer) withObject:nil waitUntilDone: YES]; } void OSystem_IPHONE::hideOverlay() { //printf("hideOverlay()\n"); - _overlayVisible = false; + _videoContext->overlayVisible = false; _dirtyOverlayRects.clear(); dirtyFullScreen(); - iPhone_enableOverlay(false); + [g_iPhoneViewInstance performSelectorOnMainThread:@selector(updateMouseCursorScaling) withObject:nil waitUntilDone: YES]; + [g_iPhoneViewInstance performSelectorOnMainThread:@selector(clearColorBuffer) withObject:nil waitUntilDone: YES]; } void OSystem_IPHONE::clearOverlay() { //printf("clearOverlay()\n"); - bzero(_overlayBuffer, _overlayWidth * _overlayHeight * sizeof(OverlayColor)); + bzero(_videoContext->overlayTexture.getBasePtr(0, 0), _videoContext->overlayTexture.h * _videoContext->overlayTexture.pitch); dirtyFullOverlayScreen(); } void OSystem_IPHONE::grabOverlay(OverlayColor *buf, int pitch) { //printf("grabOverlay()\n"); - int h = _overlayHeight; - OverlayColor *src = _overlayBuffer; + int h = _videoContext->overlayHeight; + const byte *src = (const byte *)_videoContext->overlayTexture.getBasePtr(0, 0); do { - memcpy(buf, src, _overlayWidth * sizeof(OverlayColor)); - src += _overlayWidth; + memcpy(buf, src, _videoContext->overlayWidth * sizeof(OverlayColor)); + src += _videoContext->overlayTexture.pitch; buf += pitch; } while (--h); } @@ -300,11 +293,11 @@ void OSystem_IPHONE::copyRectToOverlay(const OverlayColor *buf, int pitch, int x y = 0; } - if (w > _overlayWidth - x) - w = _overlayWidth - x; + if (w > (int)_videoContext->overlayWidth - x) + w = _videoContext->overlayWidth - x; - if (h > _overlayHeight - y) - h = _overlayHeight - y; + if (h > (int)_videoContext->overlayHeight - y) + h = _videoContext->overlayHeight - y; if (w <= 0 || h <= 0) return; @@ -313,30 +306,25 @@ void OSystem_IPHONE::copyRectToOverlay(const OverlayColor *buf, int pitch, int x _dirtyOverlayRects.push_back(Common::Rect(x, y, x + w, y + h)); } - OverlayColor *dst = _overlayBuffer + (y * _overlayWidth + x); - if (_overlayWidth == pitch && pitch == w) - memcpy(dst, buf, h * w * sizeof(OverlayColor)); - else { - do { - memcpy(dst, buf, w * sizeof(OverlayColor)); - buf += pitch; - dst += _overlayWidth; - } while (--h); - } + byte *dst = (byte *)_videoContext->overlayTexture.getBasePtr(x, y); + do { + memcpy(dst, buf, w * sizeof(OverlayColor)); + buf += pitch; + dst += _videoContext->overlayTexture.pitch; + } while (--h); } int16 OSystem_IPHONE::getOverlayHeight() { - return _overlayHeight; + return _videoContext->overlayHeight; } int16 OSystem_IPHONE::getOverlayWidth() { - return _overlayWidth; + return _videoContext->overlayWidth; } bool OSystem_IPHONE::showMouse(bool visible) { - bool last = _mouseVisible; - _mouseVisible = visible; - iPhone_showCursor(visible); + bool last = _videoContext->mouseIsVisible; + _videoContext->mouseIsVisible = visible; _mouseDirty = true; return last; @@ -344,16 +332,16 @@ bool OSystem_IPHONE::showMouse(bool visible) { void OSystem_IPHONE::warpMouse(int x, int y) { //printf("warpMouse()\n"); - - _mouseX = x; - _mouseY = y; + _videoContext->mouseX = x; + _videoContext->mouseY = y; + [g_iPhoneViewInstance performSelectorOnMainThread:@selector(notifyMouseMove) withObject:nil waitUntilDone: YES]; _mouseDirty = true; } void OSystem_IPHONE::dirtyFullScreen() { if (!_fullScreenIsDirty) { _dirtyRects.clear(); - _dirtyRects.push_back(Common::Rect(0, 0, _screenWidth, _screenHeight)); + _dirtyRects.push_back(Common::Rect(0, 0, _videoContext->screenWidth, _videoContext->screenHeight)); _fullScreenIsDirty = true; } } @@ -361,7 +349,7 @@ void OSystem_IPHONE::dirtyFullScreen() { void OSystem_IPHONE::dirtyFullOverlayScreen() { if (!_fullScreenOverlayIsDirty) { _dirtyOverlayRects.clear(); - _dirtyOverlayRects.push_back(Common::Rect(0, 0, _overlayWidth, _overlayHeight)); + _dirtyOverlayRects.push_back(Common::Rect(0, 0, _videoContext->overlayWidth, _videoContext->overlayHeight)); _fullScreenOverlayIsDirty = true; } } @@ -369,7 +357,7 @@ void OSystem_IPHONE::dirtyFullOverlayScreen() { void OSystem_IPHONE::setMouseCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, int cursorTargetScale, const Graphics::PixelFormat *format) { //printf("setMouseCursor(%i, %i, scale %u)\n", hotspotX, hotspotY, cursorTargetScale); - if (_mouseBuf != NULL && (_mouseWidth != w || _mouseHeight != h)) { + if (_mouseBuf != NULL && (_videoContext->mouseWidth != w || _videoContext->mouseHeight != h)) { free(_mouseBuf); _mouseBuf = NULL; } @@ -377,11 +365,11 @@ void OSystem_IPHONE::setMouseCursor(const byte *buf, uint w, uint h, int hotspot if (_mouseBuf == NULL) _mouseBuf = (byte *)malloc(w * h); - _mouseWidth = w; - _mouseHeight = h; + _videoContext->mouseWidth = w; + _videoContext->mouseHeight = h; - _mouseHotspotX = hotspotX; - _mouseHotspotY = hotspotY; + _videoContext->mouseHotspotX = hotspotX; + _videoContext->mouseHotspotY = hotspotY; _mouseKeyColor = (byte)keycolor; @@ -406,11 +394,12 @@ void OSystem_IPHONE::setCursorPalette(const byte *colors, uint start, uint num) } void OSystem_IPHONE::updateMouseTexture() { - int texWidth = getSizeNextPOT(_mouseWidth); - int texHeight = getSizeNextPOT(_mouseHeight); - int bufferSize = texWidth * texHeight * sizeof(int16); - uint16 *mouseBuf = (uint16 *)malloc(bufferSize); - memset(mouseBuf, 0, bufferSize); + uint texWidth = getSizeNextPOT(_videoContext->mouseWidth); + uint texHeight = getSizeNextPOT(_videoContext->mouseHeight); + + Graphics::Surface &mouseTexture = _videoContext->mouseTexture; + if (mouseTexture.w != texWidth || mouseTexture.h != texHeight) + mouseTexture.create(texWidth, texHeight, Graphics::createPixelFormat<5551>()); const uint16 *palette; if (_mouseCursorPaletteEnabled) @@ -418,9 +407,10 @@ void OSystem_IPHONE::updateMouseTexture() { else palette = _gamePaletteRGBA5551; - for (uint x = 0; x < _mouseWidth; ++x) { - for (uint y = 0; y < _mouseHeight; ++y) { - const byte color = _mouseBuf[y * _mouseWidth + x]; + uint16 *mouseBuf = (uint16 *)mouseTexture.getBasePtr(0, 0); + for (uint x = 0; x < _videoContext->mouseWidth; ++x) { + for (uint y = 0; y < _videoContext->mouseHeight; ++y) { + const byte color = _mouseBuf[y * _videoContext->mouseWidth + x]; if (color != _mouseKeyColor) mouseBuf[y * texWidth + x] = palette[color] | 0x1; else @@ -428,5 +418,5 @@ void OSystem_IPHONE::updateMouseTexture() { } } - iPhone_setMouseCursor(mouseBuf, _mouseWidth, _mouseHeight, _mouseHotspotX, _mouseHotspotY); + [g_iPhoneViewInstance performSelectorOnMainThread:@selector(updateMouseCursor) withObject:nil waitUntilDone: YES]; } diff --git a/base/main.cpp b/base/main.cpp index 5311b6fd78..5e9f1d4f25 100644 --- a/base/main.cpp +++ b/base/main.cpp @@ -264,9 +264,7 @@ static void setupKeymapper(OSystem &system) { Keymapper *mapper = system.getEventManager()->getKeymapper(); - HardwareKeySet *keySet; - - keySet = system.getHardwareKeySet(); + HardwareKeySet *keySet = system.getHardwareKeySet(); // Query backend for hardware keys and register them mapper->registerHardwareKeySet(keySet); diff --git a/common/array.h b/common/array.h index ef0ee27f24..a2c3023362 100644 --- a/common/array.h +++ b/common/array.h @@ -24,7 +24,7 @@ #include "common/scummsys.h" #include "common/algorithm.h" -#include "common/textconsole.h" // For error() +#include "common/textconsole.h" // For error() #include "common/memory.h" namespace Common { @@ -42,17 +42,19 @@ namespace Common { */ template<class T> class Array { -protected: - uint _capacity; - uint _size; - T *_storage; - public: typedef T *iterator; typedef const T *const_iterator; typedef T value_type; + typedef uint size_type; + +protected: + size_type _capacity; + size_type _size; + T *_storage; + public: Array() : _capacity(0), _size(0), _storage(0) {} @@ -67,7 +69,7 @@ public: * Construct an array by copying data from a regular array. */ template<class T2> - Array(const T2 *data, int n) { + Array(const T2 *data, size_type n) { _size = n; allocCapacity(n); uninitialized_copy(data, data + _size, _storage); @@ -128,19 +130,19 @@ public: } - void insert_at(int idx, const T &element) { - assert(idx >= 0 && (uint)idx <= _size); + void insert_at(size_type idx, const T &element) { + assert(idx <= _size); insert_aux(_storage + idx, &element, &element + 1); } - void insert_at(int idx, const Array<T> &array) { - assert(idx >= 0 && (uint)idx <= _size); + void insert_at(size_type idx, const Array<T> &array) { + assert(idx <= _size); insert_aux(_storage + idx, array.begin(), array.end()); } - T remove_at(int idx) { - assert(idx >= 0 && (uint)idx < _size); + T remove_at(size_type idx) { + assert(idx < _size); T tmp = _storage[idx]; copy(_storage + idx + 1, _storage + _size, _storage + idx); _size--; @@ -151,17 +153,17 @@ public: // TODO: insert, remove, ... - T& operator[](int idx) { - assert(idx >= 0 && (uint)idx < _size); + T &operator[](size_type idx) { + assert(idx < _size); return _storage[idx]; } - const T& operator[](int idx) const { - assert(idx >= 0 && (uint)idx < _size); + const T &operator[](size_type idx) const { + assert(idx < _size); return _storage[idx]; } - Array<T>& operator=(const Array<T> &array) { + Array<T> &operator=(const Array<T> &array) { if (this == &array) return *this; @@ -173,7 +175,7 @@ public: return *this; } - uint size() const { + size_type size() const { return _size; } @@ -193,34 +195,34 @@ public: return true; if (_size != other._size) return false; - for (uint i = 0; i < _size; ++i) { + for (size_type i = 0; i < _size; ++i) { if (_storage[i] != other._storage[i]) return false; } return true; } + bool operator!=(const Array<T> &other) const { return !(*this == other); } - - iterator begin() { + iterator begin() { return _storage; } - iterator end() { + iterator end() { return _storage + _size; } - const_iterator begin() const { + const_iterator begin() const { return _storage; } - const_iterator end() const { + const_iterator end() const { return _storage + _size; } - void reserve(uint newCapacity) { + void reserve(size_type newCapacity) { if (newCapacity <= _capacity) return; @@ -234,9 +236,9 @@ public: } } - void resize(uint newSize) { + void resize(size_type newSize) { reserve(newSize); - for (uint i = _size; i < newSize; ++i) + for (size_type i = _size; i < newSize; ++i) new ((void *)&_storage[i]) T(); _size = newSize; } @@ -249,28 +251,28 @@ public: } protected: - static uint roundUpCapacity(uint capacity) { + static size_type roundUpCapacity(size_type capacity) { // Round up capacity to the next power of 2; // we use a minimal capacity of 8. - uint capa = 8; + size_type capa = 8; while (capa < capacity) capa <<= 1; return capa; } - void allocCapacity(uint capacity) { + void allocCapacity(size_type capacity) { _capacity = capacity; if (capacity) { _storage = (T *)malloc(sizeof(T) * capacity); if (!_storage) - ::error("Common::Array: failure to allocate %u bytes", capacity * (uint)sizeof(T)); + ::error("Common::Array: failure to allocate %u bytes", capacity * (size_type)sizeof(T)); } else { _storage = 0; } } - void freeStorage(T *storage, const uint elements) { - for (uint i = 0; i < elements; ++i) + void freeStorage(T *storage, const size_type elements) { + for (size_type i = 0; i < elements; ++i) storage[i].~T(); free(storage); } @@ -291,9 +293,9 @@ protected: iterator insert_aux(iterator pos, const_iterator first, const_iterator last) { assert(_storage <= pos && pos <= _storage + _size); assert(first <= last); - const uint n = last - first; + const size_type n = last - first; if (n) { - const uint idx = pos - _storage; + const size_type idx = pos - _storage; if (_size + n > _capacity || (_storage <= first && first <= _storage + _size)) { T *const oldStorage = _storage; diff --git a/common/events.h b/common/events.h index 69cca9b54a..5f6a7798dd 100644 --- a/common/events.h +++ b/common/events.h @@ -118,7 +118,11 @@ struct Event { CustomEventType customType; #endif - Event() : type(EVENT_INVALID), synthetic(false) {} + Event() : type(EVENT_INVALID), synthetic(false) { +#ifdef ENABLE_KEYMAPPER + customType = 0; +#endif + } }; /** diff --git a/common/hashmap.h b/common/hashmap.h index 347ac1fd25..7cf54997e8 100644 --- a/common/hashmap.h +++ b/common/hashmap.h @@ -67,7 +67,7 @@ template<class T> class IteratorImpl; /** * HashMap<Key,Val> maps objects of type Key to objects of type Val. - * For each used Key type, we need an "uint hashit(Key,uint)" function + * For each used Key type, we need an "size_type hashit(Key,size_type)" function * that computes a hash for the given Key object and returns it as an * an integer from 0 to hashsize-1, and also an "equality functor". * that returns true if if its two arguments are to be considered @@ -80,6 +80,9 @@ template<class T> class IteratorImpl; */ template<class Key, class Val, class HashFunc = Hash<Key>, class EqualFunc = EqualTo<Key> > class HashMap { +public: + typedef uint size_type; + private: typedef HashMap<Key, Val, HashFunc, EqualFunc> HM_t; @@ -111,9 +114,9 @@ private: #endif Node **_storage; ///< hashtable of size arrsize. - uint _mask; ///< Capacity of the HashMap minus one; must be a power of two of minus one - uint _size; - uint _deleted; ///< Number of deleted elements (_dummyNodes) + size_type _mask; ///< Capacity of the HashMap minus one; must be a power of two of minus one + size_type _size; + size_type _deleted; ///< Number of deleted elements (_dummyNodes) HashFunc _hash; EqualFunc _equal; @@ -146,9 +149,9 @@ private: } void assign(const HM_t &map); - uint lookup(const Key &key) const; - uint lookupAndCreateIfMissing(const Key &key); - void expandStorage(uint newCapacity); + size_type lookup(const Key &key) const; + size_type lookupAndCreateIfMissing(const Key &key); + void expandStorage(size_type newCapacity); #if !defined(__sgi) || defined(__GNUC__) template<class T> friend class IteratorImpl; @@ -168,11 +171,11 @@ private: protected: typedef const HashMap hashmap_t; - uint _idx; + size_type _idx; hashmap_t *_hashmap; protected: - IteratorImpl(uint idx, hashmap_t *hashmap) : _idx(idx), _hashmap(hashmap) {} + IteratorImpl(size_type idx, hashmap_t *hashmap) : _idx(idx), _hashmap(hashmap) {} NodeType *deref() const { assert(_hashmap != 0); @@ -200,7 +203,7 @@ private: _idx++; } while (_idx <= _hashmap->_mask && (_hashmap->_storage[_idx] == 0 || _hashmap->_storage[_idx] == HASHMAP_DUMMY_NODE)); if (_idx > _hashmap->_mask) - _idx = (uint)-1; + _idx = (size_type)-1; return *this; } @@ -247,41 +250,41 @@ public: void erase(iterator entry); void erase(const Key &key); - uint size() const { return _size; } + size_type size() const { return _size; } iterator begin() { // Find and return the first non-empty entry - for (uint ctr = 0; ctr <= _mask; ++ctr) { + for (size_type ctr = 0; ctr <= _mask; ++ctr) { if (_storage[ctr] && _storage[ctr] != HASHMAP_DUMMY_NODE) return iterator(ctr, this); } return end(); } iterator end() { - return iterator((uint)-1, this); + return iterator((size_type)-1, this); } const_iterator begin() const { // Find and return the first non-empty entry - for (uint ctr = 0; ctr <= _mask; ++ctr) { + for (size_type ctr = 0; ctr <= _mask; ++ctr) { if (_storage[ctr] && _storage[ctr] != HASHMAP_DUMMY_NODE) return const_iterator(ctr, this); } return end(); } const_iterator end() const { - return const_iterator((uint)-1, this); + return const_iterator((size_type)-1, this); } iterator find(const Key &key) { - uint ctr = lookup(key); + size_type ctr = lookup(key); if (_storage[ctr]) return iterator(ctr, this); return end(); } const_iterator find(const Key &key) const { - uint ctr = lookup(key); + size_type ctr = lookup(key); if (_storage[ctr]) return const_iterator(ctr, this); return end(); @@ -346,7 +349,7 @@ HashMap<Key, Val, HashFunc, EqualFunc>::HashMap(const HM_t &map) : */ template<class Key, class Val, class HashFunc, class EqualFunc> HashMap<Key, Val, HashFunc, EqualFunc>::~HashMap() { - for (uint ctr = 0; ctr <= _mask; ++ctr) + for (size_type ctr = 0; ctr <= _mask; ++ctr) freeNode(_storage[ctr]); delete[] _storage; @@ -373,7 +376,7 @@ void HashMap<Key, Val, HashFunc, EqualFunc>::assign(const HM_t &map) { // Simply clone the map given to us, one by one. _size = 0; _deleted = 0; - for (uint ctr = 0; ctr <= _mask; ++ctr) { + for (size_type ctr = 0; ctr <= _mask; ++ctr) { if (map._storage[ctr] == HASHMAP_DUMMY_NODE) { _storage[ctr] = HASHMAP_DUMMY_NODE; _deleted++; @@ -391,7 +394,7 @@ void HashMap<Key, Val, HashFunc, EqualFunc>::assign(const HM_t &map) { template<class Key, class Val, class HashFunc, class EqualFunc> void HashMap<Key, Val, HashFunc, EqualFunc>::clear(bool shrinkArray) { - for (uint ctr = 0; ctr <= _mask; ++ctr) { + for (size_type ctr = 0; ctr <= _mask; ++ctr) { freeNode(_storage[ctr]); _storage[ctr] = NULL; } @@ -414,13 +417,13 @@ void HashMap<Key, Val, HashFunc, EqualFunc>::clear(bool shrinkArray) { } template<class Key, class Val, class HashFunc, class EqualFunc> -void HashMap<Key, Val, HashFunc, EqualFunc>::expandStorage(uint newCapacity) { +void HashMap<Key, Val, HashFunc, EqualFunc>::expandStorage(size_type newCapacity) { assert(newCapacity > _mask+1); #ifndef NDEBUG - const uint old_size = _size; + const size_type old_size = _size; #endif - const uint old_mask = _mask; + const size_type old_mask = _mask; Node **old_storage = _storage; // allocate a new array @@ -432,7 +435,7 @@ void HashMap<Key, Val, HashFunc, EqualFunc>::expandStorage(uint newCapacity) { memset(_storage, 0, newCapacity * sizeof(Node *)); // rehash all the old elements - for (uint ctr = 0; ctr <= old_mask; ++ctr) { + for (size_type ctr = 0; ctr <= old_mask; ++ctr) { if (old_storage[ctr] == NULL || old_storage[ctr] == HASHMAP_DUMMY_NODE) continue; @@ -440,9 +443,9 @@ void HashMap<Key, Val, HashFunc, EqualFunc>::expandStorage(uint newCapacity) { // Since we know that no key exists twice in the old table, we // can do this slightly better than by calling lookup, since we // don't have to call _equal(). - const uint hash = _hash(old_storage[ctr]->_key); - uint idx = hash & _mask; - for (uint perturb = hash; _storage[idx] != NULL && _storage[idx] != HASHMAP_DUMMY_NODE; perturb >>= HASHMAP_PERTURB_SHIFT) { + const size_type hash = _hash(old_storage[ctr]->_key); + size_type idx = hash & _mask; + for (size_type perturb = hash; _storage[idx] != NULL && _storage[idx] != HASHMAP_DUMMY_NODE; perturb >>= HASHMAP_PERTURB_SHIFT) { idx = (5 * idx + perturb + 1) & _mask; } @@ -460,10 +463,10 @@ void HashMap<Key, Val, HashFunc, EqualFunc>::expandStorage(uint newCapacity) { } template<class Key, class Val, class HashFunc, class EqualFunc> -uint HashMap<Key, Val, HashFunc, EqualFunc>::lookup(const Key &key) const { - const uint hash = _hash(key); - uint ctr = hash & _mask; - for (uint perturb = hash; ; perturb >>= HASHMAP_PERTURB_SHIFT) { +typename HashMap<Key, Val, HashFunc, EqualFunc>::size_type HashMap<Key, Val, HashFunc, EqualFunc>::lookup(const Key &key) const { + const size_type hash = _hash(key); + size_type ctr = hash & _mask; + for (size_type perturb = hash; ; perturb >>= HASHMAP_PERTURB_SHIFT) { if (_storage[ctr] == NULL) break; if (_storage[ctr] == HASHMAP_DUMMY_NODE) { @@ -491,13 +494,13 @@ uint HashMap<Key, Val, HashFunc, EqualFunc>::lookup(const Key &key) const { } template<class Key, class Val, class HashFunc, class EqualFunc> -uint HashMap<Key, Val, HashFunc, EqualFunc>::lookupAndCreateIfMissing(const Key &key) { - const uint hash = _hash(key); - uint ctr = hash & _mask; - const uint NONE_FOUND = _mask + 1; - uint first_free = NONE_FOUND; +typename HashMap<Key, Val, HashFunc, EqualFunc>::size_type HashMap<Key, Val, HashFunc, EqualFunc>::lookupAndCreateIfMissing(const Key &key) { + const size_type hash = _hash(key); + size_type ctr = hash & _mask; + const size_type NONE_FOUND = _mask + 1; + size_type first_free = NONE_FOUND; bool found = false; - for (uint perturb = hash; ; perturb >>= HASHMAP_PERTURB_SHIFT) { + for (size_type perturb = hash; ; perturb >>= HASHMAP_PERTURB_SHIFT) { if (_storage[ctr] == NULL) break; if (_storage[ctr] == HASHMAP_DUMMY_NODE) { @@ -537,7 +540,7 @@ uint HashMap<Key, Val, HashFunc, EqualFunc>::lookupAndCreateIfMissing(const Key // Keep the load factor below a certain threshold. // Deleted nodes are also counted - uint capacity = _mask + 1; + size_type capacity = _mask + 1; if ((_size + _deleted) * HASHMAP_LOADFACTOR_DENOMINATOR > capacity * HASHMAP_LOADFACTOR_NUMERATOR) { capacity = capacity < 500 ? (capacity * 4) : (capacity * 2); @@ -553,7 +556,7 @@ uint HashMap<Key, Val, HashFunc, EqualFunc>::lookupAndCreateIfMissing(const Key template<class Key, class Val, class HashFunc, class EqualFunc> bool HashMap<Key, Val, HashFunc, EqualFunc>::contains(const Key &key) const { - uint ctr = lookup(key); + size_type ctr = lookup(key); return (_storage[ctr] != NULL); } @@ -569,7 +572,7 @@ const Val &HashMap<Key, Val, HashFunc, EqualFunc>::operator[](const Key &key) co template<class Key, class Val, class HashFunc, class EqualFunc> Val &HashMap<Key, Val, HashFunc, EqualFunc>::getVal(const Key &key) { - uint ctr = lookupAndCreateIfMissing(key); + size_type ctr = lookupAndCreateIfMissing(key); assert(_storage[ctr] != NULL); return _storage[ctr]->_value; } @@ -581,7 +584,7 @@ const Val &HashMap<Key, Val, HashFunc, EqualFunc>::getVal(const Key &key) const template<class Key, class Val, class HashFunc, class EqualFunc> const Val &HashMap<Key, Val, HashFunc, EqualFunc>::getVal(const Key &key, const Val &defaultVal) const { - uint ctr = lookup(key); + size_type ctr = lookup(key); if (_storage[ctr] != NULL) return _storage[ctr]->_value; else @@ -590,7 +593,7 @@ const Val &HashMap<Key, Val, HashFunc, EqualFunc>::getVal(const Key &key, const template<class Key, class Val, class HashFunc, class EqualFunc> void HashMap<Key, Val, HashFunc, EqualFunc>::setVal(const Key &key, const Val &val) { - uint ctr = lookupAndCreateIfMissing(key); + size_type ctr = lookupAndCreateIfMissing(key); assert(_storage[ctr] != NULL); _storage[ctr]->_value = val; } @@ -599,7 +602,7 @@ template<class Key, class Val, class HashFunc, class EqualFunc> void HashMap<Key, Val, HashFunc, EqualFunc>::erase(iterator entry) { // Check whether we have a valid iterator assert(entry._hashmap == this); - const uint ctr = entry._idx; + const size_type ctr = entry._idx; assert(ctr <= _mask); Node * const node = _storage[ctr]; assert(node != NULL); @@ -615,7 +618,7 @@ void HashMap<Key, Val, HashFunc, EqualFunc>::erase(iterator entry) { template<class Key, class Val, class HashFunc, class EqualFunc> void HashMap<Key, Val, HashFunc, EqualFunc>::erase(const Key &key) { - uint ctr = lookup(key); + size_type ctr = lookup(key); if (_storage[ctr] == NULL) return; diff --git a/common/list.h b/common/list.h index 044b9d7a49..9792042239 100644 --- a/common/list.h +++ b/common/list.h @@ -43,6 +43,7 @@ public: typedef ListInternal::ConstIterator<t_T> const_iterator; typedef t_T value_type; + typedef uint size_type; public: List() { @@ -181,8 +182,8 @@ public: return *this; } - uint size() const { - uint n = 0; + size_type size() const { + size_type n = 0; for (const NodeBase *cur = _anchor._next; cur != &_anchor; cur = cur->_next) ++n; return n; diff --git a/common/stack.h b/common/stack.h index 0d13049f2e..bc5de9ac7f 100644 --- a/common/stack.h +++ b/common/stack.h @@ -30,48 +30,59 @@ namespace Common { /** * Extremly simple fixed size stack class. */ -template<class T, int MAX_SIZE = 10> +template<class T, uint MAX_SIZE = 10> class FixedStack { -protected: - T _stack[MAX_SIZE]; - int _size; public: + typedef uint size_type; + FixedStack<T, MAX_SIZE>() : _size(0) {} bool empty() const { return _size <= 0; } + void clear() { _size = 0; } + void push(const T &x) { assert(_size < MAX_SIZE); _stack[_size++] = x; } + const T &top() const { assert(_size > 0); return _stack[_size - 1]; } + T &top() { assert(_size > 0); return _stack[_size - 1]; } + T pop() { T tmp = top(); --_size; return tmp; } - int size() const { + + size_type size() const { return _size; } - T &operator[](int i) { - assert(0 <= i && i < MAX_SIZE); + + T &operator[](size_type i) { + assert(i < MAX_SIZE); return _stack[i]; } - const T &operator[](int i) const { - assert(0 <= i && i < MAX_SIZE); + + const T &operator[](size_type i) const { + assert(i < MAX_SIZE); return _stack[i]; } + +protected: + T _stack[MAX_SIZE]; + size_type _size; }; @@ -81,39 +92,49 @@ public: template<class T> class Stack { private: - Array<T> _stack; + Array<T> _stack; public: + typedef typename Array<T>::size_type size_type; + Stack<T>() {} Stack<T>(const Array<T> &stackContent) : _stack(stackContent) {} bool empty() const { return _stack.empty(); } + void clear() { _stack.clear(); } + void push(const T &x) { _stack.push_back(x); } + T &top() { return _stack.back(); } + const T &top() const { return _stack.back(); } + T pop() { T tmp = _stack.back(); _stack.pop_back(); return tmp; } - int size() const { + + size_type size() const { return _stack.size(); } - T &operator[](int i) { + + T &operator[](size_type i) { return _stack[i]; } - const T &operator[](int i) const { + + const T &operator[](size_type i) const { return _stack[i]; } }; diff --git a/engines/agi/saveload.cpp b/engines/agi/saveload.cpp index 00d6a1c8dd..0ef6230374 100644 --- a/engines/agi/saveload.cpp +++ b/engines/agi/saveload.cpp @@ -221,8 +221,8 @@ int AgiEngine::saveGame(const Common::String &fileName, const Common::String &de // Save image stack - for (i = 0; i < _imageStack.size(); i++) { - ImageStackElement ise = _imageStack[i]; + for (Common::Stack<ImageStackElement>::size_type j = 0; j < _imageStack.size(); ++j) { + const ImageStackElement &ise = _imageStack[j]; out->writeByte(ise.type); out->writeSint16BE(ise.parm1); out->writeSint16BE(ise.parm2); diff --git a/engines/dreamweb/dreamweb.h b/engines/dreamweb/dreamweb.h index 981ee86d4e..6d7253da65 100644 --- a/engines/dreamweb/dreamweb.h +++ b/engines/dreamweb/dreamweb.h @@ -75,6 +75,7 @@ const unsigned int kSymbolx = 64; const unsigned int kSymboly = 56; const unsigned int kLengthofvars = 68; const unsigned int kFrameBlocksize = 2080; +const unsigned int kGraphicsFileFrameSize = 347; // ceil(2080 / sizeof(Frame)) const unsigned int kNumexobjects = 114; const unsigned int kNumExTexts = kNumexobjects + 2; const uint16 kExtextlen = 18000; @@ -261,13 +262,28 @@ protected: TextFile _puzzleText; TextFile _commandText; - // graphics files - GraphicsFile _tempGraphics; - GraphicsFile _tempGraphics2; - GraphicsFile _tempGraphics3; + // local graphics files + GraphicsFile _keypadGraphics; + GraphicsFile _menuGraphics; + GraphicsFile _menuGraphics2; + GraphicsFile _folderGraphics; + GraphicsFile _folderGraphics2; + GraphicsFile _folderGraphics3; + GraphicsFile _folderCharset; + GraphicsFile _symbolGraphics; + GraphicsFile _diaryGraphics; + GraphicsFile _diaryCharset; + GraphicsFile _monitorGraphics; + GraphicsFile _monitorCharset; + GraphicsFile _newplaceGraphics; + GraphicsFile _newplaceGraphics2; + GraphicsFile _newplaceGraphics3; + GraphicsFile _cityGraphics; + GraphicsFile _saveGraphics; + + // global graphics files GraphicsFile _icons1; GraphicsFile _icons2; - GraphicsFile _tempCharset; GraphicsFile _charset1; GraphicsFile _mainSprites; const GraphicsFile *_currentCharset; @@ -793,15 +809,11 @@ public: void loadGraphicsFile(GraphicsFile &file, const char *fileName); void loadGraphicsSegment(GraphicsFile &file, Common::File &inFile, unsigned int len); void loadTextSegment(TextFile &file, Common::File &inFile, unsigned int len); - void loadIntoTemp(const char *fileName); - void loadIntoTemp2(const char *fileName); - void loadIntoTemp3(const char *fileName); - void loadTempCharset(const char *fileName); void loadTravelText(); void loadTempText(const char *fileName); void sortOutMap(); void loadRoomData(const Room &room, bool skipDat); - void useTempCharset(); + void useTempCharset(GraphicsFile *charset); void useCharset1(); void printMessage(uint16 x, uint16 y, uint8 index, uint8 maxWidth, bool centered); void printMessage2(uint16 x, uint16 y, uint8 index, uint8 maxWidth, bool centered, uint8 count); @@ -844,11 +856,7 @@ public: bool isItWorn(const DynObject *object); bool compare(uint8 index, uint8 flag, const char id[4]); void hangOnW(uint16 frameCount); - void getRidOfTemp(); void getRidOfTempText(); - void getRidOfTemp2(); - void getRidOfTemp3(); - void getRidOfTempCharset(); void getRidOfAll(); void placeSetObject(uint8 index); void removeSetObject(uint8 index); diff --git a/engines/dreamweb/keypad.cpp b/engines/dreamweb/keypad.cpp index 2a31652ace..172e85104f 100644 --- a/engines/dreamweb/keypad.cpp +++ b/engines/dreamweb/keypad.cpp @@ -93,7 +93,7 @@ void DreamWebEngine::enterCode(uint8 digit0, uint8 digit1, uint8 digit2, uint8 d } } _manIsOffScreen = 0; - getRidOfTemp(); + _keypadGraphics.clear(); restoreReels(); redrawMainScrn(); workToScreenM(); @@ -108,7 +108,7 @@ bool DreamWebEngine::isItRight(uint8 digit0, uint8 digit1, uint8 digit2, uint8 d } void DreamWebEngine::loadKeypad() { - loadIntoTemp("DREAMWEB.G02"); + loadGraphicsFile(_keypadGraphics, "DREAMWEB.G02"); } void DreamWebEngine::quitKey() { @@ -185,8 +185,8 @@ void DreamWebEngine::buttonPress(uint8 buttonId) { } void DreamWebEngine::showOuterPad() { - showFrame(_tempGraphics, kKeypadx-3, kKeypady-4, 1, 0); - showFrame(_tempGraphics, kKeypadx+74, kKeypady+76, 37, 0); + showFrame(_keypadGraphics, kKeypadx-3, kKeypady-4, 1, 0); + showFrame(_keypadGraphics, kKeypadx+74, kKeypady+76, 37, 0); } void DreamWebEngine::showKeypad() { @@ -214,7 +214,7 @@ void DreamWebEngine::showKeypad() { } if ((_lightCount >= 60) && (_lightCount < 100)) --frameIndex; - showFrame(_tempGraphics, kKeypadx+60, y, frameIndex, 0); + showFrame(_keypadGraphics, kKeypadx+60, y, frameIndex, 0); } } @@ -225,7 +225,7 @@ void DreamWebEngine::singleKey(uint8 key, uint16 x, uint16 y) { key -= 11; } key -= 20; - showFrame(_tempGraphics, x, y, key, 0); + showFrame(_keypadGraphics, x, y, key, 0); } void DreamWebEngine::dumpKeypad() { @@ -241,9 +241,9 @@ void DreamWebEngine::useMenu() { _vars._newObs = 0; drawFloor(); printSprites(); - showFrame(_tempGraphics2, kMenux-48, kMenuy-4, 4, 0); + showFrame(_menuGraphics2, kMenux-48, kMenuy-4, 4, 0); getUnderMenu(); - showFrame(_tempGraphics2, kMenux+54, kMenuy+72, 5, 0); + showFrame(_menuGraphics2, kMenux+54, kMenuy+72, 5, 0); workToScreenM(); _getBack = 0; do { @@ -265,8 +265,8 @@ void DreamWebEngine::useMenu() { } while ((_getBack != 1) && !_quitRequested); _manIsOffScreen = 0; redrawMainScrn(); - getRidOfTemp(); - getRidOfTemp2(); + _menuGraphics.clear(); + _menuGraphics2.clear(); restoreReels(); workToScreenM(); } @@ -289,12 +289,12 @@ void DreamWebEngine::showMenu() { ++_menuCount; if (_menuCount == 37*2) _menuCount = 0; - showFrame(_tempGraphics, kMenux, kMenuy, _menuCount / 2, 0); + showFrame(_menuGraphics, kMenux, kMenuy, _menuCount / 2, 0); } void DreamWebEngine::loadMenu() { - loadIntoTemp("DREAMWEB.S02"); // sprite name 3 - loadIntoTemp2("DREAMWEB.G07"); // mon. graphics 2 + loadGraphicsFile(_menuGraphics, "DREAMWEB.S02"); // sprite name 3 + loadGraphicsFile(_menuGraphics2, "DREAMWEB.G07"); // mon. graphics 2 } void DreamWebEngine::viewFolder() { @@ -317,10 +317,10 @@ void DreamWebEngine::viewFolder() { checkFolderCoords(); } while (_getBack == 0); _manIsOffScreen = 0; - getRidOfTemp(); - getRidOfTemp2(); - getRidOfTemp3(); - getRidOfTempCharset(); + _folderGraphics.clear(); + _folderGraphics2.clear(); + _folderGraphics3.clear(); + _folderCharset.clear(); restoreAll(); redrawMainScrn(); workToScreenM(); @@ -394,22 +394,22 @@ void DreamWebEngine::checkFolderCoords() { } void DreamWebEngine::loadFolder() { - loadIntoTemp("DREAMWEB.G09"); // folder graphics 1 - loadIntoTemp2("DREAMWEB.G10"); // folder graphics 2 - loadIntoTemp3("DREAMWEB.G11"); // folder graphics 3 - loadTempCharset("DREAMWEB.C02"); // character set 3 + loadGraphicsFile(_folderGraphics, "DREAMWEB.G09"); // folder graphics 1 + loadGraphicsFile(_folderGraphics2, "DREAMWEB.G10"); // folder graphics 2 + loadGraphicsFile(_folderGraphics3, "DREAMWEB.G11"); // folder graphics 3 + loadGraphicsFile(_folderCharset, "DREAMWEB.C02"); // character set 3 loadTempText("DREAMWEB.T50"); // folder text } void DreamWebEngine::showFolder() { _commandType = 255; if (_folderPage) { - useTempCharset(); + useTempCharset(&_folderCharset); createPanel2(); - showFrame(_tempGraphics, 0, 0, 0, 0); - showFrame(_tempGraphics, 143, 0, 1, 0); - showFrame(_tempGraphics, 0, 92, 2, 0); - showFrame(_tempGraphics, 143, 92, 3, 0); + showFrame(_folderGraphics, 0, 0, 0, 0); + showFrame(_folderGraphics, 143, 0, 1, 0); + showFrame(_folderGraphics, 0, 92, 2, 0); + showFrame(_folderGraphics, 143, 92, 3, 0); folderExit(); if (_folderPage != 1) showLeftPage(); @@ -419,25 +419,25 @@ void DreamWebEngine::showFolder() { underTextLine(); } else { createPanel2(); - showFrame(_tempGraphics3, 143-28, 0, 0, 0); - showFrame(_tempGraphics3, 143-28, 92, 1, 0); + showFrame(_folderGraphics3, 143-28, 0, 0, 0); + showFrame(_folderGraphics3, 143-28, 92, 1, 0); folderExit(); underTextLine(); } } void DreamWebEngine::folderExit() { - showFrame(_tempGraphics2, 296, 178, 6, 0); + showFrame(_folderGraphics2, 296, 178, 6, 0); } void DreamWebEngine::showLeftPage() { - showFrame(_tempGraphics2, 0, 12, 3, 0); + showFrame(_folderGraphics2, 0, 12, 3, 0); uint16 y = 12+5; for (size_t i = 0; i < 9; ++i) { - showFrame(_tempGraphics2, 0, y, 4, 0); + showFrame(_folderGraphics2, 0, y, 4, 0); y += 16; } - showFrame(_tempGraphics2, 0, y, 5, 0); + showFrame(_folderGraphics2, 0, y, 5, 0); _lineSpacing = 8; _charShift = 91; _kerning = 1; @@ -464,14 +464,14 @@ void DreamWebEngine::showLeftPage() { } void DreamWebEngine::showRightPage() { - showFrame(_tempGraphics2, 143, 12, 0, 0); + showFrame(_folderGraphics2, 143, 12, 0, 0); uint16 y = 12+37; for (size_t i = 0; i < 7; ++i) { - showFrame(_tempGraphics2, 143, y, 1, 0); + showFrame(_folderGraphics2, 143, y, 1, 0); y += 16; } - showFrame(_tempGraphics2, 143, y, 2, 0); + showFrame(_folderGraphics2, 143, y, 2, 0); _lineSpacing = 8; _kerning = 1; uint8 pageIndex = _folderPage - 1; @@ -491,7 +491,7 @@ void DreamWebEngine::showRightPage() { void DreamWebEngine::enterSymbol() { _manIsOffScreen = 1; getRidOfReels(); - loadIntoTemp("DREAMWEB.G12"); // symbol graphics + loadGraphicsFile(_symbolGraphics, "DREAMWEB.G12"); // symbol graphics _symbolTopX = 24; _symbolTopDir = 0; _symbolBotX = 24; @@ -529,7 +529,7 @@ void DreamWebEngine::enterSymbol() { turnAnyPathOn(0, _roomNum + 12); _manIsOffScreen = 0; redrawMainScrn(); - getRidOfTemp(); + _symbolGraphics.clear(); restoreReels(); workToScreenM(); playChannel1(13); @@ -539,7 +539,7 @@ void DreamWebEngine::enterSymbol() { turnAnyPathOff(0, _roomNum + 12); _manIsOffScreen = 0; redrawMainScrn(); - getRidOfTemp(); + _symbolGraphics.clear(); restoreReels(); workToScreenM(); } @@ -616,19 +616,19 @@ void DreamWebEngine::dumpSymbol() { } void DreamWebEngine::showSymbol() { - showFrame(_tempGraphics, kSymbolx, kSymboly, 12, 0); + showFrame(_symbolGraphics, kSymbolx, kSymboly, 12, 0); - showFrame(_tempGraphics, _symbolTopX + kSymbolx-44, kSymboly+20, _symbolTopNum, 32); + showFrame(_symbolGraphics, _symbolTopX + kSymbolx-44, kSymboly+20, _symbolTopNum, 32); uint8 nextTopSymbol = nextSymbol(_symbolTopNum); - showFrame(_tempGraphics, _symbolTopX + kSymbolx+5, kSymboly+20, nextTopSymbol, 32); + showFrame(_symbolGraphics, _symbolTopX + kSymbolx+5, kSymboly+20, nextTopSymbol, 32); uint8 nextNextTopSymbol = nextSymbol(nextTopSymbol); - showFrame(_tempGraphics, _symbolTopX + kSymbolx+54, kSymboly+20, nextNextTopSymbol, 32); + showFrame(_symbolGraphics, _symbolTopX + kSymbolx+54, kSymboly+20, nextNextTopSymbol, 32); - showFrame(_tempGraphics, _symbolBotX + kSymbolx-44, kSymboly+49, 6 + _symbolBotNum, 32); + showFrame(_symbolGraphics, _symbolBotX + kSymbolx-44, kSymboly+49, 6 + _symbolBotNum, 32); uint8 nextBotSymbol = nextSymbol(_symbolBotNum); - showFrame(_tempGraphics, _symbolBotX + kSymbolx+5, kSymboly+49, 6 + nextBotSymbol, 32); + showFrame(_symbolGraphics, _symbolBotX + kSymbolx+5, kSymboly+49, 6 + nextBotSymbol, 32); uint8 nextNextBotSymbol = nextSymbol(nextBotSymbol); - showFrame(_tempGraphics, _symbolBotX + kSymbolx+54, kSymboly+49, 6 + nextNextBotSymbol, 32); + showFrame(_symbolGraphics, _symbolBotX + kSymbolx+54, kSymboly+49, 6 + nextNextBotSymbol, 32); } uint8 DreamWebEngine::nextSymbol(uint8 symbol) { @@ -716,9 +716,9 @@ void DreamWebEngine::updateSymbolBot() { void DreamWebEngine::useDiary() { getRidOfReels(); - loadIntoTemp("DREAMWEB.G14"); + loadGraphicsFile(_diaryGraphics, "DREAMWEB.G14"); loadTempText("DREAMWEB.T51"); - loadTempCharset("DREAMWEB.C02"); + loadGraphicsFile(_diaryCharset, "DREAMWEB.C02"); createPanel(); showIcon(); showDiary(); @@ -751,9 +751,9 @@ void DreamWebEngine::useDiary() { } while (!_getBack && !_quitRequested); - getRidOfTemp(); + _diaryGraphics.clear(); getRidOfTempText(); - getRidOfTempCharset(); + _diaryCharset.clear(); restoreReels(); _manIsOffScreen = 0; redrawMainScrn(); @@ -761,8 +761,8 @@ void DreamWebEngine::useDiary() { } void DreamWebEngine::showDiary() { - showFrame(_tempGraphics, kDiaryx, kDiaryy + 37, 1, 0); - showFrame(_tempGraphics, kDiaryx + 176, kDiaryy + 108, 2, 0); + showFrame(_diaryGraphics, kDiaryx, kDiaryy + 37, 1, 0); + showFrame(_diaryGraphics, kDiaryx + 176, kDiaryy + 108, 2, 0); } void DreamWebEngine::showDiaryKeys() { @@ -776,10 +776,10 @@ void DreamWebEngine::showDiaryKeys() { if (_pressed == 'N') { byte frame = (_pressCount == 1) ? 3 : 4; - showFrame(_tempGraphics, kDiaryx + 94, kDiaryy + 97, frame, 0); + showFrame(_diaryGraphics, kDiaryx + 94, kDiaryy + 97, frame, 0); } else { byte frame = (_pressCount == 1) ? 5 : 6; - showFrame(_tempGraphics, kDiaryx + 151, kDiaryy + 71, frame, 0); + showFrame(_diaryGraphics, kDiaryx + 151, kDiaryy + 71, frame, 0); } if (_pressCount == 1) @@ -847,9 +847,9 @@ void DreamWebEngine::diaryKeyN() { } void DreamWebEngine::showDiaryPage() { - showFrame(_tempGraphics, kDiaryx, kDiaryy, 0, 0); + showFrame(_diaryGraphics, kDiaryx, kDiaryy, 0, 0); _kerning = 1; - useTempCharset(); + useTempCharset(&_diaryCharset); _charShift = 91+91; const uint8 *string = getTextInFile1(_diaryPage); uint16 y = kDiaryy + 16; diff --git a/engines/dreamweb/monitor.cpp b/engines/dreamweb/monitor.cpp index d2f6b376ae..f5f064f855 100644 --- a/engines/dreamweb/monitor.cpp +++ b/engines/dreamweb/monitor.cpp @@ -54,11 +54,11 @@ void DreamWebEngine::useMon() { showIcon(); drawFloor(); getRidOfAll(); - loadIntoTemp("DREAMWEB.G03"); // mon. graphic name + loadGraphicsFile(_monitorGraphics, "DREAMWEB.G03"); // mon. graphic name loadPersonal(); loadNews(); loadCart(); - loadTempCharset("DREAMWEB.C01"); // character set 2 + loadGraphicsFile(_monitorCharset, "DREAMWEB.C01"); // character set 2 printOuterMon(); initialMonCols(); printLogo(); @@ -89,8 +89,8 @@ void DreamWebEngine::useMon() { if (_quitRequested) //TODO : Check why it crashes when put before the execcommand break; } while (!stop); - getRidOfTemp(); - getRidOfTempCharset(); + _monitorGraphics.clear(); + _monitorCharset.clear(); _textFile1.clear(); _textFile2.clear(); @@ -188,14 +188,14 @@ void DreamWebEngine::monitorLogo() { } void DreamWebEngine::printLogo() { - showFrame(_tempGraphics, 56, 32, 0, 0); + showFrame(_monitorGraphics, 56, 32, 0, 0); showCurrentFile(); } void DreamWebEngine::input() { memset(_inputLine, 0, 64); _curPos = 0; - printChar(_tempCharset, _monAdX, _monAdY, '>', 0, NULL, NULL); + printChar(_monitorCharset, _monAdX, _monAdY, '>', 0, NULL, NULL); multiDump(_monAdX, _monAdY, 6, 8); _monAdX += 6; _cursLocX = _monAdX; @@ -227,7 +227,7 @@ void DreamWebEngine::input() { continue; multiGet(_mapStore + _curPos * 256, _monAdX, _monAdY, 8, 8); uint8 charWidth; - printChar(_tempCharset, _monAdX, _monAdY, currentKey, 0, &charWidth, NULL); + printChar(_monitorCharset, _monAdX, _monAdY, currentKey, 0, &charWidth, NULL); _inputLine[_curPos * 2 + 1] = charWidth; _monAdX += charWidth; ++_curPos; @@ -266,7 +266,7 @@ void DreamWebEngine::printCurs() { multiGet(_textUnder, x, y, 6, height); ++_mainTimer; if ((_mainTimer & 16) == 0) - showFrame(_tempCharset, x, y, '/' - 32, 0); + showFrame(_monitorCharset, x, y, '/' - 32, 0); multiDump(x - 6, y, 12, height); } @@ -302,17 +302,17 @@ void DreamWebEngine::showCurrentFile() { while (*currentFile) { char c = *currentFile++; c = modifyChar(c); - printChar(_tempCharset, &x, 37, c, 0, NULL, NULL); + printChar(_monitorCharset, &x, 37, c, 0, NULL, NULL); } } void DreamWebEngine::accessLightOn() { - showFrame(_tempGraphics, 74, 182, 8, 0); + showFrame(_monitorGraphics, 74, 182, 8, 0); multiDump(74, 182, 12, 8); } void DreamWebEngine::accessLightOff() { - showFrame(_tempGraphics, 74, 182, 7, 0); + showFrame(_monitorGraphics, 74, 182, 7, 0); multiDump(74, 182, 12, 8); } @@ -345,22 +345,22 @@ void DreamWebEngine::netError() { } void DreamWebEngine::powerLightOn() { - showFrame(_tempGraphics, 257+4, 182, 6, 0); + showFrame(_monitorGraphics, 257+4, 182, 6, 0); multiDump(257+4, 182, 12, 8); } void DreamWebEngine::powerLightOff() { - showFrame(_tempGraphics, 257+4, 182, 5, 0); + showFrame(_monitorGraphics, 257+4, 182, 5, 0); multiDump(257+4, 182, 12, 8); } void DreamWebEngine::lockLightOn() { - showFrame(_tempGraphics, 56, 182, 10, 0); + showFrame(_monitorGraphics, 56, 182, 10, 0); multiDump(58, 182, 12, 8); } void DreamWebEngine::lockLightOff() { - showFrame(_tempGraphics, 56, 182, 9, 0); + showFrame(_monitorGraphics, 56, 182, 9, 0); multiDump(58, 182, 12, 8); } @@ -375,10 +375,10 @@ void DreamWebEngine::turnOnPower() { } void DreamWebEngine::printOuterMon() { - showFrame(_tempGraphics, 40, 32, 1, 0); - showFrame(_tempGraphics, 264, 32, 2, 0); - showFrame(_tempGraphics, 40, 12, 3, 0); - showFrame(_tempGraphics, 40, 164, 4, 0); + showFrame(_monitorGraphics, 40, 32, 1, 0); + showFrame(_monitorGraphics, 264, 32, 2, 0); + showFrame(_monitorGraphics, 40, 12, 3, 0); + showFrame(_monitorGraphics, 40, 164, 4, 0); } void DreamWebEngine::loadPersonal() { diff --git a/engines/dreamweb/newplace.cpp b/engines/dreamweb/newplace.cpp index 8083055da6..c484855da4 100644 --- a/engines/dreamweb/newplace.cpp +++ b/engines/dreamweb/newplace.cpp @@ -41,7 +41,7 @@ void DreamWebEngine::selectLocation() { _pointerFrame = 22; readCityPic(); showCity(); - getRidOfTemp(); + _cityGraphics.clear(); readDestIcon(); loadTravelText(); showPanel(); @@ -89,17 +89,17 @@ void DreamWebEngine::selectLocation() { _getBack = 0; } - getRidOfTemp(); - getRidOfTemp2(); - getRidOfTemp3(); + _newplaceGraphics.clear(); + _newplaceGraphics2.clear(); + _newplaceGraphics3.clear(); _travelText.clear(); } void DreamWebEngine::showCity() { clearWork(); - showFrame(_tempGraphics, 57, 32, 0, 0); - showFrame(_tempGraphics, 120+57, 32, 1, 0); + showFrame(_cityGraphics, 57, 32, 0, 0); + showFrame(_cityGraphics, 120+57, 32, 1, 0); } void DreamWebEngine::lookAtPlace() { @@ -113,10 +113,10 @@ void DreamWebEngine::lookAtPlace() { delPointer(); delTextLine(); getUnderCentre(); - showFrame(_tempGraphics3, 60, 72, 0, 0); - showFrame(_tempGraphics3, 60, 72 + 55, 4, 0); + showFrame(_newplaceGraphics3, 60, 72, 0, 0); + showFrame(_newplaceGraphics3, 60, 72 + 55, 4, 0); if (_foreignRelease) - showFrame(_tempGraphics3, 60, 72+55+21, 4, 0); + showFrame(_newplaceGraphics3, 60, 72+55+21, 4, 0); const uint8 *string = (const uint8 *)_travelText.getString(_destPos); findNextColon(&string); @@ -143,21 +143,21 @@ void DreamWebEngine::locationPic() { byte picture = roomPics[_destPos]; if (picture >= 6) - showFrame(_tempGraphics2, 104, 138 + 14, picture - 6, 0); // Second slot + showFrame(_newplaceGraphics2, 104, 138 + 14, picture - 6, 0); // Second slot else - showFrame(_tempGraphics, 104, 138 + 14, picture + 4, 0); + showFrame(_newplaceGraphics, 104, 138 + 14, picture + 4, 0); if (_destPos == _realLocation) - showFrame(_tempGraphics, 104, 140 + 14, 3, 0); // Currently in this location + showFrame(_newplaceGraphics, 104, 140 + 14, 3, 0); // Currently in this location const uint8 *string = (const uint8 *)_travelText.getString(_destPos); printDirect(string, 50, 20, 241, 241 & 1); } void DreamWebEngine::showArrows() { - showFrame(_tempGraphics, 116 - 12, 16, 0, 0); - showFrame(_tempGraphics, 226 + 12, 16, 1, 0); - showFrame(_tempGraphics, 280, 14, 2, 0); + showFrame(_newplaceGraphics, 116 - 12, 16, 0, 0); + showFrame(_newplaceGraphics, 226 + 12, 16, 1, 0); + showFrame(_newplaceGraphics, 280, 14, 2, 0); } void DreamWebEngine::nextDest() { @@ -259,13 +259,13 @@ void DreamWebEngine::resetLocation(uint8 index) { } void DreamWebEngine::readDestIcon() { - loadIntoTemp("DREAMWEB.G05"); - loadIntoTemp2("DREAMWEB.G06"); - loadIntoTemp3("DREAMWEB.G08"); + loadGraphicsFile(_newplaceGraphics, "DREAMWEB.G05"); + loadGraphicsFile(_newplaceGraphics2, "DREAMWEB.G06"); + loadGraphicsFile(_newplaceGraphics3, "DREAMWEB.G08"); } void DreamWebEngine::readCityPic() { - loadIntoTemp("DREAMWEB.G04"); + loadGraphicsFile(_cityGraphics, "DREAMWEB.G04"); } } // End of namespace DreamWeb diff --git a/engines/dreamweb/print.cpp b/engines/dreamweb/print.cpp index 24e0183a07..a6b93a5590 100644 --- a/engines/dreamweb/print.cpp +++ b/engines/dreamweb/print.cpp @@ -210,7 +210,7 @@ const char *DreamWebEngine::monPrint(const char *string) { bool done = false; while (!done) { - uint16 count = getNumber(_tempCharset, (const uint8 *)iterator, 166, false, &x); + uint16 count = getNumber(_monitorCharset, (const uint8 *)iterator, 166, false, &x); do { char c = *iterator++; if (c == ':') @@ -226,7 +226,7 @@ const char *DreamWebEngine::monPrint(const char *string) { break; } c = modifyChar(c); - printChar(_tempCharset, &x, _monAdY, c, 0, NULL, NULL); + printChar(_monitorCharset, &x, _monAdY, c, 0, NULL, NULL); _cursLocX = x; _cursLocY = _monAdY; _mainTimer = 1; diff --git a/engines/dreamweb/saveload.cpp b/engines/dreamweb/saveload.cpp index 4779d0baef..acc76572ef 100644 --- a/engines/dreamweb/saveload.cpp +++ b/engines/dreamweb/saveload.cpp @@ -178,7 +178,7 @@ void DreamWebEngine::doLoad(int savegameId) { // If we reach this point, loadPosition() has just been called. // Among other things, it will have filled g_MadeUpRoomDat. - getRidOfTemp(); + _saveGraphics.clear(); startLoading(g_madeUpRoomDat); loadRoomsSample(); @@ -270,7 +270,7 @@ void DreamWebEngine::saveGame() { descbuf[++desclen] = 1; // TODO: The below is copied from actualsave - getRidOfTemp(); + _saveGraphics.clear(); restoreAll(); // reels _textAddressX = 13; _textAddressY = 182; @@ -360,7 +360,7 @@ void DreamWebEngine::doSaveLoad() { _textAddressY = 182; _textLen = 240; if (_getBack != 4) { - getRidOfTemp(); + _saveGraphics.clear(); restoreAll(); redrawMainScrn(); workToScreenM(); @@ -388,16 +388,16 @@ void DreamWebEngine::getBackToOps() { } void DreamWebEngine::showMainOps() { - showFrame(_tempGraphics, kOpsx+10, kOpsy+10, 8, 0); - showFrame(_tempGraphics, kOpsx+59, kOpsy+30, 7, 0); - showFrame(_tempGraphics, kOpsx+128+4, kOpsy+12, 1, 0); + showFrame(_saveGraphics, kOpsx+10, kOpsy+10, 8, 0); + showFrame(_saveGraphics, kOpsx+59, kOpsy+30, 7, 0); + showFrame(_saveGraphics, kOpsx+128+4, kOpsy+12, 1, 0); } void DreamWebEngine::showDiscOps() { - showFrame(_tempGraphics, kOpsx+128+4, kOpsy+12, 1, 0); - showFrame(_tempGraphics, kOpsx+10, kOpsy+10, 9, 0); - showFrame(_tempGraphics, kOpsx+59, kOpsy+30, 10, 0); - showFrame(_tempGraphics, kOpsx+176+2, kOpsy+60-4, 5, 0); + showFrame(_saveGraphics, kOpsx+128+4, kOpsy+12, 1, 0); + showFrame(_saveGraphics, kOpsx+10, kOpsy+10, 9, 0); + showFrame(_saveGraphics, kOpsx+59, kOpsy+30, 10, 0); + showFrame(_saveGraphics, kOpsx+176+2, kOpsy+60-4, 5, 0); } void DreamWebEngine::discOps() { @@ -450,7 +450,7 @@ void DreamWebEngine::actualSave() { savePosition(slot, desc); - getRidOfTemp(); + _saveGraphics.clear(); restoreAll(); // reels _textAddressX = 13; _textAddressY = 182; @@ -703,12 +703,12 @@ void DreamWebEngine::loadOld() { void DreamWebEngine::showDecisions() { createPanel2(); showOpBox(); - showFrame(_tempGraphics, kOpsx + 17, kOpsy + 13, 6, 0); + showFrame(_saveGraphics, kOpsx + 17, kOpsy + 13, 6, 0); underTextLine(); } void DreamWebEngine::loadSaveBox() { - loadIntoTemp("DREAMWEB.G08"); + loadGraphicsFile(_saveGraphics, "DREAMWEB.G08"); } // show savegame names (original interface), and set kCursorpos @@ -822,37 +822,37 @@ void DreamWebEngine::selectSlot() { void DreamWebEngine::showSlots() { showFrame(_icons1, kOpsx + 158, kOpsy - 11, 12, 0); showFrame(_icons1, kOpsx + 158 + 18 * _saveLoadPage, kOpsy - 11, 13 + _saveLoadPage, 0); - showFrame(_tempGraphics, kOpsx + 7, kOpsy + 8, 2, 0); + showFrame(_saveGraphics, kOpsx + 7, kOpsy + 8, 2, 0); uint16 y = kOpsy + 11; for (int slot = 0; slot < 7; slot++) { if (slot == _currentSlot) - showFrame(_tempGraphics, kOpsx + 10, y, 3, 0); + showFrame(_saveGraphics, kOpsx + 10, y, 3, 0); y += 10; } } void DreamWebEngine::showOpBox() { - showFrame(_tempGraphics, kOpsx, kOpsy, 0, 0); + showFrame(_saveGraphics, kOpsx, kOpsy, 0, 0); // This call displays half of the ops dialog in the CD version. It's not // in the floppy version, and if it's called, a stray red dot is shown in // the game dialogs. if (isCD()) - showFrame(_tempGraphics, kOpsx, kOpsy + 55, 4, 0); + showFrame(_saveGraphics, kOpsx, kOpsy + 55, 4, 0); } void DreamWebEngine::showLoadOps() { - showFrame(_tempGraphics, kOpsx + 128 + 4, kOpsy + 12, 1, 0); - showFrame(_tempGraphics, kOpsx + 176 + 2, kOpsy + 60 - 4, 5, 0); + showFrame(_saveGraphics, kOpsx + 128 + 4, kOpsy + 12, 1, 0); + showFrame(_saveGraphics, kOpsx + 176 + 2, kOpsy + 60 - 4, 5, 0); printMessage(kOpsx + 104, kOpsy + 14, 55, 101, (101 & 1)); } void DreamWebEngine::showSaveOps() { - showFrame(_tempGraphics, kOpsx + 128 + 4, kOpsy + 12, 1, 0); - showFrame(_tempGraphics, kOpsx + 176 + 2, kOpsy + 60 - 4, 5, 0); + showFrame(_saveGraphics, kOpsx + 128 + 4, kOpsy + 12, 1, 0); + showFrame(_saveGraphics, kOpsx + 176 + 2, kOpsy + 60 - 4, 5, 0); printMessage(kOpsx + 104, kOpsy + 14, 54, 101, (101 & 1)); } diff --git a/engines/dreamweb/structs.h b/engines/dreamweb/structs.h index cedf2b6d76..24b67e317a 100644 --- a/engines/dreamweb/structs.h +++ b/engines/dreamweb/structs.h @@ -339,9 +339,9 @@ struct TextFile { }; struct GraphicsFile { - GraphicsFile() : _data(0) { } + GraphicsFile() : _data(0), _frames(0) { } - Frame _frames[347]; + Frame *_frames; uint8 *_data; const uint8 *getFrameData(unsigned int i) const { @@ -351,6 +351,8 @@ struct GraphicsFile { return _data + _frames[i].ptr(); } void clear() { + delete[] _frames; + _frames = 0; delete[] _data; _data = 0; } diff --git a/engines/dreamweb/stubs.cpp b/engines/dreamweb/stubs.cpp index 5f8ea53ada..763bcb88fe 100644 --- a/engines/dreamweb/stubs.cpp +++ b/engines/dreamweb/stubs.cpp @@ -510,12 +510,27 @@ void DreamWebEngine::dreamwebFinalize() { _icons1.clear(); _icons2.clear(); _charset1.clear(); - _tempGraphics.clear(); - _tempGraphics2.clear(); - _tempGraphics3.clear(); - _tempCharset.clear(); _mainSprites.clear(); + // clear local graphics, just in case + _keypadGraphics.clear(); + _menuGraphics.clear(); + _menuGraphics2.clear(); + _folderGraphics.clear(); + _folderGraphics2.clear(); + _folderGraphics3.clear(); + _folderCharset.clear(); + _symbolGraphics.clear(); + _diaryGraphics.clear(); + _diaryCharset.clear(); + _monitorGraphics.clear(); + _monitorCharset.clear(); + _newplaceGraphics.clear(); + _newplaceGraphics2.clear(); + _newplaceGraphics3.clear(); + _cityGraphics.clear(); + _saveGraphics.clear(); + _exFrames.clear(); _exText.clear(); @@ -828,17 +843,18 @@ void DreamWebEngine::loadGraphicsFile(GraphicsFile &file, const char *fileName) uint16 sizeInBytes = header.len(0); assert(sizeInBytes >= kFrameBlocksize); - delete[] file._data; + file.clear(); file._data = new uint8[sizeInBytes - kFrameBlocksize]; - + file._frames = new Frame[kGraphicsFileFrameSize]; f.read((uint8 *)file._frames, kFrameBlocksize); f.read(file._data, sizeInBytes - kFrameBlocksize); } void DreamWebEngine::loadGraphicsSegment(GraphicsFile &file, Common::File &inFile, unsigned int len) { assert(len >= kFrameBlocksize); - delete[] file._data; + file.clear(); file._data = new uint8[len - kFrameBlocksize]; + file._frames = new Frame[kGraphicsFileFrameSize]; inFile.read((uint8 *)file._frames, kFrameBlocksize); inFile.read(file._data, len - kFrameBlocksize); } @@ -852,22 +868,6 @@ void DreamWebEngine::loadTextSegment(TextFile &file, Common::File &inFile, unsig inFile.read((uint8 *)file._text, len - headerSize); } -void DreamWebEngine::loadIntoTemp(const char *fileName) { - loadGraphicsFile(_tempGraphics, fileName); -} - -void DreamWebEngine::loadIntoTemp2(const char *fileName) { - loadGraphicsFile(_tempGraphics2, fileName); -} - -void DreamWebEngine::loadIntoTemp3(const char *fileName) { - loadGraphicsFile(_tempGraphics3, fileName); -} - -void DreamWebEngine::loadTempCharset(const char *fileName) { - loadGraphicsFile(_tempCharset, fileName); -} - void DreamWebEngine::hangOnCurs(uint16 frameCount) { for (uint16 i = 0; i < frameCount; ++i) { printCurs(); @@ -2065,30 +2065,14 @@ void DreamWebEngine::useCharset1() { _currentCharset = &_charset1; } -void DreamWebEngine::useTempCharset() { - _currentCharset = &_tempCharset; -} - -void DreamWebEngine::getRidOfTemp() { - _tempGraphics.clear(); +void DreamWebEngine::useTempCharset(GraphicsFile *charset) { + _currentCharset = charset; } void DreamWebEngine::getRidOfTempText() { _textFile1.clear(); } -void DreamWebEngine::getRidOfTemp2() { - _tempGraphics2.clear(); -} - -void DreamWebEngine::getRidOfTemp3() { - _tempGraphics3.clear(); -} - -void DreamWebEngine::getRidOfTempCharset() { - _tempCharset.clear(); -} - void DreamWebEngine::getRidOfAll() { delete[] _backdropBlocks; _backdropBlocks = 0; @@ -2274,6 +2258,7 @@ void DreamWebEngine::drawFloor() { void DreamWebEngine::allocateBuffers() { _exFrames.clear(); _exFrames._data = new uint8[kExframeslen]; + _exFrames._frames = new Frame[kGraphicsFileFrameSize]; _exText.clear(); _exText._text = new char[kExtextlen]; } @@ -2765,7 +2750,7 @@ void DreamWebEngine::decide() { } while (!_getBack); if (_getBack != 4) - getRidOfTemp(); // room not loaded + _saveGraphics.clear(); // room not loaded _textAddressX = 13; _textAddressY = 182; @@ -2794,12 +2779,13 @@ void DreamWebEngine::showGun() { _roomsSample = 34; loadRoomsSample(); _volume = 0; - loadIntoTemp("DREAMWEB.G13"); + GraphicsFile graphics; + loadGraphicsFile(graphics, "DREAMWEB.G13"); createPanel2(); - showFrame(_tempGraphics, 100, 4, 0, 0); - showFrame(_tempGraphics, 158, 106, 1, 0); + showFrame(graphics, 100, 4, 0, 0); + showFrame(graphics, 158, 106, 1, 0); workToScreen(); - getRidOfTemp(); + graphics.clear(); fadeScreenUp(); hangOn(160); playChannel0(12, 0); @@ -3018,7 +3004,7 @@ void DreamWebEngine::lookAtCard() { getRidOfReels(); loadKeypad(); createPanel2(); - showFrame(_tempGraphics, 160, 80, 42, 128); + showFrame(_keypadGraphics, 160, 80, 42, 128); const uint8 *obText = getObTextStart(); findNextColon(&obText); findNextColon(&obText); @@ -3028,12 +3014,12 @@ void DreamWebEngine::lookAtCard() { workToScreenM(); hangOnW(280); createPanel2(); - showFrame(_tempGraphics, 160, 80, 42, 128); + showFrame(_keypadGraphics, 160, 80, 42, 128); printDirect(obText, 36, 130, 241, 241 & 1); workToScreenM(); hangOnW(200); _manIsOffScreen = 0; - getRidOfTemp(); + _keypadGraphics.clear(); restoreReels(); putBackObStuff(); } diff --git a/engines/dreamweb/titles.cpp b/engines/dreamweb/titles.cpp index 8ca5aa70b3..f4112f71f6 100644 --- a/engines/dreamweb/titles.cpp +++ b/engines/dreamweb/titles.cpp @@ -40,9 +40,10 @@ void DreamWebEngine::endGame() { void DreamWebEngine::monkSpeaking() { _roomsSample = 35; loadRoomsSample(); - loadIntoTemp("DREAMWEB.G15"); + GraphicsFile graphics; + loadGraphicsFile(graphics, "DREAMWEB.G15"); clearWork(); - showFrame(_tempGraphics, 160, 72, 0, 128); // show monk + showFrame(graphics, 160, 72, 0, 128); // show monk workToScreen(); _volume = 7; _volumeDirection = -1; @@ -74,7 +75,7 @@ void DreamWebEngine::monkSpeaking() { printResult = printDirect(&string, 36, &y, 239, 239 & 1); workToScreen(); clearWork(); - showFrame(_tempGraphics, 160, 72, 0, 128); // show monk + showFrame(graphics, 160, 72, 0, 128); // show monk hangOnP(240); if (_quitRequested) return; @@ -86,7 +87,7 @@ void DreamWebEngine::monkSpeaking() { _volumeTo = 7; fadeScreenDowns(); hangOn(300); - getRidOfTemp(); + graphics.clear(); } void DreamWebEngine::gettingShot() { diff --git a/engines/dreamweb/use.cpp b/engines/dreamweb/use.cpp index fc0398c7b9..e59843539f 100644 --- a/engines/dreamweb/use.cpp +++ b/engines/dreamweb/use.cpp @@ -1501,7 +1501,7 @@ void DreamWebEngine::useCashCard() { showExit(); showMan(); uint16 y = (!_foreignRelease) ? 120 : 120 - 3; - showFrame(_tempGraphics, 114, y, 39, 0); + showFrame(_keypadGraphics, 114, y, 39, 0); const uint8 *obText = getObTextStart(); findNextColon(&obText); findNextColon(&obText); @@ -1517,7 +1517,7 @@ void DreamWebEngine::useCashCard() { _charShift = 0; workToScreenM(); hangOnP(400); - getRidOfTemp(); + _keypadGraphics.clear(); restoreReels(); putBackObStuff(); } diff --git a/engines/gob/hotspots.cpp b/engines/gob/hotspots.cpp index 5e0af847de..9a89f11923 100644 --- a/engines/gob/hotspots.cpp +++ b/engines/gob/hotspots.cpp @@ -477,7 +477,7 @@ void Hotspots::call(uint16 offset) { _shouldPush = true; - int16 stackSize = _stack.size(); + Common::Stack<StackEntry>::size_type stackSize = _stack.size(); _vm->_inter->funcBlock(0); diff --git a/engines/sword1/animation.cpp b/engines/sword1/animation.cpp index e274e02cfd..1e2964054a 100644 --- a/engines/sword1/animation.cpp +++ b/engines/sword1/animation.cpp @@ -37,6 +37,11 @@ #include "gui/message.h" +#include "video/psx_decoder.h" +#include "video/smk_decoder.h" + +#include "engines/util.h" + namespace Sword1 { static const char *const sequenceList[20] = { @@ -62,6 +67,31 @@ static const char *const sequenceList[20] = { "credits", // 19 CD2 credits, to follow "finale" sequence }; +// This is the list of the names of the PlayStation videos +// TODO: fight.str, flashy.str, +static const char *const sequenceListPSX[20] = { + "e_ferr1", + "ladder1", + "steps1", + "sewer1", + "e_intro1", + "river1", + "truck1", + "grave1", + "montfcn1", + "tapesty1", + "ireland1", + "e_fin1", + "e_hist1", + "spanish1", + "well1", + "candle1", + "geodrop1", + "vulture1", + "", // demo video not present + "" // credits are not a video +}; + /////////////////////////////////////////////////////////////////////////////// // Basic movie player /////////////////////////////////////////////////////////////////////////////// @@ -150,6 +180,21 @@ bool MoviePlayer::load(uint32 id) { case kVideoDecoderSMK: filename = Common::String::format("%s.smk", sequenceList[id]); break; + case kVideoDecoderPSX: + filename = Common::String::format("%s.str", (_vm->_systemVars.isDemo) ? sequenceList[id] : sequenceListPSX[id]); + + // Need to switch to true color + initGraphics(g_system->getWidth(), g_system->getHeight(), true, 0); + + // Need to load here in case it fails in which case we'd need + // to go back to paletted mode + if (_decoder->loadFile(filename)) { + return true; + } else { + initGraphics(g_system->getWidth(), g_system->getHeight(), true); + return false; + } + break; } return _decoder->loadFile(filename.c_str()); @@ -187,6 +232,11 @@ void MoviePlayer::play() { } void MoviePlayer::performPostProcessing(byte *screen) { + // TODO: We don't support the PSX stream videos yet + // nor using the PSX fonts to display subtitles. + if (_vm->isPsx()) + return; + if (!_movieTexts.empty()) { if (_decoder->getCurFrame() == _movieTexts.front()._startFrame) { _textMan->makeTextSprite(2, (const uint8 *)_movieTexts.front()._text.c_str(), 600, LETTER_COL); @@ -215,10 +265,10 @@ void MoviePlayer::performPostProcessing(byte *screen) { for (x = 0; x < _textWidth; x++) { switch (src[x]) { case BORDER_COL: - dst[x] = findBlackPalIndex(); + dst[x] = getBlackColor(); break; case LETTER_COL: - dst[x] = findTextColorPalIndex(); + dst[x] = findTextColor(); break; } } @@ -238,12 +288,12 @@ void MoviePlayer::performPostProcessing(byte *screen) { for (y = 0; y < _textHeight; y++) { if (_textY + y < frameY || _textY + y >= frameY + frameHeight) { - memset(dst + _textX, findBlackPalIndex(), _textWidth); + memset(dst + _textX, getBlackColor(), _textWidth); } else { if (frameX > _textX) - memset(dst + _textX, findBlackPalIndex(), frameX - _textX); + memset(dst + _textX, getBlackColor(), frameX - _textX); if (frameX + frameWidth < _textX + _textWidth) - memset(dst + frameX + frameWidth, findBlackPalIndex(), _textX + _textWidth - (frameX + frameWidth)); + memset(dst + frameX + frameWidth, getBlackColor(), _textX + _textWidth - (frameX + frameWidth)); } dst += _system->getWidth(); @@ -255,14 +305,19 @@ void MoviePlayer::performPostProcessing(byte *screen) { } bool MoviePlayer::playVideo() { + bool skipped = false; uint16 x = (g_system->getWidth() - _decoder->getWidth()) / 2; uint16 y = (g_system->getHeight() - _decoder->getHeight()) / 2; - while (!_vm->shouldQuit() && !_decoder->endOfVideo()) { + while (!_vm->shouldQuit() && !_decoder->endOfVideo() && !skipped) { if (_decoder->needsUpdate()) { const Graphics::Surface *frame = _decoder->decodeNextFrame(); - if (frame) - _vm->_system->copyRectToScreen((byte *)frame->pixels, frame->pitch, x, y, frame->w, frame->h); + if (frame) { + if (_decoderType == kVideoDecoderPSX) + drawFramePSX(frame); + else + _vm->_system->copyRectToScreen((byte *)frame->pixels, frame->pitch, x, y, frame->w, frame->h); + } if (_decoder->hasDirtyPalette()) { _decoder->setSystemPalette(); @@ -362,19 +417,40 @@ bool MoviePlayer::playVideo() { Common::Event event; while (_vm->_system->getEventManager()->pollEvent(event)) if ((event.type == Common::EVENT_KEYDOWN && event.kbd.keycode == Common::KEYCODE_ESCAPE) || event.type == Common::EVENT_LBUTTONUP) - return false; + skipped = true; _vm->_system->delayMillis(10); } - return !_vm->shouldQuit(); + if (_decoderType == kVideoDecoderPSX) { + // Need to jump back to paletted color + initGraphics(g_system->getWidth(), g_system->getHeight(), true); + } + + return !_vm->shouldQuit() && !skipped; } -byte MoviePlayer::findBlackPalIndex() { - return _black; +uint32 MoviePlayer::getBlackColor() { + return (_decoderType == kVideoDecoderPSX) ? g_system->getScreenFormat().RGBToColor(0x00, 0x00, 0x00) : _black; } - -byte MoviePlayer::findTextColorPalIndex() { + +uint32 MoviePlayer::findTextColor() { + if (_decoderType == kVideoDecoderPSX) { + // We're in true color mode, so return the actual colors + switch (_textColor) { + case 1: + return g_system->getScreenFormat().RGBToColor(248, 252, 248); + case 2: + return g_system->getScreenFormat().RGBToColor(184, 188, 184); + case 3: + return g_system->getScreenFormat().RGBToColor(200, 120, 184); + case 4: + return g_system->getScreenFormat().RGBToColor(80, 152, 184); + } + + return g_system->getScreenFormat().RGBToColor(0xFF, 0xFF, 0xFF); + } + switch (_textColor) { case 1: return _c1Color; @@ -413,6 +489,23 @@ void MoviePlayer::convertColor(byte r, byte g, byte b, float &h, float &s, float } } +void MoviePlayer::drawFramePSX(const Graphics::Surface *frame) { + // The PSX videos have half resolution + + Graphics::Surface scaledFrame; + scaledFrame.create(frame->w, frame->h * 2, frame->format); + + for (int y = 0; y < scaledFrame.h; y++) + memcpy(scaledFrame.getBasePtr(0, y), frame->getBasePtr(0, y / 2), scaledFrame.w * scaledFrame.format.bytesPerPixel); + + uint16 x = (g_system->getWidth() - scaledFrame.w) / 2; + uint16 y = (g_system->getHeight() - scaledFrame.h) / 2; + + _vm->_system->copyRectToScreen((byte *)scaledFrame.pixels, scaledFrame.pitch, x, y, scaledFrame.w, scaledFrame.h); + + scaledFrame.free(); +} + DXADecoderWithSound::DXADecoderWithSound(Audio::Mixer *mixer, Audio::SoundHandle *bgSoundHandle) : _mixer(mixer), _bgSoundHandle(bgSoundHandle) { } @@ -432,6 +525,24 @@ MoviePlayer *makeMoviePlayer(uint32 id, SwordEngine *vm, Text *textMan, ResMan * Common::String filename; Audio::SoundHandle *bgSoundHandle = new Audio::SoundHandle; + // For the PSX version, we'll try the PlayStation stream files + if (vm->isPsx()) { + // The demo uses the normal file names + filename = ((vm->_systemVars.isDemo) ? Common::String(sequenceList[id]) : Common::String(sequenceListPSX[id])) + ".str"; + + if (Common::File::exists(filename)) { +#ifdef USE_RGB_COLOR + // All BS1 PSX videos run the videos at 2x speed + Video::VideoDecoder *psxDecoder = new Video::PSXStreamDecoder(Video::PSXStreamDecoder::kCD2x); + return new MoviePlayer(vm, textMan, resMan, snd, system, bgSoundHandle, psxDecoder, kVideoDecoderPSX); +#else + GUI::MessageDialog dialog(Common::String::format(_("PSX stream cutscene '%s' cannot be played in paletted mode"), filename.c_str()), _("OK")); + dialog.runModal(); + return 0; +#endif + } + } + filename = Common::String::format("%s.smk", sequenceList[id]); if (Common::File::exists(filename)) { @@ -461,9 +572,11 @@ MoviePlayer *makeMoviePlayer(uint32 id, SwordEngine *vm, Text *textMan, ResMan * return NULL; } - Common::String buf = Common::String::format(_("Cutscene '%s' not found"), sequenceList[id]); - GUI::MessageDialog dialog(buf, _("OK")); - dialog.runModal(); + if (!vm->isPsx() || scumm_stricmp(sequenceList[id], "enddemo") != 0) { + Common::String buf = Common::String::format(_("Cutscene '%s' not found"), sequenceList[id]); + GUI::MessageDialog dialog(buf, _("OK")); + dialog.runModal(); + } return NULL; } diff --git a/engines/sword1/animation.h b/engines/sword1/animation.h index c436607211..f64b03dd1b 100644 --- a/engines/sword1/animation.h +++ b/engines/sword1/animation.h @@ -24,7 +24,6 @@ #define SWORD1_ANIMATION_H #include "video/dxa_decoder.h" -#include "video/smk_decoder.h" #include "video/video_decoder.h" #include "common/list.h" @@ -38,7 +37,8 @@ namespace Sword1 { enum DecoderType { kVideoDecoderDXA = 0, - kVideoDecoderSMK = 1 + kVideoDecoderSMK = 1, + kVideoDecoderPSX = 2 }; class MovieText { @@ -83,8 +83,8 @@ protected: Common::List<MovieText> _movieTexts; int _textX, _textY, _textWidth, _textHeight; int _textColor; - byte _black; - byte _c1Color, _c2Color, _c3Color, _c4Color; + uint32 _black; + uint32 _c1Color, _c2Color, _c3Color, _c4Color; DecoderType _decoderType; Video::VideoDecoder *_decoder; @@ -93,9 +93,10 @@ protected: bool playVideo(); void performPostProcessing(byte *screen); + void drawFramePSX(const Graphics::Surface *frame); - byte findBlackPalIndex(); - byte findTextColorPalIndex(); + uint32 getBlackColor(); + uint32 findTextColor(); void convertColor(byte r, byte g, byte b, float &h, float &s, float &v); }; diff --git a/engines/sword1/sword1.cpp b/engines/sword1/sword1.cpp index 865e025786..75e8f72d9d 100644 --- a/engines/sword1/sword1.cpp +++ b/engines/sword1/sword1.cpp @@ -62,8 +62,9 @@ SwordEngine::SwordEngine(OSystem *syst) SearchMan.addSubDirectoryMatching(gameDataDir, "speech"); SearchMan.addSubDirectoryMatching(gameDataDir, "video"); SearchMan.addSubDirectoryMatching(gameDataDir, "smackshi"); - SearchMan.addSubDirectoryMatching(gameDataDir, "english");//PSX Demo - SearchMan.addSubDirectoryMatching(gameDataDir, "italian");//PSX Demo + SearchMan.addSubDirectoryMatching(gameDataDir, "streams"); // PSX videos + SearchMan.addSubDirectoryMatching(gameDataDir, "english"); // PSX Demo + SearchMan.addSubDirectoryMatching(gameDataDir, "italian"); // PSX Demo _console = new SwordConsole(this); } diff --git a/engines/sword2/animation.cpp b/engines/sword2/animation.cpp index 80b4809722..e77ae98163 100644 --- a/engines/sword2/animation.cpp +++ b/engines/sword2/animation.cpp @@ -40,6 +40,11 @@ #include "gui/message.h" +#include "video/smk_decoder.h" +#include "video/psx_decoder.h" + +#include "engines/util.h" + namespace Sword2 { /////////////////////////////////////////////////////////////////////////////// @@ -66,6 +71,10 @@ MoviePlayer::~MoviePlayer() { * @param id the id of the file */ bool MoviePlayer::load(const char *name) { + // This happens when quitting during the "eye" cutscene. + if (_vm->shouldQuit()) + return false; + if (_decoderType == kVideoDecoderDXA) _bgSoundStream = Audio::SeekableAudioStream::openStreamFile(name); else @@ -81,16 +90,26 @@ bool MoviePlayer::load(const char *name) { case kVideoDecoderSMK: filename = Common::String::format("%s.smk", name); break; + case kVideoDecoderPSX: + filename = Common::String::format("%s.str", name); + + // Need to switch to true color + initGraphics(640, 480, true, 0); + + // Need to load here in case it fails in which case we'd need + // to go back to paletted mode + if (_decoder->loadFile(filename)) { + return true; + } else { + initGraphics(640, 480, true); + return false; + } } return _decoder->loadFile(filename.c_str()); } void MoviePlayer::play(MovieText *movieTexts, uint32 numMovieTexts, uint32 leadIn, uint32 leadOut) { - // This happens when quitting during the "eye" cutscene. - if (_vm->shouldQuit()) - return; - _leadOutFrame = _decoder->getFrameCount(); if (_leadOutFrame > 60) _leadOutFrame -= 60; @@ -120,6 +139,11 @@ void MoviePlayer::play(MovieText *movieTexts, uint32 numMovieTexts, uint32 leadI while (_snd->isSoundHandleActive(*_bgSoundHandle)) _system->delayMillis(100); + + if (_decoderType == kVideoDecoderPSX) { + // Need to jump back to paletted color + initGraphics(640, 480, true); + } } void MoviePlayer::openTextObject(uint32 index) { @@ -165,7 +189,7 @@ void MoviePlayer::openTextObject(uint32 index) { } } -void MoviePlayer::closeTextObject(uint32 index, byte *screen, uint16 pitch) { +void MoviePlayer::closeTextObject(uint32 index, Graphics::Surface *screen, uint16 pitch) { if (index < _numMovieTexts) { MovieText *text = &_movieTexts[index]; @@ -180,23 +204,23 @@ void MoviePlayer::closeTextObject(uint32 index, byte *screen, uint16 pitch) { int frameWidth = _decoder->getWidth(); int frameHeight = _decoder->getHeight(); + + if (_decoderType == kVideoDecoderPSX) + frameHeight *= 2; + int frameX = (_system->getWidth() - frameWidth) / 2; int frameY = (_system->getHeight() - frameHeight) / 2; - byte black = findBlackPalIndex(); - - byte *dst = screen + _textY * pitch; + uint32 black = getBlackColor(); for (int y = 0; y < text->_textSprite.h; y++) { if (_textY + y < frameY || _textY + y >= frameY + frameHeight) { - memset(dst + _textX, black, text->_textSprite.w); + screen->hLine(_textX, _textY + y, _textX + text->_textSprite.w, black); } else { if (frameX > _textX) - memset(dst + _textX, black, frameX - _textX); + screen->hLine(_textX, _textY + y, frameX, black); if (frameX + frameWidth < _textX + text->_textSprite.w) - memset(dst + frameX + frameWidth, black, _textX + text->_textSprite.w - (frameX + frameWidth)); + screen->hLine(frameX + frameWidth, _textY + y, text->_textSprite.w, black); } - - dst += pitch; } } @@ -206,11 +230,24 @@ void MoviePlayer::closeTextObject(uint32 index, byte *screen, uint16 pitch) { } } -void MoviePlayer::drawTextObject(uint32 index, byte *screen, uint16 pitch) { +#define PUT_PIXEL(c) \ + switch (screen->format.bytesPerPixel) { \ + case 1: \ + *dst = (c); \ + break; \ + case 2: \ + WRITE_UINT16(dst, (c)); \ + break; \ + case 4: \ + WRITE_UINT32(dst, (c)); \ + break; \ + } + +void MoviePlayer::drawTextObject(uint32 index, Graphics::Surface *screen, uint16 pitch) { MovieText *text = &_movieTexts[index]; - byte white = findWhitePalIndex(); - byte black = findBlackPalIndex(); + uint32 white = getWhiteColor(); + uint32 black = getBlackColor(); if (text->_textMem && _textSurface) { byte *src = text->_textSprite.data; @@ -226,17 +263,20 @@ void MoviePlayer::drawTextObject(uint32 index, byte *screen, uint16 pitch) { src = psxSpriteBuffer; } - byte *dst = screen + _textY * pitch + _textX; - for (int y = 0; y < height; y++) { + byte *dst = (byte *)screen->getBasePtr(_textX, _textY + y); + for (int x = 0; x < width; x++) { - if (src[x] == 1) - dst[x] = black; - else if (src[x] == 255) - dst[x] = white; + if (src[x] == 1) { + PUT_PIXEL(black); + } else if (src[x] == 255) { + PUT_PIXEL(white); + } + + dst += screen->format.bytesPerPixel; } + src += width; - dst += pitch; } // Free buffer used to resize psx sprite @@ -245,7 +285,9 @@ void MoviePlayer::drawTextObject(uint32 index, byte *screen, uint16 pitch) { } } -void MoviePlayer::performPostProcessing(byte *screen, uint16 pitch) { +#undef PUT_PIXEL + +void MoviePlayer::performPostProcessing(Graphics::Surface *screen, uint16 pitch) { MovieText *text; int frame = _decoder->getCurFrame(); @@ -286,8 +328,12 @@ bool MoviePlayer::playVideo() { while (!_vm->shouldQuit() && !_decoder->endOfVideo()) { if (_decoder->needsUpdate()) { const Graphics::Surface *frame = _decoder->decodeNextFrame(); - if (frame) - _vm->_system->copyRectToScreen((byte *)frame->pixels, frame->pitch, x, y, frame->w, frame->h); + if (frame) { + if (_decoderType == kVideoDecoderPSX) + drawFramePSX(frame); + else + _vm->_system->copyRectToScreen((byte *)frame->pixels, frame->pitch, x, y, frame->w, frame->h); + } if (_decoder->hasDirtyPalette()) { _decoder->setSystemPalette(); @@ -319,7 +365,7 @@ bool MoviePlayer::playVideo() { } Graphics::Surface *screen = _vm->_system->lockScreen(); - performPostProcessing((byte *)screen->pixels, screen->pitch); + performPostProcessing(screen, screen->pitch); _vm->_system->unlockScreen(); _vm->_system->updateScreen(); } @@ -335,12 +381,29 @@ bool MoviePlayer::playVideo() { return !_vm->shouldQuit(); } -byte MoviePlayer::findBlackPalIndex() { - return _black; +uint32 MoviePlayer::getBlackColor() { + return (_decoderType == kVideoDecoderPSX) ? g_system->getScreenFormat().RGBToColor(0x00, 0x00, 0x00) : _black; } -byte MoviePlayer::findWhitePalIndex() { - return _white; +uint32 MoviePlayer::getWhiteColor() { + return (_decoderType == kVideoDecoderPSX) ? g_system->getScreenFormat().RGBToColor(0xFF, 0xFF, 0xFF) : _white; +} + +void MoviePlayer::drawFramePSX(const Graphics::Surface *frame) { + // The PSX videos have half resolution + + Graphics::Surface scaledFrame; + scaledFrame.create(frame->w, frame->h * 2, frame->format); + + for (int y = 0; y < scaledFrame.h; y++) + memcpy(scaledFrame.getBasePtr(0, y), frame->getBasePtr(0, y / 2), scaledFrame.w * scaledFrame.format.bytesPerPixel); + + uint16 x = (g_system->getWidth() - scaledFrame.w) / 2; + uint16 y = (g_system->getHeight() - scaledFrame.h) / 2; + + _vm->_system->copyRectToScreen((byte *)scaledFrame.pixels, scaledFrame.pitch, x, y, scaledFrame.w, scaledFrame.h); + + scaledFrame.free(); } DXADecoderWithSound::DXADecoderWithSound(Audio::Mixer *mixer, Audio::SoundHandle *bgSoundHandle) @@ -358,10 +421,23 @@ uint32 DXADecoderWithSound::getElapsedTime() const { // Factory function for creating the appropriate cutscene player /////////////////////////////////////////////////////////////////////////////// -MoviePlayer *makeMoviePlayer(const char *name, Sword2Engine *vm, Audio::Mixer *snd, OSystem *system) { +MoviePlayer *makeMoviePlayer(const char *name, Sword2Engine *vm, Audio::Mixer *snd, OSystem *system, uint32 frameCount) { Common::String filename; Audio::SoundHandle *bgSoundHandle = new Audio::SoundHandle; + filename = Common::String::format("%s.str", name); + + if (Common::File::exists(filename)) { +#ifdef USE_RGB_COLOR + Video::VideoDecoder *psxDecoder = new Video::PSXStreamDecoder(Video::PSXStreamDecoder::kCD2x, frameCount); + return new MoviePlayer(vm, snd, system, bgSoundHandle, psxDecoder, kVideoDecoderPSX); +#else + GUI::MessageDialog dialog(_("PSX cutscenes found but ScummVM has been built without RGB color support"), _("OK")); + dialog.runModal(); + return NULL; +#endif + } + filename = Common::String::format("%s.smk", name); if (Common::File::exists(filename)) { diff --git a/engines/sword2/animation.h b/engines/sword2/animation.h index 1f5fced03b..3ef8dac754 100644 --- a/engines/sword2/animation.h +++ b/engines/sword2/animation.h @@ -26,7 +26,6 @@ #define SWORD2_ANIMATION_H #include "video/dxa_decoder.h" -#include "video/smk_decoder.h" #include "video/video_decoder.h" #include "audio/mixer.h" @@ -36,7 +35,8 @@ namespace Sword2 { enum DecoderType { kVideoDecoderDXA = 0, - kVideoDecoderSMK = 1 + kVideoDecoderSMK = 1, + kVideoDecoderPSX = 2 }; struct MovieText { @@ -93,18 +93,19 @@ protected: uint32 _leadOut; int _leadOutFrame; - void performPostProcessing(byte *screen, uint16 pitch); + void performPostProcessing(Graphics::Surface *screen, uint16 pitch); bool playVideo(); + void drawFramePSX(const Graphics::Surface *frame); void openTextObject(uint32 index); - void closeTextObject(uint32 index, byte *screen, uint16 pitch); - void drawTextObject(uint32 index, byte *screen, uint16 pitch); + void closeTextObject(uint32 index, Graphics::Surface *screen, uint16 pitch); + void drawTextObject(uint32 index, Graphics::Surface *screen, uint16 pitch); - byte findBlackPalIndex(); - byte findWhitePalIndex(); + uint32 getBlackColor(); + uint32 getWhiteColor(); }; -MoviePlayer *makeMoviePlayer(const char *name, Sword2Engine *vm, Audio::Mixer *snd, OSystem *system); +MoviePlayer *makeMoviePlayer(const char *name, Sword2Engine *vm, Audio::Mixer *snd, OSystem *system, uint32 frameCount); } // End of namespace Sword2 diff --git a/engines/sword2/function.cpp b/engines/sword2/function.cpp index 60ee6176a4..836b252d6c 100644 --- a/engines/sword2/function.cpp +++ b/engines/sword2/function.cpp @@ -2137,7 +2137,9 @@ int32 Logic::fnPlaySequence(int32 *params) { // pause sfx during sequence _vm->_sound->pauseFx(); - _moviePlayer = makeMoviePlayer(filename, _vm, _vm->_mixer, _vm->_system); + uint32 frameCount = Sword2Engine::isPsx() ? params[1] : 0; + + _moviePlayer = makeMoviePlayer(filename, _vm, _vm->_mixer, _vm->_system, frameCount); if (_moviePlayer && _moviePlayer->load(filename)) { _moviePlayer->play(_sequenceTextList, _sequenceTextLines, _smackerLeadIn, _smackerLeadOut); diff --git a/engines/sword2/sword2.cpp b/engines/sword2/sword2.cpp index 3b7965259c..bdfc388c5f 100644 --- a/engines/sword2/sword2.cpp +++ b/engines/sword2/sword2.cpp @@ -255,6 +255,7 @@ Sword2Engine::Sword2Engine(OSystem *syst) : Engine(syst), _rnd("sword2") { SearchMan.addSubDirectoryMatching(gameDataDir, "sword2"); SearchMan.addSubDirectoryMatching(gameDataDir, "video"); SearchMan.addSubDirectoryMatching(gameDataDir, "smacks"); + SearchMan.addSubDirectoryMatching(gameDataDir, "streams"); // PSX video if (!scumm_stricmp(ConfMan.get("gameid").c_str(), "sword2demo") || !scumm_stricmp(ConfMan.get("gameid").c_str(), "sword2psxdemo")) _features = GF_DEMO; diff --git a/engines/tinsel/background.cpp b/engines/tinsel/background.cpp index 72397db97f..8e3fc50f12 100644 --- a/engines/tinsel/background.cpp +++ b/engines/tinsel/background.cpp @@ -34,7 +34,7 @@ namespace Tinsel { // FIXME: Avoid non-const global vars // current background -const BACKGND *pCurBgnd = NULL; +const BACKGND *g_pCurBgnd = NULL; /** * Called to initialize a background. @@ -46,7 +46,7 @@ void InitBackground(const BACKGND *pBgnd) { PLAYFIELD *pPlayfield; // pointer to current playfield // set current background - pCurBgnd = pBgnd; + g_pCurBgnd = pBgnd; // init background sky color SetBgndColor(pBgnd->rgbSkyColor); @@ -83,13 +83,13 @@ void PlayfieldSetPos(int which, int newXpos, int newYpos) { PLAYFIELD *pPlayfield; // pointer to relavent playfield // make sure there is a background - assert(pCurBgnd != NULL); + assert(g_pCurBgnd != NULL); // make sure the playfield number is in range - assert(which >= 0 && which < pCurBgnd->numPlayfields); + assert(which >= 0 && which < g_pCurBgnd->numPlayfields); // get playfield pointer - pPlayfield = pCurBgnd->fieldArray + which; + pPlayfield = g_pCurBgnd->fieldArray + which; // set new integer position pPlayfield->fieldX = intToFrac(newXpos); @@ -110,13 +110,13 @@ void PlayfieldGetPos(int which, int *pXpos, int *pYpos) { PLAYFIELD *pPlayfield; // pointer to relavent playfield // make sure there is a background - assert(pCurBgnd != NULL); + assert(g_pCurBgnd != NULL); // make sure the playfield number is in range - assert(which >= 0 && which < pCurBgnd->numPlayfields); + assert(which >= 0 && which < g_pCurBgnd->numPlayfields); // get playfield pointer - pPlayfield = pCurBgnd->fieldArray + which; + pPlayfield = g_pCurBgnd->fieldArray + which; // get current integer position *pXpos = fracToInt(pPlayfield->fieldX); @@ -132,13 +132,13 @@ int PlayfieldGetCenterX(int which) { PLAYFIELD *pPlayfield; // pointer to relavent playfield // make sure there is a background - assert(pCurBgnd != NULL); + assert(g_pCurBgnd != NULL); // make sure the playfield number is in range - assert(which >= 0 && which < pCurBgnd->numPlayfields); + assert(which >= 0 && which < g_pCurBgnd->numPlayfields); // get playfield pointer - pPlayfield = pCurBgnd->fieldArray + which; + pPlayfield = g_pCurBgnd->fieldArray + which; // get current integer position return fracToInt(pPlayfield->fieldX) + SCREEN_WIDTH/2; @@ -153,13 +153,13 @@ OBJECT **GetPlayfieldList(int which) { PLAYFIELD *pPlayfield; // pointer to relavent playfield // make sure there is a background - assert(pCurBgnd != NULL); + assert(g_pCurBgnd != NULL); // make sure the playfield number is in range - assert(which >= 0 && which < pCurBgnd->numPlayfields); + assert(which >= 0 && which < g_pCurBgnd->numPlayfields); // get playfield pointer - pPlayfield = pCurBgnd->fieldArray + which; + pPlayfield = g_pCurBgnd->fieldArray + which; // return the display list pointer for this playfield return &pPlayfield->pDispList; @@ -177,13 +177,13 @@ void DrawBackgnd() { int prevX, prevY; // save interger part of position Common::Point ptWin; // window top left - if (pCurBgnd == NULL) + if (g_pCurBgnd == NULL) return; // no current background // scroll each background playfield - for (i = 0; i < pCurBgnd->numPlayfields; i++) { + for (i = 0; i < g_pCurBgnd->numPlayfields; i++) { // get pointer to correct playfield - pPlay = pCurBgnd->fieldArray + i; + pPlay = g_pCurBgnd->fieldArray + i; // save integer part of position prevX = fracToInt(pPlay->fieldX); @@ -220,11 +220,11 @@ void DrawBackgnd() { for (RectList::const_iterator r = clipRects.begin(); r != clipRects.end(); ++r) { // clear the clip rectangle on the virtual screen // for each background playfield - for (i = 0; i < pCurBgnd->numPlayfields; i++) { + for (i = 0; i < g_pCurBgnd->numPlayfields; i++) { Common::Rect rcPlayClip; // clip rect for this playfield // get pointer to correct playfield - pPlay = pCurBgnd->fieldArray + i; + pPlay = g_pCurBgnd->fieldArray + i; // convert fixed point window pos to a int ptWin.x = fracToInt(pPlay->fieldX); diff --git a/engines/tinsel/bg.cpp b/engines/tinsel/bg.cpp index cf692e16ea..72ba05f0b9 100644 --- a/engines/tinsel/bg.cpp +++ b/engines/tinsel/bg.cpp @@ -47,59 +47,59 @@ namespace Tinsel { #define MAX_BG 10 // FIXME: Avoid non-const global vars -static SCNHANDLE hBgPal = 0; // Background's palette -static POBJECT pBG[MAX_BG]; -static ANIM thisAnim[MAX_BG]; // used by BGmainProcess() -static int BGspeed = 0; -static SCNHANDLE hBackground = 0; // Current scene handle - stored in case of Save_Scene() -static bool bDoFadeIn = false; -static int bgReels; +static SCNHANDLE g_hBgPal = 0; // Background's palette +static POBJECT g_pBG[MAX_BG]; +static ANIM g_thisAnim[MAX_BG]; // used by BGmainProcess() +static int g_BGspeed = 0; +static SCNHANDLE g_hBackground = 0; // Current scene handle - stored in case of Save_Scene() +static bool g_bDoFadeIn = false; +static int g_bgReels; /** * GetBgObject */ OBJECT *GetBgObject() { - return pBG[0]; + return g_pBG[0]; } /** * BackPal */ SCNHANDLE BgPal() { - return hBgPal; + return g_hBgPal; } /** * SetDoFadeIn */ void SetDoFadeIn(bool tf) { - bDoFadeIn = tf; + g_bDoFadeIn = tf; } /** * Called before scene change. */ void DropBackground() { - pBG[0] = NULL; // No background + g_pBG[0] = NULL; // No background if (!TinselV2) - hBgPal = 0; // No background palette + g_hBgPal = 0; // No background palette } /** * Return the width of the current background. */ int BgWidth() { - assert(pBG[0]); - return MultiRightmost(pBG[0]) + 1; + assert(g_pBG[0]); + return MultiRightmost(g_pBG[0]) + 1; } /** * Return the height of the current background. */ int BgHeight() { - assert(pBG[0]); - return MultiLowest(pBG[0]) + 1; + assert(g_pBG[0]); + return MultiLowest(g_pBG[0]) + 1; } /** @@ -117,7 +117,7 @@ static void BGmainProcess(CORO_PARAM, const void *param) { const MULTI_INIT *pmi; // get the stuff copied to process when it was created - if (pBG[0] == NULL) { + if (g_pBG[0] == NULL) { /*** At start of scene ***/ if (!TinselV2) { @@ -127,40 +127,40 @@ static void BGmainProcess(CORO_PARAM, const void *param) { pmi = (const MULTI_INIT *)LockMem(FROM_LE_32(pReel->mobj)); // Initialize and insert the object, and initialize its script. - pBG[0] = MultiInitObject(pmi); - MultiInsertObject(GetPlayfieldList(FIELD_WORLD), pBG[0]); - InitStepAnimScript(&thisAnim[0], pBG[0], FROM_LE_32(pReel->script), BGspeed); - bgReels = 1; + g_pBG[0] = MultiInitObject(pmi); + MultiInsertObject(GetPlayfieldList(FIELD_WORLD), g_pBG[0]); + InitStepAnimScript(&g_thisAnim[0], g_pBG[0], FROM_LE_32(pReel->script), g_BGspeed); + g_bgReels = 1; } else { /*** At start of scene ***/ - pFilm = (const FILM *)LockMem(hBackground); - bgReels = FROM_LE_32(pFilm->numreels); + pFilm = (const FILM *)LockMem(g_hBackground); + g_bgReels = FROM_LE_32(pFilm->numreels); int i; - for (i = 0; i < bgReels; i++) { + for (i = 0; i < g_bgReels; i++) { // Get the MULTI_INIT structure pmi = (PMULTI_INIT) LockMem(FROM_LE_32(pFilm->reels[i].mobj)); // Initialize and insert the object, and initialize its script. - pBG[i] = MultiInitObject(pmi); - MultiInsertObject(GetPlayfieldList(FIELD_WORLD), pBG[i]); - MultiSetZPosition(pBG[i], 0); - InitStepAnimScript(&thisAnim[i], pBG[i], FROM_LE_32(pFilm->reels[i].script), BGspeed); + g_pBG[i] = MultiInitObject(pmi); + MultiInsertObject(GetPlayfieldList(FIELD_WORLD), g_pBG[i]); + MultiSetZPosition(g_pBG[i], 0); + InitStepAnimScript(&g_thisAnim[i], g_pBG[i], FROM_LE_32(pFilm->reels[i].script), g_BGspeed); if (i > 0) - pBG[i-1]->pSlave = pBG[i]; + g_pBG[i-1]->pSlave = g_pBG[i]; } } - if (bDoFadeIn) { + if (g_bDoFadeIn) { FadeInFast(NULL); - bDoFadeIn = false; + g_bDoFadeIn = false; } else if (TinselV2) PokeInTagColor(); for (;;) { - for (int i = 0; i < bgReels; i++) { - if (StepAnimScript(&thisAnim[i]) == ScriptFinished) + for (int i = 0; i < g_bgReels; i++) { + if (StepAnimScript(&g_thisAnim[i]) == ScriptFinished) error("Background animation has finished"); } @@ -170,16 +170,16 @@ static void BGmainProcess(CORO_PARAM, const void *param) { // New background during scene if (!TinselV2) { pReel = (const FREEL *)param; - InitStepAnimScript(&thisAnim[0], pBG[0], FROM_LE_32(pReel->script), BGspeed); - StepAnimScript(&thisAnim[0]); + InitStepAnimScript(&g_thisAnim[0], g_pBG[0], FROM_LE_32(pReel->script), g_BGspeed); + StepAnimScript(&g_thisAnim[0]); } else { - pFilm = (const FILM *)LockMem(hBackground); - assert(bgReels == (int32)FROM_LE_32(pFilm->numreels)); + pFilm = (const FILM *)LockMem(g_hBackground); + assert(g_bgReels == (int32)FROM_LE_32(pFilm->numreels)); // Just re-initialize the scripts. - for (int i = 0; i < bgReels; i++) { - InitStepAnimScript(&thisAnim[i], pBG[i], pFilm->reels[i].script, BGspeed); - StepAnimScript(&thisAnim[i]); + for (int i = 0; i < g_bgReels; i++) { + InitStepAnimScript(&g_thisAnim[i], g_pBG[i], pFilm->reels[i].script, g_BGspeed); + StepAnimScript(&g_thisAnim[i]); } } } @@ -206,7 +206,7 @@ static void BGotherProcess(CORO_PARAM, const void *param) { _ctx->pObj = MultiInitObject(pmi); MultiInsertObject(GetPlayfieldList(FIELD_WORLD), _ctx->pObj); - InitStepAnimScript(&_ctx->anim, pBG[0], FROM_LE_32(pReel->script), BGspeed); + InitStepAnimScript(&_ctx->anim, g_pBG[0], FROM_LE_32(pReel->script), g_BGspeed); while (StepAnimScript(&_ctx->anim) != ScriptFinished) CORO_SLEEP(1); @@ -218,14 +218,14 @@ static void BGotherProcess(CORO_PARAM, const void *param) { * AetBgPal() */ void SetBackPal(SCNHANDLE hPal) { - hBgPal = hPal; + g_hBgPal = hPal; - FettleFontPal(hBgPal); - CreateTranslucentPalette(hBgPal); + FettleFontPal(g_hBgPal); + CreateTranslucentPalette(g_hBgPal); } void ChangePalette(SCNHANDLE hPal) { - SwapPalette(FindPalette(hBgPal), hPal); + SwapPalette(FindPalette(g_hBgPal), hPal); SetBackPal(hPal); } @@ -245,14 +245,14 @@ void StartupBackground(CORO_PARAM, SCNHANDLE hFilm) { const FILM *pfilm; IMAGE *pim; - hBackground = hFilm; // Save handle in case of Save_Scene() + g_hBackground = hFilm; // Save handle in case of Save_Scene() pim = GetImageFromFilm(hFilm, 0, NULL, NULL, &pfilm); SetBackPal(FROM_LE_32(pim->hImgPal)); // Extract the film speed - BGspeed = ONE_SECOND / FROM_LE_32(pfilm->frate); + g_BGspeed = ONE_SECOND / FROM_LE_32(pfilm->frate); // Start display process for each reel in the film g_scheduler->createProcess(PID_REEL, BGmainProcess, &pfilm->reels[0], sizeof(FREEL)); @@ -262,7 +262,7 @@ void StartupBackground(CORO_PARAM, SCNHANDLE hFilm) { g_scheduler->createProcess(PID_REEL, BGotherProcess, &pfilm->reels[i], sizeof(FREEL)); } - if (pBG[0] == NULL) + if (g_pBG[0] == NULL) ControlStartOff(); if (TinselV2 && (coroParam != nullContext)) @@ -275,7 +275,7 @@ void StartupBackground(CORO_PARAM, SCNHANDLE hFilm) { * Return the current scene handle. */ SCNHANDLE GetBgroundHandle() { - return hBackground; + return g_hBackground; } } // End of namespace Tinsel diff --git a/engines/tinsel/cursor.cpp b/engines/tinsel/cursor.cpp index 8248609a81..bf901c03b6 100644 --- a/engines/tinsel/cursor.cpp +++ b/engines/tinsel/cursor.cpp @@ -56,36 +56,36 @@ namespace Tinsel { // FIXME: Avoid non-const global vars -static OBJECT *McurObj = NULL; // Main cursor object -static OBJECT *AcurObj = NULL; // Auxiliary cursor object +static OBJECT *g_McurObj = NULL; // Main cursor object +static OBJECT *g_AcurObj = NULL; // Auxiliary cursor object -static ANIM McurAnim = {0,0,0,0,0}; // Main cursor animation structure -static ANIM AcurAnim = {0,0,0,0,0}; // Auxiliary cursor animation structure +static ANIM g_McurAnim = {0,0,0,0,0}; // Main cursor animation structure +static ANIM g_AcurAnim = {0,0,0,0,0}; // Auxiliary cursor animation structure -static bool bHiddenCursor = false; // Set when cursor is hidden -static bool bTempNoTrailers = false; // Set when cursor trails are hidden -static bool bTempHide = false; // Set when cursor is hidden +static bool g_bHiddenCursor = false; // Set when cursor is hidden +static bool g_bTempNoTrailers = false; // Set when cursor trails are hidden +static bool g_bTempHide = false; // Set when cursor is hidden -static bool bFrozenCursor = false; // Set when cursor position is frozen +static bool g_bFrozenCursor = false; // Set when cursor position is frozen -static frac_t IterationSize = 0; +static frac_t g_IterationSize = 0; -static SCNHANDLE hCursorFilm = 0; // Handle to cursor reel data +static SCNHANDLE g_hCursorFilm = 0; // Handle to cursor reel data -static int numTrails = 0; -static int nextTrail = 0; +static int g_numTrails = 0; +static int g_nextTrail = 0; -static bool bWhoa = false; // Set by DropCursor() at the end of a scene +static bool g_bWhoa = false; // Set by DropCursor() at the end of a scene // - causes cursor processes to do nothing // Reset when main cursor has re-initialized -static uint16 restart = 0; // When main cursor has been bWhoa-ed, it waits +static uint16 g_restart = 0; // When main cursor has been bWhoa-ed, it waits // for this to be set to 0x8000. // Main cursor sets all the bits after a re-start // - each cursor trail examines it's own bit // to trigger a trail restart. -static short ACoX = 0, ACoY = 0; // Auxillary cursor image's animation offsets +static short g_ACoX = 0, g_ACoY = 0; // Auxillary cursor image's animation offsets @@ -96,9 +96,9 @@ static struct { ANIM trailAnim; // Animation structure OBJECT *trailObj; // This trailer's object -} ntrailData [MAX_TRAILERS]; +} g_ntrailData [MAX_TRAILERS]; -static int lastCursorX = 0, lastCursorY = 0; +static int g_lastCursorX = 0, g_lastCursorY = 0; //----------------- FORWARD REFERENCES -------------------- @@ -116,26 +116,26 @@ static void InitCurTrailObj(int i, int x, int y) { const FILM *pfilm; - if (!numTrails) + if (!g_numTrails) return; // Get rid of old object - if (ntrailData[i].trailObj != NULL) - MultiDeleteObject(GetPlayfieldList(FIELD_STATUS), ntrailData[i].trailObj); + if (g_ntrailData[i].trailObj != NULL) + MultiDeleteObject(GetPlayfieldList(FIELD_STATUS), g_ntrailData[i].trailObj); - pim = GetImageFromFilm(hCursorFilm, i+1, &pfr, &pmi, &pfilm);// Get pointer to image + pim = GetImageFromFilm(g_hCursorFilm, i+1, &pfr, &pmi, &pfilm);// Get pointer to image assert(BgPal()); // No background palette pim->hImgPal = TO_LE_32(BgPal()); // Initialize and insert the object, set its Z-pos, and hide it - ntrailData[i].trailObj = MultiInitObject(pmi); - MultiInsertObject(GetPlayfieldList(FIELD_STATUS), ntrailData[i].trailObj); - MultiSetZPosition(ntrailData[i].trailObj, Z_CURSORTRAIL); - MultiSetAniXY(ntrailData[i].trailObj, x, y); + g_ntrailData[i].trailObj = MultiInitObject(pmi); + MultiInsertObject(GetPlayfieldList(FIELD_STATUS), g_ntrailData[i].trailObj); + MultiSetZPosition(g_ntrailData[i].trailObj, Z_CURSORTRAIL); + MultiSetAniXY(g_ntrailData[i].trailObj, x, y); // Initialize the animation script - InitStepAnimScript(&ntrailData[i].trailAnim, ntrailData[i].trailObj, FROM_LE_32(pfr->script), ONE_SECOND / FROM_LE_32(pfilm->frate)); - StepAnimScript(&ntrailData[i].trailAnim); + InitStepAnimScript(&g_ntrailData[i].trailAnim, g_ntrailData[i].trailObj, FROM_LE_32(pfr->script), ONE_SECOND / FROM_LE_32(pfilm->frate)); + StepAnimScript(&g_ntrailData[i].trailAnim); } /** @@ -196,12 +196,12 @@ void SetCursorScreenXY(int newx, int newy) { * Returns false if there is no cursor object. */ bool GetCursorXYNoWait(int *x, int *y, bool absolute) { - if (McurObj == NULL) { + if (g_McurObj == NULL) { *x = *y = 0; return false; } - GetAniPosition(McurObj, x, y); + GetAniPosition(g_McurObj, x, y); if (absolute) { int Loffset, Toffset; // Screen offset @@ -222,7 +222,7 @@ bool GetCursorXYNoWait(int *x, int *y, bool absolute) { void GetCursorXY(int *x, int *y, bool absolute) { //while (McurObj == NULL) // ProcessSleepSelf(); - assert(McurObj); + assert(g_McurObj); GetCursorXYNoWait(x, y, absolute); } @@ -234,22 +234,22 @@ void GetCursorXY(int *x, int *y, bool absolute) { void RestoreMainCursor() { const FILM *pfilm; - if (McurObj != NULL) { - pfilm = (const FILM *)LockMem(hCursorFilm); + if (g_McurObj != NULL) { + pfilm = (const FILM *)LockMem(g_hCursorFilm); - InitStepAnimScript(&McurAnim, McurObj, FROM_LE_32(pfilm->reels->script), ONE_SECOND / FROM_LE_32(pfilm->frate)); - StepAnimScript(&McurAnim); + InitStepAnimScript(&g_McurAnim, g_McurObj, FROM_LE_32(pfilm->reels->script), ONE_SECOND / FROM_LE_32(pfilm->frate)); + StepAnimScript(&g_McurAnim); } - bHiddenCursor = false; - bFrozenCursor = false; + g_bHiddenCursor = false; + g_bFrozenCursor = false; } /** * Called from INVENTRY.C to customise the main cursor. */ void SetTempCursor(SCNHANDLE pScript) { - if (McurObj != NULL) - InitStepAnimScript(&McurAnim, McurObj, pScript, 2); + if (g_McurObj != NULL) + InitStepAnimScript(&g_McurAnim, g_McurObj, pScript, 2); } /** @@ -258,17 +258,17 @@ void SetTempCursor(SCNHANDLE pScript) { void DwHideCursor() { int i; - bHiddenCursor = true; + g_bHiddenCursor = true; - if (McurObj) - MultiHideObject(McurObj); - if (AcurObj) - MultiHideObject(AcurObj); + if (g_McurObj) + MultiHideObject(g_McurObj); + if (g_AcurObj) + MultiHideObject(g_AcurObj); - for (i = 0; i < numTrails; i++) { - if (ntrailData[i].trailObj != NULL) { - MultiDeleteObject(GetPlayfieldList(FIELD_STATUS), ntrailData[i].trailObj); - ntrailData[i].trailObj = NULL; + for (i = 0; i < g_numTrails; i++) { + if (g_ntrailData[i].trailObj != NULL) { + MultiDeleteObject(GetPlayfieldList(FIELD_STATUS), g_ntrailData[i].trailObj); + g_ntrailData[i].trailObj = NULL; } } } @@ -277,21 +277,21 @@ void DwHideCursor() { * Unhide the cursor. */ void UnHideCursor() { - bHiddenCursor = false; + g_bHiddenCursor = false; } /** * Freeze the cursor. */ void FreezeCursor() { - bFrozenCursor = true; + g_bFrozenCursor = true; } /** * Freeze the cursor, or not. */ void DoFreezeCursor(bool bFreeze) { - bFrozenCursor = bFreeze; + g_bFrozenCursor = bFreeze; } /** @@ -300,12 +300,12 @@ void DoFreezeCursor(bool bFreeze) { void HideCursorTrails() { int i; - bTempNoTrailers = true; + g_bTempNoTrailers = true; - for (i = 0; i < numTrails; i++) { - if (ntrailData[i].trailObj != NULL) { - MultiDeleteObject(GetPlayfieldList(FIELD_STATUS), ntrailData[i].trailObj); - ntrailData[i].trailObj = NULL; + for (i = 0; i < g_numTrails; i++) { + if (g_ntrailData[i].trailObj != NULL) { + MultiDeleteObject(GetPlayfieldList(FIELD_STATUS), g_ntrailData[i].trailObj); + g_ntrailData[i].trailObj = NULL; } } } @@ -314,7 +314,7 @@ void HideCursorTrails() { * UnHideCursorTrails */ void UnHideCursorTrails() { - bTempNoTrailers = false; + g_bTempNoTrailers = false; } /** @@ -356,9 +356,9 @@ IMAGE *GetImageFromFilm(SCNHANDLE hFilm, int reel, const FREEL **ppfr, const MUL * Delete auxillary cursor. Restore animation offsets in the image. */ void DelAuxCursor() { - if (AcurObj != NULL) { - MultiDeleteObject(GetPlayfieldList(FIELD_STATUS), AcurObj); - AcurObj = NULL; + if (g_AcurObj != NULL) { + MultiDeleteObject(GetPlayfieldList(FIELD_STATUS), g_AcurObj); + g_AcurObj = NULL; } } @@ -381,21 +381,21 @@ void SetAuxCursor(SCNHANDLE hFilm) { assert(BgPal()); // no background palette pim->hImgPal = TO_LE_32(BgPal()); // Poke in the background palette - ACoX = (short)(FROM_LE_16(pim->imgWidth)/2 - ((int16) FROM_LE_16(pim->anioffX))); - ACoY = (short)((FROM_LE_16(pim->imgHeight) & ~C16_FLAG_MASK)/2 - + g_ACoX = (short)(FROM_LE_16(pim->imgWidth)/2 - ((int16) FROM_LE_16(pim->anioffX))); + g_ACoY = (short)((FROM_LE_16(pim->imgHeight) & ~C16_FLAG_MASK)/2 - ((int16) FROM_LE_16(pim->anioffY))); // Initialize and insert the auxillary cursor object - AcurObj = MultiInitObject(pmi); - MultiInsertObject(GetPlayfieldList(FIELD_STATUS), AcurObj); + g_AcurObj = MultiInitObject(pmi); + MultiInsertObject(GetPlayfieldList(FIELD_STATUS), g_AcurObj); // Initialize the animation and set its position - InitStepAnimScript(&AcurAnim, AcurObj, FROM_LE_32(pfr->script), ONE_SECOND / FROM_LE_32(pfilm->frate)); - MultiSetAniXY(AcurObj, x - ACoX, y - ACoY); - MultiSetZPosition(AcurObj, Z_ACURSOR); + InitStepAnimScript(&g_AcurAnim, g_AcurObj, FROM_LE_32(pfr->script), ONE_SECOND / FROM_LE_32(pfilm->frate)); + MultiSetAniXY(g_AcurObj, x - g_ACoX, y - g_ACoY); + MultiSetZPosition(g_AcurObj, Z_ACURSOR); - if (bHiddenCursor) - MultiHideObject(AcurObj); + if (g_bHiddenCursor) + MultiHideObject(g_AcurObj); } /** @@ -421,52 +421,52 @@ static void DoCursorMove() { dir = _vm->getKeyDirection(); if (dir != 0) { if (dir & MSK_LEFT) - newX -= IterationSize; + newX -= g_IterationSize; if (dir & MSK_RIGHT) - newX += IterationSize; + newX += g_IterationSize; if (dir & MSK_UP) - newY -= IterationSize; + newY -= g_IterationSize; if (dir & MSK_DOWN) - newY += IterationSize; + newY += g_IterationSize; - IterationSize += ITER_ACCELERATION; + g_IterationSize += ITER_ACCELERATION; // set new mouse driver position _vm->setMousePosition(Common::Point(fracToInt(newX), fracToInt(newY))); } else - IterationSize = ITERATION_BASE; + g_IterationSize = ITERATION_BASE; // get new mouse driver position - could have been modified ptMouse = _vm->getMousePosition(); - if (lastCursorX != ptMouse.x || lastCursorY != ptMouse.y) { + if (g_lastCursorX != ptMouse.x || g_lastCursorY != ptMouse.y) { resetUserEventTime(); - if (!bTempNoTrailers && !bHiddenCursor) { - InitCurTrailObj(nextTrail++, lastCursorX, lastCursorY); - if (nextTrail == numTrails) - nextTrail = 0; + if (!g_bTempNoTrailers && !g_bHiddenCursor) { + InitCurTrailObj(g_nextTrail++, g_lastCursorX, g_lastCursorY); + if (g_nextTrail == g_numTrails) + g_nextTrail = 0; } } // adjust cursor to new mouse position - if (McurObj) - MultiSetAniXY(McurObj, ptMouse.x, ptMouse.y); - if (AcurObj != NULL) - MultiSetAniXY(AcurObj, ptMouse.x - ACoX, ptMouse.y - ACoY); + if (g_McurObj) + MultiSetAniXY(g_McurObj, ptMouse.x, ptMouse.y); + if (g_AcurObj != NULL) + MultiSetAniXY(g_AcurObj, ptMouse.x - g_ACoX, ptMouse.y - g_ACoY); - if (InventoryActive() && McurObj) { + if (InventoryActive() && g_McurObj) { // Notify the inventory Xmovement(ptMouse.x - startX); Ymovement(ptMouse.y - startY); } - lastCursorX = ptMouse.x; - lastCursorY = ptMouse.y; + g_lastCursorX = ptMouse.x; + g_lastCursorY = ptMouse.y; } /** @@ -479,7 +479,7 @@ static void InitCurObj() { IMAGE *pim; if (TinselV2) { - pFilm = (const FILM *)LockMem(hCursorFilm); + pFilm = (const FILM *)LockMem(g_hCursorFilm); pfr = (const FREEL *)&pFilm->reels[0]; pmi = (MULTI_INIT *)LockMem(FROM_LE_32(pfr->mobj)); @@ -487,16 +487,16 @@ static void InitCurObj() { } else { assert(BgPal()); // no background palette - pim = GetImageFromFilm(hCursorFilm, 0, &pfr, &pmi, &pFilm);// Get pointer to image + pim = GetImageFromFilm(g_hCursorFilm, 0, &pfr, &pmi, &pFilm);// Get pointer to image pim->hImgPal = TO_LE_32(BgPal()); - AcurObj = NULL; // No auxillary cursor + g_AcurObj = NULL; // No auxillary cursor } - McurObj = MultiInitObject(pmi); - MultiInsertObject(GetPlayfieldList(FIELD_STATUS), McurObj); + g_McurObj = MultiInitObject(pmi); + MultiInsertObject(GetPlayfieldList(FIELD_STATUS), g_McurObj); - InitStepAnimScript(&McurAnim, McurObj, FROM_LE_32(pfr->script), ONE_SECOND / FROM_LE_32(pFilm->frate)); + InitStepAnimScript(&g_McurAnim, g_McurObj, FROM_LE_32(pfr->script), ONE_SECOND / FROM_LE_32(pFilm->frate)); } /** @@ -504,14 +504,14 @@ static void InitCurObj() { */ static void InitCurPos() { Common::Point ptMouse = _vm->getMousePosition(); - lastCursorX = ptMouse.x; - lastCursorY = ptMouse.y; + g_lastCursorX = ptMouse.x; + g_lastCursorY = ptMouse.y; - MultiSetZPosition(McurObj, Z_CURSOR); + MultiSetZPosition(g_McurObj, Z_CURSOR); DoCursorMove(); - MultiHideObject(McurObj); + MultiHideObject(g_McurObj); - IterationSize = ITERATION_BASE; + g_IterationSize = ITERATION_BASE; } /** @@ -525,9 +525,9 @@ static void CursorStoppedCheck(CORO_PARAM) { CORO_BEGIN_CODE(_ctx); // If scene is closing down - if (bWhoa) { + if (g_bWhoa) { // ...wait for next scene start-up - while (restart != 0x8000) + while (g_restart != 0x8000) CORO_SLEEP(1); // Re-initialize @@ -536,8 +536,8 @@ static void CursorStoppedCheck(CORO_PARAM) { InventoryIconCursor(false); // May be holding something // Re-start the cursor trails - restart = (uint16)-1; // set all bits - bWhoa = false; + g_restart = (uint16)-1; // set all bits + g_bWhoa = false; } CORO_END_CODE; } @@ -552,15 +552,15 @@ void CursorProcess(CORO_PARAM, const void *) { CORO_BEGIN_CODE(_ctx); - while (!hCursorFilm || !BgPal()) + while (!g_hCursorFilm || !BgPal()) CORO_SLEEP(1); InitCurObj(); InitCurPos(); InventoryIconCursor(false); // May be holding something - bWhoa = false; - restart = 0; + g_bWhoa = false; + g_restart = 0; while (1) { // allow rescheduling @@ -570,36 +570,36 @@ void CursorProcess(CORO_PARAM, const void *) { CORO_INVOKE_0(CursorStoppedCheck); // Step the animation script(s) - StepAnimScript(&McurAnim); - if (AcurObj != NULL) - StepAnimScript(&AcurAnim); - for (int i = 0; i < numTrails; i++) { - if (ntrailData[i].trailObj != NULL) { - if (StepAnimScript(&ntrailData[i].trailAnim) == ScriptFinished) { - MultiDeleteObject(GetPlayfieldList(FIELD_STATUS), ntrailData[i].trailObj); - ntrailData[i].trailObj = NULL; + StepAnimScript(&g_McurAnim); + if (g_AcurObj != NULL) + StepAnimScript(&g_AcurAnim); + for (int i = 0; i < g_numTrails; i++) { + if (g_ntrailData[i].trailObj != NULL) { + if (StepAnimScript(&g_ntrailData[i].trailAnim) == ScriptFinished) { + MultiDeleteObject(GetPlayfieldList(FIELD_STATUS), g_ntrailData[i].trailObj); + g_ntrailData[i].trailObj = NULL; } } } // Move the cursor as appropriate - if (!bFrozenCursor) + if (!g_bFrozenCursor) DoCursorMove(); // If the cursor should be hidden... - if (bHiddenCursor || bTempHide) { + if (g_bHiddenCursor || g_bTempHide) { // ...hide the cursor object(s) - MultiHideObject(McurObj); - if (AcurObj) - MultiHideObject(AcurObj); + MultiHideObject(g_McurObj); + if (g_AcurObj) + MultiHideObject(g_AcurObj); - for (int i = 0; i < numTrails; i++) { - if (ntrailData[i].trailObj != NULL) - MultiHideObject(ntrailData[i].trailObj); + for (int i = 0; i < g_numTrails; i++) { + if (g_ntrailData[i].trailObj != NULL) + MultiHideObject(g_ntrailData[i].trailObj); } // Wait 'til cursor is again required. - while (bHiddenCursor) { + while (g_bHiddenCursor) { CORO_SLEEP(1); // Stop/start between scenes @@ -617,12 +617,12 @@ void CursorProcess(CORO_PARAM, const void *) { void DwInitCursor(SCNHANDLE bfilm) { const FILM *pfilm; - hCursorFilm = bfilm; + g_hCursorFilm = bfilm; - pfilm = (const FILM *)LockMem(hCursorFilm); - numTrails = FROM_LE_32(pfilm->numreels) - 1; + pfilm = (const FILM *)LockMem(g_hCursorFilm); + g_numTrails = FROM_LE_32(pfilm->numreels) - 1; - assert(numTrails <= MAX_TRAILERS); + assert(g_numTrails <= MAX_TRAILERS); } /** @@ -630,24 +630,24 @@ void DwInitCursor(SCNHANDLE bfilm) { */ void DropCursor() { if (TinselV2) { - if (AcurObj) - MultiDeleteObject(GetPlayfieldList(FIELD_STATUS), AcurObj); - if (McurObj) - MultiDeleteObject(GetPlayfieldList(FIELD_STATUS), McurObj); + if (g_AcurObj) + MultiDeleteObject(GetPlayfieldList(FIELD_STATUS), g_AcurObj); + if (g_McurObj) + MultiDeleteObject(GetPlayfieldList(FIELD_STATUS), g_McurObj); - restart = 0; + g_restart = 0; } - AcurObj = NULL; // No auxillary cursor - McurObj = NULL; // No cursor object (imminently deleted elsewhere) - bHiddenCursor = false; // Not hidden in next scene - bTempNoTrailers = false; // Trailers not hidden in next scene - bWhoa = true; // Suspend cursor processes + g_AcurObj = NULL; // No auxillary cursor + g_McurObj = NULL; // No cursor object (imminently deleted elsewhere) + g_bHiddenCursor = false; // Not hidden in next scene + g_bTempNoTrailers = false; // Trailers not hidden in next scene + g_bWhoa = true; // Suspend cursor processes - for (int i = 0; i < numTrails; i++) { - if (ntrailData[i].trailObj != NULL) { - MultiDeleteObject(GetPlayfieldList(FIELD_STATUS), ntrailData[i].trailObj); - ntrailData[i].trailObj = NULL; + for (int i = 0; i < g_numTrails; i++) { + if (g_ntrailData[i].trailObj != NULL) { + MultiDeleteObject(GetPlayfieldList(FIELD_STATUS), g_ntrailData[i].trailObj); + g_ntrailData[i].trailObj = NULL; } } } @@ -656,7 +656,7 @@ void DropCursor() { * RestartCursor is called when a new scene is starting up. */ void RestartCursor() { - restart = 0x8000; // Get the main cursor to re-initialize + g_restart = 0x8000; // Get the main cursor to re-initialize } /** @@ -664,32 +664,32 @@ void RestartCursor() { * pointers etc. */ void RebootCursor() { - McurObj = AcurObj = NULL; + g_McurObj = g_AcurObj = NULL; for (int i = 0; i < MAX_TRAILERS; i++) - ntrailData[i].trailObj = NULL; + g_ntrailData[i].trailObj = NULL; - bHiddenCursor = bTempNoTrailers = bFrozenCursor = false; + g_bHiddenCursor = g_bTempNoTrailers = g_bFrozenCursor = false; - hCursorFilm = 0; + g_hCursorFilm = 0; - bWhoa = false; - restart = 0; + g_bWhoa = false; + g_restart = 0; } void StartCursorFollowed() { DelAuxCursor(); if (!SysVar(SV_ENABLEPRINTCURSOR)) - bTempHide = true; + g_bTempHide = true; } void EndCursorFollowed() { InventoryIconCursor(false); // May be holding something - bTempHide = false; + g_bTempHide = false; } bool isCursorShown() { - return !(bTempHide || bHiddenCursor); + return !(g_bTempHide || g_bHiddenCursor); } } // End of namespace Tinsel diff --git a/engines/tinsel/dialogs.cpp b/engines/tinsel/dialogs.cpp index 6ca070b67a..5396e47566 100644 --- a/engines/tinsel/dialogs.cpp +++ b/engines/tinsel/dialogs.cpp @@ -63,17 +63,6 @@ namespace Tinsel { -//----------------- EXTERNAL GLOBAL DATA -------------------- - -// In DOS_DW.C -extern bool bRestart; // restart flag - set to restart the game - -#ifdef MAC_OPTIONS -// In MAC_SOUND.C -extern int volMaster; -#endif - - //----------------- LOCAL DEFINES -------------------- #define HOPPER_FILENAME "hopper" @@ -312,23 +301,23 @@ static const int vFillers[MAXVICONS] = { //----- Permanent data (set once) ----- -static SCNHANDLE hWinParts = 0; // Window members and cursors' graphic data -static SCNHANDLE flagFilm = 0; // Window members and cursors' graphic data -static SCNHANDLE configStrings[20]; +static SCNHANDLE g_hWinParts = 0; // Window members and cursors' graphic data +static SCNHANDLE g_flagFilm = 0; // Window members and cursors' graphic data +static SCNHANDLE g_configStrings[20]; -static INV_OBJECT *invObjects = NULL; // Inventory objects' data -static int numObjects = 0; // Number of inventory objects -static SCNHANDLE *invFilms = NULL; -static bool bNoLanguage = false; -static DIRECTION initialDirection; +static INV_OBJECT *g_invObjects = NULL; // Inventory objects' data +static int g_numObjects = 0; // Number of inventory objects +static SCNHANDLE *g_invFilms = NULL; +static bool g_bNoLanguage = false; +static DIRECTION g_initialDirection; //----- Permanent data (updated, valid while inventory closed) ----- -static enum {NO_INV, IDLE_INV, ACTIVE_INV, BOGUS_INV} InventoryState; +static enum {NO_INV, IDLE_INV, ACTIVE_INV, BOGUS_INV} g_InventoryState; -static int HeldItem = INV_NOICON; // Current held item +static int g_heldItem = INV_NOICON; // Current held item -static SCNHANDLE heldFilm; +static SCNHANDLE g_heldFilm; struct INV_DEF { @@ -364,60 +353,60 @@ struct INV_DEF { }; -static INV_DEF InvD[NUM_INV]; // Conversation + 2 inventories + ... +static INV_DEF g_InvD[NUM_INV]; // Conversation + 2 inventories + ... // Permanent contents of conversation inventory -static int permIcons[MAX_PERMICONS]; // Basic items i.e. permanent contents -static int numPermIcons = 0; // - copy to conv. inventory at pop-up time -static int numEndIcons = 0; +static int g_permIcons[MAX_PERMICONS]; // Basic items i.e. permanent contents +static int g_numPermIcons = 0; // - copy to conv. inventory at pop-up time +static int g_numEndIcons = 0; //----- Data pertinant to current active inventory ----- -static int ino = 0; // Which inventory is currently active +static int g_ino = 0; // Which inventory is currently active -static bool InventoryHidden = false; -static bool InventoryMaximised = false; +static bool g_InventoryHidden = false; +static bool g_InventoryMaximised = false; static enum { ID_NONE, ID_MOVE, ID_SLIDE, ID_BOTTOM, ID_TOP, ID_LEFT, ID_RIGHT, ID_TLEFT, ID_TRIGHT, ID_BLEFT, ID_BRIGHT, - ID_CSLIDE, ID_MDCONT } InvDragging; + ID_CSLIDE, ID_MDCONT } g_InvDragging; -static int SuppH = 0; // 'Linear' element of -static int SuppV = 0; // dimensions during re-sizing +static int g_SuppH = 0; // 'Linear' element of +static int g_SuppV = 0; // dimensions during re-sizing -static int Ychange = 0; // -static int Ycompensate = 0; // All to do with re-sizing. -static int Xchange = 0; // -static int Xcompensate = 0; // +static int g_Ychange = 0; // +static int g_Ycompensate = 0; // All to do with re-sizing. +static int g_Xchange = 0; // +static int g_Xcompensate = 0; // -static bool ItemsChanged = 0; // When set, causes items to be re-drawn +static bool g_ItemsChanged = 0; // When set, causes items to be re-drawn -static bool bReOpenMenu = 0; +static bool g_bReOpenMenu = 0; -static int TL = 0, TR = 0, BL = 0, BR = 0; // Used during window construction -static int TLwidth = 0, TLheight = 0; // -static int TRwidth = 0; // -static int BLheight = 0; // +static int g_TL = 0, g_TR = 0, g_BL = 0, g_BR = 0; // Used during window construction +static int g_TLwidth = 0, g_TLheight = 0; // +static int g_TRwidth = 0; // +static int g_BLheight = 0; // -static LANGUAGE displayedLanguage; +static LANGUAGE g_displayedLanguage; -static OBJECT *objArray[MAX_WCOMP]; // Current display objects (window) -static OBJECT *iconArray[MAX_ICONS]; // Current display objects (icons) -static ANIM iconAnims[MAX_ICONS]; -static OBJECT *DobjArray[MAX_WCOMP]; // Current display objects (re-sizing window) +static OBJECT *g_objArray[MAX_WCOMP]; // Current display objects (window) +static OBJECT *g_iconArray[MAX_ICONS]; // Current display objects (icons) +static ANIM g_iconAnims[MAX_ICONS]; +static OBJECT *g_DobjArray[MAX_WCOMP]; // Current display objects (re-sizing window) -static OBJECT *RectObject = 0, *SlideObject = 0; // Current display objects, for reference +static OBJECT *g_RectObject = 0, *g_SlideObject = 0; // Current display objects, for reference // objects are in objArray. -static int sliderYpos = 0; // For positioning the slider -static int sliderYmax = 0, sliderYmin = 0; // +static int g_sliderYpos = 0; // For positioning the slider +static int g_sliderYmax = 0, g_sliderYmin = 0; // -#define sliderRange (sliderYmax - sliderYmin) +#define sliderRange (g_sliderYmax - g_sliderYmin) // Also to do with the slider -static struct { int n; int y; } slideStuff[MAX_ININV_TOT+1]; +static struct { int n; int y; } g_slideStuff[MAX_ININV_TOT+1]; #define MAXSLIDES 4 struct MDSLIDES { @@ -425,25 +414,25 @@ struct MDSLIDES { OBJECT *obj; int min, max; }; -static MDSLIDES mdSlides[MAXSLIDES]; -static int numMdSlides = 0; +static MDSLIDES g_mdSlides[MAXSLIDES]; +static int g_numMdSlides = 0; -static int GlitterIndex = 0; +static int g_GlitterIndex = 0; // Icon clicked on to cause an event // - Passed to conversation polygon or actor code via Topic() // - (sometimes) Passed to inventory icon code via OtherObject() -static int thisIcon = 0; +static int g_thisIcon = 0; -static CONV_PARAM thisConvFn; // Top, 'Middle' or Bottom -static HPOLYGON thisConvPoly = 0; // Conversation code is in a polygon code block -static int thisConvActor; // ...or an actor's code block. -static int pointedIcon = INV_NOICON; // used by InvLabels - icon pointed to on last call -static volatile int PointedWaitCount = 0; // used by ObjectProcess - fix the 'repeated pressing bug' -static int sX = 0; // used by SlideMSlider() - current x-coordinate -static int lX = 0; // used by SlideMSlider() - last x-coordinate +static CONV_PARAM g_thisConvFn; // Top, 'Middle' or Bottom +static HPOLYGON g_thisConvPoly = 0; // Conversation code is in a polygon code block +static int g_thisConvActor; // ...or an actor's code block. +static int g_pointedIcon = INV_NOICON; // used by InvLabels - icon pointed to on last call +static volatile int g_PointedWaitCount = 0; // used by ObjectProcess - fix the 'repeated pressing bug' +static int g_sX = 0; // used by SlideMSlider() - current x-coordinate +static int g_lX = 0; // used by SlideMSlider() - last x-coordinate -static bool bMoveOnUnHide; // Set before start of conversation +static bool g_bMoveOnUnHide; // Set before start of conversation // - causes conversation to be started in a sensible place //----- Data pertinant to configure (incl. load/save game) ----- @@ -486,16 +475,16 @@ typedef HOPENTRY *PHOPENTRY; #include "common/pack-end.h" // END STRUCT PACKING -static PHOPPER pHopper; -static PHOPENTRY pEntries; -static int numScenes; +static PHOPPER g_pHopper; +static PHOPENTRY g_pEntries; +static int g_numScenes; -static int numEntries; +static int g_numEntries; -static PHOPPER pChosenScene = NULL; +static PHOPPER g_pChosenScene = NULL; -static int lastChosenScene; -static bool bRemember; +static int g_lastChosenScene; +static bool g_bRemember; //-------------------------------------------------------------- @@ -970,7 +959,7 @@ static struct { }; // For editing save game names -static char sedit[SG_DESC_LEN+2]; +static char g_sedit[SG_DESC_LEN+2]; #define HL1 0 // Hilight that moves with the cursor #define HL2 1 // Hilight on selected RGROUP box @@ -1096,7 +1085,7 @@ static void PrimeSceneHopper() { vSize = f.readUint32LE(); // allocate a buffer for it all - assert(pHopper == NULL); + assert(g_pHopper == NULL); uint32 size = f.size() - 8; // make sure memory allocated @@ -1111,9 +1100,9 @@ static void PrimeSceneHopper() { error(FILE_IS_CORRUPT, HOPPER_FILENAME); // Set data pointers - pHopper = (PHOPPER)pBuffer; - pEntries = (PHOPENTRY)(pBuffer + vSize); - numScenes = vSize / sizeof(HOPPER); + g_pHopper = (PHOPPER)pBuffer; + g_pEntries = (PHOPENTRY)(pBuffer + vSize); + g_numScenes = vSize / sizeof(HOPPER); // close the file f.close(); @@ -1123,31 +1112,31 @@ static void PrimeSceneHopper() { * Free the scene hopper data file */ static void FreeSceneHopper() { - free(pHopper); - pHopper = NULL; + free(g_pHopper); + g_pHopper = NULL; } static void FirstScene(int first) { int i; - assert(numScenes && pHopper); + assert(g_numScenes && g_pHopper); - if (bRemember) { + if (g_bRemember) { assert(first == 0); - first = lastChosenScene; - bRemember = false; + first = g_lastChosenScene; + g_bRemember = false; } // Force it to a sensible value - if (first > numScenes - NUM_RGROUP_BOXES) - first = numScenes - NUM_RGROUP_BOXES; + if (first > g_numScenes - NUM_RGROUP_BOXES) + first = g_numScenes - NUM_RGROUP_BOXES; if (first < 0) first = 0; // Fill in the rest - for (i = 0; i < NUM_RGROUP_BOXES && i + first < numScenes; i++) { + for (i = 0; i < NUM_RGROUP_BOXES && i + first < g_numScenes; i++) { cd.box[i].textMethod = TM_STRINGNUM; - cd.box[i].ixText = FROM_LE_32(pHopper[i + first].hSceneDesc); + cd.box[i].ixText = FROM_LE_32(g_pHopper[i + first].hSceneDesc); } // Blank out the spare ones (if any) while (i < NUM_RGROUP_BOXES) { @@ -1159,31 +1148,31 @@ static void FirstScene(int first) { } static void RememberChosenScene() { - bRemember = true; + g_bRemember = true; } static void SetChosenScene() { - lastChosenScene = cd.selBox + cd.extraBase; - pChosenScene = &pHopper[cd.selBox + cd.extraBase]; + g_lastChosenScene = cd.selBox + cd.extraBase; + g_pChosenScene = &g_pHopper[cd.selBox + cd.extraBase]; } static void FirstEntry(int first) { int i; - InvD[INV_MENU].hInvTitle = FROM_LE_32(pChosenScene->hSceneDesc); + g_InvD[INV_MENU].hInvTitle = FROM_LE_32(g_pChosenScene->hSceneDesc); // get number of entrances - numEntries = FROM_LE_32(pChosenScene->numEntries); + g_numEntries = FROM_LE_32(g_pChosenScene->numEntries); // Force first to a sensible value - if (first > numEntries-NUM_RGROUP_BOXES) - first = numEntries-NUM_RGROUP_BOXES; + if (first > g_numEntries-NUM_RGROUP_BOXES) + first = g_numEntries-NUM_RGROUP_BOXES; if (first < 0) first = 0; - for (i = 0; i < NUM_RGROUP_BOXES && i < numEntries; i++) { + for (i = 0; i < NUM_RGROUP_BOXES && i < g_numEntries; i++) { cd.box[i].textMethod = TM_STRINGNUM; - cd.box[i].ixText = FROM_LE_32(pEntries[FROM_LE_32(pChosenScene->entryIndex) + i + first].hDesc); + cd.box[i].ixText = FROM_LE_32(g_pEntries[FROM_LE_32(g_pChosenScene->entryIndex) + i + first].hDesc); } // Blank out the spare ones (if any) while (i < NUM_RGROUP_BOXES) { @@ -1195,15 +1184,15 @@ static void FirstEntry(int first) { } static void HopAction() { - PHOPENTRY pEntry = pEntries + FROM_LE_32(pChosenScene->entryIndex) + cd.selBox + cd.extraBase; + PHOPENTRY pEntry = g_pEntries + FROM_LE_32(g_pChosenScene->entryIndex) + cd.selBox + cd.extraBase; - uint32 hScene = FROM_LE_32(pChosenScene->hScene); + uint32 hScene = FROM_LE_32(g_pChosenScene->hScene); uint32 eNumber = FROM_LE_32(pEntry->eNumber); debugC(DEBUG_BASIC, kTinselDebugAnimations, "Scene hopper chose scene %xh,%d\n", hScene, eNumber); if (FROM_LE_32(pEntry->flags) & fCall) { SaveScene(nullContext); - NewScene(nullContext, pChosenScene->hScene, pEntry->eNumber, TRANS_FADE); + NewScene(nullContext, g_pChosenScene->hScene, pEntry->eNumber, TRANS_FADE); } else if (FROM_LE_32(pEntry->flags) & fHook) HookScene(hScene, eNumber, TRANS_FADE); @@ -1220,9 +1209,9 @@ static void HopAction() { */ static void DumpIconArray() { for (int i = 0; i < MAX_ICONS; i++) { - if (iconArray[i] != NULL) { - MultiDeleteObject(GetPlayfieldList(FIELD_STATUS), iconArray[i]); - iconArray[i] = NULL; + if (g_iconArray[i] != NULL) { + MultiDeleteObject(GetPlayfieldList(FIELD_STATUS), g_iconArray[i]); + g_iconArray[i] = NULL; } } } @@ -1232,9 +1221,9 @@ static void DumpIconArray() { */ static void DumpDobjArray() { for (int i = 0; i < MAX_WCOMP; i++) { - if (DobjArray[i] != NULL) { - MultiDeleteObject(GetPlayfieldList(FIELD_STATUS), DobjArray[i]); - DobjArray[i] = NULL; + if (g_DobjArray[i] != NULL) { + MultiDeleteObject(GetPlayfieldList(FIELD_STATUS), g_DobjArray[i]); + g_DobjArray[i] = NULL; } } } @@ -1244,9 +1233,9 @@ static void DumpDobjArray() { */ static void DumpObjArray() { for (int i = 0; i < MAX_WCOMP; i++) { - if (objArray[i] != NULL) { - MultiDeleteObject(GetPlayfieldList(FIELD_STATUS), objArray[i]); - objArray[i] = NULL; + if (g_objArray[i] != NULL) { + MultiDeleteObject(GetPlayfieldList(FIELD_STATUS), g_objArray[i]); + g_objArray[i] = NULL; } } } @@ -1256,9 +1245,9 @@ static void DumpObjArray() { * i.e. Image data and Glitter code. */ static INV_OBJECT *GetInvObject(int id) { - INV_OBJECT *pObject = invObjects; + INV_OBJECT *pObject = g_invObjects; - for (int i = 0; i < numObjects; i++, pObject++) { + for (int i = 0; i < g_numObjects; i++, pObject++) { if (pObject->id == id) return pObject; } @@ -1270,9 +1259,9 @@ static INV_OBJECT *GetInvObject(int id) { * Convert item ID number to index. */ static int GetObjectIndex(int id) { - INV_OBJECT *pObject = invObjects; + INV_OBJECT *pObject = g_invObjects; - for (int i = 0; i < numObjects; i++, pObject++) { + for (int i = 0; i < g_numObjects; i++, pObject++) { if (pObject->id == id) return i; } @@ -1287,15 +1276,15 @@ static int GetObjectIndex(int id) { extern int InventoryPos(int num) { int i; - for (i = 0; i < InvD[INV_1].NoofItems; i++) // First inventory - if (InvD[INV_1].contents[i] == num) + for (i = 0; i < g_InvD[INV_1].NoofItems; i++) // First inventory + if (g_InvD[INV_1].contents[i] == num) return i; - for (i = 0; i < InvD[INV_2].NoofItems; i++) // Second inventory - if (InvD[INV_2].contents[i] == num) + for (i = 0; i < g_InvD[INV_2].NoofItems; i++) // Second inventory + if (g_InvD[INV_2].contents[i] == num) return i; - if (HeldItem == num) + if (g_heldItem == num) return INV_HELDNOTIN; // Held, but not in either inventory return INV_NOICON; // Not held, not in either inventory @@ -1304,8 +1293,8 @@ extern int InventoryPos(int num) { extern bool IsInInventory(int object, int invnum) { assert(invnum == INV_1 || invnum == INV_2); - for (int i = 0; i < InvD[invnum].NoofItems; i++) // First inventory - if (InvD[invnum].contents[i] == object) + for (int i = 0; i < g_InvD[invnum].NoofItems; i++) // First inventory + if (g_InvD[invnum].contents[i] == object) return true; return false; @@ -1315,7 +1304,7 @@ extern bool IsInInventory(int object, int invnum) { * Returns which item is held (INV_NOICON (-1) if none) */ extern int WhichItemHeld() { - return HeldItem; + return g_heldItem; } /** @@ -1324,15 +1313,15 @@ extern int WhichItemHeld() { */ extern void InventoryIconCursor(bool bNewItem) { - if (HeldItem != INV_NOICON) { + if (g_heldItem != INV_NOICON) { if (TinselV2) { if (bNewItem) { - int objIndex = GetObjectIndex(HeldItem); - heldFilm = invFilms[objIndex]; + int objIndex = GetObjectIndex(g_heldItem); + g_heldFilm = g_invFilms[objIndex]; } - SetAuxCursor(heldFilm); + SetAuxCursor(g_heldFilm); } else { - INV_OBJECT *invObj = GetInvObject(HeldItem); + INV_OBJECT *invObj = GetInvObject(g_heldItem); SetAuxCursor(invObj->hIconFilm); } } @@ -1342,14 +1331,14 @@ extern void InventoryIconCursor(bool bNewItem) { * Returns true if the inventory is active. */ extern bool InventoryActive() { - return (InventoryState == ACTIVE_INV); + return (g_InventoryState == ACTIVE_INV); } extern int WhichInventoryOpen() { - if (InventoryState != ACTIVE_INV) + if (g_InventoryState != ACTIVE_INV) return 0; else - return ino; + return g_ino; } @@ -1387,7 +1376,7 @@ static void ObjectProcess(CORO_PARAM, const void *param) { CORO_INVOKE_1(Interpret, _ctx->pic); if (to->event == POINTED) { - _ctx->ThisPointedWait = ++PointedWaitCount; + _ctx->ThisPointedWait = ++g_PointedWaitCount; while (1) { CORO_SLEEP(1); int x, y; @@ -1396,7 +1385,7 @@ static void ObjectProcess(CORO_PARAM, const void *param) { break; // Fix the 'repeated pressing bug' - if (_ctx->ThisPointedWait != PointedWaitCount) + if (_ctx->ThisPointedWait != g_PointedWaitCount) CORO_KILL_SELF(); } @@ -1413,10 +1402,10 @@ static void ObjectProcess(CORO_PARAM, const void *param) { static void InvTinselEvent(INV_OBJECT *pinvo, TINSEL_EVENT event, PLR_EVENT be, int index) { OP_INIT to = { pinvo, event, be, 0 }; - if (InventoryHidden || (TinselV2 && !pinvo->hScript)) + if (g_InventoryHidden || (TinselV2 && !pinvo->hScript)) return; - GlitterIndex = index; + g_GlitterIndex = index; g_scheduler->createProcess(PID_TCODE, ObjectProcess, &to, sizeof(to)); } @@ -1491,9 +1480,9 @@ static void FirstFile(int first) { static void InvSaveGame() { if (cd.selBox != NOBOX) { #ifndef JAPAN - sedit[strlen(sedit)-1] = 0; // Don't include the cursor! + g_sedit[strlen(g_sedit)-1] = 0; // Don't include the cursor! #endif - SaveGame(ListEntry(cd.selBox-cd.modifier+cd.extraBase, LE_NAME), sedit); + SaveGame(ListEntry(cd.selBox-cd.modifier+cd.extraBase, LE_NAME), g_sedit); } } @@ -1506,17 +1495,17 @@ static void InvLoadGame() { if (cd.selBox != NOBOX && (cd.selBox+cd.extraBase < cd.numSaved)) { rGame = cd.selBox; cd.selBox = NOBOX; - if (iconArray[HL3] != NULL) { - MultiDeleteObject(GetPlayfieldList(FIELD_STATUS), iconArray[HL3]); - iconArray[HL3] = NULL; + if (g_iconArray[HL3] != NULL) { + MultiDeleteObject(GetPlayfieldList(FIELD_STATUS), g_iconArray[HL3]); + g_iconArray[HL3] = NULL; } - if (iconArray[HL2] != NULL) { - MultiDeleteObject(GetPlayfieldList(FIELD_STATUS), iconArray[HL2]); - iconArray[HL2] = NULL; + if (g_iconArray[HL2] != NULL) { + MultiDeleteObject(GetPlayfieldList(FIELD_STATUS), g_iconArray[HL2]); + g_iconArray[HL2] = NULL; } - if (iconArray[HL1] != NULL) { - MultiDeleteObject(GetPlayfieldList(FIELD_STATUS), iconArray[HL1]); - iconArray[HL1] = NULL; + if (g_iconArray[HL1] != NULL) { + MultiDeleteObject(GetPlayfieldList(FIELD_STATUS), g_iconArray[HL1]); + g_iconArray[HL1] = NULL; } RestoreGame(rGame+cd.extraBase); } @@ -1533,7 +1522,7 @@ static bool UpdateString(const Common::KeyState &kbd) { if (!cd.editableRgroup) return false; - cpos = strlen(sedit)-1; + cpos = strlen(g_sedit)-1; if (kbd.ascii == 0) return false; @@ -1541,18 +1530,18 @@ static bool UpdateString(const Common::KeyState &kbd) { if (kbd.keycode == Common::KEYCODE_BACKSPACE) { if (!cpos) return false; - sedit[cpos] = 0; + g_sedit[cpos] = 0; cpos--; - sedit[cpos] = CURSOR_CHAR; + g_sedit[cpos] = CURSOR_CHAR; return true; // } else if (isalnum(c) || c == ',' || c == '.' || c == '\'' || (c == ' ' && cpos != 0)) { } else if (IsCharImage(GetTagFontHandle(), kbd.ascii) || (kbd.ascii == ' ' && cpos != 0)) { if (cpos == SG_DESC_LEN) return false; - sedit[cpos] = kbd.ascii; + g_sedit[cpos] = kbd.ascii; cpos++; - sedit[cpos] = CURSOR_CHAR; - sedit[cpos+1] = 0; + g_sedit[cpos] = CURSOR_CHAR; + g_sedit[cpos+1] = 0; return true; } return false; @@ -1582,25 +1571,25 @@ static bool InvKeyIn(const Common::KeyState &kbd) { * Delete display of text currently being edited, * and replace it with freshly edited text. */ - if (iconArray[HL3] != NULL) { - MultiDeleteObject(GetPlayfieldList(FIELD_STATUS), iconArray[HL3]); - iconArray[HL3] = NULL; + if (g_iconArray[HL3] != NULL) { + MultiDeleteObject(GetPlayfieldList(FIELD_STATUS), g_iconArray[HL3]); + g_iconArray[HL3] = NULL; } - iconArray[HL3] = ObjectTextOut( - GetPlayfieldList(FIELD_STATUS), sedit, 0, - InvD[ino].inventoryX + cd.box[cd.selBox].xpos + 2, - InvD[ino].inventoryY + cd.box[cd.selBox].ypos + TYOFF, + g_iconArray[HL3] = ObjectTextOut( + GetPlayfieldList(FIELD_STATUS), g_sedit, 0, + g_InvD[g_ino].inventoryX + cd.box[cd.selBox].xpos + 2, + g_InvD[g_ino].inventoryY + cd.box[cd.selBox].ypos + TYOFF, GetTagFontHandle(), 0); - if (MultiRightmost(iconArray[HL3]) > MAX_NAME_RIGHT) { - MultiDeleteObject(GetPlayfieldList(FIELD_STATUS), iconArray[HL3]); + if (MultiRightmost(g_iconArray[HL3]) > MAX_NAME_RIGHT) { + MultiDeleteObject(GetPlayfieldList(FIELD_STATUS), g_iconArray[HL3]); UpdateString(Common::KeyState(Common::KEYCODE_BACKSPACE)); - iconArray[HL3] = ObjectTextOut( - GetPlayfieldList(FIELD_STATUS), sedit, 0, - InvD[ino].inventoryX + cd.box[cd.selBox].xpos + 2, - InvD[ino].inventoryY + cd.box[cd.selBox].ypos + TYOFF, + g_iconArray[HL3] = ObjectTextOut( + GetPlayfieldList(FIELD_STATUS), g_sedit, 0, + g_InvD[g_ino].inventoryX + cd.box[cd.selBox].xpos + 2, + g_InvD[g_ino].inventoryY + cd.box[cd.selBox].ypos + TYOFF, GetTagFontHandle(), 0); } - MultiSetZPosition(iconArray[HL3], Z_INV_ITEXT + 2); + MultiSetZPosition(g_iconArray[HL3], Z_INV_ITEXT + 2); } #endif } @@ -1625,28 +1614,28 @@ static void Select(int i, bool force) { cd.selBox = i; // Clear previous selected highlight and text - if (iconArray[HL2] != NULL) { - MultiDeleteObject(GetPlayfieldList(FIELD_STATUS), iconArray[HL2]); - iconArray[HL2] = NULL; + if (g_iconArray[HL2] != NULL) { + MultiDeleteObject(GetPlayfieldList(FIELD_STATUS), g_iconArray[HL2]); + g_iconArray[HL2] = NULL; } - if (iconArray[HL3] != NULL) { - MultiDeleteObject(GetPlayfieldList(FIELD_STATUS), iconArray[HL3]); - iconArray[HL3] = NULL; + if (g_iconArray[HL3] != NULL) { + MultiDeleteObject(GetPlayfieldList(FIELD_STATUS), g_iconArray[HL3]); + g_iconArray[HL3] = NULL; } // New highlight box switch (cd.box[i].boxType) { case RGROUP: - iconArray[HL2] = RectangleObject(BgPal(), + g_iconArray[HL2] = RectangleObject(BgPal(), (TinselV2 ? HighlightColor() : COL_HILIGHT), cd.box[i].w, cd.box[i].h); - MultiInsertObject(GetPlayfieldList(FIELD_STATUS), iconArray[HL2]); - MultiSetAniXY(iconArray[HL2], - InvD[ino].inventoryX + cd.box[i].xpos, - InvD[ino].inventoryY + cd.box[i].ypos); + MultiInsertObject(GetPlayfieldList(FIELD_STATUS), g_iconArray[HL2]); + MultiSetAniXY(g_iconArray[HL2], + g_InvD[g_ino].inventoryX + cd.box[i].xpos, + g_InvD[g_ino].inventoryY + cd.box[i].ypos); // Z-position of box, and add edit text if appropriate if (cd.editableRgroup) { - MultiSetZPosition(iconArray[HL2], Z_INV_ITEXT+1); + MultiSetZPosition(g_iconArray[HL2], Z_INV_ITEXT+1); if (TinselV2) { assert(cd.box[i].textMethod == TM_POINTER); @@ -1657,29 +1646,29 @@ static void Select(int i, bool force) { // Current date and time time(&secs_now); time_now = localtime(&secs_now); - strftime(sedit, SG_DESC_LEN, "%D %H:%M", time_now); + strftime(g_sedit, SG_DESC_LEN, "%D %H:%M", time_now); #else // Current description with cursor appended if (cd.box[i].boxText != NULL) { - strcpy(sedit, cd.box[i].boxText); - strcat(sedit, sCursor); + strcpy(g_sedit, cd.box[i].boxText); + strcat(g_sedit, sCursor); } else { - strcpy(sedit, sCursor); + strcpy(g_sedit, sCursor); } #endif - iconArray[HL3] = ObjectTextOut( - GetPlayfieldList(FIELD_STATUS), sedit, 0, - InvD[ino].inventoryX + cd.box[i].xpos + 2, + g_iconArray[HL3] = ObjectTextOut( + GetPlayfieldList(FIELD_STATUS), g_sedit, 0, + g_InvD[g_ino].inventoryX + cd.box[i].xpos + 2, #ifdef JAPAN - InvD[ino].inventoryY + cd.box[i].ypos + 2, + g_InvD[g_ino].inventoryY + cd.box[i].ypos + 2, #else - InvD[ino].inventoryY + cd.box[i].ypos + TYOFF, + g_InvD[g_ino].inventoryY + cd.box[i].ypos + TYOFF, #endif GetTagFontHandle(), 0); - MultiSetZPosition(iconArray[HL3], Z_INV_ITEXT + 2); + MultiSetZPosition(g_iconArray[HL3], Z_INV_ITEXT + 2); } else { - MultiSetZPosition(iconArray[HL2], Z_INV_ICONS + 1); + MultiSetZPosition(g_iconArray[HL2], Z_INV_ICONS + 1); } _vm->divertKeyInput(InvKeyIn); @@ -1687,12 +1676,12 @@ static void Select(int i, bool force) { break; case FRGROUP: - iconArray[HL2] = RectangleObject(BgPal(), COL_HILIGHT, cd.box[i].w+6, cd.box[i].h+6); - MultiInsertObject(GetPlayfieldList(FIELD_STATUS), iconArray[HL2]); - MultiSetAniXY(iconArray[HL2], - InvD[ino].inventoryX + cd.box[i].xpos - 2, - InvD[ino].inventoryY + cd.box[i].ypos - 2); - MultiSetZPosition(iconArray[HL2], Z_INV_BRECT+1); + g_iconArray[HL2] = RectangleObject(BgPal(), COL_HILIGHT, cd.box[i].w+6, cd.box[i].h+6); + MultiInsertObject(GetPlayfieldList(FIELD_STATUS), g_iconArray[HL2]); + MultiSetAniXY(g_iconArray[HL2], + g_InvD[g_ino].inventoryX + cd.box[i].xpos - 2, + g_InvD[g_ino].inventoryY + cd.box[i].ypos - 2); + MultiSetZPosition(g_iconArray[HL2], Z_INV_BRECT+1); break; @@ -1710,13 +1699,13 @@ static void Select(int i, bool force) { * Stop holding an item. */ extern void DropItem(int item) { - if (HeldItem == item) { - HeldItem = INV_NOICON; // Item not held + if (g_heldItem == item) { + g_heldItem = INV_NOICON; // Item not held DelAuxCursor(); // no longer aux cursor } // Redraw contents - held item was not displayed as a content. - ItemsChanged = true; + g_ItemsChanged = true; } /** @@ -1725,8 +1714,8 @@ extern void DropItem(int item) { extern void ClearInventory(int invno) { assert(invno == INV_1 || invno == INV_2); - InvD[invno].NoofItems = 0; - memset(InvD[invno].contents, 0, sizeof(InvD[invno].contents)); + g_InvD[invno].NoofItems = 0; + memset(g_InvD[invno].contents, 0, sizeof(g_InvD[invno].contents)); } /** @@ -1743,12 +1732,12 @@ extern void AddToInventory(int invno, int icon, bool hold) { || invno == INV_OPEN || (invno == INV_DEFAULT && TinselV2)); if (invno == INV_OPEN) { - assert(InventoryState == ACTIVE_INV && (ino == INV_1 || ino == INV_2)); // addopeninv() with inventry not open - invno = ino; + assert(g_InventoryState == ACTIVE_INV && (g_ino == INV_1 || g_ino == INV_2)); // addopeninv() with inventry not open + invno = g_ino; bOpen = true; // Make sure it doesn't get in both! - RemFromInventory(ino == INV_1 ? INV_2 : INV_1, icon); + RemFromInventory(g_ino == INV_1 ? INV_2 : INV_1, icon); } else { bOpen = false; @@ -1769,61 +1758,61 @@ extern void AddToInventory(int invno, int icon, bool hold) { RemFromInventory(INV_1, icon); // See if it's already there - for (i = 0; i < InvD[invno].NoofItems; i++) { - if (InvD[invno].contents[i] == icon) + for (i = 0; i < g_InvD[invno].NoofItems; i++) { + if (g_InvD[invno].contents[i] == icon) break; } // Add it if it isn't already there - if (i == InvD[invno].NoofItems) { + if (i == g_InvD[invno].NoofItems) { if (!bOpen) { if (invno == INV_CONV) { if (TinselV2) { int nei; // Count how many current contents have end attribute - for (i = 0, nei = 0; i < InvD[INV_CONV].NoofItems; i++) { - invObj = GetInvObject(InvD[INV_CONV].contents[i]); + for (i = 0, nei = 0; i < g_InvD[INV_CONV].NoofItems; i++) { + invObj = GetInvObject(g_InvD[INV_CONV].contents[i]); if (invObj->attribute & CONVENDITEM) nei++; } // For conversation, insert before end icons - memmove(&InvD[INV_CONV].contents[i-nei+1], - &InvD[INV_CONV].contents[i-nei], nei * sizeof(int)); - InvD[INV_CONV].contents[i - nei] = icon; - InvD[INV_CONV].NoofItems++; - InvD[INV_CONV].NoofHicons = InvD[INV_CONV].NoofItems; + memmove(&g_InvD[INV_CONV].contents[i-nei+1], + &g_InvD[INV_CONV].contents[i-nei], nei * sizeof(int)); + g_InvD[INV_CONV].contents[i - nei] = icon; + g_InvD[INV_CONV].NoofItems++; + g_InvD[INV_CONV].NoofHicons = g_InvD[INV_CONV].NoofItems; // Get the window to re-position - bMoveOnUnHide = true; + g_bMoveOnUnHide = true; } else { // For conversation, insert before last icon // which will always be the goodbye icon - InvD[invno].contents[InvD[invno].NoofItems] = InvD[invno].contents[InvD[invno].NoofItems-1]; - InvD[invno].contents[InvD[invno].NoofItems-1] = icon; - InvD[invno].NoofItems++; + g_InvD[invno].contents[g_InvD[invno].NoofItems] = g_InvD[invno].contents[g_InvD[invno].NoofItems-1]; + g_InvD[invno].contents[g_InvD[invno].NoofItems-1] = icon; + g_InvD[invno].NoofItems++; } } else { - InvD[invno].contents[InvD[invno].NoofItems++] = icon; + g_InvD[invno].contents[g_InvD[invno].NoofItems++] = icon; } - ItemsChanged = true; + g_ItemsChanged = true; } else { // It could be that the index is beyond what you'd expect // as delinv may well have been called - if (GlitterIndex < InvD[invno].NoofItems) { - memmove(&InvD[invno].contents[GlitterIndex + 1], - &InvD[invno].contents[GlitterIndex], - (InvD[invno].NoofItems - GlitterIndex) * sizeof(int)); - InvD[invno].contents[GlitterIndex] = icon; + if (g_GlitterIndex < g_InvD[invno].NoofItems) { + memmove(&g_InvD[invno].contents[g_GlitterIndex + 1], + &g_InvD[invno].contents[g_GlitterIndex], + (g_InvD[invno].NoofItems - g_GlitterIndex) * sizeof(int)); + g_InvD[invno].contents[g_GlitterIndex] = icon; } else { - InvD[invno].contents[InvD[invno].NoofItems] = icon; + g_InvD[invno].contents[g_InvD[invno].NoofItems] = icon; } - InvD[invno].NoofItems++; + g_InvD[invno].NoofItems++; } // Move here after bug on Japenese DW1 - ItemsChanged = true; + g_ItemsChanged = true; } // Hold it if requested @@ -1841,25 +1830,25 @@ extern bool RemFromInventory(int invno, int icon) { assert(invno == INV_1 || invno == INV_2 || invno == INV_CONV); // Trying to delete from illegal inventory // See if it's there - for (i = 0; i < InvD[invno].NoofItems; i++) { - if (InvD[invno].contents[i] == icon) + for (i = 0; i < g_InvD[invno].NoofItems; i++) { + if (g_InvD[invno].contents[i] == icon) break; } - if (i == InvD[invno].NoofItems) + if (i == g_InvD[invno].NoofItems) return false; // Item wasn't there else { - memmove(&InvD[invno].contents[i], &InvD[invno].contents[i+1], (InvD[invno].NoofItems-i)*sizeof(int)); - InvD[invno].NoofItems--; + memmove(&g_InvD[invno].contents[i], &g_InvD[invno].contents[i+1], (g_InvD[invno].NoofItems-i)*sizeof(int)); + g_InvD[invno].NoofItems--; if (TinselV2 && invno == INV_CONV) { - InvD[INV_CONV].NoofHicons = InvD[invno].NoofItems; + g_InvD[INV_CONV].NoofHicons = g_InvD[invno].NoofItems; // Get the window to re-position - bMoveOnUnHide = true; + g_bMoveOnUnHide = true; } - ItemsChanged = true; + g_ItemsChanged = true; return true; // Item removed } } @@ -1870,27 +1859,27 @@ extern bool RemFromInventory(int invno, int icon) { extern void HoldItem(int item, bool bKeepFilm) { INV_OBJECT *invObj; - if (HeldItem != item) { - if (TinselV2 && (HeldItem != NOOBJECT)) { + if (g_heldItem != item) { + if (TinselV2 && (g_heldItem != NOOBJECT)) { // No longer holding previous item DelAuxCursor(); // no longer aux cursor // If old held object is not in an inventory, and // has a default, stick it in its default inventory. - if (!IsInInventory(HeldItem, INV_1) && !IsInInventory(HeldItem, INV_2)) { - invObj = GetInvObject(HeldItem); + if (!IsInInventory(g_heldItem, INV_1) && !IsInInventory(g_heldItem, INV_2)) { + invObj = GetInvObject(g_heldItem); if (invObj->attribute & DEFINV1) - AddToInventory(INV_1, HeldItem); + AddToInventory(INV_1, g_heldItem); else if (invObj->attribute & DEFINV2) - AddToInventory(INV_2, HeldItem); + AddToInventory(INV_2, g_heldItem); else // Hook for definable default inventory - AddToInventory(INV_1, HeldItem); + AddToInventory(INV_1, g_heldItem); } } else if (!TinselV2) { - if (item == INV_NOICON && HeldItem != INV_NOICON) + if (item == INV_NOICON && g_heldItem != INV_NOICON) DelAuxCursor(); // no longer aux cursor if (item != INV_NOICON) { @@ -1899,19 +1888,19 @@ extern void HoldItem(int item, bool bKeepFilm) { } } - HeldItem = item; // Item held + g_heldItem = item; // Item held if (TinselV2) { InventoryIconCursor(!bKeepFilm); // Redraw contents - held item not displayed as a content. - ItemsChanged = true; + g_ItemsChanged = true; } } if (!TinselV2) // Redraw contents - held item not displayed as a content. - ItemsChanged = true; + g_ItemsChanged = true; } /**************************************************************************/ @@ -1929,8 +1918,8 @@ enum { I_NOTIN, I_HEADER, I_BODY, // the active area of the borders for re-sizing. /*---------------------------------*/ -#define LeftX InvD[ino].inventoryX -#define TopY InvD[ino].inventoryY +#define LeftX g_InvD[g_ino].inventoryX +#define TopY g_InvD[g_ino].inventoryY /*---------------------------------*/ /** @@ -1943,8 +1932,8 @@ enum { I_NOTIN, I_HEADER, I_BODY, */ static int InvArea(int x, int y) { if (TinselV2) { - int RightX = MultiRightmost(RectObject) - NM_BG_SIZ_X - NM_BG_POS_X - NM_RS_R_INSET; - int BottomY = MultiLowest(RectObject) - NM_BG_SIZ_Y - NM_BG_POS_Y - NM_RS_B_INSET; + int RightX = MultiRightmost(g_RectObject) - NM_BG_SIZ_X - NM_BG_POS_X - NM_RS_R_INSET; + int BottomY = MultiLowest(g_RectObject) - NM_BG_SIZ_Y - NM_BG_POS_Y - NM_RS_B_INSET; // Outside the whole rectangle? if (x <= LeftX || x > RightX || y <= TopY || y > BottomY) @@ -1983,7 +1972,7 @@ static int InvArea(int x, int y) { return I_HEADER; // Scroll bits - if (!(ino == INV_MENU && cd.bExtraWin)) { + if (!(g_ino == INV_MENU && cd.bExtraWin)) { if (x > RightX - NM_SLIDE_INSET && x <= RightX - NM_SLIDE_INSET + NM_SLIDE_THICKNESS) { if (y > TopY + NM_UP_ARROW_TOP && y < TopY + NM_UP_ARROW_BOTTOM) return I_UP; @@ -1992,10 +1981,10 @@ static int InvArea(int x, int y) { /* '3' is a magic adjustment with no apparent sense */ - if (y >= TopY + sliderYmin - 3 && y < TopY + sliderYmax + NM_SLH) { - if (y < TopY + sliderYpos - 3) + if (y >= TopY + g_sliderYmin - 3 && y < TopY + g_sliderYmax + NM_SLH) { + if (y < TopY + g_sliderYpos - 3) return I_SLIDE_UP; - if (y < TopY + sliderYpos + NM_SLH - 3) + if (y < TopY + g_sliderYpos + NM_SLH - 3) return I_SLIDE; else return I_SLIDE_DOWN; @@ -2003,8 +1992,8 @@ static int InvArea(int x, int y) { } } } else { - int RightX = MultiRightmost(RectObject) + 1; - int BottomY = MultiLowest(RectObject) + 1; + int RightX = MultiRightmost(g_RectObject) + 1; + int BottomY = MultiLowest(g_RectObject) + 1; // Outside the whole rectangle? if (x <= LeftX - EXTRA || x > RightX + EXTRA @@ -2041,7 +2030,7 @@ static int InvArea(int x, int y) { /* * In the move area? */ - if (ino != INV_CONF + if (g_ino != INV_CONF && x >= LeftX + M_SW - 2 && x <= RightX - M_SW + 3 && y >= TopY + M_TH - 2 && y < TopY + M_TBB + 2) return I_HEADER; @@ -2049,17 +2038,17 @@ static int InvArea(int x, int y) { /* * Scroll bits */ - if (!(ino == INV_CONF && cd.bExtraWin)) { + if (!(g_ino == INV_CONF && cd.bExtraWin)) { if (x > RightX - NM_SLIDE_INSET && x <= RightX - NM_SLIDE_INSET + NM_SLIDE_THICKNESS) { if (y > TopY + M_IUT + 1 && y < TopY + M_IUB - 1) return I_UP; if (y > BottomY - M_IDT + 4 && y <= BottomY - M_IDB + 1) return I_DOWN; - if (y >= TopY + sliderYmin && y < TopY + sliderYmax + M_SH) { - if (y < TopY + sliderYpos) + if (y >= TopY + g_sliderYmin && y < TopY + g_sliderYmax + M_SH) { + if (y < TopY + g_sliderYpos) return I_SLIDE_UP; - if (y < TopY + sliderYpos + M_SH) + if (y < TopY + g_sliderYpos + M_SH) return I_SLIDE; else return I_SLIDE_DOWN; @@ -2081,14 +2070,14 @@ extern int InvItem(int *x, int *y, bool update) { int item; int IconsX; - itop = InvD[ino].inventoryY + START_ICONY; + itop = g_InvD[g_ino].inventoryY + START_ICONY; - IconsX = InvD[ino].inventoryX + START_ICONX; + IconsX = g_InvD[g_ino].inventoryX + START_ICONX; - for (item = InvD[ino].FirstDisp, row = 0; row < InvD[ino].NoofVicons; row++) { + for (item = g_InvD[g_ino].FirstDisp, row = 0; row < g_InvD[g_ino].NoofVicons; row++) { ileft = IconsX; - for (col = 0; col < InvD[ino].NoofHicons; col++, item++) { + for (col = 0; col < g_InvD[g_ino].NoofHicons; col++, item++) { if (*x >= ileft && *x < ileft + ITEM_WIDTH && *y >= itop && *y < itop + ITEM_HEIGHT) { if (update) { @@ -2121,20 +2110,20 @@ int InvItemId(int x, int y) { int row, col; int item; - if (InventoryHidden || InventoryState == IDLE_INV) + if (g_InventoryHidden || g_InventoryState == IDLE_INV) return INV_NOICON; - itop = InvD[ino].inventoryY + START_ICONY; + itop = g_InvD[g_ino].inventoryY + START_ICONY; - int IconsX = InvD[ino].inventoryX + START_ICONX; + int IconsX = g_InvD[g_ino].inventoryX + START_ICONX; - for (item = InvD[ino].FirstDisp, row = 0; row < InvD[ino].NoofVicons; row++) { + for (item = g_InvD[g_ino].FirstDisp, row = 0; row < g_InvD[g_ino].NoofVicons; row++) { ileft = IconsX; - for (col = 0; col < InvD[ino].NoofHicons; col++, item++) { + for (col = 0; col < g_InvD[g_ino].NoofHicons; col++, item++) { if (x >= ileft && x < ileft + ITEM_WIDTH && y >= itop && y < itop + ITEM_HEIGHT) { - return InvD[ino].contents[item]; + return g_InvD[g_ino].contents[item]; } ileft += ITEM_WIDTH + 1; @@ -2149,15 +2138,15 @@ int InvItemId(int x, int y) { */ static int WhichMenuBox(int curX, int curY, bool bSlides) { if (bSlides) { - for (int i = 0; i < numMdSlides; i++) { - if (curY > MultiHighest(mdSlides[i].obj) && curY < MultiLowest(mdSlides[i].obj) - && curX > MultiLeftmost(mdSlides[i].obj) && curX < MultiRightmost(mdSlides[i].obj)) - return mdSlides[i].num | IS_SLIDER; + for (int i = 0; i < g_numMdSlides; i++) { + if (curY > MultiHighest(g_mdSlides[i].obj) && curY < MultiLowest(g_mdSlides[i].obj) + && curX > MultiLeftmost(g_mdSlides[i].obj) && curX < MultiRightmost(g_mdSlides[i].obj)) + return g_mdSlides[i].num | IS_SLIDER; } } - curX -= InvD[ino].inventoryX; - curY -= InvD[ino].inventoryY; + curX -= g_InvD[g_ino].inventoryX; + curY -= g_InvD[g_ino].inventoryY; for (int i = 0; i < cd.NumBoxes; i++) { switch (cd.box[i].boxType) { @@ -2184,7 +2173,7 @@ static int WhichMenuBox(int curX, int curY, bool bSlides) { break; case ROTATE: - if (bNoLanguage) + if (g_bNoLanguage) break; if (curY > cd.box[i].ypos && curY < cd.box[i].ypos + cd.box[i].h) { @@ -2222,9 +2211,9 @@ static int WhichMenuBox(int curX, int curY, bool bSlides) { return IB_UP; else if (curY > (r.bottom - (TinselV2 ? 18 : 5))) return IB_DOWN; - else if (curY + InvD[ino].inventoryY < sliderYpos) + else if (curY + g_InvD[g_ino].inventoryY < g_sliderYpos) return IB_SLIDE_UP; - else if (curY + InvD[ino].inventoryY >= sliderYpos + NM_SLH) + else if (curY + g_InvD[g_ino].inventoryY >= g_sliderYpos + NM_SLH) return IB_SLIDE_DOWN; else return IB_SLIDE; @@ -2260,60 +2249,60 @@ static void InvBoxes(bool InBody, int curX, int curY) { if (index < 0) { // unhigh-light box (if one was) cd.pointBox = NOBOX; - if (iconArray[HL1] != NULL) { - MultiDeleteObject(GetPlayfieldList(FIELD_STATUS), iconArray[HL1]); - iconArray[HL1] = NULL; + if (g_iconArray[HL1] != NULL) { + MultiDeleteObject(GetPlayfieldList(FIELD_STATUS), g_iconArray[HL1]); + g_iconArray[HL1] = NULL; } } else if (index != cd.pointBox) { cd.pointBox = index; // A new box is pointed to - high-light it - if (iconArray[HL1] != NULL) { - MultiDeleteObject(GetPlayfieldList(FIELD_STATUS), iconArray[HL1]); - iconArray[HL1] = NULL; + if (g_iconArray[HL1] != NULL) { + MultiDeleteObject(GetPlayfieldList(FIELD_STATUS), g_iconArray[HL1]); + g_iconArray[HL1] = NULL; } if ((cd.box[cd.pointBox].boxType == ARSBUT && cd.selBox != NOBOX) || ///* I don't agree */ cd.box[cd.pointBox].boxType == RGROUP || cd.box[cd.pointBox].boxType == AATBUT || cd.box[cd.pointBox].boxType == AABUT) { - iconArray[HL1] = RectangleObject(BgPal(), + g_iconArray[HL1] = RectangleObject(BgPal(), (TinselV2 ? HighlightColor() : COL_HILIGHT), cd.box[cd.pointBox].w, cd.box[cd.pointBox].h); - MultiInsertObject(GetPlayfieldList(FIELD_STATUS), iconArray[HL1]); - MultiSetAniXY(iconArray[HL1], - InvD[ino].inventoryX + cd.box[cd.pointBox].xpos, - InvD[ino].inventoryY + cd.box[cd.pointBox].ypos); - MultiSetZPosition(iconArray[HL1], Z_INV_ICONS+1); + MultiInsertObject(GetPlayfieldList(FIELD_STATUS), g_iconArray[HL1]); + MultiSetAniXY(g_iconArray[HL1], + g_InvD[g_ino].inventoryX + cd.box[cd.pointBox].xpos, + g_InvD[g_ino].inventoryY + cd.box[cd.pointBox].ypos); + MultiSetZPosition(g_iconArray[HL1], Z_INV_ICONS+1); } else if (cd.box[cd.pointBox].boxType == AAGBUT || cd.box[cd.pointBox].boxType == ARSGBUT || cd.box[cd.pointBox].boxType == TOGGLE || cd.box[cd.pointBox].boxType == TOGGLE1 || cd.box[cd.pointBox].boxType == TOGGLE2) { - pfilm = (const FILM *)LockMem(hWinParts); + pfilm = (const FILM *)LockMem(g_hWinParts); - iconArray[HL1] = AddObject(&pfilm->reels[cd.box[cd.pointBox].bi+HIGRAPH], -1); - MultiSetAniXY(iconArray[HL1], - InvD[ino].inventoryX + cd.box[cd.pointBox].xpos, - InvD[ino].inventoryY + cd.box[cd.pointBox].ypos); - MultiSetZPosition(iconArray[HL1], Z_INV_ICONS+1); + g_iconArray[HL1] = AddObject(&pfilm->reels[cd.box[cd.pointBox].bi+HIGRAPH], -1); + MultiSetAniXY(g_iconArray[HL1], + g_InvD[g_ino].inventoryX + cd.box[cd.pointBox].xpos, + g_InvD[g_ino].inventoryY + cd.box[cd.pointBox].ypos); + MultiSetZPosition(g_iconArray[HL1], Z_INV_ICONS+1); } else if (cd.box[cd.pointBox].boxType == ROTATE) { - if (bNoLanguage) + if (g_bNoLanguage) return; - pfilm = (const FILM *)LockMem(hWinParts); + pfilm = (const FILM *)LockMem(g_hWinParts); rotateIndex = cd.box[cd.pointBox].bi; if (rotateIndex == IX2_LEFT1) { - iconArray[HL1] = AddObject(&pfilm->reels[IX2_LEFT2], -1 ); - MultiSetAniXY(iconArray[HL1], - InvD[ino].inventoryX + cd.box[cd.pointBox].xpos - ROTX1, - InvD[ino].inventoryY + cd.box[cd.pointBox].ypos); - MultiSetZPosition(iconArray[HL1], Z_INV_ICONS+1); + g_iconArray[HL1] = AddObject(&pfilm->reels[IX2_LEFT2], -1 ); + MultiSetAniXY(g_iconArray[HL1], + g_InvD[g_ino].inventoryX + cd.box[cd.pointBox].xpos - ROTX1, + g_InvD[g_ino].inventoryY + cd.box[cd.pointBox].ypos); + MultiSetZPosition(g_iconArray[HL1], Z_INV_ICONS+1); } else if (rotateIndex == IX2_RIGHT1) { - iconArray[HL1] = AddObject(&pfilm->reels[IX2_RIGHT2], -1); - MultiSetAniXY(iconArray[HL1], - InvD[ino].inventoryX + cd.box[cd.pointBox].xpos + ROTX1, - InvD[ino].inventoryY + cd.box[cd.pointBox].ypos); - MultiSetZPosition(iconArray[HL1], Z_INV_ICONS + 1); + g_iconArray[HL1] = AddObject(&pfilm->reels[IX2_RIGHT2], -1); + MultiSetAniXY(g_iconArray[HL1], + g_InvD[g_ino].inventoryX + cd.box[cd.pointBox].xpos + ROTX1, + g_InvD[g_ino].inventoryY + cd.box[cd.pointBox].ypos); + MultiSetZPosition(g_iconArray[HL1], Z_INV_ICONS + 1); } } } @@ -2330,37 +2319,37 @@ static void ButtonPress(CORO_PARAM, CONFBOX *box) { assert(box->boxType == AAGBUT || box->boxType == ARSGBUT); // Replace highlight image with normal image - pfilm = (const FILM *)LockMem(hWinParts); - if (iconArray[HL1] != NULL) - MultiDeleteObject(GetPlayfieldList(FIELD_STATUS), iconArray[HL1]); - pfilm = (const FILM *)LockMem(hWinParts); - iconArray[HL1] = AddObject(&pfilm->reels[box->bi+NORMGRAPH], -1); - MultiSetAniXY(iconArray[HL1], InvD[ino].inventoryX + box->xpos, InvD[ino].inventoryY + box->ypos); - MultiSetZPosition(iconArray[HL1], Z_INV_ICONS+1); + pfilm = (const FILM *)LockMem(g_hWinParts); + if (g_iconArray[HL1] != NULL) + MultiDeleteObject(GetPlayfieldList(FIELD_STATUS), g_iconArray[HL1]); + pfilm = (const FILM *)LockMem(g_hWinParts); + g_iconArray[HL1] = AddObject(&pfilm->reels[box->bi+NORMGRAPH], -1); + MultiSetAniXY(g_iconArray[HL1], g_InvD[g_ino].inventoryX + box->xpos, g_InvD[g_ino].inventoryY + box->ypos); + MultiSetZPosition(g_iconArray[HL1], Z_INV_ICONS+1); // Hold normal image for 1 frame CORO_SLEEP(1); - if (iconArray[HL1] == NULL) + if (g_iconArray[HL1] == NULL) return; // Replace normal image with depresses image - pfilm = (const FILM *)LockMem(hWinParts); - MultiDeleteObject(GetPlayfieldList(FIELD_STATUS), iconArray[HL1]); - iconArray[HL1] = AddObject(&pfilm->reels[box->bi+DOWNGRAPH], -1); - MultiSetAniXY(iconArray[HL1], InvD[ino].inventoryX + box->xpos, InvD[ino].inventoryY + box->ypos); - MultiSetZPosition(iconArray[HL1], Z_INV_ICONS+1); + pfilm = (const FILM *)LockMem(g_hWinParts); + MultiDeleteObject(GetPlayfieldList(FIELD_STATUS), g_iconArray[HL1]); + g_iconArray[HL1] = AddObject(&pfilm->reels[box->bi+DOWNGRAPH], -1); + MultiSetAniXY(g_iconArray[HL1], g_InvD[g_ino].inventoryX + box->xpos, g_InvD[g_ino].inventoryY + box->ypos); + MultiSetZPosition(g_iconArray[HL1], Z_INV_ICONS+1); // Hold depressed image for 2 frames CORO_SLEEP(2); - if (iconArray[HL1] == NULL) + if (g_iconArray[HL1] == NULL) return; // Replace depressed image with normal image - pfilm = (const FILM *)LockMem(hWinParts); - MultiDeleteObject(GetPlayfieldList(FIELD_STATUS), iconArray[HL1]); - iconArray[HL1] = AddObject(&pfilm->reels[box->bi+NORMGRAPH], -1); - MultiSetAniXY(iconArray[HL1], InvD[ino].inventoryX + box->xpos, InvD[ino].inventoryY + box->ypos); - MultiSetZPosition(iconArray[HL1], Z_INV_ICONS+1); + pfilm = (const FILM *)LockMem(g_hWinParts); + MultiDeleteObject(GetPlayfieldList(FIELD_STATUS), g_iconArray[HL1]); + g_iconArray[HL1] = AddObject(&pfilm->reels[box->bi+NORMGRAPH], -1); + MultiSetAniXY(g_iconArray[HL1], g_InvD[g_ino].inventoryX + box->xpos, g_InvD[g_ino].inventoryY + box->ypos); + MultiSetZPosition(g_iconArray[HL1], Z_INV_ICONS+1); CORO_SLEEP(1); @@ -2379,25 +2368,25 @@ static void ButtonToggle(CORO_PARAM, CONFBOX *box) { || (box->boxType == TOGGLE2)); // Remove hilight image - if (iconArray[HL1] != NULL) { - MultiDeleteObject(GetPlayfieldList(FIELD_STATUS), iconArray[HL1]); - iconArray[HL1] = NULL; + if (g_iconArray[HL1] != NULL) { + MultiDeleteObject(GetPlayfieldList(FIELD_STATUS), g_iconArray[HL1]); + g_iconArray[HL1] = NULL; } // Hold normal image for 1 frame CORO_SLEEP(1); - if (InventoryState != ACTIVE_INV) + if (g_InventoryState != ACTIVE_INV) return; // Add depressed image - pfilm = (const FILM *)LockMem(hWinParts); - iconArray[HL1] = AddObject(&pfilm->reels[box->bi+DOWNGRAPH], -1); - MultiSetAniXY(iconArray[HL1], InvD[ino].inventoryX + box->xpos, InvD[ino].inventoryY + box->ypos); - MultiSetZPosition(iconArray[HL1], Z_INV_ICONS+1); + pfilm = (const FILM *)LockMem(g_hWinParts); + g_iconArray[HL1] = AddObject(&pfilm->reels[box->bi+DOWNGRAPH], -1); + MultiSetAniXY(g_iconArray[HL1], g_InvD[g_ino].inventoryX + box->xpos, g_InvD[g_ino].inventoryY + box->ypos); + MultiSetZPosition(g_iconArray[HL1], Z_INV_ICONS+1); // Hold depressed image for 1 frame CORO_SLEEP(1); - if (iconArray[HL1] == NULL) + if (g_iconArray[HL1] == NULL) return; // Toggle state @@ -2409,34 +2398,34 @@ static void ButtonToggle(CORO_PARAM, CONFBOX *box) { Select(cd.selBox, true); // New state, depressed image - pfilm = (const FILM *)LockMem(hWinParts); - if (iconArray[HL1] != NULL) - MultiDeleteObject(GetPlayfieldList(FIELD_STATUS), iconArray[HL1]); - iconArray[HL1] = AddObject(&pfilm->reels[box->bi+DOWNGRAPH], -1); - MultiSetAniXY(iconArray[HL1], InvD[ino].inventoryX + box->xpos, InvD[ino].inventoryY + box->ypos); - MultiSetZPosition(iconArray[HL1], Z_INV_ICONS+1); + pfilm = (const FILM *)LockMem(g_hWinParts); + if (g_iconArray[HL1] != NULL) + MultiDeleteObject(GetPlayfieldList(FIELD_STATUS), g_iconArray[HL1]); + g_iconArray[HL1] = AddObject(&pfilm->reels[box->bi+DOWNGRAPH], -1); + MultiSetAniXY(g_iconArray[HL1], g_InvD[g_ino].inventoryX + box->xpos, g_InvD[g_ino].inventoryY + box->ypos); + MultiSetZPosition(g_iconArray[HL1], Z_INV_ICONS+1); // Hold new depressed image for 1 frame CORO_SLEEP(1); - if (iconArray[HL1] == NULL) + if (g_iconArray[HL1] == NULL) return; // New state, normal - MultiDeleteObject(GetPlayfieldList(FIELD_STATUS), iconArray[HL1]); - iconArray[HL1] = NULL; + MultiDeleteObject(GetPlayfieldList(FIELD_STATUS), g_iconArray[HL1]); + g_iconArray[HL1] = NULL; // Hold normal image for 1 frame CORO_SLEEP(1); - if (InventoryState != ACTIVE_INV) + if (g_InventoryState != ACTIVE_INV) return; // New state, highlighted - pfilm = (const FILM *)LockMem(hWinParts); - if (iconArray[HL1] != NULL) - MultiDeleteObject(GetPlayfieldList(FIELD_STATUS), iconArray[HL1]); - iconArray[HL1] = AddObject(&pfilm->reels[box->bi+HIGRAPH], -1); - MultiSetAniXY(iconArray[HL1], InvD[ino].inventoryX + box->xpos, InvD[ino].inventoryY + box->ypos); - MultiSetZPosition(iconArray[HL1], Z_INV_ICONS+1); + pfilm = (const FILM *)LockMem(g_hWinParts); + if (g_iconArray[HL1] != NULL) + MultiDeleteObject(GetPlayfieldList(FIELD_STATUS), g_iconArray[HL1]); + g_iconArray[HL1] = AddObject(&pfilm->reels[box->bi+HIGRAPH], -1); + MultiSetAniXY(g_iconArray[HL1], g_InvD[g_ino].inventoryX + box->xpos, g_InvD[g_ino].inventoryY + box->ypos); + MultiSetZPosition(g_iconArray[HL1], Z_INV_ICONS+1); CORO_END_CODE; } @@ -2454,23 +2443,23 @@ static void InvLabels(bool InBody, int aniX, int aniY) { else { index = InvItem(&aniX, &aniY, false); if (index != INV_NOICON) { - if (index >= InvD[ino].NoofItems) + if (index >= g_InvD[g_ino].NoofItems) index = INV_NOICON; else - index = InvD[ino].contents[index]; + index = g_InvD[g_ino].contents[index]; } } // If no icon pointed to, or points to (logical position of) // currently held icon, then no icon is pointed to! - if (index == INV_NOICON || index == HeldItem) { - pointedIcon = INV_NOICON; - } else if (index != pointedIcon) { + if (index == INV_NOICON || index == g_heldItem) { + g_pointedIcon = INV_NOICON; + } else if (index != g_pointedIcon) { // A new icon is pointed to - run its script with POINTED event invObj = GetInvObject(index); if (invObj->hScript) InvTinselEvent(invObj, POINTED, PLR_NOEVENT, index); - pointedIcon = index; + g_pointedIcon = index; } } @@ -2492,54 +2481,54 @@ static void AdjustTop() { int n, i; // Only do this if there's a slider - if (!SlideObject) + if (!g_SlideObject) return; - rowsWanted = (InvD[ino].NoofItems - InvD[ino].FirstDisp + InvD[ino].NoofHicons-1) / InvD[ino].NoofHicons; + rowsWanted = (g_InvD[g_ino].NoofItems - g_InvD[g_ino].FirstDisp + g_InvD[g_ino].NoofHicons-1) / g_InvD[g_ino].NoofHicons; - while (rowsWanted < InvD[ino].NoofVicons) { - if (InvD[ino].FirstDisp) { - InvD[ino].FirstDisp -= InvD[ino].NoofHicons; - if (InvD[ino].FirstDisp < 0) - InvD[ino].FirstDisp = 0; + while (rowsWanted < g_InvD[g_ino].NoofVicons) { + if (g_InvD[g_ino].FirstDisp) { + g_InvD[g_ino].FirstDisp -= g_InvD[g_ino].NoofHicons; + if (g_InvD[g_ino].FirstDisp < 0) + g_InvD[g_ino].FirstDisp = 0; rowsWanted++; } else break; } - tMissing = InvD[ino].FirstDisp ? (InvD[ino].FirstDisp + InvD[ino].NoofHicons-1)/InvD[ino].NoofHicons : 0; - bMissing = (rowsWanted > InvD[ino].NoofVicons) ? rowsWanted - InvD[ino].NoofVicons : 0; + tMissing = g_InvD[g_ino].FirstDisp ? (g_InvD[g_ino].FirstDisp + g_InvD[g_ino].NoofHicons-1)/g_InvD[g_ino].NoofHicons : 0; + bMissing = (rowsWanted > g_InvD[g_ino].NoofVicons) ? rowsWanted - g_InvD[g_ino].NoofVicons : 0; nMissing = tMissing + bMissing; - slideRange = sliderYmax - sliderYmin; + slideRange = g_sliderYmax - g_sliderYmin; if (!tMissing) - nsliderYpos = sliderYmin; + nsliderYpos = g_sliderYmin; else if (!bMissing) - nsliderYpos = sliderYmax; + nsliderYpos = g_sliderYmax; else { nsliderYpos = tMissing*slideRange/nMissing; - nsliderYpos += sliderYmin; + nsliderYpos += g_sliderYmin; } if (nMissing) { - n = InvD[ino].FirstDisp - tMissing*InvD[ino].NoofHicons; - for (i = 0; i <= nMissing; i++, n += InvD[ino].NoofHicons) { - slideStuff[i].n = n; - slideStuff[i].y = (i*slideRange/nMissing) + sliderYmin; + n = g_InvD[g_ino].FirstDisp - tMissing*g_InvD[g_ino].NoofHicons; + for (i = 0; i <= nMissing; i++, n += g_InvD[g_ino].NoofHicons) { + g_slideStuff[i].n = n; + g_slideStuff[i].y = (i*slideRange/nMissing) + g_sliderYmin; } - if (slideStuff[0].n < 0) - slideStuff[0].n = 0; + if (g_slideStuff[0].n < 0) + g_slideStuff[0].n = 0; assert(i < MAX_ININV + 1); - slideStuff[i].n = -1; + g_slideStuff[i].n = -1; } else { - slideStuff[0].n = 0; - slideStuff[0].y = sliderYmin; - slideStuff[1].n = -1; + g_slideStuff[0].n = 0; + g_slideStuff[0].y = g_sliderYmin; + g_slideStuff[1].n = -1; } - if (nsliderYpos != sliderYpos) { - MultiMoveRelXY(SlideObject, 0, nsliderYpos - sliderYpos); - sliderYpos = nsliderYpos; + if (nsliderYpos != g_sliderYpos) { + MultiMoveRelXY(g_SlideObject, 0, nsliderYpos - g_sliderYpos); + g_sliderYpos = nsliderYpos; } } @@ -2580,26 +2569,26 @@ static void FillInInventory() { DumpIconArray(); - if (InvDragging != ID_SLIDE) + if (g_InvDragging != ID_SLIDE) AdjustTop(); // Set up slideStuff[] - Index = InvD[ino].FirstDisp; // Start from first displayed object + Index = g_InvD[g_ino].FirstDisp; // Start from first displayed object n = 0; ypos = START_ICONY; // Y-offset of first display row - for (row = 0; row < InvD[ino].NoofVicons; row++, ypos += ITEM_HEIGHT + 1) { + for (row = 0; row < g_InvD[g_ino].NoofVicons; row++, ypos += ITEM_HEIGHT + 1) { xpos = START_ICONX; // X-offset of first display column - for (col = 0; col < InvD[ino].NoofHicons; col++) { - if (Index >= InvD[ino].NoofItems) + for (col = 0; col < g_InvD[g_ino].NoofHicons; col++) { + if (Index >= g_InvD[g_ino].NoofItems) break; - else if (InvD[ino].contents[Index] != HeldItem) { + else if (g_InvD[g_ino].contents[Index] != g_heldItem) { // Create a display object and position it - iconArray[n] = AddInvObject(InvD[ino].contents[Index], &pfr, &pfilm); - MultiSetAniXY(iconArray[n], InvD[ino].inventoryX + xpos , InvD[ino].inventoryY + ypos); - MultiSetZPosition(iconArray[n], Z_INV_ICONS); + g_iconArray[n] = AddInvObject(g_InvD[g_ino].contents[Index], &pfr, &pfilm); + MultiSetAniXY(g_iconArray[n], g_InvD[g_ino].inventoryX + xpos , g_InvD[g_ino].inventoryY + ypos); + MultiSetZPosition(g_iconArray[n], Z_INV_ICONS); - InitStepAnimScript(&iconAnims[n], iconArray[n], FROM_LE_32(pfr->script), ONE_SECOND / FROM_LE_32(pfilm->frate)); + InitStepAnimScript(&g_iconAnims[n], g_iconArray[n], FROM_LE_32(pfr->script), ONE_SECOND / FROM_LE_32(pfilm->frate)); n++; } @@ -2617,16 +2606,16 @@ enum {FROM_HANDLE, FROM_STRING}; */ static void AddBackground(OBJECT **rect, OBJECT **title, int extraH, int extraV, int textFrom) { // Why not 2 ???? - int width = TLwidth + extraH + TRwidth + NM_BG_SIZ_X; - int height = TLheight + extraV + BLheight + NM_BG_SIZ_Y; + int width = g_TLwidth + extraH + g_TRwidth + NM_BG_SIZ_X; + int height = g_TLheight + extraV + g_BLheight + NM_BG_SIZ_Y; // Create a rectangle object - RectObject = *rect = TranslucentObject(width, height); + g_RectObject = *rect = TranslucentObject(width, height); // add it to display list and position it MultiInsertObject(GetPlayfieldList(FIELD_STATUS), *rect); - MultiSetAniXY(*rect, InvD[ino].inventoryX + NM_BG_POS_X, - InvD[ino].inventoryY + NM_BG_POS_Y); + MultiSetAniXY(*rect, g_InvD[g_ino].inventoryX + NM_BG_POS_X, + g_InvD[g_ino].inventoryY + NM_BG_POS_Y); MultiSetZPosition(*rect, Z_INV_BRECT); if (title == NULL) @@ -2634,16 +2623,16 @@ static void AddBackground(OBJECT **rect, OBJECT **title, int extraH, int extraV, // Create text object using title string if (textFrom == FROM_HANDLE) { - LoadStringRes(InvD[ino].hInvTitle, TextBufferAddr(), TBUFSZ); + LoadStringRes(g_InvD[g_ino].hInvTitle, TextBufferAddr(), TBUFSZ); *title = ObjectTextOut(GetPlayfieldList(FIELD_STATUS), TextBufferAddr(), 0, - InvD[ino].inventoryX + width/2, InvD[ino].inventoryY + M_TOFF, + g_InvD[g_ino].inventoryX + width/2, g_InvD[g_ino].inventoryY + M_TOFF, GetTagFontHandle(), TXT_CENTER); assert(*title); // Inventory title string produced NULL text MultiSetZPosition(*title, Z_INV_HTEXT); } else if (textFrom == FROM_STRING && cd.ixHeading != NO_HEADING) { - LoadStringRes(configStrings[cd.ixHeading], TextBufferAddr(), TBUFSZ); + LoadStringRes(g_configStrings[cd.ixHeading], TextBufferAddr(), TBUFSZ); *title = ObjectTextOut(GetPlayfieldList(FIELD_STATUS), TextBufferAddr(), 0, - InvD[ino].inventoryX + width/2, InvD[ino].inventoryY + M_TOFF, + g_InvD[g_ino].inventoryX + width/2, g_InvD[g_ino].inventoryY + M_TOFF, GetTagFontHandle(), TXT_CENTER); assert(*title); // Inventory title string produced NULL text MultiSetZPosition(*title, Z_INV_HTEXT); @@ -2661,13 +2650,13 @@ static void AddBackground(OBJECT **rect, int extraH, int extraV) { * Adds a title for a dialog */ static void AddTitle(POBJECT *title, int extraH) { - int width = TLwidth + extraH + TRwidth + NM_BG_SIZ_X; + int width = g_TLwidth + extraH + g_TRwidth + NM_BG_SIZ_X; // Create text object using title string - if (InvD[ino].hInvTitle != (SCNHANDLE)NO_HEADING) { - LoadStringRes(InvD[ino].hInvTitle, TextBufferAddr(), TBUFSZ); + if (g_InvD[g_ino].hInvTitle != (SCNHANDLE)NO_HEADING) { + LoadStringRes(g_InvD[g_ino].hInvTitle, TextBufferAddr(), TBUFSZ); *title = ObjectTextOut(GetPlayfieldList(FIELD_STATUS), TextBufferAddr(), 0, - InvD[ino].inventoryX + (width/2)+NM_BG_POS_X, InvD[ino].inventoryY + NM_TOFF, + g_InvD[g_ino].inventoryX + (width/2)+NM_BG_POS_X, g_InvD[g_ino].inventoryY + NM_TOFF, GetTagFontHandle(), TXT_CENTER, 0); assert(*title); MultiSetZPosition(*title, Z_INV_HTEXT); @@ -2691,13 +2680,13 @@ static OBJECT *AddObject(const FREEL *pfreel, int num) { // Horrible bodge involving global variables to save // width and/or height of some window frame components - if (num == TL) { - TLwidth = FROM_LE_16(pim->imgWidth); - TLheight = FROM_LE_16(pim->imgHeight) & ~C16_FLAG_MASK; - } else if (num == TR) { - TRwidth = FROM_LE_16(pim->imgWidth); - } else if (num == BL) { - BLheight = FROM_LE_16(pim->imgHeight) & ~C16_FLAG_MASK; + if (num == g_TL) { + g_TLwidth = FROM_LE_16(pim->imgWidth); + g_TLheight = FROM_LE_16(pim->imgHeight) & ~C16_FLAG_MASK; + } else if (num == g_TR) { + g_TRwidth = FROM_LE_16(pim->imgWidth); + } else if (num == g_BL) { + g_BLheight = FROM_LE_16(pim->imgHeight) & ~C16_FLAG_MASK; } // Set up and insert the multi-object @@ -2712,9 +2701,9 @@ static OBJECT *AddObject(const FREEL *pfreel, int num) { */ static void AddSlider(OBJECT **slide, const FILM *pfilm) { - SlideObject = *slide = AddObject(&pfilm->reels[IX_SLIDE], -1); - MultiSetAniXY(*slide, MultiRightmost(RectObject) + (TinselV2 ? NM_SLX : -M_SXOFF + 2) - 1, - InvD[ino].inventoryY + sliderYpos); + g_SlideObject = *slide = AddObject(&pfilm->reels[IX_SLIDE], -1); + MultiSetAniXY(*slide, MultiRightmost(g_RectObject) + (TinselV2 ? NM_SLX : -M_SXOFF + 2) - 1, + g_InvD[g_ino].inventoryY + g_sliderYpos); MultiSetZPosition(*slide, Z_INV_MFRAME); } @@ -2722,8 +2711,8 @@ static void AddSlider(OBJECT **slide, const FILM *pfilm) { * Display a box with some text in it. */ static void AddBox(int *pi, const int i) { - int x = InvD[ino].inventoryX + cd.box[i].xpos; - int y = InvD[ino].inventoryY + cd.box[i].ypos; + int x = g_InvD[g_ino].inventoryX + cd.box[i].xpos; + int y = g_InvD[g_ino].inventoryY + cd.box[i].ypos; int *pival = cd.box[i].ival; int xdisp; const FILM *pFilm; @@ -2735,11 +2724,11 @@ static void AddBox(int *pi, const int i) { break; // Give us a box - iconArray[*pi] = RectangleObject(BgPal(), TinselV2 ? BoxColor() : COL_BOX, + g_iconArray[*pi] = RectangleObject(BgPal(), TinselV2 ? BoxColor() : COL_BOX, cd.box[i].w, cd.box[i].h); - MultiInsertObject(GetPlayfieldList(FIELD_STATUS), iconArray[*pi]); - MultiSetAniXY(iconArray[*pi], x, y); - MultiSetZPosition(iconArray[*pi], Z_INV_BRECT + 1); + MultiInsertObject(GetPlayfieldList(FIELD_STATUS), g_iconArray[*pi]); + MultiSetAniXY(g_iconArray[*pi], x, y); + MultiSetZPosition(g_iconArray[*pi], Z_INV_BRECT + 1); *pi += 1; // Stick in the text @@ -2747,14 +2736,14 @@ static void AddBox(int *pi, const int i) { (!TinselV2 && (cd.box[i].ixText == USE_POINTER))) { if (cd.box[i].boxText != NULL) { if (cd.box[i].boxType == RGROUP) { - iconArray[*pi] = ObjectTextOut(GetPlayfieldList(FIELD_STATUS), cd.box[i].boxText, 0, + g_iconArray[*pi] = ObjectTextOut(GetPlayfieldList(FIELD_STATUS), cd.box[i].boxText, 0, #ifdef JAPAN x + 2, y+2, GetTagFontHandle(), 0); #else x + 2, y + TYOFF, GetTagFontHandle(), 0); #endif } else { - iconArray[*pi] = ObjectTextOut(GetPlayfieldList(FIELD_STATUS), cd.box[i].boxText, 0, + g_iconArray[*pi] = ObjectTextOut(GetPlayfieldList(FIELD_STATUS), cd.box[i].boxText, 0, #ifdef JAPAN // Note: it never seems to go here! x + cd.box[i].w/2, y+2, GetTagFontHandle(), TXT_CENTER); @@ -2763,7 +2752,7 @@ static void AddBox(int *pi, const int i) { #endif } - MultiSetZPosition(iconArray[*pi], Z_INV_ITEXT); + MultiSetZPosition(g_iconArray[*pi], Z_INV_ITEXT); *pi += 1; } } else { @@ -2775,61 +2764,61 @@ static void AddBox(int *pi, const int i) { LoadStringRes(cd.box[i].ixText, TextBufferAddr(), TBUFSZ); } } else { - LoadStringRes(configStrings[cd.box[i].ixText], TextBufferAddr(), TBUFSZ); + LoadStringRes(g_configStrings[cd.box[i].ixText], TextBufferAddr(), TBUFSZ); assert(cd.box[i].boxType != RGROUP); // You'll need to add some code! } if (TinselV2 && (cd.box[i].boxType == RGROUP)) - iconArray[*pi] = ObjectTextOut(GetPlayfieldList(FIELD_STATUS), TextBufferAddr(), + g_iconArray[*pi] = ObjectTextOut(GetPlayfieldList(FIELD_STATUS), TextBufferAddr(), 0, x + 2, y + TYOFF, GetTagFontHandle(), 0, 0); else - iconArray[*pi] = ObjectTextOut(GetPlayfieldList(FIELD_STATUS), + g_iconArray[*pi] = ObjectTextOut(GetPlayfieldList(FIELD_STATUS), TextBufferAddr(), 0, #ifdef JAPAN x + cd.box[i].w/2, y+2, GetTagFontHandle(), TXT_CENTER); #else x + cd.box[i].w / 2, y + TYOFF, GetTagFontHandle(), TXT_CENTER); #endif - MultiSetZPosition(iconArray[*pi], Z_INV_ITEXT); + MultiSetZPosition(g_iconArray[*pi], Z_INV_ITEXT); *pi += 1; } break; case AAGBUT: case ARSGBUT: - pFilm = (const FILM *)LockMem(hWinParts); + pFilm = (const FILM *)LockMem(g_hWinParts); - iconArray[*pi] = AddObject(&pFilm->reels[cd.box[i].bi + NORMGRAPH], -1); - MultiSetAniXY(iconArray[*pi], x, y); - MultiSetZPosition(iconArray[*pi], Z_INV_BRECT + 1); + g_iconArray[*pi] = AddObject(&pFilm->reels[cd.box[i].bi + NORMGRAPH], -1); + MultiSetAniXY(g_iconArray[*pi], x, y); + MultiSetZPosition(g_iconArray[*pi], Z_INV_BRECT + 1); *pi += 1; break; case FRGROUP: - assert(flagFilm != 0); // Language flags not declared! + assert(g_flagFilm != 0); // Language flags not declared! - pFilm = (const FILM *)LockMem(flagFilm); + pFilm = (const FILM *)LockMem(g_flagFilm); if (_vm->_config->_isAmericanEnglishVersion && cd.box[i].bi == FIX_UK) cd.box[i].bi = FIX_USA; - iconArray[*pi] = AddObject(&pFilm->reels[cd.box[i].bi], -1); - MultiSetAniXY(iconArray[*pi], x, y); - MultiSetZPosition(iconArray[*pi], Z_INV_BRECT+2); + g_iconArray[*pi] = AddObject(&pFilm->reels[cd.box[i].bi], -1); + MultiSetAniXY(g_iconArray[*pi], x, y); + MultiSetZPosition(g_iconArray[*pi], Z_INV_BRECT+2); *pi += 1; break; case FLIP: - pFilm = (const FILM *)LockMem(hWinParts); + pFilm = (const FILM *)LockMem(g_hWinParts); if (*pival) - iconArray[*pi] = AddObject(&pFilm->reels[cd.box[i].bi], -1); + g_iconArray[*pi] = AddObject(&pFilm->reels[cd.box[i].bi], -1); else - iconArray[*pi] = AddObject(&pFilm->reels[cd.box[i].bi+1], -1); - MultiSetAniXY(iconArray[*pi], x, y); - MultiSetZPosition(iconArray[*pi], Z_INV_BRECT+1); + g_iconArray[*pi] = AddObject(&pFilm->reels[cd.box[i].bi+1], -1); + MultiSetAniXY(g_iconArray[*pi], x, y); + MultiSetZPosition(g_iconArray[*pi], Z_INV_BRECT+1); *pi += 1; // Stick in the text @@ -2838,23 +2827,23 @@ static void AddBox(int *pi, const int i) { LoadStringRes(SysString(cd.box[i].ixText), TextBufferAddr(), TBUFSZ); } else { assert(cd.box[i].ixText != USE_POINTER); - LoadStringRes(configStrings[cd.box[i].ixText], TextBufferAddr(), TBUFSZ); + LoadStringRes(g_configStrings[cd.box[i].ixText], TextBufferAddr(), TBUFSZ); } - iconArray[*pi] = ObjectTextOut(GetPlayfieldList(FIELD_STATUS), + g_iconArray[*pi] = ObjectTextOut(GetPlayfieldList(FIELD_STATUS), TextBufferAddr(), 0, x + MDTEXT_XOFF, y + MDTEXT_YOFF, GetTagFontHandle(), TXT_RIGHT); - MultiSetZPosition(iconArray[*pi], Z_INV_ITEXT); + MultiSetZPosition(g_iconArray[*pi], Z_INV_ITEXT); *pi += 1; break; case TOGGLE: case TOGGLE1: case TOGGLE2: - pFilm = (const FILM *)LockMem(hWinParts); + pFilm = (const FILM *)LockMem(g_hWinParts); cd.box[i].bi = *pival ? IX_TICK1 : IX_CROSS1; - iconArray[*pi] = AddObject(&pFilm->reels[cd.box[i].bi + NORMGRAPH], -1); - MultiSetAniXY(iconArray[*pi], x, y); - MultiSetZPosition(iconArray[*pi], Z_INV_BRECT+1); + g_iconArray[*pi] = AddObject(&pFilm->reels[cd.box[i].bi + NORMGRAPH], -1); + MultiSetAniXY(g_iconArray[*pi], x, y); + MultiSetZPosition(g_iconArray[*pi], Z_INV_BRECT+1); *pi += 1; // Stick in the text @@ -2863,39 +2852,39 @@ static void AddBox(int *pi, const int i) { LoadStringRes(SysString(cd.box[i].ixText), TextBufferAddr(), TBUFSZ); } else { assert(cd.box[i].ixText != USE_POINTER); - LoadStringRes(configStrings[cd.box[i].ixText], TextBufferAddr(), TBUFSZ); + LoadStringRes(g_configStrings[cd.box[i].ixText], TextBufferAddr(), TBUFSZ); } if (cd.box[i].boxType == TOGGLE2) { - iconArray[*pi] = ObjectTextOut(GetPlayfieldList(FIELD_STATUS), + g_iconArray[*pi] = ObjectTextOut(GetPlayfieldList(FIELD_STATUS), TextBufferAddr(), 0, x + cd.box[i].w / 2, y + TOG2_YOFF, GetTagFontHandle(), TXT_CENTER, 0); } else { - iconArray[*pi] = ObjectTextOut(GetPlayfieldList(FIELD_STATUS), + g_iconArray[*pi] = ObjectTextOut(GetPlayfieldList(FIELD_STATUS), TextBufferAddr(), 0, x + MDTEXT_XOFF, y + MDTEXT_YOFF, GetTagFontHandle(), TXT_RIGHT, 0); } - MultiSetZPosition(iconArray[*pi], Z_INV_ITEXT); + MultiSetZPosition(g_iconArray[*pi], Z_INV_ITEXT); *pi += 1; break; case SLIDER: - pFilm = (const FILM *)LockMem(hWinParts); + pFilm = (const FILM *)LockMem(g_hWinParts); xdisp = SLIDE_RANGE*(*pival)/cd.box[i].w; - iconArray[*pi] = AddObject(&pFilm->reels[IX_MDGROOVE], -1); - MultiSetAniXY(iconArray[*pi], x, y); - MultiSetZPosition(iconArray[*pi], Z_MDGROOVE); + g_iconArray[*pi] = AddObject(&pFilm->reels[IX_MDGROOVE], -1); + MultiSetAniXY(g_iconArray[*pi], x, y); + MultiSetZPosition(g_iconArray[*pi], Z_MDGROOVE); *pi += 1; - iconArray[*pi] = AddObject(&pFilm->reels[IX_MDSLIDER], -1); - MultiSetAniXY(iconArray[*pi], x+SLIDE_MINX+xdisp, y); - MultiSetZPosition(iconArray[*pi], Z_MDSLIDER); - assert(numMdSlides < MAXSLIDES); - mdSlides[numMdSlides].num = i; - mdSlides[numMdSlides].min = x + SLIDE_MINX; - mdSlides[numMdSlides].max = x + SLIDE_MAXX; - mdSlides[numMdSlides++].obj = iconArray[*pi]; + g_iconArray[*pi] = AddObject(&pFilm->reels[IX_MDSLIDER], -1); + MultiSetAniXY(g_iconArray[*pi], x+SLIDE_MINX+xdisp, y); + MultiSetZPosition(g_iconArray[*pi], Z_MDSLIDER); + assert(g_numMdSlides < MAXSLIDES); + g_mdSlides[g_numMdSlides].num = i; + g_mdSlides[g_numMdSlides].min = x + SLIDE_MINX; + g_mdSlides[g_numMdSlides].max = x + SLIDE_MAXX; + g_mdSlides[g_numMdSlides++].obj = g_iconArray[*pi]; *pi += 1; // Stick in the text @@ -2904,55 +2893,55 @@ static void AddBox(int *pi, const int i) { LoadStringRes(SysString(cd.box[i].ixText), TextBufferAddr(), TBUFSZ); } else { assert(cd.box[i].ixText != USE_POINTER); - LoadStringRes(configStrings[cd.box[i].ixText], TextBufferAddr(), TBUFSZ); + LoadStringRes(g_configStrings[cd.box[i].ixText], TextBufferAddr(), TBUFSZ); } - iconArray[*pi] = ObjectTextOut(GetPlayfieldList(FIELD_STATUS), + g_iconArray[*pi] = ObjectTextOut(GetPlayfieldList(FIELD_STATUS), TextBufferAddr(), 0, x+MDTEXT_XOFF, y+MDTEXT_YOFF, GetTagFontHandle(), TXT_RIGHT); - MultiSetZPosition(iconArray[*pi], Z_INV_ITEXT); + MultiSetZPosition(g_iconArray[*pi], Z_INV_ITEXT); *pi += 1; break; case ROTATE: - pFilm = (const FILM *)LockMem(hWinParts); + pFilm = (const FILM *)LockMem(g_hWinParts); // Left one - if (!bNoLanguage) { - iconArray[*pi] = AddObject(&pFilm->reels[IX2_LEFT1], -1); - MultiSetAniXY(iconArray[*pi], x-ROTX1, y); - MultiSetZPosition(iconArray[*pi], Z_INV_BRECT + 1); + if (!g_bNoLanguage) { + g_iconArray[*pi] = AddObject(&pFilm->reels[IX2_LEFT1], -1); + MultiSetAniXY(g_iconArray[*pi], x-ROTX1, y); + MultiSetZPosition(g_iconArray[*pi], Z_INV_BRECT + 1); *pi += 1; // Right one - iconArray[*pi] = AddObject( &pFilm->reels[IX2_RIGHT1], -1); - MultiSetAniXY(iconArray[*pi], x + ROTX1, y); - MultiSetZPosition(iconArray[*pi], Z_INV_BRECT + 1); + g_iconArray[*pi] = AddObject( &pFilm->reels[IX2_RIGHT1], -1); + MultiSetAniXY(g_iconArray[*pi], x + ROTX1, y); + MultiSetZPosition(g_iconArray[*pi], Z_INV_BRECT + 1); *pi += 1; // Stick in the text assert(cd.box[i].textMethod == TM_INDEX); LoadStringRes(SysString(cd.box[i].ixText), TextBufferAddr(), TBUFSZ); - iconArray[*pi] = ObjectTextOut(GetPlayfieldList(FIELD_STATUS), + g_iconArray[*pi] = ObjectTextOut(GetPlayfieldList(FIELD_STATUS), TextBufferAddr(), 0, x + cd.box[i].w / 2, y + TOG2_YOFF, GetTagFontHandle(), TXT_CENTER, 0); - MultiSetZPosition(iconArray[*pi], Z_INV_ITEXT); + MultiSetZPosition(g_iconArray[*pi], Z_INV_ITEXT); *pi += 1; } // Current language's text - if (LanguageDesc(displayedLanguage) == 0) + if (LanguageDesc(g_displayedLanguage) == 0) break; - LoadStringRes(LanguageDesc(displayedLanguage), TextBufferAddr(), TBUFSZ); - iconArray[*pi] = ObjectTextOut(GetPlayfieldList(FIELD_STATUS), TextBufferAddr(), 0, + LoadStringRes(LanguageDesc(g_displayedLanguage), TextBufferAddr(), TBUFSZ); + g_iconArray[*pi] = ObjectTextOut(GetPlayfieldList(FIELD_STATUS), TextBufferAddr(), 0, x + cd.box[i].w / 2, y + ROT_YOFF, GetTagFontHandle(), TXT_CENTER, 0); - MultiSetZPosition(iconArray[*pi], Z_INV_ITEXT); + MultiSetZPosition(g_iconArray[*pi], Z_INV_ITEXT); *pi += 1; // Current language's flag - pFilm = (const FILM *)LockMem(LanguageFlag(displayedLanguage)); - iconArray[*pi] = AddObject(&pFilm->reels[0], -1); - MultiSetAniXY(iconArray[*pi], x + FLAGX, y + FLAGY); - MultiSetZPosition(iconArray[*pi], Z_INV_BRECT + 1); + pFilm = (const FILM *)LockMem(LanguageFlag(g_displayedLanguage)); + g_iconArray[*pi] = AddObject(&pFilm->reels[0], -1); + MultiSetAniXY(g_iconArray[*pi], x + FLAGX, y + FLAGY); + MultiSetZPosition(g_iconArray[*pi], Z_INV_BRECT + 1); *pi += 1; break; } @@ -2965,7 +2954,7 @@ static void AddBoxes(bool bPosnSlide) { int objCount = NUMHL; // Object count - allow for HL1, HL2 etc. DumpIconArray(); - numMdSlides = 0; + g_numMdSlides = 0; for (int i = 0; i < cd.NumBoxes; i++) { AddBox(&objCount, i); @@ -2973,32 +2962,32 @@ static void AddBoxes(bool bPosnSlide) { if (cd.bExtraWin) { if (bPosnSlide && !TinselV2) - sliderYpos = sliderYmin + (cd.extraBase*(sliderYmax-sliderYmin))/(MAX_SAVED_FILES-NUM_RGROUP_BOXES); + g_sliderYpos = g_sliderYmin + (cd.extraBase*(g_sliderYmax-g_sliderYmin))/(MAX_SAVED_FILES-NUM_RGROUP_BOXES); else if (bPosnSlide) { // Tinsel 2 bPosnSlide code - int lastY = sliderYpos; + int lastY = g_sliderYpos; if (cd.box == loadBox || cd.box == saveBox) - sliderYpos = sliderYmin + (cd.extraBase * (sliderRange)) / + g_sliderYpos = g_sliderYmin + (cd.extraBase * (sliderRange)) / (MAX_SAVED_FILES - NUM_RGROUP_BOXES); else if (cd.box == hopperBox1) { - if (numScenes <= NUM_RGROUP_BOXES) - sliderYpos = sliderYmin; + if (g_numScenes <= NUM_RGROUP_BOXES) + g_sliderYpos = g_sliderYmin; else - sliderYpos = sliderYmin + (cd.extraBase*(sliderRange))/(numScenes-NUM_RGROUP_BOXES); + g_sliderYpos = g_sliderYmin + (cd.extraBase*(sliderRange))/(g_numScenes-NUM_RGROUP_BOXES); } else if (cd.box == hopperBox2) { - if (numEntries <= NUM_RGROUP_BOXES) - sliderYpos = sliderYmin; + if (g_numEntries <= NUM_RGROUP_BOXES) + g_sliderYpos = g_sliderYmin; else - sliderYpos = sliderYmin + (cd.extraBase * (sliderRange)) / - (numEntries-NUM_RGROUP_BOXES); + g_sliderYpos = g_sliderYmin + (cd.extraBase * (sliderRange)) / + (g_numEntries-NUM_RGROUP_BOXES); } - MultiMoveRelXY(SlideObject, 0, sliderYpos - lastY); + MultiMoveRelXY(g_SlideObject, 0, g_sliderYpos - lastY); } if (!TinselV2) - MultiSetAniXY(SlideObject, InvD[ino].inventoryX + 24 + 179, sliderYpos); + MultiSetAniXY(g_SlideObject, g_InvD[g_ino].inventoryX + 24 + 179, g_sliderYpos); } assert(objCount < MAX_ICONS); // added too many icons @@ -3008,8 +2997,8 @@ static void AddBoxes(bool bPosnSlide) { * Display the scroll bar slider. */ static void AddEWSlider(OBJECT **slide, const FILM *pfilm) { - SlideObject = *slide = AddObject(&pfilm->reels[IX_SLIDE], -1); - MultiSetAniXY(*slide, InvD[ino].inventoryX + 24 + 127, sliderYpos); + g_SlideObject = *slide = AddObject(&pfilm->reels[IX_SLIDE], -1); + MultiSetAniXY(*slide, g_InvD[g_ino].inventoryX + 24 + 127, g_sliderYpos); MultiSetZPosition(*slide, Z_INV_MFRAME); } @@ -3021,7 +3010,7 @@ static int AddExtraWindow(int x, int y, OBJECT **retObj) { const FILM *pfilm; // Get the frame's data - pfilm = (const FILM *)LockMem(hWinParts); + pfilm = (const FILM *)LockMem(g_hWinParts); x += TinselV2 ? 30 : 20; y += TinselV2 ? 38 : 24; @@ -3032,56 +3021,56 @@ static int AddExtraWindow(int x, int y, OBJECT **retObj) { MultiSetZPosition(retObj[n], Z_INV_MFRAME); n++; retObj[n] = AddObject(&pfilm->reels[IX_NTR], -1); // Top right - MultiSetAniXY(retObj[n], x + (TinselV2 ? TLwidth + 312 : 152), y); + MultiSetAniXY(retObj[n], x + (TinselV2 ? g_TLwidth + 312 : 152), y); MultiSetZPosition(retObj[n], Z_INV_MFRAME); n++; retObj[n] = AddObject(&pfilm->reels[IX_BL], -1); // Bottom left - MultiSetAniXY(retObj[n], x, y + (TinselV2 ? TLheight + 208 : 124)); + MultiSetAniXY(retObj[n], x, y + (TinselV2 ? g_TLheight + 208 : 124)); MultiSetZPosition(retObj[n], Z_INV_MFRAME); n++; retObj[n] = AddObject(&pfilm->reels[IX_BR], -1); // Bottom right - MultiSetAniXY(retObj[n], x + (TinselV2 ? TLwidth + 312 : 152), - y + (TinselV2 ? TLheight + 208 : 124)); + MultiSetAniXY(retObj[n], x + (TinselV2 ? g_TLwidth + 312 : 152), + y + (TinselV2 ? g_TLheight + 208 : 124)); MultiSetZPosition(retObj[n], Z_INV_MFRAME); n++; // Draw the edges retObj[n] = AddObject(&pfilm->reels[IX_H156], -1); // Top - MultiSetAniXY(retObj[n], x + (TinselV2 ? TLwidth : 6), y + NM_TBT); + MultiSetAniXY(retObj[n], x + (TinselV2 ? g_TLwidth : 6), y + NM_TBT); MultiSetZPosition(retObj[n], Z_INV_MFRAME); n++; retObj[n] = AddObject(&pfilm->reels[IX_H156], -1); // Bottom - MultiSetAniXY(retObj[n], x + (TinselV2 ? TLwidth : 6), y + - (TinselV2 ? TLheight + 208 + BLheight + NM_BSY : 143)); + MultiSetAniXY(retObj[n], x + (TinselV2 ? g_TLwidth : 6), y + + (TinselV2 ? g_TLheight + 208 + g_BLheight + NM_BSY : 143)); MultiSetZPosition(retObj[n], Z_INV_MFRAME); n++; retObj[n] = AddObject(&pfilm->reels[IX_V104], -1); // Left - MultiSetAniXY(retObj[n], x + NM_LSX, y + (TinselV2 ? TLheight : 20)); + MultiSetAniXY(retObj[n], x + NM_LSX, y + (TinselV2 ? g_TLheight : 20)); MultiSetZPosition(retObj[n], Z_INV_MFRAME); n++; retObj[n] = AddObject(&pfilm->reels[IX_V104], -1); // Right 1 - MultiSetAniXY(retObj[n], x + (TinselV2 ? TLwidth + 312 + TRwidth + NM_RSX : 179), - y + (TinselV2 ? TLheight : 20)); + MultiSetAniXY(retObj[n], x + (TinselV2 ? g_TLwidth + 312 + g_TRwidth + NM_RSX : 179), + y + (TinselV2 ? g_TLheight : 20)); MultiSetZPosition(retObj[n], Z_INV_MFRAME); n++; retObj[n] = AddObject(&pfilm->reels[IX_V104], -1); // Right 2 - MultiSetAniXY(retObj[n], x + (TinselV2 ? TLwidth + 312 + TRwidth + NM_SBL : 188), - y + (TinselV2 ? TLheight : 20)); + MultiSetAniXY(retObj[n], x + (TinselV2 ? g_TLwidth + 312 + g_TRwidth + NM_SBL : 188), + y + (TinselV2 ? g_TLheight : 20)); MultiSetZPosition(retObj[n], Z_INV_MFRAME); n++; if (TinselV2) { - sliderYpos = sliderYmin = y + 27; - sliderYmax = y + 273; - - retObj[n++] = SlideObject = AddObject( &pfilm->reels[IX_SLIDE], -1); - MultiSetAniXY(SlideObject, - x + TLwidth + 320 + TRwidth - NM_BG_POS_X + NM_BG_SIZ_X - 2, - sliderYpos); - MultiSetZPosition(SlideObject, Z_INV_MFRAME); + g_sliderYpos = g_sliderYmin = y + 27; + g_sliderYmax = y + 273; + + retObj[n++] = g_SlideObject = AddObject( &pfilm->reels[IX_SLIDE], -1); + MultiSetAniXY(g_SlideObject, + x + g_TLwidth + 320 + g_TRwidth - NM_BG_POS_X + NM_BG_SIZ_X - 2, + g_sliderYpos); + MultiSetZPosition(g_SlideObject, Z_INV_MFRAME); } else { - sliderYpos = sliderYmin = y + 9; - sliderYmax = y + 134; + g_sliderYpos = g_sliderYmin = y + 9; + g_sliderYmax = y + 134; AddEWSlider(&retObj[n++], pfilm); } @@ -3099,17 +3088,17 @@ static void ConstructInventory(InventoryType filling) { int eH, eV; // Extra width and height int n = 0; // Index into object array int zpos; // Z-position of frame - int invX = InvD[ino].inventoryX; - int invY = InvD[ino].inventoryY; + int invX = g_InvD[g_ino].inventoryX; + int invY = g_InvD[g_ino].inventoryY; OBJECT **retObj; const FILM *pfilm; // Select the object array to use if (filling == FULL || filling == CONF) { - retObj = objArray; // Standard window + retObj = g_objArray; // Standard window zpos = Z_INV_MFRAME; } else { - retObj = DobjArray; // Re-sizing window + retObj = g_DobjArray; // Re-sizing window zpos = Z_INV_RFRAME; } @@ -3122,83 +3111,83 @@ static void ConstructInventory(InventoryType filling) { } // Get the frame's data - pfilm = (const FILM *)LockMem(hWinParts); + pfilm = (const FILM *)LockMem(g_hWinParts); // Standard window is of granular dimensions if (filling == FULL) { // Round-up/down to nearest number of icons - if (SuppH > ITEM_WIDTH / 2) - InvD[ino].NoofHicons++; - if (SuppV > ITEM_HEIGHT / 2) - InvD[ino].NoofVicons++; - SuppH = SuppV = 0; + if (g_SuppH > ITEM_WIDTH / 2) + g_InvD[g_ino].NoofHicons++; + if (g_SuppV > ITEM_HEIGHT / 2) + g_InvD[g_ino].NoofVicons++; + g_SuppH = g_SuppV = 0; } // Extra width and height - eH = (InvD[ino].NoofHicons - 1) * (ITEM_WIDTH+I_SEPARATION) + SuppH; - eV = (InvD[ino].NoofVicons - 1) * (ITEM_HEIGHT+I_SEPARATION) + SuppV; + eH = (g_InvD[g_ino].NoofHicons - 1) * (ITEM_WIDTH+I_SEPARATION) + g_SuppH; + eV = (g_InvD[g_ino].NoofVicons - 1) * (ITEM_HEIGHT+I_SEPARATION) + g_SuppV; // Which window frame corners to use - if (TinselV2 && (ino == INV_CONV)) { - TL = IX_TL; - TR = IX2_TR4; - BL = IX_BL; - BR = IX_RBR; - } else if ((filling == FULL) && (ino != INV_CONV)) { - TL = IX_TL; - TR = IX_TR; - BL = IX_BL; - BR = IX_BR; + if (TinselV2 && (g_ino == INV_CONV)) { + g_TL = IX_TL; + g_TR = IX2_TR4; + g_BL = IX_BL; + g_BR = IX_RBR; + } else if ((filling == FULL) && (g_ino != INV_CONV)) { + g_TL = IX_TL; + g_TR = IX_TR; + g_BL = IX_BL; + g_BR = IX_BR; } else { - TL = IX_RTL; - TR = IX_RTR; - BL = IX_BL; - BR = IX_RBR; + g_TL = IX_RTL; + g_TR = IX_RTR; + g_BL = IX_BL; + g_BR = IX_RBR; } // Draw the four corners - retObj[n] = AddObject(&pfilm->reels[TL], TL); + retObj[n] = AddObject(&pfilm->reels[g_TL], g_TL); MultiSetAniXY(retObj[n], invX, invY); MultiSetZPosition(retObj[n], zpos); n++; - retObj[n] = AddObject(&pfilm->reels[TR], TR); - MultiSetAniXY(retObj[n], invX + TLwidth + eH, invY); + retObj[n] = AddObject(&pfilm->reels[g_TR], g_TR); + MultiSetAniXY(retObj[n], invX + g_TLwidth + eH, invY); MultiSetZPosition(retObj[n], zpos); n++; - retObj[n] = AddObject(&pfilm->reels[BL], BL); - MultiSetAniXY(retObj[n], invX, invY + TLheight + eV); + retObj[n] = AddObject(&pfilm->reels[g_BL], g_BL); + MultiSetAniXY(retObj[n], invX, invY + g_TLheight + eV); MultiSetZPosition(retObj[n], zpos); n++; - retObj[n] = AddObject(&pfilm->reels[BR], BR); - MultiSetAniXY(retObj[n], invX + TLwidth + eH, invY + TLheight + eV); + retObj[n] = AddObject(&pfilm->reels[g_BR], g_BR); + MultiSetAniXY(retObj[n], invX + g_TLwidth + eH, invY + g_TLheight + eV); MultiSetZPosition(retObj[n], zpos); n++; // Draw extra Top and bottom parts - if (InvD[ino].NoofHicons > 1) { + if (g_InvD[g_ino].NoofHicons > 1) { // Top side - retObj[n] = AddObject(&pfilm->reels[hFillers[InvD[ino].NoofHicons-2]], -1); - MultiSetAniXY(retObj[n], invX + TLwidth, invY + NM_TBT); + retObj[n] = AddObject(&pfilm->reels[hFillers[g_InvD[g_ino].NoofHicons-2]], -1); + MultiSetAniXY(retObj[n], invX + g_TLwidth, invY + NM_TBT); MultiSetZPosition(retObj[n], zpos); n++; // Bottom of header box if (filling == FULL) { if (TinselV2) { - retObj[n] = AddObject(&pfilm->reels[hFillers[InvD[ino].NoofHicons-2]], -1); - MultiSetAniXY(retObj[n], invX + TLwidth, invY + NM_TBB); + retObj[n] = AddObject(&pfilm->reels[hFillers[g_InvD[g_ino].NoofHicons-2]], -1); + MultiSetAniXY(retObj[n], invX + g_TLwidth, invY + NM_TBB); MultiSetZPosition(retObj[n], zpos); n++; } else { - retObj[n] = AddObject(&pfilm->reels[hFillers[InvD[ino].NoofHicons-2]], -1); - MultiSetAniXY(retObj[n], invX + TLwidth, invY + M_TBB + 1); + retObj[n] = AddObject(&pfilm->reels[hFillers[g_InvD[g_ino].NoofHicons-2]], -1); + MultiSetAniXY(retObj[n], invX + g_TLwidth, invY + M_TBB + 1); MultiSetZPosition(retObj[n], zpos); n++; // Extra bits for conversation - hopefully temporary - if (ino == INV_CONV) { + if (g_ino == INV_CONV) { retObj[n] = AddObject(&pfilm->reels[IX_H26], -1); - MultiSetAniXY(retObj[n], invX + TLwidth - 2, invY + M_TBB + 1); + MultiSetAniXY(retObj[n], invX + g_TLwidth - 2, invY + M_TBB + 1); MultiSetZPosition(retObj[n], zpos); n++; @@ -3211,16 +3200,16 @@ static void ConstructInventory(InventoryType filling) { } // Bottom side - retObj[n] = AddObject(&pfilm->reels[hFillers[InvD[ino].NoofHicons-2]], -1); - MultiSetAniXY(retObj[n], invX + TLwidth, invY + TLheight + eV + BLheight + NM_BSY); + retObj[n] = AddObject(&pfilm->reels[hFillers[g_InvD[g_ino].NoofHicons-2]], -1); + MultiSetAniXY(retObj[n], invX + g_TLwidth, invY + g_TLheight + eV + g_BLheight + NM_BSY); MultiSetZPosition(retObj[n], zpos); n++; } - if (SuppH) { - int offx = TLwidth + eH - (TinselV2 ? ITEM_WIDTH + I_SEPARATION : 26); - if (offx < TLwidth) // Not too far! - offx = TLwidth; + if (g_SuppH) { + int offx = g_TLwidth + eH - (TinselV2 ? ITEM_WIDTH + I_SEPARATION : 26); + if (offx < g_TLwidth) // Not too far! + offx = g_TLwidth; // Top side extra retObj[n] = AddObject(&pfilm->reels[IX_H26], -1); @@ -3230,39 +3219,39 @@ static void ConstructInventory(InventoryType filling) { // Bottom side extra retObj[n] = AddObject(&pfilm->reels[IX_H26], -1); - MultiSetAniXY(retObj[n], invX + offx, invY + TLheight + eV + BLheight + NM_BSY); + MultiSetAniXY(retObj[n], invX + offx, invY + g_TLheight + eV + g_BLheight + NM_BSY); MultiSetZPosition(retObj[n], zpos); n++; } // Draw extra side parts - if (InvD[ino].NoofVicons > 1) { + if (g_InvD[g_ino].NoofVicons > 1) { // Left side - retObj[n] = AddObject(&pfilm->reels[vFillers[InvD[ino].NoofVicons-2]], -1); - MultiSetAniXY(retObj[n], invX + NM_LSX, invY + TLheight); + retObj[n] = AddObject(&pfilm->reels[vFillers[g_InvD[g_ino].NoofVicons-2]], -1); + MultiSetAniXY(retObj[n], invX + NM_LSX, invY + g_TLheight); MultiSetZPosition(retObj[n], zpos); n++; // Left side of scroll bar - if (filling == FULL && ino != INV_CONV) { - retObj[n] = AddObject(&pfilm->reels[vFillers[InvD[ino].NoofVicons-2]], -1); + if (filling == FULL && g_ino != INV_CONV) { + retObj[n] = AddObject(&pfilm->reels[vFillers[g_InvD[g_ino].NoofVicons-2]], -1); if (TinselV2) - MultiSetAniXY(retObj[n], invX + TLwidth + eH + TRwidth + NM_SBL, invY + TLheight); + MultiSetAniXY(retObj[n], invX + g_TLwidth + eH + g_TRwidth + NM_SBL, invY + g_TLheight); else - MultiSetAniXY(retObj[n], invX + TLwidth + eH + M_SBL + 1, invY + TLheight); + MultiSetAniXY(retObj[n], invX + g_TLwidth + eH + M_SBL + 1, invY + g_TLheight); MultiSetZPosition(retObj[n], zpos); n++; } // Right side - retObj[n] = AddObject(&pfilm->reels[vFillers[InvD[ino].NoofVicons-2]], -1); - MultiSetAniXY(retObj[n], invX + TLwidth + eH + TRwidth + NM_RSX, invY + TLheight); + retObj[n] = AddObject(&pfilm->reels[vFillers[g_InvD[g_ino].NoofVicons-2]], -1); + MultiSetAniXY(retObj[n], invX + g_TLwidth + eH + g_TRwidth + NM_RSX, invY + g_TLheight); MultiSetZPosition(retObj[n], zpos); n++; } - if (SuppV) { - int offy = TLheight + eV - (TinselV2 ? ITEM_HEIGHT + I_SEPARATION : 26); + if (g_SuppV) { + int offy = g_TLheight + eV - (TinselV2 ? ITEM_HEIGHT + I_SEPARATION : 26); int minAmount = TinselV2 ? 20 : 5; if (offy < minAmount) offy = minAmount; @@ -3275,7 +3264,7 @@ static void ConstructInventory(InventoryType filling) { // Right side extra retObj[n] = AddObject(&pfilm->reels[IX_V26], -1); - MultiSetAniXY(retObj[n], invX + TLwidth + eH + TRwidth + NM_RSX, invY + offy); + MultiSetAniXY(retObj[n], invX + g_TLwidth + eH + g_TRwidth + NM_RSX, invY + offy); MultiSetZPosition(retObj[n], zpos); n++; } @@ -3296,20 +3285,20 @@ static void ConstructInventory(InventoryType filling) { AddBackground(rect, title, eH, eV, FROM_HANDLE); } - if (ino == INV_CONV) { - SlideObject = NULL; + if (g_ino == INV_CONV) { + g_SlideObject = NULL; if (TinselV2) { // !!!!! MAGIC NUMBER ALERT !!!!! // Make sure it's big enough for the heading - if (MultiLeftmost(retObj[n-1]) < InvD[INV_CONV].inventoryX + 10) { - InvD[INV_CONV].NoofHicons++; + if (MultiLeftmost(retObj[n-1]) < g_InvD[INV_CONV].inventoryX + 10) { + g_InvD[INV_CONV].NoofHicons++; ConstructInventory(FULL); } } - } else if (InvD[ino].NoofItems > InvD[ino].NoofHicons*InvD[ino].NoofVicons) { - sliderYmin = TLheight - (TinselV2 ? 2 : 1); - sliderYmax = TLheight + eV + (TinselV2 ? 12 : 10); + } else if (g_InvD[g_ino].NoofItems > g_InvD[g_ino].NoofHicons*g_InvD[g_ino].NoofVicons) { + g_sliderYmin = g_TLheight - (TinselV2 ? 2 : 1); + g_sliderYmax = g_TLheight + eV + (TinselV2 ? 12 : 10); AddSlider(&retObj[n++], pfilm); } @@ -3333,7 +3322,7 @@ static void ConstructInventory(InventoryType filling) { assert(n < MAX_WCOMP); // added more parts than we can handle! // Reposition returns true if needs to move - if (InvD[ino].bMoveable && filling == FULL && RePosition()) { + if (g_InvD[g_ino].bMoveable && filling == FULL && RePosition()) { ConstructInventory(FULL); } } @@ -3348,32 +3337,32 @@ static bool RePosition() { int p; bool bMoveitMoveit = false; - assert(RectObject); // no recangle object! + assert(g_RectObject); // no recangle object! // Test for off-screen horizontally - p = MultiLeftmost(RectObject); + p = MultiLeftmost(g_RectObject); if (p > MAXLEFT) { // Too far to the right - InvD[ino].inventoryX += MAXLEFT - p; + g_InvD[g_ino].inventoryX += MAXLEFT - p; bMoveitMoveit = true; // I like to.... } else { // Too far to the left? - p = MultiRightmost(RectObject); + p = MultiRightmost(g_RectObject); if (p < MINRIGHT) { - InvD[ino].inventoryX += MINRIGHT - p; + g_InvD[g_ino].inventoryX += MINRIGHT - p; bMoveitMoveit = true; // I like to.... } } // Test for off-screen vertically - p = MultiHighest(RectObject); + p = MultiHighest(g_RectObject); if (p < MINTOP) { // Too high - InvD[ino].inventoryY += MINTOP - p; + g_InvD[g_ino].inventoryY += MINTOP - p; bMoveitMoveit = true; // I like to.... } else if (p > MAXTOP) { // Too low - InvD[ino].inventoryY += MAXTOP - p; + g_InvD[g_ino].inventoryY += MAXTOP - p; bMoveitMoveit = true; // I like to.... } @@ -3393,7 +3382,7 @@ static void AlterCursor(int num) { IMAGE *pim; // Get pointer to image - pim = GetImageFromFilm(hWinParts, num, &pfreel); + pim = GetImageFromFilm(g_hWinParts, num, &pfreel); // Poke in the background palette pim->hImgPal = TO_LE_32(BgPal()); @@ -3414,7 +3403,7 @@ static void InvCursor(InvCursorFN fn, int CurX, int CurY) { bool restoreMain = false; // If currently dragging, don't be messing about with the cursor shape - if (InvDragging != ID_NONE) + if (g_InvDragging != ID_NONE) return; switch (fn) { @@ -3427,7 +3416,7 @@ static void InvCursor(InvCursorFN fn, int CurX, int CurY) { area = InvArea(CurX, CurY); // Check for POINTED events - if (ino == INV_CONF) + if (g_ino == INV_CONF) InvBoxes(area == I_BODY, CurX, CurY); else InvLabels(area == I_BODY, CurX, CurY); @@ -3445,7 +3434,7 @@ static void InvCursor(InvCursorFN fn, int CurX, int CurY) { case I_TLEFT: case I_BRIGHT: - if (!InvD[ino].resizable) + if (!g_InvD[g_ino].resizable) restoreMain = true; else if (ICursor != IC_DR) { AlterCursor(IX_CURDD); @@ -3455,7 +3444,7 @@ static void InvCursor(InvCursorFN fn, int CurX, int CurY) { case I_TRIGHT: case I_BLEFT: - if (!InvD[ino].resizable) + if (!g_InvD[g_ino].resizable) restoreMain = true; else if (ICursor != IC_UR) { AlterCursor(IX_CURDU); @@ -3465,7 +3454,7 @@ static void InvCursor(InvCursorFN fn, int CurX, int CurY) { case I_TOP: case I_BOTTOM: - if (!InvD[ino].resizable) { + if (!g_InvD[g_ino].resizable) { restoreMain = true; break; } @@ -3477,7 +3466,7 @@ static void InvCursor(InvCursorFN fn, int CurX, int CurY) { case I_LEFT: case I_RIGHT: - if (!InvD[ino].resizable) + if (!g_InvD[g_ino].resizable) restoreMain = true; else if (ICursor != IC_LR) { AlterCursor(IX_CURLR); @@ -3516,7 +3505,7 @@ static void InvCursor(InvCursorFN fn, int CurX, int CurY) { extern void ConvAction(int index) { - assert(ino == INV_CONV); // not conv. window! + assert(g_ino == INV_CONV); // not conv. window! PMOVER pMover = TinselV2 ? GetMover(GetLeadId()) : NULL; switch (index) { @@ -3524,36 +3513,36 @@ extern void ConvAction(int index) { return; case INV_CLOSEICON: - thisIcon = -1; // Postamble + g_thisIcon = -1; // Postamble break; case INV_OPENICON: // Store the direction the lead character is facing in when the conversation starts if (TinselV2) - initialDirection = GetMoverDirection(pMover); - thisIcon = -2; // Preamble + g_initialDirection = GetMoverDirection(pMover); + g_thisIcon = -2; // Preamble break; default: - thisIcon = InvD[ino].contents[index]; + g_thisIcon = g_InvD[g_ino].contents[index]; break; } if (!TinselV2) - RunPolyTinselCode(thisConvPoly, CONVERSE, PLR_NOEVENT, true); + RunPolyTinselCode(g_thisConvPoly, CONVERSE, PLR_NOEVENT, true); else { // If the lead's direction has changed for any reason (such as having broken the // fourth wall and talked to the screen), reset back to the original direction DIRECTION currDirection = GetMoverDirection(pMover); - if (currDirection != initialDirection) { - SetMoverDirection(pMover, initialDirection); + if (currDirection != g_initialDirection) { + SetMoverDirection(pMover, g_initialDirection); SetMoverStanding(pMover); } - if (thisConvPoly != NOPOLY) - PolygonEvent(nullContext, thisConvPoly, CONVERSE, 0, false, 0); + if (g_thisConvPoly != NOPOLY) + PolygonEvent(nullContext, g_thisConvPoly, CONVERSE, 0, false, 0); else - ActorEvent(nullContext, thisConvActor, CONVERSE, false, 0); + ActorEvent(nullContext, g_thisConvActor, CONVERSE, false, 0); } } @@ -3566,18 +3555,18 @@ extern void ConvAction(int index) { * Note: ano may (will probably) be set when it's a polygon. */ extern void SetConvDetails(CONV_PARAM fn, HPOLYGON hPoly, int ano) { - thisConvFn = fn; - thisConvPoly = hPoly; - thisConvActor = ano; + g_thisConvFn = fn; + g_thisConvPoly = hPoly; + g_thisConvActor = ano; - bMoveOnUnHide = true; + g_bMoveOnUnHide = true; // Get the Actor Tag's or Tagged Actor's label for the conversation window title if (hPoly != NOPOLY) { int x, y; - GetTagTag(hPoly, &InvD[INV_CONV].hInvTitle, &x, &y); + GetTagTag(hPoly, &g_InvD[INV_CONV].hInvTitle, &x, &y); } else { - InvD[INV_CONV].hInvTitle = GetActorTagHandle(ano); + g_InvD[INV_CONV].hInvTitle = GetActorTagHandle(ano); } } @@ -3590,27 +3579,27 @@ extern void PermaConvIcon(int icon, bool bEnd) { int i; // See if it's already there - for (i = 0; i < numPermIcons; i++) { - if (permIcons[i] == icon) + for (i = 0; i < g_numPermIcons; i++) { + if (g_permIcons[i] == icon) break; } // Add it if it isn't already there - if (i == numPermIcons) { - assert(numPermIcons < MAX_PERMICONS); + if (i == g_numPermIcons) { + assert(g_numPermIcons < MAX_PERMICONS); - if (bEnd || !numEndIcons) { + if (bEnd || !g_numEndIcons) { // Add it at the end - permIcons[numPermIcons++] = icon; + g_permIcons[g_numPermIcons++] = icon; if (bEnd) - numEndIcons++; + g_numEndIcons++; } else { // Insert before end icons - memmove(&permIcons[numPermIcons-numEndIcons+1], - &permIcons[numPermIcons-numEndIcons], - numEndIcons * sizeof(int)); - permIcons[numPermIcons-numEndIcons] = icon; - numPermIcons++; + memmove(&g_permIcons[g_numPermIcons-g_numEndIcons+1], + &g_permIcons[g_numPermIcons-g_numEndIcons], + g_numEndIcons * sizeof(int)); + g_permIcons[g_numPermIcons-g_numEndIcons] = icon; + g_numPermIcons++; } } } @@ -3619,21 +3608,21 @@ extern void PermaConvIcon(int icon, bool bEnd) { extern void convPos(int fn) { if (fn == CONV_DEF) - InvD[INV_CONV].inventoryY = 8; + g_InvD[INV_CONV].inventoryY = 8; else if (fn == CONV_BOTTOM) - InvD[INV_CONV].inventoryY = 150; + g_InvD[INV_CONV].inventoryY = 150; } extern void ConvPoly(HPOLYGON hPoly) { - thisConvPoly = hPoly; + g_thisConvPoly = hPoly; } extern int GetIcon() { - return thisIcon; + return g_thisIcon; } extern void CloseDownConv() { - if (InventoryState == ACTIVE_INV && ino == INV_CONV) { + if (g_InventoryState == ACTIVE_INV && g_ino == INV_CONV) { KillInventory(); } } @@ -3642,43 +3631,43 @@ extern void HideConversation(bool bHide) { int aniX, aniY; int i; - if (InventoryState == ACTIVE_INV && ino == INV_CONV) { + if (g_InventoryState == ACTIVE_INV && g_ino == INV_CONV) { if (bHide) { // Move all the window and icons off-screen - for (i = 0; objArray[i] && i < MAX_WCOMP; i++) { - MultiAdjustXY(objArray[i], 2 * SCREEN_WIDTH, 0); + for (i = 0; g_objArray[i] && i < MAX_WCOMP; i++) { + MultiAdjustXY(g_objArray[i], 2 * SCREEN_WIDTH, 0); } - for (i = 0; iconArray[i] && i < MAX_ICONS; i++) { - MultiAdjustXY(iconArray[i], 2 * SCREEN_WIDTH, 0); + for (i = 0; g_iconArray[i] && i < MAX_ICONS; i++) { + MultiAdjustXY(g_iconArray[i], 2 * SCREEN_WIDTH, 0); } // Window is hidden - InventoryHidden = true; + g_InventoryHidden = true; // Remove any labels InvLabels(false, 0, 0); } else { // Window is not hidden - InventoryHidden = false; + g_InventoryHidden = false; - if (TinselV2 && ItemsChanged) + if (TinselV2 && g_ItemsChanged) // Just rebuild the whole thing ConstructInventory(FULL); else { // Move it all back on-screen - for (i = 0; objArray[i] && i < MAX_WCOMP; i++) { - MultiAdjustXY(objArray[i], -2 * SCREEN_WIDTH, 0); + for (i = 0; g_objArray[i] && i < MAX_WCOMP; i++) { + MultiAdjustXY(g_objArray[i], -2 * SCREEN_WIDTH, 0); } // Don't flash if items changed. If they have, will be redrawn anyway. - if (TinselV2 || !ItemsChanged) { - for (i = 0; iconArray[i] && i < MAX_ICONS; i++) { - MultiAdjustXY(iconArray[i], -2*SCREEN_WIDTH, 0); + if (TinselV2 || !g_ItemsChanged) { + for (i = 0; g_iconArray[i] && i < MAX_ICONS; i++) { + MultiAdjustXY(g_iconArray[i], -2*SCREEN_WIDTH, 0); } } } - if (TinselV2 && bMoveOnUnHide) { + if (TinselV2 && g_bMoveOnUnHide) { /* * First time, position it appropriately */ @@ -3686,17 +3675,17 @@ extern void HideConversation(bool bHide) { int x, y, deltay; // Only do it once per conversation - bMoveOnUnHide = false; + g_bMoveOnUnHide = false; // Current center of the window - left = MultiLeftmost(RectObject); - center = (MultiRightmost(RectObject) + left) / 2; + left = MultiLeftmost(g_RectObject); + center = (MultiRightmost(g_RectObject) + left) / 2; // Get the x-offset for the conversation window - if (thisConvActor) { + if (g_thisConvActor) { int Loffset, Toffset; - GetActorMidTop(thisConvActor, &x, &y); + GetActorMidTop(g_thisConvActor, &x, &y); PlayfieldGetPos(FIELD_WORLD, &Loffset, &Toffset); x -= Loffset; y -= Toffset; @@ -3706,19 +3695,19 @@ extern void HideConversation(bool bHide) { } // Save old y-position - deltay = InvD[INV_CONV].inventoryY; + deltay = g_InvD[INV_CONV].inventoryY; - switch (thisConvFn) { + switch (g_thisConvFn) { case CONV_TOP: - InvD[INV_CONV].inventoryY = SysVar(SV_CONV_TOPY); + g_InvD[INV_CONV].inventoryY = SysVar(SV_CONV_TOPY); break; case CONV_BOTTOM: - InvD[INV_CONV].inventoryY = SysVar(SV_CONV_BOTY); + g_InvD[INV_CONV].inventoryY = SysVar(SV_CONV_BOTY); break; case CONV_DEF: - InvD[INV_CONV].inventoryY = y - SysVar(SV_CONV_ABOVE_Y); + g_InvD[INV_CONV].inventoryY = y - SysVar(SV_CONV_ABOVE_Y); break; default: @@ -3726,34 +3715,34 @@ extern void HideConversation(bool bHide) { } // Calculate y change - deltay = InvD[INV_CONV].inventoryY - deltay; + deltay = g_InvD[INV_CONV].inventoryY - deltay; // Move it all - for (i = 0; objArray[i] && i < MAX_WCOMP; i++) { - MultiMoveRelXY(objArray[i], x - center, deltay); + for (i = 0; g_objArray[i] && i < MAX_WCOMP; i++) { + MultiMoveRelXY(g_objArray[i], x - center, deltay); } - for (i = 0; iconArray[i] && i < MAX_ICONS; i++) { - MultiMoveRelXY(iconArray[i], x - center, deltay); + for (i = 0; g_iconArray[i] && i < MAX_ICONS; i++) { + MultiMoveRelXY(g_iconArray[i], x - center, deltay); } - InvD[INV_CONV].inventoryX += x - center; + g_InvD[INV_CONV].inventoryX += x - center; /* * Now positioned as worked out * - but it must be in a sensible place */ - if (MultiLeftmost(RectObject) < SysVar(SV_CONV_MINX)) - x = SysVar(SV_CONV_MINX) - MultiLeftmost(RectObject); - else if (MultiRightmost(RectObject) > SCREEN_WIDTH - SysVar(SV_CONV_MINX)) - x = SCREEN_WIDTH - SysVar(SV_CONV_MINX) - MultiRightmost(RectObject); + if (MultiLeftmost(g_RectObject) < SysVar(SV_CONV_MINX)) + x = SysVar(SV_CONV_MINX) - MultiLeftmost(g_RectObject); + else if (MultiRightmost(g_RectObject) > SCREEN_WIDTH - SysVar(SV_CONV_MINX)) + x = SCREEN_WIDTH - SysVar(SV_CONV_MINX) - MultiRightmost(g_RectObject); else x = 0; - if (thisConvFn == CONV_DEF && MultiHighest(RectObject) < SysVar(SV_CONV_MINY) - && thisConvActor) { + if (g_thisConvFn == CONV_DEF && MultiHighest(g_RectObject) < SysVar(SV_CONV_MINY) + && g_thisConvActor) { int Loffset, Toffset; PlayfieldGetPos(FIELD_WORLD, &Loffset, &Toffset); - y = GetActorBottom(thisConvActor) - MultiHighest(RectObject) + + y = GetActorBottom(g_thisConvActor) - MultiHighest(g_RectObject) + SysVar(SV_CONV_BELOW_Y); y -= Toffset; } @@ -3761,28 +3750,28 @@ extern void HideConversation(bool bHide) { y = 0; if (x || y) { - for (i = 0; objArray[i] && i < MAX_WCOMP; i++) { - MultiMoveRelXY(objArray[i], x, y); + for (i = 0; g_objArray[i] && i < MAX_WCOMP; i++) { + MultiMoveRelXY(g_objArray[i], x, y); } - for (i = 0; iconArray[i] && i < MAX_ICONS; i++) { - MultiMoveRelXY(iconArray[i], x, y); + for (i = 0; g_iconArray[i] && i < MAX_ICONS; i++) { + MultiMoveRelXY(g_iconArray[i], x, y); } - InvD[INV_CONV].inventoryX += x; - InvD[INV_CONV].inventoryY += y; + g_InvD[INV_CONV].inventoryX += x; + g_InvD[INV_CONV].inventoryY += y; } /* * Oh shit! We might have gone off the bottom */ - if (MultiLowest(RectObject) > SCREEN_BOX_HEIGHT2 - SysVar(SV_CONV_MINY)) { - y = (SCREEN_BOX_HEIGHT2 - SysVar(SV_CONV_MINY)) - MultiLowest(RectObject); - for (i = 0; objArray[i] && i < MAX_WCOMP; i++) { - MultiMoveRelXY(objArray[i], 0, y); + if (MultiLowest(g_RectObject) > SCREEN_BOX_HEIGHT2 - SysVar(SV_CONV_MINY)) { + y = (SCREEN_BOX_HEIGHT2 - SysVar(SV_CONV_MINY)) - MultiLowest(g_RectObject); + for (i = 0; g_objArray[i] && i < MAX_WCOMP; i++) { + MultiMoveRelXY(g_objArray[i], 0, y); } - for (i = 0; iconArray[i] && i < MAX_ICONS; i++) { - MultiMoveRelXY(iconArray[i], 0, y); + for (i = 0; g_iconArray[i] && i < MAX_ICONS; i++) { + MultiMoveRelXY(g_iconArray[i], 0, y); } - InvD[INV_CONV].inventoryY += y; + g_InvD[INV_CONV].inventoryY += y; } } @@ -3793,7 +3782,7 @@ extern void HideConversation(bool bHide) { } extern bool ConvIsHidden() { - return InventoryHidden; + return g_InventoryHidden; } @@ -3808,8 +3797,8 @@ extern void PopUpInventory(int invno) { assert(invno == INV_1 || invno == INV_2 || invno == INV_CONV || invno == INV_CONF || invno == INV_MENU); // Trying to open illegal inventory - if (InventoryState == IDLE_INV) { - bReOpenMenu = false; // Better safe than sorry... + if (g_InventoryState == IDLE_INV) { + g_bReOpenMenu = false; // Better safe than sorry... DisableTags(); // Tags disabled during inventory if (TinselV2) @@ -3821,25 +3810,25 @@ extern void PopUpInventory(int invno) { _vm->_pcmMusic->dim(false); // Start conversation with permanent contents - memset(InvD[INV_CONV].contents, 0, MAX_ININV*sizeof(int)); - memcpy(InvD[INV_CONV].contents, permIcons, numPermIcons*sizeof(int)); - InvD[INV_CONV].NoofItems = numPermIcons; + memset(g_InvD[INV_CONV].contents, 0, MAX_ININV*sizeof(int)); + memcpy(g_InvD[INV_CONV].contents, g_permIcons, g_numPermIcons*sizeof(int)); + g_InvD[INV_CONV].NoofItems = g_numPermIcons; if (TinselV2) - InvD[INV_CONV].NoofHicons = numPermIcons; + g_InvD[INV_CONV].NoofHicons = g_numPermIcons; else - thisIcon = 0; + g_thisIcon = 0; } else if (invno == INV_CONF) { // Configuration window? cd.selBox = NOBOX; cd.pointBox = NOBOX; } - ino = invno; // The open inventory + g_ino = invno; // The open inventory - ItemsChanged = false; // Nothing changed - InvDragging = ID_NONE; // Not dragging - InventoryState = ACTIVE_INV; // Inventory actiive - InventoryHidden = false; // Not hidden - InventoryMaximised = InvD[ino].bMax; + g_ItemsChanged = false; // Nothing changed + g_InvDragging = ID_NONE; // Not dragging + g_InventoryState = ACTIVE_INV; // Inventory actiive + g_InventoryHidden = false; // Not hidden + g_InventoryMaximised = g_InvD[g_ino].bMax; if (invno != INV_CONF) // Configuration window? ConstructInventory(FULL); // Draw it up else { @@ -3849,10 +3838,10 @@ extern void PopUpInventory(int invno) { } static void SetMenuGlobals(CONFINIT *ci) { - InvD[INV_CONF].MinHicons = InvD[INV_CONF].MaxHicons = InvD[INV_CONF].NoofHicons = ci->h; - InvD[INV_CONF].MaxVicons = InvD[INV_CONF].MinVicons = InvD[INV_CONF].NoofVicons = ci->v; - InvD[INV_CONF].inventoryX = ci->x; - InvD[INV_CONF].inventoryY = ci->y; + g_InvD[INV_CONF].MinHicons = g_InvD[INV_CONF].MaxHicons = g_InvD[INV_CONF].NoofHicons = ci->h; + g_InvD[INV_CONF].MaxVicons = g_InvD[INV_CONF].MinVicons = g_InvD[INV_CONF].NoofVicons = ci->v; + g_InvD[INV_CONF].inventoryX = ci->x; + g_InvD[INV_CONF].inventoryY = ci->y; cd.bExtraWin = ci->bExtraWin; cd.box = ci->Box; cd.NumBoxes = ci->NumBoxes; @@ -3860,9 +3849,9 @@ static void SetMenuGlobals(CONFINIT *ci) { if (TinselV2) { if ((ci->ixHeading != NO_HEADING) && SysString(ci->ixHeading)) - InvD[INV_MENU].hInvTitle = SysString(ci->ixHeading); + g_InvD[INV_MENU].hInvTitle = SysString(ci->ixHeading); else - InvD[INV_MENU].hInvTitle = NO_HEADING; + g_InvD[INV_MENU].hInvTitle = NO_HEADING; } } @@ -3876,11 +3865,11 @@ extern void OpenMenu(CONFTYPE menuType) { if (TinselV0) return; - if (InventoryState != IDLE_INV) + if (g_InventoryState != IDLE_INV) return; - InvD[INV_CONF].resizable = false; - InvD[INV_CONF].bMoveable = false; + g_InvD[INV_CONF].resizable = false; + g_InvD[INV_CONF].bMoveable = false; switch (menuType) { case MAIN_MENU: @@ -3915,7 +3904,7 @@ extern void OpenMenu(CONFTYPE menuType) { case SOUND_MENU: if (TinselV2) - displayedLanguage = TextLanguage(); + g_displayedLanguage = TextLanguage(); #if 1 // FIXME: Hack to setup CONFBOX pointer to data in the global Config object if (TinselV2) { @@ -4003,16 +3992,16 @@ extern void OpenMenu(CONFTYPE menuType) { case TOP_WINDOW: SetMenuGlobals(&ciTopWin); - ino = INV_CONF; + g_ino = INV_CONF; ConstructInventory(CONF); // Draw it up - InventoryState = BOGUS_INV; + g_InventoryState = BOGUS_INV; return; default: return; } - if (HeldItem != INV_NOICON) + if (g_heldItem != INV_NOICON) DelAuxCursor(); // no longer aux cursor PopUpInventory(INV_CONF); @@ -4045,38 +4034,38 @@ extern void OpenMenu(CONFTYPE menuType) { * Close down an inventory window. */ extern void KillInventory() { - if (objArray[0] != NULL) { + if (g_objArray[0] != NULL) { DumpObjArray(); DumpDobjArray(); DumpIconArray(); } - if (InventoryState == ACTIVE_INV) { + if (g_InventoryState == ACTIVE_INV) { EnableTags(); if (TinselV2) EnablePointing(); - InvD[ino].bMax = InventoryMaximised; + g_InvD[g_ino].bMax = g_InventoryMaximised; UnHideCursorTrails(); _vm->divertKeyInput(NULL); } - InventoryState = IDLE_INV; + g_InventoryState = IDLE_INV; - if (bReOpenMenu) { - bReOpenMenu = false; + if (g_bReOpenMenu) { + g_bReOpenMenu = false; OpenMenu(MAIN_MENU); // Write config changes _vm->_config->writeToDisk(); - } else if (ino == INV_CONF) + } else if (g_ino == INV_CONF) InventoryIconCursor(false); if (TinselV2) // Pump up the volume - if (ino == INV_CONV) + if (g_ino == INV_CONV) _vm->_pcmMusic->unDim(false); g_system->setFeatureState(OSystem::kFeatureVirtualKeyboard, false); // Hide VK after save dialog closes @@ -4084,15 +4073,15 @@ extern void KillInventory() { extern void CloseInventory() { // If not active, ignore this - if (InventoryState != ACTIVE_INV) + if (g_InventoryState != ACTIVE_INV) return; // If hidden, a conversation action is still underway - ignore this - if (InventoryHidden) + if (g_InventoryHidden) return; // If conversation, this is a closeing event - if (ino == INV_CONV) + if (g_ino == INV_CONV) ConvAction(INV_CLOSEICON); KillInventory(); @@ -4117,13 +4106,13 @@ extern void InventoryProcess(CORO_PARAM, const void *) { CORO_BEGIN_CODE(_ctx); if (NumberOfLanguages() <= 1) - bNoLanguage = true; + g_bNoLanguage = true; while (1) { CORO_SLEEP(1); // allow scheduling - if (objArray[0] != NULL) { - if (ItemsChanged && ino != INV_CONF && !InventoryHidden) { + if (g_objArray[0] != NULL) { + if (g_ItemsChanged && g_ino != INV_CONF && !g_InventoryHidden) { FillInInventory(); // Needed when clicking on scroll bar. @@ -4131,15 +4120,15 @@ extern void InventoryProcess(CORO_PARAM, const void *) { GetCursorXY(&curX, &curY, false); InvCursor(IC_AREA, curX, curY); - ItemsChanged = false; + g_ItemsChanged = false; } - if (ino != INV_CONF) { + if (g_ino != INV_CONF) { for (int i = 0; i < MAX_ICONS; i++) { - if (iconArray[i] != NULL) - StepAnimScript(&iconAnims[i]); + if (g_iconArray[i] != NULL) + StepAnimScript(&g_iconAnims[i]); } } - if (InvDragging == ID_MDCONT) { + if (g_InvDragging == ID_MDCONT) { // Mixing desk control int sval, index, *pival; @@ -4263,12 +4252,12 @@ static int NearestSlideY(int fity) { int i = 0; do { - thisDist = ABS(slideStuff[i].y - fity); + thisDist = ABS(g_slideStuff[i].y - fity); if (thisDist < nearDist) { nearDist = thisDist; nearI = i; } - } while (slideStuff[++i].n != -1); + } while (g_slideStuff[++i].n != -1); return nearI; } @@ -4281,44 +4270,44 @@ static void SlideSlider(int y, SSFN fn) { int gotoY, ati; // Only do this if there's a slider - if (!SlideObject) + if (!g_SlideObject) return; switch (fn) { case S_START: // Start of a drag on the slider - newY = sliderYpos; - lasti = NearestSlideY(sliderYpos); + newY = g_sliderYpos; + lasti = NearestSlideY(g_sliderYpos); break; case S_SLIDE: // Y-movement during drag newY = newY + y; // New y-position - if (newY < sliderYmin) - gotoY = sliderYmin; // Above top limit - else if (newY > sliderYmax) - gotoY = sliderYmax; // Below bottom limit + if (newY < g_sliderYmin) + gotoY = g_sliderYmin; // Above top limit + else if (newY > g_sliderYmax) + gotoY = g_sliderYmax; // Below bottom limit else gotoY = newY; // Hunky-Dory // Move slider to new position - MultiMoveRelXY(SlideObject, 0, gotoY - sliderYpos); - sliderYpos = gotoY; + MultiMoveRelXY(g_SlideObject, 0, gotoY - g_sliderYpos); + g_sliderYpos = gotoY; // Re-draw icons if necessary - ati = NearestSlideY(sliderYpos); + ati = NearestSlideY(g_sliderYpos); if (ati != lasti) { - InvD[ino].FirstDisp = slideStuff[ati].n; - assert(InvD[ino].FirstDisp >= 0); // negative first displayed - ItemsChanged = true; + g_InvD[g_ino].FirstDisp = g_slideStuff[ati].n; + assert(g_InvD[g_ino].FirstDisp >= 0); // negative first displayed + g_ItemsChanged = true; lasti = ati; } break; case S_END: // End of a drag on the slider // Draw icons from new start icon - ati = NearestSlideY(sliderYpos); - InvD[ino].FirstDisp = slideStuff[ati].n; - ItemsChanged = true; + ati = NearestSlideY(g_sliderYpos); + g_InvD[g_ino].FirstDisp = g_slideStuff[ati].n; + g_ItemsChanged = true; break; default: @@ -4336,38 +4325,38 @@ static void SlideCSlider(int y, SSFN fn) { int fc; // Only do this if there's a slider - if (!SlideObject) + if (!g_SlideObject) return; switch (fn) { case S_START: // Start of a drag on the slider - newY = sliderYpos; + newY = g_sliderYpos; break; case S_SLIDE: // Y-movement during drag newY = newY + y; // New y-position - if (newY < sliderYmin) - gotoY = sliderYmin; // Above top limit - else if (newY > sliderYmax) - gotoY = sliderYmax; // Below bottom limit + if (newY < g_sliderYmin) + gotoY = g_sliderYmin; // Above top limit + else if (newY > g_sliderYmax) + gotoY = g_sliderYmax; // Below bottom limit else gotoY = newY; // Hunky-Dory // Move slider to new position if (TinselV2) - MultiMoveRelXY(SlideObject, 0, gotoY - sliderYpos); - sliderYpos = gotoY; + MultiMoveRelXY(g_SlideObject, 0, gotoY - g_sliderYpos); + g_sliderYpos = gotoY; fc = cd.extraBase; if ((cd.box == saveBox || cd.box == loadBox)) - FirstFile((sliderYpos - sliderYmin) * (MAX_SAVED_FILES - NUM_RGROUP_BOXES) / - (sliderYmax - sliderYmin)); + FirstFile((g_sliderYpos - g_sliderYmin) * (MAX_SAVED_FILES - NUM_RGROUP_BOXES) / + (g_sliderYmax - g_sliderYmin)); else if (cd.box == hopperBox1) - FirstScene((sliderYpos - sliderYmin) * (numScenes - NUM_RGROUP_BOXES) / sliderRange); + FirstScene((g_sliderYpos - g_sliderYmin) * (g_numScenes - NUM_RGROUP_BOXES) / sliderRange); else if (cd.box == hopperBox2) - FirstEntry((sliderYpos - sliderYmin) * (numEntries - NUM_RGROUP_BOXES) / sliderRange); + FirstEntry((g_sliderYpos - g_sliderYmin) * (g_numEntries - NUM_RGROUP_BOXES) / sliderRange); // If extraBase has changed... if (fc != cd.extraBase) { @@ -4409,16 +4398,16 @@ static void SlideMSlider(int x, SSFN fn) { // Work out the indices index = cd.selBox & ~IS_MASK; - for (i = 0; i < numMdSlides; i++) - if (mdSlides[i].num == index) + for (i = 0; i < g_numMdSlides; i++) + if (g_mdSlides[i].num == index) break; - assert(i < numMdSlides); + assert(i < g_numMdSlides); switch (fn) { case S_START: // Start of a drag on the slider // can use index as a throw-away value - GetAniPosition(mdSlides[i].obj, &newX, &index); - lX = sX = newX; + GetAniPosition(g_mdSlides[i].obj, &newX, &index); + g_lX = g_sX = newX; break; case S_SLIDE: // X-movement during drag @@ -4427,19 +4416,19 @@ static void SlideMSlider(int x, SSFN fn) { newX = newX + x; // New x-position - if (newX < mdSlides[i].min) - gotoX = mdSlides[i].min; // Below bottom limit - else if (newX > mdSlides[i].max) - gotoX = mdSlides[i].max; // Above top limit + if (newX < g_mdSlides[i].min) + gotoX = g_mdSlides[i].min; // Below bottom limit + else if (newX > g_mdSlides[i].max) + gotoX = g_mdSlides[i].max; // Above top limit else gotoX = newX; // Hunky-Dory // Move slider to new position - MultiMoveRelXY(mdSlides[i].obj, gotoX - sX, 0); - sX = gotoX; + MultiMoveRelXY(g_mdSlides[i].obj, gotoX - g_sX, 0); + g_sX = gotoX; - if (lX != sX) { - *cd.box[index].ival = (sX - mdSlides[i].min)*cd.box[index].w/SLIDE_RANGE; + if (g_lX != g_sX) { + *cd.box[index].ival = (g_sX - g_mdSlides[i].min)*cd.box[index].w/SLIDE_RANGE; if (cd.box[index].boxFunc == MUSICVOL) SetMidiVolume(*cd.box[index].ival); #ifdef MAC_OPTIONS @@ -4449,14 +4438,14 @@ static void SlideMSlider(int x, SSFN fn) { if (cd.box[index].boxFunc == SAMPVOL) SetSampleVolume(*cd.box[index].ival); #endif - lX = sX; + g_lX = g_sX; } break; case S_TIMEUP: case S_TIMEDN: gotoX = SLIDE_RANGE*(*cd.box[index].ival)/cd.box[index].w; - MultiSetAniX(mdSlides[i].obj, mdSlides[i].min+gotoX); + MultiSetAniX(g_mdSlides[i].obj, g_mdSlides[i].min+gotoX); if (cd.box[index].boxFunc == MUSICVOL) SetMidiVolume(*cd.box[index].ival); @@ -4471,7 +4460,7 @@ static void SlideMSlider(int x, SSFN fn) { case S_END: // End of a drag on the slider AddBoxes(false); // Might change position slightly - if (ino == INV_CONF && cd.box == subtitlesBox) + if (g_ino == INV_CONF && cd.box == subtitlesBox) Select(_vm->_config->_language, false); break; } @@ -4481,23 +4470,23 @@ static void SlideMSlider(int x, SSFN fn) { * Called from ChangeingSize() during re-sizing. */ static void GettingTaller() { - if (SuppV) { - Ychange += SuppV; - if (Ycompensate == 'T') - InvD[ino].inventoryY += SuppV; - SuppV = 0; + if (g_SuppV) { + g_Ychange += g_SuppV; + if (g_Ycompensate == 'T') + g_InvD[g_ino].inventoryY += g_SuppV; + g_SuppV = 0; } - while (Ychange > (ITEM_HEIGHT+1) && InvD[ino].NoofVicons < InvD[ino].MaxVicons) { - Ychange -= (ITEM_HEIGHT+1); - InvD[ino].NoofVicons++; - if (Ycompensate == 'T') - InvD[ino].inventoryY -= (ITEM_HEIGHT+1); + while (g_Ychange > (ITEM_HEIGHT+1) && g_InvD[g_ino].NoofVicons < g_InvD[g_ino].MaxVicons) { + g_Ychange -= (ITEM_HEIGHT+1); + g_InvD[g_ino].NoofVicons++; + if (g_Ycompensate == 'T') + g_InvD[g_ino].inventoryY -= (ITEM_HEIGHT+1); } - if (InvD[ino].NoofVicons < InvD[ino].MaxVicons) { - SuppV = Ychange; - Ychange = 0; - if (Ycompensate == 'T') - InvD[ino].inventoryY -= SuppV; + if (g_InvD[g_ino].NoofVicons < g_InvD[g_ino].MaxVicons) { + g_SuppV = g_Ychange; + g_Ychange = 0; + if (g_Ycompensate == 'T') + g_InvD[g_ino].inventoryY -= g_SuppV; } } @@ -4505,73 +4494,73 @@ static void GettingTaller() { * Called from ChangeingSize() during re-sizing. */ static void GettingShorter() { - int StartNvi = InvD[ino].NoofVicons; - int StartUv = SuppV; + int StartNvi = g_InvD[g_ino].NoofVicons; + int StartUv = g_SuppV; - if (SuppV) { - Ychange += (SuppV - (ITEM_HEIGHT+1)); - InvD[ino].NoofVicons++; - SuppV = 0; + if (g_SuppV) { + g_Ychange += (g_SuppV - (ITEM_HEIGHT+1)); + g_InvD[g_ino].NoofVicons++; + g_SuppV = 0; } - while (Ychange < -(ITEM_HEIGHT+1) && InvD[ino].NoofVicons > InvD[ino].MinVicons) { - Ychange += (ITEM_HEIGHT+1); - InvD[ino].NoofVicons--; + while (g_Ychange < -(ITEM_HEIGHT+1) && g_InvD[g_ino].NoofVicons > g_InvD[g_ino].MinVicons) { + g_Ychange += (ITEM_HEIGHT+1); + g_InvD[g_ino].NoofVicons--; } - if (InvD[ino].NoofVicons > InvD[ino].MinVicons && Ychange) { - SuppV = (ITEM_HEIGHT+1) + Ychange; - InvD[ino].NoofVicons--; - Ychange = 0; + if (g_InvD[g_ino].NoofVicons > g_InvD[g_ino].MinVicons && g_Ychange) { + g_SuppV = (ITEM_HEIGHT+1) + g_Ychange; + g_InvD[g_ino].NoofVicons--; + g_Ychange = 0; } - if (Ycompensate == 'T') - InvD[ino].inventoryY += (ITEM_HEIGHT+1)*(StartNvi - InvD[ino].NoofVicons) - (SuppV - StartUv); + if (g_Ycompensate == 'T') + g_InvD[g_ino].inventoryY += (ITEM_HEIGHT+1)*(StartNvi - g_InvD[g_ino].NoofVicons) - (g_SuppV - StartUv); } /** * Called from ChangeingSize() during re-sizing. */ static void GettingWider() { - int StartNhi = InvD[ino].NoofHicons; - int StartUh = SuppH; + int StartNhi = g_InvD[g_ino].NoofHicons; + int StartUh = g_SuppH; - if (SuppH) { - Xchange += SuppH; - SuppH = 0; + if (g_SuppH) { + g_Xchange += g_SuppH; + g_SuppH = 0; } - while (Xchange > (ITEM_WIDTH+1) && InvD[ino].NoofHicons < InvD[ino].MaxHicons) { - Xchange -= (ITEM_WIDTH+1); - InvD[ino].NoofHicons++; + while (g_Xchange > (ITEM_WIDTH+1) && g_InvD[g_ino].NoofHicons < g_InvD[g_ino].MaxHicons) { + g_Xchange -= (ITEM_WIDTH+1); + g_InvD[g_ino].NoofHicons++; } - if (InvD[ino].NoofHicons < InvD[ino].MaxHicons) { - SuppH = Xchange; - Xchange = 0; + if (g_InvD[g_ino].NoofHicons < g_InvD[g_ino].MaxHicons) { + g_SuppH = g_Xchange; + g_Xchange = 0; } - if (Xcompensate == 'L') - InvD[ino].inventoryX += (ITEM_WIDTH+1)*(StartNhi - InvD[ino].NoofHicons) - (SuppH - StartUh); + if (g_Xcompensate == 'L') + g_InvD[g_ino].inventoryX += (ITEM_WIDTH+1)*(StartNhi - g_InvD[g_ino].NoofHicons) - (g_SuppH - StartUh); } /** * Called from ChangeingSize() during re-sizing. */ static void GettingNarrower() { - int StartNhi = InvD[ino].NoofHicons; - int StartUh = SuppH; + int StartNhi = g_InvD[g_ino].NoofHicons; + int StartUh = g_SuppH; - if (SuppH) { - Xchange += (SuppH - (ITEM_WIDTH+1)); - InvD[ino].NoofHicons++; - SuppH = 0; + if (g_SuppH) { + g_Xchange += (g_SuppH - (ITEM_WIDTH+1)); + g_InvD[g_ino].NoofHicons++; + g_SuppH = 0; } - while (Xchange < -(ITEM_WIDTH+1) && InvD[ino].NoofHicons > InvD[ino].MinHicons) { - Xchange += (ITEM_WIDTH+1); - InvD[ino].NoofHicons--; + while (g_Xchange < -(ITEM_WIDTH+1) && g_InvD[g_ino].NoofHicons > g_InvD[g_ino].MinHicons) { + g_Xchange += (ITEM_WIDTH+1); + g_InvD[g_ino].NoofHicons--; } - if (InvD[ino].NoofHicons > InvD[ino].MinHicons && Xchange) { - SuppH = (ITEM_WIDTH+1) + Xchange; - InvD[ino].NoofHicons--; - Xchange = 0; + if (g_InvD[g_ino].NoofHicons > g_InvD[g_ino].MinHicons && g_Xchange) { + g_SuppH = (ITEM_WIDTH+1) + g_Xchange; + g_InvD[g_ino].NoofHicons--; + g_Xchange = 0; } - if (Xcompensate == 'L') - InvD[ino].inventoryX += (ITEM_WIDTH+1)*(StartNhi - InvD[ino].NoofHicons) - (SuppH - StartUh); + if (g_Xcompensate == 'L') + g_InvD[g_ino].inventoryX += (ITEM_WIDTH+1)*(StartNhi - g_InvD[g_ino].NoofHicons) - (g_SuppH - StartUh); } @@ -4580,15 +4569,15 @@ static void GettingNarrower() { */ static void ChangeingSize() { /* Make it taller or shorter if necessary. */ - if (Ychange > 0) + if (g_Ychange > 0) GettingTaller(); - else if (Ychange < 0) + else if (g_Ychange < 0) GettingShorter(); /* Make it wider or narrower if necessary. */ - if (Xchange > 0) + if (g_Xchange > 0) GettingWider(); - else if (Xchange < 0) + else if (g_Xchange < 0) GettingNarrower(); ConstructInventory(EMPTY); @@ -4601,29 +4590,29 @@ extern void Xmovement(int x) { int aniX, aniY; int i; - if (x && objArray[0] != NULL) { - switch (InvDragging) { + if (x && g_objArray[0] != NULL) { + switch (g_InvDragging) { case ID_MOVE: - GetAniPosition(objArray[0], &InvD[ino].inventoryX, &aniY); - InvD[ino].inventoryX +=x; - MultiSetAniX(objArray[0], InvD[ino].inventoryX); - for (i = 1; objArray[i] && i < MAX_WCOMP; i++) - MultiMoveRelXY(objArray[i], x, 0); - for (i = 0; iconArray[i] && i < MAX_ICONS; i++) - MultiMoveRelXY(iconArray[i], x, 0); + GetAniPosition(g_objArray[0], &g_InvD[g_ino].inventoryX, &aniY); + g_InvD[g_ino].inventoryX +=x; + MultiSetAniX(g_objArray[0], g_InvD[g_ino].inventoryX); + for (i = 1; g_objArray[i] && i < MAX_WCOMP; i++) + MultiMoveRelXY(g_objArray[i], x, 0); + for (i = 0; g_iconArray[i] && i < MAX_ICONS; i++) + MultiMoveRelXY(g_iconArray[i], x, 0); break; case ID_LEFT: case ID_TLEFT: case ID_BLEFT: - Xchange -= x; + g_Xchange -= x; ChangeingSize(); break; case ID_RIGHT: case ID_TRIGHT: case ID_BRIGHT: - Xchange += x; + g_Xchange += x; ChangeingSize(); break; @@ -4649,16 +4638,16 @@ extern void Ymovement(int y) { int aniX, aniY; int i; - if (y && objArray[0] != NULL) { - switch (InvDragging) { + if (y && g_objArray[0] != NULL) { + switch (g_InvDragging) { case ID_MOVE: - GetAniPosition(objArray[0], &aniX, &InvD[ino].inventoryY); - InvD[ino].inventoryY +=y; - MultiSetAniY(objArray[0], InvD[ino].inventoryY); - for (i = 1; objArray[i] && i < MAX_WCOMP; i++) - MultiMoveRelXY(objArray[i], 0, y); - for (i = 0; iconArray[i] && i < MAX_ICONS; i++) - MultiMoveRelXY(iconArray[i], 0, y); + GetAniPosition(g_objArray[0], &aniX, &g_InvD[g_ino].inventoryY); + g_InvD[g_ino].inventoryY +=y; + MultiSetAniY(g_objArray[0], g_InvD[g_ino].inventoryY); + for (i = 1; g_objArray[i] && i < MAX_WCOMP; i++) + MultiMoveRelXY(g_objArray[i], 0, y); + for (i = 0; g_iconArray[i] && i < MAX_ICONS; i++) + MultiMoveRelXY(g_iconArray[i], 0, y); break; case ID_SLIDE: @@ -4672,14 +4661,14 @@ extern void Ymovement(int y) { case ID_BOTTOM: case ID_BLEFT: case ID_BRIGHT: - Ychange += y; + g_Ychange += y; ChangeingSize(); break; case ID_TOP: case ID_TLEFT: case ID_TRIGHT: - Ychange -= y; + g_Ychange -= y; ChangeingSize(); break; @@ -4705,16 +4694,16 @@ static void InvDragStart() { /* * Do something different for Save/Restore screens */ - if (ino == INV_CONF) { + if (g_ino == INV_CONF) { int whichbox; whichbox = WhichMenuBox(curX, curY, true); if (whichbox == IB_SLIDE) { - InvDragging = ID_CSLIDE; + g_InvDragging = ID_CSLIDE; SlideCSlider(0, S_START); } else if (whichbox > 0 && (whichbox & IS_MASK)) { - InvDragging = ID_MDCONT; // Mixing desk control + g_InvDragging = ID_MDCONT; // Mixing desk control cd.selBox = whichbox; SlideMSlider(0, S_START); } @@ -4726,85 +4715,85 @@ static void InvDragStart() { */ switch (InvArea(curX, curY)) { case I_HEADER: - if (InvD[ino].bMoveable) { - InvDragging = ID_MOVE; + if (g_InvD[g_ino].bMoveable) { + g_InvDragging = ID_MOVE; } break; case I_SLIDE: - InvDragging = ID_SLIDE; + g_InvDragging = ID_SLIDE; SlideSlider(0, S_START); break; case I_BOTTOM: - if (InvD[ino].resizable) { - Ychange = 0; - InvDragging = ID_BOTTOM; - Ycompensate = 'B'; + if (g_InvD[g_ino].resizable) { + g_Ychange = 0; + g_InvDragging = ID_BOTTOM; + g_Ycompensate = 'B'; } break; case I_TOP: - if (InvD[ino].resizable) { - Ychange = 0; - InvDragging = ID_TOP; - Ycompensate = 'T'; + if (g_InvD[g_ino].resizable) { + g_Ychange = 0; + g_InvDragging = ID_TOP; + g_Ycompensate = 'T'; } break; case I_LEFT: - if (InvD[ino].resizable) { - Xchange = 0; - InvDragging = ID_LEFT; - Xcompensate = 'L'; + if (g_InvD[g_ino].resizable) { + g_Xchange = 0; + g_InvDragging = ID_LEFT; + g_Xcompensate = 'L'; } break; case I_RIGHT: - if (InvD[ino].resizable) { - Xchange = 0; - InvDragging = ID_RIGHT; - Xcompensate = 'R'; + if (g_InvD[g_ino].resizable) { + g_Xchange = 0; + g_InvDragging = ID_RIGHT; + g_Xcompensate = 'R'; } break; case I_TLEFT: - if (InvD[ino].resizable) { - Ychange = 0; - Ycompensate = 'T'; - Xchange = 0; - Xcompensate = 'L'; - InvDragging = ID_TLEFT; + if (g_InvD[g_ino].resizable) { + g_Ychange = 0; + g_Ycompensate = 'T'; + g_Xchange = 0; + g_Xcompensate = 'L'; + g_InvDragging = ID_TLEFT; } break; case I_TRIGHT: - if (InvD[ino].resizable) { - Ychange = 0; - Ycompensate = 'T'; - Xchange = 0; - Xcompensate = 'R'; - InvDragging = ID_TRIGHT; + if (g_InvD[g_ino].resizable) { + g_Ychange = 0; + g_Ycompensate = 'T'; + g_Xchange = 0; + g_Xcompensate = 'R'; + g_InvDragging = ID_TRIGHT; } break; case I_BLEFT: - if (InvD[ino].resizable) { - Ychange = 0; - Ycompensate = 'B'; - Xchange = 0; - Xcompensate = 'L'; - InvDragging = ID_BLEFT; + if (g_InvD[g_ino].resizable) { + g_Ychange = 0; + g_Ycompensate = 'B'; + g_Xchange = 0; + g_Xcompensate = 'L'; + g_InvDragging = ID_BLEFT; } break; case I_BRIGHT: - if (InvD[ino].resizable) { - Ychange = 0; - Ycompensate = 'B'; - Xchange = 0; - Xcompensate = 'R'; - InvDragging = ID_BRIGHT; + if (g_InvD[g_ino].resizable) { + g_Ychange = 0; + g_Ycompensate = 'B'; + g_Xchange = 0; + g_Xcompensate = 'R'; + g_InvDragging = ID_BRIGHT; } break; } @@ -4818,14 +4807,14 @@ static void InvDragEnd() { GetCursorXY(&curX, &curY, false); - if (InvDragging != ID_NONE) { - if (InvDragging == ID_SLIDE) { + if (g_InvDragging != ID_NONE) { + if (g_InvDragging == ID_SLIDE) { SlideSlider(0, S_END); - } else if (InvDragging == ID_CSLIDE) { + } else if (g_InvDragging == ID_CSLIDE) { ; // No action - } else if (InvDragging == ID_MDCONT) { + } else if (g_InvDragging == ID_MDCONT) { SlideMSlider(0, S_END); - } else if (InvDragging == ID_MOVE) { + } else if (g_InvDragging == ID_MOVE) { ; // No action } else { // Were re-sizing. Redraw the whole thing. @@ -4834,21 +4823,21 @@ static void InvDragEnd() { ConstructInventory(FULL); // If this was the maximised, it no longer is! - if (InventoryMaximised) { - InventoryMaximised = false; - InvD[ino].otherX = InvD[ino].inventoryX; - InvD[ino].otherY = InvD[ino].inventoryY; + if (g_InventoryMaximised) { + g_InventoryMaximised = false; + g_InvD[g_ino].otherX = g_InvD[g_ino].inventoryX; + g_InvD[g_ino].otherY = g_InvD[g_ino].inventoryY; } } - InvDragging = ID_NONE; + g_InvDragging = ID_NONE; ProcessedProvisional(); } // Cursor could well now be inappropriate InvCursor(IC_AREA, curX, curY); - Xchange = Ychange = 0; // Probably no need, but does no harm! + g_Xchange = g_Ychange = 0; // Probably no need, but does no harm! } static void MenuPageDown() { @@ -4860,7 +4849,7 @@ static void MenuPageDown() { Select(cd.selBox, true); } } else if (cd.box == hopperBox1) { - if (cd.extraBase < numScenes - NUM_RGROUP_BOXES) { + if (cd.extraBase < g_numScenes - NUM_RGROUP_BOXES) { FirstScene(cd.extraBase + (NUM_RGROUP_BOXES - 1)); AddBoxes(true); if (cd.selBox) @@ -4868,7 +4857,7 @@ static void MenuPageDown() { Select(cd.selBox, true); } } else if (cd.box == hopperBox2) { - if (cd.extraBase < numEntries - NUM_RGROUP_BOXES) { + if (cd.extraBase < g_numEntries - NUM_RGROUP_BOXES) { FirstEntry(cd.extraBase+(NUM_RGROUP_BOXES - 1)); AddBoxes(true); if (cd.selBox) @@ -5010,7 +4999,7 @@ static void ConfActionSpecial(int i) { Select(cd.selBox, true); } } else if (cd.box == hopperBox1) { - if (cd.extraBase < numScenes - NUM_RGROUP_BOXES) { + if (cd.extraBase < g_numScenes - NUM_RGROUP_BOXES) { FirstScene(cd.extraBase + 1); AddBoxes(true); if (cd.selBox) @@ -5018,7 +5007,7 @@ static void ConfActionSpecial(int i) { Select(cd.selBox, true); } } else if (cd.box == hopperBox2) { - if (cd.extraBase < numEntries - NUM_RGROUP_BOXES) { + if (cd.extraBase < g_numEntries - NUM_RGROUP_BOXES) { FirstEntry(cd.extraBase + 1); AddBoxes(true); if (cd.selBox) @@ -5045,25 +5034,25 @@ static void InvPutDown(int index) { int hiIndex; // Current position of held item (if in) // Find where the held item is positioned in this inventory (if it is) - for (hiIndex = 0; hiIndex < InvD[ino].NoofItems; hiIndex++) - if (InvD[ino].contents[hiIndex] == HeldItem) + for (hiIndex = 0; hiIndex < g_InvD[g_ino].NoofItems; hiIndex++) + if (g_InvD[g_ino].contents[hiIndex] == g_heldItem) break; // If drop position would leave a gap, move it up - if (index >= InvD[ino].NoofItems) { - if (hiIndex == InvD[ino].NoofItems) // Not in, add it - index = InvD[ino].NoofItems; + if (index >= g_InvD[g_ino].NoofItems) { + if (hiIndex == g_InvD[g_ino].NoofItems) // Not in, add it + index = g_InvD[g_ino].NoofItems; else - index = InvD[ino].NoofItems - 1; + index = g_InvD[g_ino].NoofItems - 1; } - if (hiIndex == InvD[ino].NoofItems) { // Not in, add it - if (InvD[ino].NoofItems < InvD[ino].MaxInvObj) { - InvD[ino].NoofItems++; + if (hiIndex == g_InvD[g_ino].NoofItems) { // Not in, add it + if (g_InvD[g_ino].NoofItems < g_InvD[g_ino].MaxInvObj) { + g_InvD[g_ino].NoofItems++; // Don't leave it in the other inventory! - if (InventoryPos(HeldItem) != INV_HELDNOTIN) - RemFromInventory(ino == INV_1 ? INV_2 : INV_1, HeldItem); + if (InventoryPos(g_heldItem) != INV_HELDNOTIN) + RemFromInventory(g_ino == INV_1 ? INV_2 : INV_1, g_heldItem); } else { // No room at the inn! return; @@ -5072,17 +5061,17 @@ static void InvPutDown(int index) { // Position it in the inventory if (index < hiIndex) { - memmove(&InvD[ino].contents[index + 1], &InvD[ino].contents[index], (hiIndex-index)*sizeof(int)); - InvD[ino].contents[index] = HeldItem; + memmove(&g_InvD[g_ino].contents[index + 1], &g_InvD[g_ino].contents[index], (hiIndex-index)*sizeof(int)); + g_InvD[g_ino].contents[index] = g_heldItem; } else if (index > hiIndex) { - memmove(&InvD[ino].contents[hiIndex], &InvD[ino].contents[hiIndex+1], (index-hiIndex)*sizeof(int)); - InvD[ino].contents[index] = HeldItem; + memmove(&g_InvD[g_ino].contents[hiIndex], &g_InvD[g_ino].contents[hiIndex+1], (index-hiIndex)*sizeof(int)); + g_InvD[g_ino].contents[index] = g_heldItem; } else { - InvD[ino].contents[index] = HeldItem; + g_InvD[g_ino].contents[index] = g_heldItem; } - HeldItem = INV_NOICON; - ItemsChanged = true; + g_heldItem = INV_NOICON; + g_ItemsChanged = true; DelAuxCursor(); RestoreMainCursor(); GetCursorXY(&aniX, &aniY, false); @@ -5116,26 +5105,26 @@ static void InvPickup(int index) { return; // If not holding anything - if (HeldItem == INV_NOICON && InvD[ino].contents[index] && - (!TinselV2 || InvD[ino].contents[index] != HeldItem)) { + if (g_heldItem == INV_NOICON && g_InvD[g_ino].contents[index] && + (!TinselV2 || g_InvD[g_ino].contents[index] != g_heldItem)) { // Pick-up - invObj = GetInvObject(InvD[ino].contents[index]); - thisIcon = InvD[ino].contents[index]; + invObj = GetInvObject(g_InvD[g_ino].contents[index]); + g_thisIcon = g_InvD[g_ino].contents[index]; if (TinselV2) InvTinselEvent(invObj, PICKUP, INV_PICKUP, index); else if (invObj->hScript) InvTinselEvent(invObj, WALKTO, INV_PICKUP, index); - } else if (HeldItem != INV_NOICON) { + } else if (g_heldItem != INV_NOICON) { // Put-down - invObj = GetInvObject(HeldItem); + invObj = GetInvObject(g_heldItem); // If DROPCODE set, send event, otherwise it's a putdown if (invObj->attribute & IO_DROPCODE && invObj->hScript) InvTinselEvent(invObj, PUTDOWN, INV_PICKUP, index); - else if (!(invObj->attribute & IO_ONLYINV1 && ino != INV_1) - && !(invObj->attribute & IO_ONLYINV2 && ino != INV_2)) { + else if (!(invObj->attribute & IO_ONLYINV1 && g_ino != INV_1) + && !(invObj->attribute & IO_ONLYINV2 && g_ino != INV_2)) { if (TinselV2) InvPutDown(index); else @@ -5152,7 +5141,7 @@ static void InvWalkTo(const Common::Point &coOrds) { switch (InvArea(coOrds.x, coOrds.y)) { case I_NOTIN: - if (ino == INV_CONV) + if (g_ino == INV_CONV) ConvAction(INV_CLOSEICON); if ((cd.box == hopperBox1) || (cd.box == hopperBox2)) FreeSceneHopper(); @@ -5160,43 +5149,43 @@ static void InvWalkTo(const Common::Point &coOrds) { break; case I_SLIDE_UP: - if (InvD[ino].NoofVicons == 1) - InvD[ino].FirstDisp -= InvD[ino].NoofHicons; - for (i = 1; i < InvD[ino].NoofVicons; i++) - InvD[ino].FirstDisp -= InvD[ino].NoofHicons; - if (InvD[ino].FirstDisp < 0) - InvD[ino].FirstDisp = 0; - ItemsChanged = true; + if (g_InvD[g_ino].NoofVicons == 1) + g_InvD[g_ino].FirstDisp -= g_InvD[g_ino].NoofHicons; + for (i = 1; i < g_InvD[g_ino].NoofVicons; i++) + g_InvD[g_ino].FirstDisp -= g_InvD[g_ino].NoofHicons; + if (g_InvD[g_ino].FirstDisp < 0) + g_InvD[g_ino].FirstDisp = 0; + g_ItemsChanged = true; break; case I_UP: - InvD[ino].FirstDisp -= InvD[ino].NoofHicons; - if (InvD[ino].FirstDisp < 0) - InvD[ino].FirstDisp = 0; - ItemsChanged = true; + g_InvD[g_ino].FirstDisp -= g_InvD[g_ino].NoofHicons; + if (g_InvD[g_ino].FirstDisp < 0) + g_InvD[g_ino].FirstDisp = 0; + g_ItemsChanged = true; break; case I_SLIDE_DOWN: - if (InvD[ino].NoofVicons == 1) - if (InvD[ino].FirstDisp + InvD[ino].NoofHicons*InvD[ino].NoofVicons < InvD[ino].NoofItems) - InvD[ino].FirstDisp += InvD[ino].NoofHicons; - for (i = 1; i < InvD[ino].NoofVicons; i++) { - if (InvD[ino].FirstDisp + InvD[ino].NoofHicons*InvD[ino].NoofVicons < InvD[ino].NoofItems) - InvD[ino].FirstDisp += InvD[ino].NoofHicons; + if (g_InvD[g_ino].NoofVicons == 1) + if (g_InvD[g_ino].FirstDisp + g_InvD[g_ino].NoofHicons*g_InvD[g_ino].NoofVicons < g_InvD[g_ino].NoofItems) + g_InvD[g_ino].FirstDisp += g_InvD[g_ino].NoofHicons; + for (i = 1; i < g_InvD[g_ino].NoofVicons; i++) { + if (g_InvD[g_ino].FirstDisp + g_InvD[g_ino].NoofHicons*g_InvD[g_ino].NoofVicons < g_InvD[g_ino].NoofItems) + g_InvD[g_ino].FirstDisp += g_InvD[g_ino].NoofHicons; } - ItemsChanged = true; + g_ItemsChanged = true; break; case I_DOWN: - if (InvD[ino].FirstDisp + InvD[ino].NoofHicons*InvD[ino].NoofVicons < InvD[ino].NoofItems) { - InvD[ino].FirstDisp += InvD[ino].NoofHicons; - ItemsChanged = true; + if (g_InvD[g_ino].FirstDisp + g_InvD[g_ino].NoofHicons*g_InvD[g_ino].NoofVicons < g_InvD[g_ino].NoofItems) { + g_InvD[g_ino].FirstDisp += g_InvD[g_ino].NoofHicons; + g_ItemsChanged = true; } break; case I_BODY: - if (ino == INV_CONF) { - if (!InventoryHidden) + if (g_ino == INV_CONF) { + if (!g_InventoryHidden) MenuAction(WhichMenuBox(coOrds.x, coOrds.y, false), false); } else { Common::Point pt = coOrds; @@ -5204,8 +5193,8 @@ static void InvWalkTo(const Common::Point &coOrds) { // To cater for drop in dead space between icons, // look 1 pixel right, then 1 down, then 1 right and down. - if (i == INV_NOICON && HeldItem != INV_NOICON && - (ino == INV_1 || ino == INV_2)) { + if (i == INV_NOICON && g_heldItem != INV_NOICON && + (g_ino == INV_1 || g_ino == INV_2)) { pt.x += 1; // 1 to the right i = InvItem(pt, false); if (i == INV_NOICON) { @@ -5219,7 +5208,7 @@ static void InvWalkTo(const Common::Point &coOrds) { } } - if (ino == INV_CONV) { + if (g_ino == INV_CONV) { ConvAction(i); } else InvPickup(i); @@ -5238,19 +5227,19 @@ static void InvAction() { switch (InvArea(aniX, aniY)) { case I_BODY: - if (ino == INV_CONF) { - if (!InventoryHidden) + if (g_ino == INV_CONF) { + if (!g_InventoryHidden) MenuAction(WhichMenuBox(aniX, aniY, false), true); - } else if (ino == INV_CONV) { + } else if (g_ino == INV_CONV) { index = InvItem(&aniX, &aniY, false); ConvAction(index); } else { index = InvItem(&aniX, &aniY, false); if (index != INV_NOICON) { - if (InvD[ino].contents[index] && InvD[ino].contents[index] != HeldItem) { - invObj = GetInvObject(InvD[ino].contents[index]); + if (g_InvD[g_ino].contents[index] && g_InvD[g_ino].contents[index] != g_heldItem) { + invObj = GetInvObject(g_InvD[g_ino].contents[index]); if (TinselV2) - thisIcon = InvD[ino].contents[index]; + g_thisIcon = g_InvD[g_ino].contents[index]; if (TinselV2 || (invObj->hScript)) InvTinselEvent(invObj, ACTION, INV_ACTION, index); } @@ -5259,33 +5248,33 @@ static void InvAction() { break; case I_HEADER: // Maximise/unmaximise inventory - if (!InvD[ino].resizable) + if (!g_InvD[g_ino].resizable) break; - if (!InventoryMaximised) { - InvD[ino].sNoofHicons = InvD[ino].NoofHicons; - InvD[ino].sNoofVicons = InvD[ino].NoofVicons; - InvD[ino].NoofHicons = InvD[ino].MaxHicons; - InvD[ino].NoofVicons = InvD[ino].MaxVicons; - InventoryMaximised = true; - - i = InvD[ino].inventoryX; - InvD[ino].inventoryX = InvD[ino].otherX; - InvD[ino].otherX = i; - i = InvD[ino].inventoryY; - InvD[ino].inventoryY = InvD[ino].otherY; - InvD[ino].otherY = i; + if (!g_InventoryMaximised) { + g_InvD[g_ino].sNoofHicons = g_InvD[g_ino].NoofHicons; + g_InvD[g_ino].sNoofVicons = g_InvD[g_ino].NoofVicons; + g_InvD[g_ino].NoofHicons = g_InvD[g_ino].MaxHicons; + g_InvD[g_ino].NoofVicons = g_InvD[g_ino].MaxVicons; + g_InventoryMaximised = true; + + i = g_InvD[g_ino].inventoryX; + g_InvD[g_ino].inventoryX = g_InvD[g_ino].otherX; + g_InvD[g_ino].otherX = i; + i = g_InvD[g_ino].inventoryY; + g_InvD[g_ino].inventoryY = g_InvD[g_ino].otherY; + g_InvD[g_ino].otherY = i; } else { - InvD[ino].NoofHicons = InvD[ino].sNoofHicons; - InvD[ino].NoofVicons = InvD[ino].sNoofVicons; - InventoryMaximised = false; - - i = InvD[ino].inventoryX; - InvD[ino].inventoryX = InvD[ino].otherX; - InvD[ino].otherX = i; - i = InvD[ino].inventoryY; - InvD[ino].inventoryY = InvD[ino].otherY; - InvD[ino].otherY = i; + g_InvD[g_ino].NoofHicons = g_InvD[g_ino].sNoofHicons; + g_InvD[g_ino].NoofVicons = g_InvD[g_ino].sNoofVicons; + g_InventoryMaximised = false; + + i = g_InvD[g_ino].inventoryX; + g_InvD[g_ino].inventoryX = g_InvD[g_ino].otherX; + g_InvD[g_ino].otherX = i; + i = g_InvD[g_ino].inventoryY; + g_InvD[g_ino].inventoryY = g_InvD[g_ino].otherY; + g_InvD[g_ino].otherY = i; } // Delete current, and re-draw @@ -5295,15 +5284,15 @@ static void InvAction() { break; case I_UP: - InvD[ino].FirstDisp -= InvD[ino].NoofHicons; - if (InvD[ino].FirstDisp < 0) - InvD[ino].FirstDisp = 0; - ItemsChanged = true; + g_InvD[g_ino].FirstDisp -= g_InvD[g_ino].NoofHicons; + if (g_InvD[g_ino].FirstDisp < 0) + g_InvD[g_ino].FirstDisp = 0; + g_ItemsChanged = true; break; case I_DOWN: - if (InvD[ino].FirstDisp + InvD[ino].NoofHicons*InvD[ino].NoofVicons < InvD[ino].NoofItems) { - InvD[ino].FirstDisp += InvD[ino].NoofHicons; - ItemsChanged = true; + if (g_InvD[g_ino].FirstDisp + g_InvD[g_ino].NoofHicons*g_InvD[g_ino].NoofVicons < g_InvD[g_ino].NoofItems) { + g_InvD[g_ino].FirstDisp += g_InvD[g_ino].NoofHicons; + g_ItemsChanged = true; } break; } @@ -5319,8 +5308,8 @@ static void InvLook(const Common::Point &coOrds) { case I_BODY: index = InvItem(pt, false); if (index != INV_NOICON) { - if (InvD[ino].contents[index] && InvD[ino].contents[index] != HeldItem) { - invObj = GetInvObject(InvD[ino].contents[index]); + if (g_InvD[g_ino].contents[index] && g_InvD[g_ino].contents[index] != g_heldItem) { + invObj = GetInvObject(g_InvD[g_ino].contents[index]); if (invObj->hScript) InvTinselEvent(invObj, LOOK, INV_LOOK, index); } @@ -5328,7 +5317,7 @@ static void InvLook(const Common::Point &coOrds) { break; case I_NOTIN: - if (ino == INV_CONV) + if (g_ino == INV_CONV) ConvAction(INV_CLOSEICON); KillInventory(); break; @@ -5341,7 +5330,7 @@ static void InvLook(const Common::Point &coOrds) { /**************************************************************************/ extern void EventToInventory(PLR_EVENT pEvent, const Common::Point &coOrds) { - if (InventoryHidden) + if (g_InventoryHidden) return; switch (pEvent) { @@ -5364,7 +5353,7 @@ extern void EventToInventory(PLR_EVENT pEvent, const Common::Point &coOrds) { break; case PLR_ACTION: // PLR_DLEFT - if (InvDragging != ID_MDCONT) + if (g_InvDragging != ID_MDCONT) InvDragEnd(); InvAction(); break; @@ -5380,7 +5369,7 @@ extern void EventToInventory(PLR_EVENT pEvent, const Common::Point &coOrds) { case PLR_ESCAPE: if (MenuActive()) { if (cd.box != optionBox && cd.box != hopperBox1 && cd.box != hopperBox2) - bReOpenMenu = true; + g_bReOpenMenu = true; if ((cd.box == hopperBox1) || (cd.box == hopperBox2)) FreeSceneHopper(); } @@ -5388,42 +5377,42 @@ extern void EventToInventory(PLR_EVENT pEvent, const Common::Point &coOrds) { break; case PLR_PGDN: - if (ino == INV_MENU) { + if (g_ino == INV_MENU) { // Only act if load or save screen MenuPageDown(); } else { // This code is a copy of the IB_SLIDE_DOWN case in InvWalkTo // TODO: So share this duplicate code - if (InvD[ino].NoofVicons == 1) - if (InvD[ino].FirstDisp + InvD[ino].NoofHicons*InvD[ino].NoofVicons < InvD[ino].NoofItems) - InvD[ino].FirstDisp += InvD[ino].NoofHicons; - for (int i = 1; i < InvD[ino].NoofVicons; i++) { - if (InvD[ino].FirstDisp + InvD[ino].NoofHicons*InvD[ino].NoofVicons < InvD[ino].NoofItems) - InvD[ino].FirstDisp += InvD[ino].NoofHicons; + if (g_InvD[g_ino].NoofVicons == 1) + if (g_InvD[g_ino].FirstDisp + g_InvD[g_ino].NoofHicons*g_InvD[g_ino].NoofVicons < g_InvD[g_ino].NoofItems) + g_InvD[g_ino].FirstDisp += g_InvD[g_ino].NoofHicons; + for (int i = 1; i < g_InvD[g_ino].NoofVicons; i++) { + if (g_InvD[g_ino].FirstDisp + g_InvD[g_ino].NoofHicons*g_InvD[g_ino].NoofVicons < g_InvD[g_ino].NoofItems) + g_InvD[g_ino].FirstDisp += g_InvD[g_ino].NoofHicons; } - ItemsChanged = true; + g_ItemsChanged = true; } break; case PLR_PGUP: - if (ino == INV_MENU) { + if (g_ino == INV_MENU) { // Only act if load or save screen MenuPageUp(); } else { // This code is a copy of the I_SLIDE_UP case in InvWalkTo // TODO: So share this duplicate code - if (InvD[ino].NoofVicons == 1) - InvD[ino].FirstDisp -= InvD[ino].NoofHicons; - for (int i = 1; i < InvD[ino].NoofVicons; i++) - InvD[ino].FirstDisp -= InvD[ino].NoofHicons; - if (InvD[ino].FirstDisp < 0) - InvD[ino].FirstDisp = 0; - ItemsChanged = true; + if (g_InvD[g_ino].NoofVicons == 1) + g_InvD[g_ino].FirstDisp -= g_InvD[g_ino].NoofHicons; + for (int i = 1; i < g_InvD[g_ino].NoofVicons; i++) + g_InvD[g_ino].FirstDisp -= g_InvD[g_ino].NoofHicons; + if (g_InvD[g_ino].FirstDisp < 0) + g_InvD[g_ino].FirstDisp = 0; + g_ItemsChanged = true; } break; case PLR_HOME: - if (ino == INV_MENU) { + if (g_ino == INV_MENU) { // Only act if load or save screen if (cd.box == loadBox || cd.box == saveBox) FirstFile(0); @@ -5438,19 +5427,19 @@ extern void EventToInventory(PLR_EVENT pEvent, const Common::Point &coOrds) { cd.selBox = 0; Select(cd.selBox, true); } else { - InvD[ino].FirstDisp = 0; - ItemsChanged = true; + g_InvD[g_ino].FirstDisp = 0; + g_ItemsChanged = true; } break; case PLR_END: - if (ino == INV_MENU) { + if (g_ino == INV_MENU) { if (cd.box == loadBox || cd.box == saveBox) FirstFile(MAX_SAVED_FILES); // Will get reduced to appropriate value else if (cd.box == hopperBox1) - FirstScene(numScenes); // Will get reduced to appropriate value + FirstScene(g_numScenes); // Will get reduced to appropriate value else if (cd.box == hopperBox2) - FirstEntry(numEntries); // Will get reduced to appropriate value + FirstEntry(g_numEntries); // Will get reduced to appropriate value else break; @@ -5458,10 +5447,10 @@ extern void EventToInventory(PLR_EVENT pEvent, const Common::Point &coOrds) { cd.selBox = 0; Select(cd.selBox, true); } else { - InvD[ino].FirstDisp = InvD[ino].NoofItems - InvD[ino].NoofHicons*InvD[ino].NoofVicons; - if (InvD[ino].FirstDisp < 0) - InvD[ino].FirstDisp = 0; - ItemsChanged = true; + g_InvD[g_ino].FirstDisp = g_InvD[g_ino].NoofItems - g_InvD[g_ino].NoofHicons*g_InvD[g_ino].NoofVicons; + if (g_InvD[g_ino].FirstDisp < 0) + g_InvD[g_ino].FirstDisp = 0; + g_ItemsChanged = true; } break; default: @@ -5483,8 +5472,8 @@ extern void SetObjectFilm(int object, SCNHANDLE hFilm) { invObj = GetInvObject(object); invObj->hIconFilm = hFilm; - if (HeldItem != object) - ItemsChanged = true; + if (g_heldItem != object) + g_ItemsChanged = true; } /** @@ -5492,34 +5481,34 @@ extern void SetObjectFilm(int object, SCNHANDLE hFilm) { */ extern void syncInvInfo(Common::Serializer &s) { for (int i = 0; i < NUM_INV; i++) { - s.syncAsSint32LE(InvD[i].MinHicons); - s.syncAsSint32LE(InvD[i].MinVicons); - s.syncAsSint32LE(InvD[i].MaxHicons); - s.syncAsSint32LE(InvD[i].MaxVicons); - s.syncAsSint32LE(InvD[i].NoofHicons); - s.syncAsSint32LE(InvD[i].NoofVicons); + s.syncAsSint32LE(g_InvD[i].MinHicons); + s.syncAsSint32LE(g_InvD[i].MinVicons); + s.syncAsSint32LE(g_InvD[i].MaxHicons); + s.syncAsSint32LE(g_InvD[i].MaxVicons); + s.syncAsSint32LE(g_InvD[i].NoofHicons); + s.syncAsSint32LE(g_InvD[i].NoofVicons); for (int j = 0; j < MAX_ININV; j++) { - s.syncAsSint32LE(InvD[i].contents[j]); + s.syncAsSint32LE(g_InvD[i].contents[j]); } - s.syncAsSint32LE(InvD[i].NoofItems); - s.syncAsSint32LE(InvD[i].FirstDisp); - s.syncAsSint32LE(InvD[i].inventoryX); - s.syncAsSint32LE(InvD[i].inventoryY); - s.syncAsSint32LE(InvD[i].otherX); - s.syncAsSint32LE(InvD[i].otherY); - s.syncAsSint32LE(InvD[i].MaxInvObj); - s.syncAsSint32LE(InvD[i].hInvTitle); - s.syncAsSint32LE(InvD[i].resizable); - s.syncAsSint32LE(InvD[i].bMoveable); - s.syncAsSint32LE(InvD[i].sNoofHicons); - s.syncAsSint32LE(InvD[i].sNoofVicons); - s.syncAsSint32LE(InvD[i].bMax); + s.syncAsSint32LE(g_InvD[i].NoofItems); + s.syncAsSint32LE(g_InvD[i].FirstDisp); + s.syncAsSint32LE(g_InvD[i].inventoryX); + s.syncAsSint32LE(g_InvD[i].inventoryY); + s.syncAsSint32LE(g_InvD[i].otherX); + s.syncAsSint32LE(g_InvD[i].otherY); + s.syncAsSint32LE(g_InvD[i].MaxInvObj); + s.syncAsSint32LE(g_InvD[i].hInvTitle); + s.syncAsSint32LE(g_InvD[i].resizable); + s.syncAsSint32LE(g_InvD[i].bMoveable); + s.syncAsSint32LE(g_InvD[i].sNoofHicons); + s.syncAsSint32LE(g_InvD[i].sNoofVicons); + s.syncAsSint32LE(g_InvD[i].bMax); } if (TinselV2) { - for (int i = 0; i < numObjects; ++i) - s.syncAsUint32LE(invFilms[i]); - s.syncAsUint32LE(heldFilm); + for (int i = 0; i < g_numObjects; ++i) + s.syncAsUint32LE(g_invFilms[i]); + s.syncAsUint32LE(g_heldFilm); } } @@ -5533,18 +5522,18 @@ extern void syncInvInfo(Common::Serializer &s) { */ // Note: the SCHANDLE type here has been changed to a void* extern void RegisterIcons(void *cptr, int num) { - numObjects = num; - invObjects = (INV_OBJECT *) cptr; + g_numObjects = num; + g_invObjects = (INV_OBJECT *) cptr; if (TinselV0) { // In Tinsel 0, the INV_OBJECT structure doesn't have an attributes field, so we // need to 'unpack' the source structures into the standard Tinsel v1/v2 format - MEM_NODE *node = MemoryAllocFixed(numObjects * sizeof(INV_OBJECT)); + MEM_NODE *node = MemoryAllocFixed(g_numObjects * sizeof(INV_OBJECT)); assert(node); - invObjects = (INV_OBJECT *)MemoryDeref(node); - assert(invObjects); + g_invObjects = (INV_OBJECT *)MemoryDeref(node); + assert(g_invObjects); byte *srcP = (byte *)cptr; - INV_OBJECT *destP = (INV_OBJECT *)invObjects; + INV_OBJECT *destP = (INV_OBJECT *)g_invObjects; for (int i = 0; i < num; ++i, ++destP, srcP += 12) { memmove(destP, srcP, 12); @@ -5552,12 +5541,12 @@ extern void RegisterIcons(void *cptr, int num) { } } else if (TinselV1Mac) { // Macintosh version has BE encoded resources, so the values need to be byte swapped - MEM_NODE *node = MemoryAllocFixed(numObjects * sizeof(INV_OBJECT)); + MEM_NODE *node = MemoryAllocFixed(g_numObjects * sizeof(INV_OBJECT)); assert(node); - invObjects = (INV_OBJECT *)MemoryDeref(node); - assert(invObjects); + g_invObjects = (INV_OBJECT *)MemoryDeref(node); + assert(g_invObjects); INV_OBJECT *srcP = (INV_OBJECT *)cptr; - INV_OBJECT *destP = (INV_OBJECT *)invObjects; + INV_OBJECT *destP = (INV_OBJECT *)g_invObjects; for (int i = 0; i < num; ++i, ++destP, ++srcP) { destP->id = FROM_BE_32(srcP->id); @@ -5566,14 +5555,14 @@ extern void RegisterIcons(void *cptr, int num) { destP->attribute = FROM_BE_32(srcP->attribute); } } else if (TinselV2) { - if (invFilms == NULL) { + if (g_invFilms == NULL) { // First time - allocate memory - MEM_NODE *node = MemoryAllocFixed(numObjects * sizeof(SCNHANDLE)); + MEM_NODE *node = MemoryAllocFixed(g_numObjects * sizeof(SCNHANDLE)); assert(node); - invFilms = (SCNHANDLE *)MemoryDeref(node); - if (invFilms == NULL) + g_invFilms = (SCNHANDLE *)MemoryDeref(node); + if (g_invFilms == NULL) error(NO_MEM, "inventory scripts"); - memset(invFilms, 0, numObjects * sizeof(SCNHANDLE)); + memset(g_invFilms, 0, g_numObjects * sizeof(SCNHANDLE)); } @@ -5581,11 +5570,11 @@ extern void RegisterIcons(void *cptr, int num) { // and store all the films separately int i; INV_OBJECT *pio; - for (i = 0, pio = invObjects; i < numObjects; i++, pio++) { + for (i = 0, pio = g_invObjects; i < g_numObjects; i++, pio++) { if (pio->attribute & PERMACONV) PermaConvIcon(pio->id, pio->attribute & CONVENDITEM); - invFilms[i] = pio->hIconFilm; + g_invFilms[i] = pio->hIconFilm; } } } @@ -5599,7 +5588,7 @@ extern void setInvWinParts(SCNHANDLE hf) { const FILM *pfilm; #endif - hWinParts = hf; + g_hWinParts = hf; #ifdef DEBUG pfilm = (const FILM *)LockMem(hf); @@ -5616,7 +5605,7 @@ extern void setFlagFilms(SCNHANDLE hf) { const FILM *pfilm; #endif - flagFilm = hf; + g_flagFilm = hf; #ifdef DEBUG pfilm = (const FILM *)LockMem(hf); @@ -5628,7 +5617,7 @@ extern void setFlagFilms(SCNHANDLE hf) { * Called from Glitter function 'DecCStrings()' */ extern void setConfigStrings(SCNHANDLE *tp) { - memcpy(configStrings, tp, sizeof(configStrings)); + memcpy(g_configStrings, tp, sizeof(g_configStrings)); } /** @@ -5652,36 +5641,36 @@ extern void idec_inv(int num, SCNHANDLE text, int MaxContents, if (StartHeight > MaxHeight) StartHeight = MaxHeight; - InventoryState = IDLE_INV; + g_InventoryState = IDLE_INV; - InvD[num].MaxHicons = MaxWidth; - InvD[num].MinHicons = MinWidth; - InvD[num].MaxVicons = MaxHeight; - InvD[num].MinVicons = MinHeight; + g_InvD[num].MaxHicons = MaxWidth; + g_InvD[num].MinHicons = MinWidth; + g_InvD[num].MaxVicons = MaxHeight; + g_InvD[num].MinVicons = MinHeight; - InvD[num].NoofHicons = StartWidth; - InvD[num].NoofVicons = StartHeight; + g_InvD[num].NoofHicons = StartWidth; + g_InvD[num].NoofVicons = StartHeight; - memset(InvD[num].contents, 0, sizeof(InvD[num].contents)); - InvD[num].NoofItems = 0; + memset(g_InvD[num].contents, 0, sizeof(g_InvD[num].contents)); + g_InvD[num].NoofItems = 0; - InvD[num].FirstDisp = 0; + g_InvD[num].FirstDisp = 0; - InvD[num].inventoryX = startx; - InvD[num].inventoryY = starty; - InvD[num].otherX = 21; - InvD[num].otherY = 15; + g_InvD[num].inventoryX = startx; + g_InvD[num].inventoryY = starty; + g_InvD[num].otherX = 21; + g_InvD[num].otherY = 15; - InvD[num].MaxInvObj = MaxContents; + g_InvD[num].MaxInvObj = MaxContents; - InvD[num].hInvTitle = text; + g_InvD[num].hInvTitle = text; if (MaxWidth != MinWidth && MaxHeight != MinHeight) - InvD[num].resizable = true; + g_InvD[num].resizable = true; - InvD[num].bMoveable = moveable; + g_InvD[num].bMoveable = moveable; - InvD[num].bMax = false; + g_InvD[num].bMax = false; } /** @@ -5729,7 +5718,7 @@ extern void idec_inv2(SCNHANDLE text, int MaxContents, extern int InvGetLimit(int invno) { assert(invno == INV_1 || invno == INV_2); // only INV_1 and INV_2 supported - return InvD[invno].MaxInvObj; + return g_InvD[invno].MaxInvObj; } /** @@ -5737,12 +5726,12 @@ extern int InvGetLimit(int invno) { */ extern void InvSetLimit(int invno, int MaxContents) { assert(invno == INV_1 || invno == INV_2); // only INV_1 and INV_2 supported - assert(MaxContents >= InvD[invno].NoofItems); // can't reduce maximum contents below current contents + assert(MaxContents >= g_InvD[invno].NoofItems); // can't reduce maximum contents below current contents if (MaxContents > MAX_ININV) MaxContents = MAX_ININV; // Max contents - InvD[invno].MaxInvObj = MaxContents; + g_InvD[invno].MaxInvObj = MaxContents; } /** @@ -5757,34 +5746,34 @@ extern void InvSetSize(int invno, int MinWidth, int MinHeight, if (StartHeight > MaxHeight) StartHeight = MaxHeight; - InvD[invno].MaxHicons = MaxWidth; - InvD[invno].MinHicons = MinWidth; - InvD[invno].MaxVicons = MaxHeight; - InvD[invno].MinVicons = MinHeight; + g_InvD[invno].MaxHicons = MaxWidth; + g_InvD[invno].MinHicons = MinWidth; + g_InvD[invno].MaxVicons = MaxHeight; + g_InvD[invno].MinVicons = MinHeight; - InvD[invno].NoofHicons = StartWidth; - InvD[invno].NoofVicons = StartHeight; + g_InvD[invno].NoofHicons = StartWidth; + g_InvD[invno].NoofVicons = StartHeight; if (MaxWidth != MinWidth && MaxHeight != MinHeight) - InvD[invno].resizable = true; + g_InvD[invno].resizable = true; else - InvD[invno].resizable = false; + g_InvD[invno].resizable = false; - InvD[invno].bMax = false; + g_InvD[invno].bMax = false; } /**************************************************************************/ extern bool IsTopWindow() { - return (InventoryState == BOGUS_INV); + return (g_InventoryState == BOGUS_INV); } extern bool MenuActive() { - return (InventoryState == ACTIVE_INV && ino == INV_CONF); + return (g_InventoryState == ACTIVE_INV && g_ino == INV_CONF); } extern bool IsConvWindow() { - return (InventoryState == ACTIVE_INV && ino == INV_CONV); + return (g_InventoryState == ACTIVE_INV && g_ino == INV_CONV); } } // End of namespace Tinsel diff --git a/engines/tinsel/drives.cpp b/engines/tinsel/drives.cpp index 5977d3b718..d815fd165d 100644 --- a/engines/tinsel/drives.cpp +++ b/engines/tinsel/drives.cpp @@ -32,13 +32,13 @@ namespace Tinsel { // FIXME: Avoid non-const global vars -char currentCD = '1'; +char g_currentCD = '1'; -static bool bChangingCD = false; -static char nextCD = '\0'; +static bool g_bChangingCD = false; +static char g_nextCD = '\0'; -static uint32 lastTime = 0; -extern LANGUAGE sampleLanguage; +static uint32 g_lastTime = 0; +extern LANGUAGE g_sampleLanguage; void CdCD(CORO_PARAM) { @@ -47,7 +47,7 @@ void CdCD(CORO_PARAM) { CORO_BEGIN_CODE(_ctx); - while (bChangingCD) { + while (g_bChangingCD) { if (g_scheduler->getCurrentProcess()) { // FIXME: CdCD gets passed a nullContext in RegisterGlobals() and // PrimeSceneHopper(), because I didn't know how to get a proper @@ -66,13 +66,13 @@ void CdCD(CORO_PARAM) { int GetCurrentCD() { // count from 1 - return (currentCD - '1' + 1); + return (g_currentCD - '1' + 1); } static const uint32 cdFlags[] = { fCd1, fCd2, fCd3, fCd4, fCd5, fCd6, fCd7, fCd8 }; void SetCD(int flags) { - if (flags & cdFlags[currentCD - '1']) + if (flags & cdFlags[g_currentCD - '1']) return; error("SetCD() problem"); @@ -82,7 +82,7 @@ int GetCD(int flags) { int i; char cd = '\0'; - if (flags & cdFlags[currentCD - '1']) + if (flags & cdFlags[g_currentCD - '1']) return GetCurrentCD(); for (i = 0; i < 8; i++) { @@ -93,19 +93,19 @@ int GetCD(int flags) { } assert(i != 8); - nextCD = cd; + g_nextCD = cd; return cd; } void DoCdChange() { - if (bChangingCD && (g_system->getMillis() > (lastTime + 1000))) { - lastTime = g_system->getMillis(); + if (g_bChangingCD && (g_system->getMillis() > (g_lastTime + 1000))) { + g_lastTime = g_system->getMillis(); _vm->_sound->closeSampleStream(); // Use the filesize of the sample file to determine, for Discworld 2, which CD it is if (TinselV2) { TinselFile f; - if (!f.open(_vm->getSampleFile(sampleLanguage))) + if (!f.open(_vm->getSampleFile(g_sampleLanguage))) // No CD present return; @@ -113,28 +113,28 @@ void DoCdChange() { f.close(); - if (currentCD != sampleCdNumber) + if (g_currentCD != sampleCdNumber) return; } _vm->_sound->openSampleFiles(); ChangeLanguage(TextLanguage()); - bChangingCD = false; + g_bChangingCD = false; } } void SetNextCD(int cdNumber) { assert(cdNumber == 1 || cdNumber == 2); - nextCD = (char)(cdNumber + '1' - 1); + g_nextCD = (char)(cdNumber + '1' - 1); } bool GotoCD() { // WORKAROUND: Somehow, CdDoChange() is called twice... Hopefully, this guard helps - if (currentCD == nextCD) + if (g_currentCD == g_nextCD) return false; - currentCD = nextCD; + g_currentCD = g_nextCD; /* if (bNoCD) { strcpy(cdDirectory, hdDirectory); @@ -142,7 +142,7 @@ bool GotoCD() { strcat(cdDirectory, cdLastBit); } */ - bChangingCD = true; + g_bChangingCD = true; return true; } diff --git a/engines/tinsel/events.cpp b/engines/tinsel/events.cpp index e701ddca99..74454c5f2a 100644 --- a/engines/tinsel/events.cpp +++ b/engines/tinsel/events.cpp @@ -54,37 +54,37 @@ extern HPOLYGON GetTaggedPoly(); //----------------- EXTERNAL GLOBAL DATA --------------------- -extern bool bEnableMenu; +extern bool g_bEnableMenu; //----------------- LOCAL GLOBAL DATA -------------------- // FIXME: Avoid non-const global vars -static uint32 lastUserEvent = 0; // Time it hapenned -static int leftEvents = 0; // Single or double, left or right. Or escape key. -static int escEvents = 1; // Escape key -static int userEvents = 0; // Whenever a button or a key comes in +static uint32 g_lastUserEvent = 0; // Time it hapenned +static int g_leftEvents = 0; // Single or double, left or right. Or escape key. +static int g_escEvents = 1; // Escape key +static int g_userEvents = 0; // Whenever a button or a key comes in -static int eCount = 0; +static int g_eCount = 0; -static int controlState; -static bool bStartOff; +static int g_controlState; +static bool g_bStartOff; -static int controlX, controlY; -static bool bProvNotProcessed = false; +static int g_controlX, g_controlY; +static bool g_bProvNotProcessed = false; /** * Gets called before each schedule, only 1 user action per schedule * is allowed. */ void ResetEcount() { - eCount = 0; + g_eCount = 0; } void IncUserEvents() { - userEvents++; - lastUserEvent = DwGetCurrentTime(); + g_userEvents++; + g_lastUserEvent = DwGetCurrentTime(); } /** @@ -104,7 +104,7 @@ void AllowDclick(CORO_PARAM, PLR_EVENT be) { FreeToken(TOKEN_LEFT_BUT); // Prevent activation of 2 events on the same tick - if (++eCount != 1) + if (++g_eCount != 1) CORO_KILL_SELF(); break; @@ -125,17 +125,17 @@ void ControlOn() { return; } - bEnableMenu = false; + g_bEnableMenu = false; - if (controlState == CONTROL_OFF) { + if (g_controlState == CONTROL_OFF) { // Control is on - controlState = CONTROL_ON; + g_controlState = CONTROL_ON; // Restore cursor to where it was - if (bStartOff == true) - bStartOff = false; + if (g_bStartOff == true) + g_bStartOff = false; else - SetCursorXY(controlX, controlY); + SetCursorXY(g_controlX, g_controlY); // Re-instate cursor UnHideCursor(); @@ -155,14 +155,14 @@ void ControlOff() { return; } - bEnableMenu = false; + g_bEnableMenu = false; - if (controlState == CONTROL_ON) { + if (g_controlState == CONTROL_ON) { // Control is off - controlState = CONTROL_OFF; + g_controlState = CONTROL_OFF; // Store cursor position - GetCursorXY(&controlX, &controlY, true); + GetCursorXY(&g_controlX, &g_controlY, true); // Blank out cursor DwHideCursor(); @@ -181,10 +181,10 @@ void ControlStartOff() { return; } - bEnableMenu = false; + g_bEnableMenu = false; // Control is off - controlState = CONTROL_OFF; + g_controlState = CONTROL_OFF; // Blank out cursor DwHideCursor(); @@ -192,7 +192,7 @@ void ControlStartOff() { // Switch off tags DisableTags(); - bStartOff = true; + g_bStartOff = true; } /** @@ -211,7 +211,7 @@ bool GetControl(int param) { } bool GetControl() { - if (controlState == CONTROL_ON) { + if (g_controlState == CONTROL_ON) { ControlOff(); return true; } else @@ -220,7 +220,7 @@ bool GetControl() { bool ControlIsOn() { if (TinselV2) - return (controlState == CONTROL_ON); + return (g_controlState == CONTROL_ON); return TestToken(TOKEN_CONTROL); } @@ -289,7 +289,7 @@ static void ProcessUserEvent(TINSEL_EVENT uEvent, const Common::Point &coOrds, P HPOLYGON hPoly; // Prevent activation of 2 events on the same tick - if (++eCount != 1) + if (++g_eCount != 1) return; if ((actor = GetTaggedActor()) != 0) { @@ -395,19 +395,19 @@ void PlayerEvent(PLR_EVENT pEvent, const Common::Point &coOrds) { static uint32 lastRealAction = 0; // FIXME: Avoid non-const global vars // This stuff to allow F1 key during startup. - if (bEnableMenu && pEvent == PLR_MENU) + if (g_bEnableMenu && pEvent == PLR_MENU) Control(CONTROL_ON); else IncUserEvents(); if (pEvent == PLR_ESCAPE) { - ++escEvents; - ++leftEvents; // Yes, I do mean this + ++g_escEvents; + ++g_leftEvents; // Yes, I do mean this } else if ((pEvent == PLR_PROV_WALKTO) || (pEvent == PLR_WALKTO) || (pEvent == PLR_LOOK) || (pEvent == PLR_ACTION)) { - ++leftEvents; + ++g_leftEvents; } // Only allow events if player control is on @@ -484,18 +484,18 @@ void PlayerEvent(PLR_EVENT pEvent, const Common::Point &coOrds) { * For ESCapable Glitter sequences */ int GetEscEvents() { - return escEvents; + return g_escEvents; } /** * For cutting short talk()s etc. */ int GetLeftEvents() { - return leftEvents; + return g_leftEvents; } bool LeftEventChange(int myleftEvent) { - if (leftEvents != myleftEvent) { + if (g_leftEvents != myleftEvent) { ProcessedProvisional(); return true; } else @@ -506,15 +506,15 @@ bool LeftEventChange(int myleftEvent) { * For waitkey() Glitter function */ int getUserEvents() { - return userEvents; + return g_userEvents; } uint32 getUserEventTime() { - return DwGetCurrentTime() - lastUserEvent; + return DwGetCurrentTime() - g_lastUserEvent; } void resetUserEventTime() { - lastUserEvent = DwGetCurrentTime(); + g_lastUserEvent = DwGetCurrentTime(); } struct PTP_INIT { @@ -655,18 +655,18 @@ void effRunPolyTinselCode(HPOLYGON hPoly, TINSEL_EVENT event, int actor) { * subsequent 'real' event. */ void ProcessedProvisional() { - bProvNotProcessed = false; + g_bProvNotProcessed = false; } /** * Resets the bProvNotProcessed flag */ void ProvNotProcessed() { - bProvNotProcessed = true; + g_bProvNotProcessed = true; } bool GetProvNotProcessed() { - return bProvNotProcessed; + return g_bProvNotProcessed; } } // End of namespace Tinsel diff --git a/engines/tinsel/font.cpp b/engines/tinsel/font.cpp index e857dca509..54aa7cc15f 100644 --- a/engines/tinsel/font.cpp +++ b/engines/tinsel/font.cpp @@ -34,38 +34,38 @@ namespace Tinsel { // FIXME: Avoid non-const global vars -static char tBuffer[TBUFSZ]; +static char g_tBuffer[TBUFSZ]; -static SCNHANDLE hTagFont = 0, hTalkFont = 0; -static SCNHANDLE hRegularTalkFont = 0, hRegularTagFont = 0; +static SCNHANDLE g_hTagFont = 0, g_hTalkFont = 0; +static SCNHANDLE g_hRegularTalkFont = 0, g_hRegularTagFont = 0; /** * Return address of tBuffer */ char *TextBufferAddr() { - return tBuffer; + return g_tBuffer; } /** * Return hTagFont handle. */ SCNHANDLE GetTagFontHandle() { - return hTagFont; + return g_hTagFont; } /** * Return hTalkFont handle. */ SCNHANDLE GetTalkFontHandle() { - return hTalkFont; + return g_hTalkFont; } /** * Called from dec_tagfont() Glitter function. Store the tag font handle. */ void SetTagFontHandle(SCNHANDLE hFont) { - hTagFont = hRegularTagFont = hFont; // Store the font handle + g_hTagFont = g_hRegularTagFont = hFont; // Store the font handle } /** @@ -73,20 +73,20 @@ void SetTagFontHandle(SCNHANDLE hFont) { * Store the talk font handle. */ void SetTalkFontHandle(SCNHANDLE hFont) { - hTalkFont = hRegularTalkFont = hFont; // Store the font handle + g_hTalkFont = g_hRegularTalkFont = hFont; // Store the font handle } void SetTempTagFontHandle(SCNHANDLE hFont) { - hTagFont = hFont; + g_hTagFont = hFont; } void SetTempTalkFontHandle(SCNHANDLE hFont) { - hTalkFont = hFont; + g_hTalkFont = hFont; } void ResetFontHandles() { - hTagFont = hRegularTagFont; - hTalkFont = hRegularTalkFont; + g_hTagFont = g_hRegularTagFont; + g_hTalkFont = g_hRegularTalkFont; } @@ -98,17 +98,17 @@ void FettleFontPal(SCNHANDLE fontPal) { IMAGE *pImg; assert(fontPal); - assert(hTagFont); // Tag font not declared - assert(hTalkFont); // Talk font not declared + assert(g_hTagFont); // Tag font not declared + assert(g_hTalkFont); // Talk font not declared - pFont = (const FONT *)LockMem(hTagFont); + pFont = (const FONT *)LockMem(g_hTagFont); pImg = (IMAGE *)LockMem(FROM_LE_32(pFont->fontInit.hObjImg)); // get image for char 0 if (!TinselV2) pImg->hImgPal = TO_LE_32(fontPal); else pImg->hImgPal = 0; - pFont = (const FONT *)LockMem(hTalkFont); + pFont = (const FONT *)LockMem(g_hTalkFont); pImg = (IMAGE *)LockMem(FROM_LE_32(pFont->fontInit.hObjImg)); // get image for char 0 if (!TinselV2) pImg->hImgPal = TO_LE_32(fontPal); diff --git a/engines/tinsel/graphics.cpp b/engines/tinsel/graphics.cpp index 4f3cc36994..9b06b1a501 100644 --- a/engines/tinsel/graphics.cpp +++ b/engines/tinsel/graphics.cpp @@ -40,7 +40,7 @@ namespace Tinsel { #define CHAR_WIDTH 4 #define CHAR_HEIGHT 4 -extern uint8 transPalette[MAX_COLORS]; +extern uint8 g_transPalette[MAX_COLORS]; //----------------- SUPPORT FUNCTIONS --------------------- @@ -559,7 +559,7 @@ static void WrtTrans(DRAWOBJECT *pObj, uint8 *destP, bool applyClipping) { // Loop through any remaining lines while (pObj->height > 0) { for (int i = 0; i < pObj->width; ++i, ++destP) - *destP = transPalette[*destP]; + *destP = g_transPalette[*destP]; --pObj->height; destP += lineOffset; diff --git a/engines/tinsel/handle.cpp b/engines/tinsel/handle.cpp index eeb83b1f98..e31b2141f5 100644 --- a/engines/tinsel/handle.cpp +++ b/engines/tinsel/handle.cpp @@ -69,17 +69,17 @@ enum { // FIXME: Avoid non-const global vars // handle table gets loaded from index file at runtime -static MEMHANDLE *handleTable = 0; +static MEMHANDLE *g_handleTable = 0; // number of handles in the handle table -static uint numHandles = 0; +static uint g_numHandles = 0; -static uint32 cdPlayHandle = (uint32)-1; +static uint32 g_cdPlayHandle = (uint32)-1; -static SCNHANDLE cdBaseHandle = 0, cdTopHandle = 0; -static Common::File *cdGraphStream = 0; +static SCNHANDLE g_cdBaseHandle = 0, g_cdTopHandle = 0; +static Common::File *g_cdGraphStream = 0; -static char szCdPlayFile[100]; +static char g_szCdPlayFile[100]; //----------------- FORWARD REFERENCES -------------------- @@ -110,24 +110,24 @@ void SetupHandleTable() { } // calc number of handles - numHandles = len / RECORD_SIZE; + g_numHandles = len / RECORD_SIZE; // allocate memory for the index file - handleTable = (MEMHANDLE *)calloc(numHandles, sizeof(struct MEMHANDLE)); + g_handleTable = (MEMHANDLE *)calloc(g_numHandles, sizeof(struct MEMHANDLE)); // make sure memory allocated - assert(handleTable); + assert(g_handleTable); // load data - for (i = 0; i < numHandles; i++) { - f.read(handleTable[i].szName, 12); - handleTable[i].filesize = f.readUint32(); + for (i = 0; i < g_numHandles; i++) { + f.read(g_handleTable[i].szName, 12); + g_handleTable[i].filesize = f.readUint32(); // The pointer should always be NULL. We don't // need to read that from the file. - handleTable[i]._node = NULL; + g_handleTable[i]._node = NULL; f.seek(4, SEEK_CUR); // For Discworld 2, read in the flags2 field - handleTable[i].flags2 = t2Flag ? f.readUint32() : 0; + g_handleTable[i].flags2 = t2Flag ? f.readUint32() : 0; } if (f.eos() || f.err()) { @@ -145,7 +145,7 @@ void SetupHandleTable() { } // allocate memory nodes and load all permanent graphics - for (i = 0, pH = handleTable; i < numHandles; i++, pH++) { + for (i = 0, pH = g_handleTable; i < g_numHandles; i++, pH++) { if (pH->filesize & fPreload) { // allocate a fixed memory node for permanent files pH->_node = MemoryAllocFixed((pH->filesize & FSIZE_MASK)); @@ -172,24 +172,24 @@ void SetupHandleTable() { } void FreeHandleTable() { - free(handleTable); - handleTable = NULL; + free(g_handleTable); + g_handleTable = NULL; - delete cdGraphStream; - cdGraphStream = NULL; + delete g_cdGraphStream; + g_cdGraphStream = NULL; } /** * Loads a memory block as a file. */ void OpenCDGraphFile() { - delete cdGraphStream; + delete g_cdGraphStream; // As the theory goes, the right CD will be in there! - cdGraphStream = new Common::File; - if (!cdGraphStream->open(szCdPlayFile)) - error(CANNOT_FIND_FILE, szCdPlayFile); + g_cdGraphStream = new Common::File; + if (!g_cdGraphStream->open(g_szCdPlayFile)) + error(CANNOT_FIND_FILE, g_szCdPlayFile); } void LoadCDGraphData(MEMHANDLE *pH) { @@ -210,15 +210,15 @@ void LoadCDGraphData(MEMHANDLE *pH) { assert(addr); // Move to correct place in file and load the required data - assert(cdGraphStream); - cdGraphStream->seek(cdBaseHandle & OFFSETMASK, SEEK_SET); - bytes = cdGraphStream->read(addr, (cdTopHandle - cdBaseHandle) & OFFSETMASK); + assert(g_cdGraphStream); + g_cdGraphStream->seek(g_cdBaseHandle & OFFSETMASK, SEEK_SET); + bytes = g_cdGraphStream->read(addr, (g_cdTopHandle - g_cdBaseHandle) & OFFSETMASK); // New code to try and handle CD read failures 24/2/97 - while (bytes != ((cdTopHandle - cdBaseHandle) & OFFSETMASK) && retries++ < MAX_READ_RETRIES) { + while (bytes != ((g_cdTopHandle - g_cdBaseHandle) & OFFSETMASK) && retries++ < MAX_READ_RETRIES) { // Try again - cdGraphStream->seek(cdBaseHandle & OFFSETMASK, SEEK_SET); - bytes = cdGraphStream->read(addr, (cdTopHandle - cdBaseHandle) & OFFSETMASK); + g_cdGraphStream->seek(g_cdBaseHandle & OFFSETMASK, SEEK_SET); + bytes = g_cdGraphStream->read(addr, (g_cdTopHandle - g_cdBaseHandle) & OFFSETMASK); } // discardable - unlock the memory @@ -230,7 +230,7 @@ void LoadCDGraphData(MEMHANDLE *pH) { // clear the loading flag // pH->filesize &= ~fLoading; - if (bytes != ((cdTopHandle - cdBaseHandle) & OFFSETMASK)) + if (bytes != ((g_cdTopHandle - g_cdBaseHandle) & OFFSETMASK)) // file is corrupt error(FILE_READ_ERROR, "CD play file"); } @@ -245,22 +245,22 @@ void LoadCDGraphData(MEMHANDLE *pH) { void LoadExtraGraphData(SCNHANDLE start, SCNHANDLE next) { OpenCDGraphFile(); - MemoryDiscard((handleTable + cdPlayHandle)->_node); // Free it + MemoryDiscard((g_handleTable + g_cdPlayHandle)->_node); // Free it // It must always be the same - assert(cdPlayHandle == (start >> SCNHANDLE_SHIFT)); - assert(cdPlayHandle == (next >> SCNHANDLE_SHIFT)); + assert(g_cdPlayHandle == (start >> SCNHANDLE_SHIFT)); + assert(g_cdPlayHandle == (next >> SCNHANDLE_SHIFT)); - cdBaseHandle = start; - cdTopHandle = next; + g_cdBaseHandle = start; + g_cdTopHandle = next; } void SetCdPlaySceneDetails(int fileNum, const char *fileName) { - strcpy(szCdPlayFile, fileName); + strcpy(g_szCdPlayFile, fileName); } void SetCdPlayHandle(int fileNum) { - cdPlayHandle = fileNum; + g_cdPlayHandle = fileNum; } @@ -323,26 +323,26 @@ byte *LockMem(SCNHANDLE offset) { MEMHANDLE *pH; // points to table entry // range check the memory handle - assert(handle < numHandles); + assert(handle < g_numHandles); #ifdef DEBUG if (handle != s_lockedScene) warning(" Calling LockMem(0x%x), handle %d differs from active scene %d", offset, handle, s_lockedScene); #endif - pH = handleTable + handle; + pH = g_handleTable + handle; if (pH->filesize & fPreload) { // permanent files are already loaded, nothing to be done - } else if (handle == cdPlayHandle) { + } else if (handle == g_cdPlayHandle) { // Must be in currently loaded/loadable range - if (offset < cdBaseHandle || offset >= cdTopHandle) + if (offset < g_cdBaseHandle || offset >= g_cdTopHandle) error("Overlapping (in time) CD-plays"); // May have been discarded, if so, we have to reload if (!MemoryDeref(pH->_node)) { // Data was discarded, we have to reload - MemoryReAlloc(pH->_node, cdTopHandle - cdBaseHandle); + MemoryReAlloc(pH->_node, g_cdTopHandle - g_cdBaseHandle); LoadCDGraphData(pH); @@ -353,7 +353,7 @@ byte *LockMem(SCNHANDLE offset) { // make sure address is valid assert(pH->filesize & fLoaded); - offset -= cdBaseHandle; + offset -= g_cdBaseHandle; } else { if (!MemoryDeref(pH->_node)) { // Data was discarded, we have to reload @@ -387,9 +387,9 @@ void LockScene(SCNHANDLE offset) { #endif // range check the memory handle - assert(handle < numHandles); + assert(handle < g_numHandles); - pH = handleTable + handle; + pH = g_handleTable + handle; if ((pH->filesize & fPreload) == 0) { // Ensure the scene handle is allocated. @@ -414,9 +414,9 @@ void UnlockScene(SCNHANDLE offset) { MEMHANDLE *pH; // points to table entry // range check the memory handle - assert(handle < numHandles); + assert(handle < g_numHandles); - pH = handleTable + handle; + pH = g_handleTable + handle; if ((pH->filesize & fPreload) == 0) { // unlock the scene data @@ -441,9 +441,9 @@ bool ValidHandle(SCNHANDLE offset) { MEMHANDLE *pH; // points to table entry // range check the memory handle - assert(handle < numHandles); + assert(handle < g_numHandles); - pH = handleTable + handle; + pH = g_handleTable + handle; return (pH->filesize & FSIZE_MASK) != 8; } @@ -458,7 +458,7 @@ void TouchMem(SCNHANDLE offset) { uint32 handle = offset >> SCNHANDLE_SHIFT; // calc memory handle to use if (offset != 0) { - pH = handleTable + handle; + pH = g_handleTable + handle; // update the LRU time whether its loaded or not! if (pH->_node) @@ -474,9 +474,9 @@ bool IsCdPlayHandle(SCNHANDLE offset) { uint32 handle = offset >> SCNHANDLE_SHIFT; // calc memory handle to use // range check the memory handle - assert(handle < numHandles); + assert(handle < g_numHandles); - return (handle == cdPlayHandle); + return (handle == g_cdPlayHandle); } /** @@ -486,9 +486,9 @@ int CdNumber(SCNHANDLE offset) { uint handle = offset >> SCNHANDLE_SHIFT; // calc memory handle to use // range check the memory handle - assert(handle < numHandles); + assert(handle < g_numHandles); - MEMHANDLE *pH = handleTable + handle; + MEMHANDLE *pH = g_handleTable + handle; if (!TinselV2) return 1; diff --git a/engines/tinsel/heapmem.cpp b/engines/tinsel/heapmem.cpp index 819493bda1..597cc69e66 100644 --- a/engines/tinsel/heapmem.cpp +++ b/engines/tinsel/heapmem.cpp @@ -58,16 +58,16 @@ static const uint32 MemoryPoolSize[3] = {5 * 1024 * 1024, 5 * 1024 * 1024, 10 * // list of all memory nodes -MEM_NODE mnodeList[NUM_MNODES]; +MEM_NODE g_mnodeList[NUM_MNODES]; // pointer to the linked list of free mnodes -static MEM_NODE *pFreeMemNodes; +static MEM_NODE *g_pFreeMemNodes; // list of all fixed memory nodes -MEM_NODE s_fixedMnodesList[5]; +MEM_NODE g_s_fixedMnodesList[5]; // the mnode heap sentinel -static MEM_NODE heapSentinel; +static MEM_NODE g_heapSentinel; // static MEM_NODE *AllocMemNode(); @@ -80,7 +80,7 @@ static void MemoryStats() { int lockedSize = 0; int totalSize = 0; - const MEM_NODE *pHeap = &heapSentinel; + const MEM_NODE *pHeap = &g_heapSentinel; MEM_NODE *pCur; for (pCur = pHeap->pNext; pCur != pHeap; pCur = pCur->pNext) { @@ -104,43 +104,43 @@ static void MemoryStats() { */ void MemoryInit() { // place first node on free list - pFreeMemNodes = mnodeList; + g_pFreeMemNodes = g_mnodeList; // link all other objects after first - memset(mnodeList, 0, sizeof(mnodeList)); + memset(g_mnodeList, 0, sizeof(g_mnodeList)); for (int i = 1; i < NUM_MNODES; i++) { - mnodeList[i - 1].pNext = mnodeList + i; + g_mnodeList[i - 1].pNext = g_mnodeList + i; } // null the last mnode - mnodeList[NUM_MNODES - 1].pNext = NULL; + g_mnodeList[NUM_MNODES - 1].pNext = NULL; // clear list of fixed memory nodes - memset(s_fixedMnodesList, 0, sizeof(s_fixedMnodesList)); + memset(g_s_fixedMnodesList, 0, sizeof(g_s_fixedMnodesList)); // set cyclic links to the sentinel - heapSentinel.pPrev = &heapSentinel; - heapSentinel.pNext = &heapSentinel; + g_heapSentinel.pPrev = &g_heapSentinel; + g_heapSentinel.pNext = &g_heapSentinel; // flag sentinel as locked - heapSentinel.flags = DWM_LOCKED | DWM_SENTINEL; + g_heapSentinel.flags = DWM_LOCKED | DWM_SENTINEL; // store the current heap size in the sentinel uint32 size = MemoryPoolSize[0]; if (TinselVersion == TINSEL_V1) size = MemoryPoolSize[1]; else if (TinselVersion == TINSEL_V2) size = MemoryPoolSize[2]; - heapSentinel.size = size; + g_heapSentinel.size = size; } /** * Deinitializes the memory manager. */ void MemoryDeinit() { - const MEM_NODE *pHeap = &heapSentinel; + const MEM_NODE *pHeap = &g_heapSentinel; MEM_NODE *pCur; - pCur = s_fixedMnodesList; - for (int i = 0; i < ARRAYSIZE(s_fixedMnodesList); ++i, ++pCur) { + pCur = g_s_fixedMnodesList; + for (int i = 0; i < ARRAYSIZE(g_s_fixedMnodesList); ++i, ++pCur) { free(pCur->pBaseAddr); pCur->pBaseAddr = 0; } @@ -157,13 +157,13 @@ void MemoryDeinit() { */ static MEM_NODE *AllocMemNode() { // get the first free mnode - MEM_NODE *pMemNode = pFreeMemNodes; + MEM_NODE *pMemNode = g_pFreeMemNodes; // make sure a mnode is available assert(pMemNode); // Out of memory nodes // the next free mnode - pFreeMemNodes = pMemNode->pNext; + g_pFreeMemNodes = pMemNode->pNext; // wipe out the mnode memset(pMemNode, 0, sizeof(MEM_NODE)); @@ -178,13 +178,13 @@ static MEM_NODE *AllocMemNode() { */ void FreeMemNode(MEM_NODE *pMemNode) { // validate mnode pointer - assert(pMemNode >= mnodeList && pMemNode <= mnodeList + NUM_MNODES - 1); + assert(pMemNode >= g_mnodeList && pMemNode <= g_mnodeList + NUM_MNODES - 1); // place free list in mnode next - pMemNode->pNext = pFreeMemNodes; + pMemNode->pNext = g_pFreeMemNodes; // add mnode to top of free list - pFreeMemNodes = pMemNode; + g_pFreeMemNodes = pMemNode; } @@ -194,11 +194,11 @@ void FreeMemNode(MEM_NODE *pMemNode) { * @return true if any blocks were discarded, false otherwise */ static bool HeapCompact(long size) { - const MEM_NODE *pHeap = &heapSentinel; + const MEM_NODE *pHeap = &g_heapSentinel; MEM_NODE *pCur, *pOldest; uint32 oldest; // time of the oldest discardable block - while (heapSentinel.size < size) { + while (g_heapSentinel.size < size) { // find the oldest discardable block oldest = DwGetCurrentTime(); @@ -231,7 +231,7 @@ static bool HeapCompact(long size) { * @param size Number of bytes to allocate */ static MEM_NODE *MemoryAlloc(long size) { - MEM_NODE *pHeap = &heapSentinel; + MEM_NODE *pHeap = &g_heapSentinel; #ifdef SCUMM_NEED_ALIGNMENT const int alignPadding = sizeof(void *) - 1; @@ -255,7 +255,7 @@ static MEM_NODE *MemoryAlloc(long size) { assert(pNode->pBaseAddr); // Subtract size of new block from total - heapSentinel.size -= size; + g_heapSentinel.size -= size; #ifdef DEBUG MemoryStats(); @@ -282,7 +282,7 @@ static MEM_NODE *MemoryAlloc(long size) { * by using MemoryReAlloc(). */ MEM_NODE *MemoryNoAlloc() { - MEM_NODE *pHeap = &heapSentinel; + MEM_NODE *pHeap = &g_heapSentinel; // chain a discarded node onto the end of the heap MEM_NODE *pNode = AllocMemNode(); @@ -315,8 +315,8 @@ MEM_NODE *MemoryAllocFixed(long size) { #endif // Search for a free entry in s_fixedMnodesList - MEM_NODE *pNode = s_fixedMnodesList; - for (int i = 0; i < ARRAYSIZE(s_fixedMnodesList); ++i, ++pNode) { + MEM_NODE *pNode = g_s_fixedMnodesList; + for (int i = 0; i < ARRAYSIZE(g_s_fixedMnodesList); ++i, ++pNode) { if (!pNode->pBaseAddr) { pNode->pNext = 0; pNode->pPrev = 0; @@ -326,7 +326,7 @@ MEM_NODE *MemoryAllocFixed(long size) { pNode->flags = DWM_USED; // Subtract size of new block from total - heapSentinel.size -= size; + g_heapSentinel.size -= size; return pNode; } @@ -342,7 +342,7 @@ MEM_NODE *MemoryAllocFixed(long size) { */ void MemoryDiscard(MEM_NODE *pMemNode) { // validate mnode pointer - assert(pMemNode >= mnodeList && pMemNode <= mnodeList + NUM_MNODES - 1); + assert(pMemNode >= g_mnodeList && pMemNode <= g_mnodeList + NUM_MNODES - 1); // object must be in use and locked assert((pMemNode->flags & (DWM_USED | DWM_LOCKED)) == DWM_USED); @@ -351,7 +351,7 @@ void MemoryDiscard(MEM_NODE *pMemNode) { if ((pMemNode->flags & DWM_DISCARDED) == 0) { // free memory free(pMemNode->pBaseAddr); - heapSentinel.size += pMemNode->size; + g_heapSentinel.size += pMemNode->size; #ifdef DEBUG MemoryStats(); @@ -416,7 +416,7 @@ void MemoryReAlloc(MEM_NODE *pMemNode, long size) { MEM_NODE *pNew; // validate mnode pointer - assert(pMemNode >= mnodeList && pMemNode <= mnodeList + NUM_MNODES - 1); + assert(pMemNode >= g_mnodeList && pMemNode <= g_mnodeList + NUM_MNODES - 1); // align the size to machine boundary requirements size = (size + sizeof(void *) - 1) & ~(sizeof(void *) - 1); diff --git a/engines/tinsel/mareels.cpp b/engines/tinsel/mareels.cpp index bd267a2c65..7dd905d0f2 100644 --- a/engines/tinsel/mareels.cpp +++ b/engines/tinsel/mareels.cpp @@ -48,9 +48,9 @@ struct SCIdataStruct { // FIXME: Avoid non-const global vars -static SCIdataStruct SCIdata[MAX_SCRENTRIES]; +static SCIdataStruct g_SCIdata[MAX_SCRENTRIES]; -static int scrEntries = 0; +static int g_scrEntries = 0; /** * Sets an actor's walk reels @@ -131,16 +131,16 @@ void SetScalingReels(int actor, int scale, int direction, assert(!(scale == 1 && direction == D_UP) && !(scale == NUM_MAINSCALES && direction == D_DOWN)); // illegal direction from scale - assert(scrEntries < MAX_SCRENTRIES); // Scaling reels limit reached! + assert(g_scrEntries < MAX_SCRENTRIES); // Scaling reels limit reached! - SCIdata[scrEntries].actor = actor; - SCIdata[scrEntries].scale = scale; - SCIdata[scrEntries].direction = direction; - SCIdata[scrEntries].reels[LEFTREEL] = left; - SCIdata[scrEntries].reels[RIGHTREEL] = right; - SCIdata[scrEntries].reels[FORWARD] = forward; - SCIdata[scrEntries].reels[AWAY] = away; - scrEntries++; + g_SCIdata[g_scrEntries].actor = actor; + g_SCIdata[g_scrEntries].scale = scale; + g_SCIdata[g_scrEntries].direction = direction; + g_SCIdata[g_scrEntries].reels[LEFTREEL] = left; + g_SCIdata[g_scrEntries].reels[RIGHTREEL] = right; + g_SCIdata[g_scrEntries].reels[FORWARD] = forward; + g_SCIdata[g_scrEntries].reels[AWAY] = away; + g_scrEntries++; } /** @@ -155,12 +155,12 @@ SCNHANDLE ScalingReel(int ano, int scale1, int scale2, DIRECTION reel) { else d = D_UP; - for (int i = 0; i < scrEntries; i++) { - if (SCIdata[i].actor == ano && SCIdata[i].scale == scale1 && SCIdata[i].direction == d) { - if (SCIdata[i].reels[reel] == TF_NONE) + for (int i = 0; i < g_scrEntries; i++) { + if (g_SCIdata[i].actor == ano && g_SCIdata[i].scale == scale1 && g_SCIdata[i].direction == d) { + if (g_SCIdata[i].reels[reel] == TF_NONE) return 0; else - return SCIdata[i].reels[reel]; + return g_SCIdata[i].reels[reel]; } } return 0; @@ -170,8 +170,8 @@ SCNHANDLE ScalingReel(int ano, int scale1, int scale2, DIRECTION reel) { * RebootScalingReels */ void RebootScalingReels() { - scrEntries = 0; - memset(SCIdata, 0, sizeof(SCIdata)); + g_scrEntries = 0; + memset(g_SCIdata, 0, sizeof(g_SCIdata)); } /** diff --git a/engines/tinsel/move.cpp b/engines/tinsel/move.cpp index e20f28d528..bb49e59fe7 100644 --- a/engines/tinsel/move.cpp +++ b/engines/tinsel/move.cpp @@ -77,14 +77,14 @@ HPOLYGON InitExtraBlock(PMOVER ca, PMOVER ta); // FIXME: Avoid non-const global vars #if SLOW_RINCE_DOWN -static int Interlude = 0; // For slowing down walking, for testing -static int BogusVar = 0; // For slowing down walking, for testing +static int g_Interlude = 0; // For slowing down walking, for testing +static int g_BogusVar = 0; // For slowing down walking, for testing #endif -static int32 DefaultRefer = 0; -static int lastLeadXdest = 0, lastLeadYdest = 0; +static int32 g_DefaultRefer = 0; +static int g_lastLeadXdest = 0, g_lastLeadYdest = 0; -static int hSlowVar = 0; // used by MoveActor() +static int g_hSlowVar = 0; // used by MoveActor() //----------------- FORWARD REFERENCES -------------------- @@ -101,9 +101,9 @@ static void NewCoOrdinates(int fromx, int fromy, int *targetX, int *targetY, */ void AddInterlude(int n) { - Interlude += n; - if (Interlude < 0) - Interlude = 0; + g_Interlude += n; + if (g_Interlude < 0) + g_Interlude = 0; } #endif @@ -251,7 +251,7 @@ static int ClickedOnNothing(int clickX, int clickY, int *ptgtX, int *ptgtY) { PlayfieldGetPos(FIELD_WORLD, &Loffset, &Toffset); - switch (DefaultRefer) { + switch (g_DefaultRefer) { case REF_DEFAULT: // Try searching down and up (onscreen). for (i = clickY+1; i < SCREEN_HEIGHT+Toffset; i++) @@ -1353,15 +1353,15 @@ int SetActorDest(PMOVER pMover, int clickX, int clickY, bool igPath, SCNHANDLE h targetY = clickY; if (pMover->actorID == GetLeadId()) { - lastLeadXdest = targetX; - lastLeadYdest = targetY; + g_lastLeadXdest = targetX; + g_lastLeadYdest = targetY; } } else { int wodResult = WorkOutDestination(clickX, clickY, &targetX, &targetY); if (pMover->actorID == GetLeadId()) { - lastLeadXdest = targetX; - lastLeadYdest = targetY; + g_lastLeadXdest = targetX; + g_lastLeadYdest = targetY; } if (wodResult == ALL_SORTED) { @@ -1613,17 +1613,17 @@ void MoveActor(PMOVER pMover) { } #if SLOW_RINCE_DOWN -/**/ if (BogusVar++ < Interlude) // Temporary slow-down-the-action code +/**/ if (g_BogusVar++ < g_Interlude) // Temporary slow-down-the-action code /**/ return; // -/**/ BogusVar = 0; // +/**/ g_BogusVar = 0; // #endif if (!TinselV2) { // During swalk()s, movement while hidden may be slowed down. if (pMover->bHidden) { - if (++hSlowVar < pMover->SlowFactor) + if (++g_hSlowVar < pMover->SlowFactor) return; - hSlowVar = 0; + g_hSlowVar = 0; } } @@ -1705,15 +1705,15 @@ void MoveActor(PMOVER pMover) { * Store the default refer type for the current scene. */ void SetDefaultRefer(int32 defRefer) { - DefaultRefer = defRefer; + g_DefaultRefer = defRefer; } int GetLastLeadXdest() { - return lastLeadXdest; + return g_lastLeadXdest; } int GetLastLeadYdest() { - return lastLeadYdest; + return g_lastLeadYdest; } diff --git a/engines/tinsel/music.cpp b/engines/tinsel/music.cpp index f552c49491..781a378f13 100644 --- a/engines/tinsel/music.cpp +++ b/engines/tinsel/music.cpp @@ -64,13 +64,13 @@ struct SOUND_BUFFER { // FIXME: Avoid non-const global vars // MIDI buffer -static SOUND_BUFFER midiBuffer = { 0, 0 }; +static SOUND_BUFFER g_midiBuffer = { 0, 0 }; -static SCNHANDLE currentMidi = 0; -static bool currentLoop = false; +static SCNHANDLE g_currentMidi = 0; +static bool g_currentLoop = false; // We allocate 155 entries because that's the maximum, used in the SCN version -static SCNHANDLE midiOffsets[155]; +static SCNHANDLE g_midiOffsets[155]; static const int enhancedAudioGRAVersion[] = { 1, 2, 1, 1, 3, 3, 4, 4, 5, 6, // 1-10 @@ -110,16 +110,16 @@ static const int enhancedAudioSCNVersion[] = { }; int GetTrackNumber(SCNHANDLE hMidi) { - for (int i = 0; i < ARRAYSIZE(midiOffsets); i++) - if (midiOffsets[i] == hMidi) + for (int i = 0; i < ARRAYSIZE(g_midiOffsets); i++) + if (g_midiOffsets[i] == hMidi) return i; return -1; } SCNHANDLE GetTrackOffset(int trackNumber) { - assert(trackNumber < ARRAYSIZE(midiOffsets)); - return midiOffsets[trackNumber]; + assert(trackNumber < ARRAYSIZE(g_midiOffsets)); + return g_midiOffsets[trackNumber]; } /** @@ -128,8 +128,8 @@ SCNHANDLE GetTrackOffset(int trackNumber) { * @param bLoop Whether to loop the sequence */ bool PlayMidiSequence(uint32 dwFileOffset, bool bLoop) { - currentMidi = dwFileOffset; - currentLoop = bLoop; + g_currentMidi = dwFileOffset; + g_currentLoop = bLoop; // Tinsel V1 PSX uses a different music format, so i // disable it here. @@ -166,8 +166,8 @@ bool PlayMidiSequence(uint32 dwFileOffset, bool bLoop) { StopMidi(); // StopMidi resets these fields, so set them again - currentMidi = dwFileOffset; - currentLoop = bLoop; + g_currentMidi = dwFileOffset; + g_currentLoop = bLoop; // try to play track, but don't fall back to a true CD g_system->getAudioCDManager()->play(track, bLoop ? -1 : 1, 0, 0, true); @@ -203,13 +203,13 @@ bool PlayMidiSequence(uint32 dwFileOffset, bool bLoop) { dwSeqLen = midiStream.readUint32LE(); // make sure buffer is large enough for this sequence - assert(dwSeqLen > 0 && dwSeqLen <= midiBuffer.size); + assert(dwSeqLen > 0 && dwSeqLen <= g_midiBuffer.size); // stop any currently playing tune _vm->_midiMusic->stop(); // read the sequence - if (midiStream.read(midiBuffer.pDat, dwSeqLen) != dwSeqLen) + if (midiStream.read(g_midiBuffer.pDat, dwSeqLen) != dwSeqLen) error(FILE_IS_CORRUPT, MIDI_FILE); midiStream.close(); @@ -231,14 +231,14 @@ bool PlayMidiSequence(uint32 dwFileOffset, bool bLoop) { _vm->_midiMusic->send(0x7F07B0 | 13); } - _vm->_midiMusic->playXMIDI(midiBuffer.pDat, dwSeqLen, bLoop); + _vm->_midiMusic->playXMIDI(g_midiBuffer.pDat, dwSeqLen, bLoop); // Store the length //dwLastSeqLen = dwSeqLen; } else { // dwFileOffset == dwLastMidiIndex _vm->_midiMusic->stop(); - _vm->_midiMusic->playXMIDI(midiBuffer.pDat, dwSeqLen, bLoop); + _vm->_midiMusic->playXMIDI(g_midiBuffer.pDat, dwSeqLen, bLoop); } return true; @@ -259,8 +259,8 @@ bool MidiPlaying() { * Stops any currently playing midi. */ bool StopMidi() { - currentMidi = 0; - currentLoop = false; + g_currentMidi = 0; + g_currentLoop = false; if (_vm->getFeatures() & GF_ENHANCED_AUDIO_SUPPORT) { g_system->getAudioCDManager()->stop(); @@ -295,8 +295,8 @@ void SetMidiVolume(int vol) { _vm->_midiMusic->setVolume(vol); } else if (vol != 0 && priorVolMusic == 0) { // Perhaps restart last midi sequence - if (currentLoop) - PlayMidiSequence(currentMidi, true); + if (g_currentLoop) + PlayMidiSequence(g_currentMidi, true); _vm->_midiMusic->setVolume(vol); } else if (vol != 0 && priorVolMusic != 0) { @@ -318,7 +318,7 @@ void OpenMidiFiles() { if ((_vm->getFeatures() & GF_DEMO) || (TinselVersion == TINSEL_V2) || TinselV1PSX) return; - if (midiBuffer.pDat) + if (g_midiBuffer.pDat) // already allocated return; @@ -327,15 +327,15 @@ void OpenMidiFiles() { error(CANNOT_FIND_FILE, MIDI_FILE); // gen length of the largest sequence - midiBuffer.size = midiStream.readUint32LE(); + g_midiBuffer.size = midiStream.readUint32LE(); if (midiStream.eos() || midiStream.err()) error(FILE_IS_CORRUPT, MIDI_FILE); - if (midiBuffer.size) { + if (g_midiBuffer.size) { // allocate a buffer big enough for the largest MIDI sequence - if ((midiBuffer.pDat = (uint8 *)malloc(midiBuffer.size)) != NULL) { + if ((g_midiBuffer.pDat = (uint8 *)malloc(g_midiBuffer.size)) != NULL) { // clear out the buffer - memset(midiBuffer.pDat, 0, midiBuffer.size); + memset(g_midiBuffer.pDat, 0, g_midiBuffer.size); // VMM_lock(midiBuffer.pDat, midiBuffer.size); } else { //mSeqHandle = NULL; @@ -352,15 +352,15 @@ void OpenMidiFiles() { uint32 songLength = 0; // Init - for (int i = 0; i < ARRAYSIZE(midiOffsets); i++) - midiOffsets[i] = 0; + for (int i = 0; i < ARRAYSIZE(g_midiOffsets); i++) + g_midiOffsets[i] = 0; while (!midiStream.eos() && !midiStream.err()) { if (curOffset + (4 * curTrack) >= (uint32)midiStream.size()) break; - assert(curTrack < ARRAYSIZE(midiOffsets)); - midiOffsets[curTrack] = curOffset + (4 * curTrack); + assert(curTrack < ARRAYSIZE(g_midiOffsets)); + g_midiOffsets[curTrack] = curOffset + (4 * curTrack); //debug("%d: %d", curTrack, midiOffsets[curTrack]); songLength = midiStream.readUint32LE(); @@ -374,8 +374,8 @@ void OpenMidiFiles() { } void DeleteMidiBuffer() { - free(midiBuffer.pDat); - midiBuffer.pDat = NULL; + free(g_midiBuffer.pDat); + g_midiBuffer.pDat = NULL; } MidiMusicPlayer::MidiMusicPlayer() { @@ -860,22 +860,22 @@ void PCMMusicPlayer::stop() { } void CurrentMidiFacts(SCNHANDLE *pMidi, bool *pLoop) { - *pMidi = currentMidi; - *pLoop = currentLoop; + *pMidi = g_currentMidi; + *pLoop = g_currentLoop; } void RestoreMidiFacts(SCNHANDLE Midi, bool Loop) { StopMidi(); - currentMidi = Midi; - currentLoop = Loop; + g_currentMidi = Midi; + g_currentLoop = Loop; if (_vm->_config->_musicVolume != 0 && Loop) { bool mute = false; if (ConfMan.hasKey("mute")) mute = ConfMan.getBool("mute"); - PlayMidiSequence(currentMidi, true); + PlayMidiSequence(g_currentMidi, true); SetMidiVolume(mute ? 0 : _vm->_config->_musicVolume); } } diff --git a/engines/tinsel/palette.cpp b/engines/tinsel/palette.cpp index f2437bd17e..e6c9467fab 100644 --- a/engines/tinsel/palette.cpp +++ b/engines/tinsel/palette.cpp @@ -54,33 +54,33 @@ struct VIDEO_DAC_Q { // FIXME: Avoid non-const global vars /** palette allocator data */ -static PALQ palAllocData[NUM_PALETTES]; +static PALQ g_palAllocData[NUM_PALETTES]; /** video DAC transfer Q length */ #define VDACQLENGTH (NUM_PALETTES+2) /** video DAC transfer Q */ -static VIDEO_DAC_Q vidDACdata[VDACQLENGTH]; +static VIDEO_DAC_Q g_vidDACdata[VDACQLENGTH]; /** video DAC transfer Q head pointer */ -static VIDEO_DAC_Q *pDAChead; +static VIDEO_DAC_Q *g_pDAChead; /** color index of the 4 colors used for the translucent palette */ #define COL_HILIGHT TBLUE1 /** the translucent palette lookup table */ -uint8 transPalette[MAX_COLORS]; // used in graphics.cpp +uint8 g_transPalette[MAX_COLORS]; // used in graphics.cpp -uint8 ghostPalette[MAX_COLORS]; +uint8 g_ghostPalette[MAX_COLORS]; -static int translucentIndex = 228; +static int g_translucentIndex = 228; -static int talkIndex = 233; +static int g_talkIndex = 233; -static COLORREF talkColRef; +static COLORREF g_talkColRef; -static COLORREF tagColRef; +static COLORREF g_tagColRef; #ifdef DEBUG @@ -131,11 +131,11 @@ void psxPaletteMapper(PALQ *originalPal, uint8 *psxClut, byte *mapperTable) { */ void PalettesToVideoDAC() { PALQ *pPalQ; // palette Q iterator - VIDEO_DAC_Q *pDACtail = vidDACdata; // set tail pointer + VIDEO_DAC_Q *pDACtail = g_vidDACdata; // set tail pointer byte pal[768]; // while Q is not empty - while (pDAChead != pDACtail) { + while (g_pDAChead != pDACtail) { const PALETTE *pPalette; // pointer to hardware palette const COLORREF *pColors; // pointer to list of RGB triples @@ -179,10 +179,10 @@ void PalettesToVideoDAC() { } // reset video DAC transfer Q head pointer - pDAChead = vidDACdata; + g_pDAChead = g_vidDACdata; // clear all palette moved bits - for (pPalQ = palAllocData; pPalQ < palAllocData + NUM_PALETTES; pPalQ++) + for (pPalQ = g_palAllocData; pPalQ < g_palAllocData + NUM_PALETTES; pPalQ++) pPalQ->posInDAC &= ~PALETTE_MOVED; } @@ -196,10 +196,10 @@ void ResetPalAllocator() { #endif // wipe out the palette allocator data - memset(palAllocData, 0, sizeof(palAllocData)); + memset(g_palAllocData, 0, sizeof(g_palAllocData)); // reset video DAC transfer Q head pointer - pDAChead = vidDACdata; + g_pDAChead = g_vidDACdata; } #ifdef DEBUG @@ -220,19 +220,19 @@ void PaletteStats() { */ void UpdateDACqueueHandle(int posInDAC, int numColors, SCNHANDLE hPalette) { // check Q overflow - assert(pDAChead < vidDACdata + VDACQLENGTH); + assert(g_pDAChead < g_vidDACdata + VDACQLENGTH); - pDAChead->destDACindex = posInDAC & ~PALETTE_MOVED; // set index in video DAC - pDAChead->numColors = numColors; // set number of colors - pDAChead->pal.hRGBarray = hPalette; // set handle of palette - pDAChead->bHandle = true; // we are using a palette handle + g_pDAChead->destDACindex = posInDAC & ~PALETTE_MOVED; // set index in video DAC + g_pDAChead->numColors = numColors; // set number of colors + g_pDAChead->pal.hRGBarray = hPalette; // set handle of palette + g_pDAChead->bHandle = true; // we are using a palette handle // update head pointer - ++pDAChead; + ++g_pDAChead; #ifdef DEBUG - if ((pDAChead-vidDACdata) > maxDACQ) - maxDACQ = pDAChead-vidDACdata; + if ((g_pDAChead-g_vidDACdata) > maxDACQ) + maxDACQ = g_pDAChead-g_vidDACdata; #endif } @@ -244,22 +244,22 @@ void UpdateDACqueueHandle(int posInDAC, int numColors, SCNHANDLE hPalette) { */ void UpdateDACqueue(int posInDAC, int numColors, COLORREF *pColors) { // check Q overflow - assert(pDAChead < vidDACdata + NUM_PALETTES); + assert(g_pDAChead < g_vidDACdata + NUM_PALETTES); - pDAChead->destDACindex = posInDAC & ~PALETTE_MOVED; // set index in video DAC - pDAChead->numColors = numColors; // set number of colors + g_pDAChead->destDACindex = posInDAC & ~PALETTE_MOVED; // set index in video DAC + g_pDAChead->numColors = numColors; // set number of colors if (numColors == 1) - pDAChead->pal.singleRGB = *pColors; // set single color of which the "palette" consists + g_pDAChead->pal.singleRGB = *pColors; // set single color of which the "palette" consists else - pDAChead->pal.pRGBarray = pColors; // set addr of palette - pDAChead->bHandle = false; // we are not using a palette handle + g_pDAChead->pal.pRGBarray = pColors; // set addr of palette + g_pDAChead->bHandle = false; // we are not using a palette handle // update head pointer - ++pDAChead; + ++g_pDAChead; #ifdef DEBUG - if ((pDAChead-vidDACdata) > maxDACQ) - maxDACQ = pDAChead-vidDACdata; + if ((g_pDAChead-g_vidDACdata) > maxDACQ) + maxDACQ = g_pDAChead-g_vidDACdata; #endif } @@ -271,19 +271,19 @@ void UpdateDACqueue(int posInDAC, int numColors, COLORREF *pColors) { */ void UpdateDACqueue(int posInDAC, COLORREF color) { // check Q overflow - assert(pDAChead < vidDACdata + NUM_PALETTES); + assert(g_pDAChead < g_vidDACdata + NUM_PALETTES); - pDAChead->destDACindex = posInDAC & ~PALETTE_MOVED; // set index in video DAC - pDAChead->numColors = 1; // set number of colors - pDAChead->pal.singleRGB = color; // set single color of which the "palette" consists - pDAChead->bHandle = false; // we are not using a palette handle + g_pDAChead->destDACindex = posInDAC & ~PALETTE_MOVED; // set index in video DAC + g_pDAChead->numColors = 1; // set number of colors + g_pDAChead->pal.singleRGB = color; // set single color of which the "palette" consists + g_pDAChead->bHandle = false; // we are not using a palette handle // update head pointer - ++pDAChead; + ++g_pDAChead; #ifdef DEBUG - if ((pDAChead-vidDACdata) > maxDACQ) - maxDACQ = pDAChead-vidDACdata; + if ((g_pDAChead-g_vidDACdata) > maxDACQ) + maxDACQ = g_pDAChead-g_vidDACdata; #endif } @@ -301,7 +301,7 @@ PALQ *AllocPalette(SCNHANDLE hNewPal) { pNewPal = (PALETTE *)LockMem(hNewPal); // search all structs in palette allocator - see if palette already allocated - for (p = palAllocData; p < palAllocData + NUM_PALETTES; p++) { + for (p = g_palAllocData; p < g_palAllocData + NUM_PALETTES; p++) { if (p->hPal == hNewPal) { // found the desired palette in palette allocator p->objCount++; // update number of objects using palette @@ -312,7 +312,7 @@ PALQ *AllocPalette(SCNHANDLE hNewPal) { // search all structs in palette allocator - find a free slot iDAC = FGND_DAC_INDEX; // init DAC index to first available foreground color - for (p = palAllocData; p < palAllocData + NUM_PALETTES; p++) { + for (p = g_palAllocData; p < g_palAllocData + NUM_PALETTES; p++) { if (p->hPal == 0) { // found a free slot in palette allocator p->objCount = 1; // init number of objects using palette @@ -337,7 +337,7 @@ PALQ *AllocPalette(SCNHANDLE hNewPal) { UpdateDACqueueHandle(p->posInDAC, p->numColors, p->hPal); // move all palettes after this one down (if necessary) - for (pPrev = p, pNxtPal = pPrev + 1; pNxtPal < palAllocData + NUM_PALETTES; pNxtPal++) { + for (pPrev = p, pNxtPal = pPrev + 1; pNxtPal < g_palAllocData + NUM_PALETTES; pNxtPal++) { if (pNxtPal->hPal != 0) { // palette slot is in use if (pNxtPal->posInDAC >= pPrev->posInDAC + pPrev->numColors) @@ -381,7 +381,7 @@ PALQ *AllocPalette(SCNHANDLE hNewPal) { */ void FreePalette(PALQ *pFreePal) { // validate palette Q pointer - assert(pFreePal >= palAllocData && pFreePal <= palAllocData + NUM_PALETTES - 1); + assert(pFreePal >= g_palAllocData && pFreePal <= g_palAllocData + NUM_PALETTES - 1); // reduce the palettes object reference count pFreePal->objCount--; @@ -408,7 +408,7 @@ PALQ *FindPalette(SCNHANDLE hSrchPal) { PALQ *pPal; // palette allocator iterator // search all structs in palette allocator - for (pPal = palAllocData; pPal < palAllocData + NUM_PALETTES; pPal++) { + for (pPal = g_palAllocData; pPal < g_palAllocData + NUM_PALETTES; pPal++) { if (pPal->hPal == hSrchPal) // found palette in palette allocator return pPal; @@ -428,7 +428,7 @@ void SwapPalette(PALQ *pPalQ, SCNHANDLE hNewPal) { PALETTE *pNewPal = (PALETTE *)LockMem(hNewPal); // validate palette Q pointer - assert(pPalQ >= palAllocData && pPalQ <= palAllocData + NUM_PALETTES - 1); + assert(pPalQ >= g_palAllocData && pPalQ <= g_palAllocData + NUM_PALETTES - 1); if (pPalQ->numColors >= (int)FROM_LE_32(pNewPal->numColors)) { // new palette will fit the slot @@ -455,7 +455,7 @@ void SwapPalette(PALQ *pPalQ, SCNHANDLE hNewPal) { PALQ *pNxtPalQ; // next palette queue position - for (pNxtPalQ = pPalQ + 1; pNxtPalQ < palAllocData + NUM_PALETTES; pNxtPalQ++) { + for (pNxtPalQ = pPalQ + 1; pNxtPalQ < g_palAllocData + NUM_PALETTES; pNxtPalQ++) { if (pNxtPalQ->posInDAC >= pPalQ->posInDAC + pPalQ->numColors) // no need to move palettes down break; @@ -482,14 +482,14 @@ void SwapPalette(PALQ *pPalQ, SCNHANDLE hNewPal) { PALQ *GetNextPalette(PALQ *pStrtPal) { if (pStrtPal == NULL) { // start of palette iteration - return 1st palette - return (palAllocData[0].objCount) ? palAllocData : NULL; + return (g_palAllocData[0].objCount) ? g_palAllocData : NULL; } // validate palette Q pointer - assert(pStrtPal >= palAllocData && pStrtPal <= palAllocData + NUM_PALETTES - 1); + assert(pStrtPal >= g_palAllocData && pStrtPal <= g_palAllocData + NUM_PALETTES - 1); // return next active palette in list - while (++pStrtPal < palAllocData + NUM_PALETTES) { + while (++pStrtPal < g_palAllocData + NUM_PALETTES) { if (pStrtPal->objCount) // active palette found return pStrtPal; @@ -515,7 +515,7 @@ void SetBgndColor(COLORREF color) { */ void FadingPalette(PALQ *pPalQ, bool bFading) { // validate palette Q pointer - assert(pPalQ >= palAllocData && pPalQ <= palAllocData + NUM_PALETTES - 1); + assert(pPalQ >= g_palAllocData && pPalQ <= g_palAllocData + NUM_PALETTES - 1); // validate that this is a change assert(pPalQ->bFading != bFading); @@ -530,7 +530,7 @@ void FadingPalette(PALQ *pPalQ, bool bFading) { void NoFadingPalettes() { PALQ *pPalQ; - for (pPalQ = palAllocData; pPalQ <= palAllocData + NUM_PALETTES - 1; pPalQ++) { + for (pPalQ = g_palAllocData; pPalQ <= g_palAllocData + NUM_PALETTES - 1; pPalQ++) { pPalQ->bFading = false; } } @@ -544,7 +544,7 @@ void CreateTranslucentPalette(SCNHANDLE hPalette) { PALETTE *pPal = (PALETTE *)LockMem(hPalette); // leave background color alone - transPalette[0] = 0; + g_transPalette[0] = 0; for (uint i = 0; i < FROM_LE_32(pPal->numColors); i++) { // get the RGB color model values @@ -558,7 +558,7 @@ void CreateTranslucentPalette(SCNHANDLE hPalette) { // map the Value field to one of the 4 colors reserved for the translucent palette val /= 63; - transPalette[i + 1] = (uint8)((val == 0) ? 0 : val + + g_transPalette[i + 1] = (uint8)((val == 0) ? 0 : val + (TinselV2 ? TranslucentColor() : COL_HILIGHT) - 1); } } @@ -572,7 +572,7 @@ void CreateGhostPalette(SCNHANDLE hPalette) { int i; // leave background color alone - ghostPalette[0] = 0; + g_ghostPalette[0] = 0; for (i = 0; i < (int)FROM_LE_32(pPal->numColors); i++) { // get the RGB color model values @@ -587,7 +587,7 @@ void CreateGhostPalette(SCNHANDLE hPalette) { // map the Value field to one of the 4 colors reserved for the translucent palette val /= 64; assert(/*val >= 0 &&*/ val <= 3); - ghostPalette[i + 1] = (uint8)(val + SysVar(ISV_GHOST_BASE)); + g_ghostPalette[i + 1] = (uint8)(val + SysVar(ISV_GHOST_BASE)); } } @@ -648,41 +648,41 @@ void DimPartPalette(SCNHANDLE hDimPal, int startColor, int length, int brightnes } int TranslucentColor() { - return translucentIndex; + return g_translucentIndex; } int HighlightColor() { - UpdateDACqueue(talkIndex, (COLORREF)SysVar(SYS_HighlightRGB)); + UpdateDACqueue(g_talkIndex, (COLORREF)SysVar(SYS_HighlightRGB)); - return talkIndex; + return g_talkIndex; } int TalkColor() { - return TinselV2 ? talkIndex : TALKFONT_COL; + return TinselV2 ? g_talkIndex : TALKFONT_COL; } void SetTalkColorRef(COLORREF colRef) { - talkColRef = colRef; + g_talkColRef = colRef; } COLORREF GetTalkColorRef() { - return talkColRef; + return g_talkColRef; } void SetTagColorRef(COLORREF colRef) { - tagColRef = colRef; + g_tagColRef = colRef; } COLORREF GetTagColorRef() { - return tagColRef; + return g_tagColRef; } void SetTranslucencyOffset(int offset) { - translucentIndex = offset; + g_translucentIndex = offset; } void SetTalkTextOffset(int offset) { - talkIndex = offset; + g_talkIndex = offset; } } // End of namespace Tinsel diff --git a/engines/tinsel/pcode.cpp b/engines/tinsel/pcode.cpp index 2ab1e653d4..145a6a8e5d 100644 --- a/engines/tinsel/pcode.cpp +++ b/engines/tinsel/pcode.cpp @@ -100,19 +100,19 @@ enum OPCODE { #define OPMASK 0x3F ///< mask to isolate the opcode -bool bNoPause = false; +bool g_bNoPause = false; //----------------- LOCAL GLOBAL DATA -------------------- // FIXME: Avoid non-const global vars -static int32 *pGlobals = 0; // global vars +static int32 *g_pGlobals = 0; // global vars -static int numGlobals = 0; // How many global variables to save/restore +static int g_numGlobals = 0; // How many global variables to save/restore -static INT_CONTEXT *icList = 0; +static INT_CONTEXT *g_icList = 0; -static uint32 hMasterScript; +static uint32 g_hMasterScript; //----------------- SCRIPT BUGS WORKAROUNDS -------------- @@ -227,7 +227,7 @@ void LockCode(INT_CONTEXT *ic) { if (ic->GSort == GS_MASTER) { if (TinselV2) // Get the srcipt handle from a specific global chunk - ic->code = (byte *)LockMem(hMasterScript); + ic->code = (byte *)LockMem(g_hMasterScript); else ic->code = (byte *)FindChunk(MASTER_SCNHANDLE, CHUNK_PCODE); } else @@ -241,7 +241,7 @@ static INT_CONTEXT *AllocateInterpretContext(GSORT gsort) { INT_CONTEXT *pic; int i; - for (i = 0, pic = icList; i < NUM_INTERPRET; i++, pic++) { + for (i = 0, pic = g_icList; i < NUM_INTERPRET; i++, pic++) { if (pic->GSort == GS_NONE) { pic->pProc = g_scheduler->getCurrentProcess(); pic->GSort = gsort; @@ -264,8 +264,8 @@ static void FreeWaitCheck(PINT_CONTEXT pic, bool bVoluntary) { // Is this waiting for something? if (pic->waitNumber1) { for (i = 0; i < NUM_INTERPRET; i++) { - if ((icList + i)->waitNumber2 == pic->waitNumber1) { - (icList + i)->waitNumber2 = 0; + if ((g_icList + i)->waitNumber2 == pic->waitNumber1) { + (g_icList + i)->waitNumber2 = 0; break; } } @@ -274,10 +274,10 @@ static void FreeWaitCheck(PINT_CONTEXT pic, bool bVoluntary) { // Is someone waiting for this? if (pic->waitNumber2) { for (i = 0; i < NUM_INTERPRET; i++) { - if ((icList + i)->waitNumber1 == pic->waitNumber2) { - (icList + i)->waitNumber1 = 0; - (icList + i)->resumeCode = bVoluntary ? RES_FINISHED : RES_CUTSHORT; - g_scheduler->reschedule((icList + i)->pProc); + if ((g_icList + i)->waitNumber1 == pic->waitNumber2) { + (g_icList + i)->waitNumber1 = 0; + (g_icList + i)->resumeCode = bVoluntary ? RES_FINISHED : RES_CUTSHORT; + g_scheduler->reschedule((g_icList + i)->pProc); break; } } @@ -305,7 +305,7 @@ void FreeInterpretContextPr(PROCESS *pProc) { INT_CONTEXT *pic; int i; - for (i = 0, pic = icList; i < NUM_INTERPRET; i++, pic++) { + for (i = 0, pic = g_icList; i < NUM_INTERPRET; i++, pic++) { if (pic->GSort != GS_NONE && pic->pProc == pProc) { FreeWaitCheck(pic, false); if (TinselV2) @@ -323,7 +323,7 @@ void FreeMostInterpretContexts() { INT_CONTEXT *pic; int i; - for (i = 0, pic = icList; i < NUM_INTERPRET; i++, pic++) { + for (i = 0, pic = g_icList; i < NUM_INTERPRET; i++, pic++) { if ((pic->GSort != GS_MASTER) && (pic->GSort != GS_GPROCESS)) { memset(pic, 0, sizeof(INT_CONTEXT)); pic->GSort = GS_NONE; @@ -338,7 +338,7 @@ void FreeMasterInterpretContext() { INT_CONTEXT *pic; int i; - for (i = 0, pic = icList; i < NUM_INTERPRET; i++, pic++) { + for (i = 0, pic = g_icList; i < NUM_INTERPRET; i++, pic++) { if ((pic->GSort == GS_MASTER) || (pic->GSort == GS_GPROCESS)) { memset(pic, 0, sizeof(INT_CONTEXT)); pic->GSort = GS_NONE; @@ -405,30 +405,30 @@ INT_CONTEXT *RestoreInterpretContext(INT_CONTEXT *ric) { * Allocates enough RAM to hold the global Glitter variables. */ void RegisterGlobals(int num) { - if (pGlobals == NULL) { - numGlobals = num; + if (g_pGlobals == NULL) { + g_numGlobals = num; - hMasterScript = !TinselV2 ? 0 : + g_hMasterScript = !TinselV2 ? 0 : READ_LE_UINT32(FindChunk(MASTER_SCNHANDLE, CHUNK_MASTER_SCRIPT)); // Allocate RAM for pGlobals and make sure it's allocated - pGlobals = (int32 *)calloc(numGlobals, sizeof(int32)); - if (pGlobals == NULL) { + g_pGlobals = (int32 *)calloc(g_numGlobals, sizeof(int32)); + if (g_pGlobals == NULL) { error("Cannot allocate memory for global data"); } // Allocate RAM for interpret contexts and make sure it's allocated - icList = (INT_CONTEXT *)calloc(NUM_INTERPRET, sizeof(INT_CONTEXT)); - if (icList == NULL) { + g_icList = (INT_CONTEXT *)calloc(NUM_INTERPRET, sizeof(INT_CONTEXT)); + if (g_icList == NULL) { error("Cannot allocate memory for interpret contexts"); } g_scheduler->setResourceCallback(FreeInterpretContextPr); } else { // Check size is still the same - assert(numGlobals == num); + assert(g_numGlobals == num); - memset(pGlobals, 0, numGlobals * sizeof(int32)); - memset(icList, 0, NUM_INTERPRET * sizeof(INT_CONTEXT)); + memset(g_pGlobals, 0, g_numGlobals * sizeof(int32)); + memset(g_icList, 0, NUM_INTERPRET * sizeof(INT_CONTEXT)); } if (TinselV2) { @@ -444,7 +444,7 @@ void RegisterGlobals(int num) { error(FILE_IS_CORRUPT, GLOBALS_FILENAME); for (int i = 0; i < length; ++i) - pGlobals[i] = f.readSint32LE(); + g_pGlobals[i] = f.readSint32LE(); if (f.eos() || f.err()) error(FILE_IS_CORRUPT, GLOBALS_FILENAME); @@ -454,19 +454,19 @@ void RegisterGlobals(int num) { } void FreeGlobals() { - free(pGlobals); - pGlobals = NULL; + free(g_pGlobals); + g_pGlobals = NULL; - free(icList); - icList = NULL; + free(g_icList); + g_icList = NULL; } /** * (Un)serialize the global data for save/restore game. */ void syncGlobInfo(Common::Serializer &s) { - for (int i = 0; i < numGlobals; i++) { - s.syncAsSint32LE(pGlobals[i]); + for (int i = 0; i < g_numGlobals; i++) { + s.syncAsSint32LE(g_pGlobals[i]); } } @@ -502,7 +502,7 @@ void INT_CONTEXT::syncWithSerializer(Common::Serializer &s) { * Return pointer to and size of global data for save/restore game. */ void SaveInterpretContexts(INT_CONTEXT *sICInfo) { - memcpy(sICInfo, icList, NUM_INTERPRET * sizeof(INT_CONTEXT)); + memcpy(sICInfo, g_icList, NUM_INTERPRET * sizeof(INT_CONTEXT)); } /** @@ -633,8 +633,8 @@ void Interpret(CORO_PARAM, INT_CONTEXT *ic) { case OP_GLOAD: // loads global variable onto stack tmp = Fetch(opcode, ic->code, wkEntry, ip); - assert(0 <= tmp && tmp < numGlobals); - ic->stack[++ic->sp] = pGlobals[tmp]; + assert(0 <= tmp && tmp < g_numGlobals); + ic->stack[++ic->sp] = g_pGlobals[tmp]; break; case OP_STORE: // pops stack and stores in local variable @@ -645,8 +645,8 @@ void Interpret(CORO_PARAM, INT_CONTEXT *ic) { case OP_GSTORE: // pops stack and stores in global variable tmp = Fetch(opcode, ic->code, wkEntry, ip); - assert(0 <= tmp && tmp < numGlobals); - pGlobals[tmp] = ic->stack[ic->sp--]; + assert(0 <= tmp && tmp < g_numGlobals); + g_pGlobals[tmp] = ic->stack[ic->sp--]; break; case OP_CALL: // procedure call @@ -809,7 +809,7 @@ void Interpret(CORO_PARAM, INT_CONTEXT *ic) { break; case OP_ESCON: - bNoPause = true; + g_bNoPause = true; ic->escOn = true; ic->myEscape = GetEscEvents(); break; @@ -856,8 +856,8 @@ static uint32 UniqueWaitNumber() { retval = (uint32)-1; for (i = 0; i < NUM_INTERPRET; i++) { - if ((icList+i)->waitNumber1 == retval - || (icList+i)->waitNumber2 == retval) + if ((g_icList+i)->waitNumber1 == retval + || (g_icList+i)->waitNumber2 == retval) break; } @@ -887,7 +887,7 @@ void WaitInterpret(CORO_PARAM, PPROCESS pWaitProc, bool *result) { CORO_BEGIN_CODE(_ctx); - for (i = 0, _ctx->picWaiter = icList; i < NUM_INTERPRET; i++, _ctx->picWaiter++) { + for (i = 0, _ctx->picWaiter = g_icList; i < NUM_INTERPRET; i++, _ctx->picWaiter++) { if (_ctx->picWaiter->GSort != GS_NONE && _ctx->picWaiter->pProc == currentProcess) { break; } @@ -896,7 +896,7 @@ void WaitInterpret(CORO_PARAM, PPROCESS pWaitProc, bool *result) { /* * Find the interpret context of the process we're waiting for */ - for (i = 0, _ctx->picWaitee = icList; i < NUM_INTERPRET; i++, _ctx->picWaitee++) { + for (i = 0, _ctx->picWaitee = g_icList; i < NUM_INTERPRET; i++, _ctx->picWaitee++) { if (_ctx->picWaitee->GSort != GS_NONE && _ctx->picWaitee->pProc == pWaitProc) { break; } @@ -931,11 +931,11 @@ void CheckOutWaiters() { // Check all waited for have someone waiting for (i = 0; i < NUM_INTERPRET; i++) { // If someone is supposedly waiting for this one - if ((icList + i)->GSort != GS_NONE && (icList + i)->waitNumber2) { + if ((g_icList + i)->GSort != GS_NONE && (g_icList + i)->waitNumber2) { // Someone really must be waiting for this one for (j = 0; j < NUM_INTERPRET; j++) { - if ((icList + j)->GSort != GS_NONE - && (icList + j)->waitNumber1 == (icList + i)->waitNumber2) { + if ((g_icList + j)->GSort != GS_NONE + && (g_icList + j)->waitNumber1 == (g_icList + i)->waitNumber2) { break; } } @@ -946,11 +946,11 @@ void CheckOutWaiters() { // Check waiting for someone to wait for for (i = 0; i < NUM_INTERPRET; i++) { // If someone is supposedly waiting for this one - if ((icList + i)->GSort != GS_NONE && (icList + i)->waitNumber1) { + if ((g_icList + i)->GSort != GS_NONE && (g_icList + i)->waitNumber1) { // Someone really must be waiting for this one for (j = 0; j < NUM_INTERPRET; j++) { - if ((icList + j)->GSort != GS_NONE - && (icList + j)->waitNumber2 == (icList + i)->waitNumber1) { + if ((g_icList + j)->GSort != GS_NONE + && (g_icList + j)->waitNumber2 == (g_icList + i)->waitNumber1) { break; } } diff --git a/engines/tinsel/pdisplay.cpp b/engines/tinsel/pdisplay.cpp index 7439c6f77d..9a9e6ab00f 100644 --- a/engines/tinsel/pdisplay.cpp +++ b/engines/tinsel/pdisplay.cpp @@ -50,7 +50,7 @@ namespace Tinsel { #ifdef DEBUG //extern int Overrun; // The overrun counter, in DOS_DW.C -extern int newestString; // The overrun counter, in STRRES.C +extern int g_newestString; // The overrun counter, in STRRES.C #endif @@ -73,17 +73,17 @@ enum HotSpotTag { // FIXME: Avoid non-const global vars -static bool DispPath = false; -static bool bShowString = false; +static bool g_DispPath = false; +static bool g_bShowString = false; -static int TaggedActor = 0; -static HPOLYGON hTaggedPolygon = NOPOLY; +static int g_TaggedActor = 0; +static HPOLYGON g_hTaggedPolygon = NOPOLY; -static bool bTagsActive = true; +static bool g_bTagsActive = true; -static bool bPointingActive = true; +static bool g_bPointingActive = true; -static char tagBuffer[64]; +static char g_tagBuffer[64]; #ifdef DEBUG /** @@ -158,7 +158,7 @@ void CursorPositionProcess(CORO_PARAM, const void *) { sprintf(PositionString, "%d %d", aniX + Loffset, aniY + Toffset); _ctx->cpText = ObjectTextOut(GetPlayfieldList(FIELD_STATUS), PositionString, 0, CPOSX, POSY, GetTagFontHandle(), TXT_CENTER); - if (DispPath) { + if (g_DispPath) { HPOLYGON hp = InPolygon(aniX + Loffset, aniY + Toffset, PATH); if (hp == NOPOLY) sprintf(PositionString, "No path"); @@ -226,18 +226,18 @@ void CursorPositionProcess(CORO_PARAM, const void *) { /*-------------*\ | String number | \*-------------*/ - if (bShowString && newestString != _ctx->prevString) { + if (g_bShowString && g_newestString != _ctx->prevString) { // kill current text objects if (_ctx->spText) { MultiDeleteObject(GetPlayfieldList(FIELD_STATUS), _ctx->spText); } - sprintf(PositionString, "String: %d", newestString); + sprintf(PositionString, "String: %d", g_newestString); _ctx->spText = ObjectTextOut(GetPlayfieldList(FIELD_STATUS), PositionString, 0, SPOSX, POSY+10, GetTalkFontHandle(), TXT_CENTER); // update previous value - _ctx->prevString = newestString; + _ctx->prevString = g_newestString; } // update previous playfield position @@ -257,7 +257,7 @@ void DisablePointing() { int i; HPOLYGON hPoly; // Polygon handle - bPointingActive = false; + g_bPointingActive = false; for (i = 0; i < MAX_POLY; i++) { hPoly = GetPolyHandle(i); @@ -284,7 +284,7 @@ void DisablePointing() { * EnablePointing() */ void EnablePointing() { - bPointingActive = true; + g_bPointingActive = true; } /** @@ -292,7 +292,7 @@ void EnablePointing() { * (if one is). Tag process asks us for this information, as does ProcessUserEvent(). */ static void SaveTaggedActor(int ano) { - TaggedActor = ano; + g_TaggedActor = ano; } /** @@ -300,7 +300,7 @@ static void SaveTaggedActor(int ano) { * (if one is). Tag process asks us for this information, as does ProcessUserEvent(). */ int GetTaggedActor() { - return TaggedActor; + return g_TaggedActor; } /** @@ -308,11 +308,11 @@ int GetTaggedActor() { * (if one is). Tag process asks us for this information, as does ProcessUserEvent(). */ static void SaveTaggedPoly(HPOLYGON hp) { - hTaggedPolygon = hp; + g_hTaggedPolygon = hp; } HPOLYGON GetTaggedPoly() { - return hTaggedPolygon; + return g_hTaggedPolygon; } /** @@ -405,11 +405,11 @@ static bool ActorTag(int curX, int curY, HotSpotTag *pTag, OBJECT **ppText) { if (ActorTagIsWanted(actor)) { GetActorTagPos(actor, &tagX, &tagY, false); - LoadStringRes(GetActorTagHandle(actor), tagBuffer, sizeof(tagBuffer)); + LoadStringRes(GetActorTagHandle(actor), g_tagBuffer, sizeof(g_tagBuffer)); // May have buggered cursor EndCursorFollowed(); - *ppText = ObjectTextOut(GetPlayfieldList(FIELD_STATUS), tagBuffer, + *ppText = ObjectTextOut(GetPlayfieldList(FIELD_STATUS), g_tagBuffer, 0, tagX, tagY, GetTagFontHandle(), TXT_CENTER, 0); assert(*ppText); MultiSetZPosition(*ppText, Z_TAG_TEXT); @@ -653,7 +653,7 @@ void TagProcess(CORO_PARAM, const void *) { SaveTaggedPoly(NOPOLY); // No tagged polygon yet while (1) { - if (bTagsActive) { + if (g_bTagsActive) { int curX, curY; // cursor position while (!GetCursorXYNoWait(&curX, &curY, true)) CORO_SLEEP(1); @@ -804,7 +804,7 @@ void PointProcess(CORO_PARAM, const void *) { // allow re-scheduling do { CORO_SLEEP(1); - } while (!bPointingActive); + } while (!g_bPointingActive); } else { // allow re-scheduling CORO_SLEEP(1); @@ -815,15 +815,15 @@ void PointProcess(CORO_PARAM, const void *) { } void DisableTags() { - bTagsActive = false; + g_bTagsActive = false; } void EnableTags() { - bTagsActive = true; + g_bTagsActive = true; } bool DisableTagsIfEnabled() { - if (bTagsActive) { + if (g_bTagsActive) { DisableTags(); return true; } else @@ -836,12 +836,12 @@ bool DisableTagsIfEnabled() { * cursor is in. */ void TogglePathDisplay() { - DispPath ^= 1; // Toggle path display (XOR with true) + g_DispPath ^= 1; // Toggle path display (XOR with true) } void setshowstring() { - bShowString = true; + g_bShowString = true; } } // End of namespace Tinsel diff --git a/engines/tinsel/play.cpp b/engines/tinsel/play.cpp index 71e07721a6..40729d9f3a 100644 --- a/engines/tinsel/play.cpp +++ b/engines/tinsel/play.cpp @@ -62,10 +62,10 @@ struct PPINIT { // FIXME: Avoid non-const global vars -static SOUNDREELS soundReels[MAX_SOUNDREELS]; -static int soundReelNumbers[MAX_SOUNDREELS]; +static SOUNDREELS g_soundReels[MAX_SOUNDREELS]; +static int g_soundReelNumbers[MAX_SOUNDREELS]; -static int soundReelWait; +static int g_soundReelWait; //-------------------- METHODS ---------------------- @@ -148,31 +148,31 @@ static int RegisterSoundReel(SCNHANDLE hFilm, int column, int actorCol) { for (i = 0; i < MAX_SOUNDREELS; i++) { // Should assert this doesn't happen, but let's be tolerant - if (soundReels[i].hFilm == hFilm && soundReels[i].column == column) + if (g_soundReels[i].hFilm == hFilm && g_soundReels[i].column == column) break; - if (!soundReels[i].hFilm) { - soundReels[i].hFilm = hFilm; - soundReels[i].column = column; - soundReels[i].actorCol = actorCol; + if (!g_soundReels[i].hFilm) { + g_soundReels[i].hFilm = hFilm; + g_soundReels[i].column = column; + g_soundReels[i].actorCol = actorCol; break; } } - soundReelNumbers[i]++; + g_soundReelNumbers[i]++; return i; } void NoSoundReels() { - memset(soundReels, 0, sizeof(soundReels)); - soundReelWait = 0; + memset(g_soundReels, 0, sizeof(g_soundReels)); + g_soundReelWait = 0; } static void DeRegisterSoundReel(SCNHANDLE hFilm, int column) { for (int i = 0; i < MAX_SOUNDREELS; i++) { // Should assert this doesn't happen, but let's be tolerant - if (soundReels[i].hFilm == hFilm && soundReels[i].column == column) { - soundReels[i].hFilm = 0; + if (g_soundReels[i].hFilm == hFilm && g_soundReels[i].column == column) { + g_soundReels[i].hFilm = 0; break; } } @@ -180,15 +180,15 @@ static void DeRegisterSoundReel(SCNHANDLE hFilm, int column) { void SaveSoundReels(PSOUNDREELS psr) { for (int i = 0; i < MAX_SOUNDREELS; i++) { - if (IsCdPlayHandle(soundReels[i].hFilm)) - soundReels[i].hFilm = 0; + if (IsCdPlayHandle(g_soundReels[i].hFilm)) + g_soundReels[i].hFilm = 0; } - memcpy(psr, soundReels, sizeof(soundReels)); + memcpy(psr, g_soundReels, sizeof(g_soundReels)); } void RestoreSoundReels(PSOUNDREELS psr) { - memcpy(soundReels, psr, sizeof(soundReels)); + memcpy(g_soundReels, psr, sizeof(g_soundReels)); } static uint32 GetZfactor(int actorID, PMOVER pMover, bool bNewMover) { @@ -245,7 +245,7 @@ static void SoundReel(CORO_PARAM, SCNHANDLE hFilm, int column, int speed, _ctx->bFinished = false; _ctx->bLooped = false; _ctx->myId = RegisterSoundReel(hFilm, column, actorCol); - _ctx->myNum = soundReelNumbers[_ctx->myId]; + _ctx->myNum = g_soundReelNumbers[_ctx->myId]; do { pFilm = (FILM *)LockMem(hFilm); @@ -366,10 +366,10 @@ static void SoundReel(CORO_PARAM, SCNHANDLE hFilm, int column, int speed, _ctx->bFinished = true; } - } while (!_ctx->bFinished && _ctx->myNum == soundReelNumbers[_ctx->myId]); + } while (!_ctx->bFinished && _ctx->myNum == g_soundReelNumbers[_ctx->myId]); // De-register - if not been replaced - if (_ctx->myNum == soundReelNumbers[_ctx->myId]) + if (_ctx->myNum == g_soundReelNumbers[_ctx->myId]) DeRegisterSoundReel(hFilm, column); CORO_END_CODE; @@ -384,17 +384,17 @@ static void ResSoundReel(CORO_PARAM, const void *param) { CORO_BEGIN_CODE(_ctx); - CORO_INVOKE_ARGS(SoundReel, (CORO_SUBCTX, soundReels[i].hFilm, soundReels[i].column, - -1, 0, soundReels[i].actorCol)); + CORO_INVOKE_ARGS(SoundReel, (CORO_SUBCTX, g_soundReels[i].hFilm, g_soundReels[i].column, + -1, 0, g_soundReels[i].actorCol)); CORO_KILL_SELF(); CORO_END_CODE; } static void SoundReelWaitCheck() { - if (--soundReelWait == 0) { + if (--g_soundReelWait == 0) { for (int i = 0; i < MAX_SOUNDREELS; i++) { - if (soundReels[i].hFilm) { + if (g_soundReels[i].hFilm) { g_scheduler->createProcess(PID_REEL, ResSoundReel, &i, sizeof(i)); } } @@ -1162,7 +1162,7 @@ void RestoreActorReels(SCNHANDLE hFilm, int actor, int x, int y) { // Start display process for the reel g_scheduler->createProcess(PID_REEL, PlayProcess, &ppi, sizeof(ppi)); - soundReelWait++; + g_soundReelWait++; } } } diff --git a/engines/tinsel/rince.cpp b/engines/tinsel/rince.cpp index ca196aac92..bb0aeabd2f 100644 --- a/engines/tinsel/rince.cpp +++ b/engines/tinsel/rince.cpp @@ -51,7 +51,7 @@ namespace Tinsel { //----------------- LOCAL GLOBAL DATA -------------------- -static MOVER Movers[MAX_MOVERS]; // FIXME: Avoid non-const global vars +static MOVER g_Movers[MAX_MOVERS]; // FIXME: Avoid non-const global vars //----------------- FUNCTIONS ---------------------------- @@ -115,7 +115,7 @@ void MoverBrightness(PMOVER pMover, int brightness) { * RebootMovers */ void RebootMovers() { - memset(Movers, 0, sizeof(Movers)); + memset(g_Movers, 0, sizeof(g_Movers)); } /** @@ -127,11 +127,11 @@ PMOVER GetMover(int ano) { // Slot 0 is reserved for lead actor if (ano == GetLeadId() || ano == LEAD_ACTOR) - return &Movers[0]; + return &g_Movers[0]; for (i = 1; i < MAX_MOVERS; i++) - if (Movers[i].actorID == ano) - return &Movers[i]; + if (g_Movers[i].actorID == ano) + return &g_Movers[i]; return NULL; } @@ -144,25 +144,25 @@ PMOVER RegisterMover(int ano) { // Slot 0 is reserved for lead actor if (ano == GetLeadId() || ano == LEAD_ACTOR) { - Movers[0].actorToken = TOKEN_LEAD; - Movers[0].actorID = GetLeadId(); - return &Movers[0]; + g_Movers[0].actorToken = TOKEN_LEAD; + g_Movers[0].actorID = GetLeadId(); + return &g_Movers[0]; } // Check it hasn't already been declared for (i = 1; i < MAX_MOVERS; i++) { - if (Movers[i].actorID == ano) { + if (g_Movers[i].actorID == ano) { // Actor is already a moving actor - return &Movers[i]; + return &g_Movers[i]; } } // Find an empty slot for (i = 1; i < MAX_MOVERS; i++) - if (!Movers[i].actorID) { - Movers[i].actorToken = TOKEN_LEAD + i; - Movers[i].actorID = ano; - return &Movers[i]; + if (!g_Movers[i].actorID) { + g_Movers[i].actorToken = TOKEN_LEAD + i; + g_Movers[i].actorID = ano; + return &g_Movers[i]; } error("Too many moving actors"); @@ -176,8 +176,8 @@ PMOVER RegisterMover(int ano) { PMOVER GetLiveMover(int index) { assert(index >= 0 && index < MAX_MOVERS); // out of range - if (Movers[index].bActive) - return &Movers[index]; + if (g_Movers[index].bActive) + return &g_Movers[index]; else return NULL; } @@ -185,13 +185,13 @@ PMOVER GetLiveMover(int index) { bool IsMAinEffectPoly(int index) { assert(index >= 0 && index < MAX_MOVERS); // out of range - return Movers[index].bInEffect; + return g_Movers[index].bInEffect; } void SetMoverInEffect(int index, bool tf) { assert(index >= 0 && index < MAX_MOVERS); // out of range - Movers[index].bInEffect = tf; + g_Movers[index].bInEffect = tf; } /** @@ -392,7 +392,7 @@ static void InitMover(PMOVER pMover) { */ void DropMovers() { for (int i = 0; i < MAX_MOVERS; i++) - InitMover(&Movers[i]); + InitMover(&g_Movers[i]); } @@ -880,30 +880,30 @@ PMOVER InMoverBlock(PMOVER pMover, int x, int y) { caR = GetMoverRight(pMover) + x - caX; for (int i = 0; i < MAX_MOVERS; i++) { - if (pMover == &Movers[i] || - (TinselV2 && (Movers[i].actorObj == NULL)) || - (!TinselV2 && !Movers[i].bActive)) + if (pMover == &g_Movers[i] || + (TinselV2 && (g_Movers[i].actorObj == NULL)) || + (!TinselV2 && !g_Movers[i].bActive)) continue; // At around the same height? - GetMoverPosition(&Movers[i], &taX, &taY); - if (Movers[i].hFnpath != NOPOLY) + GetMoverPosition(&g_Movers[i], &taX, &taY); + if (g_Movers[i].hFnpath != NOPOLY) continue; if (ABS(y - taY) > 2) // 2 was 8 continue; // To the left? - taL = GetMoverLeft(&Movers[i]); + taL = GetMoverLeft(&g_Movers[i]); if (caR <= taL) continue; // To the right? - taR = GetMoverRight(&Movers[i]); + taR = GetMoverRight(&g_Movers[i]); if (caL >= taR) continue; - return &Movers[i]; + return &g_Movers[i]; } return NULL; } @@ -913,33 +913,33 @@ PMOVER InMoverBlock(PMOVER pMover, int x, int y) { */ void SaveMovers(SAVED_MOVER *sMoverInfo) { for (int i = 0; i < MAX_MOVERS; i++) { - sMoverInfo[i].bActive = !TinselV2 ? Movers[i].bActive : Movers[i].actorObj != NULL; - sMoverInfo[i].actorID = Movers[i].actorID; - sMoverInfo[i].objX = Movers[i].objX; - sMoverInfo[i].objY = Movers[i].objY; - sMoverInfo[i].hLastfilm = Movers[i].hLastFilm; + sMoverInfo[i].bActive = !TinselV2 ? g_Movers[i].bActive : g_Movers[i].actorObj != NULL; + sMoverInfo[i].actorID = g_Movers[i].actorID; + sMoverInfo[i].objX = g_Movers[i].objX; + sMoverInfo[i].objY = g_Movers[i].objY; + sMoverInfo[i].hLastfilm = g_Movers[i].hLastFilm; if (TinselV2) { - sMoverInfo[i].bHidden = Movers[i].bHidden; - sMoverInfo[i].brightness = Movers[i].brightness; - sMoverInfo[i].startColor = Movers[i].startColor; - sMoverInfo[i].paletteLength = Movers[i].paletteLength; + sMoverInfo[i].bHidden = g_Movers[i].bHidden; + sMoverInfo[i].brightness = g_Movers[i].brightness; + sMoverInfo[i].startColor = g_Movers[i].startColor; + sMoverInfo[i].paletteLength = g_Movers[i].paletteLength; } - memcpy(sMoverInfo[i].walkReels, Movers[i].walkReels, TOTAL_SCALES * 4 * sizeof(SCNHANDLE)); - memcpy(sMoverInfo[i].standReels, Movers[i].standReels, TOTAL_SCALES * 4 * sizeof(SCNHANDLE)); - memcpy(sMoverInfo[i].talkReels, Movers[i].talkReels, TOTAL_SCALES * 4 * sizeof(SCNHANDLE)); + memcpy(sMoverInfo[i].walkReels, g_Movers[i].walkReels, TOTAL_SCALES * 4 * sizeof(SCNHANDLE)); + memcpy(sMoverInfo[i].standReels, g_Movers[i].standReels, TOTAL_SCALES * 4 * sizeof(SCNHANDLE)); + memcpy(sMoverInfo[i].talkReels, g_Movers[i].talkReels, TOTAL_SCALES * 4 * sizeof(SCNHANDLE)); } } void RestoreAuxScales(SAVED_MOVER *sMoverInfo) { for (int i = 0; i < MAX_MOVERS; i++) { if (TinselV2) - Movers[i].actorID = sMoverInfo[i].actorID; + g_Movers[i].actorID = sMoverInfo[i].actorID; - memcpy(Movers[i].walkReels, sMoverInfo[i].walkReels, TOTAL_SCALES * 4 * sizeof(SCNHANDLE)); - memcpy(Movers[i].standReels, sMoverInfo[i].standReels, TOTAL_SCALES * 4 * sizeof(SCNHANDLE)); - memcpy(Movers[i].talkReels, sMoverInfo[i].talkReels, TOTAL_SCALES * 4 * sizeof(SCNHANDLE)); + memcpy(g_Movers[i].walkReels, sMoverInfo[i].walkReels, TOTAL_SCALES * 4 * sizeof(SCNHANDLE)); + memcpy(g_Movers[i].standReels, sMoverInfo[i].standReels, TOTAL_SCALES * 4 * sizeof(SCNHANDLE)); + memcpy(g_Movers[i].talkReels, sMoverInfo[i].talkReels, TOTAL_SCALES * 4 * sizeof(SCNHANDLE)); } } @@ -950,10 +950,10 @@ PMOVER NextMover(PMOVER pMover) { if (pMover == NULL) next = 0; else - next = pMover - Movers + 1; + next = pMover - g_Movers + 1; - if (Movers[next].actorID) - return &Movers[next]; + if (g_Movers[next].actorID) + return &g_Movers[next]; else return NULL; } diff --git a/engines/tinsel/saveload.cpp b/engines/tinsel/saveload.cpp index f8598c05f8..0a552c8c2b 100644 --- a/engines/tinsel/saveload.cpp +++ b/engines/tinsel/saveload.cpp @@ -68,9 +68,9 @@ namespace Tinsel { //----------------- GLOBAL GLOBAL DATA -------------------- -int thingHeld = 0; -int restoreCD = 0; -SRSTATE SRstate = SR_IDLE; +int g_thingHeld = 0; +int g_restoreCD = 0; +SRSTATE g_SRstate = SR_IDLE; //----------------- EXTERN FUNCTIONS -------------------- @@ -83,9 +83,9 @@ extern void syncGlobInfo(Common::Serializer &s); // in POLYGONS.C extern void syncPolyInfo(Common::Serializer &s); -extern int sceneCtr; +extern int g_sceneCtr; -extern bool ASceneIsSaved; +extern bool g_ASceneIsSaved; //----------------- LOCAL DEFINES -------------------- @@ -123,21 +123,23 @@ struct SFILES { // FIXME: Avoid non-const global vars -static int numSfiles = 0; -static SFILES savedFiles[MAX_SAVED_FILES]; +static int g_numSfiles = 0; +static SFILES g_savedFiles[MAX_SAVED_FILES]; -static bool NeedLoad = true; +static bool g_NeedLoad = true; -static SAVED_DATA *srsd = 0; -static int RestoreGameNumber = 0; -static char *SaveSceneName = 0; -static const char *SaveSceneDesc = 0; -static int *SaveSceneSsCount = 0; -static SAVED_DATA *SaveSceneSsData = 0; // points to 'SAVED_DATA ssdata[MAX_NEST]' +static SAVED_DATA *g_srsd = 0; +static int g_RestoreGameNumber = 0; +static char *g_SaveSceneName = 0; +static const char *g_SaveSceneDesc = 0; +static int *g_SaveSceneSsCount = 0; +static SAVED_DATA *g_SaveSceneSsData = 0; // points to 'SAVED_DATA ssdata[MAX_NEST]' //------------- SAVE/LOAD SUPPORT METHODS ---------------- -void setNeedLoad() { NeedLoad = true; } +void setNeedLoad() { + g_NeedLoad = true; +} static void syncTime(Common::Serializer &s, TimeDate &t) { s.syncAsUint16LE(t.tm_year); @@ -345,18 +347,18 @@ static int cmpTimeDate(const TimeDate &a, const TimeDate &b) { int getList(Common::SaveFileManager *saveFileMan, const Common::String &target) { // No change since last call? // TODO/FIXME: Just always reload this data? Be careful about slow downs!!! - if (!NeedLoad) - return numSfiles; + if (!g_NeedLoad) + return g_numSfiles; int i; const Common::String pattern = target + ".???"; Common::StringArray files = saveFileMan->listSavefiles(pattern); - numSfiles = 0; + g_numSfiles = 0; for (Common::StringArray::const_iterator file = files.begin(); file != files.end(); ++file) { - if (numSfiles >= MAX_SAVED_FILES) + if (g_numSfiles >= MAX_SAVED_FILES) break; const Common::String &fname = *file; @@ -376,46 +378,46 @@ int getList(Common::SaveFileManager *saveFileMan, const Common::String &target) // "incompatible version". } - i = numSfiles; + i = g_numSfiles; #ifndef DISABLE_SAVEGAME_SORTING - for (i = 0; i < numSfiles; i++) { - if (cmpTimeDate(hdr.dateTime, savedFiles[i].dateTime) > 0) { - Common::copy_backward(&savedFiles[i], &savedFiles[numSfiles], &savedFiles[numSfiles + 1]); + for (i = 0; i < g_numSfiles; i++) { + if (cmpTimeDate(hdr.dateTime, g_savedFiles[i].dateTime) > 0) { + Common::copy_backward(&g_savedFiles[i], &g_savedFiles[g_numSfiles], &g_savedFiles[g_numSfiles + 1]); break; } } #endif - Common::strlcpy(savedFiles[i].name, fname.c_str(), FNAMELEN); - Common::strlcpy(savedFiles[i].desc, hdr.desc, SG_DESC_LEN); - savedFiles[i].dateTime = hdr.dateTime; + Common::strlcpy(g_savedFiles[i].name, fname.c_str(), FNAMELEN); + Common::strlcpy(g_savedFiles[i].desc, hdr.desc, SG_DESC_LEN); + g_savedFiles[i].dateTime = hdr.dateTime; - ++numSfiles; + ++g_numSfiles; } // Next getList() needn't do its stuff again - NeedLoad = false; + g_NeedLoad = false; - return numSfiles; + return g_numSfiles; } int getList() { // No change since last call? // TODO/FIXME: Just always reload this data? Be careful about slow downs!!! - if (!NeedLoad) - return numSfiles; + if (!g_NeedLoad) + return g_numSfiles; return getList(_vm->getSaveFileMan(), _vm->getTargetName()); } char *ListEntry(int i, letype which) { if (i == -1) - i = numSfiles; + i = g_numSfiles; assert(i >= 0); - if (i < numSfiles) - return which == LE_NAME ? savedFiles[i].name : savedFiles[i].desc; + if (i < g_numSfiles) + return which == LE_NAME ? g_savedFiles[i].name : g_savedFiles[i].desc; else return NULL; } @@ -425,14 +427,14 @@ static void DoSync(Common::Serializer &s) { if (TinselV2) { if (s.isSaving()) - restoreCD = GetCurrentCD(); - s.syncAsSint16LE(restoreCD); + g_restoreCD = GetCurrentCD(); + s.syncAsSint16LE(g_restoreCD); } if (TinselV2 && s.isLoading()) HoldItem(INV_NOICON); - syncSavedData(s, *srsd); + syncSavedData(s, *g_srsd); syncGlobInfo(s); // Glitter globals syncInvInfo(s); // Inventory data @@ -442,7 +444,7 @@ static void DoSync(Common::Serializer &s) { s.syncAsSint32LE(sg); if (s.isLoading()) { if (TinselV2) - thingHeld = sg; + g_thingHeld = sg; else HoldItem(sg); } @@ -452,17 +454,17 @@ static void DoSync(Common::Serializer &s) { syncPolyInfo(s); // Dead polygon data syncSCdata(s); // Hook Scene and delayed scene - s.syncAsSint32LE(*SaveSceneSsCount); + s.syncAsSint32LE(*g_SaveSceneSsCount); - if (*SaveSceneSsCount != 0) { - SAVED_DATA *sdPtr = SaveSceneSsData; - for (int i = 0; i < *SaveSceneSsCount; ++i, ++sdPtr) + if (*g_SaveSceneSsCount != 0) { + SAVED_DATA *sdPtr = g_SaveSceneSsData; + for (int i = 0; i < *g_SaveSceneSsCount; ++i, ++sdPtr) syncSavedData(s, *sdPtr); // Flag that there is a saved scene to return to. Note that in this context 'saved scene' // is a stored scene to return to from another scene, such as from the Summoning Book close-up // in Discworld 1 to whatever scene Rincewind was in prior to that - ASceneIsSaved = true; + g_ASceneIsSaved = true; } if (!TinselV2) @@ -473,7 +475,7 @@ static void DoSync(Common::Serializer &s) { * DoRestore */ static bool DoRestore() { - Common::InSaveFile *f = _vm->getSaveFileMan()->openForLoading(savedFiles[RestoreGameNumber].name); + Common::InSaveFile *f = _vm->getSaveFileMan()->openForLoading(g_savedFiles[g_RestoreGameNumber].name); if (f == NULL) { return false; @@ -507,8 +509,8 @@ static bool DoRestore() { static void SaveFailure(Common::OutSaveFile *f) { if (f) { delete f; - _vm->getSaveFileMan()->removeSavefile(SaveSceneName); - SaveSceneName = NULL; // Invalidate save name + _vm->getSaveFileMan()->removeSavefile(g_SaveSceneName); + g_SaveSceneName = NULL; // Invalidate save name } GUI::MessageDialog dialog(_("Failed to save game state to file.")); dialog.runModal(); @@ -522,9 +524,9 @@ static void DoSave() { char tmpName[FNAMELEN]; // Next getList() must do its stuff again - NeedLoad = true; + g_NeedLoad = true; - if (SaveSceneName == NULL) { + if (g_SaveSceneName == NULL) { // Generate a new unique save name int i; int ano = 1; // Allocated number @@ -533,23 +535,23 @@ static void DoSave() { Common::String fname = _vm->getSavegameFilename(ano); strcpy(tmpName, fname.c_str()); - for (i = 0; i < numSfiles; i++) - if (!strcmp(savedFiles[i].name, tmpName)) + for (i = 0; i < g_numSfiles; i++) + if (!strcmp(g_savedFiles[i].name, tmpName)) break; - if (i == numSfiles) + if (i == g_numSfiles) break; ano++; } - SaveSceneName = tmpName; + g_SaveSceneName = tmpName; } - if (SaveSceneDesc[0] == 0) - SaveSceneDesc = "unnamed"; + if (g_SaveSceneDesc[0] == 0) + g_SaveSceneDesc = "unnamed"; - f = _vm->getSaveFileMan()->openForSaving(SaveSceneName); + f = _vm->getSaveFileMan()->openForSaving(g_SaveSceneName); Common::Serializer s(0, f); if (f == NULL) { @@ -562,7 +564,7 @@ static void DoSave() { hdr.id = SAVEGAME_ID; hdr.size = SAVEGAME_HEADER_SIZE; hdr.ver = CURRENT_VER; - memcpy(hdr.desc, SaveSceneDesc, SG_DESC_LEN); + memcpy(hdr.desc, g_SaveSceneDesc, SG_DESC_LEN); hdr.desc[SG_DESC_LEN - 1] = 0; g_system->getTimeAndDate(hdr.dateTime); hdr.scnFlag = _vm->getFeatures() & GF_SCNFILES; @@ -584,28 +586,29 @@ static void DoSave() { f->finalize(); delete f; - SaveSceneName = NULL; // Invalidate save name + g_SaveSceneName = NULL; // Invalidate save name } /** * ProcessSRQueue */ void ProcessSRQueue() { - switch (SRstate) { + switch (g_SRstate) { case SR_DORESTORE: // If a load has been done directly from title screens, set a larger value for scene ctr so the // code used to skip the title screens in Discworld 1 gets properly disabled - if (sceneCtr < 10) sceneCtr = 10; + if (g_sceneCtr < 10) + g_sceneCtr = 10; if (DoRestore()) { - DoRestoreScene(srsd, false); + DoRestoreScene(g_srsd, false); } - SRstate = SR_IDLE; + g_SRstate = SR_IDLE; break; case SR_DOSAVE: DoSave(); - SRstate = SR_IDLE; + g_SRstate = SR_IDLE; break; default: break; @@ -614,14 +617,14 @@ void ProcessSRQueue() { void RequestSaveGame(char *name, char *desc, SAVED_DATA *sd, int *pSsCount, SAVED_DATA *pSsData) { - assert(SRstate == SR_IDLE); - - SaveSceneName = name; - SaveSceneDesc = desc; - SaveSceneSsCount = pSsCount; - SaveSceneSsData = pSsData; - srsd = sd; - SRstate = SR_DOSAVE; + assert(g_SRstate == SR_IDLE); + + g_SaveSceneName = name; + g_SaveSceneDesc = desc; + g_SaveSceneSsCount = pSsCount; + g_SaveSceneSsData = pSsData; + g_srsd = sd; + g_SRstate = SR_DOSAVE; } void RequestRestoreGame(int num, SAVED_DATA *sd, int *pSsCount, SAVED_DATA *pSsData) { @@ -630,17 +633,17 @@ void RequestRestoreGame(int num, SAVED_DATA *sd, int *pSsCount, SAVED_DATA *pSsD return; else if (num == -2) { // From CD change for restore - num = RestoreGameNumber; + num = g_RestoreGameNumber; } } assert(num >= 0); - RestoreGameNumber = num; - SaveSceneSsCount = pSsCount; - SaveSceneSsData = pSsData; - srsd = sd; - SRstate = SR_DORESTORE; + g_RestoreGameNumber = num; + g_SaveSceneSsCount = pSsCount; + g_SaveSceneSsData = pSsData; + g_srsd = sd; + g_SRstate = SR_DORESTORE; } /** diff --git a/engines/tinsel/savescn.cpp b/engines/tinsel/savescn.cpp index 39a8033d45..1b06e3929c 100644 --- a/engines/tinsel/savescn.cpp +++ b/engines/tinsel/savescn.cpp @@ -75,29 +75,29 @@ enum { //----------------- EXTERNAL GLOBAL DATA -------------------- -extern int thingHeld; -extern int restoreCD; -extern SRSTATE SRstate; +extern int g_thingHeld; +extern int g_restoreCD; +extern SRSTATE g_SRstate; //----------------- LOCAL GLOBAL DATA -------------------- // FIXME: Avoid non-const global vars -bool ASceneIsSaved = false; +bool g_ASceneIsSaved = false; -static int savedSceneCount = 0; +static int g_savedSceneCount = 0; -static bool bNotDoneYet = false; +static bool g_bNotDoneYet = false; //static SAVED_DATA ssData[MAX_NEST]; -static SAVED_DATA *ssData = NULL; -static SAVED_DATA sgData; +static SAVED_DATA *g_ssData = NULL; +static SAVED_DATA g_sgData; -static SAVED_DATA *rsd = 0; +static SAVED_DATA *g_rsd = 0; -static int RestoreSceneCount = 0; +static int g_RestoreSceneCount = 0; -static bool bNoFade = false; +static bool g_bNoFade = false; //----------------- FORWARD REFERENCES -------------------- @@ -133,7 +133,7 @@ void DoSaveScene(SAVED_DATA *sd) { CurrentMidiFacts(&sd->SavedMidi, &sd->SavedLoop); } - ASceneIsSaved = true; + g_ASceneIsSaved = true; } /** @@ -142,29 +142,29 @@ void DoSaveScene(SAVED_DATA *sd) { * @param bFadeOut Flag to perform a fade out */ void DoRestoreScene(SAVED_DATA *sd, bool bFadeOut) { - rsd = sd; + g_rsd = sd; if (bFadeOut) - RestoreSceneCount = RS_COUNT + COUNTOUT_COUNT; // Set restore scene count + g_RestoreSceneCount = RS_COUNT + COUNTOUT_COUNT; // Set restore scene count else - RestoreSceneCount = RS_COUNT; // Set restore scene count + g_RestoreSceneCount = RS_COUNT; // Set restore scene count } void InitializeSaveScenes() { - if (ssData == NULL) { - ssData = (SAVED_DATA *)calloc(MAX_NEST, sizeof(SAVED_DATA)); - if (ssData == NULL) { + if (g_ssData == NULL) { + g_ssData = (SAVED_DATA *)calloc(MAX_NEST, sizeof(SAVED_DATA)); + if (g_ssData == NULL) { error("Cannot allocate memory for scene changes"); } } else { // Re-initialize - no scenes saved - savedSceneCount = 0; + g_savedSceneCount = 0; } } void FreeSaveScenes() { - free(ssData); - ssData = NULL; + free(g_ssData); + g_ssData = NULL; } /** @@ -212,29 +212,29 @@ static void SortMAProcess(CORO_PARAM, const void *) { _ctx->viaActor = SysVar(ISV_DIVERT_ACTOR); SetSysVar(ISV_DIVERT_ACTOR, 0); - RestoreAuxScales(rsd->SavedMoverInfo); + RestoreAuxScales(g_rsd->SavedMoverInfo); for (_ctx->i = 0; _ctx->i < MAX_MOVERS; _ctx->i++) { - if (rsd->SavedMoverInfo[_ctx->i].bActive) { - CORO_INVOKE_ARGS(Stand, (CORO_SUBCTX, rsd->SavedMoverInfo[_ctx->i].actorID, - rsd->SavedMoverInfo[_ctx->i].objX, rsd->SavedMoverInfo[_ctx->i].objY, - rsd->SavedMoverInfo[_ctx->i].hLastfilm)); + if (g_rsd->SavedMoverInfo[_ctx->i].bActive) { + CORO_INVOKE_ARGS(Stand, (CORO_SUBCTX, g_rsd->SavedMoverInfo[_ctx->i].actorID, + g_rsd->SavedMoverInfo[_ctx->i].objX, g_rsd->SavedMoverInfo[_ctx->i].objY, + g_rsd->SavedMoverInfo[_ctx->i].hLastfilm)); - if (rsd->SavedMoverInfo[_ctx->i].bHidden) - HideMover(GetMover(rsd->SavedMoverInfo[_ctx->i].actorID)); + if (g_rsd->SavedMoverInfo[_ctx->i].bHidden) + HideMover(GetMover(g_rsd->SavedMoverInfo[_ctx->i].actorID)); } - ActorPalette(rsd->SavedMoverInfo[_ctx->i].actorID, - rsd->SavedMoverInfo[_ctx->i].startColor, rsd->SavedMoverInfo[_ctx->i].paletteLength); + ActorPalette(g_rsd->SavedMoverInfo[_ctx->i].actorID, + g_rsd->SavedMoverInfo[_ctx->i].startColor, g_rsd->SavedMoverInfo[_ctx->i].paletteLength); - if (rsd->SavedMoverInfo[_ctx->i].brightness != BOGUS_BRIGHTNESS) - ActorBrightness(rsd->SavedMoverInfo[_ctx->i].actorID, rsd->SavedMoverInfo[_ctx->i].brightness); + if (g_rsd->SavedMoverInfo[_ctx->i].brightness != BOGUS_BRIGHTNESS) + ActorBrightness(g_rsd->SavedMoverInfo[_ctx->i].actorID, g_rsd->SavedMoverInfo[_ctx->i].brightness); } // Restore via actor SetSysVar(ISV_DIVERT_ACTOR, _ctx->viaActor); - bNotDoneYet = false; + g_bNotDoneYet = false; CORO_END_CODE; } @@ -244,49 +244,49 @@ static void SortMAProcess(CORO_PARAM, const void *) { void ResumeInterprets() { // Master script only affected on restore game, not restore scene - if (!TinselV2 && (rsd == &sgData)) { + if (!TinselV2 && (g_rsd == &g_sgData)) { g_scheduler->killMatchingProcess(PID_MASTER_SCR, -1); FreeMasterInterpretContext(); } for (int i = 0; i < NUM_INTERPRET; i++) { - switch (rsd->SavedICInfo[i].GSort) { + switch (g_rsd->SavedICInfo[i].GSort) { case GS_NONE: break; case GS_INVENTORY: - if (rsd->SavedICInfo[i].event != POINTED) { - RestoreProcess(&rsd->SavedICInfo[i]); + if (g_rsd->SavedICInfo[i].event != POINTED) { + RestoreProcess(&g_rsd->SavedICInfo[i]); } break; case GS_MASTER: // Master script only affected on restore game, not restore scene - if (rsd == &sgData) - RestoreMasterProcess(&rsd->SavedICInfo[i]); + if (g_rsd == &g_sgData) + RestoreMasterProcess(&g_rsd->SavedICInfo[i]); break; case GS_PROCESS: // Tinsel 2 process - RestoreSceneProcess(&rsd->SavedICInfo[i]); + RestoreSceneProcess(&g_rsd->SavedICInfo[i]); break; case GS_GPROCESS: // Tinsel 2 Global processes only affected on restore game, not restore scene - if (rsd == &sgData) - RestoreGlobalProcess(&rsd->SavedICInfo[i]); + if (g_rsd == &g_sgData) + RestoreGlobalProcess(&g_rsd->SavedICInfo[i]); break; case GS_ACTOR: if (TinselV2) - RestoreProcess(&rsd->SavedICInfo[i]); + RestoreProcess(&g_rsd->SavedICInfo[i]); else - RestoreActorProcess(rsd->SavedICInfo[i].idActor, &rsd->SavedICInfo[i], rsd == &sgData); + RestoreActorProcess(g_rsd->SavedICInfo[i].idActor, &g_rsd->SavedICInfo[i], g_rsd == &g_sgData); break; case GS_POLYGON: case GS_SCENE: - RestoreProcess(&rsd->SavedICInfo[i]); + RestoreProcess(&g_rsd->SavedICInfo[i]); break; default: @@ -313,7 +313,7 @@ static int DoRestoreSceneFrame(SAVED_DATA *sd, int n) { if (TinselV2) { // Master script only affected on restore game, not restore scene - if (sd == &sgData) { + if (sd == &g_sgData) { g_scheduler->killMatchingProcess(PID_MASTER_SCR); KillGlobalProcesses(); FreeMasterInterpretContext(); @@ -322,12 +322,12 @@ static int DoRestoreSceneFrame(SAVED_DATA *sd, int n) { RestorePolygonStuff(sd->SavedPolygonStuff); // Abandon temporarily if different CD - if (sd == &sgData && restoreCD != GetCurrentCD()) { - SRstate = SR_IDLE; + if (sd == &g_sgData && g_restoreCD != GetCurrentCD()) { + g_SRstate = SR_IDLE; EndScene(); - SetNextCD(restoreCD); - CDChangeForRestore(restoreCD); + SetNextCD(g_restoreCD); + CDChangeForRestore(g_restoreCD); return 0; } @@ -338,8 +338,8 @@ static int DoRestoreSceneFrame(SAVED_DATA *sd, int n) { // Start up the scene StartNewScene(sd->SavedSceneHandle, NO_ENTRY_NUM); - SetDoFadeIn(!bNoFade); - bNoFade = false; + SetDoFadeIn(!g_bNoFade); + g_bNoFade = false; StartupBackground(nullContext, sd->SavedBgroundHandle); if (TinselV2) { @@ -355,7 +355,7 @@ static int DoRestoreSceneFrame(SAVED_DATA *sd, int n) { if (TinselV2) { // create process to sort out the moving actors g_scheduler->createProcess(PID_MOVER, SortMAProcess, NULL, 0); - bNotDoneYet = true; + g_bNotDoneYet = true; RestoreActorZ(sd->savedActorZ); RestoreZpositions(sd->zPositions); @@ -374,11 +374,11 @@ static int DoRestoreSceneFrame(SAVED_DATA *sd, int n) { case 1: if (TinselV2) { - if (bNotDoneYet) + if (g_bNotDoneYet) return n; - if (sd == &sgData) - HoldItem(thingHeld, true); + if (sd == &g_sgData) + HoldItem(g_thingHeld, true); if (sd->bTinselDim) _vm->_pcmMusic->dim(true); _vm->_pcmMusic->restoreThatTune(sd->SavedTune); @@ -406,7 +406,7 @@ static int DoRestoreSceneFrame(SAVED_DATA *sd, int n) { void RestoreGame(int num) { KillInventory(); - RequestRestoreGame(num, &sgData, &savedSceneCount, ssData); + RequestRestoreGame(num, &g_sgData, &g_savedSceneCount, g_ssData); // Actual restoring is performed by ProcessSRQueue } @@ -418,9 +418,9 @@ void RestoreGame(int num) { */ void SaveGame(char *name, char *desc) { // Get current scene data - DoSaveScene(&sgData); + DoSaveScene(&g_sgData); - RequestSaveGame(name, desc, &sgData, &savedSceneCount, ssData); + RequestSaveGame(name, desc, &g_sgData, &g_savedSceneCount, g_ssData); // Actual saving is performed by ProcessSRQueue } @@ -429,11 +429,11 @@ void SaveGame(char *name, char *desc) { //--------------------------------------------------------------------------------- bool IsRestoringScene() { - if (RestoreSceneCount) { - RestoreSceneCount = DoRestoreSceneFrame(rsd, RestoreSceneCount); + if (g_RestoreSceneCount) { + g_RestoreSceneCount = DoRestoreSceneFrame(g_rsd, g_RestoreSceneCount); } - return RestoreSceneCount ? true : false; + return g_RestoreSceneCount ? true : false; } /** @@ -441,13 +441,13 @@ bool IsRestoringScene() { */ void TinselRestoreScene(bool bFade) { // only called by restore_scene PCODE - if (RestoreSceneCount == 0) { - assert(savedSceneCount >= 1); // No saved scene to restore + if (g_RestoreSceneCount == 0) { + assert(g_savedSceneCount >= 1); // No saved scene to restore - if (ASceneIsSaved) - DoRestoreScene(&ssData[--savedSceneCount], bFade); + if (g_ASceneIsSaved) + DoRestoreScene(&g_ssData[--g_savedSceneCount], bFade); if (!bFade) - bNoFade = true; + g_bNoFade = true; } } @@ -461,14 +461,14 @@ void TinselSaveScene(CORO_PARAM) { CORO_BEGIN_CODE(_ctx); - assert(savedSceneCount < MAX_NEST); // nesting limit reached + assert(g_savedSceneCount < MAX_NEST); // nesting limit reached // Don't save the same thing multiple times! // FIXME/TODO: Maybe this can be changed to an assert? - if (savedSceneCount && ssData[savedSceneCount-1].SavedSceneHandle == GetSceneHandle()) + if (g_savedSceneCount && g_ssData[g_savedSceneCount-1].SavedSceneHandle == GetSceneHandle()) CORO_KILL_SELF(); - DoSaveScene(&ssData[savedSceneCount++]); + DoSaveScene(&g_ssData[g_savedSceneCount++]); CORO_END_CODE; } diff --git a/engines/tinsel/scene.cpp b/engines/tinsel/scene.cpp index 89b0da7d65..f635ce13a3 100644 --- a/engines/tinsel/scene.cpp +++ b/engines/tinsel/scene.cpp @@ -107,15 +107,15 @@ struct ENTRANCE_STRUC { // FIXME: Avoid non-const global vars #ifdef DEBUG -static bool ShowPosition = false; // Set when showpos() has been called +static bool g_ShowPosition = false; // Set when showpos() has been called #endif -int sceneCtr = 0; -static int initialMyEscape; +int g_sceneCtr = 0; +static int g_initialMyEscape; -static SCNHANDLE SceneHandle = 0; // Current scene handle - stored in case of Save_Scene() +static SCNHANDLE g_SceneHandle = 0; // Current scene handle - stored in case of Save_Scene() -SCENE_STRUC tempStruc; +SCENE_STRUC g_tempStruc; struct TP_INIT { SCNHANDLE hTinselCode; // Code @@ -128,18 +128,18 @@ const SCENE_STRUC *GetSceneStruc(const byte *pStruc) { // Copy appropriate fields into tempStruc, and return a pointer to it const byte *p = pStruc; - memset(&tempStruc, 0, sizeof(SCENE_STRUC)); - - tempStruc.numEntrance = READ_UINT32(p); p += sizeof(uint32); - tempStruc.numPoly = READ_UINT32(p); p += sizeof(uint32); - tempStruc.numTaggedActor = READ_UINT32(p); p += sizeof(uint32); - tempStruc.defRefer = READ_UINT32(p); p += sizeof(uint32); - tempStruc.hSceneScript = READ_UINT32(p); p += sizeof(uint32); - tempStruc.hEntrance = READ_UINT32(p); p += sizeof(uint32); - tempStruc.hPoly = READ_UINT32(p); p += sizeof(uint32); - tempStruc.hTaggedActor = READ_UINT32(p); p += sizeof(uint32); - - return &tempStruc; + memset(&g_tempStruc, 0, sizeof(SCENE_STRUC)); + + g_tempStruc.numEntrance = READ_UINT32(p); p += sizeof(uint32); + g_tempStruc.numPoly = READ_UINT32(p); p += sizeof(uint32); + g_tempStruc.numTaggedActor = READ_UINT32(p); p += sizeof(uint32); + g_tempStruc.defRefer = READ_UINT32(p); p += sizeof(uint32); + g_tempStruc.hSceneScript = READ_UINT32(p); p += sizeof(uint32); + g_tempStruc.hEntrance = READ_UINT32(p); p += sizeof(uint32); + g_tempStruc.hPoly = READ_UINT32(p); p += sizeof(uint32); + g_tempStruc.hTaggedActor = READ_UINT32(p); p += sizeof(uint32); + + return &g_tempStruc; } @@ -157,8 +157,8 @@ static void SceneTinselProcess(CORO_PARAM, const void *param) { CORO_BEGIN_CODE(_ctx); // The following myEscape value setting is used for enabling title screen skipping in DW1 - if (TinselV1 && (sceneCtr == 1)) initialMyEscape = GetEscEvents(); - _ctx->myEscape = (TinselV1 && (sceneCtr < 4)) ? initialMyEscape : 0; + if (TinselV1 && (g_sceneCtr == 1)) g_initialMyEscape = GetEscEvents(); + _ctx->myEscape = (TinselV1 && (g_sceneCtr < 4)) ? g_initialMyEscape : 0; // get the stuff copied to process when it was created _ctx->pInit = (const TP_INIT *)param; @@ -184,8 +184,8 @@ static void SceneTinselProcess(CORO_PARAM, const void *param) { void SendSceneTinselProcess(TINSEL_EVENT event) { SCENE_STRUC *ss; - if (SceneHandle != (SCNHANDLE)NULL) { - ss = (SCENE_STRUC *) FindChunk(SceneHandle, CHUNK_SCENE); + if (g_SceneHandle != (SCNHANDLE)NULL) { + ss = (SCENE_STRUC *) FindChunk(g_SceneHandle, CHUNK_SCENE); if (ss->hSceneScript) { TP_INIT init; @@ -214,9 +214,9 @@ static void LoadScene(SCNHANDLE scene, int entry) { const ENTRANCE_STRUC *es; // Scene handle - SceneHandle = scene; // Save scene handle in case of Save_Scene() - LockMem(SceneHandle); // Make sure scene is loaded - LockScene(SceneHandle); // Prevent current scene from being discarded + g_SceneHandle = scene; // Save scene handle in case of Save_Scene() + LockMem(g_SceneHandle); // Make sure scene is loaded + LockScene(g_SceneHandle); // Prevent current scene from being discarded if (TinselV2) { // CdPlay() stuff @@ -307,9 +307,9 @@ static void LoadScene(SCNHANDLE scene, int entry) { * Wrap up the last scene. */ void EndScene() { - if (SceneHandle != 0) { - UnlockScene(SceneHandle); - SceneHandle = 0; + if (g_SceneHandle != 0) { + UnlockScene(g_SceneHandle); + g_SceneHandle = 0; } KillInventory(); // Close down any open inventory @@ -409,7 +409,7 @@ void PrimeScene() { g_scheduler->createProcess(PID_SCROLL, EffectPolyProcess, NULL, 0); #ifdef DEBUG - if (ShowPosition) + if (g_ShowPosition) g_scheduler->createProcess(PID_POSITION, CursorPositionProcess, NULL, 0); #endif @@ -445,7 +445,7 @@ void StartNewScene(SCNHANDLE scene, int entry) { */ void setshowpos() { - ShowPosition = true; + g_ShowPosition = true; } #endif @@ -454,7 +454,7 @@ void setshowpos() { */ SCNHANDLE GetSceneHandle() { - return SceneHandle; + return g_SceneHandle; } /** diff --git a/engines/tinsel/sched.cpp b/engines/tinsel/sched.cpp index d6cd806eb2..343758d924 100644 --- a/engines/tinsel/sched.cpp +++ b/engines/tinsel/sched.cpp @@ -47,11 +47,11 @@ struct PROCESS_STRUC { // FIXME: Avoid non-const global vars -static uint32 numSceneProcess; -static SCNHANDLE hSceneProcess; +static uint32 g_numSceneProcess; +static SCNHANDLE g_hSceneProcess; -static uint32 numGlobalProcess; -static PROCESS_STRUC *pGlobalProcess; +static uint32 g_numGlobalProcess; +static PROCESS_STRUC *g_pGlobalProcess; //--------------------- FUNCTIONS ------------------------ @@ -574,8 +574,8 @@ void RestoreSceneProcess(INT_CONTEXT *pic) { uint32 i; PROCESS_STRUC *pStruc; - pStruc = (PROCESS_STRUC *)LockMem(hSceneProcess); - for (i = 0; i < numSceneProcess; i++) { + pStruc = (PROCESS_STRUC *)LockMem(g_hSceneProcess); + for (i = 0; i < g_numSceneProcess; i++) { if (FROM_LE_32(pStruc[i].hProcessCode) == pic->hCode) { g_scheduler->createProcess(PID_PROCESS + i, RestoredProcessProcess, &pic, sizeof(pic)); @@ -583,7 +583,7 @@ void RestoreSceneProcess(INT_CONTEXT *pic) { } } - assert(i < numSceneProcess); + assert(i < g_numSceneProcess); } /** @@ -602,8 +602,8 @@ void SceneProcessEvent(CORO_PARAM, uint32 procID, TINSEL_EVENT event, bool bWait CORO_BEGIN_CODE(_ctx); - _ctx->pStruc = (PROCESS_STRUC *)LockMem(hSceneProcess); - for (i = 0; i < numSceneProcess; i++) { + _ctx->pStruc = (PROCESS_STRUC *)LockMem(g_hSceneProcess); + for (i = 0; i < g_numSceneProcess; i++) { if (FROM_LE_32(_ctx->pStruc[i].processId) == procID) { assert(_ctx->pStruc[i].hProcessCode); // Must have some code to run @@ -624,7 +624,7 @@ void SceneProcessEvent(CORO_PARAM, uint32 procID, TINSEL_EVENT event, bool bWait } } - if (i == numSceneProcess) + if (i == g_numSceneProcess) return; if (bWait) { @@ -641,8 +641,8 @@ void KillSceneProcess(uint32 procID) { uint32 i; // Loop counter PROCESS_STRUC *pStruc; - pStruc = (PROCESS_STRUC *) LockMem(hSceneProcess); - for (i = 0; i < numSceneProcess; i++) { + pStruc = (PROCESS_STRUC *) LockMem(g_hSceneProcess); + for (i = 0; i < g_numSceneProcess; i++) { if (FROM_LE_32(pStruc[i].processId) == procID) { g_scheduler->killMatchingProcess(PID_PROCESS + i, -1); break; @@ -654,8 +654,8 @@ void KillSceneProcess(uint32 procID) { * Register the scene processes in a scene. */ void SceneProcesses(uint32 numProcess, SCNHANDLE hProcess) { - numSceneProcess = numProcess; - hSceneProcess = hProcess; + g_numSceneProcess = numProcess; + g_hSceneProcess = hProcess; } @@ -669,15 +669,15 @@ void SceneProcesses(uint32 numProcess, SCNHANDLE hProcess) { void RestoreGlobalProcess(INT_CONTEXT *pic) { uint32 i; // Loop counter - for (i = 0; i < numGlobalProcess; i++) { - if (pGlobalProcess[i].hProcessCode == pic->hCode) { + for (i = 0; i < g_numGlobalProcess; i++) { + if (g_pGlobalProcess[i].hProcessCode == pic->hCode) { g_scheduler->createProcess(PID_GPROCESS + i, RestoredProcessProcess, &pic, sizeof(pic)); break; } } - assert(i < numGlobalProcess); + assert(i < g_numGlobalProcess); } /** @@ -685,7 +685,7 @@ void RestoreGlobalProcess(INT_CONTEXT *pic) { */ void KillGlobalProcesses() { - for (uint32 i = 0; i < numGlobalProcess; ++i) { + for (uint32 i = 0; i < g_numGlobalProcess; ++i) { g_scheduler->killMatchingProcess(PID_GPROCESS + i, -1); } } @@ -706,12 +706,12 @@ bool GlobalProcessEvent(CORO_PARAM, uint32 procID, TINSEL_EVENT event, bool bWai uint32 i; // Loop counter _ctx->pProc = NULL; - for (i = 0; i < numGlobalProcess; ++i) { - if (pGlobalProcess[i].processId == procID) { - assert(pGlobalProcess[i].hProcessCode); // Must have some code to run + for (i = 0; i < g_numGlobalProcess; ++i) { + if (g_pGlobalProcess[i].processId == procID) { + assert(g_pGlobalProcess[i].hProcessCode); // Must have some code to run _ctx->pic = InitInterpretContext(GS_GPROCESS, - pGlobalProcess[i].hProcessCode, + g_pGlobalProcess[i].hProcessCode, event, NOPOLY, // No polygon 0, // No actor @@ -728,7 +728,7 @@ bool GlobalProcessEvent(CORO_PARAM, uint32 procID, TINSEL_EVENT event, bool bWai } } - if ((i == numGlobalProcess) || (_ctx->pic == NULL)) + if ((i == g_numGlobalProcess) || (_ctx->pic == NULL)) result = false; else if (bWait) CORO_INVOKE_ARGS_V(WaitInterpret, false, (CORO_SUBCTX, _ctx->pProc, &result)); @@ -743,8 +743,8 @@ bool GlobalProcessEvent(CORO_PARAM, uint32 procID, TINSEL_EVENT event, bool bWai void xKillGlobalProcess(uint32 procID) { uint32 i; // Loop counter - for (i = 0; i < numGlobalProcess; ++i) { - if (pGlobalProcess[i].processId == procID) { + for (i = 0; i < g_numGlobalProcess; ++i) { + if (g_pGlobalProcess[i].processId == procID) { g_scheduler->killMatchingProcess(PID_GPROCESS + i, -1); break; } @@ -755,13 +755,13 @@ void xKillGlobalProcess(uint32 procID) { * Register the global processes list */ void GlobalProcesses(uint32 numProcess, byte *pProcess) { - pGlobalProcess = new PROCESS_STRUC[numProcess]; - numGlobalProcess = numProcess; + g_pGlobalProcess = new PROCESS_STRUC[numProcess]; + g_numGlobalProcess = numProcess; byte *p = pProcess; for (uint i = 0; i < numProcess; ++i, p += 8) { - pGlobalProcess[i].processId = READ_LE_UINT32(p); - pGlobalProcess[i].hProcessCode = READ_LE_UINT32(p + 4); + g_pGlobalProcess[i].processId = READ_LE_UINT32(p); + g_pGlobalProcess[i].hProcessCode = READ_LE_UINT32(p + 4); } } @@ -769,9 +769,9 @@ void GlobalProcesses(uint32 numProcess, byte *pProcess) { * Frees the global processes list */ void FreeGlobalProcesses() { - delete[] pGlobalProcess; - pGlobalProcess = 0; - numGlobalProcess = 0; + delete[] g_pGlobalProcess; + g_pGlobalProcess = 0; + g_numGlobalProcess = 0; } } // End of namespace Tinsel diff --git a/engines/tinsel/scroll.cpp b/engines/tinsel/scroll.cpp index d75e649be3..0a6a281d35 100644 --- a/engines/tinsel/scroll.cpp +++ b/engines/tinsel/scroll.cpp @@ -49,14 +49,14 @@ namespace Tinsel { // FIXME: Avoid non-const global vars -static int LeftScroll = 0, DownScroll = 0; // Number of iterations outstanding +static int g_LeftScroll = 0, g_DownScroll = 0; // Number of iterations outstanding -static int scrollActor = 0; -static PMOVER pScrollMover = 0; -static int oldx = 0, oldy = 0; +static int g_scrollActor = 0; +static PMOVER g_pScrollMover = 0; +static int g_oldx = 0, g_oldy = 0; /** Boundaries and numbers of boundaries */ -static SCROLLDATA sd = { +static SCROLLDATA g_sd = { { {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0} @@ -77,28 +77,28 @@ static SCROLLDATA sd = { 0 }; -static int ImageH = 0, ImageW = 0; +static int g_ImageH = 0, g_ImageW = 0; -static bool ScrollCursor = 0; // If a TAG or EXIT polygon is clicked on, +static bool g_ScrollCursor = 0; // If a TAG or EXIT polygon is clicked on, // the cursor is kept over that polygon // whilst scrolling -static int scrollPixelsX = SCROLLPIXELS; -static int scrollPixelsY = SCROLLPIXELS; +static int g_scrollPixelsX = SCROLLPIXELS; +static int g_scrollPixelsY = SCROLLPIXELS; /** * Reset the ScrollCursor flag */ void DontScrollCursor() { - ScrollCursor = false; + g_ScrollCursor = false; } /** * Set the ScrollCursor flag */ void DoScrollCursor() { - ScrollCursor = true; + g_ScrollCursor = true; } /** @@ -107,20 +107,20 @@ void DoScrollCursor() { void SetNoScroll(int x1, int y1, int x2, int y2) { if (x1 == x2) { /* Vertical line */ - assert(sd.NumNoH < MAX_HNOSCROLL); + assert(g_sd.NumNoH < MAX_HNOSCROLL); - sd.NoHScroll[sd.NumNoH].ln = x1; // X pos of vertical line - sd.NoHScroll[sd.NumNoH].c1 = y1; - sd.NoHScroll[sd.NumNoH].c2 = y2; - sd.NumNoH++; + g_sd.NoHScroll[g_sd.NumNoH].ln = x1; // X pos of vertical line + g_sd.NoHScroll[g_sd.NumNoH].c1 = y1; + g_sd.NoHScroll[g_sd.NumNoH].c2 = y2; + g_sd.NumNoH++; } else if (y1 == y2) { /* Horizontal line */ - assert(sd.NumNoV < MAX_VNOSCROLL); + assert(g_sd.NumNoV < MAX_VNOSCROLL); - sd.NoVScroll[sd.NumNoV].ln = y1; // Y pos of horizontal line - sd.NoVScroll[sd.NumNoV].c1 = x1; - sd.NoVScroll[sd.NumNoV].c2 = x2; - sd.NumNoV++; + g_sd.NoVScroll[g_sd.NumNoV].ln = y1; // Y pos of horizontal line + g_sd.NoVScroll[g_sd.NumNoV].c1 = x1; + g_sd.NoVScroll[g_sd.NumNoV].c2 = x2; + g_sd.NumNoV++; } else { /* No-scroll lines must be horizontal or vertical */ } @@ -144,21 +144,21 @@ static void NeedScroll(int direction) { BottomLine = Toffset + (SCREEN_HEIGHT - 1); RightCol = Loffset + (SCREEN_WIDTH - 1); - for (i = 0; i < sd.NumNoH; i++) { - if (RightCol >= sd.NoHScroll[i].ln - 1 && RightCol <= sd.NoHScroll[i].ln + 1 && - ((sd.NoHScroll[i].c1 >= Toffset && sd.NoHScroll[i].c1 <= BottomLine) || - (sd.NoHScroll[i].c2 >= Toffset && sd.NoHScroll[i].c2 <= BottomLine) || - (sd.NoHScroll[i].c1 < Toffset && sd.NoHScroll[i].c2 > BottomLine))) + for (i = 0; i < g_sd.NumNoH; i++) { + if (RightCol >= g_sd.NoHScroll[i].ln - 1 && RightCol <= g_sd.NoHScroll[i].ln + 1 && + ((g_sd.NoHScroll[i].c1 >= Toffset && g_sd.NoHScroll[i].c1 <= BottomLine) || + (g_sd.NoHScroll[i].c2 >= Toffset && g_sd.NoHScroll[i].c2 <= BottomLine) || + (g_sd.NoHScroll[i].c1 < Toffset && g_sd.NoHScroll[i].c2 > BottomLine))) return; } - if (LeftScroll <= 0) { + if (g_LeftScroll <= 0) { if (TinselV2) { - scrollPixelsX = sd.xSpeed; - LeftScroll += sd.xDistance; + g_scrollPixelsX = g_sd.xSpeed; + g_LeftScroll += g_sd.xDistance; } else { - scrollPixelsX = SCROLLPIXELS; - LeftScroll = RLSCROLL; + g_scrollPixelsX = SCROLLPIXELS; + g_LeftScroll = RLSCROLL; } } break; @@ -167,21 +167,21 @@ static void NeedScroll(int direction) { BottomLine = Toffset + (SCREEN_HEIGHT - 1); - for (i = 0; i < sd.NumNoH; i++) { - if (Loffset >= sd.NoHScroll[i].ln - 1 && Loffset <= sd.NoHScroll[i].ln + 1 && - ((sd.NoHScroll[i].c1 >= Toffset && sd.NoHScroll[i].c1 <= BottomLine) || - (sd.NoHScroll[i].c2 >= Toffset && sd.NoHScroll[i].c2 <= BottomLine) || - (sd.NoHScroll[i].c1 < Toffset && sd.NoHScroll[i].c2 > BottomLine))) + for (i = 0; i < g_sd.NumNoH; i++) { + if (Loffset >= g_sd.NoHScroll[i].ln - 1 && Loffset <= g_sd.NoHScroll[i].ln + 1 && + ((g_sd.NoHScroll[i].c1 >= Toffset && g_sd.NoHScroll[i].c1 <= BottomLine) || + (g_sd.NoHScroll[i].c2 >= Toffset && g_sd.NoHScroll[i].c2 <= BottomLine) || + (g_sd.NoHScroll[i].c1 < Toffset && g_sd.NoHScroll[i].c2 > BottomLine))) return; } - if (LeftScroll >= 0) { + if (g_LeftScroll >= 0) { if (TinselV2) { - scrollPixelsX = sd.xSpeed; - LeftScroll -= sd.xDistance; + g_scrollPixelsX = g_sd.xSpeed; + g_LeftScroll -= g_sd.xDistance; } else { - scrollPixelsX = SCROLLPIXELS; - LeftScroll = -RLSCROLL; + g_scrollPixelsX = SCROLLPIXELS; + g_LeftScroll = -RLSCROLL; } } break; @@ -191,21 +191,21 @@ static void NeedScroll(int direction) { BottomLine = Toffset + (SCREEN_HEIGHT - 1); RightCol = Loffset + (SCREEN_WIDTH - 1); - for (i = 0; i < sd.NumNoV; i++) { - if ((BottomLine >= sd.NoVScroll[i].ln - 1 && BottomLine <= sd.NoVScroll[i].ln + 1) && - ((sd.NoVScroll[i].c1 >= Loffset && sd.NoVScroll[i].c1 <= RightCol) || - (sd.NoVScroll[i].c2 >= Loffset && sd.NoVScroll[i].c2 <= RightCol) || - (sd.NoVScroll[i].c1 < Loffset && sd.NoVScroll[i].c2 > RightCol))) + for (i = 0; i < g_sd.NumNoV; i++) { + if ((BottomLine >= g_sd.NoVScroll[i].ln - 1 && BottomLine <= g_sd.NoVScroll[i].ln + 1) && + ((g_sd.NoVScroll[i].c1 >= Loffset && g_sd.NoVScroll[i].c1 <= RightCol) || + (g_sd.NoVScroll[i].c2 >= Loffset && g_sd.NoVScroll[i].c2 <= RightCol) || + (g_sd.NoVScroll[i].c1 < Loffset && g_sd.NoVScroll[i].c2 > RightCol))) return; } - if (DownScroll <= 0) { + if (g_DownScroll <= 0) { if (TinselV2) { - scrollPixelsY = sd.ySpeed; - DownScroll += sd.yDistance; + g_scrollPixelsY = g_sd.ySpeed; + g_DownScroll += g_sd.yDistance; } else { - scrollPixelsY = SCROLLPIXELS; - DownScroll = UDSCROLL; + g_scrollPixelsY = SCROLLPIXELS; + g_DownScroll = UDSCROLL; } } break; @@ -214,21 +214,21 @@ static void NeedScroll(int direction) { RightCol = Loffset + (SCREEN_WIDTH - 1); - for (i = 0; i < sd.NumNoV; i++) { - if (Toffset >= sd.NoVScroll[i].ln - 1 && Toffset <= sd.NoVScroll[i].ln + 1 && - ((sd.NoVScroll[i].c1 >= Loffset && sd.NoVScroll[i].c1 <= RightCol) || - (sd.NoVScroll[i].c2 >= Loffset && sd.NoVScroll[i].c2 <= RightCol) || - (sd.NoVScroll[i].c1 < Loffset && sd.NoVScroll[i].c2 > RightCol))) + for (i = 0; i < g_sd.NumNoV; i++) { + if (Toffset >= g_sd.NoVScroll[i].ln - 1 && Toffset <= g_sd.NoVScroll[i].ln + 1 && + ((g_sd.NoVScroll[i].c1 >= Loffset && g_sd.NoVScroll[i].c1 <= RightCol) || + (g_sd.NoVScroll[i].c2 >= Loffset && g_sd.NoVScroll[i].c2 <= RightCol) || + (g_sd.NoVScroll[i].c1 < Loffset && g_sd.NoVScroll[i].c2 > RightCol))) return; } - if (DownScroll >= 0) { + if (g_DownScroll >= 0) { if (TinselV2) { - scrollPixelsY = sd.ySpeed; - DownScroll -= sd.yDistance; + g_scrollPixelsY = g_sd.ySpeed; + g_DownScroll -= g_sd.yDistance; } else { - scrollPixelsY = SCROLLPIXELS; - DownScroll = -UDSCROLL; + g_scrollPixelsY = SCROLLPIXELS; + g_DownScroll = -UDSCROLL; } } break; @@ -249,39 +249,39 @@ static void ScrollImage() { /* * Keeping cursor on a tag? */ - if (ScrollCursor) { + if (g_ScrollCursor) { GetCursorXYNoWait(&curX, &curY, true); if (InPolygon(curX, curY, TAG) != NOPOLY || InPolygon(curX, curY, EXIT) != NOPOLY) { OldLoffset = Loffset; OldToffset = Toffset; } else - ScrollCursor = false; + g_ScrollCursor = false; } /* * Horizontal scrolling */ - if (LeftScroll > 0) { - LeftScroll -= scrollPixelsX; - if (LeftScroll < 0) { - Loffset += LeftScroll; - LeftScroll = 0; + if (g_LeftScroll > 0) { + g_LeftScroll -= g_scrollPixelsX; + if (g_LeftScroll < 0) { + Loffset += g_LeftScroll; + g_LeftScroll = 0; } - Loffset += scrollPixelsX; // Move right - if (Loffset > ImageW - SCREEN_WIDTH) - Loffset = ImageW - SCREEN_WIDTH;// Now at extreme right + Loffset += g_scrollPixelsX; // Move right + if (Loffset > g_ImageW - SCREEN_WIDTH) + Loffset = g_ImageW - SCREEN_WIDTH;// Now at extreme right /*** New feature to prop up rickety scroll boundaries ***/ if (TinselV2 && SysVar(SV_MaximumXoffset) && (Loffset > SysVar(SV_MaximumXoffset))) Loffset = SysVar(SV_MaximumXoffset); - } else if (LeftScroll < 0) { - LeftScroll += scrollPixelsX; - if (LeftScroll > 0) { - Loffset += LeftScroll; - LeftScroll = 0; + } else if (g_LeftScroll < 0) { + g_LeftScroll += g_scrollPixelsX; + if (g_LeftScroll > 0) { + Loffset += g_LeftScroll; + g_LeftScroll = 0; } - Loffset -= scrollPixelsX; // Move left + Loffset -= g_scrollPixelsX; // Move left if (Loffset < 0) Loffset = 0; // Now at extreme left @@ -293,28 +293,28 @@ static void ScrollImage() { /* * Vertical scrolling */ - if (DownScroll > 0) { - DownScroll -= scrollPixelsY; - if (DownScroll < 0) { - Toffset += DownScroll; - DownScroll = 0; + if (g_DownScroll > 0) { + g_DownScroll -= g_scrollPixelsY; + if (g_DownScroll < 0) { + Toffset += g_DownScroll; + g_DownScroll = 0; } - Toffset += scrollPixelsY; // Move down + Toffset += g_scrollPixelsY; // Move down - if (Toffset > ImageH - SCREEN_HEIGHT) - Toffset = ImageH - SCREEN_HEIGHT;// Now at extreme bottom + if (Toffset > g_ImageH - SCREEN_HEIGHT) + Toffset = g_ImageH - SCREEN_HEIGHT;// Now at extreme bottom /*** New feature to prop up rickety scroll boundaries ***/ if (TinselV2 && SysVar(SV_MaximumYoffset) && Toffset > SysVar(SV_MaximumYoffset)) Toffset = SysVar(SV_MaximumYoffset); - } else if (DownScroll < 0) { - DownScroll += scrollPixelsY; - if (DownScroll > 0) { - Toffset += DownScroll; - DownScroll = 0; + } else if (g_DownScroll < 0) { + g_DownScroll += g_scrollPixelsY; + if (g_DownScroll > 0) { + Toffset += g_DownScroll; + g_DownScroll = 0; } - Toffset -= scrollPixelsY; // Move up + Toffset -= g_scrollPixelsY; // Move up if (Toffset < 0) Toffset = 0; // Now at extreme top @@ -327,7 +327,7 @@ static void ScrollImage() { /* * Move cursor if keeping cursor on a tag. */ - if (ScrollCursor) + if (g_ScrollCursor) AdjustCursorXY(OldLoffset - Loffset, OldToffset - Toffset); PlayfieldSetPos(FIELD_WORLD, Loffset, Toffset); @@ -345,12 +345,12 @@ static void MonitorScroll() { /* * Only do it if the actor is there and is visible */ - if (!pScrollMover || MoverHidden(pScrollMover) || !MoverIs(pScrollMover)) + if (!g_pScrollMover || MoverHidden(g_pScrollMover) || !MoverIs(g_pScrollMover)) return; - GetActorPos(scrollActor, &newx, &newy); + GetActorPos(g_scrollActor, &newx, &newy); - if (oldx == newx && oldy == newy) + if (g_oldx == newx && g_oldy == newy) return; PlayfieldGetPos(FIELD_WORLD, &Loffset, &Toffset); @@ -358,49 +358,49 @@ static void MonitorScroll() { /* * Approaching right side or left side of the screen? */ - if (newx > Loffset+SCREEN_WIDTH - RLDISTANCE && Loffset < ImageW - SCREEN_WIDTH) { - if (newx > oldx) + if (newx > Loffset+SCREEN_WIDTH - RLDISTANCE && Loffset < g_ImageW - SCREEN_WIDTH) { + if (newx > g_oldx) NeedScroll(LEFT); } else if (newx < Loffset + RLDISTANCE && Loffset) { - if (newx < oldx) + if (newx < g_oldx) NeedScroll(RIGHT); } /* * Approaching bottom or top of the screen? */ - if (newy > Toffset+SCREEN_HEIGHT-DDISTANCE && Toffset < ImageH-SCREEN_HEIGHT) { - if (newy > oldy) + if (newy > Toffset+SCREEN_HEIGHT-DDISTANCE && Toffset < g_ImageH-SCREEN_HEIGHT) { + if (newy > g_oldy) NeedScroll(UP); - } else if (Toffset && newy < Toffset + UDISTANCE + GetActorBottom(scrollActor) - GetActorTop(scrollActor)) { - if (newy < oldy) + } else if (Toffset && newy < Toffset + UDISTANCE + GetActorBottom(g_scrollActor) - GetActorTop(g_scrollActor)) { + if (newy < g_oldy) NeedScroll(DOWN); } - oldx = newx; - oldy = newy; + g_oldx = newx; + g_oldy = newy; } static void RestoreScrollDefaults() { - sd.xTrigger = SysVar(SV_SCROLL_XTRIGGER); - sd.xDistance = SysVar(SV_SCROLL_XDISTANCE); - sd.xSpeed = SysVar(SV_SCROLL_XSPEED); - sd.yTriggerTop = SysVar(SV_SCROLL_YTRIGGERTOP); - sd.yTriggerBottom= SysVar(SV_SCROLL_YTRIGGERBOT); - sd.yDistance = SysVar(SV_SCROLL_YDISTANCE); - sd.ySpeed = SysVar(SV_SCROLL_YSPEED); + g_sd.xTrigger = SysVar(SV_SCROLL_XTRIGGER); + g_sd.xDistance = SysVar(SV_SCROLL_XDISTANCE); + g_sd.xSpeed = SysVar(SV_SCROLL_XSPEED); + g_sd.yTriggerTop = SysVar(SV_SCROLL_YTRIGGERTOP); + g_sd.yTriggerBottom= SysVar(SV_SCROLL_YTRIGGERBOT); + g_sd.yDistance = SysVar(SV_SCROLL_YDISTANCE); + g_sd.ySpeed = SysVar(SV_SCROLL_YSPEED); } /** * Does the obvious - called at the end of a scene. */ void DropScroll() { - sd.NumNoH = sd.NumNoV = 0; + g_sd.NumNoH = g_sd.NumNoV = 0; if (TinselV2) { - LeftScroll = DownScroll = 0; // No iterations outstanding - oldx = oldy = 0; - scrollPixelsX = sd.xSpeed; - scrollPixelsY = sd.ySpeed; + g_LeftScroll = g_DownScroll = 0; // No iterations outstanding + g_oldx = g_oldy = 0; + g_scrollPixelsX = g_sd.xSpeed; + g_scrollPixelsY = g_sd.ySpeed; RestoreScrollDefaults(); } } @@ -420,28 +420,28 @@ void ScrollProcess(CORO_PARAM, const void *) { while (!GetBgObject()) CORO_SLEEP(1); - ImageH = BgHeight(); // Dimensions - ImageW = BgWidth(); // of this scene. + g_ImageH = BgHeight(); // Dimensions + g_ImageW = BgWidth(); // of this scene. // Give up if there'll be no purpose in this process - if (ImageW == SCREEN_WIDTH && ImageH == SCREEN_HEIGHT) + if (g_ImageW == SCREEN_WIDTH && g_ImageH == SCREEN_HEIGHT) CORO_KILL_SELF(); if (!TinselV2) { - LeftScroll = DownScroll = 0; // No iterations outstanding - oldx = oldy = 0; - scrollPixelsX = scrollPixelsY = SCROLLPIXELS; + g_LeftScroll = g_DownScroll = 0; // No iterations outstanding + g_oldx = g_oldy = 0; + g_scrollPixelsX = g_scrollPixelsY = SCROLLPIXELS; } - if (!scrollActor) - scrollActor = GetLeadId(); + if (!g_scrollActor) + g_scrollActor = GetLeadId(); - pScrollMover = GetMover(scrollActor); + g_pScrollMover = GetMover(g_scrollActor); while (1) { MonitorScroll(); // Set scroll requirement - if (LeftScroll || DownScroll) // Scroll if required + if (g_LeftScroll || g_DownScroll) // Scroll if required ScrollImage(); CORO_SLEEP(1); // allow re-scheduling @@ -454,11 +454,11 @@ void ScrollProcess(CORO_PARAM, const void *) { * Change which actor the camera is following. */ void ScrollFocus(int ano) { - if (scrollActor != ano) { - oldx = oldy = 0; - scrollActor = ano; + if (g_scrollActor != ano) { + g_oldx = g_oldy = 0; + g_scrollActor = ano; - pScrollMover = ano ? GetMover(scrollActor) : NULL; + g_pScrollMover = ano ? GetMover(g_scrollActor) : NULL; } } @@ -466,7 +466,7 @@ void ScrollFocus(int ano) { * Returns the actor which the camera is following */ int GetScrollFocus() { - return scrollActor; + return g_scrollActor; } @@ -476,29 +476,29 @@ int GetScrollFocus() { void ScrollTo(int x, int y, int xIter, int yIter) { int Loffset, Toffset; // for background offsets - scrollPixelsX = xIter != 0 ? xIter : (TinselV2 ? sd.xSpeed : SCROLLPIXELS); - scrollPixelsY = yIter != 0 ? yIter : (TinselV2 ? sd.ySpeed : SCROLLPIXELS); + g_scrollPixelsX = xIter != 0 ? xIter : (TinselV2 ? g_sd.xSpeed : SCROLLPIXELS); + g_scrollPixelsY = yIter != 0 ? yIter : (TinselV2 ? g_sd.ySpeed : SCROLLPIXELS); PlayfieldGetPos(FIELD_WORLD, &Loffset, &Toffset); // get background offsets - LeftScroll = x - Loffset; - DownScroll = y - Toffset; + g_LeftScroll = x - Loffset; + g_DownScroll = y - Toffset; } /** * Kill of any current scroll. */ void KillScroll() { - LeftScroll = DownScroll = 0; + g_LeftScroll = g_DownScroll = 0; } void GetNoScrollData(SCROLLDATA *ssd) { - memcpy(ssd, &sd, sizeof(SCROLLDATA)); + memcpy(ssd, &g_sd, sizeof(SCROLLDATA)); } void RestoreNoScrollData(SCROLLDATA *ssd) { - memcpy(&sd, ssd, sizeof(SCROLLDATA)); + memcpy(&g_sd, ssd, sizeof(SCROLLDATA)); } /** @@ -512,24 +512,24 @@ void SetScrollParameters(int xTrigger, int xDistance, int xSpeed, int yTriggerTo RestoreScrollDefaults(); } else { if (xTrigger) - sd.xTrigger = xTrigger; + g_sd.xTrigger = xTrigger; if (xDistance) - sd.xDistance = xDistance; + g_sd.xDistance = xDistance; if (xSpeed) - sd.xSpeed = xSpeed; + g_sd.xSpeed = xSpeed; if (yTriggerTop) - sd.yTriggerTop = yTriggerTop; + g_sd.yTriggerTop = yTriggerTop; if (yTriggerBottom) - sd.yTriggerBottom = yTriggerBottom; + g_sd.yTriggerBottom = yTriggerBottom; if (yDistance) - sd.yDistance = yDistance; + g_sd.yDistance = yDistance; if (ySpeed) - sd.ySpeed = ySpeed; + g_sd.ySpeed = ySpeed; } } bool IsScrolling() { - return (LeftScroll || DownScroll); + return (g_LeftScroll || g_DownScroll); } } // End of namespace Tinsel diff --git a/engines/tinsel/scroll.h b/engines/tinsel/scroll.h index 62562b20b2..bcdc15cda6 100644 --- a/engines/tinsel/scroll.h +++ b/engines/tinsel/scroll.h @@ -28,9 +28,9 @@ namespace Tinsel { #define SCROLLPIXELS 8 // Number of pixels to scroll per iteration // Distance from edge that triggers a scroll -#define RLDISTANCE (TinselV2 ? sd.xTrigger : 50) -#define UDISTANCE (TinselV2 ? sd.yTriggerTop : 20) -#define DDISTANCE (TinselV2 ? sd.yTriggerBottom : 20) +#define RLDISTANCE (TinselV2 ? g_sd.xTrigger : 50) +#define UDISTANCE (TinselV2 ? g_sd.yTriggerTop : 20) +#define DDISTANCE (TinselV2 ? g_sd.yTriggerBottom : 20) // Number of iterations to make #define RLSCROLL 160 // 20*8 = 160 = half a screen diff --git a/engines/tinsel/sound.cpp b/engines/tinsel/sound.cpp index 130928d885..f575b03270 100644 --- a/engines/tinsel/sound.cpp +++ b/engines/tinsel/sound.cpp @@ -49,7 +49,7 @@ namespace Tinsel { -extern LANGUAGE sampleLanguage; +extern LANGUAGE g_sampleLanguage; //--------------------------- General data ---------------------------------- @@ -99,12 +99,12 @@ bool SoundManager::playSample(int id, Audio::Mixer::SoundType type, Audio::Sound // move to correct position in the sample file _sampleStream.seek(dwSampleIndex); if (_sampleStream.eos() || _sampleStream.err() || (uint32)_sampleStream.pos() != dwSampleIndex) - error(FILE_IS_CORRUPT, _vm->getSampleFile(sampleLanguage)); + error(FILE_IS_CORRUPT, _vm->getSampleFile(g_sampleLanguage)); // read the length of the sample uint32 sampleLen = _sampleStream.readUint32(); if (_sampleStream.eos() || _sampleStream.err()) - error(FILE_IS_CORRUPT, _vm->getSampleFile(sampleLanguage)); + error(FILE_IS_CORRUPT, _vm->getSampleFile(g_sampleLanguage)); if (TinselV1PSX) { // Read the stream and create a XA ADPCM audio stream @@ -124,7 +124,7 @@ bool SoundManager::playSample(int id, Audio::Mixer::SoundType type, Audio::Sound // read all of the sample if (_sampleStream.read(sampleBuf, sampleLen) != sampleLen) - error(FILE_IS_CORRUPT, _vm->getSampleFile(sampleLanguage)); + error(FILE_IS_CORRUPT, _vm->getSampleFile(g_sampleLanguage)); // FIXME: Should set this in a different place ;) _vm->_mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, _vm->_config->_soundVolume); @@ -254,12 +254,12 @@ bool SoundManager::playSample(int id, int sub, bool bLooped, int x, int y, int p // move to correct position in the sample file _sampleStream.seek(dwSampleIndex); if (_sampleStream.eos() || _sampleStream.err() || (uint32)_sampleStream.pos() != dwSampleIndex) - error(FILE_IS_CORRUPT, _vm->getSampleFile(sampleLanguage)); + error(FILE_IS_CORRUPT, _vm->getSampleFile(g_sampleLanguage)); // read the length of the sample uint32 sampleLen = _sampleStream.readUint32(); if (_sampleStream.eos() || _sampleStream.err()) - error(FILE_IS_CORRUPT, _vm->getSampleFile(sampleLanguage)); + error(FILE_IS_CORRUPT, _vm->getSampleFile(g_sampleLanguage)); if (sampleLen & 0x80000000) { // Has sub samples @@ -273,11 +273,11 @@ bool SoundManager::playSample(int id, int sub, bool bLooped, int x, int y, int p sampleLen = _sampleStream.readUint32(); _sampleStream.skip(sampleLen); if (_sampleStream.eos() || _sampleStream.err()) - error(FILE_IS_CORRUPT, _vm->getSampleFile(sampleLanguage)); + error(FILE_IS_CORRUPT, _vm->getSampleFile(g_sampleLanguage)); } sampleLen = _sampleStream.readUint32(); if (_sampleStream.eos() || _sampleStream.err()) - error(FILE_IS_CORRUPT, _vm->getSampleFile(sampleLanguage)); + error(FILE_IS_CORRUPT, _vm->getSampleFile(g_sampleLanguage)); } debugC(DEBUG_DETAILED, kTinselDebugSound, "Playing sound %d.%d, %d bytes at %d (pan %d)", id, sub, sampleLen, @@ -289,7 +289,7 @@ bool SoundManager::playSample(int id, int sub, bool bLooped, int x, int y, int p // read all of the sample if (_sampleStream.read(sampleBuf, sampleLen) != sampleLen) - error(FILE_IS_CORRUPT, _vm->getSampleFile(sampleLanguage)); + error(FILE_IS_CORRUPT, _vm->getSampleFile(g_sampleLanguage)); Common::MemoryReadStream *compressedStream = new Common::MemoryReadStream(sampleBuf, sampleLen, DisposeAfterUse::YES); @@ -481,7 +481,7 @@ void SoundManager::openSampleFiles() { return; // open sample index file in binary mode - if (f.open(_vm->getSampleIndex(sampleLanguage))) { + if (f.open(_vm->getSampleIndex(g_sampleLanguage))) { // get length of index file f.seek(0, SEEK_END); // move to end of file _sampleIndexLen = f.pos(); // get file pointer @@ -502,7 +502,7 @@ void SoundManager::openSampleFiles() { // load data if (f.read(_sampleIndex, _sampleIndexLen) != (uint32)_sampleIndexLen) // file must be corrupt if we get to here - error(FILE_IS_CORRUPT, _vm->getSampleFile(sampleLanguage)); + error(FILE_IS_CORRUPT, _vm->getSampleFile(g_sampleLanguage)); // close the file f.close(); @@ -542,28 +542,28 @@ void SoundManager::openSampleFiles() { _sampleIndex[0] = 0; } else { char buf[50]; - sprintf(buf, CANNOT_FIND_FILE, _vm->getSampleIndex(sampleLanguage)); + sprintf(buf, CANNOT_FIND_FILE, _vm->getSampleIndex(g_sampleLanguage)); GUI::MessageDialog dialog(buf, "OK"); dialog.runModal(); - error(CANNOT_FIND_FILE, _vm->getSampleIndex(sampleLanguage)); + error(CANNOT_FIND_FILE, _vm->getSampleIndex(g_sampleLanguage)); } // open sample file in binary mode - if (!_sampleStream.open(_vm->getSampleFile(sampleLanguage))) { + if (!_sampleStream.open(_vm->getSampleFile(g_sampleLanguage))) { char buf[50]; - sprintf(buf, CANNOT_FIND_FILE, _vm->getSampleFile(sampleLanguage)); + sprintf(buf, CANNOT_FIND_FILE, _vm->getSampleFile(g_sampleLanguage)); GUI::MessageDialog dialog(buf, "OK"); dialog.runModal(); - error(CANNOT_FIND_FILE, _vm->getSampleFile(sampleLanguage)); + error(CANNOT_FIND_FILE, _vm->getSampleFile(g_sampleLanguage)); } /* // gen length of the largest sample sampleBuffer.size = _sampleStream.readUint32LE(); if (_sampleStream.eos() || _sampleStream.err()) - error(FILE_IS_CORRUPT, _vm->getSampleFile(sampleLanguage)); + error(FILE_IS_CORRUPT, _vm->getSampleFile(g_sampleLanguage)); */ } diff --git a/engines/tinsel/strres.cpp b/engines/tinsel/strres.cpp index f3a7278993..5a29a4d2cd 100644 --- a/engines/tinsel/strres.cpp +++ b/engines/tinsel/strres.cpp @@ -38,11 +38,11 @@ namespace Tinsel { #ifdef DEBUG // Diagnostic number -int newestString; +int g_newestString; #endif // buffer for resource strings -static uint8 *textBuffer = 0; +static uint8 *g_textBuffer = 0; static struct { bool bPresent; @@ -50,7 +50,7 @@ static struct { SCNHANDLE hDescription; SCNHANDLE hFlagFilm; -} languages[NUM_LANGUAGES] = { +} g_languages[NUM_LANGUAGES] = { { false, "English", 0, 0 }, { false, "French", 0, 0 }, @@ -65,9 +65,9 @@ static struct { // Set if we're handling 2-byte characters. -bool bMultiByte = false; +bool g_bMultiByte = false; -LANGUAGE textLanguage, sampleLanguage = TXT_ENGLISH; +LANGUAGE g_textLanguage, g_sampleLanguage = TXT_ENGLISH; //----------------- LOCAL DEFINES ---------------------------- @@ -85,12 +85,12 @@ void ChangeLanguage(LANGUAGE newLang) { TinselFile f; uint32 textLen = 0; // length of buffer - textLanguage = newLang; - sampleLanguage = newLang; + g_textLanguage = newLang; + g_sampleLanguage = newLang; // free the previous buffer - free(textBuffer); - textBuffer = NULL; + free(g_textBuffer); + g_textBuffer = NULL; // Try and open the specified language file. If it fails, and the language // isn't English, try falling back on opening 'english.txt' - some foreign @@ -116,22 +116,22 @@ void ChangeLanguage(LANGUAGE newLang) { if (textLen == CHUNK_STRING || textLen == CHUNK_MBSTRING) { // the file is uncompressed - bMultiByte = (textLen == CHUNK_MBSTRING); + g_bMultiByte = (textLen == CHUNK_MBSTRING); // get length of uncompressed file textLen = f.size(); f.seek(0, SEEK_SET); // Set to beginning of file - if (textBuffer == NULL) { + if (g_textBuffer == NULL) { // allocate a text buffer for the strings - textBuffer = (uint8 *)malloc(textLen); + g_textBuffer = (uint8 *)malloc(textLen); // make sure memory allocated - assert(textBuffer); + assert(g_textBuffer); } // load data - if (f.read(textBuffer, textLen) != textLen) + if (f.read(g_textBuffer, textLen) != textLen) // file must be corrupt if we get to here error(FILE_IS_CORRUPT, _vm->getTextFile(newLang)); @@ -147,7 +147,7 @@ void ChangeLanguage(LANGUAGE newLang) { */ static byte *FindStringBase(int id) { // base of string resource table - byte *pText = textBuffer; + byte *pText = g_textBuffer; // For Tinsel 0, Ids are decremented by 1 if (TinselV0) @@ -353,8 +353,8 @@ int SubStringCount(int id) { void FreeTextBuffer() { - free(textBuffer); - textBuffer = NULL; + free(g_textBuffer); + g_textBuffer = NULL; } /** @@ -364,29 +364,29 @@ void FreeTextBuffer() { void LanguageFacts(int language, SCNHANDLE hDescription, SCNHANDLE hFlagFilm) { assert(language >= 0 && language < NUM_LANGUAGES); - languages[language].hDescription = hDescription; - languages[language].hFlagFilm = hFlagFilm; + g_languages[language].hDescription = hDescription; + g_languages[language].hFlagFilm = hFlagFilm; } /** * Gets the current subtitles language */ LANGUAGE TextLanguage() { - return textLanguage; + return g_textLanguage; } /** * Gets the current voice language */ LANGUAGE SampleLanguage() { - return sampleLanguage; + return g_sampleLanguage; } int NumberOfLanguages() { int i, count; for (i = 0, count = 0; i < NUM_LANGUAGES; i++) { - if (languages[i].bPresent) + if (g_languages[i].bPresent) count++; } return count; @@ -396,12 +396,12 @@ LANGUAGE NextLanguage(LANGUAGE thisOne) { int i; for (i = thisOne+1; i < NUM_LANGUAGES; i++) { - if (languages[i].bPresent) + if (g_languages[i].bPresent) return (LANGUAGE)i; } for (i = 0; i < thisOne; i++) { - if (languages[i].bPresent) + if (g_languages[i].bPresent) return (LANGUAGE)i; } @@ -413,12 +413,12 @@ LANGUAGE PrevLanguage(LANGUAGE thisOne) { int i; for (i = thisOne-1; i >= 0; i--) { - if (languages[i].bPresent) + if (g_languages[i].bPresent) return (LANGUAGE)i; } for (i = NUM_LANGUAGES-1; i > thisOne; i--) { - if (languages[i].bPresent) + if (g_languages[i].bPresent) return (LANGUAGE)i; } @@ -427,11 +427,11 @@ LANGUAGE PrevLanguage(LANGUAGE thisOne) { } SCNHANDLE LanguageDesc(LANGUAGE thisOne) { - return languages[thisOne].hDescription; + return g_languages[thisOne].hDescription; } SCNHANDLE LanguageFlag(LANGUAGE thisOne) { - return languages[thisOne].hFlagFilm; + return g_languages[thisOne].hFlagFilm; } } // End of namespace Tinsel diff --git a/engines/tinsel/strres.h b/engines/tinsel/strres.h index f6e86951b6..772896c81f 100644 --- a/engines/tinsel/strres.h +++ b/engines/tinsel/strres.h @@ -35,7 +35,7 @@ namespace Tinsel { #define MAX_STRRES_SIZE 300000 // maximum size of string resource file // Set if we're handling 2-byte characters. -extern bool bMultiByte; +extern bool g_bMultiByte; /*----------------------------------------------------------------------*\ |* Function Prototypes *| diff --git a/engines/tinsel/sysvar.cpp b/engines/tinsel/sysvar.cpp index 88053f15c6..6ef4f165ab 100644 --- a/engines/tinsel/sysvar.cpp +++ b/engines/tinsel/sysvar.cpp @@ -43,7 +43,7 @@ extern int NewestSavedGame(); // FIXME: Avoid non-const global vars -static int systemVars[SV_TOPVALID] = { +static int g_systemVars[SV_TOPVALID] = { INV_1, // Default inventory @@ -105,7 +105,7 @@ static int systemVars[SV_TOPVALID] = { 0 // ISV_GHOST_COLOR }; -static SCNHANDLE systemStrings[SS_MAX_VALID]; // FIXME: Avoid non-const global vars +static SCNHANDLE g_systemStrings[SS_MAX_VALID]; // FIXME: Avoid non-const global vars //static bool bFlagNoBlocking = false; @@ -116,8 +116,8 @@ static SCNHANDLE systemStrings[SS_MAX_VALID]; // FIXME: Avoid non-const global v */ void InitSysVars() { - systemVars[SV_SCROLL_XDISTANCE] = SCREEN_WIDTH / 2; - systemVars[SV_SCROLL_YDISTANCE] = SCREEN_BOX_HEIGHT1 / 2; + g_systemVars[SV_SCROLL_XDISTANCE] = SCREEN_WIDTH / 2; + g_systemVars[SV_SCROLL_YDISTANCE] = SCREEN_BOX_HEIGHT1 / 2; } /** @@ -138,7 +138,7 @@ void SetSysVar(int varId, int newValue) { error("SetSystemVar(): read only identifier"); default: - systemVars[varId] = newValue; + g_systemVars[varId] = newValue; } } @@ -167,28 +167,28 @@ int SysVar(int varId) { //return bDebuggingAllowed; default: - return systemVars[varId]; + return g_systemVars[varId]; } } void SaveSysVars(int *pSv) { - memcpy(pSv, systemVars, sizeof(systemVars)); + memcpy(pSv, g_systemVars, sizeof(g_systemVars)); } void RestoreSysVars(int *pSv) { - memcpy(systemVars, pSv, sizeof(systemVars)); + memcpy(g_systemVars, pSv, sizeof(g_systemVars)); } void SetSysString(int number, SCNHANDLE hString) { assert(number >= 0 && number < SS_MAX_VALID); - systemStrings[number] = hString; + g_systemStrings[number] = hString; } SCNHANDLE SysString(int number) { assert(number >= 0 && number < SS_MAX_VALID); - return systemStrings[number]; + return g_systemStrings[number]; } /** diff --git a/engines/tinsel/text.cpp b/engines/tinsel/text.cpp index ecb1e153f3..5eb092d00d 100644 --- a/engines/tinsel/text.cpp +++ b/engines/tinsel/text.cpp @@ -25,7 +25,7 @@ #include "tinsel/graphics.h" // object plotting #include "tinsel/handle.h" #include "tinsel/sched.h" // process scheduler defines -#include "tinsel/strres.h" // bMultiByte +#include "tinsel/strres.h" // g_bMultiByte #include "tinsel/text.h" // text defines namespace Tinsel { @@ -42,7 +42,7 @@ int StringLengthPix(char *szStr, const FONT *pFont) { // while not end of string or end of line for (strLen = 0; (c = *szStr) != EOS_CHAR && c != LF_CHAR; szStr++) { - if (bMultiByte) { + if (g_bMultiByte) { if (c & 0x80) c = ((c & ~0x80) << 8) + *++szStr; } @@ -136,7 +136,7 @@ OBJECT *ObjectTextOut(OBJECT **pList, char *szStr, int color, // repeat until end of string or end of line while ((c = *szStr) != EOS_CHAR && c != LF_CHAR) { - if (bMultiByte) { + if (g_bMultiByte) { if (c & 0x80) c = ((c & ~0x80) << 8) + *++szStr; } @@ -265,7 +265,7 @@ bool IsCharImage(SCNHANDLE hFont, char c) { // Inventory save game name editor needs to be more clever for // multi-byte characters. This bodge will stop it erring. - if (bMultiByte && (c2 & 0x80)) + if (g_bMultiByte && (c2 & 0x80)) return false; // get font pointer diff --git a/engines/tinsel/timers.cpp b/engines/tinsel/timers.cpp index 1c3ff9b260..d3a7446565 100644 --- a/engines/tinsel/timers.cpp +++ b/engines/tinsel/timers.cpp @@ -49,7 +49,7 @@ struct TIMER { //----------------- LOCAL GLOBAL DATA -------------------- -static TIMER timers[MAX_TIMERS]; // FIXME: Avoid non-const global vars +static TIMER g_timers[MAX_TIMERS]; // FIXME: Avoid non-const global vars //-------------------------------------------------------- @@ -72,7 +72,7 @@ uint32 DwGetCurrentTime() { */ void RebootTimers() { - memset(timers, 0, sizeof(timers)); + memset(g_timers, 0, sizeof(g_timers)); } /** @@ -80,11 +80,11 @@ void RebootTimers() { */ void syncTimerInfo(Common::Serializer &s) { for (int i = 0; i < MAX_TIMERS; i++) { - s.syncAsSint32LE(timers[i].tno); - s.syncAsSint32LE(timers[i].ticks); - s.syncAsSint32LE(timers[i].secs); - s.syncAsSint32LE(timers[i].delta); - s.syncAsSint32LE(timers[i].frame); + s.syncAsSint32LE(g_timers[i].tno); + s.syncAsSint32LE(g_timers[i].ticks); + s.syncAsSint32LE(g_timers[i].secs); + s.syncAsSint32LE(g_timers[i].delta); + s.syncAsSint32LE(g_timers[i].frame); } } @@ -95,8 +95,8 @@ void syncTimerInfo(Common::Serializer &s) { */ static TIMER *findTimer(int num) { for (int i = 0; i < MAX_TIMERS; i++) { - if (timers[i].tno == num) - return &timers[i]; + if (g_timers[i].tno == num) + return &g_timers[i]; } return NULL; } @@ -109,9 +109,9 @@ static TIMER *allocateTimer(int num) { assert(!findTimer(num)); // Allocating already existant timer for (int i = 0; i < MAX_TIMERS; i++) { - if (!timers[i].tno) { - timers[i].tno = num; - return &timers[i]; + if (!g_timers[i].tno) { + g_timers[i].tno = num; + return &g_timers[i]; } } @@ -123,23 +123,23 @@ static TIMER *allocateTimer(int num) { */ void FettleTimers() { for (int i = 0; i < MAX_TIMERS; i++) { - if (!timers[i].tno) + if (!g_timers[i].tno) continue; - timers[i].ticks += timers[i].delta; // Update tick value + g_timers[i].ticks += g_timers[i].delta; // Update tick value - if (timers[i].frame) { - if (timers[i].ticks < 0) - timers[i].ticks = 0; // Have reached zero + if (g_timers[i].frame) { + if (g_timers[i].ticks < 0) + g_timers[i].ticks = 0; // Have reached zero } else { - if (timers[i].ticks < 0) { - timers[i].ticks = ONE_SECOND; - timers[i].secs--; - if (timers[i].secs < 0) - timers[i].secs = 0; // Have reached zero - } else if (timers[i].ticks == ONE_SECOND) { - timers[i].ticks = 0; - timers[i].secs++; // Another second has passed + if (g_timers[i].ticks < 0) { + g_timers[i].ticks = ONE_SECOND; + g_timers[i].secs--; + if (g_timers[i].secs < 0) + g_timers[i].secs = 0; // Have reached zero + } else if (g_timers[i].ticks == ONE_SECOND) { + g_timers[i].ticks = 0; + g_timers[i].secs++; // Another second has passed } } } diff --git a/engines/tinsel/tinlib.cpp b/engines/tinsel/tinlib.cpp index 7fbec69cbf..c652abca25 100644 --- a/engines/tinsel/tinlib.cpp +++ b/engines/tinsel/tinlib.cpp @@ -74,11 +74,11 @@ namespace Tinsel { //----------------- EXTERNAL GLOBAL DATA -------------------- // In DOS_DW.C -extern bool bRestart; // restart flag - set to restart the game -extern bool bHasRestarted; // Set after a restart +extern bool g_bRestart; // restart flag - set to restart the game +extern bool g_bHasRestarted; // Set after a restart // In PCODE.CPP -extern bool bNoPause; +extern bool g_bNoPause; // In DOS_MAIN.C // TODO/FIXME: From dos_main.c: "Only used on PSX so far" @@ -100,7 +100,7 @@ extern int NewestSavedGame(); // in SCENE.CPP extern void setshowpos(); -extern int sceneCtr; +extern int g_sceneCtr; // in TINSEL.CPP extern void SetCdChangeScene(SCNHANDLE hScene); @@ -122,10 +122,10 @@ SCNHANDLE GetSceneHandle(); // FIXME: Avoid non-const global vars -bool bEnableMenu; +bool g_bEnableMenu; -static bool bInstantScroll = false; -static bool bEscapedCdPlay = false; +static bool g_bInstantScroll = false; +static bool g_bEscapedCdPlay = false; //----------------- LOCAL DEFINES -------------------- @@ -298,13 +298,13 @@ static const MASTER_LIB_CODES DW2_CODES[] = { // as it was at control(off). // They are global so that MoveCursor(..) has a net effect if it // precedes control(on). -static int controlX = 0, controlY = 0; +static int g_controlX = 0, g_controlY = 0; -static int offtype = 0; // used by Control() -static uint32 lastValue = 0; // used by RandomFn() -static int scrollNumber = 0; // used by scroll() +static int g_offtype = 0; // used by Control() +static uint32 g_lastValue = 0; // used by RandomFn() +static int g_scrollNumber = 0; // used by scroll() -static bool bNotPointedRunning = false; // Used in Printobj and PrintObjPointed +static bool g_bNotPointedRunning = false; // Used in Printobj and PrintObjPointed //----------------- FORWARD REFERENCES -------------------- @@ -404,7 +404,7 @@ static void ScrollMonitorProcess(CORO_PARAM, const void *param) { CORO_SLEEP(1); // give up if have been superseded - if (psm->thisScroll != scrollNumber) + if (psm->thisScroll != g_scrollNumber) break; // If ESCAPE is pressed... @@ -706,7 +706,7 @@ static void CDload(SCNHANDLE start, SCNHANDLE next, int myEscape) { if (TinselV2) { if (myEscape && myEscape != GetEscEvents()) { - bEscapedCdPlay = true; + g_bEscapedCdPlay = true; return; } @@ -754,14 +754,14 @@ void Control(int param) { } // Tinsel 1 handling code - bEnableMenu = false; + g_bEnableMenu = false; switch (param) { case CONTROL_STARTOFF: GetControlToken(); // Take control DisableTags(); // Switch off tags DwHideCursor(); // Blank out cursor - offtype = param; + g_offtype = param; break; case CONTROL_OFF: @@ -771,17 +771,17 @@ void Control(int param) { GetControlToken(); // Take control DisableTags(); // Switch off tags - GetCursorXYNoWait(&controlX, &controlY, true); // Store cursor position + GetCursorXYNoWait(&g_controlX, &g_controlY, true); // Store cursor position // There may be a button timing out GetToken(TOKEN_LEFT_BUT); FreeToken(TOKEN_LEFT_BUT); } - if (offtype == CONTROL_STARTOFF) - GetCursorXYNoWait(&controlX, &controlY, true); // Store cursor position + if (g_offtype == CONTROL_STARTOFF) + GetCursorXYNoWait(&g_controlX, &g_controlY, true); // Store cursor position - offtype = param; + g_offtype = param; if (param == CONTROL_OFF) DwHideCursor(); // Blank out cursor @@ -794,8 +794,8 @@ void Control(int param) { break; case CONTROL_ON: - if (offtype != CONTROL_OFFV2 && offtype != CONTROL_STARTOFF) - SetCursorXY(controlX, controlY);// ... where it was + if (g_offtype != CONTROL_OFFV2 && g_offtype != CONTROL_STARTOFF) + SetCursorXY(g_controlX, g_controlY);// ... where it was FreeControlToken(); // Release control @@ -1092,7 +1092,7 @@ static void DropEverything() { * EnableMenu */ static void EnableMenu() { - bEnableMenu = true; + g_bEnableMenu = true; } /** @@ -1212,7 +1212,7 @@ static void HailScene(SCNHANDLE scene) { * Returns TRUE if the game has been restarted, FALSE if not. */ static bool HasRestarted() { - return bHasRestarted; + return g_bHasRestarted; } /** @@ -1308,7 +1308,7 @@ static int IdleTime() { * Set flag if InstantScroll(on), reset if InstantScroll(off) */ void InstantScroll(int onoff) { - bInstantScroll = (onoff != 0); + g_bInstantScroll = (onoff != 0); } /** @@ -1419,8 +1419,8 @@ static int LToffset(int lort) { static void MoveCursor(int x, int y) { SetCursorXY(x, y); - controlX = x; // Save these values so that - controlY = y; // control(on) doesn't undo this + g_controlX = x; // Save these values so that + g_controlY = y; // control(on) doesn't undo this } /** @@ -1465,7 +1465,7 @@ void NewScene(CORO_PARAM, SCNHANDLE scene, int entrance, int transition) { GetControl(CONTROL_STARTOFF); if (TinselV1) - ++sceneCtr; + ++g_sceneCtr; // Prevent code subsequent to this call running before scene changes if (g_scheduler->getCurrentPID() != PID_MASTER_SCR) @@ -1541,8 +1541,8 @@ static void Play(CORO_PARAM, SCNHANDLE hFilm, int x, int y, int compit, int acto // Don't do CDPlay() for now if already escaped - if (bEscapedCdPlay) { - bEscapedCdPlay = false; + if (g_bEscapedCdPlay) { + g_bEscapedCdPlay = false; return; } @@ -1583,8 +1583,8 @@ static void Play(CORO_PARAM, SCNHANDLE hFilm, int x, int y, bool bComplete, int assert(hFilm != 0); // Don't do CdPlay() for now if already escaped - if (bEscapedCdPlay) { - bEscapedCdPlay = false; + if (g_bEscapedCdPlay) { + g_bEscapedCdPlay = false; return; } @@ -2068,11 +2068,11 @@ static void PrintObj(CORO_PARAM, const SCNHANDLE hText, const INV_OBJECT *pinvo, _ctx->myEscape = myEscape; if (hText == (SCNHANDLE)-1) { // 'OFF' - bNotPointedRunning = true; + g_bNotPointedRunning = true; return; } if (hText == (SCNHANDLE)-2) { // 'ON' - bNotPointedRunning = false; + g_bNotPointedRunning = false; return; } @@ -2092,10 +2092,10 @@ static void PrintObj(CORO_PARAM, const SCNHANDLE hText, const INV_OBJECT *pinvo, * POINT/other event PrintObj() arbitration... */ if (event != POINTED) { - bNotPointedRunning = true; // Get POINTED text to die + g_bNotPointedRunning = true; // Get POINTED text to die CORO_SLEEP(1); // Give it chance to } else if (!TinselV2) - bNotPointedRunning = false; // There may have been an OFF without an ON + g_bNotPointedRunning = false; // There may have been an OFF without an ON // Make multi-ones escape if (TinselV2 && (SubStringCount(hText) > 1) && !_ctx->myEscape) @@ -2163,12 +2163,12 @@ static void PrintObj(CORO_PARAM, const SCNHANDLE hText, const INV_OBJECT *pinvo, break; // Give way to non-POINTED-generated text - if (bNotPointedRunning) { + if (g_bNotPointedRunning) { // Delete the text, and wait for the all-clear MultiDeleteObject(GetPlayfieldList(FIELD_STATUS), _ctx->pText); _ctx->pText = NULL; - while (bNotPointedRunning) + while (g_bNotPointedRunning) CORO_SLEEP(1); GetCursorXY(&x, &y, false); @@ -2262,7 +2262,7 @@ static void PrintObj(CORO_PARAM, const SCNHANDLE hText, const INV_OBJECT *pinvo, // Let POINTED text back in if this is the last if (event != POINTED) - bNotPointedRunning = false; + g_bNotPointedRunning = false; CORO_END_CODE; } @@ -2281,11 +2281,11 @@ static void PrintObjPointed(CORO_PARAM, const SCNHANDLE text, const INV_OBJECT * break; // Give way to non-POINTED-generated text - if (bNotPointedRunning) { + if (g_bNotPointedRunning) { // Delete the text, and wait for the all-clear MultiDeleteObject(GetPlayfieldList(FIELD_STATUS), pText); pText = NULL; - while (bNotPointedRunning) + while (g_bNotPointedRunning) CORO_SLEEP(1); GetCursorXY(&x, &y, false); @@ -2372,7 +2372,7 @@ static void PrintObjNonPointed(CORO_PARAM, const SCNHANDLE text, const OBJECT *p } } while (1); - bNotPointedRunning = false; // Let POINTED text back in + g_bNotPointedRunning = false; // Let POINTED text back in if (_ctx->took_control) Control(CONTROL_ON); // Free control if we took it @@ -2425,9 +2425,9 @@ static int RandomFn(int n1, int n2, int norpt) { do { value = n1 + _vm->getRandomNumber(n2 - n1); - } while ((lastValue == value) && (norpt == RAND_NORPT) && (++i <= 10)); + } while ((g_lastValue == value) && (norpt == RAND_NORPT) && (++i <= 10)); - lastValue = value; + g_lastValue = value; return value; } @@ -2446,8 +2446,8 @@ void FnRestartGame() { StopMidi(); StopSample(); - bRestart = true; - sceneCtr = 0; + g_bRestart = true; + g_sceneCtr = 0; } /** @@ -2554,15 +2554,15 @@ static void Scroll(CORO_PARAM, EXTREME extreme, int xp, int yp, int xIter, int y CORO_BEGIN_CODE(_ctx); - ++scrollNumber; + ++g_scrollNumber; _ctx->x = xp; _ctx->y = yp; - if ((TinselV2 && bInstantScroll) || (escOn && myEscape != GetEscEvents())) { + if ((TinselV2 && g_bInstantScroll) || (escOn && myEscape != GetEscEvents())) { // Instant completion! Offset(extreme, _ctx->x, _ctx->y); } else { - _ctx->thisScroll = scrollNumber; + _ctx->thisScroll = g_scrollNumber; if (TinselV2) DecodeExtreme(extreme, &_ctx->x, &_ctx->y); @@ -2581,7 +2581,7 @@ static void Scroll(CORO_PARAM, EXTREME extreme, int xp, int yp, int xIter, int y } // give up if have been superseded - if (_ctx->thisScroll != scrollNumber) + if (_ctx->thisScroll != g_scrollNumber) CORO_KILL_SELF(); PlayfieldGetPos(FIELD_WORLD, &Loffset, &Toffset); @@ -2592,7 +2592,7 @@ static void Scroll(CORO_PARAM, EXTREME extreme, int xp, int yp, int xIter, int y // Scroll is escapable even though we're not waiting for it sm.x = _ctx->x; sm.y = _ctx->y; - sm.thisScroll = scrollNumber; + sm.thisScroll = g_scrollNumber; sm.myEscape = myEscape; g_scheduler->createProcess(PID_TCODE, ScrollMonitorProcess, &sm, sizeof(sm)); } @@ -3410,8 +3410,8 @@ static void TalkOrSay(CORO_PARAM, SPEECH_TYPE speechType, SCNHANDLE hText, int x if (TinselV2 && _ctx->bSample) { // Kick off the sample now (perhaps with a delay) - if (bNoPause) - bNoPause = false; + if (g_bNoPause) + g_bNoPause = false; else if (!IsDemo) CORO_SLEEP(SysVar(SV_SPEECHDELAY)); @@ -4899,7 +4899,7 @@ int CallLibraryRoutine(CORO_PARAM, int operand, int32 *pp, const INT_CONTEXT *pi case NOPAUSE: // DW2 only - bNoPause = true; + g_bNoPause = true; return 0; case NOSCROLL: diff --git a/engines/tinsel/tinsel.cpp b/engines/tinsel/tinsel.cpp index cd0f9b9fa4..65900cc7f3 100644 --- a/engines/tinsel/tinsel.cpp +++ b/engines/tinsel/tinsel.cpp @@ -66,7 +66,7 @@ namespace Tinsel { // In BG.CPP extern void SetDoFadeIn(bool tf); extern void DropBackground(); -extern const BACKGND *pCurBgnd; +extern const BACKGND *g_pCurBgnd; // In CURSOR.CPP extern void CursorProcess(CORO_PARAM, const void *); @@ -85,16 +85,16 @@ void SetNewScene(SCNHANDLE scene, int entrance, int transition); // FIXME: Avoid non-const global vars -bool bRestart = false; -bool bHasRestarted = false; -bool loadingFromGMM = false; +bool g_bRestart = false; +bool g_bHasRestarted = false; +bool g_loadingFromGMM = false; -static bool bCuttingScene = false; +static bool g_bCuttingScene = false; -static bool bChangingForRestore = false; +static bool g_bChangingForRestore = false; #ifdef DEBUG -bool bFast; // set to make it go ludicrously fast +bool g_bFast; // set to make it go ludicrously fast #endif //----------------- LOCAL GLOBAL DATA -------------------- @@ -105,14 +105,14 @@ struct Scene { int trans; // Transition - not yet used }; -static Scene NextScene = { 0, 0, 0 }; -static Scene HookScene = { 0, 0, 0 }; -static Scene DelayedScene = { 0, 0, 0 }; +static Scene g_NextScene = { 0, 0, 0 }; +static Scene g_HookScene = { 0, 0, 0 }; +static Scene g_DelayedScene = { 0, 0, 0 }; -static PROCESS *pMouseProcess = 0; -static PROCESS *pKeyboardProcess = 0; +static PROCESS *g_pMouseProcess = 0; +static PROCESS *g_pKeyboardProcess = 0; -static SCNHANDLE hCdChangeScene; +static SCNHANDLE g_hCdChangeScene; //----------------- LOCAL PROCEDURES -------------------- @@ -457,49 +457,49 @@ static void MasterScriptProcess(CORO_PARAM, const void *) { * Store the facts pertaining to a scene change. */ void SetNewScene(SCNHANDLE scene, int entrance, int transition) { - if (!bCuttingScene && TinselV2) + if (!g_bCuttingScene && TinselV2) WrapScene(); // If we're loading from the GMM, load the scene as a delayed one - if (loadingFromGMM) { - DelayedScene.scene = scene; - DelayedScene.entry = entrance; - DelayedScene.trans = transition; - loadingFromGMM = false; + if (g_loadingFromGMM) { + g_DelayedScene.scene = scene; + g_DelayedScene.entry = entrance; + g_DelayedScene.trans = transition; + g_loadingFromGMM = false; return; } // If CD change will be required, stick in the scene change scene if (CdNumber(scene) != GetCurrentCD()) { // This scene gets delayed - DelayedScene.scene = scene; - DelayedScene.entry = entrance; - DelayedScene.trans = transition; + g_DelayedScene.scene = scene; + g_DelayedScene.entry = entrance; + g_DelayedScene.trans = transition; - NextScene.scene = hCdChangeScene; - NextScene.entry = CdNumber(scene) - '0'; - NextScene.trans = TRANS_FADE; + g_NextScene.scene = g_hCdChangeScene; + g_NextScene.entry = CdNumber(scene) - '0'; + g_NextScene.trans = TRANS_FADE; return; } - if (HookScene.scene == 0 || bCuttingScene) { + if (g_HookScene.scene == 0 || g_bCuttingScene) { // This scene comes next - NextScene.scene = scene; - NextScene.entry = entrance; - NextScene.trans = transition; + g_NextScene.scene = scene; + g_NextScene.entry = entrance; + g_NextScene.trans = transition; } else { // This scene gets delayed - DelayedScene.scene = scene; - DelayedScene.entry = entrance; - DelayedScene.trans = transition; + g_DelayedScene.scene = scene; + g_DelayedScene.entry = entrance; + g_DelayedScene.trans = transition; // The hooked scene comes next - NextScene.scene = HookScene.scene; - NextScene.entry = HookScene.entry; - NextScene.trans = HookScene.trans; + g_NextScene.scene = g_HookScene.scene; + g_NextScene.entry = g_HookScene.entry; + g_NextScene.trans = g_HookScene.trans; - HookScene.scene = 0; + g_HookScene.scene = 0; } // Workaround for "Missing Red Dragon in square" bug in Discworld 1 PSX, act IV. @@ -509,10 +509,10 @@ void SetNewScene(SCNHANDLE scene, int entrance, int transition) { // I'm forcing the load of the right scene by checking that the player has (or has not) the // right items: player must have Mambo the swamp dragon, and mustn't have fireworks (used on // the swamp dragon previously to "load it up"). - if (TinselV1PSX && NextScene.scene == 0x1800000 && NextScene.entry == 2) { + if (TinselV1PSX && g_NextScene.scene == 0x1800000 && g_NextScene.entry == 2) { if ((IsInInventory(261, INV_1) || IsInInventory(261, INV_2)) && (!IsInInventory(232, INV_1) && !IsInInventory(232, INV_2))) - NextScene.entry = 1; + g_NextScene.entry = 1; } } @@ -520,72 +520,72 @@ void SetNewScene(SCNHANDLE scene, int entrance, int transition) { * Store a scene as hooked */ void SetHookScene(SCNHANDLE scene, int entrance, int transition) { - assert(HookScene.scene == 0); // scene already hooked + assert(g_HookScene.scene == 0); // scene already hooked - HookScene.scene = scene; - HookScene.entry = entrance; - HookScene.trans = transition; + g_HookScene.scene = scene; + g_HookScene.entry = entrance; + g_HookScene.trans = transition; } /** * Hooked scene is over, trigger a change to the delayed scene */ void UnHookScene() { - assert(DelayedScene.scene != 0); // no scene delayed + assert(g_DelayedScene.scene != 0); // no scene delayed // The delayed scene can go now - NextScene.scene = DelayedScene.scene; - NextScene.entry = DelayedScene.entry; - NextScene.trans = DelayedScene.trans; + g_NextScene.scene = g_DelayedScene.scene; + g_NextScene.entry = g_DelayedScene.entry; + g_NextScene.trans = g_DelayedScene.trans; - DelayedScene.scene = 0; + g_DelayedScene.scene = 0; } void SuspendHook() { - bCuttingScene = true; + g_bCuttingScene = true; } void CdHasChanged() { - if (bChangingForRestore) { - bChangingForRestore = false; + if (g_bChangingForRestore) { + g_bChangingForRestore = false; RestoreGame(-2); } else { - assert(DelayedScene.scene != 0); + assert(g_DelayedScene.scene != 0); WrapScene(); // The delayed scene can go now - NextScene.scene = DelayedScene.scene; - NextScene.entry = DelayedScene.entry; - NextScene.trans = DelayedScene.trans; + g_NextScene.scene = g_DelayedScene.scene; + g_NextScene.entry = g_DelayedScene.entry; + g_NextScene.trans = g_DelayedScene.trans; - DelayedScene.scene = 0; + g_DelayedScene.scene = 0; } } void SetCdChangeScene(SCNHANDLE hScene) { - hCdChangeScene = hScene; + g_hCdChangeScene = hScene; } void CDChangeForRestore(int cdNumber) { - NextScene.scene = hCdChangeScene; - NextScene.entry = cdNumber; - NextScene.trans = TRANS_FADE; - bChangingForRestore = true; + g_NextScene.scene = g_hCdChangeScene; + g_NextScene.entry = cdNumber; + g_NextScene.trans = TRANS_FADE; + g_bChangingForRestore = true; } void UnSuspendHook() { - bCuttingScene = false; + g_bCuttingScene = false; } void syncSCdata(Common::Serializer &s) { - s.syncAsUint32LE(HookScene.scene); - s.syncAsSint32LE(HookScene.entry); - s.syncAsSint32LE(HookScene.trans); + s.syncAsUint32LE(g_HookScene.scene); + s.syncAsSint32LE(g_HookScene.entry); + s.syncAsSint32LE(g_HookScene.trans); - s.syncAsUint32LE(DelayedScene.scene); - s.syncAsSint32LE(DelayedScene.entry); - s.syncAsSint32LE(DelayedScene.trans); + s.syncAsUint32LE(g_DelayedScene.scene); + s.syncAsSint32LE(g_DelayedScene.entry); + s.syncAsSint32LE(g_DelayedScene.trans); } @@ -640,16 +640,16 @@ bool ChangeScene(bool bReset) { // Prevent attempt to fade-out when restarting game if (bReset) { CountOut = 1; // immediate start of first scene again - DelayedScene.scene = HookScene.scene = 0; + g_DelayedScene.scene = g_HookScene.scene = 0; return false; } if (IsRestoringScene()) return true; - if (NextScene.scene != 0) { + if (g_NextScene.scene != 0) { if (!CountOut) { - switch (NextScene.trans) { + switch (g_NextScene.trans) { case TRANS_CUT: CountOut = 1; break; @@ -667,10 +667,10 @@ bool ChangeScene(bool bReset) { if (!TinselV2) ClearScreen(); - StartNewScene(NextScene.scene, NextScene.entry); - NextScene.scene = 0; + StartNewScene(g_NextScene.scene, g_NextScene.entry); + g_NextScene.scene = 0; - switch (NextScene.trans) { + switch (g_NextScene.trans) { case TRANS_CUT: SetDoFadeIn(false); break; @@ -691,7 +691,7 @@ bool ChangeScene(bool bReset) { * CuttingScene */ void CuttingScene(bool bCutting) { - bCuttingScene = bCutting; + g_bCuttingScene = bCutting; if (!bCutting) WrapScene(); @@ -927,7 +927,7 @@ Common::Error TinselEngine::run() { RebootTimers(); RebootScalingReels(); - DelayedScene.scene = HookScene.scene = 0; + g_DelayedScene.scene = g_HookScene.scene = 0; #endif // Load in text strings @@ -957,7 +957,7 @@ Common::Error TinselEngine::run() { if (ConfMan.hasKey("save_slot")) { if (loadGameState(ConfMan.getInt("save_slot")).getCode() == Common::kNoError) - loadingFromGMM = true; + g_loadingFromGMM = true; } // Foreground loop @@ -973,10 +973,10 @@ Common::Error TinselEngine::run() { NextGameCycle(); } - if (bRestart) { + if (g_bRestart) { RestartGame(); - bRestart = false; - bHasRestarted = true; // Set restarted flag + g_bRestart = false; + g_bHasRestarted = true; // Set restarted flag } // Save/Restore scene file transfers @@ -986,7 +986,7 @@ Common::Error TinselEngine::run() { _bmv->FettleBMV(); #ifdef DEBUG - if (bFast) + if (g_bFast) continue; // run flat-out #endif // Loop processing events while there are any pending @@ -1005,7 +1005,7 @@ Common::Error TinselEngine::run() { _vm->_config->writeToDisk(); EndScene(); - pCurBgnd = NULL; + g_pCurBgnd = NULL; return Common::kNoError; } @@ -1106,7 +1106,7 @@ void TinselEngine::RestartGame() { RebootTimers(); RebootScalingReels(); - DelayedScene.scene = HookScene.scene = 0; + g_DelayedScene.scene = g_HookScene.scene = 0; // remove keyboard, mouse and joystick drivers ChopDrivers(); @@ -1135,8 +1135,8 @@ void TinselEngine::RestartDrivers() { _scheduler->reset(); // init the event handlers - pMouseProcess = _scheduler->createProcess(PID_MOUSE, MouseProcess, NULL, 0); - pKeyboardProcess = _scheduler->createProcess(PID_KEYBOARD, KeyboardProcess, NULL, 0); + g_pMouseProcess = _scheduler->createProcess(PID_MOUSE, MouseProcess, NULL, 0); + g_pKeyboardProcess = _scheduler->createProcess(PID_KEYBOARD, KeyboardProcess, NULL, 0); // open MIDI files OpenMidiFiles(); @@ -1164,8 +1164,8 @@ void TinselEngine::ChopDrivers() { DeleteMidiBuffer(); // remove event drivers - _scheduler->killProcess(pMouseProcess); - _scheduler->killProcess(pKeyboardProcess); + _scheduler->killProcess(g_pMouseProcess); + _scheduler->killProcess(g_pKeyboardProcess); } /** diff --git a/engines/tinsel/token.cpp b/engines/tinsel/token.cpp index c7490a100b..c26fa40466 100644 --- a/engines/tinsel/token.cpp +++ b/engines/tinsel/token.cpp @@ -34,7 +34,7 @@ struct Token { PROCESS *proc; }; -static Token tokens[NUMTOKENS]; // FIXME: Avoid non-const global vars +static Token g_tokens[NUMTOKENS]; // FIXME: Avoid non-const global vars /** @@ -44,8 +44,8 @@ static void TerminateProcess(PROCESS *tProc) { // Release tokens held by the process for (int i = 0; i < NUMTOKENS; i++) { - if (tokens[i].proc == tProc) { - tokens[i].proc = NULL; + if (g_tokens[i].proc == tProc) { + g_tokens[i].proc = NULL; } } @@ -59,8 +59,8 @@ static void TerminateProcess(PROCESS *tProc) { void GetControlToken() { const int which = TOKEN_CONTROL; - if (tokens[which].proc == NULL) { - tokens[which].proc = g_scheduler->getCurrentProcess(); + if (g_tokens[which].proc == NULL) { + g_tokens[which].proc = g_scheduler->getCurrentProcess(); } } @@ -69,7 +69,7 @@ void GetControlToken() { */ void FreeControlToken() { // Allow anyone to free TOKEN_CONTROL - tokens[TOKEN_CONTROL].proc = NULL; + g_tokens[TOKEN_CONTROL].proc = NULL; } @@ -84,12 +84,12 @@ void FreeControlToken() { void GetToken(int which) { assert(TOKEN_LEAD <= which && which < NUMTOKENS); - if (tokens[which].proc != NULL) { - assert(tokens[which].proc != g_scheduler->getCurrentProcess()); - TerminateProcess(tokens[which].proc); + if (g_tokens[which].proc != NULL) { + assert(g_tokens[which].proc != g_scheduler->getCurrentProcess()); + TerminateProcess(g_tokens[which].proc); } - tokens[which].proc = g_scheduler->getCurrentProcess(); + g_tokens[which].proc = g_scheduler->getCurrentProcess(); } /** @@ -99,9 +99,9 @@ void GetToken(int which) { void FreeToken(int which) { assert(TOKEN_LEAD <= which && which < NUMTOKENS); - assert(tokens[which].proc == g_scheduler->getCurrentProcess()); // we'd have been killed if some other proc had taken this token + assert(g_tokens[which].proc == g_scheduler->getCurrentProcess()); // we'd have been killed if some other proc had taken this token - tokens[which].proc = NULL; + g_tokens[which].proc = NULL; } /** @@ -111,7 +111,7 @@ bool TestToken(int which) { if (which < 0 || which >= NUMTOKENS) return false; - return (tokens[which].proc == NULL); + return (g_tokens[which].proc == NULL); } /** @@ -119,7 +119,7 @@ bool TestToken(int which) { */ void FreeAllTokens() { for (int i = 0; i < NUMTOKENS; i++) { - tokens[i].proc = NULL; + g_tokens[i].proc = NULL; } } diff --git a/graphics/cursorman.cpp b/graphics/cursorman.cpp index 1d4e482bf4..425714ea34 100644 --- a/graphics/cursorman.cpp +++ b/graphics/cursorman.cpp @@ -31,10 +31,10 @@ DECLARE_SINGLETON(Graphics::CursorManager); namespace Graphics { CursorManager::~CursorManager() { - for (int i = 0; i < _cursorStack.size(); ++i) + for (Common::Stack<Cursor *>::size_type i = 0; i < _cursorStack.size(); ++i) delete _cursorStack[i]; _cursorStack.clear(); - for (int i = 0; i < _cursorPaletteStack.size(); ++i) + for (Common::Stack<Palette *>::size_type i = 0; i < _cursorPaletteStack.size(); ++i) delete _cursorPaletteStack[i]; _cursorPaletteStack.clear(); } diff --git a/gui/gui-manager.cpp b/gui/gui-manager.cpp index e7f49e9b2a..4fa60bfe07 100644 --- a/gui/gui-manager.cpp +++ b/gui/gui-manager.cpp @@ -188,7 +188,7 @@ bool GuiManager::loadNewTheme(Common::String id, ThemeEngine::GraphicsMode gfx, } // refresh all dialogs - for (int i = 0; i < _dialogStack.size(); ++i) + for (DialogStack::size_type i = 0; i < _dialogStack.size(); ++i) _dialogStack[i]->reflowLayout(); // We need to redraw immediately. Otherwise @@ -202,7 +202,6 @@ bool GuiManager::loadNewTheme(Common::String id, ThemeEngine::GraphicsMode gfx, } void GuiManager::redraw() { - int i; ThemeEngine::ShadingStyle shading; if (_redrawStatus == kRedrawDisabled || _dialogStack.empty()) @@ -223,7 +222,7 @@ void GuiManager::redraw() { _theme->clearAll(); _theme->openDialog(true, ThemeEngine::kShadingNone); - for (i = 0; i < _dialogStack.size() - 1; i++) + for (DialogStack::size_type i = 0; i < _dialogStack.size() - 1; i++) _dialogStack[i]->drawDialog(); _theme->finishBuffering(); @@ -515,7 +514,7 @@ void GuiManager::screenChange() { _theme->refresh(); // refresh all dialogs - for (int i = 0; i < _dialogStack.size(); ++i) { + for (DialogStack::size_type i = 0; i < _dialogStack.size(); ++i) { _dialogStack[i]->reflowLayout(); } // We need to redraw immediately. Otherwise diff --git a/test/common/fixedstack.h b/test/common/fixedstack.h index 9aa00b4680..9d4cceb2e6 100644 --- a/test/common/fixedstack.h +++ b/test/common/fixedstack.h @@ -18,18 +18,20 @@ public: } void test_size() { - Common::FixedStack<int> stack; - TS_ASSERT_EQUALS(stack.size(), 0); + typedef Common::FixedStack<int> Stack; + + Stack stack; + TS_ASSERT_EQUALS(stack.size(), (Stack::size_type)0); stack.push(5); - TS_ASSERT_EQUALS(stack.size(), 1); + TS_ASSERT_EQUALS(stack.size(), (Stack::size_type)1); stack.push(9); stack.push(0); - TS_ASSERT_EQUALS(stack.size(), 3); + TS_ASSERT_EQUALS(stack.size(), (Stack::size_type)3); stack.pop(); - TS_ASSERT_EQUALS(stack.size(), 2); + TS_ASSERT_EQUALS(stack.size(), (Stack::size_type)2); } void test_top_pop() { @@ -44,7 +46,7 @@ public: stack[0] = -23; stack.top() = 42; TS_ASSERT_EQUALS(stack[0], -23); - TS_ASSERT_EQUALS(stack.top(), 42); + TS_ASSERT_EQUALS(stack.top(), 42); stack.pop(); TS_ASSERT_EQUALS(stack[0], -23); diff --git a/test/common/stack.h b/test/common/stack.h index 0b1bcee350..ed32ec6496 100644 --- a/test/common/stack.h +++ b/test/common/stack.h @@ -18,18 +18,20 @@ public: } void test_size() { - Common::Stack<int> stack; - TS_ASSERT_EQUALS(stack.size(), 0); + typedef Common::Stack<int> Stack; + + Stack stack; + TS_ASSERT_EQUALS(stack.size(), (Stack::size_type)0); stack.push(5); - TS_ASSERT_EQUALS(stack.size(), 1); + TS_ASSERT_EQUALS(stack.size(), (Stack::size_type)1); stack.push(9); stack.push(0); - TS_ASSERT_EQUALS(stack.size(), 3); + TS_ASSERT_EQUALS(stack.size(), (Stack::size_type)3); stack.pop(); - TS_ASSERT_EQUALS(stack.size(), 2); + TS_ASSERT_EQUALS(stack.size(), (Stack::size_type)2); } void test_top_pop() { diff --git a/video/module.mk b/video/module.mk index ceeac94384..900a781d0a 100644 --- a/video/module.mk +++ b/video/module.mk @@ -5,6 +5,7 @@ MODULE_OBJS := \ coktel_decoder.o \ dxa_decoder.o \ flic_decoder.o \ + psx_decoder.o \ qt_decoder.o \ smk_decoder.o \ video_decoder.o \ diff --git a/video/psx_decoder.cpp b/video/psx_decoder.cpp new file mode 100644 index 0000000000..7c04b7f041 --- /dev/null +++ b/video/psx_decoder.cpp @@ -0,0 +1,697 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +// PlayStation Stream demuxer and XA audio decoder based on FFmpeg/libav +// MDEC video emulation based on http://kenai.com/downloads/jpsxdec/Old/PlayStation1_STR_format1-00.txt + +#include "audio/audiostream.h" +#include "audio/mixer.h" +#include "audio/decoders/raw.h" +#include "common/bitstream.h" +#include "common/huffman.h" +#include "common/memstream.h" +#include "common/stream.h" +#include "common/system.h" +#include "common/textconsole.h" +#include "graphics/yuv_to_rgb.h" + +#include "video/psx_decoder.h" + +namespace Video { + +// Here are the codes/lengths/symbols that are used for decoding +// DC coefficients (version 3 frames only) + +#define DC_CODE_COUNT 9 +#define DC_HUFF_VAL(b, n, p) (((b) << 16) | ((n) << 8) | (p)) +#define GET_DC_BITS(x) ((x) >> 16) +#define GET_DC_NEG(x) ((int)(((x) >> 8) & 0xff)) +#define GET_DC_POS(x) ((int)((x) & 0xff)) + +static const uint32 s_huffmanDCChromaCodes[DC_CODE_COUNT] = { + 254, 126, 62, 30, 14, 6, 2, 1, 0 +}; + +static const byte s_huffmanDCChromaLengths[DC_CODE_COUNT] = { + 8, 7, 6, 5, 4, 3, 2, 2, 2 +}; + +static const uint32 s_huffmanDCLumaCodes[DC_CODE_COUNT] = { + 126, 62, 30, 14, 6, 5, 1, 0, 4 +}; + +static const byte s_huffmanDCLumaLengths[DC_CODE_COUNT] = { + 7, 6, 5, 4, 3, 3, 2, 2, 3 +}; + +static const uint32 s_huffmanDCSymbols[DC_CODE_COUNT] = { + DC_HUFF_VAL(8, 255, 128), DC_HUFF_VAL(7, 127, 64), DC_HUFF_VAL(6, 63, 32), + DC_HUFF_VAL(5, 31, 16), DC_HUFF_VAL(4, 15, 8), DC_HUFF_VAL(3, 7, 4), + DC_HUFF_VAL(2, 3, 2), DC_HUFF_VAL(1, 1, 1), DC_HUFF_VAL(0, 0, 0) +}; + +// Here are the codes/lengths/symbols that are used for decoding +// DC coefficients (version 2 and 3 frames) + +#define AC_CODE_COUNT 113 +#define AC_HUFF_VAL(z, a) ((z << 8) | a) +#define ESCAPE_CODE ((uint32)-1) // arbitrary, just so we can tell what code it is +#define END_OF_BLOCK ((uint32)-2) // arbitrary, just so we can tell what code it is +#define GET_AC_ZERO_RUN(code) (code >> 8) +#define GET_AC_COEFFICIENT(code) ((int)(code & 0xff)) + +static const uint32 s_huffmanACCodes[AC_CODE_COUNT] = { + // Regular codes + 3, 3, 4, 5, 5, 6, 7, 4, 5, 6, 7, 4, 5, 6, 7, + 32, 33, 34, 35, 36, 37, 38, 39, 8, 9, 10, 11, + 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, + 23, 24, 25, 26, 27, 28, 29, 30, 31, 16, 17, + 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, + 29, 30, 31, 16, 17, 18, 19, 20, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31, 16, 17, 18, + 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, + 30, 31, 16, 17, 18, 19, 20, 21, 22, 23, 24, + 25, 26, 27, 28, 29, 30, 31, + + // Escape code + 1, + // End of block code + 2 +}; + +static const byte s_huffmanACLengths[AC_CODE_COUNT] = { + // Regular codes + 2, 3, 4, 4, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, + 8, 8, 8, 8, 8, 8, 8, 8, 10, 10, 10, 10, 10, + 10, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, + 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, + 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, + 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, + + // Escape code + 6, + // End of block code + 2 +}; + +static const uint32 s_huffmanACSymbols[AC_CODE_COUNT] = { + // Regular codes + AC_HUFF_VAL(0, 1), AC_HUFF_VAL(1, 1), AC_HUFF_VAL(0, 2), AC_HUFF_VAL(2, 1), AC_HUFF_VAL(0, 3), + AC_HUFF_VAL(4, 1), AC_HUFF_VAL(3, 1), AC_HUFF_VAL(7, 1), AC_HUFF_VAL(6, 1), AC_HUFF_VAL(1, 2), + AC_HUFF_VAL(5, 1), AC_HUFF_VAL(2, 2), AC_HUFF_VAL(9, 1), AC_HUFF_VAL(0, 4), AC_HUFF_VAL(8, 1), + AC_HUFF_VAL(13, 1), AC_HUFF_VAL(0, 6), AC_HUFF_VAL(12, 1), AC_HUFF_VAL(11, 1), AC_HUFF_VAL(3, 2), + AC_HUFF_VAL(1, 3), AC_HUFF_VAL(0, 5), AC_HUFF_VAL(10, 1), AC_HUFF_VAL(16, 1), AC_HUFF_VAL(5, 2), + AC_HUFF_VAL(0, 7), AC_HUFF_VAL(2, 3), AC_HUFF_VAL(1, 4), AC_HUFF_VAL(15, 1), AC_HUFF_VAL(14, 1), + AC_HUFF_VAL(4, 2), AC_HUFF_VAL(0, 11), AC_HUFF_VAL(8, 2), AC_HUFF_VAL(4, 3), AC_HUFF_VAL(0, 10), + AC_HUFF_VAL(2, 4), AC_HUFF_VAL(7, 2), AC_HUFF_VAL(21, 1), AC_HUFF_VAL(20, 1), AC_HUFF_VAL(0, 9), + AC_HUFF_VAL(19, 1), AC_HUFF_VAL(18, 1), AC_HUFF_VAL(1, 5), AC_HUFF_VAL(3, 3), AC_HUFF_VAL(0, 8), + AC_HUFF_VAL(6, 2), AC_HUFF_VAL(17, 1), AC_HUFF_VAL(10, 2), AC_HUFF_VAL(9, 2), AC_HUFF_VAL(5, 3), + AC_HUFF_VAL(3, 4), AC_HUFF_VAL(2, 5), AC_HUFF_VAL(1, 7), AC_HUFF_VAL(1, 6), AC_HUFF_VAL(0, 15), + AC_HUFF_VAL(0, 14), AC_HUFF_VAL(0, 13), AC_HUFF_VAL(0, 12), AC_HUFF_VAL(26, 1), AC_HUFF_VAL(25, 1), + AC_HUFF_VAL(24, 1), AC_HUFF_VAL(23, 1), AC_HUFF_VAL(22, 1), AC_HUFF_VAL(0, 31), AC_HUFF_VAL(0, 30), + AC_HUFF_VAL(0, 29), AC_HUFF_VAL(0, 28), AC_HUFF_VAL(0, 27), AC_HUFF_VAL(0, 26), AC_HUFF_VAL(0, 25), + AC_HUFF_VAL(0, 24), AC_HUFF_VAL(0, 23), AC_HUFF_VAL(0, 22), AC_HUFF_VAL(0, 21), AC_HUFF_VAL(0, 20), + AC_HUFF_VAL(0, 19), AC_HUFF_VAL(0, 18), AC_HUFF_VAL(0, 17), AC_HUFF_VAL(0, 16), AC_HUFF_VAL(0, 40), + AC_HUFF_VAL(0, 39), AC_HUFF_VAL(0, 38), AC_HUFF_VAL(0, 37), AC_HUFF_VAL(0, 36), AC_HUFF_VAL(0, 35), + AC_HUFF_VAL(0, 34), AC_HUFF_VAL(0, 33), AC_HUFF_VAL(0, 32), AC_HUFF_VAL(1, 14), AC_HUFF_VAL(1, 13), + AC_HUFF_VAL(1, 12), AC_HUFF_VAL(1, 11), AC_HUFF_VAL(1, 10), AC_HUFF_VAL(1, 9), AC_HUFF_VAL(1, 8), + AC_HUFF_VAL(1, 18), AC_HUFF_VAL(1, 17), AC_HUFF_VAL(1, 16), AC_HUFF_VAL(1, 15), AC_HUFF_VAL(6, 3), + AC_HUFF_VAL(16, 2), AC_HUFF_VAL(15, 2), AC_HUFF_VAL(14, 2), AC_HUFF_VAL(13, 2), AC_HUFF_VAL(12, 2), + AC_HUFF_VAL(11, 2), AC_HUFF_VAL(31, 1), AC_HUFF_VAL(30, 1), AC_HUFF_VAL(29, 1), AC_HUFF_VAL(28, 1), + AC_HUFF_VAL(27, 1), + + // Escape code + ESCAPE_CODE, + // End of block code + END_OF_BLOCK +}; + +PSXStreamDecoder::PSXStreamDecoder(CDSpeed speed, uint32 frameCount) : _nextFrameStartTime(0, speed), _frameCount(frameCount) { + _stream = 0; + _audStream = 0; + _surface = new Graphics::Surface(); + _yBuffer = _cbBuffer = _crBuffer = 0; + _acHuffman = new Common::Huffman(0, AC_CODE_COUNT, s_huffmanACCodes, s_huffmanACLengths, s_huffmanACSymbols); + _dcHuffmanChroma = new Common::Huffman(0, DC_CODE_COUNT, s_huffmanDCChromaCodes, s_huffmanDCChromaLengths, s_huffmanDCSymbols); + _dcHuffmanLuma = new Common::Huffman(0, DC_CODE_COUNT, s_huffmanDCLumaCodes, s_huffmanDCLumaLengths, s_huffmanDCSymbols); +} + +PSXStreamDecoder::~PSXStreamDecoder() { + close(); + delete _surface; + delete _acHuffman; + delete _dcHuffmanLuma; + delete _dcHuffmanChroma; +} + +#define RAW_CD_SECTOR_SIZE 2352 + +#define CDXA_TYPE_MASK 0x0E +#define CDXA_TYPE_DATA 0x08 +#define CDXA_TYPE_AUDIO 0x04 +#define CDXA_TYPE_VIDEO 0x02 + +bool PSXStreamDecoder::loadStream(Common::SeekableReadStream *stream) { + close(); + + _stream = stream; + + Common::SeekableReadStream *sector = readSector(); + + if (!sector) { + close(); + return false; + } + + // Rip out video info from the first frame + sector->seek(18); + byte sectorType = sector->readByte() & CDXA_TYPE_MASK; + + if (sectorType != CDXA_TYPE_VIDEO && sectorType != CDXA_TYPE_DATA) { + close(); + return false; + } + + sector->seek(40); + + uint16 width = sector->readUint16LE(); + uint16 height = sector->readUint16LE(); + _surface->create(width, height, g_system->getScreenFormat()); + + _macroBlocksW = (width + 15) / 16; + _macroBlocksH = (height + 15) / 16; + _yBuffer = new byte[_macroBlocksW * _macroBlocksH * 16 * 16]; + _cbBuffer = new byte[_macroBlocksW * _macroBlocksH * 8 * 8]; + _crBuffer = new byte[_macroBlocksW * _macroBlocksH * 8 * 8]; + + delete sector; + _stream->seek(0); + + return true; +} + +void PSXStreamDecoder::close() { + if (!_stream) + return; + + delete _stream; + _stream = 0; + + // Deinitialize sound + g_system->getMixer()->stopHandle(_audHandle); + _audStream = 0; + + _surface->free(); + + memset(&_adpcmStatus, 0, sizeof(_adpcmStatus)); + + _macroBlocksW = _macroBlocksH = 0; + delete[] _yBuffer; _yBuffer = 0; + delete[] _cbBuffer; _cbBuffer = 0; + delete[] _crBuffer; _crBuffer = 0; + + reset(); +} + +uint32 PSXStreamDecoder::getElapsedTime() const { + // TODO: Currently, the audio is always after the video so using this + // can often lead to gaps in the audio... + //if (_audStream) + // return _mixer->getSoundElapsedTime(_audHandle); + + return VideoDecoder::getElapsedTime(); +} + +uint32 PSXStreamDecoder::getTimeToNextFrame() const { + if (!isVideoLoaded() || endOfVideo()) + return 0; + + uint32 nextTimeMillis = _nextFrameStartTime.msecs(); + uint32 elapsedTime = getElapsedTime(); + + if (elapsedTime > nextTimeMillis) + return 0; + + return nextTimeMillis - elapsedTime; +} + +#define VIDEO_DATA_CHUNK_SIZE 2016 +#define VIDEO_DATA_HEADER_SIZE 56 + +const Graphics::Surface *PSXStreamDecoder::decodeNextFrame() { + Common::SeekableReadStream *sector = 0; + byte *partialFrame = 0; + int sectorsRead = 0; + + while (!endOfVideo()) { + sector = readSector(); + sectorsRead++; + + if (!sector) + error("Corrupt PSX stream sector"); + + sector->seek(0x11); + byte track = sector->readByte(); + if (track >= 32) + error("Bad PSX stream track"); + + byte sectorType = sector->readByte() & CDXA_TYPE_MASK; + + switch (sectorType) { + case CDXA_TYPE_DATA: + case CDXA_TYPE_VIDEO: + if (track == 1) { + sector->seek(28); + uint16 curSector = sector->readUint16LE(); + uint16 sectorCount = sector->readUint16LE(); + sector->readUint32LE(); + uint16 frameSize = sector->readUint32LE(); + + if (curSector >= sectorCount) + error("Bad sector"); + + if (!partialFrame) + partialFrame = (byte *)malloc(sectorCount * VIDEO_DATA_CHUNK_SIZE); + + sector->seek(VIDEO_DATA_HEADER_SIZE); + sector->read(partialFrame + curSector * VIDEO_DATA_CHUNK_SIZE, VIDEO_DATA_CHUNK_SIZE); + + if (curSector == sectorCount - 1) { + // Done assembling the frame + Common::SeekableReadStream *frame = new Common::MemoryReadStream(partialFrame, frameSize, DisposeAfterUse::YES); + + decodeFrame(frame); + + delete frame; + delete sector; + + _curFrame++; + if (_curFrame == 0) + _startTime = g_system->getMillis(); + + // Increase the time by the amount of sectors we read + // One may notice that this is still not the most precise + // method since a frame takes up the time its sectors took + // up instead of the amount of time it takes the next frame + // to be read from the sectors. The actual frame rate should + // be constant instead of variable, so the slight difference + // in a frame's showing time is negligible (1/150 of a second). + _nextFrameStartTime = _nextFrameStartTime.addFrames(sectorsRead); + + return _surface; + } + } else + error("Unhandled multi-track video"); + break; + case CDXA_TYPE_AUDIO: + // We only handle one audio channel so far + if (track == 1) + queueAudioFromSector(sector); + else + warning("Unhandled multi-track audio"); + break; + default: + // This shows up way too often, but the other sectors + // are safe to ignore + //warning("Unknown PSX sector type 0x%x", sectorType); + break; + } + + delete sector; + } + + return 0; +} + +static const byte s_syncHeader[12] = { 0x00, 0xff ,0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00 }; + +Common::SeekableReadStream *PSXStreamDecoder::readSector() { + assert(_stream); + + Common::SeekableReadStream *stream = _stream->readStream(RAW_CD_SECTOR_SIZE); + + byte syncHeader[12]; + stream->read(syncHeader, 12); + if (!memcmp(s_syncHeader, syncHeader, 12)) + return stream; + + return 0; +} + +// Ha! It's palindromic! +#define AUDIO_DATA_CHUNK_SIZE 2304 +#define AUDIO_DATA_SAMPLE_COUNT 4032 + +static const int s_xaTable[5][2] = { + { 0, 0 }, + { 60, 0 }, + { 115, -52 }, + { 98, -55 }, + { 122, -60 } +}; + +void PSXStreamDecoder::queueAudioFromSector(Common::SeekableReadStream *sector) { + assert(sector); + + if (!_audStream) { + // Initialize audio stream + sector->seek(19); + byte format = sector->readByte(); + + bool stereo = (format & (1 << 0)) != 0; + uint rate = (format & (1 << 2)) ? 18900 : 37800; + + _audStream = Audio::makeQueuingAudioStream(rate, stereo); + g_system->getMixer()->playStream(Audio::Mixer::kPlainSoundType, &_audHandle, _audStream); + } + + sector->seek(24); + + // This XA audio is different (yet similar) from normal XA audio! Watch out! + // TODO: It's probably similar enough to normal XA that we can merge it somehow... + // TODO: RTZ PSX needs the same audio code in a regular AudioStream class. Probably + // will do something similar to QuickTime and creating a base class 'ISOMode2Parser' + // or something similar. + byte *buf = new byte[AUDIO_DATA_CHUNK_SIZE]; + sector->read(buf, AUDIO_DATA_CHUNK_SIZE); + + int channels = _audStream->isStereo() ? 2 : 1; + int16 *dst = new int16[AUDIO_DATA_SAMPLE_COUNT]; + int16 *leftChannel = dst; + int16 *rightChannel = dst + 1; + + for (byte *src = buf; src < buf + AUDIO_DATA_CHUNK_SIZE; src += 128) { + for (int i = 0; i < 4; i++) { + int shift = 12 - (src[4 + i * 2] & 0xf); + int filter = src[4 + i * 2] >> 4; + int f0 = s_xaTable[filter][0]; + int f1 = s_xaTable[filter][1]; + int16 s_1 = _adpcmStatus[0].sample[0]; + int16 s_2 = _adpcmStatus[0].sample[1]; + + for (int j = 0; j < 28; j++) { + byte d = src[16 + i + j * 4]; + int t = (int8)(d << 4) >> 4; + int s = (t << shift) + ((s_1 * f0 + s_2 * f1 + 32) >> 6); + s_2 = s_1; + s_1 = CLIP<int>(s, -32768, 32767); + *leftChannel = s_1; + leftChannel += channels; + } + + if (channels == 2) { + _adpcmStatus[0].sample[0] = s_1; + _adpcmStatus[0].sample[1] = s_2; + s_1 = _adpcmStatus[1].sample[0]; + s_2 = _adpcmStatus[1].sample[1]; + } + + shift = 12 - (src[5 + i * 2] & 0xf); + filter = src[5 + i * 2] >> 4; + f0 = s_xaTable[filter][0]; + f1 = s_xaTable[filter][1]; + + for (int j = 0; j < 28; j++) { + byte d = src[16 + i + j * 4]; + int t = (int8)d >> 4; + int s = (t << shift) + ((s_1 * f0 + s_2 * f1 + 32) >> 6); + s_2 = s_1; + s_1 = CLIP<int>(s, -32768, 32767); + + if (channels == 2) { + *rightChannel = s_1; + rightChannel += 2; + } else { + *leftChannel++ = s_1; + } + } + + if (channels == 2) { + _adpcmStatus[1].sample[0] = s_1; + _adpcmStatus[1].sample[1] = s_2; + } else { + _adpcmStatus[0].sample[0] = s_1; + _adpcmStatus[0].sample[1] = s_2; + } + } + } + + int flags = Audio::FLAG_16BITS; + + if (_audStream->isStereo()) + flags |= Audio::FLAG_STEREO; + +#ifdef SCUMM_LITTLE_ENDIAN + flags |= Audio::FLAG_LITTLE_ENDIAN; +#endif + + _audStream->queueBuffer((byte *)dst, AUDIO_DATA_SAMPLE_COUNT * 2, DisposeAfterUse::YES, flags); + delete[] buf; +} + +void PSXStreamDecoder::decodeFrame(Common::SeekableReadStream *frame) { + // A frame is essentially an MPEG-1 intra frame + + Common::BitStream16LEMSB bits(frame); + + bits.skip(16); // unknown + bits.skip(16); // 0x3800 + uint16 scale = bits.getBits(16); + uint16 version = bits.getBits(16); + + if (version != 2 && version != 3) + error("Unknown PSX stream frame version"); + + // Initalize default v3 DC here + _lastDC[0] = _lastDC[1] = _lastDC[2] = 0; + + for (int mbX = 0; mbX < _macroBlocksW; mbX++) + for (int mbY = 0; mbY < _macroBlocksH; mbY++) + decodeMacroBlock(&bits, mbX, mbY, scale, version); + + // Output data onto the frame + Graphics::convertYUV420ToRGB(_surface, _yBuffer, _cbBuffer, _crBuffer, _surface->w, _surface->h, _macroBlocksW * 16, _macroBlocksW * 8); +} + +void PSXStreamDecoder::decodeMacroBlock(Common::BitStream *bits, int mbX, int mbY, uint16 scale, uint16 version) { + int pitchY = _macroBlocksW * 16; + int pitchC = _macroBlocksW * 8; + + // Note the strange order of red before blue + decodeBlock(bits, _crBuffer + (mbY * pitchC + mbX) * 8, pitchC, scale, version, kPlaneV); + decodeBlock(bits, _cbBuffer + (mbY * pitchC + mbX) * 8, pitchC, scale, version, kPlaneU); + decodeBlock(bits, _yBuffer + (mbY * pitchY + mbX) * 16, pitchY, scale, version, kPlaneY); + decodeBlock(bits, _yBuffer + (mbY * pitchY + mbX) * 16 + 8, pitchY, scale, version, kPlaneY); + decodeBlock(bits, _yBuffer + (mbY * pitchY + mbX) * 16 + 8 * pitchY, pitchY, scale, version, kPlaneY); + decodeBlock(bits, _yBuffer + (mbY * pitchY + mbX) * 16 + 8 * pitchY + 8, pitchY, scale, version, kPlaneY); +} + +// Standard JPEG/MPEG zig zag table +static const byte s_zigZagTable[8 * 8] = { + 0, 1, 5, 6, 14, 15, 27, 28, + 2, 4, 7, 13, 16, 26, 29, 42, + 3, 8, 12, 17, 25, 30, 41, 43, + 9, 11, 18, 24, 31, 40, 44, 53, + 10, 19, 23, 32, 39, 45, 52, 54, + 20, 22, 33, 38, 46, 51, 55, 60, + 21, 34, 37, 47, 50, 56, 59, 61, + 35, 36, 48, 49, 57, 58, 62, 63 +}; + +// One byte different from the standard MPEG-1 table +static const byte s_quantizationTable[8 * 8] = { + 2, 16, 19, 22, 26, 27, 29, 34, + 16, 16, 22, 24, 27, 29, 34, 37, + 19, 22, 26, 27, 29, 34, 34, 38, + 22, 22, 26, 27, 29, 34, 37, 40, + 22, 26, 27, 29, 32, 35, 40, 48, + 26, 27, 29, 32, 35, 40, 48, 58, + 26, 27, 29, 34, 38, 46, 56, 69, + 27, 29, 35, 38, 46, 56, 69, 83 +}; + +void PSXStreamDecoder::dequantizeBlock(int *coefficients, float *block, uint16 scale) { + // Dequantize the data, un-zig-zagging as we go along + for (int i = 0; i < 8 * 8; i++) { + if (i == 0) // Special case for the DC coefficient + block[i] = coefficients[i] * s_quantizationTable[i]; + else + block[i] = (float)coefficients[s_zigZagTable[i]] * s_quantizationTable[i] * scale / 8; + } +} + +int PSXStreamDecoder::readDC(Common::BitStream *bits, uint16 version, PlaneType plane) { + // Version 2 just has its coefficient as 10-bits + if (version == 2) + return readSignedCoefficient(bits); + + // Version 3 has it stored as huffman codes as a difference from the previous DC value + + Common::Huffman *huffman = (plane == kPlaneY) ? _dcHuffmanLuma : _dcHuffmanChroma; + + uint32 symbol = huffman->getSymbol(*bits); + int dc = 0; + + if (GET_DC_BITS(symbol) != 0) { + bool negative = (bits->getBit() == 0); + dc = bits->getBits(GET_DC_BITS(symbol) - 1); + + if (negative) + dc -= GET_DC_NEG(symbol); + else + dc += GET_DC_POS(symbol); + } + + _lastDC[plane] += dc * 4; // convert from 8-bit to 10-bit + return _lastDC[plane]; +} + +#define BLOCK_OVERFLOW_CHECK() \ + if (count > 63) \ + error("PSXStreamDecoder::readAC(): Too many coefficients") + +void PSXStreamDecoder::readAC(Common::BitStream *bits, int *block) { + // Clear the block first + for (int i = 0; i < 63; i++) + block[i] = 0; + + int count = 0; + + while (!bits->eos()) { + uint32 symbol = _acHuffman->getSymbol(*bits); + + if (symbol == ESCAPE_CODE) { + // The escape code! + int zeroes = bits->getBits(6); + count += zeroes + 1; + BLOCK_OVERFLOW_CHECK(); + block += zeroes; + *block++ = readSignedCoefficient(bits); + } else if (symbol == END_OF_BLOCK) { + // We're done + break; + } else { + // Normal huffman code + int zeroes = GET_AC_ZERO_RUN(symbol); + count += zeroes + 1; + BLOCK_OVERFLOW_CHECK(); + block += zeroes; + + if (bits->getBit()) + *block++ = -GET_AC_COEFFICIENT(symbol); + else + *block++ = GET_AC_COEFFICIENT(symbol); + } + } +} + +int PSXStreamDecoder::readSignedCoefficient(Common::BitStream *bits) { + uint val = bits->getBits(10); + + // extend the sign + uint shift = 8 * sizeof(int) - 10; + return (int)(val << shift) >> shift; +} + +// IDCT table built with : +// _idct8x8[x][y] = cos(((2 * x + 1) * y) * (M_PI / 16.0)) * 0.5; +// _idct8x8[x][y] /= sqrt(2.0) if y == 0 +static const double s_idct8x8[8][8] = { + { 0.353553390593274, 0.490392640201615, 0.461939766255643, 0.415734806151273, 0.353553390593274, 0.277785116509801, 0.191341716182545, 0.097545161008064 }, + { 0.353553390593274, 0.415734806151273, 0.191341716182545, -0.097545161008064, -0.353553390593274, -0.490392640201615, -0.461939766255643, -0.277785116509801 }, + { 0.353553390593274, 0.277785116509801, -0.191341716182545, -0.490392640201615, -0.353553390593274, 0.097545161008064, 0.461939766255643, 0.415734806151273 }, + { 0.353553390593274, 0.097545161008064, -0.461939766255643, -0.277785116509801, 0.353553390593274, 0.415734806151273, -0.191341716182545, -0.490392640201615 }, + { 0.353553390593274, -0.097545161008064, -0.461939766255643, 0.277785116509801, 0.353553390593274, -0.415734806151273, -0.191341716182545, 0.490392640201615 }, + { 0.353553390593274, -0.277785116509801, -0.191341716182545, 0.490392640201615, -0.353553390593273, -0.097545161008064, 0.461939766255643, -0.415734806151273 }, + { 0.353553390593274, -0.415734806151273, 0.191341716182545, 0.097545161008064, -0.353553390593274, 0.490392640201615, -0.461939766255643, 0.277785116509801 }, + { 0.353553390593274, -0.490392640201615, 0.461939766255643, -0.415734806151273, 0.353553390593273, -0.277785116509801, 0.191341716182545, -0.097545161008064 } +}; + +void PSXStreamDecoder::idct(float *dequantData, float *result) { + // IDCT code based on JPEG's IDCT code + // TODO: Switch to the integer-based one mentioned in the docs + // This is by far the costliest operation here + + float tmp[8 * 8]; + + // Apply 1D IDCT to rows + for (int y = 0; y < 8; y++) { + for (int x = 0; x < 8; x++) { + tmp[y + x * 8] = dequantData[0] * s_idct8x8[x][0] + + dequantData[1] * s_idct8x8[x][1] + + dequantData[2] * s_idct8x8[x][2] + + dequantData[3] * s_idct8x8[x][3] + + dequantData[4] * s_idct8x8[x][4] + + dequantData[5] * s_idct8x8[x][5] + + dequantData[6] * s_idct8x8[x][6] + + dequantData[7] * s_idct8x8[x][7]; + } + + dequantData += 8; + } + + // Apply 1D IDCT to columns + for (int x = 0; x < 8; x++) { + const float *u = tmp + x * 8; + for (int y = 0; y < 8; y++) { + result[y * 8 + x] = u[0] * s_idct8x8[y][0] + + u[1] * s_idct8x8[y][1] + + u[2] * s_idct8x8[y][2] + + u[3] * s_idct8x8[y][3] + + u[4] * s_idct8x8[y][4] + + u[5] * s_idct8x8[y][5] + + u[6] * s_idct8x8[y][6] + + u[7] * s_idct8x8[y][7]; + } + } +} + +void PSXStreamDecoder::decodeBlock(Common::BitStream *bits, byte *block, int pitch, uint16 scale, uint16 version, PlaneType plane) { + // Version 2 just has signed 10 bits for DC + // Version 3 has them huffman coded + int coefficients[8 * 8]; + coefficients[0] = readDC(bits, version, plane); + readAC(bits, &coefficients[1]); // Read in the AC + + // Dequantize + float dequantData[8 * 8]; + dequantizeBlock(coefficients, dequantData, scale); + + // Perform IDCT + float idctData[8 * 8]; + idct(dequantData, idctData); + + // Now output the data + for (int y = 0; y < 8; y++) { + byte *start = block + pitch * y; + + // Convert the result to be in the range [0, 255] + for (int x = 0; x < 8; x++) + *start++ = (int)CLIP<float>(idctData[y * 8 + x], -128.0f, 127.0f) + 128; + } +} + +} // End of namespace Video diff --git a/video/psx_decoder.h b/video/psx_decoder.h new file mode 100644 index 0000000000..c8ad92c45a --- /dev/null +++ b/video/psx_decoder.h @@ -0,0 +1,128 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef VIDEO_PSX_DECODER_H +#define VIDEO_PSX_DECODER_H + +#include "common/endian.h" +#include "common/rational.h" +#include "common/rect.h" +#include "common/str.h" +#include "graphics/surface.h" +#include "video/video_decoder.h" + +namespace Audio { +class QueuingAudioStream; +} + +namespace Common { +class BitStream; +class Huffman; +class SeekableReadStream; +} + +namespace Graphics { +struct PixelFormat; +} + +namespace Video { + +/** + * Decoder for PSX stream videos. + * This currently implements the most basic PSX stream format that is + * used by most games on the system. Special variants are not supported + * at this time. + * + * Video decoder used in engines: + * - sword1 (psx) + * - sword2 (psx) + */ +class PSXStreamDecoder : public VideoDecoder { +public: + // CD speed in sectors/second + // Calling code should use these enum values instead of the constants + enum CDSpeed { + kCD1x = 75, + kCD2x = 150 + }; + + PSXStreamDecoder(CDSpeed speed, uint32 frameCount = 0); + virtual ~PSXStreamDecoder(); + + bool loadStream(Common::SeekableReadStream *stream); + void close(); + + bool isVideoLoaded() const { return _stream != 0; } + uint16 getWidth() const { return _surface->w; } + uint16 getHeight() const { return _surface->h; } + uint32 getFrameCount() const { return _frameCount; } + uint32 getElapsedTime() const; + uint32 getTimeToNextFrame() const; + const Graphics::Surface *decodeNextFrame(); + Graphics::PixelFormat getPixelFormat() const { return _surface->format; } + bool endOfVideo() const { return _stream->pos() >= _stream->size(); } + +private: + void initCommon(); + Common::SeekableReadStream *_stream; + Graphics::Surface *_surface; + + uint32 _frameCount; + Audio::Timestamp _nextFrameStartTime; + + Audio::SoundHandle _audHandle; + Audio::QueuingAudioStream *_audStream; + void queueAudioFromSector(Common::SeekableReadStream *sector); + + enum PlaneType { + kPlaneY = 0, + kPlaneU = 1, + kPlaneV = 2 + }; + + uint16 _macroBlocksW, _macroBlocksH; + byte *_yBuffer, *_cbBuffer, *_crBuffer; + void decodeFrame(Common::SeekableReadStream *frame); + void decodeMacroBlock(Common::BitStream *bits, int mbX, int mbY, uint16 scale, uint16 version); + void decodeBlock(Common::BitStream *bits, byte *block, int pitch, uint16 scale, uint16 version, PlaneType plane); + + void readAC(Common::BitStream *bits, int *block); + Common::Huffman *_acHuffman; + + int readDC(Common::BitStream *bits, uint16 version, PlaneType plane); + Common::Huffman *_dcHuffmanLuma, *_dcHuffmanChroma; + int _lastDC[3]; + + void dequantizeBlock(int *coefficients, float *block, uint16 scale); + void idct(float *dequantData, float *result); + int readSignedCoefficient(Common::BitStream *bits); + + struct ADPCMStatus { + int16 sample[2]; + } _adpcmStatus[2]; + + Common::SeekableReadStream *readSector(); +}; + +} // End of namespace Video + +#endif |