Staredit Network > Forums > SC1 Mapping Tools > Topic: Chkdraft Project
Chkdraft Project
Oct 9 2012, 12:42 am
By: jjf28
Pages: < 1 3 4 5 6 714 >
 

Jan 28 2013, 4:52 am Roy Post #81

An artist's depiction of an Extended Unit Death

Quote from Heinermann
Another tip:
I also noticed some blocks of code like this:
Code
    if ( location < size )
    {
        data[location] = character;
        return true;
    }
    return false;

But don't forget you can use ! (not) and come up with this, which is the same thing with less brackets:
Code
    if ( location >= size )
        return false;
    data[location] = character;
    return true;
Omitting brackets is considered a bad practice by many, though, as you sacrifice maintainability (I used to omit, but have since changed my ways). And having multiple exit points can be considered a bad practice (especially noticeable when debugging multi-threaded applications), but I personally never worry about that unless I have to.




Jan 28 2013, 5:13 am Lanthanide Post #82



Quote from Heinermann
2. Replaced some boolean code that had the following redundant format:
Code
if ( CONDITION )
 return true;
else
 return false;

/// REPLACE WITH:
return CONDITION; // if CONDITION is true it returns true, otherwise false; much cleaner!
I'm sure it's probably safe in the code you changed, but your replacement is not logically identical to the original code.



None.

Jan 28 2013, 5:32 am jjf28 Post #83

Cartography Artisan

Quote from Heinermann
1. Created a class called MyWndClass which is used to register the window classes at the beginning of the program. Hopefully this helps you understand classes better.
2. Replaced some boolean code that had the following redundant format:
3. Fixed some memory leaks! These are important. When you use "new" you have to manage the memory yourself, and can often lose it.
4. Used some standard library functions!

Oh darn, was just about to release a massive overhaul to the project (all the files are now source/header pairs, fixed a number of memory leaks/poorly written deletes), I'll look very closely at your edited code for your changes and will bring over all of them that I can, thank you very much!

Curious, are static functions advantageous or for book-keeping? answered in sb

Edit:
I copied over all the changes I could find and removed the stringy file; attached is where it's at atm (will post an 'update' after headers have been commented and undo/redo is finished).

Thanks for introducing me to sprintf, seen it around but didn't understand it till seeing it replace my code :)

Attachments:
Chkdraft.zip
Hits: 8 Size: 278.78kb

Post has been edited 3 time(s), last time on Jan 28 2013, 8:06 am by jjf28.



Rs_yes-im4real - Clan Aura - jjf28.net84.net

Reached the top of StarCraft theory crafting 2:12 AM CST, August 2nd, 2014.

Jan 28 2013, 6:03 am Roy Post #84

An artist's depiction of an Extended Unit Death

Quote from Lanthanide
I'm sure it's probably safe in the code you changed, but your replacement is not logically identical to the original code.
How so, exactly? Replace "condition" with either true or false and give me a scenario where returning it yields a different result. Let's break it down:

Code
if (condition) {
   return true;
} else {
   return false;
}
Code
if (condition == true) {
   return true;
} else if (condition == false) {
   return false;
}

Because the condition must evaluate to a boolean, those two snippets of code are the same, correct? So only if the condition is true will it return true, and only if the condition is false will it return false. Therefore, you can just return the condition as Heinermann was suggesting:
Code
return condition;

That's why a naming convention for boolean variables is to start it with "is" or "has." For example, consider the variable being called "isAllowed" in the above scenarios.
Side Note

Quote from jjf28
Curious, are static functions advantageous or for book-keeping?
Static functions are fine for arithmetic/stateless operations. Otherwise, you should try to avoid making your functions static.




Jan 28 2013, 6:08 am Lanthanide Post #85



Fell into the same trap as Heinermann, Roy :)

Assuming true = 1 and false = 0, here are the input/outputs for each case:
if (condition) return true, else return false:
input 2 return 1
input 1 return 1
input 0 return 0
input -1 return 1

return condition:
input 2 return 2
input 1 return 1
input 0 return 0
input -1 return -1

Also from a defensive programming perspective, I'd say it's much better to use the former, because it guarantees the function will only return 0 or 1 regardless of the inputs. The latter code will probably also return 0 or 1 because of the structure of your code, but there's always a chance that some random input could show up, causing it to return a very unexpected value, which could cause problems elsewhere in your program.



None.

Jan 28 2013, 6:13 am Roy Post #86

An artist's depiction of an Extended Unit Death

