Browse Source

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

legacy
Sam Hocevar 7 years ago
parent
commit
9dbfa4d550
25 changed files with 282 additions and 275 deletions
  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 View File

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

builder.Build(code);

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



+ 5
- 5
src/audio/sample.cpp View File

@@ -1,7 +1,7 @@
//
// 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
// the extent permitted by applicable law. You can redistribute it
@@ -41,7 +41,7 @@ class sample_data
friend class sample;

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

#if defined LOL_USE_SDL_MIXER
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)
break;
}
@@ -88,7 +88,7 @@ void sample::TickGame(float seconds)

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

void sample::play()


+ 11
- 9
src/image/codec/android-image.cpp View File

@@ -1,7 +1,7 @@
//
// 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
// the extent permitted by applicable law. You can redistribute it
@@ -14,6 +14,8 @@

#if defined __ANDROID__

#include <string>

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

@@ -35,9 +37,9 @@ extern ANativeActivity *g_activity;
class AndroidImageCodec : public ResourceCodec
{
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 uint8_t *GetData() const;
@@ -50,7 +52,7 @@ private:

DECLARE_IMAGE_CODEC(AndroidImageCodec, 100)

ResourceCodecData* AndroidImageCodec::Load(char const *path)
ResourceCodecData* AndroidImageCodec::Load(std::string const &path)
{
JNIEnv *env;
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 !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
return false;
}
@@ -73,13 +75,13 @@ ResourceCodecData* AndroidImageCodec::Load(char const *path)

mid = env->GetMethodID(cls, "openImage",
"(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);
env->DeleteLocalRef(name);
if (!m_bmp)
{
#if !LOL_BUILD_RELEASE
msg::error("could not load %s\n", path);
msg::error("could not load %s\n", path.c_str());
#endif
return false;
}
@@ -109,7 +111,7 @@ ResourceCodecData* AndroidImageCodec::Load(char const *path)
return new ResourceCodecData();
}

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



+ 9
- 7
src/image/codec/dummy-image.cpp View File

@@ -1,7 +1,7 @@
//
// 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
// the extent permitted by applicable law. You can redistribute it
@@ -12,6 +12,8 @@

#include <lol/engine-internal.h>

#include <string>

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

namespace lol
@@ -24,9 +26,9 @@ namespace lol
class DummyImageCodec : public ResourceCodec
{
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
@@ -36,9 +38,9 @@ DECLARE_IMAGE_CODEC(DummyImageCodec, 0)
* 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;

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

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



+ 24
- 29
src/image/codec/gdiplus-image.cpp View File

@@ -1,7 +1,7 @@
//
// 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
// the extent permitted by applicable law. You can redistribute it
@@ -10,21 +10,16 @@
// 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
# include <string>
# include <algorithm>
using std::min;
using std::max;
# include <windows.h>
# include <objidl.h> // for DEFINE_GUID
# include <gdiplus.h>
#endif

#include <lol/engine-internal.h>

#if LOL_USE_GDIPLUS

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

@@ -38,9 +33,9 @@ namespace lol
class GdiPlusImageCodec : public ResourceCodec
{
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)
@@ -49,7 +44,7 @@ DECLARE_IMAGE_CODEC(GdiPlusImageCodec, 100)
* Public Image class
*/

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

array<String> pathlist = sys::get_path_list(path);
array<std::string> pathlist = sys::get_path_list(path);
Gdiplus::Bitmap *bitmap = nullptr;
for (auto fullpath : pathlist)
for (auto const &fullpath : pathlist)
{
size_t len;
len = mbstowcs(nullptr, fullpath.C(), 0);
len = mbstowcs(nullptr, fullpath.c_str(), 0);
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;
continue;
}
@@ -85,7 +80,7 @@ ResourceCodecData* GdiPlusImageCodec::Load(char const *path)
{
if (status != Gdiplus::InvalidParameter)
msg::error("error %d loading %s\n",
status, fullpath.C());
status, fullpath.c_str());
delete bitmap;
bitmap = nullptr;
}
@@ -130,7 +125,7 @@ ResourceCodecData* GdiPlusImageCodec::Load(char const *path)
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);
if (data_image == nullptr)
@@ -141,15 +136,15 @@ bool GdiPlusImageCodec::Save(char const *path, ResourceCodecData* data)
Gdiplus::GdiplusStartup(&token, &input, nullptr);

