Initial Mercurial commit.

This commit is contained in:
rude
2009-07-26 15:46:49 +02:00
commit dcb3dfd83d
417 changed files with 124060 additions and 0 deletions
+72
View File
@@ -0,0 +1,72 @@
/**
* Copyright (c) 2006-2009 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_EVENT_EVENT_H
#define LOVE_EVENT_EVENT_H
// LOVE
#include <common/Module.h>
namespace love
{
namespace event
{
class Event : public Module
{
protected:
virtual ~Event(){};
public:
enum
{
EVENT_NOEVENT = 0,
EVENT_ACTIVEEVENT,
EVENT_KEYDOWN,
EVENT_KEYUP,
EVENT_MOUSEMOTION,
EVENT_MOUSEBUTTONDOWN,
EVENT_MOUSEBUTTONUP,
EVENT_JOYAXISMOTION,
EVENT_JOYBALLMOTION,
EVENT_JOYHATMOTION,
EVENT_JOYBUTTONDOWN,
EVENT_JOYBUTTONUP,
EVENT_QUIT,
EVENT_SYSWMEVENT,
EVENT_RESERVEDA,
EVENT_RESERVEDB,
EVENT_VIDEORESIZE,
EVENT_VIDEOEXPOSE,
EVENT_RESERVED2,
EVENT_RESERVED3,
EVENT_RESERVED4,
EVENT_RESERVED5,
EVENT_RESERVED6,
EVENT_RESERVED7,
EVENT_USEREVENT = 24,
EVENT_NUMEVENTS = 32
};
}; // Event
} // event
} // love
#endif // LOVE_EVENT_EVENT_H
+163
View File
@@ -0,0 +1,163 @@
/**
* Copyright (c) 2006-2009 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 "Event.h"
namespace love
{
namespace event
{
namespace sdl
{
const char * Event::getName() const
{
return "love.event.sdl";
}
void Event::pump()
{
SDL_PumpEvents();
}
int Event::poll(lua_State * L)
{
lua_pushcclosure(L, &poll_i, 0);
return 1;
}
int Event::wait(lua_State * L)
{
static SDL_Event e;
SDL_WaitEvent(&e);
return pushEvent(L, e);
}
void Event::quit()
{
SDL_Event e;
e.type = Event::EVENT_QUIT;
SDL_PushEvent(&e);
}
int Event::push(lua_State * L)
{
SDL_Event e;
getEvent(L, e);
SDL_PushEvent(&e);
return 0;
}
int Event::poll_i(lua_State * L)
{
SDL_EnableUNICODE(1);
// The union used to get SDL events.
static SDL_Event e;
// Get ONE event.
while(SDL_PollEvent(&e))
{
int args = Event::pushEvent(L, e);
if(args > 0)
return args;
}
// No pending events.
return 0;
}
int Event::pushEvent(lua_State * L, SDL_Event & e)
{
switch(e.type)
{
case SDL_KEYDOWN:
lua_pushinteger(L, e.type);
lua_pushinteger(L, e.key.keysym.sym);
lua_pushinteger(L, e.key.keysym.unicode);
return 3;
case SDL_KEYUP:
lua_pushinteger(L, e.type);
lua_pushinteger(L, e.key.keysym.sym);
return 2;
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP:
lua_pushinteger(L, e.type);
lua_pushinteger(L, e.button.x);
lua_pushinteger(L, e.button.y);
lua_pushinteger(L, e.button.button);
return 4;
case SDL_JOYBUTTONDOWN:
case SDL_JOYBUTTONUP:
lua_pushinteger(L, e.type);
lua_pushinteger(L, e.jbutton.which);
lua_pushinteger(L, e.jbutton.button);
return 3;
case SDL_QUIT:
lua_pushinteger(L, e.type);
return 1;
default:
break;
}
return 0;
}
int Event::getEvent(lua_State * L, SDL_Event & e)
{
int type = luaL_checkint(L, 1);
switch(type)
{
case EVENT_KEYDOWN:
e.type = type;
e.key.keysym.sym = (SDLKey)luaL_checkint(L, 2);
e.key.keysym.unicode = luaL_checkint(L, 3);
return 3;
case EVENT_KEYUP:
e.type = type;
e.key.keysym.sym = (SDLKey)luaL_checkint(L, 2);
return 2;
case EVENT_MOUSEBUTTONDOWN:
case EVENT_MOUSEBUTTONUP:
e.type = type;
e.button.x = luaL_checkint(L, 2);
e.button.y = luaL_checkint(L, 3);
e.button.button = luaL_checkint(L, 4);
return 4;
case EVENT_JOYBUTTONDOWN:
case EVENT_JOYBUTTONUP:
e.type = type;
e.jbutton.which = luaL_checkint(L, 2);
e.jbutton.button = luaL_checkint(L, 3);
return 3;
case EVENT_QUIT:
e.type = type;
return 1;
default:
e.type = EVENT_NOEVENT;
break;
}
return 0;
}
} // sdl
} // event
} // love
+91
View File
@@ -0,0 +1,91 @@
/**
* Copyright (c) 2006-2009 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_EVENT_SDL_EVENT_H
#define LOVE_EVENT_SDL_EVENT_H
// LOVE
#include <event/Event.h>
#include <common/runtime.h>
// SDL
#include <SDL.h>
namespace love
{
namespace event
{
namespace sdl
{
class Event : public event::Event
{
public:
// Implements Module.
const char * getName() const;
/**
* Pumps the event queue. This function gathers all the pending input information
* from devices and places it on the event queue. Normally not needed if you poll
* for events.
**/
void pump();
/**
* Returns an iterator function for iterating over pending events.
**/
int poll(lua_State * L);
/**
* Waits for the next event (indefinitely). Useful for creating games where
* the screen and game state only needs updating when the user interacts with
* the window.
**/
int wait(lua_State * L);
/**
* Push a quit event. Calling this does not mean the application
* will exit immediately, it just means an quit event will be issued.
* How to respond to the quit event is up the application.
**/
void quit();
/**
* Pushes an event into the queue.
**/
int push(lua_State * L);
/**
* The iterator function.
**/
static int poll_i(lua_State * L);
private:
static int pushEvent(lua_State * L, SDL_Event & e);
static int getEvent(lua_State * L, SDL_Event & e);
}; // System
} // sdl
} // event
} // love
#endif // LOVE_EVENT_SDL_EVENT_H
+95
View File
@@ -0,0 +1,95 @@
/**
* Copyright (c) 2006-2009 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 "wrap_Event.h"
// LOVE
#include <common/runtime.h>
// sdlevent
#include "Event.h"
namespace love
{
namespace event
{
namespace sdl
{
static Event * instance = 0;
int _wrap_pump(lua_State * L)
{
instance->pump();
return 0;
}
int _wrap_poll(lua_State * L)
{
return instance->poll(L);
}
int _wrap_wait(lua_State * L)
{
return instance->wait(L);
}
int _wrap_quit(lua_State * L)
{
instance->quit();
return 0;
}
int _wrap_push(lua_State * L)
{
return instance->push(L);
}
// List of functions to wrap.
static const luaL_Reg wrap_Event_functions[] = {
{ "pump", _wrap_pump },
{ "poll", _wrap_poll },
{ "wait", _wrap_wait },
{ "quit", _wrap_quit },
{ "push", _wrap_push },
{ 0, 0 }
};
int wrap_Event_open(lua_State * L)
{
if(instance == 0)
{
try
{
instance = new Event();
}
catch(Exception & e)
{
return luaL_error(L, e.what());
}
}
luax_register_gc(L, "love.event", instance);
return luax_register_module(L, wrap_Event_functions, 0);
}
} // sdl
} // event
} // love
+45
View File
@@ -0,0 +1,45 @@
/**
* Copyright (c) 2006-2009 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_EVENT_SDL_WRAP_EVENT_H
#define LOVE_EVENT_SDL_WRAP_EVENT_H
// LOVE
#include "Event.h"
namespace love
{
namespace event
{
namespace sdl
{
int _wrap_pump(lua_State * L);
int _wrap_poll(lua_State * L);
int _wrap_wait(lua_State * L);
int _wrap_quit(lua_State * L);
int _wrap_push(lua_State * L);
int wrap_Event_open(lua_State * L);
} // sdl
} // event
} // love
#endif // LOVE_EVENT_SDL_WRAP_EVENT_H
+78
View File
@@ -0,0 +1,78 @@
/**
* Copyright (c) 2006-2009 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 "Event.h"
namespace love
{
namespace event
{
namespace signal
{
Event::Event()
: signals(0)
{
cb = 0;
}
Event::~Event()
{
::signal(signals, SIG_DFL);
}
bool Event::registerSignal(int sgn)
{
signals |= sgn;
return ::signal(sgn, (void (*)(int)) &handler) != SIG_ERR;
}
void Event::setCallback(lua_State *L)
{
luax_assert_argc(L, 1, 1);
luax_assert_function(L, -1);
if(cb != 0)
{
delete cb;
cb = 0;
}
cb = new Reference(L);
}
void handler(int signal)
{
if (cb == 0)
return;
lua_State *L = cb->getL();
cb->push();
lua_pushnumber(L, signal);
lua_call(L, 1, 0);
}
const char * Event::getName() const
{
return "love.event.signal";
}
} // signal
} // event
} // love
+57
View File
@@ -0,0 +1,57 @@
/**
* Copyright (c) 2006-2009 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_EVENT_SIGNAL_EVENT_H
#define LOVE_EVENT_SIGNAL_EVENT_H
// LOVE
#include <event/Event.h>
#include <common/runtime.h>
#include <common/Reference.h>
#include <signal.h>
namespace love
{
namespace event
{
namespace signal
{
class Event : public event::Event
{
private:
int signals;
public:
Event();
~Event();
bool registerSignal(int sgn);
void setCallback(lua_State *L);
const char * getName() const;
};
void handler(int signal);
static Reference *cb;
} // signal
} // event
} // love
#endif // LOVE_EVENT_SIGNAL_EVENT_H
+78
View File
@@ -0,0 +1,78 @@
/**
* Copyright (c) 2006-2009 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 "wrap_Event.h"
// LOVE
#include <common/runtime.h>
#include "Event.h"
namespace love
{
namespace event
{
namespace signal
{
static Event * instance = 0;
int _wrap_registerSignal(lua_State *L)
{
luaL_argcheck(L, lua_isnumber(L, 1), 1, "Expected number");
lua_pushboolean(L, instance->registerSignal(lua_tonumber(L, 1)));
return 1;
}
int _wrap_setCallback(lua_State *L)
{
luaL_argcheck(L, lua_isfunction(L, 1), 1, "Expected function");
instance->setCallback(L);
return 0;
}
// List of functions to wrap.
static const luaL_Reg wrap_Event_signal_functions[] = {
{ "registerSignal", _wrap_registerSignal },
{ "setCallback", _wrap_setCallback },
{ 0, 0 }
};
int wrap_Event_signal_open(lua_State * L)
{
if(instance == 0)
{
try
{
instance = new Event();
}
catch(Exception & e)
{
return luaL_error(L, e.what());
}
}
luax_register_gc(L, "love.event.signal", instance);
return luax_register_module(L, wrap_Event_signal_functions, 0);
}
} // signal
} // event
} // love
+42
View File
@@ -0,0 +1,42 @@
/**
* Copyright (c) 2006-2009 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_EVENT_SIGNAL_WRAP_EVENT_H
#define LOVE_EVENT_SIGNAL_WRAP_EVENT_H
// LOVE
#include "Event.h"
namespace love
{
namespace event
{
namespace signal
{
int _wrap_registerSignal(lua_State *L);
int _wrap_setCallback(lua_State *L);
int wrap_Event_signal_open(lua_State * L);
} // sdl
} // event
} // love
#endif // LOVE_EVENT_SIGNAL_WRAP_EVENT_H