Navigation Menu

Skip to content

Commit

Permalink
Merge branch 'unicode'
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob1 committed May 7, 2018
2 parents 4970340 + f8586ea commit 56cba45
Show file tree
Hide file tree
Showing 199 changed files with 4,476 additions and 2,647 deletions.
16 changes: 12 additions & 4 deletions SConscript
Expand Up @@ -67,6 +67,7 @@ AddSconsOption('static', False, False, "Compile statically.")
AddSconsOption('opengl', False, False, "Build with OpenGL interface support.")
AddSconsOption('opengl-renderer', False, False, "Build with OpenGL renderer support (turns on --opengl).") #Note: this has nothing to do with --renderer, only tells the game to render particles with opengl
AddSconsOption('renderer', False, False, "Build the save renderer.")
AddSconsOption('font', False, False, "Build the font editor.")

AddSconsOption('wall', False, False, "Error on all warnings.")
AddSconsOption('no-warnings', False, False, "Disable all compiler warnings.")
Expand Down Expand Up @@ -266,7 +267,7 @@ def findLibs(env, conf):
else:
FatalError("SDL.h not found")

if not GetOption('nolua') and not GetOption('renderer'):
if not GetOption('nolua') and not GetOption('renderer') and not GetOption('font'):
#Look for Lua
if platform == "FreeBSD":
luaver = "lua-5.1"
Expand Down Expand Up @@ -494,7 +495,7 @@ if GetOption('static'):
#Add other flags and defines
if not GetOption('nofft'):
env.Append(CPPDEFINES=['GRAVFFT'])
if not GetOption('nolua') and not GetOption('renderer'):
if not GetOption('nolua') and not GetOption('renderer') and not GetOption('font'):
env.Append(CPPDEFINES=['LUACONSOLE'])

if GetOption('opengl') or GetOption('opengl-renderer'):
Expand All @@ -507,6 +508,9 @@ if GetOption('renderer'):
else:
env.Append(CPPDEFINES=['USE_SDL'])

if GetOption('font'):
env.Append(CPPDEFINES=['FONTEDITOR'])

if GetOption("wall"):
if msvc:
env.Append(CCFLAGS=['/WX'])
Expand Down Expand Up @@ -540,7 +544,7 @@ if GetOption('beta'):

#Generate list of sources to compile
sources = Glob("src/*.cpp") + Glob("src/*/*.cpp") + Glob("src/*/*/*.cpp") + Glob("generated/*.cpp")
if not GetOption('nolua') and not GetOption('renderer'):
if not GetOption('nolua') and not GetOption('renderer') and not GetOption('font'):
sources += Glob("src/lua/socket/*.c") + Glob("src/lua/LuaCompat.c")

if platform == "Windows":
Expand All @@ -559,7 +563,11 @@ elif platform == "Darwin":
if GetOption('output'):
programName = GetOption('output')
else:
programName = GetOption('renderer') and "render" or "powder"
programName = "powder"
if GetOption('renderer'):
programName = "render"
if GetOption('font'):
programName = "font"
if "BIT" in env and env["BIT"] == 64:
programName += "64"
if isX86 and GetOption('no-sse'):
Expand Down
599 changes: 308 additions & 291 deletions data/font.h

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion font/editor.c
Expand Up @@ -7,7 +7,7 @@
#include <SDL/SDL.h>

#define CELLW 12
#define CELLH 10
#define CELLH 12

#define XRES 800
#define YRES 600
Expand Down
2 changes: 1 addition & 1 deletion font/packer.c
Expand Up @@ -6,7 +6,7 @@
#include <math.h>

#define CELLW 12
#define CELLH 10
#define CELLH 12
//#define EXTENDED_FONT 1

char font[256][CELLH][CELLW];
Expand Down
2 changes: 1 addition & 1 deletion font/unpacker.c
Expand Up @@ -11,7 +11,7 @@
#include "font.h"

#define CELLW 12
#define CELLH 10
#define CELLH 12

char font[256][CELLH][CELLW];
char width[256];
Expand Down
16 changes: 8 additions & 8 deletions src/Format.cpp
@@ -1,6 +1,6 @@

