Mercurial > projects > mde
changeset 5:76d0adc92f2e
Removed non-existant files not removed in 3e58aaf3c6d4c0e1a63441dd859af433aa15c5ff.
committer: Diggory Hardy <diggory.hardy@gmail.com>
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Sun, 06 Jan 2008 17:47:11 +0000 |
parents | 9a990644948c |
children | dcb24afa0dce |
files | mde/input/core.d mde/input/eventstream.d mde/mergetag/dataset.d.old |
diffstat | 3 files changed, 0 insertions(+), 302 deletions(-) [+] |
line wrap: on
line diff
--- a/mde/input/core.d Sun Jan 06 17:38:51 2008 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,59 +0,0 @@ -/// 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 opCall (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
--- a/mde/input/eventstream.d Sun Jan 06 17:38:51 2008 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,94 +0,0 @@ -/** This module contains functions called on an event, which may modify the event (adjuster - * functions), and finally output to one (or more) of the state tables (the event stream). - * - * Adjuster and other event functions should have a format to fit the ES_X_Func types, for X is B - * (button event), A (axis event) or M (mouse relative motion event or joystick ball event). - * Adjusters should call (an) output function(s) of any type with their output(s). - * - * To control which adjusters get called and pass parameters, a stack is used. - */ -module mde.input.eventstream; - -// package imports -import mde.input.core; - -/// Module constructor fills es_*_fcts tables and rehashes them. -static this () { - es_b_fcts[ES_B_OUT] = &es_b_out; - - // Call rehash following initialisation: - es_b_fcts.rehash; - es_a_fcts.rehash; - es_m_fcts.rehash; -} - -/// These aliases are for pointers to the event functions. -alias void function (bool, readOutQueue) ES_B_Func; -alias void function (short, readOutQueue) ES_A_Func; /// ditto -alias void function (short, short, readOutQueue) ES_M_Func; /// ditto - -/// These are the tables for looking up which event function to call. -static ES_B_Func[uint] es_b_fcts; -static ES_A_Func[uint] es_a_fcts; /// ditto -static ES_M_Func[uint] es_m_fcts; /// ditto - -/// These are the codes allowing the config to specify event functions: -enum : uint { - ES_B_OUT = 0x0000_0100u, - ES_A_OUT = 0x0000_0200u, - ES_M_OUT = 0x0000_0300u, -} - -/// Functions to pass an event to the appropriate event function -void bEventOut (bool b, readOutQueue s) -{ - ES_B_Func* func = (s.next() in es_b_fcts); - if (func != null) (*func)(b,s); - else throw new InputException ("Input: Invalid configuration: bad event function code"); -} -void aEventOut (short x, readOutQueue s) /// ditto -{ - ES_A_Func* func = (s.next() in es_a_fcts); - if (func != null) (*func)(x,s); - else throw new InputException ("Input: Invalid configuration: bad event function code"); -} -void mEventOut (short x, short y, readOutQueue s) /// ditto -{ - ES_M_Func* func = (s.next() in es_m_fcts); - if (func != null) (*func)(x,y,s); - else throw new InputException ("Input: Invalid configuration: bad event function code"); -} - -/// Simple output function -void es_b_out (bool b, readOutQueue s) { - b_tbl[cast(index_t) s.next()] = b; -} -/// Adjuster to check modifier keys -void es_b_modifier (bool b, readOutQueue s); - -/** Simple output function - -Adds 1-2 items on the stack. -*/ -void es_a_out (short x, readOutQueue s) { - real y = x; - uint conf = s.next(); - enum : uint { - HALF_RANGE = 0x8000_0000u, - SENSITIVITY = 0x0080_0000u, - } - // Convert ranges into standard intervals (with or without reverse values) - if (conf & HALF_RANGE) y = (y + 32767.0) * 1.5259254737998596e-05; // range 0.0 - 1.0 - else y *= 3.0518509475997192e-05; // range -1.0 - 1.0 - real a; - if (conf & SENSITIVITY) a = s.next(); - /+ When a global sensitivity is available (possibly only use if it's enabled)... - else a = axis.sensitivity; - y = sign(y) * pow(abs(y), a); // sensitivity adjustment by a +/ - axis_tbl[cast(index_t) s.next()] = y; -} - -/// Simple output function -void es_m_out (short x, short y, readOutQueue s) { - axis_rel_tbl[cast(index_t) s.next()] = RelPair(x,y); -}
--- a/mde/mergetag/dataset.d.old Sun Jan 06 17:38:51 2008 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,149 +0,0 @@ -/// This file contains text removed from dataset.d, which might possibly still be useful. - -/** - Class for exceptions of type "Incorrect Type" thrown when trying to read an item. Identical use to class Exception, but provides an easy way to handle only exceptions of this type. -*/ -class IncorrectType : Exception { - this (char[] s) { - super(s); - } -} - -/** - Data class; contains a Data member for each loaded section of a file. - - Could be a struct, except structs are value types (not reference). -*/ -class DataSet -{ -/+ Data[SecID] sec; /// Dynamic array of section data +/ - void*[char[]][char[]] data; - - void*[char[]] opIndex(char[] i) { - return data[i]; - } - void*[char[]][char[]] opSlice() { - return data[]; - } - void*[char[]][char[]] opSlice(char[] i, char[] j) { - return data[i,j]; - } -} - -struct Item { - enum Type : ubyte { - _void = 0, // initial type - tuple, dynlist, - _bool, _byte, _ubyte, _short, _ushort, _int, _uint, _long, _ulong, _cent, _ucent, - _char, _wchar, _dchar; - _float, _double, _real, - _ifloat, _idouble, _ireal, - _cfloat, _cdouble, _creal - } - static char[][26] typeName = ["void","tuple",]; - Type type; - new union { - Tuple tuple; - DynList dynlist; -// DynMerge dynmerge; merging lists are stored as dynamic lists - bool _bool; - byte _byte; - ubyte _ubyte; - short _short; - ushort _ushort; - int _int; - uint _uint; - long _long; - ulong _ulong; - cent _cent; - ucent _ucent; - char _char; - wchar _wchar; - dchar _dchar; - float _float; - double _double; - real _real; - ifloat _ifloat; - idouble _idouble; - ireal _ireal; - cfloat _cfloat; - cdouble _cdouble; - creal _creal; - } - - /** Functions to get data - - Each function will, if the element is of the appropriate type, return the element; if the type - is incorrect it will throw an error. - */ - bool _bool () { - if (type != _bool) throw new IncorrectType("Incorrect type when trying to read: tried to read as bool when item had type " ~ typeName[type]); - return _bool; - } - int _int () { /// ditto - if (type != _int) throw new IncorrectType("Incorrect type when trying to read: tried to read as int"); - return _int; - } - uint _uint () { /// ditto - if (type != _uint) throw new IncorrectType("Incorrect type when trying to read: tried to read as uint"); - return _uint; - } -} - -struct DynList -{ - -} - -class Data -{ - // added & accessed soley by templates - private (uint,void*)[Index] _gd; // generic data -} - -// Externally, types are given as a string: -typedef char[] typeIDstr; - private: -// Internally, types are given by a uint for performance: -typedef uint typeID; -typeID[typeIDstr] typeIDTable; // used to look up type typeID - -// This (belongs in read.d) contains a table of reading functions for all supported types. Do similarly for writing. -(void function (Data, char[]))[typeID] genericReader; - -// Template function for creating a function to read a new type and adding it to genericReader: -/+ don't actually use this without specialization -void addSupport (T) () { - // create a function to read this type from a string and add it into Data.genericData as type void*; put a function pointer into generic Reader - // do same for write support - // create a reader function, accessible by the user of the library, for accessing elements/converting to the proper type -}+/ - -/** - Get data of the appropriate type. - - The function performs a check that the data is of the appropriate type and throws an exception if - not. - - Note: can be called as d.get!($(I type))(i). -*/ -get(T : int) (Data d, Index i) { - return cast(T) *d._gd[i]; -} - -// add support for basic types (for all basic types): -void addSupport (T : int) () { - T read_int (char[]); - void* get_voidp (T d) { - return cast(void*) &d; - } -} - -void addSupport (T : T[]) () { // for any array type - // reader: split input and call appropriate fct to convert sub-strings to type T - // writer: use appropriate fct to convert to substrings; concat into "[val1,val2,...,valn]" format - // access: store as void* to T[] and something like this: - T[] get(Data d, Index i) { // but cannot overload by return-type! - return cast(T[]) genericData[i] - } -}