mirror of
https://github.com/simtactics/mysimulation.git
synced 2025-07-14 18:21:58 -04:00
Added FSO.Files for use with the API server
Don't ask me. FreeSO is the prime example of dependency hell.
This commit is contained in:
parent
4b5e584eeb
commit
8fec258215
104 changed files with 14653 additions and 163 deletions
57
server/tso.files/Formats/IFF/Chunks/FSOM.cs
Executable file
57
server/tso.files/Formats/IFF/Chunks/FSOM.cs
Executable file
|
@ -0,0 +1,57 @@
|
|||
using FSO.Files.RC;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
|
||||
namespace FSO.Files.Formats.IFF.Chunks
|
||||
{
|
||||
/// <summary>
|
||||
/// Iff chunk wrapper for an FSOM file.
|
||||
/// </summary>
|
||||
public class FSOM : IffChunk
|
||||
{
|
||||
private byte[] data;
|
||||
private DGRP3DMesh Cached;
|
||||
|
||||
/// <summary>
|
||||
/// Reads a BMP chunk from a stream.
|
||||
/// </summary>
|
||||
/// <param name="iff">An Iff instance.</param>
|
||||
/// <param name="stream">A Stream object holding a BMP chunk.</param>
|
||||
public override void Read(IffFile iff, Stream stream)
|
||||
{
|
||||
data = new byte[stream.Length];
|
||||
stream.Read(data, 0, (int)stream.Length);
|
||||
}
|
||||
|
||||
public override bool Write(IffFile iff, Stream stream)
|
||||
{
|
||||
if (data == null)
|
||||
{
|
||||
using (var cstream = new GZipStream(stream, CompressionMode.Compress))
|
||||
Cached.Save(cstream);
|
||||
} else
|
||||
{
|
||||
stream.Write(data, 0, data.Length);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public DGRP3DMesh Get(DGRP dgrp, GraphicsDevice device)
|
||||
{
|
||||
if (Cached == null) {
|
||||
using (var stream = new MemoryStream(data)) {
|
||||
Cached = new DGRP3DMesh(dgrp, stream, device);
|
||||
}
|
||||
}
|
||||
data = null;
|
||||
return Cached;
|
||||
}
|
||||
|
||||
public void SetMesh(DGRP3DMesh mesh)
|
||||
{
|
||||
Cached = mesh;
|
||||
data = null;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue