Skip to content
Browse files

Events for bot gestures, Window++, Math::index1()

- ozCore
  * JSON::clear() returns true on unused variable warning
  * Math::index1()
- ozEngine
  * Window++
- common
  * posWrap(), posDiff() for toroidal world
- matrix
  * events (sounds) for all gestures
  * partial toroidal world support
  • Loading branch information...
1 parent a34e9a0 commit a5a69f0cb69a3546dc70e833630c1bfcf81458d2 @ducakar committed Apr 7, 2013
View
2 build.sh
@@ -15,7 +15,7 @@
buildType=Debug
platforms=(
-# Linux-x86_64
+ Linux-x86_64
Linux-x86_64-Clang
# Linux-i686
# Linux-i686-Clang
View
10 data/oz_main/class/bauul.json
@@ -60,12 +60,12 @@
"hit": "oz/land",
"land": "oz/land",
"splash": "free/splash1",
- "jump": "aard/jump",
- "melee": "aard/tak",
- "flip": "ppm/deathb",
- "death": "ppm/deathb",
"step": "openarena/boot4",
"waterStep": "openarena/splash1",
- "swimSurface": "openarena/watr_in"
+ "swimSurface": "openarena/watr_in",
+ "death": "ppm/deathb",
+ "jump": "aard/jump",
+ "melee": "aard/tak",
+ "flip": "ppm/deathb"
}
}
View
8 data/oz_main/class/beast.json
@@ -42,11 +42,11 @@
"hit": "oz/land",
"land": "oz/land",
"splash": "free/splash1",
- "jump": "aard/jump",
- "flip": "ppm/deathb",
- "death": "ppm/deathb",
"step": "openarena/boot4",
"waterStep": "openarena/splash1",
- "swimSurface": "openarena/watr_in"
+ "swimSurface": "openarena/watr_in",
+ "death": "ppm/deathb",
+ "jump": "aard/jump",
+ "flip": "ppm/deathb"
}
}
View
8 data/oz_main/class/cyborg.json
@@ -66,11 +66,11 @@
"hit": "oz/land",
"land": "oz/land",
"splash": "free/splash1",
- "jump": "aard/jump",
- "flip": "ppm/deathb",
- "death": "ppm/deathb",
"step": "openarena/boot4",
"waterStep": "openarena/splash1",
- "swimSurface": "openarena/watr_in"
+ "swimSurface": "openarena/watr_in",
+ "death": "ppm/deathb",
+ "jump": "aard/jump",
+ "flip": "ppm/deathb"
}
}
View
8 data/oz_main/class/droid.OOM-9.json
@@ -58,11 +58,11 @@
"hit": "droid-sounds/fall2",
"land": "droid-sounds/fall1",
"splash": "free/splash1",
- "jump": "droid-sounds/pain50_1",
- "flip": "droid-sounds/death4",
- "death": "droid-sounds/death2",
"step": "openarena/boot4",
"waterStep": "openarena/splash1",
- "swimSurface": "openarena/watr_in"
+ "swimSurface": "openarena/watr_in",
+ "death": "droid-sounds/death2",
+ "jump": "droid-sounds/pain50_1",
+ "flip": "droid-sounds/death4"
}
}
View
8 data/oz_main/class/droid.json
@@ -60,11 +60,11 @@
"hit": "droid-sounds/fall2",
"land": "droid-sounds/fall1",
"splash": "free/splash1",
- "jump": "droid-sounds/pain50_1",
- "flip": "droid-sounds/death4",
- "death": "droid-sounds/death2",
"step": "openarena/boot4",
"waterStep": "openarena/splash1",
- "swimSurface": "openarena/watr_in"
+ "swimSurface": "openarena/watr_in",
+ "death": "droid-sounds/death2",
+ "jump": "droid-sounds/pain50_1",
+ "flip": "droid-sounds/death4"
}
}
View
10 data/oz_main/class/goblin.json
@@ -57,12 +57,12 @@
"hit": "oz/land",
"land": "oz/land",
"splash": "free/splash1",
- "jump": "aard/jump",
- "melee": "aard/tak",
- "flip": "ppm/deathd",
- "death": "ppm/deathd",
"step": "openarena/boot4",
"waterStep": "openarena/splash1",
- "swimSurface": "openarena/watr_in"
+ "swimSurface": "openarena/watr_in",
+ "death": "ppm/deathd",
+ "jump": "aard/jump",
+ "melee": "aard/tak",
+ "flip": "ppm/deathd"
}
}
View
10 data/oz_main/class/knight.json
@@ -40,12 +40,12 @@
"hit": "oz/land",
"land": "oz/land",
"splash": "free/splash1",
- "jump": "aard/jump",
- "melee": "aard/tak",
- "flip": "ppm/deathb",
- "death": "ppm/deathb",
"step": "openarena/boot4",
"waterStep": "openarena/splash1",
- "swimSurface": "openarena/watr_in"
+ "swimSurface": "openarena/watr_in",
+ "death": "ppm/deathb",
+ "jump": "aard/jump",
+ "melee": "aard/tak",
+ "flip": "ppm/deathb"
}
}
View
14 data/oz_main/class/zombie.json
@@ -38,12 +38,16 @@
"hit": "oz/land",
"land": "oz/land",
"splash": "free/splash1",
- "jump": "aard/jump",
- "melee": "aard/tak",
- "flip": "aard/grunt1",
- "death": "aard/die1",
"step": "openarena/boot4",
"waterStep": "openarena/splash1",
- "swimSurface": "openarena/watr_in"
+ "swimSurface": "openarena/watr_in",
+ "death": "aard/die1",
+ "jump": "aard/jump",
+ "melee": "aard/tak",
+ "point": "aard/grunt1",
+ "fallBack": "aard/grunt1",
+ "salute": "aard/grunt1",
+ "wave": "aard/grunt1",
+ "flip": "aard/grunt1"
}
}
View
6 etc/patches/lua-5.2.1.patch → etc/patches/lua-5.2.2.patch
@@ -1,6 +1,6 @@
-diff -Naur lua-5.2.1/src/llex.c lua-5.2.1-android/src/llex.c
---- lua-5.2.1/src/llex.c 2012-01-24 00:05:51.000000000 +0100
-+++ lua-5.2.1-android/src/llex.c 2012-10-14 01:05:28.384042154 +0200
+diff -Naur lua-5.2.2.orig/src/llex.c lua-5.2.2/src/llex.c
+--- lua-5.2.2.orig/src/llex.c 2013-03-16 22:10:18.000000000 +0100
++++ lua-5.2.2/src/llex.c 2013-04-03 18:42:00.327551527 +0200
@@ -211,7 +211,7 @@
*/
static void trydecpoint (LexState *ls, SemInfo *seminfo) {
View
6 ports.sh
@@ -365,7 +365,7 @@ function fetch()
fi
# Lua
- download 'http://www.lua.org/ftp/lua-5.2.1.tar.gz'
+ download 'http://www.lua.org/ftp/lua-5.2.2.tar.gz'
# LuaJIT
# download 'http://luajit.org/download/LuaJIT-2.0.0.tar.gz'
@@ -486,8 +486,8 @@ function build_physfs()
function build_lua()
{
- prepare lua-5.2.1 lua-5.2.1.tar.gz || return
- applyPatches lua-5.2.1.patch
+ prepare lua-5.2.2 lua-5.2.2.tar.gz || return
+ applyPatches lua-5.2.2.patch
make -j4 CC="$CC" AR="$AR rcu" RANLIB="$RANLIB" CFLAGS="$CFLAGS" PLAT="generic" MYLIBS="$LDFLAGS"
make INSTALL_TOP="$buildDir/usr" install
View
30 src/builder/Class.cc
@@ -359,31 +359,43 @@ void Class::fillBot( const char* className )
fillDynamic( className );
flags |= Object::BOT_BIT | Object::CYLINDER_BIT | Object::UPDATE_FUNC_BIT;
- // we don't allow browsing bots' inventory as long as they are alive
+ // We don't allow browsing a bot's inventory as long as one is alive.
flags &= ~Object::BROWSABLE_BIT;
life *= 2.0f;
if( !audioType.isEmpty() ) {
const JSON& soundsConfig = config["audioSounds"];
- audioSounds[Bot::EVENT_JUMP] = soundsConfig["jump"].get( "" );
- audioSounds[Bot::EVENT_MELEE] = soundsConfig["melee"].get( "" );
- audioSounds[Bot::EVENT_FLIP] = soundsConfig["flip"].get( "" );
- audioSounds[Bot::EVENT_DEATH] = soundsConfig["death"].get( "" );
audioSounds[Bot::EVENT_STEP] = soundsConfig["step"].get( "" );
audioSounds[Bot::EVENT_WATERSTEP] = soundsConfig["waterStep"].get( "" );
audioSounds[Bot::EVENT_SWIM_SURFACE] = soundsConfig["swimSurface"].get( "" );
audioSounds[Bot::EVENT_SWIM_SUBMERGED] = soundsConfig["swimSubmerged"].get( "" );
- context.usedSounds.include( audioSounds[Bot::EVENT_JUMP] );
- context.usedSounds.include( audioSounds[Bot::EVENT_MELEE] );
- context.usedSounds.include( audioSounds[Bot::EVENT_FLIP] );
- context.usedSounds.include( audioSounds[Bot::EVENT_DEATH] );
+ audioSounds[Bot::EVENT_DEATH] = soundsConfig["death"].get( "" );
+ audioSounds[Bot::EVENT_JUMP] = soundsConfig["jump"].get( "" );
+ audioSounds[Bot::EVENT_MELEE] = soundsConfig["melee"].get( "" );
+
+ audioSounds[Bot::EVENT_POINT] = soundsConfig["point"].get( "" );
+ audioSounds[Bot::EVENT_FALL_BACK] = soundsConfig["fallBack"].get( "" );
+ audioSounds[Bot::EVENT_SALUTE] = soundsConfig["salute"].get( "" );
+ audioSounds[Bot::EVENT_WAVE] = soundsConfig["wave"].get( "" );
+ audioSounds[Bot::EVENT_FLIP] = soundsConfig["flip"].get( "" );
+
context.usedSounds.include( audioSounds[Bot::EVENT_STEP] );
context.usedSounds.include( audioSounds[Bot::EVENT_WATERSTEP] );
context.usedSounds.include( audioSounds[Bot::EVENT_SWIM_SURFACE] );
context.usedSounds.include( audioSounds[Bot::EVENT_SWIM_SUBMERGED] );
+
+ context.usedSounds.include( audioSounds[Bot::EVENT_DEATH] );
+ context.usedSounds.include( audioSounds[Bot::EVENT_JUMP] );
+ context.usedSounds.include( audioSounds[Bot::EVENT_MELEE] );
+
+ context.usedSounds.include( audioSounds[Bot::EVENT_POINT] );
+ context.usedSounds.include( audioSounds[Bot::EVENT_FALL_BACK] );
+ context.usedSounds.include( audioSounds[Bot::EVENT_SALUTE] );
+ context.usedSounds.include( audioSounds[Bot::EVENT_WAVE] );
+ context.usedSounds.include( audioSounds[Bot::EVENT_FLIP] );
}
state = 0;
View
3 src/client/Caelum.cc
@@ -112,7 +112,8 @@ void Caelum::draw()
glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, ibo );
glEnableVertexAttribArray( Attrib::POSITION );
- glVertexAttribPointer( Attrib::POSITION, 3, GL_FLOAT, GL_FALSE, sizeof( float[3] ), nullptr );
+ glVertexAttribPointer( Attrib::POSITION, 3, GL_FLOAT, GL_FALSE, int( sizeof( float[3] ) ),
+ nullptr );
glDrawElements( GL_TRIANGLE_STRIP, MAX_STARS * 6, GL_UNSIGNED_SHORT, nullptr );
View
2 src/client/MD2.cc
@@ -107,7 +107,7 @@ MD2::AnimType MD2::AnimState::extractAnim()
if( bot->state & Bot::GESTURE_POINT_BIT ) {
return ANIM_POINT;
}
- else if( bot->state & Bot::GESTURE_BACK_BIT ) {
+ else if( bot->state & Bot::GESTURE_FALL_BACK_BIT ) {
return ANIM_FALLBACK;
}
else if( bot->state & Bot::GESTURE_SALUTE_BIT ) {
View
6 src/client/Mesh.cc
@@ -36,15 +36,15 @@ namespace client
void Vertex::setFormat()
{
glEnableVertexAttribArray( Attrib::POSITION );
- glVertexAttribPointer( Attrib::POSITION, 3, GL_FLOAT, GL_FALSE, sizeof( Vertex ),
+ glVertexAttribPointer( Attrib::POSITION, 3, GL_FLOAT, GL_FALSE, int( sizeof( Vertex ) ),
static_cast<char*>( nullptr ) + offsetof( Vertex, pos ) );
glEnableVertexAttribArray( Attrib::TEXCOORD );
- glVertexAttribPointer( Attrib::TEXCOORD, 2, GL_FLOAT, GL_FALSE, sizeof( Vertex ),
+ glVertexAttribPointer( Attrib::TEXCOORD, 2, GL_FLOAT, GL_FALSE, int( sizeof( Vertex ) ),
static_cast<char*>( nullptr ) + offsetof( Vertex, texCoord ) );
glEnableVertexAttribArray( Attrib::NORMAL );
- glVertexAttribPointer( Attrib::NORMAL, 3, GL_FLOAT, GL_FALSE, sizeof( Vertex ),
+ glVertexAttribPointer( Attrib::NORMAL, 3, GL_FLOAT, GL_FALSE, int( sizeof( Vertex ) ),
static_cast<char*>( nullptr ) + offsetof( Vertex, normal ) );
}
View
6 src/client/Shape.cc
@@ -168,15 +168,15 @@ void Shape::bind() const
glBindBuffer( GL_ARRAY_BUFFER, vbo );
glEnableVertexAttribArray( Attrib::POSITION );
- glVertexAttribPointer( Attrib::POSITION, 3, GL_FLOAT, GL_FALSE, sizeof( Vertex ),
+ glVertexAttribPointer( Attrib::POSITION, 3, GL_FLOAT, GL_FALSE, int( sizeof( Vertex ) ),
static_cast<char*>( nullptr ) + offsetof( Vertex, pos ) );
glEnableVertexAttribArray( Attrib::TEXCOORD );
- glVertexAttribPointer( Attrib::TEXCOORD, 2, GL_FLOAT, GL_FALSE, sizeof( Vertex ),
+ glVertexAttribPointer( Attrib::TEXCOORD, 2, GL_FLOAT, GL_FALSE, int( sizeof( Vertex ) ),
static_cast<char*>( nullptr ) + offsetof( Vertex, texCoord ) );
glEnableVertexAttribArray( Attrib::NORMAL );
- glVertexAttribPointer( Attrib::NORMAL, 3, GL_FLOAT, GL_FALSE, sizeof( Vertex ),
+ glVertexAttribPointer( Attrib::NORMAL, 3, GL_FLOAT, GL_FALSE, int( sizeof( Vertex ) ),
static_cast<char*>( nullptr ) + offsetof( Vertex, normal ) );
glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, ibo );
View
2 src/client/Terra.cc
@@ -53,7 +53,7 @@ void Terra::draw()
}
// to match strip triangles with matrix terrain we have to make them clockwise since
- // we draw column-major (strips along y axis) for better cache performance
+ // we draw column-major (triangle strips along y axis) for better cache performance
glFrontFace( GL_CW );
span.minX = max( int( ( camera.p.x - frustum.radius + matrix::Terra::DIM ) / TILE_SIZE ), 0 );
View
56 src/common/common.hh
@@ -59,6 +59,11 @@ namespace common
const int MAX_WORLD_COORD = 2048;
/**
+ * Extent of world bounding box (equals `MAX_WORLD_COORD` but float type).
+ */
+const float WORLD_DIM = float( MAX_WORLD_COORD );
+
+/**
* Margin for collision detection.
*
* The maximum relative error for transition from world coordinates to relative coordinates is
@@ -74,10 +79,21 @@ const int MAX_WORLD_COORD = 2048;
const float EPSILON = float( MAX_WORLD_COORD ) * 4.0f * Math::FLOAT_EPS;
/**
- * Wrap angle to interval \f$ [0, \tau) \f$.
+ * 2D integer span.
+ */
+struct Span
+{
+ int minX; ///< Minimum X.
+ int minY; ///< Minimum Y.
+ int maxX; ///< Maximum X.
+ int maxY; ///< Maximum Y.
+};
+
+/**
+ * Wrap angle to the interval \f$ [0, \tau) \f$.
*
- * This adjustment should be made after each angle addition/subtraction. It assumes the input angle
- * lies on interval \f$ [-\tau, \infty) \f$.
+ * This adjustment should be made after each angle change. It assumes the input angle lies on
+ * the interval \f$ [-\tau, \infty) \f$.
*/
OZ_ALWAYS_INLINE
inline float angleWrap( float x )
@@ -88,7 +104,7 @@ inline float angleWrap( float x )
/**
* Difference between two angles, maps to interval \f$ [-\frac{\tau}{2}, +\frac{\tau}{2}) \f$.
*
- * This function assumes that both angles lie on interval \f$ [0, \tau) \f$.
+ * This function assumes that both angles lie on the interval \f$ [0, \tau) \f$.
*/
OZ_ALWAYS_INLINE
inline float angleDiff( float x, float y )
@@ -97,15 +113,33 @@ inline float angleDiff( float x, float y )
}
/**
- * 2D integer span.
+ * Wrap position to the interval \f$ [-WORLD_DIM, +WORLD_DIM) \f$.
+ *
+ * This adjustment should be made after each position change. It assumes the input position lies
+ * on the interval \f$ [-2 WORLD_DIM, \infty) \f$.
*/
-struct Span
+OZ_ALWAYS_INLINE
+inline Point posWrap( const Point& p )
{
- int minX; ///< Minimum X.
- int minY; ///< Minimum Y.
- int maxX; ///< Maximum X.
- int maxY; ///< Maximum Y.
-};
+ return Point( Math::fmod( p.x + 3.0f*WORLD_DIM, 2.0f*WORLD_DIM ) - WORLD_DIM,
+ Math::fmod( p.y + 3.0f*WORLD_DIM, 2.0f*WORLD_DIM ) - WORLD_DIM,
+ Math::fmod( p.z + 3.0f*WORLD_DIM, 2.0f*WORLD_DIM ) - WORLD_DIM );
+}
+
+/**
+ * Difference between two points in the world.
+ *
+ * This function assumes that both points lie on the interval \f$ [-WORLD_DIM, +WORLD_DIM) \f$.
+ */
+OZ_ALWAYS_INLINE
+inline Vec3 posDiff( const Point& p0, const Point& p1 )
+{
+ Vec3 diff = p0 - p1;
+
+ return Vec3( Math::fmod( diff.x + 3.0f*WORLD_DIM, 2.0f*WORLD_DIM ) - WORLD_DIM,
+ Math::fmod( diff.y + 3.0f*WORLD_DIM, 2.0f*WORLD_DIM ) - WORLD_DIM,
+ Math::fmod( diff.z + 3.0f*WORLD_DIM, 2.0f*WORLD_DIM ) - WORLD_DIM );
+}
}
}
View
12 src/matrix/Bot.cc
@@ -840,24 +840,32 @@ void Bot::onUpdate()
if( !( state & GESTURE_POINT_BIT ) ) {
state &= ~GESTURE_MASK;
state |= GESTURE_POINT_BIT;
+
+ addEvent( EVENT_POINT, 1.0f );
}
}
else if( actions & ACTION_BACK ) {
- if( !( state & GESTURE_BACK_BIT ) ) {
+ if( !( state & GESTURE_FALL_BACK_BIT ) ) {
state &= ~GESTURE_MASK;
- state |= GESTURE_BACK_BIT;
+ state |= GESTURE_FALL_BACK_BIT;
+
+ addEvent( EVENT_FALL_BACK, 1.0f );
}
}
else if( actions & ACTION_SALUTE ) {
if( !( state & GESTURE_SALUTE_BIT ) ) {
state &= ~GESTURE_MASK;
state |= GESTURE_SALUTE_BIT;
+
+ addEvent( EVENT_SALUTE, 1.0f );
}
}
else if( actions & ACTION_WAVE ) {
if( !( state & GESTURE_WAVE_BIT ) ) {
state &= ~GESTURE_MASK;
state |= GESTURE_WAVE_BIT;
+
+ addEvent( EVENT_WAVE, 1.0f );
}
}
else {
View
28 src/matrix/Bot.hh
@@ -40,16 +40,22 @@ class Bot : public Dynamic
* EVENTS
*/
- static const int EVENT_JUMP = 9;
- static const int EVENT_MELEE = 10;
- static const int EVENT_FLIP = 11;
- static const int EVENT_DEATH = 12;
-
// Step and swim events are not in use but merely reserve sound slots.
- static const int EVENT_STEP = 13;
- static const int EVENT_WATERSTEP = 14;
- static const int EVENT_SWIM_SURFACE = 15;
- static const int EVENT_SWIM_SUBMERGED = 16;
+ static const int EVENT_STEP = 9;
+ static const int EVENT_WATERSTEP = 10;
+ static const int EVENT_SWIM_SURFACE = 11;
+ static const int EVENT_SWIM_SUBMERGED = 12;
+
+ static const int EVENT_DEATH = 13;
+ static const int EVENT_JUMP = 14;
+ static const int EVENT_MELEE = 15;
+
+ // Gestures.
+ static const int EVENT_POINT = 16;
+ static const int EVENT_FALL_BACK = 17;
+ static const int EVENT_SALUTE = 18;
+ static const int EVENT_WAVE = 19;
+ static const int EVENT_FLIP = 20;
/*
* ACTIONS
@@ -127,12 +133,12 @@ class Bot : public Dynamic
static const int SUBMERGED_BIT = 0x00004000;
static const int GESTURE_POINT_BIT = 0x01000000;
- static const int GESTURE_BACK_BIT = 0x02000000;
+ static const int GESTURE_FALL_BACK_BIT = 0x02000000;
static const int GESTURE_SALUTE_BIT = 0x04000000;
static const int GESTURE_WAVE_BIT = 0x08000000;
static const int GESTURE_FLIP_BIT = 0x10000000;
- static const int GESTURE_MASK = GESTURE_POINT_BIT | GESTURE_BACK_BIT |
+ static const int GESTURE_MASK = GESTURE_POINT_BIT | GESTURE_FALL_BACK_BIT |
GESTURE_SALUTE_BIT | GESTURE_WAVE_BIT |
GESTURE_FLIP_BIT;
View
67 src/matrix/Orbis.hh
@@ -191,6 +191,15 @@ class Orbis : public Bounds
// get indices of min and max cells which the bounds intersects
Span getInters( const Bounds& bounds, float epsilon = 0.0f ) const;
+ Cell* getCell1( float x, float y );
+ Cell* getCell1( const Point& p );
+ Span getInters1( float x, float y, float epsilon = 0.0f ) const;
+ Span getInters1( const Point& p, float epsilon = 0.0f ) const;
+ Span getInters1( float minPosX, float minPosY, float maxPosX, float maxPosY,
+ float epsilon = 0.0f ) const;
+ Span getInters1( const AABB& bb, float epsilon = 0.0f ) const;
+ Span getInters1( const Bounds& bounds, float epsilon = 0.0f ) const;
+
void update();
void read( InputStream* istream );
@@ -333,5 +342,63 @@ inline Span Orbis::getInters( const Bounds& bounds, float epsilon ) const
return getInters( bounds.mins.x, bounds.mins.y, bounds.maxs.x, bounds.maxs.y, epsilon );
}
+OZ_ALWAYS_INLINE
+inline Cell* Orbis::getCell1( float x, float y )
+{
+ int ix = int( ( x + 3.0f*Orbis::DIM ) / Cell::SIZE ) % Orbis::CELLS;
+ int iy = int( ( y + 3.0f*Orbis::DIM ) / Cell::SIZE ) % Orbis::CELLS;
+
+ return &cells[ix][iy];
+}
+
+OZ_ALWAYS_INLINE
+inline Cell* Orbis::getCell1( const Point& p )
+{
+ return getCell1( p.x, p.y );
+}
+
+OZ_ALWAYS_INLINE
+inline Span Orbis::getInters1( float x, float y, float epsilon ) const
+{
+ return {
+ int( ( x - epsilon + 3.0f*Orbis::DIM ) / Cell::SIZE ) - Orbis::CELLS,
+ int( ( y - epsilon + 3.0f*Orbis::DIM ) / Cell::SIZE ) - Orbis::CELLS,
+ int( ( x + epsilon + 3.0f*Orbis::DIM ) / Cell::SIZE ) - Orbis::CELLS,
+ int( ( y + epsilon + 3.0f*Orbis::DIM ) / Cell::SIZE ) - Orbis::CELLS
+ };
+}
+
+OZ_ALWAYS_INLINE
+inline Span Orbis::getInters1( const Point& p, float epsilon ) const
+{
+ return getInters1( p.x, p.y, epsilon );
+}
+
+OZ_ALWAYS_INLINE
+inline Span Orbis::getInters1( float minPosX, float minPosY,
+ float maxPosX, float maxPosY, float epsilon ) const
+{
+ return {
+ int( ( minPosX - epsilon + 3.0f*Orbis::DIM ) / Cell::SIZE ) - Orbis::CELLS,
+ int( ( minPosY - epsilon + 3.0f*Orbis::DIM ) / Cell::SIZE ) - Orbis::CELLS,
+ int( ( maxPosX + epsilon + 3.0f*Orbis::DIM ) / Cell::SIZE ) - Orbis::CELLS,
+ int( ( maxPosY + epsilon + 3.0f*Orbis::DIM ) / Cell::SIZE ) - Orbis::CELLS
+ };
+}
+
+OZ_ALWAYS_INLINE
+inline Span Orbis::getInters1( const AABB& bb, float epsilon ) const
+{
+ return getInters1( bb.p.x - bb.dim.x, bb.p.y - bb.dim.y,
+ bb.p.x + bb.dim.x, bb.p.y + bb.dim.y,
+ epsilon );
+}
+
+OZ_ALWAYS_INLINE
+inline Span Orbis::getInters1( const Bounds& bounds, float epsilon ) const
+{
+ return getInters1( bounds.mins.x, bounds.mins.y, bounds.maxs.x, bounds.maxs.y, epsilon );
+}
+
}
}
View
15 src/matrix/luaapi.cc
@@ -70,19 +70,24 @@ void importMatrixConstants( lua_State* l )
registerLuaConstant( l, "OZ_EVENT_DESTROY", Object::EVENT_DESTROY );
registerLuaConstant( l, "OZ_EVENT_DAMAGE", Object::EVENT_DAMAGE );
registerLuaConstant( l, "OZ_EVENT_HIT", Object::EVENT_HIT );
+ registerLuaConstant( l, "OZ_EVENT_LAND", Object::EVENT_LAND );
registerLuaConstant( l, "OZ_EVENT_SPLASH", Object::EVENT_SPLASH );
registerLuaConstant( l, "OZ_EVENT_FRICTING", Object::EVENT_FRICTING );
registerLuaConstant( l, "OZ_EVENT_USE", Object::EVENT_USE );
registerLuaConstant( l, "OZ_EVENT_SHOT", Weapon::EVENT_SHOT );
registerLuaConstant( l, "OZ_EVENT_SHOT_EMPTY", Weapon::EVENT_SHOT_EMPTY );
- registerLuaConstant( l, "OZ_EVENT_LAND", Bot::EVENT_LAND );
- registerLuaConstant( l, "OZ_EVENT_JUMP", Bot::EVENT_JUMP );
- registerLuaConstant( l, "OZ_EVENT_FLIP", Bot::EVENT_FLIP );
- registerLuaConstant( l, "OZ_EVENT_DEATH", Bot::EVENT_DEATH );
registerLuaConstant( l, "OZ_EVENT_STEP", Bot::EVENT_STEP );
registerLuaConstant( l, "OZ_EVENT_WATERSTEP", Bot::EVENT_WATERSTEP );
registerLuaConstant( l, "OZ_EVENT_SWIM_SURFACE", Bot::EVENT_SWIM_SURFACE );
registerLuaConstant( l, "OZ_EVENT_SWIM_SUBMERGED", Bot::EVENT_SWIM_SUBMERGED );
+ registerLuaConstant( l, "OZ_EVENT_DEATH", Bot::EVENT_DEATH );
+ registerLuaConstant( l, "OZ_EVENT_JUMP", Bot::EVENT_JUMP );
+ registerLuaConstant( l, "OZ_EVENT_MELEE", Bot::EVENT_MELEE );
+ registerLuaConstant( l, "OZ_EVENT_POINT", Bot::EVENT_POINT );
+ registerLuaConstant( l, "OZ_EVENT_FALL_BACK", Bot::EVENT_FALL_BACK );
+ registerLuaConstant( l, "OZ_EVENT_SALUTE", Bot::EVENT_SALUTE );
+ registerLuaConstant( l, "OZ_EVENT_WAVE", Bot::EVENT_WAVE );
+ registerLuaConstant( l, "OZ_EVENT_FLOP", Bot::EVENT_FLIP );
registerLuaConstant( l, "OZ_EVENT_ENGINE", Vehicle::EVENT_ENGINE );
registerLuaConstant( l, "OZ_EVENT_NEXT_WEAPON", Vehicle::EVENT_NEXT_WEAPON );
registerLuaConstant( l, "OZ_EVENT_SHOT0", Vehicle::EVENT_SHOT0 );
@@ -141,7 +146,7 @@ void importMatrixConstants( lua_State* l )
registerLuaConstant( l, "OZ_BOT_SUBMERGED_BIT", Bot::SUBMERGED_BIT );
registerLuaConstant( l, "OZ_BOT_GESTURE_POINT_BIT", Bot::GESTURE_POINT_BIT );
- registerLuaConstant( l, "OZ_BOT_GESTURE_BACK_BIT", Bot::GESTURE_BACK_BIT );
+ registerLuaConstant( l, "OZ_BOT_GESTURE_FALL_BACK_BIT", Bot::GESTURE_FALL_BACK_BIT );
registerLuaConstant( l, "OZ_BOT_GESTURE_SALUTE_BIT", Bot::GESTURE_SALUTE_BIT );
registerLuaConstant( l, "OZ_BOT_GESTURE_WAVE_BIT", Bot::GESTURE_WAVE_BIT );
registerLuaConstant( l, "OZ_BOT_GESTURE_FLIP_BIT", Bot::GESTURE_FLIP_BIT );
View
38 src/ozCore/InputStream.hh
@@ -223,7 +223,7 @@ class InputStream
OZ_ALWAYS_INLINE
bool readBool()
{
- const char* data = forward( sizeof( bool ) );
+ const char* data = forward( int( sizeof( bool ) ) );
return bool( *data );
}
@@ -233,7 +233,7 @@ class InputStream
OZ_ALWAYS_INLINE
char readChar()
{
- const char* data = forward( sizeof( char ) );
+ const char* data = forward( int( sizeof( char ) ) );
return char( *data );
}
@@ -253,7 +253,7 @@ class InputStream
OZ_ALWAYS_INLINE
byte readByte()
{
- const char* data = forward( sizeof( byte ) );
+ const char* data = forward( int( sizeof( byte ) ) );
return byte( *data );
}
@@ -263,7 +263,7 @@ class InputStream
OZ_ALWAYS_INLINE
ubyte readUByte()
{
- const char* data = forward( sizeof( ubyte ) );
+ const char* data = forward( int( sizeof( ubyte ) ) );
return ubyte( *data );
}
@@ -273,7 +273,7 @@ class InputStream
OZ_ALWAYS_INLINE
short readShort()
{
- const char* data = forward( sizeof( short ) );
+ const char* data = forward( int( sizeof( short ) ) );
if( order == Endian::NATIVE ) {
Endian::BytesToShort value = { { data[0], data[1] } };
@@ -293,7 +293,7 @@ class InputStream
OZ_ALWAYS_INLINE
ushort readUShort()
{
- const char* data = forward( sizeof( ushort ) );
+ const char* data = forward( int( sizeof( ushort ) ) );
if( order == Endian::NATIVE ) {
Endian::BytesToUShort value = { { data[0], data[1] } };
@@ -313,7 +313,7 @@ class InputStream
OZ_ALWAYS_INLINE
int readInt()
{
- const char* data = forward( sizeof( int ) );
+ const char* data = forward( int( sizeof( int ) ) );
if( order == Endian::NATIVE ) {
Endian::BytesToInt value = { { data[0], data[1], data[2], data[3] } };
@@ -333,7 +333,7 @@ class InputStream
OZ_ALWAYS_INLINE
uint readUInt()
{
- const char* data = forward( sizeof( uint ) );
+ const char* data = forward( int( sizeof( uint ) ) );
if( order == Endian::NATIVE ) {
Endian::BytesToUInt value = { { data[0], data[1], data[2], data[3] } };
@@ -353,7 +353,7 @@ class InputStream
OZ_ALWAYS_INLINE
long64 readLong64()
{
- const char* data = forward( sizeof( long64 ) );
+ const char* data = forward( int( sizeof( long64 ) ) );
if( order == Endian::NATIVE ) {
Endian::BytesToLong64 value = {
@@ -377,7 +377,7 @@ class InputStream
OZ_ALWAYS_INLINE
ulong64 readULong64()
{
- const char* data = forward( sizeof( ulong64 ) );
+ const char* data = forward( int( sizeof( ulong64 ) ) );
if( order == Endian::NATIVE ) {
Endian::BytesToULong64 value = {
@@ -401,7 +401,7 @@ class InputStream
OZ_ALWAYS_INLINE
float readFloat()
{
- const char* data = forward( sizeof( float ) );
+ const char* data = forward( int( sizeof( float ) ) );
if( order == Endian::NATIVE ) {
Endian::BytesToFloat value = { { data[0], data[1], data[2], data[3] } };
@@ -421,7 +421,7 @@ class InputStream
OZ_ALWAYS_INLINE
double readDouble()
{
- const char* data = forward( sizeof( double ) );
+ const char* data = forward( int( sizeof( double ) ) );
if( order == Endian::NATIVE ) {
Endian::BytesToDouble value = {
@@ -463,7 +463,7 @@ class InputStream
OZ_ALWAYS_INLINE
Vec3 readVec3()
{
- const char* data = forward( sizeof( float[3] ) );
+ const char* data = forward( int( sizeof( float[3] ) ) );
if( order == Endian::NATIVE ) {
Endian::BytesToFloat x = { { data[ 0], data[ 1], data[ 2], data[ 3] } };
@@ -487,7 +487,7 @@ class InputStream
OZ_ALWAYS_INLINE
Vec4 readVec4()
{
- const char* data = forward( sizeof( float[4] ) );
+ const char* data = forward( int( sizeof( float[4] ) ) );
if( order == Endian::NATIVE ) {
Endian::BytesToFloat x = { { data[ 0], data[ 1], data[ 2], data[ 3] } };
@@ -513,7 +513,7 @@ class InputStream
OZ_ALWAYS_INLINE
Point readPoint()
{
- const char* data = forward( sizeof( float[3] ) );
+ const char* data = forward( int( sizeof( float[3] ) ) );
if( order == Endian::NATIVE ) {
Endian::BytesToFloat x = { { data[ 0], data[ 1], data[ 2], data[ 3] } };
@@ -537,7 +537,7 @@ class InputStream
OZ_ALWAYS_INLINE
Plane readPlane()
{
- const char* data = forward( sizeof( float[4] ) );
+ const char* data = forward( int( sizeof( float[4] ) ) );
if( order == Endian::NATIVE ) {
Endian::BytesToFloat nx = { { data[ 0], data[ 1], data[ 2], data[ 3] } };
@@ -563,7 +563,7 @@ class InputStream
OZ_ALWAYS_INLINE
Quat readQuat()
{
- const char* data = forward( sizeof( float[4] ) );
+ const char* data = forward( int( sizeof( float[4] ) ) );
if( order == Endian::NATIVE ) {
Endian::BytesToFloat x = { { data[ 0], data[ 1], data[ 2], data[ 3] } };
@@ -589,7 +589,7 @@ class InputStream
OZ_ALWAYS_INLINE
Mat33 readMat33()
{
- const char* data = forward( sizeof( float[9] ) );
+ const char* data = forward( int( sizeof( float[9] ) ) );
Mat33 m;
float* values = m;
@@ -618,7 +618,7 @@ class InputStream
OZ_ALWAYS_INLINE
Mat44 readMat44()
{
- const char* data = forward( sizeof( float[16] ) );
+ const char* data = forward( int( sizeof( float[16] ) ) );
Mat44 m;
float* values = m;
View
17 src/ozCore/JSON.cc
@@ -1960,11 +1960,14 @@ bool JSON::exclude( const char* key )
return table.exclude( key );
}
-void JSON::clear( bool unusedWarnings )
+bool JSON::clear( bool warnUnused )
{
- if( unusedWarnings && !wasAccessed ) {
+ bool hasUnused = false;
+
+ if( warnUnused && !wasAccessed ) {
Log::println( "JSON: unused value: %s", toString().cstr() );
System::bell();
+ hasUnused = true;
}
switch( valueType ) {
@@ -1987,9 +1990,9 @@ void JSON::clear( bool unusedWarnings )
case ARRAY: {
ArrayData* arrayData = static_cast<ArrayData*>( data );
- if( unusedWarnings ) {
+ if( warnUnused ) {
foreach( i, arrayData->list.iter() ) {
- i->clear( true );
+ hasUnused |= i->clear( true );
}
}
@@ -1999,9 +2002,9 @@ void JSON::clear( bool unusedWarnings )
case OBJECT: {
ObjectData* objectData = static_cast<ObjectData*>( data );
- if( unusedWarnings ) {
+ if( warnUnused ) {
foreach( i, objectData->table.iter() ) {
- i->value.clear( true );
+ hasUnused |= i->value.clear( true );
}
}
@@ -2013,6 +2016,8 @@ void JSON::clear( bool unusedWarnings )
data = nullptr;
valueType = NIL;
wasAccessed = true;
+
+ return hasUnused;
}
String JSON::toString() const
View
5 src/ozCore/JSON.hh
@@ -1239,9 +1239,10 @@ class JSON
/**
* Recursively clear node and its children.
*
- * @param unusedWarnings warn about unused variables.
+ * @param warnUnused warn about unused variables.
+ * @return True iff `warnUnused` is true and there are unused variables.
*/
- void clear( bool unusedWarnings = false );
+ bool clear( bool warnUnused = false );
/**
* String representation of a value.
View
2 src/ozCore/Log.cc
@@ -38,7 +38,7 @@ namespace oz
static const int OUT_BUFFER_SIZE = 4096;
static const int INDENT_SPACES = 2;
static const char INDENT_BUFFER[49] = " ";
-static const int INDENT_BUFFER_LENGTH = sizeof( INDENT_BUFFER ) - 1;
+static const int INDENT_BUFFER_LENGTH = int( sizeof( INDENT_BUFFER ) ) - 1;
static const char* const SIGNALS[][2] =
{
{ "SIG???", "[invalid signal number]" },
View
16 src/ozCore/Math.hh
@@ -503,11 +503,21 @@ class Math
}
/**
- * For a positive integer, true iff it is a power of 2.
+ * Index of the first 1 bit or -1 if `v` is 0.
*/
- template <typename Value>
+ template <typename Value = int>
+ OZ_ALWAYS_INLINE
+ static int index1( Value v )
+ {
+ return v == 0 ? -1 : int( sizeof( Value ) * 8 - 1 ) - __builtin_clzll( ulong64( v ) );
+ }
+
+ /**
+ * True iff the given positive integer is a power of 2.
+ */
+ template <typename Value = int>
OZ_ALWAYS_INLINE
- static bool isPow2( const Value& v )
+ static bool isPow2( Value v )
{
hard_assert( 0 < v );
View
76 src/ozCore/OutputStream.hh
@@ -420,7 +420,7 @@ class OutputStream
OZ_ALWAYS_INLINE
bool readBool()
{
- const char* data = forward( sizeof( bool ) );
+ const char* data = forward( int( sizeof( bool ) ) );
return bool( *data );
}
@@ -430,7 +430,7 @@ class OutputStream
OZ_ALWAYS_INLINE
void writeBool( bool b )
{
- char* data = forward( sizeof( bool ) );
+ char* data = forward( int( sizeof( bool ) ) );
*data = char( b );
}
@@ -440,7 +440,7 @@ class OutputStream
OZ_ALWAYS_INLINE
char readChar()
{
- const char* data = forward( sizeof( char ) );
+ const char* data = forward( int( sizeof( char ) ) );
return char( *data );
}
@@ -450,7 +450,7 @@ class OutputStream
OZ_ALWAYS_INLINE
void writeChar( char c )
{
- char* data = forward( sizeof( char ) );
+ char* data = forward( int( sizeof( char ) ) );
*data = char( c );
}
@@ -480,7 +480,7 @@ class OutputStream
OZ_ALWAYS_INLINE
byte readByte()
{
- const char* data = forward( sizeof( byte ) );
+ const char* data = forward( int( sizeof( byte ) ) );
return byte( *data );
}
@@ -490,7 +490,7 @@ class OutputStream
OZ_ALWAYS_INLINE
void writeByte( byte b )
{
- char* data = forward( sizeof( byte ) );
+ char* data = forward( int( sizeof( byte ) ) );
*data = char( b );
}
@@ -500,7 +500,7 @@ class OutputStream
OZ_ALWAYS_INLINE
ubyte readUByte()
{
- const char* data = forward( sizeof( ubyte ) );
+ const char* data = forward( int( sizeof( ubyte ) ) );
return ubyte( *data );
}
@@ -510,7 +510,7 @@ class OutputStream
OZ_ALWAYS_INLINE
void writeUByte( ubyte b )
{
- char* data = forward( sizeof( ubyte ) );
+ char* data = forward( int( sizeof( ubyte ) ) );
*data = char( b );
}
@@ -520,7 +520,7 @@ class OutputStream
OZ_ALWAYS_INLINE
short readShort()
{
- const char* data = forward( sizeof( short ) );
+ const char* data = forward( int( sizeof( short ) ) );
if( order == Endian::NATIVE ) {
Endian::BytesToShort value = { { data[0], data[1] } };
@@ -540,7 +540,7 @@ class OutputStream
OZ_ALWAYS_INLINE
void writeShort( short s )
{
- char* data = forward( sizeof( short ) );
+ char* data = forward( int( sizeof( short ) ) );
Endian::ShortToBytes value = { s };
@@ -560,7 +560,7 @@ class OutputStream
OZ_ALWAYS_INLINE
ushort readUShort()
{
- const char* data = forward( sizeof( ushort ) );
+ const char* data = forward( int( sizeof( ushort ) ) );
if( order == Endian::NATIVE ) {
Endian::BytesToUShort value = { { data[0], data[1] } };
@@ -580,7 +580,7 @@ class OutputStream
OZ_ALWAYS_INLINE
void writeUShort( ushort s )
{
- char* data = forward( sizeof( ushort ) );
+ char* data = forward( int( sizeof( ushort ) ) );
Endian::UShortToBytes value = { s };
@@ -600,7 +600,7 @@ class OutputStream
OZ_ALWAYS_INLINE
int readInt()
{
- const char* data = forward( sizeof( int ) );
+ const char* data = forward( int( sizeof( int ) ) );
if( order == Endian::NATIVE ) {
Endian::BytesToInt value = { { data[0], data[1], data[2], data[3] } };
@@ -620,7 +620,7 @@ class OutputStream
OZ_ALWAYS_INLINE
void writeInt( int i )
{
- char* data = forward( sizeof( int ) );
+ char* data = forward( int( sizeof( int ) ) );
Endian::IntToBytes value = { i };
@@ -644,7 +644,7 @@ class OutputStream
OZ_ALWAYS_INLINE
uint readUInt()
{
- const char* data = forward( sizeof( uint ) );
+ const char* data = forward( int( sizeof( uint ) ) );
if( order == Endian::NATIVE ) {
Endian::BytesToUInt value = { { data[0], data[1], data[2], data[3] } };
@@ -664,7 +664,7 @@ class OutputStream
OZ_ALWAYS_INLINE
void writeUInt( uint i )
{
- char* data = forward( sizeof( uint ) );
+ char* data = forward( int( sizeof( uint ) ) );
Endian::UIntToBytes value = { i };
@@ -688,7 +688,7 @@ class OutputStream
OZ_ALWAYS_INLINE
long64 readLong64()
{
- const char* data = forward( sizeof( long64 ) );
+ const char* data = forward( int( sizeof( long64 ) ) );
if( order == Endian::NATIVE ) {
Endian::BytesToLong64 value = {
@@ -712,7 +712,7 @@ class OutputStream
OZ_ALWAYS_INLINE
void writeLong64( long64 l )
{
- char* data = forward( sizeof( long64 ) );
+ char* data = forward( int( sizeof( long64 ) ) );
Endian::Long64ToBytes value = { l };
@@ -744,7 +744,7 @@ class OutputStream
OZ_ALWAYS_INLINE
ulong64 readULong64()
{
- const char* data = forward( sizeof( ulong64 ) );
+ const char* data = forward( int( sizeof( ulong64 ) ) );
if( order == Endian::NATIVE ) {
Endian::BytesToULong64 value = {
@@ -768,7 +768,7 @@ class OutputStream
OZ_ALWAYS_INLINE
void writeULong64( ulong64 l )
{
- char* data = forward( sizeof( ulong64 ) );
+ char* data = forward( int( sizeof( ulong64 ) ) );
Endian::ULong64ToBytes value = { l };
@@ -800,7 +800,7 @@ class OutputStream
OZ_ALWAYS_INLINE
float readFloat()
{
- const char* data = forward( sizeof( float ) );
+ const char* data = forward( int( sizeof( float ) ) );
if( order == Endian::NATIVE ) {
Endian::BytesToFloat value = { { data[0], data[1], data[2], data[3] } };
@@ -820,7 +820,7 @@ class OutputStream
OZ_ALWAYS_INLINE
void writeFloat( float f )
{
- char* data = forward( sizeof( float ) );
+ char* data = forward( int( sizeof( float ) ) );
Endian::FloatToBytes value = { f };
@@ -844,7 +844,7 @@ class OutputStream
OZ_ALWAYS_INLINE
double readDouble()
{
- const char* data = forward( sizeof( double ) );
+ const char* data = forward( int( sizeof( double ) ) );
if( order == Endian::NATIVE ) {
Endian::BytesToDouble value = {
@@ -868,7 +868,7 @@ class OutputStream
OZ_ALWAYS_INLINE
void writeDouble( double d )
{
- char* data = forward( sizeof( double ) );
+ char* data = forward( int( sizeof( double ) ) );
Endian::DoubleToBytes value = { d };
@@ -940,7 +940,7 @@ class OutputStream
OZ_ALWAYS_INLINE
Vec3 readVec3()
{
- const char* data = forward( sizeof( float[3] ) );
+ const char* data = forward( int( sizeof( float[3] ) ) );
if( order == Endian::NATIVE ) {
Endian::BytesToFloat x = { { data[ 0], data[ 1], data[ 2], data[ 3] } };
@@ -964,7 +964,7 @@ class OutputStream
OZ_ALWAYS_INLINE
void writeVec3( const Vec3& v )
{
- char* data = forward( sizeof( float[3] ) );
+ char* data = forward( int( sizeof( float[3] ) ) );
Endian::FloatToBytes x = { v.x };
Endian::FloatToBytes y = { v.y };
@@ -1006,7 +1006,7 @@ class OutputStream
OZ_ALWAYS_INLINE
Vec4 readVec4()
{
- const char* data = forward( sizeof( float[4] ) );
+ const char* data = forward( int( sizeof( float[4] ) ) );
if( order == Endian::NATIVE ) {
Endian::BytesToFloat x = { { data[ 0], data[ 1], data[ 2], data[ 3] } };
@@ -1032,7 +1032,7 @@ class OutputStream
OZ_ALWAYS_INLINE
void writeVec4( const Vec4& v )
{
- char* data = forward( sizeof( float[4] ) );
+ char* data = forward( int( sizeof( float[4] ) ) );
Endian::FloatToBytes x = { v.x };
Endian::FloatToBytes y = { v.y };
@@ -1083,7 +1083,7 @@ class OutputStream
OZ_ALWAYS_INLINE
Point readPoint()
{
- const char* data = forward( sizeof( float[3] ) );
+ const char* data = forward( int( sizeof( float[3] ) ) );
if( order == Endian::NATIVE ) {
Endian::BytesToFloat x = { { data[ 0], data[ 1], data[ 2], data[ 3] } };
@@ -1107,7 +1107,7 @@ class OutputStream
OZ_ALWAYS_INLINE
void writePoint( const Point& p )
{
- char* data = forward( sizeof( float[3] ) );
+ char* data = forward( int( sizeof( float[3] ) ) );
Endian::FloatToBytes x = { p.x };
Endian::FloatToBytes y = { p.y };
@@ -1149,7 +1149,7 @@ class OutputStream
OZ_ALWAYS_INLINE
Plane readPlane()
{
- const char* data = forward( sizeof( float[4] ) );
+ const char* data = forward( int( sizeof( float[4] ) ) );
if( order == Endian::NATIVE ) {
Endian::BytesToFloat nx = { { data[ 0], data[ 1], data[ 2], data[ 3] } };
@@ -1175,7 +1175,7 @@ class OutputStream
OZ_ALWAYS_INLINE
void writePlane( const Plane& p )
{
- char* data = forward( sizeof( float[4] ) );
+ char* data = forward( int( sizeof( float[4] ) ) );
Endian::FloatToBytes nx = { p.n.x };
Endian::FloatToBytes ny = { p.n.y };
@@ -1226,7 +1226,7 @@ class OutputStream
OZ_ALWAYS_INLINE
Quat readQuat()
{
- const char* data = forward( sizeof( float[4] ) );
+ const char* data = forward( int( sizeof( float[4] ) ) );
if( order == Endian::NATIVE ) {
Endian::BytesToFloat x = { { data[ 0], data[ 1], data[ 2], data[ 3] } };
@@ -1252,7 +1252,7 @@ class OutputStream
OZ_ALWAYS_INLINE
void writeQuat( const Quat& q )
{
- char* data = forward( sizeof( float[4] ) );
+ char* data = forward( int( sizeof( float[4] ) ) );
Endian::FloatToBytes x = { q.x };
Endian::FloatToBytes y = { q.y };
@@ -1303,7 +1303,7 @@ class OutputStream
OZ_ALWAYS_INLINE
Mat33 readMat33()
{
- const char* data = forward( sizeof( float[9] ) );
+ const char* data = forward( int( sizeof( float[9] ) ) );
Mat33 m;
float* values = m;
@@ -1332,7 +1332,7 @@ class OutputStream
OZ_ALWAYS_INLINE
void writeMat33( const Mat44& m )
{
- char* data = forward( sizeof( float[9] ) );
+ char* data = forward( int( sizeof( float[9] ) ) );
const float* values = m;
if( order == Endian::NATIVE ) {
@@ -1363,7 +1363,7 @@ class OutputStream
OZ_ALWAYS_INLINE
Mat44 readMat44()
{
- const char* data = forward( sizeof( float[16] ) );
+ const char* data = forward( int( sizeof( float[16] ) ) );
Mat44 m;
float* values = m;
@@ -1392,7 +1392,7 @@ class OutputStream
OZ_ALWAYS_INLINE
void writeMat44( const Mat44& m )
{
- char* data = forward( sizeof( float[16] ) );
+ char* data = forward( int( sizeof( float[16] ) ) );
const float* values = m;
if( order == Endian::NATIVE ) {
View
2 src/ozCore/SBitset.hh
@@ -49,7 +49,7 @@ class SBitset
private:
/// Number of bits per unit.
- static const int ULONG_BITSIZE = int( sizeof( ulong ) * 8 );
+ static const int ULONG_BITSIZE = int( sizeof( ulong ) ) * 8;
/// Number of units.
static const int SIZE = ( BITSIZE + ULONG_BITSIZE - 1 ) / ULONG_BITSIZE;
View
10 src/ozCore/SharedLib.hh
@@ -78,7 +78,7 @@ class SharedLib
private:
- void* handle; ///< Internal handle to the library.
+ void* handle; ///< Internal library handle.
public:
@@ -90,7 +90,7 @@ class SharedLib
{}
/**
- * Destructor, closes library if still opened.
+ * Destructor, closes the library if opened.
*/
~SharedLib()
{
@@ -130,17 +130,17 @@ class SharedLib
}
/**
- * Obtain pointer to the requested function in the library (`nullptr` on error).
+ * Obtain a pointer to the requested function from thr library (`nullptr` on error).
*/
Method* get( const char* symbol ) const;
/**
- * Open shared library with the given (file) name.
+ * Open a shared library with the given (file) name.
*/
bool open( const char* name );
/**
- * Close library if opened.
+ * Close the library if opened.
*/
void close();
View
5 src/ozCore/System.cc
@@ -696,10 +696,11 @@ void System::init( int flags, CrashHandler* crashHandler_ )
#if !defined( EMSCRIPTEN ) && !defined( __ANDROID__ ) && !defined( __native_client__ ) && \
!defined( _WIN32 )
- int fd = open( "/proc", O_RDONLY );
- isDebuggerAttached = fd >= 5;
+ int fd = open( "/", O_RDONLY );
close( fd );
+ isDebuggerAttached = fd >= 5;
+
if( initFlags & LOCALE_BIT ) {
setlocale( LC_ALL, "" );
}
View
10 src/ozCore/System.hh
@@ -152,11 +152,11 @@ class System
/**
* Install per-thread signal handlers if `HANDLERS_BIT` has been passed to `System::init()`.
*
- * Signal handlers must be set-up for each thread in a process separately. `System::init()`
+ * Signal handlers must be set up for each thread in a process separately. `System::init()`
* method sets them up for the caller thread only, for other threads this method should be used
* unless created with `Thread::start()`, which calls this method implicitly.
*
- * If `HANDLERS_BIT` hasn't been passed to `System::init()` this method is a no-op.
+ * If `HANDLERS_BIT` hasn't been passed to `System::init()` this method is a NOP.
*/
static void threadInit();
@@ -174,9 +174,9 @@ class System
* @li `LOCALE_BIT`: %Set-up locale for the application (calls `setlocale( LC_ALL, "" )`).
* This option has no effect on Android and NaCl.
*
- * @param crashHandler user-provided method called when the application is aborted in a signal/
- * exception handler or in `System::error()`. If non-null, it is invoked after the stack
- * trace is printed and before halting/aborting the application.
+ * @param crashHandler user-provided method called when the application is aborted by a signal/
+ * exception handler or `System::error()`. If non-null, it is invoked after the stack
+ * trace is printed.
*/
static void init( int flags = DEFAULT_MASK, CrashHandler* crashHandler = nullptr );
View
2 src/ozCore/clearmacros.hh
@@ -27,7 +27,7 @@
*
* It undefines `soft_assert()`, `hard_assert()`, `foreach()`, `float4()` and `uint4()` and macros
* that might be defined for older GCC versions only to ensure for C++11 compatibility. It is not
- * included by `\<oz/oz.hh\>`, one should include it before headers that conflict with liboz.
+ * included by `\<oz/oz.hh\>`, one should include it before headers that might conflict with liboz.
*/
#pragma once
View
2 src/ozCore/common.hh
@@ -116,6 +116,8 @@
namespace oz
{
+// These three types are also defined afterwards (which is completely unnecessary) as a workaround
+// for a QtCreator bug and to provide Doxygen documentation.
using std::nullptr_t;
using std::size_t;
using std::ptrdiff_t;
View
2 src/ozEngine/Builder.hh
@@ -71,7 +71,7 @@ class Builder
* @li `MIPMAPS_BIT` enables generation of mipmaps.
* @li `COMPRESSION_BIT` enables S3 texture compression; DXT1 is used for images without an
* alpha channel and DXT5 for images with an alpha channel.
- * Texture compression is enabled only if OZ_NONFREE is enabled on ozEngine build.
+ * Texture compression is enabled only if `OZ_NONFREE` is enabled on ozEngine build.
* @li `QUALITY_BIT` enables highest quality but slow methods for scaling texture to smaller
* dimensions in mipmap generation and highest quality settings for S3 texture compression
* libsquish supports.
View
2 src/ozEngine/Pepper.cc
@@ -72,7 +72,7 @@ void Pepper::post( const char* message )
} )
}
-String Pepper::poll()
+String Pepper::pop()
{
messageLock.lock();
String s = messageQueue.isEmpty() ? String() : messageQueue.popFirst();
View
8 src/ozEngine/Pepper.hh
@@ -149,7 +149,7 @@ class Pepper
static bool isMainThread();
/**
- * Call execute callback on the module's main thread.
+ * Execute callback on the module's main thread and block until finished.
*/
static void mainCall( Callback* callback, void* caller );
@@ -159,12 +159,12 @@ class Pepper
static void post( const char* message );
/**
- * Pop next incoming message from the queue.
+ * Pop next message from the incoming messages queue.
*/
- static String poll();
+ static String pop();
/**
- * Push message back to the queue of incoming messages.
+ * Push message to the incoming messages queue.
*/
static void push( const char* message );
View
85 src/ozEngine/Window.cc
@@ -63,27 +63,6 @@ static void flushCompleteCallback( void*, int )
flushSemaphore.post();
}
-// Because of array initialiser this code cannot reside inside OZ_MAIN_CALL macro, so it has been
-// split into a separate function.
-static void createContext()
-{
- int attribs[] = {
- PP_GRAPHICS3DATTRIB_DEPTH_SIZE, 16,
- PP_GRAPHICS3DATTRIB_WIDTH, Window::windowWidth,
- PP_GRAPHICS3DATTRIB_HEIGHT, Window::windowHeight,
- PP_GRAPHICS3DATTRIB_NONE
- };
-
- context = new pp::Graphics3D( System::instance, pp::Graphics3D(), attribs );
- if( context->is_null() ) {
- OZ_ERROR( "Failed to create OpenGL context" );
- }
-
- if( !System::instance->BindGraphics( *context ) ) {
- OZ_ERROR( "Failed to bind Graphics3D" );
- }
-}
-
#endif
bool Window::isCreated()
@@ -178,11 +157,20 @@ bool Window::resize( int newWidth, int newHeight, bool fullscreen_ )
windowHeight = newHeight;
fullscreen = fullscreen_;
+ uint flags = SDL_OPENGL | ( fullscreen ? SDL_FULLSCREEN : 0 );
+
+ if( windowWidth == 0 || windowHeight == 0 ) {
+ const SDL_VideoInfo* videoInfo = SDL_GetVideoInfo();
+
+ windowWidth = videoInfo->current_w;
+ windowHeight = videoInfo->current_h;
+ }
+
Log::print( "Resizing OpenGL window to %dx%d [%s] ... ",
windowWidth, windowHeight, fullscreen ? "fullscreen" : "windowed" );
SDL_FreeSurface( descriptor );
- descriptor = SDL_SetVideoMode( windowWidth, windowHeight, 0, fullscreen ? SDL_FULLSCREEN : 0 );
+ descriptor = SDL_SetVideoMode( windowWidth, windowHeight, 0, flags );
if( descriptor == nullptr ) {
Log::printEnd( "Window resize failed" );
@@ -196,6 +184,14 @@ bool Window::resize( int newWidth, int newHeight, bool fullscreen_ )
windowHeight = newHeight;
fullscreen = fullscreen_;
+ if( windowWidth == 0 || windowHeight == 0 ) {
+ SDL_DisplayMode mode;
+ SDL_GetDesktopDisplayMode( 0, &mode );
+
+ windowWidth = mode.w;
+ windowHeight = mode.h;
+ }
+
if( fullscreen ) {
SDL_SetWindowSize( descriptor, windowWidth, windowHeight );
SDL_SetWindowFullscreen( descriptor, SDL_TRUE );
@@ -224,19 +220,43 @@ bool Window::create( const char* title, int width, int height, bool fullscreen_
flushSemaphore.init();
+ Log::print( "Creating OpenGL surface %dx%d ... ", windowWidth, windowHeight );
+
OZ_STATIC_MAIN_CALL( {
glInitializePPAPI( pp::Module::Get()->get_browser_interface() );
- createContext();
- glSetCurrentContextPPAPI( context->pp_resource() );
-
- glClearColor( 0.0f, 0.0f, 0.0f, 1.0f );
- glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
- glFlush();
- context->SwapBuffers( pp::CompletionCallback( flushCompleteCallback, nullptr ) );
+ // Array initialiser cannot be nested inside a macro parameter.
+ int attribs[7];
+ attribs[0] = PP_GRAPHICS3DATTRIB_DEPTH_SIZE;
+ attribs[1] = 16;
+ attribs[2] = PP_GRAPHICS3DATTRIB_WIDTH;
+ attribs[3] = windowWidth;
+ attribs[4] = PP_GRAPHICS3DATTRIB_HEIGHT;
+ attribs[5] = windowHeight;
+ attribs[6] = PP_GRAPHICS3DATTRIB_NONE;
+
+ context = new pp::Graphics3D( System::instance, pp::Graphics3D(), attribs );
+
+ if( context->is_null() ) {
+ Log::printEnd( "Failed to create OpenGL context" );
+ }
+ else if( !System::instance->BindGraphics( *context ) ) {
+ Log::printEnd( "Failed to bind Graphics3D" );
+ }
+ else {
+ glSetCurrentContextPPAPI( context->pp_resource() );
+
+ glClearColor( 0.0f, 0.0f, 0.0f, 1.0f );
+ glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
+ glFlush();
+
+ context->SwapBuffers( pp::CompletionCallback( flushCompleteCallback, nullptr ) );
+ }
} )
flushSemaphore.wait();
+ Log::printEnd( "OK" );
+
#else
// Don't mess with screensaver. In X11 it only makes effect for windowed mode, in fullscreen
@@ -257,11 +277,6 @@ bool Window::create( const char* title, int width, int height, bool fullscreen_
if( windowWidth == 0 || windowHeight == 0 ) {
const SDL_VideoInfo* videoInfo = SDL_GetVideoInfo();
- Log::verboseMode = true;
- Log::println( "Desktop video mode: %dx%d-%d", videoInfo->current_w, videoInfo->current_h,
- videoInfo->vfmt->BitsPerPixel );
- Log::verboseMode = false;
-
windowWidth = videoInfo->current_w;
windowHeight = videoInfo->current_h;
}
@@ -322,7 +337,7 @@ bool Window::create( const char* title, int width, int height, bool fullscreen_
#endif
- Log::printEnd( "%dx%d ... OK", windowWidth, windowHeight );
+ Log::printEnd( "OK" );
glViewport( 0, 0, windowWidth, windowHeight );
glClearColor( 0.0f, 0.0f, 0.0f, 1.0f );
View
8 src/ozEngine/Window.hh
@@ -38,7 +38,7 @@ namespace oz
*/
class Window
{
- public:
+ private:
static int windowWidth; ///< Window inner width.
static int windowHeight; ///< Window inner height.
@@ -119,20 +119,20 @@ class Window
static void minimise();
/**
- * Resize window and/or toggle full screen mode.
+ * Resize window and/or toggle full-screen mode.
*
* If either width or height is 0, desktop resolution is used.
* On error, window is destroyed.
*/
- static bool resize( int newWidth, int newHeight, bool fullscreen );
+ static bool resize( int newWidth, int newHeight, bool fullscreen = false );
/**
* Create the window.
*
* If either width or height is 0, desktop resolution is used.
* Invoking this function when the window is already created is an error.
*/
- static bool create( const char* title, int width, int height, bool isFull );
+ static bool create( const char* title, int width, int height, bool fullscreen = false );
/**
* Destroy the window.
View
2 src/tests/test.cc
@@ -28,7 +28,5 @@ using namespace oz;
int main()
{
System::init();
-
- Log::printMemoryLeaks();
return 0;
}
View
2 src/tools/ozManifest.cc
@@ -67,7 +67,7 @@ int main( int argc, char** argv )
Log::indent();
OutputStream os( 0 );
- os.writeChars( "ozManifest", sizeof( "ozManifest" ) );
+ os.writeChars( "ozManifest", int( sizeof( "ozManifest" ) ) );
File outDir( outDirPath );
DArray<File> files = outDir.ls();

0 comments on commit a5a69f0

Please sign in to comment.
Something went wrong with that request. Please try again.