Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@
[submodule "external/beautiful-win32-api"]
path = external/beautiful-win32-api
url = https://github.com/Demonese/beautiful-win32-api
[submodule "external/spine-runtimes"]
path = external/spine-runtimes
url = https://github.com/EsotericSoftware/spine-runtimes.git
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,18 @@ option(LUASTG_LINK_YY_THUNKS "Link to YY_Thunks for older Windows version (not r
option(LUASTG_LINK_LUASOCKET "Link to luasocket" OFF)
option(LUASTG_LINK_TRACY_CLIENT "Link to Tracy client" OFF)
option(LUASTG_LINK_STEAM_API "Link to Steam API" OFF)
option(LUASTG_LINK_SPINE_RUNTIME "Link to Spine Runtime" OFF)

if(LUASTG_SUPPORTS_WINDOWS_7)
message(STATUS "[LuaSTG] Windows compatibility: Windows 7")
add_compile_definitions(LUASTG_SUPPORTS_WINDOWS_7)
endif()

if(LUASTG_LINK_SPINE_RUNTIME)
message(STATUS "[LuaSTG] Spine support: ON")
add_compile_definitions(LUASTG_SUPPORTS_SPINE)
endif()

set_property(GLOBAL PROPERTY USE_FOLDERS ON)
include(cmake/TargetCommonOptions.cmake)
include(cmake/options.cmake)
Expand Down
9 changes: 9 additions & 0 deletions LuaSTG/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ set(LUASTG_ENGINE_SOURCES
LuaSTG/GameResource/ResourceBase.hpp
LuaSTG/GameResource/ResourceTexture.hpp
LuaSTG/GameResource/ResourceSprite.hpp
LuaSTG/GameResource/ResourceSpineAtlas.hpp
LuaSTG/GameResource/ResourceSpineSkeleton.hpp
LuaSTG/GameResource/ResourceSpineAdaptor.hpp
LuaSTG/GameResource/ResourceSpineAdaptor.cpp
LuaSTG/GameResource/ResourceAnimation.hpp
LuaSTG/GameResource/ResourceMusic.hpp
LuaSTG/GameResource/ResourceSoundEffect.hpp
Expand All @@ -66,6 +70,10 @@ set(LUASTG_ENGINE_SOURCES
LuaSTG/GameResource/Implement/ResourceTextureImpl.cpp
LuaSTG/GameResource/Implement/ResourceSpriteImpl.hpp
LuaSTG/GameResource/Implement/ResourceSpriteImpl.cpp
LuaSTG/GameResource/Implement/ResourceSpineAtlasImpl.hpp
LuaSTG/GameResource/Implement/ResourceSpineAtlasImpl.cpp
LuaSTG/GameResource/Implement/ResourceSpineSkeletonImpl.hpp
LuaSTG/GameResource/Implement/ResourceSpineSkeletonImpl.cpp
LuaSTG/GameResource/Implement/ResourceAnimationImpl.hpp
LuaSTG/GameResource/Implement/ResourceAnimationImpl.cpp
LuaSTG/GameResource/Implement/ResourceMusicImpl.hpp
Expand Down Expand Up @@ -98,6 +106,7 @@ set(LUASTG_ENGINE_SOURCES
LuaSTG/LuaBinding/LW_ParticleSystem.cpp
LuaSTG/LuaBinding/LW_Render.cpp
LuaSTG/LuaBinding/LW_Renderer.cpp
LuaSTG/LuaBinding/LW_Spine.cpp
LuaSTG/LuaBinding/LW_StopWatch.cpp
LuaSTG/LuaBinding/LW_ResourceMgr.cpp
LuaSTG/LuaBinding/LW_Platform.cpp
Expand Down
6 changes: 6 additions & 0 deletions LuaSTG/Core.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,9 @@ target_link_libraries(Core PUBLIC
Core.FileSystem
win32
)

if (LUASTG_LINK_SPINE_RUNTIME)
target_link_libraries(Core PUBLIC spine-cpp)
#target_compile_definitions(Core PUBLIC LUASTG_SUPPORTS_SPINE)
message(STATUS "[Core] Link: spine-runtime")
endif ()
19 changes: 19 additions & 0 deletions LuaSTG/LuaSTG/GameResource/Implement/ResourceSpineAtlasImpl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifdef LUASTG_SUPPORTS_SPINE
#include "GameResource/Implement/ResourceSpineAtlasImpl.hpp"
#include "GameResource/Implement/ResourceTextureImpl.hpp"
#include "AppFrame.h"
#include "Core/FileSystem.hpp"
#include "Core/SmartReference.hpp"

namespace luastg
{
const std::shared_ptr<spine::Atlas>& ResourceSpineAtlasImpl::getAtlas() { return atlas; }
ResourceSpineAtlasImpl::ResourceSpineAtlasImpl(const char* name, const char* atlas_path, spine::TextureLoader* textureLoader)
: ResourceBaseImpl(ResourceType::SpineAtlas, name),
atlas(new spine::Atlas(atlas_path, textureLoader))
{

}

}
#endif // LUASTG_SUPPORTS_SPINE
20 changes: 20 additions & 0 deletions LuaSTG/LuaSTG/GameResource/Implement/ResourceSpineAtlasImpl.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once
#ifdef LUASTG_SUPPORTS_SPINE
#include "GameResource/ResourceSpineAtlas.hpp"
#include "GameResource/Implement/ResourceBaseImpl.hpp"
#include <spine/spine.h>

namespace luastg
{
class ResourceSpineAtlasImpl : public ResourceBaseImpl<IResourceSpineAtlas>
{
private:
std::shared_ptr<spine::Atlas> atlas;

public:
const std::shared_ptr<spine::Atlas>& getAtlas();
public:
ResourceSpineAtlasImpl(const char* name, const char* atlasPath, spine::TextureLoader* textureLoader);
};
}
#endif // LUASTG_SUPPORTS_SPINE
50 changes: 50 additions & 0 deletions LuaSTG/LuaSTG/GameResource/Implement/ResourceSpineSkeletonImpl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#ifdef LUASTG_SUPPORTS_SPINE
#include "GameResource/Implement/ResourceSpineSkeletonImpl.hpp"
#include "AppFrame.h"


namespace luastg
{
ResourceSpineSkeletonImpl::ResourceSpineSkeletonImpl(const char* name, const char* skel_path, const std::shared_ptr<spine::Atlas>& atlas)
: ResourceBaseImpl(ResourceType::SpineSkeleton, name)
, atlas_holder(atlas)
{
std::string_view skeleton_path = skel_path;
if (skeleton_path.ends_with(".json"))
{
auto skelJson = spine::SkeletonJson(atlas.get());
skeleton.reset(skelJson.readSkeletonDataFile(skel_path));
}
else if (skeleton_path.ends_with(".skel"))
{
auto skelBin = spine::SkeletonBinary(atlas.get());
skeleton.reset(skelBin.readSkeletonDataFile(skel_path));
}
else
{
spdlog::error("'{}' 不是可识别的SpineSkeleton文件.", skel_path);
throw std::exception("spine skeleton only support .json and .skel format, check your skeleton file!");
}

if (skeleton.get() == nullptr) throw std::exception("load spine skeleton failed! check your spine export version and make sure it's 4.2.xx!");

anistate.reset(new spine::AnimationStateData(skeleton.get()));
}
spine::SkeletonData* ResourceSpineSkeletonImpl::getSkeletonData() { return skeleton.get(); }
spine::AnimationStateData* ResourceSpineSkeletonImpl::getAnimationStateData() { return anistate.get(); }
void ResourceSpineSkeletonImpl::setAnimationMix(const char* ani1, const char* ani2, float mix_time)
{
auto from = skeleton->findAnimation(ani1);
auto to = skeleton->findAnimation(ani2);

if (!from || !to)
{
spdlog::error("SetSpineAnimationMix: 指定的骨骼 '{}' 上不存在动画 '{}' 和/或 '{}', 已取消", GetResName(), ani1, ani2);
return;
}

anistate->setMix(ani1, ani2, mix_time);
}
void ResourceSpineSkeletonImpl::setAnimationMix(float mix_time) { anistate->setDefaultMix(mix_time); };
}
#endif
25 changes: 25 additions & 0 deletions LuaSTG/LuaSTG/GameResource/Implement/ResourceSpineSkeletonImpl.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#pragma once
#ifdef LUASTG_SUPPORTS_SPINE
#include "GameResource/ResourceSpineSkeleton.hpp"
#include "GameResource/Implement/ResourceBaseImpl.hpp"
#include <spine/spine.h>

namespace luastg
{
class ResourceSpineSkeletonImpl : public ResourceBaseImpl<IResourceSpineSkeleton>
{
private:
std::shared_ptr<spine::Atlas> atlas_holder;
std::unique_ptr<spine::SkeletonData> skeleton;
std::unique_ptr<spine::AnimationStateData> anistate;

public:
spine::SkeletonData* getSkeletonData();
spine::AnimationStateData* getAnimationStateData();
void setAnimationMix(const char* ani1, const char* ani2, float mix_time);
void setAnimationMix(float mix_time);
public:
ResourceSpineSkeletonImpl(const char* name, const char* skelPath, const std::shared_ptr<spine::Atlas>& atlas);
};
}
#endif // LUASTG_SUPPORTS_SPINE
2 changes: 2 additions & 0 deletions LuaSTG/LuaSTG/GameResource/ResourceBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ namespace luastg {
TrueTypeFont,
FX,
Model,
SpineAtlas,
SpineSkeleton,
};

// 混合模式
Expand Down
18 changes: 18 additions & 0 deletions LuaSTG/LuaSTG/GameResource/ResourceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,24 @@ namespace luastg
return tRet;
}

#ifdef LUASTG_SUPPORTS_SPINE
core::SmartReference<IResourceSpineAtlas> ResourceMgr::FindSpineAtlas(const char* name) noexcept
{
core::SmartReference<IResourceSpineAtlas> tRet;
if (!(tRet = m_StageResourcePool.GetSpineAtlas(name)))
tRet = m_GlobalResourcePool.GetSpineAtlas(name);
return tRet;
}

core::SmartReference<IResourceSpineSkeleton> ResourceMgr::FindSpineSkeleton(const char* name) noexcept
{
core::SmartReference<IResourceSpineSkeleton> tRet;
if (!(tRet = m_StageResourcePool.GetSpineSkeleton(name)))
tRet = m_GlobalResourcePool.GetSpineSkeleton(name);
return tRet;
}
#endif // LUASTG_SUPPORTS_SPINE

// 其他资源操作

bool ResourceMgr::GetTextureSize(const char* name, core::Vector2U& out) noexcept {
Expand Down
24 changes: 22 additions & 2 deletions LuaSTG/LuaSTG/GameResource/ResourceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
#include "GameResource/ResourceFont.hpp"
#include "GameResource/ResourcePostEffectShader.hpp"
#include "GameResource/ResourceModel.hpp"
#include "GameResource/ResourceSpineAdaptor.hpp"
#include "GameResource/ResourceSpineAtlas.hpp"
#include "GameResource/ResourceSpineSkeleton.hpp"
#include "lua.hpp"
#include "xxhash.h"

Expand Down Expand Up @@ -87,6 +90,10 @@ namespace luastg
dictionary_t<core::SmartReference<IResourceFont>> m_TTFFontPool;
dictionary_t<core::SmartReference<IResourcePostEffectShader>> m_FXPool;
dictionary_t<core::SmartReference<IResourceModel>> m_ModelPool;
#ifdef LUASTG_SUPPORTS_SPINE
dictionary_t<core::SmartReference<IResourceSpineAtlas>> m_SpineAtlasPool;
dictionary_t<core::SmartReference<IResourceSpineSkeleton>> m_SpineSkeletonPool;
#endif // LUASTG_SUPPORTS_SPINE
private:
const char* getResourcePoolTypeName();
public:
Expand Down Expand Up @@ -132,7 +139,12 @@ namespace luastg
bool LoadFX(const char* name, const char* path) noexcept;
// 模型
bool LoadModel(const char* name, const char* path) noexcept;

// Spine
#ifdef LUASTG_SUPPORTS_SPINE
bool LoadSpineAtlas(const char* name, const char* atlas_path) noexcept;
bool LoadSpineSkeleton(const char* name, const char* atlas_name, const char* skeleton_path) noexcept;
#endif // LUASTG_SUPPORTS_SPINE

core::SmartReference<IResourceTexture> GetTexture(std::string_view name) noexcept;
core::SmartReference<IResourceSprite> GetSprite(std::string_view name) noexcept;
core::SmartReference<IResourceAnimation> GetAnimation(std::string_view name) noexcept;
Expand All @@ -143,6 +155,10 @@ namespace luastg
core::SmartReference<IResourceFont> GetTTFFont(std::string_view name) noexcept;
core::SmartReference<IResourcePostEffectShader> GetFX(std::string_view name) noexcept;
core::SmartReference<IResourceModel> GetModel(std::string_view name) noexcept;
#ifdef LUASTG_SUPPORTS_SPINE
core::SmartReference<IResourceSpineAtlas> GetSpineAtlas(std::string_view name) noexcept;
core::SmartReference<IResourceSpineSkeleton> GetSpineSkeleton(std::string_view name) noexcept;
#endif // LUASTG_SUPPORTS_SPINE
public:
ResourcePool(ResourceMgr* mgr, ResourcePoolType t);
ResourcePool& operator=(const ResourcePool&) = delete;
Expand Down Expand Up @@ -173,7 +189,11 @@ namespace luastg
core::SmartReference<IResourceFont> FindTTFFont(const char* name) noexcept;
core::SmartReference<IResourcePostEffectShader> FindFX(const char* name) noexcept;
core::SmartReference<IResourceModel> FindModel(const char* name) noexcept;

#ifdef LUASTG_SUPPORTS_SPINE
core::SmartReference<IResourceSpineAtlas> FindSpineAtlas(const char* name) noexcept;
core::SmartReference<IResourceSpineSkeleton> FindSpineSkeleton(const char* name) noexcept;
#endif

bool GetTextureSize(const char* name, core::Vector2U& out) noexcept;
void CacheTTFFontString(const char* name, const char* text, size_t len) noexcept;
void UpdateSound();
Expand Down
Loading