瀏覽代碼

Use std::string in a lot of places. Makes a few things simpler.

legacy
Sam Hocevar 8 年之前
父節點
當前提交
9dbfa4d550
共有 25 個文件被更改,包括 282 次插入275 次删除
  1. +1
    -1
      doc/tutorial/13_shader_builder.cpp
  2. +5
    -5
      src/audio/sample.cpp
  3. +11
    -9
      src/image/codec/android-image.cpp
  4. +9
    -7
      src/image/codec/dummy-image.cpp
  5. +24
    -29
      src/image/codec/gdiplus-image.cpp
  6. +13
    -11
      src/image/codec/imlib2-image.cpp
  7. +10
    -8
      src/image/codec/ios-image.cpp
  8. +10
    -10
      src/image/codec/oric-image.cpp
  9. +12
    -10
      src/image/codec/sdl-image.cpp
  10. +5
    -5
      src/image/codec/zed-image.cpp
  11. +5
    -5
      src/image/codec/zed-palette-image.cpp
  12. +3
    -3
      src/image/image.cpp
  13. +8
    -8
      src/image/movie.cpp
  14. +4
    -4
      src/image/resource-private.h
  15. +7
    -7
      src/image/resource.cpp
  16. +6
    -4
      src/lol/image/image.h
  17. +2
    -2
      src/lol/image/movie.h
  18. +3
    -3
      src/lol/image/resource.h
  19. +15
    -15
      src/lol/sys/file.h
  20. +15
    -12
      src/lol/sys/init.h
  21. +8
    -8
      src/lol/sys/threadtypes.h
  22. +5
    -5
      src/lolua/baselua.cpp
  23. +50
    -52
      src/sys/file.cpp
  24. +26
    -26
      src/sys/init.cpp
  25. +25
    -26
      src/sys/threadtypes.cpp

+ 1
- 1
doc/tutorial/13_shader_builder.cpp 查看文件

@@ -110,7 +110,7 @@ public:


builder.Build(code); builder.Build(code);


file.WriteString(code.c_str());
file.Write(code);
//code = file.ReadString(); //code = file.ReadString();
file.Close(); file.Close();




+ 5
- 5
src/audio/sample.cpp 查看文件

@@ -1,7 +1,7 @@
// //
// Lol Engine // Lol Engine
// //
// Copyright © 2010—2016 Sam Hocevar <sam@hocevar.net>
// Copyright © 2010—2018 Sam Hocevar <sam@hocevar.net>
// //
// Lol Engine is free software. It comes without any warranty, to // Lol Engine is free software. It comes without any warranty, to
// the extent permitted by applicable law. You can redistribute it // the extent permitted by applicable law. You can redistribute it
@@ -41,7 +41,7 @@ class sample_data
friend class sample; friend class sample;


