This commit is contained in:
Jonas Kulla 2014-01-02 00:11:57 +01:00
commit a0a27889a3
22 changed files with 602 additions and 100 deletions

2
.gitignore vendored
View File

@ -9,3 +9,5 @@ Makefile
mkxp
xxd+
/build

378
CMakeLists.txt Normal file
View File

@ -0,0 +1,378 @@
cmake_minimum_required(VERSION 2.8.11)
Project(mkxp)
## Setup options ##
option(RGSS2 "Enable RGSS2" ON)
option(FORCE32 "Force 32bit compile on 64bit OS" OFF)
set(BINDING "MRI" CACHE STRING "The Binding Type (MRI, MRUBY, NULL)")
set(EXTERNAL_LIB_PATH "" CACHE PATH "External precompiled lib prefix")
## Misc setup ##
include(cmake/PrepUtils.cmake)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
IF("${CMAKE_SYSTEM}" MATCHES "Linux")
SET(LINUX ON)
ENDIF()
IF(FORCE32)
if(APPLE)
SET(CMAKE_OSX_ARCHITECTURES "i386")
else()
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32")
endif()
ENDIF()
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.6)
IF(LINUX)
if(CMAKE_SIZEOF_VOID_P MATCHES "8" AND NOT(FORCE32) )
set(CMAKE_EXECUTABLE_SUFFIX ".bin.x86_64")
set(BIN_RPATH "\$ORIGIN/lib64")
set(LIB_PATH "lib64")
else()
set(CMAKE_EXECUTABLE_SUFFIX ".bin.x86")
set(BIN_RPATH "\$ORIGIN/lib")
set(LIB_PATH "lib")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_FILE_OFFSET_BITS=64")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_FILE_OFFSET_BITS=64")
endif()
elseif(APPLE)
SET(BIN_RPATH "@executable_path/../Frameworks")
set(LIB_PATH "lib")
endif()
set(CMAKE_SKIP_BUILD_RPATH TRUE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
set(CMAKE_INSTALL_RPATH ${BIN_RPATH})
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE)
## Locate core libs ##
find_package(PkgConfig REQUIRED)
if (EXTERNAL_LIB_PATH)
set(CMAKE_PREFIX_PATH ${EXTERNAL_LIB_PATH})
if(EXISTS "${EXTERNAL_LIB_PATH}/${LIB_PATH}/pkgconfig/")
SET(ENV{PKG_CONFIG_PATH} "${EXTERNAL_LIB_PATH}/${LIB_PATH}/pkgconfig/")
endif()
if(APPLE)
set(PLATFORM_SHARED_LIBS
libSDL2.dylib libSDL2_image-2.0.0.dylib libSDL2_ttf-2.0.0.dylib libSDL_sound-1.0.1.dylib
libfreetype.6.dylib libsigc-2.0.0.dylib
CACHE STRING "List of shared libraries that need to be copied into the OS X bundle")
foreach(lib ${PLATFORM_SHARED_LIBS})
if(EXISTS ${EXTERNAL_LIB_PATH}/lib/${lib})
list(APPEND PLATFORM_COPY_LIBS
${EXTERNAL_LIB_PATH}/lib/${lib}
)
endif()
endforeach()
endif()
endif()
pkg_check_modules(SIGCXX REQUIRED sigc++-2.0)
pkg_check_modules(PIXMAN REQUIRED pixman-1)
pkg_check_modules(PHYSFS REQUIRED physfs>=2.1)
pkg_check_modules(SDL2 REQUIRED sdl2)
pkg_check_modules(SDL2_TTF REQUIRED SDL2_ttf)
pkg_check_modules(SDL2_IMAGE REQUIRED SDL2_image)
pkg_check_modules(SDL_SOUND REQUIRED SDL_sound)
find_package(GLEW 1.9.0 REQUIRED)
find_package(Boost 1.49 COMPONENTS program_options REQUIRED)
find_package(OpenAL REQUIRED)
find_package(OpenGL REQUIRED)
find_package(ZLIB REQUIRED)
## Setup main source ##
set(MAIN_HEADERS
src/quadarray.h
src/audio.h
src/binding.h
src/bitmap.h
src/disposable.h
src/etc.h
src/etc-internal.h
src/eventthread.h
src/flashable.h
src/font.h
src/input.h
src/plane.h
src/scene.h
src/sprite.h
src/table.h
src/texpool.h
src/tilequad.h
src/transform.h
src/viewport.h
src/window.h
src/serializable.h
src/shader.h
src/glstate.h
src/quad.h
src/tilemap.h
src/graphics.h
src/debuglogger.h
src/global-ibo.h
src/exception.h
src/filesystem.h
src/serial-util.h
src/intrulist.h
src/binding.h
src/gl-util.h
src/util.h
src/config.h
src/tileatlas.h
src/perftimer.h
src/sharedstate.h
src/al-util.h
src/boost-hash.h
src/debugwriter.h
)
set(MAIN_SOURCE
src/main.cpp
src/audio.cpp
src/bitmap.cpp
src/eventthread.cpp
src/filesystem.cpp
src/font.cpp
src/input.cpp
src/plane.cpp
src/scene.cpp
src/sprite.cpp
src/table.cpp
src/tilequad.cpp
src/viewport.cpp
src/window.cpp
src/texpool.cpp
src/shader.cpp
src/glstate.cpp
src/tilemap.cpp
src/autotiles.cpp
src/graphics.cpp
src/debuglogger.cpp
src/etc.cpp
src/config.cpp
src/tileatlas.cpp
src/perftimer.cpp
src/sharedstate.cpp
)
source_group("MKXP Source" FILES ${MAIN_SOURCE} ${MAIN_HEADERS})
## Setup embedded source ##
set(EMBEDDED_INPUT
shader/transSimple.frag
shader/trans.frag
shader/hue.frag
shader/sprite.frag
shader/plane.frag
shader/bitmapBlit.frag
shader/simple.frag
shader/simpleColor.frag
shader/simpleAlpha.frag
shader/flashMap.frag
shader/simple.vert
shader/simpleColor.vert
shader/sprite.vert
assets/liberation.ttf
)
if (RGSS2)
list(APPEND EMBEDDED_INPUT
shader/blur.frag
shader/blurH.vert
shader/blurV.vert
shader/simpleMatrix.vert
)
endif()
## Process Embeddeds ##
find_program(XXD_EXE xxd
DOC "Location of the xxd executable"
)
macro(ProcessWithXXD outvar inputfile outdir)
get_filename_component(basefile ${inputfile} NAME)
set(outputfile ${outdir}/${basefile}.xxd)
set_source_files_properties(${outputfile} PROPERTIES HEADER_ONLY TRUE)
add_custom_command(
OUTPUT ${outputfile}
COMMAND ${XXD_EXE} -i ${inputfile} ${outputfile}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS ${inputfile}
COMMENT "Generating XXD for ${inputfile}"
)
list(APPEND ${outvar}
${outputfile}
)
endmacro()
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/xxdhack)
include_directories(
${CMAKE_CURRENT_BINARY_DIR}/xxdhack
)
foreach(item ${EMBEDDED_INPUT})
ProcessWithXXD(EMBEDDED_SOURCE ${item} ${CMAKE_CURRENT_BINARY_DIR})
endforeach()
source_group("Embedded Source" FILES ${EMBEDDED_INPUT} ${EMBEDDED_SOURCE})
## Setup binding source ##
if (BINDING STREQUAL "MRI")
set(MRIVERSION "2.0" CACHE STRING "Version of MRI to link with")
pkg_check_modules(MRI REQUIRED ruby-${MRIVERSION})
list(APPEND DEFINES
BINDING_MRI
)
set(BINDING_HEADERS
binding-mri/binding-util.h
binding-mri/binding-types.h
binding-mri/serializable-binding.h
binding-mri/disposable-binding.h
binding-mri/sceneelement-binding.h
binding-mri/viewportelement-binding.h
binding-mri/flashable-binding.h
)
set(BINDING_SOURCE
binding-mri/binding-mri.cpp
binding-mri/binding-util.cpp
binding-mri/table-binding.cpp
binding-mri/etc-binding.cpp
binding-mri/bitmap-binding.cpp
binding-mri/font-binding.cpp
binding-mri/graphics-binding.cpp
binding-mri/input-binding.cpp
binding-mri/sprite-binding.cpp
binding-mri/viewport-binding.cpp
binding-mri/plane-binding.cpp
binding-mri/window-binding.cpp
binding-mri/tilemap-binding.cpp
binding-mri/audio-binding.cpp
binding-mri/module_rpg.cpp
binding-mri/filesystem-binding.cpp
)
elseif(BINDING STREQUAL "MRUBY")
message(FATAL_ERROR "Mruby support in CMake needs to be finished")
list(APPEND DEFINES
BINDING_MRUBY
)
set(BINDING_HEADERS
binding-mruby/binding-util.h
binding-mruby/disposable-binding.h
binding-mruby/flashable-binding.h
binding-mruby/binding-types.h
binding-mruby/sceneelement-binding.h
binding-mruby/viewportelement-binding.h
binding-mruby/serializable-binding.h
binding-mruby/mrb-ext/file.h
binding-mruby/mrb-ext/rwmem.h
binding-mruby/mrb-ext/marshal.h
)
set(BINDING_SOURCE
binding-mruby/binding-mruby.cpp
binding-mruby/binding-util.cpp
binding-mruby/window-binding.cpp
binding-mruby/bitmap-binding.cpp
binding-mruby/sprite-binding.cpp
binding-mruby/font-binding.cpp
binding-mruby/viewport-binding.cpp
binding-mruby/plane-binding.cpp
binding-mruby/audio-binding.cpp
binding-mruby/tilemap-binding.cpp
binding-mruby/etc-binding.cpp
binding-mruby/graphics-binding.cpp
binding-mruby/input-binding.cpp
binding-mruby/table-binding.cpp
binding-mruby/module_rpg.c
binding-mruby/mrb-ext/file.cpp
binding-mruby/mrb-ext/marshal.cpp
binding-mruby/mrb-ext/rwmem.cpp
binding-mruby/mrb-ext/kernel.cpp
binding-mruby/mrb-ext/time.cpp
)
elseif(BINDING STREQUAL "NULL")
set(BINDING_SOURCE
binding-null/binding-null.cpp
)
else()
message(FATAL_ERROR "Must choose a valid binding type. MRI, MRUBY, or NULL")
endif()
source_group("Binding Source" FILES ${BINDING_SOURCE} ${BINDING_HEADERS})
## Setup main executable ##
if(APPLE)
find_library(CARBON_LIBRARY Carbon)
find_library(IOKIT_LIBRARY IOKit)
mark_as_advanced(CARBON_LIBRARY IOKIT_LIBRARY)
list(APPEND PLATFORM_LIBRARIES
${CARBON_LIBRARY}
${IOKIT_LIBRARY}
)
endif()
link_directories(
${SIGCXX_LIBRARY_DIRS}
${PIXMAN_LIBRARY_DIRS}
${PHYSFS_LIBRARY_DIRS}
${SDL2_LIBRARY_DIRS} # Blindly assume other SDL bits are in same directory
${Boost_LIBRARY_DIR}
${MRI_LIBDIR}
)
add_executable(${PROJECT_NAME} MACOSX_BUNDLE
${MAIN_HEADERS}
${MAIN_SOURCE}
${BINDING_HEADERS}
${BINDING_SOURCE}
${EMBEDDED_SOURCE}
)
target_compile_definitions(${PROJECT_NAME} PRIVATE
${DEFINES}
)
target_include_directories(${PROJECT_NAME} PRIVATE
src
${SIGCXX_INCLUDE_DIRS}
${PIXMAN_INCLUDE_DIRS}
${PHYSFS_INCLUDE_DIRS}
${SDL2_INCLUDE_DIRS} # Blindly assume other SDL bits are in same directory
${Boost_INCLUDE_DIR}
${GLEW_INCLUDE_DIR}/GL
${MRI_INCLUDE_DIRS}
${OPENAL_INCLUDE_DIR}
)
target_link_libraries(${PROJECT_NAME}
${SIGCXX_LIBRARIES}
${SDL2_LIBRARIES}
${SDL2_IMAGE_LIBRARIES}
${SDL2_TTF_LIBRARIES}
${SDL_SOUND_LIBRARIES}
${PHYSFS_LIBRARIES}
${PIXMAN_LIBRARIES}
${Boost_LIBRARIES}
${MRI_LIBRARIES}
${OPENAL_LIBRARY}
${OPENGL_gl_LIBRARY}
${GLEW_LIBRARY}
${ZLIB_LIBRARY}
${PLATFORM_LIBRARIES}
)
PostBuildMacBundle(${PROJECT_NAME} "" "${PLATFORM_COPY_LIBS}")

