From cf80b8ff5ec8c4904603a25f34ac456f88800aa0 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Tue, 19 May 2020 14:05:14 +0200 Subject: [PATCH] Get rid of deprecated assert.h header. --- lol-core | 2 +- src/application/application.cpp | 7 ++++-- src/base/assert.cpp | 14 +++++------ src/easymesh/easymeshlua.cpp | 5 ++-- src/easymesh/easymeshrender.cpp | 31 ++++++++++++++++++------ src/engine/ticker.cpp | 25 ++++++++----------- src/gpu/debug.cpp | 2 +- src/gpu/framebuffer.cpp | 18 ++++++++------ src/gpu/shader.cpp | 37 ++++++++++++++-------------- src/image/codec/dummy-image.cpp | 1 - src/image/combine.cpp | 4 +-- src/image/image.cpp | 20 +++++++-------- src/image/movie.cpp | 7 +++--- src/image/pixel.cpp | 16 +++++++----- src/lol/lua.h | 43 +++++++++++++++++++++++++++++++++ src/lolua/baselua.cpp | 4 ++- src/lolua/baselua.h | 43 ++++++++++++++++----------------- src/mesh/mesh.cpp | 2 +- src/scene.cpp | 31 +++++++++++++----------- src/sys/file.cpp | 3 ++- src/ui/gui.cpp | 4 +-- tools/vimlol/vimlol.vim | 1 - 22 files changed, 196 insertions(+), 124 deletions(-) diff --git a/lol-core b/lol-core index 42d43c24..d22746eb 160000 --- a/lol-core +++ b/lol-core @@ -1 +1 @@ -Subproject commit 42d43c24a7eb3eab58483f9ead5bc6b5fbf57473 +Subproject commit d22746ebaf889679f9fd5f5aecb8882ff614ee73 diff --git a/src/application/application.cpp b/src/application/application.cpp index edba6ce3..8854804e 100644 --- a/src/application/application.cpp +++ b/src/application/application.cpp @@ -11,7 +11,9 @@ // #include -#include <../legacy/lol/base/assert.h> + +#include +#include #if HAVE_EMSCRIPTEN_H # include @@ -55,7 +57,8 @@ class null_app public: null_app(char const *, ivec2, float) { - ASSERT(false, "no display library (SDL, EGL…) available"); + msg::error("no display library (SDL, EGL…) available"); + assert(false); } virtual ~null_app() {} diff --git a/src/base/assert.cpp b/src/base/assert.cpp index efcbd21a..dc6fa6c9 100644 --- a/src/base/assert.cpp +++ b/src/base/assert.cpp @@ -11,7 +11,7 @@ // #include -#include <../legacy/lol/base/assert.h> +#include #if HAVE_CXXABI_H # include @@ -33,10 +33,10 @@ namespace debug void dump_stack() { #if __EMSCRIPTEN__ - /* This would require demangling but we don't care yet. */ + // This would require demangling but we don't care yet. msg::debug("%s\n", emscripten_run_script_string("(new Error).stack")); #elif HAVE_CXA_DEMANGLE && HAVE_BACKTRACE_SYMBOLS - /* Get current stack frames */ + // Get current stack frames void *stack_ptrs[50]; size_t size = backtrace(stack_ptrs, 50); char **callstack = backtrace_symbols(stack_ptrs, size); @@ -44,8 +44,8 @@ void dump_stack() if (size > 1) msg::debug("%d functions in stack trace:\n", (int)size - 1); - /* Parse stack frames, skipping the first element (because - * that’s ourselves) and print information. */ + // Parse stack frames, skipping the first element (because + // that’s ourselves) and print information. for (size_t i = 1; i < size; ++i) { char *name = 0, *offset = 0, *address = 0; @@ -87,7 +87,7 @@ void dump_stack() #endif } -} /* namespace debug */ +} // namespace debug -} /* namespace lol */ +} // namespace lol diff --git a/src/easymesh/easymeshlua.cpp b/src/easymesh/easymeshlua.cpp index 06b0de88..3a95bd64 100644 --- a/src/easymesh/easymeshlua.cpp +++ b/src/easymesh/easymeshlua.cpp @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -86,7 +87,7 @@ EasyMeshLuaObject::~EasyMeshLuaObject() } //----------------------------------------------------------------------------- -EasyMeshLuaObject* EasyMeshLuaObject::New(lua_State *, int) +EasyMeshLuaObject* EasyMeshLuaObject::New(lua_State *l, int) { LuaStack s = LuaStack::Begin(l); std::string str = s.Get(""); @@ -295,7 +296,7 @@ void EasyMesh::ExecuteCmdStack(bool ExecAllStack) DO_EXEC_CMD(AppendSimpleQuad, (AppendSimpleQuad, vec2, vec2, float, bool)) DO_EXEC_CMD(AppendCog, (AppendCog, int, float, float, float, float, float, float, float, float, bool)) default: - ASSERT(0, "Unknown command pseudo bytecode"); + assert(false); } } BD()->Disable(MeshBuildOperation::CommandExecution); diff --git a/src/easymesh/easymeshrender.cpp b/src/easymesh/easymeshrender.cpp index 171f87f8..2736a120 100644 --- a/src/easymesh/easymeshrender.cpp +++ b/src/easymesh/easymeshrender.cpp @@ -13,7 +13,9 @@ // #include -#include <../legacy/lol/base/assert.h> + +#include +#include namespace lol { @@ -260,7 +262,11 @@ void GpuEasyMeshData::AddGpuData(std::shared_ptr gpudata, std::sh BUILD_VFLAG(has_color, VertexUsage::Color, vflags); BUILD_VFLAG(has_texcoord, VertexUsage::TexCoord, vflags); BUILD_VFLAG_OR(has_texcoord, VertexUsage::TexCoordExt, vflags); - ASSERT(!vflags, "no Vertex Usage setup for 0x%04x", vflags); + if (vflags) + { + msg::error("no Vertex Usage setup for 0x%04x", vflags); + assert(!vflags); + } if (has_position) gpudata->AddAttribute(VertexUsage::Position, 0); if (has_normal) gpudata->AddAttribute(VertexUsage::Normal, 0); @@ -324,7 +330,11 @@ void GpuEasyMeshData::SetupVertexData(uint16_t vflags, std::shared_ptr BUILD_VFLAG_COUNT(has_color, VertexUsage::Color, saveflags, flagnb); BUILD_VFLAG_COUNT(has_texcoord, VertexUsage::TexCoord, saveflags, flagnb); BUILD_VFLAG_COUNT(has_texcoordExt,VertexUsage::TexCoordExt, saveflags, flagnb); - ASSERT(!saveflags, "no Vertex Declaration setup for 0x%04x", vflags); + if (saveflags) + { + msg::error("no Vertex Declaration setup for 0x%04x", vflags); + assert(!saveflags); + } if (flagnb == 5 && has_position && has_normal && has_color && has_texcoord && has_texcoordExt) { @@ -444,7 +454,10 @@ void GpuEasyMeshData::SetupVertexData(uint16_t vflags, std::shared_ptr COPY_VBO; } else - ASSERT(0, "no known Vertex Declaration combination for 0x%04x", vflags); + { + msg::error("no known Vertex Declaration combination for 0x%04x", vflags); + assert(false); + } m_vdata.push(vflags, new_vdecl, new_vbo); } @@ -452,8 +465,8 @@ void GpuEasyMeshData::SetupVertexData(uint16_t vflags, std::shared_ptr //----------------------------------------------------------------------------- void GpuEasyMeshData::RenderMeshData(mat4 const &model, int render_mode) { - ASSERT(0 <= render_mode && render_mode < m_gpudata.count(), "render mode is not in the defined range"); - ASSERT(m_gpudata[render_mode], "gpu datas for this render mode don't exist"); + assert(0 <= render_mode && render_mode < m_gpudata.count()); + assert(m_gpudata[render_mode]); GpuShaderData& gpu_sd = *(m_gpudata[render_mode]); int vdecl_idx = 0; @@ -478,7 +491,11 @@ void GpuEasyMeshData::RenderMeshData(mat4 const &model, int render_mode) BUILD_VFLAG(has_color, VertexUsage::Color, vflags); BUILD_VFLAG(has_texcoord, VertexUsage::TexCoord, vflags); BUILD_VFLAG_OR(has_texcoord,VertexUsage::TexCoordExt, vflags); - ASSERT(!vflags, "no Vertex Stream setup for 0x%04x", vflags); + if (vflags) + { + msg::error("no Vertex Stream setup for 0x%04x", vflags); + assert(!vflags); + } int idx = 0; ShaderAttrib Attribs[4] = { lol::ShaderAttrib(), lol::ShaderAttrib(), lol::ShaderAttrib(), lol::ShaderAttrib() }; diff --git a/src/engine/ticker.cpp b/src/engine/ticker.cpp index 058a5e61..6d6cf6ba 100644 --- a/src/engine/ticker.cpp +++ b/src/engine/ticker.cpp @@ -12,8 +12,8 @@ #include #include -#include <../legacy/lol/base/assert.h> +#include // assert #include // std::unordered_set #include #include @@ -46,10 +46,9 @@ public: ~ticker_data() { - ASSERT(DEPRECATED_nentities == 0, - "still %d entities in ticker\n", DEPRECATED_nentities); - ASSERT(DEPRECATED_m_autolist.size() == 0, - "still %d autoreleased entities\n", int(DEPRECATED_m_autolist.size())); + assert(DEPRECATED_nentities == 0); + assert(DEPRECATED_m_autolist.size() == 0); + msg::debug("%d frames required to quit\n", m_frame - m_quitframe); if (thread::has_threads()) @@ -58,7 +57,7 @@ public: disktick.push(0); gamethread.release(); diskthread.release(); - ASSERT(drawtick.size() == 0); + assert(drawtick.size() == 0); } } @@ -139,10 +138,8 @@ void Ticker::Register(entity *entity) void Ticker::Ref(entity *entity) { - ASSERT(entity, "dereferencing nullptr entity\n"); - ASSERT(!entity->has_flags(entity::flags::destroying), - "referencing entity scheduled for destruction %s\n", - entity->GetName().c_str()); + assert(entity); + assert(!entity->has_flags(entity::flags::destroying)); if (entity->has_flags(entity::flags::autorelease)) { @@ -165,11 +162,9 @@ void Ticker::Ref(entity *entity) int Ticker::Unref(entity *entity) { - ASSERT(entity, "dereferencing null entity\n"); - ASSERT(entity->m_ref > 0, - "dereferencing unreferenced entity %s\n", entity->GetName().c_str()); - ASSERT(!entity->has_flags(entity::flags::autorelease), - "dereferencing autoreleased entity %s\n", entity->GetName().c_str()); + assert(entity); + assert(entity->m_ref > 0); + assert(!entity->has_flags(entity::flags::autorelease)); return --entity->m_ref; } diff --git a/src/gpu/debug.cpp b/src/gpu/debug.cpp index f5da43c8..e5af1cdc 100644 --- a/src/gpu/debug.cpp +++ b/src/gpu/debug.cpp @@ -11,7 +11,7 @@ // #include -#include <../legacy/lol/base/assert.h> +#include #include "lolgl.h" diff --git a/src/gpu/framebuffer.cpp b/src/gpu/framebuffer.cpp index e99d2124..5b9c339c 100644 --- a/src/gpu/framebuffer.cpp +++ b/src/gpu/framebuffer.cpp @@ -11,7 +11,9 @@ // #include -#include <../legacy/lol/base/assert.h> + +#include +#include // FIXME: fine-tune this define #if defined LOL_USE_GLEW || defined HAVE_GL_2X || defined HAVE_GLES_2X @@ -117,7 +119,7 @@ uint32_t FramebufferFormat::GetFormat() #endif #endif default: - ASSERT(false, "unknown framebuffer format %d", m_format); + assert(false); return 0; } } @@ -159,7 +161,7 @@ uint32_t FramebufferFormat::GetFormatOrder() # endif #endif default: - ASSERT(false, "unknown framebuffer format order %d", m_format); + assert(false); return 0; } } @@ -243,8 +245,8 @@ Framebuffer::Framebuffer(ivec2 size, FramebufferFormat fbo_format) #if defined GL_VERSION_1_1 || defined GL_ES_VERSION_2_0 GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); - ASSERT(status == GL_FRAMEBUFFER_COMPLETE, - "invalid framebuffer status 0x%x", status); + if (status != GL_FRAMEBUFFER_COMPLETE) + msg::error("invalid framebuffer status 0x%x", status); #endif #if defined GL_VERSION_1_1 || defined GL_ES_VERSION_2_0 @@ -295,7 +297,8 @@ image Framebuffer::GetImage() const void Framebuffer::Bind() { - ASSERT(!m_data->m_bound, "trying to bind an already bound framebuffer"); + if (m_data->m_bound) + msg::error("trying to bind an already bound framebuffer"); #if defined GL_VERSION_1_1 || defined GL_ES_VERSION_2_0 glBindFramebuffer(GL_FRAMEBUFFER, m_data->m_fbo); @@ -314,7 +317,8 @@ void Framebuffer::Bind() void Framebuffer::Unbind() { - ASSERT(m_data->m_bound, "trying to unbind an unbound framebuffer"); + if (!m_data->m_bound) + msg::error("trying to unbind an unbound framebuffer"); #if defined GL_VERSION_1_1 || defined GL_ES_VERSION_2_0 glBindFramebuffer(GL_FRAMEBUFFER, 0); diff --git a/src/gpu/shader.cpp b/src/gpu/shader.cpp index 0d3feba4..1a5f8e1c 100644 --- a/src/gpu/shader.cpp +++ b/src/gpu/shader.cpp @@ -13,8 +13,8 @@ #include #include #include -#include <../legacy/lol/base/assert.h> +#include #include #include #include @@ -190,11 +190,11 @@ std::shared_ptr Shader::Create(std::string const &name, std::string cons { lolfx_parser p(code); - ASSERT(has_key(p.m_programs, "vert.glsl"), - "no vertex shader in %s", name.c_str()); + if (!has_key(p.m_programs, "vert.glsl")) + msg::error("no vertex shader in %s", name.c_str()); - ASSERT(has_key(p.m_programs, "frag.glsl"), - "no fragment shader in %s", name.c_str()); + if (!has_key(p.m_programs, "frag.glsl")) + msg::error("no fragment shader in %s", name.c_str()); std::string vert = p.m_programs["vert.glsl"]; std::string frag = p.m_programs["frag.glsl"]; @@ -806,7 +806,7 @@ ShaderVar ShaderVar::GetShaderOut(ShaderProgram program) switch (program.ToScalar()) { case ShaderProgram::Geometry: //TODO : L O L ------------------------------ - default: ASSERT(false); return ShaderVar(); + default: assert(false); return ShaderVar(); case ShaderProgram::Vertex: return ShaderVar(ShaderVariable::InOut, ShaderVariableType::Vec4, Shader::GetProgramOutVariableLocal(program)); case ShaderProgram::Pixel: return ShaderVar(ShaderVariable::InOut, ShaderVariableType::Vec4, Shader::GetProgramOutVariableLocal(program)); } @@ -818,7 +818,7 @@ void ShaderBlock::AddVar(ShaderVar const& var) ShaderVariable qualifier = var.GetQualifier(); std::string type = var.GetType(); std::string name = Shader::GetVariablePrefix(qualifier) + var.m_name; - ASSERT(!has_key(m_parameters[qualifier.ToScalar()], name)); + assert(!has_key(m_parameters[qualifier.ToScalar()], name)); m_parameters[qualifier.ToScalar()][name] = type; } @@ -850,8 +850,8 @@ void ShaderBlock::AddDefinitionParameters(const ShaderVariable type, const Shade //---- void ShaderBlock::Build(const ShaderProgram program, std::string& call, std::string& function) { - ASSERT(m_name.length()); - ASSERT(m_parameters[ShaderVariable::InOut].size()); + assert(m_name.length()); + assert(m_parameters[ShaderVariable::InOut].size()); //Build call in main std::string call_name = std::string("Call_") + m_name; @@ -875,8 +875,8 @@ void ShaderBlock::Build(const ShaderProgram program, std::string& call, std::str ShaderBuilder::ShaderBuilder(std::string const& name, std::string const& version) : m_name(name), m_version(version) { - ASSERT(name.length()); - ASSERT(version.length()); + assert(name.length()); + assert(version.length()); } //---- @@ -900,7 +900,7 @@ ShaderBuilder& ShaderBuilder::operator<<(const ShaderProgram program) //---- ShaderBuilder& ShaderBuilder::operator<<(ShaderBlock* new_block) { - ASSERT(m_current_program != ShaderProgram::MAX); + assert(m_current_program != ShaderProgram::MAX); for (auto const block : m_blocks[m_current_program.ToScalar()]) if (block == new_block) return *this; @@ -911,7 +911,7 @@ ShaderBuilder& ShaderBuilder::operator<<(ShaderBlock* new_block) //---- ShaderBuilder& ShaderBuilder::operator<<(ShaderBlock const& block) { - ASSERT(m_current_program != ShaderProgram::MAX); + assert(m_current_program != ShaderProgram::MAX); m_blocks[m_current_program.ToScalar()].push_back(new ShaderBlock(block)); return *this; } @@ -953,12 +953,13 @@ void ShaderBuilder::MergeParameters(std::map& variable { bool has_param = has_key(merged, key.first); - //Key exists, check the type to make sure it's the same - ASSERT(!has_param || (has_param && merged[key.first] == variables[key.first]), - "has_param=%d, key=%s merged[key]=%s, variables[key]=%s\n", - (int)has_param, key.first.c_str(), merged[key.first].c_str(), key.second.c_str()); + // Key exists, check the type to make sure it's the same + if (has_param && merged[key.first] != variables[key.first]) + msg::error("has_param=%d, key=%s merged[key]=%s, variables[key]=%s\n", + (int)has_param, key.first.c_str(), merged[key.first].c_str(), + key.second.c_str()); - //does not exist, had it + // does not exist, had it if (!has_param) merged[key.first] = key.second; } diff --git a/src/image/codec/dummy-image.cpp b/src/image/codec/dummy-image.cpp index 6550f29d..ed43fadd 100644 --- a/src/image/codec/dummy-image.cpp +++ b/src/image/codec/dummy-image.cpp @@ -11,7 +11,6 @@ // #include -#include <../legacy/lol/base/assert.h> #include diff --git a/src/image/combine.cpp b/src/image/combine.cpp index f7271f11..026e1dd8 100644 --- a/src/image/combine.cpp +++ b/src/image/combine.cpp @@ -11,7 +11,7 @@ // #include -#include <../legacy/lol/base/assert.h> +#include /* * Image merge operations: merge, min/max, overlay, screen, multiply, @@ -42,7 +42,7 @@ static image generic_merge(image &src1, image &src2, float alpha) typedef typename PixelType::type pixel_t; - ASSERT(src1.size() == src2.size()); + assert(src1.size() == src2.size()); int const count = src1.size().x * src2.size().y; image dst(src1.size()); diff --git a/src/image/image.cpp b/src/image/image.cpp index e24fe22c..8a2f7d82 100644 --- a/src/image/image.cpp +++ b/src/image/image.cpp @@ -11,11 +11,11 @@ // #include -#include <../legacy/lol/base/assert.h> #include "image-private.h" -#include /* for std::swap */ +#include // assert +#include // std::swap namespace lol { @@ -65,7 +65,7 @@ image::~image() void image::Copy(uint8_t* src_pixels, ivec2 const& size, PixelFormat fmt) { - ASSERT(fmt != PixelFormat::Unknown); + assert(fmt != PixelFormat::Unknown); resize(size); set_format(fmt); memcpy(m_data->m_pixels[(int)fmt]->data(), src_pixels, @@ -125,8 +125,8 @@ ivec2 image::size() const void image::resize(ivec2 size) { - ASSERT(size.x > 0); - ASSERT(size.y > 0); + assert(size.x > 0); + assert(size.y > 0); if (m_data->m_size != size) { @@ -175,8 +175,8 @@ void *image::lock2d_helper(PixelFormat T) template void image::unlock2d(array2d const &array) { - ASSERT(has_key(m_data->m_pixels, (int)m_data->m_format)); - ASSERT(array.data() == m_data->m_pixels[(int)m_data->m_format]->data()); + assert(has_key(m_data->m_pixels, (int)m_data->m_format)); + assert(array.data() == m_data->m_pixels[(int)m_data->m_format]->data()); } /* Explicit specialisations for the above templates */ @@ -195,15 +195,15 @@ _T(PixelFormat::RGBA_F32) /* Special case for the "any" format: return the last active buffer */ void *image::lock() { - ASSERT(m_data->m_format != PixelFormat::Unknown); + assert(m_data->m_format != PixelFormat::Unknown); return m_data->m_pixels[(int)m_data->m_format]->data(); } void image::unlock(void const *pixels) { - ASSERT(has_key(m_data->m_pixels, (int)m_data->m_format)); - ASSERT(pixels == m_data->m_pixels[(int)m_data->m_format]->data()); + assert(has_key(m_data->m_pixels, (int)m_data->m_format)); + assert(pixels == m_data->m_pixels[(int)m_data->m_format]->data()); } } /* namespace lol */ diff --git a/src/image/movie.cpp b/src/image/movie.cpp index 111c57e7..ecd85059 100644 --- a/src/image/movie.cpp +++ b/src/image/movie.cpp @@ -11,9 +11,10 @@ // #include -#include <../legacy/lol/base/assert.h> #include +#include + #if LOL_USE_FFMPEG extern "C" { @@ -57,14 +58,14 @@ movie::movie(ivec2 size) { #if LOL_USE_FFMPEG m_frame = av_frame_alloc(); - ASSERT(m_frame); + assert(m_frame); m_frame->format = AV_PIX_FMT_RGB8; // 3:3:2 packed for GIF m_frame->width = m_size.x; m_frame->height = m_size.y; int ret = av_frame_get_buffer(m_frame, 32); - ASSERT(ret >= 0); + assert(ret >= 0); #endif } diff --git a/src/image/pixel.cpp b/src/image/pixel.cpp index 3cd31e10..57cefa25 100644 --- a/src/image/pixel.cpp +++ b/src/image/pixel.cpp @@ -11,7 +11,9 @@ // #include -#include <../legacy/lol/base/assert.h> + +#include +#include #include "image-private.h" @@ -129,8 +131,6 @@ void image::set_format(PixelFormat fmt) #endif switch (fmt) { - case PixelFormat::Unknown: - break; case PixelFormat::Y_8: data = new PixelData(isize); break; case PixelFormat::RGB_8: @@ -143,11 +143,15 @@ void image::set_format(PixelFormat fmt) data = new PixelData(isize); break; case PixelFormat::RGBA_F32: data = new PixelData(isize); break; + case PixelFormat::Unknown: + default: + msg::error("invalid pixel type %d", (int)fmt); + assert(false); + break; } #if __GNUC__ #pragma GCC diagnostic pop #endif - ASSERT(data, "invalid pixel type %d", (int)fmt); m_data->m_pixels[(int)fmt] = data; } @@ -346,8 +350,8 @@ void image::set_format(PixelFormat fmt) } else { - ASSERT(false, "Unable to find image conversion from %d to %d", - (int)old_fmt, (int)fmt); + msg::error("Unable to find image conversion from %d to %d", + (int)old_fmt, (int)fmt); } } diff --git a/src/lol/lua.h b/src/lol/lua.h index da06649e..8d688c17 100644 --- a/src/lol/lua.h +++ b/src/lol/lua.h @@ -17,6 +17,49 @@ // ------------- // +#define LOL_CALL(macro, args) macro args +#define LOL_EVAL(a) a +#define LOL_1ST(a, ...) a + +#define LOL_GET_63RD(a01, a02, a03, a04, a05, a06, a07, a08, a09, a10, \ + a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, \ + a21, a22, a23, a24, a25, a26, a27, a28, a29, a30, \ + a31, a32, a33, a34, a35, a36, a37, a38, a39, a40, \ + a41, a42, a43, a44, a45, a46, a47, a48, a49, a50, \ + a51, a52, a53, a54, a55, a56, a57, a58, a59, a60, \ + a61, a62, a63, ...) a63 +#define LOL_COUNT_TO_3(...) \ + LOL_EVAL(LOL_GET_63RD(__VA_ARGS__, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, \ + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, \ + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, \ + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, \ + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, \ + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, \ + 2, 1, TOO_FEW_ARGUMENTS)) +#define LOL_COUNT_TO_8(...) \ + LOL_EVAL(LOL_GET_63RD(__VA_ARGS__, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, \ + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, \ + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, \ + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, \ + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, \ + 8, 8, 8, 8, 8, 7, 6, 5, 4, 3, \ + 2, 1, TOO_FEW_ARGUMENTS)) + +#define LOL_COUNT_TO_12(...) \ + LOL_EVAL(LOL_GET_63RD(__VA_ARGS__, 12,12,12,12,12,12,12,12,12,12,\ + 12,12,12,12,12,12,12,12,12,12,\ + 12,12,12,12,12,12,12,12,12,12,\ + 12,12,12,12,12,12,12,12,12,12,\ + 12,12,12,12,12,12,12,12,12,12,\ + 12,11,10,9, 8, 7, 6, 5, 4, 3, \ + 2, 1, TOO_FEW_ARGUMENTS)) + +// Three levels of dispatch are needed because of Visual Studio's bizarre +// handling of __VA_ARGS__ inside macro calls +#define LOL_CAT3(a, b) a##b +#define LOL_CAT2(a, b) LOL_CAT3(a,b) +#define LOL_CAT(a, b) LOL_CAT2(a,b) + // Lua #include #include diff --git a/src/lolua/baselua.cpp b/src/lolua/baselua.cpp index 1544f1e9..58b1ea6e 100644 --- a/src/lolua/baselua.cpp +++ b/src/lolua/baselua.cpp @@ -14,6 +14,8 @@ #include #include +#include +#include #include #include #include @@ -35,7 +37,7 @@ class LuaBaseData { char const *message = lua_tostring(l, -1); msg::error("%s\n", message); - debug::abort(); + assert(false); return 0; } diff --git a/src/lolua/baselua.h b/src/lolua/baselua.h index ef917dc3..cfc8b7b9 100644 --- a/src/lolua/baselua.h +++ b/src/lolua/baselua.h @@ -19,8 +19,7 @@ extern "C" { #include "3rdparty/lua/lauxlib.h" } -#include <../legacy/lol/base/assert.h> - +#include // assert #include // std::vector #include // std::string #include // tolower @@ -115,10 +114,10 @@ public: virtual ~Object() { } static Object* New(lua_State*, int) { - ASSERT(false); + assert(false); return nullptr; } - static const Library* GetLib() { ASSERT(false); return nullptr; } + static const Library* GetLib() { assert(false); return nullptr; } }; //----------------------------------------------------------------------------- @@ -200,7 +199,7 @@ private: static const Object::Library* GetLibrary() { const Object::Library* lib = TLuaClass::GetLib(); - ASSERT(lib); + assert(lib); return lib; } @@ -243,17 +242,17 @@ protected: template static int Store(lua_State * l); template static int Del(lua_State * l); //------------------------------------------------------------------------- - template static int ToString(lua_State*) { ASSERT(false); return 0; } - template static int OpAdd(lua_State*) { ASSERT(false); return 0; } - template static int OpSubstract(lua_State*) { ASSERT(false); return 0; } - template static int OpMultiply(lua_State*) { ASSERT(false); return 0; } - template static int OpDivide(lua_State*) { ASSERT(false); return 0; } - template static int OpModulo(lua_State*) { ASSERT(false); return 0; } - template static int OpUnaryNeg(lua_State*) { ASSERT(false); return 0; } - template static int OpConcat(lua_State*) { ASSERT(false); return 0; } - template static int CmpEqual(lua_State*) { ASSERT(false); return 0; } - template static int CmpLessThan(lua_State*) { ASSERT(false); return 0; } - template static int CmpLessEqual(lua_State*) { ASSERT(false); return 0; } + template static int ToString(lua_State*) { assert(false); return 0; } + template static int OpAdd(lua_State*) { assert(false); return 0; } + template static int OpSubstract(lua_State*) { assert(false); return 0; } + template static int OpMultiply(lua_State*) { assert(false); return 0; } + template static int OpDivide(lua_State*) { assert(false); return 0; } + template static int OpModulo(lua_State*) { assert(false); return 0; } + template static int OpUnaryNeg(lua_State*) { assert(false); return 0; } + template static int OpConcat(lua_State*) { assert(false); return 0; } + template static int CmpEqual(lua_State*) { assert(false); return 0; } + template static int CmpLessThan(lua_State*) { assert(false); return 0; } + template static int CmpLessEqual(lua_State*) { assert(false); return 0; } }; //----------------------------------------------------------------------------- @@ -338,7 +337,7 @@ private: bool is_nil = lua_isnil(m_state, m_index); if (!is_optional || (!is_nil && value_validity)) { - ASSERT(!is_nil); /* touky: should it assert, though ? */ + assert(!is_nil); /* touky: should it assert, though ? */ return true; } return false; @@ -384,9 +383,9 @@ protected: //------------------------------------------------------------------------- #define INNER_ERROR "Your type is not implemented. For pointers, use LuaPtr()" template T InnerDefault() { return T(0); } - template bool InnerIsValid() { ASSERT(false, INNER_ERROR); return false; } - template T InnerGet(T) { ASSERT(false, INNER_ERROR); return InnerDefault(); } - template int InnerPush(T) { ASSERT(false, INNER_ERROR); return 0; } + template bool InnerIsValid() { msg::error("%s\n", INNER_ERROR); assert(false); return false; } + template T InnerGet(T) { msg::error("%s\n", INNER_ERROR); assert(false); return InnerDefault(); } + template int InnerPush(T) { msg::error("%s\n", INNER_ERROR); assert(false); return 0; } #ifndef INNER_SAFE_ENUM // Gets the value for the given enum type. @@ -639,7 +638,7 @@ int ObjectHelper::Store(lua_State * l) { auto stack = Lolua::Stack::Begin(l); TLuaClass* obj = stack.GetPtr(); - ASSERT(obj); + assert(obj); Loader::StoreObject(l, obj); return 0; } @@ -649,7 +648,7 @@ int ObjectHelper::Del(lua_State * l) { auto stack = Lolua::Stack::Begin(l); TLuaClass* obj = stack.GetPtr(); - ASSERT(obj); + assert(obj); delete obj; return 0; } diff --git a/src/mesh/mesh.cpp b/src/mesh/mesh.cpp index 0906b47a..9ac06a49 100644 --- a/src/mesh/mesh.cpp +++ b/src/mesh/mesh.cpp @@ -11,8 +11,8 @@ // #include -#include <../legacy/lol/base/assert.h> +#include // lol::msg #include // std::shared_ptr #include // std::make_tuple #include diff --git a/src/scene.cpp b/src/scene.cpp index 824bdd49..2ae88812 100644 --- a/src/scene.cpp +++ b/src/scene.cpp @@ -12,11 +12,12 @@ // #include -#include <../legacy/lol/base/assert.h> -#include -#include -#include +#include // lol::msg +#include // assert +#include // std::map +#include // std::vector +#include // std::array #include #if defined(_WIN32) @@ -120,7 +121,9 @@ Scene::Scene(ivec2 size) m_renderer(std::make_shared(size)) { /* TODO: FIX THAT */ - ASSERT(!(g_used_id & ((uint64_t)1 << 63)), "Too many scenes !!!!"); + if (g_used_id & ((uint64_t)1 << 63)) + msg::error("too many scenes!\n"); + m_mask_id = g_used_id; g_used_id = g_used_id << 1; @@ -249,7 +252,7 @@ void Scene::PopCamera(Camera *cam) } } - ASSERT(false, "trying to pop a nonexistent camera from the scene"); + msg::error("trying to pop a nonexistent camera from the scene\n"); } void Scene::SetTileCam(int cam_idx) @@ -300,8 +303,8 @@ int Scene::AddPrimitiveSource(uintptr_t key, std::shared_ptr so void Scene::SetPrimitiveSource(int index, uintptr_t key, std::shared_ptr source) { - ASSERT(source); - ASSERT(index >= 0); + assert(source); + assert(index >= 0); // Keep reference to old source until AFTER we release the lock std::shared_ptr old; @@ -322,7 +325,7 @@ void Scene::ReleasePrimitiveSource(int index, uintptr_t key) std::shared_ptr old; g_prim_mutex.lock(); { - ASSERT(0 <= index && index < int(g_prim_sources[key].size())); + assert(0 <= index && index < int(g_prim_sources[key].size())); old = g_prim_sources[key][index]; remove_at(g_prim_sources[key], index); } @@ -361,8 +364,8 @@ void Scene::AddPrimitiveRenderer(uintptr_t key, std::shared_ptr renderer) { - ASSERT(renderer); - ASSERT(index >= 0); + assert(renderer); + assert(index >= 0); if (index >= int(m_prim_renderers[key].size())) m_prim_renderers[key].resize(index + 1); @@ -381,7 +384,7 @@ void Scene::ReleaseAllPrimitiveRenderers(uintptr_t key) void Scene::AddTile(TileSet *tileset, int id, vec3 pos, vec2 scale, float radians) { - ASSERT(id < tileset->GetTileCount()); + assert(id < tileset->GetTileCount()); ivec2 size = tileset->GetTileSize(id); mat4 model = mat4::translate(pos) @@ -395,7 +398,7 @@ void Scene::AddTile(TileSet *tileset, int id, vec3 pos, vec2 scale, float radian void Scene::AddTile(TileSet *tileset, int id, mat4 model) { - ASSERT(id < tileset->GetTileCount()); + assert(id < tileset->GetTileCount()); Tile t; t.m_model = model; @@ -445,7 +448,7 @@ void Scene::EnableDisplay() void Scene::DisableDisplay() { - ASSERT(m_display); + assert(m_display); m_display->Disable(); } diff --git a/src/sys/file.cpp b/src/sys/file.cpp index 43d1efcc..2923a929 100644 --- a/src/sys/file.cpp +++ b/src/sys/file.cpp @@ -13,6 +13,7 @@ #include #if __ANDROID__ +# include # include # include #endif @@ -69,7 +70,7 @@ class FileData { m_type = (force_binary) ? (StreamType::FileBinary) : (StreamType::File); #if __ANDROID__ - ASSERT(g_assets); + assert(g_assets); m_asset = AAssetManager_open(g_assets, file.c_str(), AASSET_MODE_UNKNOWN); #elif HAVE_STDIO_H /* FIXME: no modes, no error checking, no nothing */ diff --git a/src/ui/gui.cpp b/src/ui/gui.cpp index 98b6d2ad..91e4cc39 100644 --- a/src/ui/gui.cpp +++ b/src/ui/gui.cpp @@ -12,8 +12,8 @@ // #include -#include <../legacy/lol/base/assert.h> +#include #include #include @@ -260,7 +260,7 @@ bool gui::init_draw() { // Create shader m_shader = Shader::Create(m_builder.GetName(), m_builder.Build()); - ASSERT(m_shader); + assert(m_shader); m_ortho.m_uniform = m_shader->GetUniformLocation(m_ortho.m_var.tostring()); m_texture.m_uniform = m_shader->GetUniformLocation(m_texture.m_var.tostring()); diff --git a/tools/vimlol/vimlol.vim b/tools/vimlol/vimlol.vim index 74e87a94..9c0f237a 100644 --- a/tools/vimlol/vimlol.vim +++ b/tools/vimlol/vimlol.vim @@ -54,7 +54,6 @@ au Syntax cpp " Global keywords au Syntax cpp \ syn keyword cConstant - \ UNUSED ASSERT """