Commit c61ffe7f authored by nanahira's avatar nanahira

Merge branch 'develop' into server-develop

parents 012d7ae2 ebc6d0ad
......@@ -2,7 +2,7 @@
set -x
set -o errexit
ARCHIVE_FILES=(ygopro.app cards.cdb locales fonts textures strings.conf system.conf pack)
ARCHIVE_FILES=(ygopro.app cards.cdb locales fonts sound textures strings.conf system.conf pack)
TARGET_PLATFORM=darwin
......
......@@ -2,7 +2,7 @@
set -x
set -o errexit
ARCHIVE_FILES=(ygopro.app LICENSE README.md lflist.conf strings.conf system.conf cards.cdb script textures deck single pics replay windbot bot bot.conf locales fonts pack)
ARCHIVE_FILES=(ygopro.app LICENSE README.md lflist.conf strings.conf system.conf cards.cdb script textures deck single pics replay sound windbot bot bot.conf locales fonts pack)
# TARGET_LOCALE
# ARCHIVE_SUFFIX
......
// Copyright (C) 2002-2012 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);
//! Gets the override font (if any)
virtual IGUIFont* getOverrideFont() const;
//! Get the font which is used right now for drawing
virtual IGUIFont* getActiveFont() const;
//! 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, HoverTime, FocusTime;
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__
This diff is collapsed.
// Copyright (C) 2002-2012 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_IMAGE_BUTTON_H_
#define _C_GUI_IMAGE_BUTTON_H_
#include <irrlicht.h>
#include "CGUIButton.h"
#include <IrrCompileConfig.h>
#ifdef _IRR_COMPILE_WITH_GUI_
#include <IGUIButton.h>
#include <SColor.h>
namespace irr {
namespace video {
class IVideoDriver;
class ITexture;
}
namespace gui {
class IGUISpriteBank;
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::vector2d<s32> position, core::vector2d<s32> rotationPoint, f32 rotation = 0.0f,
core::vector2df scale = core::vector2df(1.0, 1.0), bool useAlphaChannel = true, video::SColor color = 0xffffffff);
void Draw2DImageQuad(video::IVideoDriver* driver, video::ITexture* image, core::rect<s32> sourceRect,
core::position2d<s32> corner[4], bool useAlphaChannel = true, video::SColor color = 0xffffffff);
class CGUIImageButton : public CGUIButton {
core::vector2d<s32> corner[4], bool useAlphaChannel = true, video::SColor color = 0xffffffff);
class CGUIImageButton : public IGUIButton {
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 setImage(video::ITexture* image = 0);
virtual void setDrawImage(bool b);
virtual void setImageRotation(f32 r);
virtual void setImageScale(core::vector2df s);
virtual void setImageSize(core::dimension2di s);
virtual IGUIFont* getOverrideFont(void) const;
virtual IGUIFont* getActiveFont() const;
private:
static CGUIImageButton* addImageButton(IGUIEnvironment* env, const core::rect<s32>& rectangle, IGUIElement* parent, s32 id);
//! constructor
CGUIImageButton(IGUIEnvironment* environment, IGUIElement* parent,
s32 id, core::rect<s32> rectangle, bool noclip = false);
//! destructor
~CGUIImageButton() override;
//! called if an event happened.
bool OnEvent(const SEvent& event) override;
//! draws the element and its children
void draw() override;
//! sets another skin independent font. if this is set to zero, the button uses the font of the skin.
void setOverrideFont(IGUIFont* font = 0) override;
//! Gets the override font (if any)
IGUIFont* getOverrideFont() const override;
//! Get the font which is used right now for drawing
IGUIFont* getActiveFont() const override;
//! Sets an image which should be displayed on the button when it is in normal state.
void setImage(video::ITexture* image = 0) override;
//! Sets an image which should be displayed on the button when it is in normal state.
void setImage(video::ITexture* image, const core::rect<s32>& pos) override;
//! Sets an image which should be displayed on the button when it is in pressed state.
void setPressedImage(video::ITexture* image = 0) override;
//! Sets an image which should be displayed on the button when it is in pressed state.
void setPressedImage(video::ITexture* image, const core::rect<s32>& pos) override;
//! Sets the sprite bank used by the button
void setSpriteBank(IGUISpriteBank* bank = 0) override;
//! 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
*/
void setSprite(EGUI_BUTTON_STATE state, s32 index,
video::SColor color = video::SColor(255, 255, 255, 255), bool loop = false) override;
//! 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.
void setIsPushButton(bool isPushButton = true) override;
//! Checks whether the button is a push button
bool isPushButton() const override;
//! Sets the pressed state of the button if this is a pushbutton
void setPressed(bool pressed = true) override;
//! Returns if the button is currently pressed
bool isPressed() const override;
//! Sets if the button should use the skin to draw its border
void setDrawBorder(bool border = true) override;
//! Checks if the button face and border are being drawn
bool isDrawingBorder() const override;
//! Sets if the alpha channel should be used for drawing images on the button (default is false)
void setUseAlphaChannel(bool useAlphaChannel = true) override;
//! Checks if the alpha channel should be used for drawing images on the button
bool isAlphaChannelUsed() const override;
//! Sets if the button should scale the button images to fit
void setScaleImage(bool scaleImage = true) override;
//! Checks whether the button scales the used images
bool isScalingImage() const override;
//! Writes attributes of the element.
void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const override;
//! Reads attributes of the element
void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options) override;
// from ygopro
void setDrawImage(bool b);
void setImageRotation(f32 r);
void setImageScale(core::vector2df s);
void setImageSize(core::dimension2di s);
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;
bool IsPushButton;
bool Pressed;
bool UseAlphaChannel;
bool DrawBorder;
bool ScaleImage;
// from ygopro
bool isDrawImage;
bool isFixedSize;
f32 imageRotation;
......@@ -36,4 +155,6 @@ private:
}
}
#endif // _IRR_COMPILE_WITH_GUI_
#endif //_C_GUI_IMAGE_BUTTON_H_
......@@ -505,7 +505,7 @@ void CGUITTFont::drawUstring(const core::ustring& utext, const core::rect<s32>&p
// Set up some variables.
core::dimension2d<s32> textDimension;
core::position2d<s32> offset = position.UpperLeftCorner;
core::vector2d<s32> offset = position.UpperLeftCorner;
// Determine offset positions.
if (hcenter || vcenter) {
......@@ -561,7 +561,7 @@ void CGUITTFont::drawUstring(const core::ustring& utext, const core::rect<s32>&p
// Determine rendering information.
SGUITTGlyph& glyph = Glyphs[n - 1];
CGUITTGlyphPage* const page = Glyph_Pages[glyph.glyph_page];
page->render_positions.push_back(core::position2di(offset.X + offx, offset.Y + offy));
page->render_positions.push_back(core::vector2di(offset.X + offx, offset.Y + offy));
page->render_source_rects.push_back(glyph.source_rect);
Render_Map.set(glyph.glyph_page, page);
}
......@@ -832,7 +832,7 @@ video::IImage* CGUITTFont::createTextureFromChar(const uchar32_t& ch) {
// 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);
pageholder->copyTo(image, core::vector2di(0, 0), glyph.source_rect);
tex->unlock();
return image;
......
......@@ -148,6 +148,16 @@ void ClientField::Initial(int player, int deckc, int extrac) {
}
RefreshCardCountDisplay();
}
void ClientField::ResetSequence(std::vector<ClientCard*>& list, bool reset_height) {
unsigned char seq = 0;
for (auto& pcard : list) {
pcard->sequence = seq++;
if (reset_height) {
pcard->curPos.Z = 0.01f + 0.01f * pcard->sequence;
pcard->mTransform.setTranslation(pcard->curPos);
}
}
}
ClientCard* ClientField::GetCard(int controler, int location, int sequence, int sub_seq) {
std::vector<ClientCard*>* lst = 0;
bool is_xyz = (location & LOCATION_OVERLAY) != 0;
......@@ -199,16 +209,10 @@ void ClientField::AddCard(ClientCard* pcard, int controler, int location, int se
case LOCATION_DECK: {
if (sequence != 0 || deck[controler].size() == 0) {
deck[controler].push_back(pcard);
pcard->sequence = (unsigned char)(deck[controler].size() - 1);
} else {
deck[controler].push_back(0);
for(int i = deck[controler].size() - 1; i > 0; --i) {
deck[controler][i] = deck[controler][i - 1];
deck[controler][i]->sequence++;
}
deck[controler][0] = pcard;
pcard->sequence = 0;
deck[controler].insert(deck[controler].begin(), pcard);
}
ResetSequence(deck[controler], true);
pcard->is_reversed = false;
pcard->ClearData();
pcard->ClearTarget();
......@@ -217,7 +221,7 @@ void ClientField::AddCard(ClientCard* pcard, int controler, int location, int se
}
case LOCATION_HAND: {
hand[controler].push_back(pcard);
pcard->sequence = (unsigned char)(hand[controler].size() - 1);
ResetSequence(hand[controler], false);
break;
}
case LOCATION_MZONE: {
......@@ -230,30 +234,22 @@ void ClientField::AddCard(ClientCard* pcard, int controler, int location, int se
}
case LOCATION_GRAVE: {
grave[controler].push_back(pcard);
pcard->sequence = (unsigned char)(grave[controler].size() - 1);
ResetSequence(grave[controler], false);
break;
}
case LOCATION_REMOVED: {
remove[controler].push_back(pcard);
pcard->sequence = (unsigned char)(remove[controler].size() - 1);
ResetSequence(remove[controler], false);
break;
}
case LOCATION_EXTRA: {
if(extra_p_count[controler] == 0 || (pcard->position & POS_FACEUP)) {
extra[controler].push_back(pcard);
pcard->sequence = (unsigned char)(extra[controler].size() - 1);
} else {
extra[controler].push_back(0);
int p = extra[controler].size() - extra_p_count[controler] - 1;
for(int i = extra[controler].size() - 1; i > p; --i) {
extra[controler][i] = extra[controler][i - 1];
extra[controler][i]->sequence++;
extra[controler][i]->curPos += irr::core::vector3df(0, 0, 0.01f);
extra[controler][i]->mTransform.setTranslation(extra[controler][i]->curPos);
}
extra[controler][p] = pcard;
pcard->sequence = p;
size_t faceup_begin = extra[controler].size() - extra_p_count[controler];
extra[controler].insert(extra[controler].begin() + faceup_begin, pcard);
}
ResetSequence(extra[controler], true);
if (pcard->position & POS_FACEUP)
extra_p_count[controler]++;
break;
......@@ -262,73 +258,52 @@ void ClientField::AddCard(ClientCard* pcard, int controler, int location, int se
RefreshCardCountDisplay();
}
ClientCard* ClientField::RemoveCard(int controler, int location, int sequence) {
ClientCard* pcard = 0;
ClientCard* pcard = nullptr;
switch (location) {
case LOCATION_DECK: {
pcard = deck[controler][sequence];
for (size_t i = sequence; i < deck[controler].size() - 1; ++i) {
deck[controler][i] = deck[controler][i + 1];
deck[controler][i]->sequence--;
deck[controler][i]->curPos -= irr::core::vector3df(0, 0, 0.01f);
deck[controler][i]->mTransform.setTranslation(deck[controler][i]->curPos);
}
deck[controler].erase(deck[controler].end() - 1);
deck[controler].erase(deck[controler].begin() + sequence);
ResetSequence(deck[controler], true);
break;
}
case LOCATION_HAND: {
pcard = hand[controler][sequence];
for (size_t i = sequence; i < hand[controler].size() - 1; ++i) {
hand[controler][i] = hand[controler][i + 1];
hand[controler][i]->sequence--;
}
hand[controler].erase(hand[controler].end() - 1);
hand[controler].erase(hand[controler].begin() + sequence);
ResetSequence(hand[controler], false);
break;
}
case LOCATION_MZONE: {
pcard = mzone[controler][sequence];
mzone[controler][sequence] = 0;
mzone[controler][sequence] = nullptr;
break;
}
case LOCATION_SZONE: {
pcard = szone[controler][sequence];
szone[controler][sequence] = 0;
szone[controler][sequence] = nullptr;
break;
}
case LOCATION_GRAVE: {
pcard = grave[controler][sequence];
for (size_t i = sequence; i < grave[controler].size() - 1; ++i) {
grave[controler][i] = grave[controler][i + 1];
grave[controler][i]->sequence--;
grave[controler][i]->curPos -= irr::core::vector3df(0, 0, 0.01f);
grave[controler][i]->mTransform.setTranslation(grave[controler][i]->curPos);
}
grave[controler].erase(grave[controler].end() - 1);
grave[controler].erase(grave[controler].begin() + sequence);
ResetSequence(grave[controler], true);
break;
}
case LOCATION_REMOVED: {
pcard = remove[controler][sequence];
for (size_t i = sequence; i < remove[controler].size() - 1; ++i) {
remove[controler][i] = remove[controler][i + 1];
remove[controler][i]->sequence--;
remove[controler][i]->curPos -= irr::core::vector3df(0, 0, 0.01f);
remove[controler][i]->mTransform.setTranslation(remove[controler][i]->curPos);
}
remove[controler].erase(remove[controler].end() - 1);
remove[controler].erase(remove[controler].begin() + sequence);
ResetSequence(remove[controler], true);
break;
}
case LOCATION_EXTRA: {
pcard = extra[controler][sequence];
for (size_t i = sequence; i < extra[controler].size() - 1; ++i) {
extra[controler][i] = extra[controler][i + 1];
extra[controler][i]->sequence--;
extra[controler][i]->curPos -= irr::core::vector3df(0, 0, 0.01f);
extra[controler][i]->mTransform.setTranslation(extra[controler][i]->curPos);
}
extra[controler].erase(extra[controler].end() - 1);
extra[controler].erase(extra[controler].begin() + sequence);
ResetSequence(extra[controler], true);
if (pcard->position & POS_FACEUP)
extra_p_count[controler]--;
break;
}
default:
return nullptr;
}
pcard->location = 0;
RefreshCardCountDisplay();
......
......@@ -98,6 +98,7 @@ public:
~ClientField();
void Clear();
void Initial(int player, int deckc, int extrac);
void ResetSequence(std::vector<ClientCard*>& list, bool reset_height);
ClientCard* GetCard(int controler, int location, int sequence, int sub_seq = 0);
void AddCard(ClientCard* pcard, int controler, int location, int sequence);
ClientCard* RemoveCard(int controler, int location, int sequence);
......
......@@ -3,6 +3,9 @@
#define _IRR_STATIC_LIB_
#define IRR_COMPILE_WITH_DX9_DEV_PACK
#include <cerrno>
#ifdef _WIN32
#define NOMINMAX
......@@ -22,7 +25,6 @@
#else //_WIN32
#include <errno.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
......@@ -50,7 +52,7 @@ inline int _wtoi(const wchar_t * str){
}
#endif
#include <stdio.h>
#include <cstdio>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
......@@ -63,7 +65,7 @@ inline int myswprintf(wchar_t(&buf)[N], const wchar_t* fmt, TR... args) {
return std::swprintf(buf, N, fmt, args...);
}
inline FILE* myfopen(const wchar_t* filename, const char* mode) {
inline FILE* mywfopen(const wchar_t* filename, const char* mode) {
FILE* fp{};
#ifdef _WIN32
wchar_t wmode[20]{};
......@@ -72,7 +74,7 @@ inline FILE* myfopen(const wchar_t* filename, const char* mode) {
#else
char fname[1024]{};
BufferIO::EncodeUTF8(filename, fname);
fp = fopen(fname, mode);
fp = std::fopen(fname, mode);
#endif
return fp;
}
......
#include "data_manager.h"
#include "game.h"
#include <stdio.h>
#if !defined(YGOPRO_SERVER_MODE) || defined(SERVER_ZIP_SUPPORT)
#include "spmemvfs/spmemvfs.h"
#endif
......@@ -132,14 +131,14 @@ bool DataManager::LoadDB(const wchar_t* wfile) {
}
#ifndef YGOPRO_SERVER_MODE
bool DataManager::LoadStrings(const char* file) {
FILE* fp = fopen(file, "r");
FILE* fp = std::fopen(file, "r");
if(!fp)
return false;
char linebuf[TEXT_LINE_SIZE]{};
while(fgets(linebuf, sizeof linebuf, fp)) {
while(std::fgets(linebuf, sizeof linebuf, fp)) {
ReadStringConfLine(linebuf);
}
fclose(fp);
std::fclose(fp);
return true;
}
bool DataManager::LoadStrings(irr::io::IReadFile* reader) {
......@@ -163,26 +162,26 @@ void DataManager::ReadStringConfLine(const char* linebuf) {
char strbuf[TEXT_LINE_SIZE]{};
int value{};
wchar_t strBuffer[4096]{};
if (sscanf(linebuf, "!%63s", strbuf) != 1)
if (std::sscanf(linebuf, "!%63s", strbuf) != 1)
return;
if(!std::strcmp(strbuf, "system")) {
if (sscanf(&linebuf[7], "%d %240[^\n]", &value, strbuf) != 2)
if (std::sscanf(&linebuf[7], "%d %240[^\n]", &value, strbuf) != 2)
return;
BufferIO::DecodeUTF8(strbuf, strBuffer);
_sysStrings[value] = strBuffer;
} else if(!std::strcmp(strbuf, "victory")) {
if (sscanf(&linebuf[8], "%x %240[^\n]", &value, strbuf) != 2)
if (std::sscanf(&linebuf[8], "%x %240[^\n]", &value, strbuf) != 2)
return;
BufferIO::DecodeUTF8(strbuf, strBuffer);
_victoryStrings[value] = strBuffer;
} else if(!std::strcmp(strbuf, "counter")) {
if (sscanf(&linebuf[8], "%x %240[^\n]", &value, strbuf) != 2)
if (std::sscanf(&linebuf[8], "%x %240[^\n]", &value, strbuf) != 2)
return;
BufferIO::DecodeUTF8(strbuf, strBuffer);
_counterStrings[value] = strBuffer;
} else if(!std::strcmp(strbuf, "setname")) {
//using tab for comment
if (sscanf(&linebuf[8], "%x %240[^\t\n]", &value, strbuf) != 2)
if (std::sscanf(&linebuf[8], "%x %240[^\t\n]", &value, strbuf) != 2)
return;
BufferIO::DecodeUTF8(strbuf, strBuffer);
_setnameStrings[value] = strBuffer;
......@@ -448,7 +447,7 @@ unsigned char* DataManager::ScriptReaderEx(const char* script_name, int* slen) {
}
unsigned char* DataManager::ScriptReaderExSingle(const char* path, const char* script_name, int* slen, int pre_len, unsigned int use_irr) {
char sname[256];
snprintf(sname, sizeof sname, "%s%s", path, script_name + pre_len); //default script name: ./script/c%d.lua
std::snprintf(sname, sizeof sname, "%s%s", path, script_name + pre_len); //default script name: ./script/c%d.lua
#if !defined(YGOPRO_SERVER_MODE) || defined(SERVER_ZIP_SUPPORT)
if (use_irr) {
return ReadScriptFromIrrFS(sname, slen);
......@@ -478,7 +477,7 @@ unsigned char* DataManager::ReadScriptFromIrrFS(const char* script_name, int* sl
unsigned char* DataManager::ReadScriptFromFile(const char* script_name, int* slen) {
wchar_t fname[256]{};
BufferIO::DecodeUTF8(script_name, fname);
FILE* fp = myfopen(fname, "rb");
FILE* fp = mywfopen(fname, "rb");
if (!fp)
return nullptr;
size_t len = std::fread(scriptBuffer, 1, sizeof scriptBuffer, fp);
......
......@@ -46,6 +46,14 @@ static inline bool havePopupWindow() {
return mainGame->wQuery->isVisible() || mainGame->wCategories->isVisible() || mainGame->wLinkMarks->isVisible() || mainGame->wDeckManage->isVisible() || mainGame->wDMQuery->isVisible();
}
static inline void get_deck_file(wchar_t* ret) {
deckManager.GetDeckFile(ret, mainGame->cbDBCategory->getSelected(), mainGame->cbDBCategory->getText(), mainGame->cbDBDecks->getText());
}
static inline void load_current_deck(irr::gui::IGUIComboBox* cbCategory, irr::gui::IGUIComboBox* cbDeck) {
deckManager.LoadCurrentDeck(cbCategory->getSelected(), cbCategory->getText(), cbDeck->getText());
}
void DeckBuilder::Initialize() {
mainGame->is_building = true;
mainGame->is_siding = false;
......@@ -164,7 +172,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
if(sel == -1)
break;
wchar_t filepath[256];
deckManager.GetDeckFile(filepath, mainGame->cbDBCategory, mainGame->cbDBDecks);
get_deck_file(filepath);
if(deckManager.SaveDeck(deckManager.current_deck, filepath)) {
mainGame->stACMessage->setText(dataManager.GetSysString(1335));
mainGame->PopupElement(mainGame->wACMessage, 20);
......@@ -523,7 +531,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
int decksel = mainGame->lstDecks->getSelected();
const wchar_t* catename = mainGame->lstCategories->getListItem(catesel);
wchar_t oldfilepath[256];
deckManager.GetDeckFile(oldfilepath, mainGame->cbDBCategory, mainGame->cbDBDecks);
get_deck_file(oldfilepath);
const wchar_t* newdeckname = mainGame->ebDMName->getText();
wchar_t newfilepath[256];
if(catesel == 2) {
......@@ -555,7 +563,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
case BUTTON_DELETE_DECK_DM: {
int decksel = mainGame->lstDecks->getSelected();
wchar_t filepath[256];
deckManager.GetDeckFile(filepath, mainGame->cbDBCategory, mainGame->cbDBDecks);
get_deck_file(filepath);
if(deckManager.DeleteDeck(filepath)) {
mainGame->lstDecks->removeItem(decksel);
mainGame->cbDBDecks->removeItem(decksel);
......@@ -566,7 +574,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
if(decksel != -1) {
mainGame->lstDecks->setSelected(decksel);
mainGame->cbDBDecks->setSelected(decksel);
deckManager.LoadCurrentDeck(mainGame->cbDBCategory, mainGame->cbDBDecks);
load_current_deck(mainGame->cbDBCategory, mainGame->cbDBDecks);
}
RefreshReadonly(prev_category);
prev_deck = decksel;
......@@ -585,7 +593,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
wchar_t deckname[256];
BufferIO::CopyWideString(olddeckname, deckname);
wchar_t oldfilepath[256];
deckManager.GetDeckFile(oldfilepath, mainGame->cbDBCategory, mainGame->cbDBDecks);
get_deck_file(oldfilepath);
wchar_t newfilepath[256];
if(oldcatesel != 2 && newcatesel == 0) {
myswprintf(newfilepath, L"./deck/%ls.ydk", deckname);
......@@ -694,7 +702,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
break;
}
case BUTTON_SIDE_RELOAD: {
deckManager.LoadCurrentDeck(mainGame->cbCategorySelect, mainGame->cbDeckSelect);
load_current_deck(mainGame->cbCategorySelect, mainGame->cbDeckSelect);
break;
}
case BUTTON_BIG_CARD_ORIG_SIZE: {
......@@ -732,7 +740,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
int sel = prev_sel;
mainGame->cbDBDecks->setSelected(sel);
wchar_t filepath[256];
deckManager.GetDeckFile(filepath, mainGame->cbDBCategory, mainGame->cbDBDecks);
get_deck_file(filepath);
if(deckManager.DeleteDeck(filepath)) {
mainGame->cbDBDecks->removeItem(sel);
int count = mainGame->cbDBDecks->getItemCount();
......@@ -740,7 +748,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
sel = count - 1;
mainGame->cbDBDecks->setSelected(sel);
if(sel != -1)
deckManager.LoadCurrentDeck(mainGame->cbDBCategory, mainGame->cbDBDecks);
load_current_deck(mainGame->cbDBCategory, mainGame->cbDBDecks);
mainGame->stACMessage->setText(dataManager.GetSysString(1338));
mainGame->PopupElement(mainGame->wACMessage, 20);
prev_deck = sel;
......@@ -754,7 +762,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
ChangeCategory(catesel);
} else if(prev_operation == COMBOBOX_DBDECKS) {
int decksel = mainGame->cbDBDecks->getSelected();
deckManager.LoadCurrentDeck(mainGame->cbDBCategory, mainGame->cbDBDecks);
load_current_deck(mainGame->cbDBCategory, mainGame->cbDBDecks);
prev_deck = decksel;
is_modified = false;
} else if(prev_operation == BUTTON_MANAGE_DECK) {
......@@ -871,7 +879,7 @@ bool DeckBuilder::OnEvent(const irr::SEvent& event) {
}
int decksel = mainGame->cbDBDecks->getSelected();
if(decksel >= 0) {
deckManager.LoadCurrentDeck(mainGame->cbDBCategory, mainGame->cbDBDecks);
load_current_deck(mainGame->cbDBCategory, mainGame->cbDBDecks);
}
prev_deck = decksel;
is_modified = false;
......@@ -1259,7 +1267,7 @@ void DeckBuilder::GetHoveredCard() {
irr::gui::IGUIElement* root = mainGame->env->getRootGUIElement();
if(root->getElementFromPoint(mouse_pos) != root)
return;
position2di pos = mainGame->ResizeReverse(mouse_pos.X, mouse_pos.Y);
irr::core::vector2di pos = mainGame->ResizeReverse(mouse_pos.X, mouse_pos.Y);
int x = pos.X;
int y = pos.Y;
is_lastcard = 0;
......@@ -1674,7 +1682,7 @@ void DeckBuilder::ChangeCategory(int catesel) {
mainGame->RefreshDeck(mainGame->cbDBCategory, mainGame->cbDBDecks);
mainGame->cbDBDecks->setSelected(0);
RefreshReadonly(catesel);
deckManager.LoadCurrentDeck(mainGame->cbDBCategory, mainGame->cbDBDecks);
load_current_deck(mainGame->cbDBCategory, mainGame->cbDBDecks);
is_modified = false;
prev_category = catesel;
prev_deck = 0;
......
#ifndef DECK_CON_H
#define DECK_CON_H
#include "config.h"
#include <unordered_map>
#include <vector>
#include <irrlicht.h>
#include "data_manager.h"
#include "../ocgcore/mtrandom.h"
......@@ -28,7 +28,7 @@ public:
void ChangeCategory(int catesel);
void ShowDeckManage();
void ShowBigCard(int code, float zoom);
void ZoomBigCard(s32 centerx = -1, s32 centery = -1);
void ZoomBigCard(irr::s32 centerx = -1, irr::s32 centery = -1);
void CloseBigCard();
bool CardNameContains(const wchar_t *haystack, const wchar_t *needle);
......@@ -56,7 +56,7 @@ public:
unsigned int filter_scl{};
unsigned int filter_marks{};
int filter_lm{};
position2di mouse_pos;
irr::core::vector2di mouse_pos;
int hovered_code{};
int hovered_pos{};
int hovered_seq{ -1 };
......@@ -74,7 +74,7 @@ public:
code_pointer draging_pointer;
int prev_category{};
int prev_deck{};
s32 prev_operation{};
irr::s32 prev_operation{};
int prev_sel{ -1 };
bool is_modified{};
bool readonly{};
......
#include "deck_manager.h"
#include "game.h"
#include "myfilesystem.h"
#include "network.h"
#include "game.h"
#include "base64.h"
namespace ygo {
......@@ -13,42 +13,39 @@ DeckManager deckManager;
void DeckManager::LoadLFListSingle(const char* path) {
auto cur = _lfList.rend();
FILE* fp = fopen(path, "r");
FILE* fp = std::fopen(path, "r");
char linebuf[256]{};
wchar_t strBuffer[256]{};
if(fp) {
while(fgets(linebuf, 256, fp)) {
while(std::fgets(linebuf, sizeof linebuf, fp)) {
if(linebuf[0] == '#')
continue;
if(linebuf[0] == '!') {
int sa = BufferIO::DecodeUTF8(&linebuf[1], strBuffer);
while(strBuffer[sa - 1] == L'\r' || strBuffer[sa - 1] == L'\n' )
sa--;
strBuffer[sa] = 0;
auto len = std::strcspn(linebuf, "\r\n");
linebuf[len] = 0;
BufferIO::DecodeUTF8(&linebuf[1], strBuffer);
LFList newlist;
newlist.listName = strBuffer;
newlist.hash = 0x7dfcee6a;
_lfList.push_back(newlist);
cur = _lfList.rbegin();
cur->listName = strBuffer;
cur->hash = 0x7dfcee6a;
continue;
}
if(linebuf[0] == 0)
if (cur == _lfList.rend())
continue;
int code = 0;
int count = -1;
if (sscanf(linebuf, "%d %d", &code, &count) != 2)
if (std::sscanf(linebuf, "%9d%*[ ]%9d", &code, &count) != 2)
continue;
if (code <= 0 || code > MAX_CARD_ID)
continue;
if (count < 0 || count > 2)
continue;
if (cur == _lfList.rend())
continue;
unsigned int hcode = code;
cur->content[code] = count;
cur->hash = cur->hash ^ ((hcode << 18) | (hcode >> 14)) ^ ((hcode << (27 + count)) | (hcode >> (5 - count)));
}
fclose(fp);
std::fclose(fp);
}
}
void DeckManager::LoadLFList() {
......@@ -197,25 +194,29 @@ int DeckManager::LoadDeck(Deck& deck, int* dbuf, int mainc, int sidec, bool is_p
}
#ifndef YGOPRO_SERVER_MODE
int DeckManager::LoadDeck(Deck& deck, std::istringstream& deckStream, bool is_packlist) {
int ct = 0, mainc = 0, sidec = 0, code = 0;
size_t ct = 0;
int mainc = 0, sidec = 0, code = 0;
int cardlist[PACK_MAX_SIZE]{};
bool is_side = false;
std::string linebuf;
while (std::getline(deckStream, linebuf, '\n') && ct < (int)(sizeof cardlist / sizeof cardlist[0])) {
while (std::getline(deckStream, linebuf, '\n') && ct < (sizeof cardlist / sizeof cardlist[0])) {
if (linebuf[0] == '!') {
is_side = true;
continue;
}
if (linebuf[0] < '0' || linebuf[0] > '9')
continue;
code = std::stoi(linebuf);
errno = 0;
code = strtol(linebuf.c_str(), nullptr, 10);
if (errno == ERANGE)
continue;
cardlist[ct++] = code;
if (is_side)
++sidec;
else
++mainc;
}
return LoadDeck(current_deck, cardlist, mainc, sidec, is_packlist);
return LoadDeck(deck, cardlist, mainc, sidec, is_packlist);
}
#endif
bool DeckManager::LoadSide(Deck& deck, int* dbuf, int mainc, int sidec) {
......@@ -267,12 +268,11 @@ void DeckManager::GetCategoryPath(wchar_t* ret, int index, const wchar_t* text)
}
BufferIO::CopyWStr(catepath, ret, 256);
}
void DeckManager::GetDeckFile(wchar_t* ret, irr::gui::IGUIComboBox* cbCategory, irr::gui::IGUIComboBox* cbDeck) {
void DeckManager::GetDeckFile(wchar_t* ret, int category_index, const wchar_t* category_name, const wchar_t* deckname) {
wchar_t filepath[256];
wchar_t catepath[256];
const wchar_t* deckname = cbDeck->getItem(cbDeck->getSelected());
if(deckname != nullptr) {
GetCategoryPath(catepath, cbCategory->getSelected(), cbCategory->getText());
GetCategoryPath(catepath, category_index, category_name);
myswprintf(filepath, L"%ls/%ls.ydk", catepath, deckname);
BufferIO::CopyWStr(filepath, ret, 256);
}
......@@ -281,16 +281,16 @@ void DeckManager::GetDeckFile(wchar_t* ret, irr::gui::IGUIComboBox* cbCategory,
}
}
FILE* DeckManager::OpenDeckFile(const wchar_t* file, const char* mode) {
FILE* fp = myfopen(file, mode);
FILE* fp = mywfopen(file, mode);
return fp;
}
IReadFile* DeckManager::OpenDeckReader(const wchar_t* file) {
irr::io::IReadFile* DeckManager::OpenDeckReader(const wchar_t* file) {
#ifdef _WIN32
IReadFile* reader = DataManager::FileSystem->createAndOpenFile(file);
auto reader = DataManager::FileSystem->createAndOpenFile(file);
#else
char file2[256];
BufferIO::EncodeUTF8(file, file2);
IReadFile* reader = DataManager::FileSystem->createAndOpenFile(file2);
auto reader = DataManager::FileSystem->createAndOpenFile(file2);
#endif
return reader;
}
......@@ -319,10 +319,10 @@ bool DeckManager::LoadCurrentDeck(const wchar_t* file, bool is_packlist) {
LoadDeck(current_deck, deckStream, is_packlist);
return true; // the above LoadDeck has return value but we ignore it here for now
}
bool DeckManager::LoadCurrentDeck(irr::gui::IGUIComboBox* cbCategory, irr::gui::IGUIComboBox* cbDeck) {
bool DeckManager::LoadCurrentDeck(int category_index, const wchar_t* category_name, const wchar_t* deckname) {
wchar_t filepath[256];
GetDeckFile(filepath, cbCategory, cbDeck);
bool is_packlist = cbCategory->getSelected() == 0;
GetDeckFile(filepath, category_index, category_name, deckname);
bool is_packlist = (category_index == 0);
bool res = LoadCurrentDeck(filepath, is_packlist);
if (res && mainGame->is_building)
mainGame->deckBuilder.RefreshPackListScroll();
......@@ -334,16 +334,16 @@ bool DeckManager::SaveDeck(Deck& deck, const wchar_t* file) {
FILE* fp = OpenDeckFile(file, "w");
if(!fp)
return false;
fprintf(fp, "#created by ...\n#main\n");
std::fprintf(fp, "#created by ...\n#main\n");
for(size_t i = 0; i < deck.main.size(); ++i)
fprintf(fp, "%d\n", deck.main[i]->first);
fprintf(fp, "#extra\n");
std::fprintf(fp, "%d\n", deck.main[i]->first);
std::fprintf(fp, "#extra\n");
for(size_t i = 0; i < deck.extra.size(); ++i)
fprintf(fp, "%d\n", deck.extra[i]->first);
fprintf(fp, "!side\n");
std::fprintf(fp, "%d\n", deck.extra[i]->first);
std::fprintf(fp, "!side\n");
for(size_t i = 0; i < deck.side.size(); ++i)
fprintf(fp, "%d\n", deck.side[i]->first);
fclose(fp);
std::fprintf(fp, "%d\n", deck.side[i]->first);
std::fclose(fp);
return true;
}
bool DeckManager::DeleteDeck(const wchar_t* file) {
......@@ -427,26 +427,26 @@ bool DeckManager::SaveDeckBuffer(const int deckbuf[], const wchar_t* name) {
int it = 0;
const int mainc = deckbuf[it];
++it;
fprintf(fp, "#created by ...\n#main\n");
std::fprintf(fp, "#created by ...\n#main\n");
for (int i = 0; i < mainc; ++i) {
fprintf(fp, "%d\n", deckbuf[it]);
std::fprintf(fp, "%d\n", deckbuf[it]);
++it;
}
const int extrac = deckbuf[it];
++it;
fprintf(fp, "#extra\n");
std::fprintf(fp, "#extra\n");
for (int i = 0; i < extrac; ++i) {
fprintf(fp, "%d\n", deckbuf[it]);
std::fprintf(fp, "%d\n", deckbuf[it]);
++it;
}
const int sidec = deckbuf[it];
++it;
fprintf(fp, "!side\n");
std::fprintf(fp, "!side\n");
for (int i = 0; i < sidec; ++i) {
fprintf(fp, "%d\n", deckbuf[it]);
std::fprintf(fp, "%d\n", deckbuf[it]);
++it;
}
fclose(fp);
std::fclose(fp);
return true;
}
#endif //YGOPRO_SERVER_MODE
......
#ifndef DECKMANAGER_H
#define DECKMANAGER_H
#include "config.h"
#include "data_manager.h"
#include <unordered_map>
#include <vector>
#include <sstream>
#include "data_manager.h"
#ifndef YGOPRO_MAX_DECK
#define YGOPRO_MAX_DECK 60
......@@ -39,7 +38,7 @@ struct Deck {
std::vector<code_pointer> main;
std::vector<code_pointer> extra;
std::vector<code_pointer> side;
Deck() {}
Deck() = default;
Deck(const Deck& ndeck) {
main = ndeck.main;
extra = ndeck.extra;
......@@ -71,11 +70,11 @@ public:
#ifndef YGOPRO_SERVER_MODE
int LoadDeck(Deck& deck, std::istringstream& deckStream, bool is_packlist = false);
void GetCategoryPath(wchar_t* ret, int index, const wchar_t* text);
void GetDeckFile(wchar_t* ret, irr::gui::IGUIComboBox* cbCategory, irr::gui::IGUIComboBox* cbDeck);
void GetDeckFile(wchar_t* ret, int category_index, const wchar_t* category_name, const wchar_t* deckname);
FILE* OpenDeckFile(const wchar_t* file, const char* mode);
IReadFile* OpenDeckReader(const wchar_t* file);
irr::io::IReadFile* OpenDeckReader(const wchar_t* file);
bool LoadCurrentDeck(const wchar_t* file, bool is_packlist = false);
bool LoadCurrentDeck(irr::gui::IGUIComboBox* cbCategory, irr::gui::IGUIComboBox* cbDeck);
bool LoadCurrentDeck(int category_index, const wchar_t* category_name, const wchar_t* deckname);
bool SaveDeck(Deck& deck, const wchar_t* file);
bool DeleteDeck(const wchar_t* file);
wchar_t DeckFormatBuffer[128];
......
......@@ -947,15 +947,15 @@ void Game::DrawSpec() {
float mul = xScale;
if(xScale > yScale)
mul = yScale;
core::position2d<s32> corner[4];
irr::core::vector2d<s32> corner[4];
float y = sin(showcarddif * 3.1415926f / 180.0f) * CARD_IMG_HEIGHT * mul;
s32 winx = midx * xScale + (574 - midx) * mul;
s32 winx2 = midx * xScale + (751 - midx) * mul;
s32 winy = midy * yScale + (404 - midy) * mul;
corner[0] = core::position2d<s32>(winx - (CARD_IMG_HEIGHT * mul - y) * 0.3f, winy - y);
corner[1] = core::position2d<s32>(winx2 + (CARD_IMG_HEIGHT * mul - y) * 0.3f, winy - y);
corner[2] = core::position2d<s32>(winx, winy);
corner[3] = core::position2d<s32>(winx2, winy);
corner[0] = irr::core::vector2d<s32>(winx - (CARD_IMG_HEIGHT * mul - y) * 0.3f, winy - y);
corner[1] = irr::core::vector2d<s32>(winx2 + (CARD_IMG_HEIGHT * mul - y) * 0.3f, winy - y);
corner[2] = irr::core::vector2d<s32>(winx, winy);
corner[3] = irr::core::vector2d<s32>(winx2, winy);
irr::gui::Draw2DImageQuad(driver, imageManager.GetTexture(showcardcode, true), ResizeFit(0, 0, CARD_IMG_WIDTH, CARD_IMG_HEIGHT), corner);
showcardp++;
showcarddif += 9;
......@@ -969,8 +969,8 @@ void Game::DrawSpec() {
}
case 100: {
if(showcardp < 60) {
driver->draw2DImage(imageManager.tHand[(showcardcode >> 16) & 0x3], position2di((615 + 44.5) * xScale - 44.5, (showcarddif + 64) * yScale - 64));
driver->draw2DImage(imageManager.tHand[showcardcode & 0x3], position2di((615 + 44.5) * xScale - 44.5, (540 - showcarddif + 64) * yScale - 64));
driver->draw2DImage(imageManager.tHand[(showcardcode >> 16) & 0x3], irr::core::vector2di((615 + 44.5) * xScale - 44.5, (showcarddif + 64) * yScale - 64));
driver->draw2DImage(imageManager.tHand[showcardcode & 0x3], irr::core::vector2di((615 + 44.5) * xScale - 44.5, (540 - showcarddif + 64) * yScale - 64));
float dy = -0.333333f * showcardp + 10;
showcardp++;
if(showcardp < 30)
......@@ -1096,7 +1096,7 @@ void Game::DrawSpec() {
recti rectloc(x, y - chatRectY - h, x + 2 + w, y - chatRectY);
recti msgloc(x, y - chatRectY - h, x - 4, y - chatRectY);
recti shadowloc = msgloc + position2di(1, 1);
recti shadowloc = msgloc + irr::core::vector2di(1, 1);
driver->draw2DRectangle(rectloc, 0xa0000000, 0xa0000000, 0xa0000000, 0xa0000000);
guiFont->drawUstring(msg, msgloc, 0xff000000, false, false);
......@@ -1117,7 +1117,7 @@ void Game::ShowElement(irr::gui::IGUIElement * win, int autoframe) {
for(auto fit = fadingList.begin(); fit != fadingList.end(); ++fit)
if(win == fit->guiFading && win != wOptions && win != wANNumber) // the size of wOptions is always setted by ClientField::ShowSelectOption before showing it
fu.fadingSize = fit->fadingSize;
irr::core::position2di center = fu.fadingSize.getCenter();
irr::core::vector2di center = fu.fadingSize.getCenter();
fu.fadingDiff.X = fu.fadingSize.getWidth() / 10;
fu.fadingDiff.Y = (fu.fadingSize.getHeight() - 4) / 10;
fu.fadingUL = center;
......@@ -1202,7 +1202,7 @@ void Game::WaitFrameSignal(int frame) {
signalFrame = (gameConf.quick_animation && frame >= 12) ? 12 : frame;
frameSignal.Wait();
}
void Game::DrawThumb(code_pointer cp, position2di pos, const std::unordered_map<int,int>* lflist, bool drag) {
void Game::DrawThumb(code_pointer cp, irr::core::vector2di pos, const std::unordered_map<int,int>* lflist, bool drag) {
int code = cp->first;
int lcode = cp->second.alias;
if(lcode == 0)
......@@ -1294,7 +1294,7 @@ void Game::DrawDeckBd() {
int padding = scrPackCards->getPos() * lx;
for(int i = 0; i < mainsize - padding && i < 7 * lx; ++i) {
int j = i + padding;
DrawThumb(deckManager.current_deck.main[j], position2di(314 + (i % lx) * dx, 164 + (i / lx) * dy), deckBuilder.filterList);
DrawThumb(deckManager.current_deck.main[j], irr::core::vector2di(314 + (i % lx) * dx, 164 + (i / lx) * dy), deckBuilder.filterList);
if(deckBuilder.hovered_pos == 1 && deckBuilder.hovered_seq == j)
driver->draw2DRectangleOutline(Resize(313 + (i % lx) * dx, 163 + (i / lx) * dy, 359 + (i % lx) * dx, 228 + (i / lx) * dy));
}
......@@ -1347,7 +1347,7 @@ void Game::DrawDeckBd() {
dx = 436.0f / 9;
else dx = 436.0f / (deckManager.current_deck.extra.size() - 1);
for(size_t i = 0; i < deckManager.current_deck.extra.size(); ++i) {
DrawThumb(deckManager.current_deck.extra[i], position2di(314 + i * dx, 466), deckBuilder.filterList);
DrawThumb(deckManager.current_deck.extra[i], irr::core::vector2di(314 + i * dx, 466), deckBuilder.filterList);
if(deckBuilder.hovered_pos == 2 && deckBuilder.hovered_seq == (int)i)
driver->draw2DRectangleOutline(Resize(313 + i * dx, 465, 359 + i * dx, 531));
}
......@@ -1379,7 +1379,7 @@ void Game::DrawDeckBd() {
dx = 436.0f / 9;
else dx = 436.0f / (deckManager.current_deck.side.size() - 1);
for(size_t i = 0; i < deckManager.current_deck.side.size(); ++i) {
DrawThumb(deckManager.current_deck.side[i], position2di(314 + i * dx, 564), deckBuilder.filterList);
DrawThumb(deckManager.current_deck.side[i], irr::core::vector2di(314 + i * dx, 564), deckBuilder.filterList);
if(deckBuilder.hovered_pos == 3 && deckBuilder.hovered_seq == (int)i)
driver->draw2DRectangleOutline(Resize(313 + i * dx, 563, 359 + i * dx, 629));
}
......@@ -1406,7 +1406,7 @@ void Game::DrawDeckBd() {
}
if(deckBuilder.hovered_pos == 4 && deckBuilder.hovered_seq == (int)i)
driver->draw2DRectangle(0x80000000, Resize(806, 164 + i * 66, 1019, 230 + i * 66));
DrawThumb(ptr, position2di(810, 165 + i * 66), deckBuilder.filterList);
DrawThumb(ptr, irr::core::vector2di(810, 165 + i * 66), deckBuilder.filterList);
const wchar_t* availBuffer = L"";
if ((ptr->second.ot & AVAIL_OCGTCG) == AVAIL_OCG)
availBuffer = L" [OCG]";
......@@ -1456,7 +1456,7 @@ void Game::DrawDeckBd() {
}
}
if(deckBuilder.is_draging) {
DrawThumb(deckBuilder.draging_pointer, position2di(deckBuilder.dragx - CARD_THUMB_WIDTH / 2 * mainGame->xScale, deckBuilder.dragy - CARD_THUMB_HEIGHT / 2 * mainGame->yScale), deckBuilder.filterList, true);
DrawThumb(deckBuilder.draging_pointer, irr::core::vector2di(deckBuilder.dragx - CARD_THUMB_WIDTH / 2 * mainGame->xScale, deckBuilder.dragy - CARD_THUMB_HEIGHT / 2 * mainGame->yScale), deckBuilder.filterList, true);
}
}
}
......@@ -1090,8 +1090,8 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
if(!mainGame->dInfo.isStarted)
break;
hovered_location = 0;
position2di pos = mainGame->ResizeReverse(event.MouseInput.X, event.MouseInput.Y);
position2di mousepos(event.MouseInput.X, event.MouseInput.Y);
irr::core::vector2di pos = mainGame->ResizeReverse(event.MouseInput.X, event.MouseInput.Y);
irr::core::vector2di mousepos(event.MouseInput.X, event.MouseInput.Y);
s32 x = pos.X;
s32 y = pos.Y;
if(x < 300)
......@@ -1513,8 +1513,8 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
if(!mainGame->dInfo.isStarted)
break;
bool should_show_tip = false;
position2di pos = mainGame->ResizeReverse(event.MouseInput.X, event.MouseInput.Y);
position2di mousepos = position2di(event.MouseInput.X, event.MouseInput.Y);
irr::core::vector2di pos = mainGame->ResizeReverse(event.MouseInput.X, event.MouseInput.Y);
irr::core::vector2di mousepos = irr::core::vector2di(event.MouseInput.X, event.MouseInput.Y);
s32 x = pos.X;
s32 y = pos.Y;
wchar_t formatBuffer[2048];
......@@ -1571,7 +1571,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
if(mainGame->stTip->isVisible()) {
should_show_tip = true;
irr::core::recti tpos = mainGame->stTip->getRelativePosition();
mainGame->stTip->setRelativePosition(irr::core::position2di(mousepos.X - tpos.getWidth() - 10, mcard ? mousepos.Y - tpos.getHeight() - 10 : y + 10));
mainGame->stTip->setRelativePosition(irr::core::vector2di(mousepos.X - tpos.getWidth() - 10, mcard ? mousepos.Y - tpos.getHeight() - 10 : y + 10));
}
}
if(mcard != hovered_card) {
......@@ -2143,7 +2143,7 @@ bool ClientField::OnCommonEvent(const irr::SEvent& event) {
void ClientField::GetHoverField(int x, int y) {
irr::core::recti sfRect(430, 504, 875, 600);
irr::core::recti ofRect(531, 135, 800, 191);
irr::core::position2di pos(x, y);
irr::core::vector2di pos(x, y);
int rule = (mainGame->dInfo.duel_rule >= 4) ? 1 : 0;
if(sfRect.isPointInside(pos)) {
int hc = hand[0].size();
......@@ -2380,22 +2380,22 @@ void ClientField::ShowMenu(int flag, int x, int y) {
int offset = mainGame->gameConf.resize_popup_menu ? ((mainGame->yScale >= 0.666) ? 21 * mainGame->yScale : 14) : 21;
if(flag & COMMAND_ACTIVATE) {
mainGame->btnActivate->setVisible(true);
mainGame->btnActivate->setRelativePosition(position2di(1, height));
mainGame->btnActivate->setRelativePosition(irr::core::vector2di(1, height));
height += offset;
} else mainGame->btnActivate->setVisible(false);
if(flag & COMMAND_SUMMON) {
mainGame->btnSummon->setVisible(true);
mainGame->btnSummon->setRelativePosition(position2di(1, height));
mainGame->btnSummon->setRelativePosition(irr::core::vector2di(1, height));
height += offset;
} else mainGame->btnSummon->setVisible(false);
if(flag & COMMAND_SPSUMMON) {
mainGame->btnSPSummon->setVisible(true);
mainGame->btnSPSummon->setRelativePosition(position2di(1, height));
mainGame->btnSPSummon->setRelativePosition(irr::core::vector2di(1, height));
height += offset;
} else mainGame->btnSPSummon->setVisible(false);
if(flag & COMMAND_MSET) {
mainGame->btnMSet->setVisible(true);
mainGame->btnMSet->setRelativePosition(position2di(1, height));
mainGame->btnMSet->setRelativePosition(irr::core::vector2di(1, height));
height += offset;
} else mainGame->btnMSet->setVisible(false);
if(flag & COMMAND_SSET) {
......@@ -2404,7 +2404,7 @@ void ClientField::ShowMenu(int flag, int x, int y) {
else
mainGame->btnSSet->setText(dataManager.GetSysString(1159));
mainGame->btnSSet->setVisible(true);
mainGame->btnSSet->setRelativePosition(position2di(1, height));
mainGame->btnSSet->setRelativePosition(irr::core::vector2di(1, height));
height += offset;
} else mainGame->btnSSet->setVisible(false);
if(flag & COMMAND_REPOS) {
......@@ -2415,27 +2415,27 @@ void ClientField::ShowMenu(int flag, int x, int y) {
else
mainGame->btnRepos->setText(dataManager.GetSysString(1156));
mainGame->btnRepos->setVisible(true);
mainGame->btnRepos->setRelativePosition(position2di(1, height));
mainGame->btnRepos->setRelativePosition(irr::core::vector2di(1, height));
height += offset;
} else mainGame->btnRepos->setVisible(false);
if(flag & COMMAND_ATTACK) {
mainGame->btnAttack->setVisible(true);
mainGame->btnAttack->setRelativePosition(position2di(1, height));
mainGame->btnAttack->setRelativePosition(irr::core::vector2di(1, height));
height += offset;
} else mainGame->btnAttack->setVisible(false);
if(flag & COMMAND_LIST) {
mainGame->btnShowList->setVisible(true);
mainGame->btnShowList->setRelativePosition(position2di(1, height));
mainGame->btnShowList->setRelativePosition(irr::core::vector2di(1, height));
height += offset;
} else mainGame->btnShowList->setVisible(false);
if(flag & COMMAND_OPERATION) {
mainGame->btnOperation->setVisible(true);
mainGame->btnOperation->setRelativePosition(position2di(1, height));
mainGame->btnOperation->setRelativePosition(irr::core::vector2di(1, height));
height += offset;
} else mainGame->btnOperation->setVisible(false);
if(flag & COMMAND_RESET) {
mainGame->btnReset->setVisible(true);
mainGame->btnReset->setRelativePosition(position2di(1, height));
mainGame->btnReset->setRelativePosition(irr::core::vector2di(1, height));
height += offset;
} else mainGame->btnReset->setVisible(false);
panel = mainGame->wCmdMenu;
......
This diff is collapsed.
......@@ -38,6 +38,7 @@ constexpr int TEXT_LINE_SIZE = 256;
namespace ygo {
bool IsExtension(const wchar_t* filename, const wchar_t* extension);
bool IsExtension(const char* filename, const char* extension);
#ifndef YGOPRO_SERVER_MODE
struct Config {
......@@ -205,7 +206,7 @@ public:
void HideElement(irr::gui::IGUIElement* element, bool set_action = false);
void PopupElement(irr::gui::IGUIElement* element, int hideframe = 0);
void WaitFrameSignal(int frame);
void DrawThumb(code_pointer cp, position2di pos, const std::unordered_map<int,int>* lflist, bool drag = false);
void DrawThumb(code_pointer cp, irr::core::vector2di pos, const std::unordered_map<int,int>* lflist, bool drag = false);
void DrawDeckBd();
bool LoadConfigFromFile(const char* file);
void LoadConfig();
......@@ -246,15 +247,15 @@ public:
void ResizeChatInputWindow();
recti Resize(s32 x, s32 y, s32 x2, s32 y2);
recti Resize(s32 x, s32 y, s32 x2, s32 y2, s32 dx, s32 dy, s32 dx2, s32 dy2);
position2di Resize(s32 x, s32 y);
position2di ResizeReverse(s32 x, s32 y);
irr::core::vector2di Resize(s32 x, s32 y);
irr::core::vector2di ResizeReverse(s32 x, s32 y);
recti ResizePhaseHint(s32 x, s32 y, s32 x2, s32 y2, s32 width);
recti ResizeWin(s32 x, s32 y, s32 x2, s32 y2);
recti ResizeCardImgWin(s32 x, s32 y, s32 mx, s32 my);
recti ResizeCardHint(s32 x, s32 y, s32 x2, s32 y2);
position2di ResizeCardHint(s32 x, s32 y);
irr::core::vector2di ResizeCardHint(s32 x, s32 y);
recti ResizeCardMid(s32 x, s32 y, s32 x2, s32 y2, s32 midx, s32 midy);
position2di ResizeCardMid(s32 x, s32 y, s32 midx, s32 midy);
irr::core::vector2di ResizeCardMid(s32 x, s32 y, s32 midx, s32 midy);
recti ResizeFit(s32 x, s32 y, s32 x2, s32 y2);
void SetWindowsIcon();
......
......@@ -40,17 +40,15 @@ int main(int argc, char* argv[]) {
CFRelease(path);
#endif //__APPLE__
#ifdef _WIN32
#ifndef _DEBUG
char* pstrext;
if(argc == 2 && (pstrext = std::strrchr(argv[1], '.'))
&& (!mystrncasecmp(pstrext, ".ydk", 4) || !mystrncasecmp(pstrext, ".yrp", 4))) {
if (argc == 2 && (ygo::IsExtension(argv[1], ".ydk") || ygo::IsExtension(argv[1], ".yrp"))) { // open file from explorer
wchar_t exepath[MAX_PATH];
GetModuleFileNameW(nullptr, exepath, MAX_PATH);
wchar_t* p = std::wcsrchr(exepath, '\\');
*p = '\0';
SetCurrentDirectoryW(exepath);
wchar_t* p = std::wcsrchr(exepath, L'\\');
if (p) {
*p = 0;
SetCurrentDirectoryW(exepath);
}
}
#endif //_DEBUG
#endif //_WIN32
#ifdef _WIN32
WORD wVersionRequested;
......@@ -135,7 +133,7 @@ int main(int argc, char* argv[]) {
return 0;
#ifdef _WIN32
int wargc;
int wargc = 0;
std::unique_ptr<wchar_t*[], void(*)(wchar_t**)> wargv(CommandLineToArgvW(GetCommandLineW(), &wargc), [](wchar_t** wargv) {
LocalFree(wargv);
});
......@@ -151,6 +149,24 @@ int main(int argc, char* argv[]) {
bool deckCategorySpecified = false;
bool portSpecified = false;
for(int i = 1; i < wargc; ++i) {
if (wargc == 2 && std::wcslen(wargv[1]) >= 4) {
wchar_t* pstrext = wargv[1] + std::wcslen(wargv[1]) - 4;
if (!mywcsncasecmp(pstrext, L".ydk", 4)) {
open_file = true;
BufferIO::CopyWideString(wargv[1], open_file_name);
exit_on_return = true;
ClickButton(ygo::mainGame->btnDeckEdit);
break;
}
if (!mywcsncasecmp(pstrext, L".yrp", 4)) {
open_file = true;
BufferIO::CopyWideString(wargv[1], open_file_name);
exit_on_return = true;
ClickButton(ygo::mainGame->btnReplayMode);
ClickButton(ygo::mainGame->btnLoadReplay);
break;
}
}
if(wargv[i][0] == L'-' && wargv[i][1] == L'e' && wargv[i][2] != L'\0') {
ygo::dataManager.LoadDB(&wargv[i][2]);
continue;
......@@ -260,23 +276,6 @@ int main(int argc, char* argv[]) {
if(open_file)
ClickButton(ygo::mainGame->btnLoadSinglePlay);
break;
} else if(wargc == 2 && std::wcslen(wargv[1]) >= 4) {
wchar_t* pstrext = wargv[1] + std::wcslen(wargv[1]) - 4;
if(!mywcsncasecmp(pstrext, L".ydk", 4)) {
open_file = true;
BufferIO::CopyWideString(wargv[i], open_file_name);
exit_on_return = !keep_on_return;
ClickButton(ygo::mainGame->btnDeckEdit);
break;
}
if(!mywcsncasecmp(pstrext, L".yrp", 4)) {
open_file = true;
BufferIO::CopyWideString(wargv[i], open_file_name);
exit_on_return = !keep_on_return;
ClickButton(ygo::mainGame->btnReplayMode);
ClickButton(ygo::mainGame->btnLoadReplay);
break;
}
}
}
ygo::mainGame->MainLoop();
......
......@@ -56,11 +56,11 @@ bool ImageManager::Initial() {
tFieldTransparent[1] = driver->getTexture("textures/field-transparent3.png");
char buff[100];
for (int i = 0; i < 14; i++) {
snprintf(buff, 100, "textures/pscale/rscale_%d.png", i);
std::snprintf(buff, 100, "textures/pscale/rscale_%d.png", i);
tRScale[i] = driver->getTexture(buff);
}
for (int i = 0; i < 14; i++) {
snprintf(buff, 100, "textures/pscale/lscale_%d.png", i);
std::snprintf(buff, 100, "textures/pscale/lscale_%d.png", i);
tLScale[i] = driver->getTexture(buff);
}
tClock = driver->getTexture("textures/clock.png");
......@@ -327,26 +327,26 @@ irr::video::ITexture* ImageManager::GetTexture(int code, bool fit) {
auto tit = tMap[fit ? 1 : 0].find(code);
if(tit == tMap[fit ? 1 : 0].end()) {
char file[256];
snprintf(file, sizeof file, "expansions/pics/%d.png", code);
std::snprintf(file, sizeof file, "expansions/pics/%d.png", code);
irr::video::ITexture* img = GetTextureFromFile(file, width, height);
if(img == nullptr) {
snprintf(file, sizeof file, "expansions/pics/%d.jpg", code);
std::snprintf(file, sizeof file, "expansions/pics/%d.jpg", code);
img = GetTextureFromFile(file, width, height);
}
if(img == nullptr) {
snprintf(file, sizeof file, mainGame->GetLocaleDir("pics/%d.png"), code);
std::snprintf(file, sizeof file, mainGame->GetLocaleDir("pics/%d.png"), code);
img = GetTextureFromFile(file, width, height);
}
if(img == nullptr) {
snprintf(file, sizeof file, mainGame->GetLocaleDir("pics/%d.jpg"), code);
std::snprintf(file, sizeof file, mainGame->GetLocaleDir("pics/%d.jpg"), code);
img = GetTextureFromFile(file, width, height);
}
if(img == nullptr) {
snprintf(file, sizeof file, "pics/%d.png", code);
std::snprintf(file, sizeof file, "pics/%d.png", code);
img = GetTextureFromFile(file, width, height);
}
if(img == nullptr) {
snprintf(file, sizeof file, "pics/%d.jpg", code);
std::snprintf(file, sizeof file, "pics/%d.jpg", code);
img = GetTextureFromFile(file, width, height);
}
if(img == nullptr && !mainGame->gameConf.use_image_scale) {
......@@ -370,10 +370,10 @@ irr::video::ITexture* ImageManager::GetBigPicture(int code, float zoom) {
}
irr::video::ITexture* texture;
char file[256];
snprintf(file, sizeof file, "expansions/pics/%d.jpg", code);
std::snprintf(file, sizeof file, "expansions/pics/%d.jpg", code);
irr::video::IImage* srcimg = driver->createImageFromFile(file);
if(srcimg == nullptr) {
snprintf(file, sizeof file, "pics/%d.jpg", code);
std::snprintf(file, sizeof file, "pics/%d.jpg", code);
srcimg = driver->createImageFromFile(file);
}
if(srcimg == nullptr) {
......@@ -399,49 +399,49 @@ int ImageManager::LoadThumbThread() {
imageManager.tThumbLoadingCodes.pop();
imageManager.tThumbLoadingMutex.unlock();
char file[256];
snprintf(file, sizeof file, "expansions/pics/thumbnail/%d.png", code);
std::snprintf(file, sizeof file, "expansions/pics/thumbnail/%d.png", code);
irr::video::IImage* img = imageManager.driver->createImageFromFile(file);
if(img == nullptr) {
snprintf(file, sizeof file, "expansions/pics/thumbnail/%d.jpg", code);
std::snprintf(file, sizeof file, "expansions/pics/thumbnail/%d.jpg", code);
img = imageManager.driver->createImageFromFile(file);
}
if(img == nullptr) {
snprintf(file, sizeof file, mainGame->GetLocaleDir("pics/thumbnail/%d.png"), code);
std::snprintf(file, sizeof file, mainGame->GetLocaleDir("pics/thumbnail/%d.png"), code);
img = imageManager.driver->createImageFromFile(file);
}
if(img == nullptr) {
snprintf(file, sizeof file, mainGame->GetLocaleDir("pics/thumbnail/%d.jpg"), code);
std::snprintf(file, sizeof file, mainGame->GetLocaleDir("pics/thumbnail/%d.jpg"), code);
img = imageManager.driver->createImageFromFile(file);
}
if(img == nullptr) {
snprintf(file, sizeof file, "pics/thumbnail/%d.png", code);
std::snprintf(file, sizeof file, "pics/thumbnail/%d.png", code);
img = imageManager.driver->createImageFromFile(file);
}
if(img == nullptr) {
snprintf(file, sizeof file, "pics/thumbnail/%d.jpg", code);
std::snprintf(file, sizeof file, "pics/thumbnail/%d.jpg", code);
img = imageManager.driver->createImageFromFile(file);
}
if(img == nullptr && mainGame->gameConf.use_image_scale) {
snprintf(file, sizeof file, "expansions/pics/%d.png", code);
std::snprintf(file, sizeof file, "expansions/pics/%d.png", code);
img = imageManager.driver->createImageFromFile(file);
if(img == nullptr) {
snprintf(file, sizeof file, "expansions/pics/%d.jpg", code);
std::snprintf(file, sizeof file, "expansions/pics/%d.jpg", code);
img = imageManager.driver->createImageFromFile(file);
}
if(img == nullptr) {
snprintf(file, sizeof file, mainGame->GetLocaleDir("pics/%d.png"), code);
std::snprintf(file, sizeof file, mainGame->GetLocaleDir("pics/%d.png"), code);
img = imageManager.driver->createImageFromFile(file);
}
if(img == nullptr) {
snprintf(file, sizeof file, mainGame->GetLocaleDir("pics/%d.jpg"), code);
std::snprintf(file, sizeof file, mainGame->GetLocaleDir("pics/%d.jpg"), code);
img = imageManager.driver->createImageFromFile(file);
}
if(img == nullptr) {
snprintf(file, sizeof file, "pics/%d.png", code);
std::snprintf(file, sizeof file, "pics/%d.png", code);
img = imageManager.driver->createImageFromFile(file);
}
if(img == nullptr) {
snprintf(file, sizeof file, "pics/%d.jpg", code);
std::snprintf(file, sizeof file, "pics/%d.jpg", code);
img = imageManager.driver->createImageFromFile(file);
}
}
......@@ -487,7 +487,7 @@ irr::video::ITexture* ImageManager::GetTextureThumb(int code) {
if(lit != tThumbLoading.end()) {
if(lit->second != nullptr) {
char file[256];
snprintf(file, sizeof file, "pics/thumbnail/%d.jpg", code);
std::snprintf(file, sizeof file, "pics/thumbnail/%d.jpg", code);
irr::video::ITexture* texture = driver->addTexture(file, lit->second); // textures must be added in the main thread due to OpenGL
lit->second->drop();
tThumb[code] = texture;
......@@ -517,26 +517,26 @@ irr::video::ITexture* ImageManager::GetTextureThumb(int code) {
auto tit = tFields.find(code);
if(tit == tFields.end()) {
char file[256];
snprintf(file, sizeof file, "expansions/pics/field/%d.png", code);
std::snprintf(file, sizeof file, "expansions/pics/field/%d.png", code);
irr::video::ITexture* img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale);
if(img == nullptr) {
snprintf(file, sizeof file, "expansions/pics/field/%d.jpg", code);
std::snprintf(file, sizeof file, "expansions/pics/field/%d.jpg", code);
img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale);
}
if(img == nullptr) {
snprintf(file, sizeof file, mainGame->GetLocaleDir("pics/field/%d.png"), code);
std::snprintf(file, sizeof file, mainGame->GetLocaleDir("pics/field/%d.png"), code);
img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale);
}
if(img == nullptr) {
snprintf(file, sizeof file, mainGame->GetLocaleDir("pics/field/%d.jpg"), code);
std::snprintf(file, sizeof file, mainGame->GetLocaleDir("pics/field/%d.jpg"), code);
img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale);
}
if(img == nullptr) {
snprintf(file, sizeof file, "pics/field/%d.png", code);
std::snprintf(file, sizeof file, "pics/field/%d.png", code);
img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale);
}
if(img == nullptr) {
snprintf(file, sizeof file, "pics/field/%d.jpg", code);
std::snprintf(file, sizeof file, "pics/field/%d.jpg", code);
img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale);
if(img == nullptr) {
tFields[code] = nullptr;
......@@ -561,26 +561,26 @@ irr::video::ITexture* ImageManager::GetTextureField(int code) {
auto tit = tFields.find(code);
if(tit == tFields.end()) {
char file[256];
snprintf(file, sizeof file, "expansions/pics/field/%d.png", code);
std::snprintf(file, sizeof file, "expansions/pics/field/%d.png", code);
irr::video::ITexture* img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale);
if(img == nullptr) {
snprintf(file, sizeof file, "expansions/pics/field/%d.jpg", code);
std::snprintf(file, sizeof file, "expansions/pics/field/%d.jpg", code);
img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale);
}
if(img == nullptr) {
snprintf(file, sizeof file, mainGame->GetLocaleDir("pics/field/%d.png"), code);
std::snprintf(file, sizeof file, mainGame->GetLocaleDir("pics/field/%d.png"), code);
img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale);
}
if(img == nullptr) {
snprintf(file, sizeof file, mainGame->GetLocaleDir("pics/field/%d.jpg"), code);
std::snprintf(file, sizeof file, mainGame->GetLocaleDir("pics/field/%d.jpg"), code);
img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale);
}
if(img == nullptr) {
snprintf(file, sizeof file, "pics/field/%d.png", code);
std::snprintf(file, sizeof file, "pics/field/%d.png", code);
img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale);
}
if(img == nullptr) {
snprintf(file, sizeof file, "pics/field/%d.jpg", code);
std::snprintf(file, sizeof file, "pics/field/%d.jpg", code);
img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale);
if(img == nullptr) {
tFields[code] = nullptr;
......
This diff is collapsed.
#include "config.h"
#ifndef MATERIALS_H
#define MATERIALS_H
#include <irrlicht.h>
namespace ygo {
......@@ -7,32 +10,32 @@ public:
Materials();
void GenArrow(float y);
S3DVertex vCardFront[4];
S3DVertex vCardOutline[4];
S3DVertex vCardOutliner[4];
S3DVertex vCardBack[4];
S3DVertex vPScale[4];
S3DVertex vSymbol[4];
S3DVertex vNegate[4];
S3DVertex vChainNum[4];
S3DVertex vActivate[4];
S3DVertex vField[4];
S3DVertex vFieldSpell[4];
S3DVertex vFieldSpell1[4];
S3DVertex vFieldSpell2[4];
//S3DVertex vBackLine[76];
S3DVertex vFieldDeck[2][4];
S3DVertex vFieldGrave[2][2][4]; //[player][rule], rule = 0: dule_rule <= 3, 1: dule_rule >= 4
S3DVertex vFieldExtra[2][4];
S3DVertex vFieldRemove[2][2][4]; //[player][rule]
S3DVertex vFieldMzone[2][7][4]; //[player][sequence]
S3DVertex vFieldSzone[2][8][2][4]; //[player][sequence][rule]
irr::video::S3DVertex vCardFront[4];
irr::video::S3DVertex vCardOutline[4];
irr::video::S3DVertex vCardOutliner[4];
irr::video::S3DVertex vCardBack[4];
irr::video::S3DVertex vPScale[4];
irr::video::S3DVertex vSymbol[4];
irr::video::S3DVertex vNegate[4];
irr::video::S3DVertex vChainNum[4];
irr::video::S3DVertex vActivate[4];
irr::video::S3DVertex vField[4];
irr::video::S3DVertex vFieldSpell[4];
irr::video::S3DVertex vFieldSpell1[4];
irr::video::S3DVertex vFieldSpell2[4];
//irr::video::S3DVertex vBackLine[76];
irr::video::S3DVertex vFieldDeck[2][4];
irr::video::S3DVertex vFieldGrave[2][2][4]; //[player][rule], rule = 0: dule_rule <= 3, 1: dule_rule >= 4
irr::video::S3DVertex vFieldExtra[2][4];
irr::video::S3DVertex vFieldRemove[2][2][4]; //[player][rule]
irr::video::S3DVertex vFieldMzone[2][7][4]; //[player][sequence]
irr::video::S3DVertex vFieldSzone[2][8][2][4]; //[player][sequence][rule]
irr::core::vector3df vFieldContiAct[4];
S3DVertex vArrow[40];
SColor c2d[4];
u16 iRectangle[6];
//u16 iBackLine[116];
u16 iArrow[40];
irr::video::S3DVertex vArrow[40];
irr::video::SColor c2d[4];
irr::u16 iRectangle[6];
//irr::u16 iBackLine[116];
irr::u16 iArrow[40];
irr::video::SMaterial mCard;
irr::video::SMaterial mTexture;
irr::video::SMaterial mBackLine;
......@@ -45,3 +48,5 @@ public:
extern Materials matManager;
}
#endif //MATERIALS_H
......@@ -162,7 +162,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
}
case BUTTON_HP_READY: {
if(mainGame->cbCategorySelect->getSelected() == -1 || mainGame->cbDeckSelect->getSelected() == -1 ||
!deckManager.LoadCurrentDeck(mainGame->cbCategorySelect, mainGame->cbDeckSelect)) {
!deckManager.LoadCurrentDeck(mainGame->cbCategorySelect->getSelected(), mainGame->cbCategorySelect->getText(), mainGame->cbDeckSelect->getText())) {
mainGame->gMutex.lock();
soundManager.PlaySoundEffect(SOUND_INFO);
mainGame->env->addMessageBox(L"", dataManager.GetSysString(1406));
......@@ -353,7 +353,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
wchar_t arg1[512];
if(mainGame->botInfo[sel].select_deckfile) {
wchar_t botdeck[256];
deckManager.GetDeckFile(botdeck, mainGame->cbBotDeckCategory, mainGame->cbBotDeck);
deckManager.GetDeckFile(botdeck, mainGame->cbBotDeckCategory->getSelected(), mainGame->cbBotDeckCategory->getText(), mainGame->cbBotDeck->getText());
myswprintf(arg1, L"%ls DeckFile='%ls'", mainGame->botInfo[sel].command, botdeck);
}
else
......@@ -372,7 +372,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
wchar_t warg1[512];
if(mainGame->botInfo[sel].select_deckfile) {
wchar_t botdeck[256];
deckManager.GetDeckFile(botdeck, mainGame->cbBotDeckCategory, mainGame->cbBotDeck);
deckManager.GetDeckFile(botdeck, mainGame->cbBotDeckCategory->getSelected(), mainGame->cbBotDeckCategory->getText(), mainGame->cbBotDeck->getText());
myswprintf(warg1, L"%ls DeckFile='%ls'", mainGame->botInfo[sel].command, botdeck);
}
else
......@@ -382,9 +382,9 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
int flag = 0;
flag += (mainGame->chkBotHand->isChecked() ? 0x1 : 0);
char arg2[8];
snprintf(arg2, sizeof arg2, "%d", flag);
std::snprintf(arg2, sizeof arg2, "%d", flag);
char arg3[8];
snprintf(arg3, sizeof arg3, "%d", mainGame->gameConf.serverport);
std::snprintf(arg3, sizeof arg3, "%d", mainGame->gameConf.serverport);
execl("./bot", "bot", arg1, arg2, arg3, nullptr);
exit(0);
} else {
......@@ -458,7 +458,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
open_file = false;
}
else if(mainGame->cbDBCategory->getSelected() != -1 && mainGame->cbDBDecks->getSelected() != -1) {
deckManager.LoadCurrentDeck(mainGame->cbDBCategory, mainGame->cbDBDecks);
deckManager.LoadCurrentDeck(mainGame->cbDBCategory->getSelected(), mainGame->cbDBCategory->getText(), mainGame->cbDBDecks->getText());
mainGame->ebDeckname->setText(L"");
}
mainGame->HideElement(mainGame->wMainMenu);
......@@ -571,7 +571,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
const wchar_t* name = mainGame->lstSinglePlayList->getListItem(sel);
wchar_t fname[256];
myswprintf(fname, L"./single/%ls", name);
FILE* fp = myfopen(fname, "rb");
FILE* fp = mywfopen(fname, "rb");
if(!fp) {
mainGame->stSinglePlayInfo->setText(L"");
break;
......@@ -580,7 +580,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
wchar_t wlinebuf[1024];
std::wstring message = L"";
bool in_message = false;
while(fgets(linebuf, 1024, fp)) {
while(std::fgets(linebuf, 1024, fp)) {
if(!std::strncmp(linebuf, "--[[message", 11)) {
size_t len = std::strlen(linebuf);
char* msgend = std::strrchr(linebuf, ']');
......@@ -603,7 +603,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
message.append(wlinebuf);
}
}
fclose(fp);
std::fclose(fp);
mainGame->SetStaticText(mainGame->stSinglePlayInfo, 200, mainGame->guiFont, message.c_str());
break;
}
......@@ -627,7 +627,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
mainGame->env->setFocus(mainGame->wHostPrepare);
if(static_cast<irr::gui::IGUICheckBox*>(caller)->isChecked()) {
if(mainGame->cbCategorySelect->getSelected() == -1 || mainGame->cbDeckSelect->getSelected() == -1 ||
!deckManager.LoadCurrentDeck(mainGame->cbCategorySelect, mainGame->cbDeckSelect)) {
!deckManager.LoadCurrentDeck(mainGame->cbCategorySelect->getSelected(), mainGame->cbCategorySelect->getText(), mainGame->cbDeckSelect->getText())) {
mainGame->gMutex.lock();
static_cast<irr::gui::IGUICheckBox*>(caller)->setChecked(false);
soundManager.PlaySoundEffect(SOUND_INFO);
......
#ifndef MENU_HANDLER_H
#define MENU_HANDLER_H
#include "config.h"
#include <irrlicht.h>
namespace ygo {
class MenuHandler: public irr::IEventReceiver {
public:
bool OnEvent(const irr::SEvent& event) override;
s32 prev_operation;
int prev_sel;
irr::s32 prev_operation{ 0 };
int prev_sel{ -1 };
};
......
......@@ -2,5 +2,11 @@ project "cminiaudio"
kind "StaticLib"
files { "*.c", "*.h" }
filter "action:vs*"
forceincludes { "stb_vorbis.h" }
filter "not action:vs*"
forceincludes { "./stb_vorbis.h" }
filter "system:linux"
links { "dl", "pthread", "m" }
This diff is collapsed.
This diff is collapsed.
......@@ -94,7 +94,7 @@ public:
if(fh == INVALID_HANDLE_VALUE)
return;
do {
if(mywcsncasecmp(fdataw.cFileName, L".", 1) && mywcsncasecmp(fdataw.cFileName, L"..", 2))
if(std::wcscmp(fdataw.cFileName, L".") && std::wcscmp(fdataw.cFileName, L".."))
cb(fdataw.cFileName, (fdataw.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY));
} while(FindNextFileW(fh, &fdataw));
FindClose(fh);
......
......@@ -40,17 +40,17 @@ void Replay::BeginRecord() {
return;
#else
if(is_recording)
fclose(fp);
std::fclose(fp);
#ifdef YGOPRO_SERVER_MODE
time_t nowtime = time(nullptr);
struct tm *localedtime = localtime(&nowtime);
char tmppath[40];
strftime(tmppath, 40, "./replay/%Y-%m-%d %H-%M-%S %%u.yrp", localedtime);
char path[40];
sprintf(path, tmppath, server_port);
fp = fopen(path, "wb");
std::sprintf(path, tmppath, server_port);
fp = std::fopen(path, "wb");
#else
fp = fopen("./replay/_LastReplay.yrp", "wb");
fp = std::fopen("./replay/_LastReplay.yrp", "wb");
#endif //YGOPRO_SERVER_MODE
if(!fp)
return;
......@@ -72,8 +72,8 @@ void Replay::WriteHeader(ReplayHeader& header) {
DWORD size;
WriteFile(recording_fp, &header, sizeof(header), &size, nullptr);
#else
fwrite(&header, sizeof(header), 1, fp);
fflush(fp);
std::fwrite(&header, sizeof(header), 1, fp);
std::fflush(fp);
#endif
}
void Replay::WriteData(const void* data, size_t length, bool flush) {
......@@ -90,9 +90,9 @@ void Replay::WriteData(const void* data, size_t length, bool flush) {
DWORD size;
WriteFile(recording_fp, data, length, &size, nullptr);
#else
fwrite(data, length, 1, fp);
std::fwrite(data, length, 1, fp);
if(flush)
fflush(fp);
std::fflush(fp);
#endif
}
void Replay::WriteInt32(int32_t data, bool flush) {
......@@ -106,7 +106,7 @@ void Replay::Flush() {
#endif
#ifdef _WIN32
#else
fflush(fp);
std::fflush(fp);
#endif
}
void Replay::EndRecord() {
......@@ -118,7 +118,7 @@ void Replay::EndRecord() {
#ifdef _WIN32
CloseHandle(recording_fp);
#else
fclose(fp);
std::fclose(fp);
#endif
#ifdef YGOPRO_SERVER_MODE
}
......@@ -139,19 +139,19 @@ void Replay::SaveReplay(const wchar_t* name) {
return;
wchar_t fname[256];
myswprintf(fname, L"./replay/%ls.yrp", name);
FILE* rfp = myfopen(fname, "wb");
FILE* rfp = mywfopen(fname, "wb");
if(!rfp)
return;
fwrite(&pheader, sizeof pheader, 1, rfp);
fwrite(comp_data, comp_size, 1, rfp);
fclose(rfp);
std::fwrite(&pheader, sizeof pheader, 1, rfp);
std::fwrite(comp_data, comp_size, 1, rfp);
std::fclose(rfp);
}
bool Replay::OpenReplay(const wchar_t* name) {
FILE* rfp = myfopen(name, "rb");
FILE* rfp = mywfopen(name, "rb");
if(!rfp) {
wchar_t fname[256];
myswprintf(fname, L"./replay/%ls", name);
rfp = myfopen(fname, "rb");
rfp = mywfopen(fname, "rb");
}
if(!rfp)
return false;
......@@ -161,13 +161,13 @@ bool Replay::OpenReplay(const wchar_t* name) {
is_replaying = false;
replay_size = 0;
comp_size = 0;
if(fread(&pheader, sizeof pheader, 1, rfp) < 1) {
fclose(rfp);
if(std::fread(&pheader, sizeof pheader, 1, rfp) < 1) {
std::fclose(rfp);
return false;
}
if(pheader.flag & REPLAY_COMPRESSED) {
comp_size = fread(comp_data, 1, MAX_COMP_SIZE, rfp);
fclose(rfp);
comp_size = std::fread(comp_data, 1, MAX_COMP_SIZE, rfp);
std::fclose(rfp);
if (pheader.datasize > MAX_REPLAY_SIZE)
return false;
replay_size = pheader.datasize;
......@@ -178,8 +178,8 @@ bool Replay::OpenReplay(const wchar_t* name) {
return false;
}
} else {
replay_size = fread(replay_data, 1, MAX_REPLAY_SIZE, rfp);
fclose(rfp);
replay_size = std::fread(replay_data, 1, MAX_REPLAY_SIZE, rfp);
std::fclose(rfp);
comp_size = 0;
}
is_replaying = true;
......@@ -188,12 +188,12 @@ bool Replay::OpenReplay(const wchar_t* name) {
bool Replay::CheckReplay(const wchar_t* name) {
wchar_t fname[256];
myswprintf(fname, L"./replay/%ls", name);
FILE* rfp = myfopen(fname, "rb");
FILE* rfp = mywfopen(fname, "rb");
if(!rfp)
return false;
ReplayHeader rheader;
size_t count = fread(&rheader, sizeof rheader, 1, rfp);
fclose(rfp);
size_t count = std::fread(&rheader, sizeof rheader, 1, rfp);
std::fclose(rfp);
return count == 1 && rheader.id == 0x31707279 && rheader.version >= 0x12d0u && (rheader.version < 0x1353u || (rheader.flag & REPLAY_UNIFORM));
}
bool Replay::DeleteReplay(const wchar_t* name) {
......
......@@ -176,7 +176,7 @@ void SoundManager::PlaySoundEffect(int sound) {
break;
}
char soundPath[40];
snprintf(soundPath, 40, "./sound/%s.wav", soundName);
std::snprintf(soundPath, 40, "./sound/%s.wav", soundName);
#ifdef YGOPRO_USE_AUDIO
ma_engine_set_volume(&engineSound, mainGame->gameConf.sound_volume);
auto res = ma_engine_play_sound(&engineSound, soundPath, nullptr);
......@@ -223,7 +223,7 @@ void SoundManager::PlayMusic(char* song, bool loop) {
BufferIO::DecodeUTF8(song, song_w);
ma_sound_init_from_file_w(&engineMusic, song_w, MA_SOUND_FLAG_ASYNC | MA_SOUND_FLAG_STREAM, nullptr, nullptr, &soundBGM);
#else
ma_sound_init_from_file(&engineMusic, song, MA_SOUND_FLAG_ASYNC | MA_SOUND_FLAG_STREAM, nullptr, nullptr, &soundBGM);
auto res = ma_sound_init_from_file(&engineMusic, song, MA_SOUND_FLAG_ASYNC | MA_SOUND_FLAG_STREAM, nullptr, nullptr, &soundBGM);
#endif
ma_sound_set_looping(&soundBGM, loop);
ma_sound_start(&soundBGM);
......
......@@ -4,7 +4,6 @@
#include "game.h"
#include "../ocgcore/mtrandom.h"
#ifdef YGOPRO_USE_AUDIO
#define MINIAUDIO_IMPLEMENTATION
#include "miniaudio/miniaudio.h"
#endif
......
// Copyright (C) 2002-2007 Nikolaus Gebhardt
// This file is part of the "irrKlang" library.
// For conditions of distribution and use, see copyright notice in irrKlang.h
#include "CIrrKlangAudioStreamLoaderMP3.h"
#include "CIrrKlangAudioStreamMP3.h"
#include <string.h>
namespace irrklang
{
CIrrKlangAudioStreamLoaderMP3::CIrrKlangAudioStreamLoaderMP3()
{
}
//! Returns true if the file maybe is able to be loaded by this class.
bool CIrrKlangAudioStreamLoaderMP3::isALoadableFileExtension(const ik_c8* fileName)
{
return strstr(fileName, ".mp3") != 0;
}
//! Creates an audio file input stream from a file
IAudioStream* CIrrKlangAudioStreamLoaderMP3::createAudioStream(irrklang::IFileReader* file)
{
CIrrKlangAudioStreamMP3* stream = new CIrrKlangAudioStreamMP3(file);
if (stream && !stream->isOK())
{
stream->drop();
stream = 0;
}
return stream;
}
} // end namespace irrklang
// Copyright (C) 2002-2007 Nikolaus Gebhardt
// This file is part of the "irrKlang" library.
// For conditions of distribution and use, see copyright notice in irrKlang.h
#ifndef __C_IRRKLANG_AUDIO_STREAM_LOADER_MP3_H_INCLUDED__
#define __C_IRRKLANG_AUDIO_STREAM_LOADER_MP3_H_INCLUDED__
#include <ik_IAudioStreamLoader.h>
namespace irrklang
{
//! Class which is able to create an audio file stream from a file.
class CIrrKlangAudioStreamLoaderMP3 : public IAudioStreamLoader
{
public:
CIrrKlangAudioStreamLoaderMP3();
//! Returns true if the file maybe is able to be loaded by this class.
/** This decision should be based only on the file extension (e.g. ".wav") */
virtual bool isALoadableFileExtension(const ik_c8* fileName);
//! Creates an audio file input stream from a file
/** \return Pointer to the created audio stream. Returns 0 if loading failed.
If you no longer need the stream, you should call IAudioFileStream::drop().
See IRefCounted::drop() for more information. */
virtual IAudioStream* createAudioStream(irrklang::IFileReader* file);
};
} // end namespace irrklang
#endif
// Copyright (C) 2002-2007 Nikolaus Gebhardt
// Part of the code for this plugin for irrKlang is based on:
// MP3 input for Audiere by Matt Campbell <mattcampbell@pobox.com>, based on
// libavcodec from ffmpeg (http://ffmpeg.sourceforge.net/).
// See license.txt for license details of this plugin.
#include "CIrrKlangAudioStreamMP3.h"
#include <memory.h>
#include <stdlib.h> // free, malloc and realloc
#include <string.h>
#include <algorithm>
namespace irrklang
{
CIrrKlangAudioStreamMP3::CIrrKlangAudioStreamMP3(IFileReader* file)
: File(file), TheMPAuDecContext(0), InputPosition(0), InputLength(0),
DecodeBuffer(0), FirstFrameRead(false), EndOfFileReached(0),
FileBegin(0), Position(0)
{
if (File)
{
File->grab();
TheMPAuDecContext = new MPAuDecContext();
if (!TheMPAuDecContext || mpaudec_init(TheMPAuDecContext) < 0)
{
File->drop();
File = 0;
delete TheMPAuDecContext;
TheMPAuDecContext = 0;
return;
}
// init, get format
DecodeBuffer = new ik_u8[MPAUDEC_MAX_AUDIO_FRAME_SIZE];
if (File->getSize()>0)
{
// seekable file, now parse file to get size
// (needed to make it possible for the engine to loop a stream correctly)
skipID3IfNecessary();
TheMPAuDecContext->parse_only = 1;
Format.FrameCount = 0;
while(!EndOfFileReached)
{
if (!decodeFrame())
break;
Format.FrameCount += TheMPAuDecContext->frame_size;
if (!EndOfFileReached /*&& File->isSeekable()*/ )
{
// to be able to seek in the stream, store offsets and sizes
SFramePositionData data;
data.size = TheMPAuDecContext->frame_size;
data.offset = File->getPos() - (InputLength - InputPosition) - TheMPAuDecContext->coded_frame_size;
FramePositionData.push_back(data);
}
}
TheMPAuDecContext->parse_only = 0;
setPosition(0);
}
else
decodeFrame(); // decode first frame to read audio format
if (!TheMPAuDecContext->channels ||
!TheMPAuDecContext->sample_rate )
{
File->drop();
File = 0;
delete TheMPAuDecContext;
TheMPAuDecContext = 0;
return;
}
}
}
CIrrKlangAudioStreamMP3::~CIrrKlangAudioStreamMP3()
{
if (File)
File->drop();
if (TheMPAuDecContext)
{
mpaudec_clear(TheMPAuDecContext);
delete TheMPAuDecContext;
}
delete [] DecodeBuffer;
}
//! returns format of the audio stream
SAudioStreamFormat CIrrKlangAudioStreamMP3::getFormat()
{
return Format;
}
//! tells the audio stream to read n audio frames into the specified buffer
ik_s32 CIrrKlangAudioStreamMP3::readFrames(void* target, ik_s32 frameCountToRead)
{
const int frameSize = Format.getFrameSize();
int framesRead = 0;
ik_u8* out = (ik_u8*)target;
while (framesRead < frameCountToRead)
{
// no more samples? ask the MP3 for more
if (DecodedQueue.getSize() < frameSize)
{
if (!decodeFrame() || EndOfFileReached)
return framesRead;
// if the buffer is still empty, we are done
if (DecodedQueue.getSize() < frameSize)
return framesRead;
}
const int framesLeft = frameCountToRead - framesRead;
const int dequeSize = DecodedQueue.getSize() / frameSize;
const int framesToRead = framesLeft < dequeSize ? framesLeft : dequeSize;
DecodedQueue.read(out, framesToRead * frameSize);
out += framesToRead * frameSize;
framesRead += framesToRead;
Position += framesToRead;
}
return framesRead;
}
bool CIrrKlangAudioStreamMP3::decodeFrame()
{
int outputSize = 0;
while (!outputSize)
{
if (InputPosition == InputLength)
{
InputPosition = 0;
InputLength = File->read(InputBuffer, IKP_MP3_INPUT_BUFFER_SIZE);
if (InputLength == 0)
{
EndOfFileReached = true;
return true;
}
}
int rv = mpaudec_decode_frame( TheMPAuDecContext, (ik_s16*)DecodeBuffer,
&outputSize,
(ik_u8*)InputBuffer + InputPosition,
InputLength - InputPosition);
if (rv < 0)
return false;
InputPosition += rv;
} // end while
if (!FirstFrameRead)
{
Format.ChannelCount = TheMPAuDecContext->channels;
Format.SampleRate = TheMPAuDecContext->sample_rate;
Format.SampleFormat = ESF_S16;
Format.FrameCount = -1; // unknown lenght
FirstFrameRead = true;
}
else
if (TheMPAuDecContext->channels != Format.ChannelCount ||
TheMPAuDecContext->sample_rate != Format.SampleRate)
{
// Can't handle format changes mid-stream.
return false;
}
if (!TheMPAuDecContext->parse_only)
{
if (outputSize < 0)
{
// Couldn't decode this frame. Too bad, already lost it.
// This should only happen when seeking.
outputSize = TheMPAuDecContext->frame_size;
memset(DecodeBuffer, 0, outputSize * Format.getFrameSize());
}
DecodedQueue.write(DecodeBuffer, outputSize);
}
return true;
}
//! sets the position of the audio stream.
/** For example to let the stream be read from the beginning of the file again,
setPosition(0) would be called. This is usually done be the sound engine to
loop a stream after if has reached the end. Return true if sucessful and 0 if not. */
bool CIrrKlangAudioStreamMP3::setPosition(ik_s32 pos)
{
if (!File || !TheMPAuDecContext)
return false;
if (pos == 0)
{
// usually done for looping, just reset to start
File->seek(FileBegin); // skip possible ID3 header
EndOfFileReached = false;
DecodedQueue.clear();
MPAuDecContext oldContext = *TheMPAuDecContext;
mpaudec_clear(TheMPAuDecContext);
mpaudec_init(TheMPAuDecContext);
TheMPAuDecContext->bit_rate = oldContext.bit_rate;
TheMPAuDecContext->channels = oldContext.channels;
TheMPAuDecContext->frame_size = oldContext.frame_size;
TheMPAuDecContext->sample_rate = oldContext.sample_rate;
InputPosition = 0;
InputLength = 0;
Position = 0;
CurrentFramePosition = 0;
return true;
}
else
{
// user wants to seek in the stream, so do this here
int scan_position = 0;
int target_frame = 0;
int frame_count = (int)FramePositionData.size();
while (target_frame < frame_count)
{
int frame_size = FramePositionData[target_frame].size;
if (pos <= scan_position + frame_size)
break;
else
{
scan_position += frame_size;
target_frame++;
}
}
const int MAX_FRAME_DEPENDENCY = 10;
target_frame = std::max(0, target_frame - MAX_FRAME_DEPENDENCY);
setPosition(0);
File->seek(FramePositionData[target_frame].offset, false);
int i;
for (i = 0; i < target_frame; i++)
{
if (i>=(int)FramePositionData.size())
{
// internal error
setPosition(0);
return false;
}
Position += FramePositionData[i].size;
}
if (!decodeFrame() || EndOfFileReached)
{
setPosition(0);
return false;
}
int frames_to_consume = pos - Position; // PCM frames now
if (frames_to_consume > 0)
{
ik_u8 *buf = new ik_u8[frames_to_consume * Format.getFrameSize()];
readFrames(buf, frames_to_consume);
delete[] buf;
}
return true;
}
return false;
}
CIrrKlangAudioStreamMP3::QueueBuffer::QueueBuffer()
{
Capacity = 256;
Size = 0;
Buffer = (ik_u8*)malloc(Capacity);
}
CIrrKlangAudioStreamMP3::QueueBuffer::~QueueBuffer()
{
free(Buffer);
}
int CIrrKlangAudioStreamMP3::QueueBuffer::getSize()
{
return Size;
}
void CIrrKlangAudioStreamMP3::QueueBuffer::write(const void* buffer, int size)
{
bool needRealloc = false;
while (size + Size > Capacity)
{
Capacity *= 2;
needRealloc = true;
}
if (needRealloc)
{
Buffer = (ik_u8*)realloc(Buffer, Capacity);
}
memcpy(Buffer + Size, buffer, size);
Size += size;
}
int CIrrKlangAudioStreamMP3::QueueBuffer::read(void* buffer, int size)
{
int toRead = size < Size ? size : Size;
memcpy(buffer, Buffer, toRead);
memmove(Buffer, Buffer + toRead, Size - toRead);
Size -= toRead;
return toRead;
}
void CIrrKlangAudioStreamMP3::QueueBuffer::clear()
{
Size = 0;
}
void CIrrKlangAudioStreamMP3::skipID3IfNecessary()
{
char header[10];
int read = File->read(&header, 10);
if (read == 10 &&
header[0] == 'I' && header[1] == 'D' && header[2] == '3')
{
int versionMajor = header[3];
int versionMinor = header[4];
int flags = header[5];
// IDv2 size looks like the following: ID3v2 size 4 * %0xxxxxxx.
// Sick, but that's how it works.
int size = 0;
size = (header[6] & 0x7f) << (3*7);
size |= (header[7] & 0x7f) << (2*7);
size |= (header[8] & 0x7f) << (1*7);
size |= (header[9] & 0x7f) ;
size += 10; // header size
FileBegin = size;
File->seek(FileBegin);
}
else
File->seek(0);
}
} // end namespace irrklang
// Copyright (C) 2002-2007 Nikolaus Gebhardt
// Part of the code for this plugin for irrKlang is based on:
// MP3 input for Audiere by Matt Campbell <mattcampbell@pobox.com>, based on
// libavcodec from ffmpeg (http://ffmpeg.sourceforge.net/).
// See license.txt for license details of this plugin.
#ifndef __C_IRRKLANG_AUDIO_STREAM_MP3_H_INCLUDED__
#define __C_IRRKLANG_AUDIO_STREAM_MP3_H_INCLUDED__
#include <ik_IAudioStream.h>
#include <ik_IFileReader.h>
#include <vector>
#include "decoder/mpaudec.h"
namespace irrklang
{
const int IKP_MP3_INPUT_BUFFER_SIZE = 4096;
//! Reads and decodes audio data into an usable audio stream for the ISoundEngine
/** To extend irrKlang with new audio format decoders, the only thing needed to do
is implementing the IAudioStream interface. All the code available in this class is only for
mp3 decoding and may make this class look a bit more complicated then it actually is. */
class CIrrKlangAudioStreamMP3 : public IAudioStream
{
public:
CIrrKlangAudioStreamMP3(IFileReader* file);
~CIrrKlangAudioStreamMP3();
//! returns format of the audio stream
virtual SAudioStreamFormat getFormat();
//! tells the audio stream to read n audio frames into the specified buffer
/** \param target: Target data buffer to the method will write the read frames into. The
specified buffer will be getFormat().getFrameSize()*frameCount big.
\param frameCount: amount of frames to be read.
\returns Returns amount of frames really read. Should be frameCountToRead in most cases. */
virtual ik_s32 readFrames(void* target, ik_s32 frameCountToRead);
//! sets the position of the audio stream.
/** For example to let the stream be read from the beginning of the file again,
setPosition(0) would be called. This is usually done be the sound engine to
loop a stream after if has reached the end. Return true if sucessful and 0 if not. */
virtual bool setPosition(ik_s32 pos);
// just for the CIrrKlangAudioStreamLoaderMP3 to let him know if loading worked
bool isOK() { return File != 0; }
protected:
ik_s32 readFrameForMP3(void* target, ik_s32 frameCountToRead, bool parseOnly=false);
bool decodeFrame();
void skipID3IfNecessary();
irrklang::IFileReader* File;
SAudioStreamFormat Format;
// mpaudec specific
MPAuDecContext* TheMPAuDecContext;
ik_u8 InputBuffer[IKP_MP3_INPUT_BUFFER_SIZE];
int InputPosition;
int InputLength;
int Position;
ik_u8* DecodeBuffer;
ik_s32 FileBegin;
ik_u32 CurrentFramePosition;
bool FirstFrameRead;
bool EndOfFileReached;
// helper class for managing the streaming decoded audio data
class QueueBuffer
{
public:
QueueBuffer();
~QueueBuffer();
int getSize();
void write(const void* buffer, int size);
int read(void* buffer, int size);
void clear();
private:
ik_u8* Buffer;
int Capacity;
int Size;
};
struct SFramePositionData
{
int offset;
int size;
};
std::vector<SFramePositionData> FramePositionData;
QueueBuffer DecodedQueue;
};
} // end namespace irrklang
#endif
/*
* Common bit i/o utils
* Copyright (c) 2000, 2001 Fabrice Bellard.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Modified by Matt Campbell <mattcampbell@pobox.com> for the stand-alone
* mpaudec library. Based on common.c from libavcodec.
*/
#include "internal.h"
/**
* init GetBitContext.
* @param buffer bitstream buffer
* @param bit_size the size of the buffer in bits
*/
void init_get_bits(GetBitContext *s,
const uint8_t *buffer, int bit_size)
{
s->buffer= buffer;
s->size_in_bits= bit_size;
s->index=0;
}
unsigned int show_bits(const GetBitContext *s, int n)
{
int i;
unsigned int result = 0;
assert(s->size_in_bits - s->index >= n);
for (i = s->index; i < s->index + n; i++) {
int byte_index = i / 8;
unsigned int right_shift = 7 - (i % 8);
uint8_t byte = s->buffer[byte_index];
uint8_t bit;
result <<= 1;
if (right_shift == 0)
bit = byte & 0x1;
else
bit = (byte >> right_shift) & 0x1;
result |= (unsigned int)bit;
}
return result;
}
void skip_bits(GetBitContext *s, int n)
{
s->index += n;
}
unsigned int get_bits(GetBitContext *s, int n)
{
unsigned int result = show_bits(s, n);
skip_bits(s, n);
return result;
}
int get_bits_count(const GetBitContext *s)
{
return s->index;
}
/* VLC decoding */
/*#define DEBUG_VLC*/
#define GET_DATA(v, table, i, wrap, size) \
{\
const uint8_t *ptr = (const uint8_t *)table + i * wrap;\
switch(size) {\
case 1:\
v = *(const uint8_t *)ptr;\
break;\
case 2:\
v = *(const uint16_t *)ptr;\
break;\
default:\
v = *(const uint32_t *)ptr;\
break;\
}\
}
static int alloc_table(VLC *vlc, int size)
{
int index;
index = vlc->table_size;
vlc->table_size += size;
if (vlc->table_size > vlc->table_allocated) {
vlc->table_allocated += (1 << vlc->bits);
vlc->table = realloc(vlc->table,
sizeof(VLC_TYPE) * 2 * vlc->table_allocated);
if (!vlc->table)
return -1;
}
return index;
}
static int build_table(VLC *vlc, int table_nb_bits,
int nb_codes,
const void *bits, int bits_wrap, int bits_size,
const void *codes, int codes_wrap, int codes_size,
uint32_t code_prefix, int n_prefix)
{
int i, j, k, n, table_size, table_index, nb, n1, index;
uint32_t code;
VLC_TYPE (*table)[2];
table_size = 1 << table_nb_bits;
table_index = alloc_table(vlc, table_size);
#ifdef DEBUG_VLC
printf("new table index=%d size=%d code_prefix=%x n=%d\n",
table_index, table_size, code_prefix, n_prefix);
#endif
if (table_index < 0)
return -1;
table = &vlc->table[table_index];
for(i=0;i<table_size;i++) {
table[i][1] = 0; /*bits*/
table[i][0] = -1; /*codes*/
}
/* first pass: map codes and compute auxillary table sizes */
for(i=0;i<nb_codes;i++) {
GET_DATA(n, bits, i, bits_wrap, bits_size);
GET_DATA(code, codes, i, codes_wrap, codes_size);
/* we accept tables with holes */
if (n <= 0)
continue;
#if defined(DEBUG_VLC) && 0
printf("i=%d n=%d code=0x%x\n", i, n, code);
#endif
/* if code matches the prefix, it is in the table */
n -= n_prefix;
if (n > 0 && (code >> n) == code_prefix) {
if (n <= table_nb_bits) {
/* no need to add another table */
j = (code << (table_nb_bits - n)) & (table_size - 1);
nb = 1 << (table_nb_bits - n);
for(k=0;k<nb;k++) {
#ifdef DEBUG_VLC
printf("%4x: code=%d n=%d\n",
j, i, n);
#endif
assert(table[j][1] /*bits*/ == 0);
table[j][1] = n; /*bits*/
table[j][0] = i; /*code*/
j++;
}
} else {
n -= table_nb_bits;
j = (code >> n) & ((1 << table_nb_bits) - 1);
#ifdef DEBUG_VLC
printf("%4x: n=%d (subtable)\n",
j, n);
#endif
/* compute table size */
n1 = -table[j][1]; /*bits*/
if (n > n1)
n1 = n;
table[j][1] = -n1; /*bits*/
}
}
}
/* second pass : fill auxillary tables recursively */
for(i=0;i<table_size;i++) {
n = table[i][1]; /*bits*/
if (n < 0) {
n = -n;
if (n > table_nb_bits) {
n = table_nb_bits;
table[i][1] = -n; /*bits*/
}
index = build_table(vlc, n, nb_codes,
bits, bits_wrap, bits_size,
codes, codes_wrap, codes_size,
(code_prefix << table_nb_bits) | i,
n_prefix + table_nb_bits);
if (index < 0)
return -1;
/* note: realloc has been done, so reload tables */
table = &vlc->table[table_index];
table[i][0] = index; /*code*/
}
}
return table_index;
}
/* Build VLC decoding tables suitable for use with get_vlc().
'nb_bits' set thee decoding table size (2^nb_bits) entries. The
bigger it is, the faster is the decoding. But it should not be too
big to save memory and L1 cache. '9' is a good compromise.
'nb_codes' : number of vlcs codes
'bits' : table which gives the size (in bits) of each vlc code.
'codes' : table which gives the bit pattern of of each vlc code.
'xxx_wrap' : give the number of bytes between each entry of the
'bits' or 'codes' tables.
'xxx_size' : gives the number of bytes of each entry of the 'bits'
or 'codes' tables.
'wrap' and 'size' allows to use any memory configuration and types
(byte/word/long) to store the 'bits' and 'codes' tables.
*/
int init_vlc(VLC *vlc, int nb_bits, int nb_codes,
const void *bits, int bits_wrap, int bits_size,
const void *codes, int codes_wrap, int codes_size)
{
vlc->bits = nb_bits;
vlc->table = NULL;
vlc->table_allocated = 0;
vlc->table_size = 0;
#ifdef DEBUG_VLC
printf("build table nb_codes=%d\n", nb_codes);
#endif
if (build_table(vlc, nb_bits, nb_codes,
bits, bits_wrap, bits_size,
codes, codes_wrap, codes_size,
0, 0) < 0) {
free(vlc->table);
return -1;
}
return 0;
}
void free_vlc(VLC *vlc)
{
free(vlc->table);
}
int get_vlc(GetBitContext *s, const VLC *vlc)
{
int code = 0;
int depth = 0, max_depth = 3;
int n, index, bits = vlc->bits;
do {
index = show_bits(s, bits) + code;
code = vlc->table[index][0];
n = vlc->table[index][1];
depth++;
if (n < 0 && depth < max_depth) {
skip_bits(s, bits);
bits = -n;
}
} while (n < 0 && depth < max_depth);
skip_bits(s, n);
return code;
}
/* Based on common.h from libavcodec. Modified extensively by Matt Campbell
<mattcampbell@pobox.com> for the stand-alone mpaudec library. */
#ifndef INTERNAL_H
#define INTERNAL_H
#if defined(_WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__)
# define CONFIG_WIN32
#endif
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <stddef.h>
#include "mpaudec.h"
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#ifdef CONFIG_WIN32
/* windows */
typedef unsigned short uint16_t;
typedef signed short int16_t;
typedef unsigned char uint8_t;
typedef unsigned int uint32_t;
typedef unsigned __int64 uint64_t;
typedef signed char int8_t;
typedef signed int int32_t;
typedef signed __int64 int64_t;
# ifdef _DEBUG
# define DEBUG
# endif
/* CONFIG_WIN32 end */
#else
/* unix */
#include <inttypes.h>
#endif /* !CONFIG_WIN32 */
/* debug stuff */
#if !defined(DEBUG) && !defined(NDEBUG)
# define NDEBUG
#endif
#include <assert.h>
/* bit input */
typedef struct GetBitContext {
const uint8_t *buffer;
int index;
int size_in_bits;
} GetBitContext;
int get_bits_count(const GetBitContext *s);
#define VLC_TYPE int16_t
typedef struct VLC {
int bits;
VLC_TYPE (*table)[2];
int table_size, table_allocated;
} VLC;
unsigned int get_bits(GetBitContext *s, int n);
unsigned int show_bits(const GetBitContext *s, int n);
void skip_bits(GetBitContext *s, int n);
void init_get_bits(GetBitContext *s,
const uint8_t *buffer, int buffer_size);
int init_vlc(VLC *vlc, int nb_bits, int nb_codes,
const void *bits, int bits_wrap, int bits_size,
const void *codes, int codes_wrap, int codes_size);
void free_vlc(VLC *vlc);
int get_vlc(GetBitContext *s, const VLC *vlc);
#endif /* INTERNAL_H */
This diff is collapsed.
/* Portions based on avcodec.h from libavcodec. */
#ifndef MPAUDEC_H
#define MPAUDEC_H
#ifdef __cplusplus
extern "C" {
#endif
/* in bytes */
#define MPAUDEC_MAX_AUDIO_FRAME_SIZE 4608
typedef struct MPAuDecContext {
int bit_rate;
int layer;
int sample_rate;
int channels;
int frame_size;
void *priv_data;
int parse_only;
int coded_frame_size;
} MPAuDecContext;
int mpaudec_init(MPAuDecContext *mpctx);
int mpaudec_decode_frame(MPAuDecContext * mpctx,
void *data, int *data_size,
const unsigned char * buf, int buf_size);
void mpaudec_clear(MPAuDecContext *mpctx);
#ifdef __cplusplus
}
#endif
#endif /* MPAUDEC_H */
This diff is collapsed.
/* Modified slightly by Matt Campbell <mattcampbell@pobox.com> for the
stand-alone mpaudec library. Based on mpegaudio.h from libavcodec. */
/* max frame size, in samples */
#define MPA_FRAME_SIZE 1152
/* max compressed frame size */
#define MPA_MAX_CODED_FRAME_SIZE 1792
#define MPA_MAX_CHANNELS 2
#define SBLIMIT 32 /* number of subbands */
#define MPA_STEREO 0
#define MPA_JSTEREO 1
#define MPA_DUAL 2
#define MPA_MONO 3
#include <irrKlang.h>
#include <stdio.h>
#include <string.h>
#include "CIrrKlangAudioStreamLoaderMP3.h"
using namespace irrklang;
#ifdef WIN32
// Windows version
extern "C" __declspec(dllexport) void ikpMP3Init(ISoundEngine* engine)
#else
// Linux version
extern "C" void ikpMP3Init(ISoundEngine* engine)
#endif
{
// create and register the loader
CIrrKlangAudioStreamLoaderMP3* loader = new CIrrKlangAudioStreamLoaderMP3();
engine->registerAudioStreamLoader(loader);
loader->drop();
// that's it, that's all.
}
#include <irrKlang.h>
namespace irrklang
{
#ifdef WIN32
// Windows version
extern "C" __declspec(dllexport) void ikpMP3Init(ISoundEngine* engine);
#else
// Linux version
extern "C" void ikpMP3Init(ISoundEngine* engine);
#endif
}
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
project "ikpmp3"
kind "StaticLib"
files { "*.cpp", "*.h", "decoder/*.c", "decoder/*.h" }
includedirs { "../irrklang/include" }
ikpMP3 is a plugin for irrKlang.
Copyright (C) 2002-2007 Nikolaus Gebhardt
Part of the code for this plugin for irrKlang is based on:
MP3 input for Audiere by Matt Campbell <mattcampbell@pobox.com>, based on
libavcodec from ffmpeg (http://ffmpeg.sourceforge.net/).
See license.txt for license details of this plugin.
Subproject commit 7b7b95c582fa71f01154a0afcdf0d85f4516e35a
Subproject commit 619941aa1a8ccbe598bb8195390e49783d88c57f
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