Browse Source

Merge remote-tracking branch 'origin/lolperso_changes' into lolperso_changes

legacy
touky 8 years ago
parent
commit
a68b433ccc
4 changed files with 39 additions and 32 deletions
  1. +17
    -10
      src/image/codec/imlib2-image.cpp
  2. +1
    -1
      src/image/codec/sdl-image.cpp
  3. +1
    -1
      src/image/resource.cpp
  4. +20
    -20
      src/lolua/baselua.h

+ 17
- 10
src/image/codec/imlib2-image.cpp View File

@@ -22,7 +22,7 @@ static_assert(sizeof(DATA32) == sizeof(uint32_t), "Imlib2 type DATA32 is broken"
static_assert(sizeof(DATA16) == sizeof(uint16_t), "Imlib2 type DATA16 is broken");
static_assert(sizeof(DATA8) == sizeof(uint8_t), "Imlib2 type DATA8 is broken");

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

namespace lol
{
@@ -31,17 +31,18 @@ namespace lol
* Imlib2 image codec
*/

class Imlib2ImageCodec : public ImageCodec
class Imlib2ImageCodec : public ResourceCodec
{
public:
virtual bool Load(Image *image, char const *path);
virtual bool Save(Image *image, char const *path);
virtual char const *GetName() { return "<Imlib2ImageCodec>"; }
virtual ResourceCodecData* Load(char const *path);
virtual bool Save(char const *path, ResourceCodecData* data);
};

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

bool Imlib2ImageCodec::Load(Image *image, char const *path)
ResourceCodecData *Imlib2ImageCodec::Load(char const *path)
{
Imlib_Image im = nullptr;

@@ -57,7 +58,7 @@ bool Imlib2ImageCodec::Load(Image *image, char const *path)
#if !LOL_BUILD_RELEASE
msg::error("could not load image %s\n", path);
#endif
return false;
return nullptr;
}

imlib_context_set_image(im);
@@ -69,11 +70,12 @@ bool Imlib2ImageCodec::Load(Image *image, char const *path)
#if !LOL_BUILD_RELEASE
msg::error("could not get image data for %s\n", path);
#endif
return false;
return nullptr;
}

ivec2 size(imlib_image_get_width(), imlib_image_get_height());
image->SetSize(size);
auto data = new ResourceImageData(new Image(size));
auto image = data->m_image;

u8vec4 *dstdata = image->Lock<PixelFormat::RGBA_8>();

@@ -88,11 +90,16 @@ bool Imlib2ImageCodec::Load(Image *image, char const *path)

imlib_free_image();

return true;
return data;
}

bool Imlib2ImageCodec::Save(Image *image, char const *path)
bool Imlib2ImageCodec::Save(char const *path, ResourceCodecData *data)
{
auto data_image = dynamic_cast<ResourceImageData*>(data);
if (data_image == nullptr)
return false;

auto image = data_image->m_image;
ivec2 size = image->GetSize();
Imlib_Image priv = imlib_create_image(size.x, size.y);



+ 1
- 1
src/image/codec/sdl-image.cpp View File

@@ -62,7 +62,7 @@ ResourceCodecData* SdlImageCodec::Load(char const *path)
#if !LOL_BUILD_RELEASE
msg::error("could not load image %s\n", path);
#endif
return false;
return nullptr;
}

ivec2 size(surface->w, surface->h);


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

@@ -95,7 +95,7 @@ ResourceCodecData* ResourceLoader::Load(char const *path)

//Log error, because we shouldn't be here
msg::error("Image::Load: Last codec %s, Error loading resource %s.\n", last_codec->GetName(), path);
return false;
return nullptr;
}

bool ResourceLoader::Save(char const *path, ResourceCodecData* data)


+ 20
- 20
src/lolua/baselua.h View File

@@ -232,17 +232,17 @@ protected:
template <typename TLuaClass> static int Store(lua_State * l);
template <typename TLuaClass> static int Del(lua_State * l);
//-------------------------------------------------------------------------
template <typename TLuaClass> static int ToString(lua_State* l) { ASSERT(false); return 0; }
template <typename TLuaClass> static int OpAdd(lua_State* l) { ASSERT(false); return 0; }
template <typename TLuaClass> static int OpSubstract(lua_State* l) { ASSERT(false); return 0; }
template <typename TLuaClass> static int OpMultiply(lua_State* l) { ASSERT(false); return 0; }
template <typename TLuaClass> static int OpDivide(lua_State* l) { ASSERT(false); return 0; }
template <typename TLuaClass> static int OpModulo(lua_State* l) { ASSERT(false); return 0; }
template <typename TLuaClass> static int OpUnaryNeg(lua_State* l) { ASSERT(false); return 0; }
template <typename TLuaClass> static int OpConcat(lua_State* l) { ASSERT(false); return 0; }
template <typename TLuaClass> static int CmpEqual(lua_State* l) { ASSERT(false); return 0; }
template <typename TLuaClass> static int CmpLessThan(lua_State* l) { ASSERT(false); return 0; }
template <typename TLuaClass> static int CmpLessEqual(lua_State* l) { ASSERT(false); return 0; }
template <typename TLuaClass> static int ToString(lua_State* l) { UNUSED(l); ASSERT(false); return 0; }
template <typename TLuaClass> static int OpAdd(lua_State* l) { UNUSED(l); ASSERT(false); return 0; }
template <typename TLuaClass> static int OpSubstract(lua_State* l) { UNUSED(l); ASSERT(false); return 0; }
template <typename TLuaClass> static int OpMultiply(lua_State* l) { UNUSED(l); ASSERT(false); return 0; }
template <typename TLuaClass> static int OpDivide(lua_State* l) { UNUSED(l); ASSERT(false); return 0; }
template <typename TLuaClass> static int OpModulo(lua_State* l) { UNUSED(l); ASSERT(false); return 0; }
template <typename TLuaClass> static int OpUnaryNeg(lua_State* l) { UNUSED(l); ASSERT(false); return 0; }
template <typename TLuaClass> static int OpConcat(lua_State* l) { UNUSED(l); ASSERT(false); return 0; }
template <typename TLuaClass> static int CmpEqual(lua_State* l) { UNUSED(l); ASSERT(false); return 0; }
template <typename TLuaClass> static int CmpLessThan(lua_State* l) { UNUSED(l); ASSERT(false); return 0; }
template <typename TLuaClass> static int CmpLessEqual(lua_State* l) { UNUSED(l); ASSERT(false); return 0; }
};