View File

@ -226,7 +226,7 @@ static void runRMXPScripts()
VALUE scriptString = rb_ary_entry(script, 2);
int result = Z_OK;
ulong bufferLen;
unsigned long bufferLen;
while (true)
{

View File

@ -94,7 +94,7 @@ void raiseRbExc(const Exception &exc)
RbData *data = getRbData();
VALUE excClass = data->exc[excToRbExc[exc.type]];
rb_raise(excClass, exc.msg.c_str());
rb_raise(excClass, "%s", exc.msg.c_str());
}
int
@ -148,7 +148,7 @@ rb_get_args(int argc, VALUE *argv, const char *format, ...)
VALUE *str = va_arg(ap, VALUE*);
VALUE tmp = *arg;
if (!rb_type(tmp) == RUBY_T_STRING)
if (!(rb_type(tmp) == RUBY_T_STRING))
rb_raise(rb_eTypeError, "Argument %d: Expected string", argI);
*str = tmp;
@ -167,7 +167,7 @@ rb_get_args(int argc, VALUE *argv, const char *format, ...)
VALUE tmp = *arg;
if (!rb_type(tmp) == RUBY_T_STRING)
if (!(rb_type(tmp) == RUBY_T_STRING))
rb_raise(rb_eTypeError, "Argument %d: Expected string", argI);
*s = RSTRING_PTR(tmp);
@ -186,7 +186,7 @@ rb_get_args(int argc, VALUE *argv, const char *format, ...)
VALUE tmp = *arg++;
if (!rb_type(tmp) == RUBY_T_STRING)
if (!(rb_type(tmp) == RUBY_T_STRING))
rb_raise(rb_eTypeError, "Argument %d: Expected string", argI);
*s = RSTRING_PTR(tmp);

