| SC Map & Custom Development Learn and Discuss the Building of Battlegrounds for the Award Winning RTS Here! |

10-20-2006
|
| |
Junior Member
Join Date: Aug 2006
Posts: 36
|

Re: My own Starcraft editor project
C# is not faster than VB.NET. They both get compiled into MSIL (NOT NATIVE CODE).
|
|
|
|

10-21-2006
|
| |
Rabble Rabble Rabble!!
Join Date: Jul 2006
Posts: 555
|

Re: My own Starcraft editor project
They both get compiled into MSIL, but how well do they get compiled into it?
Theres more to take into account than the fact that they get compiled into MSIL. However I'd argree that even then the speed would be for the most part similar.
C# however does allow for pointers which can be incredibly useful and can really speed up code.
We've also been off that subject for a while.......
|
|
|
|

10-21-2006
|
| |
Trigger Mathemagician
Join Date: Jun 2006
Location: Munich, Germany
Posts: 1,488
|

Re: My own Starcraft editor project
I second proceri: In VB, you have to build overcomplex code for things that would be simple with just some pointers. That's probably one of the main reasons why any C code is usually faster than Basic code.
And I agree that we are off-topic
|
|
|
|

10-21-2006
|
| |
BF Member
Join Date: Sep 2006
Location: Laval
Posts: 196
|

Re: My own Starcraft editor project
Since Heimdal bothered to post, did he bother to check it out? I KNOW that he CAN read VB syntax.
Anyway, even if I do convert to C#, I would get the same output, and I woudn't know where to start with pointers, cause I've never really used them. (I've used JavaScript, a little of C#, VBScript, VB6 a little, ASP, some PHP, and VB.Net, none of those except C# have pointers, and what I've done in C# is quite simple)
|
|
|
|

10-28-2006
|
| |
BF Member
Join Date: Sep 2006
Location: Laval
Posts: 196
|

Re: My own Starcraft editor project
Posted a third build and removed all other build download. Refer to first post for more info.
|
|
|
|

10-29-2006
|
| |
Permanent Failure
Join Date: Jun 2006
Location: Atlanta, GA
Posts: 8,727
|

Re: My own Starcraft editor project
Quote
Originally Posted by fatimid08
Since Heimdal bothered to post, did he bother to check it out? I KNOW that he CAN read VB syntax.
Anyway, even if I do convert to C#, I would get the same output, and I woudn't know where to start with pointers, cause I've never really used them. (I've used JavaScript, a little of C#, VBScript, VB6 a little, ASP, some PHP, and VB.Net, none of those except C# have pointers, and what I've done in C# is quite simple)
|
Currently im with php and C#
i started a php editor, but then school came around and i never got to finish it.
Stick with C#.
The code is much prettier.
|
|
|
|

10-29-2006
|
| |
Trigger Mathemagician
Join Date: Jun 2006
Location: Munich, Germany
Posts: 1,488
|

Re: My own Starcraft editor project
stick with C/C++...
|
|
|
|

10-29-2006
|
| |
BF Member
Join Date: Sep 2006
Location: Laval
Posts: 196
|

Re: My own Starcraft editor project
I've found some optimization I could do to the code I posted here.
It seems that my release build runs almost twice as fast as when I'm debugging with the IDE, probably has to do with Visual Studio maintaining a lot of info, having extra debugging stuff in the app itself, and saving auto recovery info taking my CPU for a few seconds every now and then.
And stop telling me to go to C/C++ or C#, I've told you already that I'll switch to it if I have any extremely major problems that are unsolvable without it.
I do have Visual C# 2005 Express installed on my computer, I can work in both syntaxes, but I like the more english-like syntax of VB a bit more. As it is, I make far too many typos with the 3 types of brackets {[()]}, they're all on my 7-8-9-0 keys, and I often miss the SHIFT or ALT or the number. I got a little pissed at it after a while, and I haven't touched it since.
Quote
Stick with C#.
The code is much prettier.
|
Pretty is a VERY relative concept. And it depends what you mean by pretty, reading-wise or performance-wise.
Anyway, some feedback on the actual application would be nice. The up-to-date download is on the first post.
Does anyone have an idea as to why StarEdit would crash if I try to save a map saved by my editor? I tried a simple BroodWar map, the chk output is exactly the same, StarEdit opens it fine, but if you try and save, to the same file or different one, it throws an access violation.
Last edited by fatimid08; 10-29-2006 at 07:24 PM.
|
|
|
|

