summaryrefslogtreecommitdiff
path: root/apps/plugins/sdl/progs/quake/cvar.c
diff options
context:
space:
mode:
authorFranklin Wei <git@fwei.tk>2018-02-11 15:34:30 -0500
committerFranklin Wei <git@fwei.tk>2019-07-19 22:37:40 -0400
commit5d05b9d3e920a6aa5fcb553758e98ed0da8c91e4 (patch)
tree84406e21639529a185556a33e5de7f43cffc277b /apps/plugins/sdl/progs/quake/cvar.c
parentb70fecf21ddc21877ec1ae7888d9c18a979e37ad (diff)
downloadrockbox-5d05b9d3e920a6aa5fcb553758e98ed0da8c91e4.tar.gz
rockbox-5d05b9d3e920a6aa5fcb553758e98ed0da8c91e4.zip
Quake!
This ports id Software's Quake to run on the SDL plugin runtime. The source code originated from id under the GPLv2 license. I used https://github.com/ahefner/sdlquake as the base of my port. Performance is, unsurprisingly, not on par with what you're probably used to on PC. I average about 10FPS on ipod6g, but it's still playable. Sound works well enough, but in-game music is not supported. I've written ARM assembly routines for the inner sound loop. Make sure you turn the "brightness" all the way down, or colors will look funky. To run, extract Quake's data files to /.rockbox/quake. Have fun! Change-Id: I4285036e967d7f0722802d43cf2096c808ca5799
Diffstat (limited to 'apps/plugins/sdl/progs/quake/cvar.c')
-rw-r--r--apps/plugins/sdl/progs/quake/cvar.c224
1 files changed, 224 insertions, 0 deletions
diff --git a/apps/plugins/sdl/progs/quake/cvar.c b/apps/plugins/sdl/progs/quake/cvar.c
new file mode 100644
index 0000000000..07a761a332
--- /dev/null
+++ b/apps/plugins/sdl/progs/quake/cvar.c
@@ -0,0 +1,224 @@
1/*
2Copyright (C) 1996-1997 Id Software, Inc.
3
4This program is free software; you can redistribute it and/or
5modify it under the terms of the GNU General Public License
6as published by the Free Software Foundation; either version 2
7of the License, or (at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13See the GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program; if not, write to the Free Software
17Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19*/
20// cvar.c -- dynamic variable tracking
21
22#include "quakedef.h"
23
24cvar_t *cvar_vars;
25char *cvar_null_string = "";
26
27/*
28============
29Cvar_FindVar
30============
31*/
32cvar_t *Cvar_FindVar (char *var_name)
33{
34 cvar_t *var;
35
36 for (var=cvar_vars ; var ; var=var->next)
37 if (!Q_strcmp (var_name, var->name))
38 return var;
39
40 return NULL;
41}
42
43/*
44============
45Cvar_VariableValue
46============
47*/
48float Cvar_VariableValue (char *var_name)
49{
50 cvar_t *var;
51
52 var = Cvar_FindVar (var_name);
53 if (!var)
54 return 0;
55 return Q_atof (var->string);
56}
57
58
59/*
60============
61Cvar_VariableString
62============
63*/
64char *Cvar_VariableString (char *var_name)
65{
66 cvar_t *var;
67
68 var = Cvar_FindVar (var_name);
69 if (!var)
70 return cvar_null_string;
71 return var->string;
72}
73
74
75/*
76============
77Cvar_CompleteVariable
78============
79*/
80char *Cvar_CompleteVariable (char *partial)
81{
82 cvar_t *cvar;
83 int len;
84
85 len = Q_strlen(partial);
86
87 if (!len)
88 return NULL;
89
90// check functions
91 for (cvar=cvar_vars ; cvar ; cvar=cvar->next)
92 if (!Q_strncmp (partial,cvar->name, len))
93 return cvar->name;
94
95 return NULL;
96}
97
98
99/*
100============
101Cvar_Set
102============
103*/
104void Cvar_Set (char *var_name, char *value)
105{
106 cvar_t *var;
107 qboolean changed;
108
109 var = Cvar_FindVar (var_name);
110 if (!var)
111 { // there is an error in C code if this happens
112 Con_Printf ("Cvar_Set: variable %s not found\n", var_name);
113 return;
114 }
115
116 changed = Q_strcmp(var->string, value);
117
118 Z_Free (var->string); // free the old value string
119
120 var->string = Z_Malloc (Q_strlen(value)+1);
121 Q_strcpy (var->string, value);
122 var->value = Q_atof (var->string);
123 if (var->server && changed)
124 {
125 if (sv.active)
126 SV_BroadcastPrintf ("\"%s\" changed to \"%s\"\n", var->name, var->string);
127 }
128}
129
130/*
131============
132Cvar_SetValue
133============
134*/
135void Cvar_SetValue (char *var_name, float value)
136{
137 char val[32];
138
139 sprintf (val, "%f",value);
140 Cvar_Set (var_name, val);
141}
142
143
144/*
145============
146Cvar_RegisterVariable
147
148Adds a freestanding variable to the variable list.
149============
150*/
151void Cvar_RegisterVariable (cvar_t *variable)
152{
153 char *oldstr;
154
155// first check to see if it has allready been defined
156 if (Cvar_FindVar (variable->name))
157 {
158 Con_Printf ("Can't register variable %s, allready defined\n", variable->name);
159 return;
160 }
161
162// check for overlap with a command
163 if (Cmd_Exists (variable->name))
164 {
165 Con_Printf ("Cvar_RegisterVariable: %s is a command\n", variable->name);
166 return;
167 }
168
169// copy the value off, because future sets will Z_Free it
170 oldstr = variable->string;
171 variable->string = Z_Malloc (Q_strlen(variable->string)+1);
172 Q_strcpy (variable->string, oldstr);
173 variable->value = Q_atof (variable->string);
174
175// link the variable in
176 variable->next = cvar_vars;
177 cvar_vars = variable;
178}
179
180/*
181============
182Cvar_Command
183
184Handles variable inspection and changing from the console
185============
186*/
187qboolean Cvar_Command (void)
188{
189 cvar_t *v;
190
191// check variables
192 v = Cvar_FindVar (Cmd_Argv(0));
193 if (!v)
194 return false;
195
196// perform a variable print or set
197 if (Cmd_Argc() == 1)
198 {
199 Con_Printf ("\"%s\" is \"%s\"\n", v->name, v->string);
200 return true;
201 }
202
203 Cvar_Set (v->name, Cmd_Argv(1));
204 return true;
205}
206
207
208/*
209============
210Cvar_WriteVariables
211
212Writes lines containing "set variable value" for all variables
213with the archive flag set to true.
214============
215*/
216void Cvar_WriteVariables (FILE *f)
217{
218 cvar_t *var;
219
220 for (var = cvar_vars ; var ; var = var->next)
221 if (var->archive)
222 fprintf (f, "%s \"%s\"\n", var->name, var->string);
223}
224