Get rid of Loki

This commit is contained in:
Vladislav Khorev 2018-09-23 10:57:34 +05:00
parent 15a2cbe410
commit ef0392fb63
27 changed files with 92 additions and 52 deletions

View File

@ -92,15 +92,15 @@
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>../../libs/boost-gil-extension;../../tes-engine;../../eigen;../../boost_1_67_0/;../../libs/jpeg-9;../../libs/jpeg-9/vc10;../../libs/lpng1510;..\;..\math;..\coldet\;..\util;..\..\SDL2-2.0.8\include;..\..\physfs-3.0.1\build\install\include;..\..\loki-0.1.7\include\loki;..\opensteer\include</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>../../libs/boost-gil-extension;../../tes-engine;../../eigen;../../boost_1_67_0/;../../libs/jpeg-9;../../libs/jpeg-9/vc10;../../libs/lpng1510;..\;..\math;..\coldet\;..\util;..\..\SDL2-2.0.8\include;..\..\physfs-3.0.1\build\install\include;..\opensteer\include;..\replaceLoki</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_WINDOWS;TARGET_WIN32;_WIN32_WINNT=0x0501;WIN32_LEAN_AND_MEAN;EIGEN_DONT_ALIGN_STATICALLY;_CONSOLE;_SCL_SECURE_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<CompileAsWinRT>false</CompileAsWinRT>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<AdditionalLibraryDirectories>../../tes-engine/windows/Engine/x64/Debug;../../boost_1_67_0/stage/lib;..\..\SDL2-2.0.8\lib\x64;..\..\loki-0.1.7\lib;..\..\physfs-3.0.1\build\install\lib</AdditionalLibraryDirectories>
<AdditionalDependencies>libjpeg.lib;libpng.lib;Engine.lib;physfs.lib;loki_D.lib;SDL2.lib;SDL2main.lib;opengl32.lib;glu32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>../../tes-engine/windows/Engine/x64/Debug;../../boost_1_67_0/stage/lib;..\..\SDL2-2.0.8\lib\x64;..\..\physfs-3.0.1\build\install\lib</AdditionalLibraryDirectories>
<AdditionalDependencies>libjpeg.lib;libpng.lib;Engine.lib;physfs.lib;SDL2.lib;SDL2main.lib;opengl32.lib;glu32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<EntryPointSymbol>
</EntryPointSymbol>
</Link>
@ -128,7 +128,7 @@
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>../../libs/boost-gil-extension;../../tes-engine;../../eigen;../../boost_1_67_0/;../../libs/jpeg-9;../../libs/jpeg-9/vc10;../../libs/lpng1510;..\;..\math;..\coldet\;..\util;..\..\SDL2-2.0.8\include;..\..\physfs-3.0.1\build\install\include;..\..\loki-0.1.7\include\loki;..\opensteer\include</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>../../libs/boost-gil-extension;../../tes-engine;../../eigen;../../boost_1_67_0/;../../libs/jpeg-9;../../libs/jpeg-9/vc10;../../libs/lpng1510;..\;..\math;..\coldet\;..\util;..\..\SDL2-2.0.8\include;..\..\physfs-3.0.1\build\install\include;..\opensteer\include;..\replaceLoki</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;TARGET_WIN32;_WIN32_WINNT=0x0501;WIN32_LEAN_AND_MEAN;EIGEN_DONT_ALIGN_STATICALLY;_SCL_SECURE_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<CompileAsWinRT>false</CompileAsWinRT>
</ClCompile>
@ -241,6 +241,7 @@
<ClInclude Include="..\navdata.h" />
<ClInclude Include="..\opengta.h" />
<ClInclude Include="..\read_ini.h" />
<ClInclude Include="..\replaceLoki\Singleton.h" />
<ClInclude Include="..\slope1_data.h" />
<ClInclude Include="..\slope1_tcoords.h" />
<ClInclude Include="..\spritemanager.h" />

View File

@ -404,6 +404,9 @@
<ClInclude Include="frgbridge.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="..\replaceLoki\Singleton.h">
<Filter>Source Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\Doxyfile">

3
blockdata.h Normal file → Executable file
View File

@ -35,8 +35,7 @@ namespace OpenGTA {
static float lid_normal_data[numBlockTypes][3];
};
typedef Loki::SingletonHolder<BlockData, Loki::CreateUsingNew,
Loki::DefaultLifetime, Loki::SingleThreaded> BlockDataHolder;
typedef Loki::SingletonHolder<BlockData> BlockDataHolder;
}
#define SLOPE_RAW_DATA OpenGTA::BlockDataHolder::Instance().slope_raw_data

