pingus-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Pingus-CVS] CVS: Games/Pingus/src indexed_canvas.cxx,NONE,1.1 indexed_c


From: grumbel
Subject: [Pingus-CVS] CVS: Games/Pingus/src indexed_canvas.cxx,NONE,1.1 indexed_canvas.hxx,NONE,1.1 Makefile.am,1.116,1.117 action_holder.cxx,1.6,1.7 action_holder.hxx,1.8,1.9 capture_rectangle.cxx,1.11,1.12 pingu.cxx,1.33,1.34 pingu.hxx,1.21,1.22 pingu_holder.cxx,1.16,1.17 pingu_info.cxx,1.4,1.5 server.cxx,1.23,1.24
Date: 12 Oct 2002 00:24:28 -0000

Update of /usr/local/cvsroot/Games/Pingus/src
In directory dark:/tmp/cvs-serv9541

Modified Files:
        Makefile.am action_holder.cxx action_holder.hxx 
        capture_rectangle.cxx pingu.cxx pingu.hxx pingu_holder.cxx 
        pingu_info.cxx server.cxx 
Added Files:
        indexed_canvas.cxx indexed_canvas.hxx 
Log Message:
removed PinguAction* from the public API
- added Gervases experimental bomber code

--- NEW FILE: indexed_canvas.cxx ---
//  $Id: indexed_canvas.cxx,v 1.1 2002/10/12 00:24:26 grumbel Exp $
//
//  Pingus - A free Lemmings clone
//  Copyright (C) 2002 Ingo Ruhnke <address@hidden>
//
//  This program is free software; you can redistribute it and/or
//  modify it under the terms of the GNU General Public License
//  as published by the Free Software Foundation; either version 2
//  of the License, or (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

#include "indexed_canvas.hxx"

IndexedCanvas::IndexedCanvas(int width, int height)
{
  data = new unsigned char [width * height];
  new IndexedCanvas(10, 10);
}

IndexedCanvas::~IndexedCanvas()
{
  delete data;
}

void
IndexedCanvas::set_palette(CL_Palette* p)
{
  palette = *p;
}

CL_Palette*
IndexedCanvas::get_palette() const
{
  return const_cast<CL_Palette*>(&palette);
}

/* EOF */

--- NEW FILE: indexed_canvas.hxx ---
//  $Id: indexed_canvas.hxx,v 1.1 2002/10/12 00:24:26 grumbel Exp $
// 
//  Pingus - A free Lemmings clone
//  Copyright (C) 2002 Ingo Ruhnke <address@hidden>
//
//  This program is free software; you can redistribute it and/or
//  modify it under the terms of the GNU General Public License
//  as published by the Free Software Foundation; either version 2
//  of the License, or (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
// 
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

#ifndef HEADER_PINGUS_INDEXED_CANVAS_HXX
#define HEADER_PINGUS_INDEXED_CANVAS_HXX

#include <ClanLib/Display/SurfaceProviders/generic_surfaceprovider.h>
#include <ClanLib/Display/Display/palette.h>

/** This class is analog to CL_Canvas, but instead of being true
    color, it is indexed */
class IndexedCanvas : public CL_SurfaceProvider_Generic
{
private:
  unsigned int width;
  unsigned int height;
  unsigned char* data;
  CL_Palette palette;
public:
  IndexedCanvas(int width, int height);
  ~IndexedCanvas();

  bool is_indexed() const { return true; }
  unsigned int get_width()  const { return width; }
  unsigned int get_pitch()  const { return width; }
  unsigned int get_height() const { return height; }

  unsigned int   get_num_frames() const { return 1; }
  void* get_data() const { return data; }
  void  set_palette(CL_Palette*);
  CL_Palette* get_palette() const;

  void perform_lock() {}
  void perform_unlock() {}

  bool         uses_src_colorkey() const { return false; }
  unsigned int get_src_colorkey() const { return 0; }

  unsigned int get_red_mask() const { return 0; }
  unsigned int get_green_mask() const { return 0; }
  unsigned int get_blue_mask() const { return 0; }
  unsigned int get_alpha_mask() const { return 0; }
private:
  IndexedCanvas (const IndexedCanvas&);
  IndexedCanvas& operator= (const IndexedCanvas&);
};

#endif

/* EOF */

