[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pingus-CVS] CVS: Games/Pingus/src/editor object_selector.cxx,1.1,1.2 th
From: |
grumbel |
Subject: |
[Pingus-CVS] CVS: Games/Pingus/src/editor object_selector.cxx,1.1,1.2 thumb_cache.cxx,1.3,1.4 |
Date: |
22 Jun 2002 14:29:20 -0000 |
Update of /usr/local/cvsroot/Games/Pingus/src/editor
In directory dark:/tmp/cvs-serv22836/editor
Modified Files:
object_selector.cxx thumb_cache.cxx
Log Message:
- added mtime checker for the thumbnails
- added version info for the thumbnail
Index: object_selector.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/editor/object_selector.cxx,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- object_selector.cxx 12 Jun 2002 19:11:31 -0000 1.1
+++ object_selector.cxx 22 Jun 2002 14:29:18 -0000 1.2
@@ -551,6 +551,7 @@
for(std::list<string>::iterator i = liste->begin(); i != liste->end(); i++)
{
+ // FIXME: This should be moved to ThumbCache
++j;
sur_obj.name = *i;
sur_obj.datafile = resource_file;
Index: thumb_cache.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/editor/thumb_cache.cxx,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- thumb_cache.cxx 20 Jun 2002 11:23:53 -0000 1.3
+++ thumb_cache.cxx 22 Jun 2002 14:29:18 -0000 1.4
@@ -19,10 +19,14 @@
#include <stdio.h>
#include <iostream>
+#include <ClanLib/Core/IOData/outputsource_file.h>
+#include <ClanLib/Core/IOData/inputsource_file.h>
+#include <ClanLib/Core/System/error.h>
#include <ClanLib/Display/SurfaceProviders/canvas.h>
#include "../globals.hxx"
#include "../blitter.hxx"
#include "../system.hxx"
+#include "../pingus_resource.hxx"
#include "thumb_cache.hxx"
CL_Surface
@@ -40,30 +44,55 @@
if (System::exist (filename))
{
- FILE* in = fopen (filename.c_str (), "r");
-
- if (in)
+ //FILE* in = fopen (filename.c_str (), "r");
+ try
{
+ CL_InputSource_File in(filename);
+
CL_Canvas* canvas = new CL_Canvas (50, 50);
canvas->lock ();
- unsigned char* buffer = static_cast<unsigned char*>(canvas->get_data
());
+ void* buffer = canvas->get_data ();
size_t buffer_size = 50 * 50 * 4;
- size_t read_size = fread (buffer, sizeof (unsigned char*),
buffer_size, in);
+
+ unsigned int version = in.read_uint32 ();
+
+ if (version != 1)
+ {
+ std::cout << "Thumbnail: version mismatch" << std::endl;
+ delete canvas;
+ return CL_Surface ();
+ }
+
+ unsigned int timestamp = in.read_uint32 ();
+
+ // The thumbnail needs an update
+ if (timestamp != PingusResource::get_mtime (res_ident, datafile))
+ {
+ std::cout << "Thumbnail: file needs update" << std::endl;
+ delete canvas;
+ return CL_Surface ();
+ }
+
+ size_t read_size = in.read (buffer, buffer_size);
+
if (read_size != buffer_size)
{
if (pingus_debug_flags & PINGUS_DEBUG_EDITOR)
std::cerr << "ThumbCache: " << filename << ": read error:
wanted " << buffer_size << " got " << read_size << std::endl;
+ delete canvas;
+ return CL_Surface ();
}
- fclose (in);
canvas->unlock ();
return CL_Surface (canvas, true);
}
- else
+ catch (CL_Error& err)
{
- std::cout << "ThumbCache: Read error: " << filename << std::endl;
+ std::cout << "ThumbCache: Read error: " << filename << " | " <<
err.message <<std::endl;
+ return CL_Surface ();
}
}
+ // FIXME: This should return the correct surface
return CL_Surface ();
}
@@ -76,7 +105,6 @@
return;
}
- FILE* out;
std::string filename = res_ident + "-" + datafile;
for (unsigned int i = 0; i < filename.size (); i++)
@@ -85,23 +113,35 @@
filename = System::get_cachedir () + filename;
- CL_Canvas* canvas = Blitter::scale_surface_to_canvas (sur, 50, 50);
- std::cout <<" Writing cache file: " << filename << std::endl;
-
- out = fopen (filename.c_str (), "w");
+ unsigned int timestamp = PingusResource::get_mtime (res_ident, datafile);
+
+ std::cout <<"ThumbCache: Writing cache file: " << filename
+ << " timestamp: " << timestamp
+ << std::endl;
- if (out)
+ try
{
+ CL_OutputSource_File out(filename);
+
+ CL_Canvas* canvas = Blitter::scale_surface_to_canvas (sur, 50, 50);
canvas->lock ();
- unsigned char* buffer = static_cast<unsigned char*>(canvas->get_data());
+ void* buffer = canvas->get_data();
int buffer_size = canvas->get_height () * canvas->get_pitch ();
+
+ // Versionnumber of the thumbnail format
+ out.write_uint32 (1);
- fwrite (buffer, sizeof (unsigned char), buffer_size, out);
+ // Modification time of the parent file
+ out.write_uint32 (timestamp);
+
+ // Surface data
+ // FIXME: Endian issue here?!
+ out.write (buffer, buffer_size);
- fclose (out);
canvas->unlock ();
+ delete canvas;
}
- else
+ catch (CL_Error& err)
{
std::cout << "ThumbCache: Couldn't open file for writing: " << filename
<< std::endl;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pingus-CVS] CVS: Games/Pingus/src/editor object_selector.cxx,1.1,1.2 thumb_cache.cxx,1.3,1.4,
grumbel <=
- Prev by Date:
[Pingus-CVS] CVS: Games/Pingus/src pingu.hxx,1.1,1.2
- Next by Date:
[Pingus-CVS] CVS: Games/Pingus/src blitter.hxx,1.2,1.3 pingus_resource.cxx,1.4,1.5
- Previous by thread:
[Pingus-CVS] CVS: Games/Pingus/src pingu.hxx,1.1,1.2
- Next by thread:
[Pingus-CVS] CVS: Games/Pingus/src blitter.hxx,1.2,1.3 pingus_resource.cxx,1.4,1.5
- Index(es):