Mercurial > projects > mde
diff mde/input/core.d @ 0:d547009c104c
Repository creation.
committer: Diggory Hardy <diggory.hardy@gmail.com>
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Sat, 27 Oct 2007 18:05:39 +0100 |
parents | |
children | 78eb491bd642 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mde/input/core.d Sat Oct 27 18:05:39 2007 +0100 @@ -0,0 +1,60 @@ +/// This module contains the core (i.e. common part) of the input system. +module mde.input.core; +/+ +alias Exception InputException; // this can be expanded to a custom class if needed +typedef uint index_t; +struct RelPair { + real x, y; + static RelPair opCall (real a, real b) { + RelPair ret; + ret.x = a; ret.y = b; + return ret; + } +} + +/* Note: We really want an array, not a stack. We cannot edit these lists, so we can either +* copy the stack or just iterate through it as an array. +*/ +typedef uint[] outQueue; /// This is the type for the out queue config data. +struct readOutQueue { /// A convenient structure for reading an outQueue item by item. + private outQueue _q; // the queue, stored by reference to the original + private uint p = 0; // current read position (start at beginning) + + static readOutQueue (outQueue q) { /// Static constructor + readOutQueue ret; + ret._q = q; + return ret; + } + uint next () { /// Get the next element. Throws an exception if there isn't another. + if (p >= _q.length()) + throw new InputException ("Input: Invalid configuration: incomplete config stack"); + uint ret = _q[p]; + ++p; + return ret; + } +} +/+ +struct out_stack { // a remove-only stack with exception throwing + uint[] _data; + + static out_stack opCall (uint[] d) { + out_stack ret; + ret._data = d; + return ret; + } + uint pop () { + if (_data.length < 1) + throw new InputException ("Input: Invalid configuration: incomplete config stack"); + uint a = _data[length - 1]; + _data.length = _data.length - 1; + return a; + } +} ++/ + +bool[index_t] b_tbl; /// Table of button states +real[index_t] axis_tbl; /// Table of axes states +uint mouse_x, mouse_y; /// Current screen coords of the mouse +// FIXME: these need to be reset after every access: +RelPair[index_t] axis_rel_tbl; /// Table of relative mouse / joystick ball motions ++/ \ No newline at end of file