mirror of
https://github.com/love2d/love-android.git
synced 2026-08-19 20:20:25 +02:00
Update LÖVE to changeset 7cb21c8bdd64 (pre 0.10.0)
This commit is contained in:
@@ -97,9 +97,19 @@ int w_clear(lua_State *)
|
||||
|
||||
int w_quit(lua_State *L)
|
||||
{
|
||||
Message *m = new Message("quit");
|
||||
std::vector<StrongRef<Variant>> args;
|
||||
|
||||
Variant *v = Variant::fromLua(L, 1);
|
||||
if (v)
|
||||
{
|
||||
args.push_back(v);
|
||||
v->release();
|
||||
}
|
||||
|
||||
Message *m = new Message("quit", args);
|
||||
instance()->push(m);
|
||||
m->release();
|
||||
|
||||
luax_pushboolean(L, true);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -27,9 +27,9 @@
|
||||
#include <sys/stat.h>
|
||||
|
||||
#if defined(LOVE_MACOSX)
|
||||
#include "common/OSX.h"
|
||||
#include "common/macosx.h"
|
||||
#elif defined(LOVE_IOS)
|
||||
#include "common/iOS.h"
|
||||
#include "common/ios.h"
|
||||
#elif defined(LOVE_WINDOWS)
|
||||
#include <windows.h>
|
||||
#include "common/utf8.h"
|
||||
@@ -74,7 +74,7 @@ bool Filesystem::isRealDirectory(const std::string &path) const
|
||||
std::string Filesystem::getExecutablePath() const
|
||||
{
|
||||
#if defined(LOVE_MACOSX)
|
||||
return love::osx::getExecutablePath();
|
||||
return love::macosx::getExecutablePath();
|
||||
#elif defined(LOVE_IOS)
|
||||
return love::ios::getExecutablePath();
|
||||
#elif defined(LOVE_WINDOWS)
|
||||
|
||||
@@ -47,7 +47,7 @@
|
||||
#endif
|
||||
|
||||
#ifdef LOVE_IOS
|
||||
# include "common/iOS.h"
|
||||
# include "common/ios.h"
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
|
||||
@@ -199,7 +199,7 @@ void BMFontRasterizer::parseConfig(const std::string &configtext)
|
||||
throw love::Exception("Image module not loaded!");
|
||||
|
||||
// Release these variables right away since StrongRef retains.
|
||||
StrongRef<filesystem::FileData> data = filesystem->read(filename.c_str());
|
||||
StrongRef<FileData> data = filesystem->read(filename.c_str());
|
||||
data->release();
|
||||
|
||||
images[pageindex].set(imagemodule->newImageData(data.get()));
|
||||
|
||||
@@ -300,6 +300,12 @@ void Canvas::unloadVolatile()
|
||||
|
||||
void Canvas::drawv(const Matrix4 &t, const Vertex *v)
|
||||
{
|
||||
// FIXME: This doesn't handle cases where the Canvas is used as a texture
|
||||
// in a SpriteBatch, Mesh, or ParticleSystem, or when the Canvas is used in
|
||||
// a shader as a non-default texture.
|
||||
if (Canvas::current == this)
|
||||
throw love::Exception("Cannot draw a Canvas to itself.");
|
||||
|
||||
OpenGL::TempDebugGroup debuggroup("Canvas draw");
|
||||
|
||||
OpenGL::TempTransform transform(gl);
|
||||
@@ -327,8 +333,7 @@ void Canvas::drawq(Quad *quad, float x, float y, float angle, float sx, float sy
|
||||
{
|
||||
Matrix4 t(x, y, angle, sx, sy, ox, oy, kx, ky);
|
||||
|
||||
const Vertex *v = quad->getVertices();
|
||||
drawv(t, v);
|
||||
drawv(t, quad->getVertices());
|
||||
}
|
||||
|
||||
void Canvas::setFilter(const Texture::Filter &f)
|
||||
|
||||
@@ -410,8 +410,8 @@ std::vector<Font::DrawCommand> Font::generateVertices(const std::string &text, s
|
||||
for (int j = 0; j < 4; j++)
|
||||
{
|
||||
vertices.push_back(glyph.vertices[j]);
|
||||
vertices.back().x += dx /*+ kerning*/;
|
||||
vertices.back().y += dy /*+ kerning.y*/ + lineheight;
|
||||
vertices.back().x += dx;
|
||||
vertices.back().y += dy + lineheight;
|
||||
}
|
||||
|
||||
// Check if glyph texture has changed since the last iteration.
|
||||
@@ -651,13 +651,12 @@ int Font::getWidth(const std::string &str)
|
||||
prevglyph = c;
|
||||
}
|
||||
}
|
||||
catch(utf8::exception &e)
|
||||
catch (utf8::exception &e)
|
||||
{
|
||||
throw love::Exception("UTF-8 decoding error: %s", e.what());
|
||||
}
|
||||
|
||||
if (width > max_width)
|
||||
max_width = width;
|
||||
max_width = std::max(max_width, width);
|
||||
}
|
||||
|
||||
return max_width;
|
||||
@@ -671,41 +670,41 @@ int Font::getWidth(char character)
|
||||
|
||||
void Font::getWrap(const std::string &text, float wrap, std::vector<std::string> &lines, std::vector<int> *linewidths, std::vector<bool> *wrappedlines)
|
||||
{
|
||||
using namespace std;
|
||||
const float width_space = (float) getWidth(' ');
|
||||
|
||||
//split text at newlines
|
||||
istringstream iss(text);
|
||||
string line;
|
||||
ostringstream string_builder;
|
||||
while (getline(iss, line, '\n'))
|
||||
{
|
||||
// split line into words
|
||||
vector<string> words;
|
||||
istringstream word_iss(line);
|
||||
copy(istream_iterator<string>(word_iss), istream_iterator<string>(),
|
||||
back_inserter< vector<string> >(words));
|
||||
std::istringstream iss(text);
|
||||
std::string line;
|
||||
std::ostringstream string_builder;
|
||||
|
||||
// Split text at newlines.
|
||||
while (std::getline(iss, line, '\n'))
|
||||
{
|
||||
std::vector<std::string> words;
|
||||
std::istringstream word_iss(line);
|
||||
|
||||
// split line into words
|
||||
std::copy(std::istream_iterator<std::string>(word_iss), std::istream_iterator<std::string>(), std::back_inserter(words));
|
||||
|
||||
// put words back together until a wrap occurs
|
||||
float width = 0.0f;
|
||||
float oldwidth = 0.0f;
|
||||
string_builder.str("");
|
||||
vector<string>::const_iterator word_iter, wend = words.end();
|
||||
for (word_iter = words.begin(); word_iter != wend; ++word_iter)
|
||||
{
|
||||
const string &word = *word_iter;
|
||||
width += getWidth(word);
|
||||
|
||||
// on wordwrap, push line to line buffer and clear string builder
|
||||
// Put words back together until a wrap occurs.
|
||||
for (const std::string &word : words)
|
||||
{
|
||||
float wordwidth = (float) getWidth(word);
|
||||
width += wordwidth;
|
||||
|
||||
// On wordwrap, push line to line buffer and clear string builder.
|
||||
if (width > wrap && oldwidth > 0)
|
||||
{
|
||||
int realw = (int) width;
|
||||
|
||||
// remove trailing space
|
||||
string tmp = string_builder.str();
|
||||
// Remove trailing space.
|
||||
std::string tmp = string_builder.str();
|
||||
lines.push_back(tmp.substr(0,tmp.size()-1));
|
||||
string_builder.str("");
|
||||
width = static_cast<float>(getWidth(word));
|
||||
width = wordwidth;
|
||||
realw -= (int) width;
|
||||
|
||||
if (linewidths)
|
||||
@@ -715,15 +714,18 @@ void Font::getWrap(const std::string &text, float wrap, std::vector<std::string>
|
||||
if (wrappedlines)
|
||||
wrappedlines->push_back(true);
|
||||
}
|
||||
|
||||
string_builder << word << " ";
|
||||
|
||||
width += width_space;
|
||||
oldwidth = width;
|
||||
}
|
||||
// push last line
|
||||
|
||||
// Push last line.
|
||||
if (linewidths)
|
||||
linewidths->push_back(width);
|
||||
|
||||
string tmp = string_builder.str();
|
||||
std::string tmp = string_builder.str();
|
||||
lines.push_back(tmp.substr(0,tmp.size()-1));
|
||||
|
||||
// Indicate that this line was not automatically wrapped.
|
||||
|
||||
@@ -1109,17 +1109,24 @@ void Graphics::printf(const std::string &str, float x, float y, float wrap, Font
|
||||
* Primitives
|
||||
**/
|
||||
|
||||
void Graphics::point(float x, float y)
|
||||
void Graphics::points(const float *coords, const uint8 *colors, size_t numpoints)
|
||||
{
|
||||
OpenGL::TempDebugGroup debuggroup("Graphics point draw");
|
||||
|
||||
GLfloat coord[] = {x, y};
|
||||
OpenGL::TempDebugGroup debuggroup("Graphics points draw");
|
||||
|
||||
gl.prepareDraw();
|
||||
gl.bindTexture(gl.getDefaultTexture());
|
||||
gl.useVertexAttribArrays(ATTRIBFLAG_POS);
|
||||
glVertexAttribPointer(ATTRIB_POS, 2, GL_FLOAT, GL_FALSE, 0, coord);
|
||||
gl.drawArrays(GL_POINTS, 0, 1);
|
||||
|
||||
uint32 attribflags = ATTRIBFLAG_POS;
|
||||
glVertexAttribPointer(ATTRIB_POS, 2, GL_FLOAT, GL_FALSE, 0, coords);
|
||||
|
||||
if (colors)
|
||||
{
|
||||
attribflags |= ATTRIBFLAG_COLOR;
|
||||
glVertexAttribPointer(ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, colors);
|
||||
}
|
||||
|
||||
gl.useVertexAttribArrays(attribflags);
|
||||
gl.drawArrays(GL_POINTS, 0, numpoints);
|
||||
}
|
||||
|
||||
void Graphics::polyline(const float *coords, size_t count)
|
||||
|
||||
@@ -351,7 +351,7 @@ public:
|
||||
* @param x Point along x-axis.
|
||||
* @param y Point along y-axis.
|
||||
**/
|
||||
void point(float x, float y);
|
||||
void points(const float *coords, const uint8 *colors, size_t numpoints);
|
||||
|
||||
/**
|
||||
* Draws a series of lines connecting the given vertices.
|
||||
|
||||
@@ -776,14 +776,6 @@ static Mesh *newCustomMesh(lua_State *L)
|
||||
lua_rawgeti(L, 2, vertindex + 1);
|
||||
luaL_checktype(L, -1, LUA_TTABLE);
|
||||
|
||||
if ((int) luax_objlen(L, -1) < vertexcomponents)
|
||||
{
|
||||
t->release();
|
||||
const char *err = "Invalid number of components in vertex #%d (expected %d components, got %d)";
|
||||
luaL_error(L, err, vertindex+1, vertexcomponents, luax_objlen(L, -1));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int n = 0;
|
||||
for (size_t i = 0; i < vertexformat.size(); i++)
|
||||
{
|
||||
@@ -1515,11 +1507,86 @@ int w_printf(lua_State *L)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_point(lua_State *L)
|
||||
int w_points(lua_State *L)
|
||||
{
|
||||
float x = (float)luaL_checknumber(L, 1);
|
||||
float y = (float)luaL_checknumber(L, 2);
|
||||
instance()->point(x, y);
|
||||
// love.graphics.points has 3 variants:
|
||||
// - points(x1, y1, x2, y2, ...)
|
||||
// - points({x1, y1, x2, y2, ...})
|
||||
// - points({{x1, y1 [, r, g, b, a]}, {x2, y2 [, r, g, b, a]}, ...})
|
||||
|
||||
int args = lua_gettop(L);
|
||||
bool is_table = false;
|
||||
bool is_table_of_tables = false;
|
||||
if (args == 1 && lua_istable(L, 1))
|
||||
{
|
||||
is_table = true;
|
||||
args = (int) luax_objlen(L, 1);
|
||||
|
||||
lua_rawgeti(L, 1, 1);
|
||||
is_table_of_tables = lua_istable(L, -1);
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
|
||||
if (args % 2 != 0 && !is_table_of_tables)
|
||||
return luaL_error(L, "Number of vertex components must be a multiple of two");
|
||||
|
||||
int numpoints = args / 2;
|
||||
if (is_table_of_tables)
|
||||
numpoints = args;
|
||||
|
||||
float *coords = nullptr;
|
||||
uint8 *colors = nullptr;
|
||||
|
||||
coords = new float[numpoints * 2];
|
||||
|
||||
if (is_table_of_tables)
|
||||
colors = new uint8[numpoints * 4];
|
||||
|
||||
if (is_table)
|
||||
{
|
||||
if (is_table_of_tables)
|
||||
{
|
||||
// points({{x1, y1 [, r, g, b, a]}, {x2, y2 [, r, g, b, a]}, ...})
|
||||
for (int i = 0; i < args; i++)
|
||||
{
|
||||
lua_rawgeti(L, 1, i + 1);
|
||||
for (int j = 1; j <= 6; j++)
|
||||
lua_rawgeti(L, -j, j);
|
||||
|
||||
coords[i * 2 + 0] = luax_tofloat(L, -6);
|
||||
coords[i * 2 + 1] = luax_tofloat(L, -5);
|
||||
|
||||
colors[i * 4 + 0] = (uint8) luaL_optnumber(L, -4, 255);
|
||||
colors[i * 4 + 1] = (uint8) luaL_optnumber(L, -3, 255);
|
||||
colors[i * 4 + 2] = (uint8) luaL_optnumber(L, -2, 255);
|
||||
colors[i * 4 + 3] = (uint8) luaL_optnumber(L, -1, 255);
|
||||
|
||||
lua_pop(L, 7);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// points({x1, y1, x2, y2, ...})
|
||||
for (int i = 0; i < args; i++)
|
||||
{
|
||||
lua_rawgeti(L, 1, i + 1);
|
||||
coords[i] = luax_tofloat(L, -1);
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < args; i++)
|
||||
coords[i] = luax_tofloat(L, i + 1);
|
||||
}
|
||||
|
||||
instance()->points(coords, colors, numpoints);
|
||||
|
||||
delete[] coords;
|
||||
if (colors)
|
||||
delete[] colors;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1838,7 +1905,7 @@ static const luaL_Reg functions[] =
|
||||
{ "setStencilTest", w_setStencilTest },
|
||||
{ "getStencilTest", w_getStencilTest },
|
||||
|
||||
{ "point", w_point },
|
||||
{ "points", w_points },
|
||||
{ "line", w_line },
|
||||
{ "rectangle", w_rectangle },
|
||||
{ "circle", w_circle },
|
||||
|
||||
@@ -106,7 +106,7 @@ int w_getStats(lua_State *L);
|
||||
int w_draw(lua_State *L);
|
||||
int w_print(lua_State *L);
|
||||
int w_printf(lua_State *L);
|
||||
int w_point(lua_State *L);
|
||||
int w_points(lua_State *L);
|
||||
int w_line(lua_State *L);
|
||||
int w_rectangle(lua_State *L);
|
||||
int w_circle(lua_State *L);
|
||||
|
||||
@@ -210,7 +210,14 @@ int VorbisDecoder::decode()
|
||||
|
||||
bool VorbisDecoder::seek(float s)
|
||||
{
|
||||
int result = ov_time_seek(&handle, s);
|
||||
int result = 0;
|
||||
|
||||
// Avoid ov_time_seek (which calls ov_pcm_seek) when seeking to 0, to avoid
|
||||
// a bug in libvorbis <= 1.3.4 when seeking to PCM 0 in multiplexed streams.
|
||||
if (s <= 0.000001)
|
||||
result = ov_raw_seek(&handle, 0);
|
||||
else
|
||||
result = ov_time_seek(&handle, s);
|
||||
|
||||
if (result == 0)
|
||||
{
|
||||
@@ -223,7 +230,9 @@ bool VorbisDecoder::seek(float s)
|
||||
|
||||
bool VorbisDecoder::rewind()
|
||||
{
|
||||
int result = ov_pcm_seek(&handle, 0);
|
||||
// Avoid ov_time_seek to avoid a bug in libvorbis <= 1.3.4 when seeking to
|
||||
// PCM 0 in multiplexed streams.
|
||||
int result = ov_raw_seek(&handle, 0);
|
||||
|
||||
if (result == 0)
|
||||
{
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#if defined(LOVE_MACOSX)
|
||||
#include <CoreServices/CoreServices.h>
|
||||
#elif defined(LOVE_IOS)
|
||||
#include "common/iOS.h"
|
||||
#include "common/ios.h"
|
||||
#elif defined(LOVE_ANDROID)
|
||||
#include "common/android.h"
|
||||
#elif defined(LOVE_LINUX)
|
||||
@@ -68,9 +68,9 @@ std::string System::getOS() const
|
||||
return "iOS";
|
||||
#elif defined(LOVE_WINDOWS)
|
||||
return "Windows";
|
||||
#elif LOVE_ANDROID
|
||||
#elif defined(LOVE_ANDROID)
|
||||
return "Android";
|
||||
#elif LOVE_LINUX
|
||||
#elif defined(LOVE_LINUX)
|
||||
return "Linux";
|
||||
#else
|
||||
return "Unknown";
|
||||
@@ -146,6 +146,8 @@ void System::vibrate(double seconds) const
|
||||
{
|
||||
#ifdef LOVE_ANDROID
|
||||
love::android::vibrate(seconds);
|
||||
#elif defined(LOVE_IOS)
|
||||
love::ios::vibrate();
|
||||
#else
|
||||
LOVE_UNUSED(seconds);
|
||||
#endif
|
||||
|
||||
@@ -88,7 +88,7 @@ int w_openURL(lua_State *L)
|
||||
|
||||
int w_vibrate(lua_State *L)
|
||||
{
|
||||
double seconds = luaL_checknumber(L, 1);
|
||||
double seconds = luaL_optnumber(L, 1, 0.5);
|
||||
instance()->vibrate(seconds);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
#if defined(LOVE_WINDOWS)
|
||||
#include <windows.h>
|
||||
#elif defined(LOVE_MACOSX)
|
||||
#include "common/OSX.h"
|
||||
#include "common/macosx.h"
|
||||
#endif
|
||||
|
||||
#ifndef APIENTRY
|
||||
@@ -132,12 +132,14 @@ void Window::setGLContextAttributes(const ContextAttribs &attribs)
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, contextflags);
|
||||
}
|
||||
|
||||
bool Window::checkGLVersion(const ContextAttribs &attribs)
|
||||
bool Window::checkGLVersion(const ContextAttribs &attribs, std::string &outversion)
|
||||
{
|
||||
typedef unsigned char GLubyte;
|
||||
typedef unsigned int GLenum;
|
||||
typedef const GLubyte *(APIENTRY *glGetStringPtr)(GLenum name);
|
||||
const GLenum GL_VERSION_ENUM = 0x1F02;
|
||||
const GLenum GL_VENDOR_ENUM = 0x1F00;
|
||||
const GLenum GL_RENDERER_ENUM = 0x1F01;
|
||||
const GLenum GL_VERSION_ENUM = 0x1F02;
|
||||
|
||||
// We don't have OpenGL headers or an automatic OpenGL function loader in
|
||||
// this module, so we have to get the glGetString function pointer ourselves.
|
||||
@@ -149,6 +151,16 @@ bool Window::checkGLVersion(const ContextAttribs &attribs)
|
||||
if (!glversion)
|
||||
return false;
|
||||
|
||||
outversion = glversion;
|
||||
|
||||
const char *glrenderer = (const char *) glGetStringFunc(GL_RENDERER_ENUM);
|
||||
if (glrenderer)
|
||||
outversion += " - " + std::string(glrenderer);
|
||||
|
||||
const char *glvendor = (const char *) glGetStringFunc(GL_VENDOR_ENUM);
|
||||
if (glvendor)
|
||||
outversion += " (" + std::string(glvendor) + ")";
|
||||
|
||||
int glmajor = 0;
|
||||
int glminor = 0;
|
||||
|
||||
@@ -229,6 +241,7 @@ bool Window::createWindowAndContext(int x, int y, int w, int h, Uint32 windowfla
|
||||
}
|
||||
|
||||
std::string windowerror;
|
||||
std::string glversion;
|
||||
|
||||
// Try each context profile in order.
|
||||
for (ContextAttribs attribs : attribslist)
|
||||
@@ -320,7 +333,7 @@ bool Window::createWindowAndContext(int x, int y, int w, int h, Uint32 windowfla
|
||||
}
|
||||
|
||||
// Make sure the context's version is at least what we requested.
|
||||
if (context && !checkGLVersion(attribs))
|
||||
if (context && !checkGLVersion(attribs, glversion))
|
||||
{
|
||||
SDL_GL_DeleteContext(context);
|
||||
context = nullptr;
|
||||
@@ -354,6 +367,9 @@ bool Window::createWindowAndContext(int x, int y, int w, int h, Uint32 windowfla
|
||||
std::string title = "Unable to initialize OpenGL";
|
||||
std::string message = "This program requires a graphics card and video drivers which support OpenGL 2.1 or OpenGL ES 2.";
|
||||
|
||||
if (!glversion.empty())
|
||||
message += " \n\nDetected OpenGL version: " + glversion;
|
||||
|
||||
std::cerr << title << std::endl << message << std::endl;
|
||||
|
||||
// Display a message box with the error, but only once.
|
||||
@@ -1031,7 +1047,7 @@ void Window::requestAttention(bool continuous)
|
||||
|
||||
#elif defined(LOVE_MACOSX)
|
||||
|
||||
love::osx::requestAttention(continuous);
|
||||
love::macosx::requestAttention(continuous);
|
||||
|
||||
#else
|
||||
|
||||
|
||||
@@ -118,7 +118,7 @@ private:
|
||||
|
||||
void setGLFramebufferAttributes(int msaa, bool sRGB);
|
||||
void setGLContextAttributes(const ContextAttribs &attribs);
|
||||
bool checkGLVersion(const ContextAttribs &attribs);
|
||||
bool checkGLVersion(const ContextAttribs &attribs, std::string &outversion);
|
||||
bool createWindowAndContext(int x, int y, int w, int h, Uint32 windowflags, int msaa);
|
||||
|
||||
// Update the saved window settings based on the window's actual state.
|
||||
|
||||
Reference in New Issue
Block a user