wchar_t const *fmt;
if (strstr(path, ".gif"))
if (ends_with(path, ".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";
else if (strstr(path, ".png"))
else if (ends_with(path, ".png"))
fmt = L"image/png";
else if (strstr(path, ".tiff"))
else if (ends_with(path, ".tiff"))
fmt = L"image/tiff";
else /* if (strstr(path, ".bmp")) */
else /* if (ends_with(path, ".bmp")) */
fmt = L"image/bmp";

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

size_t len;
len = mbstowcs(nullptr, path, 0);
len = mbstowcs(nullptr, path.c_str(), 0);
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[] codecs;
return false;
@@ -212,7 +207,7 @@ bool GdiPlusImageCodec::Save(char const *path, ResourceCodecData* data)

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[] codecs;
delete b;


+ 13
- 11
src/image/codec/imlib2-image.cpp View File

@@ -1,7 +1,7 @@
//
// 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
// the extent permitted by applicable law. You can redistribute it
@@ -14,6 +14,8 @@

#if defined LOL_USE_IMLIB2

#include <string>

#include <Imlib2.h>

/* Check that the Imlib2 types are safe */
@@ -34,21 +36,21 @@ namespace lol
class Imlib2ImageCodec : public ResourceCodec
{
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. */
DECLARE_IMAGE_CODEC(Imlib2ImageCodec, 70)

ResourceCodecData *Imlib2ImageCodec::Load(char const *path)
ResourceCodecData *Imlib2ImageCodec::Load(std::string const &path)
{
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)
break;
}
@@ -56,7 +58,7 @@ ResourceCodecData *Imlib2ImageCodec::Load(char const *path)
if (!im)
{
#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
return nullptr;
}
@@ -68,7 +70,7 @@ ResourceCodecData *Imlib2ImageCodec::Load(char const *path)
{
imlib_free_image();
#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
return nullptr;
}
@@ -93,7 +95,7 @@ ResourceCodecData *Imlib2ImageCodec::Load(char const *path)
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);
if (data_image == nullptr)
@@ -120,7 +122,7 @@ bool Imlib2ImageCodec::Save(char const *path, ResourceCodecData *data)
imlib_image_put_back_data((DATA32 *)dstdata);
image->unlock(srcdata);

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

return true;


+ 10
- 8
src/image/codec/ios-image.cpp View File

@@ -1,7 +1,7 @@
//
// 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
// the extent permitted by applicable law. You can redistribute it
@@ -14,6 +14,8 @@

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

#include <string>

#import <UIKit/UIKit.h>

#include "../../image/resource-private.h"
@@ -28,9 +30,9 @@ namespace lol
class IosImageCodec : public ResourceCodec
{
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)
@@ -39,9 +41,9 @@ DECLARE_IMAGE_CODEC(IosImageCodec, 100)
* 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: @"/"];
NSString *filename = [chunks objectAtIndex: [chunks count] - 1];
chunks = [filename componentsSeparatedByString: @"."];
@@ -52,7 +54,7 @@ ResourceCodecData* IosImageCodec::Load(char const *path)
if (!image)
{
#if !LOL_BUILD_RELEASE
msg::error("could not load %s\n", path);
msg::error("could not load %s\n", path.c_str());
#endif
return nullptr;
}
@@ -78,7 +80,7 @@ ResourceCodecData* IosImageCodec::Load(char const *path)
return new ResourceCodecData();
}

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



+ 10
- 10
src/image/codec/oric-image.cpp View File

@@ -33,12 +33,12 @@ namespace lol
class OricImageCodec : public ResourceCodec
{
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:
static std::string ReadScreen(char const *name);
static std::string ReadScreen(std::string const &name);
static void WriteScreen(image &image, array<uint8_t> &result);
};

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

