mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 21:01:52 +00:00
EditorContentManager Part 1
This commit is contained in:
@@ -60,7 +60,7 @@ namespace GlitchyEngine
|
||||
_rendererApi = new RendererAPI();
|
||||
_rendererApi.Context = _window.Context;
|
||||
|
||||
_contentManager = new ContentManager("./content");
|
||||
//_contentManager = new ContentManager("./content");
|
||||
|
||||
SamplerStateManager.Init();
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using xxHash;
|
||||
using System.Collections;
|
||||
using Bon;
|
||||
|
||||
namespace GlitchyEngine.Content
|
||||
{
|
||||
@@ -22,17 +24,95 @@ namespace GlitchyEngine.Content
|
||||
_hash = xxHash.ComputeHash(id);
|
||||
}
|
||||
}
|
||||
|
||||
[BonTarget, BonPolyRegister]
|
||||
abstract class AssetLoaderConfig
|
||||
{
|
||||
[BonIgnore]
|
||||
protected bool _changed;
|
||||
|
||||
public bool Changed => _changed;
|
||||
|
||||
protected bool SetIfChanged<T>(ref T field, T value)
|
||||
{
|
||||
if (field == value)
|
||||
return false;
|
||||
|
||||
field = value;
|
||||
_changed = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
interface IAssetLoader
|
||||
{
|
||||
static List<StringView> FileExtensions { get; }
|
||||
|
||||
AssetLoaderConfig GetDefaultConfig();
|
||||
|
||||
/// Loads the asset from the given data stream with the specified config.
|
||||
/// @param file The stream containing the asset.
|
||||
/// @param config The configuration which specifies the settings used to load the asset.
|
||||
/// @returns The loaded asset.
|
||||
IRefCounted LoadAsset(Stream file, AssetLoaderConfig config);
|
||||
}
|
||||
|
||||
static
|
||||
{
|
||||
/// Loads the specified asset with the given contentManager or the current applications content manager.
|
||||
public static T LoadAsset<T>(StringView assetIdentifier, IContentManager contentManager = null) where T : IRefCounted
|
||||
{
|
||||
var contentManager;
|
||||
|
||||
if (contentManager == null)
|
||||
contentManager = Application.Get().ContentManager;
|
||||
|
||||
Object o = contentManager.LoadAsset(assetIdentifier);
|
||||
|
||||
Log.EngineLogger.AssertDebug(o is T);
|
||||
|
||||
return (T)o;
|
||||
}
|
||||
}
|
||||
|
||||
interface IContentManager
|
||||
{
|
||||
void GetFilePath(String outFilename, String filename);
|
||||
/// Loads the given asset.
|
||||
IRefCounted LoadAsset(StringView assetIdentifier);
|
||||
|
||||
Stream GetFile(String filename);
|
||||
/// Returns a data stream for the given asset.
|
||||
Stream GetStream(StringView assetIdentifier);
|
||||
|
||||
void RegisterAssetLoader<T>() where T : new, class, IAssetLoader;
|
||||
void SetAsDefaultAssetLoader<T>(params StringView[] fileExtensions) where T : IAssetLoader;
|
||||
//void GetFilePath(String outFilename, String filename);
|
||||
|
||||
//Stream GetFile(String filename);
|
||||
}
|
||||
|
||||
class ContentManager : IContentManager
|
||||
class RuntimeContentManager : IContentManager
|
||||
{
|
||||
private String _contentRoot;
|
||||
public IRefCounted LoadAsset(StringView identifier)
|
||||
{
|
||||
Runtime.NotImplemented();
|
||||
}
|
||||
|
||||
public Stream GetStream(StringView assetIdentifier)
|
||||
{
|
||||
Runtime.NotImplemented();
|
||||
}
|
||||
|
||||
public void RegisterAssetLoader<T>() where T : IAssetLoader where T : class where T : new
|
||||
{
|
||||
Runtime.NotImplemented();
|
||||
}
|
||||
|
||||
public void SetAsDefaultAssetLoader<T>(params StringView[] fileExtensions) where T : IAssetLoader
|
||||
{
|
||||
Runtime.NotImplemented();
|
||||
}
|
||||
/*private String _contentRoot;
|
||||
|
||||
[AllowAppend]
|
||||
public this(String contentRoot)
|
||||
@@ -65,6 +145,6 @@ namespace GlitchyEngine.Content
|
||||
}
|
||||
|
||||
return stream;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -96,16 +96,19 @@ namespace GlitchyEngine.ImGui
|
||||
|
||||
ImGui.GetIO().Fonts.Clear();
|
||||
|
||||
String fullpath = scope String();
|
||||
Application.Get().ContentManager.GetFilePath(fullpath, settings.FontName);
|
||||
// TODO: Fix fonts
|
||||
//String fullpath = scope String();
|
||||
//Application.Get().ContentManager.GetFilePath(fullpath, settings.FontName);
|
||||
/*Application.Get().ContentManager.GetStream(settings.FontName);
|
||||
if (File.Exists(fullpath))
|
||||
{
|
||||
ImGui.GetIO().Fonts.AddFontFromMemoryTTF();
|
||||
ImGui.GetIO().Fonts.AddFontFromFileTTF(fullpath, settings.FontSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
{*/
|
||||
ImGui.GetIO().Fonts.AddFontDefault();
|
||||
}
|
||||
//}
|
||||
|
||||
#if GE_GRAPHICS_DX11
|
||||
ImGuiImplDX11.CreateDeviceObjects();
|
||||
|
||||
@@ -2,12 +2,14 @@ using System;
|
||||
using GlitchyEngine.Core;
|
||||
using GlitchyEngine.Math;
|
||||
using System.Collections;
|
||||
using Bon;
|
||||
|
||||
namespace GlitchyEngine.Renderer
|
||||
{
|
||||
/**
|
||||
* Defines the filter function used when sampling from a texture.
|
||||
*/
|
||||
[BonTarget, Reflect]
|
||||
public enum FilterFunction
|
||||
{
|
||||
/// Use point filtering (nearest neighbor) for sampling.
|
||||
@@ -17,7 +19,8 @@ namespace GlitchyEngine.Renderer
|
||||
/// Use anisotropic interpolation for sampling.
|
||||
Anisotropic
|
||||
}
|
||||
|
||||
|
||||
[BonTarget, Reflect]
|
||||
public enum FilterMode
|
||||
{
|
||||
/// Just sample the texture.
|
||||
@@ -29,7 +32,8 @@ namespace GlitchyEngine.Renderer
|
||||
/// Return the maximum value of the fetched texels.
|
||||
Maximum
|
||||
}
|
||||
|
||||
|
||||
[BonTarget, Reflect]
|
||||
public enum ComparisonFunction
|
||||
{
|
||||
/**
|
||||
@@ -65,7 +69,8 @@ namespace GlitchyEngine.Renderer
|
||||
*/
|
||||
Always = 8
|
||||
}
|
||||
|
||||
|
||||
[BonTarget, Reflect]
|
||||
public enum TextureAddressMode
|
||||
{
|
||||
/// Tile the texture at every (u,v) integer junction.
|
||||
@@ -92,7 +97,8 @@ namespace GlitchyEngine.Renderer
|
||||
*/
|
||||
MirrorOnce
|
||||
}
|
||||
|
||||
|
||||
[BonTarget]
|
||||
public struct SamplerStateDescription : IHashable
|
||||
{
|
||||
public FilterFunction MinFilter = .Linear;
|
||||
|
||||
@@ -65,11 +65,17 @@ namespace GlitchyEngine.Renderer
|
||||
//public override extern uint32 ArraySize {get;}
|
||||
//public override extern uint32 MipLevels {get;}
|
||||
|
||||
public this(StringView path, bool pngSrgb = false)
|
||||
private this(StringView path, bool pngSrgb = false)
|
||||
{
|
||||
_path = new String(path);
|
||||
LoadTexture(pngSrgb);
|
||||
}
|
||||
|
||||
// TODO: remove
|
||||
private this(Stream data)
|
||||
{
|
||||
LoadDds(data);
|
||||
}
|
||||
|
||||
const String PngMagicWord = "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A";
|
||||
const String DdsMagicWord = "DDS ";
|
||||
@@ -78,7 +84,7 @@ namespace GlitchyEngine.Renderer
|
||||
{
|
||||
Debug.Profiler.ProfileResourceFunction!();
|
||||
|
||||
Stream data = Application.Get().ContentManager.GetFile(_path);
|
||||
Stream data = Application.Get().ContentManager.GetStream(_path);
|
||||
defer delete data;
|
||||
|
||||
var readResult = data.Read<char8[8]>();
|
||||
@@ -214,7 +220,7 @@ namespace GlitchyEngine.Renderer
|
||||
{
|
||||
Debug.Profiler.ProfileResourceFunction!();
|
||||
|
||||
Stream data = Application.Get().ContentManager.GetFile(_path);
|
||||
Stream data = Application.Get().ContentManager.GetStream(_path);
|
||||
defer delete data;
|
||||
|
||||
LoadTexturePlatform(data);
|
||||
|
||||
@@ -6,6 +6,8 @@ using System.IO;
|
||||
using GlitchyEngine.Math;
|
||||
using GlitchyEngine.Core;
|
||||
using System.Collections;
|
||||
using GlitchyEngine.Renderer;
|
||||
using GlitchyEngine.Content;
|
||||
|
||||
namespace GlitchyEngine.World
|
||||
{
|
||||
@@ -84,11 +86,10 @@ namespace GlitchyEngine.World
|
||||
|
||||
SerializeComponent<SpriterRendererComponent>(writer, entity, "SpriterRendererComponent", scope (component) =>
|
||||
{
|
||||
// TODO: Texture
|
||||
|
||||
Serialize.Value(writer, "Color", component.Color);
|
||||
Serialize.Value(writer, "UvTransform", component.UvTransform);
|
||||
Serialize.Value(writer, "IsCircle", component.IsCircle);
|
||||
Serialize.Value(writer, "Sprite", component.Sprite);
|
||||
Serialize.Value(writer, "UvTransform", component.UvTransform);
|
||||
});
|
||||
|
||||
SerializeComponent<TransformComponent>(writer, entity, "TransformComponent", scope (component) =>
|
||||
@@ -308,9 +309,19 @@ namespace GlitchyEngine.World
|
||||
|
||||
Try!(Deserialize.Value(reader, "Color", out component.Color));
|
||||
reader.EntryEnd();
|
||||
Try!(Deserialize.Value(reader, "UvTransform", out component.UvTransform));
|
||||
reader.EntryEnd();
|
||||
Try!(Deserialize.Value(reader, "IsCircle", out component.IsCircle));
|
||||
reader.EntryEnd();
|
||||
|
||||
String spriteName;
|
||||
Try!(Deserialize.Value(reader, "Sprite", out spriteName));
|
||||
|
||||
if (spriteName != null)
|
||||
component.Sprite = Content.LoadAsset<Texture2D>(spriteName);
|
||||
|
||||
delete spriteName;
|
||||
|
||||
reader.EntryEnd();
|
||||
Try!(Deserialize.Value(reader, "UvTransform", out component.UvTransform));
|
||||
|
||||
return .Ok;
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user