[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pingus-CVS] CVS: Games/Pingus/src col_map.cxx,1.12,1.13 col_map.hxx,1.9
From: |
grumbel |
Subject: |
[Pingus-CVS] CVS: Games/Pingus/src col_map.cxx,1.12,1.13 col_map.hxx,1.9,1.10 smallmap.cxx,1.21,1.22 smallmap.hxx,1.12,1.13 |
Date: |
7 Oct 2002 23:09:16 -0000 |
Update of /usr/local/cvsroot/Games/Pingus/src
In directory dark:/tmp/cvs-serv7461
Modified Files:
col_map.cxx col_map.hxx smallmap.cxx smallmap.hxx
Log Message:
added smallmap updates, they are fast, but not fast enough, there is still a
noticable slowdown
Index: col_map.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/col_map.cxx,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- col_map.cxx 28 Sep 2002 18:11:40 -0000 1.12
+++ col_map.cxx 7 Oct 2002 23:09:14 -0000 1.13
@@ -30,9 +30,12 @@
#include <config.h>
#include "my_gettext.hxx"
+#define COLMAP_WITH_MEMORY_HOLE 1
+
// Obtain the colmap from a memory area
ColMap::ColMap(int w, int h)
- : width(w),
+ : serial(0),
+ width(w),
height(h),
colmap(new unsigned char[width * height])
{
@@ -83,6 +86,8 @@
void
ColMap::remove(CL_SurfaceProvider* provider, int x, int y)
{
+ ++serial;
+
assert(provider);
if (provider->get_depth() == 32)
@@ -109,8 +114,9 @@
}
}
}
- // FIXME: Memory hole
- //provider->unlock();
+#if COLMAP_WITH_MEMORY_HOLE
+ provider->unlock();
+#endif
}
else if (provider->get_depth() == 8)
{
@@ -136,8 +142,9 @@
}
}
}
- // FIXME: Memory hole
- //provider->unlock();
+#if COLMAP_WITH_MEMORY_HOLE
+ provider->unlock();
+#endif
}
else
{
@@ -148,6 +155,8 @@
void
ColMap::put(int x, int y, Groundtype::GPType p)
{
+ ++serial;
+
if (x > 0 && x < width
&& y > 0 && y < height)
{
@@ -160,24 +169,6 @@
}
}
-#if 0
-int
-ColMap::load(unsigned char* b, int w, int h)
-{
- if (!init)
- {
- std::cout << "ColMap: loading..." << std::endl;
- init = true;
- colmap = b;
- width = w;
- height = h;
- return 1;
- } else {
- PingusError::raise(_("ColMap::load: Reloaded ColMap!"));
- return 0;
- }
-}
-#endif
bool
ColMap::blit_allowed (int x, int y, Groundtype::GPType gtype)
{
@@ -323,11 +314,19 @@
}
// FIXME: Memory hole
- //canvas->unlock();
+#if COLMAP_WITH_MEMORY_HOLE
+ canvas->unlock();
+#endif
sur = CL_Surface(canvas, true);
gc.draw(sur, 0, 0);
+}
+
+unsigned
+ColMap::get_serial()
+{
+ return serial;
}
/* EOF */
Index: col_map.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/col_map.hxx,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- col_map.hxx 27 Sep 2002 11:26:43 -0000 1.9
+++ col_map.hxx 7 Oct 2002 23:09:14 -0000 1.10
@@ -35,6 +35,10 @@
class ColMap
{
private:
+ /** The serial number indicates the state of the colmap, on every
+ change of the colmap it will get increased. */
+ unsigned int serial;
+
/** The width of the collision map. */
int width;
@@ -63,6 +67,10 @@
int get_width();
int getpixel(int x, int y);
+
+ /** @return a number which represents the state of the collision
+ map, once it changes the serial changes also */
+ unsigned get_serial();
/** Return true if the given GroundType i*/
bool blit_allowed (int x, int y, Groundtype::GPType);
Index: smallmap.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/smallmap.cxx,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- smallmap.cxx 6 Oct 2002 23:14:19 -0000 1.21
+++ smallmap.cxx 7 Oct 2002 23:09:14 -0000 1.22
@@ -28,11 +28,14 @@
#include "col_map.hxx"
#include "true_server.hxx"
#include "pingu.hxx"
+#include "timer.hxx"
#include "math.hxx"
using namespace std;
SmallMap::SmallMap()
+ : canvas(0),
+ update_count(0)
{
max_width = 175;
max_height = 100;
@@ -47,12 +50,12 @@
SmallMap::~SmallMap()
{
+ delete canvas;
}
void
SmallMap::init()
{
- CL_Canvas* canvas;
unsigned char* buffer;
unsigned char* cbuffer;
unsigned char current_pixel;
@@ -63,99 +66,113 @@
ColMap* colmap = client->get_server()->get_world()->get_colmap();
buffer = colmap->get_data();
- //Plf* plf = world->get_plf();
- // Scaling values used in order to keep the aspect ratio
- int x_scaling = colmap->get_width() / max_width;
- int y_scaling = colmap->get_height() / max_height;
+ colmap_serial = colmap->get_serial();
- // If at best one horizontal pixel in the smallmap represents more colmap
- // pixels than one vertical pixel
- if (x_scaling > y_scaling)
- {
- width = max_width;
- height = colmap->get_height() / x_scaling;
- }
- else
+ if (!canvas)
{
- width = colmap->get_width() / y_scaling;
- height = max_height;
- }
+ // Scaling values used in order to keep the aspect ratio
+ int x_scaling = colmap->get_width() / max_width;
+ int y_scaling = colmap->get_height() / max_height;
- canvas = new CL_Canvas(width, height);
+ // If at best one horizontal pixel in the smallmap represents more colmap
+ // pixels than one vertical pixel
+ if (x_scaling > y_scaling)
+ {
+ width = max_width;
+ height = colmap->get_height() / x_scaling;
+ }
+ else
+ {
+ width = colmap->get_width() / y_scaling;
+ height = max_height;
+ }
+
+ canvas = new CL_Canvas(width, height);
+ }
canvas->lock();
cbuffer = static_cast<unsigned char*>(canvas->get_data());
+ int cmap_width = colmap->get_width();
+ int cmap_height = colmap->get_height();
+
for(int y = 0; y < height; ++y)
{
for (int x = 0; x < width; ++x)
{
- tx = x * colmap->get_width() / width;
- ty = y * colmap->get_height() / height;
+ // Index on the smallmap canvas
+ int i = 4 * ((y * width) + x);
+
+ tx = x * cmap_width / width;
+ ty = y * cmap_height / height;
- current_pixel = buffer[tx + (ty * colmap->get_width())];
+ current_pixel = buffer[tx + (ty * cmap_width)];
- if (current_pixel == Groundtype::GP_NOTHING)
- {
- cbuffer[4 * ((y * width) + x) + 0] = 150;
- cbuffer[4 * ((y * width) + x) + 1] = 0;
- cbuffer[4 * ((y * width) + x) + 2] = 0;
- cbuffer[4 * ((y * width) + x) + 3] = 0;
- }
- else if (current_pixel == Groundtype::GP_BRIDGE)
- {
- cbuffer[4 * ((y * width) + x) + 0] = 255;
- cbuffer[4 * ((y * width) + x) + 1] = 100;
- cbuffer[4 * ((y * width) + x) + 2] = 255;
- cbuffer[4 * ((y * width) + x) + 3] = 0;
- }
- else if (current_pixel == Groundtype::GP_LAVA)
- {
- cbuffer[4 * ((y * width) + x) + 0] = 255;
- cbuffer[4 * ((y * width) + x) + 1] = 100;
- cbuffer[4 * ((y * width) + x) + 2] = 100;
- cbuffer[4 * ((y * width) + x) + 3] = 255;
- }
- else if (current_pixel == Groundtype::GP_SOLID)
- {
- cbuffer[4 * ((y * width) + x) + 0] = 255;
- cbuffer[4 * ((y * width) + x) + 1] = 100;
- cbuffer[4 * ((y * width) + x) + 2] = 100;
- cbuffer[4 * ((y * width) + x) + 3] = 100;
- }
- else
- {
- cbuffer[4 * ((y * width) + x) + 0] = 255;
- cbuffer[4 * ((y * width) + x) + 1] = 200;
- cbuffer[4 * ((y * width) + x) + 2] = 200;
- cbuffer[4 * ((y * width) + x) + 3] = 200;
- }
+ switch (current_pixel)
+ {
+ case Groundtype::GP_NOTHING:
+ cbuffer[i + 0] = 150;
+ cbuffer[i + 1] = 0;
+ cbuffer[i + 2] = 0;
+ cbuffer[i + 3] = 0;
+ break;
+
+ case Groundtype::GP_BRIDGE:
+ cbuffer[i + 0] = 255;
+ cbuffer[i + 1] = 100;
+ cbuffer[i + 2] = 255;
+ cbuffer[i + 3] = 0;
+ break;
+
+ case Groundtype::GP_LAVA:
+ cbuffer[i + 0] = 255;
+ cbuffer[i + 1] = 100;
+ cbuffer[i + 2] = 100;
+ cbuffer[i + 3] = 255;
+ break;
+
+ case Groundtype::GP_SOLID:
+ cbuffer[i + 0] = 255;
+ cbuffer[i + 1] = 100;
+ cbuffer[i + 2] = 100;
+ cbuffer[i + 3] = 100;
+ break;
+
+ default:
+ cbuffer[i + 0] = 255;
+ cbuffer[i + 1] = 200;
+ cbuffer[i + 2] = 200;
+ cbuffer[i + 3] = 200;
+ break;
+ }
}
}
/* FIXME: due to API change in PLF disabled
- std::vector<ExitData> exit_d = plf->get_exit();
- for(std::vector<ExitData>::iterator i = exit_d.begin(); i != exit_d.end();
++i)
- {
- // FIXME: Replace this with put_target() when it is bug free
- Blitter::put_surface(canvas, exit_sur,
- i->pos.x * width / colmap->get_width() -
(exit_sur.get_width()/2),
- i->pos.y * height / colmap->get_height());
- }
+ std::vector<ExitData> exit_d = plf->get_exit();
+ for(std::vector<ExitData>::iterator i = exit_d.begin(); i !=
exit_d.end(); ++i)
+ {
+ // FIXME: Replace this with put_target() when it is bug free
+ Blitter::put_surface(canvas, exit_sur,
+ i->pos.x * width / colmap->get_width() - (exit_sur.get_width()/2),
+ i->pos.y * height / colmap->get_height());
+ }
- std::vector<EntranceData> entrance_d = plf->get_entrance();
- for(std::vector<EntranceData>::iterator i = entrance_d.begin(); i !=
entrance_d.end(); ++i)
- {
- Blitter::put_surface(canvas, entrance_sur,
- i->pos.x * width / colmap->get_width() -
(entrance_sur.get_width()/2),
- i->pos.y * height / colmap->get_height() -
(entrance_sur.get_height()));
- }
+ std::vector<EntranceData> entrance_d = plf->get_entrance();
+ for(std::vector<EntranceData>::iterator i = entrance_d.begin(); i !=
entrance_d.end(); ++i)
+ {
+ Blitter::put_surface(canvas, entrance_sur,
+ i->pos.x * width / colmap->get_width() - (entrance_sur.get_width()/2),
+ i->pos.y * height / colmap->get_height() - (entrance_sur.get_height()));
+ }
*/
canvas->unlock();
-
- sur = CL_Surface(canvas, true);
-
+
+ //Timer surface_timer("Smallmap surface creation");
+ sur = CL_Surface(canvas, false);
+ //surface_timer.stop();
+
x_pos = 5;
y_pos = CL_Display::get_height() - sur.get_height();
@@ -238,7 +255,21 @@
void
SmallMap::update (float delta)
{
+ float smallmap_update_time = 2.0f;
+
UNUSED_ARG(delta);
+ update_count += delta;
+
+ if (update_count > smallmap_update_time)
+ {
+ update_count = 0.0f;
+ ColMap* colmap = client->get_server()->get_world()->get_colmap();
+
+ if (colmap_serial != colmap->get_serial())
+ {
+ init();
+ }
+ }
}
bool
Index: smallmap.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/smallmap.hxx,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- smallmap.hxx 6 Oct 2002 23:14:19 -0000 1.12
+++ smallmap.hxx 7 Oct 2002 23:09:14 -0000 1.13
@@ -25,6 +25,7 @@
class CL_Key;
class Client;
+class CL_Canvas;
/** This is the map that appears in the corner of the screen */
class SmallMap : public GUI::Component
@@ -40,6 +41,9 @@
/** Graphic surface for the generated rectanglar background of the small map
*/
CL_Surface sur;
+
+ /** The canvas that represents the small-colmap */
+ CL_Canvas* canvas;
/** Horizontal position of the small map */
int x_pos;
@@ -70,6 +74,11 @@
int rheight;
bool has_focus;
+
+ /** number of seconds till the smallmap will update itself */
+ float update_count;
+
+ unsigned int colmap_serial;
public:
SmallMap();
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pingus-CVS] CVS: Games/Pingus/src col_map.cxx,1.12,1.13 col_map.hxx,1.9,1.10 smallmap.cxx,1.21,1.22 smallmap.hxx,1.12,1.13,
grumbel <=