Skip to content

Commit

Permalink
Improve GPU rendering and fix some bugs
Browse files Browse the repository at this point in the history
Improve OpenGL Renderer using some GLExtension if available
Fix audio issue in video playback
Fix GPU rendering issue in LayerIntf
Rewrite ARM NEON optimized code into template
Fix some compile issue for clang
  • Loading branch information
ZeaS committed Feb 23, 2017
1 parent 711e17d commit 686a3a3
Show file tree
Hide file tree
Showing 71 changed files with 4,296 additions and 6,045 deletions.
6 changes: 5 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
Kirikiroid2 - A cross-platform port of Kirikiri2/KirikiriZ
==========================================================
==========================================================

Depend on most code from Kirikiri2 and KirikiriZ(https://github.com/krkrz/krkrz)
Video playback module modified from kodi(https://github.com/xbmc/xbmc)
Some string code from glibc and Apple Libc.
4 changes: 2 additions & 2 deletions src/core/base/TextStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ class tTVPTextReadStream : public iTJSTextReadStream
// check UTF-8 BOM
if(mark[0] == 0xef && mark[1] == 0xbb && mark[2] == 0xbf) {
// UTF-8 BOM
tjs_uint size = (tjs_uint)(Stream->GetSize()-3);
tjs_uint size = (tjs_uint)(Stream->GetSize() - 3) - ofs;
tjs_uint8 *nbuf = new tjs_uint8[size + 1];
try
{
Expand All @@ -254,7 +254,7 @@ class tTVPTextReadStream : public iTJSTextReadStream
// ansi/mbcs
// read whole and hold it
Stream->SetPosition(ofs);
tjs_uint size = (tjs_uint)(Stream->GetSize());
tjs_uint size = (tjs_uint)(Stream->GetSize()) - ofs;
tjs_uint8 *nbuf = new tjs_uint8[size + 1];
try
{
Expand Down
2 changes: 1 addition & 1 deletion src/core/base/win32/PluginImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ TJS_EXP_FUNC_DEF(void, TVPThrowPluginUnboundFunctionError, (const char *funcname
TJS_EXP_FUNC_DEF(void, TVPThrowPluginUnboundFunctionError, (const tjs_char *funcname));
#endif
inline TJS_EXP_FUNC_DEF(void *, TVP_malloc, (size_t size)) { return malloc(size); }
inline TJS_EXP_FUNC_DEF(void *, TVP_realloc, (void *pp, size_t size)) { return realloc(pp, size); }
// inline TJS_EXP_FUNC_DEF(void *, TVP_realloc, (void *pp, size_t size)) { return realloc(pp, size); }
inline TJS_EXP_FUNC_DEF(void, TVP_free, (void *pp)) { return free(pp); }
TJS_EXP_FUNC_DEF(tjs_int, TVPGetAutoLoadPluginCount, ());
//---------------------------------------------------------------------------
Expand Down
90 changes: 53 additions & 37 deletions src/core/base/win32/StorageImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,29 @@
#define lseek64 lseek
#endif

#ifdef WIN32
typedef struct _stat64 tTVP_stat;
#else
typedef struct ::stat64 tTVP_stat;
#endif

static bool TVP_stat(const tjs_char *name, tTVP_stat &s) {
#ifdef WIN32
return !_wstat64(name, &s);
#else
tTJSNarrowStringHolder holder(name);
return !::stat64(holder, &s);
#endif
}
static bool TVP_stat(const char *name, tTVP_stat &s) {
#ifdef WIN32
ttstr filename(name);
return !_wstat64(filename.c_str(), &s);
#else
return !::stat64(name, &s);
#endif
}

//---------------------------------------------------------------------------
// tTVPFileMedia
//---------------------------------------------------------------------------
Expand Down Expand Up @@ -126,51 +149,53 @@ tTJSBinaryStream * TJS_INTF_METHOD tTVPFileMedia::Open(const ttstr & name, tjs_u

return new tTVPLocalFileStream(origname, _name, flags);
}

void TVPListDir(const std::string &folder, std::function<void(const std::string&, int)> cb) {
DIR *dirp;
struct dirent *direntp;
struct stat stat_buf;
tTVP_stat stat_buf;
if ((dirp = opendir(folder.c_str())))
{
while ((direntp = readdir(dirp)) != NULL)
{
std::string fullpath = folder + "/" + direntp->d_name;
if (stat(fullpath.c_str(), &stat_buf) == -1) {
if (!TVP_stat(fullpath.c_str(), stat_buf))
continue;
}
cb(direntp->d_name, stat_buf.st_mode);
}
closedir(dirp);
}
}

void TVPGetLocalFileListAt(const ttstr &name, iTVPStorageLister *lister, int stat_mask) {
void TVPGetLocalFileListAt(const ttstr &name, const std::function<void(const ttstr&, tTVPLocalFileInfo*)>& cb) {
DIR *dirp;
struct dirent *direntp;
struct stat stat_buf;
tTVP_stat stat_buf;
std::string folder(name.AsNarrowStdString());
if ((dirp = opendir(folder.c_str())))
{
while ((direntp = readdir(dirp)) != NULL)
{
std::string fullpath = folder + "/" + direntp->d_name;
if (stat(fullpath.c_str(), &stat_buf) == -1)
{
if (!TVP_stat(fullpath.c_str(), stat_buf))
continue;
}
if (stat_buf.st_mode & stat_mask)
ttstr file(direntp->d_name);
tjs_char *p = file.Independ();
while (*p)
{
ttstr file(direntp->d_name);
tjs_char *p = file.Independ();
while (*p)
{
// make all characters small
if (*p >= TJS_W('A') && *p <= TJS_W('Z'))
*p += TJS_W('a') - TJS_W('A');
p++;
}
lister->Add(file);
// make all characters small
if (*p >= TJS_W('A') && *p <= TJS_W('Z'))
*p += TJS_W('a') - TJS_W('A');
p++;
}
tTVPLocalFileInfo info;
info.NativeName = direntp->d_name;
info.Mode = stat_buf.st_mode;
info.Size = stat_buf.st_size;
info.AccessTime = stat_buf.st_atime;
info.ModifyTime = stat_buf.st_mtime;
info.CreationTime = stat_buf.st_ctime;
cb(file, &info);
}
closedir(dirp);
}
Expand Down Expand Up @@ -210,7 +235,11 @@ void TJS_INTF_METHOD tTVPFileMedia::GetListAt(const ttstr &_name, iTVPStorageLis
FindClose(handle);
}
#endif
TVPGetLocalFileListAt(name, lister, S_IFREG);
TVPGetLocalFileListAt(name, [lister](const ttstr &name, tTVPLocalFileInfo* s) {
if (s->Mode & (S_IFREG)) {
lister->Add(name);
}
});
}

static int _utf8_strcasecmp(const char *a, const char *b) {
Expand Down Expand Up @@ -546,10 +575,8 @@ bool TVPCheckExistentLocalFile(const ttstr &name)
else
return true; // a file
#endif
struct stat s;
tTJSNarrowStringHolder holder(name.c_str());
if(stat(holder, &s))
{
tTVP_stat s;
if(!TVP_stat(name.c_str(), s)) {
return false; // not exist
}
return s.st_mode & S_IFREG;
Expand All @@ -564,26 +591,15 @@ bool TVPCheckExistentLocalFile(const ttstr &name)
//---------------------------------------------------------------------------
bool TVPCheckExistentLocalFolder(const ttstr &name)
{
#ifdef WIN32
#if 0
DWORD attrib = GetFileAttributes(name.c_str());
if(attrib != 0xffffffff && (attrib & FILE_ATTRIBUTE_DIRECTORY))
return true; // a folder
else
return false; // not a folder
#endif
struct _stat s = {0};
if(_wstat(name.c_str(), &s))
#else // posix utf-8
struct stat s = {0};
tTJSNarrowStringHolder holder(name.c_str());
char* p = (char*)holder.operator const tjs_nchar *();
char* t = p; while(*t) ++t;
while(t > p && (t[-1] == '\\' || t[-1] == '/')) --t;
*t = 0;
if(stat(p, &s))
#endif
{
tTVP_stat s;
if (!TVP_stat(name.c_str(), s)) {
return false; // not exist
}

Expand Down
10 changes: 9 additions & 1 deletion src/core/base/win32/StorageImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,16 @@ void TVPUnloadArchiveSPI(HINSTANCE inst);
//---------------------------------------------------------------------------
#endif

struct tTVPLocalFileInfo {
const char * NativeName;
unsigned short Mode; // S_IFMT
tjs_uint64 Size;
time_t AccessTime;
time_t ModifyTime;
time_t CreationTime;
};

void TVPGetLocalFileListAt(const ttstr &name, iTVPStorageLister *lister, int stat_mask);
void TVPGetLocalFileListAt(const ttstr &name, const std::function<void(const ttstr&, tTVPLocalFileInfo*)>& cb);

//---------------------------------------------------------------------------
// tTVPLocalFileStream
Expand Down
4 changes: 2 additions & 2 deletions src/core/base/win32/SysInitImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include "XP3Archive.h"
#include "ScriptMgnIntf.h"
#include "XP3Archive.h"
#include "VersionFormUnit.h"
//#include "VersionFormUnit.h"
#include "EmergencyExit.h"

//#include "tvpgl_ia32_intf.h"
Expand All @@ -41,7 +41,7 @@
#include "Exception.h"
#include "ApplicationSpecialPath.h"
//#include "resource.h"
#include "ConfigFormUnit.h"
//#include "ConfigFormUnit.h"
#include "TickCount.h"
#ifdef IID
#undef IID
Expand Down
2 changes: 1 addition & 1 deletion src/core/base/win32/SystemImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include "TVPScreen.h"
//#include "CompatibleNativeFuncs.h"
#include "DebugIntf.h"
#include "VersionFormUnit.h"
//#include "VersionFormUnit.h"
#include "vkdefine.h"
#include "ScriptMgnIntf.h"
#include "tjsArray.h"
Expand Down
3 changes: 0 additions & 3 deletions src/core/base/win32/win32io.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ extern "C" {
extern void* valloc(int n);
extern void vfree(void *p);
extern void logStack(std::string &out);
struct _stat_win32 : public stat {};
int _stat_win32(const char * _Filename, struct stat * _Stat);
#define stat _stat_win32
FILE * fopen(const char * _Filename, const char * _Mode);
}
#endif
9 changes: 7 additions & 2 deletions src/core/environ/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "Exception.h"
//#include "Resource.h"
#include "SystemControl.h"
#include "MouseCursor.h"
//#include "MouseCursor.h"
#include "SystemImpl.h"
#include "WaveImpl.h"
#include "GraphicsLoadThread.h"
Expand Down Expand Up @@ -1026,7 +1026,6 @@ void tTVPApplication::OnActivate()
}
void tTVPApplication::OnDeactivate( )
{
if (!image_load_thread_) return; // project is not startup yet
application_activating_ = false;
if (!_project_startup) return;

Expand Down Expand Up @@ -1056,6 +1055,12 @@ void tTVPApplication::OnExit()
CloseConsole();
}

void tTVPApplication::OnLowMemory()
{
if (!_project_startup) return;
TVPDeliverCompactEvent(TVP_COMPACT_LEVEL_MAX);
}

bool tTVPApplication::GetNotMinimizing() const
{
return !application_activating_;
Expand Down
1 change: 1 addition & 0 deletions src/core/environ/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ class tTVPApplication {
void OnActivate( );
void OnDeactivate( );
void OnExit();
void OnLowMemory();

bool GetActivating() const { return application_activating_; }
bool GetNotMinimizing() const;
Expand Down
42 changes: 33 additions & 9 deletions src/core/environ/ConfigManager/GlobalConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,30 @@
#include "tinyxml2/tinyxml2.h"
#include "platform/CCFileUtils.h"
#include "Platform.h"
#include "UtilStreams.h"
#include "LocaleConfigManager.h"

bool TVPWriteDataToFile(const ttstr &filepath, const void *data, unsigned int len);
class XMLMemPrinter : public tinyxml2::XMLPrinter {
tTVPMemoryStream _stream;
char _buffer[4096];
public:
virtual void Print(const char* format, ...) override {
va_list param;
va_start(param, format);
int n = vsnprintf(_buffer, 4096, format, param);
va_end(param);
_stream.Write(_buffer, n);
}
void SaveFile(const std::string &path) {
if (!TVPWriteDataToFile(path, _stream.GetInternalBuffer(), _stream.GetSize())) {
TVPShowSimpleMessageBox(
LocaleConfigManager::GetInstance()->GetText("cannot_create_preference"),
LocaleConfigManager::GetInstance()->GetText("readonly_storage"));
}
}
};


GlobalConfigManager::GlobalConfigManager() {
Initialize();
Expand Down Expand Up @@ -68,18 +92,18 @@ void iSysConfigManager::SaveToFile() {
}

doc.LinkEndChild(rootElement);
FILE *fp = nullptr;
#ifdef _MSC_VER
fp = _wfopen(ttstr(GetFilePath()).c_str(), TJS_W("w"));
#else
fp = fopen(GetFilePath().c_str(), "w");
#endif
doc.SaveFile(fp);
fclose(fp);

XMLMemPrinter stream;
doc.Print(&stream);
stream.SaveFile(GetFilePath());
ConfigUpdated = false;
}

bool iSysConfigManager::IsValueExist(const std::string &name)
{
auto it = AllConfig.find(name);
return it != AllConfig.end();
}

std::string GlobalConfigManager::GetFilePath() {
return TVPGetInternalPreferencePath() + "GlobalPreference.xml";
}
Expand Down
2 changes: 2 additions & 0 deletions src/core/environ/ConfigManager/GlobalConfigManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class iSysConfigManager {
public:
void SaveToFile();

bool IsValueExist(const std::string &name);

template<typename T>
T GetValue(const std::string &name, const T& defVal);

Expand Down
24 changes: 12 additions & 12 deletions src/core/environ/ConfigManager/IndividualConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ bool IndividualConfigManager::CheckExistAt(const std::string &folder) {

bool IndividualConfigManager::CreatePreferenceAt(const std::string &folder) {
std::string fullpath = folder + "/" FILENAME;
FILE *fp =
#ifdef _MSC_VER
_wfopen(ttstr(fullpath).c_str(), TJS_W("w"));
#else
fopen(fullpath.c_str(), "w");
#endif
// FILE *fp =
// #ifdef _MSC_VER
// _wfopen(ttstr(fullpath).c_str(), TJS_W("w"));
// #else
// fopen(fullpath.c_str(), "w");
// #endif
Clear();
if (!fp) {
TVPShowSimpleMessageBox(
LocaleConfigManager::GetInstance()->GetText("cannot_create_preference"),
LocaleConfigManager::GetInstance()->GetText("readonly_storage"));
return false;
}
// if (!fp) {
// TVPShowSimpleMessageBox(
// LocaleConfigManager::GetInstance()->GetText("cannot_create_preference"),
// LocaleConfigManager::GetInstance()->GetText("readonly_storage"));
// return false;
// }
CurrentPath = fullpath;
return true;
}
Expand Down
Loading

0 comments on commit 686a3a3

Please sign in to comment.