View File

@ -24,6 +24,8 @@
#include <ruby.h>
#include "exception.h"
enum RbException
{
RGSS = 0,
@ -91,7 +93,7 @@ template<class C>
static inline C *
getPrivateDataCheck(VALUE self, const rb_data_type_struct &type)
{
void *obj = rb_check_typeddata(self, &type);
void *obj = Check_TypedStruct(self, &type);
return static_cast<C*>(obj);
}
@ -195,11 +197,11 @@ rb_float_arg(VALUE arg, double *out, int argPos = 0)
switch (rb_type(arg))
{
case RUBY_T_FLOAT :
*out = rb_float_value(arg);
*out = RFLOAT_VALUE(arg);
break;
case RUBY_T_FIXNUM :
*out = rb_fix2int(arg);
*out = FIX2INT(arg);
break;
default:
@ -214,11 +216,11 @@ rb_int_arg(VALUE arg, int *out, int argPos = 0)
{
case RUBY_T_FLOAT :
// FIXME check int range?
*out = rb_num2long(arg);
*out = NUM2LONG(arg);
break;
case RUBY_T_FIXNUM :
*out = rb_fix2int(arg);
*out = FIX2INT(arg);
break;
default:

View File

@ -47,18 +47,18 @@ RB_METHOD(tableResize)
{
default:
case 1:
t->resize(rb_fix2int(argv[0]));
t->resize(FIX2INT(argv[0]));
return Qnil;
case 2:
t->resize(rb_fix2int(argv[0]),
rb_fix2int(argv[1]));
t->resize(FIX2INT(argv[0]),
FIX2INT(argv[1]));
return Qnil;
case 3:
t->resize(rb_fix2int(argv[0]),
rb_fix2int(argv[1]),
rb_fix2int(argv[2]));
t->resize(FIX2INT(argv[0]),
FIX2INT(argv[1]),
FIX2INT(argv[2]));
return Qnil;
}
}
@ -82,11 +82,11 @@ RB_METHOD(tableGetAt)
int x, y, z;
x = y = z = 0;
x = rb_num2int(argv[0]);
x = NUM2INT(argv[0]);
if (argc > 1)
y = rb_num2int(argv[1]);
y = NUM2INT(argv[1]);
if (argc > 2)
z = rb_num2int(argv[2]);
z = NUM2INT(argv[2]);
if (argc > 3)
rb_raise(rb_eArgError, "wrong number of arguments");
@ -117,21 +117,21 @@ RB_METHOD(tableSetAt)
{
default:
case 2 :
x = rb_fix2int(argv[0]);
value = rb_fix2int(argv[1]);
x = FIX2INT(argv[0]);
value = FIX2INT(argv[1]);
break;
case 3 :
x = rb_fix2int(argv[0]);
y = rb_fix2int(argv[1]);
value = rb_fix2int(argv[2]);
x = FIX2INT(argv[0]);
y = FIX2INT(argv[1]);
value = FIX2INT(argv[2]);
break;
case 4 :
x = rb_fix2int(argv[0]);
y = rb_fix2int(argv[1]);
z = rb_fix2int(argv[2]);
value = rb_fix2int(argv[3]);
x = FIX2INT(argv[0]);
y = FIX2INT(argv[1]);
z = FIX2INT(argv[2]);
value = FIX2INT(argv[3]);
break;
}

View File

@ -303,7 +303,7 @@ runRMXPScripts(mrb_state *mrb, mrbc_context *ctx)
(void) scriptChksum;
int result = Z_OK;
ulong bufferLen;
unsigned long bufferLen;
while (true)
{

38
cmake/PrepUtils.cmake Normal file
View File

@ -0,0 +1,38 @@
if(APPLE)
function(PostBuildMacBundle target framework_list lib_list)
INCLUDE(BundleUtilities)
GET_TARGET_PROPERTY(_BIN_NAME ${target} LOCATION)
GET_DOTAPP_DIR(${_BIN_NAME} _BUNDLE_DIR)
set(_SCRIPT_FILE "${CMAKE_CURRENT_BINARY_DIR}/${target}_prep.cmake")
file(WRITE ${_SCRIPT_FILE}
"# Generated Script file\n"
"include(BundleUtilities)\n"
"get_bundle_and_executable(\"\${BUNDLE_APP}\" bundle executable valid)\n"
"if(valid)\n"
" set(framework_dest \"\${bundle}/Contents/Frameworks\")\n"
" foreach(framework_path ${framework_list})\n"
" get_filename_component(framework_name \${framework_path} NAME_WE)\n"
" file(MAKE_DIRECTORY \"\${framework_dest}/\${framework_name}.framework/Versions/A/\")\n"
" copy_resolved_framework_into_bundle(\${framework_path}/Versions/A/\${framework_name} \${framework_dest}/\${framework_name}.framework/Versions/A/\${framework_name})\n"
" endforeach()\n"
" foreach(lib ${lib_list})\n"
" get_filename_component(lib_file \${lib} NAME)\n"
" copy_resolved_item_into_bundle(\${lib} \${framework_dest}/\${lib_file})\n"
" endforeach()\n"
"else()\n"
" message(ERROR \"App Not found? \${BUNDLE_APP}\")\n"
"endif()\n"
"#fixup_bundle(\"\${BUNDLE_APP}\" \"\" \"\${DEP_LIB_DIR}\")\n"
)
ADD_CUSTOM_COMMAND(TARGET ${target}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -DBUNDLE_APP="${_BUNDLE_DIR}" -P "${_SCRIPT_FILE}"
)
endfunction()
else()
function(PostBuildMacBundle target framework_list lib_list)
# noop
endfunction()
endif()

View File

@ -33,7 +33,7 @@ void main()
/* Apply bush alpha by mathematical if */
float underBush = float(v_texCoord.y < bushDepth);
frag.a *= clamp(bushOpacity + underBush, 0, 1);
frag.a *= clamp(bushOpacity + underBush, 0.0, 1.0);
gl_FragColor = frag;
}

View File

@ -873,7 +873,7 @@ void Bitmap::drawText(const IntRect &rect, const char *str, int align)
}
TEX::bind(p->gl.tex);
TEX::uploadSubImage(posRect.x, posRect.y, posRect.w, posRect.h, txtSurf->pixels, GL_BGRA_EXT);
TEX::uploadSubImage(posRect.x, posRect.y, posRect.w, posRect.h, txtSurf->pixels, GL_BGRA);
PixelStore::reset();
}
@ -884,7 +884,7 @@ void Bitmap::drawText(const IntRect &rect, const char *str, int align)
TEXFBO &gpTF = shState->gpTexFBO(txtSurf->w, txtSurf->h);
TEX::bind(gpTF.tex);
TEX::uploadSubImage(0, 0, txtSurf->w, txtSurf->h, txtSurf->pixels, GL_BGRA_EXT);
TEX::uploadSubImage(0, 0, txtSurf->w, txtSurf->h, txtSurf->pixels, GL_BGRA);
FBO::bind(gpTF.fbo, FBO::Read);
p->bindFBO();
@ -917,7 +917,7 @@ void Bitmap::drawText(const IntRect &rect, const char *str, int align)
shader.setOpacity(txtAlpha);
shState->bindTex();
TEX::uploadSubImage(0, 0, txtSurf->w, txtSurf->h, txtSurf->pixels, GL_BGRA_EXT);
TEX::uploadSubImage(0, 0, txtSurf->w, txtSurf->h, txtSurf->pixels, GL_BGRA);
TEX::setSmooth(true);
Quad &quad = shState->gpQuad();

