Commit 080d7781 authored by Chen Bill's avatar Chen Bill Committed by GitHub

clean config.h (#2568)

* move header files to game.h

* include mutex when necessary

* include myfilesystem.h when necessary

* include thread when necessary

* include string

* include GL when necessary

* remove #pragma once

* rename guard macro to YGOPRO_CONFIG_H

* fix warning C4456, C4458

* move GL to game.h

* use <cstring> functions

* include <wchar.h>
parent 08a8cda7
......@@ -32,12 +32,12 @@ ClientCard::~ClientCard() {
}
overlayed.clear();
}
void ClientCard::SetCode(int code) {
if((location == LOCATION_HAND) && (this->code != (unsigned int)code)) {
this->code = code;
void ClientCard::SetCode(int x) {
if((location == LOCATION_HAND) && (code != (unsigned int)x)) {
code = x;
mainGame->dField.MoveCard(this, 5);
} else
this->code = code;
code = x;
}
void ClientCard::UpdateInfo(unsigned char* buf) {
int flag = BufferIO::ReadInt32(buf);
......
......@@ -98,7 +98,7 @@ public:
ClientCard() = default;
~ClientCard();
void SetCode(int code);
void SetCode(int x);
void UpdateInfo(unsigned char* buf);
void ClearTarget();
void ClearData();
......
#ifndef __CONFIG_H
#define __CONFIG_H
#pragma once
#ifndef YGOPRO_CONFIG_H
#define YGOPRO_CONFIG_H
#define _IRR_STATIC_LIB_
#define IRR_COMPILE_WITH_DX9_DEV_PACK
......@@ -41,13 +39,8 @@
#define SOCKADDR sockaddr
#define SOCKET_ERRNO() (errno)
#include <wchar.h>
#define mywcsncasecmp wcsncasecmp
#define mystrncasecmp strncasecmp
inline int _wtoi(const wchar_t * s) {
wchar_t * endptr;
return (int)wcstol(s, &endptr, 10);
}
#endif
template<size_t N, typename... TR>
......@@ -56,25 +49,13 @@ inline int myswprintf(wchar_t(&buf)[N], const wchar_t* fmt, TR... args) {
}
#include <irrlicht.h>
#ifdef __APPLE__
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#else //__APPLE__
#include <GL/gl.h>
#include <GL/glu.h>
#endif //__APPLE__
#include "CGUITTFont.h"
#include "CGUIImageButton.h"
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <thread>
#include <mutex>
#include <wchar.h>
#include <iostream>
#include <algorithm>
#include <string>
#include "bufferio.h"
#include "myfilesystem.h"
#include "mysignal.h"
#include "../ocgcore/ocgapi.h"
#include "../ocgcore/common.h"
......
......@@ -127,7 +127,7 @@ bool DataManager::LoadStrings(IReadFile* reader) {
while(reader->read(&ch[0], 1)) {
if(ch[0] == '\0')
break;
strcat(linebuf, ch);
std::strcat(linebuf, ch);
if(ch[0] == '\n') {
ReadStringConfLine(linebuf);
linebuf[0] = '\0';
......@@ -144,22 +144,22 @@ void DataManager::ReadStringConfLine(const char* linebuf) {
wchar_t strBuffer[4096]{};
if (sscanf(linebuf, "!%63s", strbuf) != 1)
return;
if(!strcmp(strbuf, "system")) {
if(!std::strcmp(strbuf, "system")) {
if (sscanf(&linebuf[7], "%d %240[^\n]", &value, strbuf) != 2)
return;
BufferIO::DecodeUTF8(strbuf, strBuffer);
_sysStrings[value] = strBuffer;
} else if(!strcmp(strbuf, "victory")) {
} else if(!std::strcmp(strbuf, "victory")) {
if (sscanf(&linebuf[8], "%x %240[^\n]", &value, strbuf) != 2)
return;
BufferIO::DecodeUTF8(strbuf, strBuffer);
_victoryStrings[value] = strBuffer;
} else if(!strcmp(strbuf, "counter")) {
} else if(!std::strcmp(strbuf, "counter")) {
if (sscanf(&linebuf[8], "%x %240[^\n]", &value, strbuf) != 2)
return;
BufferIO::DecodeUTF8(strbuf, strBuffer);
_counterStrings[value] = strBuffer;
} else if(!strcmp(strbuf, "setname")) {
} else if(!std::strcmp(strbuf, "setname")) {
//using tab for comment
if (sscanf(&linebuf[8], "%x %240[^\t\n]", &value, strbuf) != 2)
return;
......
#include "config.h"
#include "deck_con.h"
#include "myfilesystem.h"
#include "data_manager.h"
#include "deck_manager.h"
#include "image_manager.h"
......@@ -1300,12 +1301,12 @@ void DeckBuilder::GetHoveredCard() {
} else if(x >= 810 && x <= 995 && y >= 165 && y <= 626) {
hovered_pos = 4;
hovered_seq = (y - 165) / 66;
int pos = mainGame->scrFilter->getPos() + hovered_seq;
if(pos >= (int)results.size()) {
int current_pos = mainGame->scrFilter->getPos() + hovered_seq;
if(current_pos >= (int)results.size()) {
hovered_seq = -1;
hovered_code = 0;
} else {
hovered_code = results[pos]->first;
hovered_code = results[current_pos]->first;
}
}
if(is_draging) {
......
#include "deck_manager.h"
#include "myfilesystem.h"
#include "data_manager.h"
#include "network.h"
#include "game.h"
......
......@@ -218,7 +218,7 @@ void Game::DrawBackGround() {
}
}
void Game::DrawLinkedZones(ClientCard* pcard) {
int mark = pcard->link_marker;
auto mark = pcard->link_marker;
ClientCard* pcard2;
if (dField.hovered_sequence < 5) {
if (mark & LINK_MARKER_LEFT && dField.hovered_sequence > 0) {
......@@ -235,25 +235,25 @@ void Game::DrawLinkedZones(ClientCard* pcard) {
if ((mark & LINK_MARKER_TOP_LEFT && dField.hovered_sequence == 2)
|| (mark & LINK_MARKER_TOP && dField.hovered_sequence == 1)
|| (mark & LINK_MARKER_TOP_RIGHT && dField.hovered_sequence == 0)) {
int mark = (dField.hovered_sequence == 2) ? LINK_MARKER_BOTTOM_RIGHT : (dField.hovered_sequence == 1) ? LINK_MARKER_BOTTOM : LINK_MARKER_BOTTOM_LEFT;
int arrow = (dField.hovered_sequence == 2) ? LINK_MARKER_BOTTOM_RIGHT : (dField.hovered_sequence == 1) ? LINK_MARKER_BOTTOM : LINK_MARKER_BOTTOM_LEFT;
pcard2 = dField.mzone[dField.hovered_controler][5];
if (!pcard2) {
pcard2 = dField.mzone[1 - dField.hovered_controler][6];
mark = (dField.hovered_sequence == 2) ? LINK_MARKER_TOP_LEFT : (dField.hovered_sequence == 1) ? LINK_MARKER_TOP : LINK_MARKER_TOP_RIGHT;
arrow = (dField.hovered_sequence == 2) ? LINK_MARKER_TOP_LEFT : (dField.hovered_sequence == 1) ? LINK_MARKER_TOP : LINK_MARKER_TOP_RIGHT;
}
CheckMutual(pcard2, mark);
CheckMutual(pcard2, arrow);
driver->drawVertexPrimitiveList(&matManager.vFieldMzone[dField.hovered_controler][5], 4, matManager.iRectangle, 2);
}
if ((mark & LINK_MARKER_TOP_LEFT && dField.hovered_sequence == 4)
|| (mark & LINK_MARKER_TOP && dField.hovered_sequence == 3)
|| (mark & LINK_MARKER_TOP_RIGHT && dField.hovered_sequence == 2)) {
int mark = (dField.hovered_sequence == 4) ? LINK_MARKER_BOTTOM_RIGHT : (dField.hovered_sequence == 3) ? LINK_MARKER_BOTTOM : LINK_MARKER_BOTTOM_LEFT;
int arrow = (dField.hovered_sequence == 4) ? LINK_MARKER_BOTTOM_RIGHT : (dField.hovered_sequence == 3) ? LINK_MARKER_BOTTOM : LINK_MARKER_BOTTOM_LEFT;
pcard2 = dField.mzone[dField.hovered_controler][6];
if (!pcard2) {
pcard2 = dField.mzone[1 - dField.hovered_controler][5];
mark = (dField.hovered_sequence == 4) ? LINK_MARKER_TOP_LEFT : (dField.hovered_sequence == 3) ? LINK_MARKER_TOP : LINK_MARKER_TOP_RIGHT;
arrow = (dField.hovered_sequence == 4) ? LINK_MARKER_TOP_LEFT : (dField.hovered_sequence == 3) ? LINK_MARKER_TOP : LINK_MARKER_TOP_RIGHT;
}
CheckMutual(pcard2, mark);
CheckMutual(pcard2, arrow);
driver->drawVertexPrimitiveList(&matManager.vFieldMzone[dField.hovered_controler][6], 4, matManager.iRectangle, 2);
}
}
......
......@@ -8,6 +8,7 @@
#include "game.h"
#include "replay.h"
#include "replay_mode.h"
#include <thread>
namespace ygo {
......@@ -61,8 +62,8 @@ bool DuelClient::StartClient(unsigned int ip, unsigned short port, bool create_g
rnd.reset((uint_fast32_t)std::random_device()());
if(!create_game) {
timeval timeout = {5, 0};
event* resp_event = event_new(client_base, 0, EV_TIMEOUT, ConnectTimeout, 0);
event_add(resp_event, &timeout);
event* timeout_event = event_new(client_base, 0, EV_TIMEOUT, ConnectTimeout, 0);
event_add(timeout_event, &timeout);
}
std::thread(ClientThread).detach();
return true;
......@@ -144,10 +145,10 @@ void DuelClient::ClientEvent(bufferevent *bev, short events, void *ctx) {
BufferIO::CopyWStr(mainGame->ebServerPass->getText(), cscg.pass, 20);
cscg.info.rule = mainGame->cbRule->getSelected();
cscg.info.mode = mainGame->cbMatchMode->getSelected();
cscg.info.start_hand = _wtoi(mainGame->ebStartHand->getText());
cscg.info.start_lp = _wtoi(mainGame->ebStartLP->getText());
cscg.info.draw_count = _wtoi(mainGame->ebDrawCount->getText());
cscg.info.time_limit = _wtoi(mainGame->ebTimeLimit->getText());
cscg.info.start_hand = wcstol(mainGame->ebStartHand->getText(),nullptr,10);
cscg.info.start_lp = wcstol(mainGame->ebStartLP->getText(),nullptr,10);
cscg.info.draw_count = wcstol(mainGame->ebDrawCount->getText(),nullptr,10);
cscg.info.time_limit = wcstol(mainGame->ebTimeLimit->getText(),nullptr,10);
cscg.info.lflist = mainGame->cbHostLFlist->getItemData(mainGame->cbHostLFlist->getSelected());
cscg.info.duel_rule = mainGame->cbDuelRule->getSelected() + 1;
cscg.info.no_check_deck = mainGame->chkNoCheckDeck->isChecked();
......@@ -1402,8 +1403,8 @@ int DuelClient::ClientAnalyze(unsigned char* msg, unsigned int len) {
else if (pcard->location == LOCATION_EXTRA)
mainGame->dField.extra_act = true;
else {
int seq = mainGame->dInfo.duel_rule >= 4 ? 0 : 6;
if (pcard->location == LOCATION_SZONE && pcard->sequence == seq && (pcard->type & TYPE_PENDULUM) && !pcard->equipTarget)
int left_seq = mainGame->dInfo.duel_rule >= 4 ? 0 : 6;
if (pcard->location == LOCATION_SZONE && pcard->sequence == left_seq && (pcard->type & TYPE_PENDULUM) && !pcard->equipTarget)
mainGame->dField.pzone_act[pcard->controler] = true;
}
}
......@@ -3148,8 +3149,8 @@ int DuelClient::ClientAnalyze(unsigned char* msg, unsigned int len) {
pcard = mainGame->dField.GetCard(player, LOCATION_DECK, mainGame->dField.deck[player].size() - 1);
mainGame->dField.deck[player].erase(mainGame->dField.deck[player].end() - 1);
mainGame->dField.AddCard(pcard, player, LOCATION_HAND, 0);
for(size_t i = 0; i < mainGame->dField.hand[player].size(); ++i)
mainGame->dField.MoveCard(mainGame->dField.hand[player][i], 10);
for(int j = 0; j < (int)mainGame->dField.hand[player].size(); ++j)
mainGame->dField.MoveCard(mainGame->dField.hand[player][j], 10);
mainGame->gMutex.unlock();
mainGame->WaitFrameSignal(5);
}
......
......@@ -1456,7 +1456,6 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
DuelClient::SetResponseB(respbuf, selectable_cards.size() * 2);
DuelClient::SendResponse();
} else {
wchar_t formatBuffer[2048];
myswprintf(formatBuffer, dataManager.GetSysString(204), select_counter_count, dataManager.GetCounterName(select_counter_type));
mainGame->stHintMsg->setText(formatBuffer);
}
......@@ -1665,8 +1664,8 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
player_name = mainGame->dInfo.clientname_tag;
}
std::wstring str(player_name);
const auto& player_desc_hints = mainGame->dField.player_desc_hints[mplayer];
for(auto iter = player_desc_hints.begin(); iter != player_desc_hints.end(); ++iter) {
const auto& mplayer_hints = mainGame->dField.player_desc_hints[mplayer];
for(auto iter = mplayer_hints.begin(); iter != mplayer_hints.end(); ++iter) {
myswprintf(formatBuffer, L"\n*%ls", dataManager.GetDesc(iter->first));
str.append(formatBuffer);
}
......
This diff is collapsed.
......@@ -2,12 +2,25 @@
#define GAME_H
#include "config.h"
#ifdef __APPLE__
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#else //__APPLE__
#include <GL/gl.h>
#include <GL/glu.h>
#endif //__APPLE__
#include "CGUIImageButton.h"
#include "CGUITTFont.h"
#include "mysignal.h"
#include "client_field.h"
#include "deck_con.h"
#include "menu_handler.h"
#include <time.h>
#include <unordered_map>
#include <vector>
#include <list>
#include <mutex>
#include <functional>
#define DEFAULT_DUEL_RULE 5
......
......@@ -38,7 +38,7 @@ int main(int argc, char* argv[]) {
#ifdef _WIN32
#ifndef _DEBUG
char* pstrext;
if(argc == 2 && (pstrext = strrchr(argv[1], '.'))
if(argc == 2 && (pstrext = std::strrchr(argv[1], '.'))
&& (!mystrncasecmp(pstrext, ".ydk", 4) || !mystrncasecmp(pstrext, ".yrp", 4))) {
wchar_t exepath[MAX_PATH];
GetModuleFileNameW(NULL, exepath, MAX_PATH);
......
#include "image_manager.h"
#include "game.h"
#include <thread>
namespace ygo {
......
......@@ -5,6 +5,7 @@
#include "data_manager.h"
#include <unordered_map>
#include <queue>
#include <mutex>
namespace ygo {
......
#include "config.h"
#include "menu_handler.h"
#include "myfilesystem.h"
#include "netserver.h"
#include "duelclient.h"
#include "deck_manager.h"
......@@ -96,7 +97,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
evutil_freeaddrinfo(answer);
}
}
unsigned int remote_port = _wtoi(mainGame->ebJoinPort->getText());
unsigned int remote_port = wcstol(mainGame->ebJoinPort->getText(), nullptr, 10);
BufferIO::CopyWStr(pstr, mainGame->gameConf.lasthost, 100);
BufferIO::CopyWStr(mainGame->ebJoinPort->getText(), mainGame->gameConf.lastport, 20);
if(DuelClient::StartClient(remote_addr, remote_port, false)) {
......@@ -161,14 +162,14 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
break;
}
case BUTTON_HP_KICK: {
int id = 0;
while(id < 4) {
if(mainGame->btnHostPrepKick[id] == caller)
int index = 0;
while(index < 4) {
if(mainGame->btnHostPrepKick[index] == caller)
break;
id++;
++index;
}
CTOS_Kick csk;
csk.pos = id;
csk.pos = index;
DuelClient::SendPacketToServer(CTOS_HS_KICK, csk);
break;
}
......@@ -252,7 +253,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
mainGame->dField.Clear();
mainGame->HideElement(mainGame->wReplay);
mainGame->device->setEventReceiver(&mainGame->dField);
unsigned int start_turn = _wtoi(mainGame->ebRepStartTurn->getText());
unsigned int start_turn = wcstol(mainGame->ebRepStartTurn->getText(), nullptr, 10);
if(start_turn == 1)
start_turn = 0;
ReplayMode::StartReplay(start_turn);
......@@ -586,9 +587,9 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
std::wstring message = L"";
bool in_message = false;
while(fgets(linebuf, 1024, fp)) {
if(!strncmp(linebuf, "--[[message", 11)) {
size_t len = strlen(linebuf);
char* msgend = strrchr(linebuf, ']');
if(!std::strncmp(linebuf, "--[[message", 11)) {
size_t len = std::strlen(linebuf);
char* msgend = std::strrchr(linebuf, ']');
if(len <= 13) {
in_message = true;
continue;
......@@ -599,7 +600,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
break;
}
}
if(!strncmp(linebuf, "]]", 2)) {
if(!std::strncmp(linebuf, "]]", 2)) {
in_message = false;
break;
}
......
#include "netserver.h"
#include "single_duel.h"
#include "tag_duel.h"
#include <thread>
namespace ygo {
std::unordered_map<bufferevent*, DuelPlayer> NetServer::users;
......
#include "replay.h"
#include "myfilesystem.h"
#include "lzma/LzmaLib.h"
namespace ygo {
......
......@@ -3,6 +3,7 @@
#include "game.h"
#include "../ocgcore/common.h"
#include "../ocgcore/mtrandom.h"
#include <thread>
namespace ygo {
......
......@@ -3,6 +3,7 @@
#include "game.h"
#include "../ocgcore/common.h"
#include "../ocgcore/mtrandom.h"
#include <thread>
namespace ygo {
......
#include "sound_manager.h"
#include "myfilesystem.h"
#ifdef IRRKLANG_STATIC
#include "../ikpmp3/ikpMP3.h"
#endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment