Merge branch 'master' into 12.0-development

This commit is contained in:
Alex Szpakowski
2021-01-06 21:49:34 -04:00
5 changed files with 81 additions and 9 deletions
+37 -9
View File
@@ -106,14 +106,25 @@ bool NativeFile::isOpen() const
int64 NativeFile::getSize()
{
int fd = file ? fileno(file) : -1;
#ifdef LOVE_WINDOWS
struct _stat64 buf;
// make sure non-ASCII filenames work.
std::wstring wfilename = to_widestr(filename);
if (fd != -1)
{
if (_fstat64(fd, &buf) != 0)
return -1;
}
else
{
// make sure non-ASCII filenames work.
std::wstring wfilename = to_widestr(filename);
struct _stat buf;
if (_wstat(wfilename.c_str(), &buf) != 0)
return -1;
if (_wstat64(wfilename.c_str(), &buf) != 0)
return -1;
}
return (int64) buf.st_size;
@@ -121,7 +132,13 @@ int64 NativeFile::getSize()
// Assume POSIX support...
struct stat buf;
if (stat(filename.c_str(), &buf) != 0)
if (fd != -1)
{
if (fstat(fd, &buf) != 0)
return -1;
}
else if (stat(filename.c_str(), &buf) != 0)
return -1;
return (int64) buf.st_size;
@@ -165,7 +182,7 @@ bool NativeFile::flush()
bool NativeFile::isEOF()
{
return file == nullptr || feof(file) != 0;
return file == nullptr || tell() >= getSize();
}
int64 NativeFile::tell()
@@ -173,12 +190,23 @@ int64 NativeFile::tell()
if (file == nullptr)
return -1;
return (int64) ftell(file);
#ifdef LOVE_WINDOWS
return (int64) _ftelli64(file);
#else
return (int64) ftello(file);
#endif
}
bool NativeFile::seek(uint64 pos)
{
return file != nullptr && fseek(file, (long) pos, SEEK_SET) == 0;
if (file == nullptr)
return false;
#ifdef LOVE_WINDOWS
return _fseeki64(file, (int64) pos, SEEK_SET) == 0;
#else
return fseeko(file, (off_t) pos, SEEK_SET) == 0;
#endif
}
bool NativeFile::setBuffer(BufferMode bufmode, int64 size)
+24
View File
@@ -361,6 +361,30 @@ void Body::getLocalVector(float x, float y, float &x_o, float &y_o)
y_o = v.y;
}
int Body::getLocalPoints(lua_State *L)
{
int argc = lua_gettop(L);
int vcount = (int)argc/2;
// at least one point
love::luax_assert_argc(L, 2);
for (int i = 0; i<vcount; i++)
{
float x = (float)lua_tonumber(L, 1);
float y = (float)lua_tonumber(L, 2);
// Remove them, so we don't run out of stack space
lua_remove(L, 1);
lua_remove(L, 1);
// Time for scaling
b2Vec2 point = Physics::scaleUp(body->GetLocalPoint(Physics::scaleDown(b2Vec2(x, y))));
// And then we push the result
lua_pushnumber(L, point.x);
lua_pushnumber(L, point.y);
}
return argc;
}
void Body::getLinearVelocityFromWorldPoint(float x, float y, float &x_o, float &y_o)
{
b2Vec2 v = Physics::scaleUp(body->GetLinearVelocityFromWorldPoint(Physics::scaleDown(b2Vec2(x, y))));
+6
View File
@@ -327,6 +327,12 @@ public:
**/
void getLocalVector(float x, float y, float &x_o, float &y_o);
/**
* Transforms a series of points (x, y) from world coordinates
* to local coordinates.
**/
int getLocalPoints(lua_State *L);
/**
* Gets the velocity on the Body for the given world point.
* @param x The x-coordinate of the world point.
+8
View File
@@ -472,6 +472,13 @@ int w_Body_getLocalVector(lua_State *L)
return 2;
}
int w_Body_getLocalPoints(lua_State *L)
{
Body *t = luax_checkbody(L, 1);
lua_remove(L, 1);
return t->getLocalPoints(L);
}
int w_Body_getLinearVelocityFromWorldPoint(lua_State *L)
{
Body *t = luax_checkbody(L, 1);
@@ -691,6 +698,7 @@ static const luaL_Reg w_Body_functions[] =
{ "getWorldPoints", w_Body_getWorldPoints },
{ "getLocalPoint", w_Body_getLocalPoint },
{ "getLocalVector", w_Body_getLocalVector },
{ "getLocalPoints", w_Body_getLocalPoints },
{ "getLinearVelocityFromWorldPoint", w_Body_getLinearVelocityFromWorldPoint },
{ "getLinearVelocityFromLocalPoint", w_Body_getLinearVelocityFromLocalPoint },
{ "isBullet", w_Body_isBullet },