Browse Source

RIP lol::String ⚰️ LOL

legacy
Sam Hocevar 7 years ago
parent
commit
37abf6193f
53 changed files with 382 additions and 570 deletions
  1. +1
    -1
      doc/samples/btphystest.h
  2. +1
    -1
      doc/samples/meshviewer/scenesetup.h
  3. +10
    -4
      doc/samples/nacl_phystest.h
  4. +14
    -10
      doc/samples/physicobject.h
  5. +10
    -9
      doc/samples/physics/easycharactercontroller.cpp
  6. +7
    -5
      doc/samples/physics/easycharactercontroller.h
  7. +5
    -5
      doc/samples/physics/lolphysics.h
  8. +6
    -5
      doc/tutorial/14_lol_lua.cpp
  9. +2
    -2
      src/audio/sample.cpp
  10. +9
    -7
      src/camera.h
  11. +10
    -8
      src/debug/record.cpp
  12. +9
    -7
      src/debug/record.h
  13. +5
    -5
      src/dict.cpp
  14. +9
    -7
      src/dict.h
  15. +2
    -2
      src/easymesh/easymesh.h
  16. +7
    -7
      src/easymesh/easymeshbuild.h
  17. +14
    -13
      src/easymesh/easymeshrender.cpp
  18. +11
    -10
      src/easymesh/easymeshrender.h
  19. +2
    -2
      src/engine/entity.cpp
  20. +2
    -2
      src/engine/entity.h
  21. +10
    -10
      src/engine/ticker.cpp
  22. +9
    -7
      src/engine/worldentity.cpp
  23. +9
    -7
      src/engine/worldentity.h
  24. +17
    -15
      src/font.cpp
  25. +11
    -9
      src/font.h
  26. +9
    -7
      src/forge.cpp
  27. +9
    -7
      src/forge.h
  28. +9
    -7
      src/gradient.h
  29. +14
    -12
      src/image/color/color.cpp
  30. +1
    -1
      src/light.h
  31. +2
    -2
      src/lol/audio/sample.h
  32. +0
    -229
      src/lol/base/string.h
  33. +1
    -1
      src/lol/gpu/vertexbuffer.h
  34. +2
    -2
      src/lol/image/color.h
  35. +4
    -4
      src/lol/math/geometry.h
  36. +1
    -1
      src/lol/sys/threadtypes.h
  37. +1
    -1
      src/lolimgui.h
  38. +4
    -4
      src/mesh/mesh.cpp
  39. +3
    -3
      src/mesh/mesh.h
  40. +1
    -1
      src/messageservice.h
  41. +4
    -4
      src/sys/getopt.cpp
  42. +11
    -5
      src/sys/threadtypes.cpp
  43. +2
    -2
      src/t/base/array.cpp
  44. +17
    -14
      src/t/sys/thread.cpp
  45. +6
    -6
      src/text.cpp
  46. +12
    -8
      src/text.h
  47. +9
    -7
      src/textureimage-private.h
  48. +9
    -9
      src/textureimage.cpp
  49. +14
    -12
      src/textureimage.h
  50. +12
    -26
      src/tiler.cpp
  51. +12
    -14
      src/tiler.h
  52. +12
    -12
      src/tileset.cpp
  53. +9
    -9
      src/tileset.h

+ 1
- 1
doc/samples/btphystest.h View File

@@ -43,7 +43,7 @@ public:
BtPhysTest(bool editor = false); BtPhysTest(bool editor = false);
virtual ~BtPhysTest(); virtual ~BtPhysTest();


char const *GetName() { return "<BtPhysTest>"; }
std::string GetName() const { return "<BtPhysTest>"; }


protected: protected:
virtual void TickGame(float seconds); virtual void TickGame(float seconds);


+ 1
- 1
doc/samples/meshviewer/scenesetup.h View File

@@ -36,7 +36,7 @@ public:
SceneSetup(std::string const& name); SceneSetup(std::string const& name);
~SceneSetup(); ~SceneSetup();


static char const *GetName() { return "<scenesetup>"; }
static std::string GetName() { return "<scenesetup>"; }


//-- //--
bool Startup(); bool Startup();


+ 10
- 4
doc/samples/nacl_phystest.h View File

@@ -1,8 +1,14 @@
// //
// BtPhysTest
// Lol Engine — Bullet physics test
// //
// Copyright: (c) 2009-2013 Benjamin "Touky" Huet <huet.benjamin@gmail.com>
// (c) 2012 Sam Hocevar <sam@hocevar.net>
// Copyright © 2009—2013 Benjamin “Touky” Huet <huet.benjamin@gmail.com>
// © 2012—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
@@ -13,7 +19,7 @@ public:
Nacl_PhysTest(bool editor = false); Nacl_PhysTest(bool editor = false);
virtual ~Nacl_PhysTest(); virtual ~Nacl_PhysTest();


char const *GetName() { return "<Nacl_PhysTest>"; }
std::string GetName() const { return "<Nacl_PhysTest>"; }


protected: protected:
virtual void TickGame(float seconds); virtual void TickGame(float seconds);


+ 14
- 10
doc/samples/physicobject.h View File

@@ -1,11 +1,15 @@
// //
// Orbital
// Lol Engine — Bullet physics test
// //
// Copyright © 2009—2013 Cédric Lecacheur <jordx@free.fr> // Copyright © 2009—2013 Cédric Lecacheur <jordx@free.fr>
// © 2009—2013 Benjamin “Touky” Huet <huet.benjamin@gmail.com> // © 2009—2013 Benjamin “Touky” Huet <huet.benjamin@gmail.com>
// © 2012—2015 Sam Hocevar <sam@hocevar.net>
// © 2012—2018 Sam Hocevar <sam@hocevar.net>
// //
// No licensing terms yet. All rights reserved.
// 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
@@ -141,13 +145,13 @@ public:


