Skip to content

Commit

Permalink
Merge branch 'master' into unblocking-android-stop
Browse files Browse the repository at this point in the history
  • Loading branch information
Shchvova committed Nov 22, 2023
2 parents 9c9385e + 996f85d commit 791c8b0
Show file tree
Hide file tree
Showing 14 changed files with 292 additions and 125 deletions.
186 changes: 164 additions & 22 deletions librtt/Rtt_DisplayObjectExtensions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,124 @@ DisplayObjectExtensions::resetMassData( lua_State *L )
return 0;
}

int
DisplayObjectExtensions::getWorldVector(lua_State* L)
{
DisplayObject* o = (DisplayObject*)LuaProxy::GetProxyableObject(L, 1);

Rtt_WARN_SIM_PROXY_TYPE(L, 1, DisplayObject);

if (o)
{
const PhysicsWorld& physics = LuaContext::GetRuntime(L)->GetPhysicsWorld();
Real scale = physics.GetPixelsPerMeter();

Self* extensions = o->GetExtensions();
b2Body* fBody = extensions->GetBody();

Real lx = Rtt_RealDiv(lua_tonumber(L, 2), scale);
Real ly = Rtt_RealDiv(lua_tonumber(L, 3), scale);

b2Vec2 localVector = b2Vec2(Rtt_RealToFloat(lx), Rtt_RealToFloat(ly));

b2Vec2 worldVector = fBody->GetWorldVector(localVector);

lua_pushnumber(L, worldVector.x);
lua_pushnumber(L, worldVector.y);

return 2;
}

return 0;
}

int
DisplayObjectExtensions::getInertia(lua_State* L)
{
DisplayObject* o = (DisplayObject*)LuaProxy::GetProxyableObject(L, 1);

Rtt_WARN_SIM_PROXY_TYPE(L, 1, DisplayObject);

if (o)
{
const PhysicsWorld& physics = LuaContext::GetRuntime(L)->GetPhysicsWorld();
Real scale = physics.GetPixelsPerMeter();

Self* extensions = o->GetExtensions();
b2Body* fBody = extensions->GetBody();

float32 inertia = fBody->GetInertia() * scale;

lua_pushnumber(L, inertia);

return 1;
}

return 0;
}

int
DisplayObjectExtensions::getLinearVelocityFromWorldPoint(lua_State* L)
{
DisplayObject* o = (DisplayObject*)LuaProxy::GetProxyableObject(L, 1);

Rtt_WARN_SIM_PROXY_TYPE(L, 1, DisplayObject);

if (o)
{
const PhysicsWorld& physics = LuaContext::GetRuntime(L)->GetPhysicsWorld();
Real scale = physics.GetPixelsPerMeter();

Self* extensions = o->GetExtensions();
b2Body* fBody = extensions->GetBody();

Real wx = Rtt_RealDiv(lua_tonumber(L, 2), scale);
Real wy = Rtt_RealDiv(lua_tonumber(L, 3), scale);

b2Vec2 worldPoint = b2Vec2(Rtt_RealToFloat(wx), Rtt_RealToFloat(wy));

b2Vec2 velocity = fBody->GetLinearVelocityFromWorldPoint(worldPoint);

lua_pushnumber(L, velocity.x);
lua_pushnumber(L, velocity.y);

return 2;
}

return 0;
}

int
DisplayObjectExtensions::getLinearVelocityFromLocalPoint(lua_State* L)
{
DisplayObject* o = (DisplayObject*)LuaProxy::GetProxyableObject(L, 1);

Rtt_WARN_SIM_PROXY_TYPE(L, 1, DisplayObject);

if (o)
{
const PhysicsWorld& physics = LuaContext::GetRuntime(L)->GetPhysicsWorld();
Real scale = physics.GetPixelsPerMeter();

Self* extensions = o->GetExtensions();
b2Body* fBody = extensions->GetBody();

Real wx = Rtt_RealDiv(lua_tonumber(L, 2), scale);
Real ly = Rtt_RealDiv(lua_tonumber(L, 3), scale);

b2Vec2 localPoint = b2Vec2(Rtt_RealToFloat(wx), Rtt_RealToFloat(ly));

b2Vec2 velocity = fBody->GetLinearVelocityFromLocalPoint(localPoint);

lua_pushnumber(L, velocity.x);
lua_pushnumber(L, velocity.y);

return 2;
}

return 0;
}

#endif // Rtt_PHYSICS


Expand All @@ -289,30 +407,34 @@ DisplayObjectExtensions::ValueForKey( lua_State *L, const MLuaProxyable& object,

static const char * keys[] =
{
"isAwake", // 0
"isBodyActive", // 1
"isBullet", // 2
"isSleepingAllowed", // 3
"isFixedRotation", // 4
"angularVelocity", // 5
"linearDamping", // 6
"angularDamping", // 7
"bodyType", // 8
"setLinearVelocity", // 9
"getLinearVelocity", // 10
"applyForce", // 11
"applyTorque", // 12
"applyLinearImpulse", // 13
"applyAngularImpulse", // 14
"resetMassData", // 15
"isSensor", // 16
"mass", // 17
"gravityScale", // 18
"getMassWorldCenter", // 19
"getMassLocalCenter", // 20
"isAwake", // 0
"isBodyActive", // 1
"isBullet", // 2
"isSleepingAllowed", // 3
"isFixedRotation", // 4
"angularVelocity", // 5
"linearDamping", // 6
"angularDamping", // 7
"bodyType", // 8
"setLinearVelocity", // 9
"getLinearVelocity", // 10
"applyForce", // 11
"applyTorque", // 12
"applyLinearImpulse", // 13
"applyAngularImpulse", // 14
"resetMassData", // 15
"isSensor", // 16
"mass", // 17
"gravityScale", // 18
"getMassWorldCenter", // 19
"getMassLocalCenter", // 20
"getWorldVector", // 21
"getInertia", // 22
"getLinearVelocityFromWorldPoint", // 23
"getLinearVelocityFromLocalPoint", // 24
};
static const int numKeys = sizeof( keys ) / sizeof( const char * );
static StringHash sHash( *LuaContext::GetAllocator( L ), keys, numKeys, 21, 24, 11, __FILE__, __LINE__ );
static StringHash sHash( *LuaContext::GetAllocator( L ), keys, numKeys, 25, 19, 14, __FILE__, __LINE__ );
StringHash *hash = &sHash;

int index = hash->Lookup( key );
Expand Down Expand Up @@ -435,6 +557,26 @@ DisplayObjectExtensions::ValueForKey( lua_State *L, const MLuaProxyable& object,
lua_pushcfunction( L, Self::getMassLocalCenter );
}
break;
case 21:
{
lua_pushcfunction(L, Self::getWorldVector );
}
break;
case 22:
{
lua_pushcfunction(L, Self::getInertia);
}
break;
case 23:
{
lua_pushcfunction(L, Self::getLinearVelocityFromWorldPoint);
}
break;
case 24:
{
lua_pushcfunction(L, Self::getLinearVelocityFromLocalPoint);
}
break;
default:
{
result = 0;
Expand Down
4 changes: 4 additions & 0 deletions librtt/Rtt_DisplayObjectExtensions.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ class DisplayObjectExtensions : public LuaProxyVTable
static int resetMassData( lua_State *L );
static int getMassWorldCenter( lua_State *L );
static int getMassLocalCenter( lua_State *L );
static int getWorldVector( lua_State *L);
static int getInertia( lua_State *L );
static int getLinearVelocityFromWorldPoint(lua_State *L);
static int getLinearVelocityFromLocalPoint(lua_State* L);

#endif // Rtt_PHYSICS

Expand Down
2 changes: 1 addition & 1 deletion librtt/Rtt_Runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1963,7 +1963,7 @@ Runtime::operator()()
const bool isSuspended = IsSuspended();
if( wasSuspended != isSuspended && isSuspended )
{
// This condition is writtein inverse for better undrerstanding
// This condition is written inverse for better understanding
// Sometimes (Splash Screen is shown) scheduled tasks can suspend Runtime
// In that case (suspension state is changed and it is suspended), skip Display update
}
Expand Down
2 changes: 1 addition & 1 deletion platform/android/app/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# This file is requiered due to Android Studio bug: if main app doesn't use NDK, project woun't use it either.
# This file is required due to Android Studio bug: if main app doesn't use NDK, project won't use it either.
cmake_minimum_required(VERSION 3.4.1)
6 changes: 4 additions & 2 deletions platform/android/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,8 @@ android.applicationVariants.all {
val isRelease = (baseName == "release")
val generatedAssetsDir = "$buildDir/generated/corona_assets/$baseName"
val compiledLuaArchive = "$buildDir/intermediates/compiled_lua_archive/$baseName/resource.car"
// fix assets not been merge when lua file changed
val luaArchiveInMergedAssets = "$buildDir/intermediates/assets/$baseName/resource.car"

val compileLuaTask = tasks.create("compileLua${baseName.capitalize()}") {
description = "If required, compiles Lua and archives it into resource.car"
Expand Down Expand Up @@ -512,9 +514,9 @@ android.applicationVariants.all {

doFirst {
delete(generatedAssetsDir)
delete(luaArchiveInMergedAssets)
mkdir(generatedAssetsDir)
}
doFirst {

if (!file(coronaSrcDir).isDirectory) {
throw InvalidUserDataException("Unable to find Solar2D project (for example platform/test/assets2/main.lua)!")
}
Expand Down
2 changes: 1 addition & 1 deletion platform/android/ndk/Rtt_AndroidPlatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ AndroidPlatform::FileExists( const char *filename ) const
else
{
// The given file name is likely a relative path to an asset file or a URL to a local file.
// Check for its existance via Android's APIs on the Java side.
// Check for its existence via Android's APIs on the Java side.
fileExists = fNativeToJavaBridge->GetRawAssetExists(filename);
if (!fileExists)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public void setId(long id) {
}

/**
* Checks if this applicaction has permission to use the microphone.
* Checks if this application has permission to use the microphone.
* @return Returns true if this application has permission. Returns false if not.
*/
private static boolean hasPermission() {
Expand Down
Loading

0 comments on commit 791c8b0

Please sign in to comment.