View File

@ -24,6 +24,7 @@
#include <boost/program_options/options_description.hpp>
#include <boost/program_options/parsers.hpp>
#include <boost/program_options/variables_map.hpp>
#include <fstream>
#include "debugwriter.h"
@ -45,6 +46,7 @@ Config::Config()
frameSkip(true),
solidFonts(false),
gameFolder("."),
anyAltToggleFS(false),
allowSymlinks(false),
pathCache(true)
{}
@ -64,10 +66,15 @@ void Config::read()
PO_DESC(frameSkip, bool) \
PO_DESC(solidFonts, bool) \
PO_DESC(gameFolder, std::string) \
PO_DESC(anyAltToggleFS, bool) \
PO_DESC(allowSymlinks, bool) \
PO_DESC(iconPath, std::string) \
PO_DESC(customScript, std::string) \
PO_DESC(pathCache, bool)
// Not gonna take your shit boost
#define GUARD_ALL( exp ) try { exp } catch(...) {}
#define PO_DESC(key, type) (#key, po::value< type >()->default_value(key))
po::options_description podesc;
@ -80,13 +87,15 @@ void Config::read()
confFile.open("mkxp.conf");
po::variables_map vm;
po::store(po::parse_config_file(confFile, podesc, true), vm);
if (confFile)
{
GUARD_ALL( po::store(po::parse_config_file(confFile, podesc, true), vm); )
po::notify(vm);
}
confFile.close();
// Not gonna take your shit boost
#define GUARD_ALL( exp ) try { exp } catch(...) {}
#undef PO_DESC
#define PO_DESC(key, type) GUARD_ALL( key = vm[#key].as< type >(); )
@ -103,7 +112,10 @@ void Config::readGameINI()
{
if (!customScript.empty())
{
game.title = basename(customScript.c_str());
size_t pos = customScript.find_last_of("/\\");
if (pos == customScript.npos)
pos = 0;
game.title = customScript.substr(pos);
return;
}
@ -120,7 +132,7 @@ void Config::readGameINI()
iniFile.open((iniPath).c_str());
po::variables_map vm;
po::store(po::parse_config_file(iniFile, podesc, true), vm);
GUARD_ALL( po::store(po::parse_config_file(iniFile, podesc, true), vm); )
po::notify(vm);
iniFile.close();
@ -131,5 +143,10 @@ void Config::readGameINI()
strReplace(game.scripts, '\\', '/');
if (game.title.empty())
game.title = basename(gameFolder.c_str());
{
size_t pos = gameFolder.find_last_of("/\\");
if (pos == gameFolder.npos)
pos = 0;
game.title = gameFolder.substr(pos);
}
}