if (!MeshRand.count()) if (!MeshRand.count())
{ {
array<String> colors_base = { "#add", "#dad", "#dda", "#daa", "#ada", "#aad" };
array<std::string> colors_base = { "#add", "#dad", "#dda", "#daa", "#ada", "#aad" };


MeshLimit << 0; MeshLimit << 0;


#if USE_BOX #if USE_BOX
{ {
array<String> colors = colors_base;
array<std::string> colors = colors_base;
while (colors.count()) while (colors.count())
{ {
EasyMesh m; EasyMesh m;
@@ -196,7 +200,7 @@ public:
MeshRand << "[tpbn tvnc sc#aaff aq 0 0]"; MeshRand << "[tpbn tvnc sc#aaff aq 0 0]";
#else #else
{ {
array<String> colors = colors_base;
array<std::string> colors = colors_base;
while (colors.count()) while (colors.count())
{ {
EasyMesh m; EasyMesh m;
@@ -220,7 +224,7 @@ public:


#if USE_CONE #if USE_CONE
{ {
array<String> colors = colors_base;
array<std::string> colors = colors_base;
while (colors.count()) while (colors.count())
{ {
EasyMesh m; EasyMesh m;
@@ -247,7 +251,7 @@ public:


#if USE_CYLINDER #if USE_CYLINDER
{ {
array<String> colors = colors_base;
array<std::string> colors = colors_base;
while (colors.count()) while (colors.count())
{ {
EasyMesh m; EasyMesh m;
@@ -275,7 +279,7 @@ public:


#if USE_CAPSULE #if USE_CAPSULE
{ {
array<String> colors = colors_base;
array<std::string> colors = colors_base;
while (colors.count()) while (colors.count())
{ {
EasyMesh m; EasyMesh m;
@@ -395,7 +399,7 @@ public:
{ {
} }


char const *GetName() { return "<PhysicsObject>"; }
std::string GetName() const { return "<PhysicsObject>"; }


protected: protected:
virtual void TickGame(float seconds) virtual void TickGame(float seconds)


+ 10
- 9
doc/samples/physics/easycharactercontroller.cpp View File

@@ -1,13 +1,14 @@
// //
// Lol Engine
// Lol Engine — Bullet physics test
// //
// Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net>
// (c) 2009-2013 Cédric Lecacheur <jordx@free.fr>
// (c) 2009-2013 Benjamin "Touky" Huet <huet.benjamin@gmail.com>
// 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 © 2009—2013 Benjamin “Touky” Huet <huet.benjamin@gmail.com>
// © 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.
// //


#if HAVE_CONFIG_H #if HAVE_CONFIG_H
@@ -125,7 +126,7 @@ void EasyCharacterController::BaseTransformChanged(const lol::mat4& PreviousMatr
} }


//--- //---
char const *EasyCharacterController::GetName()
std::string EasyCharacterController::GetName()
{ {
return "<EasyCharacterController>"; return "<EasyCharacterController>";
} }


+ 7
- 5
doc/samples/physics/easycharactercontroller.h View File

@@ -1,10 +1,10 @@
// //
// Lol Engine
// Lol Engine — Bullet physics test
// //
// Copyright © 2009—2015 Benjamin “Touky” Huet <huet.benjamin@gmail.com>
// © 2010—2015 Sam Hocevar <sam@hocevar.net>
// Copyright © 2009—2013 Benjamin “Touky” Huet <huet.benjamin@gmail.com>
// © 2012—2018 Sam Hocevar <sam@hocevar.net>
// //
// This library 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
// and/or modify it under the terms of the Do What the Fuck You Want // 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. // to Public License, Version 2, as published by the WTFPL Task Force.
@@ -69,9 +69,11 @@ public:
virtual void Jump(); virtual void Jump();


virtual void SetTransform(const lol::vec3& base_location, const lol::quat& base_rotation); virtual void SetTransform(const lol::vec3& base_location, const lol::quat& base_rotation);

protected: protected:
virtual void BaseTransformChanged(const lol::mat4& PreviousMatrix, const lol::mat4& NewMatrix); virtual void BaseTransformChanged(const lol::mat4& PreviousMatrix, const lol::mat4& NewMatrix);
virtual char const *GetName();
virtual std::string GetName();

public: public:
virtual void TickGame(float seconds); virtual void TickGame(float seconds);




+ 5
- 5
doc/samples/physics/lolphysics.h View File

@@ -1,10 +1,10 @@
// //
// Lol Engine
// Lol Engine — Bullet physics test
// //
// Copyright © 2012—2015 Sam Hocevar <sam@hocevar.net>
// © 2009—2013 Benjamin “Touky” Huet <huet.benjamin@gmail.com>
// Copyright © 2009—2013 Benjamin “Touky” Huet <huet.benjamin@gmail.com>
// © 2012—2018 Sam Hocevar <sam@hocevar.net>
// //
// This library 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
// and/or modify it under the terms of the Do What the Fuck You Want // 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. // to Public License, Version 2, as published by the WTFPL Task Force.
@@ -83,7 +83,7 @@ public:
Exit(); Exit();
} }


char const *GetName() { return "<Simulation>"; }
std::string GetName() const { return "<Simulation>"; }


public: public:
void Init() void Init()


+ 6
- 5
doc/tutorial/14_lol_lua.cpp View File

@@ -2,6 +2,7 @@
// Lol Engine — Lua tutorial // Lol Engine — Lua tutorial
// //
// Copyright © 2014—2017 Benjamin “Touky” Huet <huet.benjamin@gmail.com> // Copyright © 2014—2017 Benjamin “Touky” Huet <huet.benjamin@gmail.com>
// © 2017—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
@@ -113,7 +114,7 @@ public:
static int GlobalAddString(lua_State* l) static int GlobalAddString(lua_State* l)
{ {
auto stack = LuaStack::Begin(l); auto stack = LuaStack::Begin(l);
auto s = stack.Get<String>();
auto s = stack.Get<std::string>();


s += "_added"; s += "_added";


@@ -185,10 +186,10 @@ public:
float testvalue_num = demo_loader->Get<float>("testvalue_num"); float testvalue_num = demo_loader->Get<float>("testvalue_num");
int32_t testvalue_int = demo_loader->Get<int32_t>("testvalue_int"); int32_t testvalue_int = demo_loader->Get<int32_t>("testvalue_int");
uint32_t testvalue_uint = demo_loader->Get<uint32_t>("testvalue_uint"); uint32_t testvalue_uint = demo_loader->Get<uint32_t>("testvalue_uint");
String testvalue_str = demo_loader->Get<String>("testvalue_str");
std::string testvalue_str = demo_loader->Get<std::string>("testvalue_str");


//Grab string modified with function //Grab string modified with function
String function_return = demo_loader->Get<String>("function_return");
std::string function_return = demo_loader->Get<std::string>("function_return");


//Grab global values modified with DemoObject //Grab global values modified with DemoObject
int32_t loluademo_return = demo_loader->Get<int32_t>("loluademo_return"); int32_t loluademo_return = demo_loader->Get<int32_t>("loluademo_return");
@@ -198,10 +199,10 @@ public:


msg::info("Lua Vars: \ msg::info("Lua Vars: \
testvalue_num: %.2f, testvalue_int: %i, testvalue_uint: %i, testvalue_str: %s.\n", testvalue_num: %.2f, testvalue_int: %i, testvalue_uint: %i, testvalue_str: %s.\n",
testvalue_num, testvalue_int, testvalue_uint, testvalue_str.C());
testvalue_num, testvalue_int, testvalue_uint, testvalue_str.c_str());
msg::info("Lua Vars: \ msg::info("Lua Vars: \
function_return: %s, loluademo_return: %i, loluademo_inst_return: %.2f, loluademo_getx: %i, loluademo_inst->m_x: %i.\n", function_return: %s, loluademo_return: %i, loluademo_inst_return: %.2f, loluademo_getx: %i, loluademo_inst->m_x: %i.\n",
function_return.C(), loluademo_return, loluademo_inst_return, loluademo_getx, loluademo_inst->m_x);
function_return.c_str(), loluademo_return, loluademo_inst_return, loluademo_getx, loluademo_inst->m_x);


#define /***/ _LOLUA_ARG_1(a00) (float)a00 #define /***/ _LOLUA_ARG_1(a00) (float)a00
#define /***/ _LOLUA_ARG_2(a00, a01) _LOLUA_ARG_1(a00), _LOLUA_ARG_1(a01) #define /***/ _LOLUA_ARG_2(a00, a01) _LOLUA_ARG_1(a00), _LOLUA_ARG_1(a01)


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

@@ -86,9 +86,9 @@ void sample::TickGame(float seconds)
Entity::TickGame(seconds); Entity::TickGame(seconds);
} }


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


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


+ 9
- 7
src/camera.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 #pragma once
@@ -28,7 +30,7 @@ public:
Camera(); Camera();
~Camera(); ~Camera();


char const *GetName() { return "<camera>"; }
std::string GetName() const { return "<camera>"; }


//View functions //View functions
void SetView(mat4 const &view); void SetView(mat4 const &view);


+ 10
- 8
src/debug/record.cpp 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.
// //


#include <lol/engine-internal.h> #include <lol/engine-internal.h>
@@ -30,7 +32,7 @@ class DebugRecordData
friend class DebugRecord; friend class DebugRecord;


private: private:
String m_path;
std::string m_path;
ivec2 m_size; ivec2 m_size;
int m_fps; int m_fps;
#if defined USE_PIPI #if defined USE_PIPI
@@ -42,7 +44,7 @@ private:
* Public DebugRecord class * Public DebugRecord class
*/ */


DebugRecord::DebugRecord(String const &path, float fps)
DebugRecord::DebugRecord(std::string const &path, float fps)
: m_data(new DebugRecordData()) : m_data(new DebugRecordData())
{ {
Ticker::StartRecording(); Ticker::StartRecording();


+ 9
- 7
src/debug/record.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 #pragma once
@@ -25,7 +27,7 @@ class DebugRecordData;
class DebugRecord : public Entity class DebugRecord : public Entity
{ {
public: public:
DebugRecord(String const &path, float fps);
DebugRecord(std::string const &path, float fps);
virtual ~DebugRecord(); virtual ~DebugRecord();


protected: protected:


+ 5
- 5
src/dict.cpp View File

@@ -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
@@ -64,7 +64,7 @@ Dict::~Dict()
delete data; delete data;
} }


int Dict::MakeSlot(char const *name)
int Dict::MakeSlot(std::string const &name)
{ {
int slotid, empty = -1; int slotid, empty = -1;


@@ -80,7 +80,7 @@ int Dict::MakeSlot(char const *name)
} }
else else
{ {
char const *oldname = e->GetName();
char const *oldname = e->GetName().c_str();
if (*oldname == '<') if (*oldname == '<')
{ {
while (*oldname && *oldname != '>') while (*oldname && *oldname != '>')
@@ -91,7 +91,7 @@ int Dict::MakeSlot(char const *name)
oldname++; oldname++;
} }


if (!strcasecmp(name, oldname))
if (!strcasecmp(name.c_str(), oldname))
break; break;
} }
} }
@@ -137,7 +137,7 @@ void Dict::RemoveSlot(Entity *entity)


#if !LOL_BUILD_RELEASE #if !LOL_BUILD_RELEASE
msg::error("removing unregistered entity %p (%s)\n", msg::error("removing unregistered entity %p (%s)\n",
entity, entity->GetName());
entity, entity->GetName().c_str());
#endif #endif
} }




+ 9
- 7
src/dict.h View File

@@ -1,11 +1,13 @@
// //
// Lol Engine
// Lol Engine
// //
// Copyright: (c) 2010-2011 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
@@ -28,7 +30,7 @@ public:
Dict(); Dict();
~Dict(); ~Dict();


int MakeSlot(char const *name);
int MakeSlot(std::string const &name);
void RemoveSlot(int slotid); void RemoveSlot(int slotid);
void RemoveSlot(Entity *entity); void RemoveSlot(Entity *entity);




+ 2
- 2
src/easymesh/easymesh.h View File

@@ -41,7 +41,7 @@ struct CSGUsageBase : public StructSafeEnum
Xor Xor
}; };
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[Union] = "Union"; enum_map[Union] = "Union";
enum_map[Substract] = "Substract"; enum_map[Substract] = "Substract";
@@ -65,7 +65,7 @@ struct MeshTransformBase : public StructSafeEnum
Shear Shear
}; };
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[Taper] = "Taper"; enum_map[Taper] = "Taper";
enum_map[Twist] = "Twist"; enum_map[Twist] = "Twist";


+ 7
- 7
src/easymesh/easymeshbuild.h View File

@@ -38,7 +38,7 @@ struct MeshBuildOperationBase : public StructSafeEnum
All = 0xffff, All = 0xffff,
}; };
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[ScaleWinding] = "ScaleWinding"; enum_map[ScaleWinding] = "ScaleWinding";
enum_map[CommandRecording] = "CommandRecording"; enum_map[CommandRecording] = "CommandRecording";
@@ -99,7 +99,7 @@ struct EasyMeshCmdTypeBase : public StructSafeEnum
AppendCog, AppendCog,
}; };
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[MeshCsg] = "MeshCsg"; enum_map[MeshCsg] = "MeshCsg";
enum_map[LoopStart] = "LoopStart"; enum_map[LoopStart] = "LoopStart";
@@ -160,7 +160,7 @@ struct MeshTypeBase : public StructSafeEnum
MAX MAX
}; };
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[Triangle] = "Triangle"; enum_map[Triangle] = "Triangle";
enum_map[Quad] = "Quad"; enum_map[Quad] = "Quad";
@@ -200,7 +200,7 @@ struct TexCoordBuildTypeBase : public StructSafeEnum
Max Max
}; };
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[TriangleDefault] = "TriangleDefault"; enum_map[TriangleDefault] = "TriangleDefault";
enum_map[QuadDefault] = "QuadDefault"; enum_map[QuadDefault] = "QuadDefault";
@@ -235,7 +235,7 @@ struct MeshFaceTypeBase : public StructSafeEnum
MAX MAX
}; };
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[BoxFront] = "BoxFront"; enum_map[BoxFront] = "BoxFront";
enum_map[QuadDefault] = "QuadDefault"; enum_map[QuadDefault] = "QuadDefault";
@@ -261,7 +261,7 @@ struct TexCoordPosBase : public StructSafeEnum
TR // Top Right TR // Top Right
}; };
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[BL] = "BL"; enum_map[BL] = "BL";
enum_map[BR] = "BR"; enum_map[BR] = "BR";
@@ -512,7 +512,7 @@ struct VDictTypeBase : public StructSafeEnum
Master = -1, Master = -1,
}; };
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[DoesNotExist] = "DoesNotExist"; enum_map[DoesNotExist] = "DoesNotExist";
enum_map[Alone] = "Alone"; enum_map[Alone] = "Alone";


