Cube  Check-in [f17992369e]

Overview
Comment:Clean up menus and text drawing
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: f17992369e439fa68605017c6ffb0d11eece9d29a4cdb5768656bd874248d623
User & Date: js on 2025-03-06 00:34:42
Other Links: manifest | tags
Context
2025-03-06
01:17
Remove cvector and ivector check-in: 5bbd6d8ddd user: js tags: trunk
00:34
Clean up menus and text drawing check-in: f17992369e user: js tags: trunk
2025-03-05
23:18
Move classes into separate files check-in: 14861826d4 user: js tags: trunk
Changes

Modified src/MD2.h from [4f18777375] to [e16b607519].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#import <ObjFW/ObjFW.h>

OF_ASSUME_NONNULL_BEGIN

@class MapModelInfo;

@interface MD2 : OFObject
@property (nonatomic) MapModelInfo *mmi;
@property (copy, nonatomic) OFString *loadname;
@property (nonatomic) int mdlnum;
@property (nonatomic) bool loaded;

- (bool)loadWithIRI:(OFIRI *)IRI;
- (void)renderWithLight:(OFVector3D &)light
                  frame:(int)frame
                  range:(int)range
                      x:(float)x
                      y:(float)y
                      z:(float)z
                    yaw:(float)yaw
                  pitch:(float)pitch













|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#import <ObjFW/ObjFW.h>

OF_ASSUME_NONNULL_BEGIN

@class MapModelInfo;

@interface MD2 : OFObject
@property (nonatomic) MapModelInfo *mmi;
@property (copy, nonatomic) OFString *loadname;
@property (nonatomic) int mdlnum;
@property (nonatomic) bool loaded;

- (bool)loadWithIRI:(OFIRI *)IRI;
- (void)renderWithLight:(OFVector3D)light
                  frame:(int)frame
                  range:(int)range
                      x:(float)x
                      y:(float)y
                      z:(float)z
                    yaw:(float)yaw
                  pitch:(float)pitch

Modified src/MD2.mm from [e752e43195] to [150ffcd79c].

19
20
21
22
23
24
25






26
27
28
29
30
31
32

struct md2_frame {
	float scale[3];
	float translate[3];
	char name[16];
	md2_vertex vertices[1];
};







@implementation MD2 {
	int _numGlCommands;
	int *_glCommands;
	int _numTriangles;
	int _frameSize;
	int _numFrames;







>
>
>
>
>
>







19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

struct md2_frame {
	float scale[3];
	float translate[3];
	char name[16];
	md2_vertex vertices[1];
};

static float
snap(int sn, float f)
{
	return sn ? (float)(((int)(f + sn * 0.5f)) & (~(sn - 1))) : f;
}

@implementation MD2 {
	int _numGlCommands;
	int *_glCommands;
	int _numTriangles;
	int _frameSize;
	int _numFrames;
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
		_mverts = new OFVector3D *[_numFrames];
		loopj(_numFrames) _mverts[j] = NULL;

		return true;
	}
}

float
snap(int sn, float f)
{
	return sn ? (float)(((int)(f + sn * 0.5f)) & (~(sn - 1))) : f;
}

- (void)scaleWithFrame:(int)frame scale:(float)scale snap:(int)sn
{
	_mverts[frame] = new OFVector3D[_numVerts];
	md2_frame *cf = (md2_frame *)((char *)_frames + _frameSize * frame);
	float sc = 16.0f / scale;
	loop(vi, _numVerts)
	{
		uchar *cv = (uchar *)&cf->vertices[vi].vertex;
		OFVector3D *v = &(_mverts[frame])[vi];
		v->x = (snap(sn, cv[0] * cf->scale[0]) + cf->translate[0]) / sc;
		v->y =
		    -(snap(sn, cv[1] * cf->scale[1]) + cf->translate[1]) / sc;
		v->z = (snap(sn, cv[2] * cf->scale[2]) + cf->translate[2]) / sc;
	}
}

- (void)renderWithLight:(OFVector3D &)light
                  frame:(int)frame
                  range:(int)range
                      x:(float)x
                      y:(float)y
                      z:(float)z
                    yaw:(float)yaw
                  pitch:(float)pitch







<
<
<
<
<
<
















|







105
106
107
108
109
110
111






112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
		_mverts = new OFVector3D *[_numFrames];
		loopj(_numFrames) _mverts[j] = NULL;

		return true;
	}
}







- (void)scaleWithFrame:(int)frame scale:(float)scale snap:(int)sn
{
	_mverts[frame] = new OFVector3D[_numVerts];
	md2_frame *cf = (md2_frame *)((char *)_frames + _frameSize * frame);
	float sc = 16.0f / scale;
	loop(vi, _numVerts)
	{
		uchar *cv = (uchar *)&cf->vertices[vi].vertex;
		OFVector3D *v = &(_mverts[frame])[vi];
		v->x = (snap(sn, cv[0] * cf->scale[0]) + cf->translate[0]) / sc;
		v->y =
		    -(snap(sn, cv[1] * cf->scale[1]) + cf->translate[1]) / sc;
		v->z = (snap(sn, cv[2] * cf->scale[2]) + cf->translate[2]) / sc;
	}
}

- (void)renderWithLight:(OFVector3D)light
                  frame:(int)frame
                  range:(int)range
                      x:(float)x
                      y:(float)y
                      z:(float)z
                    yaw:(float)yaw
                  pitch:(float)pitch

