File: util.h

package info (click to toggle)
burgerspace 1.9.2-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,524 kB
  • sloc: sh: 10,939; cpp: 5,791; makefile: 240
file content (122 lines) | stat: -rw-r--r-- 2,553 bytes parent folder | download | duplicates (4)
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
/*  $Id: util.h,v 1.3 2010/09/16 03:22:22 sarrazip Exp $
    util.h - Miscellaneous definitions.

    burgerspace - A hamburger-smashing video game.
    Copyright (C) 2008-2010 Pierre Sarrazin <http://sarrazip.com/>

    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
    as published by the Free Software Foundation; either version 2
    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.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
*/

#ifndef _H_util
#define _H_util

#include <string>
#include <stdlib.h>

#ifndef _MSC_VER
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <unistd.h>
#else
#include <WinSock2.h>
#include <ws2tcpip.h>
typedef signed long ssize_t;
#endif

/** Possible directions of movement, in trigonometric order.
    This enumeration is garanteed to start at zero.
    The order of the constants is guaranteed, so they are 0, 1, 2, 3.
*/
enum { RIGHT, UP, LEFT, DOWN };


// Graphical dimensions.
enum
{
    TILE_SIDE = 32,
    SCREEN_WIDTH_IN_PIXELS = 672,
    SCREEN_HEIGHT_IN_PIXELS = 520
};


// Network-related constants.
enum
{
    MAX_LEN_PACKET = 1024,
    UPDATE_SPRITE_PACKET_LEN = 12
};


enum ServerPacketType
{
    UPDATE_LEVEL_PACKET,
    UPDATE_SPRITE_PACKET,
    UPDATE_SCORE_PACKET,
    PLAY_SOUND_EFFECT_PACKET,
    ROLE_ASSIGNMENT_PACKET
};


enum ClientPacketType
{
    CLIENT_DESC_PACKET,
    START_NEW_GAME_PACKET,
    LEVEL_DESC_REQUEST_PACKET,
    PLAYER_COMMAND_PACKET,
    DISCONNECT_PACKET
};


enum Role
{
    ROLE_SPECTATOR,
    ROLE_CHEF,
    ROLE_ENEMY
};


enum EnemyType
{
    ENEMY_EGG,
    ENEMY_HOT_DOG,
    ENEMY_PICKLE
};


inline
std::string
getDir(const char *defaultValue, const char *envVarName)
/*
    Makes sure that the returned directory name ends with a slash.
*/
{
    std::string dir;
    const char *s = getenv(envVarName);
    if (s != NULL)
        dir = s;
    else
        dir = defaultValue;
    
    if (!dir.empty() && dir[dir.length() - 1] != '/')
        dir += '/';

    return dir;
}


#endif  /* _H_util */