+ 14
- 13
src/easymesh/easymeshrender.cpp View File

@@ -2,7 +2,7 @@
// Lol Engine // Lol Engine
// //
// Copyright © 2009—2013 Benjamin “Touky” Huet <huet.benjamin@gmail.com> // Copyright © 2009—2013 Benjamin “Touky” Huet <huet.benjamin@gmail.com>
// © 2010—2017 Sam Hocevar <sam@hocevar.net>
// © 2010—2018 Sam Hocevar <sam@hocevar.net>
// © 2009—2013 Cédric Lecacheur <jordx@free.fr> // © 2009—2013 Cédric Lecacheur <jordx@free.fr>
// //
// Lol Engine is free software. It comes without any warranty, to // Lol Engine is free software. It comes without any warranty, to
@@ -93,9 +93,9 @@ GpuShaderData::~GpuShaderData()
} }


//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void GpuShaderData::AddUniform(const lol::String &new_uniform)
void GpuShaderData::AddUniform(std::string const &new_uniform)
{ {
m_shader_uniform.push(new_uniform, m_shader->GetUniformLocation(new_uniform.C()));
m_shader_uniform.push(new_uniform, m_shader->GetUniformLocation(new_uniform));
} }


//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@@ -105,7 +105,7 @@ void GpuShaderData::AddAttribute(VertexUsage usage, int index)
} }


//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
ShaderUniform const *GpuShaderData::GetUniform(const lol::String &uniform)
ShaderUniform const *GpuShaderData::GetUniform(std::string const &uniform)
{ {
for (int i = 0; i < m_shader_uniform.count(); ++i) for (int i = 0; i < m_shader_uniform.count(); ++i)
if (m_shader_uniform[i].m1 == uniform) if (m_shader_uniform[i].m1 == uniform)
@@ -159,17 +159,18 @@ DefaultShaderData::DefaultShaderData(uint16_t vert_decl_flags, Shader* shader, b
SetupDefaultData(with_UV); SetupDefaultData(with_UV);
} }


static const String DefaultUniforms[8] =
static std::string const DefaultUniforms[8] =
{ {
String("u_lights"),
String("u_model"),
String("u_modelview"),
String("u_view"),
String("u_inv_view"),
String("u_proj"),
String("u_normalmat"),
String("u_damage")
"u_lights",
"u_model",
"u_modelview",
"u_view",
"u_inv_view",
"u_proj",
"u_normalmat",
"u_damage",
}; };

//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void DefaultShaderData::StoreUniformNames() void DefaultShaderData::StoreUniformNames()
{ {


+ 11
- 10
src/easymesh/easymeshrender.h View File

@@ -2,7 +2,7 @@
// Lol Engine // Lol Engine
// //
// Copyright © 2009—2013 Benjamin “Touky” Huet <huet.benjamin@gmail.com> // Copyright © 2009—2013 Benjamin “Touky” Huet <huet.benjamin@gmail.com>
// © 2010—2017 Sam Hocevar <sam@hocevar.net>
// © 2010—2018 Sam Hocevar <sam@hocevar.net>
// © 2009—2013 Cédric Lecacheur <jordx@free.fr> // © 2009—2013 Cédric Lecacheur <jordx@free.fr>
// //
// Lol Engine is free software. It comes without any warranty, to // Lol Engine is free software. It comes without any warranty, to
@@ -14,6 +14,7 @@


#pragma once #pragma once


#include <string>
#include <map> #include <map>


namespace lol namespace lol
@@ -31,7 +32,7 @@ struct MeshRenderBase : public StructSafeEnum
IgnoreRender, IgnoreRender,
}; };
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[NeedData] = "NeedData"; enum_map[NeedData] = "NeedData";
enum_map[NeedConvert] = "NeedConvert"; enum_map[NeedConvert] = "NeedConvert";
@@ -81,20 +82,20 @@ public:
GpuShaderData(uint16_t vert_decl_flags, Shader* shader, DebugRenderMode render_mode); GpuShaderData(uint16_t vert_decl_flags, Shader* shader, DebugRenderMode render_mode);
virtual ~GpuShaderData(); virtual ~GpuShaderData();
//-- //--
void AddUniform(const lol::String &new_uniform);
void AddUniform(std::string const &new_uniform);
void AddAttribute(VertexUsage usage, int index); void AddAttribute(VertexUsage usage, int index);
ShaderUniform const *GetUniform(const lol::String &uniform);
ShaderUniform const *GetUniform(std::string const &uniform);
ShaderAttrib const *GetAttribute(VertexUsage usage, int index); ShaderAttrib const *GetAttribute(VertexUsage usage, int index);
//-- //--
virtual void SetupShaderDatas(mat4 const &model) { UNUSED(model); } virtual void SetupShaderDatas(mat4 const &model) { UNUSED(model); }
//-- //--


protected: protected:
uint16_t m_vert_decl_flags;
Shader* m_shader;
int m_render_mode;
array<lol::String, ShaderUniform> m_shader_uniform;
array<ShaderAttrib> m_shader_attrib;
uint16_t m_vert_decl_flags;
Shader *m_shader;
int m_render_mode;
array<std::string, ShaderUniform> m_shader_uniform;
array<ShaderAttrib> m_shader_attrib;
}; };


class DefaultShaderData : public GpuShaderData class DefaultShaderData : public GpuShaderData
@@ -109,7 +110,7 @@ public:
void SetupDefaultData(bool with_UV); void SetupDefaultData(bool with_UV);
virtual void SetupShaderDatas(mat4 const &model); virtual void SetupShaderDatas(mat4 const &model);
//-- //--
array<String> m_uniform_names;
array<std::string> m_uniform_names;
}; };


class GpuEasyMeshData class GpuEasyMeshData


+ 2
- 2
src/engine/entity.cpp View File

@@ -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
@@ -44,7 +44,7 @@ Entity::~Entity()
#endif #endif
} }


char const *Entity::GetName()
std::string Entity::GetName() const
{ {
return "<entity>"; return "<entity>";
} }


+ 2
- 2
src/engine/entity.h View File

@@ -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
@@ -50,7 +50,7 @@ class Entity
friend class Emcee; friend class Emcee;


public: public:
virtual char const *GetName();
virtual std::string GetName() const;


inline bool IsTicked() { return !!m_ref && !m_autorelease; } inline bool IsTicked() { return !!m_ref && !m_autorelease; }
protected: protected:


+ 10
- 10
src/engine/ticker.cpp View File

@@ -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
@@ -114,7 +114,7 @@ void Ticker::Ref(Entity *entity)
ASSERT(entity, "dereferencing nullptr entity\n"); ASSERT(entity, "dereferencing nullptr entity\n");
ASSERT(!entity->m_destroy, ASSERT(!entity->m_destroy,
"referencing entity scheduled for destruction %s\n", "referencing entity scheduled for destruction %s\n",
entity->GetName());
entity->GetName().c_str());


