summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMario Kilies <MarioKilies@GMX.net>2011-01-25 13:28:15 +0100
committerMario Kilies <MarioKilies@GMX.net>2011-01-25 13:28:15 +0100
commitec98567cc51fa1d559cf1fe076898b6537053499 (patch)
treedfc07fa64a412f6ce1fa0701dc1ce5e9eacf82e7 /src
parent52f95177eb8050f073a3d65413feb16cfce93baa (diff)
Minor changes. Renamed global.[ch] to data_store.[ch], data_store to data_store_t and datamodel() to data_store().
Diffstat (limited to 'src')
-rw-r--r--src/client_game_states.c10
-rw-r--r--src/data_store.c18
-rw-r--r--src/data_store.h20
-rw-r--r--src/game.c6
-rw-r--r--src/global.c37
-rw-r--r--src/global.h28
-rw-r--r--src/net/client.c18
-rw-r--r--src/net/server.c15
-rw-r--r--src/server_game_states.c8
9 files changed, 66 insertions, 94 deletions
diff --git a/src/client_game_states.c b/src/client_game_states.c
index 3dd8d90..58e55db 100644
--- a/src/client_game_states.c
+++ b/src/client_game_states.c
@@ -1,11 +1,11 @@
#include "game_states.h"
#include "net/comm.h"
#include "ui.h"
-#include "global.h"
+#include "data_store.h"
game_state_t state_client_wait_for_hand_cards(const int sock, const uint8_t round)
{
- data_store *d = datamodel();
+ data_store_t *d = data_store();
if(round == 1)
{
@@ -24,7 +24,7 @@ game_state_t state_client_wait_for_hand_cards(const int sock, const uint8_t roun
game_state_t state_client_select_open_card(const int sock)
{
- data_store *d = datamodel();
+ data_store_t *d = data_store();
uint8_t open_card_idx;
// Select open card
@@ -43,7 +43,7 @@ game_state_t state_client_select_open_card(const int sock)
game_state_t state_client_wait_for_open_cards(const int sock)
{
- data_store *d = datamodel();
+ data_store_t *d = data_store();
net_recv(sock, msg_type_selected_card_all);
player_list_sort_by_open_card(&d->player_list, d->player_list.count); // sort in ascending order
@@ -57,7 +57,7 @@ game_state_t state_client_wait_for_open_cards(const int sock)
game_state_t state_client_play_cards(const int sock, const uint8_t round)
{
#if 0
- data_store *d = datamodel();
+ data_store_t *d = data_store();
uint8_t stack_idx;
foreach(open_card)
diff --git a/src/data_store.c b/src/data_store.c
new file mode 100644
index 0000000..e9cd782
--- /dev/null
+++ b/src/data_store.c
@@ -0,0 +1,18 @@
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include "data_store.h"
+
+static data_store_t *d = NULL;
+
+// returns global data store
+data_store_t* data_store(void)
+{
+ if(!d)
+ {
+ d = malloc(sizeof(data_store_t));
+ memset(d, 0, sizeof(data_store_t));
+ }
+
+ return d;
+}
diff --git a/src/data_store.h b/src/data_store.h
new file mode 100644
index 0000000..afc87bc
--- /dev/null
+++ b/src/data_store.h
@@ -0,0 +1,20 @@
+#ifndef OXEN_DATA_STORE_H
+#define OXEN_DATA_STORE_H
+
+#include "player.h"
+#include "table_stacks.h"
+#include "hand.h"
+
+typedef struct
+{
+ char nickname[MAX_PLAYER_NAME_LENGTH+1];
+ player_list_t player_list;
+ table_stacks_t table_stacks;
+ hand_t hand;
+ uint8_t stack_index;
+ card selected_card;
+} data_store_t;
+
+data_store_t *data_store(void);
+
+#endif // OXEN_DATA_STORE_H
diff --git a/src/game.c b/src/game.c
index 1c86c73..6addee3 100644
--- a/src/game.c
+++ b/src/game.c
@@ -10,7 +10,7 @@
#include <curses.h>
#include <sys/types.h>
#include "ui.h"
-#include "global.h"
+#include "data_store.h"
#include "net/comm.h"
#include "net/client.h"
#include "net/server.h"
@@ -102,7 +102,7 @@ void start_game(const bool servermode, const char* addr, const char* port)
srand(time(0)); // Initialize RNG
- data_store* data = datamodel();
+ data_store_t *data = data_store();
server_sock = server_start(port);
server_get_players(server_sock, &client_socks, num_players);
@@ -130,7 +130,7 @@ void start_game(const bool servermode, const char* addr, const char* port)
sleep(1); // TODO make sure server process is listening
sock = client_connect_server(addr, port);
- data_store* data = datamodel();
+ data_store_t *data = data_store();
strncpy(data->nickname, "nickname", 10);
net_send(sock, msg_type_hello, NULL);
diff --git a/src/global.c b/src/global.c
deleted file mode 100644
index d2c0804..0000000
--- a/src/global.c
+++ /dev/null
@@ -1,37 +0,0 @@
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-#include "global.h"
-
-static data_store* data = NULL;
-
-// returns global data_store
-data_store* datamodel()
-{
- if(data == NULL)
- {
- data = malloc(sizeof(data_store));
- memset(data, 0, sizeof(data_store));
- }
-
- return data;
-}
-
-// indicate which part of model has been changed,
-// so UI can be redrawn
-void updated_model(update_type_t action)
-{
- switch(action)
- {
- case update_type_players:
- // ui_redraw_player_list()
- break;
- case update_type_stacks:
- // ui_redraw_stacks()
- break;
- case update_type_hand:
- // ui_redraw_hand()
- break;
- }
-}
-
diff --git a/src/global.h b/src/global.h
deleted file mode 100644
index 14bbc62..0000000
--- a/src/global.h
+++ /dev/null
@@ -1,28 +0,0 @@
-#ifndef OXEN_GLOBAL_H
-#define OXEN_GLOBAL_H
-
-#include "player.h"
-#include "table_stacks.h"
-#include "hand.h"
-
-typedef struct
-{
- char nickname[MAX_PLAYER_NAME_LENGTH+1];
- player_list_t player_list;
- table_stacks_t table_stacks;
- hand_t hand;
- uint8_t stack_index;
- card selected_card;
-} data_store;
-
-typedef enum
-{
- update_type_players = 0x0,
- update_type_stacks = 0x1,
- update_type_hand = 0x2
-} update_type_t;
-
-void updated_model(update_type_t type);
-data_store* datamodel();
-
-#endif // OXEN_GLOBAL_H
diff --git a/src/net/client.c b/src/net/client.c
index 7f1f98a..ae0c828 100644
--- a/src/net/client.c
+++ b/src/net/client.c
@@ -7,7 +7,7 @@
#include <unistd.h>
#include <assert.h>
#include "client.h"
-#include "../global.h"
+#include "../data_store.h"
#include "../player.h"
#include "../game.h"
@@ -66,7 +66,7 @@ bool client_parse_player_list(const msg_t *m)
{
assert(m != NULL);
- data_store* ds = datamodel();
+ data_store_t *ds = data_store();
uint32_t pos = 0;
ds->player_list.count = m->payload[pos++];
@@ -91,7 +91,7 @@ bool client_parse_deal_hand(const msg_t *m)
assert(m != NULL);
assert(m->hdr.payload_length == MAX_HAND_CARDS); // deal_cards packet have fixed size
- data_store* ds = datamodel();
+ data_store_t *ds = data_store();
for(int i=0; i<MAX_HAND_CARDS; i++)
ds->hand.cards[i] = m->payload[i];
@@ -104,7 +104,7 @@ bool client_parse_selected_stack(const msg_t *m)
assert(m != NULL);
assert(m->hdr.payload_length == 1);
- data_store* ds = datamodel();
+ data_store_t *ds = data_store();
ds->stack_index = m->payload[0];
assert(ds->stack_index <= NUM_TABLE_STACKS);
@@ -117,7 +117,7 @@ bool client_parse_initial_stacks(const msg_t *m)
assert(m != NULL);
assert(m->hdr.payload_length == NUM_TABLE_STACKS);
- data_store* ds = datamodel();
+ data_store_t *ds = data_store();
for(int i=0; i<NUM_TABLE_STACKS; i++)
ds->table_stacks.stacks[i].cards[0] = m->payload[i];
@@ -129,7 +129,7 @@ bool client_parse_selected_card_all(const msg_t *m)
assert(m != NULL);
assert(m->hdr.payload_length % 2 == 0); // payload: n times id+card
- data_store* ds = datamodel();
+ data_store_t *ds = data_store();
for(int i=0; i<m->hdr.payload_length; i+=2)
{
player_id_t pid = m->payload[i];
@@ -142,7 +142,7 @@ bool client_parse_selected_card_all(const msg_t *m)
void client_prep_hello(msg_t *m)
{
- data_store* ds = datamodel();
+ data_store_t *ds = data_store();
uint8_t namelen = strlen(ds->nickname);
m->hdr.type = msg_type_hello;
memcpy(m->payload, ds->nickname, namelen);
@@ -151,7 +151,7 @@ void client_prep_hello(msg_t *m)
void client_prep_selected_card(msg_t *m)
{
- data_store* ds = datamodel();
+ data_store_t *ds = data_store();
card c = ds->selected_card;
assert(c >= MIN_CARD && c <= MAX_CARD);
@@ -162,7 +162,7 @@ void client_prep_selected_card(msg_t *m)
void client_prep_selected_stack(msg_t *m)
{
- data_store* ds = datamodel();
+ data_store_t *ds = data_store();
assert(ds->stack_index <= NUM_TABLE_STACKS);
m->hdr.type = msg_type_selected_stack_c;
diff --git a/src/net/server.c b/src/net/server.c
index faad773..2975ec9 100644
--- a/src/net/server.c
+++ b/src/net/server.c
@@ -7,7 +7,7 @@
#include <unistd.h>
#include <assert.h>
#include "server.h"
-#include "../global.h"
+#include "../data_store.h"
/**
* Server side function; start server on specified port
@@ -113,7 +113,7 @@ bool server_parse_hello(const msg_t *m)
assert(m->hdr.payload_length > 0);
assert(m->hdr.payload_length < MAX_PLAYER_NAME_LENGTH);
- data_store* ds = datamodel();
+ data_store_t *ds = data_store();
for(int i=0; i<ds->player_list.count; i++)
{
@@ -131,7 +131,7 @@ bool server_parse_selected_card(const msg_t *m)
assert(m != NULL);
assert(m->hdr.payload_length == 1);
- data_store* ds = datamodel();
+ data_store_t *ds = data_store();
ds->selected_card = m->payload[0];
return true;
@@ -152,7 +152,7 @@ uint8_t* server_parse_selected_stack(const msg_t *m)
void server_prep_start_game(msg_t *m)
{
uint16_t pos = 0;
- data_store *ds = datamodel();
+ data_store_t *ds = data_store();
player_list_t *player_list = &ds->player_list;
m->hdr.type = msg_type_start_game;
@@ -174,7 +174,7 @@ void server_prep_start_game(msg_t *m)
void server_prep_selected_stack(msg_t *m)
{
- data_store* ds = datamodel();
+ data_store_t *ds = data_store();
m->hdr.type = msg_type_selected_stack_s;
m->payload[0] = ds->stack_index;
@@ -196,7 +196,7 @@ void server_prep_deal_hand(msg_t *m, const hand_t *h)
void server_prep_initial_stacks(msg_t *m)
{
- data_store* ds = datamodel();
+ data_store_t *ds = data_store();
m->hdr.type = msg_type_initial_stacks;
@@ -209,7 +209,7 @@ void server_prep_initial_stacks(msg_t *m)
void server_prep_selected_card_all(msg_t *m)
{
uint8_t pos = 0;
- data_store* ds = datamodel();
+ data_store_t *ds = data_store();
m->hdr.type = msg_type_selected_card_all;
@@ -224,4 +224,3 @@ void server_prep_selected_card_all(msg_t *m)
m->hdr.payload_length = pos;
}
-
diff --git a/src/server_game_states.c b/src/server_game_states.c
index 1a86814..746b4be 100644
--- a/src/server_game_states.c
+++ b/src/server_game_states.c
@@ -1,11 +1,11 @@
#include "game_states.h"
#include <stdlib.h>
#include <string.h>
-#include "global.h"
+#include "data_store.h"
game_state_t state_server_deal_hand_cards(const socket_list_t *client_socks, const uint8_t round, main_stack_t *m)
{
- data_store *d = datamodel();
+ data_store_t *d = data_store();
if(round == 1)
{
@@ -44,7 +44,7 @@ game_state_t state_server_deal_hand_cards(const socket_list_t *client_socks, con
game_state_t state_server_wait_for_open_cards(const socket_list_t *client_socks)
{
- data_store *d = datamodel();
+ data_store_t *d = data_store();
// Receive open cards from clients
for(int i = 0; i < d->player_list.count; i++)
@@ -65,7 +65,7 @@ game_state_t state_server_wait_for_open_cards(const socket_list_t *client_socks)
game_state_t state_server_play_cards(const socket_list_t *client_socks, const uint8_t round)
{
#if 0
- data_store *d = datamodel();
+ data_store_t *d = data_store();
foreach(open_card)
{