Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

SharedLib, pp::MessageLoop in File, System::bell()

- ozCore
  * SharedLib class added for loading shared libraries
  * PPAPI 25 non-main thread calls used to simplfy File class and System::bell()
- ozEngine
  * OpenGL.hh, OpenAL.hh added, Texture class stub
  • Loading branch information...
commit 9635f71d1b05cd2c742b29c554a53552d316fa95 1 parent a04b92f
@ducakar authored
Showing with 1,074 additions and 579 deletions.
  1. +3 −3 CMakeLists.txt
  2. +10 −3 autogen.sh
  3. +1 −1  clean-blanks.sh
  4. +1 −1  src/client/BuildInfo.cc.in
  5. +1 −1  src/client/CMakeLists.txt
  6. +1 −1  src/client/Client.cc
  7. +1 −1  src/client/NaClUpdater.cc
  8. +1 −1  src/client/OpenGL.hh
  9. +18 −19 src/client/Render.cc
  10. +8 −20 src/client/Sound.cc
  11. +3 −3 src/client/Sound.hh
  12. +3 −3 src/client/common.hh
  13. +1 −1  src/client/config.hh.in
  14. +1 −1  src/nirvana/common.hh
  15. +5 −3 src/ozCore/CMakeLists.txt
  16. +62 −336 src/ozCore/File.cc
  17. +6 −11 src/ozCore/File.hh
  18. +100 −0 src/ozCore/SharedLib.cc
  19. +118 −0 src/ozCore/SharedLib.hh
  20. +38 −74 src/ozCore/System.cc
  21. +15 −13 src/ozCore/Thread.cc
  22. +2 −1  src/ozCore/ozCore.hh
  23. +1 −0  src/ozDynamics/CMakeLists.txt
  24. +10 −7 src/ozDynamics/collision/Body.hh
  25. +2 −2 src/ozDynamics/collision/Collider.cc
  26. +6 −6 src/ozDynamics/physics/Physics.cc
  27. +7 −0 src/ozEngine/CMakeLists.txt
  28. +74 −0 src/ozEngine/OpenAL.cc
  29. +45 −0 src/ozEngine/OpenAL.hh
  30. +229 −0 src/ozEngine/OpenGL.cc
  31. +137 −0 src/ozEngine/OpenGL.hh
  32. +53 −0 src/ozEngine/Texture.cc
  33. +104 −0 src/ozEngine/Texture.hh
  34. +1 −0  src/ozEngine/common.hh
  35. +3 −0  src/ozEngine/config.hh.in
  36. +0 −6 src/tests/CMakeLists.txt
  37. +0 −54 src/tests/collada.cc
  38. +1 −0  src/tests/test.cc
  39. +2 −3 src/tools/openzone.cc
  40. +0 −4 src/tools/ozGettext.cc