Added src/Menu.h version [63596d2912].

Added src/Menu.m version [bdc2f1f706].

Added src/MenuItem.h version [58b3d87ceb].

Added src/MenuItem.m version [d1fadd8d50].

Modified src/clientextras.mm from [0dee11d744] to [bbd34586be].

103
104
105
106
107
108
109

110
111


112
113
114
115
116
117
118
renderscore(dynent *d)
{
	sprintf_sd(lag)("%d", d->plag);
	sprintf_sd(name)("(%s)", d->name);
	sprintf_s(scorelines.add().s)("%d\t%s\t%d\t%s\t%s", d->frags,
	    d->state == CS_LAGGED ? "LAG" : lag, d->ping, d->team,
	    d->state == CS_DEAD ? name : d->name);

	menumanual(0, scorelines.length() - 1, scorelines.last().s);
};



const int maxteams = 4;
char *teamname[maxteams];
int teamscore[maxteams], teamsused;
string teamscores;
int timeremain = 0;








>
|
<
>
>







103
104
105
106
107
108
109
110
111

112
113
114
115
116
117
118
119
120
renderscore(dynent *d)
{
	sprintf_sd(lag)("%d", d->plag);
	sprintf_sd(name)("(%s)", d->name);
	sprintf_s(scorelines.add().s)("%d\t%s\t%d\t%s\t%s", d->frags,
	    d->state == CS_LAGGED ? "LAG" : lag, d->ping, d->team,
	    d->state == CS_DEAD ? name : d->name);
	@autoreleasepool {
		menumanual(0, scorelines.length() - 1, @(scorelines.last().s));

	}
}

const int maxteams = 4;
char *teamname[maxteams];
int teamscore[maxteams], teamsused;
string teamscores;
int timeremain = 0;

137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155

156

157
158
159



160
161
162
163
164
165
166
{
	if (!scoreson)
		return;
	scorelines.setsize(0);
	if (!demoplayback)
		renderscore(player1);
	loopv(players) if (players[i]) renderscore(players[i]);
	sortmenu(0, scorelines.length());
	if (m_teammode) {
		teamsused = 0;
		loopv(players) addteamscore(players[i]);
		if (!demoplayback)
			addteamscore(player1);
		teamscores[0] = 0;
		loopj(teamsused)
		{
			sprintf_sd(sc)("[ %s: %d ]", teamname[j], teamscore[j]);
			strcat_s(teamscores, sc);
		};

		menumanual(0, scorelines.length(), "");

		menumanual(0, scorelines.length() + 1, teamscores);
	};
};




// sendmap/getmap commands, should be replaced by more intuitive map downloading

