From 87e3c4131ce39523d500f3633eb25078bedf0c58 Mon Sep 17 00:00:00 2001 From: rude Date: Sat, 10 Oct 2009 11:11:04 +0200 Subject: [PATCH] Finally abstracted constants properly. Changed how the event module works; wasn't really abstract before. Removed libs we're not going to use: native, signal. --- platform/msvc2008/common/common.vcproj | 16 + platform/msvc2008/event/event.vcproj | 20 + .../msvc2008/filesystem/filesystem.vcproj | 6 +- platform/msvc2008/graphics/graphics.vcproj | 5 + platform/msvc2008/joystick/joystick.vcproj | 4 + platform/msvc2008/keyboard/keyboard.vcproj | 4 + platform/msvc2008/love.sln | 18 - platform/msvc2008/love.vcproj | 500 +- platform/msvc2008/mouse/mouse.vcproj | 4 + platform/msvc2008/native/native.vcproj | 260 - platform/msvc2008/physics/physics.vcproj | 8 + platform/msvc2008/signal/signal.vcproj | 213 - src/common/EnumMap.h | 99 + src/common/StringMap.h | 164 + src/common/runtime.cpp | 10 - src/common/runtime.h | 12 - src/love.cpp | 6 - src/modules/audio/wrap_Audio.cpp | 1 - src/modules/event/Event.cpp | 235 + src/modules/event/Event.h | 87 +- src/modules/event/sdl/Event.cpp | 328 +- src/modules/event/sdl/Event.h | 51 +- src/modules/event/sdl/wrap_Event.cpp | 134 +- src/modules/event/sdl/wrap_Event.h | 1 - .../posix/Signal.h => filesystem/File.cpp} | 55 +- src/modules/filesystem/File.h | 12 +- src/modules/filesystem/physfs/File.cpp | 8 +- src/modules/filesystem/physfs/wrap_File.cpp | 7 +- .../filesystem/physfs/wrap_Filesystem.cpp | 10 - src/modules/font/freetype/wrap_Font.cpp | 1 - src/modules/graphics/Graphics.cpp | 141 + src/modules/graphics/Graphics.h | 73 +- src/modules/graphics/opengl/Graphics.cpp | 176 +- src/modules/graphics/opengl/Graphics.h | 60 +- src/modules/graphics/opengl/wrap_Graphics.cpp | 156 +- src/modules/image/EncodedImageData.cpp | 35 +- src/modules/image/EncodedImageData.h | 107 +- src/modules/image/Image.h | 5 - src/modules/image/devil/ImageData.cpp | 8 +- src/modules/image/devil/ImageData.h | 2 +- src/modules/image/wrap_Image.cpp | 13 +- .../Signal.cpp => joystick/Joystick.cpp} | 121 +- src/modules/joystick/Joystick.h | 37 +- src/modules/joystick/sdl/Joystick.cpp | 27 +- src/modules/joystick/sdl/Joystick.h | 14 +- src/modules/joystick/sdl/wrap_Joystick.cpp | 26 +- src/modules/keyboard/Keyboard.cpp | 187 + src/modules/keyboard/Keyboard.h | 159 +- src/modules/keyboard/sdl/Keyboard.cpp | 171 +- src/modules/keyboard/sdl/Keyboard.h | 13 +- src/modules/keyboard/sdl/wrap_Keyboard.cpp | 176 +- src/modules/keyboard/sdl/wrap_Keyboard.h | 3 + .../tcc/wrap_Native.h => mouse/Mouse.cpp} | 57 +- src/modules/mouse/Mouse.h | 25 +- src/modules/mouse/sdl/Mouse.cpp | 26 +- src/modules/mouse/sdl/Mouse.h | 10 +- src/modules/mouse/sdl/wrap_Mouse.cpp | 25 +- src/modules/native/tcc/Native.cpp | 162 - src/modules/native/tcc/Native.h | 99 - src/modules/native/tcc/api.c | 113 - src/modules/native/tcc/libtcc/arm-gen.c | 1734 ------ src/modules/native/tcc/libtcc/c67-gen.c | 2548 -------- src/modules/native/tcc/libtcc/coff.h | 446 -- src/modules/native/tcc/libtcc/config.h | 4 - src/modules/native/tcc/libtcc/elf.h | 1714 ------ src/modules/native/tcc/libtcc/i386-asm.c | 1211 ---- src/modules/native/tcc/libtcc/i386-asm.h | 446 -- src/modules/native/tcc/libtcc/i386-gen.c | 1034 ---- src/modules/native/tcc/libtcc/il-gen.c | 667 --- src/modules/native/tcc/libtcc/il-opcodes.h | 251 - src/modules/native/tcc/libtcc/libtcc.c | 2263 -------- src/modules/native/tcc/libtcc/libtcc.h | 108 - src/modules/native/tcc/libtcc/stab.def | 234 - src/modules/native/tcc/libtcc/stab.h | 17 - src/modules/native/tcc/libtcc/tcc.c | 553 -- src/modules/native/tcc/libtcc/tcc.h | 766 --- src/modules/native/tcc/libtcc/tccasm.c | 1021 ---- src/modules/native/tcc/libtcc/tcccoff.c | 957 --- src/modules/native/tcc/libtcc/tccelf.c | 2732 --------- src/modules/native/tcc/libtcc/tccgen.c | 5122 ----------------- src/modules/native/tcc/libtcc/tccpe.c | 1559 ----- src/modules/native/tcc/libtcc/tccpp.c | 2935 ---------- src/modules/native/tcc/libtcc/tcctok.h | 469 -- src/modules/native/tcc/libtcc/x86_64-gen.c | 1419 ----- src/modules/native/tcc/wrap_Native.cpp | 153 - .../{native/tcc/api.h => physics/Joint.cpp} | 52 +- src/modules/physics/Joint.h | 17 +- .../posix/wrap_Signal.h => physics/Shape.cpp} | 94 +- src/modules/physics/Shape.h | 15 +- src/modules/physics/box2d/Joint.cpp | 4 +- src/modules/physics/box2d/Joint.h | 2 +- src/modules/physics/box2d/Shape.cpp | 4 +- src/modules/physics/box2d/Shape.h | 2 +- src/modules/physics/box2d/wrap_Joint.cpp | 5 +- src/modules/physics/box2d/wrap_Physics.cpp | 15 - src/modules/physics/box2d/wrap_Shape.cpp | 5 +- src/modules/signal/posix/wrap_Signal.cpp | 103 - src/modules/sound/wrap_Sound.cpp | 1 - src/modules/timer/sdl/wrap_Timer.cpp | 1 - src/scripts/boot.lua | 23 +- src/scripts/boot.lua.h | 1509 +++-- 101 files changed, 3225 insertions(+), 33496 deletions(-) delete mode 100644 platform/msvc2008/native/native.vcproj delete mode 100644 platform/msvc2008/signal/signal.vcproj create mode 100644 src/common/EnumMap.h create mode 100644 src/common/StringMap.h create mode 100644 src/modules/event/Event.cpp rename src/modules/{signal/posix/Signal.h => filesystem/File.cpp} (63%) create mode 100644 src/modules/graphics/Graphics.cpp rename src/modules/{signal/posix/Signal.cpp => joystick/Joystick.cpp} (54%) create mode 100644 src/modules/keyboard/Keyboard.cpp rename src/modules/{native/tcc/wrap_Native.h => mouse/Mouse.cpp} (58%) delete mode 100644 src/modules/native/tcc/Native.cpp delete mode 100644 src/modules/native/tcc/Native.h delete mode 100644 src/modules/native/tcc/api.c delete mode 100644 src/modules/native/tcc/libtcc/arm-gen.c delete mode 100644 src/modules/native/tcc/libtcc/c67-gen.c delete mode 100644 src/modules/native/tcc/libtcc/coff.h delete mode 100644 src/modules/native/tcc/libtcc/config.h delete mode 100644 src/modules/native/tcc/libtcc/elf.h delete mode 100644 src/modules/native/tcc/libtcc/i386-asm.c delete mode 100644 src/modules/native/tcc/libtcc/i386-asm.h delete mode 100644 src/modules/native/tcc/libtcc/i386-gen.c delete mode 100644 src/modules/native/tcc/libtcc/il-gen.c delete mode 100644 src/modules/native/tcc/libtcc/il-opcodes.h delete mode 100644 src/modules/native/tcc/libtcc/libtcc.c delete mode 100644 src/modules/native/tcc/libtcc/libtcc.h delete mode 100644 src/modules/native/tcc/libtcc/stab.def delete mode 100644 src/modules/native/tcc/libtcc/stab.h delete mode 100644 src/modules/native/tcc/libtcc/tcc.c delete mode 100644 src/modules/native/tcc/libtcc/tcc.h delete mode 100644 src/modules/native/tcc/libtcc/tccasm.c delete mode 100644 src/modules/native/tcc/libtcc/tcccoff.c delete mode 100644 src/modules/native/tcc/libtcc/tccelf.c delete mode 100644 src/modules/native/tcc/libtcc/tccgen.c delete mode 100644 src/modules/native/tcc/libtcc/tccpe.c delete mode 100644 src/modules/native/tcc/libtcc/tccpp.c delete mode 100644 src/modules/native/tcc/libtcc/tcctok.h delete mode 100644 src/modules/native/tcc/libtcc/x86_64-gen.c delete mode 100644 src/modules/native/tcc/wrap_Native.cpp rename src/modules/{native/tcc/api.h => physics/Joint.cpp} (55%) rename src/modules/{signal/posix/wrap_Signal.h => physics/Shape.cpp} (62%) delete mode 100644 src/modules/signal/posix/wrap_Signal.cpp diff --git a/platform/msvc2008/common/common.vcproj b/platform/msvc2008/common/common.vcproj index ea6c39744..ad2161819 100644 --- a/platform/msvc2008/common/common.vcproj +++ b/platform/msvc2008/common/common.vcproj @@ -154,6 +154,10 @@ RelativePath="..\..\..\src\common\Data.h" > + + @@ -306,6 +310,18 @@ RelativePath="..\..\..\src\common\runtime.h" > + + + + + + diff --git a/platform/msvc2008/event/event.vcproj b/platform/msvc2008/event/event.vcproj index fafe117a4..ac7acfd4f 100644 --- a/platform/msvc2008/event/event.vcproj +++ b/platform/msvc2008/event/event.vcproj @@ -205,6 +205,26 @@ > + + + + + + + + diff --git a/platform/msvc2008/filesystem/filesystem.vcproj b/platform/msvc2008/filesystem/filesystem.vcproj index 30801e074..53954a800 100644 --- a/platform/msvc2008/filesystem/filesystem.vcproj +++ b/platform/msvc2008/filesystem/filesystem.vcproj @@ -170,7 +170,7 @@ + + diff --git a/platform/msvc2008/graphics/graphics.vcproj b/platform/msvc2008/graphics/graphics.vcproj index d2f6f3e2e..6f520194b 100644 --- a/platform/msvc2008/graphics/graphics.vcproj +++ b/platform/msvc2008/graphics/graphics.vcproj @@ -234,6 +234,7 @@ @@ -606,6 +607,10 @@ RelativePath="..\..\..\src\modules\graphics\Drawable.h" > + + diff --git a/platform/msvc2008/joystick/joystick.vcproj b/platform/msvc2008/joystick/joystick.vcproj index 078f37ab3..0b1f9cc67 100644 --- a/platform/msvc2008/joystick/joystick.vcproj +++ b/platform/msvc2008/joystick/joystick.vcproj @@ -205,6 +205,10 @@ > + + diff --git a/platform/msvc2008/keyboard/keyboard.vcproj b/platform/msvc2008/keyboard/keyboard.vcproj index 8d7531371..ef72139a5 100644 --- a/platform/msvc2008/keyboard/keyboard.vcproj +++ b/platform/msvc2008/keyboard/keyboard.vcproj @@ -205,6 +205,10 @@ > + + diff --git a/platform/msvc2008/love.sln b/platform/msvc2008/love.sln index 41e4571de..674311b5a 100644 --- a/platform/msvc2008/love.sln +++ b/platform/msvc2008/love.sln @@ -42,11 +42,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mouse", "mouse\mouse.vcproj {8273822F-45A4-4BE3-82F3-B8B3223C578C} = {8273822F-45A4-4BE3-82F3-B8B3223C578C} EndProjectSection EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "native", "native\native.vcproj", "{CCAD89EC-2C3C-4F69-BF71-D9DA230FE109}" - ProjectSection(ProjectDependencies) = postProject - {8273822F-45A4-4BE3-82F3-B8B3223C578C} = {8273822F-45A4-4BE3-82F3-B8B3223C578C} - EndProjectSection -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "physics", "physics\physics.vcproj", "{39CDF8C8-016D-423E-94BA-7DD798CF0E15}" ProjectSection(ProjectDependencies) = postProject {8273822F-45A4-4BE3-82F3-B8B3223C578C} = {8273822F-45A4-4BE3-82F3-B8B3223C578C} @@ -77,11 +72,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "font", "font\font.vcproj", EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "love", "love.vcproj", "{F2FDC53D-1ECD-4CF1-BA3F-3E59A2484DB9}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "signal", "signal\signal.vcproj", "{5A7AAEBC-F269-41DA-984A-75F975549CA5}" - ProjectSection(ProjectDependencies) = postProject - {8273822F-45A4-4BE3-82F3-B8B3223C578C} = {8273822F-45A4-4BE3-82F3-B8B3223C578C} - EndProjectSection -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lovedll", "lovedll\lovedll.vcproj", "{2863FF8A-153F-46E0-8E71-2E58F3809E9B}" ProjectSection(ProjectDependencies) = postProject {8273822F-45A4-4BE3-82F3-B8B3223C578C} = {8273822F-45A4-4BE3-82F3-B8B3223C578C} @@ -129,10 +119,6 @@ Global {88881251-6818-485E-A262-DE1283096589}.Debug|Win32.Build.0 = Debug|Win32 {88881251-6818-485E-A262-DE1283096589}.Release|Win32.ActiveCfg = Release|Win32 {88881251-6818-485E-A262-DE1283096589}.Release|Win32.Build.0 = Release|Win32 - {CCAD89EC-2C3C-4F69-BF71-D9DA230FE109}.Debug|Win32.ActiveCfg = Debug|Win32 - {CCAD89EC-2C3C-4F69-BF71-D9DA230FE109}.Debug|Win32.Build.0 = Debug|Win32 - {CCAD89EC-2C3C-4F69-BF71-D9DA230FE109}.Release|Win32.ActiveCfg = Release|Win32 - {CCAD89EC-2C3C-4F69-BF71-D9DA230FE109}.Release|Win32.Build.0 = Release|Win32 {39CDF8C8-016D-423E-94BA-7DD798CF0E15}.Debug|Win32.ActiveCfg = Debug|Win32 {39CDF8C8-016D-423E-94BA-7DD798CF0E15}.Debug|Win32.Build.0 = Debug|Win32 {39CDF8C8-016D-423E-94BA-7DD798CF0E15}.Release|Win32.ActiveCfg = Release|Win32 @@ -157,10 +143,6 @@ Global {F2FDC53D-1ECD-4CF1-BA3F-3E59A2484DB9}.Debug|Win32.Build.0 = Debug|Win32 {F2FDC53D-1ECD-4CF1-BA3F-3E59A2484DB9}.Release|Win32.ActiveCfg = Release|Win32 {F2FDC53D-1ECD-4CF1-BA3F-3E59A2484DB9}.Release|Win32.Build.0 = Release|Win32 - {5A7AAEBC-F269-41DA-984A-75F975549CA5}.Debug|Win32.ActiveCfg = Debug|Win32 - {5A7AAEBC-F269-41DA-984A-75F975549CA5}.Debug|Win32.Build.0 = Debug|Win32 - {5A7AAEBC-F269-41DA-984A-75F975549CA5}.Release|Win32.ActiveCfg = Release|Win32 - {5A7AAEBC-F269-41DA-984A-75F975549CA5}.Release|Win32.Build.0 = Release|Win32 {2863FF8A-153F-46E0-8E71-2E58F3809E9B}.Debug|Win32.ActiveCfg = Debug|Win32 {2863FF8A-153F-46E0-8E71-2E58F3809E9B}.Debug|Win32.Build.0 = Debug|Win32 {2863FF8A-153F-46E0-8E71-2E58F3809E9B}.Release|Win32.ActiveCfg = Release|Win32 diff --git a/platform/msvc2008/love.vcproj b/platform/msvc2008/love.vcproj index 834d388a1..62c2d83ae 100644 --- a/platform/msvc2008/love.vcproj +++ b/platform/msvc2008/love.vcproj @@ -538,6 +538,26 @@ + + + + + + + + @@ -598,6 +618,10 @@ + + @@ -778,6 +802,10 @@ RelativePath="..\..\src\modules\graphics\Drawable.h" > + + @@ -846,6 +874,7 @@ @@ -1382,6 +1412,26 @@ + + + + + + + + @@ -1442,6 +1492,26 @@ + + + + + + + + @@ -1502,6 +1572,26 @@ + + + + + + + + @@ -1562,10 +1652,50 @@ + + + + + + + + + + + + + + + + @@ -3231,368 +3361,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + @@ -3757,6 +3529,10 @@ RelativePath="..\..\src\common\runtime.h" > + + diff --git a/platform/msvc2008/mouse/mouse.vcproj b/platform/msvc2008/mouse/mouse.vcproj index 9c8400cf5..04337a725 100644 --- a/platform/msvc2008/mouse/mouse.vcproj +++ b/platform/msvc2008/mouse/mouse.vcproj @@ -205,6 +205,10 @@ > + + diff --git a/platform/msvc2008/native/native.vcproj b/platform/msvc2008/native/native.vcproj deleted file mode 100644 index 08f33c109..000000000 --- a/platform/msvc2008/native/native.vcproj +++ /dev/null @@ -1,260 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/platform/msvc2008/physics/physics.vcproj b/platform/msvc2008/physics/physics.vcproj index c66b6c607..20ff39758 100644 --- a/platform/msvc2008/physics/physics.vcproj +++ b/platform/msvc2008/physics/physics.vcproj @@ -1241,10 +1241,18 @@ + + + + diff --git a/platform/msvc2008/signal/signal.vcproj b/platform/msvc2008/signal/signal.vcproj deleted file mode 100644 index 9adf640fb..000000000 --- a/platform/msvc2008/signal/signal.vcproj +++ /dev/null @@ -1,213 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/common/EnumMap.h b/src/common/EnumMap.h new file mode 100644 index 000000000..674452c33 --- /dev/null +++ b/src/common/EnumMap.h @@ -0,0 +1,99 @@ +/** +* 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_ENUM_MAP_H +#define LOVE_ENUM_MAP_H + +#include "Exception.h" + +namespace love +{ + template + class EnumMap + { + private: + + struct Value + { + unsigned v; + bool set; + Value() : set(false) {} + }; + + Value values_t[PEAK]; + Value values_u[PEAK]; + + public: + + struct Entry + { + T t; + U u; + }; + + EnumMap(Entry * entries, unsigned size) + { + unsigned n = size/sizeof(Entry); + + for(unsigned i = 0; i + class StringMap + { + private: + + struct Record + { + const char * key; + T value; + bool set; + Record() : set(false) {} + }; + + const static unsigned MAX = (unsigned)((float)SIZE * 1.5f); + + Record records[MAX]; + const char * reverse[SIZE]; + + public: + + struct Entry + { + const char * key; + T value; + }; + + StringMap(Entry * entries, unsigned num) + { + + for(unsigned i = 0; i < SIZE; ++i) + reverse[i] = 0; + + unsigned n = num/sizeof(Entry); + + for(unsigned i = 0; i < n; ++i) + { + add(entries[i].key, entries[i].value); + } + } + + bool streq(const char * a, const char * b) + { + while(*a != 0 && *b != 0) + { + if(*a != *b) + return false; + ++a; + ++b; + } + + return (*a == 0 && *b == 0); + } + + bool find(const char * key, T & t) + { + unsigned str_hash = djb2(key); + + for(unsigned i = 0; i < MAX; ++i) + { + unsigned str_i = (str_hash + i) % MAX; + + if(records[i].set && streq(records[i].key, key)) + { + t = records[i].value; + return true; + } + } + + return false; + } + + bool find(T key, const char *& str) + { + unsigned index = (unsigned)key; + + if(index >= SIZE) + return false; + + if(reverse[index] != 0) + { + str = reverse[index]; + return true; + } + else + { + return false; + } + } + + bool add(const char * key, T value) + { + unsigned str_hash = djb2(key); + bool inserted = false; + + for(unsigned i = 0; i < MAX; ++i) + { + unsigned str_i = (str_hash + i) % MAX; + + if(!records[str_i].set) + { + inserted = true; + records[str_i].set = true; + records[str_i].key = key; + records[str_i].value = value; + break; + } + } + + unsigned index = (unsigned)value; + + if(index >= SIZE) + { + printf("\nConstant %s out of bounds with %i!\n", key, index); + return false; + } + + reverse[index] = key; + + return inserted; + } + + unsigned djb2(const char * key) + { + unsigned hash = 5381; + int c; + + while (c = *key++) + hash = ((hash << 5) + hash) + c; + + return hash; + } + + }; // StringMap + +} // love + +#endif // LOVE_STRING_MAP_H diff --git a/src/common/runtime.cpp b/src/common/runtime.cpp index 73f157cd3..3db3f3705 100644 --- a/src/common/runtime.cpp +++ b/src/common/runtime.cpp @@ -134,16 +134,6 @@ namespace love // Gets the love table. luax_insistglobal(L, "love"); - // Install constants. - if(m.constants != 0) - { - for(int i = 0; m.constants[i].name != 0; i++) - { - lua_pushinteger(L, m.constants[i].value); - lua_setfield(L, -2, m.constants[i].name); - } - } - // Create new table for module. lua_newtable(L); diff --git a/src/common/runtime.h b/src/common/runtime.h index e926d4934..1449ad57f 100644 --- a/src/common/runtime.h +++ b/src/common/runtime.h @@ -65,16 +65,6 @@ namespace love bool own; }; - - /** - * Used to store constants in arrays. - **/ - struct Constant - { - const char * name; - int value; - }; - /** * A Module with Lua wrapper functions and other data. **/ @@ -95,8 +85,6 @@ namespace love // A list of functions which expose the types of the modules (last element 0). const lua_CFunction * types; - // A list of constants (last element 0). - const Constant * constants; }; /** diff --git a/src/love.cpp b/src/love.cpp index 08b0b4a1a..7239d745c 100644 --- a/src/love.cpp +++ b/src/love.cpp @@ -33,15 +33,12 @@ #include