소스 검색

create an embedded catalog for resources

main
Sam Hocevar 1 년 전
부모
커밋
1b04009e96
6개의 변경된 파일79개의 추가작업 그리고 27개의 파일을 삭제
  1. +5
    -27
      src/include/lol/engine/private/sys/registry.ipp
  2. +43
    -0
      src/include/lol/engine/private/sys/resource.h
  3. +1
    -0
      src/include/lol/engine/sys
  4. +1
    -0
      src/lolengine.vcxproj
  5. +4
    -0
      src/lolengine.vcxproj.filters
  6. +25
    -0
      src/sys/resource.cpp

+ 5
- 27
src/include/lol/engine/private/sys/registry.ipp 파일 보기

@@ -10,40 +10,18 @@
// See http://www.wtfpl.net/ for more details.
//

#include <span>
#include <string>
#include <unordered_map>
#include <lol/engine/sys> // lol::sys::resource

#if !defined LOL_EMBED_STATIC_INITIALIZER
# error "LOL_EMBED_STATIC_INITIALIZER is not defined; please check your build system"
# error "LOL_EMBED_STATIC_INITIALIZER is not defined; please check the build system"
#endif

#define LOL_EMBED_REGISTER(name) \
extern "C" uint8_t *name; \
extern "C" size_t name##_size; \
extern "C" char const *name##_path; \
static auto name##_token = lol::registry::registry[name##_path] = lol::registry::resource(name, name##_size)
static auto name##_token = lol::sys::resource(name##_path, name, name##_size)

#if defined LOL_EMBED_REGISTRY_IMPL
// Applications must reference this variable so that embedded resources
// get linked into the final binary.
extern "C" { int LOL_EMBED_STATIC_INITIALIZER = 0xdeadbeef; }
#else
extern "C" { extern int LOL_EMBED_STATIC_INITIALIZER; }
#endif

namespace lol::registry
{

static std::unordered_map<std::string, struct resource> registry;

struct resource
{
resource() = default;

resource(uint8_t const *data, size_t size)
: data(data, size)
{}

std::span<uint8_t const> data;
};

};

+ 43
- 0
src/include/lol/engine/private/sys/resource.h 파일 보기

@@ -0,0 +1,43 @@
//
// Lol Engine
//
// Copyright © 2010–2024 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

//
// The resource classes
// ————————————————————
//

#include <span>
#include <string>
#include <unordered_map> // std::unordered_map

namespace lol::sys
{

struct resource
{
resource() = default;

resource(std::string const &path, void const *data, size_t size)
: data(static_cast<uint8_t const *>(data), size)
{
catalog()[path] = *this;
}

protected:
std::span<uint8_t const> data;

static std::unordered_map<std::string, struct resource> &catalog();
};

} // namespace lol::sys

+ 1
- 0
src/include/lol/engine/sys 파일 보기

@@ -13,3 +13,4 @@
#pragma once

#include "private/sys/init.h"
#include "private/sys/resource.h"

+ 1
- 0
src/lolengine.vcxproj 파일 보기

@@ -17,6 +17,7 @@
<ClCompile Include="net\http.cpp" />
<ClCompile Include="sys\init.cpp" />
<ClCompile Include="sys\main.cpp" />
<ClCompile Include="sys\resource.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="include\lol\engine\audio" />


+ 4
- 0
src/lolengine.vcxproj.filters 파일 보기

@@ -13,6 +13,9 @@
<ClCompile Include="audio\audio.cpp">
<Filter>audio</Filter>
</ClCompile>
<ClCompile Include="sys\resource.cpp">
<Filter>sys</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="include\lol\engine\private\net\http.h">
@@ -72,5 +75,6 @@
<ItemGroup>
<LolEmbed Include="data\black.png" />
<LolEmbed Include="data\font\ascii.png" />
<LolEmbed Include="data\token.txt" />
</ItemGroup>
</Project>

+ 25
- 0
src/sys/resource.cpp 파일 보기

@@ -0,0 +1,25 @@
//
// Lol Engine
//
// Copyright © 2010–2024 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/sys> // lol::sys::resource

namespace lol::sys
{

std::unordered_map<std::string, resource> &resource::catalog()
{
// This is not a global variable because of static initialisation order
static std::unordered_map<std::string, resource> ret;
return ret;
}

} // namespace lol::sys

불러오는 중...
취소
저장