imported Löve GLES branch (changeset 1ba9037e558b)

This commit is contained in:
Martin Felis
2013-12-05 18:05:13 +01:00
parent 41b2db04a7
commit 2644d1ee18
615 changed files with 150300 additions and 0 deletions
+63
View File
@@ -0,0 +1,63 @@
/**
* Copyright (c) 2006-2013 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
**/
#include "System.h"
namespace love
{
namespace system
{
std::string System::getOS() const
{
#ifdef LOVE_MACOSX
return "OS X";
#elif LOVE_WINDOWS
return "Windows";
#elif LOVE_LINUX
return "Linux";
#else
return "Unknown";
#endif
}
bool System::getConstant(const char *in, System::PowerState &out)
{
return powerStates.find(in, out);
}
bool System::getConstant(System::PowerState in, const char *&out)
{
return powerStates.find(in, out);
}
StringMap<System::PowerState, System::POWER_MAX_ENUM>::Entry System::powerEntries[] =
{
{"unknown", System::POWER_UNKNOWN},
{"battery", System::POWER_BATTERY},
{"nobattery", System::POWER_NO_BATTERY},
{"charging", System::POWER_CHARGING},
{"charged", System::POWER_CHARGED},
};
StringMap<System::PowerState, System::POWER_MAX_ENUM> System::powerStates(System::powerEntries, sizeof(System::powerEntries));
} // system
} // love
+101
View File
@@ -0,0 +1,101 @@
/**
* Copyright (c) 2006-2013 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
**/
#ifndef LOVE_SYSTEM_H
#define LOVE_SYSTEM_H
// LOVE
#include "common/config.h"
#include "common/Module.h"
#include "common/StringMap.h"
// stdlib
#include <string>
namespace love
{
namespace system
{
class System : public Module
{
public:
enum PowerState
{
POWER_UNKNOWN,
POWER_BATTERY,
POWER_NO_BATTERY,
POWER_CHARGING,
POWER_CHARGED,
POWER_MAX_ENUM
};
virtual ~System() {}
/**
* Gets the current operating system.
**/
std::string getOS() const;
/**
* Gets the number of reported CPU cores on the current system.
* Does not account for technologies such as Hyperthreading: a 4-core
* Hyperthreading-enabled Intel CPU will report 8, instead of 4.
**/
virtual int getProcessorCount() const = 0;
/**
* Replaces the contents of the system's text clipboard with a string.
* @param text The clipboard text to set.
**/
virtual void setClipboardText(const std::string &text) const = 0;
/**
* Gets the contents of the system's text clipboard.
**/
virtual std::string getClipboardText() const = 0;
/**
* Gets information about the system's power supply.
*
* @param[out] seconds Time in seconds of battery life left.
* -1 if a value can't be determined.
* @param[out] percent The percentage of battery life left (0-100.)
* -1 if a value can't be determined.
*
* @return The current state of the battery.
**/
virtual PowerState getPowerInfo(int &seconds, int &percent) const = 0;
static bool getConstant(const char *in, PowerState &out);
static bool getConstant(PowerState in, const char *&out);
private:
static StringMap<PowerState, POWER_MAX_ENUM>::Entry powerEntries[];
static StringMap<PowerState, POWER_MAX_ENUM> powerStates;
}; // System
} // system
} // love
#endif // LOVE_SYSTEM_H
@@ -0,0 +1,91 @@
/**
* Copyright (c) 2006-2013 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
**/
// LOVE
#include "System.h"
// SDL
#include <SDL_clipboard.h>
#include <SDL_cpuinfo.h>
namespace love
{
namespace system
{
namespace sdl
{
System::System()
{
}
const char *System::getName() const
{
return "love.system.sdl";
}
int System::getProcessorCount() const
{
return SDL_GetCPUCount();
}
void System::setClipboardText(const std::string &text) const
{
SDL_SetClipboardText(text.c_str());
}
std::string System::getClipboardText() const
{
std::string text("");
char *ctext = SDL_GetClipboardText();
if (ctext)
{
text = std::string(ctext);
SDL_free(ctext);
}
return text;
}
love::system::System::PowerState System::getPowerInfo(int &seconds, int &percent) const
{
SDL_PowerState sdlstate = SDL_GetPowerInfo(&seconds, &percent);
PowerState state = POWER_UNKNOWN;
powerStates.find(sdlstate, state);
return state;
}
EnumMap<System::PowerState, SDL_PowerState, System::POWER_MAX_ENUM>::Entry System::powerEntries[] =
{
{System::POWER_UNKNOWN, SDL_POWERSTATE_UNKNOWN},
{System::POWER_BATTERY, SDL_POWERSTATE_ON_BATTERY},
{System::POWER_NO_BATTERY, SDL_POWERSTATE_NO_BATTERY},
{System::POWER_CHARGING, SDL_POWERSTATE_CHARGING},
{System::POWER_CHARGED, SDL_POWERSTATE_CHARGED},
};
EnumMap<System::PowerState, SDL_PowerState, System::POWER_MAX_ENUM> System::powerStates(System::powerEntries, sizeof(System::powerEntries));
} // sdl
} // system
} // love
+66
View File
@@ -0,0 +1,66 @@
/**
* Copyright (c) 2006-2013 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
**/
#ifndef LOVE_SYSTEM_SDL_SYSTEM_H
#define LOVE_SYSTEM_SDL_SYSTEM_H
// LOVE
#include "system/System.h"
#include "common/EnumMap.h"
// SDL
#include <SDL_power.h>
namespace love
{
namespace system
{
namespace sdl
{
class System : public love::system::System
{
public:
System();
virtual ~System() {}
// Implements Module.
const char *getName() const;
int getProcessorCount() const;
void setClipboardText(const std::string &text) const;
std::string getClipboardText() const;
PowerState getPowerInfo(int &seconds, int &percent) const;
private:
static EnumMap<PowerState, SDL_PowerState, POWER_MAX_ENUM>::Entry powerEntries[];
static EnumMap<PowerState, SDL_PowerState, POWER_MAX_ENUM> powerStates;
}; // System
} // sdl
} // system
} // love
#endif // LOVE_SYSTEM_SDL_SYSTEM_H
+112
View File
@@ -0,0 +1,112 @@
/**
* Copyright (c) 2006-2013 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
**/
// LOVE
#include "wrap_System.h"
#include "sdl/System.h"
namespace love
{
namespace system
{
static System *instance = 0;
int w_getOS(lua_State *L)
{
luax_pushstring(L, instance->getOS());
return 1;
}
int w_getProcessorCount(lua_State *L)
{
lua_pushinteger(L, instance->getProcessorCount());
return 1;
}
int w_setClipboardText(lua_State *L)
{
const char *text = luaL_checkstring(L, 1);
instance->setClipboardText(text);
return 0;
}
int w_getClipboardText(lua_State *L)
{
luax_pushstring(L, instance->getClipboardText());
return 1;
}
int w_getPowerInfo(lua_State *L)
{
int seconds = -1, percent = -1;
const char *str;
System::PowerState state = instance->getPowerInfo(seconds, percent);
if (!System::getConstant(state, str))
str = "unknown";
lua_pushstring(L, str);
if (percent >= 0)
lua_pushinteger(L, percent);
else
lua_pushnil(L);
if (seconds >= 0)
lua_pushinteger(L, seconds);
else
lua_pushnil(L);
return 3;
}
static const luaL_Reg functions[] =
{
{ "getOS", w_getOS },
{ "getProcessorCount", w_getProcessorCount },
{ "setClipboardText", w_setClipboardText },
{ "getClipboardText", w_getClipboardText },
{ "getPowerInfo", w_getPowerInfo },
{ 0, 0 }
};
extern "C" int luaopen_love_system(lua_State *L)
{
if (instance == 0)
{
instance = new love::system::sdl::System();
}
else
instance->retain();
WrappedModule w;
w.module = instance;
w.name = "system";
w.flags = MODULE_T;
w.functions = functions;
w.types = 0;
return luax_register_module(L, w);
}
} // system
} // love
+43
View File
@@ -0,0 +1,43 @@
/**
* Copyright (c) 2006-2013 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
**/
#ifndef LOVE_WRAP_SYSTEM_H
#define LOVE_WRAP_SYSTEM_H
// LOVE
#include "System.h"
#include "common/runtime.h"
namespace love
{
namespace system
{
int w_getOS(lua_State *L);
int w_getProcessorCount(lua_State *L);
int w_setClipboardText(lua_State *L);
int w_getClipboardText(lua_State *L);
int w_getPowerInfo(lua_State *L);
extern "C" LOVE_EXPORT int luaopen_love_system(lua_State *L);
} // system
} // love
#endif // LOVE_WRAP_SYSTEM_H