The input cannot be 2 or -1, because the code inside an if statement must return a boolean value to be evaluated. Therefore, the condition variable can only be 0 or 1. C is a staticly-typed language: when you define a variable, it will be that type. If your function returns a boolean and you try to give it a 2 or -1 (or an int variable in general) to return, it will be a compile error.

Unless I fundamentally do not understand some quirk of C/C++.

Post has been edited 1 time(s), last time on Jan 28 2013, 6:27 am by Roy. Reason: Boolean types don't exist? :(




Jan 28 2013, 6:19 am Lanthanide Post #87



C doesn't have a boolean type. Hence why I said "assuming true = 1 and false = 0".



None.

Jan 28 2013, 7:10 am O)FaRTy1billion[MM] Post #88

👻 👾 👽 💪

That's why most things say it like "returns nonzero on success/failure/what". In C, true is just "nonzero" and false is "zero", so ultimately it doesn't seem like it should matter unless you give some importance to the actual binary value.

And when you use the return of that function in if(retval) you get ...
retval 2 return 1
retval 1 return 1
retval 0 return 0
retval -1 return 1
So, really, it shouldn't matter too much especially when, no matter how you choose the return value, the return value is going to have two cases: nonzero and zero.

EDIT:
Unless you are using if(condition == true) ... but who does that? :P

EDIT2:
Unless we are just assuming "condition" is a single variable, and not a placeholder for like "thing >= value".

Post has been edited 4 time(s), last time on Jan 28 2013, 8:19 am by FaRTy1billion.



TinyMap2 - Latest in map compression! ( 7/09/14 - New build! )
EUD Action Enabler - Lightweight EUD/EPD support! (ChaosLauncher/MPQDraft support!)
EUDDB - topic - Help out by adding your EUDs! Or Submit reference files in the References tab!
MapSketch - New image->map generator!
EUDTrig - topic - Quickly and easily convert offsets to EUDs! (extended players supported)
SC2 Map Texture Mask Importer/Exporter - Edit texture placement in an image editor!
\:farty\: This page has been viewed [img]http://farty1billion.dyndns.org/Clicky.php?img.gif[/img] times!

Jan 28 2013, 9:20 am Lanthanide Post #89



Quote from O)FaRTy1billion[MM]
And when you use the return of that function in if(retval) you get ...
retval 2 return 1
retval 1 return 1
retval 0 return 0
retval -1 return 1
So, really, it shouldn't matter too much especially when, no matter how you choose the return value, the return value is going to have two cases: nonzero and zero.
Unless you do retvel = function(args), in which case returning something other than 0 or 1 could potentially cause problems down the line if you aren't careful.

My whole point though is that it's potentially dangerous, not that it is dangerous.



None.

Jan 30 2013, 2:34 am Heinermann Post #90

SDE, BWAPI owner, hacker.

Quote from Roy
Quote from Heinermann
Another tip:
I also noticed some blocks of code like this:
Code
    if ( location < size )
    {
        data[location] = character;
        return true;
    }
    return false;

But don't forget you can use ! (not) and come up with this, which is the same thing with less brackets:
Code
    if ( location >= size )
        return false;
    data[location] = character;
    return true;
Omitting brackets is considered a bad practice by many, though, as you sacrifice maintainability (I used to omit, but have since changed my ways). And having multiple exit points can be considered a bad practice (especially noticeable when debugging multi-threaded applications), but I personally never worry about that unless I have to.
I disagree. As for having multiple exit points, I think it's fine to immediately return after checking validity of a call (a piece of code that is unlikely to change). But ultimately this is jjf28's decision, I just wanted to show that inverse statements can be used. I think jjf28 should consider your post though.

Quote from Lanthanide
C doesn't have a boolean type. Hence why I said "assuming true = 1 and false = 0".
We're assuming 1 = 1 and false = false. This is C++. But even in C it wouldn't necessarily be bad. You would define FALSE as 0 and just check != FALSE (or just don't compare it with anything). But in C++ returning a condition as a boolean, even if your condition is not a boolean expression, will implicitly cast it to bool (using 0 = false, otherwise true).




Jan 30 2013, 2:54 am Lanthanide Post #91



Quote from Heinermann
Quote from Lanthanide
C doesn't have a boolean type. Hence why I said "assuming true = 1 and false = 0".
We're assuming 1 = 1 and false = false. This is C++. But even in C it wouldn't necessarily be bad. You would define FALSE as 0 and just check != FALSE (or just don't compare it with anything). But in C++ returning a condition as a boolean, even if your condition is not a boolean expression, will implicitly cast it to bool (using 0 = false, otherwise true).
I didn't say it was bad, I said it was unsafe and not logically the same as the original code, which is true. My assumption was C however, not C++, so fair cop on that.



None.

Jan 30 2013, 3:49 am Heinermann Post #92

SDE, BWAPI owner, hacker.

Here are a few other changes that can be done:
Code
                        case 0x56: // Ctrl + V
                            maps.startPaste();
                            break;
                        case 0x4E: // Ctrl + N

to
Code
                        case 'V': // Ctrl + V
                            maps.startPaste();
                            break;
                        case 'N': // Ctrl + N



Code
#include <stdio.h>

may be valid, but in C++ you are supposed to use
Code
#include <cstdio>

Just drop the .h and add a c in front (doesn't apply to windows.h, just the C standard library).

Some code for your Math.cpp:
Code
void LongToBytes(long value, char *bytes)
{
 (long&)bytes[0] = value;
}

void ShortToBytes(unsigned short int value, char *bytes)
{
 (unsigned short int&)bytes[0] = value;
}

(EDIT: Not sure about the above. If it's no good then in your code use bitwise shift operators instead of dividing by large constants)


Also want to introduce you to the C++ standard library (slowly)
Code
#include <algorithm>

void AscendingOrder(long &low, long &high)
{
 if ( low > high )
 {
   std::swap(low,high);
 }
}


Eventually your Clipboard/Selection stuff will use the C++ Standard Template Library (STL) containers to hold information so you don't have to manually manage their pointers (right now you're emulating what you could do using std::forward_list<TileNode> and std::forward_list<PASTETILENODE> ). Using the standard library will help minimize the risk of errors. If you're not ready for the upgrade then you can leave it as is for now.

In Tilesets.cpp you used a bunch of strcat calls to initialize OpenFilter, but you can add null characters using sprintf with the escape sequence \0.
Code
    char OpenFilter[MAX_PATH+40];
 sprintf(OpenFilter, "%s\0*%s*;\0All Files\0*.*\0\0", FileName, FileName);


Lastly, you have a hardcoded stardat.mpq location. BWAPI has some code for retrieving the Starcraft install directory here: https://code.google.com/p/bwapi/source/browse/branches/bwapi4/bwapi/BWAPI_PluginInjector/common.cpp#20

Look at GetSingleRegString and GetRegString, both of which use mostly C-style code for the WinAPI calls.

Post has been edited 4 time(s), last time on Jan 30 2013, 4:21 am by Heinermann.




Jan 31 2013, 9:54 am SinistrouS Post #93



"Could not find StarDat.mpq

Would you like to locate it manually?"

Clicking yes just closes the program, but it remains as a process within task manager.



None.

Jan 31 2013, 3:50 pm jjf28 Post #94

Cartography Artisan

Quote
"Could not find StarDat.mpq

Would you like to locate it manually?"

I was getting a rather curious bug where compiling in debug rather than release mode caused openfilename calls to fail, should be fixed in the next release

Edit: Found the specific discrepancy; apparently the compiler didn't like me messing with heap size

Post has been edited 1 time(s), last time on Jan 31 2013, 5:43 pm by jjf28.



Rs_yes-im4real - Clan Aura - jjf28.net84.net

Reached the top of StarCraft theory crafting 2:12 AM CST, August 2nd, 2014.

Mar 20 2013, 11:58 am jjf28 Post #95

Cartography Artisan

Update 3/20/13 - Download Latest

- Basic unit and sprite display (without player-color or ISCRIPT based modifications)
- Unit and unit sprites displayed on minimap (1 pixel per)
- Terrain select-all
- Terrain copy-paste
- View-only mode for protected maps (no saving/copying)
- Protected map detection: duplicate sections, oversized sections, invalid VCOD
- Supports open-with and drag-and-drop
- Automatically gets starcraft directory, otherwise better handling
- No longer deletes or rearranges chk sections
- No longer limits how many maps can be open at once
- SFmpq.dll no longer required with the program
- Fixed misc creation and saving errors (including those due to out-of-storage situations)
- Misc crash and bug fixes



If anyone's following the code there's been a fair amount of restructuring, perhaps most notably, maps now contain a linked list of chk sections and pointers to the sections Chkdraft uses (or plans to use) - these pointers can be used safely as each method in the buffer class validates that they are not null.

Query: is the main Starcraft unit pallet hard-coded? (can't find it anywhere...) I've hard-coded one provided with starforge for now - seems to give good results.

Text triggers was ~85% complete when I ran into strings, put that off till later.

All in all there aren't that many noticeable 'functional' changes with this update, regardless I hope you enjoy!

Post has been edited 1 time(s), last time on Mar 20 2013, 12:16 pm by jjf28.



Rs_yes-im4real - Clan Aura - jjf28.net84.net

Reached the top of StarCraft theory crafting 2:12 AM CST, August 2nd, 2014.

Mar 21 2013, 1:30 am O)FaRTy1billion[MM] Post #96

👻 👾 👽 💪

Good job so far! It looks like it's coming along really nicely.

There is no specific unit palette. Use the WPE from the active terrain files as the global palette (that's what StarCraft does).

Also, if you don't already know, game\tunit.pcx has the player colors. It's a table with 16 sets of 8 (only the first 12 are used, referenced by COLR section in BW maps), and the 8 colors are mapped to indexes 8 through 15 when drawing unit sprites (if, for example, the grp wants to draw color index 9, then read the color index at tunit[pcolor*8+(9-8)])

Post has been edited 4 time(s), last time on Mar 21 2013, 1:40 am by FaRTy1billion.



TinyMap2 - Latest in map compression! ( 7/09/14 - New build! )
EUD Action Enabler - Lightweight EUD/EPD support! (ChaosLauncher/MPQDraft support!)
EUDDB - topic - Help out by adding your EUDs! Or Submit reference files in the References tab!
MapSketch - New image->map generator!
EUDTrig - topic - Quickly and easily convert offsets to EUDs! (extended players supported)
SC2 Map Texture Mask Importer/Exporter - Edit texture placement in an image editor!
\:farty\: This page has been viewed [img]http://farty1billion.dyndns.org/Clicky.php?img.gif[/img] times!

Mar 21 2013, 2:11 am jjf28 Post #97

Cartography Artisan

Quote
There is no specific unit palette. Use the WPE from the active terrain files as the global palette (that's what StarCraft does).

Simple enough, thanks :)1

Quote
Also, if you don't already know, game\tunit.pcx has the player colors.

I copied the colors seen from a minimap pic, this will be better

Quote
and the 8 colors are mapped to indexes 8 through 15 when drawing unit sprites

See #1



Rs_yes-im4real - Clan Aura - jjf28.net84.net

Reached the top of StarCraft theory crafting 2:12 AM CST, August 2nd, 2014.

Mar 21 2013, 3:48 am trgk Post #98



Quote from jjf28
- View-only mode for protected maps (no saving/copying)
- Protected map detection: duplicate sections, oversized sections, invalid VCOD

This seems dangerous, since Chkdraft is open-source now. Let's #define noProtection 1
+ Does this mark map which is missing editor-only sections as protected? (Such as IVE2, WAV, ...)



EUD

Mar 21 2013, 4:12 am jjf28 Post #99

Cartography Artisan

Quote
This seems dangerous, since Chkdraft is open-source now. Let's #define noProtection 1

I removed that flag and the VCOD failure position echo, and re-uploaded.

With the project being open source and the code cleanly written there's no real way for me to support map protection against programmers unless I purposefully write my map parser worse (no).

Ultimately unprotection tools means zilch starcraft programmers as they can unprotect the maps themselves (or can easily find means to do so). In any case, as i'm not releasing a utility that can modify protected maps, or releasing instructions to modify chkdraft to disable protection, or purposefully providing a means to do so, SEN's unprotector rules don't apply here ;)

Quote
Does this mark map which is missing editor-only sections as protected? (Such as IVE2, WAV, ...)

Edit: No it does not consider maps missing (a) section(s) to be protected

Post has been edited 1 time(s), last time on Mar 21 2013, 4:25 am by jjf28.



Rs_yes-im4real - Clan Aura - jjf28.net84.net

Reached the top of StarCraft theory crafting 2:12 AM CST, August 2nd, 2014.

Mar 31 2013, 8:44 am RexyRex Post #100



I think it's really, really cool you're doing this.



None.

Options
Pages: < 1 3 4 5 6 714 >
  Back to forum
Please log in to reply to this topic or to report it.
Members in this topic: None.
[11:04 am]
TF- -- u
[02:55 am]
KrayZee -- Watching live streams of gamers playing through trial and error feels such a waste of time.
[09:43 pm]
MTiger156 -- :wob: :wob:
[09:39 pm]
Vrael -- :wob:
[09:33 pm]
MTiger156 -- no u
[08:48 pm]
jjf28 -- no imo
[08:16 pm]
MTiger156 -- "ya imo" shall be the meme of 2020
[08:00 pm]
jjf28 -- 50 shades of minerals
[07:47 pm]
MTiger156 -- 50 boxes of shade
[04:59 pm]
NudeRaider -- 50 shades of boxed :boxed:
Please log in to shout.


Members Online: Roy, karma35328, MTiger156, 8audreye7723gh5, jun3hong, adele