mirror of
https://github.com/love2d/love.git
synced 2026-08-15 15:51:12 +02:00
Added first version of thread and enabled newFileData
This commit is contained in:
+1
-1
@@ -1,4 +1,4 @@
|
||||
AC_INIT([love], [20091206-d0384a4c71f6])
|
||||
AC_INIT([love], [HEAD])
|
||||
AC_CONFIG_HEADERS([config.h])
|
||||
AC_CONFIG_AUX_DIR([platform/unix])
|
||||
AC_CONFIG_MACRO_DIR([platform/unix/m4])
|
||||
|
||||
@@ -13,10 +13,11 @@
|
||||
./modules/native/tcc/libtcc/tcctok.h
|
||||
./modules/native/tcc/libtcc/arm-gen.c
|
||||
./modules/native/tcc/libtcc/i386-asm.c
|
||||
./modules/native/tcc/libtcc/i386-gen.c
|
||||
./modules/native/tcc/libtcc/i386-gen.c
|
||||
./modules/native/tcc/libtcc/tccgen.c
|
||||
./modules/native/tcc/libtcc/tcc.h
|
||||
./modules/native/tcc/libtcc/il-opcodes.h
|
||||
./modules/native/tcc/libtcc/coff.h
|
||||
./modules/native/tcc/libtcc/stab.h
|
||||
./libraries/luasocket/libluasocket/wsocket.*
|
||||
|
||||
|
||||
+13
-7
@@ -1,14 +1,14 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2010 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
|
||||
@@ -76,8 +76,11 @@ namespace love
|
||||
PHYSICS_REVOLUTE_JOINT_ID,
|
||||
PHYSICS_PULLEY_JOINT_ID,
|
||||
PHYSICS_GEAR_JOINT_ID,
|
||||
|
||||
// The modules themselves. Only add abstracted modules here.
|
||||
|
||||
// Thread
|
||||
THREAD_THREAD_ID,
|
||||
|
||||
// The modules themselves. Only add abstracted modules here.
|
||||
MODULE_FILESYSTEM_ID,
|
||||
MODULE_IMAGE_ID,
|
||||
MODULE_SOUND_ID,
|
||||
@@ -94,7 +97,7 @@ namespace love
|
||||
const bits DATA_T = (bits(1) << DATA_ID) | OBJECT_T;
|
||||
const bits MODULE_T = (bits(1) << MODULE_ID) | OBJECT_T;
|
||||
|
||||
// Filesystem.
|
||||
// Filesystem.
|
||||
const bits FILESYSTEM_FILE_T = (bits(1) << FILESYSTEM_FILE_ID) | OBJECT_T;
|
||||
const bits FILESYSTEM_FILE_DATA_T = (bits(1) << FILESYSTEM_FILE_DATA_ID) | DATA_T;
|
||||
|
||||
@@ -113,7 +116,7 @@ namespace love
|
||||
|
||||
// Image.
|
||||
const bits IMAGE_IMAGE_DATA_T = (bits(1) << IMAGE_IMAGE_DATA_ID) | DATA_T;
|
||||
|
||||
|
||||
// Audio.
|
||||
const bits AUDIO_SOURCE_T = (bits(1) << AUDIO_SOURCE_ID) | OBJECT_T;
|
||||
|
||||
@@ -136,6 +139,9 @@ namespace love
|
||||
const bits PHYSICS_PULLEY_JOINT_T = (bits(1) << PHYSICS_PULLEY_JOINT_ID) | PHYSICS_JOINT_T;
|
||||
const bits PHYSICS_GEAR_JOINT_T = (bits(1) << PHYSICS_GEAR_JOINT_ID) | PHYSICS_JOINT_T;
|
||||
|
||||
// Thread.
|
||||
const bits THREAD_THREAD_T = (bits(1) << THREAD_THREAD_ID) | OBJECT_T;
|
||||
|
||||
// Modules.
|
||||
const bits MODULE_FILESYSTEM_T = (bits(1) << MODULE_FILESYSTEM_ID) | MODULE_T;
|
||||
const bits MODULE_IMAGE_T = (bits(1) << MODULE_IMAGE_ID) | MODULE_T;
|
||||
|
||||
+9
-7
@@ -1,14 +1,14 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2010 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
|
||||
@@ -52,6 +52,7 @@
|
||||
#include <physics/box2d/wrap_Physics.h>
|
||||
#include <sound/wrap_Sound.h>
|
||||
#include <timer/sdl/wrap_Timer.h>
|
||||
#include <thread/sdl/wrap_Thread.h>
|
||||
|
||||
// Libraries.
|
||||
#include "libraries/luasocket/luasocket.h"
|
||||
@@ -78,6 +79,7 @@ static const luaL_Reg modules[] = {
|
||||
{ "love.physics", love::physics::box2d::luaopen_love_physics },
|
||||
{ "love.sound", love::sound::luaopen_love_sound },
|
||||
{ "love.timer", love::timer::sdl::luaopen_love_timer },
|
||||
{ "love.thread", love::thread::sdl::luaopen_love_thread },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
@@ -194,7 +196,7 @@ int w__openConsole(lua_State * L)
|
||||
FILE *fp;
|
||||
|
||||
AllocConsole();
|
||||
|
||||
|
||||
// Set size.
|
||||
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &console_info);
|
||||
console_info.dwSize.Y = MAX_CONSOLE_LINES;
|
||||
@@ -258,7 +260,7 @@ int main(int argc, char ** argv)
|
||||
|
||||
love::luax_preload(L, luaopen_love, "love");
|
||||
|
||||
luaopen_love(L);
|
||||
luaopen_love(L);
|
||||
|
||||
// Add command line arguments to global arg (like stand-alone Lua).
|
||||
{
|
||||
@@ -283,7 +285,7 @@ int main(int argc, char ** argv)
|
||||
}
|
||||
|
||||
// Add love.__exe = true.
|
||||
// This indicates that we're running the
|
||||
// This indicates that we're running the
|
||||
// standalone version of love, and not the
|
||||
// DLL version.
|
||||
{
|
||||
@@ -311,4 +313,4 @@ int main(int argc, char ** argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif // LOVE_BUILD_EXE
|
||||
#endif // LOVE_BUILD_EXE
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2010 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
|
||||
@@ -40,10 +40,10 @@ namespace physfs
|
||||
{
|
||||
const char * arg0 = luaL_checkstring(L, 1);
|
||||
|
||||
try
|
||||
try
|
||||
{
|
||||
instance->init(arg0);
|
||||
}
|
||||
}
|
||||
catch(Exception & e)
|
||||
{
|
||||
return luaL_error(L, e.what());
|
||||
@@ -186,7 +186,7 @@ namespace physfs
|
||||
{
|
||||
return luaL_error(L, e.what());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int w_enumerate(lua_State * L)
|
||||
{
|
||||
@@ -256,6 +256,7 @@ namespace physfs
|
||||
{ "enumerate", w_enumerate },
|
||||
{ "lines", w_lines },
|
||||
{ "load", w_load },
|
||||
{ "newFileData", w_newFileData },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
@@ -269,11 +270,11 @@ namespace physfs
|
||||
{
|
||||
if(instance == 0)
|
||||
{
|
||||
try
|
||||
try
|
||||
{
|
||||
instance = new Filesystem();
|
||||
love::luax_register_searcher(L, loader);
|
||||
}
|
||||
}
|
||||
catch(Exception & e)
|
||||
{
|
||||
return luaL_error(L, e.what());
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2010 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 "Thread.h"
|
||||
|
||||
extern "C" int luaopen_love(lua_State * L);
|
||||
|
||||
int threadfunc(const char *data)
|
||||
{
|
||||
lua_State * L = lua_open();
|
||||
luaL_openlibs(L);
|
||||
love::luax_preload(L, luaopen_love, "love");
|
||||
luaopen_love(L);
|
||||
luaL_dostring(L, data);
|
||||
lua_close(L);
|
||||
return 0;
|
||||
}
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace thread
|
||||
{
|
||||
namespace sdl
|
||||
{
|
||||
Thread::Thread(ThreadModuleRegistrar *reg, std::string name, love::Data *data)
|
||||
: reg(reg), name(name), handle(0)
|
||||
{
|
||||
unsigned int len = data->getSize();
|
||||
this->data = new char[len];
|
||||
memcpy(this->data, data->getData(), len);
|
||||
}
|
||||
|
||||
Thread::~Thread()
|
||||
{
|
||||
delete[] data;
|
||||
if (handle)
|
||||
SDL_KillThread(handle);
|
||||
reg->unregister(name);
|
||||
}
|
||||
|
||||
void Thread::start()
|
||||
{
|
||||
if (!handle)
|
||||
SDL_CreateThread((int (*)(void*)) threadfunc, (void*) data);
|
||||
}
|
||||
|
||||
void Thread::kill()
|
||||
{
|
||||
if (handle)
|
||||
SDL_KillThread(handle);
|
||||
}
|
||||
|
||||
std::string Thread::getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
ThreadModule::~ThreadModule()
|
||||
{
|
||||
for (threadlist_t::iterator i = threads.begin(); i != threads.end(); i++)
|
||||
{
|
||||
i->second->kill();
|
||||
}
|
||||
}
|
||||
|
||||
Thread *ThreadModule::newThread(std::string name, love::Data *data)
|
||||
{
|
||||
if (threads.count(name) != 0)
|
||||
return 0;
|
||||
Thread *t = new Thread(this, name, data);
|
||||
threads[name] = t;
|
||||
return t;
|
||||
}
|
||||
|
||||
Thread *ThreadModule::getThread(std::string name)
|
||||
{
|
||||
if (threads.count(name) == 0)
|
||||
return 0;
|
||||
threadlist_t::iterator i = threads.find(name);
|
||||
return i->second;
|
||||
}
|
||||
|
||||
Thread **ThreadModule::getThreads()
|
||||
{
|
||||
Thread **list = new Thread*[threads.size()];
|
||||
int c = 0;
|
||||
for (threadlist_t::iterator i = threads.begin(); i != threads.end(); i++, c++)
|
||||
{
|
||||
list[c] = i->second;
|
||||
}
|
||||
}
|
||||
|
||||
void ThreadModule::unregister(std::string name)
|
||||
{
|
||||
if (threads.count(name) == 0)
|
||||
return;
|
||||
threadlist_t::iterator i = threads.find(name);
|
||||
threads.erase(i);
|
||||
}
|
||||
|
||||
const char *ThreadModule::getName() const
|
||||
{
|
||||
return "love.thread.sdl";
|
||||
}
|
||||
} // sdl
|
||||
} // thread
|
||||
} // love
|
||||
@@ -0,0 +1,83 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2010 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_THREAD_THREAD_H
|
||||
#define LOVE_THREAD_THREAD_H
|
||||
|
||||
// SDL
|
||||
#include <SDL_thread.h>
|
||||
|
||||
// STL
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
// LOVE
|
||||
#include <common/Module.h>
|
||||
#include <filesystem/File.h>
|
||||
#include <common/runtime.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace thread
|
||||
{
|
||||
namespace sdl
|
||||
{
|
||||
class ThreadModuleRegistrar
|
||||
{
|
||||
public:
|
||||
virtual void unregister(std::string name) = 0;
|
||||
};
|
||||
|
||||
class Thread : public love::Object
|
||||
{
|
||||
private:
|
||||
SDL_Thread *handle;
|
||||
ThreadModuleRegistrar *reg;
|
||||
std::string name;
|
||||
char *data;
|
||||
|
||||
public:
|
||||
Thread(ThreadModuleRegistrar *reg, std::string name, love::Data *data);
|
||||
~Thread();
|
||||
void start();
|
||||
void kill();
|
||||
std::string getName();
|
||||
}; // Thread
|
||||
|
||||
typedef std::map<std::string, Thread*> threadlist_t;
|
||||
|
||||
class ThreadModule : public Module, ThreadModuleRegistrar
|
||||
{
|
||||
private:
|
||||
threadlist_t threads;
|
||||
|
||||
public:
|
||||
~ThreadModule();
|
||||
Thread *newThread(std::string name, love::Data *data);
|
||||
Thread **getThreads();
|
||||
Thread *getThread(std::string name);
|
||||
void unregister(std::string name);
|
||||
const char *getName() const;
|
||||
}; // ThreadModule
|
||||
} // sdl
|
||||
} // thread
|
||||
} // love
|
||||
|
||||
#endif // LOVE_THREAD_THREAD_H
|
||||
Binary file not shown.
@@ -0,0 +1,131 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2010 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_Thread.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace thread
|
||||
{
|
||||
namespace sdl
|
||||
{
|
||||
Thread *luax_checkthread(lua_State *L, int idx)
|
||||
{
|
||||
return luax_checktype<Thread>(L, idx, "Thread", THREAD_THREAD_T);
|
||||
}
|
||||
|
||||
int w_Thread_start(lua_State *L)
|
||||
{
|
||||
Thread *t = luax_checkthread(L, 1);
|
||||
t->start();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_Thread_kill(lua_State *L)
|
||||
{
|
||||
Thread *t = luax_checkthread(L, 1);
|
||||
t->kill();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_Thread_getName(lua_State *L)
|
||||
{
|
||||
Thread *t = luax_checkthread(L, 1);
|
||||
lua_pushstring(L, t->getName().c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const luaL_Reg type_functions[] = {
|
||||
{ "start", w_Thread_start },
|
||||
{ "kill", w_Thread_kill },
|
||||
{ "getName", w_Thread_getName },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
int luaopen_thread(lua_State *L)
|
||||
{
|
||||
return luax_register_type(L, "Thread", type_functions);
|
||||
}
|
||||
|
||||
static ThreadModule *instance;
|
||||
|
||||
int w_newThread(lua_State *L)
|
||||
{
|
||||
std::string name = luaL_checkstring(L, 1);
|
||||
if (lua_isstring(L, 2))
|
||||
luax_convobj(L, 2, "filesystem", "read");
|
||||
love::Data *data = luax_checktype<love::Data>(L, 2, "Data", DATA_T);
|
||||
Thread *t = instance->newThread(name, data);
|
||||
luax_newtype(L, "Thread", THREAD_THREAD_T, (void*)t);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_getThreads(lua_State *L)
|
||||
{
|
||||
}
|
||||
|
||||
int w_getThread(lua_State *L)
|
||||
{
|
||||
std::string name = luaL_checkstring(L, 1);
|
||||
Thread *t = instance->getThread(name);
|
||||
luax_newtype(L, "Thread", THREAD_THREAD_T, (void*)t);
|
||||
t->retain();
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
// List of functions to wrap.
|
||||
static const luaL_Reg module_functions[] = {
|
||||
{ "newThread", w_newThread },
|
||||
{ "getThread", w_getThread },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
static const lua_CFunction types[] = {
|
||||
luaopen_thread,
|
||||
0
|
||||
};
|
||||
|
||||
int luaopen_love_thread(lua_State *L)
|
||||
{
|
||||
if(instance == 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
instance = new ThreadModule();
|
||||
}
|
||||
catch(Exception & e)
|
||||
{
|
||||
return luaL_error(L, e.what());
|
||||
}
|
||||
}
|
||||
|
||||
WrappedModule w;
|
||||
w.module = instance;
|
||||
w.name = "thread";
|
||||
w.flags = MODULE_T;
|
||||
w.functions = module_functions;
|
||||
w.types = types;
|
||||
|
||||
return luax_register_module(L, w);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2010 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_THREAD_SDL_WRAP_THREAD_H
|
||||
#define LOVE_THREAD_SDL_WRAP_THREAD_H
|
||||
|
||||
// LOVE
|
||||
#include <common/config.h>
|
||||
#include "Thread.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace thread
|
||||
{
|
||||
namespace sdl
|
||||
{
|
||||
Thread *luax_checkthread(lua_State *L, int idx);
|
||||
int w_Thread_start(lua_State *L);
|
||||
int w_Thread_kill(lua_State *L);
|
||||
int w_thread_getName(lua_State *L);
|
||||
|
||||
int luaopen_thread(lua_State *L);
|
||||
|
||||
int w_newThread(lua_State *L);
|
||||
int w_getThreads(lua_State *L);
|
||||
int w_getThread(lua_State *L);
|
||||
|
||||
extern "C" LOVE_EXPORT int luaopen_love_thread(lua_State * L);
|
||||
} // sdl
|
||||
} // thread
|
||||
} // love
|
||||
|
||||
#endif // LOVE_THREAD_SDL_WRAP_THREAD_H
|
||||
Binary file not shown.
Reference in New Issue
Block a user