Index: Makefile.am
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/Makefile.am,v
retrieving revision 1.116
retrieving revision 1.117
diff -u -d -r1.116 -r1.117
--- Makefile.am 8 Oct 2002 22:58:02 -0000       1.116
+++ Makefile.am 12 Oct 2002 00:24:26 -0000      1.117
@@ -168,6 +168,8 @@
 input_event.hxx \
 input_debug_screen.hxx \
 input_debug_screen.cxx \
+indexed_canvas.hxx \
+indexed_canvas.cxx \
 intro.cxx \
 intro.hxx \
 layer_manager.cxx \

Index: action_holder.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/action_holder.cxx,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- action_holder.cxx   4 Oct 2002 11:38:28 -0000       1.6
+++ action_holder.cxx   12 Oct 2002 00:24:26 -0000      1.7
@@ -52,32 +52,26 @@
   available_actions[name]++;
 }
 
-int
-ActionHolder::get_available (ActionName name)
+bool
+ActionHolder::pop_action (ActionName name)
 {
-  return available_actions[name];
-}
+  int& avail = available_actions[name];
 
-PinguAction*
-ActionHolder::get_action (ActionName name)
-{
-  if (unlimited_actions) // runtime option; defined in global.hh
-    {    
-      return PinguActionFactory::instance()->create(name);
-    } 
-  else 
+  if (avail > 0)
     {
-      int& count = available_actions[name];
-      if (count > 0) 
-       {
-         --count;
-         return PinguActionFactory::instance()->create(name);
-       }
-      else // Out of actions
-       {
-         return 0;
-       }
+      --avail;
+      return true;
     }
+  else
+    {
+      return false;    
+    }
+}
+
+int
+ActionHolder::get_available (ActionName name)
+{
+  return available_actions[name];
 }
 
 /* EOF */

Index: action_holder.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/action_holder.hxx,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- action_holder.hxx   4 Oct 2002 11:38:28 -0000       1.8
+++ action_holder.hxx   12 Oct 2002 00:24:26 -0000      1.9
@@ -62,18 +62,16 @@
    */
   void push_action (ActionName name);
 
+  /** Removes an action from the pool of actions
+      @return true if an action was available and removed, false if no
+      actions where available */
+  bool pop_action (ActionName name);
+
   /** Returns the number of actions of the specified name which are available 
    *  thru get_action() 
    * @return 0 if the name is unknown FIXME: should use .find instead of []
    */
   int get_available (ActionName);
-
-  /** Returns a newly allocated or cached action by a given name. It
-   *  returns it from the action pool and decreases the number of available
-   *  actions if necessary. If the actions are out, it returns 0. 
-   *  The deletion of the action is handled by this class.  
-   */
-  PinguAction* get_action (ActionName);
   
 private:
   ActionHolder (const ActionHolder&);

