瀏覽代碼

Add TextResource

Daniele Bartolini 13 年之前
父節點
當前提交
da386719db
共有 2 個文件被更改,包括 72 次插入0 次删除
  1. 49 0
      src/TextResource.cpp
  2. 23 0
      src/TextResource.h

+ 49 - 0
src/TextResource.cpp

@@ -0,0 +1,49 @@
+#include "TextResource.h"
+#include "FileStream.h"
+#include "ResourceArchive.h"
+#include "Log.h"
+
+#include <cstdio>
+
+namespace crown
+{
+
+//-----------------------------------------------------------------------------
+TextResource* TextResource::load(ResourceArchive* archive, ResourceId id)
+{
+	assert(archive != NULL);
+	
+	Log::D("TextResource::load called.");
+	
+	FileStream* stream = archive->find(id);
+
+	if (stream != NULL)
+	{
+		TextResource* resource = new TextResource;
+
+		stream->read(&resource->length, sizeof(uint32_t));
+		
+		resource->data = new char[resource->length + 1];
+		
+		printf("Resource length: %d\n", resource->length);
+		
+		stream->read(resource->data, (size_t)resource->length);
+		
+		resource->data[resource->length] = '\0';
+
+		return resource;
+	}
+
+	Log::E("Unable to find the resource.");
+
+	return NULL;
+}
+
+//-----------------------------------------------------------------------------
+void TextResource::unload(TextResource* text)
+{
+
+}
+
+} // namespace crown
+

+ 23 - 0
src/TextResource.h

@@ -0,0 +1,23 @@
+#pragma once
+
+#include "Types.h"
+#include "Resource.h"
+
+namespace crown
+{
+
+class ResourceArchive;
+
+class TextResource
+{
+public:
+
+	static TextResource*		load(ResourceArchive* archive, ResourceId id);
+	static void					unload(TextResource* text);
+
+	uint32_t					length;
+	char*						data;
+};
+
+} // namespace crown
+