In-game Lua console and localized keyboard input

Get help with installing and running the Cafu Engine here. This forum is also for general questions and discussion of all aspects regarding the Cafu Engine.
Post Reply
User avatar
Carsten
Site Admin
Posts:2170
Joined:2004-08-19, 13:46
Location:Germany
Contact:
In-game Lua console and localized keyboard input

Post by Carsten » 2006-12-06, 11:57

Hi all,

just wanted to let you know that I yesterday finished revising the Ca3DE in-game console. The console is entirely based on Lua now (see http://www.lua.org for details), plus I've revised the code thoroughly again, and finally obtained a new, clean and beautiful concept for console variables and functions that I'm very content with, and I'm convinced that it is very viable for the future.

Thanks to Lua, the new console is very powerful now, you can format the harddisk and reprogram your OS from the Ca3DE in-game console now if you wish. :cheesy:
Also, a bit of familiarization might be involved, as the new console functions have been moved into their own namespace (a Lua table) "cf", and the variables have been moved into namespace "cv". That is, new console commands look for example like this:

Code: Select all

cf.help();       -- prints a help message, the ; at the end is optional.
cf.list();       -- lists all available Ca3DE console functions and variables.
cf.list("sh");   -- lists all available Ca3DE console functions and variables that match the pattern "cv.sh*" or "cf.sh*".

cv.showFPS=true;     -- sets the value of the cv.showFPS variable to true.
cv.showFPS=1;        -- same as previous line.
print(cv.showPos);   -- prints the current value of the cv.showPos variable.
cf.quit=1;           -- quits the game.
In a related matter, I'm currently finishing the localization of keyboard input, i.e. making everyones keyboard work as expected, not with a forced US layout for everyone anymore.
Interestingly, the DirectInput part of DirectX is - by design - not able to provide character codes for the keys that have been pressed, it just provides codes for the physical keys. The proper solution is to use the regular WM_CHAR messages of the regular Win32 API instead, and I'm currently in the progress to change the Ca3DE keyboard input handling appropriately.

Even more surprisingly, even Microsoft discourages the use of DirectX for keyboard and mouse input these days: Here is a quote from http://msdn.microsoft.com/library/defau ... vement.asp
DirectInput is only useful for reading data from DirectInput joysticks; however, if you only need to support the Xbox 360 controller for Windows, then use XInput instead. Overall, using DirectInput offers no advantages when reading data from mouse or keyboard devices, and the use of DirectInput in these scenarios is discouraged.
:idea: Well, let's get back to work...
Best regards,
Carsten
User avatar
Carsten
Site Admin
Posts:2170
Joined:2004-08-19, 13:46
Location:Germany
Contact:

Post by Carsten » 2006-12-12, 15:12

Just a note to myself, for completeness: It was Chuck Walbourn at Microsoft who talked about that, also see http://www.thezbuffer.com/articles/350.aspx
Here is another quote I found at http://www.gamedev.net/community/forums ... 1&#2760840
Quote from Chuck Walbourn, SDE, Windows Gaming & Graphics

DirectInput on Windows XP is just rerouting WM_KEY and WM_INPUT messages through the DI API rather than any direct processing like it did in the 9x/ME days. It tends to add a lot of complexity to the code, particularly if you don't actually care about joystick or other legacy devices for your titles. In some cases, people have run into strange latency problems because they are using DirectInput instead of direct messages--a worker thread created by DI is actually processing the messages and the communication can add latency.

WM_INPUT gives you everything the DirectInput mouse device can.

I'm not saying you have to move away from DI. I'm just saying that our recommendation is to move away from it going forward. For Mouse/Keyboard, use Windows messages directly. I've seen a lot of gnarly legacy code in games that uses DI just to handle keyboard/mouse, and it tends to be really hard to debug or fix.
Best regards,
Carsten
Post Reply

Who is online

Users browsing this forum: No registered users and 31 guests