home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DOS/V Power Report 1997 March
/
VPR9703A.ISO
/
VPR_DATA
/
DOGA
/
SOURCES
/
POLYEDIT.LZH
/
MODEL
/
OBJLIB.C
< prev
next >
Wrap
C/C++ Source or Header
|
1996-02-23
|
6KB
|
256 lines
/*
* オブジェクトデータ制御
*
* Copyright T.Kobayashi 1994.8.13
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "matrix.h"
#include "vector.h"
#include "matclass.h"
#include "strclass.h"
#include "ml.h"
#include "poly.h"
#include "menu.h"
static int StringClassID ;
static int FuncObjCurrent( int, int, DataStruct* );
static int FuncObjects( int, int, DataStruct* );
static int FuncObjAppend( int, int, DataStruct* );
static int FuncObjSearch( int, int, DataStruct* );
static int FuncObjChange( int, int, DataStruct* );
static int FuncObjName( int, int, DataStruct* );
static int FuncObjFile( int, int, DataStruct* );
static int FuncObjEdit( int, int, DataStruct* );
static int FuncObjDelete( int, int, DataStruct* );
static int FuncObjPolygons( int, int, DataStruct* );
void ObjLibInit()
{
StringClassID = ClassName( "String" );
NewFunction( 0, "ObjCurrent", FuncObjCurrent );
NewFunction( 0, "Objects", FuncObjects );
NewFunction( StringClassID, "ObjAppend", FuncObjAppend );
NewFunction( StringClassID, "ObjSearch", FuncObjSearch );
NewFunction( 0, "ObjChange", FuncObjChange );
NewFunction( 0, "ObjName", FuncObjName );
NewFunction( 0, "ObjFile", FuncObjFile );
NewFunction( 0, "ObjEdit", FuncObjEdit );
NewFunction( 0, "ObjDelete", FuncObjDelete );
NewFunction( 0, "ObjPolygons", FuncObjPolygons );
}
/* カレントオブジェクトを得る */
static int FuncObjCurrent( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
if (args == 0) {
StackPushInt( ObjCurrent );
} else {
int oldcurrent;
ArgCheck( "ObjCurrent", args, buf, TYPE_INT, TYPE_NOASN );
oldcurrent = ObjCurrent;
if (buf[0].id.i >= 0 && buf[0].id.i <= ObjLast) {
ObjCurrent = buf[0].id.i;
if (oldcurrent != ObjCurrent) {
DrawObjSelect();
}
StackPushInt( oldcurrent );
} else {
StackPushInt( -1 );
}
}
return RETURN_RETURN ;
}
/* オブジェクト数を得る */
static int FuncObjects( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
StackPushInt( ObjLast + 1 );
return RETURN_RETURN ;
}
/* オブジェクトの追加 */
static int FuncObjAppend( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
int n ;
ArgCheck( "ObjAppend", args, buf, TYPE_OBJECT, TYPE_OBJECT, TYPE_NOASN );
n = ObjAppend( ((StringClass*)buf[0].od.ptr)->str );
strcpy( ObjData[n].fname, ((StringClass*)buf[1].od.ptr)->str );
StackPushInt( n );
return RETURN_RETURN ;
}
/* 検索 */
static int FuncObjSearch( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
StackPushInt( ObjSearch( ((StringClass*)buf[0].od.ptr)->str ) );
return RETURN_RETURN ;
}
/* セレクトされているオブジェクトを変更する */
static int FuncObjChange( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
ArgCheck( "ObjChange", args, buf, TYPE_INT, TYPE_NOASN );
ObjChange( buf[0].id.i );
return RETURN_VOID ;
}
/* オブジェクト名を得る */
static int FuncObjName( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
int n ;
char *name ;
if ( args == 1 )
{
ArgCheck( "ObjFile", args, buf, TYPE_INT, TYPE_NOASN );
n = buf[0].id.i ;
}
else
{
ArgCheck( "ObjFile", args, buf, TYPE_INT, TYPE_OBJECT, TYPE_NOASN );
n = buf[0].id.i ;
if ( ObjectCheck( &buf[1], StringClassID ) == FALSE )
ExecError( "%d番目の引数の型不正です(ObjName)", 2 );
name = ((StringClass*)buf[1].od.ptr)->str ;
if ( strcmp( name, "" ) == 0 )
ObjData[n].flag = FALSE ;
strcpy( ObjData[n].name, name );
}
buf = StackAlloc( 1 );
if ( ObjData[n].flag )
StringToObject( buf, ObjData[n].name );
else
StringToObject( buf, "" );
return RETURN_RETURN ;
}
/* オブジェクトのファイル名を得る */
static int FuncObjFile( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
int n ;
if ( args == 1 )
{
ArgCheck( "ObjFile", args, buf, TYPE_INT, TYPE_NOASN );
n = buf[0].id.i ;
}
else
{
ArgCheck( "ObjFile", args, buf, TYPE_INT, TYPE_OBJECT, TYPE_NOASN );
n = buf[0].id.i ;
if ( ObjectCheck( &buf[1], StringClassID ) == FALSE )
ExecError( "%d番目の引数の型不正です(ObjFile)", 2 );
strcpy( ObjData[n].fname, ((StringClass*)buf[1].od.ptr)->str );
}
buf = StackAlloc( 1 );
StringToObject( buf, ObjData[n].fname );
return RETURN_RETURN ;
}
/* エディットフラグを得る */
static int FuncObjEdit( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
int n ;
if ( args == 1 )
{
ArgCheck( "ObjEdit", args, buf, TYPE_INT, TYPE_NOASN );
n = buf[0].id.i ;
}
else
{
ArgCheck( "ObjEdit", args, buf, TYPE_INT, TYPE_INT|TYPE_BOOLEAN, TYPE_NOASN );
n = buf[0].id.i ;
ObjData[n].edit = buf[1].id.i ;
}
StackPushInt( ObjData[n].edit );
return RETURN_RETURN ;
}
/* オブジェクトを削除する */
static int FuncObjDelete( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
ArgCheck( "ObjDelete", args, buf, TYPE_INT, TYPE_NOASN );
if (buf[0].id.i >= 0 && buf[0].id.i <= ObjLast) {
StackPushBoolean( ObjDelete( buf[0].id.i ) );
} else {
StackPushBoolean( FALSE );
}
return RETURN_RETURN ;
}
/* ポリゴン数を数える */
static int FuncObjPolygons( ident, args, buf )
int ident ;
int args ;
DataStruct *buf ;
{
int n = 0;
Polygon *poly ;
poly = PolyTop();
if ( args >= 1 )
{
int objno;
ArgCheck( "ObjPolygons", args, buf, TYPE_INT, TYPE_NOASN );
objno = buf[0].id.i;
while( poly != NULL )
{
if (poly->obj == objno) {
n++;
}
poly = PolyNext( poly );
}
} else {
while( poly != NULL )
{
n++;
poly = PolyNext( poly );
}
}
StackPushInt( n );
return RETURN_RETURN ;
}