Exemple #1
0
		void Initialize (Stream stream) {
			var tr = new TarReader(stream);
			MemoryStream modelStream = null;
			var textures = new Dictionary<string, Texture>();

			try {
				while (tr.MoveNext(false)) {
					var name = tr.FileInfo.FileName;
					if (name == "model.bin") {
						modelStream = new MemoryStream();
						tr.Read(modelStream);
						modelStream.Position = 0;
					}
					else if (name.Length > 4 && name.EndsWith(".png")) {
						using(var ms = new MemoryStream()) {
							tr.Read(ms);
							ms.Position = 0;
							textures.Add(name.Substring(0, name.Length - 4), new Texture(ms, null));
						}
					}
					else
						throw new ContentException("Unrecognized model file " + tr.FileInfo.FileName);
				}
				if (modelStream == null)
					throw new ContentException("Model data not found.");
				using (var reader = new BinaryReader(modelStream)) {
					this.InitModel(reader, textures);
				}
			} finally {
				if (modelStream != null)
					modelStream.Dispose();
			}
		}
Exemple #2
0
		public BitmapFont (Stream stream, Shader shader = null) {
			ThreadContext.Current.EnsureGLContext();

			if (shader == null)
				shader = new SpriteShader();

			var tr = new TarReader(stream);
			while (tr.MoveNext(false)) {
				switch (tr.FileInfo.FileName) {
					case "font.atlas":
						using (var atlasStream = new MemoryStream()) {
							tr.Read(atlasStream);
							atlasStream.Position = 0;
							this.ParseStream(atlasStream);
						}
						break;
					case "font.png":
						using (var textureStream = new MemoryStream()) {
							tr.Read(textureStream);
							textureStream.Position = 0;

							_material = new SpriteMaterial(shader, new Texture (textureStream));
						}
						break;
					default:
						throw new ContentException("Unrecognized font file " + tr.FileInfo.FileName);
				}
			}

			if (_chars == null)
				throw new ContentException("Missing font atlas.");
			if (_material == null)
				throw new ContentException("Missing font texture.");
		}
Exemple #3
0
		public SoundEffect (Stream inputStream) {
			byte[] pcmData = null;

			using (var s = inputStream) {
				var tr = new TarReader (s);
				while (tr.MoveNext (false)) {
					switch (tr.FileInfo.FileName) {
						case "sound.bin":
							var bytes = new byte[tr.FileInfo.SizeInBytes];
							using (var ms = new MemoryStream(bytes)) {
								tr.Read (ms);
								ms.Position = 0;
								using (var br = new BinaryReader(ms)) {
									_md = SfxMetadata.Read (br);
								}
							}
							break;
						case "sound.pcm":
							pcmData = new byte[tr.FileInfo.SizeInBytes];
							tr.Read (new MemoryStream (pcmData));
							break;
						default:
							throw new ContentException ("Unrecognized sound file " + tr.FileInfo.FileName);
					}
				}
			}

			ALFormat format;
			switch (_md.Channels) {
				case 1:
					switch (_md.Bits) {
						case 8:
							format = ALFormat.Mono8;
							break;
						case 16:
							format = ALFormat.Mono16;
							break;
						case 32:
							format = ALFormat.MonoFloat32Ext;
							break;
						default:
							throw new NotSupportedException ("Sounds must be 8, 16, or 32 bit.");
					}
					break;
				case 2:
					switch (_md.Bits) {
						case 8:
							format = ALFormat.Stereo8;
							break;
						case 16:
							format = ALFormat.Stereo16;
							break;
						case 32:
							format = ALFormat.StereoFloat32Ext;
							break;
						default:
							throw new NotSupportedException ("Sounds must be 8, 16, or 32 bit.");
					}
					break;
				default:
					throw new NotSupportedException ("Sound effects must be mono or stereo.");
			}

			_buffer = AL.GenBuffer ();
			AL.BufferData (_buffer, format, pcmData, pcmData.Length, _md.Rate);
		}