Index: capture_rectangle.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/capture_rectangle.cxx,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- capture_rectangle.cxx       4 Oct 2002 13:46:56 -0000       1.11
+++ capture_rectangle.cxx       12 Oct 2002 00:24:26 -0000      1.12
@@ -98,7 +98,7 @@
 
   if (pingu)
     {
-      action_str = pingu->get_action()->get_name();
+      action_str = pingu->get_name();
   
       if (pingu->get_wall_action() || pingu->get_fall_action())
         {

Index: pingu.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/pingu.cxx,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -d -r1.33 -r1.34
--- pingu.cxx   4 Oct 2002 16:54:04 -0000       1.33
+++ pingu.cxx   12 Oct 2002 00:24:26 -0000      1.34
@@ -42,6 +42,7 @@
     countdown_action (0),
     wall_action(0),
     fall_action(0),
+    previous_action (Actions::Faller),
     id(arg_id),
     action_time(-1),
     owner_id(owner),
@@ -51,7 +52,11 @@
     velocity(new Vector(0, 0, 0))
 {
   direction.left ();
-  set_action(Faller);
+
+  // Initialisize the action, after this step the action ptr will
+  // always be valid in the pingu class
+  action = PinguActionFactory::instance()->create(Faller);
+  action->set_pingu(this);
 }
 
 Pingu::~Pingu ()
@@ -135,7 +140,6 @@
        else if (action->change_allowed(act->get_type()))
          {
            pout(PINGUS_DEBUG_ACTIONS) << "setting instant action" << std::endl;
-           act->set_pingu(this);
            set_action(act);
            ret_val = true;
          }
@@ -229,6 +233,9 @@
 Pingu::set_action (PinguAction* act) 
 {
   assert(act);
+
+  previous_action = action->get_type();
+
   action = act;
   action->set_pingu(this);
 }
@@ -387,10 +394,16 @@
   return (status != PS_DEAD && status != PS_EXITED);
 }
 
-PinguAction*
+std::string
+Pingu::get_name()
+{
+  return action->get_name();
+}
+
+Actions::ActionName
 Pingu::get_action ()
 {
-  return action;
+  return action->get_type();
 }
 
 void

Index: pingu.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/pingu.hxx,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- pingu.hxx   4 Oct 2002 16:54:04 -0000       1.21
+++ pingu.hxx   12 Oct 2002 00:24:26 -0000      1.22
@@ -37,7 +37,7 @@
 private:
   /** The primary action with is currently in use */
   PinguAction* action;
-
+  
   /** A secondary action which will turn active after a given amount of time
       The only example is currently the bomber. */
   PinguAction* countdown_action;
@@ -48,6 +48,11 @@
   /** the action that gets triggered when the pingu falls */
   PinguAction* fall_action;
 
+  /** The previous_action contains the action type that was in action
+      before action got applied, its here to enable action to behave
+      differently depending on the previous action */
+  Actions::ActionName previous_action;
+
   /** The uniq id of the Pingu, this is used to refer to the Pingu in
       a demo file or in a network connection */
   unsigned int id;
@@ -63,15 +68,14 @@
   
   Vector* const velocity; 
 
+  bool request_set_action (PinguAction*);
+  void  set_action (PinguAction*);
+
 public:
 
   //FIXME make me private
   Direction direction;
 
-  bool request_set_action (PinguAction*);
-  
-  void  set_action (PinguAction*);
-
   /** Creates a new Pingu at the given coordinates
       @param arg_id The uniq id of the pingu
       @param pos The start position of the pingu
@@ -110,7 +114,12 @@
 
   PinguStatus set_status (PinguStatus);
 
-  PinguAction* get_action ();
+  /** The descriptive name of the action, this is used in the
+      CaputreRectangle, so it can contain more than just the name
+      (number of blocks, etc.) */
+  std::string get_name();
+
+  Actions::ActionName get_action ();
 
   /// Returns the unique id of the pingu
   unsigned int  get_id (void); 

Index: pingu_holder.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/pingu_holder.cxx,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- pingu_holder.cxx    8 Oct 2002 00:09:55 -0000       1.16
+++ pingu_holder.cxx    12 Oct 2002 00:24:26 -0000      1.17
@@ -69,7 +69,7 @@
       pingu != pingus.end(); 
       ++pingu)
     {
-      if ((*pingu)->get_action()->get_type() == Actions::Walker) 
+      if ((*pingu)->get_action() == Actions::Walker) 
        (*pingu)->draw (gc);
     }
   
@@ -84,7 +84,7 @@
       pingu != pingus.end(); 
       ++pingu)
     {
-      if ((*pingu)->get_action()->get_type() != Actions::Walker)
+      if ((*pingu)->get_action() != Actions::Walker)
        (*pingu)->draw (gc);
     }
 }

Index: pingu_info.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/pingu_info.cxx,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- pingu_info.cxx      4 Sep 2002 14:55:11 -0000       1.4
+++ pingu_info.cxx      12 Oct 2002 00:24:26 -0000      1.5
@@ -58,7 +58,7 @@
                     str);
 
     if (pingu->get_action()) {
-      snprintf(str, 128, _("action %s"), 
pingu->get_action()->get_name().c_str());
+      snprintf(str, 128, _("action %s"), pingu->get_name().c_str());
     } else {
       snprintf(str, 128, _("action none"));
     }

Index: server.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/server.cxx,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- server.cxx  5 Oct 2002 12:40:02 -0000       1.23
+++ server.cxx  12 Oct 2002 00:24:26 -0000      1.24
@@ -77,11 +77,9 @@
 void
 Server::send_pingu_action_event (Pingu* pingu, Actions::ActionName action)
 {
-  PinguAction* tmp_action = action_holder.get_action(action);
-         
-  if (tmp_action)
+  if (action_holder.pop_action(action))
     {
-      if (!(pingu->request_set_action(tmp_action)))
+      if (!(pingu->request_set_action(action)))
        {
          action_holder.push_action(action);
        }





reply via email to

[Prev in Thread] Current Thread [Next in Thread]