void
sendmap(OFString *mapname)
{
	@autoreleasepool {







|










<
>
|
>
|
<
<
>
>
>







139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156

157
158
159
160


161
162
163
164
165
166
167
168
169
170
{
	if (!scoreson)
		return;
	scorelines.setsize(0);
	if (!demoplayback)
		renderscore(player1);
	loopv(players) if (players[i]) renderscore(players[i]);
	sortmenu();
	if (m_teammode) {
		teamsused = 0;
		loopv(players) addteamscore(players[i]);
		if (!demoplayback)
			addteamscore(player1);
		teamscores[0] = 0;
		loopj(teamsused)
		{
			sprintf_sd(sc)("[ %s: %d ]", teamname[j], teamscore[j]);
			strcat_s(teamscores, sc);

		}
		menumanual(0, scorelines.length(), @"");
		@autoreleasepool {
			menumanual(0, scorelines.length() + 1, @(teamscores));


		}
	}
}

// sendmap/getmap commands, should be replaced by more intuitive map downloading

void
sendmap(OFString *mapname)
{
	@autoreleasepool {

Modified src/console.mm from [cf67d004cd] to [39120f3a5f].

81
82
83
84
85
86
87
88


89
90
91
92
93
94



95
96
97
98
99
100
101
	loopv(conlines) if (conskip ? i >= conskip - 1 ||
	                                  i >= conlines.length() - ndraw
	                            : lastmillis - conlines[i].outtime < 20000)
	{
		refs[nd++] = conlines[i].cref;
		if (nd == ndraw)
			break;
	};


	loopj(nd)
	{
		draw_text(refs[j], FONTH / 3,
		    (FONTH / 4 * 5) * (nd - j - 1) + FONTH / 3, 2);
	};
};




// keymap is defined externally in keymap.cfg

static OFMutableArray<KeyMapping *> *keyMappings = nil;

void
keymap(OFString *code, OFString *key, OFString *action)







<
>
>
|
|
|
|
<
<
>
>
>







81
82
83
84
85
86
87

88
89
90
91
92
93


94
95
96
97
98
99
100
101
102
103
	loopv(conlines) if (conskip ? i >= conskip - 1 ||
	                                  i >= conlines.length() - ndraw
	                            : lastmillis - conlines[i].outtime < 20000)
	{
		refs[nd++] = conlines[i].cref;
		if (nd == ndraw)
			break;

	}
	@autoreleasepool {
		loopj(nd)
		{
			draw_text(@(refs[j]), FONTH / 3,
			    (FONTH / 4 * 5) * (nd - j - 1) + FONTH / 3, 2);


		}
	}
}

// keymap is defined externally in keymap.cfg

static OFMutableArray<KeyMapping *> *keyMappings = nil;

void
keymap(OFString *code, OFString *key, OFString *action)
160
161
162
163
164
165
166

167
168
169
170
171

172
173
174
175
176
177
178
cvector vhistory;
int histpos = 0;

void
history(int n)
{
	static bool rec = false;

	if (!rec && n >= 0 && n < vhistory.length()) {
		rec = true;
		execute(vhistory[vhistory.length() - n - 1]);
		rec = false;
	};

}
COMMAND(history, ARG_1INT)

void
keypress(int code, bool isdown, int cooked)
{
	if (saycommandon) // keystrokes go to commandline







>




<
>







162
163
164
165
166
167
168
169
170
171
172
173

174
175
176
177
178
179
180
181
cvector vhistory;
int histpos = 0;

void
history(int n)
{
	static bool rec = false;

	if (!rec && n >= 0 && n < vhistory.length()) {
		rec = true;
		execute(vhistory[vhistory.length() - n - 1]);
		rec = false;

	}
}
COMMAND(history, ARG_1INT)

void
keypress(int code, bool isdown, int cooked)
{
	if (saycommandon) // keystrokes go to commandline

Modified src/menus.mm from [b007e3d965] to [1d03f1ff21].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40

41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62

63
64
65
66
67
68

69
70
71

72
73
74

75

76




77
78
79
80
81
82
83
84

85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100

101
102
103
104
105

106
107


108
109
110
111
112
113
114
115
116

117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139




140
141
142
143
144
145
146
147

148
149
150
151
152

153



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173




174
175


176
177

178
179

// menus.cpp: ingame menu system (also used for scores and serverlist)

#include "cube.h"

struct mitem {
	char *text, *action;
};

struct gmenu {
	char *name;
	vector<mitem> items;
	int mwidth;
	int menusel;
};

vector<gmenu> menus;

int vmenu = -1;

ivector menustack;

void
menuset(int menu)
{
	if ((vmenu = menu) >= 1)
		resetmovement(player1);
	if (vmenu == 1)
		menus[1].menusel = 0;
}

void
showmenu(OFString *name_)
{
	@autoreleasepool {
		const char *name = name_.UTF8String;
		loopv(menus) if (i > 1 && strcmp(menus[i].name, name) == 0)
		{
			menuset(i);
			return;
		}

	}
}
COMMAND(showmenu, ARG_1STR)

int
menucompare(mitem *a, mitem *b)
{
	int x = atoi(a->text);
	int y = atoi(b->text);
	if (x > y)
		return -1;
	if (x < y)
		return 1;
	return 0;
};

void
sortmenu(int start, int num)
{
	qsort(&menus[0].items[start], num, sizeof(mitem),
	    (int(__cdecl *)(const void *, const void *))menucompare);
};


void refreshservers();

bool
rendermenu()
{

	if (vmenu < 0) {
		menustack.setsize(0);
		return false;

	};
	if (vmenu == 1)
		refreshservers();

	gmenu &m = menus[vmenu];

	sprintf_sd(title)(vmenu > 1 ? "[ %s menu ]" : "%s", m.name);




	int mdisp = m.items.length();
	int w = 0;
	loopi(mdisp)
	{
		int x = text_width(m.items[i].text);
		if (x > w)
			w = x;
	};

	int tw = text_width(title);
	if (tw > w)
		w = tw;
	int step = FONTH / 4 * 5;
	int h = (mdisp + 2) * step;
	int y = (VIRTH - h) / 2;
	int x = (VIRTW - w) / 2;
	blendbox(x - FONTH / 2 * 3, y - FONTH, x + w + FONTH / 2 * 3,
	    y + h + FONTH, true);
	draw_text(title, x, y, 2);
	y += FONTH * 2;
	if (vmenu) {
		int bh = y + m.menusel * step;
		blendbox(
		    x - FONTH, bh - 10, x + w + FONTH, bh + FONTH + 10, false);
	};

	loopj(mdisp)
	{
		draw_text(m.items[j].text, x, y, 2);
		y += step;
	};

	return true;
};



void
newmenu(OFString *name)
{
	@autoreleasepool {
		gmenu &menu = menus.add();
		menu.name = newstring(name.UTF8String);
		menu.menusel = 0;
	}

}
COMMAND(newmenu, ARG_1STR)

void
menumanual(int m, int n, char *text)
{
	if (!n)
		menus[m].items.setsize(0);
	mitem &mitem = menus[m].items.add();
	mitem.text = text;
	mitem.action = "";
}

void
menuitem(OFString *text, OFString *action)
{
	@autoreleasepool {
		gmenu &menu = menus.last();
		mitem &mi = menu.items.add();
		mi.text = newstring(text.UTF8String);
		mi.action =
		    action.length > 0 ? newstring(action.UTF8String) : mi.text;
	}




}
COMMAND(menuitem, ARG_2STR)

bool
menukey(int code, bool isdown)
{
	if (vmenu <= 0)
		return false;

	int menusel = menus[vmenu].menusel;
	if (isdown) {
		if (code == SDLK_ESCAPE) {
			menuset(-1);
			if (!menustack.empty())

				menuset(menustack.pop());



			return true;
		} else if (code == SDLK_UP || code == -4)
			menusel--;
		else if (code == SDLK_DOWN || code == -5)
			menusel++;
		int n = menus[vmenu].items.length();
		if (menusel < 0)
			menusel = n - 1;
		else if (menusel >= n)
			menusel = 0;
		menus[vmenu].menusel = menusel;
	} else {
		if (code == SDLK_RETURN || code == -2) {
			char *action = menus[vmenu].items[menusel].action;
			if (vmenu == 1) {
				@autoreleasepool {
					connects(@(getservername(menusel)));
				}
			}
			menustack.add(vmenu);




			menuset(-1);
			execute(action, true);


		}
	}

	return true;
};





|
<
<

|
<
<
<
|
<

|
|
|
<
<











|

|
|
|
<



>




<
<
<
<
<
<
<
<
<
<
<
<

|

|
<
<
>






>
|
|
|
>
|
|
|
>
|
>
|
>
>
>
>
|
|
|
|
|
|
|
<
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<
>
|
|
|
|
<
>
|
<
>
>




<
|
<
|
|
>




|

|
|
|
|
|





<
|
<
<
<
<
|
>
>
>
>








>




|
>
|
>
>
>





|







|





|
>
>
>
>

|
>
>


>

<
>
1
2
3
4
5


6
7



8

9
10
11
12


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

29
30
31
32
33
34
35
36












37
38
39
40


41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70

71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86

87
88
89
90
91

92
93

94
95
96
97
98
99

100

101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119

120




121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176

177
// menus.cpp: ingame menu system (also used for scores and serverlist)

#include "cube.h"

#include <memory>



#import "Menu.h"



#import "MenuItem.h"


static OFMutableArray<OFNumber *> *menuStack;
static OFMutableArray<Menu *> *menus;
static int vmenu = -1;



void
menuset(int menu)
{
	if ((vmenu = menu) >= 1)
		resetmovement(player1);
	if (vmenu == 1)
		menus[1].menusel = 0;
}

void
showmenu(OFString *name)
{
	int i = 0;
	for (Menu *menu in menus) {
		if (i > 1 && [menu.name isEqual:name]) {

			menuset(i);
			return;
		}
		i++;
	}
}
COMMAND(showmenu, ARG_1STR)













void
sortmenu()
{
	[menus[0].items sort];


}

void refreshservers();

bool
rendermenu()
{
	@autoreleasepool {
		if (vmenu < 0) {
			[menuStack removeAllObjects];
			return false;
		}

		if (vmenu == 1)
			refreshservers();

		Menu *m = menus[vmenu];
		OFString *title;
		if (vmenu > 1)
			title =
			    [OFString stringWithFormat:@"[ %@ menu ]", m.name];
		else
			title = m.name;
		int mdisp = m.items.count;
		int w = 0;
		loopi(mdisp)
		{
			int x = text_width(m.items[i].text);
			if (x > w)
				w = x;

		}
		int tw = text_width(title);
		if (tw > w)
			w = tw;
		int step = FONTH / 4 * 5;
		int h = (mdisp + 2) * step;
		int y = (VIRTH - h) / 2;
		int x = (VIRTW - w) / 2;
		blendbox(x - FONTH / 2 * 3, y - FONTH, x + w + FONTH / 2 * 3,
		    y + h + FONTH, true);
		draw_text(title, x, y, 2);
		y += FONTH * 2;
		if (vmenu) {
			int bh = y + m.menusel * step;
			blendbox(x - FONTH, bh - 10, x + w + FONTH,
			    bh + FONTH + 10, false);

		}
		loopj(mdisp)
		{
			draw_text(m.items[j].text, x, y, 2);
			y += step;

		}
		return true;

	}
}

void
newmenu(OFString *name)
{

	if (menus == nil)

		menus = [[OFMutableArray alloc] init];

	[menus addObject:[[Menu alloc] initWithName:name]];
}
COMMAND(newmenu, ARG_1STR)

void
menumanual(int m, int n, OFString *text)
{
	if (n == 0)
		[menus[m].items removeAllObjects];

	MenuItem *item = [[MenuItem alloc] initWithText:text action:@""];
	[menus[m].items addObject:item];
}

void
menuitem(OFString *text, OFString *action)
{

	Menu *menu = menus.lastObject;





	MenuItem *item =
	    [[MenuItem alloc] initWithText:text
	                            action:(action.length > 0 ? action : text)];
	[menu.items addObject:item];
}
COMMAND(menuitem, ARG_2STR)

bool
menukey(int code, bool isdown)
{
	if (vmenu <= 0)
		return false;

	int menusel = menus[vmenu].menusel;
	if (isdown) {
		if (code == SDLK_ESCAPE) {
			menuset(-1);

			if (menuStack.count > 0) {
				menuset(menuStack.lastObject.intValue);
				[menuStack removeLastObject];
			}

			return true;
		} else if (code == SDLK_UP || code == -4)
			menusel--;
		else if (code == SDLK_DOWN || code == -5)
			menusel++;
		int n = menus[vmenu].items.count;
		if (menusel < 0)
			menusel = n - 1;
		else if (menusel >= n)
			menusel = 0;
		menus[vmenu].menusel = menusel;
	} else {
		if (code == SDLK_RETURN || code == -2) {
			OFString *action = menus[vmenu].items[menusel].action;
			if (vmenu == 1) {
				@autoreleasepool {
					connects(@(getservername(menusel)));
				}
			}

			if (menuStack == nil)
				menuStack = [[OFMutableArray alloc] init];

			[menuStack addObject:@(vmenu)];
			menuset(-1);

			std::unique_ptr<char> copy(strdup(action.UTF8String));
			execute(copy.get(), true);
		}
	}

	return true;

}

Modified src/meson.build from [a339bbfb63] to [784a6d82d7].

1
2
3
4
5
6
7


8
9
10
11
12
13
14
executable('client',
  [
    'Cube.mm',
    'Ident.m',
    'KeyMapping.m',
    'MD2.mm',
    'MapModelInfo.m',


    'client.mm',
    'clientextras.mm',
    'clientgame.mm',
    'clients2c.mm',
    'command.mm',
    'console.mm',
    'editing.mm',







>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
executable('client',
  [
    'Cube.mm',
    'Ident.m',
    'KeyMapping.m',
    'MD2.mm',
    'MapModelInfo.m',
    'Menu.m',
    'MenuItem.m',
    'client.mm',
    'clientextras.mm',
    'clientgame.mm',
    'clients2c.mm',
    'command.mm',
    'console.mm',
    'editing.mm',

Modified src/protos.h from [1a4e5c2dba] to [9515834784].

26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// init
extern void enqueueInit(void (^init)(void));
extern void processInitQueue(void);

// menus
extern bool rendermenu();
extern void menuset(int menu);
extern void menumanual(int m, int n, char *text);
extern void sortmenu(int start, int num);
extern bool menukey(int code, bool isdown);
extern void newmenu(OFString *name);

// serverbrowser
extern void addserver(OFString *servername);
extern char *getservername(int n);
extern void writeservercfg();







|
|







26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// init
extern void enqueueInit(void (^init)(void));
extern void processInitQueue(void);

// menus
extern bool rendermenu();
extern void menuset(int menu);
extern void menumanual(int m, int n, OFString *text);
extern void sortmenu();
extern bool menukey(int code, bool isdown);
extern void newmenu(OFString *name);

// serverbrowser
extern void addserver(OFString *servername);
extern char *getservername(int n);
extern void writeservercfg();
139
140
141
142
143
144
145

146
147
148
149
150
151
152
153
154
155
extern int isoccluded(float vx, float vy, float cx, float cy, float csize);

// main
extern void fatal(OFString *s, OFString *o = @"");
extern void *alloc(int s);

// rendertext

extern void draw_text(char *str, int left, int top, int gl_num);
extern void draw_textf(char *fstr, int left, int top, int gl_num, ...);
extern int text_width(char *str);
extern void draw_envbox(int t, int fogdist);

// editing
extern void cursorupdate();
extern void toggleedit();
extern void editdrag(bool isdown);
extern void setvdeltaxy(int delta, block &sel);







>
|
|
|







139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
extern int isoccluded(float vx, float vy, float cx, float cy, float csize);

// main
extern void fatal(OFString *s, OFString *o = @"");
extern void *alloc(int s);

// rendertext
extern void draw_text(OFString *string, int left, int top, int gl_num);
extern void draw_textf(
    OFConstantString *format, int left, int top, int gl_num, ...);
extern int text_width(OFString *string);
extern void draw_envbox(int t, int fogdist);

// editing
extern void cursorupdate();
extern void toggleedit();
extern void editdrag(bool isdown);
extern void setvdeltaxy(int delta, block &sel);

Modified src/renderextras.mm from [6ccf3a9b83] to [9a987704e6].

357
358
359
360
361
362
363
364

365
366
367

368
369

370
371
372
373
374
375

376
377
378
379
380
381
382
383
384
385
386
387
388
389
390

391
392
393
394
395
396
397
398
399
400
401

402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417

418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445

446
447
448
449
450
451

		glVertex2i(VIRTW, 0);
		glVertex2i(VIRTW, VIRTH);
		glVertex2i(0, VIRTH);
		glEnd();
		dblend -= curtime / 3;
		if (dblend < 0)
			dblend = 0;
	};


	glEnable(GL_TEXTURE_2D);


	char *command = getcurcommand();
	char *player = playerincrosshair();

	if (command)
		draw_textf("> %s_", 20, 1570, 2, command);
	else if (closeent[0])
		draw_text(closeent, 20, 1570, 2);
	else if (player)
		draw_text(player, 20, 1570, 2);


	renderscores();
	if (!rendermenu()) {
		glBlendFunc(GL_SRC_ALPHA, GL_SRC_ALPHA);
		glBindTexture(GL_TEXTURE_2D, 1);
		glBegin(GL_QUADS);
		glColor3ub(255, 255, 255);
		if (crosshairfx) {
			if (player1->gunwait)
				glColor3ub(128, 128, 128);
			else if (player1->health <= 25)
				glColor3ub(255, 0, 0);
			else if (player1->health <= 50)
				glColor3ub(255, 128, 0);
		};

		float chsize = (float)crosshairsize;
		glTexCoord2d(0.0, 0.0);
		glVertex2f(VIRTW / 2 - chsize, VIRTH / 2 - chsize);
		glTexCoord2d(1.0, 0.0);
		glVertex2f(VIRTW / 2 + chsize, VIRTH / 2 - chsize);
		glTexCoord2d(1.0, 1.0);
		glVertex2f(VIRTW / 2 + chsize, VIRTH / 2 + chsize);
		glTexCoord2d(0.0, 1.0);
		glVertex2f(VIRTW / 2 - chsize, VIRTH / 2 + chsize);
		glEnd();
	};


	glPopMatrix();

	glPushMatrix();
	glOrtho(0, VIRTW * 4 / 3, VIRTH * 4 / 3, 0, -1, 1);
	renderconsole();

	if (!hidestats) {
		glPopMatrix();
		glPushMatrix();
		glOrtho(0, VIRTW * 3 / 2, VIRTH * 3 / 2, 0, -1, 1);
		draw_textf("fps %d", 3200, 2390, 2, curfps);
		draw_textf("wqd %d", 3200, 2460, 2, nquads);
		draw_textf("wvt %d", 3200, 2530, 2, curvert);
		draw_textf("evt %d", 3200, 2600, 2, xtraverts);
	};


	glPopMatrix();

	if (player1->state == CS_ALIVE) {
		glPushMatrix();
		glOrtho(0, VIRTW / 2, VIRTH / 2, 0, -1, 1);
		draw_textf("%d", 90, 827, 2, player1->health);
		if (player1->armour)
			draw_textf("%d", 390, 827, 2, player1->armour);
		draw_textf(
		    "%d", 690, 827, 2, player1->ammo[player1->gunselect]);
		glPopMatrix();
		glPushMatrix();
		glOrtho(0, VIRTW, VIRTH, 0, -1, 1);
		glDisable(GL_BLEND);
		drawicon(128, 128, 20, 1650);
		if (player1->armour)
			drawicon(
			    (float)(player1->armourtype * 64), 0, 620, 1650);
		int g = player1->gunselect;
		int r = 64;
		if (g > 2) {
			g -= 3;
			r = 128;
		};
		drawicon((float)(g * 64), (float)r, 1220, 1650);
		glPopMatrix();
	};


	glDepthMask(GL_TRUE);
	glDisable(GL_BLEND);
	glDisable(GL_TEXTURE_2D);
	glEnable(GL_DEPTH_TEST);
};








<
>



>
|
|
>
|
|
|
|
|
|
>














<
>










<
>











|
|
|
|
<
>






|

|

|
















<
>





<
>
357
358
359
360
361
362
363

364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392

393
394
395
396
397
398
399
400
401
402
403

404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419

420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447

448
449
450
451
452
453

454
		glVertex2i(VIRTW, 0);
		glVertex2i(VIRTW, VIRTH);
		glVertex2i(0, VIRTH);
		glEnd();
		dblend -= curtime / 3;
		if (dblend < 0)
			dblend = 0;

	}

	glEnable(GL_TEXTURE_2D);

	@autoreleasepool {
		char *command = getcurcommand();
		char *player = playerincrosshair();

		if (command)
			draw_textf(@"> %s_", 20, 1570, 2, command);
		else if (closeent[0])
			draw_text(@(closeent), 20, 1570, 2);
		else if (player)
			draw_text(@(player), 20, 1570, 2);
	}

	renderscores();
	if (!rendermenu()) {
		glBlendFunc(GL_SRC_ALPHA, GL_SRC_ALPHA);
		glBindTexture(GL_TEXTURE_2D, 1);
		glBegin(GL_QUADS);
		glColor3ub(255, 255, 255);
		if (crosshairfx) {
			if (player1->gunwait)
				glColor3ub(128, 128, 128);
			else if (player1->health <= 25)
				glColor3ub(255, 0, 0);
			else if (player1->health <= 50)
				glColor3ub(255, 128, 0);

		}
		float chsize = (float)crosshairsize;
		glTexCoord2d(0.0, 0.0);
		glVertex2f(VIRTW / 2 - chsize, VIRTH / 2 - chsize);
		glTexCoord2d(1.0, 0.0);
		glVertex2f(VIRTW / 2 + chsize, VIRTH / 2 - chsize);
		glTexCoord2d(1.0, 1.0);
		glVertex2f(VIRTW / 2 + chsize, VIRTH / 2 + chsize);
		glTexCoord2d(0.0, 1.0);
		glVertex2f(VIRTW / 2 - chsize, VIRTH / 2 + chsize);
		glEnd();

	}

	glPopMatrix();

	glPushMatrix();
	glOrtho(0, VIRTW * 4 / 3, VIRTH * 4 / 3, 0, -1, 1);
	renderconsole();

	if (!hidestats) {
		glPopMatrix();
		glPushMatrix();
		glOrtho(0, VIRTW * 3 / 2, VIRTH * 3 / 2, 0, -1, 1);
		draw_textf(@"fps %d", 3200, 2390, 2, curfps);
		draw_textf(@"wqd %d", 3200, 2460, 2, nquads);
		draw_textf(@"wvt %d", 3200, 2530, 2, curvert);
		draw_textf(@"evt %d", 3200, 2600, 2, xtraverts);

	}

	glPopMatrix();

	if (player1->state == CS_ALIVE) {
		glPushMatrix();
		glOrtho(0, VIRTW / 2, VIRTH / 2, 0, -1, 1);
		draw_textf(@"%d", 90, 827, 2, player1->health);
		if (player1->armour)
			draw_textf(@"%d", 390, 827, 2, player1->armour);
		draw_textf(
		    @"%d", 690, 827, 2, player1->ammo[player1->gunselect]);
		glPopMatrix();
		glPushMatrix();
		glOrtho(0, VIRTW, VIRTH, 0, -1, 1);
		glDisable(GL_BLEND);
		drawicon(128, 128, 20, 1650);
		if (player1->armour)
			drawicon(
			    (float)(player1->armourtype * 64), 0, 620, 1650);
		int g = player1->gunselect;
		int r = 64;
		if (g > 2) {
			g -= 3;
			r = 128;
		};
		drawicon((float)(g * 64), (float)r, 1220, 1650);
		glPopMatrix();

	}

	glDepthMask(GL_TRUE);
	glDisable(GL_BLEND);
	glDisable(GL_TEXTURE_2D);
	glEnable(GL_DEPTH_TEST);

}

Modified src/rendertext.mm from [59ea840868] to [c20068be3f].

96
97
98
99
100
101
102
103
104




105
106
107
108
109
110

111
112
113

114
115
116

117
118
119
120
121
122
123




124
125
126

127
128
129


130



131
132
133


134
135
136

137
138
139
140
141
142
143
144
145
146
147


148
149

150
151


152

153
154
155
156

157
158
159
160

161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186

187
188
189
190
191
192
193
    {200, 448, 241, 512}, //{
    {241, 448, 270, 512}, //|
    {270, 448, 310, 512}, //}
    {310, 448, 363, 512}, //~
};

int
text_width(char *str)
{




	int x = 0;
	for (int i = 0; str[i] != 0; i++) {
		int c = str[i];
		if (c == '\t') {
			x = (x + PIXELTAB) / PIXELTAB * PIXELTAB;
			continue;

		};
		if (c == '\f')
			continue;

		if (c == ' ') {
			x += FONTH / 2;
			continue;

		};
		c -= 33;
		if (c < 0 || c >= 95)
			continue;
		int in_width = char_coords[c][2] - char_coords[c][0];
		x += in_width + 1;
	}




	return x;
}


void
draw_textf(char *fstr, int left, int top, int gl_num, ...)
{


	sprintf_sdlv(str, gl_num, fstr);



	draw_text(str, left, top, gl_num);
};



void
draw_text(char *str, int left, int top, int gl_num)
{

	glBlendFunc(GL_ONE, GL_ONE);
	glBindTexture(GL_TEXTURE_2D, gl_num);
	glColor3ub(255, 255, 255);

	int x = left;
	int y = top;

	int i;
	float in_left, in_top, in_right, in_bottom;
	int in_width, in_height;



	for (i = 0; str[i] != 0; i++) {
		int c = str[i];

		if (c == '\t') {
			x = (x - left + PIXELTAB) / PIXELTAB * PIXELTAB + left;


			continue;

		};
		if (c == '\f') {
			glColor3ub(64, 255, 128);
			continue;

		};
		if (c == ' ') {
			x += FONTH / 2;
			continue;

		};
		c -= 33;
		if (c < 0 || c >= 95)
			continue;

		in_left = ((float)char_coords[c][0]) / 512.0f;
		in_top = ((float)char_coords[c][1] + 2) / 512.0f;
		in_right = ((float)char_coords[c][2]) / 512.0f;
		in_bottom = ((float)char_coords[c][3] - 2) / 512.0f;

		in_width = char_coords[c][2] - char_coords[c][0];
		in_height = char_coords[c][3] - char_coords[c][1];

		glBegin(GL_QUADS);
		glTexCoord2f(in_left, in_top);
		glVertex2i(x, y);
		glTexCoord2f(in_right, in_top);
		glVertex2i(x + in_width, y);
		glTexCoord2f(in_right, in_bottom);
		glVertex2i(x + in_width, y + in_height);
		glTexCoord2f(in_left, in_bottom);
		glVertex2i(x, y + in_height);
		glEnd();

		xtraverts += 4;
		x += in_width + 1;

	}
}

// also Don's code, so goes in here too :)

void
draw_envbox_aux(float s0, float t0, int x0, int y0, int z0, float s1, float t1,







|

>
>
>
>
|
|
|
|
|
|
>
|
|
|
>
|
|
|
>
|
|
|
|
<
<
|
>
>
>
>
|
|
|
>

|

>
>
|
>
>
>
|
<
|
>
>

|

>
|
|
|

|
|

|
|
|

>
>
|
|
>
|
|
>
>
|
>
|
|
|
|
>
|
|
|
|
>
|
|
|
|

|
|
|
|

|
|

|
|
|
|
|
|
|
|
|
|

|
|
>







96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127


128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146

147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
    {200, 448, 241, 512}, //{
    {241, 448, 270, 512}, //|
    {270, 448, 310, 512}, //}
    {310, 448, 363, 512}, //~
};

int
text_width(OFString *string)
{
	@autoreleasepool {
		const char *str = string.UTF8String;
		size_t len = string.UTF8StringLength;

		int x = 0;
		for (int i = 0; i < len; i++) {
			int c = str[i];
			if (c == '\t') {
				x = (x + PIXELTAB) / PIXELTAB * PIXELTAB;
				continue;
			}

			if (c == '\f')
				continue;

			if (c == ' ') {
				x += FONTH / 2;
				continue;
			}

			c -= 33;
			if (c < 0 || c >= 95)
				continue;



			int in_width = char_coords[c][2] - char_coords[c][0];
			x += in_width + 1;
		}

		return x;
	}
}

void
draw_textf(OFConstantString *format, int left, int top, int gl_num, ...)
{
	@autoreleasepool {
		va_list arguments;
		va_start(arguments, gl_num);
		OFString *str = [[OFString alloc] initWithFormat:format
		                                       arguments:arguments];
		va_end(arguments);
		draw_text(str, left, top, gl_num);

	}
}

void
draw_text(OFString *string, int left, int top, int gl_num)
{
	@autoreleasepool {
		glBlendFunc(GL_ONE, GL_ONE);
		glBindTexture(GL_TEXTURE_2D, gl_num);
		glColor3ub(255, 255, 255);

		int x = left;
		int y = top;

		int i;
		float in_left, in_top, in_right, in_bottom;
		int in_width, in_height;

		const char *str = string.UTF8String;
		size_t len = string.UTF8StringLength;
		for (i = 0; i < len; i++) {
			int c = str[i];

			if (c == '\t') {
				x = (x - left + PIXELTAB) / PIXELTAB *
				        PIXELTAB +
				    left;
				continue;
			}

			if (c == '\f') {
				glColor3ub(64, 255, 128);
				continue;
			}

			if (c == ' ') {
				x += FONTH / 2;
				continue;
			}

			c -= 33;
			if (c < 0 || c >= 95)
				continue;

			in_left = ((float)char_coords[c][0]) / 512.0f;
			in_top = ((float)char_coords[c][1] + 2) / 512.0f;
			in_right = ((float)char_coords[c][2]) / 512.0f;
			in_bottom = ((float)char_coords[c][3] - 2) / 512.0f;

			in_width = char_coords[c][2] - char_coords[c][0];
			in_height = char_coords[c][3] - char_coords[c][1];

			glBegin(GL_QUADS);
			glTexCoord2f(in_left, in_top);
			glVertex2i(x, y);
			glTexCoord2f(in_right, in_top);
			glVertex2i(x + in_width, y);
			glTexCoord2f(in_right, in_bottom);
			glVertex2i(x + in_width, y + in_height);
			glTexCoord2f(in_left, in_bottom);
			glVertex2i(x, y + in_height);
			glEnd();

			xtraverts += 4;
			x += in_width + 1;
		}
	}
}

// also Don's code, so goes in here too :)

void
draw_envbox_aux(float s0, float t0, int x0, int y0, int z0, float s1, float t1,

Modified src/serverbrowser.mm from [442e527d8e] to [a2f42f1499].

239
240
241
242
243
244
245
246
247
248
249




250
251
252
253
254
255
256
257

258
259
260
261
262
263
264
				si.numplayers = getint(p);
				si.minremain = getint(p);
				sgetstr();
				strcpy_s(si.map, text);
				sgetstr();
				strcpy_s(si.sdesc, text);
				break;
			};
		};
	};
};





