Skip to content

Commit

Permalink
Merge branch 'master' into lunalua-0.7.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinW1998 committed Oct 30, 2015
2 parents 5f776b1 + a8c5a1c commit b44bb33
Show file tree
Hide file tree
Showing 10 changed files with 145 additions and 28 deletions.
16 changes: 14 additions & 2 deletions LuaScriptsLib/core/defines.lua
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ local defines = {
player_link_shieldEnabled = {defValue = true, minVal = nil, maxVal = nil, address = nil, size = FIELD_BOOLEAN,
n = 1, group = "Player Settings: Link", desc = "If the shield of link is enabled.",
customFuncGet = function()
return mem(0x00A53042, FIELD_BYTE) == 0x90
return mem(0x00A53042, FIELD_BYTE) ~= 0x90
end,
customFuncSet = function(value)
if(value)then
Expand All @@ -102,6 +102,18 @@ local defines = {
mem(0x00A53047, FIELD_BYTE, 0x90)
mem(0x00A53048, FIELD_BYTE, 0x90)
end
end},
player_link_fairyVineEnabled = {defValue = true, minVal = nil, maxVal = nil, address = nil, size = FIELD_BOOLEAN,
n = 2, group = "Player Settings: Link", desc = "If the vine fairy is enabled",
customFuncGet = function()
return mem(0x009AAF93, FIELD_BYTE) == 0x5
end,
customFuncSet = function(value)
if(value)then
mem(0x009AAF93, FIELD_BYTE, 0x5)
else
mem(0x009AAF93, FIELD_BYTE, 0xFF)
end
end}
}

Expand All @@ -123,7 +135,7 @@ end

local function getDefine(defTable)
if(defTable.customFuncGet)then
defTable.customFuncGet()
return defTable.customFuncGet()
else
return mem(defTable.address, defTable.size)
end
Expand Down
1 change: 1 addition & 0 deletions LunaDll/Changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ v0.7.2 BETA:
* Added some new Defines (Defines.* namespace)
* Added switch between letterbox-mode (forced 4:3) or scretched-mode via F4
* Bugfix [LunaLua and SMBX Engine]: Decimal numbers now work perfectly in layer speed and npc codes (Thanks to DarkMecha for testing!)
* Bugfix [LunaLua and SMBX Engine]: Fullscreen in the level editor works again!
* Added printTextWP, drawImageWP, drawImageToSceneWP which enables rendering with priority settings (also known as Z-Index)
* Added sounds.ini on level-basis

Expand Down
6 changes: 5 additions & 1 deletion LunaDll/Defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
#define LUNALUA_VERSION "LUNALUA V0.7.0.3 BETA"
#endif


// Common PGE Engine and LunaLUA constant to identify which engine is uses to run lunadll.lua script
// This need to have able use same lunadll.lua script with both PGE Engine and LunaLUA.
// PGE Engine going to have similar to LunaLUA API, but some super-special functions like mem() will NOT be made
// at PGE Engine because useless with PGE's opened API.
#define GAME_ENGINE "LunaLUA"

#define LUNA_VERSION 8
#define COMPILE_PLAYGROUND 0 //See Misc/Playground.cpp
Expand Down
3 changes: 3 additions & 0 deletions LunaDll/LuaMain/LunaLuaMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ void CLunaLua::init(LuaLunaType type, std::wstring codePath, std::wstring levelP
void CLunaLua::setupDefaults()
{
object _G = globals(L);
_G["GAME_ENGINE"] = GAME_ENGINE;
_G["LUNALUA_VER"] = LUNALUA_VERSION;

_G["PLAYER_SMALL"] = PLAYER_SMALL;
_G["PLAYER_BIG"] = PLAYER_BIG;
_G["PLAYER_FIREFLOWER"] = PLAYER_FIREFLOWER;
Expand Down
16 changes: 16 additions & 0 deletions LunaDll/Rendering/GLCompat.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,22 @@ static inline GLenum glCheckFramebufferStatusANY(GLenum target) {
}
return GL_FRAMEBUFFER_UNSUPPORTED_EXT;
}
static inline void glDeleteFramebuffersANY(GLsizei n, GLuint *framebuffers) {
if (GLEW_VERSION_3_0 || GLEW_ARB_framebuffer_object) {
glDeleteFramebuffers(n, framebuffers);
}
else if (GLEW_EXT_framebuffer_object) {
glDeleteFramebuffersEXT(n, framebuffers);
}
}
static inline void glDeleteRenderbuffersANY(GLsizei n, GLuint *renderbuffers) {
if (GLEW_VERSION_3_0 || GLEW_ARB_framebuffer_object) {
glDeleteRenderbuffers(n, renderbuffers);
}
else if (GLEW_EXT_framebuffer_object) {
glDeleteRenderbuffersEXT(n, renderbuffers);
}
}

// Core in OpenGL >=1.4
static inline void glBlendFuncSeparateANY(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
Expand Down
63 changes: 60 additions & 3 deletions LunaDll/Rendering/GLContextManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,20 @@ GLContextManager g_GLContextManager;
GLContextManager::GLContextManager() :
hDC(NULL), hCTX(NULL),
mInitialized(false), mHadError(false),
mFB(0), mColorRB(0), mDepthRB(0),
mFB(0), mDepthRB(0),
mBufTex(NULL, 800, 600) {
}

bool GLContextManager::Init(HDC hDC) {
// Note: In future versions, check if the hDC is different, and if so
// re-init.
// If we're switching HDCs, deal with it...
if (mInitialized && !mHadError && hDC != this->hDC) {
// If we're switching HDCs, deal with it...
g_GLDraw.UnbindTexture(); // Unbind current texture
g_GLTextureStore.Reset(); // Delete all textures
ReleaseFramebuffer(); // Release framebuffer
ReleaseContext(); // Release context
mInitialized = false;
}

// Don't re-run if already run
if (mInitialized || mHadError) return true;
Expand Down Expand Up @@ -72,6 +79,8 @@ bool GLContextManager::InitContextFromHDC(HDC hDC) {
pfd.cDepthBits = 32;
pfd.iLayerType = PFD_MAIN_PLANE;

mOldPixelFormat = GetPixelFormat(hDC);

int nPixelFormat = ChoosePixelFormat(hDC, &pfd);
if (0 == nPixelFormat)
return false;
Expand Down Expand Up @@ -197,3 +206,51 @@ bool GLContextManager::InitProjectionAndState() {
}


void GLContextManager::ReleaseFramebuffer() {
// Unbind framebuffer
glBindFramebufferANY(GL_FRAMEBUFFER_EXT, 0);
GLERRORCHECK();

// Unbind texture just in case
g_GLDraw.UnbindTexture();

// Delete framebuffer
if (mFB) {
glDeleteFramebuffersANY(1, &mFB);
GLERRORCHECK();
mFB = 0;
}

// Delete depth renderbuffer
if (mDepthRB) {
glDeleteRenderbuffersANY(1, &mDepthRB);
GLERRORCHECK();
mDepthRB = 0;
}

// Delete texture
if (mBufTex.name) {
glDeleteTextures(1, &mBufTex.name);
GLERRORCHECK();
mBufTex.name = 0;
}
}

void GLContextManager::ReleaseContext() {
// Delete Context
if (hCTX) {
wglMakeCurrent(NULL, NULL);
wglDeleteContext(hCTX);
hCTX = NULL;
}

// Restore pixel format if necessary
if (mOldPixelFormat != GetPixelFormat(hDC)) {
PIXELFORMATDESCRIPTOR pfd;
DescribePixelFormat(hDC, mOldPixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
SetPixelFormat(hDC, mOldPixelFormat, &pfd);
}

// Clear hDC
hDC = NULL;
}
12 changes: 9 additions & 3 deletions LunaDll/Rendering/GLContextManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,26 @@ class GLContextManager {
private:
bool mInitialized;
bool mHadError;

// Context variables
int mOldPixelFormat;
HDC hDC;
HGLRC hCTX;

// Framebuffer variables
// TODO: Move framebuffer into a class.
GLuint mFB;
GLuint mColorRB;
GLuint mDepthRB;
GLDraw::Texture mBufTex;

// Init functions
bool InitContextFromHDC(HDC hDC);
bool InitFramebuffer();
bool InitProjectionAndState();

// TODO: Implement the following to support switching hDCs
// void ReleaseContext()
// Release functions
void ReleaseContext();
void ReleaseFramebuffer();
};

// Instance
Expand Down
17 changes: 9 additions & 8 deletions LunaDll/Rendering/GLEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,16 @@ BOOL GLEngine::EmulatedStretchBlt(HDC hdcDest, int nXOriginDest, int nYOriginDes
HDC hdcSrc, int nXOriginSrc, int nYOriginSrc, int nWidthSrc, int nHeightSrc,
DWORD dwRop)
{
// TODO: This block of code will need to be changed once
// GLContextManager is modified to handle re-init
// with a new hDC
if (!g_GLContextManager.IsInitialized()) {
if (!g_GLContextManager.Init(hdcDest)) {
dbgboxA("Failed to init...");
} else {
static bool runOnce = true;
if (!g_GLContextManager.Init(hdcDest)) {
dbgboxA("Failed to init...");
} else {
// TODO: Move mGifRecorder initialization somewhere else. It can't be
// in the constructor due to when the constructor
if (runOnce) {
mGifRecorder.init();
}
runOnce = false;
}
}

if (!g_GLContextManager.IsInitialized()) return FALSE;
Expand Down
36 changes: 25 additions & 11 deletions LunaDll/Rendering/GLTextureStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,20 @@ GLTextureStore::GLTextureStore() {
mSmbxTexMap.clear();
}

void GLTextureStore::Reset() {
ClearSMBXSprites();
ClearLunaTextures();
}

void GLTextureStore::ClearLunaTextures() {
for (const auto i : mLunaTexMap) {
glDeleteTextures(1, &i.second->name);
GLERRORCHECK();
delete i.second;
}
mLunaTexMap.clear();
}

void GLTextureStore::ClearSMBXSprites()
{
for (const auto i : mSmbxTexMap) {
Expand All @@ -20,6 +34,17 @@ void GLTextureStore::ClearSMBXSprites()
mSmbxTexMap.clear();
}

void GLTextureStore::ClearLunaTexture(const BMPBox& bmp)
{
auto it = mLunaTexMap.find(&bmp);
if (it != mLunaTexMap.end()) {
glDeleteTextures(1, &it->second->name);
GLERRORCHECK();
delete it->second;
mLunaTexMap.erase(it);
}
}

const GLSprite* GLTextureStore::SpriteFromSMBXBitmap(HDC hdc) {
uint32_t w;
uint32_t h;
Expand Down Expand Up @@ -87,17 +112,6 @@ const GLSprite* GLTextureStore::SpriteFromSMBXBitmap(HDC hdc) {
return sprite;
}

void GLTextureStore::ClearLunaTexture(const BMPBox& bmp)
{
auto it = mLunaTexMap.find(&bmp);
if (it != mLunaTexMap.end()) {
glDeleteTextures(1, &it->second->name);
GLERRORCHECK();
delete it->second;
mLunaTexMap.erase(it);
}
}

const GLDraw::Texture* GLTextureStore::TextureFromLunaBitmap(const BMPBox& bmp)
{
if (bmp.m_hbmp == NULL) return NULL;
Expand Down
3 changes: 3 additions & 0 deletions LunaDll/Rendering/GLTextureStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ class GLTextureStore {
std::unordered_map<HDC, const GLSprite*> mSmbxTexMap;
std::unordered_map<const BMPBox*, const GLDraw::Texture*> mLunaTexMap;

void Reset();

GLTextureStore();
void ClearSMBXSprites();
const GLSprite* SpriteFromSMBXBitmap(HDC hdc);

void ClearLunaTextures();
void ClearLunaTexture(const BMPBox& bmp);
const GLDraw::Texture* TextureFromLunaBitmap(const BMPBox& bmp);
};
Expand Down

0 comments on commit b44bb33

Please sign in to comment.