Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 04 Feb 2008
Online Last Active Today, 01:35 PM

Posts I've Made

In Topic: Read Adobe Illustrator file without using external libraries, on C#?

27 August 2016 - 11:24 AM

public static byte[] readAdobeIllustratorFileWithoutUsingExternalLibrariesInCSharp(string path) {
    return System.IO.File.ReadAllBytes(path);
AI files are either post script or PDF. You will need to study and implement one or both to use AI files.

Or, you know, you could save yourself a million hours of work and just use a library or export to an intermediate format such as SVG...

In Topic: What to consider for an RPG damage formula?

26 August 2016 - 01:13 PM

Seems similar to my approach. :)

Just to throw out my two cents, the fundamental problem with “a ratio of the attacker’s attack stat” is that the stat is multiplied with itself, giving it an unfair advantage. Adding one or two points to attack is much stronger than adding one or two points to defense. It may be helpful to separate the “bonus stats” gained from items from “base stats” gained from levels. I don’t have my exact formula, but I think I have something similar to:

Probably totally incorrect:

STR: Strength (base attack)     ATK: Bonus attack
RES: Resistance (base defense)  DEF: Bonus defense

         A_STR + max(0,A_ATK - B_DEF)
damage = ----------------------------  x  (A_STR+A_ATK)
           A_STR + B_RES + B_DEF

In Topic: Errors that effect a computer's system.

22 August 2016 - 07:14 PM

Operating systems these days have layers upon layers of abstraction that can catch and recover from serious errors. For example, memory is virtualized, so a program cannot trash another program’s memory-- both program could have memory reserved at 0xC0000123, but is mapped to different locations of physical memory: 0xF0010123 and 0xF0020123. Files are also protected with permissions, you don’t accidentally overwrite important system files.

The worst you can do is crash your video driver, but Windows can generally recover. At worst, you might need to restart your computer.

Now, if you were writing kernel drivers, that’s another story altogether...

In Topic: IFSTREAM: take coordinate from file and convert 3 digit coordinate into integer

21 August 2016 - 09:13 PM

You’re almost there. std::string::c_str returns the actual contents of the string as a const char*; there’s no need to atoi every character in the array:
std::string input = "123";
int expected = 123;
int value = atoi(input.c_str());

assert( value == expected );

After that there's a problem, because I can't have an array that stores '1' '0' '0' because that would be 3 integers, and I don't think integers can be concatenated to get '100'.

Actually, you can using powers of ten: 123 == 1*100 + 2*10 + 3.
(N.B.: This is how we convert from hex to dec: 0x3E8 == 3*16^2 + 15*16^1 + 8*16^0 == 1000)
However, ASCII '0' has a different value from the literal zero, so we’ll need to “slide the ASCII chart” to bring '0' to a literal zero, like so:
char input[] = "123";
int expected = 123;
int value =
     (input[0]-'0') * 100 +
     (input[1]-'0') *  10 +
     (input[2]-'0') *   1;

assert( expected == value );
This works because the char type is an integer type and can be operating like regular integers. We could write the actual ASCII value of '0' (48) in place of '0' in the test above, but with '0' written out, it is more clear.

While there’s nothing wrong with using atoi, there are more C++-y ways to do parsing using streams:
std::string input = "123";
int expected = 123;
int value = 0;

std::istringstream stream(input);
stream >> value;

assert( expected == value );
And extending on the above, you could read your entire file:
int x;
int y;
int type;

// buffer to hold the non-integer tokens, used to validate that 
// the line is in the correct format
char dummy[4] = {};

string line;
ifstream file;
while ( getline(file, line) ) {
    istringstream stream(line);

    // line := x 'x' y '[' type ']'
    stream >> x >> dummy[0] >> y >> dummy[1] >> type >> dummy[2];

    if ( !stream ) {
        // not enough tokens, or a problem converting some of the integers

    if ( strcmp(dummy, "x[]") ) {
        // expected "100 x 200 [300]", but got something
        // like     "100 A 200 ?300~" instead

    // x, y, and type have been extracted from the line
    objects.push_back({x, y, type});

In Topic: C++ what is in string after std::istreambuf_iterator< char >(sourceFi...

17 August 2016 - 04:39 PM

I did used the debugger. when i was in the debugger, the content of *c and *ac are all strange looking char, It is not from my input file.

Is the file loaded correctly inside loadFromFile? (Hint, the issue is inside loadFromFile.)