Merged default into minor

--HG--
branch : minor
This commit is contained in:
Alex Szpakowski
2014-04-01 20:46:31 -03:00
50 changed files with 416 additions and 160 deletions
+4 -1
View File
@@ -25,6 +25,9 @@
#include "config.h"
#include "Object.h"
// C
#include <stddef.h>
namespace love
{
@@ -49,7 +52,7 @@ public:
/**
* Gets the size of the Data in bytes.
**/
virtual int getSize() const = 0;
virtual size_t getSize() const = 0;
}; // Data
Regular → Executable
+21
View File
@@ -45,6 +45,27 @@ std::string to_utf8(LPCWSTR wstr)
return ret;
}
std::wstring to_widestr(const std::string &str)
{
if (str.empty())
return std::wstring();
int wide_size = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), (int) str.length(), nullptr, 0);
if (wide_size == 0)
return std::wstring();
std::wstring widestr;
widestr.resize(wide_size);
int ok = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), (int) str.length(), &widestr[0], widestr.length());
if (!ok)
return std::wstring();
return widestr;
}
void replace_char(std::string &str, char find, char replace)
{
int length = str.length();
Regular → Executable
+7
View File
@@ -35,6 +35,13 @@ namespace love
**/
std::string to_utf8(LPCWSTR wstr);
/**
* Convert a UTF-8 encoded string to a wide string.
* @param str The UTF-8 string.
* @return A wide string.
**/
std::wstring to_widestr(const std::string &str);
/**
* Replace all occurences of 'find' with 'replace' in a string.
* @param str The string to modify.
+2 -2
View File
@@ -31,7 +31,7 @@ Data *luax_checkdata(lua_State *L, int idx)
int w_Data_getString(lua_State *L)
{
Data *t = luax_checkdata(L, 1);
lua_pushlstring(L, (const char *) t->getData(), (size_t) t->getSize());
lua_pushlstring(L, (const char *) t->getData(), t->getSize());
return 1;
}
@@ -45,7 +45,7 @@ int w_Data_getPointer(lua_State *L)
int w_Data_getSize(lua_State *L)
{
Data *t = luax_checkdata(L, 1);
lua_pushinteger(L, t->getSize());
lua_pushnumber(L, (lua_Number) t->getSize());
return 1;
}
+1 -1
View File
@@ -89,7 +89,7 @@ static void parse_address(lua_State *l, const char *addr_str, ENetAddress *addre
/**
* Find the index of a given peer for which we only have the pointer.
*/
size_t find_peer_index (lua_State *l, ENetHost *enet_host, ENetPeer *peer) {
static size_t find_peer_index(lua_State *l, ENetHost *enet_host, ENetPeer *peer) {
size_t peer_index;
for (peer_index = 0; peer_index < enet_host->peerCount; peer_index++) {
if (peer == &(enet_host->peers[peer_index]))
+6
View File
@@ -1,3 +1,9 @@
ENet 1.3.11 (December 26, 2013):
* allow an ENetHost to connect to itself
* fixed possible bug with disconnect notifications during connect attempts
* fixed some preprocessor definition bugs
ENet 1.3.10 (October 23, 2013);
* doubled maximum reliable window size
@@ -25,7 +25,7 @@ extern "C"
#define ENET_VERSION_MAJOR 1
#define ENET_VERSION_MINOR 3
#define ENET_VERSION_PATCH 10
#define ENET_VERSION_PATCH 11
#define ENET_VERSION_CREATE(major, minor, patch) (((major)<<16) | ((minor)<<8) | (patch))
#define ENET_VERSION_GET_MAJOR(version) (((version)>>16)&0xFF)
#define ENET_VERSION_GET_MINOR(version) (((version)>>8)&0xFF)
@@ -54,7 +54,7 @@ typedef enum _ENetProtocolFlag
ENET_PROTOCOL_HEADER_SESSION_SHIFT = 12
} ENetProtocolFlag;
#ifdef _MSC_VER_
#ifdef _MSC_VER
#pragma pack(push, 1)
#define ENET_PACKED
#elif defined(__GNUC__) || defined(__clang__)
@@ -191,7 +191,7 @@ typedef union _ENetProtocol
ENetProtocolThrottleConfigure throttleConfigure;
} ENET_PACKED ENetProtocol;
#ifdef _MSC_VER_
#ifdef _MSC_VER
#pragma pack(pop)
#endif
@@ -40,7 +40,7 @@ typedef fd_set ENetSocketSet;
#define ENET_SOCKETSET_EMPTY(sockset) FD_ZERO (& (sockset))
#define ENET_SOCKETSET_ADD(sockset, socket) FD_SET (socket, & (sockset))
#define ENET_SOCKETSET_REMOVE(sockset, socket) FD_CLEAR (socket, & (sockset))
#define ENET_SOCKETSET_REMOVE(sockset, socket) FD_CLR (socket, & (sockset))
#define ENET_SOCKETSET_CHECK(sockset, socket) FD_ISSET (socket, & (sockset))
#endif /* __ENET_UNIX_H__ */
@@ -50,7 +50,7 @@ typedef fd_set ENetSocketSet;
#define ENET_SOCKETSET_EMPTY(sockset) FD_ZERO (& (sockset))
#define ENET_SOCKETSET_ADD(sockset, socket) FD_SET (socket, & (sockset))
#define ENET_SOCKETSET_REMOVE(sockset, socket) FD_CLEAR (socket, & (sockset))
#define ENET_SOCKETSET_REMOVE(sockset, socket) FD_CLR (socket, & (sockset))
#define ENET_SOCKETSET_CHECK(sockset, socket) FD_ISSET (socket, & (sockset))
#endif /* __ENET_WIN32_H__ */
+3 -2
View File
@@ -297,7 +297,8 @@ enet_protocol_handle_connect (ENetHost * host, ENetProtocolHeader * header, ENet
peer = currentPeer;
}
else
if (currentPeer -> address.host == host -> receivedAddress.host)
if (currentPeer -> state != ENET_PEER_STATE_CONNECTING &&
currentPeer -> address.host == host -> receivedAddress.host)
{
if (currentPeer -> address.port == host -> receivedAddress.port &&
currentPeer -> connectID == command -> connect.connectID)
@@ -819,7 +820,7 @@ enet_protocol_handle_disconnect (ENetHost * host, ENetPeer * peer, const ENetPro
enet_peer_reset_queues (peer);
if (peer -> state == ENET_PEER_STATE_CONNECTION_SUCCEEDED || peer -> state == ENET_PEER_STATE_DISCONNECTING)
if (peer -> state == ENET_PEER_STATE_CONNECTION_SUCCEEDED || peer -> state == ENET_PEER_STATE_DISCONNECTING || peer -> state == ENET_PEER_STATE_CONNECTING)
enet_protocol_dispatch_state (host, peer, ENET_PEER_STATE_ZOMBIE);
else
if (peer -> state != ENET_PEER_STATE_CONNECTED && peer -> state != ENET_PEER_STATE_DISCONNECT_LATER)
+2 -2
View File
@@ -468,8 +468,8 @@ void Source::getDirection(float *v) const
void Source::setCone(float innerAngle, float outerAngle, float outerVolume)
{
cone.innerAngle = LOVE_TODEG(innerAngle);
cone.outerAngle = LOVE_TODEG(outerAngle);
cone.innerAngle = (int) LOVE_TODEG(innerAngle);
cone.outerAngle = (int) LOVE_TODEG(outerAngle);
cone.outerVolume = outerVolume;
if (valid)
+3 -1
View File
@@ -27,6 +27,7 @@
#include "graphics/Graphics.h"
#include "window/Window.h"
#include "common/Exception.h"
#include "common/config.h"
#include <cmath>
@@ -427,7 +428,8 @@ Message *Event::convertWindowEvent(const SDL_Event &e) const
int px_w = e.window.data1;
int px_h = e.window.data2;
#if SDL_VERSION_ATLEAST(2,0,1)
// FIXME: disabled in Linux for runtime SDL 2.0.0 compatibility.
#if SDL_VERSION_ATLEAST(2,0,1) && !defined(LOVE_LINUX)
SDL_Window *sdlwin = SDL_GetWindowFromID(e.window.windowID);
if (sdlwin)
SDL_GL_GetDrawableSize(sdlwin, &px_w, &px_h);
+6 -11
View File
@@ -20,9 +20,9 @@
#include "FileData.h"
// STD
// C++
#include <iostream>
#include <climits>
#include <limits>
namespace love
{
@@ -31,7 +31,7 @@ namespace filesystem
FileData::FileData(uint64 size, const std::string &filename)
: data(new char[(size_t) size])
, size(size)
, size((size_t) size)
, filename(filename)
{
if (filename.rfind('.') != std::string::npos)
@@ -48,15 +48,10 @@ void *FileData::getData() const
return (void *)data;
}
// TODO: Enable this
/*uint64 FileData::getSize() const
size_t FileData::getSize() const
{
return size;
}*/
int FileData::getSize() const
{
return size > INT_MAX ? INT_MAX : (int) size;
size_t sizemax = std::numeric_limits<size_t>::max();
return size > sizemax ? sizemax : (size_t) size;
}
const std::string &FileData::getFilename() const
+1 -3
View File
@@ -49,9 +49,7 @@ public:
// Implements Data.
void *getData() const;
//TODO: Enable this
//uint64 getSize() const;
int getSize() const;
size_t getSize() const;
const std::string &getFilename() const;
const std::string &getExtension() const;
@@ -397,6 +397,16 @@ std::string Filesystem::getSourceBaseDirectory() const
return game_source.substr(0, base_end_pos);
}
std::string Filesystem::getRealDirectory(const char *filename) const
{
const char *dir = PHYSFS_getRealDir(filename);
if (dir == nullptr)
throw love::Exception("File does not exist.");
return std::string(dir);
}
bool Filesystem::exists(const char *file) const
{
return PHYSFS_exists(file);
@@ -467,6 +477,10 @@ void Filesystem::append(const char *filename, const void *data, int64 size) cons
int Filesystem::getDirectoryItems(lua_State *L)
{
const char *dir = luaL_checkstring(L, 1);
bool hascallback = !lua_isnoneornil(L, 2);
if (hascallback)
luaL_checktype(L, 2, LUA_TFUNCTION);
char **rc = PHYSFS_enumerateFiles(dir);
int index = 1;
@@ -475,6 +489,13 @@ int Filesystem::getDirectoryItems(lua_State *L)
for (char **i = rc; *i != 0; i++)
{
if (hascallback)
{
lua_pushvalue(L, 2);
lua_pushstring(L, *i);
lua_call(L, 1, 0);
}
lua_pushstring(L, *i);
lua_rawseti(L, -2, index);
index++;
@@ -166,6 +166,11 @@ public:
**/
std::string getSourceBaseDirectory() const;
/**
* Gets the real directory path containing the file.
**/
std::string getRealDirectory(const char *filename) const;
/**
* Checks whether a file exists in the current search path
* or not.
@@ -526,9 +526,31 @@ int extloader(lua_State *L)
tokenized_name += library_extension();
void *handle = SDL_LoadObject((std::string(instance->getAppdataDirectory()) + LOVE_PATH_SEPARATOR LOVE_APPDATA_FOLDER LOVE_PATH_SEPARATOR + tokenized_name).c_str());
if (!handle && instance->isFused())
handle = SDL_LoadObject((std::string(instance->getSaveDirectory()) + LOVE_PATH_SEPARATOR + tokenized_name).c_str());
void *handle = nullptr;
// If the game is fused, try looking for the DLL in the game's read paths.
if (instance->isFused())
{
try
{
std::string dir = instance->getRealDirectory(tokenized_name.c_str());
// We don't want to look in the game's source, because it can be a
// zip sometimes and a folder other times.
if (dir.find(instance->getSource()) == std::string::npos)
handle = SDL_LoadObject((dir + LOVE_PATH_SEPARATOR + tokenized_name).c_str());
}
catch (love::Exception &)
{
// Nothing...
}
}
if (!handle)
{
std::string path = std::string(instance->getAppdataDirectory()) + LOVE_PATH_SEPARATOR LOVE_APPDATA_FOLDER LOVE_PATH_SEPARATOR + tokenized_name;
handle = SDL_LoadObject(path.c_str());
}
if (!handle)
{
+3 -3
View File
@@ -64,16 +64,16 @@ void *GlyphData::getData() const
return (void *) data;
}
int GlyphData::getSize() const
size_t GlyphData::getSize() const
{
switch (format)
{
case GlyphData::FORMAT_LUMINANCE_ALPHA:
return getWidth() * getHeight() * 2;
return size_t(getWidth() * getHeight() * 2);
break;
case GlyphData::FORMAT_RGBA:
default:
return getWidth() * getHeight() * 4;
return size_t(getWidth() * getHeight() * 4);
break;
}
+1 -1
View File
@@ -67,7 +67,7 @@ public:
// Implements Data.
void *getData() const;
int getSize() const;
size_t getSize() const;
/**
* Gets the height of the glyph.
@@ -33,12 +33,15 @@ namespace freetype
TrueTypeRasterizer::TrueTypeRasterizer(FT_Library library, Data *data, int size)
: data(data)
{
if (FT_New_Memory_Face(library,
(const FT_Byte *)data->getData(), /* first byte in memory */
data->getSize(), /* size in bytes */
0, /* face_index */
&face))
throw love::Exception("TrueTypeFont Loading error: FT_New_Face failed (there is probably a problem with your font file)");
FT_Error err = FT_Err_Ok;
err = FT_New_Memory_Face(library,
(const FT_Byte *)data->getData(), /* first byte in memory */
data->getSize(), /* size in bytes */
0, /* face_index */
&face);
if (err != FT_Err_Ok)
throw love::Exception("TrueType Font Loading error: FT_New_Face failed: 0x%x (problem with font file?)", err);
FT_Set_Pixel_Sizes(face, size, size);
@@ -68,12 +71,18 @@ GlyphData *TrueTypeRasterizer::getGlyphData(uint32 glyph) const
love::font::GlyphMetrics glyphMetrics = {};
FT_Glyph ftglyph;
// Initialize
if (FT_Load_Glyph(face, FT_Get_Char_Index(face, glyph), FT_LOAD_DEFAULT))
throw love::Exception("TrueTypeFont Loading error: FT_Load_Glyph failed");
FT_Error err = FT_Err_Ok;
if (FT_Get_Glyph(face->glyph, &ftglyph))
throw love::Exception("TrueTypeFont Loading error: FT_Get_Glyph failed");
// Initialize
err = FT_Load_Glyph(face, FT_Get_Char_Index(face, glyph), FT_LOAD_DEFAULT);
if (err != FT_Err_Ok)
throw love::Exception("TrueType Font Loading error: FT_Load_Glyph failed (0x%x)", err);
err = FT_Get_Glyph(face->glyph, &ftglyph);
if (err != FT_Err_Ok)
throw love::Exception("TrueType Font Loading error: FT_Get_Glyph failed (0x%x)", err);
FT_Glyph_To_Bitmap(&ftglyph, FT_RENDER_MODE_NORMAL, 0, 1);
+1
View File
@@ -134,6 +134,7 @@ StringMap<Graphics::BlendMode, Graphics::BLEND_MAX_ENUM>::Entry Graphics::blendM
{ "subtractive", Graphics::BLEND_SUBTRACTIVE },
{ "multiplicative", Graphics::BLEND_MULTIPLICATIVE },
{ "premultiplied", Graphics::BLEND_PREMULTIPLIED },
{ "screen", Graphics::BLEND_SCREEN },
{ "replace", Graphics::BLEND_REPLACE },
};
+1
View File
@@ -57,6 +57,7 @@ public:
BLEND_SUBTRACTIVE,
BLEND_MULTIPLICATIVE,
BLEND_PREMULTIPLIED,
BLEND_SCREEN,
BLEND_REPLACE,
BLEND_MAX_ENUM
};
+12 -2
View File
@@ -265,15 +265,19 @@ bool Graphics::setMode(int width, int height, bool &sRGB)
void Graphics::unSetMode()
{
if (!isCreated())
return;
// Window re-creation may destroy the GL context, so we must save the state.
if (isCreated())
savedState = saveState();
savedState = saveState();
// Unload all volatile objects. These must be reloaded after the display
// mode change.
Volatile::unloadAll();
gl.deInitContext();
created = false;
}
static void APIENTRY debugCB(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei /*len*/, const GLchar *msg, GLvoid* /*usr*/)
@@ -649,6 +653,10 @@ void Graphics::setBlendMode(Graphics::BlendMode mode)
state.srcRGB = state.srcA = GL_SRC_ALPHA;
state.dstRGB = state.dstA = GL_ONE;
break;
case BLEND_SCREEN:
state.srcRGB = state.srcA = GL_ONE;
state.dstRGB = state.dstA = GL_ONE_MINUS_SRC_COLOR;
break;
case BLEND_REPLACE:
default:
state.srcRGB = state.srcA = GL_ONE;
@@ -676,6 +684,8 @@ Graphics::BlendMode Graphics::getBlendMode() const
return BLEND_MULTIPLICATIVE;
else if (state.srcRGB == GL_ONE && state.dstRGB == GL_ONE_MINUS_SRC_ALPHA)
return BLEND_PREMULTIPLIED;
else if (state.srcRGB == GL_ONE && state.dstRGB == GL_ONE_MINUS_SRC_COLOR)
return BLEND_SCREEN;
else if (state.srcRGB == GL_ONE && state.dstRGB == GL_ZERO)
return BLEND_REPLACE;
}
+6 -2
View File
@@ -371,8 +371,12 @@ static const luaL_Reg functions[] =
{ "getVertexCount", w_Mesh_getVertexCount },
{ "setVertexMap", w_Mesh_setVertexMap },
{ "getVertexMap", w_Mesh_getVertexMap },
{ "setInstanceCount", w_Mesh_setInstanceCount },
{ "getInstanceCount", w_Mesh_getInstanceCount },
// Disabled for now, since implementation is incomplete and might change
// if/when VertexBuffers / custom vertex attributes are added.
// { "setInstanceCount", w_Mesh_setInstanceCount },
// { "getInstanceCount", w_Mesh_getInstanceCount },
{ "setTexture", w_Mesh_setTexture },
{ "getTexture", w_Mesh_getTexture },
{ "setDrawMode", w_Mesh_setDrawMode },
+4 -4
View File
@@ -36,9 +36,9 @@ CompressedData::~CompressedData()
{
}
int CompressedData::getSize() const
size_t CompressedData::getSize() const
{
return int(dataSize);
return dataSize;
}
void *CompressedData::getData() const
@@ -51,11 +51,11 @@ int CompressedData::getMipmapCount() const
return dataImages.size();
}
int CompressedData::getSize(int miplevel) const
size_t CompressedData::getSize(int miplevel) const
{
checkMipmapLevelExists(miplevel);
return int(dataImages[miplevel].size);
return dataImages[miplevel].size;
}
void *CompressedData::getData(int miplevel) const
+2 -2
View File
@@ -71,7 +71,7 @@ public:
// Implements Data.
virtual void *getData() const;
virtual int getSize() const;
virtual size_t getSize() const;
/**
* Gets the number of mipmaps in this Compressed Image Data.
@@ -82,7 +82,7 @@ public:
/**
* Gets the size in bytes of a sub-image at the specified mipmap level.
**/
int getSize(int miplevel) const;
size_t getSize(int miplevel) const;
/**
* Gets the byte data of a sub-image at the specified mipmap level.
+2 -2
View File
@@ -38,9 +38,9 @@ ImageData::~ImageData()
delete mutex;
}
int ImageData::getSize() const
size_t ImageData::getSize() const
{
return getWidth()*getHeight()*sizeof(pixel);
return size_t(getWidth()*getHeight())*sizeof(pixel);
}
void *ImageData::getData() const
+1 -1
View File
@@ -130,7 +130,7 @@ public:
// Implements Data.
virtual void *getData() const;
virtual int getSize() const;
virtual size_t getSize() const;
protected:
+13 -13
View File
@@ -198,14 +198,14 @@ bool Math::isConvex(const std::vector<Vertex> &polygon)
**/
float Math::gammaToLinear(float c) const
{
if (c > 1.0)
return 1.0;
else if (c < 0.0)
return 0.0;
if (c > 1.0f)
return 1.0f;
else if (c < 0.0f)
return 0.0f;
else if (c <= 0.04045)
return c / 12.92;
return c / 12.92f;
else
return powf((c + 0.055) / 1.055, 2.4);
return powf((c + 0.055f) / 1.055f, 2.4f);
}
/**
@@ -213,14 +213,14 @@ float Math::gammaToLinear(float c) const
**/
float Math::linearToGamma(float c) const
{
if (c > 1.0)
return 1.0;
else if (c < 0.0)
return 0.0;
else if (c < 0.0031308)
return c * 12.92;
if (c > 1.0f)
return 1.0f;
else if (c < 0.0f)
return 0.0f;
else if (c < 0.0031308f)
return c * 12.92f;
else
return 1.055 * powf(c, 0.41666) - 0.055;
return 1.055f * powf(c, 0.41666f) - 0.055f;
}
} // math
+2 -2
View File
@@ -259,7 +259,7 @@ static int getGammaArgs(lua_State *L, float color[4])
for (int i = 1; i <= n && i <= 4; i++)
{
lua_rawgeti(L, 1, i);
color[i - 1] = (float) luaL_checknumber(L, -1) / 255.0;
color[i - 1] = (float) luaL_checknumber(L, -1) / 255.0f;
numcomponents++;
}
@@ -270,7 +270,7 @@ static int getGammaArgs(lua_State *L, float color[4])
int n = lua_gettop(L);
for (int i = 1; i <= n && i <= 4; i++)
{
color[i - 1] = (float) luaL_checknumber(L, i) / 255.0;
color[i - 1] = (float) luaL_checknumber(L, i) / 255.0f;
numcomponents++;
}
}
+1 -1
View File
@@ -202,7 +202,7 @@ uint16 Fixture::getBits(lua_State *L)
{
size_t bpos = (size_t)(lua_tointeger(L, i)-1);
if (bpos >= 16)
return luaL_error(L, "Values must be in range 1-16.");
luaL_error(L, "Values must be in range 1-16.");
b.set(bpos, true);
}
+25 -19
View File
@@ -21,11 +21,11 @@
#include "SoundData.h"
// C
#include <climits>
#include <cstdlib>
#include <cstring>
// STL
// C++
#include <limits>
#include <iostream>
#include <vector>
@@ -48,11 +48,11 @@ SoundData::SoundData(Decoder *decoder)
{
// Expand or allocate buffer. Note that realloc may move
// memory to other locations.
if (!data || bufferSize < (size_t) size + decoded)
if (!data || bufferSize < size + decoded)
{
while (bufferSize < (size_t) size + decoded)
while (bufferSize < size + decoded)
bufferSize <<= 1;
data = (int8 *) realloc(data, bufferSize);
data = (uint8 *) realloc(data, bufferSize);
}
if (!data)
@@ -61,22 +61,22 @@ SoundData::SoundData(Decoder *decoder)
// Copy memory into new part of memory.
memcpy(data + size, decoder->getBuffer(), decoded);
// Keep this up to date.
size += decoded;
// Overflow check.
if (size < 0)
if (size > std::numeric_limits<size_t>::max() - decoded)
{
free(data);
throw love::Exception("Not enough memory.");
}
// Keep this up to date.
size += decoded;
decoded = decoder->decode();
}
// Shrink buffer if necessary.
if (data && bufferSize > (size_t) size)
data = (int8 *) realloc(data, size);
if (data && bufferSize > size)
data = (uint8 *) realloc(data, size);
channels = decoder->getChannels();
bitDepth = decoder->getBitDepth();
@@ -136,15 +136,17 @@ void SoundData::load(int samples, int sampleRate, int bitDepth, int channels, vo
double realsize = samples;
realsize *= (bitDepth / 8) * channels;
if (realsize > INT_MAX)
if (realsize > std::numeric_limits<size_t>::max())
throw love::Exception("Data is too big!");
data = (int8 *) malloc(size);
data = (uint8 *) malloc(size);
if (!data)
throw love::Exception("Not enough memory.");
if (newData)
memcpy(data, newData, size);
else
memset(data, bitDepth == 8 ? 128 : 0, size);
}
void *SoundData::getData() const
@@ -152,9 +154,9 @@ void *SoundData::getData() const
return (void *)data;
}
int SoundData::getSize() const
size_t SoundData::getSize() const
{
return (int)size;
return size;
}
int SoundData::getChannels() const
@@ -185,34 +187,38 @@ float SoundData::getDuration() const
void SoundData::setSample(int i, float sample)
{
// Check range.
if (i < 0 || i >= size/(bitDepth/8))
if (i < 0 || (size_t) i >= size/(bitDepth/8))
throw love::Exception("Attempt to set out-of-range sample!");
if (bitDepth == 16)
{
// 16-bit sample values are signed.
int16 *s = (int16 *) data;
s[i] = (int16) (sample * (float) LOVE_INT16_MAX);
}
else
{
data[i] = (int8) (sample * (float) LOVE_INT8_MAX);
// 8-bit sample values are unsigned internally.
data[i] = (uint8) ((sample * 127.0f) + 128.0f);
}
}
float SoundData::getSample(int i) const
{
// Check range.
if (i < 0 || i >= size/(bitDepth/8))
if (i < 0 || (size_t) i >= size/(bitDepth/8))
throw love::Exception("Attempt to get out-of-range sample!");
if (bitDepth == 16)
{
// 16-bit sample values are signed.
int16 *s = (int16 *) data;
return (float) s[i] / (float) LOVE_INT16_MAX;
}
else
{
return (float) data[i] / (float) LOVE_INT8_MAX;
// 8-bit sample values are unsigned internally.
return ((float) data[i] - 128.0f) / 127.0f;
}
}
+3 -3
View File
@@ -43,7 +43,7 @@ public:
// Implements Data.
void *getData() const;
int getSize() const;
size_t getSize() const;
virtual int getChannels() const;
virtual int getBitDepth() const;
@@ -59,8 +59,8 @@ private:
void load(int samples, int sampleRate, int bitDepth, int channels, void *newData = 0);
int8 *data;
int size;
uint8 *data;
size_t size;
int sampleRate;
int bitDepth;
Regular → Executable
+81 -3
View File
@@ -18,8 +18,23 @@
* 3. This notice may not be removed or altered from any source distribution.
**/
// LOVE
#include "common/config.h"
#include "System.h"
#if defined(LOVE_MACOSX)
#include <CoreServices/CoreServices.h>
#elif defined(LOVE_LINUX)
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
#elif defined(LOVE_WINDOWS)
#include "common/utf8.h"
#include <shlobj.h>
#include <shellapi.h>
#pragma comment(lib, "shell32.lib")
#endif
namespace love
{
namespace system
@@ -27,17 +42,80 @@ namespace system
std::string System::getOS() const
{
#ifdef LOVE_MACOSX
#if defined(LOVE_MACOSX)
return "OS X";
#elif LOVE_WINDOWS
#elif defined(LOVE_WINDOWS)
return "Windows";
#elif LOVE_LINUX
#elif defined(LOVE_LINUX)
return "Linux";
#else
return "Unknown";
#endif
}
bool System::openURL(const std::string &url) const
{
bool success = false;
#if defined(LOVE_MACOSX)
// We could be lazy and use system("open " + url), but this is safer.
CFURLRef cfurl = CFURLCreateWithBytes(nullptr,
(const UInt8 *) url.c_str(),
url.length(),
kCFStringEncodingUTF8,
nullptr);
success = LSOpenCFURLRef(cfurl, nullptr) == noErr;
CFRelease(cfurl);
#elif defined(LOVE_LINUX)
// Spawn a child process, which we'll replace with xdg-open.
pid_t pid = vfork();
if (pid == 0) // Child process.
{
// Replace the child process with xdg-open and pass in the URL.
execlp("xdg-open", "xdg-open", url.c_str(), nullptr);
// exec will only return if it errored, so we should exit with non-zero.
_exit(1);
}
else if (pid > 0) // Parent process.
{
// Wait for xdg-open to complete (or fail.)
int status = 0;
if (waitpid(pid, &status, 0) == pid)
success = (status == 0);
else
success = false;
}
else
{
// vfork() failed.
success = false;
}
#elif defined(LOVE_WINDOWS)
// Unicode-aware WinAPI functions don't accept UTF-8, so we need to convert.
std::wstring wurl = to_widestr(url);
HINSTANCE result = ShellExecuteW(nullptr,
L"open",
wurl.c_str(),
nullptr,
nullptr,
SW_SHOW);
success = (int) result > 32;
#endif
return success;
}
bool System::getConstant(const char *in, System::PowerState &out)
{
return powerStates.find(in, out);
+10
View File
@@ -85,6 +85,16 @@ public:
**/
virtual PowerState getPowerInfo(int &seconds, int &percent) const = 0;
/**
* Opens the specified URL with the user's default program to handle that
* particular URL type.
*
* @param url The URL to open.
*
* @return Whether the URL was opened successfully.
**/
virtual bool openURL(const std::string &url) const;
static bool getConstant(const char *in, PowerState &out);
static bool getConstant(PowerState in, const char *&out);
+8
View File
@@ -79,6 +79,13 @@ int w_getPowerInfo(lua_State *L)
return 3;
}
int w_openURL(lua_State *L)
{
std::string url = luax_checkstring(L, 1);
luax_pushboolean(L, instance->openURL(url));
return 1;
}
static const luaL_Reg functions[] =
{
{ "getOS", w_getOS },
@@ -86,6 +93,7 @@ static const luaL_Reg functions[] =
{ "setClipboardText", w_setClipboardText },
{ "getClipboardText", w_getClipboardText },
{ "getPowerInfo", w_getPowerInfo },
{ "openURL", w_openURL },
{ 0, 0 }
};
+1
View File
@@ -35,6 +35,7 @@ int w_getProcessorCount(lua_State *L);
int w_setClipboardText(lua_State *L);
int w_getClipboardText(lua_State *L);
int w_getPowerInfo(lua_State *L);
int w_openURL(lua_State *L);
extern "C" LOVE_EXPORT int luaopen_love_system(lua_State *L);
} // system
+16 -9
View File
@@ -70,10 +70,6 @@ Window::_currentMode::_currentMode()
bool Window::setWindow(int width, int height, WindowSettings *settings)
{
graphics::Graphics *gfx = (graphics::Graphics *) Module::findInstance("love.graphics.");
if (gfx != nullptr)
gfx->unSetMode();
WindowSettings f;
if (settings)
@@ -116,11 +112,16 @@ bool Window::setWindow(int width, int height, WindowSettings *settings)
if (f.borderless)
sdlflags |= SDL_WINDOW_BORDERLESS;
#if SDL_VERSION_ATLEAST(2,0,1)
// FIXME: disabled in Linux for runtime SDL 2.0.0 compatibility.
#if SDL_VERSION_ATLEAST(2,0,1) && !defined(LOVE_LINUX)
if (f.highdpi)
sdlflags |= SDL_WINDOW_ALLOW_HIGHDPI;
#endif
graphics::Graphics *gfx = (graphics::Graphics *) Module::findInstance("love.graphics.");
if (gfx != nullptr)
gfx->unSetMode();
// Destroy and recreate the window if the dimensions or flags have changed.
if (window)
{
@@ -130,7 +131,8 @@ bool Window::setWindow(int width, int height, WindowSettings *settings)
Uint32 testflags = SDL_WINDOW_OPENGL | SDL_WINDOW_FULLSCREEN_DESKTOP
| SDL_WINDOW_RESIZABLE | SDL_WINDOW_BORDERLESS;
#if SDL_VERSION_ATLEAST(2,0,1)
// FIXME: disabled in Linux for runtime SDL 2.0.0 compatibility.
#if SDL_VERSION_ATLEAST(2,0,1) && !defined(LOVE_LINUX)
testflags |= SDL_WINDOW_ALLOW_HIGHDPI;
#endif
@@ -153,6 +155,8 @@ bool Window::setWindow(int width, int height, WindowSettings *settings)
if (!window)
{
created = false;
// In Windows and Linux, some GL attributes are set on window creation.
setWindowGLAttributes(f.fsaa, f.sRGB);
@@ -202,7 +206,8 @@ bool Window::setWindow(int width, int height, WindowSettings *settings)
int width = curMode.width;
int height = curMode.height;
#if SDL_VERSION_ATLEAST(2,0,1)
// FIXME: disabled in Linux for runtime SDL 2.0.0 compatibility.
#if SDL_VERSION_ATLEAST(2,0,1) && !defined(LOVE_LINUX)
SDL_GL_GetDrawableSize(window, &width, &height);
#endif
@@ -431,7 +436,8 @@ bool Window::setFullscreen(bool fullscreen, Window::FullscreenType fstype)
int width = curMode.width;
int height = curMode.height;
#if SDL_VERSION_ATLEAST(2,0,1)
// FIXME: disabled in Linux for runtime SDL 2.0.0 compatibility.
#if SDL_VERSION_ATLEAST(2,0,1) && !defined(LOVE_LINUX)
SDL_GL_GetDrawableSize(window, &width, &height);
#endif
@@ -633,7 +639,8 @@ double Window::getPixelScale() const
{
double scale = 1.0;
#if SDL_VERSION_ATLEAST(2,0,1)
// FIXME: disabled in Linux for runtime SDL 2.0.0 compatibility.
#if SDL_VERSION_ATLEAST(2,0,1) && !defined(LOVE_LINUX)
if (window)
{
int wheight;
+2 -1
View File
@@ -34,7 +34,8 @@ const unsigned char %s[] =
{
%s
}; // [%s]
} // love]]
} // love
]]
--formatting parameters:
-- - input file name
-- - c variable name
+1
View File
@@ -468,6 +468,7 @@ function love.run()
if love.math then
love.math.setRandomSeed(os.time())
for i=1,3 do love.math.random() end
end
if love.event then
+4 -1
View File
@@ -836,6 +836,9 @@ const unsigned char boot_lua[] =
0x09, 0x69, 0x66, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x6d, 0x61, 0x74, 0x68, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a,
0x09, 0x09, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x6d, 0x61, 0x74, 0x68, 0x2e, 0x73, 0x65, 0x74, 0x52, 0x61, 0x6e,
0x64, 0x6f, 0x6d, 0x53, 0x65, 0x65, 0x64, 0x28, 0x6f, 0x73, 0x2e, 0x74, 0x69, 0x6d, 0x65, 0x28, 0x29, 0x29, 0x0a,
0x09, 0x09, 0x66, 0x6f, 0x72, 0x20, 0x69, 0x3d, 0x31, 0x2c, 0x33, 0x20, 0x64, 0x6f, 0x20, 0x6c, 0x6f, 0x76,
0x65, 0x2e, 0x6d, 0x61, 0x74, 0x68, 0x2e, 0x72, 0x61, 0x6e, 0x64, 0x6f, 0x6d, 0x28, 0x29, 0x20, 0x65, 0x6e,
0x64, 0x0a,
0x09, 0x65, 0x6e, 0x64, 0x0a,
0x09, 0x69, 0x66, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x20, 0x74, 0x68, 0x65,
0x6e, 0x0a,
@@ -5360,4 +5363,4 @@ const unsigned char boot_lua[] =
0x65, 0x74, 0x76, 0x61, 0x6c, 0x29, 0x20, 0x6f, 0x72, 0x20, 0x30, 0x0a,
0x65, 0x6e, 0x64, 0x0a,
}; // [boot.lua]
} // love
} // love
+8 -7
View File
@@ -1317,13 +1317,14 @@ uniform vec4 love_ScreenSize;]]
#define VaryingTexCoord gl_TexCoord[0]
#define VaryingColor gl_FrontColor
#if defined(GL_ARB_draw_instanced)
#extension GL_ARB_draw_instanced : enable
#define love_InstanceID gl_InstanceIDARB
#else
attribute float love_PseudoInstanceID;
int love_InstanceID = int(love_PseudoInstanceID);
#endif]],
// #if defined(GL_ARB_draw_instanced)
// #extension GL_ARB_draw_instanced : enable
// #define love_InstanceID gl_InstanceIDARB
// #else
// attribute float love_PseudoInstanceID;
// int love_InstanceID = int(love_PseudoInstanceID);
// #endif
]],
FOOTER = [[
void main() {
+19 -17
View File
@@ -6313,22 +6313,24 @@ const unsigned char graphics_lua[] =
0x30, 0x5d, 0x0a,
0x23, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x65, 0x20, 0x56, 0x61, 0x72, 0x79, 0x69, 0x6e, 0x67, 0x43, 0x6f, 0x6c,
0x6f, 0x72, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x6f, 0x6e, 0x74, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x0a,
0x23, 0x69, 0x66, 0x20, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x65, 0x64, 0x28, 0x47, 0x4c, 0x5f, 0x41, 0x52, 0x42,
0x5f, 0x64, 0x72, 0x61, 0x77, 0x5f, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x64, 0x29, 0x0a,
0x09, 0x23, 0x65, 0x78, 0x74, 0x65, 0x6e, 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x47, 0x4c, 0x5f, 0x41, 0x52, 0x42,
0x5f, 0x64, 0x72, 0x61, 0x77, 0x5f, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x64, 0x20, 0x3a, 0x20,
0x65, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x0a,
0x09, 0x23, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x65, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x5f, 0x49, 0x6e, 0x73, 0x74,
0x61, 0x6e, 0x63, 0x65, 0x49, 0x44, 0x20, 0x67, 0x6c, 0x5f, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65,
0x49, 0x44, 0x41, 0x52, 0x42, 0x0a,
0x23, 0x65, 0x6c, 0x73, 0x65, 0x0a,
0x09, 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x20, 0x6c,
0x6f, 0x76, 0x65, 0x5f, 0x50, 0x73, 0x65, 0x75, 0x64, 0x6f, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65,
0x49, 0x44, 0x3b, 0x0a,
0x09, 0x69, 0x6e, 0x74, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x5f, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65,
0x49, 0x44, 0x20, 0x3d, 0x20, 0x69, 0x6e, 0x74, 0x28, 0x6c, 0x6f, 0x76, 0x65, 0x5f, 0x50, 0x73, 0x65, 0x75,
0x64, 0x6f, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x49, 0x44, 0x29, 0x3b, 0x0a,
0x23, 0x65, 0x6e, 0x64, 0x69, 0x66, 0x5d, 0x5d, 0x2c, 0x0a,
0x2f, 0x2f, 0x20, 0x23, 0x69, 0x66, 0x20, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x65, 0x64, 0x28, 0x47, 0x4c, 0x5f,
0x41, 0x52, 0x42, 0x5f, 0x64, 0x72, 0x61, 0x77, 0x5f, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x64,
0x29, 0x0a,
0x2f, 0x2f, 0x09, 0x23, 0x65, 0x78, 0x74, 0x65, 0x6e, 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x47, 0x4c, 0x5f, 0x41,
0x52, 0x42, 0x5f, 0x64, 0x72, 0x61, 0x77, 0x5f, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x64, 0x20,
0x3a, 0x20, 0x65, 0x6e, 0x61, 0x62, 0x6c, 0x65, 0x0a,
0x2f, 0x2f, 0x09, 0x23, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x65, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x5f, 0x49, 0x6e,
0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x49, 0x44, 0x20, 0x67, 0x6c, 0x5f, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6e,
0x63, 0x65, 0x49, 0x44, 0x41, 0x52, 0x42, 0x0a,
0x2f, 0x2f, 0x20, 0x23, 0x65, 0x6c, 0x73, 0x65, 0x0a,
0x2f, 0x2f, 0x09, 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74,
0x20, 0x6c, 0x6f, 0x76, 0x65, 0x5f, 0x50, 0x73, 0x65, 0x75, 0x64, 0x6f, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6e,
0x63, 0x65, 0x49, 0x44, 0x3b, 0x0a,
0x2f, 0x2f, 0x09, 0x69, 0x6e, 0x74, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x5f, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6e,
0x63, 0x65, 0x49, 0x44, 0x20, 0x3d, 0x20, 0x69, 0x6e, 0x74, 0x28, 0x6c, 0x6f, 0x76, 0x65, 0x5f, 0x50, 0x73,
0x65, 0x75, 0x64, 0x6f, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x49, 0x44, 0x29, 0x3b, 0x0a,
0x2f, 0x2f, 0x20, 0x23, 0x65, 0x6e, 0x64, 0x69, 0x66, 0x0a,
0x5d, 0x5d, 0x2c, 0x0a,
0x09, 0x09, 0x46, 0x4f, 0x4f, 0x54, 0x45, 0x52, 0x20, 0x3d, 0x20, 0x5b, 0x5b, 0x0a,
0x76, 0x6f, 0x69, 0x64, 0x20, 0x6d, 0x61, 0x69, 0x6e, 0x28, 0x29, 0x20, 0x7b, 0x0a,
0x09, 0x56, 0x61, 0x72, 0x79, 0x69, 0x6e, 0x67, 0x54, 0x65, 0x78, 0x43, 0x6f, 0x6f, 0x72, 0x64, 0x20, 0x3d,
@@ -6626,4 +6628,4 @@ const unsigned char graphics_lua[] =
0x09, 0x65, 0x6e, 0x64, 0x0a,
0x65, 0x6e, 0x64, 0x0a,
}; // [graphics.lua]
} // love
} // love