//-----------------------------------------------------------------------------
@@ -334,7 +334,7 @@ private:
}

public:
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
template<typename T> T Get() { return Get(InnerDefault<T>(), false); }
template<typename T> T Get(T default_value) { return Get(default_value, true); }
template<typename E> SafeEnum<E> GetEnum() { return GetEnum(InnerDefaultSafeEnum<E>(), false); }
@@ -373,7 +373,7 @@ protected:
//-------------------------------------------------------------------------
#define INNER_ERROR "Your type is not implemented. For pointers, use LuaPtr<MyType>()"
template<typename T> T InnerDefault() { return T(0); }
template<typename T> bool InnerIsValid() { ASSERT(false, INNER_ERROR); return false; }
template<typename T> bool InnerIsValid() { ASSERT(false, INNER_ERROR); return false; }
template<typename T> T InnerGet(T value) { UNUSED(value); ASSERT(false, INNER_ERROR); return InnerDefault<T>(); }
template<typename T> int InnerPush(T value) { UNUSED(value); ASSERT(false, INNER_ERROR); return 0; }

@@ -441,7 +441,7 @@ private:
#define LOLUA_DECLARE_BEGIN(LUA_FUNC_NAME, INSTANCE_GET) \
static int LUA_FUNC_NAME(lua_State* l) \
{ \
auto s = LuaStack::Begin(l); \
auto s = Lolua::Stack::Begin(l); \
auto o = s.INSTANCE_GET;

#define LOLUA_DECLARE_VARS(...) \
@@ -473,7 +473,7 @@ private:
#define LOLUA_DECLARE_RETURN_METHOD_ARGS(LUA_FUNC_NAME, INSTANCE_GET, INSTANCE_CALL, ...) \
static int LUA_FUNC_NAME(lua_State* l) \
{ \
auto s = LuaStack::Begin(l); \
auto s = Lolua::Stack::Begin(l); \
auto o = s.INSTANCE_GET; \
LOL_CALL(LOL_CAT(LOLUA_VAR_, LOL_CALL(LOL_COUNT_TO_12, (__VA_ARGS__))), (__VA_ARGS__)) \
s << o->INSTANCE_CALL(LOL_CALL(LOL_CAT(LOLUA_ARG_, LOL_CALL(LOL_COUNT_TO_12, (__VA_ARGS__))), (__VA_ARGS__))); \
@@ -537,7 +537,7 @@ template<> inline int Stack::InnerPush<uint64_t>(uint64_t value) { lua_pushi
template<> inline bool Stack::InnerIsValid<int32_t>() { return !!lua_isnumber(m_state, m_index); }
template<> inline int32_t Stack::InnerGet<int32_t>(int32_t value) { UNUSED(value); return (int32_t)lua_tointeger(m_state, m_index++); }
template<> inline int Stack::InnerPush<int32_t>(int32_t value) { lua_pushinteger(m_state, (lua_Integer)value); return 1; }
#endif STACK_INT32
#endif // STACK_INT32

//-----------------------------------------------------------------------------
#ifndef STACK_UINT32
@@ -565,7 +565,7 @@ template<> inline int Stack::InnerPush<vec3>(vec3 value) { return (InnerPush<flo
template<> inline bool Stack::InnerIsValid<vec4>() { return InnerIsValid<float>(); }
template<> inline vec4 Stack::InnerGet<vec4>(vec4 value) { return vec4(InnerGet<float>(value.x), Get<float>(value.y, true), Get<float>(value.z, true), Get<float>(value.w, true)); }
template<> inline int Stack::InnerPush<vec4>(vec4 value) { return (InnerPush<float>(value.x) + InnerPush<float>(value.y) + InnerPush<float>(value.z) + InnerPush<float>(value.w)); }
#endif STACK_VEC4
#endif // STACK_VEC4

#endif //REGION_STACK_VAR

@@ -586,7 +586,7 @@ public:
T1 GET_NAME(String const &name) \
{ \
lua_getglobal(m_lua_state, name.C()); \
auto stack = LuaStack::Begin(m_lua_state, -1); \
auto stack = Lolua::Stack::Begin(m_lua_state, -1); \
auto result = stack.GET_NAME<T0>(); \
lua_pop(m_lua_state, 1); \
return result; \
@@ -616,7 +616,7 @@ private:
template <typename TLuaClass>
int ObjectHelper::Store(lua_State * l)
{
auto stack = LuaStack::Begin(l);
auto stack = Lolua::Stack::Begin(l);
TLuaClass* obj = stack.GetPtr<TLuaClass>();
ASSERT(obj);
Loader::StoreObject(l, obj);
@@ -626,7 +626,7 @@ int ObjectHelper::Store(lua_State * l)
template <typename TLuaClass>
int ObjectHelper::Del(lua_State * l)
{
auto stack = LuaStack::Begin(l);
auto stack = Lolua::Stack::Begin(l);
TLuaClass* obj = stack.GetPtr<TLuaClass>();
ASSERT(obj);
delete obj;


Loading…
Cancel
Save