Skip to content

Commit

Permalink
Merged with axblk/race, porting to 0.7.2. Closes #36
Browse files Browse the repository at this point in the history
  • Loading branch information
Dune-jr committed Dec 31, 2018
2 parents a0c1048 + 7c6b876 commit 37da4de
Show file tree
Hide file tree
Showing 60 changed files with 892 additions and 572 deletions.
7 changes: 7 additions & 0 deletions datasrc/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ def FileList(format, num):
set_tee_hands = SpriteSet("tee_hands", image_null, 2, 1)
set_tee_feet = SpriteSet("tee_feet", image_null, 2, 1)
set_tee_eyes = SpriteSet("tee_eyes", image_null, 2, 4)
set_tee_hats = SpriteSet("tee_hats", image_null, 1, 4)
set_browseicons = SpriteSet("browseicons", image_browseicons, 4, 2)
set_emoticons = SpriteSet("emoticons", image_emoticons, 4, 4)
set_demobuttons = SpriteSet("demobuttons", image_demobuttons, 5, 1)
Expand All @@ -310,6 +311,7 @@ def FileList(format, num):
container.spritesets.Add(set_tee_hands)
container.spritesets.Add(set_tee_feet)
container.spritesets.Add(set_tee_eyes)
container.spritesets.Add(set_tee_hats)
container.spritesets.Add(set_browseicons)
container.spritesets.Add(set_emoticons)
container.spritesets.Add(set_demobuttons)
Expand Down Expand Up @@ -430,6 +432,11 @@ def FileList(format, num):
container.sprites.Add(Sprite("tee_eyes_happy", set_tee_eyes, 1,1,1,1))
container.sprites.Add(Sprite("tee_eyes_surprise", set_tee_eyes, 0,2,1,1))

container.sprites.Add(Sprite("tee_hats_top1", set_tee_hats, 0,0,1,1))
container.sprites.Add(Sprite("tee_hats_top2", set_tee_hats, 0,1,1,1))
container.sprites.Add(Sprite("tee_hats_side1", set_tee_hats, 0,2,1,1))
container.sprites.Add(Sprite("tee_hats_side2", set_tee_hats, 0,3,1,1))

container.sprites.Add(Sprite("oop", set_emoticons, 0, 0, 1, 1))
container.sprites.Add(Sprite("exclamation", set_emoticons, 1, 0, 1, 1))
container.sprites.Add(Sprite("hearts", set_emoticons, 2, 0, 1, 1))
Expand Down
2 changes: 1 addition & 1 deletion datasrc/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Pickups = Enum("PICKUP", ["HEALTH", "ARMOR", "GRENADE", "SHOTGUN", "LASER", "NINJA"])
Emotes = Enum("EMOTE", ["NORMAL", "PAIN", "HAPPY", "SURPRISE", "ANGRY", "BLINK"])
Emoticons = Enum("EMOTICON", ["OOP", "EXCLAMATION", "HEARTS", "DROP", "DOTDOT", "MUSIC", "SORRY", "GHOST", "SUSHI", "SPLATTEE", "DEVILTEE", "ZOMG", "ZZZ", "WTF", "EYES", "QUESTION"])
Votes = Enum("VOTE", ["UNKNOWN", "START_OP", "START_KICK", "START_SPEC", "END_ABORT", "END_PASS", "END_FAIL"])
Votes = Enum("VOTE", ["UNKNOWN", "START_OP", "START_KICK", "START_SPEC", "END_ABORT", "END_PASS", "END_FAIL"]) # todo: add RUN_OP, RUN_KICK, RUN_SPEC; rem UNKNOWN
ChatModes = Enum("CHAT", ["NONE", "ALL", "TEAM", "WHISPER"])

PlayerFlags = Flags("PLAYERFLAG", ["ADMIN", "CHATTING", "SCOREBOARD", "READY", "DEAD", "WATCHING", "BOT"])
Expand Down
Binary file added datasrc/skins/xmas_hat.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 40 additions & 10 deletions scripts/tw_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def get_server_info(address):

# Get info request
sock.sendto(header_connless(token_srv, token_cl) + PACKET_GETINFO + b'\x00', address)
data, addr = sock.recvfrom(1024)
data, addr = sock.recvfrom(4096)
head = header_connless(token_cl, token_srv) + PACKET_INFO + b'\x00'
assert data[:len(head)] == head, "Server %s info header mismatch: %r != %r (expected)" % (address, data[:len(head)], head)
sock.close()
Expand All @@ -131,15 +131,22 @@ def get_server_info(address):
slots = data.split(b"\x00", maxsplit=5)