ResourceCodecData* OricImageCodec::Load(char const *path)
ResourceCodecData* OricImageCodec::Load(std::string const &path)
{
static u8vec4 const pal[8] =
{
@@ -109,13 +109,13 @@ ResourceCodecData* OricImageCodec::Load(char const *path)
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);
if (data_image == nullptr)
return false;

int len = (int)strlen(path);
int len = (int)path.length();
if (len < 4 || path[len - 4] != '.'
|| std::toupper(path[len - 3]) != 'T'
|| 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;

/* 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 << 0;

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

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

/* Skip the sync bytes */


+ 12
- 10
src/image/codec/sdl-image.cpp View File

@@ -1,7 +1,7 @@
//
// 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
// the extent permitted by applicable law. You can redistribute it
@@ -25,6 +25,8 @@
# include <SDL_image.h>
#endif

#include <string>

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

namespace lol
@@ -37,22 +39,22 @@ namespace lol
class SdlImageCodec : public ResourceCodec
{
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);
};

DECLARE_IMAGE_CODEC(SdlImageCodec, 50)

ResourceCodecData* SdlImageCodec::Load(char const *path)
ResourceCodecData* SdlImageCodec::Load(std::string const &path)
{
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)
break;
}
@@ -60,7 +62,7 @@ ResourceCodecData* SdlImageCodec::Load(char const *path)
if (!surface)
{
#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
return nullptr;
}
@@ -86,7 +88,7 @@ ResourceCodecData* SdlImageCodec::Load(char const *path)
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);
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);
image->unlock(pixel_data);

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

return ret == 0;


+ 5
- 5
src/image/codec/zed-image.cpp View File

@@ -27,9 +27,9 @@ namespace lol
class ZedImageCodec : public ResourceCodec
{
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)
@@ -38,7 +38,7 @@ DECLARE_IMAGE_CODEC(ZedImageCodec, 10)
* Public Image class
*/

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

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


+ 5
- 5
src/image/codec/zed-palette-image.cpp View File

@@ -27,9 +27,9 @@ namespace lol
class ZedPaletteImageCodec : public ResourceCodec
{
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)
@@ -38,7 +38,7 @@ DECLARE_IMAGE_CODEC(ZedPaletteImageCodec, 10)
* Public Image class
*/

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

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


+ 3
- 3
src/image/image.cpp View File

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

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

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

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


+ 8
- 8
src/image/movie.cpp View File

@@ -1,7 +1,7 @@
//
// 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
// the extent permitted by applicable law. You can redistribute it
@@ -29,12 +29,12 @@ namespace lol
{

#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];
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)
@@ -69,11 +69,11 @@ movie::movie(ivec2 size)
#endif
}

bool movie::open_file(char const *filename)
bool movie::open_file(std::string const &filename)
{
#if LOL_USE_FFMPEG
/* 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)
{
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))
{
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)
{
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;
}
}


+ 4
- 4
src/image/resource-private.h View File

@@ -1,7 +1,7 @@
//
// 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>
//
// Lol Engine is free software. It comes without any warranty, to
@@ -24,9 +24,9 @@ namespace lol
class ResourceCodec
{
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 */
int m_priority;


+ 7
- 7
src/image/resource.cpp View File

@@ -1,7 +1,7 @@
//
// 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>
//
// Lol Engine is free software. It comes without any warranty, to
@@ -79,7 +79,7 @@ g_resource_loader;
* The public resource loader
*/

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

//Log error, because we shouldn't be here
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;
}

bool ResourceLoader::Save(char const *path, ResourceCodecData* data)
bool ResourceLoader::Save(std::string const &path, ResourceCodecData* data)
{
ResourceCodec* last_codec = nullptr;
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))
{
msg::debug("image::save: codec %s succesfully saved %s.\n",
codec->GetName(), path);
codec->GetName().c_str(), path.c_str());
return true;
}
}

//Log error, because we shouldn't be here
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;
}



+ 6
- 4
src/lol/image/image.h View File

@@ -1,7 +1,7 @@
//
// 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
// the extent permitted by applicable law. You can redistribute it
@@ -22,6 +22,8 @@
#include <lol/math/geometry.h>
#include <lol/image/pixel.h>