View File

@ -44,9 +44,12 @@ struct Config
bool solidFonts;
std::string gameFolder;
bool anyAltToggleFS;
bool allowSymlinks;
bool pathCache;
std::string iconPath;
std::string customScript;
std::vector<std::string> rtps;

View File

@ -125,7 +125,7 @@ struct CVertex
static const void *colorOffset()
{
return (const void*) sizeof(pos);
return (const void*) sizeof(Vec2);
}
};

View File

@ -70,6 +70,7 @@ void EventThread::process(RGSSThreadData &rtData)
WindowSizeNotify &windowSizeMsg = rtData.windowSizeMsg;
fullscreen = rtData.config.fullscreen;
int toggleFSMod = rtData.config.anyAltToggleFS ? KMOD_ALT : KMOD_LALT;
fps.lastFrame = SDL_GetPerformanceCounter();
fps.displaying = false;
@ -151,7 +152,7 @@ void EventThread::process(RGSSThreadData &rtData)
case SDL_KEYDOWN :
if (event.key.keysym.scancode == SDL_SCANCODE_RETURN &&
(event.key.keysym.mod & KMOD_LALT))
(event.key.keysym.mod & toggleFSMod))
{
setFullscreen(win, !fullscreen);
if (!fullscreen && havePendingTitle)

View File

@ -179,13 +179,15 @@ struct RGSSThreadData
RGSSThreadData(EventThread *ethread,
const char *argv0,
SDL_Window *window)
SDL_Window *window,
const Config& newconf)
: rqTerm(false),
rqTermAck(false),
ethread(ethread),
argv0(argv0),
window(window),
sizeResoRatio(1, 1),
config(newconf),
rqScreenshot(false)
{}
};

