About Store Forum Documentation Contact
Donations:
158$/mo



Post Reply 
Configurations (& Input example)
Author Message
BlackHornet Offline
Member

Post: #1
Configurations (& Input example)
--------------------

Configuration System
My first code contribution, comments are welcome!



.7z  EEConfigSystem.7z (Size: 5.29 KB / Downloads: 40)

Last Updated: 09/17/11


Config System Overview:
I created this configuration system, because I wasn't satisfied with the current approach and its integration examples in the EE tutorials. In addition I thought about an input class that manages and evaluate device inputs being mapped to certain function commands.
I wanted to create a small framework: easy to understand, flexible in use.

Features:
  • Easy to implement using an "Interface" (c++ abstract class) providing the minimum function set to be implemented with ease
  • Complete example of a PlayerInput class with Forward, Backward, TurnLeft and TurnRight command bind

Known issues:
  • The evaluation of the keyboard inputs are not yet finished, returning the flags for "button on", "button pushed", "button released", "button double clicked" are not fully supported at the moment.


------------------------------

Example Main.es:
Code:
//*****************************************************************************/
//
// File : Main.es
// Date : 16.09.2011
// Autor : Sebastian Schlicht
//
// Description :
//    Main game loop.
//
// Changes :
//    <SC> - <16.09.2011>: Created
//
//*****************************************************************************/

PlayerInput input;

/******************************************************************************/
void InitPre()
{
   App.name("Configuration & Input");
   DataPath("../../Data");
   Paks.add("engine.pak");
  
   D.mode(800,600).sync(true).viewRange(200);
}

bool Init()
{
   // Load configuration of PlayerInput
   input.cLoad();
  
   // Direct save, to create a file if it doesn't exist yet
   input.cSave();
  
   return true;
}

void Shut()
{
}

/******************************************************************************/
bool Update()
{
   // Update PlayerInput and read input variables from input devices
   input.updateInput();

   return true;
}

void Draw()
{
   D      .clear();

   D.text(0, 0.5, Str("Forward command: ") + input.forward());
   D.text(0, 0.4, Str("Backward command: ") + input.backward());
   D.text(0, 0.3, Str("TurnLeft command: ") + input.turnLeft());
   D.text(0, 0.2, Str("TurnRight command: ") + input.turnRight());
}
/******************************************************************************/

Maybe there are more features and issues, let me know and I'll add it here.

Urbanity Online: http://www.facebook.com/pages/Urbanity-Online/162454237136358
Join the Esenthel IRC Channel @ Freenode: http://webchat.freenode.net/?channels=##Esenthel
09-16-2011 11:57 PM
Visit this user's website Find all posts by this user Quote this message in a reply
gwald Offline
Member

Post: #2
RE: Configurations (& Input example)
Man this is some sweet ass coding!
Very complex stuff and really impressive!
But it's broken :(


class BaseInput : ConfigurableInterface
{
.
.
.

// Variables
Int _connectedJoypad; // stores the index of connected Joypad
Map<Str,Str> _actionBinding(PlayerInput::MapABCreate, PlayerInput::MapABCompare); // successfully read command bindings
Map<Str,UInt> _functionKeys(PlayerInput::MapFKCreate, PlayerInput::MapFKCompare); // default map for command => KB conversions
};

