Commit a5e9cb40 authored by argon.sun's avatar argon.sun

init

parents
// Copyright (C) 2002-2010 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __C_GUI_BUTTON_H_INCLUDED__
#define __C_GUI_BUTTON_H_INCLUDED__
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_GUI_
#include "IGUIButton.h"
#include "IGUISpriteBank.h"
#include "SColor.h"
namespace irr {
namespace gui {
class CGUIButton : public IGUIButton {
public:
//! constructor
CGUIButton(IGUIEnvironment* environment, IGUIElement* parent,
s32 id, core::rect<s32> rectangle, bool noclip = false);
//! destructor
virtual ~CGUIButton();
//! called if an event happened.
virtual bool OnEvent(const SEvent& event);
//! draws the element and its children
virtual void draw();
//! sets another skin independent font. if this is set to zero, the button uses the font of the skin.
virtual void setOverrideFont(IGUIFont* font = 0);
//! Sets an image which should be displayed on the button when it is in normal state.
virtual void setImage(video::ITexture* image = 0);
//! Sets an image which should be displayed on the button when it is in normal state.
virtual void setImage(video::ITexture* image, const core::rect<s32>& pos);
//! Sets an image which should be displayed on the button when it is in pressed state.
virtual void setPressedImage(video::ITexture* image = 0);
//! Sets an image which should be displayed on the button when it is in pressed state.
virtual void setPressedImage(video::ITexture* image, const core::rect<s32>& pos);
//! Sets the sprite bank used by the button
virtual void setSpriteBank(IGUISpriteBank* bank = 0);
//! Sets the animated sprite for a specific button state
/** \param index: Number of the sprite within the sprite bank, use -1 for no sprite
\param state: State of the button to set the sprite for
\param index: The sprite number from the current sprite bank
\param color: The color of the sprite
*/
virtual void setSprite(EGUI_BUTTON_STATE state, s32 index,
video::SColor color = video::SColor(255, 255, 255, 255), bool loop = false);
//! Sets if the button should behave like a push button. Which means it
//! can be in two states: Normal or Pressed. With a click on the button,
//! the user can change the state of the button.
virtual void setIsPushButton(bool isPushButton = true);
//! Checks whether the button is a push button
virtual bool isPushButton() const;
//! Sets the pressed state of the button if this is a pushbutton
virtual void setPressed(bool pressed = true);
//! Returns if the button is currently pressed
virtual bool isPressed() const;
//! Sets if the button should use the skin to draw its border
virtual void setDrawBorder(bool border = true);
//! Checks if the button face and border are being drawn
virtual bool isDrawingBorder() const;
//! Sets if the alpha channel should be used for drawing images on the button (default is false)
virtual void setUseAlphaChannel(bool useAlphaChannel = true);
//! Checks if the alpha channel should be used for drawing images on the button
virtual bool isAlphaChannelUsed() const;
//! Sets if the button should scale the button images to fit
virtual void setScaleImage(bool scaleImage = true);
//! Checks whether the button scales the used images
virtual bool isScalingImage() const;
//! Writes attributes of the element.
virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const;
//! Reads attributes of the element
virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options);
protected:
struct ButtonSprite {
s32 Index;
video::SColor Color;
bool Loop;
};
ButtonSprite ButtonSprites[EGBS_COUNT];
IGUISpriteBank* SpriteBank;
IGUIFont* OverrideFont;
video::ITexture* Image;
video::ITexture* PressedImage;
core::rect<s32> ImageRect;
core::rect<s32> PressedImageRect;
u32 ClickTime;
bool IsPushButton;
bool Pressed;
bool UseAlphaChannel;
bool DrawBorder;
bool ScaleImage;
};
} // end namespace gui
} // end namespace irr
#endif // _IRR_COMPILE_WITH_GUI_
#endif // __C_GUI_BUTTON_H_INCLUDED__
#include "CGUIImageButton.h"
namespace irr {
namespace gui {
void Draw2DImageRotation(video::IVideoDriver* driver, video::ITexture* image, core::rect<s32> sourceRect,
core::position2d<s32> position, core::position2d<s32> rotationPoint, f32 rotation, core::vector2df scale, bool useAlphaChannel, video::SColor color) {
irr::video::SMaterial material;
irr::core::matrix4 oldProjMat = driver->getTransform(irr::video::ETS_PROJECTION);
driver->setTransform(irr::video::ETS_PROJECTION, irr::core::matrix4());
irr::core::matrix4 oldViewMat = driver->getTransform(irr::video::ETS_VIEW);
driver->setTransform(irr::video::ETS_VIEW, irr::core::matrix4());
irr::core::vector2df corner[4];
corner[0] = irr::core::vector2df(position.X, position.Y);
corner[1] = irr::core::vector2df(position.X + sourceRect.getWidth() * scale.X, position.Y);
corner[2] = irr::core::vector2df(position.X, position.Y + sourceRect.getHeight() * scale.Y);
corner[3] = irr::core::vector2df(position.X + sourceRect.getWidth() * scale.X, position.Y + sourceRect.getHeight() * scale.Y);
if (rotation != 0.0f) {
for (int x = 0; x < 4; x++)
corner[x].rotateBy(rotation, irr::core::vector2df(rotationPoint.X, rotationPoint.Y));
}
irr::core::vector2df uvCorner[4];
uvCorner[0] = irr::core::vector2df(sourceRect.UpperLeftCorner.X, sourceRect.UpperLeftCorner.Y);
uvCorner[1] = irr::core::vector2df(sourceRect.LowerRightCorner.X, sourceRect.UpperLeftCorner.Y);
uvCorner[2] = irr::core::vector2df(sourceRect.UpperLeftCorner.X, sourceRect.LowerRightCorner.Y);
uvCorner[3] = irr::core::vector2df(sourceRect.LowerRightCorner.X, sourceRect.LowerRightCorner.Y);
for (int x = 0; x < 4; x++) {
float uvX = uvCorner[x].X / (float)image->getSize().Width;
float uvY = uvCorner[x].Y / (float)image->getSize().Height;
uvCorner[x] = irr::core::vector2df(uvX, uvY);
}
irr::video::S3DVertex vertices[4];
irr::u16 indices[6] = { 0, 1, 2, 3, 2, 1 };
float screenWidth = driver->getScreenSize().Width;
float screenHeight = driver->getScreenSize().Height;
for (int x = 0; x < 4; x++) {
float screenPosX = ((corner[x].X / screenWidth) - 0.5f) * 2.0f;
float screenPosY = ((corner[x].Y / screenHeight) - 0.5f) * -2.0f;
vertices[x].Pos = irr::core::vector3df(screenPosX, screenPosY, 1);
vertices[x].TCoords = uvCorner[x];
vertices[x].Color = color;
}
material.Lighting = false;
material.ZWriteEnable = false;
material.TextureLayer[0].Texture = image;
if (useAlphaChannel)
material.MaterialType = irr::video::EMT_TRANSPARENT_ALPHA_CHANNEL;
else material.MaterialType = irr::video::EMT_SOLID;
driver->setMaterial(material);
driver->drawIndexedTriangleList(&vertices[0], 4, &indices[0], 2);
driver->setTransform(irr::video::ETS_PROJECTION, oldProjMat);
driver->setTransform(irr::video::ETS_VIEW, oldViewMat);
}
CGUIImageButton::CGUIImageButton(IGUIEnvironment* environment, IGUIElement* parent, s32 id, core::rect<s32> rectangle)
: CGUIButton(environment, parent, id, rectangle) {
isDrawImage = true;
imageRotation = 0.0f;
imageScale = core::vector2df(1.0f, 1.0f);
}
CGUIImageButton* CGUIImageButton::addImageButton(IGUIEnvironment *env, const core::rect<s32>& rectangle, IGUIElement* parent, s32 id) {
CGUIImageButton* button = new CGUIImageButton(env, parent ? parent : dynamic_cast<IGUIElement*>(env), id, rectangle);
button->drop();
return button;
}
void CGUIImageButton::draw() {
if (!IsVisible)
return;
IGUISkin* skin = Environment->getSkin();
video::IVideoDriver* driver = Environment->getVideoDriver();
core::position2di center = AbsoluteRect.getCenter();
core::position2di pos = center;
pos.X -= (s32)(ImageRect.getWidth() * imageScale.X * 0.5f);
pos.Y -= (s32)(ImageRect.getHeight() * imageScale.Y * 0.5f);
if(Pressed) {
pos.X += 1;
pos.Y += 1;
center.X += 1;
center.Y += 1;
if (DrawBorder)
skin->draw3DButtonPanePressed(this, AbsoluteRect, &AbsoluteClippingRect);
} else {
if (DrawBorder)
skin->draw3DButtonPaneStandard(this, AbsoluteRect, &AbsoluteClippingRect);
}
if(Image && isDrawImage)
irr::gui::Draw2DImageRotation(driver, Image, ImageRect, pos, center, imageRotation, imageScale);
IGUIElement::draw();
}
void CGUIImageButton::setDrawImage(bool b) {
isDrawImage = b;
}
void CGUIImageButton::setImageRotation(f32 r) {
imageRotation = r;
}
void CGUIImageButton::setImageScale(core::vector2df s) {
imageScale = s;
}
}
}
#ifndef _C_GUI_IMAGE_BUTTON_H_
#define _C_GUI_IMAGE_BUTTON_H_
#include <irrlicht.h>
#include "CGUIButton.h"
namespace irr {
namespace gui {
void Draw2DImageRotation(video::IVideoDriver* driver, video::ITexture* image, core::rect<s32> sourceRect,
core::position2d<s32> position, core::position2d<s32> rotationPoint, f32 rotation = 0.0f,
core::vector2df scale = core::vector2df(1.0, 1.0), bool useAlphaChannel = true, video::SColor color = 0xffffffff);
class CGUIImageButton : public CGUIButton {
public:
CGUIImageButton(IGUIEnvironment* environment, IGUIElement* parent, s32 id, core::rect<s32> rectangle);
static CGUIImageButton* addImageButton(IGUIEnvironment *env, const core::rect<s32>& rectangle, IGUIElement* parent, s32 id);
virtual void draw();
virtual void setDrawImage(bool b);
virtual void setImageRotation(f32 r);
virtual void setImageScale(core::vector2df s);
private:
bool isDrawImage;
f32 imageRotation;
core::vector2df imageScale;
};
}
}
#endif //_C_GUI_IMAGE_BUTTON_H_
This diff is collapsed.
This diff is collapsed.
#include "client_card.h"
#include "game.h"
extern ygo::Game* mainGame;
namespace ygo {
ClientCard::ClientCard() {
curAlpha = 255;
dAlpha = 0;
aniFrame = 0;
is_moving = false;
is_fading = false;
is_hovered = false;
is_selectable = false;
is_selected = false;
is_showequip = false;
is_showtarget = false;
is_highlighting = false;
is_disabled = false;
cmdFlag = 0;
code = 0;
type = 0;
alias = 0;
level = 0;
rank = 0;
race = 0;
attribute = 0;
attack = 0;
defence = 0;
base_attack = 0;
base_defence = 0;
turnCounter = 0;
atkstring[0] = 0;
defstring[0] = 0;
lvstring[0] = 0;
overlayTarget = 0;
equipTarget = 0;
}
void ClientCard::SetCode(int code) {
if(location == LOCATION_HAND && controler == 1 && this->code != code)
mainGame->dField.MoveCard(this, 5);
this->code = code;
}
void ClientCard::UpdateInfo(char* buf) {
int flag = NetManager::ReadInt32(buf);
if(flag == 0)
return;
int pdata;
if(flag & QUERY_CODE) {
pdata = NetManager::ReadInt32(buf);
if(location == LOCATION_HAND && controler == 1 && pdata != code)
mainGame->dField.MoveCard(this, 5);
code = pdata;
}
if(flag & QUERY_POSITION)
pdata = NetManager::ReadInt32(buf);
if(flag & QUERY_ALIAS)
alias = NetManager::ReadInt32(buf);
if(flag & QUERY_TYPE)
type = NetManager::ReadInt32(buf);
if(flag & QUERY_LEVEL) {
pdata = NetManager::ReadInt32(buf);
if(pdata && level != pdata) {
level = pdata;
myswprintf(lvstring, L"L%d", level);
}
}
if(flag & QUERY_RANK) {
pdata = NetManager::ReadInt32(buf);
if(pdata && rank != pdata) {
rank = pdata;
myswprintf(lvstring, L"R%d", rank);
}
}
if(flag & QUERY_ATTRIBUTE)
attribute = NetManager::ReadInt32(buf);
if(flag & QUERY_RACE)
race = NetManager::ReadInt32(buf);
if(flag & QUERY_ATTACK) {
attack = NetManager::ReadInt32(buf);
if(attack < 0) {
atkstring[0] = '?';
atkstring[1] = 0;
} else
myswprintf(atkstring, L"%d", attack);
}
if(flag & QUERY_DEFENCE) {
defence = NetManager::ReadInt32(buf);
if(defence < 0) {
defstring[0] = '?';
defstring[1] = 0;
} else
myswprintf(defstring, L"%d", defence);
}
if(flag & QUERY_BASE_ATTACK)
base_attack = NetManager::ReadInt32(buf);
if(flag & QUERY_BASE_DEFENCE)
base_defence = NetManager::ReadInt32(buf);
if(flag & QUERY_REASON)
reason = NetManager::ReadInt32(buf);
if(flag & QUERY_IS_DISABLED)
is_disabled = NetManager::ReadInt32(buf);
if(flag & QUERY_IS_PUBLIC)
is_public = NetManager::ReadInt32(buf);
}
void ClientCard::ClearTarget() {
for(auto cit = cardTarget.begin(); cit != cardTarget.end(); ++cit)
(*cit)->ownerTarget.erase(this);
for(auto cit = ownerTarget.begin(); cit != ownerTarget.end(); ++cit)
(*cit)->cardTarget.erase(this);
cardTarget.clear();
ownerTarget.clear();
}
bool ClientCard::client_card_sort(ClientCard* c1, ClientCard* c2) {
int32 cp1 = c1->overlayTarget ? c1->overlayTarget->controler : c1->controler;
int32 cp2 = c2->overlayTarget ? c2->overlayTarget->controler : c2->controler;
if(cp1 != cp2)
return cp1 < cp2;
if(c1->location != c2->location)
return c1->location < c2->location;
if(c1->location & LOCATION_OVERLAY)
if(c1->overlayTarget != c2->overlayTarget)
return c1->overlayTarget->sequence < c2->overlayTarget->sequence;
else return c1->sequence < c2->sequence;
else {
if(c1->location & 0x71)
return c1->sequence > c2->sequence;
else
return c1->sequence < c2->sequence;
}
}
bool ClientCard::deck_sort_atk(code_pointer p1, code_pointer p2) {
if((p1->second.type & 0x7) != (p2->second.type & 0x7))
return (p1->second.type & 0x7) < (p2->second.type & 0x7);
if((p1->second.type & 0x7) == 1) {
int type1 = (p1->second.type & 0x8020c0) ? (p1->second.type & 0x8020c1) : (p1->second.type & 0x31);
int type2 = (p2->second.type & 0x8020c0) ? (p2->second.type & 0x8020c1) : (p2->second.type & 0x31);
if(type1 != type2)
return type1 < type2;
if(p1->second.attack != p2->second.attack)
return p1->second.attack > p2->second.attack;
else return p1->first < p2->first;
}
if((p1->second.type & 0xfffffff8) != (p2->second.type & 0xfffffff8))
return (p1->second.type & 0xfffffff8) < (p2->second.type & 0xfffffff8);
return p1->first < p2->first;
}
bool ClientCard::deck_sort_def(code_pointer p1, code_pointer p2) {
if((p1->second.type & 0x7) != (p2->second.type & 0x7))
return (p1->second.type & 0x7) < (p2->second.type & 0x7);
if((p1->second.type & 0x7) == 1) {
int type1 = (p1->second.type & 0x8020c0) ? (p1->second.type & 0x8020c1) : (p1->second.type & 0x31);
int type2 = (p2->second.type & 0x8020c0) ? (p2->second.type & 0x8020c1) : (p2->second.type & 0x31);
if(type1 != type2)
return type1 < type2;
if(p1->second.defence != p2->second.defence)
return p1->second.defence > p2->second.defence;
else return p1->first < p2->first;
}
if((p1->second.type & 0xfffffff8) != (p2->second.type & 0xfffffff8))
return (p1->second.type & 0xfffffff8) < (p2->second.type & 0xfffffff8);
return p1->first < p2->first;
}
bool ClientCard::deck_sort_lv(code_pointer p1, code_pointer p2) {
if((p1->second.type & 0x7) != (p2->second.type & 0x7))
return (p1->second.type & 0x7) < (p2->second.type & 0x7);
if((p1->second.type & 0x7) == 1) {
int type1 = (p1->second.type & 0x8020c0) ? (p1->second.type & 0x8020c1) : (p1->second.type & 0x31);
int type2 = (p2->second.type & 0x8020c0) ? (p2->second.type & 0x8020c1) : (p2->second.type & 0x31);
if(type1 != type2)
return type1 < type2;
if(p1->second.level != p2->second.level)
return p1->second.level > p2->second.level;
else return p1->first < p2->first;
}
if((p1->second.type & 0xfffffff8) != (p2->second.type & 0xfffffff8))
return (p1->second.type & 0xfffffff8) < (p2->second.type & 0xfffffff8);
return p1->first < p2->first;
}
}
#ifndef CLIENT_CARD_H
#define CLIENT_CARD_H
#include "config.h"
#include <vector>
#include <set>
#include <unordered_map>
namespace ygo {
struct CardData {
unsigned int code;
unsigned int alias;
unsigned int setcode;
unsigned int type;
unsigned int level;
unsigned int attribute;
unsigned int race;
int attack;
int defence;
};
struct CardDataC {
unsigned int code;
unsigned int alias;
unsigned int setcode;
unsigned int type;
unsigned int level;
unsigned int attribute;
unsigned int race;
int attack;
int defence;
unsigned int category;
};
struct CardString {
wchar_t* name;
wchar_t* text;
wchar_t* desc[16];
};
typedef std::unordered_map<unsigned int, CardDataC>::iterator code_pointer;
struct ClientCard {
public:
irr::video::ITexture* curTexture;
irr::core::matrix4 mTransform;
irr::core::vector3df curPos;
irr::core::vector3df curRot;
irr::core::vector3df dPos;
irr::core::vector3df dRot;
u32 curAlpha;
u32 dAlpha;
u32 aniFrame;
bool is_moving;
bool is_fading;
bool is_hovered;
bool is_selectable;
bool is_selected;
bool is_showequip;
bool is_showtarget;
bool is_highlighting;
u32 code;
u32 alias;
u32 type;
u32 level;
u32 rank;
u32 attribute;
u32 race;
s32 attack;
s32 defence;
s32 base_attack;
s32 base_defence;
u32 reason;
u32 select_seq;
u8 owner;
u8 controler;
u8 location;
u8 sequence;
u8 position;
u8 is_disabled;
u8 is_public;
u32 turnCounter;
u32 opParam;
u32 symbol;
u32 cmdFlag;
ClientCard* overlayTarget;
std::vector<ClientCard*> overlayed;
ClientCard* equipTarget;
std::set<ClientCard*> equipped;
std::set<ClientCard*> cardTarget;
std::set<ClientCard*> ownerTarget;
std::map<int, int> counters;
wchar_t atkstring[16];
wchar_t defstring[16];
wchar_t lvstring[16];
ClientCard();
void SetCode(int code);
void UpdateInfo(char* buf);
void ClearTarget();
static bool client_card_sort(ClientCard* c1, ClientCard* c2);
static bool deck_sort_atk(code_pointer p1, code_pointer p2);
static bool deck_sort_def(code_pointer def, code_pointer p2);
static bool deck_sort_lv(code_pointer lv, code_pointer p2);
};
}
#endif //CLIENT_CARD_H
This diff is collapsed.
#ifndef CLIENT_FIELD_H
#define CLIENT_FIELD_H
#include "config.h"
#include "client_card.h"
#include <vector>
namespace ygo {
struct ChainInfo{
irr::core::vector3df chain_pos;
ClientCard* chain_card;
int code;
int desc;
int controler;
int location;
int sequence;
bool solved;
};
class ClientField: public irr::IEventReceiver {
public:
std::vector<ClientCard*> deck[2];
std::vector<ClientCard*> hand[2];
std::vector<ClientCard*> mzone[2];
std::vector<ClientCard*> szone[2];
std::vector<ClientCard*> grave[2];
std::vector<ClientCard*> remove[2];
std::vector<ClientCard*> extra[2];
std::set<ClientCard*> overlay_cards;
std::vector<ClientCard*> summonable_cards;
std::vector<ClientCard*> spsummonable_cards;
std::vector<ClientCard*> msetable_cards;
std::vector<ClientCard*> ssetable_cards;
std::vector<ClientCard*> reposable_cards;
std::vector<ClientCard*> activatable_cards;
std::vector<ClientCard*> attackable_cards;
std::vector<int> activatable_descs;
std::vector<int> select_options;
std::vector<ChainInfo> chains;
bool is_replaying;
bool is_pausing;
bool is_paused;
bool is_swaping;
int selected_option;
ClientCard* attacker;
ClientCard* attack_target;
int disabled_field;
int selectable_field;
int selected_field;
int select_min;
int select_max;
int select_cancelable;
int select_mode;
bool select_ready;
int announce_count;
int select_counter_count;
int select_counter_type;
std::vector<ClientCard*> selectable_cards;
std::vector<ClientCard*> selected_cards;
std::set<ClientCard*> selectsum_cards;
std::vector<ClientCard*> selectsum_all;
std::vector<int> sort_list;
bool grave_act;
bool remove_act;
bool deck_act;
bool extra_act;
ChainInfo current_chain;
bool last_chain;
ClientField();
void Clear();
void Initial(int player, int deckc, int extrac);
ClientCard* GetCard(int controler, int location, int sequence);
void AddCard(ClientCard* pcard, int controler, int location, int sequence);
ClientCard* RemoveCard(int controler, int location, int sequence);
void UpdateCard(int controler, int location, int sequence, char* data);
void UpdateFieldCard(int controler, int location, char* data);
void ClearCommandFlag();
void ClearSelect();
void ClearChainSelect();
void ShowSelectCard(bool buttonok = false);
void ReplaySwap();
void GetChainLocation(int controler, int location, int sequence, irr::core::vector3df* t);
void GetCardLocation(ClientCard* pcard, irr::core::vector3df* t, irr::core::vector3df* r);
void MoveCard(ClientCard* pcard, int frame);
void FadeCard(ClientCard* pcard, int alpha, int frame);
bool CheckSelectSum();
bool check_min(std::set<ClientCard*>& left, std::set<ClientCard*>::iterator index, int min, int max);
bool check_sel_sum_s(std::set<ClientCard*>& left, int index, int acc);
void check_sel_sum_t(std::set<ClientCard*>& left, int acc);
bool check_sum(std::set<ClientCard*>& testlist, std::set<ClientCard*>::iterator index, int acc, int count);
irr::IrrlichtDevice* device;
irr::gui::IGUIElement* panel;
int hovered_controler;
int hovered_location;
int hovered_sequence;
int command_controler;
int command_location;
int command_sequence;
ClientCard* hovered_card;
ClientCard* clicked_card;
ClientCard* command_card;
int list_command;
wchar_t formatBuffer[256];
virtual bool OnEvent(const irr::SEvent& event);
void GetHoverField(int x, int y);
void ShowMenu(int flag, int x, int y);
};
}
#endif //CLIENT_FIELD_H
#ifndef __CONFIG_H
#define __CONFIG_H
#pragma once
#define _IRR_STATIC_LIB_
#include <irrlicht.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include "CGUITTFont.h"
#include "CGUIImageButton.h"
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include "mytimer.h"
#include "mymutex.h"
#include "mysignal.h"
#include "mythread.h"
#include "../ocgcore/ocgapi.h"
#include "../ocgcore/card.h"
#ifdef _WIN32
#include <windows.h>
#define myswprintf swprintf
#else
#include <errno.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <arpa/inet.h>
#include <netdb.h>
#define SD_BOTH 2
#define SOCKET int
#define closesocket close
#define INVALID_SOCKET -1
#define SOCKET_ERROR -1
#define SOCKADDR_IN sockaddr_in
#define SOCKADDR sockaddr
#define SOCKET_ERRNO() (errno)
#include <wchar.h>
#define myswprintf(buf, fmt, ...) swprintf(buf, 4096, fmt, ##__VA_ARGS__)
inline int _wtoi(const wchar_t * s) {
wchar_t * endptr;
return (int)wcstol(s, &endptr, 10);
}
#endif
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
#endif
This diff is collapsed.
#ifndef DATAMANAGER_H
#define DATAMANAGER_H
#include "config.h"
#include "sqlite3.h"
#include "client_card.h"
#include <unordered_map>
namespace ygo {
class DataManager {
public:
DataManager() {
}
~DataManager() {
}
bool LoadDates(const char* file);
bool Error(sqlite3* pDB, sqlite3_stmt* pStmt = 0);
bool GetData(int code, CardData* pData);
code_pointer GetCodePointer(int code);
bool GetString(int code, CardString* pStr);
const wchar_t* GetName(int code);
const wchar_t* GetText(int code);
const wchar_t* GetDesc(int strCode);
const wchar_t* GetSysString(int code);
const wchar_t* GetVictoryString(int code);
const wchar_t* GetCounterName(int code);
const wchar_t* GetSeriesName(int code);
const wchar_t* GetNumString(int num);
static int EncodeUTF8(const wchar_t * wsrc, char * str);
static int DecodeUTF8(const char * src, wchar_t * wstr);
std::unordered_map<unsigned int, CardDataC> _datas;
std::unordered_map<unsigned int, CardString> _strings;
std::unordered_map<unsigned int, wchar_t*> _sysStrings;
std::unordered_map<unsigned int, wchar_t*> _counterStrings;
std::unordered_map<unsigned int, wchar_t*> _victoryStrings;
std::unordered_map<unsigned int, wchar_t*> _seriesStrings;
wchar_t numStrings[256][4];
static wchar_t strBuffer[2048];
static wchar_t attBuffer[128];
static wchar_t racBuffer[128];
static wchar_t tpBuffer[128];
static const wchar_t* unknown_string;
static const wchar_t* effect_strings[];
static const wchar_t* FormatLocation(int location);
static const wchar_t* FormatAttribute(int attribute);
static const wchar_t* FormatRace(int race);
static const wchar_t* FormatType(int type);
};
}
#endif // DATAMANAGER_H
This diff is collapsed.
#ifndef DECK_CON_H
#define DECK_CON_H
#include "config.h"
#include <unordered_map>
#include <vector>
#include "client_card.h"
namespace ygo {
class DeckBuilder: public irr::IEventReceiver {
public:
virtual bool OnEvent(const irr::SEvent& event);
int GetVal(const wchar_t* pstr);
void FilterCards();
void FilterCardsFromResult();
long long filter_effect;
int filter_type;
int filter_type2;
int filter_series;
int filter_attrib;
int filter_race;
int filter_atktype;
int filter_atk;
int filter_deftype;
int filter_def;
int filter_lvtype;
int filter_lv;
int filter_lm;
int hovered_code;
int hovered_pos;
int hovered_seq;
int click_pos;
bool is_draging;
int dragx;
int dragy;
code_pointer draging_pointer;
irr::IrrlichtDevice* device;
std::unordered_map<int, int>* filterList;
std::vector<code_pointer> results;
wchar_t result_string[8];
};
}
#endif //DECK_CON
#include "deck_manager.h"
#include "data_manager.h"
#include "game.h"
#include <algorithm>
extern ygo::Game* mainGame;
namespace ygo {
void DeckManager::LoadLFList() {
LFList cur;
std::unordered_map<int, int>* curMap = 0;
FILE* fp = fopen("lflist.conf", "r");
char linebuf[256];
wchar_t strBuffer[256];
if(fp) {
fseek(fp, 0, SEEK_END);
size_t fsize = ftell(fp);
fseek(fp, 0, SEEK_SET);
fgets(linebuf, 256, fp);
while(ftell(fp) < fsize) {
fgets(linebuf, 256, fp);
if(linebuf[0] == '#')
continue;
int p = 0, sa = 0, code, count;
if(linebuf[0] == '!') {
sa = DataManager::DecodeUTF8((const char*)(&linebuf[1]), strBuffer);
while(strBuffer[sa - 1] == L'\r' || strBuffer[sa - 1] == L'\n' ) sa--;
memcpy(cur.listName, (const void*)strBuffer, 40);
cur.listName[sa] = 0;
curMap = new std::unordered_map<int, int>;
cur.content = curMap;
_lfList.push_back(cur);
continue;
}
while(linebuf[p] != ' ' && linebuf[p] != '\t' && linebuf[p] != 0) p++;
if(linebuf[p] == 0)
continue;
linebuf[p++] = 0;
sa = p;
code = atoi(linebuf);
if(code == 0)
continue;
while(linebuf[p] == ' ' || linebuf[p] == '\t') p++;
while(linebuf[p] != ' ' && linebuf[p] != '\t' && linebuf[p] != 0) p++;
linebuf[p] = 0;
count = atoi(&linebuf[sa]);
(*curMap)[code] = count;
}
fclose(fp);
}
myswprintf(cur.listName, L"无限制");
cur.content = new std::unordered_map<int, int>;
_lfList.push_back(cur);
}
bool DeckManager::CheckLFList(Deck& deck, int lfindex) {
std::unordered_map<int, int> ccount;
std::unordered_map<int, int>* list = _lfList[lfindex].content;
int dc = 0, dec = 0;
if(deck.main.size() < 40 || deck.main.size() > 60 || deck.extra.size() > 15 || deck.side.size() > 15)
return false;
for(int i = 0; i < deck.main.size(); ++i) {
ccount[deck.main[i]->first]++;
dc = ccount[deck.main[i]->first];
auto it = list->find(deck.main[i]->first);
if(dc > 3 || (it != list->end() && dc > it->second))
return false;
}
for(int i = 0; i < deck.extra.size(); ++i) {
ccount[deck.extra[i]->first]++;
dc = ccount[deck.extra[i]->first];
auto it = list->find(deck.extra[i]->first);
if(dc > 3 || (it != list->end() && dc > it->second))
return false;
}
for(int i = 0; i < deck.side.size(); ++i) {
ccount[deck.side[i]->first]++;
dc = ccount[deck.side[i]->first];
auto it = list->find(deck.side[i]->first);
if(dc > 3 || (it != list->end() && dc > it->second))
return false;
}
return true;
}
void DeckManager::LoadDeck(Deck& deck, int* dbuf, int mainc, int sidec) {
deck.main.clear();
deck.extra.clear();
deck.side.clear();
int code;
CardData cd;
for(int i = 0; i < mainc; ++i) {
code = dbuf[i];
if(!mainGame->dataManager.GetData(code, &cd))
continue;
if(cd.type & TYPE_TOKEN)
continue;
else if(cd.type & 0x802040 && deck.extra.size() < 15) {
deck.extra.push_back(mainGame->dataManager.GetCodePointer(code));
} else if(deck.main.size() < 60) {
deck.main.push_back(mainGame->dataManager.GetCodePointer(code));
}
}
for(int i = 0; i < sidec; ++i) {
code = dbuf[mainc + i];
if(deck.side.size() < 15)
deck.side.push_back(mainGame->dataManager.GetCodePointer(code));
}
}
bool DeckManager::LoadDeck(const wchar_t* file) {
int sp = 0, ct = 0, mainc = 0, sidec = 0, code;
wchar_t deck[64];
myswprintf(deck, L"./deck/%ls.ydk", file);
int cardlist[128];
bool is_side = false;
#ifdef WIN32
FILE* fp = _wfopen(deck, L"r");
#else
char deckfn[256];
DataManager::EncodeUTF8(deck, deckfn);
FILE* fp = fopen(deckfn, "r");
#endif
if(!fp)
return false;
char linebuf[256];
fseek(fp, 0, SEEK_END);
size_t fsize = ftell(fp);
fseek(fp, 0, SEEK_SET);
fgets(linebuf, 256, fp);
while(ftell(fp) < fsize && ct < 128) {
fgets(linebuf, 256, fp);
if(linebuf[0] == '!') {
is_side = true;
continue;
}
if(linebuf[0] < '0' || linebuf[0] > '9')
continue;
sp = 0;
while(linebuf[sp] >= '0' && linebuf[sp] <= '9') sp++;
linebuf[sp] = 0;
code = atoi(linebuf);
cardlist[ct++] = code;
if(is_side) sidec++;
else mainc++;
}
fclose(fp);
LoadDeck(deckhost, cardlist, mainc, sidec);
return true;
}
void DeckManager::SaveDeck(Deck& deck, const wchar_t* name) {
wchar_t file[64];
myswprintf(file, L"./deck/%ls.ydk", name);
#ifdef WIN32
FILE* fp = _wfopen(file, L"w");
#else
char filefn[256];
DataManager::EncodeUTF8(file, filefn);
FILE* fp = fopen(filefn, "w");
#endif
if(!fp)
return;
fprintf(fp, "#created by ...\n#main\n");
for(int i = 0; i < deck.main.size(); ++i)
fprintf(fp, "%d\n", deck.main[i]->first);
fprintf(fp, "#extra\n");
for(int i = 0; i < deck.extra.size(); ++i)
fprintf(fp, "%d\n", deck.extra[i]->first);
fprintf(fp, "!side\n");
for(int i = 0; i < deck.side.size(); ++i)
fprintf(fp, "%d\n", deck.side[i]->first);
fclose(fp);
}
}
#ifndef DECKMANAGER_H
#define DECKMANAGER_H
#include "config.h"
#include "client_card.h"
#include <unordered_map>
#include <vector>
namespace ygo {
struct LFList {
wchar_t listName[20];
std::unordered_map<int, int>* content;
};
struct Deck {
std::vector<code_pointer> main;
std::vector<code_pointer> extra;
std::vector<code_pointer> side;
};
class DeckManager {
public:
Deck deckhost;
Deck deckclient;
std::vector<LFList> _lfList;
void LoadLFList();
bool CheckLFList(Deck& deck, int lfindex);
void LoadDeck(Deck& deck, int* dbuf, int mainc, int sidec);
bool LoadDeck(const wchar_t* file);
void SaveDeck(Deck& deck, const wchar_t* name);
};
}
#endif //DECKMANAGER_H
This diff is collapsed.
This diff is collapsed.
#ifndef EVENT_HANDLER_H
#define EVENT_HANDLER_H
#include "config.h"
#include "game.h"
#include "client_card.h"
namespace ygo {
class EventHandler : public irr::IEventReceiver {
public:
EventHandler(irr::IrrlichtDevice* dev);
virtual bool OnEvent(const irr::SEvent& event);
void GetHoverField(int x, int y);
void ShowMenu(int flag, int x, int y);
irr::IrrlichtDevice* device;
irr::gui::IGUIElement* panel;
int hovered_controler;
int hovered_location;
int hovered_sequence;
ClientCard* hovered_card;
ClientCard* clicked_card;
wchar_t formatBuffer[256];
};
}
#endif //EVENT_HANDLER_H
This diff is collapsed.
This diff is collapsed.
#include "config.h"
#include "game.h"
ygo::Game* mainGame;
int main() {
#ifdef _WIN32
WORD wVersionRequested;
WSADATA wsaData;
wVersionRequested = MAKEWORD(2, 2);
WSAStartup(wVersionRequested, &wsaData);
timeBeginPeriod(1);
#else
#endif //_WIN32
ygo::Game _game;
mainGame = &_game;
if(!mainGame->Initialize())
return 0;
mainGame->MainLoop();
#ifdef _WIN32
timeEndPeriod(1);
WSACleanup();
#else
#endif //_WIN32
return EXIT_SUCCESS;
}
#include "image_manager.h"
#include "game.h"
extern ygo::Game* mainGame;
namespace ygo {
bool ImageManager::Initial() {
tCover = driver->getTexture("textures/cover.jpg");
tAct = driver->getTexture("textures/act.png");
tAttack = driver->getTexture("textures/attack.png");
tChain = driver->getTexture("textures/chain.png");
tNegated = driver->getTexture("textures/negated.png");
tNumber = driver->getTexture("textures/number.png");
tLPBar = driver->getTexture("textures/lp.png");
tLPFrame = driver->getTexture("textures/lpf.png");
tMask = driver->getTexture("textures/mask.png");
tEquip = driver->getTexture("textures/equip.png");
tTarget = driver->getTexture("textures/target.png");
tLim = driver->getTexture("textures/lim.png");
tBackGround = driver->getTexture("textures/bg.jpg");
return true;
}
void ImageManager::SetDevice(irr::IrrlichtDevice* dev) {
device = dev;
driver = dev->getVideoDriver();
}
void ImageManager::ClearTexture() {
mainGame->matManager.mCard.setTexture(0, 0);
mainGame->imgCard->setImage(0);
mainGame->btnPSAU->setImage();
mainGame->btnPSDU->setImage();
mainGame->btnCardSelect[0]->setImage();
mainGame->btnCardSelect[1]->setImage();
mainGame->btnCardSelect[2]->setImage();
mainGame->btnCardSelect[3]->setImage();
mainGame->btnCardSelect[4]->setImage();
for(auto tit = tMap.begin(); tit != tMap.end(); ++tit) {
if(tit->second)
driver->removeTexture(tit->second);
}
for(auto tit = tThumb.begin(); tit != tThumb.end(); ++tit) {
if(tit->second)
driver->removeTexture(tit->second);
}
tMap.clear();
tThumb.clear();
}
void ImageManager::RemoveTexture(int code) {
auto tit = tMap.find(code);
if(tit != tMap.end()) {
if(tit->second)
driver->removeTexture(tit->second);
tMap.erase(tit);
}
}
irr::video::ITexture* ImageManager::GetTexture(int code) {
if(code == 0)
return 0;
auto tit = tMap.find(code);
if(tit == tMap.end()) {
char file[256];
sprintf(file, "pics/%d.jpg", code);
irr::video::ITexture* img = driver->getTexture(file);
tMap[code] = img;
return img;
}
return tit->second;
}
irr::video::ITexture* ImageManager::GetTextureThumb(int code) {
if(code == 0)
return 0;
auto tit = tThumb.find(code);
if(tit == tThumb.end()) {
char file[32];
sprintf(file, "pics/thumbnail/%d.jpg", code);
irr::video::ITexture* img = driver->getTexture(file);
tThumb[code] = img;
return img;
}
return tit->second;
}
}
#ifndef IMAGEMANAGER_H
#define IMAGEMANAGER_H
#include "config.h"
#include "data_manager.h"
#include <unordered_map>
namespace ygo {
class ImageManager {
public:
bool Initial();
void SetDevice(irr::IrrlichtDevice* dev);
void ClearTexture();
void RemoveTexture(int code);
irr::video::ITexture* GetTexture(int code);
irr::video::ITexture* GetTextureThumb(int code);
std::unordered_map<int, irr::video::ITexture*> tMap;
std::unordered_map<int, irr::video::ITexture*> tThumb;
irr::IrrlichtDevice* device;
irr::video::IVideoDriver* driver;
irr::video::ITexture* tCover;
irr::video::ITexture* tAct;
irr::video::ITexture* tAttack;
irr::video::ITexture* tNegated;
irr::video::ITexture* tChain;
irr::video::ITexture* tNumber;
irr::video::ITexture* tLPFrame;
irr::video::ITexture* tLPBar;
irr::video::ITexture* tMask;
irr::video::ITexture* tEquip;
irr::video::ITexture* tTarget;
irr::video::ITexture* tLim;
irr::video::ITexture* tBackGround;
};
}
#endif // IMAGEMANAGER_H
This diff is collapsed.
/* Alloc.c -- Memory allocation functions
2008-09-24
Igor Pavlov
Public domain */
#ifdef _WIN32
#include <windows.h>
#endif
#include <stdlib.h>
#include "Alloc.h"
/* #define _SZ_ALLOC_DEBUG */
/* use _SZ_ALLOC_DEBUG to debug alloc/free operations */
#ifdef _SZ_ALLOC_DEBUG
#include <stdio.h>
int g_allocCount = 0;
int g_allocCountMid = 0;
int g_allocCountBig = 0;
#endif
void *MyAlloc(size_t size)
{
if (size == 0)
return 0;
#ifdef _SZ_ALLOC_DEBUG
{
void *p = malloc(size);
fprintf(stderr, "\nAlloc %10d bytes, count = %10d, addr = %8X", size, g_allocCount++, (unsigned)p);
return p;
}
#else
return malloc(size);
#endif
}
void MyFree(void *address)
{
#ifdef _SZ_ALLOC_DEBUG
if (address != 0)
fprintf(stderr, "\nFree; count = %10d, addr = %8X", --g_allocCount, (unsigned)address);
#endif
free(address);
}
#ifdef _WIN32
void *MidAlloc(size_t size)
{
if (size == 0)
return 0;
#ifdef _SZ_ALLOC_DEBUG
fprintf(stderr, "\nAlloc_Mid %10d bytes; count = %10d", size, g_allocCountMid++);
#endif
return VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE);
}
void MidFree(void *address)
{
#ifdef _SZ_ALLOC_DEBUG
if (address != 0)
fprintf(stderr, "\nFree_Mid; count = %10d", --g_allocCountMid);
#endif
if (address == 0)
return;
VirtualFree(address, 0, MEM_RELEASE);
}
#ifndef MEM_LARGE_PAGES
#undef _7ZIP_LARGE_PAGES
#endif
#ifdef _7ZIP_LARGE_PAGES
SIZE_T g_LargePageSize = 0;
typedef SIZE_T (WINAPI *GetLargePageMinimumP)();
#endif
void SetLargePageSize()
{
#ifdef _7ZIP_LARGE_PAGES
SIZE_T size = 0;
GetLargePageMinimumP largePageMinimum = (GetLargePageMinimumP)
GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "GetLargePageMinimum");
if (largePageMinimum == 0)
return;
size = largePageMinimum();
if (size == 0 || (size & (size - 1)) != 0)
return;
g_LargePageSize = size;
#endif
}
void *BigAlloc(size_t size)
{
if (size == 0)
return 0;
#ifdef _SZ_ALLOC_DEBUG
fprintf(stderr, "\nAlloc_Big %10d bytes; count = %10d", size, g_allocCountBig++);
#endif
#ifdef _7ZIP_LARGE_PAGES
if (g_LargePageSize != 0 && g_LargePageSize <= (1 << 30) && size >= (1 << 18))
{
void *res = VirtualAlloc(0, (size + g_LargePageSize - 1) & (~(g_LargePageSize - 1)),
MEM_COMMIT | MEM_LARGE_PAGES, PAGE_READWRITE);
if (res != 0)
return res;
}
#endif
return VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE);
}
void BigFree(void *address)
{
#ifdef _SZ_ALLOC_DEBUG
if (address != 0)
fprintf(stderr, "\nFree_Big; count = %10d", --g_allocCountBig);
#endif
if (address == 0)
return;
VirtualFree(address, 0, MEM_RELEASE);
}
#endif
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
project "clzma"
kind "StaticLib"
files { "**.c", "**.h" }
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
project "ocgcore"
kind "StaticLib"
files { "**.cc", "**.cpp", "**.c", "**.h" }
configuration "not vs*"
buildoptions { "-std=gnu++0x" }
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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