/*
   CMSC 427 - Term Project Candidate
   ---------------------------------

   Beth Weinstein - bweinste@wam.umd.edu
   Ben Stewart - stewartb@wam.umd.edu
   Nawfel Tricha - Topaz@endorproductions.com

   Minimal OpenGL project using Microsoft Visual C++.
   This project is a premilinary candidate for the term 
   project required by CMSC 427.

   ABSTRACT:
      In this project, we will develop several fast 
      rendering and collision routines which would 
      require C/C++ speed and accuracy and then 
      implement a VisualJ++ interface.

   MODULE:
      Skin library module.
*/

#include "Global.h"

/* 
   NT: 
   Spawn new skin (next free slot in array) and return pointer to it:
*/

int SkinSpawn(char *skin_name, skin_t *skin)
{
   int x = 0;
   while (g_skins[x] && x < G_MAX_SKINS)
      x++;
   if (x == G_MAX_SKINS)
      {
      EngineError("Maximum number of skins [%i] reached. Engine resources are low. Shutting down.\n", G_MAX_SKINS);
      return 0;
      }
   g_skins[x] = new skin_list_t;
   memset (g_skins[x], 0, sizeof(*g_skins[x]));
   if (x >= eng.num_skins)
      eng.num_skins++;
   g_skins[x]->skin_name = new char[strlen(skin_name) + 1];
   strcpy (g_skins[x]->skin_name, skin_name);
   g_skins[x]->skin = skin;
   return x;
}

/* 
   NT: 
   Return index of skin, else return NOT_FOUND:
*/
int SkinIndex(char *skin_name)
{
   int x = 0;
   if (!skin_name)
      return NOT_FOUND;
   for (; x < eng.num_skins; x++)
      if (g_skins[x])
         if (!strcmpi(g_skins[x]->skin_name, skin_name))
            return x;
   return NOT_FOUND;
}