View File

@ -109,19 +109,19 @@ namespace RBO
inline ID gen()
{
ID id;
glGenRenderbuffersEXT(1, &id.gl);
glGenRenderbuffers(1, &id.gl);
return id;
}
inline void del(ID id)
{
glDeleteRenderbuffersEXT(1, &id.gl);
glDeleteRenderbuffers(1, &id.gl);
}
inline void bind(ID id)
{
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, id.gl);
glBindRenderbuffer(GL_RENDERBUFFER, id.gl);
}
inline void unbind()
@ -131,7 +131,7 @@ namespace RBO
inline void allocEmpty(GLsizei width, GLsizei height)
{
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA8, width, height);
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, width, height);
}
}
@ -155,25 +155,25 @@ namespace FBO
inline ID gen()
{
ID id;
glGenFramebuffersEXT(1, &id.gl);
glGenFramebuffers(1, &id.gl);
return id;
}
inline void del(ID id)
{
glDeleteFramebuffersEXT(1, &id.gl);
glDeleteFramebuffers(1, &id.gl);
}
inline void bind(ID id, Mode mode)
{
static const GLenum modes[] =
{
GL_DRAW_FRAMEBUFFER_EXT,
GL_READ_FRAMEBUFFER_EXT
GL_DRAW_FRAMEBUFFER,
GL_READ_FRAMEBUFFER
};
glBindFramebufferEXT(modes[mode], id.gl);
glBindFramebuffer(modes[mode], id.gl);
}
inline void unbind(Mode mode)
@ -183,12 +183,12 @@ namespace FBO
inline void setTarget(TEX::ID target, unsigned colorAttach = 0)
{
glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + colorAttach, GL_TEXTURE_2D, target.gl, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + colorAttach, GL_TEXTURE_2D, target.gl, 0);
}
inline void setTarget(RBO::ID target, unsigned colorAttach = 0)
{
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + colorAttach, GL_RENDERBUFFER, target.gl);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + colorAttach, GL_RENDERBUFFER, target.gl);
}
inline void blit(int srcX, int srcY,
@ -203,7 +203,7 @@ namespace FBO
GL_LINEAR
};
glBlitFramebufferEXT(srcX, srcY, srcX+srcW, srcY+srcH,
glBlitFramebuffer(srcX, srcY, srcX+srcW, srcY+srcH,
dstX, dstY, dstX+dstW, dstY+dstH,
GL_COLOR_BUFFER_BIT, modes[mode]);
}