View
6 CMakeLists.txt
@@ -11,11 +11,11 @@ set( OZ_VERSION 0.3.81 )
option( OZ_TRACK_ALLOCS "Track memory allocations to detect new/delete mismatches and memory leaks." OFF )
option( OZ_SIMD_MATH "Use SIMD implementation of linear algebra classes." OFF )
option( OZ_DYNAMICS "Build complete ozDynamics library with ODE support." OFF )
+option( OZ_GLES "Use OpenGL ES 2.0 instead of OpenGL 2.1." OFF )
option( OZ_LUAJIT "Use use LuaJIT 2.0 instead of official Lua." OFF )
option( OZ_SDL2 "Use SDL 2.0 instead of SDL 1.2." OFF )
option( OZ_NET "Enable networking support." OFF )
-option( OZ_GL_ES "Use OpenGL ES 2.0 instead of OpenGL 2.1." OFF )
option( OZ_NONFREE "Enable support for building S3TC textures." OFF )
option( OZ_STANDALONE "Install layout appropriate for launching from its own folder." OFF )
@@ -34,7 +34,7 @@ set( OZ_PLATFORM_NAME ${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR} )
if( PLATFORM_EMBEDDED )
set( OZ_PLATFORM_NAME ${PLATFORM_NAME}-${CMAKE_SYSTEM_PROCESSOR} )
- set( OZ_GL_ES ON )
+ set( OZ_GLES ON )
set( OZ_STANDALONE OFF )
endif()
@@ -105,7 +105,7 @@ else()
include_directories( SYSTEM ${SDL_INCLUDE_DIRS} )
endif()
-if( OZ_GL_ES )
+if( OZ_GLES )
# On embedded platform GLES is part of system libraries and is guaranteed to exist in toolchain or
# platform directory, no need to explicitly check existence or to detect library names.
if( ANDROID )
View
13 autogen.sh
@@ -17,9 +17,16 @@ for component in ${components[@]}; do
echo "Generating src/$component/CMakeLists.txt"
cd src/$component
- # The sed statement removes uninstantiated *.hh, *.cc, */*.hh and */*.cc expressions and makes the
- # file list newline-separated and indented.
- sources=`echo *.{hh,cc} */*.{hh,cc} | sed -r 's| (\*/)?\*\...||g; s| |\\\\n |g'`
+
+ sources=`echo *.{hh,cc} */*.{hh,cc}`
+ # Remove uninstantiated *.hh, *.cc, */*.hh and */*.cc expressions.
+ sources=`echo $sources | sed -r 's|(\*/)?\*\...||g'`
+ # Remove PCH trigger library.
+ sources=`echo $sources | sed -r 's|pch\.cc||g'`
+ # Remove duplicated spaces that may have been introduced by the previous removals.
+ sources=`echo $sources | sed -r 's| +| |g'`
+ # Make file list newline-separated and indented.
+ sources=`echo $sources | sed -r 's| |\\\\n |g'`
# Insert source file list between "#BEGIN SOURCES" and "#END SOURCES" tags in CMakeLists.txt.
sed -r '/^#BEGIN SOURCES$/,/^#END SOURCES$/ c\#BEGIN SOURCES\n '"$sources"'\n#END SOURCES' \
View
2  clean-blanks.sh
@@ -10,7 +10,7 @@
# each file, remove duplicated blank lines and then remove one blank line at the end of each file.
#
-files=`git ls-files | egrep -v '^doc/licences/|^include/|\.patch$|\.po$'`
+files=`git ls-files | egrep -v '^doc/licences/|^include/|^etc/android-project/|\.patch$|\.po$'`
for file in $files; do
# Remove trailing blanks at the end of line.
View
2  src/client/BuildInfo.cc.in
@@ -47,6 +47,6 @@ const char* const BuildInfo::CONFIG = "OZ_TRACK_ALLOCS: @OZ_TRACK_ALLOCS@
"OZ_DYNAMICS: @OZ_DYNAMICS@, "
"OZ_LUAJIT: @OZ_LUAJIT@, "
"OZ_SDL2: @OZ_SDL2@, "
- "OZ_GL_ES: @OZ_GL_ES@";
+ "OZ_GLES: @OZ_GLES@";
}
View
2  src/client/CMakeLists.txt
@@ -174,7 +174,7 @@ else()
target_link_libraries( client ${SDL_TTF_LIBRARIES} ${SDL_LIBRARIES} )
endif()
-if( OZ_GL_ES )
+if( OZ_GLES )
target_link_libraries( client ${GLES2_LIBRARIES} )
else()
target_link_libraries( client ${OPENGL_gl_LIBRARY} )
View
2  src/client/Client.cc
@@ -94,7 +94,7 @@ int Client::init( int argc, char** argv )
optind = 1;
int opt;
- while( ( opt = getopt( argc, argv, "vlie:t:L:p:h?" ) ) >= 0 ) {
+ while( ( opt = getopt( argc, argv, "vli:e:t:L:p:h?" ) ) >= 0 ) {
switch( opt ) {
case 'v': {
Log::showVerbose = true;
View
2  src/client/NaClUpdater.cc
@@ -107,7 +107,7 @@ bool NaClUpdater::checkUpdates()
downloader.begin( REMOTE_MANIFEST );
do {
- Time::sleep( 100 );
+ Time::sleep( 20 );
Log::printRaw( "." );
}
while( !downloader.isComplete() );
View
2  src/client/OpenGL.hh
@@ -25,7 +25,7 @@
#include <client/NaClPlatform.hh>
-#ifdef OZ_GL_ES
+#ifdef OZ_GLES
# include <GLES2/gl2.h>
#else
# define GL_GLEXT_PROTOTYPES
View
37 src/client/Render.cc
@@ -624,12 +624,12 @@ void Render::init()
bool hasFloatTex = false;
bool hasS3TC = false;
- 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( ' ' );
+ 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();
@@ -818,12 +818,11 @@ void Render::drawDyn()
colour = Vec4( 0.0f, 0.0f, 1.0f, 1.0f );
}
- body->rot = ~body->rot;
- body->rotMat = Mat33::rotation( body->rot );
+ body->update();
shape.colour( colour );
- shape.wireBox( body->getBounds().toAABB() );
- shape.object( body->pos, body->rotMat, body->shape() );
+ shape.wireBox( body->bb.toAABB() );
+ shape.object( body->p, body->oMat, body->shape() );
}
}
@@ -841,10 +840,10 @@ void Render::loadDyn()
// Capsule* c = new Capsule( 1, 1 );
body = new DBody();
- body->pos = Point( 140, 0, 80 );
- body->rot = Quat::ID;
- body->rotMat = Mat33::rotation( body->rot );
+ body->p = Point( 140, 0, 80 );
+ body->o = Quat::ID;
body->setShape( c );
+ body->update();
space.bodies.add( body );
physics.add( body );
@@ -852,10 +851,10 @@ void Render::loadDyn()
Box* b = new Box( Vec3( 1, 1, 2 ) );
body = new DBody();
- body->pos = Point( 143, 0, 80 );
- body->rot = Quat::ID;
- body->rotMat = Mat33::rotation( body->rot );
+ body->p = Point( 143, 0, 80 );
+ body->o = Quat::ID;
body->setShape( b );
+ body->update();
space.bodies.add( body );
physics.add( body );
@@ -863,10 +862,10 @@ void Render::loadDyn()
Box* p = new Box( Vec3( 10, 10, 1 ) );
body = new DBody();
- body->pos = Point( 142, 0, 75 );
- body->rot = Quat::ID;
- body->rotMat = Mat33::rotation( body->rot );
+ body->p = Point( 142, 0, 75 );
+ body->o = Quat::ID;
body->setShape( p );
+ body->update();
space.bodies.add( body );
}
View
28 src/client/Sound.cc
@@ -104,7 +104,7 @@ void Sound::musicOpen( const char* path )
musicStreamType = OGG;
}
else if( file.hasExtension( "mp3" ) ) {
- if( libMad != nullptr ) {
+ if( libMad.isOpened() ) {
musicStreamType = MP3;
}
else {
@@ -112,7 +112,7 @@ void Sound::musicOpen( const char* path )
}
}
else if( file.hasExtension( "aac" ) ) {
- if( libFaad != nullptr ) {
+ if( libFaad.isOpened() ) {
musicStreamType = AAC;
}
else {
@@ -868,15 +868,9 @@ void Sound::destroy()
}
#ifndef __native_client__
- if( libFaad != nullptr ) {
- SDL_UnloadObject( libFaad );
- }
- if( libMad != nullptr ) {
- SDL_UnloadObject( libMad );
- }
- if( libeSpeak != nullptr ) {
- SDL_UnloadObject( libeSpeak );
- }
+ libFaad.close();
+ libMad.close();
+ libeSpeak.close();
#endif
Log::printEnd( " OK" );
@@ -901,9 +895,7 @@ void Sound::initLibs()
Log::print( "Linking eSpeak library '%s' ...", libeSpeakName );
- libeSpeak = SDL_LoadObject( libeSpeakName );
-
- if( libeSpeak == nullptr ) {
+ if( !libeSpeak.open( libeSpeakName ) ) {
Log::printEnd( " Not found, speech synthesis not supported" );
}
else {
@@ -919,9 +911,7 @@ void Sound::initLibs()
Log::print( "Linking MAD library '%s' ...", libMadName );
- libMad = SDL_LoadObject( libMadName );
-
- if( libMad == nullptr ) {
+ if( !libMad.open( libMadName ) ) {
liber.mapMP3s = false;
Log::printEnd( " Not found, MP3 not supported" );
@@ -943,9 +933,7 @@ void Sound::initLibs()
Log::print( "Linking FAAD library '%s' ...", libFaadName );
- libFaad = SDL_LoadObject( libFaadName );
-
- if( libFaad == nullptr ) {
+ if( !libFaad.open( libFaadName ) ) {
liber.mapAACs = false;
Log::printEnd( " Not found, AAC not supported" );
View
6 src/client/Sound.hh
@@ -59,9 +59,9 @@ class Sound
ALCdevice* soundDevice;
ALCcontext* soundContext;
- void* libeSpeak;
- void* libMad;
- void* libFaad;
+ SharedLib libeSpeak;
+ SharedLib libMad;
+ SharedLib libFaad;
Bitset playedStructs;
float volume;
View
6 src/client/common.hh
@@ -41,7 +41,7 @@
decltype( ::func )* func = nullptr
#define OZ_DL_LOAD( l, func ) \
- *( void** )( &func ) = SDL_LoadFunction( l, #func ); \
+ func = reinterpret_cast< decltype( func ) >( l.get( #func ) ); \
if( func == nullptr ) { \
OZ_ERROR( "Failed to link function: " #func ); \
}
@@ -118,8 +118,8 @@ struct TexCoord
}
};
-extern Collider collider;
-extern JSON config;
+extern matrix::Collider collider;
+extern JSON config;
}
}
View
2  src/client/config.hh.in
@@ -33,4 +33,4 @@
#cmakedefine OZ_NET
// Use OpenGL ES 2.0.
-#cmakedefine OZ_GL_ES
+#cmakedefine OZ_GLES
View
2  src/nirvana/common.hh
@@ -33,7 +33,7 @@ namespace nirvana
using namespace common;
using namespace matrix;
-extern Collider collider;
+extern matrix::Collider collider;
}
}
View
8 src/ozCore/CMakeLists.txt
@@ -39,6 +39,7 @@ add_library( ozCore
SBitset.hh
Semaphore.hh
Set.hh
+ SharedLib.hh
simd.hh
SList.hh
SpinLock.hh
@@ -63,6 +64,7 @@ add_library( ozCore
Point.cc
Quat.cc
Semaphore.cc
+ SharedLib.cc
StackTrace.cc
String.cc
System.cc
@@ -76,16 +78,16 @@ add_library( ozCore
if( EMSCRIPTEN )
# target_link_libraries( ozCore )
elseif( ANDROID )
- target_link_libraries( ozCore ${PHYSFS_LIBRARY} ${ZLIB_LIBRARY} -lOpenSLES -llog ${PLATFORM_STL_LIBRARY} )
+ target_link_libraries( ozCore ${PHYSFS_LIBRARY} ${ZLIB_LIBRARY} -ldl -lOpenSLES -llog ${PLATFORM_STL_LIBRARY} )
elseif( NACL )
target_link_libraries( ozCore ${PHYSFS_LIBRARY} ${ZLIB_LIBRARY} -lppapi_cpp -lppapi -lpthread )
elseif( WIN32 )
target_link_libraries( ozCore ${PHYSFS_LIBRARY} -lwinmm )
elseif( NOT CMAKE_SYSTEM_NAME STREQUAL Linux )
- target_link_libraries( ozCore ${PHYSFS_LIBRARY} -lpulse-simple -lrt -lpthread )
+ target_link_libraries( ozCore ${PHYSFS_LIBRARY} -ldl -lpulse-simple -lrt -lpthread )
else()
# TODO: Remove -lrt once glibc 2.17 becomes minimum.
- target_link_libraries( ozCore ${PHYSFS_LIBRARY} -lpulse-simple -lasound -lrt -lpthread )
+ target_link_libraries( ozCore ${PHYSFS_LIBRARY} -ldl -lpulse-simple -lasound -lrt -lpthread )
endif()
set_target_properties( ozCore PROPERTIES VERSION ${OZ_VERSION} SOVERSION 0 )
View
398 src/ozCore/File.cc
@@ -65,81 +65,8 @@ namespace oz
#ifdef __native_client__
-#define SEMAPHORE_POST() \
- pthread_mutex_lock( &_fd->semaphore.mutex ); \
- ++_fd->semaphore.counter; \
- pthread_mutex_unlock( &_fd->semaphore.mutex ); \
- pthread_cond_signal( &_fd->semaphore.cond )
-
-#define SEMAPHORE_WAIT() \
- pthread_mutex_lock( &descriptor->semaphore.mutex ); \
- while( descriptor->semaphore.counter == 0 ) { \
- pthread_cond_wait( &descriptor->semaphore.cond, &descriptor->semaphore.mutex ); \
- } \
- --descriptor->semaphore.counter; \
- pthread_mutex_unlock( &descriptor->semaphore.mutex )
-
-#define DEFINE_CALLBACK( name, code ) \
- struct _Callback##name \
- { \
- static void _main##name( void* _data, int _result ) \
- { \
- Descriptor* _fd = static_cast<Descriptor*>( _data ); \
- static_cast<void>( _fd ); \
- static_cast<void>( _result ); \
- code \
- } \
- }
-
-#define CALLBACK_OBJECT( name, arg ) \
- pp::CompletionCallback( _Callback##name::_main##name, arg )
-
-#define MAIN_CALL( name ) \
- ppCore->CallOnMainThread( 0, CALLBACK_OBJECT( name, descriptor ) )
-
-struct File::Descriptor
-{
- struct Semaphore
- {
- pthread_mutex_t mutex;
- pthread_cond_t cond;
- volatile int counter;
- };
-
- // Some Descriptor members are also useful for static functions.
- static Descriptor staticDesc;
-
- Semaphore semaphore;
- File* file;
- pp::FileRef* fref;
- pp::FileIO* fio;
- PP_FileInfo info;
- char* buffer;
- int size;
- int offset;
-
- OZ_HIDDEN
- explicit Descriptor( File* file_ ) :
- file( file_ )
- {
- pthread_mutex_init( &semaphore.mutex, nullptr );
- pthread_cond_init( &semaphore.cond, nullptr );
- semaphore.counter = 0;
- }
-
- OZ_HIDDEN
- ~Descriptor()
- {
- pthread_cond_destroy( &semaphore.cond );
- pthread_mutex_destroy( &semaphore.mutex );
- }
-};
-
-OZ_HIDDEN
-File::Descriptor File::Descriptor::staticDesc( nullptr );
-
-static pp::Core* ppCore = nullptr;
-static pp::FileSystem* ppFileSystem = nullptr;
+static pp::Core* ppCore = nullptr;
+static pp::FileSystem ppFileSystem;
#endif // __native_client__
@@ -152,10 +79,6 @@ File::File( FileSystem fileSystem, const char* path ) :
filePath( path ), fileType( MISSING ), fileFS( fileSystem ), fileSize( -1 ), fileTime( 0 ),
data( nullptr )
{
-#ifdef __native_client__
- descriptor = new Descriptor( this );
-#endif
-
// Avoid stat'ing obviously non-existent files.
if( filePath.isEmpty() ) {
return;
@@ -167,29 +90,17 @@ File::File( FileSystem fileSystem, const char* path ) :
File::~File()
{
unmap();
-
-#ifdef __native_client__
- delete descriptor;
-#endif
}
File::File( const File& file ) :
filePath( file.filePath ), fileType( file.fileType ), fileFS( file.fileFS ),
fileSize( file.fileSize ), fileTime( file.fileTime ), data( nullptr )
-{
-#ifdef __native_client__
- descriptor = new Descriptor( this );
-#endif
-}
+{}
File::File( File&& file ) :
filePath( static_cast<String&&>( file.filePath ) ), fileType( file.fileType ),
fileFS( file.fileFS ), fileSize( file.fileSize ), fileTime( file.fileTime ), data( file.data )
{
-#ifdef __native_client__
- descriptor = new Descriptor( this );
-#endif
-
file.filePath = "";
file.fileType = MISSING;
file.fileFS = NATIVE;
@@ -311,51 +222,28 @@ bool File::stat()
return true;
}
- DEFINE_CALLBACK( queryResult, {
- if( _result == PP_OK ) {
- if( _fd->info.type == PP_FILETYPE_REGULAR ) {
- _fd->file->fileType = REGULAR;
- _fd->file->fileSize = int( _fd->info.size );
- _fd->file->fileTime = long64( max( _fd->info.creation_time,
- _fd->info.last_modified_time ) );
- }
- else if( _fd->info.type == PP_FILETYPE_DIRECTORY ) {
- _fd->file->fileType = DIRECTORY;
- _fd->file->fileSize = -1;
- _fd->file->fileTime = long64( max( _fd->info.creation_time,
- _fd->info.last_modified_time ) );
- }
- }
-
- delete _fd->fio;
- SEMAPHORE_POST();
- } );
- DEFINE_CALLBACK( query, {
- if( _result == PP_OK ) {
- int ret = _fd->fio->Query( &_fd->info, CALLBACK_OBJECT( queryResult, _fd ) );
- if( ret == PP_OK_COMPLETIONPENDING ) {
- return;
- }
- }
+ pp::FileRef file( ppFileSystem, filePath );
+ pp::FileIO fio( System::instance );
- delete _fd->fio;
- SEMAPHORE_POST();
- } );
- DEFINE_CALLBACK( open, {
- _fd->fio = new pp::FileIO( System::instance );
-
- int ret = _fd->fio->Open( pp::FileRef( *ppFileSystem, _fd->file->filePath ), 0,
- CALLBACK_OBJECT( query, _fd ) );
- if( ret == PP_OK_COMPLETIONPENDING ) {
- return;
- }
+ if( fio.Open( file, 0, pp::BlockUntilComplete() ) != PP_OK ) {
+ return false;
+ }
- delete _fd->fio;
- SEMAPHORE_POST();
- } );
+ PP_FileInfo fileInfo;
+ if( fio.Query( &fileInfo, pp::BlockUntilComplete() ) != PP_OK ) {
+ return false;
+ }
- MAIN_CALL( open );
- SEMAPHORE_WAIT();
+ if( fileInfo.type == PP_FILETYPE_REGULAR ) {
+ fileType = REGULAR;
+ fileSize = int( fileInfo.size );
+ fileTime = long64( max( fileInfo.creation_time, fileInfo.last_modified_time ) );
+ }
+ else if( fileInfo.type == PP_FILETYPE_DIRECTORY ) {
+ fileType = DIRECTORY;
+ fileSize = -1;
+ fileTime = long64( max( fileInfo.creation_time, fileInfo.last_modified_time ) );
+ }
#elif defined( _WIN32 )
@@ -566,59 +454,30 @@ bool File::read( char* buffer, int* size ) const
#if defined( __native_client__ )
- descriptor->buffer = buffer;
- descriptor->size = min( *size, fileSize );
- descriptor->offset = 0;
-
- DEFINE_CALLBACK( read, {
- if( _result > 0 ) {
- _fd->offset += _result;
-
- if( _fd->offset != _fd->size ) {
- int ret = _fd->fio->Read( _fd->offset, &_fd->buffer[_fd->offset], _fd->size - _fd->offset,
- CALLBACK_OBJECT( read, _fd ) );
- if( ret == PP_OK_COMPLETIONPENDING ) {
- return;
- }
- }
- }
-
- delete _fd->fio;
- SEMAPHORE_POST();
- } );
- DEFINE_CALLBACK( beginRead, {
- if( _result == PP_OK ) {
- int ret = _fd->fio->Read( 0, _fd->buffer, _fd->size, CALLBACK_OBJECT( read, _fd ) );
- if( ret == PP_OK_COMPLETIONPENDING ) {
- return;
- }
- }
-
- delete _fd->fio;
- SEMAPHORE_POST();
- } );
- DEFINE_CALLBACK( open, {
- _fd->fio = new pp::FileIO( System::instance );
+ int readSize = min( *size, fileSize );
+ int offset = 0;
- int ret = _fd->fio->Open( pp::FileRef( *ppFileSystem, _fd->file->filePath ),
- PP_FILEOPENFLAG_READ, CALLBACK_OBJECT( beginRead, _fd ) );
- if( ret == PP_OK_COMPLETIONPENDING ) {
- return;
- }
+ pp::FileRef file( ppFileSystem, filePath );
+ pp::FileIO fio( System::instance );
- delete _fd->fio;
- SEMAPHORE_POST();
- } );
+ if( fio.Open( file, PP_FILEOPENFLAG_READ, pp::BlockUntilComplete() ) != PP_OK ) {
+ *size = 0;
+ return false;
+ }
- MAIN_CALL( open );
- SEMAPHORE_WAIT();
+ int result;
+ while( ( result = fio.Read( offset, &buffer[offset], readSize - offset,
+ pp::BlockUntilComplete() ) ) > 0 )
+ {
+ offset += result;
+ }
- if( descriptor->offset != descriptor->size ) {
+ if( result < 0 ) {
*size = 0;
return false;
}
- *size = descriptor->offset;
+ *size = offset;
#elif defined( _WIN32 )
@@ -721,55 +580,26 @@ bool File::write( const char* buffer, int size ) const
#if defined( __native_client__ )
- descriptor->buffer = const_cast<char*>( buffer );
- descriptor->size = size;
- descriptor->offset = 0;
+ int offset = 0;
- DEFINE_CALLBACK( write, {
- if( _result > 0 ) {
- _fd->offset += _result;
-
- if( _fd->offset != _fd->size ) {
- int ret = _fd->fio->Write( _fd->offset, &_fd->buffer[_fd->offset],
- _fd->size - _fd->offset, CALLBACK_OBJECT( write, _fd ) );
- if( ret == PP_OK_COMPLETIONPENDING ) {
- return;
- }
- }
- }
-
- delete _fd->fio;
- SEMAPHORE_POST();
- } );
- DEFINE_CALLBACK( beginWrite, {
- if( _result == PP_OK ) {
- int ret = _fd->fio->Write( 0, _fd->buffer, _fd->size, CALLBACK_OBJECT( write, _fd ) );
- if( ret == PP_OK_COMPLETIONPENDING ) {
- return;
- }
- }
-
- delete _fd->fio;
- SEMAPHORE_POST();
- } );
- DEFINE_CALLBACK( open, {
- _fd->fio = new pp::FileIO( System::instance );
-
- int ret = _fd->fio->Open( pp::FileRef( *ppFileSystem, _fd->file->filePath ),
- PP_FILEOPENFLAG_WRITE | PP_FILEOPENFLAG_CREATE | PP_FILEOPENFLAG_TRUNCATE,
- CALLBACK_OBJECT( beginWrite, _fd ) );
- if( ret == PP_OK_COMPLETIONPENDING ) {
- return;
- }
+ pp::FileRef file( ppFileSystem, filePath );
+ pp::FileIO fio( System::instance );
- delete _fd->fio;
- SEMAPHORE_POST();
- } );
+ if( fio.Open( file, PP_FILEOPENFLAG_WRITE | PP_FILEOPENFLAG_CREATE | PP_FILEOPENFLAG_TRUNCATE,
+ pp::BlockUntilComplete() ) != PP_OK )
+ {
+ return false;
+ }
- MAIN_CALL( open );
- SEMAPHORE_WAIT();
+ int result;
+ while( offset != size &&
+ ( result = fio.Write( offset, &buffer[offset], size - offset,
+ pp::BlockUntilComplete() ) ) > 0 )
+ {
+ offset += result;
+ }
- if( descriptor->offset != size ) {
+ if( offset != size ) {
return false;
}
@@ -1024,37 +854,8 @@ bool File::mkdir( const char* path, FileSystem fileSystem )
else {
#if defined( __native_client__ )
- Descriptor localDescriptor( nullptr );
- Descriptor* descriptor = &localDescriptor;
-
- // Abuse buffer for file path and size for result.
- descriptor->buffer = const_cast<char*>( path );
- descriptor->size = false;
-
- DEFINE_CALLBACK( mkdirResult, {
- if( _result == PP_OK ) {
- _fd->size = true;
- }
-
- delete _fd->fref;
- SEMAPHORE_POST();
- } );
- DEFINE_CALLBACK( mkdir, {
- _fd->fref = new pp::FileRef( *ppFileSystem, _fd->buffer );
-
- int ret = _fd->fref->MakeDirectory( CALLBACK_OBJECT( mkdirResult, _fd ) );
- if( ret == PP_OK_COMPLETIONPENDING ) {
- return;
- }
-
- delete _fd->fref;
- SEMAPHORE_POST();
- } );
-
- MAIN_CALL( mkdir );
- SEMAPHORE_WAIT();
-
- return descriptor->size != 0;
+ pp::FileRef file( ppFileSystem, path );
+ return file.MakeDirectory( pp::BlockUntilComplete() ) == PP_OK;
#elif defined( _WIN32 )
@@ -1076,37 +877,8 @@ bool File::rm( const char* path, FileSystem fileSystem )
else {
#if defined( __native_client__ )
- Descriptor localDescriptor( nullptr );
- Descriptor* descriptor = &localDescriptor;
-
- // Abuse buffer for file path and size for result.
- descriptor->buffer = const_cast<char*>( path );
- descriptor->size = false;
-
- DEFINE_CALLBACK( rmResult, {
- if( _result == PP_OK ) {
- _fd->size = true;
- }
-
- delete _fd->fref;
- SEMAPHORE_POST();
- } );
- DEFINE_CALLBACK( rm, {
- _fd->fref = new pp::FileRef( *ppFileSystem, _fd->buffer );
-
- int ret = _fd->fref->Delete( CALLBACK_OBJECT( rmResult, _fd ) );
- if( ret == PP_OK_COMPLETIONPENDING ) {
- return;
- }
-
- delete _fd->fref;
- SEMAPHORE_POST();
- } );
-
- MAIN_CALL( rm );
- SEMAPHORE_WAIT();
-
- return descriptor->size != 0;
+ pp::FileRef file( ppFileSystem, path );
+ return file.Delete( pp::BlockUntilComplete() ) == PP_OK;
#elif defined( _WIN32 )
@@ -1187,38 +959,11 @@ void File::init( FileSystem fileSystem, NaClFileSystem naclFileSystem, int naclS
destroy();
- Descriptor* descriptor = &Descriptor::staticDesc;
-
- // We abuse staticDesc.size and staticDesc.offset variables to pass file system type and size to
- // callback.
- descriptor->size = naclSize;
- descriptor->offset = naclFileSystem == PERSISTENT ? PP_FILESYSTEMTYPE_LOCALPERSISTENT :
- PP_FILESYSTEMTYPE_LOCALTEMPORARY;
-
- DEFINE_CALLBACK( initResult, {
- if( _result != PP_OK ) {
- delete ppFileSystem;
- ppFileSystem = nullptr;
- }
- SEMAPHORE_POST();
- } );
- DEFINE_CALLBACK( init, {
- ppFileSystem = new pp::FileSystem( System::instance, PP_FileSystemType( _fd->offset ) );
-
- int ret = ppFileSystem->Open( _fd->size, CALLBACK_OBJECT( initResult, _fd ) );
- if( ret == PP_OK_COMPLETIONPENDING ) {
- return;
- }
+ PP_FileSystemType type = naclFileSystem == PERSISTENT ? PP_FILESYSTEMTYPE_LOCALPERSISTENT :
+ PP_FILESYSTEMTYPE_LOCALTEMPORARY;
- delete ppFileSystem;
- ppFileSystem = nullptr;
- SEMAPHORE_POST();
- } );
-
- MAIN_CALL( init );
- SEMAPHORE_WAIT();
-
- if( ppFileSystem == nullptr ) {
+ ppFileSystem = pp::FileSystem( System::instance, type );
+ if( ppFileSystem.Open( naclSize, pp::BlockUntilComplete() ) != PP_OK ) {
OZ_ERROR( "Local file system open failed" );
}
@@ -1231,25 +976,6 @@ void File::destroy( FileSystem fileSystem )
if( fileSystem == VIRTUAL ) {
PHYSFS_deinit();
}
- else {
-#ifdef __native_client__
-
- if( ppFileSystem != nullptr ) {
- Descriptor* descriptor = &Descriptor::staticDesc;
-
- DEFINE_CALLBACK( free, {
- delete ppFileSystem;
- ppFileSystem = nullptr;
-
- SEMAPHORE_POST();
- } );
-
- MAIN_CALL( free );
- SEMAPHORE_WAIT();
- }
-
-#endif
- }
}
}
View
17 src/ozCore/File.hh
@@ -73,17 +73,12 @@ class File
private:
- struct Descriptor;
-
- String filePath; ///< %File path.
- Type fileType; ///< %File type.
- FileSystem fileFS; ///< %File system type.
- int fileSize; ///< %File size (>= 0 if `fileType == REGULAR`, -1 otherwise).
- long64 fileTime; ///< Modification or creation time, what is newer.
- char* data; ///< Mapped memory.
-#ifdef __native_client__
- Descriptor* descriptor; ///< Structure for control and data exchange with NaCl callbacks.
-#endif
+ String filePath; ///< %File path.
+ Type fileType; ///< %File type.
+ FileSystem fileFS; ///< %File system type.
+ int fileSize; ///< %File size (>= 0 if `fileType == REGULAR`, -1 otherwise).
+ long64 fileTime; ///< Modification or creation time, what is newer.
+ char* data; ///< Mapped memory.
public:
View
100 src/ozCore/SharedLib.cc
@@ -0,0 +1,100 @@
+/*
+ * ozCore - OpenZone Core Library.
+ *
+ * Copyright © 2002-2013 Davorin Učakar
+ *
+ * This software is provided 'as-is', without any express or implied warranty.
+ * In no event will the authors be held liable for any damages arising from
+ * the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software in
+ * a product, an acknowledgement in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+/**
+ * @file ozCore/SharedLib.cc
+ */
+
+#include "SharedLib.hh"
+
+#if defined( __native_client__ )
+#elif defined( _WIN32 )
+# include <windows.h>
+#else
+# include <dlfcn.h>
+#endif
+
+namespace oz
+{
+
+#ifdef __native_client__
+
+const bool SharedLib::SUPPORTED = false;
+
+SharedLib::Method* SharedLib::get( const char* ) const
+{
+ return nullptr;
+}
+
+bool SharedLib::open( const char* )
+{
+ return nullptr;
+}
+
+void SharedLib::close()
+{}
+
+#else
+
+const bool SharedLib::SUPPORTED = true;
+
+SharedLib::Method* SharedLib::get( const char* symbol ) const
+{
+ if( handle == nullptr ) {
+ return nullptr;
+ }
+ else {
+#ifdef _WIN32
+ return reinterpret_cast<Method*>( GetProcAddress( static_cast<HMODULE>( handle ), symbol ) );
+#else
+ Method* method;
+ *( void** ) &method = dlsym( handle, symbol );
+ return method;
+#endif
+ }
+}
+
+bool SharedLib::open( const char* name )
+{
+#ifdef _WIN32
+ handle = static_cast<void*>( LoadLibrary( name ) );
+#else
+ handle = dlopen( name, RTLD_NOW );
+#endif
+ return handle != nullptr;
+}
+
+void SharedLib::close()
+{
+ if( handle != nullptr ) {
+#ifdef _WIN32
+ FreeLibrary( static_cast<HMODULE>( handle ) );
+#else
+ dlclose( handle );
+#endif
+ handle = nullptr;
+ }
+}
+
+#endif
+
+}
View
118 src/ozCore/SharedLib.hh
@@ -0,0 +1,118 @@
+/*
+ * ozCore - OpenZone Core Library.
+ *
+ * Copyright © 2002-2013 Davorin Učakar
+ *
+ * This software is provided 'as-is', without any express or implied warranty.
+ * In no event will the authors be held liable for any damages arising from
+ * the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software in
+ * a product, an acknowledgement in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+/**
+ * @file ozCore/SharedLib.hh
+ *
+ * SharedLib class.
+ */
+
+#pragma once
+
+#include "common.hh"
+
+namespace oz
+{
+
+/**
+ * Class for loading shared libraries.
+ */
+class SharedLib
+{
+ public:
+
+ /**
+ * True iff platform supports shared libraries.
+ */
+ static const bool SUPPORTED;
+
+ /**
+ * Generic method type to avoid casts between pointer-to-function and pointer-to-object.
+ */
+ typedef void Method();
+
+ private:
+
+ void* handle; ///< Internal handle to the library.
+
+ public:
+
+ /**
+ * Create uninitialised instance.
+ */
+ explicit SharedLib() :
+ handle( nullptr )
+ {}
+
+ /**
+ * Destructor, closes library if still opened.
+ */
+ ~SharedLib()
+ {
+ close();
+ }
+
+ /**
+ * Move constructor, transfers ownership.
+ */
+ SharedLib( SharedLib&& l ) :
+ handle( l.handle )
+ {
+ l.handle = nullptr;
+ }
+
+ /**
+ * Move operator, transfers ownership.
+ */
+ SharedLib& operator = ( SharedLib&& l )
+ {
+ handle = l.handle;
+ l.handle = nullptr;
+ return *this;
+ }
+
+ /**
+ * True iff successfully opened.
+ */
+ bool isOpened() const
+ {
+ return handle != nullptr;
+ }
+
+ /**
+ * Obtain pointer to the requested function in the library (`nullptr` on error).
+ */
+ Method* get( const char* symbol ) const;
+
+ /**
+ * Open shared library with the given (file) name.
+ */
+ bool open( const char* name );
+
+ /**
+ * Close library if opened.
+ */
+ void close();
+
+};
+
+}
View
112 src/ozCore/System.cc
@@ -96,32 +96,25 @@ int raise( int )
namespace oz
{
-static const float BELL_TIME = 0.30f;
-static const float BELL_FREQUENCY = 1000.0f;
-static const int BELL_PREFERRED_RATE = 44100;
-
-#if defined( EMSCRIPTEN )
-
-static const timespec TIMESPEC_10MS = { 0, 10 * 1000000 };
-
-#elif defined( __ANDROID__ )
-
-static const timespec TIMESPEC_10MS = { 0, 10 * 1000000 };
+static const float BELL_TIME = 0.30f;
+static const float BELL_FREQUENCY = 1000.0f;
+static const int BELL_PREFERRED_RATE = 44100;
+#ifndef _WIN32
+static const timespec TIMESPEC_10MS = { 0, 10 * 1000000 };
+#endif
-#elif defined( __native_client__ )
+#if defined( __native_client__ )
struct SampleInfo
{
- pp::Audio* audio;
- int nFrameSamples;
- int nSamples;
- int rate;
- int end;
- int offset;
+ int nFrameSamples;
+ int nSamples;
+ int rate;
+ int end;
+ int offset;
};
-static const timespec TIMESPEC_10MS = { 0, 10 * 1000000 };
-static pp::Core* core = nullptr;
+static pp::Core* core = nullptr;
#elif defined( _WIN32 )
@@ -147,11 +140,6 @@ struct Wave
short samples[BELL_WAVE_SAMPLES * 2];
};
-#else
-
-static const timespec TIMESPEC_10MS = { 0, 10 * 1000000 };
-static const pa_sample_spec PA_SAMPLE_SPEC = { PA_SAMPLE_S16NE, BELL_PREFERRED_RATE, 2 };
-
#endif
static volatile int bellLock = 0;
@@ -282,65 +270,47 @@ static void* bellMain( void* )
#elif defined( __native_client__ )
-static void stopBellCallback( void* info_, int )
-{
- SampleInfo* info = static_cast<SampleInfo*>( info_ );
-
- info->audio->StopPlayback();
- info->audio->~Audio();
- free( info->audio );
- free( info );
-
- __sync_lock_release( &bellLock );
-}
-
static void bellPlayCallback( void* buffer, uint, void* info_ )
{
SampleInfo* info = static_cast<SampleInfo*>( info_ );
short* samples = static_cast<short*>( buffer );
if( info->offset >= info->end ) {
- core->CallOnMainThread( 0, pp::CompletionCallback( stopBellCallback, info ) );
+ __sync_lock_release( &bellLock );
+ }
+ else {
+ genBellSamples( samples, info->nSamples, info->rate, info->offset,
+ info->offset + info->nFrameSamples );
+ info->offset += info->nFrameSamples;
}
-
- genBellSamples( samples, info->nSamples, info->rate, info->offset,
- info->offset + info->nFrameSamples );
- info->offset += info->nFrameSamples;
}
-static void bellInitCallback( void*, int )
+static void* bellMain( void* )
{
- SampleInfo* info = static_cast<SampleInfo*>( malloc( sizeof( SampleInfo ) ) );
- if( info == nullptr ) {
- return;
- }
-
PP_AudioSampleRate rate = pp::AudioConfig::RecommendSampleRate( System::instance );
uint nFrameSamples = pp::AudioConfig::RecommendSampleFrameCount( System::instance, rate, 4096 );
- pp::AudioConfig config( System::instance, rate, nFrameSamples );
+ SampleInfo info;
+ info.nFrameSamples = int( nFrameSamples );
+ info.nSamples = Math::lround( BELL_TIME * float( rate ) );
+ info.rate = rate;
+ info.end = info.nSamples + 2*int( nFrameSamples );
+ info.offset = 0;
- info->nFrameSamples = int( nFrameSamples );
- info->nSamples = Math::lround( BELL_TIME * float( rate ) );
- info->rate = rate;
- info->end = info->nSamples + 2*int( nFrameSamples );
- info->offset = 0;
+ pp::AudioConfig config( System::instance, rate, nFrameSamples );
+ pp::Audio audio( System::instance, config, bellPlayCallback, &info );
- void* audioPtr = malloc( sizeof( pp::Audio ) );
- if( audioPtr == nullptr ) {
- free( info );
- return;
+ if( audio.StartPlayback() == PP_FALSE ) {
+ __sync_lock_release( &bellLock );
+ return nullptr;
}
- info->audio = new( audioPtr ) pp::Audio( System::instance, config, bellPlayCallback, info );
- if( info->audio->StartPlayback() == PP_FALSE ) {
- info->audio->~Audio();
- free( info->audio );
- free( info );
-
- __sync_lock_release( &bellLock );
- return;
+ while( bellLock != 0 ) {
+ nanosleep( &TIMESPEC_10MS, nullptr );
}
+
+ audio.StopPlayback();
+ return nullptr;
}
#elif defined( _WIN32 )
@@ -390,6 +360,7 @@ static DWORD WINAPI bellMain( void* )
static void* bellMain( void* )
{
+ const pa_sample_spec PA_SAMPLE_SPEC = { PA_SAMPLE_S16NE, BELL_PREFERRED_RATE, 2 };
#ifndef _GNU_SOURCE
const char* program_invocation_short_name = "liboz";
#endif
@@ -592,14 +563,7 @@ bool System::isInstrumented()
void System::bell()
{
-#if defined( __native_client__ )
-
- if( instance != nullptr && !__sync_lock_test_and_set( &bellLock, 1 ) == 0 ) {
- core = pp::Module::Get()->core();
- core->CallOnMainThread( 0, pp::CompletionCallback( bellInitCallback, nullptr ) );
- }
-
-#elif defined( _WIN32 )
+#ifdef _WIN32
if( __sync_lock_test_and_set( &bellLock, 1 ) == 0 ) {
HANDLE bellThread = CreateThread( nullptr, 0, bellMain, nullptr, 0, nullptr );
View
28 src/ozCore/Thread.cc
@@ -34,10 +34,10 @@
#if defined( __ANDROID__ )
# include <jni.h>
# include <pthread.h>
-// #elif defined( __native_client__ )
-// # include <ppapi/cpp/instance_handle.h>
-// # include <ppapi/cpp/dev/message_loop_dev.h>
-// # include <pthread.h>
+#elif defined( __native_client__ )
+# include <ppapi/cpp/instance_handle.h>
+# include <ppapi/cpp/message_loop.h>
+# include <pthread.h>
#elif defined( _WIN32 )
# include <windows.h>
#else
@@ -157,6 +157,7 @@ void* Thread::Descriptor::threadMain( void* data )
pthread_setspecific( nameKey, descriptor->name );
#if defined( __ANDROID__ )
+
if( System::javaVM == nullptr ) {
OZ_ERROR( "System::javaVM must be set before starting new threads" );
}
@@ -165,24 +166,25 @@ void* Thread::Descriptor::threadMain( void* data )
JavaVM* javaVM = static_cast<JavaVM*>( System::javaVM );
javaVM->AttachCurrentThread( &jniEnv, nullptr );
+
#elif defined( __native_client__ )
- // TODO: Implement MessageLoop?
-// if( System::instance == nullptr ) {
-// OZ_ERROR( "System::instance must be set before starting new threads" );
-// }
-//
-// pp::MessageLoop_Dev messageLoop( *System::instance );
-// messageLoop.AttachToCurrentThread();
+
+ if( System::instance == nullptr ) {
+ OZ_ERROR( "System::instance must be set before starting new threads" );
+ }
+
+ pp::MessageLoop messageLoop( pp::InstanceHandle( System::instance ) );
+ messageLoop.AttachToCurrentThread();
+
#endif
System::threadInit();
+ descriptor->main( descriptor->data );
#ifdef __ANDROID__
javaVM->DetachCurrentThread();
#endif
- descriptor->main( descriptor->data );
-
if( descriptor->type == DETACHED ) {
free( descriptor );
}
View
3  src/ozCore/ozCore.hh
@@ -110,7 +110,8 @@
/*
* Utilities.
*/
-#include "Time.hh"
#include "Log.hh"
+#include "Time.hh"
+#include "SharedLib.hh"
#include "JSON.hh"
#include "Gettext.hh"
View
1  src/ozDynamics/CMakeLists.txt
@@ -6,6 +6,7 @@ add_library( ozDynamics
#BEGIN SOURCES
common.hh
ozDynamics.hh
+ pch.hh
common.cc
collision/AABB.hh
collision/Body.hh
View
17 src/ozDynamics/collision/Body.hh
@@ -55,9 +55,9 @@ class Body
Bounds bb; ///< Cached axis-aligned bounding box in absolute coordinates.
- Point pos; ///< Position.
- Quat rot; ///< Rotation.
- Mat33 rotMat; ///< Cached rotation matrix.
+ Point p; ///< Position.
+ Quat o; ///< Orientation.
+ Mat33 oMat; ///< Cached orientation matrix.
int flags; ///< Flags.
int mask; ///< Collision bitmask.
@@ -98,11 +98,14 @@ class Body
}
}
- Bounds getBounds() const
+ /**
+ * Normalise rotation quaternion and update cached rotation matrix and bounding box.
+ */
+ void update()
{
- hard_assert( bodyShape != nullptr );
-
- return bodyShape->getBounds( pos, rotMat );
+ o = ~o;
+ oMat = Mat33::rotation( o );
+ bb = bodyShape == nullptr ? Bounds( p, p ) : bodyShape->getBounds( p, oMat );
}
OZ_STATIC_POOL_ALLOC( pool )
View
4 src/ozDynamics/collision/Collider.cc
@@ -387,11 +387,11 @@ bool Collider::overlaps( const Body* body0, const Body* body1, Result* result )
if( type0 <= type1 ) {
OverlapFunc* func = dispatchMatrix[type0][type1];
- return func( body0->rotMat, shape0, body1->rotMat, shape1, body1->pos - body0->pos, result );
+ return func( body0->oMat, shape0, body1->oMat, shape1, body1->p - body0->p, result );
}
else {
OverlapFunc* func = dispatchMatrix[type1][type0];
- return func( body1->rotMat, shape1, body0->rotMat, shape0, body0->pos - body1->pos, result );
+ return func( body1->oMat, shape1, body0->oMat, shape0, body0->p - body1->p, result );
}
}
View
12 src/ozDynamics/physics/Physics.cc
@@ -69,8 +69,8 @@ void Physics::add( DBody* body )
body->odeId = dBodyCreate( world );
- dBodySetPosition( body->odeId, body->pos.x, body->pos.y, body->pos.z );
- dBodySetQuaternion( body->odeId, body->rot );
+ dBodySetPosition( body->odeId, body->p.x, body->p.y, body->p.z );
+ dBodySetQuaternion( body->odeId, body->o );
dBodySetMass( body->odeId, &mass );
}
@@ -94,7 +94,7 @@ void Physics::update( float time )
Collider::Result result;
if( collider->overlaps( body0, body1, &result ) ) {
- Point p = Math::mix( body0->pos, body1->pos, 0.5f );
+ Point p = Math::mix( body0->p, body1->p, 0.5f );
// Log() << result.depth << ", " << result.axis << "\n";
@@ -124,9 +124,9 @@ void Physics::update( float time )
DBody* body = static_cast<DBody*>( *i );
if( body->odeId != nullptr ) {
- body->pos = Point( dBodyGetPosition( body->odeId ) );
- body->rot = Quat( dBodyGetQuaternion( body->odeId ) );
- body->rotMat = Mat33::rotation( body->rot );
+ body->p = Point( dBodyGetPosition( body->odeId ) );
+ body->o = Quat( dBodyGetQuaternion( body->odeId ) );
+ body->update();
}
}
}
View
7 src/ozEngine/CMakeLists.txt
@@ -5,8 +5,15 @@ add_library( ozEngine
${CMAKE_CURRENT_BINARY_DIR}/config.hh
#BEGIN SOURCES
common.hh
+ OpenAL.hh
+ OpenGL.hh
ozEngine.hh
+ pch.hh
+ Texture.hh
common.cc
+ OpenAL.cc
+ OpenGL.cc
+ Texture.cc
#END SOURCES
)
target_link_libraries( ozEngine ozDynamics )
View
74 src/ozEngine/OpenAL.cc
@@ -0,0 +1,74 @@
+/*
+ * ozEngine - OpenZone Engine Library.
+ *
+ * Copyright © 2002-2013 Davorin Učakar
+ *
+ * This software is provided 'as-is', without any express or implied warranty.
+ * In no event will the authors be held liable for any damages arising from
+ * the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software in
+ * a product, an acknowledgement in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+/**
+ * @file ozEngine/OpenAL.cc
+ */
+
+#include "OpenAL.hh"
+
+namespace oz
+{
+
+#ifndef NDEBUG
+
+void alCheckError( const char* function, const char* file, int line )
+{
+ const char* message;
+ ALenum result = alGetError();
+
+ switch( result ) {
+ case AL_NO_ERROR: {
+ return;
+ }
+ case AL_INVALID_NAME: {
+ message = "AL_INVALID_NAME";
+ break;
+ }
+ case AL_INVALID_ENUM: {
+ message = "AL_INVALID_ENUM";
+ break;
+ }
+ case AL_INVALID_VALUE: {
+ message = "AL_INVALID_VALUE";
+ break;
+ }
+ case AL_INVALID_OPERATION: {
+ message = "AL_INVALID_OPERATION";
+ break;
+ }
+ case AL_OUT_OF_MEMORY: {
+ message = "AL_OUT_OF_MEMORY";
+ break;
+ }
+ default: {
+ message = String::str( "UNKNOWN(%d)", int( result ) );
+ break;
+ }
+ }
+
+ System::error( function, file, line, 1, "AL error '%s'", message );
+}
+
+#endif
+
+}
View
45 src/ozEngine/OpenAL.hh
@@ -0,0 +1,45 @@
+/*
+ * ozEngine - OpenZone Engine Library.
+ *
+ * Copyright © 2002-2013 Davorin Učakar
+ *
+ * This software is provided 'as-is', without any express or implied warranty.
+ * In no event will the authors be held liable for any damages arising from
+ * the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software in
+ * a product, an acknowledgement in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+/**
+ * @file ozEngine/OpenAL.hh
+ */
+
+#pragma once
+
+#include "client/common.hh"
+
+#include <AL/al.h>
+
+namespace oz
+{
+
+#ifdef NDEBUG
+# define OZ_AL_CHECK_ERROR() void( 0 )
+#else
+# define OZ_AL_CHECK_ERROR() oz::client::alCheckError( __PRETTY_FUNCTION__, __FILE__, __LINE__ )
+
+void alCheckError( const char* function, const char* file, int line );
+
+#endif
+
+}
View
229 src/ozEngine/OpenGL.cc
@@ -0,0 +1,229 @@
+/*
+ * ozEngine - OpenZone Engine Library.
+ *
+ * Copyright © 2002-2013 Davorin Učakar
+ *
+ * This software is provided 'as-is', without any express or implied warranty.
+ * In no event will the authors be held liable for any damages arising from
+ * the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software in
+ * a product, an acknowledgement in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+/**
+ * @file ozEngine/OpenGL.cc
+ */
+
+#include "OpenGL.hh"
+
+#include <SDL.h>
+
+namespace oz
+{
+
+#ifdef _WIN32
+
+OZ_DL_DEFINE( glUniform1i );
+OZ_DL_DEFINE( glUniform2i );
+OZ_DL_DEFINE( glUniform3i );
+OZ_DL_DEFINE( glUniform4i );
+OZ_DL_DEFINE( glUniform1iv );
+OZ_DL_DEFINE( glUniform2iv );
+OZ_DL_DEFINE( glUniform3iv );
+OZ_DL_DEFINE( glUniform4iv );
+OZ_DL_DEFINE( glUniform1f );
+OZ_DL_DEFINE( glUniform2f );
+OZ_DL_DEFINE( glUniform3f );
+OZ_DL_DEFINE( glUniform4f );
+OZ_DL_DEFINE( glUniform1fv );
+OZ_DL_DEFINE( glUniform2fv );
+OZ_DL_DEFINE( glUniform3fv );
+OZ_DL_DEFINE( glUniform4fv );
+OZ_DL_DEFINE( glUniformMatrix2fv );
+OZ_DL_DEFINE( glUniformMatrix3fv );
+OZ_DL_DEFINE( glUniformMatrix4fv );
+
+OZ_DL_DEFINE( glEnableVertexAttribArray );
+OZ_DL_DEFINE( glVertexAttribPointer );
+OZ_DL_DEFINE( glDrawRangeElements );
+
+OZ_DL_DEFINE( glGenBuffers );
+OZ_DL_DEFINE( glDeleteBuffers );
+OZ_DL_DEFINE( glBindBuffer );
+OZ_DL_DEFINE( glBufferData );
+OZ_DL_DEFINE( glMapBuffer );
+OZ_DL_DEFINE( glUnmapBuffer );
+
+OZ_DL_DEFINE( glCreateShader );
+OZ_DL_DEFINE( glDeleteShader );
+OZ_DL_DEFINE( glShaderSource );
+OZ_DL_DEFINE( glCompileShader );
+OZ_DL_DEFINE( glGetShaderiv );
+OZ_DL_DEFINE( glGetShaderInfoLog );
+OZ_DL_DEFINE( glCreateProgram );
+OZ_DL_DEFINE( glDeleteProgram );
+OZ_DL_DEFINE( glAttachShader );
+OZ_DL_DEFINE( glDetachShader );
+OZ_DL_DEFINE( glLinkProgram );
+OZ_DL_DEFINE( glGetProgramiv );
+OZ_DL_DEFINE( glGetProgramInfoLog );
+OZ_DL_DEFINE( glGetUniformLocation );
+OZ_DL_DEFINE( glBindAttribLocation );
+OZ_DL_DEFINE( glUseProgram );
+
+OZ_DL_DEFINE( glActiveTexture );
+OZ_DL_DEFINE( glCompressedTexImage2D );
+OZ_DL_DEFINE( glGetCompressedTexImage );
+
+OZ_DL_DEFINE( glGenerateMipmapEXT );
+OZ_DL_DEFINE( glGenRenderbuffersEXT );
+OZ_DL_DEFINE( glDeleteRenderbuffersEXT );
+OZ_DL_DEFINE( glBindRenderbufferEXT );
+OZ_DL_DEFINE( glRenderbufferStorageEXT );
+OZ_DL_DEFINE( glGenFramebuffersEXT );
+OZ_DL_DEFINE( glDeleteFramebuffersEXT );
+OZ_DL_DEFINE( glBindFramebufferEXT );
+OZ_DL_DEFINE( glFramebufferRenderbufferEXT );
+OZ_DL_DEFINE( glFramebufferTexture2DEXT );
+OZ_DL_DEFINE( glCheckFramebufferStatusEXT );
+
+#endif
+
+#ifndef NDEBUG
+
+void glCheckError( const char* function, const char* file, int line )
+{
+ const char* message;
+ GLenum result = glGetError();
+
+ switch( result ) {
+ case GL_NO_ERROR: {
+ return;
+ }
+ case GL_INVALID_ENUM: {
+ message = "GL_INVALID_ENUM";
+ break;
+ }
+ case GL_INVALID_VALUE: {
+ message = "GL_INVALID_VALUE";
+ break;
+ }
+ case GL_INVALID_OPERATION: {
+ message = "GL_INVALID_OPERATION";
+ break;
+ }
+# ifdef GL_STACK_OVERFLOW
+ case GL_STACK_OVERFLOW: {
+ message = "GL_STACK_OVERFLOW";
+ break;
+ }
+# endif
+# ifdef GL_STACK_UNDERFLOW
+ case GL_STACK_UNDERFLOW: {
+ message = "GL_STACK_UNDERFLOW";
+ break;
+ }
+# endif
+ case GL_OUT_OF_MEMORY: {
+ message = "GL_OUT_OF_MEMORY";
+ break;
+ }
+# ifdef GL_TABLE_TOO_LARGE
+ case GL_TABLE_TOO_LARGE: {
+ message = "GL_TABLE_TOO_LARGE";
+ break;
+ }
+# endif
+ default: {
+ message = String::str( "UNKNOWN(%d)", int( result ) );
+ break;
+ }
+ }
+
+ System::error( function, file, line, 1, "GL error '%s'", message );
+}
+
+#endif
+
+void glInit()
+{
+#ifdef _WIN32
+
+ OZ_DL_GLLOAD( glUniform1i );
+ OZ_DL_GLLOAD( glUniform2i );
+ OZ_DL_GLLOAD( glUniform3i );
+ OZ_DL_GLLOAD( glUniform4i );
+ OZ_DL_GLLOAD( glUniform1iv );
+ OZ_DL_GLLOAD( glUniform2iv );
+ OZ_DL_GLLOAD( glUniform3iv );
+ OZ_DL_GLLOAD( glUniform4iv );
+ OZ_DL_GLLOAD( glUniform1f );
+ OZ_DL_GLLOAD( glUniform2f );
+ OZ_DL_GLLOAD( glUniform3f );
+ OZ_DL_GLLOAD( glUniform4f );
+ OZ_DL_GLLOAD( glUniform1fv );
+ OZ_DL_GLLOAD( glUniform2fv );
+ OZ_DL_GLLOAD( glUniform3fv );
+ OZ_DL_GLLOAD( glUniform4fv );
+ OZ_DL_GLLOAD( glUniformMatrix2fv );
+ OZ_DL_GLLOAD( glUniformMatrix3fv );
+ OZ_DL_GLLOAD( glUniformMatrix4fv );
+
+ OZ_DL_GLLOAD( glEnableVertexAttribArray );
+ OZ_DL_GLLOAD( glVertexAttribPointer );
+ OZ_DL_GLLOAD( glDrawRangeElements );
+
+ OZ_DL_GLLOAD( glGenBuffers );
+ OZ_DL_GLLOAD( glDeleteBuffers );
+ OZ_DL_GLLOAD( glBindBuffer );
+ OZ_DL_GLLOAD( glBufferData );
+ OZ_DL_GLLOAD( glMapBuffer );
+ OZ_DL_GLLOAD( glUnmapBuffer );
+
+ OZ_DL_GLLOAD( glCreateShader );
+ OZ_DL_GLLOAD( glDeleteShader );
+ OZ_DL_GLLOAD( glShaderSource );
+ OZ_DL_GLLOAD( glCompileShader );
+ OZ_DL_GLLOAD( glGetShaderiv );
+ OZ_DL_GLLOAD( glGetShaderInfoLog );
+ OZ_DL_GLLOAD( glCreateProgram );
+ OZ_DL_GLLOAD( glDeleteProgram );
+ OZ_DL_GLLOAD( glAttachShader );
+ OZ_DL_GLLOAD( glDetachShader );
+ OZ_DL_GLLOAD( glLinkProgram );
+ OZ_DL_GLLOAD( glGetProgramiv );
+ OZ_DL_GLLOAD( glGetProgramInfoLog );
+ OZ_DL_GLLOAD( glGetUniformLocation );
+ OZ_DL_GLLOAD( glBindAttribLocation );
+ OZ_DL_GLLOAD( glUseProgram );
+
+ OZ_DL_GLLOAD( glActiveTexture );
+ OZ_DL_GLLOAD( glCompressedTexImage2D );
+ OZ_DL_GLLOAD( glGetCompressedTexImage );
+
+ OZ_DL_GLLOAD( glGenerateMipmapEXT );
+ OZ_DL_GLLOAD( glGenRenderbuffersEXT );
+ OZ_DL_GLLOAD( glDeleteRenderbuffersEXT );
+ OZ_DL_GLLOAD( glBindRenderbufferEXT );
+ OZ_DL_GLLOAD( glRenderbufferStorageEXT );
+ OZ_DL_GLLOAD( glGenFramebuffersEXT );
+ OZ_DL_GLLOAD( glDeleteFramebuffersEXT );
+ OZ_DL_GLLOAD( glBindFramebufferEXT );
+ OZ_DL_GLLOAD( glFramebufferRenderbufferEXT );
+ OZ_DL_GLLOAD( glFramebufferTexture2DEXT );
+ OZ_DL_GLLOAD( glCheckFramebufferStatusEXT );
+
+#endif
+}
+
+}
View
137 src/ozEngine/OpenGL.hh
@@ -0,0 +1,137 @@
+/*
+ * ozEngine - OpenZone Engine Library.
+ *
+ * Copyright © 2002-2013 Davorin Učakar
+ *
+ * This software is provided 'as-is', without any express or implied warranty.
+ * In no event will the authors be held liable for any damages arising from
+ * the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software in
+ * a product, an acknowledgement in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+/**
+ * @file ozEngine/OpenGL.hh
+ */
+
+#pragma once
+
+#include "common.hh"
+
+#ifdef OZ_GLES
+# include <GLES2/gl2.h>
+#else
+# define GL_GLEXT_PROTOTYPES
+# include <SDL_opengl.h>
+#endif
+
+// Floating-point texture formats.
+#ifndef GL_VERSION_3_0
+# define GL_RGBA32F 0x8814
+# define GL_RGB32F 0x8815
+# define GL_RGBA16F 0x881A
+# define GL_RGB16F 0x881B
+#endif
+
+// S3 texture compression formats.
+#ifndef GL_EXT_texture_compression_s3tc
+# define GL_EXT_texture_compression_s3tc
+# define GL_COMPRESSED_RGB_S3TC_DXT1_EXT 0x83F0
+# define GL_COMPRESSED_RGBA_S3TC_DXT1_EXT 0x83F1
+# define GL_COMPRESSED_RGBA_S3TC_DXT3_EXT 0x83F2
+# define GL_COMPRESSED_RGBA_S3TC_DXT5_EXT 0x83F3
+#endif
+
+namespace oz
+{
+
+#ifdef _WIN32
+
+extern OZ_DL_DECLARE( glUniform1i );
+extern OZ_DL_DECLARE( glUniform2i );
+extern OZ_DL_DECLARE( glUniform3i );
+extern OZ_DL_DECLARE( glUniform4i );
+extern OZ_DL_DECLARE( glUniform1iv );
+extern OZ_DL_DECLARE( glUniform2iv );
+extern OZ_DL_DECLARE( glUniform3iv );
+extern OZ_DL_DECLARE( glUniform4iv );
+extern OZ_DL_DECLARE( glUniform1f );
+extern OZ_DL_DECLARE( glUniform2f );
+extern OZ_DL_DECLARE( glUniform3f );
+extern OZ_DL_DECLARE( glUniform4f );
+extern OZ_DL_DECLARE( glUniform1fv );
+extern OZ_DL_DECLARE( glUniform2fv );
+extern OZ_DL_DECLARE( glUniform3fv );
+extern OZ_DL_DECLARE( glUniform4fv );
+extern OZ_DL_DECLARE( glUniformMatrix2fv );
+extern OZ_DL_DECLARE( glUniformMatrix3fv );
+extern OZ_DL_DECLARE( glUniformMatrix4fv );
+
+extern OZ_DL_DECLARE( glEnableVertexAttribArray );
+extern OZ_DL_DECLARE( glVertexAttribPointer );
+extern OZ_DL_DECLARE( glDrawRangeElements );
+
+extern OZ_DL_DECLARE( glGenBuffers );
+extern OZ_DL_DECLARE( glDeleteBuffers );
+extern OZ_DL_DECLARE( glBindBuffer );
+extern OZ_DL_DECLARE( glBufferData );
+extern OZ_DL_DECLARE( glMapBuffer );
+extern OZ_DL_DECLARE( glUnmapBuffer );
+
+extern OZ_DL_DECLARE( glCreateShader );
+extern OZ_DL_DECLARE( glDeleteShader );
+extern OZ_DL_DECLARE( glShaderSource );
+extern OZ_DL_DECLARE( glCompileShader );
+extern OZ_DL_DECLARE( glGetShaderiv );
+extern OZ_DL_DECLARE( glGetShaderInfoLog );
+extern OZ_DL_DECLARE( glCreateProgram );
+extern OZ_DL_DECLARE( glDeleteProgram );
+extern OZ_DL_DECLARE( glAttachShader );
+extern OZ_DL_DECLARE( glDetachShader );
+extern OZ_DL_DECLARE( glLinkProgram );
+extern OZ_DL_DECLARE( glGetProgramiv );
+extern OZ_DL_DECLARE( glGetProgramInfoLog );
+extern OZ_DL_DECLARE( glGetUniformLocation );
+extern OZ_DL_DECLARE( glBindAttribLocation );
+extern OZ_DL_DECLARE( glUseProgram );
+
+extern OZ_DL_DECLARE( glActiveTexture );
+extern OZ_DL_DECLARE( glCompressedTexImage2D );
+extern OZ_DL_DECLARE( glGetCompressedTexImage );
+
+extern OZ_DL_DECLARE( glGenerateMipmapEXT );
+extern OZ_DL_DECLARE( glGenRenderbuffersEXT );
+extern OZ_DL_DECLARE( glDeleteRenderbuffersEXT );
+extern OZ_DL_DECLARE( glBindRenderbufferEXT );
+extern OZ_DL_DECLARE( glRenderbufferStorageEXT );
+extern OZ_DL_DECLARE( glGenFramebuffersEXT );
+extern OZ_DL_DECLARE( glDeleteFramebuffersEXT );
+extern OZ_DL_DECLARE( glBindFramebufferEXT );
+extern OZ_DL_DECLARE( glFramebufferRenderbufferEXT );
+extern OZ_DL_DECLARE( glFramebufferTexture2DEXT );
+extern OZ_DL_DECLARE( glCheckFramebufferStatusEXT );
+
+#endif
+
+#ifdef NDEBUG
+# define OZ_GL_CHECK_ERROR() void( 0 )
+#else
+# define OZ_GL_CHECK_ERROR() oz::client::glCheckError( __PRETTY_FUNCTION__, __FILE__, __LINE__ )
+
+void glCheckError( const char* function, const char* file, int line );
+
+#endif
+
+void glInit();
+
+}
View
53 src/ozEngine/Texture.cc
@@ -0,0 +1,53 @@
+/*
+ * ozEngine - OpenZone Engine Library.
+ *
+ * Copyright © 2002-2013 Davorin Učakar
+ *
+ * This software is provided 'as-is', without any express or implied warranty.
+ * In no event will the authors be held liable for any damages arising from
+ * the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software in
+ * a product, an acknowledgement in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+/**
+ * @file ozEngine/Texture.cc
+ */
+
+#include "Texture.hh"
+
+#include "OpenGL.hh"
+
+namespace oz
+{
+
+Texture::Texture() :
+ id( 0 ), flags( 0 )
+{}
+
+Texture::~Texture()
+{
+ destroy();
+}
+
+void Texture::destroy()
+{
+ if( flags & UPLOADED_BIT ) {
+ glDeleteTextures( 1, &id );
+
+ id = 0;
+ flags &= ~UPLOADED_BIT;
+ }
+}
+
+}
View
104 src/ozEngine/Texture.hh
@@ -0,0 +1,104 @@
+/*
+ * ozEngine - OpenZone Engine Library.
+ *
+ * Copyright © 2002-2013 Davorin Učakar
+ *
+ * This software is provided 'as-is', without any express or implied warranty.
+ * In no event will the authors be held liable for any damages arising from
+ * the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software in
+ * a product, an acknowledgement in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+/**
+ * @file ozEngine/Texture.hh
+ */
+
+#pragma once
+
+#include "common.hh"
+
+namespace oz
+{
+
+class Texture
+{
+ public:
+
+ /**
+ * Flag bit telling the texture is uploaded to the graphic card.
+ */
+ static const int UPLOADED_BIT = 0x01;
+
+ /**
+ * Build option bit enabling highest quality scaling and compression.
+ */
+ static const int QUALITY_BIT = 0x01;
+
+ /**
+ * Build option bit enabling texture compression (must be compiled with libsquish).
+ */
+ static const int COMPRESSION_BIT = 0x02;
+
+ public:
+
+ uint id; ///< OpenGL texture id.
+ int flags; ///< Texture flags.
+
+ public:
+
+ /**
+ * Load texture components from files and convert it to OpenZone format.
+ *
+ * Texture is loaded from different files representing texture diffuse colour (none or "_d"
+ * suffix), normal map ("_n", "_nm", "_normal" or "_local" suffix), specular ("_spec" suffix or
+ * red component in "_m" suffixed image) and emission masks (".blend" suffix or green component
+ * in "_m" suffixed image. png, jpg, jpeg, tga and bmp file extensions are recognised (must be
+ * lower-case).
+ *
+ * Quality of texture compression and texture scaling can be controlled via `options` parameter.
+ * `QUALITY_BIT` enables highest quality but slow methods for scaling texture to smaller
+ * dimensions used for mipmaps and for texture compression if enabled. `COMPRESSION_BIT` enables
+ * S3TC texture compression, DXT1 and DXT5 for textures without and with alpha channel
+ * respectively.
+ *
+ * @param fs file system type.
+ * @param path path to texture files, without suffixes and extensions.
+ * @param options bit-mask to control quality and compression.
+ * @param ostream stream to write texture to.
+ */
+ static bool build( File::FileSystem fs, const char* path, int options, OutputStream* ostream );
+
+ /**
+ * Create new empty instance.
+ */
+ explicit Texture();
+
+ /**
+ * Destructor, unloads texture from graphics card if loaded.
+ */
+ ~Texture();
+
+ /**
+ * Upload texture in OpenZone format to graphics card.
+ */
+ bool upload( InputStream* istream );
+
+ /**
+ * Unload texture from graphics card if uploaded.
+ */
+ void destroy();
+
+};
+
+}
View
1  src/ozEngine/common.hh
@@ -27,3 +27,4 @@
#pragma once
#include "pch.hh"
+#include <ozEngine/config.hh>
View
3  src/ozEngine/config.hh.in
@@ -25,3 +25,6 @@
/*
* Configuration variables
*/
+
+// Use OpenGL ES 2.0 instead of OpenGL 2.1.
+#cmakedefine OZ_GLES
View
6 src/tests/CMakeLists.txt
@@ -2,12 +2,6 @@ if( NOT OZ_TESTS )
return()
endif()
-# pkg_check_modules( COLLADA collada-dom )
-# include_directories( SYSTEM /usr/include/collada-dom2.4 )
-# include_directories( SYSTEM /usr/include/collada-dom2.4/1.4 )
-# add_executable( collada collada.cc )
-# target_link_libraries( collada ozCore ${COLLADA_LIBRARIES} boost_system )
-
add_executable( foreach foreach.cc )
target_link_libraries( foreach ozCore )
View
54 src/tests/collada.cc
@@ -1,54 +0,0 @@
-/*
- * OpenZone - simple cross-platform FPS/RTS game engine.
- *
- * Copyright © 2002-2013 Davorin Učakar
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/**
- * @file tests/collada.cc
- */
-
-#include <ozCore/ozCore.hh>
-
-#include <dae.h>
-#include <1.4/dom/domCOLLADA.h>
-
-using namespace oz;
-using namespace ColladaDOM141;
-
-int main()
-{
- System::init();
-
- File file( File::NATIVE, "/home/davorin/untitled.dae" );
-
- DAE dae;
- domElement* root = dae.open( file.path().cstr() );
- hard_assert( root != nullptr );
- domCOLLADA* dom = static_cast<domCOLLADA*>( dae.getDom( file.name() ) );
- hard_assert( dom != nullptr );
-
- auto geometries = dom->getLibrary_geometries_array();
- for( size_t i = 0; i < geometries.getCount(); ++i ) {
- Log() << "Geometry #" << i << ": " << geometries[i]->getName() << "\n";
-
- auto meshes = geometries[i]->getGeometry_array();
- for( size_t j = 0; j < meshes.getCount(); ++j ) {
- Log() << "+ Mesh #" << j << ": " << meshes[j]->getName() << "\n";
- }
- }
- return 0;
-}
View
1  src/tests/test.cc
@@ -186,6 +186,7 @@ struct Foo : Resource
int main()
{
System::init();
+ System::bell();
Ref<Foo> foo = new Foo();
Ref<Foo> bar = foo;
View
5 src/tools/openzone.cc
@@ -56,7 +56,7 @@ static void crashHandler()
#if defined( __ANDROID__ )
void Java_com_github_ducakar_openzone_SDLActivity_nativeInit( JNIEnv* env, jclass clazz )
#elif defined( __native_client__ )
-void MainInstance::mainThreadMain( void* instance )
+void MainInstance::mainThreadMain( void* )
#elif defined( _WIN32 )
int SDL_main( int argc, char** argv )
#else
@@ -67,8 +67,6 @@ int main( int argc, char** argv )
JavaVM* javaVM;
env->GetJavaVM( &javaVM );
System::javaVM = javaVM;
-#elif defined( __native_client__ )
- System::instance = static_cast<pp::Instance*>( instance );
#endif
System::init( System::DEFAULT_MASK, &crashHandler );
@@ -125,6 +123,7 @@ int main( int argc, char** argv )
MainInstance::MainInstance( PP_Instance instance_ ) :
pp::Instance( instance_ ), pp::MouseLock( this ), fullscreen( this )
{
+ System::instance = static_cast<pp::Instance*>( this );
NaClPlatform::init();
RequestInputEvents( PP_INPUTEVENT_CLASS_KEYBOARD | PP_INPUTEVENT_CLASS_MOUSE |
View
4 src/tools/ozGettext.cc
@@ -66,8 +66,6 @@ static void readBSP( const File& file )
titles.include( file.baseName(), file.path() );