Page MenuHomePhabricator (Chris)

No OneTemporary

Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None
diff --git a/util/resource.cpp b/util/resource.cpp
new file mode 100644
index 00000000..fd247fda
--- /dev/null
+++ b/util/resource.cpp
@@ -0,0 +1,50 @@
+#include "bitmap.h"
+#include "resource.h"
+#include "factory/collector.h"
+#include "funcs.h"
+#include "sound.h"
+#include "load_exception.h"
+#include "file-system.h"
+#include <string>
+#include <vector>
+
+using namespace std;
+
+Resource * Resource::resource = NULL;
+Sound * Resource::getSound(const Filesystem::RelativePath & path) throw (LoadException){
+ return resource->_getSound(Filesystem::find(path));
+}
+
+Bitmap * Resource::getBitmap(const Filesystem::RelativePath & path) throw (LoadException){
+ return resource->_getBitmap(Filesystem::find(path));
+}
+
+/* the resource is created in the Collector */
+Resource::Resource(){
+ resource = this;
+}
+
+Resource::~Resource(){
+ for (std::map<std::string, Sound*>::iterator it = sounds.begin(); it != sounds.end(); it++){
+ delete (*it).second;
+ }
+
+ for (std::map<std::string, Bitmap*>::iterator it = bitmaps.begin(); it != bitmaps.end(); it++){
+ delete (*it).second;
+ }
+}
+
+Sound * Resource::_getSound(const Filesystem::AbsolutePath & path) throw (LoadException){
+ if (sounds[path.path()] == NULL){
+ sounds[path.path()] = new Sound(path.path());
+ }
+ return sounds[path.path()];
+}
+
+Bitmap * Resource::_getBitmap(const Filesystem::AbsolutePath & path) throw (LoadException){
+ if (bitmaps[path.path()] == NULL){
+ bitmaps[path.path()] = new Bitmap(path.path());
+ }
+
+ return bitmaps[path.path()];
+}
diff --git a/util/resource.h b/util/resource.h
new file mode 100644
index 00000000..4b977d93
--- /dev/null
+++ b/util/resource.h
@@ -0,0 +1,34 @@
+#ifndef _paintown_resource_manager_h
+#define _paintown_resource_manager_h
+
+#include "factory/collector.h"
+#include "load_exception.h"
+#include "file-system.h"
+#include <map>
+#include <string>
+#include <vector>
+
+class Sound;
+class Bitmap;
+
+class Resource{
+public:
+ /* do not prepend Util::getDataPath() to paths. Resource will do it for you.
+ */
+ static Sound * getSound(const Filesystem::RelativePath & path) throw (LoadException);
+ static Bitmap * getBitmap(const Filesystem::RelativePath & path) throw (LoadException);
+private:
+ friend class Collector;
+ Resource();
+ virtual ~Resource();
+
+ Sound * _getSound(const Filesystem::AbsolutePath & path) throw (LoadException);
+ Bitmap * _getBitmap(const Filesystem::AbsolutePath & path) throw (LoadException);
+
+private:
+ static Resource * resource;
+ std::map<std::string, Sound*> sounds;
+ std::map<std::string, Bitmap*> bitmaps;
+};
+
+#endif

File Metadata

Mime Type
text/x-diff
Expires
Thu, Jun 11, 11:47 AM (3 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
68866
Default Alt Text
(2 KB)

Event Timeline