View File

@ -71,20 +71,20 @@ void GLBlendMode::apply(const BlendType &value)
case BlendNormal :
glBlendEquation(GL_FUNC_ADD);
glBlendFuncSeparateEXT(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,
GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
break;
case BlendAddition :
glBlendEquation(GL_FUNC_ADD);
glBlendFuncSeparateEXT(GL_SRC_ALPHA, GL_ONE,
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE,
GL_ONE, GL_ONE);
break;
case BlendSubstraction :
// FIXME Alpha calculation is untested
glBlendEquation(GL_FUNC_REVERSE_SUBTRACT_EXT);
glBlendFuncSeparateEXT(GL_SRC_ALPHA, GL_ONE,
glBlendEquation(GL_FUNC_REVERSE_SUBTRACT);
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE,
GL_ONE, GL_ONE);
break;
}

View File

@ -52,6 +52,10 @@ struct GLProperty
set(value);
}
void refresh()
{
apply(current);
}
private:
virtual void apply(const T &value) = 0;

View File

@ -461,6 +461,8 @@ struct GraphicsPrivate
{
if (threadData->windowSizeMsg.pollChange(&winSize.x, &winSize.y))
{
// some GL drivers change the viewport on window resize
glState.viewport.refresh();
recalculateScreenSize();
updateScreenResoRatio();
}

View File

@ -37,22 +37,7 @@
#include "binding.h"
static const char *reqExt[] =
{
"GL_ARB_fragment_shader",
"GL_ARB_shader_objects",
"GL_ARB_vertex_shader",
"GL_ARB_shading_language_100",
"GL_ARB_texture_non_power_of_two",
"GL_ARB_vertex_array_object",
"GL_ARB_vertex_buffer_object",
"GL_EXT_bgra",
"GL_EXT_blend_func_separate",
"GL_EXT_blend_subtract",
"GL_EXT_framebuffer_object",
"GL_EXT_framebuffer_blit",
0
};
#include <unistd.h>
static void
rgssThreadError(RGSSThreadData *rtData, const std::string &msg)
@ -77,6 +62,60 @@ printGLInfo()
Debug() << "GLSL Version :" << glGetStringInt(GL_SHADING_LANGUAGE_VERSION);
}
static bool
setupOptionalGLExtensions(RGSSThreadData* threadData)
{
if (!GLEW_ARB_framebuffer_object)
{
if (!GLEW_EXT_framebuffer_object && !GLEW_EXT_framebuffer_blit)
{
rgssThreadError(threadData, "GL extensions \"GL_ARB_framebuffer_object\" or compatible extensiosns GL_EXT_framebuffer_object and GL_EXT_framebuffer_blit are not present");
return false;
}
else
{
/* setup compat */
/* From EXT_framebuffer_object */
glGenRenderbuffers = glGenRenderbuffersEXT;
glDeleteRenderbuffers = glDeleteRenderbuffersEXT;
glBindRenderbuffer = glBindRenderbufferEXT;
glRenderbufferStorage = glRenderbufferStorageEXT;
glGenFramebuffers = glGenFramebuffersEXT;
glDeleteFramebuffers = glDeleteFramebuffersEXT;
glBindFramebuffer = glBindFramebufferEXT;
glFramebufferTexture2D = glFramebufferTexture2DEXT;
glFramebufferRenderbuffer = glFramebufferRenderbufferEXT;
/* From EXT_framebuffer_blit */
glBlitFramebuffer = glBlitFramebufferEXT;
}
}
if (!GLEW_ARB_timer_query && GLEW_EXT_timer_query)
{
glGetQueryObjecti64v = glGetQueryObjecti64vEXT;
glGetQueryObjectui64v = glGetQueryObjectui64vEXT;
}
if (!GLEW_ARB_vertex_array_object )
{
if (!GLEW_APPLE_vertex_array_object)
{
rgssThreadError(threadData, "GL extensions \"GL_ARB_vertex_array_object\" or compatible extensiosn GL_APPLE_vertex_array_object are not present");
return false;
}
else
{
/* setup compat */
glBindVertexArray = glBindVertexArrayAPPLE;
/* the cast is because apple's uses const GLuint* and ARB doesn't */
glGenVertexArrays = (PFNGLGENVERTEXARRAYSPROC)glGenVertexArraysAPPLE;
glDeleteVertexArrays = glDeleteVertexArraysAPPLE;
}
}
return true;
}
int rgssThreadFun(void *userdata)
{
RGSSThreadData *threadData = static_cast<RGSSThreadData*>(userdata);
@ -120,18 +159,12 @@ int rgssThreadFun(void *userdata)
return 0;
}
/* Check for required GL extensions */
for (int i = 0; reqExt[i]; ++i)
/* Setup optional GL extensions */
if (!setupOptionalGLExtensions(threadData))
{
if (!glewIsSupported(reqExt[i]))
{
rgssThreadError(threadData, std::string("Required GL extension \"")
+ reqExt[i] + "\" not present");
SDL_GL_DeleteContext(glCtx);
return 0;
}
}
SDL_GL_SetSwapInterval(threadData->config.vsync ? 1 : 0);
@ -193,11 +226,7 @@ int rgssThreadFun(void *userdata)
int main(int, char *argv[])
{
Config conf;
conf.read();
conf.readGameINI();
/* initialize SDL first */
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0)
{
Debug() << "Error initializing SDL:" << SDL_GetError();
@ -205,6 +234,21 @@ int main(int, char *argv[])
return 0;
}
/* set working directory */
char *dataDir = SDL_GetBasePath();
if (dataDir)
{
int result = chdir(dataDir);
(void)result;
SDL_free(dataDir);
}
/* now we load the config */
Config conf;
conf.read();
conf.readGameINI();
int imgFlags = IMG_INIT_PNG | IMG_INIT_JPG;
if (IMG_Init(imgFlags) != imgFlags)
{
@ -253,9 +297,18 @@ int main(int, char *argv[])
return 0;
}
if (!conf.iconPath.empty())
{
SDL_Surface *iconImg = IMG_Load(conf.iconPath.c_str());
if (iconImg)
{
SDL_SetWindowIcon(win, iconImg);
SDL_FreeSurface(iconImg);
}
}
EventThread eventThread;
RGSSThreadData rtData(&eventThread, argv[0], win);
rtData.config = conf;
RGSSThreadData rtData(&eventThread, argv[0], win, conf);
/* Start RGSS thread */
SDL_Thread *rgssThread =

View File

@ -193,7 +193,7 @@ PerfTimer *createCPUTimer(int iter)
PerfTimer *createGPUTimer(int iter)
{
if (GLEW_EXT_timer_query)
if (GLEW_ARB_timer_query || GLEW_EXT_timer_query)
{
return new GPUTimerGLQuery(iter);
}

View File

@ -30,7 +30,7 @@
class SceneElement;
class Viewport;
class Window;
class ScanRow;
struct ScanRow;
struct TilemapPrivate;
class Scene
@ -63,7 +63,7 @@ protected:
friend class SceneElement;
friend class Window;
friend class ScanRow;
friend struct ScanRow;
};
class SceneElement