// Description: Constructor, initalizes the _functionsKeys map with all KB_BUTTON
BaseInput.BaseInput()
{ //throws error here line 43
*_functionKeys("0") = KB_0;
*_functionKeys("1") = KB_1;
.
.
}
Code:
1>------ Build started: Project: Bloody Massacre, Configuration: Debug Win32 ------
1>Compiling...
1>BaseInput.cpp
1>c:\esenthel 2.0\projects\_build_\bloody massacre\source\input\baseinput.cpp(43) : error C2664: 'EE::Map<KEY,DATA>::Map(Int (__cdecl *)(const KEY &,const KEY &),Bool (__cdecl *)(DATA &,const KEY &,Ptr),Ptr,Int)' : cannot convert parameter 1 from 'Bool (__cdecl *)(EE::Str &,EE::Str &,Ptr)' to 'Int (__cdecl *)(const KEY &,const KEY &)'
1>        with
1>        [
1>            KEY=EE::Str,
1>            DATA=EE::Str
1>        ]
1>        and
1>        [
1>            KEY=EE::Str
1>        ]
1>        None of the functions with this name in scope match the target type
1>c:\esenthel 2.0\projects\_build_\bloody massacre\source\input\baseinput.cpp(43) : error C2664: 'EE::Map<KEY,DATA>::Map(Int (__cdecl *)(const KEY &,const KEY &),Bool (__cdecl *)(DATA &,const KEY &,Ptr),Ptr,Int)' : cannot convert parameter 1 from 'Bool (__cdecl *)(UInt &,EE::Str &,Ptr)' to 'Int (__cdecl *)(const KEY &,const KEY &)'
1>        with
1>        [
1>            KEY=EE::Str,
1>            DATA=UInt
1>        ]
1>        and
1>        [
1>            KEY=EE::Str
1>        ]
1>        None of the functions with this name in scope match the target type
1>c:\esenthel 2.0\projects\_build_\bloody massacre\source\input\baseinput.cpp(281) : error C2228: left of '.x' must have class/struct/union
1>        type is 'EE::Vec2 [2]'
1>c:\esenthel 2.0\projects\_build_\bloody massacre\source\input\baseinput.cpp(281) : error C2228: left of '.y' must have class/struct/union
1>        type is 'EE::Vec2 [2]'
1>Build log was saved at "file://c:\Esenthel 2.0\Projects\_Build_\Bloody Massacre\Debug\BuildLog.htm"
1>Bloody Massacre - 4 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I'm going to try and debug it because it's very flexible, but I doubt I can.. my C++ is on the week side.


Edit: I just noticed your footer, the IRC link is wrong, it should be:
http://webchat.freenode.net/?channels=#Esenthel

Oh I see it's an esenthel update issue:
http://www.esenthel.com/community/showth...p?tid=4730
http://www.esenthel.com/community/showth...6#pid27896

-all custom Compare functions that want to be passed to memory containers search methods, and Map constructors now need to accept parameters in const mode "Compare(C TYPE &a, C TYPE &b)"


BaseInput file:

Added C to all inputs, but still fails
// Map related functions
static Bool MapABCreate(C Str &data, C Str &key, Ptr user) { return true; }
static Int MapABCompare(C Str &a, C Str &b) { return Compare(a, b); }
static Bool MapFKCreate(C UInt &data, C Str &key, Ptr user){ return true; }
static Int MapFKCompare(C Str &a, C Str &b) { return Compare(a, b); }

My Blog
http://www.esenthel.com/community/showthread.php?tid=6043

I hang out at Esenthel IRC Channel
http://webchat.freenode.net/?channels=#Esenthel
(This post was last modified: 05-20-2013 11:16 AM by gwald.)
05-20-2013 10:42 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #3
RE: Configurations (& Input example)
in the Map constructor the Compare function must now be first, Create function must be second and it is optional.
05-20-2013 11:56 AM
Find all posts by this user Quote this message in a reply
gwald Offline
Member

Post: #4
RE: Configurations (& Input example)
Thank you smile
I see it now in the header!
I would have never seen it, thanks grin

Map<Str, Str> _actionBinding(PlayerInput::MapABCompare,PlayerInput::MapABCreate) ; // successfully read command bindings
Map<Str,UInt> _functionKeys( PlayerInput::MapFKCompare,PlayerInput::MapFKCreate) ; // default map for command => KB conversions

Next issue was this line:
newEval.value = testAxisX ? Joypad[_connectedJoypad].dir_a.x : (testAxisY ? Joypad[_connectedJoypad].dir_a.y : 0.0f) * value;

error C2228: left of '.x' must have class/struct/union

Because dir_a is an array, adding [0] to the two dir_a[0].x compiles.
This only checks left stick.

My Blog
http://www.esenthel.com/community/showthread.php?tid=6043

I hang out at Esenthel IRC Channel
http://webchat.freenode.net/?channels=#Esenthel
(This post was last modified: 05-20-2013 12:18 PM by gwald.)
05-20-2013 12:01 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Post Reply