Overview
Comment: | More string cleanups |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
3e5cb10d19eb7d5dbe346bff2f443f7e |
User & Date: | js on 2025-03-09 00:56:28 |
Other Links: | manifest | tags |
Context
2025-03-09
| ||
10:25 | Use SDL_TextInputEvent for input check-in: 4c092023dc user: js tags: trunk | |
00:56 | More string cleanups check-in: 3e5cb10d19 user: js tags: trunk | |
00:39 | Clean up user data vs. game data check-in: d751d8b0b7 user: js tags: trunk | |
Changes
Modified src/rendergl.mm from [ed4ed00e36] to [f024dcac09].
︙ | ︙ | |||
159 160 161 162 163 164 165 | } } // management of texture slots // each texture slot can have multople texture frames, of which currently only // the first is used additional frames can be used for various shaders | | | | | | | | > | | | 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 | } } // management of texture slots // each texture slot can have multople texture frames, of which currently only // the first is used additional frames can be used for various shaders static const int MAXTEX = 1000; static int texx[MAXTEX]; // ( loaded texture ) -> ( name, size ) static int texy[MAXTEX]; static OFString *texname[MAXTEX]; static int curtex = 0; static const int FIRSTTEX = 1000; // opengl id = loaded id + FIRSTTEX // std 1+, sky 14+, mdls 20+ static const int MAXFRAMES = 2; // increase to allow more complex shader defs static int mapping[256] [MAXFRAMES]; // ( cube texture, frame ) -> ( opengl id, name ) static OFString *mapname[256][MAXFRAMES]; void purgetextures() { loopi(256) loop(j, MAXFRAMES) mapping[i][j] = 0; } |
︙ | ︙ | |||
194 195 196 197 198 199 200 | texture(OFString *aframe, OFString *name) { @autoreleasepool { int num = curtexnum++, frame = (int)aframe.longLongValue; if (num < 0 || num >= 256 || frame < 0 || frame >= MAXFRAMES) return; mapping[num][frame] = 1; | | < | 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | texture(OFString *aframe, OFString *name) { @autoreleasepool { int num = curtexnum++, frame = (int)aframe.longLongValue; if (num < 0 || num >= 256 || frame < 0 || frame >= MAXFRAMES) return; mapping[num][frame] = 1; mapname[num][frame] = name; } } COMMAND(texture, ARG_2STR) int lookuptexture(int tex, int *xs, int *ys) { |
︙ | ︙ | |||
218 219 220 221 222 223 224 | *xs = *ys = 16; if (tid == 0) return 1; // crosshair :) loopi(curtex) // lazily happens once per "texture" command, basically { | | | | | 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 | *xs = *ys = 16; if (tid == 0) return 1; // crosshair :) loopi(curtex) // lazily happens once per "texture" command, basically { if ([mapname[tex][frame] isEqual:texname[i]]) { mapping[tex][frame] = tid = i + FIRSTTEX; *xs = texx[i]; *ys = texy[i]; return tid; } } if (curtex == MAXTEX) fatal(@"loaded too many textures"); int tnum = curtex + FIRSTTEX; texname[curtex] = mapname[tex][frame]; @autoreleasepool { OFString *path = [OFString stringWithFormat:@"packages/%@", texname[curtex]]; if (installtex(tnum, [Cube.sharedInstance.gameDataIRI IRIByAppendingPathComponent:path], xs, ys, false)) { mapping[tex][frame] = tnum; texx[curtex] = *xs; |
︙ | ︙ |
Modified src/serverms.mm from [1d1c1a8ddd] to [fcffeffeb7].
1 2 3 4 | // all server side masterserver and pinging functionality #include "cube.h" | | | | > | > | > | > > | | | | | | | | | | | | | | > > | > | | > | > > | | | > | | 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 | // all server side masterserver and pinging functionality #include "cube.h" static ENetSocket mssock = ENET_SOCKET_NULL; static void httpgetsend(ENetAddress &ad, OFString *hostname, OFString *req, OFString *ref, OFString *agent) { if (ad.host == ENET_HOST_ANY) { [OFStdOut writeFormat:@"looking up %@...\n", hostname]; @autoreleasepool { enet_address_set_host(&ad, hostname.UTF8String); } if (ad.host == ENET_HOST_ANY) return; } if (mssock != ENET_SOCKET_NULL) enet_socket_destroy(mssock); mssock = enet_socket_create(ENET_SOCKET_TYPE_STREAM, NULL); if (mssock == ENET_SOCKET_NULL) { printf("could not open socket\n"); return; } if (enet_socket_connect(mssock, &ad) < 0) { printf("could not connect\n"); return; } ENetBuffer buf; OFString *httpget = [OFString stringWithFormat:@"GET %@ HTTP/1.0\n" @"Host: %@\n" @"Referer: %@\n" @"User-Agent: %@\n\n", req, hostname, ref, agent]; buf.data = (void *)httpget.UTF8String; buf.dataLength = httpget.UTF8StringLength; [OFStdOut writeFormat:@"sending request to %@...\n", hostname]; enet_socket_send(mssock, NULL, &buf, 1); } static void httpgetrecieve(ENetBuffer &buf) { if (mssock == ENET_SOCKET_NULL) return; enet_uint32 events = ENET_SOCKET_WAIT_RECEIVE; if (enet_socket_wait(mssock, &events, 0) >= 0 && events) { int len = enet_socket_receive(mssock, NULL, &buf, 1); if (len <= 0) { enet_socket_destroy(mssock); mssock = ENET_SOCKET_NULL; return; } buf.data = ((char *)buf.data) + len; ((char *)buf.data)[0] = 0; buf.dataLength -= len; } } static uchar * stripheader(uchar *b) { char *s = strstr((char *)b, "\n\r\n"); if (!s) s = strstr((char *)b, "\n\n"); return s ? (uchar *)s : b; } static ENetAddress masterserver = { ENET_HOST_ANY, 80 }; static int updmaster = 0; static OFString *masterbase; static OFString *masterpath; static uchar masterrep[MAXTRANS]; static ENetBuffer masterb; static void updatemasterserver(int seconds) { // send alive signal to masterserver every hour of uptime if (seconds > updmaster) { @autoreleasepool { OFString *path = [OFString stringWithFormat:@"%@register.do?action=add", masterpath]; httpgetsend(masterserver, masterbase, path, @"cubeserver", @"Cube Server"); } masterrep[0] = 0; masterb.data = masterrep; masterb.dataLength = MAXTRANS - 1; updmaster = seconds + 60 * 60; } } static void checkmasterreply() { bool busy = mssock != ENET_SOCKET_NULL; httpgetrecieve(masterb); if (busy && mssock == ENET_SOCKET_NULL) printf("masterserver reply: %s\n", stripheader(masterrep)); } uchar * retrieveservers(uchar *buf, int buflen) { @autoreleasepool { OFString *path = [OFString stringWithFormat:@"%@retrieve.do?item=list", masterpath]; httpgetsend(masterserver, masterbase, path, @"cubeserver", @"Cube Server"); } ENetBuffer eb; buf[0] = 0; eb.data = buf; eb.dataLength = buflen - 1; while (mssock != ENET_SOCKET_NULL) httpgetrecieve(eb); return stripheader(buf); } static ENetSocket pongsock = ENET_SOCKET_NULL; static OFString *serverdesc; void serverms(int mode, int numplayers, int minremain, OFString *smapname, int seconds, bool isfull) { checkmasterreply(); |
︙ | ︙ | |||
149 150 151 152 153 154 155 | servermsinit(OFString *master_, OFString *sdesc, bool listen) { @autoreleasepool { const char *master = master_.UTF8String; const char *mid = strstr(master, "/"); if (!mid) mid = master; | | > | | 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | servermsinit(OFString *master_, OFString *sdesc, bool listen) { @autoreleasepool { const char *master = master_.UTF8String; const char *mid = strstr(master, "/"); if (!mid) mid = master; masterpath = @(mid); masterbase = [[OFString alloc] initWithUTF8String:master length:mid - master]; serverdesc = sdesc; if (listen) { ENetAddress address = { ENET_HOST_ANY, CUBE_SERVINFO_PORT }; pongsock = enet_socket_create( ENET_SOCKET_TYPE_DATAGRAM, &address); if (pongsock == ENET_SOCKET_NULL) fatal(@"could not create server info socket\n"); } } } |