#include <ctime>
#include <string>
#include "common/String.h"
#include <stdexcept>
#include <iostream>
#include <iterator>
Expand All @@ -9,7 +9,7 @@
#include "Format.h"
#include "graphics/Graphics.h"

std::string format::URLEncode(std::string source)
ByteString format::URLEncode(ByteString source)
{
char * src = (char *)source.c_str();
char * dst = new char[(source.length()*3)+2];
Expand All @@ -33,23 +33,23 @@ std::string format::URLEncode(std::string source)
}
*d = 0;

std::string finalString(dst);
ByteString finalString(dst);
delete[] dst;
return finalString;
}

std::string format::UnixtimeToDate(time_t unixtime, std::string dateFormat)
ByteString format::UnixtimeToDate(time_t unixtime, ByteString dateFormat)
{
struct tm * timeData;
char buffer[128];

timeData = localtime(&unixtime);

strftime(buffer, 128, dateFormat.c_str(), timeData);
return std::string(buffer);
return ByteString(buffer);
}

std::string format::UnixtimeToDateMini(time_t unixtime)
ByteString format::UnixtimeToDateMini(time_t unixtime)
{
time_t currentTime = time(NULL);
struct tm currentTimeData = *localtime(&currentTime);
Expand All @@ -69,7 +69,7 @@ std::string format::UnixtimeToDateMini(time_t unixtime)
}
}

