mirror of
https://github.com/jeremysrand/BuGS.git
synced 2025-01-13 19:29:50 +00:00
Start trying to extract the global high scores code so it can be turned into a generic library.
This commit is contained in:
parent
f1a80c792a
commit
b8b9089aa2
@ -116,7 +116,7 @@
|
||||
9DE37B3E2694E0B0005FC562 /* globalScores.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = globalScores.h; sourceTree = "<group>"; };
|
||||
9DE37B3F2694E0B0005FC562 /* globals.s */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.asm; path = globals.s; sourceTree = "<group>"; };
|
||||
9DE37B402694E0B0005FC562 /* gameSegments.s */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.asm; path = gameSegments.s; sourceTree = "<group>"; };
|
||||
9DE37B412694E0B0005FC562 /* score.s */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.asm; path = score.s; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.asm.orcam; };
|
||||
9DE37B412694E0B0005FC562 /* score.s */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.asm; path = score.s; sourceTree = "<group>"; };
|
||||
9DE37B422694E0B0005FC562 /* gamePlayer.s */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.asm; path = gamePlayer.s; sourceTree = "<group>"; };
|
||||
9DE37B432694E0B0005FC562 /* Read.Me.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = Read.Me.md; sourceTree = "<group>"; };
|
||||
9DE37B442694E0B0005FC562 /* global.macros */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = global.macros; sourceTree = "<group>"; };
|
||||
@ -234,9 +234,9 @@
|
||||
9DE37B412694E0B0005FC562 /* score.s */,
|
||||
9DE37B482694E0B0005FC562 /* settings.c */,
|
||||
9DE37B462694E0B0005FC562 /* settings.h */,
|
||||
9DE37B342694E0B0005FC562 /* tileConvert.s */,
|
||||
9DE37B5C2694E0B0005FC562 /* sound */,
|
||||
9DE37B4A2694E0B0005FC562 /* sprites */,
|
||||
9DE37B342694E0B0005FC562 /* tileConvert.s */,
|
||||
9DE37AF62694E070005FC562 /* Makefile */,
|
||||
9DE37AF82694E070005FC562 /* make */,
|
||||
9DE37B112694E070005FC562 /* Supporting Files */,
|
||||
|
@ -22,12 +22,12 @@
|
||||
<key>DiskImage.xcscheme_^#shared#^_</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>2</integer>
|
||||
<integer>1</integer>
|
||||
</dict>
|
||||
<key>doNotBuild.xcscheme_^#shared#^_</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>1</integer>
|
||||
<integer>2</integer>
|
||||
</dict>
|
||||
</dict>
|
||||
</dict>
|
||||
|
@ -149,7 +149,7 @@ COPYBOOTDIRS=
|
||||
# By default, the build uses these arguments with mame:
|
||||
# apple2gs -skip_gameinfo -mouse -window -resolution 1408x1056 -ramsize 4M -sl7 cffa202
|
||||
# If you would like to use different arguments, specify that here.
|
||||
MAMEARGS=apple2gs -skip_gameinfo -mouse -window -resolution 1408x1056 -ramsize 4M -sl3 uthernet -sl7 cffa2
|
||||
MAMEARGS=apple2gs -skip_gameinfo -mouse -window -resolution 1408x1056 -ramsize 4M -sl3 uthernet -sl7 scsi
|
||||
|
||||
# For a desktop application, it can operate in 640x200 or 320x200
|
||||
# resolution. This setting is used to define which horizontal
|
||||
|
@ -14,6 +14,10 @@
|
||||
extern void game(void);
|
||||
extern void randInit(void);
|
||||
extern void waitForVbl(void);
|
||||
extern void uploadSpin1(void);
|
||||
extern void uploadSpin2(void);
|
||||
extern void uploadSpin3(void);
|
||||
extern void displayConnectionString(void);
|
||||
extern void swapStereoChannels(void);
|
||||
|
||||
|
||||
|
@ -16,9 +16,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "game.h"
|
||||
#include "globalScores.h"
|
||||
#include "tileData.h"
|
||||
|
||||
|
||||
// Defines
|
||||
@ -154,6 +152,7 @@ typedef struct tGameNetworkGlobals {
|
||||
tHighScoreRequestWithHash highScoreRequest;
|
||||
Boolean hasHighScoreToSend;
|
||||
tStatusResponse setHighScoreResponse;
|
||||
tHighScoreInitParams initParams;
|
||||
uint16_t errorCode;
|
||||
uint16_t timeout;
|
||||
} tGameNetworkGlobals;
|
||||
@ -172,7 +171,7 @@ Boolean hasGlobalHighScores = FALSE;
|
||||
tScoresResponse highScoreResponse;
|
||||
Word globalScoreAge = 0;
|
||||
tSetHighScoreRequestWithHash setHighScoreRequest;
|
||||
char globalScoreInfo[GAME_NUM_TILES_WIDE + 1];
|
||||
char globalScoreInfo[26];
|
||||
|
||||
|
||||
// Implementation
|
||||
@ -180,12 +179,13 @@ char globalScoreInfo[GAME_NUM_TILES_WIDE + 1];
|
||||
|
||||
segment "highscores";
|
||||
|
||||
void initNetwork(void)
|
||||
void initNetwork(tHighScoreInitParams * params)
|
||||
{
|
||||
networkGlobals = NULL;
|
||||
|
||||
if ((NETWORK_SERVER == NULL) ||
|
||||
(NETWORK_SERVERPORT == 0))
|
||||
if ((params->scoreServer == NULL) ||
|
||||
(params->scorePort == 0) ||
|
||||
(params->waitForVbl == NULL))
|
||||
return;
|
||||
|
||||
LoadOneTool(54, 0x200); // Load Marinetti
|
||||
@ -223,6 +223,8 @@ void initNetwork(void)
|
||||
|
||||
}
|
||||
|
||||
memcpy(&(networkGlobals->initParams), params, sizeof(networkGlobals->initParams));
|
||||
|
||||
networkGlobals->networkStartedConnected = TCPIPGetConnectStatus();
|
||||
if (networkGlobals->networkStartedConnected) {
|
||||
networkGlobals->gameNetworkState = GAME_NETWORK_CONNECTED;
|
||||
@ -230,8 +232,8 @@ void initNetwork(void)
|
||||
networkGlobals->gameNetworkState = GAME_NETWORK_UNCONNECTED;
|
||||
}
|
||||
|
||||
networkGlobals->secrets[0] = NETWORK_SERVERSECRET1;
|
||||
networkGlobals->secrets[1] = NETWORK_SERVERSECRET2;
|
||||
networkGlobals->secrets[0] = params->secret1;
|
||||
networkGlobals->secrets[1] = params->secret2;
|
||||
|
||||
networkGlobals->hasHighScoreToSend = FALSE;
|
||||
|
||||
@ -275,7 +277,7 @@ void disconnectNetwork(void)
|
||||
}
|
||||
|
||||
while (networkGlobals->gameNetworkState > GAME_NETWORK_TCP_UNCONNECTED) {
|
||||
waitForVbl();
|
||||
networkGlobals->initParams.waitForVbl();
|
||||
pollNetwork();
|
||||
}
|
||||
}
|
||||
@ -380,7 +382,8 @@ void pollNetwork(void)
|
||||
break;
|
||||
|
||||
case GAME_NETWORK_UNCONNECTED:
|
||||
displayConnectionString();
|
||||
if (networkGlobals->initParams.displayConnectionString != NULL)
|
||||
networkGlobals->initParams.displayConnectionString();
|
||||
TCPIPConnect(NULL);
|
||||
if ((!toolerror()) &&
|
||||
(TCPIPGetConnectStatus())) {
|
||||
@ -391,7 +394,7 @@ void pollNetwork(void)
|
||||
break;
|
||||
|
||||
case GAME_NETWORK_CONNECTED:
|
||||
TCPIPDNRNameToIP("\p" NETWORK_SERVER, &(networkGlobals->domainNameResolution));
|
||||
TCPIPDNRNameToIP(networkGlobals->initParams.scoreServer, &(networkGlobals->domainNameResolution));
|
||||
if (toolerror()) {
|
||||
networkGlobals->gameNetworkState = GAME_NETWORK_LOOKUP_FAILED;
|
||||
networkGlobals->errorCode = toolerror();
|
||||
@ -418,7 +421,7 @@ void pollNetwork(void)
|
||||
(!networkGlobals->hasHighScoreToSend))
|
||||
break;
|
||||
|
||||
networkGlobals->ipid = TCPIPLogin(myUserId, networkGlobals->domainNameResolution.DNRIPaddress, NETWORK_SERVERPORT, 0, 64);
|
||||
networkGlobals->ipid = TCPIPLogin(networkGlobals->initParams.userId, networkGlobals->domainNameResolution.DNRIPaddress, networkGlobals->initParams.scorePort, 0, 64);
|
||||
if (toolerror()) {
|
||||
networkGlobals->gameNetworkState = GAME_NETWORK_SOCKET_ERROR;
|
||||
networkGlobals->errorCode = toolerror();
|
||||
@ -686,26 +689,30 @@ BOOLEAN sendHighScore(void)
|
||||
networkGlobals->gameNetworkState = GAME_NETWORK_TCP_UNCONNECTED;
|
||||
|
||||
do {
|
||||
waitForVbl();
|
||||
networkGlobals->initParams.waitForVbl();
|
||||
pollNetwork();
|
||||
cycleCount++;
|
||||
|
||||
if ((cycleCount & 0x7) == 0) {
|
||||
switch (cycleCount & 0x18) {
|
||||
case 0x00:
|
||||
uploadSpin1();
|
||||
if (networkGlobals->initParams.uploadSpin != NULL)
|
||||
networkGlobals->initParams.uploadSpin(0);
|
||||
break;
|
||||
|
||||
case 0x08:
|
||||
uploadSpin2();
|
||||
if (networkGlobals->initParams.uploadSpin != NULL)
|
||||
networkGlobals->initParams.uploadSpin(1);
|
||||
break;
|
||||
|
||||
case 0x10:
|
||||
uploadSpin3();
|
||||
if (networkGlobals->initParams.uploadSpin != NULL)
|
||||
networkGlobals->initParams.uploadSpin(2);
|
||||
break;
|
||||
|
||||
case 0x18:
|
||||
uploadSpin2();
|
||||
if (networkGlobals->initParams.uploadSpin != NULL)
|
||||
networkGlobals->initParams.uploadSpin(3);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -718,11 +725,11 @@ BOOLEAN sendHighScore(void)
|
||||
for (cycleCount = strlen(globalScoreInfo); cycleCount < sizeof(globalScoreInfo); cycleCount++) {
|
||||
globalScoreInfo[cycleCount] = ' ';
|
||||
}
|
||||
globalScoreInfo[GAME_NUM_TILES_WIDE] = '\0';
|
||||
globalScoreInfo[25] = '\0'; // TODO - Get rid of hard coded value...
|
||||
displayScorePosition();
|
||||
|
||||
for (cycleCount = 4 * 60; cycleCount > 0; cycleCount--) {
|
||||
waitForVbl();
|
||||
networkGlobals->initParams.waitForVbl();
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
|
@ -12,8 +12,6 @@
|
||||
|
||||
#include <types.h>
|
||||
|
||||
#include "tileData.h"
|
||||
|
||||
typedef struct tHighScore
|
||||
{
|
||||
char scoreText[10];
|
||||
@ -21,11 +19,23 @@ typedef struct tHighScore
|
||||
unsigned long score;
|
||||
} tHighScore;
|
||||
|
||||
extern char globalScoreInfo[GAME_NUM_TILES_WIDE + 1];
|
||||
extern char globalScoreInfo[26]; /* TODO - Get rid of this global and the hard coded length */
|
||||
|
||||
extern unsigned int myUserId;
|
||||
typedef struct tHighScoreInitParams
|
||||
{
|
||||
unsigned int userId;
|
||||
const char * scoreServer; /* Pascal string of the hostname of the score server. */
|
||||
unsigned int scorePort;
|
||||
unsigned long secret1;
|
||||
unsigned long secret2;
|
||||
|
||||
void (*displayConnectionString)(void); /* This function should display a message to the user that the network is being brought up. */
|
||||
void (*waitForVbl)(void); /* This function should wait for the next VBL and is used to poll the network and limit upload time for a high score. */
|
||||
void (*uploadSpin)(int); /* This argument iterates over 0, 1, 2, 3 and then back to 0, 1, 2, etc and is intended to show some kind of spinner to the user
|
||||
while uploading a high score. */
|
||||
} tHighScoreInitParams;
|
||||
|
||||
extern void initNetwork(void);
|
||||
extern void initNetwork(tHighScoreInitParams * params);
|
||||
extern void disconnectNetwork(void);
|
||||
extern void pollNetwork(void);
|
||||
extern void shutdownNetwork(void);
|
||||
@ -33,10 +43,6 @@ extern BOOLEAN canSendHighScore(void);
|
||||
extern BOOLEAN sendHighScore(void);
|
||||
|
||||
// These are actually assembly functions called from the C code.
|
||||
extern void uploadSpin1(void);
|
||||
extern void uploadSpin2(void);
|
||||
extern void uploadSpin3(void);
|
||||
extern void displayConnectionString(void);
|
||||
extern void displayScorePosition(void);
|
||||
|
||||
|
||||
|
35
BuGS/main.c
35
BuGS/main.c
@ -43,9 +43,32 @@ word randomMushroomOffset(void)
|
||||
}
|
||||
|
||||
|
||||
void uploadSpin(int val)
|
||||
{
|
||||
switch (val)
|
||||
{
|
||||
case 0:
|
||||
uploadSpin1();
|
||||
break;
|
||||
|
||||
case 1:
|
||||
uploadSpin2();
|
||||
break;
|
||||
|
||||
case 2:
|
||||
uploadSpin3();
|
||||
break;
|
||||
|
||||
case 3:
|
||||
uploadSpin2();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
static tHighScoreInitParams highScoreInitParams;
|
||||
int event;
|
||||
Ref toolStartupRef;
|
||||
|
||||
@ -73,7 +96,17 @@ int main(void)
|
||||
InitMouse(0);
|
||||
SetMouse(transparent);
|
||||
|
||||
initNetwork();
|
||||
highScoreInitParams.userId = myUserId;
|
||||
highScoreInitParams.scoreServer = "\p" NETWORK_SERVER;
|
||||
highScoreInitParams.scorePort = NETWORK_SERVERPORT;
|
||||
highScoreInitParams.secret1 = NETWORK_SERVERSECRET1;
|
||||
highScoreInitParams.secret2 = NETWORK_SERVERSECRET2;
|
||||
|
||||
highScoreInitParams.displayConnectionString = displayConnectionString;
|
||||
highScoreInitParams.waitForVbl = waitForVbl;
|
||||
highScoreInitParams.uploadSpin = uploadSpin;
|
||||
|
||||
initNetwork(&highScoreInitParams);
|
||||
|
||||
if (!loadSettings())
|
||||
saveSettings();
|
||||
|
@ -12,6 +12,8 @@
|
||||
#include <types.h>
|
||||
|
||||
|
||||
extern unsigned int myUserId;
|
||||
|
||||
extern void saveSettings(void);
|
||||
BOOLEAN loadSettings(void);
|
||||
extern void swapStereoSettings(void);
|
||||
|
Loading…
x
Reference in New Issue
Block a user