1
dataholder.cpp Normal file → Executable file
View File

@ -24,6 +24,7 @@
#include "log.h"
#include "cistring.h"
namespace OpenGTA {
template<> ActiveStyle::ActiveData() {
m_data = 0;

9
dataholder.h Normal file → Executable file
View File

@ -57,16 +57,13 @@ namespace OpenGTA {
/** Singleton: Graphics
*/
typedef Loki::SingletonHolder< ActiveStyle, Loki::CreateUsingNew, Loki::DefaultLifetime,
Loki::SingleThreaded> StyleHolder;
typedef Loki::SingletonHolder< ActiveStyle> StyleHolder;
/** Singleton: Map
*/
typedef Loki::SingletonHolder< ActiveMap, Loki::CreateUsingNew, Loki::DefaultLifetime,
Loki::SingleThreaded> MapHolder;
typedef Loki::SingletonHolder< ActiveMap> MapHolder;
/** Singleton: Message strings
*/
typedef Loki::SingletonHolder< MainMsgLookup, Loki::CreateUsingNew, Loki::DefaultLifetime,
Loki::SingleThreaded> MainMsgHolder;
typedef Loki::SingletonHolder< MainMsgLookup> MainMsgHolder;
}

3
font_cache.h Normal file → Executable file
View File

@ -59,8 +59,7 @@ namespace OpenGTA {
OpenGL::DrawableFont* createFont(const std::string & file, const uint32_t & scale);
};
typedef Loki::SingletonHolder<FontCache, Loki::CreateUsingNew,
Loki::DefaultLifetime, Loki::SingleThreaded> FontCacheHolder;
typedef Loki::SingletonHolder<FontCache> FontCacheHolder;
}
#endif

View File

@ -25,11 +25,10 @@
#include "dataholder.h"
#include "cell_iterator.h"
#include "timer.h"
#include "Functor.h"
#include "plane.h"
#include "ai.h"
#include "localplayer.h"
#include <functional>
#include "log.h"
@ -464,7 +463,9 @@ activeWeapon = chooseWeapon;
return;
}
anim.set(Util::Animation::PLAY_FORWARD, Util::Animation::FCALLBACK);
Loki::Functor<void> cmd(this, &Pedestrian::die);
std::function<void()> cmd = std::bind(&Pedestrian::die, this);
anim.setCallback(cmd);
isDead++;
}
@ -473,7 +474,7 @@ activeWeapon = chooseWeapon;
isDead = 1;
switchToAnim(45);
anim.set(Util::Animation::PLAY_FORWARD, Util::Animation::FCALLBACK);
Loki::Functor<void> cmd(this, &Pedestrian::die);
std::function<void()> cmd = std::bind(&Pedestrian::die, this);
anim.setCallback(cmd);
}

1
game_objects.h Normal file → Executable file
View File

@ -31,6 +31,7 @@
#include "entity_controller.h"
#include "OpenSteer/Proximity.h"
#include "util/set.h"
#include <list>
namespace OpenGTA {

3
gl_camera.h Normal file → Executable file
View File

@ -45,7 +45,6 @@ namespace OpenGL {
};
using namespace Loki;
typedef SingletonHolder<Camera, CreateUsingNew, DefaultLifetime,
SingleThreaded> CameraHolder;
typedef SingletonHolder<Camera> CameraHolder;
}
#endif

View File

@ -75,7 +75,7 @@ namespace OpenGL {
};
using namespace Loki;
typedef SingletonHolder<Screen, CreateUsingNew, DefaultLifetime, SingleThreaded> ScreenHolder;
typedef SingletonHolder<Screen> ScreenHolder;
}
#endif

3
gl_spritecache.h Normal file → Executable file
View File

@ -75,8 +75,7 @@ namespace OpenGL {
bool doScale2x;
};
typedef Loki::SingletonHolder<SpriteCache, Loki::CreateUsingNew,
Loki::DefaultLifetime, Loki::SingleThreaded> SpriteCacheHolder;
typedef Loki::SingletonHolder<SpriteCache> SpriteCacheHolder;
}
#endif

3
localplayer.h Normal file → Executable file
View File

@ -52,8 +52,7 @@ namespace OpenGTA {
PedController * pc_ptr;
};
typedef Loki::SingletonHolder<PlayerController, Loki::CreateUsingNew,
Loki::DefaultLifetime, Loki::SingleThreaded> LocalPlayer;
typedef Loki::SingletonHolder<PlayerController> LocalPlayer;
}
#endif

