Commit 6361c05b authored by 神楽坂玲奈's avatar 神楽坂玲奈

core by yuyu

parent 19b97989
......@@ -229,108 +229,7 @@ bool CGUIButton::OnEvent(const SEvent& event)
//! draws the element and its children
void CGUIButton::draw()
{
if (!IsVisible)
return;
IGUISkin* skin = Environment->getSkin();
video::IVideoDriver* driver = Environment->getVideoDriver();
// todo: move sprite up and text down if the pressed state has a sprite
const core::position2di spritePos = AbsoluteRect.getCenter();
if (!Pressed)
{
if (DrawBorder)
skin->draw3DButtonPaneStandard(this, AbsoluteRect, &AbsoluteClippingRect);
if (Image)
{
core::position2d<s32> pos = spritePos;
pos.X -= ImageRect.getWidth() / 2;
pos.Y -= ImageRect.getHeight() / 2;
driver->draw2DImage(Image,
ScaleImage? AbsoluteRect :
core::recti(pos, ImageRect.getSize()),
ImageRect, &AbsoluteClippingRect,
0, UseAlphaChannel);
}
}
else
{
if (DrawBorder)
skin->draw3DButtonPanePressed(this, AbsoluteRect, &AbsoluteClippingRect);
if (PressedImage)
{
core::position2d<s32> pos = spritePos;
pos.X -= PressedImageRect.getWidth() / 2;
pos.Y -= PressedImageRect.getHeight() / 2;
if (Image == PressedImage && PressedImageRect == ImageRect)
{
pos.X += skin->getSize(EGDS_BUTTON_PRESSED_IMAGE_OFFSET_X);
pos.Y += skin->getSize(EGDS_BUTTON_PRESSED_IMAGE_OFFSET_Y);
}
driver->draw2DImage(PressedImage,
ScaleImage? AbsoluteRect :
core::recti(pos, PressedImageRect.getSize()),
PressedImageRect, &AbsoluteClippingRect,
0, UseAlphaChannel);
}
}
if (SpriteBank)
{
// pressed / unpressed animation
u32 state = Pressed ? (u32)EGBS_BUTTON_DOWN : (u32)EGBS_BUTTON_UP;
if (ButtonSprites[state].Index != -1)
{
SpriteBank->draw2DSprite(ButtonSprites[state].Index, spritePos,
&AbsoluteClippingRect, ButtonSprites[state].Color, ClickTime, os::Timer::getTime(),
ButtonSprites[state].Loop, true);
}
// focused / unfocused animation
state = Environment->hasFocus(this) ? (u32)EGBS_BUTTON_FOCUSED : (u32)EGBS_BUTTON_NOT_FOCUSED;
if (ButtonSprites[state].Index != -1)
{
SpriteBank->draw2DSprite(ButtonSprites[state].Index, spritePos,
&AbsoluteClippingRect, ButtonSprites[state].Color, FocusTime, os::Timer::getTime(),
ButtonSprites[state].Loop, true);
}
// mouse over / off animation
if (isEnabled())
{
state = Environment->getHovered() == this ? (u32)EGBS_BUTTON_MOUSE_OVER : (u32)EGBS_BUTTON_MOUSE_OFF;
if (ButtonSprites[state].Index != -1)
{
SpriteBank->draw2DSprite(ButtonSprites[state].Index, spritePos,
&AbsoluteClippingRect, ButtonSprites[state].Color, HoverTime, os::Timer::getTime(),
ButtonSprites[state].Loop, true);
}
}
}
if (Text.size())
{
IGUIFont* font = getActiveFont();
core::rect<s32> rect = AbsoluteRect;
if (Pressed)
{
rect.UpperLeftCorner.X += skin->getSize(EGDS_BUTTON_PRESSED_TEXT_OFFSET_X);
rect.UpperLeftCorner.Y += skin->getSize(EGDS_BUTTON_PRESSED_TEXT_OFFSET_Y);
}
if (font)
font->draw(Text.c_str(), rect,
skin->getColor(isEnabled() ? EGDC_BUTTON_TEXT : EGDC_GRAY_TEXT),
true, true, &AbsoluteClippingRect);
}
IGUIElement::draw();
}
......
......@@ -812,29 +812,8 @@ void CGUITTFont::setInvisibleCharacters(const core::ustring& s) {
}
video::IImage* CGUITTFont::createTextureFromChar(const uchar32_t& ch) {
u32 n = getGlyphIndexByChar(ch);
const SGUITTGlyph& glyph = Glyphs[n - 1];
CGUITTGlyphPage* page = Glyph_Pages[glyph.glyph_page];
if (page->dirty)
page->updateTexture();
video::ITexture* tex = page->texture;
// Acquire a read-only lock of the corresponding page texture.
void* ptr = tex->lock(video::ETLM_READ_ONLY);
video::ECOLOR_FORMAT format = tex->getColorFormat();
core::dimension2du tex_size = tex->getOriginalSize();
video::IImage* pageholder = Driver->createImageFromData(format, tex_size, ptr, true, false);
// Copy the image data out of the page texture.
core::dimension2du glyph_size(glyph.source_rect.getSize());
video::IImage* image = Driver->createImage(format, glyph_size);
pageholder->copyTo(image, core::position2di(0, 0), glyph.source_rect);
tex->unlock();
return image;
return 0;
}
video::ITexture* CGUITTFont::getPageTextureByIndex(const u32& page_index) const {
......
......@@ -9,7 +9,6 @@
#include <WinSock2.h>
#include <windows.h>
#include <ws2tcpip.h>
#ifdef _MSC_VER
#define myswprintf _swprintf
......
......@@ -20,6 +20,27 @@ namespace ygo {
Game* mainGame;
unsigned short aServerPort;
unsigned int lflist;
unsigned char rule;
unsigned char mode;
bool enable_priority;
bool no_check_deck;
bool no_shuffle_deck;
unsigned int start_lp;
unsigned char start_hand;
unsigned char draw_count;
void Game::MainServerLoop(int bDuel_mode) {
deckManager.LoadLFList();
dataManager.LoadDB("cards.cdb");
NetServer::StartServer(aServerPort);
NetServer::Initduel(bDuel_mode);
while(NetServer::net_evbase) {
Sleep(200);
}
}
bool Game::Initialize() {
srand(time(0));
LoadConfig();
......
......@@ -68,6 +68,7 @@ class Game {
public:
bool Initialize();
void MainLoop();
void Game::MainServerLoop(int bDuel_mode);
void BuildProjectionMatrix(irr::core::matrix4& mProjection, f32 left, f32 right, f32 bottom, f32 top, f32 znear, f32 zfar);
void SetStaticText(irr::gui::IGUIStaticText* pControl, u32 cWidth, irr::gui::CGUITTFont* font, wchar_t* text);
void RefreshDeck(irr::gui::IGUIComboBox* cbDeck);
......@@ -356,6 +357,16 @@ public:
};
extern Game* mainGame;
extern unsigned short aServerPort;
extern unsigned int lflist;
extern unsigned char rule;
extern unsigned char mode;
extern bool enable_priority;
extern bool no_check_deck;
extern bool no_shuffle_deck;
extern unsigned int start_lp;
extern unsigned char start_hand;
extern unsigned char draw_count;
}
......
......@@ -5,6 +5,7 @@
int enable_log = 0;
bool exit_on_return = false;
bool runasserver = true;
int main(int argc, char* argv[]) {
#ifdef _WIN32
......@@ -17,6 +18,35 @@ int main(int argc, char* argv[]) {
evthread_use_pthreads();
#endif //_WIN32
ygo::Game _game;
if (runasserver){
ygo::aServerPort=7911;
ygo::aServerPort=atoi(argv[1]);
ygo::lflist=atoi(argv[2]);
ygo::start_hand=0;
if (argc>2) {
ygo::rule=atoi(argv[3]);
ygo::mode=atoi(argv[4]);
if (argv[5][0]=='T')
ygo::enable_priority=true;
else
ygo::enable_priority=false;
if (argv[6][0]=='T')
ygo::no_check_deck=true;
else
ygo::no_check_deck=false;
if (argv[7][0]=='T')
ygo::no_shuffle_deck=true;
else
ygo::no_shuffle_deck=false;
ygo::start_lp=atoi(argv[8]);
ygo::start_hand=atoi(argv[9]);
ygo::draw_count=atoi(argv[10]);
}
ygo::mainGame = &_game;
ygo::mainGame->MainServerLoop(ygo::mode);
return 0;
}
ygo::mainGame = &_game;
if(!ygo::mainGame->Initialize())
return 0;
......
......@@ -336,7 +336,7 @@ Materials::Materials() {
mCard.DiffuseColor = 0xff000000;
mCard.ColorMaterial = irr::video::ECM_NONE;
mCard.MaterialType = irr::video::EMT_ONETEXTURE_BLEND;
mCard.MaterialTypeParam = pack_textureBlendFunc(EBF_SRC_ALPHA, EBF_ONE_MINUS_SRC_ALPHA, EMFN_MODULATE_1X, EAS_VERTEX_COLOR);
// mCard.MaterialTypeParam = pack_textureBlendFunc(EBF_SRC_ALPHA, EBF_ONE_MINUS_SRC_ALPHA, EMFN_MODULATE_1X, EAS_VERTEX_COLOR);
mTexture.AmbientColor = 0xffffffff;
mTexture.DiffuseColor = 0xff000000;
mTexture.ColorMaterial = irr::video::ECM_NONE;
......@@ -346,13 +346,13 @@ Materials::Materials() {
mBackLine.DiffuseColor = 0xc0000000;
mBackLine.AntiAliasing = EAAM_FULL_BASIC;
mBackLine.MaterialType = irr::video::EMT_ONETEXTURE_BLEND;
mBackLine.MaterialTypeParam = pack_textureBlendFunc(EBF_SRC_ALPHA, EBF_ONE_MINUS_SRC_ALPHA, EMFN_MODULATE_1X, EAS_VERTEX_COLOR);
// mBackLine.MaterialTypeParam = pack_textureBlendFunc(EBF_SRC_ALPHA, EBF_ONE_MINUS_SRC_ALPHA, EMFN_MODULATE_1X, EAS_VERTEX_COLOR);
mBackLine.Thickness = 2;
mSelField.ColorMaterial = irr::video::ECM_NONE;
mSelField.AmbientColor = 0xffffffff;
mSelField.DiffuseColor = 0xff000000;
mSelField.MaterialType = irr::video::EMT_ONETEXTURE_BLEND;
mSelField.MaterialTypeParam = pack_textureBlendFunc(EBF_SRC_ALPHA, EBF_ONE_MINUS_SRC_ALPHA, EMFN_MODULATE_1X, EAS_VERTEX_COLOR);
// mSelField.MaterialTypeParam = pack_textureBlendFunc(EBF_SRC_ALPHA, EBF_ONE_MINUS_SRC_ALPHA, EMFN_MODULATE_1X, EAS_VERTEX_COLOR);
mOutLine.ColorMaterial = irr::video::ECM_AMBIENT;
mOutLine.DiffuseColor = 0xff000000;
mOutLine.Thickness = 2;
......@@ -362,7 +362,7 @@ Materials::Materials() {
mATK.DiffuseColor = 0x80000000;
mATK.setFlag(EMF_BACK_FACE_CULLING, FALSE);
mATK.MaterialType = irr::video::EMT_ONETEXTURE_BLEND;
mATK.MaterialTypeParam = pack_textureBlendFunc(EBF_SRC_ALPHA, EBF_ONE_MINUS_SRC_ALPHA, EMFN_MODULATE_1X, EAS_VERTEX_COLOR);
// mATK.MaterialTypeParam = pack_textureBlendFunc(EBF_SRC_ALPHA, EBF_ONE_MINUS_SRC_ALPHA, EMFN_MODULATE_1X, EAS_VERTEX_COLOR);
}
void Materials::GenArrow(float y) {
float ay = 1.0f;
......
......@@ -50,14 +50,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
int status;
char hostname[100];
BufferIO::CopyWStr((wchar_t *)mainGame->ebJoinIP->getText(),hostname,100);
if ((status = getaddrinfo(hostname, NULL, &hints, &servinfo)) == -1) {
//fprintf(stderr, "getaddrinfo error: %s\n", gai_strerror(status));
//error handling
}
else
{
inet_ntop(AF_INET, &(((struct sockaddr_in *)servinfo->ai_addr)->sin_addr), ip, 20);
}
unsigned int remote_addr = htonl(inet_addr(ip));
unsigned int remote_port = _wtoi(mainGame->ebJoinPort->getText());
BufferIO::CopyWStr(mainGame->ebJoinIP->getText(), mainGame->gameConf.lastip, 20);
......
......@@ -13,6 +13,49 @@ char NetServer::net_server_read[0x2000];
char NetServer::net_server_write[0x2000];
unsigned short NetServer::last_sent = 0;
void NetServer::Initduel(int bDuel_mode)
{
CTOS_CreateGame* pkt = new CTOS_CreateGame;
pkt->info.mode=MODE_SINGLE;
if(bDuel_mode == MODE_SINGLE) {
duel_mode = new SingleDuel(false);
duel_mode->etimer = event_new(net_evbase, 0, EV_TIMEOUT | EV_PERSIST, SingleDuel::SingleTimer, duel_mode);
} else if(bDuel_mode == MODE_MATCH) {
duel_mode = new SingleDuel(true);
duel_mode->etimer = event_new(net_evbase, 0, EV_TIMEOUT | EV_PERSIST, SingleDuel::SingleTimer, duel_mode);
} else if(bDuel_mode == MODE_TAG) {
duel_mode = new TagDuel();
duel_mode->etimer = event_new(net_evbase, 0, EV_TIMEOUT | EV_PERSIST, TagDuel::TagTimer, duel_mode);
}
if(pkt->info.rule > 3)
pkt->info.rule = 0;
if(pkt->info.mode > 2)
pkt->info.mode = 0;
unsigned int hash = 0;
//pkt->info.lflist = deckManager._lfList[lflist].hash;
for(auto lfit = deckManager._lfList.begin(); lfit != deckManager._lfList.end(); ++lfit) {
if(pkt->info.lflist == lfit->hash) {
hash = pkt->info.lflist;
break;
}
}
if(!hash)
pkt->info.lflist = deckManager._lfList[0].hash;
duel_mode->host_info = pkt->info;
BufferIO::CopyWStr(pkt->name, duel_mode->name, 20);
BufferIO::CopyWStr(pkt->pass, duel_mode->pass, 20);
// duel_mode->JoinGame(dp, 0, true);
// StartBroadcast();
}
bool NetServer::StartServer(unsigned short port) {
if(net_evbase)
return false;
......
......@@ -14,7 +14,7 @@ class NetServer {
private:
static std::unordered_map<bufferevent*, DuelPlayer> users;
static unsigned short server_port;
static event_base* net_evbase;
static event* broadcast_ev;
static evconnlistener* listener;
static DuelMode* duel_mode;
......@@ -23,6 +23,8 @@ private:
static unsigned short last_sent;
public:
static event_base* net_evbase;
static void Initduel(int duel_mode);
static bool StartServer(unsigned short port);
static bool StartBroadcast();
static void StopServer();
......
......@@ -3,9 +3,12 @@
#include "../ocgcore/card.h"
#include <algorithm>
#include "lzma/LzmaLib.h"
#include <sstream>
namespace ygo {
extern unsigned short aServerPort;
Replay::Replay() {
is_recording = false;
is_replaying = false;
......@@ -16,11 +19,42 @@ Replay::~Replay() {
delete[] replay_data;
delete[] comp_data;
}
std::wstring SA2W(std::string& strA)
{
setlocale(LC_ALL, "chs");
const char* _Source = strA.c_str();
size_t _Dsize = strA.size() + 1;
wchar_t *_Dest = new wchar_t[_Dsize];
wmemset(_Dest, 0, _Dsize);
mbstowcs(_Dest,_Source,_Dsize);
std::wstring result = _Dest;
delete []_Dest;
setlocale(LC_ALL, "C");
return result;
}
void Replay::BeginRecord() {
#ifdef _WIN32
if(is_recording)
if(is_recording)
CloseHandle(recording_fp);
recording_fp = CreateFileW(L"./replay/_LastReplay.yrp", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_FLAG_WRITE_THROUGH, NULL);
std::stringstream ss;
ss<<ygo::aServerPort;
std::string ssss;
ssss=ss.str();
std::wstring comPrefix = L"./replay/";
std::wstring comID =comPrefix+ SA2W(ssss)+L"Replay.yrp" ;
recording_fp = CreateFileW(comID.c_str(), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_FLAG_WRITE_THROUGH, NULL);
if(recording_fp == INVALID_HANDLE_VALUE)
return;
#else
......
......@@ -9,6 +9,17 @@
namespace ygo {
extern unsigned int lflist;
extern unsigned char rule;
extern unsigned char mode;
extern bool enable_priority;
extern bool no_check_deck;
extern bool no_shuffle_deck;
extern unsigned int start_lp;
extern unsigned char start_hand;
extern unsigned char draw_count;
bool runasserver = true;
SingleDuel::SingleDuel(bool is_match) {
match_mode = is_match;
match_kill = 0;
......@@ -57,6 +68,31 @@ void SingleDuel::JoinGame(DuelPlayer* dp, void* pdata, bool is_creater) {
NetServer::DisconnectPlayer(dp);
return;
}
if (runasserver){
host_info.start_hand=5;
host_info.start_lp=8000;
host_info.draw_count=1;
host_info.mode=1;
host_info.no_check_deck=false;
host_info.no_shuffle_deck=false;
host_info.enable_priority=false;
host_info.rule=0;
host_info.time_limit=180;
if (ygo::start_hand !=0 ){
host_info.start_hand=ygo::start_hand;
host_info.start_lp=ygo::start_lp;
host_info.draw_count=ygo::draw_count;
host_info.mode=ygo::mode;
host_info.no_check_deck=ygo::no_check_deck;
host_info.no_shuffle_deck=ygo::no_shuffle_deck;
host_info.enable_priority=ygo::enable_priority;
host_info.rule=ygo::rule;
host_info.time_limit=180;
}
}else
{
wchar_t jpass[20];
BufferIO::CopyWStr(pkt->pass, jpass, 20);
if(wcscmp(jpass, pass)) {
......@@ -66,6 +102,7 @@ void SingleDuel::JoinGame(DuelPlayer* dp, void* pdata, bool is_creater) {
NetServer::SendPacketToPlayer(dp, STOC_ERROR_MSG, scem);
return;
}
}
}
dp->game = this;
if(!players[0] && !players[1] && observers.size() == 0)
......
......@@ -9,6 +9,16 @@
namespace ygo {
extern unsigned int lflist;
extern unsigned char rule;
extern unsigned char mode;
extern bool enable_priority;
extern bool no_check_deck;
extern bool no_shuffle_deck;
extern unsigned int start_lp;
extern unsigned char start_hand;
extern unsigned char draw_count;
TagDuel::TagDuel() {
for(int i = 0; i < 4; ++i) {
players[i] = 0;
......@@ -45,14 +55,39 @@ void TagDuel::JoinGame(DuelPlayer* dp, void* pdata, bool is_creater) {
NetServer::DisconnectPlayer(dp);
return;
}
wchar_t jpass[20];
BufferIO::CopyWStr(pkt->pass, jpass, 20);
if(wcscmp(jpass, pass)) {
STOC_ErrorMsg scem;
scem.msg = ERRMSG_JOINERROR;
scem.code = 1;
NetServer::SendPacketToPlayer(dp, STOC_ERROR_MSG, scem);
return;
if (true){
host_info.start_hand=5;
host_info.start_lp=8000;
host_info.draw_count=1;
host_info.mode=3;
host_info.no_check_deck=false;
host_info.no_shuffle_deck=false;
host_info.enable_priority=false;
host_info.rule=0;
host_info.time_limit=180;
if (ygo::start_hand !=0 ){
host_info.start_hand=ygo::start_hand;
host_info.start_lp=ygo::start_lp;
host_info.draw_count=ygo::draw_count;
host_info.mode=ygo::mode;
host_info.no_check_deck=ygo::no_check_deck;
host_info.no_shuffle_deck=ygo::no_shuffle_deck;
host_info.enable_priority=ygo::enable_priority;
host_info.rule=ygo::rule;
host_info.time_limit=180;
}
}else
{
wchar_t jpass[20];
BufferIO::CopyWStr(pkt->pass, jpass, 20);
if(wcscmp(jpass, pass)) {
STOC_ErrorMsg scem;
scem.msg = ERRMSG_JOINERROR;
scem.code = 1;
NetServer::SendPacketToPlayer(dp, STOC_ERROR_MSG, scem);
return;
}
}
}
dp->game = this;
......
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