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

📄 cvwrite.cpp

📁 Windows上的MUD客户端程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*----------------------------------------------------------------------------
                        _                              _ _       
        /\             | |                            | (_)      
       /  \   _ __   __| |_ __ ___  _ __ ___   ___  __| |_  __ _ 
      / /\ \ | '_ \ / _` | '__/ _ \| '_ ` _ \ / _ \/ _` | |/ _` |
     / ____ \| | | | (_| | | | (_) | | | | | |  __/ (_| | | (_| |
    /_/    \_\_| |_|\__,_|_|  \___/|_| |_| |_|\___|\__,_|_|\__,_|

    The contents of this file are subject to the Andromedia Public
	License Version 1.0 (the "License"); you may not use this file
	except in compliance with the License. You may obtain a copy of
	the License at http://www.andromedia.com/APL/

    Software distributed under the License is distributed on an
	"AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
	implied. See the License for the specific language governing
	rights and limitations under the License.

    The Original Code is Pueblo client code, released November 4, 1998.

    The Initial Developer of the Original Code is Andromedia Incorporated.
	Portions created by Andromedia are Copyright (C) 1998 Andromedia
	Incorporated.  All Rights Reserved.

	Andromedia Incorporated                         415.365.6700
	818 Mission Street - 2nd Floor                  415.365.6701 fax
	San Francisco, CA 94103

    Contributor(s):
	--------------------------------------------------------------------------
	   Chaco team:  Dan Greening, Glenn Crocker, Jim Doubek,
	                Coyote Lussier, Pritham Shetty.

					Wrote and designed original codebase.

------------------------------------------------------------------------------

	Implementation for the traversal of a VRML QV tree into Intel 3DR.

----------------------------------------------------------------------------*/

// $Header: /home/cvs/chaco/modules/client/msw/ChGraphx/CvWrite.cpp,v 2.13 1996/08/22 22:45:19 jimd Exp $
/*
 Copyright 1995 by Tenet Networks, Inc.
 Carlsbad, California, USA. All rights reserved.

 Redistribution and use of this software, with or without modification, is
 permitted provided that the following conditions are met:

 1. Redistributions of this software must retain the above copyright
    notice, this list of conditions and the following disclaimer.

  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO
  EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "grheader.h"
//

#if defined( CH_ARCH_16 )
#include <QvElemnt.h>   
#else
#include <QvElement.h>   
#endif
#include <QvNodes.h>
#include <QvState.h>
#if defined( CH_ARCH_16 )
#include <UnknNode.h>   
#else
#include <QvUnknownNode.h>
#endif

#include <iostream.h>

// int i is used in some macros, but not needed for all
#pragma warning(disable:4101)

//////////////////////////////////////////////////////////////////////////////
//
// write code for all nodes. The default method (in QvNode) does
// nothing. Because write() is defined in the header for ALL node
// classes, each one has an implementation here.
//
//////////////////////////////////////////////////////////////////////////////

// For debugging
static int indent = 0;
static void
announce(const char *className, ostream &strm)
{
    for (int i = 0; i < indent; i++)
	strm << "\t";
    strm <<  className << " {\n";
}
#define ANNOUNCE(className) announce(QV__QUOTE(className), strm)

#define DEFAULT_write(className)					      \
void									      \
className::write(ostream &strm)						      \
{									      \
    ANNOUNCE(className);						      \
}

static void end_brack(ostream &strm )
	{
	for (int i = 0; i < indent; i++)
		strm << "\t";
	strm << "}\n";
	}
 
#define END_BRACK  end_brack( strm );

void tab_in(int in, ostream &strm)
{
	for (int i = 0; i < in; i++) strm << "\t";
}

void print_bitmask(QvSFEnum enm, ostream &strm)
{
	int out_vals_written = 0, all_val;
	QvName all("ALL");

	enm.findEnumValue(all, all_val);

	if (enm.value == all_val) 
		strm << "\tALL\n";
	else  {
		strm << "\t(";
		for (int i = 0; i < enm.numEnums-1; i++) {
	
			if (enm.enumValues[i] & enm.value) {
				if (out_vals_written++) strm << " | ";
				strm << (char *)enm.enumNames[i].getString( );
				}
			}
		strm << ")\n";
		}
}

void print_enum(QvSFEnum enm, ostream &strm)
{
	if (enm.isDefault( )) 
		strm << "DEFAULT\n";
	else  {
		for (int i = 0; i < enm.numEnums; i++) 
			if (enm.enumValues[i] == enm.value) {
				strm << (char *)enm.enumNames[i].getString( ) << "\n";
				break;
				}
		}
}
 
#define MFIELD(fieldNm, grouping)						\
	if (!(fieldNm.isDefault( ))) {						\
		tab_in( indent, strm );								\
 		strm << QV__QUOTE(fieldNm) << "\t[";				\
		for (i = 0; i < fieldNm.num * grouping; i++) {	\
			if (i && (grouping != 1) && (i % grouping == 0)) strm << ",";	\
			strm << " " << fieldNm.values[i];			\
 			}									 		\
	 	strm << "]\n";									\
	 	}

	  
#define BITMASK(fieldNm)								\
 	if (!(fieldNm.isDefault( ))) {						\
		if (fieldNm.numEnums) {							\
			tab_in( indent, strm  );							\
			strm << QV__QUOTE(fieldNm);					\
			print_bitmask(fieldNm, strm);						\
			}											\
		}
 	
  
#define FIXEDARRAYFIELD(fieldNm, grouping)				\
	if (!(fieldNm.isDefault( ))) {						\
		tab_in( indent, strm  );								\
		strm << QV__QUOTE(fieldNm) << "\t";				\
		for (i = 0; i < grouping; i++) {				\
			strm << fieldNm.value[i] << " ";			\
			}									 		\
	 	strm << "\n";									\
		}

#define FIELD(fieldNm) 									\
	if (!(fieldNm.isDefault( ))) {						\
		tab_in( indent, strm  );								\
		strm << QV__QUOTE(fieldNm) << "\t" << fieldNm.value << "\n"; \
		}	 

#define STRINGFIELD(fieldNm) 							\
	if (!(fieldNm.isDefault( ))) {						\
		tab_in( indent, strm  );								\
		strm << QV__QUOTE(fieldNm) << "\t" 				\
			<< "\""  << fieldNm.value.getString( ) << "\"\n"; \
		}
		 

#define MSTRINGFIELD(fieldNm, grouping)						\
	if (!(fieldNm.isDefault( ))) {						\
		tab_in( indent, strm );								\
 		strm << QV__QUOTE(fieldNm) << "\t[";				\
		for (i = 0; i < fieldNm.num * grouping; i++) {	\
			if (i && (grouping != 1) && (i % grouping == 0)) strm << ",";	\
			strm << " " << "\""  << fieldNm.values[i].getString( ) << "\"\n";			\
 			}									 		\
	 	strm << "]\n";									\
	 	}

	  

#define ENUMFIELD(fieldNm)								\
	if (!(fieldNm.isDefault( ))) {						\
		if (fieldNm.numEnums) {							\
			tab_in( indent, strm );							\
			strm << QV__QUOTE(fieldNm) << "\t";			\
			print_enum(fieldNm, strm);						\
			}											\
		}
	
 
#define ROTATIONFIELD(fieldNm)							\
	if (!(fieldNm.isDefault( ))) {						\
		tab_in( indent, strm  );								\
		strm << QV__QUOTE(fieldNm) << "\t";				\
		for (i = 0; i < 3 ; i++) 						\
			strm << fieldNm.axis[i] << " ";				\
		strm <<	fieldNm.angle << "\n";					\
		} 

#define MATRIXFIELD(fieldNm)							\
	if (!(fieldNm.isDefault( ))) {						\
		tab_in( indent, strm  );								\
		strm << QV__QUOTE(fieldNm) << "\t";				\
		for (i = 0; i < 4; i++)							\
			for (int j = 0; j < 4; j++)					\
				strm << fieldNm.value[i][j] << " ";		\
		strm << "\n";									\
		}

#define BOOLFIELD(fieldNm) 								\
	if (!(fieldNm.isDefault( ))) {						\
		tab_in( indent, strm  );								\
		strm << QV__QUOTE(fieldNm) << "\t" <<			\
			(fieldNm.value ? "TRUE" : "FALSE") << "\n"; \
		}
		
//////////////////////////////////////////////////////////////////////////////
//
// Groups.
//
//////////////////////////////////////////////////////////////////////////////

void
QvGroup::write(ostream &strm)
{
    ANNOUNCE(Group);
    indent++;
    for (int i = 0; i < getNumChildren(); i++)
	getChild(i)->write(strm);
	END_BRACK;
    indent--;
}

void
QvLOD::write(ostream &strm)
{  	
	int i;
    ANNOUNCE(QvLOD);
    indent++;

	MFIELD(range,1)
	FIXEDARRAYFIELD(center,3);

    for (i = 0; i < getNumChildren(); i++)
	getChild(i)->write(strm);

	END_BRACK;
    indent--;
}

void
QvSeparator::write(ostream &strm)
{
    ANNOUNCE(Separator);
    indent++;
	
	ENUMFIELD(renderCulling)

    for (int i = 0; i < getNumChildren(); i++)
	getChild(i)->write(strm);
	END_BRACK;
    indent--;
}

void
QvSwitch::write(ostream &strm)
{
    ANNOUNCE(Switch);
    indent++;

	FIELD(whichChild)

    int which = whichChild.value;

    if (which == QV_SWITCH_NONE)
	;

    else if (which == QV_SWITCH_ALL)
	for (int i = 0; i < getNumChildren(); i++)
	    getChild(i)->write(strm);

    else
	if (which < getNumChildren())
	    getChild(which)->write(strm);

	END_BRACK;
    indent--;
}

⌨️ 快捷键说明

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