Skip to content

Commit be17031

Browse files
committed
Initial networking and overlay enhancements
1 parent 26a3aa5 commit be17031

File tree

10 files changed

+656
-155
lines changed

10 files changed

+656
-155
lines changed

Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ BUILD := build
3131
SOURCES := source
3232
APP_AUTHOR := MasterFeizz
3333
APP_TITLE := ctrQuake
34+
APP_DESCRIPTION := Port of Quake
3435

3536
DATA := data
3637
INCLUDES := include
@@ -143,9 +144,11 @@ COMMON_OBJS = chase.o \
143144
snd_mem.o \
144145
snd_ctr.o \
145146
vid_ctr.o \
146-
net_none.o \
147+
net_bsd.o \
148+
net_udpctr.o \
147149
in_ctr.o \
148-
cd_null.o
150+
cd_null.o \
151+
touch_ctr.o
149152

150153

151154
CFILES := $(COMMON_OBJS)

keyboardOverlay.bin

0 Bytes
Binary file not shown.

source/in_ctr.c

Lines changed: 8 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -26,167 +26,42 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2626
#include <3ds.h>
2727
#include "ctr.h"
2828

29-
//Touchscreen mode identifiers
30-
#define TMODE_TOUCHPAD 1
31-
#define TMODE_KEYBOARD 2
32-
#define TMODE_SETTINGS 3
33-
34-
//Keyboard is currently laid out on a 14*4 grid of 20px*20px boxes for lazy implementation
35-
char keymap[14 * 4] = {
36-
'`' , '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '+', K_BACKSPACE,
37-
K_TAB, 'q' , 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '|',
38-
0, 'a' , 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', K_ENTER, K_ENTER,
39-
K_SHIFT, 'z' , 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/', K_SHIFT, K_SHIFT, K_SHIFT
40-
};
41-
42-
u16* touchpadOverlay;
43-
u16* keyboardOverlay;
44-
4529
circlePosition cstick;
4630
circlePosition circlepad;
4731
touchPosition oldtouch, touch;
48-
char lastKey = 0;
49-
50-
int tmode;
51-
u16* tfb;
52-
53-
u64 lastTap = 0;
54-
void ctrTouchpadTap(){
55-
u64 thisTap = Sys_FloatTime();
56-
if(oldtouch.py > 195 && oldtouch.py < 240 && oldtouch.px > 0 && oldtouch.px < 45){
57-
Key_Event('`', true);
58-
lastKey = '`';
59-
}
60-
else if(oldtouch.py > 195 && oldtouch.py < 240 && oldtouch.px > 1 && oldtouch.px < 320){
61-
tmode = 2;
62-
ctrDrawTouchOverlay();
63-
}
64-
else if ((thisTap - lastTap) < 0.5){
65-
Key_Event(K_SPACE, true);
66-
lastKey = K_SPACE;
67-
}
68-
lastTap = thisTap;
69-
}
70-
71-
void ctrKeyboardTap(){
72-
if(oldtouch.py > 20 && oldtouch.py < 100 && oldtouch.px > 15 && oldtouch.px < 295){
73-
char key = keymap[((oldtouch.py - 20) / 20) * 14 + (oldtouch.px - 15)/20];
74-
Key_Event(key, true);
75-
lastKey = key;
76-
}
77-
78-
else if(oldtouch.py > 100 && oldtouch.py < 120 && oldtouch.px > 95 && oldtouch.px < 215){
79-
Key_Event(K_SPACE, true);
80-
lastKey = K_SPACE;
81-
}
82-
83-
if(oldtouch.py > 195 && oldtouch.py < 240 && oldtouch.px > 1 && oldtouch.px < 320){
84-
tmode = 1;
85-
ctrDrawTouchOverlay();
86-
}
87-
}
88-
89-
void ctrProcessTap(){
90-
if(tmode == TMODE_TOUCHPAD)
91-
ctrTouchpadTap();
92-
else
93-
ctrKeyboardTap();
94-
}
95-
96-
void ctrDrawTouchOverlay(){
97-
u16* overlay = 0;
98-
if(tmode == TMODE_TOUCHPAD)
99-
overlay = touchpadOverlay;
100-
else
101-
overlay = keyboardOverlay;
102-
103-
if(!overlay)
104-
return;
105-
int x,y;
106-
107-
for(x=0; x<320; x++){
108-
for(y=0; y<240;y++){
109-
tfb[(x*240 + (239 - y))] = overlay[(y*320 + x)];
110-
}
111-
}
112-
113-
}
11432

11533
void IN_Init (void)
11634
{
11735
if ( COM_CheckParm ("-nomouse") )
11836
return;
119-
120-
tmode = TMODE_TOUCHPAD; //Start in touchpad Mode
121-
122-
tfb = (u16*)gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL);
123-
124-
//Load overlay files from sdmc for easier testing
125-
FILE *texture = fopen("touchpadOverlay.bin", "rb");
126-
if(!texture)
127-
Sys_Error("Could not open touchpadOverlay.bin\n");
128-
fseek(texture, 0, SEEK_END);
129-
int size = ftell(texture);
130-
fseek(texture, 0, SEEK_SET);
131-
touchpadOverlay = malloc(size);
132-
fread(touchpadOverlay, 1, size, texture);
133-
fclose(texture);
134-
135-
texture = fopen("keyboardOverlay.bin", "rb");
136-
if(!texture)
137-
Sys_Error("Could not open keyboardOverlay.bin\n");
138-
fseek(texture, 0, SEEK_END);
139-
size = ftell(texture);
140-
fseek(texture, 0, SEEK_SET);
141-
keyboardOverlay = malloc(size);
142-
fread(keyboardOverlay, 1, size, texture);
143-
fclose(texture);
14437
}
14538

14639
void IN_Shutdown (void)
14740
{
148-
free(touchpadOverlay);
149-
free(keyboardOverlay);
15041
}
15142

15243
void IN_Commands (void)
15344
{
15445
}
15546

156-
u64 tick;
157-
15847
void IN_Move (usercmd_t *cmd)
15948
{
160-
161-
if(lastKey){
162-
Key_Event(lastKey, false);
163-
lastKey = 0;
164-
}
165-
166-
if(hidKeysDown() & KEY_TOUCH){
167-
hidTouchRead(&oldtouch);
168-
tick = Sys_FloatTime();
169-
}
170-
171-
//If touchscreen is released in certain amount of time it's a tap
172-
if(hidKeysUp() & KEY_TOUCH){
173-
if((Sys_FloatTime() - tick) < 1.0) //FIX ME: find optimal timeframe
174-
ctrProcessTap();
175-
}
176-
177-
else if(hidKeysHeld() & KEY_TOUCH){
49+
if(hidKeysHeld() & KEY_TOUCH){
17850
hidTouchRead(&touch);
179-
touch.px = (touch.px + oldtouch.px) / 2;
180-
touch.py = (touch.py + oldtouch.py) / 2;
51+
touch.px = (touch.px + oldtouch.px) / 2;
52+
touch.py = (touch.py + oldtouch.py) / 2;
18153
cl.viewangles[YAW] -= (touch.px - oldtouch.px) * sensitivity.value/2;
18254
if(in_mlook.state & 1)
18355
cl.viewangles[PITCH] += (touch.py - oldtouch.py) * sensitivity.value/2;
18456
oldtouch = touch;
18557
}
18658

18759
hidCircleRead(&circlepad);
188-
cmd->forwardmove += m_forward.value * circlepad.dy * 2; //FIX ME: allow circlepad sensitivity to be changed
189-
cmd->sidemove += m_side.value * circlepad.dx * 2; //FIX ME: allow player to choose between strafing or turning
60+
//CirclePad deadzone to fix ghost movements
61+
if(abs(circlepad.dy) > 15)
62+
cmd->forwardmove += m_forward.value * circlepad.dy * 2; //FIX ME: allow circlepad sensitivity to be changed
63+
if(abs(circlepad.dx) > 15)
64+
cmd->sidemove += m_side.value * circlepad.dx * 2; //FIX ME: allow player to choose between strafing or turning
19065

19166
//cStick is only available on N3DS... Until libctru implements support for circlePad Pro
19267
if(isN3DS){

source/net_dgrm.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
88
99
This program is distributed in the hope that it will be useful,
1010
but WITHOUT ANY WARRANTY; without even the implied warranty of
11-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1212
1313
See the GNU General Public License for more details.
1414
@@ -326,7 +326,7 @@ int Datagram_GetMessage (qsocket_t *sock)
326326
ReSendMessage (sock);
327327

328328
while(1)
329-
{
329+
{
330330
length = sfunc.Read (sock->socket, (byte *)&packetBuffer, NET_DATAGRAMSIZE, &readaddr);
331331

332332
// if ((rand() & 255) > 220)
@@ -890,7 +890,7 @@ static qsocket_t *_Datagram_CheckNewConnections (void)
890890
int activeNumber;
891891
int clientNumber;
892892
client_t *client;
893-
893+
894894
playerNumber = MSG_ReadByte();
895895
activeNumber = -1;
896896
for (clientNumber = 0, client = svs.clients; clientNumber < svs.maxclients; clientNumber++, client++)
@@ -1067,7 +1067,7 @@ static qsocket_t *_Datagram_CheckNewConnections (void)
10671067
return NULL;
10681068
}
10691069

1070-
// everything is allocated, just fill in the details
1070+
// everything is allocated, just fill in the details
10711071
sock->socket = newsock;
10721072
sock->landriver = net_landriverlevel;
10731073
sock->addr = clientaddr;
@@ -1210,7 +1210,8 @@ void Datagram_SearchForHosts (qboolean xmit)
12101210
}
12111211
}
12121212

1213-
1213+
//Temporary fix for 3DS
1214+
int ctrport_fix = 5001;
12141215
static qsocket_t *_Datagram_Connect (char *host)
12151216
{
12161217
struct qsockaddr sendaddr;
@@ -1227,7 +1228,8 @@ static qsocket_t *_Datagram_Connect (char *host)
12271228
if (dfunc.GetAddrFromName(host, &sendaddr) == -1)
12281229
return NULL;
12291230

1230-
newsock = dfunc.OpenSocket (0);
1231+
newsock = dfunc.OpenSocket (ctrport_fix);
1232+
ctrport_fix++;
12311233
if (newsock == -1)
12321234
return NULL;
12331235

source/net_udp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
88
99
This program is distributed in the hope that it will be useful,
1010
but WITHOUT ANY WARRANTY; without even the implied warranty of
11-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1212
1313
See the GNU General Public License for more details.
1414

0 commit comments

Comments
 (0)