#include <string>

namespace lol
{

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

/* Rule of three */
image(image const &other);
@@ -76,8 +78,8 @@ public:
void DummyFill();
void Copy(uint8_t* pixels, ivec2 const& size, PixelFormat fmt);
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 */
ivec2 size() const;


+ 2
- 2
src/lol/image/movie.h View File

@@ -1,7 +1,7 @@
//
// 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
// the extent permitted by applicable law. You can redistribute it
@@ -33,7 +33,7 @@ class movie
public:
movie(ivec2 size);

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



+ 3
- 3
src/lol/image/resource.h View File

@@ -1,7 +1,7 @@
//
// 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>
//
// Lol Engine is free software. It comes without any warranty, to
@@ -66,8 +66,8 @@ namespace lol
class ResourceLoader
{
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 */


+ 15
- 15
src/lol/sys/file.h View File

@@ -32,7 +32,7 @@ struct FileAccessBase : public StructSafeEnum
Write
};
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[Write] = "Write";
@@ -53,7 +53,7 @@ struct StreamTypeBase : public StructSafeEnum
FileBinary
};
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[StdOut] = "StdOut";
@@ -74,14 +74,14 @@ public:
~File();

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;
void Close();

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();
void SetPosFromStart(long int pos);
long int size();
@@ -94,7 +94,7 @@ private:
class Directory
{
public:
Directory(String const &name);
Directory(std::string const &name);
Directory(Directory const &that);
Directory &operator =(Directory const &that);
~Directory();
@@ -104,20 +104,20 @@ public:
void Close();

private:
bool GetContent(array<String>* files, array<Directory>* directories);
bool GetContent(array<std::string>* files, array<Directory>* directories);
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<String>& files);
String GetName();
bool GetContent(array<std::string>& files);
std::string GetName();
long int GetModificationTime();

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

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

} /* namespace lol */


+ 15
- 12
src/lol/sys/init.h View File

@@ -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
@@ -15,7 +17,8 @@
// -------------------------------
//

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

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

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 */



+ 8
- 8
src/lol/sys/threadtypes.h View File

@@ -37,7 +37,7 @@ struct ThreadStatusBase : public StructSafeEnum
THREAD_STOPPED,
};
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[THREAD_STARTED] = "THREAD_STARTED";
@@ -59,7 +59,7 @@ struct ThreadJobTypeBase : public StructSafeEnum
THREAD_STOP
};
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[WORK_TODO] = "WORK_TODO";
@@ -229,13 +229,13 @@ public:
virtual ~FileUpdateTester();

//-------------------------------------------------------------------------
FileUpdateTester::Status* RegisterFile(String const& path);
FileUpdateTester::Status* RegisterFile(std::string const& path);
protected:
void UnregisterFile(String const& path);
void UnregisterFile(std::string const& path);
public:
void UnregisterFile(FileUpdateTester::Status*& status);
//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 TreatResult(ThreadJob* result);

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

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

//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);

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

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



+ 5
- 5
src/lolua/baselua.cpp View File

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

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

File f;
for (auto candidate : sys::get_path_list(filename))
for (auto const &candidate : sys::get_path_list(filename))
{
f.Open(candidate, FileAccess::Read);
if (f.IsValid())
{
std::string s = f.ReadString().C();
std::string s = f.ReadString();
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);
break;
}
}

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)
{
stack.SetIndex(-1);


+ 50
- 52
src/sys/file.cpp View File

@@ -1,7 +1,7 @@
//
// 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
// the extent permitted by applicable law. You can redistribute it
@@ -30,6 +30,8 @@
#endif

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

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);
#if __ANDROID__
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
/* 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
}

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

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

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

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

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

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

long int GetPosFromStart()
{
#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);
}
@@ -298,21 +296,21 @@ int File::Read(uint8_t *buf, int count)
}

//--
String File::ReadString()
std::string File::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);
}

//--
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
}

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

@@ -364,14 +362,14 @@ class DirectoryData
/* FIXME: not implemented */
#elif defined(_WIN32)
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;
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
m_dd = opendir(directory.C());
stat(directory.C(), &m_stat);
m_dd = opendir(directory.c_str());
stat(directory.c_str(), &m_stat);
#endif
}

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

