├── .gitignore
├── .travis.yml
├── COPYING.txt
├── Makefile
├── README.md
├── code
├── botlib
│ ├── aasfile.h
│ ├── be_aas.h
│ ├── be_aas_bsp.h
│ ├── be_aas_bspq3.c
│ ├── be_aas_cluster.c
│ ├── be_aas_cluster.h
│ ├── be_aas_debug.c
│ ├── be_aas_debug.h
│ ├── be_aas_def.h
│ ├── be_aas_entity.c
│ ├── be_aas_entity.h
│ ├── be_aas_file.c
│ ├── be_aas_file.h
│ ├── be_aas_funcs.h
│ ├── be_aas_main.c
│ ├── be_aas_main.h
│ ├── be_aas_move.c
│ ├── be_aas_move.h
│ ├── be_aas_optimize.c
│ ├── be_aas_optimize.h
│ ├── be_aas_reach.c
│ ├── be_aas_reach.h
│ ├── be_aas_route.c
│ ├── be_aas_route.h
│ ├── be_aas_routealt.c
│ ├── be_aas_routealt.h
│ ├── be_aas_sample.c
│ ├── be_aas_sample.h
│ ├── be_interface.c
│ ├── be_interface.h
│ ├── botlib.h
│ ├── l_crc.c
│ ├── l_crc.h
│ ├── l_libvar.c
│ ├── l_libvar.h
│ ├── l_log.c
│ ├── l_log.h
│ ├── l_memory.c
│ └── l_memory.h
├── cgame
│ ├── cg_atmospheric.c
│ ├── cg_audio.c
│ ├── cg_console.c
│ ├── cg_consolecmds.c
│ ├── cg_draw.c
│ ├── cg_drawtools.c
│ ├── cg_effects.c
│ ├── cg_ents.c
│ ├── cg_event.c
│ ├── cg_field.c
│ ├── cg_info.c
│ ├── cg_input.c
│ ├── cg_local.h
│ ├── cg_localents.c
│ ├── cg_main.c
│ ├── cg_marks.c
│ ├── cg_newdraw.c
│ ├── cg_particles.c
│ ├── cg_players.c
│ ├── cg_playerstate.c
│ ├── cg_polybus.c
│ ├── cg_predict.c
│ ├── cg_public.h
│ ├── cg_scoreboard.c
│ ├── cg_servercmds.c
│ ├── cg_snapshot.c
│ ├── cg_spawn.c
│ ├── cg_surface.c
│ ├── cg_syscalls.c
│ ├── cg_syscalls.h
│ ├── cg_text.c
│ ├── cg_unlagged.c
│ ├── cg_view.c
│ └── cg_weapons.c
├── client
│ └── keycodes.h
├── game
│ ├── ai_char.c
│ ├── ai_char.h
│ ├── ai_chat.c
│ ├── ai_chat.h
│ ├── ai_chat_sys.c
│ ├── ai_chat_sys.h
│ ├── ai_cmd.c
│ ├── ai_cmd.h
│ ├── ai_dmnet.c
│ ├── ai_dmnet.h
│ ├── ai_dmq3.c
│ ├── ai_dmq3.h
│ ├── ai_ea.c
│ ├── ai_ea.h
│ ├── ai_gen.c
│ ├── ai_gen.h
│ ├── ai_goal.c
│ ├── ai_goal.h
│ ├── ai_main.c
│ ├── ai_main.h
│ ├── ai_move.c
│ ├── ai_move.h
│ ├── ai_team.c
│ ├── ai_team.h
│ ├── ai_vcmd.c
│ ├── ai_vcmd.h
│ ├── ai_weap.c
│ ├── ai_weap.h
│ ├── ai_weight.c
│ ├── ai_weight.h
│ ├── bg_config.c
│ ├── bg_lib.c
│ ├── bg_lib.h
│ ├── bg_local.h
│ ├── bg_misc.c
│ ├── bg_pmove.c
│ ├── bg_public.h
│ ├── bg_slidemove.c
│ ├── bg_syscalls.asm
│ ├── bg_tracemap.c
│ ├── chars.h
│ ├── g_active.c
│ ├── g_arenas.c
│ ├── g_bot.c
│ ├── g_botlib.c
│ ├── g_client.c
│ ├── g_cmds.c
│ ├── g_combat.c
│ ├── g_items.c
│ ├── g_local.h
│ ├── g_main.c
│ ├── g_misc.c
│ ├── g_missile.c
│ ├── g_mover.c
│ ├── g_paths.c
│ ├── g_public.h
│ ├── g_save.c
│ ├── g_session.c
│ ├── g_spawn.c
│ ├── g_svcmds.c
│ ├── g_syscalls.c
│ ├── g_syscalls.h
│ ├── g_target.c
│ ├── g_team.c
│ ├── g_team.h
│ ├── g_trigger.c
│ ├── g_unlagged.c
│ ├── g_utils.c
│ ├── g_weapon.c
│ ├── inv.h
│ ├── match.h
│ └── syn.h
├── q3_ui
│ ├── ui_addbots.c
│ ├── ui_atoms.c
│ ├── ui_cinematics.c
│ ├── ui_confirm.c
│ ├── ui_connect.c
│ ├── ui_controls2.c
│ ├── ui_credits.c
│ ├── ui_demo2.c
│ ├── ui_display.c
│ ├── ui_gameinfo.c
│ ├── ui_ingame.c
│ ├── ui_ingame_selectplayer.c
│ ├── ui_ingame_server.c
│ ├── ui_joystick.c
│ ├── ui_loadconfig.c
│ ├── ui_local.h
│ ├── ui_main.c
│ ├── ui_menu.c
│ ├── ui_mfield.c
│ ├── ui_mods.c
│ ├── ui_multiplayer.c
│ ├── ui_network.c
│ ├── ui_options.c
│ ├── ui_playermodel.c
│ ├── ui_players.c
│ ├── ui_playersettings.c
│ ├── ui_playersetup.c
│ ├── ui_preferences.c
│ ├── ui_qmenu.c
│ ├── ui_removebots.c
│ ├── ui_saveconfig.c
│ ├── ui_selectplayer.c
│ ├── ui_serverinfo.c
│ ├── ui_servers2.c
│ ├── ui_setup.c
│ ├── ui_sound.c
│ ├── ui_sparena.c
│ ├── ui_specifyserver.c
│ ├── ui_splevel.c
│ ├── ui_spplayer.c
│ ├── ui_sppostgame.c
│ ├── ui_spreset.c
│ ├── ui_spskill.c
│ ├── ui_startserver.c
│ ├── ui_team.c
│ ├── ui_teamorders.c
│ └── ui_video.c
├── qcommon
│ ├── q_math.c
│ ├── q_platform.h
│ ├── q_shared.c
│ ├── q_shared.h
│ ├── q_unicode.c
│ ├── q_unicode.h
│ ├── qfiles.h
│ ├── surfaceflags.h
│ └── unicode_data.h
├── renderercommon
│ └── tr_types.h
├── tools
│ ├── asm
│ │ ├── README.Id
│ │ ├── cmdlib.c
│ │ ├── cmdlib.h
│ │ ├── lib.txt
│ │ ├── mathlib.h
│ │ ├── notes.txt
│ │ ├── ops.txt
│ │ ├── opstrings.h
│ │ └── q3asm.c
│ └── lcc
│ │ ├── COPYRIGHT
│ │ ├── LOG
│ │ ├── README
│ │ ├── README.id
│ │ ├── cpp
│ │ ├── cpp.c
│ │ ├── cpp.h
│ │ ├── eval.c
│ │ ├── getopt.c
│ │ ├── hideset.c
│ │ ├── include.c
│ │ ├── lex.c
│ │ ├── macro.c
│ │ ├── nlist.c
│ │ ├── tokens.c
│ │ └── unix.c
│ │ ├── doc
│ │ ├── 4.html
│ │ ├── bprint.1
│ │ ├── bprint.pdf
│ │ ├── install.html
│ │ ├── lcc.1
│ │ └── lcc.pdf
│ │ ├── etc
│ │ ├── bytecode.c
│ │ └── lcc.c
│ │ ├── lburg
│ │ ├── gram.c
│ │ ├── gram.y
│ │ ├── lburg.1
│ │ ├── lburg.c
│ │ └── lburg.h
│ │ └── src
│ │ ├── alloc.c
│ │ ├── bind.c
│ │ ├── bytecode.c
│ │ ├── c.h
│ │ ├── config.h
│ │ ├── dag.c
│ │ ├── dagcheck.md
│ │ ├── decl.c
│ │ ├── enode.c
│ │ ├── error.c
│ │ ├── event.c
│ │ ├── expr.c
│ │ ├── gen.c
│ │ ├── init.c
│ │ ├── inits.c
│ │ ├── input.c
│ │ ├── lex.c
│ │ ├── list.c
│ │ ├── main.c
│ │ ├── null.c
│ │ ├── output.c
│ │ ├── prof.c
│ │ ├── profio.c
│ │ ├── simp.c
│ │ ├── stmt.c
│ │ ├── string.c
│ │ ├── sym.c
│ │ ├── symbolic.c
│ │ ├── token.h
│ │ ├── trace.c
│ │ ├── tree.c
│ │ └── types.c
└── ui
│ ├── ui_atoms.c
│ ├── ui_gameinfo.c
│ ├── ui_local.h
│ ├── ui_main.c
│ ├── ui_players.c
│ ├── ui_public.h
│ ├── ui_shared.c
│ └── ui_shared.h
├── travis-ci-build.sh
└── ui
├── hud.txt
├── hud2.txt
├── ingame.txt
├── menudef.h
└── menus.txt
/.gitignore:
--------------------------------------------------------------------------------
1 | build
2 | Makefile.local
3 | *.swp
4 | *tags
5 | misc/code_blocks/*.layout
6 |
7 | # OS X
8 | ####################
9 | .Spotlight-V100/
10 | .Trashes/
11 | ._*
12 | .AppleDouble
13 | .DS_Store
14 | .LSOverride
15 | Icon?
16 |
17 | # Xcode
18 | ####################
19 | *.mode1v3
20 | *.mode2v3
21 | *.pbxuser
22 | *.perspectivev3
23 | *.user
24 | *.xcuserstate
25 | *.moved-aside
26 | *~.nib
27 | .idea/
28 | DerivedData/
29 | project.xcworkspace/
30 | xcuserdata/
31 | profile
32 | !default.pbxuser
33 | !default.mode1v3
34 | !default.mode2v3
35 | !default.perspectivev3
36 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: c
2 |
3 | env:
4 | matrix:
5 | # standard builds
6 | - CC=gcc
7 | - CC=clang
8 | # cross-compile using mingw
9 | - CC= PLATFORM="mingw32" ARCH="x86"
10 | - CC= PLATFORM="mingw32" ARCH="x86_64"
11 |
12 | script: ./travis-ci-build.sh
13 |
14 | sudo: false
15 |
16 | addons:
17 | apt:
18 | packages:
19 | - binutils-mingw-w64-i686
20 | - gcc-mingw-w64-i686
21 | - binutils-mingw-w64-x86-64
22 | - gcc-mingw-w64-x86-64
23 | - gcc-mingw-w64
24 | - mingw-w64
25 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | **Turtle Arena** game code.
2 |
3 | To use this you'll need the [Spearmint engine](https://github.com/zturtleman/spearmint).
4 |
5 | * On Windows, install [Cygwin and mingw-w64](https://github.com/zturtleman/spearmint/wiki/Compiling#windows).
6 | * Get the source for Spearmint and build it using `make`.
7 | * Get the source for this repo and build it using `make`.
8 | * Copy the [turtle-arena-data](https://github.com/Turtle-Arena/turtle-arena-data) to `turtle-arena-code/build/release-mingw32-x86/baseturtle/data.pk3dir`
9 |
10 | If you put both projects in the same directory you can launch the game using;
11 |
12 | spearmint/build/release-mingw32-x86/spearmint_x86.exe +set fs_basepath "turtle-arena-code/build/release-mingw32-x86/" +set fs_game "baseturtle"
13 |
14 | On Linux and OS X you'll need to put `./` before the command and substitute the correct platform and architecture (look in the build directory).
15 |
16 |
--------------------------------------------------------------------------------
/code/botlib/be_aas_bsp.h:
--------------------------------------------------------------------------------
1 | /*
2 | ===========================================================================
3 | Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
4 |
5 | This file is part of Spearmint Source Code.
6 |
7 | Spearmint Source Code is free software; you can redistribute it
8 | and/or modify it under the terms of the GNU General Public License as
9 | published by the Free Software Foundation; either version 3 of the License,
10 | or (at your option) any later version.
11 |
12 | Spearmint Source Code is distributed in the hope that it will be
13 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with Spearmint Source Code. If not, see .
19 |
20 | In addition, Spearmint Source Code is also subject to certain additional terms.
21 | You should have received a copy of these additional terms immediately following
22 | the terms and conditions of the GNU General Public License. If not, please
23 | request a copy in writing from id Software at the address below.
24 |
25 | If you have questions concerning this license or the applicable additional
26 | terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc.,
27 | Suite 120, Rockville, Maryland 20850 USA.
28 | ===========================================================================
29 | */
30 |
31 | /*****************************************************************************
32 | * name: be_aas_bsp.h
33 | *
34 | * desc: AAS
35 | *
36 | * $Archive: /source/code/botlib/be_aas_bsp.h $
37 | *
38 | *****************************************************************************/
39 |
40 | #ifdef AASINTERN
41 | //loads the given BSP file
42 | int AAS_LoadBSPFile(void);
43 | //dump the loaded BSP data
44 | void AAS_DumpBSPData(void);
45 | //unlink the given entity from the bsp tree leaves
46 | void AAS_UnlinkFromBSPLeaves(bsp_link_t *leaves);
47 | //link the given entity to the bsp tree leaves of the given model
48 | bsp_link_t *AAS_BSPLinkEntity(vec3_t absmins,
49 | vec3_t absmaxs,
50 | int entnum,
51 | int modelnum);
52 |
53 | //calculates collision with given entity
54 | qboolean AAS_EntityCollision(int entnum,
55 | vec3_t start,
56 | vec3_t boxmins,
57 | vec3_t boxmaxs,
58 | vec3_t end,
59 | int contentmask,
60 | bsp_trace_t *trace);
61 | //for debugging
62 | void AAS_PrintFreeBSPLinks(char *str);
63 | //
64 | #endif //AASINTERN
65 |
66 | //trace through the world
67 | bsp_trace_t AAS_Trace( vec3_t start,
68 | vec3_t mins,
69 | vec3_t maxs,
70 | vec3_t end,
71 | int passent,
72 | int contentmask);
73 | //returns the contents at the given point
74 | int AAS_PointContents(vec3_t point);
75 | //returns true when p2 is in the PVS of p1
76 | qboolean AAS_inPVS(vec3_t p1, vec3_t p2);
77 | //returns true when p2 is in the PHS of p1
78 | qboolean AAS_inPHS(vec3_t p1, vec3_t p2);
79 | //returns true if the given areas are connected
80 | qboolean AAS_AreasConnected(int area1, int area2);
81 | //creates a list with entities totally or partly within the given box
82 | int AAS_BoxEntities(vec3_t absmins, vec3_t absmaxs, int *list, int maxcount);
83 | //gets the mins, maxs and origin of a BSP model
84 | void AAS_BSPModelMinsMaxsOrigin(int modelnum, vec3_t angles, vec3_t mins, vec3_t maxs, vec3_t origin);
85 | //handle to the next bsp entity
86 | int AAS_NextBSPEntity(int ent);
87 | //return the value of the BSP epair key
88 | int AAS_ValueForBSPEpairKey(int ent, char *key, char *value, int size);
89 | //get a vector for the BSP epair key
90 | int AAS_VectorForBSPEpairKey(int ent, char *key, vec3_t v);
91 | //get a float for the BSP epair key
92 | int AAS_FloatForBSPEpairKey(int ent, char *key, float *value);
93 | //get an integer for the BSP epair key
94 | int AAS_IntForBSPEpairKey(int ent, char *key, int *value);
95 |
96 |
--------------------------------------------------------------------------------
/code/botlib/be_aas_cluster.h:
--------------------------------------------------------------------------------
1 | /*
2 | ===========================================================================
3 | Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
4 |
5 | This file is part of Spearmint Source Code.
6 |
7 | Spearmint Source Code is free software; you can redistribute it
8 | and/or modify it under the terms of the GNU General Public License as
9 | published by the Free Software Foundation; either version 3 of the License,
10 | or (at your option) any later version.
11 |
12 | Spearmint Source Code is distributed in the hope that it will be
13 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with Spearmint Source Code. If not, see .
19 |
20 | In addition, Spearmint Source Code is also subject to certain additional terms.
21 | You should have received a copy of these additional terms immediately following
22 | the terms and conditions of the GNU General Public License. If not, please
23 | request a copy in writing from id Software at the address below.
24 |
25 | If you have questions concerning this license or the applicable additional
26 | terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc.,
27 | Suite 120, Rockville, Maryland 20850 USA.
28 | ===========================================================================
29 | */
30 |
31 | /*****************************************************************************
32 | * name: be_aas_cluster.h
33 | *
34 | * desc: AAS
35 | *
36 | * $Archive: /source/code/botlib/be_aas_cluster.h $
37 | *
38 | *****************************************************************************/
39 |
40 | #ifdef AASINTERN
41 | //initialize the AAS clustering
42 | void AAS_InitClustering(void);
43 | //
44 | void AAS_SetViewPortalsAsClusterPortals(void);
45 | #endif //AASINTERN
46 |
47 |
--------------------------------------------------------------------------------
/code/botlib/be_aas_debug.h:
--------------------------------------------------------------------------------
1 | /*
2 | ===========================================================================
3 | Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
4 |
5 | This file is part of Spearmint Source Code.
6 |
7 | Spearmint Source Code is free software; you can redistribute it
8 | and/or modify it under the terms of the GNU General Public License as
9 | published by the Free Software Foundation; either version 3 of the License,
10 | or (at your option) any later version.
11 |
12 | Spearmint Source Code is distributed in the hope that it will be
13 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with Spearmint Source Code. If not, see .
19 |
20 | In addition, Spearmint Source Code is also subject to certain additional terms.
21 | You should have received a copy of these additional terms immediately following
22 | the terms and conditions of the GNU General Public License. If not, please
23 | request a copy in writing from id Software at the address below.
24 |
25 | If you have questions concerning this license or the applicable additional
26 | terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc.,
27 | Suite 120, Rockville, Maryland 20850 USA.
28 | ===========================================================================
29 | */
30 |
31 | /*****************************************************************************
32 | * name: be_aas_debug.h
33 | *
34 | * desc: AAS
35 | *
36 | * $Archive: /source/code/botlib/be_aas_debug.h $
37 | *
38 | *****************************************************************************/
39 |
40 | //clear the shown debug lines
41 | void AAS_ClearShownDebugLines(void);
42 | //
43 | void AAS_ClearShownPolygons(void);
44 | //show a debug line
45 | void AAS_DebugLine(vec3_t start, vec3_t end, int color);
46 | //show a permenent line
47 | void AAS_PermanentLine(vec3_t start, vec3_t end, int color);
48 | //show a permanent cross
49 | void AAS_DrawPermanentCross(vec3_t origin, float size, int color);
50 | //draw a cross in the plane
51 | void AAS_DrawPlaneCross(vec3_t point, vec3_t normal, float dist, int type, int color);
52 | //show a bounding box
53 | void AAS_ShowBoundingBox(vec3_t origin, vec3_t mins, vec3_t maxs);
54 | //show a face
55 | void AAS_ShowFace(int facenum);
56 | //show an area
57 | void AAS_ShowArea(int areanum, int groundfacesonly);
58 | //
59 | void AAS_ShowAreaPolygons(int areanum, int color, int groundfacesonly);
60 | //draw a cros
61 | void AAS_DrawCross(vec3_t origin, float size, int color);
62 | //print the travel type
63 | void AAS_PrintTravelType(int traveltype);
64 | //draw an arrow
65 | void AAS_DrawArrow(vec3_t start, vec3_t end, int linecolor, int arrowcolor);
66 | //visualize the given reachability
67 | void AAS_ShowReachability(struct aas_reachability_s *reach, int contentmask);
68 | //show the reachable areas from the given area
69 | void AAS_ShowReachableAreas(int areanum, int contentmask);
70 | //
71 | void AAS_FloodAreas(vec3_t origin);
72 |
73 |
--------------------------------------------------------------------------------
/code/botlib/be_aas_entity.h:
--------------------------------------------------------------------------------
1 | /*
2 | ===========================================================================
3 | Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
4 |
5 | This file is part of Spearmint Source Code.
6 |
7 | Spearmint Source Code is free software; you can redistribute it
8 | and/or modify it under the terms of the GNU General Public License as
9 | published by the Free Software Foundation; either version 3 of the License,
10 | or (at your option) any later version.
11 |
12 | Spearmint Source Code is distributed in the hope that it will be
13 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with Spearmint Source Code. If not, see .
19 |
20 | In addition, Spearmint Source Code is also subject to certain additional terms.
21 | You should have received a copy of these additional terms immediately following
22 | the terms and conditions of the GNU General Public License. If not, please
23 | request a copy in writing from id Software at the address below.
24 |
25 | If you have questions concerning this license or the applicable additional
26 | terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc.,
27 | Suite 120, Rockville, Maryland 20850 USA.
28 | ===========================================================================
29 | */
30 |
31 | /*****************************************************************************
32 | * name: be_aas_entity.h
33 | *
34 | * desc: AAS
35 | *
36 | * $Archive: /source/code/botlib/be_aas_entity.h $
37 | *
38 | *****************************************************************************/
39 |
40 | #ifdef AASINTERN
41 | //invalidates all entity infos
42 | void AAS_InvalidateEntities(void);
43 | //unlink not updated entities
44 | void AAS_UnlinkInvalidEntities(void);
45 | //resets the entity AAS and BSP links (sets areas and leaves pointers to NULL)
46 | void AAS_ResetEntityLinks(void);
47 | //updates an entity
48 | int AAS_UpdateEntity(int ent, bot_entitystate_t *state);
49 | #endif //AASINTERN
50 |
51 |
--------------------------------------------------------------------------------
/code/botlib/be_aas_file.h:
--------------------------------------------------------------------------------
1 | /*
2 | ===========================================================================
3 | Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
4 |
5 | This file is part of Spearmint Source Code.
6 |
7 | Spearmint Source Code is free software; you can redistribute it
8 | and/or modify it under the terms of the GNU General Public License as
9 | published by the Free Software Foundation; either version 3 of the License,
10 | or (at your option) any later version.
11 |
12 | Spearmint Source Code is distributed in the hope that it will be
13 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with Spearmint Source Code. If not, see .
19 |
20 | In addition, Spearmint Source Code is also subject to certain additional terms.
21 | You should have received a copy of these additional terms immediately following
22 | the terms and conditions of the GNU General Public License. If not, please
23 | request a copy in writing from id Software at the address below.
24 |
25 | If you have questions concerning this license or the applicable additional
26 | terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc.,
27 | Suite 120, Rockville, Maryland 20850 USA.
28 | ===========================================================================
29 | */
30 |
31 | /*****************************************************************************
32 | * name: be_aas_file.h
33 | *
34 | * desc: AAS
35 | *
36 | * $Archive: /source/code/botlib/be_aas_file.h $
37 | *
38 | *****************************************************************************/
39 |
40 | #ifdef AASINTERN
41 | //loads the AAS file with the given name
42 | int AAS_LoadAASFile(char *filename);
43 | //writes an AAS file with the given name
44 | qboolean AAS_WriteAASFile(char *filename);
45 | //dumps the loaded AAS data
46 | void AAS_DumpAASData(void);
47 | //print AAS file information
48 | void AAS_FileInfo(void);
49 | #endif //AASINTERN
50 |
51 |
--------------------------------------------------------------------------------
/code/botlib/be_aas_funcs.h:
--------------------------------------------------------------------------------
1 | /*
2 | ===========================================================================
3 | Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
4 |
5 | This file is part of Spearmint Source Code.
6 |
7 | Spearmint Source Code is free software; you can redistribute it
8 | and/or modify it under the terms of the GNU General Public License as
9 | published by the Free Software Foundation; either version 3 of the License,
10 | or (at your option) any later version.
11 |
12 | Spearmint Source Code is distributed in the hope that it will be
13 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with Spearmint Source Code. If not, see .
19 |
20 | In addition, Spearmint Source Code is also subject to certain additional terms.
21 | You should have received a copy of these additional terms immediately following
22 | the terms and conditions of the GNU General Public License. If not, please
23 | request a copy in writing from id Software at the address below.
24 |
25 | If you have questions concerning this license or the applicable additional
26 | terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc.,
27 | Suite 120, Rockville, Maryland 20850 USA.
28 | ===========================================================================
29 | */
30 |
31 | /*****************************************************************************
32 | * name: be_aas_funcs.h
33 | *
34 | * desc: AAS
35 | *
36 | * $Archive: /source/code/botlib/be_aas_funcs.h $
37 | *
38 | *****************************************************************************/
39 |
40 | #ifndef BSPCINCLUDE
41 |
42 | #include "be_aas_main.h"
43 | #include "be_aas_entity.h"
44 | #include "be_aas_sample.h"
45 | #include "be_aas_cluster.h"
46 | #include "be_aas_reach.h"
47 | #include "be_aas_route.h"
48 | #include "be_aas_routealt.h"
49 | #include "be_aas_debug.h"
50 | #include "be_aas_file.h"
51 | #include "be_aas_optimize.h"
52 | #include "be_aas_bsp.h"
53 | #include "be_aas_move.h"
54 |
55 | #endif //BSPCINCLUDE
56 |
--------------------------------------------------------------------------------
/code/botlib/be_aas_main.h:
--------------------------------------------------------------------------------
1 | /*
2 | ===========================================================================
3 | Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
4 |
5 | This file is part of Spearmint Source Code.
6 |
7 | Spearmint Source Code is free software; you can redistribute it
8 | and/or modify it under the terms of the GNU General Public License as
9 | published by the Free Software Foundation; either version 3 of the License,
10 | or (at your option) any later version.
11 |
12 | Spearmint Source Code is distributed in the hope that it will be
13 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with Spearmint Source Code. If not, see .
19 |
20 | In addition, Spearmint Source Code is also subject to certain additional terms.
21 | You should have received a copy of these additional terms immediately following
22 | the terms and conditions of the GNU General Public License. If not, please
23 | request a copy in writing from id Software at the address below.
24 |
25 | If you have questions concerning this license or the applicable additional
26 | terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc.,
27 | Suite 120, Rockville, Maryland 20850 USA.
28 | ===========================================================================
29 | */
30 |
31 | /*****************************************************************************
32 | * name: be_aas_main.h
33 | *
34 | * desc: AAS
35 | *
36 | * $Archive: /source/code/botlib/be_aas_main.h $
37 | *
38 | *****************************************************************************/
39 |
40 | #ifdef AASINTERN
41 |
42 | extern aas_t aasworld;
43 |
44 | //AAS error message
45 | void QDECL AAS_Error(char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
46 | //set AAS initialized
47 | void AAS_SetInitialized(void);
48 | //setup AAS with the given number of entities and clients
49 | int AAS_Setup(void);
50 | //shutdown AAS
51 | void AAS_Shutdown(void);
52 | //start a new map
53 | int AAS_LoadMap(const char *mapname);
54 | //start a new time frame
55 | int AAS_StartFrame(float time);
56 | #endif //AASINTERN
57 |
58 | //returns true if AAS is initialized
59 | int AAS_Initialized(void);
60 | //returns true if the AAS file is loaded
61 | int AAS_Loaded(void);
62 | //returns the current time
63 | float AAS_Time(void);
64 | //
65 | void AAS_ProjectPointOntoVector( vec3_t point, vec3_t vStart, vec3_t vEnd, vec3_t vProj );
66 |
--------------------------------------------------------------------------------
/code/botlib/be_aas_move.h:
--------------------------------------------------------------------------------
1 | /*
2 | ===========================================================================
3 | Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
4 |
5 | This file is part of Spearmint Source Code.
6 |
7 | Spearmint Source Code is free software; you can redistribute it
8 | and/or modify it under the terms of the GNU General Public License as
9 | published by the Free Software Foundation; either version 3 of the License,
10 | or (at your option) any later version.
11 |
12 | Spearmint Source Code is distributed in the hope that it will be
13 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with Spearmint Source Code. If not, see .
19 |
20 | In addition, Spearmint Source Code is also subject to certain additional terms.
21 | You should have received a copy of these additional terms immediately following
22 | the terms and conditions of the GNU General Public License. If not, please
23 | request a copy in writing from id Software at the address below.
24 |
25 | If you have questions concerning this license or the applicable additional
26 | terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc.,
27 | Suite 120, Rockville, Maryland 20850 USA.
28 | ===========================================================================
29 | */
30 |
31 | /*****************************************************************************
32 | * name: be_aas_move.h
33 | *
34 | * desc: AAS
35 | *
36 | * $Archive: /source/code/botlib/be_aas_move.h $
37 | *
38 | *****************************************************************************/
39 |
40 | #ifdef AASINTERN
41 | extern aas_settings_t aassettings;
42 | #endif //AASINTERN
43 |
44 | //movement prediction
45 | int AAS_PredictPlayerMovement(struct aas_clientmove_s *move,
46 | int entnum, vec3_t origin,
47 | int presencetype, int onground,
48 | vec3_t velocity, vec3_t cmdmove,
49 | int cmdframes,
50 | int maxframes, float frametime,
51 | int stopevent, int stopareanum, int visualize, int contentmask);
52 | //predict movement until bounding box is hit
53 | int AAS_PlayerMovementHitBBox(struct aas_clientmove_s *move,
54 | int entnum, vec3_t origin,
55 | int presencetype, int onground,
56 | vec3_t velocity, vec3_t cmdmove,
57 | int cmdframes,
58 | int maxframes, float frametime,
59 | vec3_t mins, vec3_t maxs, int visualize, int contentmask);
60 | //returns true if on the ground at the given origin
61 | int AAS_OnGround(vec3_t origin, int presencetype, int passent, int contentmask);
62 | //returns true if swimming at the given origin
63 | int AAS_Swimming(vec3_t origin);
64 | //returns the jump reachability run start point
65 | void AAS_JumpReachRunStart(struct aas_reachability_s *reach, vec3_t runstart, int contentmask);
66 | //returns true if against a ladder at the given origin
67 | int AAS_AgainstLadder(vec3_t origin);
68 | //rocket jump Z velocity when rocket-jumping at origin
69 | float AAS_RocketJumpZVelocity(vec3_t origin, int contentmask);
70 | //bfg jump Z velocity when bfg-jumping at origin
71 | float AAS_BFGJumpZVelocity(vec3_t origin, int contentmask);
72 | //calculates the horizontal velocity needed for a jump and returns true this velocity could be calculated
73 | int AAS_HorizontalVelocityForJump(float zvel, vec3_t start, vec3_t end, float *velocity);
74 | //
75 | void AAS_SetMovedir(vec3_t angles, vec3_t movedir);
76 | //
77 | int AAS_DropToFloor(vec3_t origin, vec3_t mins, vec3_t maxs, int passent, int contentsmask);
78 | //
79 | void AAS_InitSettings(void);
80 |
--------------------------------------------------------------------------------
/code/botlib/be_aas_optimize.h:
--------------------------------------------------------------------------------
1 | /*
2 | ===========================================================================
3 | Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
4 |
5 | This file is part of Spearmint Source Code.
6 |
7 | Spearmint Source Code is free software; you can redistribute it
8 | and/or modify it under the terms of the GNU General Public License as
9 | published by the Free Software Foundation; either version 3 of the License,
10 | or (at your option) any later version.
11 |
12 | Spearmint Source Code is distributed in the hope that it will be
13 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with Spearmint Source Code. If not, see .
19 |
20 | In addition, Spearmint Source Code is also subject to certain additional terms.
21 | You should have received a copy of these additional terms immediately following
22 | the terms and conditions of the GNU General Public License. If not, please
23 | request a copy in writing from id Software at the address below.
24 |
25 | If you have questions concerning this license or the applicable additional
26 | terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc.,
27 | Suite 120, Rockville, Maryland 20850 USA.
28 | ===========================================================================
29 | */
30 |
31 | /*****************************************************************************
32 | * name: be_aas_optimize.h
33 | *
34 | * desc: AAS
35 | *
36 | * $Archive: /source/code/botlib/be_aas_optimize.h $
37 | *
38 | *****************************************************************************/
39 |
40 | void AAS_Optimize(void);
41 |
42 |
--------------------------------------------------------------------------------
/code/botlib/be_aas_reach.h:
--------------------------------------------------------------------------------
1 | /*
2 | ===========================================================================
3 | Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
4 |
5 | This file is part of Spearmint Source Code.
6 |
7 | Spearmint Source Code is free software; you can redistribute it
8 | and/or modify it under the terms of the GNU General Public License as
9 | published by the Free Software Foundation; either version 3 of the License,
10 | or (at your option) any later version.
11 |
12 | Spearmint Source Code is distributed in the hope that it will be
13 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with Spearmint Source Code. If not, see .
19 |
20 | In addition, Spearmint Source Code is also subject to certain additional terms.
21 | You should have received a copy of these additional terms immediately following
22 | the terms and conditions of the GNU General Public License. If not, please
23 | request a copy in writing from id Software at the address below.
24 |
25 | If you have questions concerning this license or the applicable additional
26 | terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc.,
27 | Suite 120, Rockville, Maryland 20850 USA.
28 | ===========================================================================
29 | */
30 |
31 | /*****************************************************************************
32 | * name: be_aas_reach.h
33 | *
34 | * desc: AAS
35 | *
36 | * $Archive: /source/code/botlib/be_aas_reach.h $
37 | *
38 | *****************************************************************************/
39 |
40 | #ifdef AASINTERN
41 | //initialize calculating the reachabilities
42 | void AAS_InitReachability(void);
43 | //continue calculating the reachabilities
44 | int AAS_ContinueInitReachability(float time);
45 | //
46 | int AAS_BestReachableLinkArea(aas_link_t *areas);
47 | #endif //AASINTERN
48 |
49 | //returns true if the are has reachabilities to other areas
50 | int AAS_AreaReachability(int areanum);
51 | //returns the best reachable area and goal origin for a bounding box at the given origin
52 | int AAS_BestReachableArea(vec3_t origin, vec3_t mins, vec3_t maxs, vec3_t goalorigin);
53 | //returns the best jumppad area from which the bbox at origin is reachable
54 | int AAS_BestReachableFromJumpPadArea(vec3_t origin, vec3_t mins, vec3_t maxs);
55 | //returns the next reachability using the given model
56 | int AAS_NextModelReachability(int num, int modelnum);
57 | //returns the total area of the ground faces of the given area
58 | float AAS_AreaGroundFaceArea(int areanum);
59 | //returns true if the area is crouch only
60 | int AAS_AreaCrouch(int areanum);
61 | //returns true if a player can swim in this area
62 | int AAS_AreaSwim(int areanum);
63 | //returns true if the area is filled with a liquid
64 | int AAS_AreaLiquid(int areanum);
65 | //returns true if the area contains lava
66 | int AAS_AreaLava(int areanum);
67 | //returns true if the area contains slime
68 | int AAS_AreaSlime(int areanum);
69 | //returns true if the area has one or more ground faces
70 | int AAS_AreaGrounded(int areanum);
71 | //returns true if the area has one or more ladder faces
72 | int AAS_AreaLadder(int areanum);
73 | //returns true if the area is a jump pad
74 | int AAS_AreaJumpPad(int areanum);
75 | //returns true if the area is donotenter
76 | int AAS_AreaDoNotEnter(int areanum);
77 |
--------------------------------------------------------------------------------
/code/botlib/be_aas_route.h:
--------------------------------------------------------------------------------
1 | /*
2 | ===========================================================================
3 | Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
4 |
5 | This file is part of Spearmint Source Code.
6 |
7 | Spearmint Source Code is free software; you can redistribute it
8 | and/or modify it under the terms of the GNU General Public License as
9 | published by the Free Software Foundation; either version 3 of the License,
10 | or (at your option) any later version.
11 |
12 | Spearmint Source Code is distributed in the hope that it will be
13 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with Spearmint Source Code. If not, see .
19 |
20 | In addition, Spearmint Source Code is also subject to certain additional terms.
21 | You should have received a copy of these additional terms immediately following
22 | the terms and conditions of the GNU General Public License. If not, please
23 | request a copy in writing from id Software at the address below.
24 |
25 | If you have questions concerning this license or the applicable additional
26 | terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc.,
27 | Suite 120, Rockville, Maryland 20850 USA.
28 | ===========================================================================
29 | */
30 |
31 | /*****************************************************************************
32 | * name: be_aas_route.h
33 | *
34 | * desc: AAS
35 | *
36 | * $Archive: /source/code/botlib/be_aas_route.h $
37 | *
38 | *****************************************************************************/
39 |
40 | #ifdef AASINTERN
41 | //initialize the AAS routing
42 | void AAS_InitRouting(void);
43 | //free the AAS routing caches
44 | void AAS_FreeRoutingCaches(void);
45 | //returns the travel time from start to end in the given area
46 | unsigned short int AAS_AreaTravelTime(int areanum, vec3_t start, vec3_t end);
47 | //
48 | void AAS_CreateAllRoutingCache(void);
49 | void AAS_WriteRouteCache(void);
50 | //
51 | void AAS_RoutingInfo(void);
52 | #endif //AASINTERN
53 |
54 | //returns the travel flag for the given travel type
55 | int AAS_TravelFlagForType(int traveltype);
56 | //return the travel flag(s) for traveling through this area
57 | int AAS_AreaContentsTravelFlags(int areanum);
58 | //returns the index of the next reachability for the given area
59 | int AAS_NextAreaReachability(int areanum, int reachnum);
60 | //returns the reachability with the given index
61 | void AAS_ReachabilityFromNum(int num, struct aas_reachability_s *reach);
62 | //returns a random goal area and goal origin
63 | int AAS_RandomGoalArea(int areanum, int travelflags, int contentmask, int *goalareanum, vec3_t goalorigin);
64 | //enable or disable an area for routing
65 | int AAS_EnableRoutingArea(int areanum, int enable);
66 | //returns the travel time within the given area from start to end
67 | unsigned short int AAS_AreaTravelTime(int areanum, vec3_t start, vec3_t end);
68 | //returns the travel time from the area to the goal area using the given travel flags
69 | int AAS_AreaTravelTimeToGoalArea(int areanum, vec3_t origin, int goalareanum, int travelflags);
70 | //predict a route up to a stop event
71 | int AAS_PredictRoute(struct aas_predictroute_s *route, int areanum, vec3_t origin,
72 | int goalareanum, int travelflags, int maxareas, int maxtime,
73 | int stopevent, int stopcontents, int stoptfl, int stopareanum);
74 |
75 |
76 |
--------------------------------------------------------------------------------
/code/botlib/be_aas_routealt.h:
--------------------------------------------------------------------------------
1 | /*
2 | ===========================================================================
3 | Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
4 |
5 | This file is part of Spearmint Source Code.
6 |
7 | Spearmint Source Code is free software; you can redistribute it
8 | and/or modify it under the terms of the GNU General Public License as
9 | published by the Free Software Foundation; either version 3 of the License,
10 | or (at your option) any later version.
11 |
12 | Spearmint Source Code is distributed in the hope that it will be
13 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with Spearmint Source Code. If not, see .
19 |
20 | In addition, Spearmint Source Code is also subject to certain additional terms.
21 | You should have received a copy of these additional terms immediately following
22 | the terms and conditions of the GNU General Public License. If not, please
23 | request a copy in writing from id Software at the address below.
24 |
25 | If you have questions concerning this license or the applicable additional
26 | terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc.,
27 | Suite 120, Rockville, Maryland 20850 USA.
28 | ===========================================================================
29 | */
30 |
31 | /*****************************************************************************
32 | * name: be_aas_routealt.h
33 | *
34 | * desc: AAS
35 | *
36 | * $Archive: /source/code/botlib/be_aas_routealt.h $
37 | *
38 | *****************************************************************************/
39 |
40 | #ifdef AASINTERN
41 | void AAS_InitAlternativeRouting(void);
42 | void AAS_ShutdownAlternativeRouting(void);
43 | #endif //AASINTERN
44 |
45 |
46 | int AAS_AlternativeRouteGoals(vec3_t start, int startareanum, vec3_t goal, int goalareanum, int travelflags,
47 | aas_altroutegoal_t *altroutegoals, int maxaltroutegoals,
48 | int type);
49 |
--------------------------------------------------------------------------------
/code/botlib/be_aas_sample.h:
--------------------------------------------------------------------------------
1 | /*
2 | ===========================================================================
3 | Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
4 |
5 | This file is part of Spearmint Source Code.
6 |
7 | Spearmint Source Code is free software; you can redistribute it
8 | and/or modify it under the terms of the GNU General Public License as
9 | published by the Free Software Foundation; either version 3 of the License,
10 | or (at your option) any later version.
11 |
12 | Spearmint Source Code is distributed in the hope that it will be
13 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with Spearmint Source Code. If not, see .
19 |
20 | In addition, Spearmint Source Code is also subject to certain additional terms.
21 | You should have received a copy of these additional terms immediately following
22 | the terms and conditions of the GNU General Public License. If not, please
23 | request a copy in writing from id Software at the address below.
24 |
25 | If you have questions concerning this license or the applicable additional
26 | terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc.,
27 | Suite 120, Rockville, Maryland 20850 USA.
28 | ===========================================================================
29 | */
30 |
31 | /*****************************************************************************
32 | * name: be_aas_sample.h
33 | *
34 | * desc: AAS
35 | *
36 | * $Archive: /source/code/botlib/be_aas_sample.h $
37 | *
38 | *****************************************************************************/
39 |
40 | #ifdef AASINTERN
41 | void AAS_InitAASLinkHeap(void);
42 | void AAS_InitAASLinkedEntities(void);
43 | void AAS_FreeAASLinkHeap(void);
44 | void AAS_FreeAASLinkedEntities(void);
45 | aas_face_t *AAS_AreaGroundFace(int areanum, vec3_t point);
46 | aas_face_t *AAS_TraceEndFace(aas_trace_t *trace);
47 | aas_plane_t *AAS_PlaneFromNum(int planenum);
48 | aas_link_t *AAS_AASLinkEntity(vec3_t absmins, vec3_t absmaxs, int entnum);
49 | aas_link_t *AAS_LinkEntityClientBBox(vec3_t absmins, vec3_t absmaxs, int entnum, int presencetype);
50 | qboolean AAS_PointInsideFace(int facenum, vec3_t point, float epsilon);
51 | qboolean AAS_InsideFace(aas_face_t *face, vec3_t pnormal, vec3_t point, float epsilon);
52 | void AAS_UnlinkFromAreas(aas_link_t *areas);
53 | #endif //AASINTERN
54 |
55 | //returns the mins and maxs of the bounding box for the given presence type
56 | void AAS_PresenceTypeBoundingBox(int presencetype, vec3_t mins, vec3_t maxs);
57 | //returns the cluster the area is in (negative portal number if the area is a portal)
58 | int AAS_AreaCluster(int areanum);
59 | //returns the presence type(s) of the area
60 | int AAS_AreaPresenceType(int areanum);
61 | //returns the presence type(s) at the given point
62 | int AAS_PointPresenceType(vec3_t point);
63 | //returns the result of the trace of a client bbox
64 | aas_trace_t AAS_TracePlayerBBox(vec3_t start, vec3_t end, int presencetype, int passent, int contentmask);
65 | //AAS_TracePlayerBBox contentmask for AAS generation
66 | #define BOTMASK_SOLID (CONTENTS_SOLID|CONTENTS_PLAYERCLIP)
67 | //stores the areas the trace went through and returns the number of passed areas
68 | int AAS_TraceAreas(vec3_t start, vec3_t end, int *areas, vec3_t *points, int maxareas);
69 | //returns the areas the bounding box is in
70 | int AAS_BBoxAreas(vec3_t absmins, vec3_t absmaxs, int *areas, int maxareas);
71 | //return area information
72 | int AAS_AreaInfo( int areanum, aas_areainfo_t *info );
73 | //returns the area the point is in
74 | int AAS_PointAreaNum(vec3_t point);
75 | //
76 | int AAS_PointReachabilityAreaIndex( vec3_t point );
77 | //returns the plane the given face is in
78 | void AAS_FacePlane(int facenum, vec3_t normal, float *dist);
79 |
80 |
--------------------------------------------------------------------------------
/code/botlib/be_interface.h:
--------------------------------------------------------------------------------
1 | /*
2 | ===========================================================================
3 | Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
4 |
5 | This file is part of Spearmint Source Code.
6 |
7 | Spearmint Source Code is free software; you can redistribute it
8 | and/or modify it under the terms of the GNU General Public License as
9 | published by the Free Software Foundation; either version 3 of the License,
10 | or (at your option) any later version.
11 |
12 | Spearmint Source Code is distributed in the hope that it will be
13 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with Spearmint Source Code. If not, see .
19 |
20 | In addition, Spearmint Source Code is also subject to certain additional terms.
21 | You should have received a copy of these additional terms immediately following
22 | the terms and conditions of the GNU General Public License. If not, please
23 | request a copy in writing from id Software at the address below.
24 |
25 | If you have questions concerning this license or the applicable additional
26 | terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc.,
27 | Suite 120, Rockville, Maryland 20850 USA.
28 | ===========================================================================
29 | */
30 |
31 | /*****************************************************************************
32 | * name: be_interface.h
33 | *
34 | * desc: botlib interface
35 | *
36 | * $Archive: /source/code/botlib/be_interface.h $
37 | *
38 | *****************************************************************************/
39 |
40 | //#define DEBUG //debug code
41 | #define RANDOMIZE //randomize bot behaviour
42 |
43 | //FIXME: get rid of this global structure
44 | typedef struct botlib_globals_s
45 | {
46 | int botlibsetup; //true when the bot library has been setup
47 | int maxentities; //maximum number of entities
48 | int maxclients; //maximum number of clients
49 | float time; //the global time
50 | } botlib_globals_t;
51 |
52 |
53 | extern botlib_globals_t botlibglobals;
54 | extern botlib_import_t botimport;
55 | extern int botDeveloper; //true if developer is on
56 |
--------------------------------------------------------------------------------
/code/botlib/l_crc.h:
--------------------------------------------------------------------------------
1 | /*
2 | ===========================================================================
3 | Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
4 |
5 | This file is part of Spearmint Source Code.
6 |
7 | Spearmint Source Code is free software; you can redistribute it
8 | and/or modify it under the terms of the GNU General Public License as
9 | published by the Free Software Foundation; either version 3 of the License,
10 | or (at your option) any later version.
11 |
12 | Spearmint Source Code is distributed in the hope that it will be
13 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with Spearmint Source Code. If not, see .
19 |
20 | In addition, Spearmint Source Code is also subject to certain additional terms.
21 | You should have received a copy of these additional terms immediately following
22 | the terms and conditions of the GNU General Public License. If not, please
23 | request a copy in writing from id Software at the address below.
24 |
25 | If you have questions concerning this license or the applicable additional
26 | terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc.,
27 | Suite 120, Rockville, Maryland 20850 USA.
28 | ===========================================================================
29 | */
30 |
31 | typedef unsigned short crc_t;
32 |
33 | void CRC_Init(unsigned short *crcvalue);
34 | void CRC_ProcessByte(unsigned short *crcvalue, byte data);
35 | unsigned short CRC_Value(unsigned short crcvalue);
36 | unsigned short CRC_ProcessString(unsigned char *data, int length);
37 | void CRC_ContinueProcessString(unsigned short *crc, char *data, int length);
38 |
--------------------------------------------------------------------------------
/code/botlib/l_libvar.h:
--------------------------------------------------------------------------------
1 | /*
2 | ===========================================================================
3 | Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
4 |
5 | This file is part of Spearmint Source Code.
6 |
7 | Spearmint Source Code is free software; you can redistribute it
8 | and/or modify it under the terms of the GNU General Public License as
9 | published by the Free Software Foundation; either version 3 of the License,
10 | or (at your option) any later version.
11 |
12 | Spearmint Source Code is distributed in the hope that it will be
13 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with Spearmint Source Code. If not, see .
19 |
20 | In addition, Spearmint Source Code is also subject to certain additional terms.
21 | You should have received a copy of these additional terms immediately following
22 | the terms and conditions of the GNU General Public License. If not, please
23 | request a copy in writing from id Software at the address below.
24 |
25 | If you have questions concerning this license or the applicable additional
26 | terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc.,
27 | Suite 120, Rockville, Maryland 20850 USA.
28 | ===========================================================================
29 | */
30 |
31 | /*****************************************************************************
32 | * name: l_libvar.h
33 | *
34 | * desc: botlib vars
35 | *
36 | * $Archive: /source/code/botlib/l_libvar.h $
37 | *
38 | *****************************************************************************/
39 |
40 | //library variable
41 | typedef struct libvar_s
42 | {
43 | char *name;
44 | char *string;
45 | int flags;
46 | qboolean modified; // set each time the cvar is changed
47 | float value;
48 | struct libvar_s *next;
49 | } libvar_t;
50 |
51 | //removes all library variables
52 | void LibVarDeAllocAll(void);
53 | //gets the library variable with the given name
54 | libvar_t *LibVarGet(const char *var_name);
55 | //gets the string of the library variable with the given name
56 | char *LibVarGetString(const char *var_name);
57 | //gets the value of the library variable with the given name
58 | float LibVarGetValue(const char *var_name);
59 | //creates the library variable if not existing already and returns it
60 | libvar_t *LibVar(const char *var_name, const char *value);
61 | //creates the library variable if not existing already and returns the value
62 | float LibVarValue(const char *var_name, const char *value);
63 | //creates the library variable if not existing already and returns the value string
64 | char *LibVarString(const char *var_name, const char *value);
65 | //sets the library variable
66 | void LibVarSet(const char *var_name, const char *value);
67 | //returns true if the library variable has been modified
68 | qboolean LibVarChanged(const char *var_name);
69 | //sets the library variable to unmodified
70 | void LibVarSetNotModified(const char *var_name);
71 |
72 |
--------------------------------------------------------------------------------
/code/botlib/l_log.h:
--------------------------------------------------------------------------------
1 | /*
2 | ===========================================================================
3 | Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
4 |
5 | This file is part of Spearmint Source Code.
6 |
7 | Spearmint Source Code is free software; you can redistribute it
8 | and/or modify it under the terms of the GNU General Public License as
9 | published by the Free Software Foundation; either version 3 of the License,
10 | or (at your option) any later version.
11 |
12 | Spearmint Source Code is distributed in the hope that it will be
13 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with Spearmint Source Code. If not, see .
19 |
20 | In addition, Spearmint Source Code is also subject to certain additional terms.
21 | You should have received a copy of these additional terms immediately following
22 | the terms and conditions of the GNU General Public License. If not, please
23 | request a copy in writing from id Software at the address below.
24 |
25 | If you have questions concerning this license or the applicable additional
26 | terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc.,
27 | Suite 120, Rockville, Maryland 20850 USA.
28 | ===========================================================================
29 | */
30 |
31 | /*****************************************************************************
32 | * name: l_log.h
33 | *
34 | * desc: log file
35 | *
36 | * $Archive: /source/code/botlib/l_log.h $
37 | *
38 | *****************************************************************************/
39 |
40 | //open a log file
41 | void Log_Open(char *filename);
42 | //close the current log file
43 | void Log_Close(void);
44 | //close log file if present
45 | void Log_Shutdown(void);
46 | //write to the current opened log file
47 | void QDECL Log_Write(char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
48 | //write to the current opened log file with a time stamp
49 | void QDECL Log_WriteTimeStamped(char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
50 | //returns a handle to the log file
51 | qhandle_t Log_FileHandle(void);
52 | //flush log file
53 | void Log_Flush(void);
54 |
55 |
--------------------------------------------------------------------------------
/code/botlib/l_memory.h:
--------------------------------------------------------------------------------
1 | /*
2 | ===========================================================================
3 | Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
4 |
5 | This file is part of Spearmint Source Code.
6 |
7 | Spearmint Source Code is free software; you can redistribute it
8 | and/or modify it under the terms of the GNU General Public License as
9 | published by the Free Software Foundation; either version 3 of the License,
10 | or (at your option) any later version.
11 |
12 | Spearmint Source Code is distributed in the hope that it will be
13 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with Spearmint Source Code. If not, see .
19 |
20 | In addition, Spearmint Source Code is also subject to certain additional terms.
21 | You should have received a copy of these additional terms immediately following
22 | the terms and conditions of the GNU General Public License. If not, please
23 | request a copy in writing from id Software at the address below.
24 |
25 | If you have questions concerning this license or the applicable additional
26 | terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc.,
27 | Suite 120, Rockville, Maryland 20850 USA.
28 | ===========================================================================
29 | */
30 |
31 | /*****************************************************************************
32 | * name: l_memory.h
33 | *
34 | * desc: memory management
35 | *
36 | * $Archive: /source/code/botlib/l_memory.h $
37 | *
38 | *****************************************************************************/
39 |
40 | //#define MEMDEBUG
41 |
42 | #ifdef MEMDEBUG
43 | #define GetMemory(size) GetMemoryDebug(size, #size, __FILE__, __LINE__);
44 | #define GetClearedMemory(size) GetClearedMemoryDebug(size, #size, __FILE__, __LINE__);
45 | //allocate a memory block of the given size
46 | void *GetMemoryDebug(unsigned long size, char *label, char *file, int line);
47 | //allocate a memory block of the given size and clear it
48 | void *GetClearedMemoryDebug(unsigned long size, char *label, char *file, int line);
49 | //
50 | #define GetHunkMemory(size) GetHunkMemoryDebug(size, #size, __FILE__, __LINE__);
51 | #define GetClearedHunkMemory(size) GetClearedHunkMemoryDebug(size, #size, __FILE__, __LINE__);
52 | //allocate a memory block of the given size
53 | void *GetHunkMemoryDebug(unsigned long size, char *label, char *file, int line);
54 | //allocate a memory block of the given size and clear it
55 | void *GetClearedHunkMemoryDebug(unsigned long size, char *label, char *file, int line);
56 | #else
57 | //allocate a memory block of the given size
58 | void *GetMemory(unsigned long size);
59 | //allocate a memory block of the given size and clear it
60 | void *GetClearedMemory(unsigned long size);
61 | //
62 | #ifdef BSPC
63 | #define GetHunkMemory GetMemory
64 | #define GetClearedHunkMemory GetClearedMemory
65 | #else
66 | //allocate a memory block of the given size
67 | void *GetHunkMemory(unsigned long size);
68 | //allocate a memory block of the given size and clear it
69 | void *GetClearedHunkMemory(unsigned long size);
70 | #endif
71 | #endif
72 |
73 | //free the given memory block
74 | void FreeMemory(void *ptr);
75 | //returns the amount available memory
76 | int AvailableMemory(void);
77 | //prints the total used memory size
78 | void PrintUsedMemorySize(void);
79 | //print all memory blocks with label
80 | void PrintMemoryLabels(void);
81 | //returns the size of the memory block in bytes
82 | int MemoryByteSize(void *ptr);
83 | //free all allocated memory
84 | void DumpMemory(void);
85 |
--------------------------------------------------------------------------------
/code/cgame/cg_polybus.c:
--------------------------------------------------------------------------------
1 | /*
2 | ===========================================================================
3 | Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
4 |
5 | This file is part of Spearmint Source Code.
6 |
7 | Spearmint Source Code is free software; you can redistribute it
8 | and/or modify it under the terms of the GNU General Public License as
9 | published by the Free Software Foundation; either version 3 of the License,
10 | or (at your option) any later version.
11 |
12 | Spearmint Source Code is distributed in the hope that it will be
13 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with Spearmint Source Code. If not, see .
19 |
20 | In addition, Spearmint Source Code is also subject to certain additional terms.
21 | You should have received a copy of these additional terms immediately following
22 | the terms and conditions of the GNU General Public License. If not, please
23 | request a copy in writing from id Software at the address below.
24 |
25 | If you have questions concerning this license or the applicable additional
26 | terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc.,
27 | Suite 120, Rockville, Maryland 20850 USA.
28 | ===========================================================================
29 | */
30 |
31 | #include "cg_local.h"
32 |
33 | #define MAX_PB_BUFFERS 128
34 |
35 | polyBuffer_t cg_polyBuffers[MAX_PB_BUFFERS];
36 | int cg_polyBuffersInuse[MAX_PB_BUFFERS];
37 |
38 | polyBuffer_t* CG_PB_FindFreePolyBuffer( qhandle_t shader, int numVerts, int numIndicies ) {
39 | int i;
40 | int firstFree = -1;
41 |
42 | // find one with the same shader if possible
43 | for ( i = 0; i < MAX_PB_BUFFERS; i++ ) {
44 | if ( !cg_polyBuffersInuse[i] ) {
45 | if ( firstFree == -1 ) {
46 | firstFree = i;
47 | }
48 | continue;
49 | }
50 |
51 | if ( cg_polyBuffersInuse[i] != 1+cg.cur_localPlayerNum ) {
52 | continue;
53 | }
54 |
55 | if ( cg_polyBuffers[i].shader != shader ) {
56 | continue;
57 | }
58 |
59 | if ( cg_polyBuffers[i].numIndicies + numIndicies >= MAX_PB_INDICIES ) {
60 | continue;
61 | }
62 |
63 | if ( cg_polyBuffers[i].numVerts + numVerts >= MAX_PB_VERTS ) {
64 | continue;
65 | }
66 |
67 | return &cg_polyBuffers[i];
68 | }
69 |
70 | // return new poly buffer
71 | if ( firstFree != -1 ) {
72 | cg_polyBuffersInuse[firstFree] = 1+cg.cur_localPlayerNum;
73 | cg_polyBuffers[firstFree].shader = shader;
74 | cg_polyBuffers[firstFree].numIndicies = 0;
75 | cg_polyBuffers[firstFree].numVerts = 0;
76 |
77 | return &cg_polyBuffers[firstFree];
78 | }
79 |
80 | return NULL;
81 | }
82 |
83 | void CG_PB_ClearPolyBuffers( void ) {
84 | // Gordon: changed numIndicies and numVerts to be reset in CG_PB_FindFreePolyBuffer, not here (should save the cache misses we were prolly getting)
85 | memset( cg_polyBuffersInuse, 0, sizeof( cg_polyBuffersInuse ) );
86 | }
87 |
88 | void CG_PB_RenderPolyBuffers( void ) {
89 | int i;
90 |
91 | for ( i = 0; i < MAX_PB_BUFFERS; i++ ) {
92 | if ( cg_polyBuffersInuse[i] == 1+cg.cur_localPlayerNum ) {
93 | trap_R_AddPolyBufferToScene( &cg_polyBuffers[i] );
94 | }
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/code/game/ai_char.h:
--------------------------------------------------------------------------------
1 | /*
2 | ===========================================================================
3 | Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
4 |
5 | This file is part of Spearmint Source Code.
6 |
7 | Spearmint Source Code is free software; you can redistribute it
8 | and/or modify it under the terms of the GNU General Public License as
9 | published by the Free Software Foundation; either version 3 of the License,
10 | or (at your option) any later version.
11 |
12 | Spearmint Source Code is distributed in the hope that it will be
13 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with Spearmint Source Code. If not, see .
19 |
20 | In addition, Spearmint Source Code is also subject to certain additional terms.
21 | You should have received a copy of these additional terms immediately following
22 | the terms and conditions of the GNU General Public License. If not, please
23 | request a copy in writing from id Software at the address below.
24 |
25 | If you have questions concerning this license or the applicable additional
26 | terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc.,
27 | Suite 120, Rockville, Maryland 20850 USA.
28 | ===========================================================================
29 | */
30 | //
31 |
32 | /*****************************************************************************
33 | * name: ai_char.h
34 | *
35 | * desc: bot characters
36 | *
37 | * $Archive: /source/code/game/ai_char.h $
38 | *
39 | *****************************************************************************/
40 |
41 | //loads a bot character from a file
42 | int BotLoadCharacter(char *charfile, float skill);
43 | //frees a bot character
44 | void BotFreeCharacter(int character);
45 | //returns a float characteristic
46 | float Characteristic_Float(int character, int index);
47 | //returns a bounded float characteristic
48 | float Characteristic_BFloat(int character, int index, float min, float max);
49 | //returns an integer characteristic
50 | int Characteristic_Integer(int character, int index);
51 | //returns a bounded integer characteristic
52 | int Characteristic_BInteger(int character, int index, int min, int max);
53 | //returns a string characteristic
54 | void Characteristic_String(int character, int index, char *buf, int size);
55 | //free cached bot characters
56 | void BotShutdownCharacters(void);
57 |
--------------------------------------------------------------------------------
/code/game/ai_chat.h:
--------------------------------------------------------------------------------
1 | /*
2 | ===========================================================================
3 | Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
4 |
5 | This file is part of Spearmint Source Code.
6 |
7 | Spearmint Source Code is free software; you can redistribute it
8 | and/or modify it under the terms of the GNU General Public License as
9 | published by the Free Software Foundation; either version 3 of the License,
10 | or (at your option) any later version.
11 |
12 | Spearmint Source Code is distributed in the hope that it will be
13 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with Spearmint Source Code. If not, see .
19 |
20 | In addition, Spearmint Source Code is also subject to certain additional terms.
21 | You should have received a copy of these additional terms immediately following
22 | the terms and conditions of the GNU General Public License. If not, please
23 | request a copy in writing from id Software at the address below.
24 |
25 | If you have questions concerning this license or the applicable additional
26 | terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc.,
27 | Suite 120, Rockville, Maryland 20850 USA.
28 | ===========================================================================
29 | */
30 | //
31 |
32 | /*****************************************************************************
33 | * name: ai_chat.h
34 | *
35 | * desc: Quake3 bot AI
36 | *
37 | * $Archive: /source/code/game/ai_chat.h $
38 | *
39 | *****************************************************************************/
40 |
41 | //
42 | int BotChat_EnterGame(bot_state_t *bs);
43 | //
44 | int BotChat_ExitGame(bot_state_t *bs);
45 | //
46 | int BotChat_StartLevel(bot_state_t *bs);
47 | //
48 | int BotChat_EndLevel(bot_state_t *bs);
49 | //
50 | int BotChat_HitTalking(bot_state_t *bs);
51 | //
52 | int BotChat_HitNoDeath(bot_state_t *bs);
53 | //
54 | int BotChat_HitNoKill(bot_state_t *bs);
55 | //
56 | int BotChat_Death(bot_state_t *bs);
57 | //
58 | int BotChat_Kill(bot_state_t *bs);
59 | //
60 | int BotChat_EnemySuicide(bot_state_t *bs);
61 | //
62 | int BotChat_Random(bot_state_t *bs);
63 | // time the selected chat takes to type in
64 | float BotChatTime(bot_state_t *bs);
65 | // returns true if the bot can chat at the current position
66 | int BotValidChatPosition(bot_state_t *bs);
67 | // test the initial bot chats
68 | void BotChatTest(bot_state_t *bs);
69 |
70 |
--------------------------------------------------------------------------------
/code/game/ai_chat_sys.h:
--------------------------------------------------------------------------------
1 | /*
2 | ===========================================================================
3 | Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
4 |
5 | This file is part of Spearmint Source Code.
6 |
7 | Spearmint Source Code is free software; you can redistribute it
8 | and/or modify it under the terms of the GNU General Public License as
9 | published by the Free Software Foundation; either version 3 of the License,
10 | or (at your option) any later version.
11 |
12 | Spearmint Source Code is distributed in the hope that it will be
13 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with Spearmint Source Code. If not, see .
19 |
20 | In addition, Spearmint Source Code is also subject to certain additional terms.
21 | You should have received a copy of these additional terms immediately following
22 | the terms and conditions of the GNU General Public License. If not, please
23 | request a copy in writing from id Software at the address below.
24 |
25 | If you have questions concerning this license or the applicable additional
26 | terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc.,
27 | Suite 120, Rockville, Maryland 20850 USA.
28 | ===========================================================================
29 | */
30 | //
31 | /*****************************************************************************
32 | * name: ai_chat_sys.h
33 | *
34 | * desc: char AI
35 | *
36 | * $Archive: /source/code/game/ai_chat_sys.h $
37 | *
38 | *****************************************************************************/
39 |
40 | #define MAX_MESSAGE_SIZE 256
41 | #define MAX_CHATTYPE_NAME 32
42 | #define MAX_MATCHVARIABLES 8
43 |
44 | #define CHAT_GENDERLESS 0
45 | #define CHAT_GENDERFEMALE 1
46 | #define CHAT_GENDERMALE 2
47 |
48 | #define CHAT_ALL 0
49 | #define CHAT_TEAM 1
50 | #define CHAT_TELL 2
51 |
52 | //console message types
53 | #define CMS_NORMAL 0
54 | #define CMS_CHAT 1
55 |
56 | //a console message
57 | typedef struct bot_consolemessage_s
58 | {
59 | int handle;
60 | float time; //message time
61 | int type; //message type
62 | char message[MAX_MESSAGE_SIZE]; //message
63 | struct bot_consolemessage_s *prev, *next; //prev and next in list
64 | int references; //references to this message
65 | } bot_consolemessage_t;
66 |
67 | //match variable
68 | typedef struct bot_matchvariable_s
69 | {
70 | char offset;
71 | int length;
72 | } bot_matchvariable_t;
73 | //returned to AI when a match is found
74 | typedef struct bot_match_s
75 | {
76 | char string[MAX_MESSAGE_SIZE];
77 | int type;
78 | int subtype;
79 | bot_matchvariable_t variables[MAX_MATCHVARIABLES];
80 | } bot_match_t;
81 |
82 | //setup the chat AI
83 | int BotSetupChatAI(void);
84 | //shutdown the chat AI
85 | void BotShutdownChatAI(void);
86 | //returns the handle to a newly allocated chat state
87 | int BotAllocChatState(void);
88 | //frees the chatstate
89 | void BotFreeChatState(int handle);
90 | //adds a console message to the chat state
91 | void BotQueueConsoleMessage(int chatstate, int type, char *message);
92 | //removes the console message from the chat state
93 | void BotRemoveConsoleMessage(int chatstate, int handle);
94 | //returns the next console message from the state
95 | int BotNextConsoleMessage(int chatstate, bot_consolemessage_t *cm);
96 | //returns the number of console messages currently stored in the state
97 | int BotNumConsoleMessages(int chatstate);
98 | //selects a chat message of the given type
99 | void BotInitialChat(int chatstate, char *type, int mcontext, char *var0, char *var1, char *var2, char *var3, char *var4, char *var5, char *var6, char *var7);
100 | //returns the number of initial chat messages of the given type
101 | int BotNumInitialChats(int chatstate, char *type);
102 | //find and select a reply for the given message
103 | int BotReplyChat(int chatstate, char *message, int mcontext, int vcontext, char *var0, char *var1, char *var2, char *var3, char *var4, char *var5, char *var6, char *var7);
104 | //returns the length of the currently selected chat message
105 | int BotChatLength(int chatstate);
106 | //enters the selected chat message
107 | void BotEnterChat(int chatstate, int playerto, int sendto);
108 | //get the chat message ready to be output
109 | void BotGetChatMessage(int chatstate, char *buf, int size);
110 | //checks if the first string contains the second one, returns index into first string or -1 if not found
111 | int StringContains(char *str1, char *str2, int casesensitive);
112 | //finds a match for the given string using the match templates
113 | int BotFindMatch(char *str, bot_match_t *match, unsigned long int context);
114 | //returns a variable from a match
115 | void BotMatchVariable(bot_match_t *match, int variable, char *buf, int size);
116 | //unify all the white spaces in the string
117 | void UnifyWhiteSpaces(char *string);
118 | //replace all the context related synonyms in the string
119 | void BotReplaceSynonyms(char *string, unsigned long int context);
120 | //loads a chat file for the chat state
121 | int BotLoadChatFile(int chatstate, char *chatfile, char *chatname);
122 | //store the gender of the bot in the chat state
123 | void BotSetChatGender(int chatstate, int gender);
124 | //store the bot name in the chat state
125 | void BotSetChatName(int chatstate, char *name, int playernum);
126 | //check if string exists in any match template
127 | int BotMatchTemplatesContainsString(const char *findstr);
128 |
--------------------------------------------------------------------------------
/code/game/ai_cmd.h:
--------------------------------------------------------------------------------
1 | /*
2 | ===========================================================================
3 | Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
4 |
5 | This file is part of Spearmint Source Code.
6 |
7 | Spearmint Source Code is free software; you can redistribute it
8 | and/or modify it under the terms of the GNU General Public License as
9 | published by the Free Software Foundation; either version 3 of the License,
10 | or (at your option) any later version.
11 |
12 | Spearmint Source Code is distributed in the hope that it will be
13 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with Spearmint Source Code. If not, see .
19 |
20 | In addition, Spearmint Source Code is also subject to certain additional terms.
21 | You should have received a copy of these additional terms immediately following
22 | the terms and conditions of the GNU General Public License. If not, please
23 | request a copy in writing from id Software at the address below.
24 |
25 | If you have questions concerning this license or the applicable additional
26 | terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc.,
27 | Suite 120, Rockville, Maryland 20850 USA.
28 | ===========================================================================
29 | */
30 | //
31 |
32 | /*****************************************************************************
33 | * name: ai_cmd.h
34 | *
35 | * desc: Quake3 bot AI
36 | *
37 | * $Archive: /source/code/game/ai_cmd.h $
38 | *
39 | *****************************************************************************/
40 |
41 | extern int notleader[MAX_CLIENTS];
42 |
43 | int BotMatchMessage(bot_state_t *bs, char *message);
44 | void BotPrintTeamGoal(bot_state_t *bs);
45 |
46 |
--------------------------------------------------------------------------------
/code/game/ai_dmnet.h:
--------------------------------------------------------------------------------
1 | /*
2 | ===========================================================================
3 | Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
4 |
5 | This file is part of Spearmint Source Code.
6 |
7 | Spearmint Source Code is free software; you can redistribute it
8 | and/or modify it under the terms of the GNU General Public License as
9 | published by the Free Software Foundation; either version 3 of the License,
10 | or (at your option) any later version.
11 |
12 | Spearmint Source Code is distributed in the hope that it will be
13 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with Spearmint Source Code. If not, see .
19 |
20 | In addition, Spearmint Source Code is also subject to certain additional terms.
21 | You should have received a copy of these additional terms immediately following
22 | the terms and conditions of the GNU General Public License. If not, please
23 | request a copy in writing from id Software at the address below.
24 |
25 | If you have questions concerning this license or the applicable additional
26 | terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc.,
27 | Suite 120, Rockville, Maryland 20850 USA.
28 | ===========================================================================
29 | */
30 | //
31 |
32 | /*****************************************************************************
33 | * name: ai_dmnet.h
34 | *
35 | * desc: Quake3 bot AI
36 | *
37 | * $Archive: /source/code/game/ai_dmnet.h $
38 | *
39 | *****************************************************************************/
40 |
41 | #define MAX_NODESWITCHES 50
42 |
43 | void AIEnter_Intermission(bot_state_t *bs, char *s);
44 | void AIEnter_Observer(bot_state_t *bs, char *s);
45 | void AIEnter_Respawn(bot_state_t *bs, char *s);
46 | void AIEnter_Stand(bot_state_t *bs, char *s);
47 | void AIEnter_Seek_ActivateEntity(bot_state_t *bs, char *s);
48 | void AIEnter_Seek_NBG(bot_state_t *bs, char *s);
49 | void AIEnter_Seek_LTG(bot_state_t *bs, char *s);
50 | void AIEnter_Seek_Camp(bot_state_t *bs, char *s);
51 | void AIEnter_Battle_Fight(bot_state_t *bs, char *s);
52 | void AIEnter_Battle_Chase(bot_state_t *bs, char *s);
53 | void AIEnter_Battle_Retreat(bot_state_t *bs, char *s);
54 | void AIEnter_Battle_NBG(bot_state_t *bs, char *s);
55 | int AINode_Intermission(bot_state_t *bs);
56 | int AINode_Observer(bot_state_t *bs);
57 | int AINode_Respawn(bot_state_t *bs);
58 | int AINode_Stand(bot_state_t *bs);
59 | int AINode_Seek_ActivateEntity(bot_state_t *bs);
60 | int AINode_Seek_NBG(bot_state_t *bs);
61 | int AINode_Seek_LTG(bot_state_t *bs);
62 | int AINode_Battle_Fight(bot_state_t *bs);
63 | int AINode_Battle_Chase(bot_state_t *bs);
64 | int AINode_Battle_Retreat(bot_state_t *bs);
65 | int AINode_Battle_NBG(bot_state_t *bs);
66 |
67 | void BotResetNodeSwitches(void);
68 | void BotDumpNodeSwitches(bot_state_t *bs);
69 |
70 |
--------------------------------------------------------------------------------
/code/game/ai_ea.h:
--------------------------------------------------------------------------------
1 | /*
2 | ===========================================================================
3 | Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
4 |
5 | This file is part of Spearmint Source Code.
6 |
7 | Spearmint Source Code is free software; you can redistribute it
8 | and/or modify it under the terms of the GNU General Public License as
9 | published by the Free Software Foundation; either version 3 of the License,
10 | or (at your option) any later version.
11 |
12 | Spearmint Source Code is distributed in the hope that it will be
13 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with Spearmint Source Code. If not, see .
19 |
20 | In addition, Spearmint Source Code is also subject to certain additional terms.
21 | You should have received a copy of these additional terms immediately following
22 | the terms and conditions of the GNU General Public License. If not, please
23 | request a copy in writing from id Software at the address below.
24 |
25 | If you have questions concerning this license or the applicable additional
26 | terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc.,
27 | Suite 120, Rockville, Maryland 20850 USA.
28 | ===========================================================================
29 | */
30 | //
31 |
32 | /*****************************************************************************
33 | * name: ai_ea.h
34 | *
35 | * desc: elementary actions
36 | *
37 | * $Archive: /source/code/game/ai_ea.h $
38 | *
39 | *****************************************************************************/
40 |
41 | #ifndef __AI_EA_H__
42 | #define __AI_EA_H__
43 |
44 | //action flags
45 | #define ACTION_ATTACK 0x00000001
46 | #define ACTION_USE 0x00000002
47 | #define ACTION_RESPAWN 0x00000008
48 | #define ACTION_JUMP 0x00000010
49 | #define ACTION_MOVEUP 0x00000020
50 | #define ACTION_CROUCH 0x00000080
51 | #define ACTION_MOVEDOWN 0x00000100
52 | #define ACTION_MOVEFORWARD 0x00000200
53 | #define ACTION_MOVEBACK 0x00000800
54 | #define ACTION_MOVELEFT 0x00001000
55 | #define ACTION_MOVERIGHT 0x00002000
56 | #define ACTION_DELAYEDJUMP 0x00008000
57 | #define ACTION_TALK 0x00010000
58 | #define ACTION_GESTURE 0x00020000
59 | #define ACTION_WALK 0x00080000
60 | #define ACTION_AFFIRMATIVE 0x00100000
61 | #define ACTION_NEGATIVE 0x00200000
62 | #define ACTION_GETFLAG 0x00800000
63 | #define ACTION_GUARDBASE 0x01000000
64 | #define ACTION_PATROL 0x02000000
65 | #define ACTION_FOLLOWME 0x08000000
66 | #define ACTION_JUMPEDLASTFRAME 0x10000000
67 | #ifdef TA_WEAPSYS_EX // BOTLIB
68 | #define ACTION_DROP_WEAPON 0x20000000
69 | #endif
70 |
71 | //the bot input, will be converted to a usercmd_t
72 | typedef struct bot_input_s
73 | {
74 | float thinktime; //time since last output (in seconds)
75 | vec3_t dir; //movement direction
76 | float speed; //speed in the range [0, 400]
77 | vec3_t viewangles; //the view angles
78 | int actionflags; //one of the ACTION_? flags
79 | #ifndef TA_WEAPSYS_EX
80 | int weapon; //weapon to use
81 | #endif
82 | #ifdef TA_HOLDSYS
83 | int holdable; //holdable to use
84 | #endif
85 | } bot_input_t;
86 |
87 | //ClientCommand elementary actions
88 | void EA_Say(int playerNum, char *str);
89 | void EA_SayTeam(int playerNum, char *str);
90 | void EA_Command(int playerNum, char *command );
91 |
92 | void EA_Action(int playerNum, int action);
93 | void EA_Crouch(int playerNum);
94 | void EA_MoveUp(int playerNum);
95 | void EA_MoveDown(int playerNum);
96 | void EA_MoveForward(int playerNum);
97 | void EA_MoveBack(int playerNum);
98 | void EA_MoveLeft(int playerNum);
99 | void EA_MoveRight(int playerNum);
100 | void EA_Attack(int playerNum);
101 | void EA_Respawn(int playerNum);
102 | void EA_Talk(int playerNum);
103 | void EA_Gesture(int playerNum);
104 | #ifdef TA_HOLDSYS
105 | void EA_Use(int playerNum, int holdable);
106 | #else
107 | void EA_Use(int playerNum);
108 | #endif
109 |
110 | //regular elementary actions
111 | #ifdef TA_WEAPSYS_EX
112 | void EA_DropWeapon(int playerNum);
113 | #else
114 | void EA_SelectWeapon(int playerNum, int weapon);
115 | #endif
116 | void EA_Jump(int playerNum);
117 | void EA_DelayedJump(int playerNum);
118 | void EA_Move(int playerNum, vec3_t dir, float speed);
119 | void EA_View(int playerNum, vec3_t viewangles);
120 |
121 | //send regular input to the server
122 | void EA_EndRegular(int playerNum, float thinktime);
123 | void EA_GetInput(int playerNum, float thinktime, bot_input_t *input);
124 | void EA_ResetInput(int playerNum);
125 | //setup and shutdown routines
126 | int EA_Setup(void);
127 | void EA_Shutdown(void);
128 |
129 | #endif // __AI_EA_H__
130 |
--------------------------------------------------------------------------------
/code/game/ai_gen.c:
--------------------------------------------------------------------------------
1 | /*
2 | ===========================================================================
3 | Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
4 |
5 | This file is part of Spearmint Source Code.
6 |
7 | Spearmint Source Code is free software; you can redistribute it
8 | and/or modify it under the terms of the GNU General Public License as
9 | published by the Free Software Foundation; either version 3 of the License,
10 | or (at your option) any later version.
11 |
12 | Spearmint Source Code is distributed in the hope that it will be
13 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with Spearmint Source Code. If not, see .
19 |
20 | In addition, Spearmint Source Code is also subject to certain additional terms.
21 | You should have received a copy of these additional terms immediately following
22 | the terms and conditions of the GNU General Public License. If not, please
23 | request a copy in writing from id Software at the address below.
24 |
25 | If you have questions concerning this license or the applicable additional
26 | terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc.,
27 | Suite 120, Rockville, Maryland 20850 USA.
28 | ===========================================================================
29 | */
30 |
31 | /*****************************************************************************
32 | * name: ai_gen.c
33 | *
34 | * desc: genetic selection
35 | *
36 | * $Archive: /source/code/game/ai_gen.c $
37 | *
38 | *****************************************************************************/
39 |
40 | #include "g_local.h"
41 | #include "../botlib/botlib.h"
42 | #include "../botlib/be_aas.h"
43 | //
44 | #include "ai_char.h"
45 | #include "ai_chat_sys.h"
46 | #include "ai_ea.h"
47 | #include "ai_gen.h"
48 | #include "ai_goal.h"
49 | #include "ai_move.h"
50 | #include "ai_weap.h"
51 | #include "ai_weight.h"
52 | //
53 | #include "ai_main.h"
54 | #include "ai_dmq3.h"
55 | #include "ai_chat.h"
56 | #include "ai_cmd.h"
57 | #include "ai_vcmd.h"
58 | #include "ai_dmnet.h"
59 | #include "ai_team.h"
60 | //
61 | #include "chars.h" //characteristics
62 | #include "inv.h" //indexes into the inventory
63 | #include "syn.h" //synonyms
64 | #include "match.h" //string matching types and vars
65 |
66 | //===========================================================================
67 | //
68 | // Parameter: -
69 | // Returns: -
70 | // Changes Globals: -
71 | //===========================================================================
72 | int GeneticSelection(int numranks, float *rankings)
73 | {
74 | float sum;
75 | int i, index;
76 |
77 | sum = 0;
78 | for (i = 0; i < numranks; i++)
79 | {
80 | if (rankings[i] < 0) continue;
81 | sum += rankings[i];
82 | } //end for
83 | if (sum > 0)
84 | {
85 | //select a bot where the ones with the highest rankings have
86 | //the highest chance of being selected
87 | //sum *= random();
88 | for (i = 0; i < numranks; i++)
89 | {
90 | if (rankings[i] < 0) continue;
91 | sum -= rankings[i];
92 | if (sum <= 0) return i;
93 | } //end for
94 | } //end if
95 | //select a bot randomly
96 | index = random() * numranks;
97 | for (i = 0; i < numranks; i++)
98 | {
99 | if (rankings[index] >= 0) return index;
100 | index = (index + 1) % numranks;
101 | } //end for
102 | return 0;
103 | } //end of the function GeneticSelection
104 | //===========================================================================
105 | //
106 | // Parameter: -
107 | // Returns: -
108 | // Changes Globals: -
109 | //===========================================================================
110 | int GeneticParentsAndChildSelection(int numranks, float *ranks, int *parent1, int *parent2, int *child)
111 | {
112 | float rankings[256], max;
113 | int i;
114 |
115 | if (numranks > 256)
116 | {
117 | BotAI_Print(PRT_WARNING, "GeneticParentsAndChildSelection: too many bots\n");
118 | *parent1 = *parent2 = *child = 0;
119 | return qfalse;
120 | } //end if
121 | for (max = 0, i = 0; i < numranks; i++)
122 | {
123 | if (ranks[i] < 0) continue;
124 | max++;
125 | } //end for
126 | if (max < 3)
127 | {
128 | BotAI_Print(PRT_WARNING, "GeneticParentsAndChildSelection: too few valid bots\n");
129 | *parent1 = *parent2 = *child = 0;
130 | return qfalse;
131 | } //end if
132 | Com_Memcpy(rankings, ranks, sizeof(float) * numranks);
133 | //select first parent
134 | *parent1 = GeneticSelection(numranks, rankings);
135 | rankings[*parent1] = -1;
136 | //select second parent
137 | *parent2 = GeneticSelection(numranks, rankings);
138 | rankings[*parent2] = -1;
139 | //reverse the rankings
140 | max = 0;
141 | for (i = 0; i < numranks; i++)
142 | {
143 | if (rankings[i] < 0) continue;
144 | if (rankings[i] > max) max = rankings[i];
145 | } //end for
146 | for (i = 0; i < numranks; i++)
147 | {
148 | if (rankings[i] < 0) continue;
149 | rankings[i] = max - rankings[i];
150 | } //end for
151 | //select child
152 | *child = GeneticSelection(numranks, rankings);
153 | return qtrue;
154 | } //end of the function GeneticParentsAndChildSelection
155 |
--------------------------------------------------------------------------------
/code/game/ai_gen.h:
--------------------------------------------------------------------------------
1 | /*
2 | ===========================================================================
3 | Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
4 |
5 | This file is part of Spearmint Source Code.
6 |
7 | Spearmint Source Code is free software; you can redistribute it
8 | and/or modify it under the terms of the GNU General Public License as
9 | published by the Free Software Foundation; either version 3 of the License,
10 | or (at your option) any later version.
11 |
12 | Spearmint Source Code is distributed in the hope that it will be
13 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with Spearmint Source Code. If not, see .
19 |
20 | In addition, Spearmint Source Code is also subject to certain additional terms.
21 | You should have received a copy of these additional terms immediately following
22 | the terms and conditions of the GNU General Public License. If not, please
23 | request a copy in writing from id Software at the address below.
24 |
25 | If you have questions concerning this license or the applicable additional
26 | terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc.,
27 | Suite 120, Rockville, Maryland 20850 USA.
28 | ===========================================================================
29 | */
30 | //
31 |
32 | /*****************************************************************************
33 | * name: ai_gen.h
34 | *
35 | * desc: genetic selection
36 | *
37 | * $Archive: /source/code/game/ai_gen.h $
38 | *
39 | *****************************************************************************/
40 |
41 | int GeneticParentsAndChildSelection(int numranks, float *ranks, int *parent1, int *parent2, int *child);
42 |
--------------------------------------------------------------------------------
/code/game/ai_team.h:
--------------------------------------------------------------------------------
1 | /*
2 | ===========================================================================
3 | Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
4 |
5 | This file is part of Spearmint Source Code.
6 |
7 | Spearmint Source Code is free software; you can redistribute it
8 | and/or modify it under the terms of the GNU General Public License as
9 | published by the Free Software Foundation; either version 3 of the License,
10 | or (at your option) any later version.
11 |
12 | Spearmint Source Code is distributed in the hope that it will be
13 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with Spearmint Source Code. If not, see .
19 |
20 | In addition, Spearmint Source Code is also subject to certain additional terms.
21 | You should have received a copy of these additional terms immediately following
22 | the terms and conditions of the GNU General Public License. If not, please
23 | request a copy in writing from id Software at the address below.
24 |
25 | If you have questions concerning this license or the applicable additional
26 | terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc.,
27 | Suite 120, Rockville, Maryland 20850 USA.
28 | ===========================================================================
29 | */
30 | //
31 |
32 | /*****************************************************************************
33 | * name: ai_team.h
34 | *
35 | * desc: Quake3 bot AI
36 | *
37 | * $Archive: /source/code/game/ai_team.h $
38 | *
39 | *****************************************************************************/
40 |
41 | void BotTeamAI(bot_state_t *bs);
42 | int BotGetTeamMateTaskPreference(bot_state_t *bs, int teammate);
43 | void BotSetTeamMateTaskPreference(bot_state_t *bs, int teammate, int preference);
44 | void BotVoiceChat(bot_state_t *bs, int toPlayer, char *voicechat);
45 | void BotVoiceChatOnly(bot_state_t *bs, int toPlayer, char *voicechat);
46 |
47 |
48 |
--------------------------------------------------------------------------------
/code/game/ai_vcmd.h:
--------------------------------------------------------------------------------
1 | /*
2 | ===========================================================================
3 | Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
4 |
5 | This file is part of Spearmint Source Code.
6 |
7 | Spearmint Source Code is free software; you can redistribute it
8 | and/or modify it under the terms of the GNU General Public License as
9 | published by the Free Software Foundation; either version 3 of the License,
10 | or (at your option) any later version.
11 |
12 | Spearmint Source Code is distributed in the hope that it will be
13 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with Spearmint Source Code. If not, see .
19 |
20 | In addition, Spearmint Source Code is also subject to certain additional terms.
21 | You should have received a copy of these additional terms immediately following
22 | the terms and conditions of the GNU General Public License. If not, please
23 | request a copy in writing from id Software at the address below.
24 |
25 | If you have questions concerning this license or the applicable additional
26 | terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc.,
27 | Suite 120, Rockville, Maryland 20850 USA.
28 | ===========================================================================
29 | */
30 | //
31 |
32 | /*****************************************************************************
33 | * name: ai_vcmd.h
34 | *
35 | * desc: Quake3 bot AI
36 | *
37 | * $Archive: /source/code/game/ai_vcmd.c $
38 | *
39 | *****************************************************************************/
40 |
41 | int BotVoiceChatCommand(bot_state_t *bs, int mode, char *voicechat);
42 | void BotVoiceChat_Defend(bot_state_t *bs, int playerNum, int mode);
43 |
44 |
45 |
--------------------------------------------------------------------------------
/code/game/ai_weap.h:
--------------------------------------------------------------------------------
1 | /*
2 | ===========================================================================
3 | Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
4 |
5 | This file is part of Spearmint Source Code.
6 |
7 | Spearmint Source Code is free software; you can redistribute it
8 | and/or modify it under the terms of the GNU General Public License as
9 | published by the Free Software Foundation; either version 3 of the License,
10 | or (at your option) any later version.
11 |
12 | Spearmint Source Code is distributed in the hope that it will be
13 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with Spearmint Source Code. If not, see .
19 |
20 | In addition, Spearmint Source Code is also subject to certain additional terms.
21 | You should have received a copy of these additional terms immediately following
22 | the terms and conditions of the GNU General Public License. If not, please
23 | request a copy in writing from id Software at the address below.
24 |
25 | If you have questions concerning this license or the applicable additional
26 | terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc.,
27 | Suite 120, Rockville, Maryland 20850 USA.
28 | ===========================================================================
29 | */
30 | //
31 |
32 | /*****************************************************************************
33 | * name: ai_weap.h
34 | *
35 | * desc: weapon AI
36 | *
37 | * $Archive: /source/code/game/ai_weap.h $
38 | *
39 | *****************************************************************************/
40 |
41 | #ifndef TA_WEAPSYS // BOT_WEAP_WEIGHTS
42 | //projectile flags
43 | #define PFL_WINDOWDAMAGE 1 //projectile damages through window
44 | #define PFL_RETURN 2 //set when projectile returns to owner
45 | //weapon flags
46 | #define WFL_FIRERELEASED 1 //set when projectile is fired with key-up event
47 | //damage types
48 | #define DAMAGETYPE_IMPACT 1 //damage on impact
49 | #define DAMAGETYPE_RADIAL 2 //radial damage
50 | #define DAMAGETYPE_VISIBLE 4 //damage to all entities visible to the projectile
51 |
52 | typedef struct projectileinfo_s
53 | {
54 | char name[MAX_STRINGFIELD];
55 | char model[MAX_STRINGFIELD];
56 | int flags;
57 | float gravity;
58 | int damage;
59 | float radius;
60 | int visdamage;
61 | int damagetype;
62 | int healthinc;
63 | float push;
64 | float detonation;
65 | float bounce;
66 | float bouncefric;
67 | float bouncestop;
68 | } projectileinfo_t;
69 |
70 | typedef struct weaponinfo_s
71 | {
72 | int valid; //true if the weapon info is valid
73 | int number; //number of the weapon
74 | char name[MAX_STRINGFIELD];
75 | char model[MAX_STRINGFIELD];
76 | int level;
77 | int weaponindex;
78 | int flags;
79 | char projectile[MAX_STRINGFIELD];
80 | int numprojectiles;
81 | float hspread;
82 | float vspread;
83 | float speed;
84 | float acceleration;
85 | vec3_t recoil;
86 | vec3_t offset;
87 | vec3_t angleoffset;
88 | float extrazvelocity;
89 | int ammoamount;
90 | int ammoindex;
91 | float activate;
92 | float reload;
93 | float spinup;
94 | float spindown;
95 | projectileinfo_t proj; //pointer to the used projectile
96 | } weaponinfo_t;
97 |
98 | //weapon configuration: set of weapons with projectiles
99 | typedef struct weaponconfig_s
100 | {
101 | qboolean valid;
102 | int numweapons;
103 | int numprojectiles;
104 | projectileinfo_t projectileinfo[MAX_WEAPONS];
105 | weaponinfo_t weaponinfo[MAX_WEAPONS];
106 | } weaponconfig_t;
107 |
108 | //the bot weapon state
109 | typedef struct bot_weaponstate_s
110 | {
111 | struct weightconfig_s *weaponweightconfig; //weapon weight configuration
112 | int weaponweightindex[MAX_WEAPONS]; //weapon weight index
113 | } bot_weaponstate_t;
114 |
115 | //setup the weapon AI
116 | int BotSetupWeaponAI(void);
117 | //shut down the weapon AI
118 | void BotShutdownWeaponAI(void);
119 | //returns the best weapon to fight with
120 | int BotChooseBestFightWeapon(int weaponstate, int *inventory);
121 | //returns the information of the current weapon
122 | void BotGetWeaponInfo(int weaponstate, int weapon, weaponinfo_t *weaponinfo);
123 | //loads the weapon weights
124 | int BotLoadWeaponWeights(int weaponstate, char *filename);
125 | //frees the weapon state
126 | void BotFreeWeaponState(int weaponstate);
127 | //resets the whole weapon state
128 | void BotResetWeaponState(int weaponstate);
129 | //returns handle to weapon state for playerNum
130 | #define BotAllocWeaponState(playerNum) (playerNum+1)
131 | #endif // !TA_WEAPSYS
132 |
--------------------------------------------------------------------------------
/code/game/ai_weight.h:
--------------------------------------------------------------------------------
1 | /*
2 | ===========================================================================
3 | Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
4 |
5 | This file is part of Spearmint Source Code.
6 |
7 | Spearmint Source Code is free software; you can redistribute it
8 | and/or modify it under the terms of the GNU General Public License as
9 | published by the Free Software Foundation; either version 3 of the License,
10 | or (at your option) any later version.
11 |
12 | Spearmint Source Code is distributed in the hope that it will be
13 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with Spearmint Source Code. If not, see .
19 |
20 | In addition, Spearmint Source Code is also subject to certain additional terms.
21 | You should have received a copy of these additional terms immediately following
22 | the terms and conditions of the GNU General Public License. If not, please
23 | request a copy in writing from id Software at the address below.
24 |
25 | If you have questions concerning this license or the applicable additional
26 | terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc.,
27 | Suite 120, Rockville, Maryland 20850 USA.
28 | ===========================================================================
29 | */
30 |
31 | /*****************************************************************************
32 | * name: ai_weight.h
33 | *
34 | * desc: fuzzy weights
35 | *
36 | * $Archive: /source/code/game/ai_weight.h $
37 | *
38 | *****************************************************************************/
39 |
40 | #define MAX_INVENTORYVALUE 999999
41 |
42 | #define WT_BALANCE 1
43 | #define MAX_WEIGHTS 128
44 |
45 | //fuzzy seperator
46 | typedef struct fuzzyseperator_s
47 | {
48 | int index;
49 | int value;
50 | int type;
51 | float weight;
52 | float minweight;
53 | float maxweight;
54 | struct fuzzyseperator_s *child;
55 | struct fuzzyseperator_s *next;
56 | } fuzzyseperator_t;
57 |
58 | //fuzzy weight
59 | typedef struct weight_s
60 | {
61 | char *name;
62 | struct fuzzyseperator_s *firstseperator;
63 | } weight_t;
64 |
65 | //weight configuration
66 | typedef struct weightconfig_s
67 | {
68 | int numweights;
69 | weight_t weights[MAX_WEIGHTS];
70 | char filename[MAX_QPATH];
71 | } weightconfig_t;
72 |
73 | //reads a weight configuration
74 | weightconfig_t *ReadWeightConfig(char *filename);
75 | //free a weight configuration
76 | void FreeWeightConfig(weightconfig_t *config);
77 | //writes a weight configuration, returns true if successful
78 | qboolean WriteWeightConfig(char *filename, weightconfig_t *config);
79 | //find the fuzzy weight with the given name
80 | int FindFuzzyWeight(weightconfig_t *wc, const char *name);
81 | //returns the fuzzy weight for the given inventory and weight
82 | float FuzzyWeight(int *inventory, weightconfig_t *wc, int weightnum);
83 | float FuzzyWeightUndecided(int *inventory, weightconfig_t *wc, int weightnum);
84 | //scales the weight with the given name
85 | void ScaleWeight(weightconfig_t *config, char *name, float scale);
86 | //scale the balance range
87 | void ScaleBalanceRange(weightconfig_t *config, float scale);
88 | //evolves the weight configuration
89 | void EvolveWeightConfig(weightconfig_t *config);
90 | //interbreed the weight configurations and stores the interbreeded one in configout
91 | void InterbreedWeightConfigs(weightconfig_t *config1, weightconfig_t *config2, weightconfig_t *configout);
92 | //frees cached weight configurations
93 | void BotShutdownWeights(void);
94 |
--------------------------------------------------------------------------------
/code/game/bg_local.h:
--------------------------------------------------------------------------------
1 | /*
2 | ===========================================================================
3 | Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
4 |
5 | This file is part of Spearmint Source Code.
6 |
7 | Spearmint Source Code is free software; you can redistribute it
8 | and/or modify it under the terms of the GNU General Public License as
9 | published by the Free Software Foundation; either version 3 of the License,
10 | or (at your option) any later version.
11 |
12 | Spearmint Source Code is distributed in the hope that it will be
13 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with Spearmint Source Code. If not, see .
19 |
20 | In addition, Spearmint Source Code is also subject to certain additional terms.
21 | You should have received a copy of these additional terms immediately following
22 | the terms and conditions of the GNU General Public License. If not, please
23 | request a copy in writing from id Software at the address below.
24 |
25 | If you have questions concerning this license or the applicable additional
26 | terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc.,
27 | Suite 120, Rockville, Maryland 20850 USA.
28 | ===========================================================================
29 | */
30 | //
31 | // bg_local.h -- local definitions for the bg (both games) files
32 |
33 | #define MIN_WALK_NORMAL 0.7f // can't walk on very steep slopes
34 |
35 | #define JUMP_VELOCITY 270
36 |
37 | #if 1 // #ifndef TA_PLAYERSYS // PLAYERCFG_ANIMATION_TIMES // Doesn't work correctly?
38 | #define TIMER_LAND 130
39 | #endif
40 | #ifndef TA_PLAYERSYS // PLAYERCFG_ANIMATION_TIMES
41 | #define TIMER_GESTURE (34*66+50)
42 | #endif
43 |
44 | #define OVERCLIP 1.001f
45 |
46 | // all of the locals will be zeroed before each
47 | // pmove, just to make damn sure we don't have
48 | // any differences when running on client or server
49 | typedef struct {
50 | vec3_t forward, right, up;
51 | float frametime;
52 |
53 | int msec;
54 |
55 | qboolean walking;
56 | qboolean groundPlane;
57 | trace_t groundTrace;
58 | #ifdef IOQ3ZTM // LADDER
59 | qboolean ladder; // We'll use this to tell when the player is on a ladder
60 | #endif
61 |
62 | float impactSpeed;
63 |
64 | vec3_t previous_origin;
65 | vec3_t previous_velocity;
66 | int previous_waterlevel;
67 | } pml_t;
68 |
69 | extern pmove_t *pm;
70 | extern pml_t pml;
71 |
72 | // movement parameters
73 | extern float pm_stopspeed;
74 | extern float pm_duckScale;
75 | extern float pm_swimScale;
76 |
77 | extern float pm_accelerate;
78 | extern float pm_airaccelerate;
79 | extern float pm_wateraccelerate;
80 | extern float pm_flyaccelerate;
81 |
82 | extern float pm_friction;
83 | extern float pm_waterfriction;
84 | extern float pm_flightfriction;
85 |
86 | extern int c_pmove;
87 |
88 | void PM_ClipVelocity( vec3_t in, vec3_t normal, vec3_t out, float overbounce );
89 | void PM_AddTouchEnt( int entityNum );
90 | void PM_AddEvent( int newEvent );
91 |
92 | qboolean PM_SlideMove( qboolean gravity );
93 | void PM_StepSlideMove( qboolean gravity );
94 |
95 |
96 |
--------------------------------------------------------------------------------
/code/game/bg_syscalls.asm:
--------------------------------------------------------------------------------
1 | ; QVM-only system calls for game and cgame
2 | code
3 |
4 | equ memset -1
5 | equ memcpy -2
6 | equ strncpy -3
7 | equ sin -4
8 | equ cos -5
9 | equ atan2 -6
10 | equ sqrt -7
11 | equ floor -8
12 | equ ceil -9
13 | equ Q_acos -10
14 | equ Q_asin -11
15 | equ tan -12
16 | equ atan -13
17 | equ pow -14
18 | equ exp -15
19 | equ log -16
20 | equ log10 -17
21 | equ syscall -18
22 |
23 |
--------------------------------------------------------------------------------
/code/game/match.h:
--------------------------------------------------------------------------------
1 | /*
2 | ===========================================================================
3 | Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
4 |
5 | This file is part of Spearmint Source Code.
6 |
7 | Spearmint Source Code is free software; you can redistribute it
8 | and/or modify it under the terms of the GNU General Public License as
9 | published by the Free Software Foundation; either version 3 of the License,
10 | or (at your option) any later version.
11 |
12 | Spearmint Source Code is distributed in the hope that it will be
13 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with Spearmint Source Code. If not, see .
19 |
20 | In addition, Spearmint Source Code is also subject to certain additional terms.
21 | You should have received a copy of these additional terms immediately following
22 | the terms and conditions of the GNU General Public License. If not, please
23 | request a copy in writing from id Software at the address below.
24 |
25 | If you have questions concerning this license or the applicable additional
26 | terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc.,
27 | Suite 120, Rockville, Maryland 20850 USA.
28 | ===========================================================================
29 | */
30 |
31 | // make sure this is the same character as we use in chats in g_cmd.c
32 | #define EC "\x19"
33 |
34 | //match template contexts
35 | #define MTCONTEXT_MISC 2
36 | #define MTCONTEXT_INITIALTEAMCHAT 4
37 | #define MTCONTEXT_TIME 8
38 | #define MTCONTEXT_TEAMMATE 16
39 | #define MTCONTEXT_ADDRESSEE 32
40 | #define MTCONTEXT_PATROLKEYAREA 64
41 | #define MTCONTEXT_REPLYCHAT 128
42 | #define MTCONTEXT_CTF 256
43 |
44 | //message types
45 | #define MSG_NEWLEADER 1 //new leader
46 | #define MSG_ENTERGAME 2 //enter game message
47 | #define MSG_HELP 3 //help someone
48 | #define MSG_ACCOMPANY 4 //accompany someone
49 | #define MSG_DEFENDKEYAREA 5 //defend a key area
50 | #define MSG_RUSHBASE 6 //everyone rush to base
51 | #define MSG_GETFLAG 7 //get the enemy flag
52 | #define MSG_STARTTEAMLEADERSHIP 8 //someone wants to become the team leader
53 | #define MSG_STOPTEAMLEADERSHIP 9 //someone wants to stop being the team leader
54 | #define MSG_WHOISTEAMLAEDER 10 //who is the team leader
55 | #define MSG_WAIT 11 //wait for someone
56 | #define MSG_WHATAREYOUDOING 12 //what are you doing?
57 | #define MSG_JOINSUBTEAM 13 //join a sub-team
58 | #define MSG_LEAVESUBTEAM 14 //leave a sub-team
59 | #define MSG_CREATENEWFORMATION 15 //create a new formation
60 | #define MSG_FORMATIONPOSITION 16 //tell someone his/her position in a formation
61 | #define MSG_FORMATIONSPACE 17 //set the formation intervening space
62 | #define MSG_DOFORMATION 18 //form a known formation
63 | #define MSG_DISMISS 19 //dismiss commanded team mates
64 | #define MSG_CAMP 20 //camp somewhere
65 | #define MSG_CHECKPOINT 21 //remember a check point
66 | #define MSG_PATROL 22 //patrol between certain keypoints
67 | #define MSG_LEADTHEWAY 23 //lead the way
68 | #define MSG_GETITEM 24 //get an item
69 | #define MSG_KILL 25 //kill someone
70 | #define MSG_WHEREAREYOU 26 //where is someone
71 | #define MSG_RETURNFLAG 27 //return the flag
72 | #define MSG_WHATISMYCOMMAND 28 //ask the team leader what to do
73 | #define MSG_WHICHTEAM 29 //ask which team a bot is in
74 | #define MSG_TASKPREFERENCE 30 //tell your teamplay task preference
75 | #define MSG_ATTACKENEMYBASE 31 //attack the enemy base
76 | #ifdef MISSIONPACK_HARVESTER
77 | #define MSG_HARVEST 32 //go harvest
78 | #endif
79 | #define MSG_SUICIDE 33 //order to suicide
80 | //
81 | #define MSG_ME 100
82 | #define MSG_EVERYONE 101
83 | #define MSG_MULTIPLENAMES 102
84 | #define MSG_NAME 103
85 | #define MSG_PATROLKEYAREA 104
86 | #define MSG_MINUTES 105
87 | #define MSG_SECONDS 106
88 | #define MSG_FOREVER 107
89 | #define MSG_FORALONGTIME 108
90 | #define MSG_FORAWHILE 109
91 | //
92 | #define MSG_CHATALL 200
93 | #define MSG_CHATTEAM 201
94 | #define MSG_CHATTELL 202
95 | //
96 | #define MSG_CTF 300 //ctf message
97 |
98 | //command sub types
99 | #define ST_SOMEWHERE 0
100 | #define ST_NEARITEM 1
101 | #define ST_ADDRESSED 2
102 | #define ST_METER 4
103 | #define ST_FEET 8
104 | #define ST_TIME 16
105 | #define ST_HERE 32
106 | #define ST_THERE 64
107 | #define ST_I 128
108 | #define ST_MORE 256
109 | #define ST_BACK 512
110 | #define ST_REVERSE 1024
111 | #define ST_SOMEONE 2048
112 | #define ST_GOTFLAG 4096
113 | #define ST_CAPTUREDFLAG 8192
114 | #define ST_RETURNEDFLAG 16384
115 | #define ST_TEAM 32768
116 | #define ST_1FCTFGOTFLAG 65535
117 | //ctf task preferences
118 | #define ST_DEFENDER 1
119 | #define ST_ATTACKER 2
120 | #define ST_ROAMER 4
121 |
122 |
123 | //word replacement variables
124 | #define THE_ENEMY 7
125 | #define THE_TEAM 7
126 | //team message variables
127 | #define NETNAME 0
128 | #define PLACE 1
129 | #define FLAG 1
130 | #define MESSAGE 2
131 | #define ADDRESSEE 2
132 | #define ITEM 3
133 | #define TEAMMATE 4
134 | #define TEAMNAME 4
135 | #define ENEMY 4
136 | #define KEYAREA 5
137 | #define FORMATION 5
138 | #define POSITION 5
139 | #define NUMBER 5
140 | #define TIME 6
141 | #define NAME 6
142 | #define MORE 6
143 |
144 |
145 |
--------------------------------------------------------------------------------
/code/game/syn.h:
--------------------------------------------------------------------------------
1 | /*
2 | ===========================================================================
3 | Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
4 |
5 | This file is part of Spearmint Source Code.
6 |
7 | Spearmint Source Code is free software; you can redistribute it
8 | and/or modify it under the terms of the GNU General Public License as
9 | published by the Free Software Foundation; either version 3 of the License,
10 | or (at your option) any later version.
11 |
12 | Spearmint Source Code is distributed in the hope that it will be
13 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with Spearmint Source Code. If not, see .
19 |
20 | In addition, Spearmint Source Code is also subject to certain additional terms.
21 | You should have received a copy of these additional terms immediately following
22 | the terms and conditions of the GNU General Public License. If not, please
23 | request a copy in writing from id Software at the address below.
24 |
25 | If you have questions concerning this license or the applicable additional
26 | terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc.,
27 | Suite 120, Rockville, Maryland 20850 USA.
28 | ===========================================================================
29 | */
30 |
31 | #define CONTEXT_ALL 0xFFFFFFFF
32 | #define CONTEXT_NORMAL 1
33 | #define CONTEXT_NEARBYITEM 2
34 | #define CONTEXT_CTFREDTEAM 4
35 | #define CONTEXT_CTFBLUETEAM 8
36 | #define CONTEXT_REPLY 16
37 | #define CONTEXT_OBELISKREDTEAM 32
38 | #define CONTEXT_OBELISKBLUETEAM 64
39 | #ifdef MISSIONPACK_HARVESTER
40 | #define CONTEXT_HARVESTERREDTEAM 128
41 | #define CONTEXT_HARVESTERBLUETEAM 256
42 | #endif
43 |
44 | #define CONTEXT_NAMES 1024
45 |
--------------------------------------------------------------------------------
/code/q3_ui/ui_mfield.c:
--------------------------------------------------------------------------------
1 | /*
2 | ===========================================================================
3 | Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
4 |
5 | This file is part of Spearmint Source Code.
6 |
7 | Spearmint Source Code is free software; you can redistribute it
8 | and/or modify it under the terms of the GNU General Public License as
9 | published by the Free Software Foundation; either version 3 of the License,
10 | or (at your option) any later version.
11 |
12 | Spearmint Source Code is distributed in the hope that it will be
13 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with Spearmint Source Code. If not, see .
19 |
20 | In addition, Spearmint Source Code is also subject to certain additional terms.
21 | You should have received a copy of these additional terms immediately following
22 | the terms and conditions of the GNU General Public License. If not, please
23 | request a copy in writing from id Software at the address below.
24 |
25 | If you have questions concerning this license or the applicable additional
26 | terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc.,
27 | Suite 120, Rockville, Maryland 20850 USA.
28 | ===========================================================================
29 | */
30 | //
31 | #include "ui_local.h"
32 |
33 | /*
34 | ==================
35 | MenuField_Init
36 | ==================
37 | */
38 | void MenuField_Init( menufield_s* m ) {
39 | int l;
40 | int w;
41 | int h;
42 | int style;
43 |
44 | MField_Clear( &m->field );
45 |
46 | if (m->generic.flags & QMF_SMALLFONT)
47 | {
48 | w = SMALLCHAR_WIDTH;
49 | h = SMALLCHAR_HEIGHT;
50 | style = UI_SMALLFONT;
51 | }
52 | else
53 | {
54 | w = BIGCHAR_WIDTH;
55 | h = BIGCHAR_HEIGHT;
56 | style = UI_BIGFONT;
57 | }
58 |
59 | l = UI_DrawStrlen( m->generic.name, style ) + w;
60 |
61 | #ifdef IOQ3ZTM
62 | if (m->generic.flags & QMF_LEFT_JUSTIFY) {
63 | m->generic.left = m->generic.x;
64 | m->generic.x += l;
65 | } else
66 | #endif
67 | m->generic.left = m->generic.x - l;
68 | m->generic.top = m->generic.y;
69 | m->generic.right = m->generic.x + w + m->field.widthInChars*w;
70 | m->generic.bottom = m->generic.y + h;
71 | }
72 |
73 | /*
74 | ==================
75 | MenuField_Draw
76 | ==================
77 | */
78 | void MenuField_Draw( menufield_s *f )
79 | {
80 | int x;
81 | int y;
82 | int w;
83 | int style;
84 | qboolean focus;
85 | float *color;
86 |
87 | x = f->generic.x;
88 | y = f->generic.y;
89 |
90 | if (f->generic.flags & QMF_SMALLFONT)
91 | {
92 | w = SMALLCHAR_WIDTH;
93 | style = UI_SMALLFONT;
94 | }
95 | else
96 | {
97 | w = BIGCHAR_WIDTH;
98 | style = UI_BIGFONT;
99 | }
100 |
101 | if (Menu_ItemAtCursor( f->generic.parent ) == f) {
102 | focus = qtrue;
103 | style |= UI_PULSE;
104 | }
105 | else {
106 | focus = qfalse;
107 | }
108 |
109 | if (f->generic.flags & QMF_GRAYED)
110 | color = text_color_disabled;
111 | else if (focus)
112 | color = text_color_highlight;
113 | else
114 | color = text_color_normal;
115 |
116 | if ( focus )
117 | {
118 | // draw cursor
119 | CG_FillRect( f->generic.left, f->generic.top, f->generic.right-f->generic.left+1, f->generic.bottom-f->generic.top+1, listbar_color );
120 | UI_DrawChar( x, y, GLYPH_ARROW, UI_CENTER|UI_BLINK|style, color);
121 | }
122 |
123 | if ( f->generic.name ) {
124 | UI_DrawString( x - w, y, f->generic.name, style|UI_RIGHT, color );
125 | }
126 |
127 | UI_MField_Draw( &f->field, x + w, y, style, color, focus );
128 | }
129 |
130 | /*
131 | ==================
132 | MenuField_Key
133 | ==================
134 | */
135 | sfxHandle_t MenuField_Key( menufield_s* m, int* key )
136 | {
137 | int keycode;
138 |
139 | keycode = *key;
140 |
141 | switch ( keycode )
142 | {
143 | case K_KP_ENTER:
144 | case K_ENTER:
145 | case K_JOY_A:
146 | case K_2JOY_A:
147 | case K_3JOY_A:
148 | case K_4JOY_A:
149 | // have enter go to next cursor point
150 | *key = K_TAB;
151 | break;
152 |
153 | case K_TAB:
154 | case K_KP_DOWNARROW:
155 | case K_DOWNARROW:
156 | case K_KP_UPARROW:
157 | case K_UPARROW:
158 | break;
159 |
160 | default:
161 | if ( keycode & K_CHAR_FLAG )
162 | {
163 | keycode &= ~K_CHAR_FLAG;
164 |
165 | if ((m->generic.flags & QMF_UPPERCASE) && Q_islower( keycode ))
166 | keycode -= 'a' - 'A';
167 | else if ((m->generic.flags & QMF_LOWERCASE) && Q_isupper( keycode ))
168 | keycode -= 'A' - 'a';
169 | else if ((m->generic.flags & QMF_NUMBERSONLY) && Q_isalpha( keycode ))
170 | return (menu_buzz_sound);
171 |
172 | MField_CharEvent( &m->field, keycode);
173 | }
174 | else
175 | MField_KeyDownEvent( &m->field, keycode );
176 | break;
177 | }
178 |
179 | return (0);
180 | }
181 |
182 |
183 |
--------------------------------------------------------------------------------
/code/qcommon/q_unicode.h:
--------------------------------------------------------------------------------
1 | /*
2 | ===========================================================================
3 | Copyright (C) 2012-2013 Unvanquished Developers
4 |
5 | This file is part of Spearmint Source Code.
6 |
7 | Spearmint Source Code is free software; you can redistribute it
8 | and/or modify it under the terms of the GNU General Public License as
9 | published by the Free Software Foundation; either version 3 of the License,
10 | or (at your option) any later version.
11 |
12 | Spearmint Source Code is distributed in the hope that it will be
13 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with Spearmint Source Code. If not, see .
19 |
20 | In addition, Spearmint Source Code is also subject to certain additional terms.
21 | You should have received a copy of these additional terms immediately following
22 | the terms and conditions of the GNU General Public License. If not, please
23 | request a copy in writing from id Software at the address below.
24 |
25 | If you have questions concerning this license or the applicable additional
26 | terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc.,
27 | Suite 120, Rockville, Maryland 20850 USA.
28 | ===========================================================================
29 | */
30 |
31 | #ifndef Q_UNICODE_H_
32 | #define Q_UNICODE_H_
33 |
34 | int Q_UTF8_Width( const char *str );
35 | int Q_UTF8_WidthCP( int ch );
36 | int Q_UTF8_Strlen( const char *str );
37 | int Q_UTF8_PrintStrlen( const char *str );
38 | qboolean Q_UTF8_ContByte( char c );
39 | unsigned long Q_UTF8_CodePoint( const char **str );
40 | char *Q_UTF8_Encode( unsigned long codepoint );
41 | int Q_UTF8_Store( const char *s );
42 | char *Q_UTF8_Unstore( int e );
43 |
44 | qboolean Q_Unicode_IsAlpha( int ch );
45 | qboolean Q_Unicode_IsUpper( int ch );
46 | qboolean Q_Unicode_IsLower( int ch );
47 | qboolean Q_Unicode_IsIdeo( int ch );
48 | qboolean Q_Unicode_IsAlphaOrIdeo( int ch );
49 | qboolean Q_Unicode_IsAlphaOrIdeoOrDigit( int ch );
50 |
51 | int Q_Unicode_ToUpper( int ch );
52 | int Q_Unicode_ToLower( int ch );
53 |
54 | #endif /* Q_UNICODE_H_ */
55 |
--------------------------------------------------------------------------------
/code/qcommon/surfaceflags.h:
--------------------------------------------------------------------------------
1 | /*
2 | ===========================================================================
3 | Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
4 |
5 | This file is part of Spearmint Source Code.
6 |
7 | Spearmint Source Code is free software; you can redistribute it
8 | and/or modify it under the terms of the GNU General Public License as
9 | published by the Free Software Foundation; either version 3 of the License,
10 | or (at your option) any later version.
11 |
12 | Spearmint Source Code is distributed in the hope that it will be
13 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with Spearmint Source Code. If not, see .
19 |
20 | In addition, Spearmint Source Code is also subject to certain additional terms.
21 | You should have received a copy of these additional terms immediately following
22 | the terms and conditions of the GNU General Public License. If not, please
23 | request a copy in writing from id Software at the address below.
24 |
25 | If you have questions concerning this license or the applicable additional
26 | terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc.,
27 | Suite 120, Rockville, Maryland 20850 USA.
28 | ===========================================================================
29 | */
30 | //
31 | // This file must be identical in the quake and utils directories
32 |
33 | // contents flags are separate bits
34 | // a given brush can contribute multiple content bits
35 |
36 | // these definitions also need to be in q_shared.h!
37 |
38 | #define CONTENTS_SOLID 1 // an eye is never valid in a solid
39 | #define CONTENTS_LAVA 8
40 | #define CONTENTS_SLIME 16
41 | #define CONTENTS_WATER 32
42 | #define CONTENTS_FOG 64
43 |
44 | #define CONTENTS_NOTTEAM1 0x0080
45 | #define CONTENTS_NOTTEAM2 0x0100
46 | #define CONTENTS_NOBOTCLIP 0x0200
47 |
48 | #ifdef TA_WEAPSYS // XREAL
49 | // ZTM: Used for shootable projectiles.
50 | #define CONTENTS_SHOOTABLE 0x0400 // Tr3B: used for game entities that can be destroyed like railgun spheres
51 | #endif
52 |
53 | #define CONTENTS_AREAPORTAL 0x8000
54 |
55 | #define CONTENTS_PLAYERCLIP 0x10000
56 | #define CONTENTS_MONSTERCLIP 0x20000
57 | //bot specific contents types
58 | #define CONTENTS_TELEPORTER 0x40000
59 | #define CONTENTS_JUMPPAD 0x80000
60 | #define CONTENTS_CLUSTERPORTAL 0x100000
61 | #define CONTENTS_DONOTENTER 0x200000
62 | #define CONTENTS_BOTCLIP 0x400000
63 | #define CONTENTS_MOVER 0x800000
64 |
65 | #define CONTENTS_ORIGIN 0x1000000 // removed before bsping an entity
66 |
67 | #define CONTENTS_BODY 0x2000000 // should never be on a brush, only in game
68 | #define CONTENTS_CORPSE 0x4000000
69 | #define CONTENTS_DETAIL 0x8000000 // brushes not used for the bsp
70 | #define CONTENTS_STRUCTURAL 0x10000000 // brushes used for the bsp
71 | #define CONTENTS_TRANSLUCENT 0x20000000 // don't consume surface fragments inside
72 | #define CONTENTS_TRIGGER 0x40000000
73 | #define CONTENTS_NODROP 0x80000000 // don't leave bodies or items (death fog, lava)
74 |
75 | #define CONTENTS_LADDER CONTENTS_ORIGIN // used by BSPC internally
76 |
77 | #define SURF_NODAMAGE 0x1 // never give falling damage
78 | #define SURF_SLICK 0x2 // effects game physics
79 | #define SURF_SKY 0x4 // lighting from environment map
80 | #define SURF_LADDER 0x8
81 | #define SURF_NOIMPACT 0x10 // don't make missile explosions
82 | #define SURF_NOMARKS 0x20 // don't leave missile marks
83 | #define SURF_FLESH 0x40 // make flesh sounds and effects
84 | #define SURF_NODRAW 0x80 // don't generate a drawsurface at all
85 | #define SURF_HINT 0x100 // make a primary bsp splitter
86 | #define SURF_SKIP 0x200 // completely ignore, allowing non-closed brushes
87 | #define SURF_NOLIGHTMAP 0x400 // surface doesn't need a lightmap
88 | #define SURF_POINTLIGHT 0x800 // generate lighting info at vertexes
89 | #define SURF_METALSTEPS 0x1000 // clanking footsteps
90 | #define SURF_NOSTEPS 0x2000 // no footstep sounds
91 | #define SURF_NONSOLID 0x4000 // don't collide against curves with this set
92 | #define SURF_LIGHTFILTER 0x8000 // act as a light filter during q3map -light
93 | #define SURF_ALPHASHADOW 0x10000 // do per-pixel light shadow casting in q3map
94 | #define SURF_NODLIGHT 0x20000 // don't dlight even if solid (solid lava, skies)
95 | #define SURF_DUST 0x40000 // leave a dust trail when walking on this surface
96 |
97 | #ifdef TA_MISC // MATERIALS
98 | #if ( defined GAME || defined CGAME )
99 | // MT_DIRT
100 | #define SURF_DIRT 0x80000
101 | #define SURF_GRASS 0x100000
102 | #define SURF_WOOD 0x200000
103 | #define SURF_STONE 0x400000
104 | #define SURF_SPARKS 0x800000
105 | #define SURF_GLASS 0x1000000
106 | #define SURF_METAL 0x2000000
107 | #endif
108 | #endif
109 |
--------------------------------------------------------------------------------
/code/tools/asm/README.Id:
--------------------------------------------------------------------------------
1 | 2002-10-25 Timothee Besset
2 | If you are looking for a faster version of the q3asm tool, try:
3 | http://www.icculus.org/~phaethon/q3/q3asm-turbo/q3asm-turbo.html
4 |
5 | 2001-10-31 Timothee Besset
6 | updated from the $/source/q3asm code
7 | modified for portability and use with >= 1.31 mod source release
8 |
9 | the cmdlib.c cmdlib.h mathlib.h qfiles.h have been copied from
10 | $/source/common
11 |
--------------------------------------------------------------------------------
/code/tools/asm/cmdlib.h:
--------------------------------------------------------------------------------
1 | /*
2 | ===========================================================================
3 | Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
4 |
5 | This file is part of Spearmint Source Code.
6 |
7 | Spearmint Source Code is free software; you can redistribute it
8 | and/or modify it under the terms of the GNU General Public License as
9 | published by the Free Software Foundation; either version 3 of the License,
10 | or (at your option) any later version.
11 |
12 | Spearmint Source Code is distributed in the hope that it will be
13 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with Spearmint Source Code. If not, see .
19 |
20 | In addition, Spearmint Source Code is also subject to certain additional terms.
21 | You should have received a copy of these additional terms immediately following
22 | the terms and conditions of the GNU General Public License. If not, please
23 | request a copy in writing from id Software at the address below.
24 |
25 | If you have questions concerning this license or the applicable additional
26 | terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc.,
27 | Suite 120, Rockville, Maryland 20850 USA.
28 | ===========================================================================
29 | */
30 | // cmdlib.h
31 |
32 | #ifndef __CMDLIB__
33 | #define __CMDLIB__
34 |
35 | #ifdef _MSC_VER
36 | #pragma warning(disable : 4244) // MIPS
37 | #pragma warning(disable : 4136) // X86
38 | #pragma warning(disable : 4051) // ALPHA
39 |
40 | #pragma warning(disable : 4018) // signed/unsigned mismatch
41 | #pragma warning(disable : 4305) // truncate from double to float
42 |
43 | #pragma check_stack(off)
44 |
45 | #endif
46 |
47 | #include
48 | #include
49 | #include
50 | #include
51 | #include
52 | #include
53 | #include
54 |
55 | #ifdef _MSC_VER
56 |
57 | #pragma intrinsic( memset, memcpy )
58 |
59 | #endif
60 |
61 | #ifndef __BYTEBOOL__
62 | #define __BYTEBOOL__
63 | typedef enum { qfalse, qtrue } qboolean;
64 | typedef unsigned char byte;
65 | #endif
66 |
67 | #define MAX_OS_PATH 1024
68 | #define MEM_BLOCKSIZE 4096
69 |
70 | // the dec offsetof macro doesn't work very well...
71 | #define myoffsetof(type,identifier) ((size_t)&((type *)0)->identifier)
72 |
73 |
74 | // set these before calling CheckParm
75 | extern int myargc;
76 | extern char **myargv;
77 |
78 | char *strupr (char *in);
79 | char *strlower (char *in);
80 | int Q_strncasecmp( const char *s1, const char *s2, int n );
81 | int Q_stricmp( const char *s1, const char *s2 );
82 | void Q_getwd( char *out );
83 |
84 | int Q_filelength (FILE *f);
85 | int FileTime( const char *path );
86 |
87 | void Q_mkdir( const char *path );
88 |
89 | extern char qdir[1024];
90 | extern char gamedir[1024];
91 | extern char writedir[1024];
92 | void SetQdirFromPath( const char *path );
93 | char *ExpandArg( const char *path ); // from cmd line
94 | char *ExpandPath( const char *path ); // from scripts
95 | char *ExpandGamePath (const char *path);
96 | char *ExpandPathAndArchive( const char *path );
97 |
98 |
99 | double I_FloatTime( void );
100 |
101 | void Error( const char *error, ... );
102 | int CheckParm( const char *check );
103 |
104 | FILE *SafeOpenWrite( const char *filename );
105 | FILE *SafeOpenRead( const char *filename );
106 | void SafeRead (FILE *f, void *buffer, int count);
107 | void SafeWrite (FILE *f, const void *buffer, int count);
108 |
109 | int LoadFile( const char *filename, void **bufferptr );
110 | int LoadFileBlock( const char *filename, void **bufferptr );
111 | int TryLoadFile( const char *filename, void **bufferptr );
112 | void SaveFile( const char *filename, const void *buffer, int count );
113 | qboolean FileExists( const char *filename );
114 |
115 | void DefaultExtension( char *path, const char *extension );
116 | void DefaultPath( char *path, const char *basepath );
117 | void StripFilename( char *path );
118 | void StripExtension( char *path );
119 |
120 | void ExtractFilePath( const char *path, char *dest );
121 | void ExtractFileBase( const char *path, char *dest );
122 | void ExtractFileExtension( const char *path, char *dest );
123 |
124 | int ParseNum (const char *str);
125 |
126 | char *COM_Parse (char *data);
127 |
128 | extern char com_token[1024];
129 | extern qboolean com_eof;
130 |
131 | char *copystring(const char *s);
132 |
133 |
134 | void CRC_Init(unsigned short *crcvalue);
135 | void CRC_ProcessByte(unsigned short *crcvalue, byte data);
136 | unsigned short CRC_Value(unsigned short crcvalue);
137 |
138 | void CreatePath( const char *path );
139 | void QCopyFile( const char *from, const char *to );
140 |
141 | extern qboolean archive;
142 | extern char archivedir[1024];
143 |
144 |
145 | extern qboolean verbose;
146 | void qprintf( const char *format, ... );
147 | void _printf( const char *format, ... );
148 |
149 | void ExpandWildcards( int *argc, char ***argv );
150 |
151 |
152 | // for compression routines
153 | typedef struct
154 | {
155 | void *data;
156 | int count, width, height;
157 | } cblock_t;
158 |
159 |
160 | #endif
161 |
--------------------------------------------------------------------------------
/code/tools/asm/lib.txt:
--------------------------------------------------------------------------------
1 |
2 | strlen
3 | strcasecmp
4 | tolower
5 | strcat
6 | strncpy
7 | strcmp
8 | strcpy
9 | strchr
10 |
11 | vsprintf
12 |
13 | memcpy
14 | memset
15 | rand
16 |
17 | atoi
18 | atof
19 |
20 | abs
21 |
22 | floor
23 | fabs
24 | tan
25 | atan
26 | sqrt
27 | log
28 | cos
29 | sin
30 | atan2
31 |
32 |
--------------------------------------------------------------------------------
/code/tools/asm/mathlib.h:
--------------------------------------------------------------------------------
1 | /*
2 | ===========================================================================
3 | Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
4 |
5 | This file is part of Spearmint Source Code.
6 |
7 | Spearmint Source Code is free software; you can redistribute it
8 | and/or modify it under the terms of the GNU General Public License as
9 | published by the Free Software Foundation; either version 3 of the License,
10 | or (at your option) any later version.
11 |
12 | Spearmint Source Code is distributed in the hope that it will be
13 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with Spearmint Source Code. If not, see .
19 |
20 | In addition, Spearmint Source Code is also subject to certain additional terms.
21 | You should have received a copy of these additional terms immediately following
22 | the terms and conditions of the GNU General Public License. If not, please
23 | request a copy in writing from id Software at the address below.
24 |
25 | If you have questions concerning this license or the applicable additional
26 | terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc.,
27 | Suite 120, Rockville, Maryland 20850 USA.
28 | ===========================================================================
29 | */
30 | #ifndef __MATHLIB__
31 | #define __MATHLIB__
32 |
33 | // mathlib.h
34 |
35 | #include
36 |
37 | #ifdef DOUBLEVEC_T
38 | typedef double vec_t;
39 | #else
40 | typedef float vec_t;
41 | #endif
42 | typedef vec_t vec2_t[3];
43 | typedef vec_t vec3_t[3];
44 | typedef vec_t vec4_t[4];
45 |
46 | #define SIDE_FRONT 0
47 | #define SIDE_ON 2
48 | #define SIDE_BACK 1
49 | #define SIDE_CROSS -2
50 |
51 | #define Q_PI 3.14159265358979323846
52 | #define DEG2RAD( a ) ( ( (a) * Q_PI ) / 180.0F )
53 | #define RAD2DEG( a ) ( ( (a) * 180.0f ) / Q_PI )
54 |
55 | extern vec3_t vec3_origin;
56 |
57 | #define EQUAL_EPSILON 0.001
58 |
59 | // plane types are used to speed some tests
60 | // 0-2 are axial planes
61 | #define PLANE_X 0
62 | #define PLANE_Y 1
63 | #define PLANE_Z 2
64 | #define PLANE_NON_AXIAL 3
65 |
66 | qboolean VectorCompare( const vec3_t v1, const vec3_t v2 );
67 |
68 | #define DotProduct(x,y) (x[0]*y[0]+x[1]*y[1]+x[2]*y[2])
69 | #define VectorSubtract(a,b,c) {c[0]=a[0]-b[0];c[1]=a[1]-b[1];c[2]=a[2]-b[2];}
70 | #define VectorAdd(a,b,c) {c[0]=a[0]+b[0];c[1]=a[1]+b[1];c[2]=a[2]+b[2];}
71 | #define VectorCopy(a,b) {b[0]=a[0];b[1]=a[1];b[2]=a[2];}
72 | #define VectorScale(a,b,c) {c[0]=b*a[0];c[1]=b*a[1];c[2]=b*a[2];}
73 | #define VectorClear(x) {x[0] = x[1] = x[2] = 0;}
74 | #define VectorNegate(x) {x[0]=-x[0];x[1]=-x[1];x[2]=-x[2];}
75 | void Vec10Copy( vec_t *in, vec_t *out );
76 |
77 | vec_t Q_rint (vec_t in);
78 | vec_t _DotProduct (vec3_t v1, vec3_t v2);
79 | void _VectorSubtract (vec3_t va, vec3_t vb, vec3_t out);
80 | void _VectorAdd (vec3_t va, vec3_t vb, vec3_t out);
81 | void _VectorCopy (vec3_t in, vec3_t out);
82 | void _VectorScale (vec3_t v, vec_t scale, vec3_t out);
83 |
84 | double VectorLength( const vec3_t v );
85 |
86 | void VectorMA( const vec3_t va, double scale, const vec3_t vb, vec3_t vc );
87 |
88 | void CrossProduct( const vec3_t v1, const vec3_t v2, vec3_t cross );
89 | vec_t VectorNormalize( const vec3_t in, vec3_t out );
90 | vec_t ColorNormalize( const vec3_t in, vec3_t out );
91 | void VectorInverse (vec3_t v);
92 |
93 | void ClearBounds (vec3_t mins, vec3_t maxs);
94 | void AddPointToBounds( const vec3_t v, vec3_t mins, vec3_t maxs );
95 |
96 | qboolean PlaneFromPoints( vec4_t plane, const vec3_t a, const vec3_t b, const vec3_t c );
97 |
98 | void NormalToLatLong( const vec3_t normal, byte bytes[2] );
99 |
100 | int PlaneTypeForNormal (vec3_t normal);
101 |
102 | #endif
103 |
--------------------------------------------------------------------------------
/code/tools/asm/notes.txt:
--------------------------------------------------------------------------------
1 |
2 | don't do any parameter conversion (double to float, etc)
3 |
4 |
5 |
6 | Why?
7 |
8 | Security.
9 | Portability.
10 |
11 | It may be more aproachable.
12 |
13 | can still use regular dlls for development purposes
14 |
15 | lcc
16 | q3asm
17 |
--------------------------------------------------------------------------------
/code/tools/asm/ops.txt:
--------------------------------------------------------------------------------
1 | CNSTF,
2 | CNSTI,
3 | CNSTP,
4 | CNSTU,
5 |
6 | ARGB,
7 | ARGF,
8 | ARGI,
9 | ARGP,
10 | ARGU,
11 |
12 | ASGNB,
13 | ASGNF,
14 | ASGNI,
15 | ASGNP,
16 | ASGNU,
17 |
18 | INDIRB,
19 | INDIRF,
20 | INDIRI,
21 | INDIRP,
22 | INDIRU,
23 |
24 | CVFF,
25 | CVFI,
26 |
27 | CVIF,
28 | CVII,
29 | CVIU,
30 |
31 | CVPU,
32 |
33 | CVUI,
34 | CVUP,
35 | CVUU,
36 |
37 | NEGF,
38 | NEGI,
39 |
40 | CALLB,
41 | CALLF,
42 | CALLI,
43 | CALLP,
44 | CALLU,
45 | CALLV,
46 |
47 | RETF,
48 | RETI,
49 | RETP,
50 | RETU,
51 | RETV,
52 |
53 | ADDRGP,
54 |
55 | ADDRFP,
56 |
57 | ADDRLP,
58 |
59 | ADDF,
60 | ADDI,
61 | ADDP,
62 | ADDU,
63 |
64 | SUBF,
65 | SUBI,
66 | SUBP,
67 | SUBU,
68 |
69 | LSHI,
70 | LSHU,
71 |
72 | MODI,
73 | MODU,
74 |
75 | RSHI,
76 | RSHU,
77 |
78 | BANDI,
79 | BANDU,
80 |
81 | BCOMI,
82 | BCOMU,
83 |
84 | BORI,
85 | BORU,
86 |
87 | BXORI,
88 | BXORU,
89 |
90 | DIVF,
91 | DIVI,
92 | DIVU,
93 |
94 | MULF,
95 | MULI,
96 | MULU,
97 |
98 | EQF,
99 | EQI,
100 | EQU,
101 |
102 | GEF,
103 | GEI,
104 | GEU,
105 |
106 | GTF,
107 | GTI,
108 | GTU,
109 |
110 | LEF,
111 | LEI,
112 | LEU,
113 |
114 | LTF,
115 | LTI,
116 | LTU,
117 |
118 | NEF,
119 | NEI,
120 | NEU,
121 |
122 | JUMPV,
123 |
124 | LABELV,
125 |
126 | LOADB,
127 | LOADF,
128 | LOADI,
129 | LOADP,
130 | LOADU,
131 |
132 |
133 |
--------------------------------------------------------------------------------
/code/tools/asm/opstrings.h:
--------------------------------------------------------------------------------
1 | /*
2 | ===========================================================================
3 | Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
4 |
5 | This file is part of Spearmint Source Code.
6 |
7 | Spearmint Source Code is free software; you can redistribute it
8 | and/or modify it under the terms of the GNU General Public License as
9 | published by the Free Software Foundation; either version 3 of the License,
10 | or (at your option) any later version.
11 |
12 | Spearmint Source Code is distributed in the hope that it will be
13 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with Spearmint Source Code. If not, see .
19 |
20 | In addition, Spearmint Source Code is also subject to certain additional terms.
21 | You should have received a copy of these additional terms immediately following
22 | the terms and conditions of the GNU General Public License. If not, please
23 | request a copy in writing from id Software at the address below.
24 |
25 | If you have questions concerning this license or the applicable additional
26 | terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc.,
27 | Suite 120, Rockville, Maryland 20850 USA.
28 | ===========================================================================
29 | */
30 | { "BREAK", OP_BREAK },
31 |
32 | { "CNSTF4", OP_CONST },
33 | { "CNSTI4", OP_CONST },
34 | { "CNSTP4", OP_CONST },
35 | { "CNSTU4", OP_CONST },
36 |
37 | { "CNSTI2", OP_CONST },
38 | { "CNSTU2", OP_CONST },
39 |
40 | { "CNSTI1", OP_CONST },
41 | { "CNSTU1", OP_CONST },
42 |
43 | //{ "ARGB", OP_ARG },
44 | //{ "ARGF", OP_ARG },
45 | //{ "ARGI", OP_ARG },
46 | //{ "ARGP", OP_ARG },
47 | //{ "ARGU", OP_ARG },
48 |
49 | { "ASGNB", OP_BLOCK_COPY },
50 | { "ASGNF4", OP_STORE4 },
51 | { "ASGNI4", OP_STORE4 },
52 | { "ASGNP4", OP_STORE4 },
53 | { "ASGNU4", OP_STORE4 },
54 |
55 | { "ASGNI2", OP_STORE2 },
56 | { "ASGNU2", OP_STORE2 },
57 |
58 | { "ASGNI1", OP_STORE1 },
59 | { "ASGNU1", OP_STORE1 },
60 |
61 | { "INDIRB", OP_IGNORE }, // block copy deals with this
62 | { "INDIRF4", OP_LOAD4 },
63 | { "INDIRI4", OP_LOAD4 },
64 | { "INDIRP4", OP_LOAD4 },
65 | { "INDIRU4", OP_LOAD4 },
66 |
67 | { "INDIRI2", OP_LOAD2 },
68 | { "INDIRU2", OP_LOAD2 },
69 |
70 | { "INDIRI1", OP_LOAD1 },
71 | { "INDIRU1", OP_LOAD1 },
72 |
73 | { "CVFF4", OP_UNDEF },
74 | { "CVFI4", OP_CVFI },
75 |
76 | { "CVIF4", OP_CVIF },
77 | { "CVII4", OP_SEX8 }, // will be either SEX8 or SEX16
78 | { "CVII1", OP_IGNORE },
79 | { "CVII2", OP_IGNORE },
80 | { "CVIU4", OP_IGNORE },
81 |
82 | { "CVPU4", OP_IGNORE },
83 |
84 | { "CVUI4", OP_IGNORE },
85 | { "CVUP4", OP_IGNORE },
86 | { "CVUU4", OP_IGNORE },
87 |
88 | { "CVUU2", OP_IGNORE },
89 | { "CVUU1", OP_IGNORE },
90 |
91 | { "NEGF4", OP_NEGF },
92 | { "NEGI4", OP_NEGI },
93 |
94 | //{ "CALLB", OP_UNDEF },
95 | //{ "CALLF", OP_UNDEF },
96 | //{ "CALLI", OP_UNDEF },
97 | //{ "CALLP", OP_UNDEF },
98 | //{ "CALLU", OP_UNDEF },
99 | //{ "CALLV", OP_CALL },
100 |
101 | //{ "RETF", OP_UNDEF },
102 | //{ "RETI", OP_UNDEF },
103 | //{ "RETP", OP_UNDEF },
104 | //{ "RETU", OP_UNDEF },
105 | //{ "RETV", OP_UNDEF },
106 |
107 | { "ADDRGP4", OP_CONST },
108 |
109 | //{ "ADDRFP", OP_PARM },
110 | //{ "ADDRLP", OP_LOCAL },
111 |
112 | { "ADDF4", OP_ADDF },
113 | { "ADDI4", OP_ADD },
114 | { "ADDP4", OP_ADD },
115 | { "ADDP", OP_ADD },
116 | { "ADDU4", OP_ADD },
117 |
118 | { "SUBF4", OP_SUBF },
119 | { "SUBI4", OP_SUB },
120 | { "SUBP4", OP_SUB },
121 | { "SUBU4", OP_SUB },
122 |
123 | { "LSHI4", OP_LSH },
124 | { "LSHU4", OP_LSH },
125 |
126 | { "MODI4", OP_MODI },
127 | { "MODU4", OP_MODU },
128 |
129 | { "RSHI4", OP_RSHI },
130 | { "RSHU4", OP_RSHU },
131 |
132 | { "BANDI4", OP_BAND },
133 | { "BANDU4", OP_BAND },
134 |
135 | { "BCOMI4", OP_BCOM },
136 | { "BCOMU4", OP_BCOM },
137 |
138 | { "BORI4", OP_BOR },
139 | { "BORU4", OP_BOR },
140 |
141 | { "BXORI4", OP_BXOR },
142 | { "BXORU4", OP_BXOR },
143 |
144 | { "DIVF4", OP_DIVF },
145 | { "DIVI4", OP_DIVI },
146 | { "DIVU4", OP_DIVU },
147 |
148 | { "MULF4", OP_MULF },
149 | { "MULI4", OP_MULI },
150 | { "MULU4", OP_MULU },
151 |
152 | { "EQF4", OP_EQF },
153 | { "EQI4", OP_EQ },
154 | { "EQU4", OP_EQ },
155 |
156 | { "GEF4", OP_GEF },
157 | { "GEI4", OP_GEI },
158 | { "GEU4", OP_GEU },
159 |
160 | { "GTF4", OP_GTF },
161 | { "GTI4", OP_GTI },
162 | { "GTU4", OP_GTU },
163 |
164 | { "LEF4", OP_LEF },
165 | { "LEI4", OP_LEI },
166 | { "LEU4", OP_LEU },
167 |
168 | { "LTF4", OP_LTF },
169 | { "LTI4", OP_LTI },
170 | { "LTU4", OP_LTU },
171 |
172 | { "NEF4", OP_NEF },
173 | { "NEI4", OP_NE },
174 | { "NEU4", OP_NE },
175 |
176 | { "JUMPV", OP_JUMP },
177 |
178 | { "LOADB4", OP_UNDEF },
179 | { "LOADF4", OP_UNDEF },
180 | { "LOADI4", OP_UNDEF },
181 | { "LOADP4", OP_UNDEF },
182 | { "LOADU4", OP_UNDEF },
183 |
184 |
185 |
--------------------------------------------------------------------------------
/code/tools/lcc/COPYRIGHT:
--------------------------------------------------------------------------------
1 | The authors of this software are Christopher W. Fraser and
2 | David R. Hanson.
3 |
4 | Copyright (c) 1991,1992,1993,1994,1995,1996,1997,1998 by AT&T,
5 | Christopher W. Fraser, and David R. Hanson. All Rights Reserved.
6 |
7 | Permission to use, copy, modify, and distribute this software for any
8 | purpose, subject to the provisions described below, without fee is
9 | hereby granted, provided that this entire notice is included in all
10 | copies of any software that is or includes a copy or modification of
11 | this software and in all copies of the supporting documentation for
12 | such software.
13 |
14 | THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
15 | WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR AT&T MAKE ANY
16 | REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
17 | OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
18 |
19 |
20 | lcc is not public-domain software, shareware, and it is not protected
21 | by a `copyleft' agreement, like the code from the Free Software
22 | Foundation.
23 |
24 | lcc is available free for your personal research and instructional use
25 | under the `fair use' provisions of the copyright law. You may, however,
26 | redistribute lcc in whole or in part provided you acknowledge its
27 | source and include this CPYRIGHT file. You may, for example, include
28 | the distribution in a CDROM of free software, provided you charge only
29 | for the media, or mirror the distribution files at your site.
30 |
31 | You may not sell lcc or any product derived from it in which it is a
32 | significant part of the value of the product. Using the lcc front end
33 | to build a C syntax checker is an example of this kind of product.
34 |
35 | You may use parts of lcc in products as long as you charge for only
36 | those components that are entirely your own and you acknowledge the use
37 | of lcc clearly in all product documentation and distribution media. You
38 | must state clearly that your product uses or is based on parts of lcc
39 | and that lcc is available free of charge. You must also request that
40 | bug reports on your product be reported to you. Using the lcc front
41 | end to build a C compiler for the Motorola 88000 chip and charging for
42 | and distributing only the 88000 code generator is an example of this
43 | kind of product.
44 |
45 | Using parts of lcc in other products is more problematic. For example,
46 | using parts of lcc in a C++ compiler could save substantial time and
47 | effort and therefore contribute significantly to the profitability of
48 | the product. This kind of use, or any use where others stand to make a
49 | profit from what is primarily our work, requires a license agreement
50 | with Addison-Wesley. Per-copy and unlimited use licenses are
51 | available; for more information, contact
52 |
53 | J. Carter Shanklin
54 | Addison Wesley Longman, Inc.
55 | 2725 Sand Hill Rd.
56 | Menlo Park, CA 94025
57 | 650/854-0300 x2478 FAX: 650/614-2930 jcs@awl.com
58 | -----
59 | Chris Fraser / cwfraser@microsoft.com
60 | David Hanson / drh@microsoft.com
61 | $Revision: 145 $ $Date: 2001-10-17 16:53:10 -0500 (Wed, 17 Oct 2001) $
62 |
--------------------------------------------------------------------------------
/code/tools/lcc/LOG:
--------------------------------------------------------------------------------
1 | From lcc 4.0 to 4.1:
2 |
3 | Changes:
4 |
5 | See doc/4.html for changes in the code-generation interface.
6 |
7 | Warns about constants that are too large, eg, short x = 70000;
8 |
9 | Warns about expressions that have no effect.
10 |
11 | Unsigned shorts are now used for wide-character constants, and
12 | wchar_t is a typedef for unsigned short.
13 |
14 | More assertions in gen.c to confirm that the register allocator is
15 | configured correctly; ie, that the various masks, wildcards,
16 | clobbers, and targets are internally consistent. Full checking
17 | appears impractical, but there's still more than than there was
18 | before.
19 |
20 | On the SPARC, lcc now emits .type and .size directives
21 | unconditionally.
22 |
23 | On the x86, constants are now emitted into the text segment.
24 |
25 | If the environment variable "LCCDIR" is defined, it gives the directory
26 | that contains the preprocessor, the compiler proper, and the
27 | lcc-specific libraries.
28 |
29 | Under Windows, lcc searches the directories named in the environment
30 | variable "include" for header files.
31 |
32 | Errors fixed:
33 |
34 | Erroneously complained about unknown sizes for some const fields, eg,
35 | typedef struct foo ref; struct foo { const ref *q; int a; };
36 | f(ref *p, int i) { return p->q[i].a; }
37 |
38 | -A -A erroneously complained about static main's that didn't conform
39 | to the ANSI-mandated "int main(void)" or "int main(int, char **)".
40 |
41 | Silently generated incorrect code for a structure copy with a
42 | post-incremented target, eg,
43 | struct { int x; } data = {1}, copy[2], *q = copy;
44 | main() { *q++ = data; }
45 |
46 | Generated incorrect values in some expressions with constant pointers.
47 |
48 | Silently truncated string literals longer than 4095 characters.
49 |
50 | Failed to emit debugging information for uninitialized globals.
51 |
52 | Failed to diagnose missing sizes in some multi-dimensioned array
53 | declarators, eg, extern int x[][10]; int x[5][];
54 |
55 | Silently emitted incorrect sizes and initalizations for some
56 | incomplete multi-dimensioned arrays involving pointers and whose size
57 | is determined by the number of initializers.
58 |
59 | Set only the x.name field for some back-end symbols (eg, wildcards),
60 | and the uninitialized name field crashed some debugging output.
61 |
62 | uses() failed to check the register *set* as well as the register
63 | mask. There's no known bug demo, but a wildcard set might be
64 | contrived that would need the test.
65 |
66 | Crashed with -b on some conditional expressions involving calls, eg,
67 | int p; void g(void) { p ? f() : 1; }
68 |
69 | On the MIPS, sometimes generated an incorrect frame size and thus a
70 | crash when floating-point registers were saved.
71 |
72 | On the SPARC, erroneously reused a register variable as a temporary
73 | when the variable is compiler-generated.
74 |
75 | On the SPARC with -b, emitted incorrect code for returning structs.
76 |
77 | On the x86, conversion from float to int rounded instead of truncated
78 | with the default floating-point mode.
79 |
80 | On the x86, eliminate rtargets for kids after the first (see p. 419).
81 |
82 | On the x86, substitute reg for freg, in order to use the common reg
83 | rules. Needed only for debugging output, since we're not using any
84 | float regs as regs at this time.
85 |
86 | On the x86, "double f(); main(){f();}" wasn't popping the FP register stack.
87 |
88 | On the x86, ECX was saved by the callee, when it should have been
89 | saved by the caller.
90 |
91 | $Id: LOG 145 2001-10-17 21:53:10Z timo $
92 |
--------------------------------------------------------------------------------
/code/tools/lcc/README:
--------------------------------------------------------------------------------
1 | This hierarchy is the distribution for lcc version 4.1.
2 |
3 | lcc version 3.x is described in the book "A Retargetable C Compiler:
4 | Design and Implementation" (Addison-Wesley, 1995, ISBN 0-8053-1670-1).
5 | There are significant differences between 3.x and 4.x, most notably in
6 | the intermediate code. doc/4.html summarizes the differences.
7 |
8 | VERSION 4.1 IS INCOMPATIBLE WITH EARLIER VERSIONS OF LCC. DO NOT
9 | UNLOAD THIS DISTRIBUTION ON TOP OF A 3.X DISTRIBUTION.
10 |
11 | LOG describes the changes since the last release.
12 |
13 | CPYRIGHT describes the conditions under you can use, copy, modify, and
14 | distribute lcc or works derived from lcc.
15 |
16 | doc/install.html is an HTML file that gives a complete description of
17 | the distribution and installation instructions.
18 |
19 | Chris Fraser / cwfraser@microsoft.com
20 | David Hanson / drh@microsoft.com
21 | $Revision: 145 $ $Date: 2001-10-17 16:53:10 -0500 (Wed, 17 Oct 2001) $
22 |
--------------------------------------------------------------------------------
/code/tools/lcc/README.id:
--------------------------------------------------------------------------------
1 | 2001-10-31 Timothee Besset
2 | updated from the $/source/lcc code
3 | modified for portability and use with >= 1.31 mod source release
4 |
--------------------------------------------------------------------------------
/code/tools/lcc/cpp/cpp.h:
--------------------------------------------------------------------------------
1 | #define INS 32768 /* input buffer */
2 | #define OBS 4096 /* outbut buffer */
3 | #define NARG 32 /* Max number arguments to a macro */
4 | #define NINCLUDE 32 /* Max number of include directories (-I) */
5 | #define NIF 32 /* depth of nesting of #if */
6 | #ifndef EOF
7 | #define EOF (-1)
8 | #endif
9 | #ifndef NULL
10 | #define NULL 0
11 | #endif
12 |
13 | #ifndef __alpha
14 | typedef unsigned char uchar;
15 | #endif
16 |
17 | enum toktype { END, UNCLASS, NAME, NUMBER, STRING, CCON, NL, WS, DSHARP,
18 | EQ, NEQ, LEQ, GEQ, LSH, RSH, LAND, LOR, PPLUS, MMINUS,
19 | ARROW, SBRA, SKET, LP, RP, DOT, AND, STAR, PLUS, MINUS,
20 | TILDE, NOT, SLASH, PCT, LT, GT, CIRC, OR, QUEST,
21 | COLON, ASGN, COMMA, SHARP, SEMIC, CBRA, CKET,
22 | ASPLUS, ASMINUS, ASSTAR, ASSLASH, ASPCT, ASCIRC, ASLSH,
23 | ASRSH, ASOR, ASAND, ELLIPS,
24 | DSHARP1, NAME1, DEFINED, UMINUS };
25 |
26 | enum kwtype { KIF, KIFDEF, KIFNDEF, KELIF, KELSE, KENDIF, KINCLUDE, KDEFINE,
27 | KUNDEF, KLINE, KWARNING, KERROR, KPRAGMA, KDEFINED,
28 | KLINENO, KFILE, KDATE, KTIME, KSTDC, KEVAL };
29 |
30 | #define ISDEFINED 01 /* has #defined value */
31 | #define ISKW 02 /* is PP keyword */
32 | #define ISUNCHANGE 04 /* can't be #defined in PP */
33 | #define ISMAC 010 /* builtin macro, e.g. __LINE__ */
34 |
35 | #define EOB 0xFE /* sentinel for end of input buffer */
36 | #define EOFC 0xFD /* sentinel for end of input file */
37 | #define XPWS 1 /* token flag: white space to assure token sep. */
38 |
39 | typedef struct token {
40 | unsigned char type;
41 | unsigned char flag;
42 | unsigned short hideset;
43 | unsigned int wslen;
44 | unsigned int len;
45 | uchar *t;
46 | } Token;
47 |
48 | typedef struct tokenrow {
49 | Token *tp; /* current one to scan */
50 | Token *bp; /* base (allocated value) */
51 | Token *lp; /* last+1 token used */
52 | int max; /* number allocated */
53 | } Tokenrow;
54 |
55 | typedef struct source {
56 | char *filename; /* name of file of the source */
57 | int line; /* current line number */
58 | int lineinc; /* adjustment for \\n lines */
59 | uchar *inb; /* input buffer */
60 | uchar *inp; /* input pointer */
61 | uchar *inl; /* end of input */
62 | int fd; /* input source */
63 | int ifdepth; /* conditional nesting in include */
64 | struct source *next; /* stack for #include */
65 | } Source;
66 |
67 | typedef struct nlist {
68 | struct nlist *next;
69 | uchar *name;
70 | int len;
71 | Tokenrow *vp; /* value as macro */
72 | Tokenrow *ap; /* list of argument names, if any */
73 | char val; /* value as preprocessor name */
74 | char flag; /* is defined, is pp name */
75 | } Nlist;
76 |
77 | typedef struct includelist {
78 | char deleted;
79 | char always;
80 | char *file;
81 | } Includelist;
82 |
83 | #define new(t) (t *)domalloc(sizeof(t))
84 | #define quicklook(a,b) (namebit[(a)&077] & (1<<((b)&037)))
85 | #define quickset(a,b) namebit[(a)&077] |= (1<<((b)&037))
86 | extern unsigned long namebit[077+1];
87 |
88 | enum errtype { WARNING, ERROR, FATAL };
89 |
90 | void expandlex(void);
91 | void fixlex(void);
92 | void setup(int, char **);
93 | int gettokens(Tokenrow *, int);
94 | int comparetokens(Tokenrow *, Tokenrow *);
95 | Source *setsource(char *, int, char *);
96 | void unsetsource(void);
97 | void puttokens(Tokenrow *);
98 | void process(Tokenrow *);
99 | void *domalloc(int);
100 | void dofree(void *);
101 | void error(enum errtype, char *, ...);
102 | void flushout(void);
103 | int fillbuf(Source *);
104 | int trigraph(Source *);
105 | int foldline(Source *);
106 | Nlist *lookup(Token *, int);
107 | void control(Tokenrow *);
108 | void dodefine(Tokenrow *);
109 | void doadefine(Tokenrow *, int);
110 | void doinclude(Tokenrow *);
111 | void appendDirToIncludeList( char *dir );
112 | void doif(Tokenrow *, enum kwtype);
113 | void expand(Tokenrow *, Nlist *);
114 | void builtin(Tokenrow *, int);
115 | int gatherargs(Tokenrow *, Tokenrow **, int *);
116 | void substargs(Nlist *, Tokenrow *, Tokenrow **);
117 | void expandrow(Tokenrow *, char *);
118 | void maketokenrow(int, Tokenrow *);
119 | Tokenrow *copytokenrow(Tokenrow *, Tokenrow *);
120 | Token *growtokenrow(Tokenrow *);
121 | Tokenrow *normtokenrow(Tokenrow *);
122 | void adjustrow(Tokenrow *, int);
123 | void movetokenrow(Tokenrow *, Tokenrow *);
124 | void insertrow(Tokenrow *, int, Tokenrow *);
125 | void peektokens(Tokenrow *, char *);
126 | void doconcat(Tokenrow *);
127 | Tokenrow *stringify(Tokenrow *);
128 | int lookuparg(Nlist *, Token *);
129 | long eval(Tokenrow *, int);
130 | void genline(void);
131 | void setempty(Tokenrow *);
132 | void makespace(Tokenrow *);
133 | char *outnum(char *, int);
134 | int digit(int);
135 | uchar *newstring(uchar *, int, int);
136 | int checkhideset(int, Nlist *);
137 | void prhideset(int);
138 | int newhideset(int, Nlist *);
139 | int unionhideset(int, int);
140 | void iniths(void);
141 | void setobjname(char *);
142 | #define rowlen(tokrow) ((tokrow)->lp - (tokrow)->bp)
143 |
144 | char *basepath( char *fname );
145 |
146 | extern char *outbufp;
147 | extern Token nltoken;
148 | extern Source *cursource;
149 | extern char *curtime;
150 | extern int incdepth;
151 | extern int ifdepth;
152 | extern int ifsatisfied[NIF];
153 | extern int Mflag;
154 | extern int skipping;
155 | extern int verbose;
156 | extern int Cplusplus;
157 | extern Nlist *kwdefined;
158 | extern Includelist includelist[NINCLUDE];
159 | extern char wd[];
160 |
161 | #ifndef _WIN32
162 | #include
163 | #else
164 | #include
165 | #endif
166 | #include
167 |
--------------------------------------------------------------------------------
/code/tools/lcc/cpp/getopt.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #define EPR fprintf(stderr,
4 | #define ERR(str, chr) if(opterr){EPR "%s%c\n", str, chr);}
5 | int opterr = 1;
6 | int optind = 1;
7 | int optopt;
8 | char *optarg;
9 |
10 | int
11 | lcc_getopt (int argc, char *const argv[], const char *opts)
12 | {
13 | static int sp = 1;
14 | int c;
15 | char *cp;
16 |
17 | if (sp == 1) {
18 | if (optind >= argc ||
19 | argv[optind][0] != '-' || argv[optind][1] == '\0')
20 | return -1;
21 | else if (strcmp(argv[optind], "--") == 0) {
22 | optind++;
23 | return -1;
24 | }
25 | }
26 | optopt = c = argv[optind][sp];
27 | if (c == ':' || (cp=strchr(opts, c)) == 0) {
28 | ERR (": illegal option -- ", c);
29 | if (argv[optind][++sp] == '\0') {
30 | optind++;
31 | sp = 1;
32 | }
33 | return '?';
34 | }
35 | if (*++cp == ':') {
36 | if (argv[optind][sp+1] != '\0')
37 | optarg = &argv[optind++][sp+1];
38 | else if (++optind >= argc) {
39 | ERR (": option requires an argument -- ", c);
40 | sp = 1;
41 | return '?';
42 | } else
43 | optarg = argv[optind++];
44 | sp = 1;
45 | } else {
46 | if (argv[optind][++sp] == '\0') {
47 | sp = 1;
48 | optind++;
49 | }
50 | optarg = 0;
51 | }
52 | return c;
53 | }
54 |
--------------------------------------------------------------------------------
/code/tools/lcc/cpp/hideset.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include "cpp.h"
5 |
6 | /*
7 | * A hideset is a null-terminated array of Nlist pointers.
8 | * They are referred to by indices in the hidesets array.
9 | * Hideset 0 is empty.
10 | */
11 |
12 | #define HSSIZ 32
13 | typedef Nlist **Hideset;
14 | Hideset *hidesets;
15 | int nhidesets = 0;
16 | int maxhidesets = 3;
17 | int inserths(Hideset, Hideset, Nlist *);
18 |
19 | /*
20 | * Test for membership in a hideset
21 | */
22 | int
23 | checkhideset(int hs, Nlist *np)
24 | {
25 | Hideset hsp;
26 |
27 | if (hs>=nhidesets)
28 | abort();
29 | for (hsp = hidesets[hs]; *hsp; hsp++) {
30 | if (*hsp == np)
31 | return 1;
32 | }
33 | return 0;
34 | }
35 |
36 | /*
37 | * Return the (possibly new) hideset obtained by adding np to hs.
38 | */
39 | int
40 | newhideset(int hs, Nlist *np)
41 | {
42 | int i, len;
43 | Nlist *nhs[HSSIZ+3];
44 | Hideset hs1, hs2;
45 |
46 | len = inserths(nhs, hidesets[hs], np);
47 | for (i=0; i=HSSIZ)
53 | return hs;
54 | if (nhidesets >= maxhidesets) {
55 | maxhidesets = 3*maxhidesets/2+1;
56 | hidesets = (Hideset *)realloc(hidesets, (sizeof (Hideset *))*maxhidesets);
57 | if (hidesets == NULL)
58 | error(FATAL, "Out of memory from realloc");
59 | }
60 | hs1 = (Hideset)domalloc(len*sizeof(Hideset));
61 | memmove(hs1, nhs, len*sizeof(Hideset));
62 | hidesets[nhidesets] = hs1;
63 | return nhidesets++;
64 | }
65 |
66 | int
67 | inserths(Hideset dhs, Hideset shs, Nlist *np)
68 | {
69 | Hideset odhs = dhs;
70 |
71 | while (*shs && *shs < np)
72 | *dhs++ = *shs++;
73 | if (*shs != np)
74 | *dhs++ = np;
75 | do {
76 | *dhs++ = *shs;
77 | } while (*shs++);
78 | return dhs - odhs;
79 | }
80 |
81 | /*
82 | * Hideset union
83 | */
84 | int
85 | unionhideset(int hs1, int hs2)
86 | {
87 | Hideset hp;
88 |
89 | for (hp = hidesets[hs2]; *hp; hp++)
90 | hs1 = newhideset(hs1, *hp);
91 | return hs1;
92 | }
93 |
94 | void
95 | iniths(void)
96 | {
97 | hidesets = (Hideset *)domalloc(maxhidesets*sizeof(Hideset *));
98 | hidesets[0] = (Hideset)domalloc(sizeof(Hideset));
99 | *hidesets[0] = NULL;
100 | nhidesets++;
101 | }
102 |
103 | void
104 | prhideset(int hs)
105 | {
106 | Hideset np;
107 |
108 | for (np = hidesets[hs]; *np; np++) {
109 | fprintf(stderr, (char*)(*np)->name, (*np)->len);
110 | fprintf(stderr, " ");
111 | }
112 | }
113 |
--------------------------------------------------------------------------------
/code/tools/lcc/cpp/include.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include "cpp.h"
5 |
6 | Includelist includelist[NINCLUDE];
7 |
8 | extern char *objname;
9 |
10 | void appendDirToIncludeList( char *dir )
11 | {
12 | int i;
13 | char *fqdir;
14 |
15 | fqdir = (char *)newstring( (uchar *)includelist[NINCLUDE-1].file, 256, 0 );
16 | strcat( fqdir, "/" );
17 | strcat( fqdir, dir );
18 |
19 | //avoid adding it more than once
20 | for (i=NINCLUDE-2; i>=0; i--) {
21 | if (includelist[i].file &&
22 | !strcmp (includelist[i].file, fqdir)) {
23 | return;
24 | }
25 | }
26 |
27 | for (i=NINCLUDE-2; i>=0; i--) {
28 | if (includelist[i].file==NULL) {
29 | includelist[i].always = 1;
30 | includelist[i].file = fqdir;
31 | break;
32 | }
33 | }
34 | if (i<0)
35 | error(FATAL, "Too many -I directives");
36 | }
37 |
38 | void
39 | doinclude(Tokenrow *trp)
40 | {
41 | char fname[256], iname[256];
42 | Includelist *ip;
43 | int angled, len, fd, i;
44 |
45 | trp->tp += 1;
46 | if (trp->tp>=trp->lp)
47 | goto syntax;
48 | if (trp->tp->type!=STRING && trp->tp->type!=LT) {
49 | len = trp->tp - trp->bp;
50 | expandrow(trp, "");
51 | trp->tp = trp->bp+len;
52 | }
53 | if (trp->tp->type==STRING) {
54 | len = trp->tp->len-2;
55 | if (len > sizeof(fname) - 1)
56 | len = sizeof(fname) - 1;
57 | strncpy(fname, (char*)trp->tp->t+1, len);
58 | angled = 0;
59 | } else if (trp->tp->type==LT) {
60 | len = 0;
61 | trp->tp++;
62 | while (trp->tp->type!=GT) {
63 | if (trp->tp>trp->lp || len+trp->tp->len+2 >= sizeof(fname))
64 | goto syntax;
65 | strncpy(fname+len, (char*)trp->tp->t, trp->tp->len);
66 | len += trp->tp->len;
67 | trp->tp++;
68 | }
69 | angled = 1;
70 | } else
71 | goto syntax;
72 | trp->tp += 2;
73 | if (trp->tp < trp->lp || len==0)
74 | goto syntax;
75 | fname[len] = '\0';
76 |
77 | appendDirToIncludeList( basepath( fname ) );
78 |
79 | if (fname[0]=='/') {
80 | fd = open(fname, 0);
81 | strcpy(iname, fname);
82 | } else for (fd = -1,i=NINCLUDE-1; i>=0; i--) {
83 | ip = &includelist[i];
84 | if (ip->file==NULL || ip->deleted || (angled && ip->always==0))
85 | continue;
86 | if (strlen(fname)+strlen(ip->file)+2 > sizeof(iname))
87 | continue;
88 | strcpy(iname, ip->file);
89 | strcat(iname, "/");
90 | strcat(iname, fname);
91 | if ((fd = open(iname, 0)) >= 0)
92 | break;
93 | }
94 | if ( Mflag>1 || (!angled&&Mflag==1) ) {
95 | write(1,objname,strlen(objname));
96 | write(1,iname,strlen(iname));
97 | write(1,"\n",1);
98 | }
99 | if (fd >= 0) {
100 | if (++incdepth > 10)
101 | error(FATAL, "#include too deeply nested");
102 | setsource((char*)newstring((uchar*)iname, strlen(iname), 0), fd, NULL);
103 | genline();
104 | } else {
105 | trp->tp = trp->bp+2;
106 | error(ERROR, "Could not find include file %r", trp);
107 | }
108 | return;
109 | syntax:
110 | error(ERROR, "Syntax error in #include");
111 | }
112 |
113 | /*
114 | * Generate a line directive for cursource
115 | */
116 | void
117 | genline(void)
118 | {
119 | static Token ta = { UNCLASS };
120 | static Tokenrow tr = { &ta, &ta, &ta+1, 1 };
121 | uchar *p;
122 |
123 | ta.t = p = (uchar*)outbufp;
124 | strcpy((char*)p, "#line ");
125 | p += sizeof("#line ")-1;
126 | p = (uchar*)outnum((char*)p, cursource->line);
127 | *p++ = ' '; *p++ = '"';
128 | if (cursource->filename[0]!='/' && wd[0]) {
129 | strcpy((char*)p, wd);
130 | p += strlen(wd);
131 | *p++ = '/';
132 | }
133 | strcpy((char*)p, cursource->filename);
134 | p += strlen((char*)p);
135 | *p++ = '"'; *p++ = '\n';
136 | ta.len = (char*)p-outbufp;
137 | outbufp = (char*)p;
138 | tr.tp = tr.bp;
139 | puttokens(&tr);
140 | }
141 |
142 | void
143 | setobjname(char *f)
144 | {
145 | int n = strlen(f);
146 | objname = (char*)domalloc(n+5);
147 | strcpy(objname,f);
148 | if(objname[n-2]=='.'){
149 | strcpy(objname+n-1,"$O: ");
150 | }else{
151 | strcpy(objname+n,"$O: ");
152 | }
153 | }
154 |
--------------------------------------------------------------------------------
/code/tools/lcc/cpp/nlist.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include "cpp.h"
5 |
6 | extern char *optarg;
7 | extern int optind;
8 | extern int verbose;
9 | extern int Cplusplus;
10 | Nlist *kwdefined;
11 | char wd[128];
12 |
13 | #define NLSIZE 128
14 |
15 | static Nlist *nlist[NLSIZE];
16 |
17 | struct kwtab {
18 | char *kw;
19 | int val;
20 | int flag;
21 | } kwtab[] = {
22 | {"if", KIF, ISKW},
23 | {"ifdef", KIFDEF, ISKW},
24 | {"ifndef", KIFNDEF, ISKW},
25 | {"elif", KELIF, ISKW},
26 | {"else", KELSE, ISKW},
27 | {"endif", KENDIF, ISKW},
28 | {"include", KINCLUDE, ISKW},
29 | {"define", KDEFINE, ISKW},
30 | {"undef", KUNDEF, ISKW},
31 | {"line", KLINE, ISKW},
32 | {"warning", KWARNING, ISKW},
33 | {"error", KERROR, ISKW},
34 | {"pragma", KPRAGMA, ISKW},
35 | {"eval", KEVAL, ISKW},
36 | {"defined", KDEFINED, ISDEFINED+ISUNCHANGE},
37 | {"__LINE__", KLINENO, ISMAC+ISUNCHANGE},
38 | {"__FILE__", KFILE, ISMAC+ISUNCHANGE},
39 | {"__DATE__", KDATE, ISMAC+ISUNCHANGE},
40 | {"__TIME__", KTIME, ISMAC+ISUNCHANGE},
41 | {"__STDC__", KSTDC, ISUNCHANGE},
42 | {NULL}
43 | };
44 |
45 | unsigned long namebit[077+1];
46 | Nlist *np;
47 |
48 | void
49 | setup_kwtab(void)
50 | {
51 | struct kwtab *kp;
52 | Nlist *np;
53 | Token t;
54 | static Token deftoken[1] = {{ NAME, 0, 0, 0, 7, (uchar*)"defined" }};
55 | static Tokenrow deftr = { deftoken, deftoken, deftoken+1, 1 };
56 |
57 | for (kp=kwtab; kp->kw; kp++) {
58 | t.t = (uchar*)kp->kw;
59 | t.len = strlen(kp->kw);
60 | np = lookup(&t, 1);
61 | np->flag = kp->flag;
62 | np->val = kp->val;
63 | if (np->val == KDEFINED) {
64 | kwdefined = np;
65 | np->val = NAME;
66 | np->vp = &deftr;
67 | np->ap = 0;
68 | }
69 | }
70 | }
71 |
72 | Nlist *
73 | lookup(Token *tp, int install)
74 | {
75 | unsigned int h;
76 | Nlist *np;
77 | uchar *cp, *cpe;
78 |
79 | h = 0;
80 | for (cp=tp->t, cpe=cp+tp->len; cpt==*np->name && tp->len==np->len
86 | && strncmp((char*)tp->t, (char*)np->name, tp->len)==0)
87 | return np;
88 | np = np->next;
89 | }
90 | if (install) {
91 | np = new(Nlist);
92 | np->vp = NULL;
93 | np->ap = NULL;
94 | np->flag = 0;
95 | np->val = 0;
96 | np->len = tp->len;
97 | np->name = newstring(tp->t, tp->len, 0);
98 | np->next = nlist[h];
99 | nlist[h] = np;
100 | quickset(tp->t[0], tp->len>1? tp->t[1]:0);
101 | return np;
102 | }
103 | return NULL;
104 | }
105 |
--------------------------------------------------------------------------------
/code/tools/lcc/cpp/unix.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include "cpp.h"
7 |
8 | extern int lcc_getopt(int, char *const *, const char *);
9 | extern char *optarg, rcsid[];
10 | extern int optind;
11 | int verbose;
12 | int Mflag; /* only print active include files */
13 | char *objname; /* "src.$O: " */
14 | int Cplusplus = 1;
15 |
16 | void
17 | setup(int argc, char **argv)
18 | {
19 | int c, fd, i;
20 | char *fp, *dp;
21 | Tokenrow tr;
22 | extern void setup_kwtab(void);
23 | uchar *includeDirs[ NINCLUDE ] = { 0 };
24 | int numIncludeDirs = 0;
25 |
26 | setup_kwtab();
27 | while ((c = lcc_getopt(argc, argv, "MNOVv+I:D:U:F:lg")) != -1)
28 | switch (c) {
29 | case 'N':
30 | for (i=0; i", -1, optarg);
40 | maketokenrow(3, &tr);
41 | gettokens(&tr, 1);
42 | doadefine(&tr, c);
43 | unsetsource();
44 | break;
45 | case 'M':
46 | Mflag++;
47 | break;
48 | case 'v':
49 | fprintf(stderr, "%s %s\n", argv[0], rcsid);
50 | break;
51 | case 'V':
52 | verbose++;
53 | break;
54 | case '+':
55 | Cplusplus++;
56 | break;
57 | default:
58 | break;
59 | }
60 | dp = ".";
61 | fp = "";
62 | fd = 0;
63 | if (optind
4 | #include
5 | #include "../../../qcommon/q_platform.h"
6 |
7 | #ifdef _WIN32
8 | #define BINEXT ".exe"
9 | #else
10 | #define BINEXT ""
11 | #endif
12 |
13 | char *suffixes[] = { ".c", ".i", ".asm", ".o", ".out", 0 };
14 | char inputs[256] = "";
15 | char *cpp[] = { "q3cpp" BINEXT,
16 | "-D__STDC__=1", "-D__STRICT_ANSI__", "-D__signed__=signed", "-DQ3_VM",
17 | "$1", "$2", "$3", 0 };
18 | char *include[] = { 0 };
19 | char *com[] = { "q3rcc" BINEXT, "-target=bytecode", "$1", "$2", "$3", 0 };
20 | char *ld[] = { 0 };
21 | char *as[] = { 0 };
22 |
23 | extern char *concat(char *, char *);
24 |
25 | /*
26 | ===============
27 | UpdatePaths
28 |
29 | Updates the paths to q3cpp and q3rcc based on
30 | the directory that contains q3lcc
31 | ===============
32 | */
33 | void UpdatePaths( const char *lccBinary )
34 | {
35 | char basepath[ 1024 ];
36 | char *p;
37 |
38 | strncpy( basepath, lccBinary, 1024 );
39 | p = strrchr( basepath, PATH_SEP );
40 |
41 | if( p )
42 | {
43 | *( p + 1 ) = '\0';
44 |
45 | cpp[ 0 ] = concat( basepath, "q3cpp" BINEXT );
46 | com[ 0 ] = concat( basepath, "q3rcc" BINEXT );
47 | }
48 | }
49 |
50 | int option(char *arg) {
51 | if (strncmp(arg, "-lccdir=", 8) == 0) {
52 | cpp[0] = concat(&arg[8], "/q3cpp" BINEXT);
53 | include[0] = concat("-I", concat(&arg[8], "/include"));
54 | com[0] = concat(&arg[8], "/q3rcc" BINEXT);
55 | } else if (strncmp(arg, "-lcppdir=", 9) == 0) {
56 | cpp[0] = concat(&arg[9], "/q3cpp" BINEXT);
57 | } else if (strncmp(arg, "-lrccdir=", 9) == 0) {
58 | com[0] = concat(&arg[9], "/q3rcc" BINEXT);
59 | } else if (strcmp(arg, "-p") == 0 || strcmp(arg, "-pg") == 0) {
60 | fprintf( stderr, "no profiling supported, %s ignored.\n", arg);
61 | } else if (strcmp(arg, "-b") == 0)
62 | ;
63 | else if (strcmp(arg, "-g") == 0)
64 | fprintf( stderr, "no debugging supported, %s ignored.\n", arg);
65 | else if (strncmp(arg, "-ld=", 4) == 0 || strcmp(arg, "-static") == 0) {
66 | fprintf( stderr, "no linking supported, %s ignored.\n", arg);
67 | } else
68 | return 0;
69 | return 1;
70 | }
71 |
--------------------------------------------------------------------------------
/code/tools/lcc/lburg/gram.y:
--------------------------------------------------------------------------------
1 | %{
2 | #include
3 | #include "lburg.h"
4 | static char rcsid[] = "$Id: gram.y 145 2001-10-17 21:53:10Z timo $";
5 | /*lint -e616 -e527 -e652 -esym(552,yynerrs) -esym(563,yynewstate,yyerrlab) */
6 | static int yylineno = 0;
7 | %}
8 | %union {
9 | int n;
10 | char *string;
11 | Tree tree;
12 | }
13 | %term TERMINAL
14 | %term START
15 | %term PPERCENT
16 |
17 | %token ID TEMPLATE CODE
18 | %token INT
19 | %type nonterm cost
20 | %type tree
21 | %%
22 | spec : decls PPERCENT rules { yylineno = 0; }
23 | | decls { yylineno = 0; }
24 | ;
25 |
26 | decls : /* lambda */
27 | | decls decl
28 | ;
29 |
30 | decl : TERMINAL blist '\n'
31 | | START nonterm '\n' {
32 | if (nonterm($2)->number != 1)
33 | yyerror("redeclaration of the start symbol\n");
34 | }
35 | | '\n'
36 | | error '\n' { yyerrok; }
37 | ;
38 |
39 | blist : /* lambda */
40 | | blist ID '=' INT { term($2, $4); }
41 | ;
42 |
43 | rules : /* lambda */
44 | | rules nonterm ':' tree TEMPLATE cost '\n' { rule($2, $4, $5, $6); }
45 | | rules '\n'
46 | | rules error '\n' { yyerrok; }
47 | ;
48 |
49 | nonterm : ID { nonterm($$ = $1); }
50 | ;
51 |
52 | tree : ID { $$ = tree($1, 0, 0); }
53 | | ID '(' tree ')' { $$ = tree($1, $3, 0); }
54 | | ID '(' tree ',' tree ')' { $$ = tree($1, $3, $5); }
55 | ;
56 |
57 | cost : CODE { if (*$1 == 0) $$ = "0"; }
58 | ;
59 | %%
60 | #include
61 | #include
62 | #include
63 | #include
64 | #include
65 |
66 | int errcnt = 0;
67 | FILE *infp = NULL;
68 | FILE *outfp = NULL;
69 | static char buf[BUFSIZ], *bp = buf;
70 | static int ppercent = 0;
71 | static int code = 0;
72 |
73 | static int get(void) {
74 | if (*bp == 0) {
75 | bp = buf;
76 | *bp = 0;
77 | if (fgets(buf, sizeof buf, infp) == NULL)
78 | return EOF;
79 | yylineno++;
80 | while (buf[0] == '%' && buf[1] == '{' && buf[2] == '\n') {
81 | for (;;) {
82 | if (fgets(buf, sizeof buf, infp) == NULL) {
83 | yywarn("unterminated %{...%}\n");
84 | return EOF;
85 | }
86 | yylineno++;
87 | if (strcmp(buf, "%}\n") == 0)
88 | break;
89 | fputs(buf, outfp);
90 | }
91 | if (fgets(buf, sizeof buf, infp) == NULL)
92 | return EOF;
93 | yylineno++;
94 | }
95 | }
96 | return *bp++;
97 | }
98 |
99 | void yyerror(char *fmt, ...) {
100 | va_list ap;
101 |
102 | va_start(ap, fmt);
103 | if (yylineno > 0)
104 | fprintf(stderr, "line %d: ", yylineno);
105 | vfprintf(stderr, fmt, ap);
106 | if (fmt[strlen(fmt)-1] != '\n')
107 | fprintf(stderr, "\n");
108 | errcnt++;
109 | va_end(ap);
110 | }
111 |
112 | int yylex(void) {
113 | int c;
114 |
115 | if (code) {
116 | char *p;
117 | bp += strspn(bp, " \t\f");
118 | p = strchr(bp, '\n');
119 | if (p == NULL)
120 | p = strchr(bp, '\n');
121 | while (p > bp && isspace(p[-1]))
122 | p--;
123 | yylval.string = alloc(p - bp + 1);
124 | strncpy(yylval.string, bp, p - bp);
125 | yylval.string[p - bp] = 0;
126 | bp = p;
127 | code--;
128 | return CODE;
129 | }
130 | while ((c = get()) != EOF) {
131 | switch (c) {
132 | case ' ': case '\f': case '\t':
133 | continue;
134 | case '\n':
135 | case '(': case ')': case ',':
136 | case ':': case '=':
137 | return c;
138 | }
139 | if (c == '%' && *bp == '%') {
140 | bp++;
141 | return ppercent++ ? 0 : PPERCENT;
142 | } else if (c == '%' && strncmp(bp, "term", 4) == 0
143 | && isspace(bp[4])) {
144 | bp += 4;
145 | return TERMINAL;
146 | } else if (c == '%' && strncmp(bp, "start", 5) == 0
147 | && isspace(bp[5])) {
148 | bp += 5;
149 | return START;
150 | } else if (c == '"') {
151 | char *p = strchr(bp, '"');
152 | if (p == NULL) {
153 | yyerror("missing \" in assembler template\n");
154 | p = strchr(bp, '\n');
155 | if (p == NULL)
156 | p = strchr(bp, '\0');
157 | }
158 | assert(p);
159 | yylval.string = alloc(p - bp + 1);
160 | strncpy(yylval.string, bp, p - bp);
161 | yylval.string[p - bp] = 0;
162 | bp = *p == '"' ? p + 1 : p;
163 | code++;
164 | return TEMPLATE;
165 | } else if (isdigit(c)) {
166 | int n = 0;
167 | do {
168 | int d = c - '0';
169 | if (n > (INT_MAX - d)/10)
170 | yyerror("integer greater than %d\n", INT_MAX);
171 | else
172 | n = 10*n + d;
173 | c = get();
174 | } while (c != EOF && isdigit(c));
175 | bp--;
176 | yylval.n = n;
177 | return INT;
178 | } else if (isalpha(c)) {
179 | char *p = bp - 1;
180 | while (isalpha(*bp) || isdigit(*bp) || *bp == '_')
181 | bp++;
182 | yylval.string = alloc(bp - p + 1);
183 | strncpy(yylval.string, p, bp - p);
184 | yylval.string[bp - p] = 0;
185 | return ID;
186 | } else if (isprint(c))
187 | yyerror("invalid character `%c'\n", c);
188 | else
189 | yyerror("invalid character `\\%03o'\n", (unsigned char)c);
190 | }
191 | return 0;
192 | }
193 |
194 | void yywarn(char *fmt, ...) {
195 | va_list ap;
196 |
197 | va_start(ap, fmt);
198 | if (yylineno > 0)
199 | fprintf(stderr, "line %d: ", yylineno);
200 | fprintf(stderr, "warning: ");
201 | vfprintf(stderr, fmt, ap);
202 | va_end(ap);
203 | }
204 |
--------------------------------------------------------------------------------
/code/tools/lcc/lburg/lburg.1:
--------------------------------------------------------------------------------
1 | .TH LBURG 1 "local \- 11/30/94"
2 | .\" $Id: lburg.1 145 2001-10-17 21:53:10Z timo $
3 | .SH NAME
4 | lburg \- lcc's code-generator generator
5 | .SH SYNOPSIS
6 | .B lburg
7 | [
8 | .I option
9 | ]...
10 | [ [
11 | .I input
12 | ]
13 | .I output
14 | ]
15 | .br
16 | .SH DESCRIPTION
17 | .PP
18 | .I lburg
19 | reads an lcc-style BURG specification from
20 | .I input
21 | and writes a pattern-matching code generator to
22 | .IR output .
23 | If
24 | .I input
25 | is `\-' or is omitted,
26 | .I lburg
27 | reads the standard input;
28 | If
29 | .I output
30 | is `\-' or is omitted,
31 | .I lburg
32 | writes to the standard output.
33 | .PP
34 | .I lburg
35 | accepts specifications that conform to the following EBNF grammar.
36 | Terminals are enclosed in single quotes or are
37 | given in uppercase, all other symbols are nonterminals or English phrases,
38 | {X} denotes zero or more instances of X, and [X] denotes an optional X.
39 | .PP
40 | .nf
41 | .RS
42 | .ft CW
43 | spec: `%{' configuration `%}' { dcl } `%%' { rule }
44 | [ `%%' C code ]
45 |
46 | dcl: `%start' nonterm
47 | `%term' { ID `=' INT }
48 |
49 | rule: nonterm `:' tree template [ C expression ]
50 |
51 | tree: term `(' tree `,' tree `)'
52 | term `(' tree `)'
53 | term
54 | nonterm
55 |
56 | nonterm: ID
57 |
58 | template: `"' { any character except double quote } `"'
59 | .RE
60 | .fi
61 | .PP
62 | Specifications are structurally similar to
63 | .IR yacc 's.
64 | Text between
65 | `\f(CW%{\fP'
66 | and
67 | `\f(CW%}\fP'
68 | is called the configuration section; there may be several such segments.
69 | All are concatenated and copied verbatim into the head of the output.
70 | Text after the second
71 | `\f(CW%%\fP',
72 | if any, is also copied verbatim into the output, at the end.
73 | .PP
74 | Specifications consist of declarations, a
75 | `\f(CW%%\fP'
76 | separator, and rules.
77 | Input is line-oriented; each declaration and rule must appear on a separate line,
78 | and declarations must begin in column 1.
79 | Declarations declare terminals \(em the operators in subject
80 | trees \(em and associate a unique, positive external symbol
81 | number with each one.
82 | Nonterminals are declared by their presence
83 | on the left side of rules. The
84 | \f(CW%start\fP
85 | declaration optionally declares a nonterminal as the start symbol.
86 | In the grammar above,
87 | \f(CWterm\fP
88 | and
89 | \f(CWnonterm\fP
90 | denote identifiers that are terminals and nonterminals.
91 | .PP
92 | Rules define tree patterns in a fully parenthesized prefix
93 | form. Every nonterminal denotes a tree.
94 | Each operator has a fixed
95 | arity, which is inferred from the rules in which it is used.
96 | A chain rule is a rule whose pattern is another nonterminal.
97 | If no start symbol is declared, the nonterminal defined by the first rule is used.
98 | .PP
99 | Each rule ends with an expression that computes the cost of matching
100 | that rule; omitted costs
101 | default to zero. Costs of chain rules must be constants.
102 | .PP
103 | The configuration section configures the output
104 | for the trees being parsed and the client's environment.
105 | As shown, this section must define
106 | \f(CWNODEPTR_TYPE\fP
107 | to be a visible typedef symbol for a pointer to a
108 | node in the subject tree.
109 | The labeller invokes
110 | \f(CWOP_LABEL(p)\fP,
111 | \f(CWLEFT\_CHILD(p)\fP, and
112 | \f(CWRIGHT\_CHILD(p)\fP
113 | to read the operator and children from the node pointed to by \f(CWp\fP.
114 | If the configuration section defines these operations as macros, they are implemented in-line;
115 | otherwise, they must be implemented as functions.
116 | .PP
117 | The matcher
118 | computes and stores a single integral state in each node of the subject tree.
119 | The configuration section must define a macro
120 | \f(CWSTATE_LABEL(p)\fP
121 | to access the state field of the node pointed to
122 | by \f(CWp\fP. It must be large enough to hold a pointer, and
123 | a macro is required because it is used as an lvalue.
124 | .PP
125 | .SH OPTIONS
126 | .TP
127 | .BI \-p \ prefix
128 | .br
129 | .ns
130 | .TP
131 | .BI \-p prefix
132 | Use
133 | .I prefix
134 | as the disambiquating prefix for visible names and fields.
135 | The default is `\f(CW_\fP'.
136 | .TP
137 | .B \-T
138 | Arrange for
139 | .sp
140 | .nf
141 | .ft CW
142 | void _trace(NODEPTR_TYPE p, int eruleno,
143 | int cost, int bestcost);
144 | .sp
145 | .fi
146 | .ft R
147 | to be called at each successful match.
148 | \f(CWp\fP
149 | identifies the node and
150 | \f(CWeruleno\fP
151 | identifies the matching rule; the rules are numbered
152 | beginning at 1 in the order they appear in the input.
153 | \f(CWcost\fP
154 | is the cost of the match and
155 | \f(CWbestcost\fP
156 | is the cost of the best previous match. The current match
157 | wins only if
158 | \f(CWcost\fP
159 | is less than \f(CWbestcost\fP.
160 | 32767 represents the infinite cost of no previous match.
161 | \f(CW_trace\fP must be declared in the configuration section.
162 | .SH "SEE ALSO"
163 | .IR lcc (1)
164 | .PP
165 | C. W. Fraser and D. R. Hanson,
166 | .IR A Retargetable C Compiler: Design and Implementation ,
167 | Benjamin/Cummings, Redwood City, CA, 1995,
168 | ISBN 0-8053-1670-1. Chapter 14.
169 | .PP
170 | C. W. Fraser, D. R. Hanson and T. A. Proebsting,
171 | `Engineering a simple, efficient code generator generator,'
172 | .I
173 | ACM Letters on Programming Languages and Systems
174 | .BR 1 ,
175 | 3 (Sep. 1992), 213-226.
176 | .br
177 | .SH BUGS
178 | Mail bug reports along with the shortest input
179 | that exposes them to drh@cs.princeton.edu.
180 |
--------------------------------------------------------------------------------
/code/tools/lcc/lburg/lburg.h:
--------------------------------------------------------------------------------
1 | #ifndef BURG_INCLUDED
2 | #define BURG_INCLUDED
3 |
4 | /* iburg.c: */
5 | extern void *alloc(int nbytes);
6 |
7 | typedef enum { TERM=1, NONTERM } Kind;
8 | typedef struct rule *Rule;
9 | typedef struct term *Term;
10 | struct term { /* terminals: */
11 | char *name; /* terminal name */
12 | Kind kind; /* TERM */
13 | int esn; /* external symbol number */
14 | int arity; /* operator arity */
15 | Term link; /* next terminal in esn order */
16 | Rule rules; /* rules whose pattern starts with term */
17 | };
18 |
19 | typedef struct nonterm *Nonterm;
20 | struct nonterm { /* nonterminals: */
21 | char *name; /* nonterminal name */
22 | Kind kind; /* NONTERM */
23 | int number; /* identifying number */
24 | int lhscount; /* # times nt appears in a rule lhs */
25 | int reached; /* 1 iff reached from start nonterminal */
26 | Rule rules; /* rules w/nonterminal on lhs */
27 | Rule chain; /* chain rules w/nonterminal on rhs */
28 | Nonterm link; /* next terminal in number order */
29 | };
30 | extern Nonterm nonterm(char *id);
31 | extern Term term(char *id, int esn);
32 |
33 | typedef struct tree *Tree;
34 | struct tree { /* tree patterns: */
35 | void *op; /* a terminal or nonterminal */
36 | Tree left, right; /* operands */
37 | int nterms; /* number of terminal nodes in this tree */
38 | };
39 | extern Tree tree(char *op, Tree left, Tree right);
40 |
41 | struct rule { /* rules: */
42 | Nonterm lhs; /* lefthand side nonterminal */
43 | Tree pattern; /* rule pattern */
44 | int ern; /* external rule number */
45 | int packed; /* packed external rule number */
46 | int cost; /* cost, if a constant */
47 | char *code; /* cost, if an expression */
48 | char *template; /* assembler template */
49 | Rule link; /* next rule in ern order */
50 | Rule next; /* next rule with same pattern root */
51 | Rule chain; /* next chain rule with same rhs */
52 | Rule decode; /* next rule with same lhs */
53 | Rule kids; /* next rule with same _kids pattern */
54 | };
55 | extern Rule rule(char *id, Tree pattern, char *template, char *code);
56 |
57 | /* gram.y: */
58 | void yyerror(char *fmt, ...);
59 | int yyparse(void);
60 | void yywarn(char *fmt, ...);
61 | extern int errcnt;
62 | extern FILE *infp;
63 | extern FILE *outfp;
64 |
65 | #endif
66 |
--------------------------------------------------------------------------------
/code/tools/lcc/src/alloc.c:
--------------------------------------------------------------------------------
1 | #include "c.h"
2 | struct block {
3 | struct block *next;
4 | char *limit;
5 | char *avail;
6 | };
7 | union align {
8 | long l;
9 | char *p;
10 | double d;
11 | int (*f)(void);
12 | };
13 | union header {
14 | struct block b;
15 | union align a;
16 | };
17 | #ifdef PURIFY
18 | union header *arena[3];
19 |
20 | void *allocate(unsigned long n, unsigned a) {
21 | union header *new = malloc(sizeof *new + n);
22 |
23 | assert(a < NELEMS(arena));
24 | if (new == NULL) {
25 | error("insufficient memory\n");
26 | exit(1);
27 | }
28 | new->b.next = (void *)arena[a];
29 | arena[a] = new;
30 | return new + 1;
31 | }
32 |
33 | void deallocate(unsigned a) {
34 | union header *p, *q;
35 |
36 | assert(a < NELEMS(arena));
37 | for (p = arena[a]; p; p = q) {
38 | q = (void *)p->b.next;
39 | free(p);
40 | }
41 | arena[a] = NULL;
42 | }
43 |
44 | void *newarray(unsigned long m, unsigned long n, unsigned a) {
45 | return allocate(m*n, a);
46 | }
47 | #else
48 | static struct block
49 | first[] = { { NULL }, { NULL }, { NULL } },
50 | *arena[] = { &first[0], &first[1], &first[2] };
51 | static struct block *freeblocks;
52 |
53 | void *allocate(unsigned long n, unsigned a) {
54 | struct block *ap;
55 |
56 | assert(a < NELEMS(arena));
57 | assert(n > 0);
58 | ap = arena[a];
59 | n = roundup(n, sizeof (union align));
60 | while (n > ap->limit - ap->avail) {
61 | if ((ap->next = freeblocks) != NULL) {
62 | freeblocks = freeblocks->next;
63 | ap = ap->next;
64 | } else
65 | {
66 | unsigned m = sizeof (union header) + n + roundup(10*1024, sizeof (union align));
67 | ap->next = malloc(m);
68 | ap = ap->next;
69 | if (ap == NULL) {
70 | error("insufficient memory\n");
71 | exit(1);
72 | }
73 | ap->limit = (char *)ap + m;
74 | }
75 | ap->avail = (char *)((union header *)ap + 1);
76 | ap->next = NULL;
77 | arena[a] = ap;
78 |
79 | }
80 | ap->avail += n;
81 | return ap->avail - n;
82 | }
83 |
84 | void *newarray(unsigned long m, unsigned long n, unsigned a) {
85 | return allocate(m*n, a);
86 | }
87 | void deallocate(unsigned a) {
88 | assert(a < NELEMS(arena));
89 | arena[a]->next = freeblocks;
90 | freeblocks = first[a].next;
91 | first[a].next = NULL;
92 | arena[a] = &first[a];
93 | }
94 | #endif
95 |
--------------------------------------------------------------------------------
/code/tools/lcc/src/bind.c:
--------------------------------------------------------------------------------
1 | #include "c.h"
2 | extern Interface nullIR;
3 | extern Interface bytecodeIR;
4 | Binding bindings[] = {
5 | { "null", &nullIR },
6 | { "bytecode", &bytecodeIR },
7 | { NULL, NULL },
8 | };
9 |
--------------------------------------------------------------------------------
/code/tools/lcc/src/config.h:
--------------------------------------------------------------------------------
1 | typedef struct {
2 | unsigned char max_unaligned_load;
3 | Symbol (*rmap)(int);
4 |
5 | void (*blkfetch)(int size, int off, int reg, int tmp);
6 | void (*blkstore)(int size, int off, int reg, int tmp);
7 | void (*blkloop)(int dreg, int doff,
8 | int sreg, int soff,
9 | int size, int tmps[]);
10 | void (*_label)(Node);
11 | int (*_rule)(void*, int);
12 | short **_nts;
13 | void (*_kids)(Node, int, Node*);
14 | char **_string;
15 | char **_templates;
16 | char *_isinstruction;
17 | char **_ntname;
18 | void (*emit2)(Node);
19 | void (*doarg)(Node);
20 | void (*target)(Node);
21 | void (*clobber)(Node);
22 | } Xinterface;
23 | extern int askregvar(Symbol, Symbol);
24 | extern void blkcopy(int, int, int, int, int, int[]);
25 | extern int getregnum(Node);
26 | extern int mayrecalc(Node);
27 | extern int mkactual(int, int);
28 | extern void mkauto(Symbol);
29 | extern Symbol mkreg(char *, int, int, int);
30 | extern Symbol mkwildcard(Symbol *);
31 | extern int move(Node);
32 | extern int notarget(Node);
33 | extern void parseflags(int, char **);
34 | extern int range(Node, int, int);
35 | extern unsigned regloc(Symbol); /* omit */
36 | extern void rtarget(Node, int, Symbol);
37 | extern void setreg(Node, Symbol);
38 | extern void spill(unsigned, int, Node);
39 | extern int widens(Node);
40 |
41 | extern int argoffset, maxargoffset;
42 | extern int bflag, dflag;
43 | extern int dalign, salign;
44 | extern int framesize;
45 | extern unsigned freemask[], usedmask[];
46 | extern int offset, maxoffset;
47 | extern int swap;
48 | extern unsigned tmask[], vmask[];
49 | typedef struct {
50 | unsigned listed:1;
51 | unsigned registered:1;
52 | unsigned emitted:1;
53 | unsigned copy:1;
54 | unsigned equatable:1;
55 | unsigned spills:1;
56 | unsigned mayrecalc:1;
57 | void *state;
58 | short inst;
59 | Node kids[3];
60 | Node prev, next;
61 | Node prevuse;
62 | short argno;
63 | } Xnode;
64 | typedef struct {
65 | Symbol vbl;
66 | short set;
67 | short number;
68 | unsigned mask;
69 | } *Regnode;
70 | enum { IREG=0, FREG=1 };
71 | typedef struct {
72 | char *name;
73 | unsigned int eaddr; /* omit */
74 | int offset;
75 | Node lastuse;
76 | int usecount;
77 | Regnode regnode;
78 | Symbol *wildcard;
79 | } Xsymbol;
80 | enum { RX=2 };
81 | typedef struct {
82 | int offset;
83 | unsigned freemask[2];
84 | } Env;
85 |
86 | #define LBURG_MAX SHRT_MAX
87 |
88 | enum { VREG=(44<<4) };
89 |
90 | /* Exported for the front end */
91 | extern void blockbeg(Env *);
92 | extern void blockend(Env *);
93 | extern void emit(Node);
94 | extern Node gen(Node);
95 |
96 | extern unsigned emitbin(Node, int);
97 |
98 | #ifdef NDEBUG
99 | #define debug(x) (void)0
100 | #else
101 | #define debug(x) (void)(dflag&&((x),0))
102 | #endif
103 |
--------------------------------------------------------------------------------
/code/tools/lcc/src/dagcheck.md:
--------------------------------------------------------------------------------
1 | %{
2 | #include "c.h"
3 | typedef Node NODEPTR_TYPE;
4 | #define OP_LABEL(p) (specific((p)->op))
5 | #define LEFT_CHILD(p) ((p)->kids[0])
6 | #define RIGHT_CHILD(p) ((p)->kids[1])
7 | #define STATE_LABEL(p) ((p)->x.state)
8 | #define PANIC error
9 | %}
10 | %term CNSTF=17 CNSTI=21 CNSTP=23 CNSTU=22
11 | %term ARGB=41 ARGF=33 ARGI=37 ARGP=39 ARGU=38
12 | %term ASGNB=57 ASGNF=49 ASGNI=53 ASGNP=55 ASGNU=54
13 | %term INDIRB=73 INDIRF=65 INDIRI=69 INDIRP=71 INDIRU=70
14 | %term CVFF=113 CVFI=117
15 | %term CVIF=129 CVII=133 CVIU=134
16 | %term CVPP=151 CVPU=150
17 | %term CVUI=181 CVUP=183 CVUU=182
18 | %term NEGF=193 NEGI=197
19 | %term CALLB=217 CALLF=209 CALLI=213 CALLP=215 CALLU=214 CALLV=216
20 | %term RETF=241 RETI=245 RETP=247 RETU=246 RETV=248
21 | %term ADDRGP=263
22 | %term ADDRFP=279
23 | %term ADDRLP=295
24 | %term ADDF=305 ADDI=309 ADDP=311 ADDU=310
25 | %term SUBF=321 SUBI=325 SUBP=327 SUBU=326
26 | %term LSHI=341 LSHU=342
27 | %term MODI=357 MODU=358
28 | %term RSHI=373 RSHU=374
29 | %term BANDI=389 BANDU=390
30 | %term BCOMI=405 BCOMU=406
31 | %term BORI=421 BORU=422
32 | %term BXORI=437 BXORU=438
33 | %term DIVF=449 DIVI=453 DIVU=454
34 | %term MULF=465 MULI=469 MULU=470
35 | %term EQF=481 EQI=485 EQU=486
36 | %term GEF=497 GEI=501 GEU=502
37 | %term GTF=513 GTI=517 GTU=518
38 | %term LEF=529 LEI=533 LEU=534
39 | %term LTF=545 LTI=549 LTU=550
40 | %term NEF=561 NEI=565 NEU=566
41 | %term JUMPV=584
42 | %term LABELV=600
43 | %%
44 | stmt: INDIRB(P) ""
45 | stmt: INDIRF(P) ""
46 | stmt: INDIRI(P) ""
47 | stmt: INDIRU(P) ""
48 | stmt: INDIRP(P) ""
49 | stmt: CALLF(P) ""
50 | stmt: CALLI(P) ""
51 | stmt: CALLU(P) ""
52 | stmt: CALLP(P) ""
53 | stmt: V ""
54 | bogus: I "" 1
55 | bogus: U "" 1
56 | bogus: P "" 1
57 | bogus: F "" 1
58 | bogus: B "" 1
59 | bogus: V "" 1
60 | I: bogus "" 1
61 | U: bogus "" 1
62 | P: bogus "" 1
63 | F: bogus "" 1
64 | B: bogus "" 1
65 | V: bogus "" 1
66 | F: CNSTF ""
67 | I: CNSTI ""
68 | P: CNSTP ""
69 | U: CNSTU ""
70 | V: ARGB(B) ""
71 | V: ARGF(F) ""
72 | V: ARGI(I) ""
73 | V: ARGU(U) ""
74 | V: ARGP(P) ""
75 | V: ASGNB(P,B) ""
76 | V: ASGNF(P,F) ""
77 | V: ASGNI(P,I) ""
78 | V: ASGNU(P,U) ""
79 | V: ASGNP(P,P) ""
80 | B: INDIRB(P) ""
81 | F: INDIRF(P) ""
82 | I: INDIRI(P) ""
83 | U: INDIRU(P) ""
84 | P: INDIRP(P) ""
85 | I: CVII(I) ""
86 | I: CVUI(U) ""
87 | I: CVFI(F) ""
88 | U: CVIU(I) ""
89 | U: CVUU(U) ""
90 | U: CVPU(P) ""
91 | F: CVIF(I) ""
92 | F: CVFF(F) ""
93 | P: CVUP(U) ""
94 | P: CVPP(P) ""
95 | F: NEGF(F) ""
96 | I: NEGI(I) ""
97 | V: CALLB(P,P) ""
98 | F: CALLF(P) ""
99 | I: CALLI(P) ""
100 | U: CALLU(P) ""
101 | P: CALLP(P) ""
102 | V: CALLV(P) ""
103 | V: RETF(F) ""
104 | V: RETI(I) ""
105 | V: RETU(U) ""
106 | V: RETP(P) ""
107 | V: RETV ""
108 | P: ADDRGP ""
109 | P: ADDRFP ""
110 | P: ADDRLP ""
111 | F: ADDF(F,F) ""
112 | I: ADDI(I,I) ""
113 | P: ADDP(P,I) ""
114 | P: ADDP(I,P) ""
115 | P: ADDP(U,P) ""
116 | P: ADDP(P,U) ""
117 | U: ADDU(U,U) ""
118 | F: SUBF(F,F) ""
119 | I: SUBI(I,I) ""
120 | P: SUBP(P,I) ""
121 | P: SUBP(P,U) ""
122 | U: SUBU(U,U) ""
123 | I: LSHI(I,I) ""
124 | U: LSHU(U,I) ""
125 | I: MODI(I,I) ""
126 | U: MODU(U,U) ""
127 | I: RSHI(I,I) ""
128 | U: RSHU(U,I) ""
129 | U: BANDU(U,U) ""
130 | I: BANDI(I,I) ""
131 | U: BCOMU(U) ""
132 | I: BCOMI(I) ""
133 | I: BORI(I,I) ""
134 | U: BORU(U,U) ""
135 | U: BXORU(U,U) ""
136 | I: BXORI(I,I) ""
137 | F: DIVF(F,F) ""
138 | I: DIVI(I,I) ""
139 | U: DIVU(U,U) ""
140 | F: MULF(F,F) ""
141 | I: MULI(I,I) ""
142 | U: MULU(U,U) ""
143 | V: EQF(F,F) ""
144 | V: EQI(I,I) ""
145 | V: EQU(U,U) ""
146 | V: GEF(F,F) ""
147 | V: GEI(I,I) ""
148 | V: GEU(U,U) ""
149 | V: GTF(F,F) ""
150 | V: GTI(I,I) ""
151 | V: GTU(U,U) ""
152 | V: LEF(F,F) ""
153 | V: LEI(I,I) ""
154 | V: LEU(U,U) ""
155 | V: LTF(F,F) ""
156 | V: LTI(I,I) ""
157 | V: LTU(U,U) ""
158 | V: NEF(F,F) ""
159 | V: NEI(I,I) ""
160 | V: NEU(U,U) ""
161 | V: JUMPV(P) ""
162 | V: LABELV ""
163 | %%
164 |
165 | static void reduce(NODEPTR_TYPE p, int goalnt) {
166 | int i, sz = opsize(p->op), rulenumber = _rule(p->x.state, goalnt);
167 | short *nts = _nts[rulenumber];
168 | NODEPTR_TYPE kids[10];
169 |
170 | assert(rulenumber);
171 | _kids(p, rulenumber, kids);
172 | for (i = 0; nts[i]; i++)
173 | reduce(kids[i], nts[i]);
174 | switch (optype(p->op)) {
175 | #define xx(ty) if (sz == ty->size) return
176 | case I:
177 | case U:
178 | xx(chartype);
179 | xx(shorttype);
180 | xx(inttype);
181 | xx(longtype);
182 | xx(longlong);
183 | break;
184 | case F:
185 | xx(floattype);
186 | xx(doubletype);
187 | xx(longdouble);
188 | break;
189 | case P:
190 | xx(voidptype);
191 | xx(funcptype);
192 | break;
193 | case V:
194 | case B: if (sz == 0) return;
195 | #undef xx
196 | }
197 | printdag(p, 2);
198 | assert(0);
199 | }
200 |
201 | void check(Node p) {
202 | struct _state { short cost[1]; };
203 |
204 | _label(p);
205 | if (((struct _state *)p->x.state)->cost[1] > 0) {
206 | printdag(p, 2);
207 | assert(0);
208 | }
209 | reduce(p, 1);
210 | }
211 |
--------------------------------------------------------------------------------
/code/tools/lcc/src/error.c:
--------------------------------------------------------------------------------
1 | #include "c.h"
2 |
3 |
4 | static void printtoken(void);
5 | int errcnt = 0;
6 | int errlimit = 20;
7 | char kind[] = {
8 | #define xx(a,b,c,d,e,f,g) f,
9 | #define yy(a,b,c,d,e,f,g) f,
10 | #include "token.h"
11 | };
12 | int wflag; /* != 0 to suppress warning messages */
13 |
14 | void test(int tok, char set[]) {
15 | if (t == tok)
16 | t = gettok();
17 | else {
18 | expect(tok);
19 | skipto(tok, set);
20 | if (t == tok)
21 | t = gettok();
22 | }
23 | }
24 | void expect(int tok) {
25 | if (t == tok)
26 | t = gettok();
27 | else {
28 | error("syntax error; found");
29 | printtoken();
30 | fprint(stderr, " expecting `%k'\n", tok);
31 | }
32 | }
33 | void error(const char *fmt, ...) {
34 | va_list ap;
35 |
36 | if (errcnt++ >= errlimit) {
37 | errcnt = -1;
38 | error("too many errors\n");
39 | exit(1);
40 | }
41 | va_start(ap, fmt);
42 | if (firstfile != file && firstfile && *firstfile)
43 | fprint(stderr, "%s: ", firstfile);
44 | fprint(stderr, "%w: ", &src);
45 | vfprint(stderr, NULL, fmt, ap);
46 | va_end(ap);
47 | }
48 |
49 | void skipto(int tok, char set[]) {
50 | int n;
51 | char *s;
52 |
53 | assert(set);
54 | for (n = 0; t != EOI && t != tok; t = gettok()) {
55 | for (s = set; *s && kind[t] != *s; s++)
56 | ;
57 | if (kind[t] == *s)
58 | break;
59 | if (n++ == 0)
60 | error("skipping");
61 | if (n <= 8)
62 | printtoken();
63 | else if (n == 9)
64 | fprint(stderr, " ...");
65 | }
66 | if (n > 8) {
67 | fprint(stderr, " up to");
68 | printtoken();
69 | }
70 | if (n > 0)
71 | fprint(stderr, "\n");
72 | }
73 | /* fatal - issue fatal error message and exit */
74 | int fatal(const char *name, const char *fmt, int n) {
75 | print("\n");
76 | errcnt = -1;
77 | error("compiler error in %s--", name);
78 | fprint(stderr, fmt, n);
79 | exit(EXIT_FAILURE);
80 | return 0;
81 | }
82 |
83 | /* printtoken - print current token preceded by a space */
84 | static void printtoken(void) {
85 | switch (t) {
86 | case ID: fprint(stderr, " `%s'", token); break;
87 | case ICON:
88 | fprint(stderr, " `%s'", vtoa(tsym->type, tsym->u.c.v));
89 | break;
90 | case SCON: {
91 | int i, n;
92 | if (ischar(tsym->type->type)) {
93 | char *s = tsym->u.c.v.p;
94 | n = tsym->type->size;
95 | fprint(stderr, " \"");
96 | for (i = 0; i < 20 && i < n && *s; s++, i++)
97 | if (*s < ' ' || *s >= 0177)
98 | fprint(stderr, "\\%o", *s);
99 | else
100 | fprint(stderr, "%c", *s);
101 | } else { /* wchar_t string */
102 | unsigned int *s = tsym->u.c.v.p;
103 | assert(tsym->type->type->size == widechar->size);
104 | n = tsym->type->size/widechar->size;
105 | fprint(stderr, " L\"");
106 | for (i = 0; i < 20 && i < n && *s; s++, i++)
107 | if (*s < ' ' || *s >= 0177)
108 | fprint(stderr, "\\x%x", *s);
109 | else
110 | fprint(stderr, "%c", *s);
111 | }
112 | if (i < n)
113 | fprint(stderr, " ...");
114 | else
115 | fprint(stderr, "\"");
116 | break;
117 | }
118 | case FCON:
119 | fprint(stderr, " `%S'", token, (char*)cp - token);
120 | break;
121 | case '`': case '\'': fprint(stderr, " \"%k\"", t); break;
122 | default: fprint(stderr, " `%k'", t);
123 | }
124 | }
125 |
126 | /* warning - issue warning error message */
127 | void warning(const char *fmt, ...) {
128 | va_list ap;
129 |
130 | va_start(ap, fmt);
131 | if (wflag == 0) {
132 | errcnt--;
133 | error("warning: ");
134 | vfprint(stderr, NULL, fmt, ap);
135 | }
136 | va_end(ap);
137 | }
138 |
--------------------------------------------------------------------------------
/code/tools/lcc/src/event.c:
--------------------------------------------------------------------------------
1 | #include "c.h"
2 |
3 |
4 | struct entry {
5 | Apply func;
6 | void *cl;
7 | };
8 |
9 | Events events;
10 | void attach(Apply func, void *cl, List *list) {
11 | struct entry *p;
12 |
13 | NEW(p, PERM);
14 | p->func = func;
15 | p->cl = cl;
16 | *list = append(p, *list);
17 | }
18 | void apply(List event, void *arg1, void *arg2) {
19 | if (event) {
20 | List lp = event;
21 | do {
22 | struct entry *p = lp->x;
23 | (*p->func)(p->cl, arg1, arg2);
24 | lp = lp->link;
25 | } while (lp != event);
26 | }
27 | }
28 |
29 |
--------------------------------------------------------------------------------
/code/tools/lcc/src/inits.c:
--------------------------------------------------------------------------------
1 | void init(int argc, char *argv[]) {
2 | {extern void input_init(int, char *[]); input_init(argc, argv);}
3 | {extern void main_init(int, char *[]); main_init(argc, argv);}
4 | {extern void prof_init(int, char *[]); prof_init(argc, argv);}
5 | {extern void trace_init(int, char *[]); trace_init(argc, argv);}
6 | {extern void type_init(int, char *[]); type_init(argc, argv);}
7 | }
8 |
--------------------------------------------------------------------------------
/code/tools/lcc/src/input.c:
--------------------------------------------------------------------------------
1 | #include "c.h"
2 |
3 |
4 | static void pragma(void);
5 | static void resynch(void);
6 |
7 | static int bsize;
8 | static unsigned char buffer[MAXLINE+1 + BUFSIZE+1];
9 | unsigned char *cp; /* current input character */
10 | char *file; /* current input file name */
11 | char *firstfile; /* first input file */
12 | unsigned char *limit; /* points to last character + 1 */
13 | char *line; /* current line */
14 | int lineno; /* line number of current line */
15 |
16 | void nextline(void) {
17 | do {
18 | if (cp >= limit) {
19 | fillbuf();
20 | if (cp >= limit)
21 | cp = limit;
22 | if (cp == limit)
23 | return;
24 | } else {
25 | lineno++;
26 | for (line = (char *)cp; *cp==' ' || *cp=='\t'; cp++)
27 | ;
28 | if (*cp == '#') {
29 | resynch();
30 | nextline();
31 | }
32 | }
33 | } while (*cp == '\n' && cp == limit);
34 | }
35 | void fillbuf(void) {
36 | if (bsize == 0)
37 | return;
38 | if (cp >= limit)
39 | cp = &buffer[MAXLINE+1];
40 | else
41 | {
42 | int n = limit - cp;
43 | unsigned char *s = &buffer[MAXLINE+1] - n;
44 | assert(s >= buffer);
45 | line = (char *)s - ((char *)cp - line);
46 | while (cp < limit)
47 | *s++ = *cp++;
48 | cp = &buffer[MAXLINE+1] - n;
49 | }
50 | if (feof(stdin))
51 | bsize = 0;
52 | else
53 | bsize = fread(&buffer[MAXLINE+1], 1, BUFSIZE, stdin);
54 | if (bsize < 0) {
55 | error("read error\n");
56 | exit(EXIT_FAILURE);
57 | }
58 | limit = &buffer[MAXLINE+1+bsize];
59 | *limit = '\n';
60 | }
61 | void input_init(int argc, char *argv[]) {
62 | static int inited;
63 |
64 | if (inited)
65 | return;
66 | inited = 1;
67 | main_init(argc, argv);
68 | limit = cp = &buffer[MAXLINE+1];
69 | bsize = -1;
70 | lineno = 0;
71 | file = NULL;
72 | fillbuf();
73 | if (cp >= limit)
74 | cp = limit;
75 | nextline();
76 | }
77 |
78 | /* pragma - handle #pragma ref id... */
79 | static void pragma(void) {
80 | if ((t = gettok()) == ID && strcmp(token, "ref") == 0)
81 | for (;;) {
82 | while (*cp == ' ' || *cp == '\t')
83 | cp++;
84 | if (*cp == '\n' || *cp == 0)
85 | break;
86 | if ((t = gettok()) == ID && tsym) {
87 | tsym->ref++;
88 | use(tsym, src);
89 | }
90 | }
91 | }
92 |
93 | /* resynch - set line number/file name in # n [ "file" ] and #pragma ... */
94 | static void resynch(void) {
95 | for (cp++; *cp == ' ' || *cp == '\t'; )
96 | cp++;
97 | if (limit - cp < MAXLINE)
98 | fillbuf();
99 | if (strncmp((char *)cp, "pragma", 6) == 0) {
100 | cp += 6;
101 | pragma();
102 | } else if (*cp >= '0' && *cp <= '9') {
103 | line: for (lineno = 0; *cp >= '0' && *cp <= '9'; )
104 | lineno = 10*lineno + *cp++ - '0';
105 | lineno--;
106 | while (*cp == ' ' || *cp == '\t')
107 | cp++;
108 | if (*cp == '"') {
109 | file = (char *)++cp;
110 | while (*cp && *cp != '"' && *cp != '\n')
111 | cp++;
112 | file = stringn(file, (char *)cp - file);
113 | if (*cp == '\n')
114 | warning("missing \" in preprocessor line\n");
115 | if (firstfile == 0)
116 | firstfile = file;
117 | }
118 | } else if (strncmp((char *)cp, "line", 4) == 0) {
119 | for (cp += 4; *cp == ' ' || *cp == '\t'; )
120 | cp++;
121 | if (*cp >= '0' && *cp <= '9')
122 | goto line;
123 | if (Aflag >= 2)
124 | warning("unrecognized control line\n");
125 | } else if (Aflag >= 2 && *cp != '\n')
126 | warning("unrecognized control line\n");
127 | while (*cp)
128 | if (*cp++ == '\n') {
129 | if (cp == limit + 1)
130 | nextline();
131 | else
132 | break;
133 | }
134 | }
135 |
136 |
--------------------------------------------------------------------------------
/code/tools/lcc/src/list.c:
--------------------------------------------------------------------------------
1 | #include "c.h"
2 |
3 |
4 | static List freenodes; /* free list nodes */
5 |
6 | /* append - append x to list, return new list */
7 | List append(void *x, List list) {
8 | List new;
9 |
10 | if ((new = freenodes) != NULL)
11 | freenodes = freenodes->link;
12 | else
13 | NEW(new, PERM);
14 | if (list) {
15 | new->link = list->link;
16 | list->link = new;
17 | } else
18 | new->link = new;
19 | new->x = x;
20 | return new;
21 | }
22 |
23 | /* length - # elements in list */
24 | int length(List list) {
25 | int n = 0;
26 |
27 | if (list) {
28 | List lp = list;
29 | do
30 | n++;
31 | while ((lp = lp->link) != list);
32 | }
33 | return n;
34 | }
35 |
36 | /* ltov - convert list to a NULL-terminated vector allocated in arena */
37 | void *ltov(List *list, unsigned arena) {
38 | int i = 0;
39 | void **array = newarray(length(*list) + 1, sizeof array[0], arena);
40 |
41 | if (*list) {
42 | List lp = *list;
43 | do {
44 | lp = lp->link;
45 | array[i++] = lp->x;
46 | } while (lp != *list);
47 | #ifndef PURIFY
48 | lp = (*list)->link;
49 | (*list)->link = freenodes;
50 | freenodes = lp;
51 | #endif
52 | }
53 | *list = NULL;
54 | array[i] = NULL;
55 | return array;
56 | }
57 |
--------------------------------------------------------------------------------
/code/tools/lcc/src/null.c:
--------------------------------------------------------------------------------
1 | #include "c.h"
2 | #define I(f) null_##f
3 |
4 | static Node I(gen)(Node p) { return p; }
5 | static void I(address)(Symbol q, Symbol p, long n) {}
6 | static void I(blockbeg)(Env *e) {}
7 | static void I(blockend)(Env *e) {}
8 | static void I(defaddress)(Symbol p) {}
9 | static void I(defconst)(int suffix, int size, Value v) {}
10 | static void I(defstring)(int len, char *s) {}
11 | static void I(defsymbol)(Symbol p) {}
12 | static void I(emit)(Node p) {}
13 | static void I(export)(Symbol p) {}
14 | static void I(function)(Symbol f, Symbol caller[], Symbol callee[], int ncalls) {}
15 | static void I(global)(Symbol p) {}
16 | static void I(import)(Symbol p) {}
17 | static void I(local)(Symbol p) {}
18 | static void I(progbeg)(int argc, char *argv[]) {}
19 | static void I(progend)(void) {}
20 | static void I(segment)(int s) {}
21 | static void I(space)(int n) {}
22 | static void I(stabblock)(int brace, int lev, Symbol *p) {}
23 | static void I(stabend)(Coordinate *cp, Symbol p, Coordinate **cpp, Symbol *sp, Symbol *stab) {}
24 | static void I(stabfend)(Symbol p, int lineno) {}
25 | static void I(stabinit)(char *file, int argc, char *argv[]) {}
26 | static void I(stabline)(Coordinate *cp) {}
27 | static void I(stabsym)(Symbol p) {}
28 | static void I(stabtype)(Symbol p) {}
29 |
30 |
31 | Interface nullIR = {
32 | {1, 1, 0}, /* char */
33 | {2, 2, 0}, /* short */
34 | {4, 4, 0}, /* int */
35 | {8, 8, 1}, /* long */
36 | {8 ,8, 1}, /* long long */
37 | {4, 4, 1}, /* float */
38 | {8, 8, 1}, /* double */
39 | {16,16,1}, /* long double */
40 | {4, 4, 0}, /* T* */
41 | {0, 4, 0}, /* struct */
42 | 1, /* little_endian */
43 | 0, /* mulops_calls */
44 | 0, /* wants_callb */
45 | 0, /* wants_argb */
46 | 1, /* left_to_right */
47 | 0, /* wants_dag */
48 | 0, /* unsigned_char */
49 | I(address),
50 | I(blockbeg),
51 | I(blockend),
52 | I(defaddress),
53 | I(defconst),
54 | I(defstring),
55 | I(defsymbol),
56 | I(emit),
57 | I(export),
58 | I(function),
59 | I(gen),
60 | I(global),
61 | I(import),
62 | I(local),
63 | I(progbeg),
64 | I(progend),
65 | I(segment),
66 | I(space),
67 | I(stabblock),
68 | I(stabend),
69 | I(stabfend),
70 | I(stabinit),
71 | I(stabline),
72 | I(stabsym),
73 | I(stabtype)
74 | };
75 |
--------------------------------------------------------------------------------
/code/tools/lcc/src/output.c:
--------------------------------------------------------------------------------
1 | #include "c.h"
2 |
3 |
4 | static char *outs(const char *str, FILE *f, char *bp) {
5 | if (f)
6 | fputs(str, f);
7 | else
8 | while ((*bp = *str++))
9 | bp++;
10 | return bp;
11 | }
12 |
13 | static char *outd(long n, FILE *f, char *bp) {
14 | unsigned long m;
15 | char buf[25], *s = buf + sizeof buf;
16 |
17 | *--s = '\0';
18 | if (n < 0)
19 | m = -n;
20 | else
21 | m = n;
22 | do
23 | *--s = m%10 + '0';
24 | while ((m /= 10) != 0);
25 | if (n < 0)
26 | *--s = '-';
27 | return outs(s, f, bp);
28 | }
29 |
30 | static char *outu(unsigned long n, int base, FILE *f, char *bp) {
31 | char buf[25], *s = buf + sizeof buf;
32 |
33 | *--s = '\0';
34 | do
35 | *--s = "0123456789abcdef"[n%base];
36 | while ((n /= base) != 0);
37 | return outs(s, f, bp);
38 | }
39 | void print(const char *fmt, ...) {
40 | va_list ap;
41 |
42 | va_start(ap, fmt);
43 | vfprint(stdout, NULL, fmt, ap);
44 | va_end(ap);
45 | }
46 | /* fprint - formatted output to f */
47 | void fprint(FILE *f, const char *fmt, ...) {
48 | va_list ap;
49 |
50 | va_start(ap, fmt);
51 | vfprint(f, NULL, fmt, ap);
52 | va_end(ap);
53 | }
54 |
55 | /* stringf - formatted output to a saved string */
56 | char *stringf(const char *fmt, ...) {
57 | char buf[1024];
58 | va_list ap;
59 |
60 | va_start(ap, fmt);
61 | vfprint(NULL, buf, fmt, ap);
62 | va_end(ap);
63 | return string(buf);
64 | }
65 |
66 | /* vfprint - formatted output to f or string bp */
67 | void vfprint(FILE *f, char *bp, const char *fmt, va_list ap) {
68 | for (; *fmt; fmt++)
69 | if (*fmt == '%')
70 | switch (*++fmt) {
71 | case 'd': bp = outd(va_arg(ap, int), f, bp); break;
72 | case 'D': bp = outd(va_arg(ap, long), f, bp); break;
73 | case 'U': bp = outu(va_arg(ap, unsigned long), 10, f, bp); break;
74 | case 'u': bp = outu(va_arg(ap, unsigned), 10, f, bp); break;
75 | case 'o': bp = outu(va_arg(ap, unsigned), 8, f, bp); break;
76 | case 'X': bp = outu(va_arg(ap, unsigned long), 16, f, bp); break;
77 | case 'x': bp = outu(va_arg(ap, unsigned), 16, f, bp); break;
78 | case 'f': case 'e':
79 | case 'g': {
80 | static char format[] = "%f";
81 | char buf[128];
82 | format[1] = *fmt;
83 | sprintf(buf, format, va_arg(ap, double));
84 | bp = outs(buf, f, bp);
85 | }
86 | ; break;
87 | case 's': bp = outs(va_arg(ap, char *), f, bp); break;
88 | case 'p': {
89 | void *p = va_arg(ap, void *);
90 | if (p)
91 | bp = outs("0x", f, bp);
92 | bp = outu((unsigned long)p, 16, f, bp);
93 | break;
94 | }
95 | case 'c': if (f) fputc(va_arg(ap, int), f); else *bp++ = va_arg(ap, int); break;
96 | case 'S': { char *s = va_arg(ap, char *);
97 | int n = va_arg(ap, int);
98 | if (s) {
99 | for ( ; n-- > 0; s++)
100 | if (f) (void)putc(*s, f); else *bp++ = *s;
101 | }
102 | } break;
103 | case 'k': { int t = va_arg(ap, int);
104 | static char *tokens[] = {
105 | #define xx(a,b,c,d,e,f,g) g,
106 | #define yy(a,b,c,d,e,f,g) g,
107 | #include "token.h"
108 | };
109 | assert(tokens[t&0177]);
110 | bp = outs(tokens[t&0177], f, bp);
111 | } break;
112 | case 't': { Type ty = va_arg(ap, Type);
113 | assert(f);
114 | outtype(ty ? ty : voidtype, f);
115 | } break;
116 | case 'w': { Coordinate *p = va_arg(ap, Coordinate *);
117 | if (p->file && *p->file) {
118 | bp = outs(p->file, f, bp);
119 | bp = outs(":", f, bp);
120 | }
121 | bp = outd(p->y, f, bp);
122 | } break;
123 | case 'I': { int n = va_arg(ap, int);
124 | while (--n >= 0)
125 | if (f) (void)putc(' ', f); else *bp++ = ' ';
126 | } break;
127 | default: if (f) (void)putc(*fmt, f); else *bp++ = *fmt; break;
128 | }
129 | else if (f)
130 | (void)putc(*fmt, f);
131 | else
132 | *bp++ = *fmt;
133 | if (!f)
134 | *bp = '\0';
135 | }
136 |
--------------------------------------------------------------------------------
/code/tools/lcc/src/string.c:
--------------------------------------------------------------------------------
1 | #include "c.h"
2 |
3 |
4 | static struct string {
5 | char *str;
6 | int len;
7 | struct string *link;
8 | } *buckets[1024];
9 | static int scatter[] = { /* map characters to random values */
10 | 2078917053, 143302914, 1027100827, 1953210302, 755253631,
11 | 2002600785, 1405390230, 45248011, 1099951567, 433832350,
12 | 2018585307, 438263339, 813528929, 1703199216, 618906479,
13 | 573714703, 766270699, 275680090, 1510320440, 1583583926,
14 | 1723401032, 1965443329, 1098183682, 1636505764, 980071615,
15 | 1011597961, 643279273, 1315461275, 157584038, 1069844923,
16 | 471560540, 89017443, 1213147837, 1498661368, 2042227746,
17 | 1968401469, 1353778505, 1300134328, 2013649480, 306246424,
18 | 1733966678, 1884751139, 744509763, 400011959, 1440466707,
19 | 1363416242, 973726663, 59253759, 1639096332, 336563455,
20 | 1642837685, 1215013716, 154523136, 593537720, 704035832,
21 | 1134594751, 1605135681, 1347315106, 302572379, 1762719719,
22 | 269676381, 774132919, 1851737163, 1482824219, 125310639,
23 | 1746481261, 1303742040, 1479089144, 899131941, 1169907872,
24 | 1785335569, 485614972, 907175364, 382361684, 885626931,
25 | 200158423, 1745777927, 1859353594, 259412182, 1237390611,
26 | 48433401, 1902249868, 304920680, 202956538, 348303940,
27 | 1008956512, 1337551289, 1953439621, 208787970, 1640123668,
28 | 1568675693, 478464352, 266772940, 1272929208, 1961288571,
29 | 392083579, 871926821, 1117546963, 1871172724, 1771058762,
30 | 139971187, 1509024645, 109190086, 1047146551, 1891386329,
31 | 994817018, 1247304975, 1489680608, 706686964, 1506717157,
32 | 579587572, 755120366, 1261483377, 884508252, 958076904,
33 | 1609787317, 1893464764, 148144545, 1415743291, 2102252735,
34 | 1788268214, 836935336, 433233439, 2055041154, 2109864544,
35 | 247038362, 299641085, 834307717, 1364585325, 23330161,
36 | 457882831, 1504556512, 1532354806, 567072918, 404219416,
37 | 1276257488, 1561889936, 1651524391, 618454448, 121093252,
38 | 1010757900, 1198042020, 876213618, 124757630, 2082550272,
39 | 1834290522, 1734544947, 1828531389, 1982435068, 1002804590,
40 | 1783300476, 1623219634, 1839739926, 69050267, 1530777140,
41 | 1802120822, 316088629, 1830418225, 488944891, 1680673954,
42 | 1853748387, 946827723, 1037746818, 1238619545, 1513900641,
43 | 1441966234, 367393385, 928306929, 946006977, 985847834,
44 | 1049400181, 1956764878, 36406206, 1925613800, 2081522508,
45 | 2118956479, 1612420674, 1668583807, 1800004220, 1447372094,
46 | 523904750, 1435821048, 923108080, 216161028, 1504871315,
47 | 306401572, 2018281851, 1820959944, 2136819798, 359743094,
48 | 1354150250, 1843084537, 1306570817, 244413420, 934220434,
49 | 672987810, 1686379655, 1301613820, 1601294739, 484902984,
50 | 139978006, 503211273, 294184214, 176384212, 281341425,
51 | 228223074, 147857043, 1893762099, 1896806882, 1947861263,
52 | 1193650546, 273227984, 1236198663, 2116758626, 489389012,
53 | 593586330, 275676551, 360187215, 267062626, 265012701,
54 | 719930310, 1621212876, 2108097238, 2026501127, 1865626297,
55 | 894834024, 552005290, 1404522304, 48964196, 5816381,
56 | 1889425288, 188942202, 509027654, 36125855, 365326415,
57 | 790369079, 264348929, 513183458, 536647531, 13672163,
58 | 313561074, 1730298077, 286900147, 1549759737, 1699573055,
59 | 776289160, 2143346068, 1975249606, 1136476375, 262925046,
60 | 92778659, 1856406685, 1884137923, 53392249, 1735424165,
61 | 1602280572
62 | };
63 | char *string(const char *str) {
64 | const char *s;
65 |
66 | for (s = str; *s; s++)
67 | ;
68 | return stringn(str, s - str);
69 | }
70 | char *stringd(long n) {
71 | char str[25], *s = str + sizeof (str);
72 | unsigned long m;
73 |
74 | if (n == LONG_MIN)
75 | m = (unsigned long)LONG_MAX + 1;
76 | else if (n < 0)
77 | m = -n;
78 | else
79 | m = n;
80 | do
81 | *--s = m%10 + '0';
82 | while ((m /= 10) != 0);
83 | if (n < 0)
84 | *--s = '-';
85 | return stringn(s, str + sizeof (str) - s);
86 | }
87 | char *stringn(const char *str, int len) {
88 | int i;
89 | unsigned int h;
90 | const char *end;
91 | struct string *p;
92 |
93 | assert(str);
94 | for (h = 0, i = len, end = str; i > 0; i--)
95 | h = (h<<1) + scatter[*(unsigned char *)end++];
96 | h &= NELEMS(buckets)-1;
97 | for (p = buckets[h]; p; p = p->link)
98 | if (len == p->len) {
99 | const char *s1 = str;
100 | char *s2 = p->str;
101 | do {
102 | if (s1 == end)
103 | return p->str;
104 | } while (*s1++ == *s2++);
105 | }
106 | {
107 | static char *next, *strlimit;
108 | if (len + 1 >= strlimit - next) {
109 | int n = len + 4*1024;
110 | next = allocate(n, PERM);
111 | strlimit = next + n;
112 | }
113 | NEW(p, PERM);
114 | p->len = len;
115 | for (p->str = next; str < end; )
116 | *next++ = *str++;
117 | *next++ = 0;
118 | p->link = buckets[h];
119 | buckets[h] = p;
120 | return p->str;
121 | }
122 | }
123 |
--------------------------------------------------------------------------------
/code/tools/lcc/src/trace.c:
--------------------------------------------------------------------------------
1 | #include "c.h"
2 |
3 |
4 | static char *fmt, *fp, *fmtend; /* format string, current & limit pointer */
5 | static Tree args; /* printf arguments */
6 | static Symbol frameno; /* local holding frame number */
7 |
8 | /* appendstr - append str to the evolving format string, expanding it if necessary */
9 | static void appendstr(char *str) {
10 | do
11 | if (fp == fmtend) {
12 | if (fp) {
13 | char *s = allocate(2*(fmtend - fmt), FUNC);
14 | strncpy(s, fmt, fmtend - fmt);
15 | fp = s + (fmtend - fmt);
16 | fmtend = s + 2*(fmtend - fmt);
17 | fmt = s;
18 | } else {
19 | fp = fmt = allocate(80, FUNC);
20 | fmtend = fmt + 80;
21 | }
22 | }
23 | while ((*fp++ = *str++) != 0);
24 | fp--;
25 | }
26 |
27 | /* tracevalue - append format and argument to print the value of e */
28 | static void tracevalue(Tree e, int lev) {
29 | Type ty = unqual(e->type);
30 |
31 | switch (ty->op) {
32 | case INT:
33 | if (ty == chartype || ty == signedchar)
34 | appendstr("'\\x%02x'");
35 | else if (ty == longtype)
36 | appendstr("0x%ld");
37 | else
38 | appendstr("0x%d");
39 | break;
40 | case UNSIGNED:
41 | if (ty == chartype || ty == unsignedchar)
42 | appendstr("'\\x%02x'");
43 | else if (ty == unsignedlong)
44 | appendstr("0x%lx");
45 | else
46 | appendstr("0x%x");
47 | break;
48 | case FLOAT:
49 | if (ty == longdouble)
50 | appendstr("%Lg");
51 | else
52 | appendstr("%g");
53 | break;
54 | case POINTER:
55 | if (unqual(ty->type) == chartype
56 | || unqual(ty->type) == signedchar
57 | || unqual(ty->type) == unsignedchar) {
58 | static Symbol null;
59 | if (null == NULL)
60 | null = mkstr("(null)");
61 | tracevalue(cast(e, unsignedtype), lev + 1);
62 | appendstr(" \"%.30s\"");
63 | e = condtree(e, e, pointer(idtree(null->u.c.loc)));
64 | } else {
65 | appendstr("("); appendstr(typestring(ty, "")); appendstr(")0x%x");
66 | }
67 | break;
68 | case STRUCT: {
69 | Field q;
70 | appendstr("("); appendstr(typestring(ty, "")); appendstr("){");
71 | for (q = ty->u.sym->u.s.flist; q; q = q->link) {
72 | appendstr(q->name); appendstr("=");
73 | tracevalue(field(addrof(e), q->name), lev + 1);
74 | if (q->link)
75 | appendstr(",");
76 | }
77 | appendstr("}");
78 | return;
79 | }
80 | case UNION:
81 | appendstr("("); appendstr(typestring(ty, "")); appendstr("){...}");
82 | return;
83 | case ARRAY:
84 | if (lev && ty->type->size > 0) {
85 | int i;
86 | e = pointer(e);
87 | appendstr("{");
88 | for (i = 0; i < ty->size/ty->type->size; i++) {
89 | Tree p = (*optree['+'])(ADD, e, consttree(i, inttype));
90 | if (isptr(p->type) && isarray(p->type->type))
91 | p = retype(p, p->type->type);
92 | else
93 | p = rvalue(p);
94 | if (i)
95 | appendstr(",");
96 | tracevalue(p, lev + 1);
97 | }
98 | appendstr("}");
99 | } else
100 | appendstr(typestring(ty, ""));
101 | return;
102 | default:
103 | assert(0);
104 | }
105 | e = cast(e, promote(ty));
106 | args = tree(mkop(ARG,e->type), e->type, e, args);
107 | }
108 |
109 | /* tracefinis - complete & generate the trace call to print */
110 | static void tracefinis(Symbol printer) {
111 | Tree *ap;
112 | Symbol p;
113 |
114 | *fp = 0;
115 | p = mkstr(string(fmt));
116 | for (ap = &args; *ap; ap = &(*ap)->kids[1])
117 | ;
118 | *ap = tree(ARG+P, charptype, pointer(idtree(p->u.c.loc)), 0);
119 | walk(calltree(pointer(idtree(printer)), freturn(printer->type), args, NULL), 0, 0);
120 | args = 0;
121 | fp = fmtend = 0;
122 | }
123 |
124 | /* tracecall - generate code to trace entry to f */
125 | static void tracecall(Symbol printer, Symbol f) {
126 | int i;
127 | Symbol counter = genident(STATIC, inttype, GLOBAL);
128 |
129 | defglobal(counter, BSS);
130 | (*IR->space)(counter->type->size);
131 | frameno = genident(AUTO, inttype, level);
132 | addlocal(frameno);
133 | appendstr(f->name); appendstr("#");
134 | tracevalue(asgn(frameno, incr(INCR, idtree(counter), consttree(1, inttype))), 0);
135 | appendstr("(");
136 | for (i = 0; f->u.f.callee[i]; i++) {
137 | if (i)
138 | appendstr(",");
139 | appendstr(f->u.f.callee[i]->name); appendstr("=");
140 | tracevalue(idtree(f->u.f.callee[i]), 0);
141 | }
142 | if (variadic(f->type))
143 | appendstr(",...");
144 | appendstr(") called\n");
145 | tracefinis(printer);
146 | }
147 |
148 | /* tracereturn - generate code to trace return e */
149 | static void tracereturn(Symbol printer, Symbol f, Tree e) {
150 | appendstr(f->name); appendstr("#");
151 | tracevalue(idtree(frameno), 0);
152 | appendstr(" returned");
153 | if (freturn(f->type) != voidtype && e) {
154 | appendstr(" ");
155 | tracevalue(e, 0);
156 | }
157 | appendstr("\n");
158 | tracefinis(printer);
159 | }
160 |
161 | /* trace_init - initialize for tracing */
162 | void trace_init(int argc, char *argv[]) {
163 | int i;
164 | static int inited;
165 |
166 | if (inited)
167 | return;
168 | inited = 1;
169 | type_init(argc, argv);
170 | if (IR)
171 | for (i = 1; i < argc; i++)
172 | if (strncmp(argv[i], "-t", 2) == 0 && strchr(argv[i], '=') == NULL) {
173 | Symbol printer = mksymbol(EXTERN,
174 | argv[i][2] ? &argv[i][2] : "printf",
175 | ftype(inttype, ptr(qual(CONST, chartype))));
176 | printer->defined = 0;
177 | attach((Apply)tracecall, printer, &events.entry);
178 | attach((Apply)tracereturn, printer, &events.returns);
179 | break;
180 | }
181 | }
182 |
--------------------------------------------------------------------------------
/code/ui/ui_public.h:
--------------------------------------------------------------------------------
1 | /*
2 | ===========================================================================
3 | Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
4 |
5 | This file is part of Spearmint Source Code.
6 |
7 | Spearmint Source Code is free software; you can redistribute it
8 | and/or modify it under the terms of the GNU General Public License as
9 | published by the Free Software Foundation; either version 3 of the License,
10 | or (at your option) any later version.
11 |
12 | Spearmint Source Code is distributed in the hope that it will be
13 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with Spearmint Source Code. If not, see .
19 |
20 | In addition, Spearmint Source Code is also subject to certain additional terms.
21 | You should have received a copy of these additional terms immediately following
22 | the terms and conditions of the GNU General Public License. If not, please
23 | request a copy in writing from id Software at the address below.
24 |
25 | If you have questions concerning this license or the applicable additional
26 | terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc.,
27 | Suite 120, Rockville, Maryland 20850 USA.
28 | ===========================================================================
29 | */
30 | //
31 | #ifndef __UI_PUBLIC_H__
32 | #define __UI_PUBLIC_H__
33 |
34 | #include "../cgame/cg_public.h"
35 |
36 | // UI commands
37 | extern consoleCommand_t ui_commands[];
38 | extern int ui_numCommands;
39 |
40 | // UI functions used by cgame
41 |
42 | void UI_Init( qboolean inGameLoad, int maxSplitView );
43 | void UI_Shutdown( void );
44 |
45 | void UI_KeyEvent( int key, qboolean down );
46 | void UI_MouseEvent( int localPlayerNum, int dx, int dy );
47 |
48 | void UI_GetCursorPos( int localPlayerNum, int *x, int *y );
49 | void UI_SetCursorPos( int localPlayerNum, int x, int y );
50 |
51 | qboolean UI_IsFullscreen( void );
52 |
53 | void UI_Refresh( int time );
54 | void UI_SetActiveMenu( uiMenuCommand_t menu );
55 | void UI_ConsoleCommand( int realTime );
56 |
57 | void UI_DrawConnectScreen( qboolean overlay );
58 | // if !overlay, the background will be drawn, otherwise it will be
59 | // overlayed over whatever the cgame has drawn.
60 | // a GetClientState syscall will be made to get the current strings
61 |
62 | qboolean UI_WantsBindKeys( void );
63 | void UI_WindowResized( void );
64 |
65 | // used by cg_info.c
66 | void UI_DrawProportionalString( int x, int y, const char* str, int style, vec4_t color );
67 |
68 | #endif
69 |
--------------------------------------------------------------------------------
/travis-ci-build.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | failed=0;
4 |
5 | # Default Build
6 | (make clean release) || failed=1;
7 |
8 | if [ $failed -eq 1 ]; then
9 | echo "Build failure.";
10 | else
11 | echo "Build successful.";
12 | fi
13 |
14 | exit $failed;
15 |
16 |
--------------------------------------------------------------------------------
/ui/hud.txt:
--------------------------------------------------------------------------------
1 | // hud menu defs
2 | //
3 | {
4 | loadMenu { "ui/hud.menu" }
5 | loadMenu { "ui/score.menu" }
6 | loadMenu { "ui/teamscore.menu" }
7 | }
8 |
--------------------------------------------------------------------------------
/ui/hud2.txt:
--------------------------------------------------------------------------------
1 | // hud menu defs
2 | //
3 | {
4 | loadMenu { "ui/min_hud.menu" }
5 | loadMenu { "ui/score.menu" }
6 | loadMenu { "ui/teamscore.menu" }
7 | }
8 |
--------------------------------------------------------------------------------
/ui/ingame.txt:
--------------------------------------------------------------------------------
1 | // menu defs
2 | //
3 | {
4 | loadMenu { "ui/ingame.menu" }
5 | loadMenu { "ui/ingame_vote.menu" }
6 | loadMenu { "ui/ingame_about.menu" }
7 | loadMenu { "ui/ingame_controls.menu" }
8 | loadMenu { "ui/ingame_join.menu" }
9 | loadMenu { "ui/ingame_options.menu" }
10 | loadMenu { "ui/ingame_system.menu" }
11 | loadMenu { "ui/ingame_leave.menu" }
12 | loadMenu { "ui/ingame_player.menu" }
13 | loadMenu { "ui/ingame_addbot.menu" }
14 | loadMenu { "ui/ingame_callvote.menu" }
15 | loadMenu { "ui/ingame_orders.menu" }
16 | }
17 |
--------------------------------------------------------------------------------
/ui/menus.txt:
--------------------------------------------------------------------------------
1 | // menu defs
2 | //
3 | {
4 | loadMenu { "ui/main.menu" }
5 | loadMenu { "ui/joinserver.menu" }
6 | loadMenu { "ui/filter.menu" }
7 | loadMenu { "ui/punkbuster.menu" }
8 | loadMenu { "ui/player.menu" }
9 | loadMenu { "ui/setup.menu" }
10 | loadMenu { "ui/fight.menu" }
11 | loadMenu { "ui/skirmish.menu" }
12 | loadMenu { "ui/createserver.menu" }
13 | loadMenu { "ui/controls.menu" }
14 | loadMenu { "ui/cdkey.menu" }
15 | loadMenu { "ui/system.menu" }
16 | loadMenu { "ui/options.menu" }
17 | loadMenu { "ui/help.menu" }
18 | loadMenu { "ui/ordershelp.menu" }
19 | loadMenu { "ui/mod.menu" }
20 | loadMenu { "ui/demo.menu" }
21 | loadMenu { "ui/cinematicmenu.menu" }
22 | loadMenu { "ui/credit.menu" }
23 | loadMenu { "ui/demo_quit.menu" }
24 | loadMenu { "ui/connect.menu" }
25 | loadMenu { "ui/powerup.menu" }
26 | loadMenu { "ui/password.menu" }
27 | loadMenu { "ui/quake3.menu" }
28 | loadMenu { "ui/quit.menu" }
29 | loadMenu { "ui/vid_restart.menu" }
30 | loadMenu { "ui/default.menu" }
31 | loadMenu { "ui/addfilter.menu" }
32 | loadMenu { "ui/error.menu" }
33 | loadMenu { "ui/serverinfo.menu" }
34 | loadMenu { "ui/findplayer.menu" }
35 | loadMenu { "ui/endofgame.menu" }
36 | loadMenu { "ui/quitcredit.menu" }
37 | loadMenu { "ui/resetscore.menu" }
38 | loadMenu { "ui/createfavorite.menu" }
39 | }
40 |
--------------------------------------------------------------------------------