/* * GRacer * * Copyright (C) 1999 Takashi Matsuda * * 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. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ #include #include #include #include "tcldefs.h" #include "glutgame.h" #include #include #include #include #include "lap.h" #include "glbind.h" #include #include "sound.h" #ifndef MAX #define MAX(a,b) (((a) > (b))? (a) : (b)) #endif #define LFONT_SIZE 0.10 #define SFONT_SIZE 0.08 #define LFONT_HEIGHT (LFONT_SIZE + 0.02) #define SFONT_HEIGHT (SFONT_SIZE + 0.01) #define LFONT_WIDTH (LFONT_SIZE * 0.8) #define SFONT_WIDTH (SFONT_SIZE * 0.8) #define RPM_ANGLE 215.0 #define MIN_INTERVAL 0.02 typedef struct GrViewerQueryInfo { char *name; int (*func) (GrViewer *game, GrViewerEntryInfo *gentry, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]); } GrViewerQueryInfo; static void glut_game_overhead_reshape (GlutObject obj, int width, int height); static void glut_game_draw_panel (GlutObject obj); Tcl_Obj *obj_time; Tcl_Obj *obj_lap; Tcl_Obj *obj_speed; Tcl_Obj *obj_rpm; Tcl_Obj *obj_entry; Tcl_HashTable query_hash; GrViewerOption gr_viewer_get_options (GrViewer *viewer) { return viewer->options; } void gr_viewer_set_options (GrViewer *viewer, GrViewerOption options) { const GrObjectDrawOption linear_mask = GR_OBJECT_MAG_LINEAR | GR_OBJECT_MIN_LINEAR | GR_OBJECT_MIP_LINEAR; viewer->options = options; viewer->use_texture = (options & GR_VIEWER_USE_TEXTURE) != 0; viewer->use_mipmap = (options & GR_VIEWER_USE_MIPMAP) != 0; viewer->use_linear = (options & GR_VIEWER_USE_LINEAR) != 0; viewer->use_shading = (options & GR_VIEWER_USE_SHADING) != 0; viewer->show_sky = (options & GR_VIEWER_SHOW_SKY) != 0; viewer->show_decr = (options & GR_VIEWER_SHOW_DECR) != 0; viewer->use_audio = (options & GR_VIEWER_USE_AUDIO) != 0; viewer->draw_option = GR_OBJECT_ALL; viewer->draw_option &= (options & GR_VIEWER_USE_TEXTURE)? ~0 : ~GR_OBJECT_TEXTURE; viewer->draw_option &= (options & GR_VIEWER_USE_MIPMAP)? ~0 : ~GR_OBJECT_MIPMAP; viewer->draw_option &= (options & GR_VIEWER_USE_LINEAR)? ~0 : ~linear_mask; viewer->draw_option &= (options & GR_VIEWER_USE_SHADING)? ~0 : ~GR_OBJECT_SMOOTH; } static int Tcl_GrViewerConfigure (Tcl_Interp *interp, GlutObject obj, int objc, Tcl_Obj *CONST objv[]) { GrViewer *game = obj; Tcl_Obj *res_obj; char *str; int i; int res; GrViewerOption option; for (i=0; iinterp || !trigger->script) return; interp = trigger->interp; script = trigger->script; obj = Tcl_NewIntObj (vehicle->entry_no); Tcl_ObjSetVar2 (interp, obj_entry, NULL, obj, 0); Tcl_IncrRefCount (script); if (Tcl_EvalObj (interp, script) == TCL_ERROR) { fputs (Tcl_GetVar (interp, "errorInfo", TCL_GLOBAL_ONLY), stderr); } Tcl_DecrRefCount (script); } static void gr_tcltrigger_destroy (GrTclTrigger *trigger) { if (trigger->script) { Tcl_DecrRefCount (trigger->script); } free (trigger); } static int tcl_GrViewerTrigger (GrViewer *game, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) { int i, length; GrTclTrigger trigger, *ptr; char *str; Tcl_HashEntry *entry; int key; int _new; if (objc < 3) { goto ERROR; } memset (&trigger, 0, sizeof (trigger)); trigger.key = -1; for (i=0; i 0) { Tcl_IncrRefCount (objv[i]); trigger.interp = interp; trigger.script = objv[i]; } else { goto ERROR; } } else if (!strcmp (str, "-remove") && i+1 == objc -1) { i ++; TCL_CHECK(Tcl_GetIntFromObj (interp, objv[i], &key), ERROR); if (trigger.key <= 0) { Tcl_AppendResult (interp, ": trigger key must greater than zero.", NULL); return TCL_ERROR; } entry = Tcl_FindHashEntry (&game->trigger_hash, (ClientData) key); if (!entry) goto NOT_DEFINED_ERROR; ptr = Tcl_GetHashValue (entry); Tcl_DeleteHashEntry (entry); gr_DECREF (ptr); gr_world_remove_trigger (game->world, (GrTrigger *) ptr); return TCL_OK; } else { goto ERROR; } } ptr = gr_new0 (GrTclTrigger, 1); if (!ptr) { Tcl_AppendResult (interp, ": memory allocation error.", NULL); return TCL_ERROR; } gr_FREE_FUNC (ptr, gr_tcltrigger_destroy); *ptr = trigger; ptr->core.callback = (GrTriggerFunc) gr_tcltrigger_callback; gr_world_add_trigger (game->world, (GrTrigger *) ptr); game->trigger_key ++; entry = Tcl_CreateHashEntry (&game->trigger_hash, (char *) game->trigger_key, &_new); Tcl_SetHashValue (entry, ptr); gr_INCREF (ptr); Tcl_SetObjResult (interp, Tcl_NewIntObj (game->trigger_key)); return TCL_OK; ERROR: Tcl_AppendResult (interp, ": wrong args. should be -cline , -a_to_a, -a_to_b, -a_to_c, " "-b_to_a, -b_to_b, -b_to_c, -c_to_a, -c_to_b, -lap , -key , " "-speed_lt , -speed_gt , -rpm_lt , -rpm_gt , " "-command