std::string format::CleanString(std::string dirtyString, bool ascii, bool color, bool newlines, bool numeric)
String format::CleanString(String dirtyString, bool ascii, bool color, bool newlines, bool numeric)
{
for (size_t i = 0; i < dirtyString.size(); i++)
{
Expand Down Expand Up @@ -226,7 +226,7 @@ struct PNGChunk

//char[4] CRC();

PNGChunk(int length, std::string name)
PNGChunk(int length, ByteString name)
{
if (name.length()!=4)
throw std::runtime_error("Invalid chunk name");
Expand Down
24 changes: 5 additions & 19 deletions src/Format.h
@@ -1,6 +1,6 @@
#pragma once

#include <sstream>
#include "common/String.h"
#include <vector>

class VideoBuffer;
Expand All @@ -9,24 +9,10 @@ namespace format
{
const static char hex[] = "0123456789ABCDEF";

template <typename T> std::string NumberToString(T number)
{
std::stringstream ss;
ss << number;
return ss.str();
}

template <typename T> T StringToNumber(const std::string & text)
{
std::stringstream ss(text);
T number;
return (ss >> number)?number:0;
}

std::string URLEncode(std::string value);
std::string UnixtimeToDate(time_t unixtime, std::string dateFomat = "%d %b %Y");
std::string UnixtimeToDateMini(time_t unixtime);
std::string CleanString(std::string dirtyString, bool ascii, bool color, bool newlines, bool numeric = false);
ByteString URLEncode(ByteString value);
ByteString UnixtimeToDate(time_t unixtime, ByteString dateFomat = "%d %b %Y");
ByteString UnixtimeToDateMini(time_t unixtime);
String CleanString(String dirtyString, bool ascii, bool color, bool newlines, bool numeric = false);
std::vector<char> VideoBufferToPNG(const VideoBuffer & vidBuf);
std::vector<char> VideoBufferToBMP(const VideoBuffer & vidBuf);
std::vector<char> VideoBufferToPPM(const VideoBuffer & vidBuf);
Expand Down
2 changes: 0 additions & 2 deletions src/Misc.h
Expand Up @@ -2,8 +2,6 @@
#define UTILS_H
#include <cstdio>
#include <cstdlib>
#include <string>
#include <sstream>
#include <vector>

//Linear interpolation
Expand Down
8 changes: 4 additions & 4 deletions src/Platform.cpp
Expand Up @@ -20,9 +20,9 @@
namespace Platform
{

std::string ExecutableName()
ByteString ExecutableName()
{
std::string ret;
ByteString ret;
#if defined(WIN)
char *name = (char *)malloc(64);
DWORD max = 64, res;
Expand Down Expand Up @@ -73,7 +73,7 @@ std::string ExecutableName()

void DoRestart()
{
std::string exename = ExecutableName();
ByteString exename = ExecutableName();
if (exename.length())
{
#ifdef WIN
Expand All @@ -85,7 +85,7 @@ void DoRestart()
exit(-1);
}

void OpenURI(std::string uri)
void OpenURI(ByteString uri)
{
#if defined(WIN)
ShellExecute(0, "OPEN", uri.c_str(), NULL, NULL, 0);
Expand Down
6 changes: 3 additions & 3 deletions src/Platform.h
@@ -1,14 +1,14 @@
#ifndef PLATFORM_H
#define PLATFORM_H

#include <string>
#include "common/String.h"

namespace Platform
{
std::string ExecutableName();
ByteString ExecutableName();
void DoRestart();

void OpenURI(std::string uri);
void OpenURI(ByteString uri);

void Millisleep(long int t);
long unsigned int GetTime();
Expand Down
5 changes: 2 additions & 3 deletions src/PowderToy.h
@@ -1,9 +1,8 @@
#pragma once
#include <string>

void EngineProcess();
void ClipboardPush(std::string text);
std::string ClipboardPull();
void ClipboardPush(ByteString text);
ByteString ClipboardPull();
int GetModifiers();
bool LoadWindowPosition(int scale);
void SetCursorEnabled(int enabled);
Expand Down
25 changes: 12 additions & 13 deletions src/PowderToyRenderer.cpp
Expand Up @@ -2,11 +2,10 @@

#include <ctime>
#include <iostream>
#include <sstream>
#include <string>
#include <fstream>
#include <vector>

#include "common/String.h"
#include "Config.h"
#include "Format.h"
#include "gui/interface/Engine.h"
Expand All @@ -18,16 +17,16 @@


void EngineProcess() {}
void ClipboardPush(std::string) {}
std::string ClipboardPull() { return ""; }
void ClipboardPush(ByteString) {}
ByteString ClipboardPull() { return ""; }
int GetModifiers() { return 0; }
void SetCursorEnabled(int enabled) {}
unsigned int GetTicks() { return 0; }

void readFile(std::string filename, std::vector<char> & storage)
void readFile(ByteString filename, std::vector<char> & storage)
{
std::ifstream fileStream;
fileStream.open(std::string(filename).c_str(), std::ios::binary);
fileStream.open(filename.c_str(), std::ios::binary);
if(fileStream.is_open())
{
fileStream.seekg(0, std::ios::end);
Expand All @@ -45,10 +44,10 @@ void readFile(std::string filename, std::vector<char> & storage)
}
}

void writeFile(std::string filename, std::vector<char> & fileData)
void writeFile(ByteString filename, std::vector<char> & fileData)
{
std::ofstream fileStream;
fileStream.open(std::string(filename).c_str(), std::ios::binary);
fileStream.open(filename.c_str(), std::ios::binary);
if(fileStream.is_open())
{
fileStream.write(&fileData[0], fileData.size());
Expand All @@ -59,13 +58,13 @@ void writeFile(std::string filename, std::vector<char> & fileData)
int main(int argc, char *argv[])
{
ui::Engine * engine;
std::string outputPrefix, inputFilename;
ByteString outputPrefix, inputFilename;
std::vector<char> inputFile;
std::string ppmFilename, ptiFilename, ptiSmallFilename, pngFilename, pngSmallFilename;
ByteString ppmFilename, ptiFilename, ptiSmallFilename, pngFilename, pngSmallFilename;
std::vector<char> ppmFile, ptiFile, ptiSmallFile, pngFile, pngSmallFile;

inputFilename = std::string(argv[1]);
outputPrefix = std::string(argv[2]);
inputFilename = argv[1];
outputPrefix = argv[2];

ppmFilename = outputPrefix+".ppm";
ptiFilename = outputPrefix+".pti";
Expand All @@ -88,7 +87,7 @@ int main(int argc, char *argv[])
catch (ParseException e)
{
//Render the save again later or something? I don't know
if (e.what() == "Save from newer version")
if (ByteString(e.what()).FromUtf8() == "Save from newer version")
throw e;
}

Expand Down

0 comments on commit 56cba45

Please sign in to comment.