• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
KingofNoobs

Wide Text Reading

4 posts in this topic

Hello,

I am outputting some Atlas and Sprite initialization data to a file. I am trying to keep everything in my game wide chars in Unicode for eventual localization purposes. I can reroute wcout to my file, but when I open it in notepad it is gibberish. I know notepad can read unicode because I save txt files in Unicode from time to time using Notepad. Can anyone tell me if I need a new text reader for wide characters, or how I can set up notepad to accept my wide char UNICODE file as unicode and read it appropriately?

Thanks again.

-Dave Ottley
0

Share this post


Link to post
Share on other sites
Can you post your code, and a hex dump of the resulting text file? Is the file readable in, say, wordpad or word?

PS: ditch notepad - wordpad is superior in every single aspect (and if you want better, there's always notepad2, notepad++, etc...) Edited by Bacterius
0

Share this post


Link to post
Share on other sites
WARNING: This is long:
--------------------------------------
int main()
{
ifstream atlas("temp.atlas", ios::binary | ios::app | ios::ate);
uint32_t size = (uint32_t)atlas.tellg();
char * buffer = new char[size+1];
uint32_t imageDataStartsHere = 0;
atlas.seekg(0);
atlas.read(&buffer[0], size);
buffer[size] = 0;
atlas.close();

ofstream wcout("Atlas_Header_Logger.txt");
wcout << "The buffer is: " << size << L" bytes long." << endl;
wcout << L"The file is safely in memory." << endl;
wcout << endl << L"File Data:" << endl;
wcout << L"----------" << endl;
const uint32_t MAX_SPRITES = 100;
wstring atlasTitle;
uint32_t numOfSprites;
vector<wstring> spriteTitle; spriteTitle.reserve(MAX_SPRITES);
vector<uint32_t> frameWidth; frameWidth.reserve(MAX_SPRITES);
vector<uint32_t> frameHeight; frameHeight.reserve(MAX_SPRITES);
vector<uint32_t> originX; originX.reserve(MAX_SPRITES);
vector<uint32_t> originY; originY.reserve(MAX_SPRITES);
vector<uint32_t> numFrames; numFrames.reserve(MAX_SPRITES);
vector<uint32_t> sheetWidthInFrames; sheetWidthInFrames.reserve(MAX_SPRITES);
vector<uint32_t> sheetHeightInFrames; sheetHeightInFrames.reserve(MAX_SPRITES);
vector<uint32_t> numOfAnimations; numOfAnimations.reserve(MAX_SPRITES);
vector<vector<wstring>> animNames; animNames.reserve(MAX_SPRITES);
vector<vector<uint32_t>> animNumFrames; animNumFrames.reserve(MAX_SPRITES);
vector<vector<vector<uint32_t>>> animFrameList; animFrameList.reserve(MAX_SPRITES);

enum FileSection
{
ATLAS_TITLE,
NUM_OF_SPRITES,
SPRITE_NAME,
FRAME_WIDTH,
FRAME_HEIGHT,
ORIGIN_X,
ORIGIN_Y,
NUM_FRAMES,
SHEET_WIDTH_IN_FRAMES,
SHEET_HEIGHT_IN_FRAMES,
NUM_OF_ANIMATIONS,
ANIM_NAME,
ANIM_NUM_FRAMES,
ANIM_FRAMELIST,
ANIM_NEXT_FRAME,
END_OF_HEADER
};
FileSection currentFileSection = ATLAS_TITLE;
bool abort = false;
const uint32_t MAX_DIGITS = 4;
char numberBuffer[MAX_DIGITS + 1];
uint32_t digits = 0;
uint32_t letters = 0;
uint32_t spriteNum = 0;
uint32_t animationNum = 0;
uint32_t animationFrameNum = 0;
uint32_t spritesRemaining = 0;
uint32_t animationsRemaining = 0;
uint32_t animationFramesRemaining = 0;
bool newSprite = true;
bool newAnimation = true;
bool newAnimationFrame = true;
auto ExtractString = [&](wstring& dest, char source, FileSection& currentFileSection, FileSection nextFileSection, char* fieldTitle)
{
if(source != 0)
{
wchar_t wSource = (wchar_t) source;
dest += source;
++letters;
}
else
{
if(letters == 0)
{
wcout << "Error: Correct field not found in the original file." << endl;
abort = true;
}
else
{
letters = 0;
currentFileSection = nextFileSection;
string temp;
for(auto i = dest.begin(); i != dest.end(); ++i)
{
temp.insert(temp.end(), *i);
}
wcout << fieldTitle << " " << temp << endl;
}
}
};
auto ExtractInt = [&](uint32_t& dest, char source, FileSection& currentFileSection, FileSection nextFileSection, char* fieldTitle)
{
if(source >= '0' && source <= '9')
{
numberBuffer[digits] = source;
++digits;
}
else
{
if(digits == 0)
{
wcout << "Error: Field not found in the original file." << endl;
abort = true;
}
else // To next section
{
numberBuffer[digits] = 0;
digits = 0;
dest = atoi(numberBuffer);
currentFileSection = nextFileSection;
wcout << fieldTitle << " " << dest << endl;
}
}
};
for(unsigned i = 0; i < size; ++i)
{
switch(currentFileSection)
{
case ATLAS_TITLE:
{
ExtractString(atlasTitle, buffer[i], currentFileSection, NUM_OF_SPRITES, "Atlas Title: ");
break;
}
case NUM_OF_SPRITES:
{
ExtractInt(numOfSprites, buffer[i], currentFileSection, SPRITE_NAME, "Num Sprites: ");
break;
}
case SPRITE_NAME:
{
static bool first = true;

auto ResizeSprites = [&]()
{
spriteTitle.resize(spriteTitle.size() + 1);
frameWidth.resize(frameWidth.size() + 1);
frameHeight.resize(frameHeight.size() + 1);
originX.resize(originX.size() + 1);
originY.resize(originY.size() + 1);
numFrames.resize(numFrames.size() + 1);
sheetWidthInFrames.resize(sheetWidthInFrames.size() + 1);
sheetHeightInFrames.resize(sheetHeightInFrames.size() + 1);
numOfAnimations.resize(numOfAnimations.size() + 1);
animNames.resize(animNames.size() + 1);
animNumFrames.resize(animNumFrames.size() + 1);
animFrameList.resize(animFrameList.size() + 1);
};
if(first)
{
spritesRemaining = numOfSprites;
first = false;
}
if(newSprite)
{
wcout << endl;
ResizeSprites();
newSprite = false;
}

ExtractString(spriteTitle[spriteNum], buffer[i], currentFileSection, FRAME_WIDTH, "Sprite Name: ");
break;
}
case FRAME_WIDTH:
{
newSprite = true;
ExtractInt(frameWidth[spriteNum], buffer[i], currentFileSection, FRAME_HEIGHT, "Frame Width: ");
break;
}
case FRAME_HEIGHT:
{
ExtractInt(frameHeight[spriteNum], buffer[i], currentFileSection, ORIGIN_X, "Frame Height: ");
break;
}
case ORIGIN_X:
{
ExtractInt(originX[spriteNum], buffer[i], currentFileSection, ORIGIN_Y, "Origin X: ");
break;
}
case ORIGIN_Y:
{
ExtractInt(originY[spriteNum], buffer[i], currentFileSection, NUM_FRAMES, "Origin Y: ");
break;
}

case NUM_FRAMES:
{
ExtractInt(numFrames[spriteNum], buffer[i], currentFileSection, SHEET_WIDTH_IN_FRAMES, "Frames: ");
break;
}
case SHEET_WIDTH_IN_FRAMES:
{
ExtractInt(sheetWidthInFrames[spriteNum], buffer[i], currentFileSection, SHEET_HEIGHT_IN_FRAMES, "Width(Frames): ");
break;
}
case SHEET_HEIGHT_IN_FRAMES:
{
ExtractInt(sheetHeightInFrames[spriteNum], buffer[i], currentFileSection, NUM_OF_ANIMATIONS, "Height(Frames):");
break;
}
case NUM_OF_ANIMATIONS:
{
ExtractInt(numOfAnimations[spriteNum], buffer[i], currentFileSection, ANIM_NAME, "Animations: ");
break;
}
case ANIM_NAME:
{
auto ResizeAnimations = [&]()
{
animNames[spriteNum].resize(animNames[spriteNum].size() + 1);
animNumFrames[spriteNum].resize(animNumFrames[spriteNum].size() + 1);
animFrameList[spriteNum].resize(animFrameList[spriteNum].size() + 1);
};
if(newAnimation)
{
animationsRemaining = numOfAnimations[spriteNum];
ResizeAnimations();
newAnimation = false;
}
ExtractString(animNames[spriteNum][animationNum], buffer[i], currentFileSection, ANIM_NUM_FRAMES, "Anim Name: ");
break;
}
case ANIM_NUM_FRAMES:
{
ExtractInt(animNumFrames[spriteNum][animationNum], buffer[i], currentFileSection, ANIM_FRAMELIST, " Frames: ");
if(currentFileSection == ANIM_FRAMELIST)
{
animationFramesRemaining = animNumFrames[spriteNum][animationNum];
animFrameList[spriteNum][animationNum].resize(animationFramesRemaining);
}
break;
}
case ANIM_FRAMELIST:
{
if(animationFramesRemaining != 0)
{
ExtractInt(animNumFrames[spriteNum][animationNum], buffer[i], currentFileSection, ANIM_NEXT_FRAME, " #: ");
if(currentFileSection == ANIM_NEXT_FRAME)
{
--animationFramesRemaining;
if(animationFramesRemaining)
{
currentFileSection = ANIM_FRAMELIST;
break;
}
else // No frames remaining
{
--animationsRemaining;
if(animationsRemaining)
{
currentFileSection = ANIM_NAME;
}
else // No animations remaining
{
--spritesRemaining;
if(spritesRemaining)
{
currentFileSection = SPRITE_NAME;
}
else // No sprites remaining
{
currentFileSection = END_OF_HEADER;
}
}
}
}
}
switch(currentFileSection)
{
// Do this only once at the end of the animation
case ANIM_NAME:
{
++animationNum;
newAnimation = true;
break;
}

// Do this only once at the end of the last animation for this sprite
case SPRITE_NAME:
{
++spriteNum;
newSprite = true;
newAnimation = true;
break;
}
case ANIM_FRAMELIST:
{
break;
}
case END_OF_HEADER:
{
break;
}

default:
{
wcout << endl << "Heading to Unknown File Section. Aborting Program." << endl;
abort = true;
break;
}
} // switch
break;
} // ANIM_FRAMELIST
case END_OF_HEADER:
{
imageDataStartsHere = i + 1;
wcout << endl << "End of Header." << endl;
abort = true;
break;
}
default:
{
wcout << endl << "Unknwon File Section. Aborting Program." << endl;
abort = true;
break;
}
} // switch
if(abort) break;

} // for

wcout << endl;
delete[] buffer;
system("pause");
return 0;
}


-------
DUMP:

he buffer is: 88080020CF68
0020CF88
0020CFD0
0020CFEC
Atlas Title: Level1Atlas
Num Sprites: 4
Sprite Name: Title
Frame Width: 800
Frame Height: 300
Origin X: 0
Origin Y: 0
Frames: 1
Width(Frames): 1
Height(Frames): 1
Animations: 1
Anim Name: Default
Frames: 1
#: 0
Sprite Name: Background
Frame Width: 1
Frame Height: 1
Origin X: 800
Origin Y: 0
Frames: 1
Width(Frames): 1
Height(Frames): 1
Animations: 1
Anim Name: Default
Frames: 1
#: 0
Sprite Name: Play
Frame Width: 348
Frame Height: 119
Origin X: 0
Origin Y: 419
Frames: 2
Width(Frames): 2
Height(Frames): 1
Animations: 1
Anim Name: Default
Frames: 2
#: 0
#: 1
Sprite Name: Quit
Frame Width: 348
Frame Height: 119
Origin X: 0
Origin Y: 300
Frames: 2
Width(Frames): 2
Height(Frames): 1
Animations: 1
Anim Name: Default
Frames: 2
#: 0
#: 1
End of Header.

----------------------

Notice that when I use L"..." to output the file, I get garbage. When I don't use wide chars, it prints to file just fine. This is what I'm talking about.
0

Share this post


Link to post
Share on other sites
An ofstream expects the strings output with << to be narrow character strings. If you want to use wide character strings use wofstream instead.
2

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0