private: private:
String m_name;
std::string m_name;
#if defined LOL_USE_SDL_MIXER #if defined LOL_USE_SDL_MIXER
Mix_Chunk *m_chunk; Mix_Chunk *m_chunk;
int m_channel; int m_channel;
@@ -55,12 +55,12 @@ private:
sample::sample(char const *path) sample::sample(char const *path)
: data(new sample_data()) : data(new sample_data())
{ {
data->m_name = String("<sample> ") + path;
data->m_name = std::string("<sample> ") + path;


#if defined LOL_USE_SDL_MIXER #if defined LOL_USE_SDL_MIXER
for (auto candidate : sys::get_path_list(path)) for (auto candidate : sys::get_path_list(path))
{ {
data->m_chunk = Mix_LoadWAV(candidate.C());
data->m_chunk = Mix_LoadWAV(candidate.c_str());
if (data->m_chunk) if (data->m_chunk)
break; break;
} }
@@ -88,7 +88,7 @@ void sample::TickGame(float seconds)


char const *sample::GetName() char const *sample::GetName()
{ {
return data->m_name.C();
return data->m_name.c_str();
} }


void sample::play() void sample::play()


+ 11
- 9
src/image/codec/android-image.cpp 查看文件

@@ -1,7 +1,7 @@
// //
// Lol Engine // Lol Engine
// //
// Copyright © 2010—2015 Sam Hocevar <sam@hocevar.net>
// Copyright © 2010—2018 Sam Hocevar <sam@hocevar.net>
// //
// Lol Engine is free software. It comes without any warranty, to // Lol Engine is free software. It comes without any warranty, to
// the extent permitted by applicable law. You can redistribute it // the extent permitted by applicable law. You can redistribute it
@@ -14,6 +14,8 @@


#if defined __ANDROID__ #if defined __ANDROID__


#include <string>

#include <jni.h> #include <jni.h>
#include <android/log.h> #include <android/log.h>


@@ -35,9 +37,9 @@ extern ANativeActivity *g_activity;
class AndroidImageCodec : public ResourceCodec class AndroidImageCodec : public ResourceCodec
{ {
public: public:
virtual char const *GetName() { return "<AndroidImageCodec>"; }
virtual ResourceCodecData* Load(char const *path);
virtual bool Save(char const *path, ResourceCodecData* data);
virtual std::string GetName() { return "<AndroidImageCodec>"; }
virtual ResourceCodecData* Load(std::string const &path);
virtual bool Save(std::string const &path, ResourceCodecData* data);
virtual bool Close(); virtual bool Close();


virtual uint8_t *GetData() const; virtual uint8_t *GetData() const;
@@ -50,7 +52,7 @@ private:


DECLARE_IMAGE_CODEC(AndroidImageCodec, 100) DECLARE_IMAGE_CODEC(AndroidImageCodec, 100)


ResourceCodecData* AndroidImageCodec::Load(char const *path)
ResourceCodecData* AndroidImageCodec::Load(std::string const &path)
{ {
JNIEnv *env; JNIEnv *env;
jint res = g_activity->vm->GetEnv((void **)&env, JNI_VERSION_1_2); jint res = g_activity->vm->GetEnv((void **)&env, JNI_VERSION_1_2);
@@ -64,7 +66,7 @@ ResourceCodecData* AndroidImageCodec::Load(char const *path)
if (res < 0) if (res < 0)
{ {
#if !LOL_BUILD_RELEASE #if !LOL_BUILD_RELEASE
msg::error("JVM environment not found, cannot open image %s\n", path);
msg::error("JVM environment not found, cannot open image %s\n", path.c_str());
#endif #endif
return false; return false;
} }
@@ -73,13 +75,13 @@ ResourceCodecData* AndroidImageCodec::Load(char const *path)


mid = env->GetMethodID(cls, "openImage", mid = env->GetMethodID(cls, "openImage",
"(Ljava/lang/String;)Landroid/graphics/Bitmap;"); "(Ljava/lang/String;)Landroid/graphics/Bitmap;");
jstring name = env->NewStringUTF(path);
jstring name = env->NewStringUTF(path.c_str());
m_bmp = env->CallObjectMethod(g_activity->clazz, mid, name); m_bmp = env->CallObjectMethod(g_activity->clazz, mid, name);
env->DeleteLocalRef(name); env->DeleteLocalRef(name);
if (!m_bmp) if (!m_bmp)
{ {
#if !LOL_BUILD_RELEASE #if !LOL_BUILD_RELEASE
msg::error("could not load %s\n", path);
msg::error("could not load %s\n", path.c_str());
#endif #endif
return false; return false;
} }
@@ -109,7 +111,7 @@ ResourceCodecData* AndroidImageCodec::Load(char const *path)
return new ResourceCodecData(); return new ResourceCodecData();
} }


bool AndroidImageCodec::Save(char const *path, ResourceCodecData* data)
bool AndroidImageCodec::Save(std::string const &path, ResourceCodecData* data)
{ {
UNUSED(path, data); UNUSED(path, data);




+ 9
- 7
src/image/codec/dummy-image.cpp 查看文件

@@ -1,7 +1,7 @@
// //
// Lol Engine // Lol Engine
// //
// Copyright © 2010—2017 Sam Hocevar <sam@hocevar.net>
// Copyright © 2010—2018 Sam Hocevar <sam@hocevar.net>
// //
// Lol Engine is free software. It comes without any warranty, to // Lol Engine is free software. It comes without any warranty, to
// the extent permitted by applicable law. You can redistribute it // the extent permitted by applicable law. You can redistribute it
@@ -12,6 +12,8 @@


#include <lol/engine-internal.h> #include <lol/engine-internal.h>


#include <string>

#include "../../image/resource-private.h" #include "../../image/resource-private.h"


namespace lol namespace lol
@@ -24,9 +26,9 @@ namespace lol
class DummyImageCodec : public ResourceCodec class DummyImageCodec : public ResourceCodec
{ {
public: public:
virtual char const *GetName() { return "<DummyImageCodec>"; }
virtual ResourceCodecData* Load(char const *path);
virtual bool Save(char const *path, ResourceCodecData* data);
virtual std::string GetName() { return "<DummyImageCodec>"; }
virtual ResourceCodecData* Load(std::string const &path);
virtual bool Save(std::string const &path, ResourceCodecData* data);
}; };


//Priority 0 because it's supposed to be the last one //Priority 0 because it's supposed to be the last one
@@ -36,9 +38,9 @@ DECLARE_IMAGE_CODEC(DummyImageCodec, 0)
* Public Image class * Public Image class
*/ */


ResourceCodecData* DummyImageCodec::Load(char const *path)
ResourceCodecData* DummyImageCodec::Load(std::string const &path)
{ {
if (strcmp("DUMMY", path))
if (path == "DUMMY")
return nullptr; return nullptr;


auto data = new ResourceImageData(new image(ivec2(256))); auto data = new ResourceImageData(new image(ivec2(256)));
@@ -58,7 +60,7 @@ ResourceCodecData* DummyImageCodec::Load(char const *path)
return data; return data;
} }


bool DummyImageCodec::Save(char const *path, ResourceCodecData* data)
bool DummyImageCodec::Save(std::string const &path, ResourceCodecData* data)
{ {
UNUSED(path, data); UNUSED(path, data);




+ 24
- 29
src/image/codec/gdiplus-image.cpp 查看文件

@@ -1,7 +1,7 @@
// //
// Lol Engine // Lol Engine
// //
// Copyright © 2010—2017 Sam Hocevar <sam@hocevar.net>
// Copyright © 2010—2018 Sam Hocevar <sam@hocevar.net>
// //
// Lol Engine is free software. It comes without any warranty, to // Lol Engine is free software. It comes without any warranty, to
// the extent permitted by applicable law. You can redistribute it // the extent permitted by applicable law. You can redistribute it
@@ -10,21 +10,16 @@
// See http://www.wtfpl.net/ for more details. // See http://www.wtfpl.net/ for more details.
// //


#if HAVE_CONFIG_H
# include "config.h"
#endif
#include <lol/engine-internal.h>

#if LOL_USE_GDIPLUS #if LOL_USE_GDIPLUS
# include <string>
# include <algorithm> # include <algorithm>
using std::min; using std::min;
using std::max; using std::max;
# include <windows.h> # include <windows.h>
# include <objidl.h> // for DEFINE_GUID # include <objidl.h> // for DEFINE_GUID
# include <gdiplus.h> # include <gdiplus.h>
#endif

#include <lol/engine-internal.h>

#if LOL_USE_GDIPLUS


#include "../../image/resource-private.h" #include "../../image/resource-private.h"


@@ -38,9 +33,9 @@ namespace lol
class GdiPlusImageCodec : public ResourceCodec class GdiPlusImageCodec : public ResourceCodec
{ {
public: public:
virtual char const *GetName() { return "<GdiPlusImageCodec>"; }
virtual ResourceCodecData* Load(char const *path);
virtual bool Save(char const *path, ResourceCodecData* data);
virtual std::string GetName() { return "<GdiPlusImageCodec>"; }
virtual ResourceCodecData* Load(std::string const &path);
virtual bool Save(std::string const &path, ResourceCodecData* data);
}; };


DECLARE_IMAGE_CODEC(GdiPlusImageCodec, 100) DECLARE_IMAGE_CODEC(GdiPlusImageCodec, 100)
@@ -49,7 +44,7 @@ DECLARE_IMAGE_CODEC(GdiPlusImageCodec, 100)
* Public Image class * Public Image class
*/ */


ResourceCodecData* GdiPlusImageCodec::Load(char const *path)
ResourceCodecData* GdiPlusImageCodec::Load(std::string const &path)
{ {
Gdiplus::Status status; Gdiplus::Status status;
ULONG_PTR token; ULONG_PTR token;
@@ -61,16 +56,16 @@ ResourceCodecData* GdiPlusImageCodec::Load(char const *path)
return nullptr; return nullptr;
} }


array<String> pathlist = sys::get_path_list(path);
array<std::string> pathlist = sys::get_path_list(path);
Gdiplus::Bitmap *bitmap = nullptr; Gdiplus::Bitmap *bitmap = nullptr;
for (auto fullpath : pathlist)
for (auto const &fullpath : pathlist)
{ {
size_t len; size_t len;
len = mbstowcs(nullptr, fullpath.C(), 0);
len = mbstowcs(nullptr, fullpath.c_str(), 0);
wchar_t *wpath = new wchar_t[len + 1]; wchar_t *wpath = new wchar_t[len + 1];
if (mbstowcs(wpath, fullpath.C(), len + 1) == (size_t)-1)
if (mbstowcs(wpath, fullpath.c_str(), len + 1) == (size_t)-1)
{ {
msg::error("invalid image name %s\n", fullpath.C());
msg::error("invalid image name %s\n", fullpath.c_str());
delete[] wpath; delete[] wpath;
continue; continue;
} }
@@ -85,7 +80,7 @@ ResourceCodecData* GdiPlusImageCodec::Load(char const *path)
{ {
if (status != Gdiplus::InvalidParameter) if (status != Gdiplus::InvalidParameter)
msg::error("error %d loading %s\n", msg::error("error %d loading %s\n",
status, fullpath.C());
status, fullpath.c_str());
delete bitmap; delete bitmap;
bitmap = nullptr; bitmap = nullptr;
} }
@@ -130,7 +125,7 @@ ResourceCodecData* GdiPlusImageCodec::Load(char const *path)
return data; return data;
} }


bool GdiPlusImageCodec::Save(char const *path, ResourceCodecData* data)
bool GdiPlusImageCodec::Save(std::string const &path, ResourceCodecData* data)
{ {
auto data_image = dynamic_cast<ResourceImageData*>(data); auto data_image = dynamic_cast<ResourceImageData*>(data);
if (data_image == nullptr) if (data_image == nullptr)
@@ -141,15 +136,15 @@ bool GdiPlusImageCodec::Save(char const *path, ResourceCodecData* data)
Gdiplus::GdiplusStartup(&token, &input, nullptr); Gdiplus::GdiplusStartup(&token, &input, nullptr);


wchar_t const *fmt; wchar_t const *fmt;
if (strstr(path, ".gif"))
if (ends_with(path, ".gif"))
fmt = L"image/gif"; fmt = L"image/gif";
else if (strstr(path, ".jpg") || strstr(path, ".jpeg"))
else if (ends_with(path, ".jpg") || ends_with(path, ".jpeg"))
fmt = L"image/jpeg"; fmt = L"image/jpeg";
else if (strstr(path, ".png"))
else if (ends_with(path, ".png"))
fmt = L"image/png"; fmt = L"image/png";
else if (strstr(path, ".tiff"))
else if (ends_with(path, ".tiff"))
fmt = L"image/tiff"; fmt = L"image/tiff";
else /* if (strstr(path, ".bmp")) */
else /* if (ends_with(path, ".bmp")) */
fmt = L"image/bmp"; fmt = L"image/bmp";


unsigned int num = 0, encoder_size = 0; unsigned int num = 0, encoder_size = 0;
@@ -173,11 +168,11 @@ bool GdiPlusImageCodec::Save(char const *path, ResourceCodecData* data)
} }


size_t len; size_t len;
len = mbstowcs(nullptr, path, 0);
len = mbstowcs(nullptr, path.c_str(), 0);
wchar_t *wpath = new wchar_t[len + 1]; wchar_t *wpath = new wchar_t[len + 1];
if (mbstowcs(wpath, path, len + 1) == (size_t)-1)
if (mbstowcs(wpath, path.c_str(), len + 1) == (size_t)-1)
{ {
msg::error("could not convert GDI+ filename '%s' to widechar\n", path);
msg::error("could not convert GDI+ filename '%s' to widechar\n", path.c_str());
delete[] wpath; delete[] wpath;
delete[] codecs; delete[] codecs;
return false; return false;
@@ -212,7 +207,7 @@ bool GdiPlusImageCodec::Save(char const *path, ResourceCodecData* data)


if (b->Save(wpath, &clsid, nullptr) != Gdiplus::Ok) if (b->Save(wpath, &clsid, nullptr) != Gdiplus::Ok)
{ {
msg::error("could not save GDI+ image '%s'\n", path);
msg::error("could not save GDI+ image '%s'\n", path.c_str());
delete[] wpath; delete[] wpath;
delete[] codecs; delete[] codecs;
delete b; delete b;


+ 13
- 11
src/image/codec/imlib2-image.cpp 查看文件

@@ -1,7 +1,7 @@
// //
// Lol Engine // Lol Engine
// //
// Copyright © 2010—2017 Sam Hocevar <sam@hocevar.net>
// Copyright © 2010—2018 Sam Hocevar <sam@hocevar.net>
// //
// Lol Engine is free software. It comes without any warranty, to // Lol Engine is free software. It comes without any warranty, to
// the extent permitted by applicable law. You can redistribute it // the extent permitted by applicable law. You can redistribute it
@@ -14,6 +14,8 @@


#if defined LOL_USE_IMLIB2 #if defined LOL_USE_IMLIB2


#include <string>

#include <Imlib2.h> #include <Imlib2.h>


/* Check that the Imlib2 types are safe */ /* Check that the Imlib2 types are safe */
@@ -34,21 +36,21 @@ namespace lol
class Imlib2ImageCodec : public ResourceCodec class Imlib2ImageCodec : public ResourceCodec
{ {
public: public:
virtual char const *GetName() { return "<Imlib2ImageCodec>"; }
virtual ResourceCodecData* Load(char const *path);
virtual bool Save(char const *path, ResourceCodecData* data);
virtual std::string GetName() { return "<Imlib2ImageCodec>"; }
virtual ResourceCodecData* Load(std::string const &path);
virtual bool Save(std::string const &path, ResourceCodecData* data);
}; };


/* Set priority higher than SDL because we can save in many formats. */ /* Set priority higher than SDL because we can save in many formats. */
DECLARE_IMAGE_CODEC(Imlib2ImageCodec, 70) DECLARE_IMAGE_CODEC(Imlib2ImageCodec, 70)


ResourceCodecData *Imlib2ImageCodec::Load(char const *path)
ResourceCodecData *Imlib2ImageCodec::Load(std::string const &path)
{ {
Imlib_Image im = nullptr; Imlib_Image im = nullptr;


for (auto candidate : sys::get_path_list(path))
for (auto const &candidate : sys::get_path_list(path))
{ {
im = imlib_load_image(candidate.C());
im = imlib_load_image(candidate.c_str());
if (im) if (im)
break; break;
} }
@@ -56,7 +58,7 @@ ResourceCodecData *Imlib2ImageCodec::Load(char const *path)
if (!im) if (!im)
{ {
#if !LOL_BUILD_RELEASE #if !LOL_BUILD_RELEASE
msg::error("could not load image %s\n", path);
msg::error("could not load image %s\n", path.c_str());
#endif #endif
return nullptr; return nullptr;
} }
@@ -68,7 +70,7 @@ ResourceCodecData *Imlib2ImageCodec::Load(char const *path)
{ {
imlib_free_image(); imlib_free_image();
#if !LOL_BUILD_RELEASE #if !LOL_BUILD_RELEASE
msg::error("could not get image data for %s\n", path);
msg::error("could not get image data for %s\n", path.c_str());
#endif #endif
return nullptr; return nullptr;
} }
@@ -93,7 +95,7 @@ ResourceCodecData *Imlib2ImageCodec::Load(char const *path)
return data; return data;
} }


bool Imlib2ImageCodec::Save(char const *path, ResourceCodecData *data)
bool Imlib2ImageCodec::Save(std::string const &path, ResourceCodecData *data)
{ {
auto data_image = dynamic_cast<ResourceImageData*>(data); auto data_image = dynamic_cast<ResourceImageData*>(data);
if (data_image == nullptr) if (data_image == nullptr)
@@ -120,7 +122,7 @@ bool Imlib2ImageCodec::Save(char const *path, ResourceCodecData *data)
imlib_image_put_back_data((DATA32 *)dstdata); imlib_image_put_back_data((DATA32 *)dstdata);
image->unlock(srcdata); image->unlock(srcdata);


imlib_save_image(path);
imlib_save_image(path.c_str());
imlib_free_image(); imlib_free_image();


return true; return true;


+ 10
- 8
src/image/codec/ios-image.cpp 查看文件

@@ -1,7 +1,7 @@
// //
// Lol Engine // Lol Engine
// //
// Copyright © 2010—2015 Sam Hocevar <sam@hocevar.net>
// Copyright © 2010—2018 Sam Hocevar <sam@hocevar.net>
// //
// Lol Engine is free software. It comes without any warranty, to // Lol Engine is free software. It comes without any warranty, to
// the extent permitted by applicable law. You can redistribute it // the extent permitted by applicable law. You can redistribute it
@@ -14,6 +14,8 @@


#if defined __APPLE__ && defined __MACH__ && defined __arm__ #if defined __APPLE__ && defined __MACH__ && defined __arm__


#include <string>

#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>


#include "../../image/resource-private.h" #include "../../image/resource-private.h"
@@ -28,9 +30,9 @@ namespace lol
class IosImageCodec : public ResourceCodec class IosImageCodec : public ResourceCodec
{ {
public: public:
virtual char const *GetName() { return "<IosImageCodec>"; }
virtual ResourceCodecData* Load(char const *path);
virtual bool Save(char const *path, ResourceCodecData* data);
virtual std::string GetName() { return "<IosImageCodec>"; }
virtual ResourceCodecData* Load(std::string const &path);
virtual bool Save(std::string const &path, ResourceCodecData* data);
}; };


DECLARE_IMAGE_CODEC(IosImageCodec, 100) DECLARE_IMAGE_CODEC(IosImageCodec, 100)
@@ -39,9 +41,9 @@ DECLARE_IMAGE_CODEC(IosImageCodec, 100)
* Public Image class * Public Image class
*/ */


ResourceCodecData* IosImageCodec::Load(char const *path)
ResourceCodecData* IosImageCodec::Load(std::string const &path)
{ {
NSString *fullpath = [NSString stringWithUTF8String:path];
NSString *fullpath = [NSString stringWithUTF8String:path.c_str()];
NSArray *chunks = [fullpath componentsSeparatedByString: @"/"]; NSArray *chunks = [fullpath componentsSeparatedByString: @"/"];
NSString *filename = [chunks objectAtIndex: [chunks count] - 1]; NSString *filename = [chunks objectAtIndex: [chunks count] - 1];
chunks = [filename componentsSeparatedByString: @"."]; chunks = [filename componentsSeparatedByString: @"."];
@@ -52,7 +54,7 @@ ResourceCodecData* IosImageCodec::Load(char const *path)
if (!image) if (!image)
{ {
#if !LOL_BUILD_RELEASE #if !LOL_BUILD_RELEASE
msg::error("could not load %s\n", path);
msg::error("could not load %s\n", path.c_str());
#endif #endif
return nullptr; return nullptr;
} }
@@ -78,7 +80,7 @@ ResourceCodecData* IosImageCodec::Load(char const *path)
return new ResourceCodecData(); return new ResourceCodecData();
} }


bool IosImageCodec::Save(char const *path, ResourceCodecData* data)
bool IosImageCodec::Save(std::string const &path, ResourceCodecData* data)
{ {
UNUSED(path, data); UNUSED(path, data);




+ 10
- 10
src/image/codec/oric-image.cpp 查看文件

@@ -33,12 +33,12 @@ namespace lol
class OricImageCodec : public ResourceCodec class OricImageCodec : public ResourceCodec
{ {
public: public:
virtual char const *GetName() { return "<OricImageCodec>"; }
virtual ResourceCodecData* Load(char const *path);
virtual bool Save(char const *path, ResourceCodecData* data);
virtual std::string GetName() { return "<OricImageCodec>"; }
virtual ResourceCodecData* Load(std::string const &path);
virtual bool Save(std::string const &path, ResourceCodecData* data);


private: private:
static std::string ReadScreen(char const *name);
static std::string ReadScreen(std::string const &name);
static void WriteScreen(image &image, array<uint8_t> &result); static void WriteScreen(image &image, array<uint8_t> &result);
}; };


@@ -48,7 +48,7 @@ DECLARE_IMAGE_CODEC(OricImageCodec, 100)
* Public Image class * Public Image class
*/ */


ResourceCodecData* OricImageCodec::Load(char const *path)
ResourceCodecData* OricImageCodec::Load(std::string const &path)
{ {
static u8vec4 const pal[8] = static u8vec4 const pal[8] =
{ {
@@ -109,13 +109,13 @@ ResourceCodecData* OricImageCodec::Load(char const *path)
return data; return data;
} }


bool OricImageCodec::Save(char const *path, ResourceCodecData* data)
bool OricImageCodec::Save(std::string const &path, ResourceCodecData* data)
{ {
auto data_image = dynamic_cast<ResourceImageData*>(data); auto data_image = dynamic_cast<ResourceImageData*>(data);
if (data_image == nullptr) if (data_image == nullptr)
return false; return false;


int len = (int)strlen(path);
int len = (int)path.length();
if (len < 4 || path[len - 4] != '.' if (len < 4 || path[len - 4] != '.'
|| std::toupper(path[len - 3]) != 'T' || std::toupper(path[len - 3]) != 'T'
|| std::toupper(path[len - 2]) != 'A' || std::toupper(path[len - 2]) != 'A'
@@ -128,7 +128,7 @@ bool OricImageCodec::Save(char const *path, ResourceCodecData* data)
result << 0 << 0xff << 0x80 << 0 << 0xbf << 0x3f << 0xa0 << 0; result << 0 << 0xff << 0x80 << 0 << 0xbf << 0x3f << 0xa0 << 0;


/* Add filename, except the last 4 characters */ /* Add filename, except the last 4 characters */
for (char const *name = path; name[4]; ++name)
for (char const *name = path.c_str(); name[4]; ++name)
result << (uint8_t)name[0]; result << (uint8_t)name[0];
result << 0; result << 0;


@@ -153,11 +153,11 @@ bool OricImageCodec::Save(char const *path, ResourceCodecData* data)
return true; return true;
} }


std::string OricImageCodec::ReadScreen(char const *name)
std::string OricImageCodec::ReadScreen(std::string const &name)
{ {
File f; File f;
f.Open(name, FileAccess::Read); f.Open(name, FileAccess::Read);
std::string data = f.ReadString().C();
std::string data = f.ReadString();
f.Close(); f.Close();


/* Skip the sync bytes */ /* Skip the sync bytes */


+ 12
- 10
src/image/codec/sdl-image.cpp 查看文件

@@ -1,7 +1,7 @@
// //
// Lol Engine // Lol Engine
// //
// Copyright © 2010—2017 Sam Hocevar <sam@hocevar.net>
// Copyright © 2010—2018 Sam Hocevar <sam@hocevar.net>
// //
// Lol Engine is free software. It comes without any warranty, to // Lol Engine is free software. It comes without any warranty, to
// the extent permitted by applicable law. You can redistribute it // the extent permitted by applicable law. You can redistribute it
@@ -25,6 +25,8 @@
# include <SDL_image.h> # include <SDL_image.h>
#endif #endif


#include <string>

#include "../../image/resource-private.h" #include "../../image/resource-private.h"


namespace lol namespace lol
@@ -37,22 +39,22 @@ namespace lol
class SdlImageCodec : public ResourceCodec class SdlImageCodec : public ResourceCodec
{ {
public: public:
virtual char const *GetName() { return "<SdlImageCodec>"; }
virtual ResourceCodecData* Load(char const *path);
virtual bool Save(char const *path, ResourceCodecData* data);
virtual std::string GetName() { return "<SdlImageCodec>"; }
virtual ResourceCodecData* Load(std::string const &path);
virtual bool Save(std::string const &path, ResourceCodecData* data);


static SDL_Surface *Create32BppSurface(ivec2 size); static SDL_Surface *Create32BppSurface(ivec2 size);
}; };


DECLARE_IMAGE_CODEC(SdlImageCodec, 50) DECLARE_IMAGE_CODEC(SdlImageCodec, 50)


ResourceCodecData* SdlImageCodec::Load(char const *path)
ResourceCodecData* SdlImageCodec::Load(std::string const &path)
{ {
SDL_Surface *surface = nullptr; SDL_Surface *surface = nullptr;


for (auto candidate : sys::get_path_list(path))
for (auto const &candidate : sys::get_path_list(path))
{ {
surface = IMG_Load(candidate.C());
surface = IMG_Load(candidate.c_str());
if (surface) if (surface)
break; break;
} }
@@ -60,7 +62,7 @@ ResourceCodecData* SdlImageCodec::Load(char const *path)
if (!surface) if (!surface)
{ {
#if !LOL_BUILD_RELEASE #if !LOL_BUILD_RELEASE
msg::error("could not load image %s\n", path);
msg::error("could not load image %s\n", path.c_str());
#endif #endif
return nullptr; return nullptr;
} }
@@ -86,7 +88,7 @@ ResourceCodecData* SdlImageCodec::Load(char const *path)
return data; return data;
} }


bool SdlImageCodec::Save(char const *path, ResourceCodecData* data)
bool SdlImageCodec::Save(std::string const &path, ResourceCodecData* data)
{ {
auto data_image = dynamic_cast<ResourceImageData*>(data); auto data_image = dynamic_cast<ResourceImageData*>(data);
if (data_image == nullptr) if (data_image == nullptr)
@@ -100,7 +102,7 @@ bool SdlImageCodec::Save(char const *path, ResourceCodecData* data)
memcpy(surface->pixels, pixel_data, 4 * size.x * size.y); memcpy(surface->pixels, pixel_data, 4 * size.x * size.y);
image->unlock(pixel_data); image->unlock(pixel_data);


int ret = SDL_SaveBMP(surface, path);
int ret = SDL_SaveBMP(surface, path.c_str());
SDL_FreeSurface(surface); SDL_FreeSurface(surface);


return ret == 0; return ret == 0;


+ 5
- 5
src/image/codec/zed-image.cpp 查看文件

@@ -27,9 +27,9 @@ namespace lol
class ZedImageCodec : public ResourceCodec class ZedImageCodec : public ResourceCodec
{ {
public: public:
virtual char const *GetName() { return "<ZedImageCodec>"; }
virtual ResourceCodecData* Load(char const *path);
virtual bool Save(char const *path, ResourceCodecData* data);
virtual std::string GetName() { return "<ZedImageCodec>"; }
virtual ResourceCodecData* Load(std::string const &path);
virtual bool Save(std::string const &path, ResourceCodecData* data);
}; };


DECLARE_IMAGE_CODEC(ZedImageCodec, 10) DECLARE_IMAGE_CODEC(ZedImageCodec, 10)
@@ -38,7 +38,7 @@ DECLARE_IMAGE_CODEC(ZedImageCodec, 10)
* Public Image class * Public Image class
*/ */


ResourceCodecData* ZedImageCodec::Load(char const *path)
ResourceCodecData* ZedImageCodec::Load(std::string const &path)
{ {
if (!ends_with(path, ".RSC")) if (!ends_with(path, ".RSC"))
return nullptr; return nullptr;
@@ -295,7 +295,7 @@ ResourceCodecData* ZedImageCodec::Load(char const *path)
return data; return data;
} }


bool ZedImageCodec::Save(char const *path, ResourceCodecData* data)
bool ZedImageCodec::Save(std::string const &path, ResourceCodecData* data)
{ {
UNUSED(path, data); UNUSED(path, data);
/* FIXME: do we need to implement this? */ /* FIXME: do we need to implement this? */


+ 5
- 5
src/image/codec/zed-palette-image.cpp 查看文件

@@ -27,9 +27,9 @@ namespace lol
class ZedPaletteImageCodec : public ResourceCodec class ZedPaletteImageCodec : public ResourceCodec
{ {
public: public:
virtual char const *GetName() { return "<ZedPaletteImageCodec>"; }
virtual ResourceCodecData* Load(char const *path);
virtual bool Save(char const *path, ResourceCodecData* data);
virtual std::string GetName() { return "<ZedPaletteImageCodec>"; }
virtual ResourceCodecData* Load(std::string const &path);
virtual bool Save(std::string const &path, ResourceCodecData* data);
}; };


DECLARE_IMAGE_CODEC(ZedPaletteImageCodec, 10) DECLARE_IMAGE_CODEC(ZedPaletteImageCodec, 10)
@@ -38,7 +38,7 @@ DECLARE_IMAGE_CODEC(ZedPaletteImageCodec, 10)
* Public Image class * Public Image class
*/ */


ResourceCodecData* ZedPaletteImageCodec::Load(char const *path)
ResourceCodecData* ZedPaletteImageCodec::Load(std::string const &path)
{ {
if (!ends_with(path, ".pal")) if (!ends_with(path, ".pal"))
return nullptr; return nullptr;
@@ -83,7 +83,7 @@ ResourceCodecData* ZedPaletteImageCodec::Load(char const *path)
return data; return data;
} }


bool ZedPaletteImageCodec::Save(char const *path, ResourceCodecData* data)
bool ZedPaletteImageCodec::Save(std::string const &path, ResourceCodecData* data)
{ {
UNUSED(path, data); UNUSED(path, data);
/* FIXME: do we need to implement this? */ /* FIXME: do we need to implement this? */


+ 3
- 3
src/image/image.cpp 查看文件

@@ -28,7 +28,7 @@ image::image()
{ {
} }


image::image(char const *path)
image::image(std::string const &path)
: m_data(new image_data()) : m_data(new image_data())
{ {
load(path); load(path);
@@ -91,7 +91,7 @@ void image::DummyFill()
load("DUMMY"); load("DUMMY");
} }


bool image::load(char const *path)
bool image::load(std::string const &path)
{ {
auto resource = ResourceLoader::Load(path); auto resource = ResourceLoader::Load(path);
if (resource == nullptr) if (resource == nullptr)
@@ -109,7 +109,7 @@ bool image::load(char const *path)
return true; return true;
} }


bool image::save(char const *path)
bool image::save(std::string const &path)
{ {
auto data = new ResourceImageData(new image(*this)); auto data = new ResourceImageData(new image(*this));
auto result = ResourceLoader::Save(path, data); auto result = ResourceLoader::Save(path, data);


+ 8
- 8
src/image/movie.cpp 查看文件

@@ -1,7 +1,7 @@
// //
// Lol Engine // Lol Engine
// //
// Copyright © 2010—2017 Sam Hocevar <sam@hocevar.net>
// Copyright © 2010—2018 Sam Hocevar <sam@hocevar.net>
// //
// Lol Engine is free software. It comes without any warranty, to // Lol Engine is free software. It comes without any warranty, to
// the extent permitted by applicable law. You can redistribute it // the extent permitted by applicable law. You can redistribute it
@@ -29,12 +29,12 @@ namespace lol
{ {


#if LOL_USE_FFMPEG #if LOL_USE_FFMPEG
#define ERROR_TO_STRING(errnum) (error2string((errnum)).C())
static String error2string(int errnum)
#define ERROR_TO_STRING(errnum) (error2string((errnum)).c_str())
static std::string error2string(int errnum)
{ {
char tmp[AV_ERROR_MAX_STRING_SIZE]; char tmp[AV_ERROR_MAX_STRING_SIZE];
av_strerror(errnum, tmp, AV_ERROR_MAX_STRING_SIZE); av_strerror(errnum, tmp, AV_ERROR_MAX_STRING_SIZE);
return String(tmp);
return std::string(tmp);
} }


/*static void ffmpeg_logger(void *ptr, int level, const char *fmt, va_list vl) /*static void ffmpeg_logger(void *ptr, int level, const char *fmt, va_list vl)
@@ -69,11 +69,11 @@ movie::movie(ivec2 size)
#endif #endif
} }


bool movie::open_file(char const *filename)
bool movie::open_file(std::string const &filename)
{ {
#if LOL_USE_FFMPEG #if LOL_USE_FFMPEG
/* Third argument specifies format */ /* Third argument specifies format */
avformat_alloc_output_context2(&m_avformat, nullptr, "gif", filename);
avformat_alloc_output_context2(&m_avformat, nullptr, "gif", filename.c_str());
if (!m_avformat) if (!m_avformat)
{ {
msg::debug("could not create output context"); msg::debug("could not create output context");
@@ -85,10 +85,10 @@ bool movie::open_file(char const *filename)


if (!(m_avformat->oformat->flags & AVFMT_NOFILE)) if (!(m_avformat->oformat->flags & AVFMT_NOFILE))
{ {
int ret = avio_open(&m_avformat->pb, filename, AVIO_FLAG_WRITE);
int ret = avio_open(&m_avformat->pb, filename.c_str(), AVIO_FLAG_WRITE);
if (ret < 0) if (ret < 0)
{ {
msg::error("could not open '%s': %s\n", filename, ERROR_TO_STRING(ret));
msg::error("could not open '%s': %s\n", filename.c_str(), ERROR_TO_STRING(ret));
return false; return false;
} }
} }


+ 4
- 4
src/image/resource-private.h 查看文件

@@ -1,7 +1,7 @@
// //
// Lol Engine // Lol Engine
// //
// Copyright © 2010—2017 Sam Hocevar <sam@hocevar.net>
// Copyright © 2010—2018 Sam Hocevar <sam@hocevar.net>
// © 2016—2017 Benjamin “Touky” Huet <huet.benjamin@gmail.com> // © 2016—2017 Benjamin “Touky” Huet <huet.benjamin@gmail.com>
// //
// Lol Engine is free software. It comes without any warranty, to // Lol Engine is free software. It comes without any warranty, to
@@ -24,9 +24,9 @@ namespace lol
class ResourceCodec class ResourceCodec
{ {
public: public:
virtual char const *GetName() { return "<ResourceCodec>"; }
virtual ResourceCodecData* Load(char const *path) = 0;
virtual bool Save(char const *path, ResourceCodecData* data) = 0;
virtual std::string GetName() { return "<ResourceCodec>"; }
virtual ResourceCodecData* Load(std::string const &path) = 0;
virtual bool Save(std::string const &path, ResourceCodecData* data) = 0;


/* TODO: this should become more fine-grained */ /* TODO: this should become more fine-grained */
int m_priority; int m_priority;


+ 7
- 7
src/image/resource.cpp 查看文件

@@ -1,7 +1,7 @@
// //
// Lol Engine // Lol Engine
// //
// Copyright © 2010—2017 Sam Hocevar <sam@hocevar.net>
// Copyright © 2010—2018 Sam Hocevar <sam@hocevar.net>
// Copyright © 2016—2017 Benjamin “Touky” Huet <huet.benjamin@gmail.com> // Copyright © 2016—2017 Benjamin “Touky” Huet <huet.benjamin@gmail.com>
// //
// Lol Engine is free software. It comes without any warranty, to // Lol Engine is free software. It comes without any warranty, to
@@ -79,7 +79,7 @@ g_resource_loader;
* The public resource loader * The public resource loader
*/ */


ResourceCodecData* ResourceLoader::Load(char const *path)
ResourceCodecData* ResourceLoader::Load(std::string const &path)
{ {
ResourceCodec* last_codec = nullptr; ResourceCodec* last_codec = nullptr;
for (auto codec : g_resource_loader.m_codecs) for (auto codec : g_resource_loader.m_codecs)
@@ -89,18 +89,18 @@ ResourceCodecData* ResourceLoader::Load(char const *path)
if (data != nullptr) if (data != nullptr)
{ {
msg::debug("image::load: codec %s succesfully loaded %s.\n", msg::debug("image::load: codec %s succesfully loaded %s.\n",
codec->GetName(), path);
codec->GetName().c_str(), path.c_str());
return data; return data;
} }
} }


//Log error, because we shouldn't be here //Log error, because we shouldn't be here
msg::error("image::load: last codec %s, error loading resource %s.\n", msg::error("image::load: last codec %s, error loading resource %s.\n",
last_codec->GetName(), path);
last_codec->GetName().c_str(), path.c_str());
return nullptr; return nullptr;
} }


bool ResourceLoader::Save(char const *path, ResourceCodecData* data)
bool ResourceLoader::Save(std::string const &path, ResourceCodecData* data)
{ {
ResourceCodec* last_codec = nullptr; ResourceCodec* last_codec = nullptr;
for (auto codec : g_resource_loader.m_codecs) for (auto codec : g_resource_loader.m_codecs)
@@ -109,14 +109,14 @@ bool ResourceLoader::Save(char const *path, ResourceCodecData* data)
if (codec->Save(path, data)) if (codec->Save(path, data))
{ {
msg::debug("image::save: codec %s succesfully saved %s.\n", msg::debug("image::save: codec %s succesfully saved %s.\n",
codec->GetName(), path);
codec->GetName().c_str(), path.c_str());
return true; return true;
} }
} }


//Log error, because we shouldn't be here //Log error, because we shouldn't be here
msg::error("image::save: last codec %s, error saving resource %s.\n", msg::error("image::save: last codec %s, error saving resource %s.\n",
last_codec->GetName(), path);
last_codec->GetName().c_str(), path.c_str());
return false; return false;
} }




+ 6
- 4
src/lol/image/image.h 查看文件

@@ -1,7 +1,7 @@
// //
// Lol Engine // Lol Engine
// //
// Copyright © 2010—2017 Sam Hocevar <sam@hocevar.net>
// Copyright © 2010—2018 Sam Hocevar <sam@hocevar.net>
// //
// Lol Engine is free software. It comes without any warranty, to // Lol Engine is free software. It comes without any warranty, to
// the extent permitted by applicable law. You can redistribute it // the extent permitted by applicable law. You can redistribute it
@@ -22,6 +22,8 @@
#include <lol/math/geometry.h> #include <lol/math/geometry.h>
#include <lol/image/pixel.h> #include <lol/image/pixel.h>


#include <string>

namespace lol namespace lol
{ {


@@ -66,7 +68,7 @@ public:
image(ivec2 size); image(ivec2 size);
/* XXX: use of this ctor should be discouraged, as it will not /* XXX: use of this ctor should be discouraged, as it will not
* return information about a possible error. */ * return information about a possible error. */
image(char const *path);
image(std::string const &path);


/* Rule of three */ /* Rule of three */
image(image const &other); image(image const &other);
@@ -76,8 +78,8 @@ public:
void DummyFill(); void DummyFill();
void Copy(uint8_t* pixels, ivec2 const& size, PixelFormat fmt); void Copy(uint8_t* pixels, ivec2 const& size, PixelFormat fmt);
void Copy(image const &other); void Copy(image const &other);
bool load(char const *path);
bool save(char const *path);
bool load(std::string const &path);
bool save(std::string const &path);


/* Low level access */ /* Low level access */
ivec2 size() const; ivec2 size() const;


+ 2
- 2
src/lol/image/movie.h 查看文件

@@ -1,7 +1,7 @@
// //
// Lol Engine // Lol Engine
// //
// Copyright © 2010—2017 Sam Hocevar <sam@hocevar.net>
// Copyright © 2010—2018 Sam Hocevar <sam@hocevar.net>
// //
// Lol Engine is free software. It comes without any warranty, to // Lol Engine is free software. It comes without any warranty, to
// the extent permitted by applicable law. You can redistribute it // the extent permitted by applicable law. You can redistribute it
@@ -33,7 +33,7 @@ class movie
public: public:
movie(ivec2 size); movie(ivec2 size);


bool open_file(char const *filename);
bool open_file(std::string const &filename);
bool push_image(image &im); bool push_image(image &im);
void close(); void close();




+ 3
- 3
src/lol/image/resource.h 查看文件

@@ -1,7 +1,7 @@
// //
// Lol Engine // Lol Engine
// //
// Copyright © 2010—2017 Sam Hocevar <sam@hocevar.net>
// Copyright © 2010—2018 Sam Hocevar <sam@hocevar.net>
// © 2016—2017 Benjamin “Touky” Huet <huet.benjamin@gmail.com> // © 2016—2017 Benjamin “Touky” Huet <huet.benjamin@gmail.com>
// //
// Lol Engine is free software. It comes without any warranty, to // Lol Engine is free software. It comes without any warranty, to
@@ -66,8 +66,8 @@ namespace lol
class ResourceLoader class ResourceLoader
{ {
public: public:
static ResourceCodecData* Load(char const *path);
static bool Save(char const *path, ResourceCodecData* data);
static ResourceCodecData* Load(std::string const &path);
static bool Save(std::string const &path, ResourceCodecData* data);
}; };


} /* namespace lol */ } /* namespace lol */


+ 15
- 15
src/lol/sys/file.h 查看文件

@@ -32,7 +32,7 @@ struct FileAccessBase : public StructSafeEnum
Write Write
}; };
protected: protected:
virtual bool BuildEnumMap(std::map<int64_t, String>& enum_map)
virtual bool BuildEnumMap(std::map<int64_t, std::string>& enum_map)
{ {
enum_map[Read] = "Read"; enum_map[Read] = "Read";
enum_map[Write] = "Write"; enum_map[Write] = "Write";
@@ -53,7 +53,7 @@ struct StreamTypeBase : public StructSafeEnum
FileBinary FileBinary
}; };
protected: protected:
virtual bool BuildEnumMap(std::map<int64_t, String>& enum_map)
virtual bool BuildEnumMap(std::map<int64_t, std::string>& enum_map)
{ {
enum_map[StdIn] = "StdIn"; enum_map[StdIn] = "StdIn";
enum_map[StdOut] = "StdOut"; enum_map[StdOut] = "StdOut";
@@ -74,14 +74,14 @@ public:
~File(); ~File();


void Open(StreamType stream); void Open(StreamType stream);
void Open(String const &file, FileAccess mode, bool force_binary=false);
void Open(std::string const &file, FileAccess mode, bool force_binary=false);
bool IsValid() const; bool IsValid() const;
void Close(); void Close();


int Read(uint8_t *buf, int count); int Read(uint8_t *buf, int count);
String ReadString();
int Write(uint8_t const *buf, int count);
int WriteString(const String &buf);
std::string ReadString();
int Write(void const *buf, int count);
int Write(std::string const &buf);
long int GetPosFromStart(); long int GetPosFromStart();
void SetPosFromStart(long int pos); void SetPosFromStart(long int pos);
long int size(); long int size();
@@ -94,7 +94,7 @@ private:
class Directory class Directory
{ {
public: public:
Directory(String const &name);
Directory(std::string const &name);
Directory(Directory const &that); Directory(Directory const &that);
Directory &operator =(Directory const &that); Directory &operator =(Directory const &that);
~Directory(); ~Directory();
@@ -104,20 +104,20 @@ public:
void Close(); void Close();


private: private:
bool GetContent(array<String>* files, array<Directory>* directories);
bool GetContent(array<std::string>* files, array<Directory>* directories);
public: public:
bool GetContent(array<String>& files, array<Directory>& directories);
bool GetContent(array<std::string>& files, array<Directory>& directories);
bool GetContent(array<Directory>& directories); bool GetContent(array<Directory>& directories);
bool GetContent(array<String>& files);
String GetName();
bool GetContent(array<std::string>& files);
std::string GetName();
long int GetModificationTime(); long int GetModificationTime();


static String GetCurrent();
static bool SetCurrent(String directory);
static std::string GetCurrent();
static bool SetCurrent(std::string directory);


private: private:
class DirectoryData* m_data;
String m_name;
class DirectoryData* m_data;
std::string m_name;
}; };


} /* namespace lol */ } /* namespace lol */


+ 15
- 12
src/lol/sys/init.h 查看文件

@@ -1,11 +1,13 @@
// //
// Lol Engine
// Lol Engine
// //
// Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net>
// This program is free software; you can redistribute it and/or
// modify it under the terms of the Do What The Fuck You Want To
// Public License, Version 2, as published by Sam Hocevar. See
// http://www.wtfpl.net/ for more details.
// Copyright © 2010—2018 Sam Hocevar <sam@hocevar.net>
//
// Lol Engine is free software. It comes without any warranty, to
// the extent permitted by applicable law. You can redistribute it
// and/or modify it under the terms of the Do What the Fuck You Want
// to Public License, Version 2, as published by the WTFPL Task Force.
// See http://www.wtfpl.net/ for more details.
// //


#pragma once #pragma once
@@ -15,7 +17,8 @@
// ------------------------------- // -------------------------------
// //


#include <stdint.h>
#include <string>
#include <cstdint>


namespace lol namespace lol
{ {
@@ -46,12 +49,12 @@ namespace sys
{ {


extern void init(int argc, char *argv[], extern void init(int argc, char *argv[],
String const &projectdir = LOL_CONFIG_PROJECTDIR,
String const &solutiondir = LOL_CONFIG_SOLUTIONDIR,
String const &sourcesubdir = LOL_CONFIG_SOURCESUBDIR);
std::string const &projectdir = LOL_CONFIG_PROJECTDIR,
std::string const &solutiondir = LOL_CONFIG_SOLUTIONDIR,
std::string const &sourcesubdir = LOL_CONFIG_SOURCESUBDIR);


extern void add_data_dir(String const &dir);
extern array<String> get_path_list(String const &file);
extern void add_data_dir(std::string const &dir);
extern array<std::string> get_path_list(std::string const &file);


} /* namespace sys */ } /* namespace sys */




+ 8
- 8
src/lol/sys/threadtypes.h 查看文件

@@ -37,7 +37,7 @@ struct ThreadStatusBase : public StructSafeEnum
THREAD_STOPPED, THREAD_STOPPED,
}; };
protected: protected:
virtual bool BuildEnumMap(std::map<int64_t, String>& enum_map)
virtual bool BuildEnumMap(std::map<int64_t, std::string>& enum_map)
{ {
enum_map[NOTHING] = "NOTHING"; enum_map[NOTHING] = "NOTHING";
enum_map[THREAD_STARTED] = "THREAD_STARTED"; enum_map[THREAD_STARTED] = "THREAD_STARTED";
@@ -59,7 +59,7 @@ struct ThreadJobTypeBase : public StructSafeEnum
THREAD_STOP THREAD_STOP
}; };
protected: protected:
virtual bool BuildEnumMap(std::map<int64_t, String>& enum_map)
virtual bool BuildEnumMap(std::map<int64_t, std::string>& enum_map)
{ {
enum_map[NONE] = "NONE"; enum_map[NONE] = "NONE";
enum_map[WORK_TODO] = "WORK_TODO"; enum_map[WORK_TODO] = "WORK_TODO";
@@ -229,13 +229,13 @@ public:
virtual ~FileUpdateTester(); virtual ~FileUpdateTester();


//------------------------------------------------------------------------- //-------------------------------------------------------------------------
FileUpdateTester::Status* RegisterFile(String const& path);
FileUpdateTester::Status* RegisterFile(std::string const& path);
protected: protected:
void UnregisterFile(String const& path);
void UnregisterFile(std::string const& path);
public: public:
void UnregisterFile(FileUpdateTester::Status*& status); void UnregisterFile(FileUpdateTester::Status*& status);
//TODO: Add directories //TODO: Add directories
//FileUpdateTester::Status* RegisterDirectory(String const& path, bool check_files=false);
//FileUpdateTester::Status* RegisterDirectory(std::string const& path, bool check_files=false);
virtual void TickGame(float seconds); virtual void TickGame(float seconds);
virtual void TreatResult(ThreadJob* result); virtual void TreatResult(ThreadJob* result);


@@ -243,7 +243,7 @@ private:
uint32_t m_frame_skip = 4; uint32_t m_frame_skip = 4;
uint32_t m_frame_count = 0; uint32_t m_frame_count = 0;
array<ThreadJob*> m_job_done; array<ThreadJob*> m_job_done;
std::map<String, Status*> m_files;
std::map<std::string, Status*> m_files;
}; };
typedef FileUpdateTester::Status FileUpdateStatus; typedef FileUpdateTester::Status FileUpdateStatus;


@@ -262,7 +262,7 @@ public:
{ } { }


//Returns a dummy image, and start a job to load the image on a thread //Returns a dummy image, and start a job to load the image on a thread
image* Load(const lol::String& path);
image* Load(const std::string& path);
bool CheckStatus(image* img); bool CheckStatus(image* img);


protected: protected:
@@ -270,7 +270,7 @@ protected:


private: private:
image m_dummy_image; image m_dummy_image;
std::map<String, image*> m_images;
std::map<std::string, image*> m_images;
array<image*> m_loaded_images; array<image*> m_loaded_images;
}; };




+ 5
- 5
src/lolua/baselua.cpp 查看文件

@@ -60,26 +60,26 @@ class LuaBaseData
return LUA_ERRFILE; return LUA_ERRFILE;


auto stack = LuaStack::Begin(l); auto stack = LuaStack::Begin(l);
char const *filename = stack.Get<char const*>();
std::string filename = stack.Get<std::string>();
int status = LUA_ERRFILE; int status = LUA_ERRFILE;


File f; File f;
for (auto candidate : sys::get_path_list(filename))
for (auto const &candidate : sys::get_path_list(filename))
{ {
f.Open(candidate, FileAccess::Read); f.Open(candidate, FileAccess::Read);
if (f.IsValid()) if (f.IsValid())
{ {
std::string s = f.ReadString().C();
std::string s = f.ReadString();
f.Close(); f.Close();


msg::debug("loading Lua file %s\n", candidate.C());
msg::debug("loading Lua file %s\n", candidate.c_str());
status = LuaDoCode(l, s); status = LuaDoCode(l, s);
break; break;
} }
} }


if (status == LUA_ERRFILE) if (status == LUA_ERRFILE)
msg::error("could not find Lua file %s\n", filename);
msg::error("could not find Lua file %s\n", filename.c_str());
else if (status == 1) else if (status == 1)
{ {
stack.SetIndex(-1); stack.SetIndex(-1);


+ 50
- 52
src/sys/file.cpp 查看文件

@@ -1,7 +1,7 @@
// //
// Lol Engine // Lol Engine
// //
// Copyright © 2010—2017 Sam Hocevar <sam@hocevar.net>
// Copyright © 2010—2018 Sam Hocevar <sam@hocevar.net>
// //
// Lol Engine is free software. It comes without any warranty, to // Lol Engine is free software. It comes without any warranty, to
// the extent permitted by applicable law. You can redistribute it // the extent permitted by applicable law. You can redistribute it
@@ -30,6 +30,8 @@
#endif #endif


#include <atomic> #include <atomic>
#include <string>
#include <algorithm>
#include <sys/stat.h> #include <sys/stat.h>


namespace lol namespace lol
@@ -68,18 +70,19 @@ class FileData
} }
} }


void Open(String const &file, FileAccess mode, bool force_binary)
void Open(std::string const &file, FileAccess mode, bool force_binary)
{ {
m_type = (force_binary) ? (StreamType::FileBinary) : (StreamType::File); m_type = (force_binary) ? (StreamType::FileBinary) : (StreamType::File);
#if __ANDROID__ #if __ANDROID__
ASSERT(g_assets); ASSERT(g_assets);
m_asset = AAssetManager_open(g_assets, file.C(), AASSET_MODE_UNKNOWN);
m_asset = AAssetManager_open(g_assets, file.c_str(), AASSET_MODE_UNKNOWN);
#elif HAVE_STDIO_H #elif HAVE_STDIO_H
/* FIXME: no modes, no error checking, no nothing */ /* FIXME: no modes, no error checking, no nothing */
stat(file.C(), &m_stat);
String access = (mode == FileAccess::Write) ? ("w") : ("r");
if (force_binary) access += "b";
m_fd = fopen(file.C(), access.C());
stat(file.c_str(), &m_stat);
std::string access(mode == FileAccess::Write ? "w" : "r");
if (force_binary)
access += "b";
m_fd = fopen(file.c_str(), access.c_str());
#endif #endif
} }


@@ -125,11 +128,11 @@ class FileData
#endif #endif
} }


String ReadString()
std::string ReadString()
{ {
array<uint8_t> buf; array<uint8_t> buf;
buf.resize(BUFSIZ); buf.resize(BUFSIZ);
String ret;
std::string ret;
while (IsValid()) while (IsValid())
{ {
int done = Read(&buf[0], buf.count()); int done = Read(&buf[0], buf.count());
@@ -137,7 +140,7 @@ class FileData
if (done <= 0) if (done <= 0)
break; break;


int oldsize = ret.count();
int oldsize = ret.length();
ret.resize(oldsize + done); ret.resize(oldsize + done);
memcpy(&ret[oldsize], &buf[0], done); memcpy(&ret[oldsize], &buf[0], done);


@@ -146,7 +149,7 @@ class FileData
return ret; return ret;
} }


int Write(uint8_t const *buf, int count)
int Write(void const *buf, int count)
{ {
#if __ANDROID__ #if __ANDROID__
//return AAsset_read(m_asset, buf, count); //return AAsset_read(m_asset, buf, count);
@@ -162,11 +165,6 @@ class FileData
#endif #endif
} }


int WriteString(const String &buf)
{
return Write((uint8_t const *)buf.C(), buf.count());
}

long int GetPosFromStart() long int GetPosFromStart()
{ {
#if __ANDROID__ #if __ANDROID__
@@ -274,7 +272,7 @@ void File::Open(StreamType stream)
} }


//-- //--
void File::Open(String const &file, FileAccess mode, bool force_binary)
void File::Open(std::string const &file, FileAccess mode, bool force_binary)
{ {
m_data->Open(file, mode, force_binary); m_data->Open(file, mode, force_binary);
} }
@@ -298,21 +296,21 @@ int File::Read(uint8_t *buf, int count)
} }


//-- //--
String File::ReadString()
std::string File::ReadString()
{ {
return m_data->ReadString(); return m_data->ReadString();
} }


//-- //--
int File::Write(uint8_t const *buf, int count)
int File::Write(void const *buf, int count)
{ {
return m_data->Write(buf, count); return m_data->Write(buf, count);
} }


//-- //--
int File::WriteString(const String &buf)
int File::Write(std::string const &buf)
{ {
return m_data->WriteString(buf);
return m_data->Write(buf.c_str(), buf.length());
} }


//-- //--
@@ -355,7 +353,7 @@ class DirectoryData
#endif #endif
} }


void Open(String const &directory, FileAccess mode)
void Open(std::string const &directory, FileAccess mode)
{ {
UNUSED(mode); /* FIXME */ UNUSED(mode); /* FIXME */


@@ -364,14 +362,14 @@ class DirectoryData
/* FIXME: not implemented */ /* FIXME: not implemented */
#elif defined(_WIN32) #elif defined(_WIN32)
m_directory = directory; m_directory = directory;
String filter = m_directory + String("*");
filter.replace('/', '\\', true);
std::string filter = m_directory + "*";
std::replace(filter.begin(), filter.end(), '/', '\\');
WIN32_FIND_DATA FindFileData; WIN32_FIND_DATA FindFileData;
m_handle = FindFirstFile(filter.C(), &FindFileData);
stat(directory.C(), &m_stat);
m_handle = FindFirstFile(filter.c_str(), &FindFileData);
stat(directory.c_str(), &m_stat);
#elif HAVE_STDIO_H #elif HAVE_STDIO_H
m_dd = opendir(directory.C());
stat(directory.C(), &m_stat);
m_dd = opendir(directory.c_str());
stat(directory.c_str(), &m_stat);
#endif #endif
} }


@@ -400,7 +398,7 @@ class DirectoryData
#endif #endif
} }


bool GetContentList(array<String>* files, array<String>* directories)
bool GetContentList(array<std::string>* files, array<std::string>* directories)
{ {
if (!IsValid()) if (!IsValid())
return false; return false;
@@ -408,10 +406,10 @@ class DirectoryData
#if __ANDROID__ #if __ANDROID__
/* FIXME: not implemented */ /* FIXME: not implemented */
#elif defined(_WIN32) #elif defined(_WIN32)
String filter = m_directory + String("*");
filter.replace('/', '\\', true);
std::string filter = m_directory + "*";
std::replace(filter.begin(), filter.end(), '/', '\\');
WIN32_FIND_DATA find_data; WIN32_FIND_DATA find_data;
HANDLE handle = FindFirstFile(filter.C(), &find_data);
HANDLE handle = FindFirstFile(filter.c_str(), &find_data);
bool file_valid = (handle != INVALID_HANDLE_VALUE); bool file_valid = (handle != INVALID_HANDLE_VALUE);


while (file_valid) while (file_valid)
@@ -422,12 +420,12 @@ class DirectoryData
if (find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) if (find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{ {
if (directories) if (directories)
*directories << String(std::string(find_data.cFileName).c_str());
*directories << std::string(find_data.cFileName);
} }
else else
{ {
if (files) if (files)
*files << String(find_data.cFileName);
*files << std::string(find_data.cFileName);
} }
} }
//Go for next one //Go for next one
@@ -467,7 +465,7 @@ class DirectoryData
/* FIXME: not implemented */ /* FIXME: not implemented */
#elif defined(_WIN32) #elif defined(_WIN32)
HANDLE m_handle; HANDLE m_handle;
String m_directory;
std::string m_directory;
#elif HAVE_STDIO_H #elif HAVE_STDIO_H
DIR *m_dd; DIR *m_dd;
#endif #endif
@@ -477,9 +475,9 @@ class DirectoryData
}; };


//-- DIRECTORY -- //-- DIRECTORY --
Directory::Directory(String const &name)
Directory::Directory(std::string const &name)
: m_data(new DirectoryData), : m_data(new DirectoryData),
m_name(name + String("/"))
m_name(name + "/")
{ {
++m_data->m_refcount; ++m_data->m_refcount;
} }
@@ -543,9 +541,9 @@ void Directory::Close()
} }


//-- //--
bool Directory::GetContent(array<String>* files, array<Directory>* directories)
bool Directory::GetContent(array<std::string>* files, array<Directory>* directories)
{ {
array<String> sfiles, sdirectories;
array<std::string> sfiles, sdirectories;
bool found_some = m_data->GetContentList(&sfiles, &sdirectories); bool found_some = m_data->GetContentList(&sfiles, &sdirectories);
UNUSED(found_some); UNUSED(found_some);


@@ -561,7 +559,7 @@ bool Directory::GetContent(array<String>* files, array<Directory>* directories)
} }


//-- //--
bool Directory::GetContent(array<String>& files, array<Directory>& directories)
bool Directory::GetContent(array<std::string>& files, array<Directory>& directories)
{ {
return GetContent(&files, &directories); return GetContent(&files, &directories);
} }
@@ -573,13 +571,13 @@ bool Directory::GetContent(array<Directory>& directories)
} }


//-- //--
bool Directory::GetContent(array<String>& files)
bool Directory::GetContent(array<std::string>& files)
{ {
return GetContent(&files, nullptr); return GetContent(&files, nullptr);
} }


//-- //--
String Directory::GetName()
std::string Directory::GetName()
{ {
return m_name; return m_name;
} }
@@ -591,33 +589,33 @@ long int Directory::GetModificationTime()
} }


//-- //--
String Directory::GetCurrent()
std::string Directory::GetCurrent()
{ {
String result;
std::string ret;
#if __ANDROID__ #if __ANDROID__
/* FIXME: not implemented */ /* FIXME: not implemented */
#elif defined(_WIN32) #elif defined(_WIN32)
TCHAR buff[MAX_PATH * 2]; TCHAR buff[MAX_PATH * 2];
GetCurrentDirectory(MAX_PATH, buff); GetCurrentDirectory(MAX_PATH, buff);
result = buff;
result.replace('\\', '/', true);
ret = buff;
std::replace(ret.begin(), ret.end(), '\\', '/');
#elif HAVE_STDIO_H #elif HAVE_STDIO_H
/* FIXME: not implemented */ /* FIXME: not implemented */
#endif #endif
return result;
return ret;
} }


//-- //--
bool Directory::SetCurrent(String directory)
bool Directory::SetCurrent(std::string directory)
{ {
#if __ANDROID__ #if __ANDROID__
/* FIXME: not implemented */ /* FIXME: not implemented */
#elif defined(_WIN32) #elif defined(_WIN32)
String result = directory;
result.replace('/', '\\', true);
return !!SetCurrentDirectory(result.C());
std::string result = directory;
std::replace(result.begin(), result.end(), '/', '\\');
return !!SetCurrentDirectory(result.c_str());
#elif HAVE_UNISTD_H #elif HAVE_UNISTD_H
chdir(directory.C());
chdir(directory.c_str());
#endif #endif
return false; return false;
} }


+ 26
- 26
src/sys/init.cpp 查看文件

@@ -1,7 +1,7 @@
// //
// Lol Engine // Lol Engine
// //
// Copyright © 2010—2015 Sam Hocevar <sam@hocevar.net>
// Copyright © 2010—2018 Sam Hocevar <sam@hocevar.net>
// //
// Lol Engine is free software. It comes without any warranty, to // Lol Engine is free software. It comes without any warranty, to
// the extent permitted by applicable law. You can redistribute it // the extent permitted by applicable law. You can redistribute it
@@ -36,18 +36,18 @@ namespace sys
# define SEPARATOR '/' # define SEPARATOR '/'
#endif #endif


static array<String> data_dir;
static array<std::string> data_dir;


void init(int argc, char *argv[], void init(int argc, char *argv[],
String const &projectdir,
String const &solutiondir,
String const &sourcesubdir)
std::string const &projectdir,
std::string const &solutiondir,
std::string const &sourcesubdir)
{ {
using namespace std; using namespace std;


msg::debug("project dir: “%s”\n", projectdir.C());
msg::debug("solution dir: “%s”\n", solutiondir.C());
msg::debug("source subdir: “%s”\n", sourcesubdir.C());
msg::debug("project dir: “%s”\n", projectdir.c_str());
msg::debug("solution dir: “%s”\n", solutiondir.c_str());
msg::debug("source subdir: “%s”\n", sourcesubdir.c_str());


/* /*
* Retrieve binary directory, defaulting to no directory on Android * Retrieve binary directory, defaulting to no directory on Android
@@ -55,9 +55,9 @@ void init(int argc, char *argv[],
*/ */


#if __ANDROID__ || EMSCRIPTEN #if __ANDROID__ || EMSCRIPTEN
String binarydir = "";
std::string binarydir = "";
#else #else
String binarydir = ".";
std::string binarydir = ".";
char *cwd = nullptr; char *cwd = nullptr;


# if HAVE_GETCWD # if HAVE_GETCWD
@@ -78,7 +78,7 @@ void init(int argc, char *argv[],
{ {
char const *last_sep = strrchr(argv[0], SEPARATOR); char const *last_sep = strrchr(argv[0], SEPARATOR);
if (last_sep) if (last_sep)
binarydir = String(argv[0], last_sep - argv[0] + 1);
binarydir = std::string(argv[0], last_sep - argv[0] + 1);
} }
#endif #endif


@@ -89,31 +89,31 @@ void init(int argc, char *argv[],
* add current directory in case we were launched from another place. * add current directory in case we were launched from another place.
*/ */


if (!got_rootdir && projectdir.count() && solutiondir.count())
if (!got_rootdir && projectdir.length() && solutiondir.length())
{ {
/* This data dir is for standalone executables */ /* This data dir is for standalone executables */
String rootdir = binarydir;
if (rootdir.count() && rootdir.last() != SEPARATOR)
std::string rootdir = binarydir;
if (rootdir.length() && rootdir.back() != SEPARATOR)
rootdir += SEPARATOR; rootdir += SEPARATOR;
add_data_dir(rootdir); add_data_dir(rootdir);


/* This data dir is for engine stuff */ /* This data dir is for engine stuff */
rootdir = solutiondir; rootdir = solutiondir;
if (rootdir.count() && rootdir.last() != SEPARATOR)
if (rootdir.length() && rootdir.back() != SEPARATOR)
rootdir += SEPARATOR; rootdir += SEPARATOR;
rootdir += "../src/"; /* FIXME: use SEPARATOR? */ rootdir += "../src/"; /* FIXME: use SEPARATOR? */
add_data_dir(rootdir); add_data_dir(rootdir);


/* This data dir is for submodule support stuff */ /* This data dir is for submodule support stuff */
rootdir = solutiondir; rootdir = solutiondir;
if (rootdir.count() && rootdir.last() != SEPARATOR)
if (rootdir.length() && rootdir.back() != SEPARATOR)
rootdir += SEPARATOR; rootdir += SEPARATOR;
rootdir += "./lol/src/"; /* FIXME: use SEPARATOR? */ rootdir += "./lol/src/"; /* FIXME: use SEPARATOR? */
add_data_dir(rootdir); add_data_dir(rootdir);


/* This data dir is for project-specific stuff */ /* This data dir is for project-specific stuff */
rootdir = projectdir; rootdir = projectdir;
if (rootdir.count() && rootdir.last() != SEPARATOR)
if (rootdir.length() && rootdir.back() != SEPARATOR)
rootdir += SEPARATOR; rootdir += SEPARATOR;
add_data_dir(rootdir); add_data_dir(rootdir);


@@ -128,14 +128,14 @@ void init(int argc, char *argv[],
{ {
/* First climb back the hierarchy to get to the engine root and /* First climb back the hierarchy to get to the engine root and
* add a data dir for engine stuff. */ * add a data dir for engine stuff. */
String rootdir = binarydir;
if (rootdir.count() && rootdir.last() != SEPARATOR)
std::string rootdir = binarydir;
if (rootdir.length() && rootdir.back() != SEPARATOR)
rootdir += SEPARATOR; rootdir += SEPARATOR;
for (int i = 1; i < sourcesubdir.count(); ++i)
for (int i = 1; i < (int)sourcesubdir.length(); ++i)
{ {
if ((sourcesubdir[i] == SEPARATOR if ((sourcesubdir[i] == SEPARATOR
&& sourcesubdir[i - 1] != SEPARATOR) && sourcesubdir[i - 1] != SEPARATOR)
|| i == sourcesubdir.count() - 1)
|| i == (int)sourcesubdir.length() - 1)
rootdir += "../"; rootdir += "../";
} }
rootdir += "src/"; rootdir += "src/";
@@ -148,24 +148,24 @@ void init(int argc, char *argv[],
got_rootdir = true; got_rootdir = true;
} }


msg::debug("binary dir: “%s”\n", binarydir.C());
msg::debug("binary dir: “%s”\n", binarydir.c_str());
for (int i = 0; i < data_dir.count(); ++i) for (int i = 0; i < data_dir.count(); ++i)
msg::debug("data dir %d/%d: “%s”\n", i + 1, data_dir.count(), msg::debug("data dir %d/%d: “%s”\n", i + 1, data_dir.count(),
data_dir[i].C());
data_dir[i].c_str());
} }


/* /*
* Data directory handling * Data directory handling
*/ */


void add_data_dir(String const &dir)
void add_data_dir(std::string const &dir)
{ {
data_dir << dir; data_dir << dir;
} }


array<String> get_path_list(String const &file)
array<std::string> get_path_list(std::string const &file)
{ {
array<String> ret;
array<std::string> ret;


/* If not an absolute path, look through known data directories */ /* If not an absolute path, look through known data directories */
if (file[0] != '/') if (file[0] != '/')


+ 25
- 26
src/sys/threadtypes.cpp 查看文件

@@ -35,12 +35,12 @@ public:
char const *GetName() { return "<FileUpdateTesterJob>"; } char const *GetName() { return "<FileUpdateTesterJob>"; }
FileUpdateTesterJob() FileUpdateTesterJob()
: ThreadJob(ThreadJobType::NONE) { } : ThreadJob(ThreadJobType::NONE) { }
FileUpdateTesterJob(String path)
FileUpdateTesterJob(std::string const &path)
: ThreadJob(ThreadJobType::WORK_TODO) : ThreadJob(ThreadJobType::WORK_TODO)
{ {
m_path = path; m_path = path;
} }
String& GetPath() { return m_path; }
std::string const &GetPath() { return m_path; }
long int GetTime() { return m_time; } long int GetTime() { return m_time; }
bool HasUpdated() { return m_updated; } bool HasUpdated() { return m_updated; }
void Restart() void Restart()
@@ -52,9 +52,9 @@ public:
protected: protected:
virtual bool DoWork() virtual bool DoWork()
{ {
array<String> pathlist = sys::get_path_list(m_path);
array<std::string> pathlist = sys::get_path_list(m_path);
File f; File f;
for (String path : pathlist)
for (auto const &path : pathlist)
{ {
f.Open(path, FileAccess::Read); f.Open(path, FileAccess::Read);
if (f.IsValid()) if (f.IsValid())
@@ -77,10 +77,10 @@ protected:
} }


//----------------- //-----------------
bool m_ready = false;
String m_path = String();
long int m_time = 0;
bool m_updated = false;
bool m_ready = false;
std::string m_path;
long int m_time = 0;
bool m_updated = false;
}; };


//FileUpdateTester ------------------------------------------------------------ //FileUpdateTester ------------------------------------------------------------
@@ -90,14 +90,14 @@ FileUpdateTester::~FileUpdateTester()
} }


//File interface -------------------------------------------------------------- //File interface --------------------------------------------------------------
FileUpdateTester::Status* FileUpdateTester::RegisterFile(String const& path)
FileUpdateTester::Status* FileUpdateTester::RegisterFile(std::string const& path)
{ {
DispatchJob(new FileUpdateTesterJob(path)); DispatchJob(new FileUpdateTesterJob(path));
m_files[path] = new FileUpdateTester::Status(); m_files[path] = new FileUpdateTester::Status();
return m_files[path]; return m_files[path];
} }


void FileUpdateTester::UnregisterFile(String const& path)
void FileUpdateTester::UnregisterFile(std::string const& path)
{ {
ASSERT(has_key(m_files, path)); ASSERT(has_key(m_files, path));
delete m_files[path]; delete m_files[path];
@@ -107,8 +107,7 @@ void FileUpdateTester::UnregisterFile(String const& path)
void FileUpdateTester::UnregisterFile(FileUpdateTester::Status*& status) void FileUpdateTester::UnregisterFile(FileUpdateTester::Status*& status)
{ {
ASSERT(status); ASSERT(status);
array<String> all_keys = keys(m_files);
for (String key : all_keys)
for (auto const &key : keys(m_files))
{ {
if (m_files[key] == status) if (m_files[key] == status)
{ {
@@ -123,10 +122,9 @@ void FileUpdateTester::UnregisterFile(FileUpdateTester::Status*& status)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void FileUpdateTester::TickGame(float seconds) void FileUpdateTester::TickGame(float seconds)
{ {
//Reset update for this frame
array<String> all_keys = keys(m_files);
for (String key : all_keys)
m_files[key]->SetUpdated(false);
// Reset update for this frame
for (auto &kv : m_files)
kv.second->SetUpdated(false);


super::TickGame(seconds); super::TickGame(seconds);


@@ -160,30 +158,31 @@ class AsyncImageJob : public ThreadJob
public: public:
char const *GetName() { return "<AsyncImageJob>"; } char const *GetName() { return "<AsyncImageJob>"; }
AsyncImageJob() AsyncImageJob()
: ThreadJob(ThreadJobType::NONE)
: ThreadJob(ThreadJobType::NONE)
{ {
m_path = String();
} }
AsyncImageJob(String path)
: ThreadJob(ThreadJobType::WORK_TODO)

AsyncImageJob(std::string const &path)
: ThreadJob(ThreadJobType::WORK_TODO),
m_path(path)
{ {
m_path = path;
} }
String const& GetPath() { return m_path; }

std::string const& GetPath() { return m_path; }
Image const& GetImage() { return m_image; } Image const& GetImage() { return m_image; }


protected: protected:
virtual bool DoWork() virtual bool DoWork()
{ {
return m_image.load(m_path.C());
return m_image.load(m_path);
} }


String m_path;
Image m_image;
std::string m_path;
Image m_image;
}; };


//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
Image* AsyncImageLoader::Load(const lol::String& path)
Image* AsyncImageLoader::Load(std::string const &path)
{ {
//Create a job //Create a job
AsyncImageJob* job = new AsyncImageJob(path); AsyncImageJob* job = new AsyncImageJob(path);


Loading…
取消
儲存