Skip to content

Commit

Permalink
解决符号问题
Browse files Browse the repository at this point in the history
  • Loading branch information
TsXor committed May 1, 2024
1 parent fbba331 commit a65933b
Show file tree
Hide file tree
Showing 19 changed files with 3,586 additions and 3,534 deletions.
18 changes: 13 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,17 @@ set(SPDLOG_USE_STD_FORMAT ON)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extlibs/spdlog)


function(mingw_static_lib TARGET)
if(MINGW)
target_link_libraries(${TARGET} PRIVATE -static gcc stdc++ winpthread -dynamic)
function(compiler_static_lib TARGET)
if(CMAKE_COMPILER_IS_GNUCC)
target_link_libraries(${TARGET} PRIVATE -static-libgcc)
if(CMAKE_COMPILER_IS_GNUCXX)
target_link_libraries(${TARGET} PRIVATE -static-libstdc++)
if (MINGW)
target_link_libraries(${TARGET} PRIVATE -static winpthread -dynamic)
endif()
endif()
endif()
endfunction(mingw_static_lib)
endfunction(compiler_static_lib)

function(make_windows_compiler_happy TARGET)
if(WIN32)
Expand All @@ -35,6 +41,8 @@ set(SILLY_FRAMEWORK_SOURCE_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/src/silly_framework)
set(SILLY_FRAMEWORK_HEADER_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/include/silly_framework)
file(GLOB_RECURSE SILLY_FRAMEWORK_SOURCES ${SILLY_FRAMEWORK_SOURCE_ROOT}/*.cpp ${SILLY_FRAMEWORK_SOURCE_ROOT}/*.c)
add_library(SillyFramework SHARED ${SILLY_FRAMEWORK_SOURCES})
compiler_static_lib(SillyFramework)
target_compile_definitions(SillyFramework PRIVATE SF_BUILD)
target_include_directories(SillyFramework PRIVATE ${SILLY_FRAMEWORK_SOURCE_ROOT}/..)
target_include_directories(SillyFramework PUBLIC ${SILLY_FRAMEWORK_HEADER_ROOT}/..)

Expand All @@ -48,13 +56,13 @@ target_link_libraries(SillyFramework PRIVATE uv-cpp)
target_link_libraries(SillyFramework PRIVATE spdlog::spdlog $<$<BOOL:${MINGW}>:ws2_32>)
if(WIN32)
target_link_libraries(SillyFramework PRIVATE imm32)
mingw_static_lib(SillyFramework)
endif()


set(SILLY_GAME_SOURCE_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/src/main)
file(GLOB_RECURSE SILLY_GAME_SOURCES ${SILLY_GAME_SOURCE_ROOT}/*.cpp)
add_executable(SillyGame ${SILLY_GAME_SOURCES})
compiler_static_lib(SillyGame)
target_include_directories(SillyGame PRIVATE ${SILLY_GAME_SOURCE_ROOT})
target_link_libraries(SillyGame PRIVATE SillyFramework)
make_windows_compiler_happy(SillyGame)
3,472 changes: 1,737 additions & 1,735 deletions include/silly_framework/bundled/glad/glad.h

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions include/silly_framework/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#pragma once
#ifndef __SF_CONFIG__
#define __SF_CONFIG__

#if defined(_WIN32)
// MinGW可以识别__declspec
# if defined(SF_BUILD)
# define SF_EXPORT __declspec(dllexport)
# else
# define SF_EXPORT __declspec(dllimport)
# endif
#elif defined(__GNUC__)
// 编译选项需加-fvisibility=hidden
# if defined(SF_BUILD)
# define SF_EXPORT __attribute__ ((visibility ("default")))
# else
# define SF_EXPORT extern
# endif
#else
# define SF_EXPORT extern
#endif

#define GLAD_GLAPI_EXPORT
#ifdef SF_BUILD
# define GLAD_GLAPI_EXPORT_BUILD
#endif

#endif // __SF_CONFIG__
3 changes: 2 additions & 1 deletion include/silly_framework/facilities/activity_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
#include <thread>
#include <atomic>
#include <functional>
#include "silly_framework/config.h"
#include "silly_framework/rewheel/circ_queue.hpp"
#include "silly_framework/facilities/iface_activity.hpp"

namespace silly_framework {

class activity_manager {
class SF_EXPORT activity_manager {
using stack_type = std::vector<iface_activity*>;
using stack_operator = std::function<void(stack_type&)>;
stack_type stack;
Expand Down
3 changes: 2 additions & 1 deletion include/silly_framework/facilities/game_window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <functional>
#include <chrono>
#include <memory>
#include "silly_framework/config.h"
#include "silly_framework/rewheel/ogl_env.hpp"
#include "silly_framework/facilities/texture_manager.hpp"
#include "silly_framework/facilities/activity_manager.hpp"
Expand All @@ -20,7 +21,7 @@ class res_jloader;
* 游戏窗口类。
* 这个类主要负责将一众部件打包在一起,具体的功能由各个部件分别实现。
*/
class game_window {
class SF_EXPORT game_window {
using base_duration = std::chrono::microseconds;

void render_loop(std::stop_token stoken);
Expand Down
3 changes: 2 additions & 1 deletion include/silly_framework/facilities/input_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
#include <vector>
#include <mutex>
#include <unordered_map>
#include "silly_framework/config.h"
#include "silly_framework/rewheel/ogl_env.hpp"
#include "silly_framework/facilities/vkey_def.hpp"
#include "silly_framework/facilities/iface_activity.hpp"

namespace silly_framework {

class input_manager {
class SF_EXPORT input_manager {
std::unordered_multimap<int, vkey::code> kc_r2v_map;
volatile bool key_states[1024];
std::recursive_mutex ks_lock;
Expand Down
3 changes: 2 additions & 1 deletion include/silly_framework/facilities/render_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
#include <string>
#include <tuple>
#include <optional>
#include "silly_framework/config.h"
#include "silly_framework/rewheel/ogl_utils.hpp"
#include "silly_framework/rewheel/ogl_env.hpp"

namespace silly_framework {

class render_manager {
class SF_EXPORT render_manager {
using position = glut::position;
// OpenGL窗口
glenv::window& gl_wnd;
Expand Down
3 changes: 2 additions & 1 deletion include/silly_framework/facilities/texture_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <optional>
#include <mutex>
#include <coutils.hpp>
#include "silly_framework/config.h"
#include "silly_framework/rewheel/gpu_tex_img.hpp"
#include "silly_framework/rewheel/swap_queue.hpp"
#include "silly_framework/rewheel/naive_lru.hpp"
Expand All @@ -21,7 +22,7 @@ class res_loader;
* - 这个类的代码很大程度上依赖于“纹理缓存至少足够保存当前使用的纹理”这个事实。
* 如果纹理缓存过小,图片将不断重复加载,还可能发生一些不可预测的问题。
*/
class texture_manager {
class SF_EXPORT texture_manager {
// GPU纹理缓存上限,单位:字节
static constexpr size_t gpu_mem_thresh = 64 << 20; // MB
// CPU纹理缓存上限,单位:字节
Expand Down
5 changes: 3 additions & 2 deletions include/silly_framework/facilities/vkey_def.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <string>
#include <unordered_set>
#include "silly_framework/config.h"

namespace silly_framework::vkey {

Expand All @@ -24,10 +25,10 @@ struct info {
};

// 虚拟按键码的总数量
size_t code_count();
SF_EXPORT size_t code_count();

// 获取指定虚拟按键码的信息
const info& code_info(code c);
SF_EXPORT const info& code_info(code c);

} // namespace silly_framework::vkey

Expand Down
5 changes: 3 additions & 2 deletions include/silly_framework/rewheel/gpu_tex_img.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
#ifndef __SFLIB_GPU_TEX_IMG__
#define __SFLIB_GPU_TEX_IMG__

#include "silly_framework/config.h"
#include "silly_framework/ogl/oglwrap.hpp"
#include "silly_framework/rewheel/stb_image.hpp"

namespace silly_framework::rewheel {

// 将已读取的图片加载到GPU纹理,需要在主线程执行
gl::Texture2D load_texture2d_from_stb(const stb_decoded_image_view &img);
SF_EXPORT gl::Texture2D load_texture2d_from_stb(const stb_decoded_image_view &img);

struct gpu_tex2d {
struct SF_EXPORT gpu_tex2d {
int width, height, n_channels;
gl::Texture2D tex;

Expand Down
5 changes: 3 additions & 2 deletions include/silly_framework/rewheel/ogl_env.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#define __SFLIB_GLFW_CONTEXT__

#include <tuple>
#include "silly_framework/config.h"
#include "silly_framework/ogl/glfw.h"

namespace silly_framework::glenv {
Expand All @@ -12,7 +13,7 @@ namespace silly_framework::glenv {
* 第一个引用构造时,初始化OpenGL环境。
* 最后一个引用析构时,关闭OpenGL环境。
*/
struct ctx_ref {
struct SF_EXPORT ctx_ref {
ctx_ref();
~ctx_ref();
};
Expand All @@ -22,7 +23,7 @@ struct ctx_ref {
* 注:默认情况下,窗口初始化在处于屏幕中央且可以随意缩放,要改变这个行为,
* 可以在对象构造后调用GLFW API修改窗口属性。
*/
struct window {
struct SF_EXPORT window {
using handle_type = GLFWwindow*;
const ctx_ref ctx;
handle_type hwnd;
Expand Down
7 changes: 4 additions & 3 deletions include/silly_framework/rewheel/os_misc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
#define __SFLIB_OS_MISC__

#include <cstdint>
#include "silly_framework/config.h"

namespace silly_framework::os_misc {

void disable_ime();
void encoding_spell(int argc, char** argv);
int32_t proc_id();
SF_EXPORT void disable_ime();
SF_EXPORT void encoding_spell(int argc, char** argv);
SF_EXPORT int32_t proc_id();

} // namespace silly_framework::os_misc

Expand Down
3 changes: 2 additions & 1 deletion include/silly_framework/rewheel/stb_image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#define __SFLIB_STB_IMAGE_LOADER__

#include <cstdint>
#include "silly_framework/config.h"

namespace silly_framework::rewheel {

Expand All @@ -12,7 +13,7 @@ struct stb_decoded_image_view {
size_t mem_size() { return width * height * n_channels; }
};

struct stb_decoded_image : stb_decoded_image_view {
struct SF_EXPORT stb_decoded_image : stb_decoded_image_view {
stb_decoded_image();
stb_decoded_image(const byte* data, size_t data_len);
~stb_decoded_image();
Expand Down
10 changes: 6 additions & 4 deletions include/silly_framework/settings/logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
#ifndef __SFOPT_LOGGER__
#define __SFOPT_LOGGER__

#include "silly_framework/config.h"

namespace silly_framework::logger {

size_t lib_identity();
const std::string& default_name();
SF_EXPORT size_t lib_identity();
SF_EXPORT const std::string& default_name();

// 获取logger
const std::string& name();
SF_EXPORT const std::string& name();
// 设置logger
void make(const std::string& logger_name, const std::string& filename);
SF_EXPORT void make(const std::string& logger_name, const std::string& filename);

} // namespace silly_framework::logger

Expand Down
4 changes: 2 additions & 2 deletions include/silly_framework/settings/logger_all.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
namespace silly_framework::logger {

// 获取logger
std::shared_ptr<spdlog::logger> is();
SF_EXPORT std::shared_ptr<spdlog::logger> is();
// 设置logger
void is(std::shared_ptr<spdlog::logger> logger);
SF_EXPORT void is(std::shared_ptr<spdlog::logger> logger);

} // namespace silly_framework::logger

Expand Down
3 changes: 2 additions & 1 deletion include/silly_framework/utilities/map2d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <string>
#include <span>
#include <coutils.hpp>
#include "silly_framework/config.h"
#include "silly_framework/rewheel/ogl_utils.hpp"

namespace silly_framework {
Expand All @@ -16,7 +17,7 @@ class game_window;
* 一个地图图像由若干“地图块”构成,每个“地图块”可看作一个素材。
* 此类使用了一个简单的缓存,uv变换矩阵只计算一次。
*/
class map2d {
class SF_EXPORT map2d {
public:
using block_pos = std::pair<glut::position, glut::coord>;
protected:
Expand Down
3 changes: 2 additions & 1 deletion include/silly_framework/utilities/sprite2d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#define __SFUT_SPRITE_2D__

#include <string>
#include "silly_framework/config.h"
#include "silly_framework/rewheel/ogl_utils.hpp"

namespace silly_framework {
Expand All @@ -14,7 +15,7 @@ class game_window;
* 我们默认一个素材指的是一个固定图像上固定的一部分,所以它的uv是固定的。
* 此类使用了一个简单的缓存,uv变换矩阵只计算一次。
*/
class sprite2d {
class SF_EXPORT sprite2d {
protected:
std::string file_path;
glut::position uvpos;
Expand Down
Loading

0 comments on commit a65933b

Please sign in to comment.