if (entity->m_autorelease) if (entity->m_autorelease)
{ {
@@ -139,9 +139,9 @@ int Ticker::Unref(Entity *entity)
{ {
ASSERT(entity, "dereferencing null entity\n"); ASSERT(entity, "dereferencing null entity\n");
ASSERT(entity->m_ref > 0, "dereferencing unreferenced entity %s\n", ASSERT(entity->m_ref > 0, "dereferencing unreferenced entity %s\n",
entity->GetName());
entity->GetName().c_str());
ASSERT(!entity->m_autorelease, "dereferencing autoreleased entity %s\n", ASSERT(!entity->m_autorelease, "dereferencing autoreleased entity %s\n",
entity->GetName());
entity->GetName().c_str());


return --entity->m_ref; return --entity->m_ref;
} }
@@ -223,7 +223,7 @@ void TickerData::GameThreadTick()
{ {
Entity *e = data->m_list[g][i]; Entity *e = data->m_list[g][i];
msg::debug(" \\-- [%p] %s (m_ref %d, destroy %d)\n", msg::debug(" \\-- [%p] %s (m_ref %d, destroy %d)\n",
e, e->GetName(), e->m_ref, e->m_destroy);
e, e->GetName().c_str(), e->m_ref, e->m_destroy);
} }
} }
#endif #endif
@@ -276,7 +276,7 @@ void TickerData::GameThreadTick()
if (e->m_ref) if (e->m_ref)
{ {
#if !LOL_BUILD_RELEASE #if !LOL_BUILD_RELEASE
msg::error("poking %s\n", e->GetName());
msg::error("poking %s\n", e->GetName().c_str());
#endif #endif
e->m_ref--; e->m_ref--;
n++; n++;
@@ -401,14 +401,14 @@ void TickerData::GameThreadTick()
#if !LOL_BUILD_RELEASE #if !LOL_BUILD_RELEASE
if (e->m_tickstate != Entity::STATE_IDLE) if (e->m_tickstate != Entity::STATE_IDLE)
msg::error("entity %s [%p] not idle for game tick\n", msg::error("entity %s [%p] not idle for game tick\n",
e->GetName(), e);
e->GetName().c_str(), e);
e->m_tickstate = Entity::STATE_PRETICK_GAME; e->m_tickstate = Entity::STATE_PRETICK_GAME;
#endif #endif
e->TickGame(data->deltatime); e->TickGame(data->deltatime);
#if !LOL_BUILD_RELEASE #if !LOL_BUILD_RELEASE
if (e->m_tickstate != Entity::STATE_POSTTICK_GAME) if (e->m_tickstate != Entity::STATE_POSTTICK_GAME)
msg::error("entity %s [%p] missed super game tick\n", msg::error("entity %s [%p] missed super game tick\n",
e->GetName(), e);
e->GetName().c_str(), e);
e->m_tickstate = Entity::STATE_IDLE; e->m_tickstate = Entity::STATE_IDLE;
#endif #endif
} }
@@ -455,14 +455,14 @@ void TickerData::DrawThreadTick()
#if !LOL_BUILD_RELEASE #if !LOL_BUILD_RELEASE
if (e->m_tickstate != Entity::STATE_IDLE) if (e->m_tickstate != Entity::STATE_IDLE)
msg::error("entity %s [%p] not idle for draw tick\n", msg::error("entity %s [%p] not idle for draw tick\n",
e->GetName(), e);
e->GetName().c_str(), e);
e->m_tickstate = Entity::STATE_PRETICK_DRAW; e->m_tickstate = Entity::STATE_PRETICK_DRAW;
#endif #endif
e->TickDraw(data->deltatime, scene); e->TickDraw(data->deltatime, scene);
#if !LOL_BUILD_RELEASE #if !LOL_BUILD_RELEASE
if (e->m_tickstate != Entity::STATE_POSTTICK_DRAW) if (e->m_tickstate != Entity::STATE_POSTTICK_DRAW)
msg::error("entity %s [%p] missed super draw tick\n", msg::error("entity %s [%p] missed super draw tick\n",
e->GetName(), e);
e->GetName().c_str(), e);
e->m_tickstate = Entity::STATE_IDLE; e->m_tickstate = Entity::STATE_IDLE;
#endif #endif
} }


+ 9
- 7
src/engine/worldentity.cpp 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.
// //


#include <lol/engine-internal.h> #include <lol/engine-internal.h>
@@ -32,7 +34,7 @@ WorldEntity::~WorldEntity()
{ {
} }


char const *WorldEntity::GetName()
std::string WorldEntity::GetName() const
{ {
return "<worldentity>"; return "<worldentity>";
} }


+ 9
- 7
src/engine/worldentity.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 #pragma once
@@ -25,7 +27,7 @@ namespace lol
class WorldEntity : public Entity class WorldEntity : public Entity
{ {
public: public:
virtual char const *GetName();
virtual std::string GetName() const;


public: public:
box3 m_aabb; box3 m_aabb;


+ 17
- 15
src/font.cpp View File

@@ -1,12 +1,14 @@
// //
// Lol Engine
// Lol Engine
// //
// Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net>
// 2013 Jean-Yves Lamoureux <jylam@lnxscene.org>
// 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>
// 2013 Jean-Yves Lamoureux <jylam@lnxscene.org>
//
// 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.
// //


#include <lol/engine-internal.h> #include <lol/engine-internal.h>
@@ -26,7 +28,7 @@ class FontData
friend class Font; friend class Font;


private: private:
String m_name;
std::string m_name;
TileSet *tileset; TileSet *tileset;
ivec2 size; ivec2 size;
}; };
@@ -35,10 +37,10 @@ private:
* Public Font class * Public Font class
*/ */


Font::Font(char const *path)
Font::Font(std::string const &path)
: data(new FontData()) : data(new FontData())
{ {
data->m_name = String("<font> ") + path;
data->m_name = "<font> " + path;


data->tileset = Tiler::Register(path, ivec2::zero, ivec2(16)); data->tileset = Tiler::Register(path, ivec2::zero, ivec2(16));
data->size = data->tileset->GetTileSize(0); data->size = data->tileset->GetTileSize(0);
@@ -63,17 +65,17 @@ void Font::TickDraw(float seconds, Scene &scene)
} }
} }


char const *Font::GetName()
std::string Font::GetName() const
{ {
return data->m_name.C();
return data->m_name;
} }