int
sicompare(const serverinfo *a, const serverinfo *b)
{
	return a->ping > b->ping
	           ? 1
	           : (a->ping < b->ping ? -1 : strcmp(a->name, b->name));
};


void
refreshservers()
{
	checkresolver();
	checkpings();
	if (lastmillis - lastinfo >= 5000)







<
<
<
<
>
>
>
>







<
>







239
240
241
242
243
244
245




246
247
248
249
250
251
252
253
254
255
256

257
258
259
260
261
262
263
264
				si.numplayers = getint(p);
				si.minremain = getint(p);
				sgetstr();
				strcpy_s(si.map, text);
				sgetstr();
				strcpy_s(si.sdesc, text);
				break;




			}
		}
	}
}

int
sicompare(const serverinfo *a, const serverinfo *b)
{
	return a->ping > b->ping
	           ? 1
	           : (a->ping < b->ping ? -1 : strcmp(a->name, b->name));

}

void
refreshservers()
{
	checkresolver();
	checkpings();
	if (lastmillis - lastinfo >= 5000)
281
282
283
284
285
286
287

288

289
290
291
292


293
294
295
296
297
298
299
			sprintf_s(si.full)(
			    si.address.host != ENET_HOST_ANY
			        ? "%s [waiting for server response]"
			        : "%s [unknown host]\t",
			    si.name);
		}
		si.full[50] = 0; // cut off too long server descriptions

		menumanual(1, i, si.full);

		if (!--maxmenu)
			return;
	};
};



void
servermenu()
{
	if (pingsock == ENET_SOCKET_NULL) {
		pingsock = enet_socket_create(ENET_SOCKET_TYPE_DATAGRAM, NULL);
		resolverinit(1, 1000);







>
|
>


<
<
>
>







281
282
283
284
285
286
287
288
289
290
291
292


293
294
295
296
297
298
299
300
301
			sprintf_s(si.full)(
			    si.address.host != ENET_HOST_ANY
			        ? "%s [waiting for server response]"
			        : "%s [unknown host]\t",
			    si.name);
		}
		si.full[50] = 0; // cut off too long server descriptions
		@autoreleasepool {
			menumanual(1, i, @(si.full));
		}
		if (!--maxmenu)
			return;


	}
}

void
servermenu()
{
	if (pingsock == ENET_SOCKET_NULL) {
		pingsock = enet_socket_create(ENET_SOCKET_TYPE_DATAGRAM, NULL);
		resolverinit(1, 1000);