10-29-2006
|
| |
Rabble Rabble Rabble!!
Join Date: Jul 2006
Posts: 555
|

Re: My own Starcraft editor project
Quote
|
Does anyone have an idea as to why StarEdit would crash if I try to save a map saved by my editor? I tried a simple BroodWar map, the chk output is exactly the same, StarEdit opens it fine, but if you try and save, to the same file or different one, it throws an access violation.
|
Make sure this doesn't happen with other maps saved by Scmdraft 2\etc.. you may have deleted something from the Starcraft directory that staredit needs.
Also whats your code for saving(not the CHK part but the MPQ part). Maybe you have one of the functions not called correctly. If I could make a suggestion, if you have VC++ 2005. Get a static library of SFMPQAPI(not a dll), included it in your project(and sfmpqapi.h\sfmpq_static.h), and have your MPQ created with C++ code then have VB call a single function to do so. Thats what I do, works good.
|
|
|
|

10-30-2006
|
| |
BF Member
Join Date: Sep 2006
Location: Laval
Posts: 196
|

Re: My own Starcraft editor project
I don't have C++, unfortunately, maybe I'll get something other than Visual C++.
SCMDraft and Starforge saved maps save fine in StarEdit, mine just open fine, it doesn't save if overriting a file, but if it saves to a new file, it saves, and then crashes.
Here's my MPQ saving code:
Code:
Private Sub SaveToMpq(ByVal filename As String)
'Open/Create an Mpq and add the tempory CHK to it.
Dim MpqHandle As IntPtr
Dim TempPath As String = Path.GetTempPath()
Dim ListPath As String
Dim ListFile As FileStream
If TempPath.EndsWith("\") = False Then TempPath += "\"
ListPath = TempPath & "(listfile)"
TempPath += "temp.chk"
ListFile = New FileStream(ListPath, FileMode.Create, FileAccess.Write, FileShare.None)
ListFile.Write(System.Text.ASCIIEncoding.ASCII.GetBytes("staredit\scenario.chk"), 0, System.Text.ASCIIEncoding.ASCII.GetByteCount("staredit\scenario.chk"))
ListFile.Dispose()
ListFile = Nothing
If Map.WriteChk(TempPath) = True Then
MpqHandle = SFmpqapi.MpqOpenArchiveForUpdate(filename, SFmpqapi.MpqOpenArchiveForUpdateFlags.MOAU_OPEN_ALWAYS, 1024)
If MpqHandle <> CType(SFmpqapi.INVALID_HANDLE_VALUE, IntPtr) Or MpqHandle = Nothing Then
Try
If TempPath.EndsWith(Chr(0)) = False Then TempPath += Chr(0)
If ListPath.EndsWith(Chr(0)) = False Then ListPath += Chr(0)
If SFmpqapi.MpqAddFileToArchive(MpqHandle, TempPath, "staredit\scenario.chk" & Chr(0), SFmpqapi.MpqAddFileToArchiveFlags.MAFA_REPLACE_EXISTING Or SFmpqapi.MpqAddFileToArchiveFlags.MAFA_COMPRESS) = False Then
MessageBox.Show("Save failed, could not add file to specified Mpq Archive", "Save Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
If SFmpqapi.MpqAddFileToArchive(MpqHandle, ListPath, "(listfile)" & Chr(0), SFmpqapi.MpqAddFileToArchiveFlags.MAFA_REPLACE_EXISTING) = False Then
MessageBox.Show("Could not add listfile to specified Mpq Archive", "Save Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
End If
SFmpqapi.MpqCompactArchive(MpqHandle)
Finally
SFmpqapi.MpqCloseUpdatedArchive(MpqHandle, Nothing)
End Try
End If
If TempPath.EndsWith(Chr(0)) = True Then TempPath = TempPath.Remove(TempPath.Length - 1)
File.Delete(TempPath)
End If
If ListPath.EndsWith(Chr(0)) = True Then ListPath = ListPath.Remove(TempPath.Length - 1)
File.Delete(ListPath)
MpqHandle = Nothing
TempPath = Nothing
ListPath = Nothing
End Sub
Starforge and SCMDraft can save the maps made with this code fine.
EDIT:
I'm adding a C# translation of the code posted above. If I make mistakes (semi-colons, mostly), ah well, I'm not that good of a translator.
It should be done, except for Chr functions, didn't feel like changing them.
Code:
void SaveToMpq(String filename) {
/* Open/Create an Mpq and add the tempory CHK to it. */
IntPtr MpqHandle;
String TempPath = Path.GetTempPath();
String ListPath;
FileStream ListFile;
if (TempPath.EndsWith("\\") == false) {TempPath += "\\"};
ListPath = TempPath + "(listfile)";
TempPath += "temp.chk";
ListFile = new FileStream(ListPath, FileMode.Create, FileAccess.Write, FileShare.None);
ListFile.Write(System.Text.ASCIIEncoding.ASCII.GetBytes("staredit\\scenario.chk"), 0, System.Text.ASCIIEncoding.ASCII.GetByteCount("staredit\\scenario.chk"));
ListFile.Dispose();
ListFile = null;
if (Map.WriteChk(TempPath) == true) {
MpqHandle = SFmpqapi.MpqOpenArchiveForUpdate(filename, SFmpqapi.MpqOpenArchiveForUpdateFlags.MOAU_OPEN_ALWAYS, 1024);
if (MpqHandle != CType(SFmpqapi.INVALID_HANDLE_VALUE, IntPtr) || MpqHandle == null) {
try
if (TempPath.EndsWith(Chr(0)) == false) {TempPath += Chr(0)};
if (ListPath.EndsWith(Chr(0)) == false) {ListPath += Chr(0)};
if (SFmpqapi.MpqAddFileToArchive(MpqHandle, TempPath, "staredit\\scenario.chk" + Chr(0), SFmpqapi.MpqAddFileToArchiveFlags.MAFA_REPLACE_EXISTING | SFmpqapi.MpqAddFileToArchiveFlags.MAFA_COMPRESS) == false) {
MessageBox.Show("Save failed, could not add file to specified Mpq Archive", "Save Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else {
if (SFmpqapi.MpqAddFileToArchive(MpqHandle, ListPath, "(listfile)" + Chr(0), SFmpqapi.MpqAddFileToArchiveFlags.MAFA_REPLACE_EXISTING) == false) {
MessageBox.Show("Could not add listfile to specified Mpq Archive", "Save Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
};
};
SFmpqapi.MpqCompactArchive(MpqHandle);
}
finally
{
SFmpqapi.MpqCloseUpdatedArchive(MpqHandle, null)
};
};
if (TempPath.EndsWith(Chr(0)) == true) {TempPath = TempPath.Remove(TempPath.Length - 1)};
File.Delete(TempPath);
};
if (ListPath.EndsWith(Chr(0)) == true) {ListPath = ListPath.Remove(TempPath.Length - 1)};
File.Delete(ListPath);
MpqHandle = null;
TempPath = null;
ListPath = null;
};
Last edited by fatimid08; 10-30-2006 at 06:46 PM.
|
|
|
|

10-30-2006
|
| |
Rabble Rabble Rabble!!
Join Date: Jul 2006
Posts: 555
|

Re: My own Starcraft editor project
Why not just build a buffer of the CHK and pass the buffer into it rather than creating a temporary file? Or can't you do that in the VB sfmpqapi? If your using the C++ dll and just specifying the functions heres two ways to do it:
BOOL MpqAddFileFromBufferEx(MPQHANDLE hMPQ, LPVOID lpBuffer, DWORD dwLength, LPCSTR lpFileName, DWORD dwFlags, DWORD dwCompressionType, DWORD dwCompressLevel);
BOOL MpqAddFileFromBuffer(MPQHANDLE hMPQ, LPVOID lpBuffer, DWORD dwLength, LPCSTR lpFileName, DWORD dwFlags);
I prefer MpqAddFileFromBufferEx. As you can specify your compression methods. Heres my C++ code for this function:
MpqAddFileFromBufferEx(handlempq, buff, length, "staredit\\scenario.chk", 0x00000101, Z_BEST_COMPRESSION, Z_BEST_COMPRESSION)
Z_BEST_COMPRESSION = 0, so you can substitute that with 0.
0x00000101 specifys to overwrite the file and to compress.
length = length of buffer for the data
buff = all the data for your CHK
handlempq = handle of the mpq your using.
That might simply the C++ code if you don't understand it.
Ok. Try not adding the listfile. If that doesn't change anything then try: changing the compression to: Z_BEST_COMPRESSION
|
|
|
|

10-30-2006
|
| |
BF Member
Join Date: Sep 2006
Location: Laval
Posts: 196
|

Re: My own Starcraft editor project
I've tried without the listfile, and I think I'm using the same compression as StarEdit, I get to the same size. I'll try it out with what you suggested for compression though. The dll does have the buffer declarations, but it is useless the way my code is set up.
My main class basically reads and writes chks to files, and deals with setting defaults values read from dat files by another class, and there is a wrapper class that handles stuff like drawing and mpqs over the main class, and soon to handle terrain modifying with undo/redo.
I still don't understand why StarEdit can open the maps, but not save them, and I guess I never will.
EDIT:
The SFmpqapi declaration I have has Z_BEST_COMPRESSION = 9, not 0.
EDIT 2:
OMG, I just replaced MAFA_COMPRESS by MAFA_COMPRESS2, and suddenly, it works. How dumb is this?
Well then, next build will have this bug fixed.
MpqAddFileToArchive is the function I'm using, it does have basic compression used by StarEdit.
Last edited by fatimid08; 10-30-2006 at 06:59 PM.
|
|
|
|

10-30-2006
|
| |
Rabble Rabble Rabble!!
Join Date: Jul 2006
Posts: 555
|

Re: My own Starcraft editor project
Quote
|
OMG, I just replaced MAFA_COMPRESS by MAFA_COMPRESS2, and suddenly, it works. How dumb is this?
|
I was thinking that could have been a problem, but wasn't sure. Why? In one of the C++ header files it tells you not to use the MAFA_COMPRESS. I just didn't know what you were using for VB.
Quote
|
The SFmpqapi declaration I have has Z_BEST_COMPRESSION = 9, not 0.
|
Ah yes you'd be right. My mistake I looked at Z_NO_COMPRESSION.
I'm alost sure theres a way to maintain the listfile so you actually don't have to write it. In the C++ header file.
// MpqOpenArchiveForUpdate flags
#define MOAU_CREATE_NEW 0x00
#define MOAU_CREATE_ALWAYS 0x08 //Was wrongly named MOAU_CREATE_NEW
#define MOAU_OPEN_EXISTING 0x04
#define MOAU_OPEN_ALWAYS 0x20
#define MOAU_READ_ONLY 0x10 //Must be used with MOAU_OPEN_EXISTING
#define MOAU_MAINTAIN_LISTFILE 0x01
Obviously the last one confuses me on what it exactly is....
|
|
|
|

10-31-2006
|
| |
Trigger Mathemagician
Join Date: Jun 2006
Location: Munich, Germany
Posts: 1,488
|

Re: My own Starcraft editor project
MOAU_MAINTAIN_LISTFILE should - from what I know, didn't test it yet - update the listfile, IF there is one. So if you create a new map, you would have to add it manually at first, and from then the MPQAddFile functions SHOULD do the rest.But as I said, I haven't tested it yet.
About you C# translation... Is this C# syntax or what is this: }; I usually don't put semikola after those brackets :p
|
|
|
|

10-31-2006
|
| |
BF Member
Join Date: Sep 2006
Location: Laval
Posts: 196
|

Re: My own Starcraft editor project
ya, VB doesn't tell me not to use it. I think I read somewhere that you can only use MOAU_MAINTAIN_LISTFILE if there already is a listfile in the file.
Found it:
Quote
MOAU_MAINTAIN_LISTFILE
This flag specifies that as MpqOpenArchiveForUpdate uses the archive lpFileName, it should update the internal listfile, if one exists. This is a flag, and must be ORed (with the | operator) with one of the other options for dwCreationDisposition
|
Taken from this link.
Haven't used C syntax for a while, I thought it needed ; after a final }. I don't think it the compiler (both C and C#) minds if I do put them though.
|
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 07:12 PM.
vBulletin® Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
BlizzForums is hosted by DarkStar Communications, home to high quality Ventrilo Servers.
|
|