├── Bin ├── Bomb │ ├── game.lua │ └── scene.lua ├── DS │ ├── class.lua │ └── queue.lua ├── Dbgview.exe ├── Fairy2D.exe ├── GL │ ├── define.lua │ ├── engine.lua │ ├── matrix.lua │ └── shader.lua ├── Net │ ├── application.lua │ ├── json.lua │ ├── json │ │ ├── decode.lua │ │ ├── decode │ │ │ ├── composite.lua │ │ │ ├── number.lua │ │ │ ├── others.lua │ │ │ ├── state.lua │ │ │ ├── strings.lua │ │ │ └── util.lua │ │ ├── encode.lua │ │ ├── encode │ │ │ ├── array.lua │ │ │ ├── calls.lua │ │ │ ├── number.lua │ │ │ ├── object.lua │ │ │ ├── others.lua │ │ │ ├── output.lua │ │ │ ├── output_utility.lua │ │ │ └── strings.lua │ │ └── util.lua │ ├── lpeg.dll │ ├── ltn12.lua │ ├── mime.lua │ ├── mime │ │ └── core.dll │ ├── socket.lua │ ├── socket │ │ ├── core.dll │ │ ├── ftp.lua │ │ ├── headers.lua │ │ ├── http.lua │ │ ├── smtp.lua │ │ ├── tp.lua │ │ └── url.lua │ └── tcpserver.lua ├── Resource │ ├── RPG │ │ ├── Animations │ │ │ ├── Attack1.png │ │ │ ├── Blow1.png │ │ │ ├── Blow2.png │ │ │ ├── Darkness2.png │ │ │ ├── Earth2.png │ │ │ ├── Fire1.png │ │ │ ├── Heal1.png │ │ │ ├── Light2.png │ │ │ ├── Spear1.png │ │ │ ├── Spear2.png │ │ │ ├── Special5.png │ │ │ ├── State4.png │ │ │ ├── State5.png │ │ │ ├── Sword1.png │ │ │ ├── Sword6.png │ │ │ ├── Water2.png │ │ │ └── Wind2.png │ │ ├── Battlers │ │ │ ├── Bat.png │ │ │ ├── Cockatrice.png │ │ │ ├── Dragon.png │ │ │ ├── Fairy.png │ │ │ ├── Hornet.png │ │ │ ├── Plant.png │ │ │ ├── Rat.png │ │ │ ├── Scorpion.png │ │ │ ├── Slime.png │ │ │ ├── Spider.png │ │ │ ├── Willowisp.png │ │ │ └── 吉尔.png │ │ ├── Characters │ │ │ ├── !$Gate1.png │ │ │ ├── !$Gate2.png │ │ │ ├── !Chest.png │ │ │ ├── !Door1.png │ │ │ ├── !Door3.png │ │ │ ├── !Other2.png │ │ │ ├── !Other3.png │ │ │ ├── Actor1.png │ │ │ ├── Actor2.png │ │ │ ├── Actor3.png │ │ │ ├── Animal.png │ │ │ ├── Evil.png │ │ │ ├── Monster.png │ │ │ ├── People1.png │ │ │ ├── People2.png │ │ │ ├── People3.png │ │ │ ├── People4.png │ │ │ ├── People5.png │ │ │ ├── Spiritual.png │ │ │ └── Vehicle.png │ │ ├── Faces │ │ │ ├── Actor1.png │ │ │ ├── Actor2.png │ │ │ ├── Actor3.png │ │ │ ├── Evil.png │ │ │ ├── Monster.png │ │ │ ├── People1.png │ │ │ ├── People2.png │ │ │ ├── People3.png │ │ │ ├── People4.png │ │ │ ├── Spiritual.png │ │ │ ├── 吉尔.png │ │ │ ├── 拉尔夫&莉娜.png │ │ │ ├── 杰克.png │ │ │ ├── 维罗尼克&吉尔.png │ │ │ └── 萨迪.png │ │ ├── Parallaxes │ │ │ └── CloudySky.jpg │ │ ├── Pictures │ │ │ ├── END.jpg │ │ │ ├── 白色.jpg │ │ │ └── 黑色.jpg │ │ └── System │ │ │ ├── Balloon.png │ │ │ ├── BattleFloor.png │ │ │ ├── BattleStart.png │ │ │ ├── GameOver.png │ │ │ ├── IconSet.png │ │ │ ├── MessageBack.png │ │ │ ├── Shadow.png │ │ │ ├── TileA1.png │ │ │ ├── TileA2.png │ │ │ ├── TileA3.png │ │ │ ├── TileA4.png │ │ │ ├── TileA5.png │ │ │ ├── TileB.png │ │ │ ├── TileC.png │ │ │ ├── TileD.png │ │ │ ├── TileE.png │ │ │ ├── Title.jpg │ │ │ └── Window.png │ ├── Tank │ │ ├── Boom.png │ │ ├── Char.png │ │ ├── Frag.png │ │ ├── Misc.png │ │ ├── Tank.png │ │ └── Terr.png │ ├── bomb │ │ ├── 0.jpg │ │ ├── 1.jpg │ │ ├── 2.jpg │ │ ├── 3.jpg │ │ ├── 4.jpg │ │ ├── 5.jpg │ │ ├── 6.jpg │ │ ├── 7.jpg │ │ ├── 8.jpg │ │ ├── bomb.jpg │ │ ├── bomb1.jpg │ │ ├── flag.jpg │ │ ├── flag2.jpg │ │ └── null.jpg │ ├── frames │ │ ├── frame_0.png │ │ ├── frame_1.png │ │ ├── frame_2.png │ │ ├── frame_3.png │ │ ├── frame_4.png │ │ ├── frame_5.png │ │ ├── frame_6.png │ │ ├── frame_7.png │ │ └── stars.png │ ├── items │ │ ├── item_0.png │ │ ├── item_1.png │ │ ├── item_2.png │ │ └── item_3.png │ ├── tiles │ │ ├── tile_0.png │ │ └── tile_1.png │ └── window │ │ ├── background.png │ │ ├── border.png │ │ └── window.png ├── Snake │ ├── Game │ │ └── snake.lua │ ├── Resource │ │ └── item.png │ └── main.lua ├── Tank │ ├── bullet.lua │ ├── explosion.lua │ ├── game.lua │ ├── rune.lua │ ├── scene.lua │ ├── stage.lua │ ├── tank.lua │ ├── tile.lua │ ├── title.lua │ └── world.lua ├── Tower │ ├── evil.lua │ ├── fight.lua │ ├── frames.lua │ ├── game.lua │ ├── hero.lua │ ├── npc.lua │ ├── port.lua │ ├── prop.lua │ ├── scene.lua │ ├── sprite.lua │ ├── talk.lua │ └── terrain.lua ├── libtcmalloc_minimal.dll ├── lua-5.2.2.dll ├── main-bomb.lua ├── main-snake.lua ├── main-tower.lua ├── main.lua ├── msvcp110.dll └── msvcr110.dll ├── Fairy2D ├── Binding │ ├── Color.h │ ├── LuaBinding.h │ ├── LuaVM.cpp │ ├── LuaVM.h │ ├── OpenGLBinding.cpp │ ├── OpenGLBinding.h │ ├── ProgramBinding.cpp │ ├── ProgramBinding.h │ ├── RenderTextureBinding.cpp │ ├── RenderTextureBinding.h │ ├── TextRender.cpp │ ├── TextRender.h │ ├── TextRenderBinding.cpp │ ├── TextRenderBinding.h │ ├── TextureBinding.cpp │ ├── TextureBinding.h │ ├── VAOBinding.cpp │ ├── VAOBinding.h │ ├── VBOBinding.cpp │ └── VBOBinding.h ├── Fairy2D.vcxproj ├── Fairy2D.vcxproj.filters ├── Fairy2D.vcxproj.user ├── GameWindow.cpp ├── GameWindow.h ├── Lua │ ├── lauxlib.h │ ├── lua-5.2.2.dll │ ├── lua-5.2.2.lib │ ├── lua.h │ ├── lua.hpp │ ├── luaconf.h │ └── lualib.h ├── OpenGL │ ├── FileSystem.cpp │ ├── FileSystem.h │ ├── GLBuffer.cpp │ ├── GLBuffer.h │ ├── GLCache.cpp │ ├── GLCache.h │ ├── GLCommon.h │ ├── GLDevice.cpp │ ├── GLDevice.h │ ├── GLFontTexture.cpp │ ├── GLFontTexture.h │ ├── GLProgram.cpp │ ├── GLProgram.h │ ├── GLRenderTarget.cpp │ ├── GLRenderTarget.h │ ├── GLTexture.cpp │ ├── GLTexture.h │ ├── GLVertexArray.cpp │ ├── GLVertexArray.h │ ├── glew │ │ ├── glew.c │ │ ├── glew.h │ │ ├── glxew.h │ │ └── wglew.h │ ├── stb_image.c │ └── stb_image.h ├── System.cpp ├── System.h ├── Tcmalloc │ ├── libtcmalloc_minimal.dll │ ├── libtcmalloc_minimal.lib │ └── tcmalloc.h ├── UI │ ├── Window.cpp │ └── Window.h └── main.cpp └── README.md /Bin/Bomb/game.lua: -------------------------------------------------------------------------------- 1 | require 'gl.define' 2 | require 'gl.engine' 3 | require 'gl.matrix' 4 | require 'bomb.scene' 5 | 6 | local textures = { 7 | [0] = loadImage('bomb\\0.jpg'), 8 | loadImage('bomb\\1.jpg'), 9 | loadImage('bomb\\2.jpg'), 10 | loadImage('bomb\\3.jpg'), 11 | loadImage('bomb\\4.jpg'), 12 | loadImage('bomb\\5.jpg'), 13 | loadImage('bomb\\6.jpg'), 14 | loadImage('bomb\\7.jpg'), 15 | loadImage('bomb\\8.jpg'), 16 | } 17 | 18 | local bomb = loadImage('bomb\\bomb.jpg') 19 | local flag = loadImage('bomb\\flag.jpg') 20 | local null = loadImage('bomb\\null.jpg') 21 | 22 | local GameLayer = Class() 23 | function GameLayer:__init__() 24 | math.randomseed(os.time()) 25 | self.grids = {} 26 | for i = 1,24 do 27 | local grids = {} 28 | for j = 1,24 do 29 | local grid = {} 30 | grid.isbomb = math.random() < 0.15 31 | grids[j] = grid 32 | end 33 | self.grids[i] = grids 34 | end 35 | end 36 | 37 | local drawImage = drawImage 38 | local color = {1, 1, 1, 1} 39 | local function drawSprite(sprite, x, y) 40 | drawImage(sprite, x, y, 20, 20, 0, 0, 20, 20, color) 41 | end 42 | 43 | function GameLayer:render() 44 | local matrix = Matrix() 45 | matrix.translate(1, 0) 46 | pushMatrix(matrix, true) 47 | 48 | for i = 1,24 do 49 | local grids = self.grids[i] 50 | local y = (i - 1) * 20 51 | for j = 1,24 do 52 | local x = (j - 1) * 20 53 | local g = grids[j] 54 | local p = null 55 | if g.isreveal then 56 | p = g.isbomb and bomb or textures[g.number] 57 | elseif g.isflag then 58 | p = flag 59 | end 60 | drawSprite(p, x, y) 61 | end 62 | end 63 | 64 | for i = 0, 24 do 65 | drawLine(-1, i * 20, 480, i * 20, {0.5,0.5,0.5,1}) 66 | end 67 | 68 | for i = 0, 24 do 69 | drawLine(i * 20, -1, i * 20, 480, {0.5,0.5,0.5,1}) 70 | end 71 | 72 | popMatrix() 73 | end 74 | 75 | function GameLayer:isBomb(i, j) 76 | if i >= 1 and i <= 24 and j >= 1 and j <= 24 and self.grids[i][j].isbomb then 77 | return 1 78 | end 79 | return 0 80 | end 81 | 82 | function GameLayer:expand(i, j) 83 | if i >= 1 and i <= 24 and j >= 1 and j <= 24 then 84 | local grid = self.grids[i][j] 85 | if grid.isreveal then return end 86 | 87 | grid.isreveal = true 88 | if grid.isbomb then 89 | self.gameover = true 90 | return 91 | end 92 | 93 | grid.number = self.isBomb(i, j + 1) + 94 | self.isBomb(i, j - 1) + 95 | self.isBomb(i + 1, j + 1) + 96 | self.isBomb(i + 1, j - 1) + 97 | self.isBomb(i + 1, j) + 98 | self.isBomb(i - 1, j) + 99 | self.isBomb(i - 1, j + 1) + 100 | self.isBomb(i - 1, j - 1); 101 | 102 | if grid.number == 0 then 103 | self.expand(i, j + 1) 104 | self.expand(i, j - 1) 105 | self.expand(i + 1, j) 106 | self.expand(i - 1, j) 107 | end 108 | end 109 | end 110 | 111 | function GameLayer:handle_mouse_event(x, y, how, press) 112 | if self.gameover then return end 113 | 114 | local i = math.floor((480 - y) / 20 + 1) 115 | local j = math.floor(x / 20 + 1) 116 | if i >= 1 and i <= 24 and j >= 1 and j <= 24 then 117 | local grid = self.grids[i][j] 118 | if grid.isreveal then return end 119 | 120 | if how == Win32.WM_RBUTTONDOWN then 121 | grid.isflag = not grid.isflag 122 | elseif how == Win32.WM_LBUTTONDOWN then 123 | self.expand(i, j) 124 | end 125 | end 126 | end 127 | 128 | Game = Scene() 129 | Game.addLayer(GameLayer()) 130 | -------------------------------------------------------------------------------- /Bin/DS/class.lua: -------------------------------------------------------------------------------- 1 | function WrapMethod(self, f) 2 | return function(...) 3 | return f(self, ...) 4 | end 5 | end 6 | 7 | function Class(...) 8 | local class = {} 9 | local proto = {...} --lua5.2.3 10 | setmetatable(class, {__index = function(_, key) 11 | --disable __index 12 | for i = 1, #proto do 13 | local value = rawget(proto[i], key) 14 | if value then 15 | return value 16 | end 17 | end 18 | --enable __index 19 | for i = 1, #proto do 20 | local value = proto[i][key] 21 | if value then 22 | return value 23 | end 24 | end 25 | end, 26 | 27 | __call = function(_, ...) 28 | local obj = {} 29 | setmetatable(obj, {__index = function(self, key) 30 | local value = class[key] 31 | if type(value) == 'nil' then 32 | return value 33 | end 34 | 35 | if type(value) == 'function' then 36 | self[key] = WrapMethod(self, value) 37 | else 38 | self[key] = value 39 | end 40 | return self[key] 41 | end}) 42 | if class.__init__ then class.__init__(obj, ...) end 43 | return obj 44 | end}) 45 | return class 46 | end 47 | -------------------------------------------------------------------------------- /Bin/DS/queue.lua: -------------------------------------------------------------------------------- 1 | require 'ds.class' 2 | 3 | Queue = Class() 4 | 5 | function Queue:front() 6 | if self.head then 7 | return self.head.key 8 | end 9 | end 10 | 11 | function Queue:back() 12 | if self.tail then 13 | return self.tail.key 14 | end 15 | end 16 | 17 | function Queue:clear() 18 | self.head = nil 19 | self.tail = nil 20 | end 21 | 22 | function Queue:push_back(val) 23 | local item = {key = val} 24 | if self.tail then 25 | item.prev = self.tail 26 | self.tail.next = item 27 | self.tail = item 28 | else 29 | self.head = item 30 | self.tail = item 31 | end 32 | end 33 | 34 | function Queue:push_front(val) 35 | local item = {key = val} 36 | if self.head then 37 | self.head.prev = item 38 | item.next = self.head 39 | self.head = item 40 | else 41 | self.head = item 42 | self.tail = item 43 | end 44 | end 45 | 46 | function Queue:pop_back() 47 | if not self.tail then 48 | return 49 | end 50 | 51 | self.tail = self.tail.prev 52 | if not self.tail then 53 | self.head = nil 54 | else 55 | self.tail.next = nil 56 | end 57 | end 58 | 59 | function Queue:pop_front() 60 | if not self.head then return end 61 | 62 | self.head = self.head.next 63 | if not self.head then 64 | self.tail = nil 65 | else 66 | self.head.prev = nil 67 | end 68 | end 69 | 70 | function Queue:iterator() 71 | local item = self.head 72 | return function() 73 | if item then 74 | local prev = item 75 | item = prev.next 76 | return prev.key 77 | end 78 | end 79 | end 80 | 81 | function Queue:riterator() 82 | local item = self.tail 83 | return function() 84 | if item then 85 | local next = item 86 | item = next.prev 87 | return next.key 88 | end 89 | end 90 | end 91 | 92 | function Queue:remove(val) 93 | local item = self.head 94 | while item do 95 | if item.key == val then 96 | if item == self.head then 97 | self.head = item.next 98 | if not self.head then 99 | self.tail = nil 100 | else 101 | self.head.prev = nil 102 | end 103 | elseif item == self.tail then 104 | self.tail = item.prev 105 | self.tail.next = nil 106 | else 107 | item.next.prev = item.prev 108 | item.prev.next = item.next 109 | end 110 | break 111 | end 112 | item = item.next 113 | end 114 | end 115 | 116 | -------------------------------------------------------------------------------- /Bin/Dbgview.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Dbgview.exe -------------------------------------------------------------------------------- /Bin/Fairy2D.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Fairy2D.exe -------------------------------------------------------------------------------- /Bin/GL/define.lua: -------------------------------------------------------------------------------- 1 | Win32 = { 2 | VK_LEFT = 0x25, 3 | VK_RIGHT = 0x27, 4 | 5 | VK_UP = 0x26, 6 | VK_DOWN = 0x28, 7 | 8 | VK_RETURN = 0x0d, 9 | 10 | WM_KEYDOWN = 0x100, 11 | WM_KEYUP = 0x101, 12 | 13 | WM_LBUTTONDOWN = 0x0201, 14 | WM_RBUTTONDOWN = 0x0204, 15 | } 16 | 17 | GL_LINES = 0x0001 18 | GL_LINE_LOOP = 0x0002 19 | GL_LINE_STRIP = 0x0003 20 | GL_TRIANGLES = 0x0004 21 | GL_TRIANGLE_STRIP = 0x0005 22 | GL_TRIANGLE_FAN = 0x0006 23 | GL_QUADS = 0x0007 24 | GL_QUAD_STRIP = 0x0008 25 | 26 | GL_POINT_SMOOTH = 0x0B10 27 | GL_LINE_SMOOTH = 0x0B20 28 | 29 | GL_DONT_CARE = 0x1100 30 | GL_FASTEST = 0x1101 31 | GL_NICEST = 0x1102 32 | 33 | GL_BLEND = 0x0BE2 -------------------------------------------------------------------------------- /Bin/GL/matrix.lua: -------------------------------------------------------------------------------- 1 | require "ds.class" 2 | 3 | Matrix = Class() 4 | function Matrix:__init__() 5 | self.reset() 6 | end 7 | 8 | function Matrix:reset() 9 | local elemts = {} 10 | for i = 1, 16 do 11 | elemts[i] = 0 12 | end 13 | 14 | elemts[1] = 1 15 | elemts[6] = 1 16 | elemts[11] = 1 17 | elemts[16] = 1 18 | self.data = elemts 19 | end 20 | 21 | function Matrix:scale(scalex, scaley) 22 | local scale = Matrix() 23 | scale.data[1] = scalex 24 | scale.data[6] = scaley 25 | self.premultiply(scale) 26 | end 27 | 28 | function Matrix:rotate(degree) 29 | local rotate = Matrix() 30 | rotate.data[1] = cos(degree) 31 | rotate.data[2] = -sin(degree) 32 | rotate.data[5] = -rotate.data[2] 33 | rotate.data[6] = rotate[1] 34 | self.premultiply(rotate) 35 | end 36 | 37 | function Matrix:translate(deltax, deltay) 38 | local translate = Matrix() 39 | translate.data[4] = deltax 40 | translate.data[8] = deltay 41 | self.premultiply(translate) 42 | end 43 | 44 | function Matrix:orthoproject(width, height) 45 | self.reset() 46 | self.scale(2 / width, 2.0 / height) 47 | self.translate(-1, -1) 48 | end 49 | 50 | function Matrix:premultiply(mtx) 51 | local result = Matrix() 52 | 53 | local rdata = result.data 54 | local mdata = mtx.data 55 | local edata = self.data 56 | 57 | rdata[1] = mdata[1] * edata[1] + mdata[2] * edata[5] + mdata[3] * edata[9] + mdata[4] * edata[13] 58 | rdata[2] = mdata[1] * edata[2] + mdata[2] * edata[6] + mdata[3] * edata[10] + mdata[4] * edata[14] 59 | rdata[3] = mdata[1] * edata[3] + mdata[2] * edata[7] + mdata[3] * edata[11] + mdata[4] * edata[15] 60 | rdata[4] = mdata[1] * edata[4] + mdata[2] * edata[8] + mdata[3] * edata[12] + mdata[4] * edata[16] 61 | 62 | rdata[5] = mdata[5] * edata[1] + mdata[6] * edata[5] + mdata[7] * edata[9] + mdata[8] * edata[13] 63 | rdata[6] = mdata[5] * edata[2] + mdata[6] * edata[6] + mdata[7] * edata[10] + mdata[8] * edata[14] 64 | rdata[7] = mdata[5] * edata[3] + mdata[6] * edata[7] + mdata[7] * edata[11] + mdata[8] * edata[15] 65 | rdata[8] = mdata[5] * edata[4] + mdata[6] * edata[8] + mdata[7] * edata[12] + mdata[8] * edata[16] 66 | 67 | rdata[9] = mdata[9] * edata[1] + mdata[10] * edata[5] + mdata[11] * edata[9] + mdata[12] * edata[13] 68 | rdata[10] = mdata[9] * edata[2] + mdata[10] * edata[6] + mdata[11] * edata[10] + mdata[12] * edata[14] 69 | rdata[11] = mdata[9] * edata[3] + mdata[10] * edata[7] + mdata[11] * edata[11] + mdata[12] * edata[15] 70 | rdata[12] = mdata[9] * edata[4] + mdata[10] * edata[8] + mdata[11] * edata[12] + mdata[12] * edata[16] 71 | 72 | rdata[13] = mdata[13] * edata[1] + mdata[14] * edata[5] + mdata[15] * edata[9] + mdata[16] * edata[13] 73 | rdata[14] = mdata[13] * edata[2] + mdata[14] * edata[6] + mdata[15] * edata[10] + mdata[16] * edata[14] 74 | rdata[15] = mdata[13] * edata[3] + mdata[14] * edata[7] + mdata[15] * edata[11] + mdata[16] * edata[15] 75 | rdata[16] = mdata[13] * edata[4] + mdata[14] * edata[8] + mdata[15] * edata[12] + mdata[16] * edata[16] 76 | 77 | self.data = result.data 78 | end 79 | 80 | function Matrix:postmultiply(mtx) 81 | local result = Matrix() 82 | for i = 1, 16 do 83 | result.data[i] = mdata[i] 84 | end 85 | result.premultiply(self) 86 | self.data = result.data 87 | end -------------------------------------------------------------------------------- /Bin/GL/shader.lua: -------------------------------------------------------------------------------- 1 | texture_ucolor = { 2 | vertexshader = 3 | [[#version 330 4 | layout(location=0) in vec4 a_position; 5 | layout(location=1) in vec2 a_textureCoord; 6 | uniform mat4 MVP; 7 | varying vec2 v_texCoord; 8 | void main() 9 | { 10 | gl_Position = MVP * a_position; 11 | v_texCoord = a_textureCoord; 12 | } 13 | ]], 14 | 15 | fragshader = 16 | [[uniform sampler2D texture; 17 | uniform vec4 color; 18 | varying vec2 v_texCoord; 19 | void main() 20 | { 21 | gl_FragDepth = gl_FragCoord.z; 22 | gl_FragColor = texture2D(texture, v_texCoord) * color; 23 | } 24 | ]] 25 | } 26 | 27 | position_ucolor = { 28 | vertexshader = 29 | [[#version 330 30 | layout(location=0) in vec4 a_position; 31 | uniform mat4 MVP; 32 | void main() 33 | { 34 | gl_Position = MVP * a_position; 35 | } 36 | ]], 37 | 38 | fragshader = 39 | [[uniform vec4 color; 40 | void main() 41 | { 42 | gl_FragDepth = gl_FragCoord.z; 43 | gl_FragColor = color; 44 | } 45 | ]] 46 | 47 | } 48 | 49 | -------------------------------------------------------------------------------- /Bin/Net/json.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | Licensed according to the included 'LICENSE' document 3 | Author: Thomas Harning Jr 4 | ]] 5 | local decode = require("json.decode") 6 | local encode = require("json.encode") 7 | local util = require("json.util") 8 | 9 | local _G = _G 10 | 11 | local _ENV = nil 12 | 13 | local json = { 14 | _VERSION = "1.3.4", 15 | _DESCRIPTION = "LuaJSON : customizable JSON decoder/encoder", 16 | _COPYRIGHT = "Copyright (c) 2007-2014 Thomas Harning Jr. ", 17 | decode = decode, 18 | encode = encode, 19 | util = util 20 | } 21 | 22 | _G.json = json 23 | 24 | return json 25 | -------------------------------------------------------------------------------- /Bin/Net/json/decode.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | Licensed according to the included 'LICENSE' document 3 | Author: Thomas Harning Jr 4 | ]] 5 | local lpeg = require("lpeg") 6 | 7 | local error = error 8 | local pcall = pcall 9 | 10 | local jsonutil = require("json.util") 11 | local merge = jsonutil.merge 12 | local util = require("json.decode.util") 13 | 14 | local decode_state = require("json.decode.state") 15 | 16 | local setmetatable, getmetatable = setmetatable, getmetatable 17 | local assert = assert 18 | local ipairs, pairs = ipairs, pairs 19 | local string_char = require("string").char 20 | 21 | local type = type 22 | 23 | local require = require 24 | 25 | local _ENV = nil 26 | 27 | local modulesToLoad = { 28 | "composite", 29 | "strings", 30 | "number", 31 | "others" 32 | } 33 | local loadedModules = { 34 | } 35 | 36 | local json_decode = {} 37 | 38 | json_decode.default = { 39 | unicodeWhitespace = true, 40 | initialObject = false, 41 | nothrow = false 42 | } 43 | 44 | local modes_defined = { "default", "strict", "simple" } 45 | 46 | json_decode.simple = {} 47 | 48 | json_decode.strict = { 49 | unicodeWhitespace = true, 50 | initialObject = true, 51 | nothrow = false 52 | } 53 | 54 | for _,name in ipairs(modulesToLoad) do 55 | local mod = require("json.decode." .. name) 56 | if mod.mergeOptions then 57 | for _, mode in pairs(modes_defined) do 58 | mod.mergeOptions(json_decode[mode], mode) 59 | end 60 | end 61 | loadedModules[#loadedModules + 1] = mod 62 | end 63 | 64 | -- Shift over default into defaultOptions to permit build optimization 65 | local defaultOptions = json_decode.default 66 | json_decode.default = nil 67 | 68 | local function generateDecoder(lexer, options) 69 | -- Marker to permit detection of final end 70 | local marker = {} 71 | local parser = lpeg.Ct((options.ignored * lexer)^0 * lpeg.Cc(marker)) * options.ignored * (lpeg.P(-1) + util.unexpected()) 72 | local decoder = function(data) 73 | local state = decode_state.create(options) 74 | local parsed = parser:match(data) 75 | assert(parsed, "Invalid JSON data") 76 | local i = 0 77 | while true do 78 | i = i + 1 79 | local item = parsed[i] 80 | if item == marker then break end 81 | if type(item) == 'function' and item ~= jsonutil.undefined and item ~= jsonutil.null then 82 | item(state) 83 | else 84 | state:set_value(item) 85 | end 86 | end 87 | if options.initialObject then 88 | assert(type(state.previous) == 'table', "Initial value not an object or array") 89 | end 90 | -- Make sure stack is empty 91 | assert(state.i == 0, "Unclosed elements present") 92 | return state.previous 93 | end 94 | if options.nothrow then 95 | return function(data) 96 | local status, rv = pcall(decoder, data) 97 | if status then 98 | return rv 99 | else 100 | return nil, rv 101 | end 102 | end 103 | end 104 | return decoder 105 | end 106 | 107 | local function buildDecoder(mode) 108 | mode = mode and merge({}, defaultOptions, mode) or defaultOptions 109 | for _, mod in ipairs(loadedModules) do 110 | if mod.mergeOptions then 111 | mod.mergeOptions(mode) 112 | end 113 | end 114 | local ignored = mode.unicodeWhitespace and util.unicode_ignored or util.ascii_ignored 115 | -- Store 'ignored' in the global options table 116 | mode.ignored = ignored 117 | 118 | --local grammar = { 119 | -- [1] = mode.initialObject and (ignored * (object_type + array_type)) or value_type 120 | --} 121 | local lexer 122 | for _, mod in ipairs(loadedModules) do 123 | local new_lexer = mod.generateLexer(mode) 124 | lexer = lexer and lexer + new_lexer or new_lexer 125 | end 126 | return generateDecoder(lexer, mode) 127 | end 128 | 129 | -- Since 'default' is nil, we cannot take map it 130 | local defaultDecoder = buildDecoder(json_decode.default) 131 | local prebuilt_decoders = {} 132 | for _, mode in pairs(modes_defined) do 133 | if json_decode[mode] ~= nil then 134 | prebuilt_decoders[json_decode[mode]] = buildDecoder(json_decode[mode]) 135 | end 136 | end 137 | 138 | --[[ 139 | Options: 140 | number => number decode options 141 | string => string decode options 142 | array => array decode options 143 | object => object decode options 144 | initialObject => whether or not to require the initial object to be a table/array 145 | allowUndefined => whether or not to allow undefined values 146 | ]] 147 | local function getDecoder(mode) 148 | mode = mode == true and json_decode.strict or mode or json_decode.default 149 | local decoder = mode == nil and defaultDecoder or prebuilt_decoders[mode] 150 | if decoder then 151 | return decoder 152 | end 153 | return buildDecoder(mode) 154 | end 155 | 156 | local function decode(data, mode) 157 | local decoder = getDecoder(mode) 158 | return decoder(data) 159 | end 160 | 161 | local mt = {} 162 | mt.__call = function(self, ...) 163 | return decode(...) 164 | end 165 | 166 | json_decode.getDecoder = getDecoder 167 | json_decode.decode = decode 168 | json_decode.util = util 169 | setmetatable(json_decode, mt) 170 | 171 | return json_decode 172 | -------------------------------------------------------------------------------- /Bin/Net/json/decode/number.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | Licensed according to the included 'LICENSE' document 3 | Author: Thomas Harning Jr 4 | ]] 5 | local lpeg = require("lpeg") 6 | local tonumber = tonumber 7 | local jsonutil = require("json.util") 8 | local merge = jsonutil.merge 9 | local util = require("json.decode.util") 10 | 11 | local _ENV = nil 12 | 13 | local digit = lpeg.R("09") 14 | local digits = digit^1 15 | 16 | -- Illegal octal declaration 17 | local illegal_octal_detect = #(lpeg.P('0') * digits) * util.denied("Octal numbers") 18 | 19 | local int = (lpeg.P('-') + 0) * (lpeg.R("19") * digits + illegal_octal_detect + digit) 20 | 21 | local frac = lpeg.P('.') * digits 22 | 23 | local exp = lpeg.S("Ee") * (lpeg.S("-+") + 0) * digits 24 | 25 | local nan = lpeg.S("Nn") * lpeg.S("Aa") * lpeg.S("Nn") 26 | local inf = lpeg.S("Ii") * lpeg.P("nfinity") 27 | local ninf = lpeg.P('-') * lpeg.S("Ii") * lpeg.P("nfinity") 28 | local hex = (lpeg.P("0x") + lpeg.P("0X")) * lpeg.R("09","AF","af")^1 29 | 30 | local defaultOptions = { 31 | nan = true, 32 | inf = true, 33 | frac = true, 34 | exp = true, 35 | hex = false 36 | } 37 | 38 | local modeOptions = {} 39 | 40 | modeOptions.strict = { 41 | nan = false, 42 | inf = false 43 | } 44 | 45 | local nan_value = 0/0 46 | local inf_value = 1/0 47 | local ninf_value = -1/0 48 | 49 | --[[ 50 | Options: configuration options for number rules 51 | nan: match NaN 52 | inf: match Infinity 53 | frac: match fraction portion (.0) 54 | exp: match exponent portion (e1) 55 | DEFAULT: nan, inf, frac, exp 56 | ]] 57 | local function mergeOptions(options, mode) 58 | jsonutil.doOptionMerge(options, false, 'number', defaultOptions, mode and modeOptions[mode]) 59 | end 60 | 61 | local function generateLexer(options) 62 | options = options.number 63 | local ret = int 64 | if options.frac then 65 | ret = ret * (frac + 0) 66 | else 67 | ret = ret * (#frac * util.denied("Fractions", "number.frac") + 0) 68 | end 69 | if options.exp then 70 | ret = ret * (exp + 0) 71 | else 72 | ret = ret * (#exp * util.denied("Exponents", "number.exp") + 0) 73 | end 74 | if options.hex then 75 | ret = hex + ret 76 | else 77 | ret = #hex * util.denied("Hexadecimal", "number.hex") + ret 78 | end 79 | -- Capture number now 80 | ret = ret / tonumber 81 | if options.nan then 82 | ret = ret + nan / function() return nan_value end 83 | else 84 | ret = ret + #nan * util.denied("NaN", "number.nan") 85 | end 86 | if options.inf then 87 | ret = ret + ninf / function() return ninf_value end + inf / function() return inf_value end 88 | else 89 | ret = ret + (#ninf + #inf) * util.denied("+/-Inf", "number.inf") 90 | end 91 | return ret 92 | end 93 | 94 | local number = { 95 | int = int, 96 | mergeOptions = mergeOptions, 97 | generateLexer = generateLexer 98 | } 99 | 100 | return number 101 | -------------------------------------------------------------------------------- /Bin/Net/json/decode/others.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | Licensed according to the included 'LICENSE' document 3 | Author: Thomas Harning Jr 4 | ]] 5 | local lpeg = require("lpeg") 6 | local jsonutil = require("json.util") 7 | local merge = jsonutil.merge 8 | local util = require("json.decode.util") 9 | 10 | -- Container module for other JavaScript types (bool, null, undefined) 11 | 12 | local _ENV = nil 13 | 14 | -- For null and undefined, use the util.null value to preserve null-ness 15 | local booleanCapture = 16 | lpeg.P("true") * lpeg.Cc(true) 17 | + lpeg.P("false") * lpeg.Cc(false) 18 | 19 | local nullCapture = lpeg.P("null") 20 | local undefinedCapture = lpeg.P("undefined") 21 | 22 | local defaultOptions = { 23 | allowUndefined = true, 24 | null = jsonutil.null, 25 | undefined = jsonutil.undefined 26 | } 27 | 28 | local modeOptions = {} 29 | 30 | modeOptions.simple = { 31 | null = false, -- Mapped to nil 32 | undefined = false -- Mapped to nil 33 | } 34 | modeOptions.strict = { 35 | allowUndefined = false 36 | } 37 | 38 | local function mergeOptions(options, mode) 39 | jsonutil.doOptionMerge(options, false, 'others', defaultOptions, mode and modeOptions[mode]) 40 | end 41 | 42 | local function generateLexer(options) 43 | -- The 'or nil' clause allows false to map to a nil value since 'nil' cannot be merged 44 | options = options.others 45 | local valueCapture = ( 46 | booleanCapture 47 | + nullCapture * lpeg.Cc(options.null or nil) 48 | ) 49 | if options.allowUndefined then 50 | valueCapture = valueCapture + undefinedCapture * lpeg.Cc(options.undefined or nil) 51 | else 52 | valueCapture = valueCapture + #undefinedCapture * util.denied("undefined", "others.allowUndefined") 53 | end 54 | return valueCapture 55 | end 56 | 57 | local others = { 58 | mergeOptions = mergeOptions, 59 | generateLexer = generateLexer 60 | } 61 | 62 | return others 63 | -------------------------------------------------------------------------------- /Bin/Net/json/decode/state.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | Licensed according to the included 'LICENSE' document 3 | Author: Thomas Harning Jr 4 | ]] 5 | 6 | local setmetatable = setmetatable 7 | local jsonutil = require("json.util") 8 | local assert = assert 9 | local type = type 10 | local next = next 11 | local unpack = unpack 12 | 13 | local _ENV = nil 14 | 15 | local state_ops = {} 16 | local state_mt = { 17 | __index = state_ops 18 | } 19 | 20 | function state_ops.pop(self) 21 | self.previous_set = true 22 | self.previous = self.active 23 | local i = self.i 24 | -- Load in this array into the active item 25 | self.active = self.stack[i] 26 | self.active_state = self.state_stack[i] 27 | self.active_key = self.key_stack[i] 28 | self.stack[i] = nil 29 | self.state_stack[i] = nil 30 | self.key_stack[i] = nil 31 | 32 | self.i = i - 1 33 | end 34 | 35 | function state_ops.push(self) 36 | local i = self.i + 1 37 | self.i = i 38 | 39 | self.stack[i] = self.active 40 | self.state_stack[i] = self.active_state 41 | self.key_stack[i] = self.active_key 42 | end 43 | 44 | function state_ops.put_object_value(self, trailing) 45 | local object_options = self.options.object 46 | if trailing and object_options.trailingComma then 47 | if not self.active_key then 48 | return 49 | end 50 | end 51 | assert(self.active_key, "Missing key value") 52 | object_options.setObjectKey(self.active, self.active_key, self:grab_value()) 53 | self.active_key = nil 54 | end 55 | 56 | function state_ops.put_array_value(self, trailing) 57 | -- Safety check 58 | if trailing and not self.previous_set and self.options.array.trailingComma then 59 | return 60 | end 61 | local new_index = self.active_state + 1 62 | self.active_state = new_index 63 | self.active[new_index] = self:grab_value() 64 | end 65 | 66 | function state_ops.put_value(self, trailing) 67 | if self.active_state == 'object' then 68 | self:put_object_value(trailing) 69 | else 70 | self:put_array_value(trailing) 71 | end 72 | end 73 | 74 | function state_ops.new_array(self) 75 | local new_array = {} 76 | if jsonutil.InitArray then 77 | new_array = jsonutil.InitArray(new_array) or new_array 78 | end 79 | self.active = new_array 80 | self.active_state = 0 81 | self.active_key = nil 82 | self:unset_value() 83 | end 84 | 85 | function state_ops.end_array(self) 86 | if self.previous_set or self.active_state ~= 0 then 87 | -- Not an empty array 88 | self:put_value(true) 89 | end 90 | if self.active_state ~= #self.active then 91 | -- Store the length in 92 | self.active.n = self.active_state 93 | end 94 | end 95 | 96 | function state_ops.new_object(self) 97 | local new_object = {} 98 | self.active = new_object 99 | self.active_state = 'object' 100 | self.active_key = nil 101 | self:unset_value() 102 | end 103 | 104 | function state_ops.end_object(self) 105 | if self.previous_set or next(self.active) then 106 | -- Not an empty object 107 | self:put_value(true) 108 | end 109 | end 110 | 111 | function state_ops.new_call(self, name, func) 112 | -- TODO setup properly 113 | local new_call = {} 114 | new_call.name = name 115 | new_call.func = func 116 | self.active = new_call 117 | self.active_state = 0 118 | self.active_key = nil 119 | self:unset_value() 120 | end 121 | 122 | function state_ops.end_call(self) 123 | if self.previous_set or self.active_state ~= 0 then 124 | -- Not an empty array 125 | self:put_value(true) 126 | end 127 | if self.active_state ~= #self.active then 128 | -- Store the length in 129 | self.active.n = self.active_state 130 | end 131 | local func = self.active.func 132 | if func == true then 133 | func = jsonutil.buildCall 134 | end 135 | self.active = func(self.active.name, unpack(self.active, 1, self.active.n or #self.active)) 136 | end 137 | 138 | 139 | function state_ops.unset_value(self) 140 | self.previous_set = false 141 | self.previous = nil 142 | end 143 | 144 | function state_ops.grab_value(self) 145 | assert(self.previous_set, "Previous value not set") 146 | self.previous_set = false 147 | return self.previous 148 | end 149 | 150 | function state_ops.set_value(self, value) 151 | assert(not self.previous_set, "Value set when one already in slot") 152 | self.previous_set = true 153 | self.previous = value 154 | end 155 | 156 | function state_ops.set_key(self) 157 | assert(self.active_state == 'object', "Cannot set key on array") 158 | local value = self:grab_value() 159 | local value_type = type(value) 160 | if self.options.object.number then 161 | assert(value_type == 'string' or value_type == 'number', "As configured, a key must be a number or string") 162 | else 163 | assert(value_type == 'string', "As configured, a key must be a string") 164 | end 165 | self.active_key = value 166 | end 167 | 168 | 169 | local function create(options) 170 | local ret = { 171 | options = options, 172 | stack = {}, 173 | state_stack = {}, 174 | key_stack = {}, 175 | i = 0, 176 | active = nil, 177 | active_key = nil, 178 | previous = nil, 179 | active_state = nil 180 | 181 | } 182 | return setmetatable(ret, state_mt) 183 | end 184 | 185 | local state = { 186 | create = create 187 | } 188 | 189 | return state 190 | -------------------------------------------------------------------------------- /Bin/Net/json/decode/strings.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | Licensed according to the included 'LICENSE' document 3 | Author: Thomas Harning Jr 4 | ]] 5 | local lpeg = require("lpeg") 6 | local jsonutil = require("json.util") 7 | local util = require("json.decode.util") 8 | local merge = jsonutil.merge 9 | 10 | local tonumber = tonumber 11 | local string_char = require("string").char 12 | local floor = require("math").floor 13 | local table_concat = require("table").concat 14 | 15 | local error = error 16 | 17 | local _ENV = nil 18 | 19 | local function get_error(item) 20 | local fmt_string = item .. " in string [%q] @ %i:%i" 21 | return lpeg.P(function(data, index) 22 | local line, line_index, bad_char, last_line = util.get_invalid_character_info(data, index) 23 | local err = fmt_string:format(bad_char, line, line_index) 24 | error(err) 25 | end) * 1 26 | end 27 | 28 | local bad_unicode = get_error("Illegal unicode escape") 29 | local bad_hex = get_error("Illegal hex escape") 30 | local bad_character = get_error("Illegal character") 31 | local bad_escape = get_error("Illegal escape") 32 | 33 | local knownReplacements = { 34 | ["'"] = "'", 35 | ['"'] = '"', 36 | ['\\'] = '\\', 37 | ['/'] = '/', 38 | b = '\b', 39 | f = '\f', 40 | n = '\n', 41 | r = '\r', 42 | t = '\t', 43 | v = '\v', 44 | z = '\z' 45 | } 46 | 47 | -- according to the table at http://da.wikipedia.org/wiki/UTF-8 48 | local function utf8DecodeUnicode(code1, code2) 49 | code1, code2 = tonumber(code1, 16), tonumber(code2, 16) 50 | if code1 == 0 and code2 < 0x80 then 51 | return string_char(code2) 52 | end 53 | if code1 < 0x08 then 54 | return string_char( 55 | 0xC0 + code1 * 4 + floor(code2 / 64), 56 | 0x80 + code2 % 64) 57 | end 58 | return string_char( 59 | 0xE0 + floor(code1 / 16), 60 | 0x80 + (code1 % 16) * 4 + floor(code2 / 64), 61 | 0x80 + code2 % 64) 62 | end 63 | 64 | local function decodeX(code) 65 | code = tonumber(code, 16) 66 | return string_char(code) 67 | end 68 | 69 | local doSimpleSub = lpeg.C(lpeg.S("'\"\\/bfnrtvz")) / knownReplacements 70 | local doUniSub = lpeg.P('u') * (lpeg.C(util.hexpair) * lpeg.C(util.hexpair) + bad_unicode) 71 | local doXSub = lpeg.P('x') * (lpeg.C(util.hexpair) + bad_hex) 72 | 73 | local defaultOptions = { 74 | badChars = '', 75 | additionalEscapes = false, -- disallow untranslated escapes 76 | escapeCheck = #lpeg.S('bfnrtv/\\"xu\'z'), -- no check on valid characters 77 | decodeUnicode = utf8DecodeUnicode, 78 | strict_quotes = false 79 | } 80 | 81 | local modeOptions = {} 82 | 83 | modeOptions.strict = { 84 | badChars = '\b\f\n\r\t\v', 85 | additionalEscapes = false, -- no additional escapes 86 | escapeCheck = #lpeg.S('bfnrtv/\\"u'), --only these chars are allowed to be escaped 87 | strict_quotes = true 88 | } 89 | 90 | local function mergeOptions(options, mode) 91 | jsonutil.doOptionMerge(options, false, 'strings', defaultOptions, mode and modeOptions[mode]) 92 | end 93 | 94 | local function buildCaptureString(quote, badChars, escapeMatch) 95 | local captureChar = (1 - lpeg.S("\\" .. badChars .. quote)) + (lpeg.P("\\") / "" * escapeMatch) 96 | -- During error, force end 97 | local captureString = captureChar^0 + (-#lpeg.P(quote) * bad_character + -1) 98 | return lpeg.P(quote) * lpeg.Cs(captureString) * lpeg.P(quote) 99 | end 100 | 101 | local function generateLexer(options) 102 | options = options.strings 103 | local quotes = { '"' } 104 | if not options.strict_quotes then 105 | quotes[#quotes + 1] = "'" 106 | end 107 | local escapeMatch = doSimpleSub 108 | escapeMatch = escapeMatch + doXSub / decodeX 109 | escapeMatch = escapeMatch + doUniSub / options.decodeUnicode 110 | if options.additionalEscapes then 111 | escapeMatch = escapeMatch + options.additionalEscapes 112 | end 113 | if options.escapeCheck then 114 | escapeMatch = options.escapeCheck * escapeMatch + bad_escape 115 | end 116 | local captureString 117 | for i = 1, #quotes do 118 | local cap = buildCaptureString(quotes[i], options.badChars, escapeMatch) 119 | if captureString == nil then 120 | captureString = cap 121 | else 122 | captureString = captureString + cap 123 | end 124 | end 125 | return captureString 126 | end 127 | 128 | local strings = { 129 | mergeOptions = mergeOptions, 130 | generateLexer = generateLexer 131 | } 132 | 133 | return strings 134 | -------------------------------------------------------------------------------- /Bin/Net/json/decode/util.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | Licensed according to the included 'LICENSE' document 3 | Author: Thomas Harning Jr 4 | ]] 5 | local lpeg = require("lpeg") 6 | local select = select 7 | local pairs, ipairs = pairs, ipairs 8 | local tonumber = tonumber 9 | local string_char = require("string").char 10 | local rawset = rawset 11 | local jsonutil = require("json.util") 12 | 13 | local error = error 14 | local setmetatable = setmetatable 15 | 16 | local table_concat = require("table").concat 17 | 18 | local merge = require("json.util").merge 19 | 20 | local _ENV = nil 21 | 22 | local function get_invalid_character_info(input, index) 23 | local parsed = input:sub(1, index) 24 | local bad_character = input:sub(index, index) 25 | local _, line_number = parsed:gsub('\n',{}) 26 | local last_line = parsed:match("\n([^\n]+.)$") or parsed 27 | return line_number, #last_line, bad_character, last_line 28 | end 29 | 30 | local function build_report(msg) 31 | local fmt = msg:gsub("%%", "%%%%") .. " @ character: %i %i:%i [%s] line:\n%s" 32 | return lpeg.P(function(data, pos) 33 | local line, line_index, bad_char, last_line = get_invalid_character_info(data, pos) 34 | local text = fmt:format(pos, line, line_index, bad_char, last_line) 35 | error(text) 36 | end) * 1 37 | end 38 | local function unexpected() 39 | local msg = "unexpected character" 40 | return build_report(msg) 41 | end 42 | local function expected(...) 43 | local items = {...} 44 | local msg 45 | if #items > 1 then 46 | msg = "expected one of '" .. table_concat(items, "','") .. "'" 47 | else 48 | msg = "expected '" .. items[1] .. "'" 49 | end 50 | return build_report(msg) 51 | end 52 | local function denied(item, option) 53 | local msg 54 | if option then 55 | msg = ("'%s' denied by option set '%s'"):format(item, option) 56 | else 57 | msg = ("'%s' denied"):format(item) 58 | end 59 | return build_report(msg) 60 | end 61 | 62 | -- 09, 0A, 0B, 0C, 0D, 20 63 | local ascii_space = lpeg.S("\t\n\v\f\r ") 64 | local unicode_space 65 | do 66 | local chr = string_char 67 | local u_space = ascii_space 68 | -- \u0085 \u00A0 69 | u_space = u_space + lpeg.P(chr(0xC2)) * lpeg.S(chr(0x85) .. chr(0xA0)) 70 | -- \u1680 \u180E 71 | u_space = u_space + lpeg.P(chr(0xE1)) * (lpeg.P(chr(0x9A, 0x80)) + chr(0xA0, 0x8E)) 72 | -- \u2000 - \u200A, also 200B 73 | local spacing_end = "" 74 | for i = 0x80,0x8b do 75 | spacing_end = spacing_end .. chr(i) 76 | end 77 | -- \u2028 \u2029 \u202F 78 | spacing_end = spacing_end .. chr(0xA8) .. chr(0xA9) .. chr(0xAF) 79 | u_space = u_space + lpeg.P(chr(0xE2, 0x80)) * lpeg.S(spacing_end) 80 | -- \u205F 81 | u_space = u_space + lpeg.P(chr(0xE2, 0x81, 0x9F)) 82 | -- \u3000 83 | u_space = u_space + lpeg.P(chr(0xE3, 0x80, 0x80)) 84 | -- BOM \uFEFF 85 | u_space = u_space + lpeg.P(chr(0xEF, 0xBB, 0xBF)) 86 | unicode_space = u_space 87 | end 88 | 89 | local identifier = lpeg.R("AZ","az","__") * lpeg.R("AZ","az", "__", "09") ^0 90 | 91 | local hex = lpeg.R("09","AF","af") 92 | local hexpair = hex * hex 93 | 94 | local comments = { 95 | cpp = lpeg.P("//") * (1 - lpeg.P("\n"))^0 * lpeg.P("\n"), 96 | c = lpeg.P("/*") * (1 - lpeg.P("*/"))^0 * lpeg.P("*/") 97 | } 98 | 99 | local comment = comments.cpp + comments.c 100 | 101 | local ascii_ignored = (ascii_space + comment)^0 102 | 103 | local unicode_ignored = (unicode_space + comment)^0 104 | 105 | -- Parse the lpeg version skipping patch-values 106 | -- LPEG <= 0.7 have no version value... so 0.7 is value 107 | local DecimalLpegVersion = lpeg.version and tonumber(lpeg.version():match("^(%d+%.%d+)")) or 0.7 108 | 109 | local function setObjectKeyForceNumber(t, key, value) 110 | key = tonumber(key) or key 111 | return rawset(t, key, value) 112 | end 113 | 114 | local util = { 115 | unexpected = unexpected, 116 | expected = expected, 117 | denied = denied, 118 | ascii_space = ascii_space, 119 | unicode_space = unicode_space, 120 | identifier = identifier, 121 | hex = hex, 122 | hexpair = hexpair, 123 | comments = comments, 124 | comment = comment, 125 | ascii_ignored = ascii_ignored, 126 | unicode_ignored = unicode_ignored, 127 | DecimalLpegVersion = DecimalLpegVersion, 128 | get_invalid_character_info = get_invalid_character_info, 129 | setObjectKeyForceNumber = setObjectKeyForceNumber 130 | } 131 | 132 | return util 133 | -------------------------------------------------------------------------------- /Bin/Net/json/encode/array.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | Licensed according to the included 'LICENSE' document 3 | Author: Thomas Harning Jr 4 | ]] 5 | local jsonutil = require("json.util") 6 | 7 | local type = type 8 | local pairs = pairs 9 | local assert = assert 10 | 11 | local table = require("table") 12 | local math = require("math") 13 | local table_concat = table.concat 14 | local math_floor, math_modf = math.floor, math.modf 15 | 16 | local jsonutil = require("json.util") 17 | local util_IsArray = jsonutil.IsArray 18 | 19 | local _ENV = nil 20 | 21 | local defaultOptions = { 22 | isArray = util_IsArray 23 | } 24 | 25 | local modeOptions = {} 26 | 27 | local function mergeOptions(options, mode) 28 | jsonutil.doOptionMerge(options, false, 'array', defaultOptions, mode and modeOptions[mode]) 29 | end 30 | 31 | --[[ 32 | Utility function to determine whether a table is an array or not. 33 | Criteria for it being an array: 34 | * ExternalIsArray returns true (or false directly reports not-array) 35 | * If the table has an 'n' value that is an integer >= 1 then it 36 | is an array... may result in false positives (should check some values 37 | before it) 38 | * It is a contiguous list of values with zero string-based keys 39 | ]] 40 | local function isArray(val, options) 41 | local externalIsArray = options and options.isArray 42 | 43 | if externalIsArray then 44 | local ret = externalIsArray(val) 45 | if ret == true or ret == false then 46 | return ret 47 | end 48 | end 49 | -- Use the 'n' element if it's a number 50 | if type(val.n) == 'number' and math_floor(val.n) == val.n and val.n >= 1 then 51 | return true 52 | end 53 | local len = #val 54 | for k,v in pairs(val) do 55 | if type(k) ~= 'number' then 56 | return false 57 | end 58 | local _, decim = math_modf(k) 59 | if not (decim == 0 and 1<=k) then 60 | return false 61 | end 62 | if k > len then -- Use Lua's length as absolute determiner 63 | return false 64 | end 65 | end 66 | 67 | return true 68 | end 69 | 70 | --[[ 71 | Cleanup function to unmark a value as in the encoding process and return 72 | trailing results 73 | ]] 74 | local function unmarkAfterEncode(tab, state, ...) 75 | state.already_encoded[tab] = nil 76 | return ... 77 | end 78 | local function getEncoder(options) 79 | options = options and jsonutil.merge({}, defaultOptions, options) or defaultOptions 80 | local function encodeArray(tab, state) 81 | if not isArray(tab, options) then 82 | return false 83 | end 84 | -- Make sure this value hasn't been encoded yet 85 | state.check_unique(tab) 86 | local encode = state.encode 87 | local compositeEncoder = state.outputEncoder.composite 88 | local valueEncoder = [[ 89 | for i = 1, (composite.n or #composite) do 90 | local val = composite[i] 91 | PUTINNER(i ~= 1) 92 | val = encode(val, state) 93 | val = val or '' 94 | if val then 95 | PUTVALUE(val) 96 | end 97 | end 98 | ]] 99 | return unmarkAfterEncode(tab, state, compositeEncoder(valueEncoder, '[', ']', ',', tab, encode, state)) 100 | end 101 | return { table = encodeArray } 102 | end 103 | 104 | local array = { 105 | mergeOptions = mergeOptions, 106 | isArray = isArray, 107 | getEncoder = getEncoder 108 | } 109 | 110 | return array 111 | -------------------------------------------------------------------------------- /Bin/Net/json/encode/calls.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | Licensed according to the included 'LICENSE' document 3 | Author: Thomas Harning Jr 4 | ]] 5 | local table = require("table") 6 | local table_concat = table.concat 7 | 8 | local select = select 9 | local getmetatable, setmetatable = getmetatable, setmetatable 10 | local assert = assert 11 | 12 | local jsonutil = require("json.util") 13 | 14 | local isCall, decodeCall = jsonutil.isCall, jsonutil.decodeCall 15 | 16 | local _ENV = nil 17 | 18 | local defaultOptions = { 19 | } 20 | 21 | -- No real default-option handling needed... 22 | local modeOptions = {} 23 | 24 | local function mergeOptions(options, mode) 25 | jsonutil.doOptionMerge(options, false, 'calls', defaultOptions, mode and modeOptions[mode]) 26 | end 27 | 28 | 29 | --[[ 30 | Encodes 'value' as a function call 31 | Must have parameters in the 'callData' field of the metatable 32 | name == name of the function call 33 | parameters == array of parameters to encode 34 | ]] 35 | local function getEncoder(options) 36 | options = options and jsonutil.merge({}, defaultOptions, options) or defaultOptions 37 | local function encodeCall(value, state) 38 | if not isCall(value) then 39 | return false 40 | end 41 | local encode = state.encode 42 | local name, params = decodeCall(value) 43 | local compositeEncoder = state.outputEncoder.composite 44 | local valueEncoder = [[ 45 | for i = 1, (composite.n or #composite) do 46 | local val = composite[i] 47 | PUTINNER(i ~= 1) 48 | val = encode(val, state) 49 | val = val or '' 50 | if val then 51 | PUTVALUE(val) 52 | end 53 | end 54 | ]] 55 | return compositeEncoder(valueEncoder, name .. '(', ')', ',', params, encode, state) 56 | end 57 | return { 58 | table = encodeCall, 59 | ['function'] = encodeCall 60 | } 61 | end 62 | 63 | local calls = { 64 | mergeOptions = mergeOptions, 65 | getEncoder = getEncoder 66 | } 67 | 68 | return calls 69 | -------------------------------------------------------------------------------- /Bin/Net/json/encode/number.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | Licensed according to the included 'LICENSE' document 3 | Author: Thomas Harning Jr 4 | ]] 5 | local tostring = tostring 6 | local assert = assert 7 | local jsonutil = require("json.util") 8 | local huge = require("math").huge 9 | 10 | local _ENV = nil 11 | 12 | local defaultOptions = { 13 | nan = true, 14 | inf = true 15 | } 16 | 17 | local modeOptions = {} 18 | modeOptions.strict = { 19 | nan = false, 20 | inf = false 21 | } 22 | 23 | local function mergeOptions(options, mode) 24 | jsonutil.doOptionMerge(options, false, 'number', defaultOptions, mode and modeOptions[mode]) 25 | end 26 | 27 | 28 | local function encodeNumber(number, options) 29 | if number ~= number then 30 | assert(options.nan, "Invalid number: NaN not enabled") 31 | return "NaN" 32 | end 33 | if number == huge then 34 | assert(options.inf, "Invalid number: Infinity not enabled") 35 | return "Infinity" 36 | end 37 | if number == -huge then 38 | assert(options.inf, "Invalid number: Infinity not enabled") 39 | return "-Infinity" 40 | end 41 | return tostring(number) 42 | end 43 | 44 | local function getEncoder(options) 45 | options = options and jsonutil.merge({}, defaultOptions, options) or defaultOptions 46 | return { 47 | number = function(number, state) 48 | return encodeNumber(number, options) 49 | end 50 | } 51 | end 52 | 53 | local number = { 54 | mergeOptions = mergeOptions, 55 | getEncoder = getEncoder 56 | } 57 | 58 | return number 59 | -------------------------------------------------------------------------------- /Bin/Net/json/encode/object.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | Licensed according to the included 'LICENSE' document 3 | Author: Thomas Harning Jr 4 | ]] 5 | local pairs = pairs 6 | local assert = assert 7 | 8 | local type = type 9 | local tostring = tostring 10 | 11 | local table_concat = require("table").concat 12 | local jsonutil = require("json.util") 13 | 14 | local _ENV = nil 15 | 16 | local defaultOptions = { 17 | } 18 | 19 | local modeOptions = {} 20 | 21 | local function mergeOptions(options, mode) 22 | jsonutil.doOptionMerge(options, false, 'object', defaultOptions, mode and modeOptions[mode]) 23 | end 24 | 25 | --[[ 26 | Cleanup function to unmark a value as in the encoding process and return 27 | trailing results 28 | ]] 29 | local function unmarkAfterEncode(tab, state, ...) 30 | state.already_encoded[tab] = nil 31 | return ... 32 | end 33 | --[[ 34 | Encode a table as a JSON Object ( keys = strings, values = anything else ) 35 | ]] 36 | local function encodeTable(tab, options, state) 37 | -- Make sure this value hasn't been encoded yet 38 | state.check_unique(tab) 39 | local encode = state.encode 40 | local compositeEncoder = state.outputEncoder.composite 41 | local valueEncoder = [[ 42 | local first = true 43 | for k, v in pairs(composite) do 44 | local ti = type(k) 45 | assert(ti == 'string' or ti == 'number' or ti == 'boolean', "Invalid object index type: " .. ti) 46 | local name = encode(tostring(k), state, true) 47 | if first then 48 | first = false 49 | else 50 | name = ',' .. name 51 | end 52 | PUTVALUE(name .. ':') 53 | local val = encode(v, state) 54 | val = val or '' 55 | if val then 56 | PUTVALUE(val) 57 | end 58 | end 59 | ]] 60 | return unmarkAfterEncode(tab, state, compositeEncoder(valueEncoder, '{', '}', nil, tab, encode, state)) 61 | end 62 | 63 | local function getEncoder(options) 64 | options = options and jsonutil.merge({}, defaultOptions, options) or defaultOptions 65 | return { 66 | table = function(tab, state) 67 | return encodeTable(tab, options, state) 68 | end 69 | } 70 | end 71 | 72 | local object = { 73 | mergeOptions = mergeOptions, 74 | getEncoder = getEncoder 75 | } 76 | 77 | return object 78 | -------------------------------------------------------------------------------- /Bin/Net/json/encode/others.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | Licensed according to the included 'LICENSE' document 3 | Author: Thomas Harning Jr 4 | ]] 5 | local tostring = tostring 6 | 7 | local assert = assert 8 | local jsonutil = require("json.util") 9 | local type = type 10 | 11 | local _ENV = nil 12 | 13 | -- Shortcut that works 14 | local encodeBoolean = tostring 15 | 16 | local defaultOptions = { 17 | allowUndefined = true, 18 | null = jsonutil.null, 19 | undefined = jsonutil.undefined 20 | } 21 | 22 | local modeOptions = {} 23 | 24 | modeOptions.strict = { 25 | allowUndefined = false 26 | } 27 | 28 | local function mergeOptions(options, mode) 29 | jsonutil.doOptionMerge(options, false, 'others', defaultOptions, mode and modeOptions[mode]) 30 | end 31 | local function getEncoder(options) 32 | options = options and jsonutil.merge({}, defaultOptions, options) or defaultOptions 33 | local function encodeOthers(value, state) 34 | if value == options.null then 35 | return 'null' 36 | elseif value == options.undefined then 37 | assert(options.allowUndefined, "Invalid value: Unsupported 'Undefined' parameter") 38 | return 'undefined' 39 | else 40 | return false 41 | end 42 | end 43 | local function encodeBoolean(value, state) 44 | return value and 'true' or 'false' 45 | end 46 | local nullType = type(options.null) 47 | local undefinedType = options.undefined and type(options.undefined) 48 | -- Make sure that all of the types handled here are handled 49 | local ret = { 50 | boolean = encodeBoolean, 51 | ['nil'] = function() return 'null' end, 52 | [nullType] = encodeOthers 53 | } 54 | if undefinedType then 55 | ret[undefinedType] = encodeOthers 56 | end 57 | return ret 58 | end 59 | 60 | local others = { 61 | encodeBoolean = encodeBoolean, 62 | mergeOptions = mergeOptions, 63 | getEncoder = getEncoder 64 | } 65 | 66 | return others 67 | -------------------------------------------------------------------------------- /Bin/Net/json/encode/output.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | Licensed according to the included 'LICENSE' document 3 | Author: Thomas Harning Jr 4 | ]] 5 | local type = type 6 | local assert, error = assert, error 7 | local table_concat = require("table").concat 8 | local loadstring = loadstring or load 9 | 10 | local io = require("io") 11 | 12 | local setmetatable = setmetatable 13 | 14 | local output_utility = require("json.encode.output_utility") 15 | 16 | local _ENV = nil 17 | 18 | local tableCompositeCache = setmetatable({}, {__mode = 'v'}) 19 | 20 | local TABLE_VALUE_WRITER = [[ 21 | ret[#ret + 1] = %VALUE% 22 | ]] 23 | 24 | local TABLE_INNER_WRITER = "" 25 | 26 | --[[ 27 | nextValues can output a max of two values to throw into the data stream 28 | expected to be called until nil is first return value 29 | value separator should either be attached to v1 or in innerValue 30 | ]] 31 | local function defaultTableCompositeWriter(nextValues, beginValue, closeValue, innerValue, composite, encode, state) 32 | if type(nextValues) == 'string' then 33 | local fun = output_utility.prepareEncoder(defaultTableCompositeWriter, nextValues, innerValue, TABLE_VALUE_WRITER, TABLE_INNER_WRITER) 34 | local ret = {} 35 | fun(composite, ret, encode, state) 36 | return beginValue .. table_concat(ret, innerValue) .. closeValue 37 | end 38 | end 39 | 40 | -- no 'simple' as default action is just to return the value 41 | local function getDefault() 42 | return { composite = defaultTableCompositeWriter } 43 | end 44 | 45 | -- BEGIN IO-WRITER OUTPUT 46 | local IO_INNER_WRITER = [[ 47 | if %WRITE_INNER% then 48 | state.__outputFile:write(%INNER_VALUE%) 49 | end 50 | ]] 51 | local IO_VALUE_WRITER = [[ 52 | state.__outputFile:write(%VALUE%) 53 | ]] 54 | 55 | local function buildIoWriter(output) 56 | if not output then -- Default to stdout 57 | output = io.output() 58 | end 59 | local function ioWriter(nextValues, beginValue, closeValue, innerValue, composite, encode, state) 60 | -- HOOK OUTPUT STATE 61 | state.__outputFile = output 62 | if type(nextValues) == 'string' then 63 | local fun = output_utility.prepareEncoder(ioWriter, nextValues, innerValue, IO_VALUE_WRITER, IO_INNER_WRITER) 64 | local ret = {} 65 | output:write(beginValue) 66 | fun(composite, ret, encode, state) 67 | output:write(closeValue) 68 | return nil 69 | end 70 | end 71 | 72 | local function ioSimpleWriter(encoded) 73 | if encoded then 74 | output:write(encoded) 75 | end 76 | return nil 77 | end 78 | return { composite = ioWriter, simple = ioSimpleWriter } 79 | end 80 | local function getIoWriter(output) 81 | return function() 82 | return buildIoWriter(output) 83 | end 84 | end 85 | 86 | local output = { 87 | getDefault = getDefault, 88 | getIoWriter = getIoWriter 89 | } 90 | 91 | return output 92 | -------------------------------------------------------------------------------- /Bin/Net/json/encode/output_utility.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | Licensed according to the included 'LICENSE' document 3 | Author: Thomas Harning Jr 4 | ]] 5 | local setmetatable = setmetatable 6 | local assert, loadstring = assert, loadstring or load 7 | 8 | local _ENV = nil 9 | 10 | -- Key == weak, if main key goes away, then cache cleared 11 | local outputCache = setmetatable({}, {__mode = 'k'}) 12 | -- TODO: inner tables weak? 13 | 14 | local function buildFunction(nextValues, innerValue, valueWriter, innerWriter) 15 | local putInner = "" 16 | if innerValue and innerWriter then 17 | -- Prepare the lua-string representation of the separator to put in between values 18 | local formattedInnerValue = ("%q"):format(innerValue) 19 | -- Fill in the condition %WRITE_INNER% and the %INNER_VALUE% to actually write 20 | putInner = innerWriter:gsub("%%WRITE_INNER%%", "%%1"):gsub("%%INNER_VALUE%%", formattedInnerValue) 21 | end 22 | -- Template-in the value writer (if present) and its conditional argument 23 | local functionCode = nextValues:gsub("PUTINNER(%b())", putInner) 24 | -- %VALUE% is to be filled in by the value-to-write 25 | valueWriter = valueWriter:gsub("%%VALUE%%", "%%1") 26 | -- Template-in the value writer with its argument 27 | functionCode = functionCode:gsub("PUTVALUE(%b())", valueWriter) 28 | functionCode = [[ 29 | return function(composite, ret, encode, state) 30 | ]] .. functionCode .. [[ 31 | end 32 | ]] 33 | return assert(loadstring(functionCode))() 34 | end 35 | 36 | local function prepareEncoder(cacheKey, nextValues, innerValue, valueWriter, innerWriter) 37 | local cache = outputCache[cacheKey] 38 | if not cache then 39 | cache = {} 40 | outputCache[cacheKey] = cache 41 | end 42 | local fun = cache[nextValues] 43 | if not fun then 44 | fun = buildFunction(nextValues, innerValue, valueWriter, innerWriter) 45 | cache[nextValues] = fun 46 | end 47 | return fun 48 | end 49 | 50 | local output_utility = { 51 | prepareEncoder = prepareEncoder 52 | } 53 | 54 | return output_utility 55 | -------------------------------------------------------------------------------- /Bin/Net/json/encode/strings.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | Licensed according to the included 'LICENSE' document 3 | Author: Thomas Harning Jr 4 | ]] 5 | local string_char = require("string").char 6 | local pairs = pairs 7 | 8 | local jsonutil = require("json.util") 9 | local util_merge = jsonutil.merge 10 | 11 | local _ENV = nil 12 | 13 | local normalEncodingMap = { 14 | ['"'] = '\\"', 15 | ['\\'] = '\\\\', 16 | ['/'] = '\\/', 17 | ['\b'] = '\\b', 18 | ['\f'] = '\\f', 19 | ['\n'] = '\\n', 20 | ['\r'] = '\\r', 21 | ['\t'] = '\\t', 22 | ['\v'] = '\\v' -- not in official spec, on report, removing 23 | } 24 | 25 | local xEncodingMap = {} 26 | for char, encoded in pairs(normalEncodingMap) do 27 | xEncodingMap[char] = encoded 28 | end 29 | 30 | -- Pre-encode the control characters to speed up encoding... 31 | -- NOTE: UTF-8 may not work out right w/ JavaScript 32 | -- JavaScript uses 2 bytes after a \u... yet UTF-8 is a 33 | -- byte-stream encoding, not pairs of bytes (it does encode 34 | -- some letters > 1 byte, but base case is 1) 35 | for i = 0, 255 do 36 | local c = string_char(i) 37 | if c:match('[%z\1-\031\128-\255]') and not normalEncodingMap[c] then 38 | -- WARN: UTF8 specializes values >= 0x80 as parts of sequences... 39 | -- without \x encoding, do not allow encoding > 7F 40 | normalEncodingMap[c] = ('\\u%.4X'):format(i) 41 | xEncodingMap[c] = ('\\x%.2X'):format(i) 42 | end 43 | end 44 | 45 | local defaultOptions = { 46 | xEncode = false, -- Encode single-bytes as \xXX 47 | processor = nil, -- Simple processor for the string prior to quoting 48 | -- / is not required to be quoted but it helps with certain decoding 49 | -- Required encoded characters, " \, and 00-1F (0 - 31) 50 | encodeSet = '\\"/%z\1-\031', 51 | encodeSetAppend = nil -- Chars to append to the default set 52 | } 53 | 54 | local modeOptions = {} 55 | 56 | local function mergeOptions(options, mode) 57 | jsonutil.doOptionMerge(options, false, 'strings', defaultOptions, mode and modeOptions[mode]) 58 | end 59 | 60 | local function getEncoder(options) 61 | options = options and util_merge({}, defaultOptions, options) or defaultOptions 62 | local encodeSet = options.encodeSet 63 | if options.encodeSetAppend then 64 | encodeSet = encodeSet .. options.encodeSetAppend 65 | end 66 | local encodingMap = options.xEncode and xEncodingMap or normalEncodingMap 67 | local encodeString 68 | if options.processor then 69 | local processor = options.processor 70 | encodeString = function(s, state) 71 | return '"' .. processor(s:gsub('[' .. encodeSet .. ']', encodingMap)) .. '"' 72 | end 73 | else 74 | encodeString = function(s, state) 75 | return '"' .. s:gsub('[' .. encodeSet .. ']', encodingMap) .. '"' 76 | end 77 | end 78 | return { 79 | string = encodeString 80 | } 81 | end 82 | 83 | local strings = { 84 | mergeOptions = mergeOptions, 85 | getEncoder = getEncoder 86 | } 87 | 88 | return strings 89 | -------------------------------------------------------------------------------- /Bin/Net/json/util.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | Licensed according to the included 'LICENSE' document 3 | Author: Thomas Harning Jr 4 | ]] 5 | local type = type 6 | local print = print 7 | local tostring = tostring 8 | local pairs = pairs 9 | local getmetatable, setmetatable = getmetatable, setmetatable 10 | local select = select 11 | 12 | local _ENV = nil 13 | 14 | local function foreach(tab, func) 15 | for k, v in pairs(tab) do 16 | func(k,v) 17 | end 18 | end 19 | local function printValue(tab, name) 20 | local parsed = {} 21 | local function doPrint(key, value, space) 22 | space = space or '' 23 | if type(value) == 'table' then 24 | if parsed[value] then 25 | print(space .. key .. '= <' .. parsed[value] .. '>') 26 | else 27 | parsed[value] = key 28 | print(space .. key .. '= {') 29 | space = space .. ' ' 30 | foreach(value, function(key, value) doPrint(key, value, space) end) 31 | end 32 | else 33 | if type(value) == 'string' then 34 | value = '[[' .. tostring(value) .. ']]' 35 | end 36 | print(space .. key .. '=' .. tostring(value)) 37 | end 38 | end 39 | doPrint(name, tab) 40 | end 41 | 42 | local function clone(t) 43 | local ret = {} 44 | for k,v in pairs(t) do 45 | ret[k] = v 46 | end 47 | return ret 48 | end 49 | 50 | local function inner_merge(t, remaining, from, ...) 51 | if remaining == 0 then 52 | return t 53 | end 54 | if from then 55 | for k,v in pairs(from) do 56 | t[k] = v 57 | end 58 | end 59 | return inner_merge(t, remaining - 1, ...) 60 | end 61 | 62 | --[[* 63 | Shallow-merges tables in order onto the first table. 64 | 65 | @param t table to merge entries onto 66 | @param ... sequence of 0 or more tables to merge onto 't' 67 | 68 | @returns table 't' from input 69 | ]] 70 | local function merge(t, ...) 71 | return inner_merge(t, select('#', ...), ...) 72 | end 73 | 74 | -- Function to insert nulls into the JSON stream 75 | local function null() 76 | return null 77 | end 78 | 79 | -- Marker for 'undefined' values 80 | local function undefined() 81 | return undefined 82 | end 83 | 84 | local ArrayMT = {} 85 | 86 | --[[ 87 | Return's true if the metatable marks it as an array.. 88 | Or false if it has no array component at all 89 | Otherwise nil to get the normal detection component working 90 | ]] 91 | local function IsArray(value) 92 | if type(value) ~= 'table' then return false end 93 | local meta = getmetatable(value) 94 | local ret = meta == ArrayMT or (meta ~= nil and meta.__is_luajson_array) 95 | if not ret then 96 | if #value == 0 then return false end 97 | else 98 | return ret 99 | end 100 | end 101 | local function InitArray(array) 102 | setmetatable(array, ArrayMT) 103 | return array 104 | end 105 | 106 | local CallMT = {} 107 | 108 | local function isCall(value) 109 | return CallMT == getmetatable(value) 110 | end 111 | 112 | local function buildCall(name, ...) 113 | local callData = { 114 | name = name, 115 | parameters = {n = select('#', ...), ...} 116 | } 117 | return setmetatable(callData, CallMT) 118 | end 119 | 120 | local function decodeCall(callData) 121 | if not isCall(callData) then return nil end 122 | return callData.name, callData.parameters 123 | end 124 | 125 | local function doOptionMerge(options, nested, name, defaultOptions, modeOptions) 126 | if nested then 127 | modeOptions = modeOptions and modeOptions[name] 128 | defaultOptions = defaultOptions and defaultOptions[name] 129 | end 130 | options[name] = merge( 131 | {}, 132 | defaultOptions, 133 | modeOptions, 134 | options[name] 135 | ) 136 | end 137 | 138 | local json_util = { 139 | printValue = printValue, 140 | clone = clone, 141 | merge = merge, 142 | null = null, 143 | undefined = undefined, 144 | IsArray = IsArray, 145 | InitArray = InitArray, 146 | isCall = isCall, 147 | buildCall = buildCall, 148 | decodeCall = decodeCall, 149 | doOptionMerge = doOptionMerge 150 | } 151 | 152 | return json_util 153 | -------------------------------------------------------------------------------- /Bin/Net/lpeg.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Net/lpeg.dll -------------------------------------------------------------------------------- /Bin/Net/mime.lua: -------------------------------------------------------------------------------- 1 | ----------------------------------------------------------------------------- 2 | -- MIME support for the Lua language. 3 | -- Author: Diego Nehab 4 | -- Conforming to RFCs 2045-2049 5 | ----------------------------------------------------------------------------- 6 | 7 | ----------------------------------------------------------------------------- 8 | -- Declare module and import dependencies 9 | ----------------------------------------------------------------------------- 10 | local base = _G 11 | local ltn12 = require("ltn12") 12 | local mime = require("mime.core") 13 | local io = require("io") 14 | local string = require("string") 15 | local _M = mime 16 | 17 | -- encode, decode and wrap algorithm tables 18 | local encodet, decodet, wrapt = {},{},{} 19 | 20 | _M.encodet = encodet 21 | _M.decodet = decodet 22 | _M.wrapt = wrapt 23 | 24 | -- creates a function that chooses a filter by name from a given table 25 | local function choose(table) 26 | return function(name, opt1, opt2) 27 | if base.type(name) ~= "string" then 28 | name, opt1, opt2 = "default", name, opt1 29 | end 30 | local f = table[name or "nil"] 31 | if not f then 32 | base.error("unknown key (" .. base.tostring(name) .. ")", 3) 33 | else return f(opt1, opt2) end 34 | end 35 | end 36 | 37 | -- define the encoding filters 38 | encodet['base64'] = function() 39 | return ltn12.filter.cycle(_M.b64, "") 40 | end 41 | 42 | encodet['quoted-printable'] = function(mode) 43 | return ltn12.filter.cycle(_M.qp, "", 44 | (mode == "binary") and "=0D=0A" or "\r\n") 45 | end 46 | 47 | -- define the decoding filters 48 | decodet['base64'] = function() 49 | return ltn12.filter.cycle(_M.unb64, "") 50 | end 51 | 52 | decodet['quoted-printable'] = function() 53 | return ltn12.filter.cycle(_M.unqp, "") 54 | end 55 | 56 | local function format(chunk) 57 | if chunk then 58 | if chunk == "" then return "''" 59 | else return string.len(chunk) end 60 | else return "nil" end 61 | end 62 | 63 | -- define the line-wrap filters 64 | wrapt['text'] = function(length) 65 | length = length or 76 66 | return ltn12.filter.cycle(_M.wrp, length, length) 67 | end 68 | wrapt['base64'] = wrapt['text'] 69 | wrapt['default'] = wrapt['text'] 70 | 71 | wrapt['quoted-printable'] = function() 72 | return ltn12.filter.cycle(_M.qpwrp, 76, 76) 73 | end 74 | 75 | -- function that choose the encoding, decoding or wrap algorithm 76 | _M.encode = choose(encodet) 77 | _M.decode = choose(decodet) 78 | _M.wrap = choose(wrapt) 79 | 80 | -- define the end-of-line normalization filter 81 | function _M.normalize(marker) 82 | return ltn12.filter.cycle(_M.eol, 0, marker) 83 | end 84 | 85 | -- high level stuffing filter 86 | function _M.stuff() 87 | return ltn12.filter.cycle(_M.dot, 2) 88 | end 89 | 90 | return _M -------------------------------------------------------------------------------- /Bin/Net/mime/core.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Net/mime/core.dll -------------------------------------------------------------------------------- /Bin/Net/socket.lua: -------------------------------------------------------------------------------- 1 | ----------------------------------------------------------------------------- 2 | -- LuaSocket helper module 3 | -- Author: Diego Nehab 4 | ----------------------------------------------------------------------------- 5 | 6 | ----------------------------------------------------------------------------- 7 | -- Declare module and import dependencies 8 | ----------------------------------------------------------------------------- 9 | local base = _G 10 | local string = require("string") 11 | local math = require("math") 12 | local socket = require("socket.core") 13 | 14 | local _M = socket 15 | 16 | ----------------------------------------------------------------------------- 17 | -- Exported auxiliar functions 18 | ----------------------------------------------------------------------------- 19 | function _M.connect4(address, port, laddress, lport) 20 | return socket.connect(address, port, laddress, lport, "inet") 21 | end 22 | 23 | function _M.connect6(address, port, laddress, lport) 24 | return socket.connect(address, port, laddress, lport, "inet6") 25 | end 26 | 27 | function _M.bind(host, port, backlog) 28 | if host == "*" then host = "0.0.0.0" end 29 | local addrinfo, err = socket.dns.getaddrinfo(host); 30 | if not addrinfo then return nil, err end 31 | local sock, res 32 | err = "no info on address" 33 | for i, alt in base.ipairs(addrinfo) do 34 | if alt.family == "inet" then 35 | sock, err = socket.tcp() 36 | else 37 | sock, err = socket.tcp6() 38 | end 39 | if not sock then return nil, err end 40 | sock:setoption("reuseaddr", true) 41 | res, err = sock:bind(alt.addr, port) 42 | if not res then 43 | sock:close() 44 | else 45 | res, err = sock:listen(backlog) 46 | if not res then 47 | sock:close() 48 | else 49 | return sock 50 | end 51 | end 52 | end 53 | return nil, err 54 | end 55 | 56 | _M.try = _M.newtry() 57 | 58 | function _M.choose(table) 59 | return function(name, opt1, opt2) 60 | if base.type(name) ~= "string" then 61 | name, opt1, opt2 = "default", name, opt1 62 | end 63 | local f = table[name or "nil"] 64 | if not f then base.error("unknown key (".. base.tostring(name) ..")", 3) 65 | else return f(opt1, opt2) end 66 | end 67 | end 68 | 69 | ----------------------------------------------------------------------------- 70 | -- Socket sources and sinks, conforming to LTN12 71 | ----------------------------------------------------------------------------- 72 | -- create namespaces inside LuaSocket namespace 73 | local sourcet, sinkt = {}, {} 74 | _M.sourcet = sourcet 75 | _M.sinkt = sinkt 76 | 77 | _M.BLOCKSIZE = 2048 78 | 79 | sinkt["close-when-done"] = function(sock) 80 | return base.setmetatable({ 81 | getfd = function() return sock:getfd() end, 82 | dirty = function() return sock:dirty() end 83 | }, { 84 | __call = function(self, chunk, err) 85 | if not chunk then 86 | sock:close() 87 | return 1 88 | else return sock:send(chunk) end 89 | end 90 | }) 91 | end 92 | 93 | sinkt["keep-open"] = function(sock) 94 | return base.setmetatable({ 95 | getfd = function() return sock:getfd() end, 96 | dirty = function() return sock:dirty() end 97 | }, { 98 | __call = function(self, chunk, err) 99 | if chunk then return sock:send(chunk) 100 | else return 1 end 101 | end 102 | }) 103 | end 104 | 105 | sinkt["default"] = sinkt["keep-open"] 106 | 107 | _M.sink = _M.choose(sinkt) 108 | 109 | sourcet["by-length"] = function(sock, length) 110 | return base.setmetatable({ 111 | getfd = function() return sock:getfd() end, 112 | dirty = function() return sock:dirty() end 113 | }, { 114 | __call = function() 115 | if length <= 0 then return nil end 116 | local size = math.min(socket.BLOCKSIZE, length) 117 | local chunk, err = sock:receive(size) 118 | if err then return nil, err end 119 | length = length - string.len(chunk) 120 | return chunk 121 | end 122 | }) 123 | end 124 | 125 | sourcet["until-closed"] = function(sock) 126 | local done 127 | return base.setmetatable({ 128 | getfd = function() return sock:getfd() end, 129 | dirty = function() return sock:dirty() end 130 | }, { 131 | __call = function() 132 | if done then return nil end 133 | local chunk, err, partial = sock:receive(socket.BLOCKSIZE) 134 | if not err then return chunk 135 | elseif err == "closed" then 136 | sock:close() 137 | done = 1 138 | return partial 139 | else return nil, err end 140 | end 141 | }) 142 | end 143 | 144 | 145 | sourcet["default"] = sourcet["until-closed"] 146 | 147 | _M.source = _M.choose(sourcet) 148 | 149 | return _M 150 | -------------------------------------------------------------------------------- /Bin/Net/socket/core.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Net/socket/core.dll -------------------------------------------------------------------------------- /Bin/Net/socket/headers.lua: -------------------------------------------------------------------------------- 1 | ----------------------------------------------------------------------------- 2 | -- Canonic header field capitalization 3 | -- LuaSocket toolkit. 4 | -- Author: Diego Nehab 5 | ----------------------------------------------------------------------------- 6 | local socket = require("socket") 7 | socket.headers = {} 8 | local _M = socket.headers 9 | 10 | _M.canonic = { 11 | ["accept"] = "Accept", 12 | ["accept-charset"] = "Accept-Charset", 13 | ["accept-encoding"] = "Accept-Encoding", 14 | ["accept-language"] = "Accept-Language", 15 | ["accept-ranges"] = "Accept-Ranges", 16 | ["action"] = "Action", 17 | ["alternate-recipient"] = "Alternate-Recipient", 18 | ["age"] = "Age", 19 | ["allow"] = "Allow", 20 | ["arrival-date"] = "Arrival-Date", 21 | ["authorization"] = "Authorization", 22 | ["bcc"] = "Bcc", 23 | ["cache-control"] = "Cache-Control", 24 | ["cc"] = "Cc", 25 | ["comments"] = "Comments", 26 | ["connection"] = "Connection", 27 | ["content-description"] = "Content-Description", 28 | ["content-disposition"] = "Content-Disposition", 29 | ["content-encoding"] = "Content-Encoding", 30 | ["content-id"] = "Content-ID", 31 | ["content-language"] = "Content-Language", 32 | ["content-length"] = "Content-Length", 33 | ["content-location"] = "Content-Location", 34 | ["content-md5"] = "Content-MD5", 35 | ["content-range"] = "Content-Range", 36 | ["content-transfer-encoding"] = "Content-Transfer-Encoding", 37 | ["content-type"] = "Content-Type", 38 | ["cookie"] = "Cookie", 39 | ["date"] = "Date", 40 | ["diagnostic-code"] = "Diagnostic-Code", 41 | ["dsn-gateway"] = "DSN-Gateway", 42 | ["etag"] = "ETag", 43 | ["expect"] = "Expect", 44 | ["expires"] = "Expires", 45 | ["final-log-id"] = "Final-Log-ID", 46 | ["final-recipient"] = "Final-Recipient", 47 | ["from"] = "From", 48 | ["host"] = "Host", 49 | ["if-match"] = "If-Match", 50 | ["if-modified-since"] = "If-Modified-Since", 51 | ["if-none-match"] = "If-None-Match", 52 | ["if-range"] = "If-Range", 53 | ["if-unmodified-since"] = "If-Unmodified-Since", 54 | ["in-reply-to"] = "In-Reply-To", 55 | ["keywords"] = "Keywords", 56 | ["last-attempt-date"] = "Last-Attempt-Date", 57 | ["last-modified"] = "Last-Modified", 58 | ["location"] = "Location", 59 | ["max-forwards"] = "Max-Forwards", 60 | ["message-id"] = "Message-ID", 61 | ["mime-version"] = "MIME-Version", 62 | ["original-envelope-id"] = "Original-Envelope-ID", 63 | ["original-recipient"] = "Original-Recipient", 64 | ["pragma"] = "Pragma", 65 | ["proxy-authenticate"] = "Proxy-Authenticate", 66 | ["proxy-authorization"] = "Proxy-Authorization", 67 | ["range"] = "Range", 68 | ["received"] = "Received", 69 | ["received-from-mta"] = "Received-From-MTA", 70 | ["references"] = "References", 71 | ["referer"] = "Referer", 72 | ["remote-mta"] = "Remote-MTA", 73 | ["reply-to"] = "Reply-To", 74 | ["reporting-mta"] = "Reporting-MTA", 75 | ["resent-bcc"] = "Resent-Bcc", 76 | ["resent-cc"] = "Resent-Cc", 77 | ["resent-date"] = "Resent-Date", 78 | ["resent-from"] = "Resent-From", 79 | ["resent-message-id"] = "Resent-Message-ID", 80 | ["resent-reply-to"] = "Resent-Reply-To", 81 | ["resent-sender"] = "Resent-Sender", 82 | ["resent-to"] = "Resent-To", 83 | ["retry-after"] = "Retry-After", 84 | ["return-path"] = "Return-Path", 85 | ["sender"] = "Sender", 86 | ["server"] = "Server", 87 | ["smtp-remote-recipient"] = "SMTP-Remote-Recipient", 88 | ["status"] = "Status", 89 | ["subject"] = "Subject", 90 | ["te"] = "TE", 91 | ["to"] = "To", 92 | ["trailer"] = "Trailer", 93 | ["transfer-encoding"] = "Transfer-Encoding", 94 | ["upgrade"] = "Upgrade", 95 | ["user-agent"] = "User-Agent", 96 | ["vary"] = "Vary", 97 | ["via"] = "Via", 98 | ["warning"] = "Warning", 99 | ["will-retry-until"] = "Will-Retry-Until", 100 | ["www-authenticate"] = "WWW-Authenticate", 101 | ["x-mailer"] = "X-Mailer", 102 | } 103 | 104 | return _M -------------------------------------------------------------------------------- /Bin/Net/socket/tp.lua: -------------------------------------------------------------------------------- 1 | ----------------------------------------------------------------------------- 2 | -- Unified SMTP/FTP subsystem 3 | -- LuaSocket toolkit. 4 | -- Author: Diego Nehab 5 | ----------------------------------------------------------------------------- 6 | 7 | ----------------------------------------------------------------------------- 8 | -- Declare module and import dependencies 9 | ----------------------------------------------------------------------------- 10 | local base = _G 11 | local string = require("string") 12 | local socket = require("socket") 13 | local ltn12 = require("ltn12") 14 | 15 | socket.tp = {} 16 | local _M = socket.tp 17 | 18 | ----------------------------------------------------------------------------- 19 | -- Program constants 20 | ----------------------------------------------------------------------------- 21 | _M.TIMEOUT = 60 22 | 23 | ----------------------------------------------------------------------------- 24 | -- Implementation 25 | ----------------------------------------------------------------------------- 26 | -- gets server reply (works for SMTP and FTP) 27 | local function get_reply(c) 28 | local code, current, sep 29 | local line, err = c:receive() 30 | local reply = line 31 | if err then return nil, err end 32 | code, sep = socket.skip(2, string.find(line, "^(%d%d%d)(.?)")) 33 | if not code then return nil, "invalid server reply" end 34 | if sep == "-" then -- reply is multiline 35 | repeat 36 | line, err = c:receive() 37 | if err then return nil, err end 38 | current, sep = socket.skip(2, string.find(line, "^(%d%d%d)(.?)")) 39 | reply = reply .. "\n" .. line 40 | -- reply ends with same code 41 | until code == current and sep == " " 42 | end 43 | return code, reply 44 | end 45 | 46 | -- metatable for sock object 47 | local metat = { __index = {} } 48 | 49 | function metat.__index:check(ok) 50 | local code, reply = get_reply(self.c) 51 | if not code then return nil, reply end 52 | if base.type(ok) ~= "function" then 53 | if base.type(ok) == "table" then 54 | for i, v in base.ipairs(ok) do 55 | if string.find(code, v) then 56 | return base.tonumber(code), reply 57 | end 58 | end 59 | return nil, reply 60 | else 61 | if string.find(code, ok) then return base.tonumber(code), reply 62 | else return nil, reply end 63 | end 64 | else return ok(base.tonumber(code), reply) end 65 | end 66 | 67 | function metat.__index:command(cmd, arg) 68 | cmd = string.upper(cmd) 69 | if arg then 70 | return self.c:send(cmd .. " " .. arg.. "\r\n") 71 | else 72 | return self.c:send(cmd .. "\r\n") 73 | end 74 | end 75 | 76 | function metat.__index:sink(snk, pat) 77 | local chunk, err = c:receive(pat) 78 | return snk(chunk, err) 79 | end 80 | 81 | function metat.__index:send(data) 82 | return self.c:send(data) 83 | end 84 | 85 | function metat.__index:receive(pat) 86 | return self.c:receive(pat) 87 | end 88 | 89 | function metat.__index:getfd() 90 | return self.c:getfd() 91 | end 92 | 93 | function metat.__index:dirty() 94 | return self.c:dirty() 95 | end 96 | 97 | function metat.__index:getcontrol() 98 | return self.c 99 | end 100 | 101 | function metat.__index:source(source, step) 102 | local sink = socket.sink("keep-open", self.c) 103 | local ret, err = ltn12.pump.all(source, sink, step or ltn12.pump.step) 104 | return ret, err 105 | end 106 | 107 | -- closes the underlying c 108 | function metat.__index:close() 109 | self.c:close() 110 | return 1 111 | end 112 | 113 | -- connect with server and return c object 114 | function _M.connect(host, port, timeout, create) 115 | local c, e = (create or socket.tcp)() 116 | if not c then return nil, e end 117 | c:settimeout(timeout or _M.TIMEOUT) 118 | local r, e = c:connect(host, port) 119 | if not r then 120 | c:close() 121 | return nil, e 122 | end 123 | return base.setmetatable({c = c}, metat) 124 | end 125 | 126 | return _M -------------------------------------------------------------------------------- /Bin/Resource/RPG/Animations/Attack1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Animations/Attack1.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/Animations/Blow1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Animations/Blow1.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/Animations/Blow2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Animations/Blow2.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/Animations/Darkness2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Animations/Darkness2.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/Animations/Earth2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Animations/Earth2.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/Animations/Fire1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Animations/Fire1.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/Animations/Heal1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Animations/Heal1.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/Animations/Light2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Animations/Light2.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/Animations/Spear1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Animations/Spear1.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/Animations/Spear2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Animations/Spear2.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/Animations/Special5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Animations/Special5.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/Animations/State4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Animations/State4.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/Animations/State5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Animations/State5.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/Animations/Sword1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Animations/Sword1.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/Animations/Sword6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Animations/Sword6.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/Animations/Water2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Animations/Water2.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/Animations/Wind2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Animations/Wind2.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/Battlers/Bat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Battlers/Bat.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/Battlers/Cockatrice.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Battlers/Cockatrice.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/Battlers/Dragon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Battlers/Dragon.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/Battlers/Fairy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Battlers/Fairy.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/Battlers/Hornet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Battlers/Hornet.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/Battlers/Plant.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Battlers/Plant.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/Battlers/Rat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Battlers/Rat.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/Battlers/Scorpion.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Battlers/Scorpion.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/Battlers/Slime.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Battlers/Slime.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/Battlers/Spider.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Battlers/Spider.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/Battlers/Willowisp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Battlers/Willowisp.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/Battlers/吉尔.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Battlers/吉尔.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/Characters/!$Gate1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Characters/!$Gate1.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/Characters/!$Gate2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Characters/!$Gate2.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/Characters/!Chest.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Characters/!Chest.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/Characters/!Door1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Characters/!Door1.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/Characters/!Door3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Characters/!Door3.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/Characters/!Other2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Characters/!Other2.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/Characters/!Other3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Characters/!Other3.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/Characters/Actor1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Characters/Actor1.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/Characters/Actor2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Characters/Actor2.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/Characters/Actor3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Characters/Actor3.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/Characters/Animal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Characters/Animal.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/Characters/Evil.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Characters/Evil.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/Characters/Monster.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Characters/Monster.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/Characters/People1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Characters/People1.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/Characters/People2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Characters/People2.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/Characters/People3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Characters/People3.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/Characters/People4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Characters/People4.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/Characters/People5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Characters/People5.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/Characters/Spiritual.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Characters/Spiritual.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/Characters/Vehicle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Characters/Vehicle.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/Faces/Actor1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Faces/Actor1.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/Faces/Actor2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Faces/Actor2.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/Faces/Actor3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Faces/Actor3.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/Faces/Evil.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Faces/Evil.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/Faces/Monster.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Faces/Monster.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/Faces/People1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Faces/People1.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/Faces/People2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Faces/People2.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/Faces/People3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Faces/People3.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/Faces/People4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Faces/People4.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/Faces/Spiritual.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Faces/Spiritual.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/Faces/吉尔.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Faces/吉尔.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/Faces/拉尔夫&莉娜.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Faces/拉尔夫&莉娜.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/Faces/杰克.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Faces/杰克.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/Faces/维罗尼克&吉尔.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Faces/维罗尼克&吉尔.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/Faces/萨迪.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Faces/萨迪.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/Parallaxes/CloudySky.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Parallaxes/CloudySky.jpg -------------------------------------------------------------------------------- /Bin/Resource/RPG/Pictures/END.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Pictures/END.jpg -------------------------------------------------------------------------------- /Bin/Resource/RPG/Pictures/白色.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Pictures/白色.jpg -------------------------------------------------------------------------------- /Bin/Resource/RPG/Pictures/黑色.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/Pictures/黑色.jpg -------------------------------------------------------------------------------- /Bin/Resource/RPG/System/Balloon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/System/Balloon.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/System/BattleFloor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/System/BattleFloor.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/System/BattleStart.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/System/BattleStart.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/System/GameOver.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/System/GameOver.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/System/IconSet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/System/IconSet.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/System/MessageBack.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/System/MessageBack.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/System/Shadow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/System/Shadow.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/System/TileA1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/System/TileA1.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/System/TileA2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/System/TileA2.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/System/TileA3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/System/TileA3.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/System/TileA4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/System/TileA4.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/System/TileA5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/System/TileA5.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/System/TileB.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/System/TileB.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/System/TileC.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/System/TileC.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/System/TileD.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/System/TileD.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/System/TileE.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/System/TileE.png -------------------------------------------------------------------------------- /Bin/Resource/RPG/System/Title.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/System/Title.jpg -------------------------------------------------------------------------------- /Bin/Resource/RPG/System/Window.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/RPG/System/Window.png -------------------------------------------------------------------------------- /Bin/Resource/Tank/Boom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/Tank/Boom.png -------------------------------------------------------------------------------- /Bin/Resource/Tank/Char.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/Tank/Char.png -------------------------------------------------------------------------------- /Bin/Resource/Tank/Frag.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/Tank/Frag.png -------------------------------------------------------------------------------- /Bin/Resource/Tank/Misc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/Tank/Misc.png -------------------------------------------------------------------------------- /Bin/Resource/Tank/Tank.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/Tank/Tank.png -------------------------------------------------------------------------------- /Bin/Resource/Tank/Terr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/Tank/Terr.png -------------------------------------------------------------------------------- /Bin/Resource/bomb/0.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/bomb/0.jpg -------------------------------------------------------------------------------- /Bin/Resource/bomb/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/bomb/1.jpg -------------------------------------------------------------------------------- /Bin/Resource/bomb/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/bomb/2.jpg -------------------------------------------------------------------------------- /Bin/Resource/bomb/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/bomb/3.jpg -------------------------------------------------------------------------------- /Bin/Resource/bomb/4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/bomb/4.jpg -------------------------------------------------------------------------------- /Bin/Resource/bomb/5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/bomb/5.jpg -------------------------------------------------------------------------------- /Bin/Resource/bomb/6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/bomb/6.jpg -------------------------------------------------------------------------------- /Bin/Resource/bomb/7.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/bomb/7.jpg -------------------------------------------------------------------------------- /Bin/Resource/bomb/8.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/bomb/8.jpg -------------------------------------------------------------------------------- /Bin/Resource/bomb/bomb.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/bomb/bomb.jpg -------------------------------------------------------------------------------- /Bin/Resource/bomb/bomb1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/bomb/bomb1.jpg -------------------------------------------------------------------------------- /Bin/Resource/bomb/flag.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/bomb/flag.jpg -------------------------------------------------------------------------------- /Bin/Resource/bomb/flag2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/bomb/flag2.jpg -------------------------------------------------------------------------------- /Bin/Resource/bomb/null.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/bomb/null.jpg -------------------------------------------------------------------------------- /Bin/Resource/frames/frame_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/frames/frame_0.png -------------------------------------------------------------------------------- /Bin/Resource/frames/frame_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/frames/frame_1.png -------------------------------------------------------------------------------- /Bin/Resource/frames/frame_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/frames/frame_2.png -------------------------------------------------------------------------------- /Bin/Resource/frames/frame_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/frames/frame_3.png -------------------------------------------------------------------------------- /Bin/Resource/frames/frame_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/frames/frame_4.png -------------------------------------------------------------------------------- /Bin/Resource/frames/frame_5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/frames/frame_5.png -------------------------------------------------------------------------------- /Bin/Resource/frames/frame_6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/frames/frame_6.png -------------------------------------------------------------------------------- /Bin/Resource/frames/frame_7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/frames/frame_7.png -------------------------------------------------------------------------------- /Bin/Resource/frames/stars.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/frames/stars.png -------------------------------------------------------------------------------- /Bin/Resource/items/item_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/items/item_0.png -------------------------------------------------------------------------------- /Bin/Resource/items/item_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/items/item_1.png -------------------------------------------------------------------------------- /Bin/Resource/items/item_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/items/item_2.png -------------------------------------------------------------------------------- /Bin/Resource/items/item_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/items/item_3.png -------------------------------------------------------------------------------- /Bin/Resource/tiles/tile_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/tiles/tile_0.png -------------------------------------------------------------------------------- /Bin/Resource/tiles/tile_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/tiles/tile_1.png -------------------------------------------------------------------------------- /Bin/Resource/window/background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/window/background.png -------------------------------------------------------------------------------- /Bin/Resource/window/border.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/window/border.png -------------------------------------------------------------------------------- /Bin/Resource/window/window.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Resource/window/window.png -------------------------------------------------------------------------------- /Bin/Snake/Game/snake.lua: -------------------------------------------------------------------------------- 1 | require 'gl.python' 2 | 3 | local Queue = Class() 4 | 5 | function Queue:front() 6 | if self.head then 7 | return self.head.key 8 | end 9 | end 10 | 11 | function Queue:back() 12 | if self.tail then 13 | return self.tail.key 14 | end 15 | end 16 | 17 | function Queue:push_back(val) 18 | local item = {key = val} 19 | if self.tail then 20 | item.prev = self.tail 21 | self.tail.next = item 22 | self.tail = item 23 | else 24 | self.head = item 25 | self.tail = item 26 | end 27 | end 28 | 29 | function Queue:push_front(val) 30 | local item = {key = val} 31 | if self.head then 32 | self.head.prev = item 33 | item.next = self.head 34 | self.head = item 35 | else 36 | self.head = item 37 | self.tail = item 38 | end 39 | end 40 | 41 | function Queue:pop_back() 42 | if not self.tail then 43 | return 44 | end 45 | 46 | self.tail = self.tail.prev 47 | if not self.tail then 48 | self.head = nil 49 | else 50 | self.tail.next = nil 51 | end 52 | end 53 | 54 | function Queue:pop_front() 55 | if not self.head then return end 56 | 57 | self.head = self.head.next 58 | if not self.head then 59 | self.tail = nil 60 | else 61 | self.head.prev = nil 62 | end 63 | end 64 | 65 | Snake = Class() 66 | function Snake:__init__(x, y) 67 | self.x = x 68 | self.y = y 69 | self.g = x * y 70 | self.m = {} 71 | 72 | self.reset() 73 | end 74 | 75 | function Snake:mark(px, py, val) 76 | self.m[1 + py * self.x + px] = val 77 | end 78 | 79 | function Snake:getMark(px, py) 80 | return self.m[1 + py * self.x + px] 81 | end 82 | 83 | function Snake:spawn() 84 | local p = math.random() * self.r 85 | for i, v in ipairs(self.m) do 86 | if v == 0 then 87 | p = p - 1 88 | if p < 1 then 89 | local m = i % self.x 90 | local d = math.floor(i / self.x) 91 | self.mark(m, d, 1) 92 | self.r = self.r - 1 93 | return 94 | end 95 | end 96 | end 97 | end 98 | 99 | function Snake:update(elapse) 100 | if self.o then return end 101 | 102 | self.p = self.p + elapse 103 | while self.p > self.i and not self.o do 104 | local pos = self.q.front() 105 | 106 | local nx, ny = self.forward(pos[1], pos[2]) 107 | 108 | local mark = self.getMark(nx, ny) 109 | 110 | if mark == 1 then 111 | self.q.push_front({nx, ny}) 112 | self.mark(nx, ny, 2) 113 | self.spawn() 114 | if self.i > 0.12 then 115 | self.i = self.i * 0.9 116 | end 117 | self.p = self.p + self.i / 2 118 | elseif mark == 2 then 119 | self.o = true 120 | return 121 | else 122 | self.q.push_front({nx, ny}) 123 | self.mark(nx, ny, 2) 124 | 125 | local back = self.q.back() 126 | self.mark(back[1], back[2], 0) 127 | self.q.pop_back() 128 | end 129 | self.p = self.p - self.i 130 | end 131 | end 132 | 133 | function Snake:forward(x, y) 134 | if self.d == 0 then 135 | return (x + 1) % self.x, y 136 | elseif self.d == 1 then 137 | return x, (y + 1) % self.y 138 | elseif self.d == 2 then 139 | return (x - 1 + self.x) % self.x, y 140 | else 141 | return x, (y - 1 + self.y) % self.y 142 | end 143 | end 144 | 145 | local texture = loadTexture('item.png') 146 | local texWidth = texture:width() 147 | local texHeight = texture:height() 148 | 149 | function Snake:render() 150 | for i, v in ipairs(self.m) do 151 | if v ~= 0 then 152 | local ii = i - 1 153 | local nx = ii % self.x 154 | local ny = math.floor(ii / self.x) 155 | drawImage(texture, nx * 40 + 1, ny * 40 + 1, texWidth, texHeight, 0, 0, texWidth, texHeight, {1, 1, 1, 1}) 156 | end 157 | end 158 | end 159 | 160 | function Snake:renderGameOver() 161 | 162 | end 163 | 164 | function Snake:turn(direction) 165 | self.d = direction 166 | end 167 | 168 | function Snake:reset() 169 | self.i = 0.3 170 | self.p = 0 171 | 172 | local m = self.m 173 | for i = 1, self.g do 174 | m[i] = 0 175 | end 176 | 177 | local q = Queue() 178 | q.push_front({1, 1}) 179 | q.push_front({2, 1}) 180 | q.push_front({3, 1}) 181 | q.push_front({4, 1}) 182 | 183 | self.mark(1, 1, 2) 184 | self.mark(2, 1, 2) 185 | self.mark(3, 1, 2) 186 | self.mark(4, 1, 2) 187 | self.q = q 188 | self.o = false 189 | 190 | self.r = self.g - 4 191 | self.spawn() 192 | self.turn(0) 193 | end -------------------------------------------------------------------------------- /Bin/Snake/Resource/item.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Snake/Resource/item.png -------------------------------------------------------------------------------- /Bin/Snake/main.lua: -------------------------------------------------------------------------------- 1 | require 'gl.engine' 2 | require 'game.snake' 3 | 4 | glViewport(800, 600) 5 | 6 | local snake = Snake(20, 15) 7 | 8 | local game = {} 9 | 10 | function game.update(elapse) 11 | snake.update(elapse) 12 | end 13 | 14 | function game.render() 15 | snake.render() 16 | end 17 | 18 | function game.handle_mouse_event(x, y, how, pressed) 19 | 20 | end 21 | 22 | local VK_LEFT = 0x25 23 | local VK_UP = 0x26 24 | local VK_RIGHT = 0x27 25 | local VK_DOWN = 0x28 26 | 27 | function game.handle_keyboard_event(what, how) 28 | if how == 0x100 then 29 | if what == VK_RIGHT then 30 | snake.turn(0) 31 | elseif what == VK_UP then 32 | snake.turn(1) 33 | elseif what == VK_LEFT then 34 | snake.turn(2) 35 | elseif what == VK_DOWN then 36 | snake.turn(3) 37 | end 38 | end 39 | end 40 | 41 | glClearColor(190.0/255, 157/255.0, 118/255.0, 1) 42 | glEnable(3042) 43 | glBlendFunc(770, 771) 44 | 45 | return game -------------------------------------------------------------------------------- /Bin/Tank/bullet.lua: -------------------------------------------------------------------------------- 1 | require 'gl.engine' 2 | 3 | Bullet = Class() 4 | 5 | function Bullet:__init__(locX, locY, camp, power, direction) 6 | self.locX = locX 7 | self.locY = locY 8 | 9 | self.camp = camp 10 | self.power = power 11 | self.direction = direction 12 | end 13 | 14 | local color = {1, 1, 1, 1} 15 | 16 | local image = loadImage('tank\\misc.png') 17 | 18 | local drawImage = drawImage 19 | 20 | function Bullet:render() 21 | drawImage(image, self.locX - 4, self.locY - 4, 8, 8, self.direction * 8 - 8, 0, 8, 8, color) 22 | end -------------------------------------------------------------------------------- /Bin/Tank/explosion.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Tank/explosion.lua -------------------------------------------------------------------------------- /Bin/Tank/game.lua: -------------------------------------------------------------------------------- 1 | require 'tank.title' 2 | require 'tank.world' 3 | 4 | Game = Scene() 5 | 6 | Game.addLayer(TitleLayer()) -------------------------------------------------------------------------------- /Bin/Tank/rune.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/Tank/rune.lua -------------------------------------------------------------------------------- /Bin/Tank/tank.lua: -------------------------------------------------------------------------------- 1 | require 'gl.engine' 2 | 3 | --数值与纹理位置对应 4 | Direction = {East = 2, West = 4, South = 1, North = 3} 5 | 6 | TankState = {Standing = 1, Driving = 2, Slipping = 3} 7 | 8 | Tank = Class() 9 | 10 | function Tank:__init__(locX, locY, direction, logo, speed) 11 | self.locX = locX 12 | self.locY = locY 13 | self.logo = logo 14 | 15 | self.frame = 0 16 | self.speed = speed 17 | self.state = TankState.Standing 18 | 19 | 20 | self.direction = direction 21 | 22 | self.frameTimer = Timer(self.updateFrame, speed == 4 and 0.025 or 0.05) 23 | end 24 | 25 | local color = {1, 1, 1, 1} 26 | 27 | local image = loadImage('tank\\tank.png') 28 | 29 | local drawImage = drawImage 30 | 31 | function Tank:render() 32 | local left = (self.direction * 36 - 36 + self.frame * 18 + self.logo) * 32 33 | drawImage(image, self.locX - 16, self.locY - 16, 32, 32, left, 0, 32, 32, color) 34 | end 35 | 36 | function Tank:updateFrame() 37 | self.frame = (self.frame + 1) % 2 38 | end 39 | 40 | function Tank:move(direction) 41 | if not self.frameTimer.enabled then 42 | self.frameTimer.setTimer() 43 | end 44 | 45 | if direction == self.direction and self.state == TankState.Driving then 46 | return 47 | end 48 | 49 | --转向调整 50 | if direction == Direction.West or direction == Direction.East then 51 | self.locY = math.floor((self.locY + 7) / 16) * 16 52 | else 53 | self.locX = math.floor((self.locX + 7) / 16) * 16 54 | end 55 | 56 | self.direction = direction 57 | self.state = TankState.Driving 58 | end 59 | 60 | function Tank:stop(direction) 61 | if self.direction == direction and self.state == TankState.Driving then 62 | self.state = TankState.Standing 63 | self.frameTimer.killTimer() 64 | end 65 | end 66 | 67 | function Tank:detectCollision(direction, p1, p2, val) 68 | local locX = self.locX 69 | local locY = self.locY 70 | 71 | if direction == Direction.East then 72 | if p1 >= locY + 16 or p2 <= locY - 16 then 73 | return val 74 | end 75 | 76 | if val > locX - 16 then return locX - 16 end 77 | 78 | return val 79 | end 80 | 81 | if direction == Direction.West then 82 | if p1 >= locY + 16 or p2 <= locY - 16 then 83 | return val 84 | end 85 | 86 | if val < locX + 16 then return locX + 16 end 87 | 88 | return val 89 | end 90 | 91 | if direction == Direction.North then 92 | if p1 >= locX + 16 or p2 <= locX - 16 then 93 | return val 94 | end 95 | 96 | if val < locY + 16 then return locY + 16 end 97 | 98 | return val 99 | end 100 | 101 | if direction == Direction.South then 102 | if p1 >= locX + 16 or p2 <= locX - 16 then 103 | return val 104 | end 105 | 106 | if val > locY - 16 then return locY - 16 end 107 | 108 | return val 109 | end 110 | 111 | end -------------------------------------------------------------------------------- /Bin/Tank/tile.lua: -------------------------------------------------------------------------------- 1 | require 'gl.engine' 2 | 3 | --16px*16px的地图元素 4 | 5 | Tile = Class() 6 | 7 | Tile.Wall = 1 8 | Tile.Iron = 2 9 | Tile.Tree = 3 10 | Tile.Lake = 4 11 | Tile.Road = 5 12 | 13 | local canDetectCollision = {1, 1, 0, 1, 0, 1, 1, 1, 1} 14 | 15 | function Tile:__init__(type, locX, locY) 16 | self.type = type 17 | self.locX = locX 18 | self.locY = locY 19 | end 20 | 21 | local frame = 0 22 | 23 | function Tile.updateLake() 24 | frame = (frame + 1) % 2 25 | end 26 | 27 | local color = {1, 1, 1, 1} 28 | 29 | local image = loadImage('tank\\terr.png') 30 | 31 | local drawImage = drawImage 32 | 33 | function Tile:render() 34 | local top = self.type == Tile.Lake and frame * 16 or 0 35 | drawImage(image, self.locX, self.locY, 16, 16, self.type * 16, top, 16, 16, color) 36 | end 37 | 38 | function Tile:detectCollision(direction, p1, p2, val, oldVal) 39 | if not canDetectCollision[self.type] then return val end 40 | 41 | local locX = self.locX 42 | local locY = self.locY 43 | 44 | if direction == Direction.East then 45 | if p1 >= locY + 16 or p2 <= locY or oldVal > locX then 46 | return val 47 | end 48 | 49 | if val > locX then return locX end 50 | 51 | return val 52 | end 53 | 54 | if direction == Direction.West then 55 | if p1 >= locY + 16 or p2 <= locY or oldVal < locX + 16 then 56 | return val 57 | end 58 | 59 | if val < locX + 16 then return locX + 16 end 60 | 61 | return val 62 | end 63 | 64 | if direction == Direction.North then 65 | if p1 >= locX + 16 or p2 <= locX or oldVal < locY + 16 then 66 | return val 67 | end 68 | 69 | if val < locY + 16 then return locY + 16 end 70 | 71 | return val 72 | end 73 | 74 | if direction == Direction.South then 75 | if p1 >= locX + 16 or p2 <= locX or oldVal > locY then 76 | return val 77 | end 78 | 79 | if val > locY then return locY end 80 | 81 | return val 82 | end 83 | end -------------------------------------------------------------------------------- /Bin/Tank/title.lua: -------------------------------------------------------------------------------- 1 | require 'gl.define' 2 | require 'tank.scene' 3 | 4 | local state = {opening = 1, ongoing = 2, leaving = 3} 5 | 6 | TitleLayer = Class() 7 | 8 | function TitleLayer:__init__() 9 | self.offsetY = -480 10 | 11 | self.openingAni = Animation(self, 'offsetY') 12 | self.openingAni.onStop = self.onOpeningStop 13 | 14 | self.selectIndex = 1 15 | self.selectFrame = 0 16 | self.selectTimer = Timer(self.onTimer, 0.1) 17 | 18 | self.keyboardHandlers = {self.handle_keyboard_event_opening, 19 | self.handle_keyboard_event_ongoing} 20 | 21 | self.scissorY = 0 22 | self.leavingAni = Animation(self, 'scissorY') 23 | self.leavingAni.onStop = self.onLeavingStop 24 | end 25 | 26 | function TitleLayer:onOpeningStop() 27 | self.state = state.ongoing 28 | 29 | self.offsetY = 0 30 | self.selectTimer.setTimer() 31 | end 32 | 33 | function TitleLayer:onLeavingStop() 34 | --场景转换 35 | Game.delLayer(self) 36 | 37 | local worldLayer = WorldLayer() 38 | worldLayer.load(1) 39 | 40 | Game.addLayer(worldLayer) 41 | end 42 | 43 | function TitleLayer:onTimer() 44 | self.selectFrame = (self.selectFrame + 1) % 2 45 | end 46 | 47 | function TitleLayer:onEnter() 48 | self.state = state.opening 49 | self.openingAni.start(0, 3.2) 50 | end 51 | 52 | local VK_S = 83 53 | local VK_W = 87 54 | local VK_ENTER = 13 55 | 56 | function TitleLayer:handle_keyboard_event_opening(what, how) 57 | if how == Win32.WM_KEYDOWN and what == VK_ENTER then 58 | self.openingAni.stop() 59 | end 60 | end 61 | 62 | function TitleLayer:handle_keyboard_event_ongoing(what, how) 63 | if how == Win32.WM_KEYDOWN then 64 | if what == VK_ENTER then 65 | self.selectTimer.killTimer() 66 | self.state = state.leaving 67 | self.leavingAni.start(208, 0.8) 68 | elseif what == VK_W then 69 | self.selectIndex = self.selectIndex == 1 and 3 or self.selectIndex - 1 70 | elseif what == VK_S then 71 | self.selectIndex = self.selectIndex == 3 and 1 or self.selectIndex + 1 72 | end 73 | end 74 | end 75 | 76 | function TitleLayer:handle_keyboard_event(what, how) 77 | local handler = self.keyboardHandlers[self.state] 78 | if handler then handler(what, how) end 79 | end 80 | 81 | local bkgnd = loadImage('tank\\char.png') 82 | local white = {1.0, 1.0, 1.0, 1.0} 83 | local black = {0.0, 0.0, 0.0, 1.0} 84 | 85 | local loadImage = loadImage 86 | local drawImage = drawImage 87 | 88 | local function drawSprite(sprite, x, y, f) 89 | local image = loadImage(sprite.image) 90 | local frame = sprite.frame 91 | drawImage(image, x, y, 32, 32, frame[f][1], frame[f][2], 32, 32, white) 92 | end 93 | 94 | local font24 = loadTextRenderer('微软雅黑', 24) 95 | local sprite = {image = 'tank\\tank.png', frame = {{36 * 32, 0}, {54 * 32, 0}}} 96 | 97 | function TitleLayer:render() 98 | local matrix = Matrix() 99 | matrix.translate(0, self.offsetY) 100 | pushMatrix(matrix, true) 101 | 102 | drawImage(bkgnd, 52, 175, 372, 156, 0, 0, 372, 156, white) 103 | 104 | drawString(font24, '1 PLAYER', 192, 130, white) 105 | drawString(font24, '2 PLAYERS', 192, 100, white) 106 | drawString(font24, 'CONSTRUCTION', 192, 70, white) 107 | 108 | if self.state == state.ongoing then 109 | local tankY = (3 - self.selectIndex) * 30 + 66 110 | drawSprite(sprite, 150, tankY, self.selectFrame + 1) 111 | end 112 | 113 | popMatrix() 114 | 115 | if self.state == state.leaving then 116 | drawRectangle(0, 0, 480, self.scissorY, black) 117 | drawRectangle(0, 416 - self.scissorY, 480, 416, black) 118 | end 119 | end 120 | 121 | -------------------------------------------------------------------------------- /Bin/Tower/evil.lua: -------------------------------------------------------------------------------- 1 | require 'ds.class' 2 | require 'gl.engine' 3 | require 'tower.fight' 4 | require 'tower.frames' 5 | 6 | local Monster = Class() 7 | function Monster:__init__(name, frames, health, attack, defence, experience, gold, special) 8 | self.name = name 9 | self.frames = frames 10 | self.health = health 11 | self.attack = attack 12 | self.defence = defence 13 | self.experience = experience 14 | self.gold = gold 15 | self.special = special 16 | end 17 | 18 | function Monster:toEnter(player) 19 | startFight(player, self) 20 | end 21 | 22 | function Monster:doAttack(player) 23 | if self.attack > player.defence then 24 | return self.attack - player.defence 25 | end 26 | return 0 27 | end 28 | 29 | local MagicMonster = Class(Monster) 30 | function MagicMonster:__init__(name, frames, health, attack, defence, experience, gold) 31 | Monster.__init__(self, name, frames, health, attack, defence, experience, gold, '魔法攻击') 32 | end 33 | 34 | function MagicMonster:doAttack(player) 35 | if self.attack > player.resistance then 36 | return self.attack - player.resistance 37 | end 38 | return 0 39 | end 40 | 41 | local drawImage = drawImage 42 | local loadImage = loadImage 43 | function Monster:render(x, y, step) 44 | local image = loadImage(self.frames.image) 45 | local frame = self.frames.frame[step + 1] 46 | drawImage(image, x, y, 32, 32, 47 | frame[1], frame[2], 32, 32, {1, 1, 1, 1}) 48 | end 49 | 50 | Monsters = { 51 | ['绿色史莱姆'] = Monster('绿色史莱姆', Frames['绿色史莱姆'], 56, 20, 1, 1, 1), 52 | ['红色史莱姆'] = Monster('红色史莱姆', Frames['红色史莱姆'], 64, 25, 2, 2, 1), 53 | ['小蝙蝠'] = Monster('小蝙蝠', Frames['小蝙蝠'], 75, 35, 4, 3, 1), 54 | ['骷髅怪'] = Monster('骷髅怪', Frames['骷髅怪'], 99, 70, 0, 4, 1), 55 | } -------------------------------------------------------------------------------- /Bin/Tower/fight.lua: -------------------------------------------------------------------------------- 1 | require 'gl.engine' 2 | require 'gl.matrix' 3 | require 'gl.define' 4 | require 'tower.scene' 5 | require 'tower.frames' 6 | 7 | local loadImage = loadImage 8 | local drawImage = drawImage 9 | 10 | local texture = loadImage('window\\window.png') 11 | local bgPos = {0, 0, 128, 128} 12 | 13 | local borderTexture = loadImage('window\\border.png') 14 | local bdPos = {0, 0, 32, 32} 15 | 16 | local renderer = loadTextRenderer('黑体', 18) 17 | 18 | local FightLayer = Class() 19 | 20 | function FightLayer:__init__(hero, monster, gridx, gridy) 21 | self.hero = hero 22 | self.gridx = gridx 23 | self.gridy = gridy 24 | 25 | self.monster = monster 26 | self.monsterhealth = monster.health 27 | 28 | self.timer = Timer(self.onTimer, 0.25) 29 | self.complete = false 30 | self.combatlog = {} 31 | 32 | self.heroturn = true 33 | end 34 | 35 | local frames = Frames['英雄下'] 36 | function FightLayer:render() 37 | local matrix = Matrix() 38 | matrix.translate(60, 105) 39 | pushMatrix(matrix, true) 40 | drawImage(texture, 0, 0, 360, 270, 0, 0, 128, 128, {1, 1, 1, .75}) 41 | drawImageScaleGrid(borderTexture, -1, -1, 362, 272, 4, 4, 4, 4, {0.9, 0.9, 0.9, 1}) 42 | 43 | --画勇士 44 | local image = loadImage(frames.image) 45 | local frame = frames.frame[1] 46 | drawImage(image, 58, 222, 32, 32, frame[1], frame[2], 32, 32, {1,1,1,1}) 47 | 48 | drawString(renderer, '生命: '..self.hero.health, 27, 186, {0.8,0.9,1,1}) 49 | drawString(renderer, '攻击: '..self.hero.attack, 27, 162, {0.8,0.9,1,1}) 50 | drawString(renderer, '防御: '..self.hero.defence, 27, 138, {0.8,0.9,1,1}) 51 | drawString(renderer, '魔防: '..self.hero.resistance, 27, 114, {0.8,0.9,1,1}) 52 | 53 | drawString(renderer, 'VS', 164, 222, {0.9,0,0.5,1}) 54 | 55 | 56 | --画怪物 57 | local image = loadImage(self.monster.frames.image) 58 | local frame = self.monster.frames.frame[1] 59 | drawImage(image, 270, 222, 32, 32, frame[1], frame[2], 32, 32, {1, 1, 1, 1}) 60 | drawString(renderer, '生命: '..self.monsterhealth, 239, 186, {0.8,0.9,1,1}) 61 | drawString(renderer, '攻击: '..self.monster.attack, 239, 162, {0.8,0.9,1,1}) 62 | drawString(renderer, '防御: '..self.monster.defence, 239, 138, {0.8,0.9,1,1}) 63 | 64 | local top = 86 65 | for i, v in ipairs(self.combatlog) do 66 | drawString(renderer, v, 27, top, {0.9,0,1,1}) 67 | top = top - 24 68 | end 69 | 70 | drawString(renderer, '撤退(L)', 284, 16, {1,0,0,1}) 71 | 72 | popMatrix() 73 | end 74 | 75 | 76 | function FightLayer:handle_keyboard_event(what, how) 77 | if how == Win32.WM_KEYDOWN and what == 0x4c then 78 | local scene = getCurrentScene() 79 | if scene then 80 | scene.delLayer(self) 81 | end 82 | end 83 | return true 84 | end 85 | 86 | function FightLayer:onTimer() 87 | if self.complete then 88 | local scene = getCurrentScene() 89 | if scene then 90 | scene.delLayer(self) 91 | end 92 | return 93 | end 94 | 95 | if self.heroturn then 96 | local damage, continue = self.hero.doAttack(self.monster) 97 | self.addCombatLog('勇士攻击,怪物损失'..damage..'点生命') 98 | self.monsterhealth = self.monsterhealth - damage 99 | if self.monsterhealth <= 0 then 100 | self.monsterhealth = 0 101 | self.complete = true 102 | self.hero.gold = self.hero.gold + self.monster.gold 103 | self.hero.experience = self.hero.experience + self.monster.experience 104 | self.addCombatLog('战斗胜利! 获得'..self.monster.experience..'经验 '..self.monster.gold..'金币') 105 | end 106 | self.heroturn = continue 107 | else 108 | local damage, continue = self.monster.doAttack(self.hero) 109 | self.addCombatLog('怪物攻击,勇士损失'..damage..'点生命') 110 | self.hero.health = self.hero.health - damage 111 | self.heroturn = not continue 112 | end 113 | end 114 | 115 | function FightLayer:addCombatLog(inf) 116 | table.insert(self.combatlog, inf) 117 | if #self.combatlog > 3 then 118 | table.remove(self.combatlog, 1) 119 | end 120 | end 121 | 122 | function FightLayer:onEnter() 123 | self.timer.setTimer() 124 | end 125 | 126 | function FightLayer:onLeave() 127 | self.timer.killTimer() 128 | 129 | if self.complete then 130 | Game.delGrid(self.gridx, self.gridy) 131 | end 132 | end 133 | 134 | function startFight(hero, monster) 135 | local scene = getCurrentScene() 136 | if scene then 137 | local gridx, gridy = hero.nextGrid() 138 | scene.addLayer(FightLayer(hero, monster, gridx, gridy)) 139 | end 140 | end 141 | 142 | -------------------------------------------------------------------------------- /Bin/Tower/frames.lua: -------------------------------------------------------------------------------- 1 | Frames = { 2 | ['星星'] = { 3 | image = 'frames\\stars.png', 4 | frame = {{0, 0}, {32, 0}, {64, 0}, {96, 0}} 5 | }, 6 | 7 | ['英雄下'] = { 8 | image = 'frames\\frame_0.png', 9 | frame = {{0, 0}, {32, 0}, {64, 0}, {96, 0}} 10 | }, 11 | 12 | ['英雄左'] = { 13 | image = 'frames\\frame_0.png', 14 | frame = {{0, 32}, {32, 32}, {64, 32}, {96, 32}} 15 | }, 16 | 17 | ['英雄右'] = { 18 | image = 'frames\\frame_0.png', 19 | frame = {{0, 64}, {32, 64}, {64, 64}, {96, 64}} 20 | }, 21 | 22 | ['英雄上'] = { 23 | image = 'frames\\frame_0.png', 24 | frame = {{0, 96}, {32, 96}, {64, 96}, {96, 96}} 25 | }, 26 | 27 | ['老人'] = { 28 | image = 'frames\\frame_1.png', 29 | frame = {{0, 0}, {32, 0}, {64, 0}, {96, 0}} 30 | }, 31 | 32 | ['商人'] = { 33 | image = 'frames\\frame_1.png', 34 | frame = {{0, 32}, {32, 32}, {64, 32}, {96, 32}} 35 | }, 36 | 37 | ['勇士'] = { 38 | image = 'frames\\frame_1.png', 39 | frame = {{0, 64}, {32, 64}, {64, 64}, {96, 64}} 40 | }, 41 | 42 | ['精灵'] = { 43 | image = 'frames\\frame_1.png', 44 | frame = {{0, 96}, {32, 96}, {64, 96}, {96, 96}} 45 | }, 46 | 47 | ['绿色史莱姆'] = { 48 | image = 'frames\\frame_2.png', 49 | frame = {{0, 0}, {32, 0}, {64, 0}, {96, 0}} 50 | }, 51 | 52 | ['红色史莱姆'] = { 53 | image = 'frames\\frame_2.png', 54 | frame = {{0, 32}, {32, 32}, {64, 32}, {96, 32}} 55 | }, 56 | 57 | ['黑色史莱姆'] = { 58 | image = 'frames\\frame_2.png', 59 | frame = {{0, 64}, {32, 64}, {64, 64}, {96, 64}} 60 | }, 61 | 62 | ['大型史莱姆'] = { 63 | image = 'frames\\frame_2.png', 64 | frame = {{0, 96}, {32, 96}, {65, 96}, {96, 96}} 65 | }, 66 | 67 | ['小蝙蝠'] = { 68 | image = 'frames\\frame_3.png', 69 | frame = {{0, 0}, {32, 0}, {64, 0}, {96, 0}} 70 | }, 71 | 72 | ['骷髅怪'] = { 73 | image = 'frames\\frame_4.png', 74 | frame = {{0, 0}, {32, 0}, {64, 0}, {96, 0}} 75 | }, 76 | 77 | ['黄门'] = { 78 | image = 'frames\\frame_7.png', 79 | frame = {{0, 0}, {0, 32}, {0, 64}, {0, 96}} 80 | }, 81 | 82 | ['蓝门'] = { 83 | image = 'frames\\frame_7.png', 84 | frame = {{32, 0}, {32, 32}, {32, 64}, {32, 96}} 85 | }, 86 | 87 | ['红门'] = { 88 | image = 'frames\\frame_7.png', 89 | frame = {{64, 0}, {64, 32}, {64, 64}, {64, 96}} 90 | }, 91 | 92 | ['银门'] = { 93 | image = 'frames\\frame_7.png', 94 | frame = {{96, 0}, {96, 32}, {96, 64}, {96, 96}} 95 | }, 96 | } -------------------------------------------------------------------------------- /Bin/Tower/hero.lua: -------------------------------------------------------------------------------- 1 | require 'ds.class' 2 | require 'gl.engine' 3 | require 'tower.terrain' 4 | require 'tower.frames' 5 | require 'tower.scene' 6 | 7 | --下0, 左1, 上2,右3, 停4 8 | 9 | local T = Terrains 10 | 11 | Hero = Class() 12 | function Hero:__init__() 13 | --战斗属性 14 | self.level = 1 15 | self.health = 1000 16 | self.attack = 10 17 | self.defence = 10 18 | self.resistance = 0 19 | 20 | self.agility = 3 21 | self.strength = 0 22 | 23 | self.experience = 31 24 | self.gold = 71 25 | 26 | --物品 27 | self.redKey = 0 28 | self.buleKey = 0 29 | self.greenKey = 0 30 | self.yellowKey = 0 31 | 32 | --移动 33 | self.face = 0 --当前朝向 34 | self.gridx = 0 35 | self.grixy = 0 36 | 37 | self.head = 4 --移动朝向 38 | self.step = 0 --移动步数 39 | self.frame = 0 --移动帧数 40 | 41 | self.timer = Timer(function() 42 | self.frame = (self.frame + 1) % 4 43 | end, 0.08) 44 | 45 | self.transition = Animation(self, 'step') 46 | self.transition.onStart = function() 47 | self.timer.setTimer() 48 | end 49 | 50 | self.transition.onStop = function() 51 | local item = self.grid[2] 52 | self.gridx, self.gridy = self.nextGrid() 53 | self.step = 0 54 | 55 | if item and item.onEnter then 56 | item.onEnter(self) 57 | end 58 | 59 | if self.head ~= 4 then 60 | self.face = self.head 61 | local x, y = self.nextGrid() 62 | local grid = Game.getGrid(x, y) 63 | if grid and T[grid[1]][2] then 64 | local item = grid[2] 65 | if not item or item.toEnter(self) then 66 | self.grid = grid 67 | self.transition.start(32, 0.16) 68 | return 69 | end 70 | end 71 | end 72 | self.head = 4 73 | self.frame = 0 74 | self.timer.killTimer() 75 | end 76 | end 77 | 78 | function Hero:place(x, y, face) 79 | self.face = face 80 | self.head = 4 81 | self.gridx = x 82 | self.gridy = y 83 | self.frame = 0 84 | self.step = 0 85 | self.transition.stop() 86 | end 87 | 88 | function Hero:nextGrid() 89 | local x = self.gridx 90 | local y = self.gridy 91 | local f = self.face 92 | if f == 0 then 93 | y = y - 1 94 | elseif f == 1 then 95 | x = x - 1 96 | elseif f == 2 then 97 | y = y + 1 98 | elseif f == 3 then 99 | x = x + 1 100 | end 101 | return x, y 102 | end 103 | 104 | function Hero:move(face) 105 | self.head = face 106 | if not self.timer.enabled then 107 | self.face = face 108 | local x, y = self.nextGrid() 109 | local grid = Game.getGrid(x, y) 110 | if grid and T[grid[1]][2] then 111 | local item = grid[2] 112 | if not item or item.toEnter(self) then 113 | self.step = 0 114 | self.grid = grid 115 | self.transition.start(32, 0.16) 116 | return 117 | end 118 | end 119 | self.head = 4 120 | end 121 | end 122 | 123 | function Hero:stop(face) 124 | if not face or self.head == face then 125 | self.head = 4 126 | end 127 | end 128 | 129 | function Hero:location() 130 | if not self.transition.running then 131 | return self.gridx * 32, self.gridy * 32 132 | else 133 | local face = self.face 134 | if face == 1 then 135 | return self.gridx * 32 - self.step, self.gridy * 32 136 | elseif face == 0 then 137 | return self.gridx * 32, self.gridy * 32 - self.step 138 | elseif face == 3 then 139 | return self.gridx * 32 + self.step, self.gridy * 32 140 | elseif face == 2 then 141 | return self.gridx * 32, self.gridy * 32 + self.step 142 | end 143 | end 144 | end 145 | 146 | function Hero:render() 147 | local face = self.face 148 | local frame = Frames['英雄下'] 149 | if face == 1 then 150 | frame = Frames['英雄左'] 151 | elseif face == 2 then 152 | frame = Frames['英雄上'] 153 | elseif face == 3 then 154 | frame = Frames['英雄右'] 155 | end 156 | 157 | local x, y = self.location() 158 | local image = loadImage(frame.image) 159 | local texuv = frame.frame[self.frame + 1] 160 | drawImage(image, x, y, 32, 32, texuv[1], texuv[2], 32, 32, {1, 1, 1, 1}) 161 | end 162 | 163 | function Hero:onLeave() 164 | self.stop() 165 | self.transition.stop() 166 | end 167 | 168 | function Hero:doAttack(monster) 169 | if self.attack > monster.defence then 170 | return self.attack - monster.defence 171 | end 172 | return 0 173 | end 174 | -------------------------------------------------------------------------------- /Bin/Tower/npc.lua: -------------------------------------------------------------------------------- 1 | require 'ds.class' 2 | require 'gl.engine' 3 | 4 | local loadImage = loadImage 5 | local drawImage = drawImage 6 | 7 | NPC = Class() 8 | function NPC:__init__(frames) 9 | self.frames = frames 10 | end 11 | 12 | function NPC:render(x, y, step) 13 | local image = loadImage(self.frames.image) 14 | local frame = self.frames.frame[step + 1] 15 | drawImage(image, x, y, 32, 32, 16 | frame[1], frame[2], 32, 32, {1, 1, 1, 1}) 17 | end 18 | -------------------------------------------------------------------------------- /Bin/Tower/port.lua: -------------------------------------------------------------------------------- 1 | require 'ds.class' 2 | require 'gl.engine' 3 | require 'tower.sprite' 4 | 5 | local uport = Sprites['楼梯上'] 6 | local dport = Sprites['楼梯下'] 7 | local loadImage = loadImage 8 | local drawImage = drawImage 9 | 10 | UpLadder = Class() 11 | function UpLadder:__init__(target, gridx, gridy, face) 12 | self.target = target 13 | self.gridx = gridx 14 | self.gridy = gridy 15 | self.face = face 16 | end 17 | 18 | function UpLadder:render(x, y) 19 | local image = loadImage(uport.image) 20 | drawImage(image, x, y, 32, 32, uport.frame[1], uport.frame[2], 32, 32, {1,1,1,1}) 21 | end 22 | 23 | function UpLadder:onEnter() 24 | Game.transport(self.target, self.gridx, self.gridy, self.face) 25 | end 26 | 27 | function UpLadder:toEnter() 28 | return true 29 | end 30 | 31 | DownLadder = Class() 32 | function DownLadder:__init__(target, gridx, gridy, face) 33 | self.target = target 34 | self.gridx = gridx 35 | self.gridy = gridy 36 | self.face = face 37 | end 38 | 39 | function DownLadder:render(x, y) 40 | local image = loadImage(dport.image) 41 | drawImage(image, x, y, 32, 32, dport.frame[1], dport.frame[2], 32, 32, {1,1,1,1}) 42 | end 43 | 44 | function DownLadder:onEnter() 45 | Game.transport(self.target, self.gridx, self.gridy, self.face) 46 | end 47 | 48 | function DownLadder:toEnter() 49 | return true 50 | end -------------------------------------------------------------------------------- /Bin/Tower/sprite.lua: -------------------------------------------------------------------------------- 1 | Sprites = { 2 | --地图 3 | ['黄墙'] = { 4 | image = 'tiles\\tile_0.png', 5 | frame = {192, 0} 6 | }, 7 | 8 | ['白墙'] = { 9 | image = 'tiles\\tile_0.png', 10 | frame = {224, 0} 11 | }, 12 | 13 | ['铁板'] = { 14 | image = 'tiles\\tile_0.png', 15 | frame = {224, 32} 16 | }, 17 | 18 | ['地面'] = { 19 | image = 'tiles\\tile_0.png', 20 | frame = {96, 32} 21 | }, 22 | 23 | ['边框上'] = { 24 | image = 'tiles\\tile_0.png', 25 | frame = {32, 160} 26 | }, 27 | 28 | ['边框下'] = { 29 | image = 'tiles\\tile_0.png', 30 | frame = {32, 192} 31 | }, 32 | 33 | ['边框左'] = { 34 | image = 'tiles\\tile_0.png', 35 | frame = {0, 160} 36 | }, 37 | 38 | ['边框右'] = { 39 | image = 'tiles\\tile_0.png', 40 | frame = {64, 160} 41 | }, 42 | 43 | ['边框左下'] = { 44 | image = 'tiles\\tile_0.png', 45 | frame = {0, 192} 46 | }, 47 | 48 | ['边框右下'] = { 49 | image = 'tiles\\tile_0.png', 50 | frame = {64, 192} 51 | }, 52 | 53 | --通道 54 | ['黄门'] = { 55 | image = 'tiles\\tile_1.png', 56 | frame = {0, 0} 57 | }, 58 | 59 | ['蓝门'] = { 60 | image = 'tiles\\tile_1.png', 61 | frame = {32, 0} 62 | }, 63 | 64 | ['红门'] = { 65 | image = 'tiles\\tile_1.png', 66 | frame = {64, 0} 67 | }, 68 | 69 | ['绿门'] = { 70 | image = 'tiles\\tile_1.png', 71 | frame = {96, 0} 72 | }, 73 | 74 | ['银门'] = { 75 | image = 'tiles\\tile_1.png', 76 | frame = {128, 0} 77 | }, 78 | 79 | --楼梯 80 | ['楼梯上'] = { 81 | image = 'tiles\\tile_1.png', 82 | frame = {32,32} 83 | }, 84 | 85 | ['楼梯下'] = { 86 | image = 'tiles\\tile_1.png', 87 | frame = {0, 32} 88 | }, 89 | 90 | --钥匙 91 | ['黄钥匙'] = { 92 | image = 'items\\item_0.png', 93 | frame = {0, 0} 94 | }, 95 | 96 | ['蓝钥匙'] = { 97 | image = 'items\\item_0.png', 98 | frame = {32, 0} 99 | }, 100 | 101 | ['红钥匙'] = { 102 | image = 'items\\item_0.png', 103 | frame = {64, 0} 104 | }, 105 | 106 | ['绿钥匙'] = { 107 | image = 'items\\item_0.png', 108 | frame = {96, 0} 109 | }, 110 | 111 | --宝石 112 | ['红宝石'] = { 113 | image = 'items\\item_1.png', 114 | frame = {0, 0} 115 | }, 116 | 117 | ['蓝宝石'] = { 118 | image = 'items\\item_1.png', 119 | frame = {32, 0} 120 | }, 121 | 122 | --装备 123 | ['武器'] = { 124 | image = 'items\\item_3.png', 125 | frame = {64, 96} 126 | }, 127 | 128 | ['盾牌'] = { 129 | image = 'items\\item_2.png', 130 | frame = {32, 96} 131 | }, 132 | 133 | ['护甲'] = { 134 | 135 | }, 136 | 137 | --药品 138 | ['红药水'] = { 139 | image = 'items\\item_1.png', 140 | frame = {0, 32} 141 | }, 142 | 143 | ['蓝药水'] = { 144 | image = 'items\\item_1.png', 145 | frame = {32, 32} 146 | }, 147 | 148 | ['绿药水'] = { 149 | image = 'items\\item_1.png', 150 | frame = {64, 32} 151 | }, 152 | 153 | ['黄药水'] = { 154 | image = 'items\\item_1.png', 155 | frame = {96, 32} 156 | } 157 | } -------------------------------------------------------------------------------- /Bin/Tower/terrain.lua: -------------------------------------------------------------------------------- 1 | require 'tower.sprite' 2 | 3 | Terrains = { 4 | [1] = {Sprites['地面'], true}, 5 | [2] = {Sprites['黄墙'], false}, 6 | [3] = {Sprites['白墙'], false}, 7 | [4] = {Sprites['铁板'], false} 8 | } -------------------------------------------------------------------------------- /Bin/libtcmalloc_minimal.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/libtcmalloc_minimal.dll -------------------------------------------------------------------------------- /Bin/lua-5.2.2.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/lua-5.2.2.dll -------------------------------------------------------------------------------- /Bin/main-bomb.lua: -------------------------------------------------------------------------------- 1 | package.cpath = package.cpath..';.\\net\\?.dll' 2 | package.path = package.path ..';.\\net\\?.lua' 3 | 4 | require 'Bomb.game' 5 | 6 | glClearColor(1, 1, 1, 1) 7 | glEnable(3042) 8 | glBlendFunc(0x302, 0x303) 9 | glViewport(481, 481) 10 | 11 | setCurrentScene(Game) 12 | 13 | local game = 14 | { 15 | update = update, render = render, 16 | handle_mouse_event = handle_mouse_event, 17 | handle_keyboard_event = handle_keyboard_event 18 | } 19 | 20 | return game -------------------------------------------------------------------------------- /Bin/main-snake.lua: -------------------------------------------------------------------------------- 1 | require 'gl.engine' 2 | require 'game.snake' 3 | 4 | glViewport(800, 600) 5 | 6 | local snake = Snake(20, 15) 7 | 8 | local game = {} 9 | 10 | function game.update(elapse) 11 | snake.update(elapse) 12 | end 13 | 14 | function game.render() 15 | snake.render() 16 | end 17 | 18 | function game.handle_mouse_event(x, y, how, pressed) 19 | 20 | end 21 | 22 | local VK_LEFT = 0x25 23 | local VK_UP = 0x26 24 | local VK_RIGHT = 0x27 25 | local VK_DOWN = 0x28 26 | 27 | function game.handle_keyboard_event(what, how) 28 | if how == 0x100 then 29 | if what == VK_RIGHT then 30 | snake.turn(0) 31 | elseif what == VK_UP then 32 | snake.turn(1) 33 | elseif what == VK_LEFT then 34 | snake.turn(2) 35 | elseif what == VK_DOWN then 36 | snake.turn(3) 37 | end 38 | end 39 | end 40 | 41 | glClearColor(190.0/255, 157/255.0, 118/255.0, 1) 42 | glEnable(3042) 43 | glBlendFunc(770, 771) 44 | 45 | return game -------------------------------------------------------------------------------- /Bin/main-tower.lua: -------------------------------------------------------------------------------- 1 | require 'tower.game' 2 | 3 | glClearColor(0, 0, 0, 1) 4 | glEnable(3042) 5 | glBlendFunc(0x302, 0x303) 6 | glViewport(480, 480) 7 | 8 | setCurrentScene(Game) 9 | 10 | local game = 11 | { 12 | update = update, render = render, 13 | handle_mouse_event = handle_mouse_event, 14 | handle_keyboard_event = handle_keyboard_event 15 | } 16 | 17 | return game -------------------------------------------------------------------------------- /Bin/main.lua: -------------------------------------------------------------------------------- 1 | require 'tank.game' 2 | 3 | glClearColor(0, 0, 0, 1) 4 | glEnable(3042) 5 | glBlendFunc(0x302, 0x303) 6 | glViewport(480, 416) 7 | 8 | setCurrentScene(Game) 9 | 10 | local game = 11 | { 12 | update = update, render = render, 13 | handle_mouse_event = handle_mouse_event, 14 | handle_keyboard_event = handle_keyboard_event 15 | } 16 | 17 | return game -------------------------------------------------------------------------------- /Bin/msvcp110.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/msvcp110.dll -------------------------------------------------------------------------------- /Bin/msvcr110.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Bin/msvcr110.dll -------------------------------------------------------------------------------- /Fairy2D/Binding/Color.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | struct Color 4 | { 5 | Color() { 6 | r = g = b = a = 1.f; 7 | } 8 | 9 | float r, g, b, a; 10 | }; 11 | -------------------------------------------------------------------------------- /Fairy2D/Binding/LuaVM.cpp: -------------------------------------------------------------------------------- 1 | #include "System.h" 2 | #include "GLCache.h" 3 | #include "GLDevice.h" 4 | 5 | #include "VAOBinding.h" 6 | #include "VBOBinding.h" 7 | #include "OpenGLBinding.h" 8 | #include "ProgramBinding.h" 9 | #include "TextureBinding.h" 10 | #include "TextRenderBinding.h" 11 | #include "RenderTextureBinding.h" 12 | #include "GameWindow.h" 13 | 14 | #include "TextRender.h" 15 | 16 | #include "LuaVM.h" 17 | #include "tcmalloc.h" 18 | 19 | using namespace System; 20 | using namespace Fairy2D; 21 | using namespace LuaBinding; 22 | 23 | LuaVM::LuaVM() 24 | { 25 | _L = NULL; 26 | } 27 | 28 | LuaVM::~LuaVM() 29 | { 30 | close(); 31 | } 32 | 33 | static int lPrint(lua_State* state) 34 | { 35 | OutputDebugStringA(lua_tostring(state, 1)); 36 | return 0; 37 | } 38 | 39 | void* lmalloc(void* ud, void* ptr, size_t osize, size_t nsize) 40 | { 41 | if (nsize == 0) { 42 | tc_cfree(ptr); 43 | return NULL; 44 | } else { 45 | return tc_realloc(ptr, nsize); 46 | } 47 | } 48 | 49 | int LuaVM::start(const std::wstring& file) 50 | { 51 | _L = luaL_newstate(); 52 | lua_setallocf(_L, lmalloc, 0); 53 | if (_L == NULL) return false; 54 | 55 | luaL_openlibs(_L); 56 | 57 | SetupOpenGLBinding(_L); 58 | SetupProgramBinding(_L); 59 | SetupTextureBinding(_L); 60 | SetupTextRenderBinding(_L); 61 | SetupVertexArrayBinding(_L); 62 | SetupVertexBufferBinding(_L); 63 | SetupRenderTextureBinding(_L); 64 | GameWindow::SetupWindowBinding(_L); 65 | TextRender::createProgram(); 66 | 67 | lua_register(_L, "print", lPrint); 68 | 69 | string name = Encoding::unicodeToUTF8(file); 70 | if (luaL_dofile(_L, name.c_str()) == LUA_OK) { 71 | lua_getfield(_L, 1, "update"); 72 | lua_setfield(_L, LUA_REGISTRYINDEX, "game_update"); 73 | 74 | lua_getfield(_L, 1, "render"); 75 | lua_setfield(_L, LUA_REGISTRYINDEX, "game_render"); 76 | 77 | lua_getfield(_L, 1, "handle_mouse_event"); 78 | lua_setfield(_L, LUA_REGISTRYINDEX, "handle_mouse_event"); 79 | 80 | lua_getfield(_L, 1, "handle_keyboard_event"); 81 | lua_setfield(_L, LUA_REGISTRYINDEX, "handle_keyboard_event"); 82 | lua_settop(_L, 0); 83 | return 1; 84 | } else { 85 | OutputDebugStringA(lua_tostring(_L, -1)); 86 | exit(-1); 87 | } 88 | close(); 89 | return 0; 90 | } 91 | 92 | void LuaVM::close() 93 | { 94 | if (_L != NULL) { 95 | lua_close(_L); 96 | _L = NULL; 97 | 98 | TextRender::deleteProgram(); 99 | } 100 | } 101 | 102 | void LuaVM::update(float elapsed) 103 | { 104 | if (_L != NULL) { 105 | lua_getfield(_L, LUA_REGISTRYINDEX, "game_update"); 106 | lua_pushnumber(_L, elapsed); 107 | if (lua_pcall(_L, 1, 0, 0) != LUA_OK) { 108 | OutputDebugStringA("update error: "); 109 | OutputDebugStringA(lua_tostring(_L, -1)); 110 | OutputDebugStringA("\n"); 111 | } 112 | lua_settop(_L, 0); 113 | lua_gc(_L, LUA_GCCOLLECT, 0); 114 | } 115 | } 116 | 117 | void LuaVM::render() 118 | { 119 | if (_L != NULL) { 120 | glClear(GL_COLOR_BUFFER_BIT); 121 | glDisable(GL_MULTISAMPLE); 122 | lua_getfield(_L, LUA_REGISTRYINDEX, "game_render"); 123 | if (lua_pcall(_L, 0, 0, 0) != LUA_OK) { 124 | OutputDebugStringA("render error: "); 125 | OutputDebugStringA(lua_tostring(_L, -1)); 126 | OutputDebugStringA("\n"); 127 | } 128 | lua_settop(_L, 0); 129 | GLCache::clear(); 130 | 131 | glFinish(); 132 | 133 | GLDevice::instance().present(); 134 | } 135 | } 136 | 137 | void LuaVM::fireMouseEvent(int x, int y, int how, bool pressed) 138 | { 139 | if (_L != NULL) { 140 | lua_getfield(_L, LUA_REGISTRYINDEX, "handle_mouse_event"); 141 | lua_pushnumber(_L, x); 142 | lua_pushnumber(_L, y); 143 | lua_pushnumber(_L, how); 144 | lua_pushboolean(_L, pressed); 145 | if (lua_pcall(_L, 4, 0, 0) != LUA_OK) { 146 | OutputDebugStringA("mosueEvent error: "); 147 | OutputDebugStringA(lua_tostring(_L, -1)); 148 | OutputDebugStringA("\n"); 149 | } 150 | lua_settop(_L, 0); 151 | } 152 | } 153 | 154 | void LuaVM::fireKeyboardEvent(int what, int how) 155 | { 156 | if (_L != NULL) { 157 | lua_getfield(_L, LUA_REGISTRYINDEX, "handle_keyboard_event"); 158 | lua_pushnumber(_L, what); 159 | lua_pushnumber(_L, how); 160 | if (lua_pcall(_L, 2, 0, 0) != LUA_OK) { 161 | OutputDebugStringA("keyboardEvent error: "); 162 | OutputDebugStringA(lua_tostring(_L, -1)); 163 | OutputDebugStringA("\n"); 164 | } 165 | lua_settop(_L, 0); 166 | } 167 | } -------------------------------------------------------------------------------- /Fairy2D/Binding/LuaVM.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "lua.hpp" 4 | 5 | class LuaVM 6 | { 7 | public: 8 | LuaVM(); 9 | ~LuaVM(); 10 | 11 | static LuaVM& instance() 12 | { 13 | static LuaVM lvm; 14 | return lvm; 15 | } 16 | 17 | int start(const std::wstring& file); 18 | void close(); 19 | 20 | void update(float elapsed); 21 | void render(); 22 | 23 | void fireMouseEvent(int x, int y, int how, bool pressed); 24 | void fireKeyboardEvent(int what, int how); 25 | private: 26 | lua_State* _L; 27 | }; -------------------------------------------------------------------------------- /Fairy2D/Binding/OpenGLBinding.cpp: -------------------------------------------------------------------------------- 1 | #include "GLCommon.h" 2 | #include "OpenGLBinding.h" 3 | #include "LuaBinding.h" 4 | 5 | namespace LuaBinding 6 | { 7 | LUA_NEW(BlendColor) 8 | LUA_NEW(BlendEquation) 9 | LUA_NEW(BlendEquationSeparate) 10 | LUA_NEW(BlendFunc) 11 | LUA_NEW(BlendFuncSeparate) 12 | LUA_NEW(Clear) 13 | LUA_NEW(ClearColor) 14 | LUA_NEW(ClearDepth) 15 | LUA_NEW(ClearStencil) 16 | LUA_NEW(ColorMask) 17 | LUA_NEW(CullFace) 18 | LUA_NEW(DepthFunc) 19 | LUA_NEW(DepthMask) 20 | LUA_NEW(DepthRange) 21 | LUA_NEW(Disable) 22 | LUA_NEW(Enable) 23 | LUA_NEW(Finish) 24 | LUA_NEW(Flush) 25 | LUA_NEW(FrontFace) 26 | LUA_NEW(Hint) 27 | LUA_NEW(IsEnabled) 28 | LUA_NEW(LineWidth) 29 | LUA_NEW(LogicOp) 30 | LUA_NEW(PointSize) 31 | LUA_NEW(PolygonMode) 32 | LUA_NEW(PolygonOffset) 33 | LUA_NEW(Scissor) 34 | LUA_NEW(StencilFunc) 35 | LUA_NEW(StencilFuncSeparate) 36 | LUA_NEW(StencilMask) 37 | LUA_NEW(StencilMaskSeparate) 38 | LUA_NEW(StencilOp) 39 | LUA_NEW(StencilOpSeparate) 40 | 41 | void SetupOpenGLBinding(lua_State* state) 42 | { 43 | luaL_Reg regs[] = { 44 | LUA_REG(BlendColor) 45 | LUA_REG(BlendEquation) 46 | LUA_REG(BlendEquationSeparate) 47 | LUA_REG(BlendFunc) 48 | LUA_REG(BlendFuncSeparate) 49 | LUA_REG(Clear) 50 | LUA_REG(ClearColor) 51 | LUA_REG(ClearDepth) 52 | LUA_REG(ClearStencil) 53 | LUA_REG(ColorMask) 54 | LUA_REG(CullFace) 55 | LUA_REG(DepthFunc) 56 | LUA_REG(DepthMask) 57 | LUA_REG(DepthRange) 58 | LUA_REG(Disable) 59 | LUA_REG(Enable) 60 | LUA_REG(Finish) 61 | LUA_REG(Flush) 62 | LUA_REG(FrontFace) 63 | LUA_REG(Hint) 64 | LUA_REG(IsEnabled) 65 | LUA_REG(LineWidth) 66 | LUA_REG(LogicOp) 67 | LUA_REG(PointSize) 68 | LUA_REG(PolygonMode) 69 | LUA_REG(PolygonOffset) 70 | LUA_REG(Scissor) 71 | LUA_REG(StencilFunc) 72 | LUA_REG(StencilFuncSeparate) 73 | LUA_REG(StencilMask) 74 | LUA_REG(StencilMaskSeparate) 75 | LUA_REG(StencilOp) 76 | LUA_REG(StencilOpSeparate) 77 | }; 78 | 79 | for (int i = 0; i < sizeof(regs)/sizeof(regs[0]); i++) { 80 | lua_register(state, regs[i].name, regs[i].func); 81 | } 82 | } 83 | } -------------------------------------------------------------------------------- /Fairy2D/Binding/OpenGLBinding.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "lua.hpp" 3 | 4 | namespace LuaBinding 5 | { 6 | void SetupOpenGLBinding(lua_State* state); 7 | } -------------------------------------------------------------------------------- /Fairy2D/Binding/ProgramBinding.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "lua.hpp" 3 | 4 | namespace LuaBinding 5 | { 6 | void SetupProgramBinding(lua_State* state); 7 | } -------------------------------------------------------------------------------- /Fairy2D/Binding/RenderTextureBinding.cpp: -------------------------------------------------------------------------------- 1 | #include "GLRenderTarget.h" 2 | #include "RenderTextureBinding.h" 3 | #include "GLCache.h" 4 | 5 | using namespace Fairy2D; 6 | 7 | namespace LuaBinding 8 | { 9 | int lBeginRender(lua_State* state) 10 | { 11 | GLCache::clear(); 12 | auto renderTexture = (GLRenderTarget*)lua_touserdata(state, 1); 13 | renderTexture->beginRender(); 14 | return 0; 15 | } 16 | 17 | int lEndRender(lua_State* state) 18 | { 19 | auto renderTexture = (GLRenderTarget*)lua_touserdata(state, 1); 20 | renderTexture->endRender(); 21 | GLCache::clear(); 22 | return 0; 23 | } 24 | 25 | int lBind(lua_State* state) 26 | { 27 | auto renderTexture = (GLRenderTarget*)lua_touserdata(state, 1); 28 | glActiveTexture(GL_TEXTURE0 + lua_tointeger(state, 2)); 29 | glBindTexture(GL_TEXTURE_2D, renderTexture->getTexture()); 30 | return 0; 31 | } 32 | 33 | int lGetWidth(lua_State* state) 34 | { 35 | auto renderTexture = (GLRenderTarget*)lua_touserdata(state, 1); 36 | lua_pushinteger(state, renderTexture->getTexture().getWidth()); 37 | return 1; 38 | } 39 | 40 | int lGetHeight(lua_State* state) 41 | { 42 | auto renderTexture = (GLRenderTarget*)lua_touserdata(state, 1); 43 | lua_pushinteger(state, renderTexture->getTexture().getHeight()); 44 | return 1; 45 | } 46 | 47 | int lDestroyRenderTexture(lua_State* state) 48 | { 49 | auto renderTexture = (GLRenderTarget*)lua_touserdata(state, 1); 50 | renderTexture->~GLRenderTarget(); 51 | return 0; 52 | } 53 | 54 | int lCreateRenderTexture(lua_State* state) 55 | { 56 | auto renderTexture = (GLRenderTarget*)lua_newuserdata(state, sizeof(GLRenderTarget)); 57 | 58 | new (renderTexture) GLRenderTarget; 59 | if (renderTexture->create(lua_tointeger(state, 1), lua_tointeger(state, 2))) { 60 | lua_getfield(state, LUA_REGISTRYINDEX, "__renderTexture"); 61 | lua_setmetatable(state, -2); 62 | return 1; 63 | } 64 | return 0; 65 | } 66 | 67 | void SetupRenderTextureBinding(lua_State* state) 68 | { 69 | luaL_Reg regs[] = { 70 | {"beginRender", lBeginRender}, 71 | {"endRender", lEndRender}, 72 | {"bind", lBind}, 73 | {"width", lGetWidth}, 74 | {"height", lGetHeight}, 75 | {"__gc", lDestroyRenderTexture}, 76 | {NULL, NULL} 77 | }; 78 | 79 | lua_newtable(state); 80 | luaL_setfuncs(state, regs, 0); 81 | lua_pushnil(state); 82 | lua_copy(state, -2, -1); 83 | lua_setfield(state, -2, "__index"); 84 | lua_setfield(state, LUA_REGISTRYINDEX, "__renderTexture"); 85 | 86 | lua_register(state, "createRenderTexture", lCreateRenderTexture); 87 | } 88 | } -------------------------------------------------------------------------------- /Fairy2D/Binding/RenderTextureBinding.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "lua.hpp" 3 | 4 | namespace LuaBinding 5 | { 6 | void SetupRenderTextureBinding(lua_State* state); 7 | } -------------------------------------------------------------------------------- /Fairy2D/Binding/TextRender.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Fairy2D/Binding/TextRender.cpp -------------------------------------------------------------------------------- /Fairy2D/Binding/TextRender.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "GLBuffer.h" 3 | #include "GLProgram.h" 4 | #include "GLVertexArray.h" 5 | #include "GLFontTexture.h" 6 | 7 | #include "Color.h" 8 | 9 | using namespace Fairy2D; 10 | 11 | class TextRender 12 | { 13 | public: 14 | TextRender(const wstring& face, int size, BOOL bold = FALSE); 15 | ~TextRender(); 16 | 17 | static void createProgram(); 18 | static void deleteProgram(); 19 | 20 | int charWidth(wchar_t ch); 21 | int charHeight(); 22 | 23 | int measure(const std::wstring& text); 24 | int render(const std::wstring& text, float left, float bottom, const Color& color, const float* matrix); 25 | 26 | void reset(); 27 | private: 28 | void addGlyph(wchar_t ch); 29 | int render(wchar_t ch, float left, float top, const Color& color, const float* matrix); 30 | 31 | struct TextureItem 32 | { 33 | GLFontTexture _texture; 34 | int _freeleft; 35 | int _freetop; 36 | TextureItem* _next; 37 | }; 38 | TextureItem* _textures; 39 | TextureItem* createTexture(); 40 | TextureItem* ensureTexture(int width); 41 | 42 | struct CharItem 43 | { 44 | int _width; 45 | float _textureCoord[4][2]; 46 | TextureItem* _texture; 47 | }; 48 | map _characters; 49 | 50 | HDC _memdc; 51 | HFONT _font; 52 | HBITMAP _bitmap; 53 | 54 | DWORD* _data; 55 | int _width; 56 | int _height; 57 | 58 | 59 | static GLBuffer* __buffer; 60 | static GLProgram* __program; 61 | static GLVertexArray* __vertexArray; 62 | }; -------------------------------------------------------------------------------- /Fairy2D/Binding/TextRenderBinding.cpp: -------------------------------------------------------------------------------- 1 | #include "System.h" 2 | #include "TextRender.h" 3 | #include "TextRenderBinding.h" 4 | 5 | using namespace System; 6 | 7 | namespace LuaBinding 8 | { 9 | int lCharWidth(lua_State* state) 10 | { 11 | auto render = (TextRender*)lua_touserdata(state, 1); 12 | auto text = Encoding::UTF8ToUnicode(lua_tostring(state, 2)); 13 | lua_pushinteger(state, render->charWidth(text[0])); 14 | return 1; 15 | } 16 | 17 | int lCharHeight(lua_State* state) 18 | { 19 | auto render = (TextRender*)lua_touserdata(state, 1); 20 | lua_pushinteger(state, render->charHeight()); 21 | return 1; 22 | } 23 | 24 | int lMeasure(lua_State* state) 25 | { 26 | auto render = (TextRender*)lua_touserdata(state, 1); 27 | auto text = Encoding::UTF8ToUnicode(lua_tostring(state, 2)); 28 | lua_pushinteger(state, render->measure(text)); 29 | return 1; 30 | } 31 | 32 | int lRender(lua_State* state) 33 | { 34 | auto render = (TextRender*)lua_touserdata(state, 1); 35 | auto text = Encoding::UTF8ToUnicode(lua_tostring(state, 2)); 36 | 37 | float color[4]; 38 | for (size_t i = 0; i < 4; i++) { 39 | lua_rawgeti(state, 5, i + 1); 40 | color[i] = lua_tonumber(state, -1); 41 | lua_pop(state, 1); 42 | } 43 | 44 | float matrix[16]; 45 | for (size_t i = 0; i < 16; i++) { 46 | lua_rawgeti(state, 6, i + 1); 47 | matrix[i] = lua_tonumber(state, -1); 48 | lua_pop(state, 1); 49 | } 50 | 51 | Color fcolor; 52 | memcpy(&fcolor, color, sizeof(Color)); 53 | 54 | lua_pushinteger(state, render->render(text, lua_tonumber(state, 3), 55 | lua_tonumber(state, 4), fcolor, matrix)); 56 | return 1; 57 | } 58 | 59 | int lDestroyTextRender(lua_State* state) 60 | { 61 | auto render = (TextRender*)lua_touserdata(state, 1); 62 | render->~TextRender(); 63 | return 0; 64 | } 65 | 66 | int lCreateTextRender(lua_State* state) 67 | { 68 | auto fontface = Encoding::UTF8ToUnicode(lua_tostring(state, 1)); 69 | int fontsize = lua_tointeger(state, 2); 70 | 71 | auto render = (TextRender*)lua_newuserdata(state, sizeof(TextRender)); 72 | new (render) TextRender(fontface, fontsize); 73 | lua_getfield(state, LUA_REGISTRYINDEX, "__textRender"); 74 | lua_setmetatable(state, -2); 75 | return 1; 76 | } 77 | 78 | void SetupTextRenderBinding(lua_State* state) 79 | { 80 | luaL_Reg regs[] = { 81 | {"charWidth", lCharWidth}, 82 | {"charHeight", lCharHeight}, 83 | {"measure", lMeasure}, 84 | {"render", lRender}, 85 | {"__gc", lDestroyTextRender}, 86 | {NULL, NULL} 87 | }; 88 | 89 | lua_newtable(state); 90 | luaL_setfuncs(state, regs, 0); 91 | lua_pushnil(state); 92 | lua_copy(state, -2, -1); 93 | lua_setfield(state, -2, "__index"); 94 | lua_setfield(state, LUA_REGISTRYINDEX, "__textRender"); 95 | 96 | lua_register(state, "createTextRenderer", lCreateTextRender); 97 | } 98 | } -------------------------------------------------------------------------------- /Fairy2D/Binding/TextRenderBinding.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "lua.hpp" 3 | 4 | namespace LuaBinding 5 | { 6 | void SetupTextRenderBinding(lua_State* state); 7 | } -------------------------------------------------------------------------------- /Fairy2D/Binding/TextureBinding.cpp: -------------------------------------------------------------------------------- 1 | #include "System.h" 2 | #include "FileSystem.h" 3 | 4 | #include "stb_image.h" 5 | #include "GLTexture.h" 6 | #include "TextureBinding.h" 7 | 8 | using namespace System; 9 | using namespace Fairy2D; 10 | 11 | namespace LuaBinding 12 | { 13 | int lBindTexture(lua_State* state) 14 | { 15 | auto texture = (GLTexture*)lua_touserdata(state, 1); 16 | glActiveTexture(GL_TEXTURE0 + lua_tointeger(state, 2)); 17 | glBindTexture(GL_TEXTURE_2D, *texture); 18 | return 0; 19 | } 20 | 21 | int lGetTextureWidth(lua_State* state) 22 | { 23 | auto texture = (GLTexture*)lua_touserdata(state, 1); 24 | lua_pushinteger(state, texture->getWidth()); 25 | return 1; 26 | } 27 | 28 | int lGetTextureHeight(lua_State* state) 29 | { 30 | auto texture = (GLTexture*)lua_touserdata(state, 1); 31 | lua_pushinteger(state, texture->getHeight()); 32 | return 1; 33 | } 34 | 35 | int lDestroyTexture(lua_State* state) 36 | { 37 | auto texture = (GLTexture*)lua_touserdata(state, 1); 38 | texture->~GLTexture(); 39 | return 0; 40 | } 41 | 42 | int lLoadTextureFromFile(lua_State* state) 43 | { 44 | FileSystem* resource = FileSystem::current(); 45 | 46 | size_t size; 47 | void* buff = resource->read(Encoding::UTF8ToUnicode(lua_tostring(state, 1)), size); 48 | GLASSERT(buff != NULL); 49 | 50 | int x, y, comp = 4; 51 | stbi_uc* data = stbi_load_from_memory((stbi_uc*)buff, size, &x, &y, &comp, 4); 52 | GLASSERT(data != NULL); 53 | 54 | auto texture = (GLTexture*)lua_newuserdata(state, sizeof(GLTexture)); //texture 55 | 56 | new (texture) GLTexture; 57 | texture->create(x, y, NULL); 58 | texture->update(0, 0, x, y, data); 59 | stbi_image_free(data); 60 | resource->free(buff); 61 | 62 | lua_getfield(state, LUA_REGISTRYINDEX, "__texture"); //texture m 63 | lua_setmetatable(state, -2); //texture 64 | return 1; 65 | } 66 | 67 | void SetupTextureBinding(lua_State* state) 68 | { 69 | luaL_Reg regs[] = { 70 | {"bind", lBindTexture}, 71 | {"width", lGetTextureWidth}, 72 | {"height", lGetTextureHeight}, 73 | {"__gc", lDestroyTexture}, 74 | {NULL, NULL} 75 | }; 76 | 77 | lua_newtable(state); 78 | luaL_setfuncs(state, regs, 0); 79 | 80 | lua_pushnil(state); 81 | lua_copy(state, -2, -1); 82 | lua_setfield(state, -2, "__index"); 83 | 84 | lua_setfield(state, LUA_REGISTRYINDEX, "__texture"); 85 | 86 | lua_register(state, "loadTexture", lLoadTextureFromFile); 87 | } 88 | } -------------------------------------------------------------------------------- /Fairy2D/Binding/TextureBinding.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "lua.hpp" 3 | 4 | namespace LuaBinding 5 | { 6 | void SetupTextureBinding(lua_State* state); 7 | } 8 | -------------------------------------------------------------------------------- /Fairy2D/Binding/VAOBinding.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "lua.hpp" 3 | 4 | namespace LuaBinding 5 | { 6 | void SetupVertexArrayBinding(lua_State* state); 7 | } 8 | -------------------------------------------------------------------------------- /Fairy2D/Binding/VBOBinding.cpp: -------------------------------------------------------------------------------- 1 | #include "GLBuffer.h" 2 | #include "VBOBinding.h" 3 | 4 | using namespace Fairy2D; 5 | 6 | namespace LuaBinding 7 | { 8 | int lVertexBufferDataf(lua_State* state) 9 | { 10 | GLBuffer* buffer = (GLBuffer*)lua_touserdata(state, 1); 11 | size_t length = lua_rawlen(state, 3); 12 | float* data = new float[length]; 13 | for (size_t i = 0; i < length; i++) { 14 | lua_rawgeti(state, 3, i + 1); 15 | data[i] = lua_tonumber(state, -1); 16 | lua_pop(state, 1); 17 | } 18 | 19 | glBindBuffer(GL_ARRAY_BUFFER, *buffer); 20 | glBufferSubData(GL_ARRAY_BUFFER, lua_tointeger(state, 2), length * 4, data); 21 | glBindBuffer(GL_ARRAY_BUFFER, 0); 22 | 23 | delete[] data; 24 | return 0; 25 | } 26 | 27 | int lVertexBufferDatai(lua_State* state) 28 | { 29 | GLBuffer* buffer = (GLBuffer*)lua_touserdata(state, 1); 30 | size_t length = lua_rawlen(state, 3); 31 | GLuint* data = new GLuint[length]; 32 | for (size_t i = 0; i < length; i++) { 33 | lua_rawgeti(state, 3, i + 1); 34 | data[i] = lua_tointeger(state, -1); 35 | lua_pop(state, 1); 36 | } 37 | 38 | glBindBuffer(GL_ARRAY_BUFFER, *buffer); 39 | glBufferSubData(GL_ARRAY_BUFFER, lua_tointeger(state, 2), length * 4, data); 40 | glBindBuffer(GL_ARRAY_BUFFER, 0); 41 | delete[] data; 42 | return 0; 43 | } 44 | 45 | int lDestroyVertexBuffer(lua_State* state) 46 | { 47 | GLBuffer* buffer = (GLBuffer*)lua_touserdata(state, 1); 48 | buffer->~GLBuffer(); 49 | OutputDebugString(L"lDestroyVertexBuffer.\n"); 50 | return 0; 51 | } 52 | 53 | int lCreateVertexBuffer(lua_State* state) 54 | { 55 | GLBuffer* buffer = (GLBuffer*)lua_newuserdata(state, sizeof(GLBuffer)); 56 | new (buffer) GLBuffer; 57 | buffer->create(lua_tointeger(state, 1), NULL); 58 | 59 | lua_getfield(state, LUA_REGISTRYINDEX, "__vertexBuffer"); 60 | lua_setmetatable(state, -2); 61 | return 1; 62 | } 63 | 64 | void SetupVertexBufferBinding(lua_State* state) 65 | { 66 | luaL_Reg regs[] = { 67 | {"copyf", lVertexBufferDataf}, 68 | {"copyi", lVertexBufferDatai}, 69 | {"__gc", lDestroyVertexBuffer}, 70 | {NULL, NULL} 71 | }; 72 | 73 | lua_newtable(state); 74 | luaL_setfuncs(state, regs, 0); 75 | lua_pushnil(state); 76 | lua_copy(state, -2, -1); 77 | lua_setfield(state, -2, "__index"); 78 | lua_setfield(state, LUA_REGISTRYINDEX, "__vertexBuffer"); 79 | 80 | lua_register(state, "createVertexBuffer", lCreateVertexBuffer); 81 | } 82 | } -------------------------------------------------------------------------------- /Fairy2D/Binding/VBOBinding.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "lua.hpp" 3 | 4 | namespace LuaBinding 5 | { 6 | void SetupVertexBufferBinding(lua_State* state); 7 | } -------------------------------------------------------------------------------- /Fairy2D/Fairy2D.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /Fairy2D/GameWindow.cpp: -------------------------------------------------------------------------------- 1 | #include "LuaVM.h" 2 | #include "GLDevice.h" 3 | #include "GameWindow.h" 4 | 5 | using namespace Fairy2D; 6 | 7 | BEGIN_MESSAGE_MAP(GameWindow, Window) 8 | ON_MESSAGE(WM_CREATE, onCreate) 9 | ON_MESSAGE(WM_KEYDOWN, onKeyDown) 10 | ON_MESSAGE(WM_KEYUP, onKeyUp) 11 | ON_MESSAGE(WM_CHAR, onChar) 12 | 13 | ON_MESSAGE(WM_MOUSEMOVE, onMouseMove) 14 | ON_MESSAGE(WM_LBUTTONDOWN, onMouseDown) 15 | ON_MESSAGE(WM_LBUTTONUP, onMouseUp) 16 | 17 | ON_MESSAGE(WM_RBUTTONDOWN, onRMouseDown) 18 | ON_MESSAGE(WM_RBUTTONUP, onRMouseUp) 19 | 20 | ON_MESSAGE(WM_DESTROY, onDestroy) 21 | 22 | END_MESSAGE_MAP() 23 | 24 | LRESULT GameWindow::onCreate(WPARAM wParam, LPARAM lParam) 25 | { 26 | GLDevice::instance().initialize(_window); 27 | return 0; 28 | } 29 | 30 | LRESULT GameWindow::onKeyDown(WPARAM wParam, LPARAM lParam) 31 | { 32 | LuaVM::instance().fireKeyboardEvent(wParam, WM_KEYDOWN); 33 | return 0; 34 | } 35 | 36 | LRESULT GameWindow::onKeyUp(WPARAM wParam, LPARAM lParam) 37 | { 38 | LuaVM::instance().fireKeyboardEvent(wParam, WM_KEYUP); 39 | 40 | if (wParam == VK_ESCAPE) { 41 | close(); 42 | } 43 | return 0; 44 | } 45 | 46 | LRESULT GameWindow::onChar(WPARAM wParam, LPARAM lParam) 47 | { 48 | LuaVM::instance().fireKeyboardEvent(wParam, WM_CHAR); 49 | return 0; 50 | } 51 | 52 | LRESULT GameWindow::onMouseMove(WPARAM wParam, LPARAM lParam) 53 | { 54 | POINT point = getCursorPos(); 55 | LuaVM::instance().fireMouseEvent(point.x, point.y, WM_MOUSEMOVE, GetCapture() == _window); 56 | return 0; 57 | } 58 | 59 | LRESULT GameWindow::onMouseDown(WPARAM wParam, LPARAM lParam) 60 | { 61 | POINT point = getCursorPos(); 62 | SetCapture(_window); 63 | LuaVM::instance().fireMouseEvent(point.x, point.y, WM_LBUTTONDOWN, TRUE); 64 | return 0; 65 | } 66 | 67 | LRESULT GameWindow::onMouseUp(WPARAM wParam, LPARAM lParam) 68 | { 69 | POINT point = getCursorPos(); 70 | ReleaseCapture(); 71 | 72 | LuaVM::instance().fireMouseEvent(point.x, point.y, WM_LBUTTONUP, FALSE); 73 | return 0; 74 | } 75 | 76 | LRESULT GameWindow::onRMouseDown(WPARAM wParam, LPARAM lParam) 77 | { 78 | POINT point = getCursorPos(); 79 | SetCapture(_window); 80 | LuaVM::instance().fireMouseEvent(point.x, point.y, WM_RBUTTONDOWN, TRUE); 81 | return 0; 82 | } 83 | 84 | LRESULT GameWindow::onRMouseUp(WPARAM wParam, LPARAM lParam) 85 | { 86 | POINT point = getCursorPos(); 87 | ReleaseCapture(); 88 | 89 | LuaVM::instance().fireMouseEvent(point.x, point.y, WM_RBUTTONUP, FALSE); 90 | return 0; 91 | } 92 | 93 | LRESULT GameWindow::onDestroy(WPARAM wParam, LPARAM lParam) 94 | { 95 | LuaVM::instance().close(); 96 | GLDevice::instance().release(); 97 | 98 | PostQuitMessage(0); 99 | return 0; 100 | } 101 | 102 | static GameWindow* window; 103 | 104 | GameWindow::GameWindow() 105 | { 106 | window = this; 107 | } 108 | 109 | int lSetViewport(lua_State* state) 110 | { 111 | int width = lua_tointeger(state, 1); 112 | int height = lua_tointeger(state, 2); 113 | RECT rect = {0, 0, width, height}; 114 | AdjustWindowRect(&rect, window->getWindowLong(GWL_STYLE), FALSE); 115 | window->setWindowPos(NULL, 0, 0, rect.right - rect.left, rect.bottom - rect.top, SWP_NOZORDER|SWP_NOMOVE); 116 | window->centerWindow(); 117 | glViewport(0, 0, width, height); 118 | return 0; 119 | } 120 | 121 | void GameWindow::SetupWindowBinding(lua_State* state) 122 | { 123 | lua_register(state, "glViewport", lSetViewport); 124 | } -------------------------------------------------------------------------------- /Fairy2D/GameWindow.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Window.h" 3 | #include "lua.hpp" 4 | 5 | class GameWindow : public Window 6 | { 7 | public: 8 | GameWindow(); 9 | 10 | static void SetupWindowBinding(lua_State* state); 11 | protected: 12 | DECLARE_MESSAGE_MAP() 13 | 14 | HANDLER(onCreate); 15 | 16 | HANDLER(onKeyDown); 17 | HANDLER(onKeyUp); 18 | HANDLER(onChar); 19 | 20 | HANDLER(onMouseMove); 21 | 22 | HANDLER(onMouseUp); 23 | HANDLER(onMouseDown); 24 | 25 | HANDLER(onRMouseUp); 26 | HANDLER(onRMouseDown); 27 | 28 | HANDLER(onDestroy); 29 | }; -------------------------------------------------------------------------------- /Fairy2D/Lua/lua-5.2.2.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Fairy2D/Lua/lua-5.2.2.dll -------------------------------------------------------------------------------- /Fairy2D/Lua/lua-5.2.2.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Fairy2D/Lua/lua-5.2.2.lib -------------------------------------------------------------------------------- /Fairy2D/Lua/lua.hpp: -------------------------------------------------------------------------------- 1 | // lua.hpp 2 | // Lua header files for C++ 3 | // <> not supplied automatically because Lua also compiles as C++ 4 | 5 | extern "C" { 6 | #include "lua.h" 7 | #include "lualib.h" 8 | #include "lauxlib.h" 9 | } 10 | -------------------------------------------------------------------------------- /Fairy2D/Lua/lualib.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lualib.h,v 1.43 2011/12/08 12:11:37 roberto Exp $ 3 | ** Lua standard libraries 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lualib_h 9 | #define lualib_h 10 | 11 | #include "lua.h" 12 | 13 | 14 | 15 | LUAMOD_API int (luaopen_base) (lua_State *L); 16 | 17 | #define LUA_COLIBNAME "coroutine" 18 | LUAMOD_API int (luaopen_coroutine) (lua_State *L); 19 | 20 | #define LUA_TABLIBNAME "table" 21 | LUAMOD_API int (luaopen_table) (lua_State *L); 22 | 23 | #define LUA_IOLIBNAME "io" 24 | LUAMOD_API int (luaopen_io) (lua_State *L); 25 | 26 | #define LUA_OSLIBNAME "os" 27 | LUAMOD_API int (luaopen_os) (lua_State *L); 28 | 29 | #define LUA_STRLIBNAME "string" 30 | LUAMOD_API int (luaopen_string) (lua_State *L); 31 | 32 | #define LUA_BITLIBNAME "bit32" 33 | LUAMOD_API int (luaopen_bit32) (lua_State *L); 34 | 35 | #define LUA_MATHLIBNAME "math" 36 | LUAMOD_API int (luaopen_math) (lua_State *L); 37 | 38 | #define LUA_DBLIBNAME "debug" 39 | LUAMOD_API int (luaopen_debug) (lua_State *L); 40 | 41 | #define LUA_LOADLIBNAME "package" 42 | LUAMOD_API int (luaopen_package) (lua_State *L); 43 | 44 | 45 | /* open all previous libraries */ 46 | LUALIB_API void (luaL_openlibs) (lua_State *L); 47 | 48 | 49 | 50 | #if !defined(lua_assert) 51 | #define lua_assert(x) ((void)0) 52 | #endif 53 | 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /Fairy2D/OpenGL/FileSystem.cpp: -------------------------------------------------------------------------------- 1 | #include "System.h" 2 | #include "FileSystem.h" 3 | using namespace System; 4 | 5 | class LocalFileSystem : public FileSystem 6 | { 7 | public: 8 | LocalFileSystem(const std::wstring& path); 9 | 10 | void* read(const std::wstring& file, size_t& size); 11 | void free(void* data); 12 | private: 13 | std::wstring path; 14 | }; 15 | 16 | LocalFileSystem::LocalFileSystem(const std::wstring& path) 17 | { 18 | this->path = path; 19 | } 20 | 21 | void* LocalFileSystem::read(const std::wstring& file, size_t& size) 22 | { 23 | File::FileReader reader; 24 | if (!reader.open(path + file)) 25 | return NULL; 26 | 27 | DWORD fileSize = reader.getFileSize(); 28 | if (fileSize == INVALID_FILE_SIZE) 29 | return NULL; 30 | 31 | void* data = malloc(fileSize + 4); 32 | memset((char*)data + fileSize, 0, 4); 33 | 34 | if (!reader.read(data, fileSize)) { 35 | ::free(data); 36 | return NULL; 37 | } 38 | 39 | size = fileSize; 40 | return data; 41 | } 42 | 43 | void LocalFileSystem::free(void* data) 44 | { 45 | ::free(data); 46 | } 47 | 48 | FileSystem* FileSystem::current() 49 | { 50 | static LocalFileSystem* system; 51 | if (system == NULL) { 52 | wchar_t file[MAX_PATH]; 53 | GetModuleFileName(NULL, file, MAX_PATH); 54 | system = new LocalFileSystem(File::getPath(file) + L"\\Resource\\"); 55 | } 56 | return system; 57 | } -------------------------------------------------------------------------------- /Fairy2D/OpenGL/FileSystem.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | class FileSystem 5 | { 6 | public: 7 | static FileSystem* current(); 8 | 9 | virtual void* read(const std::wstring& file, size_t& size) = 0; 10 | virtual void free(void* data) = 0; 11 | }; 12 | -------------------------------------------------------------------------------- /Fairy2D/OpenGL/GLBuffer.cpp: -------------------------------------------------------------------------------- 1 | #include "GLBuffer.h" 2 | 3 | NS_GL_BEGIN 4 | 5 | GLBuffer::GLBuffer() 6 | { 7 | _buffer = 0; 8 | } 9 | 10 | GLBuffer::~GLBuffer() 11 | { 12 | if (_buffer != 0) { 13 | glDeleteBuffers(1, &_buffer); 14 | } 15 | } 16 | 17 | GLBuffer::operator GLuint() 18 | { 19 | return _buffer; 20 | } 21 | 22 | void GLBuffer::create(size_t size, const GLvoid* data, GLenum usage) 23 | { 24 | if (_buffer == 0) { 25 | glGenBuffers(1, &_buffer); 26 | } 27 | glBindBuffer(GL_ARRAY_BUFFER, _buffer); 28 | glBufferData(GL_ARRAY_BUFFER, size, data, usage); 29 | glBindBuffer(GL_ARRAY_BUFFER, 0); 30 | } 31 | 32 | void GLBuffer::update(size_t from, size_t size, const GLvoid* data) 33 | { 34 | glBindBuffer(GL_ARRAY_BUFFER, _buffer); 35 | glBufferSubData(GL_ARRAY_BUFFER, from, size, data); 36 | glBindBuffer(GL_ARRAY_BUFFER, 0); 37 | } 38 | 39 | NS_GL_CLOSE -------------------------------------------------------------------------------- /Fairy2D/OpenGL/GLBuffer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "GLCommon.h" 3 | 4 | NS_GL_BEGIN 5 | 6 | class GLBuffer 7 | { 8 | public: 9 | GLBuffer(); 10 | ~GLBuffer(); 11 | 12 | operator GLuint(); 13 | 14 | void create(size_t size, const GLvoid* data, GLenum usage = GL_STREAM_DRAW); 15 | void update(size_t from, size_t size, const GLvoid* data); 16 | private: 17 | GLuint _buffer; 18 | 19 | GL_NO_COPY(GLBuffer); 20 | }; 21 | 22 | NS_GL_CLOSE -------------------------------------------------------------------------------- /Fairy2D/OpenGL/GLCache.cpp: -------------------------------------------------------------------------------- 1 | #include "GLCache.h" 2 | 3 | NS_GL_BEGIN 4 | 5 | GLuint _program; 6 | GLuint _vertexArray; 7 | 8 | void GLCache::bindVertexArray(GLuint vertexArray) 9 | { 10 | if (vertexArray != _vertexArray) { 11 | _vertexArray = vertexArray; 12 | glBindVertexArray(vertexArray); 13 | } 14 | } 15 | 16 | void GLCache::useProgram(GLuint program) 17 | { 18 | if (program != _program) { 19 | _program = program; 20 | glUseProgram(program); 21 | } 22 | } 23 | 24 | void GLCache::clear() 25 | { 26 | _program = _vertexArray = 0; 27 | } 28 | 29 | NS_GL_CLOSE -------------------------------------------------------------------------------- /Fairy2D/OpenGL/GLCache.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "GLCommon.h" 3 | 4 | NS_GL_BEGIN 5 | 6 | class GLCache 7 | { 8 | public: 9 | static void bindVertexArray(GLuint vertex); 10 | 11 | static void useProgram(GLuint program); 12 | 13 | static void clear(); 14 | }; 15 | 16 | 17 | NS_GL_CLOSE 18 | -------------------------------------------------------------------------------- /Fairy2D/OpenGL/GLCommon.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "glew.h" 4 | #include "wglew.h" 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | using namespace std; 12 | 13 | #define GL_NO_COPY(cls) \ 14 | private: \ 15 | cls(const cls&); \ 16 | cls& operator=(const cls&) 17 | 18 | #define GLUNI(x) L##x 19 | #define WIDEN(x) GLUNI(x) 20 | #define GLTRACER WIDEN(__FUNCTION__) 21 | 22 | #define GLASSERT(cond) \ 23 | do \ 24 | { \ 25 | if (!(cond)) { \ 26 | OutputDebugString(GLTRACER); \ 27 | OutputDebugString(L"\nAssert Fail.\n"); \ 28 | exit(-1); \ 29 | } \ 30 | } while(0) 31 | 32 | #define NS_GL_BEGIN namespace Fairy2D { 33 | #define NS_GL_CLOSE } -------------------------------------------------------------------------------- /Fairy2D/OpenGL/GLDevice.cpp: -------------------------------------------------------------------------------- 1 | #include "GLDevice.h" 2 | #pragma comment(lib, "opengl32.lib") 3 | 4 | NS_GL_BEGIN 5 | 6 | static BOOL VerifyMultiSample(PIXELFORMATDESCRIPTOR& pfd, int& pixelFormat) 7 | { 8 | HWND hWnd = CreateWindow(L"BUTTON", NULL, WS_POPUP, 9 | 0, 0, 0, 0, GetDesktopWindow(), NULL, NULL, NULL); 10 | 11 | GLASSERT(hWnd != NULL); 12 | 13 | HDC hDC = GetDC(hWnd); 14 | pixelFormat = ChoosePixelFormat(hDC, &pfd); 15 | SetPixelFormat(hDC, pixelFormat, &pfd); 16 | HGLRC hGL = wglCreateContext(hDC); 17 | wglMakeCurrent(hDC, hGL); 18 | 19 | BOOL success = FALSE; 20 | typedef BOOL (WINAPI* pfnChooseProc)(HDC, const int*, const float*, UINT, int*, UINT*); 21 | pfnChooseProc wglChoose = (pfnChooseProc)wglGetProcAddress("wglChoosePixelFormatARB"); 22 | if (wglChoose == NULL) goto Cleanup; 23 | 24 | UINT nFormats; 25 | float fAttr[] = {0, 0}; 26 | int iAttr[] = { 27 | WGL_DRAW_TO_WINDOW_ARB, GL_TRUE, 28 | WGL_SUPPORT_OPENGL_ARB, GL_TRUE, 29 | WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB, 30 | WGL_COLOR_BITS_ARB, 32, 31 | WGL_ALPHA_BITS_ARB, 8, 32 | WGL_DEPTH_BITS_ARB, 24, 33 | WGL_STENCIL_BITS_ARB, 8, 34 | WGL_DOUBLE_BUFFER_ARB, GL_TRUE, 35 | WGL_SAMPLE_BUFFERS_ARB, GL_TRUE, 36 | WGL_SAMPLES_ARB, 4, 37 | 0, 0 38 | }; 39 | 40 | if (wglChoose(hDC, iAttr, fAttr, 1, &pixelFormat, &nFormats) && nFormats >= 1) { 41 | success = TRUE; 42 | goto Cleanup; 43 | } 44 | 45 | iAttr[19] = 2; 46 | success = wglChoose(hDC, iAttr, fAttr, 1, &pixelFormat, &nFormats) && nFormats >= 1; 47 | 48 | Cleanup: 49 | wglMakeCurrent(hDC, 0); 50 | wglDeleteContext(hGL); 51 | ReleaseDC(hWnd, hDC); 52 | DestroyWindow(hWnd); 53 | return success; 54 | } 55 | 56 | static void SetupPixelFormat(HDC hDC) 57 | { 58 | int pixelFormat; 59 | PIXELFORMATDESCRIPTOR pfd = // pfd Tells Windows How We Want Things To Be 60 | { 61 | sizeof (PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor 62 | 1, // Version Number 63 | PFD_DRAW_TO_WINDOW | // Format Must Support Window 64 | PFD_SUPPORT_OPENGL | // Format Must Support OpenGL 65 | PFD_DOUBLEBUFFER, // Must Support Double Buffering 66 | PFD_TYPE_RGBA, // Request An RGBA Format 67 | 32, // Select Our Color Depth 68 | 0, 0, 0, 0, 0, 0, // Color Bits Ignored 69 | 1, // Alpha Buffer 70 | 0, // Shift Bit Ignored 71 | 0, // No Accumulation Buffer 72 | 0, 0, 0, 0, // Accumulation Bits Ignored 73 | 16, // 16Bit Z-Buffer (Depth Buffer) 74 | 0, // No Stencil Buffer 75 | 0, // No Auxiliary Buffer 76 | PFD_MAIN_PLANE, // Main Drawing Layer 77 | 0, // Reserved 78 | 0, 0, 0 // Layer Masks Ignored 79 | }; 80 | if (!VerifyMultiSample(pfd, pixelFormat)) { 81 | pixelFormat = ChoosePixelFormat(hDC, &pfd); 82 | } 83 | SetPixelFormat(hDC, pixelFormat, &pfd); 84 | } 85 | 86 | BOOL GLDevice::initialize(HWND hWnd) 87 | { 88 | GLASSERT(_hDC == NULL); 89 | _hDC = GetDC(hWnd); 90 | SetupPixelFormat(_hDC); 91 | 92 | _hGL = wglCreateContext(_hDC); 93 | wglMakeCurrent(_hDC, _hGL); 94 | GLenum flag = glewInit(); 95 | GLASSERT(flag == GLEW_OK); 96 | _hWnd = hWnd; 97 | 98 | return TRUE; 99 | } 100 | 101 | void GLDevice::release() 102 | { 103 | wglMakeCurrent(_hDC, 0); 104 | wglDeleteContext(_hGL); 105 | ReleaseDC(_hWnd, _hDC); 106 | } 107 | 108 | void GLDevice::present() 109 | { 110 | SwapBuffers(_hDC); 111 | } 112 | 113 | NS_GL_CLOSE -------------------------------------------------------------------------------- /Fairy2D/OpenGL/GLDevice.h: -------------------------------------------------------------------------------- 1 | #include "GLCommon.h" 2 | 3 | NS_GL_BEGIN 4 | 5 | class GLDevice 6 | { 7 | public: 8 | static GLDevice& instance() 9 | { 10 | static GLDevice device; 11 | return device; 12 | } 13 | 14 | BOOL initialize(HWND hWnd); 15 | void release(); 16 | void present(); 17 | private: 18 | HDC _hDC; 19 | HGLRC _hGL; 20 | HWND _hWnd; 21 | }; 22 | NS_GL_CLOSE -------------------------------------------------------------------------------- /Fairy2D/OpenGL/GLFontTexture.cpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "GLFontTexture.h" 3 | 4 | NS_GL_BEGIN 5 | 6 | GLFontTexture::GLFontTexture() 7 | { 8 | _texture = 0; 9 | _height = 0; 10 | _width = 0; 11 | } 12 | 13 | GLFontTexture::~GLFontTexture() 14 | { 15 | if (_texture != 0) { 16 | glDeleteTextures(1, &_texture); 17 | } 18 | } 19 | 20 | void GLFontTexture::create(size_t width, size_t height) 21 | { 22 | glGenTextures(1, &_texture); 23 | glBindTexture(GL_TEXTURE_2D, _texture); 24 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, width, height, 0, GL_RED, GL_UNSIGNED_BYTE, NULL); 25 | glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 26 | glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 27 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 28 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 29 | glBindTexture(GL_TEXTURE_2D, 0); 30 | 31 | _width = width; 32 | _height = height; 33 | } 34 | 35 | void GLFontTexture::update(GLint left, GLint top, size_t width, size_t height, const GLvoid* pixels) 36 | { 37 | glBindTexture(GL_TEXTURE_2D, _texture); 38 | glPixelStorei(GL_UNPACK_ALIGNMENT, 1); 39 | glTexSubImage2D(GL_TEXTURE_2D, 0, left, top, width, height, GL_RED, GL_UNSIGNED_BYTE, pixels); 40 | glBindTexture(GL_TEXTURE_2D, 0); 41 | } 42 | 43 | GLFontTexture::operator GLuint() 44 | { 45 | return _texture; 46 | } 47 | 48 | size_t GLFontTexture::getWidth() const 49 | { 50 | return _width; 51 | } 52 | 53 | size_t GLFontTexture::getHeight() const 54 | { 55 | return _height; 56 | } 57 | 58 | NS_GL_CLOSE -------------------------------------------------------------------------------- /Fairy2D/OpenGL/GLFontTexture.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "GLCommon.h" 3 | 4 | NS_GL_BEGIN 5 | 6 | class GLFontTexture 7 | { 8 | public: 9 | GLFontTexture(); 10 | ~GLFontTexture(); 11 | 12 | operator GLuint(); 13 | 14 | void create(size_t width, size_t height); 15 | void update(GLint left, GLint top, size_t width, size_t height, const GLvoid* pixels); 16 | size_t getWidth() const; 17 | size_t getHeight() const; 18 | private: 19 | GLuint _texture; 20 | 21 | size_t _width; 22 | size_t _height; 23 | 24 | GL_NO_COPY(GLFontTexture); 25 | }; 26 | 27 | 28 | 29 | 30 | NS_GL_CLOSE 31 | 32 | -------------------------------------------------------------------------------- /Fairy2D/OpenGL/GLProgram.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "GLCommon.h" 3 | 4 | NS_GL_BEGIN 5 | 6 | class GLProgram 7 | { 8 | public: 9 | GLProgram(); 10 | ~GLProgram(); 11 | 12 | operator GLuint(); 13 | 14 | GLint getUniformLocation(const GLchar* location); 15 | GLint getAttribLocation(const GLchar* location); 16 | 17 | BOOL createFromFile(const GLchar* vertexFile, const GLchar* fragFile); 18 | BOOL create(const GLchar* vertexSource, const GLchar* fragSource); 19 | BOOL isValid(); 20 | 21 | void useProgram(); 22 | void endProgram(); 23 | void setVertexAttribPointer(const GLchar* location, GLint size, GLenum type, 24 | GLboolean normalized, GLsizei stride, const GLvoid* data); 25 | 26 | void setUniform1i(const GLchar* location, GLint i1); 27 | void setUniform2i(const GLchar* location, GLint i1, GLint i2); 28 | void setUniform3i(const GLchar* location, GLint i1, GLint i2, GLint i3); 29 | void setUniform4i(const GLchar* location, GLint i1, GLint i2, GLint i3, GLint i4); 30 | 31 | void setUniform1iv(const GLchar* location, const GLint* ints, size_t numberofArrays); 32 | void setUniform2iv(const GLchar* location, const GLint* ints, size_t numberofArrays); 33 | void setUniform3iv(const GLchar* location, const GLint* ints, size_t numberofArrays); 34 | void setUniform4iv(const GLchar* location, const GLint* ints, size_t numberofArrays); 35 | 36 | void setUniform1f(const GLchar* location, GLfloat f1); 37 | void setUniform2f(const GLchar* location, GLfloat f1, GLfloat f2); 38 | void setUniform3f(const GLchar* location, GLfloat f1, GLfloat f2, GLfloat f3); 39 | void setUniform4f(const GLchar* location, GLfloat f1, GLfloat f2, GLfloat f3, GLfloat f4); 40 | 41 | void setUniform1fv(const GLchar* location, const GLfloat* floats, size_t numberOfArrays); 42 | void setUniform2fv(const GLchar* location, const GLfloat* floats, size_t numberOfArrays); 43 | void setUniform3fv(const GLchar* location, const GLfloat* floats, size_t numberOfArrays); 44 | void setUniform4fv(const GLchar* location, const GLfloat* floats, size_t numberOfArrays); 45 | 46 | void setUniformMatrix4fv(const GLchar* location, const GLfloat* matrixArray); 47 | void setUniformMatrix3fv(const GLchar* location, const GLfloat* matrixArray); 48 | 49 | void setUniformTexture(const GLchar* location, GLint texture, GLenum target, int level = 0); 50 | private: 51 | GLuint createShader(const GLchar* source, GLuint type); 52 | 53 | GLuint _program; 54 | GLuint _vertexShader; 55 | GLuint _fragShader; 56 | 57 | map _attributes; 58 | map _uniforms; 59 | 60 | GL_NO_COPY(GLProgram); 61 | }; 62 | 63 | NS_GL_CLOSE 64 | -------------------------------------------------------------------------------- /Fairy2D/OpenGL/GLRenderTarget.cpp: -------------------------------------------------------------------------------- 1 | #include "GLRenderTarget.h" 2 | 3 | NS_GL_BEGIN 4 | 5 | GLRenderTarget::GLRenderTarget() 6 | { 7 | } 8 | 9 | BOOL GLRenderTarget::create(size_t width, size_t height) 10 | { 11 | _texture.create(width, height, NULL); 12 | 13 | glGenFramebuffers(1, &_frameBufferMSP); 14 | glBindFramebuffer(GL_FRAMEBUFFER, _frameBufferMSP); 15 | 16 | //glGenRenderbuffers(1, &_depthBufferMSP); 17 | //glBindRenderbuffer(GL_RENDERBUFFER, _depthBufferMSP); 18 | //glRenderbufferStorageMultisample(GL_RENDERBUFFER, 8, GL_DEPTH_COMPONENT, width, height); 19 | //glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_COMPONENT, 20 | // GL_RENDERBUFFER, _depthBufferMSP); 21 | 22 | // glGenRenderbuffers(1, &_textureMSP); 23 | // glBindRenderbuffer(GL_RENDERBUFFER, _textureMSP); 24 | // glRenderbufferStorageMultisample(GL_RENDERBUFFER, 8, GL_RGBA8, width, height); 25 | // glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, 26 | // GL_RENDERBUFFER, _textureMSP); 27 | 28 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _texture, 0); 29 | 30 | // glBindRenderbuffer(GL_RENDERBUFFER, 0); 31 | glBindFramebuffer(GL_FRAMEBUFFER, 0); 32 | 33 | return TRUE; 34 | } 35 | 36 | GLRenderTarget::~GLRenderTarget() 37 | { 38 | if (_frameBufferMSP != 0) { 39 | glDeleteRenderbuffers(1, &_frameBufferMSP); 40 | } 41 | 42 | if (_textureMSP != 0) { 43 | // glDeleteRenderbuffers(1, &_textureMSP); 44 | } 45 | 46 | if (_depthBufferMSP != 0) { 47 | // glDeleteRenderbuffers(1, &_depthBufferMSP); 48 | } 49 | } 50 | 51 | void GLRenderTarget::beginRender() 52 | { 53 | GLASSERT(glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE && _texture != 0); 54 | 55 | glBindFramebuffer(GL_FRAMEBUFFER, _frameBufferMSP); 56 | //glEnable(GL_MULTISAMPLE); 57 | } 58 | 59 | void GLRenderTarget::endRender() 60 | { 61 | glBindFramebuffer(GL_FRAMEBUFFER, 0); 62 | } 63 | 64 | GLTexture& GLRenderTarget::getTexture() 65 | { 66 | return _texture; 67 | } 68 | 69 | NS_GL_CLOSE -------------------------------------------------------------------------------- /Fairy2D/OpenGL/GLRenderTarget.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "GLTexture.h" 3 | 4 | NS_GL_BEGIN 5 | 6 | class GLRenderTarget 7 | { 8 | public: 9 | GLRenderTarget(); 10 | ~GLRenderTarget(); 11 | 12 | GLTexture& getTexture(); 13 | BOOL create(size_t width, size_t height); 14 | void beginRender(); 15 | void endRender(); 16 | GLenum getStatus(); 17 | private: 18 | GLTexture _texture; 19 | 20 | GLuint _textureMSP; 21 | GLuint _depthBufferMSP; 22 | GLuint _frameBufferMSP; 23 | 24 | GL_NO_COPY(GLRenderTarget); 25 | }; 26 | 27 | NS_GL_CLOSE -------------------------------------------------------------------------------- /Fairy2D/OpenGL/GLTexture.cpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "GLTexture.h" 3 | #include "stb_image.h" 4 | 5 | NS_GL_BEGIN 6 | 7 | GLTexture::GLTexture() 8 | { 9 | _texture = 0; 10 | _target = 0; 11 | _height = 0; 12 | _width = 0; 13 | } 14 | 15 | GLTexture::~GLTexture() 16 | { 17 | if (_texture != 0) { 18 | glDeleteTextures(1, &_texture); 19 | } 20 | } 21 | 22 | void GLTexture::create(size_t width, size_t height, const GLvoid* pixels) 23 | { 24 | GLASSERT(_texture == 0); 25 | 26 | glGenTextures(1, &_texture); 27 | glBindTexture(GL_TEXTURE_2D, _texture); 28 | glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 29 | glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 30 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 31 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 32 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); 33 | glBindTexture(GL_TEXTURE_2D, 0); 34 | 35 | _target = GL_TEXTURE_2D; 36 | _width = width; 37 | _height = height; 38 | } 39 | 40 | void GLTexture::create(size_t width, const GLvoid* pixels) 41 | { 42 | GLASSERT(_texture == 0); 43 | 44 | glGenTextures(1, &_texture); 45 | glBindTexture(GL_TEXTURE_1D, _texture); 46 | glTexParameterf(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 47 | glTexParameterf(GL_TEXTURE_1D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 48 | glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 49 | glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 50 | glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA, width, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); 51 | glBindTexture(GL_TEXTURE_1D, 0); 52 | 53 | _target = GL_TEXTURE_1D; 54 | _width = width; 55 | _height = 1; 56 | } 57 | 58 | void GLTexture::update(GLint offsetX, GLint offsetY, size_t width, size_t height, const GLvoid* pixels) 59 | { 60 | GLASSERT(_target == GL_TEXTURE_2D && _texture != 0); 61 | 62 | glBindTexture(GL_TEXTURE_2D, _texture); 63 | glTexSubImage2D(GL_TEXTURE_2D, 0, offsetX, offsetY, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels); 64 | glBindTexture(GL_TEXTURE_2D, 0); 65 | } 66 | 67 | void GLTexture::update(GLint x, GLint y, GLint offsetX, GLint offsetY, size_t width, size_t height) 68 | { 69 | GLASSERT(_target == GL_TEXTURE_2D && _texture != 0); 70 | 71 | glBindTexture(GL_TEXTURE_2D, _texture); 72 | glCopyTexSubImage2D(GL_TEXTURE_2D, 0, offsetX, offsetY, x, y, width, height); 73 | glBindTexture(GL_TEXTURE_2D, 0); 74 | } 75 | 76 | void GLTexture::update(GLint offsetX, size_t width, const GLvoid* pixels) 77 | { 78 | GLASSERT(_target == GL_TEXTURE_1D); 79 | 80 | glBindTexture(GL_TEXTURE_1D, _texture); 81 | glTexSubImage1D(GL_TEXTURE_1D, 0, offsetX, width, GL_RGBA, GL_UNSIGNED_BYTE, pixels); 82 | glBindTexture(GL_TEXTURE_1D, 0); 83 | } 84 | 85 | GLTexture::operator GLuint() 86 | { 87 | return _texture; 88 | } 89 | 90 | size_t GLTexture::getWidth() const 91 | { 92 | return _width; 93 | } 94 | 95 | size_t GLTexture::getHeight() const 96 | { 97 | return _height; 98 | } 99 | 100 | NS_GL_CLOSE -------------------------------------------------------------------------------- /Fairy2D/OpenGL/GLTexture.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "GLCommon.h" 3 | 4 | NS_GL_BEGIN 5 | 6 | class GLTexture 7 | { 8 | public: 9 | GLTexture(); 10 | ~GLTexture(); 11 | 12 | operator GLuint(); 13 | void create(size_t width, size_t height, const GLvoid* pixels); 14 | void update(GLint offsetX, GLint offsetY, size_t width, size_t height, const GLvoid* pixels); 15 | void update(GLint x, GLint y, GLint offsetX, GLint offsetY, size_t width, size_t height); 16 | 17 | void create(size_t width, const GLvoid* pixels); 18 | void update(GLint offsetX, size_t width, const GLvoid* pixels); 19 | size_t getWidth() const; 20 | size_t getHeight() const; 21 | private: 22 | GLuint _texture; 23 | GLenum _target; 24 | 25 | size_t _width; 26 | size_t _height; 27 | 28 | GL_NO_COPY(GLTexture); 29 | }; 30 | 31 | NS_GL_CLOSE -------------------------------------------------------------------------------- /Fairy2D/OpenGL/GLVertexArray.cpp: -------------------------------------------------------------------------------- 1 | #include "GLVertexArray.h" 2 | 3 | NS_GL_BEGIN 4 | 5 | GLVertexArray::GLVertexArray() 6 | { 7 | glGenVertexArrays(1, &_vertexArray); 8 | } 9 | 10 | GLVertexArray::~GLVertexArray() 11 | { 12 | glDeleteVertexArrays(1, &_vertexArray); 13 | } 14 | 15 | GLVertexArray::operator GLuint() 16 | { 17 | return _vertexArray; 18 | } 19 | 20 | NS_GL_CLOSE -------------------------------------------------------------------------------- /Fairy2D/OpenGL/GLVertexArray.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "GLCommon.h" 3 | 4 | NS_GL_BEGIN 5 | 6 | class GLVertexArray 7 | { 8 | public: 9 | GLVertexArray(); 10 | ~GLVertexArray(); 11 | 12 | operator GLuint(); 13 | private: 14 | GLuint _vertexArray; 15 | 16 | GL_NO_COPY(GLVertexArray); 17 | }; 18 | 19 | NS_GL_CLOSE 20 | -------------------------------------------------------------------------------- /Fairy2D/System.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #define NOCOPYASSIGN(clazz) \ 12 | clazz(const clazz&); \ 13 | clazz& operator=(const clazz&); \ 14 | \ 15 | clazz(clazz&&); \ 16 | clazz& operator=(clazz&&) 17 | 18 | #define NAMESPACE_START(space) namespace space { 19 | #define NAMESPACE_CLOSE(space) } 20 | 21 | NAMESPACE_START(System) 22 | 23 | class Mutex 24 | { 25 | NOCOPYASSIGN(Mutex); 26 | public: 27 | Mutex() 28 | { 29 | InitializeCriticalSectionAndSpinCount(&_section, 100); 30 | } 31 | 32 | ~Mutex() 33 | { 34 | DeleteCriticalSection(&_section); 35 | } 36 | 37 | void enter() 38 | { 39 | EnterCriticalSection(&_section); 40 | } 41 | 42 | void leave() 43 | { 44 | LeaveCriticalSection(&_section); 45 | } 46 | private: 47 | CRITICAL_SECTION _section; 48 | }; 49 | 50 | class MutexGuard 51 | { 52 | NOCOPYASSIGN(MutexGuard); 53 | public: 54 | MutexGuard(Mutex& mutex) : _mutex(mutex) 55 | { 56 | mutex.enter(); 57 | } 58 | 59 | ~MutexGuard() 60 | { 61 | _mutex.leave(); 62 | } 63 | private: 64 | Mutex& _mutex; 65 | }; 66 | 67 | NAMESPACE_START(Encoding) 68 | 69 | std::string unicodeToUTF8(const wchar_t* text); 70 | std::string unicodeToUTF8(const std::wstring& text); 71 | 72 | std::wstring UTF8ToUnicode(const char* utf8); 73 | std::wstring UTF8ToUnicode(const std::string& utf8); 74 | 75 | NAMESPACE_CLOSE(Encoding) 76 | 77 | NAMESPACE_START(File) 78 | 79 | class FileReader 80 | { 81 | NOCOPYASSIGN(FileReader); 82 | public: 83 | FileReader(); 84 | ~FileReader(); 85 | 86 | bool open(const std::wstring& file , DWORD createflag = OPEN_EXISTING, DWORD sharemode = 0); 87 | void close(); 88 | 89 | bool read(void* data, DWORD count); 90 | bool seek(DWORD length, DWORD method); 91 | 92 | size_t getFileSize(); 93 | size_t getPosition(); 94 | 95 | HANDLE _hFile; 96 | }; 97 | 98 | class FileWriter 99 | { 100 | NOCOPYASSIGN(FileWriter); 101 | public: 102 | FileWriter(); 103 | ~FileWriter(); 104 | 105 | bool open(const std::wstring& file , DWORD createflag = CREATE_ALWAYS, DWORD sharemode = 0); 106 | void close(); 107 | 108 | bool write(const void* data, DWORD count); 109 | bool seek(DWORD length, DWORD method); 110 | 111 | size_t getFileSize(); 112 | size_t getPosition(); 113 | 114 | HANDLE _hFile; 115 | }; 116 | 117 | bool isExists(const std::wstring& file); 118 | 119 | std::wstring getTempPath(); 120 | std::wstring getCurrentPath(); 121 | std::wstring getAppDataPath(); 122 | std::wstring getProgramFile(); 123 | 124 | std::wstring getPath(const std::wstring& file); 125 | std::wstring getName(const std::wstring& file, bool clean = false); 126 | 127 | std::vector search(const std::wstring& path, const std::wstring& what); 128 | 129 | NAMESPACE_CLOSE(File) 130 | 131 | NAMESPACE_START(Directory) 132 | 133 | bool isExists(const std::wstring& path); 134 | bool canWrite(const std::wstring& path); 135 | 136 | void prepare(const std::wstring& path); 137 | void cleanup(const std::wstring& path); 138 | 139 | std::vector search(const std::wstring& path, const std::wstring& what); 140 | 141 | NAMESPACE_CLOSE(Directory) 142 | 143 | NAMESPACE_START(String) 144 | 145 | std::vector split(const std::wstring& text, wchar_t ch); 146 | std::vector split(const std::wstring& text); 147 | 148 | void toLower(std::wstring& text); 149 | void toUpper(std::wstring& text); 150 | void replace(std::wstring& text, wchar_t old, wchar_t rep); 151 | 152 | std::wstring trim(const std::wstring&text, wchar_t ch = L' '); 153 | std::wstring format(const wchar_t* form, ...); 154 | std::wstring replace(const std::wstring& text, const std::wstring& old, const std::wstring& rep); 155 | 156 | NAMESPACE_CLOSE(String) 157 | 158 | 159 | NAMESPACE_CLOSE(System) -------------------------------------------------------------------------------- /Fairy2D/Tcmalloc/libtcmalloc_minimal.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Fairy2D/Tcmalloc/libtcmalloc_minimal.dll -------------------------------------------------------------------------------- /Fairy2D/Tcmalloc/libtcmalloc_minimal.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gmmybu/Fariy2D/46a761982500501db1cc2bfdc949bf870fdd547c/Fairy2D/Tcmalloc/libtcmalloc_minimal.lib -------------------------------------------------------------------------------- /Fairy2D/UI/Window.cpp: -------------------------------------------------------------------------------- 1 | #include "Window.h" 2 | #include 3 | 4 | static Window* s_window; 5 | 6 | static LRESULT WINAPI windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) 7 | { 8 | if (uMsg == WM_NCCREATE) { 9 | s_window->_window = hWnd; 10 | } 11 | return s_window->windowProc(uMsg, wParam, lParam); 12 | } 13 | 14 | static void prepareClass() 15 | { 16 | static bool isReady = false; 17 | 18 | if (!isReady) { 19 | WNDCLASSEX wc = {0}; 20 | wc.cbSize = sizeof(WNDCLASSEX); 21 | wc.style = CS_DBLCLKS|CS_OWNDC; 22 | wc.lpfnWndProc = windowProc; 23 | wc.hInstance = NULL; 24 | wc.hIcon = LoadIcon(NULL, MAKEINTRESOURCE(IDI_APPLICATION)); 25 | wc.hCursor = LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW)); 26 | wc.lpszClassName = WINDOW_CLASS; 27 | 28 | if (!RegisterClassEx(&wc)) { 29 | OutputDebugString(L"prepareClass Failed\n"); 30 | exit(-1); 31 | } 32 | isReady = true; 33 | } 34 | } 35 | 36 | Window::Window() : _window(NULL) 37 | { 38 | s_window = this; 39 | } 40 | 41 | Window::~Window() 42 | { 43 | s_window = nullptr; 44 | } 45 | 46 | bool Window::create( 47 | int left, 48 | int top, 49 | int width, 50 | int height, 51 | DWORD style, 52 | LPCTSTR title, 53 | HWND parent, 54 | HMENU menu, 55 | HINSTANCE instance) 56 | { 57 | prepareClass(); 58 | 59 | return CreateWindow( 60 | WINDOW_CLASS, 61 | title, 62 | style, 63 | left, 64 | top, 65 | width, 66 | height, 67 | parent, 68 | menu, 69 | instance, 70 | NULL) != NULL; 71 | } 72 | 73 | bool Window::createEx( 74 | int left, 75 | int top, 76 | int width, 77 | int height, 78 | DWORD style, 79 | DWORD styleEx, 80 | LPCTSTR title, 81 | HWND parent, 82 | HMENU menu, 83 | HINSTANCE instance) 84 | { 85 | prepareClass(); 86 | 87 | return ::CreateWindowEx( 88 | styleEx, 89 | WINDOW_CLASS, 90 | title, 91 | style, 92 | left, 93 | top, 94 | width, 95 | height, 96 | parent, 97 | menu, 98 | instance, 99 | NULL) != NULL; 100 | } 101 | 102 | LRESULT Window::windowProc(UINT uMsg, WPARAM wParam, LPARAM lParam) 103 | { 104 | if (uMsg == WM_DESTROY) { 105 | delete this; 106 | return 0; 107 | } 108 | return DefWindowProc(_window, uMsg, wParam, lParam); 109 | } 110 | 111 | bool Window::trackMouseEvent(bool hover) 112 | { 113 | TRACKMOUSEEVENT track; 114 | track.cbSize = sizeof(TRACKMOUSEEVENT); 115 | track.dwFlags = TME_LEAVE; 116 | if (hover) { 117 | track.dwFlags |= TME_HOVER; 118 | } 119 | track.hwndTrack = _window; 120 | track.dwHoverTime = HOVER_DEFAULT; 121 | return TrackMouseEvent(&track); 122 | } 123 | 124 | POINT Window::getCursorPos() 125 | { 126 | POINT point; 127 | GetCursorPos(&point); 128 | ScreenToClient(_window, &point); 129 | return point; 130 | } 131 | 132 | void Window::centerWindow() 133 | { 134 | RECT rect = getWindowRect(); 135 | int cx = rect.right - rect.left; 136 | int cy = rect.bottom - rect.top; 137 | int ys = GetSystemMetrics(SM_CYSCREEN); 138 | int xs = GetSystemMetrics(SM_CXSCREEN); 139 | setWindowPos(0, (xs - cx) / 2, (ys - cy - 100) / 2, 140 | 0, 0, SWP_NOZORDER|SWP_NOSIZE); 141 | } 142 | -------------------------------------------------------------------------------- /Fairy2D/UI/Window.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | #define HANDLER(func) LRESULT func(WPARAM wParam, LPARAM lParam) 5 | 6 | #define DECLARE_MESSAGE_MAP() \ 7 | LRESULT windowProc(UINT uMsg, WPARAM wParam, LPARAM lParam); 8 | 9 | #define BEGIN_MESSAGE_MAP(theClass, baseClass) \ 10 | LRESULT theClass::windowProc(UINT uMsg, WPARAM wParam, LPARAM lParam) \ 11 | { \ 12 | typedef baseClass base; \ 13 | switch(uMsg) \ 14 | { 15 | 16 | #define ON_MESSAGE(msg, func) \ 17 | case msg: return func(wParam, lParam); 18 | 19 | #define END_MESSAGE_MAP() \ 20 | default: \ 21 | break; \ 22 | } \ 23 | return base::windowProc(uMsg, wParam, lParam); \ 24 | } 25 | 26 | #define WINDOW_CLASS L"Fairy2DWindow" 27 | 28 | class Window 29 | { 30 | public: 31 | Window(); 32 | virtual ~Window(); 33 | 34 | bool create( 35 | int left = 0, 36 | int top = 0, 37 | int width = 0, 38 | int height = 0, 39 | DWORD style = WS_POPUP, 40 | LPCTSTR title = NULL, 41 | HWND parent = NULL, 42 | HMENU menu = NULL, 43 | HINSTANCE instance = NULL); 44 | 45 | bool createEx( 46 | int left = 0, 47 | int top = 0, 48 | int width = 0, 49 | int height = 0, 50 | DWORD style = WS_POPUP, 51 | DWORD styleEx = 0, 52 | LPCTSTR title = NULL, 53 | HWND parent = NULL, 54 | HMENU menu = NULL, 55 | HINSTANCE instance = NULL); 56 | 57 | void close() 58 | { 59 | postMessage(WM_CLOSE, 0, 0); 60 | } 61 | 62 | bool enable(BOOL bEnabled) 63 | { 64 | return EnableWindow(_window, bEnabled); 65 | } 66 | 67 | bool show(int nShow) 68 | { 69 | return ShowWindow(_window, nShow); 70 | } 71 | 72 | bool destroy() 73 | { 74 | return DestroyWindow(_window); 75 | } 76 | 77 | bool isZoomed() 78 | { 79 | return IsZoomed(_window); 80 | } 81 | 82 | bool isVisible() 83 | { 84 | return IsWindowVisible(_window); 85 | } 86 | 87 | bool isIconic() 88 | { 89 | return IsIconic(_window); 90 | } 91 | 92 | bool isFocused() 93 | { 94 | return GetFocus() == _window; 95 | } 96 | 97 | bool isActive() 98 | { 99 | return GetActiveWindow() == _window; 100 | } 101 | 102 | bool isEnabled() 103 | { 104 | return IsWindowEnabled(_window); 105 | } 106 | 107 | LONG setWindowLong(int nIndex, LONG dwNewLong) 108 | { 109 | return SetWindowLong(_window, nIndex, dwNewLong); 110 | } 111 | 112 | LONG getWindowLong(int nIndex) 113 | { 114 | return GetWindowLong(_window, nIndex); 115 | } 116 | 117 | bool setWindowPos(HWND hWndInsertAfter, int X, int Y, int cx, int cy, UINT uFlags) 118 | { 119 | return SetWindowPos(_window, hWndInsertAfter, X, Y, cx, cy, uFlags); 120 | } 121 | 122 | LRESULT sendMessage(UINT Msg, WPARAM wParam, LPARAM lParam) 123 | { 124 | return SendMessage(_window, Msg, wParam, lParam); 125 | } 126 | 127 | bool postMessage(UINT Msg, WPARAM wParam, LPARAM lParam) 128 | { 129 | return PostMessage(_window, Msg, wParam, lParam); 130 | } 131 | 132 | RECT getWindowRect() 133 | { 134 | RECT rect; 135 | GetWindowRect(_window, &rect); 136 | return rect; 137 | } 138 | 139 | RECT getClientRect() 140 | { 141 | RECT rect; 142 | GetClientRect(_window, &rect); 143 | return rect; 144 | } 145 | 146 | bool invalidateRect(RECT* rect, BOOL bErase = FALSE) 147 | { 148 | return InvalidateRect(_window, rect, bErase); 149 | } 150 | 151 | bool update() 152 | { 153 | return UpdateWindow(_window); 154 | } 155 | 156 | bool screenToClient(POINT* point) 157 | { 158 | return ScreenToClient(_window, point); 159 | } 160 | 161 | bool clientToScreen(POINT* point) 162 | { 163 | return ClientToScreen(_window, point); 164 | } 165 | 166 | POINT getCursorPos(); 167 | void centerWindow(); 168 | 169 | bool trackMouseEvent(bool bHover); 170 | 171 | virtual LRESULT windowProc(UINT msg, WPARAM wParam, LPARAM lParam); 172 | 173 | HWND _window; 174 | }; -------------------------------------------------------------------------------- /Fairy2D/main.cpp: -------------------------------------------------------------------------------- 1 | #include "LuaVM.h" 2 | #include "System.h" 3 | #include "GameWindow.h" 4 | 5 | using namespace System; 6 | 7 | int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR lpCmdLine, int nShowCmd) 8 | { 9 | GameWindow* window = new GameWindow; 10 | window->create(0, 0, 600, 480, WS_OVERLAPPEDWINDOW&~WS_MAXIMIZEBOX); 11 | 12 | wchar_t file[MAX_PATH]; 13 | GetModuleFileName(NULL, file, MAX_PATH); 14 | LuaVM::instance().start(File::getPath(file) + L"\\main.lua"); 15 | 16 | window->update(); 17 | window->show(SW_NORMAL); 18 | window->centerWindow(); 19 | 20 | LARGE_INTEGER interval; 21 | LARGE_INTEGER freq; 22 | QueryPerformanceFrequency(&freq); 23 | interval.QuadPart = freq.QuadPart / 120; 24 | 25 | LARGE_INTEGER nLast; 26 | QueryPerformanceCounter(&nLast); 27 | 28 | MSG msg; 29 | LARGE_INTEGER nNow; 30 | while (true) 31 | { 32 | if (!PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) 33 | { 34 | QueryPerformanceCounter(&nNow); 35 | 36 | LONGLONG delta = nNow.QuadPart - nLast.QuadPart; 37 | if (delta > interval.QuadPart) 38 | { 39 | nLast.QuadPart = nNow.QuadPart; 40 | LuaVM::instance().update(delta * 1.f / freq.QuadPart); 41 | LuaVM::instance().render(); 42 | } 43 | continue; 44 | } 45 | 46 | if (WM_QUIT == msg.message) 47 | break; 48 | 49 | TranslateMessage(&msg); 50 | DispatchMessage(&msg); 51 | } 52 | return 0; 53 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Fariy2D 2 | Simple 2D Game Engine powered by OpenGL and Lua 3 | 4 | 5 | 6 | 0 参考了ejoy2d,cocos2dx,love2d等,文字绘制功能照搬的ejoyed,场景管理基本照搬的cocos2dx 7 | 8 | 1 用到的第三方库包括lua,tcmalloc,stb_image,glew等 9 | 10 | 2 程序最大的优点是简单明了,最大的缺点是绘制图形时没有合并batch,绘一张图提交一次。(不过可以修改lua来合并batch) 11 | 12 | 3 代码比较规范除了某个头文件使用了using namespace std; 13 | 14 | 4 Bin下的文件使用前请杀毒。Fairy2d.exe启动时自动加载main.lua的代码,修改main-tower.lua以及main-bomb.lua为main.lua再运行Fairy2d.exe来启动不同的demo,demo仅起功能演示作用,不完善。Dbgview.exe是为了调试用的,错误信息通过OutputDebugString输出的,可以用Dbgview.exe看到。。。 15 | 16 | 5 做这个最初的想法是用C++提供最基本的功能,用lua来实现游戏框架以及游戏业务,通过lua库来扩展游戏功能 17 | 18 | 6 Bin的说明:Resource放的素材,Bomb,Tower,Tank,Snake放的demo的业务逻辑。GL是OpenGL的图形操作的封装。DS是基本的数据结构。Net是luaSocket。 Tower和Tank下的scene.lua封装的是简单游戏框架。 --------------------------------------------------------------------------------