server_info = {}
server_info["address"] = address
server_info["version"] = slots[0].decode()
server_info["name"] = slots[1].decode()
server_info["hostname"] = slots[2].decode()
server_info["map"] = slots[3].decode()
server_info["gametype"] = slots[4].decode()
data = slots[5]

# these integers should fit in one byte each
server_info["flags"], server_info["skill"], server_info["num_players"], server_info["max_players"], server_info["num_clients"], server_info["max_clients"] = tuple(data[:6])
data = data[6:]
server_info["flags"], server_info["skill"] = tuple(data[:2])
data = data[2:]

server_info["num_players"], data = unpack_int(data)
server_info["max_players"], data = unpack_int(data)
server_info["num_clients"], data = unpack_int(data)
server_info["max_clients"], data = unpack_int(data)
server_info["players"] = []

for i in range(server_info["num_clients"]):
Expand All @@ -159,6 +166,7 @@ def get_server_info(address):
except OSError as e: # Timeout
print('> Server %s did not answer' % (address,))
except:
# print('> Server %s did something wrong here' % (address,))
# import traceback
# traceback.print_exc()
pass
Expand Down Expand Up @@ -260,19 +268,41 @@ def get_list(address):

num_players = 0
num_clients = 0
num_bots = 0
num_botplayers = 0
num_botspectators = 0

while len(servers_info) != 0:
if servers_info[0].finished == True:
if servers_info[0].info:
num_players += servers_info[0].info["num_players"]
num_clients += servers_info[0].info["num_clients"]
for p in servers_info[0].info["players"]:
if p["player"] == 2:
num_bots += 1
server_info = servers_info[0].info
# check num/max validity
if server_info["num_players"] > server_info["max_players"] \
or server_info["num_clients"] > server_info["max_clients"] \
or server_info["max_players"] > server_info["max_clients"] \
or server_info["num_players"] < 0 \
or server_info["num_clients"] < 0 \
or server_info["max_clients"] < 0 \
or server_info["max_players"] < 0 \
or server_info["max_clients"] > 64:
server_info["bad"] = 'invalid num/max'
print('> Server %s has %s' % (server_info["address"], server_info["bad"]))
# check actual purity
elif server_info["gametype"] in ('DM', 'TDM', 'CTF', 'LMS', 'LTS') \
and server_info["max_players"] > 16:
server_info["bad"] = 'too many players for vanilla'
print('> Server %s has %s' % (server_info["address"], server_info["bad"]))

else:
num_players += server_info["num_players"]
num_clients += server_info["num_clients"]
for p in servers_info[0].info["players"]:
if p["player"] == 2:
num_botplayers += 1
if p["player"] == 3:
num_botspectators += 1

del servers_info[0]

time.sleep(0.001) # be nice

print('%d players (%d bots) and %d spectators' % (num_players, num_bots, num_clients - num_players))
print('%d players (%d bots) and %d spectators (%d bots)' % (num_players, num_botplayers, num_clients - num_players, num_botspectators))
12 changes: 12 additions & 0 deletions src/base/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -1658,6 +1658,18 @@ int time_houroftheday()
return time_info->tm_hour;
}

int time_isxmasday()
{
time_t time_data;
struct tm *time_info;

time(&time_data);
time_info = localtime(&time_data);
if(time_info->tm_mon == 11 && time_info->tm_mday >= 24 && time_info->tm_mday <= 26)
return 1;
return 0;
}

