Added sharedIoWin library

This commit is contained in:
Anonymous
2014-01-19 03:11:35 -07:00
parent 3a082554e9
commit babd79e527
21 changed files with 1803 additions and 0 deletions
+1
View File
@@ -10,6 +10,7 @@ add_subdirectory(sharedFoundationTypes)
add_subdirectory(sharedFractal)
add_subdirectory(sharedGame)
add_subdirectory(sharedImage)
add_subdirectory(sharedIoWin)
add_subdirectory(sharedLog)
add_subdirectory(sharedMath)
add_subdirectory(sharedMathArchive)
@@ -148,6 +148,7 @@ include_directories(
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedDebug/include/public
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedFile/include/public
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedFoundationTypes/include/public
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedIoWin/include/public
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedLog/include/public
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedMath/include/public
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedMathArchive/include/public
@@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 2.8)
project(sharedIoWin)
if(WIN32)
add_definitions(/D_CRT_SECURE_NO_WARNINGS)
endif()
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/public)
add_subdirectory(src)
@@ -0,0 +1 @@
#include "../../src/shared/ConfigSharedIoWin.h"
@@ -0,0 +1 @@
#include "../../src/shared/FirstSharedIoWin.h"
@@ -0,0 +1 @@
#include "../../src/shared/IoWin.def"
@@ -0,0 +1 @@
#include "../../src/shared/IoWin.h"
@@ -0,0 +1 @@
#include "../../src/shared/IoWinManager.h"
@@ -0,0 +1 @@
#include "../../src/shared/SetupSharedIoWin.h"
@@ -0,0 +1,36 @@
set(SHARED_SOURCES
shared/FirstSharedIoWin.h
shared/ConfigSharedIoWin.cpp
shared/ConfigSharedIoWin.h
shared/IoWin.cpp
shared/IoWin.def
shared/IoWin.h
shared/IoWinManager.cpp
shared/IoWinManager.h
shared/SetupSharedIoWin.cpp
shared/SetupSharedIoWin.h
)
if(WIN32)
set(PLATFORM_SOURCES
win32/FirstSharedImage.cpp
)
else()
set(PLATFORM_SOURCES "")
endif()
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/shared
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedDebug/include/public
#${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedFile/include/public
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedFoundation/include/public
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedFoundationTypes/include/public
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedMemoryManager/include/public
#${SWG_EXTERNALS_SOURCE_DIR}/ours/library/fileInterface/include/public
)
add_library(sharedIoWin STATIC
${SHARED_SOURCES}
${PLATFORM_SOURCES}
)
@@ -0,0 +1,42 @@
// ======================================================================
//
// ConfigSharedIoWin.cpp
// copyright 2004 Sony Online Entertainment
//
// ======================================================================
#include "sharedIoWin/FirstSharedIoWin.h"
#include "sharedIoWin/ConfigSharedIoWin.h"
#include "sharedFoundation/ConfigFile.h"
// ======================================================================
#define KEY_BOOL(a,b) (ms_ ## a = ConfigFile::getKeyBool("SharedIoWin", #a, (b)))
// ======================================================================
namespace ConfigSharedIoWinNamespace
{
bool ms_sample;
}
using namespace ConfigSharedIoWinNamespace;
// ======================================================================
void ConfigSharedIoWin::install()
{
KEY_BOOL(sample, false);
}
// ----------------------------------------------------------------------
bool ConfigSharedIoWin::getSample()
{
return ms_sample;
}
// ======================================================================
@@ -0,0 +1,24 @@
// ======================================================================
//
// ConfigSharedIoWin.h
// Copyright 2004, Sony Online Entertainment Inc.
// All Rights Reserved.
//
// ======================================================================
#ifndef INCLUDED_ConfigSharedIoWin_H
#define INCLUDED_ConfigSharedIoWin_H
// ======================================================================
class ConfigSharedIoWin
{
public:
static void install();
static bool getSample();
};
// ======================================================================
#endif
@@ -0,0 +1,17 @@
// ======================================================================
//
// FirstIoWin.h
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_FirstIoWin_H
#define INCLUDED_FirstIoWin_H
// ======================================================================
#include "sharedFoundation/FirstSharedFoundation.h"
// ======================================================================
#endif
@@ -0,0 +1,117 @@
// ======================================================================
//
// IoWin.cpp
// copyright 1998 Bootprint Entertainment
// copyright 2001 Sony Online Entertainment
//
// ======================================================================
#include "sharedIoWin/FirstSharedIoWin.h"
#include "sharedIoWin/IoWin.h"
#include "sharedIoWin/IoWinManager.h"
// ======================================================================
// Cosntruct an IoWin
//
// Remarks:
//
// The debugName argument is used only for debugging
IoWin::IoWin(
const char *debugName // Name used for debugging purposes
)
: ioDebugName(DuplicateString(debugName)),
ioNext(NULL)
{
}
// ----------------------------------------------------------------------
/**
* Destroy an IoWin.
*
* This routine is intended to be overloaded in derived classes.
*/
IoWin::~IoWin(void)
{
delete [] ioDebugName;
ioDebugName = NULL;
ioNext = NULL;
}
// ----------------------------------------------------------------------
/**
* Process an event.
*
* This routine is intended to be overloaded in derived classes.
*
* The event is intentionally not const so that a IoWin may modify the event
* for other IoWins that are further down the stack.
*
* If this routine returns IOR_Pass or IOR_PassKillMe, the event will be passed
* down to the next window on the stack. If this routine returns IOR_Block or
* IOR_BlockKillMe, the event will not be passed down to the next window on the
* stack, and will effectively be squelched.
*
* If this routine returns IOR_PassKillMe or IOR_BlockKillMe, the window will
* first be closed, and then will be deleted.
*
* This base-class version simply returns IOR_Pass.
*
* @param event The event to process
* @return How the IoWinManager should handle this window and event
*/
IoResult IoWin::processEvent(IoEvent *event)
{
UNREF(event);
return IOR_Pass;
}
// ----------------------------------------------------------------------
/**
* Draw the window.
*
* This routine is intended to be overloaded in derived classes.
*
* This base-class version simply calls the next IoWin's draw routine. Derived classes
* may or may not want to call this routine in the base class, depending on their needs.
*/
void IoWin::draw(void) const
{
if (ioNext)
ioNext->draw();
}
// ----------------------------------------------------------------------
/**
* Open this window.
*
* This routine simply calls IoWinManager::open() with itself as the argument.
*/
void IoWin::open(void)
{
IoWinManager::open(this);
}
// ----------------------------------------------------------------------
/**
* Close this window.
*
* This routine simply calls IoWinManager::close() with itself as the argument.
*/
void IoWin::close(void)
{
IoWinManager::close(this);
}
// ======================================================================
@@ -0,0 +1,92 @@
// ======================================================================
//
// IoWin.def
// jeff grills
//
// copyright 1998 Bootprint Entertainment
//
// ======================================================================
#ifndef IO_WIN_DEF
#define IO_WIN_DEF
// ======================================================================
const int IOR_PASS_BIT = BINARY1(0001);
const int IOR_BLOCK_BIT = BINARY1(0010);
const int IOR_KILL_BIT = BINARY1(0100);
enum IoResult
{
IOR_Pass = IOR_PASS_BIT,
IOR_PassKillMe = IOR_PASS_BIT | IOR_KILL_BIT,
IOR_Block = IOR_BLOCK_BIT,
IOR_BlockKillMe = IOR_BLOCK_BIT | IOR_KILL_BIT
};
enum IoEventType
{
IOET_WindowOpen, // the window is being put on the top of the IoWinManager stack; no arguments
IOET_WindowClose, // the window is being removed from the IoWinManager stack; no arguments
IOET_WindowKill, // the game is shutting down and all the open windows will be sent this event; no arguments
IOET_Prepare, // sent once per frame, before any other events are sent; no arguments
IOET_Update, // sent once per frame; arg3 = time elapsed in seconds
IOET_InputReset, // assume all input in default state (assume all buttons up, input focus probably lost); no arguments
IOET_Character, // arg1 = keyboard number, arg2 = character
IOET_KeyDown, // arg1 = keyboard number, arg2 = keycode
IOET_KeyUp, // arg1 = keyboard number, arg2 = keycode
IOET_JoystickMove, // arg1 = joystick number, arg2 = movement type, arg3 = offset amount
IOET_JoystickButtonDown, // arg1 = joystick number, arg2 = button number
IOET_JoystickButtonUp, // arg1 = joystick number, arg2 = button number
IOET_JoystickPovHat, // arg1 = joystick number, arg2 = pov hat number, arg3 = pov angle (-1 centered, 0 .. 2pi)
IOET_JoystickSlider, // arg1 = joystick number, arg2 = slider, arg3 = value
IOET_MouseMove, // arg1 = mouse number, arg2 = movement type, arg3 = movement amount
IOET_MouseButtonDown, // arg1 = mouse number, arg2 = button number
IOET_MouseButtonUp, // arg1 = mouse number, arg2 = button number
IOET_SetSystemMouseCursorPosition, // arg1 = cursor X, arg2 = cursor Y
IOET_IMEComposition, // Changes an IME composition
IOET_IMEChangeCandidate, // Show the IME candidate selection panel
IOET_IMECloseCandidate, // Close the IME candidate selection panel
IOET_IMEEndComposition, // End an IME composition
IOET_Count // ALWAYS KEEP THIS LAST
};
enum // IoMovementType
{
IOMT_TranslateX,
IOMT_TranslateY,
IOMT_TranslateZ,
IOMT_RotateX,
IOMT_RotateY,
IOMT_RotateZ
};
struct IoEvent
{
friend class IoWinManager;
private:
IoEvent *next; // pointer to next event; only valid while in the queue within IoWinManager
public:
IoEventType type; // type of the event
int arg1; // value defined by IoEvent::type
int arg2; // value defined by IoEvent::type
real arg3; // value defined by IoEvent::type
};
// ======================================================================
#endif
@@ -0,0 +1,50 @@
// ======================================================================
//
// IoWin.h
// jeff grills
//
// copyright 1998 Bootprint Entertainment
//
// ======================================================================
#ifndef IO_WIN_H
#define IO_WIN_H
// ======================================================================
#include "sharedIoWin/IoWin.def"
// ======================================================================
class IoWin
{
friend class IoWinManager;
private:
// explicitly disable these routines
IoWin(void);
IoWin(const IoWin &);
IoWin &operator =(const IoWin &);
private:
char *ioDebugName;
IoWin *ioNext;
public:
explicit IoWin(const char *debugName);
virtual ~IoWin(void);
virtual IoResult processEvent(IoEvent *event);
virtual void draw(void) const;
void open(void);
void close(void);
};
// ======================================================================
#endif
@@ -0,0 +1,717 @@
// ======================================================================
//
// IoWinManager.cpp
// Portions copyright 1998 Bootprint Entertainment
// Portions copyright 2001 Sony Online Entertainment
// All Rights Reserved.
//
// ======================================================================
#include "sharedIoWin/FirstSharedIoWin.h"
#include "sharedIoWin/IoWinManager.h"
#include "sharedDebug/DebugFlags.h"
#include "sharedFoundation/ExitChain.h"
#include "sharedFoundation/MemoryBlockManager.h"
#include "sharedFoundation/Os.h"
#include "sharedIoWin/IoWin.h"
#include "sharedFoundation/Timer.h"
// ======================================================================
namespace IoWinManagerNamespace
{
bool s_discardIdenticalJoystickMotionEvents = false;
int const s_numJoystickAxes = 10;
int const s_numJoystickSliders = 10;
int const s_numJoysticks = 3;
float s_lastJoystickAxis[s_numJoysticks][s_numJoystickAxes];
float s_lastJoystickSlider[s_numJoysticks][s_numJoystickSliders];
float const s_joystickAxisIdenticalThreshold = 0.1f;
float const s_joystickSliderIdenticalThreshold = 0.1f;
// Inactivity timer.
float const s_defaultInactivityTimeSeconds = 15.0f * 60.0f;
IoWinManager::InactivityCallback s_inactivityCallback = NULL;
Timer s_inactivityTimer(s_defaultInactivityTimeSeconds);
bool s_isInactive = true;
bool activtyDetected(IoEventType eventType);
void triggerInactive(bool inactive);
}
//----------------------------------------------------------------------
bool IoWinManagerNamespace::activtyDetected(IoEventType eventType)
{
bool modifiesInactivityState = true;
switch (eventType)
{
case IOET_KeyDown:
case IOET_KeyUp:
case IOET_JoystickMove:
case IOET_JoystickButtonDown:
case IOET_JoystickButtonUp:
case IOET_JoystickPovHat:
case IOET_MouseMove:
case IOET_MouseButtonDown:
case IOET_MouseButtonUp:
modifiesInactivityState = true;
break;
default:
modifiesInactivityState = false;
break;
}
return modifiesInactivityState;
}
//----------------------------------------------------------------------
void IoWinManagerNamespace::triggerInactive(bool inactive)
{
if (!boolEqual(s_isInactive, inactive))
{
if (s_inactivityCallback != NULL)
{
(*s_inactivityCallback)(inactive);
}
s_isInactive = inactive;
}
}
using namespace IoWinManagerNamespace;
//----------------------------------------------------------------------
bool IoWinManager::installed;
bool IoWinManager::discardInput;
#ifdef _DEBUG
bool IoWinManager::debugReportFlag;
bool IoWinManager::debugReportEvents;
#endif
IoWin *IoWinManager::top;
IoWin *IoWinManager::captured;
IoEvent *IoWinManager::firstEvent;
IoEvent *IoWinManager::lastEvent;
MemoryBlockManager *IoWinManager::eventBlockManager;
IoWinManager::IMEFunctionPointer IoWinManager::imeFunction = NULL;
// ======================================================================
// Install the IoWinManager
//
// Remarks:
//
// This routine installs the IoWinManager subsystem. It will add IoWinManager::remove()
// to the ExitChain.
//
// See Also:
//
// IoWinManager::remove()
void IoWinManager::install()
{
DEBUG_FATAL(installed, ("double install"));
top = NULL;
captured = NULL;
ExitChain::add(IoWinManager::remove, "IoWinManager::remove");
eventBlockManager = new MemoryBlockManager("IoWinManager eventBlockManager", true, sizeof(IoEvent), 0, 0, 0);
installed = true;
Os::setQueueCharacterHookFunction(queueCharacter);
Os::setSetSystemMouseCursorPositionHookFunction(queueSetSystemMouseCursorPosition);
Os::setQueueKeyDownHookFunction(queueKeyDown);
Zero(s_lastJoystickAxis);
Zero(s_lastJoystickSlider);
#ifdef _DEBUG
DebugFlags::registerFlag(debugReportFlag, "SharedIoWin", "reportIoWinManager", debugReport);
DebugFlags::registerFlag(debugReportEvents, "SharedIoWin", "reportIoWinEvents");
#endif
}
// ----------------------------------------------------------------------
/**
* Remove the IoWinManager.
*
* This routine removes the IoWinManager subststem. It should not be called
* normally by the game, but rather automatically through the ExitChain
* system.
*
* If there are any windows left on the window stack when this routine is
* called, this routine will send the IOET_WindowKill event to each window
* on the stack. If the window processEvent() routine returns a Kill result,
* the window will be deleted, otherwise it will just be closed.
*
* @see IoWinManager::install()
*/
void IoWinManager::remove(void)
{
IoResult result;
IoEvent *event;
Os::setQueueCharacterHookFunction(NULL);
Os::setSetSystemMouseCursorPositionHookFunction(NULL);
Os::setQueueKeyDownHookFunction(NULL);
DEBUG_FATAL(!installed, ("not installed"));
installed = false;
while (top)
{
// create the WindowKill event
event = newEvent(IOET_WindowKill, 0, 0, CONST_REAL(0));
result = top->processEvent(event);
deleteEvent(event);
// handle the return value
if (isKill(result))
{
IoWin *currentTop = top;
close(currentTop, false);
delete currentTop;
}
else
close(top, true);
}
delete eventBlockManager;
// Remove the inactivity timer.
registerInactivityCallback(NULL, 0.0f);
}
// ----------------------------------------------------------------------
/**
* Dump debugging information about the IoWinManager's stack.
*/
void IoWinManager::debugReport()
{
#ifdef _DEBUG
IoWin *ioWin;
DEBUG_REPORT_PRINT(true, ("IoWinManager:\n"));
if (captured)
DEBUG_REPORT_PRINT(true, (" [captured] %s\n", captured->ioDebugName));
for (ioWin = top; ioWin; ioWin = ioWin->ioNext)
DEBUG_REPORT_PRINT(true, (" %s\n", ioWin->ioDebugName));
#endif
}
// ----------------------------------------------------------------------
/**
* Pass all the queued input events to the windows on the IoWinManager.
*
* Events are passed down to the top window first, unless a capture window is
* currently set, in which case the capture window will receive the event first,
* and then it will be passed to the top window of the stack.
*
* The first routine that returns a blocking result will cause the event to
* be discarded. If there is a capture window, and it returns a blocking result,
* the event will not be passed down to the top window.
*/
void IoWinManager::processEvents(float elapsedTime)
{
IoWin * w = NULL;
IoWin * next = NULL;
IoEvent * queue = NULL;
IoEvent * event = NULL;
IoResult result;
// setup the event list to send to the windows
enqueueEvent(IOET_Update, 0, 0, elapsedTime);
queue = newEvent(IOET_Prepare, 0, 0, CONST_REAL(0));
queue->next = firstEvent;
// the event list is now empty
firstEvent = NULL;
lastEvent = NULL;
// Update the activity timer.
if (!s_isInactive)
{
bool const isInactive = s_inactivityTimer.updateNoReset(elapsedTime);
if (isInactive)
{
// Allow the timer to trigger inactive.
triggerInactive(true);
}
}
// process all the events
while (queue)
{
// remove the first element from the linked list
event = queue;
queue = queue->next;
// keep people from peeking ahead in the event queue
event->next = NULL;
// Check to see if the event resets
if (activtyDetected(event->type))
{
// No longer inactive.
triggerInactive(false);
// Reset the timer.
s_inactivityTimer.reset();
}
if (discardInput)
{
const IoEventType type = event->type;
if (
type == IOET_Character ||
type == IOET_KeyDown ||
type == IOET_KeyUp ||
type == IOET_JoystickMove ||
type == IOET_JoystickButtonDown ||
type == IOET_JoystickButtonUp ||
type == IOET_JoystickPovHat ||
type == IOET_JoystickSlider ||
type == IOET_MouseMove ||
type == IOET_MouseButtonDown ||
type == IOET_MouseButtonUp ||
type == IOET_IMEComposition ||
type == IOET_IMEChangeCandidate ||
type == IOET_IMECloseCandidate ||
type == IOET_IMEEndComposition
)
{
deleteEvent(event);
continue;
}
}
#ifdef _DEBUG
if (debugReportEvents)
{
const char *name = NULL;
switch (event->type)
{
#define CASE(a) case a: name = #a; break
CASE(IOET_WindowOpen);
CASE(IOET_WindowClose);
CASE(IOET_WindowKill);
CASE(IOET_Prepare);
CASE(IOET_Update);
CASE(IOET_InputReset);
CASE(IOET_Character);
CASE(IOET_KeyDown);
CASE(IOET_KeyUp);
CASE(IOET_JoystickMove);
CASE(IOET_JoystickButtonDown);
CASE(IOET_JoystickButtonUp);
CASE(IOET_JoystickPovHat);
CASE(IOET_JoystickSlider);
CASE(IOET_MouseMove);
CASE(IOET_MouseButtonDown);
CASE(IOET_MouseButtonUp);
CASE(IOET_SetSystemMouseCursorPosition);
CASE(IOET_IMEComposition);
CASE(IOET_IMEChangeCandidate);
CASE(IOET_IMECloseCandidate);
CASE(IOET_IMEEndComposition);
CASE(IOET_Count);
#undef CASE
default:
name = "";
DEBUG_FATAL(true, ("default case"));
break;
}
DEBUG_REPORT_PRINT(true, ("%-25s %-8d %-8d %-8.4f\n", name, event->arg1, event->arg2, event->arg3));
}
#endif
// If the user presses enter to close the candidate list, consume the enter key
if (event->type == IOET_KeyDown && imeFunction)
{
int key = event->arg2;
if(imeFunction(key))
{
deleteEvent(event);
continue;
}
}
// if there is a captured window, give it first shot at the event
if (captured)
{
result = captured->processEvent(event);
DEBUG_FATAL(isKill(result), ("captured windows can not [currently] ask to be killed"));
}
else
result = IOR_Pass;
// iterate through all the windows, passing the event down to each one
for (result = IOR_Pass, w = top; w && isPass(result); w = next)
{
// save the next window
next = w->ioNext;
// have this window process this event
result = w->processEvent(event);
// check to see if the window needs to be destroyed
if (isKill(result))
{
close(w, false);
delete w;
}
}
// free the event
deleteEvent(event);
}
discardInput = false;
}
// ----------------------------------------------------------------------
/**
* Draw the windows on the IoWinManager.
*
* This routine will call the top window's draw routine. That window is responsible
* for passing along the draw message to any other windows that it wishes to allow
* to draw.
*/
void IoWinManager::draw(void)
{
if (top)
top->draw();
}
// ----------------------------------------------------------------------
/**
* Open an IoWin.
*
* This places the specified window on the top of the IoWinManager stack.
*
* In DEBUG compiles, this routine will verify that the window is not already on the stack.
* If it is found to already be on the window stack, this routine will call Fatal. This check
* is not done in RELEASE compiles, and may corrupt the stack.
*
* @param window Window to place on top of the window stack
* @see IoWinManager::close()
*/
void IoWinManager::open(IoWin *window)
{
IoEvent *event;
IoResult result;
// validate the arguments
if (!window)
{
DEBUG_FATAL(true, ("null window"));
return; //lint !e527 // Warning -- Unreachable
}
#ifdef _DEBUG
// make sure the window isn't already on the window stack
IoWin *w;
for (w = top; w && w != window; w = w->ioNext)
;
DEBUG_FATAL(w == window, ("window already open"));
#endif
// put the window on top of the window stack
window->ioNext = top;
top = window;
// send the window an open event
event = newEvent(IOET_WindowOpen, 0, 0, CONST_REAL(0));
result = top->processEvent(event);
deleteEvent(event);
// handle the window wanting to die immediately
if (isKill(result))
{
close(top, false);
delete top;
}
}
// ----------------------------------------------------------------------
/**
* Close a window.
*
* This routine will remove the specified window from the window stack.
*
* This routine will send the IOET_WindowClose message to the window.
* If the window's processEvent() routine returns a Kill result, the
* routine will delete the window.
*
* In DEBUG compiles, if the window is not on the window stack, this routine will
* call Fatal. In RELEASE compiles, this routine will simply return if the window
* is not on the window stack.
*
* @param window Window to remove from the window stack
*/
void IoWinManager::close(IoWin *window)
{
close(window, true);
}
// ----------------------------------------------------------------------
/**
* Close a window.
*
* This routine will remove the specified window from the window stack.
*
* This routine will send the IOET_WindowClose message to the window.
* If the window's processEvent() routine returns a Kill result, the
* routine will delete the window only if the allowDelete flag is true.
*
* In DEBUG compiles, if the window is not on the window stack, this routine will
* call Fatal. In RELEASE compiles, this routine will simply return if the window
* is not on the window stack.
*
* @param window Window to remove from the window stack
* @param allowDelete Whether to allow the routine to delete the window or not
*/
void IoWinManager::close(IoWin *window, bool allowDelete)
{
// validate the arguments
if (!window)
{
DEBUG_FATAL(true, ("null window"));
return; //lint !e527 // Warning -- Unreachable
}
// linked list traversal with a back pointer
IoWin *back, *front;
for (back = NULL, front = top; front && front != window; back = front, front = front->ioNext)
;
// verify the window was found
if (front != window)
{
DEBUG_FATAL(true, ("window not found %p %s", window, window->ioDebugName));
return; //lint !e527 // Warning -- Unreachable
}
// -qq- lint hack
DEBUG_FATAL(!window, ("null window"));
// remove it from the singly linked list
if (back)
back->ioNext = window->ioNext;
else
top = window->ioNext;
// send the window a close event
IoEvent *event = newEvent(IOET_WindowClose, 0, 0, CONST_REAL(0));
const IoResult result = window->processEvent(event);
deleteEvent(event);
// handle the window wanting to die immediately
if (allowDelete && isKill(result))
delete window;
}
// ----------------------------------------------------------------------
/**
* Allocate and fill out a new event structure.
*
* This routine is used to create new events. Events created with this
* routine must be deleted calling deleteEvent().
*
* @param eventType Event type to be created
* @param arg1 Event-type dependent argument value
* @param arg2 Event-type dependent argument value
* @param arg3 Event-type dependent argument value
* @see IoWinManager::deleteEvent()
*/
IoEvent *IoWinManager::newEvent(IoEventType eventType, int arg1, int arg2, real arg3)
{
// create the new event
IoEvent * const event = reinterpret_cast<IoEvent *>(eventBlockManager->allocate());
// fill out the event data
event->next = NULL;
event->type = eventType;
event->arg1 = arg1;
event->arg2 = arg2;
event->arg3 = arg3;
return event;
}
// ----------------------------------------------------------------------
/**
* Free an event.
*
* The event must have been allocated with newEvent().
*
* @see IoWinManager::newEvent()
*/
void IoWinManager::deleteEvent(IoEvent *event)
{
eventBlockManager->free(event);
}
// ----------------------------------------------------------------------
/**
* Create a new event and add it to the event list.
*
* This routine is an internal helper routine designed to make creating a new event easier.
*
* @param eventType Event type to be created
* @param arg1 Event-type dependent argument value
* @param arg2 Event-type dependent argument value
* @param arg3 Event-type dependent argument value
*/
void IoWinManager::enqueueEvent(IoEventType eventType, int arg1, int arg2, real arg3)
{
switch (eventType)
{
case IOET_JoystickMove:
if (arg1 >= 0 && arg1 < s_numJoysticks && arg2 >= 0 && arg2 < s_numJoystickAxes)
{
if (s_discardIdenticalJoystickMotionEvents &&
WithinEpsilonExclusive(arg3, s_lastJoystickAxis[arg1][arg2], s_joystickAxisIdenticalThreshold))
{
return;
}
s_lastJoystickAxis[arg1][arg2] = arg3;
}
break;
case IOET_JoystickSlider:
if (arg1 >= 0 && arg1 < s_numJoysticks && arg2 >= 0 && arg2 < s_numJoystickSliders)
{
if (s_discardIdenticalJoystickMotionEvents &&
WithinEpsilonExclusive(arg3, s_lastJoystickSlider[arg1][arg2], s_joystickSliderIdenticalThreshold))
{
return;
}
s_lastJoystickSlider[arg1][arg2] = arg3;
}
break;
case IOET_WindowOpen:
case IOET_WindowClose:
case IOET_WindowKill:
case IOET_Prepare:
case IOET_Update:
case IOET_InputReset:
case IOET_Character:
case IOET_KeyDown:
case IOET_KeyUp:
case IOET_JoystickButtonDown:
case IOET_JoystickButtonUp:
case IOET_JoystickPovHat:
case IOET_MouseMove:
case IOET_MouseButtonDown:
case IOET_MouseButtonUp:
case IOET_SetSystemMouseCursorPosition:
case IOET_Count:
case IOET_IMEComposition:
case IOET_IMEChangeCandidate:
case IOET_IMECloseCandidate:
case IOET_IMEEndComposition:
break;
}
// create the new event
IoEvent * const event = newEvent(eventType, arg1, arg2, arg3);
// put on the singly linked list
if (!firstEvent)
firstEvent = event;
else
lastEvent->next = event;
lastEvent = event;
}
//----------------------------------------------------------------------
void IoWinManager::setDiscardIdenticalJoystickMotionEvents(bool b)
{
s_discardIdenticalJoystickMotionEvents = b;
}
//----------------------------------------------------------------------
bool IoWinManager::isDiscardIdenticalJoystickMotionEvents()
{
return s_discardIdenticalJoystickMotionEvents;
}
//----------------------------------------------------------------------
void IoWinManager::registerIMEFunction(IMEFunctionPointer imeFunctionIn)
{
DEBUG_FATAL(imeFunction, ("IoWinManager: 2 IME functions registered"));
imeFunction = imeFunctionIn;
}
//----------------------------------------------------------------------
void IoWinManager::registerInactivityCallback(InactivityCallback callback, float timeInSeconds = 1.0f)
{
if (s_inactivityCallback != callback)
{
// Set the activity timer.
if (timeInSeconds > 0.0f)
{
s_inactivityTimer.setExpireTime(timeInSeconds);
}
s_inactivityTimer.reset();
// Set the new callback.
s_inactivityCallback = callback;
}
}
//----------------------------------------------------------------------
bool IoWinManager::isInactive(void)
{
return s_isInactive;
}
// ======================================================================
@@ -0,0 +1,628 @@
// ======================================================================
//
// IoWinManager.h
// Portions copyright 1998 Bootprint Entertainment
// Portions copyright 2002 Sony Online Entertainment
// All Rights Reserved.
//
// ======================================================================
#ifndef INCLUDED_IoWinManager_H
#define INCLUDED_IoWinManager_H
// ======================================================================
#include "sharedIoWin/IoWin.def"
class IoWin;
class MemoryBlockManager;
// ======================================================================
class IoWinManager
{
typedef bool (*IMEFunctionPointer)(int key);
public:
static bool installed;
static bool discardInput;
#ifdef _DEBUG
static bool debugReportFlag;
static bool debugReportEvents;
#endif
static IoWin *top;
static IoWin *captured;
static IoEvent *firstEvent;
static IoEvent *lastEvent;
static MemoryBlockManager *eventBlockManager;
static IMEFunctionPointer imeFunction;
private:
static IoEvent *newEvent(IoEventType eventType, int arg1, int arg2, real arg3);
static void deleteEvent(IoEvent *event);
static void enqueueEvent(IoEventType eventType, int arg1, int arg2, real arg3);
static void close(IoWin *window, bool allowDelete);
protected:
// disabled
IoWinManager(void);
IoWinManager(const IoWinManager &);
IoWinManager &operator =(const IoWinManager &);
public:
static void install();
static void remove(void);
static void debugReport();
static void processEvents(float elapsedTime);
static void draw(void);
static bool isPass(IoResult result);
static bool isBlock(IoResult result);
static bool isKill(IoResult result);
static bool haveWindow(void);
static void open(IoWin *window);
static void close(IoWin *window);
static void discardUserInputUntilNextProcessEvents();
static void setDiscardIdenticalJoystickMotionEvents(bool b);
static bool isDiscardIdenticalJoystickMotionEvents();
static void queueInputReset(void);
static void queueCharacter(int keyboard, int character);
static void queueKeyDown(int keyboard, int key);
static void queueKeyUp(int keyboard, int key);
static void queueMouseButtonDown(int mouse, int mouseButton);
static void queueMouseButtonUp(int mouse, int mouseButton);
static void queueMouseTranslateX(int mouse, real value);
static void queueMouseTranslateY(int mouse, real value);
static void queueMouseTranslateZ(int mouse, real value);
static void queueMouseRotateX(int mouse, real value);
static void queueMouseRotateY(int mouse, real value);
static void queueMouseRotateZ(int mouse, real value);
static void queueJoystickTranslateX(int joystick, real value);
static void queueJoystickTranslateY(int joystick, real value);
static void queueJoystickTranslateZ(int joystick, real value);
static void queueJoystickRotateX(int joystick, real value);
static void queueJoystickRotateY(int joystick, real value);
static void queueJoystickRotateZ(int joystick, real value);
static void queueJoystickPOVHatCentered(int joystick, int hat);
static void queueJoystickPOVHatOffset(int joystick, int hat, real value);
static void queueJoystickButtonDown(int joystick, int mouseButton);
static void queueJoystickButtonUp(int joystick, int mouseButton);
static void queueJoystickSlider(int joystick, int slider, real value);
static void queueSetSystemMouseCursorPosition(int x, int y);
static void queueIMEComposition(void);
static void queueIMEChangeCandidate(void);
static void queueIMECloseCandidate(void);
static void queueIMEEndComposition(void);
static void registerIMEFunction(IMEFunctionPointer imeFunctionIn);
typedef bool (*InactivityCallback)(bool inactive);
static void registerInactivityCallback(InactivityCallback callback, float timeInSeconds);
static bool isInactive(void);
};
// ======================================================================
// Determine if any windows are currently on the window stack
//
// Return value:
//
// True if any windows are on the IoWinManager's stack, false otherwise
//
// Remarks:
//
// The game may want to terminate if no windows are open on the IoWinManager.
inline bool IoWinManager::haveWindow(void)
{
return (top != NULL);
}
// ----------------------------------------------------------------------
/** Discard user input.
*
* This routine will cause the next call to processEvents() to ignore all
* user input events (keyboard, mouse, and joystick).
*/
inline void IoWinManager::discardUserInputUntilNextProcessEvents()
{
discardInput = true;
}
// ----------------------------------------------------------------------
/**
* Enqueue a character press.
*
* This adds a input-reset event to the queue. That event indicates that
* the input devices are now in unknown state and any previous state is
* invalid.
*
* @return Pointer to the event that was enqueued
*/
inline void IoWinManager::queueInputReset(void)
{
enqueueEvent(IOET_InputReset, 0, 0, 0.0f);
}
// ----------------------------------------------------------------------
/**
* Enqueue a character press.
*
* This adds a typeable character to the input queue. The character should already
* have any necessary shifting applied to it. The characters should be read for
* text input, not for key presses.
*
* @param keyboard Keyboard that generated the character
* @param character Character to be enqueued
* @return Pointer to the event that was enqueued
* @see IoWinManager::queueKeyPress()
*/
inline void IoWinManager::queueCharacter(int keyboard, int character)
{
enqueueEvent(IOET_Character, keyboard, character, 0.0f);
}
// ----------------------------------------------------------------------
/**
* Enqueue a key down.
*
* This adds a keyboard key press to the input queue. Events of this type should
* not be used for string entry.
*
* @param keyboard Keyboard that generated the character
* @param key Key that was pressed
* @return Pointer to the event that was enqueued
*/
inline void IoWinManager::queueKeyDown(int keyboard, int key)
{
enqueueEvent(IOET_KeyDown, keyboard, key, 0.0f);
}
// ----------------------------------------------------------------------
/**
* Enqueue a key up message.
*
* This adds a keyboard key release to the input queue.
*
* @param keyboard Keyboard that generated the character
* @param key Key that was released
* @return Pointer to the event that was enqueued
*/
inline void IoWinManager::queueKeyUp(int keyboard, int key)
{
enqueueEvent(IOET_KeyUp, keyboard, key, 0.0f);
}
// ----------------------------------------------------------------------
/**
* Enqueue a mouse button down message.
*
* This adds a mouse button down to the input queue.
*
* @param mouse Mouse that generated this event
* @param mouseButton Mouse button that was pressed
* @return Pointer to the event that was enqueued
*/
inline void IoWinManager::queueMouseButtonDown(int mouse, int mouseButton)
{
enqueueEvent(IOET_MouseButtonDown, mouse, mouseButton, 0.0f);
}
// ----------------------------------------------------------------------
/**
* Enqueue a mouse button up message.
*
* This adds a mouse button up to the input queue.
*
* @param mouse Mouse that generated this event
* @param mouseButton Mouse button that was released
* @return Pointer to the event that was enqueued
*/
inline void IoWinManager::queueMouseButtonUp(int mouse, int mouseButton)
{
enqueueEvent(IOET_MouseButtonUp, mouse, mouseButton, 0.0f);
}
// ----------------------------------------------------------------------
/**
* Enqueue a mouse x translation message.
*
* This adds a message indicating that the mouse moved in the X direction.
*
* @param mouse Mouse that generated this event
* @param offset Distance the mouse moved in the X direction
* @return Pointer to the event that was enqueued
*/
inline void IoWinManager::queueMouseTranslateX(int mouse, real offset)
{
enqueueEvent(IOET_MouseMove, mouse, IOMT_TranslateX, offset);
}
// ----------------------------------------------------------------------
/**
* Enqueue a mouse y translation message.
*
* This adds a message indicating that the mouse moved in the Y direction.
*
* @param mouse Mouse that generated this event
* @param offset Distance the mouse moved in the Y direction
* @return Pointer to the event that was enqueued
*/
inline void IoWinManager::queueMouseTranslateY(int mouse, real offset)
{
enqueueEvent(IOET_MouseMove, mouse, IOMT_TranslateY, offset);
}
// ----------------------------------------------------------------------
/**
* Enqueue a mouse z translation message.
*
* This adds a message indicating that the mouse moved in the Z direction.
*
* @param mouse Mouse that generated this event
* @param offset Distance the mouse moved in the Z direction
* @return Pointer to the event that was enqueued
*/
inline void IoWinManager::queueMouseTranslateZ(int mouse, real offset)
{
enqueueEvent(IOET_MouseMove, mouse, IOMT_TranslateZ, offset);
}
// ----------------------------------------------------------------------
/**
* Enqueue a mouse x rotation message.
*
* This adds a message indicating that the mouse rotated around the X axis
*
* @param mouse Mouse that generated this event
* @param offset Amount the mouse rotated around the X axis
* @return Pointer to the event that was enqueued
*/
inline void IoWinManager::queueMouseRotateX(int mouse, real offset)
{
enqueueEvent(IOET_MouseMove, mouse, IOMT_RotateX, offset);
}
// ----------------------------------------------------------------------
/**
* Enqueue a mouse y rotation message.
*
* This adds a message indicating that the mouse rotated around the YX axis
*
* @param mouse Mouse that generated this event
* @param offset Amount the mouse rotated around the Y axis
* @return Pointer to the event that was enqueued
*/
inline void IoWinManager::queueMouseRotateY(int mouse, real offset)
{
enqueueEvent(IOET_MouseMove, mouse, IOMT_RotateY, offset);
}
// ----------------------------------------------------------------------
/**
* Enqueue a mouse z rotation message.
*
* This adds a message indicating that the mouse rotated around the Z axis
*
* @param mouse Mouse that generated this event
* @param offset Amount the mouse rotated around the Y axis
* @return Pointer to the event that was enqueued
*/
inline void IoWinManager::queueMouseRotateZ(int mouse, real offset)
{
enqueueEvent(IOET_MouseMove, mouse, IOMT_RotateZ, offset);
}
// ----------------------------------------------------------------------
/**
* Enqueue a joystick x translation message.
*
* This adds a message indicating that the joystick offset in the X direction
*
* @param joystick Joystick that generated this event
* @param offset Joystick offset in the X direction
* @return Pointer to the event that was enqueued
*/
inline void IoWinManager::queueJoystickTranslateX(int joystick, real offset)
{
enqueueEvent(IOET_JoystickMove, joystick, IOMT_TranslateX, offset);
}
// ----------------------------------------------------------------------
/**
* Enqueue a joystick y translation message.
*
* This adds a message indicating that the joystick offset in the Y direction
*
* @param joystick Joystick that generated this event
* @param offset Joystick offset in the Y direction
* @return Pointer to the event that was enqueued
*/
inline void IoWinManager::queueJoystickTranslateY(int joystick, real offset)
{
enqueueEvent(IOET_JoystickMove, joystick, IOMT_TranslateY, offset);
}
// ----------------------------------------------------------------------
/**
* Enqueue a joystick z translation message.
*
* This adds a message indicating that the joystick offset in the Z direction
*
* @param joystick Joystick that generated this event
* @param offset Joystick offset in the Z direction
* @return Pointer to the event that was enqueued
*/
inline void IoWinManager::queueJoystickTranslateZ(int joystick, real offset)
{
enqueueEvent(IOET_JoystickMove, joystick, IOMT_TranslateZ, offset);
}
// ----------------------------------------------------------------------
/**
* Enqueue a joystick x rotation message.
*
* This adds a message indicating that the joystick offset around the X axis
*
* @param joystick Joystick that generated this event
* @param offset Joystick offset around the X axis
* @return Pointer to the event that was enqueued
*/
inline void IoWinManager::queueJoystickRotateX(int joystick, real offset)
{
enqueueEvent(IOET_JoystickMove, joystick, IOMT_RotateX, offset);
}
// ----------------------------------------------------------------------
/**
* Enqueue a joystick y rotation message.
*
* This adds a message indicating that the joystick offset around the Y axis
*
* @param joystick Joystick that generated this event
* @param offset Joystick offset around the Y axis
* @return Pointer to the event that was enqueued
*/
inline void IoWinManager::queueJoystickRotateY(int joystick, real offset)
{
enqueueEvent(IOET_JoystickMove, joystick, IOMT_RotateY, offset);
}
// ----------------------------------------------------------------------
/**
* Enqueue a joystick z rotation message.
*
* This adds a message indicating that the joystick offset around the Z axis
*
* @param joystick Joystick that generated this event
* @param offset Joystick offset around the Z axis
* @return Pointer to the event that was enqueued
*/
inline void IoWinManager::queueJoystickRotateZ(int joystick, real offset)
{
enqueueEvent(IOET_JoystickMove, joystick, IOMT_RotateZ, offset);
}
// ----------------------------------------------------------------------
/**
* Enqueue a POV hat centered message.
*
* This adds a message indicating that the specified POV hat is centered.
* The offset for a centered hat is -1.
*
* @param joystick Joystick that generated this event
* @param hat POV hat that is centered
* @return Pointer to the event that was enqueued
*/
inline void IoWinManager::queueJoystickPOVHatCentered(int joystick, int hat)
{
enqueueEvent(IOET_JoystickPovHat, joystick, hat, CONST_REAL(-1));
}
// ----------------------------------------------------------------------
/**
* Enqueue a POV hat offset message.
*
* This adds a message indicating that the specified POV hat is offset.
* The offset goes from 0 to 2*Pi.
*
* @param joystick Joystick that generated this event
* @param hat POV hat that is offset
* @param value Offset from 0 to 2*Pi
* @return Pointer to the event that was enqueued
*/
inline void IoWinManager::queueJoystickPOVHatOffset(int joystick, int hat, real value)
{
enqueueEvent(IOET_JoystickPovHat, joystick, hat, value);
}
// ----------------------------------------------------------------------
/**
* Enqueue a joystick button down message.
*
* This adds a message indicating that the specified joystick button was
* pressed.
*
* @param joystick Joystick that generated this event
* @param joystickButton Joystick button that was pressed
* @return Pointer to the event that was enqueued
*/
inline void IoWinManager::queueJoystickButtonDown(int joystick, int joystickButton)
{
enqueueEvent(IOET_JoystickButtonDown, joystick, joystickButton, 0.0f);
}
// ----------------------------------------------------------------------
/**
* Enqueue a joystick button up message.
*
* This adds a message indicating that the specified joystick button was
* released.
*
* @param joystick Joystick that generated this event
* @param joystickButton Joystick button that was released
* @return Pointer to the event that was enqueued
*/
inline void IoWinManager::queueJoystickButtonUp(int joystick, int joystickButton)
{
enqueueEvent(IOET_JoystickButtonUp, joystick, joystickButton, 0.0f);
}
// ----------------------------------------------------------------------
inline void IoWinManager::queueJoystickSlider(int joystick, int slider, real value)
{
enqueueEvent(IOET_JoystickSlider, joystick, slider, value);
}
// ----------------------------------------------------------------------
inline void IoWinManager::queueSetSystemMouseCursorPosition(int x, int y)
{
enqueueEvent(IOET_SetSystemMouseCursorPosition, x, y, 0.0f);
}
// ----------------------------------------------------------------------
/**
* Enqueue an IME Composition message
*
* This adds a message indicating that the current IME composition has changed
*
*/
inline void IoWinManager::queueIMEComposition(void)
{
enqueueEvent(IOET_IMEComposition, 0, 0, 0.0f);
}
// ----------------------------------------------------------------------
/**
* Enqueue an IME Change Candidate message
*
* This adds a message indicating that the candidate list has changed
*
*/
inline void IoWinManager::queueIMEChangeCandidate(void)
{
enqueueEvent(IOET_IMEChangeCandidate, 0, 0, 0.0f);
}
// ----------------------------------------------------------------------
/**
* Enqueue an IME Close Candidate message
*
* This adds a message indicating that candidate list has been closed
*
*/
inline void IoWinManager::queueIMECloseCandidate(void)
{
enqueueEvent(IOET_IMECloseCandidate, 0, 0, 0.0f);
}
// ----------------------------------------------------------------------
/**
* Enqueue a joystick button down message.
*
* This adds a message indicating that the specified joystick button was
* pressed.
*
* @param joystick Joystick that generated this event
* @param joystickButton Joystick button that was pressed
* @return Pointer to the event that was enqueued
*/
inline void IoWinManager::queueIMEEndComposition(void)
{
enqueueEvent(IOET_IMEEndComposition, 0, 0, 0.0f);
}
// ----------------------------------------------------------------------
/**
* Determine if a IoResult is a pass result.
*
* This routine tests a single bit in the result to check if it is a pass value.
*
* @return True if the result is IOR_Pass or IOR_PassKillMe, false otherwise
* @see IoWinManager::isBlock(), IoWinManager::isKill()
*/
inline bool IoWinManager::isPass(IoResult result)
{
return (static_cast<int>(result) & IOR_PASS_BIT) != 0;
}
// ----------------------------------------------------------------------
/**
* Determine if a IoResult is a block result.
*
* This routine tests a single bit in the result to check if it is a block value.
*
* @return True if the result is IOR_Block or IOR_BlockKillMe, false otherwise
* @see IoWinManager::isPass(), IoWinManager::isKill()
*/
inline bool IoWinManager::isBlock(IoResult result)
{
return (static_cast<int>(result) & IOR_BLOCK_BIT) != 0;
}
// ----------------------------------------------------------------------
/**
* Determine if a IoResult is a kill result.
*
* This routine tests a single bit in the result to check if it is a kill value.
*
* @return True if the result is IOR_PassKillMe or IOR_BlockKillMe, false otherwise
* @see IoWinManager::isPass(), IoWinManager::isBlock()
*/
inline bool IoWinManager::isKill(IoResult result)
{
return (static_cast<int>(result) & IOR_KILL_BIT) != 0;
}
// ======================================================================
#endif
@@ -0,0 +1,25 @@
// ======================================================================
//
// SetupSharedIoWin.cpp
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#include "sharedIoWin/FirstSharedIoWin.h"
#include "sharedIoWin/SetupSharedIoWin.h"
#include "sharedDebug/InstallTimer.h"
#include "sharedIoWin/ConfigSharedIoWin.h"
#include "sharedIoWin/IoWinManager.h"
// ======================================================================
void SetupSharedIoWin::install()
{
InstallTimer const installTimer("SetupSharedIoWin::install");
ConfigSharedIoWin::install();
IoWinManager::install();
}
// ======================================================================
@@ -0,0 +1,28 @@
// ======================================================================
//
// SetupSharedIoWin.h
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#ifndef INCLUDED_SetupSharedIoWin_H
#define INCLUDED_SetupSharedIoWin_H
// ======================================================================
class SetupSharedIoWin
{
public:
static void install();
private:
SetupSharedIoWin();
SetupSharedIoWin(const SetupSharedIoWin &);
SetupSharedIoWin &operator =(const SetupSharedIoWin &);
};
// ======================================================================
#endif
@@ -0,0 +1,8 @@
// ======================================================================
//
// FirstIoWin.cpp
// copyright (c) 2001 Sony Online Entertainment
//
// ======================================================================
#include "sharedIoWin/FirstSharedIoWin.h"