⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shapepalette.cpp

📁 S.C.O.U.R.G.E.是一款类似Rogue的游戏
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/***************************************************************************                          shapepalette.cpp  -  description                             -------------------    begin                : Sat Jun 14 2003    copyright            : (C) 2003 by Gabor Torok    email                : cctorok@yahoo.com ***************************************************************************//*************************************************************************** *                                                                         * *   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.                                   * *                                                                         * ***************************************************************************/#include "shapepalette.h"ShapePalette *ShapePalette::instance = NULL;ShapePalette::ShapePalette(){  texture_count = 0;  textureGroupCount = 0;  // load textures  gui_texture = loadGLTextures("/gui.bmp");  gui_wood_texture = loadGLTextures("/gui-wood.bmp");  paper_doll_texture = loadGLTextures("/paperdoll.bmp");  cloud = loadGLTextures("/cloud.bmp");  candle = loadGLTextures("/candle.bmp");  torchback = loadGLTextures("/torchback.bmp");    // load the texture info  char errMessage[500];  char s[200];  sprintf(s, "%s/world/shapes.txt", rootDir);  FILE *fp = fopen(s, "r");  if(!fp) {            sprintf(errMessage, "Unable to find the file: %s!", s);    cerr << errMessage << endl;    exit(1);  }  //int sum = 0;  char path[300];  char line[255];  int n = fgetc(fp);  while(n != EOF) {    if(n == 'T') {      // skip ':'      fgetc(fp);      n = Constants::readLine(line, fp);      // texture declaration      strcpy(textures[texture_count].filename, line);      sprintf(path, "/%s", textures[texture_count].filename);      // load the texture      textures[texture_count].id = loadGLTextures(path);      texture_count++;      /*    } else if(n == 'S') {      fgetc(fp);      n = Constants::readLine(line, fp);      // load md2 skin       GLuint skin;      sprintf(path, "%s", line);      cerr << "Loading md2 skin: " << line << endl;      CreateTexture(&skin, path, 0);      string name = line;      creature_skins[name] = skin;      */    } else if(n == 'G') {      // skip ':'      fgetc(fp);      n = Constants::readLine(line, fp);      // parse native texture group      int c = 0;      char *token = strtok(line, ",");      while(token && c < 3) {        // store the index only, resolve after all textures loaded        textureGroup[textureGroupCount][c++] = atoi(token);        token = strtok(NULL, ",");      }      // resolve the indexes      if(c == 3) {        textureGroupCount++;      }    } else if(n == 'D') {      fgetc(fp);      n = Constants::readLine(line, fp);      // read description lines      int count = atoi(line);      if(count > 0) {        vector<string> *list = new vector<string>();        descriptions.push_back(list);        for(int i = 0; i < count; i++) {          n = Constants::readLine(line, fp);          string s = line + 1;          list->push_back(s);        }        cerr << "added " << count << " lines of description. # of description groups=" << descriptions.size() << endl;      }    } else if(n == 'N') {      fgetc(fp);      n = Constants::readLine(line, fp);      // texture group      ShapeValues *sv = new ShapeValues();      sv->textureGroupIndex = atoi(line);      sv->xrot = sv->yrot = sv->zrot = 0.0f;      // dimensions      n = Constants::readLine(line, fp);      sv->width = atoi(strtok(line + 1, ","));      sv->depth = atoi(strtok(NULL, ","));      sv->height = atoi(strtok(NULL, ","));      // name      n = Constants::readLine(line, fp);      strcpy(sv->name, line + 1);      // description      n = Constants::readLine(line, fp);      //	  cerr << "*** shape description group (string): " << line << endl;      sv->descriptionIndex = atoi(line + 1);      // color      n = Constants::readLine(line, fp);      sv->color = strtoul(line + 1, NULL, 16);      // extra for torches:      sv->torch = -1;      sv->m3ds_name[0] = '\0';      sv->teleporter = 0;      if(n == 'T') {        n = Constants::readLine(line, fp);        sv->torch = atoi(line + 1);      } else if(n == '3') {        n = Constants::readLine(line, fp);        strcpy(sv->m3ds_name, line + 1);        n = Constants::readLine(line, fp);        sv->m3ds_scale = strtod(line + 1, NULL);      } else if(n == 'L') {        n = Constants::readLine(line, fp);        sv->teleporter = 1;      }             // icon rotation      if(n == 'R') {        n = Constants::readLine(line, fp);        sv->xrot = atof(strtok(line + 1, ","));        sv->yrot = atof(strtok(NULL, ","));        sv->zrot = atof(strtok(NULL, ","));      }      // store it for now      shapeValueVector.push_back(sv);    } else if(n == '2') {         Md2ModelInfo *info = new Md2ModelInfo();      // name      n = Constants::readLine(line, fp);      strcpy(info->name, line + 1);      // file      n = Constants::readLine(line, fp);      strcpy(info->filename, line + 1);      n = Constants::readLine(line, fp);      // scale      info->scale = strtod(strtok(line + 1, ","), NULL);      // dimensions      info->width = atoi(strtok(NULL, ","));      info->depth = atoi(strtok(NULL, ","));      info->height = atoi(strtok(NULL, ","));      // store the md2 model and info      sprintf(path, "%s%s", rootDir, info->filename);      cerr << "Loading md2 model: " << path << " scale: " << info->scale <<       " dim: " << info->width << ", " << info->depth << "," << info->height << endl;      info->model = LoadMd2Model(path);      // store it      string s = info->name;      creature_models[s] = info;      // create a block shape for this model      // (used to measure space w/o creating a creature shape)      creature_block_shapes[s] =       new GLShape(textureGroup[14],                  info->width, info->depth, info->height,                  strdup(info->name),                  0xffffffff, 0, 0);    } else if(n == 'P') {      fgetc(fp);      n = Constants::readLine(line, fp);      int index = atoi(strtok(line, ","));      cerr << "options for shape, index=" << index << " size=" << shapeValueVector.size() << endl;      ShapeValues *sv = shapeValueVector[index];      sv->skipSide = atoi(strtok(NULL, ","));      sv->stencil = atoi(strtok(NULL, ","));      sv->blocksLight = atoi(strtok(NULL, ","));    } else {      // skip this line      n = Constants::readLine(line, fp);    }  }  fclose(fp);  // resolve texture groups  for(int i = 0; i < textureGroupCount; i++) {    for(int c = 0; c < 3; c++) {      textureGroup[i][c] = textures[textureGroup[i][c]].id;    }  }  // create shapes  GLuint dl = 0;  for(int i = 0; i < (int)shapeValueVector.size(); i++) {    cerr << "Creating shape i=" << i << endl;    ShapeValues *sv = shapeValueVector[i];    cerr << "\t" <<    " width=" << sv->width <<     " depth=" << sv->depth <<     " height=" << sv->height << endl;    if(sv->teleporter) {      shapes[(i + 1)] =      new GLTeleporter(textureGroup[sv->textureGroupIndex], textures[9].id,                       sv->width, sv->depth, sv->height,                       strdup(sv->name),                        sv->descriptionIndex,                       sv->color,                       dl, (i + 1));    } else if(strlen(sv->m3ds_name)) {      shapes[(i + 1)] =      new C3DSShape(sv->m3ds_name, sv->m3ds_scale, this,                    textureGroup[sv->textureGroupIndex],                     sv->width, sv->depth, sv->height,                    strdup(sv->name),                     sv->descriptionIndex,                    sv->color,                    dl,(i + 1));    } else if(sv->torch > -1) {      if(sv->torch == 5) {        shapes[(i + 1)] =        new GLTorch(textureGroup[sv->textureGroupIndex], textures[9].id,                    sv->width, sv->depth, sv->height,                    strdup(sv->name),                    sv->descriptionIndex,                    sv->color,                    dl, (i + 1));      } else {        shapes[(i + 1)] =        new GLTorch(textureGroup[sv->textureGroupIndex], textures[9].id,                    sv->width, sv->depth, sv->height,                    strdup(sv->name),                    sv->descriptionIndex,                    sv->color,                    dl, (i + 1),                     torchback, sv->torch);      }    } else {      shapes[(i + 1)] =      new GLShape(textureGroup[sv->textureGroupIndex],                  sv->width, sv->depth, sv->height,                  strdup(sv->name),                  sv->descriptionIndex,                  sv->color,                  dl, (i + 1));    }    shapes[(i + 1)]->setSkipSide(sv->skipSide);    shapes[(i + 1)]->setStencil(sv->stencil == 1);    shapes[(i + 1)]->setLightBlocking(sv->blocksLight == 1);    shapes[(i + 1)]->setIconRotation(sv->xrot, sv->yrot, sv->zrot);    string s = sv->name;    shapeMap[s] = shapes[(i + 1)];  }  // remember the number of shapes

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -