Skip to content

Commit

Permalink
Initial networking and overlay enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
masterfeizz committed Oct 23, 2015
1 parent 26a3aa5 commit be17031
Show file tree
Hide file tree
Showing 10 changed files with 656 additions and 155 deletions.
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ BUILD := build
SOURCES := source
APP_AUTHOR := MasterFeizz
APP_TITLE := ctrQuake
APP_DESCRIPTION := Port of Quake

DATA := data
INCLUDES := include
Expand Down Expand Up @@ -143,9 +144,11 @@ COMMON_OBJS = chase.o \
snd_mem.o \
snd_ctr.o \
vid_ctr.o \
net_none.o \
net_bsd.o \
net_udpctr.o \
in_ctr.o \
cd_null.o
cd_null.o \
touch_ctr.o


CFILES := $(COMMON_OBJS)
Expand Down
Binary file modified keyboardOverlay.bin
Binary file not shown.
141 changes: 8 additions & 133 deletions source/in_ctr.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,167 +26,42 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <3ds.h>
#include "ctr.h"

//Touchscreen mode identifiers
#define TMODE_TOUCHPAD 1
#define TMODE_KEYBOARD 2
#define TMODE_SETTINGS 3

//Keyboard is currently laid out on a 14*4 grid of 20px*20px boxes for lazy implementation
char keymap[14 * 4] = {
'`' , '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '+', K_BACKSPACE,
K_TAB, 'q' , 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '|',
0, 'a' , 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', K_ENTER, K_ENTER,
K_SHIFT, 'z' , 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/', K_SHIFT, K_SHIFT, K_SHIFT
};

u16* touchpadOverlay;
u16* keyboardOverlay;

circlePosition cstick;
circlePosition circlepad;
touchPosition oldtouch, touch;
char lastKey = 0;

int tmode;
u16* tfb;

u64 lastTap = 0;
void ctrTouchpadTap(){
u64 thisTap = Sys_FloatTime();
if(oldtouch.py > 195 && oldtouch.py < 240 && oldtouch.px > 0 && oldtouch.px < 45){
Key_Event('`', true);
lastKey = '`';
}
else if(oldtouch.py > 195 && oldtouch.py < 240 && oldtouch.px > 1 && oldtouch.px < 320){
tmode = 2;
ctrDrawTouchOverlay();
}
else if ((thisTap - lastTap) < 0.5){
Key_Event(K_SPACE, true);
lastKey = K_SPACE;
}
lastTap = thisTap;
}

void ctrKeyboardTap(){
if(oldtouch.py > 20 && oldtouch.py < 100 && oldtouch.px > 15 && oldtouch.px < 295){
char key = keymap[((oldtouch.py - 20) / 20) * 14 + (oldtouch.px - 15)/20];
Key_Event(key, true);
lastKey = key;
}

else if(oldtouch.py > 100 && oldtouch.py < 120 && oldtouch.px > 95 && oldtouch.px < 215){
Key_Event(K_SPACE, true);
lastKey = K_SPACE;
}

if(oldtouch.py > 195 && oldtouch.py < 240 && oldtouch.px > 1 && oldtouch.px < 320){
tmode = 1;
ctrDrawTouchOverlay();
}
}

void ctrProcessTap(){
if(tmode == TMODE_TOUCHPAD)
ctrTouchpadTap();
else
ctrKeyboardTap();
}

void ctrDrawTouchOverlay(){
u16* overlay = 0;
if(tmode == TMODE_TOUCHPAD)
overlay = touchpadOverlay;
else
overlay = keyboardOverlay;

if(!overlay)
return;
int x,y;

for(x=0; x<320; x++){
for(y=0; y<240;y++){
tfb[(x*240 + (239 - y))] = overlay[(y*320 + x)];
}
}

}

void IN_Init (void)
{
if ( COM_CheckParm ("-nomouse") )
return;

tmode = TMODE_TOUCHPAD; //Start in touchpad Mode

tfb = (u16*)gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL);

//Load overlay files from sdmc for easier testing
FILE *texture = fopen("touchpadOverlay.bin", "rb");
if(!texture)
Sys_Error("Could not open touchpadOverlay.bin\n");
fseek(texture, 0, SEEK_END);
int size = ftell(texture);
fseek(texture, 0, SEEK_SET);
touchpadOverlay = malloc(size);
fread(touchpadOverlay, 1, size, texture);
fclose(texture);

texture = fopen("keyboardOverlay.bin", "rb");
if(!texture)
Sys_Error("Could not open keyboardOverlay.bin\n");
fseek(texture, 0, SEEK_END);
size = ftell(texture);
fseek(texture, 0, SEEK_SET);
keyboardOverlay = malloc(size);
fread(keyboardOverlay, 1, size, texture);
fclose(texture);
}

void IN_Shutdown (void)
{
free(touchpadOverlay);
free(keyboardOverlay);
}

void IN_Commands (void)
{
}

u64 tick;

void IN_Move (usercmd_t *cmd)
{

if(lastKey){
Key_Event(lastKey, false);
lastKey = 0;
}

if(hidKeysDown() & KEY_TOUCH){
hidTouchRead(&oldtouch);
tick = Sys_FloatTime();
}

//If touchscreen is released in certain amount of time it's a tap
if(hidKeysUp() & KEY_TOUCH){
if((Sys_FloatTime() - tick) < 1.0) //FIX ME: find optimal timeframe
ctrProcessTap();
}

else if(hidKeysHeld() & KEY_TOUCH){
if(hidKeysHeld() & KEY_TOUCH){
hidTouchRead(&touch);
touch.px = (touch.px + oldtouch.px) / 2;
touch.py = (touch.py + oldtouch.py) / 2;
touch.px = (touch.px + oldtouch.px) / 2;
touch.py = (touch.py + oldtouch.py) / 2;
cl.viewangles[YAW] -= (touch.px - oldtouch.px) * sensitivity.value/2;
if(in_mlook.state & 1)
cl.viewangles[PITCH] += (touch.py - oldtouch.py) * sensitivity.value/2;
oldtouch = touch;
}

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

//cStick is only available on N3DS... Until libctru implements support for circlePad Pro
if(isN3DS){
Expand Down
14 changes: 8 additions & 6 deletions source/net_dgrm.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
Expand Down Expand Up @@ -326,7 +326,7 @@ int Datagram_GetMessage (qsocket_t *sock)
ReSendMessage (sock);

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

// if ((rand() & 255) > 220)
Expand Down Expand Up @@ -890,7 +890,7 @@ static qsocket_t *_Datagram_CheckNewConnections (void)
int activeNumber;
int clientNumber;
client_t *client;

playerNumber = MSG_ReadByte();
activeNumber = -1;
for (clientNumber = 0, client = svs.clients; clientNumber < svs.maxclients; clientNumber++, client++)
Expand Down Expand Up @@ -1067,7 +1067,7 @@ static qsocket_t *_Datagram_CheckNewConnections (void)
return NULL;
}

// everything is allocated, just fill in the details
// everything is allocated, just fill in the details
sock->socket = newsock;
sock->landriver = net_landriverlevel;
sock->addr = clientaddr;
Expand Down Expand Up @@ -1210,7 +1210,8 @@ void Datagram_SearchForHosts (qboolean xmit)
}
}


//Temporary fix for 3DS
int ctrport_fix = 5001;
static qsocket_t *_Datagram_Connect (char *host)
{
struct qsockaddr sendaddr;
Expand All @@ -1227,7 +1228,8 @@ static qsocket_t *_Datagram_Connect (char *host)
if (dfunc.GetAddrFromName(host, &sendaddr) == -1)
return NULL;

newsock = dfunc.OpenSocket (0);
newsock = dfunc.OpenSocket (ctrport_fix);
ctrport_fix++;
if (newsock == -1)
return NULL;

Expand Down
2 changes: 1 addition & 1 deletion source/net_udp.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
Expand Down
Loading

0 comments on commit be17031

Please sign in to comment.