@@ -1,12 +1,20 @@ | |||||
// | // | ||||
// 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 | ||||
#include <string> | |||||
class CatShaderData : public GpuShaderData | class CatShaderData : public GpuShaderData | ||||
{ | { | ||||
friend class CRenderer; | friend class CRenderer; | ||||
@@ -18,14 +26,14 @@ public: | |||||
void SetupDefaultData(); | void SetupDefaultData(); | ||||
virtual void SetupShaderDatas(mat4 const &model); | virtual void SetupShaderDatas(mat4 const &model); | ||||
//-- | //-- | ||||
virtual lol::String GetInVertexName() { return lol::String("in_vertex"); } | |||||
virtual lol::String GetInNormalName() { return lol::String("in_normal"); } | |||||
virtual lol::String GetInColorName() { return lol::String("in_color"); } | |||||
virtual lol::String GetInTexCoordName() { return lol::String("in_texcoord"); } | |||||
TextureUniform m_tex_uniform; | |||||
float m_sprite_orientation; | |||||
float m_sprite_flip; | |||||
virtual std::string GetInVertexName() { return "in_vertex"; } | |||||
virtual std::string GetInNormalName() { return "in_normal"; } | |||||
virtual std::string GetInColorName() { return "in_color"; } | |||||
virtual std::string GetInTexCoordName() { return "in_texcoord"; } | |||||
TextureUniform m_tex_uniform; | |||||
float m_sprite_orientation; | |||||
float m_sprite_flip; | |||||
}; | }; | ||||
class BtPhysTest : public WorldEntity | class BtPhysTest : public WorldEntity | ||||
@@ -62,7 +70,7 @@ private: | |||||
KEY_MAX | KEY_MAX | ||||
}; | }; | ||||
protected: | protected: | ||||
virtual bool BuildEnumMap(map<int64_t, String>& enum_map) | |||||
virtual bool BuildEnumMap(map<int64_t, std::string>& enum_map) | |||||
{ | { | ||||
enum_map[KEY_MOVE_FORWARD] = g_name_key_Up; | enum_map[KEY_MOVE_FORWARD] = g_name_key_Up; | ||||
enum_map[KEY_MOVE_BACK] = g_name_key_Down; | enum_map[KEY_MOVE_BACK] = g_name_key_Down; | ||||
@@ -1,7 +1,7 @@ | |||||
// | // | ||||
// Lol Engine — EasyMesh tutorial | // Lol Engine — EasyMesh tutorial | ||||
// | // | ||||
// Copyright © 2011—2015 Sam Hocevar <sam@hocevar.net> | |||||
// Copyright © 2011—2018 Sam Hocevar <sam@hocevar.net> | |||||
// © 2012—2015 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | // © 2012—2015 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | ||||
// | // | ||||
// Lol Engine is free software. It comes without any warranty, to | // Lol Engine is free software. It comes without any warranty, to | ||||
@@ -16,6 +16,7 @@ | |||||
#endif | #endif | ||||
#include <cfloat> /* for FLT_MAX */ | #include <cfloat> /* for FLT_MAX */ | ||||
#include <string> | |||||
#include <lol/engine.h> | #include <lol/engine.h> | ||||
#include <lol/lua.h> | #include <lol/lua.h> | ||||
@@ -112,18 +113,18 @@ void EasyMeshViewerObject::TickDraw(float seconds, Scene &scene) | |||||
//EasyMeshLoadJob ------------------------------------------------------------- | //EasyMeshLoadJob ------------------------------------------------------------- | ||||
bool EasyMeshLoadJob::DoWork() | bool EasyMeshLoadJob::DoWork() | ||||
{ | { | ||||
map<String, EasyMeshLuaObject*> meshes; | |||||
map<std::string, EasyMeshLuaObject*> meshes; | |||||
if (m_loader.ExecLuaFile(m_path) && EasyMeshLuaLoader::GetRegisteredMeshes(meshes)) | if (m_loader.ExecLuaFile(m_path) && EasyMeshLuaLoader::GetRegisteredMeshes(meshes)) | ||||
{ | { | ||||
array<String> keys = meshes.keys(); | |||||
for (String key : keys) | |||||
array<std::string> keys = meshes.keys(); | |||||
for (auto const &key : keys) | |||||
m_meshes << new EasyMeshViewerObject(key, meshes[key]->GetMesh()); | m_meshes << new EasyMeshViewerObject(key, meshes[key]->GetMesh()); | ||||
} | } | ||||
return !!m_meshes.count(); | return !!m_meshes.count(); | ||||
} | } | ||||
//----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||||
MeshViewerLoadJob* EasyMeshLoadJob::GetInstance(String const& path) | |||||
MeshViewerLoadJob* EasyMeshLoadJob::GetInstance(std::string const& path) | |||||
{ | { | ||||
if (Check(path)) | if (Check(path)) | ||||
return new EasyMeshLoadJob(path); | return new EasyMeshLoadJob(path); | ||||
@@ -242,8 +243,8 @@ void MeshViewer::Stop() | |||||
void MeshViewer::UpdateSceneSetup(bool only_destroy) | void MeshViewer::UpdateSceneSetup(bool only_destroy) | ||||
{ | { | ||||
//Delete previous setups | //Delete previous setups | ||||
array<String> keys = m_ssetups.keys(); | |||||
for (String key : keys) | |||||
array<std::string> keys = m_ssetups.keys(); | |||||
for (auto const &key : keys) | |||||
delete m_ssetups[key]; | delete m_ssetups[key]; | ||||
m_ssetups.empty(); | m_ssetups.empty(); | ||||
if (m_ssetup_file_status) | if (m_ssetup_file_status) | ||||
@@ -260,15 +261,15 @@ void MeshViewer::UpdateSceneSetup(bool only_destroy) | |||||
if (m_ssetup_loader.GetLoadedSetups(m_ssetups)) | if (m_ssetup_loader.GetLoadedSetups(m_ssetups)) | ||||
{ | { | ||||
m_ssetup_file_status = m_file_check->RegisterFile(m_ssetup_file_name); | m_ssetup_file_status = m_file_check->RegisterFile(m_ssetup_file_name); | ||||
array<String> keys = m_ssetups.keys(); | |||||
if (!m_ssetup_name.count() || !keys.find(m_ssetup_name)) | |||||
array<std::string> keys = m_ssetups.keys(); | |||||
if (!m_ssetup_name.length() || !keys.find(m_ssetup_name)) | |||||
m_ssetup_name = keys[0]; | m_ssetup_name = keys[0]; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
//----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||||
MeshViewerLoadJob* MeshViewer::GetLoadJob(String const& path) | |||||
MeshViewerLoadJob* MeshViewer::GetLoadJob(std::string const& path) | |||||
{ | { | ||||
MeshViewerLoadJob* job = nullptr; | MeshViewerLoadJob* job = nullptr; | ||||
if (job = EasyMeshLoadJob::GetInstance(path)) return job; | if (job = EasyMeshLoadJob::GetInstance(path)) return job; | ||||
@@ -303,15 +304,15 @@ void MeshViewer::TickGame(float seconds) | |||||
//static float f; | //static float f; | ||||
//static int mesh_idx = 0; | //static int mesh_idx = 0; | ||||
//static array<char*> mesh_names_char; | //static array<char*> mesh_names_char; | ||||
//static array<String> mesh_names_str; | |||||
//static array<std::string> mesh_names_str; | |||||
//Draw viewer objects | //Draw viewer objects | ||||
m_menu_mesh_names_char.empty(); | m_menu_mesh_names_char.empty(); | ||||
m_menu_mesh_names_str.empty(); | m_menu_mesh_names_str.empty(); | ||||
for (ViewerObject* obj : m_objs) | for (ViewerObject* obj : m_objs) | ||||
m_menu_mesh_names_str << obj->GetName(); | m_menu_mesh_names_str << obj->GetName(); | ||||
for (auto str : m_menu_mesh_names_str) | |||||
m_menu_mesh_names_char << str.C(); | |||||
for (auto const &str : m_menu_mesh_names_str) | |||||
m_menu_mesh_names_char << str.c_str(); | |||||
ImGuiIO& io = ImGui::GetIO(); | ImGuiIO& io = ImGui::GetIO(); | ||||
//CAMERA UI --------------------------------------------------------------- | //CAMERA UI --------------------------------------------------------------- | ||||
@@ -382,7 +383,7 @@ void MeshViewer::TickDraw(float seconds, Scene &scene) | |||||
if (m_menu_mesh_idx >= 0 && m_menu_mesh_idx < m_objs.count()) | if (m_menu_mesh_idx >= 0 && m_menu_mesh_idx < m_objs.count()) | ||||
m_objs[m_menu_mesh_idx]->TickDraw(seconds, scene); | m_objs[m_menu_mesh_idx]->TickDraw(seconds, scene); | ||||
m_text->SetText(String("CECI EST UN TEST\n")); | |||||
m_text->SetText("CECI EST UN TEST\n"); | |||||
//Draw gizmos & grid | //Draw gizmos & grid | ||||
Debug::DrawGizmo(vec3::zero, vec3::axis_x, vec3::axis_y, vec3::axis_z, 10.f); | Debug::DrawGizmo(vec3::zero, vec3::axis_x, vec3::axis_y, vec3::axis_z, 10.f); | ||||
@@ -486,7 +487,7 @@ void MeshViewer::Prepare() | |||||
m_controller = new Controller("Default"); | m_controller = new Controller("Default"); | ||||
m_controller->SetInputCount(MAX_KEYS, MAX_AXIS); | m_controller->SetInputCount(MAX_KEYS, MAX_AXIS); | ||||
if (InputDevice::Get(g_name_mouse.C())) | |||||
if (InputDevice::Get(g_name_mouse.c_str())) | |||||
{ | { | ||||
m_input_usage |= (1 << IPT_MV_MOUSE); | m_input_usage |= (1 << IPT_MV_MOUSE); | ||||
@@ -498,7 +499,7 @@ void MeshViewer::Prepare() | |||||
m_controller->GetAxis(MSEX_CAM_X).BindMouse("X"); | m_controller->GetAxis(MSEX_CAM_X).BindMouse("X"); | ||||
} | } | ||||
if (InputDevice::Get(g_name_keyboard.C())) | |||||
if (InputDevice::Get(g_name_keyboard.c_str())) | |||||
{ | { | ||||
m_input_usage |= (1 << IPT_MV_KBOARD); | m_input_usage |= (1 << IPT_MV_KBOARD); | ||||
@@ -804,7 +805,7 @@ void MeshViewer::Update(float seconds) | |||||
//-- | //-- | ||||
//Message Service | //Message Service | ||||
//-- | //-- | ||||
String mesh(""); | |||||
std::string mesh; | |||||
int u = 1; | int u = 1; | ||||
while (u-- > 0 && MessageService::FetchFirst(MessageBucket::AppIn, mesh)) | while (u-- > 0 && MessageService::FetchFirst(MessageBucket::AppIn, mesh)) | ||||
{ | { | ||||
@@ -812,7 +813,7 @@ void MeshViewer::Update(float seconds) | |||||
while (o-- > 0) | while (o-- > 0) | ||||
{ | { | ||||
SceneSetup* new_ssetup = new SceneSetup(); | SceneSetup* new_ssetup = new SceneSetup(); | ||||
if (false) //new_ssetup->Compile(mesh.C()) && new_ssetup->m_lights.count()) | |||||
if (false) //new_ssetup->Compile(mesh.c_str()) && new_ssetup->m_lights.count()) | |||||
{ | { | ||||
//Store current light datas, in World | //Store current light datas, in World | ||||
array<LightData> light_datas; | array<LightData> light_datas; | ||||
@@ -866,7 +867,7 @@ void MeshViewer::Update(float seconds) | |||||
{ | { | ||||
//Create a new mesh | //Create a new mesh | ||||
EasyMesh* em = new EasyMesh(); | EasyMesh* em = new EasyMesh(); | ||||
if (em->Compile(m_ssetup->m_custom_cmd[i].m2.C(), false)) | |||||
if (em->Compile(m_ssetup->m_custom_cmd[i].m2.c_str(), false)) | |||||
{ | { | ||||
em->BD()->Cmdi() = 0; | em->BD()->Cmdi() = 0; | ||||
if (m_mesh_id == m_meshes.count() - 1) | if (m_mesh_id == m_meshes.count() - 1) | ||||
@@ -906,8 +907,8 @@ void MeshViewer::Update(float seconds) | |||||
m_stream_update_time = 0.f; | m_stream_update_time = 0.f; | ||||
File f; | File f; | ||||
f.Open(m_file_name.C(), FileAccess::Read); | |||||
String cmd = f.ReadString(); | |||||
f.Open(m_file_name.c_str(), FileAccess::Read); | |||||
std::string cmd = f.ReadString().C(); | |||||
f.Close(); | f.Close(); | ||||
if (cmd.count() | if (cmd.count() | ||||
@@ -2,6 +2,7 @@ | |||||
// Lol Engine — EasyMesh tutorial | // Lol Engine — EasyMesh tutorial | ||||
// | // | ||||
// Copyright © 2009—2015 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | // Copyright © 2009—2015 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 | // Lol Engine is free software. It comes without any warranty, to | ||||
// the extent permitted by applicable law. You can redistribute it | // the extent permitted by applicable law. You can redistribute it | ||||
@@ -12,6 +13,8 @@ | |||||
#pragma once | #pragma once | ||||
#include <string> | |||||
namespace lol | namespace lol | ||||
{ | { | ||||
@@ -90,7 +93,7 @@ struct MeshViewerKeyInputBase : public StructSafeEnum | |||||
MAX = MSE_END, | MAX = MSE_END, | ||||
}; | }; | ||||
protected: | protected: | ||||
virtual bool BuildEnumMap(map<int64_t, String>& enum_map) | |||||
virtual bool BuildEnumMap(map<int64_t, std::string>& enum_map) | |||||
{ | { | ||||
enum_map[Exit] = g_name_key_Escape; | enum_map[Exit] = g_name_key_Escape; | ||||
@@ -133,14 +136,14 @@ class ViewerObject | |||||
{ | { | ||||
public: | public: | ||||
ViewerObject() { } | ViewerObject() { } | ||||
ViewerObject(String const& name) : m_name(name) { } | |||||
ViewerObject(std::string const& name) : m_name(name) { } | |||||
virtual ~ViewerObject() { } | virtual ~ViewerObject() { } | ||||
virtual void TickDraw(float seconds, Scene &scene) { } | virtual void TickDraw(float seconds, Scene &scene) { } | ||||
String GetName() { return m_name; } | |||||
std::string GetName() { return m_name; } | |||||
protected: | protected: | ||||
String m_name; | |||||
std::string m_name; | |||||
}; | }; | ||||
//EasyMeshViewerObject -------------------------------------------------------- | //EasyMeshViewerObject -------------------------------------------------------- | ||||
@@ -151,7 +154,7 @@ class EasyMeshViewerObject : public ViewerObject | |||||
public: | public: | ||||
EasyMeshViewerObject() | EasyMeshViewerObject() | ||||
: ViewerObject() { } | : ViewerObject() { } | ||||
EasyMeshViewerObject(String const& name, EasyMesh const& mesh) | |||||
EasyMeshViewerObject(std::string const& name, EasyMesh const& mesh) | |||||
: ViewerObject(name) | : ViewerObject(name) | ||||
{ | { | ||||
Init(name, mesh); | Init(name, mesh); | ||||
@@ -160,7 +163,7 @@ public: | |||||
virtual void TickDraw(float seconds, Scene &scene); | virtual void TickDraw(float seconds, Scene &scene); | ||||
void Init(String const& name, EasyMesh const& mesh) | |||||
void Init(std::string const& name, EasyMesh const& mesh) | |||||
{ | { | ||||
m_name = name; | m_name = name; | ||||
m_mesh = mesh; | m_mesh = mesh; | ||||
@@ -178,7 +181,7 @@ class MeshViewerLoadJob : public ThreadJob | |||||
public: | public: | ||||
inline MeshViewerLoadJob() : ThreadJob() { } | inline MeshViewerLoadJob() : ThreadJob() { } | ||||
inline MeshViewerLoadJob(String const& path) | |||||
inline MeshViewerLoadJob(std::string const& path) | |||||
: ThreadJob(ThreadJobType::WORK_TODO), m_path(path) { } | : ThreadJob(ThreadJobType::WORK_TODO), m_path(path) { } | ||||
virtual ~MeshViewerLoadJob() { } | virtual ~MeshViewerLoadJob() { } | ||||
@@ -188,7 +191,7 @@ protected: | |||||
virtual bool DoWork() { return super::DoWork(); } | virtual bool DoWork() { return super::DoWork(); } | ||||
protected: | protected: | ||||
String m_path; | |||||
std::string m_path; | |||||
}; | }; | ||||
//EasyMeshLoadJob ------------------------------------------------------------- | //EasyMeshLoadJob ------------------------------------------------------------- | ||||
@@ -199,15 +202,15 @@ class EasyMeshLoadJob : public MeshViewerLoadJob | |||||
public: | public: | ||||
inline EasyMeshLoadJob() : MeshViewerLoadJob() { } | inline EasyMeshLoadJob() : MeshViewerLoadJob() { } | ||||
inline EasyMeshLoadJob(String const& path) | |||||
inline EasyMeshLoadJob(std::string const& path) | |||||
: MeshViewerLoadJob(path) { } | : MeshViewerLoadJob(path) { } | ||||
virtual ~EasyMeshLoadJob() { } | virtual ~EasyMeshLoadJob() { } | ||||
static MeshViewerLoadJob* GetInstance(String const& path); | |||||
static MeshViewerLoadJob* GetInstance(std::string const& path); | |||||
virtual void RetrieveResult(class MeshViewer* app); | virtual void RetrieveResult(class MeshViewer* app); | ||||
protected: | protected: | ||||
static bool Check(String const& path) { return path.contains(".easymesh"); } | |||||
static bool Check(std::string const& path) { return path.find(".easymesh") != std::string::npos; } | |||||
virtual bool DoWork(); | virtual bool DoWork(); | ||||
protected: | protected: | ||||
@@ -228,7 +231,7 @@ public: | |||||
void UpdateSceneSetup(bool only_destroy = false); | void UpdateSceneSetup(bool only_destroy = false); | ||||
MeshViewerLoadJob* GetLoadJob(String const& path); | |||||
MeshViewerLoadJob* GetLoadJob(std::string const& path); | |||||
void AddViewerObj(ViewerObject* obj) { m_objs << obj; } | void AddViewerObj(ViewerObject* obj) { m_objs << obj; } | ||||
virtual void TickGame(float seconds); | virtual void TickGame(float seconds); | ||||
@@ -260,18 +263,18 @@ private: | |||||
float m_menu_cam_fov = radians(40.f); | float m_menu_cam_fov = radians(40.f); | ||||
vec3 m_menu_cam_pos = vec3(20.f, 45.f, 45.f); | vec3 m_menu_cam_pos = vec3(20.f, 45.f, 45.f); | ||||
int m_menu_mesh_idx = 0; | int m_menu_mesh_idx = 0; | ||||
array<char*> m_menu_mesh_names_char; | |||||
array<String> m_menu_mesh_names_str; | |||||
array<char const *> m_menu_mesh_names_char; | |||||
array<std::string> m_menu_mesh_names_str; | |||||
//Scene setup data | //Scene setup data | ||||
SceneSetupLuaLoader m_ssetup_loader; | |||||
FileUpdateStatus* m_ssetup_file_status = nullptr; | |||||
String m_ssetup_file_name; | |||||
String m_ssetup_name; | |||||
map<String, SceneSetup*> m_ssetups; | |||||
SceneSetupLuaLoader m_ssetup_loader; | |||||
FileUpdateStatus *m_ssetup_file_status = nullptr; | |||||
std::string m_ssetup_file_name; | |||||
std::string m_ssetup_name; | |||||
map<std::string, SceneSetup*> m_ssetups; | |||||
//File data | //File data | ||||
String m_file_name; | |||||
std::string m_file_name; | |||||
FileUpdateStatus* m_file_status; | FileUpdateStatus* m_file_status; | ||||
//Object data | //Object data | ||||
@@ -288,47 +291,47 @@ private: | |||||
DefaultThreadManager* m_file_loader = nullptr; | DefaultThreadManager* m_file_loader = nullptr; | ||||
//OLD --------------------------------------------------------------------- | //OLD --------------------------------------------------------------------- | ||||
SceneSetup* m_ssetup = nullptr; | |||||
array<LightData> m_light_datas; | |||||
short m_input_usage; | |||||
mat4 m_mat; | |||||
mat4 m_mat_prev; | |||||
SceneSetup *m_ssetup = nullptr; | |||||
array<LightData> m_light_datas; | |||||
short m_input_usage; | |||||
mat4 m_mat; | |||||
mat4 m_mat_prev; | |||||
//Camera Setup | //Camera Setup | ||||
float m_reset_timer; | |||||
float m_fov; | |||||
float m_fov_mesh; | |||||
float m_fov_speed; | |||||
float m_zoom; | |||||
float m_zoom_mesh; | |||||
float m_zoom_speed; | |||||
vec2 m_rot; | |||||
vec2 m_rot_mesh; | |||||
vec2 m_rot_speed; | |||||
vec2 m_pos; | |||||
vec2 m_pos_mesh; | |||||
vec2 m_pos_speed; | |||||
vec2 m_hist_scale; | |||||
vec2 m_hist_scale_mesh; | |||||
vec2 m_hist_scale_speed; | |||||
vec2 m_screen_offset; | |||||
float m_reset_timer; | |||||
float m_fov; | |||||
float m_fov_mesh; | |||||
float m_fov_speed; | |||||
float m_zoom; | |||||
float m_zoom_mesh; | |||||
float m_zoom_speed; | |||||
vec2 m_rot; | |||||
vec2 m_rot_mesh; | |||||
vec2 m_rot_speed; | |||||
vec2 m_pos; | |||||
vec2 m_pos_mesh; | |||||
vec2 m_pos_speed; | |||||
vec2 m_hist_scale; | |||||
vec2 m_hist_scale_mesh; | |||||
vec2 m_hist_scale_speed; | |||||
vec2 m_screen_offset; | |||||
//Mesh update timer | //Mesh update timer | ||||
float m_build_timer; | |||||
float m_build_time; | |||||
float m_build_timer; | |||||
float m_build_time; | |||||
//Mesh infos | //Mesh infos | ||||
vec2 m_render_max; | |||||
int m_mesh_render; | |||||
int m_mesh_id; | |||||
float m_mesh_id1; | |||||
vec2 m_render_max; | |||||
int m_mesh_render; | |||||
int m_mesh_id; | |||||
float m_mesh_id1; | |||||
array<EasyMesh*, EasyMesh*> m_meshes; | array<EasyMesh*, EasyMesh*> m_meshes; | ||||
array<EasyMesh*> m_gizmos; | |||||
array<EasyMesh*> m_gizmos; | |||||
//File data | //File data | ||||
array<String> m_cmdlist; | |||||
float m_stream_update_time; | |||||
float m_stream_update_timer; | |||||
array<std::string> m_cmdlist; | |||||
float m_stream_update_time; | |||||
float m_stream_update_timer; | |||||
//misc datas | //misc datas | ||||
Shader * m_texture_shader; | Shader * m_texture_shader; | ||||
@@ -1,12 +1,14 @@ | |||||
// | // | ||||
// Lol Engine | |||||
// Lol Engine — Mesh viewer | |||||
// | // | ||||
// Copyright: (c) 2013 Benjamin "Touky" Huet <huet.benjamin@gmail.com> | |||||
// 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 © 2003—2015 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | |||||
// © 2013—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 | ||||
@@ -16,6 +18,8 @@ | |||||
#include <lol/engine.h> | #include <lol/engine.h> | ||||
#include <lol/lua.h> | #include <lol/lua.h> | ||||
#include <string> | |||||
#include "scenesetup.h" | #include "scenesetup.h" | ||||
namespace lol | namespace lol | ||||
@@ -23,7 +27,7 @@ namespace lol | |||||
//----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||||
//CTor/DTor | //CTor/DTor | ||||
SceneSetup::SceneSetup(String const& name) | |||||
SceneSetup::SceneSetup(std::string const& name) | |||||
{ | { | ||||
m_name = name; | m_name = name; | ||||
m_clear_color = vec4(vec3::zero, 1.f); | m_clear_color = vec4(vec3::zero, 1.f); | ||||
@@ -147,7 +151,7 @@ void SceneSetup::Set(SceneSetup::Display const& d, DisplayFlag const& f) | |||||
} | } | ||||
//----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||||
SceneSetupLuaObject::SceneSetupLuaObject(String& name) : LuaObject() | |||||
SceneSetupLuaObject::SceneSetupLuaObject(std::string const& name) : LuaObject() | |||||
{ | { | ||||
m_setup = new SceneSetup(name); | m_setup = new SceneSetup(name); | ||||
SceneSetupLuaLoader::RegisterSetup(m_setup); | SceneSetupLuaLoader::RegisterSetup(m_setup); | ||||
@@ -163,7 +167,7 @@ SceneSetupLuaObject* SceneSetupLuaObject::New(lua_State* l, int arg_nb) | |||||
{ | { | ||||
UNUSED(arg_nb); | UNUSED(arg_nb); | ||||
auto s = LuaStack::Begin(l); | auto s = LuaStack::Begin(l); | ||||
auto n = s.Get<String>(); | |||||
auto n = s.Get<std::string>(); | |||||
return new SceneSetupLuaObject(n); | return new SceneSetupLuaObject(n); | ||||
} | } | ||||
@@ -172,8 +176,8 @@ int SceneSetupLuaObject::AddLight(lua_State* l) | |||||
{ | { | ||||
auto s = LuaStack::Begin(l); | auto s = LuaStack::Begin(l); | ||||
auto o = s.GetPtr<SceneSetupLuaObject>(); | auto o = s.GetPtr<SceneSetupLuaObject>(); | ||||
auto t = s.Get<String>(); | |||||
o->m_setup->AddLight(FindValue<LightType>(t.C())); | |||||
auto t = s.Get<std::string>(); | |||||
o->m_setup->AddLight(FindValue<LightType>(t)); | |||||
return s.End(); | return s.End(); | ||||
} | } | ||||
int SceneSetupLuaObject::SetupScene(lua_State* l) | int SceneSetupLuaObject::SetupScene(lua_State* l) | ||||
@@ -260,7 +264,7 @@ const LuaObjectLibrary* SceneSetupLuaObject::GetLib() | |||||
} | } | ||||
//----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||||
map<String, SceneSetup*> SceneSetupLuaLoader::m_setups; | |||||
map<std::string, SceneSetup*> SceneSetupLuaLoader::m_setups; | |||||
SceneSetupLuaLoader::SceneSetupLuaLoader() : LuaLoader() | SceneSetupLuaLoader::SceneSetupLuaLoader() : LuaLoader() | ||||
{ | { | ||||
lua_State* l = GetLuaState(); | lua_State* l = GetLuaState(); | ||||
@@ -292,14 +296,14 @@ void SceneSetupLuaLoader::RegisterSetup(SceneSetup* setup) | |||||
} | } | ||||
//----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||||
bool SceneSetupLuaLoader::GetRegisteredSetups(map<String, SceneSetup*>& setups) | |||||
bool SceneSetupLuaLoader::GetRegisteredSetups(map<std::string, SceneSetup*>& setups) | |||||
{ | { | ||||
setups = m_setups; | setups = m_setups; | ||||
return !!m_setups.count(); | return !!m_setups.count(); | ||||
} | } | ||||
//----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||||
bool SceneSetupLuaLoader::GetLoadedSetups(map<String, SceneSetup*>& setups) | |||||
bool SceneSetupLuaLoader::GetLoadedSetups(map<std::string, SceneSetup*>& setups) | |||||
{ | { | ||||
return GetRegisteredSetups(setups); | return GetRegisteredSetups(setups); | ||||
} | } | ||||
@@ -1,12 +1,14 @@ | |||||
// | // | ||||
// Lol Engine | |||||
// Lol Engine — Mesh viewer | |||||
// | // | ||||
// Copyright: (c) 2013 Benjamin "Touky" Huet <huet.benjamin@gmail.com> | |||||
// (c) 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 © 2003—2015 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | |||||
// © 2013—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 | ||||
@@ -16,6 +18,8 @@ | |||||
// ---------------- | // ---------------- | ||||
// | // | ||||
#include <string> | |||||
namespace lol | namespace lol | ||||
{ | { | ||||
@@ -28,7 +32,7 @@ class SceneSetup | |||||
public: | public: | ||||
//CTor/DTor | //CTor/DTor | ||||
SceneSetup() : SceneSetup("default") { } | SceneSetup() : SceneSetup("default") { } | ||||
SceneSetup(String const& name); | |||||
SceneSetup(std::string const& name); | |||||
~SceneSetup(); | ~SceneSetup(); | ||||
static char const *GetName() { return "<scenesetup>"; } | static char const *GetName() { return "<scenesetup>"; } | ||||
@@ -57,7 +61,7 @@ public: | |||||
Max | Max | ||||
}; | }; | ||||
protected: | protected: | ||||
virtual bool BuildEnumMap(map<int64_t, String>& enum_map) | |||||
virtual bool BuildEnumMap(map<int64_t, std::string>& enum_map) | |||||
{ | { | ||||
enum_map[Gizmo] = "Gizmo"; | enum_map[Gizmo] = "Gizmo"; | ||||
enum_map[Light] = "Light"; | enum_map[Light] = "Light"; | ||||
@@ -84,7 +88,7 @@ protected: | |||||
Max | Max | ||||
}; | }; | ||||
protected: | protected: | ||||
virtual bool BuildEnumMap(map<int64_t, String>& enum_map) | |||||
virtual bool BuildEnumMap(map<int64_t, std::string>& enum_map) | |||||
{ | { | ||||
enum_map[AddLight] = "AddLight"; | enum_map[AddLight] = "AddLight"; | ||||
enum_map[SetupScene] = "SetupScene"; | enum_map[SetupScene] = "SetupScene"; | ||||
@@ -95,13 +99,13 @@ protected: | |||||
public: | public: | ||||
//-- | //-- | ||||
String m_name; | |||||
Command m_last_cmd; | |||||
vec4 m_clear_color; | |||||
array<Light *> m_lights; | |||||
array<String, String> m_custom_cmd; | |||||
bool m_show_gizmo; | |||||
bool m_show_lights; | |||||
std::string m_name; | |||||
Command m_last_cmd; | |||||
vec4 m_clear_color; | |||||
array<Light *> m_lights; | |||||
array<std::string, std::string> m_custom_cmd; | |||||
bool m_show_gizmo; | |||||
bool m_show_lights; | |||||
}; | }; | ||||
//----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||||
@@ -109,7 +113,7 @@ class SceneSetupLuaObject : public LuaObject | |||||
{ | { | ||||
public: | public: | ||||
//------------------------------------------------------------------------- | //------------------------------------------------------------------------- | ||||
SceneSetupLuaObject(String& name); | |||||
SceneSetupLuaObject(std::string const& name); | |||||
virtual ~SceneSetupLuaObject(); | virtual ~SceneSetupLuaObject(); | ||||
//------------------------------------------------------------------------- | //------------------------------------------------------------------------- | ||||
@@ -159,12 +163,12 @@ public: | |||||
//------------------------------------------------------------------------- | //------------------------------------------------------------------------- | ||||
protected: | protected: | ||||
static void RegisterSetup(SceneSetup* setup); | static void RegisterSetup(SceneSetup* setup); | ||||
static bool GetRegisteredSetups(map<String, SceneSetup*>& setups); | |||||
static bool GetRegisteredSetups(map<std::string, SceneSetup*>& setups); | |||||
public: | public: | ||||
bool GetLoadedSetups(map<String, SceneSetup*>& setups); | |||||
bool GetLoadedSetups(map<std::string, SceneSetup*>& setups); | |||||
private: | private: | ||||
static map<String, SceneSetup*> m_setups; | |||||
static map<std::string, SceneSetup*> m_setups; | |||||
}; | }; | ||||
/* | /* | ||||
@@ -1,7 +1,8 @@ | |||||
// | // | ||||
// Lol Engine — Shader builder tutorial | // Lol Engine — Shader builder tutorial | ||||
// | // | ||||
// Copyright © 2012—2015 Sam Hocevar <sam@hocevar.net> | |||||
// Copyright © 2002—2015 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 | // 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 | ||||
@@ -16,12 +17,12 @@ | |||||
#include <lol/engine.h> | #include <lol/engine.h> | ||||
#include "loldebug.h" | #include "loldebug.h" | ||||
#include <cstdio> | #include <cstdio> | ||||
#include <string> | |||||
using namespace lol; | using namespace lol; | ||||
#define Line(x) ((x) + "\n") | |||||
class ShaderBuilderDemo : public WorldEntity | class ShaderBuilderDemo : public WorldEntity | ||||
{ | { | ||||
public: | public: | ||||
@@ -41,7 +42,7 @@ public: | |||||
File file; | File file; | ||||
file.Open("13_shader_builder_export.txt", FileAccess::Write); | file.Open("13_shader_builder_export.txt", FileAccess::Write); | ||||
//file.Open("13_shader_builder_export.txt", FileAccess::Read); | //file.Open("13_shader_builder_export.txt", FileAccess::Read); | ||||
String code; | |||||
std::string code; | |||||
ShaderBuilder builder("red_blue_green", "120"); | ShaderBuilder builder("red_blue_green", "120"); | ||||
ShaderBlock nothing_vertex("NothingVertex"); | ShaderBlock nothing_vertex("NothingVertex"); | ||||
@@ -60,9 +61,9 @@ public: | |||||
<< in_color | << in_color | ||||
<< pass_color; | << pass_color; | ||||
nothing_vertex.AddVar(out_vertex); | nothing_vertex.AddVar(out_vertex); | ||||
nothing_vertex.SetMainCode(String() + | |||||
Line(pass_color + " = " + in_color + ";") + | |||||
Line(out_vertex + " = vec4(" + in_position + ", 0.f);") | |||||
nothing_vertex.SetMainCode( | |||||
pass_color.tostring() + " = " + in_color.tostring() + ";\n" + | |||||
out_vertex.tostring() + " = vec4(" + in_position.tostring() + ", 0.f);\n" | |||||
); | ); | ||||
ShaderVar ambient = ShaderVar(ShaderVariable::InOut, ShaderVariableType::Vec4, "ambient"); | ShaderVar ambient = ShaderVar(ShaderVariable::InOut, ShaderVariableType::Vec4, "ambient"); | ||||
@@ -70,34 +71,34 @@ public: | |||||
red_pixel.AddVar(pass_color); | red_pixel.AddVar(pass_color); | ||||
red_pixel.AddVar(out_pixel); | red_pixel.AddVar(out_pixel); | ||||
red_pixel.AddVar(ambient); | red_pixel.AddVar(ambient); | ||||
red_pixel.SetMainCode(String() + | |||||
out_pixel + " = " + pass_color + ";\n" + | |||||
out_pixel + ".r = 1.0;\n" + | |||||
red_pixel.SetMainCode( | |||||
out_pixel.tostring() + " = " + pass_color.tostring() + ";\n" + | |||||
out_pixel.tostring() + ".r = 1.0;\n" | |||||
"ambient = vec4(1.0);\n" | "ambient = vec4(1.0);\n" | ||||
); | ); | ||||
green_pixel.AddVar(pass_color); | green_pixel.AddVar(pass_color); | ||||
green_pixel.AddVar(out_pixel); | green_pixel.AddVar(out_pixel); | ||||
green_pixel.AddVar(ambient); | green_pixel.AddVar(ambient); | ||||
green_pixel.SetMainCode(String() + | |||||
out_pixel + " = " + pass_color + ";\n" + | |||||
out_pixel + ".g = 1.0;\n" + | |||||
green_pixel.SetMainCode( | |||||
out_pixel.tostring() + " = " + pass_color.tostring() + ";\n" + | |||||
out_pixel.tostring() + ".g = 1.0;\n" | |||||
"ambient.r = 0.0;\n" | "ambient.r = 0.0;\n" | ||||
); | ); | ||||
blue_pixel.AddVar(pass_color); | blue_pixel.AddVar(pass_color); | ||||
blue_pixel.AddVar(out_pixel); | blue_pixel.AddVar(out_pixel); | ||||
blue_pixel.AddVar(ambient); | blue_pixel.AddVar(ambient); | ||||
blue_pixel.SetCustomCode(String() + | |||||
"void SetAmbient(inout vec4 ambient)\n" + | |||||
"{\n" + | |||||
" ambient = vec4(1.0, 1.0, 1.0, 1.0);\n" + | |||||
blue_pixel.SetCustomCode( | |||||
"void SetAmbient(inout vec4 ambient)\n" | |||||
"{\n" | |||||
" ambient = vec4(1.0, 1.0, 1.0, 1.0);\n" | |||||
"}\n"); | "}\n"); | ||||
blue_pixel.SetMainCode(String() + | |||||
out_pixel + " = " + pass_color + ";\n" + | |||||
out_pixel + ".b = 1.0;\n" + | |||||
blue_pixel.SetMainCode( | |||||
out_pixel.tostring() + " = " + pass_color.tostring() + ";\n" + | |||||
out_pixel.tostring() + ".b = 1.0;\n" | |||||
"SetAmbient(ambient);\n" + | "SetAmbient(ambient);\n" + | ||||
out_pixel + " *= ambient;\n" | |||||
out_pixel.tostring() + " *= ambient;\n" | |||||
); | ); | ||||
builder << ShaderProgram::Vertex | builder << ShaderProgram::Vertex | ||||
@@ -109,7 +110,7 @@ public: | |||||
builder.Build(code); | builder.Build(code); | ||||
file.WriteString(code); | |||||
file.WriteString(code.c_str()); | |||||
//code = file.ReadString(); | //code = file.ReadString(); | ||||
file.Close(); | file.Close(); | ||||
@@ -1,7 +1,8 @@ | |||||
// | // | ||||
// Lol Engine — Shader builder tutorial | |||||
// Lol Engine — Imgui tutorial | |||||
// | // | ||||
// Copyright © 2012—2015 Sam Hocevar <sam@hocevar.net> | |||||
// Copyright © 2002—2015 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 | // 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 | ||||
@@ -15,8 +16,11 @@ | |||||
#endif | #endif | ||||
#include <lol/engine.h> | #include <lol/engine.h> | ||||
#include "loldebug.h" | |||||
#include <cstdio> | #include <cstdio> | ||||
#include <string> | |||||
#include "loldebug.h" | |||||
using namespace lol; | using namespace lol; | ||||
@@ -64,7 +68,7 @@ public: | |||||
ImGui::Text("Scroll: %f", io.MouseWheel); | ImGui::Text("Scroll: %f", io.MouseWheel); | ||||
ImGui::Text("Maj: %s", io.KeyShift ? "true" : "false"); | ImGui::Text("Maj: %s", io.KeyShift ? "true" : "false"); | ||||
ImGui::Text("Ctrl: %s", io.KeyCtrl ? "true" : "false"); | ImGui::Text("Ctrl: %s", io.KeyCtrl ? "true" : "false"); | ||||
ImGui::Text("Clipboard %s", LolImGui::GetClipboard().C()); | |||||
ImGui::Text("Clipboard %s", LolImGui::GetClipboard().c_str()); | |||||
ImGui::InputText("base input", buf, 512); | ImGui::InputText("base input", buf, 512); | ||||
} | } | ||||
ImGui::End(); | ImGui::End(); | ||||
@@ -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 | ||||
@@ -13,6 +13,7 @@ | |||||
#include <lol/engine-internal.h> | #include <lol/engine-internal.h> | ||||
#include <cstdio> | #include <cstdio> | ||||
#include <string> | |||||
#if defined(_WIN32) | #if defined(_WIN32) | ||||
# define WIN32_LEAN_AND_MEAN | # define WIN32_LEAN_AND_MEAN | ||||
@@ -21,6 +22,7 @@ | |||||
#endif | #endif | ||||
#include <cstdarg> | #include <cstdarg> | ||||
#include <cctype> | |||||
namespace lol | namespace lol | ||||
{ | { | ||||
@@ -54,6 +56,34 @@ array<std::string> split(std::string const &s, std::string const &seps) | |||||
return ret; | return ret; | ||||
} | } | ||||
bool starts_with(std::string const &s, std::string const &prefix) | |||||
{ | |||||
return s.size() >= prefix.size() && | |||||
s.compare(0, prefix.size(), prefix) == 0; | |||||
} | |||||
bool ends_with(std::string const &s, std::string const &suffix) | |||||
{ | |||||
return s.size() >= suffix.size() && | |||||
s.compare(s.size() - suffix.size(), suffix.size(), suffix) == 0; | |||||
} | |||||
std::string tolower(std::string const &s) | |||||
{ | |||||
std::string ret; | |||||
std::transform(s.begin(), s.end(), std::back_inserter(ret), | |||||
[](unsigned char c){ return std::tolower(c); }); | |||||
return ret; | |||||
} | |||||
std::string toupper(std::string const &s) | |||||
{ | |||||
std::string ret; | |||||
std::transform(s.begin(), s.end(), std::back_inserter(ret), | |||||
[](unsigned char c){ return std::toupper(c); }); | |||||
return ret; | |||||
} | |||||
std::string format(char const *format, ...) | std::string format(char const *format, ...) | ||||
{ | { | ||||
va_list ap; | va_list ap; | ||||
@@ -2,6 +2,7 @@ | |||||
// Lol Engine — EasyMesh Lua loader | // Lol Engine — EasyMesh Lua loader | ||||
// | // | ||||
// Copyright © 2009—2015 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | // Copyright © 2009—2015 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 | ||||
@@ -14,10 +15,12 @@ | |||||
# include "config.h" | # include "config.h" | ||||
#endif | #endif | ||||
#include <cstdio> | |||||
#include <lol/engine.h> | #include <lol/engine.h> | ||||
#include <lol/lua.h> | #include <lol/lua.h> | ||||
#include <cstdio> | |||||
#include <string> | |||||
#include "loldebug.h" | #include "loldebug.h" | ||||
using namespace lol; | using namespace lol; | ||||
@@ -52,23 +55,23 @@ array<EasyMeshLuaObject*>& EasyMeshLuaLoader::GetInstances() | |||||
} | } | ||||
//----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||||
map<String, EasyMeshLuaObject*> EasyMeshLuaLoader::m_meshes; | |||||
void EasyMeshLuaLoader::RegisterMesh(EasyMeshLuaObject* mesh, String const& name) | |||||
map<std::string, EasyMeshLuaObject*> EasyMeshLuaLoader::m_meshes; | |||||
void EasyMeshLuaLoader::RegisterMesh(EasyMeshLuaObject* mesh, std::string const& name) | |||||
{ | { | ||||
m_meshes[name] = mesh; | m_meshes[name] = mesh; | ||||
} | } | ||||
//----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||||
bool EasyMeshLuaLoader::GetRegisteredMeshes(map<String, EasyMeshLuaObject*>& meshes) | |||||
bool EasyMeshLuaLoader::GetRegisteredMeshes(map<std::string, EasyMeshLuaObject*>& meshes) | |||||
{ | { | ||||
meshes = m_meshes; | meshes = m_meshes; | ||||
return !!m_meshes.count(); | |||||
return m_meshes.count() > 0; | |||||
} | } | ||||
//----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||||
EasyMeshLuaObject::EasyMeshLuaObject(String const& name) : LuaObject() | |||||
EasyMeshLuaObject::EasyMeshLuaObject(std::string const& name) : LuaObject() | |||||
{ | { | ||||
if (!!name.count()) | |||||
if (name.length() > 0) | |||||
EasyMeshLuaLoader::RegisterMesh(this, name); | EasyMeshLuaLoader::RegisterMesh(this, name); | ||||
} | } | ||||
@@ -83,7 +86,7 @@ EasyMeshLuaObject* EasyMeshLuaObject::New(lua_State* l, int arg_nb) | |||||
UNUSED(l); | UNUSED(l); | ||||
UNUSED(arg_nb); | UNUSED(arg_nb); | ||||
LuaStack s = LuaStack::Begin(l); | LuaStack s = LuaStack::Begin(l); | ||||
String str = s.Get<String>(""); | |||||
std::string str = s.Get<std::string>(""); | |||||
return new EasyMeshLuaObject(str); | return new EasyMeshLuaObject(str); | ||||
} | } | ||||
@@ -2,6 +2,7 @@ | |||||
// Lol Engine — EasyMesh Lua loader | // Lol Engine — EasyMesh Lua loader | ||||
// | // | ||||
// Copyright © 2009—2015 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | // Copyright © 2009—2015 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 | ||||
@@ -12,6 +13,8 @@ | |||||
#pragma once | #pragma once | ||||
#include <string> | |||||
namespace lol | namespace lol | ||||
{ | { | ||||
@@ -21,7 +24,7 @@ class EasyMeshLuaObject : public LuaObject | |||||
EasyMesh m_instance; | EasyMesh m_instance; | ||||
public: | public: | ||||
//------------------------------------------------------------------------- | //------------------------------------------------------------------------- | ||||
EasyMeshLuaObject(String const& name); | |||||
EasyMeshLuaObject(std::string const& name); | |||||
virtual ~EasyMeshLuaObject(); | virtual ~EasyMeshLuaObject(); | ||||
EasyMesh& GetMesh() { return m_instance; } | EasyMesh& GetMesh() { return m_instance; } | ||||
@@ -137,12 +140,12 @@ public: | |||||
//------------------------------------------------------------------------- | //------------------------------------------------------------------------- | ||||
protected: | protected: | ||||
static void RegisterMesh(EasyMeshLuaObject* mesh, String const& name); | |||||
static void RegisterMesh(EasyMeshLuaObject* mesh, std::string const& name); | |||||
public: | public: | ||||
static bool GetRegisteredMeshes(map<String, EasyMeshLuaObject*>& meshes); | |||||
static bool GetRegisteredMeshes(map<std::string, EasyMeshLuaObject*>& meshes); | |||||
private: | private: | ||||
static map<String, EasyMeshLuaObject*> m_meshes; | |||||
static map<std::string, EasyMeshLuaObject*> m_meshes; | |||||
}; | }; | ||||
} /* namespace lol */ | } /* namespace lol */ |
@@ -1,7 +1,7 @@ | |||||
// | // | ||||
// Lol Engine | // Lol Engine | ||||
// | // | ||||
// Copyright © 2010—2017 Sam Hocevar <sam@hocevar.net> | |||||
// Copyright © 2010—2018 Sam Hocevar <sam@hocevar.net> | |||||
// | // | ||||
// Lol Engine is free software. It comes without any warranty, to | // Lol Engine is free software. It comes without any warranty, to | ||||
// the extent permitted by applicable law. You can redistribute it | // the extent permitted by applicable law. You can redistribute it | ||||
@@ -12,6 +12,7 @@ | |||||
#include <lol/engine-internal.h> | #include <lol/engine-internal.h> | ||||
#include <string> | |||||
#include <cstring> | #include <cstring> | ||||
#include <cstdio> | #include <cstdio> | ||||
@@ -76,7 +77,7 @@ class ShaderData | |||||
friend class Shader; | friend class Shader; | ||||
private: | private: | ||||
String m_name; | |||||
std::string m_name; | |||||
GLuint prog_id, vert_id, frag_id; | GLuint prog_id, vert_id, frag_id; | ||||
// Benlitz: using a simple array could be faster since there is never more than a few attribute locations to store | // Benlitz: using a simple array could be faster since there is never more than a few attribute locations to store | ||||
@@ -86,7 +87,7 @@ private: | |||||
/* Shader patcher */ | /* Shader patcher */ | ||||
static int GetVersion(); | static int GetVersion(); | ||||
static String Patch(String const &code, ShaderType type); | |||||
static std::string Patch(std::string const &code, ShaderType type); | |||||
/* Global shader cache */ | /* Global shader cache */ | ||||
static Shader *shaders[]; | static Shader *shaders[]; | ||||
@@ -108,8 +109,8 @@ using namespace pegtl; | |||||
struct lolfx_parser | struct lolfx_parser | ||||
{ | { | ||||
public: | public: | ||||
String m_section; | |||||
map<String, String> m_programs; | |||||
std::string m_section; | |||||
map<std::string, std::string> m_programs; | |||||
private: | private: | ||||
// title <- '[' (!']')+ ']' .{eol} | // title <- '[' (!']')+ ']' .{eol} | ||||
@@ -155,10 +156,10 @@ private: | |||||
struct action : nothing<RULE> {}; | struct action : nothing<RULE> {}; | ||||
public: | public: | ||||
lolfx_parser(String const &code) | |||||
lolfx_parser(std::string const &code) | |||||
: m_section("header") | : m_section("header") | ||||
{ | { | ||||
string_input<> in(code.C(), "shader"); | |||||
string_input<> in(code, "shader"); | |||||
pegtl::parse<lolfx, action>(in, this); | pegtl::parse<lolfx, action>(in, this); | ||||
} | } | ||||
}; | }; | ||||
@@ -169,7 +170,7 @@ struct lolfx_parser::action<lolfx_parser::do_title> | |||||
template<typename INPUT> | template<typename INPUT> | ||||
static void apply(INPUT const &in, lolfx_parser *that) | static void apply(INPUT const &in, lolfx_parser *that) | ||||
{ | { | ||||
that->m_section = in.string().c_str(); | |||||
that->m_section = in.string(); | |||||
} | } | ||||
}; | }; | ||||
@@ -179,7 +180,7 @@ struct lolfx_parser::action<lolfx_parser::code_section> | |||||
template<typename INPUT> | template<typename INPUT> | ||||
static void apply(INPUT const &in, lolfx_parser *that) | static void apply(INPUT const &in, lolfx_parser *that) | ||||
{ | { | ||||
that->m_programs[that->m_section] = in.string().c_str(); | |||||
that->m_programs[that->m_section] = in.string(); | |||||
} | } | ||||
}; | }; | ||||
@@ -187,18 +188,18 @@ struct lolfx_parser::action<lolfx_parser::code_section> | |||||
* Public Shader class | * Public Shader class | ||||
*/ | */ | ||||
Shader *Shader::Create(String const &name, String const &code) | |||||
Shader *Shader::Create(std::string const &name, std::string const &code) | |||||
{ | { | ||||
lolfx_parser p(code); | lolfx_parser p(code); | ||||
ASSERT(p.m_programs.has_key("vert.glsl"), | ASSERT(p.m_programs.has_key("vert.glsl"), | ||||
"no vertex shader in %s", name.C()); | |||||
"no vertex shader in %s", name.c_str()); | |||||
ASSERT(p.m_programs.has_key("frag.glsl"), | ASSERT(p.m_programs.has_key("frag.glsl"), | ||||
"no fragment shader in %s", name.C()); | |||||
"no fragment shader in %s", name.c_str()); | |||||
String vert = p.m_programs["vert.glsl"]; | |||||
String frag = p.m_programs["frag.glsl"]; | |||||
std::string vert = p.m_programs["vert.glsl"]; | |||||
std::string frag = p.m_programs["frag.glsl"]; | |||||
uint32_t new_vert_crc = ShaderData::Hash(vert); | uint32_t new_vert_crc = ShaderData::Hash(vert); | ||||
uint32_t new_frag_crc = ShaderData::Hash(frag); | uint32_t new_frag_crc = ShaderData::Hash(frag); | ||||
@@ -225,14 +226,14 @@ void Shader::Destroy(Shader *shader) | |||||
UNUSED(shader); | UNUSED(shader); | ||||
} | } | ||||
Shader::Shader(String const &name, | |||||
String const &vert, String const &frag) | |||||
Shader::Shader(std::string const &name, | |||||
std::string const &vert, std::string const &frag) | |||||
: data(new ShaderData()) | : data(new ShaderData()) | ||||
{ | { | ||||
data->m_name = name; | data->m_name = name; | ||||
char errbuf[4096]; | char errbuf[4096]; | ||||
String shader_code; | |||||
std::string shader_code; | |||||
GLchar const *gl_code; | GLchar const *gl_code; | ||||
GLint status; | GLint status; | ||||
GLsizei len; | GLsizei len; | ||||
@@ -242,7 +243,7 @@ Shader::Shader(String const &name, | |||||
shader_code = ShaderData::Patch(vert, ShaderType::Vertex); | shader_code = ShaderData::Patch(vert, ShaderType::Vertex); | ||||
data->vert_id = glCreateShader(GL_VERTEX_SHADER); | data->vert_id = glCreateShader(GL_VERTEX_SHADER); | ||||
gl_code = shader_code.C(); | |||||
gl_code = shader_code.c_str(); | |||||
glShaderSource(data->vert_id, 1, &gl_code, nullptr); | glShaderSource(data->vert_id, 1, &gl_code, nullptr); | ||||
glCompileShader(data->vert_id); | glCompileShader(data->vert_id); | ||||
@@ -251,13 +252,13 @@ Shader::Shader(String const &name, | |||||
if (status != GL_TRUE) | if (status != GL_TRUE) | ||||
{ | { | ||||
msg::error("failed to compile vertex shader %s: %s\n", | msg::error("failed to compile vertex shader %s: %s\n", | ||||
name.C(), errbuf); | |||||
msg::error("shader source:\n%s\n", shader_code.C()); | |||||
name.c_str(), errbuf); | |||||
msg::error("shader source:\n%s\n", shader_code.c_str()); | |||||
} | } | ||||
else if (len > 16) | else if (len > 16) | ||||
{ | { | ||||
msg::debug("compile log for vertex shader %s: %s\n", name.C(), errbuf); | |||||
msg::debug("shader source:\n%s\n", shader_code.C()); | |||||
msg::debug("compile log for vertex shader %s: %s\n", name.c_str(), errbuf); | |||||
msg::debug("shader source:\n%s\n", shader_code.c_str()); | |||||
} | } | ||||
/* Compile fragment shader */ | /* Compile fragment shader */ | ||||
@@ -265,7 +266,7 @@ Shader::Shader(String const &name, | |||||
shader_code = ShaderData::Patch(frag, ShaderType::Fragment); | shader_code = ShaderData::Patch(frag, ShaderType::Fragment); | ||||
data->frag_id = glCreateShader(GL_FRAGMENT_SHADER); | data->frag_id = glCreateShader(GL_FRAGMENT_SHADER); | ||||
gl_code = shader_code.C(); | |||||
gl_code = shader_code.c_str(); | |||||
glShaderSource(data->frag_id, 1, &gl_code, nullptr); | glShaderSource(data->frag_id, 1, &gl_code, nullptr); | ||||
glCompileShader(data->frag_id); | glCompileShader(data->frag_id); | ||||
@@ -274,14 +275,14 @@ Shader::Shader(String const &name, | |||||
if (status != GL_TRUE) | if (status != GL_TRUE) | ||||
{ | { | ||||
msg::error("failed to compile fragment shader %s: %s\n", | msg::error("failed to compile fragment shader %s: %s\n", | ||||
name.C(), errbuf); | |||||
msg::error("shader source:\n%s\n", shader_code.C()); | |||||
name.c_str(), errbuf); | |||||
msg::error("shader source:\n%s\n", shader_code.c_str()); | |||||
} | } | ||||
else if (len > 16) | else if (len > 16) | ||||
{ | { | ||||
msg::debug("compile log for fragment shader %s: %s\n", | msg::debug("compile log for fragment shader %s: %s\n", | ||||
name.C(), errbuf); | |||||
msg::debug("shader source:\n%s\n", shader_code.C()); | |||||
name.c_str(), errbuf); | |||||
msg::debug("shader source:\n%s\n", shader_code.c_str()); | |||||
} | } | ||||
/* Create program */ | /* Create program */ | ||||
@@ -294,11 +295,11 @@ Shader::Shader(String const &name, | |||||
glGetProgramiv(data->prog_id, GL_LINK_STATUS, &status); | glGetProgramiv(data->prog_id, GL_LINK_STATUS, &status); | ||||
if (status != GL_TRUE) | if (status != GL_TRUE) | ||||
{ | { | ||||
msg::error("failed to link program %s: %s\n", name.C(), errbuf); | |||||
msg::error("failed to link program %s: %s\n", name.c_str(), errbuf); | |||||
} | } | ||||
else if (len > 16) | else if (len > 16) | ||||
{ | { | ||||
msg::debug("link log for program %s: %s\n", name.C(), errbuf); | |||||
msg::debug("link log for program %s: %s\n", name.c_str(), errbuf); | |||||
} | } | ||||
GLint validated; | GLint validated; | ||||
@@ -306,7 +307,7 @@ Shader::Shader(String const &name, | |||||
glGetProgramiv(data->prog_id, GL_VALIDATE_STATUS, &validated); | glGetProgramiv(data->prog_id, GL_VALIDATE_STATUS, &validated); | ||||
if (validated != GL_TRUE) | if (validated != GL_TRUE) | ||||
{ | { | ||||
msg::error("failed to validate program %s\n", name.C()); | |||||
msg::error("failed to validate program %s\n", name.c_str()); | |||||
} | } | ||||
GLint num_attribs; | GLint num_attribs; | ||||
@@ -327,16 +328,16 @@ Shader::Shader(String const &name, | |||||
int attrib_type; | int attrib_type; | ||||
glGetActiveAttrib(data->prog_id, i, max_len, &attrib_len, (GLint*)&attrib_size, (GLenum*)&attrib_type, name_buffer); | glGetActiveAttrib(data->prog_id, i, max_len, &attrib_len, (GLint*)&attrib_size, (GLenum*)&attrib_type, name_buffer); | ||||
String attr_name(name_buffer); | |||||
std::string attr_name(name_buffer); | |||||
int index = -1; | int index = -1; | ||||
VertexUsage usage = VertexUsage::MAX; | VertexUsage usage = VertexUsage::MAX; | ||||
for (int j = 0; j < (int)VertexUsage::MAX; ++j) | for (int j = 0; j < (int)VertexUsage::MAX; ++j) | ||||
{ | { | ||||
if (attr_name.starts_with(attribute_names[j]) || | |||||
attr_name.starts_with(String(attribute_names[j]).to_lower())) | |||||
if (starts_with(attr_name, attribute_names[j]) || | |||||
starts_with(attr_name, tolower(attribute_names[j]))) | |||||
{ | { | ||||
usage = VertexUsage(j); | usage = VertexUsage(j); | ||||
char* idx_ptr = attr_name.C() + strlen(attribute_names[j]); | |||||
char* idx_ptr = &attr_name[0] + strlen(attribute_names[j]); | |||||
index = strtol(idx_ptr, nullptr, 10); | index = strtol(idx_ptr, nullptr, 10); | ||||
break; | break; | ||||
} | } | ||||
@@ -357,7 +358,7 @@ Shader::Shader(String const &name, | |||||
if (data->attrib_locations.has_key(flags)) | if (data->attrib_locations.has_key(flags)) | ||||
{ | { | ||||
msg::error("error while parsing attribute semantics in %s\n", | msg::error("error while parsing attribute semantics in %s\n", | ||||
attr_name.C()); | |||||
attr_name.c_str()); | |||||
} | } | ||||
#endif | #endif | ||||
data->attrib_locations[flags] = location; | data->attrib_locations[flags] = location; | ||||
@@ -386,7 +387,7 @@ ShaderAttrib Shader::GetAttribLocation(VertexUsage usage, int index) const | |||||
if (!data->attrib_errors.has_key(ret.m_flags)) | if (!data->attrib_errors.has_key(ret.m_flags)) | ||||
{ | { | ||||
msg::error("attribute %s not found in shader %s\n", | msg::error("attribute %s not found in shader %s\n", | ||||
usage.ToString().C(), data->m_name.C()); | |||||
usage.tostring().c_str(), data->m_name.c_str()); | |||||
data->attrib_errors[ret.m_flags] = true; | data->attrib_errors[ret.m_flags] = true; | ||||
} | } | ||||
} | } | ||||
@@ -394,9 +395,9 @@ ShaderAttrib Shader::GetAttribLocation(VertexUsage usage, int index) const | |||||
return ret; | return ret; | ||||
} | } | ||||
ShaderUniform Shader::GetUniformLocation(String const& uni) const | |||||
ShaderUniform Shader::GetUniformLocation(std::string const& uni) const | |||||
{ | { | ||||
return GetUniformLocation(uni.C()); | |||||
return GetUniformLocation(uni.c_str()); | |||||
} | } | ||||
ShaderUniform Shader::GetUniformLocation(char const *uni) const | ShaderUniform Shader::GetUniformLocation(char const *uni) const | ||||
{ | { | ||||
@@ -572,16 +573,17 @@ int ShaderData::GetVersion() | |||||
/* | /* | ||||
* Simple shader source patching for old GLSL versions. | * Simple shader source patching for old GLSL versions. | ||||
*/ | */ | ||||
String ShaderData::Patch(String const &code, ShaderType type) | |||||
std::string ShaderData::Patch(std::string const &code, ShaderType type) | |||||
{ | { | ||||
int ver_driver = GetVersion(); | int ver_driver = GetVersion(); | ||||
String patched_code = code; | |||||
std::string patched_code = code; | |||||
if (ver_driver >= 130) | if (ver_driver >= 130) | ||||
return patched_code; | return patched_code; | ||||
/* FIXME: use std::string instead of char * for parsing? */ | |||||
int ver_shader = 110; | int ver_shader = 110; | ||||
char *parser = strstr(patched_code.C(), "#version"); | |||||
char *parser = strstr(&patched_code[0], "#version"); | |||||
if (parser) | if (parser) | ||||
ver_shader = atoi(parser + strlen("#version")); | ver_shader = atoi(parser + strlen("#version")); | ||||
@@ -590,7 +592,7 @@ String ShaderData::Patch(String const &code, ShaderType type) | |||||
{ | { | ||||
/* FIXME: this isn't elegant but honestly, we don't care, this | /* FIXME: this isn't elegant but honestly, we don't care, this | ||||
* whole file is going to die soon. */ | * whole file is going to die soon. */ | ||||
char *p = strstr(patched_code.C(), "#version"); | |||||
char *p = strstr(&patched_code[0], "#version"); | |||||
if (p) | if (p) | ||||
{ | { | ||||
p += 8; | p += 8; | ||||
@@ -603,10 +605,10 @@ String ShaderData::Patch(String const &code, ShaderType type) | |||||
if (ver_shader > 120 && ver_driver <= 120) | if (ver_shader > 120 && ver_driver <= 120) | ||||
{ | { | ||||
char const *end = patched_code.C() + patched_code.count() + 1; | |||||
char const *end = patched_code.c_str() + patched_code.length() + 1; | |||||
/* Find main() */ | /* Find main() */ | ||||
parser = strstr(patched_code.C(), "main"); | |||||
parser = strstr(&patched_code[0], "main"); | |||||
if (!parser) return patched_code; | if (!parser) return patched_code; | ||||
parser = strstr(parser, "("); | parser = strstr(parser, "("); | ||||
if (!parser) return patched_code; | if (!parser) return patched_code; | ||||
@@ -651,7 +653,7 @@ String ShaderData::Patch(String const &code, ShaderType type) | |||||
for (char const * const *rep = main_replaces; rep[0]; rep += 2) | for (char const * const *rep = main_replaces; rep[0]; rep += 2) | ||||
{ | { | ||||
char *match = strstr(patched_code.C(), rep[0]); | |||||
char *match = strstr(&patched_code[0], rep[0]); | |||||
if (match && match < main) | if (match && match < main) | ||||
{ | { | ||||
size_t l0 = strlen(rep[0]); | size_t l0 = strlen(rep[0]); | ||||
@@ -685,18 +687,18 @@ String ShaderData::Patch(String const &code, ShaderType type) | |||||
{ | { | ||||
while (true) | while (true) | ||||
{ | { | ||||
int index = patched_code.index_of(rep[0]); | |||||
if (index == INDEX_NONE) | |||||
size_t index = patched_code.find(rep[0]); | |||||
if (index == std::string::npos) | |||||
break; | break; | ||||
size_t l0 = strlen(rep[0]); | size_t l0 = strlen(rep[0]); | ||||
size_t l1 = strlen(rep[1]); | size_t l1 = strlen(rep[1]); | ||||
UNUSED(l1); | UNUSED(l1); | ||||
String left = patched_code.sub(0, index); | |||||
String right = patched_code.sub(index + l0, patched_code.count() - (index + l0)); | |||||
std::string left = patched_code.substr(0, index); | |||||
std::string right = patched_code.substr(index + l0, patched_code.length() - (index + l0)); | |||||
patched_code = left + String(rep[1]) + right; | |||||
patched_code = left + std::string(rep[1]) + right; | |||||
} | } | ||||
} | } | ||||
} | } | ||||
@@ -704,112 +706,112 @@ String ShaderData::Patch(String const &code, ShaderType type) | |||||
return patched_code; | return patched_code; | ||||
} | } | ||||
static const String g_ret = "\n"; | |||||
static const String g_eol = ";"; | |||||
static const String g_bop = "{"; | |||||
static const String g_bcl = "}"; | |||||
static const String g_tab = " "; | |||||
static const std::string g_ret = "\n"; | |||||
static const std::string g_eol = ";"; | |||||
static const std::string g_bop = "{"; | |||||
static const std::string g_bcl = "}"; | |||||
static const std::string g_tab = " "; | |||||
//---- | //---- | ||||
String Shader::GetVariablePrefix(const ShaderVariable variable) | |||||
std::string Shader::GetVariablePrefix(const ShaderVariable variable) | |||||
{ | { | ||||
switch (variable.ToScalar()) | switch (variable.ToScalar()) | ||||
{ | { | ||||
case ShaderVariable::Attribute: return String("in_"); | |||||
case ShaderVariable::Uniform: return String("u_"); | |||||
case ShaderVariable::Varying: return String("pass_"); | |||||
case ShaderVariable::Attribute: return "in_"; | |||||
case ShaderVariable::Uniform: return "u_"; | |||||
case ShaderVariable::Varying: return "pass_"; | |||||
case ShaderVariable::InOut: | case ShaderVariable::InOut: | ||||
default: return String(); | |||||
default: return ""; | |||||
} | } | ||||
} | } | ||||
//---- | //---- | ||||
String Shader::GetVariableQualifier(const ShaderVariable variable) | |||||
std::string Shader::GetVariableQualifier(const ShaderVariable variable) | |||||
{ | { | ||||
switch (variable.ToScalar()) | switch (variable.ToScalar()) | ||||
{ | { | ||||
case ShaderVariable::Attribute: return String("attribute"); | |||||
case ShaderVariable::Uniform: return String("uniform"); | |||||
case ShaderVariable::Varying: return String("varying"); | |||||
case ShaderVariable::Attribute: return "attribute"; | |||||
case ShaderVariable::Uniform: return "uniform"; | |||||
case ShaderVariable::Varying: return "varying"; | |||||
case ShaderVariable::InOut: | case ShaderVariable::InOut: | ||||
default: return String(); | |||||
default: return ""; | |||||
} | } | ||||
} | } | ||||
//---- | //---- | ||||
String Shader::GetFunctionQualifier(const ShaderVariable variable, const ShaderProgram program) | |||||
std::string Shader::GetFunctionQualifier(const ShaderVariable variable, const ShaderProgram program) | |||||
{ | { | ||||
switch (program.ToScalar()) | switch (program.ToScalar()) | ||||
{ | { | ||||
case ShaderProgram::Geometry: | case ShaderProgram::Geometry: | ||||
{ | { | ||||
//TODO : L O L ---------------- | //TODO : L O L ---------------- | ||||
return String(); | |||||
return ""; | |||||
} | } | ||||
case ShaderProgram::Vertex: | case ShaderProgram::Vertex: | ||||
{ | { | ||||
switch (variable.ToScalar()) | switch (variable.ToScalar()) | ||||
{ | { | ||||
case ShaderVariable::Attribute: return String("in"); | |||||
case ShaderVariable::Uniform: return String("in"); | |||||
case ShaderVariable::Varying: return String("inout"); | |||||
case ShaderVariable::InOut: return String("inout"); | |||||
default: return String(); | |||||
case ShaderVariable::Attribute: return "in"; | |||||
case ShaderVariable::Uniform: return "in"; | |||||
case ShaderVariable::Varying: return "inout"; | |||||
case ShaderVariable::InOut: return "inout"; | |||||
default: return ""; | |||||
} | } | ||||
return String(); | |||||
return ""; | |||||
} | } | ||||
case ShaderProgram::Pixel: | case ShaderProgram::Pixel: | ||||
{ | { | ||||
switch (variable.ToScalar()) | switch (variable.ToScalar()) | ||||
{ | { | ||||
case ShaderVariable::Attribute: return String("in"); | |||||
case ShaderVariable::Uniform: return String("in"); | |||||
case ShaderVariable::Varying: return String("in"); | |||||
case ShaderVariable::InOut: return String("inout"); | |||||
default: return String(); | |||||
case ShaderVariable::Attribute: return "in"; | |||||
case ShaderVariable::Uniform: return "in"; | |||||
case ShaderVariable::Varying: return "in"; | |||||
case ShaderVariable::InOut: return "inout"; | |||||
default: return ""; | |||||
} | } | ||||
return String(); | |||||
return ""; | |||||
} | } | ||||
default: | default: | ||||
{ | { | ||||
return String(); | |||||
return ""; | |||||
} | } | ||||
} | } | ||||
} | } | ||||
//---- | //---- | ||||
String Shader::GetProgramQualifier(const ShaderProgram program) | |||||
std::string Shader::GetProgramQualifier(const ShaderProgram program) | |||||
{ | { | ||||
switch (program.ToScalar()) | switch (program.ToScalar()) | ||||
{ | { | ||||
case ShaderProgram::Geometry: return String(); //TODO : L O L --------- | |||||
case ShaderProgram::Vertex: return String("[vert.glsl]"); | |||||
case ShaderProgram::Pixel: return String("[frag.glsl]"); | |||||
default: return String(); | |||||
case ShaderProgram::Geometry: return ""; //TODO : L O L --------- | |||||
case ShaderProgram::Vertex: return "[vert.glsl]"; | |||||
case ShaderProgram::Pixel: return "[frag.glsl]"; | |||||
default: return ""; | |||||
} | } | ||||
} | } | ||||
//---- | //---- | ||||
String Shader::GetProgramOutVariable(const ShaderProgram program) | |||||
std::string Shader::GetProgramOutVariable(const ShaderProgram program) | |||||
{ | { | ||||
switch (program.ToScalar()) | switch (program.ToScalar()) | ||||
{ | { | ||||
case ShaderProgram::Geometry: return String(); //TODO : L O L --------- | |||||
case ShaderProgram::Vertex: return String("gl_Position"); | |||||
case ShaderProgram::Pixel: return String("gl_FragColor"); | |||||
default: return String(); | |||||
case ShaderProgram::Geometry: return ""; //TODO : L O L --------- | |||||
case ShaderProgram::Vertex: return "gl_Position"; | |||||
case ShaderProgram::Pixel: return "gl_FragColor"; | |||||
default: return ""; | |||||
} | } | ||||
} | } | ||||
//---- | //---- | ||||
String Shader::GetProgramOutVariableLocal(const ShaderProgram program) | |||||
std::string Shader::GetProgramOutVariableLocal(const ShaderProgram program) | |||||
{ | { | ||||
switch (program.ToScalar()) | switch (program.ToScalar()) | ||||
{ | { | ||||
case ShaderProgram::Geometry: return String(); //TODO : L O L --------- | |||||
case ShaderProgram::Vertex: return String("out_position"); | |||||
case ShaderProgram::Pixel: return String("out_frag_color"); | |||||
default: return String(); | |||||
case ShaderProgram::Geometry: return ""; //TODO : L O L --------- | |||||
case ShaderProgram::Vertex: return "out_position"; | |||||
case ShaderProgram::Pixel: return "out_frag_color"; | |||||
default: return ""; | |||||
} | } | ||||
} | } | ||||
@@ -829,70 +831,70 @@ ShaderVar ShaderVar::GetShaderOut(ShaderProgram program) | |||||
void ShaderBlock::AddVar(ShaderVar const& var) | void ShaderBlock::AddVar(ShaderVar const& var) | ||||
{ | { | ||||
ShaderVariable qualifier = var.GetQualifier(); | ShaderVariable qualifier = var.GetQualifier(); | ||||
String type = var.GetType(); | |||||
String name = Shader::GetVariablePrefix(qualifier) + var.m_name; | |||||
std::string type = var.GetType(); | |||||
std::string name = Shader::GetVariablePrefix(qualifier) + var.m_name; | |||||
ASSERT(!m_parameters[qualifier.ToScalar()].has_key(name)); | ASSERT(!m_parameters[qualifier.ToScalar()].has_key(name)); | ||||
m_parameters[qualifier.ToScalar()][name] = type; | m_parameters[qualifier.ToScalar()][name] = type; | ||||
} | } | ||||
//---- | //---- | ||||
void ShaderBlock::AddCallParameters(map<String, String> const& variables, String& result) | |||||
void ShaderBlock::AddCallParameters(map<std::string, std::string> const& variables, std::string& result) | |||||
{ | { | ||||
array<String> keys = variables.keys(); | |||||
for (String key : keys) | |||||
array<std::string> keys = variables.keys(); | |||||
for (auto const &key : keys) | |||||
{ | { | ||||
if (result.count() > 0) | |||||
if (result.length() > 0) | |||||
result += ", "; | result += ", "; | ||||
result += key; | result += key; | ||||
} | } | ||||
} | } | ||||
//---- | //---- | ||||
void ShaderBlock::AddDefinitionParameters(const ShaderVariable type, const ShaderProgram program, map<String, String>& variables, String& result) | |||||
void ShaderBlock::AddDefinitionParameters(const ShaderVariable type, const ShaderProgram program, map<std::string, std::string>& variables, std::string& result) | |||||
{ | { | ||||
array<String> keys = variables.keys(); | |||||
for (String key : keys) | |||||
array<std::string> keys = variables.keys(); | |||||
for (auto const &key : keys) | |||||
{ | { | ||||
if (result.count() > 0) | |||||
if (result.length() > 0) | |||||
result += ", "; | result += ", "; | ||||
result += Shader::GetFunctionQualifier(type, program) + " "; | result += Shader::GetFunctionQualifier(type, program) + " "; | ||||
result += variables[key]; | result += variables[key]; | ||||
result += String(" "); | |||||
result += " "; | |||||
result += key; | result += key; | ||||
} | } | ||||
} | } | ||||
//---- | //---- | ||||
void ShaderBlock::Build(const ShaderProgram program, String& call, String& function) | |||||
void ShaderBlock::Build(const ShaderProgram program, std::string& call, std::string& function) | |||||
{ | { | ||||
ASSERT(m_name.count()); | |||||
ASSERT(m_name.length()); | |||||
ASSERT(m_parameters[ShaderVariable::InOut].count()); | ASSERT(m_parameters[ShaderVariable::InOut].count()); | ||||
//Build call in main | //Build call in main | ||||
String call_name = String("Call_") + m_name; | |||||
std::string call_name = std::string("Call_") + m_name; | |||||
call = call_name + "("; | call = call_name + "("; | ||||
String call_parameters; | |||||
std::string call_parameters; | |||||
for (int i = 0; i < ShaderVariable::MAX; i++) | for (int i = 0; i < ShaderVariable::MAX; i++) | ||||
AddCallParameters(/*(ShaderVariable)i, */m_parameters[i], call_parameters); | AddCallParameters(/*(ShaderVariable)i, */m_parameters[i], call_parameters); | ||||
call += call_parameters + ");"; | call += call_parameters + ");"; | ||||
//Build function declaration | //Build function declaration | ||||
function = String("void ") + call_name + "("; | |||||
String def_parameters; | |||||
function = std::string("void ") + call_name + "("; | |||||
std::string def_parameters; | |||||
for (int i = 0; i < ShaderVariable::MAX; i++) | for (int i = 0; i < ShaderVariable::MAX; i++) | ||||
AddDefinitionParameters((ShaderVariable)i, program, m_parameters[i], def_parameters); | AddDefinitionParameters((ShaderVariable)i, program, m_parameters[i], def_parameters); | ||||
function += def_parameters + ")" + g_ret + | function += def_parameters + ")" + g_ret + | ||||
"{" + g_ret + | "{" + g_ret + | ||||
m_code_main + ((m_code_main.ends_with(g_ret)) ? (String()) : (g_ret)) + | |||||
m_code_main + (ends_with(m_code_main, g_ret) ? std::string() : g_ret) + | |||||
"}"; | "}"; | ||||
} | } | ||||
//Shader Builder implementation class ----------------------------------------- | //Shader Builder implementation class ----------------------------------------- | ||||
ShaderBuilder::ShaderBuilder(String const& name, String const& version) | |||||
ShaderBuilder::ShaderBuilder(std::string const& name, std::string const& version) | |||||
: m_name(name), m_version(version) | : m_name(name), m_version(version) | ||||
{ | { | ||||
ASSERT(name.count()); | |||||
ASSERT(version.count()); | |||||
ASSERT(name.length()); | |||||
ASSERT(version.length()); | |||||
} | } | ||||
//---- | //---- | ||||
@@ -901,7 +903,7 @@ ShaderBuilder::~ShaderBuilder() | |||||
} | } | ||||
//---- | //---- | ||||
String const& ShaderBuilder::GetName() | |||||
std::string const& ShaderBuilder::GetName() | |||||
{ | { | ||||
return m_name; | return m_name; | ||||
} | } | ||||
@@ -930,10 +932,10 @@ ShaderBuilder& ShaderBuilder::operator<<(ShaderBlock const& block) | |||||
} | } | ||||
//---- | //---- | ||||
String ShaderBuilder::AddSlotOutVariableLocal(const ShaderProgram program) | |||||
std::string ShaderBuilder::AddSlotOutVariableLocal(const ShaderProgram program) | |||||
{ | { | ||||
ShaderVariable var = ShaderVariable::InOut; | ShaderVariable var = ShaderVariable::InOut; | ||||
String result = Shader::GetProgramOutVariableLocal(program); | |||||
std::string result = Shader::GetProgramOutVariableLocal(program); | |||||
switch (program.ToScalar()) | switch (program.ToScalar()) | ||||
{ | { | ||||
case ShaderProgram::Geometry: | case ShaderProgram::Geometry: | ||||
@@ -960,17 +962,17 @@ String ShaderBuilder::AddSlotOutVariableLocal(const ShaderProgram program) | |||||
} | } | ||||
//---- | //---- | ||||
void ShaderBuilder::MergeParameters(map<String, String>& variables, map<String, String>& merged) | |||||
void ShaderBuilder::MergeParameters(map<std::string, std::string>& variables, map<std::string, std::string>& merged) | |||||
{ | { | ||||
array<String> keys = variables.keys(); | |||||
for (String key : keys) | |||||
array<std::string> keys = variables.keys(); | |||||
for (auto const &key : keys) | |||||
{ | { | ||||
bool has_key = merged.has_key(key); | bool has_key = merged.has_key(key); | ||||
//Key exists, check the type to make sure it's the same | //Key exists, check the type to make sure it's the same | ||||
ASSERT(!has_key || (has_key && merged[key] == variables[key]), | ASSERT(!has_key || (has_key && merged[key] == variables[key]), | ||||
"has_key=%d, key=%s merged[key]=%s, variables[key]=%s\n", | "has_key=%d, key=%s merged[key]=%s, variables[key]=%s\n", | ||||
(int)has_key, key.C(), merged[key].C(), variables[key].C()); | |||||
(int)has_key, key.c_str(), merged[key].c_str(), variables[key].c_str()); | |||||
//does not exist, had it | //does not exist, had it | ||||
if (!has_key) | if (!has_key) | ||||
@@ -979,7 +981,7 @@ void ShaderBuilder::MergeParameters(map<String, String>& variables, map<String, | |||||
} | } | ||||
//---- | //---- | ||||
void ShaderBuilder::Build(String& code) | |||||
void ShaderBuilder::Build(std::string& code) | |||||
{ | { | ||||
//Cleanup first | //Cleanup first | ||||
for (int prog = 0; prog < ShaderProgram::MAX; prog++) | for (int prog = 0; prog < ShaderProgram::MAX; prog++) | ||||
@@ -990,9 +992,9 @@ void ShaderBuilder::Build(String& code) | |||||
for (int prog = 0; prog < ShaderProgram::MAX; prog++) | for (int prog = 0; prog < ShaderProgram::MAX; prog++) | ||||
{ | { | ||||
//Add default local out in merged variables | //Add default local out in merged variables | ||||
String out_local_var = AddSlotOutVariableLocal((ShaderProgram)prog); | |||||
std::string out_local_var = AddSlotOutVariableLocal((ShaderProgram)prog); | |||||
if (!out_local_var.count()) | |||||
if (!out_local_var.length()) | |||||
continue; | continue; | ||||
//Merge all variables | //Merge all variables | ||||
@@ -1004,16 +1006,16 @@ void ShaderBuilder::Build(String& code) | |||||
code += Shader::GetProgramQualifier((ShaderProgram)prog) + g_ret; | code += Shader::GetProgramQualifier((ShaderProgram)prog) + g_ret; | ||||
//Add actual code | //Add actual code | ||||
code += String("#version ") + m_version + g_ret + g_ret; | |||||
code += std::string("#version ") + m_version + g_ret + g_ret; | |||||
//Added shader variables | //Added shader variables | ||||
for (int var = 0; var < ShaderVariable::InOut; var++) | for (int var = 0; var < ShaderVariable::InOut; var++) | ||||
{ | { | ||||
array<String> keys = m_parameters[prog][var].keys(); | |||||
array<std::string> keys = m_parameters[prog][var].keys(); | |||||
if (keys.count()) | if (keys.count()) | ||||
{ | { | ||||
code += String("//- ") + Shader::GetVariableQualifier((ShaderVariable)var) + " ----" + g_ret; | |||||
for (String key : keys) | |||||
code += std::string("//- ") + Shader::GetVariableQualifier((ShaderVariable)var) + " ----" + g_ret; | |||||
for (auto const &key : keys) | |||||
{ | { | ||||
code += Shader::GetVariableQualifier((ShaderVariable)var) + " "; | code += Shader::GetVariableQualifier((ShaderVariable)var) + " "; | ||||
code += m_parameters[prog][var][key] + " " + key + ";" + g_ret; | code += m_parameters[prog][var][key] + " " + key + ";" + g_ret; | ||||
@@ -1025,30 +1027,30 @@ void ShaderBuilder::Build(String& code) | |||||
code += g_ret; | code += g_ret; | ||||
//Build Blocks code and add it | //Build Blocks code and add it | ||||
array<String> calls; | |||||
array<std::string> calls; | |||||
for (int block = 0; block < m_blocks[prog].count(); block++) | for (int block = 0; block < m_blocks[prog].count(); block++) | ||||
{ | { | ||||
String call; | |||||
String function; | |||||
std::string call; | |||||
std::string function; | |||||
m_blocks[prog][block]->Build(ShaderProgram(prog), call, function); | m_blocks[prog][block]->Build(ShaderProgram(prog), call, function); | ||||
calls << call; | calls << call; | ||||
if (m_blocks[prog][block]->m_code_custom.count()) | |||||
if (m_blocks[prog][block]->m_code_custom.length()) | |||||
{ | { | ||||
code += String("//- ") + m_blocks[prog][block]->GetName() + " custom code ----" + g_ret; | |||||
code += std::string("//- ") + m_blocks[prog][block]->GetName() + " custom code ----" + g_ret; | |||||
code += m_blocks[prog][block]->m_code_custom + g_ret + g_ret; | code += m_blocks[prog][block]->m_code_custom + g_ret + g_ret; | ||||
} | } | ||||
code += String("//- ") + m_blocks[prog][block]->GetName() + " main code ----" + g_ret; | |||||
code += std::string("//- ") + m_blocks[prog][block]->GetName() + " main code ----" + g_ret; | |||||
code += function + g_ret + g_ret; | code += function + g_ret + g_ret; | ||||
} | } | ||||
//Added main definition | //Added main definition | ||||
code += String("//- Main ----") + g_ret + | |||||
String("void main(void)") + g_ret + "{" + g_ret; | |||||
code += std::string("//- Main ----") + g_ret + | |||||
"void main(void)" + g_ret + "{" + g_ret; | |||||
//Add local variables | //Add local variables | ||||
int var = ShaderVariable::InOut; | int var = ShaderVariable::InOut; | ||||
array<String> keys = m_parameters[prog][var].keys(); | |||||
for (String key : keys) | |||||
array<std::string> keys = m_parameters[prog][var].keys(); | |||||
for (auto const &key : keys) | |||||
{ | { | ||||
if (keys.count()) | if (keys.count()) | ||||
{ | { | ||||
@@ -1058,13 +1060,13 @@ void ShaderBuilder::Build(String& code) | |||||
code += g_ret; | code += g_ret; | ||||
//Add calls | //Add calls | ||||
code += g_tab + String("//- Calls ----") + g_ret; | |||||
for (String call : calls) | |||||
code += g_tab + "//- Calls ----" + g_ret; | |||||
for (auto const &call : calls) | |||||
code += g_tab + call + g_ret; | code += g_tab + call + g_ret; | ||||
code += g_ret; | code += g_ret; | ||||
code += g_tab + Shader::GetProgramOutVariable((ShaderProgram)prog) + " = " + out_local_var + ";" + g_ret + | code += g_tab + Shader::GetProgramOutVariable((ShaderProgram)prog) + " = " + out_local_var + ";" + g_ret + | ||||
String("}") + g_ret + g_ret; | |||||
"}" + g_ret + g_ret; | |||||
} | } | ||||
} | } | ||||
@@ -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 | ||||
@@ -13,6 +13,7 @@ | |||||
#include <lol/engine-internal.h> | #include <lol/engine-internal.h> | ||||
#include <cctype> | #include <cctype> | ||||
#include <string> | |||||
#include "../../image/resource-private.h" | #include "../../image/resource-private.h" | ||||
@@ -37,7 +38,7 @@ public: | |||||
virtual bool Save(char const *path, ResourceCodecData* data); | virtual bool Save(char const *path, ResourceCodecData* data); | ||||
private: | private: | ||||
static String ReadScreen(char const *name); | |||||
static std::string ReadScreen(char const *name); | |||||
static void WriteScreen(image &image, array<uint8_t> &result); | static void WriteScreen(image &image, array<uint8_t> &result); | ||||
}; | }; | ||||
@@ -61,11 +62,11 @@ ResourceCodecData* OricImageCodec::Load(char const *path) | |||||
u8vec4(0xff, 0xff, 0xff, 0xff), | u8vec4(0xff, 0xff, 0xff, 0xff), | ||||
}; | }; | ||||
String screen = ReadScreen(path); | |||||
if (screen.count() == 0) | |||||
std::string screen = ReadScreen(path); | |||||
if (screen.length() == 0) | |||||
return nullptr; | return nullptr; | ||||
auto data = new ResourceImageData(new image(ivec2(WIDTH, screen.count() * 6 / WIDTH))); | |||||
auto data = new ResourceImageData(new image(ivec2(WIDTH, screen.length() * 6 / WIDTH))); | |||||
auto img = data->m_image; | auto img = data->m_image; | ||||
u8vec4 *pixels = img->lock<PixelFormat::RGBA_8>(); | u8vec4 *pixels = img->lock<PixelFormat::RGBA_8>(); | ||||
@@ -116,9 +117,9 @@ bool OricImageCodec::Save(char const *path, ResourceCodecData* data) | |||||
int len = (int)strlen(path); | int len = (int)strlen(path); | ||||
if (len < 4 || path[len - 4] != '.' | if (len < 4 || path[len - 4] != '.' | ||||
|| toupper(path[len - 3]) != 'T' | |||||
|| toupper(path[len - 2]) != 'A' | |||||
|| toupper(path[len - 1]) != 'P') | |||||
|| std::toupper(path[len - 3]) != 'T' | |||||
|| std::toupper(path[len - 2]) != 'A' | |||||
|| std::toupper(path[len - 1]) != 'P') | |||||
return false; | return false; | ||||
array<uint8_t> result; | array<uint8_t> result; | ||||
@@ -152,11 +153,11 @@ bool OricImageCodec::Save(char const *path, ResourceCodecData* data) | |||||
return true; | return true; | ||||
} | } | ||||
String OricImageCodec::ReadScreen(char const *name) | |||||
std::string OricImageCodec::ReadScreen(char const *name) | |||||
{ | { | ||||
File f; | File f; | ||||
f.Open(name, FileAccess::Read); | f.Open(name, FileAccess::Read); | ||||
String data = f.ReadString(); | |||||
std::string data = f.ReadString().C(); | |||||
f.Close(); | f.Close(); | ||||
/* Skip the sync bytes */ | /* Skip the sync bytes */ | ||||
@@ -170,17 +171,17 @@ String OricImageCodec::ReadScreen(char const *name) | |||||
++header; | ++header; | ||||
/* Skip the header, ignoring the last byte’s value */ | /* Skip the header, ignoring the last byte’s value */ | ||||
if (data.sub(header, 8) != String("\x00\xff\x80\x00\xbf\x3f\xa0\x00", 8)) | |||||
if (!starts_with(data, std::string("\x00\xff\x80\x00\xbf\x3f\xa0\x00", 8))) | |||||
return ""; | return ""; | ||||
/* Skip the file name, including trailing nul char */ | /* Skip the file name, including trailing nul char */ | ||||
data = data.sub(header + 8); | |||||
int filename_end = data.index_of('\0'); | |||||
if (filename_end < 0) | |||||
return ""; | |||||
data = data.substr(header + 8); | |||||
size_t filename_end = data.find('\0'); | |||||
if (filename_end == std::string::npos) | |||||
return ""; | |||||
/* Read screen data */ | /* Read screen data */ | ||||
return data.sub(filename_end + 1); | |||||
return data.substr(filename_end + 1); | |||||
} | } | ||||
/* Error diffusion table, similar to Floyd-Steinberg. I choose not to | /* Error diffusion table, similar to Floyd-Steinberg. I choose not to | ||||
@@ -1,8 +1,8 @@ | |||||
// | // | ||||
// Lol Engine | // Lol Engine | ||||
// | // | ||||
// Copyright © 2010—2017 Sam Hocevar <sam@hocevar.net> | |||||
// 2014 Benjamin Huet <huet.benjamin@gmail.com> | |||||
// Copyright © 2009—2014 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 | // 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 | ||||
@@ -13,6 +13,8 @@ | |||||
#include <lol/engine-internal.h> | #include <lol/engine-internal.h> | ||||
#include <string> | |||||
#include "../../image/resource-private.h" | #include "../../image/resource-private.h" | ||||
namespace lol | namespace lol | ||||
@@ -38,7 +40,7 @@ DECLARE_IMAGE_CODEC(ZedImageCodec, 10) | |||||
ResourceCodecData* ZedImageCodec::Load(char const *path) | ResourceCodecData* ZedImageCodec::Load(char const *path) | ||||
{ | { | ||||
if (!lol::String(path).ends_with(".RSC")) | |||||
if (!ends_with(path, ".RSC")) | |||||
return nullptr; | return nullptr; | ||||
// Compacter definition | // Compacter definition | ||||
@@ -1,8 +1,8 @@ | |||||
// | // | ||||
// Lol Engine | // Lol Engine | ||||
// | // | ||||
// Copyright © 2010—2017 Sam Hocevar <sam@hocevar.net> | |||||
// 2014 Benjamin Huet <huet.benjamin@gmail.com> | |||||
// Copyright © 2009—2014 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 | // 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 | ||||
@@ -13,6 +13,8 @@ | |||||
#include <lol/engine-internal.h> | #include <lol/engine-internal.h> | ||||
#include <string> | |||||
#include "../../image/resource-private.h" | #include "../../image/resource-private.h" | ||||
namespace lol | namespace lol | ||||
@@ -38,7 +40,7 @@ DECLARE_IMAGE_CODEC(ZedPaletteImageCodec, 10) | |||||
ResourceCodecData* ZedPaletteImageCodec::Load(char const *path) | ResourceCodecData* ZedPaletteImageCodec::Load(char const *path) | ||||
{ | { | ||||
if (!lol::String(path).ends_with(".pal")) | |||||
if (!ends_with(path, ".pal")) | |||||
return nullptr; | return nullptr; | ||||
File file; | File file; | ||||
@@ -2,6 +2,7 @@ | |||||
// Lol Engine | // Lol Engine | ||||
// | // | ||||
// Copyright © 2010—2015 Benjamin Litzelmann | // Copyright © 2010—2015 Benjamin Litzelmann | ||||
// © 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 | ||||
@@ -12,20 +13,22 @@ | |||||
#include <lol/engine-internal.h> | #include <lol/engine-internal.h> | ||||
#include <string> | |||||
namespace lol | namespace lol | ||||
{ | { | ||||
/////////////////////////////////////////////////////////////////////////////// | /////////////////////////////////////////////////////////////////////////////// | ||||
// KeyBinding | // KeyBinding | ||||
void KeyBinding::Bind(const String& device_name, const String& key_name) | |||||
void KeyBinding::Bind(const std::string& device_name, const std::string& key_name) | |||||
{ | { | ||||
const InputDevice* device = InputDevice::Get(device_name); | const InputDevice* device = InputDevice::Get(device_name); | ||||
if (!device) | if (!device) | ||||
{ | { | ||||
msg::warn("trying to bind key to nonexistent input device %s\n", | msg::warn("trying to bind key to nonexistent input device %s\n", | ||||
device_name.C()); | |||||
device_name.c_str()); | |||||
return; | return; | ||||
} | } | ||||
@@ -33,14 +36,14 @@ void KeyBinding::Bind(const String& device_name, const String& key_name) | |||||
if (keyindex < 0) | if (keyindex < 0) | ||||
{ | { | ||||
msg::warn("trying to bind nonexistent key %s.%s\n", | msg::warn("trying to bind nonexistent key %s.%s\n", | ||||
device_name.C(), key_name.C()); | |||||
device_name.c_str(), key_name.c_str()); | |||||
return; | return; | ||||
} | } | ||||
m_keybindings.push(device, keyindex); | m_keybindings.push(device, keyindex); | ||||
} | } | ||||
bool KeyBinding::Unbind(const String& device_name, const String& key_name) | |||||
bool KeyBinding::Unbind(const std::string& device_name, const std::string& key_name) | |||||
{ | { | ||||
for (int i = 0; i < m_keybindings.count(); ++i) | for (int i = 0; i < m_keybindings.count(); ++i) | ||||
{ | { | ||||
@@ -64,13 +67,13 @@ void KeyBinding::ClearBindings() | |||||
/////////////////////////////////////////////////////////////////////////////// | /////////////////////////////////////////////////////////////////////////////// | ||||
// AxisBinding | // AxisBinding | ||||
void AxisBinding::Bind(const String& device_name, const String& axis_name) | |||||
void AxisBinding::Bind(const std::string& device_name, const std::string& axis_name) | |||||
{ | { | ||||
const InputDevice* device = InputDevice::Get(device_name); | const InputDevice* device = InputDevice::Get(device_name); | ||||
if (!device) | if (!device) | ||||
{ | { | ||||
msg::warn("trying to bind axis to nonexistent input device %s\n", | msg::warn("trying to bind axis to nonexistent input device %s\n", | ||||
device_name.C()); | |||||
device_name.c_str()); | |||||
return; | return; | ||||
} | } | ||||
@@ -78,20 +81,20 @@ void AxisBinding::Bind(const String& device_name, const String& axis_name) | |||||
if (axisindex < 0) | if (axisindex < 0) | ||||
{ | { | ||||
msg::warn("trying to bind nonexistent axis %s.%s\n", | msg::warn("trying to bind nonexistent axis %s.%s\n", | ||||
device_name.C(), axis_name.C()); | |||||
device_name.c_str(), axis_name.c_str()); | |||||
return; | return; | ||||
} | } | ||||
m_axisbindings.push(device, axisindex); | m_axisbindings.push(device, axisindex); | ||||
} | } | ||||
void AxisBinding::BindKey(const String& device_name, const String& key_name) | |||||
void AxisBinding::BindKey(const std::string& device_name, const std::string& key_name) | |||||
{ | { | ||||
const InputDevice* device = InputDevice::Get(device_name); | const InputDevice* device = InputDevice::Get(device_name); | ||||
if (!device) | if (!device) | ||||
{ | { | ||||
msg::warn("trying to bind axis key to nonexistent input device %s\n", | msg::warn("trying to bind axis key to nonexistent input device %s\n", | ||||
device_name.C()); | |||||
device_name.c_str()); | |||||
return; | return; | ||||
} | } | ||||
@@ -99,20 +102,20 @@ void AxisBinding::BindKey(const String& device_name, const String& key_name) | |||||
if (keyindex < 0) | if (keyindex < 0) | ||||
{ | { | ||||
msg::warn("trying to bind nonexistent axis key %s.%s\n", | msg::warn("trying to bind nonexistent axis key %s.%s\n", | ||||
device_name.C(), key_name.C()); | |||||
device_name.c_str(), key_name.c_str()); | |||||
return; | return; | ||||
} | } | ||||
m_keybindings.push(device, -1, keyindex); | m_keybindings.push(device, -1, keyindex); | ||||
} | } | ||||
void AxisBinding::BindKeys(const String& device_name, const String& min_key_name, const String& max_key_name) | |||||
void AxisBinding::BindKeys(const std::string& device_name, const std::string& min_key_name, const std::string& max_key_name) | |||||
{ | { | ||||
const InputDevice* device = InputDevice::Get(device_name); | const InputDevice* device = InputDevice::Get(device_name); | ||||
if (!device) | if (!device) | ||||
{ | { | ||||
msg::warn("trying to bind axis keys to nonexistent input device %s\n", | msg::warn("trying to bind axis keys to nonexistent input device %s\n", | ||||
device_name.C()); | |||||
device_name.c_str()); | |||||
return; | return; | ||||
} | } | ||||
@@ -120,7 +123,7 @@ void AxisBinding::BindKeys(const String& device_name, const String& min_key_name | |||||
if (minkeyindex < 0) | if (minkeyindex < 0) | ||||
{ | { | ||||
msg::warn("trying to bind nonexistent axis key %s.%s\n", | msg::warn("trying to bind nonexistent axis key %s.%s\n", | ||||
device_name.C(), min_key_name.C()); | |||||
device_name.c_str(), min_key_name.c_str()); | |||||
return; | return; | ||||
} | } | ||||
@@ -128,14 +131,14 @@ void AxisBinding::BindKeys(const String& device_name, const String& min_key_name | |||||
if (maxkeyindex < 0) | if (maxkeyindex < 0) | ||||
{ | { | ||||
msg::warn("trying to bind nonexistent axis key %s.%s\n", | msg::warn("trying to bind nonexistent axis key %s.%s\n", | ||||
device_name.C(), max_key_name.C()); | |||||
device_name.c_str(), max_key_name.c_str()); | |||||
return; | return; | ||||
} | } | ||||
m_keybindings.push(device, minkeyindex, maxkeyindex); | m_keybindings.push(device, minkeyindex, maxkeyindex); | ||||
} | } | ||||
bool AxisBinding::Unbind(const String& device_name, const String& axis_name) | |||||
bool AxisBinding::Unbind(const std::string& device_name, const std::string& axis_name) | |||||
{ | { | ||||
for (int i = 0; i < m_keybindings.count(); ++i) | for (int i = 0; i < m_keybindings.count(); ++i) | ||||
{ | { | ||||
@@ -151,7 +154,7 @@ bool AxisBinding::Unbind(const String& device_name, const String& axis_name) | |||||
return false; | return false; | ||||
} | } | ||||
bool AxisBinding::UnbindKey(const String& device_name, const String& key_name) | |||||
bool AxisBinding::UnbindKey(const std::string& device_name, const std::string& key_name) | |||||
{ | { | ||||
for (int i = 0; i < m_keybindings.count(); ++i) | for (int i = 0; i < m_keybindings.count(); ++i) | ||||
{ | { | ||||
@@ -167,7 +170,7 @@ bool AxisBinding::UnbindKey(const String& device_name, const String& key_name) | |||||
return false; | return false; | ||||
} | } | ||||
bool AxisBinding::UnbindKeys(const String& device_name, const String& min_key_name, const String& max_key_name) | |||||
bool AxisBinding::UnbindKeys(const std::string& device_name, const std::string& min_key_name, const std::string& max_key_name) | |||||
{ | { | ||||
for (int i = 0; i < m_keybindings.count(); ++i) | for (int i = 0; i < m_keybindings.count(); ++i) | ||||
{ | { | ||||
@@ -229,7 +232,7 @@ array<Controller*> Controller::controllers; | |||||
uint32_t Controller::m_active_layer = ~((uint32_t)0); | uint32_t Controller::m_active_layer = ~((uint32_t)0); | ||||
//----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||||
Controller::Controller(String const &name) | |||||
Controller::Controller(std::string const &name) | |||||
{ | { | ||||
m_gamegroup = GAMEGROUP_INPUT; | m_gamegroup = GAMEGROUP_INPUT; | ||||
m_name = name; | m_name = name; | ||||
@@ -238,12 +241,12 @@ Controller::Controller(String const &name) | |||||
m_active = false; | m_active = false; | ||||
if (Get(name) != nullptr) | if (Get(name) != nullptr) | ||||
{ | { | ||||
msg::warn("controller “%s” has already been registered\n", name.C()); | |||||
msg::warn("controller “%s” has already been registered\n", name.c_str()); | |||||
} | } | ||||
controllers.push(this); | controllers.push(this); | ||||
} | } | ||||
Controller::Controller(String const &name, InputProfile const& profile) | |||||
Controller::Controller(std::string const &name, InputProfile const& profile) | |||||
: Controller(name) | : Controller(name) | ||||
{ | { | ||||
Init(profile); | Init(profile); | ||||
@@ -342,13 +345,11 @@ float Controller::GetAxisDelta(int index) const | |||||
} | } | ||||
//----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||||
Controller* Controller::Get(String const &name) | |||||
Controller* Controller::Get(std::string const &name) | |||||
{ | { | ||||
for (int i = 0; i < controllers.count(); ++i) | |||||
{ | |||||
if (controllers[i]->m_name == name) | |||||
return controllers[i]; | |||||
} | |||||
for (auto controller : controllers) | |||||
if (controller->m_name == name) | |||||
return controller; | |||||
return nullptr; | return nullptr; | ||||
} | } | ||||
@@ -1,15 +1,20 @@ | |||||
// | // | ||||
// Lol Engine | |||||
// Lol Engine | |||||
// | // | ||||
// Copyright: (c) 2010-2013 Benjamin Litzelmann | |||||
// 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—2015 Benjamin Litzelmann | |||||
// © 2017—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 | ||||
#include <string> | |||||
namespace lol | namespace lol | ||||
{ | { | ||||
@@ -37,16 +42,16 @@ protected: | |||||
public: | public: | ||||
//Binding methods --------------------------------------------------------- | //Binding methods --------------------------------------------------------- | ||||
/** Bind a physical device and key */ | /** Bind a physical device and key */ | ||||
void Bind(const String& device_name, const String& key_name); | |||||
void Bind(const std::string& device_name, const std::string& key_name); | |||||
/** Unbind a previously bound physical device and key. Returns true if the binding was existing. */ | /** Unbind a previously bound physical device and key. Returns true if the binding was existing. */ | ||||
bool Unbind(const String& device_name, const String& key_name); | |||||
bool Unbind(const std::string& device_name, const std::string& key_name); | |||||
/* Small helpers */ | /* Small helpers */ | ||||
void BindMouse(const String& key_name) { Bind(g_name_mouse, key_name); } | |||||
void BindKeyboard(const String& key_name) { Bind(g_name_keyboard, key_name); } | |||||
void BindJoystick(const uint64_t num, const String& key_name) { Bind(g_name_joystick(num), key_name); } | |||||
bool UnbindMouse(const String& key_name) { return Unbind(g_name_mouse, key_name); } | |||||
bool UnbindKeyboard(const String& key_name) { return Unbind(g_name_keyboard, key_name); } | |||||
bool UnbindJoystick(const uint64_t num, const String& key_name) { return Unbind(g_name_joystick(num), key_name); } | |||||
void BindMouse(const std::string& key_name) { Bind(g_name_mouse, key_name); } | |||||
void BindKeyboard(const std::string& key_name) { Bind(g_name_keyboard, key_name); } | |||||
void BindJoystick(const uint64_t num, const std::string& key_name) { Bind(g_name_joystick(num), key_name); } | |||||
bool UnbindMouse(const std::string& key_name) { return Unbind(g_name_mouse, key_name); } | |||||
bool UnbindKeyboard(const std::string& key_name) { return Unbind(g_name_keyboard, key_name); } | |||||
bool UnbindJoystick(const uint64_t num, const std::string& key_name) { return Unbind(g_name_joystick(num), key_name); } | |||||
/** Clear current binding */ | /** Clear current binding */ | ||||
void ClearBindings(); | void ClearBindings(); | ||||
/** Indicate wheither a physical device and key has been bound. Returns the number of bindings set. */ | /** Indicate wheither a physical device and key has been bound. Returns the number of bindings set. */ | ||||
@@ -92,31 +97,31 @@ protected: | |||||
public: | public: | ||||
//Binding methods --------------------------------------------------------- | //Binding methods --------------------------------------------------------- | ||||
/** Bind a physical device and axis */ | /** Bind a physical device and axis */ | ||||
void Bind(const String& device_name, const String& axis_name); | |||||
void Bind(const std::string& device_name, const std::string& axis_name); | |||||
/** Bind a physical device and key over this axis. The axis value will be 0 if the key is up and 1 if it's down */ | /** Bind a physical device and key over this axis. The axis value will be 0 if the key is up and 1 if it's down */ | ||||
void BindKey(const String& device_name, const String& key_name); | |||||
void BindKey(const std::string& device_name, const std::string& key_name); | |||||
/** Bind physical device and keys over this axis. The axis value will be 0 if both the key are up, -1 if minkey is down, and 1 if maxkey is down */ | /** Bind physical device and keys over this axis. The axis value will be 0 if both the key are up, -1 if minkey is down, and 1 if maxkey is down */ | ||||
void BindKeys(const String& device_name, const String& min_key_name, const String& max_key_name); | |||||
void BindKeys(const std::string& device_name, const std::string& min_key_name, const std::string& max_key_name); | |||||
/** Unbind a previously bound physical device and axis. Returns true if the binding was existing. */ | /** Unbind a previously bound physical device and axis. Returns true if the binding was existing. */ | ||||
bool Unbind(const String& device_name, const String& axis_name); | |||||
bool Unbind(const std::string& device_name, const std::string& axis_name); | |||||
/** Unbind a previously bound physical device and axis. Returns true if the binding was existing. */ | /** Unbind a previously bound physical device and axis. Returns true if the binding was existing. */ | ||||
bool UnbindKey(const String& device_name, const String& key_name); | |||||
bool UnbindKey(const std::string& device_name, const std::string& key_name); | |||||
/** Unbind a previously bound physical device and axis. Returns true if the binding was existing. */ | /** Unbind a previously bound physical device and axis. Returns true if the binding was existing. */ | ||||
bool UnbindKeys(const String& device_name, const String& min_key_name, const String& max_key_name); | |||||
bool UnbindKeys(const std::string& device_name, const std::string& min_key_name, const std::string& max_key_name); | |||||
/* Small helpers */ | /* Small helpers */ | ||||
void BindMouse(const String& axis_name) { Bind(g_name_mouse, axis_name); } | |||||
void BindMouseKey(const String& key_name) { BindKey(g_name_mouse, key_name); } | |||||
void BindMouseKeys(const String& min_key_name, const String& max_key_name) { BindKeys(g_name_mouse, min_key_name, max_key_name); } | |||||
bool UnbindMouse(const String& axis_name) { return Unbind(g_name_mouse, axis_name); } | |||||
bool UnbindMouseKey(const String& key_name) { return UnbindKey(g_name_mouse, key_name); } | |||||
bool UnbindMouseKeys(const String& min_key_name, const String& max_key_name){ return UnbindKeys(g_name_mouse, min_key_name, max_key_name); } | |||||
void BindMouse(const std::string& axis_name) { Bind(g_name_mouse, axis_name); } | |||||
void BindMouseKey(const std::string& key_name) { BindKey(g_name_mouse, key_name); } | |||||
void BindMouseKeys(const std::string& min_key_name, const std::string& max_key_name) { BindKeys(g_name_mouse, min_key_name, max_key_name); } | |||||
bool UnbindMouse(const std::string& axis_name) { return Unbind(g_name_mouse, axis_name); } | |||||
bool UnbindMouseKey(const std::string& key_name) { return UnbindKey(g_name_mouse, key_name); } | |||||
bool UnbindMouseKeys(const std::string& min_key_name, const std::string& max_key_name){ return UnbindKeys(g_name_mouse, min_key_name, max_key_name); } | |||||
/* */ | /* */ | ||||
void BindJoystick(const uint64_t num, const String& axis_name) { Bind(g_name_joystick(num), axis_name); } | |||||
void BindJoystickKey(const uint64_t num, const String& key_name) { BindKey(g_name_joystick(num), key_name); } | |||||
void BindJoystickKeys(const uint64_t num, const String& min_key_name, const String& max_key_name) { BindKeys(g_name_joystick(num), min_key_name, max_key_name); } | |||||
bool UnbindJoystick(const uint64_t num, const String& axis_name) { return Unbind(g_name_joystick(num), axis_name); } | |||||
bool UnbindJoystickKey(const uint64_t num, const String& key_name) { return UnbindKey(g_name_joystick(num), key_name); } | |||||
bool UnbindJoystickKeys(const uint64_t num, const String& min_key_name, const String& max_key_name){ return UnbindKeys(g_name_joystick(num), min_key_name, max_key_name); } | |||||
void BindJoystick(const uint64_t num, const std::string& axis_name) { Bind(g_name_joystick(num), axis_name); } | |||||
void BindJoystickKey(const uint64_t num, const std::string& key_name) { BindKey(g_name_joystick(num), key_name); } | |||||
void BindJoystickKeys(const uint64_t num, const std::string& min_key_name, const std::string& max_key_name) { BindKeys(g_name_joystick(num), min_key_name, max_key_name); } | |||||
bool UnbindJoystick(const uint64_t num, const std::string& axis_name) { return Unbind(g_name_joystick(num), axis_name); } | |||||
bool UnbindJoystickKey(const uint64_t num, const std::string& key_name) { return UnbindKey(g_name_joystick(num), key_name); } | |||||
bool UnbindJoystickKeys(const uint64_t num, const std::string& min_key_name, const std::string& max_key_name){ return UnbindKeys(g_name_joystick(num), min_key_name, max_key_name); } | |||||
/** Clear current binding */ | /** Clear current binding */ | ||||
void ClearBindings(); | void ClearBindings(); | ||||
/** Indicate wheither a physical device and axis has been bound. Returns the number of bindings set. */ | /** Indicate wheither a physical device and axis has been bound. Returns the number of bindings set. */ | ||||
@@ -150,13 +155,13 @@ private: | |||||
friend class InputProfile; | friend class InputProfile; | ||||
public: | public: | ||||
Key() { } | Key() { } | ||||
Key(int idx, String const& name) : m_idx(idx), m_name(name) { } | |||||
Key(int idx, std::string const& name) : m_idx(idx), m_name(name) { } | |||||
Key(const Key& other) : m_idx(other.m_idx), m_name(other.m_name) { } | Key(const Key& other) : m_idx(other.m_idx), m_name(other.m_name) { } | ||||
~Key() { } | ~Key() { } | ||||
bool operator==(const Key& other) { return m_name == other.m_name; } | bool operator==(const Key& other) { return m_name == other.m_name; } | ||||
private: | private: | ||||
int m_idx = 0; | int m_idx = 0; | ||||
String m_name; | |||||
std::string m_name; | |||||
}; | }; | ||||
//--------------------------------------------------------------------- | //--------------------------------------------------------------------- | ||||
class Joystick | class Joystick | ||||
@@ -165,14 +170,14 @@ private: | |||||
friend class InputProfile; | friend class InputProfile; | ||||
public: | public: | ||||
Joystick() { } | Joystick() { } | ||||
Joystick(uint64_t joy, int idx, String const& name) : m_joy(joy), m_idx(idx), m_name(name) { } | |||||
Joystick(uint64_t joy, int idx, std::string const& name) : m_joy(joy), m_idx(idx), m_name(name) { } | |||||
Joystick(const Joystick& other) : m_joy(other.m_joy), m_idx(other.m_idx), m_name(other.m_name) { } | Joystick(const Joystick& other) : m_joy(other.m_joy), m_idx(other.m_idx), m_name(other.m_name) { } | ||||
~Joystick() { } | ~Joystick() { } | ||||
bool operator==(const Joystick& other) { return m_name == other.m_name; } | bool operator==(const Joystick& other) { return m_name == other.m_name; } | ||||
private: | private: | ||||
uint64_t m_joy = 0; | uint64_t m_joy = 0; | ||||
int m_idx = 0; | int m_idx = 0; | ||||
String m_name; | |||||
std::string m_name; | |||||
}; | }; | ||||
public: | public: | ||||
//--------------------------------------------------------------------- | //--------------------------------------------------------------------- | ||||
@@ -182,7 +187,7 @@ public: | |||||
friend class InputProfile; | friend class InputProfile; | ||||
public: | public: | ||||
Keyboard() : Key() { } | Keyboard() : Key() { } | ||||
Keyboard(int idx, String const& name) : Key(idx, name) { } | |||||
Keyboard(int idx, std::string const& name) : Key(idx, name) { } | |||||
Keyboard(const Keyboard& other) : Key(other.m_idx, other.m_name) { } | Keyboard(const Keyboard& other) : Key(other.m_idx, other.m_name) { } | ||||
}; | }; | ||||
//--------------------------------------------------------------------- | //--------------------------------------------------------------------- | ||||
@@ -192,7 +197,7 @@ public: | |||||
friend class InputProfile; | friend class InputProfile; | ||||
public: | public: | ||||
MouseKey() : Key() { } | MouseKey() : Key() { } | ||||
MouseKey(int idx, String const& name) : Key(idx, name) { } | |||||
MouseKey(int idx, std::string const& name) : Key(idx, name) { } | |||||
MouseKey(const Keyboard& other) : Key(other.m_idx, other.m_name) { } | MouseKey(const Keyboard& other) : Key(other.m_idx, other.m_name) { } | ||||
}; | }; | ||||
//--------------------------------------------------------------------- | //--------------------------------------------------------------------- | ||||
@@ -202,7 +207,7 @@ public: | |||||
friend class InputProfile; | friend class InputProfile; | ||||
public: | public: | ||||
MouseAxis() : Key() { } | MouseAxis() : Key() { } | ||||
MouseAxis(int idx, String const& name) : Key(idx, name) { } | |||||
MouseAxis(int idx, std::string const& name) : Key(idx, name) { } | |||||
MouseAxis(const Keyboard& other) : Key(other.m_idx, other.m_name) { } | MouseAxis(const Keyboard& other) : Key(other.m_idx, other.m_name) { } | ||||
}; | }; | ||||
//--------------------------------------------------------------------- | //--------------------------------------------------------------------- | ||||
@@ -212,7 +217,7 @@ public: | |||||
friend class InputProfile; | friend class InputProfile; | ||||
public: | public: | ||||
JoystickKey() : Joystick() { } | JoystickKey() : Joystick() { } | ||||
JoystickKey(uint64_t joy, int idx, String const& name) : Joystick(joy, idx, name) { } | |||||
JoystickKey(uint64_t joy, int idx, std::string const& name) : Joystick(joy, idx, name) { } | |||||
JoystickKey(const JoystickKey& other) : Joystick(other.m_joy, other.m_idx, other.m_name) { } | JoystickKey(const JoystickKey& other) : Joystick(other.m_joy, other.m_idx, other.m_name) { } | ||||
}; | }; | ||||
//--------------------------------------------------------------------- | //--------------------------------------------------------------------- | ||||
@@ -222,7 +227,7 @@ public: | |||||
friend class InputProfile; | friend class InputProfile; | ||||
public: | public: | ||||
JoystickAxis() : Joystick() { } | JoystickAxis() : Joystick() { } | ||||
JoystickAxis(uint64_t joy, int idx, String const& name) : Joystick(joy, idx, name) { } | |||||
JoystickAxis(uint64_t joy, int idx, std::string const& name) : Joystick(joy, idx, name) { } | |||||
JoystickAxis(const JoystickAxis& other) : Joystick(other.m_joy, other.m_idx, other.m_name) { } | JoystickAxis(const JoystickAxis& other) : Joystick(other.m_joy, other.m_idx, other.m_name) { } | ||||
}; | }; | ||||
public: | public: | ||||
@@ -326,7 +331,7 @@ public: | |||||
MAX, | MAX, | ||||
}; | }; | ||||
protected: | protected: | ||||
virtual bool BuildEnumMap(map<int64_t, String>& enum_map) { UNUSED(enum_map); return true; } | |||||
virtual bool BuildEnumMap(map<int64_t, std::string>& enum_map) { UNUSED(enum_map); return true; } | |||||
}; | }; | ||||
typedef SafeEnum<InputTypeBase> InputType; | typedef SafeEnum<InputTypeBase> InputType; | ||||
@@ -338,11 +343,11 @@ public: | |||||
{ | { | ||||
switch (type.ToScalar()) | switch (type.ToScalar()) | ||||
{ | { | ||||
case InputType::Keyboard:/******/*this << InputProfile::Keyboard/******/(/***/i, T(i).ToString()); break; | |||||
case InputType::MouseKey:/******/*this << InputProfile::MouseKey/******/(/***/i, T(i).ToString()); break; | |||||
case InputType::JoystickKey:/***/*this << InputProfile::JoystickKey/***/(joy, i, T(i).ToString()); break; | |||||
case InputType::MouseAxis:/*****/*this << InputProfile::MouseAxis/*****/(/***/i, T(i).ToString()); break; | |||||
case InputType::JoystickAxis:/**/*this << InputProfile::JoystickAxis/**/(joy, i, T(i).ToString()); break; | |||||
case InputType::Keyboard:/******/*this << InputProfile::Keyboard/******/(/***/i, T(i).tostring()); break; | |||||
case InputType::MouseKey:/******/*this << InputProfile::MouseKey/******/(/***/i, T(i).tostring()); break; | |||||
case InputType::JoystickKey:/***/*this << InputProfile::JoystickKey/***/(joy, i, T(i).tostring()); break; | |||||
case InputType::MouseAxis:/*****/*this << InputProfile::MouseAxis/*****/(/***/i, T(i).tostring()); break; | |||||
case InputType::JoystickAxis:/**/*this << InputProfile::JoystickAxis/**/(joy, i, T(i).tostring()); break; | |||||
default: break; | default: break; | ||||
} | } | ||||
} | } | ||||
@@ -363,8 +368,8 @@ typedef InputProfile::InputType InputProfileType; | |||||
class Controller : public Entity | class Controller : public Entity | ||||
{ | { | ||||
public: | public: | ||||
Controller(String const &name); | |||||
Controller(String const &name, InputProfile const& setup); | |||||
Controller(std::string const &name); | |||||
Controller(std::string const &name, InputProfile const& setup); | |||||
virtual ~Controller(); | virtual ~Controller(); | ||||
virtual void TickGame(float seconds); | virtual void TickGame(float seconds); | ||||
@@ -413,7 +418,7 @@ public: | |||||
float GetAxisDelta(int index) const; | float GetAxisDelta(int index) const; | ||||
/** Get named controller */ | /** Get named controller */ | ||||
static Controller* Get(String const &name); | |||||
static Controller* Get(std::string const &name); | |||||
protected: | protected: | ||||
/** Input profile system */ | /** Input profile system */ | ||||
@@ -427,7 +432,7 @@ private: | |||||
static uint32_t m_active_layer; //All active by default | static uint32_t m_active_layer; //All active by default | ||||
static array<Controller*> controllers; | static array<Controller*> controllers; | ||||
String m_name; | |||||
std::string m_name; | |||||
bool m_activate_nextframe; | bool m_activate_nextframe; | ||||
bool m_deactivate_nextframe; | bool m_deactivate_nextframe; | ||||
bool m_active; | bool m_active; | ||||
@@ -1,15 +1,20 @@ | |||||
// | // | ||||
// Lol Engine | |||||
// Lol Engine | |||||
// | // | ||||
// Copyright: (c) 2010-2013 Benjamin Litzelmann | |||||
// 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—2015 Benjamin Litzelmann | |||||
// © 2017—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> | ||||
#include <string> | |||||
#include "input/input_internal.h" | #include "input/input_internal.h" | ||||
namespace lol | namespace lol | ||||
@@ -19,19 +24,17 @@ array<InputDevice*> InputDevice::devices; | |||||
int InputDevice::joystick_count = 0; | int InputDevice::joystick_count = 0; | ||||
bool InputDevice::m_capturemouse; | bool InputDevice::m_capturemouse; | ||||
array<String> InputDevice::GetAvailableDevices() | |||||
array<std::string> InputDevice::GetAvailableDevices() | |||||
{ | { | ||||
array<String> result; | |||||
for (int i = 0; i < devices.count(); ++i) | |||||
{ | |||||
result.push(devices[i]->m_name); | |||||
} | |||||
array<std::string> result; | |||||
for (auto const &device : devices) | |||||
result.push(device->m_name); | |||||
return result; | return result; | ||||
} | } | ||||
String InputDevice::GetText() | |||||
std::string InputDevice::GetText() | |||||
{ | { | ||||
String ret = m_text; | |||||
std::string ret = m_text; | |||||
m_text = ""; | m_text = ""; | ||||
return ret; | return ret; | ||||
} | } | ||||
@@ -92,7 +95,7 @@ void InputDeviceInternal::AddCursor(int index, const char* name) | |||||
InputDeviceInternal* InputDeviceInternal::CreateStandardKeyboard() | InputDeviceInternal* InputDeviceInternal::CreateStandardKeyboard() | ||||
{ | { | ||||
InputDeviceInternal* keyboard = new InputDeviceInternal(g_name_keyboard.C()); | |||||
InputDeviceInternal* keyboard = new InputDeviceInternal(g_name_keyboard.c_str()); | |||||
/* Register all scancodes known to SDL (from the USB standard) */ | /* Register all scancodes known to SDL (from the USB standard) */ | ||||
# define _SC(id, str, name) keyboard->AddKey(id, #name); | # define _SC(id, str, name) keyboard->AddKey(id, #name); | ||||
@@ -103,20 +106,20 @@ InputDeviceInternal* InputDeviceInternal::CreateStandardKeyboard() | |||||
InputDeviceInternal* InputDeviceInternal::CreateStandardMouse() | InputDeviceInternal* InputDeviceInternal::CreateStandardMouse() | ||||
{ | { | ||||
InputDeviceInternal* mouse = new InputDeviceInternal(g_name_mouse.C()); | |||||
mouse->AddKey(g_name_mouse_key_left.C()); | |||||
mouse->AddKey(g_name_mouse_key_middle.C()); | |||||
mouse->AddKey(g_name_mouse_key_right.C()); | |||||
InputDeviceInternal* mouse = new InputDeviceInternal(g_name_mouse.c_str()); | |||||
mouse->AddKey(g_name_mouse_key_left.c_str()); | |||||
mouse->AddKey(g_name_mouse_key_middle.c_str()); | |||||
mouse->AddKey(g_name_mouse_key_right.c_str()); | |||||
//Added to manage if mouse is in the screen or not. | //Added to manage if mouse is in the screen or not. | ||||
mouse->AddKey(g_name_mouse_key_in_screen.C()); | |||||
mouse->AddKey(g_name_mouse_key_in_screen.c_str()); | |||||
mouse->AddAxis(g_name_mouse_axis_x.C()); | |||||
mouse->AddAxis(g_name_mouse_axis_y.C()); | |||||
mouse->AddAxis(g_name_mouse_axis_xpixel.C()); | |||||
mouse->AddAxis(g_name_mouse_axis_ypixel.C()); | |||||
mouse->AddAxis(g_name_mouse_axis_scroll.C(), .0000001f); | |||||
mouse->AddAxis(g_name_mouse_axis_x.c_str()); | |||||
mouse->AddAxis(g_name_mouse_axis_y.c_str()); | |||||
mouse->AddAxis(g_name_mouse_axis_xpixel.c_str()); | |||||
mouse->AddAxis(g_name_mouse_axis_ypixel.c_str()); | |||||
mouse->AddAxis(g_name_mouse_axis_scroll.c_str(), .0000001f); | |||||
mouse->AddCursor(g_name_mouse_cursor.C()); | |||||
mouse->AddCursor(g_name_mouse_cursor.c_str()); | |||||
// TODO: extended button, and wheel (as axis or as buttons? or both?) | // TODO: extended button, and wheel (as axis or as buttons? or both?) | ||||
return mouse; | return mouse; | ||||
@@ -1,90 +1,93 @@ | |||||
// | // | ||||
// Lol Engine | |||||
// Lol Engine | |||||
// | // | ||||
// Copyright: (c) 2010-2013 Benjamin Litzelmann | |||||
// 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—2015 Benjamin Litzelmann | |||||
// © 2017—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 | ||||
#include <string> | |||||
namespace lol | namespace lol | ||||
{ | { | ||||
const String g_name_max("MAX"); | |||||
const String g_name_mouse("Mouse"); | |||||
const String g_name_keyboard("Keyboard"); | |||||
static String g_name_joystick() | |||||
{ | |||||
return String("Joystick"); | |||||
} | |||||
const std::string g_name_max("MAX"); | |||||
const std::string g_name_mouse("Mouse"); | |||||
const std::string g_name_keyboard("Keyboard"); | |||||
static std::string g_name_joystick() { return "Joystick"; } | |||||
static std::string g_name_joystick(const uint64_t num) | static std::string g_name_joystick(const uint64_t num) | ||||
{ | { | ||||
return format("Joystick%d", (int)num); | return format("Joystick%d", (int)num); | ||||
} | } | ||||
# define _SC(id, str, name) const String g_name_key_##name(#name); | |||||
# define _SC(id, str, name) const std::string g_name_key_##name(#name); | |||||
# include "input/keys.h" | # include "input/keys.h" | ||||
//Mouse default buttons/axis | //Mouse default buttons/axis | ||||
const String g_name_mouse_key_left("Left"); | |||||
const String g_name_mouse_key_middle("Middle"); | |||||
const String g_name_mouse_key_right("Right"); | |||||
const String g_name_mouse_key_in_screen("InScreen"); | |||||
const String g_name_mouse_axis_x("X"); | |||||
const String g_name_mouse_axis_y("Y"); | |||||
const String g_name_mouse_axis_xpixel("XPixel"); | |||||
const String g_name_mouse_axis_ypixel("YPixel"); | |||||
const String g_name_mouse_axis_scroll("Scroll"); | |||||
const String g_name_mouse_cursor("Cursor"); | |||||
const std::string g_name_mouse_key_left("Left"); | |||||
const std::string g_name_mouse_key_middle("Middle"); | |||||
const std::string g_name_mouse_key_right("Right"); | |||||
const std::string g_name_mouse_key_in_screen("InScreen"); | |||||
const std::string g_name_mouse_axis_x("X"); | |||||
const std::string g_name_mouse_axis_y("Y"); | |||||
const std::string g_name_mouse_axis_xpixel("XPixel"); | |||||
const std::string g_name_mouse_axis_ypixel("YPixel"); | |||||
const std::string g_name_mouse_axis_scroll("Scroll"); | |||||
const std::string g_name_mouse_cursor("Cursor"); | |||||
//Xbox default buttons/axis | //Xbox default buttons/axis | ||||
const String g_name_xbox_key_dpad_up("DPadUp"); | |||||
const String g_name_xbox_key_dpad_down("DPadDown"); | |||||
const String g_name_xbox_key_dpad_left("DPadLeft"); | |||||
const String g_name_xbox_key_dpad_right("DPadRight"); | |||||
const String g_name_xbox_key_left_thumb("LeftThumb"); | |||||
const String g_name_xbox_key_right_thumb("RightThumb"); | |||||
const String g_name_xbox_key_left_shoulder("LeftShoulder"); | |||||
const String g_name_xbox_key_right_shoulder("Rightshoulder"); | |||||
const String g_name_xbox_key_a("A"); | |||||
const String g_name_xbox_key_b("B"); | |||||
const String g_name_xbox_key_x("X"); | |||||
const String g_name_xbox_key_y("Y"); | |||||
const String g_name_xbox_key_start("Start"); | |||||
const String g_name_xbox_key_back("Back"); | |||||
const String g_name_xbox_axis_left_x("Axis1"); | |||||
const String g_name_xbox_axis_left_y("Axis2"); | |||||
const String g_name_xbox_axis_right_x("Axis3"); | |||||
const String g_name_xbox_axis_right_y("Axis4"); | |||||
const String g_name_xbox_axis_left_trigger("Axis5"); | |||||
const String g_name_xbox_axis_right_trigger("Axis6"); | |||||
const std::string g_name_xbox_key_dpad_up("DPadUp"); | |||||
const std::string g_name_xbox_key_dpad_down("DPadDown"); | |||||
const std::string g_name_xbox_key_dpad_left("DPadLeft"); | |||||
const std::string g_name_xbox_key_dpad_right("DPadRight"); | |||||
const std::string g_name_xbox_key_left_thumb("LeftThumb"); | |||||
const std::string g_name_xbox_key_right_thumb("RightThumb"); | |||||
const std::string g_name_xbox_key_left_shoulder("LeftShoulder"); | |||||
const std::string g_name_xbox_key_right_shoulder("Rightshoulder"); | |||||
const std::string g_name_xbox_key_a("A"); | |||||
const std::string g_name_xbox_key_b("B"); | |||||
const std::string g_name_xbox_key_x("X"); | |||||
const std::string g_name_xbox_key_y("Y"); | |||||
const std::string g_name_xbox_key_start("Start"); | |||||
const std::string g_name_xbox_key_back("Back"); | |||||
const std::string g_name_xbox_axis_left_x("Axis1"); | |||||
const std::string g_name_xbox_axis_left_y("Axis2"); | |||||
const std::string g_name_xbox_axis_right_x("Axis3"); | |||||
const std::string g_name_xbox_axis_right_y("Axis4"); | |||||
const std::string g_name_xbox_axis_left_trigger("Axis5"); | |||||
const std::string g_name_xbox_axis_right_trigger("Axis6"); | |||||
class InputDevice | class InputDevice | ||||
{ | { | ||||
public: | public: | ||||
/** Gets the name of this input device */ | /** Gets the name of this input device */ | ||||
const String& GetName() const | |||||
const std::string& GetName() const | |||||
{ | { | ||||
return m_name; | return m_name; | ||||
} | } | ||||
/** Gets the index of the corresponding key, needed to call GetKey */ | /** Gets the index of the corresponding key, needed to call GetKey */ | ||||
ptrdiff_t GetKeyIndex(String const &name) const | |||||
ptrdiff_t GetKeyIndex(std::string const &name) const | |||||
{ | { | ||||
return GetItemIndex(name, m_keynames); | return GetItemIndex(name, m_keynames); | ||||
} | } | ||||
/** Gets the index of the corresponding axis, needed to call GetAxis */ | /** Gets the index of the corresponding axis, needed to call GetAxis */ | ||||
ptrdiff_t GetAxisIndex(String const &name) const | |||||
ptrdiff_t GetAxisIndex(std::string const &name) const | |||||
{ | { | ||||
return GetItemIndex(name, m_axisnames); | return GetItemIndex(name, m_axisnames); | ||||
} | } | ||||
/** Gets the index of the corresponding cursor, needed to call GetCursor */ | /** Gets the index of the corresponding cursor, needed to call GetCursor */ | ||||
ptrdiff_t GetCursorIndex(String const &name) const | |||||
ptrdiff_t GetCursorIndex(std::string const &name) const | |||||
{ | { | ||||
return GetItemIndex(name, m_cursornames); | return GetItemIndex(name, m_cursornames); | ||||
} | } | ||||
@@ -97,7 +100,7 @@ public: | |||||
} | } | ||||
/** Gets the latest contents of text input. */ | /** Gets the latest contents of text input. */ | ||||
String GetText(); | |||||
std::string GetText(); | |||||
bool IsTextInputActive(); | bool IsTextInputActive(); | ||||
void SetTextInputActive(bool status); | void SetTextInputActive(bool status); | ||||
@@ -139,26 +142,26 @@ public: | |||||
} | } | ||||
/** Gets a list of the name of all available keys in this device */ | /** Gets a list of the name of all available keys in this device */ | ||||
const array<String>& GetAllKeys() const | |||||
const array<std::string>& GetAllKeys() const | |||||
{ | { | ||||
return m_keynames; | return m_keynames; | ||||
} | } | ||||
/** Gets a list of the name of all available axis in this device */ | /** Gets a list of the name of all available axis in this device */ | ||||
const array<String>& GetAllAxis() const | |||||
const array<std::string>& GetAllAxis() const | |||||
{ | { | ||||
return m_axisnames; | return m_axisnames; | ||||
} | } | ||||
/** Gets a list of the name of all available cursors in this device */ | /** Gets a list of the name of all available cursors in this device */ | ||||
const array<String>& GetAllCursors() const | |||||
const array<std::string>& GetAllCursors() const | |||||
{ | { | ||||
return m_cursornames; | return m_cursornames; | ||||
} | } | ||||
/** Gets a list of the name of all available input devices */ | /** Gets a list of the name of all available input devices */ | ||||
static array<String> GetAvailableDevices(); | |||||
static array<std::string> GetAvailableDevices(); | |||||
/** Gets an input device by its name */ | /** Gets an input device by its name */ | ||||
static InputDevice* Get(String const &name) | |||||
static InputDevice* Get(std::string const &name) | |||||
{ | { | ||||
return GetDevice(name); | return GetDevice(name); | ||||
} | } | ||||
@@ -190,17 +193,17 @@ public: | |||||
protected: | protected: | ||||
// TODO: hide all of this in a InputDeviceData? | // TODO: hide all of this in a InputDeviceData? | ||||
String m_name; | |||||
std::string m_name; | |||||
array<String> m_keynames; | |||||
array<String> m_axisnames; | |||||
array<String> m_cursornames; | |||||
array<std::string> m_keynames; | |||||
array<std::string> m_axisnames; | |||||
array<std::string> m_cursornames; | |||||
/** Key states (pressed/released) */ | /** Key states (pressed/released) */ | ||||
array<bool> m_keys; | array<bool> m_keys; | ||||
/** Text input state */ | /** Text input state */ | ||||
String m_text; | |||||
std::string m_text; | |||||
bool m_input_active; | bool m_input_active; | ||||
/** Axis states (value and sensitivity) */ | /** Axis states (value and sensitivity) */ | ||||
@@ -211,7 +214,7 @@ protected: | |||||
static bool m_capturemouse; | static bool m_capturemouse; | ||||
InputDevice(String const &name) | |||||
InputDevice(std::string const &name) | |||||
: m_name(name), | : m_name(name), | ||||
m_input_active(false) | m_input_active(false) | ||||
{ | { | ||||
@@ -235,7 +238,7 @@ private: | |||||
static int joystick_count; | static int joystick_count; | ||||
template <typename... T> | template <typename... T> | ||||
ptrdiff_t GetItemIndex(String const &name, const array<String, T...>& a) const | |||||
ptrdiff_t GetItemIndex(std::string const &name, const array<std::string, T...>& a) const | |||||
{ | { | ||||
for (int i = 0; i < a.count(); ++i) | for (int i = 0; i < a.count(); ++i) | ||||
{ | { | ||||
@@ -245,10 +248,11 @@ private: | |||||
return -1; | return -1; | ||||
} | } | ||||
static InputDevice* GetDevice(String const &name) | |||||
static InputDevice* GetDevice(std::string const &name) | |||||
{ | { | ||||
//Count the device types. TODO: Multi mouse/keyboard | //Count the device types. TODO: Multi mouse/keyboard | ||||
if (name.contains(g_name_joystick())) joystick_count++; | |||||
if (name.find(g_name_joystick()) != std::string::npos) | |||||
++joystick_count; | |||||
for (int i = 0; i < devices.count(); ++i) | for (int i = 0; i < devices.count(); ++i) | ||||
{ | { | ||||
@@ -1,15 +1,20 @@ | |||||
// | // | ||||
// Lol Engine | |||||
// Lol Engine | |||||
// | // | ||||
// Copyright: (c) 2010-2013 Benjamin Litzelmann | |||||
// 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—2015 Benjamin Litzelmann | |||||
// © 2017—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 | ||||
#include <string> | |||||
namespace lol | namespace lol | ||||
{ | { | ||||
@@ -19,7 +24,7 @@ namespace lol | |||||
class InputDeviceInternal : public InputDevice | class InputDeviceInternal : public InputDevice | ||||
{ | { | ||||
public: | public: | ||||
inline InputDeviceInternal(String const& name) : InputDevice(name) { } | |||||
inline InputDeviceInternal(std::string const& name) : InputDevice(name) { } | |||||
void AddKey(int id, char const * name); | void AddKey(int id, char const * name); | ||||
@@ -47,7 +52,7 @@ public: | |||||
m_keys[id] = state; | m_keys[id] = state; | ||||
} | } | ||||
void AddText(String const &text) | |||||
void AddText(std::string const &text) | |||||
{ | { | ||||
m_text += text; | m_text += text; | ||||
} | } | ||||
@@ -1,11 +1,13 @@ | |||||
// | // | ||||
// Lol Engine | |||||
// Lol Engine | |||||
// | // | ||||
// Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net> | |||||
// This program is free software; you can redistribute it and/or | |||||
// modify it under the terms of the Do What The Fuck You Want To | |||||
// Public License, Version 2, as published by Sam Hocevar. See | |||||
// http://www.wtfpl.net/ for more details. | |||||
// Copyright © 2010—2018 Sam Hocevar <sam@hocevar.net> | |||||
// | |||||
// Lol Engine is free software. It comes without any warranty, to | |||||
// the extent permitted by applicable law. You can redistribute it | |||||
// and/or modify it under the terms of the Do What the Fuck You Want | |||||
// to Public License, Version 2, as published by the WTFPL Task Force. | |||||
// See http://www.wtfpl.net/ for more details. | |||||
// | // | ||||
#pragma once | #pragma once | ||||
@@ -15,10 +17,11 @@ | |||||
// --------------- | // --------------- | ||||
// | // | ||||
#include <cfloat> /* for FLT_MAX */ | |||||
#include "engine/worldentity.h" | #include "engine/worldentity.h" | ||||
#include <cfloat> /* for FLT_MAX */ | |||||
#include <string> | |||||
namespace lol | namespace lol | ||||
{ | { | ||||
@@ -33,7 +36,7 @@ struct LightType | |||||
} | } | ||||
m_value; | m_value; | ||||
String ToString() | |||||
std::string tostring() | |||||
{ | { | ||||
switch (m_value) | switch (m_value) | ||||
{ | { | ||||
@@ -1,8 +1,8 @@ | |||||
// | // | ||||
// Lol Engine | // Lol Engine | ||||
// | // | ||||
// Copyright © 2010-2015 Sam Hocevar <sam@hocevar.net> | |||||
// © 2013-2015 Guillaume Bittoun <guillaume.bittoun@gmail.com> | |||||
// Copyright © 2010—2018 Sam Hocevar <sam@hocevar.net> | |||||
// © 2013—2015 Guillaume Bittoun <guillaume.bittoun@gmail.com> | |||||
// | // | ||||
// 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 | ||||
@@ -15,6 +15,8 @@ | |||||
#include <lol/base/map.h> | #include <lol/base/map.h> | ||||
#include <string> | |||||
namespace lol | namespace lol | ||||
{ | { | ||||
@@ -25,7 +27,7 @@ namespace lol | |||||
// { | // { | ||||
// }; | // }; | ||||
//protected: | //protected: | ||||
// virtual bool BuildEnumMap(map<int64_t, String>& enum_map) | |||||
// virtual bool BuildEnumMap(map<int64_t, std::string>& enum_map) | |||||
// { | // { | ||||
// enum_map[] = ""; | // enum_map[] = ""; | ||||
// return true; | // return true; | ||||
@@ -38,7 +40,7 @@ struct StructSafeEnum | |||||
{ | { | ||||
protected: | protected: | ||||
/* Convert to string stuff */ | /* Convert to string stuff */ | ||||
virtual bool BuildEnumMap(map<int64_t, String>&) { return false; } | |||||
virtual bool BuildEnumMap(map<int64_t, std::string>&) { return false; } | |||||
}; | }; | ||||
//----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||||
template<typename BASE, typename T = typename BASE::Type> | template<typename BASE, typename T = typename BASE::Type> | ||||
@@ -54,14 +56,14 @@ public: | |||||
/* Allow conversion from int and to the underlying type */ | /* Allow conversion from int and to the underlying type */ | ||||
inline explicit SafeEnum(int i) : m_value(T(i)) {} | inline explicit SafeEnum(int i) : m_value(T(i)) {} | ||||
inline Type ToScalar() const { return m_value; } | inline Type ToScalar() const { return m_value; } | ||||
//inline class String ToString() const { return ToString(); } | |||||
//inline std::string tostring() const { return tostring(); } | |||||
/* Convert to string stuff */ | /* Convert to string stuff */ | ||||
inline class String ToString() | |||||
inline std::string tostring() | |||||
{ | { | ||||
/* FIXME: we all know this isn’t thread safe. But is it really | /* FIXME: we all know this isn’t thread safe. But is it really | ||||
* a big deal? */ | * a big deal? */ | ||||
static map<int64_t, String> enum_map; | |||||
static map<int64_t, std::string> enum_map; | |||||
static bool ready = false; | static bool ready = false; | ||||
if (ready || this->BuildEnumMap(enum_map)) | if (ready || this->BuildEnumMap(enum_map)) | ||||
@@ -112,7 +114,7 @@ struct DisplayFlagBase : public StructSafeEnum | |||||
MAX | MAX | ||||
}; | }; | ||||
protected: | protected: | ||||
virtual bool BuildEnumMap(map<int64_t, String>& enum_map) | |||||
virtual bool BuildEnumMap(map<int64_t, std::string>& enum_map) | |||||
{ | { | ||||
enum_map[On] = "On"; | enum_map[On] = "On"; | ||||
enum_map[Off] = "Off"; | enum_map[Off] = "Off"; | ||||
@@ -1,7 +1,7 @@ | |||||
// | // | ||||
// Lol Engine | // Lol Engine | ||||
// | // | ||||
// Copyright © 2010—2017 Sam Hocevar <sam@hocevar.net> | |||||
// Copyright © 2010—2018 Sam Hocevar <sam@hocevar.net> | |||||
// © 2013—2015 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | // © 2013—2015 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | ||||
// | // | ||||
// Lol Engine is free software. It comes without any warranty, to | // Lol Engine is free software. It comes without any warranty, to | ||||
@@ -25,11 +25,20 @@ namespace lol | |||||
{ | { | ||||
/* Split a string along a single separator */ | /* Split a string along a single separator */ | ||||
array<std::string> split(std::string const &s, char sep); | |||||
array<std::string> split(std::string const &s, char sep = '\n'); | |||||
/* Split a string along multiple separators */ | /* Split a string along multiple separators */ | ||||
array<std::string> split(std::string const &s, std::string const &seps); | array<std::string> split(std::string const &s, std::string const &seps); | ||||
/* Check whether a string starts or ends with a given substring */ | |||||
bool starts_with(std::string const &s, std::string const &prefix); | |||||
bool ends_with(std::string const &s, std::string const &suffix); | |||||
/* Convert a string to lowercase or uppercase */ | |||||
std::string tolower(std::string const &s); | |||||
std::string toupper(std::string const &s); | |||||
/* Format a string, printf-style */ | |||||
std::string format(char const *format, ...) LOL_ATTR_FORMAT(1, 2); | std::string format(char const *format, ...) LOL_ATTR_FORMAT(1, 2); | ||||
std::string vformat(char const *format, va_list ap); | std::string vformat(char const *format, va_list ap); | ||||
@@ -158,61 +167,6 @@ public: | |||||
return String(&(*this)[start], item_count); | return String(&(*this)[start], item_count); | ||||
} | } | ||||
bool contains(String const &s) const | |||||
{ | |||||
return index_of(s.C()) != INDEX_NONE; | |||||
} | |||||
int index_of(char token) const | |||||
{ | |||||
using namespace std; | |||||
char const *tmp = strchr(C(), token); | |||||
return tmp ? int(tmp - C()) : INDEX_NONE; | |||||
} | |||||
int index_of(String const& token) const { return index_of(token.C()); } | |||||
int index_of(char const* token) const | |||||
{ | |||||
using namespace std; | |||||
char const *tmp = strstr(C(), token); | |||||
return tmp ? int(tmp - C()) : INDEX_NONE; | |||||
} | |||||
int last_index_of(char token) const | |||||
{ | |||||
using namespace std; | |||||
char const *tmp = strrchr(C(), token); | |||||
return tmp ? int(tmp - C()) : INDEX_NONE; | |||||
} | |||||
int last_index_of(String const& token) const { return last_index_of(token.C()); } | |||||
int last_index_of(char const* token) const | |||||
{ | |||||
using namespace std; | |||||
int token_len = (int)strlen(token); | |||||
for (int i = count() - token_len; i >= 0; --i) | |||||
if (strstr(C() + i, token)) | |||||
return i; | |||||
return -1; | |||||
} | |||||
int count_occurence(String const& token) const { return last_index_of(token.C()); } | |||||
int count_occurence(char const* token) const | |||||
{ | |||||
int count = 0; | |||||
const char *match = strstr(C(), token); | |||||
while (match) | |||||
{ | |||||
count++; | |||||
match = strstr(match + 1, token); | |||||
} | |||||
return count; | |||||
} | |||||
int replace(char const old_token, char const new_token, | int replace(char const old_token, char const new_token, | ||||
bool all_occurrences = false) | bool all_occurrences = false) | ||||
{ | { | ||||
@@ -230,74 +184,6 @@ public: | |||||
return res; | return res; | ||||
} | } | ||||
inline String& to_lower() | |||||
{ | |||||
String ret(*this); | |||||
for (int i = 0; i < ret.count(); ++i) | |||||
{ | |||||
if ('A' <= ret[i] && ret[i] <= 'Z') | |||||
ret[i] += 'a' - 'A'; | |||||
} | |||||
*this = ret; | |||||
return *this; | |||||
} | |||||
inline String& to_upper() | |||||
{ | |||||
String ret(*this); | |||||
for (int i = 0; i < ret.count(); ++i) | |||||
{ | |||||
if ('a' <= ret[i] && ret[i] <= 'z') | |||||
ret[i] += 'A' - 'a'; | |||||
} | |||||
*this = ret; | |||||
return *this; | |||||
} | |||||
inline String& case_change(bool case_to_upper) | |||||
{ | |||||
return case_to_upper ? to_upper() : to_lower(); | |||||
} | |||||
bool starts_with(String const &s) const | |||||
{ | |||||
using namespace std; | |||||
return count() >= s.count() | |||||
&& memcmp(C(), s.C(), s.count()) == 0; | |||||
} | |||||
bool ends_with(String const &s) const | |||||
{ | |||||
using namespace std; | |||||
return count() >= s.count() | |||||
&& memcmp(C() + count() - s.count(), s.C(), s.count()) == 0; | |||||
} | |||||
array<String> split(char c = '\n') const | |||||
{ | |||||
array<String> ret; | |||||
for (int start = 0; start < m_count; ) | |||||
{ | |||||
char const *tmp = strchr(C() + start, c); | |||||
if (!tmp) | |||||
{ | |||||
ret.push(String(C() + start)); | |||||
break; | |||||
} | |||||
int size = int(tmp - C()) - start; | |||||
ret.push(String(C() + start, size)); | |||||
start += size + 1; | |||||
} | |||||
return ret; | |||||
} | |||||
bool is_alpha() const | |||||
{ | |||||
for (int i = 0; i < m_count; i++) | |||||
if (m_data[i] != '\0' && (m_data[i] < '0' || '9' < m_data[i])) | |||||
return false; | |||||
return true; | |||||
} | |||||
inline String operator +(String const &s) const | inline String operator +(String const &s) const | ||||
{ | { | ||||
String ret(*this); | String ret(*this); | ||||
@@ -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 | ||||
@@ -15,7 +17,8 @@ | |||||
// ---------------- | // ---------------- | ||||
// | // | ||||
#include <stdint.h> | |||||
#include <cstdint> | |||||
#include <string> | |||||
#include "engine/entity.h" | #include "engine/entity.h" | ||||
@@ -57,7 +60,7 @@ struct VertexUsageBase : public StructSafeEnum | |||||
}; | }; | ||||
protected: | protected: | ||||
virtual bool BuildEnumMap(map<int64_t, String>& enum_map) | |||||
virtual bool BuildEnumMap(map<int64_t, std::string>& enum_map) | |||||
{ | { | ||||
enum_map[Position] = "Position"; | enum_map[Position] = "Position"; | ||||
enum_map[BlendWeight] = "BlendWeight"; | enum_map[BlendWeight] = "BlendWeight"; | ||||
@@ -99,7 +102,7 @@ struct ShaderVariableBase | |||||
MAX | MAX | ||||
}; | }; | ||||
protected: | protected: | ||||
virtual bool BuildEnumMap(map<int64_t, String>& enum_map) | |||||
virtual bool BuildEnumMap(map<int64_t, std::string>& enum_map) | |||||
{ | { | ||||
enum_map[Attribute] = "Attribute"; | enum_map[Attribute] = "Attribute"; | ||||
enum_map[Uniform] = "Uniform"; | enum_map[Uniform] = "Uniform"; | ||||
@@ -123,7 +126,7 @@ struct ShaderProgramBase | |||||
MAX | MAX | ||||
}; | }; | ||||
protected: | protected: | ||||
virtual bool BuildEnumMap(map<int64_t, String>& enum_map) | |||||
virtual bool BuildEnumMap(map<int64_t, std::string>& enum_map) | |||||
{ | { | ||||
enum_map[Geometry] = "Geometry"; | enum_map[Geometry] = "Geometry"; | ||||
enum_map[Vertex] = "Vertex"; | enum_map[Vertex] = "Vertex"; | ||||
@@ -198,7 +201,7 @@ struct ShaderVariableTypeBase | |||||
MAX | MAX | ||||
}; | }; | ||||
protected: | protected: | ||||
virtual bool BuildEnumMap(map<int64_t, String>& enum_map) | |||||
virtual bool BuildEnumMap(map<int64_t, std::string>& enum_map) | |||||
{ | { | ||||
enum_map[Bool] = "bool"; | enum_map[Bool] = "bool"; | ||||
enum_map[Int] = "int"; enum_map[UInt] = "uint"; | enum_map[Int] = "int"; enum_map[UInt] = "uint"; | ||||
@@ -312,13 +315,13 @@ class ShaderData; | |||||
class Shader : public Entity | class Shader : public Entity | ||||
{ | { | ||||
public: | public: | ||||
static Shader *Create(String const &name, String const &code); | |||||
static Shader *Create(std::string const &name, std::string const &code); | |||||
static void Destroy(Shader *shader); | static void Destroy(Shader *shader); | ||||
int GetAttribCount() const; | int GetAttribCount() const; | ||||
ShaderAttrib GetAttribLocation(VertexUsage usage, int index) const; | ShaderAttrib GetAttribLocation(VertexUsage usage, int index) const; | ||||
ShaderUniform GetUniformLocation(String const& uni) const; | |||||
ShaderUniform GetUniformLocation(std::string const& uni) const; | |||||
ShaderUniform GetUniformLocation(char const *uni) const; | ShaderUniform GetUniformLocation(char const *uni) const; | ||||
void SetUniform(ShaderUniform const &uni, int i); | void SetUniform(ShaderUniform const &uni, int i); | ||||
void SetUniform(ShaderUniform const &uni, ivec2 const &v); | void SetUniform(ShaderUniform const &uni, ivec2 const &v); | ||||
@@ -342,19 +345,19 @@ public: | |||||
void Unbind() const; | void Unbind() const; | ||||
protected: | protected: | ||||
Shader(String const &name, String const &vert, String const &frag); | |||||
Shader(std::string const &name, std::string const &vert, std::string const &frag); | |||||
~Shader(); | ~Shader(); | ||||
private: | private: | ||||
ShaderData *data; | ShaderData *data; | ||||
public: | public: | ||||
static String GetVariablePrefix(const ShaderVariable variable); | |||||
static String GetVariableQualifier(const ShaderVariable variable); | |||||
static String GetFunctionQualifier(const ShaderVariable variable, const ShaderProgram program); | |||||
static String GetProgramQualifier(const ShaderProgram program); | |||||
static String GetProgramOutVariable(const ShaderProgram program); | |||||
static String GetProgramOutVariableLocal(const ShaderProgram program); | |||||
static std::string GetVariablePrefix(const ShaderVariable variable); | |||||
static std::string GetVariableQualifier(const ShaderVariable variable); | |||||
static std::string GetFunctionQualifier(const ShaderVariable variable, const ShaderProgram program); | |||||
static std::string GetProgramQualifier(const ShaderProgram program); | |||||
static std::string GetProgramOutVariable(const ShaderProgram program); | |||||
static std::string GetProgramOutVariableLocal(const ShaderProgram program); | |||||
}; | }; | ||||
//ShaderVar ------------------------------------------------------------------- | //ShaderVar ------------------------------------------------------------------- | ||||
@@ -363,31 +366,31 @@ class ShaderVar | |||||
friend class ShaderBuilder; | friend class ShaderBuilder; | ||||
friend class ShaderBlock; | friend class ShaderBlock; | ||||
protected: | |||||
public: | public: | ||||
ShaderVar() { } | ShaderVar() { } | ||||
ShaderVar(ShaderVariable const& qualifier, String const& type, String const& name) | |||||
ShaderVar(ShaderVariable const& qualifier, std::string const& type, std::string const& name) | |||||
{ | { | ||||
m_qualifier = qualifier; | m_qualifier = qualifier; | ||||
m_type = type; | m_type = type; | ||||
m_name = name; | m_name = name; | ||||
} | } | ||||
ShaderVar(ShaderVariable const& qualifier, ShaderVariableType const& type, String const& name) | |||||
: ShaderVar(qualifier, ShaderVariableType(type).ToString(), name) | |||||
ShaderVar(ShaderVariable const& qualifier, ShaderVariableType const& type, std::string const& name) | |||||
: ShaderVar(qualifier, ShaderVariableType(type).tostring(), name) | |||||
{ } | { } | ||||
~ShaderVar() { } | ~ShaderVar() { } | ||||
inline operator String() const { return Shader::GetVariablePrefix(m_qualifier) + m_name; } | |||||
inline std::string tostring() const { return Shader::GetVariablePrefix(m_qualifier) + m_name; } | |||||
inline ShaderVariable GetQualifier() const { return m_qualifier; } | inline ShaderVariable GetQualifier() const { return m_qualifier; } | ||||
inline String GetType() const { return m_type; } | |||||
inline String operator+(String const& value) { return String() + *this + value; } | |||||
inline std::string GetType() const { return m_type; } | |||||
inline std::string operator+(std::string const& s) { return tostring() + s; } | |||||
static ShaderVar GetShaderOut(ShaderProgram program); | static ShaderVar GetShaderOut(ShaderProgram program); | ||||
protected: | protected: | ||||
ShaderVariable m_qualifier; | ShaderVariable m_qualifier; | ||||
String m_type; | |||||
String m_name; | |||||
std::string m_type; | |||||
std::string m_name; | |||||
}; | }; | ||||
//ShaderBlock ----------------------------------------------------------------- | //ShaderBlock ----------------------------------------------------------------- | ||||
@@ -396,28 +399,28 @@ class ShaderBlock | |||||
friend class ShaderBuilder; | friend class ShaderBuilder; | ||||
protected: | protected: | ||||
String m_name; | |||||
std::string m_name; | |||||
//-------------------------- | //-------------------------- | ||||
//map : <var_name, var_type> | //map : <var_name, var_type> | ||||
//-------------------------- | //-------------------------- | ||||
//Main shader parameters | //Main shader parameters | ||||
map<String, String> m_parameters[ShaderVariable::MAX]; | |||||
map<std::string, std::string> m_parameters[ShaderVariable::MAX]; | |||||
//Actual code | //Actual code | ||||
String m_code_main; | |||||
String m_code_custom; | |||||
std::string m_code_main; | |||||
std::string m_code_custom; | |||||
public: | public: | ||||
ShaderBlock(String const& name) : m_name(name) { } | |||||
ShaderBlock(std::string const& name) : m_name(name) { } | |||||
~ShaderBlock() { } | ~ShaderBlock() { } | ||||
String const& GetName() { return m_name; } | |||||
std::string const& GetName() { return m_name; } | |||||
//Sets code that will be used in the main | //Sets code that will be used in the main | ||||
void SetMainCode(String const& code_main) { m_code_main = code_main; } | |||||
void SetMainCode(std::string const& code_main) { m_code_main = code_main; } | |||||
//Sets custom code that will be put before the main -so functions- | //Sets custom code that will be put before the main -so functions- | ||||
void SetCustomCode(String const& code_custom) { m_code_custom = code_custom; } | |||||
void SetCustomCode(std::string const& code_custom) { m_code_custom = code_custom; } | |||||
//Add parameter to the block | //Add parameter to the block | ||||
void AddVar(ShaderVar const& var); | void AddVar(ShaderVar const& var); | ||||
inline ShaderBlock& operator<<(ShaderVar const& var) | inline ShaderBlock& operator<<(ShaderVar const& var) | ||||
@@ -427,40 +430,40 @@ public: | |||||
} | } | ||||
protected: | protected: | ||||
void AddCallParameters(map<String, String> const& variables, String& result); | |||||
void AddDefinitionParameters(const ShaderVariable variable, const ShaderProgram program, map<String, String>& variables, String& result); | |||||
void Build(const ShaderProgram program, String& call, String& function); | |||||
void AddCallParameters(map<std::string, std::string> const& variables, std::string& result); | |||||
void AddDefinitionParameters(const ShaderVariable variable, const ShaderProgram program, map<std::string, std::string>& variables, std::string& result); | |||||
void Build(const ShaderProgram program, std::string& call, std::string& function); | |||||
}; | }; | ||||
//Shaderbuilder --------------------------------------------------------------- | //Shaderbuilder --------------------------------------------------------------- | ||||
class ShaderBuilder | class ShaderBuilder | ||||
{ | { | ||||
protected: | protected: | ||||
String m_name; | |||||
String m_version; | |||||
std::string m_name; | |||||
std::string m_version; | |||||
ShaderProgram m_current_program = ShaderProgram::MAX; | ShaderProgram m_current_program = ShaderProgram::MAX; | ||||
//Blocks | //Blocks | ||||
array<ShaderBlock*> m_blocks[ShaderProgram::MAX]; | array<ShaderBlock*> m_blocks[ShaderProgram::MAX]; | ||||
//Final shader parameters | //Final shader parameters | ||||
map<String, String> m_parameters[ShaderProgram::MAX][ShaderVariable::MAX]; | |||||
map<std::string, std::string> m_parameters[ShaderProgram::MAX][ShaderVariable::MAX]; | |||||
public: | public: | ||||
ShaderBuilder(String const& name, String const& version); | |||||
ShaderBuilder(std::string const& name, std::string const& version); | |||||
~ShaderBuilder(); | ~ShaderBuilder(); | ||||
String const& GetName(); | |||||
std::string const& GetName(); | |||||
ShaderBuilder& operator<<(const ShaderProgram program); | ShaderBuilder& operator<<(const ShaderProgram program); | ||||
ShaderBuilder& operator<<(ShaderBlock* block); | ShaderBuilder& operator<<(ShaderBlock* block); | ||||
ShaderBuilder& operator<<(ShaderBlock const& block); | ShaderBuilder& operator<<(ShaderBlock const& block); | ||||
protected: | protected: | ||||
String AddSlotOutVariableLocal(const ShaderProgram program); | |||||
void MergeParameters(map<String, String>& variables, map<String, String>& merged); | |||||
std::string AddSlotOutVariableLocal(const ShaderProgram program); | |||||
void MergeParameters(map<std::string, std::string>& variables, map<std::string, std::string>& merged); | |||||
public: | public: | ||||
void Build(String& code); | |||||
void Build(std::string& code); | |||||
}; | }; | ||||
} /* namespace lol */ | } /* namespace lol */ | ||||
@@ -1,7 +1,8 @@ | |||||
// | // | ||||
// imGui integration in lolengine | |||||
// Lol Engine | |||||
// | // | ||||
// Copyright © 2009—2015 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | // Copyright © 2009—2015 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 | ||||
@@ -15,6 +16,11 @@ | |||||
#include "imgui.cpp" | #include "imgui.cpp" | ||||
#include <cstdio> | #include <cstdio> | ||||
#include <string> | |||||
// | |||||
// The Imgui integration | |||||
// | |||||
using namespace lol; | using namespace lol; | ||||
@@ -111,18 +117,18 @@ LolImGui::LolImGui() | |||||
<< out_vertex << m_ortho << in_position | << out_vertex << m_ortho << in_position | ||||
<< pass_texcoord << in_texcoord | << pass_texcoord << in_texcoord | ||||
<< pass_color << in_color; | << pass_color << in_color; | ||||
imgui_vertex.SetMainCode(String() + | |||||
Line(out_vertex + " = .5 *" + m_ortho + " * vec4(" + in_position + ", -1.0, 1.0);") | |||||
+ Line(pass_texcoord + " = " + in_texcoord + ";") | |||||
+ Line(pass_color + " = " + in_color + ";") | |||||
imgui_vertex.SetMainCode(std::string() + | |||||
Line(out_vertex + " = .5 *" + m_ortho.tostring() + " * vec4(" + in_position.tostring() + ", -1.0, 1.0);") | |||||
+ Line(pass_texcoord + " = " + in_texcoord.tostring() + ";") | |||||
+ Line(pass_color + " = " + in_color.tostring() + ";") | |||||
); | ); | ||||
ShaderBlock imgui_pixel("imgui_pixel"); | ShaderBlock imgui_pixel("imgui_pixel"); | ||||
imgui_pixel << m_texture << pass_texcoord << pass_color << out_pixel; | imgui_pixel << m_texture << pass_texcoord << pass_color << out_pixel; | ||||
imgui_pixel.SetMainCode(String() + | |||||
Line(String() | |||||
+ "vec4 col = " + pass_color + " * texture2D(" + m_texture + ", " + pass_texcoord + ");") | |||||
+ Line(String() | |||||
imgui_pixel.SetMainCode(std::string() + | |||||
Line(std::string() | |||||
+ "vec4 col = " + pass_color.tostring() + " * texture2D(" + m_texture.tostring() + ", " + pass_texcoord.tostring() + ");") | |||||
+ Line(std::string() | |||||
+ "if (col.a == 0.0) discard; ") | + "if (col.a == 0.0) discard; ") | ||||
+ Line(out_pixel + " = col;") | + Line(out_pixel + " = col;") | ||||
); | ); | ||||
@@ -135,12 +141,12 @@ LolImGui::LolImGui() | |||||
InputProfile& ip = m_profile; | InputProfile& ip = m_profile; | ||||
ip.AddBindings<LolImGuiKey, LolImGuiKey::KEY_START, LolImGuiKey::KEY_END>(InputProfileType::Keyboard); | ip.AddBindings<LolImGuiKey, LolImGuiKey::KEY_START, LolImGuiKey::KEY_END>(InputProfileType::Keyboard); | ||||
//for (int i = LolImGuiKey::KEY_START; i < LolImGuiKey::KEY_END; ++i) | //for (int i = LolImGuiKey::KEY_START; i < LolImGuiKey::KEY_END; ++i) | ||||
// m_profile << InputProfile::Keyboard(i, LolImGuiKey(i).ToString()); | |||||
// m_profile << InputProfile::Keyboard(i, LolImGuiKey(i).tostring()); | |||||
for (int i = LolImGuiKey::MOUSE_KEY_START; i < LolImGuiKey::MOUSE_KEY_END; ++i) | for (int i = LolImGuiKey::MOUSE_KEY_START; i < LolImGuiKey::MOUSE_KEY_END; ++i) | ||||
m_profile << InputProfile::MouseKey(i, LolImGuiKey(i).ToString()); | |||||
m_profile << InputProfile::MouseKey(i, LolImGuiKey(i).tostring()); | |||||
for (int i = LolImGuiAxis::MOUSE_AXIS_START; i < LolImGuiAxis::MOUSE_AXIS_END; ++i) | for (int i = LolImGuiAxis::MOUSE_AXIS_START; i < LolImGuiAxis::MOUSE_AXIS_END; ++i) | ||||
m_profile << InputProfile::MouseAxis(i, LolImGuiAxis(i).ToString()); | |||||
m_profile << InputProfile::MouseAxis(i, LolImGuiAxis(i).tostring()); | |||||
Ticker::Ref(m_controller = new Controller("ImGui_Controller")); | Ticker::Ref(m_controller = new Controller("ImGui_Controller")); | ||||
m_controller->Init(m_profile); | m_controller->Init(m_profile); | ||||
@@ -221,20 +227,20 @@ void LolImGui::Shutdown() | |||||
} | } | ||||
//----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||||
String LolImGui::GetClipboard() | |||||
std::string LolImGui::GetClipboard() | |||||
{ | { | ||||
return g_lolimgui ? g_lolimgui->m_clipboard : ""; | return g_lolimgui ? g_lolimgui->m_clipboard : ""; | ||||
} | } | ||||
void LolImGui::SetClipboardCallback(void *data, const char* text) | void LolImGui::SetClipboardCallback(void *data, const char* text) | ||||
{ | { | ||||
String *clipboard = (String *)data; | |||||
std::string *clipboard = (std::string *)data; | |||||
*clipboard = text; | *clipboard = text; | ||||
} | } | ||||
const char* LolImGui::GetClipboardCallback(void *data) | const char* LolImGui::GetClipboardCallback(void *data) | ||||
{ | { | ||||
String *clipboard = (String *)data; | |||||
return clipboard->C(); | |||||
std::string *clipboard = (std::string *)data; | |||||
return clipboard->c_str(); | |||||
} | } | ||||
//----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||||
@@ -296,10 +302,10 @@ void LolImGui::TickGame(float seconds) | |||||
m_keyboard->SetTextInputActive(io.WantTextInput); | m_keyboard->SetTextInputActive(io.WantTextInput); | ||||
//Update text input | //Update text input | ||||
String text = m_keyboard->GetText(); | |||||
std::string text = m_keyboard->GetText(); | |||||
//text.case_change(io.KeyShift); | //text.case_change(io.KeyShift); | ||||
for (int i = 0; i < text.count(); ++i) | |||||
io.AddInputCharacter(text[i]); | |||||
for (auto ch : text) | |||||
io.AddInputCharacter(ch); | |||||
//Update mouse | //Update mouse | ||||
if (m_mouse) | if (m_mouse) | ||||
@@ -384,14 +390,14 @@ void LolImGui::RenderDrawListsMethod(ImDrawData* draw_data) | |||||
//Create shader | //Create shader | ||||
if (!m_shader) | if (!m_shader) | ||||
{ | { | ||||
String code; | |||||
std::string code; | |||||
m_builder.Build(code); | m_builder.Build(code); | ||||
m_shader = Shader::Create(m_builder.GetName(), code); | m_shader = Shader::Create(m_builder.GetName(), code); | ||||
ASSERT(m_shader); | ASSERT(m_shader); | ||||
m_ortho.m_uniform = m_shader->GetUniformLocation(m_ortho.m_var); | |||||
m_texture.m_uniform = m_shader->GetUniformLocation(m_texture.m_var); | |||||
m_ortho.m_uniform = m_shader->GetUniformLocation(m_ortho.m_var.tostring()); | |||||
m_texture.m_uniform = m_shader->GetUniformLocation(m_texture.m_var.tostring()); | |||||
m_attribs | m_attribs | ||||
<< m_shader->GetAttribLocation(VertexUsage::Position, 0) | << m_shader->GetAttribLocation(VertexUsage::Position, 0) | ||||
@@ -1,7 +1,8 @@ | |||||
// | // | ||||
// Lol Engine — imGui integration | |||||
// Lol Engine | |||||
// | // | ||||
// Copyright © 2009—2015 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | // Copyright © 2009—2015 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 | ||||
@@ -12,6 +13,12 @@ | |||||
#pragma once | #pragma once | ||||
#include <string> | |||||
// | |||||
// The Imgui integration | |||||
// | |||||
#define IM_VEC2_CLASS_EXTRA ImVec2(const lol::vec2 &v) { x = v.x; y = v.y; } \ | #define IM_VEC2_CLASS_EXTRA ImVec2(const lol::vec2 &v) { x = v.x; y = v.y; } \ | ||||
ImVec2(const lol::ivec2 &v) : ImVec2(lol::vec2(v)) { } \ | ImVec2(const lol::ivec2 &v) : ImVec2(lol::vec2(v)) { } \ | ||||
operator lol::vec2() const { return lol::vec2(x, y); } \ | operator lol::vec2() const { return lol::vec2(x, y); } \ | ||||
@@ -105,7 +112,7 @@ class LolImGui : public Entity | |||||
MAX = MOUSE_KEY_END, | MAX = MOUSE_KEY_END, | ||||
}; | }; | ||||
protected: | protected: | ||||
virtual bool BuildEnumMap(map<int64_t, String>& enum_map) | |||||
virtual bool BuildEnumMap(map<int64_t, std::string>& enum_map) | |||||
{ | { | ||||
enum_map[Tab] = g_name_key_Tab; | enum_map[Tab] = g_name_key_Tab; | ||||
enum_map[LeftArrow] = g_name_key_Left; | enum_map[LeftArrow] = g_name_key_Left; | ||||
@@ -155,7 +162,7 @@ class LolImGui : public Entity | |||||
MAX = MOUSE_AXIS_END, | MAX = MOUSE_AXIS_END, | ||||
}; | }; | ||||
protected: | protected: | ||||
virtual bool BuildEnumMap(map<int64_t, String>& enum_map) | |||||
virtual bool BuildEnumMap(map<int64_t, std::string>& enum_map) | |||||
{ | { | ||||
enum_map[Scroll] = g_name_mouse_axis_scroll; | enum_map[Scroll] = g_name_mouse_axis_scroll; | ||||
@@ -175,7 +182,7 @@ public: | |||||
static void Shutdown(); | static void Shutdown(); | ||||
//------------------------------------------------------------------------- | //------------------------------------------------------------------------- | ||||
static String GetClipboard(); | |||||
static std::string GetClipboard(); | |||||
protected: | protected: | ||||
virtual void TickGame(float seconds); | virtual void TickGame(float seconds); | ||||
@@ -191,9 +198,9 @@ protected: | |||||
{ | { | ||||
Uniform() { } | Uniform() { } | ||||
Uniform(ShaderVar var) { m_var = var; } | Uniform(ShaderVar var) { m_var = var; } | ||||
operator String() { return m_var; } | |||||
operator ShaderVar() { return m_var; } | |||||
operator ShaderUniform() { return m_uniform; } | |||||
std::string tostring() const { return m_var.tostring(); } | |||||
operator ShaderVar() const { return m_var; } | |||||
operator ShaderUniform() const { return m_uniform; } | |||||
//-- | //-- | ||||
ShaderVar m_var; | ShaderVar m_var; | ||||
ShaderUniform m_uniform; | ShaderUniform m_uniform; | ||||
@@ -212,7 +219,7 @@ protected: | |||||
InputDevice* m_keyboard = nullptr; | InputDevice* m_keyboard = nullptr; | ||||
InputProfile m_profile; | InputProfile m_profile; | ||||
//map<ImGuiKey_, LolImGuiKey> m_keys; | //map<ImGuiKey_, LolImGuiKey> m_keys; | ||||
String m_clipboard; | |||||
std::string m_clipboard; | |||||
}; | }; | ||||
//----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||||
@@ -1,7 +1,7 @@ | |||||
// | // | ||||
// Base Lua class for Lua script loading | |||||
// Lol Engine | |||||
// | // | ||||
// Copyright © 2009—2015 Sam Hocevar <sam@hocevar.net> | |||||
// Copyright © 2017—2018 Sam Hocevar <sam@hocevar.net> | |||||
// © 2009—2015 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | // © 2009—2015 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | ||||
// | // | ||||
// Lol Engine is free software. It comes without any warranty, to | // Lol Engine is free software. It comes without any warranty, to | ||||
@@ -14,9 +14,13 @@ | |||||
#include <lol/engine-internal.h> | #include <lol/engine-internal.h> | ||||
#include <lol/lua.h> | #include <lol/lua.h> | ||||
#include <cstring> | |||||
#include <string> | |||||
#include <cstdlib> | #include <cstdlib> | ||||
#include <ctype.h> | |||||
#include <cctype> | |||||
// | |||||
// Base Lua class for Lua script loading | |||||
// | |||||
namespace lol | namespace lol | ||||
{ | { | ||||
@@ -36,14 +40,14 @@ class LuaBaseData | |||||
} | } | ||||
//Exec lua code ----------------------------------------------------------- | //Exec lua code ----------------------------------------------------------- | ||||
static int LuaDoCode(lua_State *l, String const& s) | |||||
static int LuaDoCode(lua_State *l, std::string const& s) | |||||
{ | { | ||||
int status = luaL_dostring(l, s.C()); | |||||
int status = luaL_dostring(l, s.c_str()); | |||||
if (status == 1) | if (status == 1) | ||||
{ | { | ||||
auto stack = LuaStack::Begin(l, -1); | auto stack = LuaStack::Begin(l, -1); | ||||
auto error = stack.Get<String>(); | |||||
msg::error("Lua error %s\n", error.C()); | |||||
auto error = stack.Get<std::string>(); | |||||
msg::error("Lua error %s\n", error.c_str()); | |||||
lua_pop(l, 1); | lua_pop(l, 1); | ||||
} | } | ||||
return status; | return status; | ||||
@@ -65,7 +69,7 @@ class LuaBaseData | |||||
f.Open(candidate, FileAccess::Read); | f.Open(candidate, FileAccess::Read); | ||||
if (f.IsValid()) | if (f.IsValid()) | ||||
{ | { | ||||
String s = f.ReadString(); | |||||
std::string s = f.ReadString().C(); | |||||
f.Close(); | f.Close(); | ||||
msg::debug("loading Lua file %s\n", candidate.C()); | msg::debug("loading Lua file %s\n", candidate.C()); | ||||
@@ -79,8 +83,8 @@ class LuaBaseData | |||||
else if (status == 1) | else if (status == 1) | ||||
{ | { | ||||
stack.SetIndex(-1); | stack.SetIndex(-1); | ||||
auto error = stack.Get<String>(); | |||||
msg::error("Lua error %s\n", error.C()); | |||||
auto error = stack.Get<std::string>(); | |||||
msg::error("Lua error %s\n", error.c_str()); | |||||
lua_pop(l, 1); | lua_pop(l, 1); | ||||
} | } | ||||
@@ -150,15 +154,15 @@ void Loader::StoreObject(lua_State* l, Object* obj) | |||||
} | } | ||||
//----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||||
bool Loader::ExecLuaFile(String const &lua) | |||||
bool Loader::ExecLuaFile(std::string const &lua) | |||||
{ | { | ||||
lua_pushstring(m_lua_state, lua.C()); | |||||
lua_pushstring(m_lua_state, lua.c_str()); | |||||
int status = LuaBaseData::LuaDoFile(m_lua_state); | int status = LuaBaseData::LuaDoFile(m_lua_state); | ||||
return status == 0; | return status == 0; | ||||
} | } | ||||
//----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||||
bool Loader::ExecLuaCode(String const &lua) | |||||
bool Loader::ExecLuaCode(std::string const &lua) | |||||
{ | { | ||||
return 0 == LuaBaseData::LuaDoCode(m_lua_state, lua); | return 0 == LuaBaseData::LuaDoCode(m_lua_state, lua); | ||||
} | } | ||||
@@ -1,7 +1,7 @@ | |||||
// | // | ||||
// Lol Engine — base class for Lua script loading | |||||
// Lol Engine | |||||
// | // | ||||
// Copyright © 2009—2015 Sam Hocevar <sam@hocevar.net> | |||||
// Copyright © 2017—2018 Sam Hocevar <sam@hocevar.net> | |||||
// © 2009—2015 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | // © 2009—2015 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | ||||
// | // | ||||
// Lol Engine is free software. It comes without any warranty, to | // Lol Engine is free software. It comes without any warranty, to | ||||
@@ -11,10 +11,16 @@ | |||||
// See http://www.wtfpl.net/ for more details. | // See http://www.wtfpl.net/ for more details. | ||||
// | // | ||||
#pragma once | |||||
#include "3rdparty/lua/src/lua.hpp" | #include "3rdparty/lua/src/lua.hpp" | ||||
//#include "lua/luawrapper.hpp" | //#include "lua/luawrapper.hpp" | ||||
#pragma once | |||||
#include <string> | |||||
// | |||||
// Base Lua class for Lua script loading | |||||
// | |||||
namespace lol | namespace lol | ||||
{ | { | ||||
@@ -42,20 +48,20 @@ public: | |||||
typedef struct ClassVarStr | typedef struct ClassVarStr | ||||
{ | { | ||||
ClassVarStr() { } | ClassVarStr() { } | ||||
ClassVarStr(String var_name, lua_CFunction get, lua_CFunction set) | |||||
ClassVarStr(std::string const &var_name, lua_CFunction get, lua_CFunction set) | |||||
{ | { | ||||
m_get_name = String("Get") + var_name; | |||||
m_set_name = String("Set") + var_name; | |||||
m_get_name = std::string("Get") + var_name; | |||||
m_set_name = std::string("Set") + var_name; | |||||
m_get = get; | m_get = get; | ||||
m_set = set; | m_set = set; | ||||
} | } | ||||
String m_get_name = ""; | |||||
String m_set_name = ""; | |||||
std::string m_get_name = ""; | |||||
std::string m_set_name = ""; | |||||
lua_CFunction m_get = nullptr; | lua_CFunction m_get = nullptr; | ||||
lua_CFunction m_set = nullptr; | lua_CFunction m_set = nullptr; | ||||
} ClassVarStr; | } ClassVarStr; | ||||
Library(String class_name, | |||||
Library(std::string const &class_name, | |||||
array<ClassMethod> const& statics, | array<ClassMethod> const& statics, | ||||
array<ClassMethod> const& methods, | array<ClassMethod> const& methods, | ||||
array<ClassVar> const& variables) | array<ClassVar> const& variables) | ||||
@@ -89,9 +95,9 @@ public: | |||||
|| variables.last().set != nullptr) | || variables.last().set != nullptr) | ||||
m_variables.push(ClassVarStr()); | m_variables.push(ClassVarStr()); | ||||
} | } | ||||
String m_class_name = ""; | |||||
String m_static_name = ""; | |||||
String m_method_name = ""; | |||||
std::string m_class_name = ""; | |||||
std::string m_static_name = ""; | |||||
std::string m_method_name = ""; | |||||
array<ClassMethod> m_statics; | array<ClassMethod> m_statics; | ||||
array<ClassMethod> m_methods; | array<ClassMethod> m_methods; | ||||
array<ClassVarStr> m_variables; | array<ClassVarStr> m_variables; | ||||
@@ -172,11 +178,11 @@ public: | |||||
//Add getter | //Add getter | ||||
lua_pushcfunction(l, var.m_get); | lua_pushcfunction(l, var.m_get); | ||||
lua_setfield(l, -2, var.m_get_name.C()); | |||||
lua_setfield(l, -2, var.m_get_name.c_str()); | |||||
//Add setter | //Add setter | ||||
lua_pushcfunction(l, var.m_set); | lua_pushcfunction(l, var.m_set); | ||||
lua_setfield(l, -2, var.m_set_name.C()); | |||||
lua_setfield(l, -2, var.m_set_name.c_str()); | |||||
} | } | ||||
//Don't set it to global, but pop the stack to hide the metatable | //Don't set it to global, but pop the stack to hide the metatable | ||||
@@ -196,11 +202,11 @@ private: | |||||
public: | public: | ||||
//------------------------------------------------------------------------- | //------------------------------------------------------------------------- | ||||
template <typename TLuaClass> | template <typename TLuaClass> | ||||
static const char* GetObjectName() { return GetLibrary<TLuaClass>()->m_class_name.C(); } | |||||
static const char* GetObjectName() { return GetLibrary<TLuaClass>()->m_class_name.c_str(); } | |||||
template <typename TLuaClass> | template <typename TLuaClass> | ||||
static const char* GetStaticName() { return GetLibrary<TLuaClass>()->m_static_name.C(); } | |||||
static const char* GetStaticName() { return GetLibrary<TLuaClass>()->m_static_name.c_str(); } | |||||
template <typename TLuaClass> | template <typename TLuaClass> | ||||
static const char* GetMethodName() { return GetLibrary<TLuaClass>()->m_method_name.C(); } | |||||
static const char* GetMethodName() { return GetLibrary<TLuaClass>()->m_method_name.c_str(); } | |||||
template <typename TLuaClass> | template <typename TLuaClass> | ||||
static const ClassMethod* GetStaticMethods() { return GetLibrary<TLuaClass>()->m_statics.data(); } | static const ClassMethod* GetStaticMethods() { return GetLibrary<TLuaClass>()->m_statics.data(); } | ||||
template <typename TLuaClass> | template <typename TLuaClass> | ||||
@@ -379,9 +385,9 @@ protected: | |||||
#ifndef INNER_SAFE_ENUM | #ifndef INNER_SAFE_ENUM | ||||
template<typename E> SafeEnum<E> InnerDefaultSafeEnum() { return SafeEnum<E>(); } | template<typename E> SafeEnum<E> InnerDefaultSafeEnum() { return SafeEnum<E>(); } | ||||
template<typename E> bool InnerIsValidSafeEnum() { return InnerIsValid<String>(); } | |||||
template<typename E> SafeEnum<E> InnerGetSafeEnum(SafeEnum<E> value) { return FindValue<SafeEnum<E> >(InnerGet<String>(value.ToString())); } | |||||
template<typename E> int InnerPushSafeEnum(SafeEnum<E> value) { return InnerPush<String>(value.ToString()); } | |||||
template<typename E> bool InnerIsValidSafeEnum() { return InnerIsValid<std::string>(); } | |||||
template<typename E> SafeEnum<E> InnerGetSafeEnum(SafeEnum<E> value) { return FindValue<SafeEnum<E> >(InnerGet<std::string>(value.tostring())); } | |||||
template<typename E> int InnerPushSafeEnum(SafeEnum<E> value) { return InnerPush<std::string>(value.tostring()); } | |||||
#endif //STACK_STRING | #endif //STACK_STRING | ||||
#ifndef INNER_PTR | #ifndef INNER_PTR | ||||
@@ -498,10 +504,10 @@ template<> inline int Stack::InnerPush<char const*>(char const* value) { | |||||
//----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||||
#ifndef STACK_STRING | #ifndef STACK_STRING | ||||
template<> inline String Stack::InnerDefault<String>() { return String(); } | |||||
template<> inline bool Stack::InnerIsValid<String>() { return InnerIsValid<char const*>(); } | |||||
template<> inline String Stack::InnerGet<String>(String value) { return String(InnerGet<char const*>(value.C())); } | |||||
template<> inline int Stack::InnerPush<String>(String value) { return InnerPush<char const*>(value.C()); } | |||||
template<> inline std::string Stack::InnerDefault<std::string>() { return ""; } | |||||
template<> inline bool Stack::InnerIsValid<std::string>() { return InnerIsValid<char const*>(); } | |||||
template<> inline std::string Stack::InnerGet<std::string>(std::string value) { return std::string(InnerGet<char const*>(value.c_str())); } | |||||
template<> inline int Stack::InnerPush<std::string>(std::string value) { return InnerPush<char const*>(value.c_str()); } | |||||
#endif //STACK_STRING | #endif //STACK_STRING | ||||
//----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||||
@@ -577,15 +583,15 @@ public: | |||||
Loader(); | Loader(); | ||||
virtual ~Loader(); | virtual ~Loader(); | ||||
bool ExecLuaFile(String const &lua); | |||||
bool ExecLuaCode(String const &lua); | |||||
bool ExecLuaFile(std::string const &lua); | |||||
bool ExecLuaCode(std::string const &lua); | |||||
//------------------------------------------------------------------------- | //------------------------------------------------------------------------- | ||||
#define DECLARE_LOADER_GET(T0, T1, GET_NAME) \ | #define DECLARE_LOADER_GET(T0, T1, GET_NAME) \ | ||||
template<typename T0> \ | template<typename T0> \ | ||||
T1 GET_NAME(String const &name) \ | |||||
T1 GET_NAME(std::string const &name) \ | |||||
{ \ | { \ | ||||
lua_getglobal(m_lua_state, name.C()); \ | |||||
lua_getglobal(m_lua_state, name.c_str()); \ | |||||
auto stack = Lolua::Stack::Begin(m_lua_state, -1); \ | auto stack = Lolua::Stack::Begin(m_lua_state, -1); \ | ||||
auto result = stack.GET_NAME<T0>(); \ | auto result = stack.GET_NAME<T0>(); \ | ||||
lua_pop(m_lua_state, 1); \ | lua_pop(m_lua_state, 1); \ | ||||
@@ -1,16 +1,19 @@ | |||||
// | // | ||||
// Lol Engine | |||||
// Lol Engine | |||||
// | // | ||||
// Copyright: (c) 2013 Benjamin "Touky" Huet <huet.benjamin@gmail.com> | |||||
// 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 © 2013—2015 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 | |||||
// 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> | ||||
#include <string> | |||||
#include <cstring> | #include <cstring> | ||||
#include <cstdlib> | #include <cstdlib> | ||||
#include <time.h> | #include <time.h> | ||||
@@ -24,7 +27,7 @@ extern "C" | |||||
{ | { | ||||
int C_Send(const char* message) { return (int)MessageService::Send(MessageBucket::AppIn, message); } | int C_Send(const char* message) { return (int)MessageService::Send(MessageBucket::AppIn, message); } | ||||
//NOT IMPLEMENTED | //NOT IMPLEMENTED | ||||
//bool C_FetchFirst(String& message); | |||||
//bool C_FetchFirst(std::string& message); | |||||
} | } | ||||
#endif //EMSCRIPTEN | #endif //EMSCRIPTEN | ||||
@@ -59,31 +62,20 @@ void MessageService::Destroy() | |||||
} | } | ||||
//----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||||
bool MessageService::Send(MessageBucket id, const String& message) | |||||
{ | |||||
if (g_messageservice) | |||||
{ | |||||
ASSERT(0 <= id.ToScalar() && id.ToScalar() < g_messageservice->m_bucket.count()); | |||||
return g_messageservice->Send(id, message.C()); | |||||
} | |||||
return false; | |||||
} | |||||
bool MessageService::Send(MessageBucket id, const char* message) | |||||
bool MessageService::Send(MessageBucket id, const std::string& message) | |||||
{ | { | ||||
if (g_messageservice) | if (g_messageservice) | ||||
{ | { | ||||
ASSERT(0 <= id.ToScalar() && id.ToScalar() < g_messageservice->m_bucket.count()); | |||||
MessageService& g = *g_messageservice; | MessageService& g = *g_messageservice; | ||||
array<MessageList>& bucket = g.m_bucket[id.ToScalar()]; | array<MessageList>& bucket = g.m_bucket[id.ToScalar()]; | ||||
bucket << MessageList(time(nullptr), String(message)); | |||||
bucket << MessageList(time(nullptr), message); | |||||
return true; | return true; | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
//---- | //---- | ||||
bool MessageService::FetchFirst(MessageBucket id, String& message) | |||||
bool MessageService::FetchFirst(MessageBucket id, std::string& message) | |||||
{ | { | ||||
if (g_messageservice) | if (g_messageservice) | ||||
{ | { | ||||
@@ -94,7 +86,7 @@ bool MessageService::FetchFirst(MessageBucket id, String& message) | |||||
return false; | return false; | ||||
} | } | ||||
bool MessageService::FetchFirst(MessageBucket id, String& message, time_t& timestamp) | |||||
bool MessageService::FetchFirst(MessageBucket id, std::string& message, time_t& timestamp) | |||||
{ | { | ||||
if (g_messageservice) | if (g_messageservice) | ||||
{ | { | ||||
@@ -114,7 +106,7 @@ bool MessageService::FetchFirst(MessageBucket id, String& message, time_t& times | |||||
} | } | ||||
//---- | //---- | ||||
bool MessageService::FetchAll(MessageBucket id, String& message) | |||||
bool MessageService::FetchAll(MessageBucket id, std::string& message) | |||||
{ | { | ||||
if (g_messageservice) | if (g_messageservice) | ||||
{ | { | ||||
@@ -125,14 +117,14 @@ bool MessageService::FetchAll(MessageBucket id, String& message) | |||||
return false; | return false; | ||||
} | } | ||||
bool MessageService::FetchAll(MessageBucket id, String& message, time_t& first_timestamp) | |||||
bool MessageService::FetchAll(MessageBucket id, std::string& message, time_t& first_timestamp) | |||||
{ | { | ||||
if (g_messageservice) | if (g_messageservice) | ||||
{ | { | ||||
ASSERT(0 <= id.ToScalar() && id.ToScalar() < g_messageservice->m_bucket.count()); | ASSERT(0 <= id.ToScalar() && id.ToScalar() < g_messageservice->m_bucket.count()); | ||||
MessageService& g = *g_messageservice; | MessageService& g = *g_messageservice; | ||||
array<MessageList>& bucket = g.m_bucket[id.ToScalar()]; | array<MessageList>& bucket = g.m_bucket[id.ToScalar()]; | ||||
message = String(""); | |||||
message = ""; | |||||
if (bucket.count()) | if (bucket.count()) | ||||
{ | { | ||||
@@ -1,19 +1,23 @@ | |||||
// | // | ||||
// Lol Engine | |||||
// Lol Engine | |||||
// | // | ||||
// Copyright: (c) 2013 Benjamin "Touky" Huet <huet.benjamin@gmail.com> | |||||
// (c) 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 © 2013—2015 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 | |||||
// 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 | ||||
#include <string> | |||||
// | // | ||||
// The Message Service class | // The Message Service class | ||||
// ---------------- | |||||
// ------------------------- | |||||
// | // | ||||
namespace lol | namespace lol | ||||
@@ -41,7 +45,7 @@ struct MessageBucketBase : public StructSafeEnum | |||||
MAX | MAX | ||||
}; | }; | ||||
protected: | protected: | ||||
virtual bool BuildEnumMap(map<int64_t, String>& enum_map) | |||||
virtual bool BuildEnumMap(map<int64_t, std::string>& enum_map) | |||||
{ | { | ||||
enum_map[AppIn] = "AppIn"; | enum_map[AppIn] = "AppIn"; | ||||
enum_map[AppOut] = "AppOut"; | enum_map[AppOut] = "AppOut"; | ||||
@@ -64,14 +68,14 @@ typedef SafeEnum<MessageBucketBase> MessageBucket; | |||||
//Message list container with time in it | //Message list container with time in it | ||||
struct MessageList | struct MessageList | ||||
{ | { | ||||
MessageList(time_t timestamp, const String& message) | |||||
MessageList(time_t timestamp, const std::string& message) | |||||
: m_timestamp(timestamp), | |||||
m_message(message) | |||||
{ | { | ||||
m_timestamp = timestamp; | |||||
m_message = message; | |||||
} | } | ||||
time_t m_timestamp; | |||||
String m_message; | |||||
time_t m_timestamp; | |||||
std::string m_message; | |||||
}; | }; | ||||
/* | /* | ||||
@@ -91,12 +95,11 @@ public: | |||||
static void Destroy(); | static void Destroy(); | ||||
//Common interactions | //Common interactions | ||||
static bool Send(MessageBucket id, const String& message); | |||||
static bool Send(MessageBucket id, const char* message); | |||||
static bool FetchFirst(MessageBucket id, String& message); | |||||
static bool FetchFirst(MessageBucket id, String& message, time_t ×tamp); | |||||
static bool FetchAll(MessageBucket id, String& message); | |||||
static bool FetchAll(MessageBucket id, String& message, time_t &first_timestamp); | |||||
static bool Send(MessageBucket id, const std::string& message); | |||||
static bool FetchFirst(MessageBucket id, std::string& message); | |||||
static bool FetchFirst(MessageBucket id, std::string& message, time_t ×tamp); | |||||
static bool FetchAll(MessageBucket id, std::string& message); | |||||
static bool FetchAll(MessageBucket id, std::string& message, time_t &first_timestamp); | |||||
private: | private: | ||||
array<array<MessageList> > m_bucket; | array<array<MessageList> > m_bucket; | ||||
@@ -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 | ||||
@@ -14,6 +14,8 @@ | |||||
#include <lolunit.h> | #include <lolunit.h> | ||||
#include <string> | |||||
namespace lol | namespace lol | ||||
{ | { | ||||
@@ -31,7 +33,7 @@ lolunit_declare_fixture(enum_test) | |||||
}; | }; | ||||
protected: | protected: | ||||
virtual bool BuildEnumMap(map<int64_t, String>& enum_map) | |||||
virtual bool BuildEnumMap(map<int64_t, std::string>& enum_map) | |||||
{ | { | ||||
enum_map[first] = "first"; | enum_map[first] = "first"; | ||||
enum_map[second] = "second"; | enum_map[second] = "second"; | ||||
@@ -42,18 +44,18 @@ lolunit_declare_fixture(enum_test) | |||||
typedef SafeEnum<my_enum_base> my_enum; | typedef SafeEnum<my_enum_base> my_enum; | ||||
my_enum e = my_enum::first; | my_enum e = my_enum::first; | ||||
lolunit_assert(e.ToString() == "first"); | |||||
lolunit_assert(e.tostring() == "first"); | |||||
e = my_enum::second; | e = my_enum::second; | ||||
lolunit_assert(e.ToString() == "second"); | |||||
lolunit_assert(e.tostring() == "second"); | |||||
e = my_enum::third; | e = my_enum::third; | ||||
lolunit_assert(e.ToString() == "third"); | |||||
lolunit_assert(e.tostring() == "third"); | |||||
e = my_enum(42); | e = my_enum(42); | ||||
lolunit_assert(e.ToString() != "first"); | |||||
lolunit_assert(e.ToString() != "second"); | |||||
lolunit_assert(e.ToString() != "third"); | |||||
lolunit_assert(e.tostring() != "first"); | |||||
lolunit_assert(e.tostring() != "second"); | |||||
lolunit_assert(e.tostring() != "third"); | |||||
} | } | ||||
}; | }; | ||||
@@ -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> | |||||
// © 2014—2015 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | // © 2014—2015 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | ||||
// | // | ||||
// Lol Engine is free software. It comes without any warranty, to | // Lol Engine is free software. It comes without any warranty, to | ||||
@@ -13,6 +13,8 @@ | |||||
#include <lol/engine-internal.h> | #include <lol/engine-internal.h> | ||||
#include <string> | |||||
#include <lolunit.h> | #include <lolunit.h> | ||||
namespace lol | namespace lol | ||||
@@ -20,130 +22,6 @@ namespace lol | |||||
lolunit_declare_fixture(string_test) | lolunit_declare_fixture(string_test) | ||||
{ | { | ||||
lolunit_declare_test(string_build) | |||||
{ | |||||
String s1; | |||||
lolunit_assert_equal(s1.count(), 0); | |||||
lolunit_assert_equal(s1[0], '\0'); | |||||
String s2(""); | |||||
lolunit_assert_equal(s2.count(), 0); | |||||
lolunit_assert_equal(s2[0], '\0'); | |||||
String s3("a"); | |||||
lolunit_assert_equal(s3.count(), 1); | |||||
lolunit_assert_equal(s3[0], 'a'); | |||||
lolunit_assert_equal(s3[1], '\0'); | |||||
String s4(s3); | |||||
lolunit_assert_equal(s4.count(), 1); | |||||
lolunit_assert_equal(s4[0], 'a'); | |||||
lolunit_assert_equal(s4[1], '\0'); | |||||
} | |||||
lolunit_declare_test(string_append_char) | |||||
{ | |||||
String s; | |||||
s += 'a'; | |||||
s += 'b'; | |||||
s += 'c'; | |||||
lolunit_assert_equal(s[0], 'a'); | |||||
lolunit_assert_equal(s[1], 'b'); | |||||
lolunit_assert_equal(s[2], 'c'); | |||||
lolunit_assert_equal(s[3], '\0'); | |||||
} | |||||
lolunit_declare_test(string_copy) | |||||
{ | |||||
String s1 = "abc"; | |||||
String s2 = s1; | |||||
lolunit_assert_equal(s1[0], s2[0]); | |||||
lolunit_assert_equal(s1[1], s2[1]); | |||||
lolunit_assert_equal(s1[2], s2[2]); | |||||
lolunit_assert_equal(s1[3], s2[3]); | |||||
} | |||||
lolunit_declare_test(string_concat) | |||||
{ | |||||
String s1("ab"), s2("cd"); | |||||
String s3 = s1 + s2; | |||||
lolunit_assert_equal(s3[0], 'a'); | |||||
lolunit_assert_equal(s3[1], 'b'); | |||||
lolunit_assert_equal(s3[2], 'c'); | |||||
lolunit_assert_equal(s3[3], 'd'); | |||||
lolunit_assert_equal(s3[4], '\0'); | |||||
} | |||||
lolunit_declare_test(string_append_string) | |||||
{ | |||||
String s1("ab"), s2("cd"); | |||||
s1 += s2; | |||||
lolunit_assert_equal(s1.count(), 4); | |||||
lolunit_assert_equal(s1[0], 'a'); | |||||
lolunit_assert_equal(s1[1], 'b'); | |||||
lolunit_assert_equal(s1[2], 'c'); | |||||
lolunit_assert_equal(s1[3], 'd'); | |||||
lolunit_assert_equal(s1[4], '\0'); | |||||
s2 += s2; | |||||
lolunit_assert_equal(s2.count(), 4); | |||||
lolunit_assert_equal(s2[0], 'c'); | |||||
lolunit_assert_equal(s2[1], 'd'); | |||||
lolunit_assert_equal(s2[2], 'c'); | |||||
lolunit_assert_equal(s2[3], 'd'); | |||||
lolunit_assert_equal(s2[4], '\0'); | |||||
} | |||||
lolunit_declare_test(string_equal) | |||||
{ | |||||
String s1("abc"); | |||||
String s2("abc"); | |||||
String s3("ab"); | |||||
lolunit_assert(s1 == s2); | |||||
lolunit_assert(!(s1 == s3)); | |||||
} | |||||
lolunit_declare_test(string_different) | |||||
{ | |||||
String s1("abc"); | |||||
String s2("ab"); | |||||
String s3("abc"); | |||||
lolunit_assert(s1 != s2); | |||||
lolunit_assert(!(s1 != s3)); | |||||
} | |||||
lolunit_declare_test(string_chars_equal) | |||||
{ | |||||
char const* sz = "abc"; | |||||
String s1("abc"); | |||||
String s2("ab"); | |||||
lolunit_assert(s1 == sz); | |||||
lolunit_assert(sz == s1); | |||||
lolunit_assert(!(s2 == sz)); | |||||
lolunit_assert(!(sz == s2)); | |||||
} | |||||
lolunit_declare_test(string_chars_different) | |||||
{ | |||||
char const* sz = "abc"; | |||||
String s1("ab"); | |||||
String s2("abc"); | |||||
lolunit_assert(s1 != sz); | |||||
lolunit_assert(sz != s1); | |||||
lolunit_assert(!(s2 != sz)); | |||||
lolunit_assert(!(sz != s2)); | |||||
} | |||||
lolunit_declare_test(string_format) | lolunit_declare_test(string_format) | ||||
{ | { | ||||
std::string s1 = "3a"; | std::string s1 = "3a"; | ||||
@@ -157,113 +35,42 @@ lolunit_declare_fixture(string_test) | |||||
lolunit_assert(s3 == s4); | lolunit_assert(s3 == s4); | ||||
} | } | ||||
lolunit_declare_test(substring) | |||||
{ | |||||
String s1 = "Hello World"; | |||||
String s2 = s1.sub(0, 5); | |||||
String s3 = "Hello"; | |||||
lolunit_assert(s2 == s3); | |||||
String s4 = s1.sub(6, 5); | |||||
String s5 = "World"; | |||||
lolunit_assert(s4 == s5); | |||||
} | |||||
lolunit_declare_test(index_of) | |||||
{ | |||||
String s1 = "Hello World"; | |||||
int i1 = s1.index_of('H'); | |||||
int i2 = s1.index_of('W'); | |||||
int i3 = s1.index_of('d'); | |||||
int i4 = s1.index_of("Hello"); | |||||
int i5 = s1.index_of("World"); | |||||
int i6 = s1.index_of("lo"); | |||||
int i7 = s1.index_of("Hello World"); | |||||
int i8 = s1.index_of("Sup' dude"); | |||||
lolunit_assert(i1 == 0); | |||||
lolunit_assert(i2 == 6); | |||||
lolunit_assert(i3 == 10); | |||||
lolunit_assert(i4 == i1); | |||||
lolunit_assert(i5 == i2); | |||||
lolunit_assert(i6 == 3); | |||||
lolunit_assert(i7 == 0); | |||||
lolunit_assert(i8 == -1); | |||||
} | |||||
lolunit_declare_test(last_index_of) | |||||
{ | |||||
String s1 = "Hello World"; | |||||
int i1 = s1.last_index_of('H'); | |||||
int i2 = s1.last_index_of('W'); | |||||
int i3 = s1.last_index_of('d'); | |||||
int i4 = s1.last_index_of("Hello"); | |||||
int i5 = s1.last_index_of("World"); | |||||
int i6 = s1.last_index_of("lo"); | |||||
int i7 = s1.last_index_of("Hello World"); | |||||
int i8 = s1.last_index_of("Sup' dude"); | |||||
int i9 = s1.last_index_of('l'); | |||||
lolunit_assert(i1 == 0); | |||||
lolunit_assert(i2 == 6); | |||||
lolunit_assert(i3 == 10); | |||||
lolunit_assert(i4 == i1); | |||||
lolunit_assert(i5 == i2); | |||||
lolunit_assert(i6 == 3); | |||||
lolunit_assert(i7 == 0); | |||||
lolunit_assert(i8 == -1); | |||||
lolunit_assert(i9 == 9); | |||||
} | |||||
lolunit_declare_test(starts_ends_with) | lolunit_declare_test(starts_ends_with) | ||||
{ | { | ||||
String s = "lolilol"; | |||||
lolunit_assert(s.starts_with("loli")); | |||||
lolunit_assert(!s.starts_with("lolo")); | |||||
lolunit_assert(!s.starts_with("lolilolilol")); | |||||
lolunit_assert(s.ends_with("ilol")); | |||||
lolunit_assert(!s.ends_with("olol")); | |||||
lolunit_assert(!s.ends_with("lolilolilol")); | |||||
} | |||||
std::string s = "lolilol"; | |||||
lolunit_declare_test(string_compare) | |||||
{ | |||||
String s1 = "lolilol"; | |||||
String s2 = s1; | |||||
String s3 = "trololol"; | |||||
String s4 = "lolilololol"; | |||||
lolunit_assert(starts_with(s, "loli")); | |||||
lolunit_assert(!starts_with(s, "lolo")); | |||||
lolunit_assert(!starts_with(s, "lolilolilol")); | |||||
lolunit_assert(!(s1 < s2)); | |||||
lolunit_assert(!(s2 < s1)); | |||||
lolunit_assert(s1 < s3); | |||||
lolunit_assert(s1 < s4); | |||||
lolunit_assert(!(s4 < s1)); | |||||
lolunit_assert(ends_with(s, "ilol")); | |||||
lolunit_assert(!ends_with(s, "olol")); | |||||
lolunit_assert(!ends_with(s, "lolilolilol")); | |||||
} | } | ||||
lolunit_declare_test(string_split) | lolunit_declare_test(string_split) | ||||
{ | { | ||||
auto l1 = String("abc").split(); | |||||
auto l1 = split(std::string("abc")); | |||||
lolunit_assert(l1.count() == 1); | lolunit_assert(l1.count() == 1); | ||||
lolunit_assert(l1[0] == "abc"); | lolunit_assert(l1[0] == "abc"); | ||||
auto l2 = String("\nabc").split(); | |||||
auto l2 = split(std::string("\nabc")); | |||||
lolunit_assert(l2.count() == 2); | lolunit_assert(l2.count() == 2); | ||||
lolunit_assert(l2[0] == ""); | lolunit_assert(l2[0] == ""); | ||||
lolunit_assert(l2[1] == "abc"); | lolunit_assert(l2[1] == "abc"); | ||||
auto l3 = String("abc\n").split(); | |||||
auto l3 = split(std::string("abc\n")); | |||||
lolunit_assert(l3.count() == 2); | lolunit_assert(l3.count() == 2); | ||||
lolunit_assert(l3[0] == "abc"); | lolunit_assert(l3[0] == "abc"); | ||||
lolunit_assert(l3[1] == ""); | lolunit_assert(l3[1] == ""); | ||||
auto l4 = String("\n\n").split(); | |||||
auto l4 = split(std::string("\n\n")); | |||||
lolunit_assert(l4.count() == 3); | lolunit_assert(l4.count() == 3); | ||||
lolunit_assert(l4[0] == ""); | lolunit_assert(l4[0] == ""); | ||||
lolunit_assert(l4[1] == ""); | lolunit_assert(l4[1] == ""); | ||||
lolunit_assert(l4[2] == ""); | lolunit_assert(l4[2] == ""); | ||||
auto l5 = String("abc\nde\n\nf\n").split(); | |||||
auto l5 = split(std::string("abc\nde\n\nf\n")); | |||||
lolunit_assert(l5.count() == 5); | lolunit_assert(l5.count() == 5); | ||||
lolunit_assert(l5[0] == "abc"); | lolunit_assert(l5[0] == "abc"); | ||||
lolunit_assert(l5[1] == "de"); | lolunit_assert(l5[1] == "de"); | ||||
@@ -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> | |||||
// © 2014—2015 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | // © 2014—2015 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | ||||
// | // | ||||
// Lol Engine is free software. It comes without any warranty, to | // Lol Engine is free software. It comes without any warranty, to | ||||
@@ -13,6 +13,8 @@ | |||||
#include <lol/engine-internal.h> | #include <lol/engine-internal.h> | ||||
#include <string> | |||||
#include <lolunit.h> | #include <lolunit.h> | ||||
namespace lol | namespace lol | ||||
@@ -61,7 +63,7 @@ lolunit_declare_fixture(thread_test) | |||||
DONE, | DONE, | ||||
}; | }; | ||||
protected: | protected: | ||||
virtual bool BuildEnumMap(map<int64_t, String>& enum_map) | |||||
virtual bool BuildEnumMap(map<int64_t, std::string>& enum_map) | |||||
{ | { | ||||
enum_map[NOT_QUEUED] = "NOT_QUEUED"; | enum_map[NOT_QUEUED] = "NOT_QUEUED"; | ||||
enum_map[QUEUED] = "QUEUED"; | enum_map[QUEUED] = "QUEUED"; | ||||
@@ -99,7 +101,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()); | |||||
msg::info("%s TICKGAME %s\n", GetName(), m_status.tostring().c_str()); | |||||
m_status = UnitTestStatus::QUEUED; | m_status = UnitTestStatus::QUEUED; | ||||
} | } | ||||
break; | break; | ||||
@@ -110,14 +112,14 @@ lolunit_declare_fixture(thread_test) | |||||
if (GetDispatchedCount()) | if (GetDispatchedCount()) | ||||
#endif | #endif | ||||
{ | { | ||||
msg::info("%s TICKGAME %s\n", GetName(), m_status.ToString().C()); | |||||
msg::info("%s TICKGAME %s\n", GetName(), 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()); | |||||
msg::info("%s TICKGAME %s\n", GetName(), m_status.tostring().c_str()); | |||||
m_status = UnitTestStatus::DONE; | m_status = UnitTestStatus::DONE; | ||||
} | } | ||||
break; | break; | ||||
@@ -1,7 +1,7 @@ | |||||
// | // | ||||
// Lol Engine | // Lol Engine | ||||
// | // | ||||
// Copyright © 2010—2015 Sam Hocevar <sam@hocevar.net> | |||||
// Copyright © 2010—2018 Sam Hocevar <sam@hocevar.net> | |||||
// © 2012—2015 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | // © 2012—2015 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | ||||
// | // | ||||
// Lol Engine is free software. It comes without any warranty, to | // Lol Engine is free software. It comes without any warranty, to | ||||
@@ -15,11 +15,13 @@ | |||||
// | // | ||||
// Various basic convenience functions | // Various basic convenience functions | ||||
// ------------------ | |||||
// ----------------------------------- | |||||
// | // | ||||
#include <lol/base/string.h> | #include <lol/base/string.h> | ||||
#include <string> | |||||
namespace lol | namespace lol | ||||
{ | { | ||||
@@ -60,22 +62,12 @@ template< class T > inline int GetRandom(array<T> src) | |||||
} | } | ||||
// Gets the value for the given enum type. | // Gets the value for the given enum type. | ||||
template<class T> inline T FindValue(const char* name) | |||||
{ | |||||
auto str = String(name); | |||||
return FindValue<T>(str); | |||||
} | |||||
template<class T> inline T FindValue(String const& name) | |||||
template<class T> inline T FindValue(std::string const& name) | |||||
{ | { | ||||
String n = name; | |||||
n.to_lower(); | |||||
std::string needle = tolower(name); | |||||
for (int i = 0; i < T::Max; ++i) | for (int i = 0; i < T::Max; ++i) | ||||
{ | |||||
String s = T(i).ToString().to_lower(); | |||||
if (s.contains(n)) | |||||
if (tolower(T(i).tostring()).find(needle) != std::string::npos) | |||||
return T(i); | return T(i); | ||||
} | |||||
return T::Max; | return T::Max; | ||||
} | } | ||||