bool GetContentList(array<String>* files, array<String>* directories)
bool GetContentList(array<std::string>* files, array<std::string>* directories)
{
if (!IsValid())
return false;
@@ -408,10 +406,10 @@ class DirectoryData
#if __ANDROID__
/* FIXME: not implemented */
#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;
HANDLE handle = FindFirstFile(filter.C(), &find_data);
HANDLE handle = FindFirstFile(filter.c_str(), &find_data);
bool file_valid = (handle != INVALID_HANDLE_VALUE);

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

//-- DIRECTORY --
Directory::Directory(String const &name)
Directory::Directory(std::string const &name)
: m_data(new DirectoryData),
m_name(name + String("/"))
m_name(name + "/")
{
++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);
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);
}
@@ -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);
}

//--
String Directory::GetName()
std::string Directory::GetName()
{
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__
/* FIXME: not implemented */
#elif defined(_WIN32)
TCHAR buff[MAX_PATH * 2];
GetCurrentDirectory(MAX_PATH, buff);
result = buff;
result.replace('\\', '/', true);
ret = buff;
std::replace(ret.begin(), ret.end(), '\\', '/');
#elif HAVE_STDIO_H
/* FIXME: not implemented */
#endif
return result;
return ret;
}

//--
bool Directory::SetCurrent(String directory)
bool Directory::SetCurrent(std::string directory)
{
#if __ANDROID__
/* FIXME: not implemented */
#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
chdir(directory.C());
chdir(directory.c_str());
#endif
return false;
}


+ 26
- 26
src/sys/init.cpp View File

@@ -1,7 +1,7 @@
//
// 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
// the extent permitted by applicable law. You can redistribute it
@@ -36,18 +36,18 @@ namespace sys
# define SEPARATOR '/'
#endif

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

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;

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
@@ -55,9 +55,9 @@ void init(int argc, char *argv[],
*/

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

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

@@ -89,31 +89,31 @@ void init(int argc, char *argv[],
* 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 */
String rootdir = binarydir;
if (rootdir.count() && rootdir.last() != SEPARATOR)
std::string rootdir = binarydir;
if (rootdir.length() && rootdir.back() != SEPARATOR)
rootdir += SEPARATOR;
add_data_dir(rootdir);

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

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

/* This data dir is for project-specific stuff */
rootdir = projectdir;
if (rootdir.count() && rootdir.last() != SEPARATOR)
if (rootdir.length() && rootdir.back() != SEPARATOR)
rootdir += SEPARATOR;
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
* 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;
for (int i = 1; i < sourcesubdir.count(); ++i)
for (int i = 1; i < (int)sourcesubdir.length(); ++i)
{
if ((sourcesubdir[i] == SEPARATOR
&& sourcesubdir[i - 1] != SEPARATOR)
|| i == sourcesubdir.count() - 1)
|| i == (int)sourcesubdir.length() - 1)
rootdir += "../";
}
rootdir += "src/";
@@ -148,24 +148,24 @@ void init(int argc, char *argv[],
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)
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
*/

void add_data_dir(String const &dir)
void add_data_dir(std::string const &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 (file[0] != '/')


+ 25
- 26
src/sys/threadtypes.cpp View File

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

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

void FileUpdateTester::UnregisterFile(String const& path)
void FileUpdateTester::UnregisterFile(std::string const& path)
{
ASSERT(has_key(m_files, path));
delete m_files[path];
@@ -107,8 +107,7 @@ void FileUpdateTester::UnregisterFile(String const& path)
void FileUpdateTester::UnregisterFile(FileUpdateTester::Status*& 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)
{
@@ -123,10 +122,9 @@ void FileUpdateTester::UnregisterFile(FileUpdateTester::Status*& status)
//-----------------------------------------------------------------------------
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);

@@ -160,30 +158,31 @@ class AsyncImageJob : public ThreadJob
public:
char const *GetName() { return "<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; }

protected:
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
AsyncImageJob* job = new AsyncImageJob(path);


Loading…
Cancel
Save