void str_append(char *dst, const char *src, int dst_size)
{
int s = strlen(dst);
Expand Down
10 changes: 10 additions & 0 deletions src/base/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,16 @@ int time_timestamp();
*/
int time_houroftheday();

/*
Function: time_isxmasday
Checks if it's xmas
Returns:
1 - if it's a xmas day
0 - if not
*/
int time_isxmasday();

/* Group: Network General */
typedef struct
{
Expand Down
72 changes: 40 additions & 32 deletions src/engine/client/backend_sdl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ void CCommandProcessorFragment_OpenGL::SetState(const CCommandBuffer::SState &St
else if(State.m_Dimension == 3 && (m_aTextures[State.m_Texture].m_State&CTexture::STATE_TEX3D))
{
glEnable(GL_TEXTURE_3D);
glBindTexture(GL_TEXTURE_3D, m_aTextures[State.m_Texture].m_Tex3D);
glBindTexture(GL_TEXTURE_3D, m_aTextures[State.m_Texture].m_Tex3D[State.m_TextureArrayIndex]);
}
else
dbg_msg("render", "invalid texture %d %d %d\n", State.m_Texture, State.m_Dimension, m_aTextures[State.m_Texture].m_State);
Expand Down Expand Up @@ -249,6 +249,13 @@ void CCommandProcessorFragment_OpenGL::SetState(const CCommandBuffer::SState &St
void CCommandProcessorFragment_OpenGL::Cmd_Init(const SCommand_Init *pCommand)
{
m_pTextureMemoryUsage = pCommand->m_pTextureMemoryUsage;
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &m_MaxTexSize);
glGetIntegerv(GL_MAX_3D_TEXTURE_SIZE, &m_Max3DTexSize);
dbg_msg("render", "opengl max texture sizes: %d, %d(3D)", m_MaxTexSize, m_Max3DTexSize);
if(m_Max3DTexSize < IGraphics::NUMTILES_DIMENSION * IGraphics::NUMTILES_DIMENSION)
dbg_msg("render", "*** warning *** max 3D texture size is too low - using the fallback system");
m_TextureArraySize = IGraphics::NUMTILES_DIMENSION * IGraphics::NUMTILES_DIMENSION / min(m_Max3DTexSize, IGraphics::NUMTILES_DIMENSION * IGraphics::NUMTILES_DIMENSION);
*pCommand->m_pTextureArraySize = m_TextureArraySize;
}

void CCommandProcessorFragment_OpenGL::Cmd_Texture_Update(const CCommandBuffer::SCommand_Texture_Update *pCommand)
Expand All @@ -267,7 +274,7 @@ void CCommandProcessorFragment_OpenGL::Cmd_Texture_Destroy(const CCommandBuffer:
if(m_aTextures[pCommand->m_Slot].m_State&CTexture::STATE_TEX2D)
glDeleteTextures(1, &m_aTextures[pCommand->m_Slot].m_Tex2D);
if(m_aTextures[pCommand->m_Slot].m_State&CTexture::STATE_TEX3D)
glDeleteTextures(1, &m_aTextures[pCommand->m_Slot].m_Tex3D);
glDeleteTextures(m_TextureArraySize, m_aTextures[pCommand->m_Slot].m_Tex3D);
*m_pTextureMemoryUsage -= m_aTextures[pCommand->m_Slot].m_MemSize;
m_aTextures[pCommand->m_Slot].m_State = CTexture::STATE_EMPTY;
m_aTextures[pCommand->m_Slot].m_MemSize = 0;
Expand All @@ -283,16 +290,13 @@ void CCommandProcessorFragment_OpenGL::Cmd_Texture_Create(const CCommandBuffer::
// resample if needed
if(pCommand->m_Format == CCommandBuffer::TEXFORMAT_RGBA || pCommand->m_Format == CCommandBuffer::TEXFORMAT_RGB)
{
int MaxTexSize;
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &MaxTexSize);
if(pCommand->m_Flags&CCommandBuffer::TEXFLAG_TEXTURE3D)
int MaxTexSize = m_MaxTexSize;
if((pCommand->m_Flags&CCommandBuffer::TEXFLAG_TEXTURE3D) && m_Max3DTexSize >= CTexture::MIN_GL_MAX_3D_TEXTURE_SIZE)
{
int Max3DTexSize;
glGetIntegerv(GL_MAX_3D_TEXTURE_SIZE, &Max3DTexSize);
if(pCommand->m_Flags&CCommandBuffer::TEXFLAG_TEXTURE2D)
MaxTexSize = min(MaxTexSize, Max3DTexSize*16);
MaxTexSize = min(MaxTexSize, m_Max3DTexSize * IGraphics::NUMTILES_DIMENSION);
else
MaxTexSize = Max3DTexSize*16;
MaxTexSize = m_Max3DTexSize * IGraphics::NUMTILES_DIMENSION;
}
if(Width > MaxTexSize || Height > MaxTexSize)
{
Expand All @@ -307,7 +311,7 @@ void CCommandProcessorFragment_OpenGL::Cmd_Texture_Create(const CCommandBuffer::
mem_free(pTexData);
pTexData = pTmpData;
}
else if(Width > 16 && Height > 16 && (pCommand->m_Flags&CCommandBuffer::TEXFLAG_QUALITY) == 0)
else if(Width > IGraphics::NUMTILES_DIMENSION && Height > IGraphics::NUMTILES_DIMENSION && (pCommand->m_Flags&CCommandBuffer::TEXFLAG_QUALITY) == 0)
{
Width>>=1;
Height>>=1;
Expand Down Expand Up @@ -382,42 +386,45 @@ void CCommandProcessorFragment_OpenGL::Cmd_Texture_Create(const CCommandBuffer::
}

// 3D texture
if(pCommand->m_Flags&CCommandBuffer::TEXFLAG_TEXTURE3D)
if((pCommand->m_Flags&CCommandBuffer::TEXFLAG_TEXTURE3D) && m_Max3DTexSize >= CTexture::MIN_GL_MAX_3D_TEXTURE_SIZE)
{
Width /= 16;
Height /= 16;
Depth = 256;
Width /= IGraphics::NUMTILES_DIMENSION;
Height /= IGraphics::NUMTILES_DIMENSION;
Depth = min(m_Max3DTexSize, IGraphics::NUMTILES_DIMENSION * IGraphics::NUMTILES_DIMENSION);

// copy and reorder texture data
int MemSize = Width*Height*Depth*pCommand->m_PixelSize;
int MemSize = Width*Height*IGraphics::NUMTILES_DIMENSION*IGraphics::NUMTILES_DIMENSION*pCommand->m_PixelSize;
char *pTmpData = (char *)mem_alloc(MemSize, sizeof(void*));

const int TileSize = (Height * Width) * pCommand->m_PixelSize;
const int TileRowSize = Width * pCommand->m_PixelSize;
const int ImagePitch = Width*16 * pCommand->m_PixelSize;
const int ImagePitch = Width * IGraphics::NUMTILES_DIMENSION * pCommand->m_PixelSize;
mem_zero(pTmpData, MemSize);
for(int i = 0; i < 256; i++)
for(int i = 0; i < IGraphics::NUMTILES_DIMENSION * IGraphics::NUMTILES_DIMENSION; i++)
{
const int px = (i%16) * Width;
const int py = (i/16) * Height;
const char *pTileData = (const char *)pTexData + (py * Width*16 + px) * pCommand->m_PixelSize;
const int px = (i%IGraphics::NUMTILES_DIMENSION) * Width;
const int py = (i/IGraphics::NUMTILES_DIMENSION) * Height;
const char *pTileData = (const char *)pTexData + (py * Width * IGraphics::NUMTILES_DIMENSION + px) * pCommand->m_PixelSize;
for(int y = 0; y < Height; y++)
mem_copy(pTmpData + i*TileSize + y*TileRowSize, pTileData + y * ImagePitch, TileRowSize);
}

mem_free(pTexData);
pTexData = pTmpData;

//
glGenTextures(1, &m_aTextures[pCommand->m_Slot].m_Tex3D);
glGenTextures(m_TextureArraySize, m_aTextures[pCommand->m_Slot].m_Tex3D);
m_aTextures[pCommand->m_Slot].m_State |= CTexture::STATE_TEX3D;
glBindTexture(GL_TEXTURE_3D, m_aTextures[pCommand->m_Slot].m_Tex3D);

glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage3D(GL_TEXTURE_3D, 0, StoreOglformat, Width, Height, Depth, 0, Oglformat, GL_UNSIGNED_BYTE, pTexData);

m_aTextures[pCommand->m_Slot].m_MemSize += Width*Height*pCommand->m_PixelSize;
for(int i = 0; i < m_TextureArraySize; ++i)
{
glBindTexture(GL_TEXTURE_3D, m_aTextures[pCommand->m_Slot].m_Tex3D[i]);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
pTexData = pTmpData+i*(Width*Height*Depth*pCommand->m_PixelSize);
glTexImage3D(GL_TEXTURE_3D, 0, StoreOglformat, Width, Height, Depth, 0, Oglformat, GL_UNSIGNED_BYTE, pTexData);

m_aTextures[pCommand->m_Slot].m_MemSize += Width*Height*pCommand->m_PixelSize;
}
pTexData = pTmpData;
}

*m_pTextureMemoryUsage += m_aTextures[pCommand->m_Slot].m_MemSize;
Expand Down Expand Up @@ -756,13 +763,14 @@ int CGraphicsBackend_SDL_OpenGL::Init(const char *pName, int *Screen, int *pWidt

// issue init commands for OpenGL and SDL
CCommandBuffer CmdBuffer(1024, 512);
CCommandProcessorFragment_OpenGL::SCommand_Init CmdOpenGL;
CmdOpenGL.m_pTextureMemoryUsage = &m_TextureMemoryUsage;
CmdBuffer.AddCommand(CmdOpenGL);
CCommandProcessorFragment_SDL::SCommand_Init CmdSDL;
CmdSDL.m_pWindow = m_pWindow;
CmdSDL.m_GLContext = m_GLContext;
CmdBuffer.AddCommand(CmdSDL);
CCommandProcessorFragment_OpenGL::SCommand_Init CmdOpenGL;
CmdOpenGL.m_pTextureMemoryUsage = &m_TextureMemoryUsage;
CmdOpenGL.m_pTextureArraySize = &m_TextureArraySize;
CmdBuffer.AddCommand(CmdOpenGL);
RunBuffer(&CmdBuffer);
WaitForIdle();

Expand Down
11 changes: 10 additions & 1 deletion src/engine/client/backend_sdl.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,21 @@ class CCommandProcessorFragment_OpenGL
STATE_EMPTY = 0,
STATE_TEX2D = 1,
STATE_TEX3D = 2,

MIN_GL_MAX_3D_TEXTURE_SIZE = 64, // GL_MAX_3D_TEXTURE_SIZE must be at least 64 according to the standard
MAX_ARRAYSIZE_TEX3D = IGraphics::NUMTILES_DIMENSION * IGraphics::NUMTILES_DIMENSION / MIN_GL_MAX_3D_TEXTURE_SIZE, // = 4
};
GLuint m_Tex2D;
GLuint m_Tex3D;
GLuint m_Tex3D[MAX_ARRAYSIZE_TEX3D];
int m_State;
int m_Format;
int m_MemSize;
};
CTexture m_aTextures[CCommandBuffer::MAX_TEXTURES];
volatile int *m_pTextureMemoryUsage;
int m_MaxTexSize;
int m_Max3DTexSize;
int m_TextureArraySize;

public:
enum
Expand All @@ -111,6 +117,7 @@ class CCommandProcessorFragment_OpenGL
{
SCommand_Init() : SCommand(CMD_INIT) {}
volatile int *m_pTextureMemoryUsage;
int *m_pTextureArraySize;
};

private:
Expand Down Expand Up @@ -189,11 +196,13 @@ class CGraphicsBackend_SDL_OpenGL : public CGraphicsBackend_Threaded
ICommandProcessor *m_pProcessor;
volatile int m_TextureMemoryUsage;
int m_NumScreens;
int m_TextureArraySize;
public:
virtual int Init(const char *pName, int *Screen, int *Width, int *Height, int FsaaSamples, int Flags, int *pDesktopWidth, int *pDesktopHeight);
virtual int Shutdown();

virtual int MemoryUsage() const;
virtual int GetTextureArraySize() const { return m_TextureArraySize; }

virtual int GetNumScreens() const { return m_NumScreens; }

Expand Down
2 changes: 1 addition & 1 deletion src/engine/client/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ int CClient::UnpackServerInfo(CUnpacker *pUnpacker, CServerInfo *pInfo, int *pTo
pInfo->m_NumBotSpectators = 0;

// don't add invalid info to the server browser list
if(pInfo->m_NumClients < 0 || pInfo->m_NumClients > MAX_CLIENTS || pInfo->m_MaxClients < 0 || pInfo->m_MaxClients > MAX_CLIENTS ||
if(pInfo->m_NumClients < 0 || pInfo->m_NumClients > pInfo->m_MaxClients || pInfo->m_MaxClients < 0 || pInfo->m_MaxClients > MAX_CLIENTS ||
pInfo->m_NumPlayers < 0 || pInfo->m_NumPlayers > pInfo->m_NumClients || pInfo->m_MaxPlayers < 0 || pInfo->m_MaxPlayers > pInfo->m_MaxClients)
return -1;
// drop standard gametype with more than MAX_PLAYERS
Expand Down
Loading

0 comments on commit 37da4de

Please sign in to comment.