Permalink
Browse files

String++, Area::onKeyEvent()

- ozCore
  * String
    + static functions for const char* are orthogonal to String functions
    + split() omits empty sections
    + String(const char*, const char*) constructs a string from two C strings
- ui
  * Area::onKeyEvent(), ESC goes back in menus
  • Loading branch information...
1 parent 6a9b437 commit fafd6a52b5fa874f7dae468dd55e9611fe2a7268 @ducakar committed Jan 6, 2013
View
@@ -191,8 +191,6 @@ if( ${CMAKE_CXX_COMPILER_ID} STREQUAL Clang )
# set( flags "${flags} -fsanitize=address" )
elseif( ${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 4.5 )
set( flags "-std=gnu++0x" )
-elseif( ANDROID )
- set( flags "-std=gnu++0x -pedantic -fstrict-enums" )
else()
set( flags "-std=c++0x -pedantic -fstrict-enums" )
endif()
View
@@ -5,6 +5,7 @@ CURRENT
- TalkFrame
- per-game data subdirs
- 6-direction-layered meshes
+- String: complete orthogonality for const char*
0.4
@@ -1,6 +1,7 @@
set( ANDROID ON )
set( PLATFORM_EMBEDDED ON )
+set( PLATFORM_NAME "Android" )
set( PLATFORM_TRIPLET "arm-linux-androideabi" )
set( PLATFORM_PROC_PREFIX "armeabi" )
set( PLATFORM_PREFIX "$ENV{ANDROID_NDK}/platforms/android-14/arch-arm" )
@@ -1,6 +1,7 @@
set( ANDROID ON )
set( PLATFORM_EMBEDDED ON )
+set( PLATFORM_NAME "Android" )
set( PLATFORM_TRIPLET "arm-linux-androideabi" )
set( PLATFORM_PROC_PREFIX "armeabi-v7a" )
set( PLATFORM_PREFIX "$ENV{ANDROID_NDK}/platforms/android-14/arch-arm" )
@@ -1,6 +1,7 @@
set( ANDROID ON )
set( PLATFORM_EMBEDDED ON )
+set( PLATFORM_NAME "Android" )
set( PLATFORM_TRIPLET "mipsel-linux-android" )
set( PLATFORM_PROC_PREFIX "mips" )
set( PLATFORM_PREFIX "$ENV{ANDROID_NDK}/platforms/android-14/arch-mips" )
@@ -1,6 +1,7 @@
set( ANDROID ON )
set( PLATFORM_EMBEDDED ON )
+set( PLATFORM_NAME "Android" )
set( PLATFORM_TRIPLET "i686-linux-android" )
set( PLATFORM_PROC_PREFIX "x86" )
set( PLATFORM_PREFIX "$ENV{ANDROID_NDK}/platforms/android-14/arch-x86" )
@@ -1,7 +1,7 @@
set( NACL ON )
-set( PLATFORM_NAME "NaCl" )
set( PLATFORM_EMBEDDED ON )
+set( PLATFORM_NAME "NaCl" )
set( PLATFORM_TRIPLET "arm-nacl" )
set( PLATFORM_PREFIX "$ENV{NACL_SDK_ROOT}/toolchain/linux_arm_newlib" )
set( PLATFORM_PORTS_PREFIX "${CMAKE_SOURCE_DIR}/ports/NaCl-ARM" )
@@ -3,18 +3,16 @@ set( NACL ON )
set( PLATFORM_NAME "PNaCl" )
set( PLATFORM_EMBEDDED ON )
set( PLATFORM_TRIPLET "pnacl" )
-set( PLATFORM_PREFIX "/home/davorin/Razvoj/nacl_sdk/pepper_canary/toolchain/linux_x86_pnacl/newlib" )
+set( PLATFORM_PREFIX "$ENV{NACL_SDK_ROOT}/toolchain/linux_x86_pnacl/newlib" )
set( PLATFORM_PORTS_PREFIX "${CMAKE_SOURCE_DIR}/ports/PNaCl" )
set( PLATFORM_EXE_SUFFIX ".pexe" )
set( CMAKE_SYSTEM_NAME "Linux" CACHE STRING "Target system." )
-set( CMAKE_SYSTEM_PROCESSOR "LLVM" CACHE STRING "Target processor." )
+set( CMAKE_SYSTEM_PROCESSOR "LLVM-IR" CACHE STRING "Target processor." )
set( CMAKE_FIND_ROOT_PATH "${PLATFORM_PORTS_PREFIX};${PLATFORM_PREFIX}/usr" )
set( CMAKE_FIND_ROOT_PATH "${CMAKE_FIND_ROOT_PATH};${PLATFORM_PREFIX}/sdk" )
set( CMAKE_C_COMPILER "${PLATFORM_PREFIX}/bin/${PLATFORM_TRIPLET}-clang" )
set( CMAKE_CXX_COMPILER "${PLATFORM_PREFIX}/bin/${PLATFORM_TRIPLET}-clang++" )
-set( CMAKE_C_FLAGS "-U__STRICT_ANSI__" CACHE STRING "" )
-set( CMAKE_CXX_FLAGS "-U__STRICT_ANSI__" CACHE STRING "" )
set( CMAKE_AR "${PLATFORM_PREFIX}/bin/${PLATFORM_TRIPLET}-ar" CACHE STRING "")
set( CMAKE_RANLIB "${PLATFORM_PREFIX}/bin/${PLATFORM_TRIPLET}-ranlib" CACHE STRING "")
View
@@ -743,7 +743,7 @@ void Builder::packArchive( const char* name, bool useCompression, bool use7zip )
int Builder::main( int argc, char** argv )
{
- String invocationName = String( argv[0] ).fileBaseName();
+ String invocationName = String::fileBaseName( argv[0] );
config.setObject();
View
@@ -29,7 +29,7 @@ void Lingua::buildCatalogue( const char* directory, const char* catalogue )
{
Log::print( "%s/%s ...", directory, catalogue );
- File::mkdir( String::str( "%s", directory ) );
+ File::mkdir( directory );
PFile srcFile( String::str( "%s/%s.po", directory, catalogue ) );
File outFile( String::str( "%s/%s.ozCat", directory, catalogue ) );
View
@@ -42,7 +42,6 @@
#include <client/BuildInfo.hh>
#include <clocale>
-#include <sstream>
#include <unistd.h>
#include <SDL.h>
#include <SDL_ttf.h>
@@ -86,7 +85,7 @@ int Client::init( int argc, char** argv )
isBenchmark = false;
benchmarkTime = 0.0f;
- String invocationName = String( argv[0] ).fileBaseName();
+ String invocationName = String::fileBaseName( argv[0] );
String prefix;
String language;
String mission;
@@ -109,10 +108,10 @@ int Client::init( int argc, char** argv )
break;
}
case 't': {
- std::istringstream ss( optarg );
- ss >> benchmarkTime;
+ const char* end;
+ benchmarkTime = String::parseFloat( optarg, &end );
- if( ss.fail() ) {
+ if( end == optarg ) {
printUsage( invocationName );
return EXIT_FAILURE;
}
@@ -163,9 +162,9 @@ int Client::init( int argc, char** argv )
OZ_ERROR( "Failed to obtain MYMUSIC directory" );
}
- String configDir = String::str( "%s\\openzone", configRoot );
- String localDir = String::str( "%s\\openzone", localRoot );
- String musicDir = String::str( "%s\\OpenZone", musicRoot );
+ String configDir = String( configRoot, "\\openzone" );
+ String localDir = String( localRoot, "\\openzone" );
+ String musicDir = String( musicRoot, "\\OpenZone" );
#else
@@ -178,14 +177,14 @@ int Client::init( int argc, char** argv )
OZ_ERROR( "Cannot determine user home directory from environment" );
}
- String configDir = configRoot == nullptr ? String::str( "%s/.config/openzone", home ) :
- String::str( "%s/openzone", configRoot );
+ String configDir = configRoot == nullptr ? String( home, "/.config/openzone" ) :
+ String( configRoot, "/openzone" );
- String localDir = localRoot == nullptr ? String::str( "%s/.local/share/openzone", home ) :
- String::str( "%s/openzone", localRoot );
+ String localDir = localRoot == nullptr ? String( home, "/.local/share/openzone" ) :
+ String( localRoot, "/openzone" );
- String musicDir = musicRoot == nullptr ? String::str( "%s/Music/OpenZone", home ) :
- String::str( "%s/OpenZone", musicRoot );
+ String musicDir = musicRoot == nullptr ? String( home, "/Music/OpenZone" ) :
+ String( musicRoot, "/OpenZone" );
#endif
View
@@ -563,8 +563,8 @@ void GameStage::init()
Log::println( "Initialising GameStage {" );
Log::indent();
- AUTOSAVE_FILE = String::str( "%s/saves/autosave.ozState", config["dir.config"].get( "" ) );
- QUICKSAVE_FILE = String::str( "%s/saves/quicksave.ozState", config["dir.config"].get( "" ) );
+ AUTOSAVE_FILE = String( config["dir.config"].get( "" ), "/saves/autosave.ozState" );
+ QUICKSAVE_FILE = String( config["dir.config"].get( "" ), "/saves/quicksave.ozState" );
matrix.init();
nirvana.init();
View
@@ -384,6 +384,7 @@ void Input::readEvent( SDL_Event* event )
#else
sdlCurrKeys[event->key.keysym.scancode] = false;
#endif
+ isKeyReleased = true;
break;
}
case SDL_KEYDOWN: {
@@ -394,6 +395,7 @@ void Input::readEvent( SDL_Event* event )
sdlKeys[event->key.keysym.scancode] = true;
sdlCurrKeys[event->key.keysym.scancode] = true;
#endif
+ isKeyPressed = true;
break;
}
default: {
@@ -443,6 +445,9 @@ void Input::prepare()
mCopy( sdlOldKeys, sdlKeys, sizeof( sdlKeys ) );
mCopy( sdlKeys, sdlCurrKeys, sizeof( sdlKeys ) );
+
+ isKeyPressed = false;
+ isKeyReleased = false;
}
void Input::update()
@@ -596,6 +601,9 @@ void Input::init()
mSet( keys, 0, sizeof( keys ) );
mSet( oldKeys, 0, sizeof( oldKeys ) );
+ isKeyPressed = false;
+ isKeyReleased = false;
+
mouseSensX = mouseConfig["sensitivity.x"].get( 0.004f );
mouseSensY = mouseConfig["sensitivity.y"].get( 0.004f );
mouseSensZ = mouseConfig["sensitivity.z"].get( 2.0f );
View
@@ -161,6 +161,9 @@ class Input
bool keys[KEY_MAX];
bool oldKeys[KEY_MAX];
+ bool isKeyPressed;
+ bool isKeyReleased;
+
float mouseSensX;
float mouseSensY;
float mouseSensZ;
View
@@ -610,20 +610,20 @@ void Render::init()
bool hasFloatTex = false;
bool hasS3TC = false;
- String vendor = String::cstr( glGetString( GL_VENDOR ) );
- String renderer = String::cstr( glGetString( GL_RENDERER ) );
- String version = String::cstr( glGetString( GL_VERSION ) );
- String glslVersion = String::cstr( glGetString( GL_SHADING_LANGUAGE_VERSION ) );
- String sExtensions = String::cstr( glGetString( GL_EXTENSIONS ) );
- DArray<String> extensions = sExtensions.trim().split( ' ' );
+ const char* vendor = String::cstr( glGetString( GL_VENDOR ) );
+ const char* renderer = String::cstr( glGetString( GL_RENDERER ) );
+ const char* version = String::cstr( glGetString( GL_VERSION ) );
+ const char* glslVersion = String::cstr( glGetString( GL_SHADING_LANGUAGE_VERSION ) );
+ const char* sExtensions = String::cstr( glGetString( GL_EXTENSIONS ) );
+ DArray<String> extensions = String::trim( sExtensions ).split( ' ' );
// glGetString( GL_EXTENSIONS ) generates an error when using OpenGL 3.2+ Core Profile.
glGetError();
- Log::println( "OpenGL vendor: %s", vendor.cstr() );
- Log::println( "OpenGL renderer: %s", renderer.cstr() );
- Log::println( "OpenGL version: %s", version.cstr() );
- Log::println( "GLSL version: %s", glslVersion.cstr() );
+ Log::println( "OpenGL vendor: %s", vendor );
+ Log::println( "OpenGL renderer: %s", renderer );
+ Log::println( "OpenGL version: %s", version );
+ Log::println( "GLSL version: %s", glslVersion );
Log::verboseMode = true;
View
@@ -769,8 +769,8 @@ void Sound::init()
Log::println( "OpenAL renderer: %s", alGetString( AL_RENDERER ) );
Log::println( "OpenAL version: %s", alGetString( AL_VERSION ) );
- String sExtensions = alGetString( AL_EXTENSIONS );
- DArray<String> extensions = sExtensions.trim().split( ' ' );
+ const char* sExtensions = alGetString( AL_EXTENSIONS );
+ DArray<String> extensions = String::trim( sExtensions ).split( ' ' );
Log::verboseMode = true;
Log::println( "OpenAL extensions {" );
View
@@ -101,7 +101,10 @@ bool Area::passMouseEvents()
}
}
- foreach( child, children.iter() ) {
+ for( auto i = children.iter(); i.isValid(); ) {
+ Area* child = i;
+ ++i;
+
if( child->x <= mouse.x && mouse.x < child->x + child->width &&
child->y <= mouse.y && mouse.y < child->y + child->height )
{
@@ -116,6 +119,20 @@ bool Area::passMouseEvents()
return false;
}
+bool Area::passKeyEvents()
+{
+ for( auto i = children.iter(); i.isValid(); ) {
+ Area* child = i;
+ ++i;
+
+ if( !( child->flags & ( IGNORE_BIT | DISABLED_BIT ) ) ) {
+ child->onKeyEvent();
+ }
+ }
+
+ return true;
+}
+
void Area::drawChildren()
{
// Render in opposite order; last added child (the first one in the list) should be rendered last.
@@ -140,6 +157,11 @@ bool Area::onMouseEvent()
return false;
}
+bool Area::onKeyEvent()
+{
+ return false;
+}
+
void Area::onDraw()
{}
View
@@ -87,13 +87,15 @@ class Area
void updateChildren();
// return true if event has been caught
bool passMouseEvents();
+ bool passKeyEvents();
void drawChildren();
virtual void onVisibilityChange( bool doShow );
virtual void onReposition();
virtual void onUpdate();
// return true if event has been caught
virtual bool onMouseEvent();
+ virtual bool onKeyEvent();
virtual void onDraw();
public:
@@ -112,6 +112,17 @@ bool CreditsMenu::onMouseEvent()
return true;
}
+bool CreditsMenu::onKeyEvent()
+{
+ if( input.keys[Input::KEY_QUIT] ) {
+ parent->remove( this );
+ return true;
+ }
+ else {
+ return passKeyEvents();
+ }
+}
+
void CreditsMenu::onDraw()
{
shape.colour( 0.0f, 0.0f, 0.0f, 1.0f );
@@ -49,6 +49,7 @@ class CreditsMenu : public Area
void onReposition() override;
void onUpdate() override;
bool onMouseEvent() override;
+ bool onKeyEvent() override;
void onDraw() override;
public:
View
@@ -66,6 +66,11 @@ bool Frame::onMouseEvent()
return true;
}
+bool Frame::onKeyEvent()
+{
+ return passKeyEvents();
+}
+
void Frame::onDraw()
{
shape.colour( style.colours.frame );
View
@@ -46,6 +46,7 @@ class Frame : public Area
protected:
bool onMouseEvent() override;
+ bool onKeyEvent() override;
void onDraw() override;
public:
@@ -160,6 +160,11 @@ bool MainMenu::onMouseEvent()
return passMouseEvents();
}
+bool MainMenu::onKeyEvent()
+{
+ return passKeyEvents();
+}
+
void MainMenu::onDraw()
{
shape.colour( style.colours.background );
@@ -46,6 +46,7 @@ class MainMenu : public Area
void onReposition() override;
void onUpdate() override;
bool onMouseEvent() override;
+ bool onKeyEvent() override;
void onDraw() override;
public:
Oops, something went wrong.

0 comments on commit fafd6a5

Please sign in to comment.