PLM Software Multimedia Tools and Games
PLMBase

PLMBase Component : Base


Overview

In this section, we will find basic building blocks, such as :

  • data structures like PLMPoint, PLMRect and PLMVec3 but also PLMStack and PLMString.
  • File utilities, to easily perform simple operations on files and directories in a portable way (linux and win32).
  • Event system, based on the PLMInput class, who gives access to the system event queue (keyboard, mouse, joystick, window manager, ...). Keys are defined as enums in PLMKey.hpp. A series of structures is defined in PLMEvent.hpp to handle many types of event.
  • PLMCallback, mainly used by the user interface classes to handle smart pointers.
  • PLMSDLMgr, the SDL session manager helps the hardware-oriented classes to automatically initialise and de-initialise the SDL components (mainly for video, audio, input and timer).
  • The PLMTimer allows to measure time. It can save and compute elapsed time from the last saved time.
  • The PLMClipboard class gives access to the system clipboard (copy/paste).

Example

This example illustrate PLMInput and PLMTimer classes, it is in fact the main event loop of an application :

void Game::Menu()
{
  bool finished = false;
  u32 FPS = 40;
	
  DrawMenu ();  // draw some graphics

  PLMInput *in = PLMInput::GetInstance ();
  if (! in)
    { cerr << "Could not initialise main event manager.\n"; exit(1); }
  in->SetEventTypes (PLMInput::EM_QUIT | PLMInput::EM_KEYDOWN);
  in->SetKeyRepeat();
  in->Flush();

  PLMEvent ev;
  PLMTimer timer;
  do
    {
      timer.StoreTicks ();
			
      if (in->GetNextEvent (&ev))
        switch (ev.type)
          {
          case PLMEV_QUIT: finished = true; break;
          case PLMEV_KEYDOWN:
            switch (ev.key.key.sym)
              {
              case PLMK_ESCAPE: finished = true; break;
        // suppose we have a MovePlayer (dx, dy) method
              case PLMK_UP:    MovePlayer ( 0,  1); break;
              case PLMK_DOWN:  MovePlayer ( 0, -1); break;
              case PLMK_LEFT:  MovePlayer (-1,  0); break;
              case PLMK_RIGHT: MovePlayer ( 1,  0); break;
        // and a FirePlayer () method to kill ennemies
              case PLMK_SPACE:
              case PLMK_RETURN:
              case PLMK_KP_ENTER: FirePlayer (); break;
              default : break;
              }
            break;
          default : break;
          }
					
      // here you update your graphics and refresh the screen
      UpdateScreen ();
      
      u32 diff = timer.GetDiffNow ();
      if (diff < FPS)
        timer.Wait (FPS - diff);
    }
  while (! finished);
}

Copyright 2001-2004 PLMSoft All rights reserved. (last mod.: 15 Oct 2004)