void Font::Print(Scene &scene, vec3 pos, char const *str, vec2 scale, float spacing)
void Font::Print(Scene &scene, vec3 pos, std::string const &str, vec2 scale, float spacing)
{ {
float origin_x = pos.x; float origin_x = pos.x;
while (*str)
for (int i = 0; i < (int)str.length(); ++i)
{ {
uint32_t ch = (uint8_t)*str++;
uint32_t ch = str[i];


switch (ch) switch (ch)
{ {


+ 11
- 9
src/font.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 #pragma once
@@ -25,17 +27,17 @@ class FontData;
class Font : public Entity class Font : public Entity
{ {
public: public:
Font(char const *path);
Font(std::string const &path);
~Font(); ~Font();


protected: protected:
/* Inherited from Entity */ /* Inherited from Entity */
virtual char const *GetName();
virtual std::string GetName() const;
virtual void TickDraw(float seconds, Scene &scene); virtual void TickDraw(float seconds, Scene &scene);


public: public:
/* New methods */ /* New methods */
void Print(Scene &scene, vec3 pos, char const *str, vec2 scale = vec2(1.0f), float spacing = 0.0f);
void Print(Scene &scene, vec3 pos, std::string const &str, vec2 scale = vec2(1.0f), float spacing = 0.0f);
ivec2 GetSize() const; ivec2 GetSize() const;


private: private:


+ 9
- 7
src/forge.cpp View File

@@ -1,11 +1,13 @@
// //
// Lol Engine
// Lol Engine
// //
// Copyright: (c) 2010-2011 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.
// //


#include <lol/engine-internal.h> #include <lol/engine-internal.h>
@@ -32,7 +34,7 @@ static ForgeData * const data = &forgedata;
* Public Forge class * Public Forge class
*/ */


int Forge::Register(char const *path)
int Forge::Register(std::string const &path)
{ {
int id = data->fonts.MakeSlot(path); int id = data->fonts.MakeSlot(path);




+ 9
- 7
src/forge.h View File

@@ -1,11 +1,13 @@
// //
// Lol Engine
// Lol Engine
// //
// Copyright: (c) 2010-2011 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
@@ -24,7 +26,7 @@ namespace lol
class Forge class Forge
{ {
public: public:
static int Register(char const *path);
static int Register(std::string const &path);
static void Deregister(int id); static void Deregister(int id);
static Font *GetFont(int id); static Font *GetFont(int id);




+ 9
- 7
src/gradient.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 #pragma once
@@ -28,7 +30,7 @@ public:
Gradient(vec3 aa, vec3 bb); Gradient(vec3 aa, vec3 bb);
virtual ~Gradient(); virtual ~Gradient();


char const *GetName() { return "<gradient>"; }
std::string GetName() const { return "<gradient>"; }


protected: protected:
virtual void TickGame(float seconds); virtual void TickGame(float seconds);


+ 14
- 12
src/image/color/color.cpp View File

@@ -1,11 +1,13 @@
// //
// Lol Engine
// Lol Engine
// //
// Copyright: (c) 2010-2014 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.
// //


#include <lol/engine-internal.h> #include <lol/engine-internal.h>
@@ -107,25 +109,25 @@ uint16_t Color::ToRGB16(vec4 c)
/* /*
* Conversion from colours to hexadecimal * Conversion from colours to hexadecimal
*/ */
vec4 Color::C8BppHexString(String s)
vec4 Color::C8BppHexString(std::string const &s)
{ {
String c = s[0] == '#' ? &s[1] : s;
uint32_t tmp = std::strtol(c.C(), nullptr, 16);
if (c.count() == 3)
std::string c = s[0] == '#' ? &s[1] : s;
uint32_t tmp = std::strtol(c.c_str(), nullptr, 16);
if (c.length() == 3)
{ {
tmp = 0x11000000u * (tmp >> 8) tmp = 0x11000000u * (tmp >> 8)
| 0x00110000u * ((tmp >> 4) & 0xf) | 0x00110000u * ((tmp >> 4) & 0xf)
| 0x00001100u * (tmp & 0xf) | 0x00001100u * (tmp & 0xf)
| 0x000000ffu; | 0x000000ffu;
} }
else if (c.count() == 4)
else if (c.length() == 4)
{ {
tmp = 0x11000000u * (tmp >> 12) tmp = 0x11000000u * (tmp >> 12)
| 0x00110000u * ((tmp >> 8) & 0xf) | 0x00110000u * ((tmp >> 8) & 0xf)
| 0x00001100u * ((tmp >> 4) & 0xf) | 0x00001100u * ((tmp >> 4) & 0xf)
| 0x00000011u * (tmp & 0xf); | 0x00000011u * (tmp & 0xf);
} }
else if (c.count() == 6)
else if (c.length() == 6)
{ {
tmp = 0xffu | 0x100u * tmp; tmp = 0xffu | 0x100u * tmp;
} }


+ 1
- 1
src/light.h View File

@@ -79,7 +79,7 @@ public:
Light(); Light();
~Light(); ~Light();


char const *GetName() { return "<light>"; }
std::string GetName() const { return "<light>"; }


void SetType(LightType const &type); void SetType(LightType const &type);
LightType GetType(); LightType GetType();


+ 2
- 2
src/lol/audio/sample.h View File

@@ -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
@@ -35,7 +35,7 @@ public:


protected: protected:
/* Inherited from Entity */ /* Inherited from Entity */
virtual char const *GetName();
virtual std::string GetName() const;
virtual void TickGame(float seconds); virtual void TickGame(float seconds);


public: public:


+ 0
- 229
src/lol/base/string.h View File

@@ -44,232 +44,3 @@ std::string vformat(char const *format, va_list ap);


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


//
// The deprecated String class
// ---------------------------
// A very simple String class, based on Array. The most interesting
// thing in there was LOL_ATTR_NODISCARD but apart from that there was
// no real point in using our own class. Phase this out.
//

#include <lol/base/assert.h>
#include <lol/base/array.h>

#include <cstring>
#include <cstdarg>

namespace lol
{

class LOL_ATTR_NODISCARD String : protected array<char>
{
private:
typedef array<char> super;

public:
inline String()
: super()
{
push('\0');
}

inline String(char const *str)
: super()
{
using namespace std;
ASSERT(str);
resize((int)strlen(str));
memcpy(&(*this)[0], str, count() + 1);
}

inline String(char const *str, int item_count)
: super()
{
using namespace std;
ASSERT(str);
resize(item_count);
memcpy(&(*this)[0], str, item_count);
((super &)*this)[item_count] = '\0';
}

/* Legacy constructor for std::string */
inline String(std::string const &s)
: String(s.c_str())
{
}

inline String(String const &s)
: super((super const &)s)
{
}

inline char &operator [](int n)
{
/* Allow n == count() because we might have reasonable reasons
* to access that hidden null character. We cast to unsigned so
* as to avoid a harmless message from the GCC optimiser. */
ASSERT(n >= 0);
ASSERT((unsigned)n <= (unsigned)count());
return ((super &)*this)[n];
}

inline char const &operator [](int n) const
{
ASSERT(n >= 0);
ASSERT((unsigned)n <= (unsigned)count());
return ((super const &)*this)[n];
}

inline char &last()
{
ASSERT(count() > 0);
return (*this)[count() - 1];
}

inline char const &last() const
{
ASSERT(count() > 0);
return (*this)[count() - 1];
}

inline int count() const
{
return ((super const &)*this).count() - 1;
}

/* Return a C string */
inline char const *C() const
{
return &(*this)[0];
}

/* Non-const version; make sure to not overflow the internal array */
inline char *C()
{
return &(*this)[0];
}

/* Does not initialise the newly allocated characters */
void resize(int item_count)
{
ASSERT(item_count >= 0);
((super &)*this).resize(item_count + 1);
((super &)*this).last() = '\0';
}

String sub(int start, int item_count = -1) const
{
ASSERT(start >= 0);
if (start >= count())
return String();
if (item_count < 0 || item_count >= count() - start)
item_count = count() - start;
return String(&(*this)[start], item_count);
}

int replace(char const old_token, char const new_token,
bool all_occurrences = false)
{
using namespace std;

int res = 0;
char *tmp = NULL;
while ((tmp = strrchr(C(), old_token)))
{
*tmp = new_token;
res++;
if (!all_occurrences)
break;
}
return res;
}

inline String operator +(String const &s) const
{
String ret(*this);
return ret += s;
}

inline String operator +(char c) const
{
String ret(*this);
return ret += c;
}

inline String& operator +=(String const &s)
{
using namespace std;
int old_count = count();
resize(count() + s.count());
memcpy(&(*this)[old_count], &s[0], count() - old_count);
return *this;
}

inline String& operator +=(char c)
{
((super &)*this).last() = c;
((super &)*this).push('\0');
return *this;
}

inline bool operator ==(String const &s) const
{
using namespace std;
return count() == s.count()
&& memcmp(C(), s.C(), count()) == 0;
}

inline bool operator !=(String const &s) const
{
return !(*this == s);
}

inline bool operator ==(char const* sz) const
{
/* We parse the C string twice because of strlen + memcmp
* but it's probably still faster than doing it by hand. */
using namespace std;
int sz_len = (int)strlen(sz);
return count() == sz_len
&& memcmp(C(), sz, sz_len) == 0;
}

inline bool operator !=(char const* sz) const
{
return !(*this == sz);
}

inline bool operator <(String const & s) const
{
using namespace std;
int res = memcmp(C(), s.C(), count() < s.count() ? count() : s.count());

if (!res)
return count() < s.count();

return res < 0;
}
};

inline String operator +(char c, String const &s)
{
return String() + c + s;
}

inline String operator +(char const *sz, String const &s)
{
return String(sz) + s;
}

inline bool operator ==(char const* sz, String const &s)
{
return s == sz;
}

inline bool operator !=(char const* sz, String const &s)
{
return s != sz;
}

} /* namespace lol */


+ 1
- 1
src/lol/gpu/vertexbuffer.h View File

@@ -54,7 +54,7 @@ struct MeshPrimitiveBase : public StructSafeEnum
Lines, Lines,
}; };
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[Triangles] = "Triangles"; enum_map[Triangles] = "Triangles";
enum_map[TriangleStrips] = "TriangleStrips"; enum_map[TriangleStrips] = "TriangleStrips";


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

@@ -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
@@ -345,7 +345,7 @@ public:
/* /*
* Convert hex strings to colors. * Convert hex strings to colors.
*/ */
static vec4 C8BppHexString(String c);
static vec4 C8BppHexString(std::string const &c);


/* /*
* Some predefined colours * Some predefined colours


+ 4
- 4
src/lol/math/geometry.h View File

@@ -37,7 +37,7 @@ struct AxisBase : public StructSafeEnum
X = 0, Y, Z, MAX, XY = 2, XYZ = 3, X = 0, Y, Z, MAX, XY = 2, XYZ = 3,
}; };
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[X] = "X"; enum_map[X] = "X";
enum_map[Y] = "Y"; enum_map[Y] = "Y";
@@ -58,7 +58,7 @@ struct DirectionBase : public StructSafeEnum
Up = 0, Down, Left, Right, MAX, Up = 0, Down, Left, Right, MAX,
}; };
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[Up] = "Up"; enum_map[Up] = "Up";
enum_map[Down] = "Down"; enum_map[Down] = "Down";
@@ -260,7 +260,7 @@ struct RayIntersectBase : public StructSafeEnum
}; };
//LOL_DECLARE_ENUM_METHODS(RayIntersectBase) //LOL_DECLARE_ENUM_METHODS(RayIntersectBase)
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[All] = "All"; enum_map[All] = "All";
@@ -325,7 +325,7 @@ struct PlaneIntersectionBase : public StructSafeEnum
Back, Front, Plane, Back, Front, Plane,
}; };
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[Back] = "Back"; enum_map[Back] = "Back";
enum_map[Front] = "Front"; enum_map[Front] = "Front";


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

@@ -80,7 +80,7 @@ class ThreadJob
protected: protected:
inline ThreadJob(ThreadJobType type) : m_type(type) {} inline ThreadJob(ThreadJobType type) : m_type(type) {}
public: public:
char const *GetName() { return "<ThreadJob>"; }
std::string GetName() const { return "<ThreadJob>"; }
inline ThreadJob() : m_type(ThreadJobType::NONE) {} inline ThreadJob() : m_type(ThreadJobType::NONE) {}
virtual ~ThreadJob() {} virtual ~ThreadJob() {}




+ 1
- 1
src/lolimgui.h View File

@@ -176,7 +176,7 @@ public:
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
LolImGui(); LolImGui();
~LolImGui(); ~LolImGui();
char const *GetName() { return "<LolImGui>"; }
std::string GetName() const { return "<LolImGui>"; }


//------------------------------------------------------------------------- //-------------------------------------------------------------------------
static void Init(); static void Init();


+ 4
- 4
src/mesh/mesh.cpp View File

@@ -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
@@ -104,9 +104,9 @@ void SubMesh::SetIndexBuffer(IndexBuffer* ibo)
m_ibo = ibo; m_ibo = ibo;
} }


void SubMesh::AddTexture(const char* name, Texture* texture)
void SubMesh::AddTexture(std::string const &name, Texture* texture)
{ {
m_textures.push(String(name), texture);
m_textures.push(name, texture);
} }


void SubMesh::Render() void SubMesh::Render()
@@ -142,7 +142,7 @@ void SubMesh::Render()
for (int i = 0; i < m_textures.count(); ++i) for (int i = 0; i < m_textures.count(); ++i)
{ {
// TODO: might be good to cache this // TODO: might be good to cache this
ShaderUniform u_tex = m_shader->GetUniformLocation(m_textures[i].m1.C());
ShaderUniform u_tex = m_shader->GetUniformLocation(m_textures[i].m1);
m_shader->SetUniform(u_tex, m_textures[i].m2->GetTextureUniform(), i); m_shader->SetUniform(u_tex, m_textures[i].m2->GetTextureUniform(), i);
} }




+ 3
- 3
src/mesh/mesh.h View File

@@ -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
@@ -94,7 +94,7 @@ public:
void SetVertexDeclaration(VertexDeclaration *vdecl); void SetVertexDeclaration(VertexDeclaration *vdecl);
void SetVertexBuffer(int index, VertexBuffer* vbo); void SetVertexBuffer(int index, VertexBuffer* vbo);
void SetIndexBuffer(IndexBuffer* ibo); void SetIndexBuffer(IndexBuffer* ibo);
void AddTexture(const char* name, Texture* texture);
void AddTexture(std::string const &name, Texture* texture);


protected: protected:
void Render(); void Render();
@@ -105,7 +105,7 @@ protected:
array<VertexBuffer *> m_vbos; array<VertexBuffer *> m_vbos;
IndexBuffer *m_ibo; IndexBuffer *m_ibo;


array<String, Texture*> m_textures;
array<std::string, Texture*> m_textures;
}; };


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


+ 1
- 1
src/messageservice.h View File

@@ -89,7 +89,7 @@ public:
MessageService(); MessageService();
~MessageService(); ~MessageService();


static char const *GetName() { return "<messageservice>"; }
static std::string GetName() { return "<messageservice>"; }


//Setup/Destroy //Setup/Destroy
static void Setup(); static void Setup();


+ 4
- 4
src/sys/getopt.cpp View File

@@ -1,7 +1,7 @@
// //
// Lol Engine // Lol Engine
// //
// Copyright © 2002—2016 Sam Hocevar <sam@hocevar.net>
// Copyright © 2002—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
@@ -44,7 +44,7 @@ struct getopt_private
int m_argc; int m_argc;
char * const *m_argv; char * const *m_argv;


String m_optstring;
std::string m_optstring;
array<optdesc> m_opts; array<optdesc> m_opts;
}; };


@@ -90,7 +90,7 @@ int getopt::parse()
optind = this->index; optind = this->index;
optarg = this->arg; optarg = this->arg;
m_private->m_opts.push(getopt_private::optdesc { nullptr, 0, nullptr, 0 }); m_private->m_opts.push(getopt_private::optdesc { nullptr, 0, nullptr, 0 });
ret = getopt_long(m_private->m_argc, m_private->m_argv, m_private->m_optstring.C(),
ret = getopt_long(m_private->m_argc, m_private->m_argv, m_private->m_optstring.c_str(),
(option const *)m_private->m_opts.data(), &longindex); (option const *)m_private->m_opts.data(), &longindex);
this->index = optind; this->index = optind;
this->arg = optarg; this->arg = optarg;
@@ -117,7 +117,7 @@ int getopt::parse()
if (ret == '\0') if (ret == '\0')
return -1; return -1;


tmp = strchr(m_private->m_optstring.C(), ret);
tmp = strchr(m_private->m_optstring.c_str(), ret);
if (!tmp || ret == ':') if (!tmp || ret == ':')
return '?'; return '?';




+ 11
- 5
src/sys/threadtypes.cpp View File

@@ -32,14 +32,19 @@ class FileUpdateTesterJob : public ThreadJob
{ {
friend class FileUpdateTester; friend class FileUpdateTester;
public: public:
char const *GetName() { return "<FileUpdateTesterJob>"; }
std::string GetName() const { return "<FileUpdateTesterJob>"; }

FileUpdateTesterJob() FileUpdateTesterJob()
: ThreadJob(ThreadJobType::NONE) { }
: ThreadJob(ThreadJobType::NONE)
{
}

FileUpdateTesterJob(std::string const &path) FileUpdateTesterJob(std::string const &path)
: ThreadJob(ThreadJobType::WORK_TODO)
: ThreadJob(ThreadJobType::WORK_TODO),
m_path(path)
{ {
m_path = path;
} }

std::string const &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; }
@@ -156,7 +161,8 @@ void FileUpdateTester::TreatResult(ThreadJob* result)
class AsyncImageJob : public ThreadJob class AsyncImageJob : public ThreadJob
{ {
public: public:
char const *GetName() { return "<AsyncImageJob>"; }
std::string GetName() const { return "<AsyncImageJob>"; }

AsyncImageJob() AsyncImageJob()
: ThreadJob(ThreadJobType::NONE) : ThreadJob(ThreadJobType::NONE)
{ {


+ 2
- 2
src/t/base/array.cpp View File

@@ -1,7 +1,7 @@
// //
// Lol Engine — Unit tests // Lol Engine — Unit tests
// //
// 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
@@ -191,7 +191,7 @@ lolunit_declare_fixture(array_test)


lolunit_declare_test(array_insert_tuple) lolunit_declare_test(array_insert_tuple)
{ {
array<int, float, String> b;
array<int, float, std::string> b;
b.insert(0, 5, 6.f, "lol"); b.insert(0, 5, 6.f, "lol");
lolunit_assert_equal(5, b[0].m1); lolunit_assert_equal(5, b[0].m1);
lolunit_assert_equal(6.f, b[0].m2); lolunit_assert_equal(6.f, b[0].m2);


+ 17
- 14
src/t/sys/thread.cpp View File

@@ -28,9 +28,12 @@ lolunit_declare_fixture(thread_test)
{ {
friend class UnitTestThreadManager; friend class UnitTestThreadManager;
public: public:
char const *GetName() { return "<UnitTestJob>"; }
UnitTestJob() : ThreadJob(ThreadJobType::WORK_TODO)
std::string GetName() const { return "<UnitTestJob>"; }

UnitTestJob()
: ThreadJob(ThreadJobType::WORK_TODO)
{ } { }

bool IsDone() bool IsDone()
{ {
return m_done; return m_done;
@@ -41,9 +44,9 @@ lolunit_declare_fixture(thread_test)
{ {
timer t; timer t;
m_done = false; m_done = false;
msg::info("%s: STARTED WORK\n", GetName());
msg::info("%s: STARTED WORK\n", GetName().c_str());
t.wait(2.f); t.wait(2.f);
msg::info("%s: ENDED WORK\n", GetName());
msg::info("%s: ENDED WORK\n", GetName().c_str());
m_done = true; m_done = true;
return true; return true;
} }
@@ -76,7 +79,7 @@ lolunit_declare_fixture(thread_test)
typedef SafeEnum<UnitTestStatusBase> UnitTestStatus; typedef SafeEnum<UnitTestStatusBase> UnitTestStatus;


public: public:
char const *GetName() { return "<UnitTestThreadManager>"; }
std::string GetName() const { return "<UnitTestThreadManager>"; }
UnitTestThreadManager() : BaseThreadManager(4, 1) UnitTestThreadManager() : BaseThreadManager(4, 1)
{ } { }
virtual ~UnitTestThreadManager() virtual ~UnitTestThreadManager()
@@ -84,14 +87,14 @@ lolunit_declare_fixture(thread_test)


void AddJob(ThreadJob* job) void AddJob(ThreadJob* job)
{ {
msg::info("%s DISPATCHING JOB %s\n", GetName(), job->GetName());
msg::info("%s DISPATCHING JOB %s\n", GetName().c_str(), job->GetName().c_str());
DispatchJob(job); DispatchJob(job);
} }
bool GetWorkResult(array<ThreadJob*>& results) bool GetWorkResult(array<ThreadJob*>& results)
{ {
results += m_job_result; results += m_job_result;
m_job_result.empty(); m_job_result.empty();
msg::info("%s GETWORKRESULT (%i)\n", GetName(), results.count());
msg::info("%s GETWORKRESULT (%i)\n", GetName().c_str(), results.count());
return results.count() > 0; return results.count() > 0;
} }


@@ -102,7 +105,7 @@ lolunit_declare_fixture(thread_test)
case UnitTestStatus::NOT_QUEUED: case UnitTestStatus::NOT_QUEUED:
if (!!GetDispatchCount()) if (!!GetDispatchCount())
{ {
msg::info("%s TICKGAME %s\n", GetName(), m_status.tostring().c_str());
msg::info("%s TICKGAME %s\n", GetName().c_str(), m_status.tostring().c_str());
m_status = UnitTestStatus::QUEUED; m_status = UnitTestStatus::QUEUED;
} }
break; break;
@@ -113,14 +116,14 @@ lolunit_declare_fixture(thread_test)
if (GetDispatchedCount()) if (GetDispatchedCount())
#endif #endif
{ {
msg::info("%s TICKGAME %s\n", GetName(), m_status.tostring().c_str());
msg::info("%s TICKGAME %s\n", GetName().c_str(), m_status.tostring().c_str());
m_status = UnitTestStatus::RETRIEVED; m_status = UnitTestStatus::RETRIEVED;
} }
break; break;
case UnitTestStatus::RETRIEVED: case UnitTestStatus::RETRIEVED:
if (m_job_result.count() == 4) if (m_job_result.count() == 4)
{ {
msg::info("%s TICKGAME %s\n", GetName(), m_status.tostring().c_str());
msg::info("%s TICKGAME %s\n", GetName().c_str(), m_status.tostring().c_str());
m_status = UnitTestStatus::DONE; m_status = UnitTestStatus::DONE;
} }
break; break;
@@ -154,10 +157,10 @@ lolunit_declare_fixture(thread_test)


lolunit_declare_test(threads) lolunit_declare_test(threads)
{ {
msg::info("%s START\n", m_manager.GetName());
msg::info("%s START\n", m_manager.GetName().c_str());
//Start threads manager //Start threads manager
m_manager.Start(); m_manager.Start();
msg::info("%s STARTED\n", m_manager.GetName());
msg::info("%s STARTED\n", m_manager.GetName().c_str());


UnitTestJob job[4]; UnitTestJob job[4];
lolunit_assert_equal(0, m_manager.Test_GetDispatchCount()); lolunit_assert_equal(0, m_manager.Test_GetDispatchCount());
@@ -190,10 +193,10 @@ lolunit_declare_fixture(thread_test)
m_manager.GetWorkResult(results); m_manager.GetWorkResult(results);
lolunit_assert_equal(4, results.count()); lolunit_assert_equal(4, results.count());


msg::info("%s STOP\n", m_manager.GetName());
msg::info("%s STOP\n", m_manager.GetName().c_str());
//Stop manager //Stop manager
m_manager.Stop(); m_manager.Stop();
msg::info("%s STOPPED\n", m_manager.GetName());
msg::info("%s STOPPED\n", m_manager.GetName().c_str());
} }


lolunit_declare_test(queue_try_push) lolunit_declare_test(queue_try_push)


+ 6
- 6
src/text.cpp View File

@@ -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
@@ -30,7 +30,7 @@ class TextData
private: private:
int m_font; int m_font;
TextAlign m_align; TextAlign m_align;
String m_text;
std::string m_text;
vec3 m_pos; vec3 m_pos;
vec2 m_scale; vec2 m_scale;
float m_spacing; float m_spacing;
@@ -40,7 +40,7 @@ private:
* Public Text class * Public Text class
*/ */


Text::Text(String const &text, char const *font)
Text::Text(std::string const &text, char const *font)
: data(new TextData()) : data(new TextData())
{ {
data->m_font = Forge::Register(font); data->m_font = Forge::Register(font);
@@ -53,7 +53,7 @@ Text::Text(String const &text, char const *font)
m_drawgroup = DRAWGROUP_HUD; m_drawgroup = DRAWGROUP_HUD;
} }


void Text::SetText(String const &text)
void Text::SetText(std::string const &text)
{ {
data->m_text = text; data->m_text = text;
} }
@@ -98,7 +98,7 @@ void Text::TickDraw(float seconds, Scene &scene)
{ {
Entity::TickDraw(seconds, scene); Entity::TickDraw(seconds, scene);


if (auto length = data->m_text.count())
if (auto length = data->m_text.length())
{ {
Font *font = Forge::GetFont(data->m_font); Font *font = Forge::GetFont(data->m_font);
vec3 delta(0.0f); vec3 delta(0.0f);
@@ -110,7 +110,7 @@ void Text::TickDraw(float seconds, Scene &scene)
else if (data->m_align == TextAlign::Center) else if (data->m_align == TextAlign::Center)
delta.x -= 0.5f * text_width * data->m_scale.x; delta.x -= 0.5f * text_width * data->m_scale.x;


font->Print(scene, data->m_pos + delta, data->m_text.C(),
font->Print(scene, data->m_pos + delta, data->m_text,
data->m_scale, data->m_spacing); data->m_scale, data->m_spacing);
} }
} }


+ 12
- 8
src/text.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 #pragma once
@@ -17,6 +19,8 @@


#include "engine/entity.h" #include "engine/entity.h"


#include <string>

namespace lol namespace lol
{ {


@@ -32,11 +36,11 @@ enum class TextAlign
class Text : public Entity class Text : public Entity
{ {
public: public:
Text(String const &text, char const *font);
Text(std::string const &text, char const *font);
virtual ~Text(); virtual ~Text();


/** Set the text that will be displayed */ /** Set the text that will be displayed */
void SetText(String const &text);
void SetText(std::string const &text);
void SetInt(int val); void SetInt(int val);


/** Set the position of the text object, in the 3D world. */ /** Set the position of the text object, in the 3D world. */


+ 9
- 7
src/textureimage-private.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 #pragma once
@@ -27,7 +29,7 @@ class TextureImageData


//T'was protected .... should it be ? //T'was protected .... should it be ?
public: public:
String m_name;
std::string m_name;


/* Pixels, then texture coordinates */ /* Pixels, then texture coordinates */
ivec2 m_image_size, m_texture_size; ivec2 m_image_size, m_texture_size;


+ 9
- 9
src/textureimage.cpp View File

@@ -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
@@ -40,13 +40,13 @@ TextureImageData* TextureImage::GetNewData()
* Public TextureImage class * Public TextureImage class
*/ */


TextureImage::TextureImage(char const *path)
TextureImage::TextureImage(std::string const &path)
: m_data(GetNewData()) : m_data(GetNewData())
{ {
Init(path); Init(path);
} }


TextureImage::TextureImage(char const *path, image* img)
TextureImage::TextureImage(std::string const &path, image* img)
: m_data(GetNewData()) : m_data(GetNewData())
{ {
Init(path, img); Init(path, img);
@@ -57,12 +57,12 @@ TextureImage::~TextureImage()
delete m_data; delete m_data;
} }


void TextureImage::Init(char const *path)
void TextureImage::Init(std::string const &path)
{ {
Init(path, ResourceLoader::Load(path)); Init(path, ResourceLoader::Load(path));
} }


void TextureImage::Init(char const *path, ResourceCodecData* loaded_data)
void TextureImage::Init(std::string const &path, ResourceCodecData* loaded_data)
{ {
//Load image if available //Load image if available
auto image_data = dynamic_cast<ResourceImageData*>(loaded_data); auto image_data = dynamic_cast<ResourceImageData*>(loaded_data);
@@ -74,9 +74,9 @@ void TextureImage::Init(char const *path, ResourceCodecData* loaded_data)
delete image_data; delete image_data;
} }


void TextureImage::Init(char const *path, image* img)
void TextureImage::Init(std::string const &path, image* img)
{ {
m_data->m_name = String("<textureimage> ") + path;
m_data->m_name = "<textureimage> " + path;


m_data->m_texture = nullptr; m_data->m_texture = nullptr;
m_data->m_image = img; m_data->m_image = img;
@@ -144,9 +144,9 @@ void TextureImage::TickDraw(float seconds, Scene &scene)
} }


//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
char const *TextureImage::GetName()
std::string TextureImage::GetName() const
{ {
return m_data->m_name.C();
return m_data->m_name;
} }


void TextureImage::UpdateTexture(image* img) void TextureImage::UpdateTexture(image* img)


+ 14
- 12
src/textureimage.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 #pragma once
@@ -38,21 +40,21 @@ protected:
virtual TextureImageData* GetNewData(); virtual TextureImageData* GetNewData();


public: public:
TextureImage(char const *path);
TextureImage(char const *path, image* img);
TextureImage(std::string const &path);
TextureImage(std::string const &path, image* img);
virtual ~TextureImage(); virtual ~TextureImage();


protected: protected:
void Init(char const *path);
virtual void Init(char const *path, ResourceCodecData* loaded_data);
virtual void Init(char const *path, image* img);
void Init(std::string const &path);
virtual void Init(std::string const &path, ResourceCodecData* loaded_data);
virtual void Init(std::string const &path, image* img);


protected: protected:
virtual void TickDraw(float seconds, Scene &scene); virtual void TickDraw(float seconds, Scene &scene);


public: public:
/* Inherited from Entity */ /* Inherited from Entity */
virtual char const *GetName();
virtual std::string GetName() const;


void UpdateTexture(image* img); void UpdateTexture(image* img);
Texture * GetTexture(); Texture * GetTexture();


+ 12
- 26
src/tiler.cpp 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.
// //


#include <lol/engine-internal.h> #include <lol/engine-internal.h>
@@ -36,11 +38,7 @@ static TilerData * const data = &tilerdata;
* Public Tiler class * Public Tiler class
*/ */


TileSet *Tiler::Register(String const &path, ivec2 size, ivec2 count)
{
return Tiler::Register(path.C(), size, count);
}
TileSet *Tiler::Register(char const *path, ivec2 size, ivec2 count)
TileSet *Tiler::Register(std::string const &path, ivec2 size, ivec2 count)
{ {
int id = data->tilesets.MakeSlot(path); int id = data->tilesets.MakeSlot(path);
TileSet *tileset = (TileSet *)data->tilesets.GetEntity(id); TileSet *tileset = (TileSet *)data->tilesets.GetEntity(id);
@@ -54,11 +52,7 @@ TileSet *Tiler::Register(char const *path, ivec2 size, ivec2 count)
return tileset; return tileset;
} }


TileSet *Tiler::Register(String const &path)
{
return Tiler::Register(path.C());
}
TileSet *Tiler::Register(char const *path)
TileSet *Tiler::Register(std::string const &path)
{ {
int id = data->tilesets.MakeSlot(path); int id = data->tilesets.MakeSlot(path);
TileSet *tileset = (TileSet *)data->tilesets.GetEntity(id); TileSet *tileset = (TileSet *)data->tilesets.GetEntity(id);
@@ -72,11 +66,7 @@ TileSet *Tiler::Register(char const *path)
return tileset; return tileset;
} }


TileSet *Tiler::Register(String const &path, Image* image, ivec2 size, ivec2 count)
{
return Tiler::Register(path.C(), image, size, count);
}
TileSet *Tiler::Register(char const *path, Image* image, ivec2 size, ivec2 count)
TileSet *Tiler::Register(std::string const &path, Image* image, ivec2 size, ivec2 count)
{ {
int id = data->tilesets.MakeSlot(path); int id = data->tilesets.MakeSlot(path);
TileSet *tileset = (TileSet *)data->tilesets.GetEntity(id); TileSet *tileset = (TileSet *)data->tilesets.GetEntity(id);
@@ -90,11 +80,7 @@ TileSet *Tiler::Register(char const *path, Image* image, ivec2 size, ivec2 count
return tileset; return tileset;
} }


TileSet *Tiler::Register(String const &path, Image* image)
{
return Tiler::Register(path.C(), image);
}
TileSet *Tiler::Register(char const *path, Image* image)
TileSet *Tiler::Register(std::string const &path, Image* image)
{ {
int id = data->tilesets.MakeSlot(path); int id = data->tilesets.MakeSlot(path);
TileSet *tileset = (TileSet *)data->tilesets.GetEntity(id); TileSet *tileset = (TileSet *)data->tilesets.GetEntity(id);


+ 12
- 14
src/tiler.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 #pragma once
@@ -26,14 +28,10 @@ namespace lol
class Tiler class Tiler
{ {
public: public:
static TileSet *Register(String const &path, ivec2 size, ivec2 count);
static TileSet *Register(char const *path, ivec2 size, ivec2 count);
static TileSet *Register(String const &path);
static TileSet *Register(char const *path);
static TileSet *Register(String const &path, image* img, ivec2 size, ivec2 count);
static TileSet *Register(char const *path, image* img, ivec2 size, ivec2 count);
static TileSet *Register(String const &path, image* img);
static TileSet *Register(char const *path, image* img);
static TileSet *Register(std::string const &path, ivec2 size, ivec2 count);
static TileSet *Register(std::string const &path);
static TileSet *Register(std::string const &path, image* img, ivec2 size, ivec2 count);
static TileSet *Register(std::string const &path, image* img);
static void Deregister(TileSet *); static void Deregister(TileSet *);


private: private:


+ 12
- 12
src/tileset.cpp View File

@@ -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
@@ -45,21 +45,21 @@ protected:
* Public TileSet class * Public TileSet class
*/ */


TileSet::TileSet(char const *path)
TileSet::TileSet(std::string const &path)
: TextureImage(path), : TextureImage(path),
m_tileset_data(new TileSetData()), m_tileset_data(new TileSetData()),
m_palette(nullptr) m_palette(nullptr)
{ {
} }


TileSet::TileSet(char const *path, Image* image)
TileSet::TileSet(std::string const &path, Image* image)
: TextureImage(path, image), : TextureImage(path, image),
m_tileset_data(new TileSetData()), m_tileset_data(new TileSetData()),
m_palette(nullptr) m_palette(nullptr)
{ {
} }


TileSet::TileSet(char const *path, Image* image, array<ivec2, ivec2>& tiles)
TileSet::TileSet(std::string const &path, Image* image, array<ivec2, ivec2>& tiles)
: TextureImage(path, image), : TextureImage(path, image),
m_tileset_data(new TileSetData()), m_tileset_data(new TileSetData()),
m_palette(nullptr) m_palette(nullptr)
@@ -67,7 +67,7 @@ TileSet::TileSet(char const *path, Image* image, array<ivec2, ivec2>& tiles)
define_tile(tiles); define_tile(tiles);
} }


TileSet::TileSet(char const *path, ivec2 size, ivec2 count)
TileSet::TileSet(std::string const &path, ivec2 size, ivec2 count)
: TileSet(path) : TileSet(path)
{ {
/* If count is valid, fix size; otherwise, fix count. */ /* If count is valid, fix size; otherwise, fix count. */
@@ -90,7 +90,7 @@ TileSet::TileSet(char const *path, ivec2 size, ivec2 count)
} }
} }


TileSet::TileSet(char const *path, Image* image, ivec2 size, ivec2 count)
TileSet::TileSet(std::string const &path, Image* image, ivec2 size, ivec2 count)
: TileSet(path, image) : TileSet(path, image)
{ {
/* If count is valid, fix size; otherwise, fix count. */ /* If count is valid, fix size; otherwise, fix count. */
@@ -118,7 +118,7 @@ TileSet::~TileSet()
delete m_tileset_data; delete m_tileset_data;
} }


void TileSet::Init(char const *path, ResourceCodecData* loaded_data)
void TileSet::Init(std::string const &path, ResourceCodecData* loaded_data)
{ {
//Load tileset if available //Load tileset if available
auto tileset_data = dynamic_cast<ResourceTilesetData*>(loaded_data); auto tileset_data = dynamic_cast<ResourceTilesetData*>(loaded_data);
@@ -127,22 +127,22 @@ void TileSet::Init(char const *path, ResourceCodecData* loaded_data)
define_tile(tileset_data->m_tiles); define_tile(tileset_data->m_tiles);
} }


m_data->m_name = String("<tileset> ") + path;
m_data->m_name = "<tileset> " + path;


super::Init(path, loaded_data); super::Init(path, loaded_data);
} }


void TileSet::Init(char const *path, Image* image)
void TileSet::Init(std::string const &path, Image* image)
{ {
super::Init(path, image); super::Init(path, image);


m_data->m_name = String("<tileset> ") + path;
m_data->m_name = "<tileset> " + path;
} }


//Inherited from Entity ------------------------------------------------------- //Inherited from Entity -------------------------------------------------------
char const *TileSet::GetName()
std::string TileSet::GetName() const
{ {
return m_data->m_name.C();
return m_data->m_name;
} }


//New methods ----------------------------------------------------------------- //New methods -----------------------------------------------------------------


+ 9
- 9
src/tileset.h View File

@@ -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
@@ -41,23 +41,23 @@ class TileSet : public TextureImage
typedef TextureImage super; typedef TextureImage super;


public: public:
TileSet(char const *path);
TileSet(char const *path, image* img);
TileSet(char const *path, image* img, array<ivec2, ivec2>& tiles);
TileSet(std::string const &path);
TileSet(std::string const &path, image* img);
TileSet(std::string const &path, image* img, array<ivec2, ivec2>& tiles);


/* Old style: path to PNG file */ /* Old style: path to PNG file */
TileSet(char const *path, ivec2 size, ivec2 count);
TileSet(char const *path, image* img, ivec2 size, ivec2 count);
TileSet(std::string const &path, ivec2 size, ivec2 count);
TileSet(std::string const &path, image* img, ivec2 size, ivec2 count);


virtual ~TileSet(); virtual ~TileSet();


protected: protected:
virtual void Init(char const *path, ResourceCodecData* loaded_data);
virtual void Init(char const *path, image* img);
virtual void Init(std::string const &path, ResourceCodecData* loaded_data);
virtual void Init(std::string const &path, image* img);


public: public:
/* Inherited from Entity */ /* Inherited from Entity */
virtual char const *GetName();
virtual std::string GetName() const;


/* New methods */ /* New methods */
void clear_all(); void clear_all();


Loading…
Cancel
Save