3
read_gry.cpp Normal file → Executable file
View File

@ -11,6 +11,7 @@
#include <iostream>
#include <cassert>
#include <sstream>
#include <algorithm>
#include "opengta.h"
#include "buffercache.h"
#include "log.h"
@ -292,7 +293,7 @@ namespace OpenGTA {
fd = PHYSFS_openRead(style.c_str());
if (fd == NULL) {
std::string style2(style);
transform(style2.begin(), style2.end(), style2.begin(), tolower);
std::transform(style2.begin(), style2.end(), style2.begin(), tolower);
fd = PHYSFS_openRead(style2.c_str());
}
if (fd == NULL) {

32
replaceLoki/Singleton.h Executable file
View File

@ -0,0 +1,32 @@
#ifndef SINGLETON_H_INCLUDED
#define SINGLETON_H_INCLUDED
#include <memory>
#include <cassert>
#include <thread>
#include <mutex>
namespace Loki
{
template <typename T>
struct SingletonHolder
{
static T& Instance()
{
static std::once_flag onceFlag;
static std::unique_ptr<T> singleton;
std::call_once(onceFlag,
[] {
singleton = std::make_unique<T>();
});
return *singleton.get();
}
};
}
#endif

3
spritemanager.h Normal file → Executable file
View File

@ -186,8 +186,7 @@ namespace OpenGTA {
};
typedef Loki::SingletonHolder<SpriteManager, Loki::CreateUsingNew,
Loki::DefaultLifetime, Loki::SingleThreaded> SpriteManagerHolder;
typedef Loki::SingletonHolder<SpriteManager> SpriteManagerHolder;
}
#endif

4
util/animation.h Normal file → Executable file
View File

@ -23,7 +23,7 @@
#ifndef UTIL_ANIMATION_H
#define UTIL_ANIMATION_H
#include <vector>
#include "Functor.h"
#include <functional>
#include "log.h"
namespace Util {
@ -56,7 +56,7 @@ namespace Util {
inline const OnDone & getDone() const { return onDone; }
void jumpToFrame(const uint16_t num, const Status andDo);
void update(const uint32_t & nowTicks);
typedef Loki::Functor<void> CallbackType;
typedef std::function<void()> CallbackType;
void setCallback(CallbackType & cb) { callback = cb; }
uint16_t currentFrame;

3
util/buffercache.h Normal file → Executable file
View File

@ -110,7 +110,6 @@ namespace Util {
/** Instance of BufferCache.
*/
typedef SingletonHolder<BufferCache, CreateUsingNew, DefaultLifetime,
SingleThreaded> BufferCacheHolder;
typedef SingletonHolder<BufferCache> BufferCacheHolder;
}
#endif

1
util/file_helper.cpp Normal file → Executable file
View File

@ -23,6 +23,7 @@
#include <cstdlib>
#include <physfs.h>
#include <sstream>
#include <algorithm>
#include "m_exceptions.h"
#include "file_helper.h"
#include "buffercache.h"

3
util/file_helper.h Normal file → Executable file
View File

@ -47,8 +47,7 @@ namespace Util {
std::string userHomeDir;
};
typedef Loki::SingletonHolder<FileHelper, Loki::CreateUsingNew, Loki::DefaultLifetime,
Loki::SingleThreaded> FileHelperHolder;
typedef Loki::SingletonHolder<FileHelper> FileHelperHolder;
}
#define GET_FILE_HELPER Util::FileHelperHolder::Instance()

6
util/gui.h Normal file → Executable file
View File

@ -85,8 +85,7 @@ namespace GUI {
};
typedef Loki::SingletonHolder<Manager, Loki::CreateUsingNew, Loki::DefaultLifetime,
Loki::SingleThreaded> ManagerHolder;
typedef Loki::SingletonHolder<Manager> ManagerHolder;
class Animation : public Util::Animation {
public:
@ -196,7 +195,8 @@ namespace GUI {
void receive(SDL_MouseButtonEvent & mb_event);
SDL_Color innerColor;
float value;
typedef Loki::Functor<void, LOKI_TYPELIST_1(float)> SC_Functor;
//typedef Loki::Functor<void, LOKI_TYPELIST_1(float)> SC_Functor;
typedef std::function<void(float)> SC_Functor;
SC_Functor changeCB;
};

View File

@ -1,7 +1,18 @@
#include "map_helper.h"
#include "log.h"
#include <cstdlib>
#include <iostream>
#include <ctime>
namespace Util {
SpriteCreationArea::SpriteCreationArea()
{
std::srand(unsigned(std::time(0)));
}
void SpriteCreationArea::setRects(const SDL_Rect & allowed, const SDL_Rect & denied) {
validRects = std::make_pair(allowed, denied);
onScreen = denied;
@ -23,8 +34,9 @@ namespace Util {
}
TupleOfUint8 SpriteCreationArea::getValidCoord() {
uint32_t x = rnd.nextUint(validRects.first.w) + validRects.first.x;
uint32_t y = rnd.nextUint(validRects.first.h) + validRects.first.y;
uint32_t x = std::rand() % validRects.first.w + validRects.first.x;
uint32_t y = std::rand() % validRects.first.h + validRects.first.y;
return std::make_pair(x, y);
}

View File

@ -6,7 +6,7 @@
#include <SDL_video.h>
#include <cassert> // yasli/random.h needs it
#include "math3d.h"
#include "yasli/random.h"
//#include "yasli/random.h"
namespace Util {
typedef std::pair<SDL_Rect, SDL_Rect> TupleOfRects;
@ -15,11 +15,11 @@ namespace Util {
class SpriteCreationArea {
public:
SpriteCreationArea();
//ListOfTupleOfRects validTuple;
TupleOfRects validRects;
void setRects(const SDL_Rect & allowed, const SDL_Rect & denied);
TupleOfUint8 getValidCoord();
Random rnd;
bool isOnScreen(const Vector3D & p);
bool isOffScreen(const Vector3D & p);
private:

3
util/sample_cache.h Normal file → Executable file
View File

@ -70,8 +70,7 @@ namespace Audio {
m_map.clear();
}
typedef Loki::SingletonHolder< SampleCache , Loki::CreateUsingNew,
Loki::DefaultLifetime, Loki::SingleThreaded> SampleCacheHolder;
typedef Loki::SingletonHolder< SampleCache> SampleCacheHolder;
}
#endif

3
util/sound_mixer.h Normal file → Executable file
View File

@ -28,8 +28,7 @@ namespace Audio {
Audio::SoundDevice::OPEN); }
};
typedef Loki::SingletonHolder<Mixer, Loki::CreateUsingNew,
Loki::DefaultLifetime, Loki::SingleThreaded> MixerHolder;
typedef Loki::SingletonHolder<Mixer> MixerHolder;
}
#endif

5
util/sound_music_player.h Normal file → Executable file
View File

@ -25,11 +25,12 @@
#ifdef WITH_SOUND
#include <SDL_sound.h>
#include "Functor.h"
#include <functional>
namespace Audio {
static int music_volume = 127;
typedef Loki::Functor<void> MusicFinishedCallbackType;
//typedef Loki::Functor<void> MusicFinishedCallbackType;
typedef std::function<void()> MusicFinishedCallbackType;
struct MusicPlayerCtrl {
static bool isPlaying;

7
util/timer.h Normal file → Executable file
View File

@ -24,7 +24,7 @@
#define OGTA_TIMER_H
#include <map>
#include "Singleton.h"
#include "Functor.h"
#include <functional>
// instead of SDL_GetTicks()
#define TIMER_OPENSTEER_CLOCK
@ -35,7 +35,7 @@
class Timer {
public:
typedef Loki::Functor<void, LOKI_TYPELIST_1(float)> CallbackType;
typedef std::function<void(float)> CallbackType;
struct TimeEvent {
TimeEvent(const uint32_t & b, const uint32_t e, CallbackType & c);
TimeEvent(const uint32_t & b, CallbackType & c);
@ -73,7 +73,6 @@ class Timer {
SimTimeMap simTimeEvents;
};
typedef Loki::SingletonHolder<Timer, Loki::CreateUsingNew,
Loki::DefaultLifetime, Loki::SingleThreaded> TimerHolder;
typedef Loki::SingletonHolder<Timer> TimerHolder;
#endif

View File

@ -70,7 +70,7 @@ OpenGTA::CityView *city = NULL;
GUI::Label * fps_label = NULL;
//Xperimental -- Vladislav Khorev vladislav.khorev@fishrungames.com
int city_num = 2;
int city_num = 0;
const char* styles_8[3] = { "STYLE001.GRY", "STYLE002.GRY", "STYLE003.GRY" };
const char* styles_24[3] = { "STYLE001.G24", "STYLE002.G24", "STYLE003.G24" };