/* orxonox - the future of 3D-vertical-scrollers Copyright (C) 2004 orx 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, or (at your option) any later version. ### File Specific: main-programmer: Patrick Boenzli */ #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_IMPORTER #include "md3_animation_cfg.h" #include "tokenizer.h" #include "debug.h" using namespace std; namespace md3 { /** * create an empty MD3AnimationCfg object */ MD3AnimationCfg::MD3AnimationCfg() { } /** * create a new MD3 Anumation object and initialize it with the data on the given line * @param line: the line to read from */ MD3AnimationCfg::MD3AnimationCfg(std::string filename) { this->dataStream.open(filename.c_str()); if( !this->dataStream) { PRINTF(1)("Error: file could not be opened: %s\n", filename.c_str()); } } /** * deconstructor */ MD3AnimationCfg::~MD3AnimationCfg() {} /** * loads the configuration file */ void MD3AnimationCfg::loadConfig() { // BufferedReader bin=new BufferedReader(new InputStreamReader(in)); int i = 0; //!< last read animation, animation order is hard coded! int torsoOffset = -1; //!< torso offset int firstTorsoFrame = -1; //!< first of the TORSO animation frames bool inHeader = true; //!< are we still in the header of the .cfg file? char buffer[1024]; //!< buffer to write stuff into // parse file this->dataStream.getline(buffer, 1024, '\n'); std::string line(buffer); PRINTF(0)("line = %s\n", line.c_str()); while( !this->dataStream.eof()) { //ignore empty lines and comments if( line != "" && line.find("//") != 0) { // find the sex section if( inHeader && line.find("sex") == 0) { //parse line: sex [m | f | ...] // StringTokenizer st=new StringTokenizer(line, " \t\n\r\f/"); std::vector tokens; Tokenizer::tokenize(line, tokens, " \t\n\r\f/"); while( !tokens.empty()) { PRINTF(0)("tokens: %s\n", tokens.back()); tokens.pop_back(); } return; /* st.nextToken(); //throw away first token String sexStr=st.nextToken(); if (sexStr.length()!=1) //non-fatal error, don't thow exception newAnimCfg.sex='?'; else newAnimCfg.sex=sexStr.charAt(0); } else if (IN_HEADER && line.startsWith("headoffset")) { //parse line: headoffset X Y Z StringTokenizer st=new StringTokenizer(line, " \t\n\r\f/"); st.nextToken(); //throw away first token newAnimCfg.headOffset= new md3.util.Vec3(new Float(st.nextToken()).floatValue(), new Float(st.nextToken()).floatValue(), new Float(st.nextToken()).floatValue()); } else if (IN_HEADER && line.startsWith("footsteps")) { //parse line: footsteps [normal | mech | ...] StringTokenizer st=new StringTokenizer(line, " \t\n\r\f/"); st.nextToken(); //throw away first token newAnimCfg.footsteps=st.nextToken().trim(); if (!(newAnimCfg.footsteps.toLowerCase().equals("default") || newAnimCfg.footsteps.toLowerCase().equals("normal") || newAnimCfg.footsteps.toLowerCase().equals("boot") || newAnimCfg.footsteps.toLowerCase().equals("flesh") || newAnimCfg.footsteps.toLowerCase().equals("mech") || newAnimCfg.footsteps.toLowerCase().equals("energy") )) //don't throw an exception, non-fatal error newAnimCfg.footsteps="illegal footsteps value (" + newAnimCfg.footsteps + ")"; } else { //assume it's an animation line IN_HEADER=false; //no longer in header MD3Animation animation=MD3ModelFactory.getFactory().makeMD3Animation(line); animation.name=animationNames[i]; animation.type=animationTypes[i++]; //workaround for strange numbering in animation.cfg: skip TORSO frames //for LEGS animation lines... if (animation.type==AnimationType.LEGS) { //when first LEGS animation is found, calc # of TORSO frames if (TORSO_OFFSET==-1) TORSO_OFFSET=animation.first-firstTORSOFrame; animation.first-=TORSO_OFFSET; animation.offset=TORSO_OFFSET; } else if (animation.type==AnimationType.TORSO) if (firstTORSOFrame==-1) firstTORSOFrame=animation.first; newAnimCfg.putAnimation(animation); } } line=bin.readLine(); } catch (Exception e) { throw new IOException(e.getMessage()); }*/ } } } } /** *

Look up the animation data for the animation with the specified name. * * @param name Name of the animation. * @return The animation data associated with the name or null if no data was found. */ MD3Animation* getAnimation(std::string name) { // return (MD3Animation)animations.get(name); } } #if 0 /** *

Create an empty animation data resource. Use this when creating and * managing your own animations. */ protected AnimationCfg() { animations=new TreeMap(); } /** *

Constructor that loads an animation.cfg file into the internal * data stuctures. The read information can later be consulted using the * animationNames() and getAnimation() methods. * * @param file The file to open. */ protected AnimationCfg(String file) throws IOException { this(); InputStream fin=new FileInputStream(file); CFGIO.loadAnimationCfg(this, fin); fin.close(); } /** *

Constructor that loads animation.cfg data coming from the specified * input stream into the internal data stuctures. The read information can later * be consulted using the animationNames() and getAnimation() methods. * * @param in The stream to read data from. */ protected AnimationCfg(InputStream in) throws IOException { this(); CFGIO.loadAnimationCfg(this, in); } /** *

Return an Iterator listing the names of all known animations. */ public Iterator animationNames() { return animations.keySet().iterator(); } /** *

Look up the animation data for the animation with the specified name. * * @param name Name of the animation. * @return The animation data associated with the name or null if no data was found. */ public MD3Animation getAnimation(String name) { return (MD3Animation)animations.get(name); } /** *

Add the specified animation to the list of known animations. */ public void putAnimation(MD3Animation anim) { animations.put(anim.name, anim); } #endif